| globjects 1.0.0.000000000000 Strict OpenGL objects wrapper.

Framebuffer.h
Go to the documentation of this file.
1
2 #pragma once
3
4 #include <map>
5 #include <string>
6 #include <vector>
7 #include <array>
8
9 #include <glm/fwd.hpp>
10
11 #include <globjects/base/ref_ptr.h>
12
13 #include <globjects/globjects_api.h>
14 #include <globjects/Object.h>
15
16
17 namespace globjects
18 {
19
20
21 class FramebufferAttachment;
22 class Renderbuffer;
23 class Texture;
24 class Buffer;
25
46 class GLOBJECTS_API Framebuffer : public Object
47 {
48 public:
49 enum class BindlessImplementation
50 {
51 DirectStateAccessARB
52 , DirectStateAccessEXT
53 , Legacy
54 };
55
56 static void hintBindlessImplementation(BindlessImplementation impl);
57
58 public:
59 Framebuffer();
60 static Framebuffer * fromId(gl::GLuint id);
61
62 static Framebuffer * defaultFBO();
63
64 virtual void accept(ObjectVisitor& visitor) override;
65
68 void bind() const;
69 void bind(gl::GLenum target) const;
70
73 static void unbind();
74 static void unbind(gl::GLenum target);
75
76 void setParameter(gl::GLenum pname, gl::GLint param);
77 gl::GLint getAttachmentParameter(gl::GLenum attachment, gl::GLenum pname) const;
78
79 void attachTexture(gl::GLenum attachment, Texture * texture, gl::GLint level = 0);
80 void attachTextureLayer(gl::GLenum attachment, Texture * texture, gl::GLint level = 0, gl::GLint layer = 0);
81 void attachRenderBuffer(gl::GLenum attachment, Renderbuffer * renderBuffer);
82
83 bool detach(gl::GLenum attachment);
84
85 void setReadBuffer(gl::GLenum mode) const;
86 void setDrawBuffer(gl::GLenum mode) const;
87 void setDrawBuffers(gl::GLsizei n, const gl::GLenum * modes) const;
88 void setDrawBuffers(const std::vector<gl::GLenum> & modes) const;
89
90 void clear(gl::ClearBufferMask mask);
91
92 void clearBufferiv(gl::GLenum buffer, gl::GLint drawBuffer, const gl::GLint * value);
93 void clearBufferuiv(gl::GLenum buffer, gl::GLint drawBuffer, const gl::GLuint * value);
94 void clearBufferfv(gl::GLenum buffer, gl::GLint drawBuffer, const gl::GLfloat * value);
95 void clearBufferfi(gl::GLenum buffer, gl::GLint drawBuffer, gl::GLfloat depth, gl::GLint stencil);
96
97 void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const glm::ivec4 & value);
98 void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const glm::uvec4 & value);
99 void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const glm::vec4 & value);
100
101 static void colorMask(gl::GLboolean red, gl::GLboolean green, gl::GLboolean blue, gl::GLboolean alpha);
102 static void colorMask(const glm::bvec4 & mask);
103 static void colorMaski(gl::GLuint buffer, gl::GLboolean red, gl::GLboolean green, gl::GLboolean blue, gl::GLboolean alpha);
104 static void colorMaski(gl::GLuint buffer, const glm::bvec4 & mask);
105 static void clearColor(gl::GLfloat red, gl::GLfloat green, gl::GLfloat blue, gl::GLfloat alpha);
106 static void clearColor(const glm::vec4 & color);
107 static void clearDepth(gl::GLclampd depth);
108
109 void readPixels(gl::GLint x, gl::GLint y, gl::GLsizei width, gl::GLsizei height, gl::GLenum format, gl::GLenum type, gl::GLvoid * data = nullptr) const;
110 void readPixels(const std::array<gl::GLint, 4> & rect, gl::GLenum format, gl::GLenum type, gl::GLvoid * data = nullptr) const;
111 void readPixels(gl::GLenum readBuffer, const std::array<gl::GLint, 4> & rect, gl::GLenum format, gl::GLenum type, gl::GLvoid * data = nullptr) const;
112 std::vector<unsigned char> readPixelsToByteArray(const std::array<gl::GLint, 4> & rect, gl::GLenum format, gl::GLenum type) const;
113 std::vector<unsigned char> readPixelsToByteArray(gl::GLenum readBuffer, const std::array<gl::GLint, 4> & rect, gl::GLenum format, gl::GLenum type) const;
114 void readPixelsToBuffer(const std::array<gl::GLint, 4> & rect, gl::GLenum format, gl::GLenum type, Buffer * pbo) const;
115
116 gl::GLenum checkStatus() const;
117 std::string statusString() const;
118 void printStatus(bool onlyErrors = false) const;
119
120 FramebufferAttachment * getAttachment(gl::GLenum attachment);
121 std::vector<FramebufferAttachment*> attachments();
122
123 void blit(gl::GLenum readBuffer, const std::array<gl::GLint, 4> & srcRect, Framebuffer * destFbo, gl::GLenum drawBuffer, const std::array<gl::GLint, 4> & destRect, gl::ClearBufferMask mask, gl::GLenum filter) const;
124 void blit(gl::GLenum readBuffer, const std::array<gl::GLint, 4> & srcRect, Framebuffer * destFbo, const std::vector<gl::GLenum> & drawBuffers, const std::array<gl::GLint, 4> & destRect, gl::ClearBufferMask mask, gl::GLenum filter) const;
125
126 virtual gl::GLenum objectType() const override;
127
128 protected:
129 Framebuffer(IDResource * resource);
130 virtual ~Framebuffer();
131
132 void addAttachment(FramebufferAttachment * attachment);
133
134 static void blit(gl::GLint srcX0, gl::GLint srcY0, gl::GLint srcX1, gl::GLint srcY1, gl::GLint destX0, gl::GLint destY0, gl::GLint destX1, gl::GLint destY1, gl::ClearBufferMask mask, gl::GLenum filter);
135 static void blit(const std::array<gl::GLint, 4> & srcRect, const std::array<gl::GLint, 4> & destRect, gl::ClearBufferMask mask, gl::GLenum filter);
136
137 protected:
138 std::map<gl::GLenum, ref_ptr<FramebufferAttachment>> m_attachments;
139 };
140
141
142 } // namespace globjects
globjects::Renderbuffer
Encapsulates OpenGL render buffer objects.
Definition: Renderbuffer.h:18
globjects::Framebuffer::m_attachments
std::map< gl::GLenum, ref_ptr< FramebufferAttachment > > m_attachments
Definition: Framebuffer.h:138
globjects::Framebuffer::BindlessImplementation
BindlessImplementation
Definition: Framebuffer.h:49
globjects
Contains all the classes that wrap OpenGL functionality.
globjects::Object
Superclass of all wrapped OpenGL objects.
Definition: Object.h:26
ref_ptr.h
globjects::FramebufferAttachment
Wraps attachments to a FrameBufferObject.
Definition: FramebufferAttachment.h:29
globjects::Buffer
Wrapper for OpenGL buffer objects.
Definition: Buffer.h:35
globjects::ObjectVisitor
Implements a Visitor Pattern to iterate over all tracked globjects objects.
Definition: ObjectVisitor.h:29
Object.h
globjects::Framebuffer
Enables creation of arbitrary render targets that are not directly drawn on the screen.
Definition: Framebuffer.h:46
globjects::Texture
Wraps OpenGL texture objects. A Texture provides both interfaces to bind them for the OpenGL pipeline...
Definition: Texture.h:30