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);
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 {
76 X11DRV_PDEVICE *physDev;
80 struct wine_glcontext *next;
81 struct wine_glcontext *prev;
84 typedef struct wine_glpbuffer {
93 int use_render_texture;
94 GLuint texture_target;
95 GLuint texture_bind_target;
104 typedef struct wine_glextension {
107 const char *funcName;
113 const char *glVersion;
114 const char *glExtensions;
118 const char *glxServerVersion;
119 const char *glxServerExtensions;
121 const char *glxClientVersion;
122 const char *glxClientExtensions;
124 const char *glxExtensions;
127 char wglExtensions[4096];
130 typedef struct wine_glpixelformat {
132 GLXFBConfig fbconfig;
137 static Wine_GLContext *context_list;
138 static struct WineGLInfo WineGLInfo = { 0 };
139 static int use_render_texture_emulation = 1;
140 static int use_render_texture_ati = 0;
141 static int swap_interval = 1;
143 #define MAX_EXTENSIONS 16
144 static const WineGLExtension *WineGLExtensionList[MAX_EXTENSIONS];
145 static int WineGLExtensionListSize;
147 static WineGLPixelFormat *WineGLPixelFormatList;
148 static int WineGLPixelFormatListSize = 0;
150 static void X11DRV_WineGL_LoadExtensions(void);
152 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
153 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
154 TRACE(" - dwFlags : ");
155 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
156 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
157 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
158 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
159 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
160 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
161 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
162 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
163 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
164 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
165 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
166 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
167 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
168 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
169 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
170 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
171 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
175 TRACE(" - iPixelType : ");
176 switch (ppfd->iPixelType) {
177 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
178 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
182 TRACE(" - Color : %d\n", ppfd->cColorBits);
183 TRACE(" - Red : %d\n", ppfd->cRedBits);
184 TRACE(" - Green : %d\n", ppfd->cGreenBits);
185 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
186 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
187 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
188 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
189 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
190 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
192 TRACE(" - iLayerType : ");
193 switch (ppfd->iLayerType) {
194 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
195 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
196 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
201 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
202 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
204 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
206 MAKE_FUNCPTR(glXChooseVisual)
207 MAKE_FUNCPTR(glXCreateContext)
208 MAKE_FUNCPTR(glXCreateGLXPixmap)
209 MAKE_FUNCPTR(glXGetCurrentContext)
210 MAKE_FUNCPTR(glXGetCurrentDrawable)
211 MAKE_FUNCPTR(glXDestroyContext)
212 MAKE_FUNCPTR(glXDestroyGLXPixmap)
213 MAKE_FUNCPTR(glXGetConfig)
214 MAKE_FUNCPTR(glXIsDirect)
215 MAKE_FUNCPTR(glXMakeCurrent)
216 MAKE_FUNCPTR(glXSwapBuffers)
217 MAKE_FUNCPTR(glXQueryExtension)
218 MAKE_FUNCPTR(glXQueryVersion)
219 MAKE_FUNCPTR(glXUseXFont)
222 MAKE_FUNCPTR(glXGetClientString)
223 MAKE_FUNCPTR(glXQueryExtensionsString)
224 MAKE_FUNCPTR(glXQueryServerString)
227 MAKE_FUNCPTR(glXGetFBConfigs)
228 MAKE_FUNCPTR(glXChooseFBConfig)
229 MAKE_FUNCPTR(glXCreatePbuffer)
230 MAKE_FUNCPTR(glXCreateNewContext)
231 MAKE_FUNCPTR(glXDestroyPbuffer)
232 MAKE_FUNCPTR(glXGetFBConfigAttrib)
233 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
234 MAKE_FUNCPTR(glXMakeContextCurrent)
235 MAKE_FUNCPTR(glXQueryDrawable)
236 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
239 static void* (*pglXGetProcAddressARB)(const GLubyte *);
240 static BOOL (*pglXBindTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
241 static BOOL (*pglXReleaseTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
242 static BOOL (*pglXDrawableAttribARB)(Display *dpy, GLXDrawable draw, const int *attribList);
243 static int (*pglXSwapIntervalSGI)(int);
245 /* NV GLX Extension */
246 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
247 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
249 /* Standard OpenGL */
250 MAKE_FUNCPTR(glBindTexture)
251 MAKE_FUNCPTR(glBitmap)
252 MAKE_FUNCPTR(glCopyTexSubImage1D)
253 MAKE_FUNCPTR(glCopyTexSubImage2D)
254 MAKE_FUNCPTR(glDisable)
255 MAKE_FUNCPTR(glDrawBuffer)
256 MAKE_FUNCPTR(glEnable)
257 MAKE_FUNCPTR(glEndList)
258 MAKE_FUNCPTR(glGetError)
259 MAKE_FUNCPTR(glGetIntegerv)
260 MAKE_FUNCPTR(glGetString)
261 MAKE_FUNCPTR(glIsEnabled)
262 MAKE_FUNCPTR(glNewList)
263 MAKE_FUNCPTR(glPixelStorei)
264 MAKE_FUNCPTR(glReadPixels)
265 MAKE_FUNCPTR(glScissor)
266 MAKE_FUNCPTR(glTexImage2D)
267 MAKE_FUNCPTR(glViewport)
270 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
272 static BOOL infoInitialized = FALSE;
274 int screen = DefaultScreen(gdi_display);
275 Window win = RootWindow(gdi_display, screen);
277 XVisualInfo template;
280 GLXContext ctx = NULL;
284 infoInitialized = TRUE;
288 visual = DefaultVisual(gdi_display, screen);
289 template.visualid = XVisualIDFromVisual(visual);
290 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
292 WORD old_fs = wine_get_fs();
293 /* Create a GLX Context. Without one we can't query GL information */
294 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
295 if (wine_get_fs() != old_fs)
297 wine_set_fs( old_fs );
299 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
300 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
306 pglXMakeCurrent(gdi_display, win, ctx);
308 ERR(" couldn't initialize OpenGL, expect problems\n");
313 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
314 WineGLInfo.glExtensions = strdup((const char *) pglGetString(GL_EXTENSIONS));
316 /* Get the common GLX version supported by GLX client and server ( major/minor) */
317 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
319 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
320 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
322 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
323 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
325 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
326 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
328 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
329 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
330 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
331 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
332 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
336 pglXMakeCurrent(gdi_display, None, NULL);
337 pglXDestroyContext(gdi_display, ctx);
343 static BOOL has_opengl(void)
345 static int init_done;
346 static void *opengl_handle;
347 const char *glx_extensions;
349 int error_base, event_base;
351 if (init_done) return (opengl_handle != NULL);
354 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
355 and include all dependencies */
356 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, NULL, 0);
357 if (opengl_handle == NULL) return FALSE;
359 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
360 if (pglXGetProcAddressARB == NULL) {
361 ERR("could not find glXGetProcAddressARB in libGL.\n");
365 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
367 LOAD_FUNCPTR(glXChooseVisual)
368 LOAD_FUNCPTR(glXCreateContext)
369 LOAD_FUNCPTR(glXCreateGLXPixmap)
370 LOAD_FUNCPTR(glXGetCurrentContext)
371 LOAD_FUNCPTR(glXGetCurrentDrawable)
372 LOAD_FUNCPTR(glXDestroyContext)
373 LOAD_FUNCPTR(glXDestroyGLXPixmap)
374 LOAD_FUNCPTR(glXGetConfig)
375 LOAD_FUNCPTR(glXIsDirect)
376 LOAD_FUNCPTR(glXMakeCurrent)
377 LOAD_FUNCPTR(glXSwapBuffers)
378 LOAD_FUNCPTR(glXQueryExtension)
379 LOAD_FUNCPTR(glXQueryVersion)
380 LOAD_FUNCPTR(glXUseXFont)
383 LOAD_FUNCPTR(glXGetClientString)
384 LOAD_FUNCPTR(glXQueryExtensionsString)
385 LOAD_FUNCPTR(glXQueryServerString)
388 LOAD_FUNCPTR(glXCreatePbuffer)
389 LOAD_FUNCPTR(glXCreateNewContext)
390 LOAD_FUNCPTR(glXDestroyPbuffer)
391 LOAD_FUNCPTR(glXMakeContextCurrent)
392 LOAD_FUNCPTR(glXGetCurrentReadDrawable)
393 LOAD_FUNCPTR(glXGetFBConfigs)
395 /* Standard OpenGL calls */
396 LOAD_FUNCPTR(glBindTexture)
397 LOAD_FUNCPTR(glBitmap)
398 LOAD_FUNCPTR(glCopyTexSubImage1D)
399 LOAD_FUNCPTR(glCopyTexSubImage2D)
400 LOAD_FUNCPTR(glDisable)
401 LOAD_FUNCPTR(glDrawBuffer)
402 LOAD_FUNCPTR(glEnable)
403 LOAD_FUNCPTR(glEndList)
404 LOAD_FUNCPTR(glGetError)
405 LOAD_FUNCPTR(glGetIntegerv)
406 LOAD_FUNCPTR(glGetString)
407 LOAD_FUNCPTR(glIsEnabled)
408 LOAD_FUNCPTR(glNewList)
409 LOAD_FUNCPTR(glPixelStorei)
410 LOAD_FUNCPTR(glReadPixels)
411 LOAD_FUNCPTR(glScissor)
412 LOAD_FUNCPTR(glTexImage2D)
413 LOAD_FUNCPTR(glViewport)
416 /* It doesn't matter if these fail. They'll only be used if the driver reports
417 the associated extension is available (and if a driver reports the extension
418 is available but fails to provide the functions, it's quite broken) */
419 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f);
420 /* NV GLX Extension */
421 LOAD_FUNCPTR(glXAllocateMemoryNV)
422 LOAD_FUNCPTR(glXFreeMemoryNV)
425 if(!X11DRV_WineGL_InitOpenglInfo()) {
426 wine_dlclose(opengl_handle, NULL, 0);
427 opengl_handle = NULL;
432 if (pglXQueryExtension(gdi_display, &error_base, &event_base) == True) {
433 TRACE("GLX is up and running error_base = %d\n", error_base);
435 wine_dlclose(opengl_handle, NULL, 0);
436 opengl_handle = NULL;
439 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
440 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
443 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
444 * depends on the reported GLX client / server version and on the client / server extension list.
445 * Those don't have to be the same.
447 * In general the server GLX information should be used in case of indirect rendering. When direct
448 * rendering is used, the OpenGL client library is responsible for which GLX calls are available.
449 * Nvidia's OpenGL drivers are the best in terms of GLX features. At the moment of writing their
450 * 8762 drivers support 1.3 for the server and 1.4 for the client and they support lots of extensions.
451 * Unfortunately it is much more complicated for Mesa/DRI-based drivers and ATI's drivers.
452 * Both sets of drivers report a server version of 1.2 and the client version can be 1.3 or 1.4.
453 * Further, in case of at least ATI's drivers, one crucial extension needed for our pixel format code
454 * is only available in the list of server extensions and not in the client list.
456 * The versioning checks below try to take into account the comments from above.
459 /* Depending on the use of direct or indirect rendering we need either the list of extensions
460 * exported by the client or by the server.
462 if(WineGLInfo.glxDirect)
463 glx_extensions = WineGLInfo.glxClientExtensions;
465 glx_extensions = WineGLInfo.glxServerExtensions;
467 /* Based on the default opengl context we decide whether direct or indirect rendering is used.
468 * In case of indirect rendering we check if the GLX version of the server is 1.2 and else
469 * the client version is checked.
471 if ((!WineGLInfo.glxDirect && !strcmp("1.2", WineGLInfo.glxServerVersion)) ||
472 (WineGLInfo.glxDirect && !strcmp("1.2", WineGLInfo.glxClientVersion)))
474 if (NULL != strstr(glx_extensions, "GLX_SGIX_fbconfig")) {
475 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
476 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
477 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
479 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxClientVersion);
482 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
483 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
484 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
487 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
488 * enable this function when the Xserver understand GLX 1.3 or newer
490 if (!strcmp("1.2", WineGLInfo.glxServerVersion))
491 pglXQueryDrawable = NULL;
493 pglXQueryDrawable = wine_dlsym(RTLD_DEFAULT, "glXQueryDrawable", NULL, 0);
495 if (NULL != strstr(glx_extensions, "GLX_ATI_render_texture")) {
496 pglXBindTexImageARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageARB");
497 pglXReleaseTexImageARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageARB");
498 pglXDrawableAttribARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribARB");
501 X11DRV_WineGL_LoadExtensions();
504 return (opengl_handle != NULL);
507 wine_dlclose(opengl_handle, NULL, 0);
508 opengl_handle = NULL;
512 static inline Wine_GLContext *alloc_context(void)
516 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLContext))))
518 ret->next = context_list;
519 if (context_list) context_list->prev = ret;
525 static inline void free_context(Wine_GLContext *context)
527 if (context->next != NULL) context->next->prev = context->prev;
528 if (context->prev != NULL) context->prev->next = context->next;
529 else context_list = context->next;
531 HeapFree(GetProcessHeap(), 0, context);
534 static inline Wine_GLContext *get_context_from_GLXContext(GLXContext ctx)
537 if (!ctx) return NULL;
538 for (ret = context_list; ret; ret = ret->next) if (ctx == ret->ctx) break;
543 * get_hdc_from_Drawable (internal)
545 * For use by wglGetCurrentReadDCARB.
547 static inline HDC get_hdc_from_Drawable(GLXDrawable d)
550 for (ret = context_list; ret; ret = ret->next) {
551 if (d == ret->physDev->drawable) {
558 static inline BOOL is_valid_context( Wine_GLContext *ctx )
561 for (ptr = context_list; ptr; ptr = ptr->next) if (ptr == ctx) break;
562 return (ptr != NULL);
565 static int describeContext(Wine_GLContext* ctx) {
568 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
569 pglXGetFBConfigAttrib(gdi_display, ctx->fbconfig, GLX_FBCONFIG_ID, &tmp);
570 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
571 pglXGetFBConfigAttrib(gdi_display, ctx->fbconfig, GLX_VISUAL_ID, &tmp);
572 TRACE(" - VISUAL_ID 0x%x\n", tmp);
577 static int describeDrawable(Wine_GLContext* ctx, Drawable drawable) {
580 int attribList[3] = { GLX_FBCONFIG_ID, 0, None };
583 if (pglXQueryDrawable == NULL) {
584 /** glXQueryDrawable not available so returns not supported */
588 TRACE(" Drawable %p have :\n", (void*) drawable);
589 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &tmp);
590 TRACE(" - WIDTH as %d\n", tmp);
591 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &tmp);
592 TRACE(" - HEIGHT as %d\n", tmp);
593 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &tmp);
594 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
597 fbCfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribList, &nElements);
598 if (fbCfgs == NULL) {
602 pglXGetFBConfigAttrib(gdi_display, fbCfgs[0], GLX_VISUAL_ID, &tmp);
603 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
610 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
616 int wantColorBits = 0;
619 /* The list of WGL attributes is allowed to be NULL, so don't return -1 (error) but just 0 */
623 while (0 != iWGLAttr[cur]) {
624 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
626 switch (iWGLAttr[cur]) {
627 case WGL_COLOR_BITS_ARB:
628 pop = iWGLAttr[++cur];
629 wantColorBits = pop; /** see end */
631 case WGL_BLUE_BITS_ARB:
632 pop = iWGLAttr[++cur];
633 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
634 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
636 case WGL_RED_BITS_ARB:
637 pop = iWGLAttr[++cur];
638 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
639 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
641 case WGL_GREEN_BITS_ARB:
642 pop = iWGLAttr[++cur];
643 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
644 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
646 case WGL_ALPHA_BITS_ARB:
647 pop = iWGLAttr[++cur];
649 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
650 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
652 case WGL_DEPTH_BITS_ARB:
653 pop = iWGLAttr[++cur];
654 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
655 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
657 case WGL_STENCIL_BITS_ARB:
658 pop = iWGLAttr[++cur];
659 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
660 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
662 case WGL_DOUBLE_BUFFER_ARB:
663 pop = iWGLAttr[++cur];
664 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
665 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
668 case WGL_PIXEL_TYPE_ARB:
669 pop = iWGLAttr[++cur];
671 case WGL_TYPE_COLORINDEX_ARB: pop = GLX_COLOR_INDEX_BIT; isColor = 1; break ;
672 case WGL_TYPE_RGBA_ARB: pop = GLX_RGBA_BIT; break ;
673 case WGL_TYPE_RGBA_FLOAT_ATI: pop = GLX_RGBA_FLOAT_ATI_BIT; break ;
675 ERR("unexpected PixelType(%x)\n", pop);
678 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pop);
679 TRACE("pAttr[%d] = GLX_RENDER_TYPE: %d\n", cur, pop);
682 case WGL_SUPPORT_GDI_ARB:
683 pop = iWGLAttr[++cur];
684 /* We only support a limited number of formats which are all renderable by X (similar to GDI).
685 * Ignore this attribute to prevent us from not finding a match due to the limited
686 * amount of formats supported right now. This option could be matched to GLX_X_RENDERABLE
687 * but the issue is that when a program asks for no GDI support, there's no format we can return
688 * as all our supported formats are renderable by X.
690 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
693 case WGL_DRAW_TO_BITMAP_ARB:
694 pop = iWGLAttr[++cur];
695 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
696 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
698 drawattrib |= GLX_PIXMAP_BIT;
702 case WGL_DRAW_TO_WINDOW_ARB:
703 pop = iWGLAttr[++cur];
704 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
705 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
707 drawattrib |= GLX_WINDOW_BIT;
711 case WGL_DRAW_TO_PBUFFER_ARB:
712 pop = iWGLAttr[++cur];
713 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
714 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
716 drawattrib |= GLX_PBUFFER_BIT;
720 case WGL_ACCELERATION_ARB:
721 case WGL_SUPPORT_OPENGL_ARB:
722 pop = iWGLAttr[++cur];
723 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
724 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
727 case WGL_PBUFFER_LARGEST_ARB:
728 pop = iWGLAttr[++cur];
729 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
730 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
733 case WGL_SAMPLE_BUFFERS_ARB:
734 pop = iWGLAttr[++cur];
735 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
736 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
739 case WGL_SAMPLES_ARB:
740 pop = iWGLAttr[++cur];
741 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
742 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
745 case WGL_TEXTURE_FORMAT_ARB:
746 case WGL_TEXTURE_TARGET_ARB:
747 case WGL_MIPMAP_TEXTURE_ARB:
748 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
749 pop = iWGLAttr[++cur];
751 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
753 if (use_render_texture_ati) {
754 /** nothing to do here */
756 else if (!use_render_texture_emulation) {
757 if (WGL_NO_TEXTURE_ARB != pop) {
758 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
759 return -1; /** error: don't support it */
761 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
762 drawattrib |= GLX_PBUFFER_BIT;
767 case WGL_BIND_TO_TEXTURE_RGB_ARB:
768 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
769 pop = iWGLAttr[++cur];
770 /** cannot be converted, see direct handling on
771 * - wglGetPixelFormatAttribivARB
772 * TODO: wglChoosePixelFormat
777 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
784 * Trick as WGL_COLOR_BITS_ARB != GLX_BUFFER_SIZE
785 * WGL_COLOR_BITS_ARB + WGL_ALPHA_BITS_ARB == GLX_BUFFER_SIZE
788 * The number of color bitplanes in each color buffer. For RGBA
789 * pixel types, it is the size of the color buffer, excluding the
790 * alpha bitplanes. For color-index pixels, it is the size of the
791 * color index buffer.
794 * This attribute defines the number of bits per color buffer.
795 * For GLX FBConfigs that correspond to a PseudoColor or StaticColor visual,
796 * this is equal to the depth value reported in the X11 visual.
797 * For GLX FBConfigs that correspond to TrueColor or DirectColor visual,
798 * this is the sum of GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_BLUE_SIZE, and GLX_ALPHA_SIZE.
801 if (0 < wantColorBits) {
803 wantColorBits += sz_alpha;
805 if (32 < wantColorBits) {
806 ERR("buggy %d GLX_BUFFER_SIZE default to 32\n", wantColorBits);
809 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, wantColorBits);
810 TRACE("pAttr[%d] = WGL_COLOR_BITS_ARB: %d\n", cur, wantColorBits);
813 /* Apply the OR'd drawable type bitmask now. */
815 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
816 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
822 static BOOL get_fbconfig_from_visualid(Display *display, Visual *visual, GLXFBConfig *fbconfig, int *fmt_id)
824 GLXFBConfig* cfgs = NULL;
831 if(!display || !visual) {
832 ERR("Invalid display or visual\n");
835 visualid = XVisualIDFromVisual(visual);
837 /* Get a list of all available framebuffer configurations */
838 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
839 if (NULL == cfgs || 0 == nCfgs) {
840 ERR("glXChooseFBConfig returns NULL\n");
841 if(cfgs != NULL) XFree(cfgs);
845 /* Find the requested offscreen format and count the number of offscreen formats */
846 for(i=0; i<nCfgs; i++) {
847 pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id);
848 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id);
850 /* We are looking up the GLX index of our main visual and have found it :) */
851 if(visualid == tmp_vis_id) {
852 TRACE("Found FBCONFIG_ID 0x%x at index %d for VISUAL_ID 0x%x\n", tmp_fmt_id, i, tmp_vis_id);
854 *fmt_id = tmp_fmt_id;
860 ERR("No fbconfig found for Wine's main visual (0x%lx), expect problems!\n", visualid);
865 static BOOL init_formats(Display *display, int screen, Visual *visual)
867 int fmt_id, tmp_vis_id, tmp_fmt_id, nCfgs, i;
869 GLXFBConfig fbconfig;
870 int nOffscreenFormats = 0;
872 /* Locate the fbconfig correspondig to our main visual */
873 if(!get_fbconfig_from_visualid(display, visual, &fbconfig, &fmt_id)) {
874 ERR("Can't get the FBCONFIG_ID for the main visual, expect problems!\n");
878 /* As mentioned in various parts of the code only the format of the main visual can be used for onscreen rendering.
879 * Next to this format there are also so called offscreen rendering formats (used for pbuffers) which can be supported
880 * because they don't need a visual. Below we use glXGetFBConfigs instead of glXChooseFBConfig to enumerate the fb configurations
881 * because this call lists both types of formats instead of only onscreen ones. */
882 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
883 if (NULL == cfgs || 0 == nCfgs) {
884 WARN("glXChooseFBConfig returns NULL\n");
885 if(cfgs != NULL) XFree(cfgs);
887 /* We only have the single format of Wine's main visual */
888 WineGLPixelFormatList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WineGLPixelFormat));
889 WineGLPixelFormatList[0].iPixelFormat = 1;
890 WineGLPixelFormatList[0].fbconfig = fbconfig;
891 WineGLPixelFormatList[0].fmt_id = fmt_id;
892 WineGLPixelFormatList[0].offscreenOnly = FALSE;
893 WineGLPixelFormatListSize = 1;
896 /* Count the number of offscreen formats to determine the size for our pixelformat list */
897 for(i=0; i<nCfgs; i++) {
898 pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id);
900 /* We have found an offscreen rendering format :) */
901 if(tmp_vis_id == 0) {
905 TRACE("Number of offscreen formats: %d\n", nOffscreenFormats);
907 /* Allocate memory for all the offscreen pixelformats and the format of Wine's main visual */
908 WineGLPixelFormatList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (1+nOffscreenFormats)*sizeof(WineGLPixelFormat));
909 WineGLPixelFormatList[0].iPixelFormat = 1;
910 WineGLPixelFormatList[0].fbconfig = fbconfig;
911 WineGLPixelFormatList[0].fmt_id = fmt_id;
912 WineGLPixelFormatList[0].offscreenOnly = FALSE;
913 WineGLPixelFormatListSize = 1;
915 /* Fill the list with offscreen formats */
916 for(i=0; i<nCfgs; i++) {
917 pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id);
918 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id);
920 /* We have found an offscreen rendering format :) */
921 if(tmp_vis_id == 0) {
922 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", tmp_fmt_id, WineGLPixelFormatListSize, i);
923 WineGLPixelFormatList[WineGLPixelFormatListSize].iPixelFormat = WineGLPixelFormatListSize;
924 WineGLPixelFormatList[WineGLPixelFormatListSize].fbconfig = cfgs[i];
925 WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_id = tmp_fmt_id;
926 WineGLPixelFormatList[WineGLPixelFormatListSize].offscreenOnly = TRUE;
927 WineGLPixelFormatListSize++;
932 if(cfgs != NULL) XFree(cfgs);
937 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
938 * In our WGL implementation we only support a subset of these formats namely the format of
939 * Wine's main visual and offscreen formats (if they are available).
940 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
941 * and it returns the number of supported WGL formats in fmt_count.
943 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count)
945 WineGLPixelFormat *res = NULL;
947 /* Init the list of pixel formats when we need it */
948 if(!WineGLPixelFormatListSize)
949 init_formats(display, DefaultScreen(display), visual);
951 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
952 * iPixelFormat in case of probing the number of pixelformats.
954 if((iPixelFormat <= 0) || (iPixelFormat > WineGLPixelFormatListSize)) {
955 ERR("invalid iPixelFormat %d\n", iPixelFormat);
957 *fmt_count = WineGLPixelFormatListSize;
959 *fmt_count = 1; /* Only show the format of our main visual */
961 else if(iPixelFormat == 1) {
962 res = &WineGLPixelFormatList[0];
963 *fmt_count = 1; /* Only show the format of our main visual */
965 else if((WineGLPixelFormatList[iPixelFormat-1].offscreenOnly == TRUE) && AllowOffscreen) {
966 res = &WineGLPixelFormatList[iPixelFormat-1];
967 *fmt_count = WineGLPixelFormatListSize;
968 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res->fbconfig, iPixelFormat);
971 TRACE("Number of returned pixelformats=%d\n", *fmt_count);
976 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
977 static int ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id)
981 /* Init the list of pixel formats when we need it */
982 if(!WineGLPixelFormatListSize)
983 init_formats(display, DefaultScreen(display), visual);
985 for(i=0; i<WineGLPixelFormatListSize; i++) {
986 if(WineGLPixelFormatList[i].fmt_id == fmt_id) {
987 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", WineGLPixelFormatList[i].iPixelFormat, fmt_id);
988 return WineGLPixelFormatList[i].iPixelFormat;
991 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id);
996 * X11DRV_ChoosePixelFormat
998 * Equivalent to glXChooseVisual.
1000 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
1001 const PIXELFORMATDESCRIPTOR *ppfd) {
1002 WineGLPixelFormat *fmt;
1006 if (!has_opengl()) {
1007 ERR("No libGL on this box - disabling OpenGL support !\n");
1011 if (TRACE_ON(opengl)) {
1012 TRACE("(%p,%p)\n", physDev, ppfd);
1014 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR *) ppfd);
1019 ERR("Can't get an opengl visual!\n");
1023 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, 1 /* main visual */, FALSE /* offscreen */, &value);
1024 /* In case an fbconfig was found, check if it matches to the requirements of the ppfd */
1026 ERR("Can't find a matching FBCONFIG_ID for VISUAL_ID 0x%lx!\n", visual->visualid);
1033 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1034 if (value & GLX_RGBA_BIT)
1035 iPixelType = PFD_TYPE_RGBA;
1037 iPixelType = PFD_TYPE_COLORINDEX;
1039 if (ppfd->iPixelType != iPixelType) {
1040 TRACE("pixel type mismatch\n");
1045 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value); if (value) dwFlags |= PFD_DOUBLEBUFFER;
1046 if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) && (ppfd->dwFlags & PFD_DOUBLEBUFFER)) {
1047 if (!(dwFlags & PFD_DOUBLEBUFFER)) {
1048 TRACE("dbl buffer mismatch\n");
1054 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) dwFlags |= PFD_STEREO;
1055 if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE) && (ppfd->dwFlags & PFD_STEREO)) {
1056 if (!(dwFlags & PFD_STEREO)) {
1057 TRACE("stereo mismatch\n");
1063 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &value);
1064 if (ppfd->iPixelType==PFD_TYPE_RGBA && ppfd->cAlphaBits && !value) {
1065 TRACE("alpha mismatch\n");
1070 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1071 if (ppfd->cDepthBits && !value) {
1072 TRACE("depth mismatch\n");
1077 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1078 if (ppfd->cStencilBits && !value) {
1079 TRACE("stencil mismatch\n");
1084 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1085 if (ppfd->cAuxBuffers && !value) {
1086 TRACE("aux mismatch\n");
1090 /* When we pass all the checks we have found a matching format :) */
1092 TRACE("Successfully found a matching mode, returning index: %d\n", ret);
1097 TRACE("No matching mode was found returning 0\n");
1099 wine_tsx11_unlock();
1104 * X11DRV_DescribePixelFormat
1106 * Get the pixel-format descriptor associated to the given id
1108 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
1111 PIXELFORMATDESCRIPTOR *ppfd) {
1112 /*XVisualInfo *vis;*/
1115 WineGLPixelFormat *fmt;
1119 if (!has_opengl()) {
1120 ERR("No libGL on this box - disabling OpenGL support !\n");
1124 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
1126 /* Look for the iPixelFormat in our list of supported formats. If it is supported we get the index in the FBConfig table and the number of supported formats back */
1127 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_count);
1129 /* The application is only querying the number of pixelformats */
1131 } else if(fmt == NULL) {
1132 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1136 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1137 ERR("Wrong structure size !\n");
1138 /* Should set error */
1144 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1145 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1148 /* These flags are always the same... */
1149 ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
1150 /* Now the flags extracted from the Visual */
1154 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_CONFIG_CAVEAT, &value);
1155 if(value == GLX_SLOW_CONFIG)
1156 ppfd->dwFlags |= PFD_GENERIC_ACCELERATED;
1158 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value); if (value) ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1159 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1162 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1163 if (value & GLX_RGBA_BIT)
1164 ppfd->iPixelType = PFD_TYPE_RGBA;
1166 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1169 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1170 ppfd->cColorBits = value;
1172 /* Red, green, blue and alpha bits / shifts */
1173 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1174 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1175 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1176 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1177 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1179 ppfd->cRedBits = rb;
1180 ppfd->cRedShift = gb + bb + ab;
1181 ppfd->cBlueBits = bb;
1182 ppfd->cBlueShift = ab;
1183 ppfd->cGreenBits = gb;
1184 ppfd->cGreenShift = bb + ab;
1185 ppfd->cAlphaBits = ab;
1186 ppfd->cAlphaShift = 0;
1189 ppfd->cRedShift = 0;
1190 ppfd->cBlueBits = 0;
1191 ppfd->cBlueShift = 0;
1192 ppfd->cGreenBits = 0;
1193 ppfd->cGreenShift = 0;
1194 ppfd->cAlphaBits = 0;
1195 ppfd->cAlphaShift = 0;
1197 /* Accums : to do ... */
1200 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1201 ppfd->cDepthBits = value;
1204 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1205 ppfd->cStencilBits = value;
1207 wine_tsx11_unlock();
1209 /* Aux : to do ... */
1211 ppfd->iLayerType = PFD_MAIN_PLANE;
1213 if (TRACE_ON(opengl)) {
1214 dump_PIXELFORMATDESCRIPTOR(ppfd);
1221 * X11DRV_GetPixelFormat
1223 * Get the pixel-format id used by this DC
1225 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
1226 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1228 return physDev->current_pf;
1232 * X11DRV_SetPixelFormat
1234 * Set the pixel-format id used by this DC
1236 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
1238 const PIXELFORMATDESCRIPTOR *ppfd) {
1239 WineGLPixelFormat *fmt;
1242 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1244 if (!has_opengl()) {
1245 ERR("No libGL on this box - disabling OpenGL support !\n");
1249 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1250 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
1252 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1256 physDev->current_pf = iPixelFormat;
1258 if (TRACE_ON(opengl)) {
1262 * How to test if hdc current drawable is compatible (visual/FBConfig) ?
1264 * in case of root window created HDCs we crash here :(
1266 Drawable drawable = get_drawable( physDev->hdc );
1267 TRACE(" drawable (%p,%p) have :\n", drawable, root_window);
1268 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &value);
1269 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
1270 pglXQueryDrawable(gdi_display, drawable, GLX_VISUAL_ID, (unsigned int*) &value);
1271 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
1272 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &value);
1273 TRACE(" - WIDTH as %d\n", tmp);
1274 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &value);
1275 TRACE(" - HEIGHT as %d\n", tmp);
1277 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1279 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1281 TRACE(" FBConfig have :\n");
1282 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1283 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1284 TRACE(" - VISUAL_ID 0x%x\n", value);
1285 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1286 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1293 * X11DRV_wglCreateContext
1295 * For OpenGL32 wglCreateContext.
1297 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
1299 Wine_GLContext *ret;
1300 WineGLPixelFormat *fmt;
1301 int hdcPF = physDev->current_pf;
1305 HDC hdc = physDev->hdc;
1307 TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1309 if (!has_opengl()) {
1310 ERR("No libGL on this box - disabling OpenGL support !\n");
1314 /* First, get the visual in use by the X11DRV */
1315 if (!gdi_display) return 0;
1317 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, TRUE /* Offscreen */, &fmt_count);
1318 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1319 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1320 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1321 * If this fails something is very wrong on the system. */
1323 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF);
1324 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1328 if (fmt_count < hdcPF) {
1329 ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, hdcPF, fmt_count);
1330 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1334 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1336 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1337 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1341 /* The context will be allocated in the wglMakeCurrent call */
1343 ret = alloc_context();
1344 wine_tsx11_unlock();
1346 ret->physDev = physDev;
1347 ret->fbconfig = fmt->fbconfig;
1349 ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1351 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1356 * X11DRV_wglDeleteContext
1358 * For OpenGL32 wglDeleteContext.
1360 BOOL X11DRV_wglDeleteContext(HGLRC hglrc)
1362 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1365 TRACE("(%p)\n", hglrc);
1367 if (!has_opengl()) {
1368 ERR("No libGL on this box - disabling OpenGL support !\n");
1373 /* A game (Half Life not to name it) deletes twice the same context,
1374 * so make sure it is valid first */
1375 if (is_valid_context( ctx ))
1377 if (ctx->ctx) pglXDestroyContext(gdi_display, ctx->ctx);
1382 WARN("Error deleting context !\n");
1383 SetLastError(ERROR_INVALID_HANDLE);
1386 wine_tsx11_unlock();
1392 * X11DRV_wglGetCurrentReadDCARB
1394 * For OpenGL32 wglGetCurrentReadDCARB.
1396 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1404 gl_d = pglXGetCurrentReadDrawable();
1405 ret = get_hdc_from_Drawable(gl_d);
1406 wine_tsx11_unlock();
1408 TRACE(" returning %p (GL drawable %lu)\n", ret, gl_d);
1413 * X11DRV_wglGetProcAddress
1415 * For OpenGL32 wglGetProcAddress.
1417 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1420 const WineGLExtension *ext;
1422 int padding = 32 - strlen(lpszProc);
1426 if (!has_opengl()) {
1427 ERR("No libGL on this box - disabling OpenGL support !\n");
1431 /* Check the table of WGL extensions to see if we need to return a WGL extension
1432 * or a function pointer to a native OpenGL function. */
1433 if(strncmp(lpszProc, "wgl", 3) != 0) {
1434 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1436 TRACE("('%s'):%*s", lpszProc, padding, " ");
1437 for (i = 0; i < WineGLExtensionListSize; ++i) {
1438 ext = WineGLExtensionList[i];
1439 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1440 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1441 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1442 return ext->extEntryPoints[j].funcAddress;
1448 ERR("(%s) - not found\n", lpszProc);
1452 /***********************************************************************
1453 * sync_current_drawable
1455 * Adjust the current viewport and scissor in order to position
1456 * and size the current drawable correctly on the parent window.
1458 static void sync_current_drawable(BOOL updatedc)
1464 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1468 if (ctx && ctx->physDev)
1471 GetClipBox(ctx->physDev->hdc, &rc); /* Make sure physDev is up to date */
1473 dy = ctx->physDev->drawable_rect.bottom - ctx->physDev->drawable_rect.top -
1474 ctx->physDev->dc_rect.bottom;
1475 width = ctx->physDev->dc_rect.right - ctx->physDev->dc_rect.left;
1476 height = ctx->physDev->dc_rect.bottom - ctx->physDev->dc_rect.top;
1480 pglViewport(ctx->physDev->dc_rect.left + ctx->viewport.left,
1481 dy + ctx->viewport.top,
1482 ctx->viewport.right ? (ctx->viewport.right - ctx->viewport.left) : width,
1483 ctx->viewport.bottom ? (ctx->viewport.bottom - ctx->viewport.top) : height);
1485 pglEnable(GL_SCISSOR_TEST);
1487 if (ctx->scissor_enabled)
1488 pglScissor(ctx->physDev->dc_rect.left + min(width, max(0, ctx->scissor.left)),
1489 dy + min(height, max(0, ctx->scissor.top)),
1490 min(width, max(0, ctx->scissor.right - ctx->scissor.left)),
1491 min(height, max(0, ctx->scissor.bottom - ctx->scissor.top)));
1493 pglScissor(ctx->physDev->dc_rect.left, dy, width, height);
1495 wine_tsx11_unlock();
1500 * X11DRV_wglMakeCurrent
1502 * For OpenGL32 wglMakeCurrent.
1504 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
1506 HDC hdc = physDev->hdc;
1507 DWORD type = GetObjectType(hdc);
1509 TRACE("(%p,%p)\n", hdc, hglrc);
1511 if (!has_opengl()) {
1512 ERR("No libGL on this box - disabling OpenGL support !\n");
1517 if (hglrc == NULL) {
1518 ret = pglXMakeCurrent(gdi_display, None, NULL);
1519 NtCurrentTeb()->glContext = NULL;
1521 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1522 Drawable drawable = get_glxdrawable(physDev);
1523 if (ctx->ctx == NULL) {
1524 /* The describe lines below are for debugging purposes only */
1525 if (TRACE_ON(wgl)) {
1526 describeDrawable(ctx, drawable);
1527 describeContext(ctx);
1530 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1531 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1533 TRACE(" Creating GLX Context\n");
1535 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, type == OBJ_MEMDC ? False : True);
1536 else /* Create a GLX Context for a pbuffer */
1537 ctx->ctx = pglXCreateNewContext(gdi_display, ctx->fbconfig, GLX_RGBA_TYPE, NULL, True);
1539 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1541 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display, (void*) drawable, ctx->ctx);
1542 ret = pglXMakeCurrent(gdi_display, drawable, ctx->ctx);
1543 NtCurrentTeb()->glContext = ctx;
1546 ctx->physDev = physDev;
1548 if (type == OBJ_MEMDC)
1550 ctx->do_escape = TRUE;
1551 pglDrawBuffer(GL_FRONT_LEFT);
1555 sync_current_drawable(FALSE);
1559 wine_tsx11_unlock();
1560 TRACE(" returning %s\n", (ret ? "True" : "False"));
1565 * X11DRV_wglMakeContextCurrentARB
1567 * For OpenGL32 wglMakeContextCurrentARB
1569 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc)
1572 TRACE("(%p,%p,%p)\n", hDrawDev, hReadDev, hglrc);
1574 if (!has_opengl()) {
1575 ERR("No libGL on this box - disabling OpenGL support !\n");
1580 if (hglrc == NULL) {
1581 ret = pglXMakeCurrent(gdi_display, None, NULL);
1582 NtCurrentTeb()->glContext = NULL;
1584 if (NULL == pglXMakeContextCurrent) {
1587 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1588 Drawable d_draw = get_glxdrawable(hDrawDev);
1589 Drawable d_read = get_glxdrawable(hReadDev);
1591 if (ctx->ctx == NULL) {
1592 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, GetObjectType(hDrawDev->hdc) == OBJ_MEMDC ? False : True);
1593 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1595 ret = pglXMakeContextCurrent(gdi_display, d_draw, d_read, ctx->ctx);
1596 NtCurrentTeb()->glContext = ctx;
1599 wine_tsx11_unlock();
1601 TRACE(" returning %s\n", (ret ? "True" : "False"));
1606 * X11DRV_wglShareLists
1608 * For OpenGL32 wglShaderLists.
1610 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
1611 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1612 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1614 TRACE("(%p, %p)\n", org, dest);
1616 if (!has_opengl()) {
1617 ERR("No libGL on this box - disabling OpenGL support !\n");
1621 if (NULL != dest && dest->ctx != NULL) {
1622 ERR("Could not share display lists, context already created !\n");
1625 if (org->ctx == NULL) {
1627 describeContext(org);
1630 org->ctx = pglXCreateContext(gdi_display, org->vis, NULL, GetObjectType(org->physDev->hdc) == OBJ_MEMDC ? False : True);
1631 else /* Create a GLX Context for a pbuffer */
1632 org->ctx = pglXCreateNewContext(gdi_display, org->fbconfig, GLX_RGBA_TYPE, NULL, True);
1633 wine_tsx11_unlock();
1634 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org->ctx, org);
1638 describeContext(dest);
1639 /* Create the destination context with display lists shared */
1641 dest->ctx = pglXCreateContext(gdi_display, dest->vis, org->ctx, GetObjectType(org->physDev->hdc) == OBJ_MEMDC ? False : True);
1642 else /* Create a GLX Context for a pbuffer */
1643 dest->ctx = pglXCreateNewContext(gdi_display, dest->fbconfig, GLX_RGBA_TYPE, org->ctx, True);
1644 wine_tsx11_unlock();
1645 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1652 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
1654 /* We are running using client-side rendering fonts... */
1658 void *bitmap = NULL, *gl_bitmap = NULL;
1662 pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1663 pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1664 wine_tsx11_unlock();
1666 for (glyph = first; glyph < first + count; glyph++) {
1667 unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, NULL);
1668 int height, width_int;
1670 TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
1671 if (needed_size == GDI_ERROR) {
1672 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size);
1675 TRACE(" - needed size : %d\n", needed_size);
1678 if (needed_size > size) {
1680 HeapFree(GetProcessHeap(), 0, bitmap);
1681 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1682 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1683 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1685 if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, NULL) == GDI_ERROR) goto error;
1686 if (TRACE_ON(opengl)) {
1687 unsigned int height, width, bitmask;
1688 unsigned char *bitmap_ = (unsigned char *) bitmap;
1690 TRACE(" - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
1691 TRACE(" - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
1692 TRACE(" - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
1693 if (needed_size != 0) {
1694 TRACE(" - bitmap :\n");
1695 for (height = 0; height < gm.gmBlackBoxY; height++) {
1697 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
1702 if (*bitmap_ & bitmask)
1707 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
1713 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1714 * glyph for it to be drawn properly.
1716 if (needed_size != 0) {
1717 width_int = (gm.gmBlackBoxX + 31) / 32;
1718 for (height = 0; height < gm.gmBlackBoxY; height++) {
1720 for (width = 0; width < width_int; width++) {
1721 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
1722 ((int *) bitmap)[height * width_int + width];
1728 pglNewList(listBase++, GL_COMPILE);
1729 if (needed_size != 0) {
1730 pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
1731 0 - (int) gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - (int) gm.gmptGlyphOrigin.y,
1732 gm.gmCellIncX, gm.gmCellIncY,
1735 /* This is the case of 'empty' glyphs like the space character */
1736 pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
1739 wine_tsx11_unlock();
1743 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1744 wine_tsx11_unlock();
1746 HeapFree(GetProcessHeap(), 0, bitmap);
1747 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1752 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1753 wine_tsx11_unlock();
1755 HeapFree(GetProcessHeap(), 0, bitmap);
1756 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1761 * X11DRV_wglUseFontBitmapsA
1763 * For OpenGL32 wglUseFontBitmapsA.
1765 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1767 Font fid = physDev->font;
1769 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1771 if (!has_opengl()) {
1772 ERR("No libGL on this box - disabling OpenGL support !\n");
1777 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineA);
1781 /* I assume that the glyphs are at the same position for X and for Windows */
1782 pglXUseXFont(fid, first, count, listBase);
1783 wine_tsx11_unlock();
1788 * X11DRV_wglUseFontBitmapsW
1790 * For OpenGL32 wglUseFontBitmapsW.
1792 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1794 Font fid = physDev->font;
1796 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1798 if (!has_opengl()) {
1799 ERR("No libGL on this box - disabling OpenGL support !\n");
1804 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineW);
1807 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1810 /* I assume that the glyphs are at the same position for X and for Windows */
1811 pglXUseXFont(fid, first, count, listBase);
1812 wine_tsx11_unlock();
1816 static void WINAPI X11DRV_wglDisable(GLenum cap)
1818 if (cap == GL_SCISSOR_TEST)
1820 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1823 ctx->scissor_enabled = FALSE;
1829 wine_tsx11_unlock();
1833 static void WINAPI X11DRV_wglEnable(GLenum cap)
1835 if (cap == GL_SCISSOR_TEST)
1837 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1840 ctx->scissor_enabled = TRUE;
1846 wine_tsx11_unlock();
1850 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1851 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params)
1858 GLXContext gl_ctx = pglXGetCurrentContext();
1859 Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx);
1861 pglGetIntegerv(pname, params);
1863 * if we cannot find a Wine Context
1864 * we only have the default wine desktop context,
1865 * so if we have only a 24 depth say we have 32
1867 if (NULL == ret && 24 == *params) {
1870 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
1875 GLXContext gl_ctx = pglXGetCurrentContext();
1876 Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx);
1878 pglXGetFBConfigAttrib(gdi_display, ret->fbconfig, GLX_ALPHA_SIZE, params);
1879 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params);
1883 pglGetIntegerv(pname, params);
1886 wine_tsx11_unlock();
1889 static GLboolean WINAPI X11DRV_wglIsEnabled(GLenum cap)
1891 GLboolean enabled = False;
1893 if (cap == GL_SCISSOR_TEST)
1895 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1898 enabled = ctx->scissor_enabled;
1903 enabled = pglIsEnabled(cap);
1904 wine_tsx11_unlock();
1909 static void WINAPI X11DRV_wglScissor(GLint x, GLint y, GLsizei width, GLsizei height)
1911 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1915 ctx->scissor.left = x;
1916 ctx->scissor.top = y;
1917 ctx->scissor.right = x + width;
1918 ctx->scissor.bottom = y + height;
1920 sync_current_drawable(TRUE);
1924 static void WINAPI X11DRV_wglViewport(GLint x, GLint y, GLsizei width, GLsizei height)
1926 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1930 ctx->viewport.left = x;
1931 ctx->viewport.top = y;
1932 ctx->viewport.right = x + width;
1933 ctx->viewport.bottom = y + height;
1935 sync_current_drawable(TRUE);
1940 * X11DRV_wglGetExtensionsStringARB
1942 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
1944 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
1945 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
1946 return WineGLInfo.wglExtensions;
1950 * X11DRV_wglCreatePbufferARB
1952 * WGL_ARB_pbuffer: wglCreatePbufferARB
1954 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
1956 Wine_GLPBuffer* object = NULL;
1957 WineGLPixelFormat *fmt = NULL;
1962 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
1964 if (0 >= iPixelFormat) {
1965 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
1966 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1967 return NULL; /* unexpected error */
1970 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
1971 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nCfgs);
1973 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
1974 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1975 goto create_failed; /* unexpected error */
1978 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
1979 if (NULL == object) {
1980 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
1981 goto create_failed; /* unexpected error */
1984 object->display = gdi_display;
1985 object->width = iWidth;
1986 object->height = iHeight;
1987 object->pixelFormat = iPixelFormat;
1989 nAttribs = ConvertAttribWGLtoGLX(piAttribList, attribs, object);
1990 if (-1 == nAttribs) {
1991 WARN("Cannot convert WGL to GLX attributes\n");
1994 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
1995 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
1996 while (piAttribList && 0 != *piAttribList) {
1998 switch (*piAttribList) {
1999 case WGL_TEXTURE_FORMAT_ARB: {
2001 attr_v = *piAttribList;
2002 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2003 if (use_render_texture_ati) {
2006 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2007 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
2008 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
2010 SetLastError(ERROR_INVALID_DATA);
2013 object->use_render_texture = 1;
2014 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
2016 if (WGL_NO_TEXTURE_ARB == attr_v) {
2017 object->use_render_texture = 0;
2019 if (!use_render_texture_emulation) {
2020 SetLastError(ERROR_INVALID_DATA);
2024 case WGL_TEXTURE_RGB_ARB:
2025 object->use_render_texture = GL_RGB;
2027 case WGL_TEXTURE_RGBA_ARB:
2028 object->use_render_texture = GL_RGBA;
2031 SetLastError(ERROR_INVALID_DATA);
2039 case WGL_TEXTURE_TARGET_ARB: {
2041 attr_v = *piAttribList;
2042 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2043 if (use_render_texture_ati) {
2046 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2047 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
2048 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
2049 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
2051 SetLastError(ERROR_INVALID_DATA);
2054 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
2056 if (WGL_NO_TEXTURE_ARB == attr_v) {
2057 object->texture_target = 0;
2059 if (!use_render_texture_emulation) {
2060 SetLastError(ERROR_INVALID_DATA);
2064 case WGL_TEXTURE_CUBE_MAP_ARB: {
2065 if (iWidth != iHeight) {
2066 SetLastError(ERROR_INVALID_DATA);
2069 object->texture_target = GL_TEXTURE_CUBE_MAP;
2070 object->texture_bind_target = GL_TEXTURE_CUBE_MAP;
2073 case WGL_TEXTURE_1D_ARB: {
2075 SetLastError(ERROR_INVALID_DATA);
2078 object->texture_target = GL_TEXTURE_1D;
2079 object->texture_bind_target = GL_TEXTURE_1D;
2082 case WGL_TEXTURE_2D_ARB: {
2083 object->texture_target = GL_TEXTURE_2D;
2084 object->texture_bind_target = GL_TEXTURE_2D;
2088 SetLastError(ERROR_INVALID_DATA);
2096 case WGL_MIPMAP_TEXTURE_ARB: {
2098 attr_v = *piAttribList;
2099 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2100 if (use_render_texture_ati) {
2101 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
2103 if (!use_render_texture_emulation) {
2104 SetLastError(ERROR_INVALID_DATA);
2114 PUSH1(attribs, None);
2115 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2116 TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
2117 if (!object->drawable) {
2118 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2119 goto create_failed; /* unexpected error */
2121 TRACE("->(%p)\n", object);
2122 return (HPBUFFERARB) object;
2125 HeapFree(GetProcessHeap(), 0, object);
2126 TRACE("->(FAILED)\n");
2127 return (HPBUFFERARB) NULL;
2131 * X11DRV_wglDestroyPbufferARB
2133 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2135 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2137 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2138 TRACE("(%p)\n", hPbuffer);
2139 if (NULL == object) {
2140 SetLastError(ERROR_INVALID_HANDLE);
2143 pglXDestroyPbuffer(object->display, object->drawable);
2144 HeapFree(GetProcessHeap(), 0, object);
2149 * X11DRV_wglGetPbufferDCARB
2151 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2152 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2153 * Gdi32 implements the part of this function which creates a device context.
2154 * This part associates the physDev with the X drawable of the pbuffer.
2156 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
2158 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2159 if (NULL == object) {
2160 SetLastError(ERROR_INVALID_HANDLE);
2164 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2165 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2166 physDev->current_pf = object->pixelFormat;
2167 physDev->drawable = object->drawable;
2168 SetRect( &physDev->drawable_rect, 0, 0, object->width, object->height );
2169 physDev->dc_rect = physDev->drawable_rect;
2171 TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);
2172 return physDev->hdc;
2176 * X11DRV_wglQueryPbufferARB
2178 * WGL_ARB_pbuffer: wglQueryPbufferARB
2180 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2182 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2183 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2184 if (NULL == object) {
2185 SetLastError(ERROR_INVALID_HANDLE);
2188 switch (iAttribute) {
2189 case WGL_PBUFFER_WIDTH_ARB:
2190 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2192 case WGL_PBUFFER_HEIGHT_ARB:
2193 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2196 case WGL_PBUFFER_LOST_ARB:
2197 FIXME("unsupported WGL_PBUFFER_LOST_ARB (need glXSelectEvent/GLX_DAMAGED work)\n");
2200 case WGL_TEXTURE_FORMAT_ARB:
2201 if (use_render_texture_ati) {
2203 int type = WGL_NO_TEXTURE_ARB;
2204 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2206 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2207 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2208 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2212 if (!object->use_render_texture) {
2213 *piValue = WGL_NO_TEXTURE_ARB;
2215 if (!use_render_texture_emulation) {
2216 SetLastError(ERROR_INVALID_HANDLE);
2219 if (GL_RGBA == object->use_render_texture) {
2220 *piValue = WGL_TEXTURE_RGBA_ARB;
2222 *piValue = WGL_TEXTURE_RGB_ARB;
2228 case WGL_TEXTURE_TARGET_ARB:
2229 if (use_render_texture_ati) {
2231 int type = WGL_NO_TEXTURE_ARB;
2232 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2234 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2235 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2236 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2237 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2241 if (!object->texture_target) {
2242 *piValue = WGL_NO_TEXTURE_ARB;
2244 if (!use_render_texture_emulation) {
2245 SetLastError(ERROR_INVALID_DATA);
2248 switch (object->texture_target) {
2249 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2250 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_1D_ARB; break;
2251 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_2D_ARB; break;
2257 case WGL_MIPMAP_TEXTURE_ARB:
2258 if (use_render_texture_ati) {
2259 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2261 *piValue = GL_FALSE; /** don't support that */
2262 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2267 FIXME("unexpected attribute %x\n", iAttribute);
2275 * X11DRV_wglReleasePbufferDCARB
2277 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2279 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2281 TRACE("(%p, %p)\n", hPbuffer, hdc);
2287 * X11DRV_wglSetPbufferAttribARB
2289 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2291 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2293 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2294 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2295 if (NULL == object) {
2296 SetLastError(ERROR_INVALID_HANDLE);
2299 if (!object->use_render_texture) {
2300 SetLastError(ERROR_INVALID_HANDLE);
2303 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2306 if (NULL != pglXDrawableAttribARB) {
2307 if (use_render_texture_ati) {
2308 FIXME("Need conversion for GLX_ATI_render_texture\n");
2310 return pglXDrawableAttribARB(object->display, object->drawable, piAttribList);
2316 * X11DRV_wglChoosePixelFormatARB
2318 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2320 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2325 GLXFBConfig* cfgs = NULL;
2330 GLXFBConfig* cfgs_fmt = NULL;
2336 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2337 if (NULL != pfAttribFList) {
2338 FIXME("unused pfAttribFList\n");
2341 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2342 if (-1 == nAttribs) {
2343 WARN("Cannot convert WGL to GLX attributes\n");
2346 PUSH1(attribs, None);
2348 /* Search for FB configurations matching the requirements in attribs */
2349 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2351 WARN("Compatible Pixel Format not found\n");
2355 /* Get a list of all FB configurations */
2356 cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
2357 if (NULL == cfgs_fmt) {
2358 ERR("Failed to get All FB Configs\n");
2363 /* Loop through all matching formats and check if they are suitable.
2364 * Note that this function should at max return nMaxFormats different formats */
2365 for (it = 0; pfmt_it < nMaxFormats && it < nCfgs; ++it) {
2366 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2368 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2372 /* Search for the format in our list of compatible formats */
2373 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id);
2377 piFormats[pfmt_it] = fmt;
2378 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d/%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it], nCfgs_fmt);
2382 *nNumFormats = pfmt_it;
2390 * X11DRV_wglGetPixelFormatAttribivARB
2392 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2394 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2397 WineGLPixelFormat *fmt = NULL;
2401 int nWGLFormats = 0;
2403 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2405 if (0 < iLayerPlane) {
2406 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2410 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2411 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2412 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2413 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nWGLFormats);
2415 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2418 for (i = 0; i < nAttributes; ++i) {
2419 const int curWGLAttr = piAttributes[i];
2420 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2422 switch (curWGLAttr) {
2423 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2424 piValues[i] = nWGLFormats;
2427 case WGL_SUPPORT_OPENGL_ARB:
2428 piValues[i] = GL_TRUE;
2431 case WGL_ACCELERATION_ARB:
2432 curGLXAttr = GLX_CONFIG_CAVEAT;
2433 if (!fmt) goto pix_error;
2434 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2435 if (hTest) goto get_error;
2437 case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2438 case GLX_SLOW_CONFIG: piValues[i] = WGL_NO_ACCELERATION_ARB; break;
2439 case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2441 ERR("unexpected Config Caveat(%x)\n", tmp);
2442 piValues[i] = WGL_NO_ACCELERATION_ARB;
2446 case WGL_TRANSPARENT_ARB:
2447 curGLXAttr = GLX_TRANSPARENT_TYPE;
2448 if (!fmt) goto pix_error;
2449 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2450 if (hTest) goto get_error;
2451 piValues[i] = GL_FALSE;
2452 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2455 case WGL_PIXEL_TYPE_ARB:
2456 curGLXAttr = GLX_RENDER_TYPE;
2457 if (!fmt) goto pix_error;
2458 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2459 if (hTest) goto get_error;
2460 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2461 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2462 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2463 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2464 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2466 ERR("unexpected RenderType(%x)\n", tmp);
2467 piValues[i] = WGL_TYPE_RGBA_ARB;
2471 case WGL_COLOR_BITS_ARB:
2472 /** see ConvertAttribWGLtoGLX for explain */
2473 if (!fmt) goto pix_error;
2474 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, piValues + i);
2475 if (hTest) goto get_error;
2476 TRACE("WGL_COLOR_BITS_ARB: GLX_BUFFER_SIZE = %d\n", piValues[i]);
2477 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &tmp);
2478 if (hTest) goto get_error;
2479 TRACE("WGL_COLOR_BITS_ARB: GLX_ALPHA_SIZE = %d\n", tmp);
2480 piValues[i] = piValues[i] - tmp;
2483 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2484 if (use_render_texture_ati) {
2485 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
2488 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2489 if (use_render_texture_ati) {
2490 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
2493 if (!use_render_texture_emulation) {
2494 piValues[i] = GL_FALSE;
2497 curGLXAttr = GLX_RENDER_TYPE;
2498 if (!fmt) goto pix_error;
2499 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2500 if (hTest) goto get_error;
2501 if (GLX_COLOR_INDEX_BIT == tmp) {
2502 piValues[i] = GL_FALSE;
2505 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2506 if (hTest) goto get_error;
2507 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2510 case WGL_BLUE_BITS_ARB:
2511 curGLXAttr = GLX_BLUE_SIZE;
2513 case WGL_RED_BITS_ARB:
2514 curGLXAttr = GLX_RED_SIZE;
2516 case WGL_GREEN_BITS_ARB:
2517 curGLXAttr = GLX_GREEN_SIZE;
2519 case WGL_ALPHA_BITS_ARB:
2520 curGLXAttr = GLX_ALPHA_SIZE;
2522 case WGL_DEPTH_BITS_ARB:
2523 curGLXAttr = GLX_DEPTH_SIZE;
2525 case WGL_STENCIL_BITS_ARB:
2526 curGLXAttr = GLX_STENCIL_SIZE;
2528 case WGL_DOUBLE_BUFFER_ARB:
2529 curGLXAttr = GLX_DOUBLEBUFFER;
2531 case WGL_STEREO_ARB:
2532 curGLXAttr = GLX_STEREO;
2534 case WGL_AUX_BUFFERS_ARB:
2535 curGLXAttr = GLX_AUX_BUFFERS;
2537 case WGL_SUPPORT_GDI_ARB:
2538 case WGL_DRAW_TO_WINDOW_ARB:
2539 case WGL_DRAW_TO_BITMAP_ARB:
2540 /* We only supported a limited number of formats right now which are all renderable by X 'GLX_X_RENDERABLE' */
2541 piValues[i] = GL_TRUE;
2543 case WGL_DRAW_TO_PBUFFER_ARB:
2544 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2545 if (hTest) goto get_error;
2546 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2549 case WGL_PBUFFER_LARGEST_ARB:
2550 curGLXAttr = GLX_LARGEST_PBUFFER;
2553 case WGL_SAMPLE_BUFFERS_ARB:
2554 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2557 case WGL_SAMPLES_ARB:
2558 curGLXAttr = GLX_SAMPLES_ARB;
2562 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2565 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2566 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2567 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2569 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2570 * and check which options can work using iPixelFormat=0 and which not.
2571 * A problem would be that this function is an extension. This would
2572 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2574 if (0 != curGLXAttr && iPixelFormat != 0) {
2575 if (!fmt) goto pix_error;
2576 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2577 if (hTest) goto get_error;
2580 piValues[i] = GL_FALSE;
2586 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2590 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats);
2595 * X11DRV_wglGetPixelFormatAttribfvARB
2597 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2599 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
2605 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2607 /* Allocate a temporary array to store integer values */
2608 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2610 ERR("couldn't allocate %d array\n", nAttributes);
2614 /* Piggy-back on wglGetPixelFormatAttribivARB */
2615 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2617 /* Convert integer values to float. Should also check for attributes
2618 that can give decimal values here */
2619 for (i=0; i<nAttributes;i++) {
2620 pfValues[i] = attr[i];
2624 HeapFree(GetProcessHeap(), 0, attr);
2629 * X11DRV_wglBindTexImageARB
2631 * WGL_ARB_render_texture: wglBindTexImageARB
2633 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2635 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2636 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2637 if (NULL == object) {
2638 SetLastError(ERROR_INVALID_HANDLE);
2641 if (!object->use_render_texture) {
2642 SetLastError(ERROR_INVALID_HANDLE);
2646 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2648 static int init = 0;
2649 GLXContext prev_context = pglXGetCurrentContext();
2650 Drawable prev_drawable = pglXGetCurrentDrawable();
2652 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2653 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2654 isn't ideal performance wise but I wasn't able to get other ways working.
2657 init = 1; /* Only show the FIXME once for performance reasons */
2658 FIXME("partial stub!\n");
2661 buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 4*object->width*object->height);
2663 ERR("Unable to allocate a buffer for render_texture emulation\n");
2667 /* Switch to our pbuffer and readback its contents */
2668 pglXMakeCurrent(gdi_display, object->drawable, prev_context);
2669 pglReadPixels(0, 0, object->width, object->height, GL_RGBA, GL_UNSIGNED_BYTE, buf);
2671 /* Switch back to the original drawable and upload the pbuffer-texture */
2672 pglXMakeCurrent(object->display, prev_drawable, prev_context);
2673 pglTexImage2D(object->texture_target, 0, GL_RGBA8, object->width, object->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf);
2675 HeapFree(GetProcessHeap(), 0, buf);
2678 if (NULL != pglXBindTexImageARB) {
2679 return pglXBindTexImageARB(object->display, object->drawable, iBuffer);
2685 * X11DRV_wglReleaseTexImageARB
2687 * WGL_ARB_render_texture: wglReleaseTexImageARB
2689 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2691 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2692 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2693 if (NULL == object) {
2694 SetLastError(ERROR_INVALID_HANDLE);
2697 if (!object->use_render_texture) {
2698 SetLastError(ERROR_INVALID_HANDLE);
2701 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2704 if (NULL != pglXReleaseTexImageARB) {
2705 return pglXReleaseTexImageARB(object->display, object->drawable, iBuffer);
2711 * X11DRV_wglGetExtensionsStringEXT
2713 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2715 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
2716 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2717 return WineGLInfo.wglExtensions;
2721 * X11DRV_wglGetSwapIntervalEXT
2723 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2725 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
2726 FIXME("(),stub!\n");
2727 return swap_interval;
2731 * X11DRV_wglSwapIntervalEXT
2733 * WGL_EXT_swap_control: wglSwapIntervalEXT
2735 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
2736 TRACE("(%d)\n", interval);
2737 swap_interval = interval;
2738 if (NULL != pglXSwapIntervalSGI) {
2739 return 0 == pglXSwapIntervalSGI(interval);
2741 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
2746 * X11DRV_wglAllocateMemoryNV
2748 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
2750 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
2751 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
2752 if (pglXAllocateMemoryNV == NULL)
2755 return pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
2759 * X11DRV_wglFreeMemoryNV
2761 * WGL_NV_vertex_array_range: wglFreeMemoryNV
2763 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
2764 TRACE("(%p)\n", pointer);
2765 if (pglXFreeMemoryNV == NULL)
2768 pglXFreeMemoryNV(pointer);
2772 * glxRequireVersion (internal)
2774 * Check if the supported GLX version matches requiredVersion.
2776 static BOOL glxRequireVersion(int requiredVersion)
2778 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2779 if(requiredVersion <= WineGLInfo.glxVersion[1])
2785 static BOOL glxRequireExtension(const char *requiredExtension)
2787 if (strstr(WineGLInfo.glxClientExtensions, requiredExtension) == NULL) {
2794 static BOOL register_extension(const WineGLExtension * ext)
2798 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
2799 WineGLExtensionList[WineGLExtensionListSize++] = ext;
2801 strcat(WineGLInfo.wglExtensions, " ");
2802 strcat(WineGLInfo.wglExtensions, ext->extName);
2804 TRACE("'%s'\n", ext->extName);
2806 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
2807 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
2812 static const WineGLExtension WGL_internal_functions =
2816 { "wglDisable", X11DRV_wglDisable },
2817 { "wglEnable", X11DRV_wglEnable },
2818 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
2819 { "wglIsEnabled", X11DRV_wglIsEnabled },
2820 { "wglScissor", X11DRV_wglScissor },
2821 { "wglViewport", X11DRV_wglViewport },
2826 static const WineGLExtension WGL_ARB_extensions_string =
2828 "WGL_ARB_extensions_string",
2830 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
2834 static const WineGLExtension WGL_ARB_make_current_read =
2836 "WGL_ARB_make_current_read",
2838 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
2839 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
2843 static const WineGLExtension WGL_ARB_multisample =
2845 "WGL_ARB_multisample",
2848 static const WineGLExtension WGL_ARB_pbuffer =
2852 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
2853 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
2854 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
2855 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
2856 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
2857 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
2861 static const WineGLExtension WGL_ARB_pixel_format =
2863 "WGL_ARB_pixel_format",
2865 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
2866 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
2867 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
2871 static const WineGLExtension WGL_ARB_render_texture =
2873 "WGL_ARB_render_texture",
2875 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
2876 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
2880 static const WineGLExtension WGL_EXT_extensions_string =
2882 "WGL_EXT_extensions_string",
2884 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
2888 static const WineGLExtension WGL_EXT_swap_control =
2890 "WGL_EXT_swap_control",
2892 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
2893 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
2897 static const WineGLExtension WGL_NV_vertex_array_range =
2899 "WGL_NV_vertex_array_range",
2901 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
2902 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
2907 * X11DRV_WineGL_LoadExtensions
2909 static void X11DRV_WineGL_LoadExtensions(void)
2911 WineGLInfo.wglExtensions[0] = 0;
2913 /* Load Wine internal functions */
2914 register_extension(&WGL_internal_functions);
2916 /* ARB Extensions */
2918 register_extension(&WGL_ARB_extensions_string);
2920 if (glxRequireVersion(3))
2921 register_extension(&WGL_ARB_make_current_read);
2923 if (glxRequireExtension("GLX_ARB_multisample"))
2924 register_extension(&WGL_ARB_multisample);
2926 /* In general pbuffer functionality requires support in the X-server. The functionality is
2927 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
2928 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
2929 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
2931 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
2932 * without support in the X-server (which other Mesa based drivers require).
2934 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
2935 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
2936 * is available pbuffers must be available too. */
2937 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
2938 register_extension(&WGL_ARB_pbuffer);
2940 register_extension(&WGL_ARB_pixel_format);
2942 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
2943 if (glxRequireExtension("GLX_ATI_render_texture") ||
2944 glxRequireExtension("GLX_ARB_render_texture") ||
2945 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation))
2946 register_extension(&WGL_ARB_render_texture);
2948 /* EXT Extensions */
2950 register_extension(&WGL_EXT_extensions_string);
2952 if (glxRequireExtension("GLX_SGI_swap_control"))
2953 register_extension(&WGL_EXT_swap_control);
2955 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
2956 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
2957 register_extension(&WGL_NV_vertex_array_range);
2961 static XID create_glxpixmap(X11DRV_PDEVICE *physDev)
2965 XVisualInfo template;
2970 /* Retrieve the visualid from our main visual which is the only visual we can use */
2971 template.visualid = XVisualIDFromVisual(visual);
2972 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
2974 ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
2976 wine_tsx11_unlock();
2977 TRACE("return %lx\n", ret);
2981 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
2987 if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
2988 ret = physDev->drawable; /* PBuffer */
2991 if(!physDev->bitmap->glxpixmap)
2992 physDev->bitmap->glxpixmap = create_glxpixmap(physDev);
2993 ret = physDev->bitmap->glxpixmap;
2997 ret = physDev->drawable;
3001 BOOL destroy_glxpixmap(XID glxpixmap)
3004 pglXDestroyGLXPixmap(gdi_display, glxpixmap);
3005 wine_tsx11_unlock();
3010 * X11DRV_SwapBuffers
3012 * Swap the buffers of this DC
3014 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev)
3016 GLXDrawable drawable;
3017 if (!has_opengl()) {
3018 ERR("No libGL on this box - disabling OpenGL support !\n");
3022 TRACE_(opengl)("(%p)\n", physDev);
3024 drawable = get_glxdrawable(physDev);
3026 pglXSwapBuffers(gdi_display, drawable);
3027 wine_tsx11_unlock();
3032 static long prev_time, frames;
3034 DWORD time = GetTickCount();
3036 /* every 1.5 seconds */
3037 if (time - prev_time > 1500) {
3038 TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
3047 /***********************************************************************
3048 * X11DRV_setup_opengl_visual
3050 * Setup the default visual used for OpenGL and Direct3D, and the desktop
3051 * window (if it exists). If OpenGL isn't available, the visual is simply
3052 * set to the default visual for the display
3054 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
3056 XVisualInfo *visual = NULL;
3059 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support,
3060 * D3D and some applications can make use of aux buffers.
3062 int visualProperties[][11] = {
3063 { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_AUX_BUFFERS, 1, None },
3064 { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_ALPHA_SIZE, 8, None },
3065 { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, GLX_STENCIL_SIZE, 8, None },
3066 { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, None },
3073 for (i = 0; i < sizeof(visualProperties)/sizeof(visualProperties[0]); ++i) {
3074 visual = pglXChooseVisual(display, DefaultScreen(display), visualProperties[i]);
3078 wine_tsx11_unlock();
3081 TRACE("Visual ID %lx Chosen\n", visual->visualid);
3083 WARN("No suitable visual found\n");
3088 #else /* no OpenGL includes */
3090 /***********************************************************************
3091 * ChoosePixelFormat (X11DRV.@)
3093 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
3094 const PIXELFORMATDESCRIPTOR *ppfd) {
3095 ERR("No OpenGL support compiled in.\n");
3100 /***********************************************************************
3101 * DescribePixelFormat (X11DRV.@)
3103 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
3106 PIXELFORMATDESCRIPTOR *ppfd) {
3107 ERR("No OpenGL support compiled in.\n");
3112 /***********************************************************************
3113 * GetPixelFormat (X11DRV.@)
3115 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
3116 ERR("No OpenGL support compiled in.\n");
3121 /***********************************************************************
3122 * SetPixelFormat (X11DRV.@)
3124 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
3126 const PIXELFORMATDESCRIPTOR *ppfd) {
3127 ERR("No OpenGL support compiled in.\n");
3132 /***********************************************************************
3133 * SwapBuffers (X11DRV.@)
3135 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
3136 ERR_(opengl)("No OpenGL support compiled in.\n");
3142 * X11DRV_wglCreateContext
3144 * For OpenGL32 wglCreateContext.
3146 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) {
3147 ERR_(opengl)("No OpenGL support compiled in.\n");
3152 * X11DRV_wglDeleteContext
3154 * For OpenGL32 wglDeleteContext.
3156 BOOL X11DRV_wglDeleteContext(HGLRC hglrc) {
3157 ERR_(opengl)("No OpenGL support compiled in.\n");
3162 * X11DRV_wglGetProcAddress
3164 * For OpenGL32 wglGetProcAddress.
3166 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
3167 ERR_(opengl)("No OpenGL support compiled in.\n");
3171 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *hDevice, void *hPbuffer)
3173 ERR_(opengl)("No OpenGL support compiled in.\n");
3177 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) {
3178 ERR_(opengl)("No OpenGL support compiled in.\n");
3183 * X11DRV_wglMakeCurrent
3185 * For OpenGL32 wglMakeCurrent.
3187 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
3188 ERR_(opengl)("No OpenGL support compiled in.\n");
3193 * X11DRV_wglShareLists
3195 * For OpenGL32 wglShaderLists.
3197 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
3198 ERR_(opengl)("No OpenGL support compiled in.\n");
3203 * X11DRV_wglUseFontBitmapsA
3205 * For OpenGL32 wglUseFontBitmapsA.
3207 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3209 ERR_(opengl)("No OpenGL support compiled in.\n");
3214 * X11DRV_wglUseFontBitmapsW
3216 * For OpenGL32 wglUseFontBitmapsW.
3218 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3220 ERR_(opengl)("No OpenGL support compiled in.\n");
3224 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
3229 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3234 BOOL destroy_glxpixmap(XID glxpixmap)
3239 #endif /* defined(HAVE_OPENGL) */