Introducing a true Primary Framebuffer and a different Deferred Framebuffer

This commit is contained in:
samcake 2015-12-03 17:26:54 -08:00
parent 72d393905b
commit d593b824e9
7 changed files with 86 additions and 54 deletions

View file

@ -676,9 +676,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
_applicationStateDevice->addInputVariant(QString("ComfortMode"), controller::StateController::ReadLambda([]() -> float {
return (float)Menu::getInstance()->isOptionChecked(MenuOption::ComfortMode);
}));
_applicationStateDevice->addInputVariant(QString("Grounded"), controller::StateController::ReadLambda([]() -> float {
return (float)qApp->getMyAvatar()->getCharacterController()->onGround();
}));
_applicationStateDevice->addInputVariant(QString("Grounded"), controller::StateController::ReadLambda([]() -> float {
return (float)qApp->getMyAvatar()->getCharacterController()->onGround();
}));
userInputMapper->registerDevice(_applicationStateDevice);
@ -1347,7 +1347,7 @@ void Application::paintGL() {
{
PROFILE_RANGE(__FUNCTION__ "/compositor");
PerformanceTimer perfTimer("compositor");
auto primaryFbo = framebufferCache->getPrimaryFramebuffer();
auto primaryFbo = framebufferCache->getPrimaryFramebufferDepthColor();
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFbo));
if (displayPlugin->isStereo()) {
QRect currentViewport(QPoint(0, 0), QSize(size.width() / 2, size.height()));
@ -1372,7 +1372,7 @@ void Application::paintGL() {
{
PROFILE_RANGE(__FUNCTION__ "/pluginOutput");
PerformanceTimer perfTimer("pluginOutput");
auto primaryFbo = framebufferCache->getPrimaryFramebuffer();
auto primaryFbo = framebufferCache->getPrimaryFramebufferDepthColor();
GLuint finalTexture = gpu::GLBackend::getTextureID(primaryFbo->getRenderBuffer(0));
// Ensure the rendering context commands are completed when rendering
GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);

View file

@ -201,7 +201,7 @@ void AmbientOcclusion::run(const render::SceneContextPointer& sceneContext, cons
// Occlusion step
getOcclusionPipeline();
batch.setResourceTexture(0, framebufferCache->getPrimaryDepthTexture());
batch.setResourceTexture(1, framebufferCache->getPrimaryNormalTexture());
batch.setResourceTexture(1, framebufferCache->getDeferredNormalTexture());
_occlusionBuffer->setRenderBuffer(0, _occlusionTexture);
batch.setFramebuffer(_occlusionBuffer);
@ -276,7 +276,7 @@ void AmbientOcclusion::run(const render::SceneContextPointer& sceneContext, cons
// Blend step
getBlendPipeline();
batch.setResourceTexture(0, _hBlurTexture);
batch.setFramebuffer(framebufferCache->getPrimaryFramebuffer());
batch.setFramebuffer(framebufferCache->getDeferredFramebuffer());
// Bind the fourth gpu::Pipeline we need - for blending the primary color buffer with blurred occlusion texture
batch.setPipeline(getBlendPipeline());

View file

@ -123,7 +123,7 @@ void Antialiasing::run(const render::SceneContextPointer& sceneContext, const re
// FXAA step
getAntialiasingPipeline();
batch.setResourceTexture(0, framebufferCache->getPrimaryColorTexture());
batch.setResourceTexture(0, framebufferCache->getDeferredColorTexture());
_antialiasingBuffer->setRenderBuffer(0, _antialiasingTexture);
batch.setFramebuffer(_antialiasingBuffer);
batch.setPipeline(getAntialiasingPipeline());
@ -153,7 +153,7 @@ void Antialiasing::run(const render::SceneContextPointer& sceneContext, const re
// Blend step
getBlendPipeline();
batch.setResourceTexture(0, _antialiasingTexture);
batch.setFramebuffer(framebufferCache->getPrimaryFramebuffer());
batch.setFramebuffer(framebufferCache->getDeferredFramebuffer());
batch.setPipeline(getBlendPipeline());
DependencyManager::get<GeometryCache>()->renderQuad(batch, bottomLeft, topRight, texCoordTopLeft, texCoordBottomRight, color);

View file

@ -374,9 +374,9 @@ void DeferredLightingEffect::prepare(RenderArgs* args) {
batch.enableStereo(false);
batch.setStateScissorRect(args->_viewport);
auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
auto deferredFbo = DependencyManager::get<FramebufferCache>()->getDeferredFramebuffer();
batch.setFramebuffer(primaryFbo);
batch.setFramebuffer(deferredFbo);
// clear the normal and specular buffers
batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR1, glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), true);
const float MAX_SPECULAR_EXPONENT = 128.0f;
@ -412,9 +412,9 @@ void DeferredLightingEffect::render(RenderArgs* args) {
batch.clearColorFramebuffer(lightingFBO->getBufferMask(), glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), true);
// BInd the G-Buffer surfaces
batch.setResourceTexture(0, framebufferCache->getPrimaryColorTexture());
batch.setResourceTexture(1, framebufferCache->getPrimaryNormalTexture());
batch.setResourceTexture(2, framebufferCache->getPrimarySpecularTexture());
batch.setResourceTexture(0, framebufferCache->getDeferredColorTexture());
batch.setResourceTexture(1, framebufferCache->getDeferredNormalTexture());
batch.setResourceTexture(2, framebufferCache->getDeferredSpecularTexture());
batch.setResourceTexture(3, framebufferCache->getPrimaryDepthTexture());
// THe main viewport is assumed to be the mono viewport (or the 2 stereo faces side by side within that viewport)

View file

@ -33,12 +33,14 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) {
//If the size changed, we need to delete our FBOs
if (_frameBufferSize != frameBufferSize) {
_frameBufferSize = frameBufferSize;
_primaryFramebufferFull.reset();
_primaryFramebufferDepthColor.reset();
_primaryDepthTexture.reset();
_primaryColorTexture.reset();
_primaryNormalTexture.reset();
_primarySpecularTexture.reset();
_deferredFramebuffer.reset();
_deferredFramebufferDepthColor.reset();
_deferredColorTexture.reset();
_deferredNormalTexture.reset();
_deferredSpecularTexture.reset();
_selfieFramebuffer.reset();
_cachedFramebuffers.clear();
_lightingTexture.reset();
@ -47,8 +49,9 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) {
}
void FramebufferCache::createPrimaryFramebuffer() {
_primaryFramebufferFull = gpu::FramebufferPointer(gpu::Framebuffer::create());
_primaryFramebufferDepthColor = gpu::FramebufferPointer(gpu::Framebuffer::create());
_deferredFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create());
_deferredFramebufferDepthColor = gpu::FramebufferPointer(gpu::Framebuffer::create());
auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA);
auto width = _frameBufferSize.width();
@ -56,23 +59,30 @@ void FramebufferCache::createPrimaryFramebuffer() {
auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT);
_primaryColorTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler));
_primaryNormalTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler));
_primarySpecularTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler));
_primaryFramebufferFull->setRenderBuffer(0, _primaryColorTexture);
_primaryFramebufferFull->setRenderBuffer(1, _primaryNormalTexture);
_primaryFramebufferFull->setRenderBuffer(2, _primarySpecularTexture);
_primaryFramebufferDepthColor->setRenderBuffer(0, _primaryColorTexture);
_deferredColorTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler));
_deferredNormalTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler));
_deferredSpecularTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler));
_deferredFramebuffer->setRenderBuffer(0, _deferredColorTexture);
_deferredFramebuffer->setRenderBuffer(1, _deferredNormalTexture);
_deferredFramebuffer->setRenderBuffer(2, _deferredSpecularTexture);
_deferredFramebufferDepthColor->setRenderBuffer(0, _deferredColorTexture);
// auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH);
auto depthFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL); // Depth24_Stencil8 texel format
_primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler));
_primaryFramebufferFull->setDepthStencilBuffer(_primaryDepthTexture, depthFormat);
_primaryFramebufferDepthColor->setDepthStencilBuffer(_primaryDepthTexture, depthFormat);
_deferredFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat);
_deferredFramebufferDepthColor->setDepthStencilBuffer(_primaryDepthTexture, depthFormat);
_selfieFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create());
auto tex = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width * 0.5, height * 0.5, defaultSampler));
_selfieFramebuffer->setRenderBuffer(0, tex);
@ -84,13 +94,6 @@ void FramebufferCache::createPrimaryFramebuffer() {
_lightingFramebuffer->setRenderBuffer(0, _lightingTexture);
}
gpu::FramebufferPointer FramebufferCache::getPrimaryFramebuffer() {
if (!_primaryFramebufferFull) {
createPrimaryFramebuffer();
}
return _primaryFramebufferFull;
}
gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferDepthColor() {
if (!_primaryFramebufferDepthColor) {
createPrimaryFramebuffer();
@ -112,18 +115,39 @@ gpu::TexturePointer FramebufferCache::getPrimaryColorTexture() {
return _primaryColorTexture;
}
gpu::TexturePointer FramebufferCache::getPrimaryNormalTexture() {
if (!_primaryNormalTexture) {
gpu::FramebufferPointer FramebufferCache::getDeferredFramebuffer() {
if (!_deferredFramebuffer) {
createPrimaryFramebuffer();
}
return _primaryNormalTexture;
return _deferredFramebuffer;
}
gpu::TexturePointer FramebufferCache::getPrimarySpecularTexture() {
if (!_primarySpecularTexture) {
gpu::FramebufferPointer FramebufferCache::getDeferredFramebufferDepthColor() {
if (!_deferredFramebufferDepthColor) {
createPrimaryFramebuffer();
}
return _primarySpecularTexture;
return _deferredFramebufferDepthColor;
}
gpu::TexturePointer FramebufferCache::getDeferredColorTexture() {
if (!_deferredColorTexture) {
createPrimaryFramebuffer();
}
return _deferredColorTexture;
}
gpu::TexturePointer FramebufferCache::getDeferredNormalTexture() {
if (!_deferredNormalTexture) {
createPrimaryFramebuffer();
}
return _deferredNormalTexture;
}
gpu::TexturePointer FramebufferCache::getDeferredSpecularTexture() {
if (!_deferredSpecularTexture) {
createPrimaryFramebuffer();
}
return _deferredSpecularTexture;
}
gpu::FramebufferPointer FramebufferCache::getLightingFramebuffer() {

View file

@ -29,13 +29,17 @@ public:
/// Returns a pointer to the primary framebuffer object. This render target includes a depth component, and is
/// used for scene rendering.
gpu::FramebufferPointer getPrimaryFramebuffer();
gpu::FramebufferPointer getPrimaryFramebufferDepthColor();
gpu::TexturePointer getPrimaryDepthTexture();
gpu::TexturePointer getPrimaryColorTexture();
gpu::TexturePointer getPrimaryNormalTexture();
gpu::TexturePointer getPrimarySpecularTexture();
gpu::FramebufferPointer getDeferredFramebuffer();
gpu::FramebufferPointer getDeferredFramebufferDepthColor();
gpu::TexturePointer getDeferredColorTexture();
gpu::TexturePointer getDeferredNormalTexture();
gpu::TexturePointer getDeferredSpecularTexture();
gpu::TexturePointer getLightingTexture();
@ -60,13 +64,17 @@ private:
void createPrimaryFramebuffer();
gpu::FramebufferPointer _primaryFramebufferFull;
gpu::FramebufferPointer _primaryFramebufferDepthColor;
gpu::TexturePointer _primaryDepthTexture;
gpu::TexturePointer _primaryColorTexture;
gpu::TexturePointer _primaryNormalTexture;
gpu::TexturePointer _primarySpecularTexture;
gpu::FramebufferPointer _deferredFramebuffer;
gpu::FramebufferPointer _deferredFramebufferDepthColor;
gpu::TexturePointer _deferredColorTexture;
gpu::TexturePointer _deferredNormalTexture;
gpu::TexturePointer _deferredSpecularTexture;
gpu::TexturePointer _lightingTexture;
gpu::FramebufferPointer _lightingFramebuffer;

View file

@ -38,13 +38,13 @@ void SetupDeferred::run(const SceneContextPointer& sceneContext, const RenderCon
RenderArgs* args = renderContext->args;
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor();
auto deferredFbo = DependencyManager::get<FramebufferCache>()->getDeferredFramebufferDepthColor();
batch.enableStereo(false);
batch.setViewportTransform(args->_viewport);
batch.setStateScissorRect(args->_viewport);
batch.setFramebuffer(primaryFbo);
batch.setFramebuffer(deferredFbo);
batch.clearFramebuffer(
gpu::Framebuffer::BUFFER_COLOR0 |
gpu::Framebuffer::BUFFER_DEPTH |
@ -332,11 +332,11 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren
doInBatch(args->_context, [=](gpu::Batch& batch) {
args->_batch = &batch;
auto primaryFboColorDepthStencil = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor();
auto deferredFboColorDepthStencil = DependencyManager::get<FramebufferCache>()->getDeferredFramebufferDepthColor();
batch.enableStereo(false);
batch.setFramebuffer(primaryFboColorDepthStencil);
batch.setFramebuffer(deferredFboColorDepthStencil);
batch.setViewportTransform(args->_viewport);
batch.setStateScissorRect(args->_viewport);
@ -367,12 +367,12 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const
doInBatch(args->_context, [=](gpu::Batch& batch) {
args->_batch = &batch;
auto primaryFboColorDepthStencil = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor();
auto primaryFboFull = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
auto deferredFboColorDepthStencil = DependencyManager::get<FramebufferCache>()->getDeferredFramebufferDepthColor();
auto deferredFboFull = DependencyManager::get<FramebufferCache>()->getDeferredFramebuffer();
batch.enableSkybox(true);
batch.setFramebuffer(primaryFboColorDepthStencil);
batch.setFramebuffer(deferredFboColorDepthStencil);
batch.setViewportTransform(args->_viewport);
batch.setStateScissorRect(args->_viewport);
@ -387,7 +387,7 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const
renderItems(sceneContext, renderContext, inItems);
batch.setFramebuffer(primaryFboFull);
batch.setFramebuffer(deferredFboFull);
});
args->_batch = nullptr;