Ocean
rendering/glescenegraph/GLESFramebuffer.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_FRAMEBUFFER_H
9 #define META_OCEAN_RENDERING_GLES_FRAMEBUFFER_H
10 
15 
17 
18 namespace Ocean
19 {
20 
21 namespace Rendering
22 {
23 
24 namespace GLESceneGraph
25 {
26 
27 /**
28  * This class implements a base for all GLESceneGraph framebuffers.
29  * @ingroup renderinggles
30  */
31 class OCEAN_RENDERING_GLES_EXPORT GLESFramebuffer :
32  virtual public GLESObject,
33  virtual public Framebuffer
34 {
35  public:
36 
37  /**
38  * Definitions of individual stereo framebuffers.
39  */
41  {
42  /// An invalid framebuffer type.
43  ST_INVALID = 0,
44  /// Framebuffer of a mono view.
46  /// Framebuffer of a left stereo view.
48  /// Framebuffer of a right stereo view.
49  ST_RIGHT
50  };
51 
52  public:
53 
54  /**
55  * Returns the viewport of this framebuffer.
56  * @see Framebuffer::viewport().
57  */
58  void viewport(unsigned int& left, unsigned int& top, unsigned int& width, unsigned int& height) const override;
59 
60  /**
61  * Returns whether the framebuffer supports hardware anti-aliasing.
62  * @see Framebuffer::isAntialiasingSupported().
63  */
64  bool isAntialiasingSupported(const unsigned int buffers) const override;
65 
66  /**
67  * Returns whether the framebuffer uses hardware anti-aliasing.
68  * @see Framebuffer::isAntialiasing().
69  */
70  bool isAntialiasing() const override;
71 
72  /**
73  * Returns the face mode of the entire framebuffer.
74  * @see Framebuffer::faceMode().
75  */
76  FaceMode faceMode() const override;
77 
78  /**
79  * Returns the global face culling mode of the entire framebuffer.
80  * @see Framebuffer::cullingMode().
81  */
82  CullingMode cullingMode() const override;
83 
84  /**
85  * Returns the global lighting mode of the entire framebuffer.
86  * @see Framebuffer::lightingMode().
87  */
88  LightingMode lightingMode() const override;
89 
90  /**
91  * Returns the render technique of the entire framebuffer.
92  * @see Framebuffer::renderTechnique().
93  */
94  RenderTechnique renderTechnique() const override;
95 
96  /**
97  * Returns the shadow technique of the entire framebuffer.
98  * @see Framebuffer::shadowTechnique().
99  */
101 
102  /**
103  * Returns the stereo type of this framebuffer.
104  * @return The framebuffer's stereo type, ST_MONO by default
105  */
106  virtual StereoType stereoType() const;
107 
108  /**
109  * Sets the viewport of this framebuffer.
110  * @see Framebuffer::setViewport().
111  */
112  void setViewport(const unsigned int left, const unsigned int top, const unsigned int width, const unsigned int height) override;
113 
114  /**
115  * Sets whether the framebuffer uses hardware anti-aliasing.
116  * @see Framebuffer::setAntialiasing().
117  */
118  bool setAntialiasing(const bool antialiasing) override;
119 
120  /**
121  * Sets the face mode of the entire framebuffer.
122  * @see Framebuffer::setFaceMode().
123  */
124  void setFaceMode(const FaceMode mode) override;
125 
126  /**
127  * Sets the global culling mode of the entire framebuffer.
128  * @see Framebuffer::setCullingMode().
129  */
130  void setCullingMode(const CullingMode cullingMode) override;
131 
132  /**
133  * Sets the global lighting mode of the entire framebuffer.
134  * @see Framebuffer::setLightingMode().
135  */
136  void setLightingMode(const LightingMode lightingMode) override;
137 
138  /**
139  * Sets the rendering technique of the entire framebuffer.
140  * @see Framebuffer::setRenderTechnique().
141  */
142  void setRenderTechnique(const RenderTechnique technique) override;
143 
144  /**
145  * Sets the shadow technique of the entire framebuffer.
146  * @see Framebuffer::setShadowTechnique().
147  */
148  void setShadowTechnique(const ShadowTechnique technique) override;
149 
150  /**
151  * Sets the stereo type of this framebuffer.
152  * @param stereoType The stereo type to set
153  */
154  virtual void setStereoType(const StereoType stereoType);
155 
156  /**
157  * Renders the next frame into the framebuffer.
158  * @see Framebuffer::render().
159  */
160  void render() override;
161 
162  /**
163  * Returns the renderable object intersected by a given ray.
164  * @see Framebuffer::intersection().
165  */
166  bool intersection(const Line3& ray, RenderableRef& renderable, Vector3& position) override;
167 
168  /**
169  * Returns whether the platform supports a specific extension.
170  * @see Framebuffer::hasExtension().
171  */
172  bool hasExtension(const std::string& extension) const override;
173 
174  /**
175  * Linearizes a given z-buffer depth frame with non-linear (e.g., logarithmic) depth.
176  * By default in OpenGL, the depth coordinates range from −1 to 1, corresponding to the near and far clipping planes (after clipping and division by w).<br>
177  * @param depthFrame The non-linear depth to linearize, with value range [-1, 1], must be valid
178  * @param nearDistance The distance to the near clipping plane of the depth frame, with range (0, infinity)
179  * @param farDistance The distance to the far clipping plane of the depth frame, with range (nearDistance, infinity)
180  * @return True, if succeeded
181  */
182  bool linearizeDepthFrame(Frame& depthFrame, const Scalar nearDistance, const Scalar farDistance) const override;
183 
184  protected:
185 
186  /**
187  * Creates a new GLESceneGraph framebuffer object.
188  */
190 
191  /**
192  * Destructs a GLESceneGraph framebuffer object.
193  */
194  ~GLESFramebuffer() override;
195 
196  /**
197  * Initializes the framebuffer.
198  * @see Framebuffer::initialize().
199  */
200  bool initialize(const FramebufferRef& shareFramebuffer = FramebufferRef()) override;
201 
202  /**
203  * Initialize the OpenGL ES display and context.
204  * @return True, if succeeded
205  */
206  virtual bool initializeContext();
207 
208  /**
209  * Initialize the OpenGL ES environment properties.
210  * @return True, if succeeded
211  */
212  virtual bool initializeOpenGLES();
213 
214  /**
215  * Releases the framebuffer.
216  * @see Framebuffer::release().
217  */
218  void release() override;
219 
220  protected:
221 
222 #ifndef OCEAN_RENDERING_GLES_USE_ES
223  /// The face mode which is only supported in OpenGL.
225 #endif
226 
227  /// Global lighting mode for the entire framebuffer.
229 
230  /// Global lighting mode for the entire framebuffer.
232 
233  /// The string will all extensions separated by spaces.
234  std::string extensions_;
235 
236  /// Viewport left position.
237  unsigned int viewportLeft_ = (unsigned int)(-1);
238 
239  /// Viewport top position.
240  unsigned int viewportTop_ = (unsigned int)(-1);
241 
242  /// Viewport width value.
243  unsigned int viewportWidth_ = (unsigned int)(0);
244 
245  /// Viewport height value.
246  unsigned int viewportHeight_ = (unsigned int)(0);
247 
248  /// The stereo framebuffer type.
249  StereoType stereoType_ = ST_MONO;
250 
251  /// The traverser which is used for rendering.
253 
254  /// The texture framebuffer which is used for picking objects.
256 };
257 
258 }
259 
260 }
261 
262 }
263 
264 #endif // META_OCEAN_RENDERING_GLES_FRAMEBUFFER_H
This class implements Ocean's image class.
Definition: Frame.h:1760
This class implements an infinite line in 3D space.
Definition: Line3.h:70
This class is the base class for all rendering framebuffers.
Definition: rendering/Framebuffer.h:48
RenderTechnique
Definition of different render techniques.
Definition: rendering/Framebuffer.h:68
ShadowTechnique
Definition of different shadow techniques.
Definition: rendering/Framebuffer.h:83
This class implements a base for all GLESceneGraph framebuffers.
Definition: rendering/glescenegraph/GLESFramebuffer.h:34
ShadowTechnique shadowTechnique() const override
Returns the shadow technique of the entire framebuffer.
GLESFramebuffer()
Creates a new GLESceneGraph framebuffer object.
virtual void setStereoType(const StereoType stereoType)
Sets the stereo type of this framebuffer.
void setCullingMode(const CullingMode cullingMode) override
Sets the global culling mode of the entire framebuffer.
void setFaceMode(const FaceMode mode) override
Sets the face mode of the entire framebuffer.
bool setAntialiasing(const bool antialiasing) override
Sets whether the framebuffer uses hardware anti-aliasing.
bool linearizeDepthFrame(Frame &depthFrame, const Scalar nearDistance, const Scalar farDistance) const override
Linearizes a given z-buffer depth frame with non-linear (e.g., logarithmic) depth.
virtual bool initializeContext()
Initialize the OpenGL ES display and context.
GLESTraverser traverser_
The traverser which is used for rendering.
Definition: rendering/glescenegraph/GLESFramebuffer.h:252
bool isAntialiasingSupported(const unsigned int buffers) const override
Returns whether the framebuffer supports hardware anti-aliasing.
bool isAntialiasing() const override
Returns whether the framebuffer uses hardware anti-aliasing.
StereoType
Definitions of individual stereo framebuffers.
Definition: rendering/glescenegraph/GLESFramebuffer.h:41
@ ST_LEFT
Framebuffer of a left stereo view.
Definition: rendering/glescenegraph/GLESFramebuffer.h:47
@ ST_MONO
Framebuffer of a mono view.
Definition: rendering/glescenegraph/GLESFramebuffer.h:45
~GLESFramebuffer() override
Destructs a GLESceneGraph framebuffer object.
void release() override
Releases the framebuffer.
CullingMode cullingMode() const override
Returns the global face culling mode of the entire framebuffer.
std::string extensions_
The string will all extensions separated by spaces.
Definition: rendering/glescenegraph/GLESFramebuffer.h:234
void setRenderTechnique(const RenderTechnique technique) override
Sets the rendering technique of the entire framebuffer.
virtual StereoType stereoType() const
Returns the stereo type of this framebuffer.
FaceMode faceMode() const override
Returns the face mode of the entire framebuffer.
void setViewport(const unsigned int left, const unsigned int top, const unsigned int width, const unsigned int height) override
Sets the viewport of this framebuffer.
virtual bool initializeOpenGLES()
Initialize the OpenGL ES environment properties.
bool intersection(const Line3 &ray, RenderableRef &renderable, Vector3 &position) override
Returns the renderable object intersected by a given ray.
LightingMode lightingMode() const override
Returns the global lighting mode of the entire framebuffer.
bool initialize(const FramebufferRef &shareFramebuffer=FramebufferRef()) override
Initializes the framebuffer.
void setShadowTechnique(const ShadowTechnique technique) override
Sets the shadow technique of the entire framebuffer.
RenderTechnique renderTechnique() const override
Returns the render technique of the entire framebuffer.
bool hasExtension(const std::string &extension) const override
Returns whether the platform supports a specific extension.
SmartObjectRef< GLESTextureFramebuffer > pickingTextureFramebuffer_
The texture framebuffer which is used for picking objects.
Definition: rendering/glescenegraph/GLESFramebuffer.h:255
void setLightingMode(const LightingMode lightingMode) override
Sets the global lighting mode of the entire framebuffer.
void render() override
Renders the next frame into the framebuffer.
void viewport(unsigned int &left, unsigned int &top, unsigned int &width, unsigned int &height) const override
Returns the viewport of this framebuffer.
This class is the base class for all GLESceneGraph objects.
Definition: GLESObject.h:57
This class implements a traverser for renderables.
Definition: GLESTraverser.h:39
FaceMode
Defines different face rendering modes.
Definition: PrimitiveAttribute.h:42
@ MODE_FACE
Face rendering mode rendering the entire face, which is the default mode.
Definition: PrimitiveAttribute.h:44
CullingMode
Defines different face culling modes.
Definition: PrimitiveAttribute.h:57
@ CULLING_DEFAULT
Default culling mode.
Definition: PrimitiveAttribute.h:67
LightingMode
Definition of different lighting modes.
Definition: PrimitiveAttribute.h:74
@ LM_DEFAULT
Default lighting.
Definition: PrimitiveAttribute.h:80
This class implements a smart rendering object reference.
Definition: rendering/ObjectRef.h:34
float Scalar
Definition of a scalar type.
Definition: Math.h:128
SmartObjectRef< Framebuffer > FramebufferRef
Definition of a smart object reference holding a framebuffer.
Definition: rendering/Framebuffer.h:31
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15