Commit 9ca3a224 authored by Roderick Colenbrander's avatar Roderick Colenbrander Committed by Alexandre Julliard

wined3d: Dynamically load WGL functions.

parent 06cc0fa9
...@@ -266,8 +266,8 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar ...@@ -266,8 +266,8 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
} }
} }
ctx = wglCreateContext(hdc); ctx = pwglCreateContext(hdc);
if(This->numContexts) wglShareLists(This->contexts[0]->glCtx, ctx); if(This->numContexts) pwglShareLists(This->contexts[0]->glCtx, ctx);
if(!ctx) { if(!ctx) {
ERR("Failed to create a WGL context\n"); ERR("Failed to create a WGL context\n");
...@@ -280,7 +280,7 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar ...@@ -280,7 +280,7 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
ret = AddContextToArray(This, win_handle, hdc, ctx, pbuffer); ret = AddContextToArray(This, win_handle, hdc, ctx, pbuffer);
if(!ret) { if(!ret) {
ERR("Failed to add the newly created context to the context list\n"); ERR("Failed to add the newly created context to the context list\n");
wglDeleteContext(ctx); pwglDeleteContext(ctx);
if(create_pbuffer) { if(create_pbuffer) {
GL_EXTCALL(wglReleasePbufferDCARB(pbuffer, hdc)); GL_EXTCALL(wglReleasePbufferDCARB(pbuffer, hdc));
GL_EXTCALL(wglDestroyPbufferARB(pbuffer)); GL_EXTCALL(wglDestroyPbufferARB(pbuffer));
...@@ -294,9 +294,9 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar ...@@ -294,9 +294,9 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
TRACE("Successfully created new context %p\n", ret); TRACE("Successfully created new context %p\n", ret);
/* Set up the context defaults */ /* Set up the context defaults */
oldCtx = wglGetCurrentContext(); oldCtx = pwglGetCurrentContext();
oldDrawable = wglGetCurrentDC(); oldDrawable = pwglGetCurrentDC();
if(wglMakeCurrent(hdc, ctx) == FALSE) { if(pwglMakeCurrent(hdc, ctx) == FALSE) {
ERR("Cannot activate context to set up defaults\n"); ERR("Cannot activate context to set up defaults\n");
goto out; goto out;
} }
...@@ -368,7 +368,7 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar ...@@ -368,7 +368,7 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
} }
if(oldDrawable && oldCtx) { if(oldDrawable && oldCtx) {
wglMakeCurrent(oldDrawable, oldCtx); pwglMakeCurrent(oldDrawable, oldCtx);
} }
out: out:
...@@ -430,15 +430,15 @@ void DestroyContext(IWineD3DDeviceImpl *This, WineD3DContext *context) { ...@@ -430,15 +430,15 @@ void DestroyContext(IWineD3DDeviceImpl *This, WineD3DContext *context) {
/* check that we are the current context first */ /* check that we are the current context first */
TRACE("Destroying ctx %p\n", context); TRACE("Destroying ctx %p\n", context);
if(wglGetCurrentContext() == context->glCtx){ if(pwglGetCurrentContext() == context->glCtx){
wglMakeCurrent(NULL, NULL); pwglMakeCurrent(NULL, NULL);
} }
if(context->isPBuffer) { if(context->isPBuffer) {
GL_EXTCALL(wglReleasePbufferDCARB(context->pbuffer, context->hdc)); GL_EXTCALL(wglReleasePbufferDCARB(context->pbuffer, context->hdc));
GL_EXTCALL(wglDestroyPbufferARB(context->pbuffer)); GL_EXTCALL(wglDestroyPbufferARB(context->pbuffer));
} else ReleaseDC(context->win_handle, context->hdc); } else ReleaseDC(context->win_handle, context->hdc);
wglDeleteContext(context->glCtx); pwglDeleteContext(context->glCtx);
RemoveContextFromArray(This, context); RemoveContextFromArray(This, context);
} }
...@@ -831,7 +831,7 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU ...@@ -831,7 +831,7 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU
BOOL ret; BOOL ret;
TRACE("Switching gl ctx to %p, hdc=%p ctx=%p\n", context, context->hdc, context->glCtx); TRACE("Switching gl ctx to %p, hdc=%p ctx=%p\n", context, context->hdc, context->glCtx);
LEAVE_GL(); LEAVE_GL();
ret = wglMakeCurrent(context->hdc, context->glCtx); ret = pwglMakeCurrent(context->hdc, context->glCtx);
ENTER_GL(); ENTER_GL();
if(ret == FALSE) { if(ret == FALSE) {
ERR("Failed to activate the new context\n"); ERR("Failed to activate the new context\n");
......
...@@ -168,14 +168,14 @@ static void WineD3D_ReleaseFakeGLContext(void) { ...@@ -168,14 +168,14 @@ static void WineD3D_ReleaseFakeGLContext(void) {
return; return;
} }
glCtx = wglGetCurrentContext(); glCtx = pwglGetCurrentContext();
TRACE_(d3d_caps)("decrementing ref from %i\n", wined3d_fake_gl_context_ref); TRACE_(d3d_caps)("decrementing ref from %i\n", wined3d_fake_gl_context_ref);
if (0 == (--wined3d_fake_gl_context_ref) ) { if (0 == (--wined3d_fake_gl_context_ref) ) {
if(!wined3d_fake_gl_context_foreign && glCtx) { if(!wined3d_fake_gl_context_foreign && glCtx) {
TRACE_(d3d_caps)("destroying fake GL context\n"); TRACE_(d3d_caps)("destroying fake GL context\n");
wglMakeCurrent(NULL, NULL); pwglMakeCurrent(NULL, NULL);
wglDeleteContext(glCtx); pwglDeleteContext(glCtx);
} }
if(wined3d_fake_gl_context_hdc) if(wined3d_fake_gl_context_hdc)
ReleaseDC(wined3d_fake_gl_context_hwnd, 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) { ...@@ -203,7 +203,7 @@ static BOOL WineD3D_CreateFakeGLContext(void) {
wined3d_fake_gl_context_foreign = TRUE; wined3d_fake_gl_context_foreign = TRUE;
glCtx = wglGetCurrentContext(); glCtx = pwglGetCurrentContext();
if (!glCtx) { if (!glCtx) {
PIXELFORMATDESCRIPTOR pfd; PIXELFORMATDESCRIPTOR pfd;
int iPixelFormat; int iPixelFormat;
...@@ -241,14 +241,14 @@ static BOOL WineD3D_CreateFakeGLContext(void) { ...@@ -241,14 +241,14 @@ static BOOL WineD3D_CreateFakeGLContext(void) {
SetPixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, &pfd); SetPixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, &pfd);
/* Create a GL context */ /* Create a GL context */
glCtx = wglCreateContext(wined3d_fake_gl_context_hdc); glCtx = pwglCreateContext(wined3d_fake_gl_context_hdc);
if (!glCtx) { if (!glCtx) {
WARN_(d3d_caps)("Error creating default context for capabilities initialization\n"); WARN_(d3d_caps)("Error creating default context for capabilities initialization\n");
goto fail; goto fail;
} }
/* Make it the current GL context */ /* 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"); WARN_(d3d_caps)("Error setting default context as current for capabilities initialization\n");
goto fail; goto fail;
} }
...@@ -267,7 +267,7 @@ static BOOL WineD3D_CreateFakeGLContext(void) { ...@@ -267,7 +267,7 @@ static BOOL WineD3D_CreateFakeGLContext(void) {
if(wined3d_fake_gl_context_hwnd) if(wined3d_fake_gl_context_hwnd)
DestroyWindow(wined3d_fake_gl_context_hwnd); DestroyWindow(wined3d_fake_gl_context_hwnd);
wined3d_fake_gl_context_hwnd = NULL; wined3d_fake_gl_context_hwnd = NULL;
if(glCtx) wglDeleteContext(glCtx); if(glCtx) pwglDeleteContext(glCtx);
LeaveCriticalSection(&wined3d_fake_gl_context_cs); LeaveCriticalSection(&wined3d_fake_gl_context_cs);
LEAVE_GL(); LEAVE_GL();
return FALSE; return FALSE;
...@@ -404,35 +404,26 @@ BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) { ...@@ -404,35 +404,26 @@ BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) {
int i; int i;
HDC hdc; HDC hdc;
HMODULE mod_gl; HMODULE mod_gl;
PROC (WINAPI *p_wglGetProcAddress)(LPCSTR lpszProc);
/* Make sure that we've got a context */
/* TODO: CreateFakeGLContext should really take a display as a parameter */
/* Only save the values obtained when a display is provided */
if (!WineD3D_CreateFakeGLContext() || wined3d_fake_gl_context_foreign)
return_value = FALSE;
TRACE_(d3d_caps)("(%p)\n", gl_info);
#ifdef USE_WIN32_OPENGL #ifdef USE_WIN32_OPENGL
#define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, (const char *) #pfn); #define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn);
mod_gl = LoadLibraryA("opengl32.dll"); mod_gl = LoadLibraryA("opengl32.dll");
if(!mod_gl) { if(!mod_gl) {
ERR("Can't load opengl32.dll!\n"); ERR("Can't load opengl32.dll!\n");
return FALSE; return FALSE;
} }
#else #else
#define USE_GL_FUNC(pfn) pfn = (void*)p_wglGetProcAddress( (const char *) #pfn); #define USE_GL_FUNC(pfn) pfn = (void*)pwglGetProcAddress(#pfn);
/* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 (glXGetProcAddress wrapper) instead of opengl32's */ /* To bypass the opengl32 thunks load wglGetProcAddress from gdi32 (glXGetProcAddress wrapper) instead of opengl32's */
mod_gl = LoadLibraryA("gdi32.dll"); mod_gl = GetModuleHandleA("gdi32.dll");
if(!mod_gl) {
ERR("Can't load gdi32.dll!\n");
return FALSE;
}
#endif #endif
p_wglGetProcAddress = (void*)GetProcAddress(mod_gl, "wglGetProcAddress"); /* Load WGL core functions from opengl32.dll */
if(!p_wglGetProcAddress) { #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"); ERR("Unable to load wglGetProcAddress!\n");
return FALSE; return FALSE;
} }
...@@ -441,6 +432,14 @@ BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) { ...@@ -441,6 +432,14 @@ BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) {
GL_FUNCS_GEN; GL_FUNCS_GEN;
#undef USE_GL_FUNC #undef USE_GL_FUNC
/* Make sure that we've got a context */
/* TODO: CreateFakeGLContext should really take a display as a parameter */
/* Only save the values obtained when a display is provided */
if (!WineD3D_CreateFakeGLContext() || wined3d_fake_gl_context_foreign)
return_value = FALSE;
TRACE_(d3d_caps)("(%p)\n", gl_info);
gl_string = (const char *) glGetString(GL_RENDERER); gl_string = (const char *) glGetString(GL_RENDERER);
if (NULL == gl_string) if (NULL == gl_string)
gl_string = "None"; gl_string = "None";
...@@ -607,7 +606,7 @@ BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) { ...@@ -607,7 +606,7 @@ BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) {
gl_info->ps_arb_constantsF = 0; gl_info->ps_arb_constantsF = 0;
/* Now work out what GL support this card really has */ /* 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; GL_EXT_FUNCS_GEN;
WGL_EXT_FUNCS_GEN; WGL_EXT_FUNCS_GEN;
#undef USE_GL_FUNC #undef USE_GL_FUNC
...@@ -1009,7 +1008,7 @@ BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) { ...@@ -1009,7 +1008,7 @@ BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) {
/* TODO: config lookups */ /* TODO: config lookups */
/* Make sure there's an active HDC else the WGL extensions will fail */ /* Make sure there's an active HDC else the WGL extensions will fail */
hdc = wglGetCurrentDC(); hdc = pwglGetCurrentDC();
if (hdc) { if (hdc) {
WGL_Extensions = GL_EXTCALL(wglGetExtensionsStringARB(hdc)); WGL_Extensions = GL_EXTCALL(wglGetExtensionsStringARB(hdc));
TRACE_(d3d_caps)("WGL_Extensions reported:\n"); TRACE_(d3d_caps)("WGL_Extensions reported:\n");
......
...@@ -1138,6 +1138,15 @@ void (WINE_GLAPI *glVertex4sv) (const GLshort* v); ...@@ -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 *glVertexPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid* pointer);
void (WINE_GLAPI *glViewport) (GLint x, GLint y, GLsizei width, GLsizei height); 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 \ #define GL_FUNCS_GEN \
USE_GL_FUNC(glAccum) \ USE_GL_FUNC(glAccum) \
USE_GL_FUNC(glAlphaFunc) \ USE_GL_FUNC(glAlphaFunc) \
...@@ -1476,6 +1485,15 @@ void (WINE_GLAPI *glViewport) (GLint x, GLint y, GLsizei width, GLsizei height); ...@@ -1476,6 +1485,15 @@ void (WINE_GLAPI *glViewport) (GLint x, GLint y, GLsizei width, GLsizei height);
USE_GL_FUNC(glVertexPointer) \ USE_GL_FUNC(glVertexPointer) \
USE_GL_FUNC(glViewport) 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) * OpenGL Extensions (EXT and ARB)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment