[Bf-blender-cvs] [2381efb38ea] epoxy: port EGL from GLEW to epoxy

Christian Rauch noreply at git.blender.org
Sat Jun 25 01:38:02 CEST 2022


Commit: 2381efb38ea6d3e8e649acdb3ee9a8598dab5f12
Author: Christian Rauch
Date:   Fri Jun 24 23:47:36 2022 +0100
Branches: epoxy
https://developer.blender.org/rB2381efb38ea6d3e8e649acdb3ee9a8598dab5f12

port EGL from GLEW to epoxy

===================================================================

M	intern/ghost/intern/GHOST_Context.cpp
M	intern/ghost/intern/GHOST_Context.h
M	intern/ghost/intern/GHOST_ContextEGL.cpp
M	intern/ghost/intern/GHOST_ContextEGL.h
M	intern/ghost/intern/GHOST_SystemX11.cpp
M	intern/ghost/intern/GHOST_WindowX11.cpp
M	source/blender/gpu/opengl/gl_backend.cc
M	source/blender/gpu/opengl/gl_batch.hh
M	source/blender/gpu/opengl/gl_context.cc
M	source/blender/gpu/opengl/gl_context.hh
M	source/blender/gpu/opengl/gl_debug.cc
M	source/blender/gpu/opengl/gl_debug.hh
M	source/blender/gpu/opengl/gl_framebuffer.hh
M	source/blender/gpu/opengl/gl_immediate.hh
M	source/blender/gpu/opengl/gl_index_buffer.hh
M	source/blender/gpu/opengl/gl_primitive.hh
M	source/blender/gpu/opengl/gl_query.hh
M	source/blender/gpu/opengl/gl_shader.cc
M	source/blender/gpu/opengl/gl_shader.hh
M	source/blender/gpu/opengl/gl_shader_interface.hh
M	source/blender/gpu/opengl/gl_state.hh
M	source/blender/gpu/opengl/gl_storage_buffer.hh
M	source/blender/gpu/opengl/gl_texture.hh
M	source/blender/gpu/opengl/gl_uniform_buffer.hh
M	source/blender/gpu/opengl/gl_vertex_array.hh
M	source/blender/gpu/opengl/gl_vertex_buffer.hh
M	source/blender/python/generic/bgl.c

===================================================================

diff --git a/intern/ghost/intern/GHOST_Context.cpp b/intern/ghost/intern/GHOST_Context.cpp
index f9aa80dc13d..7f70cb6d2c7 100644
--- a/intern/ghost/intern/GHOST_Context.cpp
+++ b/intern/ghost/intern/GHOST_Context.cpp
@@ -10,7 +10,6 @@
 #include "GHOST_Context.h"
 
 #ifdef _WIN32
-#  include <GL/wglew.h>  // only for symbolic constants, do not use API functions
 #  include <tchar.h>
 #
 #  ifndef ERROR_PROFILE_DOES_NOT_MATCH_DEVICE
@@ -122,11 +121,6 @@ bool win32_chk(bool result, const char *file, int line, const char *text)
 
 #endif  // _WIN32
 
