cleaned opengl texture and framebuffer code

Minor code changes and improvements.
This commit is contained in:
itsmattkc
2019-12-21 20:08:20 +11:00
parent 401de26733
commit 355baa893a
3 changed files with 41 additions and 45 deletions
+35 -37
View File
@@ -77,7 +77,7 @@ void OpenGLFramebuffer::Bind()
if (context_ == nullptr) {
return;
}
context_->functions()->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, buffer_);
context_->functions()->glBindFramebuffer(GL_FRAMEBUFFER, buffer_);
}
void OpenGLFramebuffer::Release()
@@ -85,7 +85,7 @@ void OpenGLFramebuffer::Release()
if (context_ == nullptr) {
return;
}
context_->functions()->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
context_->functions()->glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void OpenGLFramebuffer::Attach(OpenGLTexturePtr texture, bool clear)
@@ -94,47 +94,17 @@ void OpenGLFramebuffer::Attach(OpenGLTexturePtr texture, bool clear)
return;
}
texture_ = texture;
AttachInternal(texture_->texture(), clear);
}
void OpenGLFramebuffer::Detach()
{
if (context_ == nullptr) {
return;
}
QOpenGLFunctions* f = context_->functions();
// bind framebuffer for attaching
f->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, buffer_);
context_->extraFunctions()->glFramebufferTexture2D(
GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0
);
// release framebuffer
f->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
texture_ = nullptr;
}
const GLuint &OpenGLFramebuffer::buffer() const
{
return buffer_;
}
void OpenGLFramebuffer::AttachInternal(GLuint tex, bool clear)
{
Detach();
texture_ = texture;
QOpenGLFunctions* f = context_->functions();
// bind framebuffer for attaching
f->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, buffer_);
f->glBindFramebuffer(GL_FRAMEBUFFER, buffer_);
context_->extraFunctions()->glFramebufferTexture2D(
GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_->texture(), 0
);
if (clear) {
@@ -143,5 +113,33 @@ void OpenGLFramebuffer::AttachInternal(GLuint tex, bool clear)
}
// release framebuffer
f->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
f->glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void OpenGLFramebuffer::Detach()
{
if (context_ == nullptr) {
return;
}
if (texture_) {
QOpenGLFunctions* f = context_->functions();
// bind framebuffer for attaching
f->glBindFramebuffer(GL_FRAMEBUFFER, buffer_);
context_->extraFunctions()->glFramebufferTexture2D(
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0
);
// release framebuffer
f->glBindFramebuffer(GL_FRAMEBUFFER, 0);
texture_ = nullptr;
}
}
const GLuint &OpenGLFramebuffer::buffer() const
{
return buffer_;
}
@@ -53,8 +53,6 @@ public slots:
void Destroy();
private:
void AttachInternal(GLuint tex, bool clear);
QOpenGLContext* context_;
GLuint buffer_;
+6 -6
View File
@@ -47,7 +47,7 @@ bool OpenGLTexture::IsCreated() const
void OpenGLTexture::Create(QOpenGLContext *ctx, int width, int height, const olive::PixelFormat &format, const void* data)
{
if (!ctx) {
qWarning() << "RenderTexture::Create was passed an invalid context";
qWarning() << "OpenGLTexture::Create was passed an invalid context";
return;
}
@@ -86,7 +86,7 @@ void OpenGLTexture::Bind()
QOpenGLContext* context = QOpenGLContext::currentContext();
if (!context) {
qWarning() << "RenderTexture::Bind() called with an invalid context";
qWarning() << "OpenGLTexture::Bind() called with an invalid context";
return;
}
@@ -98,7 +98,7 @@ void OpenGLTexture::Release()
QOpenGLContext* context = QOpenGLContext::currentContext();
if (!context) {
qWarning() << "RenderTexture::Release() called with an invalid context";
qWarning() << "OpenGLTexture::Release() called with an invalid context";
return;
}
@@ -128,14 +128,14 @@ const GLuint &OpenGLTexture::texture() const
void OpenGLTexture::Upload(const void *data)
{
if (!IsCreated()) {
qWarning() << "RenderTexture::Upload() called while it wasn't created";
qWarning() << "OpenGLTexture::Upload() called while it wasn't created";
return;
}
QOpenGLContext* context = QOpenGLContext::currentContext();
if (!context) {
qWarning() << "RenderTexture::Release() called with an invalid context";
qWarning() << "OpenGLTexture::Release() called with an invalid context";
return;
}
@@ -159,7 +159,7 @@ void OpenGLTexture::Upload(const void *data)
uchar *OpenGLTexture::Download() const
{
if (!IsCreated()) {
qWarning() << "RenderTexture::Download() called while it wasn't created";
qWarning() << "OpenGLTexture::Download() called while it wasn't created";
return nullptr;
}