2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006 Roderick Colenbrander
8 * Copyright 2006 Tomas Carnecky
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
34 #include "wine/library.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
38 WINE_DECLARE_DEBUG_CHANNEL(opengl);
52 #ifdef HAVE_GL_GLEXT_H
53 # include <GL/glext.h>
62 /* Redefines the constants */
63 #define CALLBACK __stdcall
64 #define WINAPI __stdcall
65 #define APIENTRY WINAPI
68 WINE_DECLARE_DEBUG_CHANNEL(fps);
70 typedef struct wine_glextension {
79 const char *glVersion;
80 const char *glExtensions;
84 const char *glxServerVersion;
85 const char *glxServerVendor;
86 const char *glxServerExtensions;
88 const char *glxClientVersion;
89 const char *glxClientVendor;
90 const char *glxClientExtensions;
92 const char *glxExtensions;
95 char wglExtensions[4096];
98 typedef struct wine_glpixelformat {
100 GLXFBConfig fbconfig;
106 typedef struct wine_glcontext {
109 WineGLPixelFormat *fmt;
112 X11DRV_PDEVICE *physDev;
113 X11DRV_PDEVICE *pReadDev;
116 BOOL scissor_enabled;
117 struct wine_glcontext *next;
118 struct wine_glcontext *prev;
121 typedef struct wine_glpbuffer {
124 WineGLPixelFormat* fmt;
130 int use_render_texture; /* This is also the internal texture format */
131 int texture_bind_target;
133 GLint texture_format;
134 GLuint texture_target;
140 static Wine_GLContext *context_list;
141 static struct WineGLInfo WineGLInfo = { 0 };
142 static int use_render_texture_emulation = 1;
143 static int use_render_texture_ati = 0;
144 static int swap_interval = 1;
146 #define MAX_EXTENSIONS 16
147 static const WineGLExtension *WineGLExtensionList[MAX_EXTENSIONS];
148 static int WineGLExtensionListSize;
150 static WineGLPixelFormat *WineGLPixelFormatList;
151 static int WineGLPixelFormatListSize = 0;
152 static int WineGLPixelFormatOnScreenSize = 0;
154 static void X11DRV_WineGL_LoadExtensions(void);
155 static BOOL glxRequireVersion(int requiredVersion);
156 static BOOL glxRequireExtension(const char *requiredExtension);
158 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
159 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
160 TRACE(" - dwFlags : ");
161 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
162 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
163 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
164 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
165 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
166 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
167 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
168 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
169 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
170 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
171 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
172 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
173 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
174 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
175 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
176 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
177 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
178 /* PFD_SUPPORT_COMPOSITION is new in Vista, it is similar to composition
179 * under X e.g. COMPOSITE + GLX_EXT_TEXTURE_FROM_PIXMAP. */
180 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_COMPOSITION);
184 TRACE(" - iPixelType : ");
185 switch (ppfd->iPixelType) {
186 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
187 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
191 TRACE(" - Color : %d\n", ppfd->cColorBits);
192 TRACE(" - Red : %d\n", ppfd->cRedBits);
193 TRACE(" - Green : %d\n", ppfd->cGreenBits);
194 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
195 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
196 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
197 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
198 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
199 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
201 TRACE(" - iLayerType : ");
202 switch (ppfd->iLayerType) {
203 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
204 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
205 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
210 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
211 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
213 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
215 MAKE_FUNCPTR(glXChooseVisual)
216 MAKE_FUNCPTR(glXCreateContext)
217 MAKE_FUNCPTR(glXCreateGLXPixmap)
218 MAKE_FUNCPTR(glXGetCurrentContext)
219 MAKE_FUNCPTR(glXGetCurrentDrawable)
220 MAKE_FUNCPTR(glXDestroyContext)
221 MAKE_FUNCPTR(glXDestroyGLXPixmap)
222 MAKE_FUNCPTR(glXGetConfig)
223 MAKE_FUNCPTR(glXIsDirect)
224 MAKE_FUNCPTR(glXMakeCurrent)
225 MAKE_FUNCPTR(glXSwapBuffers)
226 MAKE_FUNCPTR(glXQueryExtension)
227 MAKE_FUNCPTR(glXQueryVersion)
228 MAKE_FUNCPTR(glXUseXFont)
231 MAKE_FUNCPTR(glXGetClientString)
232 MAKE_FUNCPTR(glXQueryExtensionsString)
233 MAKE_FUNCPTR(glXQueryServerString)
236 MAKE_FUNCPTR(glXGetFBConfigs)
237 MAKE_FUNCPTR(glXChooseFBConfig)
238 MAKE_FUNCPTR(glXCreatePbuffer)
239 MAKE_FUNCPTR(glXCreateNewContext)
240 MAKE_FUNCPTR(glXDestroyPbuffer)
241 MAKE_FUNCPTR(glXGetFBConfigAttrib)
242 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
243 MAKE_FUNCPTR(glXMakeContextCurrent)
244 MAKE_FUNCPTR(glXQueryDrawable)
245 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
248 static void* (*pglXGetProcAddressARB)(const GLubyte *);
249 static int (*pglXSwapIntervalSGI)(int);
251 /* ATI GLX Extensions */
252 static BOOL (*pglXBindTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
253 static BOOL (*pglXReleaseTexImageATI)(Display *dpy, GLXPbuffer pbuffer, int buffer);
254 static BOOL (*pglXDrawableAttribATI)(Display *dpy, GLXDrawable draw, const int *attribList);
256 /* NV GLX Extension */
257 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
258 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
260 /* Standard OpenGL */
261 MAKE_FUNCPTR(glBindTexture)
262 MAKE_FUNCPTR(glBitmap)
263 MAKE_FUNCPTR(glCopyTexSubImage1D)
264 MAKE_FUNCPTR(glCopyTexImage2D)
265 MAKE_FUNCPTR(glCopyTexSubImage2D)
266 MAKE_FUNCPTR(glDisable)
267 MAKE_FUNCPTR(glDrawBuffer)
268 MAKE_FUNCPTR(glEnable)
269 MAKE_FUNCPTR(glEndList)
270 MAKE_FUNCPTR(glGetError)
271 MAKE_FUNCPTR(glGetIntegerv)
272 MAKE_FUNCPTR(glGetString)
273 MAKE_FUNCPTR(glIsEnabled)
274 MAKE_FUNCPTR(glNewList)
275 MAKE_FUNCPTR(glPixelStorei)
276 MAKE_FUNCPTR(glReadPixels)
277 MAKE_FUNCPTR(glScissor)
278 MAKE_FUNCPTR(glTexImage2D)
279 MAKE_FUNCPTR(glViewport)
282 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
284 static BOOL infoInitialized = FALSE;
286 int screen = DefaultScreen(gdi_display);
287 Window win = RootWindow(gdi_display, screen);
289 XVisualInfo template;
292 GLXContext ctx = NULL;
296 infoInitialized = TRUE;
300 visual = DefaultVisual(gdi_display, screen);
301 template.visualid = XVisualIDFromVisual(visual);
302 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
304 WORD old_fs = wine_get_fs();
305 /* Create a GLX Context. Without one we can't query GL information */
306 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
307 if (wine_get_fs() != old_fs)
309 wine_set_fs( old_fs );
311 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
312 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
318 pglXMakeCurrent(gdi_display, win, ctx);
320 ERR(" couldn't initialize OpenGL, expect problems\n");
325 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
326 WineGLInfo.glExtensions = strdup((const char *) pglGetString(GL_EXTENSIONS));
328 /* Get the common GLX version supported by GLX client and server ( major/minor) */
329 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
331 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
332 WineGLInfo.glxServerVendor = pglXQueryServerString(gdi_display, screen, GLX_VENDOR);
333 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
335 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
336 WineGLInfo.glxClientVendor = pglXGetClientString(gdi_display, GLX_VENDOR);
337 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
339 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
340 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
342 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
343 TRACE("GL renderer : %s.\n", pglGetString(GL_RENDERER));
344 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
345 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
346 TRACE("Server GLX vendor: : %s.\n", WineGLInfo.glxServerVendor);
347 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
348 TRACE("Client GLX vendor: : %s.\n", WineGLInfo.glxClientVendor);
349 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
353 pglXMakeCurrent(gdi_display, None, NULL);
354 pglXDestroyContext(gdi_display, ctx);
360 static BOOL has_opengl(void)
362 static int init_done;
363 static void *opengl_handle;
365 int error_base, event_base;
367 if (init_done) return (opengl_handle != NULL);
370 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
371 and include all dependencies */
372 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, NULL, 0);
373 if (opengl_handle == NULL) return FALSE;
375 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
376 if (pglXGetProcAddressARB == NULL) {
377 ERR("could not find glXGetProcAddressARB in libGL.\n");
381 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
383 LOAD_FUNCPTR(glXChooseVisual)
384 LOAD_FUNCPTR(glXCreateContext)
385 LOAD_FUNCPTR(glXCreateGLXPixmap)
386 LOAD_FUNCPTR(glXGetCurrentContext)
387 LOAD_FUNCPTR(glXGetCurrentDrawable)
388 LOAD_FUNCPTR(glXDestroyContext)
389 LOAD_FUNCPTR(glXDestroyGLXPixmap)
390 LOAD_FUNCPTR(glXGetConfig)
391 LOAD_FUNCPTR(glXIsDirect)
392 LOAD_FUNCPTR(glXMakeCurrent)
393 LOAD_FUNCPTR(glXSwapBuffers)
394 LOAD_FUNCPTR(glXQueryExtension)
395 LOAD_FUNCPTR(glXQueryVersion)
396 LOAD_FUNCPTR(glXUseXFont)
399 LOAD_FUNCPTR(glXGetClientString)
400 LOAD_FUNCPTR(glXQueryExtensionsString)
401 LOAD_FUNCPTR(glXQueryServerString)
404 LOAD_FUNCPTR(glXCreatePbuffer)
405 LOAD_FUNCPTR(glXCreateNewContext)
406 LOAD_FUNCPTR(glXDestroyPbuffer)
407 LOAD_FUNCPTR(glXMakeContextCurrent)
408 LOAD_FUNCPTR(glXGetCurrentReadDrawable)
409 LOAD_FUNCPTR(glXGetFBConfigs)
411 /* Standard OpenGL calls */
412 LOAD_FUNCPTR(glBindTexture)
413 LOAD_FUNCPTR(glBitmap)
414 LOAD_FUNCPTR(glCopyTexSubImage1D)
415 LOAD_FUNCPTR(glCopyTexImage2D)
416 LOAD_FUNCPTR(glCopyTexSubImage2D)
417 LOAD_FUNCPTR(glDisable)
418 LOAD_FUNCPTR(glDrawBuffer)
419 LOAD_FUNCPTR(glEnable)
420 LOAD_FUNCPTR(glEndList)
421 LOAD_FUNCPTR(glGetError)
422 LOAD_FUNCPTR(glGetIntegerv)
423 LOAD_FUNCPTR(glGetString)
424 LOAD_FUNCPTR(glIsEnabled)
425 LOAD_FUNCPTR(glNewList)
426 LOAD_FUNCPTR(glPixelStorei)
427 LOAD_FUNCPTR(glReadPixels)
428 LOAD_FUNCPTR(glScissor)
429 LOAD_FUNCPTR(glTexImage2D)
430 LOAD_FUNCPTR(glViewport)
433 /* It doesn't matter if these fail. They'll only be used if the driver reports
434 the associated extension is available (and if a driver reports the extension
435 is available but fails to provide the functions, it's quite broken) */
436 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f);
437 /* NV GLX Extension */
438 LOAD_FUNCPTR(glXAllocateMemoryNV)
439 LOAD_FUNCPTR(glXFreeMemoryNV)
442 if(!X11DRV_WineGL_InitOpenglInfo()) {
443 wine_dlclose(opengl_handle, NULL, 0);
444 opengl_handle = NULL;
449 if (pglXQueryExtension(gdi_display, &error_base, &event_base) == True) {
450 TRACE("GLX is up and running error_base = %d\n", error_base);
452 wine_dlclose(opengl_handle, NULL, 0);
453 opengl_handle = NULL;
456 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
457 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
460 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
461 * depends on the reported GLX client / server version and on the client / server extension list.
462 * Those don't have to be the same.
464 * In general the server GLX information lists the capabilities in case of indirect rendering.
465 * When direct rendering is used, the OpenGL client library is responsible for which GLX calls are
466 * available and in that case the client GLX informat can be used.
467 * OpenGL programs should use the 'intersection' of both sets of information which is advertised
468 * in the GLX version/extension list. When a program does this it works for certain for both
469 * direct and indirect rendering.
471 * The problem we are having in this area is that ATI's Linux drivers are broken. For some reason
472 * they haven't added some very important GLX extensions like GLX_SGIX_fbconfig to their client
473 * extension list which causes this extension not to be listed. (Wine requires this extension).
474 * ATI advertises a GLX client version of 1.3 which implies that this fbconfig extension among
475 * pbuffers is around.
477 * In order to provide users of Ati's proprietary drivers with OpenGL support, we need to detect
478 * the ATI drivers and from then on use GLX client information for them.
481 if(glxRequireVersion(3)) {
482 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
483 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
484 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
485 pglXQueryDrawable = (void*)pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
486 } else if(glxRequireExtension("GLX_SGIX_fbconfig")) {
487 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
488 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
489 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
491 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
492 * enable this function when the Xserver understand GLX 1.3 or newer
494 pglXQueryDrawable = NULL;
495 } else if(strcmp("ATI", WineGLInfo.glxClientVendor) == 0) {
496 TRACE("Overriding ATI GLX capabilities!\n");
497 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
498 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
499 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
500 pglXQueryDrawable = (void*)pglXGetProcAddressARB((const GLubyte *) "glXQueryDrawable");
502 /* Use client GLX information in case of the ATI drivers. We override the
503 * capabilities over here and not somewhere else as ATI might better their
504 * life in the future. In case they release proper drivers this block of
505 * code won't be called. */
506 WineGLInfo.glxExtensions = WineGLInfo.glxClientExtensions;
508 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxServerVersion);
511 if(glxRequireExtension("GLX_ATI_render_texture")) {
512 use_render_texture_ati = 1;
513 pglXBindTexImageATI = (void*)pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageATI");
514 pglXReleaseTexImageATI = (void*)pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageATI");
515 pglXDrawableAttribATI = (void*)pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribATI");
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;
612 /* The list of WGL attributes is allowed to be NULL. We don't return here for NULL
613 * because we need to do fixups for GLX_DRAWABLE_TYPE/GLX_RENDER_TYPE/GLX_FLOAT_COMPONENTS_NV. */
614 while (iWGLAttr && 0 != iWGLAttr[cur]) {
615 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
617 switch (iWGLAttr[cur]) {
618 case WGL_COLOR_BITS_ARB:
619 pop = iWGLAttr[++cur];
620 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
621 TRACE("pAttr[%d] = GLX_BUFFER_SIZE: %d\n", cur, pop);
623 case WGL_BLUE_BITS_ARB:
624 pop = iWGLAttr[++cur];
625 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
626 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
628 case WGL_RED_BITS_ARB:
629 pop = iWGLAttr[++cur];
630 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
631 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
633 case WGL_GREEN_BITS_ARB:
634 pop = iWGLAttr[++cur];
635 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
636 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
638 case WGL_ALPHA_BITS_ARB:
639 pop = iWGLAttr[++cur];
640 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
641 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
643 case WGL_DEPTH_BITS_ARB:
644 pop = iWGLAttr[++cur];
645 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
646 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
648 case WGL_STENCIL_BITS_ARB:
649 pop = iWGLAttr[++cur];
650 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
651 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
653 case WGL_DOUBLE_BUFFER_ARB:
654 pop = iWGLAttr[++cur];
655 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
656 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
659 case WGL_PIXEL_TYPE_ARB:
660 pop = iWGLAttr[++cur];
661 TRACE("pAttr[%d] = WGL_PIXEL_TYPE_ARB: %d\n", cur, pop);
663 case WGL_TYPE_COLORINDEX_ARB: pixelattrib = GLX_COLOR_INDEX_BIT; break ;
664 case WGL_TYPE_RGBA_ARB: pixelattrib = GLX_RGBA_BIT; break ;
665 /* 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 */
666 case WGL_TYPE_RGBA_FLOAT_ATI: pixelattrib = GLX_RGBA_FLOAT_BIT; break ;
668 ERR("unexpected PixelType(%x)\n", pop);
673 case WGL_SUPPORT_GDI_ARB:
674 pop = iWGLAttr[++cur];
675 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
676 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
679 case WGL_DRAW_TO_BITMAP_ARB:
680 pop = iWGLAttr[++cur];
681 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
682 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
684 drawattrib |= GLX_PIXMAP_BIT;
688 case WGL_DRAW_TO_WINDOW_ARB:
689 pop = iWGLAttr[++cur];
690 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
691 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
693 drawattrib |= GLX_WINDOW_BIT;
697 case WGL_DRAW_TO_PBUFFER_ARB:
698 pop = iWGLAttr[++cur];
699 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
700 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
702 drawattrib |= GLX_PBUFFER_BIT;
706 case WGL_ACCELERATION_ARB:
707 case WGL_SUPPORT_OPENGL_ARB:
708 pop = iWGLAttr[++cur];
709 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
710 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
713 case WGL_PBUFFER_LARGEST_ARB:
714 pop = iWGLAttr[++cur];
715 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
716 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
719 case WGL_SAMPLE_BUFFERS_ARB:
720 pop = iWGLAttr[++cur];
721 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
722 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
725 case WGL_SAMPLES_ARB:
726 pop = iWGLAttr[++cur];
727 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
728 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
731 case WGL_TEXTURE_FORMAT_ARB:
732 case WGL_TEXTURE_TARGET_ARB:
733 case WGL_MIPMAP_TEXTURE_ARB:
734 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
735 pop = iWGLAttr[++cur];
737 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
739 if (use_render_texture_ati) {
740 /** nothing to do here */
742 else if (!use_render_texture_emulation) {
743 if (WGL_NO_TEXTURE_ARB != pop) {
744 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
745 return -1; /** error: don't support it */
747 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
748 drawattrib |= GLX_PBUFFER_BIT;
752 case WGL_FLOAT_COMPONENTS_NV:
753 nvfloatattrib = iWGLAttr[++cur];
754 TRACE("pAttr[%d] = WGL_FLOAT_COMPONENTS_NV: %x\n", cur, nvfloatattrib);
756 case WGL_BIND_TO_TEXTURE_RGB_ARB:
757 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
758 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
759 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
760 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
761 case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
762 pop = iWGLAttr[++cur];
763 /** cannot be converted, see direct handling on
764 * - wglGetPixelFormatAttribivARB
765 * TODO: wglChoosePixelFormat
770 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
776 /* Apply the OR'd drawable type bitmask now EVEN when WGL_DRAW_TO* is unset.
777 * It is needed in all cases because GLX_DRAWABLE_TYPE default to GLX_WINDOW_BIT. */
778 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
779 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
781 /* Set GLX_RENDER_TYPE all the time */
782 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pixelattrib);
783 TRACE("pAttr[?] = GLX_RENDER_TYPE: %#x\n", pixelattrib);
785 /* Set GLX_FLOAT_COMPONENTS_NV all the time */
786 if(strstr(WineGLInfo.glxExtensions, "GLX_NV_float_buffer")) {
787 PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, nvfloatattrib);
788 TRACE("pAttr[?] = GLX_FLOAT_COMPONENTS_NV: %#x\n", nvfloatattrib);
794 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
796 int render_type=0, render_type_bit;
797 pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
798 switch(render_type_bit)
801 render_type = GLX_RGBA_TYPE;
803 case GLX_COLOR_INDEX_BIT:
804 render_type = GLX_COLOR_INDEX_TYPE;
806 case GLX_RGBA_FLOAT_BIT:
807 render_type = GLX_RGBA_FLOAT_TYPE;
810 ERR("Unknown render_type: %x\n", render_type);
815 static BOOL init_formats(Display *display, int screen, Visual *visual)
817 int fmt_id, tmp_fmt_id, nCfgs, i;
819 GLXFBConfig fbconfig = NULL;
820 XVisualInfo *visinfo;
821 VisualID visualid = XVisualIDFromVisual(visual);
822 int nOffscreenFormats = 0;
824 /* As mentioned in various parts of the code only the format of the main visual can be used for onscreen rendering.
825 * Next to this format there are also so called offscreen rendering formats (used for pbuffers) which can be supported
826 * because they don't need a visual. Below we use glXGetFBConfigs instead of glXChooseFBConfig to enumerate the fb configurations
827 * because this call lists both types of formats instead of only onscreen ones. */
828 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
829 if (NULL == cfgs || 0 == nCfgs) {
830 ERR("glXChooseFBConfig returns NULL\n");
831 if(cfgs != NULL) XFree(cfgs);
835 /* Count the number of offscreen formats to determine the size for our pixelformat list */
836 for(i=0; i<nCfgs; i++) {
837 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id);
839 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
840 /* Onscreen formats have a corresponding XVisual, offscreen ones don't */
843 } else if(visinfo && visinfo->visualid == visualid) {
844 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &fmt_id);
849 TRACE("Number of offscreen formats: %d\n", nOffscreenFormats);
851 /* Allocate memory for all the offscreen pixelformats and the format of Wine's main visual */
852 WineGLPixelFormatList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (1+nOffscreenFormats)*sizeof(WineGLPixelFormat));
853 WineGLPixelFormatList[0].iPixelFormat = 1;
854 WineGLPixelFormatList[0].fbconfig = fbconfig;
855 WineGLPixelFormatList[0].fmt_id = fmt_id;
856 WineGLPixelFormatList[0].render_type = get_render_type_from_fbconfig(display, fbconfig);
857 WineGLPixelFormatList[0].offscreenOnly = FALSE;
858 WineGLPixelFormatListSize = 1;
859 WineGLPixelFormatOnScreenSize = 1;
861 /* Fill the list with offscreen formats */
862 for(i=0; i<nCfgs; i++) {
863 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id);
865 visinfo = pglXGetVisualFromFBConfig(display, cfgs[i]);
866 /* We have found an offscreen rendering format when there is no visualinfo :) */
868 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", tmp_fmt_id, WineGLPixelFormatListSize+1, i);
869 WineGLPixelFormatList[WineGLPixelFormatListSize].iPixelFormat = WineGLPixelFormatListSize+1; /* The index starts at 1 */
870 WineGLPixelFormatList[WineGLPixelFormatListSize].fbconfig = cfgs[i];
871 WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_id = tmp_fmt_id;
872 WineGLPixelFormatList[WineGLPixelFormatListSize].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
873 WineGLPixelFormatList[WineGLPixelFormatListSize].offscreenOnly = TRUE;
874 WineGLPixelFormatListSize++;
880 if(cfgs != NULL) XFree(cfgs);
885 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
886 * In our WGL implementation we only support a subset of these formats namely the format of
887 * Wine's main visual and offscreen formats (if they are available).
888 * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
889 * and it returns the number of supported WGL formats in fmt_count.
891 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count)
893 WineGLPixelFormat *res = NULL;
895 /* Init the list of pixel formats when we need it */
896 if(!WineGLPixelFormatListSize)
897 init_formats(display, DefaultScreen(display), visual);
899 /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
900 * iPixelFormat in case of probing the number of pixelformats.
902 if((iPixelFormat > 0) && (iPixelFormat <= WineGLPixelFormatListSize) &&
903 ((WineGLPixelFormatList[iPixelFormat-1].offscreenOnly == FALSE) ||
905 res = &WineGLPixelFormatList[iPixelFormat-1];
906 TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res->fbconfig, iPixelFormat);
910 *fmt_count = WineGLPixelFormatListSize;
912 *fmt_count = WineGLPixelFormatOnScreenSize;
914 TRACE("Number of returned pixelformats=%d\n", *fmt_count);
919 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
920 static WineGLPixelFormat* ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id)
924 /* Init the list of pixel formats when we need it */
925 if(!WineGLPixelFormatListSize)
926 init_formats(display, DefaultScreen(display), visual);
928 for(i=0; i<WineGLPixelFormatListSize; i++) {
929 if(WineGLPixelFormatList[i].fmt_id == fmt_id) {
930 TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", WineGLPixelFormatList[i].iPixelFormat, fmt_id);
931 return &WineGLPixelFormatList[i];
934 TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id);
939 * X11DRV_ChoosePixelFormat
941 * Equivalent to glXChooseVisual.
943 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
944 const PIXELFORMATDESCRIPTOR *ppfd) {
945 WineGLPixelFormat *fmt = NULL;
951 int bestDBuffer = -1;
956 int bestStencil = -1;
961 ERR("No libGL on this box - disabling OpenGL support !\n");
965 if (TRACE_ON(opengl)) {
966 TRACE("(%p,%p)\n", physDev, ppfd);
968 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR *) ppfd);
972 ConvertPixelFormatWGLtoGLX(gdi_display, 0, FALSE /* offscreen */, &nPixelFormats);
973 for(i=0; i<nPixelFormats; i++)
977 int alpha=0, color=0, depth=0, stencil=0, aux=0;
979 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, i+1 /* 1-based index */, FALSE /* offscreen */, &value);
983 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
984 if (value & GLX_RGBA_BIT)
985 iPixelType = PFD_TYPE_RGBA;
987 iPixelType = PFD_TYPE_COLORINDEX;
989 if (ppfd->iPixelType != iPixelType)
991 TRACE("pixel type mismatch for iPixelFormat=%d\n", i+1);
995 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
996 if (value) dwFlags |= PFD_DOUBLEBUFFER;
997 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value);
998 if (value) dwFlags |= PFD_STEREO;
999 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &color); /* cColorBits */
1000 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &alpha); /* cAlphaBits */
1001 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &depth); /* cDepthBits */
1002 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &stencil); /* cStencilBits */
1003 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &aux); /* cAuxBuffers */
1005 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
1006 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
1007 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
1008 * formats without the given flag set.
1009 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
1010 * has indicated that a format without stereo is returned when stereo is unavailable.
1011 * So in case PFD_STEREO is set, formats that support it should have priority above formats
1012 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
1014 * To summarize the following is most likely the correct behavior:
1015 * stereo not set -> prefer no-stereo formats, else also accept stereo formats
1016 * stereo set -> prefer stereo formats, else also accept no-stereo formats
1017 * stereo don't care -> it doesn't matter whether we get stereo or not
1019 * In Wine we will treat no-stereo the same way as don't care because it makes
1020 * format selection even more complicated and second drivers with Stereo advertise
1021 * each format twice anyway.
1024 /* Doublebuffer, see the comments above */
1025 if( !(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) ) {
1026 if( ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) &&
1027 ((dwFlags & PFD_DOUBLEBUFFER) == (ppfd->dwFlags & PFD_DOUBLEBUFFER)) )
1029 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1030 bestStereo = dwFlags & PFD_STEREO;
1034 bestStencil = stencil;
1039 if(bestDBuffer != -1 && (dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer)
1043 /* Stereo, see the comments above. */
1044 if( !(ppfd->dwFlags & PFD_STEREO_DONTCARE) ) {
1045 if( ((ppfd->dwFlags & PFD_STEREO) != bestStereo) &&
1046 ((dwFlags & PFD_STEREO) == (ppfd->dwFlags & PFD_STEREO)) )
1048 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1049 bestStereo = dwFlags & PFD_STEREO;
1053 bestStencil = stencil;
1058 if(bestStereo != -1 && (dwFlags & PFD_STEREO) != bestStereo)
1062 /* Below we will do a number of checks to select the 'best' pixelformat.
1063 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
1064 * The code works by trying to match the most important options as close as possible.
1065 * When a reasonable format is found, we will try to match more options. */
1068 if( ((ppfd->cColorBits > bestColor) && (color > bestColor)) ||
1069 ((color >= ppfd->cColorBits) && (color < bestColor)) )
1071 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1072 bestStereo = dwFlags & PFD_STEREO;
1076 bestStencil = stencil;
1080 } else if(bestColor != color) { /* Do further checks if the format is compatible */
1081 TRACE("color mismatch for iPixelFormat=%d\n", i+1);
1086 if( ((ppfd->cAlphaBits > bestAlpha) && (alpha > bestAlpha)) ||
1087 ((alpha >= ppfd->cAlphaBits) && (alpha < bestAlpha)) )
1089 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1090 bestStereo = dwFlags & PFD_STEREO;
1094 bestStencil = stencil;
1098 } else if(bestAlpha != alpha) {
1099 TRACE("alpha mismatch for iPixelFormat=%d\n", i+1);
1104 if( ((ppfd->cDepthBits > bestDepth) && (depth > bestDepth)) ||
1105 ((depth >= ppfd->cDepthBits) && (depth < bestDepth)) )
1107 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1108 bestStereo = dwFlags & PFD_STEREO;
1112 bestStencil = stencil;
1116 } else if(bestDepth != depth) {
1117 TRACE("depth mismatch for iPixelFormat=%d\n", i+1);
1122 if( ((ppfd->cStencilBits > bestStencil) && (stencil > bestStencil)) ||
1123 ((stencil >= ppfd->cStencilBits) && (stencil < bestStencil)) )
1125 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1126 bestStereo = dwFlags & PFD_STEREO;
1130 bestStencil = stencil;
1134 } else if(bestStencil != stencil) {
1135 TRACE("stencil mismatch for iPixelFormat=%d\n", i+1);
1140 if( ((ppfd->cAuxBuffers > bestAux) && (aux > bestAux)) ||
1141 ((aux >= ppfd->cAuxBuffers) && (aux < bestAux)) )
1143 bestDBuffer = dwFlags & PFD_DOUBLEBUFFER;
1144 bestStereo = dwFlags & PFD_STEREO;
1148 bestStencil = stencil;
1152 } else if(bestAux != aux) {
1153 TRACE("aux mismatch for iPixelFormat=%d\n", i+1);
1158 if(bestFormat == -1) {
1159 TRACE("No matching mode was found returning 0\n");
1163 ret = bestFormat+1; /* the return value should be a 1-based index */
1164 TRACE("Successfully found a matching mode, returning index: %d %x\n", ret, WineGLPixelFormatList[bestFormat].fmt_id);
1167 wine_tsx11_unlock();
1172 * X11DRV_DescribePixelFormat
1174 * Get the pixel-format descriptor associated to the given id
1176 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
1179 PIXELFORMATDESCRIPTOR *ppfd) {
1180 /*XVisualInfo *vis;*/
1183 WineGLPixelFormat *fmt;
1187 if (!has_opengl()) {
1188 ERR("No libGL on this box - disabling OpenGL support !\n");
1192 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
1194 /* 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 */
1195 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_count);
1197 /* The application is only querying the number of pixelformats */
1199 } else if(fmt == NULL) {
1200 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1204 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1205 ERR("Wrong structure size !\n");
1206 /* Should set error */
1212 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1213 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1216 /* These flags are always the same... */
1217 ppfd->dwFlags = PFD_SUPPORT_OPENGL;
1218 /* Now the flags extracted from the Visual */
1222 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_X_RENDERABLE, &value);
1224 ppfd->dwFlags |= PFD_SUPPORT_GDI;
1226 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1227 if(value & GLX_WINDOW_BIT)
1228 ppfd->dwFlags |= PFD_DRAW_TO_WINDOW;
1229 if(value & GLX_PIXMAP_BIT)
1230 ppfd->dwFlags |= PFD_DRAW_TO_BITMAP;
1232 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_CONFIG_CAVEAT, &value);
1233 if(value == GLX_SLOW_CONFIG)
1234 ppfd->dwFlags |= PFD_GENERIC_ACCELERATED;
1236 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value);
1238 ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1239 ppfd->dwFlags &= ~PFD_SUPPORT_GDI;
1241 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1244 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1245 if (value & GLX_RGBA_BIT)
1246 ppfd->iPixelType = PFD_TYPE_RGBA;
1248 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1251 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1252 ppfd->cColorBits = value;
1254 /* Red, green, blue and alpha bits / shifts */
1255 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1256 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1257 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1258 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1259 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1261 ppfd->cRedBits = rb;
1262 ppfd->cRedShift = gb + bb + ab;
1263 ppfd->cBlueBits = bb;
1264 ppfd->cBlueShift = ab;
1265 ppfd->cGreenBits = gb;
1266 ppfd->cGreenShift = bb + ab;
1267 ppfd->cAlphaBits = ab;
1268 ppfd->cAlphaShift = 0;
1271 ppfd->cRedShift = 0;
1272 ppfd->cBlueBits = 0;
1273 ppfd->cBlueShift = 0;
1274 ppfd->cGreenBits = 0;
1275 ppfd->cGreenShift = 0;
1276 ppfd->cAlphaBits = 0;
1277 ppfd->cAlphaShift = 0;
1280 /* Accum RGBA bits */
1281 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &rb);
1282 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &gb);
1283 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &bb);
1284 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &ab);
1286 ppfd->cAccumBits = rb+gb+bb+ab;
1287 ppfd->cAccumRedBits = rb;
1288 ppfd->cAccumGreenBits = gb;
1289 ppfd->cAccumBlueBits = bb;
1290 ppfd->cAccumAlphaBits = ab;
1293 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1294 ppfd->cDepthBits = value;
1297 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1298 ppfd->cStencilBits = value;
1300 wine_tsx11_unlock();
1302 /* Aux : to do ... */
1304 ppfd->iLayerType = PFD_MAIN_PLANE;
1306 if (TRACE_ON(opengl)) {
1307 dump_PIXELFORMATDESCRIPTOR(ppfd);
1314 * X11DRV_GetPixelFormat
1316 * Get the pixel-format id used by this DC
1318 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
1319 WineGLPixelFormat *fmt;
1321 TRACE("(%p)\n", physDev);
1323 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, physDev->current_pf, TRUE, &tmp);
1326 /* This happens on HDCs on which SetPixelFormat wasn't called yet */
1327 ERR("Unable to find a WineGLPixelFormat for iPixelFormat=%d\n", physDev->current_pf);
1330 else if(fmt->offscreenOnly)
1332 /* Offscreen formats can't be used with traditional WGL calls.
1333 * As has been verified on Windows GetPixelFormat doesn't fail but returns iPixelFormat=1. */
1334 TRACE("Returning iPixelFormat=1 for offscreen format: %d\n", fmt->iPixelFormat);
1338 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1339 return physDev->current_pf;
1343 * X11DRV_SetPixelFormat
1345 * Set the pixel-format id used by this DC
1347 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
1349 const PIXELFORMATDESCRIPTOR *ppfd) {
1350 WineGLPixelFormat *fmt;
1353 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1355 if (!has_opengl()) {
1356 ERR("No libGL on this box - disabling OpenGL support !\n");
1360 /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */
1361 if(get_glxdrawable(physDev) == root_window)
1363 ERR("Invalid operation on root_window\n");
1367 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1368 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
1370 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1374 physDev->current_pf = iPixelFormat;
1376 if (TRACE_ON(opengl)) {
1379 gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1381 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1383 TRACE(" FBConfig have :\n");
1384 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1385 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1386 TRACE(" - VISUAL_ID 0x%x\n", value);
1387 pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1388 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1395 * X11DRV_wglCreateContext
1397 * For OpenGL32 wglCreateContext.
1399 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
1401 Wine_GLContext *ret;
1402 WineGLPixelFormat *fmt;
1403 int hdcPF = physDev->current_pf;
1405 HDC hdc = physDev->hdc;
1407 TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1409 if (!has_opengl()) {
1410 ERR("No libGL on this box - disabling OpenGL support !\n");
1414 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, TRUE /* Offscreen */, &fmt_count);
1415 /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1416 * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1417 * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1418 * If this fails something is very wrong on the system. */
1420 ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF);
1421 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1425 /* The context will be allocated in the wglMakeCurrent call */
1427 ret = alloc_context();
1428 wine_tsx11_unlock();
1430 ret->physDev = physDev;
1434 ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1436 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1441 * X11DRV_wglDeleteContext
1443 * For OpenGL32 wglDeleteContext.
1445 BOOL X11DRV_wglDeleteContext(HGLRC hglrc)
1447 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1450 TRACE("(%p)\n", hglrc);
1452 if (!has_opengl()) {
1453 ERR("No libGL on this box - disabling OpenGL support !\n");
1458 /* A game (Half Life not to name it) deletes twice the same context,
1459 * so make sure it is valid first */
1460 if (is_valid_context( ctx ))
1462 if (ctx->ctx) pglXDestroyContext(gdi_display, ctx->ctx);
1467 WARN("Error deleting context !\n");
1468 SetLastError(ERROR_INVALID_HANDLE);
1471 wine_tsx11_unlock();
1477 * X11DRV_wglGetCurrentReadDCARB
1479 * For OpenGL32 wglGetCurrentReadDCARB.
1481 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1484 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1485 X11DRV_PDEVICE *physDev = ctx ? ctx->pReadDev : NULL;
1490 TRACE(" returning %p (GL drawable %lu)\n", ret, physDev ? physDev->drawable : 0);
1495 * X11DRV_wglGetProcAddress
1497 * For OpenGL32 wglGetProcAddress.
1499 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1502 const WineGLExtension *ext;
1504 int padding = 32 - strlen(lpszProc);
1508 if (!has_opengl()) {
1509 ERR("No libGL on this box - disabling OpenGL support !\n");
1513 /* Check the table of WGL extensions to see if we need to return a WGL extension
1514 * or a function pointer to a native OpenGL function. */
1515 if(strncmp(lpszProc, "wgl", 3) != 0) {
1516 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1518 TRACE("('%s'):%*s", lpszProc, padding, " ");
1519 for (i = 0; i < WineGLExtensionListSize; ++i) {
1520 ext = WineGLExtensionList[i];
1521 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1522 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1523 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1524 return ext->extEntryPoints[j].funcAddress;
1530 WARN("(%s) - not found\n", lpszProc);
1534 /***********************************************************************
1535 * sync_current_drawable
1537 * Adjust the current viewport and scissor in order to position
1538 * and size the current drawable correctly on the parent window.
1540 static void sync_current_drawable(BOOL updatedc)
1546 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1550 if (ctx && ctx->physDev)
1553 GetClipBox(ctx->physDev->hdc, &rc); /* Make sure physDev is up to date */
1555 dy = ctx->physDev->drawable_rect.bottom - ctx->physDev->drawable_rect.top -
1556 ctx->physDev->dc_rect.bottom;
1557 width = ctx->physDev->dc_rect.right - ctx->physDev->dc_rect.left;
1558 height = ctx->physDev->dc_rect.bottom - ctx->physDev->dc_rect.top;
1562 pglViewport(ctx->physDev->dc_rect.left + ctx->viewport.left,
1563 dy + ctx->viewport.top,
1564 ctx->viewport.right ? (ctx->viewport.right - ctx->viewport.left) : width,
1565 ctx->viewport.bottom ? (ctx->viewport.bottom - ctx->viewport.top) : height);
1567 pglEnable(GL_SCISSOR_TEST);
1569 if (ctx->scissor_enabled)
1570 pglScissor(ctx->physDev->dc_rect.left + min(width, max(0, ctx->scissor.left)),
1571 dy + min(height, max(0, ctx->scissor.top)),
1572 min(width, max(0, ctx->scissor.right - ctx->scissor.left)),
1573 min(height, max(0, ctx->scissor.bottom - ctx->scissor.top)));
1575 pglScissor(ctx->physDev->dc_rect.left, dy, width, height);
1577 wine_tsx11_unlock();
1582 * X11DRV_wglMakeCurrent
1584 * For OpenGL32 wglMakeCurrent.
1586 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
1588 HDC hdc = physDev->hdc;
1589 DWORD type = GetObjectType(hdc);
1591 TRACE("(%p,%p)\n", hdc, hglrc);
1593 if (!has_opengl()) {
1594 ERR("No libGL on this box - disabling OpenGL support !\n");
1599 if (hglrc == NULL) {
1600 ret = pglXMakeCurrent(gdi_display, None, NULL);
1601 NtCurrentTeb()->glContext = NULL;
1603 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1604 Drawable drawable = get_glxdrawable(physDev);
1605 if (ctx->ctx == NULL) {
1606 /* The describe lines below are for debugging purposes only */
1607 if (TRACE_ON(wgl)) {
1608 describeDrawable(ctx, drawable);
1609 describeContext(ctx);
1612 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1613 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1615 TRACE(" Creating GLX Context\n");
1617 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, type == OBJ_MEMDC ? False : True);
1618 else /* Create a GLX Context for a pbuffer */
1619 ctx->ctx = pglXCreateNewContext(gdi_display, ctx->fmt->fbconfig, ctx->fmt->render_type, NULL, True);
1621 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1623 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display, (void*) drawable, ctx->ctx);
1624 ret = pglXMakeCurrent(gdi_display, drawable, ctx->ctx);
1625 NtCurrentTeb()->glContext = ctx;
1629 ctx->physDev = physDev;
1630 ctx->pReadDev = physDev;
1632 if (type == OBJ_MEMDC)
1634 ctx->do_escape = TRUE;
1635 pglDrawBuffer(GL_FRONT_LEFT);
1639 sync_current_drawable(FALSE);
1643 wine_tsx11_unlock();
1644 TRACE(" returning %s\n", (ret ? "True" : "False"));
1649 * X11DRV_wglMakeContextCurrentARB
1651 * For OpenGL32 wglMakeContextCurrentARB
1653 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* pDrawDev, X11DRV_PDEVICE* pReadDev, HGLRC hglrc)
1656 TRACE("(%p,%p,%p)\n", pDrawDev, pReadDev, hglrc);
1658 if (!has_opengl()) {
1659 ERR("No libGL on this box - disabling OpenGL support !\n");
1664 if (hglrc == NULL) {
1665 ret = pglXMakeCurrent(gdi_display, None, NULL);
1666 NtCurrentTeb()->glContext = NULL;
1668 if (NULL == pglXMakeContextCurrent) {
1671 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1672 Drawable d_draw = get_glxdrawable(pDrawDev);
1673 Drawable d_read = get_glxdrawable(pReadDev);
1675 if (ctx->ctx == NULL) {
1676 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, GetObjectType(pDrawDev->hdc) == OBJ_MEMDC ? False : True);
1677 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1679 ctx->hdc = pDrawDev->hdc;
1680 ctx->physDev = pDrawDev;
1681 ctx->pReadDev = pReadDev;
1682 ret = pglXMakeContextCurrent(gdi_display, d_draw, d_read, ctx->ctx);
1683 NtCurrentTeb()->glContext = ctx;
1686 wine_tsx11_unlock();
1688 TRACE(" returning %s\n", (ret ? "True" : "False"));
1693 * X11DRV_wglShareLists
1695 * For OpenGL32 wglShaderLists.
1697 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
1698 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1699 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1701 TRACE("(%p, %p)\n", org, dest);
1703 if (!has_opengl()) {
1704 ERR("No libGL on this box - disabling OpenGL support !\n");
1708 if (NULL != dest && dest->ctx != NULL) {
1709 ERR("Could not share display lists, context already created !\n");
1712 if (org->ctx == NULL) {
1714 describeContext(org);
1717 org->ctx = pglXCreateContext(gdi_display, org->vis, NULL, GetObjectType(org->hdc) == OBJ_MEMDC ? False : True);
1718 else /* Create a GLX Context for a pbuffer */
1719 org->ctx = pglXCreateNewContext(gdi_display, org->fmt->fbconfig, org->fmt->render_type, NULL, True);
1720 wine_tsx11_unlock();
1721 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org->ctx, org);
1725 describeContext(dest);
1726 /* Create the destination context with display lists shared */
1728 dest->ctx = pglXCreateContext(gdi_display, dest->vis, org->ctx, GetObjectType(org->hdc) == OBJ_MEMDC ? False : True);
1729 else /* Create a GLX Context for a pbuffer */
1730 dest->ctx = pglXCreateNewContext(gdi_display, dest->fmt->fbconfig, dest->fmt->render_type, org->ctx, True);
1731 wine_tsx11_unlock();
1732 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1739 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
1741 /* We are running using client-side rendering fonts... */
1745 void *bitmap = NULL, *gl_bitmap = NULL;
1749 pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1750 pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1751 wine_tsx11_unlock();
1753 for (glyph = first; glyph < first + count; glyph++) {
1754 unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, NULL);
1755 int height, width_int;
1757 TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
1758 if (needed_size == GDI_ERROR) {
1759 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size);
1762 TRACE(" - needed size : %d\n", needed_size);
1765 if (needed_size > size) {
1767 HeapFree(GetProcessHeap(), 0, bitmap);
1768 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1769 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1770 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1772 if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, NULL) == GDI_ERROR) goto error;
1773 if (TRACE_ON(opengl)) {
1774 unsigned int height, width, bitmask;
1775 unsigned char *bitmap_ = (unsigned char *) bitmap;
1777 TRACE(" - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
1778 TRACE(" - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
1779 TRACE(" - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
1780 if (needed_size != 0) {
1781 TRACE(" - bitmap :\n");
1782 for (height = 0; height < gm.gmBlackBoxY; height++) {
1784 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
1789 if (*bitmap_ & bitmask)
1794 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
1800 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1801 * glyph for it to be drawn properly.
1803 if (needed_size != 0) {
1804 width_int = (gm.gmBlackBoxX + 31) / 32;
1805 for (height = 0; height < gm.gmBlackBoxY; height++) {
1807 for (width = 0; width < width_int; width++) {
1808 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
1809 ((int *) bitmap)[height * width_int + width];
1815 pglNewList(listBase++, GL_COMPILE);
1816 if (needed_size != 0) {
1817 pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
1818 0 - (int) gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - (int) gm.gmptGlyphOrigin.y,
1819 gm.gmCellIncX, gm.gmCellIncY,
1822 /* This is the case of 'empty' glyphs like the space character */
1823 pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
1826 wine_tsx11_unlock();
1830 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1831 wine_tsx11_unlock();
1833 HeapFree(GetProcessHeap(), 0, bitmap);
1834 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1839 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1840 wine_tsx11_unlock();
1842 HeapFree(GetProcessHeap(), 0, bitmap);
1843 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1848 * X11DRV_wglUseFontBitmapsA
1850 * For OpenGL32 wglUseFontBitmapsA.
1852 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1854 Font fid = physDev->font;
1856 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1858 if (!has_opengl()) {
1859 ERR("No libGL on this box - disabling OpenGL support !\n");
1864 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineA);
1868 /* I assume that the glyphs are at the same position for X and for Windows */
1869 pglXUseXFont(fid, first, count, listBase);
1870 wine_tsx11_unlock();
1875 * X11DRV_wglUseFontBitmapsW
1877 * For OpenGL32 wglUseFontBitmapsW.
1879 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1881 Font fid = physDev->font;
1883 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1885 if (!has_opengl()) {
1886 ERR("No libGL on this box - disabling OpenGL support !\n");
1891 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineW);
1894 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1897 /* I assume that the glyphs are at the same position for X and for Windows */
1898 pglXUseXFont(fid, first, count, listBase);
1899 wine_tsx11_unlock();
1903 static void WINAPI X11DRV_wglDisable(GLenum cap)
1905 if (cap == GL_SCISSOR_TEST)
1907 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1910 ctx->scissor_enabled = FALSE;
1916 wine_tsx11_unlock();
1920 static void WINAPI X11DRV_wglEnable(GLenum cap)
1922 if (cap == GL_SCISSOR_TEST)
1924 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1927 ctx->scissor_enabled = TRUE;
1933 wine_tsx11_unlock();
1937 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1938 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params)
1945 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1947 pglGetIntegerv(pname, params);
1949 * if we cannot find a Wine Context
1950 * we only have the default wine desktop context,
1951 * so if we have only a 24 depth say we have 32
1953 if (!ctx && *params == 24) {
1956 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
1961 Wine_GLContext *ctx = NtCurrentTeb()->glContext;
1963 pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_ALPHA_SIZE, params);
1964 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params);
1968 pglGetIntegerv(pname, params);
1971 wine_tsx11_unlock();
1974 static GLboolean WINAPI X11DRV_wglIsEnabled(GLenum cap)
1976 GLboolean enabled = False;
1978 if (cap == GL_SCISSOR_TEST)
1980 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1983 enabled = ctx->scissor_enabled;
1988 enabled = pglIsEnabled(cap);
1989 wine_tsx11_unlock();
1994 static void WINAPI X11DRV_wglScissor(GLint x, GLint y, GLsizei width, GLsizei height)
1996 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
2000 ctx->scissor.left = x;
2001 ctx->scissor.top = y;
2002 ctx->scissor.right = x + width;
2003 ctx->scissor.bottom = y + height;
2005 sync_current_drawable(TRUE);
2009 static void WINAPI X11DRV_wglViewport(GLint x, GLint y, GLsizei width, GLsizei height)
2011 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
2015 ctx->viewport.left = x;
2016 ctx->viewport.top = y;
2017 ctx->viewport.right = x + width;
2018 ctx->viewport.bottom = y + height;
2020 sync_current_drawable(TRUE);
2025 * X11DRV_wglGetExtensionsStringARB
2027 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
2029 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
2030 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2031 return WineGLInfo.wglExtensions;
2035 * X11DRV_wglCreatePbufferARB
2037 * WGL_ARB_pbuffer: wglCreatePbufferARB
2039 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
2041 Wine_GLPBuffer* object = NULL;
2042 WineGLPixelFormat *fmt = NULL;
2047 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
2049 if (0 >= iPixelFormat) {
2050 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
2051 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2052 return NULL; /* unexpected error */
2055 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2056 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nCfgs);
2058 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
2059 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2060 goto create_failed; /* unexpected error */
2063 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
2064 if (NULL == object) {
2065 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2066 goto create_failed; /* unexpected error */
2069 object->display = gdi_display;
2070 object->width = iWidth;
2071 object->height = iHeight;
2074 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
2075 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
2076 while (piAttribList && 0 != *piAttribList) {
2078 switch (*piAttribList) {
2079 case WGL_PBUFFER_LARGEST_ARB: {
2081 attr_v = *piAttribList;
2082 TRACE("WGL_LARGEST_PBUFFER_ARB = %d\n", attr_v);
2083 PUSH2(attribs, GLX_LARGEST_PBUFFER, attr_v);
2087 case WGL_TEXTURE_FORMAT_ARB: {
2089 attr_v = *piAttribList;
2090 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2091 if (use_render_texture_ati) {
2094 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2095 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
2096 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
2098 SetLastError(ERROR_INVALID_DATA);
2101 object->use_render_texture = 1;
2102 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
2104 if (WGL_NO_TEXTURE_ARB == attr_v) {
2105 object->use_render_texture = 0;
2107 if (!use_render_texture_emulation) {
2108 SetLastError(ERROR_INVALID_DATA);
2112 case WGL_TEXTURE_RGB_ARB:
2113 object->use_render_texture = GL_RGB;
2114 object->texture_bpp = 3;
2115 object->texture_format = GL_RGB;
2116 object->texture_type = GL_UNSIGNED_BYTE;
2118 case WGL_TEXTURE_RGBA_ARB:
2119 object->use_render_texture = GL_RGBA;
2120 object->texture_bpp = 4;
2121 object->texture_format = GL_RGBA;
2122 object->texture_type = GL_UNSIGNED_BYTE;
2125 /* WGL_FLOAT_COMPONENTS_NV */
2126 case WGL_TEXTURE_FLOAT_R_NV:
2127 object->use_render_texture = GL_FLOAT_R_NV;
2128 object->texture_bpp = 4;
2129 object->texture_format = GL_RED;
2130 object->texture_type = GL_FLOAT;
2132 case WGL_TEXTURE_FLOAT_RG_NV:
2133 object->use_render_texture = GL_FLOAT_RG_NV;
2134 object->texture_bpp = 8;
2135 object->texture_format = GL_LUMINANCE_ALPHA;
2136 object->texture_type = GL_FLOAT;
2138 case WGL_TEXTURE_FLOAT_RGB_NV:
2139 object->use_render_texture = GL_FLOAT_RGB_NV;
2140 object->texture_bpp = 12;
2141 object->texture_format = GL_RGB;
2142 object->texture_type = GL_FLOAT;
2144 case WGL_TEXTURE_FLOAT_RGBA_NV:
2145 object->use_render_texture = GL_FLOAT_RGBA_NV;
2146 object->texture_bpp = 16;
2147 object->texture_format = GL_RGBA;
2148 object->texture_type = GL_FLOAT;
2151 ERR("Unknown texture format: %x\n", attr_v);
2152 SetLastError(ERROR_INVALID_DATA);
2160 case WGL_TEXTURE_TARGET_ARB: {
2162 attr_v = *piAttribList;
2163 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2164 if (use_render_texture_ati) {
2167 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2168 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
2169 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
2170 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
2172 SetLastError(ERROR_INVALID_DATA);
2175 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
2177 if (WGL_NO_TEXTURE_ARB == attr_v) {
2178 object->texture_target = 0;
2180 if (!use_render_texture_emulation) {
2181 SetLastError(ERROR_INVALID_DATA);
2185 case WGL_TEXTURE_CUBE_MAP_ARB: {
2186 if (iWidth != iHeight) {
2187 SetLastError(ERROR_INVALID_DATA);
2190 object->texture_target = GL_TEXTURE_CUBE_MAP;
2191 object->texture_bind_target = GL_TEXTURE_BINDING_CUBE_MAP;
2194 case WGL_TEXTURE_1D_ARB: {
2196 SetLastError(ERROR_INVALID_DATA);
2199 object->texture_target = GL_TEXTURE_1D;
2200 object->texture_bind_target = GL_TEXTURE_BINDING_1D;
2203 case WGL_TEXTURE_2D_ARB: {
2204 object->texture_target = GL_TEXTURE_2D;
2205 object->texture_bind_target = GL_TEXTURE_BINDING_2D;
2208 case WGL_TEXTURE_RECTANGLE_NV: {
2209 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2210 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2214 ERR("Unknown texture target: %x\n", attr_v);
2215 SetLastError(ERROR_INVALID_DATA);
2223 case WGL_MIPMAP_TEXTURE_ARB: {
2225 attr_v = *piAttribList;
2226 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2227 if (use_render_texture_ati) {
2228 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
2230 if (!use_render_texture_emulation) {
2231 SetLastError(ERROR_INVALID_DATA);
2241 PUSH1(attribs, None);
2242 object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2243 TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
2244 if (!object->drawable) {
2245 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2246 goto create_failed; /* unexpected error */
2248 TRACE("->(%p)\n", object);
2249 return (HPBUFFERARB) object;
2252 HeapFree(GetProcessHeap(), 0, object);
2253 TRACE("->(FAILED)\n");
2254 return (HPBUFFERARB) NULL;
2258 * X11DRV_wglDestroyPbufferARB
2260 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2262 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2264 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2265 TRACE("(%p)\n", hPbuffer);
2266 if (NULL == object) {
2267 SetLastError(ERROR_INVALID_HANDLE);
2270 pglXDestroyPbuffer(object->display, object->drawable);
2271 HeapFree(GetProcessHeap(), 0, object);
2276 * X11DRV_wglGetPbufferDCARB
2278 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2279 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2280 * Gdi32 implements the part of this function which creates a device context.
2281 * This part associates the physDev with the X drawable of the pbuffer.
2283 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
2285 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2286 if (NULL == object) {
2287 SetLastError(ERROR_INVALID_HANDLE);
2291 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2292 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2293 physDev->current_pf = object->fmt->iPixelFormat;
2294 physDev->drawable = object->drawable;
2295 SetRect( &physDev->drawable_rect, 0, 0, object->width, object->height );
2296 physDev->dc_rect = physDev->drawable_rect;
2298 TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);
2299 return physDev->hdc;
2303 * X11DRV_wglQueryPbufferARB
2305 * WGL_ARB_pbuffer: wglQueryPbufferARB
2307 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2309 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2310 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2311 if (NULL == object) {
2312 SetLastError(ERROR_INVALID_HANDLE);
2315 switch (iAttribute) {
2316 case WGL_PBUFFER_WIDTH_ARB:
2317 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2319 case WGL_PBUFFER_HEIGHT_ARB:
2320 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2323 case WGL_PBUFFER_LOST_ARB:
2324 /* GLX Pbuffers cannot be lost by default. We can support this by
2325 * setting GLX_PRESERVED_CONTENTS to False and using glXSelectEvent
2326 * to receive pixel buffer clobber events, however that may or may
2327 * not give any benefit */
2328 *piValue = GL_FALSE;
2331 case WGL_TEXTURE_FORMAT_ARB:
2332 if (use_render_texture_ati) {
2334 int type = WGL_NO_TEXTURE_ARB;
2335 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2337 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2338 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2339 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2343 if (!object->use_render_texture) {
2344 *piValue = WGL_NO_TEXTURE_ARB;
2346 if (!use_render_texture_emulation) {
2347 SetLastError(ERROR_INVALID_HANDLE);
2350 switch(object->use_render_texture) {
2352 *piValue = WGL_TEXTURE_RGB_ARB;
2355 *piValue = WGL_TEXTURE_RGBA_ARB;
2357 /* WGL_FLOAT_COMPONENTS_NV */
2359 *piValue = WGL_TEXTURE_FLOAT_R_NV;
2361 case GL_FLOAT_RG_NV:
2362 *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2364 case GL_FLOAT_RGB_NV:
2365 *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2367 case GL_FLOAT_RGBA_NV:
2368 *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2371 ERR("Unknown texture format: %x\n", object->use_render_texture);
2377 case WGL_TEXTURE_TARGET_ARB:
2378 if (use_render_texture_ati) {
2380 int type = WGL_NO_TEXTURE_ARB;
2381 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2383 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2384 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2385 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2386 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2390 if (!object->texture_target) {
2391 *piValue = WGL_NO_TEXTURE_ARB;
2393 if (!use_render_texture_emulation) {
2394 SetLastError(ERROR_INVALID_DATA);
2397 switch (object->texture_target) {
2398 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_1D_ARB; break;
2399 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_2D_ARB; break;
2400 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2401 case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2407 case WGL_MIPMAP_TEXTURE_ARB:
2408 if (use_render_texture_ati) {
2409 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2411 *piValue = GL_FALSE; /** don't support that */
2412 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2417 FIXME("unexpected attribute %x\n", iAttribute);
2425 * X11DRV_wglReleasePbufferDCARB
2427 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2429 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2431 TRACE("(%p, %p)\n", hPbuffer, hdc);
2437 * X11DRV_wglSetPbufferAttribARB
2439 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2441 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2443 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2444 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2445 if (NULL == object) {
2446 SetLastError(ERROR_INVALID_HANDLE);
2449 if (!object->use_render_texture) {
2450 SetLastError(ERROR_INVALID_HANDLE);
2453 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2456 if (NULL != pglXDrawableAttribATI) {
2457 if (use_render_texture_ati) {
2458 FIXME("Need conversion for GLX_ATI_render_texture\n");
2460 return pglXDrawableAttribATI(object->display, object->drawable, piAttribList);
2466 * X11DRV_wglChoosePixelFormatARB
2468 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2470 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2475 GLXFBConfig* cfgs = NULL;
2479 WineGLPixelFormat *fmt;
2483 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2484 if (NULL != pfAttribFList) {
2485 FIXME("unused pfAttribFList\n");
2488 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2489 if (-1 == nAttribs) {
2490 WARN("Cannot convert WGL to GLX attributes\n");
2493 PUSH1(attribs, None);
2495 /* Search for FB configurations matching the requirements in attribs */
2496 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2498 WARN("Compatible Pixel Format not found\n");
2502 /* Loop through all matching formats and check if they are suitable.
2503 * Note that this function should at max return nMaxFormats different formats */
2504 for(run=0; run < 2; run++)
2506 for (it = 0; it < nCfgs; ++it) {
2507 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2509 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2513 /* Search for the format in our list of compatible formats */
2514 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id);
2518 /* During the first run we only want onscreen formats and during the second only offscreen 'XOR' */
2519 if( ((run == 0) && fmt->offscreenOnly) || ((run == 1) && !fmt->offscreenOnly) )
2522 if(pfmt_it < nMaxFormats) {
2523 piFormats[pfmt_it] = fmt->iPixelFormat;
2524 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it]);
2530 *nNumFormats = pfmt_it;
2537 * X11DRV_wglGetPixelFormatAttribivARB
2539 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2541 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2544 WineGLPixelFormat *fmt = NULL;
2548 int nWGLFormats = 0;
2550 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2552 if (0 < iLayerPlane) {
2553 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2557 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2558 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2559 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2560 fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nWGLFormats);
2562 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2565 for (i = 0; i < nAttributes; ++i) {
2566 const int curWGLAttr = piAttributes[i];
2567 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2569 switch (curWGLAttr) {
2570 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2571 piValues[i] = nWGLFormats;
2574 case WGL_SUPPORT_OPENGL_ARB:
2575 piValues[i] = GL_TRUE;
2578 case WGL_ACCELERATION_ARB:
2579 curGLXAttr = GLX_CONFIG_CAVEAT;
2580 if (!fmt) goto pix_error;
2581 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2582 if (hTest) goto get_error;
2584 case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2585 case GLX_SLOW_CONFIG: piValues[i] = WGL_GENERIC_ACCELERATION_ARB; break;
2586 case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2588 ERR("unexpected Config Caveat(%x)\n", tmp);
2589 piValues[i] = WGL_NO_ACCELERATION_ARB;
2593 case WGL_TRANSPARENT_ARB:
2594 curGLXAttr = GLX_TRANSPARENT_TYPE;
2595 if (!fmt) goto pix_error;
2596 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2597 if (hTest) goto get_error;
2598 piValues[i] = GL_FALSE;
2599 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2602 case WGL_PIXEL_TYPE_ARB:
2603 curGLXAttr = GLX_RENDER_TYPE;
2604 if (!fmt) goto pix_error;
2605 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2606 if (hTest) goto get_error;
2607 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2608 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2609 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2610 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2611 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2613 ERR("unexpected RenderType(%x)\n", tmp);
2614 piValues[i] = WGL_TYPE_RGBA_ARB;
2618 case WGL_COLOR_BITS_ARB:
2619 curGLXAttr = GLX_BUFFER_SIZE;
2622 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2623 if (use_render_texture_ati) {
2624 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
2627 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2628 if (use_render_texture_ati) {
2629 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
2632 if (!use_render_texture_emulation) {
2633 piValues[i] = GL_FALSE;
2636 curGLXAttr = GLX_RENDER_TYPE;
2637 if (!fmt) goto pix_error;
2638 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2639 if (hTest) goto get_error;
2640 if (GLX_COLOR_INDEX_BIT == tmp) {
2641 piValues[i] = GL_FALSE;
2644 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2645 if (hTest) goto get_error;
2646 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2649 case WGL_BLUE_BITS_ARB:
2650 curGLXAttr = GLX_BLUE_SIZE;
2652 case WGL_RED_BITS_ARB:
2653 curGLXAttr = GLX_RED_SIZE;
2655 case WGL_GREEN_BITS_ARB:
2656 curGLXAttr = GLX_GREEN_SIZE;
2658 case WGL_ALPHA_BITS_ARB:
2659 curGLXAttr = GLX_ALPHA_SIZE;
2661 case WGL_DEPTH_BITS_ARB:
2662 curGLXAttr = GLX_DEPTH_SIZE;
2664 case WGL_STENCIL_BITS_ARB:
2665 curGLXAttr = GLX_STENCIL_SIZE;
2667 case WGL_DOUBLE_BUFFER_ARB:
2668 curGLXAttr = GLX_DOUBLEBUFFER;
2670 case WGL_STEREO_ARB:
2671 curGLXAttr = GLX_STEREO;
2673 case WGL_AUX_BUFFERS_ARB:
2674 curGLXAttr = GLX_AUX_BUFFERS;
2677 case WGL_SUPPORT_GDI_ARB:
2678 if (!fmt) goto pix_error;
2679 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &tmp);
2680 if (hTest) goto get_error;
2682 piValues[i] = GL_FALSE;
2685 curGLXAttr = GLX_X_RENDERABLE;
2688 case WGL_DRAW_TO_WINDOW_ARB:
2689 case WGL_DRAW_TO_BITMAP_ARB:
2690 case WGL_DRAW_TO_PBUFFER_ARB:
2691 if (!fmt) goto pix_error;
2692 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2693 if (hTest) goto get_error;
2694 if((curWGLAttr == WGL_DRAW_TO_WINDOW_ARB && (tmp&GLX_WINDOW_BIT)) ||
2695 (curWGLAttr == WGL_DRAW_TO_BITMAP_ARB && (tmp&GLX_PIXMAP_BIT)) ||
2696 (curWGLAttr == WGL_DRAW_TO_PBUFFER_ARB && (tmp&GLX_PBUFFER_BIT)))
2697 piValues[i] = GL_TRUE;
2699 piValues[i] = GL_FALSE;
2702 case WGL_PBUFFER_LARGEST_ARB:
2703 curGLXAttr = GLX_LARGEST_PBUFFER;
2706 case WGL_SAMPLE_BUFFERS_ARB:
2707 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2710 case WGL_SAMPLES_ARB:
2711 curGLXAttr = GLX_SAMPLES_ARB;
2714 case WGL_FLOAT_COMPONENTS_NV:
2715 curGLXAttr = GLX_FLOAT_COMPONENTS_NV;
2718 case WGL_ACCUM_RED_BITS_ARB:
2719 curGLXAttr = GLX_ACCUM_RED_SIZE;
2721 case WGL_ACCUM_GREEN_BITS_ARB:
2722 curGLXAttr = GLX_ACCUM_GREEN_SIZE;
2724 case WGL_ACCUM_BLUE_BITS_ARB:
2725 curGLXAttr = GLX_ACCUM_BLUE_SIZE;
2727 case WGL_ACCUM_ALPHA_BITS_ARB:
2728 curGLXAttr = GLX_ACCUM_ALPHA_SIZE;
2730 case WGL_ACCUM_BITS_ARB:
2731 if (!fmt) goto pix_error;
2732 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_RED_SIZE, &tmp);
2733 if (hTest) goto get_error;
2735 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_GREEN_SIZE, &tmp);
2736 if (hTest) goto get_error;
2738 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_BLUE_SIZE, &tmp);
2739 if (hTest) goto get_error;
2741 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ACCUM_ALPHA_SIZE, &tmp);
2742 if (hTest) goto get_error;
2747 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2750 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2751 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2752 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2754 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2755 * and check which options can work using iPixelFormat=0 and which not.
2756 * A problem would be that this function is an extension. This would
2757 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2759 if (0 != curGLXAttr && iPixelFormat != 0) {
2760 if (!fmt) goto pix_error;
2761 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2762 if (hTest) goto get_error;
2765 piValues[i] = GL_FALSE;
2771 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2775 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats);
2780 * X11DRV_wglGetPixelFormatAttribfvARB
2782 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2784 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
2790 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2792 /* Allocate a temporary array to store integer values */
2793 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2795 ERR("couldn't allocate %d array\n", nAttributes);
2799 /* Piggy-back on wglGetPixelFormatAttribivARB */
2800 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2802 /* Convert integer values to float. Should also check for attributes
2803 that can give decimal values here */
2804 for (i=0; i<nAttributes;i++) {
2805 pfValues[i] = attr[i];
2809 HeapFree(GetProcessHeap(), 0, attr);
2814 * X11DRV_wglBindTexImageARB
2816 * WGL_ARB_render_texture: wglBindTexImageARB
2818 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2820 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2821 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2822 if (NULL == object) {
2823 SetLastError(ERROR_INVALID_HANDLE);
2826 if (!object->use_render_texture) {
2827 SetLastError(ERROR_INVALID_HANDLE);
2831 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2832 static int init = 0;
2833 int prev_binded_texture = 0;
2834 GLXContext prev_context = pglXGetCurrentContext();
2835 Drawable prev_drawable = pglXGetCurrentDrawable();
2836 GLXContext tmp_context;
2838 /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2839 This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2840 isn't ideal performance wise but I wasn't able to get other ways working.
2843 init = 1; /* Only show the FIXME once for performance reasons */
2844 FIXME("partial stub!\n");
2847 TRACE("drawable=%p, context=%p\n", (void*)object->drawable, prev_context);
2848 tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, prev_context, True);
2850 pglGetIntegerv(object->texture_bind_target, &prev_binded_texture);
2852 /* Switch to our pbuffer */
2853 pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
2855 /* Make sure that the prev_binded_texture is set as the current texture state isn't shared between contexts.
2856 * After that upload the pbuffer texture data. */
2857 pglBindTexture(object->texture_target, prev_binded_texture);
2858 pglCopyTexImage2D(object->texture_target, 0, object->use_render_texture, 0, 0, object->width, object->height, 0);
2860 /* Switch back to the original drawable and upload the pbuffer-texture */
2861 pglXMakeCurrent(object->display, prev_drawable, prev_context);
2862 pglXDestroyContext(gdi_display, tmp_context);
2866 if (NULL != pglXBindTexImageATI) {
2871 case WGL_FRONT_LEFT_ARB:
2872 buffer = GLX_FRONT_LEFT_ATI;
2874 case WGL_FRONT_RIGHT_ARB:
2875 buffer = GLX_FRONT_RIGHT_ATI;
2877 case WGL_BACK_LEFT_ARB:
2878 buffer = GLX_BACK_LEFT_ATI;
2880 case WGL_BACK_RIGHT_ARB:
2881 buffer = GLX_BACK_RIGHT_ATI;
2884 ERR("Unknown iBuffer=%#x\n", iBuffer);
2888 /* In the sample 'ogl_offscreen_rendering_3' from codesampler.net I get garbage on the screen.
2889 * I'm not sure if that's a bug in the ATI extension or in the program. I think that the program
2890 * expected a single buffering format since it didn't ask for double buffering. A buffer swap
2891 * fixed the program. I don't know what the correct behavior is. On the other hand that demo
2892 * works fine using our pbuffer emulation path.
2894 return pglXBindTexImageATI(object->display, object->drawable, buffer);
2900 * X11DRV_wglReleaseTexImageARB
2902 * WGL_ARB_render_texture: wglReleaseTexImageARB
2904 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2906 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2907 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2908 if (NULL == object) {
2909 SetLastError(ERROR_INVALID_HANDLE);
2912 if (!object->use_render_texture) {
2913 SetLastError(ERROR_INVALID_HANDLE);
2916 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2919 if (NULL != pglXReleaseTexImageATI) {
2924 case WGL_FRONT_LEFT_ARB:
2925 buffer = GLX_FRONT_LEFT_ATI;
2927 case WGL_FRONT_RIGHT_ARB:
2928 buffer = GLX_FRONT_RIGHT_ATI;
2930 case WGL_BACK_LEFT_ARB:
2931 buffer = GLX_BACK_LEFT_ATI;
2933 case WGL_BACK_RIGHT_ARB:
2934 buffer = GLX_BACK_RIGHT_ATI;
2937 ERR("Unknown iBuffer=%#x\n", iBuffer);
2940 return pglXReleaseTexImageATI(object->display, object->drawable, buffer);
2946 * X11DRV_wglGetExtensionsStringEXT
2948 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2950 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
2951 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2952 return WineGLInfo.wglExtensions;
2956 * X11DRV_wglGetSwapIntervalEXT
2958 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2960 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
2961 FIXME("(),stub!\n");
2962 return swap_interval;
2966 * X11DRV_wglSwapIntervalEXT
2968 * WGL_EXT_swap_control: wglSwapIntervalEXT
2970 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
2971 TRACE("(%d)\n", interval);
2972 swap_interval = interval;
2973 if (NULL != pglXSwapIntervalSGI) {
2974 return 0 == pglXSwapIntervalSGI(interval);
2976 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
2981 * X11DRV_wglAllocateMemoryNV
2983 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
2985 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
2986 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
2987 if (pglXAllocateMemoryNV == NULL)
2990 return pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
2994 * X11DRV_wglFreeMemoryNV
2996 * WGL_NV_vertex_array_range: wglFreeMemoryNV
2998 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
2999 TRACE("(%p)\n", pointer);
3000 if (pglXFreeMemoryNV == NULL)
3003 pglXFreeMemoryNV(pointer);
3007 * glxRequireVersion (internal)
3009 * Check if the supported GLX version matches requiredVersion.
3011 static BOOL glxRequireVersion(int requiredVersion)
3013 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
3014 if(requiredVersion <= WineGLInfo.glxVersion[1])
3020 static BOOL glxRequireExtension(const char *requiredExtension)
3022 if (strstr(WineGLInfo.glxExtensions, requiredExtension) == NULL) {
3029 static void register_extension_string(const char *ext)
3031 if (WineGLInfo.wglExtensions[0])
3032 strcat(WineGLInfo.wglExtensions, " ");
3033 strcat(WineGLInfo.wglExtensions, ext);
3035 TRACE("'%s'\n", ext);
3038 static BOOL register_extension(const WineGLExtension * ext)
3042 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
3043 WineGLExtensionList[WineGLExtensionListSize++] = ext;
3045 register_extension_string(ext->extName);
3047 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
3048 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
3053 static const WineGLExtension WGL_internal_functions =
3057 { "wglDisable", X11DRV_wglDisable },
3058 { "wglEnable", X11DRV_wglEnable },
3059 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
3060 { "wglIsEnabled", X11DRV_wglIsEnabled },
3061 { "wglScissor", X11DRV_wglScissor },
3062 { "wglViewport", X11DRV_wglViewport },
3067 static const WineGLExtension WGL_ARB_extensions_string =
3069 "WGL_ARB_extensions_string",
3071 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
3075 static const WineGLExtension WGL_ARB_make_current_read =
3077 "WGL_ARB_make_current_read",
3079 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
3080 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
3084 static const WineGLExtension WGL_ARB_multisample =
3086 "WGL_ARB_multisample",
3089 static const WineGLExtension WGL_ARB_pbuffer =
3093 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
3094 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
3095 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
3096 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
3097 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
3098 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
3102 static const WineGLExtension WGL_ARB_pixel_format =
3104 "WGL_ARB_pixel_format",
3106 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
3107 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
3108 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
3112 static const WineGLExtension WGL_ARB_render_texture =
3114 "WGL_ARB_render_texture",
3116 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
3117 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
3121 static const WineGLExtension WGL_EXT_extensions_string =
3123 "WGL_EXT_extensions_string",
3125 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
3129 static const WineGLExtension WGL_EXT_swap_control =
3131 "WGL_EXT_swap_control",
3133 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
3134 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
3138 static const WineGLExtension WGL_NV_vertex_array_range =
3140 "WGL_NV_vertex_array_range",
3142 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
3143 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
3148 * X11DRV_WineGL_LoadExtensions
3150 static void X11DRV_WineGL_LoadExtensions(void)
3152 WineGLInfo.wglExtensions[0] = 0;
3154 /* Load Wine internal functions */
3155 register_extension(&WGL_internal_functions);
3157 /* ARB Extensions */
3159 if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3161 register_extension_string("WGL_ARB_pixel_format_float");
3162 register_extension_string("WGL_ATI_pixel_format_float");
3165 register_extension(&WGL_ARB_extensions_string);
3167 if (glxRequireVersion(3))
3168 register_extension(&WGL_ARB_make_current_read);
3170 if (glxRequireExtension("GLX_ARB_multisample"))
3171 register_extension(&WGL_ARB_multisample);
3173 /* In general pbuffer functionality requires support in the X-server. The functionality is
3174 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3175 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3176 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3178 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3179 * without support in the X-server (which other Mesa based drivers require).
3181 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3182 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3183 * is available pbuffers must be available too. */
3184 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3185 register_extension(&WGL_ARB_pbuffer);
3187 register_extension(&WGL_ARB_pixel_format);
3189 /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3190 if (glxRequireExtension("GLX_ATI_render_texture") ||
3191 glxRequireExtension("GLX_ARB_render_texture") ||
3192 (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation))
3194 register_extension(&WGL_ARB_render_texture);
3196 /* The WGL version of GLX_NV_float_buffer requires render_texture */
3197 if(glxRequireExtension("GLX_NV_float_buffer"))
3198 register_extension_string("WGL_NV_float_buffer");
3200 /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3201 if(strstr(WineGLInfo.glExtensions, "GL_NV_texture_rectangle") != NULL)
3202 register_extension_string("WGL_NV_texture_rectangle");
3205 /* EXT Extensions */
3207 register_extension(&WGL_EXT_extensions_string);
3209 /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3210 * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3211 register_extension(&WGL_EXT_swap_control);
3213 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3214 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
3215 register_extension(&WGL_NV_vertex_array_range);
3219 static XID create_glxpixmap(X11DRV_PDEVICE *physDev)
3223 XVisualInfo template;
3228 /* Retrieve the visualid from our main visual which is the only visual we can use */
3229 template.visualid = XVisualIDFromVisual(visual);
3230 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
3232 ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
3234 wine_tsx11_unlock();
3235 TRACE("return %lx\n", ret);
3239 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3245 if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
3246 ret = physDev->drawable; /* PBuffer */
3249 if(!physDev->bitmap->glxpixmap)
3250 physDev->bitmap->glxpixmap = create_glxpixmap(physDev);
3251 ret = physDev->bitmap->glxpixmap;
3255 ret = physDev->drawable;
3259 BOOL destroy_glxpixmap(XID glxpixmap)
3262 pglXDestroyGLXPixmap(gdi_display, glxpixmap);
3263 wine_tsx11_unlock();
3268 * X11DRV_SwapBuffers
3270 * Swap the buffers of this DC
3272 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev)
3274 GLXDrawable drawable;
3275 if (!has_opengl()) {
3276 ERR("No libGL on this box - disabling OpenGL support !\n");
3280 TRACE_(opengl)("(%p)\n", physDev);
3282 drawable = get_glxdrawable(physDev);
3284 pglXSwapBuffers(gdi_display, drawable);
3285 wine_tsx11_unlock();
3290 static long prev_time, frames;
3292 DWORD time = GetTickCount();
3294 /* every 1.5 seconds */
3295 if (time - prev_time > 1500) {
3296 TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
3305 /***********************************************************************
3306 * X11DRV_setup_opengl_visual
3308 * Setup the default visual used for OpenGL and Direct3D, and the desktop
3309 * window (if it exists). If OpenGL isn't available, the visual is simply
3310 * set to the default visual for the display
3312 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
3314 XVisualInfo *visual = NULL;
3317 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support,
3318 * D3D and some applications can make use of aux buffers.
3320 int visualProperties[][11] = {
3321 { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_AUX_BUFFERS, 1, None },
3322 { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_ALPHA_SIZE, 8, None },
3323 { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, GLX_STENCIL_SIZE, 8, None },
3324 { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, None },
3331 for (i = 0; i < sizeof(visualProperties)/sizeof(visualProperties[0]); ++i) {
3332 visual = pglXChooseVisual(display, DefaultScreen(display), visualProperties[i]);
3336 wine_tsx11_unlock();
3339 TRACE("Visual ID %lx Chosen\n", visual->visualid);
3341 WARN("No suitable visual found\n");
3346 #else /* no OpenGL includes */
3348 /***********************************************************************
3349 * ChoosePixelFormat (X11DRV.@)
3351 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
3352 const PIXELFORMATDESCRIPTOR *ppfd) {
3353 ERR("No OpenGL support compiled in.\n");
3358 /***********************************************************************
3359 * DescribePixelFormat (X11DRV.@)
3361 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
3364 PIXELFORMATDESCRIPTOR *ppfd) {
3365 ERR("No OpenGL support compiled in.\n");
3370 /***********************************************************************
3371 * GetPixelFormat (X11DRV.@)
3373 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
3374 ERR("No OpenGL support compiled in.\n");
3379 /***********************************************************************
3380 * SetPixelFormat (X11DRV.@)
3382 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
3384 const PIXELFORMATDESCRIPTOR *ppfd) {
3385 ERR("No OpenGL support compiled in.\n");
3390 /***********************************************************************
3391 * SwapBuffers (X11DRV.@)
3393 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
3394 ERR_(opengl)("No OpenGL support compiled in.\n");
3400 * X11DRV_wglCreateContext
3402 * For OpenGL32 wglCreateContext.
3404 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) {
3405 ERR_(opengl)("No OpenGL support compiled in.\n");
3410 * X11DRV_wglDeleteContext
3412 * For OpenGL32 wglDeleteContext.
3414 BOOL X11DRV_wglDeleteContext(HGLRC hglrc) {
3415 ERR_(opengl)("No OpenGL support compiled in.\n");
3420 * X11DRV_wglGetProcAddress
3422 * For OpenGL32 wglGetProcAddress.
3424 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
3425 ERR_(opengl)("No OpenGL support compiled in.\n");
3429 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *hDevice, void *hPbuffer)
3431 ERR_(opengl)("No OpenGL support compiled in.\n");
3435 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) {
3436 ERR_(opengl)("No OpenGL support compiled in.\n");
3441 * X11DRV_wglMakeCurrent
3443 * For OpenGL32 wglMakeCurrent.
3445 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
3446 ERR_(opengl)("No OpenGL support compiled in.\n");
3451 * X11DRV_wglShareLists
3453 * For OpenGL32 wglShaderLists.
3455 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
3456 ERR_(opengl)("No OpenGL support compiled in.\n");
3461 * X11DRV_wglUseFontBitmapsA
3463 * For OpenGL32 wglUseFontBitmapsA.
3465 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3467 ERR_(opengl)("No OpenGL support compiled in.\n");
3472 * X11DRV_wglUseFontBitmapsW
3474 * For OpenGL32 wglUseFontBitmapsW.
3476 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3478 ERR_(opengl)("No OpenGL support compiled in.\n");
3482 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
3487 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3492 BOOL destroy_glxpixmap(XID glxpixmap)
3497 #endif /* defined(HAVE_OPENGL) */