Ocean
MemoryFramebuffer.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_MEMORY_FRAMEBUFFER_H
9 #define META_OCEAN_PLATFORM_GL_MEMORY_FRAMEBUFFER_H
10 
11 #include "ocean/platform/gl/GL.h"
13 
14 #include "ocean/base/Frame.h"
15 
16 namespace Ocean
17 {
18 
19 namespace Platform
20 {
21 
22 namespace GL
23 {
24 
25 /**
26  * This class implements a framebuffer allowing to render into an off-screen framebuffer memory and not into an on-screen framebuffer.
27  * @see setFrame().
28  * @ingroup platformgl
29  */
30 class OCEAN_PLATFORM_GL_EXPORT MemoryFramebuffer : public Framebuffer
31 {
32  public:
33 
34  /**
35  * Creates a new framebuffer object with initially no associated context.
36  */
38 
39  /**
40  * Creates a new framebuffer object with a given associated context.
41  * @param context The associated context
42  */
43  explicit MemoryFramebuffer(Context& context);
44 
45  /**
46  * Destructs this object.
47  */
48  virtual ~MemoryFramebuffer();
49 
50  /**
51  * Returns whether this framebuffer is currently bound.
52  * @return True, if so
53  * @see bind(), unbind().
54  */
55  inline bool isBound() const;
56 
57  /**
58  * Sets the context of this object.
59  * @see Framebuffer::setContext().
60  */
61  virtual bool setContext(Context& context);
62 
63  /**
64  * Sets the frame in which the framebuffer will be copied.
65  * The frame type of the given frame must match with the current dimension and pixel format of the framebuffer.
66  * @param frame The receiving the pixel data from the framebuffer
67  * @return True, if succeeded
68  * @see unsetTargetFrame().
69  */
70  bool setTargetFrame(Frame& frame);
71 
72  /**
73  * Unsets the frame in which the framebuffer will be copied.
74  * @see setTargetFrame().
75  */
76  inline void unsetTargetFrame();
77 
78  /**
79  * Resizes the off-screen framebuffer.
80  * @see Framebuffer::resize().
81  */
82  virtual bool resize(const unsigned int width, const unsigned int height, const GLenum internalFormat = GL_RGBA8);
83 
84  /**
85  * Binds the framebuffer as target framebuffer.
86  * @see Framebuffer::bind(), isBound().
87  */
88  virtual bool bind();
89 
90  /**
91  * Unbinds the framebuffer as target framebuffer.
92  * If a target frame is defined the pixel data of the framebuffer will be copied into the target frame just before the framebuffer is unbound.<br>
93  * @see Framebuffer::unbind(), isBound(), setTargetFrame().
94  */
95  virtual bool unbind();
96 
97  /**
98  * Releases the object.
99  * @return True, if succeeded
100  */
101  bool release();
102 
103  protected:
104 
105  /// The id of the framebuffer object.
107 
108  /// The id of the render buffer.
110 
111  /// The id of the intermediate framebuffer object.
113 
114  /// The id of the intermediate render buffer object.
116 
117  /// True, if this framebuffer is currently bound.
119 
120  /// The frame in which the pixel data from the framebuffer will be copied, if defined
122 };
123 
124 inline bool MemoryFramebuffer::isBound() const
125 {
126  return framebufferIsBound;
127 }
128 
130 {
131  framebufferFrame = nullptr;
132 }
133 
134 
135 }
136 
137 }
138 
139 }
140 
141 #endif // META_OCEAN_PLATFORM_GL_MEMORY_FRAMEBUFFER_H
This class implements Ocean's image class.
Definition: Frame.h:1792
This class encapsulates an OpenGL context.
Definition: platform/gl/Context.h:29
This class implements the base class for an OpenGL framebuffers.
Definition: platform/gl/Framebuffer.h:30
This class implements a framebuffer allowing to render into an off-screen framebuffer memory and not ...
Definition: MemoryFramebuffer.h:31
virtual ~MemoryFramebuffer()
Destructs this object.
GLuint framebufferRenderBufferId
The id of the render buffer.
Definition: MemoryFramebuffer.h:109
GLuint framebufferIntermediateObjectId
The id of the intermediate framebuffer object.
Definition: MemoryFramebuffer.h:112
MemoryFramebuffer()
Creates a new framebuffer object with initially no associated context.
GLuint framebufferIntermediateRenderBufferId
The id of the intermediate render buffer object.
Definition: MemoryFramebuffer.h:115
GLuint framebufferObjectId
The id of the framebuffer object.
Definition: MemoryFramebuffer.h:106
Frame * framebufferFrame
The frame in which the pixel data from the framebuffer will be copied, if defined.
Definition: MemoryFramebuffer.h:121
virtual bool setContext(Context &context)
Sets the context of this object.
bool framebufferIsBound
True, if this framebuffer is currently bound.
Definition: MemoryFramebuffer.h:118
void unsetTargetFrame()
Unsets the frame in which the framebuffer will be copied.
Definition: MemoryFramebuffer.h:129
MemoryFramebuffer(Context &context)
Creates a new framebuffer object with a given associated context.
virtual bool unbind()
Unbinds the framebuffer as target framebuffer.
bool release()
Releases the object.
bool isBound() const
Returns whether this framebuffer is currently bound.
Definition: MemoryFramebuffer.h:124
virtual bool bind()
Binds the framebuffer as target framebuffer.
bool setTargetFrame(Frame &frame)
Sets the frame in which the framebuffer will be copied.
virtual bool resize(const unsigned int width, const unsigned int height, const GLenum internalFormat=GL_RGBA8)
Resizes the off-screen framebuffer.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15