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 BOOL has_gl_drawable( HWND hwnd )
1119 struct gl_drawable *gl;
1121 gl = get_gl_drawable( hwnd, 0 );
1122 release_gl_drawable( gl );
1126 static GLXContext create_glxcontext(Display *display, struct wgl_context *context, GLXContext shareList)
1130 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1131 BOOL indirect = !(context->fmt->dwFlags & PFD_DRAW_TO_BITMAP);
1133 if(context->gl3_context)
1135 if(context->numAttribs)
1136 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, context->attribList);
1138 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, NULL);
1140 else if(context->vis)
1141 ctx = pglXCreateContext(gdi_display, context->vis, shareList, indirect);
1142 else /* Create a GLX Context for a pbuffer */
1143 ctx = pglXCreateNewContext(gdi_display, context->fmt->fbconfig, context->fmt->render_type, shareList, TRUE);
1149 /***********************************************************************
1152 static void free_gl_drawable( struct gl_drawable *gl )
1157 case DC_GL_CHILD_WIN:
1158 XDestroyWindow( gdi_display, gl->drawable );
1159 XFreeColormap( gdi_display, gl->colormap );
1161 case DC_GL_PIXMAP_WIN:
1162 pglXDestroyGLXPixmap( gdi_display, gl->drawable );
1163 XFreePixmap( gdi_display, gl->pixmap );
1168 if (gl->visual) XFree( gl->visual );
1169 HeapFree( GetProcessHeap(), 0, gl );
1173 /***********************************************************************
1176 static BOOL set_win_format( HWND hwnd, const struct wgl_pixel_format *format )
1178 HWND parent = GetAncestor( hwnd, GA_PARENT );
1179 XSetWindowAttributes attrib;
1180 struct gl_drawable *gl, *prev;
1182 gl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*gl) );
1183 gl->format = format;
1184 gl->visual = pglXGetVisualFromFBConfig( gdi_display, format->fbconfig );
1187 HeapFree( GetProcessHeap(), 0, gl );
1191 GetClientRect( hwnd, &gl->rect );
1192 gl->rect.right = min( max( 1, gl->rect.right ), 65535 );
1193 gl->rect.bottom = min( max( 1, gl->rect.bottom ), 65535 );
1195 if (parent == GetDesktopWindow()) /* top-level window */
1197 Window xparent = X11DRV_get_whole_window( hwnd );
1199 gl->type = DC_GL_WINDOW;
1200 gl->colormap = XCreateColormap( gdi_display, root_window, gl->visual->visual,
1201 (gl->visual->class == PseudoColor ||
1202 gl->visual->class == GrayScale ||
1203 gl->visual->class == DirectColor) ? AllocAll : AllocNone );
1204 attrib.colormap = gl->colormap;
1205 attrib.bit_gravity = NorthWestGravity;
1206 attrib.win_gravity = NorthWestGravity;
1207 attrib.backing_store = NotUseful;
1208 /* put the initial rect outside of the window, it will be moved into place by SetWindowPos */
1209 OffsetRect( &gl->rect, gl->rect.right, gl->rect.bottom );
1211 gl->drawable = XCreateWindow( gdi_display, xparent, gl->rect.left, gl->rect.top,
1212 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top,
1213 0, default_visual.depth, InputOutput, gl->visual->visual,
1214 CWBitGravity | CWWinGravity | CWBackingStore | CWColormap,
1217 XMapWindow( gdi_display, gl->drawable );
1219 XFreeColormap( gdi_display, gl->colormap );
1221 else if (!GetAncestor( parent, GA_PARENT ))
1223 FIXME( "can't set format of HWND_MESSAGE window %p\n", hwnd );
1225 #ifdef SONAME_LIBXCOMPOSITE
1226 else if(usexcomposite)
1228 static Window dummy_parent;
1230 attrib.override_redirect = True;
1233 dummy_parent = XCreateWindow( gdi_display, root_window, -1, -1, 1, 1, 0, default_visual.depth,
1234 InputOutput, default_visual.visual, CWOverrideRedirect, &attrib );
1235 XMapWindow( gdi_display, dummy_parent );
1237 gl->colormap = XCreateColormap(gdi_display, dummy_parent, gl->visual->visual,
1238 (gl->visual->class == PseudoColor ||
1239 gl->visual->class == GrayScale ||
1240 gl->visual->class == DirectColor) ?
1241 AllocAll : AllocNone);
1242 attrib.colormap = gl->colormap;
1243 XInstallColormap(gdi_display, attrib.colormap);
1245 gl->type = DC_GL_CHILD_WIN;
1246 gl->drawable = XCreateWindow( gdi_display, dummy_parent, 0, 0,
1247 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top,
1248 0, gl->visual->depth, InputOutput, gl->visual->visual,
1249 CWColormap | CWOverrideRedirect, &attrib );
1252 pXCompositeRedirectWindow(gdi_display, gl->drawable, CompositeRedirectManual);
1253 XMapWindow(gdi_display, gl->drawable);
1255 else XFreeColormap( gdi_display, gl->colormap );
1260 WARN("XComposite is not available, using GLXPixmap hack\n");
1262 gl->type = DC_GL_PIXMAP_WIN;
1263 gl->pixmap = XCreatePixmap( gdi_display, root_window,
1264 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top,
1265 gl->visual->depth );
1268 gl->drawable = pglXCreateGLXPixmap( gdi_display, gl->visual, gl->pixmap );
1269 if (!gl->drawable) XFreePixmap( gdi_display, gl->pixmap );
1275 XFree( gl->visual );
1276 HeapFree( GetProcessHeap(), 0, gl );
1280 TRACE("created GL drawable %lx for win %p format %x\n", gl->drawable, hwnd, format->fmt_id );
1282 XFlush( gdi_display );
1284 EnterCriticalSection( &context_section );
1285 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&prev ))
1286 free_gl_drawable( prev );
1287 XSaveContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char *)gl );
1288 LeaveCriticalSection( &context_section );
1290 __wine_set_pixel_format( hwnd, pixel_format_index( format ));
1294 /***********************************************************************
1297 void sync_gl_drawable( HWND hwnd, const RECT *visible_rect, const RECT *client_rect )
1299 struct gl_drawable *gl;
1303 XWindowChanges changes;
1305 changes.x = client_rect->left - visible_rect->left;
1306 changes.y = client_rect->top - visible_rect->top;
1307 changes.width = min( max( 1, client_rect->right - client_rect->left ), 65535 );
1308 changes.height = min( max( 1, client_rect->bottom - client_rect->top ), 65535 );
1310 if (!(gl = get_gl_drawable( hwnd, 0 ))) return;
1312 if (changes.width != gl->rect.right - gl->rect.left) mask |= CWWidth;
1313 if (changes.height != gl->rect.bottom - gl->rect.top) mask |= CWHeight;
1315 TRACE( "setting drawable %lx pos %d,%d,%dx%d\n",
1316 gl->drawable, changes.x, changes.y, changes.width, changes.height );
1321 if (changes.x != gl->rect.left) mask |= CWX;
1322 if (changes.y != gl->rect.top) mask |= CWY;
1324 case DC_GL_CHILD_WIN:
1325 if (mask) XConfigureWindow( gdi_display, gl->drawable, mask, &changes );
1327 case DC_GL_PIXMAP_WIN:
1329 pix = XCreatePixmap(gdi_display, root_window, changes.width, changes.height, gl->visual->depth);
1330 if (!pix) goto done;
1331 glxp = pglXCreateGLXPixmap(gdi_display, gl->visual, pix);
1334 XFreePixmap(gdi_display, pix);
1337 mark_drawable_dirty(gl->drawable, glxp);
1338 XFlush( gdi_display );
1340 XFreePixmap(gdi_display, gl->pixmap);
1341 pglXDestroyGLXPixmap(gdi_display, gl->drawable);
1342 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp, gl->drawable );
1345 gl->drawable = glxp;
1350 SetRect( &gl->rect, changes.x, changes.y, changes.x + changes.width, changes.y + changes.height );
1352 release_gl_drawable( gl );
1355 /***********************************************************************
1356 * destroy_gl_drawable
1358 void destroy_gl_drawable( HWND hwnd )
1360 struct gl_drawable *gl;
1362 EnterCriticalSection( &context_section );
1363 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl ))
1365 XDeleteContext( gdi_display, (XID)hwnd, gl_hwnd_context );
1366 free_gl_drawable( gl );
1368 LeaveCriticalSection( &context_section );
1373 * glxdrv_DescribePixelFormat
1375 * Get the pixel-format descriptor associated to the given id
1377 static int glxdrv_wglDescribePixelFormat( HDC hdc, int iPixelFormat,
1378 UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd)
1380 /*XVisualInfo *vis;*/
1383 const struct wgl_pixel_format *fmt;
1385 if (!has_opengl()) return 0;
1387 TRACE("(%p,%d,%d,%p)\n", hdc, iPixelFormat, nBytes, ppfd);
1389 if (!ppfd) return nb_onscreen_formats;
1391 /* 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 */
1392 fmt = get_pixel_format(gdi_display, iPixelFormat, FALSE /* Offscreen */);
1394 WARN("unexpected format %d\n", iPixelFormat);
1398 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1399 ERR("Wrong structure size !\n");
1400 /* Should set error */
1404 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1405 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1408 /* These flags are always the same... */
1409 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1410 /* Now the flags extracted from the Visual */
1412 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1413 if(value & GLX_WINDOW_BIT)
1414 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1416 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1417 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1418 * 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
1419 * offered the GDI bit either. */
1420 ppfd->dwFlags |= fmt->dwFlags & (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI);
1422 /* PFD_GENERIC_FORMAT - gdi software rendering
1423 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1424 * none set - full hardware accelerated by a ICD
1426 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1427 ppfd->dwFlags |= fmt->dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED);
1429 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1431 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1432 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1434 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1437 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1438 if (value & GLX_RGBA_BIT)
1439 ppfd->iPixelType = PFD_TYPE_RGBA;
1441 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1444 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1445 ppfd->cColorBits = value;
1447 /* Red, green, blue and alpha bits / shifts */
1448 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1449 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1450 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1451 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1452 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1454 ppfd->cRedBits = rb;
1455 ppfd->cRedShift = gb + bb + ab;
1456 ppfd->cBlueBits = bb;
1457 ppfd->cBlueShift = ab;
1458 ppfd->cGreenBits = gb;
1459 ppfd->cGreenShift = bb + ab;
1460 ppfd->cAlphaBits = ab;
1461 ppfd->cAlphaShift = 0;
1464 ppfd->cRedShift = 0;
1465 ppfd->cBlueBits = 0;
1466 ppfd->cBlueShift = 0;
1467 ppfd->cGreenBits = 0;
1468 ppfd->cGreenShift = 0;
1469 ppfd->cAlphaBits = 0;
1470 ppfd->cAlphaShift = 0;
1473 /* Accum RGBA bits */
1474 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1475 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1476 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1477 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1479 ppfd->cAccumBits = rb+gb+bb+ab;
1480 ppfd->cAccumRedBits = rb;
1481 ppfd->cAccumGreenBits = gb;
1482 ppfd->cAccumBlueBits = bb;
1483 ppfd->cAccumAlphaBits = ab;
1486 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1487 ppfd->cAuxBuffers = value;
1490 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1491 ppfd->cDepthBits = value;
1494 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1495 ppfd->cStencilBits = value;
1497 ppfd->iLayerType = PFD_MAIN_PLANE;
1499 if (TRACE_ON(wgl)) {
1500 dump_PIXELFORMATDESCRIPTOR(ppfd);
1503 return nb_onscreen_formats;
1506 /***********************************************************************
1507 * glxdrv_wglGetPixelFormat
1509 static int glxdrv_wglGetPixelFormat( HDC hdc )
1511 struct gl_drawable *gl;
1514 if ((gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1516 ret = pixel_format_index( gl->format );
1517 /* Offscreen formats can't be used with traditional WGL calls.
1518 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1519 if (!is_onscreen_pixel_format( ret )) ret = 1;
1520 release_gl_drawable( gl );
1522 TRACE( "%p -> %d\n", hdc, ret );
1526 /***********************************************************************
1527 * glxdrv_wglSetPixelFormat
1529 static BOOL glxdrv_wglSetPixelFormat( HDC hdc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd )
1531 const struct wgl_pixel_format *fmt;
1533 struct gl_drawable *gl;
1534 HWND hwnd = WindowFromDC( hdc );
1536 TRACE("(%p,%d,%p)\n", hdc, iPixelFormat, ppfd);
1538 if (!hwnd || hwnd == GetDesktopWindow())
1540 WARN( "not a proper window DC %p/%p\n", hdc, hwnd );
1544 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1545 fmt = get_pixel_format(gdi_display, iPixelFormat, FALSE /* Offscreen */);
1547 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1551 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1552 if (!(value & GLX_WINDOW_BIT))
1554 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1558 if ((gl = get_gl_drawable( hwnd, hdc )))
1560 int prev = pixel_format_index( gl->format );
1561 release_gl_drawable( gl );
1562 return prev == iPixelFormat; /* cannot change it if already set */
1565 if (TRACE_ON(wgl)) {
1568 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1570 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1572 TRACE(" FBConfig have :\n");
1573 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1574 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1575 TRACE(" - VISUAL_ID 0x%x\n", value);
1576 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1577 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1581 return set_win_format( hwnd, fmt );
1584 /***********************************************************************
1585 * glxdrv_wglCopyContext
1587 static BOOL glxdrv_wglCopyContext(struct wgl_context *src, struct wgl_context *dst, UINT mask)
1589 TRACE("%p -> %p mask %#x\n", src, dst, mask);
1591 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1593 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1597 /***********************************************************************
1598 * glxdrv_wglCreateContext
1600 static struct wgl_context *glxdrv_wglCreateContext( HDC hdc )
1602 struct wgl_context *ret = NULL;
1603 struct gl_drawable *gl;
1605 if (!(gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1607 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1611 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret))))
1614 ret->fmt = gl->format;
1615 ret->vis = pglXGetVisualFromFBConfig(gdi_display, gl->format->fbconfig);
1616 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1617 list_add_head( &context_list, &ret->entry );
1619 release_gl_drawable( gl );
1620 TRACE( "%p -> %p\n", hdc, ret );
1624 /***********************************************************************
1625 * glxdrv_wglDeleteContext
1627 static void glxdrv_wglDeleteContext(struct wgl_context *ctx)
1629 TRACE("(%p)\n", ctx);
1631 EnterCriticalSection( &context_section );
1632 list_remove( &ctx->entry );
1633 LeaveCriticalSection( &context_section );
1635 if (ctx->ctx) pglXDestroyContext( gdi_display, ctx->ctx );
1636 if (ctx->vis) XFree( ctx->vis );
1637 HeapFree( GetProcessHeap(), 0, ctx );
1640 /***********************************************************************
1641 * glxdrv_wglGetProcAddress
1643 static PROC glxdrv_wglGetProcAddress(LPCSTR lpszProc)
1645 if (!strncmp(lpszProc, "wgl", 3)) return NULL;
1646 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1649 /***********************************************************************
1650 * glxdrv_wglMakeCurrent
1652 static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx)
1655 struct gl_drawable *gl;
1657 TRACE("(%p,%p)\n", hdc, ctx);
1661 pglXMakeCurrent(gdi_display, None, NULL);
1662 NtCurrentTeb()->glContext = NULL;
1666 if ((gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1668 if (ctx->fmt != gl->format)
1670 WARN( "mismatched pixel format hdc %p %p ctx %p %p\n", hdc, gl->format, ctx, ctx->fmt );
1671 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1675 if (TRACE_ON(wgl)) {
1676 describeContext(ctx);
1677 TRACE("hdc %p drawable %lx fmt %p ctx %p\n", hdc, gl->drawable, gl->format, ctx->ctx );
1680 ret = pglXMakeCurrent(gdi_display, gl->drawable, ctx->ctx);
1683 NtCurrentTeb()->glContext = ctx;
1684 ctx->has_been_current = TRUE;
1686 ctx->drawables[0] = gl->drawable;
1687 ctx->drawables[1] = gl->drawable;
1688 ctx->refresh_drawables = FALSE;
1692 SetLastError( ERROR_INVALID_HANDLE );
1695 release_gl_drawable( gl );
1696 TRACE( "%p,%p returning %d\n", hdc, ctx, ret );
1700 /***********************************************************************
1701 * X11DRV_wglMakeContextCurrentARB
1703 static BOOL X11DRV_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *ctx )
1706 struct gl_drawable *draw_gl, *read_gl = NULL;
1708 TRACE("(%p,%p,%p)\n", draw_hdc, read_hdc, ctx);
1712 pglXMakeCurrent(gdi_display, None, NULL);
1713 NtCurrentTeb()->glContext = NULL;
1717 if (!pglXMakeContextCurrent) return FALSE;
1719 if ((draw_gl = get_gl_drawable( WindowFromDC( draw_hdc ), draw_hdc )))
1721 read_gl = get_gl_drawable( WindowFromDC( read_hdc ), read_hdc );
1722 ret = pglXMakeContextCurrent(gdi_display, draw_gl->drawable,
1723 read_gl ? read_gl->drawable : 0, ctx->ctx);
1726 ctx->has_been_current = TRUE;
1727 ctx->hdc = draw_hdc;
1728 ctx->drawables[0] = draw_gl->drawable;
1729 ctx->drawables[1] = read_gl ? read_gl->drawable : 0;
1730 ctx->refresh_drawables = FALSE;
1731 NtCurrentTeb()->glContext = ctx;
1735 SetLastError( ERROR_INVALID_HANDLE );
1737 release_gl_drawable( read_gl );
1738 release_gl_drawable( draw_gl );
1739 TRACE( "%p,%p,%p returning %d\n", draw_hdc, read_hdc, ctx, ret );
1743 /***********************************************************************
1744 * glxdrv_wglShareLists
1746 static BOOL glxdrv_wglShareLists(struct wgl_context *org, struct wgl_context *dest)
1748 TRACE("(%p, %p)\n", org, dest);
1750 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1751 * at context creation time but in case of WGL it is done using wglShareLists.
1752 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1753 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1754 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1755 * so there delaying context creation doesn't work.
1757 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1758 * and when a program requests sharing we recreate the destination context if it hasn't been made
1759 * current or when it hasn't shared display lists before.
1762 if((org->has_been_current && dest->has_been_current) || dest->has_been_current)
1764 ERR("Could not share display lists, one of the contexts has been current already !\n");
1767 else if(dest->sharing)
1769 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1774 describeContext(org);
1775 describeContext(dest);
1777 /* Re-create the GLX context and share display lists */
1778 pglXDestroyContext(gdi_display, dest->ctx);
1779 dest->ctx = create_glxcontext(gdi_display, dest, org->ctx);
1780 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1782 org->sharing = TRUE;
1783 dest->sharing = TRUE;
1789 static void wglFinish(void)
1791 struct x11drv_escape_flush_gl_drawable escape;
1792 struct gl_drawable *gl;
1793 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1795 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
1796 escape.gl_drawable = 0;
1798 if ((gl = get_gl_drawable( WindowFromDC( ctx->hdc ), 0 )))
1802 case DC_GL_PIXMAP_WIN: escape.gl_drawable = gl->pixmap; break;
1803 case DC_GL_CHILD_WIN: escape.gl_drawable = gl->drawable; break;
1807 release_gl_drawable( gl );
1811 if (escape.gl_drawable) ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1814 static void wglFlush(void)
1816 struct x11drv_escape_flush_gl_drawable escape;
1817 struct gl_drawable *gl;
1818 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1820 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
1821 escape.gl_drawable = 0;
1823 if ((gl = get_gl_drawable( WindowFromDC( ctx->hdc ), 0 )))
1827 case DC_GL_PIXMAP_WIN: escape.gl_drawable = gl->pixmap; break;
1828 case DC_GL_CHILD_WIN: escape.gl_drawable = gl->drawable; break;
1832 release_gl_drawable( gl );
1836 if (escape.gl_drawable) ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1839 /***********************************************************************
1840 * X11DRV_wglCreateContextAttribsARB
1842 static struct wgl_context *X11DRV_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *hShareContext,
1843 const int* attribList )
1845 struct wgl_context *ret = NULL;
1846 struct gl_drawable *gl;
1848 TRACE("(%p %p %p)\n", hdc, hShareContext, attribList);
1850 if (!(gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1852 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1856 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret))))
1859 ret->fmt = gl->format;
1860 ret->vis = NULL; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
1861 ret->gl3_context = TRUE;
1862 ret->numAttribs = 0;
1865 int *pContextAttribList = &ret->attribList[0];
1866 /* attribList consists of pairs {token, value] terminated with 0 */
1867 while(attribList[0] != 0)
1869 TRACE("%#x %#x\n", attribList[0], attribList[1]);
1870 switch(attribList[0])
1872 case WGL_CONTEXT_MAJOR_VERSION_ARB:
1873 pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
1874 pContextAttribList[1] = attribList[1];
1876 case WGL_CONTEXT_MINOR_VERSION_ARB:
1877 pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB;
1878 pContextAttribList[1] = attribList[1];
1880 case WGL_CONTEXT_LAYER_PLANE_ARB:
1882 case WGL_CONTEXT_FLAGS_ARB:
1883 pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB;
1884 pContextAttribList[1] = attribList[1];
1886 case WGL_CONTEXT_PROFILE_MASK_ARB:
1887 pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
1888 pContextAttribList[1] = attribList[1];
1891 ERR("Unhandled attribList pair: %#x %#x\n", attribList[0], attribList[1]);
1895 pContextAttribList += 2;
1899 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
1900 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1901 XSync(gdi_display, False);
1902 if (X11DRV_check_error() || !ret->ctx)
1904 /* In the future we should convert the GLX error to a win32 one here if needed */
1905 ERR("Context creation failed\n");
1906 HeapFree( GetProcessHeap(), 0, ret );
1909 else list_add_head( &context_list, &ret->entry );
1912 release_gl_drawable( gl );
1913 TRACE( "%p -> %p\n", hdc, ret );
1918 * X11DRV_wglGetExtensionsStringARB
1920 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
1922 static const GLubyte *X11DRV_wglGetExtensionsStringARB(HDC hdc)
1924 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
1925 return (const GLubyte *)WineGLInfo.wglExtensions;
1929 * X11DRV_wglCreatePbufferARB
1931 * WGL_ARB_pbuffer: wglCreatePbufferARB
1933 static struct wgl_pbuffer *X11DRV_wglCreatePbufferARB( HDC hdc, int iPixelFormat, int iWidth, int iHeight,
1934 const int *piAttribList )
1936 struct wgl_pbuffer* object = NULL;
1937 const struct wgl_pixel_format *fmt = NULL;
1941 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
1943 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
1944 fmt = get_pixel_format(gdi_display, iPixelFormat, TRUE /* Offscreen */);
1946 ERR("(%p): invalid pixel format %d\n", hdc, iPixelFormat);
1947 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1951 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1952 if (NULL == object) {
1953 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
1956 object->width = iWidth;
1957 object->height = iHeight;
1960 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
1961 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
1962 while (piAttribList && 0 != *piAttribList) {
1964 switch (*piAttribList) {
1965 case WGL_PBUFFER_LARGEST_ARB: {
1967 attr_v = *piAttribList;
1968 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
1969 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
1973 case WGL_TEXTURE_FORMAT_ARB: {
1975 attr_v = *piAttribList;
1976 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
1977 if (WGL_NO_TEXTURE_ARB == attr_v) {
1978 object->use_render_texture = 0;
1980 if (!use_render_texture_emulation) {
1981 SetLastError(ERROR_INVALID_DATA);
1985 case WGL_TEXTURE_RGB_ARB:
1986 object->use_render_texture = GL_RGB;
1987 object->texture_bpp = 3;
1988 object->texture_format = GL_RGB;
1989 object->texture_type = GL_UNSIGNED_BYTE;
1991 case WGL_TEXTURE_RGBA_ARB:
1992 object->use_render_texture = GL_RGBA;
1993 object->texture_bpp = 4;
1994 object->texture_format = GL_RGBA;
1995 object->texture_type = GL_UNSIGNED_BYTE;
1998 /* WGL_FLOAT_COMPONENTS_NV */
1999 case WGL_TEXTURE_FLOAT_R_NV:
2000 object->use_render_texture = GL_FLOAT_R_NV;
2001 object->texture_bpp = 4;
2002 object->texture_format = GL_RED;
2003 object->texture_type = GL_FLOAT;
2005 case WGL_TEXTURE_FLOAT_RG_NV:
2006 object->use_render_texture = GL_FLOAT_RG_NV;
2007 object->texture_bpp = 8;
2008 object->texture_format = GL_LUMINANCE_ALPHA;
2009 object->texture_type = GL_FLOAT;
2011 case WGL_TEXTURE_FLOAT_RGB_NV:
2012 object->use_render_texture = GL_FLOAT_RGB_NV;
2013 object->texture_bpp = 12;
2014 object->texture_format = GL_RGB;
2015 object->texture_type = GL_FLOAT;
2017 case WGL_TEXTURE_FLOAT_RGBA_NV:
2018 object->use_render_texture = GL_FLOAT_RGBA_NV;
2019 object->texture_bpp = 16;
2020 object->texture_format = GL_RGBA;
2021 object->texture_type = GL_FLOAT;
2024 ERR("Unknown texture format: %x\n", attr_v);
2025 SetLastError(ERROR_INVALID_DATA);
2032 case WGL_TEXTURE_TARGET_ARB: {
2034 attr_v = *piAttribList;
2035 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2036 if (WGL_NO_TEXTURE_ARB == attr_v) {
2037 object->texture_target = 0;
2039 if (!use_render_texture_emulation) {
2040 SetLastError(ERROR_INVALID_DATA);
2044 case WGL_TEXTURE_CUBE_MAP_ARB: {
2045 if (iWidth != iHeight) {
2046 SetLastError(ERROR_INVALID_DATA);
2049 object->texture_target = GL_TEXTURE_CUBE_MAP;
2050 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2053 case WGL_TEXTURE_1D_ARB: {
2055 SetLastError(ERROR_INVALID_DATA);
2058 object->texture_target = GL_TEXTURE_1D;
2059 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2062 case WGL_TEXTURE_2D_ARB: {
2063 object->texture_target = GL_TEXTURE_2D;
2064 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2067 case WGL_TEXTURE_RECTANGLE_NV: {
2068 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2069 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2073 ERR("Unknown texture target: %x\n", attr_v);
2074 SetLastError(ERROR_INVALID_DATA);
2081 case WGL_MIPMAP_TEXTURE_ARB: {
2083 attr_v = *piAttribList;
2084 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2085 if (!use_render_texture_emulation) {
2086 SetLastError(ERROR_INVALID_DATA);
2095 PUSH1(attribs, None);
2096 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2097 TRACE("new Pbuffer drawable as %lx\n", object->drawable);
2098 if (!object->drawable) {
2099 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2100 goto create_failed; /* unexpected error */
2102 TRACE("->(%p)\n", object);
2106 HeapFree(GetProcessHeap(), 0, object);
2107 TRACE("->(FAILED)\n");
2112 * X11DRV_wglDestroyPbufferARB
2114 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2116 static BOOL X11DRV_wglDestroyPbufferARB( struct wgl_pbuffer *object )
2118 TRACE("(%p)\n", object);
2120 pglXDestroyPbuffer(gdi_display, object->drawable);
2121 HeapFree(GetProcessHeap(), 0, object);
2126 * X11DRV_wglGetPbufferDCARB
2128 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2130 static HDC X11DRV_wglGetPbufferDCARB( struct wgl_pbuffer *object )
2132 struct x11drv_escape_set_drawable escape;
2133 struct gl_drawable *gl, *prev;
2136 hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
2139 if (!(gl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*gl) )))
2144 gl->type = DC_GL_PBUFFER;
2145 gl->drawable = object->drawable;
2146 gl->format = object->fmt;
2148 EnterCriticalSection( &context_section );
2149 if (!XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&prev ))
2150 free_gl_drawable( prev );
2151 XSaveContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char *)gl );
2152 LeaveCriticalSection( &context_section );
2154 escape.code = X11DRV_SET_DRAWABLE;
2156 escape.drawable = object->drawable;
2157 escape.mode = IncludeInferiors;
2158 SetRect( &escape.dc_rect, 0, 0, object->width, object->height );
2159 escape.fbconfig_id = object->fmt->fmt_id;
2160 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2162 TRACE( "(%p)->(%p)\n", object, hdc );
2167 * X11DRV_wglQueryPbufferARB
2169 * WGL_ARB_pbuffer: wglQueryPbufferARB
2171 static BOOL X11DRV_wglQueryPbufferARB( struct wgl_pbuffer *object, int iAttribute, int *piValue )
2173 TRACE("(%p, 0x%x, %p)\n", object, iAttribute, piValue);
2175 switch (iAttribute) {
2176 case WGL_PBUFFER_WIDTH_ARB:
2177 pglXQueryDrawable(gdi_display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2179 case WGL_PBUFFER_HEIGHT_ARB:
2180 pglXQueryDrawable(gdi_display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2183 case WGL_PBUFFER_LOST_ARB:
2184 /* GLX Pbuffers cannot be lost by default. We can support this by
2185 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2186 * to receive pixel buffer clobber events, however that may or may
2187 * not give any benefit */
2188 *piValue = GL_FALSE;
2191 case WGL_TEXTURE_FORMAT_ARB:
2192 if (!object->use_render_texture) {
2193 *piValue = WGL_NO_TEXTURE_ARB;
2195 if (!use_render_texture_emulation) {
2196 SetLastError(ERROR_INVALID_HANDLE);
2199 switch(object->use_render_texture) {
2201 *piValue = WGL_TEXTURE_RGB_ARB;
2204 *piValue = WGL_TEXTURE_RGBA_ARB;
2206 /* WGL_FLOAT_COMPONENTS_NV */
2208 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2210 case GL_FLOAT_RG_NV:
2211 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2213 case GL_FLOAT_RGB_NV:
2214 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2216 case GL_FLOAT_RGBA_NV:
2217 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2220 ERR("Unknown texture format: %x\n", object->use_render_texture);
2225 case WGL_TEXTURE_TARGET_ARB:
2226 if (!object->texture_target){
2227 *piValue = WGL_NO_TEXTURE_ARB;
2229 if (!use_render_texture_emulation) {
2230 SetLastError(ERROR_INVALID_DATA);
2233 switch (object->texture_target) {
2234 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2235 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2236 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2237 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2242 case WGL_MIPMAP_TEXTURE_ARB:
2243 *piValue = GL_FALSE; /** don't support that */
2244 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2248 FIXME("unexpected attribute %x\n", iAttribute);
2256 * X11DRV_wglReleasePbufferDCARB
2258 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2260 static int X11DRV_wglReleasePbufferDCARB( struct wgl_pbuffer *object, HDC hdc )
2262 struct gl_drawable *gl;
2264 TRACE("(%p, %p)\n", object, hdc);
2266 EnterCriticalSection( &context_section );
2267 if (!XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl ))
2269 XDeleteContext( gdi_display, (XID)hdc, gl_pbuffer_context );
2270 free_gl_drawable( gl );
2272 LeaveCriticalSection( &context_section );
2274 return DeleteDC(hdc);
2278 * X11DRV_wglSetPbufferAttribARB
2280 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2282 static BOOL X11DRV_wglSetPbufferAttribARB( struct wgl_pbuffer *object, const int *piAttribList )
2284 GLboolean ret = GL_FALSE;
2286 WARN("(%p, %p): alpha-testing, report any problem\n", object, piAttribList);
2288 if (!object->use_render_texture) {
2289 SetLastError(ERROR_INVALID_HANDLE);
2292 if (1 == use_render_texture_emulation) {
2299 * X11DRV_wglChoosePixelFormatARB
2301 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2303 static BOOL X11DRV_wglChoosePixelFormatARB( HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList,
2304 UINT nMaxFormats, int *piFormats, UINT *nNumFormats )
2308 GLXFBConfig* cfgs = NULL;
2318 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2319 if (NULL != pfAttribFList) {
2320 FIXME("unused pfAttribFList\n");
2323 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2324 if (-1 == nAttribs) {
2325 WARN("Cannot convert WGL to GLX attributes\n");
2328 PUSH1(attribs, None);
2330 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2331 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the pixel format. We don't query these attributes
2332 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on.
2334 for(i=0; piAttribIList[i] != 0; i+=2)
2336 switch(piAttribIList[i])
2338 case WGL_DRAW_TO_BITMAP_ARB:
2339 if(piAttribIList[i+1])
2340 dwFlags |= PFD_DRAW_TO_BITMAP;
2342 case WGL_ACCELERATION_ARB:
2343 switch(piAttribIList[i+1])
2345 case WGL_NO_ACCELERATION_ARB:
2346 dwFlags |= PFD_GENERIC_FORMAT;
2348 case WGL_GENERIC_ACCELERATION_ARB:
2349 dwFlags |= PFD_GENERIC_ACCELERATED;
2351 case WGL_FULL_ACCELERATION_ARB:
2356 case WGL_SUPPORT_GDI_ARB:
2357 if(piAttribIList[i+1])
2358 dwFlags |= PFD_SUPPORT_GDI;
2363 /* Search for FB configurations matching the requirements in attribs */
2364 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2366 WARN("Compatible Pixel Format not found\n");
2370 /* Loop through all matching formats and check if they are suitable.
2371 * Note that this function should at max return nMaxFormats different formats */
2372 for(run=0; run < 2; run++)
2374 for (it = 0; it < nCfgs && pfmt_it < nMaxFormats; ++it)
2376 if (pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id))
2378 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2382 /* During the first run we only want onscreen formats and during the second only offscreen */
2383 start = run == 1 ? nb_onscreen_formats : 0;
2384 end = run == 1 ? nb_pixel_formats : nb_onscreen_formats;
2386 for (i = start; i < end; i++)
2388 if (pixel_formats[i].fmt_id == fmt_id && (pixel_formats[i].dwFlags & dwFlags) == dwFlags)
2390 piFormats[pfmt_it++] = i + 1;
2391 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n",
2392 it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2399 *nNumFormats = pfmt_it;
2406 * X11DRV_wglGetPixelFormatAttribivARB
2408 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2410 static BOOL X11DRV_wglGetPixelFormatAttribivARB( HDC hdc, int iPixelFormat, int iLayerPlane,
2411 UINT nAttributes, const int *piAttributes, int *piValues )
2414 const struct wgl_pixel_format *fmt = NULL;
2419 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2421 if (0 < iLayerPlane) {
2422 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2426 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2427 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2428 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2429 fmt = get_pixel_format(gdi_display, iPixelFormat, TRUE /* Offscreen */);
2431 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2434 for (i = 0; i < nAttributes; ++i) {
2435 const int curWGLAttr = piAttributes[i];
2436 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2438 switch (curWGLAttr) {
2439 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2440 piValues[i] = nb_pixel_formats;
2443 case WGL_SUPPORT_OPENGL_ARB:
2444 piValues[i] = GL_TRUE;
2447 case WGL_ACCELERATION_ARB:
2448 curGLXAttr = GLX_CONFIG_CAVEAT;
2449 if (!fmt) goto pix_error;
2450 if(fmt->dwFlags & PFD_GENERIC_FORMAT)
2451 piValues[i] = WGL_NO_ACCELERATION_ARB;
2452 else if(fmt->dwFlags & PFD_GENERIC_ACCELERATED)
2453 piValues[i] = WGL_GENERIC_ACCELERATION_ARB;
2455 piValues[i] = WGL_FULL_ACCELERATION_ARB;
2458 case WGL_TRANSPARENT_ARB:
2459 curGLXAttr = GLX_TRANSPARENT_TYPE;
2460 if (!fmt) goto pix_error;
2461 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2462 if (hTest) goto get_error;
2463 piValues[i] = GL_FALSE;
2464 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2467 case WGL_PIXEL_TYPE_ARB:
2468 curGLXAttr = GLX_RENDER_TYPE;
2469 if (!fmt) goto pix_error;
2470 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2471 if (hTest) goto get_error;
2472 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2473 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2474 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2475 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2476 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2477 else if (tmp & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) { piValues[i] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT; }
2479 ERR("unexpected RenderType(%x)\n", tmp);
2480 piValues[i] = WGL_TYPE_RGBA_ARB;
2484 case WGL_COLOR_BITS_ARB:
2485 curGLXAttr = GLX_BUFFER_SIZE;
2488 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2489 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2490 if (!use_render_texture_emulation) {
2491 piValues[i] = GL_FALSE;
2494 curGLXAttr = GLX_RENDER_TYPE;
2495 if (!fmt) goto pix_error;
2496 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2497 if (hTest) goto get_error;
2498 if (GLX_COLOR_INDEX_BIT == tmp) {
2499 piValues[i] = GL_FALSE;
2502 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2503 if (hTest) goto get_error;
2504 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2507 case WGL_BLUE_BITS_ARB:
2508 curGLXAttr = GLX_BLUE_SIZE;
2510 case WGL_RED_BITS_ARB:
2511 curGLXAttr = GLX_RED_SIZE;
2513 case WGL_GREEN_BITS_ARB:
2514 curGLXAttr = GLX_GREEN_SIZE;
2516 case WGL_ALPHA_BITS_ARB:
2517 curGLXAttr = GLX_ALPHA_SIZE;
2519 case WGL_DEPTH_BITS_ARB:
2520 curGLXAttr = GLX_DEPTH_SIZE;
2522 case WGL_STENCIL_BITS_ARB:
2523 curGLXAttr = GLX_STENCIL_SIZE;
2525 case WGL_DOUBLE_BUFFER_ARB:
2526 curGLXAttr = GLX_DOUBLEBUFFER;
2528 case WGL_STEREO_ARB:
2529 curGLXAttr = GLX_STEREO;
2531 case WGL_AUX_BUFFERS_ARB:
2532 curGLXAttr = GLX_AUX_BUFFERS;
2535 case WGL_SUPPORT_GDI_ARB:
2536 if (!fmt) goto pix_error;
2537 piValues[i] = (fmt->dwFlags & PFD_SUPPORT_GDI) != 0;
2540 case WGL_DRAW_TO_BITMAP_ARB:
2541 if (!fmt) goto pix_error;
2542 piValues[i] = (fmt->dwFlags & PFD_DRAW_TO_BITMAP) != 0;
2545 case WGL_DRAW_TO_WINDOW_ARB:
2546 case WGL_DRAW_TO_PBUFFER_ARB:
2547 if (!fmt) goto pix_error;
2548 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2549 if (hTest) goto get_error;
2550 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2551 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2552 piValues[i] = GL_TRUE;
2554 piValues[i] = GL_FALSE;
2557 case WGL_SWAP_METHOD_ARB:
2558 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
2559 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
2560 * point only ATI offers this.
2562 piValues[i] = WGL_SWAP_EXCHANGE_ARB;
2565 case WGL_PBUFFER_LARGEST_ARB:
2566 curGLXAttr = GLX_LARGEST_PBUFFER;
2569 case WGL_SAMPLE_BUFFERS_ARB:
2570 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2573 case WGL_SAMPLES_ARB:
2574 curGLXAttr = GLX_SAMPLES_ARB;
2577 case WGL_FLOAT_COMPONENTS_NV:
2578 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2581 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
2582 curGLXAttr = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT;
2585 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
2586 curGLXAttr = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
2589 case WGL_ACCUM_RED_BITS_ARB:
2590 curGLXAttr = GLX_ACCUM_RED_SIZE;
2592 case WGL_ACCUM_GREEN_BITS_ARB:
2593 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2595 case WGL_ACCUM_BLUE_BITS_ARB:
2596 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2598 case WGL_ACCUM_ALPHA_BITS_ARB:
2599 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2601 case WGL_ACCUM_BITS_ARB:
2602 if (!fmt) goto pix_error;
2603 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2604 if (hTest) goto get_error;
2606 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2607 if (hTest) goto get_error;
2609 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2610 if (hTest) goto get_error;
2612 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2613 if (hTest) goto get_error;
2618 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2621 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2622 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2623 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2625 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2626 * and check which options can work using iPixelFormat=0 and which not.
2627 * A problem would be that this function is an extension. This would
2628 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2630 if (0 != curGLXAttr && iPixelFormat != 0) {
2631 if (!fmt) goto pix_error;
2632 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2633 if (hTest) goto get_error;
2636 piValues[i] = GL_FALSE;
2642 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2646 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nb_pixel_formats);
2651 * X11DRV_wglGetPixelFormatAttribfvARB
2653 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2655 static BOOL X11DRV_wglGetPixelFormatAttribfvARB( HDC hdc, int iPixelFormat, int iLayerPlane,
2656 UINT nAttributes, const int *piAttributes, FLOAT *pfValues )
2662 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2664 /* Allocate a temporary array to store integer values */
2665 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2667 ERR("couldn't allocate %d array\n", nAttributes);
2671 /* Piggy-back on wglGetPixelFormatAttribivARB */
2672 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2674 /* Convert integer values to float. Should also check for attributes
2675 that can give decimal values here */
2676 for (i=0; i<nAttributes;i++) {
2677 pfValues[i] = attr[i];
2681 HeapFree(GetProcessHeap(), 0, attr);
2686 * X11DRV_wglBindTexImageARB
2688 * WGL_ARB_render_texture: wglBindTexImageARB
2690 static BOOL X11DRV_wglBindTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2692 GLboolean ret = GL_FALSE;
2694 TRACE("(%p, %d)\n", object, iBuffer);
2696 if (!object->use_render_texture) {
2697 SetLastError(ERROR_INVALID_HANDLE);
2701 if (1 == use_render_texture_emulation) {
2702 static int init = 0;
2703 int prev_binded_texture = 0;
2704 GLXContext prev_context;
2705 Drawable prev_drawable;
2706 GLXContext tmp_context;
2708 prev_context = pglXGetCurrentContext();
2709 prev_drawable = pglXGetCurrentDrawable();
2711 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2712 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2713 isn't ideal performance wise but I wasn't able to get other ways working.
2716 init = 1; /* Only show the FIXME once for performance reasons */
2717 FIXME("partial stub!\n");
2720 TRACE("drawable=%lx, context=%p\n", object->drawable, prev_context);
2721 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2723 opengl_funcs.gl.p_glGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2725 /* Switch to our pbuffer */
2726 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
2728 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2729 * After that upload the pbuffer texture data. */
2730 opengl_funcs.gl.p_glBindTexture(object->texture_target, prev_binded_texture);
2731 opengl_funcs.gl.p_glCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2733 /* Switch back to the original drawable and upload the pbuffer-texture */
2734 pglXMakeCurrent(gdi_display, prev_drawable, prev_context);
2735 pglXDestroyContext(gdi_display, tmp_context);
2743 * X11DRV_wglReleaseTexImageARB
2745 * WGL_ARB_render_texture: wglReleaseTexImageARB
2747 static BOOL X11DRV_wglReleaseTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2749 GLboolean ret = GL_FALSE;
2751 TRACE("(%p, %d)\n", object, iBuffer);
2753 if (!object->use_render_texture) {
2754 SetLastError(ERROR_INVALID_HANDLE);
2757 if (1 == use_render_texture_emulation) {
2764 * X11DRV_wglGetExtensionsStringEXT
2766 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2768 static const GLubyte *X11DRV_wglGetExtensionsStringEXT(void)
2770 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2771 return (const GLubyte *)WineGLInfo.wglExtensions;
2775 * X11DRV_wglGetSwapIntervalEXT
2777 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2779 static int X11DRV_wglGetSwapIntervalEXT(void)
2781 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
2782 * interval, so the swap interval has to be tracked. */
2784 return swap_interval;
2788 * X11DRV_wglSwapIntervalEXT
2790 * WGL_EXT_swap_control: wglSwapIntervalEXT
2792 static BOOL X11DRV_wglSwapIntervalEXT(int interval)
2796 TRACE("(%d)\n", interval);
2800 SetLastError(ERROR_INVALID_DATA);
2803 else if (!has_swap_control && interval == 0)
2805 /* wglSwapIntervalEXT considers an interval value of zero to mean that
2806 * vsync should be disabled, but glXSwapIntervalSGI considers such a
2807 * value to be an error. Just silently ignore the request for now. */
2808 WARN("Request to disable vertical sync is not handled\n");
2813 if (pglXSwapIntervalSGI)
2814 ret = !pglXSwapIntervalSGI(interval);
2816 WARN("GLX_SGI_swap_control extension is not available\n");
2819 swap_interval = interval;
2821 SetLastError(ERROR_DC_NOT_FOUND);
2828 * X11DRV_wglSetPixelFormatWINE
2830 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
2831 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
2833 static BOOL X11DRV_wglSetPixelFormatWINE(HDC hdc, int format)
2835 const struct wgl_pixel_format *fmt;
2839 TRACE("(%p,%d)\n", hdc, format);
2841 fmt = get_pixel_format(gdi_display, format, FALSE /* Offscreen */);
2844 ERR( "Invalid format %d\n", format );
2848 hwnd = WindowFromDC( hdc );
2849 if (!hwnd || hwnd == GetDesktopWindow())
2851 ERR( "not a valid window DC %p\n", hdc );
2855 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
2856 if (!(value & GLX_WINDOW_BIT))
2858 WARN( "Pixel format %d is not compatible for window rendering\n", format );
2862 return set_win_format( hwnd, fmt );
2866 * glxRequireVersion (internal)
2868 * Check if the supported GLX version matches requiredVersion.
2870 static BOOL glxRequireVersion(int requiredVersion)
2872 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2873 if(requiredVersion <= WineGLInfo.glxVersion[1])
2879 static void register_extension(const char *ext)
2881 if (WineGLInfo.wglExtensions[0])
2882 strcat(WineGLInfo.wglExtensions, " ");
2883 strcat(WineGLInfo.wglExtensions, ext);
2885 TRACE("'%s'\n", ext);
2889 * X11DRV_WineGL_LoadExtensions
2891 static void X11DRV_WineGL_LoadExtensions(void)
2893 WineGLInfo.wglExtensions[0] = 0;
2895 /* ARB Extensions */
2897 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_create_context"))
2899 register_extension( "WGL_ARB_create_context" );
2900 opengl_funcs.ext.p_wglCreateContextAttribsARB = X11DRV_wglCreateContextAttribsARB;
2902 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_create_context_profile"))
2903 register_extension("WGL_ARB_create_context_profile");
2906 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_fbconfig_float"))
2908 register_extension("WGL_ARB_pixel_format_float");
2909 register_extension("WGL_ATI_pixel_format_float");
2912 register_extension( "WGL_ARB_extensions_string" );
2913 opengl_funcs.ext.p_wglGetExtensionsStringARB = X11DRV_wglGetExtensionsStringARB;
2915 if (glxRequireVersion(3))
2917 register_extension( "WGL_ARB_make_current_read" );
2918 opengl_funcs.ext.p_wglGetCurrentReadDCARB = (void *)1; /* never called */
2919 opengl_funcs.ext.p_wglMakeContextCurrentARB = X11DRV_wglMakeContextCurrentARB;
2922 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_multisample")) register_extension( "WGL_ARB_multisample" );
2924 /* In general pbuffer functionality requires support in the X-server. The functionality is
2925 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
2927 if ( glxRequireVersion(3) && has_extension( WineGLInfo.glxExtensions, "GLX_SGIX_pbuffer") )
2929 register_extension( "WGL_ARB_pbuffer" );
2930 opengl_funcs.ext.p_wglCreatePbufferARB = X11DRV_wglCreatePbufferARB;
2931 opengl_funcs.ext.p_wglDestroyPbufferARB = X11DRV_wglDestroyPbufferARB;
2932 opengl_funcs.ext.p_wglGetPbufferDCARB = X11DRV_wglGetPbufferDCARB;
2933 opengl_funcs.ext.p_wglQueryPbufferARB = X11DRV_wglQueryPbufferARB;
2934 opengl_funcs.ext.p_wglReleasePbufferDCARB = X11DRV_wglReleasePbufferDCARB;
2935 opengl_funcs.ext.p_wglSetPbufferAttribARB = X11DRV_wglSetPbufferAttribARB;
2938 register_extension( "WGL_ARB_pixel_format" );
2939 opengl_funcs.ext.p_wglChoosePixelFormatARB = X11DRV_wglChoosePixelFormatARB;
2940 opengl_funcs.ext.p_wglGetPixelFormatAttribfvARB = X11DRV_wglGetPixelFormatAttribfvARB;
2941 opengl_funcs.ext.p_wglGetPixelFormatAttribivARB = X11DRV_wglGetPixelFormatAttribivARB;
2943 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
2944 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_render_texture") ||
2945 (glxRequireVersion(3) && has_extension( WineGLInfo.glxExtensions, "GLX_SGIX_pbuffer") && use_render_texture_emulation))
2947 register_extension( "WGL_ARB_render_texture" );
2948 opengl_funcs.ext.p_wglBindTexImageARB = X11DRV_wglBindTexImageARB;
2949 opengl_funcs.ext.p_wglReleaseTexImageARB = X11DRV_wglReleaseTexImageARB;
2951 /* The WGL version of GLX_NV_float_buffer requires render_texture */
2952 if (has_extension( WineGLInfo.glxExtensions, "GLX_NV_float_buffer"))
2953 register_extension("WGL_NV_float_buffer");
2955 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
2956 if (has_extension(WineGLInfo.glExtensions, "GL_NV_texture_rectangle"))
2957 register_extension("WGL_NV_texture_rectangle");
2960 /* EXT Extensions */
2962 register_extension( "WGL_EXT_extensions_string" );
2963 opengl_funcs.ext.p_wglGetExtensionsStringEXT = X11DRV_wglGetExtensionsStringEXT;
2965 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
2966 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
2967 register_extension( "WGL_EXT_swap_control" );
2968 opengl_funcs.ext.p_wglSwapIntervalEXT = X11DRV_wglSwapIntervalEXT;
2969 opengl_funcs.ext.p_wglGetSwapIntervalEXT = X11DRV_wglGetSwapIntervalEXT;
2971 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_framebuffer_sRGB"))
2972 register_extension("WGL_EXT_framebuffer_sRGB");
2974 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_fbconfig_packed_float"))
2975 register_extension("WGL_EXT_pixel_format_packed_float");
2977 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_swap_control"))
2978 has_swap_control = TRUE;
2980 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
2981 if (has_extension(WineGLInfo.glExtensions, "GL_NV_vertex_array_range"))
2983 register_extension( "WGL_NV_vertex_array_range" );
2984 opengl_funcs.ext.p_wglAllocateMemoryNV = pglXAllocateMemoryNV;
2985 opengl_funcs.ext.p_wglFreeMemoryNV = pglXFreeMemoryNV;
2988 /* WINE-specific WGL Extensions */
2990 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
2991 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
2993 register_extension( "WGL_WINE_pixel_format_passthrough" );
2994 opengl_funcs.ext.p_wglSetPixelFormatWINE = X11DRV_wglSetPixelFormatWINE;
2999 * glxdrv_SwapBuffers
3001 * Swap the buffers of this DC
3003 static BOOL glxdrv_wglSwapBuffers( HDC hdc )
3005 struct x11drv_escape_flush_gl_drawable escape;
3006 struct gl_drawable *gl;
3007 struct wgl_context *ctx = NtCurrentTeb()->glContext;
3009 TRACE("(%p)\n", hdc);
3011 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
3012 escape.gl_drawable = 0;
3014 if (!(gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
3016 SetLastError( ERROR_INVALID_HANDLE );
3022 case DC_GL_PIXMAP_WIN:
3023 if (ctx) sync_context( ctx );
3024 escape.gl_drawable = gl->pixmap;
3025 if (pglXCopySubBufferMESA) {
3026 /* (glX)SwapBuffers has an implicit glFlush effect, however
3027 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3030 pglXCopySubBufferMESA( gdi_display, gl->drawable, 0, 0,
3031 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top );
3034 pglXSwapBuffers(gdi_display, gl->drawable);
3036 case DC_GL_CHILD_WIN:
3037 escape.gl_drawable = gl->drawable;
3040 pglXSwapBuffers(gdi_display, gl->drawable);
3044 release_gl_drawable( gl );
3046 if (escape.gl_drawable) ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
3050 static struct opengl_funcs opengl_funcs =
3053 glxdrv_wglCopyContext, /* p_wglCopyContext */
3054 glxdrv_wglCreateContext, /* p_wglCreateContext */
3055 glxdrv_wglDeleteContext, /* p_wglDeleteContext */
3056 glxdrv_wglDescribePixelFormat, /* p_wglDescribePixelFormat */
3057 glxdrv_wglGetPixelFormat, /* p_wglGetPixelFormat */
3058 glxdrv_wglGetProcAddress, /* p_wglGetProcAddress */
3059 glxdrv_wglMakeCurrent, /* p_wglMakeCurrent */
3060 glxdrv_wglSetPixelFormat, /* p_wglSetPixelFormat */
3061 glxdrv_wglShareLists, /* p_wglShareLists */
3062 glxdrv_wglSwapBuffers, /* p_wglSwapBuffers */
3066 struct opengl_funcs *get_glx_driver( UINT version )
3068 if (version != WINE_WGL_DRIVER_VERSION)
3070 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_WGL_DRIVER_VERSION );
3073 if (has_opengl()) return &opengl_funcs;
3077 #else /* no OpenGL includes */
3079 struct opengl_funcs *get_glx_driver( UINT version )
3084 BOOL has_gl_drawable( HWND hwnd )
3089 void sync_gl_drawable( HWND hwnd, const RECT *visible_rect, const RECT *client_rect )
3093 void destroy_gl_drawable( HWND hwnd )
3097 #endif /* defined(SONAME_LIBGL) */