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
}
}
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");
......
......@@ -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,35 +404,26 @@ BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) {
int i;
HDC hdc;
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
#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");
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);
#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 = LoadLibraryA("gdi32.dll");
if(!mod_gl) {
ERR("Can't load gdi32.dll!\n");
return FALSE;
}
mod_gl = GetModuleHandleA("gdi32.dll");
#endif
p_wglGetProcAddress = (void*)GetProcAddress(mod_gl, "wglGetProcAddress");
if(!p_wglGetProcAddress) {
/* 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;
}
......@@ -441,6 +432,14 @@ BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) {
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 */
/* 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);
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");
......
......@@ -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)
......
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