Failed to render with GL3Plus RS in multiple windows

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


User avatar
bishopnator
Gnome
Posts: 361
Joined: Thu Apr 26, 2007 11:43 am
Location: Slovakia / Switzerland
x 16

Failed to render with GL3Plus RS in multiple windows

Post by bishopnator »

I am using Ogre-Next 4.0.0 and in my try-out application if I switch from D3D11 render system to GL3Plus, I am getting a strange OpenGL error already before rendering of the 1st geometry:

OpenGL:error(high) 1282: GL_INVALID_OPERATION error generated. VAO names must be generated with glGenVertexArrays before they can be bound or used.

It is coming from GL3PlusRenderSystem::_startLegacyV1Rendering() where mGlobalVao is trying to bind. I see in the debugger, that the GL contexts are switched - I am not sure whether this could be a problem. My application initializes the Ogre and its render system by creating a 1x1 pixel hidden window and then I create my real window(s). The error pops by trying to redraw my very first visible window.

The D3D11 render system works without any problems.

Note that I have made some changes to my Ogre, but this kind of error sounds like some core issue (just for an overview and completeness, the changes are on this branch: https://github.com/bishopnator/ogre-nex ... or/hlmsext). I tried to debug ogre and understand this behavior, but I am running out of ideas. In several discussions, it was stated that VAO shouldn't be (or cannot be) shared between the contexts. The context with creates the VAO should be used also to bind the VAO - but this just sounds like the whole idea with mGlobalVao is wrong, or all windows should use same context. Not sure about the indented design in ogre.

The callstack of the reported OpenGL error:

Code: Select all

 	OgreNextMain_d.dll!Ogre::Log::logMessage(const std::string & message={...}, Ogre::LogMessageLevel lml=LML_NORMAL, bool maskDebug=false) Line 76	C++
 	OgreNextMain_d.dll!Ogre::Log::Stream::~Stream() Line 189	C++
 	RenderSystem_GL3Plus_d.dll!GLDebugCallback(unsigned int source=33350, unsigned int type=33356, unsigned int id=1282, unsigned int severity=37190, int length=122, const char * message=0x00007ffc1d15e3d0, const void * userParam=0x0000000000000000) Line 143	C++
 	nvoglv64.dll!00007ffc1b3806e5()	Unknown
 	nvoglv64.dll!00007ffc1b380795()	Unknown
 	RenderSystem_GL3Plus_d.dll!Ogre::GL3PlusRenderSystem::_startLegacyV1Rendering() Line 2970	C++
 	OgreNextMain_d.dll!Ogre::SceneManager::_renderPhase02(Ogre::Camera * camera=0x0000022df2880dc0, const Ogre::Camera * lodCamera=0x0000022df2880dc0, unsigned char firstRq='2', unsigned char lastRq='3', bool includeOverlays=true) Line 1518	C++
 	OgreNextMain_d.dll!Ogre::Camera::_renderScenePhase02(const Ogre::Camera * lodCamera=0x0000022df2880dc0, unsigned char firstRq='2', unsigned char lastRq='3', bool includeOverlays=true) Line 389	C++
 	OgreNextMain_d.dll!Ogre::Viewport::_updateRenderPhase02(Ogre::Camera * camera=0x0000022df2880dc0, const Ogre::Camera * lodCamera=0x0000022df2880dc0, unsigned char firstRq='2', unsigned char lastRq='3') Line 207	C++
 	OgreNextMain_d.dll!Ogre::CompositorPassScene::execute(const Ogre::Camera * lodCamera=0x0000000000000000) Line 316	C++
 	OgreNextMain_d.dll!Ogre::CompositorNode::_update(const Ogre::Camera * lodCamera=0x0000000000000000, Ogre::SceneManager * sceneManager=0x0000022df260ebc0) Line 836	C++
 	OgreNextMain_d.dll!Ogre::CompositorWorkspace::_update(const bool bInsideAutoreleasePool=true) Line 907	C++
 	OgreNextMain_d.dll!Ogre::CompositorManager2::_updateImplementation() Line 791	C++
 	OgreNextMain_d.dll!Ogre::RenderSystem::updateCompositorManager(Ogre::CompositorManager2 * compositorManager=0x0000022dd09d2f40) Line 1326	C++
 	OgreNextMain_d.dll!Ogre::CompositorManager2::_update() Line 713	C++
 	OgreNextMain_d.dll!Ogre::Root::_updateAllRenderTargets() Line 1582	C++
 	OgreNextMain_d.dll!Ogre::Root::renderOneFrame() Line 1113	C++

I debugged e.g. Sample_Tutorial_Distortion and there is only a single window hence single OpenGL context and this method _startLegacyV1Rendering is called with the value of mCurrentContext as used during the initialization of the mGlobalVao. But this is not in my case.

Any ideas? Even some suggestions where to look in Ogre would be great.

User avatar
bishopnator
Gnome
Posts: 361
Joined: Thu Apr 26, 2007 11:43 am
Location: Slovakia / Switzerland
x 16

Re: Failed to render with GL3Plus RS in multiple windows

Post by bishopnator »

Just for the sake of debugging, I updated my app so there is only a single instance of Ogre::Window created in whole my app and then the rendering is correct without any complains from GL3Plus (or OpenGL). Are there any rules to follow when app creates 2 windows in GL3Plus render system?

User avatar
bishopnator
Gnome
Posts: 361
Joined: Thu Apr 26, 2007 11:43 am
Location: Slovakia / Switzerland
x 16

Re: Failed to render with GL3Plus RS in multiple windows

Post by bishopnator »

I compiled Ogre 4.0.0 without my modifications (commit ID 4cb7ab24) and updated the Sample_Tutorial_Distortion to create one extra window before the window which renders the scene. I added following code in Tutorial_Distortion.cpp at line 51:

Code: Select all

        void initMiscParamsListener(Ogre::NameValuePairList& /*params*/) override
        {
            Ogre::NameValuePairList primaryWindowParams;
            primaryWindowParams["hidden"] = Ogre::StringConverter::toString(true);
            mPrimaryWindow = Ogre::Root::getSingleton().createRenderWindow("primary", 1, 1, false, &primaryWindowParams);
        }

private:
    Ogre::Window* mPrimaryWindow = nullptr;

The OpenGL doesn't report any errors as I mentioned in my initial message, but the output is not correct - the floor polygon is missing:
Image

With D3D11, the sample looks of course good:
Image

User avatar
bishopnator
Gnome
Posts: 361
Joined: Thu Apr 26, 2007 11:43 am
Location: Slovakia / Switzerland
x 16

Re: Failed to render with GL3Plus RS in multiple windows

Post by bishopnator »

Most of the examples don't work with the additional window. I tried to reproduce with this simple code insertion the GL_INVALID_OPERATION so I inserted the code in multiple samples/tutorials. Most of the time there is some missing geometry. However the Sample_Forward3D even crashed.

Code: Select all

void GL3PlusRenderSystem::_render( const CbDrawCallIndexed *cmd )

Exception thrown at 0x00007FFBEC9165A4 (nvoglv64.dll) in Sample_Forward3D.exe: 0xC0000005: Access violation reading location 0x0000000000028028.

There seems some problems with the OpenGL context.

Note that all my modified examples work without problems with D3D11 render system.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5560
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1403

Re: Failed to render with GL3Plus RS in multiple windows

Post by dark_sylinc »

OpenGL context problems are a PITA to debug and fix.

Check:

  1. There is no multithreading. OpenGL must belong to one thread and one thread only. Do not initialize OgreNext in one thread then use it in another thread. Do not use OgreNext rendering routines from multiple threads either.
  2. See this thread viewtopic.php?p=522313#p522313
User avatar
bishopnator
Gnome
Posts: 361
Joined: Thu Apr 26, 2007 11:43 am
Location: Slovakia / Switzerland
x 16

Re: Failed to render with GL3Plus RS in multiple windows

Post by bishopnator »

This is hard, and up to now for me without any fix. I tried to use "currentGLContext" or "externalGLContext" for the 2nd window, but without any change. I even put the break points on the calls where new context is created, just to ensure that there is only a single GL context created, but still without success.

Let's ignore my application and its setup (even that I believe, I am not doing anything special as D3D11 is working without any complains). Let's rather focus on the Ogre's sample - the change is very simple - just creating a 1x1pixel "initialization" window, which holds the "main" context. Why the samples are not working as expected? How can I bring them back to life with this extra hidden window?

From RenderDoc, I see that whole rendering pipeline seems ok, but the rendered (missing) plane has empty vertex buffer - there are no vertices. What this one can indicate? If there could be a reasonable solution found, I think that it will resolve the problems also in my app.

Update: I re-read the suggested link, and it solution with vsync=No is actually working for me. I can live with it - for the "windowed" mode (not fullscreen) it is perfectly valid option and forcing vsync sounds more like a bad idea.

Last edited by bishopnator on Mon May 25, 2026 4:17 pm, edited 1 time in total.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5560
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1403

Re: Failed to render with GL3Plus RS in multiple windows

Post by dark_sylinc »

See this example which creates multiple windows and keeps them under m_renderWindows.

User avatar
bishopnator
Gnome
Posts: 361
Joined: Thu Apr 26, 2007 11:43 am
Location: Slovakia / Switzerland
x 16

Re: Failed to render with GL3Plus RS in multiple windows

Post by bishopnator »

Thanks, I will integrate similar initialization/creation of the windows in my app. I don't like particularly the checking of the render system with string, but the idea about vsync is there. If you rely on wglGetCurrentContext I would prefer setting of "cuttingGLContext" in the window creation parameter instead of using "externalGLContext", but it looks just like a preference instead of thumb of rule.