OpenGL single-threaded?


#1

A question for whoever is kind enough to answer from someone who is not feeling like the shiniest coin in the fountain, (since nobody else seems to have a problem with this)...

My app is attempting to use an an OpenGLContext but not render with an OpenGLRenderer - at least just yet until some resource locking issues are sorted out.

First, is that possible? The API documentation seems to say the OpenGLRenderer is optional if you wish to render from another thread, though all examples and discussion I find are using it.

If it is possible then where do you have a context? There is not an active context from the paint() function of the Component the OpenGLContext was attached to.

If it should work and it's just my bug I'm not trying to plea for help debugging it. Just not sure if I should keep debugging or if I'm mixed up and that's not even supposed to work.

 


#2

I don't see how it'd make any difference whether you use your own thread, or the one juce provides.. An OpenGLRenderer gets called on its own dedicated background thread, the only difference is that you don't have to start or stop it (?)


#3

I am porting existing code. The rendering code itself accesses classes that are updated elsewhere in the application. I can put locks around them and do other things to sort it out for multi-threading, but I was planning to get it ported first as single threaded and then do that later to clean-up and optimize.

Guess I'm out in the weeds. I'll switch plans and use a renderer.

Thanks for the reply. I don't know how the *hell* you maintain this kind of multi-platform code base and support it too. I'd rather herd cats :)

 


#4

Yes, when I retire, my plan is to become a cat-herder.

The thing with GL is that some platforms like Android make it impossible to use your own thread, so I designed the classes to work in a way that works around those limitations.


#5

I need to ask again, I'm not sure I was clear the first time.

I'd like to use OpenGL rendering single-threaded. Is that possible? If so, how?

 


#6

Well, I guess I don't really understand what you're asking.

Each OpenGLRenderer is single-threaded. If you want one thread, just use one renderer.. (??)


#7

I mean a single thread for the entire application - as in - render the openGL from the main thread. 

 


#8

That's impossible on platforms like Android, and it'd make no sense for me to add it, since you could just use a MessageManagerLock if you need to enforce locking.

But I really don't recommend doing it that way - it'd be a terrible waste of CPU on any modern machine. Better to use low-level locking of the resources that are shared.


#9

Ok, thanks again.