Ogre Version: 14.2.6
Operating System: Windows, Mac, Linux
Render System: OpenGL/OpenGL3
With my project, I'm working on multithreading it's sim engines, by running each engine's runloop in a separate thread. So far it's working very well, and works mostly fine (except with some sync issues) on DirectX11. Since my app mostly uses OpenGL, GL uses graphics contexts (unlike DX11) and I'm currently finding a way for other threads to access the primary thread's GL context in order to run the related Ogre graphics functions on it (mainly just the texture/material functions with mutexes, rendering code is all done in the primary thread). I'm wondering if others have done something similar to this, and I'm going over the Ogre source code to see what I can do in it to solve this problem. Previously I was having the app copy some data between threads, so that it could execute the graphics code on the primary thread, but since the code was becoming cumbersome, I thought switching contexts would be a better and simpler idea.
Here's some of the context switch testing code I have (this doesn't work in the simulator at the moment, due to header and linking issues). What I'm doing is trying to store the app's GL context from the primary thread, and then have the other threads switch to that stored context if possible.
In the code, the main thread runs GetGLContext() and stores the result, the secondary thread then runs SwitchGraphicsContext() to apply that stored context to itself, not sure if I'm doing it right though:
Code: Select all
#include <RenderSystems/GL/OgreGLRenderSystem.h>
//GL graphics context
Ogre::GLContext *gl_context;
Ogre::GLContext* GetGLContext()
{
//get application OpenGL context
Ogre::RenderSystem *rendersystem = mRoot->getRenderSystem();
Ogre::GLRenderSystem* system = (Ogre::GLRenderSystem*)rendersystem;
return system->_getMainContext();
}
void SwitchGraphicsContext()
{
//switch OpenGL graphics context to the primary thread's context
Ogre::RenderSystem *rendersystem = mRoot->getRenderSystem();
Ogre::GLRenderSystem* system = (Ogre::GLRenderSystem*)rendersystem;
system->_switchContext(gl_context);
}
I'm mainly wondering what the best way to do this might be. I might try modifying some of the Ogre source to see if I can come up with a solution too. I posted about my project in the Showcase board, but it's here:
https://www.skyscrapersim.net