2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006 Roderick Colenbrander
8 * Copyright 2006 Tomas Carnecky
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
34 #include "wine/library.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
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 {
108 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 WineGLPixelFormat *WineGLPixelFormatList;
148 static int WineGLPixelFormatListSize = 0;
149 static int WineGLPixelFormatOnScreenSize = 0;
151 static void X11DRV_WineGL_LoadExtensions(void);
152 static BOOL glxRequireVersion(int requiredVersion);
153 static BOOL glxRequireExtension(const char *requiredExtension);
155 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
156 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
157 TRACE(" - dwFlags : ");
158 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
159 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
160 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
161 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
162 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
163 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
164 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
165 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
166 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
167 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
168 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
169 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
170 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
171 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
172 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
173 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
174 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
175 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
176 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
177 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
181 TRACE(" - iPixelType : ");
182 switch (ppfd->iPixelType) {
183 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
184 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
188 TRACE(" - Color : %d\n", ppfd->cColorBits);
189 TRACE(" - Red : %d\n", ppfd->cRedBits);
190 TRACE(" - Green : %d\n", ppfd->cGreenBits);
191 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
192 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
193 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
194 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
195 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
196 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
198 TRACE(" - iLayerType : ");
199 switch (ppfd->iLayerType) {
200 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
201 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
202 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
207 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
208 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
210 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
212 MAKE_FUNCPTR(glXChooseVisual)
213 MAKE_FUNCPTR(glXCopyContext)
214 MAKE_FUNCPTR(glXCreateContext)
215 MAKE_FUNCPTR(glXCreateGLXPixmap)
216 MAKE_FUNCPTR(glXGetCurrentContext)
217 MAKE_FUNCPTR(glXGetCurrentDrawable)
218 MAKE_FUNCPTR(glXDestroyContext)
219 MAKE_FUNCPTR(glXDestroyGLXPixmap)
220 MAKE_FUNCPTR(glXGetConfig)
221 MAKE_FUNCPTR(glXIsDirect)
222 MAKE_FUNCPTR(glXMakeCurrent)
223 MAKE_FUNCPTR(glXSwapBuffers)
224 MAKE_FUNCPTR(glXQueryExtension)
225 MAKE_FUNCPTR(glXQueryVersion)
226 MAKE_FUNCPTR(glXUseXFont)
229 MAKE_FUNCPTR(glXGetClientString)
230 MAKE_FUNCPTR(glXQueryExtensionsString)
231 MAKE_FUNCPTR(glXQueryServerString)
234 MAKE_FUNCPTR(glXGetFBConfigs)
235 MAKE_FUNCPTR(glXChooseFBConfig)
236 MAKE_FUNCPTR(glXCreatePbuffer)
237 MAKE_FUNCPTR(glXCreateNewContext)
238 MAKE_FUNCPTR(glXDestroyPbuffer)
239 MAKE_FUNCPTR(glXGetFBConfigAttrib)
240 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
241 MAKE_FUNCPTR(glXMakeContextCurrent)
242 MAKE_FUNCPTR(glXQueryDrawable)
243 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
246 static void* (*pglXGetProcAddressARB)(const GLubyte *);
247 static int (*pglXSwapIntervalSGI)(int);
249 /* ATI GLX Extensions */
250 static BOOL (*pglXBindTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
251 static BOOL (*pglXReleaseTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
252 static BOOL (*pglXDrawableAttribATI)(Display *dpy, GLXDrawable draw, const int *attribList);
254 /* NV GLX Extension */
255 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
256 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
258 /* MESA GLX Extensions */
259 static void (*pglXCopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
261 /* Standard OpenGL */
262 MAKE_FUNCPTR(glBindTexture)
263 MAKE_FUNCPTR(glBitmap)
264 MAKE_FUNCPTR(glCopyTexSubImage1D)
265 MAKE_FUNCPTR(glCopyTexImage2D)
266 MAKE_FUNCPTR(glCopyTexSubImage2D)
267 MAKE_FUNCPTR(glDrawBuffer)
268 MAKE_FUNCPTR(glEndList)
269 MAKE_FUNCPTR(glGetError)
270 MAKE_FUNCPTR(glGetIntegerv)
271 MAKE_FUNCPTR(glGetString)
272 MAKE_FUNCPTR(glNewList)
273 MAKE_FUNCPTR(glPixelStorei)
274 MAKE_FUNCPTR(glReadPixels)
275 MAKE_FUNCPTR(glTexImage2D)
276 MAKE_FUNCPTR(glFinish)
277 MAKE_FUNCPTR(glFlush)
280 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
282 static BOOL infoInitialized = FALSE;
284 int screen = DefaultScreen(gdi_display);
285 Window win = RootWindow(gdi_display, screen);
287 XVisualInfo template;
290 GLXContext ctx = NULL;
294 infoInitialized = TRUE;
298 visual = DefaultVisual(gdi_display, screen);
299 template.visualid = XVisualIDFromVisual(visual);
300 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
302 WORD old_fs = wine_get_fs();
303 /* Create a GLX Context. Without one we can't query GL information */
304 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
305 if (wine_get_fs() != old_fs)
307 wine_set_fs( old_fs );
309 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
310 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
316 pglXMakeCurrent(gdi_display, win, ctx);
318 ERR(" couldn't initialize OpenGL, expect problems\n");
323 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
324 WineGLInfo.glExtensions = strdup((const char *) pglGetString(GL_EXTENSIONS));
326 /* Get the common GLX version supported by GLX client and server ( major/minor) */
327 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
329 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
330 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
331 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
333 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
334 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
335 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
337 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
338 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
340 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
341 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER));
342 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
343 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
344 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
345 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
346 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
347 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
351 pglXMakeCurrent(gdi_display, None, NULL);
352 pglXDestroyContext(gdi_display, ctx);
358 static BOOL has_opengl(void)
360 static int init_done;
361 static void *opengl_handle;
363 int error_base, event_base;
365 if (init_done) return (opengl_handle != NULL);
368 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
369 and include all dependencies */
370 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, NULL, 0);
371 if (opengl_handle == NULL) return FALSE;
373 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
374 if (pglXGetProcAddressARB == NULL) {
375 ERR("could not find glXGetProcAddressARB in libGL.\n");
379 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
381 LOAD_FUNCPTR(glXChooseVisual)
382 LOAD_FUNCPTR(glXCopyContext)
383 LOAD_FUNCPTR(glXCreateContext)
384 LOAD_FUNCPTR(glXCreateGLXPixmap)
385 LOAD_FUNCPTR(glXGetCurrentContext)
386 LOAD_FUNCPTR(glXGetCurrentDrawable)
387 LOAD_FUNCPTR(glXDestroyContext)
388 LOAD_FUNCPTR(glXDestroyGLXPixmap)
389 LOAD_FUNCPTR(glXGetConfig)
390 LOAD_FUNCPTR(glXIsDirect)
391 LOAD_FUNCPTR(glXMakeCurrent)
392 LOAD_FUNCPTR(glXSwapBuffers)
393 LOAD_FUNCPTR(glXQueryExtension)
394 LOAD_FUNCPTR(glXQueryVersion)
395 LOAD_FUNCPTR(glXUseXFont)
398 LOAD_FUNCPTR(glXGetClientString)
399 LOAD_FUNCPTR(glXQueryExtensionsString)
400 LOAD_FUNCPTR(glXQueryServerString)
403 LOAD_FUNCPTR(glXCreatePbuffer)
404 LOAD_FUNCPTR(glXCreateNewContext)
405 LOAD_FUNCPTR(glXDestroyPbuffer)
406 LOAD_FUNCPTR(glXMakeContextCurrent)
407 LOAD_FUNCPTR(glXGetCurrentReadDrawable)
408 LOAD_FUNCPTR(glXGetFBConfigs)
410 /* Standard OpenGL calls */
411 LOAD_FUNCPTR(glBindTexture)
412 LOAD_FUNCPTR(glBitmap)
413 LOAD_FUNCPTR(glCopyTexSubImage1D)
414 LOAD_FUNCPTR(glCopyTexImage2D)
415 LOAD_FUNCPTR(glCopyTexSubImage2D)
416 LOAD_FUNCPTR(glDrawBuffer)
417 LOAD_FUNCPTR(glEndList)
418 LOAD_FUNCPTR(glGetError)
419 LOAD_FUNCPTR(glGetIntegerv)
420 LOAD_FUNCPTR(glGetString)
421 LOAD_FUNCPTR(glNewList)
422 LOAD_FUNCPTR(glPixelStorei)
423 LOAD_FUNCPTR(glReadPixels)
424 LOAD_FUNCPTR(glTexImage2D)
425 LOAD_FUNCPTR(glFinish)
426 LOAD_FUNCPTR(glFlush)
429 /* It doesn't matter if these fail. They'll only be used if the driver reports
430 the associated extension is available (and if a driver reports the extension
431 is available but fails to provide the functions, it's quite broken) */
432 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f);
433 /* NV GLX Extension */
434 LOAD_FUNCPTR(glXAllocateMemoryNV)
435 LOAD_FUNCPTR(glXFreeMemoryNV)
438 if(!X11DRV_WineGL_InitOpenglInfo()) {
439 wine_dlclose(opengl_handle, NULL, 0);
440 opengl_handle = NULL;
445 if (pglXQueryExtension(gdi_display, &error_base, &event_base) == True) {
446 TRACE("GLX is up and running error_base = %d\n", error_base);
448 wine_dlclose(opengl_handle, NULL, 0);
449 opengl_handle = NULL;
452 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
453 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
456 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
457 * depends on the reported GLX client / server version and on the client / server extension list.
458 * Those don't have to be the same.
460 * In general the server GLX information lists the capabilities in case of indirect rendering.
461 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
462 * available and in that case the client GLX informat can be used.
463 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
464 * in the GLX version/extension list. When a program does this it works for certain for both
465 * direct and indirect rendering.
467 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
468 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
469 * extension list which causes this extension not to be listed. (Wine requires this extension).
470 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
471 * pbuffers is around.
473 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
474 * the ATI drivers and from then on use GLX client information for them.
477 if(glxRequireVersion(3)) {
478 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
479 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
480 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
481 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
482 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
483 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
484 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
485 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
487 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
488 * enable this function when the Xserver understand GLX 1.3 or newer
490 pglXQueryDrawable = NULL;
491 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
492 TRACE("Overriding ATI GLX capabilities!\n");
493 pglXChooseFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
494 pglXGetFBConfigAttrib = pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
495 pglXGetVisualFromFBConfig = pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
496 pglXQueryDrawable = pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
498 /* Use client GLX information in case of the ATI drivers. We override the
499 * capabilities over here and not somewhere else as ATI might better their
500 * life in the future. In case they release proper drivers this block of
501 * code won't be called. */
502 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
504 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
507 if(glxRequireExtension("GLX_ATI_render_texture")) {
508 use_render_texture_ati = 1;
509 pglXBindTexImageATI = pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageATI");
510 pglXReleaseTexImageATI = pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageATI");
511 pglXDrawableAttribATI = pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribATI");
514 if(glxRequireExtension("GLX_MESA_copy_sub_buffer")) {
515 pglXCopySubBufferMESA = pglXGetProcAddressARB((const GLubyte *) "glXCopySubBufferMESA");
518 X11DRV_WineGL_LoadExtensions();
521 return (opengl_handle != NULL);
524 wine_dlclose(opengl_handle, NULL, 0);
525 opengl_handle = NULL;
529 static inline Wine_GLContext *alloc_context(void)
533 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLContext))))
535 ret->next = context_list;
536 if (context_list) context_list->prev = ret;
542 static inline void free_context(Wine_GLContext *context)
544 if (context->next != NULL) context->next->prev = context->prev;
545 if (context->prev != NULL) context->prev->next = context->next;
546 else context_list = context->next;
548 if (context->vis) XFree(context->vis);
549 HeapFree(GetProcessHeap(), 0, context);
552 static inline BOOL is_valid_context( Wine_GLContext *ctx )
555 for (ptr = context_list; ptr; ptr = ptr->next) if (ptr == ctx) break;
556 return (ptr != NULL);
559 static int describeContext(Wine_GLContext* ctx) {
562 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
563 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
564 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
565 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
566 TRACE(" - VISUAL_ID 0x%x\n", tmp);
571 static int describeDrawable(Wine_GLContext* ctx, Drawable drawable) {
574 int attribList[3] = { GLX_FBCONFIG_ID, 0, None };
577 if (pglXQueryDrawable == NULL) {
578 /** glXQueryDrawable not available so returns not supported */
582 TRACE(" Drawable %p have :\n", (void*) drawable);
583 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &tmp);
584 TRACE(" - WIDTH as %d\n", tmp);
585 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &tmp);
586 TRACE(" - HEIGHT as %d\n", tmp);
587 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &tmp);
588 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
591 fbCfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribList, &nElements);
592 if (fbCfgs == NULL) {
596 pglXGetFBConfigAttrib(gdi_display, fbCfgs[0], GLX_VISUAL_ID, &tmp);
597 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
604 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
609 int nvfloatattrib = GLX_DONT_CARE;
614 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
615 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
616 while (iWGLAttr && 0 != iWGLAttr[cur]) {
617 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
619 switch (iWGLAttr[cur]) {
620 case WGL_AUX_BUFFERS_ARB:
621 pop = iWGLAttr[++cur];
622 PUSH2(oGLXAttr, GLX_AUX_BUFFERS, pop);
623 TRACE("pAttr[%d] = GLX_AUX_BUFFERS: %d\n", cur, pop);
625 case WGL_COLOR_BITS_ARB:
626 pop = iWGLAttr[++cur];
627 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
628 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
630 case WGL_BLUE_BITS_ARB:
631 pop = iWGLAttr[++cur];
632 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
633 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
635 case WGL_RED_BITS_ARB:
636 pop = iWGLAttr[++cur];
637 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
638 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
640 case WGL_GREEN_BITS_ARB:
641 pop = iWGLAttr[++cur];
642 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
643 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
645 case WGL_ALPHA_BITS_ARB:
646 pop = iWGLAttr[++cur];
647 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
648 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
650 case WGL_DEPTH_BITS_ARB:
651 pop = iWGLAttr[++cur];
652 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
653 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
655 case WGL_STENCIL_BITS_ARB:
656 pop = iWGLAttr[++cur];
657 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
658 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
660 case WGL_DOUBLE_BUFFER_ARB:
661 pop = iWGLAttr[++cur];
662 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
663 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
667 pop = iWGLAttr[++cur];
668 PUSH2(oGLXAttr, GLX_STEREO, pop);
669 TRACE("pAttr[%d] = GLX_STEREO: %d\n", cur, pop);
672 case WGL_PIXEL_TYPE_ARB:
673 pop = iWGLAttr[++cur];
674 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
676 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
677 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
678 /* 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 */
679 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
681 ERR("unexpected PixelType(%x)\n", pop);
686 case WGL_SUPPORT_GDI_ARB:
687 pop = iWGLAttr[++cur];
688 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
689 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
693 case WGL_DRAW_TO_BITMAP_ARB:
694 pop = iWGLAttr[++cur];
695 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
696 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
698 drawattrib |= GLX_PIXMAP_BIT;
702 case WGL_DRAW_TO_WINDOW_ARB:
703 pop = iWGLAttr[++cur];
704 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
705 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
707 drawattrib |= GLX_WINDOW_BIT;
711 case WGL_DRAW_TO_PBUFFER_ARB:
712 pop = iWGLAttr[++cur];
713 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
714 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
716 drawattrib |= GLX_PBUFFER_BIT;
720 case WGL_ACCELERATION_ARB:
721 case WGL_SUPPORT_OPENGL_ARB:
722 pop = iWGLAttr[++cur];
723 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
724 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
727 case WGL_PBUFFER_LARGEST_ARB:
728 pop = iWGLAttr[++cur];
729 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
730 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
733 case WGL_SAMPLE_BUFFERS_ARB:
734 pop = iWGLAttr[++cur];
735 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
736 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
739 case WGL_SAMPLES_ARB:
740 pop = iWGLAttr[++cur];
741 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
742 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
745 case WGL_TEXTURE_FORMAT_ARB:
746 case WGL_TEXTURE_TARGET_ARB:
747 case WGL_MIPMAP_TEXTURE_ARB:
748 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
749 pop = iWGLAttr[++cur];
751 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
753 if (use_render_texture_ati) {
754 /** nothing to do here */
756 else if (!use_render_texture_emulation) {
757 if (WGL_NO_TEXTURE_ARB != pop) {
758 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
759 return -1; /** error: don't support it */
761 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
762 drawattrib |= GLX_PBUFFER_BIT;
766 case WGL_FLOAT_COMPONENTS_NV:
767 nvfloatattrib = iWGLAttr[++cur];
768 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
770 case WGL_BIND_TO_TEXTURE_DEPTH_NV:
771 case WGL_BIND_TO_TEXTURE_RGB_ARB:
772 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
773 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
774 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
775 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
776 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
777 pop = iWGLAttr[++cur];
778 /** cannot be converted, see direct handling on
779 * - wglGetPixelFormatAttribivARB
780 * TODO: wglChoosePixelFormat
785 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
793 WARN("Attempting double-buffered gdi format\n");
797 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, False);
800 /* Apply the OR'd drawable type bitmask now EVEN when WGL_DRAW_TO* is unset.
801 * It is needed in all cases because GLX_DRAWABLE_TYPE default to GLX_WINDOW_BIT. */
802 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
803 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
805 /* Set GLX_RENDER_TYPE all the time */
806 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
807 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
809 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
810 if(strstr(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
811 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
812 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
818 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
820 int render_type=0, render_type_bit;
821 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
822 switch(render_type_bit)
825 render_type = GLX_RGBA_TYPE;
827 case GLX_COLOR_INDEX_BIT:
828 render_type = GLX_COLOR_INDEX_TYPE;
830 case GLX_RGBA_FLOAT_BIT:
831 render_type = GLX_RGBA_FLOAT_TYPE;
834 ERR("Unknown render_type: %x\n", render_type);
839 static BOOL init_formats(Display *display, int screen, Visual *visual)
841 int fmt_id, nCfgs, i, run;
843 XVisualInfo *visinfo;
845 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
846 if (NULL == cfgs || 0 == nCfgs) {
847 ERR("glXChooseFBConfig returns NULL\n");
848 if(cfgs != NULL) XFree(cfgs);
852 WineGLPixelFormatList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nCfgs*sizeof(WineGLPixelFormat));
854 /* Fill the pixel format list. Put onscreen formats at the top and offscreen ones at the bottom.
855 * Do this as GLX doesn't guarantee that the list is sorted */
856 for(run=0; run < 2; run++)
858 for(i=0; i<nCfgs; i++) {
859 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
860 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
862 /* The first run we only add onscreen formats (ones which have an associated X Visual).
863 * The second run we only set offscreen formats. */
866 /* We implement child window rendering using offscreen buffers (using composite or an XPixmap).
867 * The contents is copied to the destination using XCopyArea. For the copying to work
868 * the depth of the source and destination window should be the same. In general this should
869 * not be a problem for OpenGL as drivers only advertise formats with a similar depth (or no depth).
870 * As of the introduction of composition managers at least Nvidia now also offers ARGB visuals
871 * with a depth of 32 in addition to the default 24 bit. In order to prevent BadMatch errors we only
872 * list formats with the same depth. */
873 if(visinfo->depth != screen_depth)
876 TRACE("Found onscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, WineGLPixelFormatListSize+1, i);
877 WineGLPixelFormatList[WineGLPixelFormatListSize].iPixelFormat = WineGLPixelFormatListSize+1; /* The index starts at 1 */
878 WineGLPixelFormatList[WineGLPixelFormatListSize].fbconfig = cfgs[i];
879 WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_id = fmt_id;
880 WineGLPixelFormatList[WineGLPixelFormatListSize].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
882 WineGLPixelFormatList[WineGLPixelFormatListSize].offscreenOnly = FALSE;
883 WineGLPixelFormatListSize++;
884 WineGLPixelFormatOnScreenSize++;
886 } else if(run && !visinfo) {
887 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", fmt_id, WineGLPixelFormatListSize+1, i);
888 WineGLPixelFormatList[WineGLPixelFormatListSize].iPixelFormat = WineGLPixelFormatListSize+1; /* The index starts at 1 */
889 WineGLPixelFormatList[WineGLPixelFormatListSize].fbconfig = cfgs[i];
890 WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_id = fmt_id;
891 WineGLPixelFormatList[WineGLPixelFormatListSize].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
893 WineGLPixelFormatList[WineGLPixelFormatListSize].offscreenOnly = TRUE;
894 WineGLPixelFormatListSize++;
899 if(cfgs != NULL) XFree(cfgs);
904 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
905 * In our WGL implementation we only support a subset of these formats namely the format of
906 * Wine's main visual and offscreen formats (if they are available).
907 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
908 * and it returns the number of supported WGL formats in fmt_count.
910 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count)
912 WineGLPixelFormat *res = NULL;
914 /* Init the list of pixel formats when we need it */
915 if(!WineGLPixelFormatListSize)
916 init_formats(display, DefaultScreen(display), visual);
918 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
919 * iPixelFormat in case of probing the number of pixelformats.
921 if((iPixelFormat > 0) && (iPixelFormat <= WineGLPixelFormatListSize) &&
922 ((WineGLPixelFormatList[iPixelFormat-1].offscreenOnly == FALSE) ||
924 res = &WineGLPixelFormatList[iPixelFormat-1];
925 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res->fbconfig, iPixelFormat);
929 *fmt_count = WineGLPixelFormatListSize;
931 *fmt_count = WineGLPixelFormatOnScreenSize;
933 TRACE("Number of returned pixelformats=%d\n", *fmt_count);
938 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
939 static WineGLPixelFormat* ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id)
943 /* Init the list of pixel formats when we need it */
944 if(!WineGLPixelFormatListSize)
945 init_formats(display, DefaultScreen(display), visual);
947 for(i=0; i<WineGLPixelFormatListSize; i++) {
948 if(WineGLPixelFormatList[i].fmt_id == fmt_id) {
949 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", WineGLPixelFormatList[i].iPixelFormat, fmt_id);
950 return &WineGLPixelFormatList[i];
953 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id);
957 int pixelformat_from_fbconfig_id(XID fbconfig_id)
959 WineGLPixelFormat *fmt;
961 if (!fbconfig_id) return 0;
963 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id);
965 return fmt->iPixelFormat;
966 /* This will happen on hwnds without a pixel format set; it's ok */
971 /* Mark any allocated context using the glx drawable 'old' to use 'new' */
972 void mark_drawable_dirty(Drawable old, Drawable new)
975 for (ctx = context_list; ctx; ctx = ctx->next) {
976 if (old == ctx->drawables[0]) {
977 ctx->drawables[0] = new;
978 ctx->refresh_drawables = TRUE;
980 if (old == ctx->drawables[1]) {
981 ctx->drawables[1] = new;
982 ctx->refresh_drawables = TRUE;
987 /* Given the current context, make sure its drawable is sync'd */
988 static inline void sync_context(Wine_GLContext *context)
990 if(context && context->refresh_drawables) {
991 if (glxRequireVersion(3))
992 pglXMakeContextCurrent(gdi_display, context->drawables[0],
993 context->drawables[1], context->ctx);
995 pglXMakeCurrent(gdi_display, context->drawables[0], context->ctx);
996 context->refresh_drawables = FALSE;
1001 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
1003 return pglXCreateGLXPixmap(display, vis, parent);
1007 static XID create_bitmap_glxpixmap(X11DRV_PDEVICE *physDev, WineGLPixelFormat *fmt)
1014 vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1016 if(vis->depth == physDev->bitmap->pixmap_depth)
1017 ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
1020 wine_tsx11_unlock();
1021 TRACE("return %lx\n", ret);
1026 * X11DRV_ChoosePixelFormat
1028 * Equivalent to glXChooseVisual.
1030 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
1031 const PIXELFORMATDESCRIPTOR *ppfd) {
1032 WineGLPixelFormat *fmt = NULL;
1037 int bestFormat = -1;
1038 int bestDBuffer = -1;
1039 int bestStereo = -1;
1043 int bestStencil = -1;
1047 if (!has_opengl()) {
1048 ERR("No libGL on this box - disabling OpenGL support !\n");
1052 if (TRACE_ON(wgl)) {
1053 TRACE("(%p,%p)\n", physDev, ppfd);
1055 dump_PIXELFORMATDESCRIPTOR(ppfd);
1059 ConvertPixelFormatWGLtoGLX(gdi_display, 0, FALSE /* offscreen */, &nPixelFormats);
1060 for(i=0; i<nPixelFormats; i++)
1064 int alpha=0, color=0, depth=0, stencil=0, aux=0;
1066 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, i+1 /* 1-based index */, FALSE /* offscreen */, &value);
1070 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1071 if (value & GLX_RGBA_BIT)
1072 iPixelType = PFD_TYPE_RGBA;
1074 iPixelType = PFD_TYPE_COLORINDEX;
1076 if (ppfd->iPixelType != iPixelType)
1078 TRACE("pixel type mismatch for iPixelFormat=%d\n", i+1);
1082 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1083 if (value) dwFlags |= PFD_DOUBLEBUFFER;
1084 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value);
1085 if (value) dwFlags |= PFD_STEREO;
1086 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &color); /* cColorBits */
1087 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &alpha); /* cAlphaBits */
1088 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &depth); /* cDepthBits */
1089 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &stencil); /* cStencilBits */
1090 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &aux); /* cAuxBuffers */
1092 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1093 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1094 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1095 * formats without the given flag set.
1096 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1097 * has indicated that a format without stereo is returned when stereo is unavailable.
1098 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1099 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1101 * To summarize the following is most likely the correct behavior:
1102 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1103 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1104 * stereo don't care -> it doesn't matter whether we get stereo or not
1106 * In Wine we will treat no-stereo the same way as don't care because it makes
1107 * format selection even more complicated and second drivers with Stereo advertise
1108 * each format twice anyway.
1111 /* Doublebuffer, see the comments above */
1112 if( !(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) ) {
1113 if( ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) &&
1114 ((dwFlags & PFD_DOUBLEBUFFER) == (ppfd->dwFlags & PFD_DOUBLEBUFFER)) )
1116 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1117 bestStereo = dwFlags & PFD_STEREO;
1121 bestStencil = stencil;
1126 if(bestDBuffer != -1 && (dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer)
1130 /* Stereo, see the comments above. */
1131 if( !(ppfd->dwFlags & PFD_STEREO_DONTCARE) ) {
1132 if( ((ppfd->dwFlags & PFD_STEREO) != bestStereo) &&
1133 ((dwFlags & PFD_STEREO) == (ppfd->dwFlags & PFD_STEREO)) )
1135 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1136 bestStereo = dwFlags & PFD_STEREO;
1140 bestStencil = stencil;
1145 if(bestStereo != -1 && (dwFlags & PFD_STEREO) != bestStereo)
1149 /* Below we will do a number of checks to select the 'best' pixelformat.
1150 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1151 * The code works by trying to match the most important options as close as possible.
1152 * When a reasonable format is found, we will try to match more options.
1153 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
1154 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
1155 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
1158 if(ppfd->cColorBits) {
1159 if( ((ppfd->cColorBits > bestColor) && (color > bestColor)) ||
1160 ((color >= ppfd->cColorBits) && (color < bestColor)) )
1162 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1163 bestStereo = dwFlags & PFD_STEREO;
1167 bestStencil = stencil;
1171 } else if(bestColor != color) { /* Do further checks if the format is compatible */
1172 TRACE("color mismatch for iPixelFormat=%d\n", i+1);
1178 if(ppfd->cAlphaBits) {
1179 if( ((ppfd->cAlphaBits > bestAlpha) && (alpha > bestAlpha)) ||
1180 ((alpha >= ppfd->cAlphaBits) && (alpha < bestAlpha)) )
1182 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1183 bestStereo = dwFlags & PFD_STEREO;
1187 bestStencil = stencil;
1191 } else if(bestAlpha != alpha) {
1192 TRACE("alpha mismatch for iPixelFormat=%d\n", i+1);
1198 if(ppfd->cDepthBits) {
1199 if( ((ppfd->cDepthBits > bestDepth) && (depth > bestDepth)) ||
1200 ((depth >= ppfd->cDepthBits) && (depth < bestDepth)) )
1202 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1203 bestStereo = dwFlags & PFD_STEREO;
1207 bestStencil = stencil;
1211 } else if(bestDepth != depth) {
1212 TRACE("depth mismatch for iPixelFormat=%d\n", i+1);
1218 if(ppfd->cStencilBits) {
1219 if( ((ppfd->cStencilBits > bestStencil) && (stencil > bestStencil)) ||
1220 ((stencil >= ppfd->cStencilBits) && (stencil < bestStencil)) )
1222 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1223 bestStereo = dwFlags & PFD_STEREO;
1227 bestStencil = stencil;
1231 } else if(bestStencil != stencil) {
1232 TRACE("stencil mismatch for iPixelFormat=%d\n", i+1);
1238 if(ppfd->cAuxBuffers) {
1239 if( ((ppfd->cAuxBuffers > bestAux) && (aux > bestAux)) ||
1240 ((aux >= ppfd->cAuxBuffers) && (aux < bestAux)) )
1242 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1243 bestStereo = dwFlags & PFD_STEREO;
1247 bestStencil = stencil;
1251 } else if(bestAux != aux) {
1252 TRACE("aux mismatch for iPixelFormat=%d\n", i+1);
1258 if(bestFormat == -1) {
1259 TRACE("No matching mode was found returning 0\n");
1263 ret = bestFormat+1; /* the return value should be a 1-based index */
1264 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret, WineGLPixelFormatList[bestFormat].fmt_id);
1267 wine_tsx11_unlock();
1272 * X11DRV_DescribePixelFormat
1274 * Get the pixel-format descriptor associated to the given id
1276 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
1279 PIXELFORMATDESCRIPTOR *ppfd) {
1280 /*XVisualInfo *vis;*/
1283 WineGLPixelFormat *fmt;
1287 if (!has_opengl()) {
1288 ERR("No libGL on this box - disabling OpenGL support !\n");
1292 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
1294 /* 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 */
1295 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_count);
1297 /* The application is only querying the number of pixelformats */
1299 } else if(fmt == NULL) {
1300 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1304 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1305 ERR("Wrong structure size !\n");
1306 /* Should set error */
1312 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1313 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1316 /* These flags are always the same... */
1317 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1318 /* Now the flags extracted from the Visual */
1322 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_X_RENDERABLE, &value);
1324 ppfd->dwFlags |= PFD_SUPPORT_GDI;
1326 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1327 if(value & GLX_WINDOW_BIT)
1328 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1329 if(value & GLX_PIXMAP_BIT)
1330 ppfd->dwFlags |= PFD_DRAW_TO_BITMAP;
1332 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_CONFIG_CAVEAT, &value);
1333 if(value == GLX_SLOW_CONFIG)
1334 ppfd->dwFlags |= PFD_GENERIC_ACCELERATED;
1336 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1338 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1339 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1341 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1344 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1345 if (value & GLX_RGBA_BIT)
1346 ppfd->iPixelType = PFD_TYPE_RGBA;
1348 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1351 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1352 ppfd->cColorBits = value;
1354 /* Red, green, blue and alpha bits / shifts */
1355 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1356 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1357 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1358 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1359 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1361 ppfd->cRedBits = rb;
1362 ppfd->cRedShift = gb + bb + ab;
1363 ppfd->cBlueBits = bb;
1364 ppfd->cBlueShift = ab;
1365 ppfd->cGreenBits = gb;
1366 ppfd->cGreenShift = bb + ab;
1367 ppfd->cAlphaBits = ab;
1368 ppfd->cAlphaShift = 0;
1371 ppfd->cRedShift = 0;
1372 ppfd->cBlueBits = 0;
1373 ppfd->cBlueShift = 0;
1374 ppfd->cGreenBits = 0;
1375 ppfd->cGreenShift = 0;
1376 ppfd->cAlphaBits = 0;
1377 ppfd->cAlphaShift = 0;
1380 /* Accum RGBA bits */
1381 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1382 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1383 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1384 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1386 ppfd->cAccumBits = rb+gb+bb+ab;
1387 ppfd->cAccumRedBits = rb;
1388 ppfd->cAccumGreenBits = gb;
1389 ppfd->cAccumBlueBits = bb;
1390 ppfd->cAccumAlphaBits = ab;
1393 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1394 ppfd->cAuxBuffers = value;
1397 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1398 ppfd->cDepthBits = value;
1401 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1402 ppfd->cStencilBits = value;
1404 wine_tsx11_unlock();
1406 ppfd->iLayerType = PFD_MAIN_PLANE;
1408 if (TRACE_ON(wgl)) {
1409 dump_PIXELFORMATDESCRIPTOR(ppfd);
1416 * X11DRV_GetPixelFormat
1418 * Get the pixel-format id used by this DC
1420 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
1421 WineGLPixelFormat *fmt;
1423 TRACE("(%p)\n", physDev);
1425 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physDev->current_pf, TRUE, &tmp);
1428 /* This happens on HDCs on which SetPixelFormat wasn't called yet */
1429 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev->current_pf);
1432 else if(fmt->offscreenOnly)
1434 /* Offscreen formats can't be used with traditional WGL calls.
1435 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1436 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt->iPixelFormat);
1440 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1441 return physDev->current_pf;
1445 * X11DRV_SetPixelFormat
1447 * Set the pixel-format id used by this DC
1449 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
1451 const PIXELFORMATDESCRIPTOR *ppfd) {
1452 WineGLPixelFormat *fmt;
1456 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1458 if (!has_opengl()) {
1459 ERR("No libGL on this box - disabling OpenGL support !\n");
1463 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1464 if(get_glxdrawable(physDev) == root_window)
1466 ERR("Invalid operation on root_window\n");
1470 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1471 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
1473 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1477 if(physDev->current_pf) /* cannot change it if already set */
1478 return (physDev->current_pf == iPixelFormat);
1480 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1482 hwnd = WindowFromDC(physDev->hdc);
1484 if(!(value&GLX_WINDOW_BIT)) {
1485 WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat);
1489 if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, (WPARAM)fmt->fmt_id, 0)) {
1490 ERR("Couldn't set format of the window, returning failure\n");
1494 else if(physDev->bitmap) {
1495 if(!(value&GLX_PIXMAP_BIT)) {
1496 WARN("Pixel format %d is not compatible for bitmap rendering\n", iPixelFormat);
1500 physDev->bitmap->glxpixmap = create_bitmap_glxpixmap(physDev, fmt);
1501 if(!physDev->bitmap->glxpixmap) {
1502 WARN("Couldn't create glxpixmap for pixel format %d\n", iPixelFormat);
1507 FIXME("called on a non-window, non-bitmap object?\n");
1510 physDev->current_pf = iPixelFormat;
1512 if (TRACE_ON(wgl)) {
1515 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1517 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1519 TRACE(" FBConfig have :\n");
1520 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1521 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1522 TRACE(" - VISUAL_ID 0x%x\n", value);
1523 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1524 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1531 * X11DRV_wglCopyContext
1533 * For OpenGL32 wglCopyContext.
1535 BOOL X11DRV_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask) {
1536 Wine_GLContext *src = (Wine_GLContext*)hglrcSrc;
1537 Wine_GLContext *dst = (Wine_GLContext*)hglrcDst;
1539 TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc, hglrcDst, mask);
1541 /* There is a slight difference in the way GL contexts share display lists in WGL and GLX.
1542 * In case of GLX you need to specify this at context creation time but in case of WGL you
1543 * do this using wglShareLists which you can call after creating the context.
1544 * To emulate WGL we try to delay the creation of the context until wglShareLists or wglMakeCurrent.
1545 * Up to now that works fine.
1547 * The delayed GLX context creation could cause issues for wglCopyContext as it might get called
1548 * when there is no GLX context yet. The chance this will cause problems is small as at the time of
1549 * writing Wine has had OpenGL support for more than 7 years and this function has remained a stub
1552 if(!src->ctx || !dst->ctx) {
1553 /* NOTE: As a special case, if both GLX contexts are NULL, that means
1554 * neither WGL context was made current. In that case, both contexts
1555 * are in a default state, so any copy would no-op.
1557 if(!src->ctx && !dst->ctx) {
1558 TRACE("No source or destination contexts set. No-op.\n");
1563 DWORD type = GetObjectType(src->hdc);
1566 src->ctx = pglXCreateContext(gdi_display, src->vis, NULL, type == OBJ_MEMDC ? False : True);
1567 else /* Create a GLX Context for a pbuffer */
1568 src->ctx = pglXCreateNewContext(gdi_display, src->fmt->fbconfig, src->fmt->render_type, NULL, True);
1569 TRACE(" created a delayed OpenGL context (%p)\n", src->ctx);
1571 else if (!dst->ctx) {
1572 DWORD type = GetObjectType(dst->hdc);
1575 dst->ctx = pglXCreateContext(gdi_display, dst->vis, NULL, type == OBJ_MEMDC ? False : True);
1576 else /* Create a GLX Context for a pbuffer */
1577 dst->ctx = pglXCreateNewContext(gdi_display, dst->fmt->fbconfig, dst->fmt->render_type, NULL, True);
1578 TRACE(" created a delayed OpenGL context (%p)\n", dst->ctx);
1584 pglXCopyContext(gdi_display, src->ctx, dst->ctx, mask);
1585 wine_tsx11_unlock();
1587 /* As opposed to wglCopyContext, glXCopyContext doesn't return anything, so hopefully we passed */
1592 * X11DRV_wglCreateContext
1594 * For OpenGL32 wglCreateContext.
1596 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
1598 Wine_GLContext *ret;
1599 WineGLPixelFormat *fmt;
1600 int hdcPF = physDev->current_pf;
1602 HDC hdc = physDev->hdc;
1604 TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1606 if (!has_opengl()) {
1607 ERR("No libGL on this box - disabling OpenGL support !\n");
1611 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, TRUE /* Offscreen */, &fmt_count);
1612 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1613 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1614 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1615 * If this fails something is very wrong on the system. */
1617 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF);
1618 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1622 /* The context will be allocated in the wglMakeCurrent call */
1624 ret = alloc_context();
1625 wine_tsx11_unlock();
1630 ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1632 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1637 * X11DRV_wglDeleteContext
1639 * For OpenGL32 wglDeleteContext.
1641 BOOL X11DRV_wglDeleteContext(HGLRC hglrc)
1643 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1646 TRACE("(%p)\n", hglrc);
1648 if (!has_opengl()) {
1649 ERR("No libGL on this box - disabling OpenGL support !\n");
1654 /* A game (Half Life not to name it) deletes twice the same context,
1655 * so make sure it is valid first */
1656 if (is_valid_context( ctx ))
1658 if (ctx->ctx) pglXDestroyContext(gdi_display, ctx->ctx);
1663 WARN("Error deleting context !\n");
1664 SetLastError(ERROR_INVALID_HANDLE);
1667 wine_tsx11_unlock();
1673 * X11DRV_wglGetCurrentReadDCARB
1675 * For OpenGL32 wglGetCurrentReadDCARB.
1677 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1680 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1682 if (ctx) ret = ctx->read_hdc;
1684 TRACE(" returning %p (GL drawable %lu)\n", ret, ctx ? ctx->drawables[1] : 0);
1689 * X11DRV_wglGetProcAddress
1691 * For OpenGL32 wglGetProcAddress.
1693 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1696 const WineGLExtension *ext;
1698 int padding = 32 - strlen(lpszProc);
1702 if (!has_opengl()) {
1703 ERR("No libGL on this box - disabling OpenGL support !\n");
1707 /* Check the table of WGL extensions to see if we need to return a WGL extension
1708 * or a function pointer to a native OpenGL function. */
1709 if(strncmp(lpszProc, "wgl", 3) != 0) {
1710 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1712 TRACE("('%s'):%*s", lpszProc, padding, " ");
1713 for (i = 0; i < WineGLExtensionListSize; ++i) {
1714 ext = WineGLExtensionList[i];
1715 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1716 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1717 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1718 return ext->extEntryPoints[j].funcAddress;
1724 WARN("(%s) - not found\n", lpszProc);
1729 * X11DRV_wglMakeCurrent
1731 * For OpenGL32 wglMakeCurrent.
1733 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
1735 HDC hdc = physDev->hdc;
1736 DWORD type = GetObjectType(hdc);
1738 TRACE("(%p,%p)\n", hdc, hglrc);
1740 if (!has_opengl()) {
1741 ERR("No libGL on this box - disabling OpenGL support !\n");
1746 if (hglrc == NULL) {
1747 ret = pglXMakeCurrent(gdi_display, None, NULL);
1748 NtCurrentTeb()->glContext = NULL;
1750 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1751 Drawable drawable = get_glxdrawable(physDev);
1752 if (ctx->ctx == NULL) {
1753 /* The describe lines below are for debugging purposes only */
1754 if (TRACE_ON(wgl)) {
1755 describeDrawable(ctx, drawable);
1756 describeContext(ctx);
1759 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1760 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1762 TRACE(" Creating GLX Context\n");
1764 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, type == OBJ_MEMDC ? False : True);
1765 else /* Create a GLX Context for a pbuffer */
1766 ctx->ctx = pglXCreateNewContext(gdi_display, ctx->fmt->fbconfig, ctx->fmt->render_type, NULL, True);
1768 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1770 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display, (void*) drawable, ctx->ctx);
1771 ret = pglXMakeCurrent(gdi_display, drawable, ctx->ctx);
1772 NtCurrentTeb()->glContext = ctx;
1776 ctx->read_hdc = hdc;
1777 ctx->drawables[0] = drawable;
1778 ctx->drawables[1] = drawable;
1779 ctx->refresh_drawables = FALSE;
1781 if (type == OBJ_MEMDC)
1783 ctx->do_escape = TRUE;
1784 pglDrawBuffer(GL_FRONT_LEFT);
1788 wine_tsx11_unlock();
1789 TRACE(" returning %s\n", (ret ? "True" : "False"));
1794 * X11DRV_wglMakeContextCurrentARB
1796 * For OpenGL32 wglMakeContextCurrentARB
1798 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* pDrawDev, X11DRV_PDEVICE* pReadDev, HGLRC hglrc)
1801 int indirect = (GetObjectType(pDrawDev->hdc) == OBJ_MEMDC);
1803 TRACE("(%p,%p,%p)\n", pDrawDev, pReadDev, hglrc);
1805 if (!has_opengl()) {
1806 ERR("No libGL on this box - disabling OpenGL support !\n");
1811 if (hglrc == NULL) {
1812 ret = pglXMakeCurrent(gdi_display, None, NULL);
1813 NtCurrentTeb()->glContext = NULL;
1815 if (NULL == pglXMakeContextCurrent) {
1818 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1819 Drawable d_draw = get_glxdrawable(pDrawDev);
1820 Drawable d_read = get_glxdrawable(pReadDev);
1822 if (ctx->ctx == NULL) {
1823 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, !indirect);
1824 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1826 ctx->hdc = pDrawDev->hdc;
1827 ctx->read_hdc = pReadDev->hdc;
1828 ctx->drawables[0] = d_draw;
1829 ctx->drawables[1] = d_read;
1830 ctx->refresh_drawables = FALSE;
1831 ret = pglXMakeContextCurrent(gdi_display, d_draw, d_read, ctx->ctx);
1832 NtCurrentTeb()->glContext = ctx;
1835 wine_tsx11_unlock();
1837 TRACE(" returning %s\n", (ret ? "True" : "False"));
1842 * X11DRV_wglShareLists
1844 * For OpenGL32 wglShaderLists.
1846 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
1847 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1848 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1850 TRACE("(%p, %p)\n", org, dest);
1852 if (!has_opengl()) {
1853 ERR("No libGL on this box - disabling OpenGL support !\n");
1857 if (NULL != dest && dest->ctx != NULL) {
1858 ERR("Could not share display lists, context already created !\n");
1861 if (org->ctx == NULL) {
1862 int indirect = (GetObjectType(org->hdc) == OBJ_MEMDC);
1864 describeContext(org);
1867 org->ctx = pglXCreateContext(gdi_display, org->vis, NULL, !indirect);
1868 else /* Create a GLX Context for a pbuffer */
1869 org->ctx = pglXCreateNewContext(gdi_display, org->fmt->fbconfig, org->fmt->render_type, NULL, True);
1870 wine_tsx11_unlock();
1871 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org->ctx, org);
1874 int indirect = (GetObjectType(dest->hdc) == OBJ_MEMDC);
1876 describeContext(dest);
1877 /* Create the destination context with display lists shared */
1879 dest->ctx = pglXCreateContext(gdi_display, dest->vis, org->ctx, !indirect);
1880 else /* Create a GLX Context for a pbuffer */
1881 dest->ctx = pglXCreateNewContext(gdi_display, dest->fmt->fbconfig, dest->fmt->render_type, org->ctx, True);
1882 wine_tsx11_unlock();
1883 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1890 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
1892 /* We are running using client-side rendering fonts... */
1896 void *bitmap = NULL, *gl_bitmap = NULL;
1900 pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1901 pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1902 wine_tsx11_unlock();
1904 for (glyph = first; glyph < first + count; glyph++) {
1905 unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, NULL);
1906 int height, width_int;
1908 TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
1909 if (needed_size == GDI_ERROR) {
1910 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size);
1913 TRACE(" - needed size : %d\n", needed_size);
1916 if (needed_size > size) {
1918 HeapFree(GetProcessHeap(), 0, bitmap);
1919 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1920 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1921 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1923 if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, NULL) == GDI_ERROR) goto error;
1924 if (TRACE_ON(wgl)) {
1925 unsigned int height, width, bitmask;
1926 unsigned char *bitmap_ = (unsigned char *) bitmap;
1928 TRACE(" - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
1929 TRACE(" - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
1930 TRACE(" - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
1931 if (needed_size != 0) {
1932 TRACE(" - bitmap :\n");
1933 for (height = 0; height < gm.gmBlackBoxY; height++) {
1935 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
1940 if (*bitmap_ & bitmask)
1945 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
1951 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1952 * glyph for it to be drawn properly.
1954 if (needed_size != 0) {
1955 width_int = (gm.gmBlackBoxX + 31) / 32;
1956 for (height = 0; height < gm.gmBlackBoxY; height++) {
1958 for (width = 0; width < width_int; width++) {
1959 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
1960 ((int *) bitmap)[height * width_int + width];
1966 pglNewList(listBase++, GL_COMPILE);
1967 if (needed_size != 0) {
1968 pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
1969 0 - gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - gm.gmptGlyphOrigin.y,
1970 gm.gmCellIncX, gm.gmCellIncY,
1973 /* This is the case of 'empty' glyphs like the space character */
1974 pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
1977 wine_tsx11_unlock();
1981 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1982 wine_tsx11_unlock();
1984 HeapFree(GetProcessHeap(), 0, bitmap);
1985 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1990 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1991 wine_tsx11_unlock();
1993 HeapFree(GetProcessHeap(), 0, bitmap);
1994 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1999 * X11DRV_wglUseFontBitmapsA
2001 * For OpenGL32 wglUseFontBitmapsA.
2003 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
2005 Font fid = physDev->font;
2007 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
2009 if (!has_opengl()) {
2010 ERR("No libGL on this box - disabling OpenGL support !\n");
2015 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineA);
2019 /* I assume that the glyphs are at the same position for X and for Windows */
2020 pglXUseXFont(fid, first, count, listBase);
2021 wine_tsx11_unlock();
2026 * X11DRV_wglUseFontBitmapsW
2028 * For OpenGL32 wglUseFontBitmapsW.
2030 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
2032 Font fid = physDev->font;
2034 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
2036 if (!has_opengl()) {
2037 ERR("No libGL on this box - disabling OpenGL support !\n");
2042 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineW);
2045 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
2048 /* I assume that the glyphs are at the same position for X and for Windows */
2049 pglXUseXFont(fid, first, count, listBase);
2050 wine_tsx11_unlock();
2054 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
2055 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params)
2062 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2064 pglGetIntegerv(pname, params);
2066 * if we cannot find a Wine Context
2067 * we only have the default wine desktop context,
2068 * so if we have only a 24 depth say we have 32
2070 if (!ctx && *params == 24) {
2073 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
2078 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2080 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_ALPHA_SIZE, params);
2081 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params);
2085 pglGetIntegerv(pname, params);
2088 wine_tsx11_unlock();
2091 void flush_gl_drawable(X11DRV_PDEVICE *physDev)
2095 if(!physDev->gl_drawable)
2098 w = physDev->dc_rect.right - physDev->dc_rect.left;
2099 h = physDev->dc_rect.bottom - physDev->dc_rect.top;
2101 if(w > 0 && h > 0) {
2102 Drawable src = physDev->pixmap;
2103 if(!src) src = physDev->gl_drawable;
2105 /* The GL drawable may be lagged behind if we don't flush first, so
2106 * flush the display make sure we copy up-to-date data */
2108 XFlush(gdi_display);
2109 XCopyArea(gdi_display, src, physDev->drawable, physDev->gc, 0, 0, w, h,
2110 physDev->dc_rect.left, physDev->dc_rect.top);
2111 wine_tsx11_unlock();
2116 static void WINAPI X11DRV_wglFinish(void)
2118 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2119 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2124 wine_tsx11_unlock();
2125 ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2128 static void WINAPI X11DRV_wglFlush(void)
2130 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
2131 enum x11drv_escape_codes code = X11DRV_FLUSH_GL_DRAWABLE;
2136 wine_tsx11_unlock();
2137 ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
2141 * X11DRV_wglGetExtensionsStringARB
2143 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2145 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
2146 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2147 return WineGLInfo.wglExtensions;
2151 * X11DRV_wglCreatePbufferARB
2153 * WGL_ARB_pbuffer: wglCreatePbufferARB
2155 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
2157 Wine_GLPBuffer* object = NULL;
2158 WineGLPixelFormat *fmt = NULL;
2163 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2165 if (0 >= iPixelFormat) {
2166 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
2167 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2168 return NULL; /* unexpected error */
2171 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2172 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nCfgs);
2174 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
2175 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2176 goto create_failed; /* unexpected error */
2179 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
2180 if (NULL == object) {
2181 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2182 goto create_failed; /* unexpected error */
2185 object->display = gdi_display;
2186 object->width = iWidth;
2187 object->height = iHeight;
2190 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2191 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2192 while (piAttribList && 0 != *piAttribList) {
2194 switch (*piAttribList) {
2195 case WGL_PBUFFER_LARGEST_ARB: {
2197 attr_v = *piAttribList;
2198 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2199 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2203 case WGL_TEXTURE_FORMAT_ARB: {
2205 attr_v = *piAttribList;
2206 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2207 if (use_render_texture_ati) {
2210 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2211 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
2212 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
2214 SetLastError(ERROR_INVALID_DATA);
2217 object->use_render_texture = 1;
2218 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
2220 if (WGL_NO_TEXTURE_ARB == attr_v) {
2221 object->use_render_texture = 0;
2223 if (!use_render_texture_emulation) {
2224 SetLastError(ERROR_INVALID_DATA);
2228 case WGL_TEXTURE_RGB_ARB:
2229 object->use_render_texture = GL_RGB;
2230 object->texture_bpp = 3;
2231 object->texture_format = GL_RGB;
2232 object->texture_type = GL_UNSIGNED_BYTE;
2234 case WGL_TEXTURE_RGBA_ARB:
2235 object->use_render_texture = GL_RGBA;
2236 object->texture_bpp = 4;
2237 object->texture_format = GL_RGBA;
2238 object->texture_type = GL_UNSIGNED_BYTE;
2241 /* WGL_FLOAT_COMPONENTS_NV */
2242 case WGL_TEXTURE_FLOAT_R_NV:
2243 object->use_render_texture = GL_FLOAT_R_NV;
2244 object->texture_bpp = 4;
2245 object->texture_format = GL_RED;
2246 object->texture_type = GL_FLOAT;
2248 case WGL_TEXTURE_FLOAT_RG_NV:
2249 object->use_render_texture = GL_FLOAT_RG_NV;
2250 object->texture_bpp = 8;
2251 object->texture_format = GL_LUMINANCE_ALPHA;
2252 object->texture_type = GL_FLOAT;
2254 case WGL_TEXTURE_FLOAT_RGB_NV:
2255 object->use_render_texture = GL_FLOAT_RGB_NV;
2256 object->texture_bpp = 12;
2257 object->texture_format = GL_RGB;
2258 object->texture_type = GL_FLOAT;
2260 case WGL_TEXTURE_FLOAT_RGBA_NV:
2261 object->use_render_texture = GL_FLOAT_RGBA_NV;
2262 object->texture_bpp = 16;
2263 object->texture_format = GL_RGBA;
2264 object->texture_type = GL_FLOAT;
2267 ERR("Unknown texture format: %x\n", attr_v);
2268 SetLastError(ERROR_INVALID_DATA);
2276 case WGL_TEXTURE_TARGET_ARB: {
2278 attr_v = *piAttribList;
2279 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2280 if (use_render_texture_ati) {
2283 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2284 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
2285 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
2286 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
2288 SetLastError(ERROR_INVALID_DATA);
2291 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
2293 if (WGL_NO_TEXTURE_ARB == attr_v) {
2294 object->texture_target = 0;
2296 if (!use_render_texture_emulation) {
2297 SetLastError(ERROR_INVALID_DATA);
2301 case WGL_TEXTURE_CUBE_MAP_ARB: {
2302 if (iWidth != iHeight) {
2303 SetLastError(ERROR_INVALID_DATA);
2306 object->texture_target = GL_TEXTURE_CUBE_MAP;
2307 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2310 case WGL_TEXTURE_1D_ARB: {
2312 SetLastError(ERROR_INVALID_DATA);
2315 object->texture_target = GL_TEXTURE_1D;
2316 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2319 case WGL_TEXTURE_2D_ARB: {
2320 object->texture_target = GL_TEXTURE_2D;
2321 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2324 case WGL_TEXTURE_RECTANGLE_NV: {
2325 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2326 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2330 ERR("Unknown texture target: %x\n", attr_v);
2331 SetLastError(ERROR_INVALID_DATA);
2339 case WGL_MIPMAP_TEXTURE_ARB: {
2341 attr_v = *piAttribList;
2342 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2343 if (use_render_texture_ati) {
2344 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
2346 if (!use_render_texture_emulation) {
2347 SetLastError(ERROR_INVALID_DATA);
2357 PUSH1(attribs, None);
2358 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2359 TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
2360 if (!object->drawable) {
2361 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2362 goto create_failed; /* unexpected error */
2364 TRACE("->(%p)\n", object);
2365 return (HPBUFFERARB) object;
2368 HeapFree(GetProcessHeap(), 0, object);
2369 TRACE("->(FAILED)\n");
2374 * X11DRV_wglDestroyPbufferARB
2376 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2378 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2380 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2381 TRACE("(%p)\n", hPbuffer);
2382 if (NULL == object) {
2383 SetLastError(ERROR_INVALID_HANDLE);
2386 pglXDestroyPbuffer(object->display, object->drawable);
2387 HeapFree(GetProcessHeap(), 0, object);
2392 * X11DRV_wglGetPbufferDCARB
2394 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2395 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2396 * Gdi32 implements the part of this function which creates a device context.
2397 * This part associates the physDev with the X drawable of the pbuffer.
2399 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
2401 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2402 if (NULL == object) {
2403 SetLastError(ERROR_INVALID_HANDLE);
2407 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2408 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2409 physDev->current_pf = object->fmt->iPixelFormat;
2410 physDev->drawable = object->drawable;
2411 SetRect( &physDev->drawable_rect, 0, 0, object->width, object->height );
2412 physDev->dc_rect = physDev->drawable_rect;
2414 TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);
2415 return physDev->hdc;
2419 * X11DRV_wglQueryPbufferARB
2421 * WGL_ARB_pbuffer: wglQueryPbufferARB
2423 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2425 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2426 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2427 if (NULL == object) {
2428 SetLastError(ERROR_INVALID_HANDLE);
2431 switch (iAttribute) {
2432 case WGL_PBUFFER_WIDTH_ARB:
2433 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2435 case WGL_PBUFFER_HEIGHT_ARB:
2436 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2439 case WGL_PBUFFER_LOST_ARB:
2440 /* GLX Pbuffers cannot be lost by default. We can support this by
2441 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2442 * to receive pixel buffer clobber events, however that may or may
2443 * not give any benefit */
2444 *piValue = GL_FALSE;
2447 case WGL_TEXTURE_FORMAT_ARB:
2448 if (use_render_texture_ati) {
2450 int type = WGL_NO_TEXTURE_ARB;
2451 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2453 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2454 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2455 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2459 if (!object->use_render_texture) {
2460 *piValue = WGL_NO_TEXTURE_ARB;
2462 if (!use_render_texture_emulation) {
2463 SetLastError(ERROR_INVALID_HANDLE);
2466 switch(object->use_render_texture) {
2468 *piValue = WGL_TEXTURE_RGB_ARB;
2471 *piValue = WGL_TEXTURE_RGBA_ARB;
2473 /* WGL_FLOAT_COMPONENTS_NV */
2475 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2477 case GL_FLOAT_RG_NV:
2478 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2480 case GL_FLOAT_RGB_NV:
2481 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2483 case GL_FLOAT_RGBA_NV:
2484 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2487 ERR("Unknown texture format: %x\n", object->use_render_texture);
2493 case WGL_TEXTURE_TARGET_ARB:
2494 if (use_render_texture_ati) {
2496 int type = WGL_NO_TEXTURE_ARB;
2497 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2499 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2500 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2501 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2502 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2506 if (!object->texture_target) {
2507 *piValue = WGL_NO_TEXTURE_ARB;
2509 if (!use_render_texture_emulation) {
2510 SetLastError(ERROR_INVALID_DATA);
2513 switch (object->texture_target) {
2514 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2515 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2516 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2517 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2523 case WGL_MIPMAP_TEXTURE_ARB:
2524 if (use_render_texture_ati) {
2525 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2527 *piValue = GL_FALSE; /** don't support that */
2528 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2533 FIXME("unexpected attribute %x\n", iAttribute);
2541 * X11DRV_wglReleasePbufferDCARB
2543 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2545 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2547 TRACE("(%p, %p)\n", hPbuffer, hdc);
2548 return DeleteDC(hdc);
2552 * X11DRV_wglSetPbufferAttribARB
2554 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2556 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2558 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2559 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2560 if (NULL == object) {
2561 SetLastError(ERROR_INVALID_HANDLE);
2564 if (!object->use_render_texture) {
2565 SetLastError(ERROR_INVALID_HANDLE);
2568 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2571 if (NULL != pglXDrawableAttribATI) {
2572 if (use_render_texture_ati) {
2573 FIXME("Need conversion for GLX_ATI_render_texture\n");
2575 return pglXDrawableAttribATI(object->display, object->drawable, piAttribList);
2581 * X11DRV_wglChoosePixelFormatARB
2583 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2585 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2590 GLXFBConfig* cfgs = NULL;
2594 WineGLPixelFormat *fmt;
2598 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2599 if (NULL != pfAttribFList) {
2600 FIXME("unused pfAttribFList\n");
2603 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2604 if (-1 == nAttribs) {
2605 WARN("Cannot convert WGL to GLX attributes\n");
2608 PUSH1(attribs, None);
2610 /* Search for FB configurations matching the requirements in attribs */
2611 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2613 WARN("Compatible Pixel Format not found\n");
2617 /* Loop through all matching formats and check if they are suitable.
2618 * Note that this function should at max return nMaxFormats different formats */
2619 for(run=0; run < 2; run++)
2621 for (it = 0; it < nCfgs; ++it) {
2622 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2624 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2628 /* Search for the format in our list of compatible formats */
2629 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id);
2633 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2634 if( ((run == 0) && fmt->offscreenOnly) || ((run == 1) && !fmt->offscreenOnly) )
2637 if(pfmt_it < nMaxFormats) {
2638 piFormats[pfmt_it] = fmt->iPixelFormat;
2639 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2645 *nNumFormats = pfmt_it;
2652 * X11DRV_wglGetPixelFormatAttribivARB
2654 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2656 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2659 WineGLPixelFormat *fmt = NULL;
2663 int nWGLFormats = 0;
2665 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2667 if (0 < iLayerPlane) {
2668 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2672 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supported.
2673 * We don't have to fail yet as a program can specify an invalid iPixelFormat (lets say 0) if it wants to query
2674 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2675 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nWGLFormats);
2677 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2680 for (i = 0; i < nAttributes; ++i) {
2681 const int curWGLAttr = piAttributes[i];
2682 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2684 switch (curWGLAttr) {
2685 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2686 piValues[i] = nWGLFormats;
2689 case WGL_SUPPORT_OPENGL_ARB:
2690 piValues[i] = GL_TRUE;
2693 case WGL_ACCELERATION_ARB:
2694 curGLXAttr = GLX_CONFIG_CAVEAT;
2695 if (!fmt) goto pix_error;
2696 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2697 if (hTest) goto get_error;
2699 case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2700 case GLX_SLOW_CONFIG: piValues[i] = WGL_GENERIC_ACCELERATION_ARB; break;
2701 case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2703 ERR("unexpected Config Caveat(%x)\n", tmp);
2704 piValues[i] = WGL_NO_ACCELERATION_ARB;
2708 case WGL_TRANSPARENT_ARB:
2709 curGLXAttr = GLX_TRANSPARENT_TYPE;
2710 if (!fmt) goto pix_error;
2711 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2712 if (hTest) goto get_error;
2713 piValues[i] = GL_FALSE;
2714 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2717 case WGL_PIXEL_TYPE_ARB:
2718 curGLXAttr = GLX_RENDER_TYPE;
2719 if (!fmt) goto pix_error;
2720 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2721 if (hTest) goto get_error;
2722 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2723 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2724 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2725 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2726 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2728 ERR("unexpected RenderType(%x)\n", tmp);
2729 piValues[i] = WGL_TYPE_RGBA_ARB;
2733 case WGL_COLOR_BITS_ARB:
2734 curGLXAttr = GLX_BUFFER_SIZE;
2737 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2738 if (use_render_texture_ati) {
2739 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
2742 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2743 if (use_render_texture_ati) {
2744 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
2747 if (!use_render_texture_emulation) {
2748 piValues[i] = GL_FALSE;
2751 curGLXAttr = GLX_RENDER_TYPE;
2752 if (!fmt) goto pix_error;
2753 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2754 if (hTest) goto get_error;
2755 if (GLX_COLOR_INDEX_BIT == tmp) {
2756 piValues[i] = GL_FALSE;
2759 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2760 if (hTest) goto get_error;
2761 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2764 case WGL_BLUE_BITS_ARB:
2765 curGLXAttr = GLX_BLUE_SIZE;
2767 case WGL_RED_BITS_ARB:
2768 curGLXAttr = GLX_RED_SIZE;
2770 case WGL_GREEN_BITS_ARB:
2771 curGLXAttr = GLX_GREEN_SIZE;
2773 case WGL_ALPHA_BITS_ARB:
2774 curGLXAttr = GLX_ALPHA_SIZE;
2776 case WGL_DEPTH_BITS_ARB:
2777 curGLXAttr = GLX_DEPTH_SIZE;
2779 case WGL_STENCIL_BITS_ARB:
2780 curGLXAttr = GLX_STENCIL_SIZE;
2782 case WGL_DOUBLE_BUFFER_ARB:
2783 curGLXAttr = GLX_DOUBLEBUFFER;
2785 case WGL_STEREO_ARB:
2786 curGLXAttr = GLX_STEREO;
2788 case WGL_AUX_BUFFERS_ARB:
2789 curGLXAttr = GLX_AUX_BUFFERS;
2792 case WGL_SUPPORT_GDI_ARB:
2793 if (!fmt) goto pix_error;
2794 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &tmp);
2795 if (hTest) goto get_error;
2797 piValues[i] = GL_FALSE;
2800 curGLXAttr = GLX_X_RENDERABLE;
2803 case WGL_DRAW_TO_WINDOW_ARB:
2804 case WGL_DRAW_TO_BITMAP_ARB:
2805 case WGL_DRAW_TO_PBUFFER_ARB:
2806 if (!fmt) goto pix_error;
2807 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2808 if (hTest) goto get_error;
2809 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2810 (curWGLAttr == WGL_DRAW_TO_BITMAP_ARB && (tmp&GLX_PIXMAP_BIT)) ||
2811 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2812 piValues[i] = GL_TRUE;
2814 piValues[i] = GL_FALSE;
2817 case WGL_PBUFFER_LARGEST_ARB:
2818 curGLXAttr = GLX_LARGEST_PBUFFER;
2821 case WGL_SAMPLE_BUFFERS_ARB:
2822 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2825 case WGL_SAMPLES_ARB:
2826 curGLXAttr = GLX_SAMPLES_ARB;
2829 case WGL_FLOAT_COMPONENTS_NV:
2830 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2833 case WGL_ACCUM_RED_BITS_ARB:
2834 curGLXAttr = GLX_ACCUM_RED_SIZE;
2836 case WGL_ACCUM_GREEN_BITS_ARB:
2837 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2839 case WGL_ACCUM_BLUE_BITS_ARB:
2840 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2842 case WGL_ACCUM_ALPHA_BITS_ARB:
2843 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2845 case WGL_ACCUM_BITS_ARB:
2846 if (!fmt) goto pix_error;
2847 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2848 if (hTest) goto get_error;
2850 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2851 if (hTest) goto get_error;
2853 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2854 if (hTest) goto get_error;
2856 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2857 if (hTest) goto get_error;
2862 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2865 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2866 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2867 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2869 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2870 * and check which options can work using iPixelFormat=0 and which not.
2871 * A problem would be that this function is an extension. This would
2872 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2874 if (0 != curGLXAttr && iPixelFormat != 0) {
2875 if (!fmt) goto pix_error;
2876 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2877 if (hTest) goto get_error;
2880 piValues[i] = GL_FALSE;
2886 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2890 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats);
2895 * X11DRV_wglGetPixelFormatAttribfvARB
2897 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2899 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
2905 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2907 /* Allocate a temporary array to store integer values */
2908 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2910 ERR("couldn't allocate %d array\n", nAttributes);
2914 /* Piggy-back on wglGetPixelFormatAttribivARB */
2915 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2917 /* Convert integer values to float. Should also check for attributes
2918 that can give decimal values here */
2919 for (i=0; i<nAttributes;i++) {
2920 pfValues[i] = attr[i];
2924 HeapFree(GetProcessHeap(), 0, attr);
2929 * X11DRV_wglBindTexImageARB
2931 * WGL_ARB_render_texture: wglBindTexImageARB
2933 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2935 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2936 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2937 if (NULL == object) {
2938 SetLastError(ERROR_INVALID_HANDLE);
2941 if (!object->use_render_texture) {
2942 SetLastError(ERROR_INVALID_HANDLE);
2946 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2947 static int init = 0;
2948 int prev_binded_texture = 0;
2949 GLXContext prev_context = pglXGetCurrentContext();
2950 Drawable prev_drawable = pglXGetCurrentDrawable();
2951 GLXContext tmp_context;
2953 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2954 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2955 isn't ideal performance wise but I wasn't able to get other ways working.
2958 init = 1; /* Only show the FIXME once for performance reasons */
2959 FIXME("partial stub!\n");
2962 TRACE("drawable=%p, context=%p\n", (void*)object->drawable, prev_context);
2963 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2965 pglGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2967 /* Switch to our pbuffer */
2968 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
2970 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2971 * After that upload the pbuffer texture data. */
2972 pglBindTexture(object->texture_target, prev_binded_texture);
2973 pglCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2975 /* Switch back to the original drawable and upload the pbuffer-texture */
2976 pglXMakeCurrent(object->display, prev_drawable, prev_context);
2977 pglXDestroyContext(gdi_display, tmp_context);
2981 if (NULL != pglXBindTexImageATI) {
2986 case WGL_FRONT_LEFT_ARB:
2987 buffer = GLX_FRONT_LEFT_ATI;
2989 case WGL_FRONT_RIGHT_ARB:
2990 buffer = GLX_FRONT_RIGHT_ATI;
2992 case WGL_BACK_LEFT_ARB:
2993 buffer = GLX_BACK_LEFT_ATI;
2995 case WGL_BACK_RIGHT_ARB:
2996 buffer = GLX_BACK_RIGHT_ATI;
2999 ERR("Unknown iBuffer=%#x\n", iBuffer);
3003 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
3004 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
3005 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
3006 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
3007 * works fine using our pbuffer emulation path.
3009 return pglXBindTexImageATI(object->display, object->drawable, buffer);
3015 * X11DRV_wglReleaseTexImageARB
3017 * WGL_ARB_render_texture: wglReleaseTexImageARB
3019 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
3021 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
3022 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
3023 if (NULL == object) {
3024 SetLastError(ERROR_INVALID_HANDLE);
3027 if (!object->use_render_texture) {
3028 SetLastError(ERROR_INVALID_HANDLE);
3031 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
3034 if (NULL != pglXReleaseTexImageATI) {
3039 case WGL_FRONT_LEFT_ARB:
3040 buffer = GLX_FRONT_LEFT_ATI;
3042 case WGL_FRONT_RIGHT_ARB:
3043 buffer = GLX_FRONT_RIGHT_ATI;
3045 case WGL_BACK_LEFT_ARB:
3046 buffer = GLX_BACK_LEFT_ATI;
3048 case WGL_BACK_RIGHT_ARB:
3049 buffer = GLX_BACK_RIGHT_ATI;
3052 ERR("Unknown iBuffer=%#x\n", iBuffer);
3055 return pglXReleaseTexImageATI(object->display, object->drawable, buffer);
3061 * X11DRV_wglGetExtensionsStringEXT
3063 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
3065 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
3066 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
3067 return WineGLInfo.wglExtensions;
3071 * X11DRV_wglGetSwapIntervalEXT
3073 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
3075 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
3076 FIXME("(),stub!\n");
3077 return swap_interval;
3081 * X11DRV_wglSwapIntervalEXT
3083 * WGL_EXT_swap_control: wglSwapIntervalEXT
3085 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
3086 TRACE("(%d)\n", interval);
3087 swap_interval = interval;
3088 if (NULL != pglXSwapIntervalSGI) {
3089 return 0 == pglXSwapIntervalSGI(interval);
3091 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
3096 * X11DRV_wglAllocateMemoryNV
3098 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
3100 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
3101 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
3102 if (pglXAllocateMemoryNV == NULL)
3105 return pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
3109 * X11DRV_wglFreeMemoryNV
3111 * WGL_NV_vertex_array_range: wglFreeMemoryNV
3113 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
3114 TRACE("(%p)\n", pointer);
3115 if (pglXFreeMemoryNV == NULL)
3118 pglXFreeMemoryNV(pointer);
3122 * glxRequireVersion (internal)
3124 * Check if the supported GLX version matches requiredVersion.
3126 static BOOL glxRequireVersion(int requiredVersion)
3128 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3129 if(requiredVersion <= WineGLInfo.glxVersion[1])
3135 static BOOL glxRequireExtension(const char *requiredExtension)
3137 if (strstr(WineGLInfo.glxExtensions, requiredExtension) == NULL) {
3144 static void register_extension_string(const char *ext)
3146 if (WineGLInfo.wglExtensions[0])
3147 strcat(WineGLInfo.wglExtensions, " ");
3148 strcat(WineGLInfo.wglExtensions, ext);
3150 TRACE("'%s'\n", ext);
3153 static BOOL register_extension(const WineGLExtension * ext)
3157 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
3158 WineGLExtensionList[WineGLExtensionListSize++] = ext;
3160 register_extension_string(ext->extName);
3162 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
3163 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
3168 static const WineGLExtension WGL_internal_functions =
3172 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
3173 { "wglFinish", X11DRV_wglFinish },
3174 { "wglFlush", X11DRV_wglFlush },
3179 static const WineGLExtension WGL_ARB_extensions_string =
3181 "WGL_ARB_extensions_string",
3183 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
3187 static const WineGLExtension WGL_ARB_make_current_read =
3189 "WGL_ARB_make_current_read",
3191 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
3192 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
3196 static const WineGLExtension WGL_ARB_multisample =
3198 "WGL_ARB_multisample",
3201 static const WineGLExtension WGL_ARB_pbuffer =
3205 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
3206 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
3207 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
3208 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
3209 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
3210 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
3214 static const WineGLExtension WGL_ARB_pixel_format =
3216 "WGL_ARB_pixel_format",
3218 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
3219 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
3220 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
3224 static const WineGLExtension WGL_ARB_render_texture =
3226 "WGL_ARB_render_texture",
3228 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
3229 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
3233 static const WineGLExtension WGL_EXT_extensions_string =
3235 "WGL_EXT_extensions_string",
3237 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
3241 static const WineGLExtension WGL_EXT_swap_control =
3243 "WGL_EXT_swap_control",
3245 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
3246 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
3250 static const WineGLExtension WGL_NV_vertex_array_range =
3252 "WGL_NV_vertex_array_range",
3254 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
3255 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
3260 * X11DRV_WineGL_LoadExtensions
3262 static void X11DRV_WineGL_LoadExtensions(void)
3264 WineGLInfo.wglExtensions[0] = 0;
3266 /* Load Wine internal functions */
3267 register_extension(&WGL_internal_functions);
3269 /* ARB Extensions */
3271 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3273 register_extension_string("WGL_ARB_pixel_format_float");
3274 register_extension_string("WGL_ATI_pixel_format_float");
3277 register_extension(&WGL_ARB_extensions_string);
3279 if (glxRequireVersion(3))
3280 register_extension(&WGL_ARB_make_current_read);
3282 if (glxRequireExtension("GLX_ARB_multisample"))
3283 register_extension(&WGL_ARB_multisample);
3285 /* In general pbuffer functionality requires support in the X-server. The functionality is
3286 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3287 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3288 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3290 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3291 * without support in the X-server (which other Mesa based drivers require).
3293 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3294 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3295 * is available pbuffers must be available too. */
3296 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3297 register_extension(&WGL_ARB_pbuffer);
3299 register_extension(&WGL_ARB_pixel_format);
3301 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3302 if (glxRequireExtension("GLX_ATI_render_texture") ||
3303 glxRequireExtension("GLX_ARB_render_texture") ||
3304 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation))
3306 register_extension(&WGL_ARB_render_texture);
3308 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3309 if(glxRequireExtension("GLX_NV_float_buffer"))
3310 register_extension_string("WGL_NV_float_buffer");
3312 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3313 if(strstr(WineGLInfo.glExtensions, "GL_NV_texture_rectangle") != NULL)
3314 register_extension_string("WGL_NV_texture_rectangle");
3317 /* EXT Extensions */
3319 register_extension(&WGL_EXT_extensions_string);
3321 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3322 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3323 register_extension(&WGL_EXT_swap_control);
3325 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3326 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
3327 register_extension(&WGL_NV_vertex_array_range);
3331 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3337 if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
3338 ret = physDev->drawable; /* PBuffer */
3340 ret = physDev->bitmap->glxpixmap;
3342 else if(physDev->gl_drawable)
3343 ret = physDev->gl_drawable;
3345 ret = physDev->drawable;
3349 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3352 pglXDestroyGLXPixmap(display, glxpixmap);
3353 wine_tsx11_unlock();
3358 * X11DRV_SwapBuffers
3360 * Swap the buffers of this DC
3362 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev)
3364 GLXDrawable drawable;
3365 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
3367 if (!has_opengl()) {
3368 ERR("No libGL on this box - disabling OpenGL support !\n");
3372 TRACE("(%p)\n", physDev);
3374 drawable = get_glxdrawable(physDev);
3378 if(physDev->pixmap) {
3379 if(pglXCopySubBufferMESA) {
3380 int w = physDev->dc_rect.right - physDev->dc_rect.left;
3381 int h = physDev->dc_rect.bottom - physDev->dc_rect.top;
3383 /* (glX)SwapBuffers has an implicit glFlush effect, however
3384 * GLX_MESA_copy_sub_buffer doesn't. Make sure GL is flushed before
3388 pglXCopySubBufferMESA(gdi_display, drawable, 0, 0, w, h);
3391 pglXSwapBuffers(gdi_display, drawable);
3394 pglXSwapBuffers(gdi_display, drawable);
3396 flush_gl_drawable(physDev);
3397 wine_tsx11_unlock();
3402 static long prev_time, frames;
3404 DWORD time = GetTickCount();
3406 /* every 1.5 seconds */
3407 if (time - prev_time > 1500) {
3408 TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
3417 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3419 WineGLPixelFormat *fmt;
3421 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fbconfig_id);
3424 return pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
3427 #else /* no OpenGL includes */
3429 int pixelformat_from_fbconfig_id(XID fbconfig_id)
3434 void mark_drawable_dirty(Drawable old, Drawable new)
3438 void flush_gl_drawable(X11DRV_PDEVICE *physDev)
3442 Drawable create_glxpixmap(Display *display, XVisualInfo *vis, Pixmap parent)
3447 /***********************************************************************
3448 * ChoosePixelFormat (X11DRV.@)
3450 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
3451 const PIXELFORMATDESCRIPTOR *ppfd) {
3452 ERR("No OpenGL support compiled in.\n");
3457 /***********************************************************************
3458 * DescribePixelFormat (X11DRV.@)
3460 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
3463 PIXELFORMATDESCRIPTOR *ppfd) {
3464 ERR("No OpenGL support compiled in.\n");
3469 /***********************************************************************
3470 * GetPixelFormat (X11DRV.@)
3472 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
3473 ERR("No OpenGL support compiled in.\n");
3478 /***********************************************************************
3479 * SetPixelFormat (X11DRV.@)
3481 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
3483 const PIXELFORMATDESCRIPTOR *ppfd) {
3484 ERR("No OpenGL support compiled in.\n");
3489 /***********************************************************************
3490 * SwapBuffers (X11DRV.@)
3492 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
3493 ERR("No OpenGL support compiled in.\n");
3499 * X11DRV_wglCopyContext
3501 * For OpenGL32 wglCopyContext.
3503 BOOL X11DRV_wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask) {
3504 ERR("No OpenGL support compiled in.\n");
3509 * X11DRV_wglCreateContext
3511 * For OpenGL32 wglCreateContext.
3513 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) {
3514 ERR("No OpenGL support compiled in.\n");
3519 * X11DRV_wglDeleteContext
3521 * For OpenGL32 wglDeleteContext.
3523 BOOL X11DRV_wglDeleteContext(HGLRC hglrc) {
3524 ERR("No OpenGL support compiled in.\n");
3529 * X11DRV_wglGetProcAddress
3531 * For OpenGL32 wglGetProcAddress.
3533 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
3534 ERR("No OpenGL support compiled in.\n");
3538 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *hDevice, void *hPbuffer)
3540 ERR("No OpenGL support compiled in.\n");
3544 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) {
3545 ERR("No OpenGL support compiled in.\n");
3550 * X11DRV_wglMakeCurrent
3552 * For OpenGL32 wglMakeCurrent.
3554 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
3555 ERR("No OpenGL support compiled in.\n");
3560 * X11DRV_wglShareLists
3562 * For OpenGL32 wglShaderLists.
3564 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
3565 ERR("No OpenGL support compiled in.\n");
3570 * X11DRV_wglUseFontBitmapsA
3572 * For OpenGL32 wglUseFontBitmapsA.
3574 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3576 ERR("No OpenGL support compiled in.\n");
3581 * X11DRV_wglUseFontBitmapsW
3583 * For OpenGL32 wglUseFontBitmapsW.
3585 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3587 ERR("No OpenGL support compiled in.\n");
3591 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3596 BOOL destroy_glxpixmap(Display *display, XID glxpixmap)
3601 XVisualInfo *visual_from_fbconfig_id( XID fbconfig_id )
3606 #endif /* defined(HAVE_OPENGL) */