FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
lightrenderer.h
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
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_LIGHTRENDERER_H
23 #define FIFE_LIGHTRENDERER_H
24 
25 // Standard C++ library includes
26 #include <vector>
27 
28 // 3rd party library includes
29 
30 // FIFE includes
31 // These includes are split up in two parts, separated by one empty line
32 // First block: files included from the FIFE root src directory
33 // Second block: files included from the same folder
34 #include "view/rendererbase.h"
35 
36 namespace FIFE {
37  class RenderBackend;
38  class AbstractFont;
39  class ImagePool;
40  class AnimationPool;
41 
42  class LightRendererNode {
43  public:
44  LightRendererNode(Instance* attached_instance, const Location &relative_location, Layer* relative_layer, const Point &relative_point = Point(0,0));
45  LightRendererNode(Instance* attached_instance, const Location &relative_location, const Point &relative_point = Point(0,0));
46  LightRendererNode(Instance* attached_instance, Layer* relative_layer, const Point &relative_point = Point(0,0));
47  LightRendererNode(Instance* attached_instance, const Point &relative_point = Point(0,0));
48  LightRendererNode(const Location &attached_location, Layer* relative_layer, const Point &relative_point = Point(0,0));
49  LightRendererNode(const Location &attached_location, const Point &relative_point = Point(0,0));
50  LightRendererNode(Layer* attached_layer, const Point &relative_point = Point(0,0));
51  LightRendererNode(const Point &attached_point);
52  ~LightRendererNode();
53 
54  void setAttached(Instance* attached_instance, const Location &relative_location, const Point &relative_point);
55  void setAttached(Instance* attached_instance, const Location &relative_location);
56  void setAttached(Instance* attached_instance, const Point &relative_point);
57  void setAttached(Instance* attached_instance);
58  void setAttached(const Location &attached_location, const Point &relative_point);
59  void setAttached(const Location &attached_location);
60  void setAttached(Layer* attached_layer);
61  void setAttached(const Point &attached_point);
62 
63  void setRelative(const Location &relative_location);
64  void setRelative(const Location &relative_location, Point relative_point);
65  void setRelative(const Point &relative_point);
66 
67  Instance* getAttachedInstance();
68  Location getAttachedLocation();
69  Layer* getAttachedLayer();
70  Point getAttachedPoint();
71 
72  Location getOffsetLocation();
73  Point getOffsetPoint();
74 
75  Instance* getInstance();
76  Location getLocation();
77  Layer* getLayer();
78  Point getPoint();
79 
80  Point getCalculatedPoint(Camera* cam, Layer* layer);
81  private:
82  Instance* m_instance;
83  Location m_location;
84  Layer* m_layer;
85  Point m_point;
86  };
87 
88  class LightRendererElementInfo {
89  public:
90  virtual void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {};
91  virtual std::string getName() { return 0; };
92  virtual LightRendererNode* getNode() { return NULL; };
93  virtual int getId() { return -1; };
94  virtual int getSrcBlend() { return -1; };
95  virtual int getDstBlend() { return -1; };
96  virtual void setStencil(uint8_t stencil_ref, float alpha_ref) {};
97  virtual int getStencil() { return 0; };
98  virtual float getAlpha() { return 0; };
99  virtual void removeStencil() {};
100  virtual std::vector<uint8_t> getColor() { return std::vector<uint8_t>(); };
101  virtual float getRadius() { return 0; };
102  virtual int getSubdivisions() { return 0; };
103  virtual float getXStretch() { return 0; };
104  virtual float getYStretch() { return 0; };
105  virtual ~LightRendererElementInfo() {};
106  };
107 
108  class LightRendererImageInfo : public LightRendererElementInfo {
109  public:
110  void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool);
111  std::string getName() { return "image"; };
112  LightRendererNode* getNode() { return &m_anchor; };
113  int getId() { return m_image; };
114  int getSrcBlend() { return m_src; };
115  int getDstBlend() { return m_dst; };
116  void setStencil(uint8_t stencil_ref, float alpha_ref);
117  int getStencil();
118  float getAlpha();
119  void removeStencil();
120  LightRendererImageInfo(LightRendererNode n, int image, int src, int dst);
121  virtual ~LightRendererImageInfo() {};
122  private:
123  LightRendererNode m_anchor;
124  int m_image;
125  int m_src;
126  int m_dst;
127  bool m_stencil;
128  uint8_t m_stencil_ref;
129  float m_alpha_ref;
130  };
131  class LightRendererAnimationInfo : public LightRendererElementInfo {
132  public:
133  void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool);
134  std::string getName() { return "animation"; };
135  LightRendererNode* getNode() { return &m_anchor; };
136  int getId() { return m_animation; };
137  int getSrcBlend() { return m_src; };
138  int getDstBlend() { return m_dst; };
139  void setStencil(uint8_t stencil_ref, float alpha_ref);
140  int getStencil();
141  float getAlpha();
142  void removeStencil();
143  LightRendererAnimationInfo(LightRendererNode n, int animation, int src, int dst);
144  virtual ~LightRendererAnimationInfo() {};
145  private:
146  LightRendererNode m_anchor;
147  int m_animation;
148  int m_src;
149  int m_dst;
150  unsigned int m_start_time;
151  float m_time_scale;
152  bool m_stencil;
153  uint8_t m_stencil_ref;
154  float m_alpha_ref;
155  };
156  class LightRendererSimpleLightInfo : public LightRendererElementInfo {
157  public:
158  void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool);
159  std::string getName() { return "simple"; };
160  LightRendererNode* getNode() { return &m_anchor; };
161  int getSrcBlend() { return m_src; };
162  int getDstBlend() { return m_dst; };
163  void setStencil(uint8_t stencil_ref, float alpha_ref);
164  int getStencil();
165  float getAlpha();
166  void removeStencil();
167  std::vector<uint8_t> getColor();
168  float getRadius() { return m_radius; };
169  int getSubdivisions() { return m_subdivisions; };
170  float getXStretch() { return m_xstretch; };
171  float getYStretch() { return m_ystretch; };
172  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);
173  virtual ~LightRendererSimpleLightInfo() {};
174  private:
175  LightRendererNode m_anchor;
176  uint8_t m_intensity;
177  float m_radius;
178  int m_subdivisions;
179  float m_xstretch;
180  float m_ystretch;
181  uint8_t m_red;
182  uint8_t m_green;
183  uint8_t m_blue;
184  int m_src;
185  int m_dst;
186  bool m_stencil;
187  uint8_t m_stencil_ref;
188  float m_alpha_ref;
189  };
190  class LightRendererResizeInfo : public LightRendererElementInfo {
191  public:
192  void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool);
193  std::string getName() { return "resize"; };
194  LightRendererNode* getNode() { return &m_anchor; };
195  int getId() { return m_image; };
196  int getSrcBlend() { return m_src; };
197  int getDstBlend() { return m_dst; };
198  void setStencil(uint8_t stencil_ref, float alpha_ref);
199  int getStencil();
200  float getAlpha();
201  void removeStencil();
202  LightRendererResizeInfo(LightRendererNode n, int image, int width, int height, int src, int dst);
203  virtual ~LightRendererResizeInfo() {};
204  private:
205  LightRendererNode m_anchor;
206  int m_image;
207  int m_width;
208  int m_height;
209  int m_src;
210  int m_dst;
211  bool m_stencil;
212  uint8_t m_stencil_ref;
213  float m_alpha_ref;
214  };
215  class LightRenderer: public RendererBase {
216  public:
221  LightRenderer(RenderBackend* renderbackend, int position, ImagePool* imagepool, AnimationPool* animpool);
222 
223  LightRenderer(const LightRenderer& old);
224 
225  RendererBase* clone();
226 
229  virtual ~LightRenderer();
230  void render(Camera* cam, Layer* layer, RenderList& instances);
231  std::string getName() { return "LightRenderer"; }
232 
235  static LightRenderer* getInstance(IRendererContainer* cnt);
236 
237  void addImage(const std::string &group, LightRendererNode n, int image, int src=-1, int dst=-1);
238  void addAnimation(const std::string &group, LightRendererNode n, int animation, int src=-1, int dst=-1);
239  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);
240  void resizeImage(const std::string &group, LightRendererNode n, int image, int width, int height, int src=-1, int dst=-1);
241  void addStencilTest(const std::string &group, uint8_t stencil_ref=0, float alpha_ref=0.0);
242  void removeStencilTest(const std::string &group);
243  std::list<std::string> getGroups();
244  std::vector<LightRendererElementInfo*> getLightInfo(const std::string &group);
245  void removeAll(const std::string &group);
246 
247  private:
248  ImagePool* m_imagepool;
249  AnimationPool* m_animationpool;
250  std::map<std::string, std::vector<LightRendererElementInfo*> > m_groups;
251  };
252 
253 }
254 
255 #endif