OpenGL: continuous rendering


#1

I'm working on a webplugin, that uses the openglcontext from JUCE. I was wondering if there is any other way than waiting for an event in the render loop in my code to avoid it render-looping ? I want to use some kind of "lazy rendering" where the frame is only updated when something needs to be refreshed, and looking at the code of the OpenGLContext, it does not seems it is possible.

 

Thanks !

 


#2

I dont think there is. Here's what i call in `renderOpenGL' to provide an optional frame rate clamp and "pause" signal.

    void waitForNextFrame ()
    {
        int t = 0;
        
#ifdef FRAME_LIMIT
        int elapsed = (int) (Time::getMillisecondCounter() - _frameStartTime);
        int dt = 1000 / FRAME_LIMIT - elapsed;
        if (dt > t) t = dt;
#endif
        if (_pause) t = -1;
        if (t) _frameEvent.wait (t);
    }

 


#3

Thanks for the reply !

I found out that everything needed is actually inside the thread class. The main problem with your solution is that you can be unlucky, and the context might be destroy in between your wait, and the actual render, which might lead to a crash.

I have attached the modification I did to the juceOpenGLContext file to get lazy rendering. 

Doc :

before attaching the context, call "setLazyRendering(true)", then after attaching, whenever you need a refresh call "triggerRepaint" on the context, and voila.

 

Update : seems like I cant attache any CPP files :/ it might be interesting to have this modification in juce ? 


#4

I've updated it now so that I think it'll let you upload cpp files.. 


#5

Nop, still not working :(


#6

How about copy and pasting the changes into a forum post?


#7

Better a patch file :)


#8

Thanks, it seems like a good idea - I'll see what I can do.


#9

..FYI, I've added this now, and actually made it the default behaviour to not continuously paint - thinking about it, I reckon that's probably how most people will want to use it!


#10

That's great.  The continuous repainting was causing the fan on my laptop to kick in, when my app was seemingly doing nothing.


#11

This is working well in a browser plugin context. The only problem I have is when a user click a new tab and goes back, the previous tab is still visible over the OpenGL view. Is there an event I can listen to in the BrowserPluginComponent?


#12

Don't know TBH, browsers have changed enormously since I last worked on the browser plugin stuff, and they probably do all kinds of horrible windowing tricks to render themselves now. I doubt very much if there's anything in the browser plugin APIs that'd help, but I'm rather out of the loop on all that stuff, you'd need to take a look yourself.