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/C4Surface.h"
22 #include "graphics/C4FacetEx.h"
23 #include "graphics/C4Shader.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:
83  : iWidth(0), iHeight(0), pTexs(nullptr) { }
85  {}
86 
87 protected:
88  int32_t iWidth, iHeight;
90 
91 public:
92 
93  virtual bool ReInit(int32_t iWidth, int32_t iHeight) = 0;
94  virtual bool Init(int32_t iWidth, int32_t iHeight, C4TextureMap *pTexs, C4GroupSet *pGraphics) = 0;
95  virtual void Clear() = 0;
96 
97  // Returns the rectangle of pixels that must be updated on changes in the given rect
98  virtual C4Rect GetAffectedRect(C4Rect Rect) = 0;
99 
100  // Updates the landscape rendering to reflect the landscape contents in
101  // the given rectangle
102  virtual void Update(C4Rect Rect, C4Landscape *pSource) = 0;
103 
104  virtual void Draw(const C4TargetFacet &cgo, const class C4FoWRegion *Light, uint32_t clrMod) = 0;
105 };
106 
107 #ifndef USE_CONSOLE
109 {
110 public:
113 
114 private:
115  // surfaces
116  C4Surface *Surfaces[C4LR_SurfaceCount];
117 
118  // shader
119  C4Shader Shader;
120  C4Shader ShaderLight;
121  static const char *UniformNames[];
122  // VBO for landscape vertex data
123  GLuint hVBO;
124  // VAO IDs for rendering landscape w/ and w/o light
125  unsigned int hVAOIDNoLight;
126  unsigned int hVAOIDLight;
127 
128  // 1D texture for material map
129  GLuint matMapTexture;
130  // 2D texture array of material textures
131  GLuint hMaterialTexture;
132  // material texture positions in texture array
133  std::vector<StdCopyStrBuf> MaterialTextureMap;
134  // depth of material texture in layers
135  int32_t iMaterialTextureDepth;
136  // size of material textures (unzoomed)
137  int32_t iMaterialWidth, iMaterialHeight;
138 
139  // scaler image
140  C4FacetSurface fctScaler;
141 
142 public:
143  virtual bool ReInit(int32_t iWidth, int32_t iHeight);
144  virtual bool Init(int32_t iWidth, int32_t iHeight, C4TextureMap *pMap, C4GroupSet *pGraphics);
145  virtual void Clear();
146 
147  virtual C4Rect GetAffectedRect(C4Rect Rect);
148  virtual void Update(C4Rect Rect, C4Landscape *pSource);
149 
150  virtual void Draw(const C4TargetFacet &cgo, const C4FoWRegion *Light, uint32_t clrMod);
151 
152 private:
153  bool InitLandscapeTexture();
154  bool InitMaterialTexture(C4TextureMap *pMap);
155  bool LoadShader(C4GroupSet *pGraphics, C4Shader& shader, const char* name, int ssc);
156  bool LoadShaders(C4GroupSet *pGraphics);
157  bool InitVBO();
158  void ClearShaders();
159  bool LoadScaler(C4GroupSet *pGraphics);
160 
161  int CalculateScalerBitmask(int x, int y, C4Rect To, C4Landscape *pSource);
162 
163  int32_t LookupTextureTransition(const char *szFrom, const char *szTo);
164  void AddTextureTransition(const char *szFrom, const char *szTo);
165  void AddTextureAnim(const char *szTextureAnim);
166  void AddTexturesFromMap(C4TextureMap *pMap);
167  void BuildMatMap(uint32_t *pTex);
168 };
169 #endif
170 
171 #endif // C4LANDSCAPE_RENDER_H
C4LR_Attributes
C4LR_Byte
const int C4LR_SurfaceCount
virtual bool ReInit(int32_t iWidth, int32_t iHeight)=0
virtual bool ReInit(int32_t iWidth, int32_t iHeight)
Definition: C4Rect.h:29
virtual void Update(C4Rect Rect, C4Landscape *pSource)=0
const int C4LR_BytesPerPx
virtual bool Init(int32_t iWidth, int32_t iHeight, C4TextureMap *pMap, C4GroupSet *pGraphics)
virtual void Clear()=0
C4LR_Uniforms
C4TextureMap * pTexs
const int C4LR_BytesPerSurface
virtual C4Rect GetAffectedRect(C4Rect Rect)
virtual bool Init(int32_t iWidth, int32_t iHeight, C4TextureMap *pTexs, C4GroupSet *pGraphics)=0
virtual void Update(C4Rect Rect, C4Landscape *pSource)
virtual ~C4LandscapeRender()
virtual void Draw(const C4TargetFacet &cgo, const C4FoWRegion *Light, uint32_t clrMod)
virtual C4Rect GetAffectedRect(C4Rect Rect)=0
virtual void Draw(const C4TargetFacet &cgo, const class C4FoWRegion *Light, uint32_t clrMod)=0