gdk: Add support for building with OpenGL on Xbox
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
diff --git a/include/SDL_config_xbox.h b/include/SDL_config_xbox.h
index 54fa1a4..858f273 100644
--- a/include/SDL_config_xbox.h
+++ b/include/SDL_config_xbox.h
@@ -209,16 +209,21 @@
#define SDL_VIDEO_DRIVER_DUMMY 1
#define SDL_VIDEO_DRIVER_WINDOWS 1
-/* #ifndef SDL_VIDEO_RENDER_D3D
-#define SDL_VIDEO_RENDER_D3D 1
-#endif*/
-#if !defined(SDL_VIDEO_RENDER_D3D11) && defined(HAVE_D3D11_H)
-#define SDL_VIDEO_RENDER_D3D11 1
-#endif
#if !defined(SDL_VIDEO_RENDER_D3D12) && defined(HAVE_D3D12_H)
#define SDL_VIDEO_RENDER_D3D12 1
#endif
+/* Enable OpenGL support */
+#ifndef SDL_VIDEO_OPENGL
+#define SDL_VIDEO_OPENGL 1
+#endif
+#ifndef SDL_VIDEO_OPENGL_WGL
+#define SDL_VIDEO_OPENGL_WGL 1
+#endif
+#ifndef SDL_VIDEO_RENDER_OGL
+#define SDL_VIDEO_RENDER_OGL 1
+#endif
+
/* Enable system power support */
/*#define SDL_POWER_WINDOWS 1*/
#define SDL_POWER_HARDWIRED 1
diff --git a/src/video/windows/SDL_windowsopengl.c b/src/video/windows/SDL_windowsopengl.c
index dfed375..5dd046d 100644
--- a/src/video/windows/SDL_windowsopengl.c
+++ b/src/video/windows/SDL_windowsopengl.c
@@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
-#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
+#if SDL_VIDEO_DRIVER_WINDOWS
#include "SDL_loadso.h"
#include "SDL_windowsvideo.h"
@@ -97,6 +97,16 @@ typedef HGLRC(APIENTRYP PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC hDC,
const int
*attribList);
+#if __XBOXONE__ || __XBOXSERIES__
+#define GetDC(hwnd) (HDC) hwnd
+#define ReleaseDC(hwnd, hdc) 1
+#define SwapBuffers _this->gl_data->wglSwapBuffers
+#define DescribePixelFormat _this->gl_data->wglDescribePixelFormat
+#define ChoosePixelFormat _this->gl_data->wglChoosePixelFormat
+#define GetPixelFormat _this->gl_data->wglGetPixelFormat
+#define SetPixelFormat _this->gl_data->wglSetPixelFormat
+#endif
+
int WIN_GL_LoadLibrary(_THIS, const char *path)
{
void *handle;
@@ -135,10 +145,31 @@ int WIN_GL_LoadLibrary(_THIS, const char *path)
SDL_LoadFunction(handle, "wglShareLists");
/* *INDENT-ON* */ /* clang-format on */
+#if __XBOXONE__ || __XBOXSERIES__
+ _this->gl_data->wglSwapBuffers = (BOOL(WINAPI *)(HDC))
+ SDL_LoadFunction(handle, "wglSwapBuffers");
+ _this->gl_data->wglDescribePixelFormat = (int(WINAPI *)(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR))
+ SDL_LoadFunction(handle, "wglDescribePixelFormat");
+ _this->gl_data->wglChoosePixelFormat = (int(WINAPI *)(HDC, const PIXELFORMATDESCRIPTOR *))
+ SDL_LoadFunction(handle, "wglChoosePixelFormat");
+ _this->gl_data->wglSetPixelFormat = (BOOL(WINAPI *)(HDC, int, const PIXELFORMATDESCRIPTOR *))
+ SDL_LoadFunction(handle, "wglSetPixelFormat");
+ _this->gl_data->wglGetPixelFormat = (int(WINAPI *)(HDC hdc))
+ SDL_LoadFunction(handle, "wglGetPixelFormat");
+#endif
+
if (!_this->gl_data->wglGetProcAddress ||
!_this->gl_data->wglCreateContext ||
!_this->gl_data->wglDeleteContext ||
- !_this->gl_data->wglMakeCurrent) {
+ !_this->gl_data->wglMakeCurrent
+#if __XBOXONE__ || __XBOXSERIES__
+ || !_this->gl_data->wglSwapBuffers ||
+ !_this->gl_data->wglDescribePixelFormat ||
+ !_this->gl_data->wglChoosePixelFormat ||
+ !_this->gl_data->wglGetPixelFormat ||
+ !_this->gl_data->wglSetPixelFormat
+#endif
+ ) {
return SDL_SetError("Could not retrieve OpenGL functions");
}
diff --git a/src/video/windows/SDL_windowsopengl.h b/src/video/windows/SDL_windowsopengl.h
index ca1d62f..f70ae14 100644
--- a/src/video/windows/SDL_windowsopengl.h
+++ b/src/video/windows/SDL_windowsopengl.h
@@ -25,6 +25,38 @@
#if SDL_VIDEO_OPENGL_WGL
+#if __XBOXONE__ || __XBOXSERIES__
+typedef struct tagPIXELFORMATDESCRIPTOR
+{
+ WORD nSize;
+ WORD nVersion;
+ DWORD dwFlags;
+ BYTE iPixelType;
+ BYTE cColorBits;
+ BYTE cRedBits;
+ BYTE cRedShift;
+ BYTE cGreenBits;
+ BYTE cGreenShift;
+ BYTE cBlueBits;
+ BYTE cBlueShift;
+ BYTE cAlphaBits;
+ BYTE cAlphaShift;
+ BYTE cAccumBits;
+ BYTE cAccumRedBits;
+ BYTE cAccumGreenBits;
+ BYTE cAccumBlueBits;
+ BYTE cAccumAlphaBits;
+ BYTE cDepthBits;
+ BYTE cStencilBits;
+ BYTE cAuxBuffers;
+ BYTE iLayerType;
+ BYTE bReserved;
+ DWORD dwLayerMask;
+ DWORD dwVisibleMask;
+ DWORD dwDamageMask;
+} PIXELFORMATDESCRIPTOR, *PPIXELFORMATDESCRIPTOR, *LPPIXELFORMATDESCRIPTOR;
+#endif
+
struct SDL_GLDriverData
{
SDL_bool HAS_WGL_ARB_pixel_format;
@@ -53,6 +85,19 @@ struct SDL_GLDriverData
BOOL (WINAPI *wglGetPixelFormatAttribivARB)(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
BOOL (WINAPI *wglSwapIntervalEXT)(int interval);
int (WINAPI *wglGetSwapIntervalEXT)(void);
+#if __XBOXONE__ || __XBOXSERIES__
+ BOOL (WINAPI *wglSwapBuffers)(HDC hdc);
+ int (WINAPI *wglDescribePixelFormat)(HDC hdc,
+ int iPixelFormat,
+ UINT nBytes,
+ LPPIXELFORMATDESCRIPTOR ppfd);
+ int (WINAPI *wglChoosePixelFormat)(HDC hdc,
+ const PIXELFORMATDESCRIPTOR *ppfd);
+ BOOL (WINAPI *wglSetPixelFormat)(HDC hdc,
+ int format,
+ const PIXELFORMATDESCRIPTOR *ppfd);
+ int (WINAPI *wglGetPixelFormat)(HDC hdc);
+#endif
/* *INDENT-ON* */ /* clang-format on */
};
diff --git a/src/video/windows/SDL_windowsvideo.h b/src/video/windows/SDL_windowsvideo.h
index c49b0bb..59d53f4 100644
--- a/src/video/windows/SDL_windowsvideo.h
+++ b/src/video/windows/SDL_windowsvideo.h
@@ -41,12 +41,12 @@
#include "SDL_windowsclipboard.h"
#include "SDL_windowsevents.h"
+#include "SDL_windowsopengl.h"
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
#include "SDL_windowskeyboard.h"
#include "SDL_windowsmodes.h"
#include "SDL_windowsmouse.h"
-#include "SDL_windowsopengl.h"
#include "SDL_windowsopengles.h"
#endif
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index ab30713..5e0b57b 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -306,7 +306,9 @@ static int SetupWindowData(_THIS, SDL_Window *window, HWND hwnd, HWND parent, SD
data->window = window;
data->hwnd = hwnd;
data->parent = parent;
-#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
+#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
+ data->hdc = (HDC) data->hwnd;
+#else
data->hdc = GetDC(hwnd);
#endif
data->hinstance = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);