00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FIFE_LIGHTRENDERER_H
00023 #define FIFE_LIGHTRENDERER_H
00024
00025
00026 #include <vector>
00027
00028
00029
00030
00031
00032
00033
00034 #include "view/rendererbase.h"
00035
00036 namespace FIFE {
00037 class RenderBackend;
00038 class AbstractFont;
00039 class ImagePool;
00040 class AnimationPool;
00041
00042 class LightRendererNode {
00043 public:
00044 LightRendererNode(Instance* attached_instance, const Location &relative_location, Layer* relative_layer, const Point &relative_point = Point(0,0));
00045 LightRendererNode(Instance* attached_instance, const Location &relative_location, const Point &relative_point = Point(0,0));
00046 LightRendererNode(Instance* attached_instance, Layer* relative_layer, const Point &relative_point = Point(0,0));
00047 LightRendererNode(Instance* attached_instance, const Point &relative_point = Point(0,0));
00048 LightRendererNode(const Location &attached_location, Layer* relative_layer, const Point &relative_point = Point(0,0));
00049 LightRendererNode(const Location &attached_location, const Point &relative_point = Point(0,0));
00050 LightRendererNode(Layer* attached_layer, const Point &relative_point = Point(0,0));
00051 LightRendererNode(const Point &attached_point);
00052 ~LightRendererNode();
00053
00054 void setAttached(Instance* attached_instance, const Location &relative_location, const Point &relative_point);
00055 void setAttached(Instance* attached_instance, const Location &relative_location);
00056 void setAttached(Instance* attached_instance, const Point &relative_point);
00057 void setAttached(Instance* attached_instance);
00058 void setAttached(const Location &attached_location, const Point &relative_point);
00059 void setAttached(const Location &attached_location);
00060 void setAttached(Layer* attached_layer);
00061 void setAttached(const Point &attached_point);
00062
00063 void setRelative(const Location &relative_location);
00064 void setRelative(const Location &relative_location, Point relative_point);
00065 void setRelative(const Point &relative_point);
00066
00067 Instance* getAttachedInstance();
00068 Location getAttachedLocation();
00069 Layer* getAttachedLayer();
00070 Point getAttachedPoint();
00071
00072 Location getOffsetLocation();
00073 Point getOffsetPoint();
00074
00075 Instance* getInstance();
00076 Location getLocation();
00077 Layer* getLayer();
00078 Point getPoint();
00079
00080 Point getCalculatedPoint(Camera* cam, Layer* layer);
00081 private:
00082 Instance* m_instance;
00083 Location m_location;
00084 Layer* m_layer;
00085 Point m_point;
00086 };
00087
00088 class LightRendererElementInfo {
00089 public:
00090 virtual void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {};
00091 virtual std::string getName() { return 0; };
00092 virtual LightRendererNode* getNode() { return NULL; };
00093 virtual int getId() { return -1; };
00094 virtual int getSrcBlend() { return -1; };
00095 virtual int getDstBlend() { return -1; };
00096 virtual void setStencil(uint8_t stencil_ref, float alpha_ref) {};
00097 virtual int getStencil() { return 0; };
00098 virtual float getAlpha() { return 0; };
00099 virtual void removeStencil() {};
00100 virtual std::vector<uint8_t> getColor() { return std::vector<uint8_t>(); };
00101 virtual float getRadius() { return 0; };
00102 virtual int getSubdivisions() { return 0; };
00103 virtual float getXStretch() { return 0; };
00104 virtual float getYStretch() { return 0; };
00105 virtual ~LightRendererElementInfo() {};
00106 };
00107
00108 class LightRendererImageInfo : public LightRendererElementInfo {
00109 public:
00110 void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool);
00111 std::string getName() { return "image"; };
00112 LightRendererNode* getNode() { return &m_anchor; };
00113 int getId() { return m_image; };
00114 int getSrcBlend() { return m_src; };
00115 int getDstBlend() { return m_dst; };
00116 void setStencil(uint8_t stencil_ref, float alpha_ref);
00117 int getStencil();
00118 float getAlpha();
00119 void removeStencil();
00120 LightRendererImageInfo(LightRendererNode n, int image, int src, int dst);
00121 virtual ~LightRendererImageInfo() {};
00122 private:
00123 LightRendererNode m_anchor;
00124 int m_image;
00125 int m_src;
00126 int m_dst;
00127 bool m_stencil;
00128 uint8_t m_stencil_ref;
00129 float m_alpha_ref;
00130 };
00131 class LightRendererAnimationInfo : public LightRendererElementInfo {
00132 public:
00133 void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool);
00134 std::string getName() { return "animation"; };
00135 LightRendererNode* getNode() { return &m_anchor; };
00136 int getId() { return m_animation; };
00137 int getSrcBlend() { return m_src; };
00138 int getDstBlend() { return m_dst; };
00139 void setStencil(uint8_t stencil_ref, float alpha_ref);
00140 int getStencil();
00141 float getAlpha();
00142 void removeStencil();
00143 LightRendererAnimationInfo(LightRendererNode n, int animation, int src, int dst);
00144 virtual ~LightRendererAnimationInfo() {};
00145 private:
00146 LightRendererNode m_anchor;
00147 int m_animation;
00148 int m_src;
00149 int m_dst;
00150 unsigned int m_start_time;
00151 float m_time_scale;
00152 bool m_stencil;
00153 uint8_t m_stencil_ref;
00154 float m_alpha_ref;
00155 };
00156 class LightRendererSimpleLightInfo : public LightRendererElementInfo {
00157 public:
00158 void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool);
00159 std::string getName() { return "simple"; };
00160 LightRendererNode* getNode() { return &m_anchor; };
00161 int getSrcBlend() { return m_src; };
00162 int getDstBlend() { return m_dst; };
00163 void setStencil(uint8_t stencil_ref, float alpha_ref);
00164 int getStencil();
00165 float getAlpha();
00166 void removeStencil();
00167 std::vector<uint8_t> getColor();
00168 float getRadius() { return m_radius; };
00169 int getSubdivisions() { return m_subdivisions; };
00170 float getXStretch() { return m_xstretch; };
00171 float getYStretch() { return m_ystretch; };
00172 LightRendererSimpleLightInfo(LightRendererNode n, uint8_t intensity, float radius, int subdivisions, float xstretch, float ystretch, uint8_t r, uint8_t g, uint8_t b, int src, int dst);
00173 virtual ~LightRendererSimpleLightInfo() {};
00174 private:
00175 LightRendererNode m_anchor;
00176 uint8_t m_intensity;
00177 float m_radius;
00178 int m_subdivisions;
00179 float m_xstretch;
00180 float m_ystretch;
00181 uint8_t m_red;
00182 uint8_t m_green;
00183 uint8_t m_blue;
00184 int m_src;
00185 int m_dst;
00186 bool m_stencil;
00187 uint8_t m_stencil_ref;
00188 float m_alpha_ref;
00189 };
00190 class LightRendererResizeInfo : public LightRendererElementInfo {
00191 public:
00192 void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool);
00193 std::string getName() { return "resize"; };
00194 LightRendererNode* getNode() { return &m_anchor; };
00195 int getId() { return m_image; };
00196 int getSrcBlend() { return m_src; };
00197 int getDstBlend() { return m_dst; };
00198 void setStencil(uint8_t stencil_ref, float alpha_ref);
00199 int getStencil();
00200 float getAlpha();
00201 void removeStencil();
00202 LightRendererResizeInfo(LightRendererNode n, int image, int width, int height, int src, int dst);
00203 virtual ~LightRendererResizeInfo() {};
00204 private:
00205 LightRendererNode m_anchor;
00206 int m_image;
00207 int m_width;
00208 int m_height;
00209 int m_src;
00210 int m_dst;
00211 bool m_stencil;
00212 uint8_t m_stencil_ref;
00213 float m_alpha_ref;
00214 };
00215 class LightRenderer: public RendererBase {
00216 public:
00221 LightRenderer(RenderBackend* renderbackend, int position, ImagePool* imagepool, AnimationPool* animpool);
00222
00223 LightRenderer(const LightRenderer& old);
00224
00225 RendererBase* clone();
00226
00229 virtual ~LightRenderer();
00230 void render(Camera* cam, Layer* layer, RenderList& instances);
00231 std::string getName() { return "LightRenderer"; }
00232
00235 static LightRenderer* getInstance(IRendererContainer* cnt);
00236
00237 void addImage(const std::string &group, LightRendererNode n, int image, int src=-1, int dst=-1);
00238 void addAnimation(const std::string &group, LightRendererNode n, int animation, int src=-1, int dst=-1);
00239 void addSimpleLight(const std::string &group, LightRendererNode n, uint8_t intensity, float radius, int subdivisions, float xstretch, float ystretch, uint8_t r, uint8_t g, uint8_t b, int src=-1, int dst=-1);
00240 void resizeImage(const std::string &group, LightRendererNode n, int image, int width, int height, int src=-1, int dst=-1);
00241 void addStencilTest(const std::string &group, uint8_t stencil_ref=0, float alpha_ref=0.0);
00242 void removeStencilTest(const std::string &group);
00243 std::list<std::string> getGroups();
00244 std::vector<LightRendererElementInfo*> getLightInfo(const std::string &group);
00245 void removeAll(const std::string &group);
00246
00247 private:
00248 ImagePool* m_imagepool;
00249 AnimationPool* m_animationpool;
00250 std::map<std::string, std::vector<LightRendererElementInfo*> > m_groups;
00251 };
00252
00253 }
00254
00255 #endif