winex11: Get the information from the drawable structure in SwapBuffers.
[wine.git] / dlls / winex11.drv / opengl.c
blob32a10ac0799fc0a79d25312ea1bc7aeda6a6d735
1 /*
2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006-2009 Roderick Colenbrander
8 * Copyright 2006 Tomas Carnecky
9 * Copyright 2012 Alexandre Julliard
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "config.h"
27 #include "wine/port.h"
29 #include <assert.h>
30 #include <stdlib.h>
31 #include <string.h>
33 #ifdef HAVE_SYS_SOCKET_H
34 #include <sys/socket.h>
35 #endif
36 #ifdef HAVE_SYS_UN_H
37 #include <sys/un.h>
38 #endif
39 #ifdef HAVE_GL_GL_H
40 # include <GL/gl.h>
41 #endif
42 #ifdef HAVE_GL_GLX_H
43 # include <GL/glx.h>
44 #endif
45 #undef APIENTRY
46 #undef GLAPI
47 #undef WINGDIAPI
49 #include "x11drv.h"
50 #include "xcomposite.h"
51 #include "winternl.h"
52 #include "wine/library.h"
53 #include "wine/debug.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
57 #ifdef SONAME_LIBGL
59 WINE_DECLARE_DEBUG_CHANNEL(winediag);
60 WINE_DECLARE_DEBUG_CHANNEL(fps);
62 #include "wine/wgl_driver.h"
63 #include "wine/wglext.h"
65 /* For compatibility with old Mesa headers */
66 #ifndef GLX_SAMPLE_BUFFERS_ARB
67 # define GLX_SAMPLE_BUFFERS_ARB 100000
68 #endif
69 #ifndef GLX_SAMPLES_ARB
70 # define GLX_SAMPLES_ARB 100001
71 #endif
72 #ifndef GL_TEXTURE_CUBE_MAP
73 # define GL_TEXTURE_CUBE_MAP 0x8513
74 #endif
75 #ifndef GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
76 # define GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20B2
77 #endif
78 #ifndef GLX_EXT_fbconfig_packed_float
79 # define GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT 0x20B1
80 # define GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT 0x00000008
81 #endif
82 #ifndef GLX_ARB_create_context
83 # define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
84 # define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
85 # define GLX_CONTEXT_FLAGS_ARB 0x2094
86 #endif
87 #ifndef GLX_ARB_create_context_profile
88 # define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
89 #endif
90 /** GLX_ATI_pixel_format_float */
91 #define GLX_RGBA_FLOAT_ATI_BIT 0x00000100
92 /** GLX_ARB_pixel_format_float */
93 #define GLX_RGBA_FLOAT_BIT 0x00000004
94 #define GLX_RGBA_FLOAT_TYPE 0x20B9
95 /** GL_NV_float_buffer */
96 #define GL_FLOAT_R_NV 0x8880
97 #define GL_FLOAT_RG_NV 0x8881
98 #define GL_FLOAT_RGB_NV 0x8882
99 #define GL_FLOAT_RGBA_NV 0x8883
100 #define GL_FLOAT_R16_NV 0x8884
101 #define GL_FLOAT_R32_NV 0x8885
102 #define GL_FLOAT_RG16_NV 0x8886
103 #define GL_FLOAT_RG32_NV 0x8887
104 #define GL_FLOAT_RGB16_NV 0x8888
105 #define GL_FLOAT_RGB32_NV 0x8889
106 #define GL_FLOAT_RGBA16_NV 0x888A
107 #define GL_FLOAT_RGBA32_NV 0x888B
108 #define GL_TEXTURE_FLOAT_COMPONENTS_NV 0x888C
109 #define GL_FLOAT_CLEAR_COLOR_VALUE_NV 0x888D
110 #define GL_FLOAT_RGBA_MODE_NV 0x888E
111 /** GLX_NV_float_buffer */
112 #define GLX_FLOAT_COMPONENTS_NV 0x20B0
115 struct WineGLInfo {
116 const char *glVersion;
117 char *glExtensions;
119 int glxVersion[2];
121 const char *glxServerVersion;
122 const char *glxServerVendor;
123 const char *glxServerExtensions;
125 const char *glxClientVersion;
126 const char *glxClientVendor;
127 const char *glxClientExtensions;
129 const char *glxExtensions;
131 BOOL glxDirect;
132 char wglExtensions[4096];
135 struct wgl_pixel_format
137 GLXFBConfig fbconfig;
138 int fmt_id;
139 int render_type;
140 DWORD dwFlags; /* We store some PFD_* flags in here for emulated bitmap formats */
143 struct wgl_context
145 HDC hdc;
146 BOOL has_been_current;
147 BOOL sharing;
148 BOOL gl3_context;
149 XVisualInfo *vis;
150 const struct wgl_pixel_format *fmt;
151 int numAttribs; /* This is needed for delaying wglCreateContextAttribsARB */
152 int attribList[16]; /* This is needed for delaying wglCreateContextAttribsARB */
153 GLXContext ctx;
154 Drawable drawables[2];
155 BOOL refresh_drawables;
156 struct list entry;
159 struct wgl_pbuffer
161 Drawable drawable;
162 const struct wgl_pixel_format* fmt;
163 int width;
164 int height;
165 int* attribList;
166 int use_render_texture; /* This is also the internal texture format */
167 int texture_bind_target;
168 int texture_bpp;
169 GLint texture_format;
170 GLuint texture_target;
171 GLenum texture_type;
172 GLuint texture;
173 int texture_level;
176 enum dc_gl_type
178 DC_GL_NONE, /* no GL support (pixel format not set yet) */
179 DC_GL_WINDOW, /* normal top-level window */
180 DC_GL_CHILD_WIN, /* child window using XComposite */
181 DC_GL_PIXMAP_WIN, /* child window using intermediate pixmap */
182 DC_GL_PBUFFER /* pseudo memory DC using a PBuffer */
185 struct glx_physdev
187 struct gdi_physdev dev;
188 X11DRV_PDEVICE *x11dev;
189 enum dc_gl_type type; /* type of GL device context */
190 const struct wgl_pixel_format *format;
191 Drawable drawable;
192 Pixmap pixmap; /* pixmap for a DL_GL_PIXMAP_WIN drawable */
195 struct gl_drawable
197 enum dc_gl_type type; /* type of GL surface */
198 Drawable drawable; /* drawable for rendering to the client area */
199 Pixmap pixmap; /* base pixmap if drawable is a GLXPixmap */
200 Colormap colormap; /* colormap used for the drawable */
201 const struct wgl_pixel_format *format; /* pixel format for the drawable */
202 XVisualInfo *visual; /* information about the GL visual */
203 RECT rect; /* drawable rect, relative to whole window drawable */
206 /* X context to associate a struct gl_drawable to an hwnd */
207 static XContext gl_hwnd_context;
208 /* X context to associate a struct gl_drawable to a pbuffer hdc */
209 static XContext gl_pbuffer_context;
211 static const struct gdi_dc_funcs glxdrv_funcs;
213 static inline struct glx_physdev *get_glxdrv_dev( PHYSDEV dev )
215 return (struct glx_physdev *)dev;
218 static struct list context_list = LIST_INIT( context_list );
219 static struct WineGLInfo WineGLInfo = { 0 };
220 static struct wgl_pixel_format *pixel_formats;
221 static int nb_pixel_formats, nb_onscreen_formats;
222 static int use_render_texture_emulation = 1;
223 static BOOL has_swap_control;
224 static int swap_interval = 1;
226 static CRITICAL_SECTION context_section;
227 static CRITICAL_SECTION_DEBUG critsect_debug =
229 0, 0, &context_section,
230 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
231 0, 0, { (DWORD_PTR)(__FILE__ ": context_section") }
233 static CRITICAL_SECTION context_section = { &critsect_debug, -1, 0, 0, 0, 0 };
235 static struct opengl_funcs opengl_funcs;
237 #define USE_GL_FUNC(name) #name,
238 static const char *opengl_func_names[] = { ALL_WGL_FUNCS };
239 #undef USE_GL_FUNC
241 static void X11DRV_WineGL_LoadExtensions(void);
242 static void init_pixel_formats( Display *display );
243 static BOOL glxRequireVersion(int requiredVersion);
245 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
246 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
247 TRACE(" - dwFlags : ");
248 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
249 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
250 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
251 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
252 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
253 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
254 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
255 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
256 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
257 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
258 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
259 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
260 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
261 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
262 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
263 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
264 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
265 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
266 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
267 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
268 #undef TEST_AND_DUMP
269 TRACE("\n");
271 TRACE(" - iPixelType : ");
272 switch (ppfd->iPixelType) {
273 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
274 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
276 TRACE("\n");
278 TRACE(" - Color : %d\n", ppfd->cColorBits);
279 TRACE(" - Red : %d\n", ppfd->cRedBits);
280 TRACE(" - Green : %d\n", ppfd->cGreenBits);
281 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
282 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
283 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
284 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
285 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
286 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
288 TRACE(" - iLayerType : ");
289 switch (ppfd->iLayerType) {
290 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
291 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
292 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
294 TRACE("\n");
297 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
298 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
300 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
301 /* GLX 1.0 */
302 MAKE_FUNCPTR(glXChooseVisual)
303 MAKE_FUNCPTR(glXCopyContext)
304 MAKE_FUNCPTR(glXCreateContext)
305 MAKE_FUNCPTR(glXCreateGLXPixmap)
306 MAKE_FUNCPTR(glXGetCurrentContext)
307 MAKE_FUNCPTR(glXGetCurrentDrawable)
308 MAKE_FUNCPTR(glXDestroyContext)
309 MAKE_FUNCPTR(glXDestroyGLXPixmap)
310 MAKE_FUNCPTR(glXGetConfig)
311 MAKE_FUNCPTR(glXIsDirect)
312 MAKE_FUNCPTR(glXMakeCurrent)
313 MAKE_FUNCPTR(glXSwapBuffers)
314 MAKE_FUNCPTR(glXQueryExtension)
315 MAKE_FUNCPTR(glXQueryVersion)
317 /* GLX 1.1 */
318 MAKE_FUNCPTR(glXGetClientString)
319 MAKE_FUNCPTR(glXQueryExtensionsString)
320 MAKE_FUNCPTR(glXQueryServerString)
322 /* GLX 1.3 */
323 MAKE_FUNCPTR(glXGetFBConfigs)
324 MAKE_FUNCPTR(glXChooseFBConfig)
325 MAKE_FUNCPTR(glXCreatePbuffer)
326 MAKE_FUNCPTR(glXCreateNewContext)
327 MAKE_FUNCPTR(glXDestroyPbuffer)
328 MAKE_FUNCPTR(glXGetFBConfigAttrib)
329 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
330 MAKE_FUNCPTR(glXMakeContextCurrent)
331 MAKE_FUNCPTR(glXQueryDrawable)
332 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
333 #undef MAKE_FUNCPTR
335 /* GLX Extensions */
336 static GLXContext (*pglXCreateContextAttribsARB)(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
337 static void* (*pglXGetProcAddressARB)(const GLubyte *);
338 static int (*pglXSwapIntervalSGI)(int);
340 /* NV GLX Extension */
341 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
342 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
344 /* MESA GLX Extensions */
345 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
347 /* Standard OpenGL */
348 static void (*pglFinish)(void);
349 static void (*pglFlush)(void);
351 static void wglFinish(void);
352 static void wglFlush(void);
354 /* check if the extension is present in the list */
355 static BOOL has_extension( const char *list, const char *ext )
357 size_t len = strlen( ext );
359 while (list)
361 while (*list == ' ') list++;
362 if (!strncmp( list, ext, len ) && (!list[len] || list[len] == ' ')) return TRUE;
363 list = strchr( list, ' ' );
365 return FALSE;
368 static int GLXErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
370 /* In the future we might want to find the exact X or GLX error to report back to the app */
371 return 1;
374 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
376 int screen = DefaultScreen(gdi_display);
377 Window win = 0, root = 0;
378 const char *gl_renderer;
379 const char* str;
380 XVisualInfo *vis;
381 GLXContext ctx = NULL;
382 XSetWindowAttributes attr;
383 BOOL ret = FALSE;
384 int attribList[] = {GLX_RGBA, GLX_DOUBLEBUFFER, None};
386 attr.override_redirect = True;
387 attr.colormap = None;
388 attr.border_pixel = 0;
390 vis = pglXChooseVisual(gdi_display, screen, attribList);
391 if (vis) {
392 #ifdef __i386__
393 WORD old_fs = wine_get_fs();
394 /* Create a GLX Context. Without one we can't query GL information */
395 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
396 if (wine_get_fs() != old_fs)
398 wine_set_fs( old_fs );
399 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
400 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
401 goto done;
403 #else
404 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
405 #endif
407 if (!ctx) goto done;
409 root = RootWindow( gdi_display, vis->screen );
410 if (vis->visual != DefaultVisual( gdi_display, vis->screen ))
411 attr.colormap = XCreateColormap( gdi_display, root, vis->visual, AllocNone );
412 if ((win = XCreateWindow( gdi_display, root, -1, -1, 1, 1, 0, vis->depth, InputOutput,
413 vis->visual, CWBorderPixel | CWOverrideRedirect | CWColormap, &attr )))
414 XMapWindow( gdi_display, win );
415 else
416 win = root;
418 if(pglXMakeCurrent(gdi_display, win, ctx) == 0)
420 ERR_(winediag)( "Unable to activate OpenGL context, most likely your OpenGL drivers haven't been installed correctly\n" );
421 goto done;
423 gl_renderer = (const char *)opengl_funcs.gl.p_glGetString(GL_RENDERER);
424 WineGLInfo.glVersion = (const char *) opengl_funcs.gl.p_glGetString(GL_VERSION);
425 str = (const char *) opengl_funcs.gl.p_glGetString(GL_EXTENSIONS);
426 WineGLInfo.glExtensions = HeapAlloc(GetProcessHeap(), 0, strlen(str)+1);
427 strcpy(WineGLInfo.glExtensions, str);
429 /* Get the common GLX version supported by GLX client and server ( major/minor) */
430 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
432 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
433 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
434 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
436 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
437 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
438 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
440 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
441 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
443 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
444 TRACE("GL renderer : %s.\n", gl_renderer);
445 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
446 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
447 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
448 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
449 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
450 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
452 if(!WineGLInfo.glxDirect)
454 int fd = ConnectionNumber(gdi_display);
455 struct sockaddr_un uaddr;
456 unsigned int uaddrlen = sizeof(struct sockaddr_un);
458 /* In general indirect rendering on a local X11 server indicates a driver problem.
459 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
461 if(!getsockname(fd, (struct sockaddr *)&uaddr, &uaddrlen) && uaddr.sun_family == AF_UNIX)
462 ERR_(winediag)("Direct rendering is disabled, most likely your OpenGL drivers "
463 "haven't been installed correctly (using GL renderer %s, version %s).\n",
464 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
466 else
468 /* In general you would expect that if direct rendering is returned, that you receive hardware
469 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
470 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
471 * software rendering, it shows direct rendering.
473 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
474 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
475 * it shows 'Mesa X11'.
477 if(!strcmp(gl_renderer, "Software Rasterizer") || !strcmp(gl_renderer, "Mesa X11"))
478 ERR_(winediag)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL "
479 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
480 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
482 ret = TRUE;
484 done:
485 if(vis) XFree(vis);
486 if(ctx) {
487 pglXMakeCurrent(gdi_display, None, NULL);
488 pglXDestroyContext(gdi_display, ctx);
490 if (win != root) XDestroyWindow( gdi_display, win );
491 if (attr.colormap) XFreeColormap( gdi_display, attr.colormap );
492 if (!ret) ERR(" couldn't initialize OpenGL, expect problems\n");
493 return ret;
496 static BOOL has_opengl(void)
498 static int init_done;
499 static void *opengl_handle;
501 char buffer[200];
502 int error_base, event_base;
503 unsigned int i;
505 if (init_done) return (opengl_handle != NULL);
506 init_done = 1;
508 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
509 and include all dependencies */
510 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, buffer, sizeof(buffer));
511 if (opengl_handle == NULL)
513 ERR( "Failed to load libGL: %s\n", buffer );
514 ERR( "OpenGL support is disabled.\n");
515 return FALSE;
518 for (i = 0; i < sizeof(opengl_func_names)/sizeof(opengl_func_names[0]); i++)
520 if (!(((void **)&opengl_funcs.gl)[i] = wine_dlsym( opengl_handle, opengl_func_names[i], NULL, 0 )))
522 ERR( "%s not found in libGL, disabling OpenGL.\n", opengl_func_names[i] );
523 goto failed;
527 /* redirect some standard OpenGL functions */
528 #define REDIRECT(func) \
529 do { p##func = opengl_funcs.gl.p_##func; opengl_funcs.gl.p_##func = w##func; } while(0)
530 REDIRECT( glFinish );
531 REDIRECT( glFlush );
532 #undef REDIRECT
534 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
535 if (pglXGetProcAddressARB == NULL) {
536 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
537 goto failed;
540 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
542 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
543 goto failed; \
544 } while(0)
546 /* GLX 1.0 */
547 LOAD_FUNCPTR(glXChooseVisual);
548 LOAD_FUNCPTR(glXCopyContext);
549 LOAD_FUNCPTR(glXCreateContext);
550 LOAD_FUNCPTR(glXCreateGLXPixmap);
551 LOAD_FUNCPTR(glXGetCurrentContext);
552 LOAD_FUNCPTR(glXGetCurrentDrawable);
553 LOAD_FUNCPTR(glXDestroyContext);
554 LOAD_FUNCPTR(glXDestroyGLXPixmap);
555 LOAD_FUNCPTR(glXGetConfig);
556 LOAD_FUNCPTR(glXIsDirect);
557 LOAD_FUNCPTR(glXMakeCurrent);
558 LOAD_FUNCPTR(glXSwapBuffers);
559 LOAD_FUNCPTR(glXQueryExtension);
560 LOAD_FUNCPTR(glXQueryVersion);
562 /* GLX 1.1 */
563 LOAD_FUNCPTR(glXGetClientString);
564 LOAD_FUNCPTR(glXQueryExtensionsString);
565 LOAD_FUNCPTR(glXQueryServerString);
567 /* GLX 1.3 */
568 LOAD_FUNCPTR(glXCreatePbuffer);
569 LOAD_FUNCPTR(glXCreateNewContext);
570 LOAD_FUNCPTR(glXDestroyPbuffer);
571 LOAD_FUNCPTR(glXMakeContextCurrent);
572 LOAD_FUNCPTR(glXGetCurrentReadDrawable);
573 LOAD_FUNCPTR(glXGetFBConfigs);
574 #undef LOAD_FUNCPTR
576 /* It doesn't matter if these fail. They'll only be used if the driver reports
577 the associated extension is available (and if a driver reports the extension
578 is available but fails to provide the functions, it's quite broken) */
579 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
580 /* ARB GLX Extension */
581 LOAD_FUNCPTR(glXCreateContextAttribsARB);
582 /* SGI GLX Extension */
583 LOAD_FUNCPTR(glXSwapIntervalSGI);
584 /* NV GLX Extension */
585 LOAD_FUNCPTR(glXAllocateMemoryNV);
586 LOAD_FUNCPTR(glXFreeMemoryNV);
587 #undef LOAD_FUNCPTR
589 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed;
591 if (pglXQueryExtension(gdi_display, &error_base, &event_base)) {
592 TRACE("GLX is up and running error_base = %d\n", error_base);
593 } else {
594 ERR( "GLX extension is missing, disabling OpenGL.\n" );
595 goto failed;
597 gl_hwnd_context = XUniqueContext();
598 gl_pbuffer_context = XUniqueContext();
600 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
601 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
602 * rendering is used.
604 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
605 * depends on the reported GLX client / server version and on the client / server extension list.
606 * Those don't have to be the same.
608 * In general the server GLX information lists the capabilities in case of indirect rendering.
609 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
610 * available and in that case the client GLX informat can be used.
611 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
612 * in the GLX version/extension list. When a program does this it works for certain for both
613 * direct and indirect rendering.
615 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
616 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
617 * extension list which causes this extension not to be listed. (Wine requires this extension).
618 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
619 * pbuffers is around.
621 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
622 * the ATI drivers and from then on use GLX client information for them.
625 if(glxRequireVersion(3)) {
626 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
627 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
628 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
629 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
630 } else if (has_extension( WineGLInfo.glxExtensions, "GLX_SGIX_fbconfig")) {
631 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
632 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
633 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
635 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
636 * enable this function when the Xserver understand GLX 1.3 or newer
638 pglXQueryDrawable = NULL;
639 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
640 TRACE("Overriding ATI GLX capabilities!\n");
641 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
642 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
643 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
644 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
646 /* Use client GLX information in case of the ATI drivers. We override the
647 * capabilities over here and not somewhere else as ATI might better their
648 * life in the future. In case they release proper drivers this block of
649 * code won't be called. */
650 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
651 } else {
652 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
655 if (has_extension( WineGLInfo.glxExtensions, "GLX_MESA_copy_sub_buffer")) {
656 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
659 X11DRV_WineGL_LoadExtensions();
660 init_pixel_formats( gdi_display );
661 return TRUE;
663 failed:
664 wine_dlclose(opengl_handle, NULL, 0);
665 opengl_handle = NULL;
666 return FALSE;
669 static int describeContext( struct wgl_context *ctx ) {
670 int tmp;
671 int ctx_vis_id;
672 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
673 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
674 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
675 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
676 TRACE(" - VISUAL_ID 0x%x\n", tmp);
677 ctx_vis_id = tmp;
678 return ctx_vis_id;
681 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, struct wgl_pbuffer* pbuf) {
682 int nAttribs = 0;
683 unsigned cur = 0;
684 int pop;
685 int drawattrib = 0;
686 int nvfloatattrib = GLX_DONT_CARE;
687 int pixelattrib = GLX_DONT_CARE;
689 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
690 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
691 while (iWGLAttr && 0 != iWGLAttr[cur]) {
692 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
694 switch (iWGLAttr[cur]) {
695 case WGL_AUX_BUFFERS_ARB:
696 pop = iWGLAttr[++cur];
697 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
698 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
699 break;
700 case WGL_COLOR_BITS_ARB:
701 pop = iWGLAttr[++cur];
702 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
703 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
704 break;
705 case WGL_BLUE_BITS_ARB:
706 pop = iWGLAttr[++cur];
707 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
708 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
709 break;
710 case WGL_RED_BITS_ARB:
711 pop = iWGLAttr[++cur];
712 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
713 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
714 break;
715 case WGL_GREEN_BITS_ARB:
716 pop = iWGLAttr[++cur];
717 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
718 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
719 break;
720 case WGL_ALPHA_BITS_ARB:
721 pop = iWGLAttr[++cur];
722 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
723 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
724 break;
725 case WGL_DEPTH_BITS_ARB:
726 pop = iWGLAttr[++cur];
727 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
728 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
729 break;
730 case WGL_STENCIL_BITS_ARB:
731 pop = iWGLAttr[++cur];
732 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
733 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
734 break;
735 case WGL_DOUBLE_BUFFER_ARB:
736 pop = iWGLAttr[++cur];
737 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
738 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
739 break;
740 case WGL_STEREO_ARB:
741 pop = iWGLAttr[++cur];
742 PUSH2(oGLXAttr, GLX_STEREO, pop);
743 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur, pop);
744 break;
746 case WGL_PIXEL_TYPE_ARB:
747 pop = iWGLAttr[++cur];
748 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
749 switch (pop) {
750 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
751 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
752 /* This is the same as WGL_TYPE_RGBA_FLOAT_ATI but the GLX constants differ, only the ARB GLX one is widely supported so use that */
753 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
754 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT: pixelattrib = GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT; break ;
755 default:
756 ERR("unexpected PixelType(%x)\n", pop);
757 pop = 0;
759 break;
761 case WGL_SUPPORT_GDI_ARB:
762 /* This flag is set in a pixel format */
763 pop = iWGLAttr[++cur];
764 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
765 break;
767 case WGL_DRAW_TO_BITMAP_ARB:
768 /* This flag is set in a pixel format */
769 pop = iWGLAttr[++cur];
770 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
771 break;
773 case WGL_DRAW_TO_WINDOW_ARB:
774 pop = iWGLAttr[++cur];
775 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
776 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
777 if (pop) {
778 drawattrib |= GLX_WINDOW_BIT;
780 break;
782 case WGL_DRAW_TO_PBUFFER_ARB:
783 pop = iWGLAttr[++cur];
784 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
785 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
786 if (pop) {
787 drawattrib |= GLX_PBUFFER_BIT;
789 break;
791 case WGL_ACCELERATION_ARB:
792 /* This flag is set in a pixel format */
793 pop = iWGLAttr[++cur];
794 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur, pop);
795 break;
797 case WGL_SUPPORT_OPENGL_ARB:
798 pop = iWGLAttr[++cur];
799 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
800 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
801 break;
803 case WGL_SWAP_METHOD_ARB:
804 pop = iWGLAttr[++cur];
805 /* For now we ignore this and just return SWAP_EXCHANGE */
806 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur, pop);
807 break;
809 case WGL_PBUFFER_LARGEST_ARB:
810 pop = iWGLAttr[++cur];
811 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
812 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
813 break;
815 case WGL_SAMPLE_BUFFERS_ARB:
816 pop = iWGLAttr[++cur];
817 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
818 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
819 break;
821 case WGL_SAMPLES_ARB:
822 pop = iWGLAttr[++cur];
823 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
824 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
825 break;
827 case WGL_TEXTURE_FORMAT_ARB:
828 case WGL_TEXTURE_TARGET_ARB:
829 case WGL_MIPMAP_TEXTURE_ARB:
830 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
831 pop = iWGLAttr[++cur];
832 if (NULL == pbuf) {
833 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
835 if (!use_render_texture_emulation) {
836 if (WGL_NO_TEXTURE_ARB != pop) {
837 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
838 return -1; /** error: don't support it */
839 } else {
840 drawattrib |= GLX_PBUFFER_BIT;
843 break ;
844 case WGL_FLOAT_COMPONENTS_NV:
845 nvfloatattrib = iWGLAttr[++cur];
846 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
847 break ;
848 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
849 case WGL_BIND_TO_TEXTURE_RGB_ARB:
850 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
851 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
852 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
853 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
854 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
855 pop = iWGLAttr[++cur];
856 /** cannot be converted, see direct handling on
857 * - wglGetPixelFormatAttribivARB
858 * TODO: wglChoosePixelFormat
860 break ;
861 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
862 pop = iWGLAttr[++cur];
863 PUSH2(oGLXAttr, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, pop);
864 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur, pop);
865 break ;
867 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
868 pop = iWGLAttr[++cur];
869 PUSH2(oGLXAttr, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT, pop);
870 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur, pop);
871 break ;
872 default:
873 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
874 break;
876 ++cur;
879 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
880 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
881 * pixmap and pbuffer formats appear as well. */
882 if (!drawattrib) drawattrib = GLX_DONT_CARE;
883 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
884 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
886 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
887 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
888 * GLX_DONT_CARE unless it is overridden. */
889 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
890 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
892 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
893 if (has_extension(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
894 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
895 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
898 return nAttribs;
901 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
903 int render_type=0, render_type_bit;
904 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
905 switch(render_type_bit)
907 case GLX_RGBA_BIT:
908 render_type = GLX_RGBA_TYPE;
909 break;
910 case GLX_COLOR_INDEX_BIT:
911 render_type = GLX_COLOR_INDEX_TYPE;
912 break;
913 case GLX_RGBA_FLOAT_BIT:
914 render_type = GLX_RGBA_FLOAT_TYPE;
915 break;
916 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT:
917 render_type = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
918 break;
919 default:
920 ERR("Unknown render_type: %x\n", render_type_bit);
922 return render_type;
925 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
926 static BOOL check_fbconfig_bitmap_capability(Display *display, GLXFBConfig fbconfig)
928 int dbuf, value;
929 pglXGetFBConfigAttrib(display, fbconfig, GLX_DOUBLEBUFFER, &dbuf);
930 pglXGetFBConfigAttrib(gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &value);
932 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
933 * the GLX_PIXMAP_BIT set. */
934 return !dbuf && (value & GLX_PIXMAP_BIT);
937 static void init_pixel_formats( Display *display )
939 struct wgl_pixel_format *list;
940 int size = 0, onscreen_size = 0;
941 int fmt_id, nCfgs, i, run, bmp_formats;
942 GLXFBConfig* cfgs;
943 XVisualInfo *visinfo;
945 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
946 if (NULL == cfgs || 0 == nCfgs) {
947 if(cfgs != NULL) XFree(cfgs);
948 ERR("glXChooseFBConfig returns NULL\n");
949 return;
952 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
953 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
954 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
955 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
957 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
959 for(i=0, bmp_formats=0; i<nCfgs; i++)
961 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
962 bmp_formats++;
964 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats);
966 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nCfgs + bmp_formats) * sizeof(*list));
968 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
969 * Do this as GLX doesn't guarantee that the list is sorted */
970 for(run=0; run < 2; run++)
972 for(i=0; i<nCfgs; i++) {
973 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
974 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
976 /* The first run we only add onscreen formats (ones which have an associated X Visual).
977 * The second run we only set offscreen formats. */
978 if(!run && visinfo)
980 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
981 * The contents is copied to the destination using XCopyArea. For the copying to work
982 * the depth of the source and destination window should be the same. In general this should
983 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
984 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
985 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
986 * list formats with the same depth. */
987 if(visinfo->depth != screen_depth)
989 XFree(visinfo);
990 continue;
993 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
994 list[size].fbconfig = cfgs[i];
995 list[size].fmt_id = fmt_id;
996 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
997 list[size].dwFlags = 0;
998 size++;
999 onscreen_size++;
1001 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
1002 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
1004 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1005 list[size].fbconfig = cfgs[i];
1006 list[size].fmt_id = fmt_id;
1007 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1008 list[size].dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_GENERIC_FORMAT;
1009 size++;
1010 onscreen_size++;
1012 } else if(run && !visinfo) {
1013 int window_drawable=0;
1014 pglXGetFBConfigAttrib(gdi_display, cfgs[i], GLX_DRAWABLE_TYPE, &window_drawable);
1016 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
1017 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1018 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1019 * likely make our child window opengl rendering more complicated since likely you can't use
1020 * XCopyArea on a GLX Window.
1021 * For now ignore fbconfigs which are window drawable but lack a visual. */
1022 if(window_drawable & GLX_WINDOW_BIT)
1024 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id);
1025 continue;
1028 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1029 list[size].fbconfig = cfgs[i];
1030 list[size].fmt_id = fmt_id;
1031 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1032 list[size].dwFlags = 0;
1033 size++;
1036 if (visinfo) XFree(visinfo);
1040 XFree(cfgs);
1042 pixel_formats = list;
1043 nb_pixel_formats = size;
1044 nb_onscreen_formats = onscreen_size;
1047 static inline BOOL is_valid_pixel_format( int format )
1049 return format > 0 && format <= nb_pixel_formats;
1052 static inline BOOL is_onscreen_pixel_format( int format )
1054 return format > 0 && format <= nb_onscreen_formats;
1057 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1058 * In our WGL implementation we only support a subset of these formats namely the format of
1059 * Wine's main visual and offscreen formats (if they are available).
1060 * This function converts a WGL format to its corresponding GLX one.
1062 static const struct wgl_pixel_format *get_pixel_format(Display *display, int iPixelFormat, BOOL AllowOffscreen)
1064 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1065 * iPixelFormat in case of probing the number of pixelformats.
1067 if (is_valid_pixel_format( iPixelFormat ) &&
1068 (is_onscreen_pixel_format( iPixelFormat ) || AllowOffscreen)) {
1069 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n",
1070 pixel_formats[iPixelFormat-1].fmt_id, iPixelFormat);
1071 return &pixel_formats[iPixelFormat-1];
1073 return NULL;
1076 static int pixelformat_from_fbconfig_id(XID fbconfig_id)
1078 int i;
1080 if (!fbconfig_id) return 0;
1082 for (i = 0; i < nb_pixel_formats; i++)
1083 if (pixel_formats[i].fmt_id == fbconfig_id) return i + 1;
1085 /* This will happen on hwnds without a pixel format set; it's ok */
1086 return 0;
1090 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1091 static void mark_drawable_dirty(Drawable old, Drawable new)
1093 struct wgl_context *ctx;
1095 LIST_FOR_EACH_ENTRY( ctx, &context_list, struct wgl_context, entry )
1097 if (old == ctx->drawables[0]) {
1098 ctx->drawables[0] = new;
1099 ctx->refresh_drawables = TRUE;
1101 if (old == ctx->drawables[1]) {
1102 ctx->drawables[1] = new;
1103 ctx->refresh_drawables = TRUE;
1108 /* Given the current context, make sure its drawable is sync'd */
1109 static inline void sync_context(struct wgl_context *context)
1111 EnterCriticalSection( &context_section );
1112 if (context->refresh_drawables) {
1113 if (glxRequireVersion(3))
1114 pglXMakeContextCurrent(gdi_display, context->drawables[0],
1115 context->drawables[1], context->ctx);
1116 else
1117 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
1118 context->refresh_drawables = FALSE;
1120 LeaveCriticalSection( &context_section );
1124 static GLXContext create_glxcontext(Display *display, struct wgl_context *context, GLXContext shareList)
1126 GLXContext ctx;
1128 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1129 BOOL indirect = !(context->fmt->dwFlags & PFD_DRAW_TO_BITMAP);
1131 if(context->gl3_context)
1133 if(context->numAttribs)
1134 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, context->attribList);
1135 else
1136 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, NULL);
1138 else if(context->vis)
1139 ctx = pglXCreateContext(gdi_display, context->vis, shareList, indirect);
1140 else /* Create a GLX Context for a pbuffer */
1141 ctx = pglXCreateNewContext(gdi_display, context->fmt->fbconfig, context->fmt->render_type, shareList, TRUE);
1143 return ctx;
1147 /***********************************************************************
1148 * free_gl_drawable
1150 static void free_gl_drawable( struct gl_drawable *gl )
1152 switch (gl->type)
1154 case DC_GL_WINDOW:
1155 case DC_GL_CHILD_WIN:
1156 XDestroyWindow( gdi_display, gl->drawable );
1157 XFreeColormap( gdi_display, gl->colormap );
1158 break;
1159 case DC_GL_PIXMAP_WIN:
1160 pglXDestroyGLXPixmap( gdi_display, gl->drawable );
1161 XFreePixmap( gdi_display, gl->pixmap );
1162 break;
1163 default:
1164 break;
1166 if (gl->visual) XFree( gl->visual );
1167 HeapFree( GetProcessHeap(), 0, gl );
1171 /***********************************************************************
1172 * set_win_format
1174 BOOL set_win_format( HWND hwnd, XID fbconfig_id )
1176 XSetWindowAttributes attrib;
1177 struct gl_drawable *gl, *prev;
1178 int format;
1180 if (!(format = pixelformat_from_fbconfig_id( fbconfig_id ))) return FALSE;
1182 gl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*gl) );
1183 gl->format = &pixel_formats[format - 1];
1184 gl->visual = pglXGetVisualFromFBConfig( gdi_display, gl->format->fbconfig );
1185 if (!gl->visual)
1187 HeapFree( GetProcessHeap(), 0, gl );
1188 return FALSE;
1191 GetClientRect( hwnd, &gl->rect );
1192 gl->rect.right = min( max( 1, gl->rect.right ), 65535 );
1193 gl->rect.bottom = min( max( 1, gl->rect.bottom ), 65535 );
1195 if (GetAncestor( hwnd, GA_PARENT ) == GetDesktopWindow()) /* top-level window */
1197 Window parent = X11DRV_get_whole_window( hwnd );
1199 gl->type = DC_GL_WINDOW;
1200 gl->colormap = XCreateColormap( gdi_display, root_window, gl->visual->visual,
1201 (gl->visual->class == PseudoColor ||
1202 gl->visual->class == GrayScale ||
1203 gl->visual->class == DirectColor) ? AllocAll : AllocNone );
1204 attrib.colormap = gl->colormap;
1205 attrib.bit_gravity = NorthWestGravity;
1206 attrib.win_gravity = NorthWestGravity;
1207 attrib.backing_store = NotUseful;
1208 /* put the initial rect outside of the window, it will be moved into place by SetWindowPos */
1209 OffsetRect( &gl->rect, gl->rect.right, gl->rect.bottom );
1210 if (parent)
1211 gl->drawable = XCreateWindow( gdi_display, parent, gl->rect.left, gl->rect.top,
1212 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top,
1213 0, screen_depth, InputOutput, gl->visual->visual,
1214 CWBitGravity | CWWinGravity | CWBackingStore | CWColormap,
1215 &attrib );
1216 if (gl->drawable)
1217 XMapWindow( gdi_display, gl->drawable );
1218 else
1219 XFreeColormap( gdi_display, gl->colormap );
1221 #ifdef SONAME_LIBXCOMPOSITE
1222 else if(usexcomposite)
1224 static Window dummy_parent;
1226 attrib.override_redirect = True;
1227 if (!dummy_parent)
1229 dummy_parent = XCreateWindow( gdi_display, root_window, -1, -1, 1, 1, 0, screen_depth,
1230 InputOutput, visual, CWOverrideRedirect, &attrib );
1231 XMapWindow( gdi_display, dummy_parent );
1233 gl->colormap = XCreateColormap(gdi_display, dummy_parent, gl->visual->visual,
1234 (gl->visual->class == PseudoColor ||
1235 gl->visual->class == GrayScale ||
1236 gl->visual->class == DirectColor) ?
1237 AllocAll : AllocNone);
1238 attrib.colormap = gl->colormap;
1239 XInstallColormap(gdi_display, attrib.colormap);
1241 gl->type = DC_GL_CHILD_WIN;
1242 gl->drawable = XCreateWindow( gdi_display, dummy_parent, 0, 0,
1243 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top,
1244 0, gl->visual->depth, InputOutput, gl->visual->visual,
1245 CWColormap | CWOverrideRedirect, &attrib );
1246 if (gl->drawable)
1248 pXCompositeRedirectWindow(gdi_display, gl->drawable, CompositeRedirectManual);
1249 XMapWindow(gdi_display, gl->drawable);
1251 else XFreeColormap( gdi_display, gl->colormap );
1253 #endif
1254 else
1256 WARN("XComposite is not available, using GLXPixmap hack\n");
1258 gl->type = DC_GL_PIXMAP_WIN;
1259 gl->pixmap = XCreatePixmap( gdi_display, root_window,
1260 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top,
1261 gl->visual->depth );
1262 if (gl->pixmap)
1264 gl->drawable = pglXCreateGLXPixmap( gdi_display, gl->visual, gl->pixmap );
1265 if (!gl->drawable) XFreePixmap( gdi_display, gl->pixmap );
1269 if (!gl->drawable)
1271 XFree( gl->visual );
1272 HeapFree( GetProcessHeap(), 0, gl );
1273 return FALSE;
1276 TRACE("Created GL drawable 0x%lx, using FBConfigID 0x%lx\n", gl->drawable, fbconfig_id);
1278 XFlush( gdi_display );
1280 EnterCriticalSection( &context_section );
1281 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&prev ))
1282 free_gl_drawable( prev );
1283 XSaveContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char *)gl );
1284 LeaveCriticalSection( &context_section );
1286 /* force DCE invalidation */
1287 SetWindowPos( hwnd, 0, 0, 0, 0, 0,
1288 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE |
1289 SWP_NOREDRAW | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_STATECHANGED);
1290 return TRUE;
1293 /***********************************************************************
1294 * sync_gl_drawable
1296 void sync_gl_drawable( HWND hwnd, const RECT *visible_rect, const RECT *client_rect )
1298 struct gl_drawable *gl;
1299 Drawable glxp;
1300 Pixmap pix;
1301 int mask = 0;
1302 XWindowChanges changes;
1304 changes.x = client_rect->left - visible_rect->left;
1305 changes.y = client_rect->top - visible_rect->top;
1306 changes.width = min( max( 1, client_rect->right - client_rect->left ), 65535 );
1307 changes.height = min( max( 1, client_rect->bottom - client_rect->top ), 65535 );
1309 EnterCriticalSection( &context_section );
1311 if (XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl )) goto done;
1313 if (changes.width != gl->rect.right - gl->rect.left) mask |= CWWidth;
1314 if (changes.height != gl->rect.bottom - gl->rect.top) mask |= CWHeight;
1316 TRACE( "setting drawable %lx pos %d,%d,%dx%d\n",
1317 gl->drawable, changes.x, changes.y, changes.width, changes.height );
1319 switch (gl->type)
1321 case DC_GL_WINDOW:
1322 if (changes.x != gl->rect.left) mask |= CWX;
1323 if (changes.y != gl->rect.top) mask |= CWY;
1324 /* fallthrough */
1325 case DC_GL_CHILD_WIN:
1326 if (mask) XConfigureWindow( gdi_display, gl->drawable, mask, &changes );
1327 break;
1328 case DC_GL_PIXMAP_WIN:
1329 if (!mask) break;
1330 pix = XCreatePixmap(gdi_display, root_window, changes.width, changes.height, gl->visual->depth);
1331 if (!pix) goto done;
1332 glxp = pglXCreateGLXPixmap(gdi_display, gl->visual, pix);
1333 if (!glxp)
1335 XFreePixmap(gdi_display, pix);
1336 goto done;
1338 mark_drawable_dirty(gl->drawable, glxp);
1339 XFlush( gdi_display );
1341 XFreePixmap(gdi_display, gl->pixmap);
1342 pglXDestroyGLXPixmap(gdi_display, gl->drawable);
1343 TRACE( "Recreated GL drawable %lx to replace %lx\n", glxp, gl->drawable );
1345 gl->pixmap = pix;
1346 gl->drawable = glxp;
1347 break;
1348 default:
1349 break;
1351 SetRect( &gl->rect, changes.x, changes.y, changes.x + changes.width, changes.y + changes.height );
1352 done:
1353 LeaveCriticalSection( &context_section );
1356 /***********************************************************************
1357 * destroy_gl_drawable
1359 void destroy_gl_drawable( HWND hwnd )
1361 struct gl_drawable *gl;
1363 EnterCriticalSection( &context_section );
1364 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl ))
1366 XDeleteContext( gdi_display, (XID)hwnd, gl_hwnd_context );
1367 free_gl_drawable( gl );
1369 LeaveCriticalSection( &context_section );
1374 * glxdrv_DescribePixelFormat
1376 * Get the pixel-format descriptor associated to the given id
1378 static int glxdrv_wglDescribePixelFormat( HDC hdc, int iPixelFormat,
1379 UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd)
1381 /*XVisualInfo *vis;*/
1382 int value;
1383 int rb,gb,bb,ab;
1384 const struct wgl_pixel_format *fmt;
1386 if (!has_opengl()) return 0;
1388 TRACE("(%p,%d,%d,%p)\n", hdc, iPixelFormat, nBytes, ppfd);
1390 if (!ppfd) return nb_onscreen_formats;
1392 /* Look for the iPixelFormat in our list of supported formats. If it is supported we get the index in the FBConfig table and the number of supported formats back */
1393 fmt = get_pixel_format(gdi_display, iPixelFormat, FALSE /* Offscreen */);
1394 if (!fmt) {
1395 WARN("unexpected format %d\n", iPixelFormat);
1396 return 0;
1399 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1400 ERR("Wrong structure size !\n");
1401 /* Should set error */
1402 return 0;
1405 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1406 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1407 ppfd->nVersion = 1;
1409 /* These flags are always the same... */
1410 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1411 /* Now the flags extracted from the Visual */
1413 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1414 if(value & GLX_WINDOW_BIT)
1415 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1417 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1418 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1419 * Radeon 9000 indicated that all bitmap formats have PFD_SUPPORT_GDI. Except for 2 formats on the Radeon 9000 none of the hw accelerated formats
1420 * offered the GDI bit either. */
1421 ppfd->dwFlags |= fmt->dwFlags & (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI);
1423 /* PFD_GENERIC_FORMAT - gdi software rendering
1424 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1425 * none set - full hardware accelerated by a ICD
1427 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1428 ppfd->dwFlags |= fmt->dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED);
1430 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1431 if (value) {
1432 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1433 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1435 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1437 /* Pixel type */
1438 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1439 if (value & GLX_RGBA_BIT)
1440 ppfd->iPixelType = PFD_TYPE_RGBA;
1441 else
1442 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1444 /* Color bits */
1445 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1446 ppfd->cColorBits = value;
1448 /* Red, green, blue and alpha bits / shifts */
1449 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1450 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1451 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1452 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1453 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1455 ppfd->cRedBits = rb;
1456 ppfd->cRedShift = gb + bb + ab;
1457 ppfd->cBlueBits = bb;
1458 ppfd->cBlueShift = ab;
1459 ppfd->cGreenBits = gb;
1460 ppfd->cGreenShift = bb + ab;
1461 ppfd->cAlphaBits = ab;
1462 ppfd->cAlphaShift = 0;
1463 } else {
1464 ppfd->cRedBits = 0;
1465 ppfd->cRedShift = 0;
1466 ppfd->cBlueBits = 0;
1467 ppfd->cBlueShift = 0;
1468 ppfd->cGreenBits = 0;
1469 ppfd->cGreenShift = 0;
1470 ppfd->cAlphaBits = 0;
1471 ppfd->cAlphaShift = 0;
1474 /* Accum RGBA bits */
1475 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1476 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1477 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1478 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1480 ppfd->cAccumBits = rb+gb+bb+ab;
1481 ppfd->cAccumRedBits = rb;
1482 ppfd->cAccumGreenBits = gb;
1483 ppfd->cAccumBlueBits = bb;
1484 ppfd->cAccumAlphaBits = ab;
1486 /* Aux bits */
1487 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1488 ppfd->cAuxBuffers = value;
1490 /* Depth bits */
1491 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1492 ppfd->cDepthBits = value;
1494 /* stencil bits */
1495 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1496 ppfd->cStencilBits = value;
1498 ppfd->iLayerType = PFD_MAIN_PLANE;
1500 if (TRACE_ON(wgl)) {
1501 dump_PIXELFORMATDESCRIPTOR(ppfd);
1504 return nb_onscreen_formats;
1507 /***********************************************************************
1508 * glxdrv_wglGetPixelFormat
1510 static int glxdrv_wglGetPixelFormat( HDC hdc )
1512 HWND hwnd = WindowFromDC( hdc );
1513 struct gl_drawable *gl;
1514 int ret = 0;
1516 EnterCriticalSection( &context_section );
1517 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl ) ||
1518 !XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl ))
1519 ret = gl->format - pixel_formats + 1;
1520 LeaveCriticalSection( &context_section );
1522 /* Offscreen formats can't be used with traditional WGL calls.
1523 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1524 if (ret && !is_onscreen_pixel_format( ret )) ret = 1;
1526 TRACE( "%p -> %d\n", hdc, ret );
1527 return ret;
1530 /***********************************************************************
1531 * glxdrv_wglSetPixelFormat
1533 static BOOL glxdrv_wglSetPixelFormat( HDC hdc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd )
1535 const struct wgl_pixel_format *fmt;
1536 int value, prev = 0;
1537 struct gl_drawable *gl;
1538 HWND hwnd = WindowFromDC( hdc );
1540 TRACE("(%p,%d,%p)\n", hdc, iPixelFormat, ppfd);
1542 if (!hwnd || hwnd == GetDesktopWindow())
1544 WARN( "not a proper window DC %p/%p\n", hdc, hwnd );
1545 return FALSE;
1548 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1549 fmt = get_pixel_format(gdi_display, iPixelFormat, FALSE /* Offscreen */);
1550 if(!fmt) {
1551 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1552 return FALSE;
1555 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1556 if (!(value & GLX_WINDOW_BIT))
1558 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1559 return FALSE;
1562 EnterCriticalSection( &context_section );
1563 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl ))
1564 prev = gl->format - pixel_formats + 1;
1565 LeaveCriticalSection( &context_section );
1567 if (prev) return prev == iPixelFormat; /* cannot change it if already set */
1569 if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, fmt->fmt_id, 0)) {
1570 ERR("Couldn't set format of the window, returning failure\n");
1571 return FALSE;
1573 /* physDev->current_pf will be set by the DCE update */
1575 if (TRACE_ON(wgl)) {
1576 int gl_test = 0;
1578 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1579 if (gl_test) {
1580 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1581 } else {
1582 TRACE(" FBConfig have :\n");
1583 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1584 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1585 TRACE(" - VISUAL_ID 0x%x\n", value);
1586 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1587 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1590 return TRUE;
1593 /***********************************************************************
1594 * glxdrv_wglCopyContext
1596 static BOOL glxdrv_wglCopyContext(struct wgl_context *src, struct wgl_context *dst, UINT mask)
1598 TRACE("%p -> %p mask %#x\n", src, dst, mask);
1600 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1602 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1603 return TRUE;
1606 /***********************************************************************
1607 * glxdrv_wglCreateContext
1609 static struct wgl_context *glxdrv_wglCreateContext( HDC hdc )
1611 struct wgl_context *ret = NULL;
1612 struct gl_drawable *gl;
1613 HWND hwnd = WindowFromDC( hdc );
1615 EnterCriticalSection( &context_section );
1617 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl ) ||
1618 !XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl ))
1620 if (!(ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret)))) goto done;
1621 ret->hdc = hdc;
1622 ret->fmt = gl->format;
1623 ret->vis = pglXGetVisualFromFBConfig(gdi_display, gl->format->fbconfig);
1624 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1625 list_add_head( &context_list, &ret->entry );
1627 else SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1629 done:
1630 LeaveCriticalSection( &context_section );
1631 TRACE( "%p -> %p\n", hdc, ret );
1632 return ret;
1635 /***********************************************************************
1636 * glxdrv_wglDeleteContext
1638 static void glxdrv_wglDeleteContext(struct wgl_context *ctx)
1640 TRACE("(%p)\n", ctx);
1642 EnterCriticalSection( &context_section );
1643 list_remove( &ctx->entry );
1644 LeaveCriticalSection( &context_section );
1646 if (ctx->ctx) pglXDestroyContext( gdi_display, ctx->ctx );
1647 if (ctx->vis) XFree( ctx->vis );
1648 HeapFree( GetProcessHeap(), 0, ctx );
1651 /***********************************************************************
1652 * glxdrv_wglGetProcAddress
1654 static PROC glxdrv_wglGetProcAddress(LPCSTR lpszProc)
1656 if (!strncmp(lpszProc, "wgl", 3)) return NULL;
1657 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1660 /***********************************************************************
1661 * glxdrv_wglMakeCurrent
1663 static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx)
1665 BOOL ret = FALSE;
1666 HWND hwnd;
1667 struct gl_drawable *gl;
1669 TRACE("(%p,%p)\n", hdc, ctx);
1671 if (!ctx)
1673 pglXMakeCurrent(gdi_display, None, NULL);
1674 NtCurrentTeb()->glContext = NULL;
1675 return TRUE;
1678 hwnd = WindowFromDC( hdc );
1679 EnterCriticalSection( &context_section );
1681 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl ) ||
1682 !XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl ))
1684 if (ctx->fmt != gl->format)
1686 WARN( "mismatched pixel format hdc %p %p ctx %p %p\n", hdc, gl->format, ctx, ctx->fmt );
1687 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1688 goto done;
1691 if (TRACE_ON(wgl)) {
1692 describeContext(ctx);
1693 TRACE("hdc %p drawable %lx fmt %p ctx %p\n", hdc, gl->drawable, gl->format, ctx->ctx );
1696 ret = pglXMakeCurrent(gdi_display, gl->drawable, ctx->ctx);
1697 if (ret)
1699 NtCurrentTeb()->glContext = ctx;
1700 ctx->has_been_current = TRUE;
1701 ctx->hdc = hdc;
1702 ctx->drawables[0] = gl->drawable;
1703 ctx->drawables[1] = gl->drawable;
1704 ctx->refresh_drawables = FALSE;
1705 goto done;
1708 SetLastError( ERROR_INVALID_HANDLE );
1710 done:
1711 LeaveCriticalSection( &context_section );
1712 TRACE( "%p,%p returning %d\n", hdc, ctx, ret );
1713 return ret;
1716 /***********************************************************************
1717 * X11DRV_wglMakeContextCurrentARB
1719 static BOOL X11DRV_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *ctx )
1721 BOOL ret = FALSE;
1722 HWND draw_hwnd, read_hwnd;
1723 struct gl_drawable *draw_gl, *read_gl;
1725 TRACE("(%p,%p,%p)\n", draw_hdc, read_hdc, ctx);
1727 if (!ctx)
1729 pglXMakeCurrent(gdi_display, None, NULL);
1730 NtCurrentTeb()->glContext = NULL;
1731 return TRUE;
1734 if (!pglXMakeContextCurrent) return FALSE;
1736 draw_hwnd = WindowFromDC( draw_hdc );
1737 read_hwnd = WindowFromDC( read_hdc );
1738 EnterCriticalSection( &context_section );
1740 if (!XFindContext( gdi_display, (XID)draw_hwnd, gl_hwnd_context, (char **)&draw_gl ) ||
1741 !XFindContext( gdi_display, (XID)draw_hdc, gl_pbuffer_context, (char **)&draw_gl ))
1743 if (XFindContext( gdi_display, (XID)read_hwnd, gl_hwnd_context, (char **)&read_gl ) &&
1744 XFindContext( gdi_display, (XID)read_hdc, gl_pbuffer_context, (char **)&read_gl ))
1745 read_gl = NULL;
1747 ret = pglXMakeContextCurrent(gdi_display, draw_gl->drawable,
1748 read_gl ? read_gl->drawable : 0, ctx->ctx);
1749 if (ret)
1751 ctx->has_been_current = TRUE;
1752 ctx->hdc = draw_hdc;
1753 ctx->drawables[0] = draw_gl->drawable;
1754 ctx->drawables[1] = read_gl ? read_gl->drawable : 0;
1755 ctx->refresh_drawables = FALSE;
1756 NtCurrentTeb()->glContext = ctx;
1757 goto done;
1760 SetLastError( ERROR_INVALID_HANDLE );
1761 done:
1762 LeaveCriticalSection( &context_section );
1763 TRACE( "%p,%p,%p returning %d\n", draw_hdc, read_hdc, ctx, ret );
1764 return ret;
1767 /***********************************************************************
1768 * glxdrv_wglShareLists
1770 static BOOL glxdrv_wglShareLists(struct wgl_context *org, struct wgl_context *dest)
1772 TRACE("(%p, %p)\n", org, dest);
1774 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1775 * at context creation time but in case of WGL it is done using wglShareLists.
1776 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1777 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1778 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1779 * so there delaying context creation doesn't work.
1781 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1782 * and when a program requests sharing we recreate the destination context if it hasn't been made
1783 * current or when it hasn't shared display lists before.
1786 if((org->has_been_current && dest->has_been_current) || dest->has_been_current)
1788 ERR("Could not share display lists, one of the contexts has been current already !\n");
1789 return FALSE;
1791 else if(dest->sharing)
1793 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1794 return FALSE;
1796 else
1798 describeContext(org);
1799 describeContext(dest);
1801 /* Re-create the GLX context and share display lists */
1802 pglXDestroyContext(gdi_display, dest->ctx);
1803 dest->ctx = create_glxcontext(gdi_display, dest, org->ctx);
1804 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1806 org->sharing = TRUE;
1807 dest->sharing = TRUE;
1808 return TRUE;
1810 return FALSE;
1813 static void flush_gl_drawable( struct glx_physdev *physdev )
1815 RECT rect;
1816 int w = physdev->x11dev->dc_rect.right - physdev->x11dev->dc_rect.left;
1817 int h = physdev->x11dev->dc_rect.bottom - physdev->x11dev->dc_rect.top;
1818 Drawable src = physdev->drawable;
1820 if (w <= 0 || h <= 0) return;
1822 switch (physdev->type)
1824 case DC_GL_PIXMAP_WIN:
1825 src = physdev->pixmap;
1826 /* fall through */
1827 case DC_GL_CHILD_WIN:
1828 /* The GL drawable may be lagged behind if we don't flush first, so
1829 * flush the display make sure we copy up-to-date data */
1830 XFlush(gdi_display);
1831 XSetFunction(gdi_display, physdev->x11dev->gc, GXcopy);
1832 XCopyArea(gdi_display, src, physdev->x11dev->drawable, physdev->x11dev->gc, 0, 0, w, h,
1833 physdev->x11dev->dc_rect.left, physdev->x11dev->dc_rect.top);
1834 SetRect( &rect, 0, 0, w, h );
1835 add_device_bounds( physdev->x11dev, &rect );
1836 default:
1837 break;
1842 static void wglFinish(void)
1844 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1845 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
1847 sync_context(ctx);
1848 pglFinish();
1849 ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
1852 static void wglFlush(void)
1854 struct wgl_context *ctx = NtCurrentTeb()->glContext;
1855 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
1857 sync_context(ctx);
1858 pglFlush();
1859 ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
1862 /***********************************************************************
1863 * X11DRV_wglCreateContextAttribsARB
1865 static struct wgl_context *X11DRV_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *hShareContext,
1866 const int* attribList )
1868 struct wgl_context *ret = NULL;
1869 struct gl_drawable *gl;
1870 HWND hwnd = WindowFromDC( hdc );
1872 TRACE("(%p %p %p)\n", hdc, hShareContext, attribList);
1874 EnterCriticalSection( &context_section );
1876 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl ) ||
1877 !XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl ))
1879 if (!(ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret)))) goto done;
1880 ret->hdc = hdc;
1881 ret->fmt = gl->format;
1882 ret->vis = NULL; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
1883 ret->gl3_context = TRUE;
1884 ret->numAttribs = 0;
1885 if (attribList)
1887 int *pContextAttribList = &ret->attribList[0];
1888 /* attribList consists of pairs {token, value] terminated with 0 */
1889 while(attribList[0] != 0)
1891 TRACE("%#x %#x\n", attribList[0], attribList[1]);
1892 switch(attribList[0])
1894 case WGL_CONTEXT_MAJOR_VERSION_ARB:
1895 pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
1896 pContextAttribList[1] = attribList[1];
1897 break;
1898 case WGL_CONTEXT_MINOR_VERSION_ARB:
1899 pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB;
1900 pContextAttribList[1] = attribList[1];
1901 break;
1902 case WGL_CONTEXT_LAYER_PLANE_ARB:
1903 break;
1904 case WGL_CONTEXT_FLAGS_ARB:
1905 pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB;
1906 pContextAttribList[1] = attribList[1];
1907 break;
1908 case WGL_CONTEXT_PROFILE_MASK_ARB:
1909 pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
1910 pContextAttribList[1] = attribList[1];
1911 break;
1912 default:
1913 ERR("Unhandled attribList pair: %#x %#x\n", attribList[0], attribList[1]);
1915 ret->numAttribs++;
1916 attribList += 2;
1917 pContextAttribList += 2;
1921 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
1922 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1923 XSync(gdi_display, False);
1924 if (!X11DRV_check_error() && ret->ctx)
1926 list_add_head( &context_list, &ret->entry );
1927 goto done;
1929 /* In the future we should convert the GLX error to a win32 one here if needed */
1930 ERR("Context creation failed\n");
1931 HeapFree( GetProcessHeap(), 0, ret );
1932 ret = NULL;
1934 else SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1936 done:
1937 LeaveCriticalSection( &context_section );
1938 TRACE( "%p -> %p\n", hdc, ret );
1939 return ret;
1943 * X11DRV_wglGetExtensionsStringARB
1945 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
1947 static const GLubyte *X11DRV_wglGetExtensionsStringARB(HDC hdc)
1949 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
1950 return (const GLubyte *)WineGLInfo.wglExtensions;
1954 * X11DRV_wglCreatePbufferARB
1956 * WGL_ARB_pbuffer: wglCreatePbufferARB
1958 static struct wgl_pbuffer *X11DRV_wglCreatePbufferARB( HDC hdc, int iPixelFormat, int iWidth, int iHeight,
1959 const int *piAttribList )
1961 struct wgl_pbuffer* object = NULL;
1962 const struct wgl_pixel_format *fmt = NULL;
1963 int attribs[256];
1964 int nAttribs = 0;
1966 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
1968 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
1969 fmt = get_pixel_format(gdi_display, iPixelFormat, TRUE /* Offscreen */);
1970 if(!fmt) {
1971 ERR("(%p): invalid pixel format %d\n", hdc, iPixelFormat);
1972 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1973 return NULL;
1976 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1977 if (NULL == object) {
1978 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
1979 return NULL;
1981 object->width = iWidth;
1982 object->height = iHeight;
1983 object->fmt = fmt;
1985 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
1986 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
1987 while (piAttribList && 0 != *piAttribList) {
1988 int attr_v;
1989 switch (*piAttribList) {
1990 case WGL_PBUFFER_LARGEST_ARB: {
1991 ++piAttribList;
1992 attr_v = *piAttribList;
1993 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
1994 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
1995 break;
1998 case WGL_TEXTURE_FORMAT_ARB: {
1999 ++piAttribList;
2000 attr_v = *piAttribList;
2001 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2002 if (WGL_NO_TEXTURE_ARB == attr_v) {
2003 object->use_render_texture = 0;
2004 } else {
2005 if (!use_render_texture_emulation) {
2006 SetLastError(ERROR_INVALID_DATA);
2007 goto create_failed;
2009 switch (attr_v) {
2010 case WGL_TEXTURE_RGB_ARB:
2011 object->use_render_texture = GL_RGB;
2012 object->texture_bpp = 3;
2013 object->texture_format = GL_RGB;
2014 object->texture_type = GL_UNSIGNED_BYTE;
2015 break;
2016 case WGL_TEXTURE_RGBA_ARB:
2017 object->use_render_texture = GL_RGBA;
2018 object->texture_bpp = 4;
2019 object->texture_format = GL_RGBA;
2020 object->texture_type = GL_UNSIGNED_BYTE;
2021 break;
2023 /* WGL_FLOAT_COMPONENTS_NV */
2024 case WGL_TEXTURE_FLOAT_R_NV:
2025 object->use_render_texture = GL_FLOAT_R_NV;
2026 object->texture_bpp = 4;
2027 object->texture_format = GL_RED;
2028 object->texture_type = GL_FLOAT;
2029 break;
2030 case WGL_TEXTURE_FLOAT_RG_NV:
2031 object->use_render_texture = GL_FLOAT_RG_NV;
2032 object->texture_bpp = 8;
2033 object->texture_format = GL_LUMINANCE_ALPHA;
2034 object->texture_type = GL_FLOAT;
2035 break;
2036 case WGL_TEXTURE_FLOAT_RGB_NV:
2037 object->use_render_texture = GL_FLOAT_RGB_NV;
2038 object->texture_bpp = 12;
2039 object->texture_format = GL_RGB;
2040 object->texture_type = GL_FLOAT;
2041 break;
2042 case WGL_TEXTURE_FLOAT_RGBA_NV:
2043 object->use_render_texture = GL_FLOAT_RGBA_NV;
2044 object->texture_bpp = 16;
2045 object->texture_format = GL_RGBA;
2046 object->texture_type = GL_FLOAT;
2047 break;
2048 default:
2049 ERR("Unknown texture format: %x\n", attr_v);
2050 SetLastError(ERROR_INVALID_DATA);
2051 goto create_failed;
2054 break;
2057 case WGL_TEXTURE_TARGET_ARB: {
2058 ++piAttribList;
2059 attr_v = *piAttribList;
2060 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2061 if (WGL_NO_TEXTURE_ARB == attr_v) {
2062 object->texture_target = 0;
2063 } else {
2064 if (!use_render_texture_emulation) {
2065 SetLastError(ERROR_INVALID_DATA);
2066 goto create_failed;
2068 switch (attr_v) {
2069 case WGL_TEXTURE_CUBE_MAP_ARB: {
2070 if (iWidth != iHeight) {
2071 SetLastError(ERROR_INVALID_DATA);
2072 goto create_failed;
2074 object->texture_target = GL_TEXTURE_CUBE_MAP;
2075 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2076 break;
2078 case WGL_TEXTURE_1D_ARB: {
2079 if (1 != iHeight) {
2080 SetLastError(ERROR_INVALID_DATA);
2081 goto create_failed;
2083 object->texture_target = GL_TEXTURE_1D;
2084 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2085 break;
2087 case WGL_TEXTURE_2D_ARB: {
2088 object->texture_target = GL_TEXTURE_2D;
2089 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2090 break;
2092 case WGL_TEXTURE_RECTANGLE_NV: {
2093 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2094 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2095 break;
2097 default:
2098 ERR("Unknown texture target: %x\n", attr_v);
2099 SetLastError(ERROR_INVALID_DATA);
2100 goto create_failed;
2103 break;
2106 case WGL_MIPMAP_TEXTURE_ARB: {
2107 ++piAttribList;
2108 attr_v = *piAttribList;
2109 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2110 if (!use_render_texture_emulation) {
2111 SetLastError(ERROR_INVALID_DATA);
2112 goto create_failed;
2114 break;
2117 ++piAttribList;
2120 PUSH1(attribs, None);
2121 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2122 TRACE("new Pbuffer drawable as %lx\n", object->drawable);
2123 if (!object->drawable) {
2124 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2125 goto create_failed; /* unexpected error */
2127 TRACE("->(%p)\n", object);
2128 return object;
2130 create_failed:
2131 HeapFree(GetProcessHeap(), 0, object);
2132 TRACE("->(FAILED)\n");
2133 return NULL;
2137 * X11DRV_wglDestroyPbufferARB
2139 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2141 static BOOL X11DRV_wglDestroyPbufferARB( struct wgl_pbuffer *object )
2143 TRACE("(%p)\n", object);
2145 pglXDestroyPbuffer(gdi_display, object->drawable);
2146 HeapFree(GetProcessHeap(), 0, object);
2147 return GL_TRUE;
2151 * X11DRV_wglGetPbufferDCARB
2153 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2155 static HDC X11DRV_wglGetPbufferDCARB( struct wgl_pbuffer *object )
2157 struct x11drv_escape_set_drawable escape;
2158 struct gl_drawable *gl, *prev;
2159 HDC hdc;
2161 hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
2162 if (!hdc) return 0;
2164 if (!(gl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*gl) )))
2166 DeleteDC( hdc );
2167 return 0;
2169 gl->type = DC_GL_PBUFFER;
2170 gl->drawable = object->drawable;
2171 gl->format = object->fmt;
2173 EnterCriticalSection( &context_section );
2174 if (!XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&prev ))
2175 free_gl_drawable( prev );
2176 XSaveContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char *)gl );
2177 LeaveCriticalSection( &context_section );
2179 escape.code = X11DRV_SET_DRAWABLE;
2180 escape.hwnd = 0;
2181 escape.drawable = object->drawable;
2182 escape.mode = IncludeInferiors;
2183 SetRect( &escape.dc_rect, 0, 0, object->width, object->height );
2184 escape.fbconfig_id = object->fmt->fmt_id;
2185 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2187 TRACE( "(%p)->(%p)\n", object, hdc );
2188 return hdc;
2192 * X11DRV_wglQueryPbufferARB
2194 * WGL_ARB_pbuffer: wglQueryPbufferARB
2196 static BOOL X11DRV_wglQueryPbufferARB( struct wgl_pbuffer *object, int iAttribute, int *piValue )
2198 TRACE("(%p, 0x%x, %p)\n", object, iAttribute, piValue);
2200 switch (iAttribute) {
2201 case WGL_PBUFFER_WIDTH_ARB:
2202 pglXQueryDrawable(gdi_display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2203 break;
2204 case WGL_PBUFFER_HEIGHT_ARB:
2205 pglXQueryDrawable(gdi_display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2206 break;
2208 case WGL_PBUFFER_LOST_ARB:
2209 /* GLX Pbuffers cannot be lost by default. We can support this by
2210 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2211 * to receive pixel buffer clobber events, however that may or may
2212 * not give any benefit */
2213 *piValue = GL_FALSE;
2214 break;
2216 case WGL_TEXTURE_FORMAT_ARB:
2217 if (!object->use_render_texture) {
2218 *piValue = WGL_NO_TEXTURE_ARB;
2219 } else {
2220 if (!use_render_texture_emulation) {
2221 SetLastError(ERROR_INVALID_HANDLE);
2222 return GL_FALSE;
2224 switch(object->use_render_texture) {
2225 case GL_RGB:
2226 *piValue = WGL_TEXTURE_RGB_ARB;
2227 break;
2228 case GL_RGBA:
2229 *piValue = WGL_TEXTURE_RGBA_ARB;
2230 break;
2231 /* WGL_FLOAT_COMPONENTS_NV */
2232 case GL_FLOAT_R_NV:
2233 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2234 break;
2235 case GL_FLOAT_RG_NV:
2236 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2237 break;
2238 case GL_FLOAT_RGB_NV:
2239 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2240 break;
2241 case GL_FLOAT_RGBA_NV:
2242 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2243 break;
2244 default:
2245 ERR("Unknown texture format: %x\n", object->use_render_texture);
2248 break;
2250 case WGL_TEXTURE_TARGET_ARB:
2251 if (!object->texture_target){
2252 *piValue = WGL_NO_TEXTURE_ARB;
2253 } else {
2254 if (!use_render_texture_emulation) {
2255 SetLastError(ERROR_INVALID_DATA);
2256 return GL_FALSE;
2258 switch (object->texture_target) {
2259 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2260 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2261 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2262 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2265 break;
2267 case WGL_MIPMAP_TEXTURE_ARB:
2268 *piValue = GL_FALSE; /** don't support that */
2269 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2270 break;
2272 default:
2273 FIXME("unexpected attribute %x\n", iAttribute);
2274 break;
2277 return GL_TRUE;
2281 * X11DRV_wglReleasePbufferDCARB
2283 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2285 static int X11DRV_wglReleasePbufferDCARB( struct wgl_pbuffer *object, HDC hdc )
2287 struct gl_drawable *gl;
2289 TRACE("(%p, %p)\n", object, hdc);
2291 EnterCriticalSection( &context_section );
2292 if (!XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl ))
2294 XDeleteContext( gdi_display, (XID)hdc, gl_pbuffer_context );
2295 free_gl_drawable( gl );
2297 LeaveCriticalSection( &context_section );
2299 return DeleteDC(hdc);
2303 * X11DRV_wglSetPbufferAttribARB
2305 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2307 static BOOL X11DRV_wglSetPbufferAttribARB( struct wgl_pbuffer *object, const int *piAttribList )
2309 GLboolean ret = GL_FALSE;
2311 WARN("(%p, %p): alpha-testing, report any problem\n", object, piAttribList);
2313 if (!object->use_render_texture) {
2314 SetLastError(ERROR_INVALID_HANDLE);
2315 return GL_FALSE;
2317 if (1 == use_render_texture_emulation) {
2318 return GL_TRUE;
2320 return ret;
2324 * X11DRV_wglChoosePixelFormatARB
2326 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2328 static BOOL X11DRV_wglChoosePixelFormatARB( HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList,
2329 UINT nMaxFormats, int *piFormats, UINT *nNumFormats )
2331 int attribs[256];
2332 int nAttribs = 0;
2333 GLXFBConfig* cfgs = NULL;
2334 int nCfgs = 0;
2335 int it;
2336 int fmt_id;
2337 int start, end;
2338 UINT pfmt_it = 0;
2339 int run;
2340 int i;
2341 DWORD dwFlags = 0;
2343 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2344 if (NULL != pfAttribFList) {
2345 FIXME("unused pfAttribFList\n");
2348 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2349 if (-1 == nAttribs) {
2350 WARN("Cannot convert WGL to GLX attributes\n");
2351 return GL_FALSE;
2353 PUSH1(attribs, None);
2355 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2356 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the pixel format. We don't query these attributes
2357 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on.
2359 for(i=0; piAttribIList[i] != 0; i+=2)
2361 switch(piAttribIList[i])
2363 case WGL_DRAW_TO_BITMAP_ARB:
2364 if(piAttribIList[i+1])
2365 dwFlags |= PFD_DRAW_TO_BITMAP;
2366 break;
2367 case WGL_ACCELERATION_ARB:
2368 switch(piAttribIList[i+1])
2370 case WGL_NO_ACCELERATION_ARB:
2371 dwFlags |= PFD_GENERIC_FORMAT;
2372 break;
2373 case WGL_GENERIC_ACCELERATION_ARB:
2374 dwFlags |= PFD_GENERIC_ACCELERATED;
2375 break;
2376 case WGL_FULL_ACCELERATION_ARB:
2377 /* Nothing to do */
2378 break;
2380 break;
2381 case WGL_SUPPORT_GDI_ARB:
2382 if(piAttribIList[i+1])
2383 dwFlags |= PFD_SUPPORT_GDI;
2384 break;
2388 /* Search for FB configurations matching the requirements in attribs */
2389 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2390 if (NULL == cfgs) {
2391 WARN("Compatible Pixel Format not found\n");
2392 return GL_FALSE;
2395 /* Loop through all matching formats and check if they are suitable.
2396 * Note that this function should at max return nMaxFormats different formats */
2397 for(run=0; run < 2; run++)
2399 for (it = 0; it < nCfgs && pfmt_it < nMaxFormats; ++it)
2401 if (pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id))
2403 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2404 continue;
2407 /* During the first run we only want onscreen formats and during the second only offscreen */
2408 start = run == 1 ? nb_onscreen_formats : 0;
2409 end = run == 1 ? nb_pixel_formats : nb_onscreen_formats;
2411 for (i = start; i < end; i++)
2413 if (pixel_formats[i].fmt_id == fmt_id && (pixel_formats[i].dwFlags & dwFlags) == dwFlags)
2415 piFormats[pfmt_it++] = i + 1;
2416 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n",
2417 it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2418 break;
2424 *nNumFormats = pfmt_it;
2425 /** free list */
2426 XFree(cfgs);
2427 return GL_TRUE;
2431 * X11DRV_wglGetPixelFormatAttribivARB
2433 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2435 static BOOL X11DRV_wglGetPixelFormatAttribivARB( HDC hdc, int iPixelFormat, int iLayerPlane,
2436 UINT nAttributes, const int *piAttributes, int *piValues )
2438 UINT i;
2439 const struct wgl_pixel_format *fmt = NULL;
2440 int hTest;
2441 int tmp;
2442 int curGLXAttr = 0;
2444 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2446 if (0 < iLayerPlane) {
2447 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2448 return GL_FALSE;
2451 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2452 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2453 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2454 fmt = get_pixel_format(gdi_display, iPixelFormat, TRUE /* Offscreen */);
2455 if(!fmt) {
2456 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2459 for (i = 0; i < nAttributes; ++i) {
2460 const int curWGLAttr = piAttributes[i];
2461 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2463 switch (curWGLAttr) {
2464 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2465 piValues[i] = nb_pixel_formats;
2466 continue;
2468 case WGL_SUPPORT_OPENGL_ARB:
2469 piValues[i] = GL_TRUE;
2470 continue;
2472 case WGL_ACCELERATION_ARB:
2473 curGLXAttr = GLX_CONFIG_CAVEAT;
2474 if (!fmt) goto pix_error;
2475 if(fmt->dwFlags & PFD_GENERIC_FORMAT)
2476 piValues[i] = WGL_NO_ACCELERATION_ARB;
2477 else if(fmt->dwFlags & PFD_GENERIC_ACCELERATED)
2478 piValues[i] = WGL_GENERIC_ACCELERATION_ARB;
2479 else
2480 piValues[i] = WGL_FULL_ACCELERATION_ARB;
2481 continue;
2483 case WGL_TRANSPARENT_ARB:
2484 curGLXAttr = GLX_TRANSPARENT_TYPE;
2485 if (!fmt) goto pix_error;
2486 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2487 if (hTest) goto get_error;
2488 piValues[i] = GL_FALSE;
2489 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2490 continue;
2492 case WGL_PIXEL_TYPE_ARB:
2493 curGLXAttr = GLX_RENDER_TYPE;
2494 if (!fmt) goto pix_error;
2495 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2496 if (hTest) goto get_error;
2497 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2498 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2499 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2500 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2501 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2502 else if (tmp & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) { piValues[i] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT; }
2503 else {
2504 ERR("unexpected RenderType(%x)\n", tmp);
2505 piValues[i] = WGL_TYPE_RGBA_ARB;
2507 continue;
2509 case WGL_COLOR_BITS_ARB:
2510 curGLXAttr = GLX_BUFFER_SIZE;
2511 break;
2513 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2514 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2515 if (!use_render_texture_emulation) {
2516 piValues[i] = GL_FALSE;
2517 continue;
2519 curGLXAttr = GLX_RENDER_TYPE;
2520 if (!fmt) goto pix_error;
2521 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2522 if (hTest) goto get_error;
2523 if (GLX_COLOR_INDEX_BIT == tmp) {
2524 piValues[i] = GL_FALSE;
2525 continue;
2527 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2528 if (hTest) goto get_error;
2529 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2530 continue;
2532 case WGL_BLUE_BITS_ARB:
2533 curGLXAttr = GLX_BLUE_SIZE;
2534 break;
2535 case WGL_RED_BITS_ARB:
2536 curGLXAttr = GLX_RED_SIZE;
2537 break;
2538 case WGL_GREEN_BITS_ARB:
2539 curGLXAttr = GLX_GREEN_SIZE;
2540 break;
2541 case WGL_ALPHA_BITS_ARB:
2542 curGLXAttr = GLX_ALPHA_SIZE;
2543 break;
2544 case WGL_DEPTH_BITS_ARB:
2545 curGLXAttr = GLX_DEPTH_SIZE;
2546 break;
2547 case WGL_STENCIL_BITS_ARB:
2548 curGLXAttr = GLX_STENCIL_SIZE;
2549 break;
2550 case WGL_DOUBLE_BUFFER_ARB:
2551 curGLXAttr = GLX_DOUBLEBUFFER;
2552 break;
2553 case WGL_STEREO_ARB:
2554 curGLXAttr = GLX_STEREO;
2555 break;
2556 case WGL_AUX_BUFFERS_ARB:
2557 curGLXAttr = GLX_AUX_BUFFERS;
2558 break;
2560 case WGL_SUPPORT_GDI_ARB:
2561 if (!fmt) goto pix_error;
2562 piValues[i] = (fmt->dwFlags & PFD_SUPPORT_GDI) != 0;
2563 continue;
2565 case WGL_DRAW_TO_BITMAP_ARB:
2566 if (!fmt) goto pix_error;
2567 piValues[i] = (fmt->dwFlags & PFD_DRAW_TO_BITMAP) != 0;
2568 continue;
2570 case WGL_DRAW_TO_WINDOW_ARB:
2571 case WGL_DRAW_TO_PBUFFER_ARB:
2572 if (!fmt) goto pix_error;
2573 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2574 if (hTest) goto get_error;
2575 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2576 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2577 piValues[i] = GL_TRUE;
2578 else
2579 piValues[i] = GL_FALSE;
2580 continue;
2582 case WGL_SWAP_METHOD_ARB:
2583 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
2584 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
2585 * point only ATI offers this.
2587 piValues[i] = WGL_SWAP_EXCHANGE_ARB;
2588 break;
2590 case WGL_PBUFFER_LARGEST_ARB:
2591 curGLXAttr = GLX_LARGEST_PBUFFER;
2592 break;
2594 case WGL_SAMPLE_BUFFERS_ARB:
2595 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2596 break;
2598 case WGL_SAMPLES_ARB:
2599 curGLXAttr = GLX_SAMPLES_ARB;
2600 break;
2602 case WGL_FLOAT_COMPONENTS_NV:
2603 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2604 break;
2606 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
2607 curGLXAttr = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT;
2608 break;
2610 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
2611 curGLXAttr = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
2612 break;
2614 case WGL_ACCUM_RED_BITS_ARB:
2615 curGLXAttr = GLX_ACCUM_RED_SIZE;
2616 break;
2617 case WGL_ACCUM_GREEN_BITS_ARB:
2618 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2619 break;
2620 case WGL_ACCUM_BLUE_BITS_ARB:
2621 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2622 break;
2623 case WGL_ACCUM_ALPHA_BITS_ARB:
2624 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2625 break;
2626 case WGL_ACCUM_BITS_ARB:
2627 if (!fmt) goto pix_error;
2628 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2629 if (hTest) goto get_error;
2630 piValues[i] = tmp;
2631 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2632 if (hTest) goto get_error;
2633 piValues[i] += tmp;
2634 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2635 if (hTest) goto get_error;
2636 piValues[i] += tmp;
2637 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2638 if (hTest) goto get_error;
2639 piValues[i] += tmp;
2640 continue;
2642 default:
2643 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2646 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2647 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2648 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2650 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2651 * and check which options can work using iPixelFormat=0 and which not.
2652 * A problem would be that this function is an extension. This would
2653 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2655 if (0 != curGLXAttr && iPixelFormat != 0) {
2656 if (!fmt) goto pix_error;
2657 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2658 if (hTest) goto get_error;
2659 curGLXAttr = 0;
2660 } else {
2661 piValues[i] = GL_FALSE;
2664 return GL_TRUE;
2666 get_error:
2667 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2668 return GL_FALSE;
2670 pix_error:
2671 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nb_pixel_formats);
2672 return GL_FALSE;
2676 * X11DRV_wglGetPixelFormatAttribfvARB
2678 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2680 static BOOL X11DRV_wglGetPixelFormatAttribfvARB( HDC hdc, int iPixelFormat, int iLayerPlane,
2681 UINT nAttributes, const int *piAttributes, FLOAT *pfValues )
2683 int *attr;
2684 int ret;
2685 UINT i;
2687 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2689 /* Allocate a temporary array to store integer values */
2690 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2691 if (!attr) {
2692 ERR("couldn't allocate %d array\n", nAttributes);
2693 return GL_FALSE;
2696 /* Piggy-back on wglGetPixelFormatAttribivARB */
2697 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2698 if (ret) {
2699 /* Convert integer values to float. Should also check for attributes
2700 that can give decimal values here */
2701 for (i=0; i<nAttributes;i++) {
2702 pfValues[i] = attr[i];
2706 HeapFree(GetProcessHeap(), 0, attr);
2707 return ret;
2711 * X11DRV_wglBindTexImageARB
2713 * WGL_ARB_render_texture: wglBindTexImageARB
2715 static BOOL X11DRV_wglBindTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2717 GLboolean ret = GL_FALSE;
2719 TRACE("(%p, %d)\n", object, iBuffer);
2721 if (!object->use_render_texture) {
2722 SetLastError(ERROR_INVALID_HANDLE);
2723 return GL_FALSE;
2726 if (1 == use_render_texture_emulation) {
2727 static int init = 0;
2728 int prev_binded_texture = 0;
2729 GLXContext prev_context;
2730 Drawable prev_drawable;
2731 GLXContext tmp_context;
2733 prev_context = pglXGetCurrentContext();
2734 prev_drawable = pglXGetCurrentDrawable();
2736 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2737 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2738 isn't ideal performance wise but I wasn't able to get other ways working.
2740 if(!init) {
2741 init = 1; /* Only show the FIXME once for performance reasons */
2742 FIXME("partial stub!\n");
2745 TRACE("drawable=%lx, context=%p\n", object->drawable, prev_context);
2746 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2748 opengl_funcs.gl.p_glGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2750 /* Switch to our pbuffer */
2751 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
2753 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2754 * After that upload the pbuffer texture data. */
2755 opengl_funcs.gl.p_glBindTexture(object->texture_target, prev_binded_texture);
2756 opengl_funcs.gl.p_glCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2758 /* Switch back to the original drawable and upload the pbuffer-texture */
2759 pglXMakeCurrent(gdi_display, prev_drawable, prev_context);
2760 pglXDestroyContext(gdi_display, tmp_context);
2761 return GL_TRUE;
2764 return ret;
2768 * X11DRV_wglReleaseTexImageARB
2770 * WGL_ARB_render_texture: wglReleaseTexImageARB
2772 static BOOL X11DRV_wglReleaseTexImageARB( struct wgl_pbuffer *object, int iBuffer )
2774 GLboolean ret = GL_FALSE;
2776 TRACE("(%p, %d)\n", object, iBuffer);
2778 if (!object->use_render_texture) {
2779 SetLastError(ERROR_INVALID_HANDLE);
2780 return GL_FALSE;
2782 if (1 == use_render_texture_emulation) {
2783 return GL_TRUE;
2785 return ret;
2789 * X11DRV_wglGetExtensionsStringEXT
2791 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2793 static const GLubyte *X11DRV_wglGetExtensionsStringEXT(void)
2795 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2796 return (const GLubyte *)WineGLInfo.wglExtensions;
2800 * X11DRV_wglGetSwapIntervalEXT
2802 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2804 static int X11DRV_wglGetSwapIntervalEXT(void)
2806 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
2807 * interval, so the swap interval has to be tracked. */
2808 TRACE("()\n");
2809 return swap_interval;
2813 * X11DRV_wglSwapIntervalEXT
2815 * WGL_EXT_swap_control: wglSwapIntervalEXT
2817 static BOOL X11DRV_wglSwapIntervalEXT(int interval)
2819 BOOL ret = TRUE;
2821 TRACE("(%d)\n", interval);
2823 if (interval < 0)
2825 SetLastError(ERROR_INVALID_DATA);
2826 return FALSE;
2828 else if (!has_swap_control && interval == 0)
2830 /* wglSwapIntervalEXT considers an interval value of zero to mean that
2831 * vsync should be disabled, but glXSwapIntervalSGI considers such a
2832 * value to be an error. Just silently ignore the request for now. */
2833 WARN("Request to disable vertical sync is not handled\n");
2834 swap_interval = 0;
2836 else
2838 if (pglXSwapIntervalSGI)
2839 ret = !pglXSwapIntervalSGI(interval);
2840 else
2841 WARN("GLX_SGI_swap_control extension is not available\n");
2843 if (ret)
2844 swap_interval = interval;
2845 else
2846 SetLastError(ERROR_DC_NOT_FOUND);
2849 return ret;
2853 * X11DRV_wglSetPixelFormatWINE
2855 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
2856 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
2858 static BOOL X11DRV_wglSetPixelFormatWINE(HDC hdc, int format)
2860 const struct wgl_pixel_format *fmt;
2861 int value;
2862 HWND hwnd;
2864 TRACE("(%p,%d)\n", hdc, format);
2866 fmt = get_pixel_format(gdi_display, format, FALSE /* Offscreen */);
2867 if (!fmt)
2869 ERR( "Invalid format %d\n", format );
2870 return FALSE;
2873 hwnd = WindowFromDC( hdc );
2874 if (!hwnd || hwnd == GetDesktopWindow())
2876 ERR( "not a valid window DC %p\n", hdc );
2877 return FALSE;
2880 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
2881 if (!(value & GLX_WINDOW_BIT))
2883 WARN( "Pixel format %d is not compatible for window rendering\n", format );
2884 return FALSE;
2887 return SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, fmt->fmt_id, 0);
2888 /* DC pixel format will be set by the DCE update */
2892 * glxRequireVersion (internal)
2894 * Check if the supported GLX version matches requiredVersion.
2896 static BOOL glxRequireVersion(int requiredVersion)
2898 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2899 if(requiredVersion <= WineGLInfo.glxVersion[1])
2900 return TRUE;
2902 return FALSE;
2905 static void register_extension(const char *ext)
2907 if (WineGLInfo.wglExtensions[0])
2908 strcat(WineGLInfo.wglExtensions, " ");
2909 strcat(WineGLInfo.wglExtensions, ext);
2911 TRACE("'%s'\n", ext);
2915 * X11DRV_WineGL_LoadExtensions
2917 static void X11DRV_WineGL_LoadExtensions(void)
2919 WineGLInfo.wglExtensions[0] = 0;
2921 /* ARB Extensions */
2923 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_create_context"))
2925 register_extension( "WGL_ARB_create_context" );
2926 opengl_funcs.ext.p_wglCreateContextAttribsARB = X11DRV_wglCreateContextAttribsARB;
2928 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_create_context_profile"))
2929 register_extension("WGL_ARB_create_context_profile");
2932 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_fbconfig_float"))
2934 register_extension("WGL_ARB_pixel_format_float");
2935 register_extension("WGL_ATI_pixel_format_float");
2938 register_extension( "WGL_ARB_extensions_string" );
2939 opengl_funcs.ext.p_wglGetExtensionsStringARB = X11DRV_wglGetExtensionsStringARB;
2941 if (glxRequireVersion(3))
2943 register_extension( "WGL_ARB_make_current_read" );
2944 opengl_funcs.ext.p_wglGetCurrentReadDCARB = (void *)1; /* never called */
2945 opengl_funcs.ext.p_wglMakeContextCurrentARB = X11DRV_wglMakeContextCurrentARB;
2948 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_multisample")) register_extension( "WGL_ARB_multisample" );
2950 /* In general pbuffer functionality requires support in the X-server. The functionality is
2951 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
2953 if ( glxRequireVersion(3) && has_extension( WineGLInfo.glxExtensions, "GLX_SGIX_pbuffer") )
2955 register_extension( "WGL_ARB_pbuffer" );
2956 opengl_funcs.ext.p_wglCreatePbufferARB = X11DRV_wglCreatePbufferARB;
2957 opengl_funcs.ext.p_wglDestroyPbufferARB = X11DRV_wglDestroyPbufferARB;
2958 opengl_funcs.ext.p_wglGetPbufferDCARB = X11DRV_wglGetPbufferDCARB;
2959 opengl_funcs.ext.p_wglQueryPbufferARB = X11DRV_wglQueryPbufferARB;
2960 opengl_funcs.ext.p_wglReleasePbufferDCARB = X11DRV_wglReleasePbufferDCARB;
2961 opengl_funcs.ext.p_wglSetPbufferAttribARB = X11DRV_wglSetPbufferAttribARB;
2964 register_extension( "WGL_ARB_pixel_format" );
2965 opengl_funcs.ext.p_wglChoosePixelFormatARB = X11DRV_wglChoosePixelFormatARB;
2966 opengl_funcs.ext.p_wglGetPixelFormatAttribfvARB = X11DRV_wglGetPixelFormatAttribfvARB;
2967 opengl_funcs.ext.p_wglGetPixelFormatAttribivARB = X11DRV_wglGetPixelFormatAttribivARB;
2969 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
2970 if (has_extension( WineGLInfo.glxExtensions, "GLX_ARB_render_texture") ||
2971 (glxRequireVersion(3) && has_extension( WineGLInfo.glxExtensions, "GLX_SGIX_pbuffer") && use_render_texture_emulation))
2973 register_extension( "WGL_ARB_render_texture" );
2974 opengl_funcs.ext.p_wglBindTexImageARB = X11DRV_wglBindTexImageARB;
2975 opengl_funcs.ext.p_wglReleaseTexImageARB = X11DRV_wglReleaseTexImageARB;
2977 /* The WGL version of GLX_NV_float_buffer requires render_texture */
2978 if (has_extension( WineGLInfo.glxExtensions, "GLX_NV_float_buffer"))
2979 register_extension("WGL_NV_float_buffer");
2981 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
2982 if (has_extension(WineGLInfo.glExtensions, "GL_NV_texture_rectangle"))
2983 register_extension("WGL_NV_texture_rectangle");
2986 /* EXT Extensions */
2988 register_extension( "WGL_EXT_extensions_string" );
2989 opengl_funcs.ext.p_wglGetExtensionsStringEXT = X11DRV_wglGetExtensionsStringEXT;
2991 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
2992 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
2993 register_extension( "WGL_EXT_swap_control" );
2994 opengl_funcs.ext.p_wglSwapIntervalEXT = X11DRV_wglSwapIntervalEXT;
2995 opengl_funcs.ext.p_wglGetSwapIntervalEXT = X11DRV_wglGetSwapIntervalEXT;
2997 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_framebuffer_sRGB"))
2998 register_extension("WGL_EXT_framebuffer_sRGB");
3000 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_fbconfig_packed_float"))
3001 register_extension("WGL_EXT_pixel_format_packed_float");
3003 if (has_extension( WineGLInfo.glxExtensions, "GLX_EXT_swap_control"))
3004 has_swap_control = TRUE;
3006 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3007 if (has_extension(WineGLInfo.glExtensions, "GL_NV_vertex_array_range"))
3009 register_extension( "WGL_NV_vertex_array_range" );
3010 opengl_funcs.ext.p_wglAllocateMemoryNV = pglXAllocateMemoryNV;
3011 opengl_funcs.ext.p_wglFreeMemoryNV = pglXFreeMemoryNV;
3014 /* WINE-specific WGL Extensions */
3016 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3017 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3019 register_extension( "WGL_WINE_pixel_format_passthrough" );
3020 opengl_funcs.ext.p_wglSetPixelFormatWINE = X11DRV_wglSetPixelFormatWINE;
3025 * glxdrv_SwapBuffers
3027 * Swap the buffers of this DC
3029 static BOOL glxdrv_SwapBuffers(PHYSDEV dev)
3031 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
3032 struct gl_drawable *gl;
3033 HWND hwnd;
3034 struct wgl_context *ctx = NtCurrentTeb()->glContext;
3036 TRACE("(%p)\n", dev->hdc);
3038 if (!ctx)
3040 WARN("Using a NULL context, skipping\n");
3041 SetLastError(ERROR_INVALID_HANDLE);
3042 return FALSE;
3045 sync_context(ctx);
3047 hwnd = WindowFromDC( dev->hdc );
3048 EnterCriticalSection( &context_section );
3050 if (!XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl ) ||
3051 !XFindContext( gdi_display, (XID)dev->hdc, gl_pbuffer_context, (char **)&gl ))
3053 switch (gl->type)
3055 case DC_GL_PIXMAP_WIN:
3056 if (pglXCopySubBufferMESA) {
3057 /* (glX)SwapBuffers has an implicit glFlush effect, however
3058 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3059 * copying */
3060 pglFlush();
3061 pglXCopySubBufferMESA( gdi_display, gl->drawable, 0, 0,
3062 gl->rect.right - gl->rect.left, gl->rect.bottom - gl->rect.top );
3063 break;
3065 /* fall through */
3066 default:
3067 pglXSwapBuffers(gdi_display, gl->drawable);
3068 break;
3071 LeaveCriticalSection( &context_section );
3073 ExtEscape( dev->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
3075 /* FPS support */
3076 if (TRACE_ON(fps))
3078 static long prev_time, start_time;
3079 static unsigned long frames, frames_total;
3081 DWORD time = GetTickCount();
3082 frames++;
3083 frames_total++;
3084 /* every 1.5 seconds */
3085 if (time - prev_time > 1500) {
3086 TRACE_(fps)("@ approx %.2ffps, total %.2ffps\n",
3087 1000.0*frames/(time - prev_time), 1000.0*frames_total/(time - start_time));
3088 prev_time = time;
3089 frames = 0;
3090 if(start_time == 0) start_time = time;
3094 return TRUE;
3097 static BOOL create_glx_dc( PHYSDEV *pdev )
3099 /* assume that only the main x11 device implements GetDeviceCaps */
3100 X11DRV_PDEVICE *x11dev = get_x11drv_dev( GET_NEXT_PHYSDEV( *pdev, pGetDeviceCaps ));
3101 struct glx_physdev *physdev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physdev) );
3103 if (!physdev) return FALSE;
3104 physdev->x11dev = x11dev;
3105 push_dc_driver( pdev, &physdev->dev, &glxdrv_funcs );
3106 return TRUE;
3109 /**********************************************************************
3110 * glxdrv_CreateDC
3112 static BOOL glxdrv_CreateDC( PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device,
3113 LPCWSTR output, const DEVMODEW* initData )
3115 return create_glx_dc( pdev );
3118 /**********************************************************************
3119 * glxdrv_CreateCompatibleDC
3121 static BOOL glxdrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
3123 if (orig) /* chain to next driver first */
3125 orig = GET_NEXT_PHYSDEV( orig, pCreateCompatibleDC );
3126 if (!orig->funcs->pCreateCompatibleDC( orig, pdev )) return FALSE;
3128 /* otherwise we have been called by x11drv */
3129 return create_glx_dc( pdev );
3132 /**********************************************************************
3133 * glxdrv_DeleteDC
3135 static BOOL glxdrv_DeleteDC( PHYSDEV dev )
3137 struct glx_physdev *physdev = get_glxdrv_dev( dev );
3138 HeapFree( GetProcessHeap(), 0, physdev );
3139 return TRUE;
3142 /**********************************************************************
3143 * glxdrv_ExtEscape
3145 static INT glxdrv_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
3146 INT out_count, LPVOID out_data )
3148 struct glx_physdev *physdev = get_glxdrv_dev( dev );
3150 dev = GET_NEXT_PHYSDEV( dev, pExtEscape );
3152 if (escape == X11DRV_ESCAPE && in_data && in_count >= sizeof(enum x11drv_escape_codes))
3154 switch (*(const enum x11drv_escape_codes *)in_data)
3156 case X11DRV_SET_DRAWABLE:
3157 if (in_count >= sizeof(struct x11drv_escape_set_drawable))
3159 struct gl_drawable *gl;
3160 const struct x11drv_escape_set_drawable *data = in_data;
3162 EnterCriticalSection( &context_section );
3163 if (!XFindContext( gdi_display, (XID)data->hwnd, gl_hwnd_context, (char **)&gl ) ||
3164 !XFindContext( gdi_display, (XID)dev->hdc, gl_pbuffer_context, (char **)&gl ))
3166 physdev->format = gl->format;
3167 physdev->type = gl->type;
3168 physdev->drawable = gl->drawable;
3169 physdev->pixmap = gl->pixmap;
3171 else
3173 physdev->format = NULL;
3174 physdev->type = DC_GL_NONE;
3175 physdev->drawable = 0;
3176 physdev->pixmap = 0;
3178 LeaveCriticalSection( &context_section );
3179 TRACE( "SET_DRAWABLE hdc %p drawable %lx pf %p type %u\n",
3180 dev->hdc, physdev->drawable, physdev->format, physdev->type );
3182 break;
3183 case X11DRV_GET_DRAWABLE:
3184 if (out_count >= sizeof(struct x11drv_escape_get_drawable))
3186 struct x11drv_escape_get_drawable *data = out_data;
3187 data->pixel_format = physdev->format ? physdev->format - pixel_formats + 1 : 0;
3188 data->gl_drawable = physdev->drawable;
3190 break;
3191 case X11DRV_FLUSH_GL_DRAWABLE:
3192 flush_gl_drawable( physdev );
3193 return TRUE;
3194 default:
3195 break;
3198 return dev->funcs->pExtEscape( dev, escape, in_count, in_data, out_count, out_data );
3201 /**********************************************************************
3202 * glxdrv_wine_get_wgl_driver
3204 static struct opengl_funcs * glxdrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
3206 if (version != WINE_WGL_DRIVER_VERSION)
3208 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_WGL_DRIVER_VERSION );
3209 return NULL;
3212 if (has_opengl()) return &opengl_funcs;
3214 dev = GET_NEXT_PHYSDEV( dev, wine_get_wgl_driver );
3215 return dev->funcs->wine_get_wgl_driver( dev, version );
3218 static const struct gdi_dc_funcs glxdrv_funcs =
3220 NULL, /* pAbortDoc */
3221 NULL, /* pAbortPath */
3222 NULL, /* pAlphaBlend */
3223 NULL, /* pAngleArc */
3224 NULL, /* pArc */
3225 NULL, /* pArcTo */
3226 NULL, /* pBeginPath */
3227 NULL, /* pBlendImage */
3228 NULL, /* pChord */
3229 NULL, /* pCloseFigure */
3230 glxdrv_CreateCompatibleDC, /* pCreateCompatibleDC */
3231 glxdrv_CreateDC, /* pCreateDC */
3232 glxdrv_DeleteDC, /* pDeleteDC */
3233 NULL, /* pDeleteObject */
3234 NULL, /* pDeviceCapabilities */
3235 NULL, /* pEllipse */
3236 NULL, /* pEndDoc */
3237 NULL, /* pEndPage */
3238 NULL, /* pEndPath */
3239 NULL, /* pEnumFonts */
3240 NULL, /* pEnumICMProfiles */
3241 NULL, /* pExcludeClipRect */
3242 NULL, /* pExtDeviceMode */
3243 glxdrv_ExtEscape, /* pExtEscape */
3244 NULL, /* pExtFloodFill */
3245 NULL, /* pExtSelectClipRgn */
3246 NULL, /* pExtTextOut */
3247 NULL, /* pFillPath */
3248 NULL, /* pFillRgn */
3249 NULL, /* pFlattenPath */
3250 NULL, /* pFontIsLinked */
3251 NULL, /* pFrameRgn */
3252 NULL, /* pGdiComment */
3253 NULL, /* pGdiRealizationInfo */
3254 NULL, /* pGetBoundsRect */
3255 NULL, /* pGetCharABCWidths */
3256 NULL, /* pGetCharABCWidthsI */
3257 NULL, /* pGetCharWidth */
3258 NULL, /* pGetDeviceCaps */
3259 NULL, /* pGetDeviceGammaRamp */
3260 NULL, /* pGetFontData */
3261 NULL, /* pGetFontUnicodeRanges */
3262 NULL, /* pGetGlyphIndices */
3263 NULL, /* pGetGlyphOutline */
3264 NULL, /* pGetICMProfile */
3265 NULL, /* pGetImage */
3266 NULL, /* pGetKerningPairs */
3267 NULL, /* pGetNearestColor */
3268 NULL, /* pGetOutlineTextMetrics */
3269 NULL, /* pGetPixel */
3270 NULL, /* pGetSystemPaletteEntries */
3271 NULL, /* pGetTextCharsetInfo */
3272 NULL, /* pGetTextExtentExPoint */
3273 NULL, /* pGetTextExtentExPointI */
3274 NULL, /* pGetTextFace */
3275 NULL, /* pGetTextMetrics */
3276 NULL, /* pGradientFill */
3277 NULL, /* pIntersectClipRect */
3278 NULL, /* pInvertRgn */
3279 NULL, /* pLineTo */
3280 NULL, /* pModifyWorldTransform */
3281 NULL, /* pMoveTo */
3282 NULL, /* pOffsetClipRgn */
3283 NULL, /* pOffsetViewportOrg */
3284 NULL, /* pOffsetWindowOrg */
3285 NULL, /* pPaintRgn */
3286 NULL, /* pPatBlt */
3287 NULL, /* pPie */
3288 NULL, /* pPolyBezier */
3289 NULL, /* pPolyBezierTo */
3290 NULL, /* pPolyDraw */
3291 NULL, /* pPolyPolygon */
3292 NULL, /* pPolyPolyline */
3293 NULL, /* pPolygon */
3294 NULL, /* pPolyline */
3295 NULL, /* pPolylineTo */
3296 NULL, /* pPutImage */
3297 NULL, /* pRealizeDefaultPalette */
3298 NULL, /* pRealizePalette */
3299 NULL, /* pRectangle */
3300 NULL, /* pResetDC */
3301 NULL, /* pRestoreDC */
3302 NULL, /* pRoundRect */
3303 NULL, /* pSaveDC */
3304 NULL, /* pScaleViewportExt */
3305 NULL, /* pScaleWindowExt */
3306 NULL, /* pSelectBitmap */
3307 NULL, /* pSelectBrush */
3308 NULL, /* pSelectClipPath */
3309 NULL, /* pSelectFont */
3310 NULL, /* pSelectPalette */
3311 NULL, /* pSelectPen */
3312 NULL, /* pSetArcDirection */
3313 NULL, /* pSetBkColor */
3314 NULL, /* pSetBkMode */
3315 NULL, /* pSetBoundsRect */
3316 NULL, /* pSetDCBrushColor */
3317 NULL, /* pSetDCPenColor */
3318 NULL, /* pSetDIBitsToDevice */
3319 NULL, /* pSetDeviceClipping */
3320 NULL, /* pSetDeviceGammaRamp */
3321 NULL, /* pSetLayout */
3322 NULL, /* pSetMapMode */
3323 NULL, /* pSetMapperFlags */
3324 NULL, /* pSetPixel */
3325 NULL, /* pSetPolyFillMode */
3326 NULL, /* pSetROP2 */
3327 NULL, /* pSetRelAbs */
3328 NULL, /* pSetStretchBltMode */
3329 NULL, /* pSetTextAlign */
3330 NULL, /* pSetTextCharacterExtra */
3331 NULL, /* pSetTextColor */
3332 NULL, /* pSetTextJustification */
3333 NULL, /* pSetViewportExt */
3334 NULL, /* pSetViewportOrg */
3335 NULL, /* pSetWindowExt */
3336 NULL, /* pSetWindowOrg */
3337 NULL, /* pSetWorldTransform */
3338 NULL, /* pStartDoc */
3339 NULL, /* pStartPage */
3340 NULL, /* pStretchBlt */
3341 NULL, /* pStretchDIBits */
3342 NULL, /* pStrokeAndFillPath */
3343 NULL, /* pStrokePath */
3344 glxdrv_SwapBuffers, /* pSwapBuffers */
3345 NULL, /* pUnrealizePalette */
3346 NULL, /* pWidenPath */
3347 glxdrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
3348 GDI_PRIORITY_GRAPHICS_DRV + 20 /* priority */
3351 static struct opengl_funcs opengl_funcs =
3354 glxdrv_wglCopyContext, /* p_wglCopyContext */
3355 glxdrv_wglCreateContext, /* p_wglCreateContext */
3356 glxdrv_wglDeleteContext, /* p_wglDeleteContext */
3357 glxdrv_wglDescribePixelFormat, /* p_wglDescribePixelFormat */
3358 glxdrv_wglGetPixelFormat, /* p_wglGetPixelFormat */
3359 glxdrv_wglGetProcAddress, /* p_wglGetProcAddress */
3360 glxdrv_wglMakeCurrent, /* p_wglMakeCurrent */
3361 glxdrv_wglSetPixelFormat, /* p_wglSetPixelFormat */
3362 glxdrv_wglShareLists, /* p_wglShareLists */
3366 const struct gdi_dc_funcs *get_glx_driver(void)
3368 return &glxdrv_funcs;
3371 #else /* no OpenGL includes */
3373 const struct gdi_dc_funcs *get_glx_driver(void)
3375 return NULL;
3378 BOOL set_win_format( HWND hwnd, XID fbconfig_id )
3380 return FALSE;
3383 void sync_gl_drawable( HWND hwnd, const RECT *visible_rect, const RECT *client_rect )
3387 void destroy_gl_drawable( HWND hwnd )
3391 #endif /* defined(SONAME_LIBGL) */