2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006 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"
34 #include "wine/library.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
38 WINE_DECLARE_DEBUG_CHANNEL(opengl);
40 #if defined(HAVE_GL_GL_H) && defined(HAVE_GL_GLX_H)
52 #ifdef HAVE_GL_GLEXT_H
53 # include <GL/glext.h>
62 /* Redefines the constants */
63 #define CALLBACK __stdcall
64 #define WINAPI __stdcall
65 #define APIENTRY WINAPI
68 WINE_DECLARE_DEBUG_CHANNEL(fps);
70 typedef struct wine_glcontext {
77 struct wine_glcontext *next;
78 struct wine_glcontext *prev;
81 typedef struct wine_glpbuffer {
90 int use_render_texture;
91 GLuint texture_target;
92 GLuint texture_bind_target;
101 typedef struct wine_glextension {
104 const char *funcName;
110 const char *glVersion;
111 const char *glExtensions;
115 const char *glxServerVersion;
116 const char *glxServerExtensions;
118 const char *glxClientVersion;
119 const char *glxClientExtensions;
121 const char *glxExtensions;
124 char wglExtensions[4096];
127 static Wine_GLContext *context_list;
128 static struct WineGLInfo WineGLInfo = { 0 };
129 static int use_render_texture_emulation = 0;
130 static int use_render_texture_ati = 0;
131 static int swap_interval = 1;
133 #define MAX_EXTENSIONS 16
134 static const WineGLExtension *WineGLExtensionList[MAX_EXTENSIONS];
135 static int WineGLExtensionListSize;
137 static void X11DRV_WineGL_LoadExtensions(void);
139 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
140 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
141 TRACE(" - dwFlags : ");
142 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
143 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
144 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
145 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
146 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
147 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
148 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
149 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
150 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
151 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
152 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
153 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
154 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
155 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
156 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
157 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
158 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
162 TRACE(" - iPixelType : ");
163 switch (ppfd->iPixelType) {
164 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
165 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
169 TRACE(" - Color : %d\n", ppfd->cColorBits);
170 TRACE(" - Red : %d\n", ppfd->cRedBits);
171 TRACE(" - Green : %d\n", ppfd->cGreenBits);
172 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
173 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
174 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
175 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
176 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
177 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
179 TRACE(" - iLayerType : ");
180 switch (ppfd->iLayerType) {
181 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
182 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
183 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
188 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient and
189 include all dependencies
192 #define SONAME_LIBGL "libGL.so"
195 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
196 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
198 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
200 MAKE_FUNCPTR(glXChooseVisual)
201 MAKE_FUNCPTR(glXCreateContext)
202 MAKE_FUNCPTR(glXCreateGLXPixmap)
203 MAKE_FUNCPTR(glXGetCurrentContext)
204 MAKE_FUNCPTR(glXDestroyContext)
205 MAKE_FUNCPTR(glXDestroyGLXPixmap)
206 MAKE_FUNCPTR(glXGetConfig)
207 MAKE_FUNCPTR(glXIsDirect)
208 MAKE_FUNCPTR(glXMakeCurrent)
209 MAKE_FUNCPTR(glXSwapBuffers)
210 MAKE_FUNCPTR(glXQueryExtension)
211 MAKE_FUNCPTR(glXQueryVersion)
214 MAKE_FUNCPTR(glXGetClientString)
215 MAKE_FUNCPTR(glXQueryExtensionsString)
216 MAKE_FUNCPTR(glXQueryServerString)
219 MAKE_FUNCPTR(glXGetFBConfigs)
220 MAKE_FUNCPTR(glXChooseFBConfig)
221 MAKE_FUNCPTR(glXCreatePbuffer)
222 MAKE_FUNCPTR(glXDestroyPbuffer)
223 MAKE_FUNCPTR(glXGetFBConfigAttrib)
224 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
225 MAKE_FUNCPTR(glXMakeContextCurrent)
226 MAKE_FUNCPTR(glXQueryDrawable)
227 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
230 static void* (*pglXGetProcAddressARB)(const GLubyte *);
231 static BOOL (*pglXBindTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
232 static BOOL (*pglXReleaseTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
233 static BOOL (*pglXDrawableAttribARB)(Display *dpy, GLXDrawable draw, const int *attribList);
234 static int (*pglXSwapIntervalSGI)(int);
236 /* Standard OpenGL */
237 MAKE_FUNCPTR(glBindTexture)
238 MAKE_FUNCPTR(glCopyTexSubImage1D)
239 MAKE_FUNCPTR(glCopyTexSubImage2D)
240 MAKE_FUNCPTR(glDrawBuffer)
241 MAKE_FUNCPTR(glGetError)
242 MAKE_FUNCPTR(glGetIntegerv)
243 MAKE_FUNCPTR(glGetString)
246 BOOL X11DRV_WineGL_InitOpenglInfo()
248 static BOOL infoInitialized = FALSE;
250 int screen = DefaultScreen(gdi_display);
251 Window win = RootWindow(gdi_display, screen);
253 XVisualInfo template;
256 GLXContext ctx = NULL;
260 infoInitialized = TRUE;
264 visual = DefaultVisual(gdi_display, screen);
265 template.visualid = XVisualIDFromVisual(visual);
266 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
268 /* Create a GLX Context. Without one we can't query GL information */
269 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
273 pglXMakeCurrent(gdi_display, win, ctx);
275 ERR(" couldn't initialize OpenGL, expect problems\n");
279 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
280 WineGLInfo.glExtensions = (const char *) pglGetString(GL_EXTENSIONS);
282 /* Get the common GLX version supported by GLX client and server ( major/minor) */
283 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
285 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
286 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
288 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
289 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
291 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
292 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
294 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
295 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
296 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
297 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
298 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
303 pglXMakeCurrent(gdi_display, None, NULL);
304 pglXDestroyContext(gdi_display, ctx);
309 static BOOL has_opengl(void)
311 static int init_done;
312 static void *opengl_handle;
313 const char *glx_extensions;
315 int error_base, event_base;
317 if (init_done) return (opengl_handle != NULL);
320 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, NULL, 0);
321 if (opengl_handle == NULL) return FALSE;
323 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
324 if (pglXGetProcAddressARB == NULL) {
325 ERR("could not find glXGetProcAddressARB in libGL.\n");
329 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((unsigned char*)#f)) == NULL) goto sym_not_found;
331 LOAD_FUNCPTR(glXChooseVisual)
332 LOAD_FUNCPTR(glXCreateContext)
333 LOAD_FUNCPTR(glXCreateGLXPixmap)
334 LOAD_FUNCPTR(glXGetCurrentContext)
335 LOAD_FUNCPTR(glXDestroyContext)
336 LOAD_FUNCPTR(glXDestroyGLXPixmap)
337 LOAD_FUNCPTR(glXGetConfig)
338 LOAD_FUNCPTR(glXIsDirect)
339 LOAD_FUNCPTR(glXMakeCurrent)
340 LOAD_FUNCPTR(glXSwapBuffers)
341 LOAD_FUNCPTR(glXQueryExtension)
342 LOAD_FUNCPTR(glXQueryVersion)
345 LOAD_FUNCPTR(glXGetClientString)
346 LOAD_FUNCPTR(glXQueryExtensionsString)
347 LOAD_FUNCPTR(glXQueryServerString)
350 LOAD_FUNCPTR(glXCreatePbuffer)
351 LOAD_FUNCPTR(glXDestroyPbuffer)
352 LOAD_FUNCPTR(glXMakeContextCurrent)
353 LOAD_FUNCPTR(glXGetCurrentReadDrawable)
354 LOAD_FUNCPTR(glXGetFBConfigs)
356 /* Standard OpenGL calls */
357 LOAD_FUNCPTR(glBindTexture)
358 LOAD_FUNCPTR(glCopyTexSubImage1D)
359 LOAD_FUNCPTR(glCopyTexSubImage2D)
360 LOAD_FUNCPTR(glDrawBuffer)
361 LOAD_FUNCPTR(glGetError)
362 LOAD_FUNCPTR(glGetIntegerv)
363 LOAD_FUNCPTR(glGetString)
366 if(!X11DRV_WineGL_InitOpenglInfo()) {
367 ERR("Intialization of OpenGL info failed, disabling OpenGL!\n");
368 wine_dlclose(opengl_handle, NULL, 0);
369 opengl_handle = NULL;
374 if (pglXQueryExtension(gdi_display, &error_base, &event_base) == True) {
375 TRACE("GLX is up and running error_base = %d\n", error_base);
377 wine_dlclose(opengl_handle, NULL, 0);
378 opengl_handle = NULL;
381 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
382 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
385 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
386 * depends on the reported GLX client / server version and on the client / server extension list.
387 * Those don't have to be the same.
389 * In general the server GLX information should be used in case of indirect rendering. When direct
390 * rendering is used, the OpenGL client library is responsible for which GLX calls are available.
391 * Nvidia's OpenGL drivers are the best in terms of GLX features. At the moment of writing their
392 * 8762 drivers support 1.3 for the server and 1.4 for the client and they support lots of extensions.
393 * Unfortunately it is much more complicated for Mesa/DRI-based drivers and ATI's drivers.
394 * Both sets of drivers report a server version of 1.2 and the client version can be 1.3 or 1.4.
395 * Further in case of atleast ATI's drivers one crucial extension needed for our pixel format code
396 * is only available in the list of server extensions and not in the client list.
398 * The versioning checks below try to take into account the comments from above.
401 /* Depending on the use of direct or indirect rendering we need either the list of extensions
402 * exported by the client or by the server.
404 if(WineGLInfo.glxDirect)
405 glx_extensions = WineGLInfo.glxClientExtensions;
407 glx_extensions = WineGLInfo.glxServerExtensions;
409 /* Based on the default opengl context we decide whether direct or indirect rendering is used.
410 * In case of indirect rendering we check if the GLX version of the server is 1.2 and else
411 * the client version is checked.
413 if ((!WineGLInfo.glxDirect && !strcmp("1.2", WineGLInfo.glxServerVersion)) ||
414 (WineGLInfo.glxDirect && !strcmp("1.2", WineGLInfo.glxClientVersion)))
416 if (NULL != strstr(glx_extensions, "GLX_SGIX_fbconfig")) {
417 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
418 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
419 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
421 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxClientVersion);
424 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
425 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
426 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
429 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
430 * enable this function when the Xserver understand GLX 1.3 or newer
432 if (!strcmp("1.2", WineGLInfo.glxServerVersion))
433 pglXQueryDrawable = NULL;
435 pglXQueryDrawable = wine_dlsym(RTLD_DEFAULT, "glXQueryDrawable", NULL, 0);
437 if (NULL != strstr(glx_extensions, "GLX_ATI_render_texture")) {
438 pglXBindTexImageARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageARB");
439 pglXReleaseTexImageARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageARB");
440 pglXDrawableAttribARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribARB");
443 X11DRV_WineGL_LoadExtensions();
446 return (opengl_handle != NULL);
449 wine_dlclose(opengl_handle, NULL, 0);
450 opengl_handle = NULL;
454 static inline Wine_GLContext *alloc_context(void)
458 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLContext))))
460 ret->next = context_list;
461 if (context_list) context_list->prev = ret;
467 static inline void free_context(Wine_GLContext *context)
469 if (context->next != NULL) context->next->prev = context->prev;
470 if (context->prev != NULL) context->prev->next = context->next;
471 else context_list = context->next;
473 HeapFree(GetProcessHeap(), 0, context);
476 static inline Wine_GLContext *get_context_from_GLXContext(GLXContext ctx)
479 if (!ctx) return NULL;
480 for (ret = context_list; ret; ret = ret->next) if (ctx == ret->ctx) break;
484 /* retrieve the GLX drawable to use on a given DC */
485 inline static Drawable get_drawable( HDC hdc )
487 GLXDrawable drawable;
488 enum x11drv_escape_codes escape = X11DRV_GET_GLX_DRAWABLE;
490 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape,
491 sizeof(drawable), (LPSTR)&drawable )) drawable = 0;
495 inline static void set_drawable( HDC hdc, Drawable drawable )
497 struct x11drv_escape_set_drawable escape;
499 escape.code = X11DRV_SET_DRAWABLE;
500 escape.drawable = drawable;
501 escape.mode = IncludeInferiors;
502 escape.org.x = escape.org.y = 0;
503 escape.drawable_org.x = escape.drawable_org.y = 0;
505 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape, 0, NULL );
508 /** for use of wglGetCurrentReadDCARB */
509 inline static HDC get_hdc_from_Drawable(GLXDrawable d)
512 for (ret = context_list; ret; ret = ret->next) {
513 if (d == get_drawable( ret->hdc )) {
520 inline static BOOL is_valid_context( Wine_GLContext *ctx )
523 for (ptr = context_list; ptr; ptr = ptr->next) if (ptr == ctx) break;
524 return (ptr != NULL);
527 static int describeContext(Wine_GLContext* ctx) {
530 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
531 pglXGetFBConfigAttrib(ctx->display, ctx->fb_conf, GLX_FBCONFIG_ID, &tmp);
532 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
533 pglXGetFBConfigAttrib(ctx->display, ctx->fb_conf, GLX_VISUAL_ID, &tmp);
534 TRACE(" - VISUAL_ID 0x%x\n", tmp);
539 static int describeDrawable(Wine_GLContext* ctx, Drawable drawable) {
542 int attribList[3] = { GLX_FBCONFIG_ID, 0, None };
545 if (pglXQueryDrawable == NULL) {
546 /** glXQueryDrawable not available so returns not supported */
550 TRACE(" Drawable %p have :\n", (void*) drawable);
551 pglXQueryDrawable(ctx->display, drawable, GLX_WIDTH, (unsigned int*) &tmp);
552 TRACE(" - WIDTH as %d\n", tmp);
553 pglXQueryDrawable(ctx->display, drawable, GLX_HEIGHT, (unsigned int*) &tmp);
554 TRACE(" - HEIGHT as %d\n", tmp);
555 pglXQueryDrawable(ctx->display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &tmp);
556 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
559 fbCfgs = pglXChooseFBConfig(ctx->display, DefaultScreen(ctx->display), attribList, &nElements);
560 if (fbCfgs == NULL) {
564 pglXGetFBConfigAttrib(ctx->display, fbCfgs[0], GLX_VISUAL_ID, &tmp);
565 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
572 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
577 int wantColorBits = 0;
580 while (0 != iWGLAttr[cur]) {
581 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
583 switch (iWGLAttr[cur]) {
584 case WGL_COLOR_BITS_ARB:
585 pop = iWGLAttr[++cur];
586 wantColorBits = pop; /** see end */
588 case WGL_BLUE_BITS_ARB:
589 pop = iWGLAttr[++cur];
590 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
591 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
593 case WGL_RED_BITS_ARB:
594 pop = iWGLAttr[++cur];
595 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
596 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
598 case WGL_GREEN_BITS_ARB:
599 pop = iWGLAttr[++cur];
600 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
601 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
603 case WGL_ALPHA_BITS_ARB:
604 pop = iWGLAttr[++cur];
606 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
607 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
609 case WGL_DEPTH_BITS_ARB:
610 pop = iWGLAttr[++cur];
611 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
612 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
614 case WGL_STENCIL_BITS_ARB:
615 pop = iWGLAttr[++cur];
616 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
617 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
619 case WGL_DOUBLE_BUFFER_ARB:
620 pop = iWGLAttr[++cur];
621 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
622 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
625 case WGL_PIXEL_TYPE_ARB:
626 pop = iWGLAttr[++cur];
628 case WGL_TYPE_COLORINDEX_ARB: pop = GLX_COLOR_INDEX_BIT; isColor = 1; break ;
629 case WGL_TYPE_RGBA_ARB: pop = GLX_RGBA_BIT; break ;
630 case WGL_TYPE_RGBA_FLOAT_ATI: pop = GLX_RGBA_FLOAT_ATI_BIT; break ;
632 ERR("unexpected PixelType(%x)\n", pop);
635 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pop);
636 TRACE("pAttr[%d] = GLX_RENDER_TYPE: %d\n", cur, pop);
639 case WGL_SUPPORT_GDI_ARB:
640 pop = iWGLAttr[++cur];
641 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
642 TRACE("pAttr[%d] = GLX_RENDERABLE: %d\n", cur, pop);
645 case WGL_DRAW_TO_BITMAP_ARB:
646 pop = iWGLAttr[++cur];
647 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
648 TRACE("pAttr[%d] = GLX_RENDERABLE: %d\n", cur, pop);
650 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT);
651 TRACE("pAttr[%d] = GLX_DRAWABLE_TYPE: GLX_PIXMAP_BIT\n", cur);
655 case WGL_DRAW_TO_WINDOW_ARB:
656 pop = iWGLAttr[++cur];
658 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT);
659 TRACE("pAttr[%d] = GLX_DRAWABLE_TYPE: GLX_WINDOW_BIT\n", cur);
663 case WGL_DRAW_TO_PBUFFER_ARB:
664 pop = iWGLAttr[++cur];
665 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
666 TRACE("pAttr[%d] = GLX_RENDERABLE: %d\n", cur, pop);
668 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT);
669 TRACE("pAttr[%d] = GLX_DRAWABLE_TYPE: GLX_PBUFFER_BIT\n", cur);
673 case WGL_ACCELERATION_ARB:
674 case WGL_SUPPORT_OPENGL_ARB:
675 pop = iWGLAttr[++cur];
676 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
677 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
680 case WGL_PBUFFER_LARGEST_ARB:
681 pop = iWGLAttr[++cur];
682 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
683 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
686 case WGL_SAMPLE_BUFFERS_ARB:
687 pop = iWGLAttr[++cur];
688 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
689 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
692 case WGL_SAMPLES_ARB:
693 pop = iWGLAttr[++cur];
694 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
695 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
698 case WGL_TEXTURE_FORMAT_ARB:
699 case WGL_TEXTURE_TARGET_ARB:
700 case WGL_MIPMAP_TEXTURE_ARB:
701 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
702 pop = iWGLAttr[++cur];
704 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
706 if (use_render_texture_ati) {
707 /** nothing to do here */
709 else if (!use_render_texture_emulation) {
710 if (WGL_NO_TEXTURE_ARB != pop) {
711 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
712 return -1; /** error: don't support it */
714 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
715 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT);
720 case WGL_BIND_TO_TEXTURE_RGB_ARB:
721 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
722 pop = iWGLAttr[++cur];
723 /** cannot be converted, see direct handling on
724 * - wglGetPixelFormatAttribivARB
725 * TODO: wglChoosePixelFormat
730 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
737 * Trick as WGL_COLOR_BITS_ARB != GLX_BUFFER_SIZE
738 * WGL_COLOR_BITS_ARB + WGL_ALPHA_BITS_ARB == GLX_BUFFER_SIZE
741 * The number of color bitplanes in each color buffer. For RGBA
742 * pixel types, it is the size of the color buffer, excluding the
743 * alpha bitplanes. For color-index pixels, it is the size of the
744 * color index buffer.
747 * This attribute defines the number of bits per color buffer.
748 * For GLX FBConfigs that correspond to a PseudoColor or StaticColor visual,
749 * this is equal to the depth value reported in the X11 visual.
750 * For GLX FBConfigs that correspond to TrueColor or DirectColor visual,
751 * this is the sum of GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_BLUE_SIZE, and GLX_ALPHA_SIZE.
754 if (0 < wantColorBits) {
756 wantColorBits += sz_alpha;
758 if (32 < wantColorBits) {
759 ERR("buggy %d GLX_BUFFER_SIZE default to 32\n", wantColorBits);
762 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, wantColorBits);
763 TRACE("pAttr[%d] = WGL_COLOR_BITS_ARB: %d\n", cur, wantColorBits);
769 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
770 * In our WGL implementation we only support a subset of these formats namely the format of
771 * Wine's main visual and offscreen formats (if they are available).
772 * This function converts a WGL format to its corresponding GLX one. It returns the index (zero-based)
773 * into the GLX FB config table and it returns the number of supported WGL formats in fmt_count.
775 static BOOL ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, int *fmt_index, int *fmt_count)
779 GLXFBConfig* cfgs = NULL;
783 int nFormats = 1; /* Start at 1 as we always have a main visual */
784 VisualID visualid = 0;
786 /* Request to look up the format of the main visual when iPixelFormat = 1 */
787 if(iPixelFormat == 1) visualid = XVisualIDFromVisual(visual);
789 /* As mentioned in various parts of the code only the format of the main visual can be used for onscreen rendering.
790 * Next to this format there are also so called offscreen rendering formats (used for pbuffers) which can be supported
791 * because they don't need a visual. Below we use glXGetFBConfigs instead of glXChooseFBConfig to enumerate the fb configurations
792 * bas this call lists both types of formats instead of only onscreen ones. */
793 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
794 if (NULL == cfgs || 0 == nCfgs) {
795 ERR("glXChooseFBConfig returns NULL\n");
796 if(cfgs != NULL) XFree(cfgs);
800 /* Find the requested offscreen format and count the number of offscreen formats */
801 for(i=0; i<nCfgs; i++) {
802 pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id);
803 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id);
805 /* We are looking up the GLX index of our main visual and have found it :) */
806 if(iPixelFormat == 1 && visualid == tmp_vis_id) {
808 TRACE("Found FBCONFIG_ID 0x%x at index %d for VISUAL_ID 0x%x\n", tmp_fmt_id, *fmt_index, tmp_vis_id);
811 /* We found an offscreen rendering format :) */
812 else if(tmp_vis_id == 0) {
814 TRACE("Checking offscreen format FBCONFIG_ID 0x%x at index %d\n", tmp_fmt_id, i);
816 if(iPixelFormat == nFormats) {
818 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", tmp_fmt_id, iPixelFormat, i);
823 *fmt_count = nFormats;
824 TRACE("Number of offscreen formats: %d; returning index: %d\n", *fmt_count, *fmt_index);
826 if(cfgs != NULL) XFree(cfgs);
828 if(res == FALSE && iPixelFormat == 1)
829 ERR("Can't find a matching FBCONFIG_ID for VISUAL_ID 0x%lx!\n", visualid);
835 * X11DRV_ChoosePixelFormat
837 * Equivalent of glXChooseVisual
839 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
840 const PIXELFORMATDESCRIPTOR *ppfd) {
841 GLXFBConfig* cfgs = NULL;
848 ERR("No libGL on this box - disabling OpenGL support !\n");
852 if (TRACE_ON(opengl)) {
853 TRACE("(%p,%p)\n", physDev, ppfd);
855 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR *) ppfd);
860 ERR("Can't get an opengl visual!\n");
864 /* Get a list containing all supported FB configurations */
865 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), NULL, &nCfgs);
866 if (NULL == cfgs || 0 == nCfgs) {
867 ERR("glXChooseFBConfig returns NULL (glError: %d)\n", pglGetError());
871 /* In case an fbconfig was found, check if it matches to the requirements of the ppfd */
872 if(!ConvertPixelFormatWGLtoGLX(gdi_display, 1 /* main visual */, &fmt_index, &value)) {
873 ERR("Can't find a matching FBCONFIG_ID for VISUAL_ID 0x%lx!\n", visual->visualid);
880 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_RENDER_TYPE, &value);
881 if (value & GLX_RGBA_BIT)
882 iPixelType = PFD_TYPE_RGBA;
884 iPixelType = PFD_TYPE_COLORINDEX;
886 if (ppfd->iPixelType != iPixelType) {
891 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_DOUBLEBUFFER, &value); if (value) dwFlags |= PFD_DOUBLEBUFFER;
892 if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE)) {
893 if ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != (dwFlags & PFD_DOUBLEBUFFER)) {
899 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_STEREO, &value); if (value) dwFlags |= PFD_STEREO;
900 if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE)) {
901 if ((ppfd->dwFlags & PFD_STEREO) != (dwFlags & PFD_STEREO)) {
907 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_ALPHA_SIZE, &value);
908 if (ppfd->iPixelType==PFD_TYPE_RGBA && ppfd->cAlphaBits && !value) {
913 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_DEPTH_SIZE, &value);
914 if (ppfd->cDepthBits && !value) {
919 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_STENCIL_SIZE, &value);
920 if (ppfd->cStencilBits && !value) {
925 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_AUX_BUFFERS, &value);
926 if (ppfd->cAuxBuffers && !value) {
930 /* When we pass all the checks we have found a matching format :) */
932 TRACE("Successfully found a matching mode, returning index: %d\n", ret);
937 TRACE("No matching mode was found returning 0\n");
939 if (NULL != cfgs) XFree(cfgs);
945 * X11DRV_DescribePixelFormat
947 * Get the pixel-format descriptor associated to the given id
949 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
952 PIXELFORMATDESCRIPTOR *ppfd) {
953 /*XVisualInfo *vis;*/
957 GLXFBConfig* cfgs = NULL;
964 ERR("No libGL on this box - disabling OpenGL support !\n");
968 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
971 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
974 if (NULL == cfgs || 0 == nCfgs) {
975 ERR("unexpected iPixelFormat(%d), returns NULL\n", iPixelFormat);
976 return 0; /* unespected error */
979 /* This function always reports the total number of supported pixel formats.
980 * At the moment we only support the pixel format corresponding to the main
981 * visual which got created at x11drv initialization. More formats could be
982 * supported if there was a way to recreate x11 windows in x11drv.
983 * Because we only support one format nCfgs needs to be set to 1.
988 /* The application is only querying the number of visuals */
990 if (NULL != cfgs) XFree(cfgs);
995 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
996 ERR("Wrong structure size !\n");
997 /* Should set error */
1001 if (nCfgs < iPixelFormat || 1 > iPixelFormat) {
1002 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL\n", iPixelFormat, nCfgs);
1006 /* Retrieve the index in the FBConfig table corresponding to the visual ID from the main visual */
1007 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &value)) {
1008 ERR("Can't find a valid pixel format index from the main visual, expect problems!\n");
1013 cur = cfgs[fmt_index];
1015 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1016 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1019 /* These flags are always the same... */
1020 ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
1021 /* Now the flags extracted from the Visual */
1025 pglXGetFBConfigAttrib(gdi_display, cur, GLX_CONFIG_CAVEAT, &value);
1026 if(value == GLX_SLOW_CONFIG)
1027 ppfd->dwFlags |= PFD_GENERIC_ACCELERATED;
1029 pglXGetFBConfigAttrib(gdi_display, cur, GLX_DOUBLEBUFFER, &value); if (value) ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1030 pglXGetFBConfigAttrib(gdi_display, cur, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1033 pglXGetFBConfigAttrib(gdi_display, cur, GLX_RENDER_TYPE, &value);
1034 if (value & GLX_RGBA_BIT)
1035 ppfd->iPixelType = PFD_TYPE_RGBA;
1037 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1040 pglXGetFBConfigAttrib(gdi_display, cur, GLX_BUFFER_SIZE, &value);
1041 ppfd->cColorBits = value;
1043 /* Red, green, blue and alpha bits / shifts */
1044 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1045 pglXGetFBConfigAttrib(gdi_display, cur, GLX_RED_SIZE, &rb);
1046 pglXGetFBConfigAttrib(gdi_display, cur, GLX_GREEN_SIZE, &gb);
1047 pglXGetFBConfigAttrib(gdi_display, cur, GLX_BLUE_SIZE, &bb);
1048 pglXGetFBConfigAttrib(gdi_display, cur, GLX_ALPHA_SIZE, &ab);
1050 ppfd->cRedBits = rb;
1051 ppfd->cRedShift = gb + bb + ab;
1052 ppfd->cBlueBits = bb;
1053 ppfd->cBlueShift = ab;
1054 ppfd->cGreenBits = gb;
1055 ppfd->cGreenShift = bb + ab;
1056 ppfd->cAlphaBits = ab;
1057 ppfd->cAlphaShift = 0;
1060 ppfd->cRedShift = 0;
1061 ppfd->cBlueBits = 0;
1062 ppfd->cBlueShift = 0;
1063 ppfd->cGreenBits = 0;
1064 ppfd->cGreenShift = 0;
1065 ppfd->cAlphaBits = 0;
1066 ppfd->cAlphaShift = 0;
1068 /* Accums : to do ... */
1071 pglXGetFBConfigAttrib(gdi_display, cur, GLX_DEPTH_SIZE, &value);
1072 ppfd->cDepthBits = value;
1075 pglXGetFBConfigAttrib(gdi_display, cur, GLX_STENCIL_SIZE, &value);
1076 ppfd->cStencilBits = value;
1078 wine_tsx11_unlock();
1080 /* Aux : to do ... */
1082 ppfd->iLayerType = PFD_MAIN_PLANE;
1084 if (TRACE_ON(opengl)) {
1085 dump_PIXELFORMATDESCRIPTOR(ppfd);
1089 if (NULL != cfgs) XFree(cfgs);
1090 wine_tsx11_unlock();
1096 * X11DRV_GetPixelFormat
1098 * Get the pixel-format id used by this DC
1100 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
1101 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1103 return physDev->current_pf;
1107 * X11DRV_SetPixelFormat
1109 * Set the pixel-format id used by this DC
1111 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
1113 const PIXELFORMATDESCRIPTOR *ppfd) {
1114 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1116 /* At the moment we only support the pixelformat corresponding to the main
1117 * x11drv visual which got created at x11drv initialization. More formats
1118 * can be supported if there was a way to recreate x11 windows in x11drv
1120 if(iPixelFormat != 1) {
1121 TRACE("Invalid iPixelFormat: %d\n", iPixelFormat);
1125 physDev->current_pf = iPixelFormat;
1127 if (TRACE_ON(opengl)) {
1129 GLXFBConfig* cfgs_fmt = NULL;
1130 GLXFBConfig cur_cfg;
1135 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &value)) {
1136 ERR("Can't find a valid pixel format index from the main visual, expect problems!\n");
1137 return TRUE; /* Return true because the SetPixelFormat stuff itself passed */
1141 * How to test if hdc current drawable is compatible (visual/FBConfig) ?
1143 * in case of root window created HDCs we crash here :(
1145 Drawable drawable = get_drawable( physDev->hdc );
1146 TRACE(" drawable (%p,%p) have :\n", drawable, root_window);
1147 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &value);
1148 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
1149 pglXQueryDrawable(gdi_display, drawable, GLX_VISUAL_ID, (unsigned int*) &value);
1150 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
1151 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &value);
1152 TRACE(" - WIDTH as %d\n", tmp);
1153 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &value);
1154 TRACE(" - HEIGHT as %d\n", tmp);
1156 cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
1157 cur_cfg = cfgs_fmt[fmt_index];
1158 gl_test = pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_FBCONFIG_ID, &value);
1160 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1162 TRACE(" FBConfig have :\n");
1163 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1164 pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_VISUAL_ID, &value);
1165 TRACE(" - VISUAL_ID 0x%x\n", value);
1166 pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_DRAWABLE_TYPE, &value);
1167 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1174 /* OpenGL32 wglCreateContext */
1175 HGLRC WINAPI X11DRV_wglCreateContext(HDC hdc)
1177 Wine_GLContext *ret;
1178 GLXFBConfig* cfgs_fmt = NULL;
1179 GLXFBConfig cur_cfg;
1180 int hdcPF = 1; /* We can only use the Wine's main visual which has an index of 1 */
1187 TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1189 /* First, get the visual in use by the X11DRV */
1190 if (!gdi_display) return 0;
1192 /* We can only render using the iPixelFormat (1) of Wine's Main visual, we need to get the correspondig GLX format.
1193 * If this fails something is very wrong on the system. */
1194 if(!ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, &tmp, &fmt_index)) {
1195 ERR("Cannot get FB Config for main iPixelFormat 1, expect problems!\n");
1196 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1200 cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
1201 if (NULL == cfgs_fmt || 0 == nCfgs_fmt) {
1202 ERR("Cannot get FB Configs, expect problems.\n");
1203 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1207 if (nCfgs_fmt < fmt_index) {
1208 ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, fmt_index, nCfgs_fmt);
1209 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1213 cur_cfg = cfgs_fmt[fmt_index];
1214 gl_test = pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_FBCONFIG_ID, &value);
1216 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1217 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1222 /* The context will be allocated in the wglMakeCurrent call */
1224 ret = alloc_context();
1225 wine_tsx11_unlock();
1227 ret->display = gdi_display;
1228 ret->fb_conf = cur_cfg;
1230 ret->vis = pglXGetVisualFromFBConfig(gdi_display, cur_cfg);
1232 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1236 /* OpenGL32 wglDeleteContext */
1237 BOOL WINAPI X11DRV_wglDeleteContext(HGLRC hglrc)
1239 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1242 TRACE("(%p)\n", hglrc);
1245 /* A game (Half Life not to name it) deletes twice the same context,
1246 * so make sure it is valid first */
1247 if (is_valid_context( ctx ))
1249 if (ctx->ctx) pglXDestroyContext(ctx->display, ctx->ctx);
1254 WARN("Error deleting context !\n");
1255 SetLastError(ERROR_INVALID_HANDLE);
1258 wine_tsx11_unlock();
1263 /* OpenGL32 wglGetCurrentContext() */
1264 HGLRC WINAPI X11DRV_wglGetCurrentContext(void) {
1266 Wine_GLContext *ret;
1271 gl_ctx = pglXGetCurrentContext();
1272 ret = get_context_from_GLXContext(gl_ctx);
1273 wine_tsx11_unlock();
1275 TRACE(" returning %p (GL context %p)\n", ret, gl_ctx);
1280 /* OpenGL32 wglGetCurrentDC */
1281 HDC WINAPI X11DRV_wglGetCurrentDC(void) {
1283 Wine_GLContext *ret;
1288 gl_ctx = pglXGetCurrentContext();
1289 ret = get_context_from_GLXContext(gl_ctx);
1290 wine_tsx11_unlock();
1293 TRACE(" returning %p (GL context %p - Wine context %p)\n", ret->hdc, gl_ctx, ret);
1296 TRACE(" no Wine context found for GLX context %p\n", gl_ctx);
1301 /* OpenGL32 wglGetCurrentReadDCARB */
1302 HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1310 gl_d = pglXGetCurrentReadDrawable();
1311 ret = get_hdc_from_Drawable(gl_d);
1312 wine_tsx11_unlock();
1314 TRACE(" returning %p (GL drawable %lu)\n", ret, gl_d);
1318 /* OpenGL32: wglGetProcAddress */
1319 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1322 const WineGLExtension *ext;
1324 int padding = 32 - strlen(lpszProc);
1328 TRACE("('%s'):%*s", lpszProc, padding, " ");
1329 for (i = 0; i < WineGLExtensionListSize; ++i) {
1330 ext = WineGLExtensionList[i];
1331 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1332 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1333 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1334 return ext->extEntryPoints[j].funcAddress;
1339 ERR("(%s) - not found\n", lpszProc);
1345 /* OpenGL32 wglMakeCurrent */
1346 BOOL WINAPI X11DRV_wglMakeCurrent(HDC hdc, HGLRC hglrc) {
1348 DWORD type = GetObjectType(hdc);
1350 TRACE("(%p,%p)\n", hdc, hglrc);
1353 if (hglrc == NULL) {
1354 ret = pglXMakeCurrent(gdi_display, None, NULL);
1355 NtCurrentTeb()->glContext = NULL;
1357 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1358 Drawable drawable = get_drawable( hdc );
1359 if (ctx->ctx == NULL) {
1360 int draw_vis_id, ctx_vis_id;
1361 VisualID visualid = (VisualID)GetPropA( GetDesktopWindow(), "__wine_x11_visual_id" );
1362 TRACE(" Wine desktop VISUAL_ID is 0x%x\n", (unsigned int) visualid);
1363 draw_vis_id = describeDrawable(ctx, drawable);
1364 ctx_vis_id = describeContext(ctx);
1366 if (-1 == draw_vis_id || (draw_vis_id == visualid && draw_vis_id != ctx_vis_id)) {
1368 * Inherits from root window so reuse desktop visual
1370 XVisualInfo template;
1373 template.visualid = visualid;
1374 vis = XGetVisualInfo(ctx->display, VisualIDMask, &template, &num);
1376 TRACE(" Creating GLX Context\n");
1377 ctx->ctx = pglXCreateContext(ctx->display, vis, NULL, type == OBJ_MEMDC ? False : True);
1379 TRACE(" Creating GLX Context\n");
1380 ctx->ctx = pglXCreateContext(ctx->display, ctx->vis, NULL, type == OBJ_MEMDC ? False : True);
1382 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1384 TRACE(" make current for dis %p, drawable %p, ctx %p\n", ctx->display, (void*) drawable, ctx->ctx);
1385 ret = pglXMakeCurrent(ctx->display, drawable, ctx->ctx);
1386 NtCurrentTeb()->glContext = ctx;
1387 if(ret && type == OBJ_MEMDC)
1389 ctx->do_escape = TRUE;
1390 pglDrawBuffer(GL_FRONT_LEFT);
1393 wine_tsx11_unlock();
1394 TRACE(" returning %s\n", (ret ? "True" : "False"));
1398 /* OpenGL32 wglMakeContextCurrentARB */
1399 BOOL WINAPI X11DRV_wglMakeContextCurrentARB(HDC hDrawDC, HDC hReadDC, HGLRC hglrc)
1402 TRACE("(%p,%p,%p)\n", hDrawDC, hReadDC, hglrc);
1405 if (hglrc == NULL) {
1406 ret = pglXMakeCurrent(gdi_display, None, NULL);
1408 if (NULL == pglXMakeContextCurrent) {
1411 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1412 Drawable d_draw = get_drawable( hDrawDC );
1413 Drawable d_read = get_drawable( hReadDC );
1415 if (ctx->ctx == NULL) {
1416 ctx->ctx = pglXCreateContext(ctx->display, ctx->vis, NULL, GetObjectType(hDrawDC) == OBJ_MEMDC ? False : True);
1417 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1419 ret = pglXMakeContextCurrent(ctx->display, d_draw, d_read, ctx->ctx);
1422 wine_tsx11_unlock();
1424 TRACE(" returning %s\n", (ret ? "True" : "False"));
1428 /* OpenGL32 wglShaderLists */
1429 BOOL WINAPI X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
1430 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1431 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1433 TRACE("(%p, %p)\n", org, dest);
1435 if (NULL != dest && dest->ctx != NULL) {
1436 ERR("Could not share display lists, context already created !\n");
1439 if (org->ctx == NULL) {
1441 describeContext(org);
1442 org->ctx = pglXCreateContext(org->display, org->vis, NULL, GetObjectType(org->hdc) == OBJ_MEMDC ? False : True);
1443 wine_tsx11_unlock();
1444 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org->ctx, org);
1448 describeContext(dest);
1449 /* Create the destination context with display lists shared */
1450 dest->ctx = pglXCreateContext(org->display, dest->vis, org->ctx, GetObjectType(org->hdc) == OBJ_MEMDC ? False : True);
1451 wine_tsx11_unlock();
1452 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1460 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1461 void X11DRV_wglGetIntegerv(GLenum pname, GLint* params) {
1462 TRACE("pname: 0x%x, params: %p\n", pname, params);
1463 if (pname == GL_DEPTH_BITS) {
1464 GLXContext gl_ctx = pglXGetCurrentContext();
1465 Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx);
1466 /*TRACE("returns Wine Ctx as %p\n", ret);*/
1468 * if we cannot find a Wine Context
1469 * we only have the default wine desktop context,
1470 * so if we have only a 24 depth say we have 32
1472 if (NULL == ret && 24 == *params) {
1475 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
1477 if (pname == GL_ALPHA_BITS) {
1479 GLXContext gl_ctx = pglXGetCurrentContext();
1480 Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx);
1481 pglXGetFBConfigAttrib(ret->display, ret->fb_conf, GLX_ALPHA_SIZE, &tmp);
1482 TRACE("returns GL_ALPHA_BITS as '%d'\n", tmp);
1487 /* WGL_ARB_extensions_string: wglGetExtensionsStringARB */
1488 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
1489 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
1490 return WineGLInfo.wglExtensions;
1493 /* WGL_ARB_pbuffer: wglCreatePbufferARB */
1494 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
1496 Wine_GLPBuffer* object = NULL;
1497 GLXFBConfig* cfgs = NULL;
1500 unsigned nAttribs = 0;
1503 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
1505 if (0 >= iPixelFormat) {
1506 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
1507 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1508 return NULL; /* unexpected error */
1511 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
1513 if (NULL == cfgs || 0 == nCfgs) {
1514 ERR("(%p): Cannot get FB Configs for iPixelFormat(%d), returns NULL\n", hdc, iPixelFormat);
1515 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1516 return NULL; /* unexpected error */
1519 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
1520 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &nCfgs)) {
1521 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
1522 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1523 goto create_failed; /* unexpected error */
1526 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
1527 if (NULL == object) {
1528 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
1529 goto create_failed; /* unexpected error */
1532 object->display = gdi_display;
1533 object->width = iWidth;
1534 object->height = iHeight;
1536 nAttribs = ConvertAttribWGLtoGLX(piAttribList, attribs, object);
1537 if (-1 == nAttribs) {
1538 WARN("Cannot convert WGL to GLX attributes\n");
1541 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
1542 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
1543 while (0 != *piAttribList) {
1545 switch (*piAttribList) {
1546 case WGL_TEXTURE_FORMAT_ARB: {
1548 attr_v = *piAttribList;
1549 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
1550 if (use_render_texture_ati) {
1553 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
1554 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
1555 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
1557 SetLastError(ERROR_INVALID_DATA);
1560 object->use_render_texture = 1;
1561 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
1563 if (WGL_NO_TEXTURE_ARB == attr_v) {
1564 object->use_render_texture = 0;
1566 if (!use_render_texture_emulation) {
1567 SetLastError(ERROR_INVALID_DATA);
1571 case WGL_TEXTURE_RGB_ARB:
1572 object->use_render_texture = GL_RGB;
1574 case WGL_TEXTURE_RGBA_ARB:
1575 object->use_render_texture = GL_RGBA;
1578 SetLastError(ERROR_INVALID_DATA);
1586 case WGL_TEXTURE_TARGET_ARB: {
1588 attr_v = *piAttribList;
1589 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
1590 if (use_render_texture_ati) {
1593 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
1594 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
1595 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
1596 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
1598 SetLastError(ERROR_INVALID_DATA);
1601 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
1603 if (WGL_NO_TEXTURE_ARB == attr_v) {
1604 object->texture_target = 0;
1606 if (!use_render_texture_emulation) {
1607 SetLastError(ERROR_INVALID_DATA);
1611 case WGL_TEXTURE_CUBE_MAP_ARB: {
1612 if (iWidth != iHeight) {
1613 SetLastError(ERROR_INVALID_DATA);
1616 object->texture_target = GL_TEXTURE_CUBE_MAP;
1617 object->texture_bind_target = GL_TEXTURE_CUBE_MAP;
1620 case WGL_TEXTURE_1D_ARB: {
1622 SetLastError(ERROR_INVALID_DATA);
1625 object->texture_target = GL_TEXTURE_1D;
1626 object->texture_bind_target = GL_TEXTURE_1D;
1629 case WGL_TEXTURE_2D_ARB: {
1630 object->texture_target = GL_TEXTURE_2D;
1631 object->texture_bind_target = GL_TEXTURE_2D;
1635 SetLastError(ERROR_INVALID_DATA);
1643 case WGL_MIPMAP_TEXTURE_ARB: {
1645 attr_v = *piAttribList;
1646 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
1647 if (use_render_texture_ati) {
1648 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
1650 if (!use_render_texture_emulation) {
1651 SetLastError(ERROR_INVALID_DATA);
1661 PUSH1(attribs, None);
1662 object->drawable = pglXCreatePbuffer(gdi_display, cfgs[fmt_index], attribs);
1663 TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
1664 if (!object->drawable) {
1665 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
1666 goto create_failed; /* unexpected error */
1668 TRACE("->(%p)\n", object);
1672 return (HPBUFFERARB) object;
1675 if (NULL != cfgs) XFree(cfgs);
1676 HeapFree(GetProcessHeap(), 0, object);
1677 TRACE("->(FAILED)\n");
1678 return (HPBUFFERARB) NULL;
1681 /* WGL_ARB_pbuffer: wglDestroyPbufferARB */
1682 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
1684 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
1685 TRACE("(%p)\n", hPbuffer);
1686 if (NULL == object) {
1687 SetLastError(ERROR_INVALID_HANDLE);
1690 pglXDestroyPbuffer(object->display, object->drawable);
1691 HeapFree(GetProcessHeap(), 0, object);
1695 /* WGL_ARB_pbuffer: wglGetPbufferDCARB */
1696 static HDC WINAPI X11DRV_wglGetPbufferDCARB(HPBUFFERARB hPbuffer)
1698 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
1700 if (NULL == object) {
1701 SetLastError(ERROR_INVALID_HANDLE);
1704 hDC = CreateCompatibleDC(object->hdc);
1706 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
1707 * We only support one onscreen rendering format (the one from the main visual), so use that. */
1708 SetPixelFormat(hDC, 1, NULL);
1709 set_drawable(hDC, object->drawable); /* works ?? */
1710 TRACE("(%p)->(%p)\n", hPbuffer, hDC);
1714 /* WGL_ARB_pbuffer: wglQueryPbufferARB */
1715 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
1717 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
1718 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
1719 if (NULL == object) {
1720 SetLastError(ERROR_INVALID_HANDLE);
1723 switch (iAttribute) {
1724 case WGL_PBUFFER_WIDTH_ARB:
1725 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
1727 case WGL_PBUFFER_HEIGHT_ARB:
1728 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
1731 case WGL_PBUFFER_LOST_ARB:
1732 FIXME("unsupported WGL_PBUFFER_LOST_ARB (need glXSelectEvent/GLX_DAMAGED work)\n");
1735 case WGL_TEXTURE_FORMAT_ARB:
1736 if (use_render_texture_ati) {
1738 int type = WGL_NO_TEXTURE_ARB;
1739 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
1741 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
1742 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
1743 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
1747 if (!object->use_render_texture) {
1748 *piValue = WGL_NO_TEXTURE_ARB;
1750 if (!use_render_texture_emulation) {
1751 SetLastError(ERROR_INVALID_HANDLE);
1754 if (GL_RGBA == object->use_render_texture) {
1755 *piValue = WGL_TEXTURE_RGBA_ARB;
1757 *piValue = WGL_TEXTURE_RGB_ARB;
1763 case WGL_TEXTURE_TARGET_ARB:
1764 if (use_render_texture_ati) {
1766 int type = WGL_NO_TEXTURE_ARB;
1767 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
1769 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
1770 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
1771 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
1772 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
1776 if (!object->texture_target) {
1777 *piValue = WGL_NO_TEXTURE_ARB;
1779 if (!use_render_texture_emulation) {
1780 SetLastError(ERROR_INVALID_DATA);
1783 switch (object->texture_target) {
1784 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
1785 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_1D_ARB; break;
1786 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_2D_ARB; break;
1792 case WGL_MIPMAP_TEXTURE_ARB:
1793 if (use_render_texture_ati) {
1794 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
1796 *piValue = GL_FALSE; /** don't support that */
1797 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
1802 FIXME("unexpected attribute %x\n", iAttribute);
1809 /* WGL_ARB_pbuffer: wglReleasePbufferDCARB */
1810 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
1812 TRACE("(%p, %p)\n", hPbuffer, hdc);
1817 /* WGL_ARB_pbuffer: wglSetPbufferAttribARB */
1818 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
1820 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
1821 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
1822 if (NULL == object) {
1823 SetLastError(ERROR_INVALID_HANDLE);
1826 if (!object->use_render_texture) {
1827 SetLastError(ERROR_INVALID_HANDLE);
1830 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
1833 if (NULL != pglXDrawableAttribARB) {
1834 if (use_render_texture_ati) {
1835 FIXME("Need conversion for GLX_ATI_render_texture\n");
1837 return pglXDrawableAttribARB(object->display, object->drawable, piAttribList);
1842 /* WGL_ARB_pixel_format: wglChoosePixelFormatARB */
1843 GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
1848 GLboolean res = FALSE;
1850 /* We need the visualid to check if the format is suitable */
1851 VisualID visualid = XVisualIDFromVisual(visual);
1853 GLXFBConfig* cfgs = NULL;
1858 GLXFBConfig* cfgs_fmt = NULL;
1865 int offscreen_index = 1; /* Start at one because we allways have a main visual at iPixelFormat=1 */
1867 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
1868 if (NULL != pfAttribFList) {
1869 FIXME("unused pfAttribFList\n");
1872 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
1873 if (-1 == nAttribs) {
1874 WARN("Cannot convert WGL to GLX attributes\n");
1877 PUSH1(attribs, None);
1879 /* Search for FB configurations matching the requirements in attribs */
1880 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
1882 WARN("Compatible Pixel Format not found\n");
1886 /* Get a list of all FB configurations */
1887 cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
1888 if (NULL == cfgs_fmt) {
1889 ERR("Failed to get All FB Configs\n");
1894 /* Loop through all matching formats and check if they are suitable.
1895 * Note that this function should at max return nMaxFormats different formats */
1896 for (it = 0; pfmt_it < nMaxFormats && it < nCfgs; ++it) {
1897 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
1899 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1903 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_VISUAL_ID, &tmp_vis_id);
1905 ERR("Failed to retrieve VISUAL_ID from GLXFBConfig, expect problems.\n");
1909 /* When the visualid of the GLXFBConfig matches the one of the main visual we have found our
1910 * only supported onscreen rendering format. This format has a WGL index of 1. */
1911 if(tmp_vis_id == visualid) {
1912 piFormats[pfmt_it] = 1;
1915 TRACE("Found compatible GLXFBConfig 0x%x with WGL index 1\n", fmt_id);
1918 /* Only continue with this loop for offscreen rendering formats (visualid = 0) */
1919 else if(tmp_vis_id != 0) {
1920 TRACE("Discarded GLXFBConfig %0x with VisualID %x because the visualid is not the same as our main visual (%lx)\n", fmt_id, tmp_vis_id, visualid);
1924 /* Find the index of the found format in the whole format table */
1925 for (it_fmt = 0; it_fmt < nCfgs_fmt; ++it_fmt) {
1926 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs_fmt[it_fmt], GLX_FBCONFIG_ID, &tmp_fmt_id);
1928 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1931 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_VISUAL_ID, &tmp_vis_id);
1933 ERR("Failed to retrieve VISUAL_ID from GLXFBConfig, expect problems.\n");
1936 /* The format of Wine's main visual is stored at index 1 of our WGL format table.
1937 * At higher indices we store offscreen rendering formats (visualid=0). Below we calculate
1938 * the index of the offscreen format. We do this by counting the number of offscreen formats
1939 * which we see upto reaching our target format. */
1943 /* We have found the format in the table (note the format is offscreen) */
1944 if (fmt_id == tmp_fmt_id) {
1947 piFormats[pfmt_it] = offscreen_index + 1; /* Add 1 to get a one-based index */
1949 pglXGetFBConfigAttrib(gdi_display, cfgs_fmt[it_fmt], GLX_ALPHA_SIZE, &tmp);
1950 TRACE("ALPHA_SIZE of FBCONFIG_ID(%d/%d) found as '%d'\n", it_fmt + 1, nCfgs_fmt, tmp);
1954 if (it_fmt == nCfgs_fmt) {
1955 ERR("Failed to get valid fmt for %d. Try next.\n", it);
1958 TRACE("at %d/%d found FBCONFIG_ID(%d/%d)\n", it + 1, nCfgs, piFormats[it], nCfgs_fmt);
1961 *nNumFormats = pfmt_it;
1968 /* WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB */
1969 GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
1971 FIXME("(%p, %d, %d, %d, %p, %p): stub\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
1975 /* WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB */
1976 GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
1979 GLXFBConfig* cfgs = NULL;
1980 GLXFBConfig curCfg = NULL;
1985 int nWGLFormats = 0;
1988 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
1990 if (0 < iLayerPlane) {
1991 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
1995 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
1997 ERR("no FB Configs found for display(%p)\n", gdi_display);
2001 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2002 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2003 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2004 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &nWGLFormats)) {
2005 ERR("Unable to convert iPixelFormat %d to a GLX one, expect problems!\n", iPixelFormat);
2008 for (i = 0; i < nAttributes; ++i) {
2009 const int curWGLAttr = piAttributes[i];
2010 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2012 switch (curWGLAttr) {
2013 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2014 piValues[i] = nWGLFormats;
2017 case WGL_SUPPORT_OPENGL_ARB:
2018 piValues[i] = GL_TRUE;
2021 case WGL_ACCELERATION_ARB:
2022 curGLXAttr = GLX_CONFIG_CAVEAT;
2024 if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
2025 curCfg = cfgs[iPixelFormat - 1];
2027 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2028 if (hTest) goto get_error;
2030 case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2031 case GLX_SLOW_CONFIG: piValues[i] = WGL_NO_ACCELERATION_ARB; break;
2032 case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2034 ERR("unexpected Config Caveat(%x)\n", tmp);
2035 piValues[i] = WGL_NO_ACCELERATION_ARB;
2039 case WGL_TRANSPARENT_ARB:
2040 curGLXAttr = GLX_TRANSPARENT_TYPE;
2041 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2042 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2043 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2044 curCfg = cfgs[fmt_index];
2045 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2046 if (hTest) goto get_error;
2047 piValues[i] = GL_FALSE;
2048 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2051 case WGL_PIXEL_TYPE_ARB:
2052 curGLXAttr = GLX_RENDER_TYPE;
2053 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2054 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2055 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2056 curCfg = cfgs[fmt_index];
2057 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2058 if (hTest) goto get_error;
2059 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2060 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2061 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2062 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2063 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2065 ERR("unexpected RenderType(%x)\n", tmp);
2066 piValues[i] = WGL_TYPE_RGBA_ARB;
2070 case WGL_COLOR_BITS_ARB:
2071 /** see ConvertAttribWGLtoGLX for explain */
2072 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2073 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2074 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2075 curCfg = cfgs[fmt_index];
2076 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_BUFFER_SIZE, piValues + i);
2077 if (hTest) goto get_error;
2078 TRACE("WGL_COLOR_BITS_ARB: GLX_BUFFER_SIZE = %d\n", piValues[i]);
2079 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_ALPHA_SIZE, &tmp);
2080 if (hTest) goto get_error;
2081 TRACE("WGL_COLOR_BITS_ARB: GLX_ALPHA_SIZE = %d\n", tmp);
2082 piValues[i] = piValues[i] - tmp;
2085 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2086 if (use_render_texture_ati) {
2087 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
2090 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2091 if (use_render_texture_ati) {
2092 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
2095 if (!use_render_texture_emulation) {
2096 piValues[i] = GL_FALSE;
2099 curGLXAttr = GLX_RENDER_TYPE;
2100 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2101 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2102 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2103 curCfg = cfgs[fmt_index];
2104 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2105 if (hTest) goto get_error;
2106 if (GLX_COLOR_INDEX_BIT == tmp) {
2107 piValues[i] = GL_FALSE;
2110 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_DRAWABLE_TYPE, &tmp);
2111 if (hTest) goto get_error;
2112 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2115 case WGL_BLUE_BITS_ARB:
2116 curGLXAttr = GLX_BLUE_SIZE;
2118 case WGL_RED_BITS_ARB:
2119 curGLXAttr = GLX_RED_SIZE;
2121 case WGL_GREEN_BITS_ARB:
2122 curGLXAttr = GLX_GREEN_SIZE;
2124 case WGL_ALPHA_BITS_ARB:
2125 curGLXAttr = GLX_ALPHA_SIZE;
2127 case WGL_DEPTH_BITS_ARB:
2128 curGLXAttr = GLX_DEPTH_SIZE;
2130 case WGL_STENCIL_BITS_ARB:
2131 curGLXAttr = GLX_STENCIL_SIZE;
2133 case WGL_DOUBLE_BUFFER_ARB:
2134 curGLXAttr = GLX_DOUBLEBUFFER;
2136 case WGL_STEREO_ARB:
2137 curGLXAttr = GLX_STEREO;
2139 case WGL_AUX_BUFFERS_ARB:
2140 curGLXAttr = GLX_AUX_BUFFERS;
2143 case WGL_SUPPORT_GDI_ARB:
2144 case WGL_DRAW_TO_WINDOW_ARB:
2145 case WGL_DRAW_TO_BITMAP_ARB:
2146 case WGL_DRAW_TO_PBUFFER_ARB:
2147 curGLXAttr = GLX_X_RENDERABLE;
2150 case WGL_PBUFFER_LARGEST_ARB:
2151 curGLXAttr = GLX_LARGEST_PBUFFER;
2154 case WGL_SAMPLE_BUFFERS_ARB:
2155 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2158 case WGL_SAMPLES_ARB:
2159 curGLXAttr = GLX_SAMPLES_ARB;
2163 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2166 if (0 != curGLXAttr) {
2167 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2168 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2169 if((iPixelFormat > 0) && ((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs))) goto pix_error;
2170 curCfg = cfgs[fmt_index];
2171 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, piValues + i);
2172 if (hTest) goto get_error;
2174 piValues[i] = GL_FALSE;
2180 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2185 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nCfgs);
2190 /* WGL_ARB_render_texture: wglBindTexImageARB */
2191 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2193 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2194 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2195 if (NULL == object) {
2196 SetLastError(ERROR_INVALID_HANDLE);
2199 if (!object->use_render_texture) {
2200 SetLastError(ERROR_INVALID_HANDLE);
2203 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2205 GLint prev_binded_tex;
2206 pglGetIntegerv(object->texture_target, &prev_binded_tex);
2207 if (NULL == object->render_ctx) {
2208 object->render_hdc = X11DRV_wglGetPbufferDCARB(hPbuffer);
2209 object->render_ctx = X11DRV_wglCreateContext(object->render_hdc);
2212 object->prev_hdc = X11DRV_wglGetCurrentDC();
2213 object->prev_ctx = X11DRV_wglGetCurrentContext();
2214 X11DRV_wglMakeCurrent(object->render_hdc, object->render_ctx);
2217 glBindTexture(object->texture_target, object->texture);
2218 if (GL_RGBA == object->use_render_texture) {
2219 glTexImage2D(object->texture_target, 0, GL_RGBA8, object->width, object->height, 0, GL_RGBA, GL_FLOAT, NULL);
2221 glTexImage2D(object->texture_target, 0, GL_RGB8, object->width, object->height, 0, GL_RGB, GL_FLOAT, NULL);
2225 object->texture = prev_binded_tex;
2228 if (NULL != pglXBindTexImageARB) {
2229 return pglXBindTexImageARB(object->display, object->drawable, iBuffer);
2234 /* WGL_ARB_render_texture: wglReleaseTexImageARB */
2235 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2237 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2238 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2239 if (NULL == object) {
2240 SetLastError(ERROR_INVALID_HANDLE);
2243 if (!object->use_render_texture) {
2244 SetLastError(ERROR_INVALID_HANDLE);
2247 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2249 GLint prev_binded_tex;
2250 glGetIntegerv(object->texture_target, &prev_binded_tex);
2251 if (GL_TEXTURE_1D == object->texture_target) {
2252 glCopyTexSubImage1D(object->texture_target, object->texture_level, 0, 0, 0, object->width);
2254 glCopyTexSubImage2D(object->texture_target, object->texture_level, 0, 0, 0, 0, object->width, object->height);
2256 glBindTexture(object->texture_target, prev_binded_tex);
2257 SwapBuffers(object->render_hdc);
2259 pglBindTexture(object->texture_target, object->texture);
2260 if (GL_TEXTURE_1D == object->texture_target) {
2261 pglCopyTexSubImage1D(object->texture_target, object->texture_level, 0, 0, 0, object->width);
2263 pglCopyTexSubImage2D(object->texture_target, object->texture_level, 0, 0, 0, 0, object->width, object->height);
2266 X11DRV_wglMakeCurrent(object->prev_hdc, object->prev_ctx);
2269 if (NULL != pglXReleaseTexImageARB) {
2270 return pglXReleaseTexImageARB(object->display, object->drawable, iBuffer);
2275 /* WGL_EXT_extensions_string: wglGetExtensionsStringEXT */
2276 const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
2277 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2278 return WineGLInfo.wglExtensions;
2281 /* WGL_EXT_swap_control: wglGetSwapIntervalEXT */
2282 int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
2283 FIXME("(),stub!\n");
2284 return swap_interval;
2287 /* WGL_EXT_swap_control: wglSwapIntervalEXT */
2288 BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
2289 TRACE("(%d)\n", interval);
2290 swap_interval = interval;
2291 if (NULL != pglXSwapIntervalSGI) {
2292 return 0 == pglXSwapIntervalSGI(interval);
2294 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
2298 /* Check if the supported GLX version matches requiredVersion */
2299 static BOOL glxRequireVersion(int requiredVersion)
2301 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2302 if(requiredVersion <= WineGLInfo.glxVersion[1])
2308 static BOOL glxRequireExtension(const char *requiredExtension)
2310 if (strstr(WineGLInfo.glxClientExtensions, requiredExtension) == NULL) {
2317 static BOOL register_extension(const WineGLExtension * ext)
2321 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
2322 WineGLExtensionList[WineGLExtensionListSize++] = ext;
2324 strcat(WineGLInfo.wglExtensions, " ");
2325 strcat(WineGLInfo.wglExtensions, ext->extName);
2327 TRACE("'%s'\n", ext->extName);
2329 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
2330 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
2335 static const WineGLExtension WGL_ARB_extensions_string =
2337 "WGL_ARB_extensions_string",
2339 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
2343 static const WineGLExtension WGL_ARB_make_current_read =
2345 "WGL_ARB_make_current_read",
2347 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
2348 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
2352 static const WineGLExtension WGL_ARB_multisample =
2354 "WGL_ARB_multisample",
2357 static const WineGLExtension WGL_ARB_pbuffer =
2361 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
2362 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
2363 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
2364 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
2365 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
2366 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
2370 static const WineGLExtension WGL_ARB_pixel_format =
2372 "WGL_ARB_pixel_format",
2374 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
2375 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
2376 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
2380 static const WineGLExtension WGL_ARB_render_texture =
2382 "WGL_ARB_render_texture",
2384 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
2385 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
2389 static const WineGLExtension WGL_EXT_extensions_string =
2391 "WGL_EXT_extensions_string",
2393 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
2397 static const WineGLExtension WGL_EXT_swap_control =
2399 "WGL_EXT_swap_control",
2401 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
2402 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
2408 * X11DRV_WineGL_LoadExtensions
2410 static void X11DRV_WineGL_LoadExtensions(void)
2412 WineGLInfo.wglExtensions[0] = 0;
2414 /* ARB Extensions */
2416 register_extension(&WGL_ARB_extensions_string);
2418 if (glxRequireVersion(3))
2419 register_extension(&WGL_ARB_make_current_read);
2421 if (glxRequireExtension("GLX_ARB_multisample"))
2422 register_extension(&WGL_ARB_multisample);
2424 if (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer"))
2425 register_extension(&WGL_ARB_pbuffer);
2427 register_extension(&WGL_ARB_pixel_format);
2429 if (glxRequireExtension("GLX_ATI_render_texture") ||
2430 glxRequireExtension("GLX_ARB_render_texture"))
2431 register_extension(&WGL_ARB_render_texture);
2433 /* EXT Extensions */
2435 register_extension(&WGL_EXT_extensions_string);
2437 if (glxRequireExtension("GLX_SGI_swap_control"))
2438 register_extension(&WGL_EXT_swap_control);
2442 static XID create_glxpixmap(X11DRV_PDEVICE *physDev)
2446 XVisualInfo template;
2451 /* Retrieve the visualid from our main visual which is the only visual we can use */
2452 template.visualid = XVisualIDFromVisual(visual);
2453 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
2455 ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
2457 wine_tsx11_unlock();
2458 TRACE("return %lx\n", ret);
2462 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
2468 if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
2469 ret = physDev->drawable; /* PBuffer */
2472 if(!physDev->bitmap->glxpixmap)
2473 physDev->bitmap->glxpixmap = create_glxpixmap(physDev);
2474 ret = physDev->bitmap->glxpixmap;
2478 ret = physDev->drawable;
2482 BOOL destroy_glxpixmap(XID glxpixmap)
2485 pglXDestroyGLXPixmap(gdi_display, glxpixmap);
2486 wine_tsx11_unlock();
2491 * X11DRV_SwapBuffers
2493 * Swap the buffers of this DC
2495 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev)
2497 GLXDrawable drawable;
2498 if (!has_opengl()) {
2499 ERR("No libGL on this box - disabling OpenGL support !\n");
2503 TRACE_(opengl)("(%p)\n", physDev);
2505 drawable = get_glxdrawable(physDev);
2507 pglXSwapBuffers(gdi_display, drawable);
2508 wine_tsx11_unlock();
2513 static long prev_time, frames;
2515 DWORD time = GetTickCount();
2517 /* every 1.5 seconds */
2518 if (time - prev_time > 1500) {
2519 TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
2528 /***********************************************************************
2529 * X11DRV_setup_opengl_visual
2531 * Setup the default visual used for OpenGL and Direct3D, and the desktop
2532 * window (if it exists). If OpenGL isn't available, the visual is simply
2533 * set to the default visual for the display
2535 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
2537 XVisualInfo *visual = NULL;
2538 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support, */
2539 int dblBuf[] = {GLX_RGBA,GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DOUBLEBUFFER, None};
2540 if (!has_opengl()) return NULL;
2543 visual = pglXChooseVisual(display, DefaultScreen(display), dblBuf);
2544 wine_tsx11_unlock();
2545 if (visual == NULL) {
2546 /* fallback to 16 bits depth, no alpha */
2547 int dblBuf2[] = {GLX_RGBA,GLX_DEPTH_SIZE, 16, GLX_STENCIL_SIZE, 8, GLX_DOUBLEBUFFER, None};
2548 WARN("Failed to get a visual with at least 24 bits depth\n");
2551 visual = pglXChooseVisual(display, DefaultScreen(display), dblBuf2);
2552 wine_tsx11_unlock();
2553 if (visual == NULL) {
2554 /* fallback to no stencil */
2555 int dblBuf2[] = {GLX_RGBA,GLX_DEPTH_SIZE, 16, GLX_DOUBLEBUFFER, None};
2556 WARN("Failed to get a visual with at least 8 bits of stencil\n");
2559 visual = pglXChooseVisual(display, DefaultScreen(display), dblBuf2);
2560 wine_tsx11_unlock();
2561 if (visual == NULL) {
2562 /* This should only happen if we cannot find a match with a depth size 16 */
2563 FIXME("Failed to find a suitable visual\n");
2568 TRACE("Visual ID %lx Chosen\n",visual->visualid);
2572 #else /* no OpenGL includes */
2574 void X11DRV_OpenGL_Init(Display *display)
2578 /***********************************************************************
2579 * ChoosePixelFormat (X11DRV.@)
2581 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
2582 const PIXELFORMATDESCRIPTOR *ppfd) {
2583 ERR("No OpenGL support compiled in.\n");
2588 /***********************************************************************
2589 * DescribePixelFormat (X11DRV.@)
2591 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
2594 PIXELFORMATDESCRIPTOR *ppfd) {
2595 ERR("No OpenGL support compiled in.\n");
2600 /***********************************************************************
2601 * GetPixelFormat (X11DRV.@)
2603 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
2604 ERR("No OpenGL support compiled in.\n");
2609 /***********************************************************************
2610 * SetPixelFormat (X11DRV.@)
2612 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
2614 const PIXELFORMATDESCRIPTOR *ppfd) {
2615 ERR("No OpenGL support compiled in.\n");
2620 /***********************************************************************
2621 * SwapBuffers (X11DRV.@)
2623 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
2624 ERR_(opengl)("No OpenGL support compiled in.\n");
2629 /* OpenGL32 wglCreateContext */
2630 HGLRC WINAPI X11DRV_wglCreateContext(HDC hdc) {
2631 ERR_(opengl)("No OpenGL support compiled in.\n");
2635 /* OpenGL32 wglDeleteContext */
2636 BOOL WINAPI X11DRV_wglDeleteContext(HGLRC hglrc) {
2637 ERR_(opengl)("No OpenGL support compiled in.\n");
2641 /* OpenGL32 wglGetCurrentContext() */
2642 HGLRC WINAPI X11DRV_wglGetCurrentContext(void) {
2643 ERR_(opengl)("No OpenGL support compiled in.\n");
2647 /* OpenGL32 wglGetCurrentDC */
2648 HDC WINAPI X11DRV_wglGetCurrentDC(void) {
2649 ERR_(opengl)("No OpenGL support compiled in.\n");
2653 /* OpenGL32 wglGetCurrentReadDCARB */
2654 HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
2656 ERR_(opengl)("No OpenGL support compiled in.\n");
2660 /* OpenGL32: wglGetProcAddress */
2661 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
2662 ERR_(opengl)("No OpenGL support compiled in.\n");
2666 /* OpenGL32 wglMakeCurrent */
2667 BOOL WINAPI X11DRV_wglMakeCurrent(HDC hdc, HGLRC hglrc) {
2668 ERR_(opengl)("No OpenGL support compiled in.\n");
2672 /* OpenGL32 wglMakeContextCurrentARB */
2673 BOOL WINAPI X11DRV_wglMakeContextCurrentARB(HDC hDrawDC, HDC hReadDC, HGLRC hglrc)
2675 ERR_(opengl)("No OpenGL support compiled in.\n");
2679 /* OpenGL32 wglShaderLists */
2680 BOOL WINAPI X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
2681 ERR_(opengl)("No OpenGL support compiled in.\n");
2685 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2686 void X11DRV_wglGetIntegerv(int pname, int* params) {
2687 ERR_(opengl)("No OpenGL support compiled in.\n");
2690 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
2695 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
2700 BOOL destroy_glxpixmap(XID glxpixmap)
2705 #endif /* defined(HAVE_OPENGL) */