created double buffered textures

This commit is contained in:
itsmattkc
2019-08-27 23:45:18 +10:00
parent b9ce02a0ec
commit d76218924e
4 changed files with 114 additions and 53 deletions
+29 -19
View File
@@ -86,27 +86,14 @@ void RenderFramebuffer::Release()
void RenderFramebuffer::Attach(RenderTexturePtr texture)
{
Detach();
texture_ = texture;
AttachInternal(texture_->texture());
}
QOpenGLFunctions* f = context_->functions();
// bind framebuffer for attaching
f->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, buffer_);
// bind texture
f->glBindTexture(GL_TEXTURE_2D, texture_->texture());
context_->extraFunctions()->glFramebufferTexture2D(
GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_->texture(), 0
);
// release texture
f->glBindTexture(GL_TEXTURE_2D, 0);
// release framebuffer
f->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
void RenderFramebuffer::AttachBackBuffer(RenderTexturePtr texture)
{
texture_ = texture;
AttachInternal(texture_->back_texture());
}
void RenderFramebuffer::Detach()
@@ -130,3 +117,26 @@ const GLuint &RenderFramebuffer::buffer() const
{
return buffer_;
}
void RenderFramebuffer::AttachInternal(GLuint tex)
{
Detach();
QOpenGLFunctions* f = context_->functions();
// bind framebuffer for attaching
f->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, buffer_);
// bind texture
f->glBindTexture(GL_TEXTURE_2D, tex);
context_->extraFunctions()->glFramebufferTexture2D(
GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0
);
// release texture
f->glBindTexture(GL_TEXTURE_2D, 0);
// release framebuffer
f->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
}