| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 by the FIFE team * |
| 3 |
* http://www.fifengine.net * |
| 4 |
* This file is part of FIFE. * |
| 5 |
* * |
| 6 |
* FIFE is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Lesser General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2.1 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 14 |
* Lesser General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Lesser General Public * |
| 17 |
* License along with this library; if not, write to the * |
| 18 |
* Free Software Foundation, Inc., * |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
***************************************************************************/ |
| 21 |
|
| 22 |
#ifndef FIFE_RENDERERBASE_H |
| 23 |
#define FIFE_RENDERERBASE_H |
| 24 |
|
| 25 |
// Standard C++ library includes |
| 26 |
#include <list> |
| 27 |
#include <vector> |
| 28 |
|
| 29 |
// 3rd party library includes |
| 30 |
|
| 31 |
// FIFE includes |
| 32 |
// These includes are split up in two parts, separated by one empty line |
| 33 |
// First block: files included from the FIFE root src directory |
| 34 |
// Second block: files included from the same folder |
| 35 |
|
| 36 |
#include "renderitem.h" |
| 37 |
|
| 38 |
namespace FIFE { |
| 39 |
class Camera; |
| 40 |
class Layer; |
| 41 |
class Map; |
| 42 |
class Instance; |
| 43 |
class RenderBackend; |
| 44 |
|
| 45 |
class RendererBase; |
| 46 |
/** RendererListener allows reaction to changes in renderer |
| 47 |
* Having this implemented via callback mechanism should speed up the rendering a bit |
| 48 |
* (e.g. no need to sort pipeline order per each frame) |
| 49 |
*/ |
| 50 |
class IRendererListener { |
| 51 |
public: |
| 52 |
virtual ~IRendererListener() {} |
| 53 |
|
| 54 |
/** Renderer's pipeline position has been changed |
| 55 |
*/ |
| 56 |
virtual void onRendererPipelinePositionChanged(RendererBase* renderer) = 0; |
| 57 |
|
| 58 |
/** Renderer is enabled / disabled |
| 59 |
*/ |
| 60 |
virtual void onRendererEnabledChanged(RendererBase* renderer) = 0; |
| 61 |
}; |
| 62 |
|
| 63 |
/** Interface to class owning the renderers |
| 64 |
* Used to get correct subclass of renderer in scripting side (via renderer's static method) |
| 65 |
*/ |
| 66 |
class IRendererContainer { |
| 67 |
public: |
| 68 |
virtual ~IRendererContainer() {} |
| 69 |
|
| 70 |
/** Returns renderer with given name |
| 71 |
*/ |
| 72 |
virtual RendererBase* getRenderer(const std::string& renderername) = 0; |
| 73 |
}; |
| 74 |
|
| 75 |
/** Base class for all view renderers |
| 76 |
* View renderer renders one aspect of the view shown on screen |
| 77 |
*/ |
| 78 |
class RendererBase { |
| 79 |
public: |
| 80 |
/** Constructor |
| 81 |
* @param renderbackend to use |
| 82 |
* @param position position for this renderer in rendering pipeline |
| 83 |
*/ |
| 84 |
RendererBase(RenderBackend* renderbackend, int32_t position); |
| 85 |
|
| 86 |
/** Copy Constructor |
| 87 |
*/ |
| 88 |
RendererBase(const RendererBase& old); |
| 89 |
|
| 90 |
/** Makes copy of this renderer |
| 91 |
*/ |
| 92 |
virtual RendererBase* clone() = 0; |
| 93 |
|
| 94 |
/** Destructor |
| 95 |
*/ |
| 96 |
virtual ~RendererBase() {}; |
| 97 |
|
| 98 |
/** This method is called by the view to ask renderer to draw its rendering aspect based on |
| 99 |
* given parameters. Renderers receive non-clipped instance stack since there is no |
| 100 |
* way to know which information is relevant for the renderer. E.g. effect renderer |
| 101 |
* might need to know offscreen instance locations to be able to draw radiation coming from |
| 102 |
* some instance not visible on the screen. |
| 103 |
* |
| 104 |
* @param cam camera view to draw |
| 105 |
* @param layer current layer to be rendered |
| 106 |
* @param instances instances on the current layer |
| 107 |
* @ see setPipelinePosition |
| 108 |
*/ |
| 109 |
virtual void render(Camera* cam, Layer* layer, RenderList& instances) = 0; |
| 110 |
|
| 111 |
/** Name of the renderer |
| 112 |
*/ |
| 113 |
virtual std::string getName() = 0; |
| 114 |
|
| 115 |
/** Gets renderer position in the rendering pipeline |
| 116 |
*/ |
| 117 |
int32_t getPipelinePosition() const { return m_pipeline_position; } |
| 118 |
|
| 119 |
/** Sets renderer position in the rendering pipeline |
| 120 |
* Pipeline position defines in which order view calls the renderers when update occurs |
| 121 |
* Note that renderers are called once per rendered layer, thus to update the |
| 122 |
* whole screen, renderer might receive multiple calls |
| 123 |
*/ |
| 124 |
void setPipelinePosition(int32_t position); |
| 125 |
|
| 126 |
/** Enables renderer |
| 127 |
*/ |
| 128 |
virtual void setEnabled(bool enabled); |
| 129 |
|
| 130 |
/** Resets information in the renderer |
| 131 |
*/ |
| 132 |
virtual void reset() {} |
| 133 |
|
| 134 |
/** Is renderer enabled |
| 135 |
*/ |
| 136 |
bool isEnabled() const { return m_enabled; } |
| 137 |
|
| 138 |
/** Sets listener for renderer |
| 139 |
*/ |
| 140 |
void setRendererListener(IRendererListener* listener) { m_listener = listener; } |
| 141 |
|
| 142 |
/** Adds active layer to renderer. Only active layers are rendered |
| 143 |
*/ |
| 144 |
void addActiveLayer(Layer* layer); |
| 145 |
|
| 146 |
/** Removes active layer from renderer. |
| 147 |
*/ |
| 148 |
void removeActiveLayer(Layer* layer); |
| 149 |
|
| 150 |
/** Clears all active layers from renderer |
| 151 |
*/ |
| 152 |
void clearActiveLayers(); |
| 153 |
|
| 154 |
/** Activates all layers from given elevation |
| 155 |
*/ |
| 156 |
void activateAllLayers(Map* elevation); |
| 157 |
|
| 158 |
/** Returns if given layer is currently activated |
| 159 |
*/ |
| 160 |
bool isActivedLayer(Layer* layer); |
| 161 |
|
| 162 |
/** Returns list of activated layer |
| 163 |
*/ |
| 164 |
std::list<Layer*> getActiveLayers() const {return m_active_layers;} |
| 165 |
|
| 166 |
|
| 167 |
protected: |
| 168 |
RendererBase(); |
| 169 |
|
| 170 |
std::list<Layer*> m_active_layers; |
| 171 |
RenderBackend* m_renderbackend; |
| 172 |
|
| 173 |
private: |
| 174 |
bool m_enabled; |
| 175 |
int32_t m_pipeline_position; |
| 176 |
IRendererListener* m_listener; |
| 177 |
}; |
| 178 |
} |
| 179 |
|
| 180 |
#endif |