gloperate icon indicating copy to clipboard operation
gloperate copied to clipboard

Deferred functions for Stages

Open j-o opened this issue 7 years ago • 4 comments

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.

j-o avatar Mar 14 '17 14:03 j-o

Which use case can be achieved using such interface and functionality?

scheibel avatar Mar 14 '17 17:03 scheibel

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.

j-o avatar Mar 14 '17 19:03 j-o

I think I had a discussion with @cgcostume for such kind of functionality. Your example code looks clean and understandable.

scheibel avatar Mar 14 '17 19:03 scheibel

Some thoughts on this:

  1. 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?)

  2. 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.

sbusch42 avatar Mar 15 '17 11:03 sbusch42