From 9ca3a2248705c46a8f2371d446caa73b2b0d3352 Mon Sep 17 00:00:00 2001 From: Roderick Colenbrander Date: Thu, 16 Aug 2007 15:04:47 +0200 Subject: [PATCH] wined3d: Dynamically load WGL functions. --- dlls/wined3d/context.c | 22 ++++++------ dlls/wined3d/directx.c | 73 +++++++++++++++++++-------------------- include/wine/wined3d_gl.h | 18 ++++++++++ 3 files changed, 65 insertions(+), 48 deletions(-) diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index 0727aee3b24..25078353e23 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -266,8 +266,8 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar } } - ctx = wglCreateContext(hdc); - if(This->numContexts) wglShareLists(This->contexts[0]->glCtx, ctx); + ctx = pwglCreateContext(hdc); + if(This->numContexts) pwglShareLists(This->contexts[0]->glCtx, ctx); if(!ctx) { ERR("Failed to create a WGL context\n"); @@ -280,7 +280,7 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar ret = AddContextToArray(This, win_handle, hdc, ctx, pbuffer); if(!ret) { ERR("Failed to add the newly created context to the context list\n"); - wglDeleteContext(ctx); + pwglDeleteContext(ctx); if(create_pbuffer) { GL_EXTCALL(wglReleasePbufferDCARB(pbuffer, hdc)); GL_EXTCALL(wglDestroyPbufferARB(pbuffer)); @@ -294,9 +294,9 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar TRACE("Successfully created new context %p\n", ret); /* Set up the context defaults */ - oldCtx = wglGetCurrentContext(); - oldDrawable = wglGetCurrentDC(); - if(wglMakeCurrent(hdc, ctx) == FALSE) { + oldCtx = pwglGetCurrentContext(); + oldDrawable = pwglGetCurrentDC(); + if(pwglMakeCurrent(hdc, ctx) == FALSE) { ERR("Cannot activate context to set up defaults\n"); goto out; } @@ -368,7 +368,7 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar } if(oldDrawable && oldCtx) { - wglMakeCurrent(oldDrawable, oldCtx); + pwglMakeCurrent(oldDrawable, oldCtx); } out: @@ -430,15 +430,15 @@ void DestroyContext(IWineD3DDeviceImpl *This, WineD3DContext *context) { /* check that we are the current context first */ TRACE("Destroying ctx %p\n", context); - if(wglGetCurrentContext() == context->glCtx){ - wglMakeCurrent(NULL, NULL); + if(pwglGetCurrentContext() == context->glCtx){ + pwglMakeCurrent(NULL, NULL); } if(context->isPBuffer) { GL_EXTCALL(wglReleasePbufferDCARB(context->pbuffer, context->hdc)); GL_EXTCALL(wglDestroyPbufferARB(context->pbuffer)); } else ReleaseDC(context->win_handle, context->hdc); - wglDeleteContext(context->glCtx); + pwglDeleteContext(context->glCtx); RemoveContextFromArray(This, context); } @@ -831,7 +831,7 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU BOOL ret; TRACE("Switching gl ctx to %p, hdc=%p ctx=%p\n", context, context->hdc, context->glCtx); LEAVE_GL(); - ret = wglMakeCurrent(context->hdc, context->glCtx); + ret = pwglMakeCurrent(context->hdc, context->glCtx); ENTER_GL(); if(ret == FALSE) { ERR("Failed to activate the new context\n"); diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index b294004960d..e9b2acada7d 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -168,14 +168,14 @@ static void WineD3D_ReleaseFakeGLContext(void) { return; } - glCtx = wglGetCurrentContext(); + glCtx = pwglGetCurrentContext(); TRACE_(d3d_caps)("decrementing ref from %i\n", wined3d_fake_gl_context_ref); if (0 == (--wined3d_fake_gl_context_ref) ) { if(!wined3d_fake_gl_context_foreign && glCtx) { TRACE_(d3d_caps)("destroying fake GL context\n"); - wglMakeCurrent(NULL, NULL); - wglDeleteContext(glCtx); + pwglMakeCurrent(NULL, NULL); + pwglDeleteContext(glCtx); } if(wined3d_fake_gl_context_hdc) ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc); @@ -203,7 +203,7 @@ static BOOL WineD3D_CreateFakeGLContext(void) { wined3d_fake_gl_context_foreign = TRUE; - glCtx = wglGetCurrentContext(); + glCtx = pwglGetCurrentContext(); if (!glCtx) { PIXELFORMATDESCRIPTOR pfd; int iPixelFormat; @@ -241,14 +241,14 @@ static BOOL WineD3D_CreateFakeGLContext(void) { SetPixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, &pfd); /* Create a GL context */ - glCtx = wglCreateContext(wined3d_fake_gl_context_hdc); + glCtx = pwglCreateContext(wined3d_fake_gl_context_hdc); if (!glCtx) { WARN_(d3d_caps)("Error creating default context for capabilities initialization\n"); goto fail; } /* Make it the current GL context */ - if (!wglMakeCurrent(wined3d_fake_gl_context_hdc, glCtx)) { + if (!pwglMakeCurrent(wined3d_fake_gl_context_hdc, glCtx)) { WARN_(d3d_caps)("Error setting default context as current for capabilities initialization\n"); goto fail; } @@ -267,7 +267,7 @@ static BOOL WineD3D_CreateFakeGLContext(void) { if(wined3d_fake_gl_context_hwnd) DestroyWindow(wined3d_fake_gl_context_hwnd); wined3d_fake_gl_context_hwnd = NULL; - if(glCtx) wglDeleteContext(glCtx); + if(glCtx) pwglDeleteContext(glCtx); LeaveCriticalSection(&wined3d_fake_gl_context_cs); LEAVE_GL(); return FALSE; @@ -404,7 +404,33 @@ BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) { int i; HDC hdc; HMODULE mod_gl; - PROC (WINAPI *p_wglGetProcAddress)(LPCSTR lpszProc); + +#ifdef USE_WIN32_OPENGL +#define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn); + mod_gl = LoadLibraryA("opengl32.dll"); + if(!mod_gl) { + ERR("Can't load opengl32.dll!\n"); + return FALSE; + } +#else +#define USE_GL_FUNC(pfn) pfn = (void*)pwglGetProcAddress(#pfn); + /* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 (glXGetProcAddress wrapper) instead of opengl32's */ + mod_gl = GetModuleHandleA("gdi32.dll"); +#endif + +/* Load WGL core functions from opengl32.dll */ +#define USE_WGL_FUNC(pfn) p##pfn = (void*)GetProcAddress(mod_gl, #pfn); + WGL_FUNCS_GEN; +#undef USE_WGL_FUNC + + if(!pwglGetProcAddress) { + ERR("Unable to load wglGetProcAddress!\n"); + return FALSE; + } + +/* Dynamicly load all GL core functions */ + GL_FUNCS_GEN; +#undef USE_GL_FUNC /* Make sure that we've got a context */ /* TODO: CreateFakeGLContext should really take a display as a parameter */ @@ -414,33 +440,6 @@ BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) { TRACE_(d3d_caps)("(%p)\n", gl_info); -#ifdef USE_WIN32_OPENGL -#define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, (const char *) #pfn); - mod_gl = LoadLibraryA("opengl32.dll"); - if(!mod_gl) { - ERR("Can't load opengl32.dll!\n"); - return FALSE; - } -#else -#define USE_GL_FUNC(pfn) pfn = (void*)p_wglGetProcAddress( (const char *) #pfn); - /* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 (glXGetProcAddress wrapper) instead of opengl32's */ - mod_gl = LoadLibraryA("gdi32.dll"); - if(!mod_gl) { - ERR("Can't load gdi32.dll!\n"); - return FALSE; - } -#endif - - p_wglGetProcAddress = (void*)GetProcAddress(mod_gl, "wglGetProcAddress"); - if(!p_wglGetProcAddress) { - ERR("Unable to load wglGetProcAddress!\n"); - return FALSE; - } - -/* Dynamicly load all GL core functions */ - GL_FUNCS_GEN; -#undef USE_GL_FUNC - gl_string = (const char *) glGetString(GL_RENDERER); if (NULL == gl_string) gl_string = "None"; @@ -607,7 +606,7 @@ BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) { gl_info->ps_arb_constantsF = 0; /* Now work out what GL support this card really has */ -#define USE_GL_FUNC(type, pfn) gl_info->pfn = (type) p_wglGetProcAddress( (const char *) #pfn); +#define USE_GL_FUNC(type, pfn) gl_info->pfn = (type) pwglGetProcAddress(#pfn); GL_EXT_FUNCS_GEN; WGL_EXT_FUNCS_GEN; #undef USE_GL_FUNC @@ -1009,7 +1008,7 @@ BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) { /* TODO: config lookups */ /* Make sure there's an active HDC else the WGL extensions will fail */ - hdc = wglGetCurrentDC(); + hdc = pwglGetCurrentDC(); if (hdc) { WGL_Extensions = GL_EXTCALL(wglGetExtensionsStringARB(hdc)); TRACE_(d3d_caps)("WGL_Extensions reported:\n"); diff --git a/include/wine/wined3d_gl.h b/include/wine/wined3d_gl.h index b381b1c9a9d..7348b835ba1 100644 --- a/include/wine/wined3d_gl.h +++ b/include/wine/wined3d_gl.h @@ -1138,6 +1138,15 @@ void (WINE_GLAPI *glVertex4sv) (const GLshort* v); void (WINE_GLAPI *glVertexPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid* pointer); void (WINE_GLAPI *glViewport) (GLint x, GLint y, GLsizei width, GLsizei height); +/* WGL functions */ +HGLRC (WINAPI *pwglCreateContext)(HDC); +BOOL (WINAPI *pwglDeleteContext)(HGLRC); +HGLRC (WINAPI *pwglGetCurrentContext)(void); +HDC (WINAPI *pwglGetCurrentDC)(void); +PROC (WINAPI *pwglGetProcAddress)(LPCSTR); +BOOL (WINAPI *pwglMakeCurrent)(HDC,HGLRC); +BOOL (WINAPI *pwglShareLists)(HGLRC,HGLRC); + #define GL_FUNCS_GEN \ USE_GL_FUNC(glAccum) \ USE_GL_FUNC(glAlphaFunc) \ @@ -1476,6 +1485,15 @@ void (WINE_GLAPI *glViewport) (GLint x, GLint y, GLsizei width, GLsizei height); USE_GL_FUNC(glVertexPointer) \ USE_GL_FUNC(glViewport) +#define WGL_FUNCS_GEN \ + USE_WGL_FUNC(wglCreateContext) \ + USE_WGL_FUNC(wglDeleteContext) \ + USE_WGL_FUNC(wglGetCurrentContext) \ + USE_WGL_FUNC(wglGetCurrentDC) \ + USE_WGL_FUNC(wglGetProcAddress) \ + USE_WGL_FUNC(wglMakeCurrent) \ + USE_WGL_FUNC(wglShareLists) + /**************************************************** * OpenGL Extensions (EXT and ARB)