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;
118 WineGLPixelFormat *fmt;
119 int numAttribs; /* This is needed for delaying wglCreateContextAttribsARB */
120 int attribList[16]; /* This is needed for delaying wglCreateContextAttribsARB */
123 Drawable drawables[2];
124 BOOL refresh_drawables;
125 struct wine_glcontext *next;
126 struct wine_glcontext *prev;
129 typedef struct wine_glpbuffer {
132 WineGLPixelFormat* fmt;
138 int use_render_texture; /* This is also the internal texture format */
139 int texture_bind_target;
141 GLint texture_format;
142 GLuint texture_target;
148 static Wine_GLContext *context_list;
149 static struct WineGLInfo WineGLInfo = { 0 };
150 static int use_render_texture_emulation = 1;
151 static int use_render_texture_ati = 0;
152 static int swap_interval = 1;
154 #define MAX_EXTENSIONS 16
155 static const WineGLExtension *WineGLExtensionList[MAX_EXTENSIONS];
156 static int WineGLExtensionListSize;
158 static void X11DRV_WineGL_LoadExtensions(void);
159 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count);
160 static BOOL glxRequireVersion(int requiredVersion);
161 static BOOL glxRequireExtension(const char *requiredExtension);
163 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
164 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
165 TRACE(" - dwFlags : ");
166 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
167 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
168 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
169 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
170 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
171 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
172 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
173 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
174 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
175 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
176 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
177 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
178 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
179 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
180 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
181 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
182 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
183 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
184 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
185 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
189 TRACE(" - iPixelType : ");
190 switch (ppfd->iPixelType) {
191 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
192 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
196 TRACE(" - Color : %d\n", ppfd->cColorBits);
197 TRACE(" - Red : %d\n", ppfd->cRedBits);
198 TRACE(" - Green : %d\n", ppfd->cGreenBits);
199 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
200 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
201 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
202 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
203 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
204 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
206 TRACE(" - iLayerType : ");
207 switch (ppfd->iLayerType) {
208 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
209 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
210 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
215 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
216 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
218 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
220 MAKE_FUNCPTR(glXChooseVisual)
221 MAKE_FUNCPTR(glXCopyContext)
222 MAKE_FUNCPTR(glXCreateContext)
223 MAKE_FUNCPTR(glXCreateGLXPixmap)
224 MAKE_FUNCPTR(glXGetCurrentContext)
225 MAKE_FUNCPTR(glXGetCurrentDrawable)
226 MAKE_FUNCPTR(glXDestroyContext)
227 MAKE_FUNCPTR(glXDestroyGLXPixmap)
228 MAKE_FUNCPTR(glXGetConfig)
229 MAKE_FUNCPTR(glXIsDirect)
230 MAKE_FUNCPTR(glXMakeCurrent)
231 MAKE_FUNCPTR(glXSwapBuffers)
232 MAKE_FUNCPTR(glXQueryExtension)
233 MAKE_FUNCPTR(glXQueryVersion)
234 MAKE_FUNCPTR(glXUseXFont)
237 MAKE_FUNCPTR(glXGetClientString)
238 MAKE_FUNCPTR(glXQueryExtensionsString)
239 MAKE_FUNCPTR(glXQueryServerString)
242 MAKE_FUNCPTR(glXGetFBConfigs)
243 MAKE_FUNCPTR(glXChooseFBConfig)
244 MAKE_FUNCPTR(glXCreatePbuffer)
245 MAKE_FUNCPTR(glXCreateNewContext)
246 MAKE_FUNCPTR(glXDestroyPbuffer)
247 MAKE_FUNCPTR(glXGetFBConfigAttrib)
248 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
249 MAKE_FUNCPTR(glXMakeContextCurrent)
250 MAKE_FUNCPTR(glXQueryDrawable)
251 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
254 static GLXContext (*pglXCreateContextAttribsARB)(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
255 static void* (*pglXGetProcAddressARB)(const GLubyte *);
256 static int (*pglXSwapIntervalSGI)(int);
258 /* ATI GLX Extensions */
259 static BOOL (*pglXBindTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
260 static BOOL (*pglXReleaseTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
261 static BOOL (*pglXDrawableAttribATI)(Display *dpy, GLXDrawable draw, const int *attribList);
263 /* NV GLX Extension */
264 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
265 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
267 /* MESA GLX Extensions */
268 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
270 /* Standard OpenGL */
271 MAKE_FUNCPTR(glBindTexture)
272 MAKE_FUNCPTR(glBitmap)
273 MAKE_FUNCPTR(glCopyTexSubImage1D)
274 MAKE_FUNCPTR(glCopyTexImage2D)
275 MAKE_FUNCPTR(glCopyTexSubImage2D)
276 MAKE_FUNCPTR(glDrawBuffer)
277 MAKE_FUNCPTR(glEndList)
278 MAKE_FUNCPTR(glGetError)
279 MAKE_FUNCPTR(glGetIntegerv)
280 MAKE_FUNCPTR(glGetString)
281 MAKE_FUNCPTR(glNewList)
282 MAKE_FUNCPTR(glPixelStorei)
283 MAKE_FUNCPTR(glReadPixels)
284 MAKE_FUNCPTR(glTexImage2D)
285 MAKE_FUNCPTR(glFinish)
286 MAKE_FUNCPTR(glFlush)
289 static int GLXErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
291 /* In the future we might want to find the exact X or GLX error to report back to the app */
295 static BOOL infoInitialized = FALSE;
296 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
298 int screen = DefaultScreen(gdi_display);
299 Window win = RootWindow(gdi_display, screen);
302 GLXContext ctx = NULL;
303 int attribList[] = {GLX_RGBA, GLX_DOUBLEBUFFER, None};
307 infoInitialized = TRUE;
311 vis = pglXChooseVisual(gdi_display, screen, attribList);
314 WORD old_fs = wine_get_fs();
315 /* Create a GLX Context. Without one we can't query GL information */
316 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
317 if (wine_get_fs() != old_fs)
319 wine_set_fs( old_fs );
321 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
322 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
326 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
331 pglXMakeCurrent(gdi_display, win, ctx);
333 ERR(" couldn't initialize OpenGL, expect problems\n");
338 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
339 str = (const char *) pglGetString(GL_EXTENSIONS);
340 WineGLInfo.glExtensions = HeapAlloc(GetProcessHeap(), 0, strlen(str)+1);
341 strcpy(WineGLInfo.glExtensions, str);
343 /* Get the common GLX version supported by GLX client and server ( major/minor) */
344 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
346 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
347 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
348 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
350 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
351 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
352 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
354 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
355 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
357 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
358 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER));
359 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
360 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
361 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
362 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
363 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
364 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
366 if(!WineGLInfo.glxDirect)
368 int fd = ConnectionNumber(gdi_display);
369 struct sockaddr_un uaddr;
370 unsigned int uaddrlen = sizeof(struct sockaddr_un);
372 /* In general indirect rendering on a local X11 server indicates a driver problem.
373 * Detect a local X11 server by checking whether the X11 socket is a Unix socket.
375 if(!getsockname(fd, (struct sockaddr *)&uaddr, &uaddrlen) && uaddr.sun_family == AF_UNIX)
376 ERR_(winediag)("Direct rendering is disabled, most likely your OpenGL drivers haven't been installed correctly\n");
380 /* In general you would expect that if direct rendering is returned, that you receive hardware
381 * accelerated OpenGL rendering. The definition of direct rendering is that rendering is performed
382 * client side without sending all GL commands to X using the GLX protocol. When Mesa falls back to
383 * software rendering, it shows direct rendering.
385 * Depending on the cause of software rendering a different rendering string is shown. In case Mesa fails
386 * to load a DRI module 'Software Rasterizer' is returned. When Mesa is compiled as a OpenGL reference driver
387 * it shows 'Mesa X11'.
389 const char *gl_renderer = (const char *)pglGetString(GL_RENDERER);
390 if(!strcmp(gl_renderer, "Software Rasterizer") || !strcmp(gl_renderer, "Mesa X11"))
391 ERR_(winediag)("The Mesa OpenGL driver is using software rendering, most likely your OpenGL drivers haven't been installed correctly\n");
396 pglXMakeCurrent(gdi_display, None, NULL);
397 pglXDestroyContext(gdi_display, ctx);
403 void X11DRV_OpenGL_Cleanup(void)
405 HeapFree(GetProcessHeap(), 0, WineGLInfo.glExtensions);
406 infoInitialized = FALSE;
409 static BOOL has_opengl(void)
411 static int init_done;
412 static void *opengl_handle;
415 int error_base, event_base;
417 if (init_done) return (opengl_handle != NULL);
420 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
421 and include all dependencies */
422 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, buffer, sizeof(buffer));
423 if (opengl_handle == NULL)
425 ERR( "Failed to load libGL: %s\n", buffer );
426 ERR( "OpenGL support is disabled.\n");
430 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
431 if (pglXGetProcAddressARB == NULL) {
432 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
436 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
438 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
443 LOAD_FUNCPTR(glXChooseVisual);
444 LOAD_FUNCPTR(glXCopyContext);
445 LOAD_FUNCPTR(glXCreateContext);
446 LOAD_FUNCPTR(glXCreateGLXPixmap);
447 LOAD_FUNCPTR(glXGetCurrentContext);
448 LOAD_FUNCPTR(glXGetCurrentDrawable);
449 LOAD_FUNCPTR(glXDestroyContext);
450 LOAD_FUNCPTR(glXDestroyGLXPixmap);
451 LOAD_FUNCPTR(glXGetConfig);
452 LOAD_FUNCPTR(glXIsDirect);
453 LOAD_FUNCPTR(glXMakeCurrent);
454 LOAD_FUNCPTR(glXSwapBuffers);
455 LOAD_FUNCPTR(glXQueryExtension);
456 LOAD_FUNCPTR(glXQueryVersion);
457 LOAD_FUNCPTR(glXUseXFont);
460 LOAD_FUNCPTR(glXGetClientString);
461 LOAD_FUNCPTR(glXQueryExtensionsString);
462 LOAD_FUNCPTR(glXQueryServerString);
465 LOAD_FUNCPTR(glXCreatePbuffer);
466 LOAD_FUNCPTR(glXCreateNewContext);
467 LOAD_FUNCPTR(glXDestroyPbuffer);
468 LOAD_FUNCPTR(glXMakeContextCurrent);
469 LOAD_FUNCPTR(glXGetCurrentReadDrawable);
470 LOAD_FUNCPTR(glXGetFBConfigs);
472 /* Standard OpenGL calls */
473 LOAD_FUNCPTR(glBindTexture);
474 LOAD_FUNCPTR(glBitmap);
475 LOAD_FUNCPTR(glCopyTexSubImage1D);
476 LOAD_FUNCPTR(glCopyTexImage2D);
477 LOAD_FUNCPTR(glCopyTexSubImage2D);
478 LOAD_FUNCPTR(glDrawBuffer);
479 LOAD_FUNCPTR(glEndList);
480 LOAD_FUNCPTR(glGetError);
481 LOAD_FUNCPTR(glGetIntegerv);
482 LOAD_FUNCPTR(glGetString);
483 LOAD_FUNCPTR(glNewList);
484 LOAD_FUNCPTR(glPixelStorei);
485 LOAD_FUNCPTR(glReadPixels);
486 LOAD_FUNCPTR(glTexImage2D);
487 LOAD_FUNCPTR(glFinish);
488 LOAD_FUNCPTR(glFlush);
491 /* It doesn't matter if these fail. They'll only be used if the driver reports
492 the associated extension is available (and if a driver reports the extension
493 is available but fails to provide the functions, it's quite broken) */
494 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)
495 /* ARB GLX Extension */
496 LOAD_FUNCPTR(glXCreateContextAttribsARB);
497 /* NV GLX Extension */
498 LOAD_FUNCPTR(glXAllocateMemoryNV);
499 LOAD_FUNCPTR(glXFreeMemoryNV);
502 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed;
505 if (pglXQueryExtension(gdi_display, &error_base, &event_base)) {
506 TRACE("GLX is up and running error_base = %d\n", error_base);
509 ERR( "GLX extension is missing, disabling OpenGL.\n" );
513 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
514 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
517 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
518 * depends on the reported GLX client / server version and on the client / server extension list.
519 * Those don't have to be the same.
521 * In general the server GLX information lists the capabilities in case of indirect rendering.
522 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
523 * available and in that case the client GLX informat can be used.
524 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
525 * in the GLX version/extension list. When a program does this it works for certain for both
526 * direct and indirect rendering.
528 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
529 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
530 * extension list which causes this extension not to be listed. (Wine requires this extension).
531 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
532 * pbuffers is around.
534 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
535 * the ATI drivers and from then on use GLX client information for them.
538 if(glxRequireVersion(3)) {
539 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
540 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
541 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
542 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
543 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
544 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
545 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
546 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
548 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
549 * enable this function when the Xserver understand GLX 1.3 or newer
551 pglXQueryDrawable = NULL;
552 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
553 TRACE("Overriding ATI GLX capabilities!\n");
554 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
555 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
556 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
557 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
559 /* Use client GLX information in case of the ATI drivers. We override the
560 * capabilities over here and not somewhere else as ATI might better their
561 * life in the future. In case they release proper drivers this block of
562 * code won't be called. */
563 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
565 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
568 if(glxRequireExtension("GLX_ATI_render_texture")) {
569 use_render_texture_ati = 1;
570 pglXBindTexImageATI = pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageATI");
571 pglXReleaseTexImageATI = pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageATI");
572 pglXDrawableAttribATI = pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribATI");
575 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
576 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
579 X11DRV_WineGL_LoadExtensions();
585 wine_dlclose(opengl_handle, NULL, 0);
586 opengl_handle = NULL;
590 static inline Wine_GLContext *alloc_context(void)
594 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLContext))))
596 ret->next = context_list;
597 if (context_list) context_list->prev = ret;
603 static inline void free_context(Wine_GLContext *context)
605 if (context->next != NULL) context->next->prev = context->prev;
606 if (context->prev != NULL) context->prev->next = context->next;
607 else context_list = context->next;
609 if (context->vis) XFree(context->vis);
610 HeapFree(GetProcessHeap(), 0, context);
613 static inline BOOL is_valid_context( Wine_GLContext *ctx )
616 for (ptr = context_list; ptr; ptr = ptr->next) if (ptr == ctx) break;
617 return (ptr != NULL);
620 static int describeContext(Wine_GLContext* ctx) {
623 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
624 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
625 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
626 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
627 TRACE(" - VISUAL_ID 0x%x\n", tmp);
632 static BOOL describeDrawable(X11DRV_PDEVICE *physDev) {
634 WineGLPixelFormat *fmt;
637 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physDev->current_pf, TRUE /* Offscreen */, &fmt_count);
638 if(!fmt) return FALSE;
640 TRACE(" HDC %p has:\n", physDev->hdc);
641 TRACE(" - iPixelFormat %d\n", fmt->iPixelFormat);
642 TRACE(" - Drawable %p\n", (void*) get_glxdrawable(physDev));
643 TRACE(" - FBCONFIG_ID 0x%x\n", fmt->fmt_id);
645 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &tmp);
646 TRACE(" - VISUAL_ID 0x%x\n", tmp);
651 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
656 int nvfloatattrib = GLX_DONT_CARE;
657 int pixelattrib = ~0;
659 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
660 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
661 while (iWGLAttr && 0 != iWGLAttr[cur]) {
662 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
664 switch (iWGLAttr[cur]) {
665 case WGL_AUX_BUFFERS_ARB:
666 pop = iWGLAttr[++cur];
667 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
668 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
670 case WGL_COLOR_BITS_ARB:
671 pop = iWGLAttr[++cur];
672 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
673 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
675 case WGL_BLUE_BITS_ARB:
676 pop = iWGLAttr[++cur];
677 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
678 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
680 case WGL_RED_BITS_ARB:
681 pop = iWGLAttr[++cur];
682 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
683 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
685 case WGL_GREEN_BITS_ARB:
686 pop = iWGLAttr[++cur];
687 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
688 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
690 case WGL_ALPHA_BITS_ARB:
691 pop = iWGLAttr[++cur];
692 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
693 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
695 case WGL_DEPTH_BITS_ARB:
696 pop = iWGLAttr[++cur];
697 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
698 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
700 case WGL_STENCIL_BITS_ARB:
701 pop = iWGLAttr[++cur];
702 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
703 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
705 case WGL_DOUBLE_BUFFER_ARB:
706 pop = iWGLAttr[++cur];
707 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
708 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
711 pop = iWGLAttr[++cur];
712 PUSH2(oGLXAttr, GLX_STEREO, pop);
713 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur, pop);
716 case WGL_PIXEL_TYPE_ARB:
717 pop = iWGLAttr[++cur];
718 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
720 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
721 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
722 /* 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 */
723 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
724 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT: pixelattrib = GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT; break ;
726 ERR("unexpected PixelType(%x)\n", pop);
731 case WGL_SUPPORT_GDI_ARB:
732 /* This flag is set in a WineGLPixelFormat */
733 pop = iWGLAttr[++cur];
734 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
737 case WGL_DRAW_TO_BITMAP_ARB:
738 /* This flag is set in a WineGLPixelFormat */
739 pop = iWGLAttr[++cur];
740 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
743 case WGL_DRAW_TO_WINDOW_ARB:
744 pop = iWGLAttr[++cur];
745 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
746 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
748 drawattrib |= GLX_WINDOW_BIT;
752 case WGL_DRAW_TO_PBUFFER_ARB:
753 pop = iWGLAttr[++cur];
754 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
755 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
757 drawattrib |= GLX_PBUFFER_BIT;
761 case WGL_ACCELERATION_ARB:
762 /* This flag is set in a WineGLPixelFormat */
763 pop = iWGLAttr[++cur];
764 TRACE("pAttr[%d] = WGL_ACCELERATION_ARB: %d\n", cur, pop);
767 case WGL_SUPPORT_OPENGL_ARB:
768 pop = iWGLAttr[++cur];
769 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
770 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
773 case WGL_SWAP_METHOD_ARB:
774 pop = iWGLAttr[++cur];
775 /* For now we ignore this and just return SWAP_EXCHANGE */
776 TRACE("pAttr[%d] = WGL_SWAP_METHOD_ARB: %#x\n", cur, pop);
779 case WGL_PBUFFER_LARGEST_ARB:
780 pop = iWGLAttr[++cur];
781 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
782 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
785 case WGL_SAMPLE_BUFFERS_ARB:
786 pop = iWGLAttr[++cur];
787 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
788 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
791 case WGL_SAMPLES_ARB:
792 pop = iWGLAttr[++cur];
793 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
794 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
797 case WGL_TEXTURE_FORMAT_ARB:
798 case WGL_TEXTURE_TARGET_ARB:
799 case WGL_MIPMAP_TEXTURE_ARB:
800 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
801 pop = iWGLAttr[++cur];
803 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
805 if (use_render_texture_ati) {
806 /** nothing to do here */
808 else if (!use_render_texture_emulation) {
809 if (WGL_NO_TEXTURE_ARB != pop) {
810 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
811 return -1; /** error: don't support it */
813 drawattrib |= GLX_PBUFFER_BIT;
817 case WGL_FLOAT_COMPONENTS_NV:
818 nvfloatattrib = iWGLAttr[++cur];
819 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
821 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
822 case WGL_BIND_TO_TEXTURE_RGB_ARB:
823 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
824 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
825 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
826 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
827 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
828 pop = iWGLAttr[++cur];
829 /** cannot be converted, see direct handling on
830 * - wglGetPixelFormatAttribivARB
831 * TODO: wglChoosePixelFormat
834 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
835 pop = iWGLAttr[++cur];
836 PUSH2(oGLXAttr, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, pop);
837 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur, pop);
840 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
841 pop = iWGLAttr[++cur];
842 PUSH2(oGLXAttr, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT, pop);
843 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur, pop);
846 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
852 /* By default glXChooseFBConfig defaults to GLX_WINDOW_BIT. wglChoosePixelFormatARB searches through
853 * all formats. Unless drawattrib is set to a non-zero value override it with ~0, so that pixmap and pbuffer
854 * formats appear as well. */
855 if(!drawattrib) drawattrib = ~0;
856 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
857 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
859 /* By default glXChooseFBConfig uses GLX_RGBA_BIT as the default value. Since wglChoosePixelFormatARB
860 * searches in all formats we have to do the same. For this reason we set GLX_RENDER_TYPE to ~0 unless
861 * it is overridden. */
862 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
863 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
865 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
866 if(strstr(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
867 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
868 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
874 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
876 int render_type=0, render_type_bit;
877 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
878 switch(render_type_bit)
881 render_type = GLX_RGBA_TYPE;
883 case GLX_COLOR_INDEX_BIT:
884 render_type = GLX_COLOR_INDEX_TYPE;
886 case GLX_RGBA_FLOAT_BIT:
887 render_type = GLX_RGBA_FLOAT_TYPE;
889 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT:
890 render_type = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
893 ERR("Unknown render_type: %x\n", render_type);
898 /* Check whether a fbconfig is suitable for Windows-style bitmap rendering */
899 static BOOL check_fbconfig_bitmap_capability(Display *display, GLXFBConfig fbconfig)
902 pglXGetFBConfigAttrib(display, fbconfig, GLX_DOUBLEBUFFER, &dbuf);
903 pglXGetFBConfigAttrib(gdi_display, fbconfig, GLX_DRAWABLE_TYPE, &value);
905 /* Windows only supports bitmap rendering on single buffered formats, further the fbconfig needs to have
906 * the GLX_PIXMAP_BIT set. */
907 return !dbuf && (value & GLX_PIXMAP_BIT);
910 static WineGLPixelFormat *get_formats(Display *display, int *size_ret, int *onscreen_size_ret)
912 static WineGLPixelFormat *list;
913 static int size, onscreen_size;
915 int fmt_id, nCfgs, i, run, bmp_formats;
917 XVisualInfo *visinfo;
922 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
923 if (NULL == cfgs || 0 == nCfgs) {
924 if(cfgs != NULL) XFree(cfgs);
926 ERR("glXChooseFBConfig returns NULL\n");
930 /* Bitmap rendering on Windows implies the use of the Microsoft GDI software renderer.
931 * Further most GLX drivers only offer pixmap rendering using indirect rendering (except for modern drivers which support 'AIGLX' / composite).
932 * Indirect rendering can indicate software rendering (on Nvidia it is hw accelerated)
933 * Since bitmap rendering implies the use of software rendering we can safely use indirect rendering for bitmaps.
935 * Below we count the number of formats which are suitable for bitmap rendering. Windows restricts bitmap rendering to single buffered formats.
937 for(i=0, bmp_formats=0; i<nCfgs; i++)
939 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
942 TRACE("Found %d bitmap capable fbconfigs\n", bmp_formats);
944 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nCfgs + bmp_formats)*sizeof(WineGLPixelFormat));
946 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
947 * Do this as GLX doesn't guarantee that the list is sorted */
948 for(run=0; run < 2; run++)
950 for(i=0; i<nCfgs; i++) {
951 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
952 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
954 /* The first run we only add onscreen formats (ones which have an associated X Visual).
955 * The second run we only set offscreen formats. */
958 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
959 * The contents is copied to the destination using XCopyArea. For the copying to work
960 * the depth of the source and destination window should be the same. In general this should
961 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
962 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
963 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
964 * list formats with the same depth. */
965 if(visinfo->depth != screen_depth)
971 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
972 list[size].iPixelFormat = size+1; /* The index starts at 1 */
973 list[size].fbconfig = cfgs[i];
974 list[size].fmt_id = fmt_id;
975 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
976 list[size].offscreenOnly = FALSE;
977 list[size].dwFlags = 0;
981 /* Clone a format if it is bitmap capable for indirect rendering to bitmaps */
982 if(check_fbconfig_bitmap_capability(display, cfgs[i]))
984 TRACE("Found bitmap capable format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
985 list[size].iPixelFormat = size+1; /* The index starts at 1 */
986 list[size].fbconfig = cfgs[i];
987 list[size].fmt_id = fmt_id;
988 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
989 list[size].offscreenOnly = FALSE;
990 list[size].dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_GENERIC_FORMAT;
994 } else if(run && !visinfo) {
995 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
996 list[size].iPixelFormat = size+1; /* The index starts at 1 */
997 list[size].fbconfig = cfgs[i];
998 list[size].fmt_id = fmt_id;
999 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
1000 list[size].offscreenOnly = TRUE;
1001 list[size].dwFlags = 0;
1005 if (visinfo) XFree(visinfo);
1009 if(cfgs != NULL) XFree(cfgs);
1012 if (size_ret) *size_ret = size;
1013 if (onscreen_size_ret) *onscreen_size_ret = onscreen_size;
1014 wine_tsx11_unlock();
1018 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
1019 * In our WGL implementation we only support a subset of these formats namely the format of
1020 * Wine's main visual and offscreen formats (if they are available).
1021 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
1022 * and it returns the number of supported WGL formats in fmt_count.
1024 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count)
1026 WineGLPixelFormat *list, *res = NULL;
1027 int size, onscreen_size;
1029 if (!(list = get_formats(display, &size, &onscreen_size ))) return NULL;
1031 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
1032 * iPixelFormat in case of probing the number of pixelformats.
1034 if((iPixelFormat > 0) && (iPixelFormat <= size) &&
1035 (!list[iPixelFormat-1].offscreenOnly || AllowOffscreen)) {
1036 res = &list[iPixelFormat-1];
1037 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res->fbconfig, iPixelFormat);
1043 *fmt_count = onscreen_size;
1045 TRACE("Number of returned pixelformats=%d\n", *fmt_count);
1050 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1051 static WineGLPixelFormat* ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id, DWORD dwFlags)
1053 WineGLPixelFormat *list;
1056 if (!(list = get_formats(display, &size, NULL ))) return NULL;
1058 for(i=0; i<size; i++) {
1059 /* A GLX format can appear multiple times in the pixel format list due to fake formats for bitmap rendering.
1060 * Fake formats might get selected when the user passes the proper flags using the dwFlags parameter. */
1061 if( (list[i].fmt_id == fmt_id) && ((list[i].dwFlags & dwFlags) == dwFlags) ) {
1062 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list[i].iPixelFormat, fmt_id);
1066 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id);
1070 int pixelformat_from_fbconfig_id(XID fbconfig_id)
1072 WineGLPixelFormat *fmt;
1074 if (!fbconfig_id) return 0;
1076 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id, 0 /* no flags */);
1078 return fmt->iPixelFormat;
1079 /* This will happen on hwnds without a pixel format set; it's ok */
1084 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
1085 void mark_drawable_dirty(Drawable old, Drawable new)
1087 Wine_GLContext *ctx;
1088 for (ctx = context_list; ctx; ctx = ctx->next) {
1089 if (old == ctx->drawables[0]) {
1090 ctx->drawables[0] = new;
1091 ctx->refresh_drawables = TRUE;
1093 if (old == ctx->drawables[1]) {
1094 ctx->drawables[1] = new;
1095 ctx->refresh_drawables = TRUE;
1100 /* Given the current context, make sure its drawable is sync'd */
1101 static inline void sync_context(Wine_GLContext *context)
1103 if(context && context->refresh_drawables) {
1104 if (glxRequireVersion(3))
1105 pglXMakeContextCurrent(gdi_display, context->drawables[0],
1106 context->drawables[1], context->ctx);
1108 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
1109 context->refresh_drawables = FALSE;
1114 static GLXContext create_glxcontext(Display *display, Wine_GLContext *context, GLXContext shareList)
1118 /* We use indirect rendering for rendering to bitmaps. See get_formats for a comment about this. */
1119 BOOL indirect = (context->fmt->dwFlags & PFD_DRAW_TO_BITMAP) ? FALSE : TRUE;
1121 if(context->gl3_context)
1123 if(context->numAttribs)
1124 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, context->attribList);
1126 ctx = pglXCreateContextAttribsARB(gdi_display, context->fmt->fbconfig, shareList, indirect, NULL);
1128 else if(context->vis)
1129 ctx = pglXCreateContext(gdi_display, context->vis, shareList, indirect);
1130 else /* Create a GLX Context for a pbuffer */
1131 ctx = pglXCreateNewContext(gdi_display, context->fmt->fbconfig, context->fmt->render_type, shareList, TRUE);
1137 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
1139 return pglXCreateGLXPixmap(display, vis, parent);
1143 static XID create_bitmap_glxpixmap(X11DRV_PDEVICE *physDev, WineGLPixelFormat *fmt)
1150 vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1152 if(vis->depth == physDev->bitmap->pixmap_depth)
1153 ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
1156 wine_tsx11_unlock();
1157 TRACE("return %lx\n", ret);
1162 * X11DRV_ChoosePixelFormat
1164 * Equivalent to glXChooseVisual.
1166 int CDECL X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
1167 const PIXELFORMATDESCRIPTOR *ppfd) {
1168 WineGLPixelFormat *list;
1173 int bestFormat = -1;
1174 int bestDBuffer = -1;
1175 int bestStereo = -1;
1179 int bestStencil = -1;
1182 if (!has_opengl()) return 0;
1184 if (TRACE_ON(wgl)) {
1185 TRACE("(%p,%p)\n", physDev, ppfd);
1187 dump_PIXELFORMATDESCRIPTOR(ppfd);
1190 if (!(list = get_formats(gdi_display, NULL, &onscreen_size ))) return 0;
1193 for(i=0; i<onscreen_size; i++)
1197 int alpha=0, color=0, depth=0, stencil=0, aux=0;
1198 WineGLPixelFormat *fmt = &list[i];
1201 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1202 if (value & GLX_RGBA_BIT)
1203 iPixelType = PFD_TYPE_RGBA;
1205 iPixelType = PFD_TYPE_COLORINDEX;
1207 if (ppfd->iPixelType != iPixelType)
1209 TRACE("pixel type mismatch for iPixelFormat=%d\n", i+1);
1213 /* Only use bitmap capable for formats for bitmap rendering.
1214 * See get_formats for more info. */
1215 if( (ppfd->dwFlags & PFD_DRAW_TO_BITMAP) != (fmt->dwFlags & PFD_DRAW_TO_BITMAP))
1217 TRACE("PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i+1);
1221 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1222 if (value) dwFlags |= PFD_DOUBLEBUFFER;
1223 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value);
1224 if (value) dwFlags |= PFD_STEREO;
1225 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &color); /* cColorBits */
1226 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &alpha); /* cAlphaBits */
1227 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &depth); /* cDepthBits */
1228 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &stencil); /* cStencilBits */
1229 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &aux); /* cAuxBuffers */
1231 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1232 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1233 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1234 * formats without the given flag set.
1235 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1236 * has indicated that a format without stereo is returned when stereo is unavailable.
1237 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1238 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1240 * To summarize the following is most likely the correct behavior:
1241 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1242 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1243 * stereo don't care -> it doesn't matter whether we get stereo or not
1245 * In Wine we will treat no-stereo the same way as don't care because it makes
1246 * format selection even more complicated and second drivers with Stereo advertise
1247 * each format twice anyway.
1250 /* Doublebuffer, see the comments above */
1251 if( !(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) ) {
1252 if( ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) &&
1253 ((dwFlags & PFD_DOUBLEBUFFER) == (ppfd->dwFlags & PFD_DOUBLEBUFFER)) )
1255 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1256 bestStereo = dwFlags & PFD_STEREO;
1260 bestStencil = stencil;
1265 if(bestDBuffer != -1 && (dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer)
1269 /* Stereo, see the comments above. */
1270 if( !(ppfd->dwFlags & PFD_STEREO_DONTCARE) ) {
1271 if( ((ppfd->dwFlags & PFD_STEREO) != bestStereo) &&
1272 ((dwFlags & PFD_STEREO) == (ppfd->dwFlags & PFD_STEREO)) )
1274 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1275 bestStereo = dwFlags & PFD_STEREO;
1279 bestStencil = stencil;
1284 if(bestStereo != -1 && (dwFlags & PFD_STEREO) != bestStereo)
1288 /* Below we will do a number of checks to select the 'best' pixelformat.
1289 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1290 * The code works by trying to match the most important options as close as possible.
1291 * When a reasonable format is found, we will try to match more options.
1292 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1293 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1294 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1297 if(ppfd->cColorBits) {
1298 if( ((ppfd->cColorBits > bestColor) && (color > bestColor)) ||
1299 ((color >= ppfd->cColorBits) && (color < bestColor)) )
1301 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1302 bestStereo = dwFlags & PFD_STEREO;
1306 bestStencil = stencil;
1310 } else if(bestColor != color) { /* Do further checks if the format is compatible */
1311 TRACE("color mismatch for iPixelFormat=%d\n", i+1);
1317 if(ppfd->cAlphaBits) {
1318 if( ((ppfd->cAlphaBits > bestAlpha) && (alpha > bestAlpha)) ||
1319 ((alpha >= ppfd->cAlphaBits) && (alpha < bestAlpha)) )
1321 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1322 bestStereo = dwFlags & PFD_STEREO;
1326 bestStencil = stencil;
1330 } else if(bestAlpha != alpha) {
1331 TRACE("alpha mismatch for iPixelFormat=%d\n", i+1);
1337 if(ppfd->cDepthBits) {
1338 if( ((ppfd->cDepthBits > bestDepth) && (depth > bestDepth)) ||
1339 ((depth >= ppfd->cDepthBits) && (depth < bestDepth)) )
1341 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1342 bestStereo = dwFlags & PFD_STEREO;
1346 bestStencil = stencil;
1350 } else if(bestDepth != depth) {
1351 TRACE("depth mismatch for iPixelFormat=%d\n", i+1);
1357 if(ppfd->cStencilBits) {
1358 if( ((ppfd->cStencilBits > bestStencil) && (stencil > bestStencil)) ||
1359 ((stencil >= ppfd->cStencilBits) && (stencil < bestStencil)) )
1361 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1362 bestStereo = dwFlags & PFD_STEREO;
1366 bestStencil = stencil;
1370 } else if(bestStencil != stencil) {
1371 TRACE("stencil mismatch for iPixelFormat=%d\n", i+1);
1377 if(ppfd->cAuxBuffers) {
1378 if( ((ppfd->cAuxBuffers > bestAux) && (aux > bestAux)) ||
1379 ((aux >= ppfd->cAuxBuffers) && (aux < bestAux)) )
1381 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1382 bestStereo = dwFlags & PFD_STEREO;
1386 bestStencil = stencil;
1390 } else if(bestAux != aux) {
1391 TRACE("aux mismatch for iPixelFormat=%d\n", i+1);
1397 if(bestFormat == -1) {
1398 TRACE("No matching mode was found returning 0\n");
1402 ret = bestFormat+1; /* the return value should be a 1-based index */
1403 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret, list[bestFormat].fmt_id);
1406 wine_tsx11_unlock();
1411 * X11DRV_DescribePixelFormat
1413 * Get the pixel-format descriptor associated to the given id
1415 int CDECL X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
1418 PIXELFORMATDESCRIPTOR *ppfd) {
1419 /*XVisualInfo *vis;*/
1422 WineGLPixelFormat *fmt;
1426 if (!has_opengl()) return 0;
1428 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
1430 /* 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 */
1431 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_count);
1433 /* The application is only querying the number of pixelformats */
1435 } else if(fmt == NULL) {
1436 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1440 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1441 ERR("Wrong structure size !\n");
1442 /* Should set error */
1448 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1449 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1452 /* These flags are always the same... */
1453 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1454 /* Now the flags extracted from the Visual */
1458 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1459 if(value & GLX_WINDOW_BIT)
1460 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1462 /* On Windows bitmap rendering is only offered using the GDI Software renderer. We reserve some formats (see get_formats for more info)
1463 * for bitmap rendering since we require indirect rendering for this. Further pixel format logs of a GeforceFX, Geforce8800GT, Radeon HD3400 and a
1464 * 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
1465 * offered the GDI bit either. */
1466 ppfd->dwFlags |= fmt->dwFlags & (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI);
1468 /* PFD_GENERIC_FORMAT - gdi software rendering
1469 * PFD_GENERIC_ACCELERATED - some parts are accelerated by a display driver (MCD e.g. 3dfx minigl)
1470 * none set - full hardware accelerated by a ICD
1472 * We only set PFD_GENERIC_FORMAT on bitmap formats (see get_formats) as that's what ATI and Nvidia Windows drivers do */
1473 ppfd->dwFlags |= fmt->dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED);
1475 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1477 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1478 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1480 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1483 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1484 if (value & GLX_RGBA_BIT)
1485 ppfd->iPixelType = PFD_TYPE_RGBA;
1487 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1490 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1491 ppfd->cColorBits = value;
1493 /* Red, green, blue and alpha bits / shifts */
1494 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1495 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1496 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1497 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1498 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1500 ppfd->cRedBits = rb;
1501 ppfd->cRedShift = gb + bb + ab;
1502 ppfd->cBlueBits = bb;
1503 ppfd->cBlueShift = ab;
1504 ppfd->cGreenBits = gb;
1505 ppfd->cGreenShift = bb + ab;
1506 ppfd->cAlphaBits = ab;
1507 ppfd->cAlphaShift = 0;
1510 ppfd->cRedShift = 0;
1511 ppfd->cBlueBits = 0;
1512 ppfd->cBlueShift = 0;
1513 ppfd->cGreenBits = 0;
1514 ppfd->cGreenShift = 0;
1515 ppfd->cAlphaBits = 0;
1516 ppfd->cAlphaShift = 0;
1519 /* Accum RGBA bits */
1520 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1521 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1522 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1523 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1525 ppfd->cAccumBits = rb+gb+bb+ab;
1526 ppfd->cAccumRedBits = rb;
1527 ppfd->cAccumGreenBits = gb;
1528 ppfd->cAccumBlueBits = bb;
1529 ppfd->cAccumAlphaBits = ab;
1532 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1533 ppfd->cAuxBuffers = value;
1536 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1537 ppfd->cDepthBits = value;
1540 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1541 ppfd->cStencilBits = value;
1543 wine_tsx11_unlock();
1545 ppfd->iLayerType = PFD_MAIN_PLANE;
1547 if (TRACE_ON(wgl)) {
1548 dump_PIXELFORMATDESCRIPTOR(ppfd);
1555 * X11DRV_GetPixelFormat
1557 * Get the pixel-format id used by this DC
1559 int CDECL X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
1560 WineGLPixelFormat *fmt;
1562 TRACE("(%p)\n", physDev);
1564 if (!physDev->current_pf) return 0; /* not set yet */
1566 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physDev->current_pf, TRUE, &tmp);
1569 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev->current_pf);
1572 else if(fmt->offscreenOnly)
1574 /* Offscreen formats can't be used with traditional WGL calls.
1575 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1576 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt->iPixelFormat);
1580 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1581 return physDev->current_pf;
1584 /* This function is the core of X11DRV_SetPixelFormat and X11DRV_SetPixelFormatWINE.
1585 * Both functions are the same except that X11DRV_SetPixelFormatWINE allows you to
1586 * set the pixel format multiple times. */
1587 static BOOL internal_SetPixelFormat(X11DRV_PDEVICE *physDev,
1589 const PIXELFORMATDESCRIPTOR *ppfd) {
1590 WineGLPixelFormat *fmt;
1594 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1595 if(get_glxdrawable(physDev) == root_window)
1597 ERR("Invalid operation on root_window\n");
1601 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1602 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
1604 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1609 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1610 wine_tsx11_unlock();
1612 hwnd = WindowFromDC(physDev->hdc);
1614 if(!(value&GLX_WINDOW_BIT)) {
1615 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1619 if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, fmt->fmt_id, 0)) {
1620 ERR("Couldn't set format of the window, returning failure\n");
1624 else if(physDev->bitmap) {
1625 if(!(value&GLX_PIXMAP_BIT)) {
1626 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat);
1630 physDev->bitmap->glxpixmap = create_bitmap_glxpixmap(physDev, fmt);
1631 if(!physDev->bitmap->glxpixmap) {
1632 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat);
1637 FIXME("called on a non-window, non-bitmap object?\n");
1640 physDev->current_pf = iPixelFormat;
1642 if (TRACE_ON(wgl)) {
1646 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1648 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1650 TRACE(" FBConfig have :\n");
1651 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1652 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1653 TRACE(" - VISUAL_ID 0x%x\n", value);
1654 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1655 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1657 wine_tsx11_unlock();
1664 * X11DRV_SetPixelFormat
1666 * Set the pixel-format id used by this DC
1668 BOOL CDECL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
1670 const PIXELFORMATDESCRIPTOR *ppfd) {
1671 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1673 if (!has_opengl()) return FALSE;
1675 if(physDev->current_pf) /* cannot change it if already set */
1676 return (physDev->current_pf == iPixelFormat);
1678 return internal_SetPixelFormat(physDev, iPixelFormat, ppfd);
1682 * X11DRV_wglCopyContext
1684 * For OpenGL32 wglCopyContext.
1686 BOOL CDECL X11DRV_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask) {
1687 Wine_GLContext *src = (Wine_GLContext*)hglrcSrc;
1688 Wine_GLContext *dst = (Wine_GLContext*)hglrcDst;
1690 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc, hglrcDst, mask);
1693 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1694 wine_tsx11_unlock();
1696 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1701 * X11DRV_wglCreateContext
1703 * For OpenGL32 wglCreateContext.
1705 HGLRC CDECL X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
1707 Wine_GLContext *ret;
1708 WineGLPixelFormat *fmt;
1709 int hdcPF = physDev->current_pf;
1711 HDC hdc = physDev->hdc;
1713 TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1715 if (!has_opengl()) return 0;
1717 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, TRUE /* Offscreen */, &fmt_count);
1718 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1719 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1720 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1721 * If this fails something is very wrong on the system. */
1723 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF);
1724 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1729 ret = alloc_context();
1732 ret->has_been_current = FALSE;
1733 ret->sharing = FALSE;
1735 ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1736 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
1737 wine_tsx11_unlock();
1739 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1744 * X11DRV_wglDeleteContext
1746 * For OpenGL32 wglDeleteContext.
1748 BOOL CDECL X11DRV_wglDeleteContext(HGLRC hglrc)
1750 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1753 TRACE("(%p)\n", hglrc);
1755 if (!has_opengl()) return 0;
1758 /* A game (Half Life not to name it) deletes twice the same context,
1759 * so make sure it is valid first */
1760 if (is_valid_context( ctx ))
1762 if (ctx->ctx) pglXDestroyContext(gdi_display, ctx->ctx);
1767 WARN("Error deleting context !\n");
1768 SetLastError(ERROR_INVALID_HANDLE);
1771 wine_tsx11_unlock();
1777 * X11DRV_wglGetCurrentReadDCARB
1779 * For OpenGL32 wglGetCurrentReadDCARB.
1781 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1784 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1786 if (ctx) ret = ctx->read_hdc;
1788 TRACE(" returning %p (GL drawable %lu)\n", ret, ctx ? ctx->drawables[1] : 0);
1793 * X11DRV_wglGetProcAddress
1795 * For OpenGL32 wglGetProcAddress.
1797 PROC CDECL X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1800 const WineGLExtension *ext;
1802 int padding = 32 - strlen(lpszProc);
1806 if (!has_opengl()) return NULL;
1808 /* Check the table of WGL extensions to see if we need to return a WGL extension
1809 * or a function pointer to a native OpenGL function. */
1810 if(strncmp(lpszProc, "wgl", 3) != 0) {
1811 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1813 TRACE("('%s'):%*s", lpszProc, padding, " ");
1814 for (i = 0; i < WineGLExtensionListSize; ++i) {
1815 ext = WineGLExtensionList[i];
1816 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1817 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1818 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1819 return ext->extEntryPoints[j].funcAddress;
1825 WARN("(%s) - not found\n", lpszProc);
1830 * X11DRV_wglMakeCurrent
1832 * For OpenGL32 wglMakeCurrent.
1834 BOOL CDECL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
1836 HDC hdc = physDev->hdc;
1837 DWORD type = GetObjectType(hdc);
1838 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1840 TRACE("(%p,%p)\n", hdc, hglrc);
1842 if (!has_opengl()) return FALSE;
1845 if (hglrc == NULL) {
1846 ret = pglXMakeCurrent(gdi_display, None, NULL);
1847 NtCurrentTeb()->glContext = NULL;
1848 } else if (ctx->fmt->iPixelFormat != physDev->current_pf) {
1849 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1850 hdc, physDev->current_pf, ctx, ctx->fmt->iPixelFormat );
1851 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1854 Drawable drawable = get_glxdrawable(physDev);
1856 /* The describe lines below are for debugging purposes only */
1857 if (TRACE_ON(wgl)) {
1858 describeDrawable(physDev);
1859 describeContext(ctx);
1862 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display, (void*) drawable, ctx->ctx);
1863 ret = pglXMakeCurrent(gdi_display, drawable, ctx->ctx);
1864 NtCurrentTeb()->glContext = ctx;
1868 ctx->has_been_current = TRUE;
1870 ctx->read_hdc = hdc;
1871 ctx->drawables[0] = drawable;
1872 ctx->drawables[1] = drawable;
1873 ctx->refresh_drawables = FALSE;
1875 if (type == OBJ_MEMDC)
1877 ctx->do_escape = TRUE;
1878 pglDrawBuffer(GL_FRONT_LEFT);
1882 wine_tsx11_unlock();
1883 TRACE(" returning %s\n", (ret ? "True" : "False"));
1888 * X11DRV_wglMakeContextCurrentARB
1890 * For OpenGL32 wglMakeContextCurrentARB
1892 BOOL CDECL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* pDrawDev, X11DRV_PDEVICE* pReadDev, HGLRC hglrc)
1896 TRACE("(%p,%p,%p)\n", pDrawDev, pReadDev, hglrc);
1898 if (!has_opengl()) return 0;
1901 if (hglrc == NULL) {
1902 ret = pglXMakeCurrent(gdi_display, None, NULL);
1903 NtCurrentTeb()->glContext = NULL;
1905 if (NULL == pglXMakeContextCurrent) {
1908 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1909 Drawable d_draw = get_glxdrawable(pDrawDev);
1910 Drawable d_read = get_glxdrawable(pReadDev);
1912 ctx->has_been_current = TRUE;
1913 ctx->hdc = pDrawDev->hdc;
1914 ctx->read_hdc = pReadDev->hdc;
1915 ctx->drawables[0] = d_draw;
1916 ctx->drawables[1] = d_read;
1917 ctx->refresh_drawables = FALSE;
1918 ret = pglXMakeContextCurrent(gdi_display, d_draw, d_read, ctx->ctx);
1919 NtCurrentTeb()->glContext = ctx;
1922 wine_tsx11_unlock();
1924 TRACE(" returning %s\n", (ret ? "True" : "False"));
1929 * X11DRV_wglShareLists
1931 * For OpenGL32 wglShareLists.
1933 BOOL CDECL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
1934 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1935 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1937 TRACE("(%p, %p)\n", org, dest);
1939 if (!has_opengl()) return FALSE;
1941 /* Sharing of display lists works differently in GLX and WGL. In case of GLX it is done
1942 * at context creation time but in case of WGL it is done using wglShareLists.
1943 * In the past we tried to emulate wglShareLists by delaying GLX context creation until
1944 * either a wglMakeCurrent or wglShareLists. This worked fine for most apps but it causes
1945 * issues for OpenGL 3 because there wglCreateContextAttribsARB can fail in a lot of cases,
1946 * so there delaying context creation doesn't work.
1948 * The new approach is to create a GLX context in wglCreateContext / wglCreateContextAttribsARB
1949 * and when a program requests sharing we recreate the destination context if it hasn't been made
1950 * current or when it hasn't shared display lists before.
1953 if((org->has_been_current && dest->has_been_current) || dest->has_been_current)
1955 ERR("Could not share display lists, one of the contexts has been current already !\n");
1958 else if(dest->sharing)
1960 ERR("Could not share display lists because hglrc2 has already shared lists before\n");
1965 if((GetObjectType(org->hdc) == OBJ_MEMDC) ^ (GetObjectType(dest->hdc) == OBJ_MEMDC))
1967 WARN("Attempting to share a context between a direct and indirect rendering context, expect issues!\n");
1971 describeContext(org);
1972 describeContext(dest);
1974 /* Re-create the GLX context and share display lists */
1975 pglXDestroyContext(gdi_display, dest->ctx);
1976 dest->ctx = create_glxcontext(gdi_display, dest, org->ctx);
1977 wine_tsx11_unlock();
1978 TRACE(" re-created an OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1980 org->sharing = TRUE;
1981 dest->sharing = TRUE;
1987 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
1989 /* We are running using client-side rendering fonts... */
1991 unsigned int glyph, size = 0;
1992 void *bitmap = NULL, *gl_bitmap = NULL;
1996 pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1997 pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1998 wine_tsx11_unlock();
2000 for (glyph = first; glyph < first + count; glyph++) {
2001 static const MAT2 identity = { {0,1},{0,0},{0,0},{0,1} };
2002 unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, &identity);
2003 unsigned int height, width_int;
2005 TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
2006 if (needed_size == GDI_ERROR) {
2007 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size);
2010 TRACE(" - needed size : %d\n", needed_size);
2013 if (needed_size > size) {
2015 HeapFree(GetProcessHeap(), 0, bitmap);
2016 HeapFree(GetProcessHeap(), 0, gl_bitmap);
2017 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
2018 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
2020 if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, &identity) == GDI_ERROR)
2022 if (TRACE_ON(wgl)) {
2023 unsigned int height, width, bitmask;
2024 unsigned char *bitmap_ = bitmap;
2026 TRACE(" - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
2027 TRACE(" - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
2028 TRACE(" - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
2029 if (needed_size != 0) {
2030 TRACE(" - bitmap :\n");
2031 for (height = 0; height < gm.gmBlackBoxY; height++) {
2033 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
2038 if (*bitmap_ & bitmask)
2043 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
2049 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
2050 * glyph for it to be drawn properly.
2052 if (needed_size != 0) {
2053 width_int = (gm.gmBlackBoxX + 31) / 32;
2054 for (height = 0; height < gm.gmBlackBoxY; height++) {
2056 for (width = 0; width < width_int; width++) {
2057 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
2058 ((int *) bitmap)[height * width_int + width];
2064 pglNewList(listBase++, GL_COMPILE);
2065 if (needed_size != 0) {
2066 pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
2067 0 - gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - gm.gmptGlyphOrigin.y,
2068 gm.gmCellIncX, gm.gmCellIncY,
2071 /* This is the case of 'empty' glyphs like the space character */
2072 pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
2075 wine_tsx11_unlock();
2079 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
2080 wine_tsx11_unlock();
2082 HeapFree(GetProcessHeap(), 0, bitmap);
2083 HeapFree(GetProcessHeap(), 0, gl_bitmap);
2088 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
2089 wine_tsx11_unlock();
2091 HeapFree(GetProcessHeap(), 0, bitmap);
2092 HeapFree(GetProcessHeap(), 0, gl_bitmap);
2097 * X11DRV_wglUseFontBitmapsA
2099 * For OpenGL32 wglUseFontBitmapsA.
2101 BOOL CDECL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
2103 Font fid = physDev->font;
2105 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
2107 if (!has_opengl()) return FALSE;
2110 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineA);
2114 /* I assume that the glyphs are at the same position for X and for Windows */
2115 pglXUseXFont(fid, first, count, listBase);
2116 wine_tsx11_unlock();
2121 * X11DRV_wglUseFontBitmapsW
2123 * For OpenGL32 wglUseFontBitmapsW.
2125 BOOL CDECL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
2127 Font fid = physDev->font;
2129 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
2131 if (!has_opengl()) return FALSE;
2134 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineW);
2137 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
2140 /* I assume that the glyphs are at the same position for X and for Windows */
2141 pglXUseXFont(fid, first, count, listBase);
2142 wine_tsx11_unlock();
2146 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2147 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params)
2154 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2156 pglGetIntegerv(pname, params);
2158 * if we cannot find a Wine Context
2159 * we only have the default wine desktop context,
2160 * so if we have only a 24 depth say we have 32
2162 if (!ctx && *params == 24) {
2165 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
2170 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2172 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_ALPHA_SIZE, params);
2173 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params);
2177 pglGetIntegerv(pname, params);
2180 wine_tsx11_unlock();
2183 void flush_gl_drawable(X11DRV_PDEVICE *physDev)
2187 if (!physDev->gl_copy)
2190 w = physDev->dc_rect.right - physDev->dc_rect.left;
2191 h = physDev->dc_rect.bottom - physDev->dc_rect.top;
2193 if(w > 0 && h > 0) {
2194 Drawable src = physDev->pixmap;
2195 if(!src) src = physDev->gl_drawable;
2197 /* The GL drawable may be lagged behind if we don't flush first, so
2198 * flush the display make sure we copy up-to-date data */
2200 XFlush(gdi_display);
2201 XSetFunction(gdi_display, physDev->gc, GXcopy);
2202 XCopyArea(gdi_display, src, physDev->drawable, physDev->gc, 0, 0, w, h,
2203 physDev->dc_rect.left, physDev->dc_rect.top);
2204 wine_tsx11_unlock();
2209 static void WINAPI X11DRV_wglFinish(void)
2211 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2212 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2217 wine_tsx11_unlock();
2218 if (ctx) ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2221 static void WINAPI X11DRV_wglFlush(void)
2223 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2224 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2229 wine_tsx11_unlock();
2230 if (ctx) ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2234 * X11DRV_wglCreateContextAttribsARB
2236 * WGL_ARB_create_context: wglCreateContextAttribsARB
2238 HGLRC CDECL X11DRV_wglCreateContextAttribsARB(X11DRV_PDEVICE *physDev, HGLRC hShareContext, const int* attribList)
2240 Wine_GLContext *ret;
2241 WineGLPixelFormat *fmt;
2242 int hdcPF = physDev->current_pf;
2245 TRACE("(%p %p %p)\n", physDev, hShareContext, attribList);
2247 if (!has_opengl()) return 0;
2249 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, TRUE /* Offscreen */, &fmt_count);
2250 /* wglCreateContextAttribsARB supports ALL pixel formats, so also offscreen ones.
2251 * If this fails something is very wrong on the system. */
2254 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF);
2255 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2260 ret = alloc_context();
2261 wine_tsx11_unlock();
2262 ret->hdc = physDev->hdc;
2264 ret->vis = NULL; /* glXCreateContextAttribsARB requires a fbconfig instead of a visual */
2265 ret->gl3_context = TRUE;
2267 ret->numAttribs = 0;
2270 int *pAttribList = (int*)attribList;
2271 int *pContextAttribList = &ret->attribList[0];
2272 /* attribList consists of pairs {token, value] terminated with 0 */
2273 while(pAttribList[0] != 0)
2275 TRACE("%#x %#x\n", pAttribList[0], pAttribList[1]);
2276 switch(pAttribList[0])
2278 case WGL_CONTEXT_MAJOR_VERSION_ARB:
2279 pContextAttribList[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
2280 pContextAttribList[1] = pAttribList[1];
2282 case WGL_CONTEXT_MINOR_VERSION_ARB:
2283 pContextAttribList[0] = GLX_CONTEXT_MINOR_VERSION_ARB;
2284 pContextAttribList[1] = pAttribList[1];
2286 case WGL_CONTEXT_LAYER_PLANE_ARB:
2288 case WGL_CONTEXT_FLAGS_ARB:
2289 pContextAttribList[0] = GLX_CONTEXT_FLAGS_ARB;
2290 pContextAttribList[1] = pAttribList[1];
2292 case WGL_CONTEXT_PROFILE_MASK_ARB:
2293 pContextAttribList[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
2294 pContextAttribList[1] = pAttribList[1];
2297 ERR("Unhandled attribList pair: %#x %#x\n", pAttribList[0], pAttribList[1]);
2302 pContextAttribList += 2;
2307 X11DRV_expect_error(gdi_display, GLXErrorHandler, NULL);
2308 ret->ctx = create_glxcontext(gdi_display, ret, NULL);
2310 XSync(gdi_display, False);
2311 if(X11DRV_check_error() || !ret->ctx)
2313 /* In the future we should convert the GLX error to a win32 one here if needed */
2314 ERR("Context creation failed\n");
2316 wine_tsx11_unlock();
2320 wine_tsx11_unlock();
2321 TRACE(" creating context %p\n", ret);
2326 * X11DRV_wglGetExtensionsStringARB
2328 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2330 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
2331 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2332 return WineGLInfo.wglExtensions;
2336 * X11DRV_wglCreatePbufferARB
2338 * WGL_ARB_pbuffer: wglCreatePbufferARB
2340 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
2342 Wine_GLPBuffer* object = NULL;
2343 WineGLPixelFormat *fmt = NULL;
2348 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2350 if (0 >= iPixelFormat) {
2351 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
2352 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2353 return NULL; /* unexpected error */
2356 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2357 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nCfgs);
2359 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
2360 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2361 goto create_failed; /* unexpected error */
2364 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
2365 if (NULL == object) {
2366 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2367 goto create_failed; /* unexpected error */
2370 object->display = gdi_display;
2371 object->width = iWidth;
2372 object->height = iHeight;
2375 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2376 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2377 while (piAttribList && 0 != *piAttribList) {
2379 switch (*piAttribList) {
2380 case WGL_PBUFFER_LARGEST_ARB: {
2382 attr_v = *piAttribList;
2383 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2384 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2388 case WGL_TEXTURE_FORMAT_ARB: {
2390 attr_v = *piAttribList;
2391 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2392 if (use_render_texture_ati) {
2395 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2396 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
2397 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
2399 SetLastError(ERROR_INVALID_DATA);
2402 object->use_render_texture = 1;
2403 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
2405 if (WGL_NO_TEXTURE_ARB == attr_v) {
2406 object->use_render_texture = 0;
2408 if (!use_render_texture_emulation) {
2409 SetLastError(ERROR_INVALID_DATA);
2413 case WGL_TEXTURE_RGB_ARB:
2414 object->use_render_texture = GL_RGB;
2415 object->texture_bpp = 3;
2416 object->texture_format = GL_RGB;
2417 object->texture_type = GL_UNSIGNED_BYTE;
2419 case WGL_TEXTURE_RGBA_ARB:
2420 object->use_render_texture = GL_RGBA;
2421 object->texture_bpp = 4;
2422 object->texture_format = GL_RGBA;
2423 object->texture_type = GL_UNSIGNED_BYTE;
2426 /* WGL_FLOAT_COMPONENTS_NV */
2427 case WGL_TEXTURE_FLOAT_R_NV:
2428 object->use_render_texture = GL_FLOAT_R_NV;
2429 object->texture_bpp = 4;
2430 object->texture_format = GL_RED;
2431 object->texture_type = GL_FLOAT;
2433 case WGL_TEXTURE_FLOAT_RG_NV:
2434 object->use_render_texture = GL_FLOAT_RG_NV;
2435 object->texture_bpp = 8;
2436 object->texture_format = GL_LUMINANCE_ALPHA;
2437 object->texture_type = GL_FLOAT;
2439 case WGL_TEXTURE_FLOAT_RGB_NV:
2440 object->use_render_texture = GL_FLOAT_RGB_NV;
2441 object->texture_bpp = 12;
2442 object->texture_format = GL_RGB;
2443 object->texture_type = GL_FLOAT;
2445 case WGL_TEXTURE_FLOAT_RGBA_NV:
2446 object->use_render_texture = GL_FLOAT_RGBA_NV;
2447 object->texture_bpp = 16;
2448 object->texture_format = GL_RGBA;
2449 object->texture_type = GL_FLOAT;
2452 ERR("Unknown texture format: %x\n", attr_v);
2453 SetLastError(ERROR_INVALID_DATA);
2461 case WGL_TEXTURE_TARGET_ARB: {
2463 attr_v = *piAttribList;
2464 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2465 if (use_render_texture_ati) {
2468 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2469 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
2470 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
2471 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
2473 SetLastError(ERROR_INVALID_DATA);
2476 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
2478 if (WGL_NO_TEXTURE_ARB == attr_v) {
2479 object->texture_target = 0;
2481 if (!use_render_texture_emulation) {
2482 SetLastError(ERROR_INVALID_DATA);
2486 case WGL_TEXTURE_CUBE_MAP_ARB: {
2487 if (iWidth != iHeight) {
2488 SetLastError(ERROR_INVALID_DATA);
2491 object->texture_target = GL_TEXTURE_CUBE_MAP;
2492 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2495 case WGL_TEXTURE_1D_ARB: {
2497 SetLastError(ERROR_INVALID_DATA);
2500 object->texture_target = GL_TEXTURE_1D;
2501 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2504 case WGL_TEXTURE_2D_ARB: {
2505 object->texture_target = GL_TEXTURE_2D;
2506 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2509 case WGL_TEXTURE_RECTANGLE_NV: {
2510 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2511 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2515 ERR("Unknown texture target: %x\n", attr_v);
2516 SetLastError(ERROR_INVALID_DATA);
2524 case WGL_MIPMAP_TEXTURE_ARB: {
2526 attr_v = *piAttribList;
2527 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2528 if (use_render_texture_ati) {
2529 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
2531 if (!use_render_texture_emulation) {
2532 SetLastError(ERROR_INVALID_DATA);
2542 PUSH1(attribs, None);
2544 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2545 wine_tsx11_unlock();
2546 TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
2547 if (!object->drawable) {
2548 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2549 goto create_failed; /* unexpected error */
2551 TRACE("->(%p)\n", object);
2555 HeapFree(GetProcessHeap(), 0, object);
2556 TRACE("->(FAILED)\n");
2561 * X11DRV_wglDestroyPbufferARB
2563 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2565 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2567 Wine_GLPBuffer* object = hPbuffer;
2568 TRACE("(%p)\n", hPbuffer);
2569 if (NULL == object) {
2570 SetLastError(ERROR_INVALID_HANDLE);
2574 pglXDestroyPbuffer(object->display, object->drawable);
2575 wine_tsx11_unlock();
2576 HeapFree(GetProcessHeap(), 0, object);
2581 * X11DRV_wglGetPbufferDCARB
2583 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2584 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2585 * Gdi32 implements the part of this function which creates a device context.
2586 * This part associates the physDev with the X drawable of the pbuffer.
2588 HDC CDECL X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
2590 Wine_GLPBuffer* object = hPbuffer;
2591 if (NULL == object) {
2592 SetLastError(ERROR_INVALID_HANDLE);
2596 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2597 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2598 physDev->current_pf = object->fmt->iPixelFormat;
2599 physDev->drawable = object->drawable;
2600 SetRect( &physDev->drawable_rect, 0, 0, object->width, object->height );
2601 physDev->dc_rect = physDev->drawable_rect;
2603 TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);
2604 return physDev->hdc;
2608 * X11DRV_wglQueryPbufferARB
2610 * WGL_ARB_pbuffer: wglQueryPbufferARB
2612 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2614 Wine_GLPBuffer* object = hPbuffer;
2615 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2616 if (NULL == object) {
2617 SetLastError(ERROR_INVALID_HANDLE);
2620 switch (iAttribute) {
2621 case WGL_PBUFFER_WIDTH_ARB:
2623 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2624 wine_tsx11_unlock();
2626 case WGL_PBUFFER_HEIGHT_ARB:
2628 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2629 wine_tsx11_unlock();
2632 case WGL_PBUFFER_LOST_ARB:
2633 /* GLX Pbuffers cannot be lost by default. We can support this by
2634 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2635 * to receive pixel buffer clobber events, however that may or may
2636 * not give any benefit */
2637 *piValue = GL_FALSE;
2640 case WGL_TEXTURE_FORMAT_ARB:
2641 if (use_render_texture_ati) {
2643 int type = WGL_NO_TEXTURE_ARB;
2645 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2646 wine_tsx11_unlock();
2648 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2649 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2650 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2654 if (!object->use_render_texture) {
2655 *piValue = WGL_NO_TEXTURE_ARB;
2657 if (!use_render_texture_emulation) {
2658 SetLastError(ERROR_INVALID_HANDLE);
2661 switch(object->use_render_texture) {
2663 *piValue = WGL_TEXTURE_RGB_ARB;
2666 *piValue = WGL_TEXTURE_RGBA_ARB;
2668 /* WGL_FLOAT_COMPONENTS_NV */
2670 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2672 case GL_FLOAT_RG_NV:
2673 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2675 case GL_FLOAT_RGB_NV:
2676 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2678 case GL_FLOAT_RGBA_NV:
2679 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2682 ERR("Unknown texture format: %x\n", object->use_render_texture);
2688 case WGL_TEXTURE_TARGET_ARB:
2689 if (use_render_texture_ati) {
2691 int type = WGL_NO_TEXTURE_ARB;
2693 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2694 wine_tsx11_unlock();
2696 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2697 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2698 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2699 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2703 if (!object->texture_target) {
2704 *piValue = WGL_NO_TEXTURE_ARB;
2706 if (!use_render_texture_emulation) {
2707 SetLastError(ERROR_INVALID_DATA);
2710 switch (object->texture_target) {
2711 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2712 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2713 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2714 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2720 case WGL_MIPMAP_TEXTURE_ARB:
2721 if (use_render_texture_ati) {
2723 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2724 wine_tsx11_unlock();
2726 *piValue = GL_FALSE; /** don't support that */
2727 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2732 FIXME("unexpected attribute %x\n", iAttribute);
2740 * X11DRV_wglReleasePbufferDCARB
2742 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2744 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2746 TRACE("(%p, %p)\n", hPbuffer, hdc);
2747 return DeleteDC(hdc);
2751 * X11DRV_wglSetPbufferAttribARB
2753 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2755 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2757 Wine_GLPBuffer* object = hPbuffer;
2758 GLboolean ret = GL_FALSE;
2760 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2761 if (NULL == object) {
2762 SetLastError(ERROR_INVALID_HANDLE);
2765 if (!object->use_render_texture) {
2766 SetLastError(ERROR_INVALID_HANDLE);
2769 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2772 if (NULL != pglXDrawableAttribATI) {
2773 if (use_render_texture_ati) {
2774 FIXME("Need conversion for GLX_ATI_render_texture\n");
2777 ret = pglXDrawableAttribATI(object->display, object->drawable, piAttribList);
2778 wine_tsx11_unlock();
2784 * X11DRV_wglChoosePixelFormatARB
2786 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2788 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2793 GLXFBConfig* cfgs = NULL;
2797 WineGLPixelFormat *fmt;
2803 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2804 if (NULL != pfAttribFList) {
2805 FIXME("unused pfAttribFList\n");
2808 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2809 if (-1 == nAttribs) {
2810 WARN("Cannot convert WGL to GLX attributes\n");
2813 PUSH1(attribs, None);
2815 /* There is no 1:1 mapping between GLX and WGL formats because we duplicate some GLX formats for bitmap rendering (see get_formats).
2816 * Flags like PFD_SUPPORT_GDI, PFD_DRAW_TO_BITMAP and others are a property of the WineGLPixelFormat. We don't query these attributes
2817 * using glXChooseFBConfig but we filter the result of glXChooseFBConfig later on by passing a dwFlags to 'ConvertPixelFormatGLXtoWGL'. */
2818 for(i=0; piAttribIList[i] != 0; i+=2)
2820 switch(piAttribIList[i])
2822 case WGL_DRAW_TO_BITMAP_ARB:
2823 if(piAttribIList[i+1])
2824 dwFlags |= PFD_DRAW_TO_BITMAP;
2826 case WGL_ACCELERATION_ARB:
2827 switch(piAttribIList[i+1])
2829 case WGL_NO_ACCELERATION_ARB:
2830 dwFlags |= PFD_GENERIC_FORMAT;
2832 case WGL_GENERIC_ACCELERATION_ARB:
2833 dwFlags |= PFD_GENERIC_ACCELERATED;
2835 case WGL_FULL_ACCELERATION_ARB:
2840 case WGL_SUPPORT_GDI_ARB:
2841 if(piAttribIList[i+1])
2842 dwFlags |= PFD_SUPPORT_GDI;
2847 /* Search for FB configurations matching the requirements in attribs */
2849 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2851 wine_tsx11_unlock();
2852 WARN("Compatible Pixel Format not found\n");
2856 /* Loop through all matching formats and check if they are suitable.
2857 * Note that this function should at max return nMaxFormats different formats */
2858 for(run=0; run < 2; run++)
2860 for (it = 0; it < nCfgs; ++it) {
2861 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2863 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2867 /* Search for the format in our list of compatible formats */
2868 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id, dwFlags);
2872 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2873 if( ((run == 0) && fmt->offscreenOnly) || ((run == 1) && !fmt->offscreenOnly) )
2876 if(pfmt_it < nMaxFormats) {
2877 piFormats[pfmt_it] = fmt->iPixelFormat;
2878 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2884 *nNumFormats = pfmt_it;
2887 wine_tsx11_unlock();
2892 * X11DRV_wglGetPixelFormatAttribivARB
2894 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2896 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2899 WineGLPixelFormat *fmt = NULL;
2903 int nWGLFormats = 0;
2905 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2907 if (0 < iLayerPlane) {
2908 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2912 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2913 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2914 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2915 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nWGLFormats);
2917 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2921 for (i = 0; i < nAttributes; ++i) {
2922 const int curWGLAttr = piAttributes[i];
2923 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2925 switch (curWGLAttr) {
2926 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2927 piValues[i] = nWGLFormats;
2930 case WGL_SUPPORT_OPENGL_ARB:
2931 piValues[i] = GL_TRUE;
2934 case WGL_ACCELERATION_ARB:
2935 curGLXAttr = GLX_CONFIG_CAVEAT;
2936 if (!fmt) goto pix_error;
2937 if(fmt->dwFlags & PFD_GENERIC_FORMAT)
2938 piValues[i] = WGL_NO_ACCELERATION_ARB;
2939 else if(fmt->dwFlags & PFD_GENERIC_ACCELERATED)
2940 piValues[i] = WGL_GENERIC_ACCELERATION_ARB;
2942 piValues[i] = WGL_FULL_ACCELERATION_ARB;
2945 case WGL_TRANSPARENT_ARB:
2946 curGLXAttr = GLX_TRANSPARENT_TYPE;
2947 if (!fmt) goto pix_error;
2948 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2949 if (hTest) goto get_error;
2950 piValues[i] = GL_FALSE;
2951 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2954 case WGL_PIXEL_TYPE_ARB:
2955 curGLXAttr = GLX_RENDER_TYPE;
2956 if (!fmt) goto pix_error;
2957 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2958 if (hTest) goto get_error;
2959 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2960 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2961 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2962 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2963 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2964 else if (tmp & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) { piValues[i] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT; }
2966 ERR("unexpected RenderType(%x)\n", tmp);
2967 piValues[i] = WGL_TYPE_RGBA_ARB;
2971 case WGL_COLOR_BITS_ARB:
2972 curGLXAttr = GLX_BUFFER_SIZE;
2975 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2976 if (use_render_texture_ati) {
2977 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
2980 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2981 if (use_render_texture_ati) {
2982 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
2985 if (!use_render_texture_emulation) {
2986 piValues[i] = GL_FALSE;
2989 curGLXAttr = GLX_RENDER_TYPE;
2990 if (!fmt) goto pix_error;
2991 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2992 if (hTest) goto get_error;
2993 if (GLX_COLOR_INDEX_BIT == tmp) {
2994 piValues[i] = GL_FALSE;
2997 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2998 if (hTest) goto get_error;
2999 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
3002 case WGL_BLUE_BITS_ARB:
3003 curGLXAttr = GLX_BLUE_SIZE;
3005 case WGL_RED_BITS_ARB:
3006 curGLXAttr = GLX_RED_SIZE;
3008 case WGL_GREEN_BITS_ARB:
3009 curGLXAttr = GLX_GREEN_SIZE;
3011 case WGL_ALPHA_BITS_ARB:
3012 curGLXAttr = GLX_ALPHA_SIZE;
3014 case WGL_DEPTH_BITS_ARB:
3015 curGLXAttr = GLX_DEPTH_SIZE;
3017 case WGL_STENCIL_BITS_ARB:
3018 curGLXAttr = GLX_STENCIL_SIZE;
3020 case WGL_DOUBLE_BUFFER_ARB:
3021 curGLXAttr = GLX_DOUBLEBUFFER;
3023 case WGL_STEREO_ARB:
3024 curGLXAttr = GLX_STEREO;
3026 case WGL_AUX_BUFFERS_ARB:
3027 curGLXAttr = GLX_AUX_BUFFERS;
3030 case WGL_SUPPORT_GDI_ARB:
3031 if (!fmt) goto pix_error;
3032 piValues[i] = (fmt->dwFlags & PFD_SUPPORT_GDI) ? TRUE : FALSE;
3035 case WGL_DRAW_TO_BITMAP_ARB:
3036 if (!fmt) goto pix_error;
3037 piValues[i] = (fmt->dwFlags & PFD_DRAW_TO_BITMAP) ? TRUE : FALSE;
3040 case WGL_DRAW_TO_WINDOW_ARB:
3041 case WGL_DRAW_TO_PBUFFER_ARB:
3042 if (!fmt) goto pix_error;
3043 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
3044 if (hTest) goto get_error;
3045 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
3046 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
3047 piValues[i] = GL_TRUE;
3049 piValues[i] = GL_FALSE;
3052 case WGL_SWAP_METHOD_ARB:
3053 /* For now return SWAP_EXCHANGE_ARB which is the best type of buffer switch available.
3054 * Later on we can also use GLX_OML_swap_method on drivers which support this. At this
3055 * point only ATI offers this.
3057 piValues[i] = WGL_SWAP_EXCHANGE_ARB;
3060 case WGL_PBUFFER_LARGEST_ARB:
3061 curGLXAttr = GLX_LARGEST_PBUFFER;
3064 case WGL_SAMPLE_BUFFERS_ARB:
3065 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
3068 case WGL_SAMPLES_ARB:
3069 curGLXAttr = GLX_SAMPLES_ARB;
3072 case WGL_FLOAT_COMPONENTS_NV:
3073 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
3076 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
3077 curGLXAttr = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT;
3080 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
3081 curGLXAttr = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
3084 case WGL_ACCUM_RED_BITS_ARB:
3085 curGLXAttr = GLX_ACCUM_RED_SIZE;
3087 case WGL_ACCUM_GREEN_BITS_ARB:
3088 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
3090 case WGL_ACCUM_BLUE_BITS_ARB:
3091 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
3093 case WGL_ACCUM_ALPHA_BITS_ARB:
3094 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
3096 case WGL_ACCUM_BITS_ARB:
3097 if (!fmt) goto pix_error;
3098 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
3099 if (hTest) goto get_error;
3101 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
3102 if (hTest) goto get_error;
3104 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
3105 if (hTest) goto get_error;
3107 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
3108 if (hTest) goto get_error;
3113 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
3116 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
3117 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
3118 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
3120 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
3121 * and check which options can work using iPixelFormat=0 and which not.
3122 * A problem would be that this function is an extension. This would
3123 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
3125 if (0 != curGLXAttr && iPixelFormat != 0) {
3126 if (!fmt) goto pix_error;
3127 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
3128 if (hTest) goto get_error;
3131 piValues[i] = GL_FALSE;
3134 wine_tsx11_unlock();
3138 wine_tsx11_unlock();
3139 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
3143 wine_tsx11_unlock();
3144 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats);
3149 * X11DRV_wglGetPixelFormatAttribfvARB
3151 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
3153 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
3159 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
3161 /* Allocate a temporary array to store integer values */
3162 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
3164 ERR("couldn't allocate %d array\n", nAttributes);
3168 /* Piggy-back on wglGetPixelFormatAttribivARB */
3169 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
3171 /* Convert integer values to float. Should also check for attributes
3172 that can give decimal values here */
3173 for (i=0; i<nAttributes;i++) {
3174 pfValues[i] = attr[i];
3178 HeapFree(GetProcessHeap(), 0, attr);
3183 * X11DRV_wglBindTexImageARB
3185 * WGL_ARB_render_texture: wglBindTexImageARB
3187 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
3189 Wine_GLPBuffer* object = hPbuffer;
3190 GLboolean ret = GL_FALSE;
3192 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
3193 if (NULL == object) {
3194 SetLastError(ERROR_INVALID_HANDLE);
3197 if (!object->use_render_texture) {
3198 SetLastError(ERROR_INVALID_HANDLE);
3202 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
3203 static int init = 0;
3204 int prev_binded_texture = 0;
3205 GLXContext prev_context;
3206 Drawable prev_drawable;
3207 GLXContext tmp_context;
3210 prev_context = pglXGetCurrentContext();
3211 prev_drawable = pglXGetCurrentDrawable();
3213 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
3214 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
3215 isn't ideal performance wise but I wasn't able to get other ways working.
3218 init = 1; /* Only show the FIXME once for performance reasons */
3219 FIXME("partial stub!\n");
3222 TRACE("drawable=%p, context=%p\n", (void*)object->drawable, prev_context);
3223 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
3225 pglGetIntegerv(object->texture_bind_target, &prev_binded_texture);
3227 /* Switch to our pbuffer */
3228 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
3230 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
3231 * After that upload the pbuffer texture data. */
3232 pglBindTexture(object->texture_target, prev_binded_texture);
3233 pglCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
3235 /* Switch back to the original drawable and upload the pbuffer-texture */
3236 pglXMakeCurrent(object->display, prev_drawable, prev_context);
3237 pglXDestroyContext(gdi_display, tmp_context);
3238 wine_tsx11_unlock();
3242 if (NULL != pglXBindTexImageATI) {
3247 case WGL_FRONT_LEFT_ARB:
3248 buffer = GLX_FRONT_LEFT_ATI;
3250 case WGL_FRONT_RIGHT_ARB:
3251 buffer = GLX_FRONT_RIGHT_ATI;
3253 case WGL_BACK_LEFT_ARB:
3254 buffer = GLX_BACK_LEFT_ATI;
3256 case WGL_BACK_RIGHT_ARB:
3257 buffer = GLX_BACK_RIGHT_ATI;
3260 ERR("Unknown iBuffer=%#x\n", iBuffer);
3264 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3265 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3266 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3267 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3268 * works fine using our pbuffer emulation path.
3271 ret = pglXBindTexImageATI(object->display, object->drawable, buffer);
3272 wine_tsx11_unlock();
3278 * X11DRV_wglReleaseTexImageARB
3280 * WGL_ARB_render_texture: wglReleaseTexImageARB
3282 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
3284 Wine_GLPBuffer* object = hPbuffer;
3285 GLboolean ret = GL_FALSE;
3287 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
3288 if (NULL == object) {
3289 SetLastError(ERROR_INVALID_HANDLE);
3292 if (!object->use_render_texture) {
3293 SetLastError(ERROR_INVALID_HANDLE);
3296 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
3299 if (NULL != pglXReleaseTexImageATI) {
3304 case WGL_FRONT_LEFT_ARB:
3305 buffer = GLX_FRONT_LEFT_ATI;
3307 case WGL_FRONT_RIGHT_ARB:
3308 buffer = GLX_FRONT_RIGHT_ATI;
3310 case WGL_BACK_LEFT_ARB:
3311 buffer = GLX_BACK_LEFT_ATI;
3313 case WGL_BACK_RIGHT_ARB:
3314 buffer = GLX_BACK_RIGHT_ATI;
3317 ERR("Unknown iBuffer=%#x\n", iBuffer);
3321 ret = pglXReleaseTexImageATI(object->display, object->drawable, buffer);
3322 wine_tsx11_unlock();
3328 * X11DRV_wglGetExtensionsStringEXT
3330 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3332 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
3333 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
3334 return WineGLInfo.wglExtensions;
3338 * X11DRV_wglGetSwapIntervalEXT
3340 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3342 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
3343 FIXME("(),stub!\n");
3344 return swap_interval;
3348 * X11DRV_wglSwapIntervalEXT
3350 * WGL_EXT_swap_control: wglSwapIntervalEXT
3352 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
3355 TRACE("(%d)\n", interval);
3356 swap_interval = interval;
3357 if (NULL != pglXSwapIntervalSGI) {
3359 ret = !pglXSwapIntervalSGI(interval);
3360 wine_tsx11_unlock();
3362 else WARN("(): GLX_SGI_swap_control extension seems not supported\n");
3367 * X11DRV_wglAllocateMemoryNV
3369 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3371 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
3373 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
3375 if (pglXAllocateMemoryNV)
3378 ret = pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
3379 wine_tsx11_unlock();
3385 * X11DRV_wglFreeMemoryNV
3387 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3389 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
3390 TRACE("(%p)\n", pointer);
3391 if (pglXFreeMemoryNV == NULL)
3395 pglXFreeMemoryNV(pointer);
3396 wine_tsx11_unlock();
3400 * X11DRV_wglSetPixelFormatWINE
3402 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3403 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3405 BOOL CDECL X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE *physDev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
3407 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
3409 if (!has_opengl()) return FALSE;
3411 if (physDev->current_pf == iPixelFormat) return TRUE;
3413 /* Relay to the core SetPixelFormat */
3414 TRACE("Changing iPixelFormat from %d to %d\n", physDev->current_pf, iPixelFormat);
3415 return internal_SetPixelFormat(physDev, iPixelFormat, ppfd);
3419 * glxRequireVersion (internal)
3421 * Check if the supported GLX version matches requiredVersion.
3423 static BOOL glxRequireVersion(int requiredVersion)
3425 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3426 if(requiredVersion <= WineGLInfo.glxVersion[1])
3432 static BOOL glxRequireExtension(const char *requiredExtension)
3434 if (strstr(WineGLInfo.glxExtensions, requiredExtension) == NULL) {
3441 static void register_extension_string(const char *ext)
3443 if (WineGLInfo.wglExtensions[0])
3444 strcat(WineGLInfo.wglExtensions, " ");
3445 strcat(WineGLInfo.wglExtensions, ext);
3447 TRACE("'%s'\n", ext);
3450 static BOOL register_extension(const WineGLExtension * ext)
3454 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
3455 WineGLExtensionList[WineGLExtensionListSize++] = ext;
3457 register_extension_string(ext->extName);
3459 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
3460 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
3465 static const WineGLExtension WGL_internal_functions =
3469 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
3470 { "wglFinish", X11DRV_wglFinish },
3471 { "wglFlush", X11DRV_wglFlush },
3476 static const WineGLExtension WGL_ARB_create_context =
3478 "WGL_ARB_create_context",
3480 { "wglCreateContextAttribsARB", X11DRV_wglCreateContextAttribsARB },
3484 static const WineGLExtension WGL_ARB_extensions_string =
3486 "WGL_ARB_extensions_string",
3488 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
3492 static const WineGLExtension WGL_ARB_make_current_read =
3494 "WGL_ARB_make_current_read",
3496 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
3497 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
3501 static const WineGLExtension WGL_ARB_multisample =
3503 "WGL_ARB_multisample",
3506 static const WineGLExtension WGL_ARB_pbuffer =
3510 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
3511 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
3512 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
3513 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
3514 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
3515 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
3519 static const WineGLExtension WGL_ARB_pixel_format =
3521 "WGL_ARB_pixel_format",
3523 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
3524 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
3525 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
3529 static const WineGLExtension WGL_ARB_render_texture =
3531 "WGL_ARB_render_texture",
3533 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
3534 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
3538 static const WineGLExtension WGL_EXT_extensions_string =
3540 "WGL_EXT_extensions_string",
3542 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
3546 static const WineGLExtension WGL_EXT_swap_control =
3548 "WGL_EXT_swap_control",
3550 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
3551 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
3555 static const WineGLExtension WGL_NV_vertex_array_range =
3557 "WGL_NV_vertex_array_range",
3559 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
3560 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
3564 static const WineGLExtension WGL_WINE_pixel_format_passthrough =
3566 "WGL_WINE_pixel_format_passthrough",
3568 { "wglSetPixelFormatWINE", X11DRV_wglSetPixelFormatWINE },
3573 * X11DRV_WineGL_LoadExtensions
3575 static void X11DRV_WineGL_LoadExtensions(void)
3577 WineGLInfo.wglExtensions[0] = 0;
3579 /* Load Wine internal functions */
3580 register_extension(&WGL_internal_functions);
3582 /* ARB Extensions */
3584 if(glxRequireExtension("GLX_ARB_create_context"))
3586 register_extension(&WGL_ARB_create_context);
3588 if(glxRequireExtension("GLX_ARB_create_context_profile"))
3589 register_extension_string("WGL_ARB_create_context_profile");
3592 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3594 register_extension_string("WGL_ARB_pixel_format_float");
3595 register_extension_string("WGL_ATI_pixel_format_float");
3598 register_extension(&WGL_ARB_extensions_string);
3600 if (glxRequireVersion(3))
3601 register_extension(&WGL_ARB_make_current_read);
3603 if (glxRequireExtension("GLX_ARB_multisample"))
3604 register_extension(&WGL_ARB_multisample);
3606 /* In general pbuffer functionality requires support in the X-server. The functionality is
3607 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3608 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3609 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3611 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3612 * without support in the X-server (which other Mesa based drivers require).
3614 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3615 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3616 * is available pbuffers must be available too. */
3617 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3618 register_extension(&WGL_ARB_pbuffer);
3620 register_extension(&WGL_ARB_pixel_format);
3622 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3623 if (glxRequireExtension("GLX_ATI_render_texture") ||
3624 glxRequireExtension("GLX_ARB_render_texture") ||
3625 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation))
3627 register_extension(&WGL_ARB_render_texture);
3629 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3630 if(glxRequireExtension("GLX_NV_float_buffer"))
3631 register_extension_string("WGL_NV_float_buffer");
3633 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3634 if(strstr(WineGLInfo.glExtensions, "GL_NV_texture_rectangle") != NULL)
3635 register_extension_string("WGL_NV_texture_rectangle");
3638 /* EXT Extensions */
3640 register_extension(&WGL_EXT_extensions_string);
3642 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3643 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3644 register_extension(&WGL_EXT_swap_control);
3646 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3647 register_extension_string("WGL_EXT_framebuffer_sRGB");
3649 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3650 register_extension_string("WGL_EXT_pixel_format_packed_float");
3652 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3653 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
3654 register_extension(&WGL_NV_vertex_array_range);
3656 /* WINE-specific WGL Extensions */
3658 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3659 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3661 register_extension(&WGL_WINE_pixel_format_passthrough);
3665 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3671 if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
3672 ret = physDev->drawable; /* PBuffer */
3674 ret = physDev->bitmap->glxpixmap;
3676 else if(physDev->gl_drawable)
3677 ret = physDev->gl_drawable;
3679 ret = physDev->drawable;
3683 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3686 pglXDestroyGLXPixmap(display, glxpixmap);
3687 wine_tsx11_unlock();
3692 * X11DRV_SwapBuffers
3694 * Swap the buffers of this DC
3696 BOOL CDECL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev)
3698 GLXDrawable drawable;
3699 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
3701 if (!has_opengl()) return FALSE;
3703 TRACE("(%p)\n", physDev);
3705 drawable = get_glxdrawable(physDev);
3709 if(physDev->pixmap) {
3710 if(pglXCopySubBufferMESA) {
3711 int w = physDev->dc_rect.right - physDev->dc_rect.left;
3712 int h = physDev->dc_rect.bottom - physDev->dc_rect.top;
3714 /* (glX)SwapBuffers has an implicit glFlush effect, however
3715 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3719 pglXCopySubBufferMESA(gdi_display, drawable, 0, 0, w, h);
3722 pglXSwapBuffers(gdi_display, drawable);
3725 pglXSwapBuffers(gdi_display, drawable);
3727 flush_gl_drawable(physDev);
3728 wine_tsx11_unlock();
3733 static long prev_time, start_time;
3734 static unsigned long frames, frames_total;
3736 DWORD time = GetTickCount();
3739 /* every 1.5 seconds */
3740 if (time - prev_time > 1500) {
3741 TRACE_(fps)("@ approx %.2ffps, total %.2ffps\n",
3742 1000.0*frames/(time - prev_time), 1000.0*frames_total/(time - start_time));
3745 if(start_time == 0) start_time = time;
3752 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3754 WineGLPixelFormat *fmt;
3757 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id, 0 /* no flags */);
3762 ret = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
3763 wine_tsx11_unlock();
3767 #else /* no OpenGL includes */
3769 void X11DRV_OpenGL_Cleanup(void)
3773 static inline void opengl_error(void)
3776 if (!warned++) ERR("No OpenGL support compiled in.\n");
3779 int pixelformat_from_fbconfig_id(XID fbconfig_id)
3784 void mark_drawable_dirty(Drawable old, Drawable new)
3788 void flush_gl_drawable(X11DRV_PDEVICE *physDev)
3792 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
3797 /***********************************************************************
3798 * ChoosePixelFormat (X11DRV.@)
3800 int CDECL X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
3801 const PIXELFORMATDESCRIPTOR *ppfd) {
3806 /***********************************************************************
3807 * DescribePixelFormat (X11DRV.@)
3809 int CDECL X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
3812 PIXELFORMATDESCRIPTOR *ppfd) {
3817 /***********************************************************************
3818 * GetPixelFormat (X11DRV.@)
3820 int CDECL X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
3825 /***********************************************************************
3826 * SetPixelFormat (X11DRV.@)
3828 BOOL CDECL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
3830 const PIXELFORMATDESCRIPTOR *ppfd) {
3835 /***********************************************************************
3836 * SwapBuffers (X11DRV.@)
3838 BOOL CDECL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
3844 * X11DRV_wglCopyContext
3846 * For OpenGL32 wglCopyContext.
3848 BOOL CDECL X11DRV_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask) {
3854 * X11DRV_wglCreateContext
3856 * For OpenGL32 wglCreateContext.
3858 HGLRC CDECL X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) {
3864 * X11DRV_wglCreateContextAttribsARB
3866 * WGL_ARB_create_context: wglCreateContextAttribsARB
3868 HGLRC CDECL X11DRV_wglCreateContextAttribsARB(X11DRV_PDEVICE *physDev, HGLRC hShareContext, const int* attribList)
3875 * X11DRV_wglDeleteContext
3877 * For OpenGL32 wglDeleteContext.
3879 BOOL CDECL X11DRV_wglDeleteContext(HGLRC hglrc) {
3885 * X11DRV_wglGetProcAddress
3887 * For OpenGL32 wglGetProcAddress.
3889 PROC CDECL X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
3894 HDC CDECL X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *hDevice, void *hPbuffer)
3900 BOOL CDECL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) {
3906 * X11DRV_wglMakeCurrent
3908 * For OpenGL32 wglMakeCurrent.
3910 BOOL CDECL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
3916 * X11DRV_wglShareLists
3918 * For OpenGL32 wglShareLists.
3920 BOOL CDECL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
3926 * X11DRV_wglUseFontBitmapsA
3928 * For OpenGL32 wglUseFontBitmapsA.
3930 BOOL CDECL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3937 * X11DRV_wglUseFontBitmapsW
3939 * For OpenGL32 wglUseFontBitmapsW.
3941 BOOL CDECL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3948 * X11DRV_wglSetPixelFormatWINE
3950 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3951 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3953 BOOL CDECL X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE *physDev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
3959 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3964 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3969 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3974 #endif /* defined(HAVE_OPENGL) */