Added CSIDL_MYVIDEO|MYPICTURES|MYMUSIC to _SHRegisterUserShellFolders.
[wine] / dlls / opengl32 / wgl_ext.c
1 /* Support for window-specific OpenGL extensions.
2  *
3  * Copyright (c) 2004 Lionel Ulmer
4  * Copyright (c) 2005 Alex Woods
5  * Copyright (c) 2005 Raphael Junqueira
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdarg.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "winerror.h"
33
34 #include "gdi.h"
35 #include "wgl.h"
36 #include "wgl_ext.h"
37 #include "opengl_ext.h"
38 #include "wine/library.h"
39 #include "wine/debug.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
42
43
44 /* x11drv GDI escapes */
45 #define X11DRV_ESCAPE 6789
46 enum x11drv_escape_codes
47 {
48     X11DRV_GET_DISPLAY,   /* get X11 display for a DC */
49     X11DRV_GET_DRAWABLE,  /* get current drawable for a DC */
50     X11DRV_GET_FONT,      /* get current X font for a DC */
51     X11DRV_SET_DRAWABLE,     /* set current drawable for a DC */
52 };
53 struct x11drv_escape_set_drawable
54 {
55     enum x11drv_escape_codes code;         /* escape code (X11DRV_SET_DRAWABLE) */
56     Drawable                 drawable;     /* X drawable */
57     int                      mode;         /* ClipByChildren or IncludeInferiors */
58     POINT                    org;          /* origin of DC relative to drawable */
59     POINT                    drawable_org; /* origin of drawable relative to screen */
60 };
61
62 /* retrieve the X display to use on a given DC */
63 inline static Display *get_display( HDC hdc )
64 {
65     Display *display;
66     enum x11drv_escape_codes escape = X11DRV_GET_DISPLAY;
67
68     if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape,
69                     sizeof(display), (LPSTR)&display )) display = NULL;
70     return display;
71 }
72 inline static void set_drawable( HDC hdc, Drawable drawable )
73 {
74     struct x11drv_escape_set_drawable escape;
75
76     escape.code = X11DRV_SET_DRAWABLE;
77     escape.drawable = drawable;
78     escape.mode = IncludeInferiors;
79     escape.org.x = escape.org.y = 0;
80     escape.drawable_org.x = escape.drawable_org.y = 0;
81
82     ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape, 0, NULL );
83 }
84
85 /* Some WGL extensions... */
86 static const char *WGL_extensions_base = "WGL_ARB_extensions_string WGL_EXT_extensions_string";
87 static char *WGL_extensions = NULL;
88
89 /**
90  * Extensions-query functions 
91  *
92  * @TODO: use a struct to handle parameters 
93  */
94 BOOL query_function_make_current_read(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions, 
95                                       const char* glx_version, const char *glx_extensions,
96                                       const char *server_glx_extensions, const char *client_glx_extensions)
97 {
98   return 0 <= strcmp("1.3", glx_version);
99 }
100
101 BOOL query_function_multisample(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions, 
102                                 const char* glx_version, const char *glx_extensions,
103                                 const char *server_glx_extensions, const char *client_glx_extensions)
104 {
105   return NULL != strstr(glx_extensions, "GLX_ARB_multisample");
106 }
107
108 BOOL query_function_pbuffer(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions, 
109                             const char* glx_version, const char *glx_extensions,
110                             const char *server_glx_extensions, const char *client_glx_extensions)
111 {
112   TRACE("gl_version is: \"%s\"\n", gl_version);
113   TRACE("glx_exts is: \"%s\"\n", glx_extensions);
114
115   return 0 <= strcmp("1.3", glx_version) || NULL != strstr(glx_extensions, "GLX_SGIX_pbuffer");
116 }
117
118 BOOL query_function_pixel_format(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions, 
119                                  const char* glx_version, const char *glx_extensions,
120                                  const char *server_glx_extensions, const char *client_glx_extensions)
121 {
122   return TRUE;
123 }
124
125 /** GLX_ARB_render_texture */
126 /**
127  * http://oss.sgi.com/projects/ogl-sample/registry/ARB/wgl_render_texture.txt
128  * ~/tmp/ogl/ogl_offscreen_rendering_3
129  */
130 Bool (*p_glXBindTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
131 Bool (*p_glXReleaseTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
132 Bool (*p_glXDrawableAttribARB)(Display *dpy, GLXDrawable draw, const int *attribList);
133 int  use_render_texture_emulation = 0;
134 BOOL query_function_render_texture(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions, 
135                                    const char* glx_version, const char *glx_extensions,
136                                    const char *server_glx_extensions, const char *client_glx_extensions)
137 {
138   BOOL bTest = (0 <= strcmp("1.3", glx_version) || NULL != strstr(glx_extensions, "GLX_SGIX_pbuffer"));
139   if (bTest) {
140     if (NULL != strstr(glx_extensions, "GLX_ARB_render_texture")) {
141       p_glXBindTexImageARB = proc( (const GLubyte *) "glXBindTexImageARB");
142       p_glXReleaseTexImageARB = proc( (const GLubyte *) "glXReleaseTexImageARB");
143       p_glXDrawableAttribARB = proc( (const GLubyte *) "glXDrawableAttribARB");
144       bTest = (NULL != p_glXBindTexImageARB && NULL != p_glXReleaseTexImageARB && NULL != p_glXDrawableAttribARB);
145     } else {
146       use_render_texture_emulation = 0;
147     }
148   }
149   return bTest;
150 }
151
152 int (*p_glXSwapIntervalSGI)(int);
153 BOOL query_function_swap_control(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions, 
154                                  const char* glx_version, const char *glx_extensions,
155                                  const char *server_glx_extensions, const char *client_glx_extensions)
156 {
157   BOOL bTest = (0 <= strcmp("1.3", glx_version) || NULL != strstr(glx_extensions, "GLX_SGI_swap_control"));
158   if (bTest) {
159     p_glXSwapIntervalSGI = proc( (const GLubyte *) "glXSwapIntervalSGI");
160     bTest = (NULL != p_glXSwapIntervalSGI);
161   }
162   return bTest;
163 }
164
165 /***********************************************************************
166  *              wglGetExtensionsStringEXT(OPENGL32.@)
167  */
168 const char * WINAPI wglGetExtensionsStringEXT(void) {
169     TRACE("() returning \"%s\"\n", WGL_extensions);
170
171     return WGL_extensions;
172 }
173
174 /***********************************************************************
175  *              wglGetExtensionsStringARB(OPENGL32.@)
176  */
177 const char * WINAPI wglGetExtensionsStringARB(HDC hdc) {
178     TRACE("() returning \"%s\"\n", WGL_extensions);
179
180     return WGL_extensions;    
181 }
182
183 static int swap_interval = 1;
184
185 /***********************************************************************
186  *              wglSwapIntervalEXT(OPENGL32.@)
187  */
188 BOOL WINAPI wglSwapIntervalEXT(int interval) {
189   TRACE("(%d)\n", interval);
190   swap_interval = interval;
191   if (NULL != p_glXSwapIntervalSGI) {
192     return 0 == p_glXSwapIntervalSGI(interval);
193   }
194   WARN("(): GLX_SGI_swap_control extension seems not supported\n");
195   return TRUE;
196 }
197
198 /***********************************************************************
199  *              wglGetSwapIntervalEXT(OPENGL32.@)
200  */
201 int WINAPI wglGetSwapIntervalEXT(VOID) {
202     FIXME("(),stub!\n");
203     return swap_interval;
204 }
205
206 typedef struct wine_glpbuffer {
207   Drawable   drawable;
208   Display*   display;
209   int        pixelFormat;
210   int        width;
211   int        height;
212   int*       attribList;
213   HDC        hdc;
214
215   int        use_render_texture;
216   GLuint     texture_target;
217   GLuint     texture_bind_target;
218   GLuint     texture;
219   int        texture_level;
220 } Wine_GLPBuffer;
221
222 #define PUSH1(attribs,att)        attribs[nAttribs++] = (att); 
223 #define PUSH2(attribs,att,value)  attribs[nAttribs++] = (att); attribs[nAttribs++] = (value);
224
225 #define WGL_NUMBER_PIXEL_FORMATS_ARB            0x2000
226 #define WGL_DRAW_TO_WINDOW_ARB                  0x2001
227 #define WGL_DRAW_TO_BITMAP_ARB                  0x2002
228 #define WGL_ACCELERATION_ARB                    0x2003
229 #define WGL_NEED_PALETTE_ARB                    0x2004
230 #define WGL_NEED_SYSTEM_PALETTE_ARB             0x2005
231 #define WGL_SWAP_LAYER_BUFFERS_ARB              0x2006
232 #define WGL_SWAP_METHOD_ARB                     0x2007
233 #define WGL_NUMBER_OVERLAYS_ARB                 0x2008
234 #define WGL_NUMBER_UNDERLAYS_ARB                0x2009
235 #define WGL_TRANSPARENT_ARB                     0x200A
236 #define WGL_TRANSPARENT_RED_VALUE_ARB           0x2037
237 #define WGL_TRANSPARENT_GREEN_VALUE_ARB         0x2038
238 #define WGL_TRANSPARENT_BLUE_VALUE_ARB          0x2039
239 #define WGL_TRANSPARENT_ALPHA_VALUE_ARB         0x203A
240 #define WGL_TRANSPARENT_INDEX_VALUE_ARB         0x203B
241 #define WGL_SHARE_DEPTH_ARB                     0x200C
242 #define WGL_SHARE_STENCIL_ARB                   0x200D
243 #define WGL_SHARE_ACCUM_ARB                     0x200E
244 #define WGL_SUPPORT_GDI_ARB                     0x200F
245 #define WGL_SUPPORT_OPENGL_ARB                  0x2010
246 #define WGL_DOUBLE_BUFFER_ARB                   0x2011
247 #define WGL_STEREO_ARB                          0x2012
248 #define WGL_PIXEL_TYPE_ARB                      0x2013
249 #define WGL_COLOR_BITS_ARB                      0x2014
250 #define WGL_RED_BITS_ARB                        0x2015
251 #define WGL_RED_SHIFT_ARB                       0x2016
252 #define WGL_GREEN_BITS_ARB                      0x2017
253 #define WGL_GREEN_SHIFT_ARB                     0x2018
254 #define WGL_BLUE_BITS_ARB                       0x2019
255 #define WGL_BLUE_SHIFT_ARB                      0x201A
256 #define WGL_ALPHA_BITS_ARB                      0x201B
257 #define WGL_ALPHA_SHIFT_ARB                     0x201C
258 #define WGL_ACCUM_BITS_ARB                      0x201D
259 #define WGL_ACCUM_RED_BITS_ARB                  0x201E
260 #define WGL_ACCUM_GREEN_BITS_ARB                0x201F
261 #define WGL_ACCUM_BLUE_BITS_ARB                 0x2020
262 #define WGL_ACCUM_ALPHA_BITS_ARB                0x2021
263 #define WGL_DEPTH_BITS_ARB                      0x2022
264 #define WGL_STENCIL_BITS_ARB                    0x2023
265 #define WGL_AUX_BUFFERS_ARB                     0x2024
266
267 #define WGL_NO_ACCELERATION_ARB                 0x2025
268 #define WGL_GENERIC_ACCELERATION_ARB            0x2026
269 #define WGL_FULL_ACCELERATION_ARB               0x2027
270
271 #define WGL_PBUFFER_WIDTH_ARB                   0x2034
272 #define WGL_PBUFFER_HEIGHT_ARB                  0x2035
273 #define WGL_PBUFFER_LOST_ARB                    0x2036
274 #define WGL_DRAW_TO_PBUFFER_ARB                 0x202D
275 #define WGL_MAX_PBUFFER_PIXELS_ARB              0x202E
276 #define WGL_MAX_PBUFFER_WIDTH_ARB               0x202F
277 #define WGL_MAX_PBUFFER_HEIGHT_ARB              0x2030
278 #define WGL_PBUFFER_LARGEST_ARB                 0x2033
279
280 #define WGL_TYPE_RGBA_ARB                       0x202B
281 #define WGL_TYPE_COLORINDEX_ARB                 0x202C
282
283 #define WGL_SAMPLE_BUFFERS_ARB                  0x2041
284 #define WGL_SAMPLES_ARB                         0x2042
285
286 /**
287  * WGL_render_texture 
288  */
289 /** GetPixelFormat/ChoosePixelFormat */
290 #define WGL_BIND_TO_TEXTURE_RGB_ARB             0x2070
291 #define WGL_BIND_TO_TEXTURE_RGBA_ARB            0x2071
292 /** CreatePbuffer / QueryPbuffer */
293 #define WGL_TEXTURE_FORMAT_ARB                  0x2072
294 #define WGL_TEXTURE_TARGET_ARB                  0x2073
295 #define WGL_MIPMAP_TEXTURE_ARB                  0x2074
296 /** CreatePbuffer / QueryPbuffer */
297 #define WGL_TEXTURE_RGB_ARB                     0x2075
298 #define WGL_TEXTURE_RGBA_ARB                    0x2076
299 #define WGL_NO_TEXTURE_ARB                      0x2077
300 /** CreatePbuffer / QueryPbuffer */
301 #define WGL_TEXTURE_CUBE_MAP_ARB                0x2078
302 #define WGL_TEXTURE_1D_ARB                      0x2079
303 #define WGL_TEXTURE_2D_ARB                      0x207A
304 #define WGL_NO_TEXTURE_ARB                      0x2077
305 /** SetPbufferAttribARB/QueryPbufferARB parameters */
306 #define WGL_MIPMAP_LEVEL_ARB                    0x207B
307 #define WGL_CUBE_MAP_FACE_ARB                   0x207C
308 /** SetPbufferAttribARB/QueryPbufferARB attribs */
309 #define WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB     0x207D
310 #define WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB     0x207E
311 #define WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB     0x207F
312 #define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB     0x2080
313 #define WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB     0x2081 
314 #define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB     0x2082
315 /** BindTexImageARB/ReleaseTexImageARB */
316 #define WGL_FRONT_LEFT_ARB                  0x2083
317 #define WGL_FRONT_RIGHT_ARB                 0x2084
318 #define WGL_BACK_LEFT_ARB                   0x2085
319 #define WGL_BACK_RIGHT_ARB                  0x2086
320 #define WGL_AUX0_ARB                        0x2087 
321 #define WGL_AUX1_ARB                        0x2088 
322 #define WGL_AUX2_ARB                        0x2089 
323 #define WGL_AUX3_ARB                        0x208A 
324 #define WGL_AUX4_ARB                        0x208B 
325 #define WGL_AUX5_ARB                        0x208C 
326 #define WGL_AUX6_ARB                        0x208D
327 #define WGL_AUX7_ARB                        0x208E 
328 #define WGL_AUX8_ARB                        0x208F 
329 #define WGL_AUX9_ARB                        0x2090
330
331 #if 0 /* not used yet */
332 static unsigned ConvertAttribGLXtoWGL(const int* iWGLAttr, int* oGLXAttr) {
333   unsigned nAttribs = 0;
334   FIXME("not yet implemented!\n");
335   return nAttribs;
336 }
337 #endif
338
339 static unsigned ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
340   unsigned nAttribs = 0;
341   unsigned cur = 0; 
342   int pop;
343   int isColor = 0;
344   int wantColorBits = 0;
345   int sz_alpha = 0;
346
347   while (0 != iWGLAttr[cur]) {
348     TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
349
350     switch (iWGLAttr[cur]) {
351     case WGL_COLOR_BITS_ARB:
352       pop = iWGLAttr[++cur];
353       wantColorBits = pop; /** see end */
354       break;
355     case WGL_BLUE_BITS_ARB:
356       pop = iWGLAttr[++cur];
357       PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
358       TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
359       break;
360     case WGL_RED_BITS_ARB:
361       pop = iWGLAttr[++cur];
362       PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
363       TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
364       break;
365     case WGL_GREEN_BITS_ARB:
366       pop = iWGLAttr[++cur];
367       PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
368       TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
369       break;
370     case WGL_ALPHA_BITS_ARB:
371       pop = iWGLAttr[++cur];
372       sz_alpha = pop;
373       PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
374       TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
375       break;
376     case WGL_DEPTH_BITS_ARB:
377       pop = iWGLAttr[++cur];
378       PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
379       TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
380       break;
381     case WGL_STENCIL_BITS_ARB:
382       pop = iWGLAttr[++cur];
383       PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
384       TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
385       break;
386     case WGL_DOUBLE_BUFFER_ARB:
387       pop = iWGLAttr[++cur];
388       PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
389       TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
390       break;
391
392     case WGL_PIXEL_TYPE_ARB:
393       pop = iWGLAttr[++cur];
394       switch (pop) {
395       case WGL_TYPE_RGBA_ARB:  pop = GLX_RGBA_BIT; break ; 
396       case WGL_TYPE_COLORINDEX_ARB: pop = GLX_COLOR_INDEX_BIT; isColor = 1; break ;
397       default:
398         ERR("unexpected PixelType(%x)\n", pop); 
399         pop = 0;
400       }
401       PUSH2(oGLXAttr, GLX_RENDER_TYPE, pop);
402       TRACE("pAttr[%d] = GLX_RENDER_TYPE: %d\n", cur, pop);
403       break;
404
405     case WGL_SUPPORT_GDI_ARB:
406     case WGL_DRAW_TO_WINDOW_ARB:
407     case WGL_DRAW_TO_BITMAP_ARB:
408     case WGL_DRAW_TO_PBUFFER_ARB:
409       pop = iWGLAttr[++cur];
410       PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
411       TRACE("pAttr[%d] = GLX_RENDERABLE: %d\n", cur, pop);
412       break;
413
414     case WGL_ACCELERATION_ARB:
415     case WGL_SUPPORT_OPENGL_ARB:
416       pop = iWGLAttr[++cur];
417       /** nothing to do, if we are here, supposing support Accelerated OpenGL */
418       TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
419       break;
420
421     case WGL_PBUFFER_LARGEST_ARB:
422       pop = iWGLAttr[++cur];
423       PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
424       TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
425       break;
426
427     case WGL_SAMPLE_BUFFERS_ARB:
428       pop = iWGLAttr[++cur];
429       PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
430       TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
431       break;
432       
433     case WGL_SAMPLES_ARB:
434       pop = iWGLAttr[++cur];
435       PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
436       TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
437       break;
438
439     case WGL_TEXTURE_FORMAT_ARB:
440     case WGL_TEXTURE_TARGET_ARB:
441     case WGL_MIPMAP_TEXTURE_ARB:
442       TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
443       if (NULL == pbuf) {
444         ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
445       }
446       if (!use_render_texture_emulation) {
447         ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
448       }
449       pop = iWGLAttr[++cur];
450       break ;
451
452     default:
453       FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
454       break;
455     }
456     ++cur;
457   }
458
459   /**
460    * Trick as WGL_COLOR_BITS_ARB != GLX_BUFFER_SIZE
461    *    WGL_COLOR_BITS_ARB + WGL_ALPHA_BITS_ARB == GLX_BUFFER_SIZE
462    *
463    *  WGL_COLOR_BITS_ARB
464    *     The number of color bitplanes in each color buffer. For RGBA
465    *     pixel types, it is the size of the color buffer, excluding the
466    *     alpha bitplanes. For color-index pixels, it is the size of the
467    *     color index buffer.
468    *
469    *  GLX_BUFFER_SIZE   
470    *     This attribute defines the number of bits per color buffer. 
471    *     For GLX FBConfigs that correspond to a PseudoColor or StaticColor visual, 
472    *     this is equal to the depth value reported in the X11 visual. 
473    *     For GLX FBConfigs that correspond to TrueColor or DirectColor visual, 
474    *     this is the sum of GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_BLUE_SIZE, and GLX_ALPHA_SIZE.
475    * 
476    */
477   if (0 < wantColorBits) {
478     if (!isColor) { 
479       wantColorBits += sz_alpha; 
480     }
481     if (32 < wantColorBits) {
482       ERR("buggy %d GLX_BUFFER_SIZE default to 32\n", wantColorBits);
483       wantColorBits = 32;
484     }
485     PUSH2(oGLXAttr, GLX_BUFFER_SIZE, wantColorBits);
486     TRACE("pAttr[%d] = WGL_COLOR_BITS_ARB: %d\n", cur, wantColorBits);
487   }
488
489   return nAttribs;
490 }
491
492 GLboolean WINAPI wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
493 {
494   Display* display = get_display( hdc );
495   UINT i;
496   GLXFBConfig* cfgs = NULL;
497   GLXFBConfig  curCfg = NULL;
498   int nCfgs = 0;
499   int hTest;
500   int tmp;
501   int curGLXAttr = 0;
502
503   TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
504   
505   if (0 < iLayerPlane) {
506     FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
507     return GL_FALSE;
508   }
509
510   cfgs = glXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
511   if (NULL == cfgs) {
512     ERR("no FB Configs found for display(%p)\n", display);
513     return GL_FALSE;
514   }
515
516   for (i = 0; i < nAttributes; ++i) {
517     const int curWGLAttr = piAttributes[i];
518     TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
519     
520     switch (curWGLAttr) {
521     case WGL_NUMBER_PIXEL_FORMATS_ARB:
522       piValues[i] = nCfgs; 
523       continue ;
524
525     case WGL_SUPPORT_OPENGL_ARB:
526       piValues[i] = GL_TRUE; 
527       continue ;
528
529     case WGL_ACCELERATION_ARB:
530       curGLXAttr = GLX_CONFIG_CAVEAT;
531       if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
532       curCfg = cfgs[iPixelFormat - 1];
533       hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, &tmp);
534       if (hTest) goto get_error;
535       switch (tmp) {
536       case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
537       case GLX_SLOW_CONFIG: piValues[i] = WGL_NO_ACCELERATION_ARB; break;
538       case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
539       default:
540         ERR("unexpected Config Caveat(%x)\n", tmp);
541         piValues[i] = WGL_NO_ACCELERATION_ARB;
542       }
543       continue ;
544
545     case WGL_TRANSPARENT_ARB:
546       curGLXAttr = GLX_TRANSPARENT_TYPE;
547       if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
548       curCfg = cfgs[iPixelFormat - 1];
549       hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, &tmp);
550       if (hTest) goto get_error;
551       piValues[i] = GL_FALSE;
552       if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
553       continue ;
554
555     case WGL_PIXEL_TYPE_ARB:
556       curGLXAttr = GLX_RENDER_TYPE;
557       if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
558       curCfg = cfgs[iPixelFormat - 1];
559       hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, &tmp);
560       if (hTest) goto get_error;
561       switch (tmp) {
562       case GLX_RGBA_BIT: piValues[i] = WGL_TYPE_RGBA_ARB; break;
563       case GLX_COLOR_INDEX_BIT: piValues[i] = WGL_TYPE_COLORINDEX_ARB; break ;
564       default:
565         ERR("unexpected RenderType(%x)\n", tmp);
566         piValues[i] = WGL_TYPE_RGBA_ARB;
567       }
568       continue ;
569       
570     case WGL_COLOR_BITS_ARB:
571       /** see ConvertAttribWGLtoGLX for explain */
572       if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
573       curCfg = cfgs[iPixelFormat - 1];
574       hTest = glXGetFBConfigAttrib(display, curCfg, GLX_BUFFER_SIZE, piValues + i);
575       if (hTest) goto get_error;
576       hTest = glXGetFBConfigAttrib(display, curCfg, GLX_ALPHA_SIZE, &tmp);
577       if (hTest) goto get_error;
578       piValues[i] = piValues[i] - tmp;
579       break;
580
581     case WGL_BLUE_BITS_ARB:
582       curGLXAttr = GLX_BLUE_SIZE;
583       break;
584     case WGL_RED_BITS_ARB:
585       curGLXAttr = GLX_RED_SIZE;
586       break;
587     case WGL_GREEN_BITS_ARB:
588       curGLXAttr = GLX_GREEN_SIZE;
589       break;
590     case WGL_ALPHA_BITS_ARB:
591       curGLXAttr = GLX_ALPHA_SIZE;
592       break;
593     case WGL_DEPTH_BITS_ARB:
594       curGLXAttr = GLX_DEPTH_SIZE;
595       break;
596     case WGL_STENCIL_BITS_ARB:
597       curGLXAttr = GLX_STENCIL_SIZE;
598       break;
599     case WGL_DOUBLE_BUFFER_ARB:
600       curGLXAttr = GLX_DOUBLEBUFFER;
601       break;
602     case WGL_STEREO_ARB:
603       curGLXAttr = GLX_STEREO;
604       break;
605     case WGL_AUX_BUFFERS_ARB:
606       curGLXAttr = GLX_AUX_BUFFERS;
607       break;
608
609     case WGL_SUPPORT_GDI_ARB:
610     case WGL_DRAW_TO_WINDOW_ARB:
611     case WGL_DRAW_TO_BITMAP_ARB:
612     case WGL_DRAW_TO_PBUFFER_ARB:
613       curGLXAttr = GLX_X_RENDERABLE;
614       break;
615
616     case WGL_PBUFFER_LARGEST_ARB:
617       curGLXAttr = GLX_LARGEST_PBUFFER;
618       break;
619
620     case WGL_SAMPLE_BUFFERS_ARB:
621       curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
622       break;
623       
624     case WGL_SAMPLES_ARB:
625       curGLXAttr = GLX_SAMPLES_ARB;
626       break;
627
628     case WGL_BIND_TO_TEXTURE_RGB_ARB: 
629     case WGL_BIND_TO_TEXTURE_RGBA_ARB:
630       if (!use_render_texture_emulation) {
631         piValues[i] = GL_FALSE;
632         continue ;      
633       }
634       curGLXAttr = GLX_RENDER_TYPE;
635       if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
636       curCfg = cfgs[iPixelFormat - 1];
637       hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, &tmp);
638       if (hTest) goto get_error;
639       if (GLX_COLOR_INDEX_BIT == tmp) {
640         piValues[i] = GL_FALSE;  
641         continue ;
642       }
643       curGLXAttr = GLX_X_RENDERABLE;
644       break;
645
646     default:
647       FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
648     }
649     
650     if (0 != curGLXAttr) {
651       if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
652       curCfg = cfgs[iPixelFormat - 1];
653       hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, piValues + i);
654       if (hTest) goto get_error;
655     } else { 
656       piValues[i] = GL_FALSE; 
657     }
658   }
659   
660   return GL_TRUE;
661
662 get_error:
663   ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
664   XFree(cfgs);
665   return GL_FALSE;
666
667 pix_error:
668   ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nCfgs);
669   XFree(cfgs);
670   return GL_FALSE;
671 }
672
673 GLboolean WINAPI wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
674 {
675     FIXME("(%p, %d, %d, %d, %p, %p): stub\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
676     return GL_FALSE;
677 }
678 /**
679  * http://publib.boulder.ibm.com/infocenter/pseries/index.jsp?topic=/com.ibm.aix.doc/libs/openglrf/glXChooseFBConfig.htm
680  */
681 GLboolean WINAPI wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
682 {
683   Display* display = get_display( hdc );
684   int gl_test = 0;
685   int attribs[256];
686   unsigned nAttribs = 0;
687
688   GLXFBConfig* cfgs = NULL;
689   int nCfgs = 0;
690   UINT it;
691   int fmt_id;
692
693   GLXFBConfig* cfgs_fmt = NULL;
694   int nCfgs_fmt = 0;
695   UINT it_fmt;
696   int tmp_fmt_id;
697
698   int pfmt_it = 0;
699
700   TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
701   if (NULL != pfAttribFList) {
702     FIXME("unused pfAttribFList\n");
703   }
704
705   nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
706   PUSH1(attribs, None);
707
708   cfgs = glXChooseFBConfig(display, DefaultScreen(display), attribs, &nCfgs);
709   if (NULL == cfgs) {
710     WARN("Compatible Pixel Format not found\n");
711     return GL_FALSE;
712   }
713
714   cfgs_fmt = glXGetFBConfigs(display, DefaultScreen(display), &nCfgs_fmt);
715   if (NULL == cfgs_fmt) {
716     ERR("Failed to get All FB Configs\n");
717     XFree(cfgs);
718     return GL_FALSE;
719   }
720
721   for (it = 0; it < nMaxFormats && it < nCfgs; ++it) {
722     gl_test = glXGetFBConfigAttrib(display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
723     if (gl_test) {
724       ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
725       continue ;
726     }
727     for (it_fmt = 0; it_fmt < nCfgs_fmt; ++it_fmt) {
728       gl_test = glXGetFBConfigAttrib(display, cfgs_fmt[it_fmt], GLX_FBCONFIG_ID, &tmp_fmt_id);
729       if (gl_test) {
730         ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
731         continue ;
732       }
733       if (fmt_id == tmp_fmt_id) {
734         int tmp;
735         piFormats[pfmt_it] = it_fmt + 1;
736         ++pfmt_it;
737         glXGetFBConfigAttrib(display, cfgs_fmt[it_fmt], GLX_ALPHA_SIZE, &tmp);
738         TRACE("for FBCONFIG_ID(%d/%d) found '%d'\n", it_fmt + 1, nCfgs_fmt, tmp);
739         break ;
740       }
741     }
742     if (it_fmt == nCfgs_fmt) {
743       ERR("Failed to get valid fmt for %d. Try next.\n", it);
744       continue ;
745     }
746     TRACE("at %d/%d found FBCONFIG_ID(%d/%d)\n", it + 1, nCfgs, piFormats[it], nCfgs_fmt);
747   }
748   
749   *nNumFormats = pfmt_it;
750   /** free list */
751   XFree(cfgs);
752   XFree(cfgs_fmt);
753   return GL_TRUE;
754 }
755
756 #define HPBUFFERARB void *
757 HPBUFFERARB WINAPI wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
758 {
759   Wine_GLPBuffer* object = NULL;
760   Display* display = get_display( hdc );
761   GLXFBConfig* cfgs = NULL;
762   int nCfgs = 0;
763   int attribs[256];
764   unsigned nAttribs = 0;
765
766   TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
767
768   if (0 >= iPixelFormat) {
769     ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
770     SetLastError(ERROR_INVALID_PIXEL_FORMAT);
771     return NULL; /* unespected error */
772   }
773
774   cfgs = glXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
775
776   if (NULL == cfgs || 0 == nCfgs) {
777     ERR("(%p): Cannot get FB Configs for iPixelFormat(%d), returns NULL\n", hdc, iPixelFormat);
778     SetLastError(ERROR_INVALID_PIXEL_FORMAT);
779     return NULL; /* unespected error */
780   }
781   if (nCfgs < iPixelFormat) {
782     ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
783     SetLastError(ERROR_INVALID_PIXEL_FORMAT);
784     goto create_failed; /* unespected error */
785   }
786
787   object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
788   if (NULL == object) {
789     SetLastError(ERROR_NO_SYSTEM_RESOURCES);
790     goto create_failed; /* unespected error */
791   }
792   object->hdc = hdc;
793   object->display = display;
794   object->width = iWidth;
795   object->height = iHeight;
796   object->pixelFormat = iPixelFormat;
797
798   nAttribs = ConvertAttribWGLtoGLX(piAttribList, attribs, object);
799   PUSH2(attribs, GLX_PBUFFER_WIDTH,  iWidth);
800   PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight); 
801   PUSH1(attribs, None);
802
803   while (0 != *piAttribList) {
804     int attr_v;
805     switch (*piAttribList) {
806     case WGL_TEXTURE_FORMAT_ARB: {
807       if (!use_render_texture_emulation) {
808         SetLastError(ERROR_INVALID_DATA);         
809         goto create_failed;
810       }
811       ++piAttribList;
812       attr_v = *piAttribList;
813       TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
814       switch (attr_v) {
815       case WGL_TEXTURE_RGB_ARB:
816       case WGL_TEXTURE_RGBA_ARB:
817       case WGL_NO_TEXTURE_ARB:
818         break;
819       default:
820         SetLastError(ERROR_INVALID_DATA);         
821         goto create_failed;
822       }
823       break;
824     }
825     
826     case WGL_TEXTURE_TARGET_ARB: {
827       if (!use_render_texture_emulation) {
828         SetLastError(ERROR_INVALID_DATA);         
829         goto create_failed;
830       }
831       ++piAttribList;
832       attr_v = *piAttribList;
833       TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
834       switch (attr_v) {
835       case WGL_TEXTURE_CUBE_MAP_ARB: {
836         if (iWidth != iHeight) {
837           SetLastError(ERROR_INVALID_DATA);       
838           goto create_failed;
839         }
840         object->texture_target = GL_TEXTURE_CUBE_MAP;
841         object->texture_bind_target = GL_TEXTURE_CUBE_MAP;
842         break;
843       }
844       case WGL_TEXTURE_1D_ARB: {
845         if (1 != iHeight) {
846           SetLastError(ERROR_INVALID_DATA);       
847           goto create_failed;
848         }
849         object->texture_target = GL_TEXTURE_1D;
850         object->texture_bind_target = GL_TEXTURE_1D;
851         break;
852       }
853       case WGL_TEXTURE_2D_ARB: {
854         object->texture_target = GL_TEXTURE_2D;
855         object->texture_bind_target = GL_TEXTURE_2D;
856         break;
857       }
858       case WGL_NO_TEXTURE_ARB:
859         break;
860       default:
861         SetLastError(ERROR_INVALID_DATA);         
862         goto create_failed;
863       }
864       break;
865     }
866
867     case WGL_MIPMAP_TEXTURE_ARB: {
868       if (!use_render_texture_emulation) {
869         SetLastError(ERROR_INVALID_DATA);         
870         goto create_failed;
871       }
872       ++piAttribList;
873       attr_v = *piAttribList;
874       TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
875       if (0 != attr_v) {
876         SetLastError(ERROR_INVALID_DATA);         
877         goto create_failed;     
878       }
879       break ;
880     }
881
882     }
883     ++piAttribList;
884   }
885
886   object->drawable = glXCreatePbuffer(display, cfgs[iPixelFormat - 1], attribs);
887   TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
888   if (!object->drawable) {
889     SetLastError(ERROR_NO_SYSTEM_RESOURCES);
890     goto create_failed; /* unespected error */
891   }
892   TRACE("->(%p)\n", object);
893
894   /** free list */
895   XFree(cfgs);
896   return (HPBUFFERARB) object;
897
898 create_failed:
899   if (NULL != cfgs) XFree(cfgs);
900   if (NULL != object) HeapFree(GetProcessHeap(), 0, object);
901   TRACE("->(FAILED)\n");
902   return (HPBUFFERARB) NULL;
903 }
904
905 HDC WINAPI wglGetPbufferDCARB(HPBUFFERARB hPbuffer)
906 {
907   Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
908   HDC hDC;
909   if (NULL == object) {
910     SetLastError(ERROR_INVALID_HANDLE);
911     return NULL;
912   }
913   hDC = CreateCompatibleDC(object->hdc);
914   set_drawable(hDC, object->drawable); /* works ?? */
915   TRACE("(%p)->(%p)\n", hPbuffer, hDC);
916   return hDC;
917 }
918
919 int WINAPI wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
920 {
921   TRACE("(%p, %p)\n", hPbuffer, hdc);
922   DeleteDC(hdc);
923   return 0;
924 }
925
926 GLboolean WINAPI wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
927 {
928   Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
929   TRACE("(%p)\n", hPbuffer);
930   if (NULL == object) {
931     SetLastError(ERROR_INVALID_HANDLE);
932     return GL_FALSE;
933   }
934   glXDestroyPbuffer(object->display, object->drawable);
935   HeapFree(GetProcessHeap(), 0, object);
936   return GL_TRUE;
937 }
938
939 GLboolean WINAPI wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
940 {
941   Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
942   TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
943   if (NULL == object) {
944     SetLastError(ERROR_INVALID_HANDLE);
945     return GL_FALSE;
946   }
947   switch (iAttribute) {
948   case WGL_PBUFFER_WIDTH_ARB:
949     glXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
950     break;
951   case WGL_PBUFFER_HEIGHT_ARB:
952     glXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
953     break;
954
955   case WGL_PBUFFER_LOST_ARB:
956     FIXME("unsupported WGL_PBUFFER_LOST_ARB (need glXSelectEvent/GLX_DAMAGED work)\n");
957     break;
958
959   case WGL_TEXTURE_FORMAT_ARB:
960   case WGL_TEXTURE_TARGET_ARB:
961   case WGL_MIPMAP_TEXTURE_ARB:
962     if (!object->use_render_texture) {
963       SetLastError(ERROR_INVALID_HANDLE);
964       return GL_FALSE;
965     }
966     if (!use_render_texture_emulation) {
967       SetLastError(ERROR_INVALID_DATA);      
968       return GL_FALSE; /** how to FIX ? */
969     }
970     FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
971     break;
972
973   default:
974     FIXME("unexpected attribute %x\n", iAttribute);
975     break;
976   }
977
978   return GL_TRUE;
979 }
980
981 GLboolean WINAPI wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
982 {
983   Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
984   TRACE("(%p, %d)\n", hPbuffer, iBuffer);
985   if (NULL == object) {
986     SetLastError(ERROR_INVALID_HANDLE);
987     return GL_FALSE;
988   }
989   if (!object->use_render_texture) {
990     SetLastError(ERROR_INVALID_HANDLE);
991     return GL_FALSE;
992   }
993   if (1 == use_render_texture_emulation) {
994     return GL_TRUE;
995   }
996   if (NULL != p_glXBindTexImageARB) {
997     return p_glXBindTexImageARB(object->display, object->drawable, iBuffer);
998   }
999   return GL_FALSE;
1000 }
1001
1002 GLboolean WINAPI wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
1003 {
1004   Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
1005   TRACE("(%p, %d)\n", hPbuffer, iBuffer);
1006   if (NULL == object) {
1007     SetLastError(ERROR_INVALID_HANDLE);
1008     return GL_FALSE;
1009   }
1010   if (!object->use_render_texture) {
1011     SetLastError(ERROR_INVALID_HANDLE);
1012     return GL_FALSE;
1013   }
1014   if (1 == use_render_texture_emulation) {
1015     GLint prev_binded_tex;
1016     glGetIntegerv(object->texture_target, &prev_binded_tex);
1017     glBindTexture(object->texture_target, object->texture);
1018     if (GL_TEXTURE_1D == object->texture_target) {
1019       glCopyTexSubImage1D(object->texture_bind_target, object->texture_level, 0, 0, 0, object->width);
1020     } else {
1021       glCopyTexSubImage2D(object->texture_bind_target, object->texture_level, 0, 0, 0, 0, object->width, object->height);
1022     }
1023     glBindTexture(object->texture_target, prev_binded_tex);
1024     return GL_TRUE;
1025   }
1026   if (NULL != p_glXReleaseTexImageARB) {
1027     return p_glXReleaseTexImageARB(object->display, object->drawable, iBuffer);
1028   }
1029   return GL_FALSE;
1030 }
1031
1032 GLboolean WINAPI wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
1033 {
1034   Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
1035   WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
1036   if (NULL == object) {
1037     SetLastError(ERROR_INVALID_HANDLE);
1038     return GL_FALSE;
1039   }
1040   if (!object->use_render_texture) {
1041     SetLastError(ERROR_INVALID_HANDLE);
1042     return GL_FALSE;
1043   }
1044   if (1 == use_render_texture_emulation) {
1045     return GL_TRUE;
1046   }
1047   if (NULL != p_glXDrawableAttribARB) {
1048     return p_glXDrawableAttribARB(object->display, object->drawable, piAttribList); 
1049   }
1050   return GL_FALSE;
1051 }
1052
1053 static const struct {
1054     const char *name;
1055     BOOL (*query_function)(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions,
1056                            const char *glx_version, const char *glx_extensions,
1057                            const char *server_glx_extensions, const char *client_glx_extensions);
1058 } extension_list[] = {
1059   { "WGL_ARB_make_current_read", query_function_make_current_read },
1060   { "WGL_ARB_multisample",       query_function_multisample },
1061   { "WGL_ARB_pbuffer",           query_function_pbuffer },
1062   { "WGL_ARB_pixel_format" ,     query_function_pixel_format },
1063   { "WGL_ARB_render_texture",    query_function_render_texture },
1064   { "WGL_EXT_swap_control",      query_function_swap_control }
1065 };
1066
1067 /* Used to initialize the WGL extension string at DLL loading */
1068 void wgl_ext_initialize_extensions(Display *display, int screen, glXGetProcAddressARB_t proc, const char* disabled_extensions)
1069 {
1070     int size = strlen(WGL_extensions_base);
1071     const char *glx_extensions = glXQueryExtensionsString(display, screen);
1072     const char *server_glx_extensions = glXQueryServerString(display, screen, GLX_EXTENSIONS);
1073     const char *client_glx_extensions = glXGetClientString(display, GLX_EXTENSIONS);
1074     const char *gl_extensions = (const char *) glGetString(GL_EXTENSIONS);
1075     const char *gl_version = (const char *) glGetString(GL_VERSION);
1076     const char *glx_version = glXGetClientString(display, GLX_VERSION);
1077     int i;
1078
1079     TRACE("GL version      : %s.\n", debugstr_a(gl_version));
1080     TRACE("GL exts         : %s.\n", debugstr_a(gl_extensions));
1081     TRACE("GLX exts        : %s.\n", debugstr_a(glx_extensions));
1082     TRACE("Server GLX exts : %s.\n", debugstr_a(server_glx_extensions));
1083     TRACE("Client GLX exts : %s.\n", debugstr_a(client_glx_extensions));
1084
1085     for (i = 0; i < (sizeof(extension_list) / sizeof(extension_list[0])); i++) {
1086         if (strstr(disabled_extensions, extension_list[i].name)) continue ; /* disabled by config, next */
1087         if (extension_list[i].query_function(proc, 
1088                                              gl_version, gl_extensions, 
1089                                              glx_version, glx_extensions,
1090                                              server_glx_extensions, client_glx_extensions)) {
1091             size += strlen(extension_list[i].name) + 1;
1092         }
1093     }
1094
1095     /* For the moment, only 'base' extensions are supported. */
1096     WGL_extensions = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + 1);
1097     if (WGL_extensions == NULL) {
1098         WGL_extensions = (char *) WGL_extensions_base;
1099     } else {
1100         strcpy(WGL_extensions, WGL_extensions_base);
1101         for (i = 0; i < (sizeof(extension_list) / sizeof(extension_list[0])); i++) {
1102             if (strstr(disabled_extensions, extension_list[i].name)) continue ; /* disabled by config, next */
1103             if (extension_list[i].query_function(proc, 
1104                                                  gl_version, gl_extensions, 
1105                                                  glx_version, glx_extensions,
1106                                                  server_glx_extensions, client_glx_extensions)) {
1107                 strcat(WGL_extensions, " ");
1108                 strcat(WGL_extensions, extension_list[i].name);
1109             }
1110         }
1111     }
1112
1113     TRACE("Supporting following WGL extensions : %s.\n", debugstr_a(WGL_extensions));
1114 }
1115
1116 void wgl_ext_finalize_extensions(void)
1117 {
1118     if (WGL_extensions != WGL_extensions_base) {
1119         HeapFree(GetProcessHeap(), 0, WGL_extensions);
1120     }
1121 }
1122
1123 /*
1124  * Putting this at the end to prevent having to write the prototypes :-) 
1125  *
1126  * @WARNING: this list must be ordered by name
1127  *
1128  * @TODO: real handle caps on providing some func_init functions (third param, ex: to check extensions)
1129  */
1130 WGL_extension wgl_extension_registry[] = {
1131     { "wglBindTexImageARB", (void *) wglBindTexImageARB, NULL, NULL},
1132     { "wglChoosePixelFormatARB", (void *) wglChoosePixelFormatARB, NULL, NULL},
1133     { "wglCreatePbufferARB", (void *) wglCreatePbufferARB, NULL, NULL},
1134     { "wglDestroyPbufferARB", (void *) wglDestroyPbufferARB, NULL, NULL},
1135     { "wglGetCurrentReadDCARB", (void *) wglGetCurrentReadDCARB, NULL, NULL},
1136     { "wglGetExtensionsStringARB", (void *) wglGetExtensionsStringARB, NULL, NULL},
1137     { "wglGetExtensionsStringEXT", (void *) wglGetExtensionsStringEXT, NULL, NULL},
1138     { "wglGetPbufferDCARB", (void *) wglGetPbufferDCARB, NULL, NULL},
1139     { "wglGetPixelFormatAttribfvARB", (void *) wglGetPixelFormatAttribfvARB, NULL, NULL},
1140     { "wglGetPixelFormatAttribivARB", (void *) wglGetPixelFormatAttribivARB, NULL, NULL},
1141     { "wglGetSwapIntervalEXT", (void *) wglGetSwapIntervalEXT, NULL, NULL},
1142     { "wglMakeContextCurrentARB", (void *) wglMakeContextCurrentARB, NULL, NULL },
1143     { "wglQueryPbufferARB", (void *) wglQueryPbufferARB, NULL, NULL},
1144     { "wglReleasePbufferDCARB", (void *) wglReleasePbufferDCARB, NULL, NULL},
1145     { "wglReleaseTexImageARB", (void *) wglReleaseTexImageARB, NULL, NULL},
1146     { "wglSetPbufferAttribARB", (void *) wglSetPbufferAttribARB, NULL, NULL},
1147     { "wglSwapIntervalEXT", (void *) wglSwapIntervalEXT, NULL, NULL}
1148 };
1149 int wgl_extension_registry_size = sizeof(wgl_extension_registry) / sizeof(wgl_extension_registry[0]);