mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-22 12:11:25 +00:00
- set up dynamic opengl load for windows
This commit is contained in:
parent
6ef8118b80
commit
5a0c84dd2d
4 changed files with 65 additions and 16 deletions
|
@ -101,7 +101,6 @@ if( WIN32 )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set( ZDOOM_LIBS
|
set( ZDOOM_LIBS
|
||||||
opengl32
|
|
||||||
wsock32
|
wsock32
|
||||||
winmm
|
winmm
|
||||||
"${DX_dinput8_LIBRARY}"
|
"${DX_dinput8_LIBRARY}"
|
||||||
|
|
|
@ -52,6 +52,8 @@
|
||||||
|
|
||||||
extern HWND Window;
|
extern HWND Window;
|
||||||
|
|
||||||
|
extern "C" PROC zd_wglGetProcAddress(LPCSTR name);
|
||||||
|
|
||||||
PFNWGLSWAPINTERVALEXTPROC myWglSwapIntervalExtProc;
|
PFNWGLSWAPINTERVALEXTPROC myWglSwapIntervalExtProc;
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -78,15 +80,15 @@ SystemGLFrameBuffer::SystemGLFrameBuffer(void *hMonitor, bool fullscreen) : Syst
|
||||||
HDC hDC = GetDC(Window);
|
HDC hDC = GetDC(Window);
|
||||||
const char *wglext = nullptr;
|
const char *wglext = nullptr;
|
||||||
|
|
||||||
myWglSwapIntervalExtProc = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
|
myWglSwapIntervalExtProc = (PFNWGLSWAPINTERVALEXTPROC)zd_wglGetProcAddress("wglSwapIntervalEXT");
|
||||||
auto myWglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
|
auto myWglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)zd_wglGetProcAddress("wglGetExtensionsStringARB");
|
||||||
if (myWglGetExtensionsStringARB)
|
if (myWglGetExtensionsStringARB)
|
||||||
{
|
{
|
||||||
wglext = myWglGetExtensionsStringARB(hDC);
|
wglext = myWglGetExtensionsStringARB(hDC);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto myWglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)wglGetProcAddress("wglGetExtensionsStringEXT");
|
auto myWglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)zd_wglGetProcAddress("wglGetExtensionsStringEXT");
|
||||||
if (myWglGetExtensionsStringEXT)
|
if (myWglGetExtensionsStringEXT)
|
||||||
{
|
{
|
||||||
wglext = myWglGetExtensionsStringEXT();
|
wglext = myWglGetExtensionsStringEXT();
|
||||||
|
|
|
@ -55,6 +55,13 @@
|
||||||
|
|
||||||
#include "gl_framebuffer.h"
|
#include "gl_framebuffer.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
HGLRC zd_wglCreateContext(HDC Arg1);
|
||||||
|
BOOL zd_wglDeleteContext(HGLRC Arg1);
|
||||||
|
BOOL zd_wglMakeCurrent(HDC Arg1, HGLRC Arg2);
|
||||||
|
PROC zd_wglGetProcAddress(LPCSTR name);
|
||||||
|
}
|
||||||
|
|
||||||
EXTERN_CVAR(Int, vid_adapter)
|
EXTERN_CVAR(Int, vid_adapter)
|
||||||
EXTERN_CVAR(Bool, vid_hdr)
|
EXTERN_CVAR(Bool, vid_hdr)
|
||||||
|
|
||||||
|
@ -74,7 +81,7 @@ CUSTOM_CVAR(Bool, vr_enable_quadbuffered, false, CVAR_ARCHIVE | CVAR_GLOBALCONFI
|
||||||
extern bool vid_hdr_active;
|
extern bool vid_hdr_active;
|
||||||
|
|
||||||
// these get used before GLEW is initialized so we have to use separate pointers with different names
|
// these get used before GLEW is initialized so we have to use separate pointers with different names
|
||||||
PFNWGLCHOOSEPIXELFORMATARBPROC myWglChoosePixelFormatARB; // = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
|
PFNWGLCHOOSEPIXELFORMATARBPROC myWglChoosePixelFormatARB; // = (PFNWGLCHOOSEPIXELFORMATARBPROC)zd_wglGetProcAddress("wglChoosePixelFormatARB");
|
||||||
PFNWGLCREATECONTEXTATTRIBSARBPROC myWglCreateContextAttribsARB;
|
PFNWGLCREATECONTEXTATTRIBSARBPROC myWglCreateContextAttribsARB;
|
||||||
|
|
||||||
|
|
||||||
|
@ -224,15 +231,15 @@ bool Win32GLVideo::SetPixelFormat()
|
||||||
|
|
||||||
::SetPixelFormat(hDC, pixelFormat, &pfd);
|
::SetPixelFormat(hDC, pixelFormat, &pfd);
|
||||||
|
|
||||||
hRC = wglCreateContext(hDC);
|
hRC = zd_wglCreateContext(hDC);
|
||||||
wglMakeCurrent(hDC, hRC);
|
zd_wglMakeCurrent(hDC, hRC);
|
||||||
|
|
||||||
myWglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
|
myWglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)zd_wglGetProcAddress("wglChoosePixelFormatARB");
|
||||||
myWglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
|
myWglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)zd_wglGetProcAddress("wglCreateContextAttribsARB");
|
||||||
// any extra stuff here?
|
// any extra stuff here?
|
||||||
|
|
||||||
wglMakeCurrent(NULL, NULL);
|
zd_wglMakeCurrent(NULL, NULL);
|
||||||
wglDeleteContext(hRC);
|
zd_wglDeleteContext(hRC);
|
||||||
ReleaseDC(dummy, hDC);
|
ReleaseDC(dummy, hDC);
|
||||||
ShutdownDummy(dummy);
|
ShutdownDummy(dummy);
|
||||||
|
|
||||||
|
@ -436,7 +443,7 @@ bool Win32GLVideo::InitHardware(HWND Window, int multisample)
|
||||||
|
|
||||||
if (m_hRC == NULL && prof == WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB)
|
if (m_hRC == NULL && prof == WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB)
|
||||||
{
|
{
|
||||||
m_hRC = wglCreateContext(m_hDC);
|
m_hRC = zd_wglCreateContext(m_hDC);
|
||||||
if (m_hRC == NULL)
|
if (m_hRC == NULL)
|
||||||
{
|
{
|
||||||
I_Error("R_OPENGL: Unable to create an OpenGL render context.\n");
|
I_Error("R_OPENGL: Unable to create an OpenGL render context.\n");
|
||||||
|
@ -446,7 +453,7 @@ bool Win32GLVideo::InitHardware(HWND Window, int multisample)
|
||||||
|
|
||||||
if (m_hRC != NULL)
|
if (m_hRC != NULL)
|
||||||
{
|
{
|
||||||
wglMakeCurrent(m_hDC, m_hRC);
|
zd_wglMakeCurrent(m_hDC, m_hRC);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -465,8 +472,8 @@ void Win32GLVideo::Shutdown()
|
||||||
{
|
{
|
||||||
if (m_hRC)
|
if (m_hRC)
|
||||||
{
|
{
|
||||||
wglMakeCurrent(0, 0);
|
zd_wglMakeCurrent(0, 0);
|
||||||
wglDeleteContext(m_hRC);
|
zd_wglDeleteContext(m_hRC);
|
||||||
}
|
}
|
||||||
if (m_hDC) ReleaseDC(m_Window, m_hDC);
|
if (m_hDC) ReleaseDC(m_Window, m_hDC);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,10 +67,51 @@ static int TestPointer(const PROC pTest)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static HMODULE opengl32dll;
|
||||||
|
static HGLRC(WINAPI* createcontext)(HDC);
|
||||||
|
static BOOL(WINAPI* deletecontext)(HGLRC);
|
||||||
|
static BOOL(WINAPI* makecurrent)(HDC, HGLRC);
|
||||||
|
static PROC(WINAPI* getprocaddress)(LPCSTR name);
|
||||||
|
static void CheckOpenGL(void)
|
||||||
|
{
|
||||||
|
if (opengl32dll == 0)
|
||||||
|
{
|
||||||
|
opengl32dll = LoadLibrary(L"OpenGL32.DLL");
|
||||||
|
createcontext = (HGLRC(WINAPI*)(HDC)) GetProcAddress(opengl32dll, "wglCreateContext");
|
||||||
|
deletecontext = (BOOL(WINAPI*)(HGLRC)) GetProcAddress(opengl32dll, "wglDeleteContext");
|
||||||
|
makecurrent = (BOOL(WINAPI*)(HDC, HGLRC)) GetProcAddress(opengl32dll, "wglMakeCurrent");
|
||||||
|
getprocaddress = (PROC(WINAPI*)(LPCSTR)) GetProcAddress(opengl32dll, "wglGetProcAddress");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HGLRC zd_wglCreateContext(HDC dc)
|
||||||
|
{
|
||||||
|
CheckOpenGL();
|
||||||
|
return createcontext(dc);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL zd_wglDeleteContext(HGLRC context)
|
||||||
|
{
|
||||||
|
CheckOpenGL();
|
||||||
|
return deletecontext(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL zd_wglMakeCurrent(HDC dc, HGLRC context)
|
||||||
|
{
|
||||||
|
CheckOpenGL();
|
||||||
|
return makecurrent(dc, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
PROC zd_wglGetProcAddress(LPCSTR name)
|
||||||
|
{
|
||||||
|
CheckOpenGL();
|
||||||
|
return getprocaddress(name);
|
||||||
|
}
|
||||||
|
|
||||||
static PROC WinGetProcAddress(const char *name)
|
static PROC WinGetProcAddress(const char *name)
|
||||||
{
|
{
|
||||||
HMODULE glMod = NULL;
|
HMODULE glMod = NULL;
|
||||||
PROC pFunc = wglGetProcAddress((LPCSTR)name);
|
PROC pFunc = zd_wglGetProcAddress((LPCSTR)name);
|
||||||
if(TestPointer(pFunc))
|
if(TestPointer(pFunc))
|
||||||
{
|
{
|
||||||
return pFunc;
|
return pFunc;
|
||||||
|
|
Loading…
Reference in a new issue