From 6ed1b0097460472c375a3e5ec22af0c1632123b9 Mon Sep 17 00:00:00 2001
From: Niklas Haas <git@haasn.dev>
Date: Fri, 19 Aug 2022 13:43:26 +0200
Subject: [PATCH] opengl/context: add get_proc_addr_ex to take an extra void*

This is needed for both mpv and VLC. Preserve the old API for
back-compat with simpler libraries like GLFW or SDL2.

Closes https://code.videolan.org/videolan/libplacebo/-/issues/216
---
 meson.build                     | 1 +
 src/include/libplacebo/opengl.h | 5 +++++
 src/opengl/context.c            | 5 ++++-
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 5a9fdec81..8d56646df 100644
--- a/meson.build
+++ b/meson.build
@@ -12,6 +12,7 @@ project('libplacebo', ['c', 'cpp'],
     5,
     # API version
     {
+      '215': 'add pl_opengl_params.get_proc_addr_ex',
       '214': 'drop deprecated legacy C struct names',
       '213': 'add pl_opengl_params.get_proc_addr',
       '212': 'add pl_opengl.major/minor version numbers',
diff --git a/src/include/libplacebo/opengl.h b/src/include/libplacebo/opengl.h
index 3e2999bd8..0fadc1480 100644
--- a/src/include/libplacebo/opengl.h
+++ b/src/include/libplacebo/opengl.h
@@ -55,6 +55,11 @@ struct pl_opengl_params {
     // Main gl*GetProcAddr function. This will be used to load all GL/EGL
     // functions. Optional - if unspecified, libplacebo will default to an
     // internal loading logic which should work on most platforms.
+    pl_voidfunc_t (*get_proc_addr_ex)(void *proc_ctx, const char *procname);
+    void *proc_ctx;
+
+    // Simpler API for backwards compatibility / convenience. (This one
+    // directly matches the signature of most gl*GetProcAddr library functions)
     pl_voidfunc_t (*get_proc_addr)(const char *procname);
 
     // Enable OpenGL debug report callbacks. May have little effect depending
diff --git a/src/opengl/context.c b/src/opengl/context.c
index f64403080..6fcb0fdcb 100644
--- a/src/opengl/context.c
+++ b/src/opengl/context.c
@@ -120,7 +120,10 @@ pl_opengl pl_opengl_create(pl_log log, const struct pl_opengl_params *params)
     }
 
     bool ok = false;
-    if (params->get_proc_addr) {
+    if (params->get_proc_addr_ex) {
+        ok |= gladLoadGLContextUserPtr(gl, params->get_proc_addr_ex, params->proc_ctx);
+        ok |= gladLoadGLES2ContextUserPtr(gl, params->get_proc_addr_ex, params->proc_ctx);
+    } else if (params->get_proc_addr) {
         ok |= gladLoadGLContext(gl, params->get_proc_addr);
         ok |= gladLoadGLES2Context(gl, params->get_proc_addr);
     } else {
-- 
GitLab