[vlc-commits] opengl: forward api type in vlc_gl_api_Init

Alexandre Janniaux git at videolan.org
Fri Jan 29 11:06:22 UTC 2021


vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Thu Jan 28 12:11:11 2021 +0100| [df6bc9dedd034423221b437fbcc74fa18f8f98f6] | committer: Alexandre Janniaux

opengl: forward api type in vlc_gl_api_Init

Instead of defining it at compile time.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=df6bc9dedd034423221b437fbcc74fa18f8f98f6
---

 include/vlc_opengl.h                 |  2 ++
 modules/video_output/caopengllayer.m |  1 +
 modules/video_output/ios.m           |  1 +
 modules/video_output/macosx.m        |  1 +
 modules/video_output/opengl/gl_api.c | 44 ++++++++++++++++++++++--------------
 src/video_output/opengl.c            |  5 ++++
 6 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/include/vlc_opengl.h b/include/vlc_opengl.h
index ffb81a651d..a99c6ced64 100644
--- a/include/vlc_opengl.h
+++ b/include/vlc_opengl.h
@@ -83,6 +83,8 @@ struct vlc_gl_t
         } wgl;
     };
 
+    /* Defined by the core for libvlc_opengl API loading. */
+    enum vlc_gl_api_type api_type;
 };
 
 /**
diff --git a/modules/video_output/caopengllayer.m b/modules/video_output/caopengllayer.m
index 587817d153..6873a1b450 100644
--- a/modules/video_output/caopengllayer.m
+++ b/modules/video_output/caopengllayer.m
@@ -191,6 +191,7 @@ static int Open (vout_display_t *vd, const vout_display_cfg_t *cfg,
         sys->gl->release_current = OpenglUnlock;
         sys->gl->swap = OpenglSwap;
         sys->gl->get_proc_address = OurGetProcAddress;
+        sys->gl->api_type = VLC_OPENGL;
 
         struct gl_sys *glsys = sys->gl->sys = malloc(sizeof(*glsys));
         if (!sys->gl->sys)
diff --git a/modules/video_output/ios.m b/modules/video_output/ios.m
index 443c23d417..1a67a2de72 100644
--- a/modules/video_output/ios.m
+++ b/modules/video_output/ios.m
@@ -202,6 +202,7 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
         sys->gl->release_current = GLESReleaseCurrent;
         sys->gl->swap = GLESSwap;
         sys->gl->get_proc_address = OurGetProcAddress;
+        sys->gl->api_type = VLC_OPENGL_ES2;
 
         if (vlc_gl_MakeCurrent(sys->gl) != VLC_SUCCESS)
             goto bailout;
diff --git a/modules/video_output/macosx.m b/modules/video_output/macosx.m
index ee1feaad09..9420abaf90 100644
--- a/modules/video_output/macosx.m
+++ b/modules/video_output/macosx.m
@@ -227,6 +227,7 @@ static int Open (vout_display_t *vd, const vout_display_cfg_t *cfg,
         sys->gl->release_current = OpenglUnlock;
         sys->gl->swap = OpenglSwap;
         sys->gl->get_proc_address = OurGetProcAddress;
+        sys->gl->api_type = VLC_OPENGL;
 
         const vlc_fourcc_t *subpicture_chromas;
 
diff --git a/modules/video_output/opengl/gl_api.c b/modules/video_output/opengl/gl_api.c
index d990493832..dd8f37c9ba 100644
--- a/modules/video_output/opengl/gl_api.c
+++ b/modules/video_output/opengl/gl_api.c
@@ -39,6 +39,7 @@ vlc_gl_api_Init(struct vlc_gl_api *api, vlc_gl_t *gl)
 #else
 #define GET_PROC_ADDR_CORE(name) GET_PROC_ADDR_EXT(name, true)
 #endif
+
 #define GET_PROC_ADDR_EXT(name, critical) do { \
     api->vt.name = vlc_gl_GetProcAddress(gl, "gl"#name); \
     if (api->vt.name == NULL && critical) { \
@@ -46,13 +47,19 @@ vlc_gl_api_Init(struct vlc_gl_api *api, vlc_gl_t *gl)
         return VLC_EGENERIC; \
     } \
 } while(0)
-#if defined(USE_OPENGL_ES2)
-#define GET_PROC_ADDR(name) GET_PROC_ADDR_CORE(name)
-#define GET_PROC_ADDR_CORE_GL(name) GET_PROC_ADDR_EXT(name, false) /* optional for GLES */
-#else
-#define GET_PROC_ADDR(name) GET_PROC_ADDR_EXT(name, true)
-#define GET_PROC_ADDR_CORE_GL(name) GET_PROC_ADDR_CORE(name)
-#endif
+
+#define GET_PROC_ADDR(name) \
+    if (gl->api_type == VLC_OPENGL_ES2) \
+        GET_PROC_ADDR_CORE(name); \
+    else \
+        GET_PROC_ADDR_EXT(name, true)
+
+#define GET_PROC_ADDR_CORE_GL(name) \
+    if (gl->api_type == VLC_OPENGL_ES2) \
+        GET_PROC_ADDR_EXT(name, false); /* optional for GLES */ \
+    else \
+        GET_PROC_ADDR_CORE(name)
+
 #define GET_PROC_ADDR_OPTIONAL(name) GET_PROC_ADDR_EXT(name, false) /* GL 3 or more */
 
     GET_PROC_ADDR_CORE(BindTexture);
