Ocean
DepthBufferRenderer.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_DEPTH_BUFFER_RENDERER_H
9 #define META_OCEAN_TRACKING_MAPTEXTURING_DEPTH_BUFFER_RENDERER_H
10 
12 
13 #include "ocean/rendering/Engine.h"
18 
19 namespace Ocean
20 {
21 
22 namespace Tracking
23 {
24 
25 namespace MapTexturing
26 {
27 
28 /**
29  * This class implements a renderer for a depth buffer.
30  * @ingroup trackingmaptexturing
31  */
32 class OCEAN_TRACKING_MAPTEXTURING_EXPORT DepthBufferRenderer
33 {
34  public:
35 
36  /**
37  * Destructs this renderer and releases all resources.
38  */
40 
41  /**
42  * Down-samples and filters a depth framebuffer.
43  * @param engine The rendering engine to be used
44  * @param sourceFramebuffer The source texture framebuffer from which the depth buffer will be down-sampled and filtered, must be valid
45  * @param downsampleIterations The number of down-sample iterations, with range [0, infinity)
46  */
47  bool downsampleAndFilterDepthBuffer(const Rendering::Engine& engine, const Rendering::TextureFramebufferRef& sourceFramebuffer, const unsigned int downsampleIterations);
48 
49  /**
50  * Returns the current texture framebuffer of this renderer.
51  * @return The renderer's texture framebuffer
52  */
53  inline const Rendering::TextureFramebufferRef& textureFramebuffer() const;
54 
55  /**
56  * Explicitly releases this renderer and releases all resources.
57  */
58  void release();
59 
60  /**
61  * Returns whether this renderer has been initialized successfully.
62  * @return True, if succeeded
63  */
64  inline bool isValid() const;
65 
66  protected:
67 
68  /**
69  * Down-samples a framebuffer by a factor of two.
70  * @param sourceFramebuffer The source framebuffer to down-sample, must be valid
71  * @param targetFramebuffer The target framebuffer receiving the down-sampled source framebuffer, must be valid
72  * @return True, if succeeded
73  */
75 
76  /**
77  * Applies a 3x3 min-filter step to the source framebuffer.
78  * @param sourceFramebuffer The source framebuffer to which the filter will be applied, must be valid
79  * @param targetFramebuffer The target framebuffer receiving the filtered result, must be valid
80  * @return True, if succeeded
81  */
83 
84  protected:
85 
86  /// The shader program downsampling the depth buffer.
88 
89  /// The shader program filtering the depth buffer.
91 
92  /// The texture framebuffer used when rendering the color ids.
93  std::vector<Rendering::TextureFramebufferRef> textureFramebuffers_;
94 
95  /// The vertex set holding the vertices to be rendered.
97 
98  /// The triangle object which will be used to render the triangles.
100 
101  /// The platform-specific shader part.
102  static const char* partPlatform_;
103 
104  /// The vertex shader part.
105  static const char* programVertexShader_;
106 
107  /// The fragment shader part for downsampling.
109 
110  /// The fragment shader part for 3x3 box filtering.
112 };
113 
115 {
116  ocean_assert(!textureFramebuffers_.empty());
117  return textureFramebuffers_.back();
118 }
119 
120 }
121 
122 }
123 
124 }
125 
126 #endif // META_OCEAN_TRACKING_MAPTEXTURING_DEPTH_BUFFER_RENDERER_H
This class is the base class for all rendering engines like.
Definition: Engine.h:46
This class implements a renderer for a depth buffer.
Definition: DepthBufferRenderer.h:33
bool downsampleFramebuffer(const Rendering::TextureFramebufferRef &sourceFramebuffer, Rendering::TextureFramebufferRef &targetFramebuffer)
Down-samples a framebuffer by a factor of two.
bool minFilterFramebuffer(const Rendering::TextureFramebufferRef &sourceFramebuffer, Rendering::TextureFramebufferRef &targetFramebuffer)
Applies a 3x3 min-filter step to the source framebuffer.
bool downsampleAndFilterDepthBuffer(const Rendering::Engine &engine, const Rendering::TextureFramebufferRef &sourceFramebuffer, const unsigned int downsampleIterations)
Down-samples and filters a depth framebuffer.
static const char * programVertexShader_
The vertex shader part.
Definition: DepthBufferRenderer.h:105
static const char * programFragmentShaderMinFiltering_
The fragment shader part for 3x3 box filtering.
Definition: DepthBufferRenderer.h:111
~DepthBufferRenderer()
Destructs this renderer and releases all resources.
std::vector< Rendering::TextureFramebufferRef > textureFramebuffers_
The texture framebuffer used when rendering the color ids.
Definition: DepthBufferRenderer.h:93
void release()
Explicitly releases this renderer and releases all resources.
bool isValid() const
Returns whether this renderer has been initialized successfully.
const Rendering::TextureFramebufferRef & textureFramebuffer() const
Returns the current texture framebuffer of this renderer.
Definition: DepthBufferRenderer.h:114
Rendering::TrianglesRef triangles_
The triangle object which will be used to render the triangles.
Definition: DepthBufferRenderer.h:99
Rendering::VertexSetRef vertexSet_
The vertex set holding the vertices to be rendered.
Definition: DepthBufferRenderer.h:96
static const char * programFragmentShaderDownsampling_
The fragment shader part for downsampling.
Definition: DepthBufferRenderer.h:108
Rendering::ShaderProgramRef shaderProgramMinFiltering_
The shader program filtering the depth buffer.
Definition: DepthBufferRenderer.h:90
Rendering::ShaderProgramRef shaderProgramDownsampling_
The shader program downsampling the depth buffer.
Definition: DepthBufferRenderer.h:87
static const char * partPlatform_
The platform-specific shader part.
Definition: DepthBufferRenderer.h:102
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15