[vlc-commits] [Git][videolan/vlc][master] 6 commits: opengl: gl_util: use early return
Steve Lhomme (@robUx4)
gitlab at videolan.org
Tue Oct 3 05:23:28 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
1744f25c by Alexandre Janniaux at 2023-10-03T05:04:01+00:00
opengl: gl_util: use early return
- - - - -
c0373d30 by Alexandre Janniaux at 2023-10-03T05:04:01+00:00
opengl: gl_util: reindent after last changes
- - - - -
e09743a4 by Alexandre Janniaux at 2023-10-03T05:04:01+00:00
gl_common: add glGetAttachedShaders
- - - - -
355d0020 by Alexandre Janniaux at 2023-10-03T05:04:01+00:00
opengl: gl_util: refactor LogShader
- - - - -
118e4bc0 by Alexandre Janniaux at 2023-10-03T05:04:01+00:00
opengl: gl_util: log shaders on program errors
- - - - -
bdfe5c77 by Alexandre Janniaux at 2023-10-03T05:04:01+00:00
opengl: sub_renderer: dynamically setup version
The GLSL version was chosen at compile time, but the sub_renderer is
built for both OpenGL and GL ES, and linux can have both implementations
at the same time, so ensure the correct version will be picked at
runtime.
Fixes the following error in test:
test_opengl gl error: program: error: vertex shader lacks `main'
- - - - -
4 changed files:
- modules/video_output/opengl/gl_api.c
- modules/video_output/opengl/gl_common.h
- modules/video_output/opengl/gl_util.c
- modules/video_output/opengl/sub_renderer.c
Changes:
=====================================
modules/video_output/opengl/gl_api.c
=====================================
@@ -98,6 +98,7 @@ vlc_gl_api_Init(struct vlc_gl_api *api, vlc_gl_t *gl)
GET_PROC_ADDR(GetProgramiv);
GET_PROC_ADDR(GetShaderiv);
GET_PROC_ADDR(GetProgramInfoLog);
+ GET_PROC_ADDR_EXT(GetAttachedShaders, true);
GET_PROC_ADDR(GetShaderInfoLog);
GET_PROC_ADDR(GetShaderSource);
=====================================
modules/video_output/opengl/gl_common.h
=====================================
@@ -261,11 +261,13 @@ typedef void (APIENTRY *PFNGLBLITFRAMEBUFFERPROC) (GLint srcX0, GLint srcY0, GLi
GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
GLbitfield mask, GLenum filter);
typedef void (APIENTRY *PFNGLREADPIXELSPROC) (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, void *);
+typedef void (APIENTRY *PFNGLGETATTACHEDSHADERPROC)(GLuint, GLsizei, GLsizei*, GLuint*);
/* The following are defined in glext.h but not for GLES2 or on Apple systems */
#if defined(USE_OPENGL_ES2) || defined(__APPLE__)
# define PFNGLGETPROGRAMIVPROC typeof(glGetProgramiv)*
# define PFNGLGETPROGRAMINFOLOGPROC typeof(glGetProgramInfoLog)*
+# define PFNGLGETATTACHEDSHADERPROC typeof(glGetAttachedShaders)*
# define PFNGLGETSHADERSOURCEPROC typeof(glGetShaderSource)*
# define PFNGLGETSHADERIVPROC typeof(glGetShaderiv)*
# define PFNGLGETSHADERINFOLOGPROC typeof(glGetShaderInfoLog)*
@@ -399,6 +401,7 @@ typedef struct {
PFNGLLINKPROGRAMPROC LinkProgram;
PFNGLUSEPROGRAMPROC UseProgram;
PFNGLDELETEPROGRAMPROC DeleteProgram;
+ PFNGLGETATTACHEDSHADERPROC GetAttachedShaders;
/* Texture commands */
PFNGLACTIVETEXTUREPROC ActiveTexture;
=====================================
modules/video_output/opengl/gl_util.c
=====================================
@@ -32,25 +32,13 @@
#include <vlc_memstream.h>
static void
-LogShaderErrors(vlc_object_t *obj, const opengl_vtable_t *vt, GLuint id)
+LogShader(vlc_object_t *obj, const char *prefix, const opengl_vtable_t *vt, GLuint id)
{
- GLint info_len;
- vt->GetShaderiv(id, GL_INFO_LOG_LENGTH, &info_len);
- if (info_len <= 0)
- return;
-
- char *info_log = malloc(info_len);
- if (info_log == NULL)
- return;
-
- GLsizei written;
- vt->GetShaderInfoLog(id, info_len, &written, info_log);
-
GLint size;
vt->GetShaderiv(id, GL_SHADER_SOURCE_LENGTH, &size);
char *sources = malloc(size + 1);
if (sources == NULL)
- goto end;
+ return;
vt->GetShaderSource(id, size + 1, NULL, sources);
@@ -60,7 +48,10 @@ LogShaderErrors(vlc_object_t *obj, const opengl_vtable_t *vt, GLuint id)
/* This is debugging code, we don't want an hard failure if
* the allocation failed. */
if (ret != 0)
- goto end;
+ {
+ free(sources);
+ return;
+ }
const char *cursor = sources;
size_t line = 1;
@@ -82,15 +73,35 @@ LogShaderErrors(vlc_object_t *obj, const opengl_vtable_t *vt, GLuint id)
ret = vlc_memstream_close(&stream);
if (ret != 0)
- goto end;
+ {
+ free(sources);
+ return;
+ }
- msg_Err(obj, "Shader:\n%s", stream.ptr);
+ msg_Err(obj, "%s%s", prefix, stream.ptr);
free(stream.ptr);
+ free(sources);
+}
+
+static void
+LogShaderErrors(vlc_object_t *obj, const opengl_vtable_t *vt, GLuint id)
+{
+ GLint info_len;
+ vt->GetShaderiv(id, GL_INFO_LOG_LENGTH, &info_len);
+ if (info_len <= 0)
+ return;
+
+ char *info_log = malloc(info_len);
+ if (info_log == NULL)
+ return;
+
+ GLsizei written;
+ vt->GetShaderInfoLog(id, info_len, &written, info_log);
+
+ LogShader(obj, "Shader source:\n", vt, id);
-end:
msg_Err(obj, "shader: %s", info_log);
free(info_log);
- free(sources);
}
static void
@@ -98,17 +109,32 @@ LogProgramErrors(vlc_object_t *obj, const opengl_vtable_t *vt, GLuint id)
{
GLint info_len;
vt->GetProgramiv(id, GL_INFO_LOG_LENGTH, &info_len);
- if (info_len > 0)
+ if (info_len <= 0)
+ return;
+ char *info_log = malloc(info_len);
+ if (info_log == NULL)
+ return;
+
+
+ GLsizei shader_count;
+ GLuint shaders[3];
+ vt->GetAttachedShaders(id, 2, &shader_count, shaders);
+ for (size_t i=0; i<shader_count; ++i)
{
- char *info_log = malloc(info_len);
- if (info_log)
- {
- GLsizei written;
- vt->GetProgramInfoLog(id, info_len, &written, info_log);
- msg_Err(obj, "program: %s", info_log);
- free(info_log);
- }
+ GLint shader_type;
+ vt->GetShaderiv(shaders[i], GL_SHADER_TYPE, &shader_type);
+
+ const char *prefix =
+ shader_type == GL_VERTEX_SHADER ? "vertex shader:\n" :
+ shader_type == GL_FRAGMENT_SHADER ? "fragment shader:\n" :
+ "unknown shader:\n";
+ LogShader(obj, prefix, vt, shaders[i]);
}
+
+ GLsizei written;
+ vt->GetProgramInfoLog(id, info_len, &written, info_log);
+ msg_Err(obj, "program: %s", info_log);
+ free(info_log);
}
static GLuint
=====================================
modules/video_output/opengl/sub_renderer.c
=====================================
@@ -132,11 +132,10 @@ vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
sr->regions = NULL;
static const char *const VERTEX_SHADER_SRC =
-#if defined(USE_OPENGL_ES2)
- "#version 100\n"
-#else
- "#version 120\n"
-#endif
+ "#ifdef GL_ES\n"
+ "precision mediump float;\n"
+ "#endif\n"
+
"attribute vec2 vertex_pos;\n"
"attribute vec2 tex_coords_in;\n"
"varying vec2 tex_coords;\n"
@@ -146,12 +145,10 @@ vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
"}\n";
static const char *const FRAGMENT_SHADER_SRC =
-#if defined(USE_OPENGL_ES2)
- "#version 100\n"
+ "#ifdef GL_ES\n"
"precision mediump float;\n"
-#else
- "#version 120\n"
-#endif
+ "#endif\n"
+
"uniform sampler2D sampler;\n"
"uniform float alpha;\n"
"varying vec2 tex_coords;\n"
@@ -161,10 +158,23 @@ vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
" gl_FragColor = color;\n"
"}\n";
+ const char *glsl_version = gl->api_type == VLC_OPENGL ?
+ "#version 120\n" : "#version 100\n";
+
+ const char *vertex_shader[] = {
+ glsl_version,
+ VERTEX_SHADER_SRC,
+ };
+
+ const char *fragment_shader[] = {
+ glsl_version,
+ FRAGMENT_SHADER_SRC,
+ };
+
sr->program_id =
vlc_gl_BuildProgram(VLC_OBJECT(sr->gl), vt,
- 1, (const char **) &VERTEX_SHADER_SRC,
- 1, (const char **) &FRAGMENT_SHADER_SRC);
+ ARRAY_SIZE(vertex_shader), vertex_shader,
+ ARRAY_SIZE(fragment_shader), fragment_shader);
if (!sr->program_id)
goto error_1;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/17377f4b7e49b036d395ee58ca9c35ba84c1d342...bdfe5c778e0a952fdb4b514af7ab02a7322e2b0c
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/17377f4b7e49b036d395ee58ca9c35ba84c1d342...bdfe5c778e0a952fdb4b514af7ab02a7322e2b0c
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list