[vlc-commits] opengl: fix GL_ASSERT_NOERROR macro

Romain Vimont git at videolan.org
Tue Mar 17 11:02:11 CET 2020


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Wed Mar  4 08:53:49 2020 +0100| [0a71f665e1b3e5defba280fbd9c0d101184089e2] | committer: Steve Lhomme

opengl: fix GL_ASSERT_NOERROR macro

The macro assumed a local variable vgl existed, which is not always the
case.

Instead, pass a pointer to the opengl_vtable_t as parameter.

(cherry picked from commit 70e11c4f4e895269af9ecbd0e9a9666aa2a5ac33)

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

 modules/video_output/opengl/gl_common.h    |  8 +++++---
 modules/video_output/opengl/sub_renderer.c | 10 +++++-----
 modules/video_output/opengl/vout_helper.c  | 20 ++++++++++----------
 3 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/modules/video_output/opengl/gl_common.h b/modules/video_output/opengl/gl_common.h
index 303ef73131..e7a07ad869 100644
--- a/modules/video_output/opengl/gl_common.h
+++ b/modules/video_output/opengl/gl_common.h
@@ -21,6 +21,8 @@
 #ifndef VLC_GL_COMMON_H
 #define VLC_GL_COMMON_H
 
+#include <assert.h>
+
 /* if USE_OPENGL_ES2 is defined, OpenGL ES version 2 will be used, otherwise
  * normal OpenGL will be used */
 #ifdef __APPLE__
@@ -107,8 +109,8 @@
 #endif
 
 #ifdef HAVE_GL_ASSERT_NOERROR
-# define GL_ASSERT_NOERROR() do { \
-    GLenum glError = vgl->vt.GetError(); \
+# define GL_ASSERT_NOERROR(vt) do { \
+    GLenum glError = (vt)->GetError(); \
     switch (glError) \
     { \
         case GL_NO_ERROR: break; \
@@ -121,7 +123,7 @@
     } \
 } while(0)
 #else
-# define GL_ASSERT_NOERROR()
+# define GL_ASSERT_NOERROR(vt)
 #endif
 
 /* Core OpenGL/OpenGLES functions: the following functions pointers typedefs
diff --git a/modules/video_output/opengl/sub_renderer.c b/modules/video_output/opengl/sub_renderer.c
index f25900fd1c..a900f90473 100644
--- a/modules/video_output/opengl/sub_renderer.c
+++ b/modules/video_output/opengl/sub_renderer.c
@@ -320,7 +320,7 @@ vlc_gl_sub_renderer_Delete(struct vlc_gl_sub_renderer *sr)
 int
 vlc_gl_sub_renderer_Prepare(struct vlc_gl_sub_renderer *sr, subpicture_t *subpicture)
 {
-    GL_ASSERT_NOERROR();
+    GL_ASSERT_NOERROR(sr->vt);
 
     const struct vlc_gl_interop *interop = sr->interop;
 
@@ -408,7 +408,7 @@ vlc_gl_sub_renderer_Prepare(struct vlc_gl_sub_renderer *sr, subpicture_t *subpic
     }
     free(last);
 
-    GL_ASSERT_NOERROR();
+    GL_ASSERT_NOERROR(sr->vt);
 
     return VLC_SUCCESS;
 }
@@ -416,11 +416,11 @@ vlc_gl_sub_renderer_Prepare(struct vlc_gl_sub_renderer *sr, subpicture_t *subpic
 int
 vlc_gl_sub_renderer_Draw(struct vlc_gl_sub_renderer *sr)
 {
-    GL_ASSERT_NOERROR();
-
     const struct vlc_gl_interop *interop = sr->interop;
     const opengl_vtable_t *vt = sr->vt;
 
+    GL_ASSERT_NOERROR(vt);
+
     assert(sr->program_id);
     vt->UseProgram(sr->program_id);
 
@@ -477,7 +477,7 @@ vlc_gl_sub_renderer_Draw(struct vlc_gl_sub_renderer *sr)
     }
     vt->Disable(GL_BLEND);
 
-    GL_ASSERT_NOERROR();
+    GL_ASSERT_NOERROR(vt);
 
     return VLC_SUCCESS;
 }
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index d4a2eda148..61f1321f69 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -197,7 +197,7 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
     GET_PROC_ADDR_OPTIONAL(ClientWaitSync);
 #undef GET_PROC_ADDR
 
-    GL_ASSERT_NOERROR();
+    GL_ASSERT_NOERROR(&vgl->vt);
 
     const char *extensions = (const char *)vgl->vt.GetString(GL_EXTENSIONS);
     assert(extensions);
@@ -251,7 +251,7 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
         return NULL;
     }
 
-    GL_ASSERT_NOERROR();
+    GL_ASSERT_NOERROR(&vgl->vt);
 
     vgl->sub_renderer =
         vlc_gl_sub_renderer_New(gl, &vgl->vt, supports_npot);
@@ -263,7 +263,7 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
         return NULL;
     }
 
-    GL_ASSERT_NOERROR();
+    GL_ASSERT_NOERROR(&vgl->vt);
 
     if (renderer->fmt.projection_mode != PROJECTION_MODE_RECTANGULAR
      && vout_display_opengl_SetViewpoint(vgl, viewpoint) != VLC_SUCCESS)
@@ -277,13 +277,13 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
         *subpicture_chromas = gl_subpicture_chromas;
     }
 
-    GL_ASSERT_NOERROR();
+    GL_ASSERT_NOERROR(&vgl->vt);
     return vgl;
 }
 
 void vout_display_opengl_Delete(vout_display_opengl_t *vgl)
 {
-    GL_ASSERT_NOERROR();
+    GL_ASSERT_NOERROR(&vgl->vt);
 
     /* */
     vgl->vt.Finish();
@@ -292,7 +292,7 @@ void vout_display_opengl_Delete(vout_display_opengl_t *vgl)
     vlc_gl_sub_renderer_Delete(vgl->sub_renderer);
     vlc_gl_renderer_Delete(vgl->renderer);
 
-    GL_ASSERT_NOERROR();
+    GL_ASSERT_NOERROR(&vgl->vt);
 
     free(vgl);
 }
@@ -318,20 +318,20 @@ void vout_display_opengl_Viewport(vout_display_opengl_t *vgl, int x, int y,
 int vout_display_opengl_Prepare(vout_display_opengl_t *vgl,
                                 picture_t *picture, subpicture_t *subpicture)
 {
-    GL_ASSERT_NOERROR();
+    GL_ASSERT_NOERROR(&vgl->vt);
 
     int ret = vlc_gl_renderer_Prepare(vgl->renderer, picture);
     if (ret != VLC_SUCCESS)
         return ret;
 
     ret = vlc_gl_sub_renderer_Prepare(vgl->sub_renderer, subpicture);
-    GL_ASSERT_NOERROR();
+    GL_ASSERT_NOERROR(&vgl->vt);
     return ret;
 }
 int vout_display_opengl_Display(vout_display_opengl_t *vgl,
                                 const video_format_t *source)
 {
-    GL_ASSERT_NOERROR();
+    GL_ASSERT_NOERROR(&vgl->vt);
 
     /* Why drawing here and not in Render()? Because this way, the
        OpenGL providers can call vout_display_opengl_Display to force redraw.
@@ -348,7 +348,7 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl,
     /* Display */
     vlc_gl_Swap(vgl->gl);
 
-    GL_ASSERT_NOERROR();
+    GL_ASSERT_NOERROR(&vgl->vt);
 
     return VLC_SUCCESS;
 }



More information about the vlc-commits mailing list