grouping the depth and stencil buffer into a single buffer

This commit is contained in:
samcake 2015-10-08 16:47:33 -07:00
parent f105803958
commit bad5ea7d53
4 changed files with 8 additions and 45 deletions

View file

@ -35,6 +35,7 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] =
(&::gpu::GLBackend::do_setViewTransform), (&::gpu::GLBackend::do_setViewTransform),
(&::gpu::GLBackend::do_setProjectionTransform), (&::gpu::GLBackend::do_setProjectionTransform),
(&::gpu::GLBackend::do_setViewportTransform), (&::gpu::GLBackend::do_setViewportTransform),
(&::gpu::GLBackend::do_setDepthRangeTransform),
(&::gpu::GLBackend::do_setPipeline), (&::gpu::GLBackend::do_setPipeline),
(&::gpu::GLBackend::do_setStateBlendFactor), (&::gpu::GLBackend::do_setStateBlendFactor),

View file

@ -35,9 +35,7 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) {
_frameBufferSize = frameBufferSize; _frameBufferSize = frameBufferSize;
_primaryFramebufferFull.reset(); _primaryFramebufferFull.reset();
_primaryFramebufferDepthColor.reset(); _primaryFramebufferDepthColor.reset();
_primaryFramebufferStencilColor.reset();
_primaryDepthTexture.reset(); _primaryDepthTexture.reset();
_primaryStencilTexture.reset();
_primaryColorTexture.reset(); _primaryColorTexture.reset();
_primaryNormalTexture.reset(); _primaryNormalTexture.reset();
_primarySpecularTexture.reset(); _primarySpecularTexture.reset();
@ -49,7 +47,6 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) {
void FramebufferCache::createPrimaryFramebuffer() { void FramebufferCache::createPrimaryFramebuffer() {
_primaryFramebufferFull = gpu::FramebufferPointer(gpu::Framebuffer::create()); _primaryFramebufferFull = gpu::FramebufferPointer(gpu::Framebuffer::create());
_primaryFramebufferDepthColor = gpu::FramebufferPointer(gpu::Framebuffer::create()); _primaryFramebufferDepthColor = gpu::FramebufferPointer(gpu::Framebuffer::create());
_primaryFramebufferStencilColor = gpu::FramebufferPointer(gpu::Framebuffer::create());
auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA);
auto width = _frameBufferSize.width(); auto width = _frameBufferSize.width();
@ -66,24 +63,14 @@ void FramebufferCache::createPrimaryFramebuffer() {
_primaryFramebufferDepthColor->setRenderBuffer(0, _primaryColorTexture); _primaryFramebufferDepthColor->setRenderBuffer(0, _primaryColorTexture);
_primaryFramebufferStencilColor->setRenderBuffer(0, _primaryColorTexture);
// auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); // 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 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)); _primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler));
// auto stencilFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL); // Depth24_Stencil8 texel format
auto stencilFormat = depthFormat;
// _primaryStencilTexture = gpu::TexturePointer(gpu::Texture::create2D(stencilFormat, width, height, defaultSampler));
_primaryStencilTexture = _primaryDepthTexture;
_primaryFramebufferFull->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); _primaryFramebufferFull->setDepthStencilBuffer(_primaryDepthTexture, depthFormat);
_primaryFramebufferDepthColor->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); _primaryFramebufferDepthColor->setDepthStencilBuffer(_primaryDepthTexture, depthFormat);
// _primaryFramebufferStencilColor->setDepthStencilBuffer(_primaryStencilTexture, stencilFormat);
_primaryFramebufferStencilColor = _primaryFramebufferDepthColor;
_selfieFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); _selfieFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create());
auto tex = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width * 0.5, height * 0.5, defaultSampler)); auto tex = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width * 0.5, height * 0.5, defaultSampler));
_selfieFramebuffer->setRenderBuffer(0, tex); _selfieFramebuffer->setRenderBuffer(0, tex);
@ -103,13 +90,6 @@ gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferDepthColor() {
return _primaryFramebufferDepthColor; return _primaryFramebufferDepthColor;
} }
gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferStencilColor() {
if (!_primaryFramebufferStencilColor) {
createPrimaryFramebuffer();
}
return _primaryFramebufferStencilColor;
}
gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() { gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() {
if (!_primaryDepthTexture) { if (!_primaryDepthTexture) {
createPrimaryFramebuffer(); createPrimaryFramebuffer();
@ -117,13 +97,6 @@ gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() {
return _primaryDepthTexture; return _primaryDepthTexture;
} }
gpu::TexturePointer FramebufferCache::getPrimaryStencilTexture() {
if (!_primaryStencilTexture) {
createPrimaryFramebuffer();
}
return _primaryStencilTexture;
}
gpu::TexturePointer FramebufferCache::getPrimaryColorTexture() { gpu::TexturePointer FramebufferCache::getPrimaryColorTexture() {
if (!_primaryColorTexture) { if (!_primaryColorTexture) {
createPrimaryFramebuffer(); createPrimaryFramebuffer();

View file

@ -31,10 +31,8 @@ public:
/// used for scene rendering. /// used for scene rendering.
gpu::FramebufferPointer getPrimaryFramebuffer(); gpu::FramebufferPointer getPrimaryFramebuffer();
gpu::FramebufferPointer getPrimaryFramebufferDepthColor(); gpu::FramebufferPointer getPrimaryFramebufferDepthColor();
gpu::FramebufferPointer getPrimaryFramebufferStencilColor();
gpu::TexturePointer getPrimaryDepthTexture(); gpu::TexturePointer getPrimaryDepthTexture();
gpu::TexturePointer getPrimaryStencilTexture();
gpu::TexturePointer getPrimaryColorTexture(); gpu::TexturePointer getPrimaryColorTexture();
gpu::TexturePointer getPrimaryNormalTexture(); gpu::TexturePointer getPrimaryNormalTexture();
gpu::TexturePointer getPrimarySpecularTexture(); gpu::TexturePointer getPrimarySpecularTexture();
@ -60,9 +58,8 @@ private:
gpu::FramebufferPointer _primaryFramebufferFull; gpu::FramebufferPointer _primaryFramebufferFull;
gpu::FramebufferPointer _primaryFramebufferDepthColor; gpu::FramebufferPointer _primaryFramebufferDepthColor;
gpu::FramebufferPointer _primaryFramebufferStencilColor;
gpu::TexturePointer _primaryDepthTexture; gpu::TexturePointer _primaryDepthTexture;
gpu::TexturePointer _primaryStencilTexture;
gpu::TexturePointer _primaryColorTexture; gpu::TexturePointer _primaryColorTexture;
gpu::TexturePointer _primaryNormalTexture; gpu::TexturePointer _primaryNormalTexture;
gpu::TexturePointer _primarySpecularTexture; gpu::TexturePointer _primarySpecularTexture;

View file

@ -37,18 +37,12 @@ void SetupDeferred::run(const SceneContextPointer& sceneContext, const RenderCon
RenderArgs* args = renderContext->args; RenderArgs* args = renderContext->args;
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
auto primaryFboStencil = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferStencilColor();
auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor(); auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor();
batch.enableStereo(false); batch.enableStereo(false);
batch.setViewportTransform(args->_viewport); batch.setViewportTransform(args->_viewport);
batch.setStateScissorRect(args->_viewport); batch.setStateScissorRect(args->_viewport);
/* batch.setFramebuffer(primaryFboStencil);
batch.clearFramebuffer(
gpu::Framebuffer::BUFFER_STENCIL,
vec4(vec3(0), 1), 1.0, 0.0, true);
*/
batch.setFramebuffer(primaryFbo); batch.setFramebuffer(primaryFbo);
batch.clearFramebuffer( batch.clearFramebuffer(
gpu::Framebuffer::BUFFER_COLOR0 | gpu::Framebuffer::BUFFER_COLOR0 |
@ -332,9 +326,8 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren
doInBatch(args->_context, [=](gpu::Batch& batch) { doInBatch(args->_context, [=](gpu::Batch& batch) {
args->_batch = &batch; args->_batch = &batch;
auto primaryFboColorDepthStencil = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferStencilColor(); auto primaryFboColorDepthStencil = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor();
auto primaryDepth = DependencyManager::get<FramebufferCache>()->getPrimaryDepthTexture();
batch.enableStereo(false); batch.enableStereo(false);
batch.setFramebuffer(primaryFboColorDepthStencil); batch.setFramebuffer(primaryFboColorDepthStencil);
@ -342,7 +335,6 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren
batch.setStateScissorRect(args->_viewport); batch.setStateScissorRect(args->_viewport);
batch.setPipeline(getOpaquePipeline()); batch.setPipeline(getOpaquePipeline());
// batch.setResourceTexture(0, primaryDepth);
batch.draw(gpu::TRIANGLE_STRIP, 4); batch.draw(gpu::TRIANGLE_STRIP, 4);
batch.setResourceTexture(0, nullptr); batch.setResourceTexture(0, nullptr);
@ -369,12 +361,12 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const
doInBatch(args->_context, [=](gpu::Batch& batch) { doInBatch(args->_context, [=](gpu::Batch& batch) {
args->_batch = &batch; args->_batch = &batch;
auto primaryFboColorStencil = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferStencilColor(); auto primaryFboColorDepthStencil = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor();
auto primaryFboFull = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer(); auto primaryFboFull = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
batch.enableSkybox(true); batch.enableSkybox(true);
batch.setFramebuffer(primaryFboColorStencil); batch.setFramebuffer(primaryFboColorDepthStencil);
batch.setViewportTransform(args->_viewport); batch.setViewportTransform(args->_viewport);
batch.setStateScissorRect(args->_viewport); batch.setStateScissorRect(args->_viewport);