wined3d: Simplify wined3d_cs_emit_clear() slightly.
[wine.git] / dlls / winex11.drv / opengl.c
blob13a1da32ea50a44ff86329b3b38076cccb9c2f1e
1 /*
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
26 #include "config.h"
27 #include "wine/port.h"
29 #include <assert.h>
30 #include <stdlib.h>
31 #include <string.h>
33 #ifdef HAVE_SYS_SOCKET_H
34 #include <sys/socket.h>
35 #endif
36 #ifdef HAVE_SYS_UN_H
37 #include <sys/un.h>
38 #endif
40 #include "x11drv.h"
41 #include "xcomposite.h"
42 #include "winternl.h"
43 #include "wine/library.h"
44 #include "wine/debug.h"
46 #ifdef SONAME_LIBGL
48 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
49 WINE_DECLARE_DEBUG_CHANNEL(winediag);
51 #include "wine/wgl.h"
52 #include "wine/wgl_driver.h"
54 typedef struct __GLXcontextRec *GLXContext;
55 typedef struct __GLXFBConfigRec *GLXFBConfig;
56 typedef XID GLXPixmap;
57 typedef XID GLXDrawable;
58 typedef XID GLXFBConfigID;
59 typedef XID GLXContextID;
60 typedef XID GLXWindow;
61 typedef XID GLXPbuffer;
63 #define GLX_USE_GL 1
64 #define GLX_BUFFER_SIZE 2
65 #define GLX_LEVEL 3
66 #define GLX_RGBA 4
67 #define GLX_DOUBLEBUFFER 5
68 #define GLX_STEREO 6
69 #define GLX_AUX_BUFFERS 7
70 #define GLX_RED_SIZE 8
71 #define GLX_GREEN_SIZE 9
72 #define GLX_BLUE_SIZE 10
73 #define GLX_ALPHA_SIZE 11
74 #define GLX_DEPTH_SIZE 12
75 #define GLX_STENCIL_SIZE 13
76 #define GLX_ACCUM_RED_SIZE 14
77 #define GLX_ACCUM_GREEN_SIZE 15
78 #define GLX_ACCUM_BLUE_SIZE 16
79 #define GLX_ACCUM_ALPHA_SIZE 17
81 #define GLX_BAD_SCREEN 1
82 #define GLX_BAD_ATTRIBUTE 2
83 #define GLX_NO_EXTENSION 3
84 #define GLX_BAD_VISUAL 4
85 #define GLX_BAD_CONTEXT 5
86 #define GLX_BAD_VALUE 6
87 #define GLX_BAD_ENUM 7
89 #define GLX_VENDOR 1
90 #define GLX_VERSION 2
91 #define GLX_EXTENSIONS 3
93 #define GLX_CONFIG_CAVEAT 0x20
94 #define GLX_DONT_CARE 0xFFFFFFFF
95 #define GLX_X_VISUAL_TYPE 0x22
96 #define GLX_TRANSPARENT_TYPE 0x23
97 #define GLX_TRANSPARENT_INDEX_VALUE 0x24
98 #define GLX_TRANSPARENT_RED_VALUE 0x25
99 #define GLX_TRANSPARENT_GREEN_VALUE 0x26
100 #define GLX_TRANSPARENT_BLUE_VALUE 0x27
101 #define GLX_TRANSPARENT_ALPHA_VALUE 0x28
102 #define GLX_WINDOW_BIT 0x00000001
103 #define GLX_PIXMAP_BIT 0x00000002
104 #define GLX_PBUFFER_BIT 0x00000004
105 #define GLX_AUX_BUFFERS_BIT 0x00000010
106 #define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001
107 #define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002
108 #define GLX_BACK_LEFT_BUFFER_BIT 0x00000004
109 #define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008
110 #define GLX_DEPTH_BUFFER_BIT 0x00000020
111 #define GLX_STENCIL_BUFFER_BIT 0x00000040
112 #define GLX_ACCUM_BUFFER_BIT 0x00000080
113 #define GLX_NONE 0x8000
114 #define GLX_SLOW_CONFIG 0x8001
115 #define GLX_TRUE_COLOR 0x8002
116 #define GLX_DIRECT_COLOR 0x8003
117 #define GLX_PSEUDO_COLOR 0x8004
118 #define GLX_STATIC_COLOR 0x8005
119 #define GLX_GRAY_SCALE 0x8006
120 #define GLX_STATIC_GRAY 0x8007
121 #define GLX_TRANSPARENT_RGB 0x8008
122 #define GLX_TRANSPARENT_INDEX 0x8009
123 #define GLX_VISUAL_ID 0x800B
124 #define GLX_SCREEN 0x800C
125 #define GLX_NON_CONFORMANT_CONFIG 0x800D
126 #define GLX_DRAWABLE_TYPE 0x8010
127 #define GLX_RENDER_TYPE 0x8011
128 #define GLX_X_RENDERABLE 0x8012
129 #define GLX_FBCONFIG_ID 0x8013
130 #define GLX_RGBA_TYPE 0x8014
131 #define GLX_COLOR_INDEX_TYPE 0x8015
132 #define GLX_MAX_PBUFFER_WIDTH 0x8016
133 #define GLX_MAX_PBUFFER_HEIGHT 0x8017
134 #define GLX_MAX_PBUFFER_PIXELS 0x8018
135 #define GLX_PRESERVED_CONTENTS 0x801B
136 #define GLX_LARGEST_PBUFFER 0x801C
137 #define GLX_WIDTH 0x801D
138 #define GLX_HEIGHT 0x801E
139 #define GLX_EVENT_MASK 0x801F
140 #define GLX_DAMAGED 0x8020
141 #define GLX_SAVED 0x8021
142 #define GLX_WINDOW 0x8022
143 #define GLX_PBUFFER 0x8023
144 #define GLX_PBUFFER_HEIGHT 0x8040
145 #define GLX_PBUFFER_WIDTH 0x8041
146 #define GLX_SWAP_METHOD_OML 0x8060
147 #define GLX_SWAP_EXCHANGE_OML 0x8061
148 #define GLX_SWAP_COPY_OML 0x8062
149 #define GLX_SWAP_UNDEFINED_OML 0x8063
150 #define GLX_RGBA_BIT 0x00000001
151 #define GLX_COLOR_INDEX_BIT 0x00000002
152 #define GLX_PBUFFER_CLOBBER_MASK 0x08000000
154 /** GLX_ARB_multisample */
155 #define GLX_SAMPLE_BUFFERS_ARB 100000
156 #define GLX_SAMPLES_ARB 100001
157 /** GLX_ARB_framebuffer_sRGB */
158 #define GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20B2
159 /** GLX_EXT_fbconfig_packed_float */
160 #define GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT 0x20B1
161 #define GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT 0x00000008
162 /** GLX_ARB_create_context */
163 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
164 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
165 #define GLX_CONTEXT_FLAGS_ARB 0x2094
166 /** GLX_ARB_create_context_no_error */
167 #define GLX_CONTEXT_OPENGL_NO_ERROR_ARB 0x31B3
168 /** GLX_ARB_create_context_profile */
169 #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
170 /** GLX_ATI_pixel_format_float */
171 #define GLX_RGBA_FLOAT_ATI_BIT 0x00000100
172 /** GLX_ARB_pixel_format_float */
173 #define GLX_RGBA_FLOAT_BIT 0x00000004
174 #define GLX_RGBA_FLOAT_TYPE 0x20B9
175 /** GLX_MESA_query_renderer */
176 #define GLX_RENDERER_ID_MESA 0x818E
177 /** GLX_NV_float_buffer */
178 #define GLX_FLOAT_COMPONENTS_NV 0x20B0
181 static char *glExtensions;
182 static const char *glxExtensions;
183 static char wglExtensions[4096];
184 static int glxVersion[2];
186 struct wgl_pixel_format
188 GLXFBConfig fbconfig;
189 XVisualInfo *visual;
190 int fmt_id;
191 int render_type;
192 DWORD dwFlags; /* We store some PFD_* flags in here for emulated bitmap formats */
195 struct wgl_context
197 HDC hdc;
198 BOOL has_been_current;
199 BOOL sharing;
200 BOOL gl3_context;
201 const struct wgl_pixel_format *fmt;
202 int numAttribs; /* This is needed for delaying wglCreateContextAttribsARB */
203 int attribList[16]; /* This is needed for delaying wglCreateContextAttribsARB */
204 GLXContext ctx;
205 struct gl_drawable *drawables[2];
206 struct gl_drawable *new_drawables[2];
207 BOOL refresh_drawables;
208 struct list entry;
211 struct wgl_pbuffer
213 Drawable drawable;
214 const struct wgl_pixel_format* fmt;
215 int width;
216 int height;
217 int* attribList;
218 int use_render_texture; /* This is also the internal texture format */
219 int texture_bind_target;
220 int texture_bpp;
221 GLint texture_format;
222 GLuint texture_target;
223 GLenum texture_type;
224 GLuint texture;
225 int texture_level;
226 GLXContext tmp_context;
227 GLXContext prev_context;
228 struct list entry;
231 enum dc_gl_type
233 DC_GL_NONE, /* no GL support (pixel format not set yet) */
234 DC_GL_WINDOW, /* normal top-level window */
235 DC_GL_CHILD_WIN, /* child window using XComposite */
236 DC_GL_PIXMAP_WIN, /* child window using intermediate pixmap */
237 DC_GL_PBUFFER /* pseudo memory DC using a PBuffer */
240 struct gl_drawable
242 LONG ref; /* reference count */
243 enum dc_gl_type type; /* type of GL surface */
244 GLXDrawable drawable; /* drawable for rendering with GL */
245 Window window; /* window if drawable is a GLXWindow */
246 Pixmap pixmap; /* base pixmap if drawable is a GLXPixmap */
247 const struct wgl_pixel_format *format; /* pixel format for the drawable */
248 SIZE pixmap_size; /* pixmap size for GLXPixmap drawables */
249 int swap_interval;
250 BOOL refresh_swap_interval;
253 enum glx_swap_control_method
255 GLX_SWAP_CONTROL_NONE,
256 GLX_SWAP_CONTROL_EXT,
257 GLX_SWAP_CONTROL_SGI,
258 GLX_SWAP_CONTROL_MESA
261 /* X context to associate a struct gl_drawable to an hwnd */
262 static XContext gl_hwnd_context;
263 /* X context to associate a struct gl_drawable to a pbuffer hdc */
264 static XContext gl_pbuffer_context;
266 static struct list context_list = LIST_INIT( context_list );
267 static struct list pbuffer_list = LIST_INIT( pbuffer_list );
268 static struct wgl_pixel_format *pixel_formats;
269 static int nb_pixel_formats, nb_onscreen_formats;
270 static BOOL use_render_texture_emulation = TRUE;
272 /* Selects the preferred GLX swap control method for use by wglSwapIntervalEXT */
273 static enum glx_swap_control_method swap_control_method = GLX_SWAP_CONTROL_NONE;
274 /* Set when GLX_EXT_swap_control_tear is supported, requires GLX_SWAP_CONTROL_EXT */
275 static BOOL has_swap_control_tear = FALSE;
276 static BOOL has_swap_method = FALSE;
278 static CRITICAL_SECTION context_section;
279 static CRITICAL_SECTION_DEBUG critsect_debug =
281 0, 0, &context_section,
282 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
283 0, 0, { (DWORD_PTR)(__FILE__ ": context_section") }
285 static CRITICAL_SECTION context_section = { &critsect_debug, -1, 0, 0, 0, 0 };
287 static const BOOL is_win64 = sizeof(void *) > sizeof(int);
289 static struct opengl_funcs opengl_funcs;
291 #define USE_GL_FUNC(name) #name,
292 static const char *opengl_func_names[] = { ALL_WGL_FUNCS };
293 #undef USE_GL_FUNC
295 static void X11DRV_WineGL_LoadExtensions(void);
296 static void init_pixel_formats( Display *display );
297 static BOOL glxRequireVersion(int requiredVersion);
299 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
300 TRACE( "size %u version %u flags %u type %u color %u %u,%u,%u,%u "
301 "accum %u depth %u stencil %u aux %u ",
302 ppfd->nSize, ppfd->nVersion, ppfd->dwFlags, ppfd->iPixelType,
303 ppfd->cColorBits, ppfd->cRedBits, ppfd->cGreenBits, ppfd->cBlueBits, ppfd->cAlphaBits,
304 ppfd->cAccumBits, ppfd->cDepthBits, ppfd->cStencilBits, ppfd->cAuxBuffers );
305 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
306 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
307 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
308 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
309 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
310 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
311 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
312 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
313 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
314 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
315 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
316 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
317 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
318 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
319 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
320 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
321 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
322 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
323 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
324 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
325 #undef TEST_AND_DUMP
326 TRACE("\n");
329 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
330 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
332 /* GLX 1.0 */
333 static XVisualInfo* (*pglXChooseVisual)( Display *dpy, int screen, int *attribList );
334 static GLXContext (*pglXCreateContext)( Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct );
335 static void (*pglXDestroyContext)( Display *dpy, GLXContext ctx );
336 static Bool (*pglXMakeCurrent)( Display *dpy, GLXDrawable drawable, GLXContext ctx);
337 static void (*pglXCopyContext)( Display *dpy, GLXContext src, GLXContext dst, unsigned long mask );
338 static void (*pglXSwapBuffers)( Display *dpy, GLXDrawable drawable );
339 static Bool (*pglXQueryExtension)( Display *dpy, int *errorb, int *event );
340 static Bool (*pglXQueryVersion)( Display *dpy, int *maj, int *min );
341 static Bool (*pglXIsDirect)( Display *dpy, GLXContext ctx );
342 static GLXContext (*pglXGetCurrentContext)( void );
343 static GLXDrawable (*pglXGetCurrentDrawable)( void );
345 /* GLX 1.1 */
346 static const char *(*pglXQueryExtensionsString)( Display *dpy, int screen );
347 static const char *(*pglXQueryServerString)( Display *dpy, int screen, int name );
348 static const char *(*pglXGetClientString)( Display *dpy, int name );
350 /* GLX 1.3 */
351 static GLXFBConfig *(*pglXChooseFBConfig)( Display *dpy, int screen, const int *attribList, int *nitems );
352 static int (*pglXGetFBConfigAttrib)( Display *dpy, GLXFBConfig config, int attribute, int *value );
353 static GLXFBConfig *(*pglXGetFBConfigs)( Display *dpy, int screen, int *nelements );
354 static XVisualInfo *(*pglXGetVisualFromFBConfig)( Display *dpy, GLXFBConfig config );
355 static GLXPbuffer (*pglXCreatePbuffer)( Display *dpy, GLXFBConfig config, const int *attribList );
356 static void (*pglXDestroyPbuffer)( Display *dpy, GLXPbuffer pbuf );
357 static void (*pglXQueryDrawable)( Display *dpy, GLXDrawable draw, int attribute, unsigned int *value );
358 static GLXContext (*pglXCreateNewContext)( Display *dpy, GLXFBConfig config, int renderType, GLXContext shareList, Bool direct );
359 static Bool (*pglXMakeContextCurrent)( Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx );
360 static GLXPixmap (*pglXCreatePixmap)( Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list );
361 static void (*pglXDestroyPixmap)( Display *dpy, GLXPixmap pixmap );
362 static GLXWindow (*pglXCreateWindow)( Display *dpy, GLXFBConfig config, Window win, const int *attrib_list );
363 static void (*pglXDestroyWindow)( Display *dpy, GLXWindow win );
365 /* GLX Extensions */
366 static GLXContext (*pglXCreateContextAttribsARB)(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
367 static void* (*pglXGetProcAddressARB)(const GLubyte *);
368 static void (*pglXSwapIntervalEXT)(Display *dpy, GLXDrawable drawable, int interval);
369 static int (*pglXSwapIntervalSGI)(int);
371 /* NV GLX Extension */
372 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
373 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
375 /* MESA GLX Extensions */
376 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
377 static int (*pglXSwapIntervalMESA)(unsigned int interval);
378 static Bool (*pglXQueryCurrentRendererIntegerMESA)(int attribute, unsigned int *value);
379 static const char *(*pglXQueryCurrentRendererStringMESA)(int attribute);
380 static Bool (*pglXQueryRendererIntegerMESA)(Display *dpy, int screen, int renderer, int attribute, unsigned int *value);
381 static const char *(*pglXQueryRendererStringMESA)(Display *dpy, int screen, int renderer, int attribute);
383 /* OpenML GLX Extensions */
384 static Bool (*pglXWaitForSbcOML)( Display *dpy, GLXDrawable drawable,
385 INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 *sbc );
386 static INT64 (*pglXSwapBuffersMscOML)( Display *dpy, GLXDrawable drawable,
387 INT64 target_msc, INT64 divisor, INT64 remainder );
389 /* Standard OpenGL */
390 static void (*pglFinish)(void);
391 static void (*pglFlush)(void);
392 static const GLubyte *(*pglGetString)(GLenum name);
394 static void wglFinish(void);
395 static void wglFlush(void);
396 static const GLubyte *wglGetString(GLenum name);
398 /* check if the extension is present in the list */
399 static BOOL has_extension( const char *list, const char *ext )
401 size_t len = strlen( ext );
403 while (list)
405 while (*list == ' ') list++;
406 if (!strncmp( list, ext, len ) && (!list[len] || list[len] == ' ')) return TRUE;
407 list = strchr( list, ' ' );
409 return FALSE;
412 static int GLXErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
414 /* In the future we might want to find the exact X or GLX error to report back to the app */
415 return 1;
418 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
420 static const char legacy_extensions[] = " WGL_EXT_extensions_string WGL_EXT_swap_control";
422 int screen = DefaultScreen(gdi_display);
423 Window win = 0, root = 0;
424 const char *gl_version;
425 const char *gl_renderer;
426 const char* str;
427 BOOL glx_direct;
428 XVisualInfo *vis;
429 GLXContext ctx = NULL;
430 XSetWindowAttributes attr;
431 BOOL ret = FALSE;
432 int attribList[] = {GLX_RGBA, GLX_DOUBLEBUFFER, None};
434 attr.override_redirect = True;
435 attr.colormap = None;
436 attr.border_pixel = 0;
438 vis = pglXChooseVisual(gdi_display, screen, attribList);
439 if (vis) {
440 #ifdef __i386__
441 WORD old_fs = wine_get_fs();
442 /* Create a GLX Context. Without one we can't query GL information */
443 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
444 if (wine_get_fs() != old_fs)
446 wine_set_fs( old_fs );
447 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
448 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
449 goto done;
451 #else
452 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
453 #endif
455 if (!ctx) goto done;
457 root = RootWindow( gdi_display, vis->screen );
458 if (vis->visual != DefaultVisual( gdi_display, vis->screen ))
459 attr.colormap = XCreateColormap( gdi_display, root, vis->visual, AllocNone );
460 if ((win = XCreateWindow( gdi_display, root, -1, -1, 1, 1, 0, vis->depth, InputOutput,
461 vis->visual, CWBorderPixel | CWOverrideRedirect | CWColormap, &attr )))
462 XMapWindow( gdi_display, win );
463 else
464 win = root;
466 if(pglXMakeCurrent(gdi_display, win, ctx) == 0)
468 ERR_(winediag)( "Unable to activate OpenGL context, most likely your %s OpenGL drivers haven't been "
469 "installed correctly\n", is_win64 ? "64-bit" : "32-bit" );
470 goto done;
472 gl_renderer = (const char *)opengl_funcs.gl.p_glGetString(GL_RENDERER);
473 gl_version = (const char *)opengl_funcs.gl.p_glGetString(GL_VERSION);
474 str = (const char *) opengl_funcs.gl.p_glGetString(GL_EXTENSIONS);
475 glExtensions = HeapAlloc(GetProcessHeap(), 0, strlen(str)+sizeof(legacy_extensions));
476 strcpy(glExtensions, str);
477 strcat(glExtensions, legacy_extensions);
479 /* Get the common GLX version supported by GLX client and server ( major/minor) */
480 pglXQueryVersion(gdi_display, &glxVersion[0], &glxVersion[1]);
482 glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
483 glx_direct = pglXIsDirect(gdi_display, ctx);
485 TRACE("GL version : %s.\n", gl_version);
486 TRACE("GL renderer : %s.\n", gl_renderer);
487 TRACE("GLX version : %d.%d.\n", glxVersion[0], glxVersion[1]);
488 TRACE("Server GLX version : %s.\n", pglXQueryServerString(gdi_display, screen, GLX_VERSION));
489 TRACE("Server GLX vendor: : %s.\n", pglXQueryServerString(gdi_display, screen, GLX_VENDOR));
490 TRACE("Client GLX version : %s.\n", pglXGetClientString(gdi_display, GLX_VERSION));
491 TRACE("Client GLX vendor: : %s.\n", pglXGetClientString(gdi_display, GLX_VENDOR));
492 TRACE("Direct rendering enabled: %s\n", glx_direct ? "True" : "False");
494 if(!glx_direct)
496 int fd = ConnectionNumber(gdi_display);
497 struct sockaddr_un uaddr;
498 unsigned int uaddrlen = sizeof(struct sockaddr_un);
500 /* In general indirect rendering on a local X11 server indicates a driver problem.
501 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
503 if(!getsockname(fd, (struct sockaddr *)&uaddr, &uaddrlen) && uaddr.sun_family == AF_UNIX)
504 ERR_(winediag)("Direct rendering is disabled, most likely your %s OpenGL drivers "
505 "haven't been installed correctly (using GL renderer %s, version %s).\n",
506 is_win64 ? "64-bit" : "32-bit", debugstr_a(gl_renderer),
507 debugstr_a(gl_version));
509 else
511 /* In general you would expect that if direct rendering is returned, that you receive hardware
512 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
513 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
514 * software rendering, it shows direct rendering.
516 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
517 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
518 * it shows 'Mesa X11'.
520 if(!strcmp(gl_renderer, "Software Rasterizer") || !strcmp(gl_renderer, "Mesa X11"))
521 ERR_(winediag)("The Mesa OpenGL driver is using software rendering, most likely your %s OpenGL "
522 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
523 is_win64 ? "64-bit" : "32-bit", debugstr_a(gl_renderer),
524 debugstr_a(gl_version));
526 ret = TRUE;
528 done:
529 if(vis) XFree(vis);
530 if(ctx) {
531 pglXMakeCurrent(gdi_display, None, NULL);
532 pglXDestroyContext(gdi_display, ctx);
534 if (win != root) XDestroyWindow( gdi_display, win );
535 if (attr.colormap) XFreeColormap( gdi_display, attr.colormap );
536 if (!ret) ERR(" couldn't initialize OpenGL, expect problems\n");
537 return ret;
540 static void *opengl_handle;
542 static BOOL WINAPI init_opengl( INIT_ONCE *once, void *param, void **context )
544 char buffer[200];
545 int error_base, event_base;
546 unsigned int i;
548 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
549 and include all dependencies */
550 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, buffer, sizeof(buffer));
551 if (opengl_handle == NULL)
553 ERR( "Failed to load libGL: %s\n", buffer );
554 ERR( "OpenGL support is disabled.\n");
555 return TRUE;
558 for (i = 0; i < ARRAY_SIZE( opengl_func_names ); i++)
560 if (!(((void **)&opengl_funcs.gl)[i] = wine_dlsym( opengl_handle, opengl_func_names[i], NULL, 0 )))
562 ERR( "%s not found in libGL, disabling OpenGL.\n", opengl_func_names[i] );
563 goto failed;
567 /* redirect some standard OpenGL functions */
568 #define REDIRECT(func) \
569 do { p##func = opengl_funcs.gl.p_##func; opengl_funcs.gl.p_##func = w##func; } while(0)
570 REDIRECT( glFinish );
571 REDIRECT( glFlush );
572 REDIRECT( glGetString );
573 #undef REDIRECT
575 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
576 if (pglXGetProcAddressARB == NULL) {
577 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
578 goto failed;
581 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
583 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
584 goto failed; \
585 } while(0)
587 /* GLX 1.0 */
588 LOAD_FUNCPTR(glXChooseVisual);
589 LOAD_FUNCPTR(glXCopyContext);
590 LOAD_FUNCPTR(glXCreateContext);
591 LOAD_FUNCPTR(glXGetCurrentContext);
592 LOAD_FUNCPTR(glXGetCurrentDrawable);
593 LOAD_FUNCPTR(glXDestroyContext);
594 LOAD_FUNCPTR(glXIsDirect);
595 LOAD_FUNCPTR(glXMakeCurrent);
596 LOAD_FUNCPTR(glXSwapBuffers);
597 LOAD_FUNCPTR(glXQueryExtension);
598 LOAD_FUNCPTR(glXQueryVersion);
600 /* GLX 1.1 */
601 LOAD_FUNCPTR(glXGetClientString);
602 LOAD_FUNCPTR(glXQueryExtensionsString);
603 LOAD_FUNCPTR(glXQueryServerString);
605 /* GLX 1.3 */
606 LOAD_FUNCPTR(glXCreatePbuffer);
607 LOAD_FUNCPTR(glXCreateNewContext);
608 LOAD_FUNCPTR(glXDestroyPbuffer);
609 LOAD_FUNCPTR(glXMakeContextCurrent);
610 LOAD_FUNCPTR(glXGetFBConfigs);
611 LOAD_FUNCPTR(glXCreatePixmap);
612 LOAD_FUNCPTR(glXDestroyPixmap);
613 LOAD_FUNCPTR(glXCreateWindow);
614 LOAD_FUNCPTR(glXDestroyWindow);
615 #undef LOAD_FUNCPTR
617 /* It doesn't matter if these fail. They'll only be used if the driver reports
618 the associated extension is available (and if a driver reports the extension
619 is available but fails to provide the functions, it's quite broken) */
620 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
621 /* ARB GLX Extension */
622 LOAD_FUNCPTR(glXCreateContextAttribsARB);
623 /* EXT GLX Extension */
624 LOAD_FUNCPTR(glXSwapIntervalEXT);
625 /* MESA GLX Extension */
626 LOAD_FUNCPTR(glXSwapIntervalMESA);
627 /* SGI GLX Extension */
628 LOAD_FUNCPTR(glXSwapIntervalSGI);
629 /* NV GLX Extension */
630 LOAD_FUNCPTR(glXAllocateMemoryNV);
631 LOAD_FUNCPTR(glXFreeMemoryNV);
632 #undef LOAD_FUNCPTR
634 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed;
636 if (pglXQueryExtension(gdi_display, &error_base, &event_base)) {
637 TRACE("GLX is up and running error_base = %d\n", error_base);
638 } else {
639 ERR( "GLX extension is missing, disabling OpenGL.\n" );
640 goto failed;
642 gl_hwnd_context = XUniqueContext();
643 gl_pbuffer_context = XUniqueContext();
645 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
646 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
647 * rendering is used.
649 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
650 * depends on the reported GLX client / server version and on the client / server extension list.
651 * Those don't have to be the same.
653 * In general the server GLX information lists the capabilities in case of indirect rendering.
654 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
655 * available and in that case the client GLX informat can be used.
656 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
657 * in the GLX version/extension list. When a program does this it works for certain for both
658 * direct and indirect rendering.
660 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
661 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
662 * extension list which causes this extension not to be listed. (Wine requires this extension).
663 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
664 * pbuffers is around.
666 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
667 * the ATI drivers and from then on use GLX client information for them.
670 if(glxRequireVersion(3)) {
671 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
672 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
673 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
674 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
675 } else if (has_extension( glxExtensions, "GLX_SGIX_fbconfig")) {
676 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
677 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
678 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
680 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
681 * enable this function when the Xserver understand GLX 1.3 or newer
683 pglXQueryDrawable = NULL;
684 } else if(strcmp("ATI", pglXGetClientString(gdi_display, GLX_VENDOR)) == 0) {
685 TRACE("Overriding ATI GLX capabilities!\n");
686 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
687 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
688 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
689 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
691 /* Use client GLX information in case of the ATI drivers. We override the
692 * capabilities over here and not somewhere else as ATI might better their
693 * life in the future. In case they release proper drivers this block of
694 * code won't be called. */
695 glxExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
696 } else {
697 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n",
698 pglXQueryServerString(gdi_display, DefaultScreen(gdi_display), GLX_VERSION));
701 if (has_extension( glxExtensions, "GLX_MESA_copy_sub_buffer")) {
702 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
705 if (has_extension( glxExtensions, "GLX_MESA_query_renderer" ))
707 pglXQueryCurrentRendererIntegerMESA = pglXGetProcAddressARB(
708 (const GLubyte *)"glXQueryCurrentRendererIntegerMESA" );
709 pglXQueryCurrentRendererStringMESA = pglXGetProcAddressARB(
710 (const GLubyte *)"glXQueryCurrentRendererStringMESA" );
711 pglXQueryRendererIntegerMESA = pglXGetProcAddressARB( (const GLubyte *)"glXQueryRendererIntegerMESA" );
712 pglXQueryRendererStringMESA = pglXGetProcAddressARB( (const GLubyte *)"glXQueryRendererStringMESA" );
715 if (has_extension( glxExtensions, "GLX_OML_sync_control" ))
717 pglXWaitForSbcOML = pglXGetProcAddressARB( (const GLubyte *)"glXWaitForSbcOML" );
718 pglXSwapBuffersMscOML = pglXGetProcAddressARB( (const GLubyte *)"glXSwapBuffersMscOML" );
721 X11DRV_WineGL_LoadExtensions();
722 init_pixel_formats( gdi_display );
723 return TRUE;
725 failed:
726 wine_dlclose(opengl_handle, NULL, 0);
727 opengl_handle = NULL;
728 return TRUE;
731 static BOOL has_opengl(void)
733 static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
734 InitOnceExecuteOnce(&init_once, init_opengl, NULL, NULL);
735 return opengl_handle != NULL;
738 static const char *debugstr_fbconfig( GLXFBConfig fbconfig )
740 int id, visual, drawable;
742 if (pglXGetFBConfigAttrib( gdi_display, fbconfig, GLX_FBCONFIG_ID, &id ))
743 return "*** invalid fbconfig";
744 pglXGetFBConfigAttrib( gdi_display, fbconfig, GLX_VISUAL_ID, &visual );
745 pglXGetFBConfigAttrib( gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &drawable );
746 return wine_dbg_sprintf( "fbconfig %#x visual id %#x drawable type %#x", id, visual, drawable );
749 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, struct wgl_pbuffer* pbuf) {
750 int nAttribs = 0;
751 unsigned cur = 0;
752 int pop;
753 int drawattrib = 0;
754 int nvfloatattrib = GLX_DONT_CARE;
755 int pixelattrib = GLX_DONT_CARE;
757 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
758 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
759 while (iWGLAttr && 0 != iWGLAttr[cur]) {
760 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
762 switch (iWGLAttr[cur]) {
763 case WGL_AUX_BUFFERS_ARB:
764 pop = iWGLAttr[++cur];
765 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
766 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
767 break;
768 case WGL_COLOR_BITS_ARB:
769 pop = iWGLAttr[++cur];
770 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
771 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
772 break;
773 case WGL_BLUE_BITS_ARB:
774 pop = iWGLAttr[++cur];
775 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
776 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
777 break;
778 case WGL_RED_BITS_ARB:
779 pop = iWGLAttr[++cur];
780 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
781 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
782 break;
783 case WGL_GREEN_BITS_ARB:
784 pop = iWGLAttr[++cur];
785 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
786 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
787 break;
788 case WGL_ALPHA_BITS_ARB:
789 pop = iWGLAttr[++cur];
790 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
791 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
792 break;
793 case WGL_DEPTH_BITS_ARB:
794 pop = iWGLAttr[++cur];
795 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
796 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
797 break;
798 case WGL_STENCIL_BITS_ARB:
799 pop = iWGLAttr[++cur];
800 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
801 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
802 break;
803 case WGL_DOUBLE_BUFFER_ARB:
804 pop = iWGLAttr[++cur];
805 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
806 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
807 break;
808 case WGL_STEREO_ARB:
809 pop = iWGLAttr[++cur];
810 PUSH2(oGLXAttr, GLX_STEREO, pop);
811 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur, pop);
812 break;
814 case WGL_PIXEL_TYPE_ARB:
815 pop = iWGLAttr[++cur];
816 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
817 switch (pop) {
818 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
819 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
820 /* 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 */
821 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
822 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT: pixelattrib = GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT; break ;
823 default:
824 ERR("unexpected PixelType(%x)\n", pop);
825 pop = 0;
827 break;
829 case WGL_SUPPORT_GDI_ARB:
830 /* This flag is set in a pixel format */
831 pop = iWGLAttr[++cur];
832 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
833 break;
835 case WGL_DRAW_TO_BITMAP_ARB:
836 /* This flag is set in a pixel format */
837 pop = iWGLAttr[++cur];
838 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
839 break;
841 case WGL_DRAW_TO_WINDOW_ARB:
842 pop = iWGLAttr[++cur];
843 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
844 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
845 if (pop) {
846 drawattrib |= GLX_WINDOW_BIT;
848 break;
850 case WGL_DRAW_TO_PBUFFER_ARB:
851 pop = iWGLAttr[++cur];
852 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
853 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
854 if (pop) {
855 drawattrib |= GLX_PBUFFER_BIT;
857 break;
859 case WGL_ACCELERATION_ARB:
860 /* This flag is set in a pixel format */
861 pop = iWGLAttr[++cur];
862 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur, pop);
863 break;
865 case WGL_SUPPORT_OPENGL_ARB:
866 pop = iWGLAttr[++cur];
867 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
868 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
869 break;
871 case WGL_SWAP_METHOD_ARB:
872 pop = iWGLAttr[++cur];
873 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur, pop);
874 if (has_swap_method)
876 switch (pop)
878 case WGL_SWAP_EXCHANGE_ARB:
879 pop = GLX_SWAP_EXCHANGE_OML;
880 break;
881 case WGL_SWAP_COPY_ARB:
882 pop = GLX_SWAP_COPY_OML;
883 break;
884 case WGL_SWAP_UNDEFINED_ARB:
885 pop = GLX_SWAP_UNDEFINED_OML;
886 break;
887 default:
888 ERR("Unexpected swap method %#x.\n", pop);
889 pop = GLX_DONT_CARE;
891 PUSH2(oGLXAttr, GLX_SWAP_METHOD_OML, pop);
893 else
895 WARN("GLX_OML_swap_method not supported, ignoring attribute.\n");
897 break;
899 case WGL_PBUFFER_LARGEST_ARB:
900 pop = iWGLAttr[++cur];
901 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
902 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
903 break;
905 case WGL_SAMPLE_BUFFERS_ARB:
906 pop = iWGLAttr[++cur];
907 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
908 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
909 break;
911 case WGL_SAMPLES_ARB:
912 pop = iWGLAttr[++cur];
913 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
914 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
915 break;
917 case WGL_TEXTURE_FORMAT_ARB:
918 case WGL_TEXTURE_TARGET_ARB:
919 case WGL_MIPMAP_TEXTURE_ARB:
920 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
921 pop = iWGLAttr[++cur];
922 if (NULL == pbuf) {
923 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
925 if (!use_render_texture_emulation) {
926 if (WGL_NO_TEXTURE_ARB != pop) {
927 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
928 return -1; /** error: don't support it */
929 } else {
930 drawattrib |= GLX_PBUFFER_BIT;
933 break ;
934 case WGL_FLOAT_COMPONENTS_NV:
935 nvfloatattrib = iWGLAttr[++cur];
936 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
937 break ;
938 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
939 case WGL_BIND_TO_TEXTURE_RGB_ARB:
940 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
941 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
942 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
943 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
944 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
945 pop = iWGLAttr[++cur];
946 /** cannot be converted, see direct handling on
947 * - wglGetPixelFormatAttribivARB
948 * TODO: wglChoosePixelFormat
950 break ;
951 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
952 pop = iWGLAttr[++cur];
953 PUSH2(oGLXAttr, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, pop);
954 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur, pop);
955 break ;
957 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
958 pop = iWGLAttr[++cur];
959 PUSH2(oGLXAttr, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT, pop);
960 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur, pop);
961 break ;
962 default:
963 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
964 cur++;
965 break;
967 ++cur;
970 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
971 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
972 * pixmap and pbuffer formats appear as well. */
973 if (!drawattrib) drawattrib = GLX_DONT_CARE;
974 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
975 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
977 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
978 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
979 * GLX_DONT_CARE unless it is overridden. */
980 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
981 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
983 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
984 if (has_extension(glxExtensions, "GLX_NV_float_buffer")) {
985 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
986 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
989 return nAttribs;
992 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
994 int render_type, render_type_bit;
995 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
996 switch(render_type_bit)
998 case GLX_RGBA_BIT:
999 render_type = GLX_RGBA_TYPE;
1000 break;
1001 case GLX_COLOR_INDEX_BIT:
1002 render_type = GLX_COLOR_INDEX_TYPE;
1003 break;
1004 case GLX_RGBA_FLOAT_BIT:
1005 render_type = GLX_RGBA_FLOAT_TYPE;
1006 break;
1007 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT:
1008 render_type = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
1009 break;
1010 default:
1011 ERR("Unknown render_type: %x\n", render_type_bit);
1012 render_type = 0;
1014 return render_type;
1017 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
1018 static BOOL check_fbconfig_bitmap_capability(Display *display, GLXFBConfig fbconfig)
1020 int dbuf, value;
1021 pglXGetFBConfigAttrib(display, fbconfig, GLX_DOUBLEBUFFER, &dbuf);
1022 pglXGetFBConfigAttrib(gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &value);
1024 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
1025 * the GLX_PIXMAP_BIT set. */
1026 return !dbuf && (value & GLX_PIXMAP_BIT);
1029 static void init_pixel_formats( Display *display )
1031 struct wgl_pixel_format *list;
1032 int size = 0, onscreen_size = 0;
1033 int fmt_id, nCfgs, i, run, bmp_formats;
1034 GLXFBConfig* cfgs;
1035 XVisualInfo *visinfo;
1037 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
1038 if (NULL == cfgs || 0 == nCfgs) {
1039 if(cfgs != NULL) XFree(cfgs);
1040 ERR("glXChooseFBConfig returns NULL\n");
1041 return;
1044 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
1045 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
1046 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
1047 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
1049 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
1051 for(i=0, bmp_formats=0; i<nCfgs; i++)
1053 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
1054 bmp_formats++;
1056 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats);
1058 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nCfgs + bmp_formats) * sizeof(*list));
1060 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
1061 * Do this as GLX doesn't guarantee that the list is sorted */
1062 for(run=0; run < 2; run++)
1064 for(i=0; i<nCfgs; i++) {
1065 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
1066 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
1068 /* The first run we only add onscreen formats (ones which have an associated X Visual).
1069 * The second run we only set offscreen formats. */
1070 if(!run && visinfo)
1072 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
1073 * The contents is copied to the destination using XCopyArea. For the copying to work
1074 * the depth of the source and destination window should be the same. In general this should
1075 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
1076 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
1077 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
1078 * list formats with the same depth. */
1079 if(visinfo->depth != default_visual.depth)
1081 XFree(visinfo);
1082 continue;
1085 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1086 list[size].fbconfig = cfgs[i];
1087 list[size].visual = visinfo;
1088 list[size].fmt_id = fmt_id;
1089 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1090 list[size].dwFlags = 0;
1091 size++;
1092 onscreen_size++;
1094 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
1095 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
1097 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1098 list[size].fbconfig = cfgs[i];
1099 list[size].visual = visinfo;
1100 list[size].fmt_id = fmt_id;
1101 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1102 list[size].dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_GENERIC_FORMAT;
1103 size++;
1104 onscreen_size++;
1106 } else if(run && !visinfo) {
1107 int window_drawable=0;
1108 pglXGetFBConfigAttrib(gdi_display, cfgs[i], GLX_DRAWABLE_TYPE, &window_drawable);
1110 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
1111 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1112 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1113 * likely make our child window opengl rendering more complicated since likely you can't use
1114 * XCopyArea on a GLX Window.
1115 * For now ignore fbconfigs which are window drawable but lack a visual. */
1116 if(window_drawable & GLX_WINDOW_BIT)
1118 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id);
1119 continue;
1122 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1123 list[size].fbconfig = cfgs[i];
1124 list[size].fmt_id = fmt_id;
1125 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1126 list[size].dwFlags = 0;
1127 size++;
1129 else if (visinfo) XFree(visinfo);
1133 XFree(cfgs);
1135 pixel_formats = list;
1136 nb_pixel_formats = size;
1137 nb_onscreen_formats = onscreen_size;
1140 static inline BOOL is_valid_pixel_format( int format )
1142 return format > 0 && format <= nb_pixel_formats;
1145 static inline BOOL is_onscreen_pixel_format( int format )
1147 return format > 0 && format <= nb_onscreen_formats;
1150 static inline int pixel_format_index( const struct wgl_pixel_format *format )
1152 return format - pixel_formats + 1;
1155 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1156 * In our WGL implementation we only support a subset of these formats namely the format of
1157 * Wine's main visual and offscreen formats (if they are available).
1158 * This function converts a WGL format to its corresponding GLX one.
1160 static const struct wgl_pixel_format *get_pixel_format(Display *display, int iPixelFormat, BOOL AllowOffscreen)
1162 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1163 * iPixelFormat in case of probing the number of pixelformats.
1165 if (is_valid_pixel_format( iPixelFormat ) &&
1166 (is_onscreen_pixel_format( iPixelFormat ) || AllowOffscreen)) {
1167 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n",
1168 pixel_formats[iPixelFormat-1].fmt_id, iPixelFormat);
1169 return &pixel_formats[iPixelFormat-1];
1171 return NULL;
1174 static struct gl_drawable *grab_gl_drawable( struct gl_drawable *gl )
1176 InterlockedIncrement( &gl->ref );
1177 return gl;
1180 static void release_gl_drawable( struct gl_drawable *gl )
1182 if (!gl) return;
1183 if (InterlockedDecrement( &gl->ref )) return;
1184 switch (gl->type)
1186 case DC_GL_WINDOW:
1187 case DC_GL_CHILD_WIN:
1188 TRACE( "destroying %lx drawable %lx\n", gl->window, gl->drawable );
1189 pglXDestroyWindow( gdi_display, gl->drawable );
1190 XDestroyWindow( gdi_display, gl->window );
1191 break;
1192 case DC_GL_PIXMAP_WIN:
1193 TRACE( "destroying pixmap %lx drawable %lx\n", gl->pixmap, gl->drawable );
1194 pglXDestroyPixmap( gdi_display, gl->drawable );
1195 XFreePixmap( gdi_display, gl->pixmap );
1196 break;
1197 default:
1198 break;
1200 HeapFree( GetProcessHeap(), 0, gl );
1203 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1204 static void mark_drawable_dirty( struct gl_drawable *old, struct gl_drawable *new )
1206 struct wgl_context *ctx;
1208 EnterCriticalSection( &context_section );
1209 LIST_FOR_EACH_ENTRY( ctx, &context_list, struct wgl_context, entry )
1211 if (old == ctx->drawables[0] || old == ctx->new_drawables[0])
1213 release_gl_drawable( ctx->new_drawables[0] );
1214 ctx->new_drawables[0] = grab_gl_drawable( new );
1216 if (old == ctx->drawables[1] || old == ctx->new_drawables[1])
1218 release_gl_drawable( ctx->new_drawables[1] );
1219 ctx->new_drawables[1] = grab_gl_drawable( new );
1222 LeaveCriticalSection( &context_section );
1225 /* Given the current context, make sure its drawable is sync'd */
1226 static inline void sync_context(struct wgl_context *context)
1228 BOOL refresh = FALSE;
1230 EnterCriticalSection( &context_section );
1231 if (context->new_drawables[0])
1233 release_gl_drawable( context->drawables[0] );
1234 context->drawables[0] = context->new_drawables[0];
1235 context->new_drawables[0] = NULL;
1236 refresh = TRUE;
1238 if (context->new_drawables[1])
1240 release_gl_drawable( context->drawables[1] );
1241 context->drawables[1] = context->new_drawables[1];
1242 context->new_drawables[1] = NULL;
1243 refresh = TRUE;
1245 if (refresh)
1247 if (glxRequireVersion(3))
1248 pglXMakeContextCurrent(gdi_display, context->drawables[0]->drawable,
1249 context->drawables[1]->drawable, context->ctx);
1250 else
1251 pglXMakeCurrent(gdi_display, context->drawables[0]->drawable, context->ctx);
1253 LeaveCriticalSection( &context_section );
1256 static BOOL set_swap_interval(GLXDrawable drawable, int interval)
1258 BOOL ret = TRUE;
1260 switch (swap_control_method)
1262 case GLX_SWAP_CONTROL_EXT:
1263 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
1264 pglXSwapIntervalEXT(gdi_display, drawable, interval);
1265 XSync(gdi_display, False);
1266 ret = !X11DRV_check_error();
1267 break;
1269 case GLX_SWAP_CONTROL_MESA:
1270 ret = !pglXSwapIntervalMESA(interval);
1271 break;
1273 case GLX_SWAP_CONTROL_SGI:
1274 /* wglSwapIntervalEXT considers an interval value of zero to mean that
1275 * vsync should be disabled, but glXSwapIntervalSGI considers such a
1276 * value to be an error. Just silently ignore the request for now.
1278 if (!interval)
1279 WARN("Request to disable vertical sync is not handled\n");
1280 else
1281 ret = !pglXSwapIntervalSGI(interval);
1282 break;
1284 case GLX_SWAP_CONTROL_NONE:
1285 /* Unlikely to happen on modern GLX implementations */
1286 WARN("Request to adjust swap interval is not handled\n");
1287 break;
1290 return ret;
1293 static struct gl_drawable *get_gl_drawable( HWND hwnd, HDC hdc )
1295 struct gl_drawable *gl;
1297 EnterCriticalSection( &context_section );
1298 if (hwnd && !XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl ))
1299 gl = grab_gl_drawable( gl );
1300 else if (hdc && !XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl ))
1301 gl = grab_gl_drawable( gl );
1302 else
1303 gl = NULL;
1304 LeaveCriticalSection( &context_section );
1305 return gl;
1308 static GLXContext create_glxcontext(Display *display, struct wgl_context *context, GLXContext shareList)
1310 GLXContext ctx;
1312 if(context->gl3_context)
1314 if(context->numAttribs)
1315 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, GL_TRUE, context->attribList);
1316 else
1317 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, GL_TRUE, NULL);
1319 else if(context->fmt->visual)
1320 ctx = pglXCreateContext(gdi_display, context->fmt->visual, shareList, GL_TRUE);
1321 else /* Create a GLX Context for a pbuffer */
1322 ctx = pglXCreateNewContext(gdi_display, context->fmt->fbconfig, context->fmt->render_type, shareList, TRUE);
1324 return ctx;
1328 /***********************************************************************
1329 * create_gl_drawable
1331 static struct gl_drawable *create_gl_drawable( HWND hwnd, const struct wgl_pixel_format *format )
1333 struct gl_drawable *gl, *prev;
1334 XVisualInfo *visual = format->visual;
1335 RECT rect;
1336 int width, height;
1338 GetClientRect( hwnd, &rect );
1339 width = min( max( 1, rect.right ), 65535 );
1340 height = min( max( 1, rect.bottom ), 65535 );
1342 if (!(gl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*gl) ))) return NULL;
1344 /* Default GLX and WGL swap interval is 1, but in case of glXSwapIntervalSGI
1345 * there is no way to query it, so we have to store it here.
1347 gl->swap_interval = 1;
1348 gl->refresh_swap_interval = TRUE;
1349 gl->format = format;
1350 gl->ref = 1;
1352 if (GetAncestor( hwnd, GA_PARENT ) == GetDesktopWindow()) /* top-level window */
1354 gl->type = DC_GL_WINDOW;
1355 gl->window = create_client_window( hwnd, visual );
1356 if (gl->window)
1357 gl->drawable = pglXCreateWindow( gdi_display, gl->format->fbconfig, gl->window, NULL );
1358 TRACE( "%p created client %lx drawable %lx\n", hwnd, gl->window, gl->drawable );
1360 #ifdef SONAME_LIBXCOMPOSITE
1361 else if(usexcomposite)
1363 gl->type = DC_GL_CHILD_WIN;
1364 gl->window = create_client_window( hwnd, visual );
1365 if (gl->window)
1367 gl->drawable = pglXCreateWindow( gdi_display, gl->format->fbconfig, gl->window, NULL );
1368 pXCompositeRedirectWindow( gdi_display, gl->window, CompositeRedirectManual );
1370 TRACE( "%p created child %lx drawable %lx\n", hwnd, gl->window, gl->drawable );
1372 #endif
1373 else
1375 WARN("XComposite is not available, using GLXPixmap hack\n");
1377 gl->type = DC_GL_PIXMAP_WIN;
1378 gl->pixmap = XCreatePixmap( gdi_display, root_window, width, height, visual->depth );
1379 if (gl->pixmap)
1381 gl->drawable = pglXCreatePixmap( gdi_display, gl->format->fbconfig, gl->pixmap, NULL );
1382 if (!gl->drawable) XFreePixmap( gdi_display, gl->pixmap );
1383 gl->pixmap_size.cx = width;
1384 gl->pixmap_size.cy = height;
1388 if (!gl->drawable)
1390 HeapFree( GetProcessHeap(), 0, gl );
1391 return NULL;
1394 EnterCriticalSection( &context_section );
1395 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&prev ))
1397 gl->swap_interval = prev->swap_interval;
1398 release_gl_drawable( prev );
1400 XSaveContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char *)grab_gl_drawable(gl) );
1401 LeaveCriticalSection( &context_section );
1402 return gl;
1406 /***********************************************************************
1407 * set_win_format
1409 static BOOL set_win_format( HWND hwnd, const struct wgl_pixel_format *format )
1411 struct gl_drawable *gl;
1413 if (!format->visual) return FALSE;
1415 if (!(gl = create_gl_drawable( hwnd, format ))) return FALSE;
1417 TRACE( "created GL drawable %lx for win %p %s\n",
1418 gl->drawable, hwnd, debugstr_fbconfig( format->fbconfig ));
1420 XFlush( gdi_display );
1421 release_gl_drawable( gl );
1423 __wine_set_pixel_format( hwnd, pixel_format_index( format ));
1424 return TRUE;
1428 static BOOL set_pixel_format(HDC hdc, int format, BOOL allow_change)
1430 const struct wgl_pixel_format *fmt;
1431 int value;
1432 HWND hwnd = WindowFromDC( hdc );
1434 TRACE("(%p,%d)\n", hdc, format);
1436 if (!hwnd || hwnd == GetDesktopWindow())
1438 WARN( "not a valid window DC %p/%p\n", hdc, hwnd );
1439 return FALSE;
1442 fmt = get_pixel_format(gdi_display, format, FALSE /* Offscreen */);
1443 if (!fmt)
1445 ERR( "Invalid format %d\n", format );
1446 return FALSE;
1449 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1450 if (!(value & GLX_WINDOW_BIT))
1452 WARN( "Pixel format %d is not compatible for window rendering\n", format );
1453 return FALSE;
1456 if (!allow_change)
1458 struct gl_drawable *gl;
1459 if ((gl = get_gl_drawable( hwnd, hdc )))
1461 int prev = pixel_format_index( gl->format );
1462 release_gl_drawable( gl );
1463 return prev == format; /* cannot change it if already set */
1467 return set_win_format( hwnd, fmt );
1471 /***********************************************************************
1472 * sync_gl_drawable
1474 void sync_gl_drawable( HWND hwnd )
1476 struct gl_drawable *old, *new;
1478 if (!(old = get_gl_drawable( hwnd, 0 ))) return;
1480 switch (old->type)
1482 case DC_GL_PIXMAP_WIN:
1483 if (!(new = create_gl_drawable( hwnd, old->format ))) break;
1484 mark_drawable_dirty( old, new );
1485 XFlush( gdi_display );
1486 TRACE( "Recreated GL drawable %lx to replace %lx\n", new->drawable, old->drawable );
1487 release_gl_drawable( new );
1488 break;
1489 default:
1490 break;
1492 release_gl_drawable( old );
1496 /***********************************************************************
1497 * set_gl_drawable_parent
1499 void set_gl_drawable_parent( HWND hwnd, HWND parent )
1501 struct gl_drawable *old, *new;
1503 if (!(old = get_gl_drawable( hwnd, 0 ))) return;
1505 TRACE( "setting drawable %lx parent %p\n", old->drawable, parent );
1507 switch (old->type)
1509 case DC_GL_WINDOW:
1510 break;
1511 case DC_GL_CHILD_WIN:
1512 case DC_GL_PIXMAP_WIN:
1513 if (parent == GetDesktopWindow()) break;
1514 /* fall through */
1515 default:
1516 release_gl_drawable( old );
1517 return;
1520 if ((new = create_gl_drawable( hwnd, old->format )))
1522 mark_drawable_dirty( old, new );
1523 release_gl_drawable( new );
1525 else
1527 destroy_gl_drawable( hwnd );
1528 __wine_set_pixel_format( hwnd, 0 );
1530 release_gl_drawable( old );
1534 /***********************************************************************
1535 * destroy_gl_drawable
1537 void destroy_gl_drawable( HWND hwnd )
1539 struct gl_drawable *gl;
1541 EnterCriticalSection( &context_section );
1542 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl ))
1544 XDeleteContext( gdi_display, (XID)hwnd, gl_hwnd_context );
1545 release_gl_drawable( gl );
1547 LeaveCriticalSection( &context_section );
1552 * glxdrv_DescribePixelFormat
1554 * Get the pixel-format descriptor associated to the given id
1556 static int glxdrv_wglDescribePixelFormat( HDC hdc, int iPixelFormat,
1557 UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd)
1559 /*XVisualInfo *vis;*/
1560 int value;
1561 int rb,gb,bb,ab;
1562 const struct wgl_pixel_format *fmt;
1564 if (!has_opengl()) return 0;
1566 TRACE("(%p,%d,%d,%p)\n", hdc, iPixelFormat, nBytes, ppfd);
1568 if (!ppfd) return nb_onscreen_formats;
1570 /* 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 */
1571 fmt = get_pixel_format(gdi_display, iPixelFormat, FALSE /* Offscreen */);
1572 if (!fmt) {
1573 WARN("unexpected format %d\n", iPixelFormat);
1574 return 0;
1577 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1578 ERR("Wrong structure size !\n");
1579 /* Should set error */
1580 return 0;
1583 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1584 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1585 ppfd->nVersion = 1;
1587 /* These flags are always the same... */
1588 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1589 /* Now the flags extracted from the Visual */
1591 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1592 if(value & GLX_WINDOW_BIT)
1593 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1595 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1596 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1597 * 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
1598 * offered the GDI bit either. */
1599 ppfd->dwFlags |= fmt->dwFlags & (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI);
1601 /* PFD_GENERIC_FORMAT - gdi software rendering
1602 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1603 * none set - full hardware accelerated by a ICD
1605 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1606 ppfd->dwFlags |= fmt->dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED);
1608 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1609 if (value) {
1610 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1611 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1613 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1615 /* Pixel type */
1616 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1617 if (value & GLX_RGBA_BIT)
1618 ppfd->iPixelType = PFD_TYPE_RGBA;
1619 else
1620 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1622 /* Color bits */
1623 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1624 ppfd->cColorBits = value;
1626 /* Red, green, blue and alpha bits / shifts */
1627 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1628 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1629 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1630 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1631 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1633 ppfd->cRedBits = rb;
1634 ppfd->cRedShift = gb + bb + ab;
1635 ppfd->cBlueBits = bb;
1636 ppfd->cBlueShift = ab;
1637 ppfd->cGreenBits = gb;
1638 ppfd->cGreenShift = bb + ab;
1639 ppfd->cAlphaBits = ab;
1640 ppfd->cAlphaShift = 0;
1641 } else {
1642 ppfd->cRedBits = 0;
1643 ppfd->cRedShift = 0;
1644 ppfd->cBlueBits = 0;
1645 ppfd->cBlueShift = 0;
1646 ppfd->cGreenBits = 0;
1647 ppfd->cGreenShift = 0;
1648 ppfd->cAlphaBits = 0;
1649 ppfd->cAlphaShift = 0;
1652 /* Accum RGBA bits */
1653 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1654 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1655 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1656 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1658 ppfd->cAccumBits = rb+gb+bb+ab;
1659 ppfd->cAccumRedBits = rb;
1660 ppfd->cAccumGreenBits = gb;
1661 ppfd->cAccumBlueBits = bb;
1662 ppfd->cAccumAlphaBits = ab;
1664 /* Aux bits */
1665 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1666 ppfd->cAuxBuffers = value;
1668 /* Depth bits */
1669 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1670 ppfd->cDepthBits = value;
1672 /* stencil bits */
1673 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1674 ppfd->cStencilBits = value;
1676 ppfd->iLayerType = PFD_MAIN_PLANE;
1678 if (TRACE_ON(wgl)) {
1679 dump_PIXELFORMATDESCRIPTOR(ppfd);
1682 return nb_onscreen_formats;
1685 /***********************************************************************
1686 * glxdrv_wglGetPixelFormat
1688 static int glxdrv_wglGetPixelFormat( HDC hdc )
1690 struct gl_drawable *gl;
1691 int ret = 0;
1693 if ((gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1695 ret = pixel_format_index( gl->format );
1696 /* Offscreen formats can't be used with traditional WGL calls.
1697 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1698 if (!is_onscreen_pixel_format( ret )) ret = 1;
1699 release_gl_drawable( gl );
1701 TRACE( "%p -> %d\n", hdc, ret );
1702 return ret;
1705 /***********************************************************************
1706 * glxdrv_wglSetPixelFormat
1708 static BOOL glxdrv_wglSetPixelFormat( HDC hdc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd )
1710 return set_pixel_format(hdc, iPixelFormat, FALSE);
1713 /***********************************************************************
1714 * glxdrv_wglCopyContext
1716 static BOOL glxdrv_wglCopyContext(struct wgl_context *src, struct wgl_context *dst, UINT mask)
1718 TRACE("%p -> %p mask %#x\n", src, dst, mask);
1720 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1722 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1723 return TRUE;
1726 /***********************************************************************
1727 * glxdrv_wglCreateContext
1729 static struct wgl_context *glxdrv_wglCreateContext( HDC hdc )
1731 struct wgl_context *ret;
1732 struct gl_drawable *gl;
1734 if (!(gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1736 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1737 return NULL;
1740 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret))))
1742 ret->hdc = hdc;
1743 ret->fmt = gl->format;
1744 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1745 EnterCriticalSection( &context_section );
1746 list_add_head( &context_list, &ret->entry );
1747 LeaveCriticalSection( &context_section );
1749 release_gl_drawable( gl );
1750 TRACE( "%p -> %p\n", hdc, ret );
1751 return ret;
1754 /***********************************************************************
1755 * glxdrv_wglDeleteContext
1757 static BOOL glxdrv_wglDeleteContext(struct wgl_context *ctx)
1759 struct wgl_pbuffer *pb;
1761 TRACE("(%p)\n", ctx);
1763 EnterCriticalSection( &context_section );
1764 list_remove( &ctx->entry );
1765 LIST_FOR_EACH_ENTRY( pb, &pbuffer_list, struct wgl_pbuffer, entry )
1767 if (pb->prev_context == ctx->ctx) {
1768 pglXDestroyContext(gdi_display, pb->tmp_context);
1769 pb->prev_context = pb->tmp_context = NULL;
1772 LeaveCriticalSection( &context_section );
1774 if (ctx->ctx) pglXDestroyContext( gdi_display, ctx->ctx );
1775 release_gl_drawable( ctx->drawables[0] );
1776 release_gl_drawable( ctx->drawables[1] );
1777 release_gl_drawable( ctx->new_drawables[0] );
1778 release_gl_drawable( ctx->new_drawables[1] );
1779 return HeapFree( GetProcessHeap(), 0, ctx );
1782 /***********************************************************************
1783 * glxdrv_wglGetProcAddress
1785 static PROC glxdrv_wglGetProcAddress(LPCSTR lpszProc)
1787 if (!strncmp(lpszProc, "wgl", 3)) return NULL;
1788 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1791 static void set_context_drawables( struct wgl_context *ctx, struct gl_drawable *draw,
1792 struct gl_drawable *read )
1794 struct gl_drawable *prev[4];
1795 int i;
1797 prev[0] = ctx->drawables[0];
1798 prev[1] = ctx->drawables[1];
1799 prev[2] = ctx->new_drawables[0];
1800 prev[3] = ctx->new_drawables[1];
1801 ctx->drawables[0] = grab_gl_drawable( draw );
1802 ctx->drawables[1] = read ? grab_gl_drawable( read ) : NULL;
1803 ctx->new_drawables[0] = ctx->new_drawables[1] = NULL;
1804 for (i = 0; i < 4; i++) release_gl_drawable( prev[i] );
1807 /***********************************************************************
1808 * glxdrv_wglMakeCurrent
1810 static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx)
1812 BOOL ret = FALSE;
1813 struct gl_drawable *gl;
1815 TRACE("(%p,%p)\n", hdc, ctx);
1817 if (!ctx)
1819 pglXMakeCurrent(gdi_display, None, NULL);
1820 NtCurrentTeb()->glContext = NULL;
1821 return TRUE;
1824 if ((gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
1826 if (ctx->fmt != gl->format)
1828 WARN( "mismatched pixel format hdc %p %p ctx %p %p\n", hdc, gl->format, ctx, ctx->fmt );
1829 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1830 goto done;
1833 TRACE("hdc %p drawable %lx fmt %p ctx %p %s\n", hdc, gl->drawable, gl->format, ctx->ctx,
1834 debugstr_fbconfig( gl->format->fbconfig ));
1836 EnterCriticalSection( &context_section );
1837 ret = pglXMakeCurrent(gdi_display, gl->drawable, ctx->ctx);
1838 if (ret)
1840 NtCurrentTeb()->glContext = ctx;
1841 ctx->has_been_current = TRUE;
1842 ctx->hdc = hdc;
1843 set_context_drawables( ctx, gl, gl );
1844 ctx->refresh_drawables = FALSE;
1845 LeaveCriticalSection( &context_section );
1846 goto done;
1848 LeaveCriticalSection( &context_section );
1850 SetLastError( ERROR_INVALID_HANDLE );
1852 done:
1853 release_gl_drawable( gl );
1854 TRACE( "%p,%p returning %d\n", hdc, ctx, ret );
1855 return ret;
1858 /***********************************************************************
1859 * X11DRV_wglMakeContextCurrentARB
1861 static BOOL X11DRV_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *ctx )
1863 BOOL ret = FALSE;
1864 struct gl_drawable *draw_gl, *read_gl = NULL;
1866 TRACE("(%p,%p,%p)\n", draw_hdc, read_hdc, ctx);
1868 if (!ctx)
1870 pglXMakeCurrent(gdi_display, None, NULL);
1871 NtCurrentTeb()->glContext = NULL;
1872 return TRUE;
1875 if (!pglXMakeContextCurrent) return FALSE;
1877 if ((draw_gl = get_gl_drawable( WindowFromDC( draw_hdc ), draw_hdc )))
1879 read_gl = get_gl_drawable( WindowFromDC( read_hdc ), read_hdc );
1881 EnterCriticalSection( &context_section );
1882 ret = pglXMakeContextCurrent(gdi_display, draw_gl->drawable,
1883 read_gl ? read_gl->drawable : 0, ctx->ctx);
1884 if (ret)
1886 ctx->has_been_current = TRUE;
1887 ctx->hdc = draw_hdc;
1888 set_context_drawables( ctx, draw_gl, read_gl );
1889 ctx->refresh_drawables = FALSE;
1890 NtCurrentTeb()->glContext = ctx;
1891 LeaveCriticalSection( &context_section );
1892 goto done;
1894 LeaveCriticalSection( &context_section );
1896 SetLastError( ERROR_INVALID_HANDLE );
1897 done:
1898 release_gl_drawable( read_gl );
1899 release_gl_drawable( draw_gl );
1900 TRACE( "%p,%p,%p returning %d\n", draw_hdc, read_hdc, ctx, ret );
1901 return ret;
1904 /***********************************************************************
1905 * glxdrv_wglShareLists
1907 static BOOL glxdrv_wglShareLists(struct wgl_context *org, struct wgl_context *dest)
1909 TRACE("(%p, %p)\n", org, dest);
1911 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1912 * at context creation time but in case of WGL it is done using wglShareLists.
1913 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1914 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1915 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1916 * so there delaying context creation doesn't work.
1918 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1919 * and when a program requests sharing we recreate the destination context if it hasn't been made
1920 * current or when it hasn't shared display lists before.
1923 if((org->has_been_current && dest->has_been_current) || dest->has_been_current)
1925 ERR("Could not share display lists, one of the contexts has been current already !\n");
1926 return FALSE;
1928 else if(dest->sharing)
1930 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1931 return FALSE;
1933 else
1935 /* Re-create the GLX context and share display lists */
1936 pglXDestroyContext(gdi_display, dest->ctx);
1937 dest->ctx = create_glxcontext(gdi_display, dest, org->ctx);
1938 TRACE(" re-created context (%p) for Wine context %p (%s) sharing lists with ctx %p (%s)\n",
1939 dest->ctx, dest, debugstr_fbconfig(dest->fmt->fbconfig),
1940 org->ctx, debugstr_fbconfig( org->fmt->fbconfig));
1942 org->sharing = TRUE;
1943 dest->sharing = TRUE;
1944 return TRUE;
1946 return FALSE;
1949 static void wglFinish(void)
1951 struct x11drv_escape_flush_gl_drawable escape;
1952 struct gl_drawable *gl;
1953 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1955 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
1956 escape.gl_drawable = 0;
1957 escape.flush = FALSE;
1959 if ((gl = get_gl_drawable( WindowFromDC( ctx->hdc ), 0 )))
1961 switch (gl->type)
1963 case DC_GL_PIXMAP_WIN: escape.gl_drawable = gl->pixmap; break;
1964 case DC_GL_CHILD_WIN: escape.gl_drawable = gl->window; break;
1965 default: break;
1967 sync_context(ctx);
1968 release_gl_drawable( gl );
1971 pglFinish();
1972 if (escape.gl_drawable) ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1975 static void wglFlush(void)
1977 struct x11drv_escape_flush_gl_drawable escape;
1978 struct gl_drawable *gl;
1979 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1981 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
1982 escape.gl_drawable = 0;
1983 escape.flush = FALSE;
1985 if ((gl = get_gl_drawable( WindowFromDC( ctx->hdc ), 0 )))
1987 switch (gl->type)
1989 case DC_GL_PIXMAP_WIN: escape.gl_drawable = gl->pixmap; break;
1990 case DC_GL_CHILD_WIN: escape.gl_drawable = gl->window; break;
1991 default: break;
1993 sync_context(ctx);
1994 release_gl_drawable( gl );
1997 pglFlush();
1998 if (escape.gl_drawable) ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2001 static const GLubyte *wglGetString(GLenum name)
2003 if (name == GL_EXTENSIONS && glExtensions) return (const GLubyte *)glExtensions;
2004 return pglGetString(name);
2007 /***********************************************************************
2008 * X11DRV_wglCreateContextAttribsARB
2010 static struct wgl_context *X11DRV_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *hShareContext,
2011 const int* attribList )
2013 struct wgl_context *ret;
2014 struct gl_drawable *gl;
2015 int err = 0;
2017 TRACE("(%p %p %p)\n", hdc, hShareContext, attribList);
2019 if (!(gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
2021 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
2022 return NULL;
2025 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret))))
2027 ret->hdc = hdc;
2028 ret->fmt = gl->format;
2029 ret->gl3_context = TRUE;
2030 if (attribList)
2032 int *pContextAttribList = &ret->attribList[0];
2033 /* attribList consists of pairs {token, value] terminated with 0 */
2034 while(attribList[0] != 0)
2036 TRACE("%#x %#x\n", attribList[0], attribList[1]);
2037 switch(attribList[0])
2039 case WGL_CONTEXT_MAJOR_VERSION_ARB:
2040 pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
2041 pContextAttribList[1] = attribList[1];
2042 pContextAttribList += 2;
2043 ret->numAttribs++;
2044 break;
2045 case WGL_CONTEXT_MINOR_VERSION_ARB:
2046 pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB;
2047 pContextAttribList[1] = attribList[1];
2048 pContextAttribList += 2;
2049 ret->numAttribs++;
2050 break;
2051 case WGL_CONTEXT_LAYER_PLANE_ARB:
2052 break;
2053 case WGL_CONTEXT_FLAGS_ARB:
2054 pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB;
2055 pContextAttribList[1] = attribList[1];
2056 pContextAttribList += 2;
2057 ret->numAttribs++;
2058 break;
2059 case WGL_CONTEXT_OPENGL_NO_ERROR_ARB:
2060 pContextAttribList[0] = GLX_CONTEXT_OPENGL_NO_ERROR_ARB;
2061 pContextAttribList[1] = attribList[1];
2062 pContextAttribList += 2;
2063 ret->numAttribs++;
2064 break;
2065 case WGL_CONTEXT_PROFILE_MASK_ARB:
2066 pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
2067 pContextAttribList[1] = attribList[1];
2068 pContextAttribList += 2;
2069 ret->numAttribs++;
2070 break;
2071 case WGL_RENDERER_ID_WINE:
2072 pContextAttribList[0] = GLX_RENDERER_ID_MESA;
2073 pContextAttribList[1] = attribList[1];
2074 pContextAttribList += 2;
2075 ret->numAttribs++;
2076 break;
2077 default:
2078 ERR("Unhandled attribList pair: %#x %#x\n", attribList[0], attribList[1]);
2080 attribList += 2;
2084 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
2085 ret->ctx = create_glxcontext(gdi_display, ret, hShareContext ? hShareContext->ctx : NULL);
2086 XSync(gdi_display, False);
2087 if ((err = X11DRV_check_error()) || !ret->ctx)
2089 /* In the future we should convert the GLX error to a win32 one here if needed */
2090 WARN("Context creation failed (error %#x).\n", err);
2091 HeapFree( GetProcessHeap(), 0, ret );
2092 ret = NULL;
2094 else
2096 EnterCriticalSection( &context_section );
2097 list_add_head( &context_list, &ret->entry );
2098 LeaveCriticalSection( &context_section );
2102 release_gl_drawable( gl );
2103 TRACE( "%p -> %p\n", hdc, ret );
2104 return ret;
2108 * X11DRV_wglGetExtensionsStringARB
2110 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2112 static const char *X11DRV_wglGetExtensionsStringARB(HDC hdc)
2114 TRACE("() returning \"%s\"\n", wglExtensions);
2115 return wglExtensions;
2119 * X11DRV_wglCreatePbufferARB
2121 * WGL_ARB_pbuffer: wglCreatePbufferARB
2123 static struct wgl_pbuffer *X11DRV_wglCreatePbufferARB( HDC hdc, int iPixelFormat, int iWidth, int iHeight,
2124 const int *piAttribList )
2126 struct wgl_pbuffer* object;
2127 const struct wgl_pixel_format *fmt;
2128 int attribs[256];
2129 int nAttribs = 0;
2131 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2133 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2134 fmt = get_pixel_format(gdi_display, iPixelFormat, TRUE /* Offscreen */);
2135 if(!fmt) {
2136 ERR("(%p): invalid pixel format %d\n", hdc, iPixelFormat);
2137 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2138 return NULL;
2141 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2142 if (NULL == object) {
2143 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2144 return NULL;
2146 object->width = iWidth;
2147 object->height = iHeight;
2148 object->fmt = fmt;
2150 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2151 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2152 while (piAttribList && 0 != *piAttribList) {
2153 int attr_v;
2154 switch (*piAttribList) {
2155 case WGL_PBUFFER_LARGEST_ARB: {
2156 ++piAttribList;
2157 attr_v = *piAttribList;
2158 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2159 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2160 break;
2163 case WGL_TEXTURE_FORMAT_ARB: {
2164 ++piAttribList;
2165 attr_v = *piAttribList;
2166 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2167 if (WGL_NO_TEXTURE_ARB == attr_v) {
2168 object->use_render_texture = 0;
2169 } else {
2170 if (!use_render_texture_emulation) {
2171 SetLastError(ERROR_INVALID_DATA);
2172 goto create_failed;
2174 switch (attr_v) {
2175 case WGL_TEXTURE_RGB_ARB:
2176 object->use_render_texture = GL_RGB;
2177 object->texture_bpp = 3;
2178 object->texture_format = GL_RGB;
2179 object->texture_type = GL_UNSIGNED_BYTE;
2180 break;
2181 case WGL_TEXTURE_RGBA_ARB:
2182 object->use_render_texture = GL_RGBA;
2183 object->texture_bpp = 4;
2184 object->texture_format = GL_RGBA;
2185 object->texture_type = GL_UNSIGNED_BYTE;
2186 break;
2188 /* WGL_FLOAT_COMPONENTS_NV */
2189 case WGL_TEXTURE_FLOAT_R_NV:
2190 object->use_render_texture = GL_FLOAT_R_NV;
2191 object->texture_bpp = 4;
2192 object->texture_format = GL_RED;
2193 object->texture_type = GL_FLOAT;
2194 break;
2195 case WGL_TEXTURE_FLOAT_RG_NV:
2196 object->use_render_texture = GL_FLOAT_RG_NV;
2197 object->texture_bpp = 8;
2198 object->texture_format = GL_LUMINANCE_ALPHA;
2199 object->texture_type = GL_FLOAT;
2200 break;
2201 case WGL_TEXTURE_FLOAT_RGB_NV:
2202 object->use_render_texture = GL_FLOAT_RGB_NV;
2203 object->texture_bpp = 12;
2204 object->texture_format = GL_RGB;
2205 object->texture_type = GL_FLOAT;
2206 break;
2207 case WGL_TEXTURE_FLOAT_RGBA_NV:
2208 object->use_render_texture = GL_FLOAT_RGBA_NV;
2209 object->texture_bpp = 16;
2210 object->texture_format = GL_RGBA;
2211 object->texture_type = GL_FLOAT;
2212 break;
2213 default:
2214 ERR("Unknown texture format: %x\n", attr_v);
2215 SetLastError(ERROR_INVALID_DATA);
2216 goto create_failed;
2219 break;
2222 case WGL_TEXTURE_TARGET_ARB: {
2223 ++piAttribList;
2224 attr_v = *piAttribList;
2225 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2226 if (WGL_NO_TEXTURE_ARB == attr_v) {
2227 object->texture_target = 0;
2228 } else {
2229 if (!use_render_texture_emulation) {
2230 SetLastError(ERROR_INVALID_DATA);
2231 goto create_failed;
2233 switch (attr_v) {
2234 case WGL_TEXTURE_CUBE_MAP_ARB: {
2235 if (iWidth != iHeight) {
2236 SetLastError(ERROR_INVALID_DATA);
2237 goto create_failed;
2239 object->texture_target = GL_TEXTURE_CUBE_MAP;
2240 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2241 break;
2243 case WGL_TEXTURE_1D_ARB: {
2244 if (1 != iHeight) {
2245 SetLastError(ERROR_INVALID_DATA);
2246 goto create_failed;
2248 object->texture_target = GL_TEXTURE_1D;
2249 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2250 break;
2252 case WGL_TEXTURE_2D_ARB: {
2253 object->texture_target = GL_TEXTURE_2D;
2254 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2255 break;
2257 case WGL_TEXTURE_RECTANGLE_NV: {
2258 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2259 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2260 break;
2262 default:
2263 ERR("Unknown texture target: %x\n", attr_v);
2264 SetLastError(ERROR_INVALID_DATA);
2265 goto create_failed;
2268 break;
2271 case WGL_MIPMAP_TEXTURE_ARB: {
2272 ++piAttribList;
2273 attr_v = *piAttribList;
2274 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2275 if (!use_render_texture_emulation) {
2276 SetLastError(ERROR_INVALID_DATA);
2277 goto create_failed;
2279 break;
2282 ++piAttribList;
2285 PUSH1(attribs, None);
2286 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2287 TRACE("new Pbuffer drawable as %lx\n", object->drawable);
2288 if (!object->drawable) {
2289 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2290 goto create_failed; /* unexpected error */
2292 EnterCriticalSection( &context_section );
2293 list_add_head( &pbuffer_list, &object->entry );
2294 LeaveCriticalSection( &context_section );
2295 TRACE("->(%p)\n", object);
2296 return object;
2298 create_failed:
2299 HeapFree(GetProcessHeap(), 0, object);
2300 TRACE("->(FAILED)\n");
2301 return NULL;
2305 * X11DRV_wglDestroyPbufferARB
2307 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2309 static BOOL X11DRV_wglDestroyPbufferARB( struct wgl_pbuffer *object )
2311 TRACE("(%p)\n", object);
2313 EnterCriticalSection( &context_section );
2314 list_remove( &object->entry );
2315 LeaveCriticalSection( &context_section );
2316 pglXDestroyPbuffer(gdi_display, object->drawable);
2317 if (object->tmp_context)
2318 pglXDestroyContext(gdi_display, object->tmp_context);
2319 HeapFree(GetProcessHeap(), 0, object);
2320 return GL_TRUE;
2324 * X11DRV_wglGetPbufferDCARB
2326 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2328 static HDC X11DRV_wglGetPbufferDCARB( struct wgl_pbuffer *object )
2330 struct x11drv_escape_set_drawable escape;
2331 struct gl_drawable *gl, *prev;
2332 HDC hdc;
2334 hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
2335 if (!hdc) return 0;
2337 if (!(gl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*gl) )))
2339 DeleteDC( hdc );
2340 return 0;
2342 gl->type = DC_GL_PBUFFER;
2343 gl->drawable = object->drawable;
2344 gl->format = object->fmt;
2345 gl->ref = 1;
2347 EnterCriticalSection( &context_section );
2348 if (!XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&prev ))
2349 release_gl_drawable( prev );
2350 XSaveContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char *)gl );
2351 LeaveCriticalSection( &context_section );
2353 escape.code = X11DRV_SET_DRAWABLE;
2354 escape.drawable = object->drawable;
2355 escape.mode = IncludeInferiors;
2356 SetRect( &escape.dc_rect, 0, 0, object->width, object->height );
2357 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2359 TRACE( "(%p)->(%p)\n", object, hdc );
2360 return hdc;
2364 * X11DRV_wglQueryPbufferARB
2366 * WGL_ARB_pbuffer: wglQueryPbufferARB
2368 static BOOL X11DRV_wglQueryPbufferARB( struct wgl_pbuffer *object, int iAttribute, int *piValue )
2370 TRACE("(%p, 0x%x, %p)\n", object, iAttribute, piValue);
2372 switch (iAttribute) {
2373 case WGL_PBUFFER_WIDTH_ARB:
2374 pglXQueryDrawable(gdi_display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2375 break;
2376 case WGL_PBUFFER_HEIGHT_ARB:
2377 pglXQueryDrawable(gdi_display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2378 break;
2380 case WGL_PBUFFER_LOST_ARB:
2381 /* GLX Pbuffers cannot be lost by default. We can support this by
2382 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2383 * to receive pixel buffer clobber events, however that may or may
2384 * not give any benefit */
2385 *piValue = GL_FALSE;
2386 break;
2388 case WGL_TEXTURE_FORMAT_ARB:
2389 if (!object->use_render_texture) {
2390 *piValue = WGL_NO_TEXTURE_ARB;
2391 } else {
2392 if (!use_render_texture_emulation) {
2393 SetLastError(ERROR_INVALID_HANDLE);
2394 return GL_FALSE;
2396 switch(object->use_render_texture) {
2397 case GL_RGB:
2398 *piValue = WGL_TEXTURE_RGB_ARB;
2399 break;
2400 case GL_RGBA:
2401 *piValue = WGL_TEXTURE_RGBA_ARB;
2402 break;
2403 /* WGL_FLOAT_COMPONENTS_NV */
2404 case GL_FLOAT_R_NV:
2405 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2406 break;
2407 case GL_FLOAT_RG_NV:
2408 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2409 break;
2410 case GL_FLOAT_RGB_NV:
2411 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2412 break;
2413 case GL_FLOAT_RGBA_NV:
2414 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2415 break;
2416 default:
2417 ERR("Unknown texture format: %x\n", object->use_render_texture);
2420 break;
2422 case WGL_TEXTURE_TARGET_ARB:
2423 if (!object->texture_target){
2424 *piValue = WGL_NO_TEXTURE_ARB;
2425 } else {
2426 if (!use_render_texture_emulation) {
2427 SetLastError(ERROR_INVALID_DATA);
2428 return GL_FALSE;
2430 switch (object->texture_target) {
2431 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2432 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2433 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2434 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2437 break;
2439 case WGL_MIPMAP_TEXTURE_ARB:
2440 *piValue = GL_FALSE; /** don't support that */
2441 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2442 break;
2444 default:
2445 FIXME("unexpected attribute %x\n", iAttribute);
2446 break;
2449 return GL_TRUE;
2453 * X11DRV_wglReleasePbufferDCARB
2455 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2457 static int X11DRV_wglReleasePbufferDCARB( struct wgl_pbuffer *object, HDC hdc )
2459 struct gl_drawable *gl;
2461 TRACE("(%p, %p)\n", object, hdc);
2463 EnterCriticalSection( &context_section );
2465 if (!XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl ))
2467 XDeleteContext( gdi_display, (XID)hdc, gl_pbuffer_context );
2468 release_gl_drawable( gl );
2470 else hdc = 0;
2472 LeaveCriticalSection( &context_section );
2474 return hdc && DeleteDC(hdc);
2478 * X11DRV_wglSetPbufferAttribARB
2480 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2482 static BOOL X11DRV_wglSetPbufferAttribARB( struct wgl_pbuffer *object, const int *piAttribList )
2484 GLboolean ret = GL_FALSE;
2486 WARN("(%p, %p): alpha-testing, report any problem\n", object, piAttribList);
2488 if (!object->use_render_texture) {
2489 SetLastError(ERROR_INVALID_HANDLE);
2490 return GL_FALSE;
2492 if (use_render_texture_emulation) {
2493 return GL_TRUE;
2495 return ret;
2499 * X11DRV_wglChoosePixelFormatARB
2501 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2503 static BOOL X11DRV_wglChoosePixelFormatARB( HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList,
2504 UINT nMaxFormats, int *piFormats, UINT *nNumFormats )
2506 int attribs[256];
2507 int nAttribs = 0;
2508 GLXFBConfig* cfgs;
2509 int nCfgs = 0;
2510 int it;
2511 int fmt_id;
2512 int start, end;
2513 UINT pfmt_it = 0;
2514 int run;
2515 int i;
2516 DWORD dwFlags = 0;
2518 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2519 if (NULL != pfAttribFList) {
2520 FIXME("unused pfAttribFList\n");
2523 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2524 if (-1 == nAttribs) {
2525 WARN("Cannot convert WGL to GLX attributes\n");
2526 return GL_FALSE;
2528 PUSH1(attribs, None);
2530 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2531 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the pixel format. We don't query these attributes
2532 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on.
2534 for(i=0; piAttribIList[i] != 0; i+=2)
2536 switch(piAttribIList[i])
2538 case WGL_DRAW_TO_BITMAP_ARB:
2539 if(piAttribIList[i+1])
2540 dwFlags |= PFD_DRAW_TO_BITMAP;
2541 break;
2542 case WGL_ACCELERATION_ARB:
2543 switch(piAttribIList[i+1])
2545 case WGL_NO_ACCELERATION_ARB:
2546 dwFlags |= PFD_GENERIC_FORMAT;
2547 break;
2548 case WGL_GENERIC_ACCELERATION_ARB:
2549 dwFlags |= PFD_GENERIC_ACCELERATED;
2550 break;
2551 case WGL_FULL_ACCELERATION_ARB:
2552 /* Nothing to do */
2553 break;
2555 break;
2556 case WGL_SUPPORT_GDI_ARB:
2557 if(piAttribIList[i+1])
2558 dwFlags |= PFD_SUPPORT_GDI;
2559 break;
2563 /* Search for FB configurations matching the requirements in attribs */
2564 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2565 if (NULL == cfgs) {
2566 WARN("Compatible Pixel Format not found\n");
2567 return GL_FALSE;
2570 /* Loop through all matching formats and check if they are suitable.
2571 * Note that this function should at max return nMaxFormats different formats */
2572 for(run=0; run < 2; run++)
2574 for (it = 0; it < nCfgs && pfmt_it < nMaxFormats; ++it)
2576 if (pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id))
2578 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2579 continue;
2582 /* During the first run we only want onscreen formats and during the second only offscreen */
2583 start = run == 1 ? nb_onscreen_formats : 0;
2584 end = run == 1 ? nb_pixel_formats : nb_onscreen_formats;
2586 for (i = start; i < end; i++)
2588 if (pixel_formats[i].fmt_id == fmt_id && (pixel_formats[i].dwFlags & dwFlags) == dwFlags)
2590 piFormats[pfmt_it++] = i + 1;
2591 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n",
2592 it + 1, nCfgs, fmt_id, i + 1);
2593 break;
2599 *nNumFormats = pfmt_it;
2600 /** free list */
2601 XFree(cfgs);
2602 return GL_TRUE;
2606 * X11DRV_wglGetPixelFormatAttribivARB
2608 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2610 static BOOL X11DRV_wglGetPixelFormatAttribivARB( HDC hdc, int iPixelFormat, int iLayerPlane,
2611 UINT nAttributes, const int *piAttributes, int *piValues )
2613 UINT i;
2614 const struct wgl_pixel_format *fmt;
2615 int hTest;
2616 int tmp;
2617 int curGLXAttr = 0;
2619 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2621 if (0 < iLayerPlane) {
2622 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2623 return GL_FALSE;
2626 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2627 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2628 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2629 fmt = get_pixel_format(gdi_display, iPixelFormat, TRUE /* Offscreen */);
2630 if(!fmt) {
2631 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2634 for (i = 0; i < nAttributes; ++i) {
2635 const int curWGLAttr = piAttributes[i];
2636 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2638 switch (curWGLAttr) {
2639 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2640 piValues[i] = nb_pixel_formats;
2641 continue;
2643 case WGL_SUPPORT_OPENGL_ARB:
2644 piValues[i] = GL_TRUE;
2645 continue;
2647 case WGL_ACCELERATION_ARB:
2648 curGLXAttr = GLX_CONFIG_CAVEAT;
2649 if (!fmt) goto pix_error;
2650 if(fmt->dwFlags & PFD_GENERIC_FORMAT)
2651 piValues[i] = WGL_NO_ACCELERATION_ARB;
2652 else if(fmt->dwFlags & PFD_GENERIC_ACCELERATED)
2653 piValues[i] = WGL_GENERIC_ACCELERATION_ARB;
2654 else
2655 piValues[i] = WGL_FULL_ACCELERATION_ARB;
2656 continue;
2658 case WGL_TRANSPARENT_ARB:
2659 curGLXAttr = GLX_TRANSPARENT_TYPE;
2660 if (!fmt) goto pix_error;
2661 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2662 if (hTest) goto get_error;
2663 piValues[i] = GL_FALSE;
2664 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2665 continue;
2667 case WGL_PIXEL_TYPE_ARB:
2668 curGLXAttr = GLX_RENDER_TYPE;
2669 if (!fmt) goto pix_error;
2670 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2671 if (hTest) goto get_error;
2672 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2673 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2674 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2675 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2676 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2677 else if (tmp & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) { piValues[i] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT; }
2678 else {
2679 ERR("unexpected RenderType(%x)\n", tmp);
2680 piValues[i] = WGL_TYPE_RGBA_ARB;
2682 continue;
2684 case WGL_COLOR_BITS_ARB:
2685 curGLXAttr = GLX_BUFFER_SIZE;
2686 break;
2688 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2689 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2690 if (!use_render_texture_emulation) {
2691 piValues[i] = GL_FALSE;
2692 continue;
2694 curGLXAttr = GLX_RENDER_TYPE;
2695 if (!fmt) goto pix_error;
2696 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2697 if (hTest) goto get_error;
2698 if (GLX_COLOR_INDEX_BIT == tmp) {
2699 piValues[i] = GL_FALSE;
2700 continue;
2702 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2703 if (hTest) goto get_error;
2704 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2705 continue;
2707 case WGL_BLUE_BITS_ARB:
2708 curGLXAttr = GLX_BLUE_SIZE;
2709 break;
2710 case WGL_RED_BITS_ARB:
2711 curGLXAttr = GLX_RED_SIZE;
2712 break;
2713 case WGL_GREEN_BITS_ARB:
2714 curGLXAttr = GLX_GREEN_SIZE;
2715 break;
2716 case WGL_ALPHA_BITS_ARB:
2717 curGLXAttr = GLX_ALPHA_SIZE;
2718 break;
2719 case WGL_DEPTH_BITS_ARB:
2720 curGLXAttr = GLX_DEPTH_SIZE;
2721 break;
2722 case WGL_STENCIL_BITS_ARB:
2723 curGLXAttr = GLX_STENCIL_SIZE;
2724 break;
2725 case WGL_DOUBLE_BUFFER_ARB:
2726 curGLXAttr = GLX_DOUBLEBUFFER;
2727 break;
2728 case WGL_STEREO_ARB:
2729 curGLXAttr = GLX_STEREO;
2730 break;
2731 case WGL_AUX_BUFFERS_ARB:
2732 curGLXAttr = GLX_AUX_BUFFERS;
2733 break;
2735 case WGL_SUPPORT_GDI_ARB:
2736 if (!fmt) goto pix_error;
2737 piValues[i] = (fmt->dwFlags & PFD_SUPPORT_GDI) != 0;
2738 continue;
2740 case WGL_DRAW_TO_BITMAP_ARB:
2741 if (!fmt) goto pix_error;
2742 piValues[i] = (fmt->dwFlags & PFD_DRAW_TO_BITMAP) != 0;
2743 continue;
2745 case WGL_DRAW_TO_WINDOW_ARB:
2746 case WGL_DRAW_TO_PBUFFER_ARB:
2747 if (!fmt) goto pix_error;
2748 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2749 if (hTest) goto get_error;
2750 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2751 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2752 piValues[i] = GL_TRUE;
2753 else
2754 piValues[i] = GL_FALSE;
2755 continue;
2757 case WGL_SWAP_METHOD_ARB:
2758 if (has_swap_method)
2760 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_SWAP_METHOD_OML, &tmp);
2761 if (hTest) goto get_error;
2762 switch (tmp)
2764 case GLX_SWAP_EXCHANGE_OML:
2765 piValues[i] = WGL_SWAP_EXCHANGE_ARB;
2766 break;
2767 case GLX_SWAP_COPY_OML:
2768 piValues[i] = WGL_SWAP_COPY_ARB;
2769 break;
2770 case GLX_SWAP_UNDEFINED_OML:
2771 piValues[i] = WGL_SWAP_UNDEFINED_ARB;
2772 break;
2773 default:
2774 ERR("Unexpected swap method %x.\n", tmp);
2777 else
2779 WARN("GLX_OML_swap_method not supported, returning WGL_SWAP_EXCHANGE_ARB.\n");
2780 piValues[i] = WGL_SWAP_EXCHANGE_ARB;
2782 continue;
2784 case WGL_PBUFFER_LARGEST_ARB:
2785 curGLXAttr = GLX_LARGEST_PBUFFER;
2786 break;
2788 case WGL_SAMPLE_BUFFERS_ARB:
2789 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2790 break;
2792 case WGL_SAMPLES_ARB:
2793 curGLXAttr = GLX_SAMPLES_ARB;
2794 break;
2796 case WGL_FLOAT_COMPONENTS_NV:
2797 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2798 break;
2800 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
2801 curGLXAttr = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT;
2802 break;
2804 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
2805 curGLXAttr = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
2806 break;
2808 case WGL_ACCUM_RED_BITS_ARB:
2809 curGLXAttr = GLX_ACCUM_RED_SIZE;
2810 break;
2811 case WGL_ACCUM_GREEN_BITS_ARB:
2812 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2813 break;
2814 case WGL_ACCUM_BLUE_BITS_ARB:
2815 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2816 break;
2817 case WGL_ACCUM_ALPHA_BITS_ARB:
2818 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2819 break;
2820 case WGL_ACCUM_BITS_ARB:
2821 if (!fmt) goto pix_error;
2822 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2823 if (hTest) goto get_error;
2824 piValues[i] = tmp;
2825 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2826 if (hTest) goto get_error;
2827 piValues[i] += tmp;
2828 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2829 if (hTest) goto get_error;
2830 piValues[i] += tmp;
2831 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2832 if (hTest) goto get_error;
2833 piValues[i] += tmp;
2834 continue;
2836 default:
2837 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2840 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2841 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2842 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2844 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2845 * and check which options can work using iPixelFormat=0 and which not.
2846 * A problem would be that this function is an extension. This would
2847 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2849 if (0 != curGLXAttr && iPixelFormat != 0) {
2850 if (!fmt) goto pix_error;
2851 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2852 if (hTest) goto get_error;
2853 curGLXAttr = 0;
2854 } else {
2855 piValues[i] = GL_FALSE;
2858 return GL_TRUE;
2860 get_error:
2861 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2862 return GL_FALSE;
2864 pix_error:
2865 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nb_pixel_formats);
2866 return GL_FALSE;
2870 * X11DRV_wglGetPixelFormatAttribfvARB
2872 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2874 static BOOL X11DRV_wglGetPixelFormatAttribfvARB( HDC hdc, int iPixelFormat, int iLayerPlane,
2875 UINT nAttributes, const int *piAttributes, FLOAT *pfValues )
2877 int *attr;
2878 int ret;
2879 UINT i;
2881 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2883 /* Allocate a temporary array to store integer values */
2884 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2885 if (!attr) {
2886 ERR("couldn't allocate %d array\n", nAttributes);
2887 return GL_FALSE;
2890 /* Piggy-back on wglGetPixelFormatAttribivARB */
2891 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2892 if (ret) {
2893 /* Convert integer values to float. Should also check for attributes
2894 that can give decimal values here */
2895 for (i=0; i<nAttributes;i++) {
2896 pfValues[i] = attr[i];
2900 HeapFree(GetProcessHeap(), 0, attr);
2901 return ret;
2905 * X11DRV_wglBindTexImageARB
2907 * WGL_ARB_render_texture: wglBindTexImageARB
2909 static BOOL X11DRV_wglBindTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2911 GLboolean ret = GL_FALSE;
2913 TRACE("(%p, %d)\n", object, iBuffer);
2915 if (!object->use_render_texture) {
2916 SetLastError(ERROR_INVALID_HANDLE);
2917 return GL_FALSE;
2920 if (use_render_texture_emulation) {
2921 static BOOL initialized = FALSE;
2922 int prev_binded_texture = 0;
2923 GLXContext prev_context;
2924 GLXDrawable prev_drawable;
2926 prev_context = pglXGetCurrentContext();
2927 prev_drawable = pglXGetCurrentDrawable();
2929 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2930 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2931 isn't ideal performance wise but I wasn't able to get other ways working.
2933 if(!initialized) {
2934 initialized = TRUE; /* Only show the FIXME once for performance reasons */
2935 FIXME("partial stub!\n");
2938 TRACE("drawable=%lx, context=%p\n", object->drawable, prev_context);
2939 if (!object->tmp_context || object->prev_context != prev_context) {
2940 if (object->tmp_context)
2941 pglXDestroyContext(gdi_display, object->tmp_context);
2942 object->tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2943 object->prev_context = prev_context;
2946 opengl_funcs.gl.p_glGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2948 /* Switch to our pbuffer */
2949 pglXMakeCurrent(gdi_display, object->drawable, object->tmp_context);
2951 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2952 * After that copy the pbuffer texture data. */
2953 opengl_funcs.gl.p_glBindTexture(object->texture_target, prev_binded_texture);
2954 opengl_funcs.gl.p_glCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2956 /* Switch back to the original drawable and context */
2957 pglXMakeCurrent(gdi_display, prev_drawable, prev_context);
2958 return GL_TRUE;
2961 return ret;
2965 * X11DRV_wglReleaseTexImageARB
2967 * WGL_ARB_render_texture: wglReleaseTexImageARB
2969 static BOOL X11DRV_wglReleaseTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2971 GLboolean ret = GL_FALSE;
2973 TRACE("(%p, %d)\n", object, iBuffer);
2975 if (!object->use_render_texture) {
2976 SetLastError(ERROR_INVALID_HANDLE);
2977 return GL_FALSE;
2979 if (use_render_texture_emulation) {
2980 return GL_TRUE;
2982 return ret;
2986 * X11DRV_wglGetExtensionsStringEXT
2988 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2990 static const char *X11DRV_wglGetExtensionsStringEXT(void)
2992 TRACE("() returning \"%s\"\n", wglExtensions);
2993 return wglExtensions;
2997 * X11DRV_wglGetSwapIntervalEXT
2999 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3001 static int X11DRV_wglGetSwapIntervalEXT(void)
3003 struct wgl_context *ctx = NtCurrentTeb()->glContext;
3004 struct gl_drawable *gl;
3005 int swap_interval;
3007 TRACE("()\n");
3009 if (!(gl = get_gl_drawable( WindowFromDC( ctx->hdc ), ctx->hdc )))
3011 /* This can't happen because a current WGL context is required to get
3012 * here. Likely the application is buggy.
3014 WARN("No GL drawable found, returning swap interval 0\n");
3015 return 0;
3018 swap_interval = gl->swap_interval;
3019 release_gl_drawable(gl);
3021 return swap_interval;
3025 * X11DRV_wglSwapIntervalEXT
3027 * WGL_EXT_swap_control: wglSwapIntervalEXT
3029 static BOOL X11DRV_wglSwapIntervalEXT(int interval)
3031 struct wgl_context *ctx = NtCurrentTeb()->glContext;
3032 struct gl_drawable *gl;
3033 BOOL ret;
3035 TRACE("(%d)\n", interval);
3037 /* Without WGL/GLX_EXT_swap_control_tear a negative interval
3038 * is invalid.
3040 if (interval < 0 && !has_swap_control_tear)
3042 SetLastError(ERROR_INVALID_DATA);
3043 return FALSE;
3046 if (!(gl = get_gl_drawable( WindowFromDC( ctx->hdc ), ctx->hdc )))
3048 SetLastError(ERROR_DC_NOT_FOUND);
3049 return FALSE;
3052 EnterCriticalSection( &context_section );
3053 ret = set_swap_interval(gl->drawable, interval);
3054 gl->refresh_swap_interval = FALSE;
3055 if (ret)
3056 gl->swap_interval = interval;
3057 else
3058 SetLastError(ERROR_DC_NOT_FOUND);
3060 LeaveCriticalSection( &context_section );
3061 release_gl_drawable(gl);
3063 return ret;
3067 * X11DRV_wglSetPixelFormatWINE
3069 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3070 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3072 static BOOL X11DRV_wglSetPixelFormatWINE(HDC hdc, int format)
3074 return set_pixel_format(hdc, format, TRUE);
3077 static BOOL X11DRV_wglQueryCurrentRendererIntegerWINE( GLenum attribute, GLuint *value )
3079 return pglXQueryCurrentRendererIntegerMESA( attribute, value );
3082 static const char *X11DRV_wglQueryCurrentRendererStringWINE( GLenum attribute )
3084 return pglXQueryCurrentRendererStringMESA( attribute );
3087 static BOOL X11DRV_wglQueryRendererIntegerWINE( HDC dc, GLint renderer, GLenum attribute, GLuint *value )
3089 return pglXQueryRendererIntegerMESA( gdi_display, DefaultScreen(gdi_display), renderer, attribute, value );
3092 static const char *X11DRV_wglQueryRendererStringWINE( HDC dc, GLint renderer, GLenum attribute )
3094 return pglXQueryRendererStringMESA( gdi_display, DefaultScreen(gdi_display), renderer, attribute );
3098 * glxRequireVersion (internal)
3100 * Check if the supported GLX version matches requiredVersion.
3102 static BOOL glxRequireVersion(int requiredVersion)
3104 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3105 return (requiredVersion <= glxVersion[1]);
3108 static void register_extension(const char *ext)
3110 if (wglExtensions[0])
3111 strcat(wglExtensions, " ");
3112 strcat(wglExtensions, ext);
3114 TRACE("'%s'\n", ext);
3118 * X11DRV_WineGL_LoadExtensions
3120 static void X11DRV_WineGL_LoadExtensions(void)
3122 wglExtensions[0] = 0;
3124 /* ARB Extensions */
3126 if (has_extension( glxExtensions, "GLX_ARB_create_context"))
3128 register_extension( "WGL_ARB_create_context" );
3129 opengl_funcs.ext.p_wglCreateContextAttribsARB = X11DRV_wglCreateContextAttribsARB;
3131 if (has_extension( glxExtensions, "GLX_ARB_create_context_no_error" ))
3132 register_extension( "WGL_ARB_create_context_no_error" );
3133 if (has_extension( glxExtensions, "GLX_ARB_create_context_profile"))
3134 register_extension("WGL_ARB_create_context_profile");
3137 if (has_extension( glxExtensions, "GLX_ARB_fbconfig_float"))
3139 register_extension("WGL_ARB_pixel_format_float");
3140 register_extension("WGL_ATI_pixel_format_float");
3143 register_extension( "WGL_ARB_extensions_string" );
3144 opengl_funcs.ext.p_wglGetExtensionsStringARB = X11DRV_wglGetExtensionsStringARB;
3146 if (glxRequireVersion(3))
3148 register_extension( "WGL_ARB_make_current_read" );
3149 opengl_funcs.ext.p_wglGetCurrentReadDCARB = (void *)1; /* never called */
3150 opengl_funcs.ext.p_wglMakeContextCurrentARB = X11DRV_wglMakeContextCurrentARB;
3153 if (has_extension( glxExtensions, "GLX_ARB_multisample")) register_extension( "WGL_ARB_multisample" );
3155 if (glxRequireVersion(3))
3157 register_extension( "WGL_ARB_pbuffer" );
3158 opengl_funcs.ext.p_wglCreatePbufferARB = X11DRV_wglCreatePbufferARB;
3159 opengl_funcs.ext.p_wglDestroyPbufferARB = X11DRV_wglDestroyPbufferARB;
3160 opengl_funcs.ext.p_wglGetPbufferDCARB = X11DRV_wglGetPbufferDCARB;
3161 opengl_funcs.ext.p_wglQueryPbufferARB = X11DRV_wglQueryPbufferARB;
3162 opengl_funcs.ext.p_wglReleasePbufferDCARB = X11DRV_wglReleasePbufferDCARB;
3163 opengl_funcs.ext.p_wglSetPbufferAttribARB = X11DRV_wglSetPbufferAttribARB;
3166 register_extension( "WGL_ARB_pixel_format" );
3167 opengl_funcs.ext.p_wglChoosePixelFormatARB = X11DRV_wglChoosePixelFormatARB;
3168 opengl_funcs.ext.p_wglGetPixelFormatAttribfvARB = X11DRV_wglGetPixelFormatAttribfvARB;
3169 opengl_funcs.ext.p_wglGetPixelFormatAttribivARB = X11DRV_wglGetPixelFormatAttribivARB;
3171 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3172 if (has_extension( glxExtensions, "GLX_ARB_render_texture") ||
3173 (glxRequireVersion(3) && use_render_texture_emulation))
3175 register_extension( "WGL_ARB_render_texture" );
3176 opengl_funcs.ext.p_wglBindTexImageARB = X11DRV_wglBindTexImageARB;
3177 opengl_funcs.ext.p_wglReleaseTexImageARB = X11DRV_wglReleaseTexImageARB;
3179 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3180 if (has_extension( glxExtensions, "GLX_NV_float_buffer"))
3181 register_extension("WGL_NV_float_buffer");
3183 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3184 if (has_extension(glExtensions, "GL_NV_texture_rectangle"))
3185 register_extension("WGL_NV_render_texture_rectangle");
3188 /* EXT Extensions */
3190 register_extension( "WGL_EXT_extensions_string" );
3191 opengl_funcs.ext.p_wglGetExtensionsStringEXT = X11DRV_wglGetExtensionsStringEXT;
3193 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3194 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3195 register_extension( "WGL_EXT_swap_control" );
3196 opengl_funcs.ext.p_wglSwapIntervalEXT = X11DRV_wglSwapIntervalEXT;
3197 opengl_funcs.ext.p_wglGetSwapIntervalEXT = X11DRV_wglGetSwapIntervalEXT;
3199 if (has_extension( glxExtensions, "GLX_EXT_framebuffer_sRGB"))
3200 register_extension("WGL_EXT_framebuffer_sRGB");
3202 if (has_extension( glxExtensions, "GLX_EXT_fbconfig_packed_float"))
3203 register_extension("WGL_EXT_pixel_format_packed_float");
3205 if (has_extension( glxExtensions, "GLX_EXT_swap_control"))
3207 swap_control_method = GLX_SWAP_CONTROL_EXT;
3208 if (has_extension( glxExtensions, "GLX_EXT_swap_control_tear"))
3210 register_extension("WGL_EXT_swap_control_tear");
3211 has_swap_control_tear = TRUE;
3214 else if (has_extension( glxExtensions, "GLX_MESA_swap_control"))
3216 swap_control_method = GLX_SWAP_CONTROL_MESA;
3218 else if (has_extension( glxExtensions, "GLX_SGI_swap_control"))
3220 swap_control_method = GLX_SWAP_CONTROL_SGI;
3223 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3224 if (has_extension(glExtensions, "GL_NV_vertex_array_range"))
3226 register_extension( "WGL_NV_vertex_array_range" );
3227 opengl_funcs.ext.p_wglAllocateMemoryNV = pglXAllocateMemoryNV;
3228 opengl_funcs.ext.p_wglFreeMemoryNV = pglXFreeMemoryNV;
3231 if (has_extension(glxExtensions, "GLX_OML_swap_method"))
3232 has_swap_method = TRUE;
3234 /* WINE-specific WGL Extensions */
3236 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3237 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3239 register_extension( "WGL_WINE_pixel_format_passthrough" );
3240 opengl_funcs.ext.p_wglSetPixelFormatWINE = X11DRV_wglSetPixelFormatWINE;
3242 if (has_extension( glxExtensions, "GLX_MESA_query_renderer" ))
3244 register_extension( "WGL_WINE_query_renderer" );
3245 opengl_funcs.ext.p_wglQueryCurrentRendererIntegerWINE = X11DRV_wglQueryCurrentRendererIntegerWINE;
3246 opengl_funcs.ext.p_wglQueryCurrentRendererStringWINE = X11DRV_wglQueryCurrentRendererStringWINE;
3247 opengl_funcs.ext.p_wglQueryRendererIntegerWINE = X11DRV_wglQueryRendererIntegerWINE;
3248 opengl_funcs.ext.p_wglQueryRendererStringWINE = X11DRV_wglQueryRendererStringWINE;
3254 * glxdrv_SwapBuffers
3256 * Swap the buffers of this DC
3258 static BOOL glxdrv_wglSwapBuffers( HDC hdc )
3260 struct x11drv_escape_flush_gl_drawable escape;
3261 struct gl_drawable *gl;
3262 struct wgl_context *ctx = NtCurrentTeb()->glContext;
3263 INT64 ust, msc, sbc, target_sbc = 0;
3265 TRACE("(%p)\n", hdc);
3267 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
3268 escape.gl_drawable = 0;
3269 escape.flush = !pglXWaitForSbcOML;
3271 if (!(gl = get_gl_drawable( WindowFromDC( hdc ), hdc )))
3273 SetLastError( ERROR_INVALID_HANDLE );
3274 return FALSE;
3277 EnterCriticalSection( &context_section );
3278 if (gl->refresh_swap_interval)
3280 set_swap_interval(gl->drawable, gl->swap_interval);
3281 gl->refresh_swap_interval = FALSE;
3283 LeaveCriticalSection( &context_section );
3285 switch (gl->type)
3287 case DC_GL_PIXMAP_WIN:
3288 if (ctx) sync_context( ctx );
3289 escape.gl_drawable = gl->pixmap;
3290 if (pglXCopySubBufferMESA) {
3291 /* (glX)SwapBuffers has an implicit glFlush effect, however
3292 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3293 * copying */
3294 pglFlush();
3295 pglXCopySubBufferMESA( gdi_display, gl->drawable, 0, 0,
3296 gl->pixmap_size.cx, gl->pixmap_size.cy );
3297 break;
3299 if (pglXSwapBuffersMscOML)
3301 pglFlush();
3302 target_sbc = pglXSwapBuffersMscOML( gdi_display, gl->drawable, 0, 0, 0 );
3303 break;
3305 pglXSwapBuffers(gdi_display, gl->drawable);
3306 break;
3307 case DC_GL_CHILD_WIN:
3308 if (ctx) sync_context( ctx );
3309 escape.gl_drawable = gl->window;
3310 /* fall through */
3311 default:
3312 if (escape.gl_drawable && pglXSwapBuffersMscOML)
3314 pglFlush();
3315 target_sbc = pglXSwapBuffersMscOML( gdi_display, gl->drawable, 0, 0, 0 );
3316 break;
3318 pglXSwapBuffers(gdi_display, gl->drawable);
3319 break;
3322 if (escape.gl_drawable && pglXWaitForSbcOML)
3323 pglXWaitForSbcOML( gdi_display, gl->drawable, target_sbc, &ust, &msc, &sbc );
3325 release_gl_drawable( gl );
3327 if (escape.gl_drawable) ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
3328 return TRUE;
3331 static struct opengl_funcs opengl_funcs =
3334 glxdrv_wglCopyContext, /* p_wglCopyContext */
3335 glxdrv_wglCreateContext, /* p_wglCreateContext */
3336 glxdrv_wglDeleteContext, /* p_wglDeleteContext */
3337 glxdrv_wglDescribePixelFormat, /* p_wglDescribePixelFormat */
3338 glxdrv_wglGetPixelFormat, /* p_wglGetPixelFormat */
3339 glxdrv_wglGetProcAddress, /* p_wglGetProcAddress */
3340 glxdrv_wglMakeCurrent, /* p_wglMakeCurrent */
3341 glxdrv_wglSetPixelFormat, /* p_wglSetPixelFormat */
3342 glxdrv_wglShareLists, /* p_wglShareLists */
3343 glxdrv_wglSwapBuffers, /* p_wglSwapBuffers */
3347 struct opengl_funcs *get_glx_driver( UINT version )
3349 if (version != WINE_WGL_DRIVER_VERSION)
3351 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_WGL_DRIVER_VERSION );
3352 return NULL;
3354 if (has_opengl()) return &opengl_funcs;
3355 return NULL;
3358 #else /* no OpenGL includes */
3360 struct opengl_funcs *get_glx_driver( UINT version )
3362 return NULL;
3365 void sync_gl_drawable( HWND hwnd )
3369 void set_gl_drawable_parent( HWND hwnd, HWND parent )
3373 void destroy_gl_drawable( HWND hwnd )
3377 #endif /* defined(SONAME_LIBGL) */