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
12
13#include <globjects/globjects_api.h>
14#include <globjects/Object.h>
15
16
17namespace globjects
18{
19
20
21class FramebufferAttachment;
22class Renderbuffer;
23class Texture;
24class Buffer;
25
46class GLOBJECTS_API Framebuffer : public Object
47{
48public:
50 {
51 DirectStateAccessARB
52 , DirectStateAccessEXT
53 , Legacy
54 };
55
57
58public:
60 static Framebuffer * fromId(gl::GLuint id);
61
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
128protected:
129 Framebuffer(IDResource * resource);
130 virtual ~Framebuffer();
131
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
137protected:
138 std::map<gl::GLenum, ref_ptr<FramebufferAttachment>> m_attachments;
139};
140
141
142} // namespace globjects
Wrapper for OpenGL buffer objects.
Definition: Buffer.h:36
Wraps attachments to a FrameBufferObject.
Definition: FramebufferAttachment.h:30
Enables creation of arbitrary render targets that are not directly drawn on the screen.
Definition: Framebuffer.h:47
void clearBufferiv(gl::GLenum buffer, gl::GLint drawBuffer, const gl::GLint *value)
std::vector< unsigned char > readPixelsToByteArray(gl::GLenum readBuffer, const std::array< gl::GLint, 4 > &rect, gl::GLenum format, gl::GLenum type) const
BindlessImplementation
Definition: Framebuffer.h:50
gl::GLint getAttachmentParameter(gl::GLenum attachment, gl::GLenum pname) const
std::vector< unsigned char > readPixelsToByteArray(const std::array< gl::GLint, 4 > &rect, gl::GLenum format, gl::GLenum type) const
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
static Framebuffer * fromId(gl::GLuint id)
void readPixels(const std::array< gl::GLint, 4 > &rect, gl::GLenum format, gl::GLenum type, gl::GLvoid *data=nullptr) const
void clearBufferfv(gl::GLenum buffer, gl::GLint drawBuffer, const gl::GLfloat *value)
void setDrawBuffers(gl::GLsizei n, const gl::GLenum *modes) const
static void colorMask(gl::GLboolean red, gl::GLboolean green, gl::GLboolean blue, gl::GLboolean alpha)
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
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)
void clearBufferfi(gl::GLenum buffer, gl::GLint drawBuffer, gl::GLfloat depth, gl::GLint stencil)
void setDrawBuffer(gl::GLenum mode) const
void readPixelsToBuffer(const std::array< gl::GLint, 4 > &rect, gl::GLenum format, gl::GLenum type, Buffer *pbo) const
static void blit(const std::array< gl::GLint, 4 > &srcRect, const std::array< gl::GLint, 4 > &destRect, gl::ClearBufferMask mask, gl::GLenum filter)
void attachTextureLayer(gl::GLenum attachment, Texture *texture, gl::GLint level=0, gl::GLint layer=0)
static void colorMaski(gl::GLuint buffer, gl::GLboolean red, gl::GLboolean green, gl::GLboolean blue, gl::GLboolean alpha)
static void clearColor(gl::GLfloat red, gl::GLfloat green, gl::GLfloat blue, gl::GLfloat alpha)
void attachTexture(gl::GLenum attachment, Texture *texture, gl::GLint level=0)
gl::GLenum checkStatus() const
Framebuffer(IDResource *resource)
void setParameter(gl::GLenum pname, gl::GLint param)
static void unbind(gl::GLenum target)
bool detach(gl::GLenum attachment)
virtual void accept(ObjectVisitor &visitor) override
void attachRenderBuffer(gl::GLenum attachment, Renderbuffer *renderBuffer)
virtual gl::GLenum objectType() const override
static void clearDepth(gl::GLclampd depth)
static void hintBindlessImplementation(BindlessImplementation impl)
void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const glm::ivec4 &value)
void setDrawBuffers(const std::vector< gl::GLenum > &modes) const
static void clearColor(const glm::vec4 &color)
std::string statusString() const
FramebufferAttachment * getAttachment(gl::GLenum attachment)
std::map< gl::GLenum, ref_ptr< FramebufferAttachment > > m_attachments
Definition: Framebuffer.h:138
std::vector< FramebufferAttachment * > attachments()
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
void printStatus(bool onlyErrors=false) const
void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const glm::uvec4 &value)
static void colorMaski(gl::GLuint buffer, const glm::bvec4 &mask)
static void unbind()
void setReadBuffer(gl::GLenum mode) const
static void colorMask(const glm::bvec4 &mask)
void clear(gl::ClearBufferMask mask)
void clearBufferuiv(gl::GLenum buffer, gl::GLint drawBuffer, const gl::GLuint *value)
void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const glm::vec4 &value)
void readPixels(gl::GLenum readBuffer, const std::array< gl::GLint, 4 > &rect, gl::GLenum format, gl::GLenum type, gl::GLvoid *data=nullptr) const
void bind(gl::GLenum target) const
static Framebuffer * defaultFBO()
void addAttachment(FramebufferAttachment *attachment)
Superclass of all wrapped OpenGL objects.
Definition: Object.h:27
Implements a Visitor Pattern to iterate over all tracked globjects objects.
Definition: ObjectVisitor.h:30
Encapsulates OpenGL render buffer objects.
Definition: Renderbuffer.h:19
Wraps OpenGL texture objects. A Texture provides both interfaces to bind them for the OpenGL pipeline...
Definition: Texture.h:31
Contains all the classes that wrap OpenGL functionality.