Ocean
platform/gl/Framebuffer.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_GL_FRAMEBUFFER_H
9 #define META_OCEAN_PLATFORM_GL_GL_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 the base class for an OpenGL framebuffers.
27  * @ingroup platformgl
28  */
29 class OCEAN_PLATFORM_GL_EXPORT Framebuffer : public ContextAssociated
30 {
31  public:
32 
33  /**
34  * Destructs a framebuffer object.
35  */
36  virtual ~Framebuffer();
37 
38  /**
39  * Returns the width of this framebuffer in pixel.
40  * @return The framebuffer's width, with range [0, infinity)
41  */
42  inline unsigned int width() const;
43 
44  /**
45  * Returns the height of this framebuffer in pixel.
46  * @return The framebuffer's height, with range [0, infinity)
47  */
48  inline unsigned int height() const;
49 
50  /**
51  * Returns the internal format of this framebuffer.
52  * @return The framebuffer's internal format
53  */
54  inline GLenum internalFormat() const;
55 
56  /**
57  * Resizes the off-screen framebuffer.
58  * @param width The width of the framebuffer in pixel, with range [0, infinity)
59  * @param height The height of the framebuffer in pixel, with range [0, infinity)
60  * @param internalFormat The internal format of the framebuffer
61  * @return True, if succeeded
62  */
63  virtual bool resize(const unsigned int width, const unsigned int height, const GLenum internalFormat = GL_RGBA8);
64 
65  /**
66  * Binds the framebuffer as target framebuffer.
67  * @return True, if succeeded
68  */
69  virtual bool bind() = 0;
70 
71  /**
72  * Unbinds the framebuffer as target framebuffer.
73  * @return True, if succeeded
74  */
75  virtual bool unbind() = 0;
76 
77  /**
78  * Initializes the OpenGL framebuffer.
79  * @return True, if succeeded
80  */
81  virtual bool initOpenGL();
82 
83  protected:
84 
85  /**
86  * Creates a new framebuffer object which is initially not assocated with any context.
87  */
88  inline Framebuffer();
89 
90  /**
91  * Creates a new framebuffer object.
92  * @param context The OpenGL context which will be associated with the framebuffer
93  */
94  inline Framebuffer(Context& context);
95 
96  /**
97  * Translates an OpenGL framebuffer format to a corresponding pixel format.
98  * @param framebufferFormat The framebuffer format to translate
99  * @return The corresponding pixel format, FORMAT_UNDEFINED if no corresponding pixel format exists
100  */
101  static FrameType::PixelFormat framebufferFormat2pixelFormat(const GLenum framebufferFormat);
102 
103  protected:
104 
105  /// The width of the framebuffer in pixel, with range [0, infinity).
106  unsigned int framebufferWidth;
107 
108  /// The height of the framebuffer in pixel, with range [0, infinity).
109  unsigned int framebufferHeight;
110 
111  /// The internal format of the framebuffer.
113 };
114 
117  framebufferWidth(0u),
118  framebufferHeight(0u),
119  framebufferInternalFormat(0u)
120 {
121  // nothing to do here
122 }
123 
125  ContextAssociated(context),
126  framebufferWidth(0u),
127  framebufferHeight(0u),
128  framebufferInternalFormat(0u)
129 {
130  // nothing to do here
131 }
132 
133 inline unsigned int Framebuffer::width() const
134 {
135  return framebufferWidth;
136 }
137 
138 inline unsigned int Framebuffer::height() const
139 {
140  return framebufferHeight;
141 }
142 
143 inline GLenum Framebuffer::internalFormat() const
144 {
146 }
147 
148 }
149 
150 }
151 
152 }
153 
154 #endif // META_OCEAN_PLATFORM_GL_GL_FRAMEBUFFER_H
PixelFormat
Definition of all pixel formats available in the Ocean framework.
Definition: Frame.h:183
This class implements the base class for all object which have an associated context.
Definition: ContextAssociated.h:31
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
GLenum internalFormat() const
Returns the internal format of this framebuffer.
Definition: platform/gl/Framebuffer.h:143
virtual bool unbind()=0
Unbinds the framebuffer as target framebuffer.
Framebuffer()
Creates a new framebuffer object which is initially not assocated with any context.
Definition: platform/gl/Framebuffer.h:115
unsigned int framebufferWidth
The width of the framebuffer in pixel, with range [0, infinity).
Definition: platform/gl/Framebuffer.h:106
GLenum framebufferInternalFormat
The internal format of the framebuffer.
Definition: platform/gl/Framebuffer.h:112
static FrameType::PixelFormat framebufferFormat2pixelFormat(const GLenum framebufferFormat)
Translates an OpenGL framebuffer format to a corresponding pixel format.
unsigned int height() const
Returns the height of this framebuffer in pixel.
Definition: platform/gl/Framebuffer.h:138
virtual ~Framebuffer()
Destructs a framebuffer object.
virtual bool bind()=0
Binds the framebuffer as target framebuffer.
virtual bool resize(const unsigned int width, const unsigned int height, const GLenum internalFormat=GL_RGBA8)
Resizes the off-screen framebuffer.
unsigned int width() const
Returns the width of this framebuffer in pixel.
Definition: platform/gl/Framebuffer.h:133
virtual bool initOpenGL()
Initializes the OpenGL framebuffer.
unsigned int framebufferHeight
The height of the framebuffer in pixel, with range [0, infinity).
Definition: platform/gl/Framebuffer.h:109
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15