Added a few more Unicode digits from Unicode version 4.1.
[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
344   while (0 != iWGLAttr[cur]) {
345     TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
346
347     switch (iWGLAttr[cur]) {
348     case WGL_COLOR_BITS_ARB:
349       pop = iWGLAttr[++cur];
350       PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
351       TRACE("pAttr[%d] = WGL_COLOR_BITS_ARB: %d\n", cur, pop);
352       break;
353     case WGL_BLUE_BITS_ARB:
354       pop = iWGLAttr[++cur];
355       PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
356       TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
357       break;
358     case WGL_RED_BITS_ARB:
359       pop = iWGLAttr[++cur];
360       PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
361       TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
362       break;
363     case WGL_GREEN_BITS_ARB:
364       pop = iWGLAttr[++cur];
365       PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
366       TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
367       break;
368     case WGL_ALPHA_BITS_ARB:
369       pop = iWGLAttr[++cur];
370       PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
371       TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
372       break;
373     case WGL_DEPTH_BITS_ARB:
374       pop = iWGLAttr[++cur];
375       PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
376       TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
377       break;
378     case WGL_STENCIL_BITS_ARB:
379       pop = iWGLAttr[++cur];
380       PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
381       TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
382       break;
383     case WGL_DOUBLE_BUFFER_ARB:
384       pop = iWGLAttr[++cur];
385       PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
386       TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
387       break;
388
389     case WGL_PIXEL_TYPE_ARB:
390       pop = iWGLAttr[++cur];
391       switch (pop) {
392       case WGL_TYPE_RGBA_ARB:  pop = GLX_RGBA_BIT; break ; 
393       case WGL_TYPE_COLORINDEX_ARB: pop = GLX_COLOR_INDEX_BIT; break ;
394       default:
395         ERR("unexpected PixelType(%x)\n", pop); 
396         pop = 0;
397       }
398       PUSH2(oGLXAttr, GLX_RENDER_TYPE, pop);
399       TRACE("pAttr[%d] = GLX_RENDER_TYPE: %d\n", cur, pop);
400       break;
401
402     case WGL_SUPPORT_GDI_ARB:
403     case WGL_DRAW_TO_WINDOW_ARB:
404     case WGL_DRAW_TO_BITMAP_ARB:
405     case WGL_DRAW_TO_PBUFFER_ARB:
406       pop = iWGLAttr[++cur];
407       PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
408       TRACE("pAttr[%d] = GLX_RENDERABLE: %d\n", cur, pop);
409       break;
410
411     case WGL_ACCELERATION_ARB:
412     case WGL_SUPPORT_OPENGL_ARB:
413       pop = iWGLAttr[++cur];
414       /** nothing to do, if we are here, supposing support Accelerated OpenGL */
415       TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
416       break;
417
418     case WGL_PBUFFER_LARGEST_ARB:
419       pop = iWGLAttr[++cur];
420       PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
421       TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
422       break;
423
424     case WGL_SAMPLE_BUFFERS_ARB:
425       pop = iWGLAttr[++cur];
426       PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
427       TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
428       break;
429       
430     case WGL_SAMPLES_ARB:
431       pop = iWGLAttr[++cur];
432       PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
433       TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
434       break;
435
436     case WGL_TEXTURE_FORMAT_ARB:
437     case WGL_TEXTURE_TARGET_ARB:
438     case WGL_MIPMAP_TEXTURE_ARB:
439       TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
440       if (NULL == pbuf) {
441         ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
442       }
443       if (!use_render_texture_emulation) {
444         ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
445       }
446       pop = iWGLAttr[++cur];
447       break ;
448
449     default:
450       FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
451       break;
452     }
453     ++cur;
454   }
455   return nAttribs;
456 }
457
458 GLboolean WINAPI wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
459 {
460   Display* display = get_display( hdc );
461   UINT i;
462   GLXFBConfig* cfgs = NULL;
463   GLXFBConfig  curCfg = NULL;
464   int nCfgs = 0;
465   int hTest;
466   int tmp;
467   int curGLXAttr = 0;
468
469   TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
470   
471   if (0 < iLayerPlane) {
472     FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
473     return GL_FALSE;
474   }
475
476   cfgs = glXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
477   if (NULL == cfgs) {
478     ERR("no FB Configs found for display(%p)\n", display);
479     return GL_FALSE;
480   }
481
482   for (i = 0; i < nAttributes; ++i) {
483     const int curWGLAttr = piAttributes[i];
484     TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
485     
486     switch (curWGLAttr) {
487     case WGL_NUMBER_PIXEL_FORMATS_ARB:
488       piValues[i] = nCfgs; 
489       continue ;
490
491     case WGL_SUPPORT_OPENGL_ARB:
492       piValues[i] = GL_TRUE; 
493       continue ;
494
495     case WGL_ACCELERATION_ARB:
496       curGLXAttr = GLX_CONFIG_CAVEAT;
497       if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
498       curCfg = cfgs[iPixelFormat - 1];
499       hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, &tmp);
500       if (hTest) goto get_error;
501       switch (tmp) {
502       case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
503       case GLX_SLOW_CONFIG: piValues[i] = WGL_NO_ACCELERATION_ARB; break;
504       case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
505       default:
506         ERR("unexpected Config Caveat(%x)\n", tmp);
507         piValues[i] = WGL_NO_ACCELERATION_ARB;
508       }
509       continue ;
510
511     case WGL_TRANSPARENT_ARB:
512       curGLXAttr = GLX_TRANSPARENT_TYPE;
513       if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
514       curCfg = cfgs[iPixelFormat - 1];
515       hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, &tmp);
516       if (hTest) goto get_error;
517       piValues[i] = GL_FALSE;
518       if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
519       continue ;
520
521     case WGL_PIXEL_TYPE_ARB:
522       curGLXAttr = GLX_RENDER_TYPE;
523       if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
524       curCfg = cfgs[iPixelFormat - 1];
525       hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, &tmp);
526       if (hTest) goto get_error;
527       switch (tmp) {
528       case GLX_RGBA_BIT: piValues[i] = WGL_TYPE_RGBA_ARB; break;
529       case GLX_COLOR_INDEX_BIT: piValues[i] = WGL_TYPE_COLORINDEX_ARB; break ;
530       default:
531         ERR("unexpected RenderType(%x)\n", tmp);
532         piValues[i] = WGL_TYPE_RGBA_ARB;
533       }
534       continue ;
535       
536     case WGL_COLOR_BITS_ARB:
537       curGLXAttr = GLX_BUFFER_SIZE;
538       break;
539     case WGL_BLUE_BITS_ARB:
540       curGLXAttr = GLX_BLUE_SIZE;
541       break;
542     case WGL_RED_BITS_ARB:
543       curGLXAttr = GLX_RED_SIZE;
544       break;
545     case WGL_GREEN_BITS_ARB:
546       curGLXAttr = GLX_GREEN_SIZE;
547       break;
548     case WGL_ALPHA_BITS_ARB:
549       curGLXAttr = GLX_ALPHA_SIZE;
550       break;
551     case WGL_DEPTH_BITS_ARB:
552       curGLXAttr = GLX_DEPTH_SIZE;
553       break;
554     case WGL_STENCIL_BITS_ARB:
555       curGLXAttr = GLX_STENCIL_SIZE;
556       break;
557     case WGL_DOUBLE_BUFFER_ARB:
558       curGLXAttr = GLX_DOUBLEBUFFER;
559       break;
560     case WGL_STEREO_ARB:
561       curGLXAttr = GLX_STEREO;
562       break;
563     case WGL_AUX_BUFFERS_ARB:
564       curGLXAttr = GLX_AUX_BUFFERS;
565       break;
566
567     case WGL_SUPPORT_GDI_ARB:
568     case WGL_DRAW_TO_WINDOW_ARB:
569     case WGL_DRAW_TO_BITMAP_ARB:
570     case WGL_DRAW_TO_PBUFFER_ARB:
571       curGLXAttr = GLX_X_RENDERABLE;
572       break;
573
574     case WGL_PBUFFER_LARGEST_ARB:
575       curGLXAttr = GLX_LARGEST_PBUFFER;
576       break;
577
578     case WGL_SAMPLE_BUFFERS_ARB:
579       curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
580       break;
581       
582     case WGL_SAMPLES_ARB:
583       curGLXAttr = GLX_SAMPLES_ARB;
584       break;
585
586     case WGL_BIND_TO_TEXTURE_RGB_ARB: 
587     case WGL_BIND_TO_TEXTURE_RGBA_ARB:
588       if (!use_render_texture_emulation) {
589         piValues[i] = GL_FALSE;
590         continue ;      
591       }
592       curGLXAttr = GLX_RENDER_TYPE;
593       if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
594       curCfg = cfgs[iPixelFormat - 1];
595       hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, &tmp);
596       if (hTest) goto get_error;
597       if (GLX_COLOR_INDEX_BIT == tmp) {
598         piValues[i] = GL_FALSE;  
599         continue ;
600       }
601       curGLXAttr = GLX_X_RENDERABLE;
602       break;
603
604     default:
605       FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
606     }
607     
608     if (0 != curGLXAttr) {
609       if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
610       curCfg = cfgs[iPixelFormat - 1];
611       hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, piValues + i);
612       if (hTest) goto get_error;
613     } else { 
614       piValues[i] = GL_FALSE; 
615     }
616   }
617   
618   return GL_TRUE;
619
620 get_error:
621   ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
622   XFree(cfgs);
623   return GL_FALSE;
624
625 pix_error:
626   ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nCfgs);
627   XFree(cfgs);
628   return GL_FALSE;
629 }
630
631 GLboolean WINAPI wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
632 {
633     FIXME("(%p, %d, %d, %d, %p, %p): stub\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
634     return GL_FALSE;
635 }
636 /**
637  * http://publib.boulder.ibm.com/infocenter/pseries/index.jsp?topic=/com.ibm.aix.doc/libs/openglrf/glXChooseFBConfig.htm
638  */
639 GLboolean WINAPI wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
640 {
641   Display* display = get_display( hdc );
642   int gl_test = 0;
643   int attribs[256];
644   unsigned nAttribs = 0;
645
646   GLXFBConfig* cfgs = NULL;
647   int nCfgs = 0;
648   UINT it;
649   int fmt_id;
650
651   GLXFBConfig* cfgs_fmt = NULL;
652   int nCfgs_fmt = 0;
653   UINT it_fmt;
654   int tmp_fmt_id;
655
656   int pfmt_it = 0;
657
658   TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
659   if (NULL != pfAttribFList) {
660     FIXME("unused pfAttribFList\n");
661   }
662
663   nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
664   PUSH1(attribs, None);
665
666   cfgs = glXChooseFBConfig(display, DefaultScreen(display), attribs, &nCfgs);
667   if (NULL == cfgs) {
668     WARN("Compatible Pixel Format not found\n");
669     return GL_FALSE;
670   }
671
672   cfgs_fmt = glXGetFBConfigs(display, DefaultScreen(display), &nCfgs_fmt);
673   if (NULL == cfgs_fmt) {
674     ERR("Failed to get All FB Configs\n");
675     XFree(cfgs);
676     return GL_FALSE;
677   }
678
679   for (it = 0; it < nMaxFormats && it < nCfgs; ++it) {
680     gl_test = glXGetFBConfigAttrib(display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
681     if (gl_test) {
682       ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
683       continue ;
684     }
685     for (it_fmt = 0; it_fmt < nCfgs_fmt; ++it_fmt) {
686       gl_test = glXGetFBConfigAttrib(display, cfgs_fmt[it_fmt], GLX_FBCONFIG_ID, &tmp_fmt_id);
687       if (gl_test) {
688         ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
689         continue ;
690       }
691       if (fmt_id == tmp_fmt_id) {
692         int tmp;
693         piFormats[pfmt_it] = it_fmt + 1;
694         ++pfmt_it;
695         glXGetFBConfigAttrib(display, cfgs_fmt[it_fmt], GLX_ALPHA_SIZE, &tmp);
696         TRACE("for FBCONFIG_ID(%d/%d) found '%d'\n", it_fmt + 1, nCfgs_fmt, tmp);
697         break ;
698       }
699     }
700     if (it_fmt == nCfgs_fmt) {
701       ERR("Failed to get valid fmt for %d. Try next.\n", it);
702       continue ;
703     }
704     TRACE("at %d/%d found FBCONFIG_ID(%d/%d)\n", it + 1, nCfgs, piFormats[it], nCfgs_fmt);
705   }
706   
707   *nNumFormats = pfmt_it;
708   /** free list */
709   XFree(cfgs);
710   XFree(cfgs_fmt);
711   return GL_TRUE;
712 }
713
714 #define HPBUFFERARB void *
715 HPBUFFERARB WINAPI wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
716 {
717   Wine_GLPBuffer* object = NULL;
718   Display* display = get_display( hdc );
719   GLXFBConfig* cfgs = NULL;
720   int nCfgs = 0;
721   int attribs[256];
722   unsigned nAttribs = 0;
723
724   TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
725
726   if (0 >= iPixelFormat) {
727     ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
728     SetLastError(ERROR_INVALID_PIXEL_FORMAT);
729     return NULL; /* unespected error */
730   }
731
732   cfgs = glXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
733
734   if (NULL == cfgs || 0 == nCfgs) {
735     ERR("(%p): Cannot get FB Configs for iPixelFormat(%d), returns NULL\n", hdc, iPixelFormat);
736     SetLastError(ERROR_INVALID_PIXEL_FORMAT);
737     return NULL; /* unespected error */
738   }
739   if (nCfgs < iPixelFormat) {
740     ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
741     SetLastError(ERROR_INVALID_PIXEL_FORMAT);
742     goto create_failed; /* unespected error */
743   }
744
745   object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
746   if (NULL == object) {
747     SetLastError(ERROR_NO_SYSTEM_RESOURCES);
748     goto create_failed; /* unespected error */
749   }
750   object->hdc = hdc;
751   object->display = display;
752   object->width = iWidth;
753   object->height = iHeight;
754   object->pixelFormat = iPixelFormat;
755
756   nAttribs = ConvertAttribWGLtoGLX(piAttribList, attribs, object);
757   PUSH2(attribs, GLX_PBUFFER_WIDTH,  iWidth);
758   PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight); 
759   PUSH1(attribs, None);
760
761   while (0 != *piAttribList) {
762     int attr_v;
763     switch (*piAttribList) {
764     case WGL_TEXTURE_FORMAT_ARB: {
765       if (!use_render_texture_emulation) {
766         SetLastError(ERROR_INVALID_DATA);         
767         goto create_failed;
768       }
769       ++piAttribList;
770       attr_v = *piAttribList;
771       TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
772       switch (attr_v) {
773       case WGL_TEXTURE_RGB_ARB:
774       case WGL_TEXTURE_RGBA_ARB:
775       case WGL_NO_TEXTURE_ARB:
776         break;
777       default:
778         SetLastError(ERROR_INVALID_DATA);         
779         goto create_failed;
780       }
781       break;
782     }
783     
784     case WGL_TEXTURE_TARGET_ARB: {
785       if (!use_render_texture_emulation) {
786         SetLastError(ERROR_INVALID_DATA);         
787         goto create_failed;
788       }
789       ++piAttribList;
790       attr_v = *piAttribList;
791       TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
792       switch (attr_v) {
793       case WGL_TEXTURE_CUBE_MAP_ARB: {
794         if (iWidth != iHeight) {
795           SetLastError(ERROR_INVALID_DATA);       
796           goto create_failed;
797         }
798         object->texture_target = GL_TEXTURE_CUBE_MAP;
799         object->texture_bind_target = GL_TEXTURE_CUBE_MAP;
800         break;
801       }
802       case WGL_TEXTURE_1D_ARB: {
803         if (1 != iHeight) {
804           SetLastError(ERROR_INVALID_DATA);       
805           goto create_failed;
806         }
807         object->texture_target = GL_TEXTURE_1D;
808         object->texture_bind_target = GL_TEXTURE_1D;
809         break;
810       }
811       case WGL_TEXTURE_2D_ARB: {
812         object->texture_target = GL_TEXTURE_2D;
813         object->texture_bind_target = GL_TEXTURE_2D;
814         break;
815       }
816       case WGL_NO_TEXTURE_ARB:
817         break;
818       default:
819         SetLastError(ERROR_INVALID_DATA);         
820         goto create_failed;
821       }
822       break;
823     }
824
825     case WGL_MIPMAP_TEXTURE_ARB: {
826       if (!use_render_texture_emulation) {
827         SetLastError(ERROR_INVALID_DATA);         
828         goto create_failed;
829       }
830       ++piAttribList;
831       attr_v = *piAttribList;
832       TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
833       if (0 != attr_v) {
834         SetLastError(ERROR_INVALID_DATA);         
835         goto create_failed;     
836       }
837       break ;
838     }
839
840     }
841     ++piAttribList;
842   }
843
844   object->drawable = glXCreatePbuffer(display, cfgs[iPixelFormat - 1], attribs);
845   TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
846   if (!object->drawable) {
847     SetLastError(ERROR_NO_SYSTEM_RESOURCES);
848     goto create_failed; /* unespected error */
849   }
850   TRACE("->(%p)\n", object);
851
852   /** free list */
853   XFree(cfgs);
854   return (HPBUFFERARB) object;
855
856 create_failed:
857   if (NULL != cfgs) XFree(cfgs);
858   if (NULL != object) HeapFree(GetProcessHeap(), 0, object);
859   TRACE("->(FAILED)\n");
860   return (HPBUFFERARB) NULL;
861 }
862
863 HDC WINAPI wglGetPbufferDCARB(HPBUFFERARB hPbuffer)
864 {
865   Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
866   HDC hDC;
867   if (NULL == object) {
868     SetLastError(ERROR_INVALID_HANDLE);
869     return NULL;
870   }
871   hDC = CreateCompatibleDC(object->hdc);
872   set_drawable(hDC, object->drawable); /* works ?? */
873   TRACE("(%p)->(%p)\n", hPbuffer, hDC);
874   return hDC;
875 }
876
877 int WINAPI wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
878 {
879   TRACE("(%p, %p)\n", hPbuffer, hdc);
880   DeleteDC(hdc);
881   return 0;
882 }
883
884 GLboolean WINAPI wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
885 {
886   Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
887   TRACE("(%p)\n", hPbuffer);
888   if (NULL == object) {
889     SetLastError(ERROR_INVALID_HANDLE);
890     return GL_FALSE;
891   }
892   glXDestroyPbuffer(object->display, object->drawable);
893   HeapFree(GetProcessHeap(), 0, object);
894   return GL_TRUE;
895 }
896
897 GLboolean WINAPI wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
898 {
899   Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
900   TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
901   if (NULL == object) {
902     SetLastError(ERROR_INVALID_HANDLE);
903     return GL_FALSE;
904   }
905   switch (iAttribute) {
906   case WGL_PBUFFER_WIDTH_ARB:
907     glXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
908     break;
909   case WGL_PBUFFER_HEIGHT_ARB:
910     glXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
911     break;
912
913   case WGL_PBUFFER_LOST_ARB:
914     FIXME("unsupported WGL_PBUFFER_LOST_ARB (need glXSelectEvent/GLX_DAMAGED work)\n");
915     break;
916
917   case WGL_TEXTURE_FORMAT_ARB:
918   case WGL_TEXTURE_TARGET_ARB:
919   case WGL_MIPMAP_TEXTURE_ARB:
920     if (!object->use_render_texture) {
921       SetLastError(ERROR_INVALID_HANDLE);
922       return GL_FALSE;
923     }
924     if (!use_render_texture_emulation) {
925       SetLastError(ERROR_INVALID_DATA);      
926       return GL_FALSE; /** how to FIX ? */
927     }
928     FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
929     break;
930
931   default:
932     FIXME("unexpected attribute %x\n", iAttribute);
933     break;
934   }
935
936   return GL_TRUE;
937 }
938
939 GLboolean WINAPI wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
940 {
941   Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
942   TRACE("(%p, %d)\n", hPbuffer, iBuffer);
943   if (NULL == object) {
944     SetLastError(ERROR_INVALID_HANDLE);
945     return GL_FALSE;
946   }
947   if (!object->use_render_texture) {
948     SetLastError(ERROR_INVALID_HANDLE);
949     return GL_FALSE;
950   }
951   if (1 == use_render_texture_emulation) {
952     return GL_TRUE;
953   }
954   if (NULL != p_glXBindTexImageARB) {
955     return p_glXBindTexImageARB(object->display, object->drawable, iBuffer);
956   }
957   return GL_FALSE;
958 }
959
960 GLboolean WINAPI wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
961 {
962   Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
963   TRACE("(%p, %d)\n", hPbuffer, iBuffer);
964   if (NULL == object) {
965     SetLastError(ERROR_INVALID_HANDLE);
966     return GL_FALSE;
967   }
968   if (!object->use_render_texture) {
969     SetLastError(ERROR_INVALID_HANDLE);
970     return GL_FALSE;
971   }
972   if (1 == use_render_texture_emulation) {
973     GLint prev_binded_tex;
974     glGetIntegerv(object->texture_target, &prev_binded_tex);
975     glBindTexture(object->texture_target, object->texture);
976     if (GL_TEXTURE_1D == object->texture_target) {
977       glCopyTexSubImage1D(object->texture_bind_target, object->texture_level, 0, 0, 0, object->width);
978     } else {
979       glCopyTexSubImage2D(object->texture_bind_target, object->texture_level, 0, 0, 0, 0, object->width, object->height);
980     }
981     glBindTexture(object->texture_target, prev_binded_tex);
982     return GL_TRUE;
983   }
984   if (NULL != p_glXReleaseTexImageARB) {
985     return p_glXReleaseTexImageARB(object->display, object->drawable, iBuffer);
986   }
987   return GL_FALSE;
988 }
989
990 GLboolean WINAPI wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
991 {
992   Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
993   WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
994   if (NULL == object) {
995     SetLastError(ERROR_INVALID_HANDLE);
996     return GL_FALSE;
997   }
998   if (!object->use_render_texture) {
999     SetLastError(ERROR_INVALID_HANDLE);
1000     return GL_FALSE;
1001   }
1002   if (1 == use_render_texture_emulation) {
1003     return GL_TRUE;
1004   }
1005   if (NULL != p_glXDrawableAttribARB) {
1006     return p_glXDrawableAttribARB(object->display, object->drawable, piAttribList); 
1007   }
1008   return GL_FALSE;
1009 }
1010
1011 static const struct {
1012     const char *name;
1013     BOOL (*query_function)(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions,
1014                            const char *glx_version, const char *glx_extensions,
1015                            const char *server_glx_extensions, const char *client_glx_extensions);
1016 } extension_list[] = {
1017   { "WGL_ARB_make_current_read", query_function_make_current_read },
1018   { "WGL_ARB_multisample",       query_function_multisample },
1019   { "WGL_ARB_pbuffer",           query_function_pbuffer },
1020   { "WGL_ARB_pixel_format" ,     query_function_pixel_format },
1021   { "WGL_ARB_render_texture",    query_function_render_texture },
1022   { "WGL_EXT_swap_control",      query_function_swap_control }
1023 };
1024
1025 /* Used to initialize the WGL extension string at DLL loading */
1026 void wgl_ext_initialize_extensions(Display *display, int screen, glXGetProcAddressARB_t proc, const char* disabled_extensions)
1027 {
1028     int size = strlen(WGL_extensions_base);
1029     const char *glx_extensions = glXQueryExtensionsString(display, screen);
1030     const char *server_glx_extensions = glXQueryServerString(display, screen, GLX_EXTENSIONS);
1031     const char *client_glx_extensions = glXGetClientString(display, GLX_EXTENSIONS);
1032     const char *gl_extensions = (const char *) glGetString(GL_EXTENSIONS);
1033     const char *gl_version = (const char *) glGetString(GL_VERSION);
1034     const char *glx_version = glXGetClientString(display, GLX_VERSION);
1035     int i;
1036
1037     TRACE("GL version      : %s.\n", debugstr_a(gl_version));
1038     TRACE("GL exts         : %s.\n", debugstr_a(gl_extensions));
1039     TRACE("GLX exts        : %s.\n", debugstr_a(glx_extensions));
1040     TRACE("Server GLX exts : %s.\n", debugstr_a(server_glx_extensions));
1041     TRACE("Client GLX exts : %s.\n", debugstr_a(client_glx_extensions));
1042
1043     for (i = 0; i < (sizeof(extension_list) / sizeof(extension_list[0])); i++) {
1044         if (strstr(disabled_extensions, extension_list[i].name)) continue ; /* disabled by config, next */
1045         if (extension_list[i].query_function(proc, 
1046                                              gl_version, gl_extensions, 
1047                                              glx_version, glx_extensions,
1048                                              server_glx_extensions, client_glx_extensions)) {
1049             size += strlen(extension_list[i].name) + 1;
1050         }
1051     }
1052
1053     /* For the moment, only 'base' extensions are supported. */
1054     WGL_extensions = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + 1);
1055     if (WGL_extensions == NULL) {
1056         WGL_extensions = (char *) WGL_extensions_base;
1057     } else {
1058         strcpy(WGL_extensions, WGL_extensions_base);
1059         for (i = 0; i < (sizeof(extension_list) / sizeof(extension_list[0])); i++) {
1060             if (strstr(disabled_extensions, extension_list[i].name)) continue ; /* disabled by config, next */
1061             if (extension_list[i].query_function(proc, 
1062                                                  gl_version, gl_extensions, 
1063                                                  glx_version, glx_extensions,
1064                                                  server_glx_extensions, client_glx_extensions)) {
1065                 strcat(WGL_extensions, " ");
1066                 strcat(WGL_extensions, extension_list[i].name);
1067             }
1068         }
1069     }
1070
1071     TRACE("Supporting following WGL extensions : %s.\n", debugstr_a(WGL_extensions));
1072 }
1073
1074 void wgl_ext_finalize_extensions(void)
1075 {
1076     if (WGL_extensions != WGL_extensions_base) {
1077         HeapFree(GetProcessHeap(), 0, WGL_extensions);
1078     }
1079 }
1080
1081 /*
1082  * Putting this at the end to prevent having to write the prototypes :-) 
1083  *
1084  * @WARNING: this list must be ordered by name
1085  *
1086  * @TODO: real handle caps on providing some func_init functions (third param, ex: to check extensions)
1087  */
1088 WGL_extension wgl_extension_registry[] = {
1089     { "wglBindTexImageARB", (void *) wglBindTexImageARB, NULL, NULL},
1090     { "wglChoosePixelFormatARB", (void *) wglChoosePixelFormatARB, NULL, NULL},
1091     { "wglCreatePbufferARB", (void *) wglCreatePbufferARB, NULL, NULL},
1092     { "wglDestroyPbufferARB", (void *) wglDestroyPbufferARB, NULL, NULL},
1093     { "wglGetCurrentReadDCARB", (void *) wglGetCurrentReadDCARB, NULL, NULL},
1094     { "wglGetExtensionsStringARB", (void *) wglGetExtensionsStringARB, NULL, NULL},
1095     { "wglGetExtensionsStringEXT", (void *) wglGetExtensionsStringEXT, NULL, NULL},
1096     { "wglGetPbufferDCARB", (void *) wglGetPbufferDCARB, NULL, NULL},
1097     { "wglGetPixelFormatAttribfvARB", (void *) wglGetPixelFormatAttribfvARB, NULL, NULL},
1098     { "wglGetPixelFormatAttribivARB", (void *) wglGetPixelFormatAttribivARB, NULL, NULL},
1099     { "wglGetSwapIntervalEXT", (void *) wglGetSwapIntervalEXT, NULL, NULL},
1100     { "wglMakeContextCurrentARB", (void *) wglMakeContextCurrentARB, NULL, NULL },
1101     { "wglQueryPbufferARB", (void *) wglQueryPbufferARB, NULL, NULL},
1102     { "wglReleasePbufferDCARB", (void *) wglReleasePbufferDCARB, NULL, NULL},
1103     { "wglReleaseTexImageARB", (void *) wglReleaseTexImageARB, NULL, NULL},
1104     { "wglSetPbufferAttribARB", (void *) wglSetPbufferAttribARB, NULL, NULL},
1105     { "wglSwapIntervalEXT", (void *) wglSwapIntervalEXT, NULL, NULL}
1106 };
1107 int wgl_extension_registry_size = sizeof(wgl_extension_registry) / sizeof(wgl_extension_registry[0]);