Ocean
GLESTextureFramebuffer.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_TEXTURE_FRAMEBUFFER_H
9 #define META_OCEAN_RENDERING_GLES_TEXTURE_FRAMEBUFFER_H
10 
13 
18 
19 #ifdef OCEAN_PLATFORM_BUILD_APPLE_IOS_ANY
20  #include <CoreVideo/CoreVideo.h>
21 #endif
22 
23 namespace Ocean
24 {
25 
26 namespace Rendering
27 {
28 
29 namespace GLESceneGraph
30 {
31 
32 /**
33  * This class is the base class for all GLESceneGraph texture framebuffer objects.
34  * @ingroup renderinggles
35  */
36 class OCEAN_RENDERING_GLES_EXPORT GLESTextureFramebuffer :
37  virtual public GLESTexture,
38  virtual public TextureFramebuffer
39 {
40  friend class GLESFactory;
41 
42  public:
43 
44  /**
45  * Returns the name of the texture e.g., in a shader.
46  * @see Texture::textureName().
47  */
48  std::string textureName() const override;
49 
50  /**
51  * Sets the name of the texture e.g., in a shader.
52  * @see Texture::setTextureName().
53  */
54  bool setTextureName(const std::string& name) override;
55 
56  /**
57  * Resizes the texture framebuffer.
58  * @see TextureFramebuffer::resize().
59  */
60  bool resize(const unsigned int width, const unsigned int height) override;
61 
62  /**
63  * Returns the texture framebuffer's internal pixel format.
64  * @see TextureFramebuffer::pixelFormat().
65  */
67 
68  /**
69  * Returns the width of this framebuffer.
70  * @return The framebuffer's width, in pixel, with range [0, infinity)
71  */
72  inline unsigned int width() const;
73 
74  /**
75  * Returns the height of this framebuffer.
76  * @return The framebuffer's height, in pixel, with range [0, infinity)
77  */
78  inline unsigned int height() const;
79 
80  /**
81  * Returns the texture wrap type in s direction.
82  * @see Texture2D::wrapTypeS().
83  */
84  WrapType wrapTypeS() const override;
85 
86  /**
87  * Returns the texture wrap type in t direction.
88  * @see Texture2D::wrapTypeT().
89  */
90  WrapType wrapTypeT() const override;
91 
92  /**
93  * Sets the texture framebuffer's internal pixel format.
94  * @see TextureFramebuffer::setPixelFormat().
95  */
96  bool setPixelFormat(const FrameType::PixelFormat pixelFormat) override;
97 
98  /**
99  * Sets the texture wrap type in s direction.
100  * @see Texture2D::setWrapTypeS().
101  */
102  bool setWrapTypeS(const WrapType type) override;
103 
104  /**
105  * Sets the texture wrap type in t direction.
106  * @see Texture2D::setWrapTypeT().
107  */
108  bool setWrapTypeT(const WrapType type) override;
109 
110  /**
111  * Sets the number of multi-samples.
112  * @param multisamples The number of multi-samples the texture will apply, with range [1, infinity)
113  */
114  bool setMultisamples(const unsigned int multisamples);
115 
116  /**
117  * Binds this texture.
118  * @see GLESTexture::bindTexture().
119  */
120  unsigned int bindTexture(GLESShaderProgram& shaderProgram, const unsigned int id) override;
121 
122  /**
123  * Binds the framebuffer.
124  * @return True, if succeeded
125  */
127 
128  /**
129  * Unbinds the framebuffer.
130  */
132 
133  /**
134  * Copies the image content of the color texture to a given frame.
135  * @param frame The frame to which the color texture will be copied, the frame will be adjusted if the pixel format does match
136  * @param subRegion Optional sub-region within the framebuffer to copy; an invalid bounding box to copy the entire framebuffer
137  * @return True, if succeeded
138  */
139  bool copyColorTextureToFrame(Frame& frame, const CV::PixelBoundingBox& subRegion = CV::PixelBoundingBox()) override;
140 
141  /**
142  * Copies the image content of the depth texture to a given frame.
143  * @param frame The frame to which the depth texture will be copied, the frame will be adjusted if the pixel format does match
144  * @param subRegion Optional sub-region within the framebuffer to copy; an invalid bounding box to copy the entire framebuffer
145  * @return True, if succeeded
146  */
147  bool copyDepthTextureToFrame(Frame& frame, const CV::PixelBoundingBox& subRegion = CV::PixelBoundingBox()) override;
148 
149  /**
150  * Returns the id of the color texture.
151  * @return The OpenGL id of the color texture of this framebuffer.
152  */
153  inline GLuint colorTextureId() const;
154 
155  /**
156  * Returns the id of the depth texture.
157  * @return The OpenGL id of the depth texture of this framebuffer.
158  */
159  inline GLuint depthTextureId() const;
160 
161  /**
162  * Returns whether the texture framebuffer is ready for use.
163  * @return True, if so
164  */
165  bool isValid() const override;
166 
167  protected:
168 
169  /**
170  * Creates a new GLESceneGraph texture object.
171  */
173 
174  /**
175  * Destructs a GLESceneGraph texture object.
176  */
178 
179  /**
180  * Releases this texture framebuffer.
181  */
182  void release();
183 
184  /**
185  * Updates the mipmap for this texture.
186  * @see GLESTexture::createMipmap().
187  */
188  void createMipmap() override;
189 
190 #ifdef OCEAN_PLATFORM_BUILD_APPLE_IOS_ANY
191 
192  /**
193  * Creates a texture for the framebuffer on iOS platforms.
194  * @param width The width of the texture, in pixel
195  * @param height The height of the texture, in pixel
196  * @param textureInternalFormat The internal texture format
197  * @param textureFormat The texture format
198  * @param textureType The texture type
199  * @return True, if succeeded
200  */
201  bool createTextureForFramebufferAppleIOS(const unsigned int width, const unsigned int height, const GLint textureInternalFormat, const GLenum textureFormat, const GLenum textureType);
202 
203 #endif // OCEAN_PLATFORM_BUILD_APPLE
204 
205  protected:
206 
207  /// The id of the framebuffer object.
208  GLuint framebufferObjectId_ = 0u;
209 
210  /// The id of the color texture.
211  GLuint colorTextureId_ = 0u;
212 
213  /// The id of the depth texture.
214  GLuint depthTextureId_ = 0u;
215 
216  /// The width of the texture framebuffer in pixel, with range [0, infinity).
217  unsigned int width_ = 0u;
218 
219  /// The height of the texture framebuffer in pixel, with range [0, infinity).
220  unsigned int height_ = 0u;
221 
222  /// The number of multi samples the framebuffer will apply, with range [1, infinity).
223  unsigned int framebufferMultisamples_ = 1u;
224 
225  /// The texture's pixel format.
227 
228  /// The texture wrap s type.
229  WrapType wrapTypeS_ = WRAP_CLAMP;
230 
231  /// The texture wrap t type.
232  WrapType wrapTypeT_ = WRAP_CLAMP;
233 
234  /// The optional texture with one samples, needed when copying the content of the multi sample framebuffer (or depth framebuffer with OpenGLES) to memory.
236 
237  /// The optional shader program object, needed when copying the content of the multi sample framebuffer (or depth framebuffer with OpenGLES) to memory.
239 
240  /// The optional vertex set object, needed when copying the content of the multi sample framebuffer (or depth framebuffer with OpenGLES) to memory.
242 
243  /// The optional triangles object, needed when copying the content of the multi sample framebuffer (or depth framebuffer with OpenGLES) to memory.
245 
246  /// The name of the texture in the shader.
247  std::string textureName_ = std::string("primaryTexture");
248 
249 #ifdef OCEAN_PLATFORM_BUILD_APPLE_IOS_ANY
250 
251  /// The texture cache on iOS platforms, if supported.
252  CVOpenGLESTextureCacheRef iosTextureCache_ = nullptr;
253 
254  /// The pixel buffer on iOS platforms, if supported.
255  CVPixelBufferRef iosPixelBuffer_ = nullptr;
256 
257  /// The texture on iOS platforms, if supported.
258  CVOpenGLESTextureRef iosTexture_ = nullptr;
259 
260 #endif // OCEAN_PLATFORM_BUILD_APPLE_IOS_ANY
261 
262 #ifdef OCEAN_PLATFORM_BUILD_WINDOWS
263 
264  /// The function pointer to glBlitFramebuffer.
265  PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer_ = nullptr;
266 
267 #endif // OCEAN_PLATFORM_BUILD_WINDOWS
268 };
269 
270 inline unsigned int GLESTextureFramebuffer::width() const
271 {
272  return width_;
273 }
274 
275 inline unsigned int GLESTextureFramebuffer::height() const
276 {
277  return height_;
278 }
279 
281 {
282  return colorTextureId_;
283 }
284 
286 {
287  return depthTextureId_;
288 }
289 
290 }
291 
292 }
293 
294 }
295 
296 #endif // META_OCEAN_RENDERING_GLES_TEXTURE_FRAMEBUFFER_H
This class implements Ocean's image class.
Definition: Frame.h:1792
PixelFormat
Definition of all pixel formats available in the Ocean framework.
Definition: Frame.h:183
@ FORMAT_RGBA32
Pixel format with byte order RGBA and 32 bits per pixel.
Definition: Frame.h:382
This class implements a class factory for all GLESceneGraph objects.
Definition: GLESFactory.h:30
This class implements a container for an OpenGL ES shader program.
Definition: GLESShaderProgram.h:53
This class is the base class for all GLESceneGraph texture framebuffer objects.
Definition: GLESTextureFramebuffer.h:39
bool setWrapTypeT(const WrapType type) override
Sets the texture wrap type in t direction.
bool setPixelFormat(const FrameType::PixelFormat pixelFormat) override
Sets the texture framebuffer's internal pixel format.
GLuint depthTextureId_
The id of the depth texture.
Definition: GLESTextureFramebuffer.h:214
bool setWrapTypeS(const WrapType type) override
Sets the texture wrap type in s direction.
ShaderProgramRef shaderProgramForOneSample_
The optional shader program object, needed when copying the content of the multi sample framebuffer (...
Definition: GLESTextureFramebuffer.h:238
GLuint colorTextureId() const
Returns the id of the color texture.
Definition: GLESTextureFramebuffer.h:280
VertexSetRef vertexSetForOneSample_
The optional vertex set object, needed when copying the content of the multi sample framebuffer (or d...
Definition: GLESTextureFramebuffer.h:241
GLESTextureFramebuffer()
Creates a new GLESceneGraph texture object.
unsigned int height() const
Returns the height of this framebuffer.
Definition: GLESTextureFramebuffer.h:275
unsigned int width_
The width of the texture framebuffer in pixel, with range [0, infinity).
Definition: GLESTextureFramebuffer.h:217
bool copyDepthTextureToFrame(Frame &frame, const CV::PixelBoundingBox &subRegion=CV::PixelBoundingBox()) override
Copies the image content of the depth texture to a given frame.
TextureFramebufferRef textureFramebufferOneSample_
The optional texture with one samples, needed when copying the content of the multi sample framebuffe...
Definition: GLESTextureFramebuffer.h:235
FrameType::PixelFormat pixelFormat() const override
Returns the texture framebuffer's internal pixel format.
WrapType wrapTypeT() const override
Returns the texture wrap type in t direction.
unsigned int width() const
Returns the width of this framebuffer.
Definition: GLESTextureFramebuffer.h:270
GLuint depthTextureId() const
Returns the id of the depth texture.
Definition: GLESTextureFramebuffer.h:285
WrapType wrapTypeS() const override
Returns the texture wrap type in s direction.
GLuint colorTextureId_
The id of the color texture.
Definition: GLESTextureFramebuffer.h:211
std::string textureName() const override
Returns the name of the texture e.g., in a shader.
~GLESTextureFramebuffer() override
Destructs a GLESceneGraph texture object.
unsigned int bindTexture(GLESShaderProgram &shaderProgram, const unsigned int id) override
Binds this texture.
bool copyColorTextureToFrame(Frame &frame, const CV::PixelBoundingBox &subRegion=CV::PixelBoundingBox()) override
Copies the image content of the color texture to a given frame.
bool createTextureForFramebufferAppleIOS(const unsigned int width, const unsigned int height, const GLint textureInternalFormat, const GLenum textureFormat, const GLenum textureType)
Creates a texture for the framebuffer on iOS platforms.
TrianglesRef trianglesForOneSample_
The optional triangles object, needed when copying the content of the multi sample framebuffer (or de...
Definition: GLESTextureFramebuffer.h:244
bool isValid() const override
Returns whether the texture framebuffer is ready for use.
bool setMultisamples(const unsigned int multisamples)
Sets the number of multi-samples.
bool setTextureName(const std::string &name) override
Sets the name of the texture e.g., in a shader.
void createMipmap() override
Updates the mipmap for this texture.
bool resize(const unsigned int width, const unsigned int height) override
Resizes the texture framebuffer.
unsigned int height_
The height of the texture framebuffer in pixel, with range [0, infinity).
Definition: GLESTextureFramebuffer.h:220
void release()
Releases this texture framebuffer.
This class is the base class for all GLESceneGraph texture objects.
Definition: GLESTexture.h:37
This class is the base class for all textures based on a framebuffer.
Definition: rendering/TextureFramebuffer.h:39
WrapType
Definition of different texture wrapping types.
Definition: rendering/Texture.h:96
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15