2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006-2009 Roderick Colenbrander
8 * Copyright 2006 Tomas Carnecky
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
34 #include "wine/library.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
51 #ifdef HAVE_GL_GLEXT_H
52 # include <GL/glext.h>
61 /* Redefines the constants */
62 #define CALLBACK __stdcall
63 #define WINAPI __stdcall
64 #define APIENTRY WINAPI
67 WINE_DECLARE_DEBUG_CHANNEL(fps);
69 typedef struct wine_glextension {
78 const char *glVersion;
79 const char *glExtensions;
83 const char *glxServerVersion;
84 const char *glxServerVendor;
85 const char *glxServerExtensions;
87 const char *glxClientVersion;
88 const char *glxClientVendor;
89 const char *glxClientExtensions;
91 const char *glxExtensions;
94 char wglExtensions[4096];
97 typedef struct wine_glpixelformat {
105 typedef struct wine_glcontext {
109 WineGLPixelFormat *fmt;
112 Drawable drawables[2];
113 BOOL refresh_drawables;
114 struct wine_glcontext *next;
115 struct wine_glcontext *prev;
118 typedef struct wine_glpbuffer {
121 WineGLPixelFormat* fmt;
127 int use_render_texture; /* This is also the internal texture format */
128 int texture_bind_target;
130 GLint texture_format;
131 GLuint texture_target;
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 void X11DRV_WineGL_LoadExtensions(void);
148 static BOOL glxRequireVersion(int requiredVersion);
149 static BOOL glxRequireExtension(const char *requiredExtension);
151 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
152 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
153 TRACE(" - dwFlags : ");
154 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
155 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
156 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
157 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
158 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
159 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
160 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
161 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
162 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
163 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
164 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
165 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
166 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
167 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
168 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
169 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
170 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
171 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
172 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
173 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
177 TRACE(" - iPixelType : ");
178 switch (ppfd->iPixelType) {
179 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
180 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
184 TRACE(" - Color : %d\n", ppfd->cColorBits);
185 TRACE(" - Red : %d\n", ppfd->cRedBits);
186 TRACE(" - Green : %d\n", ppfd->cGreenBits);
187 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
188 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
189 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
190 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
191 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
192 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
194 TRACE(" - iLayerType : ");
195 switch (ppfd->iLayerType) {
196 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
197 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
198 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
203 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
204 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
206 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
208 MAKE_FUNCPTR(glXChooseVisual)
209 MAKE_FUNCPTR(glXCopyContext)
210 MAKE_FUNCPTR(glXCreateContext)
211 MAKE_FUNCPTR(glXCreateGLXPixmap)
212 MAKE_FUNCPTR(glXGetCurrentContext)
213 MAKE_FUNCPTR(glXGetCurrentDrawable)
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(glXCreateNewContext)
234 MAKE_FUNCPTR(glXDestroyPbuffer)
235 MAKE_FUNCPTR(glXGetFBConfigAttrib)
236 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
237 MAKE_FUNCPTR(glXMakeContextCurrent)
238 MAKE_FUNCPTR(glXQueryDrawable)
239 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
242 static void* (*pglXGetProcAddressARB)(const GLubyte *);
243 static int (*pglXSwapIntervalSGI)(int);
245 /* ATI GLX Extensions */
246 static BOOL (*pglXBindTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
247 static BOOL (*pglXReleaseTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
248 static BOOL (*pglXDrawableAttribATI)(Display *dpy, GLXDrawable draw, const int *attribList);
250 /* NV GLX Extension */
251 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
252 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
254 /* MESA GLX Extensions */
255 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
257 /* Standard OpenGL */
258 MAKE_FUNCPTR(glBindTexture)
259 MAKE_FUNCPTR(glBitmap)
260 MAKE_FUNCPTR(glCopyTexSubImage1D)
261 MAKE_FUNCPTR(glCopyTexImage2D)
262 MAKE_FUNCPTR(glCopyTexSubImage2D)
263 MAKE_FUNCPTR(glDrawBuffer)
264 MAKE_FUNCPTR(glEndList)
265 MAKE_FUNCPTR(glGetError)
266 MAKE_FUNCPTR(glGetIntegerv)
267 MAKE_FUNCPTR(glGetString)
268 MAKE_FUNCPTR(glNewList)
269 MAKE_FUNCPTR(glPixelStorei)
270 MAKE_FUNCPTR(glReadPixels)
271 MAKE_FUNCPTR(glTexImage2D)
272 MAKE_FUNCPTR(glFinish)
273 MAKE_FUNCPTR(glFlush)
276 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
278 static BOOL infoInitialized = FALSE;
280 int screen = DefaultScreen(gdi_display);
281 Window win = RootWindow(gdi_display, screen);
283 XVisualInfo template;
286 GLXContext ctx = NULL;
290 infoInitialized = TRUE;
294 visual = DefaultVisual(gdi_display, screen);
295 template.visualid = XVisualIDFromVisual(visual);
296 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
298 WORD old_fs = wine_get_fs();
299 /* Create a GLX Context. Without one we can't query GL information */
300 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
301 if (wine_get_fs() != old_fs)
303 wine_set_fs( old_fs );
305 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
306 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
312 pglXMakeCurrent(gdi_display, win, ctx);
314 ERR(" couldn't initialize OpenGL, expect problems\n");
319 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
320 WineGLInfo.glExtensions = strdup((const char *) pglGetString(GL_EXTENSIONS));
322 /* Get the common GLX version supported by GLX client and server ( major/minor) */
323 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
325 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
326 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
327 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
329 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
330 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
331 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
333 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
334 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
336 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
337 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER));
338 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
339 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
340 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
341 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
342 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
343 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
347 pglXMakeCurrent(gdi_display, None, NULL);
348 pglXDestroyContext(gdi_display, ctx);
354 static BOOL has_opengl(void)
356 static int init_done;
357 static void *opengl_handle;
360 int error_base, event_base;
362 if (init_done) return (opengl_handle != NULL);
365 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
366 and include all dependencies */
367 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, buffer, sizeof(buffer));
368 if (opengl_handle == NULL)
370 ERR( "Failed to load libGL: %s\n", buffer );
371 ERR( "OpenGL support is disabled.\n");
375 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
376 if (pglXGetProcAddressARB == NULL) {
377 ERR("Could not find glXGetProcAddressARB in libGL, disabling OpenGL.\n");
381 #define LOAD_FUNCPTR(f) do if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) \
383 ERR( "%s not found in libGL, disabling OpenGL.\n", #f ); \
388 LOAD_FUNCPTR(glXChooseVisual);
389 LOAD_FUNCPTR(glXCopyContext);
390 LOAD_FUNCPTR(glXCreateContext);
391 LOAD_FUNCPTR(glXCreateGLXPixmap);
392 LOAD_FUNCPTR(glXGetCurrentContext);
393 LOAD_FUNCPTR(glXGetCurrentDrawable);
394 LOAD_FUNCPTR(glXDestroyContext);
395 LOAD_FUNCPTR(glXDestroyGLXPixmap);
396 LOAD_FUNCPTR(glXGetConfig);
397 LOAD_FUNCPTR(glXIsDirect);
398 LOAD_FUNCPTR(glXMakeCurrent);
399 LOAD_FUNCPTR(glXSwapBuffers);
400 LOAD_FUNCPTR(glXQueryExtension);
401 LOAD_FUNCPTR(glXQueryVersion);
402 LOAD_FUNCPTR(glXUseXFont);
405 LOAD_FUNCPTR(glXGetClientString);
406 LOAD_FUNCPTR(glXQueryExtensionsString);
407 LOAD_FUNCPTR(glXQueryServerString);
410 LOAD_FUNCPTR(glXCreatePbuffer);
411 LOAD_FUNCPTR(glXCreateNewContext);
412 LOAD_FUNCPTR(glXDestroyPbuffer);
413 LOAD_FUNCPTR(glXMakeContextCurrent);
414 LOAD_FUNCPTR(glXGetCurrentReadDrawable);
415 LOAD_FUNCPTR(glXGetFBConfigs);
417 /* Standard OpenGL calls */
418 LOAD_FUNCPTR(glBindTexture);
419 LOAD_FUNCPTR(glBitmap);
420 LOAD_FUNCPTR(glCopyTexSubImage1D);
421 LOAD_FUNCPTR(glCopyTexImage2D);
422 LOAD_FUNCPTR(glCopyTexSubImage2D);
423 LOAD_FUNCPTR(glDrawBuffer);
424 LOAD_FUNCPTR(glEndList);
425 LOAD_FUNCPTR(glGetError);
426 LOAD_FUNCPTR(glGetIntegerv);
427 LOAD_FUNCPTR(glGetString);
428 LOAD_FUNCPTR(glNewList);
429 LOAD_FUNCPTR(glPixelStorei);
430 LOAD_FUNCPTR(glReadPixels);
431 LOAD_FUNCPTR(glTexImage2D);
432 LOAD_FUNCPTR(glFinish);
433 LOAD_FUNCPTR(glFlush);
436 /* It doesn't matter if these fail. They'll only be used if the driver reports
437 the associated extension is available (and if a driver reports the extension
438 is available but fails to provide the functions, it's quite broken) */
439 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)
440 /* NV GLX Extension */
441 LOAD_FUNCPTR(glXAllocateMemoryNV);
442 LOAD_FUNCPTR(glXFreeMemoryNV);
445 if(!X11DRV_WineGL_InitOpenglInfo()) goto failed;
448 if (pglXQueryExtension(gdi_display, &error_base, &event_base)) {
449 TRACE("GLX is up and running error_base = %d\n", error_base);
452 ERR( "GLX extension is missing, disabling OpenGL.\n" );
456 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
457 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
460 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
461 * depends on the reported GLX client / server version and on the client / server extension list.
462 * Those don't have to be the same.
464 * In general the server GLX information lists the capabilities in case of indirect rendering.
465 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
466 * available and in that case the client GLX informat can be used.
467 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
468 * in the GLX version/extension list. When a program does this it works for certain for both
469 * direct and indirect rendering.
471 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
472 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
473 * extension list which causes this extension not to be listed. (Wine requires this extension).
474 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
475 * pbuffers is around.
477 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
478 * the ATI drivers and from then on use GLX client information for them.
481 if(glxRequireVersion(3)) {
482 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
483 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
484 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
485 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
486 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
487 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
488 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
489 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
491 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
492 * enable this function when the Xserver understand GLX 1.3 or newer
494 pglXQueryDrawable = NULL;
495 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
496 TRACE("Overriding ATI GLX capabilities!\n");
497 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
498 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
499 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
500 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
502 /* Use client GLX information in case of the ATI drivers. We override the
503 * capabilities over here and not somewhere else as ATI might better their
504 * life in the future. In case they release proper drivers this block of
505 * code won't be called. */
506 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
508 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
511 if(glxRequireExtension("GLX_ATI_render_texture")) {
512 use_render_texture_ati = 1;
513 pglXBindTexImageATI = pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageATI");
514 pglXReleaseTexImageATI = pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageATI");
515 pglXDrawableAttribATI = pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribATI");
518 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
519 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
522 X11DRV_WineGL_LoadExtensions();
528 wine_dlclose(opengl_handle, NULL, 0);
529 opengl_handle = NULL;
533 static inline Wine_GLContext *alloc_context(void)
537 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLContext))))
539 ret->next = context_list;
540 if (context_list) context_list->prev = ret;
546 static inline void free_context(Wine_GLContext *context)
548 if (context->next != NULL) context->next->prev = context->prev;
549 if (context->prev != NULL) context->prev->next = context->next;
550 else context_list = context->next;
552 if (context->vis) XFree(context->vis);
553 HeapFree(GetProcessHeap(), 0, context);
556 static inline BOOL is_valid_context( Wine_GLContext *ctx )
559 for (ptr = context_list; ptr; ptr = ptr->next) if (ptr == ctx) break;
560 return (ptr != NULL);
563 static int describeContext(Wine_GLContext* ctx) {
566 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
567 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
568 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
569 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
570 TRACE(" - VISUAL_ID 0x%x\n", tmp);
575 static int describeDrawable(Wine_GLContext* ctx, Drawable drawable) {
578 int attribList[3] = { GLX_FBCONFIG_ID, 0, None };
581 if (pglXQueryDrawable == NULL) {
582 /** glXQueryDrawable not available so returns not supported */
586 TRACE(" Drawable %p have :\n", (void*) drawable);
587 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &tmp);
588 TRACE(" - WIDTH as %d\n", tmp);
589 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &tmp);
590 TRACE(" - HEIGHT as %d\n", tmp);
591 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &tmp);
592 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
595 fbCfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribList, &nElements);
596 if (fbCfgs == NULL) {
600 pglXGetFBConfigAttrib(gdi_display, fbCfgs[0], GLX_VISUAL_ID, &tmp);
601 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
608 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
613 int nvfloatattrib = GLX_DONT_CARE;
618 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
619 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
620 while (iWGLAttr && 0 != iWGLAttr[cur]) {
621 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
623 switch (iWGLAttr[cur]) {
624 case WGL_AUX_BUFFERS_ARB:
625 pop = iWGLAttr[++cur];
626 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
627 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
629 case WGL_COLOR_BITS_ARB:
630 pop = iWGLAttr[++cur];
631 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
632 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
634 case WGL_BLUE_BITS_ARB:
635 pop = iWGLAttr[++cur];
636 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
637 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
639 case WGL_RED_BITS_ARB:
640 pop = iWGLAttr[++cur];
641 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
642 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
644 case WGL_GREEN_BITS_ARB:
645 pop = iWGLAttr[++cur];
646 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
647 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
649 case WGL_ALPHA_BITS_ARB:
650 pop = iWGLAttr[++cur];
651 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
652 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
654 case WGL_DEPTH_BITS_ARB:
655 pop = iWGLAttr[++cur];
656 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
657 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
659 case WGL_STENCIL_BITS_ARB:
660 pop = iWGLAttr[++cur];
661 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
662 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
664 case WGL_DOUBLE_BUFFER_ARB:
665 pop = iWGLAttr[++cur];
666 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
667 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
671 pop = iWGLAttr[++cur];
672 PUSH2(oGLXAttr, GLX_STEREO, pop);
673 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur, pop);
676 case WGL_PIXEL_TYPE_ARB:
677 pop = iWGLAttr[++cur];
678 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
680 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
681 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
682 /* This is the same as WGL_TYPE_RGBA_FLOAT_ATI but the GLX constants differ, only the ARB GLX one is widely supported so use that */
683 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
684 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT: pixelattrib = GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT; break ;
686 ERR("unexpected PixelType(%x)\n", pop);
691 case WGL_SUPPORT_GDI_ARB:
692 pop = iWGLAttr[++cur];
693 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
694 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
698 case WGL_DRAW_TO_BITMAP_ARB:
699 pop = iWGLAttr[++cur];
700 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
701 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
703 drawattrib |= GLX_PIXMAP_BIT;
707 case WGL_DRAW_TO_WINDOW_ARB:
708 pop = iWGLAttr[++cur];
709 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
710 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
712 drawattrib |= GLX_WINDOW_BIT;
716 case WGL_DRAW_TO_PBUFFER_ARB:
717 pop = iWGLAttr[++cur];
718 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
719 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
721 drawattrib |= GLX_PBUFFER_BIT;
725 case WGL_ACCELERATION_ARB:
726 case WGL_SUPPORT_OPENGL_ARB:
727 pop = iWGLAttr[++cur];
728 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
729 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
732 case WGL_PBUFFER_LARGEST_ARB:
733 pop = iWGLAttr[++cur];
734 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
735 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
738 case WGL_SAMPLE_BUFFERS_ARB:
739 pop = iWGLAttr[++cur];
740 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
741 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
744 case WGL_SAMPLES_ARB:
745 pop = iWGLAttr[++cur];
746 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
747 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
750 case WGL_TEXTURE_FORMAT_ARB:
751 case WGL_TEXTURE_TARGET_ARB:
752 case WGL_MIPMAP_TEXTURE_ARB:
753 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
754 pop = iWGLAttr[++cur];
756 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
758 if (use_render_texture_ati) {
759 /** nothing to do here */
761 else if (!use_render_texture_emulation) {
762 if (WGL_NO_TEXTURE_ARB != pop) {
763 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
764 return -1; /** error: don't support it */
766 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
767 drawattrib |= GLX_PBUFFER_BIT;
771 case WGL_FLOAT_COMPONENTS_NV:
772 nvfloatattrib = iWGLAttr[++cur];
773 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
775 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
776 case WGL_BIND_TO_TEXTURE_RGB_ARB:
777 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
778 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
779 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
780 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
781 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
782 pop = iWGLAttr[++cur];
783 /** cannot be converted, see direct handling on
784 * - wglGetPixelFormatAttribivARB
785 * TODO: wglChoosePixelFormat
788 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
789 pop = iWGLAttr[++cur];
790 PUSH2(oGLXAttr, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, pop);
791 TRACE("pAttr[%d] = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT: %x\n", cur, pop);
794 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
795 pop = iWGLAttr[++cur];
796 PUSH2(oGLXAttr, GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT, pop);
797 TRACE("pAttr[%d] = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT: %x\n", cur, pop);
800 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
808 WARN("Attempting double-buffered gdi format\n");
812 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, False);
815 /* Apply the OR'd drawable type bitmask now EVEN when WGL_DRAW_TO* is unset.
816 * It is needed in all cases because GLX_DRAWABLE_TYPE default to GLX_WINDOW_BIT. */
817 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
818 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
820 /* Set GLX_RENDER_TYPE all the time */
821 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
822 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
824 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
825 if(strstr(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
826 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
827 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
833 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
835 int render_type=0, render_type_bit;
836 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
837 switch(render_type_bit)
840 render_type = GLX_RGBA_TYPE;
842 case GLX_COLOR_INDEX_BIT:
843 render_type = GLX_COLOR_INDEX_TYPE;
845 case GLX_RGBA_FLOAT_BIT:
846 render_type = GLX_RGBA_FLOAT_TYPE;
848 case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT:
849 render_type = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
852 ERR("Unknown render_type: %x\n", render_type);
857 static WineGLPixelFormat *get_formats(Display *display, int *size_ret, int *onscreen_size_ret)
859 static WineGLPixelFormat *list;
860 static int size, onscreen_size;
862 int fmt_id, nCfgs, i, run;
864 XVisualInfo *visinfo;
869 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
870 if (NULL == cfgs || 0 == nCfgs) {
871 if(cfgs != NULL) XFree(cfgs);
873 ERR("glXChooseFBConfig returns NULL\n");
877 list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nCfgs*sizeof(WineGLPixelFormat));
879 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
880 * Do this as GLX doesn't guarantee that the list is sorted */
881 for(run=0; run < 2; run++)
883 for(i=0; i<nCfgs; i++) {
884 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
885 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
887 /* The first run we only add onscreen formats (ones which have an associated X Visual).
888 * The second run we only set offscreen formats. */
891 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
892 * The contents is copied to the destination using XCopyArea. For the copying to work
893 * the depth of the source and destination window should be the same. In general this should
894 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
895 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
896 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
897 * list formats with the same depth. */
898 if(visinfo->depth != screen_depth)
901 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
902 list[size].iPixelFormat = size+1; /* The index starts at 1 */
903 list[size].fbconfig = cfgs[i];
904 list[size].fmt_id = fmt_id;
905 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
906 list[size].offscreenOnly = FALSE;
910 } else if(run && !visinfo) {
911 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, size+1, i);
912 list[size].iPixelFormat = size+1; /* The index starts at 1 */
913 list[size].fbconfig = cfgs[i];
914 list[size].fmt_id = fmt_id;
915 list[size].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
916 list[size].offscreenOnly = TRUE;
922 if(cfgs != NULL) XFree(cfgs);
925 if (size_ret) *size_ret = size;
926 if (onscreen_size_ret) *onscreen_size_ret = onscreen_size;
931 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
932 * In our WGL implementation we only support a subset of these formats namely the format of
933 * Wine's main visual and offscreen formats (if they are available).
934 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
935 * and it returns the number of supported WGL formats in fmt_count.
937 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count)
939 WineGLPixelFormat *list, *res = NULL;
940 int size, onscreen_size;
942 if (!(list = get_formats(display, &size, &onscreen_size ))) return NULL;
944 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
945 * iPixelFormat in case of probing the number of pixelformats.
947 if((iPixelFormat > 0) && (iPixelFormat <= size) &&
948 (!list[iPixelFormat-1].offscreenOnly || AllowOffscreen)) {
949 res = &list[iPixelFormat-1];
950 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res->fbconfig, iPixelFormat);
956 *fmt_count = onscreen_size;
958 TRACE("Number of returned pixelformats=%d\n", *fmt_count);
963 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
964 static WineGLPixelFormat* ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id)
966 WineGLPixelFormat *list;
969 if (!(list = get_formats(display, &size, NULL ))) return NULL;
971 for(i=0; i<size; i++) {
972 if(list[i].fmt_id == fmt_id) {
973 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", list[i].iPixelFormat, fmt_id);
977 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id);
981 int pixelformat_from_fbconfig_id(XID fbconfig_id)
983 WineGLPixelFormat *fmt;
985 if (!fbconfig_id) return 0;
987 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id);
989 return fmt->iPixelFormat;
990 /* This will happen on hwnds without a pixel format set; it's ok */
995 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
996 void mark_drawable_dirty(Drawable old, Drawable new)
999 for (ctx = context_list; ctx; ctx = ctx->next) {
1000 if (old == ctx->drawables[0]) {
1001 ctx->drawables[0] = new;
1002 ctx->refresh_drawables = TRUE;
1004 if (old == ctx->drawables[1]) {
1005 ctx->drawables[1] = new;
1006 ctx->refresh_drawables = TRUE;
1011 /* Given the current context, make sure its drawable is sync'd */
1012 static inline void sync_context(Wine_GLContext *context)
1014 if(context && context->refresh_drawables) {
1015 if (glxRequireVersion(3))
1016 pglXMakeContextCurrent(gdi_display, context->drawables[0],
1017 context->drawables[1], context->ctx);
1019 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
1020 context->refresh_drawables = FALSE;
1025 static GLXContext create_glxcontext(Display *display, Wine_GLContext *context, GLXContext shareList, BOOL direct)
1029 ctx = pglXCreateContext(gdi_display, context->vis, shareList, direct);
1030 else /* Create a GLX Context for a pbuffer */
1031 ctx = pglXCreateNewContext(gdi_display, context->fmt->fbconfig, context->fmt->render_type, shareList, direct);
1037 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
1039 return pglXCreateGLXPixmap(display, vis, parent);
1043 static XID create_bitmap_glxpixmap(X11DRV_PDEVICE *physDev, WineGLPixelFormat *fmt)
1050 vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1052 if(vis->depth == physDev->bitmap->pixmap_depth)
1053 ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
1056 wine_tsx11_unlock();
1057 TRACE("return %lx\n", ret);
1062 * X11DRV_ChoosePixelFormat
1064 * Equivalent to glXChooseVisual.
1066 int CDECL X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
1067 const PIXELFORMATDESCRIPTOR *ppfd) {
1068 WineGLPixelFormat *list;
1073 int bestFormat = -1;
1074 int bestDBuffer = -1;
1075 int bestStereo = -1;
1079 int bestStencil = -1;
1082 if (!has_opengl()) return 0;
1084 if (TRACE_ON(wgl)) {
1085 TRACE("(%p,%p)\n", physDev, ppfd);
1087 dump_PIXELFORMATDESCRIPTOR(ppfd);
1090 if (!(list = get_formats(gdi_display, NULL, &onscreen_size ))) return 0;
1093 for(i=0; i<onscreen_size; i++)
1097 int alpha=0, color=0, depth=0, stencil=0, aux=0;
1098 WineGLPixelFormat *fmt = &list[i];
1101 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1102 if (value & GLX_RGBA_BIT)
1103 iPixelType = PFD_TYPE_RGBA;
1105 iPixelType = PFD_TYPE_COLORINDEX;
1107 if (ppfd->iPixelType != iPixelType)
1109 TRACE("pixel type mismatch for iPixelFormat=%d\n", i+1);
1113 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1114 if (value) dwFlags |= PFD_DOUBLEBUFFER;
1115 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value);
1116 if (value) dwFlags |= PFD_STEREO;
1117 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &color); /* cColorBits */
1118 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &alpha); /* cAlphaBits */
1119 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &depth); /* cDepthBits */
1120 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &stencil); /* cStencilBits */
1121 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &aux); /* cAuxBuffers */
1123 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1124 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1125 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1126 * formats without the given flag set.
1127 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1128 * has indicated that a format without stereo is returned when stereo is unavailable.
1129 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1130 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1132 * To summarize the following is most likely the correct behavior:
1133 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1134 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1135 * stereo don't care -> it doesn't matter whether we get stereo or not
1137 * In Wine we will treat no-stereo the same way as don't care because it makes
1138 * format selection even more complicated and second drivers with Stereo advertise
1139 * each format twice anyway.
1142 /* Doublebuffer, see the comments above */
1143 if( !(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) ) {
1144 if( ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) &&
1145 ((dwFlags & PFD_DOUBLEBUFFER) == (ppfd->dwFlags & PFD_DOUBLEBUFFER)) )
1147 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1148 bestStereo = dwFlags & PFD_STEREO;
1152 bestStencil = stencil;
1157 if(bestDBuffer != -1 && (dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer)
1161 /* Stereo, see the comments above. */
1162 if( !(ppfd->dwFlags & PFD_STEREO_DONTCARE) ) {
1163 if( ((ppfd->dwFlags & PFD_STEREO) != bestStereo) &&
1164 ((dwFlags & PFD_STEREO) == (ppfd->dwFlags & PFD_STEREO)) )
1166 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1167 bestStereo = dwFlags & PFD_STEREO;
1171 bestStencil = stencil;
1176 if(bestStereo != -1 && (dwFlags & PFD_STEREO) != bestStereo)
1180 /* Below we will do a number of checks to select the 'best' pixelformat.
1181 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1182 * The code works by trying to match the most important options as close as possible.
1183 * When a reasonable format is found, we will try to match more options.
1184 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1185 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1186 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1189 if(ppfd->cColorBits) {
1190 if( ((ppfd->cColorBits > bestColor) && (color > bestColor)) ||
1191 ((color >= ppfd->cColorBits) && (color < bestColor)) )
1193 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1194 bestStereo = dwFlags & PFD_STEREO;
1198 bestStencil = stencil;
1202 } else if(bestColor != color) { /* Do further checks if the format is compatible */
1203 TRACE("color mismatch for iPixelFormat=%d\n", i+1);
1209 if(ppfd->cAlphaBits) {
1210 if( ((ppfd->cAlphaBits > bestAlpha) && (alpha > bestAlpha)) ||
1211 ((alpha >= ppfd->cAlphaBits) && (alpha < bestAlpha)) )
1213 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1214 bestStereo = dwFlags & PFD_STEREO;
1218 bestStencil = stencil;
1222 } else if(bestAlpha != alpha) {
1223 TRACE("alpha mismatch for iPixelFormat=%d\n", i+1);
1229 if(ppfd->cDepthBits) {
1230 if( ((ppfd->cDepthBits > bestDepth) && (depth > bestDepth)) ||
1231 ((depth >= ppfd->cDepthBits) && (depth < bestDepth)) )
1233 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1234 bestStereo = dwFlags & PFD_STEREO;
1238 bestStencil = stencil;
1242 } else if(bestDepth != depth) {
1243 TRACE("depth mismatch for iPixelFormat=%d\n", i+1);
1249 if(ppfd->cStencilBits) {
1250 if( ((ppfd->cStencilBits > bestStencil) && (stencil > bestStencil)) ||
1251 ((stencil >= ppfd->cStencilBits) && (stencil < bestStencil)) )
1253 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1254 bestStereo = dwFlags & PFD_STEREO;
1258 bestStencil = stencil;
1262 } else if(bestStencil != stencil) {
1263 TRACE("stencil mismatch for iPixelFormat=%d\n", i+1);
1269 if(ppfd->cAuxBuffers) {
1270 if( ((ppfd->cAuxBuffers > bestAux) && (aux > bestAux)) ||
1271 ((aux >= ppfd->cAuxBuffers) && (aux < bestAux)) )
1273 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1274 bestStereo = dwFlags & PFD_STEREO;
1278 bestStencil = stencil;
1282 } else if(bestAux != aux) {
1283 TRACE("aux mismatch for iPixelFormat=%d\n", i+1);
1289 if(bestFormat == -1) {
1290 TRACE("No matching mode was found returning 0\n");
1294 ret = bestFormat+1; /* the return value should be a 1-based index */
1295 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret, list[bestFormat].fmt_id);
1298 wine_tsx11_unlock();
1303 * X11DRV_DescribePixelFormat
1305 * Get the pixel-format descriptor associated to the given id
1307 int CDECL X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
1310 PIXELFORMATDESCRIPTOR *ppfd) {
1311 /*XVisualInfo *vis;*/
1314 WineGLPixelFormat *fmt;
1318 if (!has_opengl()) return 0;
1320 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
1322 /* 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 */
1323 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_count);
1325 /* The application is only querying the number of pixelformats */
1327 } else if(fmt == NULL) {
1328 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1332 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1333 ERR("Wrong structure size !\n");
1334 /* Should set error */
1340 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1341 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1344 /* These flags are always the same... */
1345 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1346 /* Now the flags extracted from the Visual */
1350 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_X_RENDERABLE, &value);
1352 ppfd->dwFlags |= PFD_SUPPORT_GDI;
1354 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1355 if(value & GLX_WINDOW_BIT)
1356 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1357 if(value & GLX_PIXMAP_BIT)
1358 ppfd->dwFlags |= PFD_DRAW_TO_BITMAP;
1360 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_CONFIG_CAVEAT, &value);
1361 if(value == GLX_SLOW_CONFIG)
1362 ppfd->dwFlags |= PFD_GENERIC_ACCELERATED;
1364 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1366 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1367 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1369 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1372 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1373 if (value & GLX_RGBA_BIT)
1374 ppfd->iPixelType = PFD_TYPE_RGBA;
1376 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1379 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1380 ppfd->cColorBits = value;
1382 /* Red, green, blue and alpha bits / shifts */
1383 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1384 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1385 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1386 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1387 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1389 ppfd->cRedBits = rb;
1390 ppfd->cRedShift = gb + bb + ab;
1391 ppfd->cBlueBits = bb;
1392 ppfd->cBlueShift = ab;
1393 ppfd->cGreenBits = gb;
1394 ppfd->cGreenShift = bb + ab;
1395 ppfd->cAlphaBits = ab;
1396 ppfd->cAlphaShift = 0;
1399 ppfd->cRedShift = 0;
1400 ppfd->cBlueBits = 0;
1401 ppfd->cBlueShift = 0;
1402 ppfd->cGreenBits = 0;
1403 ppfd->cGreenShift = 0;
1404 ppfd->cAlphaBits = 0;
1405 ppfd->cAlphaShift = 0;
1408 /* Accum RGBA bits */
1409 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1410 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1411 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1412 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1414 ppfd->cAccumBits = rb+gb+bb+ab;
1415 ppfd->cAccumRedBits = rb;
1416 ppfd->cAccumGreenBits = gb;
1417 ppfd->cAccumBlueBits = bb;
1418 ppfd->cAccumAlphaBits = ab;
1421 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1422 ppfd->cAuxBuffers = value;
1425 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1426 ppfd->cDepthBits = value;
1429 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1430 ppfd->cStencilBits = value;
1432 wine_tsx11_unlock();
1434 ppfd->iLayerType = PFD_MAIN_PLANE;
1436 if (TRACE_ON(wgl)) {
1437 dump_PIXELFORMATDESCRIPTOR(ppfd);
1444 * X11DRV_GetPixelFormat
1446 * Get the pixel-format id used by this DC
1448 int CDECL X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
1449 WineGLPixelFormat *fmt;
1451 TRACE("(%p)\n", physDev);
1453 if (!physDev->current_pf) return 0; /* not set yet */
1455 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physDev->current_pf, TRUE, &tmp);
1458 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev->current_pf);
1461 else if(fmt->offscreenOnly)
1463 /* Offscreen formats can't be used with traditional WGL calls.
1464 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1465 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt->iPixelFormat);
1469 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1470 return physDev->current_pf;
1473 /* This function is the core of X11DRV_SetPixelFormat and X11DRV_SetPixelFormatWINE.
1474 * Both functions are the same except that X11DRV_SetPixelFormatWINE allows you to
1475 * set the pixel format multiple times. */
1476 static BOOL internal_SetPixelFormat(X11DRV_PDEVICE *physDev,
1478 const PIXELFORMATDESCRIPTOR *ppfd) {
1479 WineGLPixelFormat *fmt;
1483 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1484 if(get_glxdrawable(physDev) == root_window)
1486 ERR("Invalid operation on root_window\n");
1490 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1491 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
1493 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1498 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1499 wine_tsx11_unlock();
1501 hwnd = WindowFromDC(physDev->hdc);
1503 if(!(value&GLX_WINDOW_BIT)) {
1504 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1508 if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, (WPARAM)fmt->fmt_id, 0)) {
1509 ERR("Couldn't set format of the window, returning failure\n");
1513 else if(physDev->bitmap) {
1514 if(!(value&GLX_PIXMAP_BIT)) {
1515 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat);
1519 physDev->bitmap->glxpixmap = create_bitmap_glxpixmap(physDev, fmt);
1520 if(!physDev->bitmap->glxpixmap) {
1521 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat);
1526 FIXME("called on a non-window, non-bitmap object?\n");
1529 physDev->current_pf = iPixelFormat;
1531 if (TRACE_ON(wgl)) {
1535 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1537 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1539 TRACE(" FBConfig have :\n");
1540 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1541 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1542 TRACE(" - VISUAL_ID 0x%x\n", value);
1543 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1544 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1546 wine_tsx11_unlock();
1553 * X11DRV_SetPixelFormat
1555 * Set the pixel-format id used by this DC
1557 BOOL CDECL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
1559 const PIXELFORMATDESCRIPTOR *ppfd) {
1560 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1562 if (!has_opengl()) return FALSE;
1564 if(physDev->current_pf) /* cannot change it if already set */
1565 return (physDev->current_pf == iPixelFormat);
1567 return internal_SetPixelFormat(physDev, iPixelFormat, ppfd);
1571 * X11DRV_wglCopyContext
1573 * For OpenGL32 wglCopyContext.
1575 BOOL CDECL X11DRV_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask) {
1576 Wine_GLContext *src = (Wine_GLContext*)hglrcSrc;
1577 Wine_GLContext *dst = (Wine_GLContext*)hglrcDst;
1579 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc, hglrcDst, mask);
1581 /* There is a slight difference in the way GL contexts share display lists in WGL and GLX.
1582 * In case of GLX you need to specify this at context creation time but in case of WGL you
1583 * do this using wglShareLists which you can call after creating the context.
1584 * To emulate WGL we try to delay the creation of the context until wglShareLists or wglMakeCurrent.
1585 * Up to now that works fine.
1587 * The delayed GLX context creation could cause issues for wglCopyContext as it might get called
1588 * when there is no GLX context yet. The chance this will cause problems is small as at the time of
1589 * writing Wine has had OpenGL support for more than 7 years and this function has remained a stub
1592 if(!src->ctx || !dst->ctx) {
1593 /* NOTE: As a special case, if both GLX contexts are NULL, that means
1594 * neither WGL context was made current. In that case, both contexts
1595 * are in a default state, so any copy would no-op.
1597 if(!src->ctx && !dst->ctx) {
1598 TRACE("No source or destination contexts set. No-op.\n");
1603 DWORD type = GetObjectType(src->hdc);
1605 src->ctx = create_glxcontext(gdi_display, src, NULL, type == OBJ_MEMDC ? False : True);
1606 TRACE(" created a delayed OpenGL context (%p)\n", src->ctx);
1608 else if (!dst->ctx) {
1609 DWORD type = GetObjectType(dst->hdc);
1611 dst->ctx = create_glxcontext(gdi_display, dst, NULL, type == OBJ_MEMDC ? False : True);
1612 TRACE(" created a delayed OpenGL context (%p)\n", dst->ctx);
1618 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1619 wine_tsx11_unlock();
1621 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1626 * X11DRV_wglCreateContext
1628 * For OpenGL32 wglCreateContext.
1630 HGLRC CDECL X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
1632 Wine_GLContext *ret;
1633 WineGLPixelFormat *fmt;
1634 int hdcPF = physDev->current_pf;
1636 HDC hdc = physDev->hdc;
1638 TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1640 if (!has_opengl()) return 0;
1642 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, TRUE /* Offscreen */, &fmt_count);
1643 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1644 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1645 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1646 * If this fails something is very wrong on the system. */
1648 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF);
1649 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1653 /* The context will be allocated in the wglMakeCurrent call */
1655 ret = alloc_context();
1656 wine_tsx11_unlock();
1661 ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1663 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1668 * X11DRV_wglDeleteContext
1670 * For OpenGL32 wglDeleteContext.
1672 BOOL CDECL X11DRV_wglDeleteContext(HGLRC hglrc)
1674 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1677 TRACE("(%p)\n", hglrc);
1679 if (!has_opengl()) return 0;
1682 /* A game (Half Life not to name it) deletes twice the same context,
1683 * so make sure it is valid first */
1684 if (is_valid_context( ctx ))
1686 if (ctx->ctx) pglXDestroyContext(gdi_display, ctx->ctx);
1691 WARN("Error deleting context !\n");
1692 SetLastError(ERROR_INVALID_HANDLE);
1695 wine_tsx11_unlock();
1701 * X11DRV_wglGetCurrentReadDCARB
1703 * For OpenGL32 wglGetCurrentReadDCARB.
1705 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1708 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1710 if (ctx) ret = ctx->read_hdc;
1712 TRACE(" returning %p (GL drawable %lu)\n", ret, ctx ? ctx->drawables[1] : 0);
1717 * X11DRV_wglGetProcAddress
1719 * For OpenGL32 wglGetProcAddress.
1721 PROC CDECL X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1724 const WineGLExtension *ext;
1726 int padding = 32 - strlen(lpszProc);
1730 if (!has_opengl()) return NULL;
1732 /* Check the table of WGL extensions to see if we need to return a WGL extension
1733 * or a function pointer to a native OpenGL function. */
1734 if(strncmp(lpszProc, "wgl", 3) != 0) {
1735 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1737 TRACE("('%s'):%*s", lpszProc, padding, " ");
1738 for (i = 0; i < WineGLExtensionListSize; ++i) {
1739 ext = WineGLExtensionList[i];
1740 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1741 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1742 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1743 return ext->extEntryPoints[j].funcAddress;
1749 WARN("(%s) - not found\n", lpszProc);
1754 * X11DRV_wglMakeCurrent
1756 * For OpenGL32 wglMakeCurrent.
1758 BOOL CDECL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
1760 HDC hdc = physDev->hdc;
1761 DWORD type = GetObjectType(hdc);
1762 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1764 TRACE("(%p,%p)\n", hdc, hglrc);
1766 if (!has_opengl()) return FALSE;
1769 if (hglrc == NULL) {
1770 ret = pglXMakeCurrent(gdi_display, None, NULL);
1771 NtCurrentTeb()->glContext = NULL;
1772 } else if (ctx->fmt->iPixelFormat != physDev->current_pf) {
1773 WARN( "mismatched pixel format hdc %p %u ctx %p %u\n",
1774 hdc, physDev->current_pf, ctx, ctx->fmt->iPixelFormat );
1775 SetLastError( ERROR_INVALID_PIXEL_FORMAT );
1778 Drawable drawable = get_glxdrawable(physDev);
1779 if (ctx->ctx == NULL) {
1780 /* The describe lines below are for debugging purposes only */
1781 if (TRACE_ON(wgl)) {
1782 describeDrawable(ctx, drawable);
1783 describeContext(ctx);
1786 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1787 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1789 TRACE(" Creating GLX Context\n");
1790 ctx->ctx = create_glxcontext(gdi_display, ctx, NULL, type == OBJ_MEMDC ? False : True);
1791 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1793 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display, (void*) drawable, ctx->ctx);
1794 ret = pglXMakeCurrent(gdi_display, drawable, ctx->ctx);
1795 NtCurrentTeb()->glContext = ctx;
1799 ctx->read_hdc = hdc;
1800 ctx->drawables[0] = drawable;
1801 ctx->drawables[1] = drawable;
1802 ctx->refresh_drawables = FALSE;
1804 if (type == OBJ_MEMDC)
1806 ctx->do_escape = TRUE;
1807 pglDrawBuffer(GL_FRONT_LEFT);
1811 wine_tsx11_unlock();
1812 TRACE(" returning %s\n", (ret ? "True" : "False"));
1817 * X11DRV_wglMakeContextCurrentARB
1819 * For OpenGL32 wglMakeContextCurrentARB
1821 BOOL CDECL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* pDrawDev, X11DRV_PDEVICE* pReadDev, HGLRC hglrc)
1824 int indirect = (GetObjectType(pDrawDev->hdc) == OBJ_MEMDC);
1826 TRACE("(%p,%p,%p)\n", pDrawDev, pReadDev, hglrc);
1828 if (!has_opengl()) return 0;
1831 if (hglrc == NULL) {
1832 ret = pglXMakeCurrent(gdi_display, None, NULL);
1833 NtCurrentTeb()->glContext = NULL;
1835 if (NULL == pglXMakeContextCurrent) {
1838 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1839 Drawable d_draw = get_glxdrawable(pDrawDev);
1840 Drawable d_read = get_glxdrawable(pReadDev);
1842 if (ctx->ctx == NULL) {
1843 ctx->ctx = create_glxcontext(gdi_display, ctx, NULL, !indirect);
1844 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1846 ctx->hdc = pDrawDev->hdc;
1847 ctx->read_hdc = pReadDev->hdc;
1848 ctx->drawables[0] = d_draw;
1849 ctx->drawables[1] = d_read;
1850 ctx->refresh_drawables = FALSE;
1851 ret = pglXMakeContextCurrent(gdi_display, d_draw, d_read, ctx->ctx);
1852 NtCurrentTeb()->glContext = ctx;
1855 wine_tsx11_unlock();
1857 TRACE(" returning %s\n", (ret ? "True" : "False"));
1862 * X11DRV_wglShareLists
1864 * For OpenGL32 wglShareLists.
1866 BOOL CDECL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
1867 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1868 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1870 TRACE("(%p, %p)\n", org, dest);
1872 if (!has_opengl()) return FALSE;
1874 if (NULL != dest && dest->ctx != NULL) {
1875 ERR("Could not share display lists, context already created !\n");
1878 if (org->ctx == NULL) {
1879 int indirect = (GetObjectType(org->hdc) == OBJ_MEMDC);
1881 describeContext(org);
1883 org->ctx = create_glxcontext(gdi_display, org, NULL, !indirect);
1884 wine_tsx11_unlock();
1885 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org->ctx, org);
1888 int indirect = (GetObjectType(dest->hdc) == OBJ_MEMDC);
1890 describeContext(dest);
1891 dest->ctx = create_glxcontext(gdi_display, dest, org->ctx, !indirect);
1892 wine_tsx11_unlock();
1893 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1900 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
1902 /* We are running using client-side rendering fonts... */
1904 unsigned int glyph, size = 0;
1905 void *bitmap = NULL, *gl_bitmap = NULL;
1909 pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1910 pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1911 wine_tsx11_unlock();
1913 for (glyph = first; glyph < first + count; glyph++) {
1914 static const MAT2 identity = { {0,1},{0,0},{0,0},{0,1} };
1915 unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, &identity);
1916 unsigned int height, width_int;
1918 TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
1919 if (needed_size == GDI_ERROR) {
1920 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size);
1923 TRACE(" - needed size : %d\n", needed_size);
1926 if (needed_size > size) {
1928 HeapFree(GetProcessHeap(), 0, bitmap);
1929 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1930 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1931 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1933 if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, &identity) == GDI_ERROR)
1935 if (TRACE_ON(wgl)) {
1936 unsigned int height, width, bitmask;
1937 unsigned char *bitmap_ = bitmap;
1939 TRACE(" - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
1940 TRACE(" - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
1941 TRACE(" - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
1942 if (needed_size != 0) {
1943 TRACE(" - bitmap :\n");
1944 for (height = 0; height < gm.gmBlackBoxY; height++) {
1946 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
1951 if (*bitmap_ & bitmask)
1956 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
1962 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1963 * glyph for it to be drawn properly.
1965 if (needed_size != 0) {
1966 width_int = (gm.gmBlackBoxX + 31) / 32;
1967 for (height = 0; height < gm.gmBlackBoxY; height++) {
1969 for (width = 0; width < width_int; width++) {
1970 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
1971 ((int *) bitmap)[height * width_int + width];
1977 pglNewList(listBase++, GL_COMPILE);
1978 if (needed_size != 0) {
1979 pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
1980 0 - gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - gm.gmptGlyphOrigin.y,
1981 gm.gmCellIncX, gm.gmCellIncY,
1984 /* This is the case of 'empty' glyphs like the space character */
1985 pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
1988 wine_tsx11_unlock();
1992 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1993 wine_tsx11_unlock();
1995 HeapFree(GetProcessHeap(), 0, bitmap);
1996 HeapFree(GetProcessHeap(), 0, gl_bitmap);
2001 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
2002 wine_tsx11_unlock();
2004 HeapFree(GetProcessHeap(), 0, bitmap);
2005 HeapFree(GetProcessHeap(), 0, gl_bitmap);
2010 * X11DRV_wglUseFontBitmapsA
2012 * For OpenGL32 wglUseFontBitmapsA.
2014 BOOL CDECL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
2016 Font fid = physDev->font;
2018 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
2020 if (!has_opengl()) return FALSE;
2023 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineA);
2027 /* I assume that the glyphs are at the same position for X and for Windows */
2028 pglXUseXFont(fid, first, count, listBase);
2029 wine_tsx11_unlock();
2034 * X11DRV_wglUseFontBitmapsW
2036 * For OpenGL32 wglUseFontBitmapsW.
2038 BOOL CDECL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
2040 Font fid = physDev->font;
2042 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
2044 if (!has_opengl()) return FALSE;
2047 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineW);
2050 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
2053 /* I assume that the glyphs are at the same position for X and for Windows */
2054 pglXUseXFont(fid, first, count, listBase);
2055 wine_tsx11_unlock();
2059 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2060 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params)
2067 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2069 pglGetIntegerv(pname, params);
2071 * if we cannot find a Wine Context
2072 * we only have the default wine desktop context,
2073 * so if we have only a 24 depth say we have 32
2075 if (!ctx && *params == 24) {
2078 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
2083 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2085 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_ALPHA_SIZE, params);
2086 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params);
2090 pglGetIntegerv(pname, params);
2093 wine_tsx11_unlock();
2096 void flush_gl_drawable(X11DRV_PDEVICE *physDev)
2100 if (!physDev->gl_copy)
2103 w = physDev->dc_rect.right - physDev->dc_rect.left;
2104 h = physDev->dc_rect.bottom - physDev->dc_rect.top;
2106 if(w > 0 && h > 0) {
2107 Drawable src = physDev->pixmap;
2108 if(!src) src = physDev->gl_drawable;
2110 /* The GL drawable may be lagged behind if we don't flush first, so
2111 * flush the display make sure we copy up-to-date data */
2113 XFlush(gdi_display);
2114 XSetFunction(gdi_display, physDev->gc, GXcopy);
2115 XCopyArea(gdi_display, src, physDev->drawable, physDev->gc, 0, 0, w, h,
2116 physDev->dc_rect.left, physDev->dc_rect.top);
2117 wine_tsx11_unlock();
2122 static void WINAPI X11DRV_wglFinish(void)
2124 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2125 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2130 wine_tsx11_unlock();
2131 if (ctx) ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2134 static void WINAPI X11DRV_wglFlush(void)
2136 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2137 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2142 wine_tsx11_unlock();
2143 if (ctx) ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2147 * X11DRV_wglGetExtensionsStringARB
2149 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2151 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
2152 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2153 return WineGLInfo.wglExtensions;
2157 * X11DRV_wglCreatePbufferARB
2159 * WGL_ARB_pbuffer: wglCreatePbufferARB
2161 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
2163 Wine_GLPBuffer* object = NULL;
2164 WineGLPixelFormat *fmt = NULL;
2169 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2171 if (0 >= iPixelFormat) {
2172 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
2173 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2174 return NULL; /* unexpected error */
2177 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2178 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nCfgs);
2180 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
2181 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2182 goto create_failed; /* unexpected error */
2185 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
2186 if (NULL == object) {
2187 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2188 goto create_failed; /* unexpected error */
2191 object->display = gdi_display;
2192 object->width = iWidth;
2193 object->height = iHeight;
2196 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2197 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2198 while (piAttribList && 0 != *piAttribList) {
2200 switch (*piAttribList) {
2201 case WGL_PBUFFER_LARGEST_ARB: {
2203 attr_v = *piAttribList;
2204 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2205 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2209 case WGL_TEXTURE_FORMAT_ARB: {
2211 attr_v = *piAttribList;
2212 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2213 if (use_render_texture_ati) {
2216 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2217 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
2218 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
2220 SetLastError(ERROR_INVALID_DATA);
2223 object->use_render_texture = 1;
2224 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
2226 if (WGL_NO_TEXTURE_ARB == attr_v) {
2227 object->use_render_texture = 0;
2229 if (!use_render_texture_emulation) {
2230 SetLastError(ERROR_INVALID_DATA);
2234 case WGL_TEXTURE_RGB_ARB:
2235 object->use_render_texture = GL_RGB;
2236 object->texture_bpp = 3;
2237 object->texture_format = GL_RGB;
2238 object->texture_type = GL_UNSIGNED_BYTE;
2240 case WGL_TEXTURE_RGBA_ARB:
2241 object->use_render_texture = GL_RGBA;
2242 object->texture_bpp = 4;
2243 object->texture_format = GL_RGBA;
2244 object->texture_type = GL_UNSIGNED_BYTE;
2247 /* WGL_FLOAT_COMPONENTS_NV */
2248 case WGL_TEXTURE_FLOAT_R_NV:
2249 object->use_render_texture = GL_FLOAT_R_NV;
2250 object->texture_bpp = 4;
2251 object->texture_format = GL_RED;
2252 object->texture_type = GL_FLOAT;
2254 case WGL_TEXTURE_FLOAT_RG_NV:
2255 object->use_render_texture = GL_FLOAT_RG_NV;
2256 object->texture_bpp = 8;
2257 object->texture_format = GL_LUMINANCE_ALPHA;
2258 object->texture_type = GL_FLOAT;
2260 case WGL_TEXTURE_FLOAT_RGB_NV:
2261 object->use_render_texture = GL_FLOAT_RGB_NV;
2262 object->texture_bpp = 12;
2263 object->texture_format = GL_RGB;
2264 object->texture_type = GL_FLOAT;
2266 case WGL_TEXTURE_FLOAT_RGBA_NV:
2267 object->use_render_texture = GL_FLOAT_RGBA_NV;
2268 object->texture_bpp = 16;
2269 object->texture_format = GL_RGBA;
2270 object->texture_type = GL_FLOAT;
2273 ERR("Unknown texture format: %x\n", attr_v);
2274 SetLastError(ERROR_INVALID_DATA);
2282 case WGL_TEXTURE_TARGET_ARB: {
2284 attr_v = *piAttribList;
2285 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2286 if (use_render_texture_ati) {
2289 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2290 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
2291 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
2292 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
2294 SetLastError(ERROR_INVALID_DATA);
2297 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
2299 if (WGL_NO_TEXTURE_ARB == attr_v) {
2300 object->texture_target = 0;
2302 if (!use_render_texture_emulation) {
2303 SetLastError(ERROR_INVALID_DATA);
2307 case WGL_TEXTURE_CUBE_MAP_ARB: {
2308 if (iWidth != iHeight) {
2309 SetLastError(ERROR_INVALID_DATA);
2312 object->texture_target = GL_TEXTURE_CUBE_MAP;
2313 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2316 case WGL_TEXTURE_1D_ARB: {
2318 SetLastError(ERROR_INVALID_DATA);
2321 object->texture_target = GL_TEXTURE_1D;
2322 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2325 case WGL_TEXTURE_2D_ARB: {
2326 object->texture_target = GL_TEXTURE_2D;
2327 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2330 case WGL_TEXTURE_RECTANGLE_NV: {
2331 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2332 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2336 ERR("Unknown texture target: %x\n", attr_v);
2337 SetLastError(ERROR_INVALID_DATA);
2345 case WGL_MIPMAP_TEXTURE_ARB: {
2347 attr_v = *piAttribList;
2348 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2349 if (use_render_texture_ati) {
2350 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
2352 if (!use_render_texture_emulation) {
2353 SetLastError(ERROR_INVALID_DATA);
2363 PUSH1(attribs, None);
2365 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2366 wine_tsx11_unlock();
2367 TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
2368 if (!object->drawable) {
2369 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2370 goto create_failed; /* unexpected error */
2372 TRACE("->(%p)\n", object);
2376 HeapFree(GetProcessHeap(), 0, object);
2377 TRACE("->(FAILED)\n");
2382 * X11DRV_wglDestroyPbufferARB
2384 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2386 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2388 Wine_GLPBuffer* object = hPbuffer;
2389 TRACE("(%p)\n", hPbuffer);
2390 if (NULL == object) {
2391 SetLastError(ERROR_INVALID_HANDLE);
2395 pglXDestroyPbuffer(object->display, object->drawable);
2396 wine_tsx11_unlock();
2397 HeapFree(GetProcessHeap(), 0, object);
2402 * X11DRV_wglGetPbufferDCARB
2404 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2405 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2406 * Gdi32 implements the part of this function which creates a device context.
2407 * This part associates the physDev with the X drawable of the pbuffer.
2409 HDC CDECL X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
2411 Wine_GLPBuffer* object = hPbuffer;
2412 if (NULL == object) {
2413 SetLastError(ERROR_INVALID_HANDLE);
2417 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2418 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2419 physDev->current_pf = object->fmt->iPixelFormat;
2420 physDev->drawable = object->drawable;
2421 SetRect( &physDev->drawable_rect, 0, 0, object->width, object->height );
2422 physDev->dc_rect = physDev->drawable_rect;
2424 TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);
2425 return physDev->hdc;
2429 * X11DRV_wglQueryPbufferARB
2431 * WGL_ARB_pbuffer: wglQueryPbufferARB
2433 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2435 Wine_GLPBuffer* object = hPbuffer;
2436 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2437 if (NULL == object) {
2438 SetLastError(ERROR_INVALID_HANDLE);
2441 switch (iAttribute) {
2442 case WGL_PBUFFER_WIDTH_ARB:
2444 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2445 wine_tsx11_unlock();
2447 case WGL_PBUFFER_HEIGHT_ARB:
2449 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2450 wine_tsx11_unlock();
2453 case WGL_PBUFFER_LOST_ARB:
2454 /* GLX Pbuffers cannot be lost by default. We can support this by
2455 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2456 * to receive pixel buffer clobber events, however that may or may
2457 * not give any benefit */
2458 *piValue = GL_FALSE;
2461 case WGL_TEXTURE_FORMAT_ARB:
2462 if (use_render_texture_ati) {
2464 int type = WGL_NO_TEXTURE_ARB;
2466 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2467 wine_tsx11_unlock();
2469 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2470 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2471 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2475 if (!object->use_render_texture) {
2476 *piValue = WGL_NO_TEXTURE_ARB;
2478 if (!use_render_texture_emulation) {
2479 SetLastError(ERROR_INVALID_HANDLE);
2482 switch(object->use_render_texture) {
2484 *piValue = WGL_TEXTURE_RGB_ARB;
2487 *piValue = WGL_TEXTURE_RGBA_ARB;
2489 /* WGL_FLOAT_COMPONENTS_NV */
2491 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2493 case GL_FLOAT_RG_NV:
2494 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2496 case GL_FLOAT_RGB_NV:
2497 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2499 case GL_FLOAT_RGBA_NV:
2500 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2503 ERR("Unknown texture format: %x\n", object->use_render_texture);
2509 case WGL_TEXTURE_TARGET_ARB:
2510 if (use_render_texture_ati) {
2512 int type = WGL_NO_TEXTURE_ARB;
2514 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2515 wine_tsx11_unlock();
2517 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2518 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2519 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2520 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2524 if (!object->texture_target) {
2525 *piValue = WGL_NO_TEXTURE_ARB;
2527 if (!use_render_texture_emulation) {
2528 SetLastError(ERROR_INVALID_DATA);
2531 switch (object->texture_target) {
2532 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2533 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2534 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2535 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2541 case WGL_MIPMAP_TEXTURE_ARB:
2542 if (use_render_texture_ati) {
2544 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2545 wine_tsx11_unlock();
2547 *piValue = GL_FALSE; /** don't support that */
2548 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2553 FIXME("unexpected attribute %x\n", iAttribute);
2561 * X11DRV_wglReleasePbufferDCARB
2563 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2565 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2567 TRACE("(%p, %p)\n", hPbuffer, hdc);
2568 return DeleteDC(hdc);
2572 * X11DRV_wglSetPbufferAttribARB
2574 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2576 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2578 Wine_GLPBuffer* object = hPbuffer;
2579 GLboolean ret = GL_FALSE;
2581 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2582 if (NULL == object) {
2583 SetLastError(ERROR_INVALID_HANDLE);
2586 if (!object->use_render_texture) {
2587 SetLastError(ERROR_INVALID_HANDLE);
2590 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2593 if (NULL != pglXDrawableAttribATI) {
2594 if (use_render_texture_ati) {
2595 FIXME("Need conversion for GLX_ATI_render_texture\n");
2598 ret = pglXDrawableAttribATI(object->display, object->drawable, piAttribList);
2599 wine_tsx11_unlock();
2605 * X11DRV_wglChoosePixelFormatARB
2607 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2609 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2614 GLXFBConfig* cfgs = NULL;
2618 WineGLPixelFormat *fmt;
2622 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2623 if (NULL != pfAttribFList) {
2624 FIXME("unused pfAttribFList\n");
2627 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2628 if (-1 == nAttribs) {
2629 WARN("Cannot convert WGL to GLX attributes\n");
2632 PUSH1(attribs, None);
2634 /* Search for FB configurations matching the requirements in attribs */
2636 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2638 wine_tsx11_unlock();
2639 WARN("Compatible Pixel Format not found\n");
2643 /* Loop through all matching formats and check if they are suitable.
2644 * Note that this function should at max return nMaxFormats different formats */
2645 for(run=0; run < 2; run++)
2647 for (it = 0; it < nCfgs; ++it) {
2648 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2650 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2654 /* Search for the format in our list of compatible formats */
2655 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id);
2659 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2660 if( ((run == 0) && fmt->offscreenOnly) || ((run == 1) && !fmt->offscreenOnly) )
2663 if(pfmt_it < nMaxFormats) {
2664 piFormats[pfmt_it] = fmt->iPixelFormat;
2665 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2671 *nNumFormats = pfmt_it;
2674 wine_tsx11_unlock();
2679 * X11DRV_wglGetPixelFormatAttribivARB
2681 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2683 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2686 WineGLPixelFormat *fmt = NULL;
2690 int nWGLFormats = 0;
2692 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2694 if (0 < iLayerPlane) {
2695 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2699 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2700 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2701 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2702 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nWGLFormats);
2704 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2708 for (i = 0; i < nAttributes; ++i) {
2709 const int curWGLAttr = piAttributes[i];
2710 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2712 switch (curWGLAttr) {
2713 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2714 piValues[i] = nWGLFormats;
2717 case WGL_SUPPORT_OPENGL_ARB:
2718 piValues[i] = GL_TRUE;
2721 case WGL_ACCELERATION_ARB:
2722 curGLXAttr = GLX_CONFIG_CAVEAT;
2723 if (!fmt) goto pix_error;
2724 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2725 if (hTest) goto get_error;
2727 case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2728 case GLX_SLOW_CONFIG: piValues[i] = WGL_GENERIC_ACCELERATION_ARB; break;
2729 case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2731 ERR("unexpected Config Caveat(%x)\n", tmp);
2732 piValues[i] = WGL_NO_ACCELERATION_ARB;
2736 case WGL_TRANSPARENT_ARB:
2737 curGLXAttr = GLX_TRANSPARENT_TYPE;
2738 if (!fmt) goto pix_error;
2739 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2740 if (hTest) goto get_error;
2741 piValues[i] = GL_FALSE;
2742 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2745 case WGL_PIXEL_TYPE_ARB:
2746 curGLXAttr = GLX_RENDER_TYPE;
2747 if (!fmt) goto pix_error;
2748 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2749 if (hTest) goto get_error;
2750 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2751 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2752 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2753 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2754 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2755 else if (tmp & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) { piValues[i] = WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT; }
2757 ERR("unexpected RenderType(%x)\n", tmp);
2758 piValues[i] = WGL_TYPE_RGBA_ARB;
2762 case WGL_COLOR_BITS_ARB:
2763 curGLXAttr = GLX_BUFFER_SIZE;
2766 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2767 if (use_render_texture_ati) {
2768 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
2771 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2772 if (use_render_texture_ati) {
2773 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
2776 if (!use_render_texture_emulation) {
2777 piValues[i] = GL_FALSE;
2780 curGLXAttr = GLX_RENDER_TYPE;
2781 if (!fmt) goto pix_error;
2782 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2783 if (hTest) goto get_error;
2784 if (GLX_COLOR_INDEX_BIT == tmp) {
2785 piValues[i] = GL_FALSE;
2788 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2789 if (hTest) goto get_error;
2790 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2793 case WGL_BLUE_BITS_ARB:
2794 curGLXAttr = GLX_BLUE_SIZE;
2796 case WGL_RED_BITS_ARB:
2797 curGLXAttr = GLX_RED_SIZE;
2799 case WGL_GREEN_BITS_ARB:
2800 curGLXAttr = GLX_GREEN_SIZE;
2802 case WGL_ALPHA_BITS_ARB:
2803 curGLXAttr = GLX_ALPHA_SIZE;
2805 case WGL_DEPTH_BITS_ARB:
2806 curGLXAttr = GLX_DEPTH_SIZE;
2808 case WGL_STENCIL_BITS_ARB:
2809 curGLXAttr = GLX_STENCIL_SIZE;
2811 case WGL_DOUBLE_BUFFER_ARB:
2812 curGLXAttr = GLX_DOUBLEBUFFER;
2814 case WGL_STEREO_ARB:
2815 curGLXAttr = GLX_STEREO;
2817 case WGL_AUX_BUFFERS_ARB:
2818 curGLXAttr = GLX_AUX_BUFFERS;
2821 case WGL_SUPPORT_GDI_ARB:
2822 if (!fmt) goto pix_error;
2823 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &tmp);
2824 if (hTest) goto get_error;
2826 piValues[i] = GL_FALSE;
2829 curGLXAttr = GLX_X_RENDERABLE;
2832 case WGL_DRAW_TO_WINDOW_ARB:
2833 case WGL_DRAW_TO_BITMAP_ARB:
2834 case WGL_DRAW_TO_PBUFFER_ARB:
2835 if (!fmt) goto pix_error;
2836 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2837 if (hTest) goto get_error;
2838 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2839 (curWGLAttr == WGL_DRAW_TO_BITMAP_ARB && (tmp&GLX_PIXMAP_BIT)) ||
2840 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2841 piValues[i] = GL_TRUE;
2843 piValues[i] = GL_FALSE;
2846 case WGL_PBUFFER_LARGEST_ARB:
2847 curGLXAttr = GLX_LARGEST_PBUFFER;
2850 case WGL_SAMPLE_BUFFERS_ARB:
2851 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2854 case WGL_SAMPLES_ARB:
2855 curGLXAttr = GLX_SAMPLES_ARB;
2858 case WGL_FLOAT_COMPONENTS_NV:
2859 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2862 case WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT:
2863 curGLXAttr = GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT;
2866 case WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT:
2867 curGLXAttr = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
2870 case WGL_ACCUM_RED_BITS_ARB:
2871 curGLXAttr = GLX_ACCUM_RED_SIZE;
2873 case WGL_ACCUM_GREEN_BITS_ARB:
2874 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2876 case WGL_ACCUM_BLUE_BITS_ARB:
2877 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2879 case WGL_ACCUM_ALPHA_BITS_ARB:
2880 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2882 case WGL_ACCUM_BITS_ARB:
2883 if (!fmt) goto pix_error;
2884 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2885 if (hTest) goto get_error;
2887 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2888 if (hTest) goto get_error;
2890 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2891 if (hTest) goto get_error;
2893 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2894 if (hTest) goto get_error;
2899 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2902 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2903 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2904 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2906 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2907 * and check which options can work using iPixelFormat=0 and which not.
2908 * A problem would be that this function is an extension. This would
2909 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2911 if (0 != curGLXAttr && iPixelFormat != 0) {
2912 if (!fmt) goto pix_error;
2913 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2914 if (hTest) goto get_error;
2917 piValues[i] = GL_FALSE;
2920 wine_tsx11_unlock();
2924 wine_tsx11_unlock();
2925 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2929 wine_tsx11_unlock();
2930 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats);
2935 * X11DRV_wglGetPixelFormatAttribfvARB
2937 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2939 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
2945 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2947 /* Allocate a temporary array to store integer values */
2948 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2950 ERR("couldn't allocate %d array\n", nAttributes);
2954 /* Piggy-back on wglGetPixelFormatAttribivARB */
2955 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2957 /* Convert integer values to float. Should also check for attributes
2958 that can give decimal values here */
2959 for (i=0; i<nAttributes;i++) {
2960 pfValues[i] = attr[i];
2964 HeapFree(GetProcessHeap(), 0, attr);
2969 * X11DRV_wglBindTexImageARB
2971 * WGL_ARB_render_texture: wglBindTexImageARB
2973 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2975 Wine_GLPBuffer* object = hPbuffer;
2976 GLboolean ret = GL_FALSE;
2978 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2979 if (NULL == object) {
2980 SetLastError(ERROR_INVALID_HANDLE);
2983 if (!object->use_render_texture) {
2984 SetLastError(ERROR_INVALID_HANDLE);
2988 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2989 static int init = 0;
2990 int prev_binded_texture = 0;
2991 GLXContext prev_context;
2992 Drawable prev_drawable;
2993 GLXContext tmp_context;
2996 prev_context = pglXGetCurrentContext();
2997 prev_drawable = pglXGetCurrentDrawable();
2999 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
3000 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
3001 isn't ideal performance wise but I wasn't able to get other ways working.
3004 init = 1; /* Only show the FIXME once for performance reasons */
3005 FIXME("partial stub!\n");
3008 TRACE("drawable=%p, context=%p\n", (void*)object->drawable, prev_context);
3009 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
3011 pglGetIntegerv(object->texture_bind_target, &prev_binded_texture);
3013 /* Switch to our pbuffer */
3014 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
3016 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
3017 * After that upload the pbuffer texture data. */
3018 pglBindTexture(object->texture_target, prev_binded_texture);
3019 pglCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
3021 /* Switch back to the original drawable and upload the pbuffer-texture */
3022 pglXMakeCurrent(object->display, prev_drawable, prev_context);
3023 pglXDestroyContext(gdi_display, tmp_context);
3024 wine_tsx11_unlock();
3028 if (NULL != pglXBindTexImageATI) {
3033 case WGL_FRONT_LEFT_ARB:
3034 buffer = GLX_FRONT_LEFT_ATI;
3036 case WGL_FRONT_RIGHT_ARB:
3037 buffer = GLX_FRONT_RIGHT_ATI;
3039 case WGL_BACK_LEFT_ARB:
3040 buffer = GLX_BACK_LEFT_ATI;
3042 case WGL_BACK_RIGHT_ARB:
3043 buffer = GLX_BACK_RIGHT_ATI;
3046 ERR("Unknown iBuffer=%#x\n", iBuffer);
3050 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3051 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3052 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3053 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3054 * works fine using our pbuffer emulation path.
3057 ret = pglXBindTexImageATI(object->display, object->drawable, buffer);
3058 wine_tsx11_unlock();
3064 * X11DRV_wglReleaseTexImageARB
3066 * WGL_ARB_render_texture: wglReleaseTexImageARB
3068 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
3070 Wine_GLPBuffer* object = hPbuffer;
3071 GLboolean ret = GL_FALSE;
3073 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
3074 if (NULL == object) {
3075 SetLastError(ERROR_INVALID_HANDLE);
3078 if (!object->use_render_texture) {
3079 SetLastError(ERROR_INVALID_HANDLE);
3082 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
3085 if (NULL != pglXReleaseTexImageATI) {
3090 case WGL_FRONT_LEFT_ARB:
3091 buffer = GLX_FRONT_LEFT_ATI;
3093 case WGL_FRONT_RIGHT_ARB:
3094 buffer = GLX_FRONT_RIGHT_ATI;
3096 case WGL_BACK_LEFT_ARB:
3097 buffer = GLX_BACK_LEFT_ATI;
3099 case WGL_BACK_RIGHT_ARB:
3100 buffer = GLX_BACK_RIGHT_ATI;
3103 ERR("Unknown iBuffer=%#x\n", iBuffer);
3107 ret = pglXReleaseTexImageATI(object->display, object->drawable, buffer);
3108 wine_tsx11_unlock();
3114 * X11DRV_wglGetExtensionsStringEXT
3116 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3118 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
3119 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
3120 return WineGLInfo.wglExtensions;
3124 * X11DRV_wglGetSwapIntervalEXT
3126 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3128 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
3129 FIXME("(),stub!\n");
3130 return swap_interval;
3134 * X11DRV_wglSwapIntervalEXT
3136 * WGL_EXT_swap_control: wglSwapIntervalEXT
3138 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
3141 TRACE("(%d)\n", interval);
3142 swap_interval = interval;
3143 if (NULL != pglXSwapIntervalSGI) {
3145 ret = !pglXSwapIntervalSGI(interval);
3146 wine_tsx11_unlock();
3148 else WARN("(): GLX_SGI_swap_control extension seems not supported\n");
3153 * X11DRV_wglAllocateMemoryNV
3155 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3157 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
3159 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
3161 if (pglXAllocateMemoryNV)
3164 ret = pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
3165 wine_tsx11_unlock();
3171 * X11DRV_wglFreeMemoryNV
3173 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3175 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
3176 TRACE("(%p)\n", pointer);
3177 if (pglXFreeMemoryNV == NULL)
3181 pglXFreeMemoryNV(pointer);
3182 wine_tsx11_unlock();
3186 * X11DRV_wglSetPixelFormatWINE
3188 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3189 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3191 BOOL CDECL X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE *physDev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
3193 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
3195 if (!has_opengl()) return FALSE;
3197 if (physDev->current_pf == iPixelFormat) return TRUE;
3199 /* Relay to the core SetPixelFormat */
3200 TRACE("Changing iPixelFormat from %d to %d\n", physDev->current_pf, iPixelFormat);
3201 return internal_SetPixelFormat(physDev, iPixelFormat, ppfd);
3205 * glxRequireVersion (internal)
3207 * Check if the supported GLX version matches requiredVersion.
3209 static BOOL glxRequireVersion(int requiredVersion)
3211 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3212 if(requiredVersion <= WineGLInfo.glxVersion[1])
3218 static BOOL glxRequireExtension(const char *requiredExtension)
3220 if (strstr(WineGLInfo.glxExtensions, requiredExtension) == NULL) {
3227 static void register_extension_string(const char *ext)
3229 if (WineGLInfo.wglExtensions[0])
3230 strcat(WineGLInfo.wglExtensions, " ");
3231 strcat(WineGLInfo.wglExtensions, ext);
3233 TRACE("'%s'\n", ext);
3236 static BOOL register_extension(const WineGLExtension * ext)
3240 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
3241 WineGLExtensionList[WineGLExtensionListSize++] = ext;
3243 register_extension_string(ext->extName);
3245 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
3246 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
3251 static const WineGLExtension WGL_internal_functions =
3255 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
3256 { "wglFinish", X11DRV_wglFinish },
3257 { "wglFlush", X11DRV_wglFlush },
3262 static const WineGLExtension WGL_ARB_extensions_string =
3264 "WGL_ARB_extensions_string",
3266 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
3270 static const WineGLExtension WGL_ARB_make_current_read =
3272 "WGL_ARB_make_current_read",
3274 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
3275 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
3279 static const WineGLExtension WGL_ARB_multisample =
3281 "WGL_ARB_multisample",
3284 static const WineGLExtension WGL_ARB_pbuffer =
3288 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
3289 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
3290 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
3291 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
3292 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
3293 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
3297 static const WineGLExtension WGL_ARB_pixel_format =
3299 "WGL_ARB_pixel_format",
3301 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
3302 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
3303 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
3307 static const WineGLExtension WGL_ARB_render_texture =
3309 "WGL_ARB_render_texture",
3311 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
3312 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
3316 static const WineGLExtension WGL_EXT_extensions_string =
3318 "WGL_EXT_extensions_string",
3320 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
3324 static const WineGLExtension WGL_EXT_swap_control =
3326 "WGL_EXT_swap_control",
3328 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
3329 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
3333 static const WineGLExtension WGL_NV_vertex_array_range =
3335 "WGL_NV_vertex_array_range",
3337 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
3338 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
3342 static const WineGLExtension WGL_WINE_pixel_format_passthrough =
3344 "WGL_WINE_pixel_format_passthrough",
3346 { "wglSetPixelFormatWINE", X11DRV_wglSetPixelFormatWINE },
3351 * X11DRV_WineGL_LoadExtensions
3353 static void X11DRV_WineGL_LoadExtensions(void)
3355 WineGLInfo.wglExtensions[0] = 0;
3357 /* Load Wine internal functions */
3358 register_extension(&WGL_internal_functions);
3360 /* ARB Extensions */
3362 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3364 register_extension_string("WGL_ARB_pixel_format_float");
3365 register_extension_string("WGL_ATI_pixel_format_float");
3368 register_extension(&WGL_ARB_extensions_string);
3370 if (glxRequireVersion(3))
3371 register_extension(&WGL_ARB_make_current_read);
3373 if (glxRequireExtension("GLX_ARB_multisample"))
3374 register_extension(&WGL_ARB_multisample);
3376 /* In general pbuffer functionality requires support in the X-server. The functionality is
3377 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3378 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3379 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3381 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3382 * without support in the X-server (which other Mesa based drivers require).
3384 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3385 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3386 * is available pbuffers must be available too. */
3387 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3388 register_extension(&WGL_ARB_pbuffer);
3390 register_extension(&WGL_ARB_pixel_format);
3392 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3393 if (glxRequireExtension("GLX_ATI_render_texture") ||
3394 glxRequireExtension("GLX_ARB_render_texture") ||
3395 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation))
3397 register_extension(&WGL_ARB_render_texture);
3399 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3400 if(glxRequireExtension("GLX_NV_float_buffer"))
3401 register_extension_string("WGL_NV_float_buffer");
3403 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3404 if(strstr(WineGLInfo.glExtensions, "GL_NV_texture_rectangle") != NULL)
3405 register_extension_string("WGL_NV_texture_rectangle");
3408 /* EXT Extensions */
3410 register_extension(&WGL_EXT_extensions_string);
3412 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3413 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3414 register_extension(&WGL_EXT_swap_control);
3416 if(glxRequireExtension("GLX_EXT_framebuffer_sRGB"))
3417 register_extension_string("WGL_EXT_framebuffer_sRGB");
3419 if(glxRequireExtension("GLX_EXT_fbconfig_packed_float"))
3420 register_extension_string("WGL_EXT_pixel_format_packed_float");
3422 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3423 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
3424 register_extension(&WGL_NV_vertex_array_range);
3426 /* WINE-specific WGL Extensions */
3428 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
3429 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
3431 register_extension(&WGL_WINE_pixel_format_passthrough);
3435 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3441 if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
3442 ret = physDev->drawable; /* PBuffer */
3444 ret = physDev->bitmap->glxpixmap;
3446 else if(physDev->gl_drawable)
3447 ret = physDev->gl_drawable;
3449 ret = physDev->drawable;
3453 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3456 pglXDestroyGLXPixmap(display, glxpixmap);
3457 wine_tsx11_unlock();
3462 * X11DRV_SwapBuffers
3464 * Swap the buffers of this DC
3466 BOOL CDECL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev)
3468 GLXDrawable drawable;
3469 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
3471 if (!has_opengl()) return FALSE;
3473 TRACE("(%p)\n", physDev);
3475 drawable = get_glxdrawable(physDev);
3479 if(physDev->pixmap) {
3480 if(pglXCopySubBufferMESA) {
3481 int w = physDev->dc_rect.right - physDev->dc_rect.left;
3482 int h = physDev->dc_rect.bottom - physDev->dc_rect.top;
3484 /* (glX)SwapBuffers has an implicit glFlush effect, however
3485 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3489 pglXCopySubBufferMESA(gdi_display, drawable, 0, 0, w, h);
3492 pglXSwapBuffers(gdi_display, drawable);
3495 pglXSwapBuffers(gdi_display, drawable);
3497 flush_gl_drawable(physDev);
3498 wine_tsx11_unlock();
3503 static long prev_time, start_time;
3504 static unsigned long frames, frames_total;
3506 DWORD time = GetTickCount();
3509 /* every 1.5 seconds */
3510 if (time - prev_time > 1500) {
3511 TRACE_(fps)("@ approx %.2ffps, total %.2ffps\n",
3512 1000.0*frames/(time - prev_time), 1000.0*frames_total/(time - start_time));
3515 if(start_time == 0) start_time = time;
3522 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3524 WineGLPixelFormat *fmt;
3527 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id);
3532 ret = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
3533 wine_tsx11_unlock();
3537 #else /* no OpenGL includes */
3539 static inline void opengl_error(void)
3542 if (!warned++) ERR("No OpenGL support compiled in.\n");
3545 int pixelformat_from_fbconfig_id(XID fbconfig_id)
3550 void mark_drawable_dirty(Drawable old, Drawable new)
3554 void flush_gl_drawable(X11DRV_PDEVICE *physDev)
3558 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
3563 /***********************************************************************
3564 * ChoosePixelFormat (X11DRV.@)
3566 int CDECL X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
3567 const PIXELFORMATDESCRIPTOR *ppfd) {
3572 /***********************************************************************
3573 * DescribePixelFormat (X11DRV.@)
3575 int CDECL X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
3578 PIXELFORMATDESCRIPTOR *ppfd) {
3583 /***********************************************************************
3584 * GetPixelFormat (X11DRV.@)
3586 int CDECL X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
3591 /***********************************************************************
3592 * SetPixelFormat (X11DRV.@)
3594 BOOL CDECL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
3596 const PIXELFORMATDESCRIPTOR *ppfd) {
3601 /***********************************************************************
3602 * SwapBuffers (X11DRV.@)
3604 BOOL CDECL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
3610 * X11DRV_wglCopyContext
3612 * For OpenGL32 wglCopyContext.
3614 BOOL CDECL X11DRV_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask) {
3620 * X11DRV_wglCreateContext
3622 * For OpenGL32 wglCreateContext.
3624 HGLRC CDECL X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) {
3630 * X11DRV_wglDeleteContext
3632 * For OpenGL32 wglDeleteContext.
3634 BOOL CDECL X11DRV_wglDeleteContext(HGLRC hglrc) {
3640 * X11DRV_wglGetProcAddress
3642 * For OpenGL32 wglGetProcAddress.
3644 PROC CDECL X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
3649 HDC CDECL X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *hDevice, void *hPbuffer)
3655 BOOL CDECL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) {
3661 * X11DRV_wglMakeCurrent
3663 * For OpenGL32 wglMakeCurrent.
3665 BOOL CDECL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
3671 * X11DRV_wglShareLists
3673 * For OpenGL32 wglShareLists.
3675 BOOL CDECL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
3681 * X11DRV_wglUseFontBitmapsA
3683 * For OpenGL32 wglUseFontBitmapsA.
3685 BOOL CDECL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3692 * X11DRV_wglUseFontBitmapsW
3694 * For OpenGL32 wglUseFontBitmapsW.
3696 BOOL CDECL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3703 * X11DRV_wglSetPixelFormatWINE
3705 * WGL_WINE_pixel_format_passthrough: wglSetPixelFormatWINE
3706 * This is a WINE-specific wglSetPixelFormat which can set the pixel format multiple times.
3708 BOOL CDECL X11DRV_wglSetPixelFormatWINE(X11DRV_PDEVICE *physDev, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
3714 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3719 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3724 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3729 #endif /* defined(HAVE_OPENGL) */