Loading mesh in background

Problems building or running the engine, queries about how to use features etc.
andrecaldas
Halfling
Posts: 51
Joined: Mon May 06, 2024 1:06 am
x 3

Loading mesh in background

Post by andrecaldas »

Ogre version: Ogre 14, compiled from the repo, 10 commits behind master.

I am creating a mesh in a thread different from the rendering thread.

It happens that GL buffers cannot be created outside the thread that holds the GL context. So, when I try to create the hardware buffers, an exception occurs:
https://github.com/andre-caldas/ParaCAD ... h.cpp#L245
Where the throwing happens:
https://github.com/OGRECave/ogre/blob/d ... er.cpp#L51

I am using an Ogre::ManualResourceLoader. So, I realized that probably there is someway to ask some "resource loading worker thread" to get the resource loaded by the proper thread.

How can I do that? How can I call "reload()" on the mesh and have the loading executed by the appropriate "background thread"?

PS: Probably I am doing things in a totally wrong way... :mrgreen:

andrecaldas
Halfling
Posts: 51
Joined: Mon May 06, 2024 1:06 am
x 3

Re: Loading mesh in background

Post by andrecaldas »

Probably totally wrong... but I ended up putting a queue to be executed as a FrameListener. I have used frameRenderingQueued(). But I don't know if it is correct to change the buffers just before swapping them. Maybe I should use frameEnded().

For the Resource::load() method, I just do everything in a lambda that is pushed to the listener queue.

I will properly report what I did in the other forum: Using OGRE in practice.