[vlc-devel] [PATCH 09/11] vout/opengl: expose shaders commands in an internal header
Thomas Guillem
thomas at gllm.fr
Wed Dec 14 17:16:14 CET 2016
---
modules/video_output/Makefile.am | 2 +-
modules/video_output/opengl/internal.h | 116 +++++++++
modules/video_output/opengl/vout_helper.c | 408 ++++++++++++------------------
3 files changed, 282 insertions(+), 244 deletions(-)
create mode 100644 modules/video_output/opengl/internal.h
diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am
index f53ad08..c566768 100644
--- a/modules/video_output/Makefile.am
+++ b/modules/video_output/Makefile.am
@@ -3,7 +3,7 @@ vout_LTLIBRARIES =
EXTRA_DIST += video_output/README
OPENGL_DISPLAY_SRCS = video_output/opengl/vout_helper.c \
- video_output/opengl/vout_helper.h
+ video_output/opengl/vout_helper.h video_output/opengl/internal.h
if HAVE_DECKLINK
libdecklinkoutput_plugin_la_SOURCES = video_output/decklink.cpp
diff --git a/modules/video_output/opengl/internal.h b/modules/video_output/opengl/internal.h
new file mode 100644
index 0000000..2a31cbc
--- /dev/null
+++ b/modules/video_output/opengl/internal.h
@@ -0,0 +1,116 @@
+/*****************************************************************************
+ * opengl_internal.h: OpenGL internal header
+ *****************************************************************************
+ * Copyright (C) 2016 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef VLC_OPENGL_INTERNAL_H
+#define VLC_OPENGL_INTERNAL_H
+
+#include "vout_helper.h"
+
+#if defined(USE_OPENGL_ES2)
+# define GLSL_VERSION "100"
+# define VLCGL_TEXTURE_COUNT 1
+# define PRECISION "precision highp float;"
+# define VLCGL_PICTURE_MAX 128
+# define glClientActiveTexture(x)
+#else
+# define GLSL_VERSION "120"
+# define VLCGL_TEXTURE_COUNT 1
+# define VLCGL_PICTURE_MAX 128
+# define PRECISION ""
+#endif
+
+#if defined(USE_OPENGL_ES2) || defined(__APPLE__)
+# define PFNGLGETPROGRAMIVPROC typeof(glGetProgramiv)*
+# define PFNGLGETPROGRAMINFOLOGPROC typeof(glGetProgramInfoLog)*
+# define PFNGLGETSHADERIVPROC typeof(glGetShaderiv)*
+# define PFNGLGETSHADERINFOLOGPROC typeof(glGetShaderInfoLog)*
+# define PFNGLGETUNIFORMLOCATIONPROC typeof(glGetUniformLocation)*
+# define PFNGLGETATTRIBLOCATIONPROC typeof(glGetAttribLocation)*
+# define PFNGLVERTEXATTRIBPOINTERPROC typeof(glVertexAttribPointer)*
+# define PFNGLENABLEVERTEXATTRIBARRAYPROC typeof(glEnableVertexAttribArray)*
+# define PFNGLUNIFORMMATRIX4FVPROC typeof(glUniformMatrix4fv)*
+# define PFNGLUNIFORM4FVPROC typeof(glUniform4fv)*
+# define PFNGLUNIFORM4FPROC typeof(glUniform4f)*
+# define PFNGLUNIFORM1IPROC typeof(glUniform1i)*
+# define PFNGLCREATESHADERPROC typeof(glCreateShader)*
+# define PFNGLSHADERSOURCEPROC typeof(glShaderSource)*
+# define PFNGLCOMPILESHADERPROC typeof(glCompileShader)*
+# define PFNGLDELETESHADERPROC typeof(glDeleteShader)*
+# define PFNGLCREATEPROGRAMPROC typeof(glCreateProgram)*
+# define PFNGLLINKPROGRAMPROC typeof(glLinkProgram)*
+# define PFNGLUSEPROGRAMPROC typeof(glUseProgram)*
+# define PFNGLDELETEPROGRAMPROC typeof(glDeleteProgram)*
+# define PFNGLATTACHSHADERPROC typeof(glAttachShader)*
+# define PFNGLGENBUFFERSPROC typeof(glGenBuffers)*
+# define PFNGLBINDBUFFERPROC typeof(glBindBuffer)*
+# define PFNGLBUFFERDATAPROC typeof(glBufferData)*
+# define PFNGLDELETEBUFFERSPROC typeof(glDeleteBuffers)*
+#if defined(__APPLE__)
+# import <CoreFoundation/CoreFoundation.h>
+#endif
+#endif
+
+/**
+ * Structure containing function pointers to shaders commands
+ */
+typedef struct {
+ /* Shader variables commands*/
+ PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation;
+ PFNGLGETATTRIBLOCATIONPROC GetAttribLocation;
+ PFNGLVERTEXATTRIBPOINTERPROC VertexAttribPointer;
+ PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray;
+
+ PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv;
+ PFNGLUNIFORM4FVPROC Uniform4fv;
+ PFNGLUNIFORM4FPROC Uniform4f;
+ PFNGLUNIFORM1IPROC Uniform1i;
+
+ /* Shader command */
+ PFNGLCREATESHADERPROC CreateShader;
+ PFNGLSHADERSOURCEPROC ShaderSource;
+ PFNGLCOMPILESHADERPROC CompileShader;
+ PFNGLDELETESHADERPROC DeleteShader;
+
+ PFNGLCREATEPROGRAMPROC CreateProgram;
+ PFNGLLINKPROGRAMPROC LinkProgram;
+ PFNGLUSEPROGRAMPROC UseProgram;
+ PFNGLDELETEPROGRAMPROC DeleteProgram;
+
+ PFNGLATTACHSHADERPROC AttachShader;
+
+ /* Shader log commands */
+ PFNGLGETPROGRAMIVPROC GetProgramiv;
+ PFNGLGETPROGRAMINFOLOGPROC GetProgramInfoLog;
+ PFNGLGETSHADERIVPROC GetShaderiv;
+ PFNGLGETSHADERINFOLOGPROC GetShaderInfoLog;
+
+ PFNGLGENBUFFERSPROC GenBuffers;
+ PFNGLBINDBUFFERPROC BindBuffer;
+ PFNGLBUFFERDATAPROC BufferData;
+ PFNGLDELETEBUFFERSPROC DeleteBuffers;
+
+#if defined(_WIN32)
+ PFNGLACTIVETEXTUREPROC ActiveTexture;
+ PFNGLCLIENTACTIVETEXTUREPROC ClientActiveTexture;
+#endif
+
+} opengl_shaders_api_t;
+
+#endif /* include-guard */
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index 3e34444..51a980c 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -40,55 +40,12 @@
#include <vlc_vout.h>
#include "vout_helper.h"
+#include "internal.h"
#ifndef GL_CLAMP_TO_EDGE
# define GL_CLAMP_TO_EDGE 0x812F
#endif
-#if defined(USE_OPENGL_ES2) || defined(__APPLE__)
-# define PFNGLGETPROGRAMIVPROC typeof(glGetProgramiv)*
-# define PFNGLGETPROGRAMINFOLOGPROC typeof(glGetProgramInfoLog)*
-# define PFNGLGETSHADERIVPROC typeof(glGetShaderiv)*
-# define PFNGLGETSHADERINFOLOGPROC typeof(glGetShaderInfoLog)*
-# define PFNGLGETUNIFORMLOCATIONPROC typeof(glGetUniformLocation)*
-# define PFNGLGETATTRIBLOCATIONPROC typeof(glGetAttribLocation)*
-# define PFNGLVERTEXATTRIBPOINTERPROC typeof(glVertexAttribPointer)*
-# define PFNGLENABLEVERTEXATTRIBARRAYPROC typeof(glEnableVertexAttribArray)*
-# define PFNGLUNIFORMMATRIX4FVPROC typeof(glUniformMatrix4fv)*
-# define PFNGLUNIFORM4FVPROC typeof(glUniform4fv)*
-# define PFNGLUNIFORM4FPROC typeof(glUniform4f)*
-# define PFNGLUNIFORM1IPROC typeof(glUniform1i)*
-# define PFNGLCREATESHADERPROC typeof(glCreateShader)*
-# define PFNGLSHADERSOURCEPROC typeof(glShaderSource)*
-# define PFNGLCOMPILESHADERPROC typeof(glCompileShader)*
-# define PFNGLDELETESHADERPROC typeof(glDeleteShader)*
-# define PFNGLCREATEPROGRAMPROC typeof(glCreateProgram)*
-# define PFNGLLINKPROGRAMPROC typeof(glLinkProgram)*
-# define PFNGLUSEPROGRAMPROC typeof(glUseProgram)*
-# define PFNGLDELETEPROGRAMPROC typeof(glDeleteProgram)*
-# define PFNGLATTACHSHADERPROC typeof(glAttachShader)*
-# define PFNGLGENBUFFERSPROC typeof(glGenBuffers)*
-# define PFNGLBINDBUFFERPROC typeof(glBindBuffer)*
-# define PFNGLBUFFERDATAPROC typeof(glBufferData)*
-# define PFNGLDELETEBUFFERSPROC typeof(glDeleteBuffers)*
-#if defined(__APPLE__)
-# import <CoreFoundation/CoreFoundation.h>
-#endif
-#endif
-
-#if defined(USE_OPENGL_ES2)
-# define GLSL_VERSION "100"
-# define VLCGL_TEXTURE_COUNT 1
-# define PRECISION "precision highp float;"
-# define VLCGL_PICTURE_MAX 128
-# define glClientActiveTexture(x)
-#else
-# define GLSL_VERSION "120"
-# define VLCGL_TEXTURE_COUNT 1
-# define VLCGL_PICTURE_MAX 128
-# define PRECISION ""
-#endif
-
#ifndef GL_RED
#define GL_RED 0
#endif
@@ -119,6 +76,7 @@ typedef struct {
struct vout_display_opengl_t {
vlc_gl_t *gl;
+ opengl_shaders_api_t api;
video_format_t fmt;
const vlc_chroma_description_t *chroma;
@@ -159,46 +117,6 @@ struct vout_display_opengl_t {
GLuint *subpicture_buffer_object;
int subpicture_buffer_object_count;
- /* Shader variables commands*/
- PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation;
- PFNGLGETATTRIBLOCATIONPROC GetAttribLocation;
- PFNGLVERTEXATTRIBPOINTERPROC VertexAttribPointer;
- PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray;
-
- PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv;
- PFNGLUNIFORM4FVPROC Uniform4fv;
- PFNGLUNIFORM4FPROC Uniform4f;
- PFNGLUNIFORM1IPROC Uniform1i;
-
- /* Shader command */
- PFNGLCREATESHADERPROC CreateShader;
- PFNGLSHADERSOURCEPROC ShaderSource;
- PFNGLCOMPILESHADERPROC CompileShader;
- PFNGLDELETESHADERPROC DeleteShader;
-
- PFNGLCREATEPROGRAMPROC CreateProgram;
- PFNGLLINKPROGRAMPROC LinkProgram;
- PFNGLUSEPROGRAMPROC UseProgram;
- PFNGLDELETEPROGRAMPROC DeleteProgram;
-
- PFNGLATTACHSHADERPROC AttachShader;
-
- /* Shader log commands */
- PFNGLGETPROGRAMIVPROC GetProgramiv;
- PFNGLGETPROGRAMINFOLOGPROC GetProgramInfoLog;
- PFNGLGETSHADERIVPROC GetShaderiv;
- PFNGLGETSHADERINFOLOGPROC GetShaderInfoLog;
-
- PFNGLGENBUFFERSPROC GenBuffers;
- PFNGLBINDBUFFERPROC BindBuffer;
- PFNGLBUFFERDATAPROC BufferData;
- PFNGLDELETEBUFFERSPROC DeleteBuffers;
-
-#if defined(_WIN32)
- PFNGLACTIVETEXTUREPROC ActiveTexture;
- PFNGLCLIENTACTIVETEXTUREPROC ClientActiveTexture;
-#endif
-
/* Non-power-of-2 texture size support */
bool supports_npot;
@@ -275,9 +193,9 @@ static void BuildVertexShader(vout_display_opengl_t *vgl,
" gl_Position = ProjectionMatrix * OrientationMatrix * ZoomMatrix * ZRotMatrix * XRotMatrix * YRotMatrix * vec4(VertexPosition, 1.0);"
"}";
- *shader = vgl->CreateShader(GL_VERTEX_SHADER);
- vgl->ShaderSource(*shader, 1, &vertexShader, NULL);
- vgl->CompileShader(*shader);
+ *shader = vgl->api.CreateShader(GL_VERTEX_SHADER);
+ vgl->api.ShaderSource(*shader, 1, &vertexShader, NULL);
+ vgl->api.CompileShader(*shader);
}
static void BuildYUVFragmentShader(vout_display_opengl_t *vgl,
@@ -357,9 +275,9 @@ static void BuildYUVFragmentShader(vout_display_opengl_t *vgl,
local_value[i*4+j] = j < 3 ? correction * matrix[j*4+i] : 0.f;
}
- *shader = vgl->CreateShader(GL_FRAGMENT_SHADER);
- vgl->ShaderSource(*shader, 1, (const char **)&code, NULL);
- vgl->CompileShader(*shader);
+ *shader = vgl->api.CreateShader(GL_FRAGMENT_SHADER);
+ vgl->api.ShaderSource(*shader, 1, (const char **)&code, NULL);
+ vgl->api.CompileShader(*shader);
free(code);
}
@@ -378,9 +296,9 @@ static void BuildRGBFragmentShader(vout_display_opengl_t *vgl,
"{ "
" gl_FragColor = texture2D(Texture[0], TexCoord0.st);"
"}";
- *shader = vgl->CreateShader(GL_FRAGMENT_SHADER);
- vgl->ShaderSource(*shader, 1, &code, NULL);
- vgl->CompileShader(*shader);
+ *shader = vgl->api.CreateShader(GL_FRAGMENT_SHADER);
+ vgl->api.ShaderSource(*shader, 1, &code, NULL);
+ vgl->api.CompileShader(*shader);
}
#endif
@@ -398,9 +316,9 @@ static void BuildRGBAFragmentShader(vout_display_opengl_t *vgl,
"{ "
" gl_FragColor = texture2D(Texture, TexCoord0.st) * FillColor;"
"}";
- *shader = vgl->CreateShader(GL_FRAGMENT_SHADER);
- vgl->ShaderSource(*shader, 1, &code, NULL);
- vgl->CompileShader(*shader);
+ *shader = vgl->api.CreateShader(GL_FRAGMENT_SHADER);
+ vgl->api.ShaderSource(*shader, 1, &code, NULL);
+ vgl->api.CompileShader(*shader);
}
static void BuildXYZFragmentShader(vout_display_opengl_t *vgl,
@@ -437,9 +355,9 @@ static void BuildXYZFragmentShader(vout_display_opengl_t *vgl,
" v_out = clamp(v_out, 0.0, 1.0) ;"
" gl_FragColor = v_out;"
"}";
- *shader = vgl->CreateShader(GL_FRAGMENT_SHADER);
- vgl->ShaderSource(*shader, 1, &code, NULL);
- vgl->CompileShader(*shader);
+ *shader = vgl->api.CreateShader(GL_FRAGMENT_SHADER);
+ vgl->api.ShaderSource(*shader, 1, &code, NULL);
+ vgl->api.CompileShader(*shader);
}
vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
@@ -475,71 +393,73 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
const int yuv_plane_texformat = GL_LUMINANCE;
#endif
+ opengl_shaders_api_t *api = &vgl->api;
+
#if defined(USE_OPENGL_ES2)
- vgl->CreateShader = glCreateShader;
- vgl->ShaderSource = glShaderSource;
- vgl->CompileShader = glCompileShader;
- vgl->AttachShader = glAttachShader;
-
- vgl->GetProgramiv = glGetProgramiv;
- vgl->GetShaderiv = glGetShaderiv;
- vgl->GetProgramInfoLog = glGetProgramInfoLog;
- vgl->GetShaderInfoLog = glGetShaderInfoLog;
-
- vgl->DeleteShader = glDeleteShader;
-
- vgl->GetUniformLocation = glGetUniformLocation;
- vgl->GetAttribLocation = glGetAttribLocation;
- vgl->VertexAttribPointer= glVertexAttribPointer;
- vgl->EnableVertexAttribArray = glEnableVertexAttribArray;
- vgl->UniformMatrix4fv = glUniformMatrix4fv;
- vgl->Uniform4fv = glUniform4fv;
- vgl->Uniform4f = glUniform4f;
- vgl->Uniform1i = glUniform1i;
-
- vgl->CreateProgram = glCreateProgram;
- vgl->LinkProgram = glLinkProgram;
- vgl->UseProgram = glUseProgram;
- vgl->DeleteProgram = glDeleteProgram;
-
- vgl->GenBuffers = glGenBuffers;
- vgl->BindBuffer = glBindBuffer;
- vgl->BufferData = glBufferData;
- vgl->DeleteBuffers = glDeleteBuffers;
+ api->CreateShader = glCreateShader;
+ api->ShaderSource = glShaderSource;
+ api->CompileShader = glCompileShader;
+ api->AttachShader = glAttachShader;
+
+ api->GetProgramiv = glGetProgramiv;
+ api->GetShaderiv = glGetShaderiv;
+ api->GetProgramInfoLog = glGetProgramInfoLog;
+ api->GetShaderInfoLog = glGetShaderInfoLog;
+
+ api->DeleteShader = glDeleteShader;
+
+ api->GetUniformLocation = glGetUniformLocation;
+ api->GetAttribLocation = glGetAttribLocation;
+ api->VertexAttribPointer= glVertexAttribPointer;
+ api->EnableVertexAttribArray = glEnableVertexAttribArray;
+ api->UniformMatrix4fv = glUniformMatrix4fv;
+ api->Uniform4fv = glUniform4fv;
+ api->Uniform4f = glUniform4f;
+ api->Uniform1i = glUniform1i;
+
+ api->CreateProgram = glCreateProgram;
+ api->LinkProgram = glLinkProgram;
+ api->UseProgram = glUseProgram;
+ api->DeleteProgram = glDeleteProgram;
+
+ api->GenBuffers = glGenBuffers;
+ api->BindBuffer = glBindBuffer;
+ api->BufferData = glBufferData;
+ api->DeleteBuffers = glDeleteBuffers;
#else
- vgl->CreateShader = (PFNGLCREATESHADERPROC)vlc_gl_GetProcAddress(vgl->gl, "glCreateShader");
- vgl->ShaderSource = (PFNGLSHADERSOURCEPROC)vlc_gl_GetProcAddress(vgl->gl, "glShaderSource");
- vgl->CompileShader = (PFNGLCOMPILESHADERPROC)vlc_gl_GetProcAddress(vgl->gl, "glCompileShader");
- vgl->AttachShader = (PFNGLATTACHSHADERPROC)vlc_gl_GetProcAddress(vgl->gl, "glAttachShader");
-
- vgl->GetProgramiv = (PFNGLGETPROGRAMIVPROC)vlc_gl_GetProcAddress(vgl->gl, "glGetProgramiv");
- vgl->GetShaderiv = (PFNGLGETSHADERIVPROC)vlc_gl_GetProcAddress(vgl->gl, "glGetShaderiv");
- vgl->GetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)vlc_gl_GetProcAddress(vgl->gl, "glGetProgramInfoLog");
- vgl->GetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)vlc_gl_GetProcAddress(vgl->gl, "glGetShaderInfoLog");
-
- vgl->DeleteShader = (PFNGLDELETESHADERPROC)vlc_gl_GetProcAddress(vgl->gl, "glDeleteShader");
-
- vgl->GetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)vlc_gl_GetProcAddress(vgl->gl, "glGetUniformLocation");
- vgl->GetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC)vlc_gl_GetProcAddress(vgl->gl, "glGetAttribLocation");
- vgl->VertexAttribPointer= (PFNGLVERTEXATTRIBPOINTERPROC)vlc_gl_GetProcAddress(vgl->gl, "glVertexAttribPointer");
- vgl->EnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)vlc_gl_GetProcAddress(vgl->gl, "glEnableVertexAttribArray");
- vgl->UniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC)vlc_gl_GetProcAddress(vgl->gl,"glUniformMatrix4fv");
- vgl->Uniform4fv = (PFNGLUNIFORM4FVPROC)vlc_gl_GetProcAddress(vgl->gl,"glUniform4fv");
- vgl->Uniform4f = (PFNGLUNIFORM4FPROC)vlc_gl_GetProcAddress(vgl->gl,"glUniform4f");
- vgl->Uniform1i = (PFNGLUNIFORM1IPROC)vlc_gl_GetProcAddress(vgl->gl,"glUniform1i");
-
- vgl->CreateProgram = (PFNGLCREATEPROGRAMPROC)vlc_gl_GetProcAddress(vgl->gl, "glCreateProgram");
- vgl->LinkProgram = (PFNGLLINKPROGRAMPROC)vlc_gl_GetProcAddress(vgl->gl, "glLinkProgram");
- vgl->UseProgram = (PFNGLUSEPROGRAMPROC)vlc_gl_GetProcAddress(vgl->gl, "glUseProgram");
- vgl->DeleteProgram = (PFNGLDELETEPROGRAMPROC)vlc_gl_GetProcAddress(vgl->gl, "glDeleteProgram");
-
- vgl->GenBuffers = (PFNGLGENBUFFERSPROC)vlc_gl_GetProcAddress(vgl->gl, "glGenBuffers");
- vgl->BindBuffer = (PFNGLBINDBUFFERPROC)vlc_gl_GetProcAddress(vgl->gl, "glBindBuffer");
- vgl->BufferData = (PFNGLBUFFERDATAPROC)vlc_gl_GetProcAddress(vgl->gl, "glBufferData");
- vgl->DeleteBuffers = (PFNGLDELETEBUFFERSPROC)vlc_gl_GetProcAddress(vgl->gl, "glDeleteBuffers");
-
- if (!vgl->CreateShader || !vgl->ShaderSource || !vgl->CreateProgram)
+ api->CreateShader = (PFNGLCREATESHADERPROC)vlc_gl_GetProcAddress(vgl->gl, "glCreateShader");
+ api->ShaderSource = (PFNGLSHADERSOURCEPROC)vlc_gl_GetProcAddress(vgl->gl, "glShaderSource");
+ api->CompileShader = (PFNGLCOMPILESHADERPROC)vlc_gl_GetProcAddress(vgl->gl, "glCompileShader");
+ api->AttachShader = (PFNGLATTACHSHADERPROC)vlc_gl_GetProcAddress(vgl->gl, "glAttachShader");
+
+ api->GetProgramiv = (PFNGLGETPROGRAMIVPROC)vlc_gl_GetProcAddress(vgl->gl, "glGetProgramiv");
+ api->GetShaderiv = (PFNGLGETSHADERIVPROC)vlc_gl_GetProcAddress(vgl->gl, "glGetShaderiv");
+ api->GetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)vlc_gl_GetProcAddress(vgl->gl, "glGetProgramInfoLog");
+ api->GetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)vlc_gl_GetProcAddress(vgl->gl, "glGetShaderInfoLog");
+
+ api->DeleteShader = (PFNGLDELETESHADERPROC)vlc_gl_GetProcAddress(vgl->gl, "glDeleteShader");
+
+ api->GetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)vlc_gl_GetProcAddress(vgl->gl, "glGetUniformLocation");
+ api->GetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC)vlc_gl_GetProcAddress(vgl->gl, "glGetAttribLocation");
+ api->VertexAttribPointer= (PFNGLVERTEXATTRIBPOINTERPROC)vlc_gl_GetProcAddress(vgl->gl, "glVertexAttribPointer");
+ api->EnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)vlc_gl_GetProcAddress(vgl->gl, "glEnableVertexAttribArray");
+ api->UniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC)vlc_gl_GetProcAddress(vgl->gl,"glUniformMatrix4fv");
+ api->Uniform4fv = (PFNGLUNIFORM4FVPROC)vlc_gl_GetProcAddress(vgl->gl,"glUniform4fv");
+ api->Uniform4f = (PFNGLUNIFORM4FPROC)vlc_gl_GetProcAddress(vgl->gl,"glUniform4f");
+ api->Uniform1i = (PFNGLUNIFORM1IPROC)vlc_gl_GetProcAddress(vgl->gl,"glUniform1i");
+
+ api->CreateProgram = (PFNGLCREATEPROGRAMPROC)vlc_gl_GetProcAddress(vgl->gl, "glCreateProgram");
+ api->LinkProgram = (PFNGLLINKPROGRAMPROC)vlc_gl_GetProcAddress(vgl->gl, "glLinkProgram");
+ api->UseProgram = (PFNGLUSEPROGRAMPROC)vlc_gl_GetProcAddress(vgl->gl, "glUseProgram");
+ api->DeleteProgram = (PFNGLDELETEPROGRAMPROC)vlc_gl_GetProcAddress(vgl->gl, "glDeleteProgram");
+
+ api->GenBuffers = (PFNGLGENBUFFERSPROC)vlc_gl_GetProcAddress(vgl->gl, "glGenBuffers");
+ api->BindBuffer = (PFNGLBINDBUFFERPROC)vlc_gl_GetProcAddress(vgl->gl, "glBindBuffer");
+ api->BufferData = (PFNGLBUFFERDATAPROC)vlc_gl_GetProcAddress(vgl->gl, "glBufferData");
+ api->DeleteBuffers = (PFNGLDELETEBUFFERSPROC)vlc_gl_GetProcAddress(vgl->gl, "glDeleteBuffers");
+
+ if (!api->CreateShader || !api->ShaderSource || !api->CreateProgram)
supports_shaders = false;
#endif
if (!supports_shaders)
@@ -658,7 +578,7 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
/* Check shaders messages */
for (unsigned j = 0; j < nb_shaders; j++) {
int infoLength;
- vgl->GetShaderiv(vgl->shader[j], GL_INFO_LOG_LENGTH, &infoLength);
+ vgl->api.GetShaderiv(vgl->shader[j], GL_INFO_LOG_LENGTH, &infoLength);
if (infoLength <= 1)
continue;
@@ -666,8 +586,8 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
if (infolog != NULL)
{
int charsWritten;
- vgl->GetShaderInfoLog(vgl->shader[j], infoLength, &charsWritten,
- infolog);
+ vgl->api.GetShaderInfoLog(vgl->shader[j], infoLength, &charsWritten,
+ infolog);
msg_Err(gl, "shader %d: %s", j, infolog);
free(infolog);
}
@@ -683,18 +603,18 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
{
program_idx = nb_programs++;
- program = vgl->program[program_idx] = vgl->CreateProgram();
- vgl->AttachShader(program, vgl->shader[fragment_shader_idx]);
- vgl->AttachShader(program, vgl->shader[vertex_shader_idx]);
- vgl->LinkProgram(program);
+ program = vgl->program[program_idx] = vgl->api.CreateProgram();
+ vgl->api.AttachShader(program, vgl->shader[fragment_shader_idx]);
+ vgl->api.AttachShader(program, vgl->shader[vertex_shader_idx]);
+ vgl->api.LinkProgram(program);
}
/* RGB & Vertex shaders */
rgba_program_idx = nb_programs++;
- program = vgl->program[rgba_program_idx] = vgl->CreateProgram();
- vgl->AttachShader(program, vgl->shader[rgba_fragment_shader_idx]);
- vgl->AttachShader(program, vgl->shader[vertex_shader_idx]);
- vgl->LinkProgram(program);
+ program = vgl->program[rgba_program_idx] = vgl->api.CreateProgram();
+ vgl->api.AttachShader(program, vgl->shader[rgba_fragment_shader_idx]);
+ vgl->api.AttachShader(program, vgl->shader[vertex_shader_idx]);
+ vgl->api.LinkProgram(program);
vgl->program_idx = program_idx != -1 ? program_idx : rgba_program_idx;
vgl->program_sub_idx = rgba_program_idx;
@@ -702,22 +622,22 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
/* Check program messages */
for (GLuint i = 0; i < nb_programs; i++) {
int infoLength = 0;
- vgl->GetProgramiv(vgl->program[i], GL_INFO_LOG_LENGTH, &infoLength);
+ vgl->api.GetProgramiv(vgl->program[i], GL_INFO_LOG_LENGTH, &infoLength);
if (infoLength <= 1)
continue;
char *infolog = malloc(infoLength);
if (infolog != NULL)
{
int charsWritten;
- vgl->GetProgramInfoLog(vgl->program[i], infoLength, &charsWritten,
- infolog);
+ vgl->api.GetProgramInfoLog(vgl->program[i], infoLength, &charsWritten,
+ infolog);
msg_Err(gl, "shader program %d: %s", i, infolog);
free(infolog);
}
/* If there is some message, better to check linking is ok */
GLint link_status = GL_TRUE;
- vgl->GetProgramiv(vgl->program[i], GL_LINK_STATUS, &link_status);
+ vgl->api.GetProgramiv(vgl->program[i], GL_LINK_STATUS, &link_status);
if (link_status == GL_FALSE) {
msg_Err(gl, "Unable to use program %d\n", i);
vlc_gl_Unlock(vgl->gl);
@@ -753,9 +673,9 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
- vgl->GenBuffers(1, &vgl->vertex_buffer_object);
- vgl->GenBuffers(1, &vgl->index_buffer_object);
- vgl->GenBuffers(vgl->chroma->plane_count, vgl->texture_buffer_object);
+ vgl->api.GenBuffers(1, &vgl->vertex_buffer_object);
+ vgl->api.GenBuffers(1, &vgl->index_buffer_object);
+ vgl->api.GenBuffers(vgl->chroma->plane_count, vgl->texture_buffer_object);
/* Initial number of allocated buffer objects for subpictures, will grow dynamically. */
int subpicture_buffer_object_count = 8;
@@ -766,7 +686,7 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
return NULL;
}
vgl->subpicture_buffer_object_count = subpicture_buffer_object_count;
- vgl->GenBuffers(vgl->subpicture_buffer_object_count, vgl->subpicture_buffer_object);
+ vgl->api.GenBuffers(vgl->subpicture_buffer_object_count, vgl->subpicture_buffer_object);
vlc_gl_Unlock(vgl->gl);
@@ -808,14 +728,14 @@ void vout_display_opengl_Delete(vout_display_opengl_t *vgl)
free(vgl->region);
for (int i = 0; i < 2 && vgl->program[i] != 0; i++)
- vgl->DeleteProgram(vgl->program[i]);
+ vgl->api.DeleteProgram(vgl->program[i]);
for (int i = 0; i < 3 && vgl->shader[i] != 0; i++)
- vgl->DeleteShader(vgl->shader[i]);
- vgl->DeleteBuffers(1, &vgl->vertex_buffer_object);
- vgl->DeleteBuffers(1, &vgl->index_buffer_object);
- vgl->DeleteBuffers(vgl->chroma->plane_count, vgl->texture_buffer_object);
+ vgl->api.DeleteShader(vgl->shader[i]);
+ vgl->api.DeleteBuffers(1, &vgl->vertex_buffer_object);
+ vgl->api.DeleteBuffers(1, &vgl->index_buffer_object);
+ vgl->api.DeleteBuffers(vgl->chroma->plane_count, vgl->texture_buffer_object);
if (vgl->subpicture_buffer_object_count > 0)
- vgl->DeleteBuffers(vgl->subpicture_buffer_object_count, vgl->subpicture_buffer_object);
+ vgl->api.DeleteBuffers(vgl->subpicture_buffer_object_count, vgl->subpicture_buffer_object);
free(vgl->subpicture_buffer_object);
free(vgl->texture_temp_buf);
@@ -1559,22 +1479,22 @@ static void DrawWithShaders(vout_display_opengl_t *vgl,
unsigned int program_idx)
{
GLuint program = vgl->program[program_idx];
- vgl->UseProgram(program);
+ vgl->api.UseProgram(program);
if (vlc_fourcc_IsYUV(vgl->fmt.i_chroma)
|| vgl->fmt.i_chroma == VLC_CODEC_XYZ12) { /* FIXME: ugly */
if (vgl->chroma->plane_count == 3) {
- vgl->Uniform4fv(vgl->GetUniformLocation(program,
+ vgl->api.Uniform4fv(vgl->api.GetUniformLocation(program,
"Coefficient"), 4, vgl->local_value);
- vgl->Uniform1i(vgl->GetUniformLocation(program, "Texture0"), 0);
- vgl->Uniform1i(vgl->GetUniformLocation(program, "Texture1"), 1);
- vgl->Uniform1i(vgl->GetUniformLocation(program, "Texture2"), 2);
+ vgl->api.Uniform1i(vgl->api.GetUniformLocation(program, "Texture0"), 0);
+ vgl->api.Uniform1i(vgl->api.GetUniformLocation(program, "Texture1"), 1);
+ vgl->api.Uniform1i(vgl->api.GetUniformLocation(program, "Texture2"), 2);
}
else if (vgl->chroma->plane_count == 1) {
- vgl->Uniform1i(vgl->GetUniformLocation(program, "Texture0"), 0);
+ vgl->api.Uniform1i(vgl->api.GetUniformLocation(program, "Texture0"), 0);
}
} else {
- vgl->Uniform1i(vgl->GetUniformLocation(program, "Texture0"), 0);
- vgl->Uniform4f(vgl->GetUniformLocation(program, "FillColor"),
+ vgl->api.Uniform1i(vgl->api.GetUniformLocation(program, "Texture0"), 0);
+ vgl->api.Uniform4f(vgl->api.GetUniformLocation(program, "FillColor"),
1.0f, 1.0f, 1.0f, 1.0f);
}
@@ -1643,45 +1563,45 @@ static void DrawWithShaders(vout_display_opengl_t *vgl,
glClientActiveTexture(GL_TEXTURE0+j);
glBindTexture(vgl->tex_target, vgl->texture[0][j]);
- vgl->BindBuffer(GL_ARRAY_BUFFER, vgl->texture_buffer_object[j]);
- vgl->BufferData(GL_ARRAY_BUFFER, nbVertices * 2 * sizeof(GLfloat),
+ vgl->api.BindBuffer(GL_ARRAY_BUFFER, vgl->texture_buffer_object[j]);
+ vgl->api.BufferData(GL_ARRAY_BUFFER, nbVertices * 2 * sizeof(GLfloat),
textureCoord + j * nbVertices * 2, GL_STATIC_DRAW);
char attribute[20];
snprintf(attribute, sizeof(attribute), "MultiTexCoord%1d", j);
- vgl->EnableVertexAttribArray(vgl->GetAttribLocation(program, attribute));
- vgl->VertexAttribPointer(vgl->GetAttribLocation(program, attribute), 2,
+ vgl->api.EnableVertexAttribArray(vgl->api.GetAttribLocation(program, attribute));
+ vgl->api.VertexAttribPointer(vgl->api.GetAttribLocation(program, attribute), 2,
GL_FLOAT, 0, 0, 0);
}
free(textureCoord);
glActiveTexture(GL_TEXTURE0 + 0);
glClientActiveTexture(GL_TEXTURE0 + 0);
- vgl->BindBuffer(GL_ARRAY_BUFFER, vgl->vertex_buffer_object);
- vgl->BufferData(GL_ARRAY_BUFFER, nbVertices * 3 * sizeof(GLfloat), vertexCoord, GL_STATIC_DRAW);
+ vgl->api.BindBuffer(GL_ARRAY_BUFFER, vgl->vertex_buffer_object);
+ vgl->api.BufferData(GL_ARRAY_BUFFER, nbVertices * 3 * sizeof(GLfloat), vertexCoord, GL_STATIC_DRAW);
free(vertexCoord);
- vgl->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, vgl->index_buffer_object);
- vgl->BufferData(GL_ELEMENT_ARRAY_BUFFER, nbIndices * sizeof(GLushort), indices, GL_STATIC_DRAW);
+ vgl->api.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, vgl->index_buffer_object);
+ vgl->api.BufferData(GL_ELEMENT_ARRAY_BUFFER, nbIndices * sizeof(GLushort), indices, GL_STATIC_DRAW);
free(indices);
- vgl->EnableVertexAttribArray(vgl->GetAttribLocation(program,
+ vgl->api.EnableVertexAttribArray(vgl->api.GetAttribLocation(program,
"VertexPosition"));
- vgl->VertexAttribPointer(vgl->GetAttribLocation(program, "VertexPosition"),
+ vgl->api.VertexAttribPointer(vgl->api.GetAttribLocation(program, "VertexPosition"),
3, GL_FLOAT, 0, 0, 0);
- vgl->UniformMatrix4fv(vgl->GetUniformLocation(program, "OrientationMatrix"),
+ vgl->api.UniformMatrix4fv(vgl->api.GetUniformLocation(program, "OrientationMatrix"),
1, GL_FALSE, orientationMatrix);
- vgl->UniformMatrix4fv(vgl->GetUniformLocation(program, "ProjectionMatrix"),
+ vgl->api.UniformMatrix4fv(vgl->api.GetUniformLocation(program, "ProjectionMatrix"),
1, GL_FALSE, projectionMatrix);
- vgl->UniformMatrix4fv(vgl->GetUniformLocation(program, "ZRotMatrix"),
+ vgl->api.UniformMatrix4fv(vgl->api.GetUniformLocation(program, "ZRotMatrix"),
1, GL_FALSE, zRotMatrix);
- vgl->UniformMatrix4fv(vgl->GetUniformLocation(program, "YRotMatrix"),
+ vgl->api.UniformMatrix4fv(vgl->api.GetUniformLocation(program, "YRotMatrix"),
1, GL_FALSE, yRotMatrix);
- vgl->UniformMatrix4fv(vgl->GetUniformLocation(program, "XRotMatrix"),
+ vgl->api.UniformMatrix4fv(vgl->api.GetUniformLocation(program, "XRotMatrix"),
1, GL_FALSE, xRotMatrix);
- vgl->UniformMatrix4fv(vgl->GetUniformLocation(program, "ZoomMatrix"),
+ vgl->api.UniformMatrix4fv(vgl->api.GetUniformLocation(program, "ZoomMatrix"),
1, GL_FALSE, zoomMatrix);
- vgl->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, vgl->index_buffer_object);
+ vgl->api.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, vgl->index_buffer_object);
glDrawElements(GL_TRIANGLES, nbIndices, GL_UNSIGNED_SHORT, 0);
}
@@ -1730,8 +1650,8 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl,
/* Draw the subpictures */
// Change the program for overlays
GLuint sub_program = vgl->program[vgl->program_sub_idx];
- vgl->UseProgram(sub_program);
- vgl->Uniform1i(vgl->GetUniformLocation(sub_program, "Texture"), 0);
+ vgl->api.UseProgram(sub_program);
+ vgl->api.Uniform1i(vgl->api.GetUniformLocation(sub_program, "Texture"), 0);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -1739,7 +1659,8 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl,
/* We need two buffer objects for each region: for vertex and texture coordinates. */
if (2 * vgl->region_count > vgl->subpicture_buffer_object_count) {
if (vgl->subpicture_buffer_object_count > 0)
- vgl->DeleteBuffers(vgl->subpicture_buffer_object_count, vgl->subpicture_buffer_object);
+ vgl->api.DeleteBuffers(vgl->subpicture_buffer_object_count,
+ vgl->subpicture_buffer_object);
vgl->subpicture_buffer_object_count = 0;
int new_count = 2 * vgl->region_count;
@@ -1750,7 +1671,8 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl,
}
vgl->subpicture_buffer_object_count = new_count;
- vgl->GenBuffers(vgl->subpicture_buffer_object_count, vgl->subpicture_buffer_object);
+ vgl->api.GenBuffers(vgl->subpicture_buffer_object_count,
+ vgl->subpicture_buffer_object);
}
glActiveTexture(GL_TEXTURE0 + 0);
@@ -1771,36 +1693,36 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl,
};
glBindTexture(GL_TEXTURE_2D, glr->texture);
- vgl->Uniform4f(vgl->GetUniformLocation(sub_program, "FillColor"),
- 1.0f, 1.0f, 1.0f, glr->alpha);
-
- vgl->BindBuffer(GL_ARRAY_BUFFER, vgl->subpicture_buffer_object[2 * i]);
- vgl->BufferData(GL_ARRAY_BUFFER, sizeof(textureCoord), textureCoord, GL_STATIC_DRAW);
- vgl->EnableVertexAttribArray(vgl->GetAttribLocation(sub_program,
- "MultiTexCoord0"));
- vgl->VertexAttribPointer(vgl->GetAttribLocation(sub_program,
- "MultiTexCoord0"), 2, GL_FLOAT, 0, 0, 0);
-
- vgl->BindBuffer(GL_ARRAY_BUFFER, vgl->subpicture_buffer_object[2 * i + 1]);
- vgl->BufferData(GL_ARRAY_BUFFER, sizeof(vertexCoord), vertexCoord, GL_STATIC_DRAW);
- vgl->EnableVertexAttribArray(vgl->GetAttribLocation(sub_program,
- "VertexPosition"));
- vgl->VertexAttribPointer(vgl->GetAttribLocation(sub_program,
- "VertexPosition"), 2, GL_FLOAT, 0, 0, 0);
+ vgl->api.Uniform4f(vgl->api.GetUniformLocation(sub_program, "FillColor"),
+ 1.0f, 1.0f, 1.0f, glr->alpha);
+
+ vgl->api.BindBuffer(GL_ARRAY_BUFFER, vgl->subpicture_buffer_object[2 * i]);
+ vgl->api.BufferData(GL_ARRAY_BUFFER, sizeof(textureCoord), textureCoord, GL_STATIC_DRAW);
+ vgl->api.EnableVertexAttribArray(vgl->api.GetAttribLocation(sub_program,
+ "MultiTexCoord0"));
+ vgl->api.VertexAttribPointer(vgl->api.GetAttribLocation(sub_program,
+ "MultiTexCoord0"), 2, GL_FLOAT, 0, 0, 0);
+
+ vgl->api.BindBuffer(GL_ARRAY_BUFFER, vgl->subpicture_buffer_object[2 * i + 1]);
+ vgl->api.BufferData(GL_ARRAY_BUFFER, sizeof(vertexCoord), vertexCoord, GL_STATIC_DRAW);
+ vgl->api.EnableVertexAttribArray(vgl->api.GetAttribLocation(sub_program,
+ "VertexPosition"));
+ vgl->api.VertexAttribPointer(vgl->api.GetAttribLocation(sub_program,
+ "VertexPosition"), 2, GL_FLOAT, 0, 0, 0);
// Subpictures have the correct orientation:
- vgl->UniformMatrix4fv(vgl->GetUniformLocation(sub_program,
- "OrientationMatrix"), 1, GL_FALSE, identity);
- vgl->UniformMatrix4fv(vgl->GetUniformLocation(sub_program,
- "ProjectionMatrix"), 1, GL_FALSE, identity);
- vgl->UniformMatrix4fv(vgl->GetUniformLocation(sub_program,
- "ZRotMatrix"), 1, GL_FALSE, identity);
- vgl->UniformMatrix4fv(vgl->GetUniformLocation(sub_program,
- "YRotMatrix"), 1, GL_FALSE, identity);
- vgl->UniformMatrix4fv(vgl->GetUniformLocation(sub_program,
- "XRotMatrix"), 1, GL_FALSE, identity);
- vgl->UniformMatrix4fv(vgl->GetUniformLocation(sub_program,
- "ZoomMatrix"), 1, GL_FALSE, identity);
+ vgl->api.UniformMatrix4fv(vgl->api.GetUniformLocation(sub_program,
+ "OrientationMatrix"), 1, GL_FALSE, identity);
+ vgl->api.UniformMatrix4fv(vgl->api.GetUniformLocation(sub_program,
+ "ProjectionMatrix"), 1, GL_FALSE, identity);
+ vgl->api.UniformMatrix4fv(vgl->api.GetUniformLocation(sub_program,
+ "ZRotMatrix"), 1, GL_FALSE, identity);
+ vgl->api.UniformMatrix4fv(vgl->api.GetUniformLocation(sub_program,
+ "YRotMatrix"), 1, GL_FALSE, identity);
+ vgl->api.UniformMatrix4fv(vgl->api.GetUniformLocation(sub_program,
+ "XRotMatrix"), 1, GL_FALSE, identity);
+ vgl->api.UniformMatrix4fv(vgl->api.GetUniformLocation(sub_program,
+ "ZoomMatrix"), 1, GL_FALSE, identity);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
--
2.10.2
More information about the vlc-devel
mailing list