GLW
Computer Graphics Structures library
FrameBuffer.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef GLW_FRAME_BUFFER_H
7 #define GLW_FRAME_BUFFER_H
8 #include <glm/glm.hpp>
9 #include <glbinding/gl/gl.h>
10 #include <string>
11 #include <vector>
12 #include <GLW/Texture.h>
13 
14 namespace glw
15 {
16 
17  using PFrameBuffer = std::shared_ptr<class FrameBuffer>;
18 
20  class GLW_API FrameBuffer
21  {
22  public:
23 
25  enum class DepthBufferType
26  {
27  none = 0,
28  hidden = 1,
29  texture = 2
30  };
31 
33  struct Settings
34  {
36  uint32_t width{ 0 };
38  uint32_t height{ 0 };
40  bool multisample_enabled{ false };
42  uint32_t multisample_samples{ 4 };
44  DepthBufferType depth_buffer_type{ DepthBufferType::hidden };
48  std::vector<gl::GLenum> color_format;
49  Settings() = default;
50  };
51 
58  static PFrameBuffer Create(const FrameBuffer::Settings &settings);
59 
64  FrameBuffer(const FrameBuffer::Settings &settings);
65 
67  ~FrameBuffer();
68 
69  bool IsGood() const;
70 
71  const FrameBuffer::Settings &GetSettings() const;
72 
74  void Bind() const;
75 
77  void Unbind() const;
78 
80  size_t GetTextureCount() const;
81 
83  PTexture GetTexture(size_t texture_id = 0) const;
84 
86  PTexture2D GetTexture2D(size_t texture_id = 0) const;
87 
89  PTexture GetDepthTexture() const;
90 
92  PTexture2D GetDepthTexture2D() const;
93 
95  void BindTextures() const;
96 
98  glm::uvec2 GetResolution() const;
99 
101  uint32_t GetWidth() const;
102 
104  uint32_t GetHeight() const;
105 
107  gl::GLuint GetId() const;
108 
110  bool CopyTo(const PFrameBuffer &dest) const;
111 
113  PFrameBuffer Clone() const;
114 
116  static bool TestMaxColorAttachments(int32_t color_att_count);
117 
119  static bool TestOpenGLVersion();
120 
121  private:
122  FrameBuffer(const FrameBuffer &) = delete;
123 
124  Settings settings_;
125  bool is_good_{ false };
126  gl::GLuint fbo_id_{ 0 };
127  gl::GLuint depth_renderbuffer_id_{ 0 };
128  PTexture depth_texture_{ nullptr };
129  std::vector<PTexture> color_textures_;
130 
131  };
132 
133 }
134 
135 #endif /* !GLW_FRAME_BUFFER_H */
OpenGL wrapper library namespace. Provides simplified interface for using OpenGL features.
Definition: API.h:17
DepthDataFormat
Definition: Texture.h:95
range < 0.0, 1.0> internally represented as 24 bit unsigned integral number
std::vector< gl::GLenum > color_format
Color format for every color attachment. Vector size defines number of attachments.
Definition: FrameBuffer.h:48
DepthBufferType
Possible depth buffer types.
Definition: FrameBuffer.h:25
Settings defining frame buffer properties.
Definition: FrameBuffer.h:33
Class used to store buffers for internal rendering.
Definition: FrameBuffer.h:20