[2.1] Rendering to multiple SDL created windows

Problems building or running the engine, queries about how to use features etc.
Post Reply
Boost113
Kobold
Posts: 35
Joined: Sun Sep 08, 2013 6:39 pm
x 6

[2.1] Rendering to multiple SDL created windows

Post by Boost113 »

Ogre Version: 2.1 (61b87ac4d0a8)
Operating System: Linux
Render System: OpenGL 3+

I'm trying to render to multiple windows. But I'm not getting any output on the seconds.
I create my windows with SDL.

I have managed to get this working before with Ogre 2.0 (http://cegui.org.uk/forum/viewtopic.php?f=10&t=6971) but this time it is refusing to work. Perhaps the difference is in using SDL to create the windows. Or the opengl 3+ rendersystem acts differently than the older one (I can't remember if I had already switched to the opengl 3+ at that point).

I also found this thread: viewtopic.php?t=83442 which is hinting at that multiple OpenGL contexts are the issue.
Here's a snippet from my ogre.log, which seems to indicate that the second window creates its own context.

Code: Select all

21:23:05: GL3PlusRenderSystem::_createRenderWindow "My Second window", 1280x720 windowed  miscParams: FSAA=1 gamma=false parentWindowHandle=27892224:0:155189258 vsync=false 
21:23:05: Created GL 4.3 context
21:23:05: GLXWindow::create used FBConfigID = 165
21:23:13: DefaultWorkQueue('Root') shutting down on thread main.
21:23:13: *-*-* OGRE Shutdown
I used RenderDoc to try to see what's wrong and when comparing the rendering on the main and second window I noticed that any glMultiDrawElementsIndirect calls have no buffers set. They have the textures and vertex attribute formats etc. set, but no actual vertex buffers. So I think that's what causing nothing to show up, but that of course doesn't explain what's the root cause.

My code for creating the Ogre windows is here: https://github.com/hhyyrylainen/Leviath ... ow.cpp#L55
I can additionally upload the full Ogre log and RenderDoc captures if those would be helpful.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5298
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: [2.1] Rendering to multiple SDL created windows

Post by dark_sylinc »

Hi!

You need to reuse the context by setting externalGLContext. See the 2.1 FAQ

I noticed you're on Linux. Reusing the GL context works fine on Windows and on NVIDIA Linux, but may have issues with Mesa drivers (I haven't checked again in a long while now, perhaps Mesa's issues have been fixed now)
Boost113
Kobold
Posts: 35
Joined: Sun Sep 08, 2013 6:39 pm
x 6

Re: [2.1] Rendering to multiple SDL created windows

Post by Boost113 »

Thank you, that got it almost working after I added

Code: Select all

cfg["currentGLContext"] = "true";
and commented out the line mentioned in that thread

Code: Select all

// glxDrawable = glXGetCurrentDrawable();
The only issue I have now is that the second window renders the scene really dark and the text I render in my GUI is hard to read, also probably due to everything being dark. Here's two screenshots for comparison:
Fine:
Image
Really dark (the cube is barely visible):
Image

Both of the windows should have the same gamma settings etc.

Code: Select all

GL3PlusRenderSystem::_createRenderWindow "Standalone Editor for Leviathan 0.8.0.0", 1280x720 windowed  miscParams: FSAA=4 gamma=true parentWindowHandle=29789296:0:146800648 vsync=false 
Created GL 4.3 context
GLXWindow::create used FBConfigID = 209

GL3PlusRenderSystem::_createRenderWindow "My Second window", 1280x720 windowed  miscParams: FSAA=4 currentGLContext=true gamma=true parentWindowHandle=29789296:0:146800650 vsync=false
GLXWindow::create used FBConfigID = 209
Using FSAA.
Boost113
Kobold
Posts: 35
Joined: Sun Sep 08, 2013 6:39 pm
x 6

Re: [2.1] Rendering to multiple SDL created windows

Post by Boost113 »

Okay, so based on the assumption that the other windows don't properly have the hwGamma value set I made the following change:

Code: Select all

diff -r 61b87ac4d0a8 RenderSystems/GL3Plus/src/windowing/GLX/OgreGLXWindow.cpp
--- a/RenderSystems/GL3Plus/src/windowing/GLX/OgreGLXWindow.cpp Fri Jul 13 20:05:38 2018 +0000
+++ b/RenderSystems/GL3Plus/src/windowing/GLX/OgreGLXWindow.cpp Thu Sep 20 23:05:46 2018 +0300
@@ -150,7 +150,7 @@
                 }
 
                 glxContext = glXGetCurrentContext();
-                glxDrawable = glXGetCurrentDrawable();
+                // glxDrawable = glXGetCurrentDrawable();
             }
 
             // Note: Some platforms support AA inside ordinary windows
@@ -325,6 +325,8 @@
             }
 
             mHwGamma = (gamma != 0);
+        } else {
+            mHwGamma = true;
         }
 
         if (! fbConfig)
(the first change is about making the multiple window drawing work at all).
And now rendering to as many windows as I want works perfectly (at least with the test content I used).
This looks to be caused by the fact that 'GLXGLSupport::getFBConfigFromDrawable' can't tell the second window that gamma has been successfully enabled.

I'd really appreciate a quick bug fix so that I don't have to fork Ogre in order share my latest code, that has multi-window rendering in it, with my team members.

Edit: I created a pull request of my (slightly cleaned up) changes: https://bitbucket.org/sinbad/ogre/pull- ... gamma/diff
Post Reply