Ocean
TrianglesManagerRenderer.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_TRACKING_MAPTEXTURING_TRIANGLES_MANAGER_RENDERER_H
9 #define META_OCEAN_TRACKING_MAPTEXTURING_TRIANGLES_MANAGER_RENDERER_H
10 
12 
13 #include "ocean/base/Accessor.h"
14 #include "ocean/base/Frame.h"
15 
17 
18 #include "ocean/rendering/Engine.h"
19 #include "ocean/rendering/Points.h"
25 
26 namespace Ocean
27 {
28 
29 namespace Tracking
30 {
31 
32 namespace MapTexturing
33 {
34 
35 /**
36  * This class implements a manager for active, textured, retired, and deleted triangles.
37  * The manager holds the states of the individual triangles in an own framebuffer.
38  * @ingroup trackingmaptexturing
39  */
40 class OCEAN_TRACKING_MAPTEXTURING_EXPORT TrianglesManagerRenderer
41 {
42  public:
43 
44  /**
45  * Destructs this renderer and releases all resources.
46  */
48 
49  /**
50  * Initializes the manager.
51  * @param engine The rendering engine to be used
52  * @param framebufferWidth The width of the framebuffer, in pixel, with range [1, infinity)
53  * @param framebufferHeight The height of the framebuffer, in pixel, with range [1, infinity)
54  * @return True, if succeeded
55  */
56  bool initialize(const Rendering::Engine& engine, unsigned int framebufferWidth, unsigned int framebufferHeight);
57 
58  /**
59  * Updates the manager with ids of new triangles.
60  * @param newTriangleIds The ids of all new triangles
61  * @param stateFrame Optional resulting frame holding the states of all triangles, nullptr if not of interest
62  * @return True, if succeeded
63  */
64  bool updateNewTriangles(const Indices32& newTriangleIds, Frame* stateFrame = nullptr);
65 
66  /**
67  * Updates the manager with ids of recently textured triangles.
68  * @param triangleIdFramebuffer The framebuffer holding all triangles recently textured, must be valid
69  * @param stateFrame Optional resulting frame holding the states of all triangles, nullptr if not of interest
70  * @return True, if succeeded
71  */
72  bool updateTexturedTriangles(const Rendering::TextureFramebufferRef& triangleIdFramebuffer, Frame* stateFrame = nullptr);
73 
74  /**
75  * Updates the manager with ids of recently textured triangles.
76  * @param texturedTriangleIds The ids of all textured triangles
77  * @param stateFrame Optional resulting frame holding the states of all triangles, nullptr if not of interest
78  * @return True, if succeeded
79  */
80  bool updateTexturedTriangles(const Indices32& texturedTriangleIds, Frame* stateFrame = nullptr);
81 
82  /**
83  * Updates the manager with ids of retired triangles.
84  * @param retiredTriangleIds The ids of all retired triangles
85  * @param stateFrame Optional resulting frame holding the states of all triangles, nullptr if not of interest
86  * @return True, if succeeded
87  */
88  bool updateRetiredTriangles(const Indices32& retiredTriangleIds, Frame* stateFrame = nullptr);
89 
90  /**
91  * Updates the manager with ids of deleted triangles.
92  * @param deletedTriangleIds The ids of all deleted triangles
93  * @param stateFrame Optional resulting frame holding the states of all triangles, nullptr if not of interest
94  * @return True, if succeeded
95  */
96  bool updateDeletedTriangles(const Indices32& deletedTriangleIds, Frame* stateFrame = nullptr);
97 
98  /**
99  * Returns the states of all triangles this manager.
100  * @param numberTriangles The number of triangles for which the states will be returned, with range [0, infinity)
101  * @return The states of the individual triangles, valid until the manager's data will be modified
102  */
103  ConstArrayAccessor<uint8_t> triangleStates(const unsigned int numberTriangles);
104 
105  /**
106  * Returns the current texture framebuffer of this renderer.
107  * @return The renderer's texture framebuffer
108  */
109  inline const Rendering::TextureFramebufferRef& textureFramebuffer() const;
110 
111  /**
112  * Explicitly releases this renderer and releases all resources.
113  */
114  void release();
115 
116  /**
117  * Returns whether this renderer has been initialized successfully.
118  * @return True, if succeeded
119  */
120  inline bool isValid() const;
121 
122  protected:
123 
124  /**
125  * Sets the color value (the state) of several triangles.
126  * @param triangleIds The ids of all triangles for which the state will be set
127  * @param triangleColor The color value (the state) to be set
128  * @return True, if succeeded
129  */
130  bool setTriangles(const Indices32& triangleIds, const float triangleColor);
131 
132  /**
133  * Copies the active state framebuffer to the copy framebuffer.
134  * @return True, if succeeded
135  */
137 
138  protected:
139 
140  //// The width of the framebuffer in pixel.
141  unsigned int framebufferWidth_ = 0u;
142 
143  /// The height of the framebuffer in pixel.
144  unsigned int framebufferHeight_ = 0u;
145 
146  /// True, if the manager's data has been changed recently.
147  bool hasChanged_ = false;
148 
149  /// The frame holding a copy of the triangle states, valid as long as 'hasChanged_ == false'
151 
152  /// The shader program allowing to set triangle states.
154 
155  /// The shader program allowing to set the states of textured triangles.
157 
158  /// The shader program allowing to make a copy of the state framebuffer.
160 
161  /// The shader program allowing to set the states of retired triangles.
163 
164  /// The texture framebuffer holding the states of the individual triangles.
166 
167  /// The copy of the texture framebuffer holding the states of the individual triangles.
169 
170  /// The vertex set holding the vertices to be rendered.
172 
173  /// The points object which will be used to render points.
175 
176  /// The triangles object which will be used to render triangles.
178 
179  /// The platform-specific shader part.
180  static const char* partPlatform_;
181 
182  /// The vertex shader program to set triangle states.
184 
185  /// The vertex shader program to render planar textured triangles.
187 
188  /// The vertex shader program to render retired triangles.
190 
191  /// The fragment shader program to render triangle states.
193 
194  /// The fragment shader program to render active triangles.
196 
197  /// The fragment shader program to render retired triangles.
199 
200  /// The fragment shader program to copy the framebuffer.
202 };
203 
205 {
206  return textureFramebuffer_;
207 }
208 
209 }
210 
211 }
212 
213 }
214 
215 #endif // META_OCEAN_TRACKING_MAPTEXTURING_TRIANGLES_MANAGER_RENDERER_H
This class implements an accessor providing direct access to a constant array of elements.
Definition: Accessor.h:400
This class implements Ocean's image class.
Definition: Frame.h:1760
This class is the base class for all rendering engines like.
Definition: Engine.h:46
This class implements a manager for active, textured, retired, and deleted triangles.
Definition: TrianglesManagerRenderer.h:41
Rendering::TextureFramebufferRef copyTextureFramebuffer_
The copy of the texture framebuffer holding the states of the individual triangles.
Definition: TrianglesManagerRenderer.h:168
ConstArrayAccessor< uint8_t > triangleStates(const unsigned int numberTriangles)
Returns the states of all triangles this manager.
bool updateTexturedTriangles(const Rendering::TextureFramebufferRef &triangleIdFramebuffer, Frame *stateFrame=nullptr)
Updates the manager with ids of recently textured triangles.
static const char * programFragmentShaderActiveTriangles_
The fragment shader program to render active triangles.
Definition: TrianglesManagerRenderer.h:195
static const char * partPlatform_
The platform-specific shader part.
Definition: TrianglesManagerRenderer.h:180
bool updateRetiredTriangles(const Indices32 &retiredTriangleIds, Frame *stateFrame=nullptr)
Updates the manager with ids of retired triangles.
Rendering::TextureFramebufferRef textureFramebuffer_
The texture framebuffer holding the states of the individual triangles.
Definition: TrianglesManagerRenderer.h:165
Frame triangleStatesFrame_
The frame holding a copy of the triangle states, valid as long as 'hasChanged_ == false'.
Definition: TrianglesManagerRenderer.h:150
Rendering::PointsRef points_
The points object which will be used to render points.
Definition: TrianglesManagerRenderer.h:174
bool copyFramebuffer()
Copies the active state framebuffer to the copy framebuffer.
static const char * programFragmentShaderCopyFramebuffer_
The fragment shader program to copy the framebuffer.
Definition: TrianglesManagerRenderer.h:201
bool isValid() const
Returns whether this renderer has been initialized successfully.
Rendering::ShaderProgramRef shaderProgramSetTriangles_
The shader program allowing to set triangle states.
Definition: TrianglesManagerRenderer.h:153
Rendering::ShaderProgramRef shaderProgramCopyFramebuffer_
The shader program allowing to make a copy of the state framebuffer.
Definition: TrianglesManagerRenderer.h:159
Rendering::VertexSetRef vertexSet_
The vertex set holding the vertices to be rendered.
Definition: TrianglesManagerRenderer.h:171
const Rendering::TextureFramebufferRef & textureFramebuffer() const
Returns the current texture framebuffer of this renderer.
Definition: TrianglesManagerRenderer.h:204
void release()
Explicitly releases this renderer and releases all resources.
Rendering::ShaderProgramRef shaderProgramRetiredTriangles_
The shader program allowing to set the states of retired triangles.
Definition: TrianglesManagerRenderer.h:162
Rendering::ShaderProgramRef shaderProgramTexturedTriangles_
The shader program allowing to set the states of textured triangles.
Definition: TrianglesManagerRenderer.h:156
bool updateNewTriangles(const Indices32 &newTriangleIds, Frame *stateFrame=nullptr)
Updates the manager with ids of new triangles.
static const char * programVertexShaderRetiredTriangles_
The vertex shader program to render retired triangles.
Definition: TrianglesManagerRenderer.h:189
~TrianglesManagerRenderer()
Destructs this renderer and releases all resources.
bool updateDeletedTriangles(const Indices32 &deletedTriangleIds, Frame *stateFrame=nullptr)
Updates the manager with ids of deleted triangles.
static const char * programFragmentShaderRetiredTriangles_
The fragment shader program to render retired triangles.
Definition: TrianglesManagerRenderer.h:198
bool initialize(const Rendering::Engine &engine, unsigned int framebufferWidth, unsigned int framebufferHeight)
Initializes the manager.
static const char * programVertexShaderPlanarTexturedTriangles_
The vertex shader program to render planar textured triangles.
Definition: TrianglesManagerRenderer.h:186
bool setTriangles(const Indices32 &triangleIds, const float triangleColor)
Sets the color value (the state) of several triangles.
Rendering::TrianglesRef triangles_
The triangles object which will be used to render triangles.
Definition: TrianglesManagerRenderer.h:177
static const char * programFragmentShaderSetTriangles_
The fragment shader program to render triangle states.
Definition: TrianglesManagerRenderer.h:192
static const char * programVertexShaderSetTriangles_
The vertex shader program to set triangle states.
Definition: TrianglesManagerRenderer.h:183
bool updateTexturedTriangles(const Indices32 &texturedTriangleIds, Frame *stateFrame=nullptr)
Updates the manager with ids of recently textured triangles.
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15