Debian Codegraph @

engine/core/view/renderers/lightrenderer.h

raw
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_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 "model/structures/renderernode.h"
35 #include "view/rendererbase.h"
36 #include "video/animation.h"
37
38 namespace FIFE {
39 class RenderBackend;
40 class IFont;
41
42 class LightRendererElementInfo {
43 public:
44 LightRendererElementInfo(RendererNode n, int32_t src, int32_t dst);
45 virtual ~LightRendererElementInfo() {};
46
47 virtual void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend) = 0;
48 virtual std::string getName() = 0;
49
50 RendererNode* getNode() { return &m_anchor; };
51 int32_t getSrcBlend() { return m_src; };
52 int32_t getDstBlend() { return m_dst; };
53
54 void setStencil(uint8_t stencil_ref);
55 int32_t getStencil();
56 void removeStencil();
57
58 virtual std::vector<uint8_t> getColor() { return std::vector<uint8_t>(); };
59 virtual float getRadius() { return 0; };
60 virtual int32_t getSubdivisions() { return 0; };
61 virtual float getXStretch() { return 0; };
62 virtual float getYStretch() { return 0; };
63
64 protected:
65 RendererNode m_anchor;
66 int32_t m_src;
67 int32_t m_dst;
68 bool m_stencil;
69 uint8_t m_stencil_ref;
70 };
71
72 class LightRendererImageInfo : public LightRendererElementInfo {
73 public:
74 LightRendererImageInfo(RendererNode n, ImagePtr image, int32_t src, int32_t dst);
75 virtual ~LightRendererImageInfo() {};
76
77 virtual void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
78 virtual std::string getName() { return "image"; };
79 ImagePtr getImage() { return m_image; };
80
81 private:
82 ImagePtr m_image;
83 };
84
85 class LightRendererAnimationInfo : public LightRendererElementInfo {
86 public:
87 LightRendererAnimationInfo(RendererNode n, AnimationPtr animation, int32_t src, int32_t dst);
88 virtual ~LightRendererAnimationInfo() {};
89
90 virtual void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
91 virtual std::string getName() { return "animation"; };
92 AnimationPtr getAnimation() { return m_animation; };
93
94 private:
95 AnimationPtr m_animation;
96 uint32_t m_start_time;
97 float m_time_scale;
98 };
99
100 class LightRendererSimpleLightInfo : public LightRendererElementInfo {
101 public:
102 LightRendererSimpleLightInfo(RendererNode n, uint8_t intensity, float radius, int32_t subdivisions, float xstretch, float ystretch, uint8_t r, uint8_t g, uint8_t b, int32_t src, int32_t dst);
103 virtual ~LightRendererSimpleLightInfo() {};
104
105 virtual void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
106 virtual std::string getName() { return "simple"; };
107
108 std::vector<uint8_t> getColor();
109 float getRadius() { return m_radius; };
110 int32_t getSubdivisions() { return m_subdivisions; };
111 float getXStretch() { return m_xstretch; };
112 float getYStretch() { return m_ystretch; };
113
114 private:
115 uint8_t m_intensity;
116 float m_radius;
117 int32_t m_subdivisions;
118 float m_xstretch;
119 float m_ystretch;
120 uint8_t m_red;
121 uint8_t m_green;
122 uint8_t m_blue;
123 };
124
125 class LightRendererResizeInfo : public LightRendererElementInfo {
126 public:
127 LightRendererResizeInfo(RendererNode n, ImagePtr image, int32_t width, int32_t height, int32_t src, int32_t dst);
128 virtual ~LightRendererResizeInfo() {};
129
130 virtual void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
131 virtual std::string getName() { return "resize"; };
132
133 ImagePtr getImage() { return m_image; };
134
135 private:
136 ImagePtr m_image;
137 int32_t m_width;
138 int32_t m_height;
139 };
140
141 class LightRenderer: public RendererBase {
142 public:
143 /** constructor.
144 * @param renderbackend to use
145 * @param position position for this renderer in rendering pipeline
146 */
147 LightRenderer(RenderBackend* renderbackend, int32_t position);
148
149 LightRenderer(const LightRenderer& old);
150
151 RendererBase* clone();
152
153 /** Destructor.
154 */
155 virtual ~LightRenderer();
156 void render(Camera* cam, Layer* layer, RenderList& instances);
157 std::string getName() { return "LightRenderer"; }
158
159 /** Gets instance for interface access
160 */
161 static LightRenderer* getInstance(IRendererContainer* cnt);
162
163 void addImage(const std::string &group, RendererNode n, ImagePtr image, int32_t src=-1, int32_t dst=-1);
164 void addAnimation(const std::string &group, RendererNode n, AnimationPtr animation, int32_t src=-1, int32_t dst=-1);
165 void addSimpleLight(const std::string &group, RendererNode n, uint8_t intensity, float radius, int32_t subdivisions, float xstretch, float ystretch, uint8_t r, uint8_t g, uint8_t b, int32_t src=-1, int32_t dst=-1);
166 void resizeImage(const std::string &group, RendererNode n, ImagePtr image, int32_t width, int32_t height, int32_t src=-1, int32_t dst=-1);
167 void addStencilTest(const std::string &group, uint8_t stencil_ref=0);
168 void removeStencilTest(const std::string &group);
169 std::list<std::string> getGroups();
170 std::vector<LightRendererElementInfo*> getLightInfo(const std::string &group);
171 void removeAll(const std::string &group);
172 void removeAll();
173 void reset();
174
175 private:
176 std::map<std::string, std::vector<LightRendererElementInfo*> > m_groups;
177 };
178
179 }
180
181 #endif