Skip to content

Commit

Permalink
Support modern WGL context creation
Browse files Browse the repository at this point in the history
* removed WGL extensions from glimpl
  • Loading branch information
dmaivel committed Jul 15, 2024
1 parent 9f79171 commit 5354488
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 18 deletions.
12 changes: 3 additions & 9 deletions src/client/glimpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct gl_map_buffer glimpl_map_buffer;

float glimpl_global_matrix_double_to_float[GLIMPL_MAX_COUNT_FOR_MATRIX_OP];

#define NUM_EXTENSIONS 81
#define NUM_EXTENSIONS 78
static const char *glimpl_extensions_full = "GL_ARB_ES2_compatibility "
"GL_ARB_ES3_compatibility "
"GL_ARB_color_buffer_float "
Expand Down Expand Up @@ -218,10 +218,7 @@ static const char *glimpl_extensions_full = "GL_ARB_ES2_compatibility "
"GL_EXT_texture_filter_anisotropic "
"GL_EXT_texture_sRGB "
"GL_EXT_texture_sRGB_decode "
"GL_NV_texture_barrier "
"WGL_ARB_extensions_string "
"WGL_ARB_framebuffer_sRGB "
"WGL_ARB_pixel_format";
"GL_NV_texture_barrier ";

static const char glimpl_extensions_list[NUM_EXTENSIONS][48] = {
"GL_ARB_ES2_compatibility",
Expand Down Expand Up @@ -301,10 +298,7 @@ static const char glimpl_extensions_list[NUM_EXTENSIONS][48] = {
"GL_EXT_texture_filter_anisotropic",
"GL_EXT_texture_sRGB",
"GL_EXT_texture_sRGB_decode",
"GL_NV_texture_barrier",
"WGL_ARB_extensions_string",
"WGL_ARB_framebuffer_sRGB",
"WGL_ARB_pixel_format",
"GL_NV_texture_barrier"
};

/* fake variables to be used with network feature only */
Expand Down
70 changes: 61 additions & 9 deletions src/client/platform/windrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <client/platform/windrv.h>
#include <client/platform/icd.h>

#include <stdlib.h>
#include <stdbool.h>

static PIXELFORMATDESCRIPTOR pfd_table[64] = { 0 };
Expand All @@ -21,6 +22,12 @@ ICD_RESIZE_DEFINITION(real_width, real_height);
#define MIN_INTERNAL( A, B ) ( (A)<(B) ? (A) : (B) )
#define MAX_INTERNAL( A, B ) ( (A)>(B) ? (A) : (B) )

typedef HGLRC(WINAPI * wglCreateContext_t )(HDC);
typedef BOOL(WINAPI * wglDeleteContext_t )(HGLRC);

static wglCreateContext_t g_pfnwglCreateContext = NULL;
static wglDeleteContext_t g_pfnwglDeleteContext = NULL;

struct pfd_color_info {
int rbits, gbits, bbits, abits;
int rshift, gshift, bshift, ashift;
Expand All @@ -44,6 +51,11 @@ static struct pfd_depth_info pfd_depths[4] = {
{ 24, 8 }
};

struct wgl_extension_entry {
const char *name;
PROC proc;
};

static HMODULE module_handle = 0;
static BOOL do_vflip = TRUE;

Expand All @@ -57,7 +69,24 @@ void windrv_set_vflip(BOOL flip)
do_vflip = flip;
}

static const char *wgl_extensions = "WGL_ARB_create_context WGL_ARB_create_context_profile WGL_ARB_extensions_string WGL_ARB_pixel_format";
// removed WGL_ARB_pixel_format
static const char *wgl_extensions = "WGL_ARB_create_context WGL_ARB_create_context_profile WGL_ARB_extensions_string WGL_ARB_framebuffer_sRGB";

static HGLRC wgl_create_context(HDC hdc)
{
if (g_pfnwglCreateContext == NULL)
g_pfnwglCreateContext = (wglCreateContext_t)GetProcAddress(GetModuleHandleA("opengl32.dll"), "wglCreateContext");

return g_pfnwglCreateContext(hdc);
}

static BOOL wgl_delete_context(HGLRC hglrc)
{
if (g_pfnwglDeleteContext == NULL)
g_pfnwglDeleteContext = (wglDeleteContext_t)GetProcAddress(GetModuleHandleA("opengl32.dll"), "wglDeleteContext");

return g_pfnwglDeleteContext(hglrc);
}

const char* wglGetExtensionsStringARB(HDC hdc)
{
Expand All @@ -66,7 +95,7 @@ const char* wglGetExtensionsStringARB(HDC hdc)

HGLRC wglCreateContextAttribsARB(HDC hDC, HGLRC hShareContext, const int *attribList)
{
return (HGLRC)1;
return wgl_create_context(hDC);
}

BOOL wglGetPixelFormatAttribivARB(HDC hdc,
Expand Down Expand Up @@ -101,6 +130,24 @@ BOOL wglChoosePixelFormatARB(HDC hdc,
return TRUE;
}

#define WGL_EXTENSION_ENTRY(P) { #P, (PROC) P }

static const struct wgl_extension_entry wgl_extension_entries[] = {

/* WGL_ARB_extensions_string */
WGL_EXTENSION_ENTRY( wglGetExtensionsStringARB ),

/* WGL_ARB_pixel_format */
// WGL_EXTENSION_ENTRY( wglChoosePixelFormatARB ),
// WGL_EXTENSION_ENTRY( wglGetPixelFormatAttribfvARB ),
// WGL_EXTENSION_ENTRY( wglGetPixelFormatAttribivARB ),

/* WGL_ARB_create_context */
WGL_EXTENSION_ENTRY( wglCreateContextAttribsARB ),

{ NULL, NULL }
};

static void pfd_add(
bool doublebuffer, bool gdi, unsigned int accum,
int rbits, int gbits, int bbits, int abits,
Expand Down Expand Up @@ -187,7 +234,7 @@ DHGLRC APIENTRY DrvCreateLayerContext(HDC hdc, INT iLayerPlane)

BOOL APIENTRY DrvDeleteContext(DHGLRC dhglrc)
{
return TRUE;
return wgl_delete_context(dhglrc);
}

BOOL APIENTRY DrvCopyContext(DHGLRC dhrcSource, DHGLRC dhrcDest, UINT fuMask)
Expand Down Expand Up @@ -217,14 +264,14 @@ BOOL APIENTRY DrvShareLists(DHGLRC dhglrc1, DHGLRC dhglrc2)

PROC APIENTRY DrvGetProcAddress(LPCSTR lpszProc)
{
/*
* WGL extensions, GL functions
* a table for WGL extensions makes sense, but we export every function so a table isn't needed
* commented out || (lpszProc[0] == 'w' && lpszProc[1] == 'g' && lpszProc[2] == 'l'), some apps dont like that part
*/
if ((lpszProc[0] == 'g' && lpszProc[1] == 'l'))
if (lpszProc[0] == 'g' && lpszProc[1] == 'l')
return GetProcAddress(module_handle, lpszProc);

if (lpszProc[0] == 'w' && lpszProc[1] == 'g' && lpszProc[2] == 'l')
for (struct wgl_extension_entry *entry = wgl_extension_entries; entry->name; entry++)
if (strcmp(lpszProc, entry->name) == 0)
return entry->proc;

return NULL;
}

Expand Down Expand Up @@ -325,4 +372,9 @@ BOOL APIENTRY DrvSetPixelFormat(HDC hdc, LONG iPixelFormat)
return TRUE;
}

// BOOL APIENTRY DrvMakeCurrent(HDC hDC, HGLRC hRC)
// {
// return TRUE;
// }

#endif

0 comments on commit 5354488

Please sign in to comment.