VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
TerrainShader.h
1 /*
2  * Copyright (C) 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef TERRAINSHADER_H
18 #define TERRAINSHADER_H
19 
20 #include <memory>
21 #include "TerrainMaterialDef.h"
22 #include "renderer/InstancedShader.h"
24 
37  bool hasEdge = false;
44  bool hasBevel = false;
50 
56  bool operator < (const TerrainShaderKey& other) const;
68 };
69 
70 class TerrainShader;
74 typedef std::shared_ptr<TerrainShader> TerrainShaderPtr;
75 
94 public:
99  explicit TerrainShader(const ShaderPtr& sharedShader);
100 
104  const TexturePtr& getBaseTexture() const { return mBaseTexture; }
110  void setBaseTexture(const TexturePtr& value);
114  const TexturePtr& getMaskTexture() const { return mMaskTexture; }
121  void setMaskTexture(const TexturePtr& value);
125  const TexturePtr& getBlendTexture() const { return mBlendTexture; }
132  void setBlendTexture(const TexturePtr& value);
133 
138  void setTransform(const Matrix4& matrix);
139 
147  static const ShaderPtr& getSharedShader(const TerrainShaderKey& shaderKey);
148 
149 protected:
153  virtual void updateState() override;
154 
155 private:
156  static void addShaderCodeDefines(const TerrainShaderKey& shaderKey, std::string& code);
157  static void initializeShaderMap();
158  static ShaderPtr createSharedShader(const TerrainShaderKey& shaderKey);
159 
160  static bool sShaderMapInitialized;
161  // Note: The data in this map is intentionally leaked. Used very late in rendering.
162  static QMap<TerrainShaderKey, ShaderPtr> sShaderMap;
163 
164  TexturePtr mBaseTexture;
165  TexturePtr mMaskTexture;
166  TexturePtr mBlendTexture;
167  Matrix4 mTransform;
168 
169  static const char* TERRAIN_SHADER_UNIFORMS[];
170  static const char* VERTEX_SHADER_PATH;
171  static const char* FRAGMENT_SHADER_PATH;
172 };
173 
174 #endif // TERRAINSHADER_H
TerrainShader(const ShaderPtr &sharedShader)
Construct a TerrainShader based on the given shared Shader.
Header declaring and including types common to renderer classes such as Vector2. Also includes GL hea...
void setBaseTexture(const TexturePtr &value)
Sets the base Texture.
Shader which has instanced values for uniforms and other GL state.
Definition: InstancedShader.h:46
bool operator<(const TerrainShaderKey &other) const
Less than operator for use with QMap.
TerrainMaterialDef::BlendMode blendMode
How the blend texture should be composited on to the base texture.
Definition: TerrainShader.h:49
InstancedShader which does a multi-texture blend between up to three Textures, to render terrain mesh...
Definition: TerrainShader.h:93
float Matrix4[16]
4x4 float matrix, whose layout is compatible with GL.
Definition: RendererCommon.h:46
bool hasEdge
Whether or not this shader renders edges.
Definition: TerrainShader.h:37
bool hasBevel
Whether or not this shader renders a bevel section.
Definition: TerrainShader.h:44
virtual void updateState() override
Implementation of InstancedShader::updateState().
const ShaderPtr & getSharedShader() const
Returns the Shader that is shared among instances.
Definition: InstancedShader.h:59
Selector key which picks the specific terrain shader variant to use.
Definition: TerrainShader.h:30
std::shared_ptr< Texture > TexturePtr
Shared pointer typedef for Texture.
Definition: PointerDeclarations.h:173
BlendMode
Blend modes used to mix the bevel texture with the base texture.
Definition: TerrainMaterialDef.h:47
std::shared_ptr< Shader > ShaderPtr
Shared pointer typedef for Shader.
Definition: PointerDeclarations.h:143
const TexturePtr & getBlendTexture() const
Returns the blend Texture.
Definition: TerrainShader.h:125
void setBlendTexture(const TexturePtr &value)
Sets the blend Texture.
TerrainShaderKey()
Construct an empty TerrainShaderKey with default values.
const TexturePtr & getBaseTexture() const
Returns the base Texture.
Definition: TerrainShader.h:104
void setMaskTexture(const TexturePtr &value)
Sets the mask Texture.
const TexturePtr & getMaskTexture() const
Returns the mask Texture.
Definition: TerrainShader.h:114
void setTransform(const Matrix4 &matrix)
Sets the transform to apply to vertices rendered with this Shader.