Commit 22eea683 authored by Roderick Colenbrander's avatar Roderick Colenbrander Committed by Alexandre Julliard

wgl: Cleanup pixelformat initialization code.

parent d5c0888b
...@@ -833,22 +833,18 @@ static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig) ...@@ -833,22 +833,18 @@ static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
return render_type; 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 fmt_id, tmp_vis_id, tmp_fmt_id, nCfgs, i;
int i; GLXFBConfig* cfgs;
int nCfgs; GLXFBConfig fbconfig = NULL;
int tmp_fmt_id; VisualID visualid = XVisualIDFromVisual(visual);
int tmp_vis_id; int nOffscreenFormats = 0;
VisualID visualid;
if(!display || !visual) {
ERR("Invalid display or visual\n");
return FALSE;
}
visualid = XVisualIDFromVisual(visual);
/* 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); cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
if (NULL == cfgs || 0 == nCfgs) { if (NULL == cfgs || 0 == nCfgs) {
ERR("glXChooseFBConfig returns NULL\n"); ERR("glXChooseFBConfig returns NULL\n");
...@@ -856,93 +852,46 @@ static BOOL get_fbconfig_from_visualid(Display *display, Visual *visual, GLXFBCo ...@@ -856,93 +852,46 @@ static BOOL get_fbconfig_from_visualid(Display *display, Visual *visual, GLXFBCo
return FALSE; 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++) { for(i=0; i<nCfgs; i++) {
pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id); 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 :) */ /* We have found Wine's main visual */
if(visualid == tmp_vis_id) { if(tmp_vis_id == visualid) {
TRACE("Found FBCONFIG_ID 0x%x at index %d for VISUAL_ID 0x%x\n", tmp_fmt_id, i, tmp_vis_id); pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
*fbconfig = cfgs[i]; fbconfig = cfgs[i];
*fmt_id = tmp_fmt_id;
XFree(cfgs);
return TRUE;
} }
}
ERR("No fbconfig found for Wine's main visual (0x%lx), expect problems!\n", visualid); /* We have found an offscreen rendering format :) */
XFree(cfgs); if(tmp_vis_id == 0) {
return FALSE; nOffscreenFormats++;
} }
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;
} }
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. /* Allocate memory for all the offscreen pixelformats and the format of Wine's main visual */
* Next to this format there are also so called offscreen rendering formats (used for pbuffers) which can be supported WineGLPixelFormatList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (1+nOffscreenFormats)*sizeof(WineGLPixelFormat));
* because they don't need a visual. Below we use glXGetFBConfigs instead of glXChooseFBConfig to enumerate the fb configurations WineGLPixelFormatList[0].iPixelFormat = 1;
* because this call lists both types of formats instead of only onscreen ones. */ WineGLPixelFormatList[0].fbconfig = fbconfig;
cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs); WineGLPixelFormatList[0].fmt_id = fmt_id;
if (NULL == cfgs || 0 == nCfgs) { WineGLPixelFormatList[0].render_type = get_render_type_from_fbconfig(display, fbconfig);
WARN("glXChooseFBConfig returns NULL\n"); WineGLPixelFormatList[0].offscreenOnly = FALSE;
if(cfgs != NULL) XFree(cfgs); WineGLPixelFormatListSize = 1;
/* We only have the single format of Wine's main visual */ /* Fill the list with offscreen formats */
WineGLPixelFormatList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WineGLPixelFormat)); for(i=0; i<nCfgs; i++) {
WineGLPixelFormatList[0].iPixelFormat = 1; pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id);
WineGLPixelFormatList[0].fbconfig = fbconfig; pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id);
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);
/* We have found an offscreen rendering format :) */ /* We have found an offscreen rendering format :) */
if(tmp_vis_id == 0) { if(tmp_vis_id == 0) {
nOffscreenFormats++; 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];
TRACE("Number of offscreen formats: %d\n", nOffscreenFormats); WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_id = tmp_fmt_id;
WineGLPixelFormatList[WineGLPixelFormatListSize].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
/* Allocate memory for all the offscreen pixelformats and the format of Wine's main visual */ WineGLPixelFormatList[WineGLPixelFormatListSize].offscreenOnly = TRUE;
WineGLPixelFormatList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (1+nOffscreenFormats)*sizeof(WineGLPixelFormat)); WineGLPixelFormatListSize++;
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++;
}
} }
} }
......
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