Ocean
FramebufferObject.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_PLATFORM_GL_FRAMEBUFFER_OBJECT_H
9 #define META_OCEAN_PLATFORM_GL_FRAMEBUFFER_OBJECT_H
10 
11 #include "ocean/platform/gl/GL.h"
14 
15 namespace Ocean
16 {
17 
18 namespace Platform
19 {
20 
21 namespace GL
22 {
23 
24 /**
25  * This class implements a frame buffer objects that may be used for rendering to texture.
26  * The current implementation covers 2D textures as render targets only and does not provide a depth buffer.
27  * @ingroup platformgl
28  */
29 class OCEAN_PLATFORM_GL_EXPORT FramebufferObject : public ContextAssociated
30 {
31  friend class ScopedRenderToTexture;
32 
33  public:
34 
35  /**
36  * Scoped object simplifying the rendering to a texture.
37  */
38  class OCEAN_PLATFORM_GL_EXPORT ScopedRenderToTexture
39  {
40  public:
41 
42  /**
43  * Creates a new scoped render to texture object.
44  * @param framebufferObject Frame buffer object instance
45  * @param texture The texture into which is rendered
46  */
47  inline ScopedRenderToTexture(FramebufferObject& framebufferObject, Texture& texture);
48 
49  /**
50  * Destroys the scoped render to texture object.
51  */
52  inline ~ScopedRenderToTexture();
53 
54  /**
55  * Explicitly releases the scoped object and unbinds the associated render target (already before the scope ends).
56  */
57  inline void release();
58 
59  protected:
60 
61  /**
62  * Disabled copy constructor.
63  * @param object The object that would be copied
64  */
66 
67  /**
68  * The disabled assign operator.
69  * @param object The object that would be assigned
70  */
72 
73  protected:
74 
75  /// Framebuffer object for rendering to texture
77  };
78 
79  public:
80 
81  /**
82  * Creates a new frame buffer object.
83  */
85 
86  /**
87  * Destroys the frame buffer object
88  */
89  virtual ~FramebufferObject();
90 
91  /**
92  * Releases the frame buffer object.
93  */
94  void release();
95 
96  protected:
97 
98  /**
99  * Binds the specified texture as render target.
100  * @param texture The texture which will be used as render target
101  */
102  void bindRenderTarget(Texture& texture);
103 
104  /**
105  * Unbinds the render target from a frame buffer.
106  */
108 
109  protected:
110 
111  /// The id of the framebuffer object.
113 
114  /// The viewport coordinates set before changing the render target.
115  GLint framebufferOldViewportCoordinates[4];
116 
117  /// Indicates if the frame buffer object is currently used for rendering into a texture.
119 };
120 
122  scopedFramebufferObject(&framebufferObject)
123 {
125 }
126 
128 {
129  release();
130 }
131 
133 {
134  if (scopedFramebufferObject)
135  {
136  scopedFramebufferObject->unbindRenderTarget();
137  scopedFramebufferObject = nullptr;
138  }
139 }
140 
141 }
142 
143 }
144 
145 }
146 
147 #endif // FACEBOOK_PLATOFRM_GL_FRAMEBUFFER_OBJECT_H
This class implements the base class for all object which have an associated context.
Definition: ContextAssociated.h:31
Scoped object simplifying the rendering to a texture.
Definition: FramebufferObject.h:39
void release()
Explicitly releases the scoped object and unbinds the associated render target (already before the sc...
Definition: FramebufferObject.h:132
~ScopedRenderToTexture()
Destroys the scoped render to texture object.
Definition: FramebufferObject.h:127
ScopedRenderToTexture(FramebufferObject &framebufferObject, Texture &texture)
Creates a new scoped render to texture object.
Definition: FramebufferObject.h:121
ScopedRenderToTexture & operator=(const ScopedRenderToTexture &object)=delete
The disabled assign operator.
ScopedRenderToTexture(const ScopedRenderToTexture &object)=delete
Disabled copy constructor.
FramebufferObject * scopedFramebufferObject
Framebuffer object for rendering to texture.
Definition: FramebufferObject.h:76
This class implements a frame buffer objects that may be used for rendering to texture.
Definition: FramebufferObject.h:30
void bindRenderTarget(Texture &texture)
Binds the specified texture as render target.
void release()
Releases the frame buffer object.
bool framebufferIsBound
Indicates if the frame buffer object is currently used for rendering into a texture.
Definition: FramebufferObject.h:118
GLuint framebufferObjectId
The id of the framebuffer object.
Definition: FramebufferObject.h:112
virtual ~FramebufferObject()
Destroys the frame buffer object.
void unbindRenderTarget()
Unbinds the render target from a frame buffer.
FramebufferObject()
Creates a new frame buffer object.
This class implements a 2D OpenGL texture.
Definition: platform/gl/Texture.h:30
void release(T *object)
This functions allows to release a DirectShow object if it does exist.
Definition: DSObject.h:266
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15