forked from cyberbotics/webots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenderable.hpp
133 lines (108 loc) · 5.1 KB
/
Renderable.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright 1996-2023 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef RENDERABLE_HPP
#define RENDERABLE_HPP
#include "Constants.hpp"
#include "GlslLayout.hpp"
#include "Node.hpp"
#include "Primitive.hpp"
#include <string>
#include <unordered_map>
#include <wren/renderable.h>
namespace wren {
class LightNode;
class Material;
class Mesh;
class ShaderProgram;
class ShadowVolumeCaster;
// Container class consisting of a Material, a Mesh and a drawing mode.
// Inherits from Node and can be attached to a Transform for positioning.
// During rendering, the Mesh's vertex coordinates are multiplied by the Transform's matrix.
class Renderable : public Node {
public:
// Encapsulate memory management
static Renderable *createRenderable() { return new Renderable(); }
static void setUseMaterial(const char *materialName) { Renderable::cUseMaterialName = materialName; }
static const char *useMaterial() { return Renderable::cUseMaterialName; }
void setDefaultMaterial(Material *material) { mDefaultMaterial = material; }
void setEffectiveMaterial(Material *material) { mEffectiveMaterial = material; }
void setOptionalMaterial(std::string name, Material *material) { mOptionalMaterials[name] = material; }
// To ensure a valid bounding sphere, only set a Mesh to a Renderable after having called Mesh::setup.
void setMesh(Mesh *mesh);
void setDrawingMode(WrRenderableDrawingMode drawingMode) { mDrawingMode = drawingMode; }
void setDrawingOrder(WrRenderableDrawingOrder drawingOrder) { mDrawingOrder = drawingOrder; }
void setVisibilityFlags(int flags) { mVisibilityFlags = flags; }
void setCastShadows(bool castShadows);
void setReceiveShadows(bool receiveShadows) { mReceiveShadows = receiveShadows; }
void setSceneCulling(bool culling) { mSceneCulling = culling; }
void setInViewSpace(bool inViewSpace) { mInViewSpace = inViewSpace; }
void setZSortedRendering(bool zSortedRendering) { mZSortedRendering = zSortedRendering; }
void setFaceCulling(bool faceCulling) { mFaceCulling = faceCulling; }
void setPointSize(float pointSize) { mPointSize = pointSize; }
void setInvertFrontFace(bool invertFrontFace) { mInvertFrontFace = invertFrontFace; }
const glm::mat4 &parentMatrix() const;
Material *defaultMaterial() const { return mDefaultMaterial; }
Material *effectiveMaterial() const { return mEffectiveMaterial; }
Material *optionalMaterial(const std::string &name) const;
Mesh *mesh() const { return mMesh; }
int visibilityFlags() const { return mVisibilityFlags; }
bool castShadows() const { return mCastShadows; }
bool receiveShadows() const { return mReceiveShadows; }
bool sceneCulling() const { return mSceneCulling; }
ShadowVolumeCaster *shadowVolumeCaster() { return mShadowVolumeCaster; }
WrRenderableDrawingMode drawingMode() const { return mDrawingMode; }
WrRenderableDrawingOrder drawingOrder() const { return mDrawingOrder; }
bool isInViewSpace() const { return mInViewSpace; }
bool zSortedRendering() const;
bool invertFrontFace() const { return mInvertFrontFace; }
void render(const ShaderProgram *program = NULL);
void renderWithoutMaterial(const ShaderProgram *program);
void recomputeBoundingSphereInViewSpace(const glm::mat4 &viewMatrix);
const primitive::Sphere &boundingSphereInViewSpace() const { return mBoundingSphereInViewSpace; }
bool isTranslucent() const;
size_t sortingId() const;
// Updates model matrix using parent transform
void updateFromParent() override;
const primitive::Aabb &aabb() override;
const primitive::Sphere &boundingSphere() const override;
void setMatrixDirty() const override;
private:
static const char *cUseMaterialName;
Renderable();
virtual ~Renderable();
void setupAndRender(const ShaderProgram *program);
void updateShadowVolumeCaster();
void computeMostInfluentialLights();
void recomputeAabb() const override;
void recomputeBoundingSphere() const override;
Material *mDefaultMaterial;
Material *mEffectiveMaterial;
std::unordered_map<std::string, Material *> mOptionalMaterials;
Mesh *mMesh;
ShadowVolumeCaster *mShadowVolumeCaster;
WrRenderableDrawingMode mDrawingMode;
WrRenderableDrawingOrder mDrawingOrder;
int mVisibilityFlags;
bool mCastShadows;
bool mReceiveShadows;
bool mSceneCulling;
bool mInViewSpace;
bool mZSortedRendering;
bool mFaceCulling;
bool mInvertFrontFace;
float mPointSize;
primitive::Sphere mBoundingSphereInViewSpace;
};
} // namespace wren
#endif // RENDERABLE_HPP