Commit ff49f339 authored by Tim Übelhör's avatar Tim Übelhör

using texture as framebuffer attachment so sampling in shaders is possible

parent 32be141c
......@@ -41,6 +41,9 @@ public:
*/
void clear(float color = 0, float depth = 1, int stencil = 0) const;
/** returns the texture used for rendering */
GLuint get_texture() const;
/** gets the maximum rbo size */
static int get_max_size();
......@@ -49,9 +52,9 @@ private:
int width, height;
// framebuffer object to render the texture into
GLuint fbo;
// renderbuffer for renderng colors
GLuint color_rbo;
// renderbuffer object for the depth testing
// texture for renderng colors, can be sampled from
GLuint color_tex;
// renderbuffer object for the depth testing, does not allow sampling
GLuint depth_stencil_rbo;
};
} // namespace scigl_render
\ No newline at end of file
......@@ -10,11 +10,11 @@ FrameBuffer::FrameBuffer(int width, int height, GLenum internal_format)
// Create framebuffer with renderbuffer attachements
glGenFramebuffers(1, &fbo);
activate();
glGenRenderbuffers(1, &color_rbo);
glBindRenderbuffer(GL_RENDERBUFFER, color_rbo);
glRenderbufferStorage(GL_RENDERBUFFER, internal_format, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_RENDERBUFFER, color_rbo);
glGenTextures(1, &color_tex);
glBindTexture(GL_TEXTURE_2D, color_tex);
glTexStorage2D(GL_TEXTURE_2D, 1, internal_format, width, height);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, color_tex, 0);
glGenRenderbuffers(1, &depth_stencil_rbo);
glBindRenderbuffer(GL_RENDERBUFFER, depth_stencil_rbo);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
......@@ -33,7 +33,7 @@ FrameBuffer::~FrameBuffer()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteRenderbuffers(1, &depth_stencil_rbo);
glDeleteRenderbuffers(1, &color_rbo);
glDeleteTextures(1, &color_tex);
}
void FrameBuffer::activate() const
......@@ -56,6 +56,11 @@ void FrameBuffer::clear(float color, float depth, int stencil) const
deactivate();
}
GLuint FrameBuffer::get_texture() const
{
return color_tex;
}
int FrameBuffer::get_max_size()
{
int max_rbo_size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment