Skip to content

Commit

Permalink
libgui|GL: Tweaking framebuffer behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 4, 2016
1 parent 463c67f commit 1edf507
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
7 changes: 7 additions & 0 deletions doomsday/apps/client/src/ui/clientwindow.cpp
Expand Up @@ -1131,6 +1131,13 @@ bool ClientWindow::setDefaultGLFormat() // static
fmt.setSwapInterval(1);
}
//#endif

/*if (CanvasWindow::mainExists())
{
// Testing: does this actually do anything?
CanvasWindow::main().canvas().setFormat(fmt);
}*/

/*
int sampleCount = 1;
bool configured = App::config().getb("window.main.fsaa");
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/widgets/busywidget.cpp
Expand Up @@ -225,7 +225,7 @@ GLTexture const *BusyWidget::transitionFrame() const
{
return &d->transitionFrame.colorTexture();
}
return 0;
return nullptr;
}

void BusyWidget::glInit()
Expand Down
6 changes: 6 additions & 0 deletions doomsday/sdk/libgui/include/de/graphics/glframebuffer.h
Expand Up @@ -209,6 +209,12 @@ class LIBGUI_PUBLIC GLFramebuffer : public Asset
GLTexture &texture,
Flags const &otherAttachments = NoAttachments);

/**
* Release all GL resources for the framebuffer. This is the opposite to configure().
* The object is in an unusable state after the call, ready to be destroyed.
*/
void deinit();

/**
* Activates this render target as the one where GL drawing is being done.
*/
Expand Down
20 changes: 14 additions & 6 deletions doomsday/sdk/libgui/src/graphics/glframebuffer.cpp
Expand Up @@ -513,6 +513,12 @@ void GLFramebuffer::configure(Flags const &attachment, GLTexture &texture, Flags
d->alloc();
}

void GLFramebuffer::deinit()
{
LOG_AS("GLFramebuffer");
d->releaseAndReset();
}

void GLFramebuffer::glBind() const
{
LIBGUI_ASSERT_GL_OK();
Expand All @@ -537,13 +543,15 @@ void GLFramebuffer::glBind() const
else*/
{
//DENG2_ASSERT(!d->fbo || glIsFramebuffer(d->fbo));
/*
if (fbo && !GLInfo::EXT_framebuffer_object()->glIsFramebufferEXT(fbo))
{
qWarning() << "[GLFramebuffer] WARNING! Attempting to bind FBO" << fbo
<< "that is not a valid OpenGL FBO";
}
}*/

//qDebug() << "GLFramebuffer: binding FBO" << d->fbo;

GLInfo::EXT_framebuffer_object()->glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, fbo);
LIBGUI_ASSERT_GL_OK();
}
Expand All @@ -570,7 +578,7 @@ QImage GLFramebuffer::toImage() const
// Read the contents of the color attachment.
Size imgSize = size();
QImage img(QSize(imgSize.x, imgSize.y), QImage::Format_ARGB32);
GLInfo::EXT_framebuffer_object()->glBindFramebufferEXT(GL_FRAMEBUFFER, d->fbo);
GLInfo::EXT_framebuffer_object()->glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, d->fbo);
LIBGUI_GL.glPixelStorei(GL_PACK_ALIGNMENT, 4);
LIBGUI_GL.glReadPixels(0, 0, imgSize.x, imgSize.y, GL_BGRA, GL_UNSIGNED_BYTE,
(GLvoid *) img.constBits());
Expand Down Expand Up @@ -652,7 +660,7 @@ void GLFramebuffer::blit(GLFramebuffer &dest, Flags const &attachments, gl::Filt
GLInfo::EXT_framebuffer_object()->glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, dest.glName());
LIBGUI_ASSERT_GL_OK();

GLInfo::EXT_framebuffer_object()->glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, d->fbo);
GLInfo::EXT_framebuffer_object()->glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, glName());
LIBGUI_ASSERT_GL_OK();

Flags common = d->flags & dest.flags() & attachments;
Expand All @@ -678,9 +686,9 @@ void GLFramebuffer::blit(gl::Filter filtering) const
{
LIBGUI_ASSERT_GL_OK();

//qDebug() << "Blitting from" << d->fbo << "to" << defaultFramebuffer << size().asText();
qDebug() << "Blitting from" << glName() << "to" << defaultFramebuffer << size().asText();

GLInfo::EXT_framebuffer_object()->glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, d->fbo);
GLInfo::EXT_framebuffer_object()->glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, glName());
GLInfo::EXT_framebuffer_object()->glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, defaultFramebuffer);

GLInfo::EXT_framebuffer_blit()->glBlitFramebufferEXT(
Expand All @@ -696,7 +704,7 @@ void GLFramebuffer::blit(gl::Filter filtering) const

GLuint GLFramebuffer::glName() const
{
return d->fbo;
return d->fbo? d->fbo : defaultFramebuffer;
}

GLFramebuffer::Size GLFramebuffer::size() const
Expand Down
11 changes: 6 additions & 5 deletions doomsday/sdk/libgui/src/graphics/gltextureframebuffer.cpp
Expand Up @@ -83,9 +83,9 @@ DENG2_PIMPL(GLTextureFramebuffer)
reconfigure();
}

/*
void alloc()
{
/*
// Prepare the fallback blit method.
VBuf *buf = new VBuf;
bufSwap.addBuffer(buf);
Expand Down Expand Up @@ -114,16 +114,18 @@ DENG2_PIMPL(GLTextureFramebuffer)
uMvpMatrix = Matrix4f::ortho(0, 1, 0, 1);
uBufTex = color;
uColor = Vector4f(1, 1, 1, 1);
*/
}
*/

void release()
{
//bufSwap.clear();
color.clear();
depthStencil.clear();
self.configure();
self.deinit();
//multisampleTarget.configure();

texFboState.setState(NotReady);
}

void reconfigure()
Expand Down Expand Up @@ -341,15 +343,14 @@ void GLTextureFramebuffer::glInit()
LOG_GL_WARNING("GL_EXT_packed_depth_stencil is missing, some features may be unavailable");
}

d->alloc();
//d->alloc();
d->texFboState.setState(Ready);

d->reconfigure();
}

void GLTextureFramebuffer::glDeinit()
{
d->texFboState.setState(NotReady);
d->release();
}

Expand Down

0 comments on commit 1edf507

Please sign in to comment.