SDL: Added SDL_HINT_OPENGL_LIBRARY and SDL_HINT_VULKAN_LIBRARY

From 05f870f20d6145547a30140f0e15329d0376d626 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 3 Aug 2024 09:33:32 -0700
Subject: [PATCH] Added SDL_HINT_OPENGL_LIBRARY and SDL_HINT_VULKAN_LIBRARY

---
 include/SDL3/SDL_hints.h                  | 18 ++++++++++++++++++
 src/video/android/SDL_androidvulkan.c     |  2 +-
 src/video/cocoa/SDL_cocoaopengl.m         |  2 +-
 src/video/cocoa/SDL_cocoavulkan.m         |  2 +-
 src/video/kmsdrm/SDL_kmsdrmvulkan.c       |  2 +-
 src/video/offscreen/SDL_offscreenvulkan.c |  2 +-
 src/video/uikit/SDL_uikitvulkan.m         |  2 +-
 src/video/vivante/SDL_vivantevulkan.c     |  2 +-
 src/video/wayland/SDL_waylandvulkan.c     |  2 +-
 src/video/windows/SDL_windowsopengl.c     |  2 +-
 src/video/windows/SDL_windowsvulkan.c     |  2 +-
 src/video/x11/SDL_x11opengl.c             |  2 +-
 src/video/x11/SDL_x11vulkan.c             |  2 +-
 13 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h
