Ocean
Loading...
Searching...
No Matches
TexturedTrianglesRenderer.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_TEXTURED_TRIANGLES_RENDERER_H
9#define META_OCEAN_TRACKING_MAPTEXTURING_TEXTURED_TRIANGLES_RENDERER_H
10
14
15#include "ocean/base/Frame.h"
16
18
26
27namespace Ocean
28{
29
30namespace Tracking
31{
32
33namespace MapTexturing
34{
35
36/**
37 * This class implements a renderer rendering textured triangles into a texture atlas using a geometry shader.
38 * @ingroup trackingmaptexturing
39 */
40class OCEAN_TRACKING_MAPTEXTURING_EXPORT TexturedTrianglesRenderer
41{
42 protected:
43
44 /**
45 * Definition of an unordered map mapping mesh ids to texture framebuffers.
46 */
47 typedef std::unordered_map<Index32, Rendering::TextureFramebufferRef> TextureFramebufferMap;
48
49 public:
50
51 /**
52 * Destructs this renderer and releases all resources.
53 */
55
56 /**
57 * Updates this renderer with a new live frame which will be used as source texture.
58 * @param engine The rendering engine to be used
59 * @param rgbFrame The frame to be used as source texture, must be valid
60 * @return True, if succeeded
61 */
62 bool update(const Rendering::Engine& engine, Frame&& rgbFrame);
63
64 /**
65 * Renders textured triangles into a texture atlas.
66 * @param engine The rendering engine to be used
67 * @param numberTriangles The number of triangles to render, with range [0, infinity)
68 * @param projectionMatrix The projection matrix to be used, must be valid
69 * @param world_T_camera The transformation between camera and world, must be valid
70 * @param vertexSet The vertex set containing all triangle vertices, must be valid
71 * @param triangles The triangles to render, must be valid
72 * @param visibleTrianglesFramebuffer The texture framebuffer containing all visible triangles, must be valid
73 * @param textureAtlas The texture atlas defining the layout
74 * @return True, if succeeded
75 */
76 bool render(const Rendering::Engine& engine, const unsigned int numberTriangles, const SquareMatrix4& projectionMatrix, const HomogenousMatrix4& world_T_camera, const Rendering::VertexSetRef& vertexSet, const Rendering::TrianglesRef& triangles, const Rendering::TextureFramebufferRef& visibleTrianglesFramebuffer, const TextureAtlas& textureAtlas);
77
78 /**
79 * Returns the map mapping mesh ids to texture framebuffers.
80 * @return The map of texture framebuffers
81 */
82 inline const TextureFramebufferMap& textureFramebufferMap() const;
83
84 /**
85 * Returns the latest texture atlas image for a specified mesh.
86 * @param meshId The id of the mesh for which the latest atlas image will be returned, must be valid
87 * @param textureFrame The resulting atlas image
88 * @return True, if succeeded
89 */
90 bool latestTexture(const Index32 meshId, Frame& textureFrame) const;
91
92 /**
93 * Returns the ids of all textured meshes.
94 * @return The ids of all meshes
95 */
97
98 /**
99 * Explicitly releases this renderer and releases all resources.
100 */
101 void release();
102
103 /**
104 * Returns whether this renderer has been initialized successfully.
105 * @return True, if succeeded
106 */
107 inline bool isValid() const;
108
109 protected:
110
111 /**
112 * Renders textured triangles into a texture atlas.
113 * @param engine The rendering engine to be used
114 * @param meshId The id of the mesh for which the textured triangles will be rendered, must be valid
115 * @param trianglesInMesh The number of triangles in the mesh, with range [1, infinity)
116 * @param projectionMatrix The projection matrix to be used, must be valid
117 * @param world_T_camera The transformation between camera and world, must be valid
118 * @param vertexSet The vertex set containing all triangle vertices, must be valid
119 * @param triangles The triangles to render, must be valid
120 * @param visibleTrianglesFramebuffer The texture framebuffer containing all visible triangles, must be valid
121 * @param textureAtlas The texture atlas defining the layout
122 * @return True, if succeeded
123 */
124 bool renderMesh(const Rendering::Engine& engine, const Index32 meshId, const unsigned int trianglesInMesh, const SquareMatrix4& projectionMatrix, const HomogenousMatrix4& world_T_camera, const Rendering::VertexSetRef& vertexSet, const Rendering::TrianglesRef& triangles, const Rendering::TextureFramebufferRef& visibleTrianglesFramebuffer, const TextureAtlas& textureAtlas);
125
126 protected:
127
128 /// The shader program rendering individual triangles with individual color ids.
130
131 /// The map of texture framebuffers, one for each mesh id.
133
134 /// The frame texture holding the texture information for the triangles.
136
137 /// The platform-specific shader part.
138 static const char* partPlatform_;
139
140 /// The shader part for the texture atlas.
141 static const char* partTextureAtlas_;
142
143 /// The geometry shader part.
144 static const char* programGeometryShader_;
145
146 /// The vertex shader part.
147 static const char* programVertexShader_;
148
149 /// The fragment shader part.
150 static const char* programFragmentShader_;
151};
152
157
158}
159
160}
161
162}
163
164#endif // META_OCEAN_TRACKING_MAPTEXTURING_TEXTURED_TRIANGLES_RENDERER_H
This class implements Ocean's image class.
Definition Frame.h:1808
This class is the base class for all rendering engines like.
Definition Engine.h:46
This class implements a texture atlas for triangles with regular shape.
Definition TextureAtlas.h:31
This class implements a renderer rendering textured triangles into a texture atlas using a geometry s...
Definition TexturedTrianglesRenderer.h:41
Rendering::ShaderProgramRef shaderProgram_
The shader program rendering individual triangles with individual color ids.
Definition TexturedTrianglesRenderer.h:129
bool render(const Rendering::Engine &engine, const unsigned int numberTriangles, const SquareMatrix4 &projectionMatrix, const HomogenousMatrix4 &world_T_camera, const Rendering::VertexSetRef &vertexSet, const Rendering::TrianglesRef &triangles, const Rendering::TextureFramebufferRef &visibleTrianglesFramebuffer, const TextureAtlas &textureAtlas)
Renders textured triangles into a texture atlas.
~TexturedTrianglesRenderer()
Destructs this renderer and releases all resources.
TextureFramebufferMap textureFramebufferMap_
The map of texture framebuffers, one for each mesh id.
Definition TexturedTrianglesRenderer.h:132
bool latestTexture(const Index32 meshId, Frame &textureFrame) const
Returns the latest texture atlas image for a specified mesh.
bool renderMesh(const Rendering::Engine &engine, const Index32 meshId, const unsigned int trianglesInMesh, const SquareMatrix4 &projectionMatrix, const HomogenousMatrix4 &world_T_camera, const Rendering::VertexSetRef &vertexSet, const Rendering::TrianglesRef &triangles, const Rendering::TextureFramebufferRef &visibleTrianglesFramebuffer, const TextureAtlas &textureAtlas)
Renders textured triangles into a texture atlas.
bool update(const Rendering::Engine &engine, Frame &&rgbFrame)
Updates this renderer with a new live frame which will be used as source texture.
static const char * programVertexShader_
The vertex shader part.
Definition TexturedTrianglesRenderer.h:147
static const char * programFragmentShader_
The fragment shader part.
Definition TexturedTrianglesRenderer.h:150
bool isValid() const
Returns whether this renderer has been initialized successfully.
Indices32 meshIds() const
Returns the ids of all textured meshes.
static const char * partPlatform_
The platform-specific shader part.
Definition TexturedTrianglesRenderer.h:138
static const char * partTextureAtlas_
The shader part for the texture atlas.
Definition TexturedTrianglesRenderer.h:141
Rendering::FrameTexture2DRef texture_
The frame texture holding the texture information for the triangles.
Definition TexturedTrianglesRenderer.h:135
static const char * programGeometryShader_
The geometry shader part.
Definition TexturedTrianglesRenderer.h:144
const TextureFramebufferMap & textureFramebufferMap() const
Returns the map mapping mesh ids to texture framebuffers.
Definition TexturedTrianglesRenderer.h:153
std::unordered_map< Index32, Rendering::TextureFramebufferRef > TextureFramebufferMap
Definition of an unordered map mapping mesh ids to texture framebuffers.
Definition TexturedTrianglesRenderer.h:47
void release()
Explicitly releases this renderer and releases all resources.
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition Base.h:96
uint32_t Index32
Definition of a 32 bit index value.
Definition Base.h:84
The namespace covering the entire Ocean framework.
Definition Accessor.h:15