diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c index 4bcc5a32186..01124650d21 100644 --- a/dlls/winex11.drv/opengl.c +++ b/dlls/winex11.drv/opengl.c @@ -128,10 +128,10 @@ struct WineGLInfo { }; typedef struct wine_glpixelformat { - int iPixelFormat; - int fbconfig; - int fmt_index; - BOOL offscreenOnly; + int iPixelFormat; + GLXFBConfig fbconfig; + int fmt_id; + BOOL offscreenOnly; } WineGLPixelFormat; static Wine_GLContext *context_list; @@ -817,7 +817,7 @@ static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuf return nAttribs; } -static BOOL get_fbconfig_from_visualid(Display *display, Visual *visual, int *fmt_id, int *fmt_index) +static BOOL get_fbconfig_from_visualid(Display *display, Visual *visual, GLXFBConfig *fbconfig, int *fmt_id) { GLXFBConfig* cfgs = NULL; int i; @@ -848,9 +848,9 @@ static BOOL get_fbconfig_from_visualid(Display *display, Visual *visual, int *fm /* We are looking up the GLX index of our main visual and have found it :) */ if(visualid == tmp_vis_id) { TRACE("Found FBCONFIG_ID 0x%x at index %d for VISUAL_ID 0x%x\n", tmp_fmt_id, i, tmp_vis_id); - XFree(cfgs); + *fbconfig = cfgs[i]; *fmt_id = tmp_fmt_id; - *fmt_index = i; + XFree(cfgs); return TRUE; } } @@ -862,13 +862,13 @@ static BOOL get_fbconfig_from_visualid(Display *display, Visual *visual, int *fm static BOOL init_formats(Display *display, int screen, Visual *visual) { - int fmt_id, fmt_index; - int tmp_vis_id, tmp_fmt_id, nCfgs, i; - GLXFBConfig* cfgs = NULL; + int fmt_id, tmp_vis_id, tmp_fmt_id, nCfgs, i; + GLXFBConfig* cfgs; + GLXFBConfig fbconfig; int nOffscreenFormats = 0; /* Locate the fbconfig correspondig to our main visual */ - if(!get_fbconfig_from_visualid(display, visual, &fmt_id, &fmt_index)) { + if(!get_fbconfig_from_visualid(display, visual, &fbconfig, &fmt_id)) { ERR("Can't get the FBCONFIG_ID for the main visual, expect problems!\n"); return FALSE; } @@ -885,8 +885,8 @@ static BOOL init_formats(Display *display, int screen, Visual *visual) /* We only have the single format of Wine's main visual */ WineGLPixelFormatList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WineGLPixelFormat)); WineGLPixelFormatList[0].iPixelFormat = 1; - WineGLPixelFormatList[0].fbconfig = fmt_id; - WineGLPixelFormatList[0].fmt_index = fmt_index; + WineGLPixelFormatList[0].fbconfig = fbconfig; + WineGLPixelFormatList[0].fmt_id = fmt_id; WineGLPixelFormatList[0].offscreenOnly = FALSE; WineGLPixelFormatListSize = 1; } @@ -905,8 +905,8 @@ static BOOL init_formats(Display *display, int screen, Visual *visual) /* Allocate memory for all the offscreen pixelformats and the format of Wine's main visual */ WineGLPixelFormatList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (1+nOffscreenFormats)*sizeof(WineGLPixelFormat)); WineGLPixelFormatList[0].iPixelFormat = 1; - WineGLPixelFormatList[0].fbconfig = fmt_id; - WineGLPixelFormatList[0].fmt_index = fmt_index; + WineGLPixelFormatList[0].fbconfig = fbconfig; + WineGLPixelFormatList[0].fmt_id = fmt_id; WineGLPixelFormatList[0].offscreenOnly = FALSE; WineGLPixelFormatListSize = 1; @@ -919,9 +919,9 @@ static BOOL init_formats(Display *display, int screen, Visual *visual) if(tmp_vis_id == 0) { TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", tmp_fmt_id, WineGLPixelFormatListSize, i); WineGLPixelFormatList[WineGLPixelFormatListSize].iPixelFormat = WineGLPixelFormatListSize; - WineGLPixelFormatList[WineGLPixelFormatListSize].fbconfig = tmp_fmt_id; - WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_index = i; - WineGLPixelFormatList[0].offscreenOnly = TRUE; + WineGLPixelFormatList[WineGLPixelFormatListSize].fbconfig = cfgs[i]; + WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_id = tmp_fmt_id; + WineGLPixelFormatList[WineGLPixelFormatListSize].offscreenOnly = TRUE; WineGLPixelFormatListSize++; } } @@ -935,45 +935,44 @@ static BOOL init_formats(Display *display, int screen, Visual *visual) /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones. * In our WGL implementation we only support a subset of these formats namely the format of * Wine's main visual and offscreen formats (if they are available). - * This function converts a WGL format to its corresponding GLX one. It returns the index (zero-based) - * into the GLX FB config table and it returns the number of supported WGL formats in fmt_count. + * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat + * and it returns the number of supported WGL formats in fmt_count. */ -static BOOL ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_index, int *fmt_count) +static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count) { - int ret = FALSE; + WineGLPixelFormat *res = NULL; /* Init the list of pixel formats when we need it */ if(!WineGLPixelFormatListSize) init_formats(display, DefaultScreen(display), visual); + /* Check if the pixelformat is valid. Note that it is legal to pass an invalid + * iPixelFormat in case of probing the number of pixelformats. + */ if((iPixelFormat <= 0) || (iPixelFormat > WineGLPixelFormatListSize)) { ERR("invalid iPixelFormat %d\n", iPixelFormat); - ret = FALSE; - *fmt_index = -1; - if(AllowOffscreen) *fmt_count = WineGLPixelFormatListSize; else *fmt_count = 1; /* Only show the format of our main visual */ } else if(iPixelFormat == 1) { - ret = TRUE; - *fmt_index = WineGLPixelFormatList[0].fmt_index; + res = &WineGLPixelFormatList[0]; *fmt_count = 1; /* Only show the format of our main visual */ } - /* Limit the use of offscreen formats to WGL extension calls which pass AllowOffscreen = TRUE */ else if((WineGLPixelFormatList[iPixelFormat-1].offscreenOnly == TRUE) && AllowOffscreen) { - ret = TRUE; + res = &WineGLPixelFormatList[iPixelFormat-1]; *fmt_count = WineGLPixelFormatListSize; - TRACE("Returning FBConfig_ID=%x for iPixelFormat=%d\n", WineGLPixelFormatList[iPixelFormat-1].fbconfig, iPixelFormat); + TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res->fbconfig, iPixelFormat); } TRACE("Number of returned pixelformats=%d\n", *fmt_count); - return ret; + + return res; } /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */ -static int ConvertPixelFormatGLXtoWGL(Display *display, int fbconfig) +static int ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id) { int i; @@ -982,12 +981,12 @@ static int ConvertPixelFormatGLXtoWGL(Display *display, int fbconfig) init_formats(display, DefaultScreen(display), visual); for(i=0; ivisualid); } else { int dwFlags = 0; @@ -1037,7 +1028,7 @@ int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev, int value = 0; /* Pixel type */ - pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_RENDER_TYPE, &value); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value); if (value & GLX_RGBA_BIT) iPixelType = PFD_TYPE_RGBA; else @@ -1049,7 +1040,7 @@ int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev, } /* Doublebuffer */ - pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_DOUBLEBUFFER, &value); if (value) dwFlags |= PFD_DOUBLEBUFFER; + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value); if (value) dwFlags |= PFD_DOUBLEBUFFER; if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) && (ppfd->dwFlags & PFD_DOUBLEBUFFER)) { if (!(dwFlags & PFD_DOUBLEBUFFER)) { TRACE("dbl buffer mismatch\n"); @@ -1058,7 +1049,7 @@ int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev, } /* Stereo */ - pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_STEREO, &value); if (value) dwFlags |= PFD_STEREO; + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) dwFlags |= PFD_STEREO; if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE) && (ppfd->dwFlags & PFD_STEREO)) { if (!(dwFlags & PFD_STEREO)) { TRACE("stereo mismatch\n"); @@ -1067,28 +1058,28 @@ int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev, } /* Alpha bits */ - pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_ALPHA_SIZE, &value); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &value); if (ppfd->iPixelType==PFD_TYPE_RGBA && ppfd->cAlphaBits && !value) { TRACE("alpha mismatch\n"); goto choose_exit; } /* Depth bits */ - pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_DEPTH_SIZE, &value); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value); if (ppfd->cDepthBits && !value) { TRACE("depth mismatch\n"); goto choose_exit; } /* Stencil bits */ - pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_STENCIL_SIZE, &value); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value); if (ppfd->cStencilBits && !value) { TRACE("stencil mismatch\n"); goto choose_exit; } /* Aux buffers */ - pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_AUX_BUFFERS, &value); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value); if (ppfd->cAuxBuffers && !value) { TRACE("aux mismatch\n"); goto choose_exit; @@ -1103,7 +1094,6 @@ choose_exit: if(!ret) TRACE("No matching mode was found returning 0\n"); - if (NULL != cfgs) XFree(cfgs); wine_tsx11_unlock(); return ret; } @@ -1120,14 +1110,9 @@ int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev, /*XVisualInfo *vis;*/ int value; int rb,gb,bb,ab; - - GLXFBConfig* cfgs = NULL; - GLXFBConfig cur; - int nCfgs = 0; + WineGLPixelFormat *fmt; int ret = 0; int fmt_count = 0; - int fmt_index = 0; - BOOL res = FALSE; if (!has_opengl()) { ERR("No libGL on this box - disabling OpenGL support !\n"); @@ -1136,29 +1121,13 @@ int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev, TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd); - wine_tsx11_lock(); - cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs); - wine_tsx11_unlock(); - - if (NULL == cfgs || 0 == nCfgs) { - ERR("unexpected iPixelFormat(%d), returns NULL\n", iPixelFormat); - return 0; /* unespected error */ - } - /* 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 */ - res = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_index, &fmt_count); - + fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_count); if (ppfd == NULL) { - /* The application is only querying the number of visuals */ - wine_tsx11_lock(); - if (NULL != cfgs) XFree(cfgs); - wine_tsx11_unlock(); + /* The application is only querying the number of pixelformats */ return fmt_count; - } else if(res == FALSE) { + } else if(fmt == NULL) { 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; } @@ -1169,7 +1138,6 @@ int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev, } ret = fmt_count; - cur = cfgs[fmt_index]; memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR); @@ -1181,30 +1149,30 @@ int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev, wine_tsx11_lock(); - pglXGetFBConfigAttrib(gdi_display, cur, GLX_CONFIG_CAVEAT, &value); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_CONFIG_CAVEAT, &value); if(value == GLX_SLOW_CONFIG) ppfd->dwFlags |= PFD_GENERIC_ACCELERATED; - pglXGetFBConfigAttrib(gdi_display, cur, GLX_DOUBLEBUFFER, &value); if (value) ppfd->dwFlags |= PFD_DOUBLEBUFFER; - pglXGetFBConfigAttrib(gdi_display, cur, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO; + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value); if (value) ppfd->dwFlags |= PFD_DOUBLEBUFFER; + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO; /* Pixel type */ - pglXGetFBConfigAttrib(gdi_display, cur, GLX_RENDER_TYPE, &value); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value); if (value & GLX_RGBA_BIT) ppfd->iPixelType = PFD_TYPE_RGBA; else ppfd->iPixelType = PFD_TYPE_COLORINDEX; /* Color bits */ - pglXGetFBConfigAttrib(gdi_display, cur, GLX_BUFFER_SIZE, &value); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value); ppfd->cColorBits = value; /* Red, green, blue and alpha bits / shifts */ if (ppfd->iPixelType == PFD_TYPE_RGBA) { - pglXGetFBConfigAttrib(gdi_display, cur, GLX_RED_SIZE, &rb); - pglXGetFBConfigAttrib(gdi_display, cur, GLX_GREEN_SIZE, &gb); - pglXGetFBConfigAttrib(gdi_display, cur, GLX_BLUE_SIZE, &bb); - pglXGetFBConfigAttrib(gdi_display, cur, GLX_ALPHA_SIZE, &ab); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab); ppfd->cRedBits = rb; ppfd->cRedShift = gb + bb + ab; @@ -1227,11 +1195,11 @@ int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev, /* Accums : to do ... */ /* Depth bits */ - pglXGetFBConfigAttrib(gdi_display, cur, GLX_DEPTH_SIZE, &value); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value); ppfd->cDepthBits = value; /* stencil bits */ - pglXGetFBConfigAttrib(gdi_display, cur, GLX_STENCIL_SIZE, &value); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value); ppfd->cStencilBits = value; wine_tsx11_unlock(); @@ -1244,10 +1212,6 @@ int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev, dump_PIXELFORMATDESCRIPTOR(ppfd); } - wine_tsx11_lock(); - if (NULL != cfgs) XFree(cfgs); - wine_tsx11_unlock(); - return ret; } @@ -1270,7 +1234,7 @@ int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) { BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd) { - int fmt_index = 0; + WineGLPixelFormat *fmt; int value; TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd); @@ -1281,7 +1245,8 @@ BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev, } /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */ - if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_index, &value)) { + fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value); + if(!fmt) { ERR("Invalid iPixelFormat: %d\n", iPixelFormat); return 0; } @@ -1289,9 +1254,6 @@ BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev, physDev->current_pf = iPixelFormat; if (TRACE_ON(opengl)) { - int nCfgs_fmt = 0; - GLXFBConfig* cfgs_fmt = NULL; - GLXFBConfig cur_cfg; int gl_test = 0; /* @@ -1310,20 +1272,17 @@ BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev, pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &value); TRACE(" - HEIGHT as %d\n", tmp); */ - cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt); - cur_cfg = cfgs_fmt[fmt_index]; - gl_test = pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_FBCONFIG_ID, &value); + gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value); if (gl_test) { ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n"); } else { TRACE(" FBConfig have :\n"); TRACE(" - FBCONFIG_ID 0x%x\n", value); - pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_VISUAL_ID, &value); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value); TRACE(" - VISUAL_ID 0x%x\n", value); - pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_DRAWABLE_TYPE, &value); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value); TRACE(" - DRAWABLE_TYPE 0x%x\n", value); } - XFree(cfgs_fmt); } return TRUE; } @@ -1336,12 +1295,9 @@ BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev, HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) { Wine_GLContext *ret; - GLXFBConfig* cfgs_fmt = NULL; - GLXFBConfig cur_cfg; + WineGLPixelFormat *fmt; int hdcPF = physDev->current_pf; int fmt_count = 0; - int fmt_index = 0; - int nCfgs_fmt = 0; int value = 0; int gl_test = 0; HDC hdc = physDev->hdc; @@ -1356,35 +1312,27 @@ HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) /* First, get the visual in use by the X11DRV */ if (!gdi_display) return 0; + fmt = ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, FALSE /* Offscreen */, &fmt_count); /* 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(!ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, FALSE /* Offscreen */, &fmt_index, &fmt_count)) { + if(!fmt) { ERR("Cannot get FB Config for main iPixelFormat 1, expect problems!\n"); SetLastError(ERROR_INVALID_PIXEL_FORMAT); return NULL; } - cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt); - if (NULL == cfgs_fmt || 0 == nCfgs_fmt) { - ERR("Cannot get FB Configs, expect problems.\n"); - SetLastError(ERROR_INVALID_PIXEL_FORMAT); - return NULL; - } - if (fmt_count < hdcPF) { ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, hdcPF, fmt_count); SetLastError(ERROR_INVALID_PIXEL_FORMAT); return NULL; } - cur_cfg = cfgs_fmt[fmt_index]; - gl_test = pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_FBCONFIG_ID, &value); + gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value); if (gl_test) { ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n"); SetLastError(ERROR_INVALID_PIXEL_FORMAT); return NULL; } - XFree(cfgs_fmt); /* The context will be allocated in the wglMakeCurrent call */ wine_tsx11_lock(); @@ -1392,9 +1340,9 @@ HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) wine_tsx11_unlock(); ret->hdc = hdc; ret->physDev = physDev; - ret->fb_conf = cur_cfg; + ret->fb_conf = fmt->fbconfig; /*ret->vis = vis;*/ - ret->vis = pglXGetVisualFromFBConfig(gdi_display, cur_cfg); + ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig); TRACE(" creating context %p (GL context creation delayed)\n", ret); return (HGLRC) ret; @@ -1991,11 +1939,10 @@ static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) { static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList) { Wine_GLPBuffer* object = NULL; - GLXFBConfig* cfgs = NULL; + WineGLPixelFormat *fmt = NULL; int nCfgs = 0; int attribs[256]; int nAttribs = 0; - int fmt_index = 0; TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList); @@ -2005,16 +1952,9 @@ static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, return NULL; /* unexpected error */ } - cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs); - - if (NULL == cfgs || 0 == nCfgs) { - ERR("(%p): Cannot get FB Configs for iPixelFormat(%d), returns NULL\n", hdc, iPixelFormat); - SetLastError(ERROR_INVALID_PIXEL_FORMAT); - return NULL; /* unexpected error */ - } - /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */ - if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_index, &nCfgs)) { + fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &nCfgs); + if(!fmt) { ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs); SetLastError(ERROR_INVALID_PIXEL_FORMAT); goto create_failed; /* unexpected error */ @@ -2157,20 +2097,16 @@ static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, } PUSH1(attribs, None); - object->drawable = pglXCreatePbuffer(gdi_display, cfgs[fmt_index], attribs); + object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs); TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable); if (!object->drawable) { SetLastError(ERROR_NO_SYSTEM_RESOURCES); goto create_failed; /* unexpected error */ } TRACE("->(%p)\n", object); - - /** free list */ - XFree(cfgs); return (HPBUFFERARB) object; create_failed: - if (NULL != cfgs) XFree(cfgs); HeapFree(GetProcessHeap(), 0, object); TRACE("->(FAILED)\n"); return (HPBUFFERARB) NULL; @@ -2443,14 +2379,11 @@ static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAtt static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues) { UINT i; - GLXFBConfig* cfgs = NULL; - GLXFBConfig curCfg = NULL; - int nCfgs = 0; + WineGLPixelFormat *fmt = NULL; int hTest; int tmp; int curGLXAttr = 0; int nWGLFormats = 0; - int fmt_index = 0; TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues); @@ -2459,16 +2392,11 @@ static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelF return GL_FALSE; } - cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs); - if (NULL == cfgs) { - ERR("no FB Configs found for display(%p)\n", gdi_display); - return GL_FALSE; - } - /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted. * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */ - if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_index, &nWGLFormats)) { + fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &nWGLFormats); + if(!fmt) { WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat); } @@ -2487,11 +2415,8 @@ static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelF case WGL_ACCELERATION_ARB: curGLXAttr = GLX_CONFIG_CAVEAT; - - if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error; - curCfg = cfgs[iPixelFormat - 1]; - - hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp); + if (!fmt) goto pix_error; + hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp); if (hTest) goto get_error; switch (tmp) { case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break; @@ -2505,11 +2430,8 @@ static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelF case WGL_TRANSPARENT_ARB: curGLXAttr = GLX_TRANSPARENT_TYPE; - /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of - * supported WGLFormats and also check if the GLX fmt_index is valid. */ - if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error; - curCfg = cfgs[fmt_index]; - hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp); + if (!fmt) goto pix_error; + hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp); if (hTest) goto get_error; piValues[i] = GL_FALSE; if (GLX_NONE != tmp) piValues[i] = GL_TRUE; @@ -2517,11 +2439,8 @@ static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelF case WGL_PIXEL_TYPE_ARB: curGLXAttr = GLX_RENDER_TYPE; - /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of - * supported WGLFormats and also check if the GLX fmt_index is valid. */ - if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error; - curCfg = cfgs[fmt_index]; - hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp); + if (!fmt) goto pix_error; + hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp); if (hTest) goto get_error; TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp); if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; } @@ -2536,14 +2455,11 @@ static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelF case WGL_COLOR_BITS_ARB: /** see ConvertAttribWGLtoGLX for explain */ - /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of - * supported WGLFormats and also check if the GLX fmt_index is valid. */ - if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error; - curCfg = cfgs[fmt_index]; - hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_BUFFER_SIZE, piValues + i); + if (!fmt) goto pix_error; + hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, piValues + i); if (hTest) goto get_error; TRACE("WGL_COLOR_BITS_ARB: GLX_BUFFER_SIZE = %d\n", piValues[i]); - hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_ALPHA_SIZE, &tmp); + hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &tmp); if (hTest) goto get_error; TRACE("WGL_COLOR_BITS_ARB: GLX_ALPHA_SIZE = %d\n", tmp); piValues[i] = piValues[i] - tmp; @@ -2564,17 +2480,14 @@ static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelF continue; } curGLXAttr = GLX_RENDER_TYPE; - /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of - * supported WGLFormats and also check if the GLX fmt_index is valid. */ - if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error; - curCfg = cfgs[fmt_index]; - hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp); + if (!fmt) goto pix_error; + hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp); if (hTest) goto get_error; if (GLX_COLOR_INDEX_BIT == tmp) { piValues[i] = GL_FALSE; continue; } - hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_DRAWABLE_TYPE, &tmp); + hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp); if (hTest) goto get_error; piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE; continue; @@ -2613,7 +2526,7 @@ static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelF piValues[i] = GL_TRUE; continue; case WGL_DRAW_TO_PBUFFER_ARB: - hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_DRAWABLE_TYPE, &tmp); + hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp); if (hTest) goto get_error; piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE; continue; @@ -2644,11 +2557,8 @@ static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelF * mean that the behavior could differ between different vendors (ATI, Nvidia, ..). */ if (0 != curGLXAttr && iPixelFormat != 0) { - /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of - * supported WGLFormats and also check if the GLX fmt_index is valid. */ - if((iPixelFormat > 0) && ((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs))) goto pix_error; - curCfg = cfgs[fmt_index]; - hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, piValues + i); + if (!fmt) goto pix_error; + hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i); if (hTest) goto get_error; curGLXAttr = 0; } else { @@ -2659,12 +2569,10 @@ static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelF get_error: ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr); - XFree(cfgs); return GL_FALSE; pix_error: - ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nCfgs); - XFree(cfgs); + ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats); return GL_FALSE; }