OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 // Data we want to store per landscape pixel
26 enum C4LR_Byte {
32 
34 };
35 
36 // Uniform data we give the shader (constants from its viewpoint)
37 // Don't forget to update GetUniformName when introducing new uniforms!
39 {
41 
47 
57 
59 };
60 
62 {
66 
68 };
69 
70 // How much data we want to store per landscape pixel
71 const int C4LR_BytesPerPx = 3;
72 
73 // How much data we can hold per surface, how much surfaces we therefore need.
74 const int C4LR_BytesPerSurface = 4;
76 
77 class C4Landscape; class C4TextureMap;
78 
80 {
81 public:
82  C4LandscapeRender() = default;
83  virtual ~C4LandscapeRender() = default;
84 
85 protected:
86  int32_t iWidth{0}, iHeight{0};
87  C4TextureMap *pTexs{nullptr};
88 
89 public:
90 
91  virtual bool ReInit(int32_t iWidth, int32_t iHeight) = 0;
92  virtual bool Init(int32_t iWidth, int32_t iHeight, C4TextureMap *pTexs, C4GroupSet *pGraphics) = 0;
93  virtual void Clear() = 0;
94 
95  // Returns the rectangle of pixels that must be updated on changes in the given rect
96  virtual C4Rect GetAffectedRect(C4Rect Rect) = 0;
97 
98  // Updates the landscape rendering to reflect the landscape contents in
99  // the given rectangle
100  virtual void Update(C4Rect Rect, C4Landscape *pSource) = 0;
101 
102  virtual void Draw(const C4TargetFacet &cgo, const class C4FoWRegion *Light, uint32_t clrMod) = 0;
103 };
104 
105 #ifndef USE_CONSOLE
107 {
108 public:
110  ~C4LandscapeRenderGL() override;
111 
112 private:
113  // surfaces
114  C4Surface *Surfaces[C4LR_SurfaceCount];
115 
116  // shader
117  C4Shader Shader;
118  C4Shader ShaderLight;
119  static const char *UniformNames[];
120  // VBO for landscape vertex data
121  GLuint hVBO;
122  // VAO IDs for rendering landscape w/ and w/o light
123  unsigned int hVAOIDNoLight;
124  unsigned int hVAOIDLight;
125 
126  // 1D texture for material map
127  GLuint matMapTexture;
128  // 2D texture array of material textures
129  GLuint hMaterialTexture;
130  // material texture positions in texture array
131  std::vector<StdCopyStrBuf> MaterialTextureMap;
132  // depth of material texture in layers
133  int32_t iMaterialTextureDepth;
134  // size of material textures (unzoomed)
135  int32_t iMaterialWidth, iMaterialHeight;
136 
137  // scaler image
138  C4FacetSurface fctScaler;
139 
140 public:
141  bool ReInit(int32_t iWidth, int32_t iHeight) override;
142  bool Init(int32_t iWidth, int32_t iHeight, C4TextureMap *pMap, C4GroupSet *pGraphics) override;
143  void Clear() override;
144 
145  C4Rect GetAffectedRect(C4Rect Rect) override;
146  void Update(C4Rect Rect, C4Landscape *pSource) override;
147 
148  void Draw(const C4TargetFacet &cgo, const C4FoWRegion *Light, uint32_t clrMod) override;
149 
150 private:
151  bool InitLandscapeTexture();
152  bool InitMaterialTexture(C4TextureMap *pMap);
153  bool LoadShader(C4GroupSet *pGraphics, C4Shader& shader, const char* name, int ssc);
154  bool LoadShaders(C4GroupSet *pGraphics);
155  bool InitVBO();
156  void ClearShaders();
157  bool LoadScaler(C4GroupSet *pGraphics);
158 
159  int CalculateScalerBitmask(int x, int y, C4Rect To, C4Landscape *pSource);
160 
161  int32_t LookupTextureTransition(const char *szFrom, const char *szTo);
162  void AddTextureTransition(const char *szFrom, const char *szTo);
163  void AddTextureAnim(const char *szTextureAnim);
164  void AddTexturesFromMap(C4TextureMap *pMap);
165  void BuildMatMap(uint32_t *pTex);
166 };
167 #endif
168 
169 #endif // C4LANDSCAPE_RENDER_H
C4LR_Attributes
C4LR_Byte
const int C4LR_SurfaceCount
virtual bool ReInit(int32_t iWidth, int32_t iHeight)=0
C4Rect GetAffectedRect(C4Rect Rect) override
virtual ~C4LandscapeRender()=default
Definition: C4Rect.h:27
virtual void Update(C4Rect Rect, C4Landscape *pSource)=0
void Draw(const C4TargetFacet &cgo, const C4FoWRegion *Light, uint32_t clrMod) override
const int C4LR_BytesPerPx
virtual void Clear()=0
C4LR_Uniforms
C4TextureMap * pTexs
const int C4LR_BytesPerSurface
void Update(C4Rect Rect, C4Landscape *pSource) override
bool ReInit(int32_t iWidth, int32_t iHeight) override
bool Init(int32_t iWidth, int32_t iHeight, C4TextureMap *pMap, C4GroupSet *pGraphics) override
virtual bool Init(int32_t iWidth, int32_t iHeight, C4TextureMap *pTexs, C4GroupSet *pGraphics)=0
virtual C4Rect GetAffectedRect(C4Rect Rect)=0
C4LandscapeRender()=default
virtual void Draw(const C4TargetFacet &cgo, const class C4FoWRegion *Light, uint32_t clrMod)=0