Fixed potential bug with outline frame buffer allocations. Still problems with avatar outline rect

This commit is contained in:
Olivier Prat 2017-10-19 12:39:34 +02:00
parent cc30c0b841
commit 111966b987
2 changed files with 30 additions and 31 deletions

View file

@ -37,43 +37,36 @@ OutlineRessources::OutlineRessources() {
void OutlineRessources::update(const gpu::FramebufferPointer& primaryFrameBuffer) { void OutlineRessources::update(const gpu::FramebufferPointer& primaryFrameBuffer) {
auto newFrameSize = glm::ivec2(primaryFrameBuffer->getSize()); auto newFrameSize = glm::ivec2(primaryFrameBuffer->getSize());
// If the depth buffer or size changed, we need to delete our FBOs and recreate them at the // If the buffer size changed, we need to delete our FBOs and recreate them at the
// new correct dimensions. // new correct dimensions.
if (_depthFrameBuffer) {
if (_frameSize != newFrameSize) { if (_frameSize != newFrameSize) {
_frameSize = newFrameSize; _frameSize = newFrameSize;
clear(); allocateDepthBuffer(primaryFrameBuffer);
} allocateColorBuffer(primaryFrameBuffer);
} else {
if (!_depthFrameBuffer) {
allocateDepthBuffer(primaryFrameBuffer);
} }
if (!_colorFrameBuffer) { if (!_colorFrameBuffer) {
if (_frameSize != newFrameSize) { allocateColorBuffer(primaryFrameBuffer);
_frameSize = newFrameSize; }
// Failing to recreate this frame buffer when the screen has been resized creates a bug on Mac }
}
void OutlineRessources::allocateColorBuffer(const gpu::FramebufferPointer& primaryFrameBuffer) {
_colorFrameBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("primaryWithoutDepth")); _colorFrameBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("primaryWithoutDepth"));
_colorFrameBuffer->setRenderBuffer(0, primaryFrameBuffer->getRenderBuffer(0)); _colorFrameBuffer->setRenderBuffer(0, primaryFrameBuffer->getRenderBuffer(0));
}
}
} }
void OutlineRessources::clear() { void OutlineRessources::allocateDepthBuffer(const gpu::FramebufferPointer& primaryFrameBuffer) {
_depthFrameBuffer.reset();
}
void OutlineRessources::allocate() {
auto width = _frameSize.x;
auto height = _frameSize.y;
auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH);
auto depthTexture = gpu::TexturePointer(gpu::Texture::createRenderBuffer(depthFormat, width, height)); auto depthTexture = gpu::TexturePointer(gpu::Texture::createRenderBuffer(depthFormat, _frameSize.x, _frameSize.y));
_depthFrameBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("outlineDepth")); _depthFrameBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("outlineDepth"));
_depthFrameBuffer->setDepthStencilBuffer(depthTexture, depthFormat); _depthFrameBuffer->setDepthStencilBuffer(depthTexture, depthFormat);
} }
gpu::FramebufferPointer OutlineRessources::getDepthFramebuffer() { gpu::FramebufferPointer OutlineRessources::getDepthFramebuffer() {
if (!_depthFrameBuffer) { assert(_depthFrameBuffer);
allocate();
}
return _depthFrameBuffer; return _depthFrameBuffer;
} }
@ -81,6 +74,11 @@ gpu::TexturePointer OutlineRessources::getDepthTexture() {
return getDepthFramebuffer()->getDepthStencilBuffer(); return getDepthFramebuffer()->getDepthStencilBuffer();
} }
gpu::FramebufferPointer OutlineRessources::getColorFramebuffer() {
assert(_colorFrameBuffer);
return _colorFrameBuffer;
}
OutlineSharedParameters::OutlineSharedParameters() { OutlineSharedParameters::OutlineSharedParameters() {
std::fill(_blurPixelWidths.begin(), _blurPixelWidths.end(), 0); std::fill(_blurPixelWidths.begin(), _blurPixelWidths.end(), 0);
} }
@ -305,6 +303,11 @@ void DrawOutline::run(const render::RenderContextPointer& renderContext, const I
const gpu::PipelinePointer& DrawOutline::getPipeline() { const gpu::PipelinePointer& DrawOutline::getPipeline() {
if (!_pipeline) { if (!_pipeline) {
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
state->setDepthTest(gpu::State::DepthTest(false, false));
state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA);
state->setScissorEnable(true);
auto vs = gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS(); auto vs = gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS();
auto ps = gpu::Shader::createPixel(std::string(Outline_frag)); auto ps = gpu::Shader::createPixel(std::string(Outline_frag));
gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps); gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps);
@ -316,10 +319,6 @@ const gpu::PipelinePointer& DrawOutline::getPipeline() {
slotBindings.insert(gpu::Shader::Binding("outlinedDepthMap", OUTLINED_DEPTH_SLOT)); slotBindings.insert(gpu::Shader::Binding("outlinedDepthMap", OUTLINED_DEPTH_SLOT));
gpu::Shader::makeProgram(*program, slotBindings); gpu::Shader::makeProgram(*program, slotBindings);
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
state->setDepthTest(gpu::State::DepthTest(false, false));
state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA);
state->setScissorEnable(true);
_pipeline = gpu::Pipeline::create(program, state); _pipeline = gpu::Pipeline::create(program, state);
ps = gpu::Shader::createPixel(std::string(Outline_filled_frag)); ps = gpu::Shader::createPixel(std::string(Outline_filled_frag));

View file

@ -23,7 +23,7 @@ public:
gpu::FramebufferPointer getDepthFramebuffer(); gpu::FramebufferPointer getDepthFramebuffer();
gpu::TexturePointer getDepthTexture(); gpu::TexturePointer getDepthTexture();
gpu::FramebufferPointer getColorFramebuffer() { return _colorFrameBuffer; } gpu::FramebufferPointer getColorFramebuffer();
// Update the source framebuffer size which will drive the allocation of all the other resources. // Update the source framebuffer size which will drive the allocation of all the other resources.
void update(const gpu::FramebufferPointer& primaryFrameBuffer); void update(const gpu::FramebufferPointer& primaryFrameBuffer);
@ -31,13 +31,13 @@ public:
protected: protected:
void clear();
void allocate();
gpu::FramebufferPointer _depthFrameBuffer; gpu::FramebufferPointer _depthFrameBuffer;
gpu::FramebufferPointer _colorFrameBuffer; gpu::FramebufferPointer _colorFrameBuffer;
glm::ivec2 _frameSize; glm::ivec2 _frameSize;
void allocateColorBuffer(const gpu::FramebufferPointer& primaryFrameBuffer);
void allocateDepthBuffer(const gpu::FramebufferPointer& primaryFrameBuffer);
}; };
using OutlineRessourcesPointer = std::shared_ptr<OutlineRessources>; using OutlineRessourcesPointer = std::shared_ptr<OutlineRessources>;