gloperate
gloperate copied to clipboard
Deferred functions for Stages
Extend Stage
to have a queue of deferred functions that are executed in process
. Callbacks can be added to this queue in onInputValueChanged
to react to specific input changes.
I already have an implementation in another project that could easily be ported.
Which use case can be achieved using such interface and functionality?
Example:
void HbaoStage::onInputValueChanged(gloperate::AbstractSlot * slot)
{
if (slot == &noiseSize)
{
defer(&HbaoStage::generateNoise);
}
if (slot == &viewport)
{
defer(&HbaoStage::resizeFramebuffer);
}
if (slot == &radius || slot == &intensity || slot == &bias || slot == &blurSharpness)
{
defer(&HbaoStage::updateUniformBuffer);
}
if (slot == &numDirections || slot == &numSteps)
{
defer(&HbaoStage::configureShaders);
}
gloperate::Stage::onInputValueChanged(slot);
}
void HbaoStage::onProcess(gloperate::AbstractGLContext * context)
{
executeDeferred();
Instead of having a changed
flag for each of these inputs.
I think I had a discussion with @cgcostume for such kind of functionality. Your example code looks clean and understandable.
Some thoughts on this:
-
Should this be its own derived Stage, or a functionality in the Stage base class? The latter would blow up the basic functionality and would need some thinking (what is executed if the list of deferred function is not empty? Omit onProcess and call the functions until the list is empty? All at once or one at a time? Or execute both?)
-
If we used/allowed gloperate::Function as a parameter to specify the deferred function, then we would also automatically have the ExecuteScriptFunction-Stage with this.