Fix GLEW initialization
authorTimo Röhling <roehling@debian.org>
Thu, 10 Feb 2022 11:48:51 +0000 (12:48 +0100)
committerTimo Röhling <roehling@debian.org>
Thu, 10 Feb 2022 13:14:45 +0000 (14:14 +0100)
debian/patches/0011-Replace-BlueGL-with-GLEW.patch

index 7b4030d341fe0c115019c509c5185fca56a16f27..c26d26b731162bb1f5039cf65854c4e03a356597 100644 (file)
@@ -6,10 +6,10 @@ Subject: Replace BlueGL with GLEW
  CMakeLists.txt                               |   1 -
  filament/backend/CMakeLists.txt              |  10 +-
  filament/backend/src/opengl/OpenGLDriver.cpp |   4 +-
- filament/backend/src/opengl/PlatformGLX.cpp  | 155 ++++-----------------------
+ filament/backend/src/opengl/PlatformGLX.cpp  | 167 ++++++---------------------
  filament/backend/src/opengl/PlatformGLX.h    |   6 +-
  filament/backend/src/opengl/gl_headers.h     |   3 +-
- 6 files changed, 36 insertions(+), 143 deletions(-)
+ 6 files changed, 49 insertions(+), 142 deletions(-)
 
 diff --git a/CMakeLists.txt b/CMakeLists.txt
 index a95c557..5c117c3 100644
@@ -76,10 +76,10 @@ index 9b7135f..5ccf074 100644
  #endif
          {
 diff --git a/filament/backend/src/opengl/PlatformGLX.cpp b/filament/backend/src/opengl/PlatformGLX.cpp
-index b5cb484..665fde3 100644
+index b5cb484..4253f7c 100644
 --- a/filament/backend/src/opengl/PlatformGLX.cpp
 +++ b/filament/backend/src/opengl/PlatformGLX.cpp
-@@ -20,131 +20,35 @@
+@@ -20,131 +20,41 @@
  #include <utils/Panic.h>
  
  #include <X11/Xlib.h>
@@ -190,7 +190,9 @@ index b5cb484..665fde3 100644
 -    g_x11.closeDisplay = (X11_CLOSE_DISPLAY)dlsym(g_x11.library, "XCloseDisplay");
 -    return true;
 -}
