Module: wine Branch: master Commit: 22eea683ff82b7da054b815ca178589aa881e155 URL: http://source.winehq.org/git/wine.git/?a=commit;h=22eea683ff82b7da054b815ca1...
Author: Roderick Colenbrander thunderbird2k@gmx.net Date: Mon Aug 20 15:48:11 2007 +0200
wgl: Cleanup pixelformat initialization code.
---
dlls/winex11.drv/opengl.c | 133 ++++++++++++++------------------------------- 1 files changed, 41 insertions(+), 92 deletions(-)
diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c index 455b3d0..98ecedb 100644 --- a/dlls/winex11.drv/opengl.c +++ b/dlls/winex11.drv/opengl.c @@ -833,22 +833,18 @@ static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig) return render_type; }
-static BOOL get_fbconfig_from_visualid(Display *display, Visual *visual, GLXFBConfig *fbconfig, int *fmt_id) +static BOOL init_formats(Display *display, int screen, Visual *visual) { - GLXFBConfig* cfgs = NULL; - int i; - int nCfgs; - int tmp_fmt_id; - int tmp_vis_id; - VisualID visualid; - - if(!display || !visual) { - ERR("Invalid display or visual\n"); - return FALSE; - } - visualid = XVisualIDFromVisual(visual); + int fmt_id, tmp_vis_id, tmp_fmt_id, nCfgs, i; + GLXFBConfig* cfgs; + GLXFBConfig fbconfig = NULL; + VisualID visualid = XVisualIDFromVisual(visual); + int nOffscreenFormats = 0;
- /* Get a list of all available framebuffer configurations */ + /* As mentioned in various parts of the code only the format of the main visual can be used for onscreen rendering. + * Next to this format there are also so called offscreen rendering formats (used for pbuffers) which can be supported + * because they don't need a visual. Below we use glXGetFBConfigs instead of glXChooseFBConfig to enumerate the fb configurations + * because this call lists both types of formats instead of only onscreen ones. */ cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs); if (NULL == cfgs || 0 == nCfgs) { ERR("glXChooseFBConfig returns NULL\n"); @@ -856,93 +852,46 @@ static BOOL get_fbconfig_from_visualid(Display *display, Visual *visual, GLXFBCo return FALSE; }
- /* Find the requested offscreen format and count the number of offscreen formats */ + /* Count the number of offscreen formats to determine the size for our pixelformat list */ for(i=0; i<nCfgs; i++) { pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id); - pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id);
- /* 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); - *fbconfig = cfgs[i]; - *fmt_id = tmp_fmt_id; - XFree(cfgs); - return TRUE; + /* We have found Wine's main visual */ + if(tmp_vis_id == visualid) { + pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id); + fbconfig = cfgs[i]; } - }
- ERR("No fbconfig found for Wine's main visual (0x%lx), expect problems!\n", visualid); - XFree(cfgs); - return FALSE; -} - -static BOOL init_formats(Display *display, int screen, Visual *visual) -{ - 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, &fbconfig, &fmt_id)) { - ERR("Can't get the FBCONFIG_ID for the main visual, expect problems!\n"); - return FALSE; + /* We have found an offscreen rendering format :) */ + if(tmp_vis_id == 0) { + nOffscreenFormats++; + } } + TRACE("Number of offscreen formats: %d\n", nOffscreenFormats);
- /* As mentioned in various parts of the code only the format of the main visual can be used for onscreen rendering. - * Next to this format there are also so called offscreen rendering formats (used for pbuffers) which can be supported - * because they don't need a visual. Below we use glXGetFBConfigs instead of glXChooseFBConfig to enumerate the fb configurations - * because this call lists both types of formats instead of only onscreen ones. */ - cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs); - if (NULL == cfgs || 0 == nCfgs) { - WARN("glXChooseFBConfig returns NULL\n"); - if(cfgs != NULL) XFree(cfgs); + /* 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 = fbconfig; + WineGLPixelFormatList[0].fmt_id = fmt_id; + WineGLPixelFormatList[0].render_type = get_render_type_from_fbconfig(display, fbconfig); + WineGLPixelFormatList[0].offscreenOnly = FALSE; + WineGLPixelFormatListSize = 1;
- /* 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 = fbconfig; - WineGLPixelFormatList[0].fmt_id = fmt_id; - WineGLPixelFormatList[0].render_type = get_render_type_from_fbconfig(display, fbconfig); - WineGLPixelFormatList[0].offscreenOnly = FALSE; - WineGLPixelFormatListSize = 1; - } - else { - /* Count the number of offscreen formats to determine the size for our pixelformat list */ - for(i=0; i<nCfgs; i++) { - pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id); + /* Fill the list with offscreen formats */ + for(i=0; i<nCfgs; i++) { + pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id); + pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id);
- /* We have found an offscreen rendering format :) */ - if(tmp_vis_id == 0) { - nOffscreenFormats++; - } - } - TRACE("Number of offscreen formats: %d\n", nOffscreenFormats); - - /* 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 = fbconfig; - WineGLPixelFormatList[0].fmt_id = fmt_id; - WineGLPixelFormatList[0].render_type = get_render_type_from_fbconfig(display, fbconfig); - WineGLPixelFormatList[0].offscreenOnly = FALSE; - WineGLPixelFormatListSize = 1; - - /* Fill the list with offscreen formats */ - for(i=0; i<nCfgs; i++) { - pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id); - pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id); - - /* We have found an offscreen rendering format :) */ - 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+1, i); - WineGLPixelFormatList[WineGLPixelFormatListSize].iPixelFormat = WineGLPixelFormatListSize+1; /* The index starts at 1 */ - WineGLPixelFormatList[WineGLPixelFormatListSize].fbconfig = cfgs[i]; - WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_id = tmp_fmt_id; - WineGLPixelFormatList[WineGLPixelFormatListSize].render_type = get_render_type_from_fbconfig(display, cfgs[i]); - WineGLPixelFormatList[WineGLPixelFormatListSize].offscreenOnly = TRUE; - WineGLPixelFormatListSize++; - } + /* We have found an offscreen rendering format :) */ + 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+1, i); + WineGLPixelFormatList[WineGLPixelFormatListSize].iPixelFormat = WineGLPixelFormatListSize+1; /* The index starts at 1 */ + WineGLPixelFormatList[WineGLPixelFormatListSize].fbconfig = cfgs[i]; + WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_id = tmp_fmt_id; + WineGLPixelFormatList[WineGLPixelFormatListSize].render_type = get_render_type_from_fbconfig(display, cfgs[i]); + WineGLPixelFormatList[WineGLPixelFormatListSize].offscreenOnly = TRUE; + WineGLPixelFormatListSize++; } }