Skip to content

Commit

Permalink
libgui|GLTarget: Clearing buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Apr 25, 2013
1 parent 8cfc38d commit d76d59d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions doomsday/libgui/include/de/gui/gltarget.h
Expand Up @@ -110,6 +110,20 @@ class LIBGUI_PUBLIC GLTarget : public Asset
*/
QImage toImage() const;

/**
* Sets the color for clearing the target (see clear()).
*
* @param color Color for clearing.
*/
void setClearColor(Vector4f const &color);

/**
* Clears the contents of the render target's attached buffers.
*
* @param attachments Which ones to clear.
*/
void clear(Flags const &attachments);

private:
DENG2_PRIVATE(d)
};
Expand Down
21 changes: 21 additions & 0 deletions doomsday/libgui/src/gltarget.cpp
Expand Up @@ -44,6 +44,7 @@ DENG2_OBSERVES(Asset, Deletion)
Flags flags;
GLTexture *texture;
Vector2ui size;
Vector4f clearColor;

Instance(Public *i)
: Base(i), fbo(0), flags(DefaultFlags), texture(0)
Expand Down Expand Up @@ -229,6 +230,26 @@ QImage GLTarget::toImage() const
return QImage();
}

void GLTarget::setClearColor(Vector4f const &color)
{
d->clearColor = color;
}

void GLTarget::clear(Flags const &attachments)
{
glBind();

// Only clear what we have.
Flags which = attachments & d->flags;

glClearColor(d->clearColor.x, d->clearColor.y, d->clearColor.z, d->clearColor.w);
glClear((which & Color? GL_COLOR_BUFFER_BIT : 0) |
(which & Depth? GL_DEPTH_BUFFER_BIT : 0) |
(which & Stencil? GL_STENCIL_BUFFER_BIT : 0));

GLState::top().target().glBind();
}

GLuint GLTarget::glName() const
{
return d->fbo;
Expand Down

0 comments on commit d76d59d

Please sign in to comment.