OpenClonk
C4FoW.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2014-2016, The OpenClonk Team and contributors
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 #ifndef C4FOW_H
17 #define C4FOW_H
18 
20 #include "graphics/C4FacetEx.h"
21 #include "graphics/C4Shader.h"
22 #include "graphics/C4Surface.h"
25 #include "lib/C4Rect.h"
26 #include "object/C4Object.h"
27 
33 {
34 public:
35  C4FragTransform() = default;
36 
37  // Multiplies from left
38  inline void Translate(float dx, float dy)
39  {
40  x0 += dx;
41  y0 += dy;
42  }
43 
44  // Multiplies from left
45  inline void Scale(float sx, float sy)
46  {
47  x *= sx;
48  y *= sy;
49 
50  x0 *= sx;
51  y0 *= sy;
52  }
53 
54  inline void Get2x3(float transform[6])
55  {
56  transform[0] = x;
57  transform[1] = 0.f;
58  transform[2] = x0;
59  transform[3] = 0.f;
60  transform[4] = y;
61  transform[5] = y0;
62  }
63 
64 private:
65  float x{1.0f}, y{1.0f};
66  float x0{0.0f}, y0{0.0f};
67 };
68 
70  C4FoWFSU_ProjectionMatrix, // projection matrix
71  C4FoWFSU_Texture, // source texture
72 
74 };
75 
79 
81 };
82 
84  C4FoWRSU_ProjectionMatrix, // projection matrix
85  C4FoWRSU_VertexOffset, // offset applied to vertex (TODO: could be encoded in projection matrix)
86 
88 };
89 
93 
95 };
96 
101 class C4FoW
102 {
103 public:
104  C4FoW();
105  ~C4FoW();
106 
107 private:
109  class C4FoWLight *pLights{nullptr};
110 
112  class C4FoWLight *deleted_lights{nullptr};
113 
114 public:
116 
117  // Shader to use for updating the frame buffer
119  // Shader to use for rendering the lights
121 
122  void ClearDeletedLights();
123 
125  void Add(C4Object *pObj);
127  void Remove(C4Object *pObj);
128 
130  void Update(C4Rect r, C4Player *player);
132  void Invalidate(C4Rect r);
133 
134  void Render(class C4FoWRegion *pRegion, const C4TargetFacet *pOnScreen, C4Player *pPlr, const StdProjectionMatrix& projectionMatrix);
135 
136 private:
137 #ifndef USE_CONSOLE
138  // Shader for updating the frame buffer
139  C4Shader FramebufShader;
140  C4Shader RenderShader;
141 #endif
142 };
143 
144 #endif // C4FOW_H
C4FoWRenderShaderUniforms
Definition: C4FoW.h:83
@ C4FoWRSU_ProjectionMatrix
Definition: C4FoW.h:84
@ C4FoWRSU_VertexOffset
Definition: C4FoW.h:85
@ C4FoWRSU_Count
Definition: C4FoW.h:87
C4FoWFramebufShaderUniforms
Definition: C4FoW.h:69
@ C4FoWFSU_Texture
Definition: C4FoW.h:71
@ C4FoWFSU_ProjectionMatrix
Definition: C4FoW.h:70
@ C4FoWFSU_Count
Definition: C4FoW.h:73
C4FoWRenderShaderAttributes
Definition: C4FoW.h:90
@ C4FoWRSA_Count
Definition: C4FoW.h:94
@ C4FoWRSA_Color
Definition: C4FoW.h:92
@ C4FoWRSA_Position
Definition: C4FoW.h:91
C4FoWFramebufShaderAttributes
Definition: C4FoW.h:76
@ C4FoWFSA_Position
Definition: C4FoW.h:77
@ C4FoWFSA_TexCoord
Definition: C4FoW.h:78
@ C4FoWFSA_Count
Definition: C4FoW.h:80
Definition: C4FoW.h:102
void Add(C4Object *pObj)
Definition: C4FoW.cpp:165
~C4FoW()
Definition: C4FoW.cpp:26
void Remove(C4Object *pObj)
Definition: C4FoW.cpp:201
C4Shader * GetFramebufShader()
Definition: C4FoW.cpp:47
void ClearDeletedLights()
Definition: C4FoW.cpp:34
C4FoWAmbient Ambient
Definition: C4FoW.h:115
C4Shader * GetRenderShader()
Definition: C4FoW.cpp:106
void Render(class C4FoWRegion *pRegion, const C4TargetFacet *pOnScreen, C4Player *pPlr, const StdProjectionMatrix &projectionMatrix)
Definition: C4FoW.cpp:238
void Invalidate(C4Rect r)
Definition: C4FoW.cpp:221
void Update(C4Rect r, C4Player *player)
Definition: C4FoW.cpp:229
void Scale(float sx, float sy)
Definition: C4FoW.h:45
void Get2x3(float transform[6])
Definition: C4FoW.h:54
C4FragTransform()=default
void Translate(float dx, float dy)
Definition: C4FoW.h:38
Definition: C4Rect.h:28