Ogre2RenderEngine: on Windows if useCurrentGLContext is specified, set the externalWindowHandle ogre-next option #992
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🦟 Bug fix
Fixes part of gazebosim/gz-sim#2089 .
Summary
Without this fix, ogre-next fails with error:
After this fix, I was able to correctly start
gz sim -g
on Windows:In theory, the fix can be easily backported to gz-rendering7 and ign-rendering6, but as I am only working on getting Gazebo Harmonic to work well on Windows, I am not sure if there is any benefit of doing that. Anyone interested is welcome to backport the fix to earlier versions of gz-rendering.
The fix requires the Windows ID to be passed down to the rendering engine, but this is already happening in gz-sim and gz-gui thanks to gazebosim/gz-gui#292 and gazebosim/gz-sim#1063 .
This PR adds a required on Windows for
winID
to be set ifuseCurrentGLContext
, I would be happy to document this additional constraint, but I could not find a place where these parameters are documented in the code or in the documentation, so for the time being I just added a (hopefully) descriptive error message.I guess a similar fix may be required to get
ogre
(1) to run withgz-sim -g
, but to honest now I am focusing on the minimal set of features for our Windows users to be able to migrate from Gazebo Classic.Long and boring explanation
Why is this happening? First of all, it is important to know that on Windows (see https://stackoverflow.com/questions/50014602/wglcreatecontext-fails-with-error-the-pixel-format-is-invalid):
wglMakeCurrent
on an OpenGL context on a device context, you need to set the PixelFormat of the device,NULL
/0
device context.So, in short, you can't call
wglMakeCurrent
passing as first argument0
/NULL
. However, this is exactly what was happening in ogre-next at https://github.com/OGRECave/ogre-next/blob/v2.3.3/RenderSystems/GL3Plus/src/windowing/win32/OgreWin32Window.cpp#L620-L625, when theuseCurrentGLContext
option was passed.This was happening because in https://github.com/OGRECave/ogre-next/blob/v2.3.3/RenderSystems/GL3Plus/src/windowing/win32/OgreWin32Window.cpp#L620-L625 if
useCurrentGLContext
is not passed, themHDC
argument is not zero, as it corresponds to the device context of newly created dummy window (see https://github.com/OGRECave/ogre-next/blob/v2.3.3/RenderSystems/GL3Plus/src/windowing/win32/OgreWin32Window.cpp#L492 and https://github.com/OGRECave/ogre-next/blob/v2.3.3/RenderSystems/GL3Plus/src/windowing/win32/OgreWin32Window.cpp#L516). However, ifuseCurrentGLContext
is passed, no new windows is created, and bothmHDC
andmHwnd
remain to the their default values (0
), resulting in the aforementionedThe pixel format is invalid.
error.Interestingly, exactly the same mechanism (the Windows handle passed to
ogre
with theexternalWindowHandle
) is exactly how the rendering in the window works on Windows for Gazebo Classic, see:Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.