wgl: wglBindTexImageARB should return TRUE on success.
[wine] / dlls / winex11.drv / opengl.c
1 /*
2  * X11DRV OpenGL functions
3  *
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
9  *
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.
14  *
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.
19  *
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
23  */
24
25 #include "config.h"
26 #include "wine/port.h"
27
28 #include <assert.h>
29 #include <stdlib.h>
30 #include <string.h>
31
32 #include "x11drv.h"
33 #include "winternl.h"
34 #include "wine/library.h"
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
38 WINE_DECLARE_DEBUG_CHANNEL(opengl);
39
40 #ifdef SONAME_LIBGL
41
42 #undef APIENTRY
43 #undef CALLBACK
44 #undef WINAPI
45
46 #ifdef HAVE_GL_GL_H
47 # include <GL/gl.h>
48 #endif
49 #ifdef HAVE_GL_GLX_H
50 # include <GL/glx.h>
51 #endif
52 #ifdef HAVE_GL_GLEXT_H
53 # include <GL/glext.h>
54 #endif
55
56 #include "wine/wgl.h"
57
58 #undef APIENTRY
59 #undef CALLBACK
60 #undef WINAPI
61
62 /* Redefines the constants */
63 #define CALLBACK    __stdcall
64 #define WINAPI      __stdcall
65 #define APIENTRY    WINAPI
66
67
68 WINE_DECLARE_DEBUG_CHANNEL(fps);
69
70 typedef struct wine_glextension {
71     const char *extName;
72     struct {
73         const char *funcName;
74         void *funcAddress;
75     } extEntryPoints[8];
76 } WineGLExtension;
77
78 struct WineGLInfo {
79     const char *glVersion;
80     const char *glExtensions;
81
82     int glxVersion[2];
83
84     const char *glxServerVersion;
85     const char *glxServerExtensions;
86
87     const char *glxClientVersion;
88     const char *glxClientExtensions;
89
90     const char *glxExtensions;
91
92     BOOL glxDirect;
93     char wglExtensions[4096];
94 };
95
96 typedef struct wine_glpixelformat {
97     int         iPixelFormat;
98     GLXFBConfig fbconfig;
99     int         fmt_id;
100     int         render_type;
101     BOOL        offscreenOnly;
102 } WineGLPixelFormat;
103
104 typedef struct wine_glcontext {
105     HDC hdc;
106     XVisualInfo *vis;
107     WineGLPixelFormat *fmt;
108     GLXContext ctx;
109     BOOL do_escape;
110     X11DRV_PDEVICE *physDev;
111     RECT viewport;
112     RECT scissor;
113     BOOL scissor_enabled;
114     struct wine_glcontext *next;
115     struct wine_glcontext *prev;
116 } Wine_GLContext;
117
118 typedef struct wine_glpbuffer {
119     Drawable   drawable;
120     Display*   display;
121     WineGLPixelFormat* fmt;
122     int        width;
123     int        height;
124     int*       attribList;
125     HDC        hdc;
126
127     int        use_render_texture; /* This is also the internal texture format */
128     int        texture_bind_target;
129     int        texture_bpp;
130     GLint      texture_format;
131     GLuint     texture_target;
132     GLenum     texture_type;
133     GLuint     texture;
134     int        texture_level;
135 } Wine_GLPBuffer;
136
137 static Wine_GLContext *context_list;
138 static struct WineGLInfo WineGLInfo = { 0 };
139 static int use_render_texture_emulation = 1;
140 static int use_render_texture_ati = 0;
141 static int swap_interval = 1;
142
143 #define MAX_EXTENSIONS 16
144 static const WineGLExtension *WineGLExtensionList[MAX_EXTENSIONS];
145 static int WineGLExtensionListSize;
146
147 static WineGLPixelFormat *WineGLPixelFormatList;
148 static int WineGLPixelFormatListSize = 0;
149
150 static void X11DRV_WineGL_LoadExtensions(void);
151
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);
172 #undef TEST_AND_DUMP
173   TRACE("\n");
174
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;
179   }
180   TRACE("\n");
181
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);
191
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;
197   }
198   TRACE("\n");
199 }
200
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)
203
204 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
205 /* GLX 1.0 */
206 MAKE_FUNCPTR(glXChooseVisual)
207 MAKE_FUNCPTR(glXCreateContext)
208 MAKE_FUNCPTR(glXCreateGLXPixmap)
209 MAKE_FUNCPTR(glXGetCurrentContext)
210 MAKE_FUNCPTR(glXGetCurrentDrawable)
211 MAKE_FUNCPTR(glXDestroyContext)
212 MAKE_FUNCPTR(glXDestroyGLXPixmap)
213 MAKE_FUNCPTR(glXGetConfig)
214 MAKE_FUNCPTR(glXIsDirect)
215 MAKE_FUNCPTR(glXMakeCurrent)
216 MAKE_FUNCPTR(glXSwapBuffers)
217 MAKE_FUNCPTR(glXQueryExtension)
218 MAKE_FUNCPTR(glXQueryVersion)
219 MAKE_FUNCPTR(glXUseXFont)
220
221 /* GLX 1.1 */
222 MAKE_FUNCPTR(glXGetClientString)
223 MAKE_FUNCPTR(glXQueryExtensionsString)
224 MAKE_FUNCPTR(glXQueryServerString)
225
226 /* GLX 1.3 */
227 MAKE_FUNCPTR(glXGetFBConfigs)
228 MAKE_FUNCPTR(glXChooseFBConfig)
229 MAKE_FUNCPTR(glXCreatePbuffer)
230 MAKE_FUNCPTR(glXCreateNewContext)
231 MAKE_FUNCPTR(glXDestroyPbuffer)
232 MAKE_FUNCPTR(glXGetFBConfigAttrib)
233 MAKE_FUNCPTR(glXGetVisualFromFBConfig)
234 MAKE_FUNCPTR(glXMakeContextCurrent)
235 MAKE_FUNCPTR(glXQueryDrawable)
236 MAKE_FUNCPTR(glXGetCurrentReadDrawable)
237
238 /* GLX Extensions */
239 static void* (*pglXGetProcAddressARB)(const GLubyte *);
240 static BOOL  (*pglXBindTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
241 static BOOL  (*pglXReleaseTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
242 static BOOL  (*pglXDrawableAttribARB)(Display *dpy, GLXDrawable draw, const int *attribList);
243 static int   (*pglXSwapIntervalSGI)(int);
244
245 /* NV GLX Extension */
246 static void* (*pglXAllocateMemoryNV)(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
247 static void  (*pglXFreeMemoryNV)(GLvoid *pointer);
248
249 /* Standard OpenGL */
250 MAKE_FUNCPTR(glBindTexture)
251 MAKE_FUNCPTR(glBitmap)
252 MAKE_FUNCPTR(glCopyTexSubImage1D)
253 MAKE_FUNCPTR(glCopyTexSubImage2D)
254 MAKE_FUNCPTR(glDisable)
255 MAKE_FUNCPTR(glDrawBuffer)
256 MAKE_FUNCPTR(glEnable)
257 MAKE_FUNCPTR(glEndList)
258 MAKE_FUNCPTR(glGetError)
259 MAKE_FUNCPTR(glGetIntegerv)
260 MAKE_FUNCPTR(glGetString)
261 MAKE_FUNCPTR(glIsEnabled)
262 MAKE_FUNCPTR(glNewList)
263 MAKE_FUNCPTR(glPixelStorei)
264 MAKE_FUNCPTR(glReadPixels)
265 MAKE_FUNCPTR(glScissor)
266 MAKE_FUNCPTR(glTexImage2D)
267 MAKE_FUNCPTR(glViewport)
268 #undef MAKE_FUNCPTR
269
270 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
271 {
272     static BOOL infoInitialized = FALSE;
273
274     int screen = DefaultScreen(gdi_display);
275     Window win = RootWindow(gdi_display, screen);
276     Visual *visual;
277     XVisualInfo template;
278     XVisualInfo *vis;
279     int num;
280     GLXContext ctx = NULL;
281
282     if (infoInitialized)
283         return TRUE;
284     infoInitialized = TRUE;
285
286     wine_tsx11_lock();
287
288     visual = DefaultVisual(gdi_display, screen);
289     template.visualid = XVisualIDFromVisual(visual);
290     vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
291     if (vis) {
292         WORD old_fs = wine_get_fs();
293         /* Create a GLX Context. Without one we can't query GL information */
294         ctx = pglXCreateContext(gdi_display, vis, None, GL_TRUE);
295         if (wine_get_fs() != old_fs)
296         {
297             wine_set_fs( old_fs );
298             wine_tsx11_unlock();
299             ERR( "%%fs register corrupted, probably broken ATI driver, disabling OpenGL.\n" );
300             ERR( "You need to set the \"UseFastTls\" option to \"2\" in your X config file.\n" );
301             return FALSE;
302         }
303     }
304
305     if (ctx) {
306         pglXMakeCurrent(gdi_display, win, ctx);
307     } else {
308         ERR(" couldn't initialize OpenGL, expect problems\n");
309         wine_tsx11_unlock();
310         return FALSE;
311     }
312
313     WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
314     WineGLInfo.glExtensions = strdup((const char *) pglGetString(GL_EXTENSIONS));
315
316     /* Get the common GLX version supported by GLX client and server ( major/minor) */
317     pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
318
319     WineGLInfo.glxServerVersion = pglXQueryServerString(gdi_display, screen, GLX_VERSION);
320     WineGLInfo.glxServerExtensions = pglXQueryServerString(gdi_display, screen, GLX_EXTENSIONS);
321
322     WineGLInfo.glxClientVersion = pglXGetClientString(gdi_display, GLX_VERSION);
323     WineGLInfo.glxClientExtensions = pglXGetClientString(gdi_display, GLX_EXTENSIONS);
324
325     WineGLInfo.glxExtensions = pglXQueryExtensionsString(gdi_display, screen);
326     WineGLInfo.glxDirect = pglXIsDirect(gdi_display, ctx);
327
328     TRACE("GL version             : %s.\n", WineGLInfo.glVersion);
329     TRACE("GLX version            : %d.%d.\n", WineGLInfo.glxVersion[0], WineGLInfo.glxVersion[1]);
330     TRACE("Server GLX version     : %s.\n", WineGLInfo.glxServerVersion);
331     TRACE("Client GLX version     : %s.\n", WineGLInfo.glxClientVersion);
332     TRACE("Direct rendering enabled: %s\n", WineGLInfo.glxDirect ? "True" : "False");
333
334     if(vis) XFree(vis);
335     if(ctx) {
336         pglXMakeCurrent(gdi_display, None, NULL);    
337         pglXDestroyContext(gdi_display, ctx);
338     }
339     wine_tsx11_unlock();
340     return TRUE;
341 }
342
343 static BOOL has_opengl(void)
344 {
345     static int init_done;
346     static void *opengl_handle;
347     const char *glx_extensions;
348
349     int error_base, event_base;
350
351     if (init_done) return (opengl_handle != NULL);
352     init_done = 1;
353
354     /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient
355        and include all dependencies */
356     opengl_handle = wine_dlopen(SONAME_LIBGL, RTLD_NOW|RTLD_GLOBAL, NULL, 0);
357     if (opengl_handle == NULL) return FALSE;
358
359     pglXGetProcAddressARB = wine_dlsym(opengl_handle, "glXGetProcAddressARB", NULL, 0);
360     if (pglXGetProcAddressARB == NULL) {
361         ERR("could not find glXGetProcAddressARB in libGL.\n");
362         return FALSE;
363     }
364
365 #define LOAD_FUNCPTR(f) if((p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f)) == NULL) goto sym_not_found;
366 /* GLX 1.0 */
367 LOAD_FUNCPTR(glXChooseVisual)
368 LOAD_FUNCPTR(glXCreateContext)
369 LOAD_FUNCPTR(glXCreateGLXPixmap)
370 LOAD_FUNCPTR(glXGetCurrentContext)
371 LOAD_FUNCPTR(glXGetCurrentDrawable)
372 LOAD_FUNCPTR(glXDestroyContext)
373 LOAD_FUNCPTR(glXDestroyGLXPixmap)
374 LOAD_FUNCPTR(glXGetConfig)
375 LOAD_FUNCPTR(glXIsDirect)
376 LOAD_FUNCPTR(glXMakeCurrent)
377 LOAD_FUNCPTR(glXSwapBuffers)
378 LOAD_FUNCPTR(glXQueryExtension)
379 LOAD_FUNCPTR(glXQueryVersion)
380 LOAD_FUNCPTR(glXUseXFont)
381
382 /* GLX 1.1 */
383 LOAD_FUNCPTR(glXGetClientString)
384 LOAD_FUNCPTR(glXQueryExtensionsString)
385 LOAD_FUNCPTR(glXQueryServerString)
386
387 /* GLX 1.3 */
388 LOAD_FUNCPTR(glXCreatePbuffer)
389 LOAD_FUNCPTR(glXCreateNewContext)
390 LOAD_FUNCPTR(glXDestroyPbuffer)
391 LOAD_FUNCPTR(glXMakeContextCurrent)
392 LOAD_FUNCPTR(glXGetCurrentReadDrawable)
393 LOAD_FUNCPTR(glXGetFBConfigs)
394
395 /* Standard OpenGL calls */
396 LOAD_FUNCPTR(glBindTexture)
397 LOAD_FUNCPTR(glBitmap)
398 LOAD_FUNCPTR(glCopyTexSubImage1D)
399 LOAD_FUNCPTR(glCopyTexSubImage2D)
400 LOAD_FUNCPTR(glDisable)
401 LOAD_FUNCPTR(glDrawBuffer)
402 LOAD_FUNCPTR(glEnable)
403 LOAD_FUNCPTR(glEndList)
404 LOAD_FUNCPTR(glGetError)
405 LOAD_FUNCPTR(glGetIntegerv)
406 LOAD_FUNCPTR(glGetString)
407 LOAD_FUNCPTR(glIsEnabled)
408 LOAD_FUNCPTR(glNewList)
409 LOAD_FUNCPTR(glPixelStorei)
410 LOAD_FUNCPTR(glReadPixels)
411 LOAD_FUNCPTR(glScissor)
412 LOAD_FUNCPTR(glTexImage2D)
413 LOAD_FUNCPTR(glViewport)
414 #undef LOAD_FUNCPTR
415
416 /* It doesn't matter if these fail. They'll only be used if the driver reports
417    the associated extension is available (and if a driver reports the extension
418    is available but fails to provide the functions, it's quite broken) */
419 #define LOAD_FUNCPTR(f) p##f = (void*)pglXGetProcAddressARB((const unsigned char*)#f);
420 /* NV GLX Extension */
421 LOAD_FUNCPTR(glXAllocateMemoryNV)
422 LOAD_FUNCPTR(glXFreeMemoryNV)
423 #undef LOAD_FUNCPTR
424
425     if(!X11DRV_WineGL_InitOpenglInfo()) {
426         wine_dlclose(opengl_handle, NULL, 0);
427         opengl_handle = NULL;
428         return FALSE;
429     }
430
431     wine_tsx11_lock();
432     if (pglXQueryExtension(gdi_display, &error_base, &event_base) == True) {
433         TRACE("GLX is up and running error_base = %d\n", error_base);
434     } else {
435         wine_dlclose(opengl_handle, NULL, 0);
436         opengl_handle = NULL;
437     }
438
439     /* In case of GLX you have direct and indirect rendering. Most of the time direct rendering is used
440      * as in general only that is hardware accelerated. In some cases like in case of remote X indirect
441      * rendering is used.
442      *
443      * The main problem for our OpenGL code is that we need certain GLX calls but their presence
444      * depends on the reported GLX client / server version and on the client / server extension list.
445      * Those don't have to be the same.
446      *
447      * In general the server GLX information should be used in case of indirect rendering. When direct
448      * rendering is used, the OpenGL client library is responsible for which GLX calls are available.
449      * Nvidia's OpenGL drivers are the best in terms of GLX features. At the moment of writing their
450      * 8762 drivers support 1.3 for the server and 1.4 for the client and they support lots of extensions.
451      * Unfortunately it is much more complicated for Mesa/DRI-based drivers and ATI's drivers.
452      * Both sets of drivers report a server version of 1.2 and the client version can be 1.3 or 1.4.
453      * Further, in case of at least ATI's drivers, one crucial extension needed for our pixel format code
454      * is only available in the list of server extensions and not in the client list.
455      *
456      * The versioning checks below try to take into account the comments from above.
457      */
458
459     /* Depending on the use of direct or indirect rendering we need either the list of extensions
460      * exported by the client or by the server.
461      */
462     if(WineGLInfo.glxDirect)
463         glx_extensions = WineGLInfo.glxClientExtensions;
464     else
465         glx_extensions = WineGLInfo.glxServerExtensions;
466
467     /* Based on the default opengl context we decide whether direct or indirect rendering is used.
468      * In case of indirect rendering we check if the GLX version of the server is 1.2 and else
469      * the client version is checked.
470      */
471     if ((!WineGLInfo.glxDirect && !strcmp("1.2", WineGLInfo.glxServerVersion)) ||
472         (WineGLInfo.glxDirect && !strcmp("1.2", WineGLInfo.glxClientVersion)))
473     {
474         if (NULL != strstr(glx_extensions, "GLX_SGIX_fbconfig")) {
475             pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfigSGIX");
476             pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttribSGIX");
477             pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfigSGIX");
478         } else {
479             ERR(" glx_version is %s and GLX_SGIX_fbconfig extension is unsupported. Expect problems.\n", WineGLInfo.glxClientVersion);
480         }
481     } else {
482         pglXChooseFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXChooseFBConfig");
483         pglXGetFBConfigAttrib = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetFBConfigAttrib");
484         pglXGetVisualFromFBConfig = (void*)pglXGetProcAddressARB((const GLubyte *) "glXGetVisualFromFBConfig");
485     }
486
487     /* The mesa libGL client library seems to forward glXQueryDrawable to the Xserver, so only
488      * enable this function when the Xserver understand GLX 1.3 or newer
489      */
490     if (!strcmp("1.2", WineGLInfo.glxServerVersion))
491         pglXQueryDrawable = NULL;
492     else
493         pglXQueryDrawable = wine_dlsym(RTLD_DEFAULT, "glXQueryDrawable", NULL, 0);
494
495     if (NULL != strstr(glx_extensions, "GLX_ATI_render_texture")) {
496         pglXBindTexImageARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXBindTexImageARB");
497         pglXReleaseTexImageARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXReleaseTexImageARB");
498         pglXDrawableAttribARB = (void*)pglXGetProcAddressARB((const GLubyte *) "glXDrawableAttribARB");
499     }
500
501     X11DRV_WineGL_LoadExtensions();
502
503     wine_tsx11_unlock();
504     return (opengl_handle != NULL);
505
506 sym_not_found:
507     wine_dlclose(opengl_handle, NULL, 0);
508     opengl_handle = NULL;
509     return FALSE;
510 }
511
512 static inline Wine_GLContext *alloc_context(void)
513 {
514     Wine_GLContext *ret;
515
516     if ((ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLContext))))
517     {
518         ret->next = context_list;
519         if (context_list) context_list->prev = ret;
520         context_list = ret;
521     }
522     return ret;
523 }
524
525 static inline void free_context(Wine_GLContext *context)
526 {
527     if (context->next != NULL) context->next->prev = context->prev;
528     if (context->prev != NULL) context->prev->next = context->next;
529     else context_list = context->next;
530
531     HeapFree(GetProcessHeap(), 0, context);
532 }
533
534 static inline Wine_GLContext *get_context_from_GLXContext(GLXContext ctx)
535 {
536     Wine_GLContext *ret;
537     if (!ctx) return NULL;
538     for (ret = context_list; ret; ret = ret->next) if (ctx == ret->ctx) break;
539     return ret;
540 }
541
542 /**
543  * get_hdc_from_Drawable (internal)
544  *
545  * For use by wglGetCurrentReadDCARB.
546  */
547 static inline HDC get_hdc_from_Drawable(GLXDrawable d)
548 {
549     Wine_GLContext *ret;
550     for (ret = context_list; ret; ret = ret->next) {
551         if (d == ret->physDev->drawable) {
552             return ret->hdc;
553         }
554     }
555     return NULL;
556 }
557
558 static inline BOOL is_valid_context( Wine_GLContext *ctx )
559 {
560     Wine_GLContext *ptr;
561     for (ptr = context_list; ptr; ptr = ptr->next) if (ptr == ctx) break;
562     return (ptr != NULL);
563 }
564
565 static int describeContext(Wine_GLContext* ctx) {
566     int tmp;
567     int ctx_vis_id;
568     TRACE(" Context %p have (vis:%p):\n", ctx, ctx->vis);
569     pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_FBCONFIG_ID, &tmp);
570     TRACE(" - FBCONFIG_ID 0x%x\n", tmp);
571     pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_VISUAL_ID, &tmp);
572     TRACE(" - VISUAL_ID 0x%x\n", tmp);
573     ctx_vis_id = tmp;
574     return ctx_vis_id;
575 }
576
577 static int describeDrawable(Wine_GLContext* ctx, Drawable drawable) {
578     int tmp;
579     int nElements;
580     int attribList[3] = { GLX_FBCONFIG_ID, 0, None };
581     GLXFBConfig *fbCfgs;
582
583     if (pglXQueryDrawable == NULL)  {
584         /** glXQueryDrawable not available so returns not supported */
585         return -1;
586     }
587
588     TRACE(" Drawable %p have :\n", (void*) drawable);
589     pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &tmp);
590     TRACE(" - WIDTH as %d\n", tmp);
591     pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &tmp);
592     TRACE(" - HEIGHT as %d\n", tmp);
593     pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &tmp);
594     TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
595
596     attribList[1] = tmp;
597     fbCfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribList, &nElements);
598     if (fbCfgs == NULL) {
599         return -1;
600     }
601
602     pglXGetFBConfigAttrib(gdi_display, fbCfgs[0], GLX_VISUAL_ID, &tmp);
603     TRACE(" - VISUAL_ID as 0x%x\n", tmp);
604
605     XFree(fbCfgs);
606
607     return tmp;
608 }
609
610 static int ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
611   int nAttribs = 0;
612   unsigned cur = 0; 
613   int pop;
614   int drawattrib = 0;
615   int isColor = 0;
616   int wantColorBits = 0;
617   int sz_alpha = 0;
618
619   /* The list of WGL attributes is allowed to be NULL, so don't return -1 (error) but just 0 */
620   if(iWGLAttr == NULL)
621     return 0;
622
623   while (0 != iWGLAttr[cur]) {
624     TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
625
626     switch (iWGLAttr[cur]) {
627     case WGL_COLOR_BITS_ARB:
628       pop = iWGLAttr[++cur];
629       wantColorBits = pop; /** see end */
630       break;
631     case WGL_BLUE_BITS_ARB:
632       pop = iWGLAttr[++cur];
633       PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
634       TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
635       break;
636     case WGL_RED_BITS_ARB:
637       pop = iWGLAttr[++cur];
638       PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
639       TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
640       break;
641     case WGL_GREEN_BITS_ARB:
642       pop = iWGLAttr[++cur];
643       PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
644       TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
645       break;
646     case WGL_ALPHA_BITS_ARB:
647       pop = iWGLAttr[++cur];
648       sz_alpha = pop;
649       PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
650       TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
651       break;
652     case WGL_DEPTH_BITS_ARB:
653       pop = iWGLAttr[++cur];
654       PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
655       TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
656       break;
657     case WGL_STENCIL_BITS_ARB:
658       pop = iWGLAttr[++cur];
659       PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
660       TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
661       break;
662     case WGL_DOUBLE_BUFFER_ARB:
663       pop = iWGLAttr[++cur];
664       PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
665       TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
666       break;
667
668     case WGL_PIXEL_TYPE_ARB:
669       pop = iWGLAttr[++cur];
670       switch (pop) {
671       case WGL_TYPE_COLORINDEX_ARB: pop = GLX_COLOR_INDEX_BIT; isColor = 1; break ;
672       case WGL_TYPE_RGBA_ARB: pop = GLX_RGBA_BIT; break ;
673       /* 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 */
674       case WGL_TYPE_RGBA_FLOAT_ATI: pop = GLX_RGBA_FLOAT_BIT_ARB; break ;
675       default:
676         ERR("unexpected PixelType(%x)\n", pop); 
677         pop = 0;
678       }
679       PUSH2(oGLXAttr, GLX_RENDER_TYPE, pop);
680       TRACE("pAttr[%d] = GLX_RENDER_TYPE: %d\n", cur, pop);
681       break;
682
683     case WGL_SUPPORT_GDI_ARB:
684       pop = iWGLAttr[++cur];
685       /* We only support a limited number of formats which are all renderable by X (similar to GDI).
686        * Ignore this attribute to prevent us from not finding a match due to the limited
687        * amount of formats supported right now. This option could be matched to GLX_X_RENDERABLE
688        * but the issue is that when a program asks for no GDI support, there's no format we can return
689        * as all our supported formats are renderable by X.
690        */
691       TRACE("pAttr[%d] = WGL_SUPPORT_GDI_ARB: %d\n", cur, pop);
692       break;
693
694     case WGL_DRAW_TO_BITMAP_ARB:
695       pop = iWGLAttr[++cur];
696       TRACE("pAttr[%d] = WGL_DRAW_TO_BITMAP_ARB: %d\n", cur, pop);
697       /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
698       if (pop) {
699         drawattrib |= GLX_PIXMAP_BIT;
700       }
701       break;
702
703     case WGL_DRAW_TO_WINDOW_ARB:
704       pop = iWGLAttr[++cur];
705       TRACE("pAttr[%d] = WGL_DRAW_TO_WINDOW_ARB: %d\n", cur, pop);
706       /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
707       if (pop) {
708         drawattrib |= GLX_WINDOW_BIT;
709       }
710       break;
711
712     case WGL_DRAW_TO_PBUFFER_ARB:
713       pop = iWGLAttr[++cur];
714       TRACE("pAttr[%d] = WGL_DRAW_TO_PBUFFER_ARB: %d\n", cur, pop);
715       /* GLX_DRAWABLE_TYPE flags need to be OR'd together. See below. */
716       if (pop) {
717         drawattrib |= GLX_PBUFFER_BIT;
718       }
719       break;
720
721     case WGL_ACCELERATION_ARB:
722     case WGL_SUPPORT_OPENGL_ARB:
723       pop = iWGLAttr[++cur];
724       /** nothing to do, if we are here, supposing support Accelerated OpenGL */
725       TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
726       break;
727
728     case WGL_PBUFFER_LARGEST_ARB:
729       pop = iWGLAttr[++cur];
730       PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
731       TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
732       break;
733
734     case WGL_SAMPLE_BUFFERS_ARB:
735       pop = iWGLAttr[++cur];
736       PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
737       TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
738       break;
739
740     case WGL_SAMPLES_ARB:
741       pop = iWGLAttr[++cur];
742       PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
743       TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
744       break;
745
746     case WGL_TEXTURE_FORMAT_ARB:
747     case WGL_TEXTURE_TARGET_ARB:
748     case WGL_MIPMAP_TEXTURE_ARB:
749       TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
750       pop = iWGLAttr[++cur];
751       if (NULL == pbuf) {
752         ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
753       }
754       if (use_render_texture_ati) {
755         /** nothing to do here */
756       }
757       else if (!use_render_texture_emulation) {
758         if (WGL_NO_TEXTURE_ARB != pop) {
759           ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
760           return -1; /** error: don't support it */
761         } else {
762           PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
763           drawattrib |= GLX_PBUFFER_BIT;
764         }
765       }
766       break ;
767     case WGL_FLOAT_COMPONENTS_NV:
768       pop = iWGLAttr[++cur];
769       PUSH2(oGLXAttr, GLX_FLOAT_COMPONENTS_NV, pop);
770       TRACE("pAttr[%d] = GLX_FLOAT_COMPONENTS_NV: %x\n", cur, pop);
771       break ;
772     case WGL_BIND_TO_TEXTURE_RGB_ARB:
773     case WGL_BIND_TO_TEXTURE_RGBA_ARB:
774     case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV:
775     case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV:
776     case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV:
777     case WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV:
778       pop = iWGLAttr[++cur];
779       /** cannot be converted, see direct handling on 
780        *   - wglGetPixelFormatAttribivARB
781        *  TODO: wglChoosePixelFormat
782        */
783       break ;
784
785     default:
786       FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
787       break;
788     }
789     ++cur;
790   }
791
792   /**
793    * Trick as WGL_COLOR_BITS_ARB != GLX_BUFFER_SIZE
794    *    WGL_COLOR_BITS_ARB + WGL_ALPHA_BITS_ARB == GLX_BUFFER_SIZE
795    *
796    *  WGL_COLOR_BITS_ARB
797    *     The number of color bitplanes in each color buffer. For RGBA
798    *     pixel types, it is the size of the color buffer, excluding the
799    *     alpha bitplanes. For color-index pixels, it is the size of the
800    *     color index buffer.
801    *
802    *  GLX_BUFFER_SIZE   
803    *     This attribute defines the number of bits per color buffer. 
804    *     For GLX FBConfigs that correspond to a PseudoColor or StaticColor visual, 
805    *     this is equal to the depth value reported in the X11 visual. 
806    *     For GLX FBConfigs that correspond to TrueColor or DirectColor visual, 
807    *     this is the sum of GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_BLUE_SIZE, and GLX_ALPHA_SIZE.
808    * 
809    */
810   if (0 < wantColorBits) {
811     if (!isColor) { 
812       wantColorBits += sz_alpha; 
813     }
814     if (32 < wantColorBits) {
815       ERR("buggy %d GLX_BUFFER_SIZE default to 32\n", wantColorBits);
816       wantColorBits = 32;
817     }
818     PUSH2(oGLXAttr, GLX_BUFFER_SIZE, wantColorBits);
819     TRACE("pAttr[%d] = WGL_COLOR_BITS_ARB: %d\n", cur, wantColorBits);
820   }
821
822   /* Apply the OR'd drawable type bitmask now. */
823   if (drawattrib) {
824     PUSH2(oGLXAttr, GLX_DRAWABLE_TYPE, drawattrib);
825     TRACE("pAttr[?] = GLX_DRAWABLE_TYPE: %#x\n", drawattrib);
826   }
827
828   return nAttribs;
829 }
830
831 static int get_render_type_from_fbconfig(Display *display, GLXFBConfig fbconfig)
832 {
833     int render_type=0, render_type_bit;
834     pglXGetFBConfigAttrib(display, fbconfig, GLX_RENDER_TYPE, &render_type_bit);
835     switch(render_type_bit)
836     {
837         case GLX_RGBA_BIT:
838             render_type = GLX_RGBA_TYPE;
839             break;
840         case GLX_COLOR_INDEX_BIT:
841             render_type = GLX_COLOR_INDEX_TYPE;
842             break;
843         case GLX_RGBA_FLOAT_BIT_ARB:
844             render_type = GLX_RGBA_FLOAT_TYPE_ARB;
845             break;
846         default:
847             ERR("Unknown render_type: %x\n", render_type);
848     }
849     return render_type;
850 }
851
852 static BOOL get_fbconfig_from_visualid(Display *display, Visual *visual, GLXFBConfig *fbconfig, int *fmt_id)
853 {
854     GLXFBConfig* cfgs = NULL;
855     int i;
856     int nCfgs;
857     int tmp_fmt_id;
858     int tmp_vis_id;
859     VisualID visualid;
860
861     if(!display || !visual) {
862         ERR("Invalid display or visual\n");
863         return FALSE;
864     }
865     visualid = XVisualIDFromVisual(visual);
866
867     /* Get a list of all available framebuffer configurations */
868     cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
869     if (NULL == cfgs || 0 == nCfgs) {
870         ERR("glXChooseFBConfig returns NULL\n");
871         if(cfgs != NULL) XFree(cfgs);
872         return FALSE;
873     }
874
875     /* Find the requested offscreen format and count the number of offscreen formats */
876     for(i=0; i<nCfgs; i++) {
877         pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id);
878         pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id);
879
880         /* We are looking up the GLX index of our main visual and have found it :) */
881         if(visualid == tmp_vis_id) {
882             TRACE("Found FBCONFIG_ID 0x%x at index %d for VISUAL_ID 0x%x\n", tmp_fmt_id, i, tmp_vis_id);
883             *fbconfig = cfgs[i];
884             *fmt_id = tmp_fmt_id;
885             XFree(cfgs);
886             return TRUE;
887         }
888     }
889
890     ERR("No fbconfig found for Wine's main visual (0x%lx), expect problems!\n", visualid);
891     XFree(cfgs);
892     return FALSE;
893 }
894
895 static BOOL init_formats(Display *display, int screen, Visual *visual)
896 {
897     int fmt_id, tmp_vis_id, tmp_fmt_id, nCfgs, i;
898     GLXFBConfig* cfgs;
899     GLXFBConfig fbconfig;
900     int nOffscreenFormats = 0;
901
902     /* Locate the fbconfig correspondig to our main visual */
903     if(!get_fbconfig_from_visualid(display, visual, &fbconfig, &fmt_id)) {
904         ERR("Can't get the FBCONFIG_ID for the main visual, expect problems!\n");
905         return FALSE;
906     }
907
908     /* As mentioned in various parts of the code only the format of the main visual can be used for onscreen rendering.
909     * Next to this format there are also so called offscreen rendering formats (used for pbuffers) which can be supported
910     * because they don't need a visual. Below we use glXGetFBConfigs instead of glXChooseFBConfig to enumerate the fb configurations
911     * because this call lists both types of formats instead of only onscreen ones. */
912     cfgs = pglXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
913     if (NULL == cfgs || 0 == nCfgs) {
914         WARN("glXChooseFBConfig returns NULL\n");
915         if(cfgs != NULL) XFree(cfgs);
916
917         /* We only have the single format of Wine's main visual */
918         WineGLPixelFormatList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WineGLPixelFormat));
919         WineGLPixelFormatList[0].iPixelFormat = 1;
920         WineGLPixelFormatList[0].fbconfig = fbconfig;
921         WineGLPixelFormatList[0].fmt_id = fmt_id;
922         WineGLPixelFormatList[0].render_type = get_render_type_from_fbconfig(display, fbconfig);
923         WineGLPixelFormatList[0].offscreenOnly = FALSE;
924         WineGLPixelFormatListSize = 1;
925     }
926     else {
927         /* Count the number of offscreen formats to determine the size for our pixelformat list */
928         for(i=0; i<nCfgs; i++) {
929             pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id);
930
931             /* We have found an offscreen rendering format :) */
932             if(tmp_vis_id == 0) {
933                 nOffscreenFormats++;
934             }
935         }
936         TRACE("Number of offscreen formats: %d\n", nOffscreenFormats);
937
938         /* Allocate memory for all the offscreen pixelformats and the format of Wine's main visual */
939         WineGLPixelFormatList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (1+nOffscreenFormats)*sizeof(WineGLPixelFormat));
940         WineGLPixelFormatList[0].iPixelFormat = 1;
941         WineGLPixelFormatList[0].fbconfig = fbconfig;
942         WineGLPixelFormatList[0].fmt_id = fmt_id;
943         WineGLPixelFormatList[0].render_type = get_render_type_from_fbconfig(display, fbconfig);
944         WineGLPixelFormatList[0].offscreenOnly = FALSE;
945         WineGLPixelFormatListSize = 1;
946
947         /* Fill the list with offscreen formats */
948         for(i=0; i<nCfgs; i++) {
949             pglXGetFBConfigAttrib(display, cfgs[i], GLX_VISUAL_ID, &tmp_vis_id);
950             pglXGetFBConfigAttrib(display, cfgs[i], GLX_FBCONFIG_ID, &tmp_fmt_id);
951
952             /* We have found an offscreen rendering format :) */
953             if(tmp_vis_id == 0) {
954                 TRACE("Found offscreen format FBCONFIG_ID 0x%x corresponding to iPixelFormat %d at GLX index %d\n", tmp_fmt_id, WineGLPixelFormatListSize+1, i);
955                 WineGLPixelFormatList[WineGLPixelFormatListSize].iPixelFormat = WineGLPixelFormatListSize+1; /* The index starts at 1 */
956                 WineGLPixelFormatList[WineGLPixelFormatListSize].fbconfig = cfgs[i];
957                 WineGLPixelFormatList[WineGLPixelFormatListSize].fmt_id = tmp_fmt_id;
958                 WineGLPixelFormatList[WineGLPixelFormatListSize].render_type = get_render_type_from_fbconfig(display, cfgs[i]);
959                 WineGLPixelFormatList[WineGLPixelFormatListSize].offscreenOnly = TRUE;
960                 WineGLPixelFormatListSize++;
961             }
962         }
963     }
964
965     if(cfgs != NULL) XFree(cfgs);
966
967     return TRUE;
968 }
969
970 /* GLX can advertise dozens of different pixelformats including offscreen and onscreen ones.
971  * In our WGL implementation we only support a subset of these formats namely the format of
972  * Wine's main visual and offscreen formats (if they are available).
973  * This function converts a WGL format to its corresponding GLX one. It returns a WineGLPixelFormat
974  * and it returns the number of supported WGL formats in fmt_count.
975  */
976 static WineGLPixelFormat* ConvertPixelFormatWGLtoGLX(Display *display, int iPixelFormat, BOOL AllowOffscreen, int *fmt_count)
977 {
978     WineGLPixelFormat *res = NULL;
979
980     /* Init the list of pixel formats when we need it */
981     if(!WineGLPixelFormatListSize)
982         init_formats(display, DefaultScreen(display), visual);
983
984     /* Check if the pixelformat is valid. Note that it is legal to pass an invalid
985      * iPixelFormat in case of probing the number of pixelformats.
986      */
987     if((iPixelFormat <= 0) || (iPixelFormat > WineGLPixelFormatListSize)) {
988         ERR("invalid iPixelFormat %d\n", iPixelFormat);
989         if(AllowOffscreen)
990             *fmt_count = WineGLPixelFormatListSize;
991         else
992             *fmt_count = 1; /* Only show the format of our main visual */
993     }
994     else if(iPixelFormat == 1) {
995         res = &WineGLPixelFormatList[0];
996         *fmt_count = 1; /* Only show the format of our main visual */
997     }
998     else if((WineGLPixelFormatList[iPixelFormat-1].offscreenOnly == TRUE) && AllowOffscreen) {
999         res = &WineGLPixelFormatList[iPixelFormat-1];
1000         *fmt_count = WineGLPixelFormatListSize;
1001         TRACE("Returning FBConfig=%p for iPixelFormat=%d\n", res->fbconfig, iPixelFormat);
1002     }
1003
1004     TRACE("Number of returned pixelformats=%d\n", *fmt_count);
1005
1006     return res;
1007 }
1008
1009 /* Search our internal pixelformat list for the WGL format corresponding to the given fbconfig */
1010 static int ConvertPixelFormatGLXtoWGL(Display *display, int fmt_id)
1011 {
1012     int i;
1013
1014     /* Init the list of pixel formats when we need it */
1015     if(!WineGLPixelFormatListSize)
1016         init_formats(display, DefaultScreen(display), visual);
1017
1018     for(i=0; i<WineGLPixelFormatListSize; i++) {
1019         if(WineGLPixelFormatList[i].fmt_id == fmt_id) {
1020             TRACE("Returning iPixelFormat %d for fmt_id 0x%x\n", WineGLPixelFormatList[i].iPixelFormat, fmt_id);
1021             return WineGLPixelFormatList[i].iPixelFormat;
1022         }
1023     }
1024     TRACE("No compatible format found for fmt_id 0x%x\n", fmt_id);
1025     return 0;
1026 }
1027
1028 /**
1029  * X11DRV_ChoosePixelFormat
1030  *
1031  * Equivalent to glXChooseVisual.
1032  */
1033 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev, 
1034                              const PIXELFORMATDESCRIPTOR *ppfd) {
1035   WineGLPixelFormat *fmt;
1036   int ret = 0;
1037   int value = 0;
1038
1039   if (!has_opengl()) {
1040     ERR("No libGL on this box - disabling OpenGL support !\n");
1041     return 0;
1042   }
1043
1044   if (TRACE_ON(opengl)) {
1045     TRACE("(%p,%p)\n", physDev, ppfd);
1046
1047     dump_PIXELFORMATDESCRIPTOR((const PIXELFORMATDESCRIPTOR *) ppfd);
1048   }
1049
1050   wine_tsx11_lock(); 
1051   if(!visual) {
1052     ERR("Can't get an opengl visual!\n");
1053     goto choose_exit;
1054   }
1055
1056   fmt = ConvertPixelFormatWGLtoGLX(gdi_display, 1 /* main visual */, FALSE /* offscreen */, &value);
1057   /* In case an fbconfig was found, check if it matches to the requirements of the ppfd */
1058   if(!fmt) {
1059     ERR("Can't find a matching FBCONFIG_ID for VISUAL_ID 0x%lx!\n", visual->visualid);
1060   } else {
1061     int dwFlags = 0;
1062     int iPixelType = 0;
1063     int value = 0;
1064
1065     /* Pixel type */
1066     pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1067     if (value & GLX_RGBA_BIT)
1068       iPixelType = PFD_TYPE_RGBA;
1069     else
1070       iPixelType = PFD_TYPE_COLORINDEX;
1071
1072     if (ppfd->iPixelType != iPixelType) {
1073       TRACE("pixel type mismatch\n");
1074       goto choose_exit;
1075     }
1076
1077     /* Doublebuffer */
1078     pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value); if (value) dwFlags |= PFD_DOUBLEBUFFER;
1079     if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) && (ppfd->dwFlags & PFD_DOUBLEBUFFER)) {
1080       if (!(dwFlags & PFD_DOUBLEBUFFER)) {
1081         TRACE("dbl buffer mismatch\n");
1082         goto choose_exit;
1083       }
1084     }
1085
1086     /* Stereo */
1087     pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) dwFlags |= PFD_STEREO;
1088     if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE) && (ppfd->dwFlags & PFD_STEREO)) {
1089       if (!(dwFlags & PFD_STEREO)) {
1090         TRACE("stereo mismatch\n");
1091         goto choose_exit;
1092       }
1093     }
1094
1095     /* Alpha bits */
1096     pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &value);
1097     if (ppfd->iPixelType==PFD_TYPE_RGBA && ppfd->cAlphaBits && !value) {
1098       TRACE("alpha mismatch\n");
1099       goto choose_exit;
1100     }
1101
1102     /* Depth bits */
1103     pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1104     if (ppfd->cDepthBits && !value) {
1105       TRACE("depth mismatch\n");
1106       goto choose_exit;
1107     }
1108
1109     /* Stencil bits */
1110     pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1111     if (ppfd->cStencilBits && !value) {
1112       TRACE("stencil mismatch\n");
1113       goto choose_exit;
1114     }
1115
1116     /* Aux buffers */
1117     pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_AUX_BUFFERS, &value);
1118     if (ppfd->cAuxBuffers && !value) {
1119       TRACE("aux mismatch\n");
1120       goto choose_exit;
1121     }
1122
1123     /* When we pass all the checks we have found a matching format :) */
1124     ret = 1;
1125     TRACE("Successfully found a matching mode, returning index: %d\n", ret);
1126   }
1127
1128 choose_exit:
1129   if(!ret)
1130     TRACE("No matching mode was found returning 0\n");
1131
1132   wine_tsx11_unlock();
1133   return ret;
1134 }
1135
1136 /**
1137  * X11DRV_DescribePixelFormat
1138  *
1139  * Get the pixel-format descriptor associated to the given id
1140  */
1141 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
1142                                int iPixelFormat,
1143                                UINT nBytes,
1144                                PIXELFORMATDESCRIPTOR *ppfd) {
1145   /*XVisualInfo *vis;*/
1146   int value;
1147   int rb,gb,bb,ab;
1148   WineGLPixelFormat *fmt;
1149   int ret = 0;
1150   int fmt_count = 0;
1151
1152   if (!has_opengl()) {
1153     ERR("No libGL on this box - disabling OpenGL support !\n");
1154     return 0;
1155   }
1156   
1157   TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
1158
1159   /* 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 */
1160   fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &fmt_count);
1161   if (ppfd == NULL) {
1162       /* The application is only querying the number of pixelformats */
1163       return fmt_count;
1164   } else if(fmt == NULL) {
1165       WARN("unexpected iPixelFormat(%d): not >=1 and <=nFormats(%d), returning NULL!\n", iPixelFormat, fmt_count);
1166       return 0;
1167   }
1168
1169   if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
1170     ERR("Wrong structure size !\n");
1171     /* Should set error */
1172     return 0;
1173   }
1174
1175   ret = fmt_count;
1176
1177   memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
1178   ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
1179   ppfd->nVersion = 1;
1180
1181   /* These flags are always the same... */
1182   ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
1183   /* Now the flags extracted from the Visual */
1184
1185   wine_tsx11_lock();
1186
1187   pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_CONFIG_CAVEAT, &value);
1188   if(value == GLX_SLOW_CONFIG)
1189       ppfd->dwFlags |= PFD_GENERIC_ACCELERATED;
1190
1191   pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DOUBLEBUFFER, &value); if (value) ppfd->dwFlags |= PFD_DOUBLEBUFFER;
1192   pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
1193
1194   /* Pixel type */
1195   pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RENDER_TYPE, &value);
1196   if (value & GLX_RGBA_BIT)
1197     ppfd->iPixelType = PFD_TYPE_RGBA;
1198   else
1199     ppfd->iPixelType = PFD_TYPE_COLORINDEX;
1200
1201   /* Color bits */
1202   pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, &value);
1203   ppfd->cColorBits = value;
1204
1205   /* Red, green, blue and alpha bits / shifts */
1206   if (ppfd->iPixelType == PFD_TYPE_RGBA) {
1207     pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_RED_SIZE, &rb);
1208     pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_GREEN_SIZE, &gb);
1209     pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BLUE_SIZE, &bb);
1210     pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &ab);
1211
1212     ppfd->cRedBits = rb;
1213     ppfd->cRedShift = gb + bb + ab;
1214     ppfd->cBlueBits = bb;
1215     ppfd->cBlueShift = ab;
1216     ppfd->cGreenBits = gb;
1217     ppfd->cGreenShift = bb + ab;
1218     ppfd->cAlphaBits = ab;
1219     ppfd->cAlphaShift = 0;
1220   } else {
1221     ppfd->cRedBits = 0;
1222     ppfd->cRedShift = 0;
1223     ppfd->cBlueBits = 0;
1224     ppfd->cBlueShift = 0;
1225     ppfd->cGreenBits = 0;
1226     ppfd->cGreenShift = 0;
1227     ppfd->cAlphaBits = 0;
1228     ppfd->cAlphaShift = 0;
1229   }
1230   /* Accums : to do ... */
1231
1232   /* Depth bits */
1233   pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DEPTH_SIZE, &value);
1234   ppfd->cDepthBits = value;
1235
1236   /* stencil bits */
1237   pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_STENCIL_SIZE, &value);
1238   ppfd->cStencilBits = value;
1239
1240   wine_tsx11_unlock();
1241
1242   /* Aux : to do ... */
1243
1244   ppfd->iLayerType = PFD_MAIN_PLANE;
1245
1246   if (TRACE_ON(opengl)) {
1247     dump_PIXELFORMATDESCRIPTOR(ppfd);
1248   }
1249
1250   return ret;
1251 }
1252
1253 /**
1254  * X11DRV_GetPixelFormat
1255  *
1256  * Get the pixel-format id used by this DC
1257  */
1258 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
1259   TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
1260
1261   return physDev->current_pf;
1262 }
1263
1264 /**
1265  * X11DRV_SetPixelFormat
1266  *
1267  * Set the pixel-format id used by this DC
1268  */
1269 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
1270                            int iPixelFormat,
1271                            const PIXELFORMATDESCRIPTOR *ppfd) {
1272   WineGLPixelFormat *fmt;
1273   int value;
1274
1275   TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
1276
1277   if (!has_opengl()) {
1278     ERR("No libGL on this box - disabling OpenGL support !\n");
1279     return 0;
1280   }
1281
1282   /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */
1283   fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value);
1284   if(!fmt) {
1285     ERR("Invalid iPixelFormat: %d\n", iPixelFormat);
1286     return 0;
1287   }
1288
1289   physDev->current_pf = iPixelFormat;
1290
1291   if (TRACE_ON(opengl)) {
1292     int gl_test = 0;
1293
1294     /*
1295      * How to test if hdc current drawable is compatible (visual/FBConfig) ?
1296      *
1297      * in case of root window created HDCs we crash here :(
1298      *
1299     Drawable drawable =  get_drawable( physDev->hdc );
1300     TRACE(" drawable (%p,%p) have :\n", drawable, root_window);
1301     pglXQueryDrawable(gdi_display, drawable, GLX_FBCONFIG_ID, (unsigned int*) &value);
1302     TRACE(" - FBCONFIG_ID as 0x%x\n", tmp);
1303     pglXQueryDrawable(gdi_display, drawable, GLX_VISUAL_ID, (unsigned int*) &value);
1304     TRACE(" - VISUAL_ID as 0x%x\n", tmp);
1305     pglXQueryDrawable(gdi_display, drawable, GLX_WIDTH, (unsigned int*) &value);
1306     TRACE(" - WIDTH as %d\n", tmp);
1307     pglXQueryDrawable(gdi_display, drawable, GLX_HEIGHT, (unsigned int*) &value);
1308     TRACE(" - HEIGHT as %d\n", tmp);
1309     */
1310     gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1311     if (gl_test) {
1312       ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1313     } else {
1314       TRACE(" FBConfig have :\n");
1315       TRACE(" - FBCONFIG_ID   0x%x\n", value);
1316       pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_VISUAL_ID, &value);
1317       TRACE(" - VISUAL_ID     0x%x\n", value);
1318       pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value);
1319       TRACE(" - DRAWABLE_TYPE 0x%x\n", value);
1320     }
1321   }
1322   return TRUE;
1323 }
1324
1325 /**
1326  * X11DRV_wglCreateContext
1327  *
1328  * For OpenGL32 wglCreateContext.
1329  */
1330 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev)
1331 {
1332     Wine_GLContext *ret;
1333     WineGLPixelFormat *fmt;
1334     int hdcPF = physDev->current_pf;
1335     int fmt_count = 0;
1336     int value = 0;
1337     int gl_test = 0;
1338     HDC hdc = physDev->hdc;
1339
1340     TRACE("(%p)->(PF:%d)\n", hdc, hdcPF);
1341
1342     if (!has_opengl()) {
1343         ERR("No libGL on this box - disabling OpenGL support !\n");
1344         return 0;
1345     }
1346
1347     /* First, get the visual in use by the X11DRV */
1348     if (!gdi_display) return 0;
1349
1350     fmt = ConvertPixelFormatWGLtoGLX(gdi_display, hdcPF, TRUE /* Offscreen */, &fmt_count);
1351     /* We can render using the iPixelFormat (1) of Wine's Main visual AND using some offscreen formats.
1352      * Note that standard WGL-calls don't recognize offscreen-only formats. For that reason pbuffers
1353      * use a sort of 'proxy' HDC (wglGetPbufferDCARB).
1354      * If this fails something is very wrong on the system. */
1355     if(!fmt) {
1356         ERR("Cannot get FB Config for iPixelFormat %d, expect problems!\n", hdcPF);
1357         SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1358         return NULL;
1359     }
1360
1361     if (fmt_count < hdcPF) {
1362         ERR("(%p): unexpected pixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, hdcPF, fmt_count);
1363         SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1364         return NULL;
1365     }
1366
1367     gl_test = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_FBCONFIG_ID, &value);
1368     if (gl_test) {
1369         ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
1370         SetLastError(ERROR_INVALID_PIXEL_FORMAT);
1371         return NULL;
1372     }
1373
1374     /* The context will be allocated in the wglMakeCurrent call */
1375     wine_tsx11_lock();
1376     ret = alloc_context();
1377     wine_tsx11_unlock();
1378     ret->hdc = hdc;
1379     ret->physDev = physDev;
1380     ret->fmt = fmt;
1381
1382     /*ret->vis = vis;*/
1383     ret->vis = pglXGetVisualFromFBConfig(gdi_display, fmt->fbconfig);
1384
1385     TRACE(" creating context %p (GL context creation delayed)\n", ret);
1386     return (HGLRC) ret;
1387 }
1388
1389 /**
1390  * X11DRV_wglDeleteContext
1391  *
1392  * For OpenGL32 wglDeleteContext.
1393  */
1394 BOOL X11DRV_wglDeleteContext(HGLRC hglrc)
1395 {
1396     Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1397     BOOL ret = TRUE;
1398
1399     TRACE("(%p)\n", hglrc);
1400
1401     if (!has_opengl()) {
1402         ERR("No libGL on this box - disabling OpenGL support !\n");
1403         return 0;
1404     }
1405
1406     wine_tsx11_lock();
1407     /* A game (Half Life not to name it) deletes twice the same context,
1408     * so make sure it is valid first */
1409     if (is_valid_context( ctx ))
1410     {
1411         if (ctx->ctx) pglXDestroyContext(gdi_display, ctx->ctx);
1412         free_context(ctx);
1413     }
1414     else
1415     {
1416         WARN("Error deleting context !\n");
1417         SetLastError(ERROR_INVALID_HANDLE);
1418         ret = FALSE;
1419     }
1420     wine_tsx11_unlock();
1421
1422     return ret;
1423 }
1424
1425 /**
1426  * X11DRV_wglGetCurrentReadDCARB
1427  *
1428  * For OpenGL32 wglGetCurrentReadDCARB.
1429  */
1430 static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void) 
1431 {
1432     GLXDrawable gl_d;
1433     HDC ret;
1434
1435     TRACE("()\n");
1436
1437     wine_tsx11_lock();
1438     gl_d = pglXGetCurrentReadDrawable();
1439     ret = get_hdc_from_Drawable(gl_d);
1440     wine_tsx11_unlock();
1441
1442     TRACE(" returning %p (GL drawable %lu)\n", ret, gl_d);
1443     return ret;
1444 }
1445
1446 /**
1447  * X11DRV_wglGetProcAddress
1448  *
1449  * For OpenGL32 wglGetProcAddress.
1450  */
1451 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc)
1452 {
1453     int i, j;
1454     const WineGLExtension *ext;
1455
1456     int padding = 32 - strlen(lpszProc);
1457     if (padding < 0)
1458         padding = 0;
1459
1460     if (!has_opengl()) {
1461         ERR("No libGL on this box - disabling OpenGL support !\n");
1462         return 0;
1463     }
1464
1465     /* Check the table of WGL extensions to see if we need to return a WGL extension
1466      * or a function pointer to a native OpenGL function. */
1467     if(strncmp(lpszProc, "wgl", 3) != 0) {
1468         return pglXGetProcAddressARB((const GLubyte*)lpszProc);
1469     } else {
1470         TRACE("('%s'):%*s", lpszProc, padding, " ");
1471         for (i = 0; i < WineGLExtensionListSize; ++i) {
1472             ext = WineGLExtensionList[i];
1473             for (j = 0; ext->extEntryPoints[j].funcName; ++j) {
1474                 if (strcmp(ext->extEntryPoints[j].funcName, lpszProc) == 0) {
1475                     TRACE("(%p) - WineGL\n", ext->extEntryPoints[j].funcAddress);
1476                     return ext->extEntryPoints[j].funcAddress;
1477                 }
1478             }
1479         }
1480     }
1481
1482     ERR("(%s) - not found\n", lpszProc);
1483     return NULL;
1484 }
1485
1486 /***********************************************************************
1487  *              sync_current_drawable
1488  *
1489  * Adjust the current viewport and scissor in order to position
1490  * and size the current drawable correctly on the parent window.
1491  */
1492 static void sync_current_drawable(BOOL updatedc)
1493 {
1494     int dy;
1495     int width;
1496     int height;
1497     RECT rc;
1498     Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1499
1500     TRACE("\n");
1501
1502     if (ctx && ctx->physDev)
1503     {
1504         if (updatedc)
1505             GetClipBox(ctx->physDev->hdc, &rc); /* Make sure physDev is up to date */
1506
1507         dy = ctx->physDev->drawable_rect.bottom - ctx->physDev->drawable_rect.top -
1508             ctx->physDev->dc_rect.bottom;
1509         width = ctx->physDev->dc_rect.right - ctx->physDev->dc_rect.left;
1510         height = ctx->physDev->dc_rect.bottom - ctx->physDev->dc_rect.top;
1511
1512         wine_tsx11_lock();
1513
1514         pglViewport(ctx->physDev->dc_rect.left + ctx->viewport.left,
1515             dy + ctx->viewport.top,
1516             ctx->viewport.right ? (ctx->viewport.right - ctx->viewport.left) : width,
1517             ctx->viewport.bottom ? (ctx->viewport.bottom - ctx->viewport.top) : height);
1518
1519         pglEnable(GL_SCISSOR_TEST);
1520
1521         if (ctx->scissor_enabled)
1522             pglScissor(ctx->physDev->dc_rect.left + min(width, max(0, ctx->scissor.left)),
1523                 dy + min(height, max(0, ctx->scissor.top)),
1524                 min(width, max(0, ctx->scissor.right - ctx->scissor.left)),
1525                 min(height, max(0, ctx->scissor.bottom - ctx->scissor.top)));
1526         else
1527             pglScissor(ctx->physDev->dc_rect.left, dy, width, height);
1528
1529         wine_tsx11_unlock();
1530     }
1531 }
1532
1533 /**
1534  * X11DRV_wglMakeCurrent
1535  *
1536  * For OpenGL32 wglMakeCurrent.
1537  */
1538 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
1539     BOOL ret;
1540     HDC hdc = physDev->hdc;
1541     DWORD type = GetObjectType(hdc);
1542
1543     TRACE("(%p,%p)\n", hdc, hglrc);
1544
1545     if (!has_opengl()) {
1546         ERR("No libGL on this box - disabling OpenGL support !\n");
1547         return 0;
1548     }
1549
1550     wine_tsx11_lock();
1551     if (hglrc == NULL) {
1552         ret = pglXMakeCurrent(gdi_display, None, NULL);
1553         NtCurrentTeb()->glContext = NULL;
1554     } else {
1555         Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1556         Drawable drawable = get_glxdrawable(physDev);
1557         if (ctx->ctx == NULL) {
1558             /* The describe lines below are for debugging purposes only */
1559             if (TRACE_ON(wgl)) {
1560                 describeDrawable(ctx, drawable);
1561                 describeContext(ctx);
1562             }
1563
1564             /* Create a GLX context using the same visual as chosen earlier in wglCreateContext.
1565              * We are certain that the drawable and context are compatible as we only allow compatible formats.
1566              */
1567             TRACE(" Creating GLX Context\n");
1568             if(ctx->vis)
1569                 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, type == OBJ_MEMDC ? False : True);
1570             else /* Create a GLX Context for a pbuffer */
1571                 ctx->ctx = pglXCreateNewContext(gdi_display, ctx->fmt->fbconfig, ctx->fmt->render_type, NULL, True);
1572
1573             TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1574         }
1575         TRACE(" make current for dis %p, drawable %p, ctx %p\n", gdi_display, (void*) drawable, ctx->ctx);
1576         ret = pglXMakeCurrent(gdi_display, drawable, ctx->ctx);
1577         NtCurrentTeb()->glContext = ctx;
1578         if(ret)
1579         {
1580             ctx->physDev = physDev;
1581
1582             if (type == OBJ_MEMDC)
1583             {
1584                 ctx->do_escape = TRUE;
1585                 pglDrawBuffer(GL_FRONT_LEFT);
1586             }
1587             else
1588             {
1589                 sync_current_drawable(FALSE);
1590             }
1591         }
1592     }
1593     wine_tsx11_unlock();
1594     TRACE(" returning %s\n", (ret ? "True" : "False"));
1595     return ret;
1596 }
1597
1598 /**
1599  * X11DRV_wglMakeContextCurrentARB
1600  *
1601  * For OpenGL32 wglMakeContextCurrentARB
1602  */
1603 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) 
1604 {
1605     BOOL ret;
1606     TRACE("(%p,%p,%p)\n", hDrawDev, hReadDev, hglrc);
1607
1608     if (!has_opengl()) {
1609         ERR("No libGL on this box - disabling OpenGL support !\n");
1610         return 0;
1611     }
1612
1613     wine_tsx11_lock();
1614     if (hglrc == NULL) {
1615         ret = pglXMakeCurrent(gdi_display, None, NULL);
1616         NtCurrentTeb()->glContext = NULL;
1617     } else {
1618         if (NULL == pglXMakeContextCurrent) {
1619             ret = FALSE;
1620         } else {
1621             Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
1622             Drawable d_draw = get_glxdrawable(hDrawDev);
1623             Drawable d_read = get_glxdrawable(hReadDev);
1624
1625             if (ctx->ctx == NULL) {
1626                 ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, GetObjectType(hDrawDev->hdc) == OBJ_MEMDC ? False : True);
1627                 TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx);
1628             }
1629             ret = pglXMakeContextCurrent(gdi_display, d_draw, d_read, ctx->ctx);
1630             NtCurrentTeb()->glContext = ctx;
1631         }
1632     }
1633     wine_tsx11_unlock();
1634
1635     TRACE(" returning %s\n", (ret ? "True" : "False"));
1636     return ret;
1637 }
1638
1639 /**
1640  * X11DRV_wglShareLists
1641  *
1642  * For OpenGL32 wglShaderLists.
1643  */
1644 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
1645     Wine_GLContext *org  = (Wine_GLContext *) hglrc1;
1646     Wine_GLContext *dest = (Wine_GLContext *) hglrc2;
1647
1648     TRACE("(%p, %p)\n", org, dest);
1649
1650     if (!has_opengl()) {
1651         ERR("No libGL on this box - disabling OpenGL support !\n");
1652         return 0;
1653     }
1654
1655     if (NULL != dest && dest->ctx != NULL) {
1656         ERR("Could not share display lists, context already created !\n");
1657         return FALSE;
1658     } else {
1659         if (org->ctx == NULL) {
1660             wine_tsx11_lock();
1661             describeContext(org);
1662
1663             if(org->vis)
1664                 org->ctx = pglXCreateContext(gdi_display, org->vis, NULL, GetObjectType(org->physDev->hdc) == OBJ_MEMDC ? False : True);
1665             else /* Create a GLX Context for a pbuffer */
1666                 org->ctx = pglXCreateNewContext(gdi_display, org->fmt->fbconfig, org->fmt->render_type, NULL, True);
1667             wine_tsx11_unlock();
1668             TRACE(" created a delayed OpenGL context (%p) for Wine context %p\n", org->ctx, org);
1669         }
1670         if (NULL != dest) {
1671             wine_tsx11_lock();
1672             describeContext(dest);
1673             /* Create the destination context with display lists shared */
1674             if(dest->vis)
1675                 dest->ctx = pglXCreateContext(gdi_display, dest->vis, org->ctx, GetObjectType(org->physDev->hdc) == OBJ_MEMDC ? False : True);
1676             else /* Create a GLX Context for a pbuffer */
1677                 dest->ctx = pglXCreateNewContext(gdi_display, dest->fmt->fbconfig, dest->fmt->render_type, org->ctx, True);
1678             wine_tsx11_unlock();
1679             TRACE(" created a delayed OpenGL context (%p) for Wine context %p sharing lists with OpenGL ctx %p\n", dest->ctx, dest, org->ctx);
1680             return TRUE;
1681         }
1682     }
1683     return FALSE;
1684 }
1685
1686 static BOOL internal_wglUseFontBitmaps(HDC hdc, DWORD first, DWORD count, DWORD listBase, DWORD (WINAPI *GetGlyphOutline_ptr)(HDC,UINT,UINT,LPGLYPHMETRICS,DWORD,LPVOID,const MAT2*))
1687 {
1688      /* We are running using client-side rendering fonts... */
1689      GLYPHMETRICS gm;
1690      unsigned int glyph;
1691      int size = 0;
1692      void *bitmap = NULL, *gl_bitmap = NULL;
1693      int org_alignment;
1694
1695      wine_tsx11_lock();
1696      pglGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1697      pglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1698      wine_tsx11_unlock();
1699
1700      for (glyph = first; glyph < first + count; glyph++) {
1701          unsigned int needed_size = GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, NULL);
1702          int height, width_int;
1703
1704          TRACE("Glyph : %3d / List : %d\n", glyph, listBase);
1705          if (needed_size == GDI_ERROR) {
1706              TRACE("  - needed size : %d (GDI_ERROR)\n", needed_size);
1707              goto error;
1708          } else {
1709              TRACE("  - needed size : %d\n", needed_size);
1710          }
1711
1712          if (needed_size > size) {
1713              size = needed_size;
1714              HeapFree(GetProcessHeap(), 0, bitmap);
1715              HeapFree(GetProcessHeap(), 0, gl_bitmap);
1716              bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1717              gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1718          }
1719          if (GetGlyphOutline_ptr(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, NULL) == GDI_ERROR) goto error;
1720          if (TRACE_ON(opengl)) {
1721              unsigned int height, width, bitmask;
1722              unsigned char *bitmap_ = (unsigned char *) bitmap;
1723
1724              TRACE("  - bbox : %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
1725              TRACE("  - origin : (%d , %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
1726              TRACE("  - increment : %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
1727              if (needed_size != 0) {
1728                  TRACE("  - bitmap :\n");
1729                  for (height = 0; height < gm.gmBlackBoxY; height++) {
1730                      TRACE("      ");
1731                      for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
1732                          if (bitmask == 0) {
1733                              bitmap_ += 1;
1734                              bitmask = 0x80;
1735                          }
1736                          if (*bitmap_ & bitmask)
1737                              TRACE("*");
1738                          else
1739                              TRACE(" ");
1740                      }
1741                      bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
1742                      TRACE("\n");
1743                  }
1744              }
1745          }
1746
1747          /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1748          * glyph for it to be drawn properly.
1749          */
1750          if (needed_size != 0) {
1751              width_int = (gm.gmBlackBoxX + 31) / 32;
1752              for (height = 0; height < gm.gmBlackBoxY; height++) {
1753                  int width;
1754                  for (width = 0; width < width_int; width++) {
1755                      ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
1756                      ((int *) bitmap)[height * width_int + width];
1757                  }
1758              }
1759          }
1760
1761          wine_tsx11_lock();
1762          pglNewList(listBase++, GL_COMPILE);
1763          if (needed_size != 0) {
1764              pglBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
1765                      0 - (int) gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - (int) gm.gmptGlyphOrigin.y,
1766                      gm.gmCellIncX, gm.gmCellIncY,
1767                      gl_bitmap);
1768          } else {
1769              /* This is the case of 'empty' glyphs like the space character */
1770              pglBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
1771          }
1772          pglEndList();
1773          wine_tsx11_unlock();
1774      }
1775
1776      wine_tsx11_lock();
1777      pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1778      wine_tsx11_unlock();
1779
1780      HeapFree(GetProcessHeap(), 0, bitmap);
1781      HeapFree(GetProcessHeap(), 0, gl_bitmap);
1782      return TRUE;
1783
1784   error:
1785      wine_tsx11_lock();
1786      pglPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1787      wine_tsx11_unlock();
1788
1789      HeapFree(GetProcessHeap(), 0, bitmap);
1790      HeapFree(GetProcessHeap(), 0, gl_bitmap);
1791      return FALSE;
1792 }
1793
1794 /**
1795  * X11DRV_wglUseFontBitmapsA
1796  *
1797  * For OpenGL32 wglUseFontBitmapsA.
1798  */
1799 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1800 {
1801      Font fid = physDev->font;
1802
1803      TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1804
1805      if (!has_opengl()) {
1806         ERR("No libGL on this box - disabling OpenGL support !\n");
1807         return 0;
1808      }
1809
1810      if (fid == 0) {
1811          return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineA);
1812      }
1813
1814      wine_tsx11_lock();
1815      /* I assume that the glyphs are at the same position for X and for Windows */
1816      pglXUseXFont(fid, first, count, listBase);
1817      wine_tsx11_unlock();
1818      return TRUE;
1819 }
1820
1821 /**
1822  * X11DRV_wglUseFontBitmapsW
1823  *
1824  * For OpenGL32 wglUseFontBitmapsW.
1825  */
1826 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
1827 {
1828      Font fid = physDev->font;
1829
1830      TRACE("(%p, %d, %d, %d) using font %ld\n", physDev->hdc, first, count, listBase, fid);
1831
1832      if (!has_opengl()) {
1833         ERR("No libGL on this box - disabling OpenGL support !\n");
1834         return 0;
1835      }
1836
1837      if (fid == 0) {
1838          return internal_wglUseFontBitmaps(physDev->hdc, first, count, listBase, GetGlyphOutlineW);
1839      }
1840
1841      WARN("Using the glX API for the WCHAR variant - some characters may come out incorrectly !\n");
1842
1843      wine_tsx11_lock();
1844      /* I assume that the glyphs are at the same position for X and for Windows */
1845      pglXUseXFont(fid, first, count, listBase);
1846      wine_tsx11_unlock();
1847      return TRUE;
1848 }
1849
1850 static void WINAPI X11DRV_wglDisable(GLenum cap)
1851 {
1852     if (cap == GL_SCISSOR_TEST)
1853     {
1854        Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1855
1856        if (ctx)
1857           ctx->scissor_enabled = FALSE;
1858     }
1859     else
1860     {
1861         wine_tsx11_lock();
1862         pglDisable(cap);
1863         wine_tsx11_unlock();
1864     }
1865 }
1866
1867 static void WINAPI X11DRV_wglEnable(GLenum cap)
1868 {
1869     if (cap == GL_SCISSOR_TEST)
1870     {
1871        Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1872
1873        if (ctx)
1874            ctx->scissor_enabled = TRUE;
1875     }
1876     else
1877     {
1878         wine_tsx11_lock();
1879         pglEnable(cap);
1880         wine_tsx11_unlock();
1881     }
1882 }
1883
1884 /* WGL helper function which handles differences in glGetIntegerv from WGL and GLX */
1885 static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params)
1886 {
1887     wine_tsx11_lock();
1888     switch(pname)
1889     {
1890     case GL_DEPTH_BITS:
1891         {
1892             GLXContext gl_ctx = pglXGetCurrentContext();
1893             Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx);
1894
1895             pglGetIntegerv(pname, params);
1896             /**
1897              * if we cannot find a Wine Context
1898              * we only have the default wine desktop context,
1899              * so if we have only a 24 depth say we have 32
1900              */
1901             if (NULL == ret && 24 == *params) {
1902                 *params = 32;
1903             }
1904             TRACE("returns GL_DEPTH_BITS as '%d'\n", *params);
1905             break;
1906         }
1907     case GL_ALPHA_BITS:
1908         {
1909             GLXContext gl_ctx = pglXGetCurrentContext();
1910             Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx);
1911
1912             pglXGetFBConfigAttrib(gdi_display, ret->fmt->fbconfig, GLX_ALPHA_SIZE, params);
1913             TRACE("returns GL_ALPHA_BITS as '%d'\n", *params);
1914             break;
1915         }
1916     default:
1917         pglGetIntegerv(pname, params);
1918         break;
1919     }
1920     wine_tsx11_unlock();
1921 }
1922
1923 static GLboolean WINAPI X11DRV_wglIsEnabled(GLenum cap)
1924 {
1925     GLboolean enabled = False;
1926
1927     if (cap == GL_SCISSOR_TEST)
1928     {
1929        Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1930
1931        if (ctx)
1932            enabled = ctx->scissor_enabled;
1933     }
1934     else
1935     {
1936         wine_tsx11_lock();
1937         enabled = pglIsEnabled(cap);
1938         wine_tsx11_unlock();
1939     }
1940     return enabled;
1941 }
1942
1943 static void WINAPI X11DRV_wglScissor(GLint x, GLint y, GLsizei width, GLsizei height)
1944 {
1945     Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1946
1947     if (ctx)
1948     {
1949         ctx->scissor.left = x;
1950         ctx->scissor.top = y;
1951         ctx->scissor.right = x + width;
1952         ctx->scissor.bottom = y + height;
1953
1954         sync_current_drawable(TRUE);
1955     }
1956 }
1957
1958 static void WINAPI X11DRV_wglViewport(GLint x, GLint y, GLsizei width, GLsizei height)
1959 {
1960     Wine_GLContext *ctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
1961
1962     if (ctx)
1963     {
1964         ctx->viewport.left = x;
1965         ctx->viewport.top = y;
1966         ctx->viewport.right = x + width;
1967         ctx->viewport.bottom = y + height;
1968
1969         sync_current_drawable(TRUE);
1970     }
1971 }
1972
1973 /**
1974  * X11DRV_wglGetExtensionsStringARB
1975  *
1976  * WGL_ARB_extensions_string: wglGetExtensionsStringARB
1977  */
1978 static const char * WINAPI X11DRV_wglGetExtensionsStringARB(HDC hdc) {
1979     TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
1980     return WineGLInfo.wglExtensions;
1981 }
1982
1983 /**
1984  * X11DRV_wglCreatePbufferARB
1985  *
1986  * WGL_ARB_pbuffer: wglCreatePbufferARB
1987  */
1988 static HPBUFFERARB WINAPI X11DRV_wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
1989 {
1990     Wine_GLPBuffer* object = NULL;
1991     WineGLPixelFormat *fmt = NULL;
1992     int nCfgs = 0;
1993     int attribs[256];
1994     int nAttribs = 0;
1995
1996     TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
1997
1998     if (0 >= iPixelFormat) {
1999         ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
2000         SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2001         return NULL; /* unexpected error */
2002     }
2003
2004     /* Convert the WGL pixelformat to a GLX format, if it fails then the format is invalid */
2005     fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nCfgs);
2006     if(!fmt) {
2007         ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
2008         SetLastError(ERROR_INVALID_PIXEL_FORMAT);
2009         goto create_failed; /* unexpected error */
2010     }
2011
2012     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
2013     if (NULL == object) {
2014         SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2015         goto create_failed; /* unexpected error */
2016     }
2017     object->hdc = hdc;
2018     object->display = gdi_display;
2019     object->width = iWidth;
2020     object->height = iHeight;
2021     object->fmt = fmt;
2022
2023     nAttribs = ConvertAttribWGLtoGLX(piAttribList, attribs, object);
2024     if (-1 == nAttribs) {
2025         WARN("Cannot convert WGL to GLX attributes\n");
2026         goto create_failed;
2027     }
2028     PUSH2(attribs, GLX_PBUFFER_WIDTH,  iWidth);
2029     PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight); 
2030     while (piAttribList && 0 != *piAttribList) {
2031         int attr_v;
2032         switch (*piAttribList) {
2033             case WGL_TEXTURE_FORMAT_ARB: {
2034                 ++piAttribList;
2035                 attr_v = *piAttribList;
2036                 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
2037                 if (use_render_texture_ati) {
2038                     int type = 0;
2039                     switch (attr_v) {
2040                         case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2041                         case WGL_TEXTURE_RGB_ARB: type = GLX_TEXTURE_RGB_ATI; break ;
2042                         case WGL_TEXTURE_RGBA_ARB: type = GLX_TEXTURE_RGBA_ATI; break ;
2043                         default:
2044                             SetLastError(ERROR_INVALID_DATA);
2045                             goto create_failed;
2046                     }
2047                     object->use_render_texture = 1;
2048                     PUSH2(attribs, GLX_TEXTURE_FORMAT_ATI, type);
2049                 } else {
2050                     if (WGL_NO_TEXTURE_ARB == attr_v) {
2051                         object->use_render_texture = 0;
2052                     } else {
2053                         if (!use_render_texture_emulation) {
2054                             SetLastError(ERROR_INVALID_DATA);
2055                             goto create_failed;
2056                         }
2057                         switch (attr_v) {
2058                             case WGL_TEXTURE_RGB_ARB:
2059                                 object->use_render_texture = GL_RGB;
2060                                 object->texture_bpp = 3;
2061                                 object->texture_format = GL_RGB;
2062                                 object->texture_type = GL_UNSIGNED_BYTE;
2063                                 break;
2064                             case WGL_TEXTURE_RGBA_ARB:
2065                                 object->use_render_texture = GL_RGBA;
2066                                 object->texture_bpp = 4;
2067                                 object->texture_format = GL_RGBA;
2068                                 object->texture_type = GL_UNSIGNED_BYTE;
2069                                 break;
2070
2071                             /* WGL_FLOAT_COMPONENTS_NV */
2072                             case WGL_TEXTURE_FLOAT_R_NV:
2073                                 object->use_render_texture = GL_FLOAT_R_NV;
2074                                 object->texture_bpp = 4;
2075                                 object->texture_format = GL_RED;
2076                                 object->texture_type = GL_FLOAT;
2077                                 break;
2078                             case WGL_TEXTURE_FLOAT_RG_NV:
2079                                 object->use_render_texture = GL_FLOAT_RG_NV;
2080                                 object->texture_bpp = 8;
2081                                 object->texture_format = GL_LUMINANCE_ALPHA;
2082                                 object->texture_type = GL_FLOAT;
2083                                 break;
2084                             case WGL_TEXTURE_FLOAT_RGB_NV:
2085                                 object->use_render_texture = GL_FLOAT_RGB_NV;
2086                                 object->texture_bpp = 12;
2087                                 object->texture_format = GL_RGB;
2088                                 object->texture_type = GL_FLOAT;
2089                                 break;
2090                             case WGL_TEXTURE_FLOAT_RGBA_NV:
2091                                 object->use_render_texture = GL_FLOAT_RGBA_NV;
2092                                 object->texture_bpp = 16;
2093                                 object->texture_format = GL_RGBA;
2094                                 object->texture_type = GL_FLOAT;
2095                                 break;
2096                             default:
2097                                 ERR("Unknown texture format: %x\n", attr_v);
2098                                 SetLastError(ERROR_INVALID_DATA);
2099                                 goto create_failed;
2100                         }
2101                     }
2102                 }
2103                 break;
2104             }
2105
2106             case WGL_TEXTURE_TARGET_ARB: {
2107                 ++piAttribList;
2108                 attr_v = *piAttribList;
2109                 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
2110                 if (use_render_texture_ati) {
2111                     int type = 0;
2112                     switch (attr_v) {
2113                         case WGL_NO_TEXTURE_ARB: type = GLX_NO_TEXTURE_ATI; break ;
2114                         case WGL_TEXTURE_CUBE_MAP_ARB: type = GLX_TEXTURE_CUBE_MAP_ATI; break ;
2115                         case WGL_TEXTURE_1D_ARB: type = GLX_TEXTURE_1D_ATI; break ;
2116                         case WGL_TEXTURE_2D_ARB: type = GLX_TEXTURE_2D_ATI; break ;
2117                         default:
2118                             SetLastError(ERROR_INVALID_DATA);
2119                             goto create_failed;
2120                     }
2121                     PUSH2(attribs, GLX_TEXTURE_TARGET_ATI, type);
2122                 } else {
2123                     if (WGL_NO_TEXTURE_ARB == attr_v) {
2124                         object->texture_target = 0;
2125                     } else {
2126                         if (!use_render_texture_emulation) {
2127                             SetLastError(ERROR_INVALID_DATA);
2128                             goto create_failed;
2129                         }
2130                         switch (attr_v) {
2131                             case WGL_TEXTURE_CUBE_MAP_ARB: {
2132                                 if (iWidth != iHeight) {
2133                                     SetLastError(ERROR_INVALID_DATA);
2134                                     goto create_failed;
2135                                 }
2136                                 object->texture_target = GL_TEXTURE_CUBE_MAP;
2137                                 object->texture_bind_target = GL_TEXTURE_CUBE_MAP;
2138                                break;
2139                             }
2140                             case WGL_TEXTURE_1D_ARB: {
2141                                 if (1 != iHeight) {
2142                                     SetLastError(ERROR_INVALID_DATA);
2143                                     goto create_failed;
2144                                 }
2145                                 object->texture_target = GL_TEXTURE_1D;
2146                                 object->texture_bind_target = GL_TEXTURE_1D;
2147                                 break;
2148                             }
2149                             case WGL_TEXTURE_2D_ARB: {
2150                                 object->texture_target = GL_TEXTURE_2D;
2151                                 object->texture_bind_target = GL_TEXTURE_2D;
2152                                 break;
2153                             }
2154                             case WGL_TEXTURE_RECTANGLE_NV: {
2155                                 object->texture_target = GL_TEXTURE_RECTANGLE_NV;
2156                                 object->texture_bind_target = GL_TEXTURE_BINDING_RECTANGLE_NV;
2157                                 break;
2158                             }
2159                             default:
2160                                 ERR("Unknown texture target: %x\n", attr_v);
2161                                 SetLastError(ERROR_INVALID_DATA);
2162                                 goto create_failed;
2163                         }
2164                     }
2165                 }
2166                 break;
2167             }
2168
2169             case WGL_MIPMAP_TEXTURE_ARB: {
2170                 ++piAttribList;
2171                 attr_v = *piAttribList;
2172                 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
2173                 if (use_render_texture_ati) {
2174                     PUSH2(attribs, GLX_MIPMAP_TEXTURE_ATI, attr_v);
2175                 } else {
2176                     if (!use_render_texture_emulation) {
2177                         SetLastError(ERROR_INVALID_DATA);
2178                         goto create_failed;
2179                     }
2180                 }
2181                 break;
2182             }
2183         }
2184         ++piAttribList;
2185     }
2186
2187     PUSH1(attribs, None);
2188     object->drawable = pglXCreatePbuffer(gdi_display, fmt->fbconfig, attribs);
2189     TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
2190     if (!object->drawable) {
2191         SetLastError(ERROR_NO_SYSTEM_RESOURCES);
2192         goto create_failed; /* unexpected error */
2193     }
2194     TRACE("->(%p)\n", object);
2195     return (HPBUFFERARB) object;
2196
2197 create_failed:
2198     HeapFree(GetProcessHeap(), 0, object);
2199     TRACE("->(FAILED)\n");
2200     return (HPBUFFERARB) NULL;
2201 }
2202
2203 /**
2204  * X11DRV_wglDestroyPbufferARB
2205  *
2206  * WGL_ARB_pbuffer: wglDestroyPbufferARB
2207  */
2208 static GLboolean WINAPI X11DRV_wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
2209 {
2210     Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2211     TRACE("(%p)\n", hPbuffer);
2212     if (NULL == object) {
2213         SetLastError(ERROR_INVALID_HANDLE);
2214         return GL_FALSE;
2215     }
2216     pglXDestroyPbuffer(object->display, object->drawable);
2217     HeapFree(GetProcessHeap(), 0, object);
2218     return GL_TRUE;
2219 }
2220
2221 /**
2222  * X11DRV_wglGetPbufferDCARB
2223  *
2224  * WGL_ARB_pbuffer: wglGetPbufferDCARB
2225  * The function wglGetPbufferDCARB returns a device context for a pbuffer.
2226  * Gdi32 implements the part of this function which creates a device context.
2227  * This part associates the physDev with the X drawable of the pbuffer.
2228  */
2229 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *physDev, HPBUFFERARB hPbuffer)
2230 {
2231     Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2232     if (NULL == object) {
2233         SetLastError(ERROR_INVALID_HANDLE);
2234         return NULL;
2235     }
2236
2237     /* The function wglGetPbufferDCARB returns a DC to which the pbuffer can be connected.
2238      * All formats in our pixelformat list are compatible with each other and the main drawable. */
2239     physDev->current_pf = object->fmt->iPixelFormat;
2240     physDev->drawable = object->drawable;
2241     SetRect( &physDev->drawable_rect, 0, 0, object->width, object->height );
2242     physDev->dc_rect = physDev->drawable_rect;
2243
2244     TRACE("(%p)->(%p)\n", hPbuffer, physDev->hdc);
2245     return physDev->hdc;
2246 }
2247
2248 /**
2249  * X11DRV_wglQueryPbufferARB
2250  *
2251  * WGL_ARB_pbuffer: wglQueryPbufferARB
2252  */
2253 static GLboolean WINAPI X11DRV_wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
2254 {
2255     Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2256     TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
2257     if (NULL == object) {
2258         SetLastError(ERROR_INVALID_HANDLE);
2259         return GL_FALSE;
2260     }
2261     switch (iAttribute) {
2262         case WGL_PBUFFER_WIDTH_ARB:
2263             pglXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
2264             break;
2265         case WGL_PBUFFER_HEIGHT_ARB:
2266             pglXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
2267             break;
2268
2269         case WGL_PBUFFER_LOST_ARB:
2270             FIXME("unsupported WGL_PBUFFER_LOST_ARB (need glXSelectEvent/GLX_DAMAGED work)\n");
2271             break;
2272
2273         case WGL_TEXTURE_FORMAT_ARB:
2274             if (use_render_texture_ati) {
2275                 unsigned int tmp;
2276                 int type = WGL_NO_TEXTURE_ARB;
2277                 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_FORMAT_ATI, &tmp);
2278                 switch (tmp) {
2279                     case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2280                     case GLX_TEXTURE_RGB_ATI: type = WGL_TEXTURE_RGB_ARB; break ;
2281                     case GLX_TEXTURE_RGBA_ATI: type = WGL_TEXTURE_RGBA_ARB; break ;
2282                 }
2283                 *piValue = type;
2284             } else {
2285                 if (!object->use_render_texture) {
2286                     *piValue = WGL_NO_TEXTURE_ARB;
2287                 } else {
2288                     if (!use_render_texture_emulation) {
2289                         SetLastError(ERROR_INVALID_HANDLE);
2290                         return GL_FALSE;
2291                     }
2292                     switch(object->use_render_texture) {
2293                         case GL_RGB:
2294                             *piValue = WGL_TEXTURE_RGB_ARB;
2295                             break;
2296                         case GL_RGBA:
2297                             *piValue = WGL_TEXTURE_RGBA_ARB;
2298                             break;
2299                         /* WGL_FLOAT_COMPONENTS_NV */
2300                         case GL_FLOAT_R_NV:
2301                             *piValue = WGL_TEXTURE_FLOAT_R_NV;
2302                             break;
2303                         case GL_FLOAT_RG_NV:
2304                             *piValue = WGL_TEXTURE_FLOAT_RG_NV;
2305                             break;
2306                         case GL_FLOAT_RGB_NV:
2307                             *piValue = WGL_TEXTURE_FLOAT_RGB_NV;
2308                             break;
2309                         case GL_FLOAT_RGBA_NV:
2310                             *piValue = WGL_TEXTURE_FLOAT_RGBA_NV;
2311                             break;
2312                         default:
2313                             ERR("Unknown texture format: %x\n", object->use_render_texture);
2314                     }
2315                 }
2316             }
2317             break;
2318
2319         case WGL_TEXTURE_TARGET_ARB:
2320             if (use_render_texture_ati) {
2321                 unsigned int tmp;
2322                 int type = WGL_NO_TEXTURE_ARB;
2323                 pglXQueryDrawable(object->display, object->drawable, GLX_TEXTURE_TARGET_ATI, &tmp);
2324                 switch (tmp) {
2325                     case GLX_NO_TEXTURE_ATI: type = WGL_NO_TEXTURE_ARB; break ;
2326                     case GLX_TEXTURE_CUBE_MAP_ATI: type = WGL_TEXTURE_CUBE_MAP_ARB; break ;
2327                     case GLX_TEXTURE_1D_ATI: type = WGL_TEXTURE_1D_ARB; break ;
2328                     case GLX_TEXTURE_2D_ATI: type = WGL_TEXTURE_2D_ARB; break ;
2329                 }
2330                 *piValue = type;
2331             } else {
2332             if (!object->texture_target) {
2333                 *piValue = WGL_NO_TEXTURE_ARB;
2334             } else {
2335                 if (!use_render_texture_emulation) {
2336                     SetLastError(ERROR_INVALID_DATA);      
2337                     return GL_FALSE;
2338                 }
2339                 switch (object->texture_target) {
2340                     case GL_TEXTURE_1D:       *piValue = WGL_TEXTURE_1D_ARB; break;
2341                     case GL_TEXTURE_2D:       *piValue = WGL_TEXTURE_2D_ARB; break;
2342                     case GL_TEXTURE_CUBE_MAP: *piValue = WGL_TEXTURE_CUBE_MAP_ARB; break;
2343                     case GL_TEXTURE_RECTANGLE_NV: *piValue = WGL_TEXTURE_RECTANGLE_NV; break;
2344                 }
2345             }
2346         }
2347         break;
2348
2349     case WGL_MIPMAP_TEXTURE_ARB:
2350         if (use_render_texture_ati) {
2351             pglXQueryDrawable(object->display, object->drawable, GLX_MIPMAP_TEXTURE_ATI, (unsigned int*) piValue);
2352         } else {
2353             *piValue = GL_FALSE; /** don't support that */
2354             FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
2355         }
2356         break;
2357
2358     default:
2359         FIXME("unexpected attribute %x\n", iAttribute);
2360         break;
2361     }
2362
2363     return GL_TRUE;
2364 }
2365
2366 /**
2367  * X11DRV_wglReleasePbufferDCARB
2368  *
2369  * WGL_ARB_pbuffer: wglReleasePbufferDCARB
2370  */
2371 static int WINAPI X11DRV_wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
2372 {
2373     TRACE("(%p, %p)\n", hPbuffer, hdc);
2374     DeleteDC(hdc);
2375     return 0;
2376 }
2377
2378 /**
2379  * X11DRV_wglSetPbufferAttribARB
2380  *
2381  * WGL_ARB_pbuffer: wglSetPbufferAttribARB
2382  */
2383 static GLboolean WINAPI X11DRV_wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
2384 {
2385     Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2386     WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
2387     if (NULL == object) {
2388         SetLastError(ERROR_INVALID_HANDLE);
2389         return GL_FALSE;
2390     }
2391     if (!object->use_render_texture) {
2392         SetLastError(ERROR_INVALID_HANDLE);
2393         return GL_FALSE;
2394     }
2395     if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2396         return GL_TRUE;
2397     }
2398     if (NULL != pglXDrawableAttribARB) {
2399         if (use_render_texture_ati) {
2400             FIXME("Need conversion for GLX_ATI_render_texture\n");
2401         }
2402         return pglXDrawableAttribARB(object->display, object->drawable, piAttribList); 
2403     }
2404     return GL_FALSE;
2405 }
2406
2407 /**
2408  * X11DRV_wglChoosePixelFormatARB
2409  *
2410  * WGL_ARB_pixel_format: wglChoosePixelFormatARB
2411  */
2412 static GLboolean WINAPI X11DRV_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
2413 {
2414     int gl_test = 0;
2415     int attribs[256];
2416     int nAttribs = 0;
2417     GLXFBConfig* cfgs = NULL;
2418     int nCfgs = 0;
2419     UINT it;
2420     int fmt_id;
2421
2422     GLXFBConfig* cfgs_fmt = NULL;
2423     int nCfgs_fmt = 0;
2424
2425     int fmt = 0;
2426     int pfmt_it = 0;
2427
2428     TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
2429     if (NULL != pfAttribFList) {
2430         FIXME("unused pfAttribFList\n");
2431     }
2432
2433     nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
2434     if (-1 == nAttribs) {
2435         WARN("Cannot convert WGL to GLX attributes\n");
2436         return GL_FALSE;
2437     }
2438     PUSH1(attribs, None);
2439
2440     /* Search for FB configurations matching the requirements in attribs */
2441     cfgs = pglXChooseFBConfig(gdi_display, DefaultScreen(gdi_display), attribs, &nCfgs);
2442     if (NULL == cfgs) {
2443         WARN("Compatible Pixel Format not found\n");
2444         return GL_FALSE;
2445     }
2446
2447     /* Get a list of all FB configurations */
2448     cfgs_fmt = pglXGetFBConfigs(gdi_display, DefaultScreen(gdi_display), &nCfgs_fmt);
2449     if (NULL == cfgs_fmt) {
2450         ERR("Failed to get All FB Configs\n");
2451         XFree(cfgs);
2452         return GL_FALSE;
2453     }
2454
2455     /* Loop through all matching formats and check if they are suitable.
2456     * Note that this function should at max return nMaxFormats different formats */
2457     for (it = 0; pfmt_it < nMaxFormats && it < nCfgs; ++it) {
2458         gl_test = pglXGetFBConfigAttrib(gdi_display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
2459         if (gl_test) {
2460             ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
2461             continue;
2462         }
2463
2464         /* Search for the format in our list of compatible formats */
2465         fmt = ConvertPixelFormatGLXtoWGL(gdi_display, fmt_id);
2466         if(!fmt)
2467             continue;
2468
2469         piFormats[pfmt_it] = fmt;
2470         TRACE("at %d/%d found FBCONFIG_ID 0x%x (%d/%d)\n", it + 1, nCfgs, fmt_id, piFormats[pfmt_it], nCfgs_fmt);
2471         pfmt_it++;
2472     }
2473
2474     *nNumFormats = pfmt_it;
2475     /** free list */
2476     XFree(cfgs);
2477     XFree(cfgs_fmt);
2478     return GL_TRUE;
2479 }
2480
2481 /**
2482  * X11DRV_wglGetPixelFormatAttribivARB
2483  *
2484  * WGL_ARB_pixel_format: wglGetPixelFormatAttribivARB
2485  */
2486 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
2487 {
2488     UINT i;
2489     WineGLPixelFormat *fmt = NULL;
2490     int hTest;
2491     int tmp;
2492     int curGLXAttr = 0;
2493     int nWGLFormats = 0;
2494
2495     TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
2496
2497     if (0 < iLayerPlane) {
2498         FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
2499         return GL_FALSE;
2500     }
2501
2502     /* Convert the WGL pixelformat to a GLX one, if this fails then most likely the iPixelFormat isn't supoprted.
2503     * We don't have to fail yet as a program can specify an invaled iPixelFormat (lets say 0) if it wants to query
2504     * the number of supported WGL formats. Whether the iPixelFormat is valid is handled in the for-loop below. */
2505     fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, TRUE /* Offscreen */, &nWGLFormats);
2506     if(!fmt) {
2507         WARN("Unable to convert iPixelFormat %d to a GLX one!\n", iPixelFormat);
2508     }
2509
2510     for (i = 0; i < nAttributes; ++i) {
2511         const int curWGLAttr = piAttributes[i];
2512         TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
2513
2514         switch (curWGLAttr) {
2515             case WGL_NUMBER_PIXEL_FORMATS_ARB:
2516                 piValues[i] = nWGLFormats; 
2517                 continue;
2518
2519             case WGL_SUPPORT_OPENGL_ARB:
2520                 piValues[i] = GL_TRUE; 
2521                 continue;
2522
2523             case WGL_ACCELERATION_ARB:
2524                 curGLXAttr = GLX_CONFIG_CAVEAT;
2525                 if (!fmt) goto pix_error;
2526                 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2527                 if (hTest) goto get_error;
2528                 switch (tmp) {
2529                     case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2530                     case GLX_SLOW_CONFIG: piValues[i] = WGL_NO_ACCELERATION_ARB; break;
2531                     case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
2532                     default:
2533                         ERR("unexpected Config Caveat(%x)\n", tmp);
2534                         piValues[i] = WGL_NO_ACCELERATION_ARB;
2535                 }
2536                 continue;
2537
2538             case WGL_TRANSPARENT_ARB:
2539                 curGLXAttr = GLX_TRANSPARENT_TYPE;
2540                 if (!fmt) goto pix_error;
2541                 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2542                 if (hTest) goto get_error;
2543                     piValues[i] = GL_FALSE;
2544                 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
2545                     continue;
2546
2547             case WGL_PIXEL_TYPE_ARB:
2548                 curGLXAttr = GLX_RENDER_TYPE;
2549                 if (!fmt) goto pix_error;
2550                 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2551                 if (hTest) goto get_error;
2552                 TRACE("WGL_PIXEL_TYPE_ARB: GLX_RENDER_TYPE = 0x%x\n", tmp);
2553                 if      (tmp & GLX_RGBA_BIT)           { piValues[i] = WGL_TYPE_RGBA_ARB; }
2554                 else if (tmp & GLX_COLOR_INDEX_BIT)    { piValues[i] = WGL_TYPE_COLORINDEX_ARB; }
2555                 else if (tmp & GLX_RGBA_FLOAT_BIT)     { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2556                 else if (tmp & GLX_RGBA_FLOAT_ATI_BIT) { piValues[i] = WGL_TYPE_RGBA_FLOAT_ATI; }
2557                 else {
2558                     ERR("unexpected RenderType(%x)\n", tmp);
2559                     piValues[i] = WGL_TYPE_RGBA_ARB;
2560                 }
2561                 continue;
2562
2563             case WGL_COLOR_BITS_ARB:
2564                 /** see ConvertAttribWGLtoGLX for explain */
2565                 if (!fmt) goto pix_error;
2566                 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_BUFFER_SIZE, piValues + i);
2567                 if (hTest) goto get_error;
2568                 TRACE("WGL_COLOR_BITS_ARB: GLX_BUFFER_SIZE = %d\n", piValues[i]);
2569                 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_ALPHA_SIZE, &tmp);
2570                 if (hTest) goto get_error;
2571                 TRACE("WGL_COLOR_BITS_ARB: GLX_ALPHA_SIZE = %d\n", tmp);
2572                 piValues[i] = piValues[i] - tmp;
2573                 continue;
2574
2575             case WGL_BIND_TO_TEXTURE_RGB_ARB:
2576                 if (use_render_texture_ati) {
2577                     curGLXAttr = GLX_BIND_TO_TEXTURE_RGB_ATI;
2578                     break;
2579                 }
2580             case WGL_BIND_TO_TEXTURE_RGBA_ARB:
2581                 if (use_render_texture_ati) {
2582                     curGLXAttr = GLX_BIND_TO_TEXTURE_RGBA_ATI;
2583                     break;
2584                 }
2585                 if (!use_render_texture_emulation) {
2586                     piValues[i] = GL_FALSE;
2587                     continue;   
2588                 }
2589                 curGLXAttr = GLX_RENDER_TYPE;
2590                 if (!fmt) goto pix_error;
2591                 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, &tmp);
2592                 if (hTest) goto get_error;
2593                 if (GLX_COLOR_INDEX_BIT == tmp) {
2594                     piValues[i] = GL_FALSE;  
2595                     continue;
2596                 }
2597                 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2598                 if (hTest) goto get_error;
2599                     piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2600                 continue;
2601
2602             case WGL_BLUE_BITS_ARB:
2603                 curGLXAttr = GLX_BLUE_SIZE;
2604                 break;
2605             case WGL_RED_BITS_ARB:
2606                 curGLXAttr = GLX_RED_SIZE;
2607                 break;
2608             case WGL_GREEN_BITS_ARB:
2609                 curGLXAttr = GLX_GREEN_SIZE;
2610                 break;
2611             case WGL_ALPHA_BITS_ARB:
2612                 curGLXAttr = GLX_ALPHA_SIZE;
2613                 break;
2614             case WGL_DEPTH_BITS_ARB:
2615                 curGLXAttr = GLX_DEPTH_SIZE;
2616                 break;
2617             case WGL_STENCIL_BITS_ARB:
2618                 curGLXAttr = GLX_STENCIL_SIZE;
2619                 break;
2620             case WGL_DOUBLE_BUFFER_ARB:
2621                 curGLXAttr = GLX_DOUBLEBUFFER;
2622                 break;
2623             case WGL_STEREO_ARB:
2624                 curGLXAttr = GLX_STEREO;
2625                 break;
2626             case WGL_AUX_BUFFERS_ARB:
2627                 curGLXAttr = GLX_AUX_BUFFERS;
2628                 break;
2629             case WGL_SUPPORT_GDI_ARB:
2630             case WGL_DRAW_TO_WINDOW_ARB:
2631             case WGL_DRAW_TO_BITMAP_ARB:
2632                 /* We only supported a limited number of formats right now which are all renderable by X 'GLX_X_RENDERABLE' */
2633                 piValues[i] = GL_TRUE;
2634                 continue;
2635             case WGL_DRAW_TO_PBUFFER_ARB:
2636                 hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &tmp);
2637                 if (hTest) goto get_error;
2638                     piValues[i] = (tmp & GLX_PBUFFER_BIT) ? GL_TRUE : GL_FALSE;
2639                 continue;
2640
2641             case WGL_PBUFFER_LARGEST_ARB:
2642                 curGLXAttr = GLX_LARGEST_PBUFFER;
2643                 break;
2644
2645             case WGL_SAMPLE_BUFFERS_ARB:
2646                 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
2647                 break;
2648
2649             case WGL_SAMPLES_ARB:
2650                 curGLXAttr = GLX_SAMPLES_ARB;
2651                 break;
2652
2653             default:
2654                 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
2655         }
2656
2657         /* Retrieve a GLX FBConfigAttrib when the attribute to query is valid and
2658          * iPixelFormat != 0. When iPixelFormat is 0 the only value which makes
2659          * sense to query is WGL_NUMBER_PIXEL_FORMATS_ARB.
2660          *
2661          * TODO: properly test the behavior of wglGetPixelFormatAttrib*v on Windows
2662          *       and check which options can work using iPixelFormat=0 and which not.
2663          *       A problem would be that this function is an extension. This would
2664          *       mean that the behavior could differ between different vendors (ATI, Nvidia, ..).
2665          */
2666         if (0 != curGLXAttr && iPixelFormat != 0) {
2667             if (!fmt) goto pix_error;
2668             hTest = pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, curGLXAttr, piValues + i);
2669             if (hTest) goto get_error;
2670             curGLXAttr = 0;
2671         } else { 
2672             piValues[i] = GL_FALSE; 
2673         }
2674     }
2675     return GL_TRUE;
2676
2677 get_error:
2678     ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
2679     return GL_FALSE;
2680
2681 pix_error:
2682     ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nWGLFormats);
2683     return GL_FALSE;
2684 }
2685
2686 /**
2687  * X11DRV_wglGetPixelFormatAttribfvARB
2688  *
2689  * WGL_ARB_pixel_format: wglGetPixelFormatAttribfvARB
2690  */
2691 static GLboolean WINAPI X11DRV_wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
2692 {
2693     int *attr;
2694     int ret;
2695     int i;
2696
2697     TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
2698
2699     /* Allocate a temporary array to store integer values */
2700     attr = HeapAlloc(GetProcessHeap(), 0, nAttributes * sizeof(int));
2701     if (!attr) {
2702         ERR("couldn't allocate %d array\n", nAttributes);
2703         return GL_FALSE;
2704     }
2705
2706     /* Piggy-back on wglGetPixelFormatAttribivARB */
2707     ret = X11DRV_wglGetPixelFormatAttribivARB(hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, attr);
2708     if (ret) {
2709         /* Convert integer values to float. Should also check for attributes
2710            that can give decimal values here */
2711         for (i=0; i<nAttributes;i++) {
2712             pfValues[i] = attr[i];
2713         }
2714     }
2715
2716     HeapFree(GetProcessHeap(), 0, attr);
2717     return ret;
2718 }
2719
2720 /**
2721  * X11DRV_wglBindTexImageARB
2722  *
2723  * WGL_ARB_render_texture: wglBindTexImageARB
2724  */
2725 static GLboolean WINAPI X11DRV_wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2726 {
2727     Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2728     TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2729     if (NULL == object) {
2730         SetLastError(ERROR_INVALID_HANDLE);
2731         return GL_FALSE;
2732     }
2733     if (!object->use_render_texture) {
2734         SetLastError(ERROR_INVALID_HANDLE);
2735         return GL_FALSE;
2736     }
2737
2738     if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2739         void *buf;
2740         static int init = 0;
2741         GLXContext prev_context = pglXGetCurrentContext();
2742         Drawable prev_drawable = pglXGetCurrentDrawable();
2743         GLXContext tmp_context;
2744
2745         /* Our render_texture emulation is basic and lacks some features (1D/Cube support).
2746            This is mostly due to lack of demos/games using them. Further the use of glReadPixels
2747            isn't ideal performance wise but I wasn't able to get other ways working.
2748         */
2749         if(!init) {
2750             init = 1; /* Only show the FIXME once for performance reasons */
2751             FIXME("partial stub!\n");
2752         }
2753
2754         buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, object->texture_bpp*object->width*object->height);
2755         if(!buf) {
2756             ERR("Unable to allocate a buffer for render_texture emulation\n");
2757             return GL_FALSE;
2758         }
2759
2760         TRACE("drawable=%p, context=%p\n", (void*)object->drawable, prev_context);
2761         tmp_context = pglXCreateNewContext(gdi_display, object->fmt->fbconfig, object->fmt->render_type, NULL, True);
2762
2763         /* Switch to our pbuffer and readback its contents */
2764         pglXMakeCurrent(gdi_display, object->drawable, tmp_context);
2765         pglReadPixels(0, 0, object->width, object->height, object->texture_format, object->texture_type, buf);
2766
2767         /* Switch back to the original drawable and upload the pbuffer-texture */
2768         pglXMakeCurrent(object->display, prev_drawable, prev_context);
2769         pglTexImage2D(object->texture_target, 0, object->use_render_texture, object->width, object->height, 0, object->texture_format, object->texture_type, buf);
2770
2771         pglXDestroyContext(gdi_display, tmp_context);
2772         HeapFree(GetProcessHeap(), 0, buf);
2773         return GL_TRUE;
2774     }
2775
2776     if (NULL != pglXBindTexImageARB) {
2777         return pglXBindTexImageARB(object->display, object->drawable, iBuffer);
2778     }
2779     return GL_FALSE;
2780 }
2781
2782 /**
2783  * X11DRV_wglReleaseTexImageARB
2784  *
2785  * WGL_ARB_render_texture: wglReleaseTexImageARB
2786  */
2787 static GLboolean WINAPI X11DRV_wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
2788 {
2789     Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
2790     TRACE("(%p, %d)\n", hPbuffer, iBuffer);
2791     if (NULL == object) {
2792         SetLastError(ERROR_INVALID_HANDLE);
2793         return GL_FALSE;
2794     }
2795     if (!object->use_render_texture) {
2796         SetLastError(ERROR_INVALID_HANDLE);
2797         return GL_FALSE;
2798     }
2799     if (!use_render_texture_ati && 1 == use_render_texture_emulation) {
2800         return GL_TRUE;
2801     }
2802     if (NULL != pglXReleaseTexImageARB) {
2803         return pglXReleaseTexImageARB(object->display, object->drawable, iBuffer);
2804     }
2805     return GL_FALSE;
2806 }
2807
2808 /**
2809  * X11DRV_wglGetExtensionsStringEXT
2810  *
2811  * WGL_EXT_extensions_string: wglGetExtensionsStringEXT
2812  */
2813 static const char * WINAPI X11DRV_wglGetExtensionsStringEXT(void) {
2814     TRACE("() returning \"%s\"\n", WineGLInfo.wglExtensions);
2815     return WineGLInfo.wglExtensions;
2816 }
2817
2818 /**
2819  * X11DRV_wglGetSwapIntervalEXT
2820  *
2821  * WGL_EXT_swap_control: wglGetSwapIntervalEXT
2822  */
2823 static int WINAPI X11DRV_wglGetSwapIntervalEXT(VOID) {
2824     FIXME("(),stub!\n");
2825     return swap_interval;
2826 }
2827
2828 /**
2829  * X11DRV_wglSwapIntervalEXT
2830  *
2831  * WGL_EXT_swap_control: wglSwapIntervalEXT
2832  */
2833 static BOOL WINAPI X11DRV_wglSwapIntervalEXT(int interval) {
2834     TRACE("(%d)\n", interval);
2835     swap_interval = interval;
2836     if (NULL != pglXSwapIntervalSGI) {
2837         return 0 == pglXSwapIntervalSGI(interval);
2838     }
2839     WARN("(): GLX_SGI_swap_control extension seems not supported\n");
2840     return TRUE;
2841 }
2842
2843 /**
2844  * X11DRV_wglAllocateMemoryNV
2845  *
2846  * WGL_NV_vertex_array_range: wglAllocateMemoryNV
2847  */
2848 static void* WINAPI X11DRV_wglAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority) {
2849     TRACE("(%d, %f, %f, %f)\n", size, readfreq, writefreq, priority );
2850     if (pglXAllocateMemoryNV == NULL)
2851         return NULL;
2852
2853     return pglXAllocateMemoryNV(size, readfreq, writefreq, priority);
2854 }
2855
2856 /**
2857  * X11DRV_wglFreeMemoryNV
2858  *
2859  * WGL_NV_vertex_array_range: wglFreeMemoryNV
2860  */
2861 static void WINAPI X11DRV_wglFreeMemoryNV(GLvoid* pointer) {
2862     TRACE("(%p)\n", pointer);
2863     if (pglXFreeMemoryNV == NULL)
2864         return;
2865
2866     pglXFreeMemoryNV(pointer);
2867 }
2868
2869 /**
2870  * glxRequireVersion (internal)
2871  *
2872  * Check if the supported GLX version matches requiredVersion.
2873  */
2874 static BOOL glxRequireVersion(int requiredVersion)
2875 {
2876     /* Both requiredVersion and glXVersion[1] contains the minor GLX version */
2877     if(requiredVersion <= WineGLInfo.glxVersion[1])
2878         return TRUE;
2879
2880     return FALSE;
2881 }
2882
2883 static BOOL glxRequireExtension(const char *requiredExtension)
2884 {
2885     if (strstr(WineGLInfo.glxClientExtensions, requiredExtension) == NULL) {
2886         return FALSE;
2887     }
2888
2889     return TRUE;
2890 }
2891
2892 static void register_extension_string(const char *ext)
2893 {
2894     strcat(WineGLInfo.wglExtensions, " ");
2895     strcat(WineGLInfo.wglExtensions, ext);
2896
2897     TRACE("'%s'\n", ext);
2898 }
2899
2900 static BOOL register_extension(const WineGLExtension * ext)
2901 {
2902     int i;
2903
2904     assert( WineGLExtensionListSize < MAX_EXTENSIONS );
2905     WineGLExtensionList[WineGLExtensionListSize++] = ext;
2906
2907     strcat(WineGLInfo.wglExtensions, " ");
2908     strcat(WineGLInfo.wglExtensions, ext->extName);
2909
2910     TRACE("'%s'\n", ext->extName);
2911
2912     for (i = 0; ext->extEntryPoints[i].funcName; ++i)
2913         TRACE("    - '%s'\n", ext->extEntryPoints[i].funcName);
2914
2915     return TRUE;
2916 }
2917
2918 static const WineGLExtension WGL_internal_functions =
2919 {
2920   "",
2921   {
2922     { "wglDisable", X11DRV_wglDisable },
2923     { "wglEnable", X11DRV_wglEnable },
2924     { "wglGetIntegerv", X11DRV_wglGetIntegerv },
2925     { "wglIsEnabled", X11DRV_wglIsEnabled },
2926     { "wglScissor", X11DRV_wglScissor },
2927     { "wglViewport", X11DRV_wglViewport },
2928   }
2929 };
2930
2931
2932 static const WineGLExtension WGL_ARB_extensions_string =
2933 {
2934   "WGL_ARB_extensions_string",
2935   {
2936     { "wglGetExtensionsStringARB", X11DRV_wglGetExtensionsStringARB },
2937   }
2938 };
2939
2940 static const WineGLExtension WGL_ARB_make_current_read =
2941 {
2942   "WGL_ARB_make_current_read",
2943   {
2944     { "wglGetCurrentReadDCARB", X11DRV_wglGetCurrentReadDCARB },
2945     { "wglMakeContextCurrentARB", X11DRV_wglMakeContextCurrentARB },
2946   }
2947 };
2948
2949 static const WineGLExtension WGL_ARB_multisample =
2950 {
2951   "WGL_ARB_multisample",
2952 };
2953
2954 static const WineGLExtension WGL_ARB_pbuffer =
2955 {
2956   "WGL_ARB_pbuffer",
2957   {
2958     { "wglCreatePbufferARB", X11DRV_wglCreatePbufferARB },
2959     { "wglDestroyPbufferARB", X11DRV_wglDestroyPbufferARB },
2960     { "wglGetPbufferDCARB", X11DRV_wglGetPbufferDCARB },
2961     { "wglQueryPbufferARB", X11DRV_wglQueryPbufferARB },
2962     { "wglReleasePbufferDCARB", X11DRV_wglReleasePbufferDCARB },
2963     { "wglSetPbufferAttribARB", X11DRV_wglSetPbufferAttribARB },
2964   }
2965 };
2966
2967 static const WineGLExtension WGL_ARB_pixel_format =
2968 {
2969   "WGL_ARB_pixel_format",
2970   {
2971     { "wglChoosePixelFormatARB", X11DRV_wglChoosePixelFormatARB },
2972     { "wglGetPixelFormatAttribfvARB", X11DRV_wglGetPixelFormatAttribfvARB },
2973     { "wglGetPixelFormatAttribivARB", X11DRV_wglGetPixelFormatAttribivARB },
2974   }
2975 };
2976
2977 static const WineGLExtension WGL_ARB_render_texture =
2978 {
2979   "WGL_ARB_render_texture",
2980   {
2981     { "wglBindTexImageARB", X11DRV_wglBindTexImageARB },
2982     { "wglReleaseTexImageARB", X11DRV_wglReleaseTexImageARB },
2983   }
2984 };
2985
2986 static const WineGLExtension WGL_EXT_extensions_string =
2987 {
2988   "WGL_EXT_extensions_string",
2989   {
2990     { "wglGetExtensionsStringEXT", X11DRV_wglGetExtensionsStringEXT },
2991   }
2992 };
2993
2994 static const WineGLExtension WGL_EXT_swap_control =
2995 {
2996   "WGL_EXT_swap_control",
2997   {
2998     { "wglSwapIntervalEXT", X11DRV_wglSwapIntervalEXT },
2999     { "wglGetSwapIntervalEXT", X11DRV_wglGetSwapIntervalEXT },
3000   }
3001 };
3002
3003 static const WineGLExtension WGL_NV_vertex_array_range =
3004 {
3005   "WGL_NV_vertex_array_range",
3006   {
3007     { "wglAllocateMemoryNV", X11DRV_wglAllocateMemoryNV },
3008     { "wglFreeMemoryNV", X11DRV_wglFreeMemoryNV },
3009   }
3010 };
3011
3012 /**
3013  * X11DRV_WineGL_LoadExtensions
3014  */
3015 static void X11DRV_WineGL_LoadExtensions(void)
3016 {
3017     WineGLInfo.wglExtensions[0] = 0;
3018
3019     /* Load Wine internal functions */
3020     register_extension(&WGL_internal_functions);
3021
3022     /* ARB Extensions */
3023
3024     if(glxRequireExtension("GLX_ARB_fbconfig_float"))
3025     {
3026         register_extension_string("WGL_ARB_pixel_format_float");
3027         register_extension_string("WGL_ATI_pixel_format_float");
3028     }
3029
3030     register_extension(&WGL_ARB_extensions_string);
3031
3032     if (glxRequireVersion(3))
3033         register_extension(&WGL_ARB_make_current_read);
3034
3035     if (glxRequireExtension("GLX_ARB_multisample"))
3036         register_extension(&WGL_ARB_multisample);
3037
3038     /* In general pbuffer functionality requires support in the X-server. The functionality is
3039      * available either when the GLX_SGIX_pbuffer is present or when the GLX server version is 1.3.
3040      * All display drivers except for Nvidia's use the GLX module from Xfree86/Xorg which only
3041      * supports GLX 1.2. The endresult is that only Nvidia's drivers support pbuffers.
3042      *
3043      * The only other drive which has pbuffer support is Ati's FGLRX driver. They provide clientside GLX 1.3 support
3044      * without support in the X-server (which other Mesa based drivers require).
3045      *
3046      * Support pbuffers when the GLX version is 1.3 and GLX_SGIX_pbuffer is available. Further pbuffers can
3047      * also be supported when GLX_ATI_render_texture is available. This extension depends on pbuffers, so when it
3048      * is available pbuffers must be available too. */
3049     if ( (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer")) || glxRequireExtension("GLX_ATI_render_texture"))
3050         register_extension(&WGL_ARB_pbuffer);
3051
3052     register_extension(&WGL_ARB_pixel_format);
3053
3054     /* Support WGL_ARB_render_texture when there's support or pbuffer based emulation */
3055     if (glxRequireExtension("GLX_ATI_render_texture") ||
3056         glxRequireExtension("GLX_ARB_render_texture") ||
3057         (glxRequireVersion(3) && glxRequireExtension("GLX_SGIX_pbuffer") && use_render_texture_emulation))
3058     {
3059         register_extension(&WGL_ARB_render_texture);
3060
3061         /* The WGL version of GLX_NV_float_buffer requires render_texture */
3062         if(glxRequireExtension("GLX_NV_float_buffer"))
3063             register_extension_string("WGL_NV_float_buffer");
3064
3065         /* Again there's no GLX equivalent for this extension, so depend on the required GL extension */
3066         if(strstr(WineGLInfo.glExtensions, "GL_NV_texture_rectangle") != NULL)
3067             register_extension_string("WGL_NV_texture_rectangle");
3068     }
3069
3070     /* EXT Extensions */
3071
3072     register_extension(&WGL_EXT_extensions_string);
3073
3074     /* Load this extension even when it isn't backed by a GLX extension because it is has been around for ages.
3075      * Games like Call of Duty and K.O.T.O.R. rely on it. Further our emulation is good enough. */
3076     register_extension(&WGL_EXT_swap_control);
3077
3078     /* The OpenGL extension GL_NV_vertex_array_range adds wgl/glX functions which aren't exported as 'real' wgl/glX extensions. */
3079     if(strstr(WineGLInfo.glExtensions, "GL_NV_vertex_array_range") != NULL)
3080         register_extension(&WGL_NV_vertex_array_range);
3081 }
3082
3083
3084 static XID create_glxpixmap(X11DRV_PDEVICE *physDev)
3085 {
3086     GLXPixmap ret;
3087     XVisualInfo *vis;
3088     XVisualInfo template;
3089     int num;
3090
3091     wine_tsx11_lock();
3092
3093     /* Retrieve the visualid from our main visual which is the only visual we can use */
3094     template.visualid =  XVisualIDFromVisual(visual);
3095     vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
3096
3097     ret = pglXCreateGLXPixmap(gdi_display, vis, physDev->bitmap->pixmap);
3098     XFree(vis);
3099     wine_tsx11_unlock(); 
3100     TRACE("return %lx\n", ret);
3101     return ret;
3102 }
3103
3104 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3105 {
3106     Drawable ret;
3107
3108     if(physDev->bitmap)
3109     {
3110         if (physDev->bitmap->hbitmap == BITMAP_stock_phys_bitmap.hbitmap)
3111             ret = physDev->drawable; /* PBuffer */
3112         else
3113         {
3114             if(!physDev->bitmap->glxpixmap)
3115                 physDev->bitmap->glxpixmap = create_glxpixmap(physDev);
3116             ret = physDev->bitmap->glxpixmap;
3117         }
3118     }
3119     else
3120         ret = physDev->drawable;
3121     return ret;
3122 }
3123
3124 BOOL destroy_glxpixmap(XID glxpixmap)
3125 {
3126     wine_tsx11_lock(); 
3127     pglXDestroyGLXPixmap(gdi_display, glxpixmap);
3128     wine_tsx11_unlock(); 
3129     return TRUE;
3130 }
3131
3132 /**
3133  * X11DRV_SwapBuffers
3134  *
3135  * Swap the buffers of this DC
3136  */
3137 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev)
3138 {
3139   GLXDrawable drawable;
3140   if (!has_opengl()) {
3141     ERR("No libGL on this box - disabling OpenGL support !\n");
3142     return 0;
3143   }
3144   
3145   TRACE_(opengl)("(%p)\n", physDev);
3146
3147   drawable = get_glxdrawable(physDev);
3148   wine_tsx11_lock();
3149   pglXSwapBuffers(gdi_display, drawable);
3150   wine_tsx11_unlock();
3151
3152   /* FPS support */
3153   if (TRACE_ON(fps))
3154   {
3155       static long prev_time, frames;
3156
3157       DWORD time = GetTickCount();
3158       frames++;
3159       /* every 1.5 seconds */
3160       if (time - prev_time > 1500) {
3161           TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
3162           prev_time = time;
3163           frames = 0;
3164       }
3165   }
3166
3167   return TRUE;
3168 }
3169
3170 /***********************************************************************
3171  *              X11DRV_setup_opengl_visual
3172  *
3173  * Setup the default visual used for OpenGL and Direct3D, and the desktop
3174  * window (if it exists).  If OpenGL isn't available, the visual is simply
3175  * set to the default visual for the display
3176  */
3177 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
3178 {
3179     XVisualInfo *visual = NULL;
3180     int i;
3181
3182     /* In order to support OpenGL or D3D, we require a double-buffered visual and stencil buffer support,
3183      * D3D and some applications can make use of aux buffers.
3184      */
3185     int visualProperties[][11] = {
3186         { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_AUX_BUFFERS, 1, None },
3187         { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_ALPHA_SIZE, 8, None },
3188         { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, GLX_STENCIL_SIZE, 8, None },
3189         { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, None },
3190     };
3191
3192     if (!has_opengl())
3193         return NULL;
3194
3195     wine_tsx11_lock();
3196     for (i = 0; i < sizeof(visualProperties)/sizeof(visualProperties[0]); ++i) {
3197         visual = pglXChooseVisual(display, DefaultScreen(display), visualProperties[i]);
3198         if (visual)
3199             break;
3200     }
3201     wine_tsx11_unlock();
3202
3203     if (visual)
3204         TRACE("Visual ID %lx Chosen\n", visual->visualid);
3205     else
3206         WARN("No suitable visual found\n");
3207
3208     return visual;
3209 }
3210
3211 #else  /* no OpenGL includes */
3212
3213 /***********************************************************************
3214  *              ChoosePixelFormat (X11DRV.@)
3215  */
3216 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
3217                              const PIXELFORMATDESCRIPTOR *ppfd) {
3218   ERR("No OpenGL support compiled in.\n");
3219
3220   return 0;
3221 }
3222
3223 /***********************************************************************
3224  *              DescribePixelFormat (X11DRV.@)
3225  */
3226 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
3227                                int iPixelFormat,
3228                                UINT nBytes,
3229                                PIXELFORMATDESCRIPTOR *ppfd) {
3230   ERR("No OpenGL support compiled in.\n");
3231
3232   return 0;
3233 }
3234
3235 /***********************************************************************
3236  *              GetPixelFormat (X11DRV.@)
3237  */
3238 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
3239   ERR("No OpenGL support compiled in.\n");
3240
3241   return 0;
3242 }
3243
3244 /***********************************************************************
3245  *              SetPixelFormat (X11DRV.@)
3246  */
3247 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
3248                            int iPixelFormat,
3249                            const PIXELFORMATDESCRIPTOR *ppfd) {
3250   ERR("No OpenGL support compiled in.\n");
3251
3252   return FALSE;
3253 }
3254
3255 /***********************************************************************
3256  *              SwapBuffers (X11DRV.@)
3257  */
3258 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
3259   ERR_(opengl)("No OpenGL support compiled in.\n");
3260
3261   return FALSE;
3262 }
3263
3264 /**
3265  * X11DRV_wglCreateContext
3266  *
3267  * For OpenGL32 wglCreateContext.
3268  */
3269 HGLRC X11DRV_wglCreateContext(X11DRV_PDEVICE *physDev) {
3270     ERR_(opengl)("No OpenGL support compiled in.\n");
3271     return NULL;
3272 }
3273
3274 /**
3275  * X11DRV_wglDeleteContext
3276  *
3277  * For OpenGL32 wglDeleteContext.
3278  */
3279 BOOL X11DRV_wglDeleteContext(HGLRC hglrc) {
3280     ERR_(opengl)("No OpenGL support compiled in.\n");
3281     return FALSE;
3282 }
3283
3284 /**
3285  * X11DRV_wglGetProcAddress
3286  *
3287  * For OpenGL32 wglGetProcAddress.
3288  */
3289 PROC X11DRV_wglGetProcAddress(LPCSTR lpszProc) {
3290     ERR_(opengl)("No OpenGL support compiled in.\n");
3291     return NULL;
3292 }
3293
3294 HDC X11DRV_wglGetPbufferDCARB(X11DRV_PDEVICE *hDevice, void *hPbuffer)
3295 {
3296     ERR_(opengl)("No OpenGL support compiled in.\n");
3297     return NULL;
3298 }
3299
3300 BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) {
3301     ERR_(opengl)("No OpenGL support compiled in.\n");
3302     return FALSE;
3303 }
3304
3305 /**
3306  * X11DRV_wglMakeCurrent
3307  *
3308  * For OpenGL32 wglMakeCurrent.
3309  */
3310 BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) {
3311     ERR_(opengl)("No OpenGL support compiled in.\n");
3312     return FALSE;
3313 }
3314
3315 /**
3316  * X11DRV_wglShareLists
3317  *
3318  * For OpenGL32 wglShaderLists.
3319  */
3320 BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) {
3321     ERR_(opengl)("No OpenGL support compiled in.\n");
3322     return FALSE;
3323 }
3324
3325 /**
3326  * X11DRV_wglUseFontBitmapsA
3327  *
3328  * For OpenGL32 wglUseFontBitmapsA.
3329  */
3330 BOOL X11DRV_wglUseFontBitmapsA(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3331 {
3332     ERR_(opengl)("No OpenGL support compiled in.\n");
3333     return FALSE;
3334 }
3335
3336 /**
3337  * X11DRV_wglUseFontBitmapsW
3338  *
3339  * For OpenGL32 wglUseFontBitmapsW.
3340  */
3341 BOOL X11DRV_wglUseFontBitmapsW(X11DRV_PDEVICE *physDev, DWORD first, DWORD count, DWORD listBase)
3342 {
3343     ERR_(opengl)("No OpenGL support compiled in.\n");
3344     return FALSE;
3345 }
3346
3347 XVisualInfo *X11DRV_setup_opengl_visual( Display *display )
3348 {
3349   return NULL;
3350 }
3351
3352 Drawable get_glxdrawable(X11DRV_PDEVICE *physDev)
3353 {
3354     return 0;
3355 }
3356
3357 BOOL destroy_glxpixmap(XID glxpixmap)
3358 {
3359     return FALSE;
3360 }
3361
3362 #endif /* defined(HAVE_OPENGL) */