From 8f738e46f7912ad4a3489181f67e3cc814ea9ffb Mon Sep 17 00:00:00 2001 From: Hill Ma Date: Thu, 4 Mar 2021 22:32:40 -0800 Subject: [PATCH] ogre2: explicitly request OpenGL 3.3 core profile context. (#244) This change raises system requirements as it uses GLX 1.3 API and a GLX extension. Modern systems like Ubuntu bionic and focal satisfies these without issue. Signed-off-by: Hill Ma --- ogre2/src/Ogre2RenderEngine.cc | 53 +++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/ogre2/src/Ogre2RenderEngine.cc b/ogre2/src/Ogre2RenderEngine.cc index f9df00db6..0008bf5e0 100644 --- a/ogre2/src/Ogre2RenderEngine.cc +++ b/ogre2/src/Ogre2RenderEngine.cc @@ -20,6 +20,7 @@ # include # include # include +# include #endif #ifdef _WIN32 @@ -44,7 +45,7 @@ class ignition::rendering::Ogre2RenderEnginePrivate { #if !defined(__APPLE__) && !defined(_WIN32) - public: XVisualInfo *dummyVisual = nullptr; + public: GLXFBConfig* dummyFBConfigs = nullptr; #endif /// \brief A list of supported fsaa levels @@ -136,8 +137,8 @@ void Ogre2RenderEngine::Destroy() XDestroyWindow(x11Display, this->dummyWindowId); XCloseDisplay(x11Display); this->dummyDisplay = nullptr; - XFree(this->dataPtr->dummyVisual); - this->dataPtr->dummyVisual = nullptr; + XFree(this->dataPtr->dummyFBConfigs); + this->dataPtr->dummyFBConfigs = nullptr; } #endif } @@ -346,15 +347,22 @@ void Ogre2RenderEngine::CreateContext() // create X11 visual int screenId = DefaultScreen(x11Display); - int attributeList[] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, - GLX_STENCIL_SIZE, 8, None }; + int attributeList[] = { + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DOUBLEBUFFER, True, + GLX_DEPTH_SIZE, 16, + GLX_STENCIL_SIZE, 8, + None + }; - this->dataPtr->dummyVisual = - glXChooseVisual(x11Display, screenId, attributeList); + int nelements = 0; - if (!this->dataPtr->dummyVisual) + this->dataPtr->dummyFBConfigs = + glXChooseFBConfig(x11Display, screenId, attributeList, &nelements); + + if (nelements <= 0) { - ignerr << "Unable to create glx visual" << std::endl; + ignerr << "Unable to create glx fbconfig" << std::endl; return; } @@ -362,8 +370,31 @@ void Ogre2RenderEngine::CreateContext() this->dummyWindowId = XCreateSimpleWindow(x11Display, RootWindow(this->dummyDisplay, screenId), 0, 0, 1, 1, 0, 0, 0); - this->dummyContext = glXCreateContext(x11Display, this->dataPtr->dummyVisual, - nullptr, 1); + PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = 0; + glXCreateContextAttribsARB = + (PFNGLXCREATECONTEXTATTRIBSARBPROC) + glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB"); + + if (glXCreateContextAttribsARB) + { + int contextAttribs[] = { + GLX_CONTEXT_MAJOR_VERSION_ARB, 3, + GLX_CONTEXT_MINOR_VERSION_ARB, 3, + GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_CORE_PROFILE_BIT_ARB, + None + }; + this->dummyContext = + glXCreateContextAttribsARB(x11Display, + this->dataPtr->dummyFBConfigs[0], nullptr, + 1, contextAttribs); + } + else + { + ignwarn << "glXCreateContextAttribsARB() not found" << std::endl; + this->dummyContext = glXCreateNewContext(x11Display, + this->dataPtr->dummyFBConfigs[0], + GLX_RGBA_TYPE, nullptr, 1); + } GLXContext x11Context = static_cast(this->dummyContext);