index c33bdf29e2c76..00b88ecd8eb72 100644
--- a/include/SDL3/SDL_hints.h
+++ b/include/SDL3/SDL_hints.h
@@ -2436,6 +2436,15 @@ extern "C" {
  */
 #define SDL_HINT_NO_SIGNAL_HANDLERS   "SDL_NO_SIGNAL_HANDLERS"
 
+/**
+ * Specify the OpenGL library to load.
+ *
+ * This hint should be set before creating an OpenGL window or creating an OpenGL context.
+ *
+ * \since This hint is available since SDL 3.0.0.
+ */
+#define SDL_HINT_OPENGL_LIBRARY "SDL_OPENGL_LIBRARY"
+
 /**
  * A variable controlling what driver to use for OpenGL ES contexts.
  *
@@ -3341,6 +3350,15 @@ extern "C" {
  */
 #define SDL_HINT_VITA_TOUCH_MOUSE_DEVICE    "SDL_VITA_TOUCH_MOUSE_DEVICE"
 
+/**
+ * Specify the Vulkan library to load.
+ *
+ * This hint should be set before creating a Vulkan window or calling SDL_Vulkan_LoadLibrary().
+ *
+ * \since This hint is available since SDL 3.0.0.
+ */
+#define SDL_HINT_VULKAN_LIBRARY "SDL_VULKAN_LIBRARY"
+
 /**
  * A variable controlling how the fact chunk affects the loading of a WAVE
  * file.
diff --git a/src/video/android/SDL_androidvulkan.c b/src/video/android/SDL_androidvulkan.c
index da5acfb66c21d..b4be7232a7a2e 100644
--- a/src/video/android/SDL_androidvulkan.c
+++ b/src/video/android/SDL_androidvulkan.c
@@ -49,7 +49,7 @@ int Android_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
 
     /* Load the Vulkan loader library */
     if (!path) {
-        path = SDL_getenv("SDL_VULKAN_LIBRARY");
+        path = SDL_GetHint(SDL_HINT_VULKAN_LIBRARY);
     }
     if (!path) {
         path = "libvulkan.so";
diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m
index 4cf14c75b03b3..319e31e239285 100644
--- a/src/video/cocoa/SDL_cocoaopengl.m
+++ b/src/video/cocoa/SDL_cocoaopengl.m
@@ -229,7 +229,7 @@ int Cocoa_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
 {
     /* Load the OpenGL library */
     if (path == NULL) {
-        path = SDL_getenv("SDL_OPENGL_LIBRARY");
+        path = SDL_GetHint(SDL_HINT_OPENGL_LIBRARY);
     }
     if (path == NULL) {
         path = DEFAULT_OPENGL;
diff --git a/src/video/cocoa/SDL_cocoavulkan.m b/src/video/cocoa/SDL_cocoavulkan.m
index 62929fd2ea9f2..0c956411ac09a 100644
--- a/src/video/cocoa/SDL_cocoavulkan.m
+++ b/src/video/cocoa/SDL_cocoavulkan.m
@@ -61,7 +61,7 @@ int Cocoa_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
 
     /* Load the Vulkan loader library */
     if (!path) {
-        path = SDL_getenv("SDL_VULKAN_LIBRARY");
+        path = SDL_GetHint(SDL_HINT_VULKAN_LIBRARY);
     }
 
     if (!path) {
diff --git a/src/video/kmsdrm/SDL_kmsdrmvulkan.c b/src/video/kmsdrm/SDL_kmsdrmvulkan.c
index eb68199258d17..7ca9e92d7a270 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvulkan.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvulkan.c
@@ -56,7 +56,7 @@ int KMSDRM_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
 
     /* Load the Vulkan library */
     if (!path) {
-        path = SDL_getenv("SDL_VULKAN_LIBRARY");
+        path = SDL_GetHint(SDL_HINT_VULKAN_LIBRARY);
     }
     if (!path) {
         path = DEFAULT_VULKAN;
diff --git a/src/video/offscreen/SDL_offscreenvulkan.c b/src/video/offscreen/SDL_offscreenvulkan.c
index ec33186d20f55..1727d997f2314 100644
--- a/src/video/offscreen/SDL_offscreenvulkan.c
+++ b/src/video/offscreen/SDL_offscreenvulkan.c
@@ -74,7 +74,7 @@ int OFFSCREEN_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
 
     /* Load the Vulkan loader library */
     if (!path) {
-        path = SDL_getenv("SDL_VULKAN_LIBRARY");
+        path = SDL_GetHint(SDL_HINT_VULKAN_LIBRARY);
     }
 
 #if defined(SDL_PLATFORM_APPLE)
diff --git a/src/video/uikit/SDL_uikitvulkan.m b/src/video/uikit/SDL_uikitvulkan.m
index cab1c75873b7c..9d045535a68ef 100644
--- a/src/video/uikit/SDL_uikitvulkan.m
+++ b/src/video/uikit/SDL_uikitvulkan.m
@@ -59,7 +59,7 @@ int UIKit_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
 
     /* Load the Vulkan loader library */
     if (!path) {
-        path = SDL_getenv("SDL_VULKAN_LIBRARY");
+        path = SDL_GetHint(SDL_HINT_VULKAN_LIBRARY);
     }
 
     if (!path) {
diff --git a/src/video/vivante/SDL_vivantevulkan.c b/src/video/vivante/SDL_vivantevulkan.c
index d1a7ef7cc0a0c..8325efff13788 100644
--- a/src/video/vivante/SDL_vivantevulkan.c
+++ b/src/video/vivante/SDL_vivantevulkan.c
@@ -47,7 +47,7 @@ int VIVANTE_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
 
     /* Load the Vulkan loader library */
     if (!path) {
-        path = SDL_getenv("SDL_VULKAN_LIBRARY");
+        path = SDL_GetHint(SDL_HINT_VULKAN_LIBRARY);
     }
     if (!path) {
         /* If no path set, try Vivante fb vulkan driver explicitly */
diff --git a/src/video/wayland/SDL_waylandvulkan.c b/src/video/wayland/SDL_waylandvulkan.c
index 0a0d3c5c865db..97cb61426f435 100644
--- a/src/video/wayland/SDL_waylandvulkan.c
+++ b/src/video/wayland/SDL_waylandvulkan.c
@@ -54,7 +54,7 @@ int Wayland_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
 
     /* Load the Vulkan loader library */
     if (!path) {
-        path = SDL_getenv("SDL_VULKAN_LIBRARY");
+        path = SDL_GetHint(SDL_HINT_VULKAN_LIBRARY);
     }
     if (!path) {
         path = DEFAULT_VULKAN;
diff --git a/src/video/windows/SDL_windowsopengl.c b/src/video/windows/SDL_windowsopengl.c
index 7e17e8f83ef95..0f18eb28e3689 100644
--- a/src/video/windows/SDL_windowsopengl.c
+++ b/src/video/windows/SDL_windowsopengl.c
@@ -110,7 +110,7 @@ int WIN_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
     void *handle;
 
     if (path == NULL) {
-        path = SDL_getenv("SDL_OPENGL_LIBRARY");
+        path = SDL_GetHint(SDL_HINT_OPENGL_LIBRARY);
     }
     if (path == NULL) {
         path = DEFAULT_OPENGL;
diff --git a/src/video/windows/SDL_windowsvulkan.c b/src/video/windows/SDL_windowsvulkan.c
index abd2d034ac208..f8f0cb7622761 100644
--- a/src/video/windows/SDL_windowsvulkan.c
+++ b/src/video/windows/SDL_windowsvulkan.c
@@ -49,7 +49,7 @@ int WIN_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
 
     /* Load the Vulkan loader library */
     if (!path) {
-        path = SDL_getenv("SDL_VULKAN_LIBRARY");
+        path = SDL_GetHint(SDL_HINT_VULKAN_LIBRARY);
     }
     if (!path) {
         path = "vulkan-1.dll";
diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c
index d94205130365b..b393ec260e347 100644
--- a/src/video/x11/SDL_x11opengl.c
+++ b/src/video/x11/SDL_x11opengl.c
@@ -172,7 +172,7 @@ int X11_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
 
     /* Load the OpenGL library */
     if (path == NULL) {
-        path = SDL_getenv("SDL_OPENGL_LIBRARY");
+        path = SDL_GetHint(SDL_HINT_OPENGL_LIBRARY);
     }
     if (path == NULL) {
         path = DEFAULT_OPENGL;
diff --git a/src/video/x11/SDL_x11vulkan.c b/src/video/x11/SDL_x11vulkan.c
index 93641b39a7cc8..cabd85e97cc70 100644
--- a/src/video/x11/SDL_x11vulkan.c
+++ b/src/video/x11/SDL_x11vulkan.c
@@ -58,7 +58,7 @@ int X11_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
 
     /* Load the Vulkan loader library */
     if (!path) {
-        path = SDL_getenv("SDL_VULKAN_LIBRARY");
+        path = SDL_GetHint(SDL_HINT_VULKAN_LIBRARY);
     }
     if (!path) {
         path = DEFAULT_VULKAN;