winex11: Get the current pixel format from the drawable structure in wglCreateContextAttribsARB.

This commit is contained in:
Alexandre Julliard 2012-09-07 16:19:06 +02:00
parent c01d723a4f
commit d52c2de7da
1 changed files with 40 additions and 53 deletions

View File

@ -1880,90 +1880,77 @@ static void wglFlush(void)
static struct wgl_context *X11DRV_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *hShareContext, static struct wgl_context *X11DRV_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *hShareContext,
const int* attribList ) const int* attribList )
{ {
struct x11drv_escape_get_drawable escape; struct wgl_context *ret = NULL;
struct wgl_context *ret; struct gl_drawable *gl;
const struct wgl_pixel_format *fmt; HWND hwnd = WindowFromDC( hdc );
TRACE("(%p %p %p)\n", hdc, hShareContext, attribList); TRACE("(%p %p %p)\n", hdc, hShareContext, attribList);
escape.code = X11DRV_GET_DRAWABLE; EnterCriticalSection( &context_section );
if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape.code), (LPCSTR)&escape.code,
sizeof(escape), (LPSTR)&escape ))
return 0;
fmt = get_pixel_format(gdi_display, escape.pixel_format, TRUE /* Offscreen */); if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl ) ||
/* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones. !XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl ))
* If this fails something is very wrong on the system. */
if(!fmt)
{ {
ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", escape.pixel_format); if (!(ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret)))) goto done;
SetLastError(ERROR_INVALID_PIXEL_FORMAT);
return NULL;
}
if (!(ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret)))) return 0;
ret->hdc = hdc; ret->hdc = hdc;
ret->fmt = fmt; ret->fmt = gl->format;
ret->vis = NULL; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */ ret->vis = NULL; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
ret->gl3_context = TRUE; ret->gl3_context = TRUE;
ret->numAttribs = 0; ret->numAttribs = 0;
if (attribList) if (attribList)
{ {
int *pAttribList = (int*)attribList;
int *pContextAttribList = &ret->attribList[0]; int *pContextAttribList = &ret->attribList[0];
/* attribList consists of pairs {token, value] terminated with 0 */ /* attribList consists of pairs {token, value] terminated with 0 */
while(pAttribList[0] != 0) while(attribList[0] != 0)
{ {
TRACE("%#x %#x\n", pAttribList[0], pAttribList[1]); TRACE("%#x %#x\n", attribList[0], attribList[1]);
switch(pAttribList[0]) switch(attribList[0])
{ {
case WGL_CONTEXT_MAJOR_VERSION_ARB: case WGL_CONTEXT_MAJOR_VERSION_ARB:
pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB; pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
pContextAttribList[1] = pAttribList[1]; pContextAttribList[1] = attribList[1];
break; break;
case WGL_CONTEXT_MINOR_VERSION_ARB: case WGL_CONTEXT_MINOR_VERSION_ARB:
pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB; pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB;
pContextAttribList[1] = pAttribList[1]; pContextAttribList[1] = attribList[1];
break; break;
case WGL_CONTEXT_LAYER_PLANE_ARB: case WGL_CONTEXT_LAYER_PLANE_ARB:
break; break;
case WGL_CONTEXT_FLAGS_ARB: case WGL_CONTEXT_FLAGS_ARB:
pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB; pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB;
pContextAttribList[1] = pAttribList[1]; pContextAttribList[1] = attribList[1];
break; break;
case WGL_CONTEXT_PROFILE_MASK_ARB: case WGL_CONTEXT_PROFILE_MASK_ARB:
pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB; pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
pContextAttribList[1] = pAttribList[1]; pContextAttribList[1] = attribList[1];
break; break;
default: default:
ERR("Unhandled attribList pair: %#x %#x\n", pAttribList[0], pAttribList[1]); ERR("Unhandled attribList pair: %#x %#x\n", attribList[0], attribList[1]);
} }
ret->numAttribs++; ret->numAttribs++;
pAttribList += 2; attribList += 2;
pContextAttribList += 2; pContextAttribList += 2;
} }
} }
X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL); X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
ret->ctx = create_glxcontext(gdi_display, ret, NULL); ret->ctx = create_glxcontext(gdi_display, ret, NULL);
XSync(gdi_display, False); XSync(gdi_display, False);
if(X11DRV_check_error() || !ret->ctx) if (!X11DRV_check_error() && ret->ctx)
{ {
list_add_head( &context_list, &ret->entry );
goto done;
}
/* In the future we should convert the GLX error to a win32 one here if needed */ /* In the future we should convert the GLX error to a win32 one here if needed */
ERR("Context creation failed\n"); ERR("Context creation failed\n");
HeapFree( GetProcessHeap(), 0, ret ); HeapFree( GetProcessHeap(), 0, ret );
return NULL; ret = NULL;
} }
else SetLastError( ERROR_INVALID_PIXEL_FORMAT );
EnterCriticalSection( &context_section ); done:
list_add_head( &context_list, &ret->entry );
LeaveCriticalSection( &context_section ); LeaveCriticalSection( &context_section );
TRACE( "%p -> %p\n", hdc, ret );
TRACE(" creating context %p\n", ret);
return ret; return ret;
} }