2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006-2009 Roderick Colenbrander
8 * Copyright 2006 Tomas Carnecky
9 * Copyright 2012 Alexandre Julliard
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/port.h"
33 #ifdef HAVE_SYS_SOCKET_H
34 #include <sys/socket.h>
50 #include "xcomposite.h"
52 #include "wine/library.h"
53 #include "wine/debug.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
59 WINE_DECLARE_DEBUG_CHANNEL(winediag);
61 #include "wine/wgl_driver.h"
62 #include "wine/wglext.h"
64 /* For compatibility with old Mesa headers */
65 #ifndef GLX_SAMPLE_BUFFERS_ARB
66 # define GLX_SAMPLE_BUFFERS_ARB 100000
68 #ifndef GLX_SAMPLES_ARB
69 # define GLX_SAMPLES_ARB 100001
71 #ifndef GL_TEXTURE_CUBE_MAP
72 # define GL_TEXTURE_CUBE_MAP 0x8513
74 #ifndef GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
75 # define GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20B2
77 #ifndef GLX_EXT_fbconfig_packed_float
78 # define GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT 0x20B1
79 # define GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT 0x00000008
81 #ifndef GLX_ARB_create_context
82 # define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
83 # define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
84 # define GLX_CONTEXT_FLAGS_ARB 0x2094
86 #ifndef GLX_ARB_create_context_profile
87 # define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
89 /** GLX_ATI_pixel_format_float */
90 #define GLX_RGBA_FLOAT_ATI_BIT 0x00000100
91 /** GLX_ARB_pixel_format_float */
92 #define GLX_RGBA_FLOAT_BIT 0x00000004
93 #define GLX_RGBA_FLOAT_TYPE 0x20B9
94 /** GL_NV_float_buffer */
95 #define GL_FLOAT_R_NV 0x8880
96 #define GL_FLOAT_RG_NV 0x8881
97 #define GL_FLOAT_RGB_NV 0x8882
98 #define GL_FLOAT_RGBA_NV 0x8883
99 #define GL_FLOAT_R16_NV 0x8884
100 #define GL_FLOAT_R32_NV 0x8885
101 #define GL_FLOAT_RG16_NV 0x8886
102 #define GL_FLOAT_RG32_NV 0x8887
103 #define GL_FLOAT_RGB16_NV 0x8888
104 #define GL_FLOAT_RGB32_NV 0x8889
105 #define GL_FLOAT_RGBA16_NV 0x888A
106 #define GL_FLOAT_RGBA32_NV 0x888B
107 #define GL_TEXTURE_FLOAT_COMPONENTS_NV 0x888C
108 #define GL_FLOAT_CLEAR_COLOR_VALUE_NV 0x888D
109 #define GL_FLOAT_RGBA_MODE_NV 0x888E
110 /** GLX_NV_float_buffer */
111 #define GLX_FLOAT_COMPONENTS_NV 0x20B0
115 const char *glVersion;
120 const char *glxServerVersion;
121 const char *glxServerVendor;
122 const char *glxServerExtensions;
124 const char *glxClientVersion;
125 const char *glxClientVendor;
126 const char *glxClientExtensions;
128 const char *glxExtensions;
131 char wglExtensions[4096];
134 struct wgl_pixel_format
136 GLXFBConfig fbconfig;
139 DWORD dwFlags; /* We store some PFD_* flags in here for emulated bitmap formats */
145 BOOL has_been_current;
149 const struct wgl_pixel_format *fmt;
150 int numAttribs; /* This is needed for delaying wglCreateContextAttribsARB */
151 int attribList[16]; /* This is needed for delaying wglCreateContextAttribsARB */
153 Drawable drawables[2];
154 BOOL refresh_drawables;
161 const struct wgl_pixel_format* fmt;
165 int use_render_texture; /* This is also the internal texture format */
166 int texture_bind_target;
168 GLint texture_format;
169 GLuint texture_target;
177 DC_GL_NONE, /* no GL support (pixel format not set yet) */
178 DC_GL_WINDOW, /* normal top-level window */
179 DC_GL_CHILD_WIN, /* child window using XComposite */
180 DC_GL_PIXMAP_WIN, /* child window using intermediate pixmap */
181 DC_GL_PBUFFER /* pseudo memory DC using a PBuffer */
186 enum dc_gl_type type; /* type of GL surface */
187 Drawable drawable; /* drawable for rendering to the client area */
188 Pixmap pixmap; /* base pixmap if drawable is a GLXPixmap */
189 Colormap colormap; /* colormap used for the drawable */
190 const struct wgl_pixel_format *format; /* pixel format for the drawable */
191 XVisualInfo *visual; /* information about the GL visual */
192 RECT rect; /* drawable rect, relative to whole window drawable */
195 /* X context to associate a struct gl_drawable to an hwnd */
196 static XContext gl_hwnd_context;
197 /* X context to associate a struct gl_drawable to a pbuffer hdc */
198 static XContext gl_pbuffer_context;
200 static const struct gdi_dc_funcs glxdrv_funcs;
202 static inline struct glx_physdev *get_glxdrv_dev( PHYSDEV dev )
204 return (struct glx_physdev *)dev;
207 static struct list context_list = LIST_INIT( context_list );
208 static struct WineGLInfo WineGLInfo = { 0 };
209 static struct wgl_pixel_format *pixel_formats;
210 static int nb_pixel_formats, nb_onscreen_formats;
211 static int use_render_texture_emulation = 1;
212 static BOOL has_swap_control;
213 static int swap_interval = 1;
215 static CRITICAL_SECTION context_section;
216 static CRITICAL_SECTION_DEBUG critsect_debug =
218 0, 0, &context_section,
219 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
220 0, 0, { (DWORD_PTR)(__FILE__ ": context_section") }
222 static CRITICAL_SECTION context_section = { &critsect_debug, -1, 0, 0, 0, 0 };
224 static struct opengl_funcs opengl_funcs;
226 #define USE_GL_FUNC(name) #name,
227 static const char *opengl_func_names[] = { ALL_WGL_FUNCS };
230 static void X11DRV_WineGL_LoadExtensions(void);
231 static void init_pixel_formats( Display *display );
232 static BOOL glxRequireVersion(int requiredVersion);
234 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
235 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
236 TRACE(" - dwFlags : ");
237 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
238 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
239 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
240 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
241 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
242 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
243 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
244 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
245 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
246 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
247 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
248 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
249 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
250 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
251 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
252 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
253 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
254 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
255 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
256 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
260 TRACE(" - iPixelType : ");
261 switch (ppfd->iPixelType) {
262 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
263 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
267 TRACE(" - Color : %d\n", ppfd->cColorBits);
268 TRACE(" - Red : %d\n", ppfd->cRedBits);
269 TRACE(" - Green : %d\n", ppfd->cGreenBits);
270 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
271 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
272 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
273 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
274 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
275 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
277 TRACE(" - iLayerType : ");
278 switch (ppfd->iLayerType) {
279 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
280 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
281 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
286 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
287 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
289 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
291 MAKE_FUNCPTR(glXChooseVisual)
292 MAKE_FUNCPTR(glXCopyContext)
293 MAKE_FUNCPTR(glXCreateContext)
294 MAKE_FUNCPTR(glXCreateGLXPixmap)
295 MAKE_FUNCPTR(glXGetCurrentContext)
296 MAKE_FUNCPTR(glXGetCurrentDrawable)
297 MAKE_FUNCPTR(glXDestroyContext)
298 MAKE_FUNCPTR(glXDestroyGLXPixmap)
299 MAKE_FUNCPTR(glXGetConfig)
300 MAKE_FUNCPTR(glXIsDirect)
301 MAKE_FUNCPTR(glXMakeCurrent)
302 MAKE_FUNCPTR(glXSwapBuffers)
303 MAKE_FUNCPTR(glXQueryExtension)
304 MAKE_FUNCPTR(glXQueryVersion)
307 MAKE_FUNCPTR(glXGetClientString)
308 MAKE_FUNCPTR(glXQueryExtensionsString)
309 MAKE_FUNCPTR(glXQueryServerString)
312 MAKE_FUNCPTR(glXGetFBConfigs)
313 MAKE_FUNCPTR(glXChooseFBConfig)
314 MAKE_FUNCPTR(glXCreatePbuffer)
315 MAKE_FUNCPTR(glXCreateNewContext)
316 MAKE_FUNCPTR(glXDestroyPbuffer)
317 MAKE_FUNCPTR(glXGetFBConfigAttrib)
318 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
319 MAKE_FUNCPTR(glXMakeContextCurrent)
320 MAKE_FUNCPTR(glXQueryDrawable)
321 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
325 static GLXContext (*pglXCreateContextAttribsARB)(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
326 static void* (*pglXGetProcAddressARB)(const GLubyte *);
327 static int (*pglXSwapIntervalSGI)(int);
329 /* NV GLX Extension */
330 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
331 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
333 /* MESA GLX Extensions */
334 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
336 /* Standard OpenGL */
337 static void (*pglFinish)(void);
338 static void (*pglFlush)(void);
340 static void wglFinish(void);
341 static void wglFlush(void);
343 /* check if the extension is present in the list */
344 static BOOL has_extension( const char *list, const char *ext )
346 size_t len = strlen( ext );
350 while (*list == ' ') list++;
351 if (!strncmp( list, ext, len ) && (!list[len] || list[len] == ' ')) return TRUE;
352 list = strchr( list, ' ' );
357 static int GLXErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
359 /* In the future we might want to find the exact X or GLX error to report back to the app */
363 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
365 int screen = DefaultScreen(gdi_display);
366 Window win = 0, root = 0;
367 const char *gl_renderer;
370 GLXContext ctx = NULL;
371 XSetWindowAttributes attr;
373 int attribList[] = {GLX_RGBA, GLX_DOUBLEBUFFER, None};
375 attr.override_redirect = True;
376 attr.colormap = None;
377 attr.border_pixel = 0;
379 vis = pglXChooseVisual(gdi_display, screen, attribList);
382 WORD old_fs = wine_get_fs();
383 /* Create a GLX Context. Without one we can't query GL information */
384 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
385 if (wine_get_fs() != old_fs)
387 wine_set_fs( old_fs );
388 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
389 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
393 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
398 root = RootWindow( gdi_display, vis->screen );
399 if (vis->visual != DefaultVisual( gdi_display, vis->screen ))
400 attr.colormap = XCreateColormap( gdi_display, root, vis->visual, AllocNone );
401 if ((win = XCreateWindow( gdi_display, root, -1, -1, 1, 1, 0, vis->depth, InputOutput,
402 vis->visual, CWBorderPixel | CWOverrideRedirect | CWColormap, &attr )))
403 XMapWindow( gdi_display, win );
407 if(pglXMakeCurrent(gdi_display, win, ctx) == 0)
409 ERR_(winediag)( "Unable to activate OpenGL context, most likely your OpenGL drivers haven't been installed correctly\n" );
412 gl_renderer = (const char *)opengl_funcs.gl.p_glGetString(GL_RENDERER);
413 WineGLInfo.glVersion = (const char *) opengl_funcs.gl.p_glGetString(GL_VERSION);
414 str = (const char *) opengl_funcs.gl.p_glGetString(GL_EXTENSIONS);
415 WineGLInfo.glExtensions = HeapAlloc(GetProcessHeap(), 0, strlen(str)+1);
416 strcpy(WineGLInfo.glExtensions, str);
418 /* Get the common GLX version supported by GLX client and server ( major/minor) */
419 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
421 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
422 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
423 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
425 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
426 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
427 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
429 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
430 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
432 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
433 TRACE("GL renderer : %s.\n", gl_renderer);
434 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
435 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
436 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
437 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
438 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
439 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
441 if(!WineGLInfo.glxDirect)
443 int fd = ConnectionNumber(gdi_display);
444 struct sockaddr_un uaddr;
445 unsigned int uaddrlen = sizeof(struct sockaddr_un);
447 /* In general indirect rendering on a local X11 server indicates a driver problem.
448 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
450 if(!getsockname(fd, (struct sockaddr *)&uaddr, &uaddrlen) && uaddr.sun_family == AF_UNIX)
451 ERR_(winediag)("Direct rendering is disabled, most likely your OpenGL drivers "
452 "haven't been installed correctly (using GL renderer %s, version %s).\n",
453 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
457 /* In general you would expect that if direct rendering is returned, that you receive hardware
458 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
459 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
460 * software rendering, it shows direct rendering.
462 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
463 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
464 * it shows 'Mesa X11'.
466 if(!strcmp(gl_renderer, "Software Rasterizer") || !strcmp(gl_renderer, "Mesa X11"))
467 ERR_(winediag)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL "
468 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
469 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
476 pglXMakeCurrent(gdi_display, None, NULL);
477 pglXDestroyContext(gdi_display, ctx);
479 if (win != root) XDestroyWindow( gdi_display, win );
480 if (attr.colormap) XFreeColormap( gdi_display, attr.colormap );
481 if (!ret) ERR(" couldn't initialize OpenGL, expect problems\n");
485 static BOOL has_opengl(void)
487 static int init_done;
488 static void *opengl_handle;
491 int error_base, event_base;
494 if (init_done) return (opengl_handle != NULL);
497 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
498 and include all dependencies */
499 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, buffer, sizeof(buffer));
500 if (opengl_handle == NULL)
502 ERR( "Failed to load libGL: %s\n", buffer );
503 ERR( "OpenGL support is disabled.\n");
507 for (i = 0; i < sizeof(opengl_func_names)/sizeof(opengl_func_names[0]); i++)
509 if (!(((void **)&opengl_funcs.gl)[i] = wine_dlsym( opengl_handle, opengl_func_names[i], NULL, 0 )))
511 ERR( "%s not found in libGL, disabling OpenGL.\n", opengl_func_names[i] );
516 /* redirect some standard OpenGL functions */
517 #define REDIRECT(func) \
518 do { p##func = opengl_funcs.gl.p_##func; opengl_funcs.gl.p_##func = w##func; } while(0)
519 REDIRECT( glFinish );
523 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
524 if (pglXGetProcAddressARB == NULL) {
525 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
529 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
531 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
536 LOAD_FUNCPTR(glXChooseVisual);
537 LOAD_FUNCPTR(glXCopyContext);
538 LOAD_FUNCPTR(glXCreateContext);
539 LOAD_FUNCPTR(glXCreateGLXPixmap);
540 LOAD_FUNCPTR(glXGetCurrentContext);
541 LOAD_FUNCPTR(glXGetCurrentDrawable);
542 LOAD_FUNCPTR(glXDestroyContext);
543 LOAD_FUNCPTR(glXDestroyGLXPixmap);
544 LOAD_FUNCPTR(glXGetConfig);
545 LOAD_FUNCPTR(glXIsDirect);
546 LOAD_FUNCPTR(glXMakeCurrent);
547 LOAD_FUNCPTR(glXSwapBuffers);
548 LOAD_FUNCPTR(glXQueryExtension);
549 LOAD_FUNCPTR(glXQueryVersion);
552 LOAD_FUNCPTR(glXGetClientString);
553 LOAD_FUNCPTR(glXQueryExtensionsString);
554 LOAD_FUNCPTR(glXQueryServerString);
557 LOAD_FUNCPTR(glXCreatePbuffer);
558 LOAD_FUNCPTR(glXCreateNewContext);
559 LOAD_FUNCPTR(glXDestroyPbuffer);
560 LOAD_FUNCPTR(glXMakeContextCurrent);
561 LOAD_FUNCPTR(glXGetCurrentReadDrawable);
562 LOAD_FUNCPTR(glXGetFBConfigs);
565 /* It doesn't matter if these fail. They'll only be used if the driver reports
566 the associated extension is available (and if a driver reports the extension
567 is available but fails to provide the functions, it's quite broken) */
568 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
569 /* ARB GLX Extension */
570 LOAD_FUNCPTR(glXCreateContextAttribsARB);
571 /* SGI GLX Extension */
572 LOAD_FUNCPTR(glXSwapIntervalSGI);
573 /* NV GLX Extension */
574 LOAD_FUNCPTR(glXAllocateMemoryNV);
575 LOAD_FUNCPTR(glXFreeMemoryNV);
578 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed;
580 if (pglXQueryExtension(gdi_display, &error_base, &event_base)) {
581 TRACE("GLX is up and running error_base = %d\n", error_base);
583 ERR( "GLX extension is missing, disabling OpenGL.\n" );
586 gl_hwnd_context = XUniqueContext();
587 gl_pbuffer_context = XUniqueContext();
589 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
590 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
593 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
594 * depends on the reported GLX client / server version and on the client / server extension list.
595 * Those don't have to be the same.
597 * In general the server GLX information lists the capabilities in case of indirect rendering.
598 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
599 * available and in that case the client GLX informat can be used.
600 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
601 * in the GLX version/extension list. When a program does this it works for certain for both
602 * direct and indirect rendering.
604 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
605 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
606 * extension list which causes this extension not to be listed. (Wine requires this extension).
607 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
608 * pbuffers is around.
610 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
611 * the ATI drivers and from then on use GLX client information for them.
614 if(glxRequireVersion(3)) {
615 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
616 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
617 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
618 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
619 } else if (has_extension( WineGLInfo.glxExtensions, "GLX_SGIX_fbconfig")) {
620 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
621 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
622 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
624 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
625 * enable this function when the Xserver understand GLX 1.3 or newer
627 pglXQueryDrawable = NULL;
628 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
629 TRACE("Overriding ATI GLX capabilities!\n");
630 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
631 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
632 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
633 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
635 /* Use client GLX information in case of the ATI drivers. We override the
636 * capabilities over here and not somewhere else as ATI might better their
637 * life in the future. In case they release proper drivers this block of
638 * code won't be called. */
639 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
641 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
644 if (has_extension( WineGLInfo.glxExtensions, "GLX_MESA_copy_sub_buffer")) {
645 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
648 X11DRV_WineGL_LoadExtensions();
649 init_pixel_formats( gdi_display );
653 wine_dlclose(opengl_handle, NULL, 0);
654 opengl_handle = NULL;
658 static int describeContext( struct wgl_context *ctx ) {
661 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
662 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
663 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
664 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
665 TRACE(" - VISUAL_ID 0x%x\n", tmp);
670 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, struct wgl_pbuffer* pbuf) {
675 int nvfloatattrib = GLX_DONT_CARE;
676 int pixelattrib = GLX_DONT_CARE;
678 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
679 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
680 while (iWGLAttr && 0 != iWGLAttr[cur]) {
681 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
683 switch (iWGLAttr[cur]) {
684 case WGL_AUX_BUFFERS_ARB:
685 pop = iWGLAttr[++cur];
686 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
687 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
689 case WGL_COLOR_BITS_ARB:
690 pop = iWGLAttr[++cur];
691 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
692 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
694 case WGL_BLUE_BITS_ARB:
695 pop = iWGLAttr[++cur];
696 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
697 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
699 case WGL_RED_BITS_ARB:
700 pop = iWGLAttr[++cur];
701 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
702 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
704 case WGL_GREEN_BITS_ARB:
705 pop = iWGLAttr[++cur];
706 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
707 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
709 case WGL_ALPHA_BITS_ARB:
710 pop = iWGLAttr[++cur];
711 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
712 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
714 case WGL_DEPTH_BITS_ARB:
715 pop = iWGLAttr[++cur];
716 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
717 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
719 case WGL_STENCIL_BITS_ARB:
720 pop = iWGLAttr[++cur];
721 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
722 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
724 case WGL_DOUBLE_BUFFER_ARB:
725 pop = iWGLAttr[++cur];
726 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
727 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
730 pop = iWGLAttr[++cur];
731 PUSH2(oGLXAttr, GLX_STEREO, pop);
732 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur, pop);
735 case WGL_PIXEL_TYPE_ARB:
736 pop = iWGLAttr[++cur];
737 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
739 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
740 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
741 /* This is the same as WGL_TYPE_RGBA_FLOAT_ATI but the GLX constants differ, only the ARB GLX one is widely supported so use that */
742 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
743 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT: pixelattrib = GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT; break ;
745 ERR("unexpected PixelType(%x)\n", pop);
750 case WGL_SUPPORT_GDI_ARB:
751 /* This flag is set in a pixel format */
752 pop = iWGLAttr[++cur];
753 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
756 case WGL_DRAW_TO_BITMAP_ARB:
757 /* This flag is set in a pixel format */
758 pop = iWGLAttr[++cur];
759 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
762 case WGL_DRAW_TO_WINDOW_ARB:
763 pop = iWGLAttr[++cur];
764 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
765 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
767 drawattrib |= GLX_WINDOW_BIT;
771 case WGL_DRAW_TO_PBUFFER_ARB:
772 pop = iWGLAttr[++cur];
773 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
774 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
776 drawattrib |= GLX_PBUFFER_BIT;
780 case WGL_ACCELERATION_ARB:
781 /* This flag is set in a pixel format */
782 pop = iWGLAttr[++cur];
783 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur, pop);
786 case WGL_SUPPORT_OPENGL_ARB:
787 pop = iWGLAttr[++cur];
788 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
789 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
792 case WGL_SWAP_METHOD_ARB:
793 pop = iWGLAttr[++cur];
794 /* For now we ignore this and just return SWAP_EXCHANGE */
795 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur, pop);
798 case WGL_PBUFFER_LARGEST_ARB:
799 pop = iWGLAttr[++cur];
800 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
801 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
804 case WGL_SAMPLE_BUFFERS_ARB:
805 pop = iWGLAttr[++cur];
806 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
807 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
810 case WGL_SAMPLES_ARB:
811 pop = iWGLAttr[++cur];
812 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
813 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
816 case WGL_TEXTURE_FORMAT_ARB:
817 case WGL_TEXTURE_TARGET_ARB:
818 case WGL_MIPMAP_TEXTURE_ARB:
819 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
820 pop = iWGLAttr[++cur];
822 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
824 if (!use_render_texture_emulation) {
825 if (WGL_NO_TEXTURE_ARB != pop) {
826 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
827 return -1; /** error: don't support it */
829 drawattrib |= GLX_PBUFFER_BIT;
833 case WGL_FLOAT_COMPONENTS_NV:
834 nvfloatattrib = iWGLAttr[++cur];
835 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
837 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
838 case WGL_BIND_TO_TEXTURE_RGB_ARB:
839 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
840 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
841 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
842 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
843 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
844 pop = iWGLAttr[++cur];
845 /** cannot be converted, see direct handling on
846 * - wglGetPixelFormatAttribivARB
847 * TODO: wglChoosePixelFormat
850 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
851 pop = iWGLAttr[++cur];
852 PUSH2(oGLXAttr, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, pop);
853 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur, pop);
856 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
857 pop = iWGLAttr[++cur];
858 PUSH2(oGLXAttr, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT, pop);
859 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur, pop);
862 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
868 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
869 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
870 * pixmap and pbuffer formats appear as well. */
871 if (!drawattrib) drawattrib = GLX_DONT_CARE;
872 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
873 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
875 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
876 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
877 * GLX_DONT_CARE unless it is overridden. */
878 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
879 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
881 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
882 if (has_extension(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
883 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
884 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
890 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
892 int render_type=0, render_type_bit;
893 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
894 switch(render_type_bit)
897 render_type = GLX_RGBA_TYPE;
899 case GLX_COLOR_INDEX_BIT:
900 render_type = GLX_COLOR_INDEX_TYPE;
902 case GLX_RGBA_FLOAT_BIT:
903 render_type = GLX_RGBA_FLOAT_TYPE;
905 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT:
906 render_type = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
909 ERR("Unknown render_type: %x\n", render_type_bit);
914 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
915 static BOOL check_fbconfig_bitmap_capability(Display *display, GLXFBConfig fbconfig)
918 pglXGetFBConfigAttrib(display, fbconfig, GLX_DOUBLEBUFFER, &dbuf);
919 pglXGetFBConfigAttrib(gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &value);
921 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
922 * the GLX_PIXMAP_BIT set. */
923 return !dbuf && (value & GLX_PIXMAP_BIT);
926 static void init_pixel_formats( Display *display )
928 struct wgl_pixel_format *list;
929 int size = 0, onscreen_size = 0;
930 int fmt_id, nCfgs, i, run, bmp_formats;
932 XVisualInfo *visinfo;
934 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
935 if (NULL == cfgs || 0 == nCfgs) {
936 if(cfgs != NULL) XFree(cfgs);
937 ERR("glXChooseFBConfig returns NULL\n");
941 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
942 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
943 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
944 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
946 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
948 for(i=0, bmp_formats=0; i<nCfgs; i++)
950 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
953 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats);
955 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nCfgs + bmp_formats) * sizeof(*list));
957 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
958 * Do this as GLX doesn't guarantee that the list is sorted */
959 for(run=0; run < 2; run++)
961 for(i=0; i<nCfgs; i++) {
962 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
963 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
965 /* The first run we only add onscreen formats (ones which have an associated X Visual).
966 * The second run we only set offscreen formats. */
969 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
970 * The contents is copied to the destination using XCopyArea. For the copying to work
971 * the depth of the source and destination window should be the same. In general this should
972 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
973 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
974 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
975 * list formats with the same depth. */
976 if(visinfo->depth != default_visual.depth)
982 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
983 list[size].fbconfig = cfgs[i];
984 list[size].fmt_id = fmt_id;
985 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
986 list[size].dwFlags = 0;
990 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
991 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
993 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
994 list[size].fbconfig = cfgs[i];
995 list[size].fmt_id = fmt_id;
996 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
997 list[size].dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_GENERIC_FORMAT;
1001 } else if(run && !visinfo) {
1002 int window_drawable=0;
1003 pglXGetFBConfigAttrib(gdi_display, cfgs[i], GLX_DRAWABLE_TYPE, &window_drawable);
1005 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
1006 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1007 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1008 * likely make our child window opengl rendering more complicated since likely you can't use
1009 * XCopyArea on a GLX Window.
1010 * For now ignore fbconfigs which are window drawable but lack a visual. */
1011 if(window_drawable & GLX_WINDOW_BIT)
1013 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id);
1017 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1018 list[size].fbconfig = cfgs[i];
1019 list[size].fmt_id = fmt_id;
1020 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1021 list[size].dwFlags = 0;
1025 if (visinfo) XFree(visinfo);
1031 pixel_formats = list;
1032 nb_pixel_formats = size;
1033 nb_onscreen_formats = onscreen_size;
1036 static inline BOOL is_valid_pixel_format( int format )
1038 return format > 0 && format <= nb_pixel_formats;
1041 static inline BOOL is_onscreen_pixel_format( int format )
1043 return format > 0 && format <= nb_onscreen_formats;
1046 static inline int pixel_format_index( const struct wgl_pixel_format *format )
1048 return format - pixel_formats + 1;
1051 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1052 * In our WGL implementation we only support a subset of these formats namely the format of
1053 * Wine's main visual and offscreen formats (if they are available).
1054 * This function converts a WGL format to its corresponding GLX one.
1056 static const struct wgl_pixel_format *get_pixel_format(Display *display, int iPixelFormat, BOOL AllowOffscreen)
1058 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1059 * iPixelFormat in case of probing the number of pixelformats.
1061 if (is_valid_pixel_format( iPixelFormat ) &&
1062 (is_onscreen_pixel_format( iPixelFormat ) || AllowOffscreen)) {
1063 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n",
1064 pixel_formats[iPixelFormat-1].fmt_id, iPixelFormat);
1065 return &pixel_formats[iPixelFormat-1];
1070 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1071 static void mark_drawable_dirty(Drawable old, Drawable new)
1073 struct wgl_context *ctx;
1075 LIST_FOR_EACH_ENTRY( ctx, &context_list, struct wgl_context, entry )
1077 if (old == ctx->drawables[0]) {
1078 ctx->drawables[0] = new;
1079 ctx->refresh_drawables = TRUE;
1081 if (old == ctx->drawables[1]) {
1082 ctx->drawables[1] = new;
1083 ctx->refresh_drawables = TRUE;
1088 /* Given the current context, make sure its drawable is sync'd */
1089 static inline void sync_context(struct wgl_context *context)
1091 if (context->refresh_drawables) {
1092 if (glxRequireVersion(3))
1093 pglXMakeContextCurrent(gdi_display, context->drawables[0],
1094 context->drawables[1], context->ctx);
1096 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
1097 context->refresh_drawables = FALSE;
1101 static struct gl_drawable *get_gl_drawable( HWND hwnd, HDC hdc )
1103 struct gl_drawable *gl;
1105 EnterCriticalSection( &context_section );
1106 if (hwnd && !XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl )) return gl;
1107 if (hdc && !XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl )) return gl;
1108 LeaveCriticalSection( &context_section );
1112 static void release_gl_drawable( struct gl_drawable *gl )
1114 if (gl) LeaveCriticalSection( &context_section );
1117 static GLXContext create_glxcontext(Display *display, struct wgl_context *context, GLXContext shareList)
1121 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1122 BOOL indirect = !(context->fmt->dwFlags & PFD_DRAW_TO_BITMAP);
1124 if(context->gl3_context)
1126 if(context->numAttribs)
1127 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, context->attribList);
1129 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, NULL);
1131 else if(context->vis)
1132 ctx = pglXCreateContext(gdi_display, context->vis, shareList, indirect);
1133 else /* Create a GLX Context for a pbuffer */
1134 ctx = pglXCreateNewContext(gdi_display, context->fmt->fbconfig, context->fmt->render_type, shareList, TRUE);
1140 /***********************************************************************
1143 static void free_gl_drawable( struct gl_drawable *gl )
1148 case DC_GL_CHILD_WIN:
1149 XDestroyWindow( gdi_display, gl->drawable );
1150 XFreeColormap( gdi_display, gl->colormap );
1152 case DC_GL_PIXMAP_WIN:
1153 pglXDestroyGLXPixmap( gdi_display, gl->drawable );
1154 XFreePixmap( gdi_display, gl->pixmap );
1159 if (gl->visual) XFree( gl->visual );
1160 HeapFree( GetProcessHeap(), 0, gl );
1164 /***********************************************************************
1165 * create_gl_drawable
1167 static BOOL create_gl_drawable( HWND hwnd, HWND parent, struct gl_drawable *gl )
1169 XSetWindowAttributes attrib;
1173 if (parent == GetDesktopWindow()) /* top-level window */
1175 Window xparent = X11DRV_get_whole_window( hwnd );
1177 gl->type = DC_GL_WINDOW;
1178 gl->colormap = XCreateColormap( gdi_display, root_window, gl->visual->visual,
1179 (gl->visual->class == PseudoColor ||
1180 gl->visual->class == GrayScale ||
1181 gl->visual->class == DirectColor) ? AllocAll : AllocNone );
1182 attrib.colormap = gl->colormap;
1183 attrib.bit_gravity = NorthWestGravity;
1184 attrib.win_gravity = NorthWestGravity;
1185 attrib.backing_store = NotUseful;
1186 /* put the initial rect outside of the window, it will be moved into place by SetWindowPos */
1187 OffsetRect( &gl->rect, gl->rect.right, gl->rect.bottom );
1189 gl->drawable = XCreateWindow( gdi_display, xparent, gl->rect.left, gl->rect.top,
1190 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top,
1191 0, default_visual.depth, InputOutput, gl->visual->visual,
1192 CWBitGravity | CWWinGravity | CWBackingStore | CWColormap,
1195 XMapWindow( gdi_display, gl->drawable );
1197 XFreeColormap( gdi_display, gl->colormap );
1199 else if (!GetAncestor( parent, GA_PARENT ))
1201 FIXME( "can't set format of HWND_MESSAGE window %p\n", hwnd );
1203 #ifdef SONAME_LIBXCOMPOSITE
1204 else if(usexcomposite)
1206 static Window dummy_parent;
1208 attrib.override_redirect = True;
1211 dummy_parent = XCreateWindow( gdi_display, root_window, -1, -1, 1, 1, 0, default_visual.depth,
1212 InputOutput, default_visual.visual, CWOverrideRedirect, &attrib );
1213 XMapWindow( gdi_display, dummy_parent );
1215 gl->colormap = XCreateColormap(gdi_display, dummy_parent, gl->visual->visual,
1216 (gl->visual->class == PseudoColor ||
1217 gl->visual->class == GrayScale ||
1218 gl->visual->class == DirectColor) ?
1219 AllocAll : AllocNone);
1220 attrib.colormap = gl->colormap;
1221 XInstallColormap(gdi_display, attrib.colormap);
1223 gl->type = DC_GL_CHILD_WIN;
1224 gl->drawable = XCreateWindow( gdi_display, dummy_parent, 0, 0,
1225 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top,
1226 0, gl->visual->depth, InputOutput, gl->visual->visual,
1227 CWColormap | CWOverrideRedirect, &attrib );
1230 pXCompositeRedirectWindow(gdi_display, gl->drawable, CompositeRedirectManual);
1231 XMapWindow(gdi_display, gl->drawable);
1233 else XFreeColormap( gdi_display, gl->colormap );
1238 WARN("XComposite is not available, using GLXPixmap hack\n");
1240 gl->type = DC_GL_PIXMAP_WIN;
1241 gl->pixmap = XCreatePixmap( gdi_display, root_window,
1242 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top,
1243 gl->visual->depth );
1246 gl->drawable = pglXCreateGLXPixmap( gdi_display, gl->visual, gl->pixmap );
1247 if (!gl->drawable) XFreePixmap( gdi_display, gl->pixmap );
1251 return gl->drawable != 0;
1255 /***********************************************************************
1258 static BOOL set_win_format( HWND hwnd, const struct wgl_pixel_format *format )
1260 HWND parent = GetAncestor( hwnd, GA_PARENT );
1261 struct gl_drawable *gl, *prev;
1263 gl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*gl) );
1264 gl->format = format;
1265 gl->visual = pglXGetVisualFromFBConfig( gdi_display, format->fbconfig );
1268 HeapFree( GetProcessHeap(), 0, gl );
1272 GetClientRect( hwnd, &gl->rect );
1273 gl->rect.right = min( max( 1, gl->rect.right ), 65535 );
1274 gl->rect.bottom = min( max( 1, gl->rect.bottom ), 65535 );
1276 if (!create_gl_drawable( hwnd, parent, gl ))
1278 XFree( gl->visual );
1279 HeapFree( GetProcessHeap(), 0, gl );
1283 TRACE("created GL drawable %lx for win %p format %x\n", gl->drawable, hwnd, format->fmt_id );
1285 XFlush( gdi_display );
1287 EnterCriticalSection( &context_section );
1288 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&prev ))
1289 free_gl_drawable( prev );
1290 XSaveContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char *)gl );
1291 LeaveCriticalSection( &context_section );
1293 __wine_set_pixel_format( hwnd, pixel_format_index( format ));
1297 /***********************************************************************
1300 void sync_gl_drawable( HWND hwnd, const RECT *visible_rect, const RECT *client_rect )
1302 struct gl_drawable *gl;
1306 XWindowChanges changes;
1308 changes.x = client_rect->left - visible_rect->left;
1309 changes.y = client_rect->top - visible_rect->top;
1310 changes.width = min( max( 1, client_rect->right - client_rect->left ), 65535 );
1311 changes.height = min( max( 1, client_rect->bottom - client_rect->top ), 65535 );
1313 if (!(gl = get_gl_drawable( hwnd, 0 ))) return;
1315 if (changes.width != gl->rect.right - gl->rect.left) mask |= CWWidth;
1316 if (changes.height != gl->rect.bottom - gl->rect.top) mask |= CWHeight;
1318 TRACE( "setting drawable %lx pos %d,%d,%dx%d\n",
1319 gl->drawable, changes.x, changes.y, changes.width, changes.height );
1324 if (changes.x != gl->rect.left) mask |= CWX;
1325 if (changes.y != gl->rect.top) mask |= CWY;
1327 case DC_GL_CHILD_WIN:
1328 if (mask) XConfigureWindow( gdi_display, gl->drawable, mask, &changes );
1330 case DC_GL_PIXMAP_WIN:
1332 pix = XCreatePixmap(gdi_display, root_window, changes.width, changes.height, gl->visual->depth);
1333 if (!pix) goto done;
1334 glxp = pglXCreateGLXPixmap(gdi_display, gl->visual, pix);
1337 XFreePixmap(gdi_display, pix);
1340 mark_drawable_dirty(gl->drawable, glxp);
1341 XFlush( gdi_display );
1343 XFreePixmap(gdi_display, gl->pixmap);
1344 pglXDestroyGLXPixmap(gdi_display, gl->drawable);
1345 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp, gl->drawable );
1348 gl->drawable = glxp;
1353 SetRect( &gl->rect, changes.x, changes.y, changes.x + changes.width, changes.y + changes.height );
1355 release_gl_drawable( gl );
1359 /***********************************************************************
1360 * set_gl_drawable_parent
1362 void set_gl_drawable_parent( HWND hwnd, HWND parent )
1364 struct gl_drawable *gl;
1365 Drawable old_drawable;
1367 if (!(gl = get_gl_drawable( hwnd, 0 ))) return;
1369 TRACE( "setting drawable %lx parent %p\n", gl->drawable, parent );
1371 old_drawable = gl->drawable;
1375 XDestroyWindow( gdi_display, gl->drawable );
1376 XFreeColormap( gdi_display, gl->colormap );
1378 case DC_GL_CHILD_WIN:
1379 if (parent != GetDesktopWindow()) goto done;
1380 XDestroyWindow( gdi_display, gl->drawable );
1381 XFreeColormap( gdi_display, gl->colormap );
1383 case DC_GL_PIXMAP_WIN:
1384 if (parent != GetDesktopWindow()) goto done;
1385 pglXDestroyGLXPixmap( gdi_display, gl->drawable );
1386 XFreePixmap( gdi_display, gl->pixmap );
1392 if (!create_gl_drawable( hwnd, parent, gl ))
1394 XDeleteContext( gdi_display, (XID)hwnd, gl_hwnd_context );
1395 release_gl_drawable( gl );
1396 XFree( gl->visual );
1397 HeapFree( GetProcessHeap(), 0, gl );
1398 __wine_set_pixel_format( hwnd, 0 );
1401 mark_drawable_dirty( old_drawable, gl->drawable );
1404 release_gl_drawable( gl );
1409 /***********************************************************************
1410 * destroy_gl_drawable
1412 void destroy_gl_drawable( HWND hwnd )
1414 struct gl_drawable *gl;
1416 EnterCriticalSection( &context_section );
1417 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl ))
1419 XDeleteContext( gdi_display, (XID)hwnd, gl_hwnd_context );
1420 free_gl_drawable( gl );
1422 LeaveCriticalSection( &context_section );
1427 * glxdrv_DescribePixelFormat
1429 * Get the pixel-format descriptor associated to the given id
1431 static int glxdrv_wglDescribePixelFormat( HDC hdc, int iPixelFormat,
1432 UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd)
1434 /*XVisualInfo *vis;*/
1437 const struct wgl_pixel_format *fmt;
1439 if (!has_opengl()) return 0;
1441 TRACE("(%p,%d,%d,%p)\n", hdc, iPixelFormat, nBytes, ppfd);
1443 if (!ppfd) return nb_onscreen_formats;
1445 /* 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 */
1446 fmt = get_pixel_format(gdi_display, iPixelFormat, FALSE /* Offscreen */);
1448 WARN("unexpected format %d\n", iPixelFormat);
1452 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1453 ERR("Wrong structure size !\n");
1454 /* Should set error */
1458 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1459 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1462 /* These flags are always the same... */
1463 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1464 /* Now the flags extracted from the Visual */
1466 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1467 if(value & GLX_WINDOW_BIT)
1468 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1470 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1471 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1472 * Radeon 9000 indicated that all bitmap formats have PFD_SUPPORT_GDI. Except for 2 formats on the Radeon 9000 none of the hw accelerated formats
1473 * offered the GDI bit either. */
1474 ppfd->dwFlags |= fmt->dwFlags & (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI);
1476 /* PFD_GENERIC_FORMAT - gdi software rendering
1477 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1478 * none set - full hardware accelerated by a ICD
1480 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1481 ppfd->dwFlags |= fmt->dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED);
1483 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1485 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1486 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1488 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1491 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1492 if (value & GLX_RGBA_BIT)
1493 ppfd->iPixelType = PFD_TYPE_RGBA;
1495 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1498 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1499 ppfd->cColorBits = value;
1501 /* Red, green, blue and alpha bits / shifts */
1502 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1503 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1504 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1505 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1506 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1508 ppfd->cRedBits = rb;
1509 ppfd->cRedShift = gb + bb + ab;
1510 ppfd->cBlueBits = bb;
1511 ppfd->cBlueShift = ab;
1512 ppfd->cGreenBits = gb;
1513 ppfd->cGreenShift = bb + ab;
1514 ppfd->cAlphaBits = ab;
1515 ppfd->cAlphaShift = 0;
1518 ppfd->cRedShift = 0;
1519 ppfd->cBlueBits = 0;
1520 ppfd->cBlueShift = 0;
1521 ppfd->cGreenBits = 0;
1522 ppfd->cGreenShift = 0;
1523 ppfd->cAlphaBits = 0;
1524 ppfd->cAlphaShift = 0;
1527 /* Accum RGBA bits */
1528 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1529 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1530 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1531 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1533 ppfd->cAccumBits = rb+gb+bb+ab;
1534 ppfd->cAccumRedBits = rb;
1535 ppfd->cAccumGreenBits = gb;
1536 ppfd->cAccumBlueBits = bb;
1537 ppfd->cAccumAlphaBits = ab;
1540 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1541 ppfd->cAuxBuffers = value;
1544 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1545 ppfd->cDepthBits = value;
1548 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1549 ppfd->cStencilBits = value;
1551 ppfd->iLayerType = PFD_MAIN_PLANE;
1553 if (TRACE_ON(wgl)) {
1554 dump_PIXELFORMATDESCRIPTOR(ppfd);
1557 return nb_onscreen_formats;
1560 /***********************************************************************
1561 * glxdrv_wglGetPixelFormat
1563 static int glxdrv_wglGetPixelFormat( HDC hdc )
1565 struct gl_drawable *gl;
1568 if ((gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1570 ret = pixel_format_index( gl->format );
1571 /* Offscreen formats can't be used with traditional WGL calls.
1572 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1573 if (!is_onscreen_pixel_format( ret )) ret = 1;
1574 release_gl_drawable( gl );
1576 TRACE( "%p -> %d\n", hdc, ret );
1580 /***********************************************************************
1581 * glxdrv_wglSetPixelFormat
1583 static BOOL glxdrv_wglSetPixelFormat( HDC hdc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd )
1585 const struct wgl_pixel_format *fmt;
1587 struct gl_drawable *gl;
1588 HWND hwnd = WindowFromDC( hdc );
1590 TRACE("(%p,%d,%p)\n", hdc, iPixelFormat, ppfd);
1592 if (!hwnd || hwnd == GetDesktopWindow())
1594 WARN( "not a proper window DC %p/%p\n", hdc, hwnd );
1598 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1599 fmt = get_pixel_format(gdi_display, iPixelFormat, FALSE /* Offscreen */);
1601 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1605 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1606 if (!(value & GLX_WINDOW_BIT))
1608 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1612 if ((gl = get_gl_drawable( hwnd, hdc )))
1614 int prev = pixel_format_index( gl->format );
1615 release_gl_drawable( gl );
1616 return prev == iPixelFormat; /* cannot change it if already set */
1619 if (TRACE_ON(wgl)) {
1622 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1624 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1626 TRACE(" FBConfig have :\n");
1627 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1628 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1629 TRACE(" - VISUAL_ID 0x%x\n", value);
1630 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1631 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1635 return set_win_format( hwnd, fmt );
1638 /***********************************************************************
1639 * glxdrv_wglCopyContext
1641 static BOOL glxdrv_wglCopyContext(struct wgl_context *src, struct wgl_context *dst, UINT mask)
1643 TRACE("%p -> %p mask %#x\n", src, dst, mask);
1645 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1647 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1651 /***********************************************************************
1652 * glxdrv_wglCreateContext
1654 static struct wgl_context *glxdrv_wglCreateContext( HDC hdc )
1656 struct wgl_context *ret = NULL;
1657 struct gl_drawable *gl;
1659 if (!(gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1661 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1665 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret))))
1668 ret->fmt = gl->format;
1669 ret->vis = pglXGetVisualFromFBConfig(gdi_display, gl->format->fbconfig);
1670 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1671 list_add_head( &context_list, &ret->entry );
1673 release_gl_drawable( gl );
1674 TRACE( "%p -> %p\n", hdc, ret );
1678 /***********************************************************************
1679 * glxdrv_wglDeleteContext
1681 static void glxdrv_wglDeleteContext(struct wgl_context *ctx)
1683 TRACE("(%p)\n", ctx);
1685 EnterCriticalSection( &context_section );
1686 list_remove( &ctx->entry );
1687 LeaveCriticalSection( &context_section );
1689 if (ctx->ctx) pglXDestroyContext( gdi_display, ctx->ctx );
1690 if (ctx->vis) XFree( ctx->vis );
1691 HeapFree( GetProcessHeap(), 0, ctx );
1694 /***********************************************************************
1695 * glxdrv_wglGetProcAddress
1697 static PROC glxdrv_wglGetProcAddress(LPCSTR lpszProc)
1699 if (!strncmp(lpszProc, "wgl", 3)) return NULL;
1700 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1703 /***********************************************************************
1704 * glxdrv_wglMakeCurrent
1706 static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx)
1709 struct gl_drawable *gl;
1711 TRACE("(%p,%p)\n", hdc, ctx);
1715 pglXMakeCurrent(gdi_display, None, NULL);
1716 NtCurrentTeb()->glContext = NULL;
1720 if ((gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1722 if (ctx->fmt != gl->format)
1724 WARN( "mismatched pixel format hdc %p %p ctx %p %p\n", hdc, gl->format, ctx, ctx->fmt );
1725 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1729 if (TRACE_ON(wgl)) {
1730 describeContext(ctx);
1731 TRACE("hdc %p drawable %lx fmt %p ctx %p\n", hdc, gl->drawable, gl->format, ctx->ctx );
1734 ret = pglXMakeCurrent(gdi_display, gl->drawable, ctx->ctx);
1737 NtCurrentTeb()->glContext = ctx;
1738 ctx->has_been_current = TRUE;
1740 ctx->drawables[0] = gl->drawable;
1741 ctx->drawables[1] = gl->drawable;
1742 ctx->refresh_drawables = FALSE;
1746 SetLastError( ERROR_INVALID_HANDLE );
1749 release_gl_drawable( gl );
1750 TRACE( "%p,%p returning %d\n", hdc, ctx, ret );
1754 /***********************************************************************
1755 * X11DRV_wglMakeContextCurrentARB
1757 static BOOL X11DRV_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *ctx )
1760 struct gl_drawable *draw_gl, *read_gl = NULL;
1762 TRACE("(%p,%p,%p)\n", draw_hdc, read_hdc, ctx);
1766 pglXMakeCurrent(gdi_display, None, NULL);
1767 NtCurrentTeb()->glContext = NULL;
1771 if (!pglXMakeContextCurrent) return FALSE;
1773 if ((draw_gl = get_gl_drawable( WindowFromDC( draw_hdc ), draw_hdc )))
1775 read_gl = get_gl_drawable( WindowFromDC( read_hdc ), read_hdc );
1776 ret = pglXMakeContextCurrent(gdi_display, draw_gl->drawable,
1777 read_gl ? read_gl->drawable : 0, ctx->ctx);
1780 ctx->has_been_current = TRUE;
1781 ctx->hdc = draw_hdc;
1782 ctx->drawables[0] = draw_gl->drawable;
1783 ctx->drawables[1] = read_gl ? read_gl->drawable : 0;
1784 ctx->refresh_drawables = FALSE;
1785 NtCurrentTeb()->glContext = ctx;
1789 SetLastError( ERROR_INVALID_HANDLE );
1791 release_gl_drawable( read_gl );
1792 release_gl_drawable( draw_gl );
1793 TRACE( "%p,%p,%p returning %d\n", draw_hdc, read_hdc, ctx, ret );
1797 /***********************************************************************
1798 * glxdrv_wglShareLists
1800 static BOOL glxdrv_wglShareLists(struct wgl_context *org, struct wgl_context *dest)
1802 TRACE("(%p, %p)\n", org, dest);
1804 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1805 * at context creation time but in case of WGL it is done using wglShareLists.
1806 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1807 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1808 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1809 * so there delaying context creation doesn't work.
1811 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1812 * and when a program requests sharing we recreate the destination context if it hasn't been made
1813 * current or when it hasn't shared display lists before.
1816 if((org->has_been_current && dest->has_been_current) || dest->has_been_current)
1818 ERR("Could not share display lists, one of the contexts has been current already !\n");
1821 else if(dest->sharing)
1823 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1828 describeContext(org);
1829 describeContext(dest);
1831 /* Re-create the GLX context and share display lists */
1832 pglXDestroyContext(gdi_display, dest->ctx);
1833 dest->ctx = create_glxcontext(gdi_display, dest, org->ctx);
1834 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1836 org->sharing = TRUE;
1837 dest->sharing = TRUE;
1843 static void wglFinish(void)
1845 struct x11drv_escape_flush_gl_drawable escape;
1846 struct gl_drawable *gl;
1847 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1849 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
1850 escape.gl_drawable = 0;
1852 if ((gl = get_gl_drawable( WindowFromDC( ctx->hdc ), 0 )))
1856 case DC_GL_PIXMAP_WIN: escape.gl_drawable = gl->pixmap; break;
1857 case DC_GL_CHILD_WIN: escape.gl_drawable = gl->drawable; break;
1861 release_gl_drawable( gl );
1865 if (escape.gl_drawable) ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1868 static void wglFlush(void)
1870 struct x11drv_escape_flush_gl_drawable escape;
1871 struct gl_drawable *gl;
1872 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1874 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
1875 escape.gl_drawable = 0;
1877 if ((gl = get_gl_drawable( WindowFromDC( ctx->hdc ), 0 )))
1881 case DC_GL_PIXMAP_WIN: escape.gl_drawable = gl->pixmap; break;
1882 case DC_GL_CHILD_WIN: escape.gl_drawable = gl->drawable; break;
1886 release_gl_drawable( gl );
1890 if (escape.gl_drawable) ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1893 /***********************************************************************
1894 * X11DRV_wglCreateContextAttribsARB
1896 static struct wgl_context *X11DRV_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *hShareContext,
1897 const int* attribList )
1899 struct wgl_context *ret = NULL;
1900 struct gl_drawable *gl;
1902 TRACE("(%p %p %p)\n", hdc, hShareContext, attribList);
1904 if (!(gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1906 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1910 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret))))
1913 ret->fmt = gl->format;
1914 ret->vis = NULL; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
1915 ret->gl3_context = TRUE;
1916 ret->numAttribs = 0;
1919 int *pContextAttribList = &ret->attribList[0];
1920 /* attribList consists of pairs {token, value] terminated with 0 */
1921 while(attribList[0] != 0)
1923 TRACE("%#x %#x\n", attribList[0], attribList[1]);
1924 switch(attribList[0])
1926 case WGL_CONTEXT_MAJOR_VERSION_ARB:
1927 pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
1928 pContextAttribList[1] = attribList[1];
1930 case WGL_CONTEXT_MINOR_VERSION_ARB:
1931 pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB;
1932 pContextAttribList[1] = attribList[1];
1934 case WGL_CONTEXT_LAYER_PLANE_ARB:
1936 case WGL_CONTEXT_FLAGS_ARB:
1937 pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB;
1938 pContextAttribList[1] = attribList[1];
1940 case WGL_CONTEXT_PROFILE_MASK_ARB:
1941 pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
1942 pContextAttribList[1] = attribList[1];
1945 ERR("Unhandled attribList pair: %#x %#x\n", attribList[0], attribList[1]);
1949 pContextAttribList += 2;
1953 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
1954 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1955 XSync(gdi_display, False);
1956 if (X11DRV_check_error() || !ret->ctx)
1958 /* In the future we should convert the GLX error to a win32 one here if needed */
1959 ERR("Context creation failed\n");
1960 HeapFree( GetProcessHeap(), 0, ret );
1963 else list_add_head( &context_list, &ret->entry );
1966 release_gl_drawable( gl );
1967 TRACE( "%p -> %p\n", hdc, ret );
1972 * X11DRV_wglGetExtensionsStringARB
1974 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
1976 static const GLubyte *X11DRV_wglGetExtensionsStringARB(HDC hdc)
1978 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
1979 return (const GLubyte *)WineGLInfo.wglExtensions;
1983 * X11DRV_wglCreatePbufferARB
1985 * WGL_ARB_pbuffer: wglCreatePbufferARB
1987 static struct wgl_pbuffer *X11DRV_wglCreatePbufferARB( HDC hdc, int iPixelFormat, int iWidth, int iHeight,
1988 const int *piAttribList )
1990 struct wgl_pbuffer* object = NULL;
1991 const struct wgl_pixel_format *fmt = NULL;
1995 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
1997 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
1998 fmt = get_pixel_format(gdi_display, iPixelFormat, TRUE /* Offscreen */);
2000 ERR("(%p): invalid pixel format %d\n", hdc, iPixelFormat);
2001 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2005 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2006 if (NULL == object) {
2007 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2010 object->width = iWidth;
2011 object->height = iHeight;
2014 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2015 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2016 while (piAttribList && 0 != *piAttribList) {
2018 switch (*piAttribList) {
2019 case WGL_PBUFFER_LARGEST_ARB: {
2021 attr_v = *piAttribList;
2022 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2023 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2027 case WGL_TEXTURE_FORMAT_ARB: {
2029 attr_v = *piAttribList;
2030 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2031 if (WGL_NO_TEXTURE_ARB == attr_v) {
2032 object->use_render_texture = 0;
2034 if (!use_render_texture_emulation) {
2035 SetLastError(ERROR_INVALID_DATA);
2039 case WGL_TEXTURE_RGB_ARB:
2040 object->use_render_texture = GL_RGB;
2041 object->texture_bpp = 3;
2042 object->texture_format = GL_RGB;
2043 object->texture_type = GL_UNSIGNED_BYTE;
2045 case WGL_TEXTURE_RGBA_ARB:
2046 object->use_render_texture = GL_RGBA;
2047 object->texture_bpp = 4;
2048 object->texture_format = GL_RGBA;
2049 object->texture_type = GL_UNSIGNED_BYTE;
2052 /* WGL_FLOAT_COMPONENTS_NV */
2053 case WGL_TEXTURE_FLOAT_R_NV:
2054 object->use_render_texture = GL_FLOAT_R_NV;
2055 object->texture_bpp = 4;
2056 object->texture_format = GL_RED;
2057 object->texture_type = GL_FLOAT;
2059 case WGL_TEXTURE_FLOAT_RG_NV:
2060 object->use_render_texture = GL_FLOAT_RG_NV;
2061 object->texture_bpp = 8;
2062 object->texture_format = GL_LUMINANCE_ALPHA;
2063 object->texture_type = GL_FLOAT;
2065 case WGL_TEXTURE_FLOAT_RGB_NV:
2066 object->use_render_texture = GL_FLOAT_RGB_NV;
2067 object->texture_bpp = 12;
2068 object->texture_format = GL_RGB;
2069 object->texture_type = GL_FLOAT;
2071 case WGL_TEXTURE_FLOAT_RGBA_NV:
2072 object->use_render_texture = GL_FLOAT_RGBA_NV;
2073 object->texture_bpp = 16;
2074 object->texture_format = GL_RGBA;
2075 object->texture_type = GL_FLOAT;
2078 ERR("Unknown texture format: %x\n", attr_v);
2079 SetLastError(ERROR_INVALID_DATA);
2086 case WGL_TEXTURE_TARGET_ARB: {
2088 attr_v = *piAttribList;
2089 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2090 if (WGL_NO_TEXTURE_ARB == attr_v) {
2091 object->texture_target = 0;
2093 if (!use_render_texture_emulation) {
2094 SetLastError(ERROR_INVALID_DATA);
2098 case WGL_TEXTURE_CUBE_MAP_ARB: {
2099 if (iWidth != iHeight) {
2100 SetLastError(ERROR_INVALID_DATA);
2103 object->texture_target = GL_TEXTURE_CUBE_MAP;
2104 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2107 case WGL_TEXTURE_1D_ARB: {
2109 SetLastError(ERROR_INVALID_DATA);
2112 object->texture_target = GL_TEXTURE_1D;
2113 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2116 case WGL_TEXTURE_2D_ARB: {
2117 object->texture_target = GL_TEXTURE_2D;
2118 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2121 case WGL_TEXTURE_RECTANGLE_NV: {
2122 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2123 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2127 ERR("Unknown texture target: %x\n", attr_v);
2128 SetLastError(ERROR_INVALID_DATA);
2135 case WGL_MIPMAP_TEXTURE_ARB: {
2137 attr_v = *piAttribList;
2138 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2139 if (!use_render_texture_emulation) {
2140 SetLastError(ERROR_INVALID_DATA);
2149 PUSH1(attribs, None);
2150 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2151 TRACE("new Pbuffer drawable as %lx\n", object->drawable);
2152 if (!object->drawable) {
2153 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2154 goto create_failed; /* unexpected error */
2156 TRACE("->(%p)\n", object);
2160 HeapFree(GetProcessHeap(), 0, object);
2161 TRACE("->(FAILED)\n");
2166 * X11DRV_wglDestroyPbufferARB
2168 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2170 static BOOL X11DRV_wglDestroyPbufferARB( struct wgl_pbuffer *object )
2172 TRACE("(%p)\n", object);
2174 pglXDestroyPbuffer(gdi_display, object->drawable);
2175 HeapFree(GetProcessHeap(), 0, object);
2180 * X11DRV_wglGetPbufferDCARB
2182 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2184 static HDC X11DRV_wglGetPbufferDCARB( struct wgl_pbuffer *object )
2186 struct x11drv_escape_set_drawable escape;
2187 struct gl_drawable *gl, *prev;
2190 hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
2193 if (!(gl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*gl) )))
2198 gl->type = DC_GL_PBUFFER;
2199 gl->drawable = object->drawable;
2200 gl->format = object->fmt;
2202 EnterCriticalSection( &context_section );
2203 if (!XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&prev ))
2204 free_gl_drawable( prev );
2205 XSaveContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char *)gl );
2206 LeaveCriticalSection( &context_section );
2208 escape.code = X11DRV_SET_DRAWABLE;
2210 escape.drawable = object->drawable;
2211 escape.mode = IncludeInferiors;
2212 SetRect( &escape.dc_rect, 0, 0, object->width, object->height );
2213 escape.fbconfig_id = object->fmt->fmt_id;
2214 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2216 TRACE( "(%p)->(%p)\n", object, hdc );
2221 * X11DRV_wglQueryPbufferARB
2223 * WGL_ARB_pbuffer: wglQueryPbufferARB
2225 static BOOL X11DRV_wglQueryPbufferARB( struct wgl_pbuffer *object, int iAttribute, int *piValue )
2227 TRACE("(%p, 0x%x, %p)\n", object, iAttribute, piValue);
2229 switch (iAttribute) {
2230 case WGL_PBUFFER_WIDTH_ARB:
2231 pglXQueryDrawable(gdi_display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2233 case WGL_PBUFFER_HEIGHT_ARB:
2234 pglXQueryDrawable(gdi_display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2237 case WGL_PBUFFER_LOST_ARB:
2238 /* GLX Pbuffers cannot be lost by default. We can support this by
2239 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2240 * to receive pixel buffer clobber events, however that may or may
2241 * not give any benefit */
2242 *piValue = GL_FALSE;
2245 case WGL_TEXTURE_FORMAT_ARB:
2246 if (!object->use_render_texture) {
2247 *piValue = WGL_NO_TEXTURE_ARB;
2249 if (!use_render_texture_emulation) {
2250 SetLastError(ERROR_INVALID_HANDLE);
2253 switch(object->use_render_texture) {
2255 *piValue = WGL_TEXTURE_RGB_ARB;
2258 *piValue = WGL_TEXTURE_RGBA_ARB;
2260 /* WGL_FLOAT_COMPONENTS_NV */
2262 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2264 case GL_FLOAT_RG_NV:
2265 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2267 case GL_FLOAT_RGB_NV:
2268 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2270 case GL_FLOAT_RGBA_NV:
2271 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2274 ERR("Unknown texture format: %x\n", object->use_render_texture);
2279 case WGL_TEXTURE_TARGET_ARB:
2280 if (!object->texture_target){
2281 *piValue = WGL_NO_TEXTURE_ARB;
2283 if (!use_render_texture_emulation) {
2284 SetLastError(ERROR_INVALID_DATA);
2287 switch (object->texture_target) {
2288 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2289 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2290 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2291 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2296 case WGL_MIPMAP_TEXTURE_ARB:
2297 *piValue = GL_FALSE; /** don't support that */
2298 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2302 FIXME("unexpected attribute %x\n", iAttribute);
2310 * X11DRV_wglReleasePbufferDCARB
2312 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2314 static int X11DRV_wglReleasePbufferDCARB( struct wgl_pbuffer *object, HDC hdc )
2316 struct gl_drawable *gl;
2318 TRACE("(%p, %p)\n", object, hdc);
2320 EnterCriticalSection( &context_section );
2321 if (!XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl ))
2323 XDeleteContext( gdi_display, (XID)hdc, gl_pbuffer_context );
2324 free_gl_drawable( gl );
2326 LeaveCriticalSection( &context_section );
2328 return DeleteDC(hdc);
2332 * X11DRV_wglSetPbufferAttribARB
2334 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2336 static BOOL X11DRV_wglSetPbufferAttribARB( struct wgl_pbuffer *object, const int *piAttribList )
2338 GLboolean ret = GL_FALSE;
2340 WARN("(%p, %p): alpha-testing, report any problem\n", object, piAttribList);
2342 if (!object->use_render_texture) {
2343 SetLastError(ERROR_INVALID_HANDLE);
2346 if (1 == use_render_texture_emulation) {
2353 * X11DRV_wglChoosePixelFormatARB
2355 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2357 static BOOL X11DRV_wglChoosePixelFormatARB( HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList,
2358 UINT nMaxFormats, int *piFormats, UINT *nNumFormats )
2362 GLXFBConfig* cfgs = NULL;
2372 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2373 if (NULL != pfAttribFList) {
2374 FIXME("unused pfAttribFList\n");
2377 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2378 if (-1 == nAttribs) {
2379 WARN("Cannot convert WGL to GLX attributes\n");
2382 PUSH1(attribs, None);
2384 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2385 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the pixel format. We don't query these attributes
2386 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on.
2388 for(i=0; piAttribIList[i] != 0; i+=2)
2390 switch(piAttribIList[i])
2392 case WGL_DRAW_TO_BITMAP_ARB:
2393 if(piAttribIList[i+1])
2394 dwFlags |= PFD_DRAW_TO_BITMAP;
2396 case WGL_ACCELERATION_ARB:
2397 switch(piAttribIList[i+1])
2399 case WGL_NO_ACCELERATION_ARB:
2400 dwFlags |= PFD_GENERIC_FORMAT;
2402 case WGL_GENERIC_ACCELERATION_ARB:
2403 dwFlags |= PFD_GENERIC_ACCELERATED;
2405 case WGL_FULL_ACCELERATION_ARB:
2410 case WGL_SUPPORT_GDI_ARB:
2411 if(piAttribIList[i+1])
2412 dwFlags |= PFD_SUPPORT_GDI;
2417 /* Search for FB configurations matching the requirements in attribs */
2418 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2420 WARN("Compatible Pixel Format not found\n");
2424 /* Loop through all matching formats and check if they are suitable.
2425 * Note that this function should at max return nMaxFormats different formats */
2426 for(run=0; run < 2; run++)
2428 for (it = 0; it < nCfgs && pfmt_it < nMaxFormats; ++it)
2430 if (pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id))
2432 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2436 /* During the first run we only want onscreen formats and during the second only offscreen */
2437 start = run == 1 ? nb_onscreen_formats : 0;
2438 end = run == 1 ? nb_pixel_formats : nb_onscreen_formats;
2440 for (i = start; i < end; i++)
2442 if (pixel_formats[i].fmt_id == fmt_id && (pixel_formats[i].dwFlags & dwFlags) == dwFlags)
2444 piFormats[pfmt_it++] = i + 1;
2445 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n",
2446 it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2453 *nNumFormats = pfmt_it;
2460 * X11DRV_wglGetPixelFormatAttribivARB
2462 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2464 static BOOL X11DRV_wglGetPixelFormatAttribivARB( HDC hdc, int iPixelFormat, int iLayerPlane,
2465 UINT nAttributes, const int *piAttributes, int *piValues )
2468 const struct wgl_pixel_format *fmt = NULL;
2473 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2475 if (0 < iLayerPlane) {
2476 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2480 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2481 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2482 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2483 fmt = get_pixel_format(gdi_display, iPixelFormat, TRUE /* Offscreen */);
2485 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2488 for (i = 0; i < nAttributes; ++i) {
2489 const int curWGLAttr = piAttributes[i];
2490 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2492 switch (curWGLAttr) {
2493 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2494 piValues[i] = nb_pixel_formats;
2497 case WGL_SUPPORT_OPENGL_ARB:
2498 piValues[i] = GL_TRUE;
2501 case WGL_ACCELERATION_ARB:
2502 curGLXAttr = GLX_CONFIG_CAVEAT;
2503 if (!fmt) goto pix_error;
2504 if(fmt->dwFlags & PFD_GENERIC_FORMAT)
2505 piValues[i] = WGL_NO_ACCELERATION_ARB;
2506 else if(fmt->dwFlags & PFD_GENERIC_ACCELERATED)
2507 piValues[i] = WGL_GENERIC_ACCELERATION_ARB;
2509 piValues[i] = WGL_FULL_ACCELERATION_ARB;
2512 case WGL_TRANSPARENT_ARB:
2513 curGLXAttr = GLX_TRANSPARENT_TYPE;
2514 if (!fmt) goto pix_error;
2515 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2516 if (hTest) goto get_error;
2517 piValues[i] = GL_FALSE;
2518 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2521 case WGL_PIXEL_TYPE_ARB:
2522 curGLXAttr = GLX_RENDER_TYPE;
2523 if (!fmt) goto pix_error;
2524 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2525 if (hTest) goto get_error;
2526 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2527 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2528 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2529 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2530 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2531 else if (tmp & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) { piValues[i] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT; }
2533 ERR("unexpected RenderType(%x)\n", tmp);
2534 piValues[i] = WGL_TYPE_RGBA_ARB;
2538 case WGL_COLOR_BITS_ARB:
2539 curGLXAttr = GLX_BUFFER_SIZE;
2542 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2543 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2544 if (!use_render_texture_emulation) {
2545 piValues[i] = GL_FALSE;
2548 curGLXAttr = GLX_RENDER_TYPE;
2549 if (!fmt) goto pix_error;
2550 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2551 if (hTest) goto get_error;
2552 if (GLX_COLOR_INDEX_BIT == tmp) {
2553 piValues[i] = GL_FALSE;
2556 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2557 if (hTest) goto get_error;
2558 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2561 case WGL_BLUE_BITS_ARB:
2562 curGLXAttr = GLX_BLUE_SIZE;
2564 case WGL_RED_BITS_ARB:
2565 curGLXAttr = GLX_RED_SIZE;
2567 case WGL_GREEN_BITS_ARB:
2568 curGLXAttr = GLX_GREEN_SIZE;
2570 case WGL_ALPHA_BITS_ARB:
2571 curGLXAttr = GLX_ALPHA_SIZE;
2573 case WGL_DEPTH_BITS_ARB:
2574 curGLXAttr = GLX_DEPTH_SIZE;
2576 case WGL_STENCIL_BITS_ARB:
2577 curGLXAttr = GLX_STENCIL_SIZE;
2579 case WGL_DOUBLE_BUFFER_ARB:
2580 curGLXAttr = GLX_DOUBLEBUFFER;
2582 case WGL_STEREO_ARB:
2583 curGLXAttr = GLX_STEREO;
2585 case WGL_AUX_BUFFERS_ARB:
2586 curGLXAttr = GLX_AUX_BUFFERS;
2589 case WGL_SUPPORT_GDI_ARB:
2590 if (!fmt) goto pix_error;
2591 piValues[i] = (fmt->dwFlags & PFD_SUPPORT_GDI) != 0;
2594 case WGL_DRAW_TO_BITMAP_ARB:
2595 if (!fmt) goto pix_error;
2596 piValues[i] = (fmt->dwFlags & PFD_DRAW_TO_BITMAP) != 0;
2599 case WGL_DRAW_TO_WINDOW_ARB:
2600 case WGL_DRAW_TO_PBUFFER_ARB:
2601 if (!fmt) goto pix_error;
2602 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2603 if (hTest) goto get_error;
2604 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2605 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2606 piValues[i] = GL_TRUE;
2608 piValues[i] = GL_FALSE;
2611 case WGL_SWAP_METHOD_ARB:
2612 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
2613 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
2614 * point only ATI offers this.
2616 piValues[i] = WGL_SWAP_EXCHANGE_ARB;
2619 case WGL_PBUFFER_LARGEST_ARB:
2620 curGLXAttr = GLX_LARGEST_PBUFFER;
2623 case WGL_SAMPLE_BUFFERS_ARB:
2624 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2627 case WGL_SAMPLES_ARB:
2628 curGLXAttr = GLX_SAMPLES_ARB;
2631 case WGL_FLOAT_COMPONENTS_NV:
2632 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2635 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
2636 curGLXAttr = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT;
2639 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
2640 curGLXAttr = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
2643 case WGL_ACCUM_RED_BITS_ARB:
2644 curGLXAttr = GLX_ACCUM_RED_SIZE;
2646 case WGL_ACCUM_GREEN_BITS_ARB:
2647 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2649 case WGL_ACCUM_BLUE_BITS_ARB:
2650 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2652 case WGL_ACCUM_ALPHA_BITS_ARB:
2653 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2655 case WGL_ACCUM_BITS_ARB:
2656 if (!fmt) goto pix_error;
2657 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2658 if (hTest) goto get_error;
2660 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2661 if (hTest) goto get_error;
2663 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2664 if (hTest) goto get_error;
2666 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2667 if (hTest) goto get_error;
2672 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2675 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2676 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2677 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2679 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2680 * and check which options can work using iPixelFormat=0 and which not.
2681 * A problem would be that this function is an extension. This would
2682 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2684 if (0 != curGLXAttr && iPixelFormat != 0) {
2685 if (!fmt) goto pix_error;
2686 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2687 if (hTest) goto get_error;
2690 piValues[i] = GL_FALSE;
2696 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2700 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nb_pixel_formats);
2705 * X11DRV_wglGetPixelFormatAttribfvARB
2707 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2709 static BOOL X11DRV_wglGetPixelFormatAttribfvARB( HDC hdc, int iPixelFormat, int iLayerPlane,
2710 UINT nAttributes, const int *piAttributes, FLOAT *pfValues )
2716 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2718 /* Allocate a temporary array to store integer values */
2719 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2721 ERR("couldn't allocate %d array\n", nAttributes);
2725 /* Piggy-back on wglGetPixelFormatAttribivARB */
2726 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2728 /* Convert integer values to float. Should also check for attributes
2729 that can give decimal values here */
2730 for (i=0; i<nAttributes;i++) {
2731 pfValues[i] = attr[i];
2735 HeapFree(GetProcessHeap(), 0, attr);
2740 * X11DRV_wglBindTexImageARB
2742 * WGL_ARB_render_texture: wglBindTexImageARB
2744 static BOOL X11DRV_wglBindTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2746 GLboolean ret = GL_FALSE;
2748 TRACE("(%p, %d)\n", object, iBuffer);
2750 if (!object->use_render_texture) {
2751 SetLastError(ERROR_INVALID_HANDLE);
2755 if (1 == use_render_texture_emulation) {
2756 static int init = 0;
2757 int prev_binded_texture = 0;
2758 GLXContext prev_context;
2759 Drawable prev_drawable;
2760 GLXContext tmp_context;
2762 prev_context = pglXGetCurrentContext();
2763 prev_drawable = pglXGetCurrentDrawable();
2765 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2766 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2767 isn't ideal performance wise but I wasn't able to get other ways working.
2770 init = 1; /* Only show the FIXME once for performance reasons */
2771 FIXME("partial stub!\n");
2774 TRACE("drawable=%lx, context=%p\n", object->drawable, prev_context);
2775 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2777 opengl_funcs.gl.p_glGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2779 /* Switch to our pbuffer */
2780 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
2782 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2783 * After that upload the pbuffer texture data. */
2784 opengl_funcs.gl.p_glBindTexture(object->texture_target, prev_binded_texture);
2785 opengl_funcs.gl.p_glCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2787 /* Switch back to the original drawable and upload the pbuffer-texture */
2788 pglXMakeCurrent(gdi_display, prev_drawable, prev_context);
2789 pglXDestroyContext(gdi_display, tmp_context);
2797 * X11DRV_wglReleaseTexImageARB
2799 * WGL_ARB_render_texture: wglReleaseTexImageARB
2801 static BOOL X11DRV_wglReleaseTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2803 GLboolean ret = GL_FALSE;
2805 TRACE("(%p, %d)\n", object, iBuffer);
2807 if (!object->use_render_texture) {
2808 SetLastError(ERROR_INVALID_HANDLE);
2811 if (1 == use_render_texture_emulation) {
2818 * X11DRV_wglGetExtensionsStringEXT
2820 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2822 static const GLubyte *X11DRV_wglGetExtensionsStringEXT(void)
2824 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2825 return (const GLubyte *)WineGLInfo.wglExtensions;
2829 * X11DRV_wglGetSwapIntervalEXT
2831 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2833 static int X11DRV_wglGetSwapIntervalEXT(void)
2835 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
2836 * interval, so the swap interval has to be tracked. */
2838 return swap_interval;
2842 * X11DRV_wglSwapIntervalEXT
2844 * WGL_EXT_swap_control: wglSwapIntervalEXT
2846 static BOOL X11DRV_wglSwapIntervalEXT(int interval)
2850 TRACE("(%d)\n", interval);
2854 SetLastError(ERROR_INVALID_DATA);
2857 else if (!has_swap_control && interval == 0)
2859 /* wglSwapIntervalEXT considers an interval value of zero to mean that
2860 * vsync should be disabled, but glXSwapIntervalSGI considers such a
2861 * value to be an error. Just silently ignore the request for now. */
2862 WARN("Request to disable vertical sync is not handled\n");
2867 if (pglXSwapIntervalSGI)
2868 ret = !pglXSwapIntervalSGI(interval);
2870 WARN("GLX_SGI_swap_control extension is not available\n");
2873 swap_interval = interval;
2875 SetLastError(ERROR_DC_NOT_FOUND);
2882 * X11DRV_wglSetPixelFormatWINE
2884 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
2885 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
2887 static BOOL X11DRV_wglSetPixelFormatWINE(HDC hdc, int format)
2889 const struct wgl_pixel_format *fmt;
2893 TRACE("(%p,%d)\n", hdc, format);
2895 fmt = get_pixel_format(gdi_display, format, FALSE /* Offscreen */);
2898 ERR( "Invalid format %d\n", format );
2902 hwnd = WindowFromDC( hdc );
2903 if (!hwnd || hwnd == GetDesktopWindow())
2905 ERR( "not a valid window DC %p\n", hdc );
2909 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
2910 if (!(value & GLX_WINDOW_BIT))
2912 WARN( "Pixel format %d is not compatible for window rendering\n", format );
2916 return set_win_format( hwnd, fmt );
2920 * glxRequireVersion (internal)
2922 * Check if the supported GLX version matches requiredVersion.
2924 static BOOL glxRequireVersion(int requiredVersion)
2926 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2927 if(requiredVersion <= WineGLInfo.glxVersion[1])
2933 static void register_extension(const char *ext)
2935 if (WineGLInfo.wglExtensions[0])
2936 strcat(WineGLInfo.wglExtensions, " ");
2937 strcat(WineGLInfo.wglExtensions, ext);
2939 TRACE("'%s'\n", ext);
2943 * X11DRV_WineGL_LoadExtensions
2945 static void X11DRV_WineGL_LoadExtensions(void)
2947 WineGLInfo.wglExtensions[0] = 0;
2949 /* ARB Extensions */
2951 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_create_context"))
2953 register_extension( "WGL_ARB_create_context" );
2954 opengl_funcs.ext.p_wglCreateContextAttribsARB = X11DRV_wglCreateContextAttribsARB;
2956 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_create_context_profile"))
2957 register_extension("WGL_ARB_create_context_profile");
2960 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_fbconfig_float"))
2962 register_extension("WGL_ARB_pixel_format_float");
2963 register_extension("WGL_ATI_pixel_format_float");
2966 register_extension( "WGL_ARB_extensions_string" );
2967 opengl_funcs.ext.p_wglGetExtensionsStringARB = X11DRV_wglGetExtensionsStringARB;
2969 if (glxRequireVersion(3))
2971 register_extension( "WGL_ARB_make_current_read" );
2972 opengl_funcs.ext.p_wglGetCurrentReadDCARB = (void *)1; /* never called */
2973 opengl_funcs.ext.p_wglMakeContextCurrentARB = X11DRV_wglMakeContextCurrentARB;
2976 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_multisample")) register_extension( "WGL_ARB_multisample" );
2978 /* In general pbuffer functionality requires support in the X-server. The functionality is
2979 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
2981 if ( glxRequireVersion(3) && has_extension( WineGLInfo.glxExtensions, "GLX_SGIX_pbuffer") )
2983 register_extension( "WGL_ARB_pbuffer" );
2984 opengl_funcs.ext.p_wglCreatePbufferARB = X11DRV_wglCreatePbufferARB;
2985 opengl_funcs.ext.p_wglDestroyPbufferARB = X11DRV_wglDestroyPbufferARB;
2986 opengl_funcs.ext.p_wglGetPbufferDCARB = X11DRV_wglGetPbufferDCARB;
2987 opengl_funcs.ext.p_wglQueryPbufferARB = X11DRV_wglQueryPbufferARB;
2988 opengl_funcs.ext.p_wglReleasePbufferDCARB = X11DRV_wglReleasePbufferDCARB;
2989 opengl_funcs.ext.p_wglSetPbufferAttribARB = X11DRV_wglSetPbufferAttribARB;
2992 register_extension( "WGL_ARB_pixel_format" );
2993 opengl_funcs.ext.p_wglChoosePixelFormatARB = X11DRV_wglChoosePixelFormatARB;
2994 opengl_funcs.ext.p_wglGetPixelFormatAttribfvARB = X11DRV_wglGetPixelFormatAttribfvARB;
2995 opengl_funcs.ext.p_wglGetPixelFormatAttribivARB = X11DRV_wglGetPixelFormatAttribivARB;
2997 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
2998 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_render_texture") ||
2999 (glxRequireVersion(3) && has_extension( WineGLInfo.glxExtensions, "GLX_SGIX_pbuffer") && use_render_texture_emulation))
3001 register_extension( "WGL_ARB_render_texture" );
3002 opengl_funcs.ext.p_wglBindTexImageARB = X11DRV_wglBindTexImageARB;
3003 opengl_funcs.ext.p_wglReleaseTexImageARB = X11DRV_wglReleaseTexImageARB;
3005 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3006 if (has_extension( WineGLInfo.glxExtensions, "GLX_NV_float_buffer"))
3007 register_extension("WGL_NV_float_buffer");
3009 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3010 if (has_extension(WineGLInfo.glExtensions, "GL_NV_texture_rectangle"))
3011 register_extension("WGL_NV_texture_rectangle");
3014 /* EXT Extensions */
3016 register_extension( "WGL_EXT_extensions_string" );
3017 opengl_funcs.ext.p_wglGetExtensionsStringEXT = X11DRV_wglGetExtensionsStringEXT;
3019 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3020 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3021 register_extension( "WGL_EXT_swap_control" );
3022 opengl_funcs.ext.p_wglSwapIntervalEXT = X11DRV_wglSwapIntervalEXT;
3023 opengl_funcs.ext.p_wglGetSwapIntervalEXT = X11DRV_wglGetSwapIntervalEXT;
3025 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_framebuffer_sRGB"))
3026 register_extension("WGL_EXT_framebuffer_sRGB");
3028 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_fbconfig_packed_float"))
3029 register_extension("WGL_EXT_pixel_format_packed_float");
3031 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_swap_control"))
3032 has_swap_control = TRUE;
3034 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3035 if (has_extension(WineGLInfo.glExtensions, "GL_NV_vertex_array_range"))
3037 register_extension( "WGL_NV_vertex_array_range" );
3038 opengl_funcs.ext.p_wglAllocateMemoryNV = pglXAllocateMemoryNV;
3039 opengl_funcs.ext.p_wglFreeMemoryNV = pglXFreeMemoryNV;
3042 /* WINE-specific WGL Extensions */
3044 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3045 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3047 register_extension( "WGL_WINE_pixel_format_passthrough" );
3048 opengl_funcs.ext.p_wglSetPixelFormatWINE = X11DRV_wglSetPixelFormatWINE;
3053 * glxdrv_SwapBuffers
3055 * Swap the buffers of this DC
3057 static BOOL glxdrv_wglSwapBuffers( HDC hdc )
3059 struct x11drv_escape_flush_gl_drawable escape;
3060 struct gl_drawable *gl;
3061 struct wgl_context *ctx = NtCurrentTeb()->glContext;
3063 TRACE("(%p)\n", hdc);
3065 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
3066 escape.gl_drawable = 0;
3068 if (!(gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
3070 SetLastError( ERROR_INVALID_HANDLE );
3076 case DC_GL_PIXMAP_WIN:
3077 if (ctx) sync_context( ctx );
3078 escape.gl_drawable = gl->pixmap;
3079 if (pglXCopySubBufferMESA) {
3080 /* (glX)SwapBuffers has an implicit glFlush effect, however
3081 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3084 pglXCopySubBufferMESA( gdi_display, gl->drawable, 0, 0,
3085 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top );
3088 pglXSwapBuffers(gdi_display, gl->drawable);
3090 case DC_GL_CHILD_WIN:
3091 escape.gl_drawable = gl->drawable;
3094 pglXSwapBuffers(gdi_display, gl->drawable);
3098 release_gl_drawable( gl );
3100 if (escape.gl_drawable) ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
3104 static struct opengl_funcs opengl_funcs =
3107 glxdrv_wglCopyContext, /* p_wglCopyContext */
3108 glxdrv_wglCreateContext, /* p_wglCreateContext */
3109 glxdrv_wglDeleteContext, /* p_wglDeleteContext */
3110 glxdrv_wglDescribePixelFormat, /* p_wglDescribePixelFormat */
3111 glxdrv_wglGetPixelFormat, /* p_wglGetPixelFormat */
3112 glxdrv_wglGetProcAddress, /* p_wglGetProcAddress */
3113 glxdrv_wglMakeCurrent, /* p_wglMakeCurrent */
3114 glxdrv_wglSetPixelFormat, /* p_wglSetPixelFormat */
3115 glxdrv_wglShareLists, /* p_wglShareLists */
3116 glxdrv_wglSwapBuffers, /* p_wglSwapBuffers */
3120 struct opengl_funcs *get_glx_driver( UINT version )
3122 if (version != WINE_WGL_DRIVER_VERSION)
3124 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_WGL_DRIVER_VERSION );
3127 if (has_opengl()) return &opengl_funcs;
3131 #else /* no OpenGL includes */
3133 struct opengl_funcs *get_glx_driver( UINT version )
3138 void sync_gl_drawable( HWND hwnd, const RECT *visible_rect, const RECT *client_rect )
3142 void set_gl_drawable_parent( HWND hwnd, HWND parent )
3146 void destroy_gl_drawable( HWND hwnd )
3150 #endif /* defined(SONAME_LIBGL) */