vlc | branch: master | Thomas Guillem <[email protected]> | Fri Aug 25 14:11:41 2017 +0200| [63528163650a8b3340d9a3566748f558ed35ddcf] | committer: Thomas Guillem
gl: use vtable in converters This removes OpenGL / OpenGLES link dependency in converters. Refs #18575 > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=63528163650a8b3340d9a3566748f558ed35ddcf --- modules/video_output/opengl/converter_android.c | 4 +- modules/video_output/opengl/converter_cvpx.c | 16 ++--- modules/video_output/opengl/converter_vaapi.c | 2 +- modules/video_output/opengl/converters.c | 78 ++++++++++++------------- modules/video_output/opengl/internal.h | 46 ++++++++++++--- modules/video_output/opengl/vout_helper.c | 31 ++++++---- 6 files changed, 108 insertions(+), 69 deletions(-) diff --git a/modules/video_output/opengl/converter_android.c b/modules/video_output/opengl/converter_android.c index 7132d818a0..f4ab51886f 100644 --- a/modules/video_output/opengl/converter_android.c +++ b/modules/video_output/opengl/converter_android.c @@ -154,8 +154,8 @@ tc_anop_update(const opengl_tex_converter_t *tc, GLuint *textures, return VLC_EGENERIC; } - glActiveTexture(GL_TEXTURE0); - glBindTexture(tc->tex_target, textures[0]); + tc->vt->ActiveTexture(GL_TEXTURE0); + tc->vt->BindTexture(tc->tex_target, textures[0]); return VLC_SUCCESS; } diff --git a/modules/video_output/opengl/converter_cvpx.c b/modules/video_output/opengl/converter_cvpx.c index fdcb5cbbb4..7c2472ac13 100644 --- a/modules/video_output/opengl/converter_cvpx.c +++ b/modules/video_output/opengl/converter_cvpx.c @@ -63,7 +63,7 @@ tc_cvpx_update(const opengl_tex_converter_t *tc, GLuint *textures, for (unsigned i = 0; i < tc->tex_count; ++i) { - glActiveTexture(GL_TEXTURE0 + i); + tc->vt->ActiveTexture(GL_TEXTURE0 + i); CVOpenGLESTextureRef texture; CVReturn err = CVOpenGLESTextureCacheCreateTextureFromImage( @@ -79,11 +79,11 @@ tc_cvpx_update(const opengl_tex_converter_t *tc, GLuint *textures, } textures[i] = CVOpenGLESTextureGetName(texture); - glBindTexture(tc->tex_target, textures[i]); - glTexParameteri(tc->tex_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(tc->tex_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(tc->tex_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(tc->tex_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + tc->vt->BindTexture(tc->tex_target, textures[i]); + tc->vt->TexParameteri(tc->tex_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + tc->vt->TexParameteri(tc->tex_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + tc->vt->TexParameterf(tc->tex_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + tc->vt->TexParameterf(tc->tex_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); CFRelease(texture); } @@ -113,8 +113,8 @@ tc_cvpx_update(const opengl_tex_converter_t *tc, GLuint *textures, for (unsigned i = 0; i < tc->tex_count; ++i) { - glActiveTexture(GL_TEXTURE0 + i); - glBindTexture(tc->tex_target, textures[i]); + tc->vt->ActiveTexture(GL_TEXTURE0 + i); + tc->vt->BindTexture(tc->tex_target, textures[i]); CGLError err = CGLTexImageIOSurface2D(glsys->locked_ctx, tc->tex_target, diff --git a/modules/video_output/opengl/converter_vaapi.c b/modules/video_output/opengl/converter_vaapi.c index 9044398432..463aec0345 100644 --- a/modules/video_output/opengl/converter_vaapi.c +++ b/modules/video_output/opengl/converter_vaapi.c @@ -190,7 +190,7 @@ tc_vaegl_update(const opengl_tex_converter_t *tc, GLuint *textures, if (egl_images[i] == NULL) goto error; - glBindTexture(tc->tex_target, textures[i]); + tc->vt->BindTexture(tc->tex_target, textures[i]); priv->glEGLImageTargetTexture2DOES(tc->tex_target, egl_images[i]); } diff --git a/modules/video_output/opengl/converters.c b/modules/video_output/opengl/converters.c index 096dd09154..20bc9a5cac 100644 --- a/modules/video_output/opengl/converters.c +++ b/modules/video_output/opengl/converters.c @@ -81,8 +81,8 @@ struct priv }; #if !defined(USE_OPENGL_ES2) -static int GetTexFormatSize(int target, int tex_format, int tex_internal, - int tex_type) +static int GetTexFormatSize(opengl_tex_converter_t *tc, int target, + int tex_format, int tex_internal, int tex_type) { GLint tex_param_size; switch (tex_format) @@ -98,13 +98,13 @@ static int GetTexFormatSize(int target, int tex_format, int tex_internal, } GLuint texture; - glGenTextures(1, &texture); - glBindTexture(target, texture); - glTexImage2D(target, 0, tex_internal, 64, 64, 0, tex_format, tex_type, NULL); + tc->vt->GenTextures(1, &texture); + tc->vt->BindTexture(target, texture); + tc->vt->TexImage2D(target, 0, tex_internal, 64, 64, 0, tex_format, tex_type, NULL); GLint size = 0; - glGetTexLevelParameteriv(target, 0, tex_param_size, &size); + tc->vt->GetTexLevelParameteriv(target, 0, tex_param_size, &size); - glDeleteTextures(1, &texture); + tc->vt->DeleteTextures(1, &texture); return size; } #endif @@ -150,8 +150,8 @@ tc_yuv_base_init(opengl_tex_converter_t *tc, GLenum tex_target, else if (desc->pixel_size == 2) { if (oneplane16_texfmt == 0 - || GetTexFormatSize(tex_target, oneplane_texfmt, oneplane16_texfmt, - GL_UNSIGNED_SHORT) != 16) + || GetTexFormatSize(tc, tex_target, oneplane_texfmt, + oneplane16_texfmt, GL_UNSIGNED_SHORT) != 16) return VLC_EGENERIC; internal = oneplane16_texfmt; @@ -561,7 +561,7 @@ pbo_data_alloc(const opengl_tex_converter_t *tc, picture_t *pic) { picture_sys_t *picsys = pic->p_sys; - glGetError(); + tc->vt->GetError(); tc->vt->GenBuffers(pic->i_planes, picsys->buffers); for (int i = 0; i < pic->i_planes; ++i) @@ -570,7 +570,7 @@ pbo_data_alloc(const opengl_tex_converter_t *tc, picture_t *pic) tc->vt->BufferData(GL_PIXEL_UNPACK_BUFFER, picsys->bytes[i], NULL, GL_DYNAMIC_DRAW); - if (glGetError() != GL_NO_ERROR) + if (tc->vt->GetError() != GL_NO_ERROR) { msg_Err(tc->gl, "could not alloc PBO buffers"); tc->vt->DeleteBuffers(i, picsys->buffers); @@ -636,14 +636,14 @@ tc_pbo_update(const opengl_tex_converter_t *tc, GLuint *textures, display_pic->p_sys->buffers[i]); tc->vt->BufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, size, data); - glActiveTexture(GL_TEXTURE0 + i); - glBindTexture(tc->tex_target, textures[i]); + tc->vt->ActiveTexture(GL_TEXTURE0 + i); + tc->vt->BindTexture(tc->tex_target, textures[i]); - glPixelStorei(GL_UNPACK_ROW_LENGTH, - pic->p[i].i_pitch / pic->p[i].i_pixel_pitch); + tc->vt->PixelStorei(GL_UNPACK_ROW_LENGTH, + pic->p[i].i_pitch / pic->p[i].i_pixel_pitch); - glTexSubImage2D(tc->tex_target, 0, 0, 0, tex_width[i], tex_height[i], - tc->texs[i].format, tc->texs[i].type, NULL); + tc->vt->TexSubImage2D(tc->tex_target, 0, 0, 0, tex_width[i], tex_height[i], + tc->texs[i].format, tc->texs[i].type, NULL); } /* turn off pbo */ @@ -751,14 +751,14 @@ tc_persistent_update(const opengl_tex_converter_t *tc, GLuint *textures, if (picsys->fence == NULL) tc->vt->FlushMappedBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, picsys->bytes[i]); - glActiveTexture(GL_TEXTURE0 + i); - glBindTexture(tc->tex_target, textures[i]); + tc->vt->ActiveTexture(GL_TEXTURE0 + i); + tc->vt->BindTexture(tc->tex_target, textures[i]); - glPixelStorei(GL_UNPACK_ROW_LENGTH, - pic->p[i].i_pitch / pic->p[i].i_pixel_pitch); + tc->vt->PixelStorei(GL_UNPACK_ROW_LENGTH, + pic->p[i].i_pitch / pic->p[i].i_pixel_pitch); - glTexSubImage2D(tc->tex_target, 0, 0, 0, tex_width[i], tex_height[i], - tc->texs[i].format, tc->texs[i].type, NULL); + tc->vt->TexSubImage2D(tc->tex_target, 0, 0, 0, tex_width[i], tex_height[i], + tc->texs[i].format, tc->texs[i].type, NULL); } bool hold; @@ -880,10 +880,10 @@ tc_common_allocate_textures(const opengl_tex_converter_t *tc, GLuint *textures, { for (unsigned i = 0; i < tc->tex_count; i++) { - glBindTexture(tc->tex_target, textures[i]); - glTexImage2D(tc->tex_target, 0, tc->texs[i].internal, - tex_width[i], tex_height[i], 0, tc->texs[i].format, - tc->texs[i].type, NULL); + tc->vt->BindTexture(tc->tex_target, textures[i]); + tc->vt->TexImage2D(tc->tex_target, 0, tc->texs[i].internal, + tex_width[i], tex_height[i], 0, tc->texs[i].format, + tc->texs[i].type, NULL); } return VLC_SUCCESS; } @@ -898,7 +898,7 @@ upload_plane(const opengl_tex_converter_t *tc, unsigned tex_idx, GLenum tex_type = tc->texs[tex_idx].type; /* This unpack alignment is the default, but setting it just in case. */ - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + tc->vt->PixelStorei(GL_UNPACK_ALIGNMENT, 4); if (!priv->has_unpack_subimage) { @@ -929,21 +929,21 @@ upload_plane(const opengl_tex_converter_t *tc, unsigned tex_idx, source += pitch; destination += dst_pitch; } - glTexSubImage2D(tc->tex_target, 0, 0, 0, width, height, - tex_format, tex_type, priv->texture_temp_buf); + tc->vt->TexSubImage2D(tc->tex_target, 0, 0, 0, width, height, + tex_format, tex_type, priv->texture_temp_buf); } else { - glTexSubImage2D(tc->tex_target, 0, 0, 0, width, height, - tex_format, tex_type, pixels); + tc->vt->TexSubImage2D(tc->tex_target, 0, 0, 0, width, height, + tex_format, tex_type, pixels); } #undef ALIGN } else { - glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / pixel_pitch); - glTexSubImage2D(tc->tex_target, 0, 0, 0, width, height, - tex_format, tex_type, pixels); + tc->vt->PixelStorei(GL_UNPACK_ROW_LENGTH, pitch / pixel_pitch); + tc->vt->TexSubImage2D(tc->tex_target, 0, 0, 0, width, height, + tex_format, tex_type, pixels); } return VLC_SUCCESS; } @@ -958,8 +958,8 @@ tc_common_update(const opengl_tex_converter_t *tc, GLuint *textures, for (unsigned i = 0; i < tc->tex_count && ret == VLC_SUCCESS; i++) { assert(textures[i] != 0); - glActiveTexture(GL_TEXTURE0 + i); - glBindTexture(tc->tex_target, textures[i]); + tc->vt->ActiveTexture(GL_TEXTURE0 + i); + tc->vt->BindTexture(tc->tex_target, textures[i]); const void *pixels = plane_offset != NULL ? &pic->p[i].p_pixels[plane_offset[i]] : pic->p[i].p_pixels; @@ -1066,7 +1066,7 @@ generic_init(opengl_tex_converter_t *tc, bool allow_dr) if (vlc_fourcc_IsYUV(tc->fmt.i_chroma)) { GLint max_texture_units = 0; - glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_units); + tc->vt->GetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_units); if (max_texture_units < 3) return VLC_EGENERIC; @@ -1136,7 +1136,7 @@ generic_init(opengl_tex_converter_t *tc, bool allow_dr) /* Ensure we do direct rendering with OpenGL 3.0 or higher. Indeed, * persistent mapped buffers seems to be slow with OpenGL 2.1 drivers * and bellow. This may be caused by OpenGL compatibility layer. */ - const unsigned char *ogl_version = glGetString(GL_VERSION); + const unsigned char *ogl_version = tc->vt->GetString(GL_VERSION); const bool glver_ok = strverscmp((const char *)ogl_version, "3.0") >= 0; supports_map_persistent = glver_ok && has_pbo && has_bs && tc->vt->BufferStorage diff --git a/modules/video_output/opengl/internal.h b/modules/video_output/opengl/internal.h index 764539fb72..53712c8532 100644 --- a/modules/video_output/opengl/internal.h +++ b/modules/video_output/opengl/internal.h @@ -43,6 +43,25 @@ # endif #endif +/* Core OpenGL/OpenGLES functions: the following functions pointers typedefs + * are not defined. */ +#if !defined(_WIN32) /* Already defined on Win32 */ +typedef void (*PFNGLACTIVETEXTUREPROC) (GLenum texture); +#endif +typedef GLenum (*PFNGLGETERRORPROC) (void); +typedef const GLubyte *(*PFNGLGETSTRINGPROC) (GLenum name); +typedef void (*PFNGLGETINTEGERVPROC) (GLenum pname, GLint *data); +typedef void (*PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture); +typedef void (*PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param); +typedef void (*PFNGLTEXPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat param); +typedef void (*PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures); +typedef void (*PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures); +typedef void (*PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels); +typedef void (*PFNGLTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); +typedef void (*PFNGLGETTEXLEVELPARAMETERIVPROC) (GLenum target, GLint level, GLenum pname, GLint *params); +typedef void (*PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param); + +/* 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)* @@ -91,6 +110,11 @@ * Structure containing function pointers to shaders commands */ typedef struct { + /* Utils commands */ + PFNGLGETERRORPROC GetError; + PFNGLGETSTRINGPROC GetString; + PFNGLGETINTEGERVPROC GetIntegerv; + /* Shader variables commands*/ PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation; PFNGLGETATTRIBLOCATIONPROC GetAttribLocation; @@ -122,6 +146,18 @@ typedef struct { PFNGLGETSHADERIVPROC GetShaderiv; PFNGLGETSHADERINFOLOGPROC GetShaderInfoLog; + /* Texture commands */ + PFNGLACTIVETEXTUREPROC ActiveTexture; + PFNGLBINDTEXTUREPROC BindTexture; + PFNGLTEXPARAMETERIPROC TexParameteri; + PFNGLTEXPARAMETERFPROC TexParameterf; + PFNGLGETTEXLEVELPARAMETERIVPROC GetTexLevelParameteriv; /* OpenGL only */ + PFNGLPIXELSTOREIPROC PixelStorei; + PFNGLGENTEXTURESPROC GenTextures; + PFNGLDELETETEXTURESPROC DeleteTextures; + PFNGLTEXIMAGE2DPROC TexImage2D; + PFNGLTEXSUBIMAGE2DPROC TexSubImage2D; + /* Buffers commands */ PFNGLGENBUFFERSPROC GenBuffers; PFNGLBINDBUFFERPROC BindBuffer; @@ -141,13 +177,6 @@ typedef struct { PFNGLDELETESYNCPROC DeleteSync; /* can be NULL */ PFNGLCLIENTWAITSYNCPROC ClientWaitSync; /* can be NULL */ #endif - -#if defined(_WIN32) - PFNGLACTIVETEXTUREPROC ActiveTexture; -# undef glActiveTexture -# define glActiveTexture tc->vt->ActiveTexture -#endif - } opengl_vtable_t; typedef struct opengl_tex_converter_t opengl_tex_converter_t; @@ -172,7 +201,8 @@ struct opengl_tex_converter_t { /* Pointer to object gl, set by the caller of the init cb */ vlc_gl_t *gl; - /* Function pointer to shaders commands, set by the caller of the init cb */ + + /* Function pointers to OpenGL functions, set by the caller */ const opengl_vtable_t *vt; /* Available gl extensions (from GL_EXTENSIONS) */ const char *glexts; diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c index a4173dd078..646cac5529 100644 --- a/modules/video_output/opengl/vout_helper.c +++ b/modules/video_output/opengl/vout_helper.c @@ -399,7 +399,7 @@ GenTextures(const opengl_tex_converter_t *tc, for (unsigned i = 0; i < tc->tex_count; i++) { - glBindTexture(tc->tex_target, textures[i]); + tc->vt->BindTexture(tc->tex_target, textures[i]); #if !defined(USE_OPENGL_ES2) /* Set the texture parameters */ @@ -677,6 +677,10 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt, #define GET_PROC_ADDR_GL(name) GET_PROC_ADDR(name) #endif #define GET_PROC_ADDR_OPTIONAL(name) GET_PROC_ADDR_EXT(name, false) /* GL 3 or more */ + GET_PROC_ADDR(GetError); + GET_PROC_ADDR(GetString); + GET_PROC_ADDR(GetIntegerv); + GET_PROC_ADDR(CreateShader); GET_PROC_ADDR(ShaderSource); GET_PROC_ADDR(CompileShader); @@ -704,6 +708,17 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt, GET_PROC_ADDR(UseProgram); GET_PROC_ADDR(DeleteProgram); + GET_PROC_ADDR(ActiveTexture); + GET_PROC_ADDR(BindTexture); + GET_PROC_ADDR(TexParameteri); + GET_PROC_ADDR(TexParameterf); + GET_PROC_ADDR_GL(GetTexLevelParameteriv); + GET_PROC_ADDR(PixelStorei); + GET_PROC_ADDR(GenTextures); + GET_PROC_ADDR(DeleteTextures); + GET_PROC_ADDR(TexImage2D); + GET_PROC_ADDR(TexSubImage2D); + GET_PROC_ADDR(GenBuffers); GET_PROC_ADDR(BindBuffer); GET_PROC_ADDR(BufferData); @@ -721,12 +736,6 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt, GET_PROC_ADDR_OPTIONAL(DeleteSync); GET_PROC_ADDR_OPTIONAL(ClientWaitSync); #endif - -#if defined(_WIN32) - GET_PROC_ADDR(ActiveTexture, true); -# undef glActiveTexture -# define glActiveTexture vgl->vt.ActiveTexture -#endif #undef GET_PROC_ADDR /* Resize the format if it is greater than the maximum texture size @@ -1415,8 +1424,8 @@ static void DrawWithShaders(vout_display_opengl_t *vgl, struct prgm *prgm) for (unsigned j = 0; j < vgl->prgm->tc.tex_count; j++) { assert(vgl->texture[j] != 0); - glActiveTexture(GL_TEXTURE0+j); - glBindTexture(tc->tex_target, vgl->texture[j]); + vgl->vt.ActiveTexture(GL_TEXTURE0+j); + vgl->vt.BindTexture(tc->tex_target, vgl->texture[j]); vgl->vt.BindBuffer(GL_ARRAY_BUFFER, vgl->texture_buffer_object[j]); @@ -1529,7 +1538,7 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl, vgl->subpicture_buffer_object); } - glActiveTexture(GL_TEXTURE0 + 0); + vgl->vt.ActiveTexture(GL_TEXTURE0 + 0); for (int i = 0; i < vgl->region_count; i++) { gl_region_t *glr = &vgl->region[i]; const GLfloat vertexCoord[] = { @@ -1546,7 +1555,7 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl, }; assert(glr->texture != 0); - glBindTexture(tc->tex_target, glr->texture); + vgl->vt.BindTexture(tc->tex_target, glr->texture); tc->pf_prepare_shader(tc, &glr->width, &glr->height, glr->alpha); _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
