Example #1
0
// initialize the depth buffer to depth-test the low-res particles against
void SceneRenderer::renderLowResSceneDepth()
{
    // if the scene-resolution depth buffer can be used as a depth pre-pass
    // to speedup the forward shading passes, then it may make sense to
    // render the opaque geometry in full resolution first, and then
    // downsample the full-resolution depths to the particle resolution.

    if (m_params.useDepthPrepass)
    {
        renderSceneDepth(m_fbos->m_sceneFbo);

        downsampleSceneDepth(m_fbos->m_sceneFbo, m_fbos->m_particleFbo);
    }
    else
    {
        renderSceneDepth(m_fbos->m_particleFbo);
    }
}
// initialize the depth buffer to depth-test the low-res particles against
void SceneRenderer::renderLowResSceneDepth(const MatrixStorage& mats)
{
    if (m_params.useDepthPrepass && glBlitFramebufferFunc)
        downsampleSceneDepth(mats, m_fbos->m_sceneFbo, m_fbos->m_particleFbo);

    if (getParticleParams()->render)
        renderSceneDepth(mats, m_fbos->m_particleFbo);

    CHECK_GL_ERROR();
}
void SceneRenderer::renderFrame()
{
    m_fbos->updateBuffers();

    // Update screen FBO
    glGetIntegerv(0x8CA6, (GLint*)&(m_fbos->m_backBufferFbo->fbo));

    CPU_TIMER_SCOPE(CPU_TIMER_TOTAL);
    GPU_TIMER_SCOPE(GPU_TIMER_TOTAL);

    MatrixStorage mats;
    setupMatrices(mats);
    
    {
        // render a full-screen depth pass.
        CPU_TIMER_SCOPE(CPU_TIMER_SCENE_DEPTH);
        GPU_TIMER_SCOPE(GPU_TIMER_SCENE_DEPTH);
        if (m_params.useDepthPrepass)
            renderSceneDepth(mats, m_fbos->m_sceneFbo);

        // render scene depth to buffer for particle to be depth tested against
        // This may just down-sample the above depth pre-pass.
        renderLowResSceneDepth(mats);
        CHECK_GL_ERROR();
    }

    {
        // the opaque colors need to be rendered after the particles
        //LOGI("OE renderFullResSceneColor\n");
        CPU_TIMER_SCOPE(CPU_TIMER_SCENE_COLOR);
        GPU_TIMER_SCOPE(GPU_TIMER_SCENE_COLOR);
        renderFullResSceneColor(mats);
        CHECK_GL_ERROR();
    }
    
    if (m_particles->getParams().render)
    {
        CPU_TIMER_SCOPE(CPU_TIMER_PARTICLES);
        GPU_TIMER_SCOPE(GPU_TIMER_PARTICLES);
        renderParticles(mats);
        CHECK_GL_ERROR();

        if (m_particles->getParams().renderLowResolution)
        {
            // upsample the particles & composite them on top of the opaque scene colors
            CPU_TIMER_SCOPE(CPU_TIMER_UPSAMPLE_PARTICLES);
            GPU_TIMER_SCOPE(GPU_TIMER_UPSAMPLE_PARTICLES);
            m_upsampler->upsampleParticleColors(*m_fbos->m_sceneFbo);
            CHECK_GL_ERROR();
        }
    }
    
    {
        // final bilinear upsampling from scene resolution to backbuffer resolution
        CPU_TIMER_SCOPE(CPU_TIMER_UPSAMPLE_SCENE);
        GPU_TIMER_SCOPE(GPU_TIMER_UPSAMPLE_SCENE);
        m_upsampler->upsampleSceneColors(*m_fbos->m_backBufferFbo);
        CHECK_GL_ERROR();
    }

    m_particles->swapBuffers();
}