OpenClonk
C4LandscapeRender.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 
17 #ifndef C4LANDSCAPE_RENDER_H
18 #define C4LANDSCAPE_RENDER_H
19 
21 #include "graphics/C4FacetEx.h"
22 #include "graphics/C4Shader.h"
23 #include "graphics/C4Surface.h"
24 
25 #include <chrono>
26 
27 // Data we want to store per landscape pixel
28 enum C4LR_Byte {
34 
36 };
37 
38 // Uniform data we give the shader (constants from its viewpoint)
39 // Don't forget to update GetUniformName when introducing new uniforms!
41 {
43 
49 
59 
62 
64 };
65 
67 {
71 
73 };
74 
75 // How much data we want to store per landscape pixel
76 const int C4LR_BytesPerPx = 3;
77 
78 // How much data we can hold per surface, how much surfaces we therefore need.
79 const int C4LR_BytesPerSurface = 4;
81 
82 class C4Landscape; class C4TextureMap;
83 
85 {
86 public:
87  C4LandscapeRender() = default;
88  virtual ~C4LandscapeRender() = default;
89 
90 protected:
91  int32_t iWidth{0}, iHeight{0};
92  C4TextureMap *pTexs{nullptr};
93 
94 public:
95 
96  virtual bool ReInit(int32_t iWidth, int32_t iHeight) = 0;
97  virtual bool Init(int32_t iWidth, int32_t iHeight, C4TextureMap *pTexs, C4GroupSet *pGraphics) = 0;
98  virtual void Clear() = 0;
99 
100  // Returns the rectangle of pixels that must be updated on changes in the given rect
101  virtual C4Rect GetAffectedRect(C4Rect Rect) = 0;
102 
103  // Updates the landscape rendering to reflect the landscape contents in
104  // the given rectangle
105  virtual void Update(C4Rect Rect, C4Landscape *pSource) = 0;
106 
107  virtual void Draw(const C4TargetFacet &cgo, const class C4FoWRegion *Light, uint32_t clrMod) = 0;
108 };
109 
110 #ifndef USE_CONSOLE
112 {
113 public:
115  ~C4LandscapeRenderGL() override;
116 
117 private:
118  // surfaces
119  C4Surface *Surfaces[C4LR_SurfaceCount];
120 
121  // shader
122  C4Shader Shader;
123  C4Shader ShaderLight;
124  static const char *UniformNames[];
125  // VBO for landscape vertex data
126  GLuint hVBO;
127  // VAO IDs for rendering landscape w/ and w/o light
128  unsigned int hVAOIDNoLight;
129  unsigned int hVAOIDLight;
130 
131  // 1D texture for material map
132  GLuint matMapTexture;
133  // 2D texture array of material textures
134  GLuint hMaterialTexture;
135  // material texture positions in texture array
136  std::vector<StdCopyStrBuf> MaterialTextureMap;
137  // depth of material texture in layers
138  int32_t iMaterialTextureDepth;
139  // size of material textures (unzoomed)
140  int32_t iMaterialWidth, iMaterialHeight;
141 
142  // scaler image
143  C4FacetSurface fctScaler;
144 
145  // shader timer
146  std::chrono::time_point<std::chrono::steady_clock> TimerStart;
147 
148 public:
149  bool ReInit(int32_t iWidth, int32_t iHeight) override;
150  bool Init(int32_t iWidth, int32_t iHeight, C4TextureMap *pMap, C4GroupSet *pGraphics) override;
151  void Clear() override;
152 
153  C4Rect GetAffectedRect(C4Rect Rect) override;
154  void Update(C4Rect Rect, C4Landscape *pSource) override;
155 
156  void Draw(const C4TargetFacet &cgo, const C4FoWRegion *Light, uint32_t clrMod) override;
157 
158 private:
159  bool InitLandscapeTexture();
160  bool InitMaterialTexture(C4TextureMap *pMap);
161  bool LoadShader(C4GroupSet *pGraphics, C4Shader& shader, const char* name, int ssc);
162  bool LoadShaders(C4GroupSet *pGraphics);
163  bool InitVBO();
164  void ClearShaders();
165  bool LoadScaler(C4GroupSet *pGraphics);
166 
167  int CalculateScalerBitmask(int x, int y, C4Rect To, C4Landscape *pSource);
168 
169  int32_t LookupTextureTransition(const char *szFrom, const char *szTo);
170  void AddTextureTransition(const char *szFrom, const char *szTo);
171  void AddTextureAnim(const char *szTextureAnim);
172  void AddTexturesFromMap(C4TextureMap *pMap);
173  void BuildMatMap(uint32_t *pTex);
174 };
175 #endif
176 
177 #endif // C4LANDSCAPE_RENDER_H
const int C4LR_SurfaceCount
C4LR_Byte
@ C4LR_BiasX
@ C4LR_Scaler
@ C4LR_Place
@ C4LR_ByteCount
@ C4LR_Material
@ C4LR_BiasY
C4LR_Uniforms
@ C4LRU_ScalerTex
@ C4LRU_AmbientTransform
@ C4LRU_Modulation
@ C4LRU_AmbientBrightness
@ C4LRU_LightTex
@ C4LRU_Gamma
@ C4LRU_AmbientTex
@ C4LRU_ProjectionMatrix
@ C4LRU_MaterialDepth
@ C4LRU_FrameCounter
@ C4LRU_LandscapeTex
@ C4LRU_Time
@ C4LRU_Resolution
@ C4LRU_MaterialSize
@ C4LRU_Count
@ C4LRU_MaterialTex
@ C4LRU_Center
@ C4LRU_MatMapTex
const int C4LR_BytesPerSurface
const int C4LR_BytesPerPx
C4LR_Attributes
@ C4LRA_Position
@ C4LRA_LandscapeTexCoord
@ C4LRA_Count
@ C4LRA_LightTexCoord
C4Rect GetAffectedRect(C4Rect Rect) override
bool ReInit(int32_t iWidth, int32_t iHeight) override
void Draw(const C4TargetFacet &cgo, const C4FoWRegion *Light, uint32_t clrMod) override
void Update(C4Rect Rect, C4Landscape *pSource) override
bool Init(int32_t iWidth, int32_t iHeight, C4TextureMap *pMap, C4GroupSet *pGraphics) override
virtual bool ReInit(int32_t iWidth, int32_t iHeight)=0
C4LandscapeRender()=default
virtual C4Rect GetAffectedRect(C4Rect Rect)=0
virtual bool Init(int32_t iWidth, int32_t iHeight, C4TextureMap *pTexs, C4GroupSet *pGraphics)=0
virtual ~C4LandscapeRender()=default
C4TextureMap * pTexs
virtual void Update(C4Rect Rect, C4Landscape *pSource)=0
virtual void Draw(const C4TargetFacet &cgo, const class C4FoWRegion *Light, uint32_t clrMod)=0
virtual void Clear()=0
Definition: C4Rect.h:28