SDL: Implement SDL_GL_GetAttribute for SDL_GL_FLOATBUFFERS

From d103e5531f82042228b9ffdc18e075ad0a2b585e Mon Sep 17 00:00:00 2001
From: "Boris I. Bendovsky" <[EMAIL REDACTED]>
Date: Sun, 27 Jul 2025 21:55:59 +0300
Subject: [PATCH] Implement SDL_GL_GetAttribute for SDL_GL_FLOATBUFFERS

---
 src/video/SDL_sysvideo.h              |  1 +
 src/video/SDL_video.c                 | 13 +++++++++++++
 src/video/windows/SDL_windowsopengl.c |  9 ++++++++-
 src/video/windows/SDL_windowsopengl.h |  1 +
 4 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 42ade5e7d7639..c8cd3991cf199 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -455,6 +455,7 @@ struct SDL_VideoDevice
         int retained_backing;
         int egl_platform;
         int driver_loaded;
+        int HAS_GL_ARB_color_buffer_float;
         char driver_path[256];
         SDL_SharedObject *dll_handle;
     } gl_config;
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 72b6149f445e3..1fd398bed7cbb 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -75,6 +75,10 @@
 #include <unistd.h>
 #endif
 
+#ifndef GL_RGBA_FLOAT_MODE_ARB
+#define GL_RGBA_FLOAT_MODE_ARB 0x8820
+#endif /* GL_RGBA_FLOAT_MODE_ARB */
+
 // Available video drivers
 static VideoBootStrap *bootstrap[] = {
 #ifdef SDL_VIDEO_DRIVER_PRIVATE
@@ -5124,6 +5128,15 @@ bool SDL_GL_GetAttribute(SDL_GLAttr attr, int *value)
         *value = _this->gl_config.egl_platform;
         return true;
     }
+    case SDL_GL_FLOATBUFFERS:
+    {
+        if (_this->gl_config.HAS_GL_ARB_color_buffer_float) {
+            attrib = GL_RGBA_FLOAT_MODE_ARB;
+            break;
+        } else {
+            return 0;
+        }
+    }
     default:
         return SDL_SetError("Unknown OpenGL attribute");
     }
diff --git a/src/video/windows/SDL_windowsopengl.c b/src/video/windows/SDL_windowsopengl.c
index c458796044927..a2d80e7265381 100644
--- a/src/video/windows/SDL_windowsopengl.c
+++ b/src/video/windows/SDL_windowsopengl.c
@@ -510,6 +510,10 @@ void WIN_GL_InitExtensions(SDL_VideoDevice *_this)
         _this->gl_data->HAS_WGL_ARB_create_context_no_error = true;
     }
 
+    /* Check for WGL_ARB_pixel_format_float */
+    _this->gl_data->HAS_WGL_ARB_pixel_format_float =
+        HasExtension("WGL_ARB_pixel_format_float", extensions);
+
     _this->gl_data->wglMakeCurrent(hdc, NULL);
     _this->gl_data->wglDeleteContext(hglrc);
     ReleaseDC(hwnd, hdc);
@@ -640,7 +644,7 @@ static bool WIN_GL_SetupWindowInternal(SDL_VideoDevice *_this, SDL_Window *windo
         *iAttr++ = _this->gl_config.multisamplesamples;
     }
 
-    if (_this->gl_config.floatbuffers) {
+    if (_this->gl_data->HAS_WGL_ARB_pixel_format_float && _this->gl_config.floatbuffers) {
         *iAttr++ = WGL_PIXEL_TYPE_ARB;
         *iAttr++ = WGL_TYPE_RGBA_FLOAT_ARB;
     }
@@ -825,6 +829,9 @@ SDL_GLContext WIN_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
         return NULL;
     }
 
+    _this->gl_config.HAS_GL_ARB_color_buffer_float =
+        SDL_GL_ExtensionSupported("GL_ARB_color_buffer_float");
+
     return (SDL_GLContext)context;
 }
 
diff --git a/src/video/windows/SDL_windowsopengl.h b/src/video/windows/SDL_windowsopengl.h
index 23e2f3a58f890..a4359611c2bde 100644
--- a/src/video/windows/SDL_windowsopengl.h
+++ b/src/video/windows/SDL_windowsopengl.h
@@ -64,6 +64,7 @@ struct SDL_GLDriverData
     bool HAS_WGL_ARB_context_flush_control;
     bool HAS_WGL_ARB_create_context_robustness;
     bool HAS_WGL_ARB_create_context_no_error;
+    bool HAS_WGL_ARB_pixel_format_float;
 
     /* Max version of OpenGL ES context that can be created if the
        implementation supports WGL_EXT_create_context_es2_profile.