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
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
32 #ifdef HAVE_SYS_SOCKET_H
33 #include <sys/socket.h>
41 #include "wine/library.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
48 WINE_DECLARE_DEBUG_CHANNEL(winediag);
67 /* Redefines the constants */
68 #define CALLBACK __stdcall
69 #define WINAPI __stdcall
70 #define APIENTRY WINAPI
73 WINE_DECLARE_DEBUG_CHANNEL(fps);
75 typedef struct wine_glextension {
84 const char *glVersion;
89 const char *glxServerVersion;
90 const char *glxServerVendor;
91 const char *glxServerExtensions;
93 const char *glxClientVersion;
94 const char *glxClientVendor;
95 const char *glxClientExtensions;
97 const char *glxExtensions;
100 char wglExtensions[4096];
103 typedef struct wine_glpixelformat {
105 GLXFBConfig fbconfig;
109 DWORD dwFlags; /* We store some PFD_* flags in here for emulated bitmap formats */
112 typedef struct wine_glcontext {
114 BOOL has_been_current;
119 WineGLPixelFormat *fmt;
120 int numAttribs; /* This is needed for delaying wglCreateContextAttribsARB */
121 int attribList[16]; /* This is needed for delaying wglCreateContextAttribsARB */
124 Drawable drawables[2];
125 BOOL refresh_drawables;
126 Pixmap pixmap; /* pixmap for memory DCs */
127 GLXPixmap glxpixmap; /* GLX pixmap for memory DCs */
128 SIZE pixmap_size; /* pixmap size for memory DCs */
132 typedef struct wine_glpbuffer {
135 WineGLPixelFormat* fmt;
141 int use_render_texture; /* This is also the internal texture format */
142 int texture_bind_target;
144 GLint texture_format;
145 GLuint texture_target;
153 struct gdi_physdev dev;
154 X11DRV_PDEVICE *x11dev;
155 enum dc_gl_type type; /* type of GL device context */
158 Pixmap pixmap; /* pixmap for a DL_GL_PIXMAP_WIN drawable */
161 static const struct gdi_dc_funcs glxdrv_funcs;
163 static inline struct glx_physdev *get_glxdrv_dev( PHYSDEV dev )
165 return (struct glx_physdev *)dev;
168 static struct list context_list = LIST_INIT( context_list );
169 static struct WineGLInfo WineGLInfo = { 0 };
170 static int use_render_texture_emulation = 1;
171 static int use_render_texture_ati = 0;
172 static BOOL has_swap_control;
173 static int swap_interval = 1;
175 #define MAX_EXTENSIONS 16
176 static const WineGLExtension *WineGLExtensionList[MAX_EXTENSIONS];
177 static int WineGLExtensionListSize;
179 static void X11DRV_WineGL_LoadExtensions(void);
180 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count);
181 static BOOL glxRequireVersion(int requiredVersion);
182 static BOOL glxRequireExtension(const char *requiredExtension);
184 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
185 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
186 TRACE(" - dwFlags : ");
187 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
188 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
189 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
190 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
191 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
192 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
193 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
194 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
195 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
196 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
197 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
198 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
199 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
200 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
201 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
202 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
203 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
204 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
205 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
206 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
210 TRACE(" - iPixelType : ");
211 switch (ppfd->iPixelType) {
212 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
213 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
217 TRACE(" - Color : %d\n", ppfd->cColorBits);
218 TRACE(" - Red : %d\n", ppfd->cRedBits);
219 TRACE(" - Green : %d\n", ppfd->cGreenBits);
220 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
221 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
222 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
223 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
224 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
225 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
227 TRACE(" - iLayerType : ");
228 switch (ppfd->iLayerType) {
229 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
230 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
231 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
236 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
237 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
239 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
241 MAKE_FUNCPTR(glXChooseVisual)
242 MAKE_FUNCPTR(glXCopyContext)
243 MAKE_FUNCPTR(glXCreateContext)
244 MAKE_FUNCPTR(glXCreateGLXPixmap)
245 MAKE_FUNCPTR(glXGetCurrentContext)
246 MAKE_FUNCPTR(glXGetCurrentDrawable)
247 MAKE_FUNCPTR(glXDestroyContext)
248 MAKE_FUNCPTR(glXDestroyGLXPixmap)
249 MAKE_FUNCPTR(glXGetConfig)
250 MAKE_FUNCPTR(glXIsDirect)
251 MAKE_FUNCPTR(glXMakeCurrent)
252 MAKE_FUNCPTR(glXSwapBuffers)
253 MAKE_FUNCPTR(glXQueryExtension)
254 MAKE_FUNCPTR(glXQueryVersion)
257 MAKE_FUNCPTR(glXGetClientString)
258 MAKE_FUNCPTR(glXQueryExtensionsString)
259 MAKE_FUNCPTR(glXQueryServerString)
262 MAKE_FUNCPTR(glXGetFBConfigs)
263 MAKE_FUNCPTR(glXChooseFBConfig)
264 MAKE_FUNCPTR(glXCreatePbuffer)
265 MAKE_FUNCPTR(glXCreateNewContext)
266 MAKE_FUNCPTR(glXDestroyPbuffer)
267 MAKE_FUNCPTR(glXGetFBConfigAttrib)
268 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
269 MAKE_FUNCPTR(glXMakeContextCurrent)
270 MAKE_FUNCPTR(glXQueryDrawable)
271 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
274 static GLXContext (*pglXCreateContextAttribsARB)(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
275 static void* (*pglXGetProcAddressARB)(const GLubyte *);
276 static int (*pglXSwapIntervalSGI)(int);
278 /* ATI GLX Extensions */
279 static BOOL (*pglXBindTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
280 static BOOL (*pglXReleaseTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
281 static BOOL (*pglXDrawableAttribATI)(Display *dpy, GLXDrawable draw, const int *attribList);
283 /* NV GLX Extension */
284 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
285 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
287 /* MESA GLX Extensions */
288 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
290 /* Standard OpenGL */
291 MAKE_FUNCPTR(glBindTexture)
292 MAKE_FUNCPTR(glBitmap)
293 MAKE_FUNCPTR(glCopyTexSubImage1D)
294 MAKE_FUNCPTR(glCopyTexImage2D)
295 MAKE_FUNCPTR(glCopyTexSubImage2D)
296 MAKE_FUNCPTR(glDrawBuffer)
297 MAKE_FUNCPTR(glEndList)
298 MAKE_FUNCPTR(glGetError)
299 MAKE_FUNCPTR(glGetIntegerv)
300 MAKE_FUNCPTR(glGetString)
301 MAKE_FUNCPTR(glNewList)
302 MAKE_FUNCPTR(glPixelStorei)
303 MAKE_FUNCPTR(glReadPixels)
304 MAKE_FUNCPTR(glTexImage2D)
305 MAKE_FUNCPTR(glFinish)
306 MAKE_FUNCPTR(glFlush)
309 static int GLXErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
311 /* In the future we might want to find the exact X or GLX error to report back to the app */
315 static BOOL infoInitialized = FALSE;
316 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
318 int screen = DefaultScreen(gdi_display);
319 Window win = 0, root = 0;
320 const char *gl_renderer;
323 GLXContext ctx = NULL;
324 XSetWindowAttributes attr;
326 int attribList[] = {GLX_RGBA, GLX_DOUBLEBUFFER, None};
330 infoInitialized = TRUE;
332 attr.override_redirect = True;
333 attr.colormap = None;
334 attr.border_pixel = 0;
338 vis = pglXChooseVisual(gdi_display, screen, attribList);
341 WORD old_fs = wine_get_fs();
342 /* Create a GLX Context. Without one we can't query GL information */
343 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
344 if (wine_get_fs() != old_fs)
346 wine_set_fs( old_fs );
347 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
348 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
352 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
357 root = RootWindow( gdi_display, vis->screen );
358 if (vis->visual != DefaultVisual( gdi_display, vis->screen ))
359 attr.colormap = XCreateColormap( gdi_display, root, vis->visual, AllocNone );
360 if ((win = XCreateWindow( gdi_display, root, -1, -1, 1, 1, 0, vis->depth, InputOutput,
361 vis->visual, CWBorderPixel | CWOverrideRedirect | CWColormap, &attr )))
362 XMapWindow( gdi_display, win );
366 if(pglXMakeCurrent(gdi_display, win, ctx) == 0)
368 ERR_(winediag)( "Unable to activate OpenGL context, most likely your OpenGL drivers haven't been installed correctly\n" );
371 gl_renderer = (const char *)pglGetString(GL_RENDERER);
372 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
373 str = (const char *) pglGetString(GL_EXTENSIONS);
374 WineGLInfo.glExtensions = HeapAlloc(GetProcessHeap(), 0, strlen(str)+1);
375 strcpy(WineGLInfo.glExtensions, str);
377 /* Get the common GLX version supported by GLX client and server ( major/minor) */
378 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
380 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
381 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
382 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
384 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
385 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
386 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
388 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
389 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
391 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
392 TRACE("GL renderer : %s.\n", gl_renderer);
393 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
394 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
395 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
396 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
397 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
398 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
400 if(!WineGLInfo.glxDirect)
402 int fd = ConnectionNumber(gdi_display);
403 struct sockaddr_un uaddr;
404 unsigned int uaddrlen = sizeof(struct sockaddr_un);
406 /* In general indirect rendering on a local X11 server indicates a driver problem.
407 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
409 if(!getsockname(fd, (struct sockaddr *)&uaddr, &uaddrlen) && uaddr.sun_family == AF_UNIX)
410 ERR_(winediag)("Direct rendering is disabled, most likely your OpenGL drivers "
411 "haven't been installed correctly (using GL renderer %s, version %s).\n",
412 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
416 /* In general you would expect that if direct rendering is returned, that you receive hardware
417 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
418 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
419 * software rendering, it shows direct rendering.
421 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
422 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
423 * it shows 'Mesa X11'.
425 if(!strcmp(gl_renderer, "Software Rasterizer") || !strcmp(gl_renderer, "Mesa X11"))
426 ERR_(winediag)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL "
427 "drivers haven't been installed correctly (using GL renderer %s, version %s).\n",
428 debugstr_a(gl_renderer), debugstr_a(WineGLInfo.glVersion));
435 pglXMakeCurrent(gdi_display, None, NULL);
436 pglXDestroyContext(gdi_display, ctx);
438 if (win != root) XDestroyWindow( gdi_display, win );
439 if (attr.colormap) XFreeColormap( gdi_display, attr.colormap );
441 if (!ret) ERR(" couldn't initialize OpenGL, expect problems\n");
445 static BOOL has_opengl(void)
447 static int init_done;
448 static void *opengl_handle;
451 int error_base, event_base;
453 if (init_done) return (opengl_handle != NULL);
456 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
457 and include all dependencies */
458 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, buffer, sizeof(buffer));
459 if (opengl_handle == NULL)
461 ERR( "Failed to load libGL: %s\n", buffer );
462 ERR( "OpenGL support is disabled.\n");
466 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
467 if (pglXGetProcAddressARB == NULL) {
468 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
472 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
474 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
479 LOAD_FUNCPTR(glXChooseVisual);
480 LOAD_FUNCPTR(glXCopyContext);
481 LOAD_FUNCPTR(glXCreateContext);
482 LOAD_FUNCPTR(glXCreateGLXPixmap);
483 LOAD_FUNCPTR(glXGetCurrentContext);
484 LOAD_FUNCPTR(glXGetCurrentDrawable);
485 LOAD_FUNCPTR(glXDestroyContext);
486 LOAD_FUNCPTR(glXDestroyGLXPixmap);
487 LOAD_FUNCPTR(glXGetConfig);
488 LOAD_FUNCPTR(glXIsDirect);
489 LOAD_FUNCPTR(glXMakeCurrent);
490 LOAD_FUNCPTR(glXSwapBuffers);
491 LOAD_FUNCPTR(glXQueryExtension);
492 LOAD_FUNCPTR(glXQueryVersion);
495 LOAD_FUNCPTR(glXGetClientString);
496 LOAD_FUNCPTR(glXQueryExtensionsString);
497 LOAD_FUNCPTR(glXQueryServerString);
500 LOAD_FUNCPTR(glXCreatePbuffer);
501 LOAD_FUNCPTR(glXCreateNewContext);
502 LOAD_FUNCPTR(glXDestroyPbuffer);
503 LOAD_FUNCPTR(glXMakeContextCurrent);
504 LOAD_FUNCPTR(glXGetCurrentReadDrawable);
505 LOAD_FUNCPTR(glXGetFBConfigs);
507 /* Standard OpenGL calls */
508 LOAD_FUNCPTR(glBindTexture);
509 LOAD_FUNCPTR(glBitmap);
510 LOAD_FUNCPTR(glCopyTexSubImage1D);
511 LOAD_FUNCPTR(glCopyTexImage2D);
512 LOAD_FUNCPTR(glCopyTexSubImage2D);
513 LOAD_FUNCPTR(glDrawBuffer);
514 LOAD_FUNCPTR(glEndList);
515 LOAD_FUNCPTR(glGetError);
516 LOAD_FUNCPTR(glGetIntegerv);
517 LOAD_FUNCPTR(glGetString);
518 LOAD_FUNCPTR(glNewList);
519 LOAD_FUNCPTR(glPixelStorei);
520 LOAD_FUNCPTR(glReadPixels);
521 LOAD_FUNCPTR(glTexImage2D);
522 LOAD_FUNCPTR(glFinish);
523 LOAD_FUNCPTR(glFlush);
526 /* It doesn't matter if these fail. They'll only be used if the driver reports
527 the associated extension is available (and if a driver reports the extension
528 is available but fails to provide the functions, it's quite broken) */
529 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
530 /* ARB GLX Extension */
531 LOAD_FUNCPTR(glXCreateContextAttribsARB);
532 /* SGI GLX Extension */
533 LOAD_FUNCPTR(glXSwapIntervalSGI);
534 /* NV GLX Extension */
535 LOAD_FUNCPTR(glXAllocateMemoryNV);
536 LOAD_FUNCPTR(glXFreeMemoryNV);
539 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed;
542 if (pglXQueryExtension(gdi_display, &error_base, &event_base)) {
543 TRACE("GLX is up and running error_base = %d\n", error_base);
546 ERR( "GLX extension is missing, disabling OpenGL.\n" );
550 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
551 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
554 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
555 * depends on the reported GLX client / server version and on the client / server extension list.
556 * Those don't have to be the same.
558 * In general the server GLX information lists the capabilities in case of indirect rendering.
559 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
560 * available and in that case the client GLX informat can be used.
561 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
562 * in the GLX version/extension list. When a program does this it works for certain for both
563 * direct and indirect rendering.
565 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
566 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
567 * extension list which causes this extension not to be listed. (Wine requires this extension).
568 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
569 * pbuffers is around.
571 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
572 * the ATI drivers and from then on use GLX client information for them.
575 if(glxRequireVersion(3)) {
576 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
577 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
578 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
579 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
580 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
581 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
582 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
583 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
585 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
586 * enable this function when the Xserver understand GLX 1.3 or newer
588 pglXQueryDrawable = NULL;
589 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
590 TRACE("Overriding ATI GLX capabilities!\n");
591 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
592 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
593 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
594 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
596 /* Use client GLX information in case of the ATI drivers. We override the
597 * capabilities over here and not somewhere else as ATI might better their
598 * life in the future. In case they release proper drivers this block of
599 * code won't be called. */
600 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
602 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
605 if(glxRequireExtension("GLX_ATI_render_texture")) {
606 use_render_texture_ati = 1;
607 pglXBindTexImageATI = pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageATI");
608 pglXReleaseTexImageATI = pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageATI");
609 pglXDrawableAttribATI = pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribATI");
612 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
613 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
616 X11DRV_WineGL_LoadExtensions();
622 wine_dlclose(opengl_handle, NULL, 0);
623 opengl_handle = NULL;
627 static inline BOOL is_valid_context( Wine_GLContext *ctx )
630 LIST_FOR_EACH_ENTRY( ptr, &context_list, struct wine_glcontext, entry )
631 if (ptr == ctx) return TRUE;
635 static int describeContext(Wine_GLContext* ctx) {
638 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
639 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
640 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
641 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
642 TRACE(" - VISUAL_ID 0x%x\n", tmp);
647 static BOOL describeDrawable( struct glx_physdev *physdev )
650 WineGLPixelFormat *fmt;
653 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physdev->pixel_format, TRUE /* Offscreen */, &fmt_count);
654 if(!fmt) return FALSE;
656 TRACE(" HDC %p has:\n", physdev->dev.hdc);
657 TRACE(" - iPixelFormat %d\n", fmt->iPixelFormat);
658 TRACE(" - Drawable %lx\n", physdev->drawable);
659 TRACE(" - FBCONFIG_ID 0x%x\n", fmt->fmt_id);
661 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &tmp);
662 TRACE(" - VISUAL_ID 0x%x\n", tmp);
667 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
672 int nvfloatattrib = GLX_DONT_CARE;
673 int pixelattrib = GLX_DONT_CARE;
675 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
676 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
677 while (iWGLAttr && 0 != iWGLAttr[cur]) {
678 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
680 switch (iWGLAttr[cur]) {
681 case WGL_AUX_BUFFERS_ARB:
682 pop = iWGLAttr[++cur];
683 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
684 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
686 case WGL_COLOR_BITS_ARB:
687 pop = iWGLAttr[++cur];
688 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
689 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
691 case WGL_BLUE_BITS_ARB:
692 pop = iWGLAttr[++cur];
693 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
694 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
696 case WGL_RED_BITS_ARB:
697 pop = iWGLAttr[++cur];
698 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
699 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
701 case WGL_GREEN_BITS_ARB:
702 pop = iWGLAttr[++cur];
703 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
704 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
706 case WGL_ALPHA_BITS_ARB:
707 pop = iWGLAttr[++cur];
708 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
709 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
711 case WGL_DEPTH_BITS_ARB:
712 pop = iWGLAttr[++cur];
713 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
714 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
716 case WGL_STENCIL_BITS_ARB:
717 pop = iWGLAttr[++cur];
718 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
719 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
721 case WGL_DOUBLE_BUFFER_ARB:
722 pop = iWGLAttr[++cur];
723 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
724 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
727 pop = iWGLAttr[++cur];
728 PUSH2(oGLXAttr, GLX_STEREO, pop);
729 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur, pop);
732 case WGL_PIXEL_TYPE_ARB:
733 pop = iWGLAttr[++cur];
734 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
736 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
737 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
738 /* 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 */
739 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
740 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT: pixelattrib = GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT; break ;
742 ERR("unexpected PixelType(%x)\n", pop);
747 case WGL_SUPPORT_GDI_ARB:
748 /* This flag is set in a WineGLPixelFormat */
749 pop = iWGLAttr[++cur];
750 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
753 case WGL_DRAW_TO_BITMAP_ARB:
754 /* This flag is set in a WineGLPixelFormat */
755 pop = iWGLAttr[++cur];
756 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
759 case WGL_DRAW_TO_WINDOW_ARB:
760 pop = iWGLAttr[++cur];
761 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
762 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
764 drawattrib |= GLX_WINDOW_BIT;
768 case WGL_DRAW_TO_PBUFFER_ARB:
769 pop = iWGLAttr[++cur];
770 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
771 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
773 drawattrib |= GLX_PBUFFER_BIT;
777 case WGL_ACCELERATION_ARB:
778 /* This flag is set in a WineGLPixelFormat */
779 pop = iWGLAttr[++cur];
780 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur, pop);
783 case WGL_SUPPORT_OPENGL_ARB:
784 pop = iWGLAttr[++cur];
785 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
786 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
789 case WGL_SWAP_METHOD_ARB:
790 pop = iWGLAttr[++cur];
791 /* For now we ignore this and just return SWAP_EXCHANGE */
792 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur, pop);
795 case WGL_PBUFFER_LARGEST_ARB:
796 pop = iWGLAttr[++cur];
797 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
798 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
801 case WGL_SAMPLE_BUFFERS_ARB:
802 pop = iWGLAttr[++cur];
803 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
804 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
807 case WGL_SAMPLES_ARB:
808 pop = iWGLAttr[++cur];
809 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
810 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
813 case WGL_TEXTURE_FORMAT_ARB:
814 case WGL_TEXTURE_TARGET_ARB:
815 case WGL_MIPMAP_TEXTURE_ARB:
816 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
817 pop = iWGLAttr[++cur];
819 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
821 if (use_render_texture_ati) {
822 /** nothing to do here */
824 else if (!use_render_texture_emulation) {
825 if (WGL_NO_TEXTURE_ARB != pop) {
826 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
827 return -1; /** error: don't support it */
829 drawattrib |= GLX_PBUFFER_BIT;
833 case WGL_FLOAT_COMPONENTS_NV:
834 nvfloatattrib = iWGLAttr[++cur];
835 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
837 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
838 case WGL_BIND_TO_TEXTURE_RGB_ARB:
839 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
840 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
841 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
842 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
843 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
844 pop = iWGLAttr[++cur];
845 /** cannot be converted, see direct handling on
846 * - wglGetPixelFormatAttribivARB
847 * TODO: wglChoosePixelFormat
850 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
851 pop = iWGLAttr[++cur];
852 PUSH2(oGLXAttr, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, pop);
853 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur, pop);
856 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
857 pop = iWGLAttr[++cur];
858 PUSH2(oGLXAttr, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT, pop);
859 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur, pop);
862 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
868 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
869 * all formats. Unless drawattrib is set to a non-zero value override it with GLX_DONT_CARE, so that
870 * pixmap and pbuffer formats appear as well. */
871 if (!drawattrib) drawattrib = GLX_DONT_CARE;
872 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
873 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
875 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
876 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to
877 * GLX_DONT_CARE unless it is overridden. */
878 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
879 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
881 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
882 if(strstr(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
883 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
884 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
890 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
892 int render_type=0, render_type_bit;
893 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
894 switch(render_type_bit)
897 render_type = GLX_RGBA_TYPE;
899 case GLX_COLOR_INDEX_BIT:
900 render_type = GLX_COLOR_INDEX_TYPE;
902 case GLX_RGBA_FLOAT_BIT:
903 render_type = GLX_RGBA_FLOAT_TYPE;
905 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT:
906 render_type = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
909 ERR("Unknown render_type: %x\n", render_type_bit);
914 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
915 static BOOL check_fbconfig_bitmap_capability(Display *display, GLXFBConfig fbconfig)
918 pglXGetFBConfigAttrib(display, fbconfig, GLX_DOUBLEBUFFER, &dbuf);
919 pglXGetFBConfigAttrib(gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &value);
921 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
922 * the GLX_PIXMAP_BIT set. */
923 return !dbuf && (value & GLX_PIXMAP_BIT);
926 static WineGLPixelFormat *get_formats(Display *display, int *size_ret, int *onscreen_size_ret)
928 static WineGLPixelFormat *list;
929 static int size, onscreen_size;
931 int fmt_id, nCfgs, i, run, bmp_formats;
933 XVisualInfo *visinfo;
938 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
939 if (NULL == cfgs || 0 == nCfgs) {
940 if(cfgs != NULL) XFree(cfgs);
942 ERR("glXChooseFBConfig returns NULL\n");
946 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
947 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
948 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
949 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
951 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
953 for(i=0, bmp_formats=0; i<nCfgs; i++)
955 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
958 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats);
960 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nCfgs + bmp_formats)*sizeof(WineGLPixelFormat));
962 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
963 * Do this as GLX doesn't guarantee that the list is sorted */
964 for(run=0; run < 2; run++)
966 for(i=0; i<nCfgs; i++) {
967 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
968 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
970 /* The first run we only add onscreen formats (ones which have an associated X Visual).
971 * The second run we only set offscreen formats. */
974 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
975 * The contents is copied to the destination using XCopyArea. For the copying to work
976 * the depth of the source and destination window should be the same. In general this should
977 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
978 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
979 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
980 * list formats with the same depth. */
981 if(visinfo->depth != screen_depth)
987 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
988 list[size].iPixelFormat = size+1; /* The index starts at 1 */
989 list[size].fbconfig = cfgs[i];
990 list[size].fmt_id = fmt_id;
991 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
992 list[size].offscreenOnly = FALSE;
993 list[size].dwFlags = 0;
997 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
998 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
1000 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1001 list[size].iPixelFormat = size+1; /* The index starts at 1 */
1002 list[size].fbconfig = cfgs[i];
1003 list[size].fmt_id = fmt_id;
1004 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1005 list[size].offscreenOnly = FALSE;
1006 list[size].dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_GENERIC_FORMAT;
1010 } else if(run && !visinfo) {
1011 int window_drawable=0;
1012 pglXGetFBConfigAttrib(gdi_display, cfgs[i], GLX_DRAWABLE_TYPE, &window_drawable);
1014 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
1015 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1016 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1017 * likely make our child window opengl rendering more complicated since likely you can't use
1018 * XCopyArea on a GLX Window.
1019 * For now ignore fbconfigs which are window drawable but lack a visual. */
1020 if(window_drawable & GLX_WINDOW_BIT)
1022 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id);
1026 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1027 list[size].iPixelFormat = size+1; /* The index starts at 1 */
1028 list[size].fbconfig = cfgs[i];
1029 list[size].fmt_id = fmt_id;
1030 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1031 list[size].offscreenOnly = TRUE;
1032 list[size].dwFlags = 0;
1036 if (visinfo) XFree(visinfo);
1043 if (size_ret) *size_ret = size;
1044 if (onscreen_size_ret) *onscreen_size_ret = onscreen_size;
1045 wine_tsx11_unlock();
1049 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1050 * In our WGL implementation we only support a subset of these formats namely the format of
1051 * Wine's main visual and offscreen formats (if they are available).
1052 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
1053 * and it returns the number of supported WGL formats in fmt_count.
1055 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count)
1057 WineGLPixelFormat *list, *res = NULL;
1058 int size, onscreen_size;
1060 if (!(list = get_formats(display, &size, &onscreen_size ))) return NULL;
1062 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1063 * iPixelFormat in case of probing the number of pixelformats.
1065 if((iPixelFormat > 0) && (iPixelFormat <= size) &&
1066 (!list[iPixelFormat-1].offscreenOnly || AllowOffscreen)) {
1067 res = &list[iPixelFormat-1];
1068 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n", res->fmt_id, iPixelFormat);
1074 *fmt_count = onscreen_size;
1076 TRACE("Number of returned pixelformats=%d\n", *fmt_count);
1081 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1082 static WineGLPixelFormat* ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id, DWORD dwFlags)
1084 WineGLPixelFormat *list;
1087 if (!(list = get_formats(display, &size, NULL ))) return NULL;
1089 for(i=0; i<size; i++) {
1090 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1091 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1092 if( (list[i].fmt_id == fmt_id) && ((list[i].dwFlags & dwFlags) == dwFlags) ) {
1093 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list[i].iPixelFormat, fmt_id);
1097 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id);
1101 static int pixelformat_from_fbconfig_id(XID fbconfig_id)
1103 WineGLPixelFormat *fmt;
1105 if (!fbconfig_id) return 0;
1107 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id, 0 /* no flags */);
1109 return fmt->iPixelFormat;
1110 /* This will happen on hwnds without a pixel format set; it's ok */
1115 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1116 void mark_drawable_dirty(Drawable old, Drawable new)
1118 Wine_GLContext *ctx;
1119 LIST_FOR_EACH_ENTRY( ctx, &context_list, struct wine_glcontext, entry )
1121 if (old == ctx->drawables[0]) {
1122 ctx->drawables[0] = new;
1123 ctx->refresh_drawables = TRUE;
1125 if (old == ctx->drawables[1]) {
1126 ctx->drawables[1] = new;
1127 ctx->refresh_drawables = TRUE;
1132 /* Given the current context, make sure its drawable is sync'd */
1133 static inline void sync_context(Wine_GLContext *context)
1135 if(context && context->refresh_drawables) {
1136 if (glxRequireVersion(3))
1137 pglXMakeContextCurrent(gdi_display, context->drawables[0],
1138 context->drawables[1], context->ctx);
1140 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
1141 context->refresh_drawables = FALSE;
1146 static GLXContext create_glxcontext(Display *display, Wine_GLContext *context, GLXContext shareList)
1150 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1151 BOOL indirect = (context->fmt->dwFlags & PFD_DRAW_TO_BITMAP) ? FALSE : TRUE;
1153 if(context->gl3_context)
1155 if(context->numAttribs)
1156 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, context->attribList);
1158 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, NULL);
1160 else if(context->vis)
1161 ctx = pglXCreateContext(gdi_display, context->vis, shareList, indirect);
1162 else /* Create a GLX Context for a pbuffer */
1163 ctx = pglXCreateNewContext(gdi_display, context->fmt->fbconfig, context->fmt->render_type, shareList, TRUE);
1169 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
1171 return pglXCreateGLXPixmap(display, vis, parent);
1176 * glxdrv_ChoosePixelFormat
1178 * Equivalent to glXChooseVisual.
1180 static int glxdrv_ChoosePixelFormat(PHYSDEV dev, const PIXELFORMATDESCRIPTOR *ppfd)
1182 WineGLPixelFormat *list;
1187 int bestFormat = -1;
1188 int bestDBuffer = -1;
1189 int bestStereo = -1;
1193 int bestStencil = -1;
1196 if (!has_opengl()) return 0;
1198 if (TRACE_ON(wgl)) {
1199 TRACE("(%p,%p)\n", dev->hdc, ppfd);
1201 dump_PIXELFORMATDESCRIPTOR(ppfd);
1204 if (!(list = get_formats(gdi_display, NULL, &onscreen_size ))) return 0;
1207 for(i=0; i<onscreen_size; i++)
1211 int alpha=0, color=0, depth=0, stencil=0, aux=0;
1212 WineGLPixelFormat *fmt = &list[i];
1215 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1216 if (value & GLX_RGBA_BIT)
1217 iPixelType = PFD_TYPE_RGBA;
1219 iPixelType = PFD_TYPE_COLORINDEX;
1221 if (ppfd->iPixelType != iPixelType)
1223 TRACE("pixel type mismatch for iPixelFormat=%d\n", i+1);
1227 /* Only use bitmap capable for formats for bitmap rendering.
1228 * See get_formats for more info. */
1229 if( (ppfd->dwFlags & PFD_DRAW_TO_BITMAP) != (fmt->dwFlags & PFD_DRAW_TO_BITMAP))
1231 TRACE("PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i+1);
1235 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1236 if (value) dwFlags |= PFD_DOUBLEBUFFER;
1237 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value);
1238 if (value) dwFlags |= PFD_STEREO;
1239 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &color); /* cColorBits */
1240 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &alpha); /* cAlphaBits */
1241 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &depth); /* cDepthBits */
1242 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &stencil); /* cStencilBits */
1243 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &aux); /* cAuxBuffers */
1245 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1246 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1247 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1248 * formats without the given flag set.
1249 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1250 * has indicated that a format without stereo is returned when stereo is unavailable.
1251 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1252 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1254 * To summarize the following is most likely the correct behavior:
1255 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1256 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1257 * stereo don't care -> it doesn't matter whether we get stereo or not
1259 * In Wine we will treat no-stereo the same way as don't care because it makes
1260 * format selection even more complicated and second drivers with Stereo advertise
1261 * each format twice anyway.
1264 /* Doublebuffer, see the comments above */
1265 if( !(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) ) {
1266 if( ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) &&
1267 ((dwFlags & PFD_DOUBLEBUFFER) == (ppfd->dwFlags & PFD_DOUBLEBUFFER)) )
1270 if(bestDBuffer != -1 && (dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer)
1274 /* Stereo, see the comments above. */
1275 if( !(ppfd->dwFlags & PFD_STEREO_DONTCARE) ) {
1276 if( ((ppfd->dwFlags & PFD_STEREO) != bestStereo) &&
1277 ((dwFlags & PFD_STEREO) == (ppfd->dwFlags & PFD_STEREO)) )
1280 if(bestStereo != -1 && (dwFlags & PFD_STEREO) != bestStereo)
1284 /* Below we will do a number of checks to select the 'best' pixelformat.
1285 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1286 * The code works by trying to match the most important options as close as possible.
1287 * When a reasonable format is found, we will try to match more options.
1288 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1289 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1290 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1292 if(ppfd->cColorBits) {
1293 if( ((ppfd->cColorBits > bestColor) && (color > bestColor)) ||
1294 ((color >= ppfd->cColorBits) && (color < bestColor)) )
1297 if(bestColor != color) { /* Do further checks if the format is compatible */
1298 TRACE("color mismatch for iPixelFormat=%d\n", i+1);
1303 if(ppfd->cAlphaBits) {
1304 if( ((ppfd->cAlphaBits > bestAlpha) && (alpha > bestAlpha)) ||
1305 ((alpha >= ppfd->cAlphaBits) && (alpha < bestAlpha)) )
1308 if(bestAlpha != alpha) {
1309 TRACE("alpha mismatch for iPixelFormat=%d\n", i+1);
1314 if(ppfd->cDepthBits) {
1315 if( ((ppfd->cDepthBits > bestDepth) && (depth > bestDepth)) ||
1316 ((depth >= ppfd->cDepthBits) && (depth < bestDepth)) )
1319 if(bestDepth != depth) {
1320 TRACE("depth mismatch for iPixelFormat=%d\n", i+1);
1325 if(ppfd->cStencilBits) {
1326 if( ((ppfd->cStencilBits > bestStencil) && (stencil > bestStencil)) ||
1327 ((stencil >= ppfd->cStencilBits) && (stencil < bestStencil)) )
1330 if(bestStencil != stencil) {
1331 TRACE("stencil mismatch for iPixelFormat=%d\n", i+1);
1336 if(ppfd->cAuxBuffers) {
1337 if( ((ppfd->cAuxBuffers > bestAux) && (aux > bestAux)) ||
1338 ((aux >= ppfd->cAuxBuffers) && (aux < bestAux)) )
1341 if(bestAux != aux) {
1342 TRACE("aux mismatch for iPixelFormat=%d\n", i+1);
1349 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1350 bestStereo = dwFlags & PFD_STEREO;
1354 bestStencil = stencil;
1359 if(bestFormat == -1) {
1360 TRACE("No matching mode was found returning 0\n");
1364 ret = bestFormat+1; /* the return value should be a 1-based index */
1365 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret, list[bestFormat].fmt_id);
1368 wine_tsx11_unlock();
1374 * glxdrv_DescribePixelFormat
1376 * Get the pixel-format descriptor associated to the given id
1378 static int glxdrv_DescribePixelFormat(PHYSDEV dev, int iPixelFormat,
1379 UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd)
1381 /*XVisualInfo *vis;*/
1384 WineGLPixelFormat *fmt;
1388 if (!has_opengl()) return 0;
1390 TRACE("(%p,%d,%d,%p)\n", dev->hdc, iPixelFormat, nBytes, ppfd);
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 = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_count);
1395 /* The application is only querying the number of pixelformats */
1397 } else if(fmt == NULL) {
1398 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1402 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1403 ERR("Wrong structure size !\n");
1404 /* Should set error */
1410 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1411 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1414 /* These flags are always the same... */
1415 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1416 /* Now the flags extracted from the Visual */
1420 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1421 if(value & GLX_WINDOW_BIT)
1422 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1424 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1425 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1426 * 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
1427 * offered the GDI bit either. */
1428 ppfd->dwFlags |= fmt->dwFlags & (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI);
1430 /* PFD_GENERIC_FORMAT - gdi software rendering
1431 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1432 * none set - full hardware accelerated by a ICD
1434 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1435 ppfd->dwFlags |= fmt->dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED);
1437 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1439 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1440 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1442 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1445 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1446 if (value & GLX_RGBA_BIT)
1447 ppfd->iPixelType = PFD_TYPE_RGBA;
1449 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1452 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1453 ppfd->cColorBits = value;
1455 /* Red, green, blue and alpha bits / shifts */
1456 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1457 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1458 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1459 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1460 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1462 ppfd->cRedBits = rb;
1463 ppfd->cRedShift = gb + bb + ab;
1464 ppfd->cBlueBits = bb;
1465 ppfd->cBlueShift = ab;
1466 ppfd->cGreenBits = gb;
1467 ppfd->cGreenShift = bb + ab;
1468 ppfd->cAlphaBits = ab;
1469 ppfd->cAlphaShift = 0;
1472 ppfd->cRedShift = 0;
1473 ppfd->cBlueBits = 0;
1474 ppfd->cBlueShift = 0;
1475 ppfd->cGreenBits = 0;
1476 ppfd->cGreenShift = 0;
1477 ppfd->cAlphaBits = 0;
1478 ppfd->cAlphaShift = 0;
1481 /* Accum RGBA bits */
1482 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1483 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1484 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1485 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1487 ppfd->cAccumBits = rb+gb+bb+ab;
1488 ppfd->cAccumRedBits = rb;
1489 ppfd->cAccumGreenBits = gb;
1490 ppfd->cAccumBlueBits = bb;
1491 ppfd->cAccumAlphaBits = ab;
1494 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1495 ppfd->cAuxBuffers = value;
1498 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1499 ppfd->cDepthBits = value;
1502 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1503 ppfd->cStencilBits = value;
1505 wine_tsx11_unlock();
1507 ppfd->iLayerType = PFD_MAIN_PLANE;
1509 if (TRACE_ON(wgl)) {
1510 dump_PIXELFORMATDESCRIPTOR(ppfd);
1517 * glxdrv_GetPixelFormat
1519 * Get the pixel-format id used by this DC
1521 static int glxdrv_GetPixelFormat(PHYSDEV dev)
1523 struct glx_physdev *physdev = get_glxdrv_dev( dev );
1524 WineGLPixelFormat *fmt;
1527 if (!physdev->pixel_format) return 0; /* not set yet */
1529 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physdev->pixel_format, TRUE, &tmp);
1532 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physdev->pixel_format);
1535 else if(fmt->offscreenOnly)
1537 /* Offscreen formats can't be used with traditional WGL calls.
1538 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1539 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt->iPixelFormat);
1543 TRACE("(%p): returns %d\n", dev->hdc, physdev->pixel_format);
1544 return physdev->pixel_format;
1547 /* This function is the core of X11DRV_SetPixelFormat and X11DRV_SetPixelFormatWINE.
1548 * Both functions are the same except that X11DRV_SetPixelFormatWINE allows you to
1549 * set the pixel format multiple times. */
1550 static BOOL internal_SetPixelFormat( struct glx_physdev *physdev,
1552 const PIXELFORMATDESCRIPTOR *ppfd)
1554 WineGLPixelFormat *fmt;
1558 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1559 if(physdev->x11dev->drawable == root_window)
1561 ERR("Invalid operation on root_window\n");
1565 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1566 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
1568 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1573 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1574 wine_tsx11_unlock();
1576 hwnd = WindowFromDC(physdev->dev.hdc);
1578 if(!(value&GLX_WINDOW_BIT)) {
1579 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1583 if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, fmt->fmt_id, 0)) {
1584 ERR("Couldn't set format of the window, returning failure\n");
1587 /* physDev->current_pf will be set by the DCE update */
1589 else if(physdev->x11dev->bitmap) {
1590 if(!(value&GLX_PIXMAP_BIT)) {
1591 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat);
1595 physdev->pixel_format = iPixelFormat;
1596 physdev->type = DC_GL_BITMAP;
1599 FIXME("called on a non-window, non-bitmap object?\n");
1602 if (TRACE_ON(wgl)) {
1606 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1608 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1610 TRACE(" FBConfig have :\n");
1611 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1612 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1613 TRACE(" - VISUAL_ID 0x%x\n", value);
1614 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1615 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1617 wine_tsx11_unlock();
1624 * glxdrv_SetPixelFormat
1626 * Set the pixel-format id used by this DC
1628 static BOOL glxdrv_SetPixelFormat(PHYSDEV dev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
1630 struct glx_physdev *physdev = get_glxdrv_dev( dev );
1632 TRACE("(%p,%d,%p)\n", dev->hdc, iPixelFormat, ppfd);
1634 if (!has_opengl()) return FALSE;
1636 if(physdev->pixel_format) /* cannot change it if already set */
1637 return (physdev->pixel_format == iPixelFormat);
1639 return internal_SetPixelFormat(physdev, iPixelFormat, ppfd);
1643 * glxdrv_wglCopyContext
1645 * For OpenGL32 wglCopyContext.
1647 static BOOL glxdrv_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
1649 Wine_GLContext *src = (Wine_GLContext*)hglrcSrc;
1650 Wine_GLContext *dst = (Wine_GLContext*)hglrcDst;
1652 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc, hglrcDst, mask);
1655 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1656 wine_tsx11_unlock();
1658 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1663 * X11DRV_wglCreateContext
1665 * For OpenGL32 wglCreateContext.
1667 static HGLRC glxdrv_wglCreateContext(PHYSDEV dev)
1669 struct glx_physdev *physdev = get_glxdrv_dev( dev );
1670 Wine_GLContext *ret;
1671 WineGLPixelFormat *fmt;
1674 TRACE("(%p)->(PF:%d)\n", dev->hdc, physdev->pixel_format);
1676 if (!has_opengl()) return 0;
1678 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physdev->pixel_format, TRUE /* Offscreen */, &fmt_count);
1679 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1680 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1681 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1682 * If this fails something is very wrong on the system. */
1684 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", physdev->pixel_format);
1685 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1689 if (!(ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret)))) return 0;
1691 ret->hdc = dev->hdc;
1693 ret->has_been_current = FALSE;
1694 ret->sharing = FALSE;
1697 ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1698 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1699 list_add_head( &context_list, &ret->entry );
1700 wine_tsx11_unlock();
1702 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1707 * glxdrv_wglDeleteContext
1709 * For OpenGL32 wglDeleteContext.
1711 static BOOL glxdrv_wglDeleteContext(HGLRC hglrc)
1713 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1715 TRACE("(%p)\n", hglrc);
1717 if (!has_opengl()) return 0;
1719 if (!is_valid_context(ctx))
1721 WARN("Error deleting context !\n");
1722 SetLastError(ERROR_INVALID_HANDLE);
1726 /* WGL doesn't allow deletion of a context which is current in another thread */
1727 if (ctx->tid != 0 && ctx->tid != GetCurrentThreadId())
1729 TRACE("Cannot delete context=%p because it is current in another thread.\n", ctx);
1730 SetLastError(ERROR_BUSY);
1734 /* WGL makes a context not current if it is active before deletion. GLX waits until the context is not current. */
1735 if (ctx == NtCurrentTeb()->glContext)
1736 wglMakeCurrent(ctx->hdc, NULL);
1739 list_remove( &ctx->entry );
1740 if (ctx->ctx) pglXDestroyContext( gdi_display, ctx->ctx );
1741 if (ctx->glxpixmap) pglXDestroyGLXPixmap( gdi_display, ctx->glxpixmap );
1742 if (ctx->pixmap) XFreePixmap( gdi_display, ctx->pixmap );
1743 if (ctx->vis) XFree( ctx->vis );
1744 wine_tsx11_unlock();
1746 HeapFree( GetProcessHeap(), 0, ctx );
1751 * X11DRV_wglGetCurrentReadDCARB
1753 * For OpenGL32 wglGetCurrentReadDCARB.
1755 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1758 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1760 if (ctx) ret = ctx->read_hdc;
1762 TRACE(" returning %p (GL drawable %lu)\n", ret, ctx ? ctx->drawables[1] : 0);
1767 * glxdrv_wglGetProcAddress
1769 * For OpenGL32 wglGetProcAddress.
1771 static PROC glxdrv_wglGetProcAddress(LPCSTR lpszProc)
1774 const WineGLExtension *ext;
1776 int padding = 32 - strlen(lpszProc);
1780 if (!has_opengl()) return NULL;
1782 /* Check the table of WGL extensions to see if we need to return a WGL extension
1783 * or a function pointer to a native OpenGL function. */
1784 if(strncmp(lpszProc, "wgl", 3) != 0) {
1785 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1787 TRACE("('%s'):%*s", lpszProc, padding, " ");
1788 for (i = 0; i < WineGLExtensionListSize; ++i) {
1789 ext = WineGLExtensionList[i];
1790 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1791 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1792 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1793 return ext->extEntryPoints[j].funcAddress;
1799 WARN("(%s) - not found\n", lpszProc);
1803 static GLXPixmap get_context_pixmap( struct glx_physdev *physdev, struct wine_glcontext *ctx )
1809 GetObjectW( GetCurrentObject( physdev->dev.hdc, OBJ_BITMAP ), sizeof(bmp), &bmp );
1812 ctx->pixmap = XCreatePixmap( gdi_display, root_window,
1813 bmp.bmWidth, bmp.bmHeight, ctx->vis->depth );
1814 ctx->glxpixmap = pglXCreateGLXPixmap( gdi_display, ctx->vis, ctx->pixmap );
1815 wine_tsx11_unlock();
1816 ctx->pixmap_size.cx = bmp.bmWidth;
1817 ctx->pixmap_size.cy = bmp.bmHeight;
1819 return ctx->glxpixmap;
1823 * glxdrv_wglMakeCurrent
1825 * For OpenGL32 wglMakeCurrent.
1827 static BOOL glxdrv_wglMakeCurrent(PHYSDEV dev, HGLRC hglrc)
1829 struct glx_physdev *physdev = get_glxdrv_dev( dev );
1831 Wine_GLContext *prev_ctx = NtCurrentTeb()->glContext;
1832 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1834 TRACE("(%p,%p)\n", dev->hdc, hglrc);
1836 if (!has_opengl()) return FALSE;
1840 if (prev_ctx) prev_ctx->tid = 0;
1843 ret = pglXMakeCurrent(gdi_display, None, NULL);
1844 wine_tsx11_unlock();
1845 NtCurrentTeb()->glContext = NULL;
1847 else if (!physdev->pixel_format)
1849 WARN("Trying to use an invalid drawable\n");
1850 SetLastError(ERROR_INVALID_HANDLE);
1853 else if (ctx->fmt->iPixelFormat != physdev->pixel_format)
1855 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1856 dev->hdc, physdev->pixel_format, ctx, ctx->fmt->iPixelFormat );
1857 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1862 Drawable drawable = physdev->drawable;
1864 if (physdev->type == DC_GL_BITMAP) drawable = get_context_pixmap( physdev, ctx );
1868 if (TRACE_ON(wgl)) {
1869 describeDrawable( physdev );
1870 describeContext(ctx);
1873 TRACE(" make current for drawable %lx, ctx %p\n", drawable, ctx->ctx);
1875 ret = pglXMakeCurrent(gdi_display, drawable, ctx->ctx);
1879 if (prev_ctx) prev_ctx->tid = 0;
1880 NtCurrentTeb()->glContext = ctx;
1882 ctx->has_been_current = TRUE;
1883 ctx->tid = GetCurrentThreadId();
1884 ctx->hdc = dev->hdc;
1885 ctx->read_hdc = dev->hdc;
1886 ctx->drawables[0] = drawable;
1887 ctx->drawables[1] = drawable;
1888 ctx->refresh_drawables = FALSE;
1890 if (physdev->type == DC_GL_BITMAP) pglDrawBuffer(GL_FRONT_LEFT);
1893 SetLastError(ERROR_INVALID_HANDLE);
1894 wine_tsx11_unlock();
1896 TRACE(" returning %s\n", (ret ? "True" : "False"));
1901 * glxdrv_wglMakeContextCurrentARB
1903 * For OpenGL32 wglMakeContextCurrentARB
1905 static BOOL glxdrv_wglMakeContextCurrentARB( PHYSDEV draw_dev, PHYSDEV read_dev, HGLRC hglrc )
1907 Wine_GLContext *prev_ctx = NtCurrentTeb()->glContext;
1908 struct glx_physdev *draw_physdev = get_glxdrv_dev( draw_dev );
1909 struct glx_physdev *read_physdev = get_glxdrv_dev( read_dev );
1912 TRACE("(%p,%p,%p)\n", draw_dev->hdc, read_dev->hdc, hglrc);
1914 if (!has_opengl()) return 0;
1918 if (prev_ctx) prev_ctx->tid = 0;
1921 ret = pglXMakeCurrent(gdi_display, None, NULL);
1922 wine_tsx11_unlock();
1923 NtCurrentTeb()->glContext = NULL;
1925 else if (!draw_physdev->pixel_format)
1927 WARN("Trying to use an invalid drawable\n");
1928 SetLastError(ERROR_INVALID_HANDLE);
1933 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1934 Drawable draw_drawable = draw_physdev->drawable;
1935 Drawable read_drawable = read_physdev->drawable;
1937 if (!pglXMakeContextCurrent) return FALSE;
1939 if (draw_physdev->type == DC_GL_BITMAP) draw_drawable = get_context_pixmap( draw_physdev, ctx );
1940 if (read_physdev->type == DC_GL_BITMAP) read_drawable = get_context_pixmap( read_physdev, ctx );
1943 ret = pglXMakeContextCurrent(gdi_display, draw_drawable, read_drawable, ctx->ctx);
1946 if (prev_ctx) prev_ctx->tid = 0;
1948 ctx->has_been_current = TRUE;
1949 ctx->tid = GetCurrentThreadId();
1950 ctx->hdc = draw_dev->hdc;
1951 ctx->read_hdc = read_dev->hdc;
1952 ctx->drawables[0] = draw_drawable;
1953 ctx->drawables[1] = read_drawable;
1954 ctx->refresh_drawables = FALSE;
1955 NtCurrentTeb()->glContext = ctx;
1958 SetLastError(ERROR_INVALID_HANDLE);
1959 wine_tsx11_unlock();
1962 TRACE(" returning %s\n", (ret ? "True" : "False"));
1967 * glxdrv_wglShareLists
1969 * For OpenGL32 wglShareLists.
1971 static BOOL glxdrv_wglShareLists(HGLRC hglrc1, HGLRC hglrc2)
1973 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1974 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1976 TRACE("(%p, %p)\n", org, dest);
1978 if (!has_opengl()) return FALSE;
1980 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1981 * at context creation time but in case of WGL it is done using wglShareLists.
1982 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1983 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1984 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1985 * so there delaying context creation doesn't work.
1987 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1988 * and when a program requests sharing we recreate the destination context if it hasn't been made
1989 * current or when it hasn't shared display lists before.
1992 if((org->has_been_current && dest->has_been_current) || dest->has_been_current)
1994 ERR("Could not share display lists, one of the contexts has been current already !\n");
1997 else if(dest->sharing)
1999 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
2004 if((GetObjectType(org->hdc) == OBJ_MEMDC) ^ (GetObjectType(dest->hdc) == OBJ_MEMDC))
2006 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
2010 describeContext(org);
2011 describeContext(dest);
2013 /* Re-create the GLX context and share display lists */
2014 pglXDestroyContext(gdi_display, dest->ctx);
2015 dest->ctx = create_glxcontext(gdi_display, dest, org->ctx);
2016 wine_tsx11_unlock();
2017 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
2019 org->sharing = TRUE;
2020 dest->sharing = TRUE;
2026 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
2028 /* We are running using client-side rendering fonts... */
2030 unsigned int glyph, size = 0;
2031 void *bitmap = NULL, *gl_bitmap = NULL;
2035 pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
2036 pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
2037 wine_tsx11_unlock();
2039 for (glyph = first; glyph < first + count; glyph++) {
2040 static const MAT2 identity = { {0,1},{0,0},{0,0},{0,1} };
2041 unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, &identity);
2042 unsigned int height, width_int;
2044 TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
2045 if (needed_size == GDI_ERROR) {
2046 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size);
2049 TRACE(" - needed size : %d\n", needed_size);
2052 if (needed_size > size) {
2054 HeapFree(GetProcessHeap(), 0, bitmap);
2055 HeapFree(GetProcessHeap(), 0, gl_bitmap);
2056 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
2057 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
2059 if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, &identity) == GDI_ERROR)
2061 if (TRACE_ON(wgl)) {
2062 unsigned int height, width, bitmask;
2063 unsigned char *bitmap_ = bitmap;
2065 TRACE(" - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
2066 TRACE(" - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
2067 TRACE(" - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
2068 if (needed_size != 0) {
2069 TRACE(" - bitmap :\n");
2070 for (height = 0; height < gm.gmBlackBoxY; height++) {
2072 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
2077 if (*bitmap_ & bitmask)
2082 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
2088 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
2089 * glyph for it to be drawn properly.
2091 if (needed_size != 0) {
2092 width_int = (gm.gmBlackBoxX + 31) / 32;
2093 for (height = 0; height < gm.gmBlackBoxY; height++) {
2095 for (width = 0; width < width_int; width++) {
2096 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
2097 ((int *) bitmap)[height * width_int + width];
2103 pglNewList(listBase++, GL_COMPILE);
2104 if (needed_size != 0) {
2105 pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
2106 0 - gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - gm.gmptGlyphOrigin.y,
2107 gm.gmCellIncX, gm.gmCellIncY,
2110 /* This is the case of 'empty' glyphs like the space character */
2111 pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
2114 wine_tsx11_unlock();
2118 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
2119 wine_tsx11_unlock();
2121 HeapFree(GetProcessHeap(), 0, bitmap);
2122 HeapFree(GetProcessHeap(), 0, gl_bitmap);
2127 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
2128 wine_tsx11_unlock();
2130 HeapFree(GetProcessHeap(), 0, bitmap);
2131 HeapFree(GetProcessHeap(), 0, gl_bitmap);
2136 * glxdrv_wglUseFontBitmapsA
2138 * For OpenGL32 wglUseFontBitmapsA.
2140 static BOOL glxdrv_wglUseFontBitmapsA(PHYSDEV dev, DWORD first, DWORD count, DWORD listBase)
2142 TRACE("(%p, %d, %d, %d)\n", dev->hdc, first, count, listBase);
2144 if (!has_opengl()) return FALSE;
2145 return internal_wglUseFontBitmaps(dev->hdc, first, count, listBase, GetGlyphOutlineA);
2149 * glxdrv_wglUseFontBitmapsW
2151 * For OpenGL32 wglUseFontBitmapsW.
2153 static BOOL glxdrv_wglUseFontBitmapsW(PHYSDEV dev, DWORD first, DWORD count, DWORD listBase)
2155 TRACE("(%p, %d, %d, %d)\n", dev->hdc, first, count, listBase);
2157 if (!has_opengl()) return FALSE;
2158 return internal_wglUseFontBitmaps(dev->hdc, first, count, listBase, GetGlyphOutlineW);
2161 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2162 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params)
2169 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2171 pglGetIntegerv(pname, params);
2173 * if we cannot find a Wine Context
2174 * we only have the default wine desktop context,
2175 * so if we have only a 24 depth say we have 32
2177 if (!ctx && *params == 24) {
2180 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
2185 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2187 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_ALPHA_SIZE, params);
2188 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params);
2192 pglGetIntegerv(pname, params);
2195 wine_tsx11_unlock();
2198 static void flush_pixmap( struct wine_glcontext *ctx )
2200 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
2201 BITMAPINFO *info = (BITMAPINFO *)buffer;
2202 struct gdi_image_bits bits;
2204 if (!get_pixmap_image( ctx->pixmap, ctx->pixmap_size.cx, ctx->pixmap_size.cy, ctx->vis, info, &bits ))
2206 HBITMAP bitmap = GetCurrentObject( ctx->hdc, OBJ_BITMAP );
2207 SetDIBits( 0, bitmap, 0, ctx->pixmap_size.cy, bits.ptr, info, DIB_RGB_COLORS );
2208 if (bits.free) bits.free( &bits );
2212 static void flush_gl_drawable( struct glx_physdev *physdev )
2215 int w = physdev->x11dev->dc_rect.right - physdev->x11dev->dc_rect.left;
2216 int h = physdev->x11dev->dc_rect.bottom - physdev->x11dev->dc_rect.top;
2217 Drawable src = physdev->drawable;
2219 if (w <= 0 || h <= 0) return;
2221 switch (physdev->type)
2223 case DC_GL_PIXMAP_WIN:
2224 src = physdev->pixmap;
2226 case DC_GL_CHILD_WIN:
2227 /* The GL drawable may be lagged behind if we don't flush first, so
2228 * flush the display make sure we copy up-to-date data */
2230 XFlush(gdi_display);
2231 XSetFunction(gdi_display, physdev->x11dev->gc, GXcopy);
2232 XCopyArea(gdi_display, src, physdev->x11dev->drawable, physdev->x11dev->gc, 0, 0, w, h,
2233 physdev->x11dev->dc_rect.left, physdev->x11dev->dc_rect.top);
2234 wine_tsx11_unlock();
2235 SetRect( &rect, 0, 0, w, h );
2236 add_device_bounds( physdev->x11dev, &rect );
2243 static void WINAPI X11DRV_wglFinish(void)
2245 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2246 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2251 wine_tsx11_unlock();
2254 if (ctx->pixmap) flush_pixmap( ctx );
2255 else ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2259 static void WINAPI X11DRV_wglFlush(void)
2261 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2262 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2267 wine_tsx11_unlock();
2270 if (ctx->pixmap) flush_pixmap( ctx );
2271 else ExtEscape( ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2276 * glxdrv_wglCreateContextAttribsARB
2278 * WGL_ARB_create_context: wglCreateContextAttribsARB
2280 static HGLRC glxdrv_wglCreateContextAttribsARB(PHYSDEV dev, HGLRC hShareContext, const int* attribList)
2282 struct glx_physdev *physdev = get_glxdrv_dev( dev );
2283 Wine_GLContext *ret;
2284 WineGLPixelFormat *fmt;
2287 TRACE("(%p %p %p)\n", dev->hdc, hShareContext, attribList);
2289 if (!has_opengl()) return 0;
2291 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physdev->pixel_format, TRUE /* Offscreen */, &fmt_count);
2292 /* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones.
2293 * If this fails something is very wrong on the system. */
2296 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", physdev->pixel_format);
2297 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2301 if (!(ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret)))) return 0;
2303 ret->hdc = dev->hdc;
2305 ret->vis = NULL; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
2306 ret->gl3_context = TRUE;
2308 ret->numAttribs = 0;
2311 int *pAttribList = (int*)attribList;
2312 int *pContextAttribList = &ret->attribList[0];
2313 /* attribList consists of pairs {token, value] terminated with 0 */
2314 while(pAttribList[0] != 0)
2316 TRACE("%#x %#x\n", pAttribList[0], pAttribList[1]);
2317 switch(pAttribList[0])
2319 case WGL_CONTEXT_MAJOR_VERSION_ARB:
2320 pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
2321 pContextAttribList[1] = pAttribList[1];
2323 case WGL_CONTEXT_MINOR_VERSION_ARB:
2324 pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB;
2325 pContextAttribList[1] = pAttribList[1];
2327 case WGL_CONTEXT_LAYER_PLANE_ARB:
2329 case WGL_CONTEXT_FLAGS_ARB:
2330 pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB;
2331 pContextAttribList[1] = pAttribList[1];
2333 case WGL_CONTEXT_PROFILE_MASK_ARB:
2334 pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
2335 pContextAttribList[1] = pAttribList[1];
2338 ERR("Unhandled attribList pair: %#x %#x\n", pAttribList[0], pAttribList[1]);
2343 pContextAttribList += 2;
2348 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
2349 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
2351 XSync(gdi_display, False);
2352 if(X11DRV_check_error() || !ret->ctx)
2354 /* In the future we should convert the GLX error to a win32 one here if needed */
2355 ERR("Context creation failed\n");
2356 HeapFree( GetProcessHeap(), 0, ret );
2357 wine_tsx11_unlock();
2361 list_add_head( &context_list, &ret->entry );
2362 wine_tsx11_unlock();
2363 TRACE(" creating context %p\n", ret);
2368 * X11DRV_wglGetExtensionsStringARB
2370 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2372 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
2373 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2374 return WineGLInfo.wglExtensions;
2378 * X11DRV_wglCreatePbufferARB
2380 * WGL_ARB_pbuffer: wglCreatePbufferARB
2382 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
2384 Wine_GLPBuffer* object = NULL;
2385 WineGLPixelFormat *fmt = NULL;
2390 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2392 if (0 >= iPixelFormat) {
2393 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
2394 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2395 return NULL; /* unexpected error */
2398 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2399 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nCfgs);
2401 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
2402 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2403 goto create_failed; /* unexpected error */
2406 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
2407 if (NULL == object) {
2408 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2409 goto create_failed; /* unexpected error */
2412 object->display = gdi_display;
2413 object->width = iWidth;
2414 object->height = iHeight;
2417 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2418 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2419 while (piAttribList && 0 != *piAttribList) {
2421 switch (*piAttribList) {
2422 case WGL_PBUFFER_LARGEST_ARB: {
2424 attr_v = *piAttribList;
2425 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2426 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2430 case WGL_TEXTURE_FORMAT_ARB: {
2432 attr_v = *piAttribList;
2433 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2434 if (use_render_texture_ati) {
2437 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2438 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
2439 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
2441 SetLastError(ERROR_INVALID_DATA);
2444 object->use_render_texture = 1;
2445 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
2447 if (WGL_NO_TEXTURE_ARB == attr_v) {
2448 object->use_render_texture = 0;
2450 if (!use_render_texture_emulation) {
2451 SetLastError(ERROR_INVALID_DATA);
2455 case WGL_TEXTURE_RGB_ARB:
2456 object->use_render_texture = GL_RGB;
2457 object->texture_bpp = 3;
2458 object->texture_format = GL_RGB;
2459 object->texture_type = GL_UNSIGNED_BYTE;
2461 case WGL_TEXTURE_RGBA_ARB:
2462 object->use_render_texture = GL_RGBA;
2463 object->texture_bpp = 4;
2464 object->texture_format = GL_RGBA;
2465 object->texture_type = GL_UNSIGNED_BYTE;
2468 /* WGL_FLOAT_COMPONENTS_NV */
2469 case WGL_TEXTURE_FLOAT_R_NV:
2470 object->use_render_texture = GL_FLOAT_R_NV;
2471 object->texture_bpp = 4;
2472 object->texture_format = GL_RED;
2473 object->texture_type = GL_FLOAT;
2475 case WGL_TEXTURE_FLOAT_RG_NV:
2476 object->use_render_texture = GL_FLOAT_RG_NV;
2477 object->texture_bpp = 8;
2478 object->texture_format = GL_LUMINANCE_ALPHA;
2479 object->texture_type = GL_FLOAT;
2481 case WGL_TEXTURE_FLOAT_RGB_NV:
2482 object->use_render_texture = GL_FLOAT_RGB_NV;
2483 object->texture_bpp = 12;
2484 object->texture_format = GL_RGB;
2485 object->texture_type = GL_FLOAT;
2487 case WGL_TEXTURE_FLOAT_RGBA_NV:
2488 object->use_render_texture = GL_FLOAT_RGBA_NV;
2489 object->texture_bpp = 16;
2490 object->texture_format = GL_RGBA;
2491 object->texture_type = GL_FLOAT;
2494 ERR("Unknown texture format: %x\n", attr_v);
2495 SetLastError(ERROR_INVALID_DATA);
2503 case WGL_TEXTURE_TARGET_ARB: {
2505 attr_v = *piAttribList;
2506 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2507 if (use_render_texture_ati) {
2510 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2511 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
2512 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
2513 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
2515 SetLastError(ERROR_INVALID_DATA);
2518 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
2520 if (WGL_NO_TEXTURE_ARB == attr_v) {
2521 object->texture_target = 0;
2523 if (!use_render_texture_emulation) {
2524 SetLastError(ERROR_INVALID_DATA);
2528 case WGL_TEXTURE_CUBE_MAP_ARB: {
2529 if (iWidth != iHeight) {
2530 SetLastError(ERROR_INVALID_DATA);
2533 object->texture_target = GL_TEXTURE_CUBE_MAP;
2534 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2537 case WGL_TEXTURE_1D_ARB: {
2539 SetLastError(ERROR_INVALID_DATA);
2542 object->texture_target = GL_TEXTURE_1D;
2543 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2546 case WGL_TEXTURE_2D_ARB: {
2547 object->texture_target = GL_TEXTURE_2D;
2548 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2551 case WGL_TEXTURE_RECTANGLE_NV: {
2552 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2553 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2557 ERR("Unknown texture target: %x\n", attr_v);
2558 SetLastError(ERROR_INVALID_DATA);
2566 case WGL_MIPMAP_TEXTURE_ARB: {
2568 attr_v = *piAttribList;
2569 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2570 if (use_render_texture_ati) {
2571 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
2573 if (!use_render_texture_emulation) {
2574 SetLastError(ERROR_INVALID_DATA);
2584 PUSH1(attribs, None);
2586 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2587 wine_tsx11_unlock();
2588 TRACE("new Pbuffer drawable as %lx\n", object->drawable);
2589 if (!object->drawable) {
2590 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2591 goto create_failed; /* unexpected error */
2593 TRACE("->(%p)\n", object);
2597 HeapFree(GetProcessHeap(), 0, object);
2598 TRACE("->(FAILED)\n");
2603 * X11DRV_wglDestroyPbufferARB
2605 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2607 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2609 Wine_GLPBuffer* object = hPbuffer;
2610 TRACE("(%p)\n", hPbuffer);
2611 if (NULL == object) {
2612 SetLastError(ERROR_INVALID_HANDLE);
2616 pglXDestroyPbuffer(object->display, object->drawable);
2617 wine_tsx11_unlock();
2618 HeapFree(GetProcessHeap(), 0, object);
2623 * X11DRV_wglGetPbufferDCARB
2625 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2627 static HDC WINAPI X11DRV_wglGetPbufferDCARB(HPBUFFERARB hPbuffer)
2629 struct x11drv_escape_set_drawable escape;
2630 Wine_GLPBuffer* object = hPbuffer;
2633 if (NULL == object) {
2634 SetLastError(ERROR_INVALID_HANDLE);
2638 hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
2641 escape.code = X11DRV_SET_DRAWABLE;
2642 escape.drawable = object->drawable;
2643 escape.mode = IncludeInferiors;
2644 SetRect( &escape.drawable_rect, 0, 0, object->width, object->height );
2645 escape.dc_rect = escape.drawable_rect;
2646 escape.fbconfig_id = object->fmt->fmt_id;
2647 escape.gl_drawable = object->drawable;
2649 escape.gl_type = DC_GL_PBUFFER;
2650 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
2652 TRACE( "(%p)->(%p)\n", hPbuffer, hdc );
2657 * X11DRV_wglQueryPbufferARB
2659 * WGL_ARB_pbuffer: wglQueryPbufferARB
2661 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2663 Wine_GLPBuffer* object = hPbuffer;
2664 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2665 if (NULL == object) {
2666 SetLastError(ERROR_INVALID_HANDLE);
2669 switch (iAttribute) {
2670 case WGL_PBUFFER_WIDTH_ARB:
2672 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2673 wine_tsx11_unlock();
2675 case WGL_PBUFFER_HEIGHT_ARB:
2677 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2678 wine_tsx11_unlock();
2681 case WGL_PBUFFER_LOST_ARB:
2682 /* GLX Pbuffers cannot be lost by default. We can support this by
2683 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2684 * to receive pixel buffer clobber events, however that may or may
2685 * not give any benefit */
2686 *piValue = GL_FALSE;
2689 case WGL_TEXTURE_FORMAT_ARB:
2690 if (use_render_texture_ati) {
2692 int type = WGL_NO_TEXTURE_ARB;
2694 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2695 wine_tsx11_unlock();
2697 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2698 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2699 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2703 if (!object->use_render_texture) {
2704 *piValue = WGL_NO_TEXTURE_ARB;
2706 if (!use_render_texture_emulation) {
2707 SetLastError(ERROR_INVALID_HANDLE);
2710 switch(object->use_render_texture) {
2712 *piValue = WGL_TEXTURE_RGB_ARB;
2715 *piValue = WGL_TEXTURE_RGBA_ARB;
2717 /* WGL_FLOAT_COMPONENTS_NV */
2719 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2721 case GL_FLOAT_RG_NV:
2722 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2724 case GL_FLOAT_RGB_NV:
2725 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2727 case GL_FLOAT_RGBA_NV:
2728 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2731 ERR("Unknown texture format: %x\n", object->use_render_texture);
2737 case WGL_TEXTURE_TARGET_ARB:
2738 if (use_render_texture_ati) {
2740 int type = WGL_NO_TEXTURE_ARB;
2742 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2743 wine_tsx11_unlock();
2745 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2746 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2747 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2748 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2752 if (!object->texture_target) {
2753 *piValue = WGL_NO_TEXTURE_ARB;
2755 if (!use_render_texture_emulation) {
2756 SetLastError(ERROR_INVALID_DATA);
2759 switch (object->texture_target) {
2760 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2761 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2762 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2763 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2769 case WGL_MIPMAP_TEXTURE_ARB:
2770 if (use_render_texture_ati) {
2772 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2773 wine_tsx11_unlock();
2775 *piValue = GL_FALSE; /** don't support that */
2776 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2781 FIXME("unexpected attribute %x\n", iAttribute);
2789 * X11DRV_wglReleasePbufferDCARB
2791 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2793 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2795 TRACE("(%p, %p)\n", hPbuffer, hdc);
2796 return DeleteDC(hdc);
2800 * X11DRV_wglSetPbufferAttribARB
2802 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2804 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2806 Wine_GLPBuffer* object = hPbuffer;
2807 GLboolean ret = GL_FALSE;
2809 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2810 if (NULL == object) {
2811 SetLastError(ERROR_INVALID_HANDLE);
2814 if (!object->use_render_texture) {
2815 SetLastError(ERROR_INVALID_HANDLE);
2818 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2821 if (NULL != pglXDrawableAttribATI) {
2822 if (use_render_texture_ati) {
2823 FIXME("Need conversion for GLX_ATI_render_texture\n");
2826 ret = pglXDrawableAttribATI(object->display, object->drawable, piAttribList);
2827 wine_tsx11_unlock();
2833 * X11DRV_wglChoosePixelFormatARB
2835 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2837 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2842 GLXFBConfig* cfgs = NULL;
2846 WineGLPixelFormat *fmt;
2852 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2853 if (NULL != pfAttribFList) {
2854 FIXME("unused pfAttribFList\n");
2857 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2858 if (-1 == nAttribs) {
2859 WARN("Cannot convert WGL to GLX attributes\n");
2862 PUSH1(attribs, None);
2864 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2865 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2866 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2867 for(i=0; piAttribIList[i] != 0; i+=2)
2869 switch(piAttribIList[i])
2871 case WGL_DRAW_TO_BITMAP_ARB:
2872 if(piAttribIList[i+1])
2873 dwFlags |= PFD_DRAW_TO_BITMAP;
2875 case WGL_ACCELERATION_ARB:
2876 switch(piAttribIList[i+1])
2878 case WGL_NO_ACCELERATION_ARB:
2879 dwFlags |= PFD_GENERIC_FORMAT;
2881 case WGL_GENERIC_ACCELERATION_ARB:
2882 dwFlags |= PFD_GENERIC_ACCELERATED;
2884 case WGL_FULL_ACCELERATION_ARB:
2889 case WGL_SUPPORT_GDI_ARB:
2890 if(piAttribIList[i+1])
2891 dwFlags |= PFD_SUPPORT_GDI;
2896 /* Search for FB configurations matching the requirements in attribs */
2898 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2900 wine_tsx11_unlock();
2901 WARN("Compatible Pixel Format not found\n");
2905 /* Loop through all matching formats and check if they are suitable.
2906 * Note that this function should at max return nMaxFormats different formats */
2907 for(run=0; run < 2; run++)
2909 for (it = 0; it < nCfgs; ++it) {
2910 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2912 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2916 /* Search for the format in our list of compatible formats */
2917 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id, dwFlags);
2921 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2922 if( ((run == 0) && fmt->offscreenOnly) || ((run == 1) && !fmt->offscreenOnly) )
2925 if(pfmt_it < nMaxFormats) {
2926 piFormats[pfmt_it] = fmt->iPixelFormat;
2927 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2933 *nNumFormats = pfmt_it;
2936 wine_tsx11_unlock();
2941 * X11DRV_wglGetPixelFormatAttribivARB
2943 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2945 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2948 WineGLPixelFormat *fmt = NULL;
2952 int nWGLFormats = 0;
2954 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2956 if (0 < iLayerPlane) {
2957 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2961 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2962 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2963 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2964 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nWGLFormats);
2966 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2970 for (i = 0; i < nAttributes; ++i) {
2971 const int curWGLAttr = piAttributes[i];
2972 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2974 switch (curWGLAttr) {
2975 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2976 piValues[i] = nWGLFormats;
2979 case WGL_SUPPORT_OPENGL_ARB:
2980 piValues[i] = GL_TRUE;
2983 case WGL_ACCELERATION_ARB:
2984 curGLXAttr = GLX_CONFIG_CAVEAT;
2985 if (!fmt) goto pix_error;
2986 if(fmt->dwFlags & PFD_GENERIC_FORMAT)
2987 piValues[i] = WGL_NO_ACCELERATION_ARB;
2988 else if(fmt->dwFlags & PFD_GENERIC_ACCELERATED)
2989 piValues[i] = WGL_GENERIC_ACCELERATION_ARB;
2991 piValues[i] = WGL_FULL_ACCELERATION_ARB;
2994 case WGL_TRANSPARENT_ARB:
2995 curGLXAttr = GLX_TRANSPARENT_TYPE;
2996 if (!fmt) goto pix_error;
2997 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2998 if (hTest) goto get_error;
2999 piValues[i] = GL_FALSE;
3000 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
3003 case WGL_PIXEL_TYPE_ARB:
3004 curGLXAttr = GLX_RENDER_TYPE;
3005 if (!fmt) goto pix_error;
3006 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
3007 if (hTest) goto get_error;
3008 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
3009 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
3010 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
3011 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
3012 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
3013 else if (tmp & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) { piValues[i] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT; }
3015 ERR("unexpected RenderType(%x)\n", tmp);
3016 piValues[i] = WGL_TYPE_RGBA_ARB;
3020 case WGL_COLOR_BITS_ARB:
3021 curGLXAttr = GLX_BUFFER_SIZE;
3024 case WGL_BIND_TO_TEXTURE_RGB_ARB:
3025 if (use_render_texture_ati) {
3026 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
3029 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
3030 if (use_render_texture_ati) {
3031 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
3034 if (!use_render_texture_emulation) {
3035 piValues[i] = GL_FALSE;
3038 curGLXAttr = GLX_RENDER_TYPE;
3039 if (!fmt) goto pix_error;
3040 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
3041 if (hTest) goto get_error;
3042 if (GLX_COLOR_INDEX_BIT == tmp) {
3043 piValues[i] = GL_FALSE;
3046 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
3047 if (hTest) goto get_error;
3048 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
3051 case WGL_BLUE_BITS_ARB:
3052 curGLXAttr = GLX_BLUE_SIZE;
3054 case WGL_RED_BITS_ARB:
3055 curGLXAttr = GLX_RED_SIZE;
3057 case WGL_GREEN_BITS_ARB:
3058 curGLXAttr = GLX_GREEN_SIZE;
3060 case WGL_ALPHA_BITS_ARB:
3061 curGLXAttr = GLX_ALPHA_SIZE;
3063 case WGL_DEPTH_BITS_ARB:
3064 curGLXAttr = GLX_DEPTH_SIZE;
3066 case WGL_STENCIL_BITS_ARB:
3067 curGLXAttr = GLX_STENCIL_SIZE;
3069 case WGL_DOUBLE_BUFFER_ARB:
3070 curGLXAttr = GLX_DOUBLEBUFFER;
3072 case WGL_STEREO_ARB:
3073 curGLXAttr = GLX_STEREO;
3075 case WGL_AUX_BUFFERS_ARB:
3076 curGLXAttr = GLX_AUX_BUFFERS;
3079 case WGL_SUPPORT_GDI_ARB:
3080 if (!fmt) goto pix_error;
3081 piValues[i] = (fmt->dwFlags & PFD_SUPPORT_GDI) ? TRUE : FALSE;
3084 case WGL_DRAW_TO_BITMAP_ARB:
3085 if (!fmt) goto pix_error;
3086 piValues[i] = (fmt->dwFlags & PFD_DRAW_TO_BITMAP) ? TRUE : FALSE;
3089 case WGL_DRAW_TO_WINDOW_ARB:
3090 case WGL_DRAW_TO_PBUFFER_ARB:
3091 if (!fmt) goto pix_error;
3092 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
3093 if (hTest) goto get_error;
3094 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
3095 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
3096 piValues[i] = GL_TRUE;
3098 piValues[i] = GL_FALSE;
3101 case WGL_SWAP_METHOD_ARB:
3102 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
3103 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
3104 * point only ATI offers this.
3106 piValues[i] = WGL_SWAP_EXCHANGE_ARB;
3109 case WGL_PBUFFER_LARGEST_ARB:
3110 curGLXAttr = GLX_LARGEST_PBUFFER;
3113 case WGL_SAMPLE_BUFFERS_ARB:
3114 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
3117 case WGL_SAMPLES_ARB:
3118 curGLXAttr = GLX_SAMPLES_ARB;
3121 case WGL_FLOAT_COMPONENTS_NV:
3122 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
3125 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
3126 curGLXAttr = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT;
3129 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
3130 curGLXAttr = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
3133 case WGL_ACCUM_RED_BITS_ARB:
3134 curGLXAttr = GLX_ACCUM_RED_SIZE;
3136 case WGL_ACCUM_GREEN_BITS_ARB:
3137 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
3139 case WGL_ACCUM_BLUE_BITS_ARB:
3140 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
3142 case WGL_ACCUM_ALPHA_BITS_ARB:
3143 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
3145 case WGL_ACCUM_BITS_ARB:
3146 if (!fmt) goto pix_error;
3147 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
3148 if (hTest) goto get_error;
3150 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
3151 if (hTest) goto get_error;
3153 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
3154 if (hTest) goto get_error;
3156 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
3157 if (hTest) goto get_error;
3162 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
3165 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
3166 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
3167 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
3169 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
3170 * and check which options can work using iPixelFormat=0 and which not.
3171 * A problem would be that this function is an extension. This would
3172 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
3174 if (0 != curGLXAttr && iPixelFormat != 0) {
3175 if (!fmt) goto pix_error;
3176 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
3177 if (hTest) goto get_error;
3180 piValues[i] = GL_FALSE;
3183 wine_tsx11_unlock();
3187 wine_tsx11_unlock();
3188 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
3192 wine_tsx11_unlock();
3193 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats);
3198 * X11DRV_wglGetPixelFormatAttribfvARB
3200 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
3202 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
3208 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
3210 /* Allocate a temporary array to store integer values */
3211 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
3213 ERR("couldn't allocate %d array\n", nAttributes);
3217 /* Piggy-back on wglGetPixelFormatAttribivARB */
3218 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
3220 /* Convert integer values to float. Should also check for attributes
3221 that can give decimal values here */
3222 for (i=0; i<nAttributes;i++) {
3223 pfValues[i] = attr[i];
3227 HeapFree(GetProcessHeap(), 0, attr);
3232 * X11DRV_wglBindTexImageARB
3234 * WGL_ARB_render_texture: wglBindTexImageARB
3236 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
3238 Wine_GLPBuffer* object = hPbuffer;
3239 GLboolean ret = GL_FALSE;
3241 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
3242 if (NULL == object) {
3243 SetLastError(ERROR_INVALID_HANDLE);
3246 if (!object->use_render_texture) {
3247 SetLastError(ERROR_INVALID_HANDLE);
3251 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
3252 static int init = 0;
3253 int prev_binded_texture = 0;
3254 GLXContext prev_context;
3255 Drawable prev_drawable;
3256 GLXContext tmp_context;
3259 prev_context = pglXGetCurrentContext();
3260 prev_drawable = pglXGetCurrentDrawable();
3262 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
3263 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
3264 isn't ideal performance wise but I wasn't able to get other ways working.
3267 init = 1; /* Only show the FIXME once for performance reasons */
3268 FIXME("partial stub!\n");
3271 TRACE("drawable=%lx, context=%p\n", object->drawable, prev_context);
3272 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
3274 pglGetIntegerv(object->texture_bind_target, &prev_binded_texture);
3276 /* Switch to our pbuffer */
3277 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
3279 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
3280 * After that upload the pbuffer texture data. */
3281 pglBindTexture(object->texture_target, prev_binded_texture);
3282 pglCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
3284 /* Switch back to the original drawable and upload the pbuffer-texture */
3285 pglXMakeCurrent(object->display, prev_drawable, prev_context);
3286 pglXDestroyContext(gdi_display, tmp_context);
3287 wine_tsx11_unlock();
3291 if (NULL != pglXBindTexImageATI) {
3296 case WGL_FRONT_LEFT_ARB:
3297 buffer = GLX_FRONT_LEFT_ATI;
3299 case WGL_FRONT_RIGHT_ARB:
3300 buffer = GLX_FRONT_RIGHT_ATI;
3302 case WGL_BACK_LEFT_ARB:
3303 buffer = GLX_BACK_LEFT_ATI;
3305 case WGL_BACK_RIGHT_ARB:
3306 buffer = GLX_BACK_RIGHT_ATI;
3309 ERR("Unknown iBuffer=%#x\n", iBuffer);
3313 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3314 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3315 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3316 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3317 * works fine using our pbuffer emulation path.
3320 ret = pglXBindTexImageATI(object->display, object->drawable, buffer);
3321 wine_tsx11_unlock();
3327 * X11DRV_wglReleaseTexImageARB
3329 * WGL_ARB_render_texture: wglReleaseTexImageARB
3331 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
3333 Wine_GLPBuffer* object = hPbuffer;
3334 GLboolean ret = GL_FALSE;
3336 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
3337 if (NULL == object) {
3338 SetLastError(ERROR_INVALID_HANDLE);
3341 if (!object->use_render_texture) {
3342 SetLastError(ERROR_INVALID_HANDLE);
3345 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
3348 if (NULL != pglXReleaseTexImageATI) {
3353 case WGL_FRONT_LEFT_ARB:
3354 buffer = GLX_FRONT_LEFT_ATI;
3356 case WGL_FRONT_RIGHT_ARB:
3357 buffer = GLX_FRONT_RIGHT_ATI;
3359 case WGL_BACK_LEFT_ARB:
3360 buffer = GLX_BACK_LEFT_ATI;
3362 case WGL_BACK_RIGHT_ARB:
3363 buffer = GLX_BACK_RIGHT_ATI;
3366 ERR("Unknown iBuffer=%#x\n", iBuffer);
3370 ret = pglXReleaseTexImageATI(object->display, object->drawable, buffer);
3371 wine_tsx11_unlock();
3377 * X11DRV_wglGetExtensionsStringEXT
3379 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3381 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
3382 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
3383 return WineGLInfo.wglExtensions;
3387 * X11DRV_wglGetSwapIntervalEXT
3389 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3391 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
3392 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
3393 * interval, so the swap interval has to be tracked. */
3395 return swap_interval;
3399 * X11DRV_wglSwapIntervalEXT
3401 * WGL_EXT_swap_control: wglSwapIntervalEXT
3403 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
3406 TRACE("(%d)\n", interval);
3410 SetLastError(ERROR_INVALID_DATA);
3413 else if (!has_swap_control && interval == 0)
3415 /* wglSwapIntervalEXT considers an interval value of zero to mean that
3416 * vsync should be disabled, but glXSwapIntervalSGI considers such a
3417 * value to be an error. Just silently ignore the request for now. */
3418 WARN("Request to disable vertical sync is not handled\n");
3423 if (pglXSwapIntervalSGI)
3426 ret = !pglXSwapIntervalSGI(interval);
3427 wine_tsx11_unlock();
3430 WARN("GLX_SGI_swap_control extension is not available\n");
3433 swap_interval = interval;
3435 SetLastError(ERROR_DC_NOT_FOUND);
3442 * X11DRV_wglAllocateMemoryNV
3444 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3446 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
3448 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
3450 if (pglXAllocateMemoryNV)
3453 ret = pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
3454 wine_tsx11_unlock();
3460 * X11DRV_wglFreeMemoryNV
3462 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3464 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
3465 TRACE("(%p)\n", pointer);
3466 if (pglXFreeMemoryNV == NULL)
3470 pglXFreeMemoryNV(pointer);
3471 wine_tsx11_unlock();
3475 * glxdrv_wglSetPixelFormatWINE
3477 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3478 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3480 static BOOL glxdrv_wglSetPixelFormatWINE(PHYSDEV dev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
3482 struct glx_physdev *physdev = get_glxdrv_dev( dev );
3484 TRACE("(%p,%d,%p)\n", dev->hdc, iPixelFormat, ppfd);
3486 if (!has_opengl()) return FALSE;
3488 if (physdev->pixel_format == iPixelFormat) return TRUE;
3490 /* Relay to the core SetPixelFormat */
3491 TRACE("Changing iPixelFormat from %d to %d\n", physdev->pixel_format, iPixelFormat);
3492 return internal_SetPixelFormat(physdev, iPixelFormat, ppfd);
3496 * glxRequireVersion (internal)
3498 * Check if the supported GLX version matches requiredVersion.
3500 static BOOL glxRequireVersion(int requiredVersion)
3502 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3503 if(requiredVersion <= WineGLInfo.glxVersion[1])
3509 static BOOL glxRequireExtension(const char *requiredExtension)
3511 if (strstr(WineGLInfo.glxExtensions, requiredExtension) == NULL) {
3518 static void register_extension_string(const char *ext)
3520 if (WineGLInfo.wglExtensions[0])
3521 strcat(WineGLInfo.wglExtensions, " ");
3522 strcat(WineGLInfo.wglExtensions, ext);
3524 TRACE("'%s'\n", ext);
3527 static BOOL register_extension(const WineGLExtension * ext)
3531 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
3532 WineGLExtensionList[WineGLExtensionListSize++] = ext;
3534 register_extension_string(ext->extName);
3536 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
3537 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
3542 static const WineGLExtension WGL_internal_functions =
3546 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
3547 { "wglFinish", X11DRV_wglFinish },
3548 { "wglFlush", X11DRV_wglFlush },
3553 static const WineGLExtension WGL_ARB_create_context =
3555 "WGL_ARB_create_context",
3557 { "wglCreateContextAttribsARB", (void *)1 /* not called directly */ },
3561 static const WineGLExtension WGL_ARB_extensions_string =
3563 "WGL_ARB_extensions_string",
3565 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
3569 static const WineGLExtension WGL_ARB_make_current_read =
3571 "WGL_ARB_make_current_read",
3573 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
3574 { "wglMakeContextCurrentARB", (void *)1 /* not called directly */ },
3578 static const WineGLExtension WGL_ARB_multisample =
3580 "WGL_ARB_multisample",
3583 static const WineGLExtension WGL_ARB_pbuffer =
3587 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
3588 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
3589 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
3590 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
3591 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
3592 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
3596 static const WineGLExtension WGL_ARB_pixel_format =
3598 "WGL_ARB_pixel_format",
3600 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
3601 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
3602 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
3606 static const WineGLExtension WGL_ARB_render_texture =
3608 "WGL_ARB_render_texture",
3610 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
3611 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
3615 static const WineGLExtension WGL_EXT_extensions_string =
3617 "WGL_EXT_extensions_string",
3619 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
3623 static const WineGLExtension WGL_EXT_swap_control =
3625 "WGL_EXT_swap_control",
3627 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
3628 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
3632 static const WineGLExtension WGL_NV_vertex_array_range =
3634 "WGL_NV_vertex_array_range",
3636 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
3637 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
3641 static const WineGLExtension WGL_WINE_pixel_format_passthrough =
3643 "WGL_WINE_pixel_format_passthrough",
3645 { "wglSetPixelFormatWINE", (void *)1 /* not called directly */ },
3650 * X11DRV_WineGL_LoadExtensions
3652 static void X11DRV_WineGL_LoadExtensions(void)
3654 WineGLInfo.wglExtensions[0] = 0;
3656 /* Load Wine internal functions */
3657 register_extension(&WGL_internal_functions);
3659 /* ARB Extensions */
3661 if(glxRequireExtension("GLX_ARB_create_context"))
3663 register_extension(&WGL_ARB_create_context);
3665 if(glxRequireExtension("GLX_ARB_create_context_profile"))
3666 register_extension_string("WGL_ARB_create_context_profile");
3669 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3671 register_extension_string("WGL_ARB_pixel_format_float");
3672 register_extension_string("WGL_ATI_pixel_format_float");
3675 register_extension(&WGL_ARB_extensions_string);
3677 if (glxRequireVersion(3))
3678 register_extension(&WGL_ARB_make_current_read);
3680 if (glxRequireExtension("GLX_ARB_multisample"))
3681 register_extension(&WGL_ARB_multisample);
3683 /* In general pbuffer functionality requires support in the X-server. The functionality is
3684 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3685 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3686 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3688 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3689 * without support in the X-server (which other Mesa based drivers require).
3691 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3692 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3693 * is available pbuffers must be available too. */
3694 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3695 register_extension(&WGL_ARB_pbuffer);
3697 register_extension(&WGL_ARB_pixel_format);
3699 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3700 if (glxRequireExtension("GLX_ATI_render_texture") ||
3701 glxRequireExtension("GLX_ARB_render_texture") ||
3702 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation))
3704 register_extension(&WGL_ARB_render_texture);
3706 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3707 if(glxRequireExtension("GLX_NV_float_buffer"))
3708 register_extension_string("WGL_NV_float_buffer");
3710 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3711 if(strstr(WineGLInfo.glExtensions, "GL_NV_texture_rectangle") != NULL)
3712 register_extension_string("WGL_NV_texture_rectangle");
3715 /* EXT Extensions */
3717 register_extension(&WGL_EXT_extensions_string);
3719 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3720 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3721 register_extension(&WGL_EXT_swap_control);
3723 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3724 register_extension_string("WGL_EXT_framebuffer_sRGB");
3726 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3727 register_extension_string("WGL_EXT_pixel_format_packed_float");
3729 if (glxRequireExtension("GLX_EXT_swap_control"))
3730 has_swap_control = TRUE;
3732 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3733 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
3734 register_extension(&WGL_NV_vertex_array_range);
3736 /* WINE-specific WGL Extensions */
3738 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3739 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3741 register_extension(&WGL_WINE_pixel_format_passthrough);
3745 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3748 pglXDestroyGLXPixmap(display, glxpixmap);
3749 wine_tsx11_unlock();
3754 * glxdrv_SwapBuffers
3756 * Swap the buffers of this DC
3758 static BOOL glxdrv_SwapBuffers(PHYSDEV dev)
3760 struct glx_physdev *physdev = get_glxdrv_dev( dev );
3761 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
3763 if (!has_opengl()) return FALSE;
3765 TRACE("(%p)\n", dev->hdc);
3769 WARN("Using a NULL context, skipping\n");
3770 SetLastError(ERROR_INVALID_HANDLE);
3774 if (!physdev->drawable)
3776 WARN("Using an invalid drawable, skipping\n");
3777 SetLastError(ERROR_INVALID_HANDLE);
3783 switch (physdev->type)
3785 case DC_GL_PIXMAP_WIN:
3786 if(pglXCopySubBufferMESA) {
3787 int w = physdev->x11dev->dc_rect.right - physdev->x11dev->dc_rect.left;
3788 int h = physdev->x11dev->dc_rect.bottom - physdev->x11dev->dc_rect.top;
3790 /* (glX)SwapBuffers has an implicit glFlush effect, however
3791 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3795 pglXCopySubBufferMESA(gdi_display, physdev->drawable, 0, 0, w, h);
3800 pglXSwapBuffers(gdi_display, physdev->drawable);
3804 flush_gl_drawable( physdev );
3805 wine_tsx11_unlock();
3810 static long prev_time, start_time;
3811 static unsigned long frames, frames_total;
3813 DWORD time = GetTickCount();
3816 /* every 1.5 seconds */
3817 if (time - prev_time > 1500) {
3818 TRACE_(fps)("@ approx %.2ffps, total %.2ffps\n",
3819 1000.0*frames/(time - prev_time), 1000.0*frames_total/(time - start_time));
3822 if(start_time == 0) start_time = time;
3829 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3831 WineGLPixelFormat *fmt;
3834 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id, 0 /* no flags */);
3839 ret = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
3840 wine_tsx11_unlock();
3844 static BOOL create_glx_dc( PHYSDEV *pdev )
3846 /* assume that only the main x11 device implements GetDeviceCaps */
3847 X11DRV_PDEVICE *x11dev = get_x11drv_dev( GET_NEXT_PHYSDEV( *pdev, pGetDeviceCaps ));
3848 struct glx_physdev *physdev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physdev) );
3850 if (!physdev) return FALSE;
3851 physdev->x11dev = x11dev;
3852 push_dc_driver( pdev, &physdev->dev, &glxdrv_funcs );
3856 /**********************************************************************
3859 static BOOL glxdrv_CreateDC( PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device,
3860 LPCWSTR output, const DEVMODEW* initData )
3862 return create_glx_dc( pdev );
3865 /**********************************************************************
3866 * glxdrv_CreateCompatibleDC
3868 static BOOL glxdrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
3870 if (orig) /* chain to next driver first */
3872 orig = GET_NEXT_PHYSDEV( orig, pCreateCompatibleDC );
3873 if (!orig->funcs->pCreateCompatibleDC( orig, pdev )) return FALSE;
3875 /* otherwise we have been called by x11drv */
3876 return create_glx_dc( pdev );
3879 /**********************************************************************
3882 static BOOL glxdrv_DeleteDC( PHYSDEV dev )
3884 struct glx_physdev *physdev = get_glxdrv_dev( dev );
3885 HeapFree( GetProcessHeap(), 0, physdev );
3889 /**********************************************************************
3892 static INT glxdrv_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
3893 INT out_count, LPVOID out_data )
3895 struct glx_physdev *physdev = get_glxdrv_dev( dev );
3897 dev = GET_NEXT_PHYSDEV( dev, pExtEscape );
3899 if (escape == X11DRV_ESCAPE && in_data && in_count >= sizeof(enum x11drv_escape_codes))
3901 switch (*(const enum x11drv_escape_codes *)in_data)
3903 case X11DRV_SET_DRAWABLE:
3904 if (in_count >= sizeof(struct x11drv_escape_set_drawable))
3906 const struct x11drv_escape_set_drawable *data = in_data;
3907 physdev->pixel_format = pixelformat_from_fbconfig_id( data->fbconfig_id );
3908 physdev->type = data->gl_type;
3909 physdev->drawable = data->gl_drawable;
3910 physdev->pixmap = data->pixmap;
3911 TRACE( "SET_DRAWABLE hdc %p drawable %lx pf %u type %u\n",
3912 dev->hdc, physdev->drawable, physdev->pixel_format, physdev->type );
3915 case X11DRV_FLUSH_GL_DRAWABLE:
3916 flush_gl_drawable( physdev );
3922 return dev->funcs->pExtEscape( dev, escape, in_count, in_data, out_count, out_data );
3925 static const struct gdi_dc_funcs glxdrv_funcs =
3927 NULL, /* pAbortDoc */
3928 NULL, /* pAbortPath */
3929 NULL, /* pAlphaBlend */
3930 NULL, /* pAngleArc */
3933 NULL, /* pBeginPath */
3934 NULL, /* pBlendImage */
3935 glxdrv_ChoosePixelFormat, /* pChoosePixelFormat */
3937 NULL, /* pCloseFigure */
3938 NULL, /* pCopyBitmap */
3939 NULL, /* pCreateBitmap */
3940 glxdrv_CreateCompatibleDC, /* pCreateCompatibleDC */
3941 glxdrv_CreateDC, /* pCreateDC */
3942 NULL, /* pDeleteBitmap */
3943 glxdrv_DeleteDC, /* pDeleteDC */
3944 NULL, /* pDeleteObject */
3945 glxdrv_DescribePixelFormat, /* pDescribePixelFormat */
3946 NULL, /* pDeviceCapabilities */
3947 NULL, /* pEllipse */
3949 NULL, /* pEndPage */
3950 NULL, /* pEndPath */
3951 NULL, /* pEnumFonts */
3952 NULL, /* pEnumICMProfiles */
3953 NULL, /* pExcludeClipRect */
3954 NULL, /* pExtDeviceMode */
3955 glxdrv_ExtEscape, /* pExtEscape */
3956 NULL, /* pExtFloodFill */
3957 NULL, /* pExtSelectClipRgn */
3958 NULL, /* pExtTextOut */
3959 NULL, /* pFillPath */
3960 NULL, /* pFillRgn */
3961 NULL, /* pFlattenPath */
3962 NULL, /* pFontIsLinked */
3963 NULL, /* pFrameRgn */
3964 NULL, /* pGdiComment */
3965 NULL, /* pGdiRealizationInfo */
3966 NULL, /* pGetBoundsRect */
3967 NULL, /* pGetCharABCWidths */
3968 NULL, /* pGetCharABCWidthsI */
3969 NULL, /* pGetCharWidth */
3970 NULL, /* pGetDeviceCaps */
3971 NULL, /* pGetDeviceGammaRamp */
3972 NULL, /* pGetFontData */
3973 NULL, /* pGetFontUnicodeRanges */
3974 NULL, /* pGetGlyphIndices */
3975 NULL, /* pGetGlyphOutline */
3976 NULL, /* pGetICMProfile */
3977 NULL, /* pGetImage */
3978 NULL, /* pGetKerningPairs */
3979 NULL, /* pGetNearestColor */
3980 NULL, /* pGetOutlineTextMetrics */
3981 NULL, /* pGetPixel */
3982 glxdrv_GetPixelFormat, /* pGetPixelFormat */
3983 NULL, /* pGetSystemPaletteEntries */
3984 NULL, /* pGetTextCharsetInfo */
3985 NULL, /* pGetTextExtentExPoint */
3986 NULL, /* pGetTextExtentExPointI */
3987 NULL, /* pGetTextFace */
3988 NULL, /* pGetTextMetrics */
3989 NULL, /* pGradientFill */
3990 NULL, /* pIntersectClipRect */
3991 NULL, /* pInvertRgn */
3993 NULL, /* pModifyWorldTransform */
3995 NULL, /* pOffsetClipRgn */
3996 NULL, /* pOffsetViewportOrg */
3997 NULL, /* pOffsetWindowOrg */
3998 NULL, /* pPaintRgn */
4001 NULL, /* pPolyBezier */
4002 NULL, /* pPolyBezierTo */
4003 NULL, /* pPolyDraw */
4004 NULL, /* pPolyPolygon */
4005 NULL, /* pPolyPolyline */
4006 NULL, /* pPolygon */
4007 NULL, /* pPolyline */
4008 NULL, /* pPolylineTo */
4009 NULL, /* pPutImage */
4010 NULL, /* pRealizeDefaultPalette */
4011 NULL, /* pRealizePalette */
4012 NULL, /* pRectangle */
4013 NULL, /* pResetDC */
4014 NULL, /* pRestoreDC */
4015 NULL, /* pRoundRect */
4017 NULL, /* pScaleViewportExt */
4018 NULL, /* pScaleWindowExt */
4019 NULL, /* pSelectBitmap */
4020 NULL, /* pSelectBrush */
4021 NULL, /* pSelectClipPath */
4022 NULL, /* pSelectFont */
4023 NULL, /* pSelectPalette */
4024 NULL, /* pSelectPen */
4025 NULL, /* pSetArcDirection */
4026 NULL, /* pSetBkColor */
4027 NULL, /* pSetBkMode */
4028 NULL, /* pSetBoundsRect */
4029 NULL, /* pSetDCBrushColor */
4030 NULL, /* pSetDCPenColor */
4031 NULL, /* pSetDIBitsToDevice */
4032 NULL, /* pSetDeviceClipping */
4033 NULL, /* pSetDeviceGammaRamp */
4034 NULL, /* pSetLayout */
4035 NULL, /* pSetMapMode */
4036 NULL, /* pSetMapperFlags */
4037 NULL, /* pSetPixel */
4038 glxdrv_SetPixelFormat, /* pSetPixelFormat */
4039 NULL, /* pSetPolyFillMode */
4040 NULL, /* pSetROP2 */
4041 NULL, /* pSetRelAbs */
4042 NULL, /* pSetStretchBltMode */
4043 NULL, /* pSetTextAlign */
4044 NULL, /* pSetTextCharacterExtra */
4045 NULL, /* pSetTextColor */
4046 NULL, /* pSetTextJustification */
4047 NULL, /* pSetViewportExt */
4048 NULL, /* pSetViewportOrg */
4049 NULL, /* pSetWindowExt */
4050 NULL, /* pSetWindowOrg */
4051 NULL, /* pSetWorldTransform */
4052 NULL, /* pStartDoc */
4053 NULL, /* pStartPage */
4054 NULL, /* pStretchBlt */
4055 NULL, /* pStretchDIBits */
4056 NULL, /* pStrokeAndFillPath */
4057 NULL, /* pStrokePath */
4058 glxdrv_SwapBuffers, /* pSwapBuffers */
4059 NULL, /* pUnrealizePalette */
4060 NULL, /* pWidenPath */
4061 glxdrv_wglCopyContext, /* pwglCopyContext */
4062 glxdrv_wglCreateContext, /* pwglCreateContext */
4063 glxdrv_wglCreateContextAttribsARB, /* pwglCreateContextAttribsARB */
4064 glxdrv_wglDeleteContext, /* pwglDeleteContext */
4065 glxdrv_wglGetProcAddress, /* pwglGetProcAddress */
4066 glxdrv_wglMakeContextCurrentARB, /* pwglMakeContextCurrentARB */
4067 glxdrv_wglMakeCurrent, /* pwglMakeCurrent */
4068 glxdrv_wglSetPixelFormatWINE, /* pwglSetPixelFormatWINE */
4069 glxdrv_wglShareLists, /* pwglShareLists */
4070 glxdrv_wglUseFontBitmapsA, /* pwglUseFontBitmapsA */
4071 glxdrv_wglUseFontBitmapsW, /* pwglUseFontBitmapsW */
4072 GDI_PRIORITY_GRAPHICS_DRV + 20 /* priority */
4075 const struct gdi_dc_funcs *get_glx_driver(void)
4077 return &glxdrv_funcs;
4080 #else /* no OpenGL includes */
4082 const struct gdi_dc_funcs *get_glx_driver(void)
4087 void mark_drawable_dirty(Drawable old, Drawable new)
4091 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
4097 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
4102 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
4107 #endif /* defined(SONAME_LIBGL) */