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 typedef struct wine_glpixelformat {
133 static Wine_GLContext *context_list;
134 static struct WineGLInfo WineGLInfo = { 0 };
135 static int use_render_texture_emulation = 0;
136 static int use_render_texture_ati = 0;
137 static int swap_interval = 1;
139 #define MAX_EXTENSIONS 16
140 static const WineGLExtension *WineGLExtensionList[MAX_EXTENSIONS];
141 static int WineGLExtensionListSize;
143 #define MAX_GLPIXELFORMATS 32
144 static WineGLPixelFormat WineGLPixelFormatList[MAX_GLPIXELFORMATS];
145 static int WineGLPixelFormatListSize = 0;
147 static void X11DRV_WineGL_LoadExtensions(void);
149 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
150 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
151 TRACE(" - dwFlags : ");
152 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
153 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
154 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
155 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
156 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
157 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
158 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
159 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
160 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
161 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
162 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
163 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
164 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
165 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
166 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
167 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
168 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
172 TRACE(" - iPixelType : ");
173 switch (ppfd->iPixelType) {
174 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
175 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
179 TRACE(" - Color : %d\n", ppfd->cColorBits);
180 TRACE(" - Red : %d\n", ppfd->cRedBits);
181 TRACE(" - Green : %d\n", ppfd->cGreenBits);
182 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
183 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
184 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
185 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
186 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
187 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
189 TRACE(" - iLayerType : ");
190 switch (ppfd->iLayerType) {
191 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
192 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
193 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
198 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient and
199 include all dependencies
202 #define SONAME_LIBGL "libGL.so"
205 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
206 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
208 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
210 MAKE_FUNCPTR(glXChooseVisual)
211 MAKE_FUNCPTR(glXCreateContext)
212 MAKE_FUNCPTR(glXCreateGLXPixmap)
213 MAKE_FUNCPTR(glXGetCurrentContext)
214 MAKE_FUNCPTR(glXDestroyContext)
215 MAKE_FUNCPTR(glXDestroyGLXPixmap)
216 MAKE_FUNCPTR(glXGetConfig)
217 MAKE_FUNCPTR(glXIsDirect)
218 MAKE_FUNCPTR(glXMakeCurrent)
219 MAKE_FUNCPTR(glXSwapBuffers)
220 MAKE_FUNCPTR(glXQueryExtension)
221 MAKE_FUNCPTR(glXQueryVersion)
222 MAKE_FUNCPTR(glXUseXFont)
225 MAKE_FUNCPTR(glXGetClientString)
226 MAKE_FUNCPTR(glXQueryExtensionsString)
227 MAKE_FUNCPTR(glXQueryServerString)
230 MAKE_FUNCPTR(glXGetFBConfigs)
231 MAKE_FUNCPTR(glXChooseFBConfig)
232 MAKE_FUNCPTR(glXCreatePbuffer)
233 MAKE_FUNCPTR(glXDestroyPbuffer)
234 MAKE_FUNCPTR(glXGetFBConfigAttrib)
235 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
236 MAKE_FUNCPTR(glXMakeContextCurrent)
237 MAKE_FUNCPTR(glXQueryDrawable)
238 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
241 static void* (*pglXGetProcAddressARB)(const GLubyte *);
242 static BOOL (*pglXBindTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
243 static BOOL (*pglXReleaseTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
244 static BOOL (*pglXDrawableAttribARB)(Display *dpy, GLXDrawable draw, const int *attribList);
245 static int (*pglXSwapIntervalSGI)(int);
247 /* Standard OpenGL */
248 MAKE_FUNCPTR(glBindTexture)
249 MAKE_FUNCPTR(glBitmap)
250 MAKE_FUNCPTR(glCopyTexSubImage1D)
251 MAKE_FUNCPTR(glCopyTexSubImage2D)
252 MAKE_FUNCPTR(glDrawBuffer)
253 MAKE_FUNCPTR(glEndList)
254 MAKE_FUNCPTR(glGetError)
255 MAKE_FUNCPTR(glGetIntegerv)
256 MAKE_FUNCPTR(glGetString)
257 MAKE_FUNCPTR(glNewList)
258 MAKE_FUNCPTR(glPixelStorei)
261 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
263 static BOOL infoInitialized = FALSE;
265 int screen = DefaultScreen(gdi_display);
266 Window win = RootWindow(gdi_display, screen);
268 XVisualInfo template;
271 GLXContext ctx = NULL;
275 infoInitialized = TRUE;
279 visual = DefaultVisual(gdi_display, screen);
280 template.visualid = XVisualIDFromVisual(visual);
281 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
283 /* Create a GLX Context. Without one we can't query GL information */
284 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
288 pglXMakeCurrent(gdi_display, win, ctx);
290 ERR(" couldn't initialize OpenGL, expect problems\n");
295 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
296 WineGLInfo.glExtensions = (const char *) pglGetString(GL_EXTENSIONS);
298 /* Get the common GLX version supported by GLX client and server ( major/minor) */
299 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
301 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
302 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
304 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
305 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
307 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
308 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
310 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
311 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
312 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
313 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
314 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
318 pglXMakeCurrent(gdi_display, None, NULL);
319 pglXDestroyContext(gdi_display, ctx);
325 static BOOL has_opengl(void)
327 static int init_done;
328 static void *opengl_handle;
329 const char *glx_extensions;
331 int error_base, event_base;
333 if (init_done) return (opengl_handle != NULL);
336 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, NULL, 0);
337 if (opengl_handle == NULL) return FALSE;
339 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
340 if (pglXGetProcAddressARB == NULL) {
341 ERR("could not find glXGetProcAddressARB in libGL.\n");
345 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((unsigned char*)#f)) == NULL) goto sym_not_found;
347 LOAD_FUNCPTR(glXChooseVisual)
348 LOAD_FUNCPTR(glXCreateContext)
349 LOAD_FUNCPTR(glXCreateGLXPixmap)
350 LOAD_FUNCPTR(glXGetCurrentContext)
351 LOAD_FUNCPTR(glXDestroyContext)
352 LOAD_FUNCPTR(glXDestroyGLXPixmap)
353 LOAD_FUNCPTR(glXGetConfig)
354 LOAD_FUNCPTR(glXIsDirect)
355 LOAD_FUNCPTR(glXMakeCurrent)
356 LOAD_FUNCPTR(glXSwapBuffers)
357 LOAD_FUNCPTR(glXQueryExtension)
358 LOAD_FUNCPTR(glXQueryVersion)
359 LOAD_FUNCPTR(glXUseXFont)
362 LOAD_FUNCPTR(glXGetClientString)
363 LOAD_FUNCPTR(glXQueryExtensionsString)
364 LOAD_FUNCPTR(glXQueryServerString)
367 LOAD_FUNCPTR(glXCreatePbuffer)
368 LOAD_FUNCPTR(glXDestroyPbuffer)
369 LOAD_FUNCPTR(glXMakeContextCurrent)
370 LOAD_FUNCPTR(glXGetCurrentReadDrawable)
371 LOAD_FUNCPTR(glXGetFBConfigs)
373 /* Standard OpenGL calls */
374 LOAD_FUNCPTR(glBindTexture)
375 LOAD_FUNCPTR(glBitmap)
376 LOAD_FUNCPTR(glEndList)
377 LOAD_FUNCPTR(glCopyTexSubImage1D)
378 LOAD_FUNCPTR(glCopyTexSubImage2D)
379 LOAD_FUNCPTR(glDrawBuffer)
380 LOAD_FUNCPTR(glGetError)
381 LOAD_FUNCPTR(glGetIntegerv)
382 LOAD_FUNCPTR(glGetString)
383 LOAD_FUNCPTR(glNewList)
384 LOAD_FUNCPTR(glPixelStorei)
387 if(!X11DRV_WineGL_InitOpenglInfo()) {
388 ERR("Intialization of OpenGL info failed, disabling OpenGL!\n");
389 wine_dlclose(opengl_handle, NULL, 0);
390 opengl_handle = NULL;
395 if (pglXQueryExtension(gdi_display, &error_base, &event_base) == True) {
396 TRACE("GLX is up and running error_base = %d\n", error_base);
398 wine_dlclose(opengl_handle, NULL, 0);
399 opengl_handle = NULL;
402 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
403 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
406 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
407 * depends on the reported GLX client / server version and on the client / server extension list.
408 * Those don't have to be the same.
410 * In general the server GLX information should be used in case of indirect rendering. When direct
411 * rendering is used, the OpenGL client library is responsible for which GLX calls are available.
412 * Nvidia's OpenGL drivers are the best in terms of GLX features. At the moment of writing their
413 * 8762 drivers support 1.3 for the server and 1.4 for the client and they support lots of extensions.
414 * Unfortunately it is much more complicated for Mesa/DRI-based drivers and ATI's drivers.
415 * Both sets of drivers report a server version of 1.2 and the client version can be 1.3 or 1.4.
416 * Further, in case of at least ATI's drivers, one crucial extension needed for our pixel format code
417 * is only available in the list of server extensions and not in the client list.
419 * The versioning checks below try to take into account the comments from above.
422 /* Depending on the use of direct or indirect rendering we need either the list of extensions
423 * exported by the client or by the server.
425 if(WineGLInfo.glxDirect)
426 glx_extensions = WineGLInfo.glxClientExtensions;
428 glx_extensions = WineGLInfo.glxServerExtensions;
430 /* Based on the default opengl context we decide whether direct or indirect rendering is used.
431 * In case of indirect rendering we check if the GLX version of the server is 1.2 and else
432 * the client version is checked.
434 if ((!WineGLInfo.glxDirect && !strcmp("1.2", WineGLInfo.glxServerVersion)) ||
435 (WineGLInfo.glxDirect && !strcmp("1.2", WineGLInfo.glxClientVersion)))
437 if (NULL != strstr(glx_extensions, "GLX_SGIX_fbconfig")) {
438 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
439 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
440 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
442 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxClientVersion);
445 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
446 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
447 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
450 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
451 * enable this function when the Xserver understand GLX 1.3 or newer
453 if (!strcmp("1.2", WineGLInfo.glxServerVersion))
454 pglXQueryDrawable = NULL;
456 pglXQueryDrawable = wine_dlsym(RTLD_DEFAULT, "glXQueryDrawable", NULL, 0);
458 if (NULL != strstr(glx_extensions, "GLX_ATI_render_texture")) {
459 pglXBindTexImageARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageARB");
460 pglXReleaseTexImageARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageARB");
461 pglXDrawableAttribARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribARB");
464 X11DRV_WineGL_LoadExtensions();
467 return (opengl_handle != NULL);
470 wine_dlclose(opengl_handle, NULL, 0);
471 opengl_handle = NULL;
475 static inline Wine_GLContext *alloc_context(void)
479 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLContext))))
481 ret->next = context_list;
482 if (context_list) context_list->prev = ret;
488 static inline void free_context(Wine_GLContext *context)
490 if (context->next != NULL) context->next->prev = context->prev;
491 if (context->prev != NULL) context->prev->next = context->next;
492 else context_list = context->next;
494 HeapFree(GetProcessHeap(), 0, context);
497 static inline Wine_GLContext *get_context_from_GLXContext(GLXContext ctx)
500 if (!ctx) return NULL;
501 for (ret = context_list; ret; ret = ret->next) if (ctx == ret->ctx) break;
506 * get_drawable (internal)
508 * Retrieve the GLX drawable to use on a given DC.
510 inline static Drawable get_drawable( HDC hdc )
512 GLXDrawable drawable;
513 enum x11drv_escape_codes escape = X11DRV_GET_GLX_DRAWABLE;
515 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape,
516 sizeof(drawable), (LPSTR)&drawable )) drawable = 0;
520 inline static void set_drawable( HDC hdc, Drawable drawable )
522 struct x11drv_escape_set_drawable escape;
524 escape.code = X11DRV_SET_DRAWABLE;
525 escape.drawable = drawable;
526 escape.mode = IncludeInferiors;
527 escape.org.x = escape.org.y = 0;
528 escape.drawable_org.x = escape.drawable_org.y = 0;
530 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape, 0, NULL );
534 * get_hdc_from_Drawable (internal)
536 * For use by wglGetCurrentReadDCARB.
538 inline static HDC get_hdc_from_Drawable(GLXDrawable d)
541 for (ret = context_list; ret; ret = ret->next) {
542 if (d == get_drawable( ret->hdc )) {
549 inline static BOOL is_valid_context( Wine_GLContext *ctx )
552 for (ptr = context_list; ptr; ptr = ptr->next) if (ptr == ctx) break;
553 return (ptr != NULL);
556 static int describeContext(Wine_GLContext* ctx) {
559 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
560 pglXGetFBConfigAttrib(ctx->display, ctx->fb_conf, GLX_FBCONFIG_ID, &tmp);
561 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
562 pglXGetFBConfigAttrib(ctx->display, ctx->fb_conf, GLX_VISUAL_ID, &tmp);
563 TRACE(" - VISUAL_ID 0x%x\n", tmp);
568 static int describeDrawable(Wine_GLContext* ctx, Drawable drawable) {
571 int attribList[3] = { GLX_FBCONFIG_ID, 0, None };
574 if (pglXQueryDrawable == NULL) {
575 /** glXQueryDrawable not available so returns not supported */
579 TRACE(" Drawable %p have :\n", (void*) drawable);
580 pglXQueryDrawable(ctx->display, drawable, GLX_WIDTH, (unsigned int*) &tmp);
581 TRACE(" - WIDTH as %d\n", tmp);
582 pglXQueryDrawable(ctx->display, drawable, GLX_HEIGHT, (unsigned int*) &tmp);
583 TRACE(" - HEIGHT as %d\n", tmp);
584 pglXQueryDrawable(ctx->display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &tmp);
585 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
588 fbCfgs = pglXChooseFBConfig(ctx->display, DefaultScreen(ctx->display), attribList, &nElements);
589 if (fbCfgs == NULL) {
593 pglXGetFBConfigAttrib(ctx->display, fbCfgs[0], GLX_VISUAL_ID, &tmp);
594 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
601 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
606 int wantColorBits = 0;
609 while (0 != iWGLAttr[cur]) {
610 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
612 switch (iWGLAttr[cur]) {
613 case WGL_COLOR_BITS_ARB:
614 pop = iWGLAttr[++cur];
615 wantColorBits = pop; /** see end */
617 case WGL_BLUE_BITS_ARB:
618 pop = iWGLAttr[++cur];
619 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
620 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
622 case WGL_RED_BITS_ARB:
623 pop = iWGLAttr[++cur];
624 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
625 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
627 case WGL_GREEN_BITS_ARB:
628 pop = iWGLAttr[++cur];
629 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
630 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
632 case WGL_ALPHA_BITS_ARB:
633 pop = iWGLAttr[++cur];
635 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
636 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
638 case WGL_DEPTH_BITS_ARB:
639 pop = iWGLAttr[++cur];
640 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
641 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
643 case WGL_STENCIL_BITS_ARB:
644 pop = iWGLAttr[++cur];
645 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
646 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
648 case WGL_DOUBLE_BUFFER_ARB:
649 pop = iWGLAttr[++cur];
650 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
651 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
654 case WGL_PIXEL_TYPE_ARB:
655 pop = iWGLAttr[++cur];
657 case WGL_TYPE_COLORINDEX_ARB: pop = GLX_COLOR_INDEX_BIT; isColor = 1; break ;
658 case WGL_TYPE_RGBA_ARB: pop = GLX_RGBA_BIT; break ;
659 case WGL_TYPE_RGBA_FLOAT_ATI: pop = GLX_RGBA_FLOAT_ATI_BIT; break ;
661 ERR("unexpected PixelType(%x)\n", pop);
664 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pop);
665 TRACE("pAttr[%d] = GLX_RENDER_TYPE: %d\n", cur, pop);
668 case WGL_SUPPORT_GDI_ARB:
669 pop = iWGLAttr[++cur];
670 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
671 TRACE("pAttr[%d] = GLX_RENDERABLE: %d\n", cur, pop);
674 case WGL_DRAW_TO_BITMAP_ARB:
675 pop = iWGLAttr[++cur];
676 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
677 TRACE("pAttr[%d] = GLX_RENDERABLE: %d\n", cur, pop);
679 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT);
680 TRACE("pAttr[%d] = GLX_DRAWABLE_TYPE: GLX_PIXMAP_BIT\n", cur);
684 case WGL_DRAW_TO_WINDOW_ARB:
685 pop = iWGLAttr[++cur];
687 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT);
688 TRACE("pAttr[%d] = GLX_DRAWABLE_TYPE: GLX_WINDOW_BIT\n", cur);
692 case WGL_DRAW_TO_PBUFFER_ARB:
693 pop = iWGLAttr[++cur];
694 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
695 TRACE("pAttr[%d] = GLX_RENDERABLE: %d\n", cur, pop);
697 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT);
698 TRACE("pAttr[%d] = GLX_DRAWABLE_TYPE: GLX_PBUFFER_BIT\n", cur);
702 case WGL_ACCELERATION_ARB:
703 case WGL_SUPPORT_OPENGL_ARB:
704 pop = iWGLAttr[++cur];
705 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
706 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
709 case WGL_PBUFFER_LARGEST_ARB:
710 pop = iWGLAttr[++cur];
711 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
712 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
715 case WGL_SAMPLE_BUFFERS_ARB:
716 pop = iWGLAttr[++cur];
717 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
718 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
721 case WGL_SAMPLES_ARB:
722 pop = iWGLAttr[++cur];
723 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
724 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
727 case WGL_TEXTURE_FORMAT_ARB:
728 case WGL_TEXTURE_TARGET_ARB:
729 case WGL_MIPMAP_TEXTURE_ARB:
730 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
731 pop = iWGLAttr[++cur];
733 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
735 if (use_render_texture_ati) {
736 /** nothing to do here */
738 else if (!use_render_texture_emulation) {
739 if (WGL_NO_TEXTURE_ARB != pop) {
740 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
741 return -1; /** error: don't support it */
743 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
744 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT);
749 case WGL_BIND_TO_TEXTURE_RGB_ARB:
750 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
751 pop = iWGLAttr[++cur];
752 /** cannot be converted, see direct handling on
753 * - wglGetPixelFormatAttribivARB
754 * TODO: wglChoosePixelFormat
759 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
766 * Trick as WGL_COLOR_BITS_ARB != GLX_BUFFER_SIZE
767 * WGL_COLOR_BITS_ARB + WGL_ALPHA_BITS_ARB == GLX_BUFFER_SIZE
770 * The number of color bitplanes in each color buffer. For RGBA
771 * pixel types, it is the size of the color buffer, excluding the
772 * alpha bitplanes. For color-index pixels, it is the size of the
773 * color index buffer.
776 * This attribute defines the number of bits per color buffer.
777 * For GLX FBConfigs that correspond to a PseudoColor or StaticColor visual,
778 * this is equal to the depth value reported in the X11 visual.
779 * For GLX FBConfigs that correspond to TrueColor or DirectColor visual,
780 * this is the sum of GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_BLUE_SIZE, and GLX_ALPHA_SIZE.
783 if (0 < wantColorBits) {
785 wantColorBits += sz_alpha;
787 if (32 < wantColorBits) {
788 ERR("buggy %d GLX_BUFFER_SIZE default to 32\n", wantColorBits);
791 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, wantColorBits);
792 TRACE("pAttr[%d] = WGL_COLOR_BITS_ARB: %d\n", cur, wantColorBits);
798 BOOL get_fbconfig_from_visualid(Display *display, Visual *visual, int *fmt_id, int *fmt_index)
800 GLXFBConfig* cfgs = NULL;
807 if(!display || !display) {
808 ERR("Invalid display or visual\n");
810 visualid = XVisualIDFromVisual(visual);
812 /* Get a list of all available framebuffer configurations */
813 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
814 if (NULL == cfgs || 0 == nCfgs) {
815 ERR("glXChooseFBConfig returns NULL\n");
816 if(cfgs != NULL) XFree(cfgs);
820 /* Find the requested offscreen format and count the number of offscreen formats */
821 for(i=0; i<nCfgs; i++) {
822 pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id);
823 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id);
825 /* We are looking up the GLX index of our main visual and have found it :) */
826 if(visualid == tmp_vis_id) {
827 TRACE("Found FBCONFIG_ID 0x%x at index %d for VISUAL_ID 0x%x\n", tmp_fmt_id, i, tmp_vis_id);
829 *fmt_id = tmp_fmt_id;
835 ERR("No fbconfig found for Wine's main visual (0x%lx), expect problems!\n", visualid);
840 static BOOL init_formats(Display *display, int screen, Visual *visual)
842 int fmt_id, fmt_index;
844 /* Locate the fbconfig correspondig to our main visual */
845 if(!get_fbconfig_from_visualid(display, visual, &fmt_id, &fmt_index)) {
846 ERR("Can't get the FBCONFIG_ID for the main visual, expect problems!\n");
850 /* Put Wine's internal format at the first index */
851 WineGLPixelFormatList[0].iPixelFormat = 1;
852 WineGLPixelFormatList[0].fbconfig = fmt_id;
853 WineGLPixelFormatList[0].fmt_index = fmt_index;
854 WineGLPixelFormatListSize = 1;
856 /* In the future test for compatible formats here */
861 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
862 * In our WGL implementation we only support a subset of these formats namely the format of
863 * Wine's main visual and offscreen formats (if they are available).
864 * This function converts a WGL format to its corresponding GLX one. It returns the index (zero-based)
865 * into the GLX FB config table and it returns the number of supported WGL formats in fmt_count.
867 static BOOL ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, int *fmt_index, int *fmt_count)
869 /* Init the list of pixel formats when we need it */
870 if(!WineGLPixelFormatListSize)
871 init_formats(display, DefaultScreen(display), visual);
873 if((iPixelFormat <= 0) || (iPixelFormat > WineGLPixelFormatListSize)) {
874 ERR("invalid iPixelFormat %d\n", iPixelFormat);
878 *fmt_index = WineGLPixelFormatList[iPixelFormat-1].fmt_index;
879 *fmt_count = WineGLPixelFormatListSize;
880 TRACE("Returning fmt_index=%d, fmt_count=%d for iPixelFormat=%d\n", *fmt_index, *fmt_count, iPixelFormat);
885 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
886 static int ConvertPixelFormatGLXtoWGL(Display *display, int fbconfig)
890 /* Init the list of pixel formats when we need it */
891 if(!WineGLPixelFormatListSize)
892 init_formats(display, DefaultScreen(display), visual);
894 for(i=0; i<WineGLPixelFormatListSize; i++) {
895 if(WineGLPixelFormatList[i].fbconfig == fbconfig) {
896 TRACE("Returning iPixelFormat %d for fbconfig 0x%x\n", WineGLPixelFormatList[i].iPixelFormat, fbconfig);
897 return WineGLPixelFormatList[i].iPixelFormat;
900 TRACE("No compatible format found for FBCONFIG_ID=0x%x\n", fbconfig);
905 * X11DRV_ChoosePixelFormat
907 * Equivalent to glXChooseVisual.
909 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
910 const PIXELFORMATDESCRIPTOR *ppfd) {
911 GLXFBConfig* cfgs = NULL;
918 ERR("No libGL on this box - disabling OpenGL support !\n");
922 if (TRACE_ON(opengl)) {
923 TRACE("(%p,%p)\n", physDev, ppfd);
925 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR *) ppfd);
930 ERR("Can't get an opengl visual!\n");
934 /* Get a list containing all supported FB configurations */
935 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
936 if (NULL == cfgs || 0 == nCfgs) {
937 ERR("glXGetFBConfigs returns NULL (glError: %d)\n", pglGetError());
941 /* In case an fbconfig was found, check if it matches to the requirements of the ppfd */
942 if(!ConvertPixelFormatWGLtoGLX(gdi_display, 1 /* main visual */, &fmt_index, &value)) {
943 ERR("Can't find a matching FBCONFIG_ID for VISUAL_ID 0x%lx!\n", visual->visualid);
950 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_RENDER_TYPE, &value);
951 if (value & GLX_RGBA_BIT)
952 iPixelType = PFD_TYPE_RGBA;
954 iPixelType = PFD_TYPE_COLORINDEX;
956 if (ppfd->iPixelType != iPixelType) {
957 TRACE("pixel type mismatch\n");
962 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_DOUBLEBUFFER, &value); if (value) dwFlags |= PFD_DOUBLEBUFFER;
963 if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) && (ppfd->dwFlags & PFD_DOUBLEBUFFER)) {
964 if (!(dwFlags & PFD_DOUBLEBUFFER)) {
965 TRACE("dbl buffer mismatch\n");
971 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_STEREO, &value); if (value) dwFlags |= PFD_STEREO;
972 if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE) && (ppfd->dwFlags & PFD_STEREO)) {
973 if (!(dwFlags & PFD_STEREO)) {
974 TRACE("stereo mismatch\n");
980 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_ALPHA_SIZE, &value);
981 if (ppfd->iPixelType==PFD_TYPE_RGBA && ppfd->cAlphaBits && !value) {
982 TRACE("alpha mismatch\n");
987 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_DEPTH_SIZE, &value);
988 if (ppfd->cDepthBits && !value) {
989 TRACE("depth mismatch\n");
994 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_STENCIL_SIZE, &value);
995 if (ppfd->cStencilBits && !value) {
996 TRACE("stencil mismatch\n");
1001 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_AUX_BUFFERS, &value);
1002 if (ppfd->cAuxBuffers && !value) {
1003 TRACE("aux mismatch\n");
1007 /* When we pass all the checks we have found a matching format :) */
1009 TRACE("Successfully found a matching mode, returning index: %d\n", ret);
1014 TRACE("No matching mode was found returning 0\n");
1016 if (NULL != cfgs) XFree(cfgs);
1017 wine_tsx11_unlock();
1022 * X11DRV_DescribePixelFormat
1024 * Get the pixel-format descriptor associated to the given id
1026 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
1029 PIXELFORMATDESCRIPTOR *ppfd) {
1030 /*XVisualInfo *vis;*/
1034 GLXFBConfig* cfgs = NULL;
1040 if (!has_opengl()) {
1041 ERR("No libGL on this box - disabling OpenGL support !\n");
1045 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
1048 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
1049 wine_tsx11_unlock();
1051 if (NULL == cfgs || 0 == nCfgs) {
1052 ERR("unexpected iPixelFormat(%d), returns NULL\n", iPixelFormat);
1053 return 0; /* unespected error */
1056 /* This function always reports the total number of supported pixel formats.
1057 * At the moment we only support the pixel format corresponding to the main
1058 * visual which got created at x11drv initialization. More formats could be
1059 * supported if there was a way to recreate x11 windows in x11drv.
1060 * Because we only support one format nCfgs needs to be set to 1.
1065 /* The application is only querying the number of visuals */
1067 if (NULL != cfgs) XFree(cfgs);
1068 wine_tsx11_unlock();
1072 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1073 ERR("Wrong structure size !\n");
1074 /* Should set error */
1078 if (nCfgs < iPixelFormat || 1 > iPixelFormat) {
1079 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL\n", iPixelFormat, nCfgs);
1083 /* Retrieve the index in the FBConfig table corresponding to the visual ID from the main visual */
1084 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &value)) {
1085 ERR("Can't find a valid pixel format index from the main visual, expect problems!\n");
1090 cur = cfgs[fmt_index];
1092 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1093 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1096 /* These flags are always the same... */
1097 ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
1098 /* Now the flags extracted from the Visual */
1102 pglXGetFBConfigAttrib(gdi_display, cur, GLX_CONFIG_CAVEAT, &value);
1103 if(value == GLX_SLOW_CONFIG)
1104 ppfd->dwFlags |= PFD_GENERIC_ACCELERATED;
1106 pglXGetFBConfigAttrib(gdi_display, cur, GLX_DOUBLEBUFFER, &value); if (value) ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1107 pglXGetFBConfigAttrib(gdi_display, cur, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1110 pglXGetFBConfigAttrib(gdi_display, cur, GLX_RENDER_TYPE, &value);
1111 if (value & GLX_RGBA_BIT)
1112 ppfd->iPixelType = PFD_TYPE_RGBA;
1114 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1117 pglXGetFBConfigAttrib(gdi_display, cur, GLX_BUFFER_SIZE, &value);
1118 ppfd->cColorBits = value;
1120 /* Red, green, blue and alpha bits / shifts */
1121 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1122 pglXGetFBConfigAttrib(gdi_display, cur, GLX_RED_SIZE, &rb);
1123 pglXGetFBConfigAttrib(gdi_display, cur, GLX_GREEN_SIZE, &gb);
1124 pglXGetFBConfigAttrib(gdi_display, cur, GLX_BLUE_SIZE, &bb);
1125 pglXGetFBConfigAttrib(gdi_display, cur, GLX_ALPHA_SIZE, &ab);
1127 ppfd->cRedBits = rb;
1128 ppfd->cRedShift = gb + bb + ab;
1129 ppfd->cBlueBits = bb;
1130 ppfd->cBlueShift = ab;
1131 ppfd->cGreenBits = gb;
1132 ppfd->cGreenShift = bb + ab;
1133 ppfd->cAlphaBits = ab;
1134 ppfd->cAlphaShift = 0;
1137 ppfd->cRedShift = 0;
1138 ppfd->cBlueBits = 0;
1139 ppfd->cBlueShift = 0;
1140 ppfd->cGreenBits = 0;
1141 ppfd->cGreenShift = 0;
1142 ppfd->cAlphaBits = 0;
1143 ppfd->cAlphaShift = 0;
1145 /* Accums : to do ... */
1148 pglXGetFBConfigAttrib(gdi_display, cur, GLX_DEPTH_SIZE, &value);
1149 ppfd->cDepthBits = value;
1152 pglXGetFBConfigAttrib(gdi_display, cur, GLX_STENCIL_SIZE, &value);
1153 ppfd->cStencilBits = value;
1155 wine_tsx11_unlock();
1157 /* Aux : to do ... */
1159 ppfd->iLayerType = PFD_MAIN_PLANE;
1161 if (TRACE_ON(opengl)) {
1162 dump_PIXELFORMATDESCRIPTOR(ppfd);
1166 if (NULL != cfgs) XFree(cfgs);
1167 wine_tsx11_unlock();
1173 * X11DRV_GetPixelFormat
1175 * Get the pixel-format id used by this DC
1177 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
1178 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1180 return physDev->current_pf;
1184 * X11DRV_SetPixelFormat
1186 * Set the pixel-format id used by this DC
1188 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
1190 const PIXELFORMATDESCRIPTOR *ppfd) {
1191 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1193 if (!has_opengl()) {
1194 ERR("No libGL on this box - disabling OpenGL support !\n");
1198 /* At the moment we only support the pixelformat corresponding to the main
1199 * x11drv visual which got created at x11drv initialization. More formats
1200 * could be supported if there was a way to recreate x11 windows in x11drv
1202 if(iPixelFormat != 1) {
1203 TRACE("Invalid iPixelFormat: %d\n", iPixelFormat);
1207 physDev->current_pf = iPixelFormat;
1209 if (TRACE_ON(opengl)) {
1211 GLXFBConfig* cfgs_fmt = NULL;
1212 GLXFBConfig cur_cfg;
1217 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &value)) {
1218 ERR("Can't find a valid pixel format index from the main visual, expect problems!\n");
1219 return TRUE; /* Return true because the SetPixelFormat stuff itself passed */
1223 * How to test if hdc current drawable is compatible (visual/FBConfig) ?
1225 * in case of root window created HDCs we crash here :(
1227 Drawable drawable = get_drawable( physDev->hdc );
1228 TRACE(" drawable (%p,%p) have :\n", drawable, root_window);
1229 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &value);
1230 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
1231 pglXQueryDrawable(gdi_display, drawable, GLX_VISUAL_ID, (unsigned int*) &value);
1232 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
1233 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &value);
1234 TRACE(" - WIDTH as %d\n", tmp);
1235 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &value);
1236 TRACE(" - HEIGHT as %d\n", tmp);
1238 cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
1239 cur_cfg = cfgs_fmt[fmt_index];
1240 gl_test = pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_FBCONFIG_ID, &value);
1242 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1244 TRACE(" FBConfig have :\n");
1245 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1246 pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_VISUAL_ID, &value);
1247 TRACE(" - VISUAL_ID 0x%x\n", value);
1248 pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_DRAWABLE_TYPE, &value);
1249 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1257 * X11DRV_wglCreateContext
1259 * For OpenGL32 wglCreateContext.
1261 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
1263 Wine_GLContext *ret;
1264 GLXFBConfig* cfgs_fmt = NULL;
1265 GLXFBConfig cur_cfg;
1266 int hdcPF = 1; /* We can only use Wine's main visual which has an index of 1 */
1272 HDC hdc = physDev->hdc;
1274 TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1276 if (!has_opengl()) {
1277 ERR("No libGL on this box - disabling OpenGL support !\n");
1281 /* First, get the visual in use by the X11DRV */
1282 if (!gdi_display) return 0;
1284 /* We can only render using the iPixelFormat (1) of Wine's Main visual, we need to get the corresponding GLX format.
1285 * If this fails something is very wrong on the system. */
1286 if(!ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, &fmt_index, &tmp)) {
1287 ERR("Cannot get FB Config for main iPixelFormat 1, expect problems!\n");
1288 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1292 cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
1293 if (NULL == cfgs_fmt || 0 == nCfgs_fmt) {
1294 ERR("Cannot get FB Configs, expect problems.\n");
1295 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1299 if (nCfgs_fmt < fmt_index) {
1300 ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, fmt_index, nCfgs_fmt);
1301 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1305 cur_cfg = cfgs_fmt[fmt_index];
1306 gl_test = pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_FBCONFIG_ID, &value);
1308 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1309 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1314 /* The context will be allocated in the wglMakeCurrent call */
1316 ret = alloc_context();
1317 wine_tsx11_unlock();
1319 ret->display = gdi_display;
1320 ret->fb_conf = cur_cfg;
1322 ret->vis = pglXGetVisualFromFBConfig(gdi_display, cur_cfg);
1324 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1329 * X11DRV_wglDeleteContext
1331 * For OpenGL32 wglDeleteContext.
1333 BOOL X11DRV_wglDeleteContext(HGLRC hglrc)
1335 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1338 TRACE("(%p)\n", hglrc);
1340 if (!has_opengl()) {
1341 ERR("No libGL on this box - disabling OpenGL support !\n");
1346 /* A game (Half Life not to name it) deletes twice the same context,
1347 * so make sure it is valid first */
1348 if (is_valid_context( ctx ))
1350 if (ctx->ctx) pglXDestroyContext(ctx->display, ctx->ctx);
1355 WARN("Error deleting context !\n");
1356 SetLastError(ERROR_INVALID_HANDLE);
1359 wine_tsx11_unlock();
1365 * X11DRV_wglGetCurrentReadDCARB
1367 * For OpenGL32 wglGetCurrentReadDCARB.
1369 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1377 gl_d = pglXGetCurrentReadDrawable();
1378 ret = get_hdc_from_Drawable(gl_d);
1379 wine_tsx11_unlock();
1381 TRACE(" returning %p (GL drawable %lu)\n", ret, gl_d);
1386 * X11DRV_wglGetProcAddress
1388 * For OpenGL32 wglGetProcAddress.
1390 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1393 const WineGLExtension *ext;
1395 int padding = 32 - strlen(lpszProc);
1399 if (!has_opengl()) {
1400 ERR("No libGL on this box - disabling OpenGL support !\n");
1404 /* Check the table of WGL extensions to see if we need to return a WGL extension
1405 * or a function pointer to a native OpenGL function. */
1406 if(strncmp(lpszProc, "wgl", 3) != 0) {
1407 return pglXGetProcAddressARB((GLubyte*)lpszProc);
1409 TRACE("('%s'):%*s", lpszProc, padding, " ");
1410 for (i = 0; i < WineGLExtensionListSize; ++i) {
1411 ext = WineGLExtensionList[i];
1412 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1413 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1414 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1415 return ext->extEntryPoints[j].funcAddress;
1421 ERR("(%s) - not found\n", lpszProc);
1427 * X11DRV_wglMakeCurrent
1429 * For OpenGL32 wglMakeCurrent.
1431 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
1433 HDC hdc = physDev->hdc;
1434 DWORD type = GetObjectType(hdc);
1436 TRACE("(%p,%p)\n", hdc, hglrc);
1438 if (!has_opengl()) {
1439 ERR("No libGL on this box - disabling OpenGL support !\n");
1444 if (hglrc == NULL) {
1445 ret = pglXMakeCurrent(gdi_display, None, NULL);
1446 NtCurrentTeb()->glContext = NULL;
1448 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1449 Drawable drawable = physDev->drawable;
1450 if (ctx->ctx == NULL) {
1451 int draw_vis_id, ctx_vis_id;
1452 VisualID visualid = (VisualID)GetPropA( GetDesktopWindow(), "__wine_x11_visual_id" );
1453 TRACE(" Wine desktop VISUAL_ID is 0x%x\n", (unsigned int) visualid);
1454 draw_vis_id = describeDrawable(ctx, drawable);
1455 ctx_vis_id = describeContext(ctx);
1457 if (-1 == draw_vis_id || (draw_vis_id == visualid && draw_vis_id != ctx_vis_id)) {
1459 * Inherits from root window so reuse desktop visual
1461 XVisualInfo template;
1464 template.visualid = visualid;
1465 vis = XGetVisualInfo(ctx->display, VisualIDMask, &template, &num);
1467 TRACE(" Creating GLX Context\n");
1468 ctx->ctx = pglXCreateContext(ctx->display, vis, NULL, type == OBJ_MEMDC ? False : True);
1470 TRACE(" Creating GLX Context\n");
1471 ctx->ctx = pglXCreateContext(ctx->display, ctx->vis, NULL, type == OBJ_MEMDC ? False : True);
1473 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1475 TRACE(" make current for dis %p, drawable %p, ctx %p\n", ctx->display, (void*) drawable, ctx->ctx);
1476 ret = pglXMakeCurrent(ctx->display, drawable, ctx->ctx);
1477 NtCurrentTeb()->glContext = ctx;
1478 if(ret && type == OBJ_MEMDC)
1480 ctx->do_escape = TRUE;
1481 pglDrawBuffer(GL_FRONT_LEFT);
1484 wine_tsx11_unlock();
1485 TRACE(" returning %s\n", (ret ? "True" : "False"));
1490 * X11DRV_wglMakeContextCurrentARB
1492 * For OpenGL32 wglMakeContextCurrentARB
1494 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc)
1497 TRACE("(%p,%p,%p)\n", hDrawDev, hReadDev, hglrc);
1499 if (!has_opengl()) {
1500 ERR("No libGL on this box - disabling OpenGL support !\n");
1505 if (hglrc == NULL) {
1506 ret = pglXMakeCurrent(gdi_display, None, NULL);
1507 NtCurrentTeb()->glContext = NULL;
1509 if (NULL == pglXMakeContextCurrent) {
1512 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1513 Drawable d_draw = get_glxdrawable(hDrawDev);
1514 Drawable d_read = get_glxdrawable(hReadDev);
1516 if (ctx->ctx == NULL) {
1517 ctx->ctx = pglXCreateContext(ctx->display, ctx->vis, NULL, GetObjectType(hDrawDev->hdc) == OBJ_MEMDC ? False : True);
1518 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1520 ret = pglXMakeContextCurrent(ctx->display, d_draw, d_read, ctx->ctx);
1521 NtCurrentTeb()->glContext = ctx;
1524 wine_tsx11_unlock();
1526 TRACE(" returning %s\n", (ret ? "True" : "False"));
1531 * X11DRV_wglShareLists
1533 * For OpenGL32 wglShaderLists.
1535 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
1536 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1537 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1539 TRACE("(%p, %p)\n", org, dest);
1541 if (!has_opengl()) {
1542 ERR("No libGL on this box - disabling OpenGL support !\n");
1546 if (NULL != dest && dest->ctx != NULL) {
1547 ERR("Could not share display lists, context already created !\n");
1550 if (org->ctx == NULL) {
1552 describeContext(org);
1553 org->ctx = pglXCreateContext(org->display, org->vis, NULL, GetObjectType(org->hdc) == OBJ_MEMDC ? False : True);
1554 wine_tsx11_unlock();
1555 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org->ctx, org);
1559 describeContext(dest);
1560 /* Create the destination context with display lists shared */
1561 dest->ctx = pglXCreateContext(org->display, dest->vis, org->ctx, GetObjectType(org->hdc) == OBJ_MEMDC ? False : True);
1562 wine_tsx11_unlock();
1563 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1570 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
1572 /* We are running using client-side rendering fonts... */
1576 void *bitmap = NULL, *gl_bitmap = NULL;
1580 pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1581 pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1582 wine_tsx11_unlock();
1584 for (glyph = first; glyph < first + count; glyph++) {
1585 unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, NULL);
1586 int height, width_int;
1588 TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
1589 if (needed_size == GDI_ERROR) {
1590 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size);
1593 TRACE(" - needed size : %d\n", needed_size);
1596 if (needed_size > size) {
1598 HeapFree(GetProcessHeap(), 0, bitmap);
1599 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1600 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1601 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1603 if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, NULL) == GDI_ERROR) goto error;
1604 if (TRACE_ON(opengl)) {
1605 unsigned int height, width, bitmask;
1606 unsigned char *bitmap_ = (unsigned char *) bitmap;
1608 TRACE(" - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
1609 TRACE(" - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
1610 TRACE(" - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
1611 if (needed_size != 0) {
1612 TRACE(" - bitmap :\n");
1613 for (height = 0; height < gm.gmBlackBoxY; height++) {
1615 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
1620 if (*bitmap_ & bitmask)
1625 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
1631 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1632 * glyph for it to be drawn properly.
1634 if (needed_size != 0) {
1635 width_int = (gm.gmBlackBoxX + 31) / 32;
1636 for (height = 0; height < gm.gmBlackBoxY; height++) {
1638 for (width = 0; width < width_int; width++) {
1639 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
1640 ((int *) bitmap)[height * width_int + width];
1646 pglNewList(listBase++, GL_COMPILE);
1647 if (needed_size != 0) {
1648 pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
1649 0 - (int) gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - (int) gm.gmptGlyphOrigin.y,
1650 gm.gmCellIncX, gm.gmCellIncY,
1653 /* This is the case of 'empty' glyphs like the space character */
1654 pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
1657 wine_tsx11_unlock();
1661 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1662 wine_tsx11_unlock();
1664 HeapFree(GetProcessHeap(), 0, bitmap);
1665 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1670 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1671 wine_tsx11_unlock();
1673 HeapFree(GetProcessHeap(), 0, bitmap);
1674 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1679 * X11DRV_wglUseFontBitmapsA
1681 * For OpenGL32 wglUseFontBitmapsA.
1683 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1685 Font fid = physDev->font;
1687 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1689 if (!has_opengl()) {
1690 ERR("No libGL on this box - disabling OpenGL support !\n");
1695 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineA);
1699 /* I assume that the glyphs are at the same position for X and for Windows */
1700 pglXUseXFont(fid, first, count, listBase);
1701 wine_tsx11_unlock();
1706 * X11DRV_wglUseFontBitmapsW
1708 * For OpenGL32 wglUseFontBitmapsW.
1710 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1712 Font fid = physDev->font;
1714 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1716 if (!has_opengl()) {
1717 ERR("No libGL on this box - disabling OpenGL support !\n");
1722 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineW);
1725 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1728 /* I assume that the glyphs are at the same position for X and for Windows */
1729 pglXUseXFont(fid, first, count, listBase);
1730 wine_tsx11_unlock();
1734 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1735 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params) {
1736 TRACE("pname: 0x%x, params: %p\n", pname, params);
1737 if (pname == GL_DEPTH_BITS) {
1738 GLXContext gl_ctx = pglXGetCurrentContext();
1739 Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx);
1740 /*TRACE("returns Wine Ctx as %p\n", ret);*/
1742 * if we cannot find a Wine Context
1743 * we only have the default wine desktop context,
1744 * so if we have only a 24 depth say we have 32
1746 if (NULL == ret && 24 == *params) {
1749 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
1751 if (pname == GL_ALPHA_BITS) {
1753 GLXContext gl_ctx = pglXGetCurrentContext();
1754 Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx);
1755 pglXGetFBConfigAttrib(ret->display, ret->fb_conf, GLX_ALPHA_SIZE, &tmp);
1756 TRACE("returns GL_ALPHA_BITS as '%d'\n", tmp);
1762 * X11DRV_wglGetExtensionsStringARB
1764 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
1766 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
1767 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
1768 return WineGLInfo.wglExtensions;
1772 * X11DRV_wglCreatePbufferARB
1774 * WGL_ARB_pbuffer: wglCreatePbufferARB
1776 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
1778 Wine_GLPBuffer* object = NULL;
1779 GLXFBConfig* cfgs = NULL;
1782 unsigned nAttribs = 0;
1785 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
1787 if (0 >= iPixelFormat) {
1788 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
1789 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1790 return NULL; /* unexpected error */
1793 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
1795 if (NULL == cfgs || 0 == nCfgs) {
1796 ERR("(%p): Cannot get FB Configs for iPixelFormat(%d), returns NULL\n", hdc, iPixelFormat);
1797 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1798 return NULL; /* unexpected error */
1801 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
1802 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &nCfgs)) {
1803 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
1804 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1805 goto create_failed; /* unexpected error */
1808 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
1809 if (NULL == object) {
1810 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
1811 goto create_failed; /* unexpected error */
1814 object->display = gdi_display;
1815 object->width = iWidth;
1816 object->height = iHeight;
1818 nAttribs = ConvertAttribWGLtoGLX(piAttribList, attribs, object);
1819 if (-1 == nAttribs) {
1820 WARN("Cannot convert WGL to GLX attributes\n");
1823 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
1824 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
1825 while (0 != *piAttribList) {
1827 switch (*piAttribList) {
1828 case WGL_TEXTURE_FORMAT_ARB: {
1830 attr_v = *piAttribList;
1831 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
1832 if (use_render_texture_ati) {
1835 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
1836 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
1837 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
1839 SetLastError(ERROR_INVALID_DATA);
1842 object->use_render_texture = 1;
1843 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
1845 if (WGL_NO_TEXTURE_ARB == attr_v) {
1846 object->use_render_texture = 0;
1848 if (!use_render_texture_emulation) {
1849 SetLastError(ERROR_INVALID_DATA);
1853 case WGL_TEXTURE_RGB_ARB:
1854 object->use_render_texture = GL_RGB;
1856 case WGL_TEXTURE_RGBA_ARB:
1857 object->use_render_texture = GL_RGBA;
1860 SetLastError(ERROR_INVALID_DATA);
1868 case WGL_TEXTURE_TARGET_ARB: {
1870 attr_v = *piAttribList;
1871 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
1872 if (use_render_texture_ati) {
1875 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
1876 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
1877 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
1878 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
1880 SetLastError(ERROR_INVALID_DATA);
1883 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
1885 if (WGL_NO_TEXTURE_ARB == attr_v) {
1886 object->texture_target = 0;
1888 if (!use_render_texture_emulation) {
1889 SetLastError(ERROR_INVALID_DATA);
1893 case WGL_TEXTURE_CUBE_MAP_ARB: {
1894 if (iWidth != iHeight) {
1895 SetLastError(ERROR_INVALID_DATA);
1898 object->texture_target = GL_TEXTURE_CUBE_MAP;
1899 object->texture_bind_target = GL_TEXTURE_CUBE_MAP;
1902 case WGL_TEXTURE_1D_ARB: {
1904 SetLastError(ERROR_INVALID_DATA);
1907 object->texture_target = GL_TEXTURE_1D;
1908 object->texture_bind_target = GL_TEXTURE_1D;
1911 case WGL_TEXTURE_2D_ARB: {
1912 object->texture_target = GL_TEXTURE_2D;
1913 object->texture_bind_target = GL_TEXTURE_2D;
1917 SetLastError(ERROR_INVALID_DATA);
1925 case WGL_MIPMAP_TEXTURE_ARB: {
1927 attr_v = *piAttribList;
1928 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
1929 if (use_render_texture_ati) {
1930 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
1932 if (!use_render_texture_emulation) {
1933 SetLastError(ERROR_INVALID_DATA);
1943 PUSH1(attribs, None);
1944 object->drawable = pglXCreatePbuffer(gdi_display, cfgs[fmt_index], attribs);
1945 TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
1946 if (!object->drawable) {
1947 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
1948 goto create_failed; /* unexpected error */
1950 TRACE("->(%p)\n", object);
1954 return (HPBUFFERARB) object;
1957 if (NULL != cfgs) XFree(cfgs);
1958 HeapFree(GetProcessHeap(), 0, object);
1959 TRACE("->(FAILED)\n");
1960 return (HPBUFFERARB) NULL;
1964 * X11DRV_wglDestroyPbufferARB
1966 * WGL_ARB_pbuffer: wglDestroyPbufferARB
1968 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
1970 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
1971 TRACE("(%p)\n", hPbuffer);
1972 if (NULL == object) {
1973 SetLastError(ERROR_INVALID_HANDLE);
1976 pglXDestroyPbuffer(object->display, object->drawable);
1977 HeapFree(GetProcessHeap(), 0, object);
1982 * X11DRV_wglGetPbufferDCARB
1984 * WGL_ARB_pbuffer: wglGetPbufferDCARB
1985 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
1986 * Gdi32 implements the part of this function which creates a device context.
1987 * This part associates the physDev with the X drawable of the pbuffer.
1989 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
1991 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
1992 if (NULL == object) {
1993 SetLastError(ERROR_INVALID_HANDLE);
1997 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
1998 * We only support one onscreen rendering format (the one from the main visual), so use that. */
1999 physDev->current_pf = 1;
2000 physDev->drawable = object->drawable;
2002 TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);
2003 return physDev->hdc;
2007 * X11DRV_wglQueryPbufferARB
2009 * WGL_ARB_pbuffer: wglQueryPbufferARB
2011 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2013 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2014 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2015 if (NULL == object) {
2016 SetLastError(ERROR_INVALID_HANDLE);
2019 switch (iAttribute) {
2020 case WGL_PBUFFER_WIDTH_ARB:
2021 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2023 case WGL_PBUFFER_HEIGHT_ARB:
2024 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2027 case WGL_PBUFFER_LOST_ARB:
2028 FIXME("unsupported WGL_PBUFFER_LOST_ARB (need glXSelectEvent/GLX_DAMAGED work)\n");
2031 case WGL_TEXTURE_FORMAT_ARB:
2032 if (use_render_texture_ati) {
2034 int type = WGL_NO_TEXTURE_ARB;
2035 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2037 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2038 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2039 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2043 if (!object->use_render_texture) {
2044 *piValue = WGL_NO_TEXTURE_ARB;
2046 if (!use_render_texture_emulation) {
2047 SetLastError(ERROR_INVALID_HANDLE);
2050 if (GL_RGBA == object->use_render_texture) {
2051 *piValue = WGL_TEXTURE_RGBA_ARB;
2053 *piValue = WGL_TEXTURE_RGB_ARB;
2059 case WGL_TEXTURE_TARGET_ARB:
2060 if (use_render_texture_ati) {
2062 int type = WGL_NO_TEXTURE_ARB;
2063 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2065 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2066 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2067 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2068 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2072 if (!object->texture_target) {
2073 *piValue = WGL_NO_TEXTURE_ARB;
2075 if (!use_render_texture_emulation) {
2076 SetLastError(ERROR_INVALID_DATA);
2079 switch (object->texture_target) {
2080 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2081 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_1D_ARB; break;
2082 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_2D_ARB; break;
2088 case WGL_MIPMAP_TEXTURE_ARB:
2089 if (use_render_texture_ati) {
2090 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2092 *piValue = GL_FALSE; /** don't support that */
2093 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2098 FIXME("unexpected attribute %x\n", iAttribute);
2106 * X11DRV_wglReleasePbufferDCARB
2108 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2110 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2112 TRACE("(%p, %p)\n", hPbuffer, hdc);
2118 * X11DRV_wglSetPbufferAttribARB
2120 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2122 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2124 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2125 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2126 if (NULL == object) {
2127 SetLastError(ERROR_INVALID_HANDLE);
2130 if (!object->use_render_texture) {
2131 SetLastError(ERROR_INVALID_HANDLE);
2134 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2137 if (NULL != pglXDrawableAttribARB) {
2138 if (use_render_texture_ati) {
2139 FIXME("Need conversion for GLX_ATI_render_texture\n");
2141 return pglXDrawableAttribARB(object->display, object->drawable, piAttribList);
2147 * X11DRV_wglChoosePixelFormatARB
2149 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2151 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2156 GLXFBConfig* cfgs = NULL;
2161 GLXFBConfig* cfgs_fmt = NULL;
2167 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2168 if (NULL != pfAttribFList) {
2169 FIXME("unused pfAttribFList\n");
2172 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2173 if (-1 == nAttribs) {
2174 WARN("Cannot convert WGL to GLX attributes\n");
2177 PUSH1(attribs, None);
2179 /* Search for FB configurations matching the requirements in attribs */
2180 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2182 WARN("Compatible Pixel Format not found\n");
2186 /* Get a list of all FB configurations */
2187 cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
2188 if (NULL == cfgs_fmt) {
2189 ERR("Failed to get All FB Configs\n");
2194 /* Loop through all matching formats and check if they are suitable.
2195 * Note that this function should at max return nMaxFormats different formats */
2196 for (it = 0; pfmt_it < nMaxFormats && it < nCfgs; ++it) {
2197 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2199 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2203 /* Search for the format in our list of compatible formats */
2204 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id);
2208 piFormats[pfmt_it] = fmt;
2209 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d/%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it], nCfgs_fmt);
2213 *nNumFormats = pfmt_it;
2221 * X11DRV_wglGetPixelFormatAttribfvARB
2223 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2225 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
2227 FIXME("(%p, %d, %d, %d, %p, %p): stub\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2232 * X11DRV_wglGetPixelFormatAttribivARB
2234 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2236 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2239 GLXFBConfig* cfgs = NULL;
2240 GLXFBConfig curCfg = NULL;
2245 int nWGLFormats = 0;
2248 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2250 if (0 < iLayerPlane) {
2251 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2255 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
2257 ERR("no FB Configs found for display(%p)\n", gdi_display);
2261 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2262 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2263 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2264 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &nWGLFormats)) {
2265 ERR("Unable to convert iPixelFormat %d to a GLX one, expect problems!\n", iPixelFormat);
2268 for (i = 0; i < nAttributes; ++i) {
2269 const int curWGLAttr = piAttributes[i];
2270 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2272 switch (curWGLAttr) {
2273 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2274 piValues[i] = nWGLFormats;
2277 case WGL_SUPPORT_OPENGL_ARB:
2278 piValues[i] = GL_TRUE;
2281 case WGL_ACCELERATION_ARB:
2282 curGLXAttr = GLX_CONFIG_CAVEAT;
2284 if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
2285 curCfg = cfgs[iPixelFormat - 1];
2287 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2288 if (hTest) goto get_error;
2290 case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2291 case GLX_SLOW_CONFIG: piValues[i] = WGL_NO_ACCELERATION_ARB; break;
2292 case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2294 ERR("unexpected Config Caveat(%x)\n", tmp);
2295 piValues[i] = WGL_NO_ACCELERATION_ARB;
2299 case WGL_TRANSPARENT_ARB:
2300 curGLXAttr = GLX_TRANSPARENT_TYPE;
2301 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2302 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2303 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2304 curCfg = cfgs[fmt_index];
2305 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2306 if (hTest) goto get_error;
2307 piValues[i] = GL_FALSE;
2308 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2311 case WGL_PIXEL_TYPE_ARB:
2312 curGLXAttr = GLX_RENDER_TYPE;
2313 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2314 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2315 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2316 curCfg = cfgs[fmt_index];
2317 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2318 if (hTest) goto get_error;
2319 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2320 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2321 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2322 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2323 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2325 ERR("unexpected RenderType(%x)\n", tmp);
2326 piValues[i] = WGL_TYPE_RGBA_ARB;
2330 case WGL_COLOR_BITS_ARB:
2331 /** see ConvertAttribWGLtoGLX for explain */
2332 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2333 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2334 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2335 curCfg = cfgs[fmt_index];
2336 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_BUFFER_SIZE, piValues + i);
2337 if (hTest) goto get_error;
2338 TRACE("WGL_COLOR_BITS_ARB: GLX_BUFFER_SIZE = %d\n", piValues[i]);
2339 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_ALPHA_SIZE, &tmp);
2340 if (hTest) goto get_error;
2341 TRACE("WGL_COLOR_BITS_ARB: GLX_ALPHA_SIZE = %d\n", tmp);
2342 piValues[i] = piValues[i] - tmp;
2345 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2346 if (use_render_texture_ati) {
2347 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
2350 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2351 if (use_render_texture_ati) {
2352 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
2355 if (!use_render_texture_emulation) {
2356 piValues[i] = GL_FALSE;
2359 curGLXAttr = GLX_RENDER_TYPE;
2360 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2361 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2362 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2363 curCfg = cfgs[fmt_index];
2364 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2365 if (hTest) goto get_error;
2366 if (GLX_COLOR_INDEX_BIT == tmp) {
2367 piValues[i] = GL_FALSE;
2370 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_DRAWABLE_TYPE, &tmp);
2371 if (hTest) goto get_error;
2372 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2375 case WGL_BLUE_BITS_ARB:
2376 curGLXAttr = GLX_BLUE_SIZE;
2378 case WGL_RED_BITS_ARB:
2379 curGLXAttr = GLX_RED_SIZE;
2381 case WGL_GREEN_BITS_ARB:
2382 curGLXAttr = GLX_GREEN_SIZE;
2384 case WGL_ALPHA_BITS_ARB:
2385 curGLXAttr = GLX_ALPHA_SIZE;
2387 case WGL_DEPTH_BITS_ARB:
2388 curGLXAttr = GLX_DEPTH_SIZE;
2390 case WGL_STENCIL_BITS_ARB:
2391 curGLXAttr = GLX_STENCIL_SIZE;
2393 case WGL_DOUBLE_BUFFER_ARB:
2394 curGLXAttr = GLX_DOUBLEBUFFER;
2396 case WGL_STEREO_ARB:
2397 curGLXAttr = GLX_STEREO;
2399 case WGL_AUX_BUFFERS_ARB:
2400 curGLXAttr = GLX_AUX_BUFFERS;
2403 case WGL_SUPPORT_GDI_ARB:
2404 case WGL_DRAW_TO_WINDOW_ARB:
2405 case WGL_DRAW_TO_BITMAP_ARB:
2406 case WGL_DRAW_TO_PBUFFER_ARB:
2407 curGLXAttr = GLX_X_RENDERABLE;
2410 case WGL_PBUFFER_LARGEST_ARB:
2411 curGLXAttr = GLX_LARGEST_PBUFFER;
2414 case WGL_SAMPLE_BUFFERS_ARB:
2415 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2418 case WGL_SAMPLES_ARB:
2419 curGLXAttr = GLX_SAMPLES_ARB;
2423 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2426 if (0 != curGLXAttr) {
2427 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2428 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2429 if((iPixelFormat > 0) && ((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs))) goto pix_error;
2430 curCfg = cfgs[fmt_index];
2431 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, piValues + i);
2432 if (hTest) goto get_error;
2434 piValues[i] = GL_FALSE;
2440 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2445 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nCfgs);
2451 * X11DRV_wglBindTexImageARB
2453 * WGL_ARB_render_texture: wglBindTexImageARB
2455 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2457 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2458 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2459 if (NULL == object) {
2460 SetLastError(ERROR_INVALID_HANDLE);
2463 if (!object->use_render_texture) {
2464 SetLastError(ERROR_INVALID_HANDLE);
2467 /* Disable WGL_ARB_render_texture support until it is implemented properly
2468 * using pbuffers or FBOs */
2470 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2472 GLint prev_binded_tex;
2473 pglGetIntegerv(object->texture_target, &prev_binded_tex);
2474 if (NULL == object->render_ctx) {
2475 object->render_hdc = X11DRV_wglGetPbufferDCARB(hPbuffer);
2476 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2477 object->render_ctx = wglCreateContext(object->render_hdc);
2480 object->prev_hdc = wglGetCurrentDC();
2481 object->prev_ctx = wglGetCurrentContext();
2482 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2483 wglMakeCurrent(object->render_hdc, object->render_ctx);
2486 glBindTexture(object->texture_target, object->texture);
2487 if (GL_RGBA == object->use_render_texture) {
2488 glTexImage2D(object->texture_target, 0, GL_RGBA8, object->width, object->height, 0, GL_RGBA, GL_FLOAT, NULL);
2490 glTexImage2D(object->texture_target, 0, GL_RGB8, object->width, object->height, 0, GL_RGB, GL_FLOAT, NULL);
2494 object->texture = prev_binded_tex;
2498 if (NULL != pglXBindTexImageARB) {
2499 return pglXBindTexImageARB(object->display, object->drawable, iBuffer);
2505 * X11DRV_wglReleaseTexImageARB
2507 * WGL_ARB_render_texture: wglReleaseTexImageARB
2509 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2511 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2512 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2513 if (NULL == object) {
2514 SetLastError(ERROR_INVALID_HANDLE);
2517 if (!object->use_render_texture) {
2518 SetLastError(ERROR_INVALID_HANDLE);
2521 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2523 GLint prev_binded_tex;
2524 glGetIntegerv(object->texture_target, &prev_binded_tex);
2525 if (GL_TEXTURE_1D == object->texture_target) {
2526 glCopyTexSubImage1D(object->texture_target, object->texture_level, 0, 0, 0, object->width);
2528 glCopyTexSubImage2D(object->texture_target, object->texture_level, 0, 0, 0, 0, object->width, object->height);
2530 glBindTexture(object->texture_target, prev_binded_tex);
2531 SwapBuffers(object->render_hdc);
2533 pglBindTexture(object->texture_target, object->texture);
2534 if (GL_TEXTURE_1D == object->texture_target) {
2535 pglCopyTexSubImage1D(object->texture_target, object->texture_level, 0, 0, 0, object->width);
2537 pglCopyTexSubImage2D(object->texture_target, object->texture_level, 0, 0, 0, 0, object->width, object->height);
2540 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2541 wglMakeCurrent(object->prev_hdc, object->prev_ctx);
2544 if (NULL != pglXReleaseTexImageARB) {
2545 return pglXReleaseTexImageARB(object->display, object->drawable, iBuffer);
2551 * X11DRV_wglGetExtensionsStringEXT
2553 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2555 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
2556 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2557 return WineGLInfo.wglExtensions;
2561 * X11DRV_wglGetSwapIntervalEXT
2563 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2565 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
2566 FIXME("(),stub!\n");
2567 return swap_interval;
2571 * X11DRV_wglSwapIntervalEXT
2573 * WGL_EXT_swap_control: wglSwapIntervalEXT
2575 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
2576 TRACE("(%d)\n", interval);
2577 swap_interval = interval;
2578 if (NULL != pglXSwapIntervalSGI) {
2579 return 0 == pglXSwapIntervalSGI(interval);
2581 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
2586 * glxRequireVersion (internal)
2588 * Check if the supported GLX version matches requiredVersion.
2590 static BOOL glxRequireVersion(int requiredVersion)
2592 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2593 if(requiredVersion <= WineGLInfo.glxVersion[1])
2599 static BOOL glxRequireExtension(const char *requiredExtension)
2601 if (strstr(WineGLInfo.glxClientExtensions, requiredExtension) == NULL) {
2608 static BOOL register_extension(const WineGLExtension * ext)
2612 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
2613 WineGLExtensionList[WineGLExtensionListSize++] = ext;
2615 strcat(WineGLInfo.wglExtensions, " ");
2616 strcat(WineGLInfo.wglExtensions, ext->extName);
2618 TRACE("'%s'\n", ext->extName);
2620 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
2621 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
2626 static const WineGLExtension WGL_internal_functions =
2630 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
2635 static const WineGLExtension WGL_ARB_extensions_string =
2637 "WGL_ARB_extensions_string",
2639 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
2643 static const WineGLExtension WGL_ARB_make_current_read =
2645 "WGL_ARB_make_current_read",
2647 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
2648 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
2652 static const WineGLExtension WGL_ARB_multisample =
2654 "WGL_ARB_multisample",
2657 static const WineGLExtension WGL_ARB_pbuffer =
2661 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
2662 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
2663 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
2664 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
2665 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
2666 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
2670 static const WineGLExtension WGL_ARB_pixel_format =
2672 "WGL_ARB_pixel_format",
2674 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
2675 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
2676 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
2680 static const WineGLExtension WGL_ARB_render_texture =
2682 "WGL_ARB_render_texture",
2684 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
2685 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
2689 static const WineGLExtension WGL_EXT_extensions_string =
2691 "WGL_EXT_extensions_string",
2693 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
2697 static const WineGLExtension WGL_EXT_swap_control =
2699 "WGL_EXT_swap_control",
2701 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
2702 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
2708 * X11DRV_WineGL_LoadExtensions
2710 static void X11DRV_WineGL_LoadExtensions(void)
2712 WineGLInfo.wglExtensions[0] = 0;
2714 /* Load Wine internal functions */
2715 register_extension(&WGL_internal_functions);
2717 /* ARB Extensions */
2719 register_extension(&WGL_ARB_extensions_string);
2721 if (glxRequireVersion(3))
2722 register_extension(&WGL_ARB_make_current_read);
2724 if (glxRequireExtension("GLX_ARB_multisample"))
2725 register_extension(&WGL_ARB_multisample);
2727 if (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer"))
2728 register_extension(&WGL_ARB_pbuffer);
2730 register_extension(&WGL_ARB_pixel_format);
2732 if (glxRequireExtension("GLX_ATI_render_texture") ||
2733 glxRequireExtension("GLX_ARB_render_texture"))
2734 register_extension(&WGL_ARB_render_texture);
2736 /* EXT Extensions */
2738 register_extension(&WGL_EXT_extensions_string);
2740 if (glxRequireExtension("GLX_SGI_swap_control"))
2741 register_extension(&WGL_EXT_swap_control);
2745 static XID create_glxpixmap(X11DRV_PDEVICE *physDev)
2749 XVisualInfo template;
2754 /* Retrieve the visualid from our main visual which is the only visual we can use */
2755 template.visualid = XVisualIDFromVisual(visual);
2756 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
2758 ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
2760 wine_tsx11_unlock();
2761 TRACE("return %lx\n", ret);
2765 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
2771 if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
2772 ret = physDev->drawable; /* PBuffer */
2775 if(!physDev->bitmap->glxpixmap)
2776 physDev->bitmap->glxpixmap = create_glxpixmap(physDev);
2777 ret = physDev->bitmap->glxpixmap;
2781 ret = physDev->drawable;
2785 BOOL destroy_glxpixmap(XID glxpixmap)
2788 pglXDestroyGLXPixmap(gdi_display, glxpixmap);
2789 wine_tsx11_unlock();
2794 * X11DRV_SwapBuffers
2796 * Swap the buffers of this DC
2798 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev)
2800 GLXDrawable drawable;
2801 if (!has_opengl()) {
2802 ERR("No libGL on this box - disabling OpenGL support !\n");
2806 TRACE_(opengl)("(%p)\n", physDev);
2808 drawable = get_glxdrawable(physDev);
2810 pglXSwapBuffers(gdi_display, drawable);
2811 wine_tsx11_unlock();
2816 static long prev_time, frames;
2818 DWORD time = GetTickCount();
2820 /* every 1.5 seconds */
2821 if (time - prev_time > 1500) {
2822 TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
2831 /***********************************************************************
2832 * X11DRV_setup_opengl_visual
2834 * Setup the default visual used for OpenGL and Direct3D, and the desktop
2835 * window (if it exists). If OpenGL isn't available, the visual is simply
2836 * set to the default visual for the display
2838 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
2840 XVisualInfo *visual = NULL;
2841 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support, */
2842 int dblBuf[] = {GLX_RGBA,GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DOUBLEBUFFER, None};
2843 if (!has_opengl()) return NULL;
2846 visual = pglXChooseVisual(display, DefaultScreen(display), dblBuf);
2847 wine_tsx11_unlock();
2848 if (visual == NULL) {
2849 /* fallback to 16 bits depth, no alpha */
2850 int dblBuf2[] = {GLX_RGBA,GLX_DEPTH_SIZE, 16, GLX_STENCIL_SIZE, 8, GLX_DOUBLEBUFFER, None};
2851 WARN("Failed to get a visual with at least 24 bits depth\n");
2854 visual = pglXChooseVisual(display, DefaultScreen(display), dblBuf2);
2855 wine_tsx11_unlock();
2856 if (visual == NULL) {
2857 /* fallback to no stencil */
2858 int dblBuf2[] = {GLX_RGBA,GLX_DEPTH_SIZE, 16, GLX_DOUBLEBUFFER, None};
2859 WARN("Failed to get a visual with at least 8 bits of stencil\n");
2862 visual = pglXChooseVisual(display, DefaultScreen(display), dblBuf2);
2863 wine_tsx11_unlock();
2864 if (visual == NULL) {
2865 /* This should only happen if we cannot find a match with a depth size 16 */
2866 FIXME("Failed to find a suitable visual\n");
2871 TRACE("Visual ID %lx Chosen\n",visual->visualid);
2875 #else /* no OpenGL includes */
2877 /***********************************************************************
2878 * ChoosePixelFormat (X11DRV.@)
2880 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
2881 const PIXELFORMATDESCRIPTOR *ppfd) {
2882 ERR("No OpenGL support compiled in.\n");
2887 /***********************************************************************
2888 * DescribePixelFormat (X11DRV.@)
2890 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
2893 PIXELFORMATDESCRIPTOR *ppfd) {
2894 ERR("No OpenGL support compiled in.\n");
2899 /***********************************************************************
2900 * GetPixelFormat (X11DRV.@)
2902 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
2903 ERR("No OpenGL support compiled in.\n");
2908 /***********************************************************************
2909 * SetPixelFormat (X11DRV.@)
2911 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
2913 const PIXELFORMATDESCRIPTOR *ppfd) {
2914 ERR("No OpenGL support compiled in.\n");
2919 /***********************************************************************
2920 * SwapBuffers (X11DRV.@)
2922 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
2923 ERR_(opengl)("No OpenGL support compiled in.\n");
2929 * X11DRV_wglCreateContext
2931 * For OpenGL32 wglCreateContext.
2933 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) {
2934 ERR_(opengl)("No OpenGL support compiled in.\n");
2939 * X11DRV_wglDeleteContext
2941 * For OpenGL32 wglDeleteContext.
2943 BOOL X11DRV_wglDeleteContext(HGLRC hglrc) {
2944 ERR_(opengl)("No OpenGL support compiled in.\n");
2949 * X11DRV_wglGetProcAddress
2951 * For OpenGL32 wglGetProcAddress.
2953 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
2954 ERR_(opengl)("No OpenGL support compiled in.\n");
2958 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *hDevice, void *hPbuffer)
2960 ERR_(opengl)("No OpenGL support compiled in.\n");
2964 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) {
2965 ERR_(opengl)("No OpenGL support compiled in.\n");
2970 * X11DRV_wglMakeCurrent
2972 * For OpenGL32 wglMakeCurrent.
2974 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
2975 ERR_(opengl)("No OpenGL support compiled in.\n");
2980 * X11DRV_wglShareLists
2982 * For OpenGL32 wglShaderLists.
2984 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
2985 ERR_(opengl)("No OpenGL support compiled in.\n");
2990 * X11DRV_wglUseFontBitmapsA
2992 * For OpenGL32 wglUseFontBitmapsA.
2994 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
2996 ERR_(opengl)("No OpenGL support compiled in.\n");
3001 * X11DRV_wglUseFontBitmapsW
3003 * For OpenGL32 wglUseFontBitmapsW.
3005 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3007 ERR_(opengl)("No OpenGL support compiled in.\n");
3011 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
3016 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3021 BOOL destroy_glxpixmap(XID glxpixmap)
3026 #endif /* defined(HAVE_OPENGL) */