include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / winex11.drv / opengl.c
blob5d914b74f0a19a2f97ebd1c9a9ad0a82446ed2bf
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 #if 0
27 #pragma makedep unix
28 #endif
30 #include "config.h"
32 #include <assert.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <dlfcn.h>
36 #include <sys/socket.h>
37 #ifdef HAVE_SYS_UN_H
38 #include <sys/un.h>
39 #endif
41 #include "x11drv.h"
42 #include "xcomposite.h"
43 #include "winternl.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];
185 static int glx_opcode;
187 struct glx_pixel_format
189 GLXFBConfig fbconfig;
190 XVisualInfo *visual;
191 int fmt_id;
192 int render_type;
193 DWORD dwFlags; /* We store some PFD_* flags in here for emulated bitmap formats */
196 struct wgl_context
198 HDC hdc;
199 BOOL has_been_current;
200 BOOL sharing;
201 BOOL gl3_context;
202 const struct glx_pixel_format *fmt;
203 int numAttribs; /* This is needed for delaying wglCreateContextAttribsARB */
204 int attribList[16]; /* This is needed for delaying wglCreateContextAttribsARB */
205 GLXContext ctx;
206 struct gl_drawable *drawables[2];
207 struct gl_drawable *new_drawables[2];
208 struct list entry;
211 enum dc_gl_type
213 DC_GL_NONE, /* no GL support (pixel format not set yet) */
214 DC_GL_WINDOW, /* normal top-level window */
215 DC_GL_CHILD_WIN, /* child window using XComposite */
216 DC_GL_PIXMAP_WIN, /* child window using intermediate pixmap */
217 DC_GL_PBUFFER /* pseudo memory DC using a PBuffer */
220 struct gl_drawable
222 LONG ref; /* reference count */
223 enum dc_gl_type type; /* type of GL surface */
224 HWND hwnd;
225 GLXDrawable drawable; /* drawable for rendering with GL */
226 Window window; /* window if drawable is a GLXWindow */
227 Colormap colormap; /* colormap for the client window */
228 Pixmap pixmap; /* base pixmap if drawable is a GLXPixmap */
229 const struct glx_pixel_format *format; /* pixel format for the drawable */
230 SIZE pixmap_size; /* pixmap size for GLXPixmap drawables */
231 int swap_interval;
232 BOOL refresh_swap_interval;
233 BOOL mutable_pf;
236 struct wgl_pbuffer
238 struct gl_drawable *gl;
239 const struct glx_pixel_format* fmt;
240 int width;
241 int height;
242 int* attribList;
243 int use_render_texture; /* This is also the internal texture format */
244 int texture_bind_target;
245 int texture_bpp;
246 GLint texture_format;
247 GLuint texture_target;
248 GLenum texture_type;
249 GLuint texture;
250 int texture_level;
251 GLXContext tmp_context;
252 GLXContext prev_context;
253 struct list entry;
256 enum glx_swap_control_method
258 GLX_SWAP_CONTROL_NONE,
259 GLX_SWAP_CONTROL_EXT,
260 GLX_SWAP_CONTROL_SGI,
261 GLX_SWAP_CONTROL_MESA
264 /* X context to associate a struct gl_drawable to an hwnd */
265 static XContext gl_hwnd_context;
266 /* X context to associate a struct gl_drawable to a pbuffer hdc */
267 static XContext gl_pbuffer_context;
269 static struct list context_list = LIST_INIT( context_list );
270 static struct list pbuffer_list = LIST_INIT( pbuffer_list );
271 static struct glx_pixel_format *pixel_formats;
272 static int nb_pixel_formats, nb_onscreen_formats;
273 static BOOL use_render_texture_emulation = TRUE;
275 /* Selects the preferred GLX swap control method for use by wglSwapIntervalEXT */
276 static enum glx_swap_control_method swap_control_method = GLX_SWAP_CONTROL_NONE;
277 /* Set when GLX_EXT_swap_control_tear is supported, requires GLX_SWAP_CONTROL_EXT */
278 static BOOL has_swap_control_tear = FALSE;
279 static BOOL has_swap_method = FALSE;
281 static pthread_mutex_t context_mutex = PTHREAD_MUTEX_INITIALIZER;
283 static const BOOL is_win64 = sizeof(void *) > sizeof(int);
285 static struct opengl_funcs opengl_funcs;
287 #define USE_GL_FUNC(name) #name,
288 static const char *opengl_func_names[] = { ALL_WGL_FUNCS };
289 #undef USE_GL_FUNC
291 static void X11DRV_WineGL_LoadExtensions(void);
292 static void init_pixel_formats( Display *display );
293 static BOOL glxRequireVersion(int requiredVersion);
295 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
296 TRACE( "size %u version %u flags %u type %u color %u %u,%u,%u,%u "
297 "accum %u depth %u stencil %u aux %u ",
298 ppfd->nSize, ppfd->nVersion, (int)ppfd->dwFlags, ppfd->iPixelType,
299 ppfd->cColorBits, ppfd->cRedBits, ppfd->cGreenBits, ppfd->cBlueBits, ppfd->cAlphaBits,
300 ppfd->cAccumBits, ppfd->cDepthBits, ppfd->cStencilBits, ppfd->cAuxBuffers );
301 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
302 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
303 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
304 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
305 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
306 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
307 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
308 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
309 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
310 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
311 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
312 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
313 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
314 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
315 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
316 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
317 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
318 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
319 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
320 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
321 #undef TEST_AND_DUMP
322 TRACE("\n");
325 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
326 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
328 /* GLX 1.0 */
329 static XVisualInfo* (*pglXChooseVisual)( Display *dpy, int screen, int *attribList );
330 static GLXContext (*pglXCreateContext)( Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct );
331 static void (*pglXDestroyContext)( Display *dpy, GLXContext ctx );
332 static Bool (*pglXMakeCurrent)( Display *dpy, GLXDrawable drawable, GLXContext ctx);
333 static void (*pglXCopyContext)( Display *dpy, GLXContext src, GLXContext dst, unsigned long mask );
334 static void (*pglXSwapBuffers)( Display *dpy, GLXDrawable drawable );
335 static Bool (*pglXQueryVersion)( Display *dpy, int *maj, int *min );
336 static Bool (*pglXIsDirect)( Display *dpy, GLXContext ctx );
337 static GLXContext (*pglXGetCurrentContext)( void );
338 static GLXDrawable (*pglXGetCurrentDrawable)( void );
340 /* GLX 1.1 */
341 static const char *(*pglXQueryExtensionsString)( Display *dpy, int screen );
342 static const char *(*pglXQueryServerString)( Display *dpy, int screen, int name );
343 static const char *(*pglXGetClientString)( Display *dpy, int name );
345 /* GLX 1.3 */
346 static GLXFBConfig *(*pglXChooseFBConfig)( Display *dpy, int screen, const int *attribList, int *nitems );
347 static int (*pglXGetFBConfigAttrib)( Display *dpy, GLXFBConfig config, int attribute, int *value );
348 static GLXFBConfig *(*pglXGetFBConfigs)( Display *dpy, int screen, int *nelements );
349 static XVisualInfo *(*pglXGetVisualFromFBConfig)( Display *dpy, GLXFBConfig config );
350 static GLXPbuffer (*pglXCreatePbuffer)( Display *dpy, GLXFBConfig config, const int *attribList );
351 static void (*pglXDestroyPbuffer)( Display *dpy, GLXPbuffer pbuf );
352 static void (*pglXQueryDrawable)( Display *dpy, GLXDrawable draw, int attribute, unsigned int *value );
353 static GLXContext (*pglXCreateNewContext)( Display *dpy, GLXFBConfig config, int renderType, GLXContext shareList, Bool direct );
354 static Bool (*pglXMakeContextCurrent)( Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx );
355 static GLXPixmap (*pglXCreatePixmap)( Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list );
356 static void (*pglXDestroyPixmap)( Display *dpy, GLXPixmap pixmap );
357 static GLXWindow (*pglXCreateWindow)( Display *dpy, GLXFBConfig config, Window win, const int *attrib_list );
358 static void (*pglXDestroyWindow)( Display *dpy, GLXWindow win );
360 /* GLX Extensions */
361 static GLXContext (*pglXCreateContextAttribsARB)(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
362 static void* (*pglXGetProcAddressARB)(const GLubyte *);
363 static void (*pglXSwapIntervalEXT)(Display *dpy, GLXDrawable drawable, int interval);
364 static int (*pglXSwapIntervalSGI)(int);
366 /* NV GLX Extension */
367 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
368 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
370 /* MESA GLX Extensions */
371 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
372 static int (*pglXSwapIntervalMESA)(unsigned int interval);
373 static Bool (*pglXQueryCurrentRendererIntegerMESA)(int attribute, unsigned int *value);
374 static const char *(*pglXQueryCurrentRendererStringMESA)(int attribute);
375 static Bool (*pglXQueryRendererIntegerMESA)(Display *dpy, int screen, int renderer, int attribute, unsigned int *value);
376 static const char *(*pglXQueryRendererStringMESA)(Display *dpy, int screen, int renderer, int attribute);
378 /* OpenML GLX Extensions */
379 static Bool (*pglXWaitForSbcOML)( Display *dpy, GLXDrawable drawable,
380 INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 *sbc );
381 static INT64 (*pglXSwapBuffersMscOML)( Display *dpy, GLXDrawable drawable,
382 INT64 target_msc, INT64 divisor, INT64 remainder );
384 /* Standard OpenGL */
385 static void (*pglFinish)(void);
386 static void (*pglFlush)(void);
387 static const GLubyte *(*pglGetString)(GLenum name);
389 static void wglFinish(void);
390 static void wglFlush(void);
391 static const GLubyte *wglGetString(GLenum name);
393 /* check if the extension is present in the list */
394 static BOOL has_extension( const char *list, const char *ext )
396 size_t len = strlen( ext );
398 while (list)
400 while (*list == ' ') list++;
401 if (!strncmp( list, ext, len ) && (!list[len] || list[len] == ' ')) return TRUE;
402 list = strchr( list, ' ' );
404 return FALSE;
407 static int GLXErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
409 /* In the future we might want to find the exact X or GLX error to report back to the app */
410 if (event->request_code != glx_opcode)
411 return 0;
412 return 1;
415 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
417 static const char legacy_extensions[] = " WGL_EXT_extensions_string WGL_EXT_swap_control";
419 int screen = DefaultScreen(gdi_display);
420 Window win = 0, root = 0;
421 const char *gl_version;
422 const char *gl_renderer;
423 const char* str;
424 BOOL glx_direct;
425 XVisualInfo *vis;
426 GLXContext ctx = NULL;
427 XSetWindowAttributes attr;
428 BOOL ret = FALSE;
429 int attribList[] = {GLX_RGBA, GLX_DOUBLEBUFFER, None};
431 attr.override_redirect = True;
432 attr.colormap = None;
433 attr.border_pixel = 0;
435 vis = pglXChooseVisual(gdi_display, screen, attribList);
436 if (vis) {
437 #ifdef __i386__
438 WORD old_fs, new_fs;
439 __asm__( "mov %%fs,%0" : "=r" (old_fs) );
440 /* Create a GLX Context. Without one we can't query GL information */
441 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
442 __asm__( "mov %%fs,%0" : "=r" (new_fs) );
443 __asm__( "mov %0,%%fs" :: "r" (old_fs) );
444 if (old_fs != new_fs)
446 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
447 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
448 goto done;
450 #else
451 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
452 #endif
454 if (!ctx) goto done;
456 root = RootWindow( gdi_display, vis->screen );
457 if (vis->visual != DefaultVisual( gdi_display, vis->screen ))
458 attr.colormap = XCreateColormap( gdi_display, root, vis->visual, AllocNone );
459 if ((win = XCreateWindow( gdi_display, root, -1, -1, 1, 1, 0, vis->depth, InputOutput,
460 vis->visual, CWBorderPixel | CWOverrideRedirect | CWColormap, &attr )))
461 XMapWindow( gdi_display, win );
462 else
463 win = root;
465 if(pglXMakeCurrent(gdi_display, win, ctx) == 0)
467 ERR_(winediag)( "Unable to activate OpenGL context, most likely your %s OpenGL drivers haven't been "
468 "installed correctly\n", is_win64 ? "64-bit" : "32-bit" );
469 goto done;
471 gl_renderer = (const char *)opengl_funcs.gl.p_glGetString(GL_RENDERER);
472 gl_version = (const char *)opengl_funcs.gl.p_glGetString(GL_VERSION);
473 str = (const char *) opengl_funcs.gl.p_glGetString(GL_EXTENSIONS);
474 glExtensions = malloc( strlen(str) + sizeof(legacy_extensions) );
475 strcpy(glExtensions, str);
476 strcat(glExtensions, legacy_extensions);
478 /* Get the common GLX version supported by GLX client and server ( major/minor) */
479 pglXQueryVersion(gdi_display, &glxVersion[0], &glxVersion[1]);
481 glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
482 glx_direct = pglXIsDirect(gdi_display, ctx);
484 TRACE("GL version : %s.\n", gl_version);
485 TRACE("GL renderer : %s.\n", gl_renderer);
486 TRACE("GLX version : %d.%d.\n", glxVersion[0], glxVersion[1]);
487 TRACE("Server GLX version : %s.\n", pglXQueryServerString(gdi_display, screen, GLX_VERSION));
488 TRACE("Server GLX vendor: : %s.\n", pglXQueryServerString(gdi_display, screen, GLX_VENDOR));
489 TRACE("Client GLX version : %s.\n", pglXGetClientString(gdi_display, GLX_VERSION));
490 TRACE("Client GLX vendor: : %s.\n", pglXGetClientString(gdi_display, GLX_VENDOR));
491 TRACE("Direct rendering enabled: %s\n", glx_direct ? "True" : "False");
493 if(!glx_direct)
495 int fd = ConnectionNumber(gdi_display);
496 struct sockaddr_un uaddr;
497 unsigned int uaddrlen = sizeof(struct sockaddr_un);
499 /* In general indirect rendering on a local X11 server indicates a driver problem.
500 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
502 if(!getsockname(fd, (struct sockaddr *)&uaddr, &uaddrlen) && uaddr.sun_family == AF_UNIX)
503 ERR_(winediag)("Direct rendering is disabled, most likely your %s OpenGL drivers "
504 "haven't been installed correctly (using GL renderer %s, version %s).\n",
505 is_win64 ? "64-bit" : "32-bit", debugstr_a(gl_renderer),
506 debugstr_a(gl_version));
508 else
510 /* In general you would expect that if direct rendering is returned, that you receive hardware
511 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
512 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
513 * software rendering, it shows direct rendering.
515 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
516 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
517 * it shows 'Mesa X11'.
519 if(!strcmp(gl_renderer, "Software Rasterizer") || !strcmp(gl_renderer, "Mesa X11"))
520 ERR_(winediag)("The Mesa OpenGL driver is using software rendering, most likely your %s OpenGL "
521 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
522 is_win64 ? "64-bit" : "32-bit", debugstr_a(gl_renderer),
523 debugstr_a(gl_version));
525 ret = TRUE;
527 done:
528 if(vis) XFree(vis);
529 if(ctx) {
530 pglXMakeCurrent(gdi_display, None, NULL);
531 pglXDestroyContext(gdi_display, ctx);
533 if (win != root) XDestroyWindow( gdi_display, win );
534 if (attr.colormap) XFreeColormap( gdi_display, attr.colormap );
535 if (!ret) ERR(" couldn't initialize OpenGL, expect problems\n");
536 return ret;
539 static void *opengl_handle;
541 static void init_opengl(void)
543 int error_base, event_base;
544 unsigned int i;
546 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
547 and include all dependencies */
548 opengl_handle = dlopen( SONAME_LIBGL, RTLD_NOW | RTLD_GLOBAL );
549 if (opengl_handle == NULL)
551 ERR( "Failed to load libGL: %s\n", dlerror() );
552 ERR( "OpenGL support is disabled.\n");
553 return;
556 for (i = 0; i < ARRAY_SIZE( opengl_func_names ); i++)
558 if (!(((void **)&opengl_funcs.gl)[i] = dlsym( opengl_handle, opengl_func_names[i] )))
560 ERR( "%s not found in libGL, disabling OpenGL.\n", opengl_func_names[i] );
561 goto failed;
565 /* redirect some standard OpenGL functions */
566 #define REDIRECT(func) \
567 do { p##func = opengl_funcs.gl.p_##func; opengl_funcs.gl.p_##func = w##func; } while(0)
568 REDIRECT( glFinish );
569 REDIRECT( glFlush );
570 REDIRECT( glGetString );
571 #undef REDIRECT
573 pglXGetProcAddressARB = dlsym(opengl_handle, "glXGetProcAddressARB");
574 if (pglXGetProcAddressARB == NULL) {
575 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
576 goto failed;
579 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
581 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
582 goto failed; \
583 } while(0)
585 /* GLX 1.0 */
586 LOAD_FUNCPTR(glXChooseVisual);
587 LOAD_FUNCPTR(glXCopyContext);
588 LOAD_FUNCPTR(glXCreateContext);
589 LOAD_FUNCPTR(glXGetCurrentContext);
590 LOAD_FUNCPTR(glXGetCurrentDrawable);
591 LOAD_FUNCPTR(glXDestroyContext);
592 LOAD_FUNCPTR(glXIsDirect);
593 LOAD_FUNCPTR(glXMakeCurrent);
594 LOAD_FUNCPTR(glXSwapBuffers);
595 LOAD_FUNCPTR(glXQueryVersion);
597 /* GLX 1.1 */
598 LOAD_FUNCPTR(glXGetClientString);
599 LOAD_FUNCPTR(glXQueryExtensionsString);
600 LOAD_FUNCPTR(glXQueryServerString);
602 /* GLX 1.3 */
603 LOAD_FUNCPTR(glXCreatePbuffer);
604 LOAD_FUNCPTR(glXCreateNewContext);
605 LOAD_FUNCPTR(glXDestroyPbuffer);
606 LOAD_FUNCPTR(glXMakeContextCurrent);
607 LOAD_FUNCPTR(glXGetFBConfigs);
608 LOAD_FUNCPTR(glXCreatePixmap);
609 LOAD_FUNCPTR(glXDestroyPixmap);
610 LOAD_FUNCPTR(glXCreateWindow);
611 LOAD_FUNCPTR(glXDestroyWindow);
612 #undef LOAD_FUNCPTR
614 /* It doesn't matter if these fail. They'll only be used if the driver reports
615 the associated extension is available (and if a driver reports the extension
616 is available but fails to provide the functions, it's quite broken) */
617 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
618 /* ARB GLX Extension */
619 LOAD_FUNCPTR(glXCreateContextAttribsARB);
620 /* EXT GLX Extension */
621 LOAD_FUNCPTR(glXSwapIntervalEXT);
622 /* MESA GLX Extension */
623 LOAD_FUNCPTR(glXSwapIntervalMESA);
624 /* SGI GLX Extension */
625 LOAD_FUNCPTR(glXSwapIntervalSGI);
626 /* NV GLX Extension */
627 LOAD_FUNCPTR(glXAllocateMemoryNV);
628 LOAD_FUNCPTR(glXFreeMemoryNV);
629 #undef LOAD_FUNCPTR
631 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed;
633 if (XQueryExtension( gdi_display, "GLX", &glx_opcode, &event_base, &error_base ))
635 TRACE("GLX is up and running error_base = %d\n", error_base);
636 } else {
637 ERR( "GLX extension is missing, disabling OpenGL.\n" );
638 goto failed;
640 gl_hwnd_context = XUniqueContext();
641 gl_pbuffer_context = XUniqueContext();
643 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
644 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
645 * rendering is used.
647 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
648 * depends on the reported GLX client / server version and on the client / server extension list.
649 * Those don't have to be the same.
651 * In general the server GLX information lists the capabilities in case of indirect rendering.
652 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
653 * available and in that case the client GLX informat can be used.
654 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
655 * in the GLX version/extension list. When a program does this it works for certain for both
656 * direct and indirect rendering.
658 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
659 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
660 * extension list which causes this extension not to be listed. (Wine requires this extension).
661 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
662 * pbuffers is around.
664 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
665 * the ATI drivers and from then on use GLX client information for them.
668 if(glxRequireVersion(3)) {
669 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
670 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
671 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
672 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
673 } else if (has_extension( glxExtensions, "GLX_SGIX_fbconfig")) {
674 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
675 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
676 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
678 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
679 * enable this function when the Xserver understand GLX 1.3 or newer
681 pglXQueryDrawable = NULL;
682 } else if(strcmp("ATI", pglXGetClientString(gdi_display, GLX_VENDOR)) == 0) {
683 TRACE("Overriding ATI GLX capabilities!\n");
684 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
685 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
686 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
687 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
689 /* Use client GLX information in case of the ATI drivers. We override the
690 * capabilities over here and not somewhere else as ATI might better their
691 * life in the future. In case they release proper drivers this block of
692 * code won't be called. */
693 glxExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
694 } else {
695 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n",
696 pglXQueryServerString(gdi_display, DefaultScreen(gdi_display), GLX_VERSION));
699 if (has_extension( glxExtensions, "GLX_MESA_copy_sub_buffer")) {
700 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
703 if (has_extension( glxExtensions, "GLX_MESA_query_renderer" ))
705 pglXQueryCurrentRendererIntegerMESA = pglXGetProcAddressARB(
706 (const GLubyte *)"glXQueryCurrentRendererIntegerMESA" );
707 pglXQueryCurrentRendererStringMESA = pglXGetProcAddressARB(
708 (const GLubyte *)"glXQueryCurrentRendererStringMESA" );
709 pglXQueryRendererIntegerMESA = pglXGetProcAddressARB( (const GLubyte *)"glXQueryRendererIntegerMESA" );
710 pglXQueryRendererStringMESA = pglXGetProcAddressARB( (const GLubyte *)"glXQueryRendererStringMESA" );
713 if (has_extension( glxExtensions, "GLX_OML_sync_control" ))
715 pglXWaitForSbcOML = pglXGetProcAddressARB( (const GLubyte *)"glXWaitForSbcOML" );
716 pglXSwapBuffersMscOML = pglXGetProcAddressARB( (const GLubyte *)"glXSwapBuffersMscOML" );
719 X11DRV_WineGL_LoadExtensions();
720 init_pixel_formats( gdi_display );
721 return;
723 failed:
724 dlclose(opengl_handle);
725 opengl_handle = NULL;
728 static BOOL has_opengl(void)
730 static pthread_once_t init_once = PTHREAD_ONCE_INIT;
732 return !pthread_once( &init_once, init_opengl );
735 static const char *debugstr_fbconfig( GLXFBConfig fbconfig )
737 int id, visual, drawable;
739 if (pglXGetFBConfigAttrib( gdi_display, fbconfig, GLX_FBCONFIG_ID, &id ))
740 return "*** invalid fbconfig";
741 pglXGetFBConfigAttrib( gdi_display, fbconfig, GLX_VISUAL_ID, &visual );
742 pglXGetFBConfigAttrib( gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &drawable );
743 return wine_dbg_sprintf( "fbconfig %#x visual id %#x drawable type %#x", id, visual, drawable );
746 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
748 int render_type, render_type_bit;
749 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
750 switch(render_type_bit)
752 case GLX_RGBA_BIT:
753 render_type = GLX_RGBA_TYPE;
754 break;
755 case GLX_COLOR_INDEX_BIT:
756 render_type = GLX_COLOR_INDEX_TYPE;
757 break;
758 case GLX_RGBA_FLOAT_BIT:
759 render_type = GLX_RGBA_FLOAT_TYPE;
760 break;
761 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT:
762 render_type = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
763 break;
764 default:
765 ERR("Unknown render_type: %x\n", render_type_bit);
766 render_type = 0;
768 return render_type;
771 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
772 static BOOL check_fbconfig_bitmap_capability(Display *display, GLXFBConfig fbconfig)
774 int dbuf, value;
775 pglXGetFBConfigAttrib(display, fbconfig, GLX_DOUBLEBUFFER, &dbuf);
776 pglXGetFBConfigAttrib(gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &value);
778 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
779 * the GLX_PIXMAP_BIT set. */
780 return !dbuf && (value & GLX_PIXMAP_BIT);
783 static void init_pixel_formats( Display *display )
785 struct glx_pixel_format *list;
786 int size = 0, onscreen_size = 0;
787 int fmt_id, nCfgs, i, run, bmp_formats;
788 GLXFBConfig* cfgs;
789 XVisualInfo *visinfo;
791 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
792 if (NULL == cfgs || 0 == nCfgs) {
793 if(cfgs != NULL) XFree(cfgs);
794 ERR("glXChooseFBConfig returns NULL\n");
795 return;
798 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
799 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
800 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
801 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
803 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
805 for(i=0, bmp_formats=0; i<nCfgs; i++)
807 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
808 bmp_formats++;
810 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats);
812 list = calloc( 1, (nCfgs + bmp_formats) * sizeof(*list) );
814 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
815 * Do this as GLX doesn't guarantee that the list is sorted */
816 for(run=0; run < 2; run++)
818 for(i=0; i<nCfgs; i++) {
819 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
820 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
822 /* The first run we only add onscreen formats (ones which have an associated X Visual).
823 * The second run we only set offscreen formats. */
824 if(!run && visinfo)
826 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
827 * The contents is copied to the destination using XCopyArea. For the copying to work
828 * the depth of the source and destination window should be the same. In general this should
829 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
830 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
831 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
832 * list formats with the same depth. */
833 if(visinfo->depth != default_visual.depth)
835 XFree(visinfo);
836 continue;
839 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
840 list[size].fbconfig = cfgs[i];
841 list[size].visual = visinfo;
842 list[size].fmt_id = fmt_id;
843 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
844 list[size].dwFlags = 0;
845 size++;
846 onscreen_size++;
848 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
849 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
851 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
852 list[size].fbconfig = cfgs[i];
853 list[size].visual = visinfo;
854 list[size].fmt_id = fmt_id;
855 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
856 list[size].dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_GENERIC_FORMAT;
857 size++;
858 onscreen_size++;
860 } else if(run && !visinfo) {
861 int window_drawable=0;
862 pglXGetFBConfigAttrib(gdi_display, cfgs[i], GLX_DRAWABLE_TYPE, &window_drawable);
864 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
865 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
866 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
867 * likely make our child window opengl rendering more complicated since likely you can't use
868 * XCopyArea on a GLX Window.
869 * For now ignore fbconfigs which are window drawable but lack a visual. */
870 if(window_drawable & GLX_WINDOW_BIT)
872 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id);
873 continue;
876 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
877 list[size].fbconfig = cfgs[i];
878 list[size].fmt_id = fmt_id;
879 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
880 list[size].dwFlags = 0;
881 size++;
883 else if (visinfo) XFree(visinfo);
887 XFree(cfgs);
889 pixel_formats = list;
890 nb_pixel_formats = size;
891 nb_onscreen_formats = onscreen_size;
894 static inline BOOL is_valid_pixel_format( int format )
896 return format > 0 && format <= nb_pixel_formats;
899 static inline BOOL is_onscreen_pixel_format( int format )
901 return format > 0 && format <= nb_onscreen_formats;
904 static inline int pixel_format_index( const struct glx_pixel_format *format )
906 return format - pixel_formats + 1;
909 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
910 * In our WGL implementation we only support a subset of these formats namely the format of
911 * Wine's main visual and offscreen formats (if they are available).
912 * This function converts a WGL format to its corresponding GLX one.
914 static const struct glx_pixel_format *get_pixel_format(Display *display, int iPixelFormat, BOOL AllowOffscreen)
916 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
917 * iPixelFormat in case of probing the number of pixelformats.
919 if (is_valid_pixel_format( iPixelFormat ) &&
920 (is_onscreen_pixel_format( iPixelFormat ) || AllowOffscreen)) {
921 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n",
922 pixel_formats[iPixelFormat-1].fmt_id, iPixelFormat);
923 return &pixel_formats[iPixelFormat-1];
925 return NULL;
928 static struct gl_drawable *grab_gl_drawable( struct gl_drawable *gl )
930 InterlockedIncrement( &gl->ref );
931 return gl;
934 static void release_gl_drawable( struct gl_drawable *gl )
936 if (!gl) return;
937 if (InterlockedDecrement( &gl->ref )) return;
938 switch (gl->type)
940 case DC_GL_WINDOW:
941 case DC_GL_CHILD_WIN:
942 TRACE( "destroying %lx drawable %lx\n", gl->window, gl->drawable );
943 pglXDestroyWindow( gdi_display, gl->drawable );
944 destroy_client_window( gl->hwnd, gl->window );
945 XFreeColormap( gdi_display, gl->colormap );
946 break;
947 case DC_GL_PIXMAP_WIN:
948 TRACE( "destroying pixmap %lx drawable %lx\n", gl->pixmap, gl->drawable );
949 pglXDestroyPixmap( gdi_display, gl->drawable );
950 XFreePixmap( gdi_display, gl->pixmap );
951 break;
952 case DC_GL_PBUFFER:
953 TRACE( "destroying pbuffer drawable %lx\n", gl->drawable );
954 pglXDestroyPbuffer( gdi_display, gl->drawable );
955 break;
956 default:
957 break;
959 free( gl );
962 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
963 static void mark_drawable_dirty( struct gl_drawable *old, struct gl_drawable *new )
965 struct wgl_context *ctx;
967 pthread_mutex_lock( &context_mutex );
968 LIST_FOR_EACH_ENTRY( ctx, &context_list, struct wgl_context, entry )
970 if (old == ctx->drawables[0] || old == ctx->new_drawables[0])
972 release_gl_drawable( ctx->new_drawables[0] );
973 ctx->new_drawables[0] = grab_gl_drawable( new );
975 if (old == ctx->drawables[1] || old == ctx->new_drawables[1])
977 release_gl_drawable( ctx->new_drawables[1] );
978 ctx->new_drawables[1] = grab_gl_drawable( new );
981 pthread_mutex_unlock( &context_mutex );
984 /* Given the current context, make sure its drawable is sync'd */
985 static inline void sync_context(struct wgl_context *context)
987 BOOL refresh = FALSE;
988 struct gl_drawable *old[2] = { NULL };
990 pthread_mutex_lock( &context_mutex );
991 if (context->new_drawables[0])
993 old[0] = context->drawables[0];
994 context->drawables[0] = context->new_drawables[0];
995 context->new_drawables[0] = NULL;
996 refresh = TRUE;
998 if (context->new_drawables[1])
1000 old[1] = context->drawables[1];
1001 context->drawables[1] = context->new_drawables[1];
1002 context->new_drawables[1] = NULL;
1003 refresh = TRUE;
1005 if (refresh)
1007 if (glxRequireVersion(3))
1008 pglXMakeContextCurrent(gdi_display, context->drawables[0]->drawable,
1009 context->drawables[1]->drawable, context->ctx);
1010 else
1011 pglXMakeCurrent(gdi_display, context->drawables[0]->drawable, context->ctx);
1012 release_gl_drawable( old[0] );
1013 release_gl_drawable( old[1] );
1015 pthread_mutex_unlock( &context_mutex );
1018 static BOOL set_swap_interval(GLXDrawable drawable, int interval)
1020 BOOL ret = TRUE;
1022 switch (swap_control_method)
1024 case GLX_SWAP_CONTROL_EXT:
1025 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
1026 pglXSwapIntervalEXT(gdi_display, drawable, interval);
1027 XSync(gdi_display, False);
1028 ret = !X11DRV_check_error();
1029 break;
1031 case GLX_SWAP_CONTROL_MESA:
1032 ret = !pglXSwapIntervalMESA(interval);
1033 break;
1035 case GLX_SWAP_CONTROL_SGI:
1036 /* wglSwapIntervalEXT considers an interval value of zero to mean that
1037 * vsync should be disabled, but glXSwapIntervalSGI considers such a
1038 * value to be an error. Just silently ignore the request for now.
1040 if (!interval)
1041 WARN("Request to disable vertical sync is not handled\n");
1042 else
1043 ret = !pglXSwapIntervalSGI(interval);
1044 break;
1046 case GLX_SWAP_CONTROL_NONE:
1047 /* Unlikely to happen on modern GLX implementations */
1048 WARN("Request to adjust swap interval is not handled\n");
1049 break;
1052 return ret;
1055 static struct gl_drawable *get_gl_drawable( HWND hwnd, HDC hdc )
1057 struct gl_drawable *gl;
1059 pthread_mutex_lock( &context_mutex );
1060 if (hwnd && !XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl ))
1061 gl = grab_gl_drawable( gl );
1062 else if (hdc && !XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl ))
1063 gl = grab_gl_drawable( gl );
1064 else
1065 gl = NULL;
1066 pthread_mutex_unlock( &context_mutex );
1067 return gl;
1070 static GLXContext create_glxcontext(Display *display, struct wgl_context *context, GLXContext shareList)
1072 GLXContext ctx;
1074 if(context->gl3_context)
1076 if(context->numAttribs)
1077 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, GL_TRUE, context->attribList);
1078 else
1079 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, GL_TRUE, NULL);
1081 else if(context->fmt->visual)
1082 ctx = pglXCreateContext(gdi_display, context->fmt->visual, shareList, GL_TRUE);
1083 else /* Create a GLX Context for a pbuffer */
1084 ctx = pglXCreateNewContext(gdi_display, context->fmt->fbconfig, context->fmt->render_type, shareList, TRUE);
1086 return ctx;
1090 /***********************************************************************
1091 * create_gl_drawable
1093 static struct gl_drawable *create_gl_drawable( HWND hwnd, const struct glx_pixel_format *format, BOOL known_child,
1094 BOOL mutable_pf )
1096 struct gl_drawable *gl, *prev;
1097 XVisualInfo *visual = format->visual;
1098 RECT rect;
1099 int width, height;
1101 NtUserGetClientRect( hwnd, &rect, get_win_monitor_dpi( hwnd ) );
1102 width = min( max( 1, rect.right ), 65535 );
1103 height = min( max( 1, rect.bottom ), 65535 );
1105 if (!(gl = calloc( 1, sizeof(*gl) ))) return NULL;
1107 /* Default GLX and WGL swap interval is 1, but in case of glXSwapIntervalSGI
1108 * there is no way to query it, so we have to store it here.
1110 gl->swap_interval = 1;
1111 gl->refresh_swap_interval = TRUE;
1112 gl->format = format;
1113 gl->ref = 1;
1114 gl->hwnd = hwnd;
1115 gl->mutable_pf = mutable_pf;
1117 if (!known_child && !NtUserGetWindowRelative( hwnd, GW_CHILD ) &&
1118 NtUserGetAncestor( hwnd, GA_PARENT ) == NtUserGetDesktopWindow()) /* childless top-level window */
1120 gl->type = DC_GL_WINDOW;
1121 gl->colormap = XCreateColormap( gdi_display, get_dummy_parent(), visual->visual,
1122 (visual->class == PseudoColor || visual->class == GrayScale ||
1123 visual->class == DirectColor) ? AllocAll : AllocNone );
1124 gl->window = create_client_window( hwnd, visual, gl->colormap );
1125 if (gl->window)
1126 gl->drawable = pglXCreateWindow( gdi_display, gl->format->fbconfig, gl->window, NULL );
1127 TRACE( "%p created client %lx drawable %lx\n", hwnd, gl->window, gl->drawable );
1129 #ifdef SONAME_LIBXCOMPOSITE
1130 else if(usexcomposite)
1132 gl->type = DC_GL_CHILD_WIN;
1133 gl->colormap = XCreateColormap( gdi_display, get_dummy_parent(), visual->visual,
1134 (visual->class == PseudoColor || visual->class == GrayScale ||
1135 visual->class == DirectColor) ? AllocAll : AllocNone );
1136 gl->window = create_client_window( hwnd, visual, gl->colormap );
1137 if (gl->window)
1139 gl->drawable = pglXCreateWindow( gdi_display, gl->format->fbconfig, gl->window, NULL );
1140 pXCompositeRedirectWindow( gdi_display, gl->window, CompositeRedirectManual );
1142 TRACE( "%p created child %lx drawable %lx\n", hwnd, gl->window, gl->drawable );
1144 #endif
1145 else
1147 static unsigned int once;
1149 if (!once++)
1150 ERR_(winediag)("XComposite is not available, using GLXPixmap hack.\n");
1151 WARN("XComposite is not available, using GLXPixmap hack.\n");
1153 gl->type = DC_GL_PIXMAP_WIN;
1154 gl->pixmap = XCreatePixmap( gdi_display, root_window, width, height, visual->depth );
1155 if (gl->pixmap)
1157 gl->drawable = pglXCreatePixmap( gdi_display, gl->format->fbconfig, gl->pixmap, NULL );
1158 if (!gl->drawable) XFreePixmap( gdi_display, gl->pixmap );
1159 gl->pixmap_size.cx = width;
1160 gl->pixmap_size.cy = height;
1164 if (!gl->drawable)
1166 free( gl );
1167 return NULL;
1170 pthread_mutex_lock( &context_mutex );
1171 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&prev ))
1173 gl->swap_interval = prev->swap_interval;
1174 release_gl_drawable( prev );
1176 XSaveContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char *)grab_gl_drawable(gl) );
1177 pthread_mutex_unlock( &context_mutex );
1178 return gl;
1182 /***********************************************************************
1183 * set_win_format
1185 static BOOL set_win_format( HWND hwnd, const struct glx_pixel_format *format, BOOL internal )
1187 struct gl_drawable *old, *gl;
1189 if (!format->visual) return FALSE;
1191 old = get_gl_drawable( hwnd, 0 );
1193 if (!(gl = create_gl_drawable( hwnd, format, FALSE, internal )))
1195 release_gl_drawable( old );
1196 return FALSE;
1199 TRACE( "created GL drawable %lx for win %p %s\n",
1200 gl->drawable, hwnd, debugstr_fbconfig( format->fbconfig ));
1202 if (old)
1203 mark_drawable_dirty( old, gl );
1205 XFlush( gdi_display );
1206 release_gl_drawable( gl );
1207 release_gl_drawable( old );
1209 win32u_set_window_pixel_format( hwnd, pixel_format_index( format ), internal );
1210 return TRUE;
1214 static BOOL set_pixel_format( HDC hdc, int format, BOOL internal )
1216 const struct glx_pixel_format *fmt;
1217 int value;
1218 HWND hwnd = NtUserWindowFromDC( hdc );
1219 int prev;
1221 TRACE("(%p,%d)\n", hdc, format);
1223 if (!hwnd || hwnd == NtUserGetDesktopWindow())
1225 WARN( "not a valid window DC %p/%p\n", hdc, hwnd );
1226 return FALSE;
1229 fmt = get_pixel_format(gdi_display, format, FALSE /* Offscreen */);
1230 if (!fmt)
1232 ERR( "Invalid format %d\n", format );
1233 return FALSE;
1236 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1237 if (!(value & GLX_WINDOW_BIT))
1239 WARN( "Pixel format %d is not compatible for window rendering\n", format );
1240 return FALSE;
1243 /* Even for internal pixel format fail setting it if the app has already set a
1244 * different pixel format. Let wined3d create a backup GL context instead.
1245 * Switching pixel format involves drawable recreation and is much more expensive
1246 * than blitting from backup context. */
1247 if ((prev = win32u_get_window_pixel_format( hwnd )))
1248 return prev == format;
1250 return set_win_format( hwnd, fmt, internal );
1254 /***********************************************************************
1255 * sync_gl_drawable
1257 void sync_gl_drawable( HWND hwnd, BOOL known_child )
1259 struct gl_drawable *old, *new;
1261 if (!(old = get_gl_drawable( hwnd, 0 ))) return;
1263 switch (old->type)
1265 case DC_GL_WINDOW:
1266 if (!known_child) break; /* Still a childless top-level window */
1267 /* fall through */
1268 case DC_GL_PIXMAP_WIN:
1269 if (!(new = create_gl_drawable( hwnd, old->format, known_child, old->mutable_pf ))) break;
1270 mark_drawable_dirty( old, new );
1271 XFlush( gdi_display );
1272 TRACE( "Recreated GL drawable %lx to replace %lx\n", new->drawable, old->drawable );
1273 release_gl_drawable( new );
1274 break;
1275 default:
1276 break;
1278 release_gl_drawable( old );
1282 /***********************************************************************
1283 * set_gl_drawable_parent
1285 void set_gl_drawable_parent( HWND hwnd, HWND parent )
1287 struct gl_drawable *old, *new;
1289 if (!(old = get_gl_drawable( hwnd, 0 ))) return;
1291 TRACE( "setting drawable %lx parent %p\n", old->drawable, parent );
1293 switch (old->type)
1295 case DC_GL_WINDOW:
1296 break;
1297 case DC_GL_CHILD_WIN:
1298 case DC_GL_PIXMAP_WIN:
1299 if (parent == NtUserGetDesktopWindow()) break;
1300 /* fall through */
1301 default:
1302 release_gl_drawable( old );
1303 return;
1306 if ((new = create_gl_drawable( hwnd, old->format, FALSE, old->mutable_pf )))
1308 mark_drawable_dirty( old, new );
1309 release_gl_drawable( new );
1311 else
1313 destroy_gl_drawable( hwnd );
1314 win32u_set_window_pixel_format( hwnd, 0, FALSE );
1316 release_gl_drawable( old );
1320 /***********************************************************************
1321 * destroy_gl_drawable
1323 void destroy_gl_drawable( HWND hwnd )
1325 struct gl_drawable *gl;
1327 pthread_mutex_lock( &context_mutex );
1328 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl ))
1330 XDeleteContext( gdi_display, (XID)hwnd, gl_hwnd_context );
1331 release_gl_drawable( gl );
1333 pthread_mutex_unlock( &context_mutex );
1338 * describe_pixel_format
1340 * Get the wgl_pixel_format description for the given id
1342 static int describe_pixel_format( int iPixelFormat, struct wgl_pixel_format *pf )
1344 int value, drawable_type = 0, render_type = 0;
1345 int rb, gb, bb, ab;
1346 const struct glx_pixel_format *fmt;
1348 if (!has_opengl()) return 0;
1350 /* Look for the iPixelFormat in our list of supported formats. If it is
1351 * supported we get the index in the FBConfig table and the number of
1352 * supported formats back */
1353 fmt = get_pixel_format( gdi_display, iPixelFormat, TRUE /* Offscreen */);
1354 if (!fmt)
1356 WARN( "unexpected format %d\n", iPixelFormat );
1357 return 0;
1360 /* If we can't get basic information, there is no point continuing */
1361 if (pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &drawable_type )) return 0;
1362 if (pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &render_type )) return 0;
1364 memset( pf, 0, sizeof(*pf) );
1365 pf->pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
1366 pf->pfd.nVersion = 1;
1368 /* These flags are always the same... */
1369 pf->pfd.dwFlags = PFD_SUPPORT_OPENGL;
1370 /* Now the flags extracted from the Visual */
1372 if (drawable_type & GLX_WINDOW_BIT) pf->pfd.dwFlags |= PFD_DRAW_TO_WINDOW;
1374 /* On Windows bitmap rendering is only offered using the GDI Software
1375 * renderer. We reserve some formats (see get_formats for more info) for
1376 * bitmap rendering since we require indirect rendering for this. Further
1377 * pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1378 * Radeon 9000 indicated that all bitmap formats have PFD_SUPPORT_GDI.
1379 * Except for 2 formats on the Radeon 9000 none of the hw accelerated
1380 * formats offered the GDI bit either. */
1381 pf->pfd.dwFlags |= fmt->dwFlags & (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI);
1383 /* PFD_GENERIC_FORMAT - gdi software rendering
1384 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver
1385 * (MCD e.g. 3dfx minigl) none set - full hardware accelerated by a ICD
1387 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as
1388 * that's what ATI and Nvidia Windows drivers do */
1389 pf->pfd.dwFlags |= fmt->dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED);
1391 if (!(pf->pfd.dwFlags & PFD_GENERIC_FORMAT)) pf->pfd.dwFlags |= PFD_SUPPORT_COMPOSITION;
1393 pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value );
1394 if (value)
1396 pf->pfd.dwFlags |= PFD_DOUBLEBUFFER;
1397 pf->pfd.dwFlags &= ~PFD_SUPPORT_GDI;
1399 pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_STEREO, &value );
1400 if (value) pf->pfd.dwFlags |= PFD_STEREO;
1402 /* Pixel type */
1403 if (render_type & GLX_RGBA_BIT) pf->pfd.iPixelType = PFD_TYPE_RGBA;
1404 else pf->pfd.iPixelType = PFD_TYPE_COLORINDEX;
1406 /* Color bits */
1407 pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value );
1408 pf->pfd.cColorBits = value;
1410 /* Red, green, blue and alpha bits / shifts */
1411 if (pf->pfd.iPixelType == PFD_TYPE_RGBA)
1413 pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb );
1414 pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb );
1415 pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb );
1416 pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab );
1418 pf->pfd.cBlueBits = bb;
1419 pf->pfd.cBlueShift = 0;
1420 pf->pfd.cGreenBits = gb;
1421 pf->pfd.cGreenShift = bb;
1422 pf->pfd.cRedBits = rb;
1423 pf->pfd.cRedShift = gb + bb;
1424 pf->pfd.cAlphaBits = ab;
1425 if (ab) pf->pfd.cAlphaShift = rb + gb + bb;
1426 else pf->pfd.cAlphaShift = 0;
1428 else
1430 pf->pfd.cRedBits = 0;
1431 pf->pfd.cRedShift = 0;
1432 pf->pfd.cBlueBits = 0;
1433 pf->pfd.cBlueShift = 0;
1434 pf->pfd.cGreenBits = 0;
1435 pf->pfd.cGreenShift = 0;
1436 pf->pfd.cAlphaBits = 0;
1437 pf->pfd.cAlphaShift = 0;
1440 /* Accum RGBA bits */
1441 pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb );
1442 pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb );
1443 pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb );
1444 pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab );
1446 pf->pfd.cAccumBits = rb + gb + bb + ab;
1447 pf->pfd.cAccumRedBits = rb;
1448 pf->pfd.cAccumGreenBits = gb;
1449 pf->pfd.cAccumBlueBits = bb;
1450 pf->pfd.cAccumAlphaBits = ab;
1452 /* Aux bits */
1453 pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value );
1454 pf->pfd.cAuxBuffers = value;
1456 /* Depth bits */
1457 pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value );
1458 pf->pfd.cDepthBits = value;
1460 /* stencil bits */
1461 pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value );
1462 pf->pfd.cStencilBits = value;
1464 pf->pfd.iLayerType = PFD_MAIN_PLANE;
1466 if (!has_swap_method) pf->swap_method = WGL_SWAP_EXCHANGE_ARB;
1467 else if (!pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_SWAP_METHOD_OML, &value ))
1469 switch (value) {
1470 case GLX_SWAP_EXCHANGE_OML: pf->swap_method = WGL_SWAP_EXCHANGE_ARB; break;
1471 case GLX_SWAP_COPY_OML: pf->swap_method = WGL_SWAP_COPY_ARB; break;
1472 case GLX_SWAP_UNDEFINED_OML: pf->swap_method = WGL_SWAP_UNDEFINED_ARB; break;
1473 default: { ERR( "Unexpected swap method %x.\n", value ); pf->swap_method = -1; break; }
1476 else pf->swap_method = -1;
1478 if (pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_TRANSPARENT_TYPE, &value) ) pf->transparent = -1;
1479 else pf->transparent = value != GLX_NONE;
1481 if (render_type & GLX_RGBA_BIT) pf->pixel_type = WGL_TYPE_RGBA_ARB;
1482 else if (render_type & GLX_COLOR_INDEX_BIT) pf->pixel_type = WGL_TYPE_COLORINDEX_ARB;
1483 else if (render_type & GLX_RGBA_FLOAT_BIT) pf->pixel_type = WGL_TYPE_RGBA_FLOAT_ATI;
1484 else if (render_type & GLX_RGBA_FLOAT_ATI_BIT) pf->pixel_type = WGL_TYPE_RGBA_FLOAT_ATI;
1485 else if (render_type & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) pf->pixel_type = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT;
1486 else { ERR( "unexpected RenderType(%x)\n", render_type ); pf->pixel_type = -1; }
1488 pf->draw_to_pbuffer = (drawable_type & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
1489 if (pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_MAX_PBUFFER_PIXELS, &value )) value = -1;
1490 pf->max_pbuffer_pixels = value;
1491 if (pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_MAX_PBUFFER_WIDTH, &value )) value = -1;
1492 pf->max_pbuffer_width = value;
1493 if (pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_MAX_PBUFFER_HEIGHT, &value )) value = -1;
1494 pf->max_pbuffer_height = value;
1496 if (!pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_TRANSPARENT_RED_VALUE, &value ))
1498 pf->transparent_red_value_valid = GL_TRUE;
1499 pf->transparent_red_value = value;
1501 if (!pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_TRANSPARENT_GREEN_VALUE, &value ))
1503 pf->transparent_green_value_valid = GL_TRUE;
1504 pf->transparent_green_value = value;
1506 if (!pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_TRANSPARENT_BLUE_VALUE, &value ))
1508 pf->transparent_blue_value_valid = GL_TRUE;
1509 pf->transparent_blue_value = value;
1511 if (!pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_TRANSPARENT_ALPHA_VALUE, &value ))
1513 pf->transparent_alpha_value_valid = GL_TRUE;
1514 pf->transparent_alpha_value = value;
1516 if (!pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_TRANSPARENT_INDEX_VALUE, &value ))
1518 pf->transparent_index_value_valid = GL_TRUE;
1519 pf->transparent_index_value = value;
1522 if (pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_SAMPLE_BUFFERS_ARB, &value )) value = -1;
1523 pf->sample_buffers = value;
1524 if (pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_SAMPLES_ARB, &value )) value = -1;
1525 pf->samples = value;
1527 if (pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, &value )) value = -1;
1528 pf->framebuffer_srgb_capable = value;
1530 pf->bind_to_texture_rgb = pf->bind_to_texture_rgba =
1531 use_render_texture_emulation && render_type != GLX_COLOR_INDEX_BIT && (render_type & GLX_PBUFFER_BIT);
1532 pf->bind_to_texture_rectangle_rgb = pf->bind_to_texture_rectangle_rgba = GL_FALSE;
1534 if (pglXGetFBConfigAttrib( gdi_display, fmt->fbconfig, GLX_FLOAT_COMPONENTS_NV, &value )) value = -1;
1535 pf->float_components = value;
1537 if (TRACE_ON(wgl)) dump_PIXELFORMATDESCRIPTOR( &pf->pfd );
1539 return nb_onscreen_formats;
1543 /***********************************************************************
1544 * glxdrv_wglGetPixelFormat
1546 static int glxdrv_wglGetPixelFormat( HDC hdc )
1548 struct gl_drawable *gl;
1549 int ret = 0;
1550 HWND hwnd;
1552 if ((hwnd = NtUserWindowFromDC( hdc )))
1553 return win32u_get_window_pixel_format( hwnd );
1555 if ((gl = get_gl_drawable( NULL, hdc )))
1557 ret = pixel_format_index( gl->format );
1558 /* Offscreen formats can't be used with traditional WGL calls.
1559 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1560 if (!is_onscreen_pixel_format( ret )) ret = 1;
1561 release_gl_drawable( gl );
1563 TRACE( "%p -> %d\n", hdc, ret );
1564 return ret;
1567 /***********************************************************************
1568 * glxdrv_wglSetPixelFormat
1570 static BOOL glxdrv_wglSetPixelFormat( HDC hdc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd )
1572 return set_pixel_format(hdc, iPixelFormat, FALSE);
1575 /***********************************************************************
1576 * glxdrv_wglCopyContext
1578 static BOOL glxdrv_wglCopyContext(struct wgl_context *src, struct wgl_context *dst, UINT mask)
1580 TRACE("%p -> %p mask %#x\n", src, dst, mask);
1582 X11DRV_expect_error( gdi_display, GLXErrorHandler, NULL );
1583 pglXCopyContext( gdi_display, src->ctx, dst->ctx, mask );
1584 XSync( gdi_display, False );
1585 if (X11DRV_check_error())
1587 static unsigned int once;
1589 if (!once++)
1591 ERR("glXCopyContext failed. glXCopyContext() for direct rendering contexts not "
1592 "implemented in the host graphics driver?\n");
1594 return FALSE;
1597 return TRUE;
1600 /***********************************************************************
1601 * glxdrv_wglCreateContext
1603 static struct wgl_context *glxdrv_wglCreateContext( HDC hdc )
1605 struct wgl_context *ret;
1606 struct gl_drawable *gl;
1608 if (!(gl = get_gl_drawable( NtUserWindowFromDC( hdc ), hdc )))
1610 RtlSetLastWin32Error( ERROR_INVALID_PIXEL_FORMAT );
1611 return NULL;
1614 if ((ret = calloc( 1, sizeof(*ret) )))
1616 ret->hdc = hdc;
1617 ret->fmt = gl->format;
1618 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1619 pthread_mutex_lock( &context_mutex );
1620 list_add_head( &context_list, &ret->entry );
1621 pthread_mutex_unlock( &context_mutex );
1623 release_gl_drawable( gl );
1624 TRACE( "%p -> %p\n", hdc, ret );
1625 return ret;
1628 /***********************************************************************
1629 * glxdrv_wglDeleteContext
1631 static BOOL glxdrv_wglDeleteContext(struct wgl_context *ctx)
1633 struct wgl_pbuffer *pb;
1635 TRACE("(%p)\n", ctx);
1637 pthread_mutex_lock( &context_mutex );
1638 list_remove( &ctx->entry );
1639 LIST_FOR_EACH_ENTRY( pb, &pbuffer_list, struct wgl_pbuffer, entry )
1641 if (pb->prev_context == ctx->ctx) {
1642 pglXDestroyContext(gdi_display, pb->tmp_context);
1643 pb->prev_context = pb->tmp_context = NULL;
1646 pthread_mutex_unlock( &context_mutex );
1648 if (ctx->ctx) pglXDestroyContext( gdi_display, ctx->ctx );
1649 release_gl_drawable( ctx->drawables[0] );
1650 release_gl_drawable( ctx->drawables[1] );
1651 release_gl_drawable( ctx->new_drawables[0] );
1652 release_gl_drawable( ctx->new_drawables[1] );
1653 free( ctx );
1654 return TRUE;
1657 /***********************************************************************
1658 * glxdrv_wglGetProcAddress
1660 static PROC glxdrv_wglGetProcAddress(LPCSTR lpszProc)
1662 if (!strncmp(lpszProc, "wgl", 3)) return NULL;
1663 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1666 static void set_context_drawables( struct wgl_context *ctx, struct gl_drawable *draw,
1667 struct gl_drawable *read )
1669 struct gl_drawable *prev[4];
1670 int i;
1672 prev[0] = ctx->drawables[0];
1673 prev[1] = ctx->drawables[1];
1674 prev[2] = ctx->new_drawables[0];
1675 prev[3] = ctx->new_drawables[1];
1676 ctx->drawables[0] = grab_gl_drawable( draw );
1677 ctx->drawables[1] = read ? grab_gl_drawable( read ) : NULL;
1678 ctx->new_drawables[0] = ctx->new_drawables[1] = NULL;
1679 for (i = 0; i < 4; i++) release_gl_drawable( prev[i] );
1682 /***********************************************************************
1683 * glxdrv_wglMakeCurrent
1685 static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx)
1687 BOOL ret = FALSE;
1688 struct gl_drawable *gl;
1690 TRACE("(%p,%p)\n", hdc, ctx);
1692 if (!ctx)
1694 pglXMakeCurrent(gdi_display, None, NULL);
1695 NtCurrentTeb()->glContext = NULL;
1696 return TRUE;
1699 if ((gl = get_gl_drawable( NtUserWindowFromDC( hdc ), hdc )))
1701 if (ctx->fmt != gl->format)
1703 WARN( "mismatched pixel format hdc %p %p ctx %p %p\n", hdc, gl->format, ctx, ctx->fmt );
1704 RtlSetLastWin32Error( ERROR_INVALID_PIXEL_FORMAT );
1705 goto done;
1708 TRACE("hdc %p drawable %lx fmt %p ctx %p %s\n", hdc, gl->drawable, gl->format, ctx->ctx,
1709 debugstr_fbconfig( gl->format->fbconfig ));
1711 pthread_mutex_lock( &context_mutex );
1712 ret = pglXMakeCurrent(gdi_display, gl->drawable, ctx->ctx);
1713 if (ret)
1715 NtCurrentTeb()->glContext = ctx;
1716 ctx->has_been_current = TRUE;
1717 ctx->hdc = hdc;
1718 set_context_drawables( ctx, gl, gl );
1719 pthread_mutex_unlock( &context_mutex );
1720 goto done;
1722 pthread_mutex_unlock( &context_mutex );
1724 RtlSetLastWin32Error( ERROR_INVALID_HANDLE );
1726 done:
1727 release_gl_drawable( gl );
1728 TRACE( "%p,%p returning %d\n", hdc, ctx, ret );
1729 return ret;
1732 /***********************************************************************
1733 * X11DRV_wglMakeContextCurrentARB
1735 static BOOL X11DRV_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *ctx )
1737 BOOL ret = FALSE;
1738 struct gl_drawable *draw_gl, *read_gl = NULL;
1740 TRACE("(%p,%p,%p)\n", draw_hdc, read_hdc, ctx);
1742 if (!ctx)
1744 pglXMakeCurrent(gdi_display, None, NULL);
1745 NtCurrentTeb()->glContext = NULL;
1746 return TRUE;
1749 if (!pglXMakeContextCurrent) return FALSE;
1751 if ((draw_gl = get_gl_drawable( NtUserWindowFromDC( draw_hdc ), draw_hdc )))
1753 read_gl = get_gl_drawable( NtUserWindowFromDC( read_hdc ), read_hdc );
1755 pthread_mutex_lock( &context_mutex );
1756 ret = pglXMakeContextCurrent(gdi_display, draw_gl->drawable,
1757 read_gl ? read_gl->drawable : 0, ctx->ctx);
1758 if (ret)
1760 ctx->has_been_current = TRUE;
1761 ctx->hdc = draw_hdc;
1762 set_context_drawables( ctx, draw_gl, read_gl );
1763 NtCurrentTeb()->glContext = ctx;
1764 pthread_mutex_unlock( &context_mutex );
1765 goto done;
1767 pthread_mutex_unlock( &context_mutex );
1769 RtlSetLastWin32Error( ERROR_INVALID_HANDLE );
1770 done:
1771 release_gl_drawable( read_gl );
1772 release_gl_drawable( draw_gl );
1773 TRACE( "%p,%p,%p returning %d\n", draw_hdc, read_hdc, ctx, ret );
1774 return ret;
1777 /***********************************************************************
1778 * glxdrv_wglShareLists
1780 static BOOL glxdrv_wglShareLists(struct wgl_context *org, struct wgl_context *dest)
1782 struct wgl_context *keep, *clobber;
1784 TRACE("(%p, %p)\n", org, dest);
1786 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1787 * at context creation time but in case of WGL it is done using wglShareLists.
1788 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1789 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1790 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1791 * so there delaying context creation doesn't work.
1793 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1794 * and when a program requests sharing we recreate the destination or source context if it
1795 * hasn't been made current and it hasn't shared display lists before.
1798 if (!dest->has_been_current && !dest->sharing)
1800 keep = org;
1801 clobber = dest;
1803 else if (!org->has_been_current && !org->sharing)
1805 keep = dest;
1806 clobber = org;
1808 else
1810 ERR("Could not share display lists because both of the contexts have already been current or shared\n");
1811 return FALSE;
1814 pglXDestroyContext(gdi_display, clobber->ctx);
1815 clobber->ctx = create_glxcontext(gdi_display, clobber, keep->ctx);
1816 TRACE("re-created context (%p) for Wine context %p (%s) sharing lists with ctx %p (%s)\n",
1817 clobber->ctx, clobber, debugstr_fbconfig(clobber->fmt->fbconfig),
1818 keep->ctx, debugstr_fbconfig(keep->fmt->fbconfig));
1820 org->sharing = TRUE;
1821 dest->sharing = TRUE;
1822 return TRUE;
1825 static void wglFinish(void)
1827 struct x11drv_escape_flush_gl_drawable escape;
1828 struct gl_drawable *gl;
1829 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1831 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
1832 escape.gl_drawable = 0;
1833 escape.flush = FALSE;
1835 if ((gl = get_gl_drawable( NtUserWindowFromDC( ctx->hdc ), 0 )))
1837 switch (gl->type)
1839 case DC_GL_PIXMAP_WIN: escape.gl_drawable = gl->pixmap; break;
1840 case DC_GL_CHILD_WIN: escape.gl_drawable = gl->window; break;
1841 default: break;
1843 sync_context(ctx);
1844 release_gl_drawable( gl );
1847 pglFinish();
1848 if (escape.gl_drawable)
1849 NtGdiExtEscape( ctx->hdc, NULL, 0, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1852 static void wglFlush(void)
1854 struct x11drv_escape_flush_gl_drawable escape;
1855 struct gl_drawable *gl;
1856 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1858 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
1859 escape.gl_drawable = 0;
1860 escape.flush = FALSE;
1862 if ((gl = get_gl_drawable( NtUserWindowFromDC( ctx->hdc ), 0 )))
1864 switch (gl->type)
1866 case DC_GL_PIXMAP_WIN: escape.gl_drawable = gl->pixmap; break;
1867 case DC_GL_CHILD_WIN: escape.gl_drawable = gl->window; break;
1868 default: break;
1870 sync_context(ctx);
1871 release_gl_drawable( gl );
1874 pglFlush();
1875 if (escape.gl_drawable)
1876 NtGdiExtEscape( ctx->hdc, NULL, 0, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
1879 static const GLubyte *wglGetString(GLenum name)
1881 if (name == GL_EXTENSIONS && glExtensions) return (const GLubyte *)glExtensions;
1882 return pglGetString(name);
1885 /***********************************************************************
1886 * X11DRV_wglCreateContextAttribsARB
1888 static struct wgl_context *X11DRV_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *hShareContext,
1889 const int* attribList )
1891 struct wgl_context *ret;
1892 struct gl_drawable *gl;
1893 int err = 0;
1895 TRACE("(%p %p %p)\n", hdc, hShareContext, attribList);
1897 if (!(gl = get_gl_drawable( NtUserWindowFromDC( hdc ), hdc )))
1899 RtlSetLastWin32Error( ERROR_INVALID_PIXEL_FORMAT );
1900 return NULL;
1903 if ((ret = calloc( 1, sizeof(*ret) )))
1905 ret->hdc = hdc;
1906 ret->fmt = gl->format;
1907 ret->gl3_context = TRUE;
1908 if (attribList)
1910 int *pContextAttribList = &ret->attribList[0];
1911 /* attribList consists of pairs {token, value] terminated with 0 */
1912 while(attribList[0] != 0)
1914 TRACE("%#x %#x\n", attribList[0], attribList[1]);
1915 switch(attribList[0])
1917 case WGL_CONTEXT_MAJOR_VERSION_ARB:
1918 pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
1919 pContextAttribList[1] = attribList[1];
1920 pContextAttribList += 2;
1921 ret->numAttribs++;
1922 break;
1923 case WGL_CONTEXT_MINOR_VERSION_ARB:
1924 pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB;
1925 pContextAttribList[1] = attribList[1];
1926 pContextAttribList += 2;
1927 ret->numAttribs++;
1928 break;
1929 case WGL_CONTEXT_LAYER_PLANE_ARB:
1930 break;
1931 case WGL_CONTEXT_FLAGS_ARB:
1932 pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB;
1933 pContextAttribList[1] = attribList[1];
1934 pContextAttribList += 2;
1935 ret->numAttribs++;
1936 break;
1937 case WGL_CONTEXT_OPENGL_NO_ERROR_ARB:
1938 pContextAttribList[0] = GLX_CONTEXT_OPENGL_NO_ERROR_ARB;
1939 pContextAttribList[1] = attribList[1];
1940 pContextAttribList += 2;
1941 ret->numAttribs++;
1942 break;
1943 case WGL_CONTEXT_PROFILE_MASK_ARB:
1944 pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
1945 pContextAttribList[1] = attribList[1];
1946 pContextAttribList += 2;
1947 ret->numAttribs++;
1948 break;
1949 case WGL_RENDERER_ID_WINE:
1950 pContextAttribList[0] = GLX_RENDERER_ID_MESA;
1951 pContextAttribList[1] = attribList[1];
1952 pContextAttribList += 2;
1953 ret->numAttribs++;
1954 break;
1955 default:
1956 ERR("Unhandled attribList pair: %#x %#x\n", attribList[0], attribList[1]);
1958 attribList += 2;
1962 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
1963 ret->ctx = create_glxcontext(gdi_display, ret, hShareContext ? hShareContext->ctx : NULL);
1964 XSync(gdi_display, False);
1965 if ((err = X11DRV_check_error()) || !ret->ctx)
1967 /* In the future we should convert the GLX error to a win32 one here if needed */
1968 WARN("Context creation failed (error %#x).\n", err);
1969 free( ret );
1970 ret = NULL;
1972 else
1974 pthread_mutex_lock( &context_mutex );
1975 list_add_head( &context_list, &ret->entry );
1976 pthread_mutex_unlock( &context_mutex );
1980 release_gl_drawable( gl );
1981 TRACE( "%p -> %p\n", hdc, ret );
1982 return ret;
1986 * X11DRV_wglGetExtensionsStringARB
1988 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
1990 static const char *X11DRV_wglGetExtensionsStringARB(HDC hdc)
1992 TRACE("() returning \"%s\"\n", wglExtensions);
1993 return wglExtensions;
1997 * X11DRV_wglCreatePbufferARB
1999 * WGL_ARB_pbuffer: wglCreatePbufferARB
2001 static struct wgl_pbuffer *X11DRV_wglCreatePbufferARB( HDC hdc, int iPixelFormat, int iWidth, int iHeight,
2002 const int *piAttribList )
2004 struct wgl_pbuffer* object;
2005 const struct glx_pixel_format *fmt;
2006 int attribs[256];
2007 int nAttribs = 0;
2009 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2011 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2012 fmt = get_pixel_format(gdi_display, iPixelFormat, TRUE /* Offscreen */);
2013 if(!fmt) {
2014 ERR("(%p): invalid pixel format %d\n", hdc, iPixelFormat);
2015 RtlSetLastWin32Error(ERROR_INVALID_PIXEL_FORMAT);
2016 return NULL;
2019 object = calloc( 1, sizeof(*object) );
2020 if (NULL == object) {
2021 RtlSetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES);
2022 return NULL;
2024 object->width = iWidth;
2025 object->height = iHeight;
2026 object->fmt = fmt;
2028 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2029 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2030 while (piAttribList && 0 != *piAttribList) {
2031 int attr_v;
2032 switch (*piAttribList) {
2033 case WGL_PBUFFER_LARGEST_ARB: {
2034 ++piAttribList;
2035 attr_v = *piAttribList;
2036 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2037 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2038 break;
2041 case WGL_TEXTURE_FORMAT_ARB: {
2042 ++piAttribList;
2043 attr_v = *piAttribList;
2044 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2045 if (WGL_NO_TEXTURE_ARB == attr_v) {
2046 object->use_render_texture = 0;
2047 } else {
2048 if (!use_render_texture_emulation) {
2049 RtlSetLastWin32Error(ERROR_INVALID_DATA);
2050 goto create_failed;
2052 switch (attr_v) {
2053 case WGL_TEXTURE_RGB_ARB:
2054 object->use_render_texture = GL_RGB;
2055 object->texture_bpp = 3;
2056 object->texture_format = GL_RGB;
2057 object->texture_type = GL_UNSIGNED_BYTE;
2058 break;
2059 case WGL_TEXTURE_RGBA_ARB:
2060 object->use_render_texture = GL_RGBA;
2061 object->texture_bpp = 4;
2062 object->texture_format = GL_RGBA;
2063 object->texture_type = GL_UNSIGNED_BYTE;
2064 break;
2066 /* WGL_FLOAT_COMPONENTS_NV */
2067 case WGL_TEXTURE_FLOAT_R_NV:
2068 object->use_render_texture = GL_FLOAT_R_NV;
2069 object->texture_bpp = 4;
2070 object->texture_format = GL_RED;
2071 object->texture_type = GL_FLOAT;
2072 break;
2073 case WGL_TEXTURE_FLOAT_RG_NV:
2074 object->use_render_texture = GL_FLOAT_RG_NV;
2075 object->texture_bpp = 8;
2076 object->texture_format = GL_LUMINANCE_ALPHA;
2077 object->texture_type = GL_FLOAT;
2078 break;
2079 case WGL_TEXTURE_FLOAT_RGB_NV:
2080 object->use_render_texture = GL_FLOAT_RGB_NV;
2081 object->texture_bpp = 12;
2082 object->texture_format = GL_RGB;
2083 object->texture_type = GL_FLOAT;
2084 break;
2085 case WGL_TEXTURE_FLOAT_RGBA_NV:
2086 object->use_render_texture = GL_FLOAT_RGBA_NV;
2087 object->texture_bpp = 16;
2088 object->texture_format = GL_RGBA;
2089 object->texture_type = GL_FLOAT;
2090 break;
2091 default:
2092 ERR("Unknown texture format: %x\n", attr_v);
2093 RtlSetLastWin32Error(ERROR_INVALID_DATA);
2094 goto create_failed;
2097 break;
2100 case WGL_TEXTURE_TARGET_ARB: {
2101 ++piAttribList;
2102 attr_v = *piAttribList;
2103 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2104 if (WGL_NO_TEXTURE_ARB == attr_v) {
2105 object->texture_target = 0;
2106 } else {
2107 if (!use_render_texture_emulation) {
2108 RtlSetLastWin32Error(ERROR_INVALID_DATA);
2109 goto create_failed;
2111 switch (attr_v) {
2112 case WGL_TEXTURE_CUBE_MAP_ARB: {
2113 if (iWidth != iHeight) {
2114 RtlSetLastWin32Error(ERROR_INVALID_DATA);
2115 goto create_failed;
2117 object->texture_target = GL_TEXTURE_CUBE_MAP;
2118 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2119 break;
2121 case WGL_TEXTURE_1D_ARB: {
2122 if (1 != iHeight) {
2123 RtlSetLastWin32Error(ERROR_INVALID_DATA);
2124 goto create_failed;
2126 object->texture_target = GL_TEXTURE_1D;
2127 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2128 break;
2130 case WGL_TEXTURE_2D_ARB: {
2131 object->texture_target = GL_TEXTURE_2D;
2132 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2133 break;
2135 case WGL_TEXTURE_RECTANGLE_NV: {
2136 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2137 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2138 break;
2140 default:
2141 ERR("Unknown texture target: %x\n", attr_v);
2142 RtlSetLastWin32Error(ERROR_INVALID_DATA);
2143 goto create_failed;
2146 break;
2149 case WGL_MIPMAP_TEXTURE_ARB: {
2150 ++piAttribList;
2151 attr_v = *piAttribList;
2152 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2153 if (!use_render_texture_emulation) {
2154 RtlSetLastWin32Error(ERROR_INVALID_DATA);
2155 goto create_failed;
2157 break;
2160 ++piAttribList;
2163 PUSH1(attribs, None);
2164 if (!(object->gl = calloc( 1, sizeof(*object->gl) )))
2166 RtlSetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES);
2167 goto create_failed;
2169 object->gl->type = DC_GL_PBUFFER;
2170 object->gl->format = object->fmt;
2171 object->gl->ref = 1;
2173 object->gl->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2174 TRACE("new Pbuffer drawable as %p (%lx)\n", object->gl, object->gl->drawable);
2175 if (!object->gl->drawable) {
2176 free( object->gl );
2177 RtlSetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES);
2178 goto create_failed; /* unexpected error */
2180 pthread_mutex_lock( &context_mutex );
2181 list_add_head( &pbuffer_list, &object->entry );
2182 pthread_mutex_unlock( &context_mutex );
2183 TRACE("->(%p)\n", object);
2184 return object;
2186 create_failed:
2187 free( object );
2188 TRACE("->(FAILED)\n");
2189 return NULL;
2193 * X11DRV_wglDestroyPbufferARB
2195 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2197 static BOOL X11DRV_wglDestroyPbufferARB( struct wgl_pbuffer *object )
2199 TRACE("(%p)\n", object);
2201 pthread_mutex_lock( &context_mutex );
2202 list_remove( &object->entry );
2203 pthread_mutex_unlock( &context_mutex );
2204 release_gl_drawable( object->gl );
2205 if (object->tmp_context)
2206 pglXDestroyContext(gdi_display, object->tmp_context);
2207 free( object );
2208 return GL_TRUE;
2212 * X11DRV_wglGetPbufferDCARB
2214 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2216 static HDC X11DRV_wglGetPbufferDCARB( struct wgl_pbuffer *object )
2218 struct x11drv_escape_set_drawable escape;
2219 struct gl_drawable *prev;
2220 HDC hdc;
2222 hdc = NtGdiOpenDCW( NULL, NULL, NULL, 0, TRUE, NULL, NULL, NULL );
2223 if (!hdc) return 0;
2225 pthread_mutex_lock( &context_mutex );
2226 if (!XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&prev ))
2227 release_gl_drawable( prev );
2228 grab_gl_drawable( object->gl );
2229 XSaveContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char *)object->gl );
2230 pthread_mutex_unlock( &context_mutex );
2232 escape.code = X11DRV_SET_DRAWABLE;
2233 escape.drawable = object->gl->drawable;
2234 escape.mode = IncludeInferiors;
2235 SetRect( &escape.dc_rect, 0, 0, object->width, object->height );
2236 NtGdiExtEscape( hdc, NULL, 0, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2238 TRACE( "(%p)->(%p)\n", object, hdc );
2239 return hdc;
2243 * X11DRV_wglQueryPbufferARB
2245 * WGL_ARB_pbuffer: wglQueryPbufferARB
2247 static BOOL X11DRV_wglQueryPbufferARB( struct wgl_pbuffer *object, int iAttribute, int *piValue )
2249 TRACE("(%p, 0x%x, %p)\n", object, iAttribute, piValue);
2251 switch (iAttribute) {
2252 case WGL_PBUFFER_WIDTH_ARB:
2253 pglXQueryDrawable(gdi_display, object->gl->drawable, GLX_WIDTH, (unsigned int*) piValue);
2254 break;
2255 case WGL_PBUFFER_HEIGHT_ARB:
2256 pglXQueryDrawable(gdi_display, object->gl->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2257 break;
2259 case WGL_PBUFFER_LOST_ARB:
2260 /* GLX Pbuffers cannot be lost by default. We can support this by
2261 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2262 * to receive pixel buffer clobber events, however that may or may
2263 * not give any benefit */
2264 *piValue = GL_FALSE;
2265 break;
2267 case WGL_TEXTURE_FORMAT_ARB:
2268 if (!object->use_render_texture) {
2269 *piValue = WGL_NO_TEXTURE_ARB;
2270 } else {
2271 if (!use_render_texture_emulation) {
2272 RtlSetLastWin32Error(ERROR_INVALID_HANDLE);
2273 return GL_FALSE;
2275 switch(object->use_render_texture) {
2276 case GL_RGB:
2277 *piValue = WGL_TEXTURE_RGB_ARB;
2278 break;
2279 case GL_RGBA:
2280 *piValue = WGL_TEXTURE_RGBA_ARB;
2281 break;
2282 /* WGL_FLOAT_COMPONENTS_NV */
2283 case GL_FLOAT_R_NV:
2284 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2285 break;
2286 case GL_FLOAT_RG_NV:
2287 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2288 break;
2289 case GL_FLOAT_RGB_NV:
2290 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2291 break;
2292 case GL_FLOAT_RGBA_NV:
2293 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2294 break;
2295 default:
2296 ERR("Unknown texture format: %x\n", object->use_render_texture);
2299 break;
2301 case WGL_TEXTURE_TARGET_ARB:
2302 if (!object->texture_target){
2303 *piValue = WGL_NO_TEXTURE_ARB;
2304 } else {
2305 if (!use_render_texture_emulation) {
2306 RtlSetLastWin32Error(ERROR_INVALID_DATA);
2307 return GL_FALSE;
2309 switch (object->texture_target) {
2310 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2311 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2312 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2313 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2316 break;
2318 case WGL_MIPMAP_TEXTURE_ARB:
2319 *piValue = GL_FALSE; /** don't support that */
2320 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2321 break;
2323 default:
2324 FIXME("unexpected attribute %x\n", iAttribute);
2325 break;
2328 return GL_TRUE;
2332 * X11DRV_wglReleasePbufferDCARB
2334 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2336 static int X11DRV_wglReleasePbufferDCARB( struct wgl_pbuffer *object, HDC hdc )
2338 struct gl_drawable *gl;
2340 TRACE("(%p, %p)\n", object, hdc);
2342 pthread_mutex_lock( &context_mutex );
2344 if (!XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl ))
2346 XDeleteContext( gdi_display, (XID)hdc, gl_pbuffer_context );
2347 release_gl_drawable( gl );
2349 else hdc = 0;
2351 pthread_mutex_unlock( &context_mutex );
2353 return hdc && NtGdiDeleteObjectApp(hdc);
2357 * X11DRV_wglSetPbufferAttribARB
2359 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2361 static BOOL X11DRV_wglSetPbufferAttribARB( struct wgl_pbuffer *object, const int *piAttribList )
2363 GLboolean ret = GL_FALSE;
2365 WARN("(%p, %p): alpha-testing, report any problem\n", object, piAttribList);
2367 if (!object->use_render_texture) {
2368 RtlSetLastWin32Error(ERROR_INVALID_HANDLE);
2369 return GL_FALSE;
2371 if (use_render_texture_emulation) {
2372 return GL_TRUE;
2374 return ret;
2378 * X11DRV_wglBindTexImageARB
2380 * WGL_ARB_render_texture: wglBindTexImageARB
2382 static BOOL X11DRV_wglBindTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2384 GLboolean ret = GL_FALSE;
2386 TRACE("(%p, %d)\n", object, iBuffer);
2388 if (!object->use_render_texture) {
2389 RtlSetLastWin32Error(ERROR_INVALID_HANDLE);
2390 return GL_FALSE;
2393 if (use_render_texture_emulation) {
2394 static BOOL initialized = FALSE;
2395 int prev_binded_texture = 0;
2396 GLXContext prev_context;
2397 GLXDrawable prev_drawable;
2399 prev_context = pglXGetCurrentContext();
2400 prev_drawable = pglXGetCurrentDrawable();
2402 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2403 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2404 isn't ideal performance wise but I wasn't able to get other ways working.
2406 if(!initialized) {
2407 initialized = TRUE; /* Only show the FIXME once for performance reasons */
2408 FIXME("partial stub!\n");
2411 TRACE("drawable=%p (%lx), context=%p\n", object->gl, object->gl->drawable, prev_context);
2412 if (!object->tmp_context || object->prev_context != prev_context) {
2413 if (object->tmp_context)
2414 pglXDestroyContext(gdi_display, object->tmp_context);
2415 object->tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2416 object->prev_context = prev_context;
2419 opengl_funcs.gl.p_glGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2421 /* Switch to our pbuffer */
2422 pglXMakeCurrent(gdi_display, object->gl->drawable, object->tmp_context);
2424 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2425 * After that copy the pbuffer texture data. */
2426 opengl_funcs.gl.p_glBindTexture(object->texture_target, prev_binded_texture);
2427 opengl_funcs.gl.p_glCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2429 /* Switch back to the original drawable and context */
2430 pglXMakeCurrent(gdi_display, prev_drawable, prev_context);
2431 return GL_TRUE;
2434 return ret;
2438 * X11DRV_wglReleaseTexImageARB
2440 * WGL_ARB_render_texture: wglReleaseTexImageARB
2442 static BOOL X11DRV_wglReleaseTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2444 GLboolean ret = GL_FALSE;
2446 TRACE("(%p, %d)\n", object, iBuffer);
2448 if (!object->use_render_texture) {
2449 RtlSetLastWin32Error(ERROR_INVALID_HANDLE);
2450 return GL_FALSE;
2452 if (use_render_texture_emulation) {
2453 return GL_TRUE;
2455 return ret;
2459 * X11DRV_wglGetExtensionsStringEXT
2461 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2463 static const char *X11DRV_wglGetExtensionsStringEXT(void)
2465 TRACE("() returning \"%s\"\n", wglExtensions);
2466 return wglExtensions;
2470 * X11DRV_wglGetSwapIntervalEXT
2472 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2474 static int X11DRV_wglGetSwapIntervalEXT(void)
2476 struct wgl_context *ctx = NtCurrentTeb()->glContext;
2477 struct gl_drawable *gl;
2478 int swap_interval;
2480 TRACE("()\n");
2482 if (!(gl = get_gl_drawable( NtUserWindowFromDC( ctx->hdc ), ctx->hdc )))
2484 /* This can't happen because a current WGL context is required to get
2485 * here. Likely the application is buggy.
2487 WARN("No GL drawable found, returning swap interval 0\n");
2488 return 0;
2491 swap_interval = gl->swap_interval;
2492 release_gl_drawable(gl);
2494 return swap_interval;
2498 * X11DRV_wglSwapIntervalEXT
2500 * WGL_EXT_swap_control: wglSwapIntervalEXT
2502 static BOOL X11DRV_wglSwapIntervalEXT(int interval)
2504 struct wgl_context *ctx = NtCurrentTeb()->glContext;
2505 struct gl_drawable *gl;
2506 BOOL ret;
2508 TRACE("(%d)\n", interval);
2510 /* Without WGL/GLX_EXT_swap_control_tear a negative interval
2511 * is invalid.
2513 if (interval < 0 && !has_swap_control_tear)
2515 RtlSetLastWin32Error(ERROR_INVALID_DATA);
2516 return FALSE;
2519 if (!(gl = get_gl_drawable( NtUserWindowFromDC( ctx->hdc ), ctx->hdc )))
2521 RtlSetLastWin32Error(ERROR_DC_NOT_FOUND);
2522 return FALSE;
2525 pthread_mutex_lock( &context_mutex );
2526 ret = set_swap_interval(gl->drawable, interval);
2527 gl->refresh_swap_interval = FALSE;
2528 if (ret)
2529 gl->swap_interval = interval;
2530 else
2531 RtlSetLastWin32Error(ERROR_DC_NOT_FOUND);
2533 pthread_mutex_unlock( &context_mutex );
2534 release_gl_drawable(gl);
2536 return ret;
2540 * X11DRV_wglSetPixelFormatWINE
2542 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
2543 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
2545 static BOOL X11DRV_wglSetPixelFormatWINE(HDC hdc, int format)
2547 return set_pixel_format(hdc, format, TRUE);
2550 static BOOL X11DRV_wglQueryCurrentRendererIntegerWINE( GLenum attribute, GLuint *value )
2552 return pglXQueryCurrentRendererIntegerMESA( attribute, value );
2555 static const char *X11DRV_wglQueryCurrentRendererStringWINE( GLenum attribute )
2557 return pglXQueryCurrentRendererStringMESA( attribute );
2560 static BOOL X11DRV_wglQueryRendererIntegerWINE( HDC dc, GLint renderer, GLenum attribute, GLuint *value )
2562 return pglXQueryRendererIntegerMESA( gdi_display, DefaultScreen(gdi_display), renderer, attribute, value );
2565 static const char *X11DRV_wglQueryRendererStringWINE( HDC dc, GLint renderer, GLenum attribute )
2567 return pglXQueryRendererStringMESA( gdi_display, DefaultScreen(gdi_display), renderer, attribute );
2571 * glxRequireVersion (internal)
2573 * Check if the supported GLX version matches requiredVersion.
2575 static BOOL glxRequireVersion(int requiredVersion)
2577 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2578 return (requiredVersion <= glxVersion[1]);
2581 static void register_extension(const char *ext)
2583 if (wglExtensions[0])
2584 strcat(wglExtensions, " ");
2585 strcat(wglExtensions, ext);
2587 TRACE("'%s'\n", ext);
2591 * X11DRV_WineGL_LoadExtensions
2593 static void X11DRV_WineGL_LoadExtensions(void)
2595 wglExtensions[0] = 0;
2597 /* ARB Extensions */
2599 if (has_extension( glxExtensions, "GLX_ARB_create_context"))
2601 register_extension( "WGL_ARB_create_context" );
2602 opengl_funcs.ext.p_wglCreateContextAttribsARB = X11DRV_wglCreateContextAttribsARB;
2604 if (has_extension( glxExtensions, "GLX_ARB_create_context_no_error" ))
2605 register_extension( "WGL_ARB_create_context_no_error" );
2606 if (has_extension( glxExtensions, "GLX_ARB_create_context_profile"))
2607 register_extension("WGL_ARB_create_context_profile");
2611 register_extension( "WGL_ARB_extensions_string" );
2612 opengl_funcs.ext.p_wglGetExtensionsStringARB = X11DRV_wglGetExtensionsStringARB;
2614 if (glxRequireVersion(3))
2616 register_extension( "WGL_ARB_make_current_read" );
2617 opengl_funcs.ext.p_wglGetCurrentReadDCARB = (void *)1; /* never called */
2618 opengl_funcs.ext.p_wglMakeContextCurrentARB = X11DRV_wglMakeContextCurrentARB;
2621 if (has_extension( glxExtensions, "GLX_ARB_multisample")) register_extension( "WGL_ARB_multisample" );
2623 if (glxRequireVersion(3))
2625 register_extension( "WGL_ARB_pbuffer" );
2626 opengl_funcs.ext.p_wglCreatePbufferARB = X11DRV_wglCreatePbufferARB;
2627 opengl_funcs.ext.p_wglDestroyPbufferARB = X11DRV_wglDestroyPbufferARB;
2628 opengl_funcs.ext.p_wglGetPbufferDCARB = X11DRV_wglGetPbufferDCARB;
2629 opengl_funcs.ext.p_wglQueryPbufferARB = X11DRV_wglQueryPbufferARB;
2630 opengl_funcs.ext.p_wglReleasePbufferDCARB = X11DRV_wglReleasePbufferDCARB;
2631 opengl_funcs.ext.p_wglSetPbufferAttribARB = X11DRV_wglSetPbufferAttribARB;
2634 register_extension( "WGL_ARB_pixel_format" );
2635 opengl_funcs.ext.p_wglChoosePixelFormatARB = (void *)1; /* never called */
2636 opengl_funcs.ext.p_wglGetPixelFormatAttribfvARB = (void *)1; /* never called */
2637 opengl_funcs.ext.p_wglGetPixelFormatAttribivARB = (void *)1; /* never called */
2639 if (has_extension( glxExtensions, "GLX_ARB_fbconfig_float"))
2641 register_extension("WGL_ARB_pixel_format_float");
2642 register_extension("WGL_ATI_pixel_format_float");
2645 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
2646 if (has_extension( glxExtensions, "GLX_ARB_render_texture") ||
2647 (glxRequireVersion(3) && use_render_texture_emulation))
2649 register_extension( "WGL_ARB_render_texture" );
2650 opengl_funcs.ext.p_wglBindTexImageARB = X11DRV_wglBindTexImageARB;
2651 opengl_funcs.ext.p_wglReleaseTexImageARB = X11DRV_wglReleaseTexImageARB;
2653 /* The WGL version of GLX_NV_float_buffer requires render_texture */
2654 if (has_extension( glxExtensions, "GLX_NV_float_buffer"))
2655 register_extension("WGL_NV_float_buffer");
2657 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
2658 if (has_extension(glExtensions, "GL_NV_texture_rectangle"))
2659 register_extension("WGL_NV_render_texture_rectangle");
2662 /* EXT Extensions */
2664 register_extension( "WGL_EXT_extensions_string" );
2665 opengl_funcs.ext.p_wglGetExtensionsStringEXT = X11DRV_wglGetExtensionsStringEXT;
2667 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
2668 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
2669 register_extension( "WGL_EXT_swap_control" );
2670 opengl_funcs.ext.p_wglSwapIntervalEXT = X11DRV_wglSwapIntervalEXT;
2671 opengl_funcs.ext.p_wglGetSwapIntervalEXT = X11DRV_wglGetSwapIntervalEXT;
2673 if (has_extension( glxExtensions, "GLX_EXT_framebuffer_sRGB"))
2674 register_extension("WGL_EXT_framebuffer_sRGB");
2676 if (has_extension( glxExtensions, "GLX_EXT_fbconfig_packed_float"))
2677 register_extension("WGL_EXT_pixel_format_packed_float");
2679 if (has_extension( glxExtensions, "GLX_EXT_swap_control"))
2681 swap_control_method = GLX_SWAP_CONTROL_EXT;
2682 if (has_extension( glxExtensions, "GLX_EXT_swap_control_tear"))
2684 register_extension("WGL_EXT_swap_control_tear");
2685 has_swap_control_tear = TRUE;
2688 else if (has_extension( glxExtensions, "GLX_MESA_swap_control"))
2690 swap_control_method = GLX_SWAP_CONTROL_MESA;
2692 else if (has_extension( glxExtensions, "GLX_SGI_swap_control"))
2694 swap_control_method = GLX_SWAP_CONTROL_SGI;
2697 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
2698 if (has_extension(glExtensions, "GL_NV_vertex_array_range"))
2700 register_extension( "WGL_NV_vertex_array_range" );
2701 opengl_funcs.ext.p_wglAllocateMemoryNV = pglXAllocateMemoryNV;
2702 opengl_funcs.ext.p_wglFreeMemoryNV = pglXFreeMemoryNV;
2705 if (has_extension(glxExtensions, "GLX_OML_swap_method"))
2706 has_swap_method = TRUE;
2708 /* WINE-specific WGL Extensions */
2710 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
2711 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
2713 register_extension( "WGL_WINE_pixel_format_passthrough" );
2714 opengl_funcs.ext.p_wglSetPixelFormatWINE = X11DRV_wglSetPixelFormatWINE;
2716 if (has_extension( glxExtensions, "GLX_MESA_query_renderer" ))
2718 register_extension( "WGL_WINE_query_renderer" );
2719 opengl_funcs.ext.p_wglQueryCurrentRendererIntegerWINE = X11DRV_wglQueryCurrentRendererIntegerWINE;
2720 opengl_funcs.ext.p_wglQueryCurrentRendererStringWINE = X11DRV_wglQueryCurrentRendererStringWINE;
2721 opengl_funcs.ext.p_wglQueryRendererIntegerWINE = X11DRV_wglQueryRendererIntegerWINE;
2722 opengl_funcs.ext.p_wglQueryRendererStringWINE = X11DRV_wglQueryRendererStringWINE;
2728 * glxdrv_SwapBuffers
2730 * Swap the buffers of this DC
2732 static BOOL glxdrv_wglSwapBuffers( HDC hdc )
2734 struct x11drv_escape_flush_gl_drawable escape;
2735 struct gl_drawable *gl;
2736 struct wgl_context *ctx = NtCurrentTeb()->glContext;
2737 INT64 ust, msc, sbc, target_sbc = 0;
2739 TRACE("(%p)\n", hdc);
2741 escape.code = X11DRV_FLUSH_GL_DRAWABLE;
2742 escape.gl_drawable = 0;
2743 escape.flush = !pglXWaitForSbcOML;
2745 if (!(gl = get_gl_drawable( NtUserWindowFromDC( hdc ), hdc )))
2747 RtlSetLastWin32Error( ERROR_INVALID_HANDLE );
2748 return FALSE;
2751 pthread_mutex_lock( &context_mutex );
2752 if (gl->refresh_swap_interval)
2754 set_swap_interval(gl->drawable, gl->swap_interval);
2755 gl->refresh_swap_interval = FALSE;
2757 pthread_mutex_unlock( &context_mutex );
2759 switch (gl->type)
2761 case DC_GL_PIXMAP_WIN:
2762 if (ctx) sync_context( ctx );
2763 escape.gl_drawable = gl->pixmap;
2764 if (ctx && pglXCopySubBufferMESA) {
2765 /* (glX)SwapBuffers has an implicit glFlush effect, however
2766 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
2767 * copying */
2768 pglFlush();
2769 pglXCopySubBufferMESA( gdi_display, gl->drawable, 0, 0,
2770 gl->pixmap_size.cx, gl->pixmap_size.cy );
2771 break;
2773 if (ctx && pglXSwapBuffersMscOML)
2775 pglFlush();
2776 target_sbc = pglXSwapBuffersMscOML( gdi_display, gl->drawable, 0, 0, 0 );
2777 break;
2779 pglXSwapBuffers(gdi_display, gl->drawable);
2780 break;
2781 case DC_GL_WINDOW:
2782 case DC_GL_CHILD_WIN:
2783 if (ctx) sync_context( ctx );
2784 if (gl->type == DC_GL_CHILD_WIN) escape.gl_drawable = gl->window;
2785 /* fall through */
2786 default:
2787 if (ctx && escape.gl_drawable && pglXSwapBuffersMscOML)
2789 pglFlush();
2790 target_sbc = pglXSwapBuffersMscOML( gdi_display, gl->drawable, 0, 0, 0 );
2791 break;
2793 pglXSwapBuffers(gdi_display, gl->drawable);
2794 break;
2797 if (ctx && escape.gl_drawable && pglXWaitForSbcOML)
2798 pglXWaitForSbcOML( gdi_display, gl->drawable, target_sbc, &ust, &msc, &sbc );
2800 release_gl_drawable( gl );
2802 if (escape.gl_drawable)
2803 NtGdiExtEscape( ctx ? ctx->hdc : hdc, NULL, 0, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2804 return TRUE;
2807 static void glxdrv_get_pixel_formats( struct wgl_pixel_format *formats,
2808 UINT max_formats, UINT *num_formats,
2809 UINT *num_onscreen_formats )
2811 UINT i;
2813 if (!has_opengl())
2815 *num_formats = *num_onscreen_formats = 0;
2816 return;
2818 if (formats)
2820 for (i = 0; i < min( max_formats, nb_pixel_formats ); ++i)
2821 describe_pixel_format( i + 1, &formats[i] );
2823 *num_formats = nb_pixel_formats;
2824 *num_onscreen_formats = nb_onscreen_formats;
2827 static struct opengl_funcs opengl_funcs =
2830 glxdrv_wglCopyContext, /* p_wglCopyContext */
2831 glxdrv_wglCreateContext, /* p_wglCreateContext */
2832 glxdrv_wglDeleteContext, /* p_wglDeleteContext */
2833 glxdrv_wglGetPixelFormat, /* p_wglGetPixelFormat */
2834 glxdrv_wglGetProcAddress, /* p_wglGetProcAddress */
2835 glxdrv_wglMakeCurrent, /* p_wglMakeCurrent */
2836 glxdrv_wglSetPixelFormat, /* p_wglSetPixelFormat */
2837 glxdrv_wglShareLists, /* p_wglShareLists */
2838 glxdrv_wglSwapBuffers, /* p_wglSwapBuffers */
2839 glxdrv_get_pixel_formats, /* p_get_pixel_formats */
2843 struct opengl_funcs *get_glx_driver( UINT version )
2845 if (version != WINE_WGL_DRIVER_VERSION)
2847 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_WGL_DRIVER_VERSION );
2848 return NULL;
2850 if (has_opengl()) return &opengl_funcs;
2851 return NULL;
2854 #else /* no OpenGL includes */
2856 struct opengl_funcs *get_glx_driver( UINT version )
2858 return NULL;
2861 void sync_gl_drawable( HWND hwnd, BOOL known_child )
2865 void set_gl_drawable_parent( HWND hwnd, HWND parent )
2869 void destroy_gl_drawable( HWND hwnd )
2873 #endif /* defined(SONAME_LIBGL) */