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>
41 #include "xcomposite.h"
43 #include "wine/library.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
50 WINE_DECLARE_DEBUG_CHANNEL(winediag);
53 #include "wine/wgl_driver.h"
54 #include "wine/wglext.h"
56 typedef struct __GLXcontextRec *GLXContext;
57 typedef struct __GLXFBConfigRec *GLXFBConfig;
58 typedef XID GLXPixmap;
59 typedef XID GLXDrawable;
60 typedef XID GLXFBConfigID;
61 typedef XID GLXContextID;
62 typedef XID GLXWindow;
63 typedef XID GLXPbuffer;
66 #define GLX_BUFFER_SIZE 2
69 #define GLX_DOUBLEBUFFER 5
71 #define GLX_AUX_BUFFERS 7
72 #define GLX_RED_SIZE 8
73 #define GLX_GREEN_SIZE 9
74 #define GLX_BLUE_SIZE 10
75 #define GLX_ALPHA_SIZE 11
76 #define GLX_DEPTH_SIZE 12
77 #define GLX_STENCIL_SIZE 13
78 #define GLX_ACCUM_RED_SIZE 14
79 #define GLX_ACCUM_GREEN_SIZE 15
80 #define GLX_ACCUM_BLUE_SIZE 16
81 #define GLX_ACCUM_ALPHA_SIZE 17
83 #define GLX_BAD_SCREEN 1
84 #define GLX_BAD_ATTRIBUTE 2
85 #define GLX_NO_EXTENSION 3
86 #define GLX_BAD_VISUAL 4
87 #define GLX_BAD_CONTEXT 5
88 #define GLX_BAD_VALUE 6
89 #define GLX_BAD_ENUM 7
93 #define GLX_EXTENSIONS 3
95 #define GLX_CONFIG_CAVEAT 0x20
96 #define GLX_DONT_CARE 0xFFFFFFFF
97 #define GLX_X_VISUAL_TYPE 0x22
98 #define GLX_TRANSPARENT_TYPE 0x23
99 #define GLX_TRANSPARENT_INDEX_VALUE 0x24
100 #define GLX_TRANSPARENT_RED_VALUE 0x25
101 #define GLX_TRANSPARENT_GREEN_VALUE 0x26
102 #define GLX_TRANSPARENT_BLUE_VALUE 0x27
103 #define GLX_TRANSPARENT_ALPHA_VALUE 0x28
104 #define GLX_WINDOW_BIT 0x00000001
105 #define GLX_PIXMAP_BIT 0x00000002
106 #define GLX_PBUFFER_BIT 0x00000004
107 #define GLX_AUX_BUFFERS_BIT 0x00000010
108 #define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001
109 #define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002
110 #define GLX_BACK_LEFT_BUFFER_BIT 0x00000004
111 #define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008
112 #define GLX_DEPTH_BUFFER_BIT 0x00000020
113 #define GLX_STENCIL_BUFFER_BIT 0x00000040
114 #define GLX_ACCUM_BUFFER_BIT 0x00000080
115 #define GLX_NONE 0x8000
116 #define GLX_SLOW_CONFIG 0x8001
117 #define GLX_TRUE_COLOR 0x8002
118 #define GLX_DIRECT_COLOR 0x8003
119 #define GLX_PSEUDO_COLOR 0x8004
120 #define GLX_STATIC_COLOR 0x8005
121 #define GLX_GRAY_SCALE 0x8006
122 #define GLX_STATIC_GRAY 0x8007
123 #define GLX_TRANSPARENT_RGB 0x8008
124 #define GLX_TRANSPARENT_INDEX 0x8009
125 #define GLX_VISUAL_ID 0x800B
126 #define GLX_SCREEN 0x800C
127 #define GLX_NON_CONFORMANT_CONFIG 0x800D
128 #define GLX_DRAWABLE_TYPE 0x8010
129 #define GLX_RENDER_TYPE 0x8011
130 #define GLX_X_RENDERABLE 0x8012
131 #define GLX_FBCONFIG_ID 0x8013
132 #define GLX_RGBA_TYPE 0x8014
133 #define GLX_COLOR_INDEX_TYPE 0x8015
134 #define GLX_MAX_PBUFFER_WIDTH 0x8016
135 #define GLX_MAX_PBUFFER_HEIGHT 0x8017
136 #define GLX_MAX_PBUFFER_PIXELS 0x8018
137 #define GLX_PRESERVED_CONTENTS 0x801B
138 #define GLX_LARGEST_PBUFFER 0x801C
139 #define GLX_WIDTH 0x801D
140 #define GLX_HEIGHT 0x801E
141 #define GLX_EVENT_MASK 0x801F
142 #define GLX_DAMAGED 0x8020
143 #define GLX_SAVED 0x8021
144 #define GLX_WINDOW 0x8022
145 #define GLX_PBUFFER 0x8023
146 #define GLX_PBUFFER_HEIGHT 0x8040
147 #define GLX_PBUFFER_WIDTH 0x8041
148 #define GLX_RGBA_BIT 0x00000001
149 #define GLX_COLOR_INDEX_BIT 0x00000002
150 #define GLX_PBUFFER_CLOBBER_MASK 0x08000000
152 /** GLX_ARB_multisample */
153 #define GLX_SAMPLE_BUFFERS_ARB 100000
154 #define GLX_SAMPLES_ARB 100001
155 /** GLX_ARB_framebuffer_sRGB */
156 #define GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20B2
157 /** GLX_EXT_fbconfig_packed_float */
158 #define GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT 0x20B1
159 #define GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT 0x00000008
160 /** GLX_ARB_create_context */
161 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
162 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
163 #define GLX_CONTEXT_FLAGS_ARB 0x2094
164 /** GLX_ARB_create_context_profile */
165 #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
166 /** GLX_ATI_pixel_format_float */
167 #define GLX_RGBA_FLOAT_ATI_BIT 0x00000100
168 /** GLX_ARB_pixel_format_float */
169 #define GLX_RGBA_FLOAT_BIT 0x00000004
170 #define GLX_RGBA_FLOAT_TYPE 0x20B9
171 /** GLX_NV_float_buffer */
172 #define GLX_FLOAT_COMPONENTS_NV 0x20B0
176 const char *glVersion;
181 const char *glxServerVersion;
182 const char *glxServerVendor;
183 const char *glxServerExtensions;
185 const char *glxClientVersion;
186 const char *glxClientVendor;
187 const char *glxClientExtensions;
189 const char *glxExtensions;
192 char wglExtensions[4096];
195 struct wgl_pixel_format
197 GLXFBConfig fbconfig;
200 DWORD dwFlags; /* We store some PFD_* flags in here for emulated bitmap formats */
206 BOOL has_been_current;
210 const struct wgl_pixel_format *fmt;
211 int numAttribs; /* This is needed for delaying wglCreateContextAttribsARB */
212 int attribList[16]; /* This is needed for delaying wglCreateContextAttribsARB */
214 Drawable drawables[2];
215 BOOL refresh_drawables;
222 const struct wgl_pixel_format* fmt;
226 int use_render_texture; /* This is also the internal texture format */
227 int texture_bind_target;
229 GLint texture_format;
230 GLuint texture_target;
238 DC_GL_NONE, /* no GL support (pixel format not set yet) */
239 DC_GL_WINDOW, /* normal top-level window */
240 DC_GL_CHILD_WIN, /* child window using XComposite */
241 DC_GL_PIXMAP_WIN, /* child window using intermediate pixmap */
242 DC_GL_PBUFFER /* pseudo memory DC using a PBuffer */
247 enum dc_gl_type type; /* type of GL surface */
248 Drawable drawable; /* drawable for rendering to the client area */
249 Pixmap pixmap; /* base pixmap if drawable is a GLXPixmap */
250 Colormap colormap; /* colormap used for the drawable */
251 const struct wgl_pixel_format *format; /* pixel format for the drawable */
252 XVisualInfo *visual; /* information about the GL visual */
253 RECT rect; /* drawable rect, relative to whole window drawable */
256 /* X context to associate a struct gl_drawable to an hwnd */
257 static XContext gl_hwnd_context;
258 /* X context to associate a struct gl_drawable to a pbuffer hdc */
259 static XContext gl_pbuffer_context;
261 static const struct gdi_dc_funcs glxdrv_funcs;
263 static inline struct glx_physdev *get_glxdrv_dev( PHYSDEV dev )
265 return (struct glx_physdev *)dev;
268 static struct list context_list = LIST_INIT( context_list );
269 static struct WineGLInfo WineGLInfo = { 0 };
270 static struct wgl_pixel_format *pixel_formats;
271 static int nb_pixel_formats, nb_onscreen_formats;
272 static int use_render_texture_emulation = 1;
273 static BOOL has_swap_control;
274 static int swap_interval = 1;
276 static CRITICAL_SECTION context_section;
277 static CRITICAL_SECTION_DEBUG critsect_debug =
279 0, 0, &context_section,
280 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
281 0, 0, { (DWORD_PTR)(__FILE__ ": context_section") }
283 static CRITICAL_SECTION context_section = { &critsect_debug, -1, 0, 0, 0, 0 };
285 static struct opengl_funcs opengl_funcs;
287 #define USE_GL_FUNC(name) #name,
288 static const char *opengl_func_names[] = { ALL_WGL_FUNCS };
291 static void X11DRV_WineGL_LoadExtensions(void);
292 static void init_pixel_formats( Display *display );
293 static BOOL glxRequireVersion(int requiredVersion);
295 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
296 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
297 TRACE(" - dwFlags : ");
298 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
299 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
300 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
301 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
302 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
303 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
304 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
305 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
306 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
307 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
308 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
309 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
310 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
311 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
312 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
313 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
314 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
315 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
316 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
317 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
321 TRACE(" - iPixelType : ");
322 switch (ppfd->iPixelType) {
323 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
324 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
328 TRACE(" - Color : %d\n", ppfd->cColorBits);
329 TRACE(" - Red : %d\n", ppfd->cRedBits);
330 TRACE(" - Green : %d\n", ppfd->cGreenBits);
331 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
332 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
333 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
334 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
335 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
336 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
338 TRACE(" - iLayerType : ");
339 switch (ppfd->iLayerType) {
340 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
341 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
342 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
347 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
348 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
351 static XVisualInfo* (*pglXChooseVisual)( Display *dpy, int screen, int *attribList );
352 static GLXContext (*pglXCreateContext)( Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct );
353 static void (*pglXDestroyContext)( Display *dpy, GLXContext ctx );
354 static Bool (*pglXMakeCurrent)( Display *dpy, GLXDrawable drawable, GLXContext ctx);
355 static void (*pglXCopyContext)( Display *dpy, GLXContext src, GLXContext dst, unsigned long mask );
356 static void (*pglXSwapBuffers)( Display *dpy, GLXDrawable drawable );
357 static GLXPixmap (*pglXCreateGLXPixmap)( Display *dpy, XVisualInfo *visual, Pixmap pixmap );
358 static void (*pglXDestroyGLXPixmap)( Display *dpy, GLXPixmap pixmap );
359 static Bool (*pglXQueryExtension)( Display *dpy, int *errorb, int *event );
360 static Bool (*pglXQueryVersion)( Display *dpy, int *maj, int *min );
361 static Bool (*pglXIsDirect)( Display *dpy, GLXContext ctx );
362 static int (*pglXGetConfig)( Display *dpy, XVisualInfo *visual, int attrib, int *value );
363 static GLXContext (*pglXGetCurrentContext)( void );
364 static GLXDrawable (*pglXGetCurrentDrawable)( void );
367 static const char *(*pglXQueryExtensionsString)( Display *dpy, int screen );
368 static const char *(*pglXQueryServerString)( Display *dpy, int screen, int name );
369 static const char *(*pglXGetClientString)( Display *dpy, int name );
372 static GLXFBConfig *(*pglXChooseFBConfig)( Display *dpy, int screen, const int *attribList, int *nitems );
373 static int (*pglXGetFBConfigAttrib)( Display *dpy, GLXFBConfig config, int attribute, int *value );
374 static GLXFBConfig *(*pglXGetFBConfigs)( Display *dpy, int screen, int *nelements );
375 static XVisualInfo *(*pglXGetVisualFromFBConfig)( Display *dpy, GLXFBConfig config );
376 static GLXPbuffer (*pglXCreatePbuffer)( Display *dpy, GLXFBConfig config, const int *attribList );
377 static void (*pglXDestroyPbuffer)( Display *dpy, GLXPbuffer pbuf );
378 static void (*pglXQueryDrawable)( Display *dpy, GLXDrawable draw, int attribute, unsigned int *value );
379 static GLXContext (*pglXCreateNewContext)( Display *dpy, GLXFBConfig config, int renderType, GLXContext shareList, Bool direct );
380 static Bool (*pglXMakeContextCurrent)( Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx );
383 static GLXContext (*pglXCreateContextAttribsARB)(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
384 static void* (*pglXGetProcAddressARB)(const GLubyte *);
385 static int (*pglXSwapIntervalSGI)(int);
387 /* NV GLX Extension */
388 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
389 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
391 /* MESA GLX Extensions */
392 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
394 /* Standard OpenGL */
395 static void (*pglFinish)(void);
396 static void (*pglFlush)(void);
398 static void wglFinish(void);
399 static void wglFlush(void);
401 /* check if the extension is present in the list */
402 static BOOL has_extension( const char *list, const char *ext )
404 size_t len = strlen( ext );
408 while (*list == ' ') list++;
409 if (!strncmp( list, ext, len ) && (!list[len] || list[len] == ' ')) return TRUE;
410 list = strchr( list, ' ' );
415 static int GLXErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
417 /* In the future we might want to find the exact X or GLX error to report back to the app */
421 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
423 int screen = DefaultScreen(gdi_display);
424 Window win = 0, root = 0;
425 const char *gl_renderer;
428 GLXContext ctx = NULL;
429 XSetWindowAttributes attr;
431 int attribList[] = {GLX_RGBA, GLX_DOUBLEBUFFER, None};
433 attr.override_redirect = True;
434 attr.colormap = None;
435 attr.border_pixel = 0;
437 vis = pglXChooseVisual(gdi_display, screen, attribList);
440 WORD old_fs = wine_get_fs();
441 /* Create a GLX Context. Without one we can't query GL information */
442 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
443 if (wine_get_fs() != old_fs)
445 wine_set_fs( old_fs );
446 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
447 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
451 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
456 root = RootWindow( gdi_display, vis->screen );
457 if (vis->visual != DefaultVisual( gdi_display, vis->screen ))
458 attr.colormap = XCreateColormap( gdi_display, root, vis->visual, AllocNone );
459 if ((win = XCreateWindow( gdi_display, root, -1, -1, 1, 1, 0, vis->depth, InputOutput,
460 vis->visual, CWBorderPixel | CWOverrideRedirect | CWColormap, &attr )))
461 XMapWindow( gdi_display, win );
465 if(pglXMakeCurrent(gdi_display, win, ctx) == 0)
467 ERR_(winediag)( "Unable to activate OpenGL context, most likely your OpenGL drivers haven't been installed correctly\n" );
470 gl_renderer = (const char *)opengl_funcs.gl.p_glGetString(GL_RENDERER);
471 WineGLInfo.glVersion = (const char *) opengl_funcs.gl.p_glGetString(GL_VERSION);
472 str = (const char *) opengl_funcs.gl.p_glGetString(GL_EXTENSIONS);
473 WineGLInfo.glExtensions = HeapAlloc(GetProcessHeap(), 0, strlen(str)+1);
474 strcpy(WineGLInfo.glExtensions, str);
476 /* Get the common GLX version supported by GLX client and server ( major/minor) */
477 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
479 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
480 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
481 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
483 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
484 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
485 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
487 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
488 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
490 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
491 TRACE("GL renderer : %s.\n", gl_renderer);
492 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
493 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
494 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
495 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
496 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
497 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
499 if(!WineGLInfo.glxDirect)
501 int fd = ConnectionNumber(gdi_display);
502 struct sockaddr_un uaddr;
503 unsigned int uaddrlen = sizeof(struct sockaddr_un);
505 /* In general indirect rendering on a local X11 server indicates a driver problem.
506 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
508 if(!getsockname(fd, (struct sockaddr *)&uaddr, &uaddrlen) && uaddr.sun_family == AF_UNIX)
509 ERR_(winediag)("Direct rendering is disabled, most likely your OpenGL drivers "
510 "haven't been installed correctly (using GL renderer %s, version %s).\n",
511 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
515 /* In general you would expect that if direct rendering is returned, that you receive hardware
516 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
517 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
518 * software rendering, it shows direct rendering.
520 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
521 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
522 * it shows 'Mesa X11'.
524 if(!strcmp(gl_renderer, "Software Rasterizer") || !strcmp(gl_renderer, "Mesa X11"))
525 ERR_(winediag)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL "
526 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
527 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
534 pglXMakeCurrent(gdi_display, None, NULL);
535 pglXDestroyContext(gdi_display, ctx);
537 if (win != root) XDestroyWindow( gdi_display, win );
538 if (attr.colormap) XFreeColormap( gdi_display, attr.colormap );
539 if (!ret) ERR(" couldn't initialize OpenGL, expect problems\n");
543 static BOOL has_opengl(void)
545 static int init_done;
546 static void *opengl_handle;
549 int error_base, event_base;
552 if (init_done) return (opengl_handle != NULL);
555 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
556 and include all dependencies */
557 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, buffer, sizeof(buffer));
558 if (opengl_handle == NULL)
560 ERR( "Failed to load libGL: %s\n", buffer );
561 ERR( "OpenGL support is disabled.\n");
565 for (i = 0; i < sizeof(opengl_func_names)/sizeof(opengl_func_names[0]); i++)
567 if (!(((void **)&opengl_funcs.gl)[i] = wine_dlsym( opengl_handle, opengl_func_names[i], NULL, 0 )))
569 ERR( "%s not found in libGL, disabling OpenGL.\n", opengl_func_names[i] );
574 /* redirect some standard OpenGL functions */
575 #define REDIRECT(func) \
576 do { p##func = opengl_funcs.gl.p_##func; opengl_funcs.gl.p_##func = w##func; } while(0)
577 REDIRECT( glFinish );
581 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
582 if (pglXGetProcAddressARB == NULL) {
583 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
587 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
589 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
594 LOAD_FUNCPTR(glXChooseVisual);
595 LOAD_FUNCPTR(glXCopyContext);
596 LOAD_FUNCPTR(glXCreateContext);
597 LOAD_FUNCPTR(glXCreateGLXPixmap);
598 LOAD_FUNCPTR(glXGetCurrentContext);
599 LOAD_FUNCPTR(glXGetCurrentDrawable);
600 LOAD_FUNCPTR(glXDestroyContext);
601 LOAD_FUNCPTR(glXDestroyGLXPixmap);
602 LOAD_FUNCPTR(glXGetConfig);
603 LOAD_FUNCPTR(glXIsDirect);
604 LOAD_FUNCPTR(glXMakeCurrent);
605 LOAD_FUNCPTR(glXSwapBuffers);
606 LOAD_FUNCPTR(glXQueryExtension);
607 LOAD_FUNCPTR(glXQueryVersion);
610 LOAD_FUNCPTR(glXGetClientString);
611 LOAD_FUNCPTR(glXQueryExtensionsString);
612 LOAD_FUNCPTR(glXQueryServerString);
615 LOAD_FUNCPTR(glXCreatePbuffer);
616 LOAD_FUNCPTR(glXCreateNewContext);
617 LOAD_FUNCPTR(glXDestroyPbuffer);
618 LOAD_FUNCPTR(glXMakeContextCurrent);
619 LOAD_FUNCPTR(glXGetFBConfigs);
622 /* It doesn't matter if these fail. They'll only be used if the driver reports
623 the associated extension is available (and if a driver reports the extension
624 is available but fails to provide the functions, it's quite broken) */
625 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
626 /* ARB GLX Extension */
627 LOAD_FUNCPTR(glXCreateContextAttribsARB);
628 /* SGI GLX Extension */
629 LOAD_FUNCPTR(glXSwapIntervalSGI);
630 /* NV GLX Extension */
631 LOAD_FUNCPTR(glXAllocateMemoryNV);
632 LOAD_FUNCPTR(glXFreeMemoryNV);
635 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed;
637 if (pglXQueryExtension(gdi_display, &error_base, &event_base)) {
638 TRACE("GLX is up and running error_base = %d\n", error_base);
640 ERR( "GLX extension is missing, disabling OpenGL.\n" );
643 gl_hwnd_context = XUniqueContext();
644 gl_pbuffer_context = XUniqueContext();
646 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
647 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
650 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
651 * depends on the reported GLX client / server version and on the client / server extension list.
652 * Those don't have to be the same.
654 * In general the server GLX information lists the capabilities in case of indirect rendering.
655 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
656 * available and in that case the client GLX informat can be used.
657 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
658 * in the GLX version/extension list. When a program does this it works for certain for both
659 * direct and indirect rendering.
661 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
662 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
663 * extension list which causes this extension not to be listed. (Wine requires this extension).
664 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
665 * pbuffers is around.
667 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
668 * the ATI drivers and from then on use GLX client information for them.
671 if(glxRequireVersion(3)) {
672 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
673 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
674 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
675 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
676 } else if (has_extension( WineGLInfo.glxExtensions, "GLX_SGIX_fbconfig")) {
677 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
678 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
679 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
681 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
682 * enable this function when the Xserver understand GLX 1.3 or newer
684 pglXQueryDrawable = NULL;
685 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
686 TRACE("Overriding ATI GLX capabilities!\n");
687 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
688 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
689 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
690 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
692 /* Use client GLX information in case of the ATI drivers. We override the
693 * capabilities over here and not somewhere else as ATI might better their
694 * life in the future. In case they release proper drivers this block of
695 * code won't be called. */
696 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
698 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
701 if (has_extension( WineGLInfo.glxExtensions, "GLX_MESA_copy_sub_buffer")) {
702 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
705 X11DRV_WineGL_LoadExtensions();
706 init_pixel_formats( gdi_display );
710 wine_dlclose(opengl_handle, NULL, 0);
711 opengl_handle = NULL;
715 static int describeContext( struct wgl_context *ctx ) {
718 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
719 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
720 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
721 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
722 TRACE(" - VISUAL_ID 0x%x\n", tmp);
727 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, struct wgl_pbuffer* pbuf) {
732 int nvfloatattrib = GLX_DONT_CARE;
733 int pixelattrib = GLX_DONT_CARE;
735 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
736 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
737 while (iWGLAttr && 0 != iWGLAttr[cur]) {
738 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
740 switch (iWGLAttr[cur]) {
741 case WGL_AUX_BUFFERS_ARB:
742 pop = iWGLAttr[++cur];
743 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
744 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
746 case WGL_COLOR_BITS_ARB:
747 pop = iWGLAttr[++cur];
748 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
749 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
751 case WGL_BLUE_BITS_ARB:
752 pop = iWGLAttr[++cur];
753 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
754 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
756 case WGL_RED_BITS_ARB:
757 pop = iWGLAttr[++cur];
758 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
759 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
761 case WGL_GREEN_BITS_ARB:
762 pop = iWGLAttr[++cur];
763 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
764 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
766 case WGL_ALPHA_BITS_ARB:
767 pop = iWGLAttr[++cur];
768 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
769 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
771 case WGL_DEPTH_BITS_ARB:
772 pop = iWGLAttr[++cur];
773 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
774 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
776 case WGL_STENCIL_BITS_ARB:
777 pop = iWGLAttr[++cur];
778 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
779 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
781 case WGL_DOUBLE_BUFFER_ARB:
782 pop = iWGLAttr[++cur];
783 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
784 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
787 pop = iWGLAttr[++cur];
788 PUSH2(oGLXAttr, GLX_STEREO, pop);
789 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur, pop);
792 case WGL_PIXEL_TYPE_ARB:
793 pop = iWGLAttr[++cur];
794 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
796 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
797 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
798 /* 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 */
799 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
800 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT: pixelattrib = GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT; break ;
802 ERR("unexpected PixelType(%x)\n", pop);
807 case WGL_SUPPORT_GDI_ARB:
808 /* This flag is set in a pixel format */
809 pop = iWGLAttr[++cur];
810 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
813 case WGL_DRAW_TO_BITMAP_ARB:
814 /* This flag is set in a pixel format */
815 pop = iWGLAttr[++cur];
816 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
819 case WGL_DRAW_TO_WINDOW_ARB:
820 pop = iWGLAttr[++cur];
821 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
822 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
824 drawattrib |= GLX_WINDOW_BIT;
828 case WGL_DRAW_TO_PBUFFER_ARB:
829 pop = iWGLAttr[++cur];
830 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
831 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
833 drawattrib |= GLX_PBUFFER_BIT;
837 case WGL_ACCELERATION_ARB:
838 /* This flag is set in a pixel format */
839 pop = iWGLAttr[++cur];
840 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur, pop);
843 case WGL_SUPPORT_OPENGL_ARB:
844 pop = iWGLAttr[++cur];
845 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
846 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
849 case WGL_SWAP_METHOD_ARB:
850 pop = iWGLAttr[++cur];
851 /* For now we ignore this and just return SWAP_EXCHANGE */
852 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur, pop);
855 case WGL_PBUFFER_LARGEST_ARB:
856 pop = iWGLAttr[++cur];
857 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
858 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
861 case WGL_SAMPLE_BUFFERS_ARB:
862 pop = iWGLAttr[++cur];
863 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
864 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
867 case WGL_SAMPLES_ARB:
868 pop = iWGLAttr[++cur];
869 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
870 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
873 case WGL_TEXTURE_FORMAT_ARB:
874 case WGL_TEXTURE_TARGET_ARB:
875 case WGL_MIPMAP_TEXTURE_ARB:
876 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
877 pop = iWGLAttr[++cur];
879 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
881 if (!use_render_texture_emulation) {
882 if (WGL_NO_TEXTURE_ARB != pop) {
883 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
884 return -1; /** error: don't support it */
886 drawattrib |= GLX_PBUFFER_BIT;
890 case WGL_FLOAT_COMPONENTS_NV:
891 nvfloatattrib = iWGLAttr[++cur];
892 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
894 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
895 case WGL_BIND_TO_TEXTURE_RGB_ARB:
896 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
897 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
898 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
899 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
900 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
901 pop = iWGLAttr[++cur];
902 /** cannot be converted, see direct handling on
903 * - wglGetPixelFormatAttribivARB
904 * TODO: wglChoosePixelFormat
907 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
908 pop = iWGLAttr[++cur];
909 PUSH2(oGLXAttr, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, pop);
910 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur, pop);
913 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
914 pop = iWGLAttr[++cur];
915 PUSH2(oGLXAttr, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT, pop);
916 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur, pop);
919 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
925 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
926 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
927 * pixmap and pbuffer formats appear as well. */
928 if (!drawattrib) drawattrib = GLX_DONT_CARE;
929 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
930 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
932 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
933 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
934 * GLX_DONT_CARE unless it is overridden. */
935 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
936 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
938 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
939 if (has_extension(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
940 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
941 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
947 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
949 int render_type=0, render_type_bit;
950 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
951 switch(render_type_bit)
954 render_type = GLX_RGBA_TYPE;
956 case GLX_COLOR_INDEX_BIT:
957 render_type = GLX_COLOR_INDEX_TYPE;
959 case GLX_RGBA_FLOAT_BIT:
960 render_type = GLX_RGBA_FLOAT_TYPE;
962 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT:
963 render_type = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
966 ERR("Unknown render_type: %x\n", render_type_bit);
971 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
972 static BOOL check_fbconfig_bitmap_capability(Display *display, GLXFBConfig fbconfig)
975 pglXGetFBConfigAttrib(display, fbconfig, GLX_DOUBLEBUFFER, &dbuf);
976 pglXGetFBConfigAttrib(gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &value);
978 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
979 * the GLX_PIXMAP_BIT set. */
980 return !dbuf && (value & GLX_PIXMAP_BIT);
983 static void init_pixel_formats( Display *display )
985 struct wgl_pixel_format *list;
986 int size = 0, onscreen_size = 0;
987 int fmt_id, nCfgs, i, run, bmp_formats;
989 XVisualInfo *visinfo;
991 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
992 if (NULL == cfgs || 0 == nCfgs) {
993 if(cfgs != NULL) XFree(cfgs);
994 ERR("glXChooseFBConfig returns NULL\n");
998 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
999 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
1000 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
1001 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
1003 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
1005 for(i=0, bmp_formats=0; i<nCfgs; i++)
1007 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
1010 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats);
1012 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nCfgs + bmp_formats) * sizeof(*list));
1014 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
1015 * Do this as GLX doesn't guarantee that the list is sorted */
1016 for(run=0; run < 2; run++)
1018 for(i=0; i<nCfgs; i++) {
1019 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
1020 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
1022 /* The first run we only add onscreen formats (ones which have an associated X Visual).
1023 * The second run we only set offscreen formats. */
1026 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
1027 * The contents is copied to the destination using XCopyArea. For the copying to work
1028 * the depth of the source and destination window should be the same. In general this should
1029 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
1030 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
1031 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
1032 * list formats with the same depth. */
1033 if(visinfo->depth != default_visual.depth)
1039 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1040 list[size].fbconfig = cfgs[i];
1041 list[size].fmt_id = fmt_id;
1042 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1043 list[size].dwFlags = 0;
1047 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
1048 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
1050 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1051 list[size].fbconfig = cfgs[i];
1052 list[size].fmt_id = fmt_id;
1053 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1054 list[size].dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_GENERIC_FORMAT;
1058 } else if(run && !visinfo) {
1059 int window_drawable=0;
1060 pglXGetFBConfigAttrib(gdi_display, cfgs[i], GLX_DRAWABLE_TYPE, &window_drawable);
1062 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
1063 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1064 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1065 * likely make our child window opengl rendering more complicated since likely you can't use
1066 * XCopyArea on a GLX Window.
1067 * For now ignore fbconfigs which are window drawable but lack a visual. */
1068 if(window_drawable & GLX_WINDOW_BIT)
1070 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id);
1074 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1075 list[size].fbconfig = cfgs[i];
1076 list[size].fmt_id = fmt_id;
1077 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1078 list[size].dwFlags = 0;
1082 if (visinfo) XFree(visinfo);
1088 pixel_formats = list;
1089 nb_pixel_formats = size;
1090 nb_onscreen_formats = onscreen_size;
1093 static inline BOOL is_valid_pixel_format( int format )
1095 return format > 0 && format <= nb_pixel_formats;
1098 static inline BOOL is_onscreen_pixel_format( int format )
1100 return format > 0 && format <= nb_onscreen_formats;
1103 static inline int pixel_format_index( const struct wgl_pixel_format *format )
1105 return format - pixel_formats + 1;
1108 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1109 * In our WGL implementation we only support a subset of these formats namely the format of
1110 * Wine's main visual and offscreen formats (if they are available).
1111 * This function converts a WGL format to its corresponding GLX one.
1113 static const struct wgl_pixel_format *get_pixel_format(Display *display, int iPixelFormat, BOOL AllowOffscreen)
1115 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1116 * iPixelFormat in case of probing the number of pixelformats.
1118 if (is_valid_pixel_format( iPixelFormat ) &&
1119 (is_onscreen_pixel_format( iPixelFormat ) || AllowOffscreen)) {
1120 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n",
1121 pixel_formats[iPixelFormat-1].fmt_id, iPixelFormat);
1122 return &pixel_formats[iPixelFormat-1];
1127 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1128 static void mark_drawable_dirty(Drawable old, Drawable new)
1130 struct wgl_context *ctx;
1132 LIST_FOR_EACH_ENTRY( ctx, &context_list, struct wgl_context, entry )
1134 if (old == ctx->drawables[0]) {
1135 ctx->drawables[0] = new;
1136 ctx->refresh_drawables = TRUE;
1138 if (old == ctx->drawables[1]) {
1139 ctx->drawables[1] = new;
1140 ctx->refresh_drawables = TRUE;
1145 /* Given the current context, make sure its drawable is sync'd */
1146 static inline void sync_context(struct wgl_context *context)
1148 if (context->refresh_drawables) {
1149 if (glxRequireVersion(3))
1150 pglXMakeContextCurrent(gdi_display, context->drawables[0],
1151 context->drawables[1], context->ctx);
1153 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
1154 context->refresh_drawables = FALSE;
1158 static struct gl_drawable *get_gl_drawable( HWND hwnd, HDC hdc )
1160 struct gl_drawable *gl;
1162 EnterCriticalSection( &context_section );
1163 if (hwnd && !XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl )) return gl;
1164 if (hdc && !XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl )) return gl;
1165 LeaveCriticalSection( &context_section );
1169 static void release_gl_drawable( struct gl_drawable *gl )
1171 if (gl) LeaveCriticalSection( &context_section );
1174 static GLXContext create_glxcontext(Display *display, struct wgl_context *context, GLXContext shareList)
1178 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1179 BOOL indirect = !(context->fmt->dwFlags & PFD_DRAW_TO_BITMAP);
1181 if(context->gl3_context)
1183 if(context->numAttribs)
1184 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, context->attribList);
1186 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, NULL);
1188 else if(context->vis)
1189 ctx = pglXCreateContext(gdi_display, context->vis, shareList, indirect);
1190 else /* Create a GLX Context for a pbuffer */
1191 ctx = pglXCreateNewContext(gdi_display, context->fmt->fbconfig, context->fmt->render_type, shareList, TRUE);
1197 /***********************************************************************
1200 static void free_gl_drawable( struct gl_drawable *gl )
1204 case DC_GL_CHILD_WIN:
1205 XDestroyWindow( gdi_display, gl->drawable );
1206 XFreeColormap( gdi_display, gl->colormap );
1208 case DC_GL_PIXMAP_WIN:
1209 pglXDestroyGLXPixmap( gdi_display, gl->drawable );
1210 XFreePixmap( gdi_display, gl->pixmap );
1215 if (gl->visual) XFree( gl->visual );
1216 HeapFree( GetProcessHeap(), 0, gl );
1220 /***********************************************************************
1221 * create_gl_drawable
1223 static BOOL create_gl_drawable( HWND hwnd, HWND parent, struct gl_drawable *gl )
1227 if (GetAncestor( hwnd, GA_PARENT ) == GetDesktopWindow()) /* top-level window */
1229 struct x11drv_win_data *data = get_win_data( hwnd );
1233 gl->type = DC_GL_WINDOW;
1234 gl->drawable = create_client_window( data, gl->visual );
1235 release_win_data( data );
1238 #ifdef SONAME_LIBXCOMPOSITE
1239 else if(usexcomposite)
1241 static Window dummy_parent;
1242 XSetWindowAttributes attrib;
1244 attrib.override_redirect = True;
1247 dummy_parent = XCreateWindow( gdi_display, root_window, -1, -1, 1, 1, 0, default_visual.depth,
1248 InputOutput, default_visual.visual, CWOverrideRedirect, &attrib );
1249 XMapWindow( gdi_display, dummy_parent );
1251 gl->colormap = XCreateColormap(gdi_display, dummy_parent, gl->visual->visual,
1252 (gl->visual->class == PseudoColor ||
1253 gl->visual->class == GrayScale ||
1254 gl->visual->class == DirectColor) ?
1255 AllocAll : AllocNone);
1256 attrib.colormap = gl->colormap;
1257 XInstallColormap(gdi_display, attrib.colormap);
1259 gl->type = DC_GL_CHILD_WIN;
1260 gl->drawable = XCreateWindow( gdi_display, dummy_parent, 0, 0,
1261 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top,
1262 0, gl->visual->depth, InputOutput, gl->visual->visual,
1263 CWColormap | CWOverrideRedirect, &attrib );
1266 pXCompositeRedirectWindow(gdi_display, gl->drawable, CompositeRedirectManual);
1267 XMapWindow(gdi_display, gl->drawable);
1269 else XFreeColormap( gdi_display, gl->colormap );
1274 WARN("XComposite is not available, using GLXPixmap hack\n");
1276 gl->type = DC_GL_PIXMAP_WIN;
1277 gl->pixmap = XCreatePixmap( gdi_display, root_window,
1278 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top,
1279 gl->visual->depth );
1282 gl->drawable = pglXCreateGLXPixmap( gdi_display, gl->visual, gl->pixmap );
1283 if (!gl->drawable) XFreePixmap( gdi_display, gl->pixmap );
1287 return gl->drawable != 0;
1291 /***********************************************************************
1294 static BOOL set_win_format( HWND hwnd, const struct wgl_pixel_format *format )
1296 HWND parent = GetAncestor( hwnd, GA_PARENT );
1297 struct gl_drawable *gl, *prev;
1299 gl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*gl) );
1300 gl->format = format;
1301 gl->visual = pglXGetVisualFromFBConfig( gdi_display, format->fbconfig );
1304 HeapFree( GetProcessHeap(), 0, gl );
1308 GetClientRect( hwnd, &gl->rect );
1309 gl->rect.right = min( max( 1, gl->rect.right ), 65535 );
1310 gl->rect.bottom = min( max( 1, gl->rect.bottom ), 65535 );
1312 if (!create_gl_drawable( hwnd, parent, gl ))
1314 XFree( gl->visual );
1315 HeapFree( GetProcessHeap(), 0, gl );
1319 TRACE("created GL drawable %lx for win %p format %x\n", gl->drawable, hwnd, format->fmt_id );
1321 XFlush( gdi_display );
1323 EnterCriticalSection( &context_section );
1324 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&prev ))
1325 free_gl_drawable( prev );
1326 XSaveContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char *)gl );
1327 LeaveCriticalSection( &context_section );
1329 __wine_set_pixel_format( hwnd, pixel_format_index( format ));
1333 /***********************************************************************
1336 void sync_gl_drawable( HWND hwnd, const RECT *visible_rect, const RECT *client_rect )
1338 struct gl_drawable *gl;
1342 XWindowChanges changes;
1344 changes.width = min( max( 1, client_rect->right - client_rect->left ), 65535 );
1345 changes.height = min( max( 1, client_rect->bottom - client_rect->top ), 65535 );
1347 if (!(gl = get_gl_drawable( hwnd, 0 ))) return;
1349 if (changes.width != gl->rect.right - gl->rect.left) mask |= CWWidth;
1350 if (changes.height != gl->rect.bottom - gl->rect.top) mask |= CWHeight;
1352 TRACE( "setting drawable %lx pos %d,%d,%dx%d\n",
1353 gl->drawable, changes.x, changes.y, changes.width, changes.height );
1357 case DC_GL_CHILD_WIN:
1358 if (mask) XConfigureWindow( gdi_display, gl->drawable, mask, &changes );
1360 case DC_GL_PIXMAP_WIN:
1362 pix = XCreatePixmap(gdi_display, root_window, changes.width, changes.height, gl->visual->depth);
1363 if (!pix) goto done;
1364 glxp = pglXCreateGLXPixmap(gdi_display, gl->visual, pix);
1367 XFreePixmap(gdi_display, pix);
1370 mark_drawable_dirty(gl->drawable, glxp);
1371 XFlush( gdi_display );
1373 XFreePixmap(gdi_display, gl->pixmap);
1374 pglXDestroyGLXPixmap(gdi_display, gl->drawable);
1375 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp, gl->drawable );
1378 gl->drawable = glxp;
1383 SetRect( &gl->rect, changes.x, changes.y, changes.x + changes.width, changes.y + changes.height );
1385 release_gl_drawable( gl );
1389 /***********************************************************************
1390 * set_gl_drawable_parent
1392 void set_gl_drawable_parent( HWND hwnd, HWND parent )
1394 struct gl_drawable *gl;
1395 Drawable old_drawable;
1397 if (!(gl = get_gl_drawable( hwnd, 0 ))) return;
1399 TRACE( "setting drawable %lx parent %p\n", gl->drawable, parent );
1401 old_drawable = gl->drawable;
1406 case DC_GL_CHILD_WIN:
1407 if (parent != GetDesktopWindow()) goto done;
1408 XDestroyWindow( gdi_display, gl->drawable );
1409 XFreeColormap( gdi_display, gl->colormap );
1411 case DC_GL_PIXMAP_WIN:
1412 if (parent != GetDesktopWindow()) goto done;
1413 pglXDestroyGLXPixmap( gdi_display, gl->drawable );
1414 XFreePixmap( gdi_display, gl->pixmap );
1420 if (!create_gl_drawable( hwnd, parent, gl ))
1422 XDeleteContext( gdi_display, (XID)hwnd, gl_hwnd_context );
1423 release_gl_drawable( gl );
1424 XFree( gl->visual );
1425 HeapFree( GetProcessHeap(), 0, gl );
1426 __wine_set_pixel_format( hwnd, 0 );
1429 mark_drawable_dirty( old_drawable, gl->drawable );
1432 release_gl_drawable( gl );
1437 /***********************************************************************
1438 * destroy_gl_drawable
1440 void destroy_gl_drawable( HWND hwnd )
1442 struct gl_drawable *gl;
1444 EnterCriticalSection( &context_section );
1445 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl ))
1447 XDeleteContext( gdi_display, (XID)hwnd, gl_hwnd_context );
1448 free_gl_drawable( gl );
1450 LeaveCriticalSection( &context_section );
1455 * glxdrv_DescribePixelFormat
1457 * Get the pixel-format descriptor associated to the given id
1459 static int glxdrv_wglDescribePixelFormat( HDC hdc, int iPixelFormat,
1460 UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd)
1462 /*XVisualInfo *vis;*/
1465 const struct wgl_pixel_format *fmt;
1467 if (!has_opengl()) return 0;
1469 TRACE("(%p,%d,%d,%p)\n", hdc, iPixelFormat, nBytes, ppfd);
1471 if (!ppfd) return nb_onscreen_formats;
1473 /* 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 */
1474 fmt = get_pixel_format(gdi_display, iPixelFormat, FALSE /* Offscreen */);
1476 WARN("unexpected format %d\n", iPixelFormat);
1480 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1481 ERR("Wrong structure size !\n");
1482 /* Should set error */
1486 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1487 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1490 /* These flags are always the same... */
1491 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1492 /* Now the flags extracted from the Visual */
1494 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1495 if(value & GLX_WINDOW_BIT)
1496 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1498 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1499 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1500 * 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
1501 * offered the GDI bit either. */
1502 ppfd->dwFlags |= fmt->dwFlags & (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI);
1504 /* PFD_GENERIC_FORMAT - gdi software rendering
1505 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1506 * none set - full hardware accelerated by a ICD
1508 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1509 ppfd->dwFlags |= fmt->dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED);
1511 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1513 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1514 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1516 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1519 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1520 if (value & GLX_RGBA_BIT)
1521 ppfd->iPixelType = PFD_TYPE_RGBA;
1523 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1526 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1527 ppfd->cColorBits = value;
1529 /* Red, green, blue and alpha bits / shifts */
1530 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1531 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1532 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1533 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1534 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1536 ppfd->cRedBits = rb;
1537 ppfd->cRedShift = gb + bb + ab;
1538 ppfd->cBlueBits = bb;
1539 ppfd->cBlueShift = ab;
1540 ppfd->cGreenBits = gb;
1541 ppfd->cGreenShift = bb + ab;
1542 ppfd->cAlphaBits = ab;
1543 ppfd->cAlphaShift = 0;
1546 ppfd->cRedShift = 0;
1547 ppfd->cBlueBits = 0;
1548 ppfd->cBlueShift = 0;
1549 ppfd->cGreenBits = 0;
1550 ppfd->cGreenShift = 0;
1551 ppfd->cAlphaBits = 0;
1552 ppfd->cAlphaShift = 0;
1555 /* Accum RGBA bits */
1556 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1557 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1558 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1559 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1561 ppfd->cAccumBits = rb+gb+bb+ab;
1562 ppfd->cAccumRedBits = rb;
1563 ppfd->cAccumGreenBits = gb;
1564 ppfd->cAccumBlueBits = bb;
1565 ppfd->cAccumAlphaBits = ab;
1568 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1569 ppfd->cAuxBuffers = value;
1572 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1573 ppfd->cDepthBits = value;
1576 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1577 ppfd->cStencilBits = value;
1579 ppfd->iLayerType = PFD_MAIN_PLANE;
1581 if (TRACE_ON(wgl)) {
1582 dump_PIXELFORMATDESCRIPTOR(ppfd);
1585 return nb_onscreen_formats;
1588 /***********************************************************************
1589 * glxdrv_wglGetPixelFormat
1591 static int glxdrv_wglGetPixelFormat( HDC hdc )
1593 struct gl_drawable *gl;
1596 if ((gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1598 ret = pixel_format_index( gl->format );
1599 /* Offscreen formats can't be used with traditional WGL calls.
1600 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1601 if (!is_onscreen_pixel_format( ret )) ret = 1;
1602 release_gl_drawable( gl );
1604 TRACE( "%p -> %d\n", hdc, ret );
1608 /***********************************************************************
1609 * glxdrv_wglSetPixelFormat
1611 static BOOL glxdrv_wglSetPixelFormat( HDC hdc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd )
1613 const struct wgl_pixel_format *fmt;
1615 struct gl_drawable *gl;
1616 HWND hwnd = WindowFromDC( hdc );
1618 TRACE("(%p,%d,%p)\n", hdc, iPixelFormat, ppfd);
1620 if (!hwnd || hwnd == GetDesktopWindow())
1622 WARN( "not a proper window DC %p/%p\n", hdc, hwnd );
1626 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1627 fmt = get_pixel_format(gdi_display, iPixelFormat, FALSE /* Offscreen */);
1629 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1633 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1634 if (!(value & GLX_WINDOW_BIT))
1636 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1640 if ((gl = get_gl_drawable( hwnd, hdc )))
1642 int prev = pixel_format_index( gl->format );
1643 release_gl_drawable( gl );
1644 return prev == iPixelFormat; /* cannot change it if already set */
1647 if (TRACE_ON(wgl)) {
1650 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1652 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1654 TRACE(" FBConfig have :\n");
1655 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1656 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1657 TRACE(" - VISUAL_ID 0x%x\n", value);
1658 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1659 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1663 return set_win_format( hwnd, fmt );
1666 /***********************************************************************
1667 * glxdrv_wglCopyContext
1669 static BOOL glxdrv_wglCopyContext(struct wgl_context *src, struct wgl_context *dst, UINT mask)
1671 TRACE("%p -> %p mask %#x\n", src, dst, mask);
1673 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1675 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1679 /***********************************************************************
1680 * glxdrv_wglCreateContext
1682 static struct wgl_context *glxdrv_wglCreateContext( HDC hdc )
1684 struct wgl_context *ret = NULL;
1685 struct gl_drawable *gl;
1687 if (!(gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1689 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1693 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret))))
1696 ret->fmt = gl->format;
1697 ret->vis = pglXGetVisualFromFBConfig(gdi_display, gl->format->fbconfig);
1698 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1699 list_add_head( &context_list, &ret->entry );
1701 release_gl_drawable( gl );
1702 TRACE( "%p -> %p\n", hdc, ret );
1706 /***********************************************************************
1707 * glxdrv_wglDeleteContext
1709 static void glxdrv_wglDeleteContext(struct wgl_context *ctx)
1711 TRACE("(%p)\n", ctx);
1713 EnterCriticalSection( &context_section );
1714 list_remove( &ctx->entry );
1715 LeaveCriticalSection( &context_section );
1717 if (ctx->ctx) pglXDestroyContext( gdi_display, ctx->ctx );
1718 if (ctx->vis) XFree( ctx->vis );
1719 HeapFree( GetProcessHeap(), 0, ctx );
1722 /***********************************************************************
1723 * glxdrv_wglGetProcAddress
1725 static PROC glxdrv_wglGetProcAddress(LPCSTR lpszProc)
1727 if (!strncmp(lpszProc, "wgl", 3)) return NULL;
1728 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1731 /***********************************************************************
1732 * glxdrv_wglMakeCurrent
1734 static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx)
1737 struct gl_drawable *gl;
1739 TRACE("(%p,%p)\n", hdc, ctx);
1743 pglXMakeCurrent(gdi_display, None, NULL);
1744 NtCurrentTeb()->glContext = NULL;
1748 if ((gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1750 if (ctx->fmt != gl->format)
1752 WARN( "mismatched pixel format hdc %p %p ctx %p %p\n", hdc, gl->format, ctx, ctx->fmt );
1753 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1757 if (TRACE_ON(wgl)) {
1758 describeContext(ctx);
1759 TRACE("hdc %p drawable %lx fmt %p ctx %p\n", hdc, gl->drawable, gl->format, ctx->ctx );
1762 ret = pglXMakeCurrent(gdi_display, gl->drawable, ctx->ctx);
1765 NtCurrentTeb()->glContext = ctx;
1766 ctx->has_been_current = TRUE;
1768 ctx->drawables[0] = gl->drawable;
1769 ctx->drawables[1] = gl->drawable;
1770 ctx->refresh_drawables = FALSE;
1774 SetLastError( ERROR_INVALID_HANDLE );
1777 release_gl_drawable( gl );
1778 TRACE( "%p,%p returning %d\n", hdc, ctx, ret );
1782 /***********************************************************************
1783 * X11DRV_wglMakeContextCurrentARB
1785 static BOOL X11DRV_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *ctx )
1788 struct gl_drawable *draw_gl, *read_gl = NULL;
1790 TRACE("(%p,%p,%p)\n", draw_hdc, read_hdc, ctx);
1794 pglXMakeCurrent(gdi_display, None, NULL);
1795 NtCurrentTeb()->glContext = NULL;
1799 if (!pglXMakeContextCurrent) return FALSE;
1801 if ((draw_gl = get_gl_drawable( WindowFromDC( draw_hdc ), draw_hdc )))
1803 read_gl = get_gl_drawable( WindowFromDC( read_hdc ), read_hdc );
1804 ret = pglXMakeContextCurrent(gdi_display, draw_gl->drawable,
1805 read_gl ? read_gl->drawable : 0, ctx->ctx);
1808 ctx->has_been_current = TRUE;
1809 ctx->hdc = draw_hdc;
1810 ctx->drawables[0] = draw_gl->drawable;
1811 ctx->drawables[1] = read_gl ? read_gl->drawable : 0;
1812 ctx->refresh_drawables = FALSE;
1813 NtCurrentTeb()->glContext = ctx;
1817 SetLastError( ERROR_INVALID_HANDLE );
1819 release_gl_drawable( read_gl );
1820 release_gl_drawable( draw_gl );
1821 TRACE( "%p,%p,%p returning %d\n", draw_hdc, read_hdc, ctx, ret );
1825 /***********************************************************************
1826 * glxdrv_wglShareLists
1828 static BOOL glxdrv_wglShareLists(struct wgl_context *org, struct wgl_context *dest)
1830 TRACE("(%p, %p)\n", org, dest);
1832 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1833 * at context creation time but in case of WGL it is done using wglShareLists.
1834 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1835 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1836 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1837 * so there delaying context creation doesn't work.
1839 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1840 * and when a program requests sharing we recreate the destination context if it hasn't been made
1841 * current or when it hasn't shared display lists before.
1844 if((org->has_been_current && dest->has_been_current) || dest->has_been_current)
1846 ERR("Could not share display lists, one of the contexts has been current already !\n");
1849 else if(dest->sharing)
1851 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1856 describeContext(org);
1857 describeContext(dest);
1859 /* Re-create the GLX context and share display lists */
1860 pglXDestroyContext(gdi_display, dest->ctx);
1861 dest->ctx = create_glxcontext(gdi_display, dest, org->ctx);
1862 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1864 org->sharing = TRUE;
1865 dest->sharing = TRUE;
1871 static void wglFinish(void)
1873 struct x11drv_escape_flush_gl_drawable escape;
1874 struct gl_drawable *gl;
1875 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1877 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
1878 escape.gl_drawable = 0;
1880 if ((gl = get_gl_drawable( WindowFromDC( ctx->hdc ), 0 )))
1884 case DC_GL_PIXMAP_WIN: escape.gl_drawable = gl->pixmap; break;
1885 case DC_GL_CHILD_WIN: escape.gl_drawable = gl->drawable; break;
1889 release_gl_drawable( gl );
1893 if (escape.gl_drawable) ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1896 static void wglFlush(void)
1898 struct x11drv_escape_flush_gl_drawable escape;
1899 struct gl_drawable *gl;
1900 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1902 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
1903 escape.gl_drawable = 0;
1905 if ((gl = get_gl_drawable( WindowFromDC( ctx->hdc ), 0 )))
1909 case DC_GL_PIXMAP_WIN: escape.gl_drawable = gl->pixmap; break;
1910 case DC_GL_CHILD_WIN: escape.gl_drawable = gl->drawable; break;
1914 release_gl_drawable( gl );
1918 if (escape.gl_drawable) ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1921 /***********************************************************************
1922 * X11DRV_wglCreateContextAttribsARB
1924 static struct wgl_context *X11DRV_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *hShareContext,
1925 const int* attribList )
1927 struct wgl_context *ret = NULL;
1928 struct gl_drawable *gl;
1930 TRACE("(%p %p %p)\n", hdc, hShareContext, attribList);
1932 if (!(gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1934 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1938 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret))))
1941 ret->fmt = gl->format;
1942 ret->vis = NULL; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
1943 ret->gl3_context = TRUE;
1944 ret->numAttribs = 0;
1947 int *pContextAttribList = &ret->attribList[0];
1948 /* attribList consists of pairs {token, value] terminated with 0 */
1949 while(attribList[0] != 0)
1951 TRACE("%#x %#x\n", attribList[0], attribList[1]);
1952 switch(attribList[0])
1954 case WGL_CONTEXT_MAJOR_VERSION_ARB:
1955 pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
1956 pContextAttribList[1] = attribList[1];
1958 case WGL_CONTEXT_MINOR_VERSION_ARB:
1959 pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB;
1960 pContextAttribList[1] = attribList[1];
1962 case WGL_CONTEXT_LAYER_PLANE_ARB:
1964 case WGL_CONTEXT_FLAGS_ARB:
1965 pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB;
1966 pContextAttribList[1] = attribList[1];
1968 case WGL_CONTEXT_PROFILE_MASK_ARB:
1969 pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
1970 pContextAttribList[1] = attribList[1];
1973 ERR("Unhandled attribList pair: %#x %#x\n", attribList[0], attribList[1]);
1977 pContextAttribList += 2;
1981 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
1982 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1983 XSync(gdi_display, False);
1984 if (X11DRV_check_error() || !ret->ctx)
1986 /* In the future we should convert the GLX error to a win32 one here if needed */
1987 ERR("Context creation failed\n");
1988 HeapFree( GetProcessHeap(), 0, ret );
1991 else list_add_head( &context_list, &ret->entry );
1994 release_gl_drawable( gl );
1995 TRACE( "%p -> %p\n", hdc, ret );
2000 * X11DRV_wglGetExtensionsStringARB
2002 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2004 static const GLubyte *X11DRV_wglGetExtensionsStringARB(HDC hdc)
2006 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2007 return (const GLubyte *)WineGLInfo.wglExtensions;
2011 * X11DRV_wglCreatePbufferARB
2013 * WGL_ARB_pbuffer: wglCreatePbufferARB
2015 static struct wgl_pbuffer *X11DRV_wglCreatePbufferARB( HDC hdc, int iPixelFormat, int iWidth, int iHeight,
2016 const int *piAttribList )
2018 struct wgl_pbuffer* object = NULL;
2019 const struct wgl_pixel_format *fmt = NULL;
2023 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2025 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2026 fmt = get_pixel_format(gdi_display, iPixelFormat, TRUE /* Offscreen */);
2028 ERR("(%p): invalid pixel format %d\n", hdc, iPixelFormat);
2029 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2033 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2034 if (NULL == object) {
2035 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2038 object->width = iWidth;
2039 object->height = iHeight;
2042 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2043 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2044 while (piAttribList && 0 != *piAttribList) {
2046 switch (*piAttribList) {
2047 case WGL_PBUFFER_LARGEST_ARB: {
2049 attr_v = *piAttribList;
2050 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2051 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2055 case WGL_TEXTURE_FORMAT_ARB: {
2057 attr_v = *piAttribList;
2058 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2059 if (WGL_NO_TEXTURE_ARB == attr_v) {
2060 object->use_render_texture = 0;
2062 if (!use_render_texture_emulation) {
2063 SetLastError(ERROR_INVALID_DATA);
2067 case WGL_TEXTURE_RGB_ARB:
2068 object->use_render_texture = GL_RGB;
2069 object->texture_bpp = 3;
2070 object->texture_format = GL_RGB;
2071 object->texture_type = GL_UNSIGNED_BYTE;
2073 case WGL_TEXTURE_RGBA_ARB:
2074 object->use_render_texture = GL_RGBA;
2075 object->texture_bpp = 4;
2076 object->texture_format = GL_RGBA;
2077 object->texture_type = GL_UNSIGNED_BYTE;
2080 /* WGL_FLOAT_COMPONENTS_NV */
2081 case WGL_TEXTURE_FLOAT_R_NV:
2082 object->use_render_texture = GL_FLOAT_R_NV;
2083 object->texture_bpp = 4;
2084 object->texture_format = GL_RED;
2085 object->texture_type = GL_FLOAT;
2087 case WGL_TEXTURE_FLOAT_RG_NV:
2088 object->use_render_texture = GL_FLOAT_RG_NV;
2089 object->texture_bpp = 8;
2090 object->texture_format = GL_LUMINANCE_ALPHA;
2091 object->texture_type = GL_FLOAT;
2093 case WGL_TEXTURE_FLOAT_RGB_NV:
2094 object->use_render_texture = GL_FLOAT_RGB_NV;
2095 object->texture_bpp = 12;
2096 object->texture_format = GL_RGB;
2097 object->texture_type = GL_FLOAT;
2099 case WGL_TEXTURE_FLOAT_RGBA_NV:
2100 object->use_render_texture = GL_FLOAT_RGBA_NV;
2101 object->texture_bpp = 16;
2102 object->texture_format = GL_RGBA;
2103 object->texture_type = GL_FLOAT;
2106 ERR("Unknown texture format: %x\n", attr_v);
2107 SetLastError(ERROR_INVALID_DATA);
2114 case WGL_TEXTURE_TARGET_ARB: {
2116 attr_v = *piAttribList;
2117 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2118 if (WGL_NO_TEXTURE_ARB == attr_v) {
2119 object->texture_target = 0;
2121 if (!use_render_texture_emulation) {
2122 SetLastError(ERROR_INVALID_DATA);
2126 case WGL_TEXTURE_CUBE_MAP_ARB: {
2127 if (iWidth != iHeight) {
2128 SetLastError(ERROR_INVALID_DATA);
2131 object->texture_target = GL_TEXTURE_CUBE_MAP;
2132 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2135 case WGL_TEXTURE_1D_ARB: {
2137 SetLastError(ERROR_INVALID_DATA);
2140 object->texture_target = GL_TEXTURE_1D;
2141 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2144 case WGL_TEXTURE_2D_ARB: {
2145 object->texture_target = GL_TEXTURE_2D;
2146 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2149 case WGL_TEXTURE_RECTANGLE_NV: {
2150 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2151 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2155 ERR("Unknown texture target: %x\n", attr_v);
2156 SetLastError(ERROR_INVALID_DATA);
2163 case WGL_MIPMAP_TEXTURE_ARB: {
2165 attr_v = *piAttribList;
2166 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2167 if (!use_render_texture_emulation) {
2168 SetLastError(ERROR_INVALID_DATA);
2177 PUSH1(attribs, None);
2178 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2179 TRACE("new Pbuffer drawable as %lx\n", object->drawable);
2180 if (!object->drawable) {
2181 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2182 goto create_failed; /* unexpected error */
2184 TRACE("->(%p)\n", object);
2188 HeapFree(GetProcessHeap(), 0, object);
2189 TRACE("->(FAILED)\n");
2194 * X11DRV_wglDestroyPbufferARB
2196 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2198 static BOOL X11DRV_wglDestroyPbufferARB( struct wgl_pbuffer *object )
2200 TRACE("(%p)\n", object);
2202 pglXDestroyPbuffer(gdi_display, object->drawable);
2203 HeapFree(GetProcessHeap(), 0, object);
2208 * X11DRV_wglGetPbufferDCARB
2210 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2212 static HDC X11DRV_wglGetPbufferDCARB( struct wgl_pbuffer *object )
2214 struct x11drv_escape_set_drawable escape;
2215 struct gl_drawable *gl, *prev;
2218 hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
2221 if (!(gl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*gl) )))
2226 gl->type = DC_GL_PBUFFER;
2227 gl->drawable = object->drawable;
2228 gl->format = object->fmt;
2230 EnterCriticalSection( &context_section );
2231 if (!XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&prev ))
2232 free_gl_drawable( prev );
2233 XSaveContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char *)gl );
2234 LeaveCriticalSection( &context_section );
2236 escape.code = X11DRV_SET_DRAWABLE;
2238 escape.drawable = object->drawable;
2239 escape.mode = IncludeInferiors;
2240 SetRect( &escape.dc_rect, 0, 0, object->width, object->height );
2241 escape.fbconfig_id = object->fmt->fmt_id;
2242 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2244 TRACE( "(%p)->(%p)\n", object, hdc );
2249 * X11DRV_wglQueryPbufferARB
2251 * WGL_ARB_pbuffer: wglQueryPbufferARB
2253 static BOOL X11DRV_wglQueryPbufferARB( struct wgl_pbuffer *object, int iAttribute, int *piValue )
2255 TRACE("(%p, 0x%x, %p)\n", object, iAttribute, piValue);
2257 switch (iAttribute) {
2258 case WGL_PBUFFER_WIDTH_ARB:
2259 pglXQueryDrawable(gdi_display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2261 case WGL_PBUFFER_HEIGHT_ARB:
2262 pglXQueryDrawable(gdi_display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2265 case WGL_PBUFFER_LOST_ARB:
2266 /* GLX Pbuffers cannot be lost by default. We can support this by
2267 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2268 * to receive pixel buffer clobber events, however that may or may
2269 * not give any benefit */
2270 *piValue = GL_FALSE;
2273 case WGL_TEXTURE_FORMAT_ARB:
2274 if (!object->use_render_texture) {
2275 *piValue = WGL_NO_TEXTURE_ARB;
2277 if (!use_render_texture_emulation) {
2278 SetLastError(ERROR_INVALID_HANDLE);
2281 switch(object->use_render_texture) {
2283 *piValue = WGL_TEXTURE_RGB_ARB;
2286 *piValue = WGL_TEXTURE_RGBA_ARB;
2288 /* WGL_FLOAT_COMPONENTS_NV */
2290 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2292 case GL_FLOAT_RG_NV:
2293 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2295 case GL_FLOAT_RGB_NV:
2296 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2298 case GL_FLOAT_RGBA_NV:
2299 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2302 ERR("Unknown texture format: %x\n", object->use_render_texture);
2307 case WGL_TEXTURE_TARGET_ARB:
2308 if (!object->texture_target){
2309 *piValue = WGL_NO_TEXTURE_ARB;
2311 if (!use_render_texture_emulation) {
2312 SetLastError(ERROR_INVALID_DATA);
2315 switch (object->texture_target) {
2316 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2317 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2318 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2319 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2324 case WGL_MIPMAP_TEXTURE_ARB:
2325 *piValue = GL_FALSE; /** don't support that */
2326 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2330 FIXME("unexpected attribute %x\n", iAttribute);
2338 * X11DRV_wglReleasePbufferDCARB
2340 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2342 static int X11DRV_wglReleasePbufferDCARB( struct wgl_pbuffer *object, HDC hdc )
2344 struct gl_drawable *gl;
2346 TRACE("(%p, %p)\n", object, hdc);
2348 EnterCriticalSection( &context_section );
2350 if (!XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl ))
2352 XDeleteContext( gdi_display, (XID)hdc, gl_pbuffer_context );
2353 free_gl_drawable( gl );
2357 LeaveCriticalSection( &context_section );
2359 return hdc && DeleteDC(hdc);
2363 * X11DRV_wglSetPbufferAttribARB
2365 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2367 static BOOL X11DRV_wglSetPbufferAttribARB( struct wgl_pbuffer *object, const int *piAttribList )
2369 GLboolean ret = GL_FALSE;
2371 WARN("(%p, %p): alpha-testing, report any problem\n", object, piAttribList);
2373 if (!object->use_render_texture) {
2374 SetLastError(ERROR_INVALID_HANDLE);
2377 if (1 == use_render_texture_emulation) {
2384 * X11DRV_wglChoosePixelFormatARB
2386 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2388 static BOOL X11DRV_wglChoosePixelFormatARB( HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList,
2389 UINT nMaxFormats, int *piFormats, UINT *nNumFormats )
2393 GLXFBConfig* cfgs = NULL;
2403 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2404 if (NULL != pfAttribFList) {
2405 FIXME("unused pfAttribFList\n");
2408 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2409 if (-1 == nAttribs) {
2410 WARN("Cannot convert WGL to GLX attributes\n");
2413 PUSH1(attribs, None);
2415 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2416 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the pixel format. We don't query these attributes
2417 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on.
2419 for(i=0; piAttribIList[i] != 0; i+=2)
2421 switch(piAttribIList[i])
2423 case WGL_DRAW_TO_BITMAP_ARB:
2424 if(piAttribIList[i+1])
2425 dwFlags |= PFD_DRAW_TO_BITMAP;
2427 case WGL_ACCELERATION_ARB:
2428 switch(piAttribIList[i+1])
2430 case WGL_NO_ACCELERATION_ARB:
2431 dwFlags |= PFD_GENERIC_FORMAT;
2433 case WGL_GENERIC_ACCELERATION_ARB:
2434 dwFlags |= PFD_GENERIC_ACCELERATED;
2436 case WGL_FULL_ACCELERATION_ARB:
2441 case WGL_SUPPORT_GDI_ARB:
2442 if(piAttribIList[i+1])
2443 dwFlags |= PFD_SUPPORT_GDI;
2448 /* Search for FB configurations matching the requirements in attribs */
2449 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2451 WARN("Compatible Pixel Format not found\n");
2455 /* Loop through all matching formats and check if they are suitable.
2456 * Note that this function should at max return nMaxFormats different formats */
2457 for(run=0; run < 2; run++)
2459 for (it = 0; it < nCfgs && pfmt_it < nMaxFormats; ++it)
2461 if (pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id))
2463 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2467 /* During the first run we only want onscreen formats and during the second only offscreen */
2468 start = run == 1 ? nb_onscreen_formats : 0;
2469 end = run == 1 ? nb_pixel_formats : nb_onscreen_formats;
2471 for (i = start; i < end; i++)
2473 if (pixel_formats[i].fmt_id == fmt_id && (pixel_formats[i].dwFlags & dwFlags) == dwFlags)
2475 piFormats[pfmt_it++] = i + 1;
2476 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n",
2477 it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2484 *nNumFormats = pfmt_it;
2491 * X11DRV_wglGetPixelFormatAttribivARB
2493 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2495 static BOOL X11DRV_wglGetPixelFormatAttribivARB( HDC hdc, int iPixelFormat, int iLayerPlane,
2496 UINT nAttributes, const int *piAttributes, int *piValues )
2499 const struct wgl_pixel_format *fmt = NULL;
2504 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2506 if (0 < iLayerPlane) {
2507 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2511 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2512 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2513 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2514 fmt = get_pixel_format(gdi_display, iPixelFormat, TRUE /* Offscreen */);
2516 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2519 for (i = 0; i < nAttributes; ++i) {
2520 const int curWGLAttr = piAttributes[i];
2521 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2523 switch (curWGLAttr) {
2524 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2525 piValues[i] = nb_pixel_formats;
2528 case WGL_SUPPORT_OPENGL_ARB:
2529 piValues[i] = GL_TRUE;
2532 case WGL_ACCELERATION_ARB:
2533 curGLXAttr = GLX_CONFIG_CAVEAT;
2534 if (!fmt) goto pix_error;
2535 if(fmt->dwFlags & PFD_GENERIC_FORMAT)
2536 piValues[i] = WGL_NO_ACCELERATION_ARB;
2537 else if(fmt->dwFlags & PFD_GENERIC_ACCELERATED)
2538 piValues[i] = WGL_GENERIC_ACCELERATION_ARB;
2540 piValues[i] = WGL_FULL_ACCELERATION_ARB;
2543 case WGL_TRANSPARENT_ARB:
2544 curGLXAttr = GLX_TRANSPARENT_TYPE;
2545 if (!fmt) goto pix_error;
2546 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2547 if (hTest) goto get_error;
2548 piValues[i] = GL_FALSE;
2549 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2552 case WGL_PIXEL_TYPE_ARB:
2553 curGLXAttr = GLX_RENDER_TYPE;
2554 if (!fmt) goto pix_error;
2555 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2556 if (hTest) goto get_error;
2557 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2558 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2559 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2560 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2561 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2562 else if (tmp & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) { piValues[i] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT; }
2564 ERR("unexpected RenderType(%x)\n", tmp);
2565 piValues[i] = WGL_TYPE_RGBA_ARB;
2569 case WGL_COLOR_BITS_ARB:
2570 curGLXAttr = GLX_BUFFER_SIZE;
2573 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2574 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2575 if (!use_render_texture_emulation) {
2576 piValues[i] = GL_FALSE;
2579 curGLXAttr = GLX_RENDER_TYPE;
2580 if (!fmt) goto pix_error;
2581 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2582 if (hTest) goto get_error;
2583 if (GLX_COLOR_INDEX_BIT == tmp) {
2584 piValues[i] = GL_FALSE;
2587 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2588 if (hTest) goto get_error;
2589 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2592 case WGL_BLUE_BITS_ARB:
2593 curGLXAttr = GLX_BLUE_SIZE;
2595 case WGL_RED_BITS_ARB:
2596 curGLXAttr = GLX_RED_SIZE;
2598 case WGL_GREEN_BITS_ARB:
2599 curGLXAttr = GLX_GREEN_SIZE;
2601 case WGL_ALPHA_BITS_ARB:
2602 curGLXAttr = GLX_ALPHA_SIZE;
2604 case WGL_DEPTH_BITS_ARB:
2605 curGLXAttr = GLX_DEPTH_SIZE;
2607 case WGL_STENCIL_BITS_ARB:
2608 curGLXAttr = GLX_STENCIL_SIZE;
2610 case WGL_DOUBLE_BUFFER_ARB:
2611 curGLXAttr = GLX_DOUBLEBUFFER;
2613 case WGL_STEREO_ARB:
2614 curGLXAttr = GLX_STEREO;
2616 case WGL_AUX_BUFFERS_ARB:
2617 curGLXAttr = GLX_AUX_BUFFERS;
2620 case WGL_SUPPORT_GDI_ARB:
2621 if (!fmt) goto pix_error;
2622 piValues[i] = (fmt->dwFlags & PFD_SUPPORT_GDI) != 0;
2625 case WGL_DRAW_TO_BITMAP_ARB:
2626 if (!fmt) goto pix_error;
2627 piValues[i] = (fmt->dwFlags & PFD_DRAW_TO_BITMAP) != 0;
2630 case WGL_DRAW_TO_WINDOW_ARB:
2631 case WGL_DRAW_TO_PBUFFER_ARB:
2632 if (!fmt) goto pix_error;
2633 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2634 if (hTest) goto get_error;
2635 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2636 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2637 piValues[i] = GL_TRUE;
2639 piValues[i] = GL_FALSE;
2642 case WGL_SWAP_METHOD_ARB:
2643 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
2644 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
2645 * point only ATI offers this.
2647 piValues[i] = WGL_SWAP_EXCHANGE_ARB;
2650 case WGL_PBUFFER_LARGEST_ARB:
2651 curGLXAttr = GLX_LARGEST_PBUFFER;
2654 case WGL_SAMPLE_BUFFERS_ARB:
2655 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2658 case WGL_SAMPLES_ARB:
2659 curGLXAttr = GLX_SAMPLES_ARB;
2662 case WGL_FLOAT_COMPONENTS_NV:
2663 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2666 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
2667 curGLXAttr = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT;
2670 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
2671 curGLXAttr = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
2674 case WGL_ACCUM_RED_BITS_ARB:
2675 curGLXAttr = GLX_ACCUM_RED_SIZE;
2677 case WGL_ACCUM_GREEN_BITS_ARB:
2678 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2680 case WGL_ACCUM_BLUE_BITS_ARB:
2681 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2683 case WGL_ACCUM_ALPHA_BITS_ARB:
2684 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2686 case WGL_ACCUM_BITS_ARB:
2687 if (!fmt) goto pix_error;
2688 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2689 if (hTest) goto get_error;
2691 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2692 if (hTest) goto get_error;
2694 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2695 if (hTest) goto get_error;
2697 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2698 if (hTest) goto get_error;
2703 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2706 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2707 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2708 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2710 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2711 * and check which options can work using iPixelFormat=0 and which not.
2712 * A problem would be that this function is an extension. This would
2713 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2715 if (0 != curGLXAttr && iPixelFormat != 0) {
2716 if (!fmt) goto pix_error;
2717 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2718 if (hTest) goto get_error;
2721 piValues[i] = GL_FALSE;
2727 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2731 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nb_pixel_formats);
2736 * X11DRV_wglGetPixelFormatAttribfvARB
2738 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2740 static BOOL X11DRV_wglGetPixelFormatAttribfvARB( HDC hdc, int iPixelFormat, int iLayerPlane,
2741 UINT nAttributes, const int *piAttributes, FLOAT *pfValues )
2747 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2749 /* Allocate a temporary array to store integer values */
2750 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2752 ERR("couldn't allocate %d array\n", nAttributes);
2756 /* Piggy-back on wglGetPixelFormatAttribivARB */
2757 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2759 /* Convert integer values to float. Should also check for attributes
2760 that can give decimal values here */
2761 for (i=0; i<nAttributes;i++) {
2762 pfValues[i] = attr[i];
2766 HeapFree(GetProcessHeap(), 0, attr);
2771 * X11DRV_wglBindTexImageARB
2773 * WGL_ARB_render_texture: wglBindTexImageARB
2775 static BOOL X11DRV_wglBindTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2777 GLboolean ret = GL_FALSE;
2779 TRACE("(%p, %d)\n", object, iBuffer);
2781 if (!object->use_render_texture) {
2782 SetLastError(ERROR_INVALID_HANDLE);
2786 if (1 == use_render_texture_emulation) {
2787 static int init = 0;
2788 int prev_binded_texture = 0;
2789 GLXContext prev_context;
2790 Drawable prev_drawable;
2791 GLXContext tmp_context;
2793 prev_context = pglXGetCurrentContext();
2794 prev_drawable = pglXGetCurrentDrawable();
2796 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2797 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2798 isn't ideal performance wise but I wasn't able to get other ways working.
2801 init = 1; /* Only show the FIXME once for performance reasons */
2802 FIXME("partial stub!\n");
2805 TRACE("drawable=%lx, context=%p\n", object->drawable, prev_context);
2806 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2808 opengl_funcs.gl.p_glGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2810 /* Switch to our pbuffer */
2811 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
2813 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2814 * After that upload the pbuffer texture data. */
2815 opengl_funcs.gl.p_glBindTexture(object->texture_target, prev_binded_texture);
2816 opengl_funcs.gl.p_glCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2818 /* Switch back to the original drawable and upload the pbuffer-texture */
2819 pglXMakeCurrent(gdi_display, prev_drawable, prev_context);
2820 pglXDestroyContext(gdi_display, tmp_context);
2828 * X11DRV_wglReleaseTexImageARB
2830 * WGL_ARB_render_texture: wglReleaseTexImageARB
2832 static BOOL X11DRV_wglReleaseTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2834 GLboolean ret = GL_FALSE;
2836 TRACE("(%p, %d)\n", object, iBuffer);
2838 if (!object->use_render_texture) {
2839 SetLastError(ERROR_INVALID_HANDLE);
2842 if (1 == use_render_texture_emulation) {
2849 * X11DRV_wglGetExtensionsStringEXT
2851 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2853 static const GLubyte *X11DRV_wglGetExtensionsStringEXT(void)
2855 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2856 return (const GLubyte *)WineGLInfo.wglExtensions;
2860 * X11DRV_wglGetSwapIntervalEXT
2862 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2864 static int X11DRV_wglGetSwapIntervalEXT(void)
2866 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
2867 * interval, so the swap interval has to be tracked. */
2869 return swap_interval;
2873 * X11DRV_wglSwapIntervalEXT
2875 * WGL_EXT_swap_control: wglSwapIntervalEXT
2877 static BOOL X11DRV_wglSwapIntervalEXT(int interval)
2881 TRACE("(%d)\n", interval);
2885 SetLastError(ERROR_INVALID_DATA);
2888 else if (!has_swap_control && interval == 0)
2890 /* wglSwapIntervalEXT considers an interval value of zero to mean that
2891 * vsync should be disabled, but glXSwapIntervalSGI considers such a
2892 * value to be an error. Just silently ignore the request for now. */
2893 WARN("Request to disable vertical sync is not handled\n");
2898 if (pglXSwapIntervalSGI)
2899 ret = !pglXSwapIntervalSGI(interval);
2901 WARN("GLX_SGI_swap_control extension is not available\n");
2904 swap_interval = interval;
2906 SetLastError(ERROR_DC_NOT_FOUND);
2913 * X11DRV_wglSetPixelFormatWINE
2915 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
2916 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
2918 static BOOL X11DRV_wglSetPixelFormatWINE(HDC hdc, int format)
2920 const struct wgl_pixel_format *fmt;
2924 TRACE("(%p,%d)\n", hdc, format);
2926 fmt = get_pixel_format(gdi_display, format, FALSE /* Offscreen */);
2929 ERR( "Invalid format %d\n", format );
2933 hwnd = WindowFromDC( hdc );
2934 if (!hwnd || hwnd == GetDesktopWindow())
2936 ERR( "not a valid window DC %p\n", hdc );
2940 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
2941 if (!(value & GLX_WINDOW_BIT))
2943 WARN( "Pixel format %d is not compatible for window rendering\n", format );
2947 return set_win_format( hwnd, fmt );
2951 * glxRequireVersion (internal)
2953 * Check if the supported GLX version matches requiredVersion.
2955 static BOOL glxRequireVersion(int requiredVersion)
2957 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2958 if(requiredVersion <= WineGLInfo.glxVersion[1])
2964 static void register_extension(const char *ext)
2966 if (WineGLInfo.wglExtensions[0])
2967 strcat(WineGLInfo.wglExtensions, " ");
2968 strcat(WineGLInfo.wglExtensions, ext);
2970 TRACE("'%s'\n", ext);
2974 * X11DRV_WineGL_LoadExtensions
2976 static void X11DRV_WineGL_LoadExtensions(void)
2978 WineGLInfo.wglExtensions[0] = 0;
2980 /* ARB Extensions */
2982 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_create_context"))
2984 register_extension( "WGL_ARB_create_context" );
2985 opengl_funcs.ext.p_wglCreateContextAttribsARB = X11DRV_wglCreateContextAttribsARB;
2987 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_create_context_profile"))
2988 register_extension("WGL_ARB_create_context_profile");
2991 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_fbconfig_float"))
2993 register_extension("WGL_ARB_pixel_format_float");
2994 register_extension("WGL_ATI_pixel_format_float");
2997 register_extension( "WGL_ARB_extensions_string" );
2998 opengl_funcs.ext.p_wglGetExtensionsStringARB = X11DRV_wglGetExtensionsStringARB;
3000 if (glxRequireVersion(3))
3002 register_extension( "WGL_ARB_make_current_read" );
3003 opengl_funcs.ext.p_wglGetCurrentReadDCARB = (void *)1; /* never called */
3004 opengl_funcs.ext.p_wglMakeContextCurrentARB = X11DRV_wglMakeContextCurrentARB;
3007 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_multisample")) register_extension( "WGL_ARB_multisample" );
3009 /* In general pbuffer functionality requires support in the X-server. The functionality is
3010 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3012 if ( glxRequireVersion(3) && has_extension( WineGLInfo.glxExtensions, "GLX_SGIX_pbuffer") )
3014 register_extension( "WGL_ARB_pbuffer" );
3015 opengl_funcs.ext.p_wglCreatePbufferARB = X11DRV_wglCreatePbufferARB;
3016 opengl_funcs.ext.p_wglDestroyPbufferARB = X11DRV_wglDestroyPbufferARB;
3017 opengl_funcs.ext.p_wglGetPbufferDCARB = X11DRV_wglGetPbufferDCARB;
3018 opengl_funcs.ext.p_wglQueryPbufferARB = X11DRV_wglQueryPbufferARB;
3019 opengl_funcs.ext.p_wglReleasePbufferDCARB = X11DRV_wglReleasePbufferDCARB;
3020 opengl_funcs.ext.p_wglSetPbufferAttribARB = X11DRV_wglSetPbufferAttribARB;
3023 register_extension( "WGL_ARB_pixel_format" );
3024 opengl_funcs.ext.p_wglChoosePixelFormatARB = X11DRV_wglChoosePixelFormatARB;
3025 opengl_funcs.ext.p_wglGetPixelFormatAttribfvARB = X11DRV_wglGetPixelFormatAttribfvARB;
3026 opengl_funcs.ext.p_wglGetPixelFormatAttribivARB = X11DRV_wglGetPixelFormatAttribivARB;
3028 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3029 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_render_texture") ||
3030 (glxRequireVersion(3) && has_extension( WineGLInfo.glxExtensions, "GLX_SGIX_pbuffer") && use_render_texture_emulation))
3032 register_extension( "WGL_ARB_render_texture" );
3033 opengl_funcs.ext.p_wglBindTexImageARB = X11DRV_wglBindTexImageARB;
3034 opengl_funcs.ext.p_wglReleaseTexImageARB = X11DRV_wglReleaseTexImageARB;
3036 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3037 if (has_extension( WineGLInfo.glxExtensions, "GLX_NV_float_buffer"))
3038 register_extension("WGL_NV_float_buffer");
3040 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3041 if (has_extension(WineGLInfo.glExtensions, "GL_NV_texture_rectangle"))
3042 register_extension("WGL_NV_render_texture_rectangle");
3045 /* EXT Extensions */
3047 register_extension( "WGL_EXT_extensions_string" );
3048 opengl_funcs.ext.p_wglGetExtensionsStringEXT = X11DRV_wglGetExtensionsStringEXT;
3050 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3051 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3052 register_extension( "WGL_EXT_swap_control" );
3053 opengl_funcs.ext.p_wglSwapIntervalEXT = X11DRV_wglSwapIntervalEXT;
3054 opengl_funcs.ext.p_wglGetSwapIntervalEXT = X11DRV_wglGetSwapIntervalEXT;
3056 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_framebuffer_sRGB"))
3057 register_extension("WGL_EXT_framebuffer_sRGB");
3059 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_fbconfig_packed_float"))
3060 register_extension("WGL_EXT_pixel_format_packed_float");
3062 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_swap_control"))
3063 has_swap_control = TRUE;
3065 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3066 if (has_extension(WineGLInfo.glExtensions, "GL_NV_vertex_array_range"))
3068 register_extension( "WGL_NV_vertex_array_range" );
3069 opengl_funcs.ext.p_wglAllocateMemoryNV = pglXAllocateMemoryNV;
3070 opengl_funcs.ext.p_wglFreeMemoryNV = pglXFreeMemoryNV;
3073 /* WINE-specific WGL Extensions */
3075 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3076 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3078 register_extension( "WGL_WINE_pixel_format_passthrough" );
3079 opengl_funcs.ext.p_wglSetPixelFormatWINE = X11DRV_wglSetPixelFormatWINE;
3084 * glxdrv_SwapBuffers
3086 * Swap the buffers of this DC
3088 static BOOL glxdrv_wglSwapBuffers( HDC hdc )
3090 struct x11drv_escape_flush_gl_drawable escape;
3091 struct gl_drawable *gl;
3092 struct wgl_context *ctx = NtCurrentTeb()->glContext;
3094 TRACE("(%p)\n", hdc);
3096 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
3097 escape.gl_drawable = 0;
3099 if (!(gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
3101 SetLastError( ERROR_INVALID_HANDLE );
3107 case DC_GL_PIXMAP_WIN:
3108 if (ctx) sync_context( ctx );
3109 escape.gl_drawable = gl->pixmap;
3110 if (pglXCopySubBufferMESA) {
3111 /* (glX)SwapBuffers has an implicit glFlush effect, however
3112 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3115 pglXCopySubBufferMESA( gdi_display, gl->drawable, 0, 0,
3116 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top );
3119 pglXSwapBuffers(gdi_display, gl->drawable);
3121 case DC_GL_CHILD_WIN:
3122 escape.gl_drawable = gl->drawable;
3125 pglXSwapBuffers(gdi_display, gl->drawable);
3129 release_gl_drawable( gl );
3131 if (escape.gl_drawable) ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
3135 static struct opengl_funcs opengl_funcs =
3138 glxdrv_wglCopyContext, /* p_wglCopyContext */
3139 glxdrv_wglCreateContext, /* p_wglCreateContext */
3140 glxdrv_wglDeleteContext, /* p_wglDeleteContext */
3141 glxdrv_wglDescribePixelFormat, /* p_wglDescribePixelFormat */
3142 glxdrv_wglGetPixelFormat, /* p_wglGetPixelFormat */
3143 glxdrv_wglGetProcAddress, /* p_wglGetProcAddress */
3144 glxdrv_wglMakeCurrent, /* p_wglMakeCurrent */
3145 glxdrv_wglSetPixelFormat, /* p_wglSetPixelFormat */
3146 glxdrv_wglShareLists, /* p_wglShareLists */
3147 glxdrv_wglSwapBuffers, /* p_wglSwapBuffers */
3151 struct opengl_funcs *get_glx_driver( UINT version )
3153 if (version != WINE_WGL_DRIVER_VERSION)
3155 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_WGL_DRIVER_VERSION );
3158 if (has_opengl()) return &opengl_funcs;
3162 #else /* no OpenGL includes */
3164 struct opengl_funcs *get_glx_driver( UINT version )
3169 void sync_gl_drawable( HWND hwnd, const RECT *visible_rect, const RECT *client_rect )
3173 void set_gl_drawable_parent( HWND hwnd, HWND parent )
3177 void destroy_gl_drawable( HWND hwnd )
3181 #endif /* defined(SONAME_LIBGL) */