SDL: windows: support forcing EGL for GL desktop

From e8fbb02d160ff1ef461f27ec62925284a1ed7a48 Mon Sep 17 00:00:00 2001
From: Steven Noonan <[EMAIL REDACTED]>
Date: Sun, 11 Sep 2022 12:30:18 -0700
Subject: [PATCH] windows: support forcing EGL for GL desktop

This will theoretically support ANGLE's GL desktop frontend whenever it
becomes fully implemented and enabled in the future.
---
 src/video/SDL_egl.c                     | 1 +
 src/video/windows/SDL_windowsopengles.c | 7 +++++--
 src/video/windows/SDL_windowswindow.c   | 5 +++--
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index 78f64b59f5bd..183c2546f4cc 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -76,6 +76,7 @@
 #elif SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
 /* EGL AND OpenGL ES support via ANGLE */
 #define DEFAULT_EGL "libEGL.dll"
+#define DEFAULT_OGL "opengl32.dll"
 #define DEFAULT_OGL_ES2 "libGLESv2.dll"
 #define DEFAULT_OGL_ES_PVR "libGLES_CM.dll"
 #define DEFAULT_OGL_ES "libGLESv1_CM.dll"
diff --git a/src/video/windows/SDL_windowsopengles.c b/src/video/windows/SDL_windowsopengles.c
index 74fd946c5833..4ba30ba4fd65 100644
--- a/src/video/windows/SDL_windowsopengles.c
+++ b/src/video/windows/SDL_windowsopengles.c
@@ -22,6 +22,7 @@
 
 #if SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
 
+#include "SDL_hints.h"
 #include "SDL_windowsvideo.h"
 #include "SDL_windowsopengles.h"
 #include "SDL_windowsopengl.h"
@@ -33,7 +34,8 @@ int
 WIN_GLES_LoadLibrary(_THIS, const char *path) {
 
     /* If the profile requested is not GL ES, switch over to WIN_GL functions  */
-    if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
+    if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES &&
+        !SDL_GetHintBoolean(SDL_HINT_VIDEO_FORCE_EGL, SDL_FALSE)) {
 #if SDL_VIDEO_OPENGL_WGL
         WIN_GLES_UnloadLibrary(_this);
         _this->GL_LoadLibrary = WIN_GL_LoadLibrary;
@@ -66,7 +68,8 @@ WIN_GLES_CreateContext(_THIS, SDL_Window * window)
     SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
 
 #if SDL_VIDEO_OPENGL_WGL
-    if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
+    if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES &&
+        !SDL_GetHintBoolean(SDL_HINT_VIDEO_FORCE_EGL, SDL_FALSE)) {
         /* Switch to WGL based functions */
         WIN_GLES_UnloadLibrary(_this);
         _this->GL_LoadLibrary = WIN_GL_LoadLibrary;
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index 488b6fe1a52d..ec69de5e1403 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -542,9 +542,10 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
 
     /* The rest of this macro mess is for OpenGL or OpenGL ES windows */
 #if SDL_VIDEO_OPENGL_ES2
-    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
+    if ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES ||
+         SDL_GetHintBoolean(SDL_HINT_VIDEO_FORCE_EGL, SDL_FALSE)) &&
 #if SDL_VIDEO_OPENGL_WGL
-        && (!_this->gl_data || WIN_GL_UseEGL(_this))
+        (!_this->gl_data || WIN_GL_UseEGL(_this))
 #endif /* SDL_VIDEO_OPENGL_WGL */
     ) {
 #if SDL_VIDEO_OPENGL_EGL