Ocean
MeshRenderer.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_MESH_RENDERER_H
9 #define META_OCEAN_TRACKING_MAPTEXTURING_MESH_RENDERER_H
10 
14 
15 #include "ocean/base/Frame.h"
16 
18 
20 #include "ocean/rendering/Engine.h"
26 
27 namespace Ocean
28 {
29 
30 namespace Tracking
31 {
32 
33 namespace MapTexturing
34 {
35 
36 /**
37  * This class implements a renderer for the entire mesh.
38  * @ingroup trackingmaptexturing
39  */
40 class OCEAN_TRACKING_MAPTEXTURING_EXPORT MeshRenderer
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  * Initializes this renderer.
58  * @param engine The rendering engine to be used
59  * @return True, if succeeded
60  */
61  bool initialize(const Rendering::Engine& engine);
62 
63  /**
64  * Renders textured triangles into a texture atlas.
65  * @param engine The rendering engine to be used
66  * @param vertexSet The vertex set containing all triangle vertices, must be valid
67  * @param triangles The triangles to render, must be valid
68  * @param numberTriangles The number of triangles to render, with range [0, infinity)
69  * @param anyCamera The camera profile to be used when rendering, must be valid
70  * @param world_T_camera The transformation between camera and world, must be valid
71  * @param textureFramebufferMap The map of mesh ID to texture, used for rendering associated triangles with the textures.
72  * @param trianglesStateFramebuffer The framebuffer holding the states of the individual triangles, must be valid
73  * @param textureAtlas The texture atlas defining the layout
74  * @param renderedFrame The optionally resulting frame to which the rendered frame is copied, will be ignored if set to `nullptr`.
75  * @return True, if succeeded
76  */
77  bool render(const Rendering::Engine& engine, const Rendering::VertexSetRef& vertexSet, const Rendering::TrianglesRef& triangles, const unsigned int numberTriangles, const AnyCamera& anyCamera, const HomogenousMatrix4& world_T_camera, const TextureFramebufferMap& textureFramebufferMap, const Rendering::TextureFramebufferRef& trianglesStateFramebuffer, const TextureAtlas& textureAtlas, Frame* renderedFrame = nullptr);
78 
79  /**
80  * Returns the current texture framebuffer of this renderer.
81  * @return The renderer's texture framebuffer
82  */
83  inline const Rendering::TextureFramebufferRef& textureFramebuffer() const;
84 
85  /**
86  * Explicitly releases this renderer and releases all resources.
87  */
88  void release();
89 
90  /**
91  * Returns whether this renderer has been initialized successfully.
92  * @return True, if succeeded
93  */
94  inline bool isValid() const;
95 
96  protected:
97 
98  /// The shader program rendering individual triangles with individual color ids.
100 
101  /// The texture framebuffer holding the states of the individual triangles.
103 
104  /// The platform-specific shader part.
105  static const char* partPlatform_;
106 
107  /// The shader part for the texture atlas.
108  static const char* partTextureAtlas_;
109 
110  /// The vertex shader part.
111  static const char* programVertexShader_;
112 
113  /// The fragment shader part.
114  static const char* programFragmentShader_;
115 };
116 
118 {
119  return textureFramebuffer_;
120 }
121 
122 }
123 
124 }
125 
126 }
127 
128 #endif // META_OCEAN_TRACKING_MAPTEXTURING_MESH_RENDERER_H
This class implements the abstract base class for all AnyCamera objects.
Definition: AnyCamera.h:130
This class implements Ocean's image class.
Definition: Frame.h:1792
This class is the base class for all rendering engines like.
Definition: Engine.h:46
This class implements a renderer for the entire mesh.
Definition: MeshRenderer.h:41
std::unordered_map< Index32, Rendering::TextureFramebufferRef > TextureFramebufferMap
Definition of an unordered map mapping mesh ids to texture framebuffers.
Definition: MeshRenderer.h:47
~MeshRenderer()
Destructs this renderer and releases all resources.
void release()
Explicitly releases this renderer and releases all resources.
static const char * partPlatform_
The platform-specific shader part.
Definition: MeshRenderer.h:105
static const char * programVertexShader_
The vertex shader part.
Definition: MeshRenderer.h:111
Rendering::ShaderProgramRef shaderProgram_
The shader program rendering individual triangles with individual color ids.
Definition: MeshRenderer.h:99
static const char * partTextureAtlas_
The shader part for the texture atlas.
Definition: MeshRenderer.h:108
static const char * programFragmentShader_
The fragment shader part.
Definition: MeshRenderer.h:114
bool isValid() const
Returns whether this renderer has been initialized successfully.
Rendering::TextureFramebufferRef textureFramebuffer_
The texture framebuffer holding the states of the individual triangles.
Definition: MeshRenderer.h:102
bool render(const Rendering::Engine &engine, const Rendering::VertexSetRef &vertexSet, const Rendering::TrianglesRef &triangles, const unsigned int numberTriangles, const AnyCamera &anyCamera, const HomogenousMatrix4 &world_T_camera, const TextureFramebufferMap &textureFramebufferMap, const Rendering::TextureFramebufferRef &trianglesStateFramebuffer, const TextureAtlas &textureAtlas, Frame *renderedFrame=nullptr)
Renders textured triangles into a texture atlas.
bool initialize(const Rendering::Engine &engine)
Initializes this renderer.
const Rendering::TextureFramebufferRef & textureFramebuffer() const
Returns the current texture framebuffer of this renderer.
Definition: MeshRenderer.h:117
This class implements a texture atlas for triangles with regular shape.
Definition: TextureAtlas.h:31
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15