2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006 Roderick Colenbrander
8 * Copyright 2006 Tomas Carnecky
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
34 #include "wine/library.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
38 WINE_DECLARE_DEBUG_CHANNEL(opengl);
52 #ifdef HAVE_GL_GLEXT_H
53 # include <GL/glext.h>
62 /* Redefines the constants */
63 #define CALLBACK __stdcall
64 #define WINAPI __stdcall
65 #define APIENTRY WINAPI
68 WINE_DECLARE_DEBUG_CHANNEL(fps);
70 typedef struct wine_glcontext {
76 X11DRV_PDEVICE *physDev;
80 struct wine_glcontext *next;
81 struct wine_glcontext *prev;
84 typedef struct wine_glpbuffer {
93 int use_render_texture;
94 GLuint texture_target;
95 GLuint texture_bind_target;
104 typedef struct wine_glextension {
107 const char *funcName;
113 const char *glVersion;
114 const char *glExtensions;
118 const char *glxServerVersion;
119 const char *glxServerExtensions;
121 const char *glxClientVersion;
122 const char *glxClientExtensions;
124 const char *glxExtensions;
127 char wglExtensions[4096];
130 typedef struct wine_glpixelformat {
136 static Wine_GLContext *context_list;
137 static struct WineGLInfo WineGLInfo = { 0 };
138 static int use_render_texture_emulation = 0;
139 static int use_render_texture_ati = 0;
140 static int swap_interval = 1;
142 #define MAX_EXTENSIONS 16
143 static const WineGLExtension *WineGLExtensionList[MAX_EXTENSIONS];
144 static int WineGLExtensionListSize;
146 #define MAX_GLPIXELFORMATS 32
147 static WineGLPixelFormat WineGLPixelFormatList[MAX_GLPIXELFORMATS];
148 static int WineGLPixelFormatListSize = 0;
150 static void X11DRV_WineGL_LoadExtensions(void);
152 static void dump_PIXELFORMATDESCRIPTOR(const PIXELFORMATDESCRIPTOR *ppfd) {
153 TRACE(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
154 TRACE(" - dwFlags : ");
155 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) TRACE(#tv " ")
156 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
157 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
158 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
159 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
160 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
161 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
162 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
163 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
164 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
165 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
166 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
167 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
168 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
169 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
170 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
171 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
175 TRACE(" - iPixelType : ");
176 switch (ppfd->iPixelType) {
177 case PFD_TYPE_RGBA: TRACE("PFD_TYPE_RGBA"); break;
178 case PFD_TYPE_COLORINDEX: TRACE("PFD_TYPE_COLORINDEX"); break;
182 TRACE(" - Color : %d\n", ppfd->cColorBits);
183 TRACE(" - Red : %d\n", ppfd->cRedBits);
184 TRACE(" - Green : %d\n", ppfd->cGreenBits);
185 TRACE(" - Blue : %d\n", ppfd->cBlueBits);
186 TRACE(" - Alpha : %d\n", ppfd->cAlphaBits);
187 TRACE(" - Accum : %d\n", ppfd->cAccumBits);
188 TRACE(" - Depth : %d\n", ppfd->cDepthBits);
189 TRACE(" - Stencil : %d\n", ppfd->cStencilBits);
190 TRACE(" - Aux : %d\n", ppfd->cAuxBuffers);
192 TRACE(" - iLayerType : ");
193 switch (ppfd->iLayerType) {
194 case PFD_MAIN_PLANE: TRACE("PFD_MAIN_PLANE"); break;
195 case PFD_OVERLAY_PLANE: TRACE("PFD_OVERLAY_PLANE"); break;
196 case (BYTE)PFD_UNDERLAY_PLANE: TRACE("PFD_UNDERLAY_PLANE"); break;
201 #define PUSH1(attribs,att) do { attribs[nAttribs++] = (att); } while (0)
202 #define PUSH2(attribs,att,value) do { attribs[nAttribs++] = (att); attribs[nAttribs++] = (value); } while(0)
204 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
206 MAKE_FUNCPTR(glXChooseVisual)
207 MAKE_FUNCPTR(glXCreateContext)
208 MAKE_FUNCPTR(glXCreateGLXPixmap)
209 MAKE_FUNCPTR(glXGetCurrentContext)
210 MAKE_FUNCPTR(glXDestroyContext)
211 MAKE_FUNCPTR(glXDestroyGLXPixmap)
212 MAKE_FUNCPTR(glXGetConfig)
213 MAKE_FUNCPTR(glXIsDirect)
214 MAKE_FUNCPTR(glXMakeCurrent)
215 MAKE_FUNCPTR(glXSwapBuffers)
216 MAKE_FUNCPTR(glXQueryExtension)
217 MAKE_FUNCPTR(glXQueryVersion)
218 MAKE_FUNCPTR(glXUseXFont)
221 MAKE_FUNCPTR(glXGetClientString)
222 MAKE_FUNCPTR(glXQueryExtensionsString)
223 MAKE_FUNCPTR(glXQueryServerString)
226 MAKE_FUNCPTR(glXGetFBConfigs)
227 MAKE_FUNCPTR(glXChooseFBConfig)
228 MAKE_FUNCPTR(glXCreatePbuffer)
229 MAKE_FUNCPTR(glXDestroyPbuffer)
230 MAKE_FUNCPTR(glXGetFBConfigAttrib)
231 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
232 MAKE_FUNCPTR(glXMakeContextCurrent)
233 MAKE_FUNCPTR(glXQueryDrawable)
234 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
237 static void* (*pglXGetProcAddressARB)(const GLubyte *);
238 static BOOL (*pglXBindTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
239 static BOOL (*pglXReleaseTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
240 static BOOL (*pglXDrawableAttribARB)(Display *dpy, GLXDrawable draw, const int *attribList);
241 static int (*pglXSwapIntervalSGI)(int);
243 /* NV GLX Extension */
244 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
245 static void (*pglXFreeMemoryNV)(GLvoid *pointer);
247 /* Standard OpenGL */
248 MAKE_FUNCPTR(glBindTexture)
249 MAKE_FUNCPTR(glBitmap)
250 MAKE_FUNCPTR(glCopyTexSubImage1D)
251 MAKE_FUNCPTR(glCopyTexSubImage2D)
252 MAKE_FUNCPTR(glDisable)
253 MAKE_FUNCPTR(glDrawBuffer)
254 MAKE_FUNCPTR(glEnable)
255 MAKE_FUNCPTR(glEndList)
256 MAKE_FUNCPTR(glGetError)
257 MAKE_FUNCPTR(glGetIntegerv)
258 MAKE_FUNCPTR(glGetString)
259 MAKE_FUNCPTR(glIsEnabled)
260 MAKE_FUNCPTR(glNewList)
261 MAKE_FUNCPTR(glPixelStorei)
262 MAKE_FUNCPTR(glScissor)
263 MAKE_FUNCPTR(glViewport)
266 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
268 static BOOL infoInitialized = FALSE;
270 int screen = DefaultScreen(gdi_display);
271 Window win = RootWindow(gdi_display, screen);
273 XVisualInfo template;
276 GLXContext ctx = NULL;
280 infoInitialized = TRUE;
284 visual = DefaultVisual(gdi_display, screen);
285 template.visualid = XVisualIDFromVisual(visual);
286 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
288 WORD old_fs = wine_get_fs();
289 /* Create a GLX Context. Without one we can't query GL information */
290 ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
291 if (wine_get_fs() != old_fs)
293 wine_set_fs( old_fs );
295 ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
296 ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
302 pglXMakeCurrent(gdi_display, win, ctx);
304 ERR(" couldn't initialize OpenGL, expect problems\n");
309 WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
310 WineGLInfo.glExtensions = strdup((const char *) pglGetString(GL_EXTENSIONS));
312 /* Get the common GLX version supported by GLX client and server ( major/minor) */
313 pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
315 WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
316 WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
318 WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
319 WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
321 WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
322 WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
324 TRACE("GL version : %s.\n", WineGLInfo.glVersion);
325 TRACE("GLX version : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
326 TRACE("Server GLX version : %s.\n", WineGLInfo.glxServerVersion);
327 TRACE("Client GLX version : %s.\n", WineGLInfo.glxClientVersion);
328 TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
332 pglXMakeCurrent(gdi_display, None, NULL);
333 pglXDestroyContext(gdi_display, ctx);
339 static BOOL has_opengl(void)
341 static int init_done;
342 static void *opengl_handle;
343 const char *glx_extensions;
345 int error_base, event_base;
347 if (init_done) return (opengl_handle != NULL);
350 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
351 and include all dependencies */
352 opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, NULL, 0);
353 if (opengl_handle == NULL) return FALSE;
355 pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
356 if (pglXGetProcAddressARB == NULL) {
357 ERR("could not find glXGetProcAddressARB in libGL.\n");
361 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
363 LOAD_FUNCPTR(glXChooseVisual)
364 LOAD_FUNCPTR(glXCreateContext)
365 LOAD_FUNCPTR(glXCreateGLXPixmap)
366 LOAD_FUNCPTR(glXGetCurrentContext)
367 LOAD_FUNCPTR(glXDestroyContext)
368 LOAD_FUNCPTR(glXDestroyGLXPixmap)
369 LOAD_FUNCPTR(glXGetConfig)
370 LOAD_FUNCPTR(glXIsDirect)
371 LOAD_FUNCPTR(glXMakeCurrent)
372 LOAD_FUNCPTR(glXSwapBuffers)
373 LOAD_FUNCPTR(glXQueryExtension)
374 LOAD_FUNCPTR(glXQueryVersion)
375 LOAD_FUNCPTR(glXUseXFont)
378 LOAD_FUNCPTR(glXGetClientString)
379 LOAD_FUNCPTR(glXQueryExtensionsString)
380 LOAD_FUNCPTR(glXQueryServerString)
383 LOAD_FUNCPTR(glXCreatePbuffer)
384 LOAD_FUNCPTR(glXDestroyPbuffer)
385 LOAD_FUNCPTR(glXMakeContextCurrent)
386 LOAD_FUNCPTR(glXGetCurrentReadDrawable)
387 LOAD_FUNCPTR(glXGetFBConfigs)
389 /* Standard OpenGL calls */
390 LOAD_FUNCPTR(glBindTexture)
391 LOAD_FUNCPTR(glBitmap)
392 LOAD_FUNCPTR(glCopyTexSubImage1D)
393 LOAD_FUNCPTR(glCopyTexSubImage2D)
394 LOAD_FUNCPTR(glDisable)
395 LOAD_FUNCPTR(glDrawBuffer)
396 LOAD_FUNCPTR(glEnable)
397 LOAD_FUNCPTR(glEndList)
398 LOAD_FUNCPTR(glGetError)
399 LOAD_FUNCPTR(glGetIntegerv)
400 LOAD_FUNCPTR(glGetString)
401 LOAD_FUNCPTR(glIsEnabled)
402 LOAD_FUNCPTR(glNewList)
403 LOAD_FUNCPTR(glPixelStorei)
404 LOAD_FUNCPTR(glScissor)
405 LOAD_FUNCPTR(glViewport)
408 /* It doesn't matter if these fail. They'll only be used if the driver reports
409 the associated extension is available (and if a driver reports the extension
410 is available but fails to provide the functions, it's quite broken) */
411 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f);
412 /* NV GLX Extension */
413 LOAD_FUNCPTR(glXAllocateMemoryNV)
414 LOAD_FUNCPTR(glXFreeMemoryNV)
417 if(!X11DRV_WineGL_InitOpenglInfo()) {
418 wine_dlclose(opengl_handle, NULL, 0);
419 opengl_handle = NULL;
424 if (pglXQueryExtension(gdi_display, &error_base, &event_base) == True) {
425 TRACE("GLX is up and running error_base = %d\n", error_base);
427 wine_dlclose(opengl_handle, NULL, 0);
428 opengl_handle = NULL;
431 /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
432 * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
435 * The main problem for our OpenGL code is that we need certain GLX calls but their presence
436 * depends on the reported GLX client / server version and on the client / server extension list.
437 * Those don't have to be the same.
439 * In general the server GLX information should be used in case of indirect rendering. When direct
440 * rendering is used, the OpenGL client library is responsible for which GLX calls are available.
441 * Nvidia's OpenGL drivers are the best in terms of GLX features. At the moment of writing their
442 * 8762 drivers support 1.3 for the server and 1.4 for the client and they support lots of extensions.
443 * Unfortunately it is much more complicated for Mesa/DRI-based drivers and ATI's drivers.
444 * Both sets of drivers report a server version of 1.2 and the client version can be 1.3 or 1.4.
445 * Further, in case of at least ATI's drivers, one crucial extension needed for our pixel format code
446 * is only available in the list of server extensions and not in the client list.
448 * The versioning checks below try to take into account the comments from above.
451 /* Depending on the use of direct or indirect rendering we need either the list of extensions
452 * exported by the client or by the server.
454 if(WineGLInfo.glxDirect)
455 glx_extensions = WineGLInfo.glxClientExtensions;
457 glx_extensions = WineGLInfo.glxServerExtensions;
459 /* Based on the default opengl context we decide whether direct or indirect rendering is used.
460 * In case of indirect rendering we check if the GLX version of the server is 1.2 and else
461 * the client version is checked.
463 if ((!WineGLInfo.glxDirect && !strcmp("1.2", WineGLInfo.glxServerVersion)) ||
464 (WineGLInfo.glxDirect && !strcmp("1.2", WineGLInfo.glxClientVersion)))
466 if (NULL != strstr(glx_extensions, "GLX_SGIX_fbconfig")) {
467 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
468 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
469 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
471 ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxClientVersion);
474 pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
475 pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
476 pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
479 /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
480 * enable this function when the Xserver understand GLX 1.3 or newer
482 if (!strcmp("1.2", WineGLInfo.glxServerVersion))
483 pglXQueryDrawable = NULL;
485 pglXQueryDrawable = wine_dlsym(RTLD_DEFAULT, "glXQueryDrawable", NULL, 0);
487 if (NULL != strstr(glx_extensions, "GLX_ATI_render_texture")) {
488 pglXBindTexImageARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageARB");
489 pglXReleaseTexImageARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageARB");
490 pglXDrawableAttribARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribARB");
493 X11DRV_WineGL_LoadExtensions();
496 return (opengl_handle != NULL);
499 wine_dlclose(opengl_handle, NULL, 0);
500 opengl_handle = NULL;
504 static inline Wine_GLContext *alloc_context(void)
508 if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLContext))))
510 ret->next = context_list;
511 if (context_list) context_list->prev = ret;
517 static inline void free_context(Wine_GLContext *context)
519 if (context->next != NULL) context->next->prev = context->prev;
520 if (context->prev != NULL) context->prev->next = context->next;
521 else context_list = context->next;
523 HeapFree(GetProcessHeap(), 0, context);
526 static inline Wine_GLContext *get_context_from_GLXContext(GLXContext ctx)
529 if (!ctx) return NULL;
530 for (ret = context_list; ret; ret = ret->next) if (ctx == ret->ctx) break;
535 * get_hdc_from_Drawable (internal)
537 * For use by wglGetCurrentReadDCARB.
539 static inline HDC get_hdc_from_Drawable(GLXDrawable d)
542 for (ret = context_list; ret; ret = ret->next) {
543 if (d == ret->physDev->drawable) {
550 static inline BOOL is_valid_context( Wine_GLContext *ctx )
553 for (ptr = context_list; ptr; ptr = ptr->next) if (ptr == ctx) break;
554 return (ptr != NULL);
557 static int describeContext(Wine_GLContext* ctx) {
560 TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
561 pglXGetFBConfigAttrib(gdi_display, ctx->fb_conf, GLX_FBCONFIG_ID, &tmp);
562 TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
563 pglXGetFBConfigAttrib(gdi_display, ctx->fb_conf, GLX_VISUAL_ID, &tmp);
564 TRACE(" - VISUAL_ID 0x%x\n", tmp);
569 static int describeDrawable(Wine_GLContext* ctx, Drawable drawable) {
572 int attribList[3] = { GLX_FBCONFIG_ID, 0, None };
575 if (pglXQueryDrawable == NULL) {
576 /** glXQueryDrawable not available so returns not supported */
580 TRACE(" Drawable %p have :\n", (void*) drawable);
581 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &tmp);
582 TRACE(" - WIDTH as %d\n", tmp);
583 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &tmp);
584 TRACE(" - HEIGHT as %d\n", tmp);
585 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &tmp);
586 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
589 fbCfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribList, &nElements);
590 if (fbCfgs == NULL) {
594 pglXGetFBConfigAttrib(gdi_display, fbCfgs[0], GLX_VISUAL_ID, &tmp);
595 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
602 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
608 int wantColorBits = 0;
611 /* The list of WGL attributes is allowed to be NULL, so don't return -1 (error) but just 0 */
615 while (0 != iWGLAttr[cur]) {
616 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
618 switch (iWGLAttr[cur]) {
619 case WGL_COLOR_BITS_ARB:
620 pop = iWGLAttr[++cur];
621 wantColorBits = pop; /** see end */
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];
641 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
642 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
644 case WGL_DEPTH_BITS_ARB:
645 pop = iWGLAttr[++cur];
646 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
647 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
649 case WGL_STENCIL_BITS_ARB:
650 pop = iWGLAttr[++cur];
651 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
652 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
654 case WGL_DOUBLE_BUFFER_ARB:
655 pop = iWGLAttr[++cur];
656 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
657 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
660 case WGL_PIXEL_TYPE_ARB:
661 pop = iWGLAttr[++cur];
663 case WGL_TYPE_COLORINDEX_ARB: pop = GLX_COLOR_INDEX_BIT; isColor = 1; break ;
664 case WGL_TYPE_RGBA_ARB: pop = GLX_RGBA_BIT; break ;
665 case WGL_TYPE_RGBA_FLOAT_ATI: pop = GLX_RGBA_FLOAT_ATI_BIT; break ;
667 ERR("unexpected PixelType(%x)\n", pop);
670 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pop);
671 TRACE("pAttr[%d] = GLX_RENDER_TYPE: %d\n", cur, pop);
674 case WGL_SUPPORT_GDI_ARB:
675 pop = iWGLAttr[++cur];
676 /* We only support a limited number of formats which are all renderable by X (similar to GDI).
677 * Ignore this attribute to prevent us from not finding a match due to the limited
678 * amount of formats supported right now. This option could be matched to GLX_X_RENDERABLE
679 * but the issue is that when a program asks for no GDI support, there's no format we can return
680 * as all our supported formats are renderable by X.
682 TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
685 case WGL_DRAW_TO_BITMAP_ARB:
686 pop = iWGLAttr[++cur];
687 TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
688 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
690 drawattrib |= GLX_PIXMAP_BIT;
694 case WGL_DRAW_TO_WINDOW_ARB:
695 pop = iWGLAttr[++cur];
696 TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
697 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
699 drawattrib |= GLX_WINDOW_BIT;
703 case WGL_DRAW_TO_PBUFFER_ARB:
704 pop = iWGLAttr[++cur];
705 TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
706 /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
708 drawattrib |= GLX_PBUFFER_BIT;
712 case WGL_ACCELERATION_ARB:
713 case WGL_SUPPORT_OPENGL_ARB:
714 pop = iWGLAttr[++cur];
715 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
716 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
719 case WGL_PBUFFER_LARGEST_ARB:
720 pop = iWGLAttr[++cur];
721 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
722 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
725 case WGL_SAMPLE_BUFFERS_ARB:
726 pop = iWGLAttr[++cur];
727 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
728 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
731 case WGL_SAMPLES_ARB:
732 pop = iWGLAttr[++cur];
733 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
734 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
737 case WGL_TEXTURE_FORMAT_ARB:
738 case WGL_TEXTURE_TARGET_ARB:
739 case WGL_MIPMAP_TEXTURE_ARB:
740 TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
741 pop = iWGLAttr[++cur];
743 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
745 if (use_render_texture_ati) {
746 /** nothing to do here */
748 else if (!use_render_texture_emulation) {
749 if (WGL_NO_TEXTURE_ARB != pop) {
750 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
751 return -1; /** error: don't support it */
753 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
754 drawattrib |= GLX_PBUFFER_BIT;
759 case WGL_BIND_TO_TEXTURE_RGB_ARB:
760 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
761 pop = iWGLAttr[++cur];
762 /** cannot be converted, see direct handling on
763 * - wglGetPixelFormatAttribivARB
764 * TODO: wglChoosePixelFormat
769 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
776 * Trick as WGL_COLOR_BITS_ARB != GLX_BUFFER_SIZE
777 * WGL_COLOR_BITS_ARB + WGL_ALPHA_BITS_ARB == GLX_BUFFER_SIZE
780 * The number of color bitplanes in each color buffer. For RGBA
781 * pixel types, it is the size of the color buffer, excluding the
782 * alpha bitplanes. For color-index pixels, it is the size of the
783 * color index buffer.
786 * This attribute defines the number of bits per color buffer.
787 * For GLX FBConfigs that correspond to a PseudoColor or StaticColor visual,
788 * this is equal to the depth value reported in the X11 visual.
789 * For GLX FBConfigs that correspond to TrueColor or DirectColor visual,
790 * this is the sum of GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_BLUE_SIZE, and GLX_ALPHA_SIZE.
793 if (0 < wantColorBits) {
795 wantColorBits += sz_alpha;
797 if (32 < wantColorBits) {
798 ERR("buggy %d GLX_BUFFER_SIZE default to 32\n", wantColorBits);
801 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, wantColorBits);
802 TRACE("pAttr[%d] = WGL_COLOR_BITS_ARB: %d\n", cur, wantColorBits);
805 /* Apply the OR'd drawable type bitmask now. */
807 PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
808 TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
814 static BOOL get_fbconfig_from_visualid(Display *display, Visual *visual, int *fmt_id, int *fmt_index)
816 GLXFBConfig* cfgs = NULL;
823 if(!display || !visual) {
824 ERR("Invalid display or visual\n");
827 visualid = XVisualIDFromVisual(visual);
829 /* Get a list of all available framebuffer configurations */
830 cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
831 if (NULL == cfgs || 0 == nCfgs) {
832 ERR("glXChooseFBConfig returns NULL\n");
833 if(cfgs != NULL) XFree(cfgs);
837 /* Find the requested offscreen format and count the number of offscreen formats */
838 for(i=0; i<nCfgs; i++) {
839 pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id);
840 pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id);
842 /* We are looking up the GLX index of our main visual and have found it :) */
843 if(visualid == tmp_vis_id) {
844 TRACE("Found FBCONFIG_ID 0x%x at index %d for VISUAL_ID 0x%x\n", tmp_fmt_id, i, tmp_vis_id);
846 *fmt_id = tmp_fmt_id;
852 ERR("No fbconfig found for Wine's main visual (0x%lx), expect problems!\n", visualid);
857 static BOOL init_formats(Display *display, int screen, Visual *visual)
859 int fmt_id, fmt_index;
861 /* Locate the fbconfig correspondig to our main visual */
862 if(!get_fbconfig_from_visualid(display, visual, &fmt_id, &fmt_index)) {
863 ERR("Can't get the FBCONFIG_ID for the main visual, expect problems!\n");
867 /* Put Wine's internal format at the first index */
868 WineGLPixelFormatList[0].iPixelFormat = 1;
869 WineGLPixelFormatList[0].fbconfig = fmt_id;
870 WineGLPixelFormatList[0].fmt_index = fmt_index;
871 WineGLPixelFormatListSize = 1;
873 /* In the future test for compatible formats here */
878 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
879 * In our WGL implementation we only support a subset of these formats namely the format of
880 * Wine's main visual and offscreen formats (if they are available).
881 * This function converts a WGL format to its corresponding GLX one. It returns the index (zero-based)
882 * into the GLX FB config table and it returns the number of supported WGL formats in fmt_count.
884 static BOOL ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, int *fmt_index, int *fmt_count)
888 /* Init the list of pixel formats when we need it */
889 if(!WineGLPixelFormatListSize)
890 init_formats(display, DefaultScreen(display), visual);
892 if((iPixelFormat <= 0) || (iPixelFormat > WineGLPixelFormatListSize)) {
893 ERR("invalid iPixelFormat %d\n", iPixelFormat);
899 *fmt_index = WineGLPixelFormatList[iPixelFormat-1].fmt_index;
902 *fmt_count = WineGLPixelFormatListSize;
903 TRACE("Returning fmt_index=%d, fmt_count=%d for iPixelFormat=%d\n", *fmt_index, *fmt_count, iPixelFormat);
908 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
909 static int ConvertPixelFormatGLXtoWGL(Display *display, int fbconfig)
913 /* Init the list of pixel formats when we need it */
914 if(!WineGLPixelFormatListSize)
915 init_formats(display, DefaultScreen(display), visual);
917 for(i=0; i<WineGLPixelFormatListSize; i++) {
918 if(WineGLPixelFormatList[i].fbconfig == fbconfig) {
919 TRACE("Returning iPixelFormat %d for fbconfig 0x%x\n", WineGLPixelFormatList[i].iPixelFormat, fbconfig);
920 return WineGLPixelFormatList[i].iPixelFormat;
923 TRACE("No compatible format found for FBCONFIG_ID=0x%x\n", fbconfig);
928 * X11DRV_ChoosePixelFormat
930 * Equivalent to glXChooseVisual.
932 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
933 const PIXELFORMATDESCRIPTOR *ppfd) {
934 GLXFBConfig* cfgs = NULL;
941 ERR("No libGL on this box - disabling OpenGL support !\n");
945 if (TRACE_ON(opengl)) {
946 TRACE("(%p,%p)\n", physDev, ppfd);
948 dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR *) ppfd);
953 ERR("Can't get an opengl visual!\n");
957 /* Get a list containing all supported FB configurations */
958 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
959 if (NULL == cfgs || 0 == nCfgs) {
960 ERR("glXGetFBConfigs returns NULL (glError: %d)\n", pglGetError());
964 /* In case an fbconfig was found, check if it matches to the requirements of the ppfd */
965 if(!ConvertPixelFormatWGLtoGLX(gdi_display, 1 /* main visual */, &fmt_index, &value)) {
966 ERR("Can't find a matching FBCONFIG_ID for VISUAL_ID 0x%lx!\n", visual->visualid);
973 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_RENDER_TYPE, &value);
974 if (value & GLX_RGBA_BIT)
975 iPixelType = PFD_TYPE_RGBA;
977 iPixelType = PFD_TYPE_COLORINDEX;
979 if (ppfd->iPixelType != iPixelType) {
980 TRACE("pixel type mismatch\n");
985 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_DOUBLEBUFFER, &value); if (value) dwFlags |= PFD_DOUBLEBUFFER;
986 if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) && (ppfd->dwFlags & PFD_DOUBLEBUFFER)) {
987 if (!(dwFlags & PFD_DOUBLEBUFFER)) {
988 TRACE("dbl buffer mismatch\n");
994 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_STEREO, &value); if (value) dwFlags |= PFD_STEREO;
995 if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE) && (ppfd->dwFlags & PFD_STEREO)) {
996 if (!(dwFlags & PFD_STEREO)) {
997 TRACE("stereo mismatch\n");
1003 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_ALPHA_SIZE, &value);
1004 if (ppfd->iPixelType==PFD_TYPE_RGBA && ppfd->cAlphaBits && !value) {
1005 TRACE("alpha mismatch\n");
1010 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_DEPTH_SIZE, &value);
1011 if (ppfd->cDepthBits && !value) {
1012 TRACE("depth mismatch\n");
1017 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_STENCIL_SIZE, &value);
1018 if (ppfd->cStencilBits && !value) {
1019 TRACE("stencil mismatch\n");
1024 pglXGetFBConfigAttrib(gdi_display, cfgs[fmt_index], GLX_AUX_BUFFERS, &value);
1025 if (ppfd->cAuxBuffers && !value) {
1026 TRACE("aux mismatch\n");
1030 /* When we pass all the checks we have found a matching format :) */
1032 TRACE("Successfully found a matching mode, returning index: %d\n", ret);
1037 TRACE("No matching mode was found returning 0\n");
1039 if (NULL != cfgs) XFree(cfgs);
1040 wine_tsx11_unlock();
1045 * X11DRV_DescribePixelFormat
1047 * Get the pixel-format descriptor associated to the given id
1049 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
1052 PIXELFORMATDESCRIPTOR *ppfd) {
1053 /*XVisualInfo *vis;*/
1057 GLXFBConfig* cfgs = NULL;
1065 if (!has_opengl()) {
1066 ERR("No libGL on this box - disabling OpenGL support !\n");
1070 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
1073 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
1074 wine_tsx11_unlock();
1076 if (NULL == cfgs || 0 == nCfgs) {
1077 ERR("unexpected iPixelFormat(%d), returns NULL\n", iPixelFormat);
1078 return 0; /* unespected error */
1081 /* 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 */
1082 res = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &fmt_count);
1085 /* The application is only querying the number of visuals */
1087 if (NULL != cfgs) XFree(cfgs);
1088 wine_tsx11_unlock();
1090 } else if(res == FALSE) {
1091 WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1093 if (NULL != cfgs) XFree(cfgs);
1094 wine_tsx11_unlock();
1098 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1099 ERR("Wrong structure size !\n");
1100 /* Should set error */
1105 cur = cfgs[fmt_index];
1107 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1108 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1111 /* These flags are always the same... */
1112 ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
1113 /* Now the flags extracted from the Visual */
1117 pglXGetFBConfigAttrib(gdi_display, cur, GLX_CONFIG_CAVEAT, &value);
1118 if(value == GLX_SLOW_CONFIG)
1119 ppfd->dwFlags |= PFD_GENERIC_ACCELERATED;
1121 pglXGetFBConfigAttrib(gdi_display, cur, GLX_DOUBLEBUFFER, &value); if (value) ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1122 pglXGetFBConfigAttrib(gdi_display, cur, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1125 pglXGetFBConfigAttrib(gdi_display, cur, GLX_RENDER_TYPE, &value);
1126 if (value & GLX_RGBA_BIT)
1127 ppfd->iPixelType = PFD_TYPE_RGBA;
1129 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1132 pglXGetFBConfigAttrib(gdi_display, cur, GLX_BUFFER_SIZE, &value);
1133 ppfd->cColorBits = value;
1135 /* Red, green, blue and alpha bits / shifts */
1136 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1137 pglXGetFBConfigAttrib(gdi_display, cur, GLX_RED_SIZE, &rb);
1138 pglXGetFBConfigAttrib(gdi_display, cur, GLX_GREEN_SIZE, &gb);
1139 pglXGetFBConfigAttrib(gdi_display, cur, GLX_BLUE_SIZE, &bb);
1140 pglXGetFBConfigAttrib(gdi_display, cur, GLX_ALPHA_SIZE, &ab);
1142 ppfd->cRedBits = rb;
1143 ppfd->cRedShift = gb + bb + ab;
1144 ppfd->cBlueBits = bb;
1145 ppfd->cBlueShift = ab;
1146 ppfd->cGreenBits = gb;
1147 ppfd->cGreenShift = bb + ab;
1148 ppfd->cAlphaBits = ab;
1149 ppfd->cAlphaShift = 0;
1152 ppfd->cRedShift = 0;
1153 ppfd->cBlueBits = 0;
1154 ppfd->cBlueShift = 0;
1155 ppfd->cGreenBits = 0;
1156 ppfd->cGreenShift = 0;
1157 ppfd->cAlphaBits = 0;
1158 ppfd->cAlphaShift = 0;
1160 /* Accums : to do ... */
1163 pglXGetFBConfigAttrib(gdi_display, cur, GLX_DEPTH_SIZE, &value);
1164 ppfd->cDepthBits = value;
1167 pglXGetFBConfigAttrib(gdi_display, cur, GLX_STENCIL_SIZE, &value);
1168 ppfd->cStencilBits = value;
1170 wine_tsx11_unlock();
1172 /* Aux : to do ... */
1174 ppfd->iLayerType = PFD_MAIN_PLANE;
1176 if (TRACE_ON(opengl)) {
1177 dump_PIXELFORMATDESCRIPTOR(ppfd);
1181 if (NULL != cfgs) XFree(cfgs);
1182 wine_tsx11_unlock();
1188 * X11DRV_GetPixelFormat
1190 * Get the pixel-format id used by this DC
1192 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
1193 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1195 return physDev->current_pf;
1199 * X11DRV_SetPixelFormat
1201 * Set the pixel-format id used by this DC
1203 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
1205 const PIXELFORMATDESCRIPTOR *ppfd) {
1209 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1211 if (!has_opengl()) {
1212 ERR("No libGL on this box - disabling OpenGL support !\n");
1216 /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1217 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &value)) {
1218 ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1222 physDev->current_pf = iPixelFormat;
1224 if (TRACE_ON(opengl)) {
1226 GLXFBConfig* cfgs_fmt = NULL;
1227 GLXFBConfig cur_cfg;
1231 * How to test if hdc current drawable is compatible (visual/FBConfig) ?
1233 * in case of root window created HDCs we crash here :(
1235 Drawable drawable = get_drawable( physDev->hdc );
1236 TRACE(" drawable (%p,%p) have :\n", drawable, root_window);
1237 pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &value);
1238 TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
1239 pglXQueryDrawable(gdi_display, drawable, GLX_VISUAL_ID, (unsigned int*) &value);
1240 TRACE(" - VISUAL_ID as 0x%x\n", tmp);
1241 pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &value);
1242 TRACE(" - WIDTH as %d\n", tmp);
1243 pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &value);
1244 TRACE(" - HEIGHT as %d\n", tmp);
1246 cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
1247 cur_cfg = cfgs_fmt[fmt_index];
1248 gl_test = pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_FBCONFIG_ID, &value);
1250 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1252 TRACE(" FBConfig have :\n");
1253 TRACE(" - FBCONFIG_ID 0x%x\n", value);
1254 pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_VISUAL_ID, &value);
1255 TRACE(" - VISUAL_ID 0x%x\n", value);
1256 pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_DRAWABLE_TYPE, &value);
1257 TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1265 * X11DRV_wglCreateContext
1267 * For OpenGL32 wglCreateContext.
1269 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
1271 Wine_GLContext *ret;
1272 GLXFBConfig* cfgs_fmt = NULL;
1273 GLXFBConfig cur_cfg;
1274 int hdcPF = physDev->current_pf;
1280 HDC hdc = physDev->hdc;
1282 TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1284 if (!has_opengl()) {
1285 ERR("No libGL on this box - disabling OpenGL support !\n");
1289 /* First, get the visual in use by the X11DRV */
1290 if (!gdi_display) return 0;
1292 /* We can only render using the iPixelFormat (1) of Wine's Main visual, we need to get the corresponding GLX format.
1293 * If this fails something is very wrong on the system. */
1294 if(!ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, &fmt_index, &fmt_count)) {
1295 ERR("Cannot get FB Config for main iPixelFormat 1, expect problems!\n");
1296 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1300 cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
1301 if (NULL == cfgs_fmt || 0 == nCfgs_fmt) {
1302 ERR("Cannot get FB Configs, expect problems.\n");
1303 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1307 if (fmt_count < hdcPF) {
1308 ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, hdcPF, fmt_count);
1309 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1313 cur_cfg = cfgs_fmt[fmt_index];
1314 gl_test = pglXGetFBConfigAttrib(gdi_display, cur_cfg, GLX_FBCONFIG_ID, &value);
1316 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1317 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1322 /* The context will be allocated in the wglMakeCurrent call */
1324 ret = alloc_context();
1325 wine_tsx11_unlock();
1327 ret->physDev = physDev;
1328 ret->fb_conf = cur_cfg;
1330 ret->vis = pglXGetVisualFromFBConfig(gdi_display, cur_cfg);
1332 TRACE(" creating context %p (GL context creation delayed)\n", ret);
1337 * X11DRV_wglDeleteContext
1339 * For OpenGL32 wglDeleteContext.
1341 BOOL X11DRV_wglDeleteContext(HGLRC hglrc)
1343 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1346 TRACE("(%p)\n", hglrc);
1348 if (!has_opengl()) {
1349 ERR("No libGL on this box - disabling OpenGL support !\n");
1354 /* A game (Half Life not to name it) deletes twice the same context,
1355 * so make sure it is valid first */
1356 if (is_valid_context( ctx ))
1358 if (ctx->ctx) pglXDestroyContext(gdi_display, ctx->ctx);
1363 WARN("Error deleting context !\n");
1364 SetLastError(ERROR_INVALID_HANDLE);
1367 wine_tsx11_unlock();
1373 * X11DRV_wglGetCurrentReadDCARB
1375 * For OpenGL32 wglGetCurrentReadDCARB.
1377 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void)
1385 gl_d = pglXGetCurrentReadDrawable();
1386 ret = get_hdc_from_Drawable(gl_d);
1387 wine_tsx11_unlock();
1389 TRACE(" returning %p (GL drawable %lu)\n", ret, gl_d);
1394 * X11DRV_wglGetProcAddress
1396 * For OpenGL32 wglGetProcAddress.
1398 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1401 const WineGLExtension *ext;
1403 int padding = 32 - strlen(lpszProc);
1407 if (!has_opengl()) {
1408 ERR("No libGL on this box - disabling OpenGL support !\n");
1412 /* Check the table of WGL extensions to see if we need to return a WGL extension
1413 * or a function pointer to a native OpenGL function. */
1414 if(strncmp(lpszProc, "wgl", 3) != 0) {
1415 return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1417 TRACE("('%s'):%*s", lpszProc, padding, " ");
1418 for (i = 0; i < WineGLExtensionListSize; ++i) {
1419 ext = WineGLExtensionList[i];
1420 for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1421 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1422 TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1423 return ext->extEntryPoints[j].funcAddress;
1429 ERR("(%s) - not found\n", lpszProc);
1433 /***********************************************************************
1434 * sync_current_drawable
1436 * Adjust the current viewport and scissor in order to position
1437 * and size the current drawable correctly on the parent window.
1439 static void sync_current_drawable(BOOL updatedc)
1445 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1449 if (ctx && ctx->physDev)
1452 GetClipBox(ctx->physDev->hdc, &rc); /* Make sure physDev is up to date */
1454 dy = ctx->physDev->drawable_rect.bottom - ctx->physDev->drawable_rect.top -
1455 ctx->physDev->dc_rect.bottom;
1456 width = ctx->physDev->dc_rect.right - ctx->physDev->dc_rect.left;
1457 height = ctx->physDev->dc_rect.bottom - ctx->physDev->dc_rect.top;
1461 pglViewport(ctx->physDev->dc_rect.left + ctx->viewport.left,
1462 dy + ctx->viewport.top,
1463 ctx->viewport.right ? (ctx->viewport.right - ctx->viewport.left) : width,
1464 ctx->viewport.bottom ? (ctx->viewport.bottom - ctx->viewport.top) : height);
1466 pglEnable(GL_SCISSOR_TEST);
1468 if (ctx->scissor_enabled)
1469 pglScissor(ctx->physDev->dc_rect.left + min(width, max(0, ctx->scissor.left)),
1470 dy + min(height, max(0, ctx->scissor.top)),
1471 min(width, max(0, ctx->scissor.right - ctx->scissor.left)),
1472 min(height, max(0, ctx->scissor.bottom - ctx->scissor.top)));
1474 pglScissor(ctx->physDev->dc_rect.left, dy, width, height);
1476 wine_tsx11_unlock();
1481 * X11DRV_wglMakeCurrent
1483 * For OpenGL32 wglMakeCurrent.
1485 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
1487 HDC hdc = physDev->hdc;
1488 DWORD type = GetObjectType(hdc);
1490 TRACE("(%p,%p)\n", hdc, hglrc);
1492 if (!has_opengl()) {
1493 ERR("No libGL on this box - disabling OpenGL support !\n");
1498 if (hglrc == NULL) {
1499 ret = pglXMakeCurrent(gdi_display, None, NULL);
1500 NtCurrentTeb()->glContext = NULL;
1502 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1503 Drawable drawable = get_glxdrawable(physDev);
1504 if (ctx->ctx == NULL) {
1505 /* The describe lines below are for debugging purposes only */
1506 if (TRACE_ON(wgl)) {
1507 describeDrawable(ctx, drawable);
1508 describeContext(ctx);
1511 /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1512 * We are certain that the drawable and context are compatible as we only allow compatible formats.
1514 TRACE(" Creating GLX Context\n");
1515 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, type == OBJ_MEMDC ? False : True);
1516 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1518 TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display, (void*) drawable, ctx->ctx);
1519 ret = pglXMakeCurrent(gdi_display, drawable, ctx->ctx);
1520 NtCurrentTeb()->glContext = ctx;
1523 ctx->physDev = physDev;
1525 if (type == OBJ_MEMDC)
1527 ctx->do_escape = TRUE;
1528 pglDrawBuffer(GL_FRONT_LEFT);
1532 sync_current_drawable(FALSE);
1536 wine_tsx11_unlock();
1537 TRACE(" returning %s\n", (ret ? "True" : "False"));
1542 * X11DRV_wglMakeContextCurrentARB
1544 * For OpenGL32 wglMakeContextCurrentARB
1546 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc)
1549 TRACE("(%p,%p,%p)\n", hDrawDev, hReadDev, hglrc);
1551 if (!has_opengl()) {
1552 ERR("No libGL on this box - disabling OpenGL support !\n");
1557 if (hglrc == NULL) {
1558 ret = pglXMakeCurrent(gdi_display, None, NULL);
1559 NtCurrentTeb()->glContext = NULL;
1561 if (NULL == pglXMakeContextCurrent) {
1564 Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1565 Drawable d_draw = get_glxdrawable(hDrawDev);
1566 Drawable d_read = get_glxdrawable(hReadDev);
1568 if (ctx->ctx == NULL) {
1569 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, GetObjectType(hDrawDev->hdc) == OBJ_MEMDC ? False : True);
1570 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1572 ret = pglXMakeContextCurrent(gdi_display, d_draw, d_read, ctx->ctx);
1573 NtCurrentTeb()->glContext = ctx;
1576 wine_tsx11_unlock();
1578 TRACE(" returning %s\n", (ret ? "True" : "False"));
1583 * X11DRV_wglShareLists
1585 * For OpenGL32 wglShaderLists.
1587 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
1588 Wine_GLContext *org = (Wine_GLContext *) hglrc1;
1589 Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1591 TRACE("(%p, %p)\n", org, dest);
1593 if (!has_opengl()) {
1594 ERR("No libGL on this box - disabling OpenGL support !\n");
1598 if (NULL != dest && dest->ctx != NULL) {
1599 ERR("Could not share display lists, context already created !\n");
1602 if (org->ctx == NULL) {
1604 describeContext(org);
1605 org->ctx = pglXCreateContext(gdi_display, org->vis, NULL, GetObjectType(org->physDev->hdc) == OBJ_MEMDC ? False : True);
1606 wine_tsx11_unlock();
1607 TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org->ctx, org);
1611 describeContext(dest);
1612 /* Create the destination context with display lists shared */
1613 dest->ctx = pglXCreateContext(gdi_display, dest->vis, org->ctx, GetObjectType(org->physDev->hdc) == OBJ_MEMDC ? False : True);
1614 wine_tsx11_unlock();
1615 TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1622 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
1624 /* We are running using client-side rendering fonts... */
1628 void *bitmap = NULL, *gl_bitmap = NULL;
1632 pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1633 pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1634 wine_tsx11_unlock();
1636 for (glyph = first; glyph < first + count; glyph++) {
1637 unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, NULL);
1638 int height, width_int;
1640 TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
1641 if (needed_size == GDI_ERROR) {
1642 TRACE(" - needed size : %d (GDI_ERROR)\n", needed_size);
1645 TRACE(" - needed size : %d\n", needed_size);
1648 if (needed_size > size) {
1650 HeapFree(GetProcessHeap(), 0, bitmap);
1651 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1652 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1653 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1655 if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, NULL) == GDI_ERROR) goto error;
1656 if (TRACE_ON(opengl)) {
1657 unsigned int height, width, bitmask;
1658 unsigned char *bitmap_ = (unsigned char *) bitmap;
1660 TRACE(" - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
1661 TRACE(" - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
1662 TRACE(" - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
1663 if (needed_size != 0) {
1664 TRACE(" - bitmap :\n");
1665 for (height = 0; height < gm.gmBlackBoxY; height++) {
1667 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
1672 if (*bitmap_ & bitmask)
1677 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
1683 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1684 * glyph for it to be drawn properly.
1686 if (needed_size != 0) {
1687 width_int = (gm.gmBlackBoxX + 31) / 32;
1688 for (height = 0; height < gm.gmBlackBoxY; height++) {
1690 for (width = 0; width < width_int; width++) {
1691 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
1692 ((int *) bitmap)[height * width_int + width];
1698 pglNewList(listBase++, GL_COMPILE);
1699 if (needed_size != 0) {
1700 pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
1701 0 - (int) gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - (int) gm.gmptGlyphOrigin.y,
1702 gm.gmCellIncX, gm.gmCellIncY,
1705 /* This is the case of 'empty' glyphs like the space character */
1706 pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
1709 wine_tsx11_unlock();
1713 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1714 wine_tsx11_unlock();
1716 HeapFree(GetProcessHeap(), 0, bitmap);
1717 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1722 pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1723 wine_tsx11_unlock();
1725 HeapFree(GetProcessHeap(), 0, bitmap);
1726 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1731 * X11DRV_wglUseFontBitmapsA
1733 * For OpenGL32 wglUseFontBitmapsA.
1735 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1737 Font fid = physDev->font;
1739 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1741 if (!has_opengl()) {
1742 ERR("No libGL on this box - disabling OpenGL support !\n");
1747 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineA);
1751 /* I assume that the glyphs are at the same position for X and for Windows */
1752 pglXUseXFont(fid, first, count, listBase);
1753 wine_tsx11_unlock();
1758 * X11DRV_wglUseFontBitmapsW
1760 * For OpenGL32 wglUseFontBitmapsW.
1762 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1764 Font fid = physDev->font;
1766 TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1768 if (!has_opengl()) {
1769 ERR("No libGL on this box - disabling OpenGL support !\n");
1774 return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineW);
1777 WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1780 /* I assume that the glyphs are at the same position for X and for Windows */
1781 pglXUseXFont(fid, first, count, listBase);
1782 wine_tsx11_unlock();
1786 static void WINAPI X11DRV_wglDisable(GLenum cap)
1788 if (cap == GL_SCISSOR_TEST)
1790 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1793 ctx->scissor_enabled = FALSE;
1799 wine_tsx11_unlock();
1803 static void WINAPI X11DRV_wglEnable(GLenum cap)
1805 if (cap == GL_SCISSOR_TEST)
1807 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1810 ctx->scissor_enabled = TRUE;
1816 wine_tsx11_unlock();
1820 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1821 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params)
1828 GLXContext gl_ctx = pglXGetCurrentContext();
1829 Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx);
1831 pglGetIntegerv(pname, params);
1833 * if we cannot find a Wine Context
1834 * we only have the default wine desktop context,
1835 * so if we have only a 24 depth say we have 32
1837 if (NULL == ret && 24 == *params) {
1840 TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
1845 GLXContext gl_ctx = pglXGetCurrentContext();
1846 Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx);
1848 pglXGetFBConfigAttrib(gdi_display, ret->fb_conf, GLX_ALPHA_SIZE, params);
1849 TRACE("returns GL_ALPHA_BITS as '%d'\n", *params);
1853 pglGetIntegerv(pname, params);
1856 wine_tsx11_unlock();
1859 static GLboolean WINAPI X11DRV_wglIsEnabled(GLenum cap)
1861 GLboolean enabled = False;
1863 if (cap == GL_SCISSOR_TEST)
1865 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1868 enabled = ctx->scissor_enabled;
1873 enabled = pglIsEnabled(cap);
1874 wine_tsx11_unlock();
1879 static void WINAPI X11DRV_wglScissor(GLint x, GLint y, GLsizei width, GLsizei height)
1881 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1885 ctx->scissor.left = x;
1886 ctx->scissor.top = y;
1887 ctx->scissor.right = x + width;
1888 ctx->scissor.bottom = y + height;
1890 sync_current_drawable(TRUE);
1894 static void WINAPI X11DRV_wglViewport(GLint x, GLint y, GLsizei width, GLsizei height)
1896 Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1900 ctx->viewport.left = x;
1901 ctx->viewport.top = y;
1902 ctx->viewport.right = x + width;
1903 ctx->viewport.bottom = y + height;
1905 sync_current_drawable(TRUE);
1910 * X11DRV_wglGetExtensionsStringARB
1912 * WGL_ARB_extensions_string: wglGetExtensionsStringARB
1914 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
1915 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
1916 return WineGLInfo.wglExtensions;
1920 * X11DRV_wglCreatePbufferARB
1922 * WGL_ARB_pbuffer: wglCreatePbufferARB
1924 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
1926 Wine_GLPBuffer* object = NULL;
1927 GLXFBConfig* cfgs = NULL;
1933 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
1935 if (0 >= iPixelFormat) {
1936 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
1937 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1938 return NULL; /* unexpected error */
1941 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
1943 if (NULL == cfgs || 0 == nCfgs) {
1944 ERR("(%p): Cannot get FB Configs for iPixelFormat(%d), returns NULL\n", hdc, iPixelFormat);
1945 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1946 return NULL; /* unexpected error */
1949 /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
1950 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &nCfgs)) {
1951 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
1952 SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1953 goto create_failed; /* unexpected error */
1956 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
1957 if (NULL == object) {
1958 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
1959 goto create_failed; /* unexpected error */
1962 object->display = gdi_display;
1963 object->width = iWidth;
1964 object->height = iHeight;
1965 object->pixelFormat = iPixelFormat;
1967 nAttribs = ConvertAttribWGLtoGLX(piAttribList, attribs, object);
1968 if (-1 == nAttribs) {
1969 WARN("Cannot convert WGL to GLX attributes\n");
1972 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
1973 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
1974 while (piAttribList && 0 != *piAttribList) {
1976 switch (*piAttribList) {
1977 case WGL_TEXTURE_FORMAT_ARB: {
1979 attr_v = *piAttribList;
1980 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
1981 if (use_render_texture_ati) {
1984 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
1985 case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
1986 case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
1988 SetLastError(ERROR_INVALID_DATA);
1991 object->use_render_texture = 1;
1992 PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
1994 if (WGL_NO_TEXTURE_ARB == attr_v) {
1995 object->use_render_texture = 0;
1997 if (!use_render_texture_emulation) {
1998 SetLastError(ERROR_INVALID_DATA);
2002 case WGL_TEXTURE_RGB_ARB:
2003 object->use_render_texture = GL_RGB;
2005 case WGL_TEXTURE_RGBA_ARB:
2006 object->use_render_texture = GL_RGBA;
2009 SetLastError(ERROR_INVALID_DATA);
2017 case WGL_TEXTURE_TARGET_ARB: {
2019 attr_v = *piAttribList;
2020 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2021 if (use_render_texture_ati) {
2024 case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2025 case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
2026 case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
2027 case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
2029 SetLastError(ERROR_INVALID_DATA);
2032 PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
2034 if (WGL_NO_TEXTURE_ARB == attr_v) {
2035 object->texture_target = 0;
2037 if (!use_render_texture_emulation) {
2038 SetLastError(ERROR_INVALID_DATA);
2042 case WGL_TEXTURE_CUBE_MAP_ARB: {
2043 if (iWidth != iHeight) {
2044 SetLastError(ERROR_INVALID_DATA);
2047 object->texture_target = GL_TEXTURE_CUBE_MAP;
2048 object->texture_bind_target = GL_TEXTURE_CUBE_MAP;
2051 case WGL_TEXTURE_1D_ARB: {
2053 SetLastError(ERROR_INVALID_DATA);
2056 object->texture_target = GL_TEXTURE_1D;
2057 object->texture_bind_target = GL_TEXTURE_1D;
2060 case WGL_TEXTURE_2D_ARB: {
2061 object->texture_target = GL_TEXTURE_2D;
2062 object->texture_bind_target = GL_TEXTURE_2D;
2066 SetLastError(ERROR_INVALID_DATA);
2074 case WGL_MIPMAP_TEXTURE_ARB: {
2076 attr_v = *piAttribList;
2077 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2078 if (use_render_texture_ati) {
2079 PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
2081 if (!use_render_texture_emulation) {
2082 SetLastError(ERROR_INVALID_DATA);
2092 PUSH1(attribs, None);
2093 object->drawable = pglXCreatePbuffer(gdi_display, cfgs[fmt_index], attribs);
2094 TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
2095 if (!object->drawable) {
2096 SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2097 goto create_failed; /* unexpected error */
2099 TRACE("->(%p)\n", object);
2103 return (HPBUFFERARB) object;
2106 if (NULL != cfgs) XFree(cfgs);
2107 HeapFree(GetProcessHeap(), 0, object);
2108 TRACE("->(FAILED)\n");
2109 return (HPBUFFERARB) NULL;
2113 * X11DRV_wglDestroyPbufferARB
2115 * WGL_ARB_pbuffer: wglDestroyPbufferARB
2117 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2119 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2120 TRACE("(%p)\n", hPbuffer);
2121 if (NULL == object) {
2122 SetLastError(ERROR_INVALID_HANDLE);
2125 pglXDestroyPbuffer(object->display, object->drawable);
2126 HeapFree(GetProcessHeap(), 0, object);
2131 * X11DRV_wglGetPbufferDCARB
2133 * WGL_ARB_pbuffer: wglGetPbufferDCARB
2134 * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2135 * Gdi32 implements the part of this function which creates a device context.
2136 * This part associates the physDev with the X drawable of the pbuffer.
2138 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
2140 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2141 if (NULL == object) {
2142 SetLastError(ERROR_INVALID_HANDLE);
2146 /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2147 * All formats in our pixelformat list are compatible with each other and the main drawable. */
2148 physDev->current_pf = object->pixelFormat;
2149 physDev->drawable = object->drawable;
2151 TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);
2152 return physDev->hdc;
2156 * X11DRV_wglQueryPbufferARB
2158 * WGL_ARB_pbuffer: wglQueryPbufferARB
2160 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2162 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2163 TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2164 if (NULL == object) {
2165 SetLastError(ERROR_INVALID_HANDLE);
2168 switch (iAttribute) {
2169 case WGL_PBUFFER_WIDTH_ARB:
2170 pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2172 case WGL_PBUFFER_HEIGHT_ARB:
2173 pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2176 case WGL_PBUFFER_LOST_ARB:
2177 FIXME("unsupported WGL_PBUFFER_LOST_ARB (need glXSelectEvent/GLX_DAMAGED work)\n");
2180 case WGL_TEXTURE_FORMAT_ARB:
2181 if (use_render_texture_ati) {
2183 int type = WGL_NO_TEXTURE_ARB;
2184 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2186 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2187 case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2188 case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2192 if (!object->use_render_texture) {
2193 *piValue = WGL_NO_TEXTURE_ARB;
2195 if (!use_render_texture_emulation) {
2196 SetLastError(ERROR_INVALID_HANDLE);
2199 if (GL_RGBA == object->use_render_texture) {
2200 *piValue = WGL_TEXTURE_RGBA_ARB;
2202 *piValue = WGL_TEXTURE_RGB_ARB;
2208 case WGL_TEXTURE_TARGET_ARB:
2209 if (use_render_texture_ati) {
2211 int type = WGL_NO_TEXTURE_ARB;
2212 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2214 case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2215 case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2216 case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2217 case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2221 if (!object->texture_target) {
2222 *piValue = WGL_NO_TEXTURE_ARB;
2224 if (!use_render_texture_emulation) {
2225 SetLastError(ERROR_INVALID_DATA);
2228 switch (object->texture_target) {
2229 case GL_TEXTURE_1D: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2230 case GL_TEXTURE_2D: *piValue = WGL_TEXTURE_1D_ARB; break;
2231 case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_2D_ARB; break;
2237 case WGL_MIPMAP_TEXTURE_ARB:
2238 if (use_render_texture_ati) {
2239 pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2241 *piValue = GL_FALSE; /** don't support that */
2242 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2247 FIXME("unexpected attribute %x\n", iAttribute);
2255 * X11DRV_wglReleasePbufferDCARB
2257 * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2259 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2261 TRACE("(%p, %p)\n", hPbuffer, hdc);
2267 * X11DRV_wglSetPbufferAttribARB
2269 * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2271 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2273 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2274 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2275 if (NULL == object) {
2276 SetLastError(ERROR_INVALID_HANDLE);
2279 if (!object->use_render_texture) {
2280 SetLastError(ERROR_INVALID_HANDLE);
2283 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2286 if (NULL != pglXDrawableAttribARB) {
2287 if (use_render_texture_ati) {
2288 FIXME("Need conversion for GLX_ATI_render_texture\n");
2290 return pglXDrawableAttribARB(object->display, object->drawable, piAttribList);
2296 * X11DRV_wglChoosePixelFormatARB
2298 * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2300 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2305 GLXFBConfig* cfgs = NULL;
2310 GLXFBConfig* cfgs_fmt = NULL;
2316 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2317 if (NULL != pfAttribFList) {
2318 FIXME("unused pfAttribFList\n");
2321 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2322 if (-1 == nAttribs) {
2323 WARN("Cannot convert WGL to GLX attributes\n");
2326 PUSH1(attribs, None);
2328 /* Search for FB configurations matching the requirements in attribs */
2329 cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2331 WARN("Compatible Pixel Format not found\n");
2335 /* Get a list of all FB configurations */
2336 cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
2337 if (NULL == cfgs_fmt) {
2338 ERR("Failed to get All FB Configs\n");
2343 /* Loop through all matching formats and check if they are suitable.
2344 * Note that this function should at max return nMaxFormats different formats */
2345 for (it = 0; pfmt_it < nMaxFormats && it < nCfgs; ++it) {
2346 gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2348 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2352 /* Search for the format in our list of compatible formats */
2353 fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id);
2357 piFormats[pfmt_it] = fmt;
2358 TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d/%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it], nCfgs_fmt);
2362 *nNumFormats = pfmt_it;
2370 * X11DRV_wglGetPixelFormatAttribivARB
2372 * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2374 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2377 GLXFBConfig* cfgs = NULL;
2378 GLXFBConfig curCfg = NULL;
2383 int nWGLFormats = 0;
2386 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2388 if (0 < iLayerPlane) {
2389 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2393 cfgs = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs);
2395 ERR("no FB Configs found for display(%p)\n", gdi_display);
2399 /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2400 * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2401 * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2402 if(!ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, &fmt_index, &nWGLFormats)) {
2403 WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2406 for (i = 0; i < nAttributes; ++i) {
2407 const int curWGLAttr = piAttributes[i];
2408 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2410 switch (curWGLAttr) {
2411 case WGL_NUMBER_PIXEL_FORMATS_ARB:
2412 piValues[i] = nWGLFormats;
2415 case WGL_SUPPORT_OPENGL_ARB:
2416 piValues[i] = GL_TRUE;
2419 case WGL_ACCELERATION_ARB:
2420 curGLXAttr = GLX_CONFIG_CAVEAT;
2422 if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
2423 curCfg = cfgs[iPixelFormat - 1];
2425 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2426 if (hTest) goto get_error;
2428 case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2429 case GLX_SLOW_CONFIG: piValues[i] = WGL_NO_ACCELERATION_ARB; break;
2430 case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2432 ERR("unexpected Config Caveat(%x)\n", tmp);
2433 piValues[i] = WGL_NO_ACCELERATION_ARB;
2437 case WGL_TRANSPARENT_ARB:
2438 curGLXAttr = GLX_TRANSPARENT_TYPE;
2439 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2440 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2441 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2442 curCfg = cfgs[fmt_index];
2443 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2444 if (hTest) goto get_error;
2445 piValues[i] = GL_FALSE;
2446 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2449 case WGL_PIXEL_TYPE_ARB:
2450 curGLXAttr = GLX_RENDER_TYPE;
2451 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2452 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2453 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2454 curCfg = cfgs[fmt_index];
2455 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2456 if (hTest) goto get_error;
2457 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2458 if (tmp & GLX_RGBA_BIT) { piValues[i] = WGL_TYPE_RGBA_ARB; }
2459 else if (tmp & GLX_COLOR_INDEX_BIT) { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2460 else if (tmp & GLX_RGBA_FLOAT_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2461 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2463 ERR("unexpected RenderType(%x)\n", tmp);
2464 piValues[i] = WGL_TYPE_RGBA_ARB;
2468 case WGL_COLOR_BITS_ARB:
2469 /** see ConvertAttribWGLtoGLX for explain */
2470 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2471 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2472 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2473 curCfg = cfgs[fmt_index];
2474 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_BUFFER_SIZE, piValues + i);
2475 if (hTest) goto get_error;
2476 TRACE("WGL_COLOR_BITS_ARB: GLX_BUFFER_SIZE = %d\n", piValues[i]);
2477 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_ALPHA_SIZE, &tmp);
2478 if (hTest) goto get_error;
2479 TRACE("WGL_COLOR_BITS_ARB: GLX_ALPHA_SIZE = %d\n", tmp);
2480 piValues[i] = piValues[i] - tmp;
2483 case WGL_BIND_TO_TEXTURE_RGB_ARB:
2484 if (use_render_texture_ati) {
2485 curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
2488 case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2489 if (use_render_texture_ati) {
2490 curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
2493 if (!use_render_texture_emulation) {
2494 piValues[i] = GL_FALSE;
2497 curGLXAttr = GLX_RENDER_TYPE;
2498 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2499 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2500 if((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs)) goto pix_error;
2501 curCfg = cfgs[fmt_index];
2502 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, &tmp);
2503 if (hTest) goto get_error;
2504 if (GLX_COLOR_INDEX_BIT == tmp) {
2505 piValues[i] = GL_FALSE;
2508 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_DRAWABLE_TYPE, &tmp);
2509 if (hTest) goto get_error;
2510 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2513 case WGL_BLUE_BITS_ARB:
2514 curGLXAttr = GLX_BLUE_SIZE;
2516 case WGL_RED_BITS_ARB:
2517 curGLXAttr = GLX_RED_SIZE;
2519 case WGL_GREEN_BITS_ARB:
2520 curGLXAttr = GLX_GREEN_SIZE;
2522 case WGL_ALPHA_BITS_ARB:
2523 curGLXAttr = GLX_ALPHA_SIZE;
2525 case WGL_DEPTH_BITS_ARB:
2526 curGLXAttr = GLX_DEPTH_SIZE;
2528 case WGL_STENCIL_BITS_ARB:
2529 curGLXAttr = GLX_STENCIL_SIZE;
2531 case WGL_DOUBLE_BUFFER_ARB:
2532 curGLXAttr = GLX_DOUBLEBUFFER;
2534 case WGL_STEREO_ARB:
2535 curGLXAttr = GLX_STEREO;
2537 case WGL_AUX_BUFFERS_ARB:
2538 curGLXAttr = GLX_AUX_BUFFERS;
2540 case WGL_SUPPORT_GDI_ARB:
2541 case WGL_DRAW_TO_WINDOW_ARB:
2542 case WGL_DRAW_TO_BITMAP_ARB:
2543 /* We only supported a limited number of formats right now which are all renderable by X 'GLX_X_RENDERABLE' */
2544 piValues[i] = GL_TRUE;
2546 case WGL_DRAW_TO_PBUFFER_ARB:
2547 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, GLX_DRAWABLE_TYPE, &tmp);
2548 if (hTest) goto get_error;
2549 piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2552 case WGL_PBUFFER_LARGEST_ARB:
2553 curGLXAttr = GLX_LARGEST_PBUFFER;
2556 case WGL_SAMPLE_BUFFERS_ARB:
2557 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2560 case WGL_SAMPLES_ARB:
2561 curGLXAttr = GLX_SAMPLES_ARB;
2565 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2568 /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2569 * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2570 * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2572 * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2573 * and check which options can work using iPixelFormat=0 and which not.
2574 * A problem would be that this function is an extension. This would
2575 * mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2577 if (0 != curGLXAttr && iPixelFormat != 0) {
2578 /* Check if the format is supported by checking if iPixelFormat isn't larger than the max number of
2579 * supported WGLFormats and also check if the GLX fmt_index is valid. */
2580 if((iPixelFormat > 0) && ((iPixelFormat > nWGLFormats) || (fmt_index > nCfgs))) goto pix_error;
2581 curCfg = cfgs[fmt_index];
2582 hTest = pglXGetFBConfigAttrib(gdi_display, curCfg, curGLXAttr, piValues + i);
2583 if (hTest) goto get_error;
2586 piValues[i] = GL_FALSE;
2592 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2597 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nCfgs);
2603 * X11DRV_wglGetPixelFormatAttribfvARB
2605 * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2607 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
2613 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2615 /* Allocate a temporary array to store integer values */
2616 attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2618 ERR("couldn't allocate %d array\n", nAttributes);
2622 /* Piggy-back on wglGetPixelFormatAttribivARB */
2623 ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2625 /* Convert integer values to float. Should also check for attributes
2626 that can give decimal values here */
2627 for (i=0; i<nAttributes;i++) {
2628 pfValues[i] = attr[i];
2632 HeapFree(GetProcessHeap(), 0, attr);
2637 * X11DRV_wglBindTexImageARB
2639 * WGL_ARB_render_texture: wglBindTexImageARB
2641 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2643 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2644 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2645 if (NULL == object) {
2646 SetLastError(ERROR_INVALID_HANDLE);
2649 if (!object->use_render_texture) {
2650 SetLastError(ERROR_INVALID_HANDLE);
2653 /* Disable WGL_ARB_render_texture support until it is implemented properly
2654 * using pbuffers or FBOs */
2656 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2658 GLint prev_binded_tex;
2659 pglGetIntegerv(object->texture_target, &prev_binded_tex);
2660 if (NULL == object->render_ctx) {
2661 object->render_hdc = X11DRV_wglGetPbufferDCARB(hPbuffer);
2662 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2663 object->render_ctx = wglCreateContext(object->render_hdc);
2666 object->prev_hdc = wglGetCurrentDC();
2667 object->prev_ctx = wglGetCurrentContext();
2668 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2669 wglMakeCurrent(object->render_hdc, object->render_ctx);
2672 glBindTexture(object->texture_target, object->texture);
2673 if (GL_RGBA == object->use_render_texture) {
2674 glTexImage2D(object->texture_target, 0, GL_RGBA8, object->width, object->height, 0, GL_RGBA, GL_FLOAT, NULL);
2676 glTexImage2D(object->texture_target, 0, GL_RGB8, object->width, object->height, 0, GL_RGB, GL_FLOAT, NULL);
2680 object->texture = prev_binded_tex;
2684 if (NULL != pglXBindTexImageARB) {
2685 return pglXBindTexImageARB(object->display, object->drawable, iBuffer);
2691 * X11DRV_wglReleaseTexImageARB
2693 * WGL_ARB_render_texture: wglReleaseTexImageARB
2695 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2697 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2698 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2699 if (NULL == object) {
2700 SetLastError(ERROR_INVALID_HANDLE);
2703 if (!object->use_render_texture) {
2704 SetLastError(ERROR_INVALID_HANDLE);
2707 if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2709 GLint prev_binded_tex;
2710 glGetIntegerv(object->texture_target, &prev_binded_tex);
2711 if (GL_TEXTURE_1D == object->texture_target) {
2712 glCopyTexSubImage1D(object->texture_target, object->texture_level, 0, 0, 0, object->width);
2714 glCopyTexSubImage2D(object->texture_target, object->texture_level, 0, 0, 0, 0, object->width, object->height);
2716 glBindTexture(object->texture_target, prev_binded_tex);
2717 SwapBuffers(object->render_hdc);
2719 pglBindTexture(object->texture_target, object->texture);
2720 if (GL_TEXTURE_1D == object->texture_target) {
2721 pglCopyTexSubImage1D(object->texture_target, object->texture_level, 0, 0, 0, object->width);
2723 pglCopyTexSubImage2D(object->texture_target, object->texture_level, 0, 0, 0, 0, object->width, object->height);
2726 /* FIXME: This is routed through gdi32.dll to winex11.drv, replace this with GLX calls */
2727 wglMakeCurrent(object->prev_hdc, object->prev_ctx);
2730 if (NULL != pglXReleaseTexImageARB) {
2731 return pglXReleaseTexImageARB(object->display, object->drawable, iBuffer);
2737 * X11DRV_wglGetExtensionsStringEXT
2739 * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2741 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
2742 TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2743 return WineGLInfo.wglExtensions;
2747 * X11DRV_wglGetSwapIntervalEXT
2749 * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2751 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
2752 FIXME("(),stub!\n");
2753 return swap_interval;
2757 * X11DRV_wglSwapIntervalEXT
2759 * WGL_EXT_swap_control: wglSwapIntervalEXT
2761 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
2762 TRACE("(%d)\n", interval);
2763 swap_interval = interval;
2764 if (NULL != pglXSwapIntervalSGI) {
2765 return 0 == pglXSwapIntervalSGI(interval);
2767 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
2772 * X11DRV_wglAllocateMemoryNV
2774 * WGL_NV_vertex_array_range: wglAllocateMemoryNV
2776 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
2777 TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
2778 if (pglXAllocateMemoryNV == NULL)
2781 return pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
2785 * X11DRV_wglFreeMemoryNV
2787 * WGL_NV_vertex_array_range: wglFreeMemoryNV
2789 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
2790 TRACE("(%p)\n", pointer);
2791 if (pglXFreeMemoryNV == NULL)
2794 pglXFreeMemoryNV(pointer);
2798 * glxRequireVersion (internal)
2800 * Check if the supported GLX version matches requiredVersion.
2802 static BOOL glxRequireVersion(int requiredVersion)
2804 /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2805 if(requiredVersion <= WineGLInfo.glxVersion[1])
2811 static BOOL glxRequireExtension(const char *requiredExtension)
2813 if (strstr(WineGLInfo.glxClientExtensions, requiredExtension) == NULL) {
2820 static BOOL register_extension(const WineGLExtension * ext)
2824 assert( WineGLExtensionListSize < MAX_EXTENSIONS );
2825 WineGLExtensionList[WineGLExtensionListSize++] = ext;
2827 strcat(WineGLInfo.wglExtensions, " ");
2828 strcat(WineGLInfo.wglExtensions, ext->extName);
2830 TRACE("'%s'\n", ext->extName);
2832 for (i = 0; ext->extEntryPoints[i].funcName; ++i)
2833 TRACE(" - '%s'\n", ext->extEntryPoints[i].funcName);
2838 static const WineGLExtension WGL_internal_functions =
2842 { "wglDisable", X11DRV_wglDisable },
2843 { "wglEnable", X11DRV_wglEnable },
2844 { "wglGetIntegerv", X11DRV_wglGetIntegerv },
2845 { "wglIsEnabled", X11DRV_wglIsEnabled },
2846 { "wglScissor", X11DRV_wglScissor },
2847 { "wglViewport", X11DRV_wglViewport },
2852 static const WineGLExtension WGL_ARB_extensions_string =
2854 "WGL_ARB_extensions_string",
2856 { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
2860 static const WineGLExtension WGL_ARB_make_current_read =
2862 "WGL_ARB_make_current_read",
2864 { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
2865 { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
2869 static const WineGLExtension WGL_ARB_multisample =
2871 "WGL_ARB_multisample",
2874 static const WineGLExtension WGL_ARB_pbuffer =
2878 { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
2879 { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
2880 { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
2881 { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
2882 { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
2883 { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
2887 static const WineGLExtension WGL_ARB_pixel_format =
2889 "WGL_ARB_pixel_format",
2891 { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
2892 { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
2893 { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
2897 static const WineGLExtension WGL_ARB_render_texture =
2899 "WGL_ARB_render_texture",
2901 { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
2902 { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
2906 static const WineGLExtension WGL_EXT_extensions_string =
2908 "WGL_EXT_extensions_string",
2910 { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
2914 static const WineGLExtension WGL_EXT_swap_control =
2916 "WGL_EXT_swap_control",
2918 { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
2919 { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
2923 static const WineGLExtension WGL_NV_vertex_array_range =
2925 "WGL_NV_vertex_array_range",
2927 { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
2928 { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
2933 * X11DRV_WineGL_LoadExtensions
2935 static void X11DRV_WineGL_LoadExtensions(void)
2937 WineGLInfo.wglExtensions[0] = 0;
2939 /* Load Wine internal functions */
2940 register_extension(&WGL_internal_functions);
2942 /* ARB Extensions */
2944 register_extension(&WGL_ARB_extensions_string);
2946 if (glxRequireVersion(3))
2947 register_extension(&WGL_ARB_make_current_read);
2949 if (glxRequireExtension("GLX_ARB_multisample"))
2950 register_extension(&WGL_ARB_multisample);
2952 /* In general pbuffer functionality requires support in the X-server. The functionality is
2953 * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
2954 * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
2955 * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
2957 * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
2958 * without support in the X-server (which other Mesa based drivers require).
2960 * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
2961 * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
2962 * is available pbuffers must be available too. */
2963 if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
2964 register_extension(&WGL_ARB_pbuffer);
2966 register_extension(&WGL_ARB_pixel_format);
2968 if (glxRequireExtension("GLX_ATI_render_texture") ||
2969 glxRequireExtension("GLX_ARB_render_texture"))
2970 register_extension(&WGL_ARB_render_texture);
2972 /* EXT Extensions */
2974 register_extension(&WGL_EXT_extensions_string);
2976 if (glxRequireExtension("GLX_SGI_swap_control"))
2977 register_extension(&WGL_EXT_swap_control);
2979 /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
2980 if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
2981 register_extension(&WGL_NV_vertex_array_range);
2985 static XID create_glxpixmap(X11DRV_PDEVICE *physDev)
2989 XVisualInfo template;
2994 /* Retrieve the visualid from our main visual which is the only visual we can use */
2995 template.visualid = XVisualIDFromVisual(visual);
2996 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
2998 ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
3000 wine_tsx11_unlock();
3001 TRACE("return %lx\n", ret);
3005 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3011 if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
3012 ret = physDev->drawable; /* PBuffer */
3015 if(!physDev->bitmap->glxpixmap)
3016 physDev->bitmap->glxpixmap = create_glxpixmap(physDev);
3017 ret = physDev->bitmap->glxpixmap;
3021 ret = physDev->drawable;
3025 BOOL destroy_glxpixmap(XID glxpixmap)
3028 pglXDestroyGLXPixmap(gdi_display, glxpixmap);
3029 wine_tsx11_unlock();
3034 * X11DRV_SwapBuffers
3036 * Swap the buffers of this DC
3038 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev)
3040 GLXDrawable drawable;
3041 if (!has_opengl()) {
3042 ERR("No libGL on this box - disabling OpenGL support !\n");
3046 TRACE_(opengl)("(%p)\n", physDev);
3048 drawable = get_glxdrawable(physDev);
3050 pglXSwapBuffers(gdi_display, drawable);
3051 wine_tsx11_unlock();
3056 static long prev_time, frames;
3058 DWORD time = GetTickCount();
3060 /* every 1.5 seconds */
3061 if (time - prev_time > 1500) {
3062 TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
3071 /***********************************************************************
3072 * X11DRV_setup_opengl_visual
3074 * Setup the default visual used for OpenGL and Direct3D, and the desktop
3075 * window (if it exists). If OpenGL isn't available, the visual is simply
3076 * set to the default visual for the display
3078 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
3080 XVisualInfo *visual = NULL;
3083 /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support,
3084 * D3D and some applications can make use of aux buffers.
3086 int visualProperties[][11] = {
3087 { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_AUX_BUFFERS, 1, None },
3088 { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_ALPHA_SIZE, 8, None },
3089 { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, GLX_STENCIL_SIZE, 8, None },
3090 { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, None },
3097 for (i = 0; i < sizeof(visualProperties)/sizeof(visualProperties[0]); ++i) {
3098 visual = pglXChooseVisual(display, DefaultScreen(display), visualProperties[i]);
3102 wine_tsx11_unlock();
3105 TRACE("Visual ID %lx Chosen\n", visual->visualid);
3107 WARN("No suitable visual found\n");
3112 #else /* no OpenGL includes */
3114 /***********************************************************************
3115 * ChoosePixelFormat (X11DRV.@)
3117 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
3118 const PIXELFORMATDESCRIPTOR *ppfd) {
3119 ERR("No OpenGL support compiled in.\n");
3124 /***********************************************************************
3125 * DescribePixelFormat (X11DRV.@)
3127 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
3130 PIXELFORMATDESCRIPTOR *ppfd) {
3131 ERR("No OpenGL support compiled in.\n");
3136 /***********************************************************************
3137 * GetPixelFormat (X11DRV.@)
3139 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
3140 ERR("No OpenGL support compiled in.\n");
3145 /***********************************************************************
3146 * SetPixelFormat (X11DRV.@)
3148 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
3150 const PIXELFORMATDESCRIPTOR *ppfd) {
3151 ERR("No OpenGL support compiled in.\n");
3156 /***********************************************************************
3157 * SwapBuffers (X11DRV.@)
3159 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
3160 ERR_(opengl)("No OpenGL support compiled in.\n");
3166 * X11DRV_wglCreateContext
3168 * For OpenGL32 wglCreateContext.
3170 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) {
3171 ERR_(opengl)("No OpenGL support compiled in.\n");
3176 * X11DRV_wglDeleteContext
3178 * For OpenGL32 wglDeleteContext.
3180 BOOL X11DRV_wglDeleteContext(HGLRC hglrc) {
3181 ERR_(opengl)("No OpenGL support compiled in.\n");
3186 * X11DRV_wglGetProcAddress
3188 * For OpenGL32 wglGetProcAddress.
3190 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
3191 ERR_(opengl)("No OpenGL support compiled in.\n");
3195 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *hDevice, void *hPbuffer)
3197 ERR_(opengl)("No OpenGL support compiled in.\n");
3201 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) {
3202 ERR_(opengl)("No OpenGL support compiled in.\n");
3207 * X11DRV_wglMakeCurrent
3209 * For OpenGL32 wglMakeCurrent.
3211 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
3212 ERR_(opengl)("No OpenGL support compiled in.\n");
3217 * X11DRV_wglShareLists
3219 * For OpenGL32 wglShaderLists.
3221 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
3222 ERR_(opengl)("No OpenGL support compiled in.\n");
3227 * X11DRV_wglUseFontBitmapsA
3229 * For OpenGL32 wglUseFontBitmapsA.
3231 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3233 ERR_(opengl)("No OpenGL support compiled in.\n");
3238 * X11DRV_wglUseFontBitmapsW
3240 * For OpenGL32 wglUseFontBitmapsW.
3242 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3244 ERR_(opengl)("No OpenGL support compiled in.\n");
3248 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
3253 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3258 BOOL destroy_glxpixmap(XID glxpixmap)
3263 #endif /* defined(HAVE_OPENGL) */