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 typedef struct wine_glpixelformat {
136 GLXFBConfig fbconfig;
140 DWORD dwFlags; /* We store some PFD_* flags in here for emulated bitmap formats */
146 BOOL has_been_current;
150 WineGLPixelFormat *fmt;
151 int numAttribs; /* This is needed for delaying wglCreateContextAttribsARB */
152 int attribList[16]; /* This is needed for delaying wglCreateContextAttribsARB */
155 Drawable drawables[2];
156 BOOL refresh_drawables;
157 Pixmap pixmap; /* pixmap for memory DCs */
158 GLXPixmap glxpixmap; /* GLX pixmap for memory DCs */
159 SIZE pixmap_size; /* pixmap size for memory DCs */
166 WineGLPixelFormat* fmt;
170 int use_render_texture; /* This is also the internal texture format */
171 int texture_bind_target;
173 GLint texture_format;
174 GLuint texture_target;
182 struct gdi_physdev dev;
183 X11DRV_PDEVICE *x11dev;
184 enum dc_gl_type type; /* type of GL device context */
187 Pixmap pixmap; /* pixmap for a DL_GL_PIXMAP_WIN drawable */
190 static const struct gdi_dc_funcs glxdrv_funcs;
192 static inline struct glx_physdev *get_glxdrv_dev( PHYSDEV dev )
194 return (struct glx_physdev *)dev;
197 static struct list context_list = LIST_INIT( context_list );
198 static struct WineGLInfo WineGLInfo = { 0 };
199 static int use_render_texture_emulation = 1;
200 static BOOL has_swap_control;
201 static int swap_interval = 1;
203 static struct opengl_funcs opengl_funcs;
205 #define USE_GL_FUNC(name) #name,
206 static const char *opengl_func_names[] = { ALL_WGL_FUNCS };
209 static void X11DRV_WineGL_LoadExtensions(void);
210 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count);
211 static BOOL glxRequireVersion(int requiredVersion);
212 static BOOL glxRequireExtension(const char *requiredExtension);
214 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
215 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
216 TRACE(" - dwFlags : ");
217 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
218 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
219 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
220 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
221 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
222 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
223 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
224 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
225 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
226 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
227 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
228 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
229 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
230 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
231 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
232 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
233 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
234 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
235 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
236 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
240 TRACE(" - iPixelType : ");
241 switch (ppfd->iPixelType) {
242 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
243 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
247 TRACE(" - Color : %d\n", ppfd->cColorBits);
248 TRACE(" - Red : %d\n", ppfd->cRedBits);
249 TRACE(" - Green : %d\n", ppfd->cGreenBits);
250 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
251 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
252 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
253 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
254 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
255 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
257 TRACE(" - iLayerType : ");
258 switch (ppfd->iLayerType) {
259 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
260 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
261 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
266 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
267 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
269 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
271 MAKE_FUNCPTR(glXChooseVisual)
272 MAKE_FUNCPTR(glXCopyContext)
273 MAKE_FUNCPTR(glXCreateContext)
274 MAKE_FUNCPTR(glXCreateGLXPixmap)
275 MAKE_FUNCPTR(glXGetCurrentContext)
276 MAKE_FUNCPTR(glXGetCurrentDrawable)
277 MAKE_FUNCPTR(glXDestroyContext)
278 MAKE_FUNCPTR(glXDestroyGLXPixmap)
279 MAKE_FUNCPTR(glXGetConfig)
280 MAKE_FUNCPTR(glXIsDirect)
281 MAKE_FUNCPTR(glXMakeCurrent)
282 MAKE_FUNCPTR(glXSwapBuffers)
283 MAKE_FUNCPTR(glXQueryExtension)
284 MAKE_FUNCPTR(glXQueryVersion)
287 MAKE_FUNCPTR(glXGetClientString)
288 MAKE_FUNCPTR(glXQueryExtensionsString)
289 MAKE_FUNCPTR(glXQueryServerString)
292 MAKE_FUNCPTR(glXGetFBConfigs)
293 MAKE_FUNCPTR(glXChooseFBConfig)
294 MAKE_FUNCPTR(glXCreatePbuffer)
295 MAKE_FUNCPTR(glXCreateNewContext)
296 MAKE_FUNCPTR(glXDestroyPbuffer)
297 MAKE_FUNCPTR(glXGetFBConfigAttrib)
298 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
299 MAKE_FUNCPTR(glXMakeContextCurrent)
300 MAKE_FUNCPTR(glXQueryDrawable)
301 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
305 static GLXContext (*pglXCreateContextAttribsARB)(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
306 static void* (*pglXGetProcAddressARB)(const GLubyte *);
307 static int (*pglXSwapIntervalSGI)(int);
309 /* NV GLX Extension */
310 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
311 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
313 /* MESA GLX Extensions */
314 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
316 /* Standard OpenGL */
317 static void (*pglFinish)(void);
318 static void (*pglFlush)(void);
320 static void wglFinish(void);
321 static void wglFlush(void);
323 static int GLXErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
325 /* In the future we might want to find the exact X or GLX error to report back to the app */
329 static BOOL infoInitialized = FALSE;
330 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
332 int screen = DefaultScreen(gdi_display);
333 Window win = 0, root = 0;
334 const char *gl_renderer;
337 GLXContext ctx = NULL;
338 XSetWindowAttributes attr;
340 int attribList[] = {GLX_RGBA, GLX_DOUBLEBUFFER, None};
344 infoInitialized = TRUE;
346 attr.override_redirect = True;
347 attr.colormap = None;
348 attr.border_pixel = 0;
352 vis = pglXChooseVisual(gdi_display, screen, attribList);
355 WORD old_fs = wine_get_fs();
356 /* Create a GLX Context. Without one we can't query GL information */
357 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
358 if (wine_get_fs() != old_fs)
360 wine_set_fs( old_fs );
361 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
362 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
366 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
371 root = RootWindow( gdi_display, vis->screen );
372 if (vis->visual != DefaultVisual( gdi_display, vis->screen ))
373 attr.colormap = XCreateColormap( gdi_display, root, vis->visual, AllocNone );
374 if ((win = XCreateWindow( gdi_display, root, -1, -1, 1, 1, 0, vis->depth, InputOutput,
375 vis->visual, CWBorderPixel | CWOverrideRedirect | CWColormap, &attr )))
376 XMapWindow( gdi_display, win );
380 if(pglXMakeCurrent(gdi_display, win, ctx) == 0)
382 ERR_(winediag)( "Unable to activate OpenGL context, most likely your OpenGL drivers haven't been installed correctly\n" );
385 gl_renderer = (const char *)opengl_funcs.gl.p_glGetString(GL_RENDERER);
386 WineGLInfo.glVersion = (const char *) opengl_funcs.gl.p_glGetString(GL_VERSION);
387 str = (const char *) opengl_funcs.gl.p_glGetString(GL_EXTENSIONS);
388 WineGLInfo.glExtensions = HeapAlloc(GetProcessHeap(), 0, strlen(str)+1);
389 strcpy(WineGLInfo.glExtensions, str);
391 /* Get the common GLX version supported by GLX client and server ( major/minor) */
392 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
394 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
395 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
396 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
398 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
399 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
400 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
402 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
403 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
405 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
406 TRACE("GL renderer : %s.\n", gl_renderer);
407 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
408 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
409 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
410 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
411 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
412 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
414 if(!WineGLInfo.glxDirect)
416 int fd = ConnectionNumber(gdi_display);
417 struct sockaddr_un uaddr;
418 unsigned int uaddrlen = sizeof(struct sockaddr_un);
420 /* In general indirect rendering on a local X11 server indicates a driver problem.
421 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
423 if(!getsockname(fd, (struct sockaddr *)&uaddr, &uaddrlen) && uaddr.sun_family == AF_UNIX)
424 ERR_(winediag)("Direct rendering is disabled, most likely your OpenGL drivers "
425 "haven't been installed correctly (using GL renderer %s, version %s).\n",
426 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
430 /* In general you would expect that if direct rendering is returned, that you receive hardware
431 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
432 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
433 * software rendering, it shows direct rendering.
435 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
436 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
437 * it shows 'Mesa X11'.
439 if(!strcmp(gl_renderer, "Software Rasterizer") || !strcmp(gl_renderer, "Mesa X11"))
440 ERR_(winediag)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL "
441 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
442 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
449 pglXMakeCurrent(gdi_display, None, NULL);
450 pglXDestroyContext(gdi_display, ctx);
452 if (win != root) XDestroyWindow( gdi_display, win );
453 if (attr.colormap) XFreeColormap( gdi_display, attr.colormap );
455 if (!ret) ERR(" couldn't initialize OpenGL, expect problems\n");
459 static BOOL has_opengl(void)
461 static int init_done;
462 static void *opengl_handle;
465 int error_base, event_base;
468 if (init_done) return (opengl_handle != NULL);
471 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
472 and include all dependencies */
473 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, buffer, sizeof(buffer));
474 if (opengl_handle == NULL)
476 ERR( "Failed to load libGL: %s\n", buffer );
477 ERR( "OpenGL support is disabled.\n");
481 for (i = 0; i < sizeof(opengl_func_names)/sizeof(opengl_func_names[0]); i++)
483 if (!(((void **)&opengl_funcs.gl)[i] = wine_dlsym( opengl_handle, opengl_func_names[i], NULL, 0 )))
485 ERR( "%s not found in libGL, disabling OpenGL.\n", opengl_func_names[i] );
490 /* redirect some standard OpenGL functions */
491 #define REDIRECT(func) \
492 do { p##func = opengl_funcs.gl.p_##func; opengl_funcs.gl.p_##func = w##func; } while(0)
493 REDIRECT( glFinish );
497 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
498 if (pglXGetProcAddressARB == NULL) {
499 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
503 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
505 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
510 LOAD_FUNCPTR(glXChooseVisual);
511 LOAD_FUNCPTR(glXCopyContext);
512 LOAD_FUNCPTR(glXCreateContext);
513 LOAD_FUNCPTR(glXCreateGLXPixmap);
514 LOAD_FUNCPTR(glXGetCurrentContext);
515 LOAD_FUNCPTR(glXGetCurrentDrawable);
516 LOAD_FUNCPTR(glXDestroyContext);
517 LOAD_FUNCPTR(glXDestroyGLXPixmap);
518 LOAD_FUNCPTR(glXGetConfig);
519 LOAD_FUNCPTR(glXIsDirect);
520 LOAD_FUNCPTR(glXMakeCurrent);
521 LOAD_FUNCPTR(glXSwapBuffers);
522 LOAD_FUNCPTR(glXQueryExtension);
523 LOAD_FUNCPTR(glXQueryVersion);
526 LOAD_FUNCPTR(glXGetClientString);
527 LOAD_FUNCPTR(glXQueryExtensionsString);
528 LOAD_FUNCPTR(glXQueryServerString);
531 LOAD_FUNCPTR(glXCreatePbuffer);
532 LOAD_FUNCPTR(glXCreateNewContext);
533 LOAD_FUNCPTR(glXDestroyPbuffer);
534 LOAD_FUNCPTR(glXMakeContextCurrent);
535 LOAD_FUNCPTR(glXGetCurrentReadDrawable);
536 LOAD_FUNCPTR(glXGetFBConfigs);
539 /* It doesn't matter if these fail. They'll only be used if the driver reports
540 the associated extension is available (and if a driver reports the extension
541 is available but fails to provide the functions, it's quite broken) */
542 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
543 /* ARB GLX Extension */
544 LOAD_FUNCPTR(glXCreateContextAttribsARB);
545 /* SGI GLX Extension */
546 LOAD_FUNCPTR(glXSwapIntervalSGI);
547 /* NV GLX Extension */
548 LOAD_FUNCPTR(glXAllocateMemoryNV);
549 LOAD_FUNCPTR(glXFreeMemoryNV);
552 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed;
555 if (pglXQueryExtension(gdi_display, &error_base, &event_base)) {
556 TRACE("GLX is up and running error_base = %d\n", error_base);
559 ERR( "GLX extension is missing, disabling OpenGL.\n" );
563 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
564 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
567 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
568 * depends on the reported GLX client / server version and on the client / server extension list.
569 * Those don't have to be the same.
571 * In general the server GLX information lists the capabilities in case of indirect rendering.
572 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
573 * available and in that case the client GLX informat can be used.
574 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
575 * in the GLX version/extension list. When a program does this it works for certain for both
576 * direct and indirect rendering.
578 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
579 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
580 * extension list which causes this extension not to be listed. (Wine requires this extension).
581 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
582 * pbuffers is around.
584 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
585 * the ATI drivers and from then on use GLX client information for them.
588 if(glxRequireVersion(3)) {
589 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
590 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
591 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
592 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
593 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
594 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
595 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
596 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
598 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
599 * enable this function when the Xserver understand GLX 1.3 or newer
601 pglXQueryDrawable = NULL;
602 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
603 TRACE("Overriding ATI GLX capabilities!\n");
604 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
605 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
606 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
607 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
609 /* Use client GLX information in case of the ATI drivers. We override the
610 * capabilities over here and not somewhere else as ATI might better their
611 * life in the future. In case they release proper drivers this block of
612 * code won't be called. */
613 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
615 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
618 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
619 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
622 X11DRV_WineGL_LoadExtensions();
628 wine_dlclose(opengl_handle, NULL, 0);
629 opengl_handle = NULL;
633 static int describeContext( struct wgl_context *ctx ) {
636 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
637 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
638 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
639 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
640 TRACE(" - VISUAL_ID 0x%x\n", tmp);
645 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, struct wgl_pbuffer* pbuf) {
650 int nvfloatattrib = GLX_DONT_CARE;
651 int pixelattrib = GLX_DONT_CARE;
653 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
654 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
655 while (iWGLAttr && 0 != iWGLAttr[cur]) {
656 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
658 switch (iWGLAttr[cur]) {
659 case WGL_AUX_BUFFERS_ARB:
660 pop = iWGLAttr[++cur];
661 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
662 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
664 case WGL_COLOR_BITS_ARB:
665 pop = iWGLAttr[++cur];
666 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
667 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
669 case WGL_BLUE_BITS_ARB:
670 pop = iWGLAttr[++cur];
671 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
672 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
674 case WGL_RED_BITS_ARB:
675 pop = iWGLAttr[++cur];
676 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
677 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
679 case WGL_GREEN_BITS_ARB:
680 pop = iWGLAttr[++cur];
681 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
682 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
684 case WGL_ALPHA_BITS_ARB:
685 pop = iWGLAttr[++cur];
686 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
687 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
689 case WGL_DEPTH_BITS_ARB:
690 pop = iWGLAttr[++cur];
691 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
692 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
694 case WGL_STENCIL_BITS_ARB:
695 pop = iWGLAttr[++cur];
696 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
697 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
699 case WGL_DOUBLE_BUFFER_ARB:
700 pop = iWGLAttr[++cur];
701 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
702 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
705 pop = iWGLAttr[++cur];
706 PUSH2(oGLXAttr, GLX_STEREO, pop);
707 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur, pop);
710 case WGL_PIXEL_TYPE_ARB:
711 pop = iWGLAttr[++cur];
712 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
714 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
715 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
716 /* 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 */
717 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
718 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT: pixelattrib = GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT; break ;
720 ERR("unexpected PixelType(%x)\n", pop);
725 case WGL_SUPPORT_GDI_ARB:
726 /* This flag is set in a WineGLPixelFormat */
727 pop = iWGLAttr[++cur];
728 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
731 case WGL_DRAW_TO_BITMAP_ARB:
732 /* This flag is set in a WineGLPixelFormat */
733 pop = iWGLAttr[++cur];
734 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
737 case WGL_DRAW_TO_WINDOW_ARB:
738 pop = iWGLAttr[++cur];
739 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
740 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
742 drawattrib |= GLX_WINDOW_BIT;
746 case WGL_DRAW_TO_PBUFFER_ARB:
747 pop = iWGLAttr[++cur];
748 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
749 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
751 drawattrib |= GLX_PBUFFER_BIT;
755 case WGL_ACCELERATION_ARB:
756 /* This flag is set in a WineGLPixelFormat */
757 pop = iWGLAttr[++cur];
758 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur, pop);
761 case WGL_SUPPORT_OPENGL_ARB:
762 pop = iWGLAttr[++cur];
763 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
764 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
767 case WGL_SWAP_METHOD_ARB:
768 pop = iWGLAttr[++cur];
769 /* For now we ignore this and just return SWAP_EXCHANGE */
770 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur, pop);
773 case WGL_PBUFFER_LARGEST_ARB:
774 pop = iWGLAttr[++cur];
775 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
776 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
779 case WGL_SAMPLE_BUFFERS_ARB:
780 pop = iWGLAttr[++cur];
781 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
782 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
785 case WGL_SAMPLES_ARB:
786 pop = iWGLAttr[++cur];
787 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
788 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
791 case WGL_TEXTURE_FORMAT_ARB:
792 case WGL_TEXTURE_TARGET_ARB:
793 case WGL_MIPMAP_TEXTURE_ARB:
794 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
795 pop = iWGLAttr[++cur];
797 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
799 if (!use_render_texture_emulation) {
800 if (WGL_NO_TEXTURE_ARB != pop) {
801 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
802 return -1; /** error: don't support it */
804 drawattrib |= GLX_PBUFFER_BIT;
808 case WGL_FLOAT_COMPONENTS_NV:
809 nvfloatattrib = iWGLAttr[++cur];
810 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
812 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
813 case WGL_BIND_TO_TEXTURE_RGB_ARB:
814 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
815 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
816 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
817 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
818 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
819 pop = iWGLAttr[++cur];
820 /** cannot be converted, see direct handling on
821 * - wglGetPixelFormatAttribivARB
822 * TODO: wglChoosePixelFormat
825 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
826 pop = iWGLAttr[++cur];
827 PUSH2(oGLXAttr, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, pop);
828 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur, pop);
831 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
832 pop = iWGLAttr[++cur];
833 PUSH2(oGLXAttr, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT, pop);
834 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur, pop);
837 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
843 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
844 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
845 * pixmap and pbuffer formats appear as well. */
846 if (!drawattrib) drawattrib = GLX_DONT_CARE;
847 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
848 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
850 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
851 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
852 * GLX_DONT_CARE unless it is overridden. */
853 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
854 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
856 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
857 if(strstr(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
858 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
859 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
865 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
867 int render_type=0, render_type_bit;
868 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
869 switch(render_type_bit)
872 render_type = GLX_RGBA_TYPE;
874 case GLX_COLOR_INDEX_BIT:
875 render_type = GLX_COLOR_INDEX_TYPE;
877 case GLX_RGBA_FLOAT_BIT:
878 render_type = GLX_RGBA_FLOAT_TYPE;
880 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT:
881 render_type = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
884 ERR("Unknown render_type: %x\n", render_type_bit);
889 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
890 static BOOL check_fbconfig_bitmap_capability(Display *display, GLXFBConfig fbconfig)
893 pglXGetFBConfigAttrib(display, fbconfig, GLX_DOUBLEBUFFER, &dbuf);
894 pglXGetFBConfigAttrib(gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &value);
896 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
897 * the GLX_PIXMAP_BIT set. */
898 return !dbuf && (value & GLX_PIXMAP_BIT);
901 static WineGLPixelFormat *get_formats(Display *display, int *size_ret, int *onscreen_size_ret)
903 static WineGLPixelFormat *list;
904 static int size, onscreen_size;
906 int fmt_id, nCfgs, i, run, bmp_formats;
908 XVisualInfo *visinfo;
913 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
914 if (NULL == cfgs || 0 == nCfgs) {
915 if(cfgs != NULL) XFree(cfgs);
917 ERR("glXChooseFBConfig returns NULL\n");
921 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
922 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
923 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
924 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
926 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
928 for(i=0, bmp_formats=0; i<nCfgs; i++)
930 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
933 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats);
935 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nCfgs + bmp_formats)*sizeof(WineGLPixelFormat));
937 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
938 * Do this as GLX doesn't guarantee that the list is sorted */
939 for(run=0; run < 2; run++)
941 for(i=0; i<nCfgs; i++) {
942 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
943 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
945 /* The first run we only add onscreen formats (ones which have an associated X Visual).
946 * The second run we only set offscreen formats. */
949 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
950 * The contents is copied to the destination using XCopyArea. For the copying to work
951 * the depth of the source and destination window should be the same. In general this should
952 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
953 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
954 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
955 * list formats with the same depth. */
956 if(visinfo->depth != screen_depth)
962 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
963 list[size].iPixelFormat = size+1; /* The index starts at 1 */
964 list[size].fbconfig = cfgs[i];
965 list[size].fmt_id = fmt_id;
966 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
967 list[size].offscreenOnly = FALSE;
968 list[size].dwFlags = 0;
972 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
973 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
975 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
976 list[size].iPixelFormat = size+1; /* The index starts at 1 */
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].offscreenOnly = FALSE;
981 list[size].dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_GENERIC_FORMAT;
985 } else if(run && !visinfo) {
986 int window_drawable=0;
987 pglXGetFBConfigAttrib(gdi_display, cfgs[i], GLX_DRAWABLE_TYPE, &window_drawable);
989 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
990 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
991 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
992 * likely make our child window opengl rendering more complicated since likely you can't use
993 * XCopyArea on a GLX Window.
994 * For now ignore fbconfigs which are window drawable but lack a visual. */
995 if(window_drawable & GLX_WINDOW_BIT)
997 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id);
1001 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1002 list[size].iPixelFormat = size+1; /* The index starts at 1 */
1003 list[size].fbconfig = cfgs[i];
1004 list[size].fmt_id = fmt_id;
1005 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1006 list[size].offscreenOnly = TRUE;
1007 list[size].dwFlags = 0;
1011 if (visinfo) XFree(visinfo);
1018 if (size_ret) *size_ret = size;
1019 if (onscreen_size_ret) *onscreen_size_ret = onscreen_size;
1020 wine_tsx11_unlock();
1024 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1025 * In our WGL implementation we only support a subset of these formats namely the format of
1026 * Wine's main visual and offscreen formats (if they are available).
1027 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
1028 * and it returns the number of supported WGL formats in fmt_count.
1030 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count)
1032 WineGLPixelFormat *list, *res = NULL;
1033 int size, onscreen_size;
1035 if (!(list = get_formats(display, &size, &onscreen_size ))) return NULL;
1037 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1038 * iPixelFormat in case of probing the number of pixelformats.
1040 if((iPixelFormat > 0) && (iPixelFormat <= size) &&
1041 (!list[iPixelFormat-1].offscreenOnly || AllowOffscreen)) {
1042 res = &list[iPixelFormat-1];
1043 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n", res->fmt_id, iPixelFormat);
1049 *fmt_count = onscreen_size;
1051 TRACE("Number of returned pixelformats=%d\n", *fmt_count);
1056 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1057 static WineGLPixelFormat* ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id, DWORD dwFlags)
1059 WineGLPixelFormat *list;
1062 if (!(list = get_formats(display, &size, NULL ))) return NULL;
1064 for(i=0; i<size; i++) {
1065 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1066 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1067 if( (list[i].fmt_id == fmt_id) && ((list[i].dwFlags & dwFlags) == dwFlags) ) {
1068 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list[i].iPixelFormat, fmt_id);
1072 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id);
1076 static int pixelformat_from_fbconfig_id(XID fbconfig_id)
1078 WineGLPixelFormat *fmt;
1080 if (!fbconfig_id) return 0;
1082 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id, 0 /* no flags */);
1084 return fmt->iPixelFormat;
1085 /* This will happen on hwnds without a pixel format set; it's ok */
1090 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1091 void mark_drawable_dirty(Drawable old, Drawable new)
1093 struct wgl_context *ctx;
1094 LIST_FOR_EACH_ENTRY( ctx, &context_list, struct wgl_context, entry )
1096 if (old == ctx->drawables[0]) {
1097 ctx->drawables[0] = new;
1098 ctx->refresh_drawables = TRUE;
1100 if (old == ctx->drawables[1]) {
1101 ctx->drawables[1] = new;
1102 ctx->refresh_drawables = TRUE;
1107 /* Given the current context, make sure its drawable is sync'd */
1108 static inline void sync_context(struct wgl_context *context)
1110 if(context && context->refresh_drawables) {
1111 if (glxRequireVersion(3))
1112 pglXMakeContextCurrent(gdi_display, context->drawables[0],
1113 context->drawables[1], context->ctx);
1115 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
1116 context->refresh_drawables = FALSE;
1121 static GLXContext create_glxcontext(Display *display, struct wgl_context *context, GLXContext shareList)
1125 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1126 BOOL indirect = (context->fmt->dwFlags & PFD_DRAW_TO_BITMAP) ? FALSE : TRUE;
1128 if(context->gl3_context)
1130 if(context->numAttribs)
1131 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, context->attribList);
1133 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, NULL);
1135 else if(context->vis)
1136 ctx = pglXCreateContext(gdi_display, context->vis, shareList, indirect);
1137 else /* Create a GLX Context for a pbuffer */
1138 ctx = pglXCreateNewContext(gdi_display, context->fmt->fbconfig, context->fmt->render_type, shareList, TRUE);
1144 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
1146 return pglXCreateGLXPixmap(display, vis, parent);
1151 * glxdrv_DescribePixelFormat
1153 * Get the pixel-format descriptor associated to the given id
1155 static int glxdrv_DescribePixelFormat(PHYSDEV dev, int iPixelFormat,
1156 UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd)
1158 /*XVisualInfo *vis;*/
1161 WineGLPixelFormat *fmt;
1165 if (!has_opengl()) return 0;
1167 TRACE("(%p,%d,%d,%p)\n", dev->hdc, iPixelFormat, nBytes, ppfd);
1169 /* 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 */
1170 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_count);
1172 /* The application is only querying the number of pixelformats */
1174 } else if(fmt == NULL) {
1175 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1179 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1180 ERR("Wrong structure size !\n");
1181 /* Should set error */
1187 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1188 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1191 /* These flags are always the same... */
1192 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1193 /* Now the flags extracted from the Visual */
1197 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1198 if(value & GLX_WINDOW_BIT)
1199 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1201 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1202 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1203 * 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
1204 * offered the GDI bit either. */
1205 ppfd->dwFlags |= fmt->dwFlags & (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI);
1207 /* PFD_GENERIC_FORMAT - gdi software rendering
1208 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1209 * none set - full hardware accelerated by a ICD
1211 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1212 ppfd->dwFlags |= fmt->dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED);
1214 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1216 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1217 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1219 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1222 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1223 if (value & GLX_RGBA_BIT)
1224 ppfd->iPixelType = PFD_TYPE_RGBA;
1226 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1229 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1230 ppfd->cColorBits = value;
1232 /* Red, green, blue and alpha bits / shifts */
1233 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1234 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1235 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1236 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1237 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1239 ppfd->cRedBits = rb;
1240 ppfd->cRedShift = gb + bb + ab;
1241 ppfd->cBlueBits = bb;
1242 ppfd->cBlueShift = ab;
1243 ppfd->cGreenBits = gb;
1244 ppfd->cGreenShift = bb + ab;
1245 ppfd->cAlphaBits = ab;
1246 ppfd->cAlphaShift = 0;
1249 ppfd->cRedShift = 0;
1250 ppfd->cBlueBits = 0;
1251 ppfd->cBlueShift = 0;
1252 ppfd->cGreenBits = 0;
1253 ppfd->cGreenShift = 0;
1254 ppfd->cAlphaBits = 0;
1255 ppfd->cAlphaShift = 0;
1258 /* Accum RGBA bits */
1259 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1260 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1261 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1262 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1264 ppfd->cAccumBits = rb+gb+bb+ab;
1265 ppfd->cAccumRedBits = rb;
1266 ppfd->cAccumGreenBits = gb;
1267 ppfd->cAccumBlueBits = bb;
1268 ppfd->cAccumAlphaBits = ab;
1271 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1272 ppfd->cAuxBuffers = value;
1275 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1276 ppfd->cDepthBits = value;
1279 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1280 ppfd->cStencilBits = value;
1282 wine_tsx11_unlock();
1284 ppfd->iLayerType = PFD_MAIN_PLANE;
1286 if (TRACE_ON(wgl)) {
1287 dump_PIXELFORMATDESCRIPTOR(ppfd);
1293 /***********************************************************************
1294 * glxdrv_wglGetPixelFormat
1296 static int glxdrv_wglGetPixelFormat( HDC hdc )
1298 struct x11drv_escape_get_drawable escape;
1299 WineGLPixelFormat *fmt;
1302 TRACE( "(%p)\n", hdc );
1304 escape.code = X11DRV_GET_DRAWABLE;
1305 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape.code), (LPCSTR)&escape.code,
1306 sizeof(escape), (LPSTR)&escape ))
1309 if (!escape.pixel_format) return 0; /* not set yet */
1311 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, escape.pixel_format, TRUE, &tmp);
1314 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", escape.pixel_format);
1317 if (fmt->offscreenOnly)
1319 /* Offscreen formats can't be used with traditional WGL calls.
1320 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1321 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt->iPixelFormat);
1324 TRACE("(%p): returns %d\n", hdc, escape.pixel_format);
1325 return escape.pixel_format;
1328 /***********************************************************************
1329 * glxdrv_SetPixelFormat
1331 static BOOL glxdrv_SetPixelFormat(PHYSDEV dev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
1333 struct glx_physdev *physdev = get_glxdrv_dev( dev );
1334 WineGLPixelFormat *fmt;
1338 TRACE("(%p,%d,%p)\n", dev->hdc, iPixelFormat, ppfd);
1340 if (!has_opengl()) return FALSE;
1342 if(physdev->pixel_format) /* cannot change it if already set */
1343 return (physdev->pixel_format == iPixelFormat);
1345 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1346 if(physdev->x11dev->drawable == root_window)
1348 ERR("Invalid operation on root_window\n");
1352 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1353 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
1355 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1360 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1361 wine_tsx11_unlock();
1363 hwnd = WindowFromDC(physdev->dev.hdc);
1365 if(!(value&GLX_WINDOW_BIT)) {
1366 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1370 if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, fmt->fmt_id, 0)) {
1371 ERR("Couldn't set format of the window, returning failure\n");
1374 /* physDev->current_pf will be set by the DCE update */
1376 else if (GetObjectType( physdev->dev.hdc ) == OBJ_MEMDC) {
1377 if(!(value&GLX_PIXMAP_BIT)) {
1378 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat);
1382 physdev->pixel_format = iPixelFormat;
1383 physdev->type = DC_GL_BITMAP;
1386 FIXME("called on a non-window, non-bitmap object?\n");
1389 if (TRACE_ON(wgl)) {
1393 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1395 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1397 TRACE(" FBConfig have :\n");
1398 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1399 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1400 TRACE(" - VISUAL_ID 0x%x\n", value);
1401 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1402 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1404 wine_tsx11_unlock();
1409 /***********************************************************************
1410 * glxdrv_wglCopyContext
1412 static BOOL glxdrv_wglCopyContext(struct wgl_context *src, struct wgl_context *dst, UINT mask)
1414 TRACE("%p -> %p mask %#x\n", src, dst, mask);
1417 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1418 wine_tsx11_unlock();
1420 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1424 /***********************************************************************
1425 * glxdrv_wglCreateContext
1427 static struct wgl_context *glxdrv_wglCreateContext( HDC hdc )
1429 struct x11drv_escape_get_drawable escape;
1430 struct wgl_context *ret;
1431 WineGLPixelFormat *fmt;
1434 TRACE( "(%p)\n", hdc );
1436 escape.code = X11DRV_GET_DRAWABLE;
1437 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape.code), (LPCSTR)&escape.code,
1438 sizeof(escape), (LPSTR)&escape ))
1441 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, escape.pixel_format, TRUE /* Offscreen */, &fmt_count);
1442 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1443 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1444 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1445 * If this fails something is very wrong on the system. */
1447 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", escape.pixel_format);
1448 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1452 if (!(ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret)))) return 0;
1456 ret->has_been_current = FALSE;
1457 ret->sharing = FALSE;
1460 ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1461 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1462 list_add_head( &context_list, &ret->entry );
1463 wine_tsx11_unlock();
1465 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1469 /***********************************************************************
1470 * glxdrv_wglDeleteContext
1472 static void glxdrv_wglDeleteContext(struct wgl_context *ctx)
1474 TRACE("(%p)\n", ctx);
1477 list_remove( &ctx->entry );
1478 if (ctx->ctx) pglXDestroyContext( gdi_display, ctx->ctx );
1479 if (ctx->glxpixmap) pglXDestroyGLXPixmap( gdi_display, ctx->glxpixmap );
1480 if (ctx->pixmap) XFreePixmap( gdi_display, ctx->pixmap );
1481 if (ctx->vis) XFree( ctx->vis );
1482 wine_tsx11_unlock();
1484 HeapFree( GetProcessHeap(), 0, ctx );
1488 * X11DRV_wglGetCurrentReadDCARB
1490 * For OpenGL32 wglGetCurrentReadDCARB.
1492 static HDC X11DRV_wglGetCurrentReadDCARB(void)
1495 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1497 if (ctx) ret = ctx->read_hdc;
1499 TRACE(" returning %p (GL drawable %lu)\n", ret, ctx ? ctx->drawables[1] : 0);
1503 /***********************************************************************
1504 * glxdrv_wglGetProcAddress
1506 static PROC glxdrv_wglGetProcAddress(LPCSTR lpszProc)
1508 if (!strncmp(lpszProc, "wgl", 3)) return NULL;
1509 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1512 static GLXPixmap get_context_pixmap( HDC hdc, struct wgl_context *ctx )
1518 GetObjectW( GetCurrentObject( hdc, OBJ_BITMAP ), sizeof(bmp), &bmp );
1521 ctx->pixmap = XCreatePixmap( gdi_display, root_window,
1522 bmp.bmWidth, bmp.bmHeight, ctx->vis->depth );
1523 ctx->glxpixmap = pglXCreateGLXPixmap( gdi_display, ctx->vis, ctx->pixmap );
1524 wine_tsx11_unlock();
1525 ctx->pixmap_size.cx = bmp.bmWidth;
1526 ctx->pixmap_size.cy = bmp.bmHeight;
1528 return ctx->glxpixmap;
1531 /***********************************************************************
1532 * glxdrv_wglMakeCurrent
1534 static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx)
1537 struct x11drv_escape_get_drawable escape;
1539 TRACE("(%p,%p)\n", hdc, ctx);
1544 ret = pglXMakeCurrent(gdi_display, None, NULL);
1545 wine_tsx11_unlock();
1546 NtCurrentTeb()->glContext = NULL;
1550 escape.code = X11DRV_GET_DRAWABLE;
1551 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape.code), (LPCSTR)&escape.code,
1552 sizeof(escape), (LPSTR)&escape ))
1555 if (!escape.pixel_format)
1557 WARN("Trying to use an invalid drawable\n");
1558 SetLastError(ERROR_INVALID_HANDLE);
1561 if (ctx->fmt->iPixelFormat != escape.pixel_format)
1563 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1564 hdc, escape.pixel_format, ctx, ctx->fmt->iPixelFormat );
1565 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1570 if (escape.gl_type == DC_GL_BITMAP) escape.gl_drawable = get_context_pixmap( hdc, ctx );
1574 if (TRACE_ON(wgl)) {
1576 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &vis_id);
1577 describeContext(ctx);
1578 TRACE("hdc %p drawable %lx fmt %u vis %x ctx %p\n", hdc,
1579 escape.gl_drawable, escape.pixel_format, vis_id, ctx->ctx);
1582 ret = pglXMakeCurrent(gdi_display, escape.gl_drawable, ctx->ctx);
1586 NtCurrentTeb()->glContext = ctx;
1588 ctx->has_been_current = TRUE;
1590 ctx->read_hdc = hdc;
1591 ctx->drawables[0] = escape.gl_drawable;
1592 ctx->drawables[1] = escape.gl_drawable;
1593 ctx->refresh_drawables = FALSE;
1595 if (escape.gl_type == DC_GL_BITMAP) opengl_funcs.gl.p_glDrawBuffer(GL_FRONT_LEFT);
1598 SetLastError(ERROR_INVALID_HANDLE);
1599 wine_tsx11_unlock();
1601 TRACE(" returning %s\n", (ret ? "True" : "False"));
1605 /***********************************************************************
1606 * X11DRV_wglMakeContextCurrentARB
1608 static BOOL X11DRV_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *ctx )
1610 struct x11drv_escape_get_drawable escape_draw, escape_read;
1613 TRACE("(%p,%p,%p)\n", draw_hdc, read_hdc, ctx);
1618 ret = pglXMakeCurrent(gdi_display, None, NULL);
1619 wine_tsx11_unlock();
1620 NtCurrentTeb()->glContext = NULL;
1624 escape_draw.code = X11DRV_GET_DRAWABLE;
1625 if (!ExtEscape( draw_hdc, X11DRV_ESCAPE, sizeof(escape_draw.code), (LPCSTR)&escape_draw.code,
1626 sizeof(escape_draw), (LPSTR)&escape_draw ))
1629 escape_read.code = X11DRV_GET_DRAWABLE;
1630 if (!ExtEscape( read_hdc, X11DRV_ESCAPE, sizeof(escape_read.code), (LPCSTR)&escape_read.code,
1631 sizeof(escape_read), (LPSTR)&escape_read ))
1634 if (!escape_draw.pixel_format)
1636 WARN("Trying to use an invalid drawable\n");
1637 SetLastError(ERROR_INVALID_HANDLE);
1642 if (!pglXMakeContextCurrent) return FALSE;
1644 if (escape_draw.gl_type == DC_GL_BITMAP) escape_draw.gl_drawable = get_context_pixmap( draw_hdc, ctx );
1645 if (escape_read.gl_type == DC_GL_BITMAP) escape_read.gl_drawable = get_context_pixmap( read_hdc, ctx );
1648 ret = pglXMakeContextCurrent(gdi_display, escape_draw.gl_drawable, escape_read.gl_drawable, ctx->ctx);
1651 ctx->has_been_current = TRUE;
1652 ctx->hdc = draw_hdc;
1653 ctx->read_hdc = read_hdc;
1654 ctx->drawables[0] = escape_draw.gl_drawable;
1655 ctx->drawables[1] = escape_read.gl_drawable;
1656 ctx->refresh_drawables = FALSE;
1657 NtCurrentTeb()->glContext = ctx;
1660 SetLastError(ERROR_INVALID_HANDLE);
1661 wine_tsx11_unlock();
1664 TRACE(" returning %s\n", (ret ? "True" : "False"));
1668 /***********************************************************************
1669 * glxdrv_wglShareLists
1671 static BOOL glxdrv_wglShareLists(struct wgl_context *org, struct wgl_context *dest)
1673 TRACE("(%p, %p)\n", org, dest);
1675 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1676 * at context creation time but in case of WGL it is done using wglShareLists.
1677 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1678 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1679 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1680 * so there delaying context creation doesn't work.
1682 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1683 * and when a program requests sharing we recreate the destination context if it hasn't been made
1684 * current or when it hasn't shared display lists before.
1687 if((org->has_been_current && dest->has_been_current) || dest->has_been_current)
1689 ERR("Could not share display lists, one of the contexts has been current already !\n");
1692 else if(dest->sharing)
1694 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1699 if((GetObjectType(org->hdc) == OBJ_MEMDC) ^ (GetObjectType(dest->hdc) == OBJ_MEMDC))
1701 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
1705 describeContext(org);
1706 describeContext(dest);
1708 /* Re-create the GLX context and share display lists */
1709 pglXDestroyContext(gdi_display, dest->ctx);
1710 dest->ctx = create_glxcontext(gdi_display, dest, org->ctx);
1711 wine_tsx11_unlock();
1712 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1714 org->sharing = TRUE;
1715 dest->sharing = TRUE;
1721 /***********************************************************************
1722 * glxdrv_wglGetCurrentDC
1724 static HDC glxdrv_wglGetCurrentDC( struct wgl_context *ctx )
1726 TRACE("hdc %p\n", ctx->hdc);
1730 static void flush_pixmap( struct wgl_context *ctx )
1732 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
1733 BITMAPINFO *info = (BITMAPINFO *)buffer;
1734 struct gdi_image_bits bits;
1736 if (!get_pixmap_image( ctx->pixmap, ctx->pixmap_size.cx, ctx->pixmap_size.cy, ctx->vis, info, &bits ))
1738 HBITMAP bitmap = GetCurrentObject( ctx->hdc, OBJ_BITMAP );
1739 SetDIBits( 0, bitmap, 0, ctx->pixmap_size.cy, bits.ptr, info, DIB_RGB_COLORS );
1740 if (bits.free) bits.free( &bits );
1744 static void flush_gl_drawable( struct glx_physdev *physdev )
1747 int w = physdev->x11dev->dc_rect.right - physdev->x11dev->dc_rect.left;
1748 int h = physdev->x11dev->dc_rect.bottom - physdev->x11dev->dc_rect.top;
1749 Drawable src = physdev->drawable;
1751 if (w <= 0 || h <= 0) return;
1753 switch (physdev->type)
1755 case DC_GL_PIXMAP_WIN:
1756 src = physdev->pixmap;
1758 case DC_GL_CHILD_WIN:
1759 /* The GL drawable may be lagged behind if we don't flush first, so
1760 * flush the display make sure we copy up-to-date data */
1762 XFlush(gdi_display);
1763 XSetFunction(gdi_display, physdev->x11dev->gc, GXcopy);
1764 XCopyArea(gdi_display, src, physdev->x11dev->drawable, physdev->x11dev->gc, 0, 0, w, h,
1765 physdev->x11dev->dc_rect.left, physdev->x11dev->dc_rect.top);
1766 wine_tsx11_unlock();
1767 SetRect( &rect, 0, 0, w, h );
1768 add_device_bounds( physdev->x11dev, &rect );
1775 static void wglFinish(void)
1777 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1778 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
1783 wine_tsx11_unlock();
1786 if (ctx->pixmap) flush_pixmap( ctx );
1787 else ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
1791 static void wglFlush(void)
1793 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1794 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
1799 wine_tsx11_unlock();
1802 if (ctx->pixmap) flush_pixmap( ctx );
1803 else ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
1807 /***********************************************************************
1808 * X11DRV_wglCreateContextAttribsARB
1810 static struct wgl_context *X11DRV_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *hShareContext,
1811 const int* attribList )
1813 struct x11drv_escape_get_drawable escape;
1814 struct wgl_context *ret;
1815 WineGLPixelFormat *fmt;
1818 TRACE("(%p %p %p)\n", hdc, hShareContext, attribList);
1820 escape.code = X11DRV_GET_DRAWABLE;
1821 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape.code), (LPCSTR)&escape.code,
1822 sizeof(escape), (LPSTR)&escape ))
1825 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, escape.pixel_format, TRUE /* Offscreen */, &fmt_count);
1826 /* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones.
1827 * If this fails something is very wrong on the system. */
1830 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", escape.pixel_format);
1831 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1835 if (!(ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret)))) return 0;
1839 ret->vis = NULL; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
1840 ret->gl3_context = TRUE;
1842 ret->numAttribs = 0;
1845 int *pAttribList = (int*)attribList;
1846 int *pContextAttribList = &ret->attribList[0];
1847 /* attribList consists of pairs {token, value] terminated with 0 */
1848 while(pAttribList[0] != 0)
1850 TRACE("%#x %#x\n", pAttribList[0], pAttribList[1]);
1851 switch(pAttribList[0])
1853 case WGL_CONTEXT_MAJOR_VERSION_ARB:
1854 pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
1855 pContextAttribList[1] = pAttribList[1];
1857 case WGL_CONTEXT_MINOR_VERSION_ARB:
1858 pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB;
1859 pContextAttribList[1] = pAttribList[1];
1861 case WGL_CONTEXT_LAYER_PLANE_ARB:
1863 case WGL_CONTEXT_FLAGS_ARB:
1864 pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB;
1865 pContextAttribList[1] = pAttribList[1];
1867 case WGL_CONTEXT_PROFILE_MASK_ARB:
1868 pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
1869 pContextAttribList[1] = pAttribList[1];
1872 ERR("Unhandled attribList pair: %#x %#x\n", pAttribList[0], pAttribList[1]);
1877 pContextAttribList += 2;
1882 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
1883 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1885 XSync(gdi_display, False);
1886 if(X11DRV_check_error() || !ret->ctx)
1888 /* In the future we should convert the GLX error to a win32 one here if needed */
1889 ERR("Context creation failed\n");
1890 HeapFree( GetProcessHeap(), 0, ret );
1891 wine_tsx11_unlock();
1895 list_add_head( &context_list, &ret->entry );
1896 wine_tsx11_unlock();
1897 TRACE(" creating context %p\n", ret);
1902 * X11DRV_wglGetExtensionsStringARB
1904 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
1906 static const GLubyte *X11DRV_wglGetExtensionsStringARB(HDC hdc)
1908 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
1909 return (const GLubyte *)WineGLInfo.wglExtensions;
1913 * X11DRV_wglCreatePbufferARB
1915 * WGL_ARB_pbuffer: wglCreatePbufferARB
1917 static struct wgl_pbuffer *X11DRV_wglCreatePbufferARB( HDC hdc, int iPixelFormat, int iWidth, int iHeight,
1918 const int *piAttribList )
1920 struct wgl_pbuffer* object = NULL;
1921 WineGLPixelFormat *fmt = NULL;
1926 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
1928 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
1929 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nCfgs);
1931 ERR("(%p): invalid pixel format %d\n", hdc, iPixelFormat);
1932 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1936 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1937 if (NULL == object) {
1938 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
1941 object->width = iWidth;
1942 object->height = iHeight;
1945 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
1946 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
1947 while (piAttribList && 0 != *piAttribList) {
1949 switch (*piAttribList) {
1950 case WGL_PBUFFER_LARGEST_ARB: {
1952 attr_v = *piAttribList;
1953 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
1954 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
1958 case WGL_TEXTURE_FORMAT_ARB: {
1960 attr_v = *piAttribList;
1961 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
1962 if (WGL_NO_TEXTURE_ARB == attr_v) {
1963 object->use_render_texture = 0;
1965 if (!use_render_texture_emulation) {
1966 SetLastError(ERROR_INVALID_DATA);
1970 case WGL_TEXTURE_RGB_ARB:
1971 object->use_render_texture = GL_RGB;
1972 object->texture_bpp = 3;
1973 object->texture_format = GL_RGB;
1974 object->texture_type = GL_UNSIGNED_BYTE;
1976 case WGL_TEXTURE_RGBA_ARB:
1977 object->use_render_texture = GL_RGBA;
1978 object->texture_bpp = 4;
1979 object->texture_format = GL_RGBA;
1980 object->texture_type = GL_UNSIGNED_BYTE;
1983 /* WGL_FLOAT_COMPONENTS_NV */
1984 case WGL_TEXTURE_FLOAT_R_NV:
1985 object->use_render_texture = GL_FLOAT_R_NV;
1986 object->texture_bpp = 4;
1987 object->texture_format = GL_RED;
1988 object->texture_type = GL_FLOAT;
1990 case WGL_TEXTURE_FLOAT_RG_NV:
1991 object->use_render_texture = GL_FLOAT_RG_NV;
1992 object->texture_bpp = 8;
1993 object->texture_format = GL_LUMINANCE_ALPHA;
1994 object->texture_type = GL_FLOAT;
1996 case WGL_TEXTURE_FLOAT_RGB_NV:
1997 object->use_render_texture = GL_FLOAT_RGB_NV;
1998 object->texture_bpp = 12;
1999 object->texture_format = GL_RGB;
2000 object->texture_type = GL_FLOAT;
2002 case WGL_TEXTURE_FLOAT_RGBA_NV:
2003 object->use_render_texture = GL_FLOAT_RGBA_NV;
2004 object->texture_bpp = 16;
2005 object->texture_format = GL_RGBA;
2006 object->texture_type = GL_FLOAT;
2009 ERR("Unknown texture format: %x\n", attr_v);
2010 SetLastError(ERROR_INVALID_DATA);
2017 case WGL_TEXTURE_TARGET_ARB: {
2019 attr_v = *piAttribList;
2020 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2021 if (WGL_NO_TEXTURE_ARB == attr_v) {
2022 object->texture_target = 0;
2024 if (!use_render_texture_emulation) {
2025 SetLastError(ERROR_INVALID_DATA);
2029 case WGL_TEXTURE_CUBE_MAP_ARB: {
2030 if (iWidth != iHeight) {
2031 SetLastError(ERROR_INVALID_DATA);
2034 object->texture_target = GL_TEXTURE_CUBE_MAP;
2035 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2038 case WGL_TEXTURE_1D_ARB: {
2040 SetLastError(ERROR_INVALID_DATA);
2043 object->texture_target = GL_TEXTURE_1D;
2044 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2047 case WGL_TEXTURE_2D_ARB: {
2048 object->texture_target = GL_TEXTURE_2D;
2049 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2052 case WGL_TEXTURE_RECTANGLE_NV: {
2053 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2054 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2058 ERR("Unknown texture target: %x\n", attr_v);
2059 SetLastError(ERROR_INVALID_DATA);
2066 case WGL_MIPMAP_TEXTURE_ARB: {
2068 attr_v = *piAttribList;
2069 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2070 if (!use_render_texture_emulation) {
2071 SetLastError(ERROR_INVALID_DATA);
2080 PUSH1(attribs, None);
2082 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2083 wine_tsx11_unlock();
2084 TRACE("new Pbuffer drawable as %lx\n", object->drawable);
2085 if (!object->drawable) {
2086 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2087 goto create_failed; /* unexpected error */
2089 TRACE("->(%p)\n", object);
2093 HeapFree(GetProcessHeap(), 0, object);
2094 TRACE("->(FAILED)\n");
2099 * X11DRV_wglDestroyPbufferARB
2101 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2103 static BOOL X11DRV_wglDestroyPbufferARB( struct wgl_pbuffer *object )
2105 TRACE("(%p)\n", object);
2108 pglXDestroyPbuffer(gdi_display, object->drawable);
2109 wine_tsx11_unlock();
2110 HeapFree(GetProcessHeap(), 0, object);
2115 * X11DRV_wglGetPbufferDCARB
2117 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2119 static HDC X11DRV_wglGetPbufferDCARB( struct wgl_pbuffer *object )
2121 struct x11drv_escape_set_drawable escape;
2124 hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
2127 escape.code = X11DRV_SET_DRAWABLE;
2128 escape.drawable = object->drawable;
2129 escape.mode = IncludeInferiors;
2130 SetRect( &escape.dc_rect, 0, 0, object->width, object->height );
2131 escape.fbconfig_id = object->fmt->fmt_id;
2132 escape.gl_drawable = object->drawable;
2134 escape.gl_type = DC_GL_PBUFFER;
2135 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2137 TRACE( "(%p)->(%p)\n", object, hdc );
2142 * X11DRV_wglQueryPbufferARB
2144 * WGL_ARB_pbuffer: wglQueryPbufferARB
2146 static BOOL X11DRV_wglQueryPbufferARB( struct wgl_pbuffer *object, int iAttribute, int *piValue )
2148 TRACE("(%p, 0x%x, %p)\n", object, iAttribute, piValue);
2150 switch (iAttribute) {
2151 case WGL_PBUFFER_WIDTH_ARB:
2153 pglXQueryDrawable(gdi_display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2154 wine_tsx11_unlock();
2156 case WGL_PBUFFER_HEIGHT_ARB:
2158 pglXQueryDrawable(gdi_display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2159 wine_tsx11_unlock();
2162 case WGL_PBUFFER_LOST_ARB:
2163 /* GLX Pbuffers cannot be lost by default. We can support this by
2164 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2165 * to receive pixel buffer clobber events, however that may or may
2166 * not give any benefit */
2167 *piValue = GL_FALSE;
2170 case WGL_TEXTURE_FORMAT_ARB:
2171 if (!object->use_render_texture) {
2172 *piValue = WGL_NO_TEXTURE_ARB;
2174 if (!use_render_texture_emulation) {
2175 SetLastError(ERROR_INVALID_HANDLE);
2178 switch(object->use_render_texture) {
2180 *piValue = WGL_TEXTURE_RGB_ARB;
2183 *piValue = WGL_TEXTURE_RGBA_ARB;
2185 /* WGL_FLOAT_COMPONENTS_NV */
2187 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2189 case GL_FLOAT_RG_NV:
2190 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2192 case GL_FLOAT_RGB_NV:
2193 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2195 case GL_FLOAT_RGBA_NV:
2196 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2199 ERR("Unknown texture format: %x\n", object->use_render_texture);
2204 case WGL_TEXTURE_TARGET_ARB:
2205 if (!object->texture_target){
2206 *piValue = WGL_NO_TEXTURE_ARB;
2208 if (!use_render_texture_emulation) {
2209 SetLastError(ERROR_INVALID_DATA);
2212 switch (object->texture_target) {
2213 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2214 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2215 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2216 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2221 case WGL_MIPMAP_TEXTURE_ARB:
2222 *piValue = GL_FALSE; /** don't support that */
2223 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2227 FIXME("unexpected attribute %x\n", iAttribute);
2235 * X11DRV_wglReleasePbufferDCARB
2237 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2239 static int X11DRV_wglReleasePbufferDCARB( struct wgl_pbuffer *object, HDC hdc )
2241 TRACE("(%p, %p)\n", object, hdc);
2242 return DeleteDC(hdc);
2246 * X11DRV_wglSetPbufferAttribARB
2248 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2250 static BOOL X11DRV_wglSetPbufferAttribARB( struct wgl_pbuffer *object, const int *piAttribList )
2252 GLboolean ret = GL_FALSE;
2254 WARN("(%p, %p): alpha-testing, report any problem\n", object, piAttribList);
2256 if (!object->use_render_texture) {
2257 SetLastError(ERROR_INVALID_HANDLE);
2260 if (1 == use_render_texture_emulation) {
2267 * X11DRV_wglChoosePixelFormatARB
2269 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2271 static BOOL X11DRV_wglChoosePixelFormatARB( HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList,
2272 UINT nMaxFormats, int *piFormats, UINT *nNumFormats )
2277 GLXFBConfig* cfgs = NULL;
2281 WineGLPixelFormat *fmt;
2287 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2288 if (NULL != pfAttribFList) {
2289 FIXME("unused pfAttribFList\n");
2292 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2293 if (-1 == nAttribs) {
2294 WARN("Cannot convert WGL to GLX attributes\n");
2297 PUSH1(attribs, None);
2299 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2300 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2301 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2302 for(i=0; piAttribIList[i] != 0; i+=2)
2304 switch(piAttribIList[i])
2306 case WGL_DRAW_TO_BITMAP_ARB:
2307 if(piAttribIList[i+1])
2308 dwFlags |= PFD_DRAW_TO_BITMAP;
2310 case WGL_ACCELERATION_ARB:
2311 switch(piAttribIList[i+1])
2313 case WGL_NO_ACCELERATION_ARB:
2314 dwFlags |= PFD_GENERIC_FORMAT;
2316 case WGL_GENERIC_ACCELERATION_ARB:
2317 dwFlags |= PFD_GENERIC_ACCELERATED;
2319 case WGL_FULL_ACCELERATION_ARB:
2324 case WGL_SUPPORT_GDI_ARB:
2325 if(piAttribIList[i+1])
2326 dwFlags |= PFD_SUPPORT_GDI;
2331 /* Search for FB configurations matching the requirements in attribs */
2333 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2335 wine_tsx11_unlock();
2336 WARN("Compatible Pixel Format not found\n");
2340 /* Loop through all matching formats and check if they are suitable.
2341 * Note that this function should at max return nMaxFormats different formats */
2342 for(run=0; run < 2; run++)
2344 for (it = 0; it < nCfgs && pfmt_it < nMaxFormats; ++it)
2346 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2348 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2352 /* Search for the format in our list of compatible formats */
2353 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id, dwFlags);
2357 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2358 if( ((run == 0) && fmt->offscreenOnly) || ((run == 1) && !fmt->offscreenOnly) )
2361 piFormats[pfmt_it] = fmt->iPixelFormat;
2362 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2367 *nNumFormats = pfmt_it;
2370 wine_tsx11_unlock();
2375 * X11DRV_wglGetPixelFormatAttribivARB
2377 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2379 static BOOL X11DRV_wglGetPixelFormatAttribivARB( HDC hdc, int iPixelFormat, int iLayerPlane,
2380 UINT nAttributes, const int *piAttributes, int *piValues )
2383 WineGLPixelFormat *fmt = NULL;
2387 int nWGLFormats = 0;
2389 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2391 if (0 < iLayerPlane) {
2392 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2396 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2397 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2398 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2399 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nWGLFormats);
2401 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2405 for (i = 0; i < nAttributes; ++i) {
2406 const int curWGLAttr = piAttributes[i];
2407 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2409 switch (curWGLAttr) {
2410 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2411 piValues[i] = nWGLFormats;
2414 case WGL_SUPPORT_OPENGL_ARB:
2415 piValues[i] = GL_TRUE;
2418 case WGL_ACCELERATION_ARB:
2419 curGLXAttr = GLX_CONFIG_CAVEAT;
2420 if (!fmt) goto pix_error;
2421 if(fmt->dwFlags & PFD_GENERIC_FORMAT)
2422 piValues[i] = WGL_NO_ACCELERATION_ARB;
2423 else if(fmt->dwFlags & PFD_GENERIC_ACCELERATED)
2424 piValues[i] = WGL_GENERIC_ACCELERATION_ARB;
2426 piValues[i] = WGL_FULL_ACCELERATION_ARB;
2429 case WGL_TRANSPARENT_ARB:
2430 curGLXAttr = GLX_TRANSPARENT_TYPE;
2431 if (!fmt) goto pix_error;
2432 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2433 if (hTest) goto get_error;
2434 piValues[i] = GL_FALSE;
2435 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2438 case WGL_PIXEL_TYPE_ARB:
2439 curGLXAttr = GLX_RENDER_TYPE;
2440 if (!fmt) goto pix_error;
2441 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2442 if (hTest) goto get_error;
2443 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2444 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2445 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2446 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2447 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2448 else if (tmp & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) { piValues[i] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT; }
2450 ERR("unexpected RenderType(%x)\n", tmp);
2451 piValues[i] = WGL_TYPE_RGBA_ARB;
2455 case WGL_COLOR_BITS_ARB:
2456 curGLXAttr = GLX_BUFFER_SIZE;
2459 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2460 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2461 if (!use_render_texture_emulation) {
2462 piValues[i] = GL_FALSE;
2465 curGLXAttr = GLX_RENDER_TYPE;
2466 if (!fmt) goto pix_error;
2467 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2468 if (hTest) goto get_error;
2469 if (GLX_COLOR_INDEX_BIT == tmp) {
2470 piValues[i] = GL_FALSE;
2473 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2474 if (hTest) goto get_error;
2475 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2478 case WGL_BLUE_BITS_ARB:
2479 curGLXAttr = GLX_BLUE_SIZE;
2481 case WGL_RED_BITS_ARB:
2482 curGLXAttr = GLX_RED_SIZE;
2484 case WGL_GREEN_BITS_ARB:
2485 curGLXAttr = GLX_GREEN_SIZE;
2487 case WGL_ALPHA_BITS_ARB:
2488 curGLXAttr = GLX_ALPHA_SIZE;
2490 case WGL_DEPTH_BITS_ARB:
2491 curGLXAttr = GLX_DEPTH_SIZE;
2493 case WGL_STENCIL_BITS_ARB:
2494 curGLXAttr = GLX_STENCIL_SIZE;
2496 case WGL_DOUBLE_BUFFER_ARB:
2497 curGLXAttr = GLX_DOUBLEBUFFER;
2499 case WGL_STEREO_ARB:
2500 curGLXAttr = GLX_STEREO;
2502 case WGL_AUX_BUFFERS_ARB:
2503 curGLXAttr = GLX_AUX_BUFFERS;
2506 case WGL_SUPPORT_GDI_ARB:
2507 if (!fmt) goto pix_error;
2508 piValues[i] = (fmt->dwFlags & PFD_SUPPORT_GDI) ? TRUE : FALSE;
2511 case WGL_DRAW_TO_BITMAP_ARB:
2512 if (!fmt) goto pix_error;
2513 piValues[i] = (fmt->dwFlags & PFD_DRAW_TO_BITMAP) ? TRUE : FALSE;
2516 case WGL_DRAW_TO_WINDOW_ARB:
2517 case WGL_DRAW_TO_PBUFFER_ARB:
2518 if (!fmt) goto pix_error;
2519 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2520 if (hTest) goto get_error;
2521 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2522 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2523 piValues[i] = GL_TRUE;
2525 piValues[i] = GL_FALSE;
2528 case WGL_SWAP_METHOD_ARB:
2529 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
2530 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
2531 * point only ATI offers this.
2533 piValues[i] = WGL_SWAP_EXCHANGE_ARB;
2536 case WGL_PBUFFER_LARGEST_ARB:
2537 curGLXAttr = GLX_LARGEST_PBUFFER;
2540 case WGL_SAMPLE_BUFFERS_ARB:
2541 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2544 case WGL_SAMPLES_ARB:
2545 curGLXAttr = GLX_SAMPLES_ARB;
2548 case WGL_FLOAT_COMPONENTS_NV:
2549 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2552 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
2553 curGLXAttr = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT;
2556 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
2557 curGLXAttr = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
2560 case WGL_ACCUM_RED_BITS_ARB:
2561 curGLXAttr = GLX_ACCUM_RED_SIZE;
2563 case WGL_ACCUM_GREEN_BITS_ARB:
2564 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2566 case WGL_ACCUM_BLUE_BITS_ARB:
2567 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2569 case WGL_ACCUM_ALPHA_BITS_ARB:
2570 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2572 case WGL_ACCUM_BITS_ARB:
2573 if (!fmt) goto pix_error;
2574 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2575 if (hTest) goto get_error;
2577 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2578 if (hTest) goto get_error;
2580 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2581 if (hTest) goto get_error;
2583 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2584 if (hTest) goto get_error;
2589 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2592 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2593 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2594 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2596 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2597 * and check which options can work using iPixelFormat=0 and which not.
2598 * A problem would be that this function is an extension. This would
2599 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2601 if (0 != curGLXAttr && iPixelFormat != 0) {
2602 if (!fmt) goto pix_error;
2603 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2604 if (hTest) goto get_error;
2607 piValues[i] = GL_FALSE;
2610 wine_tsx11_unlock();
2614 wine_tsx11_unlock();
2615 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2619 wine_tsx11_unlock();
2620 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats);
2625 * X11DRV_wglGetPixelFormatAttribfvARB
2627 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2629 static BOOL X11DRV_wglGetPixelFormatAttribfvARB( HDC hdc, int iPixelFormat, int iLayerPlane,
2630 UINT nAttributes, const int *piAttributes, FLOAT *pfValues )
2636 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2638 /* Allocate a temporary array to store integer values */
2639 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2641 ERR("couldn't allocate %d array\n", nAttributes);
2645 /* Piggy-back on wglGetPixelFormatAttribivARB */
2646 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2648 /* Convert integer values to float. Should also check for attributes
2649 that can give decimal values here */
2650 for (i=0; i<nAttributes;i++) {
2651 pfValues[i] = attr[i];
2655 HeapFree(GetProcessHeap(), 0, attr);
2660 * X11DRV_wglBindTexImageARB
2662 * WGL_ARB_render_texture: wglBindTexImageARB
2664 static BOOL X11DRV_wglBindTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2666 GLboolean ret = GL_FALSE;
2668 TRACE("(%p, %d)\n", object, iBuffer);
2670 if (!object->use_render_texture) {
2671 SetLastError(ERROR_INVALID_HANDLE);
2675 if (1 == use_render_texture_emulation) {
2676 static int init = 0;
2677 int prev_binded_texture = 0;
2678 GLXContext prev_context;
2679 Drawable prev_drawable;
2680 GLXContext tmp_context;
2683 prev_context = pglXGetCurrentContext();
2684 prev_drawable = pglXGetCurrentDrawable();
2686 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2687 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2688 isn't ideal performance wise but I wasn't able to get other ways working.
2691 init = 1; /* Only show the FIXME once for performance reasons */
2692 FIXME("partial stub!\n");
2695 TRACE("drawable=%lx, context=%p\n", object->drawable, prev_context);
2696 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2698 opengl_funcs.gl.p_glGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2700 /* Switch to our pbuffer */
2701 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
2703 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2704 * After that upload the pbuffer texture data. */
2705 opengl_funcs.gl.p_glBindTexture(object->texture_target, prev_binded_texture);
2706 opengl_funcs.gl.p_glCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2708 /* Switch back to the original drawable and upload the pbuffer-texture */
2709 pglXMakeCurrent(gdi_display, prev_drawable, prev_context);
2710 pglXDestroyContext(gdi_display, tmp_context);
2711 wine_tsx11_unlock();
2719 * X11DRV_wglReleaseTexImageARB
2721 * WGL_ARB_render_texture: wglReleaseTexImageARB
2723 static BOOL X11DRV_wglReleaseTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2725 GLboolean ret = GL_FALSE;
2727 TRACE("(%p, %d)\n", object, iBuffer);
2729 if (!object->use_render_texture) {
2730 SetLastError(ERROR_INVALID_HANDLE);
2733 if (1 == use_render_texture_emulation) {
2740 * X11DRV_wglGetExtensionsStringEXT
2742 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2744 static const GLubyte *X11DRV_wglGetExtensionsStringEXT(void)
2746 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2747 return (const GLubyte *)WineGLInfo.wglExtensions;
2751 * X11DRV_wglGetSwapIntervalEXT
2753 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2755 static int X11DRV_wglGetSwapIntervalEXT(void)
2757 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
2758 * interval, so the swap interval has to be tracked. */
2760 return swap_interval;
2764 * X11DRV_wglSwapIntervalEXT
2766 * WGL_EXT_swap_control: wglSwapIntervalEXT
2768 static BOOL X11DRV_wglSwapIntervalEXT(int interval)
2772 TRACE("(%d)\n", interval);
2776 SetLastError(ERROR_INVALID_DATA);
2779 else if (!has_swap_control && interval == 0)
2781 /* wglSwapIntervalEXT considers an interval value of zero to mean that
2782 * vsync should be disabled, but glXSwapIntervalSGI considers such a
2783 * value to be an error. Just silently ignore the request for now. */
2784 WARN("Request to disable vertical sync is not handled\n");
2789 if (pglXSwapIntervalSGI)
2792 ret = !pglXSwapIntervalSGI(interval);
2793 wine_tsx11_unlock();
2796 WARN("GLX_SGI_swap_control extension is not available\n");
2799 swap_interval = interval;
2801 SetLastError(ERROR_DC_NOT_FOUND);
2808 * X11DRV_wglSetPixelFormatWINE
2810 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
2811 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
2813 static BOOL X11DRV_wglSetPixelFormatWINE(HDC hdc, int format)
2815 WineGLPixelFormat *fmt;
2819 TRACE("(%p,%d)\n", hdc, format);
2821 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, format, FALSE /* Offscreen */, &value);
2824 ERR( "Invalid format %d\n", format );
2828 hwnd = WindowFromDC( hdc );
2829 if (!hwnd || hwnd == GetDesktopWindow())
2831 ERR( "not a valid window DC %p\n", hdc );
2836 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
2837 wine_tsx11_unlock();
2839 if (!(value & GLX_WINDOW_BIT))
2841 WARN( "Pixel format %d is not compatible for window rendering\n", format );
2845 return SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, fmt->fmt_id, 0);
2846 /* DC pixel format will be set by the DCE update */
2850 * glxRequireVersion (internal)
2852 * Check if the supported GLX version matches requiredVersion.
2854 static BOOL glxRequireVersion(int requiredVersion)
2856 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2857 if(requiredVersion <= WineGLInfo.glxVersion[1])
2863 static BOOL glxRequireExtension(const char *requiredExtension)
2865 if (strstr(WineGLInfo.glxExtensions, requiredExtension) == NULL) {
2872 static void register_extension(const char *ext)
2874 if (WineGLInfo.wglExtensions[0])
2875 strcat(WineGLInfo.wglExtensions, " ");
2876 strcat(WineGLInfo.wglExtensions, ext);
2878 TRACE("'%s'\n", ext);
2882 * X11DRV_WineGL_LoadExtensions
2884 static void X11DRV_WineGL_LoadExtensions(void)
2886 WineGLInfo.wglExtensions[0] = 0;
2888 /* ARB Extensions */
2890 if(glxRequireExtension("GLX_ARB_create_context"))
2892 register_extension( "WGL_ARB_create_context" );
2893 opengl_funcs.ext.p_wglCreateContextAttribsARB = X11DRV_wglCreateContextAttribsARB;
2895 if(glxRequireExtension("GLX_ARB_create_context_profile"))
2896 register_extension("WGL_ARB_create_context_profile");
2899 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
2901 register_extension("WGL_ARB_pixel_format_float");
2902 register_extension("WGL_ATI_pixel_format_float");
2905 register_extension( "WGL_ARB_extensions_string" );
2906 opengl_funcs.ext.p_wglGetExtensionsStringARB = X11DRV_wglGetExtensionsStringARB;
2908 if (glxRequireVersion(3))
2910 register_extension( "WGL_ARB_make_current_read" );
2911 opengl_funcs.ext.p_wglGetCurrentReadDCARB = X11DRV_wglGetCurrentReadDCARB;
2912 opengl_funcs.ext.p_wglMakeContextCurrentARB = X11DRV_wglMakeContextCurrentARB;
2915 if (glxRequireExtension("GLX_ARB_multisample")) register_extension( "WGL_ARB_multisample" );
2917 /* In general pbuffer functionality requires support in the X-server. The functionality is
2918 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
2920 if ( glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") )
2922 register_extension( "WGL_ARB_pbuffer" );
2923 opengl_funcs.ext.p_wglCreatePbufferARB = X11DRV_wglCreatePbufferARB;
2924 opengl_funcs.ext.p_wglDestroyPbufferARB = X11DRV_wglDestroyPbufferARB;
2925 opengl_funcs.ext.p_wglGetPbufferDCARB = X11DRV_wglGetPbufferDCARB;
2926 opengl_funcs.ext.p_wglQueryPbufferARB = X11DRV_wglQueryPbufferARB;
2927 opengl_funcs.ext.p_wglReleasePbufferDCARB = X11DRV_wglReleasePbufferDCARB;
2928 opengl_funcs.ext.p_wglSetPbufferAttribARB = X11DRV_wglSetPbufferAttribARB;
2931 register_extension( "WGL_ARB_pixel_format" );
2932 opengl_funcs.ext.p_wglChoosePixelFormatARB = X11DRV_wglChoosePixelFormatARB;
2933 opengl_funcs.ext.p_wglGetPixelFormatAttribfvARB = X11DRV_wglGetPixelFormatAttribfvARB;
2934 opengl_funcs.ext.p_wglGetPixelFormatAttribivARB = X11DRV_wglGetPixelFormatAttribivARB;
2936 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
2937 if (glxRequireExtension("GLX_ARB_render_texture") ||
2938 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation))
2940 register_extension( "WGL_ARB_render_texture" );
2941 opengl_funcs.ext.p_wglBindTexImageARB = X11DRV_wglBindTexImageARB;
2942 opengl_funcs.ext.p_wglReleaseTexImageARB = X11DRV_wglReleaseTexImageARB;
2944 /* The WGL version of GLX_NV_float_buffer requires render_texture */
2945 if(glxRequireExtension("GLX_NV_float_buffer"))
2946 register_extension("WGL_NV_float_buffer");
2948 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
2949 if(strstr(WineGLInfo.glExtensions, "GL_NV_texture_rectangle") != NULL)
2950 register_extension("WGL_NV_texture_rectangle");
2953 /* EXT Extensions */
2955 register_extension( "WGL_EXT_extensions_string" );
2956 opengl_funcs.ext.p_wglGetExtensionsStringEXT = X11DRV_wglGetExtensionsStringEXT;
2958 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
2959 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
2960 register_extension( "WGL_EXT_swap_control" );
2961 opengl_funcs.ext.p_wglSwapIntervalEXT = X11DRV_wglSwapIntervalEXT;
2962 opengl_funcs.ext.p_wglGetSwapIntervalEXT = X11DRV_wglGetSwapIntervalEXT;
2964 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
2965 register_extension("WGL_EXT_framebuffer_sRGB");
2967 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
2968 register_extension("WGL_EXT_pixel_format_packed_float");
2970 if (glxRequireExtension("GLX_EXT_swap_control"))
2971 has_swap_control = TRUE;
2973 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
2974 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
2976 register_extension( "WGL_NV_vertex_array_range" );
2977 opengl_funcs.ext.p_wglAllocateMemoryNV = pglXAllocateMemoryNV;
2978 opengl_funcs.ext.p_wglFreeMemoryNV = pglXFreeMemoryNV;
2981 /* WINE-specific WGL Extensions */
2983 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
2984 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
2986 register_extension( "WGL_WINE_pixel_format_passthrough" );
2987 opengl_funcs.ext.p_wglSetPixelFormatWINE = X11DRV_wglSetPixelFormatWINE;
2991 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
2994 pglXDestroyGLXPixmap(display, glxpixmap);
2995 wine_tsx11_unlock();
3000 * glxdrv_SwapBuffers
3002 * Swap the buffers of this DC
3004 static BOOL glxdrv_SwapBuffers(PHYSDEV dev)
3006 struct glx_physdev *physdev = get_glxdrv_dev( dev );
3007 struct wgl_context *ctx = NtCurrentTeb()->glContext;
3009 TRACE("(%p)\n", dev->hdc);
3013 WARN("Using a NULL context, skipping\n");
3014 SetLastError(ERROR_INVALID_HANDLE);
3018 if (!physdev->drawable)
3020 WARN("Using an invalid drawable, skipping\n");
3021 SetLastError(ERROR_INVALID_HANDLE);
3027 switch (physdev->type)
3029 case DC_GL_PIXMAP_WIN:
3030 if(pglXCopySubBufferMESA) {
3031 int w = physdev->x11dev->dc_rect.right - physdev->x11dev->dc_rect.left;
3032 int h = physdev->x11dev->dc_rect.bottom - physdev->x11dev->dc_rect.top;
3034 /* (glX)SwapBuffers has an implicit glFlush effect, however
3035 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3039 pglXCopySubBufferMESA(gdi_display, physdev->drawable, 0, 0, w, h);
3044 pglXSwapBuffers(gdi_display, physdev->drawable);
3048 flush_gl_drawable( physdev );
3049 wine_tsx11_unlock();
3054 static long prev_time, start_time;
3055 static unsigned long frames, frames_total;
3057 DWORD time = GetTickCount();
3060 /* every 1.5 seconds */
3061 if (time - prev_time > 1500) {
3062 TRACE_(fps)("@ approx %.2ffps, total %.2ffps\n",
3063 1000.0*frames/(time - prev_time), 1000.0*frames_total/(time - start_time));
3066 if(start_time == 0) start_time = time;
3073 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3075 WineGLPixelFormat *fmt;
3078 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id, 0 /* no flags */);
3083 ret = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
3084 wine_tsx11_unlock();
3088 static BOOL create_glx_dc( PHYSDEV *pdev )
3090 /* assume that only the main x11 device implements GetDeviceCaps */
3091 X11DRV_PDEVICE *x11dev = get_x11drv_dev( GET_NEXT_PHYSDEV( *pdev, pGetDeviceCaps ));
3092 struct glx_physdev *physdev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physdev) );
3094 if (!physdev) return FALSE;
3095 physdev->x11dev = x11dev;
3096 push_dc_driver( pdev, &physdev->dev, &glxdrv_funcs );
3100 /**********************************************************************
3103 static BOOL glxdrv_CreateDC( PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device,
3104 LPCWSTR output, const DEVMODEW* initData )
3106 return create_glx_dc( pdev );
3109 /**********************************************************************
3110 * glxdrv_CreateCompatibleDC
3112 static BOOL glxdrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
3114 if (orig) /* chain to next driver first */
3116 orig = GET_NEXT_PHYSDEV( orig, pCreateCompatibleDC );
3117 if (!orig->funcs->pCreateCompatibleDC( orig, pdev )) return FALSE;
3119 /* otherwise we have been called by x11drv */
3120 return create_glx_dc( pdev );
3123 /**********************************************************************
3126 static BOOL glxdrv_DeleteDC( PHYSDEV dev )
3128 struct glx_physdev *physdev = get_glxdrv_dev( dev );
3129 HeapFree( GetProcessHeap(), 0, physdev );
3133 /**********************************************************************
3136 static INT glxdrv_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
3137 INT out_count, LPVOID out_data )
3139 struct glx_physdev *physdev = get_glxdrv_dev( dev );
3141 dev = GET_NEXT_PHYSDEV( dev, pExtEscape );
3143 if (escape == X11DRV_ESCAPE && in_data && in_count >= sizeof(enum x11drv_escape_codes))
3145 switch (*(const enum x11drv_escape_codes *)in_data)
3147 case X11DRV_SET_DRAWABLE:
3148 if (in_count >= sizeof(struct x11drv_escape_set_drawable))
3150 const struct x11drv_escape_set_drawable *data = in_data;
3151 physdev->pixel_format = pixelformat_from_fbconfig_id( data->fbconfig_id );
3152 physdev->type = data->gl_type;
3153 physdev->drawable = data->gl_drawable;
3154 physdev->pixmap = data->pixmap;
3155 TRACE( "SET_DRAWABLE hdc %p drawable %lx pf %u type %u\n",
3156 dev->hdc, physdev->drawable, physdev->pixel_format, physdev->type );
3159 case X11DRV_GET_DRAWABLE:
3160 if (out_count >= sizeof(struct x11drv_escape_get_drawable))
3162 struct x11drv_escape_get_drawable *data = out_data;
3163 data->pixel_format = physdev->pixel_format;
3164 data->gl_type = physdev->type;
3165 data->gl_drawable = physdev->drawable;
3166 data->pixmap = physdev->pixmap;
3169 case X11DRV_FLUSH_GL_DRAWABLE:
3170 flush_gl_drawable( physdev );
3176 return dev->funcs->pExtEscape( dev, escape, in_count, in_data, out_count, out_data );
3179 /**********************************************************************
3180 * glxdrv_wine_get_wgl_driver
3182 static struct opengl_funcs * glxdrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
3184 if (version != WINE_WGL_DRIVER_VERSION)
3186 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_WGL_DRIVER_VERSION );
3190 if (has_opengl()) return &opengl_funcs;
3192 dev = GET_NEXT_PHYSDEV( dev, wine_get_wgl_driver );
3193 return dev->funcs->wine_get_wgl_driver( dev, version );
3196 static const struct gdi_dc_funcs glxdrv_funcs =
3198 NULL, /* pAbortDoc */
3199 NULL, /* pAbortPath */
3200 NULL, /* pAlphaBlend */
3201 NULL, /* pAngleArc */
3204 NULL, /* pBeginPath */
3205 NULL, /* pBlendImage */
3207 NULL, /* pCloseFigure */
3208 glxdrv_CreateCompatibleDC, /* pCreateCompatibleDC */
3209 glxdrv_CreateDC, /* pCreateDC */
3210 glxdrv_DeleteDC, /* pDeleteDC */
3211 NULL, /* pDeleteObject */
3212 glxdrv_DescribePixelFormat, /* pDescribePixelFormat */
3213 NULL, /* pDeviceCapabilities */
3214 NULL, /* pEllipse */
3216 NULL, /* pEndPage */
3217 NULL, /* pEndPath */
3218 NULL, /* pEnumFonts */
3219 NULL, /* pEnumICMProfiles */
3220 NULL, /* pExcludeClipRect */
3221 NULL, /* pExtDeviceMode */
3222 glxdrv_ExtEscape, /* pExtEscape */
3223 NULL, /* pExtFloodFill */
3224 NULL, /* pExtSelectClipRgn */
3225 NULL, /* pExtTextOut */
3226 NULL, /* pFillPath */
3227 NULL, /* pFillRgn */
3228 NULL, /* pFlattenPath */
3229 NULL, /* pFontIsLinked */
3230 NULL, /* pFrameRgn */
3231 NULL, /* pGdiComment */
3232 NULL, /* pGdiRealizationInfo */
3233 NULL, /* pGetBoundsRect */
3234 NULL, /* pGetCharABCWidths */
3235 NULL, /* pGetCharABCWidthsI */
3236 NULL, /* pGetCharWidth */
3237 NULL, /* pGetDeviceCaps */
3238 NULL, /* pGetDeviceGammaRamp */
3239 NULL, /* pGetFontData */
3240 NULL, /* pGetFontUnicodeRanges */
3241 NULL, /* pGetGlyphIndices */
3242 NULL, /* pGetGlyphOutline */
3243 NULL, /* pGetICMProfile */
3244 NULL, /* pGetImage */
3245 NULL, /* pGetKerningPairs */
3246 NULL, /* pGetNearestColor */
3247 NULL, /* pGetOutlineTextMetrics */
3248 NULL, /* pGetPixel */
3249 NULL, /* pGetSystemPaletteEntries */
3250 NULL, /* pGetTextCharsetInfo */
3251 NULL, /* pGetTextExtentExPoint */
3252 NULL, /* pGetTextExtentExPointI */
3253 NULL, /* pGetTextFace */
3254 NULL, /* pGetTextMetrics */
3255 NULL, /* pGradientFill */
3256 NULL, /* pIntersectClipRect */
3257 NULL, /* pInvertRgn */
3259 NULL, /* pModifyWorldTransform */
3261 NULL, /* pOffsetClipRgn */
3262 NULL, /* pOffsetViewportOrg */
3263 NULL, /* pOffsetWindowOrg */
3264 NULL, /* pPaintRgn */
3267 NULL, /* pPolyBezier */
3268 NULL, /* pPolyBezierTo */
3269 NULL, /* pPolyDraw */
3270 NULL, /* pPolyPolygon */
3271 NULL, /* pPolyPolyline */
3272 NULL, /* pPolygon */
3273 NULL, /* pPolyline */
3274 NULL, /* pPolylineTo */
3275 NULL, /* pPutImage */
3276 NULL, /* pRealizeDefaultPalette */
3277 NULL, /* pRealizePalette */
3278 NULL, /* pRectangle */
3279 NULL, /* pResetDC */
3280 NULL, /* pRestoreDC */
3281 NULL, /* pRoundRect */
3283 NULL, /* pScaleViewportExt */
3284 NULL, /* pScaleWindowExt */
3285 NULL, /* pSelectBitmap */
3286 NULL, /* pSelectBrush */
3287 NULL, /* pSelectClipPath */
3288 NULL, /* pSelectFont */
3289 NULL, /* pSelectPalette */
3290 NULL, /* pSelectPen */
3291 NULL, /* pSetArcDirection */
3292 NULL, /* pSetBkColor */
3293 NULL, /* pSetBkMode */
3294 NULL, /* pSetBoundsRect */
3295 NULL, /* pSetDCBrushColor */
3296 NULL, /* pSetDCPenColor */
3297 NULL, /* pSetDIBitsToDevice */
3298 NULL, /* pSetDeviceClipping */
3299 NULL, /* pSetDeviceGammaRamp */
3300 NULL, /* pSetLayout */
3301 NULL, /* pSetMapMode */
3302 NULL, /* pSetMapperFlags */
3303 NULL, /* pSetPixel */
3304 glxdrv_SetPixelFormat, /* pSetPixelFormat */
3305 NULL, /* pSetPolyFillMode */
3306 NULL, /* pSetROP2 */
3307 NULL, /* pSetRelAbs */
3308 NULL, /* pSetStretchBltMode */
3309 NULL, /* pSetTextAlign */
3310 NULL, /* pSetTextCharacterExtra */
3311 NULL, /* pSetTextColor */
3312 NULL, /* pSetTextJustification */
3313 NULL, /* pSetViewportExt */
3314 NULL, /* pSetViewportOrg */
3315 NULL, /* pSetWindowExt */
3316 NULL, /* pSetWindowOrg */
3317 NULL, /* pSetWorldTransform */
3318 NULL, /* pStartDoc */
3319 NULL, /* pStartPage */
3320 NULL, /* pStretchBlt */
3321 NULL, /* pStretchDIBits */
3322 NULL, /* pStrokeAndFillPath */
3323 NULL, /* pStrokePath */
3324 glxdrv_SwapBuffers, /* pSwapBuffers */
3325 NULL, /* pUnrealizePalette */
3326 NULL, /* pWidenPath */
3327 glxdrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
3328 GDI_PRIORITY_GRAPHICS_DRV + 20 /* priority */
3331 static struct opengl_funcs opengl_funcs =
3334 glxdrv_wglCopyContext, /* p_wglCopyContext */
3335 glxdrv_wglCreateContext, /* p_wglCreateContext */
3336 glxdrv_wglDeleteContext, /* p_wglDeleteContext */
3337 glxdrv_wglGetCurrentDC, /* p_wglGetCurrentDC */
3338 glxdrv_wglGetPixelFormat, /* p_wglGetPixelFormat */
3339 glxdrv_wglGetProcAddress, /* p_wglGetProcAddress */
3340 glxdrv_wglMakeCurrent, /* p_wglMakeCurrent */
3341 glxdrv_wglShareLists, /* p_wglShareLists */
3345 const struct gdi_dc_funcs *get_glx_driver(void)
3347 return &glxdrv_funcs;
3350 #else /* no OpenGL includes */
3352 const struct gdi_dc_funcs *get_glx_driver(void)
3357 void mark_drawable_dirty(Drawable old, Drawable new)
3361 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
3367 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3372 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3377 #endif /* defined(SONAME_LIBGL) */