Debug fade management moved out of the inner render loop

This commit is contained in:
Olivier Prat 2017-06-06 14:57:52 +02:00
parent 1936c209a5
commit e7eca7728f
3 changed files with 36 additions and 32 deletions

View file

@ -533,7 +533,7 @@ float ModelMeshPartPayload::computeFadePercent() const {
return 0.0f; return 0.0f;
} }
float fadeAlpha = 1.0f; float fadeAlpha = 1.0f;
const double INV_FADE_PERIOD = 1.0 / (double)(10 * USECS_PER_SECOND); const double INV_FADE_PERIOD = 1.0 / (double)(3 * USECS_PER_SECOND);
double fraction = (double)(usecTimestampNow() - _fadeStartTime) * INV_FADE_PERIOD; double fraction = (double)(usecTimestampNow() - _fadeStartTime) * INV_FADE_PERIOD;
if (fraction < 1.0) { if (fraction < 1.0) {
fadeAlpha = Interpolate::simpleNonLinearBlend(fraction); fadeAlpha = Interpolate::simpleNonLinearBlend(fraction);

View file

@ -252,6 +252,15 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs&
const auto& lightingModel = inputs.get1(); const auto& lightingModel = inputs.get1();
RenderArgs* args = renderContext->args; RenderArgs* args = renderContext->args;
ShapeKey::Builder defaultKeyBuilder;
if (_debugFade) {
args->_debugFlags = static_cast<RenderArgs::DebugFlags>(args->_debugFlags |
static_cast<int>(RenderArgs::RENDER_DEBUG_FADE));
args->_debugFadePercent = _debugFadePercent;
// Force fade for everyone
defaultKeyBuilder.withFade();
}
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
args->_batch = &batch; args->_batch = &batch;
@ -272,19 +281,12 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs&
batch.setUniformBuffer(render::ShapePipeline::Slot::LIGHTING_MODEL, lightingModel->getParametersBuffer()); batch.setUniformBuffer(render::ShapePipeline::Slot::LIGHTING_MODEL, lightingModel->getParametersBuffer());
// From the lighting model define a global shapKey ORED with individiual keys // From the lighting model define a global shapKey ORED with individiual keys
ShapeKey::Builder keyBuilder; ShapeKey::Builder keyBuilder = defaultKeyBuilder;
if (lightingModel->isWireframeEnabled()) { if (lightingModel->isWireframeEnabled()) {
keyBuilder.withWireframe(); keyBuilder.withWireframe();
} }
// Prepare fade effect // Prepare fade effect
batch.setResourceTexture(ShapePipeline::Slot::MAP::FADE_MASK, _fadeMaskMap); batch.setResourceTexture(ShapePipeline::Slot::MAP::FADE_MASK, _fadeMaskMap);
if (_debugFade) {
args->_debugFlags = static_cast<RenderArgs::DebugFlags>(args->_debugFlags |
static_cast<int>(RenderArgs::RENDER_DEBUG_FADE));
args->_debugFadePercent = _debugFadePercent;
// Force fade for everyone
keyBuilder.withFade();
}
ShapeKey globalKey = keyBuilder.build(); ShapeKey globalKey = keyBuilder.build();
args->_globalShapeKey = globalKey._flags.to_ulong(); args->_globalShapeKey = globalKey._flags.to_ulong();
@ -293,15 +295,15 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs&
args->_batch = nullptr; args->_batch = nullptr;
args->_globalShapeKey = 0; args->_globalShapeKey = 0;
// Not sure this is really needed...
if (_debugFade) {
// Turn off fade debug
args->_debugFlags = static_cast<RenderArgs::DebugFlags>(args->_debugFlags &
~static_cast<int>(RenderArgs::RENDER_DEBUG_FADE));
}
}); });
// Not sure this is really needed...
if (_debugFade) {
// Turn off fade debug
args->_debugFlags = static_cast<RenderArgs::DebugFlags>(args->_debugFlags &
~static_cast<int>(RenderArgs::RENDER_DEBUG_FADE));
}
config->setNumDrawn((int)inItems.size()); config->setNumDrawn((int)inItems.size());
} }
@ -315,6 +317,15 @@ void DrawStateSortDeferred::run(const RenderContextPointer& renderContext, const
const auto& lightingModel = inputs.get1(); const auto& lightingModel = inputs.get1();
RenderArgs* args = renderContext->args; RenderArgs* args = renderContext->args;
ShapeKey::Builder defaultKeyBuilder;
if (_debugFade) {
args->_debugFlags = static_cast<RenderArgs::DebugFlags>(args->_debugFlags |
static_cast<int>(RenderArgs::RENDER_DEBUG_FADE));
args->_debugFadePercent = _debugFadePercent;
// Force fade for everyone
defaultKeyBuilder.withFade();
}
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
args->_batch = &batch; args->_batch = &batch;
@ -335,20 +346,13 @@ void DrawStateSortDeferred::run(const RenderContextPointer& renderContext, const
batch.setUniformBuffer(render::ShapePipeline::Slot::LIGHTING_MODEL, lightingModel->getParametersBuffer()); batch.setUniformBuffer(render::ShapePipeline::Slot::LIGHTING_MODEL, lightingModel->getParametersBuffer());
// From the lighting model define a global shapeKey ORED with individiual keys // From the lighting model define a global shapeKey ORED with individiual keys
ShapeKey::Builder keyBuilder; ShapeKey::Builder keyBuilder = defaultKeyBuilder;
if (lightingModel->isWireframeEnabled()) { if (lightingModel->isWireframeEnabled()) {
keyBuilder.withWireframe(); keyBuilder.withWireframe();
} }
// Prepare fade effect // Prepare fade effect
batch.setResourceTexture(ShapePipeline::Slot::MAP::FADE_MASK, _fadeMaskMap); batch.setResourceTexture(ShapePipeline::Slot::MAP::FADE_MASK, _fadeMaskMap);
if (_debugFade) {
args->_debugFlags = static_cast<RenderArgs::DebugFlags>(args->_debugFlags |
static_cast<int>(RenderArgs::RENDER_DEBUG_FADE));
args->_debugFadePercent = _debugFadePercent;
// Force fade for everyone
keyBuilder.withFade();
}
ShapeKey globalKey = keyBuilder.build(); ShapeKey globalKey = keyBuilder.build();
args->_globalShapeKey = globalKey._flags.to_ulong(); args->_globalShapeKey = globalKey._flags.to_ulong();
@ -360,15 +364,15 @@ void DrawStateSortDeferred::run(const RenderContextPointer& renderContext, const
} }
args->_batch = nullptr; args->_batch = nullptr;
args->_globalShapeKey = 0; args->_globalShapeKey = 0;
// Not sure this is really needed...
if (_debugFade) {
// Turn off fade debug
args->_debugFlags = static_cast<RenderArgs::DebugFlags>(args->_debugFlags &
~static_cast<int>(RenderArgs::RENDER_DEBUG_FADE));
}
}); });
// Not sure this is really needed...
if (_debugFade) {
// Turn off fade debug
args->_debugFlags = static_cast<RenderArgs::DebugFlags>(args->_debugFlags &
~static_cast<int>(RenderArgs::RENDER_DEBUG_FADE));
}
config->setNumDrawn((int)inItems.size()); config->setNumDrawn((int)inItems.size());
} }

View file

@ -51,7 +51,6 @@ protected:
gpu::TexturePointer _fadeMaskMap; gpu::TexturePointer _fadeMaskMap;
float _debugFadePercent; float _debugFadePercent;
bool _stateSort;
bool _debugFade; bool _debugFade;
}; };
@ -135,6 +134,7 @@ public:
protected: protected:
render::ShapePlumberPointer _shapePlumber; render::ShapePlumberPointer _shapePlumber;
int _maxDrawn; // initialized by Config int _maxDrawn; // initialized by Config
bool _stateSort;
}; };
class DeferredFramebuffer; class DeferredFramebuffer;