setContinuousRepainting(false) ineffective


#1

I have made a very simple project using IntroJucer and an OpenGLAppComponent sub-class (MacOS 10.10).

It seems that a setContinuousRepainting(false) statement does not prevent the render() method from being called.

In fact, if I modify the swap interval ( e.g. setSwapInterval(1000) ), it IS taken into account and the render() method is called at the right pace, despite of the setContinuousRepainting(false) statement being used. Shouldn't it be called only if I use a triggerRepaint() call ?

Maybe I am missing something ?

Can you also please confirm that the triggerRepaint() method asynchronously calls the render() method (not the paint() method) ?

Thanks.


#2

I don't understand how that could happen.. If you look at juce_OpenGLContext.cpp line 377, it waits indefinitely if continuous repainting is disabled.

Can you also please confirm that the triggerRepaint() method asynchronously calls the render() method (not the paint() method) ?

Yes, that's right.


#3

Well it does go to the wait(-1) when stating setContinuousRepainting(false), but that does not prevent it from drawing the new shader code.

Clearly there is something I don't understand here. The following code calls render method twice every second or so. If I change the parameter for setSwapInterval to, say, 200, render() is called every 2 seconds or so.

Why is render() called ? Why does setSwapInterval have any effect since I have setContinuousRepainting(false) ? I tried to look at your code but got lost...

class MainContentComponent   : public OpenGLAppComponent,Timer
{
public:
    //==============================================================================
    MainContentComponent()
    {
        setSize (800, 600);
        startTimer(500);
    }

    ~MainContentComponent()
    {
        stopTimer();
        shutdownOpenGL();
    }

    void initialise() override
    {
        shader = nullptr;
        openGLContext.setContinuousRepainting(false);
        openGLContext.setSwapInterval(100);
    }
    
    void timerCallback()
    {
// render() should not be called since we comment line below out and because of setContinuousRepainting(false) above
//        openGLContext.triggerRepaint();   // this calls render() method (not paint()...)
        repaint();
    }

    void shutdown() override
    {
    }

    void render() override
    {
        static int count = 0;
        DBG(count++);
    }

    void paint (Graphics& g) override
    {
            g.fillAll(Colours::black);
    }

    void resized() override
    {
    }

private:

    ScopedPointer<OpenGLGraphicsContextCustomShader> shader;

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainContentComponent)
};



#4

If your timer keeps calling repaint() then of course it'll keep rendering.. (?)


#5

OK. This is what I had not understood. (Sorry the code is not that obvious...)

So, to make sure:

- triggerRepaint calls render and not paint (nor repaint)

- repaint calls render and paint

- setContinuousRepainting(true) generates continuous calls to render (not paint nor repaint)

- as long as repaint is not explicitely called, the shader will not display anything in the component (for instance if a new object has been assigned to the shader in the meantime, the new shader code will not be executed)

Is that correct ?

Thanks for your time.


#6

Yes, that sounds about right!