From 37eb6a0de0399ff005f67281beafc657fa7ed964 Mon Sep 17 00:00:00 2001 From: Vasily Khoruzhick Date: Mon, 13 Jul 2026 16:35:14 -0700 Subject: [PATCH] vo_gpu: opengl: support GL_EXT_framebuffer_object Some GL 2.1 drivers (e.g. Mesa lima) expose GL_EXT_framebuffer_object but not GL_ARB_framebuffer_object, leaving MPGL_CAP_FB unset even though FBOs are usable. Load the EXT entrypoints as an alternative provider of MPGL_CAP_FB; mpv's FBO usage (Gen'd names, GL_FRAMEBUFFER target, single color attachment, runtime completeness checks) is within the subset EXT and ARB share. The section is placed before the ARB/core one so the latter overwrites the function pointers whenever it is available. Querying attachment parameters of the default framebuffer is an ARB/GL 3.0 addition, so skip that query in ra_gl_ctx_color_depth() when only the EXT extension is present. --- video/out/opengl/common.c | 20 ++++++++++++++++++++ video/out/opengl/context.c | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/video/out/opengl/common.c b/video/out/opengl/common.c index a5de79c901..9357674353 100644 --- a/video/out/opengl/common.c +++ b/video/out/opengl/common.c @@ -212,6 +212,26 @@ static const struct gl_functions gl_functions[] = { .extension = "GL_EXT_unpack_subimage", .provides = MPGL_CAP_ROW_LENGTH, }, + // Framebuffers, alternative extension name. Some GL 2.1 drivers (e.g. + // Mesa lima) expose only this one. It provides a compatible subset of + // GL_ARB_framebuffer_object for our purposes; the entrypoints loaded + // here are overwritten by the ARB/core ones below if available. + { + .ver_exclude = 300, + .ver_es_exclude = 200, // FBOs are core in ES2 + .extension = "GL_EXT_framebuffer_object", + .provides = MPGL_CAP_FB, + .functions = (const struct gl_function[]) { + DEF_FN_NAME(BindFramebuffer, "glBindFramebufferEXT"), + DEF_FN_NAME(GenFramebuffers, "glGenFramebuffersEXT"), + DEF_FN_NAME(DeleteFramebuffers, "glDeleteFramebuffersEXT"), + DEF_FN_NAME(CheckFramebufferStatus, "glCheckFramebufferStatusEXT"), + DEF_FN_NAME(FramebufferTexture2D, "glFramebufferTexture2DEXT"), + DEF_FN_NAME(GetFramebufferAttachmentParameteriv, + "glGetFramebufferAttachmentParameterivEXT"), + {0} + }, + }, // Framebuffers, extension in GL 2.x, core in GL 3.x core. { .ver_core = 300, diff --git a/video/out/opengl/context.c b/video/out/opengl/context.c index cd76e1c5f8..9b8cabfe8c 100644 --- a/video/out/opengl/context.c +++ b/video/out/opengl/context.c @@ -193,6 +193,12 @@ int ra_gl_ctx_color_depth(struct ra_swapchain *sw) if ((gl->es < 300 && !gl->version) || !(gl->mpgl_caps & MPGL_CAP_FB)) return 0; + // The *_SIZE attachment queries need GL_ARB_framebuffer_object or + // GL 3.0+; GL_EXT_framebuffer_object does not provide them. + if (gl->version && gl->version < 300 && + !gl_check_extension(gl->extensions, "GL_ARB_framebuffer_object")) + return 0; + gl->BindFramebuffer(GL_FRAMEBUFFER, p->main_fb); GLenum obj = gl->version ? GL_BACK_LEFT : GL_BACK;