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 // TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
3 // All rights reserved. See LICENSE.txt for license.
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  /// Resize the framebuffer
35  void resize(unsigned int width, unsigned int height);
36 
37  /// Set the encode sRGB flag, which controls whether values written
38  /// to the framebuffer are encoded to the sRGB color space.
39  void setEncodeSrgb(bool encode)
40  {
41  _encodeSrgb = encode;
42  }
43 
44  /// Return the encode sRGB flag.
46  {
47  return _encodeSrgb;
48  }
49 
50  /// Bind the framebuffer for rendering.
51  void bind();
52 
53  /// Unbind the frame buffer after rendering.
54  void unbind();
55 
56  /// Return our color texture handle.
57  unsigned int getColorTexture() const
58  {
59  return _colorTexture;
60  }
61 
62  /// Return our depth texture handle.
63  unsigned int getDepthTexture() const
64  {
65  return _depthTexture;
66  }
67 
68  /// Return the color data of this framebuffer as an image.
69  /// If an input image is provided, it will be used to store the color data;
70  /// otherwise a new image of the required format will be created.
71  ImagePtr getColorImage(ImagePtr image = nullptr);
72 
73  /// Blit our color texture to the back buffer.
74  void blit();
75 
76  protected:
77  GLFramebuffer(unsigned int width, unsigned int height, unsigned int channelCount, Image::BaseType baseType);
78 
79  protected:
80  unsigned int _width;
81  unsigned int _height;
82  unsigned int _channelCount;
85 
86  unsigned int _framebuffer;
87  unsigned int _colorTexture;
88  unsigned int _depthTexture;
89 };
90 
92 
93 #endif
unsigned int _colorTexture
Definition: GLFramebuffer.h:87
unsigned int _channelCount
Definition: GLFramebuffer.h:82
unsigned int getDepthTexture() const
Return our depth texture handle.
Definition: GLFramebuffer.h:63
unsigned int getColorTexture() const
Return our color texture handle.
Definition: GLFramebuffer.h:57
std::shared_ptr< GLFramebuffer > GLFramebufferPtr
Shared pointer to a GLFramebuffer.
Definition: GLFramebuffer.h:21
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:23
GLenum GLsizei GLenum GLenum const void * image
Definition: glew.h:4973
void setEncodeSrgb(bool encode)
Definition: GLFramebuffer.h:39
BaseType
Definition: Image.h:45
#define MX_RENDERGLSL_API
Definition: Export.h:18
GLint GLsizei width
Definition: glcorearb.h:103
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
bool getEncodeSrgb()
Return the encode sRGB flag.
Definition: GLFramebuffer.h:45
unsigned int _depthTexture
Definition: GLFramebuffer.h:88
unsigned int _height
Definition: GLFramebuffer.h:81
ImageBuf OIIO_API resize(const ImageBuf &src, string_view filtername="", float filterwidth=0.0f, ROI roi={}, int nthreads=0)
unsigned int _framebuffer
Definition: GLFramebuffer.h:86
Image::BaseType _baseType
Definition: GLFramebuffer.h:83
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:24
shared_ptr< Image > ImagePtr
A shared pointer to an image.
Definition: Image.h:23
unsigned int _width
Definition: GLFramebuffer.h:80