GL_EXT_discard_framebuffer#

Supported Hardware#

Series5, Series5XT, Series6, Series6XE, Series6XT (ES2/3 only)

Valid APIs#

OpenGL ES 1.x, 2.0

Description#

Generally, OpenGL ES is expected to have the result of a render stored into memory so that it can be used for later computation. If the storage memory is also the memory that is being rendered to then this isn’t a huge problem. However, in cases where the result of a render is stored in a temporary buffer to be written outer later, bandwidth is wasted in copying this data out if it isn’t going to be used. This extension provides a mechanism for users to explicitly state that they don’t need to store part of the render output, allowing the underlying implementation to avoid the costly data copy, and potentially improving performance.

Note#

This functionality is core to OpenGL ES 3.0 however a different function, “glInvalidateFramebuffer”, is used instead. This function works identically to glDiscardFramebufferEXT but was renamed and re-specified to be brought in line with other OpenGL functionality.

Example#

// Finish rendering to a particular framebuffer
glDraw(...);
// Specify attachments to discard, typically depth and stencil are discarded in this way.
GLenum discardAttachments[] =
{
    GL_DEPTH_ATTACHMENT,
    GL_STENCIL_ATTACHMENT
};
// Discard the framebuffer's contents which we aren't interested in
glDiscardFramebufferEXT(GL_FRAMEBUFFER, sizeof(discardAttachments)/sizeof(GLenum), discardAttachments);
// The next call should always be a framebuffer change, nothing should occur between this and
// the discard.
glBindFramebuffer(0);
// Clearing will prevent any data being written back to on-chip memory as well.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);