--
++#define RESOLVE_GLX_ENTRYPOINT(Function, Type) \
++    Function = (Type)glXGetProcAddress((const GLubyte*)#Function);
  namespace filament {
  
  using namespace backend;
@@ -204,11 +206,14 @@ index b5cb484..665fde3 100644
          utils::slog.e << "Failed to open X display. (exiting)." << utils::io::endl;
          exit(1);
      }
-+    if (glewInit() != GLEW_OK)
-+    {
-+        utils::slog.e << "Failed to initialize GLEW. (exiting)." << utils::io::endl;
-+        exit(1);
-+    }
++    /* Manually resolve glX entrypoints we need to create a context */
++    RESOLVE_GLX_ENTRYPOINT(glXCreateContextAttribsARB, PFNGLXCREATECONTEXTATTRIBSARBPROC);
++    RESOLVE_GLX_ENTRYPOINT(glXCreatePbuffer, PFNGLXCREATEPBUFFERPROC);
++    RESOLVE_GLX_ENTRYPOINT(glXMakeContextCurrent, PFNGLXMAKECONTEXTCURRENTPROC);
++    RESOLVE_GLX_ENTRYPOINT(glXChooseFBConfig, PFNGLXCHOOSEFBCONFIGPROC);
++    RESOLVE_GLX_ENTRYPOINT(glXQueryContext, PFNGLXQUERYCONTEXTPROC);
++    RESOLVE_GLX_ENTRYPOINT(glXGetFBConfigs, PFNGLXGETFBCONFIGSPROC);
++    RESOLVE_GLX_ENTRYPOINT(glXGetFBConfigAttrib, PFNGLXGETFBCONFIGATTRIBPROC);
  
      if (sharedGLContext != nullptr) {
          int r = -1;
@@ -220,7 +225,7 @@ index b5cb484..665fde3 100644
          if (r != 0) {
              utils::slog.e << "Failed to get GLX_FBCONFIG_ID from shared GL context."
                            << utils::io::endl;
-@@ -152,7 +56,7 @@ Driver* PlatformGLX::createDriver(void* const sharedGLContext) noexcept {
+@@ -152,7 +62,7 @@ Driver* PlatformGLX::createDriver(void* const sharedGLContext) noexcept {
          }
  
          int numConfigs = 0;
@@ -229,7 +234,7 @@ index b5cb484..665fde3 100644
  
          if (fbConfigs == nullptr) {
              utils::slog.e << "Failed to get the available GLXFBConfigs." << utils::io::endl;
-@@ -163,7 +67,7 @@ Driver* PlatformGLX::createDriver(void* const sharedGLContext) noexcept {
+@@ -163,7 +73,7 @@ Driver* PlatformGLX::createDriver(void* const sharedGLContext) noexcept {
          int fbIndex = -1;
  
          for (int i = 0; i < numConfigs; ++i) {
@@ -238,9 +243,11 @@ index b5cb484..665fde3 100644
              if (r != 0) {
                  utils::slog.e << "Failed to get GLX_FBCONFIG_ID for entry " << i << "."
                                << utils::io::endl;
-@@ -192,29 +96,20 @@ Driver* PlatformGLX::createDriver(void* const sharedGLContext) noexcept {
+@@ -190,31 +100,21 @@ Driver* PlatformGLX::createDriver(void* const sharedGLContext) noexcept {
+                 GLX_DEPTH_SIZE, 24,
+                 None
          };
+-
          int configCount = 0;
 -        mGLXConfig = g_glx.chooseFbConfig(mGLXDisplay, DefaultScreen(mGLXDisplay),
 +        mGLXConfig = glXChooseFBConfig(mGLXDisplay, DefaultScreen(mGLXDisplay),
@@ -270,17 +277,25 @@ index b5cb484..665fde3 100644
              (GLXContext)sharedGLContext, True, contextAttribs);
  
      int pbufferAttribs[] = {
-@@ -223,21 +118,17 @@ Driver* PlatformGLX::createDriver(void* const sharedGLContext) noexcept {
+@@ -223,21 +123,26 @@ Driver* PlatformGLX::createDriver(void* const sharedGLContext) noexcept {
              GL_NONE
      };
  
 -    mDummySurface = g_glx.createPbuffer(mGLXDisplay, mGLXConfig[0], pbufferAttribs);
 -    g_glx.setCurrentContext(mGLXDisplay, mDummySurface, mDummySurface, mGLXContext);
--
--    int result = bluegl::bind();
--    ASSERT_POSTCONDITION(!result, "Unable to load OpenGL entry points.");
 +    mDummySurface = glXCreatePbuffer(mGLXDisplay, mGLXConfig[0], pbufferAttribs);
 +    glXMakeContextCurrent(mGLXDisplay, mDummySurface, mDummySurface, mGLXContext);
++
++    GLenum result;
++    /* Properly initialize the remainder of the GL entrypoints */
++    if ((result = glewInit()) != GLEW_OK)
++    {
++        utils::slog.e << "Failed to initialize GLEW. (" << result << ", exiting)." << utils::io::endl;
++        exit(1);
++    }
+-    int result = bluegl::bind();
+-    ASSERT_POSTCONDITION(!result, "Unable to load OpenGL entry points.");
  
      return OpenGLDriverFactory::create(this, sharedGLContext);
  }
@@ -298,7 +313,7 @@ index b5cb484..665fde3 100644
  }
  
  Platform::SwapChain* PlatformGLX::createSwapChain(void* nativeWindow, uint64_t& flags) noexcept {
-@@ -255,7 +146,7 @@ Platform::SwapChain* PlatformGLX::createSwapChain(
+@@ -255,7 +160,7 @@ Platform::SwapChain* PlatformGLX::createSwapChain(
              GLX_PBUFFER_HEIGHT, int(height),
              GL_NONE
      };
@@ -307,7 +322,7 @@ index b5cb484..665fde3 100644
      if (sur) {
          mPBuffers.push_back(sur);
      }
-@@ -265,19 +156,19 @@ Platform::SwapChain* PlatformGLX::createSwapChain(
+@@ -265,19 +170,19 @@ Platform::SwapChain* PlatformGLX::createSwapChain(
  void PlatformGLX::destroySwapChain(Platform::SwapChain* swapChain) noexcept {
      auto it = std::find(mPBuffers.begin(), mPBuffers.end(), (GLXPbuffer)swapChain);
      if (it != mPBuffers.end()) {