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);
45 WINE_DECLARE_DEBUG_CHANNEL(winediag);
66 /* Redefines the constants */
67 #define CALLBACK __stdcall
68 #define WINAPI __stdcall
69 #define APIENTRY WINAPI
72 WINE_DECLARE_DEBUG_CHANNEL(fps);
74 typedef struct wine_glextension {
83 const char *glVersion;
88 const char *glxServerVersion;
89 const char *glxServerVendor;
90 const char *glxServerExtensions;
92 const char *glxClientVersion;
93 const char *glxClientVendor;
94 const char *glxClientExtensions;
96 const char *glxExtensions;
99 char wglExtensions[4096];
102 typedef struct wine_glpixelformat {
104 GLXFBConfig fbconfig;
108 DWORD dwFlags; /* We store some PFD_* flags in here for emulated bitmap formats */
111 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 struct wine_glcontext *next;
127 struct wine_glcontext *prev;
130 typedef struct wine_glpbuffer {
133 WineGLPixelFormat* fmt;
139 int use_render_texture; /* This is also the internal texture format */
140 int texture_bind_target;
142 GLint texture_format;
143 GLuint texture_target;
149 static Wine_GLContext *context_list;
150 static struct WineGLInfo WineGLInfo = { 0 };
151 static int use_render_texture_emulation = 1;
152 static int use_render_texture_ati = 0;
153 static int swap_interval = 1;
155 #define MAX_EXTENSIONS 16
156 static const WineGLExtension *WineGLExtensionList[MAX_EXTENSIONS];
157 static int WineGLExtensionListSize;
159 static void X11DRV_WineGL_LoadExtensions(void);
160 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count);
161 static BOOL glxRequireVersion(int requiredVersion);
162 static BOOL glxRequireExtension(const char *requiredExtension);
164 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
165 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
166 TRACE(" - dwFlags : ");
167 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
168 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
169 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
170 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
171 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
172 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
173 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
174 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
175 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
176 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
177 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
178 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
179 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
180 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
181 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
182 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
183 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
184 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
185 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
186 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
190 TRACE(" - iPixelType : ");
191 switch (ppfd->iPixelType) {
192 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
193 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
197 TRACE(" - Color : %d\n", ppfd->cColorBits);
198 TRACE(" - Red : %d\n", ppfd->cRedBits);
199 TRACE(" - Green : %d\n", ppfd->cGreenBits);
200 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
201 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
202 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
203 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
204 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
205 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
207 TRACE(" - iLayerType : ");
208 switch (ppfd->iLayerType) {
209 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
210 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
211 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
216 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
217 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
219 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
221 MAKE_FUNCPTR(glXChooseVisual)
222 MAKE_FUNCPTR(glXCopyContext)
223 MAKE_FUNCPTR(glXCreateContext)
224 MAKE_FUNCPTR(glXCreateGLXPixmap)
225 MAKE_FUNCPTR(glXGetCurrentContext)
226 MAKE_FUNCPTR(glXGetCurrentDrawable)
227 MAKE_FUNCPTR(glXDestroyContext)
228 MAKE_FUNCPTR(glXDestroyGLXPixmap)
229 MAKE_FUNCPTR(glXGetConfig)
230 MAKE_FUNCPTR(glXIsDirect)
231 MAKE_FUNCPTR(glXMakeCurrent)
232 MAKE_FUNCPTR(glXSwapBuffers)
233 MAKE_FUNCPTR(glXQueryExtension)
234 MAKE_FUNCPTR(glXQueryVersion)
235 MAKE_FUNCPTR(glXUseXFont)
238 MAKE_FUNCPTR(glXGetClientString)
239 MAKE_FUNCPTR(glXQueryExtensionsString)
240 MAKE_FUNCPTR(glXQueryServerString)
243 MAKE_FUNCPTR(glXGetFBConfigs)
244 MAKE_FUNCPTR(glXChooseFBConfig)
245 MAKE_FUNCPTR(glXCreatePbuffer)
246 MAKE_FUNCPTR(glXCreateNewContext)
247 MAKE_FUNCPTR(glXDestroyPbuffer)
248 MAKE_FUNCPTR(glXGetFBConfigAttrib)
249 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
250 MAKE_FUNCPTR(glXMakeContextCurrent)
251 MAKE_FUNCPTR(glXQueryDrawable)
252 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
255 static GLXContext (*pglXCreateContextAttribsARB)(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
256 static void* (*pglXGetProcAddressARB)(const GLubyte *);
257 static int (*pglXSwapIntervalSGI)(int);
259 /* ATI GLX Extensions */
260 static BOOL (*pglXBindTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
261 static BOOL (*pglXReleaseTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
262 static BOOL (*pglXDrawableAttribATI)(Display *dpy, GLXDrawable draw, const int *attribList);
264 /* NV GLX Extension */
265 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
266 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
268 /* MESA GLX Extensions */
269 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
271 /* Standard OpenGL */
272 MAKE_FUNCPTR(glBindTexture)
273 MAKE_FUNCPTR(glBitmap)
274 MAKE_FUNCPTR(glCopyTexSubImage1D)
275 MAKE_FUNCPTR(glCopyTexImage2D)
276 MAKE_FUNCPTR(glCopyTexSubImage2D)
277 MAKE_FUNCPTR(glDrawBuffer)
278 MAKE_FUNCPTR(glEndList)
279 MAKE_FUNCPTR(glGetError)
280 MAKE_FUNCPTR(glGetIntegerv)
281 MAKE_FUNCPTR(glGetString)
282 MAKE_FUNCPTR(glNewList)
283 MAKE_FUNCPTR(glPixelStorei)
284 MAKE_FUNCPTR(glReadPixels)
285 MAKE_FUNCPTR(glTexImage2D)
286 MAKE_FUNCPTR(glFinish)
287 MAKE_FUNCPTR(glFlush)
290 static int GLXErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
292 /* In the future we might want to find the exact X or GLX error to report back to the app */
296 static BOOL infoInitialized = FALSE;
297 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
299 int screen = DefaultScreen(gdi_display);
300 Window win = 0, root = 0;
303 GLXContext ctx = NULL;
304 XSetWindowAttributes attr;
306 int attribList[] = {GLX_RGBA, GLX_DOUBLEBUFFER, None};
310 infoInitialized = TRUE;
312 attr.override_redirect = True;
313 attr.colormap = None;
314 attr.border_pixel = 0;
318 vis = pglXChooseVisual(gdi_display, screen, attribList);
321 WORD old_fs = wine_get_fs();
322 /* Create a GLX Context. Without one we can't query GL information */
323 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
324 if (wine_get_fs() != old_fs)
326 wine_set_fs( old_fs );
327 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
328 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
332 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
337 root = RootWindow( gdi_display, vis->screen );
338 if (vis->visual != DefaultVisual( gdi_display, vis->screen ))
339 attr.colormap = XCreateColormap( gdi_display, root, vis->visual, AllocNone );
340 if ((win = XCreateWindow( gdi_display, root, -1, -1, 1, 1, 0, vis->depth, InputOutput,
341 vis->visual, CWBorderPixel | CWOverrideRedirect | CWColormap, &attr )))
342 XMapWindow( gdi_display, win );
346 pglXMakeCurrent(gdi_display, win, ctx);
348 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
349 str = (const char *) pglGetString(GL_EXTENSIONS);
350 WineGLInfo.glExtensions = HeapAlloc(GetProcessHeap(), 0, strlen(str)+1);
351 strcpy(WineGLInfo.glExtensions, str);
353 /* Get the common GLX version supported by GLX client and server ( major/minor) */
354 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
356 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
357 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
358 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
360 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
361 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
362 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
364 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
365 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
367 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
368 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER));
369 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
370 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
371 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
372 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
373 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
374 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
376 if(!WineGLInfo.glxDirect)
378 int fd = ConnectionNumber(gdi_display);
379 struct sockaddr_un uaddr;
380 unsigned int uaddrlen = sizeof(struct sockaddr_un);
382 /* In general indirect rendering on a local X11 server indicates a driver problem.
383 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
385 if(!getsockname(fd, (struct sockaddr *)&uaddr, &uaddrlen) && uaddr.sun_family == AF_UNIX)
386 ERR_(winediag)("Direct rendering is disabled, most likely your OpenGL drivers haven't been installed correctly\n");
390 /* In general you would expect that if direct rendering is returned, that you receive hardware
391 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
392 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
393 * software rendering, it shows direct rendering.
395 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
396 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
397 * it shows 'Mesa X11'.
399 const char *gl_renderer = (const char *)pglGetString(GL_RENDERER);
400 if(!strcmp(gl_renderer, "Software Rasterizer") || !strcmp(gl_renderer, "Mesa X11"))
401 ERR_(winediag)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL drivers haven't been installed correctly\n");
408 pglXMakeCurrent(gdi_display, None, NULL);
409 pglXDestroyContext(gdi_display, ctx);
411 if (win != root) XDestroyWindow( gdi_display, win );
412 if (attr.colormap) XFreeColormap( gdi_display, attr.colormap );
414 if (!ret) ERR(" couldn't initialize OpenGL, expect problems\n");
418 void X11DRV_OpenGL_Cleanup(void)
420 HeapFree(GetProcessHeap(), 0, WineGLInfo.glExtensions);
421 infoInitialized = FALSE;
424 static BOOL has_opengl(void)
426 static int init_done;
427 static void *opengl_handle;
430 int error_base, event_base;
432 if (init_done) return (opengl_handle != NULL);
435 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
436 and include all dependencies */
437 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, buffer, sizeof(buffer));
438 if (opengl_handle == NULL)
440 ERR( "Failed to load libGL: %s\n", buffer );
441 ERR( "OpenGL support is disabled.\n");
445 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
446 if (pglXGetProcAddressARB == NULL) {
447 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
451 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
453 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
458 LOAD_FUNCPTR(glXChooseVisual);
459 LOAD_FUNCPTR(glXCopyContext);
460 LOAD_FUNCPTR(glXCreateContext);
461 LOAD_FUNCPTR(glXCreateGLXPixmap);
462 LOAD_FUNCPTR(glXGetCurrentContext);
463 LOAD_FUNCPTR(glXGetCurrentDrawable);
464 LOAD_FUNCPTR(glXDestroyContext);
465 LOAD_FUNCPTR(glXDestroyGLXPixmap);
466 LOAD_FUNCPTR(glXGetConfig);
467 LOAD_FUNCPTR(glXIsDirect);
468 LOAD_FUNCPTR(glXMakeCurrent);
469 LOAD_FUNCPTR(glXSwapBuffers);
470 LOAD_FUNCPTR(glXQueryExtension);
471 LOAD_FUNCPTR(glXQueryVersion);
472 LOAD_FUNCPTR(glXUseXFont);
475 LOAD_FUNCPTR(glXGetClientString);
476 LOAD_FUNCPTR(glXQueryExtensionsString);
477 LOAD_FUNCPTR(glXQueryServerString);
480 LOAD_FUNCPTR(glXCreatePbuffer);
481 LOAD_FUNCPTR(glXCreateNewContext);
482 LOAD_FUNCPTR(glXDestroyPbuffer);
483 LOAD_FUNCPTR(glXMakeContextCurrent);
484 LOAD_FUNCPTR(glXGetCurrentReadDrawable);
485 LOAD_FUNCPTR(glXGetFBConfigs);
487 /* Standard OpenGL calls */
488 LOAD_FUNCPTR(glBindTexture);
489 LOAD_FUNCPTR(glBitmap);
490 LOAD_FUNCPTR(glCopyTexSubImage1D);
491 LOAD_FUNCPTR(glCopyTexImage2D);
492 LOAD_FUNCPTR(glCopyTexSubImage2D);
493 LOAD_FUNCPTR(glDrawBuffer);
494 LOAD_FUNCPTR(glEndList);
495 LOAD_FUNCPTR(glGetError);
496 LOAD_FUNCPTR(glGetIntegerv);
497 LOAD_FUNCPTR(glGetString);
498 LOAD_FUNCPTR(glNewList);
499 LOAD_FUNCPTR(glPixelStorei);
500 LOAD_FUNCPTR(glReadPixels);
501 LOAD_FUNCPTR(glTexImage2D);
502 LOAD_FUNCPTR(glFinish);
503 LOAD_FUNCPTR(glFlush);
506 /* It doesn't matter if these fail. They'll only be used if the driver reports
507 the associated extension is available (and if a driver reports the extension
508 is available but fails to provide the functions, it's quite broken) */
509 #define LOAD_FUNCPTR(f) p##f = pglXGetProcAddressARB((const GLubyte *)#f)
510 /* ARB GLX Extension */
511 LOAD_FUNCPTR(glXCreateContextAttribsARB);
512 /* SGI GLX Extension */
513 LOAD_FUNCPTR(glXSwapIntervalSGI);
514 /* NV GLX Extension */
515 LOAD_FUNCPTR(glXAllocateMemoryNV);
516 LOAD_FUNCPTR(glXFreeMemoryNV);
519 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed;
522 if (pglXQueryExtension(gdi_display, &error_base, &event_base)) {
523 TRACE("GLX is up and running error_base = %d\n", error_base);
526 ERR( "GLX extension is missing, disabling OpenGL.\n" );
530 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
531 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
534 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
535 * depends on the reported GLX client / server version and on the client / server extension list.
536 * Those don't have to be the same.
538 * In general the server GLX information lists the capabilities in case of indirect rendering.
539 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
540 * available and in that case the client GLX informat can be used.
541 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
542 * in the GLX version/extension list. When a program does this it works for certain for both
543 * direct and indirect rendering.
545 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
546 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
547 * extension list which causes this extension not to be listed. (Wine requires this extension).
548 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
549 * pbuffers is around.
551 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
552 * the ATI drivers and from then on use GLX client information for them.
555 if(glxRequireVersion(3)) {
556 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
557 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
558 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
559 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
560 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
561 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
562 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
563 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
565 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
566 * enable this function when the Xserver understand GLX 1.3 or newer
568 pglXQueryDrawable = NULL;
569 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
570 TRACE("Overriding ATI GLX capabilities!\n");
571 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
572 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
573 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
574 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
576 /* Use client GLX information in case of the ATI drivers. We override the
577 * capabilities over here and not somewhere else as ATI might better their
578 * life in the future. In case they release proper drivers this block of
579 * code won't be called. */
580 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
582 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
585 if(glxRequireExtension("GLX_ATI_render_texture")) {
586 use_render_texture_ati = 1;
587 pglXBindTexImageATI = pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageATI");
588 pglXReleaseTexImageATI = pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageATI");
589 pglXDrawableAttribATI = pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribATI");
592 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
593 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
596 X11DRV_WineGL_LoadExtensions();
602 wine_dlclose(opengl_handle, NULL, 0);
603 opengl_handle = NULL;
607 static inline Wine_GLContext *alloc_context(void)
611 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLContext))))
613 ret->next = context_list;
614 if (context_list) context_list->prev = ret;
620 static inline void free_context(Wine_GLContext *context)
622 if (context->next != NULL) context->next->prev = context->prev;
623 if (context->prev != NULL) context->prev->next = context->next;
624 else context_list = context->next;
626 if (context->vis) XFree(context->vis);
627 HeapFree(GetProcessHeap(), 0, context);
630 static inline BOOL is_valid_context( Wine_GLContext *ctx )
633 for (ptr = context_list; ptr; ptr = ptr->next) if (ptr == ctx) break;
634 return (ptr != NULL);
637 static int describeContext(Wine_GLContext* ctx) {
640 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
641 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
642 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
643 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
644 TRACE(" - VISUAL_ID 0x%x\n", tmp);
649 static BOOL describeDrawable(X11DRV_PDEVICE *physDev) {
651 WineGLPixelFormat *fmt;
654 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physDev->current_pf, TRUE /* Offscreen */, &fmt_count);
655 if(!fmt) return FALSE;
657 TRACE(" HDC %p has:\n", physDev->hdc);
658 TRACE(" - iPixelFormat %d\n", fmt->iPixelFormat);
659 TRACE(" - Drawable %p\n", (void*) get_glxdrawable(physDev));
660 TRACE(" - FBCONFIG_ID 0x%x\n", fmt->fmt_id);
662 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &tmp);
663 TRACE(" - VISUAL_ID 0x%x\n", tmp);
668 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
673 int nvfloatattrib = GLX_DONT_CARE;
674 int pixelattrib = ~0;
676 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
677 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
678 while (iWGLAttr && 0 != iWGLAttr[cur]) {
679 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
681 switch (iWGLAttr[cur]) {
682 case WGL_AUX_BUFFERS_ARB:
683 pop = iWGLAttr[++cur];
684 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
685 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
687 case WGL_COLOR_BITS_ARB:
688 pop = iWGLAttr[++cur];
689 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
690 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
692 case WGL_BLUE_BITS_ARB:
693 pop = iWGLAttr[++cur];
694 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
695 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
697 case WGL_RED_BITS_ARB:
698 pop = iWGLAttr[++cur];
699 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
700 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
702 case WGL_GREEN_BITS_ARB:
703 pop = iWGLAttr[++cur];
704 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
705 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
707 case WGL_ALPHA_BITS_ARB:
708 pop = iWGLAttr[++cur];
709 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
710 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
712 case WGL_DEPTH_BITS_ARB:
713 pop = iWGLAttr[++cur];
714 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
715 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
717 case WGL_STENCIL_BITS_ARB:
718 pop = iWGLAttr[++cur];
719 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
720 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
722 case WGL_DOUBLE_BUFFER_ARB:
723 pop = iWGLAttr[++cur];
724 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
725 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
728 pop = iWGLAttr[++cur];
729 PUSH2(oGLXAttr, GLX_STEREO, pop);
730 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur, pop);
733 case WGL_PIXEL_TYPE_ARB:
734 pop = iWGLAttr[++cur];
735 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
737 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
738 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
739 /* 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 */
740 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
741 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT: pixelattrib = GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT; break ;
743 ERR("unexpected PixelType(%x)\n", pop);
748 case WGL_SUPPORT_GDI_ARB:
749 /* This flag is set in a WineGLPixelFormat */
750 pop = iWGLAttr[++cur];
751 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
754 case WGL_DRAW_TO_BITMAP_ARB:
755 /* This flag is set in a WineGLPixelFormat */
756 pop = iWGLAttr[++cur];
757 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
760 case WGL_DRAW_TO_WINDOW_ARB:
761 pop = iWGLAttr[++cur];
762 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
763 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
765 drawattrib |= GLX_WINDOW_BIT;
769 case WGL_DRAW_TO_PBUFFER_ARB:
770 pop = iWGLAttr[++cur];
771 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
772 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
774 drawattrib |= GLX_PBUFFER_BIT;
778 case WGL_ACCELERATION_ARB:
779 /* This flag is set in a WineGLPixelFormat */
780 pop = iWGLAttr[++cur];
781 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur, pop);
784 case WGL_SUPPORT_OPENGL_ARB:
785 pop = iWGLAttr[++cur];
786 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
787 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
790 case WGL_SWAP_METHOD_ARB:
791 pop = iWGLAttr[++cur];
792 /* For now we ignore this and just return SWAP_EXCHANGE */
793 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur, pop);
796 case WGL_PBUFFER_LARGEST_ARB:
797 pop = iWGLAttr[++cur];
798 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
799 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
802 case WGL_SAMPLE_BUFFERS_ARB:
803 pop = iWGLAttr[++cur];
804 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
805 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
808 case WGL_SAMPLES_ARB:
809 pop = iWGLAttr[++cur];
810 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
811 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
814 case WGL_TEXTURE_FORMAT_ARB:
815 case WGL_TEXTURE_TARGET_ARB:
816 case WGL_MIPMAP_TEXTURE_ARB:
817 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
818 pop = iWGLAttr[++cur];
820 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
822 if (use_render_texture_ati) {
823 /** nothing to do here */
825 else if (!use_render_texture_emulation) {
826 if (WGL_NO_TEXTURE_ARB != pop) {
827 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
828 return -1; /** error: don't support it */
830 drawattrib |= GLX_PBUFFER_BIT;
834 case WGL_FLOAT_COMPONENTS_NV:
835 nvfloatattrib = iWGLAttr[++cur];
836 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
838 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
839 case WGL_BIND_TO_TEXTURE_RGB_ARB:
840 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
841 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
842 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
843 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
844 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
845 pop = iWGLAttr[++cur];
846 /** cannot be converted, see direct handling on
847 * - wglGetPixelFormatAttribivARB
848 * TODO: wglChoosePixelFormat
851 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
852 pop = iWGLAttr[++cur];
853 PUSH2(oGLXAttr, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, pop);
854 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur, pop);
857 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
858 pop = iWGLAttr[++cur];
859 PUSH2(oGLXAttr, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT, pop);
860 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur, pop);
863 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
869 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
870 * all formats. Unless drawattrib is set to a non-zero value override it with ~0, so that pixmap and pbuffer
871 * formats appear as well. */
872 if(!drawattrib) drawattrib = ~0;
873 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
874 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
876 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
877 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to ~0 unless
878 * it is overridden. */
879 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
880 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
882 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
883 if(strstr(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
884 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
885 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
891 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
893 int render_type=0, render_type_bit;
894 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
895 switch(render_type_bit)
898 render_type = GLX_RGBA_TYPE;
900 case GLX_COLOR_INDEX_BIT:
901 render_type = GLX_COLOR_INDEX_TYPE;
903 case GLX_RGBA_FLOAT_BIT:
904 render_type = GLX_RGBA_FLOAT_TYPE;
906 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT:
907 render_type = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
910 ERR("Unknown render_type: %x\n", render_type_bit);
915 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
916 static BOOL check_fbconfig_bitmap_capability(Display *display, GLXFBConfig fbconfig)
919 pglXGetFBConfigAttrib(display, fbconfig, GLX_DOUBLEBUFFER, &dbuf);
920 pglXGetFBConfigAttrib(gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &value);
922 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
923 * the GLX_PIXMAP_BIT set. */
924 return !dbuf && (value & GLX_PIXMAP_BIT);
927 static WineGLPixelFormat *get_formats(Display *display, int *size_ret, int *onscreen_size_ret)
929 static WineGLPixelFormat *list;
930 static int size, onscreen_size;
932 int fmt_id, nCfgs, i, run, bmp_formats;
934 XVisualInfo *visinfo;
939 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
940 if (NULL == cfgs || 0 == nCfgs) {
941 if(cfgs != NULL) XFree(cfgs);
943 ERR("glXChooseFBConfig returns NULL\n");
947 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
948 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
949 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
950 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
952 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
954 for(i=0, bmp_formats=0; i<nCfgs; i++)
956 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
959 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats);
961 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nCfgs + bmp_formats)*sizeof(WineGLPixelFormat));
963 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
964 * Do this as GLX doesn't guarantee that the list is sorted */
965 for(run=0; run < 2; run++)
967 for(i=0; i<nCfgs; i++) {
968 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
969 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
971 /* The first run we only add onscreen formats (ones which have an associated X Visual).
972 * The second run we only set offscreen formats. */
975 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
976 * The contents is copied to the destination using XCopyArea. For the copying to work
977 * the depth of the source and destination window should be the same. In general this should
978 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
979 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
980 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
981 * list formats with the same depth. */
982 if(visinfo->depth != screen_depth)
988 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
989 list[size].iPixelFormat = size+1; /* The index starts at 1 */
990 list[size].fbconfig = cfgs[i];
991 list[size].fmt_id = fmt_id;
992 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
993 list[size].offscreenOnly = FALSE;
994 list[size].dwFlags = 0;
998 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
999 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
1001 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1002 list[size].iPixelFormat = size+1; /* The index starts at 1 */
1003 list[size].fbconfig = cfgs[i];
1004 list[size].fmt_id = fmt_id;
1005 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1006 list[size].offscreenOnly = FALSE;
1007 list[size].dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_GENERIC_FORMAT;
1011 } else if(run && !visinfo) {
1012 int window_drawable=0;
1013 pglXGetFBConfigAttrib(gdi_display, cfgs[i], GLX_DRAWABLE_TYPE, &window_drawable);
1015 /* Recent Nvidia drivers and DRI drivers offer window drawable formats without a visual.
1016 * This are formats like 16-bit rgb on a 24-bit desktop. In order to support these formats
1017 * onscreen we would have to use glXCreateWindow instead of XCreateWindow. Further it will
1018 * likely make our child window opengl rendering more complicated since likely you can't use
1019 * XCopyArea on a GLX Window.
1020 * For now ignore fbconfigs which are window drawable but lack a visual. */
1021 if(window_drawable & GLX_WINDOW_BIT)
1023 TRACE("Skipping FBCONFIG_ID 0x%x as an offscreen format because it is window_drawable\n", fmt_id);
1027 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
1028 list[size].iPixelFormat = size+1; /* The index starts at 1 */
1029 list[size].fbconfig = cfgs[i];
1030 list[size].fmt_id = fmt_id;
1031 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1032 list[size].offscreenOnly = TRUE;
1033 list[size].dwFlags = 0;
1037 if (visinfo) XFree(visinfo);
1044 if (size_ret) *size_ret = size;
1045 if (onscreen_size_ret) *onscreen_size_ret = onscreen_size;
1046 wine_tsx11_unlock();
1050 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1051 * In our WGL implementation we only support a subset of these formats namely the format of
1052 * Wine's main visual and offscreen formats (if they are available).
1053 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
1054 * and it returns the number of supported WGL formats in fmt_count.
1056 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count)
1058 WineGLPixelFormat *list, *res = NULL;
1059 int size, onscreen_size;
1061 if (!(list = get_formats(display, &size, &onscreen_size ))) return NULL;
1063 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1064 * iPixelFormat in case of probing the number of pixelformats.
1066 if((iPixelFormat > 0) && (iPixelFormat <= size) &&
1067 (!list[iPixelFormat-1].offscreenOnly || AllowOffscreen)) {
1068 res = &list[iPixelFormat-1];
1069 TRACE("Returning fmt_id=%#x for iPixelFormat=%d\n", res->fmt_id, iPixelFormat);
1075 *fmt_count = onscreen_size;
1077 TRACE("Number of returned pixelformats=%d\n", *fmt_count);
1082 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1083 static WineGLPixelFormat* ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id, DWORD dwFlags)
1085 WineGLPixelFormat *list;
1088 if (!(list = get_formats(display, &size, NULL ))) return NULL;
1090 for(i=0; i<size; i++) {
1091 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1092 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1093 if( (list[i].fmt_id == fmt_id) && ((list[i].dwFlags & dwFlags) == dwFlags) ) {
1094 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list[i].iPixelFormat, fmt_id);
1098 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id);
1102 int pixelformat_from_fbconfig_id(XID fbconfig_id)
1104 WineGLPixelFormat *fmt;
1106 if (!fbconfig_id) return 0;
1108 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id, 0 /* no flags */);
1110 return fmt->iPixelFormat;
1111 /* This will happen on hwnds without a pixel format set; it's ok */
1116 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1117 void mark_drawable_dirty(Drawable old, Drawable new)
1119 Wine_GLContext *ctx;
1120 for (ctx = context_list; ctx; ctx = ctx->next) {
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);
1175 static XID create_bitmap_glxpixmap(X11DRV_PDEVICE *physDev, WineGLPixelFormat *fmt)
1182 vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1184 if(vis->depth == physDev->bitmap->pixmap_depth)
1185 ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
1188 wine_tsx11_unlock();
1189 TRACE("return %lx\n", ret);
1194 * X11DRV_ChoosePixelFormat
1196 * Equivalent to glXChooseVisual.
1198 int CDECL X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
1199 const PIXELFORMATDESCRIPTOR *ppfd) {
1200 WineGLPixelFormat *list;
1205 int bestFormat = -1;
1206 int bestDBuffer = -1;
1207 int bestStereo = -1;
1211 int bestStencil = -1;
1214 if (!has_opengl()) return 0;
1216 if (TRACE_ON(wgl)) {
1217 TRACE("(%p,%p)\n", physDev, ppfd);
1219 dump_PIXELFORMATDESCRIPTOR(ppfd);
1222 if (!(list = get_formats(gdi_display, NULL, &onscreen_size ))) return 0;
1225 for(i=0; i<onscreen_size; i++)
1229 int alpha=0, color=0, depth=0, stencil=0, aux=0;
1230 WineGLPixelFormat *fmt = &list[i];
1233 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1234 if (value & GLX_RGBA_BIT)
1235 iPixelType = PFD_TYPE_RGBA;
1237 iPixelType = PFD_TYPE_COLORINDEX;
1239 if (ppfd->iPixelType != iPixelType)
1241 TRACE("pixel type mismatch for iPixelFormat=%d\n", i+1);
1245 /* Only use bitmap capable for formats for bitmap rendering.
1246 * See get_formats for more info. */
1247 if( (ppfd->dwFlags & PFD_DRAW_TO_BITMAP) != (fmt->dwFlags & PFD_DRAW_TO_BITMAP))
1249 TRACE("PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i+1);
1253 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1254 if (value) dwFlags |= PFD_DOUBLEBUFFER;
1255 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value);
1256 if (value) dwFlags |= PFD_STEREO;
1257 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &color); /* cColorBits */
1258 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &alpha); /* cAlphaBits */
1259 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &depth); /* cDepthBits */
1260 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &stencil); /* cStencilBits */
1261 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &aux); /* cAuxBuffers */
1263 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1264 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1265 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1266 * formats without the given flag set.
1267 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1268 * has indicated that a format without stereo is returned when stereo is unavailable.
1269 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1270 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1272 * To summarize the following is most likely the correct behavior:
1273 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1274 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1275 * stereo don't care -> it doesn't matter whether we get stereo or not
1277 * In Wine we will treat no-stereo the same way as don't care because it makes
1278 * format selection even more complicated and second drivers with Stereo advertise
1279 * each format twice anyway.
1282 /* Doublebuffer, see the comments above */
1283 if( !(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) ) {
1284 if( ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) &&
1285 ((dwFlags & PFD_DOUBLEBUFFER) == (ppfd->dwFlags & PFD_DOUBLEBUFFER)) )
1287 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1288 bestStereo = dwFlags & PFD_STEREO;
1292 bestStencil = stencil;
1297 if(bestDBuffer != -1 && (dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer)
1301 /* Stereo, see the comments above. */
1302 if( !(ppfd->dwFlags & PFD_STEREO_DONTCARE) ) {
1303 if( ((ppfd->dwFlags & PFD_STEREO) != bestStereo) &&
1304 ((dwFlags & PFD_STEREO) == (ppfd->dwFlags & PFD_STEREO)) )
1306 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1307 bestStereo = dwFlags & PFD_STEREO;
1311 bestStencil = stencil;
1316 if(bestStereo != -1 && (dwFlags & PFD_STEREO) != bestStereo)
1320 /* Below we will do a number of checks to select the 'best' pixelformat.
1321 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1322 * The code works by trying to match the most important options as close as possible.
1323 * When a reasonable format is found, we will try to match more options.
1324 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1325 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1326 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1329 if(ppfd->cColorBits) {
1330 if( ((ppfd->cColorBits > bestColor) && (color > bestColor)) ||
1331 ((color >= ppfd->cColorBits) && (color < bestColor)) )
1333 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1334 bestStereo = dwFlags & PFD_STEREO;
1338 bestStencil = stencil;
1342 } else if(bestColor != color) { /* Do further checks if the format is compatible */
1343 TRACE("color mismatch for iPixelFormat=%d\n", i+1);
1349 if(ppfd->cAlphaBits) {
1350 if( ((ppfd->cAlphaBits > bestAlpha) && (alpha > bestAlpha)) ||
1351 ((alpha >= ppfd->cAlphaBits) && (alpha < bestAlpha)) )
1353 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1354 bestStereo = dwFlags & PFD_STEREO;
1358 bestStencil = stencil;
1362 } else if(bestAlpha != alpha) {
1363 TRACE("alpha mismatch for iPixelFormat=%d\n", i+1);
1369 if(ppfd->cDepthBits) {
1370 if( ((ppfd->cDepthBits > bestDepth) && (depth > bestDepth)) ||
1371 ((depth >= ppfd->cDepthBits) && (depth < bestDepth)) )
1373 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1374 bestStereo = dwFlags & PFD_STEREO;
1378 bestStencil = stencil;
1382 } else if(bestDepth != depth) {
1383 TRACE("depth mismatch for iPixelFormat=%d\n", i+1);
1389 if(ppfd->cStencilBits) {
1390 if( ((ppfd->cStencilBits > bestStencil) && (stencil > bestStencil)) ||
1391 ((stencil >= ppfd->cStencilBits) && (stencil < bestStencil)) )
1393 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1394 bestStereo = dwFlags & PFD_STEREO;
1398 bestStencil = stencil;
1402 } else if(bestStencil != stencil) {
1403 TRACE("stencil mismatch for iPixelFormat=%d\n", i+1);
1409 if(ppfd->cAuxBuffers) {
1410 if( ((ppfd->cAuxBuffers > bestAux) && (aux > bestAux)) ||
1411 ((aux >= ppfd->cAuxBuffers) && (aux < bestAux)) )
1413 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1414 bestStereo = dwFlags & PFD_STEREO;
1418 bestStencil = stencil;
1422 } else if(bestAux != aux) {
1423 TRACE("aux mismatch for iPixelFormat=%d\n", i+1);
1429 if(bestFormat == -1) {
1430 TRACE("No matching mode was found returning 0\n");
1434 ret = bestFormat+1; /* the return value should be a 1-based index */
1435 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret, list[bestFormat].fmt_id);
1438 wine_tsx11_unlock();
1443 * X11DRV_DescribePixelFormat
1445 * Get the pixel-format descriptor associated to the given id
1447 int CDECL X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
1450 PIXELFORMATDESCRIPTOR *ppfd) {
1451 /*XVisualInfo *vis;*/
1454 WineGLPixelFormat *fmt;
1458 if (!has_opengl()) return 0;
1460 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
1462 /* 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 */
1463 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_count);
1465 /* The application is only querying the number of pixelformats */
1467 } else if(fmt == NULL) {
1468 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1472 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1473 ERR("Wrong structure size !\n");
1474 /* Should set error */
1480 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1481 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1484 /* These flags are always the same... */
1485 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1486 /* Now the flags extracted from the Visual */
1490 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1491 if(value & GLX_WINDOW_BIT)
1492 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1494 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1495 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1496 * 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
1497 * offered the GDI bit either. */
1498 ppfd->dwFlags |= fmt->dwFlags & (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI);
1500 /* PFD_GENERIC_FORMAT - gdi software rendering
1501 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1502 * none set - full hardware accelerated by a ICD
1504 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1505 ppfd->dwFlags |= fmt->dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED);
1507 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1509 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1510 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1512 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1515 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1516 if (value & GLX_RGBA_BIT)
1517 ppfd->iPixelType = PFD_TYPE_RGBA;
1519 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1522 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1523 ppfd->cColorBits = value;
1525 /* Red, green, blue and alpha bits / shifts */
1526 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1527 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1528 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1529 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1530 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1532 ppfd->cRedBits = rb;
1533 ppfd->cRedShift = gb + bb + ab;
1534 ppfd->cBlueBits = bb;
1535 ppfd->cBlueShift = ab;
1536 ppfd->cGreenBits = gb;
1537 ppfd->cGreenShift = bb + ab;
1538 ppfd->cAlphaBits = ab;
1539 ppfd->cAlphaShift = 0;
1542 ppfd->cRedShift = 0;
1543 ppfd->cBlueBits = 0;
1544 ppfd->cBlueShift = 0;
1545 ppfd->cGreenBits = 0;
1546 ppfd->cGreenShift = 0;
1547 ppfd->cAlphaBits = 0;
1548 ppfd->cAlphaShift = 0;
1551 /* Accum RGBA bits */
1552 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1553 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1554 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1555 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1557 ppfd->cAccumBits = rb+gb+bb+ab;
1558 ppfd->cAccumRedBits = rb;
1559 ppfd->cAccumGreenBits = gb;
1560 ppfd->cAccumBlueBits = bb;
1561 ppfd->cAccumAlphaBits = ab;
1564 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1565 ppfd->cAuxBuffers = value;
1568 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1569 ppfd->cDepthBits = value;
1572 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1573 ppfd->cStencilBits = value;
1575 wine_tsx11_unlock();
1577 ppfd->iLayerType = PFD_MAIN_PLANE;
1579 if (TRACE_ON(wgl)) {
1580 dump_PIXELFORMATDESCRIPTOR(ppfd);
1587 * X11DRV_GetPixelFormat
1589 * Get the pixel-format id used by this DC
1591 int CDECL X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
1592 WineGLPixelFormat *fmt;
1594 TRACE("(%p)\n", physDev);
1596 if (!physDev->current_pf) return 0; /* not set yet */
1598 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physDev->current_pf, TRUE, &tmp);
1601 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev->current_pf);
1604 else if(fmt->offscreenOnly)
1606 /* Offscreen formats can't be used with traditional WGL calls.
1607 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1608 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt->iPixelFormat);
1612 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1613 return physDev->current_pf;
1616 /* This function is the core of X11DRV_SetPixelFormat and X11DRV_SetPixelFormatWINE.
1617 * Both functions are the same except that X11DRV_SetPixelFormatWINE allows you to
1618 * set the pixel format multiple times. */
1619 static BOOL internal_SetPixelFormat(X11DRV_PDEVICE *physDev,
1621 const PIXELFORMATDESCRIPTOR *ppfd) {
1622 WineGLPixelFormat *fmt;
1626 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1627 if(get_glxdrawable(physDev) == root_window)
1629 ERR("Invalid operation on root_window\n");
1633 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1634 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
1636 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1641 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1642 wine_tsx11_unlock();
1644 hwnd = WindowFromDC(physDev->hdc);
1646 if(!(value&GLX_WINDOW_BIT)) {
1647 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1651 if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, fmt->fmt_id, 0)) {
1652 ERR("Couldn't set format of the window, returning failure\n");
1656 else if(physDev->bitmap) {
1657 if(!(value&GLX_PIXMAP_BIT)) {
1658 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat);
1662 physDev->bitmap->glxpixmap = create_bitmap_glxpixmap(physDev, fmt);
1663 if(!physDev->bitmap->glxpixmap) {
1664 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat);
1669 FIXME("called on a non-window, non-bitmap object?\n");
1672 physDev->current_pf = iPixelFormat;
1674 if (TRACE_ON(wgl)) {
1678 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1680 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1682 TRACE(" FBConfig have :\n");
1683 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1684 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1685 TRACE(" - VISUAL_ID 0x%x\n", value);
1686 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1687 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1689 wine_tsx11_unlock();
1696 * X11DRV_SetPixelFormat
1698 * Set the pixel-format id used by this DC
1700 BOOL CDECL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
1702 const PIXELFORMATDESCRIPTOR *ppfd) {
1703 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1705 if (!has_opengl()) return FALSE;
1707 if(physDev->current_pf) /* cannot change it if already set */
1708 return (physDev->current_pf == iPixelFormat);
1710 return internal_SetPixelFormat(physDev, iPixelFormat, ppfd);
1714 * X11DRV_wglCopyContext
1716 * For OpenGL32 wglCopyContext.
1718 BOOL CDECL X11DRV_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask) {
1719 Wine_GLContext *src = (Wine_GLContext*)hglrcSrc;
1720 Wine_GLContext *dst = (Wine_GLContext*)hglrcDst;
1722 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc, hglrcDst, mask);
1725 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1726 wine_tsx11_unlock();
1728 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1733 * X11DRV_wglCreateContext
1735 * For OpenGL32 wglCreateContext.
1737 HGLRC CDECL X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
1739 Wine_GLContext *ret;
1740 WineGLPixelFormat *fmt;
1741 int hdcPF = physDev->current_pf;
1743 HDC hdc = physDev->hdc;
1745 TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1747 if (!has_opengl()) return 0;
1749 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, TRUE /* Offscreen */, &fmt_count);
1750 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1751 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1752 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1753 * If this fails something is very wrong on the system. */
1755 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF);
1756 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1761 ret = alloc_context();
1764 ret->has_been_current = FALSE;
1765 ret->sharing = FALSE;
1767 ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1768 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1769 wine_tsx11_unlock();
1771 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1776 * X11DRV_wglDeleteContext
1778 * For OpenGL32 wglDeleteContext.
1780 BOOL CDECL X11DRV_wglDeleteContext(HGLRC hglrc)
1782 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1784 TRACE("(%p)\n", hglrc);
1786 if (!has_opengl()) return 0;
1788 if (!is_valid_context(ctx))
1790 WARN("Error deleting context !\n");
1791 SetLastError(ERROR_INVALID_HANDLE);
1795 /* WGL doesn't allow deletion of a context which is current in another thread */
1796 if (ctx->tid != 0 && ctx->tid != GetCurrentThreadId())
1798 TRACE("Cannot delete context=%p because it is current in another thread.\n", ctx);
1799 SetLastError(ERROR_BUSY);
1803 /* WGL makes a context not current if it is active before deletion. GLX waits until the context is not current. */
1804 if (ctx == NtCurrentTeb()->glContext)
1805 wglMakeCurrent(ctx->hdc, NULL);
1810 pglXDestroyContext(gdi_display, ctx->ctx);
1811 wine_tsx11_unlock();
1819 * X11DRV_wglGetCurrentReadDCARB
1821 * For OpenGL32 wglGetCurrentReadDCARB.
1823 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1826 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1828 if (ctx) ret = ctx->read_hdc;
1830 TRACE(" returning %p (GL drawable %lu)\n", ret, ctx ? ctx->drawables[1] : 0);
1835 * X11DRV_wglGetProcAddress
1837 * For OpenGL32 wglGetProcAddress.
1839 PROC CDECL X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1842 const WineGLExtension *ext;
1844 int padding = 32 - strlen(lpszProc);
1848 if (!has_opengl()) return NULL;
1850 /* Check the table of WGL extensions to see if we need to return a WGL extension
1851 * or a function pointer to a native OpenGL function. */
1852 if(strncmp(lpszProc, "wgl", 3) != 0) {
1853 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1855 TRACE("('%s'):%*s", lpszProc, padding, " ");
1856 for (i = 0; i < WineGLExtensionListSize; ++i) {
1857 ext = WineGLExtensionList[i];
1858 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1859 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1860 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1861 return ext->extEntryPoints[j].funcAddress;
1867 WARN("(%s) - not found\n", lpszProc);
1872 * X11DRV_wglMakeCurrent
1874 * For OpenGL32 wglMakeCurrent.
1876 BOOL CDECL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
1878 HDC hdc = physDev->hdc;
1879 DWORD type = GetObjectType(hdc);
1880 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1882 TRACE("(%p,%p)\n", hdc, hglrc);
1884 if (!has_opengl()) return FALSE;
1889 Wine_GLContext *prev_ctx = NtCurrentTeb()->glContext;
1890 if (prev_ctx) prev_ctx->tid = 0;
1892 ret = pglXMakeCurrent(gdi_display, None, NULL);
1893 NtCurrentTeb()->glContext = NULL;
1895 else if (ctx->fmt->iPixelFormat != physDev->current_pf)
1897 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1898 hdc, physDev->current_pf, ctx, ctx->fmt->iPixelFormat );
1899 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1904 Drawable drawable = get_glxdrawable(physDev);
1905 Wine_GLContext *prev_ctx = NtCurrentTeb()->glContext;
1906 if (prev_ctx) prev_ctx->tid = 0;
1908 /* The describe lines below are for debugging purposes only */
1909 if (TRACE_ON(wgl)) {
1910 describeDrawable(physDev);
1911 describeContext(ctx);
1914 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display, (void*) drawable, ctx->ctx);
1915 ret = pglXMakeCurrent(gdi_display, drawable, ctx->ctx);
1916 NtCurrentTeb()->glContext = ctx;
1920 ctx->has_been_current = TRUE;
1921 ctx->tid = GetCurrentThreadId();
1923 ctx->read_hdc = hdc;
1924 ctx->drawables[0] = drawable;
1925 ctx->drawables[1] = drawable;
1926 ctx->refresh_drawables = FALSE;
1928 if (type == OBJ_MEMDC)
1930 ctx->do_escape = TRUE;
1931 pglDrawBuffer(GL_FRONT_LEFT);
1935 wine_tsx11_unlock();
1936 TRACE(" returning %s\n", (ret ? "True" : "False"));
1941 * X11DRV_wglMakeContextCurrentARB
1943 * For OpenGL32 wglMakeContextCurrentARB
1945 BOOL CDECL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* pDrawDev, X11DRV_PDEVICE* pReadDev, HGLRC hglrc)
1949 TRACE("(%p,%p,%p)\n", pDrawDev, pReadDev, hglrc);
1951 if (!has_opengl()) return 0;
1956 Wine_GLContext *prev_ctx = NtCurrentTeb()->glContext;
1957 if (prev_ctx) prev_ctx->tid = 0;
1959 ret = pglXMakeCurrent(gdi_display, None, NULL);
1960 NtCurrentTeb()->glContext = NULL;
1964 if (NULL == pglXMakeContextCurrent) {
1967 Wine_GLContext *prev_ctx = NtCurrentTeb()->glContext;
1968 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1969 Drawable d_draw = get_glxdrawable(pDrawDev);
1970 Drawable d_read = get_glxdrawable(pReadDev);
1972 if (prev_ctx) prev_ctx->tid = 0;
1974 ctx->has_been_current = TRUE;
1975 ctx->tid = GetCurrentThreadId();
1976 ctx->hdc = pDrawDev->hdc;
1977 ctx->read_hdc = pReadDev->hdc;
1978 ctx->drawables[0] = d_draw;
1979 ctx->drawables[1] = d_read;
1980 ctx->refresh_drawables = FALSE;
1981 ret = pglXMakeContextCurrent(gdi_display, d_draw, d_read, ctx->ctx);
1982 NtCurrentTeb()->glContext = ctx;
1985 wine_tsx11_unlock();
1987 TRACE(" returning %s\n", (ret ? "True" : "False"));
1992 * X11DRV_wglShareLists
1994 * For OpenGL32 wglShareLists.
1996 BOOL CDECL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
1997 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1998 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
2000 TRACE("(%p, %p)\n", org, dest);
2002 if (!has_opengl()) return FALSE;
2004 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
2005 * at context creation time but in case of WGL it is done using wglShareLists.
2006 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
2007 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
2008 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
2009 * so there delaying context creation doesn't work.
2011 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
2012 * and when a program requests sharing we recreate the destination context if it hasn't been made
2013 * current or when it hasn't shared display lists before.
2016 if((org->has_been_current && dest->has_been_current) || dest->has_been_current)
2018 ERR("Could not share display lists, one of the contexts has been current already !\n");
2021 else if(dest->sharing)
2023 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
2028 if((GetObjectType(org->hdc) == OBJ_MEMDC) ^ (GetObjectType(dest->hdc) == OBJ_MEMDC))
2030 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
2034 describeContext(org);
2035 describeContext(dest);
2037 /* Re-create the GLX context and share display lists */
2038 pglXDestroyContext(gdi_display, dest->ctx);
2039 dest->ctx = create_glxcontext(gdi_display, dest, org->ctx);
2040 wine_tsx11_unlock();
2041 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
2043 org->sharing = TRUE;
2044 dest->sharing = TRUE;
2050 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
2052 /* We are running using client-side rendering fonts... */
2054 unsigned int glyph, size = 0;
2055 void *bitmap = NULL, *gl_bitmap = NULL;
2059 pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
2060 pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
2061 wine_tsx11_unlock();
2063 for (glyph = first; glyph < first + count; glyph++) {
2064 static const MAT2 identity = { {0,1},{0,0},{0,0},{0,1} };
2065 unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, &identity);
2066 unsigned int height, width_int;
2068 TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
2069 if (needed_size == GDI_ERROR) {
2070 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size);
2073 TRACE(" - needed size : %d\n", needed_size);
2076 if (needed_size > size) {
2078 HeapFree(GetProcessHeap(), 0, bitmap);
2079 HeapFree(GetProcessHeap(), 0, gl_bitmap);
2080 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
2081 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
2083 if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, &identity) == GDI_ERROR)
2085 if (TRACE_ON(wgl)) {
2086 unsigned int height, width, bitmask;
2087 unsigned char *bitmap_ = bitmap;
2089 TRACE(" - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
2090 TRACE(" - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
2091 TRACE(" - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
2092 if (needed_size != 0) {
2093 TRACE(" - bitmap :\n");
2094 for (height = 0; height < gm.gmBlackBoxY; height++) {
2096 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
2101 if (*bitmap_ & bitmask)
2106 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
2112 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
2113 * glyph for it to be drawn properly.
2115 if (needed_size != 0) {
2116 width_int = (gm.gmBlackBoxX + 31) / 32;
2117 for (height = 0; height < gm.gmBlackBoxY; height++) {
2119 for (width = 0; width < width_int; width++) {
2120 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
2121 ((int *) bitmap)[height * width_int + width];
2127 pglNewList(listBase++, GL_COMPILE);
2128 if (needed_size != 0) {
2129 pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
2130 0 - gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - gm.gmptGlyphOrigin.y,
2131 gm.gmCellIncX, gm.gmCellIncY,
2134 /* This is the case of 'empty' glyphs like the space character */
2135 pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
2138 wine_tsx11_unlock();
2142 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
2143 wine_tsx11_unlock();
2145 HeapFree(GetProcessHeap(), 0, bitmap);
2146 HeapFree(GetProcessHeap(), 0, gl_bitmap);
2151 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
2152 wine_tsx11_unlock();
2154 HeapFree(GetProcessHeap(), 0, bitmap);
2155 HeapFree(GetProcessHeap(), 0, gl_bitmap);
2160 * X11DRV_wglUseFontBitmapsA
2162 * For OpenGL32 wglUseFontBitmapsA.
2164 BOOL CDECL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
2166 Font fid = physDev->font;
2168 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
2170 if (!has_opengl()) return FALSE;
2173 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineA);
2177 /* I assume that the glyphs are at the same position for X and for Windows */
2178 pglXUseXFont(fid, first, count, listBase);
2179 wine_tsx11_unlock();
2184 * X11DRV_wglUseFontBitmapsW
2186 * For OpenGL32 wglUseFontBitmapsW.
2188 BOOL CDECL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
2190 Font fid = physDev->font;
2192 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
2194 if (!has_opengl()) return FALSE;
2197 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineW);
2200 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
2203 /* I assume that the glyphs are at the same position for X and for Windows */
2204 pglXUseXFont(fid, first, count, listBase);
2205 wine_tsx11_unlock();
2209 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2210 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params)
2217 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2219 pglGetIntegerv(pname, params);
2221 * if we cannot find a Wine Context
2222 * we only have the default wine desktop context,
2223 * so if we have only a 24 depth say we have 32
2225 if (!ctx && *params == 24) {
2228 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
2233 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2235 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_ALPHA_SIZE, params);
2236 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params);
2240 pglGetIntegerv(pname, params);
2243 wine_tsx11_unlock();
2246 void flush_gl_drawable(X11DRV_PDEVICE *physDev)
2250 if (!physDev->gl_copy)
2253 w = physDev->dc_rect.right - physDev->dc_rect.left;
2254 h = physDev->dc_rect.bottom - physDev->dc_rect.top;
2256 if(w > 0 && h > 0) {
2257 Drawable src = physDev->pixmap;
2258 if(!src) src = physDev->gl_drawable;
2260 /* The GL drawable may be lagged behind if we don't flush first, so
2261 * flush the display make sure we copy up-to-date data */
2263 XFlush(gdi_display);
2264 XSetFunction(gdi_display, physDev->gc, GXcopy);
2265 XCopyArea(gdi_display, src, physDev->drawable, physDev->gc, 0, 0, w, h,
2266 physDev->dc_rect.left, physDev->dc_rect.top);
2267 wine_tsx11_unlock();
2272 static void WINAPI X11DRV_wglFinish(void)
2274 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2275 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2280 wine_tsx11_unlock();
2281 if (ctx) ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2284 static void WINAPI X11DRV_wglFlush(void)
2286 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2287 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2292 wine_tsx11_unlock();
2293 if (ctx) ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2297 * X11DRV_wglCreateContextAttribsARB
2299 * WGL_ARB_create_context: wglCreateContextAttribsARB
2301 HGLRC CDECL X11DRV_wglCreateContextAttribsARB(X11DRV_PDEVICE *physDev, HGLRC hShareContext, const int* attribList)
2303 Wine_GLContext *ret;
2304 WineGLPixelFormat *fmt;
2305 int hdcPF = physDev->current_pf;
2308 TRACE("(%p %p %p)\n", physDev, hShareContext, attribList);
2310 if (!has_opengl()) return 0;
2312 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, TRUE /* Offscreen */, &fmt_count);
2313 /* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones.
2314 * If this fails something is very wrong on the system. */
2317 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF);
2318 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2323 ret = alloc_context();
2324 wine_tsx11_unlock();
2325 ret->hdc = physDev->hdc;
2327 ret->vis = NULL; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
2328 ret->gl3_context = TRUE;
2330 ret->numAttribs = 0;
2333 int *pAttribList = (int*)attribList;
2334 int *pContextAttribList = &ret->attribList[0];
2335 /* attribList consists of pairs {token, value] terminated with 0 */
2336 while(pAttribList[0] != 0)
2338 TRACE("%#x %#x\n", pAttribList[0], pAttribList[1]);
2339 switch(pAttribList[0])
2341 case WGL_CONTEXT_MAJOR_VERSION_ARB:
2342 pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
2343 pContextAttribList[1] = pAttribList[1];
2345 case WGL_CONTEXT_MINOR_VERSION_ARB:
2346 pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB;
2347 pContextAttribList[1] = pAttribList[1];
2349 case WGL_CONTEXT_LAYER_PLANE_ARB:
2351 case WGL_CONTEXT_FLAGS_ARB:
2352 pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB;
2353 pContextAttribList[1] = pAttribList[1];
2355 case WGL_CONTEXT_PROFILE_MASK_ARB:
2356 pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
2357 pContextAttribList[1] = pAttribList[1];
2360 ERR("Unhandled attribList pair: %#x %#x\n", pAttribList[0], pAttribList[1]);
2365 pContextAttribList += 2;
2370 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
2371 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
2373 XSync(gdi_display, False);
2374 if(X11DRV_check_error() || !ret->ctx)
2376 /* In the future we should convert the GLX error to a win32 one here if needed */
2377 ERR("Context creation failed\n");
2379 wine_tsx11_unlock();
2383 wine_tsx11_unlock();
2384 TRACE(" creating context %p\n", ret);
2389 * X11DRV_wglGetExtensionsStringARB
2391 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2393 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
2394 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2395 return WineGLInfo.wglExtensions;
2399 * X11DRV_wglCreatePbufferARB
2401 * WGL_ARB_pbuffer: wglCreatePbufferARB
2403 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
2405 Wine_GLPBuffer* object = NULL;
2406 WineGLPixelFormat *fmt = NULL;
2411 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2413 if (0 >= iPixelFormat) {
2414 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
2415 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2416 return NULL; /* unexpected error */
2419 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2420 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nCfgs);
2422 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
2423 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2424 goto create_failed; /* unexpected error */
2427 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
2428 if (NULL == object) {
2429 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2430 goto create_failed; /* unexpected error */
2433 object->display = gdi_display;
2434 object->width = iWidth;
2435 object->height = iHeight;
2438 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2439 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2440 while (piAttribList && 0 != *piAttribList) {
2442 switch (*piAttribList) {
2443 case WGL_PBUFFER_LARGEST_ARB: {
2445 attr_v = *piAttribList;
2446 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2447 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2451 case WGL_TEXTURE_FORMAT_ARB: {
2453 attr_v = *piAttribList;
2454 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2455 if (use_render_texture_ati) {
2458 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2459 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
2460 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
2462 SetLastError(ERROR_INVALID_DATA);
2465 object->use_render_texture = 1;
2466 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
2468 if (WGL_NO_TEXTURE_ARB == attr_v) {
2469 object->use_render_texture = 0;
2471 if (!use_render_texture_emulation) {
2472 SetLastError(ERROR_INVALID_DATA);
2476 case WGL_TEXTURE_RGB_ARB:
2477 object->use_render_texture = GL_RGB;
2478 object->texture_bpp = 3;
2479 object->texture_format = GL_RGB;
2480 object->texture_type = GL_UNSIGNED_BYTE;
2482 case WGL_TEXTURE_RGBA_ARB:
2483 object->use_render_texture = GL_RGBA;
2484 object->texture_bpp = 4;
2485 object->texture_format = GL_RGBA;
2486 object->texture_type = GL_UNSIGNED_BYTE;
2489 /* WGL_FLOAT_COMPONENTS_NV */
2490 case WGL_TEXTURE_FLOAT_R_NV:
2491 object->use_render_texture = GL_FLOAT_R_NV;
2492 object->texture_bpp = 4;
2493 object->texture_format = GL_RED;
2494 object->texture_type = GL_FLOAT;
2496 case WGL_TEXTURE_FLOAT_RG_NV:
2497 object->use_render_texture = GL_FLOAT_RG_NV;
2498 object->texture_bpp = 8;
2499 object->texture_format = GL_LUMINANCE_ALPHA;
2500 object->texture_type = GL_FLOAT;
2502 case WGL_TEXTURE_FLOAT_RGB_NV:
2503 object->use_render_texture = GL_FLOAT_RGB_NV;
2504 object->texture_bpp = 12;
2505 object->texture_format = GL_RGB;
2506 object->texture_type = GL_FLOAT;
2508 case WGL_TEXTURE_FLOAT_RGBA_NV:
2509 object->use_render_texture = GL_FLOAT_RGBA_NV;
2510 object->texture_bpp = 16;
2511 object->texture_format = GL_RGBA;
2512 object->texture_type = GL_FLOAT;
2515 ERR("Unknown texture format: %x\n", attr_v);
2516 SetLastError(ERROR_INVALID_DATA);
2524 case WGL_TEXTURE_TARGET_ARB: {
2526 attr_v = *piAttribList;
2527 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2528 if (use_render_texture_ati) {
2531 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2532 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
2533 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
2534 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
2536 SetLastError(ERROR_INVALID_DATA);
2539 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
2541 if (WGL_NO_TEXTURE_ARB == attr_v) {
2542 object->texture_target = 0;
2544 if (!use_render_texture_emulation) {
2545 SetLastError(ERROR_INVALID_DATA);
2549 case WGL_TEXTURE_CUBE_MAP_ARB: {
2550 if (iWidth != iHeight) {
2551 SetLastError(ERROR_INVALID_DATA);
2554 object->texture_target = GL_TEXTURE_CUBE_MAP;
2555 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2558 case WGL_TEXTURE_1D_ARB: {
2560 SetLastError(ERROR_INVALID_DATA);
2563 object->texture_target = GL_TEXTURE_1D;
2564 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2567 case WGL_TEXTURE_2D_ARB: {
2568 object->texture_target = GL_TEXTURE_2D;
2569 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2572 case WGL_TEXTURE_RECTANGLE_NV: {
2573 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2574 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2578 ERR("Unknown texture target: %x\n", attr_v);
2579 SetLastError(ERROR_INVALID_DATA);
2587 case WGL_MIPMAP_TEXTURE_ARB: {
2589 attr_v = *piAttribList;
2590 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2591 if (use_render_texture_ati) {
2592 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
2594 if (!use_render_texture_emulation) {
2595 SetLastError(ERROR_INVALID_DATA);
2605 PUSH1(attribs, None);
2607 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2608 wine_tsx11_unlock();
2609 TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
2610 if (!object->drawable) {
2611 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2612 goto create_failed; /* unexpected error */
2614 TRACE("->(%p)\n", object);
2618 HeapFree(GetProcessHeap(), 0, object);
2619 TRACE("->(FAILED)\n");
2624 * X11DRV_wglDestroyPbufferARB
2626 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2628 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2630 Wine_GLPBuffer* object = hPbuffer;
2631 TRACE("(%p)\n", hPbuffer);
2632 if (NULL == object) {
2633 SetLastError(ERROR_INVALID_HANDLE);
2637 pglXDestroyPbuffer(object->display, object->drawable);
2638 wine_tsx11_unlock();
2639 HeapFree(GetProcessHeap(), 0, object);
2644 * X11DRV_wglGetPbufferDCARB
2646 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2647 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2648 * Gdi32 implements the part of this function which creates a device context.
2649 * This part associates the physDev with the X drawable of the pbuffer.
2651 HDC CDECL X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
2653 Wine_GLPBuffer* object = hPbuffer;
2654 if (NULL == object) {
2655 SetLastError(ERROR_INVALID_HANDLE);
2659 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2660 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2661 physDev->current_pf = object->fmt->iPixelFormat;
2662 physDev->drawable = object->drawable;
2663 SetRect( &physDev->drawable_rect, 0, 0, object->width, object->height );
2664 physDev->dc_rect = physDev->drawable_rect;
2666 TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);
2667 return physDev->hdc;
2671 * X11DRV_wglQueryPbufferARB
2673 * WGL_ARB_pbuffer: wglQueryPbufferARB
2675 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2677 Wine_GLPBuffer* object = hPbuffer;
2678 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2679 if (NULL == object) {
2680 SetLastError(ERROR_INVALID_HANDLE);
2683 switch (iAttribute) {
2684 case WGL_PBUFFER_WIDTH_ARB:
2686 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2687 wine_tsx11_unlock();
2689 case WGL_PBUFFER_HEIGHT_ARB:
2691 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2692 wine_tsx11_unlock();
2695 case WGL_PBUFFER_LOST_ARB:
2696 /* GLX Pbuffers cannot be lost by default. We can support this by
2697 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2698 * to receive pixel buffer clobber events, however that may or may
2699 * not give any benefit */
2700 *piValue = GL_FALSE;
2703 case WGL_TEXTURE_FORMAT_ARB:
2704 if (use_render_texture_ati) {
2706 int type = WGL_NO_TEXTURE_ARB;
2708 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2709 wine_tsx11_unlock();
2711 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2712 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2713 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2717 if (!object->use_render_texture) {
2718 *piValue = WGL_NO_TEXTURE_ARB;
2720 if (!use_render_texture_emulation) {
2721 SetLastError(ERROR_INVALID_HANDLE);
2724 switch(object->use_render_texture) {
2726 *piValue = WGL_TEXTURE_RGB_ARB;
2729 *piValue = WGL_TEXTURE_RGBA_ARB;
2731 /* WGL_FLOAT_COMPONENTS_NV */
2733 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2735 case GL_FLOAT_RG_NV:
2736 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2738 case GL_FLOAT_RGB_NV:
2739 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2741 case GL_FLOAT_RGBA_NV:
2742 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2745 ERR("Unknown texture format: %x\n", object->use_render_texture);
2751 case WGL_TEXTURE_TARGET_ARB:
2752 if (use_render_texture_ati) {
2754 int type = WGL_NO_TEXTURE_ARB;
2756 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2757 wine_tsx11_unlock();
2759 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2760 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2761 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2762 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2766 if (!object->texture_target) {
2767 *piValue = WGL_NO_TEXTURE_ARB;
2769 if (!use_render_texture_emulation) {
2770 SetLastError(ERROR_INVALID_DATA);
2773 switch (object->texture_target) {
2774 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2775 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2776 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2777 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2783 case WGL_MIPMAP_TEXTURE_ARB:
2784 if (use_render_texture_ati) {
2786 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2787 wine_tsx11_unlock();
2789 *piValue = GL_FALSE; /** don't support that */
2790 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2795 FIXME("unexpected attribute %x\n", iAttribute);
2803 * X11DRV_wglReleasePbufferDCARB
2805 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2807 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2809 TRACE("(%p, %p)\n", hPbuffer, hdc);
2810 return DeleteDC(hdc);
2814 * X11DRV_wglSetPbufferAttribARB
2816 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2818 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2820 Wine_GLPBuffer* object = hPbuffer;
2821 GLboolean ret = GL_FALSE;
2823 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2824 if (NULL == object) {
2825 SetLastError(ERROR_INVALID_HANDLE);
2828 if (!object->use_render_texture) {
2829 SetLastError(ERROR_INVALID_HANDLE);
2832 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2835 if (NULL != pglXDrawableAttribATI) {
2836 if (use_render_texture_ati) {
2837 FIXME("Need conversion for GLX_ATI_render_texture\n");
2840 ret = pglXDrawableAttribATI(object->display, object->drawable, piAttribList);
2841 wine_tsx11_unlock();
2847 * X11DRV_wglChoosePixelFormatARB
2849 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2851 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2856 GLXFBConfig* cfgs = NULL;
2860 WineGLPixelFormat *fmt;
2866 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2867 if (NULL != pfAttribFList) {
2868 FIXME("unused pfAttribFList\n");
2871 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2872 if (-1 == nAttribs) {
2873 WARN("Cannot convert WGL to GLX attributes\n");
2876 PUSH1(attribs, None);
2878 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2879 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2880 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2881 for(i=0; piAttribIList[i] != 0; i+=2)
2883 switch(piAttribIList[i])
2885 case WGL_DRAW_TO_BITMAP_ARB:
2886 if(piAttribIList[i+1])
2887 dwFlags |= PFD_DRAW_TO_BITMAP;
2889 case WGL_ACCELERATION_ARB:
2890 switch(piAttribIList[i+1])
2892 case WGL_NO_ACCELERATION_ARB:
2893 dwFlags |= PFD_GENERIC_FORMAT;
2895 case WGL_GENERIC_ACCELERATION_ARB:
2896 dwFlags |= PFD_GENERIC_ACCELERATED;
2898 case WGL_FULL_ACCELERATION_ARB:
2903 case WGL_SUPPORT_GDI_ARB:
2904 if(piAttribIList[i+1])
2905 dwFlags |= PFD_SUPPORT_GDI;
2910 /* Search for FB configurations matching the requirements in attribs */
2912 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2914 wine_tsx11_unlock();
2915 WARN("Compatible Pixel Format not found\n");
2919 /* Loop through all matching formats and check if they are suitable.
2920 * Note that this function should at max return nMaxFormats different formats */
2921 for(run=0; run < 2; run++)
2923 for (it = 0; it < nCfgs; ++it) {
2924 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2926 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2930 /* Search for the format in our list of compatible formats */
2931 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id, dwFlags);
2935 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2936 if( ((run == 0) && fmt->offscreenOnly) || ((run == 1) && !fmt->offscreenOnly) )
2939 if(pfmt_it < nMaxFormats) {
2940 piFormats[pfmt_it] = fmt->iPixelFormat;
2941 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2947 *nNumFormats = pfmt_it;
2950 wine_tsx11_unlock();
2955 * X11DRV_wglGetPixelFormatAttribivARB
2957 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2959 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2962 WineGLPixelFormat *fmt = NULL;
2966 int nWGLFormats = 0;
2968 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2970 if (0 < iLayerPlane) {
2971 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2975 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2976 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2977 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2978 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nWGLFormats);
2980 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2984 for (i = 0; i < nAttributes; ++i) {
2985 const int curWGLAttr = piAttributes[i];
2986 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2988 switch (curWGLAttr) {
2989 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2990 piValues[i] = nWGLFormats;
2993 case WGL_SUPPORT_OPENGL_ARB:
2994 piValues[i] = GL_TRUE;
2997 case WGL_ACCELERATION_ARB:
2998 curGLXAttr = GLX_CONFIG_CAVEAT;
2999 if (!fmt) goto pix_error;
3000 if(fmt->dwFlags & PFD_GENERIC_FORMAT)
3001 piValues[i] = WGL_NO_ACCELERATION_ARB;
3002 else if(fmt->dwFlags & PFD_GENERIC_ACCELERATED)
3003 piValues[i] = WGL_GENERIC_ACCELERATION_ARB;
3005 piValues[i] = WGL_FULL_ACCELERATION_ARB;
3008 case WGL_TRANSPARENT_ARB:
3009 curGLXAttr = GLX_TRANSPARENT_TYPE;
3010 if (!fmt) goto pix_error;
3011 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
3012 if (hTest) goto get_error;
3013 piValues[i] = GL_FALSE;
3014 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
3017 case WGL_PIXEL_TYPE_ARB:
3018 curGLXAttr = GLX_RENDER_TYPE;
3019 if (!fmt) goto pix_error;
3020 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
3021 if (hTest) goto get_error;
3022 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
3023 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
3024 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
3025 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
3026 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
3027 else if (tmp & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) { piValues[i] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT; }
3029 ERR("unexpected RenderType(%x)\n", tmp);
3030 piValues[i] = WGL_TYPE_RGBA_ARB;
3034 case WGL_COLOR_BITS_ARB:
3035 curGLXAttr = GLX_BUFFER_SIZE;
3038 case WGL_BIND_TO_TEXTURE_RGB_ARB:
3039 if (use_render_texture_ati) {
3040 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
3043 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
3044 if (use_render_texture_ati) {
3045 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
3048 if (!use_render_texture_emulation) {
3049 piValues[i] = GL_FALSE;
3052 curGLXAttr = GLX_RENDER_TYPE;
3053 if (!fmt) goto pix_error;
3054 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
3055 if (hTest) goto get_error;
3056 if (GLX_COLOR_INDEX_BIT == tmp) {
3057 piValues[i] = GL_FALSE;
3060 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
3061 if (hTest) goto get_error;
3062 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
3065 case WGL_BLUE_BITS_ARB:
3066 curGLXAttr = GLX_BLUE_SIZE;
3068 case WGL_RED_BITS_ARB:
3069 curGLXAttr = GLX_RED_SIZE;
3071 case WGL_GREEN_BITS_ARB:
3072 curGLXAttr = GLX_GREEN_SIZE;
3074 case WGL_ALPHA_BITS_ARB:
3075 curGLXAttr = GLX_ALPHA_SIZE;
3077 case WGL_DEPTH_BITS_ARB:
3078 curGLXAttr = GLX_DEPTH_SIZE;
3080 case WGL_STENCIL_BITS_ARB:
3081 curGLXAttr = GLX_STENCIL_SIZE;
3083 case WGL_DOUBLE_BUFFER_ARB:
3084 curGLXAttr = GLX_DOUBLEBUFFER;
3086 case WGL_STEREO_ARB:
3087 curGLXAttr = GLX_STEREO;
3089 case WGL_AUX_BUFFERS_ARB:
3090 curGLXAttr = GLX_AUX_BUFFERS;
3093 case WGL_SUPPORT_GDI_ARB:
3094 if (!fmt) goto pix_error;
3095 piValues[i] = (fmt->dwFlags & PFD_SUPPORT_GDI) ? TRUE : FALSE;
3098 case WGL_DRAW_TO_BITMAP_ARB:
3099 if (!fmt) goto pix_error;
3100 piValues[i] = (fmt->dwFlags & PFD_DRAW_TO_BITMAP) ? TRUE : FALSE;
3103 case WGL_DRAW_TO_WINDOW_ARB:
3104 case WGL_DRAW_TO_PBUFFER_ARB:
3105 if (!fmt) goto pix_error;
3106 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
3107 if (hTest) goto get_error;
3108 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
3109 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
3110 piValues[i] = GL_TRUE;
3112 piValues[i] = GL_FALSE;
3115 case WGL_SWAP_METHOD_ARB:
3116 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
3117 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
3118 * point only ATI offers this.
3120 piValues[i] = WGL_SWAP_EXCHANGE_ARB;
3123 case WGL_PBUFFER_LARGEST_ARB:
3124 curGLXAttr = GLX_LARGEST_PBUFFER;
3127 case WGL_SAMPLE_BUFFERS_ARB:
3128 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
3131 case WGL_SAMPLES_ARB:
3132 curGLXAttr = GLX_SAMPLES_ARB;
3135 case WGL_FLOAT_COMPONENTS_NV:
3136 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
3139 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
3140 curGLXAttr = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT;
3143 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
3144 curGLXAttr = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
3147 case WGL_ACCUM_RED_BITS_ARB:
3148 curGLXAttr = GLX_ACCUM_RED_SIZE;
3150 case WGL_ACCUM_GREEN_BITS_ARB:
3151 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
3153 case WGL_ACCUM_BLUE_BITS_ARB:
3154 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
3156 case WGL_ACCUM_ALPHA_BITS_ARB:
3157 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
3159 case WGL_ACCUM_BITS_ARB:
3160 if (!fmt) goto pix_error;
3161 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
3162 if (hTest) goto get_error;
3164 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
3165 if (hTest) goto get_error;
3167 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
3168 if (hTest) goto get_error;
3170 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
3171 if (hTest) goto get_error;
3176 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
3179 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
3180 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
3181 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
3183 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
3184 * and check which options can work using iPixelFormat=0 and which not.
3185 * A problem would be that this function is an extension. This would
3186 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
3188 if (0 != curGLXAttr && iPixelFormat != 0) {
3189 if (!fmt) goto pix_error;
3190 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
3191 if (hTest) goto get_error;
3194 piValues[i] = GL_FALSE;
3197 wine_tsx11_unlock();
3201 wine_tsx11_unlock();
3202 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
3206 wine_tsx11_unlock();
3207 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats);
3212 * X11DRV_wglGetPixelFormatAttribfvARB
3214 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
3216 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
3222 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
3224 /* Allocate a temporary array to store integer values */
3225 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
3227 ERR("couldn't allocate %d array\n", nAttributes);
3231 /* Piggy-back on wglGetPixelFormatAttribivARB */
3232 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
3234 /* Convert integer values to float. Should also check for attributes
3235 that can give decimal values here */
3236 for (i=0; i<nAttributes;i++) {
3237 pfValues[i] = attr[i];
3241 HeapFree(GetProcessHeap(), 0, attr);
3246 * X11DRV_wglBindTexImageARB
3248 * WGL_ARB_render_texture: wglBindTexImageARB
3250 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
3252 Wine_GLPBuffer* object = hPbuffer;
3253 GLboolean ret = GL_FALSE;
3255 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
3256 if (NULL == object) {
3257 SetLastError(ERROR_INVALID_HANDLE);
3260 if (!object->use_render_texture) {
3261 SetLastError(ERROR_INVALID_HANDLE);
3265 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
3266 static int init = 0;
3267 int prev_binded_texture = 0;
3268 GLXContext prev_context;
3269 Drawable prev_drawable;
3270 GLXContext tmp_context;
3273 prev_context = pglXGetCurrentContext();
3274 prev_drawable = pglXGetCurrentDrawable();
3276 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
3277 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
3278 isn't ideal performance wise but I wasn't able to get other ways working.
3281 init = 1; /* Only show the FIXME once for performance reasons */
3282 FIXME("partial stub!\n");
3285 TRACE("drawable=%p, context=%p\n", (void*)object->drawable, prev_context);
3286 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
3288 pglGetIntegerv(object->texture_bind_target, &prev_binded_texture);
3290 /* Switch to our pbuffer */
3291 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
3293 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
3294 * After that upload the pbuffer texture data. */
3295 pglBindTexture(object->texture_target, prev_binded_texture);
3296 pglCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
3298 /* Switch back to the original drawable and upload the pbuffer-texture */
3299 pglXMakeCurrent(object->display, prev_drawable, prev_context);
3300 pglXDestroyContext(gdi_display, tmp_context);
3301 wine_tsx11_unlock();
3305 if (NULL != pglXBindTexImageATI) {
3310 case WGL_FRONT_LEFT_ARB:
3311 buffer = GLX_FRONT_LEFT_ATI;
3313 case WGL_FRONT_RIGHT_ARB:
3314 buffer = GLX_FRONT_RIGHT_ATI;
3316 case WGL_BACK_LEFT_ARB:
3317 buffer = GLX_BACK_LEFT_ATI;
3319 case WGL_BACK_RIGHT_ARB:
3320 buffer = GLX_BACK_RIGHT_ATI;
3323 ERR("Unknown iBuffer=%#x\n", iBuffer);
3327 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3328 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3329 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3330 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3331 * works fine using our pbuffer emulation path.
3334 ret = pglXBindTexImageATI(object->display, object->drawable, buffer);
3335 wine_tsx11_unlock();
3341 * X11DRV_wglReleaseTexImageARB
3343 * WGL_ARB_render_texture: wglReleaseTexImageARB
3345 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
3347 Wine_GLPBuffer* object = hPbuffer;
3348 GLboolean ret = GL_FALSE;
3350 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
3351 if (NULL == object) {
3352 SetLastError(ERROR_INVALID_HANDLE);
3355 if (!object->use_render_texture) {
3356 SetLastError(ERROR_INVALID_HANDLE);
3359 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
3362 if (NULL != pglXReleaseTexImageATI) {
3367 case WGL_FRONT_LEFT_ARB:
3368 buffer = GLX_FRONT_LEFT_ATI;
3370 case WGL_FRONT_RIGHT_ARB:
3371 buffer = GLX_FRONT_RIGHT_ATI;
3373 case WGL_BACK_LEFT_ARB:
3374 buffer = GLX_BACK_LEFT_ATI;
3376 case WGL_BACK_RIGHT_ARB:
3377 buffer = GLX_BACK_RIGHT_ATI;
3380 ERR("Unknown iBuffer=%#x\n", iBuffer);
3384 ret = pglXReleaseTexImageATI(object->display, object->drawable, buffer);
3385 wine_tsx11_unlock();
3391 * X11DRV_wglGetExtensionsStringEXT
3393 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3395 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
3396 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
3397 return WineGLInfo.wglExtensions;
3401 * X11DRV_wglGetSwapIntervalEXT
3403 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3405 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
3406 /* GLX_SGI_swap_control doesn't have any provisions for getting the swap
3407 * interval, so the swap interval has to be tracked. */
3409 return swap_interval;
3413 * X11DRV_wglSwapIntervalEXT
3415 * WGL_EXT_swap_control: wglSwapIntervalEXT
3417 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
3420 TRACE("(%d)\n", interval);
3424 SetLastError(ERROR_INVALID_DATA);
3427 else if (interval == 0)
3429 /* wglSwapIntervalEXT considers an interval value of zero to mean that
3430 * vsync should be disabled, but glXSwapIntervalSGI considers such a
3431 * value to be an error. Just silently ignore the request for now. */
3432 WARN("Request to disable vertical sync is not handled\n");
3437 if (pglXSwapIntervalSGI)
3440 ret = !pglXSwapIntervalSGI(interval);
3441 wine_tsx11_unlock();
3444 WARN("GLX_SGI_swap_control extension is not available\n");
3447 swap_interval = interval;
3449 SetLastError(ERROR_DC_NOT_FOUND);
3456 * X11DRV_wglAllocateMemoryNV
3458 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3460 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
3462 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
3464 if (pglXAllocateMemoryNV)
3467 ret = pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
3468 wine_tsx11_unlock();
3474 * X11DRV_wglFreeMemoryNV
3476 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3478 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
3479 TRACE("(%p)\n", pointer);
3480 if (pglXFreeMemoryNV == NULL)
3484 pglXFreeMemoryNV(pointer);
3485 wine_tsx11_unlock();
3489 * X11DRV_wglSetPixelFormatWINE
3491 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3492 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3494 BOOL CDECL X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE *physDev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
3496 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
3498 if (!has_opengl()) return FALSE;
3500 if (physDev->current_pf == iPixelFormat) return TRUE;
3502 /* Relay to the core SetPixelFormat */
3503 TRACE("Changing iPixelFormat from %d to %d\n", physDev->current_pf, iPixelFormat);
3504 return internal_SetPixelFormat(physDev, iPixelFormat, ppfd);
3508 * glxRequireVersion (internal)
3510 * Check if the supported GLX version matches requiredVersion.
3512 static BOOL glxRequireVersion(int requiredVersion)
3514 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3515 if(requiredVersion <= WineGLInfo.glxVersion[1])
3521 static BOOL glxRequireExtension(const char *requiredExtension)
3523 if (strstr(WineGLInfo.glxExtensions, requiredExtension) == NULL) {
3530 static void register_extension_string(const char *ext)
3532 if (WineGLInfo.wglExtensions[0])
3533 strcat(WineGLInfo.wglExtensions, " ");
3534 strcat(WineGLInfo.wglExtensions, ext);
3536 TRACE("'%s'\n", ext);
3539 static BOOL register_extension(const WineGLExtension * ext)
3543 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
3544 WineGLExtensionList[WineGLExtensionListSize++] = ext;
3546 register_extension_string(ext->extName);
3548 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
3549 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
3554 static const WineGLExtension WGL_internal_functions =
3558 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
3559 { "wglFinish", X11DRV_wglFinish },
3560 { "wglFlush", X11DRV_wglFlush },
3565 static const WineGLExtension WGL_ARB_create_context =
3567 "WGL_ARB_create_context",
3569 { "wglCreateContextAttribsARB", X11DRV_wglCreateContextAttribsARB },
3573 static const WineGLExtension WGL_ARB_extensions_string =
3575 "WGL_ARB_extensions_string",
3577 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
3581 static const WineGLExtension WGL_ARB_make_current_read =
3583 "WGL_ARB_make_current_read",
3585 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
3586 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
3590 static const WineGLExtension WGL_ARB_multisample =
3592 "WGL_ARB_multisample",
3595 static const WineGLExtension WGL_ARB_pbuffer =
3599 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
3600 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
3601 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
3602 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
3603 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
3604 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
3608 static const WineGLExtension WGL_ARB_pixel_format =
3610 "WGL_ARB_pixel_format",
3612 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
3613 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
3614 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
3618 static const WineGLExtension WGL_ARB_render_texture =
3620 "WGL_ARB_render_texture",
3622 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
3623 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
3627 static const WineGLExtension WGL_EXT_extensions_string =
3629 "WGL_EXT_extensions_string",
3631 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
3635 static const WineGLExtension WGL_EXT_swap_control =
3637 "WGL_EXT_swap_control",
3639 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
3640 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
3644 static const WineGLExtension WGL_NV_vertex_array_range =
3646 "WGL_NV_vertex_array_range",
3648 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
3649 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
3653 static const WineGLExtension WGL_WINE_pixel_format_passthrough =
3655 "WGL_WINE_pixel_format_passthrough",
3657 { "wglSetPixelFormatWINE", X11DRV_wglSetPixelFormatWINE },
3662 * X11DRV_WineGL_LoadExtensions
3664 static void X11DRV_WineGL_LoadExtensions(void)
3666 WineGLInfo.wglExtensions[0] = 0;
3668 /* Load Wine internal functions */
3669 register_extension(&WGL_internal_functions);
3671 /* ARB Extensions */
3673 if(glxRequireExtension("GLX_ARB_create_context"))
3675 register_extension(&WGL_ARB_create_context);
3677 if(glxRequireExtension("GLX_ARB_create_context_profile"))
3678 register_extension_string("WGL_ARB_create_context_profile");
3681 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3683 register_extension_string("WGL_ARB_pixel_format_float");
3684 register_extension_string("WGL_ATI_pixel_format_float");
3687 register_extension(&WGL_ARB_extensions_string);
3689 if (glxRequireVersion(3))
3690 register_extension(&WGL_ARB_make_current_read);
3692 if (glxRequireExtension("GLX_ARB_multisample"))
3693 register_extension(&WGL_ARB_multisample);
3695 /* In general pbuffer functionality requires support in the X-server. The functionality is
3696 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3697 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3698 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3700 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3701 * without support in the X-server (which other Mesa based drivers require).
3703 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3704 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3705 * is available pbuffers must be available too. */
3706 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3707 register_extension(&WGL_ARB_pbuffer);
3709 register_extension(&WGL_ARB_pixel_format);
3711 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3712 if (glxRequireExtension("GLX_ATI_render_texture") ||
3713 glxRequireExtension("GLX_ARB_render_texture") ||
3714 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation))
3716 register_extension(&WGL_ARB_render_texture);
3718 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3719 if(glxRequireExtension("GLX_NV_float_buffer"))
3720 register_extension_string("WGL_NV_float_buffer");
3722 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3723 if(strstr(WineGLInfo.glExtensions, "GL_NV_texture_rectangle") != NULL)
3724 register_extension_string("WGL_NV_texture_rectangle");
3727 /* EXT Extensions */
3729 register_extension(&WGL_EXT_extensions_string);
3731 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3732 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3733 register_extension(&WGL_EXT_swap_control);
3735 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3736 register_extension_string("WGL_EXT_framebuffer_sRGB");
3738 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3739 register_extension_string("WGL_EXT_pixel_format_packed_float");
3741 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3742 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
3743 register_extension(&WGL_NV_vertex_array_range);
3745 /* WINE-specific WGL Extensions */
3747 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3748 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3750 register_extension(&WGL_WINE_pixel_format_passthrough);
3754 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3760 if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
3761 ret = physDev->drawable; /* PBuffer */
3763 ret = physDev->bitmap->glxpixmap;
3765 else if(physDev->gl_drawable)
3766 ret = physDev->gl_drawable;
3768 ret = physDev->drawable;
3772 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3775 pglXDestroyGLXPixmap(display, glxpixmap);
3776 wine_tsx11_unlock();
3781 * X11DRV_SwapBuffers
3783 * Swap the buffers of this DC
3785 BOOL CDECL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev)
3787 GLXDrawable drawable;
3788 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
3790 if (!has_opengl()) return FALSE;
3792 TRACE("(%p)\n", physDev);
3794 drawable = get_glxdrawable(physDev);
3798 if(physDev->pixmap) {
3799 if(pglXCopySubBufferMESA) {
3800 int w = physDev->dc_rect.right - physDev->dc_rect.left;
3801 int h = physDev->dc_rect.bottom - physDev->dc_rect.top;
3803 /* (glX)SwapBuffers has an implicit glFlush effect, however
3804 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3808 pglXCopySubBufferMESA(gdi_display, drawable, 0, 0, w, h);
3811 pglXSwapBuffers(gdi_display, drawable);
3814 pglXSwapBuffers(gdi_display, drawable);
3816 flush_gl_drawable(physDev);
3817 wine_tsx11_unlock();
3822 static long prev_time, start_time;
3823 static unsigned long frames, frames_total;
3825 DWORD time = GetTickCount();
3828 /* every 1.5 seconds */
3829 if (time - prev_time > 1500) {
3830 TRACE_(fps)("@ approx %.2ffps, total %.2ffps\n",
3831 1000.0*frames/(time - prev_time), 1000.0*frames_total/(time - start_time));
3834 if(start_time == 0) start_time = time;
3841 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3843 WineGLPixelFormat *fmt;
3846 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id, 0 /* no flags */);
3851 ret = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
3852 wine_tsx11_unlock();
3856 #else /* no OpenGL includes */
3858 void X11DRV_OpenGL_Cleanup(void)
3862 static inline void opengl_error(void)
3865 if (!warned++) ERR("No OpenGL support compiled in.\n");
3868 int pixelformat_from_fbconfig_id(XID fbconfig_id)
3873 void mark_drawable_dirty(Drawable old, Drawable new)
3877 void flush_gl_drawable(X11DRV_PDEVICE *physDev)
3881 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
3886 /***********************************************************************
3887 * ChoosePixelFormat (X11DRV.@)
3889 int CDECL X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
3890 const PIXELFORMATDESCRIPTOR *ppfd) {
3895 /***********************************************************************
3896 * DescribePixelFormat (X11DRV.@)
3898 int CDECL X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
3901 PIXELFORMATDESCRIPTOR *ppfd) {
3906 /***********************************************************************
3907 * GetPixelFormat (X11DRV.@)
3909 int CDECL X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
3914 /***********************************************************************
3915 * SetPixelFormat (X11DRV.@)
3917 BOOL CDECL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
3919 const PIXELFORMATDESCRIPTOR *ppfd) {
3924 /***********************************************************************
3925 * SwapBuffers (X11DRV.@)
3927 BOOL CDECL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
3933 * X11DRV_wglCopyContext
3935 * For OpenGL32 wglCopyContext.
3937 BOOL CDECL X11DRV_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask) {
3943 * X11DRV_wglCreateContext
3945 * For OpenGL32 wglCreateContext.
3947 HGLRC CDECL X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) {
3953 * X11DRV_wglCreateContextAttribsARB
3955 * WGL_ARB_create_context: wglCreateContextAttribsARB
3957 HGLRC CDECL X11DRV_wglCreateContextAttribsARB(X11DRV_PDEVICE *physDev, HGLRC hShareContext, const int* attribList)
3964 * X11DRV_wglDeleteContext
3966 * For OpenGL32 wglDeleteContext.
3968 BOOL CDECL X11DRV_wglDeleteContext(HGLRC hglrc) {
3974 * X11DRV_wglGetProcAddress
3976 * For OpenGL32 wglGetProcAddress.
3978 PROC CDECL X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
3983 HDC CDECL X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *hDevice, void *hPbuffer)
3989 BOOL CDECL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) {
3995 * X11DRV_wglMakeCurrent
3997 * For OpenGL32 wglMakeCurrent.
3999 BOOL CDECL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
4005 * X11DRV_wglShareLists
4007 * For OpenGL32 wglShareLists.
4009 BOOL CDECL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
4015 * X11DRV_wglUseFontBitmapsA
4017 * For OpenGL32 wglUseFontBitmapsA.
4019 BOOL CDECL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
4026 * X11DRV_wglUseFontBitmapsW
4028 * For OpenGL32 wglUseFontBitmapsW.
4030 BOOL CDECL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
4037 * X11DRV_wglSetPixelFormatWINE
4039 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
4040 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
4042 BOOL CDECL X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE *physDev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
4048 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
4053 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
4058 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
4063 #endif /* defined(SONAME_LIBGL) */