VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
TerrainMeshRenderer.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 TERRAINMESHRENDERER_H
18 #define TERRAINMESHRENDERER_H
19 
20 #include <memory>
21 #include "Graphic.h"
22 #include "TerrainMaterialDef.h"
23 #include "renderer/RenderNode.h"
25 
26 class PolygonMesh;
27 class QSGTexture;
28 class TerrainShader;
29 typedef std::shared_ptr<TerrainShader> TerrainShaderPtr;
30 
43 class TerrainMeshRenderer : public Graphic {
44  Q_OBJECT
45 
52  Q_PROPERTY(QString material READ getMaterial WRITE setMaterial NOTIFY materialChanged)
65 
66 public:
71  explicit TerrainMeshRenderer(QQuickItem* parent = nullptr);
72 
76  const QString& getMaterial() const { return mMaterialName; }
81  void setMaterial(const QString& value);
85  PolygonMesh* getBaseMesh() const { return mBaseMesh; }
90  void setBaseMesh(PolygonMesh* value);
94  PolygonMesh* getEdgeMesh() const { return mEdgeMesh; }
99  void setEdgeMesh(PolygonMesh* value);
103  PolygonMesh* getBevelMesh() const { return mBevelMesh; }
108  void setBevelMesh(PolygonMesh* value);
109 
110 signals:
114  void materialChanged();
118  void baseMeshChanged();
122  void edgeMeshChanged();
126  void bevelMeshChanged();
127 
128 protected:
129  virtual void synchronizeForRendering(RenderList* renderList) override;
130 
131 private:
132  void validate();
133  void updateRenderNode(const Matrix4& transform, float zDepth, const MeshInstancePtr& mesh,
134  const TerrainShaderPtr& shader, RenderNode* node, RenderList* renderList);
135  TerrainShaderPtr createShader(bool hasEdge, bool hasBevel,
137  MeshInstancePtr createRenderMesh(PolygonMesh* mesh, const TerrainShaderPtr& shader);
138 
139  QString mMaterialName;
140  bool mInvalidated = true;
141  PolygonMesh* mBaseMesh = nullptr;
142  PolygonMesh* mEdgeMesh = nullptr;
143  PolygonMesh* mBevelMesh = nullptr;
144  MeshInstancePtr mBaseRenderMesh;
145  MeshInstancePtr mEdgeRenderMesh;
146  MeshInstancePtr mBevelRenderMesh;
147  TerrainShaderPtr mBaseShader;
148  TerrainShaderPtr mEdgeShader;
149  TerrainShaderPtr mBevelShader;
150  RenderNode mBaseRenderNode;
151  RenderNode mEdgeRenderNode;
152  RenderNode mBevelRenderNode;
153  QPointF mRenderPos;
154  float mRenderRotation = 0.0f;
155 };
156 Q_DECLARE_METATYPE(TerrainMeshRenderer*)
157 
158 #endif // TERRAINMESHRENDERER_H
void setBevelMesh(PolygonMesh *value)
Sets the value of bevelMesh.
Header declaring and including types common to renderer classes such as Vector2. Also includes GL hea...
PolygonMesh * getBevelMesh() const
Returns the value of bevelMesh.
Definition: TerrainMeshRenderer.h:103
void baseMeshChanged()
Emitted when baseMesh changes.
Base class for visual elements which are part of the game scene, and are rendered through Renderer...
Definition: Graphic.h:34
InstancedShader which does a multi-texture blend between up to three Textures, to render terrain mesh...
Definition: TerrainShader.h:93
void setMaterial(const QString &value)
Sets the value of material.
float Matrix4[16]
4x4 float matrix, whose layout is compatible with GL.
Definition: RendererCommon.h:46
void setBaseMesh(PolygonMesh *value)
Sets the value of baseMesh.
QString material
Name of the TerrainMaterialDef to apply to this terrain mesh.
Definition: TerrainMeshRenderer.h:52
void setEdgeMesh(PolygonMesh *value)
Sets the value of edgeMesh.
Graphic which performs rendering of a terrain mesh.
Definition: TerrainMeshRenderer.h:43
Class storing a renderable mesh, instantiable from QML.
Definition: PolygonMesh.h:34
void materialChanged()
Emitted when material changes.
PolygonMesh * getBaseMesh() const
Returns the value of baseMesh.
Definition: TerrainMeshRenderer.h:85
virtual void synchronizeForRendering(RenderList *renderList) override
Synchronize this Graphic for rendering, adding any RenderNodes to renderList, and buffering any data ...
PolygonMesh bevelMesh
PolygonMesh containing vertex data for the bevel mesh.
Definition: TerrainMeshRenderer.h:64
BlendMode
Blend modes used to mix the bevel texture with the base texture.
Definition: TerrainMaterialDef.h:47
Node which queues a callback (RenderableInterface) or MeshInstance for rendering. ...
Definition: RenderNode.h:33
void bevelMeshChanged()
Emitted when bevelMesh changes.
std::shared_ptr< MeshInstance > MeshInstancePtr
Shared pointer typedef for MeshInstance.
Definition: PointerDeclarations.h:113
PolygonMesh baseMesh
PolygonMesh containing vertex data for the base mesh.
Definition: TerrainMeshRenderer.h:56
List of RenderNodes, sorted by z-depth for rendering.
Definition: RenderList.h:36
QObject * parent() const
PolygonMesh * getEdgeMesh() const
Returns the value of edgeMesh.
Definition: TerrainMeshRenderer.h:94
const QString & getMaterial() const
Returns material.
Definition: TerrainMeshRenderer.h:76
void edgeMeshChanged()
Emitted when edgeMesh changes.
PolygonMesh edgeMesh
PolygonMesh containing vertex data for the edge mesh.
Definition: TerrainMeshRenderer.h:60