globjects  2.0.0.4363356ae2ef
Strict OpenGL objects wrapper.
Loading...
Searching...
No Matches
Framebuffer.h
Go to the documentation of this file.
1
2#pragma once
3
4
5#include <map>
6#include <string>
7#include <vector>
8#include <array>
9#include <memory>
10
11#include <glm/fwd.hpp>
12
13#include <globjects/globjects_api.h>
14#include <globjects/Object.h>
16
17
18#ifdef GLOBJECTS_USE_EIGEN
19#include <Eigen/Dense>
20#endif
21
22
23namespace globjects
24{
25
26
27class FramebufferAttachment;
28class Renderbuffer;
29class Texture;
30class Buffer;
31
32
53class GLOBJECTS_API Framebuffer : public Object, public Instantiator<Framebuffer>
54{
55public:
57 {
58 Legacy,
59 DirectStateAccessEXT,
60 DirectStateAccessARB
61 };
62
64
65
66public:
68
69 virtual ~Framebuffer();
70
71 static std::unique_ptr<Framebuffer> fromId(gl::GLuint id);
72
73 static std::unique_ptr<Framebuffer> defaultFBO();
74
77 void bind() const;
78 void bind(gl::GLenum target) const;
79
82 static void unbind();
83 static void unbind(gl::GLenum target);
84
85 void setParameter(gl::GLenum pname, gl::GLint param);
86 gl::GLint getAttachmentParameter(gl::GLenum attachment, gl::GLenum pname) const;
87
88 void attachTexture(gl::GLenum attachment, Texture * texture, gl::GLint level = 0);
89 void attachTextureLayer(gl::GLenum attachment, Texture * texture, gl::GLint level = 0, gl::GLint layer = 0);
90 void attachRenderBuffer(gl::GLenum attachment, Renderbuffer * renderBuffer);
91
92 bool detach(gl::GLenum attachment);
93
94 void setReadBuffer(gl::GLenum mode) const;
95 void setDrawBuffer(gl::GLenum mode) const;
96 void setDrawBuffers(gl::GLsizei n, const gl::GLenum * modes) const;
97 void setDrawBuffers(const std::vector<gl::GLenum> & modes) const;
98
99 void clear(gl::ClearBufferMask mask);
100
101 void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const gl::GLint * value);
102 void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const gl::GLuint * value);
103 void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const gl::GLfloat * value);
104 void clearBuffer(gl::GLenum buffer, gl::GLfloat depth, gl::GLint stencil, gl::GLint drawBuffer = 0);
105
106 void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const glm::ivec4 & value);
107 void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const glm::uvec4 & value);
108 void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const glm::vec4 & value);
109 void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, int value);
110 void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, float value);
111
112#ifdef GLOBJECTS_USE_EIGEN
113 void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const Eigen::Vector4i & value);
114 void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const Eigen::Matrix<unsigned, 4, 1> & value);
115 void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const Eigen::Vector4f & value);
116#endif
117
118 static void colorMask(gl::GLboolean red, gl::GLboolean green, gl::GLboolean blue, gl::GLboolean alpha);
119 static void colorMask(const glm::bvec4 & mask);
120 static void colorMaski(gl::GLuint buffer, gl::GLboolean red, gl::GLboolean green, gl::GLboolean blue, gl::GLboolean alpha);
121 static void colorMaski(gl::GLuint buffer, const glm::bvec4 & mask);
122 static void clearColor(gl::GLfloat red, gl::GLfloat green, gl::GLfloat blue, gl::GLfloat alpha);
123 static void clearColor(const glm::vec4 & color);
124 static void clearDepth(gl::GLdouble depth);
125
126 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;
127 void readPixels(const std::array<gl::GLint, 4> & rect, gl::GLenum format, gl::GLenum type, gl::GLvoid * data = nullptr) const;
128 void readPixels(gl::GLenum readBuffer, const std::array<gl::GLint, 4> & rect, gl::GLenum format, gl::GLenum type, gl::GLvoid * data = nullptr) const;
129 std::vector<unsigned char> readPixelsToByteArray(const std::array<gl::GLint, 4> & rect, gl::GLenum format, gl::GLenum type) const;
130 std::vector<unsigned char> readPixelsToByteArray(gl::GLenum readBuffer, const std::array<gl::GLint, 4> & rect, gl::GLenum format, gl::GLenum type) const;
131 void readPixelsToBuffer(const std::array<gl::GLint, 4> & rect, gl::GLenum format, gl::GLenum type, Buffer * pbo) const;
132
133 gl::GLenum checkStatus() const;
134 std::string statusString() const;
135 void printStatus(bool onlyErrors = false) const;
136
137 FramebufferAttachment * getAttachment(gl::GLenum attachment);
138 std::vector<FramebufferAttachment*> attachments();
139
140 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;
141 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;
142
143 virtual gl::GLenum objectType() const override;
144
145
146protected:
147 Framebuffer(std::unique_ptr<IDResource> && resource);
148
149 void addAttachment(std::unique_ptr<FramebufferAttachment> && attachment);
150
151
152protected:
153 std::map<gl::GLenum, std::unique_ptr<FramebufferAttachment>> m_attachments;
154};
155
156
157} // namespace globjects
Wrapper for OpenGL buffer objects.
Definition: Buffer.h:38
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:54
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:57
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
static std::unique_ptr< Framebuffer > fromId(gl::GLuint id)
std::map< gl::GLenum, std::unique_ptr< FramebufferAttachment > > m_attachments
Definition: Framebuffer.h:153
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
void readPixels(const std::array< gl::GLint, 4 > &rect, gl::GLenum format, gl::GLenum type, gl::GLvoid *data=nullptr) const
void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, int value)
static void clearDepth(gl::GLdouble depth)
void clearBuffer(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
void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, float value)
void setDrawBuffer(gl::GLenum mode) const
void readPixelsToBuffer(const std::array< gl::GLint, 4 > &rect, gl::GLenum format, gl::GLenum type, Buffer *pbo) const
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
void setParameter(gl::GLenum pname, gl::GLint param)
Framebuffer(std::unique_ptr< IDResource > &&resource)
static void unbind(gl::GLenum target)
bool detach(gl::GLenum attachment)
void attachRenderBuffer(gl::GLenum attachment, Renderbuffer *renderBuffer)
virtual gl::GLenum objectType() const override
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::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 addAttachment(std::unique_ptr< FramebufferAttachment > &&attachment)
void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const gl::GLint *value)
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
void clearBuffer(gl::GLenum buffer, gl::GLfloat depth, gl::GLint stencil, gl::GLint drawBuffer=0)
static void colorMask(const glm::bvec4 &mask)
void clear(gl::ClearBufferMask mask)
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
static std::unique_ptr< Framebuffer > defaultFBO()
void bind(gl::GLenum target) const
void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, const gl::GLuint *value)
CRTP for creating objects similar to std::make_unique.
Definition: Instantiator.h:22
Superclass of all wrapped OpenGL objects.
Definition: Object.h:28
Encapsulates OpenGL render buffer objects.
Definition: Renderbuffer.h:21
Wraps OpenGL texture objects. A Texture provides both interfaces to bind them for the OpenGL pipeline...
Definition: Texture.h:35
Contains all the classes that wrap OpenGL functionality.