From fb77881ba8021e0cd77a36b75d26d764d3cd33a7 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 31 Jan 2020 15:54:41 +0100 Subject: [PATCH] opengl: expose npot support in gl_api Expose in vlc_gl_api whether it supports non-power of 2 textures. Signed-off-by: Jean-Baptiste Kempf --- modules/video_output/opengl/gl_api.c | 5 +++++ modules/video_output/opengl/gl_api.h | 3 +++ modules/video_output/opengl/renderer.c | 4 ++-- modules/video_output/opengl/renderer.h | 4 +--- modules/video_output/opengl/sub_renderer.c | 7 ++----- modules/video_output/opengl/sub_renderer.h | 3 +-- modules/video_output/opengl/vout_helper.c | 25 ++----------------------- 7 files changed, 16 insertions(+), 35 deletions(-) diff --git a/modules/video_output/opengl/gl_api.c b/modules/video_output/opengl/gl_api.c index 9cf2bc2c19..6bead1cb6b 100644 --- a/modules/video_output/opengl/gl_api.c +++ b/modules/video_output/opengl/gl_api.c @@ -142,8 +142,13 @@ vlc_gl_api_Init(struct vlc_gl_api *api, vlc_gl_t *gl) #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 return VLC_SUCCESS; diff --git a/modules/video_output/opengl/gl_api.h b/modules/video_output/opengl/gl_api.h index 6aba0ea1be..2ddae33178 100644 --- a/modules/video_output/opengl/gl_api.h +++ b/modules/video_output/opengl/gl_api.h @@ -40,6 +40,9 @@ struct vlc_gl_api { /* Available gl extensions (from GL_EXTENSIONS) */ const char *extensions; + + /* Non-power-of-2 texture size support */ + bool supports_npot; }; int diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c index 69332defb1..93c2ea63bf 100644 --- a/modules/video_output/opengl/renderer.c +++ b/modules/video_output/opengl/renderer.c @@ -324,7 +324,7 @@ vlc_gl_renderer_Delete(struct vlc_gl_renderer *renderer) struct vlc_gl_renderer * vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api, vlc_video_context *context, const video_format_t *fmt, - bool supports_npot, bool b_dump_shaders) + bool b_dump_shaders) { const opengl_vtable_t *vt = &api->vt; @@ -390,7 +390,7 @@ vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api, / interop->texs[j].w.den; const GLsizei h = renderer->fmt.i_visible_height * interop->texs[j].h.num / interop->texs[j].h.den; - if (supports_npot) { + if (api->supports_npot) { renderer->tex_width[j] = w; renderer->tex_height[j] = h; } else { diff --git a/modules/video_output/opengl/renderer.h b/modules/video_output/opengl/renderer.h index e161e7eb52..913a8c8e6e 100644 --- a/modules/video_output/opengl/renderer.h +++ b/modules/video_output/opengl/renderer.h @@ -158,14 +158,12 @@ struct vlc_gl_renderer * \param api the OpenGL API * \param context the video context * \param fmt the video format - * \param supports_npot indicate if the implementation supports non-power-of-2 - * texture size * \param dump_shaders indicate if the shaders must be dumped in logs */ struct vlc_gl_renderer * vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api, vlc_video_context *context, const video_format_t *fmt, - bool supports_npot, bool dump_shaders); + bool dump_shaders); /** * Delete a renderer diff --git a/modules/video_output/opengl/sub_renderer.c b/modules/video_output/opengl/sub_renderer.c index 8313b81caa..bcaaad2558 100644 --- a/modules/video_output/opengl/sub_renderer.c +++ b/modules/video_output/opengl/sub_renderer.c @@ -65,7 +65,6 @@ struct vlc_gl_sub_renderer struct vlc_gl_interop *interop; - bool supports_npot; gl_region_t *regions; unsigned region_count; @@ -113,8 +112,7 @@ FetchLocations(struct vlc_gl_sub_renderer *sr) } struct vlc_gl_sub_renderer * -vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api, - bool supports_npot) +vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api) { const opengl_vtable_t *vt = &api->vt; @@ -134,7 +132,6 @@ vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api, sr->gl = gl; sr->api = api; sr->vt = vt; - sr->supports_npot = supports_npot; sr->region_count = 0; sr->regions = NULL; @@ -249,7 +246,7 @@ vlc_gl_sub_renderer_Prepare(struct vlc_gl_sub_renderer *sr, subpicture_t *subpic glr->width = r->fmt.i_visible_width; glr->height = r->fmt.i_visible_height; - if (!sr->supports_npot) { + if (!sr->api->supports_npot) { glr->width = vlc_align_pot(glr->width); glr->height = vlc_align_pot(glr->height); glr->tex_width = (float) r->fmt.i_visible_width / glr->width; diff --git a/modules/video_output/opengl/sub_renderer.h b/modules/video_output/opengl/sub_renderer.h index cfd1bc79d2..7b027a937b 100644 --- a/modules/video_output/opengl/sub_renderer.h +++ b/modules/video_output/opengl/sub_renderer.h @@ -45,8 +45,7 @@ struct vlc_gl_sub_renderer; * texture size */ struct vlc_gl_sub_renderer * -vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api, - bool supports_npot); +vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api); /** * Delete a subpictures renderer diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c index 72c5865f8d..ae955109b5 100644 --- a/modules/video_output/opengl/vout_helper.c +++ b/modules/video_output/opengl/vout_helper.c @@ -110,14 +110,6 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt, const opengl_vtable_t *vt = &vgl->api.vt; - const char *extensions = (const char *) vt->GetString(GL_EXTENSIONS); - assert(extensions); - if (!extensions) - { - msg_Err(gl, "glGetString returned NULL"); - free(vgl); - return NULL; - } #if !defined(USE_OPENGL_ES2) const unsigned char *ogl_version = vt->GetString(GL_VERSION); bool supports_shaders = strverscmp((const char *)ogl_version, "2.0") >= 0; @@ -138,22 +130,10 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt, (GLint)fmt->i_height > max_tex_size) ResizeFormatToGLMaxTexSize(fmt, max_tex_size); - /* Non-power-of-2 texture size support */ - bool supports_npot; -#if defined(USE_OPENGL_ES2) - /* 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. */ - supports_npot = true; -#else - supports_npot = vlc_gl_StrHasToken(extensions, "GL_ARB_texture_non_power_of_two") || - vlc_gl_StrHasToken(extensions, "GL_APPLE_texture_2D_limited_npot"); -#endif - bool b_dump_shaders = var_InheritInteger(gl, "verbose") >= 4; struct vlc_gl_renderer *renderer = vgl->renderer = - vlc_gl_renderer_New(gl, &vgl->api, context, fmt, supports_npot, - b_dump_shaders); + vlc_gl_renderer_New(gl, &vgl->api, context, fmt, b_dump_shaders); if (!vgl->renderer) { msg_Warn(gl, "Could not create renderer for %4.4s", @@ -164,8 +144,7 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt, GL_ASSERT_NOERROR(vt); - vgl->sub_renderer = vlc_gl_sub_renderer_New(gl, &vgl->api, - supports_npot); + vgl->sub_renderer = vlc_gl_sub_renderer_New(gl, &vgl->api); if (!vgl->sub_renderer) { msg_Err(gl, "Could not create sub renderer"); -- 2.11.4.GIT