Skip to content

Commit

Permalink
Fix Windows ICD, applications above 1.1 run now
Browse files Browse the repository at this point in the history
* add windrv.h, WinDrvSetModuleAddress to get actual proc address

* added wglGetExtensionsStringARB, wglCreateContextAttribsARB

* added wglGetPixelFormatAttribivARB/fvARB, wglChoosePixelFormatARB
  • Loading branch information
dmaivel committed Jun 9, 2024
1 parent 9dc11ca commit b1dd75e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 8 deletions.
8 changes: 8 additions & 0 deletions inc/client/platform/windrv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifdef _WIN32
#ifndef _WINDRV_H_
#define _WINDRV_H_

void WinDrvSetModuleAddress(HMODULE module);

#endif
#endif
63 changes: 57 additions & 6 deletions src/client/platform/windrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <windows.h>
#include <client/glimpl.h>
#include <client/platform/gldrv.h>
#include <client/platform/windrv.h>

#include <stdbool.h>

Expand Down Expand Up @@ -42,6 +43,57 @@ static struct pfd_depth_info pfd_depths[4] = {
{ 24, 8 }
};

static HMODULE g_hModule = 0;

void WinDrvSetModuleAddress(HMODULE module)
{
g_hModule = module;
}

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

const char* wglGetExtensionsStringARB(HDC hdc)
{
return wgl_extensions;
}

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

BOOL wglGetPixelFormatAttribivARB(HDC hdc,
int iPixelFormat,
int iLayerPlane,
UINT nAttributes,
const int *piAttributes,
int *piValues)
{
return TRUE;
}

BOOL wglGetPixelFormatAttribfvARB(HDC hdc,
int iPixelFormat,
int iLayerPlane,
UINT nAttributes,
const int *piAttributes,
FLOAT *pfValues)
{
return TRUE;
}

BOOL wglChoosePixelFormatARB(HDC hdc,
const int *piAttribIList,
const FLOAT *pfAttribFList,
UINT nMaxFormats,
int *piFormats,
UINT *nNumFormats)
{
*piFormats = 1;
*nNumFormats = 1;
return TRUE;
}

static void pfdAdd(
bool doublebuffer, bool gdi, unsigned int accum,
int rbits, int gbits, int bbits, int abits,
Expand Down Expand Up @@ -168,13 +220,12 @@ BOOL APIENTRY DrvShareLists(DHGLRC dhglrc1, DHGLRC dhglrc2)
PROC APIENTRY DrvGetProcAddress(LPCSTR lpszProc)
{
/*
* WGL Extensions
* 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] == 'w' && lpszProc[1] == 'g' && lpszProc[2] == 'l')
return NULL;

if (lpszProc[0] == 'g' && lpszProc[1] == 'l')
return GetProcAddress(GetModuleHandleW(NULL), lpszProc);
if ((lpszProc[0] == 'g' && lpszProc[1] == 'l'))
return GetProcAddress(g_hModule, lpszProc);

return NULL;
}
Expand Down
6 changes: 4 additions & 2 deletions src/client/winmain.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifdef _WIN32 /* globbed */

#include <windows.h>
#include <client/platform/wgl.h>
#include <client/platform/windrv.h>
#include <client/glimpl.h>

VOID Main()
Expand All @@ -14,8 +14,10 @@ VOID Main()

BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved)
{
if (reason == DLL_PROCESS_ATTACH)
if (reason == DLL_PROCESS_ATTACH) {
WinDrvSetModuleAddress(module);
Main();
}
if (reason == DLL_PROCESS_DETACH)
glimpl_goodbye();

Expand Down

0 comments on commit b1dd75e

Please sign in to comment.