wgl: Make the WGL code independant of the number of supported pixel formats.

This commit is contained in:
Roderick Colenbrander 2006-12-10 19:17:03 +01:00 committed by Alexandre Julliard
parent 9da10277ce
commit 055f8712b4
1 changed files with 30 additions and 44 deletions

View File

@ -1065,7 +1065,9 @@ int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
GLXFBConfig cur; GLXFBConfig cur;
int nCfgs = 0; int nCfgs = 0;
int ret = 0; int ret = 0;
int fmt_count = 0;
int fmt_index = 0; int fmt_index = 0;
BOOL res = FALSE;
if (!has_opengl()) { if (!has_opengl()) {
ERR("No libGL on this box - disabling OpenGL support !\n"); ERR("No libGL on this box - disabling OpenGL support !\n");
@ -1083,20 +1085,21 @@ int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
return 0; /* unespected error */ return 0; /* unespected error */
} }
/* This function always reports the total number of supported pixel formats. /* Look for the iPixelFormat in our list of supported formats. If it is supported we get the index in the FBConfig table and the number of supported formats back */
* At the moment we only support the pixel format corresponding to the main res = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &fmt_count);
* visual which got created at x11drv initialization. More formats could be
* supported if there was a way to recreate x11 windows in x11drv.
* Because we only support one format nCfgs needs to be set to 1.
*/
nCfgs = 1;
if (ppfd == NULL) { if (ppfd == NULL) {
/* The application is only querying the number of visuals */ /* The application is only querying the number of visuals */
wine_tsx11_lock(); wine_tsx11_lock();
if (NULL != cfgs) XFree(cfgs); if (NULL != cfgs) XFree(cfgs);
wine_tsx11_unlock(); wine_tsx11_unlock();
return nCfgs; return fmt_count;
} else if(res == FALSE) {
WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
wine_tsx11_lock();
if (NULL != cfgs) XFree(cfgs);
wine_tsx11_unlock();
return 0;
} }
if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) { if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
@ -1105,18 +1108,7 @@ int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
return 0; return 0;
} }
if (nCfgs < iPixelFormat || 1 > iPixelFormat) { ret = fmt_count;
WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL\n", iPixelFormat, nCfgs);
return 0;
}
/* Retrieve the index in the FBConfig table corresponding to the visual ID from the main visual */
if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &value)) {
ERR("Can't find a valid pixel format index from the main visual, expect problems!\n");
return 0;
}
ret = nCfgs;
cur = cfgs[fmt_index]; cur = cfgs[fmt_index];
memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
@ -1218,6 +1210,9 @@ int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev, BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
int iPixelFormat, int iPixelFormat,
const PIXELFORMATDESCRIPTOR *ppfd) { const PIXELFORMATDESCRIPTOR *ppfd) {
int fmt_index = 0;
int value;
TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd); TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
if (!has_opengl()) { if (!has_opengl()) {
@ -1225,12 +1220,9 @@ BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
return 0; return 0;
} }
/* At the moment we only support the pixelformat corresponding to the main /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
* x11drv visual which got created at x11drv initialization. More formats if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &value)) {
* could be supported if there was a way to recreate x11 windows in x11drv ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
*/
if(iPixelFormat != 1) {
TRACE("Invalid iPixelFormat: %d\n", iPixelFormat);
return 0; return 0;
} }
@ -1240,14 +1232,7 @@ BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
int nCfgs_fmt = 0; int nCfgs_fmt = 0;
GLXFBConfig* cfgs_fmt = NULL; GLXFBConfig* cfgs_fmt = NULL;
GLXFBConfig cur_cfg; GLXFBConfig cur_cfg;
int value;
int gl_test = 0; int gl_test = 0;
int fmt_index = 0;
if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &value)) {
ERR("Can't find a valid pixel format index from the main visual, expect problems!\n");
return TRUE; /* Return true because the SetPixelFormat stuff itself passed */
}
/* /*
* How to test if hdc current drawable is compatible (visual/FBConfig) ? * How to test if hdc current drawable is compatible (visual/FBConfig) ?
@ -1293,8 +1278,8 @@ HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
Wine_GLContext *ret; Wine_GLContext *ret;
GLXFBConfig* cfgs_fmt = NULL; GLXFBConfig* cfgs_fmt = NULL;
GLXFBConfig cur_cfg; GLXFBConfig cur_cfg;
int hdcPF = 1; /* We can only use Wine's main visual which has an index of 1 */ int hdcPF = physDev->current_pf;
int tmp = 0; int fmt_count = 0;
int fmt_index = 0; int fmt_index = 0;
int nCfgs_fmt = 0; int nCfgs_fmt = 0;
int value = 0; int value = 0;
@ -1313,7 +1298,7 @@ HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
/* We can only render using the iPixelFormat (1) of Wine's Main visual, we need to get the corresponding GLX format. /* We can only render using the iPixelFormat (1) of Wine's Main visual, we need to get the corresponding GLX format.
* If this fails something is very wrong on the system. */ * If this fails something is very wrong on the system. */
if(!ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, &fmt_index, &tmp)) { if(!ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, &fmt_index, &fmt_count)) {
ERR("Cannot get FB Config for main iPixelFormat 1, expect problems!\n"); ERR("Cannot get FB Config for main iPixelFormat 1, expect problems!\n");
SetLastError(ERROR_INVALID_PIXEL_FORMAT); SetLastError(ERROR_INVALID_PIXEL_FORMAT);
return NULL; return NULL;
@ -1326,8 +1311,8 @@ HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
return NULL; return NULL;
} }
if (nCfgs_fmt < fmt_index) { if (fmt_count < hdcPF) {
ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, fmt_index, nCfgs_fmt); ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, hdcPF, fmt_count);
SetLastError(ERROR_INVALID_PIXEL_FORMAT); SetLastError(ERROR_INVALID_PIXEL_FORMAT);
return NULL; return NULL;
} }
@ -1833,6 +1818,7 @@ static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat,
object->display = gdi_display; object->display = gdi_display;
object->width = iWidth; object->width = iWidth;
object->height = iHeight; object->height = iHeight;
object->pixelFormat = iPixelFormat;
nAttribs = ConvertAttribWGLtoGLX(piAttribList, attribs, object); nAttribs = ConvertAttribWGLtoGLX(piAttribList, attribs, object);
if (-1 == nAttribs) { if (-1 == nAttribs) {
@ -2014,8 +2000,8 @@ HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
} }
/* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected. /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
* We only support one onscreen rendering format (the one from the main visual), so use that. */ * All formats in our pixelformat list are compatible with each other and the main drawable. */
physDev->current_pf = 1; physDev->current_pf = object->pixelFormat;
physDev->drawable = object->drawable; physDev->drawable = object->drawable;
TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc); TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);