@@ -167,16 +174,19 @@ vlc_gl_api_Init(struct vlc_gl_api *api, vlc_gl_t *gl)
     while (error != GL_NO_ERROR)
         error = api->vt.GetError();
 
-#ifdef USE_OPENGL_ES2
-    api->is_gles = true;
-    /* OpenGL ES 2 includes support for non-power of 2 textures by specification
-     * so checks for extensions are bound to fail. Check for OpenGL ES version instead. */
-    api->supports_npot = true;
-#else
-    api->is_gles = false;
-    api->supports_npot = vlc_gl_StrHasToken(api->extensions, "GL_ARB_texture_non_power_of_two") ||
-                         vlc_gl_StrHasToken(api->extensions, "GL_APPLE_texture_2D_limited_npot");
-#endif
+    if (gl->api_type == VLC_OPENGL_ES2)
+    {
+        api->is_gles = true;
+        /* OpenGL ES 2 includes support for non-power of 2 textures by specification
+         * so checks for extensions are bound to fail. Check for OpenGL ES version instead. */
+        api->supports_npot = true;
+    }
+    else
+    {
+        api->is_gles = false;
+        api->supports_npot = vlc_gl_StrHasToken(api->extensions, "GL_ARB_texture_non_power_of_two") ||
+                             vlc_gl_StrHasToken(api->extensions, "GL_APPLE_texture_2D_limited_npot");
+    }
 
     return VLC_SUCCESS;
 }
diff --git a/src/video_output/opengl.c b/src/video_output/opengl.c
index ce127b8b3a..8355c16135 100644
--- a/src/video_output/opengl.c
+++ b/src/video_output/opengl.c
@@ -59,13 +59,17 @@ vlc_gl_t *vlc_gl_Create(const struct vout_display_cfg *restrict cfg,
     struct vlc_gl_priv_t *glpriv;
     const char *type;
 
+    enum vlc_gl_api_type api_type;
+
     switch (flags /*& VLC_OPENGL_API_MASK*/)
     {
         case VLC_OPENGL:
             type = "opengl";
+            api_type = VLC_OPENGL;
             break;
         case VLC_OPENGL_ES2:
             type = "opengl es2";
+            api_type = VLC_OPENGL_ES2;
             break;
         default:
             return NULL;
@@ -76,6 +80,7 @@ vlc_gl_t *vlc_gl_Create(const struct vout_display_cfg *restrict cfg,
         return NULL;
 
     vlc_gl_t *gl = &glpriv->gl;
+    gl->api_type = api_type;
     gl->surface = wnd;
     gl->module = vlc_module_load(gl, type, name, true, vlc_gl_start, gl,
                                  cfg->display.width, cfg->display.height);



More information about the vlc-commits mailing list