[vlc-commits] [Git][videolan/vlc][master] 5 commits: gl: only enable GL_OES_texture_3D in GLSL when extension is available
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Wed Nov 12 05:43:58 UTC 2025
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
86df4c02 by Pierre Lamot at 2025-11-12T06:23:38+01:00
gl: only enable GL_OES_texture_3D in GLSL when extension is available
- - - - -
af5a8eeb by Pierre Lamot at 2025-11-12T06:23:38+01:00
gl: adapt sub_renderer shader to the current glsl language version
- - - - -
109d5bce by Pierre Lamot at 2025-11-12T06:23:38+01:00
gl: use texture instead of texture2DRect when available
- - - - -
e59a559c by Pierre Lamot at 2025-11-12T06:23:38+01:00
gl: always assume NPOT support
NPOT textures is supported by standard in OpenGLES and OpenGL 2.0
(see OpenGL 2.0 Appendix I.3)
Some OpenGL implementations such as Apple core profile, no longer list
`GL_ARB_texture_non_power_of_two` or `GL_APPLE_texture_2D_limited_npot`
as part of their extensions
- - - - -
005d0e95 by Pierre Lamot at 2025-11-12T06:23:38+01:00
gl: assert requested texture size isn't bigger than source size in cvpx interop
Textures were potentially allocated at power of two size, this could have resulted
in querying more data than available
- - - - -
7 changed files:
- modules/video_output/opengl/gl_api.c
- modules/video_output/opengl/gl_api.h
- modules/video_output/opengl/importer.c
- modules/video_output/opengl/interop_cvpx.m
- modules/video_output/opengl/sampler.c
- modules/video_output/opengl/sub_renderer.c
- modules/video_output/opengl/sub_renderer.h
Changes:
=====================================
modules/video_output/opengl/gl_api.c
=====================================
@@ -208,15 +208,12 @@ vlc_gl_api_Init(struct vlc_gl_api *api, vlc_gl_t *gl)
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;
if (!api->glsl_version)
api->glsl_version = version >= 3 ? 300 : 100;
}
else
{
api->is_gles = false;
- api->supports_npot = vlc_gl_HasExtension(&extension_vt, "GL_ARB_texture_non_power_of_two") ||
- vlc_gl_HasExtension(&extension_vt, "GL_APPLE_texture_2D_limited_npot");
if (!api->glsl_version)
api->glsl_version = 120;
}
=====================================
modules/video_output/opengl/gl_api.h
=====================================
@@ -41,9 +41,6 @@ struct vlc_gl_api {
/* True if the current API is OpenGL ES, set by the caller */
bool is_gles;
- /* Non-power-of-2 texture size support */
- bool supports_npot;
-
/* Multisampling for anti-aliasing */
bool supports_multisample;
=====================================
modules/video_output/opengl/importer.c
=====================================
@@ -231,25 +231,15 @@ vlc_gl_importer_New(struct vlc_gl_interop *interop)
struct vlc_gl_extension_vt extension_vt;
vlc_gl_LoadExtensionFunctions(interop->gl, &extension_vt);
- /* OpenGL ES 2 includes support for non-power of 2 textures by specification. */
- bool supports_npot = interop->gl->api_type == VLC_OPENGL_ES2
- || vlc_gl_HasExtension(&extension_vt, "GL_ARB_texture_non_power_of_two")
- || vlc_gl_HasExtension(&extension_vt, "GL_APPLE_texture_2D_limited_npot");
-
/* Texture size */
for (unsigned j = 0; j < interop->tex_count; j++) {
GLsizei w = (interop->fmt_out.i_visible_width + interop->fmt_out.i_x_offset) * interop->texs[j].w.num
/ interop->texs[j].w.den;
GLsizei h = (interop->fmt_out.i_visible_height + interop->fmt_out.i_y_offset) * interop->texs[j].h.num
/ interop->texs[j].h.den;
- if (supports_npot) {
- glfmt->tex_widths[j] = w;
- glfmt->tex_heights[j] = h;
- } else {
- glfmt->tex_widths[j] = stdc_bit_ceil((unsigned)w);
- glfmt->tex_heights[j] = stdc_bit_ceil((unsigned)h);
- }
-
+ glfmt->tex_widths[j] = w;
+ glfmt->tex_heights[j] = h;
+
glfmt->formats[j] = interop->texs[j].format;
}
=====================================
modules/video_output/opengl/interop_cvpx.m
=====================================
@@ -129,6 +129,9 @@ tc_cvpx_update(const struct vlc_gl_interop *interop, uint32_t textures[],
for (unsigned i = 0; i < interop->tex_count; ++i)
{
+ assert(IOSurfaceGetWidthOfPlane(surface, i) >= tex_width[i]);
+ assert(IOSurfaceGetHeightOfPlane(surface, i) >= tex_height[i]);
+
priv->gl.ActiveTexture(GL_TEXTURE0 + i);
priv->gl.BindTexture(interop->tex_target, textures[i]);
=====================================
modules/video_output/opengl/sampler.c
=====================================
@@ -547,6 +547,10 @@ GetNames(struct vlc_gl_sampler *sampler, GLenum tex_target,
(priv->gl->api_type == VLC_OPENGL && priv->glsl_version >= 130) ||
(priv->gl->api_type == VLC_OPENGL_ES2 && priv->glsl_version >= 300);
+ //GLES has no texture rectangle
+ bool has_texture_rect_func =
+ (priv->gl->api_type == VLC_OPENGL && priv->glsl_version >= 140);
+
const bool is_yuv = vlc_fourcc_IsYUV(sampler->glfmt.fmt.i_chroma);
switch (tex_target)
@@ -561,7 +565,7 @@ GetNames(struct vlc_gl_sampler *sampler, GLenum tex_target,
break;
case GL_TEXTURE_RECTANGLE:
*glsl_sampler = "sampler2DRect";
- *texture = "texture2DRect";
+ *texture = has_texture_rect_func ? "texture" : "texture2DRect";
break;
default:
vlc_assert_unreachable();
@@ -590,9 +594,10 @@ InitShaderExtensions(struct vlc_gl_sampler *sampler, GLenum tex_target)
image_ext = image_external;
}
- int ret = asprintf(&sampler->shader.extensions,
- "#extension GL_OES_texture_3D : enable\n"
- "%s", image_ext);
+ const char *texture3D_ext = priv->api->supports_sampler3D
+ ? "#extension GL_OES_texture_3D : enable\n" : "";
+
+ int ret = asprintf(&sampler->shader.extensions,"%s%s\n", image_ext, texture3D_ext);
if (ret <= 0)
{
if (ret == 0)
=====================================
modules/video_output/opengl/sub_renderer.c
=====================================
@@ -140,9 +140,15 @@ vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
"precision mediump float;\n"
"#endif\n"
- "attribute vec2 vertex_pos;\n"
- "attribute vec2 tex_coords_in;\n"
- "varying vec2 tex_coords;\n"
+ "#if __VERSION__ < 300\n"
+ "attribute vec2 vertex_pos;\n"
+ "attribute vec2 tex_coords_in;\n"
+ "varying vec2 tex_coords;\n"
+ "#else\n"
+ "in vec2 vertex_pos;\n"
+ "in vec2 tex_coords_in;\n"
+ "out vec2 tex_coords;\n"
+ "#endif\n"
"void main() {\n"
" tex_coords = tex_coords_in;\n"
" gl_Position = vec4(vertex_pos, 0.0, 1.0);\n"
@@ -153,17 +159,43 @@ vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
"precision mediump float;\n"
"#endif\n"
+ "#if (defined(GL_ES) && __VERSION__ >= 300) || (!defined(GL_ES) && __VERSION__ >= 130)\n"
+ "#define vlc_texture texture\n"
+ "#else\n"
+ "#define vlc_texture texture2D\n"
+ "#endif\n"
+
+ "#if __VERSION__ < 300\n"
+ "#define FragColor gl_FragColor\n"
+ "#else\n"
+ "out vec4 FragColor;\n"
+ "#endif\n"
+
"uniform sampler2D sampler;\n"
"uniform float alpha;\n"
- "varying vec2 tex_coords;\n"
+ "#if __VERSION__ < 300\n"
+ "varying vec2 tex_coords;\n"
+ "#else\n"
+ "in vec2 tex_coords;\n"
+ "#endif\n"
"void main() {\n"
- " vec4 color = texture2D(sampler, tex_coords);\n"
+ " vec4 color = vlc_texture(sampler, tex_coords);\n"
" color.a *= alpha;\n"
- " gl_FragColor = color;\n"
+ " FragColor = color;\n"
"}\n";
- const char *glsl_version = gl->api_type == VLC_OPENGL ?
- "#version 120\n" : "#version 100\n";
+ char *glsl_version = NULL;
+
+ if (gl->api_type == VLC_OPENGL_ES2)
+ glsl_version = strdup("#version 100\n");
+ else
+ {
+ int target_version = __MIN(api->glsl_version, 410);
+ if (asprintf(&glsl_version, "#version %d\n", target_version) <= 0)
+ goto error_1;
+ }
+ if (!glsl_version)
+ goto error_1;
const char *vertex_shader[] = {
glsl_version,
@@ -201,6 +233,7 @@ vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
error_2:
vt->DeleteProgram(sr->program_id);
error_1:
+ free(glsl_version);
free(sr);
return NULL;
@@ -263,17 +296,10 @@ vlc_gl_sub_renderer_Prepare(struct vlc_gl_sub_renderer *sr,
vlc_vector_foreach(r, &subpicture->regions) {
gl_region_t *glr = &sr->regions[i];
- glr->width = r->p_picture->format.i_visible_width;
- glr->height = r->p_picture->format.i_visible_height;
- if (!sr->api->supports_npot) {
- glr->width = stdc_bit_ceil(r->p_picture->format.i_visible_width);
- glr->height = stdc_bit_ceil(r->p_picture->format.i_visible_height);
- glr->tex_width = (float) r->p_picture->format.i_visible_width / glr->width;
- glr->tex_height = (float) r->p_picture->format.i_visible_height / glr->height;
- } else {
- glr->tex_width = 1.0;
- glr->tex_height = 1.0;
- }
+ glr->width = stdc_bit_ceil(r->p_picture->format.i_visible_width);
+ glr->height = stdc_bit_ceil(r->p_picture->format.i_visible_height);
+ glr->tex_width = (float) r->p_picture->format.i_visible_width / glr->width;
+ glr->tex_height = (float) r->p_picture->format.i_visible_height / glr->height;
glr->alpha = (float)r->i_alpha / 255;
glr->left = 2.0 * (r->place.x ) / sr->output_width - 1.0;
glr->top = -2.0 * (r->place.y ) / sr->output_height + 1.0;
=====================================
modules/video_output/opengl/sub_renderer.h
=====================================
@@ -44,8 +44,6 @@ struct vlc_gl_sub_renderer;
*
* \param gl the GL context
* \param api the OpenGL API
- * \param supports_npot indicate if the implementation supports non-power-of-2
- * texture size
*/
struct vlc_gl_sub_renderer *
vlc_gl_sub_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/df2439ec19fc1415b006475d24452c16e9a47aa4...005d0e95de53e51a6c37a5d44f2783e19e642a15
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/df2439ec19fc1415b006475d24452c16e9a47aa4...005d0e95de53e51a6c37a5d44f2783e19e642a15
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