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>
51 #include "wine/library.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
58 WINE_DECLARE_DEBUG_CHANNEL(winediag);
59 WINE_DECLARE_DEBUG_CHANNEL(fps);
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 struct gdi_physdev dev;
178 X11DRV_PDEVICE *x11dev;
179 enum dc_gl_type type; /* type of GL device context */
182 Pixmap pixmap; /* pixmap for a DL_GL_PIXMAP_WIN drawable */
185 static const struct gdi_dc_funcs glxdrv_funcs;
187 static inline struct glx_physdev *get_glxdrv_dev( PHYSDEV dev )
189 return (struct glx_physdev *)dev;
192 static struct list context_list = LIST_INIT( context_list );
193 static struct WineGLInfo WineGLInfo = { 0 };
194 static struct wgl_pixel_format *pixel_formats;
195 static int nb_pixel_formats, nb_onscreen_formats;
196 static int use_render_texture_emulation = 1;
197 static BOOL has_swap_control;
198 static int swap_interval = 1;
200 static CRITICAL_SECTION context_section;
201 static CRITICAL_SECTION_DEBUG critsect_debug =
203 0, 0, &context_section,
204 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
205 0, 0, { (DWORD_PTR)(__FILE__ ": context_section") }
207 static CRITICAL_SECTION context_section = { &critsect_debug, -1, 0, 0, 0, 0 };
209 static struct opengl_funcs opengl_funcs;
211 #define USE_GL_FUNC(name) #name,
212 static const char *opengl_func_names[] = { ALL_WGL_FUNCS };
215 static void X11DRV_WineGL_LoadExtensions(void);
216 static void init_pixel_formats( Display *display );
217 static BOOL glxRequireVersion(int requiredVersion);
219 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
220 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
221 TRACE(" - dwFlags : ");
222 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
223 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
224 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
225 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
226 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
227 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
228 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
229 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
230 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
231 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
232 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
233 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
234 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
235 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
236 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
237 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
238 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
239 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
240 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
241 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
245 TRACE(" - iPixelType : ");
246 switch (ppfd->iPixelType) {
247 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
248 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
252 TRACE(" - Color : %d\n", ppfd->cColorBits);
253 TRACE(" - Red : %d\n", ppfd->cRedBits);
254 TRACE(" - Green : %d\n", ppfd->cGreenBits);
255 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
256 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
257 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
258 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
259 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
260 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
262 TRACE(" - iLayerType : ");
263 switch (ppfd->iLayerType) {
264 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
265 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
266 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
271 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
272 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
274 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
276 MAKE_FUNCPTR(glXChooseVisual)
277 MAKE_FUNCPTR(glXCopyContext)
278 MAKE_FUNCPTR(glXCreateContext)
279 MAKE_FUNCPTR(glXCreateGLXPixmap)
280 MAKE_FUNCPTR(glXGetCurrentContext)
281 MAKE_FUNCPTR(glXGetCurrentDrawable)
282 MAKE_FUNCPTR(glXDestroyContext)
283 MAKE_FUNCPTR(glXDestroyGLXPixmap)
284 MAKE_FUNCPTR(glXGetConfig)
285 MAKE_FUNCPTR(glXIsDirect)
286 MAKE_FUNCPTR(glXMakeCurrent)
287 MAKE_FUNCPTR(glXSwapBuffers)
288 MAKE_FUNCPTR(glXQueryExtension)
289 MAKE_FUNCPTR(glXQueryVersion)
292 MAKE_FUNCPTR(glXGetClientString)
293 MAKE_FUNCPTR(glXQueryExtensionsString)
294 MAKE_FUNCPTR(glXQueryServerString)
297 MAKE_FUNCPTR(glXGetFBConfigs)
298 MAKE_FUNCPTR(glXChooseFBConfig)
299 MAKE_FUNCPTR(glXCreatePbuffer)
300 MAKE_FUNCPTR(glXCreateNewContext)
301 MAKE_FUNCPTR(glXDestroyPbuffer)
302 MAKE_FUNCPTR(glXGetFBConfigAttrib)
303 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
304 MAKE_FUNCPTR(glXMakeContextCurrent)
305 MAKE_FUNCPTR(glXQueryDrawable)
306 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
310 static GLXContext (*pglXCreateContextAttribsARB)(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
311 static void* (*pglXGetProcAddressARB)(const GLubyte *);
312 static int (*pglXSwapIntervalSGI)(int);
314 /* NV GLX Extension */
315 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
316 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
318 /* MESA GLX Extensions */
319 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
321 /* Standard OpenGL */
322 static void (*pglFinish)(void);
323 static void (*pglFlush)(void);
325 static void wglFinish(void);
326 static void wglFlush(void);
328 /* check if the extension is present in the list */
329 static BOOL has_extension( const char *list, const char *ext )
331 size_t len = strlen( ext );
335 while (*list == ' ') list++;
336 if (!strncmp( list, ext, len ) && (!list[len] || list[len] == ' ')) return TRUE;
337 list = strchr( list, ' ' );
342 static int GLXErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
344 /* In the future we might want to find the exact X or GLX error to report back to the app */
348 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
350 int screen = DefaultScreen(gdi_display);
351 Window win = 0, root = 0;
352 const char *gl_renderer;
355 GLXContext ctx = NULL;
356 XSetWindowAttributes attr;
358 int attribList[] = {GLX_RGBA, GLX_DOUBLEBUFFER, None};
360 attr.override_redirect = True;
361 attr.colormap = None;
362 attr.border_pixel = 0;
364 vis = pglXChooseVisual(gdi_display, screen, attribList);
367 WORD old_fs = wine_get_fs();
368 /* Create a GLX Context. Without one we can't query GL information */
369 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
370 if (wine_get_fs() != old_fs)
372 wine_set_fs( old_fs );
373 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
374 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
378 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
383 root = RootWindow( gdi_display, vis->screen );
384 if (vis->visual != DefaultVisual( gdi_display, vis->screen ))
385 attr.colormap = XCreateColormap( gdi_display, root, vis->visual, AllocNone );
386 if ((win = XCreateWindow( gdi_display, root, -1, -1, 1, 1, 0, vis->depth, InputOutput,
387 vis->visual, CWBorderPixel | CWOverrideRedirect | CWColormap, &attr )))
388 XMapWindow( gdi_display, win );
392 if(pglXMakeCurrent(gdi_display, win, ctx) == 0)
394 ERR_(winediag)( "Unable to activate OpenGL context, most likely your OpenGL drivers haven't been installed correctly\n" );
397 gl_renderer = (const char *)opengl_funcs.gl.p_glGetString(GL_RENDERER);
398 WineGLInfo.glVersion = (const char *) opengl_funcs.gl.p_glGetString(GL_VERSION);
399 str = (const char *) opengl_funcs.gl.p_glGetString(GL_EXTENSIONS);
400 WineGLInfo.glExtensions = HeapAlloc(GetProcessHeap(), 0, strlen(str)+1);
401 strcpy(WineGLInfo.glExtensions, str);
403 /* Get the common GLX version supported by GLX client and server ( major/minor) */
404 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
406 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
407 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
408 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
410 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
411 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
412 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
414 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
415 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
417 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
418 TRACE("GL renderer : %s.\n", gl_renderer);
419 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
420 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
421 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
422 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
423 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
424 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
426 if(!WineGLInfo.glxDirect)
428 int fd = ConnectionNumber(gdi_display);
429 struct sockaddr_un uaddr;
430 unsigned int uaddrlen = sizeof(struct sockaddr_un);
432 /* In general indirect rendering on a local X11 server indicates a driver problem.
433 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
435 if(!getsockname(fd, (struct sockaddr *)&uaddr, &uaddrlen) && uaddr.sun_family == AF_UNIX)
436 ERR_(winediag)("Direct rendering is disabled, most likely your OpenGL drivers "
437 "haven't been installed correctly (using GL renderer %s, version %s).\n",
438 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
442 /* In general you would expect that if direct rendering is returned, that you receive hardware
443 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
444 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
445 * software rendering, it shows direct rendering.
447 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
448 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
449 * it shows 'Mesa X11'.
451 if(!strcmp(gl_renderer, "Software Rasterizer") || !strcmp(gl_renderer, "Mesa X11"))
452 ERR_(winediag)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL "
453 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
454 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
461 pglXMakeCurrent(gdi_display, None, NULL);
462 pglXDestroyContext(gdi_display, ctx);
464 if (win != root) XDestroyWindow( gdi_display, win );
465 if (attr.colormap) XFreeColormap( gdi_display, attr.colormap );
466 if (!ret) ERR(" couldn't initialize OpenGL, expect problems\n");
470 static BOOL has_opengl(void)
472 static int init_done;
473 static void *opengl_handle;
476 int error_base, event_base;
479 if (init_done) return (opengl_handle != NULL);
482 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
483 and include all dependencies */
484 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, buffer, sizeof(buffer));
485 if (opengl_handle == NULL)
487 ERR( "Failed to load libGL: %s\n", buffer );
488 ERR( "OpenGL support is disabled.\n");
492 for (i = 0; i < sizeof(opengl_func_names)/sizeof(opengl_func_names[0]); i++)
494 if (!(((void **)&opengl_funcs.gl)[i] = wine_dlsym( opengl_handle, opengl_func_names[i], NULL, 0 )))
496 ERR( "%s not found in libGL, disabling OpenGL.\n", opengl_func_names[i] );
501 /* redirect some standard OpenGL functions */
502 #define REDIRECT(func) \
503 do { p##func = opengl_funcs.gl.p_##func; opengl_funcs.gl.p_##func = w##func; } while(0)
504 REDIRECT( glFinish );
508 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
509 if (pglXGetProcAddressARB == NULL) {
510 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
514 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
516 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
521 LOAD_FUNCPTR(glXChooseVisual);
522 LOAD_FUNCPTR(glXCopyContext);
523 LOAD_FUNCPTR(glXCreateContext);
524 LOAD_FUNCPTR(glXCreateGLXPixmap);
525 LOAD_FUNCPTR(glXGetCurrentContext);
526 LOAD_FUNCPTR(glXGetCurrentDrawable);
527 LOAD_FUNCPTR(glXDestroyContext);
528 LOAD_FUNCPTR(glXDestroyGLXPixmap);
529 LOAD_FUNCPTR(glXGetConfig);
530 LOAD_FUNCPTR(glXIsDirect);
531 LOAD_FUNCPTR(glXMakeCurrent);
532 LOAD_FUNCPTR(glXSwapBuffers);
533 LOAD_FUNCPTR(glXQueryExtension);
534 LOAD_FUNCPTR(glXQueryVersion);
537 LOAD_FUNCPTR(glXGetClientString);
538 LOAD_FUNCPTR(glXQueryExtensionsString);
539 LOAD_FUNCPTR(glXQueryServerString);
542 LOAD_FUNCPTR(glXCreatePbuffer);
543 LOAD_FUNCPTR(glXCreateNewContext);
544 LOAD_FUNCPTR(glXDestroyPbuffer);
545 LOAD_FUNCPTR(glXMakeContextCurrent);
546 LOAD_FUNCPTR(glXGetCurrentReadDrawable);
547 LOAD_FUNCPTR(glXGetFBConfigs);
550 /* It doesn't matter if these fail. They'll only be used if the driver reports
551 the associated extension is available (and if a driver reports the extension
552 is available but fails to provide the functions, it's quite broken) */
553 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
554 /* ARB GLX Extension */
555 LOAD_FUNCPTR(glXCreateContextAttribsARB);
556 /* SGI GLX Extension */
557 LOAD_FUNCPTR(glXSwapIntervalSGI);
558 /* NV GLX Extension */
559 LOAD_FUNCPTR(glXAllocateMemoryNV);
560 LOAD_FUNCPTR(glXFreeMemoryNV);
563 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed;
565 if (pglXQueryExtension(gdi_display, &error_base, &event_base)) {
566 TRACE("GLX is up and running error_base = %d\n", error_base);
568 ERR( "GLX extension is missing, disabling OpenGL.\n" );
572 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
573 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
576 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
577 * depends on the reported GLX client / server version and on the client / server extension list.
578 * Those don't have to be the same.
580 * In general the server GLX information lists the capabilities in case of indirect rendering.
581 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
582 * available and in that case the client GLX informat can be used.
583 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
584 * in the GLX version/extension list. When a program does this it works for certain for both
585 * direct and indirect rendering.
587 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
588 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
589 * extension list which causes this extension not to be listed. (Wine requires this extension).
590 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
591 * pbuffers is around.
593 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
594 * the ATI drivers and from then on use GLX client information for them.
597 if(glxRequireVersion(3)) {
598 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
599 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
600 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
601 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
602 } else if (has_extension( WineGLInfo.glxExtensions, "GLX_SGIX_fbconfig")) {
603 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
604 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
605 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
607 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
608 * enable this function when the Xserver understand GLX 1.3 or newer
610 pglXQueryDrawable = NULL;
611 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
612 TRACE("Overriding ATI GLX capabilities!\n");
613 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
614 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
615 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
616 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
618 /* Use client GLX information in case of the ATI drivers. We override the
619 * capabilities over here and not somewhere else as ATI might better their
620 * life in the future. In case they release proper drivers this block of
621 * code won't be called. */
622 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
624 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
627 if (has_extension( WineGLInfo.glxExtensions, "GLX_MESA_copy_sub_buffer")) {
628 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
631 X11DRV_WineGL_LoadExtensions();
632 init_pixel_formats( gdi_display );
636 wine_dlclose(opengl_handle, NULL, 0);
637 opengl_handle = NULL;
641 static int describeContext( struct wgl_context *ctx ) {
644 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
645 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
646 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
647 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
648 TRACE(" - VISUAL_ID 0x%x\n", tmp);
653 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, struct wgl_pbuffer* pbuf) {
658 int nvfloatattrib = GLX_DONT_CARE;
659 int pixelattrib = GLX_DONT_CARE;
661 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
662 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
663 while (iWGLAttr && 0 != iWGLAttr[cur]) {
664 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
666 switch (iWGLAttr[cur]) {
667 case WGL_AUX_BUFFERS_ARB:
668 pop = iWGLAttr[++cur];
669 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
670 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
672 case WGL_COLOR_BITS_ARB:
673 pop = iWGLAttr[++cur];
674 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
675 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
677 case WGL_BLUE_BITS_ARB:
678 pop = iWGLAttr[++cur];
679 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
680 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
682 case WGL_RED_BITS_ARB:
683 pop = iWGLAttr[++cur];
684 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
685 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
687 case WGL_GREEN_BITS_ARB:
688 pop = iWGLAttr[++cur];
689 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
690 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
692 case WGL_ALPHA_BITS_ARB:
693 pop = iWGLAttr[++cur];
694 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
695 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
697 case WGL_DEPTH_BITS_ARB:
698 pop = iWGLAttr[++cur];
699 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
700 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
702 case WGL_STENCIL_BITS_ARB:
703 pop = iWGLAttr[++cur];
704 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
705 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
707 case WGL_DOUBLE_BUFFER_ARB:
708 pop = iWGLAttr[++cur];
709 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
710 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
713 pop = iWGLAttr[++cur];
714 PUSH2(oGLXAttr, GLX_STEREO, pop);
715 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur, pop);
718 case WGL_PIXEL_TYPE_ARB:
719 pop = iWGLAttr[++cur];
720 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
722 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
723 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
724 /* 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 */
725 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
726 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT: pixelattrib = GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT; break ;
728 ERR("unexpected PixelType(%x)\n", pop);
733 case WGL_SUPPORT_GDI_ARB:
734 /* This flag is set in a pixel format */
735 pop = iWGLAttr[++cur];
736 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
739 case WGL_DRAW_TO_BITMAP_ARB:
740 /* This flag is set in a pixel format */
741 pop = iWGLAttr[++cur];
742 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
745 case WGL_DRAW_TO_WINDOW_ARB:
746 pop = iWGLAttr[++cur];
747 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
748 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
750 drawattrib |= GLX_WINDOW_BIT;
754 case WGL_DRAW_TO_PBUFFER_ARB:
755 pop = iWGLAttr[++cur];
756 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
757 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
759 drawattrib |= GLX_PBUFFER_BIT;
763 case WGL_ACCELERATION_ARB:
764 /* This flag is set in a pixel format */
765 pop = iWGLAttr[++cur];
766 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur, pop);
769 case WGL_SUPPORT_OPENGL_ARB:
770 pop = iWGLAttr[++cur];
771 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
772 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
775 case WGL_SWAP_METHOD_ARB:
776 pop = iWGLAttr[++cur];
777 /* For now we ignore this and just return SWAP_EXCHANGE */
778 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur, pop);
781 case WGL_PBUFFER_LARGEST_ARB:
782 pop = iWGLAttr[++cur];
783 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
784 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
787 case WGL_SAMPLE_BUFFERS_ARB:
788 pop = iWGLAttr[++cur];
789 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
790 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
793 case WGL_SAMPLES_ARB:
794 pop = iWGLAttr[++cur];
795 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
796 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
799 case WGL_TEXTURE_FORMAT_ARB:
800 case WGL_TEXTURE_TARGET_ARB:
801 case WGL_MIPMAP_TEXTURE_ARB:
802 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
803 pop = iWGLAttr[++cur];
805 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
807 if (!use_render_texture_emulation) {
808 if (WGL_NO_TEXTURE_ARB != pop) {
809 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
810 return -1; /** error: don't support it */
812 drawattrib |= GLX_PBUFFER_BIT;
816 case WGL_FLOAT_COMPONENTS_NV:
817 nvfloatattrib = iWGLAttr[++cur];
818 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
820 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
821 case WGL_BIND_TO_TEXTURE_RGB_ARB:
822 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
823 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
824 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
825 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
826 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
827 pop = iWGLAttr[++cur];
828 /** cannot be converted, see direct handling on
829 * - wglGetPixelFormatAttribivARB
830 * TODO: wglChoosePixelFormat
833 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
834 pop = iWGLAttr[++cur];
835 PUSH2(oGLXAttr, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, pop);
836 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur, pop);
839 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
840 pop = iWGLAttr[++cur];
841 PUSH2(oGLXAttr, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT, pop);
842 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur, pop);
845 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
851 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
852 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
853 * pixmap and pbuffer formats appear as well. */
854 if (!drawattrib) drawattrib = GLX_DONT_CARE;
855 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
856 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
858 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
859 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
860 * GLX_DONT_CARE unless it is overridden. */
861 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
862 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
864 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
865 if (has_extension(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
866 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
867 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
873 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
875 int render_type=0, render_type_bit;
876 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
877 switch(render_type_bit)
880 render_type = GLX_RGBA_TYPE;
882 case GLX_COLOR_INDEX_BIT:
883 render_type = GLX_COLOR_INDEX_TYPE;
885 case GLX_RGBA_FLOAT_BIT:
886 render_type = GLX_RGBA_FLOAT_TYPE;
888 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT:
889 render_type = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
892 ERR("Unknown render_type: %x\n", render_type_bit);
897 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
898 static BOOL check_fbconfig_bitmap_capability(Display *display, GLXFBConfig fbconfig)
901 pglXGetFBConfigAttrib(display, fbconfig, GLX_DOUBLEBUFFER, &dbuf);
902 pglXGetFBConfigAttrib(gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &value);
904 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
905 * the GLX_PIXMAP_BIT set. */
906 return !dbuf && (value & GLX_PIXMAP_BIT);
909 static void init_pixel_formats( Display *display )
911 struct wgl_pixel_format *list;
912 int size = 0, onscreen_size = 0;
913 int fmt_id, nCfgs, i, run, bmp_formats;
915 XVisualInfo *visinfo;
917 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
918 if (NULL == cfgs || 0 == nCfgs) {
919 if(cfgs != NULL) XFree(cfgs);
920 ERR("glXChooseFBConfig returns NULL\n");
924 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
925 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
926 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
927 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
929 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
931 for(i=0, bmp_formats=0; i<nCfgs; i++)
933 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
936 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats);
938 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nCfgs + bmp_formats) * sizeof(*list));
940 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
941 * Do this as GLX doesn't guarantee that the list is sorted */
942 for(run=0; run < 2; run++)
944 for(i=0; i<nCfgs; i++) {
945 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
946 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
948 /* The first run we only add onscreen formats (ones which have an associated X Visual).
949 * The second run we only set offscreen formats. */
952 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
953 * The contents is copied to the destination using XCopyArea. For the copying to work
954 * the depth of the source and destination window should be the same. In general this should
955 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
956 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
957 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
958 * list formats with the same depth. */
959 if(visinfo->depth != screen_depth)
965 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
966 list[size].fbconfig = cfgs[i];
967 list[size].fmt_id = fmt_id;
968 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
969 list[size].dwFlags = 0;
973 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
974 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
976 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
977 list[size].fbconfig = cfgs[i];
978 list[size].fmt_id = fmt_id;
979 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
980 list[size].dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_GENERIC_FORMAT;
984 } else if(run && !visinfo) {
985 int window_drawable=0;
986 pglXGetFBConfigAttrib(gdi_display, cfgs[i], GLX_DRAWABLE_TYPE, &window_drawable);
988 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
989 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
990 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
991 * likely make our child window opengl rendering more complicated since likely you can't use
992 * XCopyArea on a GLX Window.
993 * For now ignore fbconfigs which are window drawable but lack a visual. */
994 if(window_drawable & GLX_WINDOW_BIT)
996 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id);
1000 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1001 list[size].fbconfig = cfgs[i];
1002 list[size].fmt_id = fmt_id;
1003 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1004 list[size].dwFlags = 0;
1008 if (visinfo) XFree(visinfo);
1014 pixel_formats = list;
1015 nb_pixel_formats = size;
1016 nb_onscreen_formats = onscreen_size;
1019 static inline BOOL is_valid_pixel_format( int format )
1021 return format > 0 && format <= nb_pixel_formats;
1024 static inline BOOL is_onscreen_pixel_format( int format )
1026 return format > 0 && format <= nb_onscreen_formats;
1029 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1030 * In our WGL implementation we only support a subset of these formats namely the format of
1031 * Wine's main visual and offscreen formats (if they are available).
1032 * This function converts a WGL format to its corresponding GLX one.
1034 static const struct wgl_pixel_format *get_pixel_format(Display *display, int iPixelFormat, BOOL AllowOffscreen)
1036 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1037 * iPixelFormat in case of probing the number of pixelformats.
1039 if (is_valid_pixel_format( iPixelFormat ) &&
1040 (is_onscreen_pixel_format( iPixelFormat ) || AllowOffscreen)) {
1041 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n",
1042 pixel_formats[iPixelFormat-1].fmt_id, iPixelFormat);
1043 return &pixel_formats[iPixelFormat-1];
1048 static int pixelformat_from_fbconfig_id(XID fbconfig_id)
1052 if (!fbconfig_id) return 0;
1054 for (i = 0; i < nb_pixel_formats; i++)
1055 if (pixel_formats[i].fmt_id == fbconfig_id) return i + 1;
1057 /* This will happen on hwnds without a pixel format set; it's ok */
1062 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1063 void mark_drawable_dirty(Drawable old, Drawable new)
1065 struct wgl_context *ctx;
1067 EnterCriticalSection( &context_section );
1068 LIST_FOR_EACH_ENTRY( ctx, &context_list, struct wgl_context, entry )
1070 if (old == ctx->drawables[0]) {
1071 ctx->drawables[0] = new;
1072 ctx->refresh_drawables = TRUE;
1074 if (old == ctx->drawables[1]) {
1075 ctx->drawables[1] = new;
1076 ctx->refresh_drawables = TRUE;
1079 LeaveCriticalSection( &context_section );
1082 /* Given the current context, make sure its drawable is sync'd */
1083 static inline void sync_context(struct wgl_context *context)
1085 EnterCriticalSection( &context_section );
1086 if (context->refresh_drawables) {
1087 if (glxRequireVersion(3))
1088 pglXMakeContextCurrent(gdi_display, context->drawables[0],
1089 context->drawables[1], context->ctx);
1091 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
1092 context->refresh_drawables = FALSE;
1094 LeaveCriticalSection( &context_section );
1098 static GLXContext create_glxcontext(Display *display, struct wgl_context *context, GLXContext shareList)
1102 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1103 BOOL indirect = !(context->fmt->dwFlags & PFD_DRAW_TO_BITMAP);
1105 if(context->gl3_context)
1107 if(context->numAttribs)
1108 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, context->attribList);
1110 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, NULL);
1112 else if(context->vis)
1113 ctx = pglXCreateContext(gdi_display, context->vis, shareList, indirect);
1114 else /* Create a GLX Context for a pbuffer */
1115 ctx = pglXCreateNewContext(gdi_display, context->fmt->fbconfig, context->fmt->render_type, shareList, TRUE);
1121 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
1123 return pglXCreateGLXPixmap(display, vis, parent);
1128 * glxdrv_DescribePixelFormat
1130 * Get the pixel-format descriptor associated to the given id
1132 static int glxdrv_wglDescribePixelFormat( HDC hdc, int iPixelFormat,
1133 UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd)
1135 /*XVisualInfo *vis;*/
1138 const struct wgl_pixel_format *fmt;
1140 if (!has_opengl()) return 0;
1142 TRACE("(%p,%d,%d,%p)\n", hdc, iPixelFormat, nBytes, ppfd);
1144 if (!ppfd) return nb_onscreen_formats;
1146 /* 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 */
1147 fmt = get_pixel_format(gdi_display, iPixelFormat, FALSE /* Offscreen */);
1149 WARN("unexpected format %d\n", iPixelFormat);
1153 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1154 ERR("Wrong structure size !\n");
1155 /* Should set error */
1159 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1160 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1163 /* These flags are always the same... */
1164 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1165 /* Now the flags extracted from the Visual */
1167 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1168 if(value & GLX_WINDOW_BIT)
1169 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1171 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1172 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1173 * 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
1174 * offered the GDI bit either. */
1175 ppfd->dwFlags |= fmt->dwFlags & (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI);
1177 /* PFD_GENERIC_FORMAT - gdi software rendering
1178 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1179 * none set - full hardware accelerated by a ICD
1181 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1182 ppfd->dwFlags |= fmt->dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED);
1184 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1186 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1187 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1189 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1192 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1193 if (value & GLX_RGBA_BIT)
1194 ppfd->iPixelType = PFD_TYPE_RGBA;
1196 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1199 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1200 ppfd->cColorBits = value;
1202 /* Red, green, blue and alpha bits / shifts */
1203 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1204 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1205 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1206 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1207 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1209 ppfd->cRedBits = rb;
1210 ppfd->cRedShift = gb + bb + ab;
1211 ppfd->cBlueBits = bb;
1212 ppfd->cBlueShift = ab;
1213 ppfd->cGreenBits = gb;
1214 ppfd->cGreenShift = bb + ab;
1215 ppfd->cAlphaBits = ab;
1216 ppfd->cAlphaShift = 0;
1219 ppfd->cRedShift = 0;
1220 ppfd->cBlueBits = 0;
1221 ppfd->cBlueShift = 0;
1222 ppfd->cGreenBits = 0;
1223 ppfd->cGreenShift = 0;
1224 ppfd->cAlphaBits = 0;
1225 ppfd->cAlphaShift = 0;
1228 /* Accum RGBA bits */
1229 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1230 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1231 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1232 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1234 ppfd->cAccumBits = rb+gb+bb+ab;
1235 ppfd->cAccumRedBits = rb;
1236 ppfd->cAccumGreenBits = gb;
1237 ppfd->cAccumBlueBits = bb;
1238 ppfd->cAccumAlphaBits = ab;
1241 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1242 ppfd->cAuxBuffers = value;
1245 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1246 ppfd->cDepthBits = value;
1249 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1250 ppfd->cStencilBits = value;
1252 ppfd->iLayerType = PFD_MAIN_PLANE;
1254 if (TRACE_ON(wgl)) {
1255 dump_PIXELFORMATDESCRIPTOR(ppfd);
1258 return nb_onscreen_formats;
1261 /***********************************************************************
1262 * glxdrv_wglGetPixelFormat
1264 static int glxdrv_wglGetPixelFormat( HDC hdc )
1266 struct x11drv_escape_get_drawable escape;
1268 TRACE( "(%p)\n", hdc );
1270 escape.code = X11DRV_GET_DRAWABLE;
1271 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape.code), (LPCSTR)&escape.code,
1272 sizeof(escape), (LPSTR)&escape ))
1275 if (!is_valid_pixel_format( escape.pixel_format )) return 0; /* not set yet */
1277 if (!is_onscreen_pixel_format( escape.pixel_format ))
1279 /* Offscreen formats can't be used with traditional WGL calls.
1280 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1281 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", escape.pixel_format);
1284 TRACE("(%p): returns %d\n", hdc, escape.pixel_format);
1285 return escape.pixel_format;
1288 /***********************************************************************
1289 * glxdrv_wglSetPixelFormat
1291 static BOOL glxdrv_wglSetPixelFormat( HDC hdc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd )
1293 struct x11drv_escape_get_drawable escape;
1294 const struct wgl_pixel_format *fmt;
1298 TRACE("(%p,%d,%p)\n", hdc, iPixelFormat, ppfd);
1300 escape.code = X11DRV_GET_DRAWABLE;
1301 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape.code), (LPCSTR)&escape.code,
1302 sizeof(escape), (LPSTR)&escape ))
1305 if (escape.pixel_format) /* cannot change it if already set */
1306 return (escape.pixel_format == iPixelFormat);
1308 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1309 if (escape.drawable == root_window)
1311 ERR("Invalid operation on root_window\n");
1315 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1316 fmt = get_pixel_format(gdi_display, iPixelFormat, FALSE /* Offscreen */);
1318 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1322 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1324 hwnd = WindowFromDC( hdc );
1326 if(!(value&GLX_WINDOW_BIT)) {
1327 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1331 if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, fmt->fmt_id, 0)) {
1332 ERR("Couldn't set format of the window, returning failure\n");
1335 /* physDev->current_pf will be set by the DCE update */
1337 else FIXME("called on a non-window object?\n");
1339 if (TRACE_ON(wgl)) {
1342 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1344 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1346 TRACE(" FBConfig have :\n");
1347 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1348 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1349 TRACE(" - VISUAL_ID 0x%x\n", value);
1350 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1351 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1357 /***********************************************************************
1358 * glxdrv_wglCopyContext
1360 static BOOL glxdrv_wglCopyContext(struct wgl_context *src, struct wgl_context *dst, UINT mask)
1362 TRACE("%p -> %p mask %#x\n", src, dst, mask);
1364 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1366 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1370 /***********************************************************************
1371 * glxdrv_wglCreateContext
1373 static struct wgl_context *glxdrv_wglCreateContext( HDC hdc )
1375 struct x11drv_escape_get_drawable escape;
1376 struct wgl_context *ret;
1377 const struct wgl_pixel_format *fmt;
1379 TRACE( "(%p)\n", hdc );
1381 escape.code = X11DRV_GET_DRAWABLE;
1382 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape.code), (LPCSTR)&escape.code,
1383 sizeof(escape), (LPSTR)&escape ))
1386 fmt = get_pixel_format(gdi_display, escape.pixel_format, TRUE /* Offscreen */);
1387 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1388 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1389 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1390 * If this fails something is very wrong on the system. */
1392 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", escape.pixel_format);
1393 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1397 if (!(ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret)))) return 0;
1401 ret->has_been_current = FALSE;
1402 ret->sharing = FALSE;
1404 ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1405 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1407 EnterCriticalSection( &context_section );
1408 list_add_head( &context_list, &ret->entry );
1409 LeaveCriticalSection( &context_section );
1411 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1415 /***********************************************************************
1416 * glxdrv_wglDeleteContext
1418 static void glxdrv_wglDeleteContext(struct wgl_context *ctx)
1420 TRACE("(%p)\n", ctx);
1422 EnterCriticalSection( &context_section );
1423 list_remove( &ctx->entry );
1424 LeaveCriticalSection( &context_section );
1426 if (ctx->ctx) pglXDestroyContext( gdi_display, ctx->ctx );
1427 if (ctx->vis) XFree( ctx->vis );
1428 HeapFree( GetProcessHeap(), 0, ctx );
1431 /***********************************************************************
1432 * glxdrv_wglGetProcAddress
1434 static PROC glxdrv_wglGetProcAddress(LPCSTR lpszProc)
1436 if (!strncmp(lpszProc, "wgl", 3)) return NULL;
1437 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1440 /***********************************************************************
1441 * glxdrv_wglMakeCurrent
1443 static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx)
1446 struct x11drv_escape_get_drawable escape;
1448 TRACE("(%p,%p)\n", hdc, ctx);
1452 pglXMakeCurrent(gdi_display, None, NULL);
1453 NtCurrentTeb()->glContext = NULL;
1457 escape.code = X11DRV_GET_DRAWABLE;
1458 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape.code), (LPCSTR)&escape.code,
1459 sizeof(escape), (LPSTR)&escape ))
1462 if (!escape.pixel_format)
1464 WARN("Trying to use an invalid drawable\n");
1465 SetLastError(ERROR_INVALID_HANDLE);
1468 if (ctx->fmt - pixel_formats != escape.pixel_format - 1)
1470 WARN( "mismatched pixel format hdc %p %u ctx %p\n", hdc, escape.pixel_format, ctx );
1471 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1476 if (TRACE_ON(wgl)) {
1478 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &vis_id);
1479 describeContext(ctx);
1480 TRACE("hdc %p drawable %lx fmt %u vis %x ctx %p\n", hdc,
1481 escape.gl_drawable, escape.pixel_format, vis_id, ctx->ctx);
1484 ret = pglXMakeCurrent(gdi_display, escape.gl_drawable, ctx->ctx);
1488 NtCurrentTeb()->glContext = ctx;
1490 EnterCriticalSection( &context_section );
1491 ctx->has_been_current = TRUE;
1493 ctx->drawables[0] = escape.gl_drawable;
1494 ctx->drawables[1] = escape.gl_drawable;
1495 ctx->refresh_drawables = FALSE;
1496 LeaveCriticalSection( &context_section );
1499 SetLastError(ERROR_INVALID_HANDLE);
1501 TRACE(" returning %s\n", (ret ? "True" : "False"));
1505 /***********************************************************************
1506 * X11DRV_wglMakeContextCurrentARB
1508 static BOOL X11DRV_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *ctx )
1510 struct x11drv_escape_get_drawable escape_draw, escape_read;
1513 TRACE("(%p,%p,%p)\n", draw_hdc, read_hdc, ctx);
1517 pglXMakeCurrent(gdi_display, None, NULL);
1518 NtCurrentTeb()->glContext = NULL;
1522 escape_draw.code = X11DRV_GET_DRAWABLE;
1523 if (!ExtEscape( draw_hdc, X11DRV_ESCAPE, sizeof(escape_draw.code), (LPCSTR)&escape_draw.code,
1524 sizeof(escape_draw), (LPSTR)&escape_draw ))
1527 escape_read.code = X11DRV_GET_DRAWABLE;
1528 if (!ExtEscape( read_hdc, X11DRV_ESCAPE, sizeof(escape_read.code), (LPCSTR)&escape_read.code,
1529 sizeof(escape_read), (LPSTR)&escape_read ))
1532 if (!escape_draw.pixel_format)
1534 WARN("Trying to use an invalid drawable\n");
1535 SetLastError(ERROR_INVALID_HANDLE);
1540 if (!pglXMakeContextCurrent) return FALSE;
1542 ret = pglXMakeContextCurrent(gdi_display, escape_draw.gl_drawable, escape_read.gl_drawable, ctx->ctx);
1545 EnterCriticalSection( &context_section );
1546 ctx->has_been_current = TRUE;
1547 ctx->hdc = draw_hdc;
1548 ctx->drawables[0] = escape_draw.gl_drawable;
1549 ctx->drawables[1] = escape_read.gl_drawable;
1550 ctx->refresh_drawables = FALSE;
1551 LeaveCriticalSection( &context_section );
1552 NtCurrentTeb()->glContext = ctx;
1555 SetLastError(ERROR_INVALID_HANDLE);
1558 TRACE(" returning %s\n", (ret ? "True" : "False"));
1562 /***********************************************************************
1563 * glxdrv_wglShareLists
1565 static BOOL glxdrv_wglShareLists(struct wgl_context *org, struct wgl_context *dest)
1567 TRACE("(%p, %p)\n", org, dest);
1569 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1570 * at context creation time but in case of WGL it is done using wglShareLists.
1571 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1572 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1573 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1574 * so there delaying context creation doesn't work.
1576 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1577 * and when a program requests sharing we recreate the destination context if it hasn't been made
1578 * current or when it hasn't shared display lists before.
1581 if((org->has_been_current && dest->has_been_current) || dest->has_been_current)
1583 ERR("Could not share display lists, one of the contexts has been current already !\n");
1586 else if(dest->sharing)
1588 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1593 describeContext(org);
1594 describeContext(dest);
1596 /* Re-create the GLX context and share display lists */
1597 pglXDestroyContext(gdi_display, dest->ctx);
1598 dest->ctx = create_glxcontext(gdi_display, dest, org->ctx);
1599 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1601 org->sharing = TRUE;
1602 dest->sharing = TRUE;
1608 static void flush_gl_drawable( struct glx_physdev *physdev )
1611 int w = physdev->x11dev->dc_rect.right - physdev->x11dev->dc_rect.left;
1612 int h = physdev->x11dev->dc_rect.bottom - physdev->x11dev->dc_rect.top;
1613 Drawable src = physdev->drawable;
1615 if (w <= 0 || h <= 0) return;
1617 switch (physdev->type)
1619 case DC_GL_PIXMAP_WIN:
1620 src = physdev->pixmap;
1622 case DC_GL_CHILD_WIN:
1623 /* The GL drawable may be lagged behind if we don't flush first, so
1624 * flush the display make sure we copy up-to-date data */
1625 XFlush(gdi_display);
1626 XSetFunction(gdi_display, physdev->x11dev->gc, GXcopy);
1627 XCopyArea(gdi_display, src, physdev->x11dev->drawable, physdev->x11dev->gc, 0, 0, w, h,
1628 physdev->x11dev->dc_rect.left, physdev->x11dev->dc_rect.top);
1629 SetRect( &rect, 0, 0, w, h );
1630 add_device_bounds( physdev->x11dev, &rect );
1637 static void wglFinish(void)
1639 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1640 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
1644 ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
1647 static void wglFlush(void)
1649 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1650 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
1654 ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
1657 /***********************************************************************
1658 * X11DRV_wglCreateContextAttribsARB
1660 static struct wgl_context *X11DRV_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *hShareContext,
1661 const int* attribList )
1663 struct x11drv_escape_get_drawable escape;
1664 struct wgl_context *ret;
1665 const struct wgl_pixel_format *fmt;
1667 TRACE("(%p %p %p)\n", hdc, hShareContext, attribList);
1669 escape.code = X11DRV_GET_DRAWABLE;
1670 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape.code), (LPCSTR)&escape.code,
1671 sizeof(escape), (LPSTR)&escape ))
1674 fmt = get_pixel_format(gdi_display, escape.pixel_format, TRUE /* Offscreen */);
1675 /* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones.
1676 * If this fails something is very wrong on the system. */
1679 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", escape.pixel_format);
1680 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1684 if (!(ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret)))) return 0;
1688 ret->vis = NULL; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
1689 ret->gl3_context = TRUE;
1691 ret->numAttribs = 0;
1694 int *pAttribList = (int*)attribList;
1695 int *pContextAttribList = &ret->attribList[0];
1696 /* attribList consists of pairs {token, value] terminated with 0 */
1697 while(pAttribList[0] != 0)
1699 TRACE("%#x %#x\n", pAttribList[0], pAttribList[1]);
1700 switch(pAttribList[0])
1702 case WGL_CONTEXT_MAJOR_VERSION_ARB:
1703 pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
1704 pContextAttribList[1] = pAttribList[1];
1706 case WGL_CONTEXT_MINOR_VERSION_ARB:
1707 pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB;
1708 pContextAttribList[1] = pAttribList[1];
1710 case WGL_CONTEXT_LAYER_PLANE_ARB:
1712 case WGL_CONTEXT_FLAGS_ARB:
1713 pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB;
1714 pContextAttribList[1] = pAttribList[1];
1716 case WGL_CONTEXT_PROFILE_MASK_ARB:
1717 pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
1718 pContextAttribList[1] = pAttribList[1];
1721 ERR("Unhandled attribList pair: %#x %#x\n", pAttribList[0], pAttribList[1]);
1726 pContextAttribList += 2;
1730 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
1731 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1733 XSync(gdi_display, False);
1734 if(X11DRV_check_error() || !ret->ctx)
1736 /* In the future we should convert the GLX error to a win32 one here if needed */
1737 ERR("Context creation failed\n");
1738 HeapFree( GetProcessHeap(), 0, ret );
1742 EnterCriticalSection( &context_section );
1743 list_add_head( &context_list, &ret->entry );
1744 LeaveCriticalSection( &context_section );
1746 TRACE(" creating context %p\n", ret);
1751 * X11DRV_wglGetExtensionsStringARB
1753 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
1755 static const GLubyte *X11DRV_wglGetExtensionsStringARB(HDC hdc)
1757 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
1758 return (const GLubyte *)WineGLInfo.wglExtensions;
1762 * X11DRV_wglCreatePbufferARB
1764 * WGL_ARB_pbuffer: wglCreatePbufferARB
1766 static struct wgl_pbuffer *X11DRV_wglCreatePbufferARB( HDC hdc, int iPixelFormat, int iWidth, int iHeight,
1767 const int *piAttribList )
1769 struct wgl_pbuffer* object = NULL;
1770 const struct wgl_pixel_format *fmt = NULL;
1774 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
1776 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
1777 fmt = get_pixel_format(gdi_display, iPixelFormat, TRUE /* Offscreen */);
1779 ERR("(%p): invalid pixel format %d\n", hdc, iPixelFormat);
1780 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1784 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1785 if (NULL == object) {
1786 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
1789 object->width = iWidth;
1790 object->height = iHeight;
1793 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
1794 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
1795 while (piAttribList && 0 != *piAttribList) {
1797 switch (*piAttribList) {
1798 case WGL_PBUFFER_LARGEST_ARB: {
1800 attr_v = *piAttribList;
1801 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
1802 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
1806 case WGL_TEXTURE_FORMAT_ARB: {
1808 attr_v = *piAttribList;
1809 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
1810 if (WGL_NO_TEXTURE_ARB == attr_v) {
1811 object->use_render_texture = 0;
1813 if (!use_render_texture_emulation) {
1814 SetLastError(ERROR_INVALID_DATA);
1818 case WGL_TEXTURE_RGB_ARB:
1819 object->use_render_texture = GL_RGB;
1820 object->texture_bpp = 3;
1821 object->texture_format = GL_RGB;
1822 object->texture_type = GL_UNSIGNED_BYTE;
1824 case WGL_TEXTURE_RGBA_ARB:
1825 object->use_render_texture = GL_RGBA;
1826 object->texture_bpp = 4;
1827 object->texture_format = GL_RGBA;
1828 object->texture_type = GL_UNSIGNED_BYTE;
1831 /* WGL_FLOAT_COMPONENTS_NV */
1832 case WGL_TEXTURE_FLOAT_R_NV:
1833 object->use_render_texture = GL_FLOAT_R_NV;
1834 object->texture_bpp = 4;
1835 object->texture_format = GL_RED;
1836 object->texture_type = GL_FLOAT;
1838 case WGL_TEXTURE_FLOAT_RG_NV:
1839 object->use_render_texture = GL_FLOAT_RG_NV;
1840 object->texture_bpp = 8;
1841 object->texture_format = GL_LUMINANCE_ALPHA;
1842 object->texture_type = GL_FLOAT;
1844 case WGL_TEXTURE_FLOAT_RGB_NV:
1845 object->use_render_texture = GL_FLOAT_RGB_NV;
1846 object->texture_bpp = 12;
1847 object->texture_format = GL_RGB;
1848 object->texture_type = GL_FLOAT;
1850 case WGL_TEXTURE_FLOAT_RGBA_NV:
1851 object->use_render_texture = GL_FLOAT_RGBA_NV;
1852 object->texture_bpp = 16;
1853 object->texture_format = GL_RGBA;
1854 object->texture_type = GL_FLOAT;
1857 ERR("Unknown texture format: %x\n", attr_v);
1858 SetLastError(ERROR_INVALID_DATA);
1865 case WGL_TEXTURE_TARGET_ARB: {
1867 attr_v = *piAttribList;
1868 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
1869 if (WGL_NO_TEXTURE_ARB == attr_v) {
1870 object->texture_target = 0;
1872 if (!use_render_texture_emulation) {
1873 SetLastError(ERROR_INVALID_DATA);
1877 case WGL_TEXTURE_CUBE_MAP_ARB: {
1878 if (iWidth != iHeight) {
1879 SetLastError(ERROR_INVALID_DATA);
1882 object->texture_target = GL_TEXTURE_CUBE_MAP;
1883 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
1886 case WGL_TEXTURE_1D_ARB: {
1888 SetLastError(ERROR_INVALID_DATA);
1891 object->texture_target = GL_TEXTURE_1D;
1892 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
1895 case WGL_TEXTURE_2D_ARB: {
1896 object->texture_target = GL_TEXTURE_2D;
1897 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
1900 case WGL_TEXTURE_RECTANGLE_NV: {
1901 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
1902 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
1906 ERR("Unknown texture target: %x\n", attr_v);
1907 SetLastError(ERROR_INVALID_DATA);
1914 case WGL_MIPMAP_TEXTURE_ARB: {
1916 attr_v = *piAttribList;
1917 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
1918 if (!use_render_texture_emulation) {
1919 SetLastError(ERROR_INVALID_DATA);
1928 PUSH1(attribs, None);
1929 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
1930 TRACE("new Pbuffer drawable as %lx\n", object->drawable);
1931 if (!object->drawable) {
1932 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
1933 goto create_failed; /* unexpected error */
1935 TRACE("->(%p)\n", object);
1939 HeapFree(GetProcessHeap(), 0, object);
1940 TRACE("->(FAILED)\n");
1945 * X11DRV_wglDestroyPbufferARB
1947 * WGL_ARB_pbuffer: wglDestroyPbufferARB
1949 static BOOL X11DRV_wglDestroyPbufferARB( struct wgl_pbuffer *object )
1951 TRACE("(%p)\n", object);
1953 pglXDestroyPbuffer(gdi_display, object->drawable);
1954 HeapFree(GetProcessHeap(), 0, object);
1959 * X11DRV_wglGetPbufferDCARB
1961 * WGL_ARB_pbuffer: wglGetPbufferDCARB
1963 static HDC X11DRV_wglGetPbufferDCARB( struct wgl_pbuffer *object )
1965 struct x11drv_escape_set_drawable escape;
1968 hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
1971 escape.code = X11DRV_SET_DRAWABLE;
1972 escape.drawable = object->drawable;
1973 escape.mode = IncludeInferiors;
1974 SetRect( &escape.dc_rect, 0, 0, object->width, object->height );
1975 escape.fbconfig_id = object->fmt->fmt_id;
1976 escape.gl_drawable = object->drawable;
1978 escape.gl_type = DC_GL_PBUFFER;
1979 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1981 TRACE( "(%p)->(%p)\n", object, hdc );
1986 * X11DRV_wglQueryPbufferARB
1988 * WGL_ARB_pbuffer: wglQueryPbufferARB
1990 static BOOL X11DRV_wglQueryPbufferARB( struct wgl_pbuffer *object, int iAttribute, int *piValue )
1992 TRACE("(%p, 0x%x, %p)\n", object, iAttribute, piValue);
1994 switch (iAttribute) {
1995 case WGL_PBUFFER_WIDTH_ARB:
1996 pglXQueryDrawable(gdi_display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
1998 case WGL_PBUFFER_HEIGHT_ARB:
1999 pglXQueryDrawable(gdi_display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2002 case WGL_PBUFFER_LOST_ARB:
2003 /* GLX Pbuffers cannot be lost by default. We can support this by
2004 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2005 * to receive pixel buffer clobber events, however that may or may
2006 * not give any benefit */
2007 *piValue = GL_FALSE;
2010 case WGL_TEXTURE_FORMAT_ARB:
2011 if (!object->use_render_texture) {
2012 *piValue = WGL_NO_TEXTURE_ARB;
2014 if (!use_render_texture_emulation) {
2015 SetLastError(ERROR_INVALID_HANDLE);
2018 switch(object->use_render_texture) {
2020 *piValue = WGL_TEXTURE_RGB_ARB;
2023 *piValue = WGL_TEXTURE_RGBA_ARB;
2025 /* WGL_FLOAT_COMPONENTS_NV */
2027 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2029 case GL_FLOAT_RG_NV:
2030 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2032 case GL_FLOAT_RGB_NV:
2033 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2035 case GL_FLOAT_RGBA_NV:
2036 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2039 ERR("Unknown texture format: %x\n", object->use_render_texture);
2044 case WGL_TEXTURE_TARGET_ARB:
2045 if (!object->texture_target){
2046 *piValue = WGL_NO_TEXTURE_ARB;
2048 if (!use_render_texture_emulation) {
2049 SetLastError(ERROR_INVALID_DATA);
2052 switch (object->texture_target) {
2053 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2054 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2055 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2056 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2061 case WGL_MIPMAP_TEXTURE_ARB:
2062 *piValue = GL_FALSE; /** don't support that */
2063 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2067 FIXME("unexpected attribute %x\n", iAttribute);
2075 * X11DRV_wglReleasePbufferDCARB
2077 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2079 static int X11DRV_wglReleasePbufferDCARB( struct wgl_pbuffer *object, HDC hdc )
2081 TRACE("(%p, %p)\n", object, hdc);
2082 return DeleteDC(hdc);
2086 * X11DRV_wglSetPbufferAttribARB
2088 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2090 static BOOL X11DRV_wglSetPbufferAttribARB( struct wgl_pbuffer *object, const int *piAttribList )
2092 GLboolean ret = GL_FALSE;
2094 WARN("(%p, %p): alpha-testing, report any problem\n", object, piAttribList);
2096 if (!object->use_render_texture) {
2097 SetLastError(ERROR_INVALID_HANDLE);
2100 if (1 == use_render_texture_emulation) {
2107 * X11DRV_wglChoosePixelFormatARB
2109 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2111 static BOOL X11DRV_wglChoosePixelFormatARB( HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList,
2112 UINT nMaxFormats, int *piFormats, UINT *nNumFormats )
2116 GLXFBConfig* cfgs = NULL;
2126 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2127 if (NULL != pfAttribFList) {
2128 FIXME("unused pfAttribFList\n");
2131 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2132 if (-1 == nAttribs) {
2133 WARN("Cannot convert WGL to GLX attributes\n");
2136 PUSH1(attribs, None);
2138 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2139 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the pixel format. We don't query these attributes
2140 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on.
2142 for(i=0; piAttribIList[i] != 0; i+=2)
2144 switch(piAttribIList[i])
2146 case WGL_DRAW_TO_BITMAP_ARB:
2147 if(piAttribIList[i+1])
2148 dwFlags |= PFD_DRAW_TO_BITMAP;
2150 case WGL_ACCELERATION_ARB:
2151 switch(piAttribIList[i+1])
2153 case WGL_NO_ACCELERATION_ARB:
2154 dwFlags |= PFD_GENERIC_FORMAT;
2156 case WGL_GENERIC_ACCELERATION_ARB:
2157 dwFlags |= PFD_GENERIC_ACCELERATED;
2159 case WGL_FULL_ACCELERATION_ARB:
2164 case WGL_SUPPORT_GDI_ARB:
2165 if(piAttribIList[i+1])
2166 dwFlags |= PFD_SUPPORT_GDI;
2171 /* Search for FB configurations matching the requirements in attribs */
2172 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2174 WARN("Compatible Pixel Format not found\n");
2178 /* Loop through all matching formats and check if they are suitable.
2179 * Note that this function should at max return nMaxFormats different formats */
2180 for(run=0; run < 2; run++)
2182 for (it = 0; it < nCfgs && pfmt_it < nMaxFormats; ++it)
2184 if (pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id))
2186 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2190 /* During the first run we only want onscreen formats and during the second only offscreen */
2191 start = run == 1 ? nb_onscreen_formats : 0;
2192 end = run == 1 ? nb_pixel_formats : nb_onscreen_formats;
2194 for (i = start; i < end; i++)
2196 if (pixel_formats[i].fmt_id == fmt_id && (pixel_formats[i].dwFlags & dwFlags) == dwFlags)
2198 piFormats[pfmt_it++] = i + 1;
2199 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n",
2200 it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2207 *nNumFormats = pfmt_it;
2214 * X11DRV_wglGetPixelFormatAttribivARB
2216 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2218 static BOOL X11DRV_wglGetPixelFormatAttribivARB( HDC hdc, int iPixelFormat, int iLayerPlane,
2219 UINT nAttributes, const int *piAttributes, int *piValues )
2222 const struct wgl_pixel_format *fmt = NULL;
2227 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2229 if (0 < iLayerPlane) {
2230 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2234 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2235 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2236 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2237 fmt = get_pixel_format(gdi_display, iPixelFormat, TRUE /* Offscreen */);
2239 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2242 for (i = 0; i < nAttributes; ++i) {
2243 const int curWGLAttr = piAttributes[i];
2244 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2246 switch (curWGLAttr) {
2247 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2248 piValues[i] = nb_pixel_formats;
2251 case WGL_SUPPORT_OPENGL_ARB:
2252 piValues[i] = GL_TRUE;
2255 case WGL_ACCELERATION_ARB:
2256 curGLXAttr = GLX_CONFIG_CAVEAT;
2257 if (!fmt) goto pix_error;
2258 if(fmt->dwFlags & PFD_GENERIC_FORMAT)
2259 piValues[i] = WGL_NO_ACCELERATION_ARB;
2260 else if(fmt->dwFlags & PFD_GENERIC_ACCELERATED)
2261 piValues[i] = WGL_GENERIC_ACCELERATION_ARB;
2263 piValues[i] = WGL_FULL_ACCELERATION_ARB;
2266 case WGL_TRANSPARENT_ARB:
2267 curGLXAttr = GLX_TRANSPARENT_TYPE;
2268 if (!fmt) goto pix_error;
2269 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2270 if (hTest) goto get_error;
2271 piValues[i] = GL_FALSE;
2272 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2275 case WGL_PIXEL_TYPE_ARB:
2276 curGLXAttr = GLX_RENDER_TYPE;
2277 if (!fmt) goto pix_error;
2278 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2279 if (hTest) goto get_error;
2280 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2281 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2282 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2283 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2284 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2285 else if (tmp & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) { piValues[i] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT; }
2287 ERR("unexpected RenderType(%x)\n", tmp);
2288 piValues[i] = WGL_TYPE_RGBA_ARB;
2292 case WGL_COLOR_BITS_ARB:
2293 curGLXAttr = GLX_BUFFER_SIZE;
2296 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2297 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2298 if (!use_render_texture_emulation) {
2299 piValues[i] = GL_FALSE;
2302 curGLXAttr = GLX_RENDER_TYPE;
2303 if (!fmt) goto pix_error;
2304 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2305 if (hTest) goto get_error;
2306 if (GLX_COLOR_INDEX_BIT == tmp) {
2307 piValues[i] = GL_FALSE;
2310 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2311 if (hTest) goto get_error;
2312 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2315 case WGL_BLUE_BITS_ARB:
2316 curGLXAttr = GLX_BLUE_SIZE;
2318 case WGL_RED_BITS_ARB:
2319 curGLXAttr = GLX_RED_SIZE;
2321 case WGL_GREEN_BITS_ARB:
2322 curGLXAttr = GLX_GREEN_SIZE;
2324 case WGL_ALPHA_BITS_ARB:
2325 curGLXAttr = GLX_ALPHA_SIZE;
2327 case WGL_DEPTH_BITS_ARB:
2328 curGLXAttr = GLX_DEPTH_SIZE;
2330 case WGL_STENCIL_BITS_ARB:
2331 curGLXAttr = GLX_STENCIL_SIZE;
2333 case WGL_DOUBLE_BUFFER_ARB:
2334 curGLXAttr = GLX_DOUBLEBUFFER;
2336 case WGL_STEREO_ARB:
2337 curGLXAttr = GLX_STEREO;
2339 case WGL_AUX_BUFFERS_ARB:
2340 curGLXAttr = GLX_AUX_BUFFERS;
2343 case WGL_SUPPORT_GDI_ARB:
2344 if (!fmt) goto pix_error;
2345 piValues[i] = (fmt->dwFlags & PFD_SUPPORT_GDI) != 0;
2348 case WGL_DRAW_TO_BITMAP_ARB:
2349 if (!fmt) goto pix_error;
2350 piValues[i] = (fmt->dwFlags & PFD_DRAW_TO_BITMAP) != 0;
2353 case WGL_DRAW_TO_WINDOW_ARB:
2354 case WGL_DRAW_TO_PBUFFER_ARB:
2355 if (!fmt) goto pix_error;
2356 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2357 if (hTest) goto get_error;
2358 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2359 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2360 piValues[i] = GL_TRUE;
2362 piValues[i] = GL_FALSE;
2365 case WGL_SWAP_METHOD_ARB:
2366 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
2367 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
2368 * point only ATI offers this.
2370 piValues[i] = WGL_SWAP_EXCHANGE_ARB;
2373 case WGL_PBUFFER_LARGEST_ARB:
2374 curGLXAttr = GLX_LARGEST_PBUFFER;
2377 case WGL_SAMPLE_BUFFERS_ARB:
2378 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2381 case WGL_SAMPLES_ARB:
2382 curGLXAttr = GLX_SAMPLES_ARB;
2385 case WGL_FLOAT_COMPONENTS_NV:
2386 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2389 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
2390 curGLXAttr = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT;
2393 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
2394 curGLXAttr = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
2397 case WGL_ACCUM_RED_BITS_ARB:
2398 curGLXAttr = GLX_ACCUM_RED_SIZE;
2400 case WGL_ACCUM_GREEN_BITS_ARB:
2401 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2403 case WGL_ACCUM_BLUE_BITS_ARB:
2404 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2406 case WGL_ACCUM_ALPHA_BITS_ARB:
2407 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2409 case WGL_ACCUM_BITS_ARB:
2410 if (!fmt) goto pix_error;
2411 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2412 if (hTest) goto get_error;
2414 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2415 if (hTest) goto get_error;
2417 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2418 if (hTest) goto get_error;
2420 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2421 if (hTest) goto get_error;
2426 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2429 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2430 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2431 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2433 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2434 * and check which options can work using iPixelFormat=0 and which not.
2435 * A problem would be that this function is an extension. This would
2436 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2438 if (0 != curGLXAttr && iPixelFormat != 0) {
2439 if (!fmt) goto pix_error;
2440 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2441 if (hTest) goto get_error;
2444 piValues[i] = GL_FALSE;
2450 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2454 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nb_pixel_formats);
2459 * X11DRV_wglGetPixelFormatAttribfvARB
2461 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2463 static BOOL X11DRV_wglGetPixelFormatAttribfvARB( HDC hdc, int iPixelFormat, int iLayerPlane,
2464 UINT nAttributes, const int *piAttributes, FLOAT *pfValues )
2470 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2472 /* Allocate a temporary array to store integer values */
2473 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2475 ERR("couldn't allocate %d array\n", nAttributes);
2479 /* Piggy-back on wglGetPixelFormatAttribivARB */
2480 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2482 /* Convert integer values to float. Should also check for attributes
2483 that can give decimal values here */
2484 for (i=0; i<nAttributes;i++) {
2485 pfValues[i] = attr[i];
2489 HeapFree(GetProcessHeap(), 0, attr);
2494 * X11DRV_wglBindTexImageARB
2496 * WGL_ARB_render_texture: wglBindTexImageARB
2498 static BOOL X11DRV_wglBindTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2500 GLboolean ret = GL_FALSE;
2502 TRACE("(%p, %d)\n", object, iBuffer);
2504 if (!object->use_render_texture) {
2505 SetLastError(ERROR_INVALID_HANDLE);
2509 if (1 == use_render_texture_emulation) {
2510 static int init = 0;
2511 int prev_binded_texture = 0;
2512 GLXContext prev_context;
2513 Drawable prev_drawable;
2514 GLXContext tmp_context;
2516 prev_context = pglXGetCurrentContext();
2517 prev_drawable = pglXGetCurrentDrawable();
2519 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2520 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2521 isn't ideal performance wise but I wasn't able to get other ways working.
2524 init = 1; /* Only show the FIXME once for performance reasons */
2525 FIXME("partial stub!\n");
2528 TRACE("drawable=%lx, context=%p\n", object->drawable, prev_context);
2529 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2531 opengl_funcs.gl.p_glGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2533 /* Switch to our pbuffer */
2534 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
2536 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2537 * After that upload the pbuffer texture data. */
2538 opengl_funcs.gl.p_glBindTexture(object->texture_target, prev_binded_texture);
2539 opengl_funcs.gl.p_glCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2541 /* Switch back to the original drawable and upload the pbuffer-texture */
2542 pglXMakeCurrent(gdi_display, prev_drawable, prev_context);
2543 pglXDestroyContext(gdi_display, tmp_context);
2551 * X11DRV_wglReleaseTexImageARB
2553 * WGL_ARB_render_texture: wglReleaseTexImageARB
2555 static BOOL X11DRV_wglReleaseTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2557 GLboolean ret = GL_FALSE;
2559 TRACE("(%p, %d)\n", object, iBuffer);
2561 if (!object->use_render_texture) {
2562 SetLastError(ERROR_INVALID_HANDLE);
2565 if (1 == use_render_texture_emulation) {
2572 * X11DRV_wglGetExtensionsStringEXT
2574 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2576 static const GLubyte *X11DRV_wglGetExtensionsStringEXT(void)
2578 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2579 return (const GLubyte *)WineGLInfo.wglExtensions;
2583 * X11DRV_wglGetSwapIntervalEXT
2585 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2587 static int X11DRV_wglGetSwapIntervalEXT(void)
2589 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
2590 * interval, so the swap interval has to be tracked. */
2592 return swap_interval;
2596 * X11DRV_wglSwapIntervalEXT
2598 * WGL_EXT_swap_control: wglSwapIntervalEXT
2600 static BOOL X11DRV_wglSwapIntervalEXT(int interval)
2604 TRACE("(%d)\n", interval);
2608 SetLastError(ERROR_INVALID_DATA);
2611 else if (!has_swap_control && interval == 0)
2613 /* wglSwapIntervalEXT considers an interval value of zero to mean that
2614 * vsync should be disabled, but glXSwapIntervalSGI considers such a
2615 * value to be an error. Just silently ignore the request for now. */
2616 WARN("Request to disable vertical sync is not handled\n");
2621 if (pglXSwapIntervalSGI)
2622 ret = !pglXSwapIntervalSGI(interval);
2624 WARN("GLX_SGI_swap_control extension is not available\n");
2627 swap_interval = interval;
2629 SetLastError(ERROR_DC_NOT_FOUND);
2636 * X11DRV_wglSetPixelFormatWINE
2638 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
2639 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
2641 static BOOL X11DRV_wglSetPixelFormatWINE(HDC hdc, int format)
2643 const struct wgl_pixel_format *fmt;
2647 TRACE("(%p,%d)\n", hdc, format);
2649 fmt = get_pixel_format(gdi_display, format, FALSE /* Offscreen */);
2652 ERR( "Invalid format %d\n", format );
2656 hwnd = WindowFromDC( hdc );
2657 if (!hwnd || hwnd == GetDesktopWindow())
2659 ERR( "not a valid window DC %p\n", hdc );
2663 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
2664 if (!(value & GLX_WINDOW_BIT))
2666 WARN( "Pixel format %d is not compatible for window rendering\n", format );
2670 return SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, fmt->fmt_id, 0);
2671 /* DC pixel format will be set by the DCE update */
2675 * glxRequireVersion (internal)
2677 * Check if the supported GLX version matches requiredVersion.
2679 static BOOL glxRequireVersion(int requiredVersion)
2681 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2682 if(requiredVersion <= WineGLInfo.glxVersion[1])
2688 static void register_extension(const char *ext)
2690 if (WineGLInfo.wglExtensions[0])
2691 strcat(WineGLInfo.wglExtensions, " ");
2692 strcat(WineGLInfo.wglExtensions, ext);
2694 TRACE("'%s'\n", ext);
2698 * X11DRV_WineGL_LoadExtensions
2700 static void X11DRV_WineGL_LoadExtensions(void)
2702 WineGLInfo.wglExtensions[0] = 0;
2704 /* ARB Extensions */
2706 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_create_context"))
2708 register_extension( "WGL_ARB_create_context" );
2709 opengl_funcs.ext.p_wglCreateContextAttribsARB = X11DRV_wglCreateContextAttribsARB;
2711 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_create_context_profile"))
2712 register_extension("WGL_ARB_create_context_profile");
2715 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_fbconfig_float"))
2717 register_extension("WGL_ARB_pixel_format_float");
2718 register_extension("WGL_ATI_pixel_format_float");
2721 register_extension( "WGL_ARB_extensions_string" );
2722 opengl_funcs.ext.p_wglGetExtensionsStringARB = X11DRV_wglGetExtensionsStringARB;
2724 if (glxRequireVersion(3))
2726 register_extension( "WGL_ARB_make_current_read" );
2727 opengl_funcs.ext.p_wglGetCurrentReadDCARB = (void *)1; /* never called */
2728 opengl_funcs.ext.p_wglMakeContextCurrentARB = X11DRV_wglMakeContextCurrentARB;
2731 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_multisample")) register_extension( "WGL_ARB_multisample" );
2733 /* In general pbuffer functionality requires support in the X-server. The functionality is
2734 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
2736 if ( glxRequireVersion(3) && has_extension( WineGLInfo.glxExtensions, "GLX_SGIX_pbuffer") )
2738 register_extension( "WGL_ARB_pbuffer" );
2739 opengl_funcs.ext.p_wglCreatePbufferARB = X11DRV_wglCreatePbufferARB;
2740 opengl_funcs.ext.p_wglDestroyPbufferARB = X11DRV_wglDestroyPbufferARB;
2741 opengl_funcs.ext.p_wglGetPbufferDCARB = X11DRV_wglGetPbufferDCARB;
2742 opengl_funcs.ext.p_wglQueryPbufferARB = X11DRV_wglQueryPbufferARB;
2743 opengl_funcs.ext.p_wglReleasePbufferDCARB = X11DRV_wglReleasePbufferDCARB;
2744 opengl_funcs.ext.p_wglSetPbufferAttribARB = X11DRV_wglSetPbufferAttribARB;
2747 register_extension( "WGL_ARB_pixel_format" );
2748 opengl_funcs.ext.p_wglChoosePixelFormatARB = X11DRV_wglChoosePixelFormatARB;
2749 opengl_funcs.ext.p_wglGetPixelFormatAttribfvARB = X11DRV_wglGetPixelFormatAttribfvARB;
2750 opengl_funcs.ext.p_wglGetPixelFormatAttribivARB = X11DRV_wglGetPixelFormatAttribivARB;
2752 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
2753 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_render_texture") ||
2754 (glxRequireVersion(3) && has_extension( WineGLInfo.glxExtensions, "GLX_SGIX_pbuffer") && use_render_texture_emulation))
2756 register_extension( "WGL_ARB_render_texture" );
2757 opengl_funcs.ext.p_wglBindTexImageARB = X11DRV_wglBindTexImageARB;
2758 opengl_funcs.ext.p_wglReleaseTexImageARB = X11DRV_wglReleaseTexImageARB;
2760 /* The WGL version of GLX_NV_float_buffer requires render_texture */
2761 if (has_extension( WineGLInfo.glxExtensions, "GLX_NV_float_buffer"))
2762 register_extension("WGL_NV_float_buffer");
2764 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
2765 if (has_extension(WineGLInfo.glExtensions, "GL_NV_texture_rectangle"))
2766 register_extension("WGL_NV_texture_rectangle");
2769 /* EXT Extensions */
2771 register_extension( "WGL_EXT_extensions_string" );
2772 opengl_funcs.ext.p_wglGetExtensionsStringEXT = X11DRV_wglGetExtensionsStringEXT;
2774 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
2775 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
2776 register_extension( "WGL_EXT_swap_control" );
2777 opengl_funcs.ext.p_wglSwapIntervalEXT = X11DRV_wglSwapIntervalEXT;
2778 opengl_funcs.ext.p_wglGetSwapIntervalEXT = X11DRV_wglGetSwapIntervalEXT;
2780 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_framebuffer_sRGB"))
2781 register_extension("WGL_EXT_framebuffer_sRGB");
2783 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_fbconfig_packed_float"))
2784 register_extension("WGL_EXT_pixel_format_packed_float");
2786 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_swap_control"))
2787 has_swap_control = TRUE;
2789 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
2790 if (has_extension(WineGLInfo.glExtensions, "GL_NV_vertex_array_range"))
2792 register_extension( "WGL_NV_vertex_array_range" );
2793 opengl_funcs.ext.p_wglAllocateMemoryNV = pglXAllocateMemoryNV;
2794 opengl_funcs.ext.p_wglFreeMemoryNV = pglXFreeMemoryNV;
2797 /* WINE-specific WGL Extensions */
2799 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
2800 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
2802 register_extension( "WGL_WINE_pixel_format_passthrough" );
2803 opengl_funcs.ext.p_wglSetPixelFormatWINE = X11DRV_wglSetPixelFormatWINE;
2807 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
2809 pglXDestroyGLXPixmap(display, glxpixmap);
2814 * glxdrv_SwapBuffers
2816 * Swap the buffers of this DC
2818 static BOOL glxdrv_SwapBuffers(PHYSDEV dev)
2820 struct glx_physdev *physdev = get_glxdrv_dev( dev );
2821 struct wgl_context *ctx = NtCurrentTeb()->glContext;
2823 TRACE("(%p)\n", dev->hdc);
2827 WARN("Using a NULL context, skipping\n");
2828 SetLastError(ERROR_INVALID_HANDLE);
2832 if (!physdev->drawable)
2834 WARN("Using an invalid drawable, skipping\n");
2835 SetLastError(ERROR_INVALID_HANDLE);
2840 switch (physdev->type)
2842 case DC_GL_PIXMAP_WIN:
2843 if(pglXCopySubBufferMESA) {
2844 int w = physdev->x11dev->dc_rect.right - physdev->x11dev->dc_rect.left;
2845 int h = physdev->x11dev->dc_rect.bottom - physdev->x11dev->dc_rect.top;
2847 /* (glX)SwapBuffers has an implicit glFlush effect, however
2848 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
2852 pglXCopySubBufferMESA(gdi_display, physdev->drawable, 0, 0, w, h);
2857 pglXSwapBuffers(gdi_display, physdev->drawable);
2861 flush_gl_drawable( physdev );
2866 static long prev_time, start_time;
2867 static unsigned long frames, frames_total;
2869 DWORD time = GetTickCount();
2872 /* every 1.5 seconds */
2873 if (time - prev_time > 1500) {
2874 TRACE_(fps)("@ approx %.2ffps, total %.2ffps\n",
2875 1000.0*frames/(time - prev_time), 1000.0*frames_total/(time - start_time));
2878 if(start_time == 0) start_time = time;
2885 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
2887 int format = pixelformat_from_fbconfig_id( fbconfig_id );
2889 if (!format) return NULL;
2890 return pglXGetVisualFromFBConfig(gdi_display, pixel_formats[format - 1].fbconfig);
2893 static BOOL create_glx_dc( PHYSDEV *pdev )
2895 /* assume that only the main x11 device implements GetDeviceCaps */
2896 X11DRV_PDEVICE *x11dev = get_x11drv_dev( GET_NEXT_PHYSDEV( *pdev, pGetDeviceCaps ));
2897 struct glx_physdev *physdev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physdev) );
2899 if (!physdev) return FALSE;
2900 physdev->x11dev = x11dev;
2901 push_dc_driver( pdev, &physdev->dev, &glxdrv_funcs );
2905 /**********************************************************************
2908 static BOOL glxdrv_CreateDC( PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device,
2909 LPCWSTR output, const DEVMODEW* initData )
2911 return create_glx_dc( pdev );
2914 /**********************************************************************
2915 * glxdrv_CreateCompatibleDC
2917 static BOOL glxdrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
2919 if (orig) /* chain to next driver first */
2921 orig = GET_NEXT_PHYSDEV( orig, pCreateCompatibleDC );
2922 if (!orig->funcs->pCreateCompatibleDC( orig, pdev )) return FALSE;
2924 /* otherwise we have been called by x11drv */
2925 return create_glx_dc( pdev );
2928 /**********************************************************************
2931 static BOOL glxdrv_DeleteDC( PHYSDEV dev )
2933 struct glx_physdev *physdev = get_glxdrv_dev( dev );
2934 HeapFree( GetProcessHeap(), 0, physdev );
2938 /**********************************************************************
2941 static INT glxdrv_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
2942 INT out_count, LPVOID out_data )
2944 struct glx_physdev *physdev = get_glxdrv_dev( dev );
2946 dev = GET_NEXT_PHYSDEV( dev, pExtEscape );
2948 if (escape == X11DRV_ESCAPE && in_data && in_count >= sizeof(enum x11drv_escape_codes))
2950 switch (*(const enum x11drv_escape_codes *)in_data)
2952 case X11DRV_SET_DRAWABLE:
2953 if (in_count >= sizeof(struct x11drv_escape_set_drawable))
2955 const struct x11drv_escape_set_drawable *data = in_data;
2956 physdev->pixel_format = pixelformat_from_fbconfig_id( data->fbconfig_id );
2957 physdev->type = data->gl_type;
2958 physdev->drawable = data->gl_drawable;
2959 physdev->pixmap = data->pixmap;
2960 TRACE( "SET_DRAWABLE hdc %p drawable %lx pf %u type %u\n",
2961 dev->hdc, physdev->drawable, physdev->pixel_format, physdev->type );
2964 case X11DRV_GET_DRAWABLE:
2965 if (out_count >= sizeof(struct x11drv_escape_get_drawable))
2967 struct x11drv_escape_get_drawable *data = out_data;
2968 data->pixel_format = physdev->pixel_format;
2969 data->gl_type = physdev->type;
2970 data->gl_drawable = physdev->drawable;
2971 data->pixmap = physdev->pixmap;
2974 case X11DRV_FLUSH_GL_DRAWABLE:
2975 flush_gl_drawable( physdev );
2981 return dev->funcs->pExtEscape( dev, escape, in_count, in_data, out_count, out_data );
2984 /**********************************************************************
2985 * glxdrv_wine_get_wgl_driver
2987 static struct opengl_funcs * glxdrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
2989 if (version != WINE_WGL_DRIVER_VERSION)
2991 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_WGL_DRIVER_VERSION );
2995 if (has_opengl()) return &opengl_funcs;
2997 dev = GET_NEXT_PHYSDEV( dev, wine_get_wgl_driver );
2998 return dev->funcs->wine_get_wgl_driver( dev, version );
3001 static const struct gdi_dc_funcs glxdrv_funcs =
3003 NULL, /* pAbortDoc */
3004 NULL, /* pAbortPath */
3005 NULL, /* pAlphaBlend */
3006 NULL, /* pAngleArc */
3009 NULL, /* pBeginPath */
3010 NULL, /* pBlendImage */
3012 NULL, /* pCloseFigure */
3013 glxdrv_CreateCompatibleDC, /* pCreateCompatibleDC */
3014 glxdrv_CreateDC, /* pCreateDC */
3015 glxdrv_DeleteDC, /* pDeleteDC */
3016 NULL, /* pDeleteObject */
3017 NULL, /* pDeviceCapabilities */
3018 NULL, /* pEllipse */
3020 NULL, /* pEndPage */
3021 NULL, /* pEndPath */
3022 NULL, /* pEnumFonts */
3023 NULL, /* pEnumICMProfiles */
3024 NULL, /* pExcludeClipRect */
3025 NULL, /* pExtDeviceMode */
3026 glxdrv_ExtEscape, /* pExtEscape */
3027 NULL, /* pExtFloodFill */
3028 NULL, /* pExtSelectClipRgn */
3029 NULL, /* pExtTextOut */
3030 NULL, /* pFillPath */
3031 NULL, /* pFillRgn */
3032 NULL, /* pFlattenPath */
3033 NULL, /* pFontIsLinked */
3034 NULL, /* pFrameRgn */
3035 NULL, /* pGdiComment */
3036 NULL, /* pGdiRealizationInfo */
3037 NULL, /* pGetBoundsRect */
3038 NULL, /* pGetCharABCWidths */
3039 NULL, /* pGetCharABCWidthsI */
3040 NULL, /* pGetCharWidth */
3041 NULL, /* pGetDeviceCaps */
3042 NULL, /* pGetDeviceGammaRamp */
3043 NULL, /* pGetFontData */
3044 NULL, /* pGetFontUnicodeRanges */
3045 NULL, /* pGetGlyphIndices */
3046 NULL, /* pGetGlyphOutline */
3047 NULL, /* pGetICMProfile */
3048 NULL, /* pGetImage */
3049 NULL, /* pGetKerningPairs */
3050 NULL, /* pGetNearestColor */
3051 NULL, /* pGetOutlineTextMetrics */
3052 NULL, /* pGetPixel */
3053 NULL, /* pGetSystemPaletteEntries */
3054 NULL, /* pGetTextCharsetInfo */
3055 NULL, /* pGetTextExtentExPoint */
3056 NULL, /* pGetTextExtentExPointI */
3057 NULL, /* pGetTextFace */
3058 NULL, /* pGetTextMetrics */
3059 NULL, /* pGradientFill */
3060 NULL, /* pIntersectClipRect */
3061 NULL, /* pInvertRgn */
3063 NULL, /* pModifyWorldTransform */
3065 NULL, /* pOffsetClipRgn */
3066 NULL, /* pOffsetViewportOrg */
3067 NULL, /* pOffsetWindowOrg */
3068 NULL, /* pPaintRgn */
3071 NULL, /* pPolyBezier */
3072 NULL, /* pPolyBezierTo */
3073 NULL, /* pPolyDraw */
3074 NULL, /* pPolyPolygon */
3075 NULL, /* pPolyPolyline */
3076 NULL, /* pPolygon */
3077 NULL, /* pPolyline */
3078 NULL, /* pPolylineTo */
3079 NULL, /* pPutImage */
3080 NULL, /* pRealizeDefaultPalette */
3081 NULL, /* pRealizePalette */
3082 NULL, /* pRectangle */
3083 NULL, /* pResetDC */
3084 NULL, /* pRestoreDC */
3085 NULL, /* pRoundRect */
3087 NULL, /* pScaleViewportExt */
3088 NULL, /* pScaleWindowExt */
3089 NULL, /* pSelectBitmap */
3090 NULL, /* pSelectBrush */
3091 NULL, /* pSelectClipPath */
3092 NULL, /* pSelectFont */
3093 NULL, /* pSelectPalette */
3094 NULL, /* pSelectPen */
3095 NULL, /* pSetArcDirection */
3096 NULL, /* pSetBkColor */
3097 NULL, /* pSetBkMode */
3098 NULL, /* pSetBoundsRect */
3099 NULL, /* pSetDCBrushColor */
3100 NULL, /* pSetDCPenColor */
3101 NULL, /* pSetDIBitsToDevice */
3102 NULL, /* pSetDeviceClipping */
3103 NULL, /* pSetDeviceGammaRamp */
3104 NULL, /* pSetLayout */
3105 NULL, /* pSetMapMode */
3106 NULL, /* pSetMapperFlags */
3107 NULL, /* pSetPixel */
3108 NULL, /* pSetPolyFillMode */
3109 NULL, /* pSetROP2 */
3110 NULL, /* pSetRelAbs */
3111 NULL, /* pSetStretchBltMode */
3112 NULL, /* pSetTextAlign */
3113 NULL, /* pSetTextCharacterExtra */
3114 NULL, /* pSetTextColor */
3115 NULL, /* pSetTextJustification */
3116 NULL, /* pSetViewportExt */
3117 NULL, /* pSetViewportOrg */
3118 NULL, /* pSetWindowExt */
3119 NULL, /* pSetWindowOrg */
3120 NULL, /* pSetWorldTransform */
3121 NULL, /* pStartDoc */
3122 NULL, /* pStartPage */
3123 NULL, /* pStretchBlt */
3124 NULL, /* pStretchDIBits */
3125 NULL, /* pStrokeAndFillPath */
3126 NULL, /* pStrokePath */
3127 glxdrv_SwapBuffers, /* pSwapBuffers */
3128 NULL, /* pUnrealizePalette */
3129 NULL, /* pWidenPath */
3130 glxdrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
3131 GDI_PRIORITY_GRAPHICS_DRV + 20 /* priority */
3134 static struct opengl_funcs opengl_funcs =
3137 glxdrv_wglCopyContext, /* p_wglCopyContext */
3138 glxdrv_wglCreateContext, /* p_wglCreateContext */
3139 glxdrv_wglDeleteContext, /* p_wglDeleteContext */
3140 glxdrv_wglDescribePixelFormat, /* p_wglDescribePixelFormat */
3141 glxdrv_wglGetPixelFormat, /* p_wglGetPixelFormat */
3142 glxdrv_wglGetProcAddress, /* p_wglGetProcAddress */
3143 glxdrv_wglMakeCurrent, /* p_wglMakeCurrent */
3144 glxdrv_wglSetPixelFormat, /* p_wglSetPixelFormat */
3145 glxdrv_wglShareLists, /* p_wglShareLists */
3149 const struct gdi_dc_funcs *get_glx_driver(void)
3151 return &glxdrv_funcs;
3154 #else /* no OpenGL includes */
3156 const struct gdi_dc_funcs *get_glx_driver(void)
3161 void mark_drawable_dirty(Drawable old, Drawable new)
3165 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
3171 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3176 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3181 #endif /* defined(SONAME_LIBGL) */