Switched to uniform buffer for Highlight

This commit is contained in:
Olivier Prat 2018-07-06 13:56:04 +02:00
parent 63c03e79d3
commit a75b4a2410
3 changed files with 20 additions and 8 deletions

View file

@ -117,6 +117,9 @@ void DrawHighlightMask::run(const render::RenderContextPointer& renderContext, c
assert(renderContext->args->hasViewFrustum());
auto& inShapes = inputs.get0();
const int BOUNDS_SLOT = 0;
const int PARAMETERS_SLOT = 1;
if (!_stencilMaskPipeline || !_stencilMaskFillPipeline) {
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
state->setDepthTest(true, false, gpu::LESS_EQUAL);
@ -135,6 +138,8 @@ void DrawHighlightMask::run(const render::RenderContextPointer& renderContext, c
gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps);
gpu::Shader::BindingSet slotBindings;
slotBindings.insert(gpu::Shader::Binding(std::string("ssbo0Buffer"), BOUNDS_SLOT));
slotBindings.insert(gpu::Shader::Binding(std::string("parametersBuffer"), PARAMETERS_SLOT));
gpu::Shader::makeProgram(*program, slotBindings);
_stencilMaskPipeline = gpu::Pipeline::create(program, state);
@ -214,6 +219,15 @@ void DrawHighlightMask::run(const render::RenderContextPointer& renderContext, c
_boundsBuffer->setData(itemBounds.size() * sizeof(render::ItemBound), (const gpu::Byte*) itemBounds.data());
const auto securityMargin = 2.0f;
const float blurPixelWidth = 2.0f * securityMargin * HighlightSharedParameters::getBlurPixelWidth(highlight._style, args->_viewport.w);
const auto framebufferSize = ressources->getSourceFrameSize();
const glm::vec2 highlightWidth = { blurPixelWidth / framebufferSize.x, blurPixelWidth / framebufferSize.y };
if (highlightWidth != _outlineWidth.get()) {
_outlineWidth.edit() = highlightWidth;
}
gpu::doInBatch("DrawHighlightMask::run::end", args->_context, [&](gpu::Batch& batch) {
// Setup camera, projection and viewport for all items
batch.setViewportTransform(args->_viewport);
@ -221,15 +235,10 @@ void DrawHighlightMask::run(const render::RenderContextPointer& renderContext, c
batch.setViewTransform(viewMat);
// Draw stencil mask with object bounding boxes
const auto highlightWidthLoc = _stencilMaskPipeline->getProgram()->getUniforms().findLocation("outlineWidth");
const auto securityMargin = 2.0f;
const float blurPixelWidth = 2.0f * securityMargin * HighlightSharedParameters::getBlurPixelWidth(highlight._style, args->_viewport.w);
const auto framebufferSize = ressources->getSourceFrameSize();
auto stencilPipeline = highlight._style.isFilled() ? _stencilMaskFillPipeline : _stencilMaskPipeline;
batch.setPipeline(stencilPipeline);
batch.setResourceBuffer(0, _boundsBuffer);
batch._glUniform2f(highlightWidthLoc, blurPixelWidth / framebufferSize.x, blurPixelWidth / framebufferSize.y);
batch.setResourceBuffer(BOUNDS_SLOT, _boundsBuffer);
batch.setUniformBuffer(PARAMETERS_SLOT, _outlineWidth);
static const int NUM_VERTICES_PER_CUBE = 36;
batch.draw(gpu::TRIANGLES, NUM_VERTICES_PER_CUBE * (gpu::uint32) itemBounds.size(), 0);
});

View file

@ -127,6 +127,7 @@ protected:
render::ShapePlumberPointer _shapePlumber;
HighlightSharedParametersPointer _sharedParameters;
gpu::BufferPointer _boundsBuffer;
gpu::StructBuffer<glm::vec2> _outlineWidth;
static gpu::PipelinePointer _stencilMaskPipeline;
static gpu::PipelinePointer _stencilMaskFillPipeline;

View file

@ -40,7 +40,9 @@ ItemBound getItemBound(int i) {
}
#endif
uniform vec2 outlineWidth;
uniform parametersBuffer {
vec2 outlineWidth;
};
void main(void) {
const vec3 UNIT_BOX_VERTICES[8] = vec3[8](