vo_gpu_next: pass GL get_proc_addr pointer to libplacebo

Facing down the multitude of ways to somehow wrangle the get_fn pointer
out of the GL environment and into libplacebo, I decided the easiest is
to just store it inside the GL struct itself.

The lifetime of this get_fn function is a bit murky, since it's not
clear on whether or not it survives the VO init call (especially in the
case of the GL render API, which explicitly states that parameters do
not need to survive the call they're passed to), so just add a
disclaimer.

(It's fine for us to use like this because `gpu_ctx_create` is still
part of VO init)

Closes https://code.videolan.org/videolan/libplacebo/-/issues/216
This commit is contained in:
Niklas Haas 2022-08-19 13:51:50 +02:00
parent 891c9c869f
commit 37aea112c1
3 changed files with 11 additions and 0 deletions

View File

@ -148,6 +148,10 @@ struct gpu_ctx *gpu_ctx_create(struct vo *vo, struct gl_video_opts *gl_opts)
pl_opengl_params(
.debug = ctx_opts->debug,
.allow_software = ctx_opts->allow_sw,
# if PL_API_VER >= 215
.get_proc_addr_ex = (void *) ra_gl_get(ctx->ra_ctx->ra)->get_fn,
.proc_ctx = ra_gl_get(ctx->ra_ctx->ra)->fn_ctx,
# endif
# if HAVE_EGL
.egl_display = eglGetCurrentDisplay(),
.egl_context = eglGetCurrentContext(),

View File

@ -504,6 +504,8 @@ void mpgl_load_functions2(GL *gl, void *(*get_fn)(void *ctx, const char *n),
talloc_free(gl->extensions);
*gl = (GL) {
.extensions = talloc_strdup(gl, ext2 ? ext2 : ""),
.get_fn = get_fn,
.fn_ctx = fn_ctx,
};
gl->GetString = get_fn(fn_ctx, "glGetString");

View File

@ -87,6 +87,11 @@ struct GL {
int mpgl_caps; // Bitfield of MPGL_CAP_* constants
bool debug_context; // use of e.g. GLX_CONTEXT_DEBUG_BIT_ARB
// Copy of function pointer used to load GL.
// Caution: Not necessarily valid to use after VO init has completed!
void *(*get_fn)(void *ctx, const char *n);
void *fn_ctx;
void (GLAPIENTRY *Viewport)(GLint, GLint, GLsizei, GLsizei);
void (GLAPIENTRY *Clear)(GLbitfield);
void (GLAPIENTRY *GenTextures)(GLsizei, GLuint *);