OpenGL: non-JUCE timer based refresh How-To?


#1

I don’t want to use the normal JUCE Timers for repainting my OpenGLComponent’s (because animations won’t be smooth as soon as the message manager is busy) but I have met some problem I just can’t seem to solve.

I override the renderAndSwapBuffers() method in a way that it just returns true and does nothing else.

In a special Thread, I then set a ScopedLock and call OpenGLComponent::makeCurrentContextActive(), OpenGLComponent::renderOpenGL(), OpenGLComponent::swapBuffers() , then make the OpenGLContext inactive again. I do that for all my OpenGLComponents.

The glViewport’s pos/size is set in each renderOpenGL() at the beginning.

Textures are also uploaded from time to time to the different OpenGL contexts, and for the texure upload I used the same CriticalSection as the one used by the painter Thread above, so this never happens at the same time as the painting itself.

The problem that arises is that, sometimes, when one resizes the window constantly by moving around the mouse for very long (and the different OpenGLComponents get resized, too), suddenly the painting stops and there’s only garbage in the OpenGLComponents. Basically, what happens is that I always get an exception in my painter Thread, but I don’t know why. At the time it is painting, nothing else should be able to use the OpenGL contexts, since there’s this ScopedLock.

I would like to know what is the proper way of doing all this, I really need it to work very soon, I’m under heavy time pressure.

This is on Windows XP. Maybe something special happens when the OpenGLComponents are resized and this would interfere in the other Threads using the OpenGLContexts at this time?


#2

Hi Zamrate,
Try also overriding resized() and renderAndSwapBuffers()
This way you determine when waht happends, especially the resized() function might help as opengl calls are being made within that function.

[code]
void OpenGLCanvas::resized()
{
isResized = true;
}

void OpenGLCanvas::renderOpenGL()
{

}

bool OpenGLCanvas::renderAndSwapBuffers()
{
return true;
}[/code]


#3

I think I found the bug already, but I must say, this OpenGL rendering and concurrent texture uploading is a hard job. I’m happy when finished with it.