Ocean
Loading...
Searching...
No Matches
GLESTraverser.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_RENDERING_GLES_TRAVERSER_H
9#define META_OCEAN_RENDERING_GLES_TRAVERSER_H
10
17
20
23
24namespace Ocean
25{
26
27namespace Rendering
28{
29
30namespace GLESceneGraph
31{
32
33/**
34 * This class implements a traverser for renderables.
35 * Each renderable which is supposed to be renderd in the next frame is managed inside this traverser.
36 * @ingroup renderinggles
37 */
38class OCEAN_RENDERING_GLES_EXPORT GLESTraverser
39{
40 protected:
41
42 /**
43 * This class stores the data which is necessary to render one renderable.
44 */
46 {
47 public:
48
49 /**
50 * Creates a new traverser object.
51 * @param renderable The renderable to be added, must be valid
52 * @param attributeSet The attribute set which is connected with the renderable, must be valid
53 * @param camera_T_renderable The transformation between the renderable and the camera, must be valid
54 * @param normalMatrix The normal transformation matrix with is the transposed inverse of the upper 3x3 model view matrix
55 * @param lights The lights used the render this renderable, can be empty
56 */
57 inline TraverserObject(const RenderableRef& renderable, const AttributeSetRef& attributeSet, const HomogenousMatrix4& camera_T_renderable, const SquareMatrix3& normalMatrix, const Lights& lights);
58
59 /**
60 * Renders all elements which have been gathered.
61 * @param framebuffer The framebuffer in which the objects are rendered
62 * @param projection The projection matrix to be used, must be valid
63 * @param camera_T_world The transformation between world and camera, must be valid
64 */
65 inline void render(const GLESFramebuffer& framebuffer, const SquareMatrix4& projection, const HomogenousMatrix4& camera_T_world) const;
66
67 /**
68 * Renders all elements which have been gathered.
69 * @param projection The projection matrix to be used, must be valid
70 * @param camera_T_world The transformation between world and camera, must be valid
71 * @param shaderProgram The shader program to use for all objects
72 */
73 inline void render(const SquareMatrix4& projection, const HomogenousMatrix4& camera_T_world, GLESShaderProgram& shaderProgram) const;
74
75 /**
76 * Returns the renderable of this traverser object.
77 * @return The object's renderable
78 */
79 inline const SmartObjectRef<GLESRenderable>& renderable() const;
80
81 /**
82 * Returns whether the distance of the left object is closer to the camera than the right object.
83 * @param left The left traverser object to compare
84 * @param right The right traverser object to compare
85 * @return True, if so
86 */
87 static inline bool compareDistance(const TraverserObject& left, const TraverserObject& right);
88
89 protected:
90
91 /// The renderable object.
93
94 /// The attribute set which is connected with the renderable.
96
97 /// The transformation between the renderable and the camera.
99
100 /// The normal transformation matrix with is the transposed inverse of the upper 3x3 model view matrix.
102
103 /// The lights used the render this renderable.
105 };
106
107 /**
108 * Definition of a vector holding traverser objects.
109 */
110 typedef std::vector<TraverserObject> TraverserObjects;
111
112 public:
113
114 /**
115 * Creates a traverser object.
116 */
117 GLESTraverser() = default;
118
119 /**
120 * Renders all gathered elements.
121 * @param framebuffer The framebuffer in which the objects are rendered
122 * @param projection The projection matrix to be used, must be valid
123 * @param camera_T_world The transformation between world and camera, must be valid
124 */
125 void render(const GLESFramebuffer& framebuffer, const SquareMatrix4& projection, const HomogenousMatrix4& camera_T_world);
126
127 /**
128 * Renders all gathered elements with an individual color id.
129 * @param engine The rendering object to be used
130 * @param projection The projection matrix to be used, must be valid
131 * @param camera_T_world The transformation between world and camera, must be valid
132 */
133 void renderColorIds(const Engine& engine, const SquareMatrix4& projection, const HomogenousMatrix4& camera_T_world);
134
135 /**
136 * Adds a new renderable to this traverser.
137 * @param renderable The renderable to be added, must be valid
138 * @param attributeSet The attribute set which is connected with the renderable, must be valid
139 * @param camera_T_renderable The transformation between the renderable and the camera, must be valid
140 * @param normalMatrix The normal transformation matrix with is the transposed inverse of the upper 3x3 model view matrix
141 * @param lights The lights used the render this renderable, can be empty
142 */
143 void addRenderable(const RenderableRef& renderable, const AttributeSetRef& attributeSet, const HomogenousMatrix4& camera_T_renderable, const SquareMatrix3& normalMatrix, const Lights& lights);
144
145 /**
146 * Lookups the renderable which has been rendered with a given color id.
147 * This function needs to be called after renderColorIds().
148 * @param colorId The id for which the renderable will be returned
149 * @return The renderable, invalid if not corresponding renderable exists
150 */
151 RenderableRef renderableFromColorId(const uint32_t colorId) const;
152
153 /**
154 * Removes all gathered renderables from this traverser.
155 */
156 void clear();
157
158 protected:
159
160 /// The renderable object with depth attribute.
162
163 /// The renderable object with depth and blend attributes.
165
166 /// The renderable object with blend attribute.
168
169 /// The shader able to render objects with individual color ids.
171};
172
173inline GLESTraverser::TraverserObject::TraverserObject(const RenderableRef& renderable, const AttributeSetRef& attributeSet, const HomogenousMatrix4& camera_T_renderable, const SquareMatrix3& normalMatrix, const Lights& lights) :
174 renderable_(renderable),
175 attributeSet_(attributeSet),
176 camera_T_renderable_(camera_T_renderable),
177 normalMatrix_(normalMatrix),
178 lights_(lights)
179{
180 // nothing to do here
181}
182
183inline void GLESTraverser::TraverserObject::render(const GLESFramebuffer& framebuffer, const SquareMatrix4& projection, const HomogenousMatrix4& camera_T_world) const
184{
185 ocean_assert(!projection.isSingular());
186 ocean_assert(renderable_ && attributeSet_);
187
188 renderable_->render(framebuffer, projection, camera_T_renderable_, camera_T_world, normalMatrix_, *attributeSet_, lights_);
189}
190
191inline void GLESTraverser::TraverserObject::render(const SquareMatrix4& projection, const HomogenousMatrix4& camera_T_world, GLESShaderProgram& shaderProgram) const
192{
193 ocean_assert(!projection.isSingular());
194 ocean_assert(renderable_);
195
196 renderable_->render(projection, camera_T_renderable_, camera_T_world, normalMatrix_, shaderProgram);
197}
198
200{
201 return renderable_;
202}
203
208
209}
210
211}
212
213}
214
215#endif // META_OCEAN_RENDERING_GLES_NODE_H
VectorT3< T > translation() const
Returns the translation of the transformation.
Definition HomogenousMatrix4.h:1381
This class is the base class for all rendering engines like.
Definition Engine.h:46
This class implements a base for all GLESceneGraph framebuffers.
Definition rendering/glescenegraph/GLESFramebuffer.h:34
This class implements a container for an OpenGL ES shader program.
Definition GLESShaderProgram.h:53
This class stores the data which is necessary to render one renderable.
Definition GLESTraverser.h:46
HomogenousMatrix4 camera_T_renderable_
The transformation between the renderable and the camera.
Definition GLESTraverser.h:98
void render(const GLESFramebuffer &framebuffer, const SquareMatrix4 &projection, const HomogenousMatrix4 &camera_T_world) const
Renders all elements which have been gathered.
Definition GLESTraverser.h:183
const SmartObjectRef< GLESRenderable > & renderable() const
Returns the renderable of this traverser object.
Definition GLESTraverser.h:199
static bool compareDistance(const TraverserObject &left, const TraverserObject &right)
Returns whether the distance of the left object is closer to the camera than the right object.
Definition GLESTraverser.h:204
Lights lights_
The lights used the render this renderable.
Definition GLESTraverser.h:104
TraverserObject(const RenderableRef &renderable, const AttributeSetRef &attributeSet, const HomogenousMatrix4 &camera_T_renderable, const SquareMatrix3 &normalMatrix, const Lights &lights)
Creates a new traverser object.
Definition GLESTraverser.h:173
SmartObjectRef< GLESAttributeSet > attributeSet_
The attribute set which is connected with the renderable.
Definition GLESTraverser.h:95
SquareMatrix3 normalMatrix_
The normal transformation matrix with is the transposed inverse of the upper 3x3 model view matrix.
Definition GLESTraverser.h:101
SmartObjectRef< GLESRenderable > renderable_
The renderable object.
Definition GLESTraverser.h:92
This class implements a traverser for renderables.
Definition GLESTraverser.h:39
TraverserObjects depthTraverserObjects_
The renderable object with depth attribute.
Definition GLESTraverser.h:161
void render(const GLESFramebuffer &framebuffer, const SquareMatrix4 &projection, const HomogenousMatrix4 &camera_T_world)
Renders all gathered elements.
std::vector< TraverserObject > TraverserObjects
Definition of a vector holding traverser objects.
Definition GLESTraverser.h:110
void clear()
Removes all gathered renderables from this traverser.
void addRenderable(const RenderableRef &renderable, const AttributeSetRef &attributeSet, const HomogenousMatrix4 &camera_T_renderable, const SquareMatrix3 &normalMatrix, const Lights &lights)
Adds a new renderable to this traverser.
TraverserObjects blendTraverserObjects_
The renderable object with blend attribute.
Definition GLESTraverser.h:167
TraverserObjects defaultTraverserObjects_
The renderable object with depth and blend attributes.
Definition GLESTraverser.h:164
GLESTraverser()=default
Creates a traverser object.
GLESShaderProgramRef shaderProgramColorId_
The shader able to render objects with individual color ids.
Definition GLESTraverser.h:170
RenderableRef renderableFromColorId(const uint32_t colorId) const
Lookups the renderable which has been rendered with a given color id.
void renderColorIds(const Engine &engine, const SquareMatrix4 &projection, const HomogenousMatrix4 &camera_T_world)
Renders all gathered elements with an individual color id.
This class implements a smart rendering object reference.
Definition rendering/ObjectRef.h:34
bool isSingular() const
Returns whether this matrix is singular (and thus cannot be inverted).
Definition SquareMatrix4.h:1040
T sqr() const
Returns the square of the vector length.
Definition Vector3.h:682
std::vector< LightPair > Lights
Definition of a set holding light sources.
Definition GLESLightSource.h:44
The namespace covering the entire Ocean framework.
Definition Accessor.h:15