Ogre Version: :14.5.2:
Operating System: :Ubuntu 24.04 LTS.:
Render System: :OpenGL ES 2.x:
I am using the following code to create and OGRE window using and existing EGL context. For reasons that I won't get into here, this is necessary for my application. The code works and I am able to run my custom rendering application.
Code: Select all
// Wayland setup done prior to this
EGLDisplay egl_display = eglGetDisplay((EGLNativeDisplayType)display);
eglInitialize(egl_display, NULL, NULL);
// This is from minAttribs in OgreWaylandEGLWindow.cpp
int minAttribs[] = {
EGL_BUFFER_SIZE, 16,
EGL_DEPTH_SIZE, 16,
EGL_SAMPLE_BUFFERS, 0,
EGL_SAMPLES, 0,
EGL_NONE
};
EGLConfig * configs;
EGLint num_configs;
EGLint nElements;
EGLConfig config;
eglChooseConfig(egl_display, minAttribs, NULL, 0, &nElements);
configs = (EGLConfig*) malloc(nElements * sizeof(EGLConfig));
eglChooseConfig(egl_display, minAttribs, configs, nElements, &num_configs);
// TODO: This is a hot mess and probably needs to change from computer to computer
// OGRE does no respect the EGL config that we give it. In WaylandEGLWindow::create
// on line 222 in OgreWaylandEGLWindow, it looks for the best EGL config from all
// returned.
config = configs[15];
eglBindAPI(EGL_OPENGL_ES_API);
EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
struct wl_egl_window* egl_window_3d = wl_egl_window_create(sub_surface, 1920, 1080);
EGLContext egl_context_3d = eglCreateContext(egl_display, config, EGL_NO_CONTEXT, context_attribs);
EGLSurface egl_surface_3d = eglCreateWindowSurface(egl_display, config, (EGLNativeWindowType)egl_window_3d, NULL);
eglMakeCurrent(egl_display, egl_surface_3d, egl_surface_3d, egl_context_3d);
NameValuePairList params;
params["currentGLContext"] = "true";
params["externalGLControl"] = "true";
params["externalWlDisplay"] = Ogre::StringConverter::toString(size_t(display));
params["externalWlSurface"] = Ogre::StringConverter::toString(size_t(surface));
Root* root = new Root("", "");
root->loadPlugin("/usr/local/lib/OGRE/RenderSystem_GLES2.so");
root->loadPlugin("/usr/local/lib/OGRE/Codec_STBI.so");
Ogre::RenderSystem* rs = root->getRenderSystemByName("OpenGL ES 2.x Rendering Subsystem");
if (!rs) {
rs = root->getRenderSystemByName("OpenGL ES 2.x Rendering Subsystem");
}
if (!rs)
{
printf("OpenGL ES Rendering Subsystem not found!\n");
return -1;
}
root->setRenderSystem(rs);
root->initialise(false);
Ogre::RenderWindow* ogreWnd = root->createRenderWindow("MyTerrainWindow", SCREEN_WIDTH, SCREEN_HEIGHT, false, ¶ms);
The problem is that although OGRE uses my existing EGL context, it attempts to select a new EGL config instead of honouring the previous selection (see OgreWaylandEGLWindow.cpp). If my code does not select a config that is compatible with the one that OGRE selects, OGRE crashes when it attempts to make the EGL context current.
My current work around is to figure out which config OGRE selects internally and hard-code that selection into my EGL setup. This is obviously very problematic and is not portable across machines.
Code: Select all
// This is from minAttribs in OgreWaylandEGLWindow.cpp
int minAttribs[] = {
EGL_BUFFER_SIZE, 16,
EGL_DEPTH_SIZE, 16,
EGL_SAMPLE_BUFFERS, 0,
EGL_SAMPLES, 0,
EGL_NONE
};
EGLConfig * configs;
EGLint num_configs;
EGLint nElements;
EGLConfig config;
eglChooseConfig(egl_display, minAttribs, NULL, 0, &nElements);
configs = (EGLConfig*) malloc(nElements * sizeof(EGLConfig));
eglChooseConfig(egl_display, minAttribs, configs, nElements, &num_configs);
// TODO: This is a hot mess and probably needs to change from computer to computer
// OGRE does no respect the EGL config that we give it. In WaylandEGLWindow::create
// on line 222 in OgreWaylandEGLWindow, it looks for the best EGL config from all
// returned.
config = configs[15];
What is the correct way to address this?