-void GHOST_Context::initContextGLEW()
-{
-  GLEW_CHK(glewInit());
-}
-
 void GHOST_Context::initClearGL()
 {
   glClearColor(0.294, 0.294, 0.294, 0.000);
diff --git a/intern/ghost/intern/GHOST_Context.h b/intern/ghost/intern/GHOST_Context.h
index d9c2cdce258..cf6aadd5cc5 100644
--- a/intern/ghost/intern/GHOST_Context.h
+++ b/intern/ghost/intern/GHOST_Context.h
@@ -11,7 +11,7 @@
 #include "GHOST_IContext.h"
 #include "GHOST_Types.h"
 
-#include "glew-mx.h"
+#include <epoxy/gl.h>
 
 #include <cstdlib>  // for NULL
 
@@ -120,8 +120,6 @@ class GHOST_Context : public GHOST_IContext {
   }
 
  protected:
-  void initContextGLEW();
-
   bool m_stereoVisual;
 
   static void initClearGL();
diff --git a/intern/ghost/intern/GHOST_ContextEGL.cpp b/intern/ghost/intern/GHOST_ContextEGL.cpp
index 8c44dfe0158..2120f5a7b71 100644
--- a/intern/ghost/intern/GHOST_ContextEGL.cpp
+++ b/intern/ghost/intern/GHOST_ContextEGL.cpp
@@ -151,15 +151,6 @@ static bool egl_chk(bool result,
 #  define EGL_CHK(x) egl_chk(x)
 #endif
 
-static inline bool bindAPI(EGLenum api)
-{
-  if (EGLEW_VERSION_1_2) {
-    return (EGL_CHK(eglBindAPI(api)) == EGL_TRUE);
-  }
-
-  return false;
-}
-
 #ifdef WITH_GL_ANGLE
 HMODULE GHOST_ContextEGL::s_d3dcompiler = nullptr;
 #endif
@@ -256,7 +247,7 @@ GHOST_TSuccess GHOST_ContextEGL::swapBuffers()
 
 GHOST_TSuccess GHOST_ContextEGL::setSwapInterval(int interval)
 {
-  if (EGLEW_VERSION_1_1) {
+  if (epoxy_egl_version(m_display)>=11) {
     if (EGL_CHK(::eglSwapInterval(m_display, interval))) {
       m_swap_interval = interval;
 
@@ -313,26 +304,13 @@ GHOST_TSuccess GHOST_ContextEGL::releaseDrawingContext()
   return GHOST_kFailure;
 }
 
-bool GHOST_ContextEGL::initContextEGLEW()
+inline bool GHOST_ContextEGL::bindAPI(EGLenum api)
 {
-  /* We have to manually get this function before we can call eglewInit, since
-   * it requires a display argument. glewInit() does the same, but we only want
-   * to initialize EGLEW here. */
-  eglGetDisplay = (PFNEGLGETDISPLAYPROC)eglGetProcAddress("eglGetDisplay");
-  if (eglGetDisplay == nullptr) {
-    return false;
-  }
-
-  if (!EGL_CHK((m_display = ::eglGetDisplay(m_nativeDisplay)) != EGL_NO_DISPLAY)) {
-    return false;
-  }
-
-  if (GLEW_CHK(eglewInit(m_display)) != GLEW_OK) {
-    fprintf(stderr, "Warning! EGLEW failed to initialize properly.\n");
-    return false;
+  if (epoxy_egl_version(m_display)>=12) {
+    return (EGL_CHK(eglBindAPI(api)) == EGL_TRUE);
   }
 
-  return true;
+  return false;
 }
 
 static const std::string &api_string(EGLenum api)
@@ -355,10 +333,6 @@ GHOST_TSuccess GHOST_ContextEGL::initializeDrawingContext()
   }
   m_stereoVisual = false; /* It doesn't matter what the Window wants. */
 
-  if (!initContextEGLEW()) {
-    return GHOST_kFailure;
-  }
-
 #ifdef WITH_GL_ANGLE
   /* `d3dcompiler_XX.dll` needs to be loaded before ANGLE will work. */
   if (s_d3dcompiler == nullptr) {
@@ -380,6 +354,10 @@ GHOST_TSuccess GHOST_ContextEGL::initializeDrawingContext()
 
   EGLint egl_major, egl_minor;
 
+  if (!EGL_CHK((m_display = ::eglGetDisplay(m_nativeDisplay)) != EGL_NO_DISPLAY)) {
+    goto error;
+  }
+
   if (!EGL_CHK(::eglInitialize(m_display, &egl_major, &egl_minor))) {
     goto error;
   }
@@ -398,7 +376,7 @@ GHOST_TSuccess GHOST_ContextEGL::initializeDrawingContext()
 
   attrib_list.reserve(20);
 
-  if (m_api == EGL_OPENGL_ES_API && EGLEW_VERSION_1_2) {
+  if (m_api == EGL_OPENGL_ES_API && epoxy_egl_version(m_display)>=12) {
     /* According to the spec it seems that you are required to set EGL_RENDERABLE_TYPE,
      * but some implementations (ANGLE) do not seem to care. */
 
@@ -421,9 +399,9 @@ GHOST_TSuccess GHOST_ContextEGL::initializeDrawingContext()
               m_contextMinorVersion);
     }
 
-    if (!((m_contextMajorVersion == 1) || (m_contextMajorVersion == 2 && EGLEW_VERSION_1_3) ||
-          (m_contextMajorVersion == 3 && /*EGLEW_VERSION_1_4 &&*/ EGLEW_KHR_create_context) ||
-          (m_contextMajorVersion == 3 && EGLEW_VERSION_1_5))) {
+    if (!((m_contextMajorVersion == 1) || (m_contextMajorVersion == 2 && epoxy_egl_version(m_display)>=13) ||
+          (m_contextMajorVersion == 3 && epoxy_has_egl_extension(m_display, "KHR_create_context")) ||
+          (m_contextMajorVersion == 3 && epoxy_egl_version(m_display)>=15))) {
       fprintf(stderr,
               "Warning! May not be able to create a version %d.%d ES context with version %d.%d "
               "of EGL\n",
@@ -488,7 +466,7 @@ GHOST_TSuccess GHOST_ContextEGL::initializeDrawingContext()
   }
   attrib_list.clear();
 
-  if (EGLEW_VERSION_1_5 || EGLEW_KHR_create_context) {
+  if (epoxy_egl_version(m_display)>=15 || epoxy_has_egl_extension(m_display, "KHR_create_context")) {
     if (m_api == EGL_OPENGL_API || m_api == EGL_OPENGL_ES_API) {
       if (m_contextMajorVersion != 0) {
         attrib_list.push_back(EGL_CONTEXT_MAJOR_VERSION_KHR);
@@ -530,7 +508,7 @@ GHOST_TSuccess GHOST_ContextEGL::initializeDrawingContext()
       }
     }
 
-    if (m_api == EGL_OPENGL_API || EGLEW_VERSION_1_5) {
+    if (m_api == EGL_OPENGL_API || epoxy_egl_version(m_display)>=15) {
       if (m_contextResetNotificationStrategy != 0) {
         attrib_list.push_back(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR);
         attrib_list.push_back(m_contextResetNotificationStrategy);
@@ -598,8 +576,6 @@ GHOST_TSuccess GHOST_ContextEGL::initializeDrawingContext()
     goto error;
   }
 
-  initContextGLEW();
-
   initClearGL();
   ::eglSwapBuffers(m_display, m_surface);
 
diff --git a/intern/ghost/intern/GHOST_ContextEGL.h b/intern/ghost/intern/GHOST_ContextEGL.h
index 3250dc94978..852b3539d78 100644
--- a/intern/ghost/intern/GHOST_ContextEGL.h
+++ b/intern/ghost/intern/GHOST_ContextEGL.h
@@ -10,7 +10,8 @@
 #include "GHOST_Context.h"
 #include "GHOST_System.h"
 
-#include <GL/eglew.h>
+#include <epoxy/gl.h>
+#include <epoxy/egl.h>
 
 #ifndef GHOST_OPENGL_EGL_CONTEXT_FLAGS
 #  define GHOST_OPENGL_EGL_CONTEXT_FLAGS 0
@@ -96,7 +97,7 @@ class GHOST_ContextEGL : public GHOST_Context {
   EGLContext getContext() const;
 
  private:
-  bool initContextEGLEW();
+  bool bindAPI(EGLenum api);
 
   const GHOST_System *const m_system;
 
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp
index bed9cd6c784..7af4ef0774b 100644
--- a/intern/ghost/intern/GHOST_SystemX11.cpp
+++ b/intern/ghost/intern/GHOST_SystemX11.cpp
@@ -393,16 +393,6 @@ GHOST_IContext *GHOST_SystemX11::createOffscreenContext(GHOST_GLSettings glSetti
 
   const bool debug_context = (glSettings.flags & GHOST_glDebugContext) != 0;
 
-#if defined(WITH_GL_PROFILE_CORE)
-  {
-    const char *version_major = (char *)glewGetString(GLEW_VERSION_MAJOR);
-    if (version_major != nullptr && version_major[0] == '1') {
-      fprintf(stderr, "Error: GLEW version 2.0 and above is required.\n");
-      abort();
-    }
-  }
-#endif
-
   const int profile_mask =
 #ifdef WITH_GL_EGL
 #  if defined(WITH_GL_PROFILE_CORE)
diff --git a/intern/ghost/intern/GHOST_WindowX11.cpp b/intern/ghost/intern/GHOST_WindowX11.cpp
index ac7a476c76f..20f89abc29d 100644
--- a/intern/ghost/intern/GHOST_WindowX11.cpp
+++ b/intern/ghost/intern/GHOST_WindowX11.cpp
@@ -1298,16 +1298,6 @@ GHOST_Context *GHOST_WindowX11::newDrawingContext(GHOST_TDrawingContextType type
      * - Try 3.3 core profile
      * - No fall-backs. */
 
-#if defined(WITH_GL_PROFILE_CORE)
-    {
-      const char *version_major = (char *)glewGetString(GLEW_VERSION_MAJOR);
-      if (version_major != nullptr && version_major[0] == '1') {
-        fprintf(stderr, "Error: GLEW version 2.0 and above is required.\n");
-        abort();
-      }
-    }
-#endif
-
     const int profile_mask =
 #ifdef WITH_GL_EGL
 #  if defined(WITH_GL_PROFILE_CORE)
diff --git a/source/blender/gpu/opengl/gl_backend.cc b/source/blender/gpu/opengl/gl_backend.cc
index 4869bff2737..375063411e7 100644
--- a/source/blender/gpu/opengl/gl_backend.cc
+++ b/source/blender/gpu/opengl/gl_backend.cc
@@ -113,7 +113,7 @@ void GLBackend::platform_init()
   }
 
   /* Detect support level */
-  if (!GLEW_VERSION_3_3) {
+  if (!(epoxy_gl_version()>=33)) {
     support_level = GPU_SUPPORT_LEVEL_UNSUPPORTED;
   }
   else {
@@ -243,14 +243,14 @@ static void detect_workarounds()
     return;
   }
 
-  /* Limit support for GLEW_ARB_base_instance to OpenGL 4.0 and higher. NVIDIA Quadro FX 4800
-   * (TeraScale) report that they support GLEW_ARB_base_instance, but the driver does not support
+  /* Limit support for GL_ARB_base_instance to OpenGL 4.0 and higher. NVIDIA Quadro FX 4800
+   * (TeraScale) report that they support GL_ARB_base_instance, but the driver does not support
    * GLEW_ARB_draw_indirect as it has an OpenGL3 context what also matches the minimum needed
    * requirements.
    *
    * We use it as a target for glMapBuffer(Range) what is part of the OpenGL 4 API. So better
    * disable it when we don't have an OpenGL4 context (See T77657) */
-  if (!GLEW_VERSION_4_0) {
+  if (!(epoxy_gl_version()>=40)) {
     GLContext::base_instance_support = false;
   }
   if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_WIN, GPU_DRIVER_OFFICIAL) &&
@@ -313,7 +313,7 @@ static void detect_workarounds()
   /* Limit this fix to older hardware with GL < 4.5. This means Broadwell GPUs are
    * covered since they only support GL 4.4 on windows.
    * This fixes some issues with workbench anti-aliasing on Win + Intel GPU. (see T76273) */
-  if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_WIN, GPU_DRIVER_OFFICIAL) && !GLEW_VERSION_4_5) {
+  if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_WIN, GPU_DRIVER_OFFICIAL) && !(epoxy_gl_version()>=45)) {
     GLContext::copy_image_support = false;
   }
   /* Spec

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list