HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GLFramebuffer.h
Go to the documentation of this file.
1 //
2 // Copyright Contributors to the MaterialX Project
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 
6 #ifndef MATERIALX_GLFRAMEBUFFER_H
7 #define MATERIALX_GLFRAMEBUFFER_H
8 
9 /// @file
10 /// OpenGL framebuffer handling
11 
13 
15 
17 
18 class GLFramebuffer;
19 
20 /// Shared pointer to a GLFramebuffer
21 using GLFramebufferPtr = std::shared_ptr<GLFramebuffer>;
22 
23 /// @class GLFramebuffer
24 /// Wrapper for an OpenGL framebuffer
26 {
27  public:
28  /// Create a new framebuffer
29  static GLFramebufferPtr create(unsigned int width, unsigned int height, unsigned int channelCount, Image::BaseType baseType);
30 
31  /// Destructor
32  virtual ~GLFramebuffer();
33 
34  /// Return the width of the framebuffer.
35  unsigned int getWidth() const
36  {
37  return _width;
38  }
39 
40  /// Return the height of the framebuffer.
41  unsigned int getHeight() const
42  {
43  return _height;
44  }
45 
46  /// Set the encode sRGB flag, which controls whether values written
47  /// to the framebuffer are encoded to the sRGB color space.
48  void setEncodeSrgb(bool encode)
49  {
50  _encodeSrgb = encode;
51  }
52 
53  /// Return the encode sRGB flag.
55  {
56  return _encodeSrgb;
57  }
58 
59  /// Bind the framebuffer for rendering.
60  void bind();
61 
62  /// Unbind the frame buffer after rendering.
63  void unbind();
64 
65  /// Return our color texture handle.
66  unsigned int getColorTexture() const
67  {
68  return _colorTexture;
69  }
70 
71  /// Return our depth texture handle.
72  unsigned int getDepthTexture() const
73  {
74  return _depthTexture;
75  }
76 
77  /// Return the color data of this framebuffer as an image.
78  /// If an input image is provided, it will be used to store the color data;
79  /// otherwise a new image of the required format will be created.
80  ImagePtr getColorImage(ImagePtr image = nullptr);
81 
82  /// Blit our color texture to the back buffer.
83  void blit();
84 
85  protected:
86  GLFramebuffer(unsigned int width, unsigned int height, unsigned int channelCount, Image::BaseType baseType);
87 
88  protected:
89  unsigned int _width;
90  unsigned int _height;
91  unsigned int _channelCount;
94 
95  unsigned int _framebuffer;
96  unsigned int _colorTexture;
97  unsigned int _depthTexture;
98 };
99 
101 
102 #endif
unsigned int _colorTexture
Definition: GLFramebuffer.h:96
unsigned int _channelCount
Definition: GLFramebuffer.h:91
unsigned int getDepthTexture() const
Return our depth texture handle.
Definition: GLFramebuffer.h:72
unsigned int getColorTexture() const
Return our color texture handle.
Definition: GLFramebuffer.h:66
std::shared_ptr< GLFramebuffer > GLFramebufferPtr
Shared pointer to a GLFramebuffer.
Definition: GLFramebuffer.h:21
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
unsigned int getWidth() const
Return the width of the framebuffer.
Definition: GLFramebuffer.h:35
GLenum GLenum GLsizei void * image
Definition: glad.h:5132
unsigned int getHeight() const
Return the height of the framebuffer.
Definition: GLFramebuffer.h:41
void setEncodeSrgb(bool encode)
Definition: GLFramebuffer.h:48
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
BaseType
Definition: Image.h:48
#define MX_RENDERGLSL_API
Definition: Export.h:18
bool getEncodeSrgb()
Return the encode sRGB flag.
Definition: GLFramebuffer.h:54
unsigned int _depthTexture
Definition: GLFramebuffer.h:97
unsigned int _height
Definition: GLFramebuffer.h:90
unsigned int _framebuffer
Definition: GLFramebuffer.h:95
Image::BaseType _baseType
Definition: GLFramebuffer.h:92
GLint GLsizei width
Definition: glcorearb.h:103
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
shared_ptr< Image > ImagePtr
A shared pointer to an image.
Definition: Image.h:23
unsigned int _width
Definition: GLFramebuffer.h:89