user1832287
user1832287

Reputation: 321

Partial redraw to FBO OpenGL

My scene is organized into groups of elements that compose to FBOs backed by floating point textures (16 bit with alpha). These FBOs are then blended together top to bottom to produce the final scene. All FBOs are the size of the screen. When the screen size gets large (> 2048 on an Intel HD Graphics 630), the framerate plummets. This is due to fill rate issues (I have experimented with no-op leaf nodes and smaller texture formats to verify this). Is there a way to blit part of an FBO to part of another FBO? Maybe something like this before drawing a textured quad:

void FrameBufferManager::SetViewportFromClipBox(const Geometry::BoundingBox& clipBox)
{
    const auto& lowerLeft = clipBox.GetLowerLeft();
    const auto lx = static_cast<GLsizei>(lowerLeft.x);
    const auto ly = static_cast<GLsizei>(lowerLeft.y);
    const auto width = static_cast<GLsizei>(clipBox.GetWidth());
    const auto height = static_cast<GLsizei>(clipBox.GetHeight());
    glViewport(lx, ly, width, height);
    glScissor(lx, ly, width, height);
}

In the vertex shaders, the geometry is transformed such that points outside of clipBox will fall outside of ((-1, -1) (1, 1)). Will the above ensure that pixels outside of clipBox do not waste GPU memory bandwidth / fillrate? If not, is there any way to do this without creating a bunch of small FBOs and splitting object rendering across these based on object location?

Upvotes: 1

Views: 377

Answers (1)

Rabbid76
Rabbid76

Reputation: 211220

Is there a way to blit part of an FBO to part of another FBO?

Since OpenGL ES 3.0 you can use glBlitFramebuffer:

glBlitFramebuffer — copy a block of pixels from the read framebuffer to the draw framebuffer

void glBlitFramebuffer(
    GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
    GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
    GLbitfield mask, GLenum filter);

This function is also provided by the extension NV_framebuffer_blit, which is is written against OpenGL ES 2.0.

Upvotes: 1

Related Questions