Skip to content

Commit

Permalink
UI|Client: Use GLFramebuffer when rendering busy transition frame
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Dec 3, 2013
1 parent 278dde1 commit 8d5c158
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 34 deletions.
13 changes: 4 additions & 9 deletions doomsday/client/include/ui/clientwindow.h
Expand Up @@ -142,17 +142,12 @@ class ClientWindow : public de::PersistentCanvasWindow,
void grab(image_t &image, bool halfSized = false) const;

/**
* Draws the untransformed game-related contents of the window to a
* texture. The drawing is done immediately; this must be called from the
* main/UI thread.
* Draws the untransformed game-related contents of the window. The drawing
* is done immediately; this must be called from the main/UI thread.
*
* The entire texture is filled, but the logical size of the UI is not
* changed for this operation. I.e., aspect ratio is changed to fit into
* the texture and appropriate scaling is done using a GL viewport.
*
* @param texture Texture to draw into.
* The current render target is cleared before drawing.
*/
void drawGameContentToTexture(de::GLTexture &texture);
void drawGameContent();

void updateCanvasFormat();
void updateRootSize();
Expand Down
15 changes: 3 additions & 12 deletions doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -814,23 +814,14 @@ void ClientWindow::grab(image_t &img, bool halfSized) const
DENG_ASSERT(img.pixelSize != 0);
}

void ClientWindow::drawGameContentToTexture(GLTexture &texture)
void ClientWindow::drawGameContent()
{
DENG_ASSERT_IN_MAIN_THREAD();
DENG_ASSERT_GL_CONTEXT_ACTIVE();

/// @todo Use GLFramebuffer
GLState::current().target().clear(GLTarget::ColorDepthStencil);

GLTarget offscreen(texture, GLTarget::DepthStencil);
GLState::push()
.setTarget(offscreen)
.setViewport(Rectangleui::fromSize(texture.size()))
.apply();

offscreen.clear(GLTarget::ColorDepthStencil);
d->root.drawUntil(*d->gameSelMenu);

GLState::pop().apply();
d->root.drawUntil(*d->busy);
}

void ClientWindow::updateCanvasFormat()
Expand Down
48 changes: 38 additions & 10 deletions doomsday/client/src/ui/widgets/busywidget.cpp
Expand Up @@ -31,7 +31,7 @@

#include <de/concurrency.h>
#include <de/Drawable>
#include <de/GLTexture>
#include <de/GLFramebuffer>

using namespace de;

Expand All @@ -40,7 +40,7 @@ DENG_GUI_PIMPL(BusyWidget)
typedef DefaultVertexBuf VertexBuf;

ProgressWidget *progress;
QScopedPointer<GLTexture> transitionTex;
GLFramebuffer transitionFrame;
Drawable drawable;
GLUniform uTex;
GLUniform uMvpMatrix;
Expand All @@ -60,6 +60,8 @@ DENG_GUI_PIMPL(BusyWidget)

void glInit()
{
//transitionFrame.setColorFormat(Image::RGB_888);

VertexBuf *buf = new VertexBuf;

VertexBuf::Builder verts;
Expand All @@ -74,6 +76,12 @@ DENG_GUI_PIMPL(BusyWidget)
void glDeinit()
{
drawable.clear();
transitionFrame.glDeinit();
}

bool haveTransitionFrame() const
{
return transitionFrame.isReady();
}
};

Expand Down Expand Up @@ -123,7 +131,7 @@ void BusyWidget::drawContent()
return;
}

if(!d->transitionTex.isNull())
if(d->haveTransitionFrame())
{
GLState::current().apply();

Expand Down Expand Up @@ -154,7 +162,7 @@ void BusyWidget::renderTransitionFrame()
{
LOG_AS("BusyWidget");

if(!d->transitionTex.isNull())
if(d->haveTransitionFrame())
{
// We already have a valid frame, no need to render again.
return;
Expand All @@ -181,20 +189,40 @@ void BusyWidget::renderTransitionFrame()
// Grab the game view's rectangle, as that's where the transition will be drawn.
GLuint grabbed = root().window().grabAsTexture(grabRect, ClientWindow::GrabHalfSized);*/

d->transitionTex.reset(new GLTexture); //grabbed, grabRect.size() / 2));
d->transitionTex->setUndefinedImage(grabRect.size(), Image::RGB_888);
root().window().drawGameContentToTexture(*d->transitionTex);
d->uTex = *d->transitionTex;
d->transitionFrame.resize(grabRect.size());
d->transitionFrame.glInit();

GLState::push()
.setTarget(d->transitionFrame.target())
.setViewport(Rectangleui::fromSize(d->transitionFrame.size()))
.apply();

//d->transitionTex.reset(new GLTexture); //grabbed, grabRect.size() / 2));
//d->transitionTex->setUndefinedImage(grabRect.size(), Image::RGB_888);

root().window().drawGameContent();

GLState::pop().apply();

d->uTex = d->transitionFrame.colorTexture();
}

void BusyWidget::releaseTransitionFrame()
{
d->transitionTex.reset();
if(d->haveTransitionFrame())
{
LOG_DEBUG("Releasing transition frame");
d->transitionFrame.glDeinit();
}
}

GLTexture const *BusyWidget::transitionFrame() const
{
return d->transitionTex.data();
if(d->haveTransitionFrame())
{
return &d->transitionFrame.colorTexture();
}
return 0;
}

void BusyWidget::glInit()
Expand Down
3 changes: 2 additions & 1 deletion doomsday/libgui/include/de/gui/glframebuffer.h
Expand Up @@ -20,6 +20,7 @@
#define LIBGUI_GLFRAMEBUFFER_H

#include <de/Vector>
#include <de/Asset>

#include "../GLTarget"
#include "../GLTexture"
Expand All @@ -34,7 +35,7 @@ class Canvas;
*
* Color values and depth/stencil values are written to textures.
*/
class GLFramebuffer
class GLFramebuffer : public Asset
{
public:
typedef Vector2ui Size;
Expand Down
7 changes: 6 additions & 1 deletion doomsday/libgui/src/glframebuffer.cpp
Expand Up @@ -81,7 +81,7 @@ DENG2_PIMPL(GLFramebuffer)

void reconfigure()
{
if(size == Size()) return;
if(!self.isReady() || size == Size()) return;

color.setUndefinedImage(size, colorFormat);
color.setWrap(gl::ClampToEdge, gl::ClampToEdge);
Expand Down Expand Up @@ -128,12 +128,17 @@ GLFramebuffer::GLFramebuffer(Image::Format const &colorFormat, Size const &initi

void GLFramebuffer::glInit()
{
if(isReady()) return;

d->alloc();
setState(Ready);

d->reconfigure();
}

void GLFramebuffer::glDeinit()
{
setState(NotReady);
d->release();
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libgui/src/gltarget.cpp
Expand Up @@ -152,7 +152,7 @@ DENG2_OBSERVES(Asset, Deletion)
{
DENG2_ASSERT(tex.isReady());

LOG_DEBUG("glTex %i (level %i) => FBO attachment %i (0x%x)")
LOG_TRACE("glTex %i (level %i) => FBO attachment %i (0x%x)")
<< tex.glName() << level << attachmentToId(attachment) << attachment;

glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, tex.glName(), level);
Expand Down

0 comments on commit 8d5c158

Please sign in to comment.