1 /* Support for window-specific OpenGL extensions.
3 * Copyright (c) 2004 Lionel Ulmer
4 * Copyright (c) 2005 Alex Woods
5 * Copyright (c) 2005 Raphael Junqueira
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.
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.
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
23 #include "wine/port.h"
37 #include "opengl_ext.h"
38 #include "wine/library.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
44 /* x11drv GDI escapes */
45 #define X11DRV_ESCAPE 6789
46 enum x11drv_escape_codes
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 */
53 struct x11drv_escape_set_drawable
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 */
62 /* retrieve the X display to use on a given DC */
63 inline static Display *get_display( HDC hdc )
66 enum x11drv_escape_codes escape = X11DRV_GET_DISPLAY;
68 if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape,
69 sizeof(display), (LPSTR)&display )) display = NULL;
72 inline static void set_drawable( HDC hdc, Drawable drawable )
74 struct x11drv_escape_set_drawable escape;
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;
82 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape, 0, NULL );
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;
90 * Extensions-query functions
92 * @TODO: use a struct to handle parameters
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)
98 return 0 <= strcmp("1.3", glx_version);
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)
105 return NULL != strstr(glx_extensions, "GLX_ARB_multisample");
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)
112 FIXME("gl_version is: \"%s\"\n", gl_version);
113 FIXME("glx_exts is: \"%s\"\n", glx_extensions);
115 return 0 <= strcmp("1.3", glx_version) || NULL != strstr(glx_extensions, "GLX_SGIX_pbuffer");
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)
125 /** GLX_ARB_render_texture */
126 Bool (*p_glXBindTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
127 Bool (*p_glXReleaseTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
128 Bool (*p_glXDrawableAttribARB)(Display *dpy, GLXDrawable draw, const int *attribList);
130 BOOL query_function_render_texture(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions,
131 const char* glx_version, const char *glx_extensions,
132 const char *server_glx_extensions, const char *client_glx_extensions)
134 BOOL bTest = (0 <= strcmp("1.3", glx_version) || NULL != strstr(glx_extensions, "GLX_SGIX_pbuffer") || NULL != strstr(glx_extensions, "GLX_ARB_render_texture"));
136 p_glXBindTexImageARB = proc("glXBindTexImageARB");
137 p_glXReleaseTexImageARB = proc("glXReleaseTexImageARB");
138 p_glXDrawableAttribARB = proc("glXDrawableAttribARB");
139 bTest = (NULL != p_glXBindTexImageARB && NULL != p_glXReleaseTexImageARB && NULL != p_glXDrawableAttribARB);
144 int (*p_glXSwapIntervalSGI)(int);
145 BOOL query_function_swap_control(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions,
146 const char* glx_version, const char *glx_extensions,
147 const char *server_glx_extensions, const char *client_glx_extensions)
149 BOOL bTest = (0 <= strcmp("1.3", glx_version) || NULL != strstr(glx_extensions, "GLX_SGI_swap_control"));
151 p_glXSwapIntervalSGI = proc("glXSwapIntervalSGI");
152 bTest = (NULL != p_glXSwapIntervalSGI);
157 /***********************************************************************
158 * wglGetExtensionsStringEXT(OPENGL32.@)
160 const char * WINAPI wglGetExtensionsStringEXT(void) {
161 TRACE("() returning \"%s\"\n", WGL_extensions);
163 return WGL_extensions;
166 /***********************************************************************
167 * wglGetExtensionsStringARB(OPENGL32.@)
169 const char * WINAPI wglGetExtensionsStringARB(HDC hdc) {
170 TRACE("() returning \"%s\"\n", WGL_extensions);
172 return WGL_extensions;
175 static int swap_interval = 1;
177 /***********************************************************************
178 * wglSwapIntervalEXT(OPENGL32.@)
180 BOOL WINAPI wglSwapIntervalEXT(int interval) {
181 TRACE("(%d)\n", interval);
182 swap_interval = interval;
183 if (NULL != p_glXSwapIntervalSGI) {
184 return 0 == p_glXSwapIntervalSGI(interval);
186 WARN("(): GLX_SGI_swap_control extension seems not supported \n");
190 /***********************************************************************
191 * wglGetSwapIntervalEXT(OPENGL32.@)
193 int WINAPI wglGetSwapIntervalEXT(VOID) {
195 return swap_interval;
198 typedef struct wine_glpbuffer {
208 #define PUSH1(attribs,att) attribs[nAttribs++] = (att);
209 #define PUSH2(attribs,att,value) attribs[nAttribs++] = (att); attribs[nAttribs++] = (value);
211 #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
212 #define WGL_DRAW_TO_WINDOW_ARB 0x2001
213 #define WGL_DRAW_TO_BITMAP_ARB 0x2002
214 #define WGL_ACCELERATION_ARB 0x2003
215 #define WGL_NEED_PALETTE_ARB 0x2004
216 #define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005
217 #define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006
218 #define WGL_SWAP_METHOD_ARB 0x2007
219 #define WGL_NUMBER_OVERLAYS_ARB 0x2008
220 #define WGL_NUMBER_UNDERLAYS_ARB 0x2009
221 #define WGL_TRANSPARENT_ARB 0x200A
222 #define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037
223 #define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
224 #define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
225 #define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
226 #define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
227 #define WGL_SHARE_DEPTH_ARB 0x200C
228 #define WGL_SHARE_STENCIL_ARB 0x200D
229 #define WGL_SHARE_ACCUM_ARB 0x200E
230 #define WGL_SUPPORT_GDI_ARB 0x200F
231 #define WGL_SUPPORT_OPENGL_ARB 0x2010
232 #define WGL_DOUBLE_BUFFER_ARB 0x2011
233 #define WGL_STEREO_ARB 0x2012
234 #define WGL_PIXEL_TYPE_ARB 0x2013
235 #define WGL_COLOR_BITS_ARB 0x2014
236 #define WGL_RED_BITS_ARB 0x2015
237 #define WGL_RED_SHIFT_ARB 0x2016
238 #define WGL_GREEN_BITS_ARB 0x2017
239 #define WGL_GREEN_SHIFT_ARB 0x2018
240 #define WGL_BLUE_BITS_ARB 0x2019
241 #define WGL_BLUE_SHIFT_ARB 0x201A
242 #define WGL_ALPHA_BITS_ARB 0x201B
243 #define WGL_ALPHA_SHIFT_ARB 0x201C
244 #define WGL_ACCUM_BITS_ARB 0x201D
245 #define WGL_ACCUM_RED_BITS_ARB 0x201E
246 #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
247 #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
248 #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
249 #define WGL_DEPTH_BITS_ARB 0x2022
250 #define WGL_STENCIL_BITS_ARB 0x2023
251 #define WGL_AUX_BUFFERS_ARB 0x2024
253 #define WGL_NO_ACCELERATION_ARB 0x2025
254 #define WGL_GENERIC_ACCELERATION_ARB 0x2026
255 #define WGL_FULL_ACCELERATION_ARB 0x2027
257 #define WGL_PBUFFER_WIDTH_ARB 0x2034
258 #define WGL_PBUFFER_HEIGHT_ARB 0x2035
259 #define WGL_PBUFFER_LOST_ARB 0x2036
260 #define WGL_DRAW_TO_PBUFFER_ARB 0x202D
261 #define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E
262 #define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F
263 #define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030
264 #define WGL_PBUFFER_LARGEST_ARB 0x2033
266 #define WGL_TYPE_RGBA_ARB 0x202B
267 #define WGL_TYPE_COLORINDEX_ARB 0x202C
269 #define WGL_SAMPLE_BUFFERS_ARB 0x2041
270 #define WGL_SAMPLES_ARB 0x2042
272 #if 0 /* not used yet */
273 static unsigned ConvertAttribGLXtoWGL(const int* iWGLAttr, int* oGLXAttr) {
274 unsigned nAttribs = 0;
275 FIXME("not yet implemented!\n");
280 static unsigned ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr) {
281 unsigned nAttribs = 0;
285 while (0 != iWGLAttr[cur]) {
286 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
288 switch (iWGLAttr[cur]) {
289 case WGL_COLOR_BITS_ARB:
290 pop = iWGLAttr[++cur];
291 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
292 TRACE("pAttr[%d] = WGL_COLOR_BITS_ARB: %d\n", cur, pop);
294 case WGL_BLUE_BITS_ARB:
295 pop = iWGLAttr[++cur];
296 PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
297 TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
299 case WGL_RED_BITS_ARB:
300 pop = iWGLAttr[++cur];
301 TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
302 PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
304 case WGL_GREEN_BITS_ARB:
305 pop = iWGLAttr[++cur];
306 TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
307 PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
309 case WGL_ALPHA_BITS_ARB:
310 pop = iWGLAttr[++cur];
311 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
312 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
314 case WGL_DEPTH_BITS_ARB:
315 pop = iWGLAttr[++cur];
316 TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
317 PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
319 case WGL_STENCIL_BITS_ARB:
320 pop = iWGLAttr[++cur];
321 PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
322 TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
324 case WGL_DOUBLE_BUFFER_ARB:
325 pop = iWGLAttr[++cur];
326 PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
327 TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
330 case WGL_PIXEL_TYPE_ARB:
331 pop = iWGLAttr[++cur];
333 case WGL_TYPE_RGBA_ARB: pop = GLX_RGBA_BIT; break ;
334 case WGL_TYPE_COLORINDEX_ARB: pop = GLX_COLOR_INDEX_BIT; break ;
336 ERR("unexpected PixelType(%x)\n", pop);
339 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pop);
340 TRACE("pAttr[%d] = GLX_RENDER_TYPE: %d\n", cur, pop);
343 case WGL_SUPPORT_GDI_ARB:
344 case WGL_DRAW_TO_WINDOW_ARB:
345 case WGL_DRAW_TO_BITMAP_ARB:
346 case WGL_DRAW_TO_PBUFFER_ARB:
347 pop = iWGLAttr[++cur];
348 PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
349 TRACE("pAttr[%d] = GLX_RENDERABLE: %d\n", cur, pop);
352 case WGL_ACCELERATION_ARB:
353 case WGL_SUPPORT_OPENGL_ARB:
354 pop = iWGLAttr[++cur];
355 /** nothing to do, if we are here, supposing support Accelerated OpenGL */
356 TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
359 case WGL_PBUFFER_LARGEST_ARB:
360 pop = iWGLAttr[++cur];
361 PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
362 TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
365 case WGL_SAMPLE_BUFFERS_ARB:
366 pop = iWGLAttr[++cur];
367 PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
368 TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
371 case WGL_SAMPLES_ARB:
372 pop = iWGLAttr[++cur];
373 PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
374 TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
378 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
386 GLboolean WINAPI wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
388 Display* display = get_display( hdc );
390 GLXFBConfig* cfgs = NULL;
391 GLXFBConfig curCfg = NULL;
397 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
399 if (0 < iLayerPlane) {
400 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
404 cfgs = glXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
406 ERR("no FB Configs found for display(%p)\n", display);
410 for (i = 0; i < nAttributes; ++i) {
411 const int curWGLAttr = piAttributes[i];
412 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
414 switch (curWGLAttr) {
415 case WGL_NUMBER_PIXEL_FORMATS_ARB:
419 case WGL_SUPPORT_OPENGL_ARB:
420 piValues[i] = GL_TRUE;
423 case WGL_ACCELERATION_ARB:
424 curGLXAttr = GLX_CONFIG_CAVEAT;
425 if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
426 curCfg = cfgs[iPixelFormat - 1];
427 hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, &tmp);
428 if (hTest) goto get_error;
430 case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
431 case GLX_SLOW_CONFIG: piValues[i] = WGL_NO_ACCELERATION_ARB; break;
432 case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
434 ERR("unexpected Config Caveat(%x)\n", tmp);
435 piValues[i] = WGL_NO_ACCELERATION_ARB;
439 case WGL_TRANSPARENT_ARB:
440 curGLXAttr = GLX_TRANSPARENT_TYPE;
441 if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
442 curCfg = cfgs[iPixelFormat - 1];
443 hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, &tmp);
444 if (hTest) goto get_error;
445 piValues[i] = GL_FALSE;
446 if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
449 case WGL_PIXEL_TYPE_ARB:
450 curGLXAttr = GLX_RENDER_TYPE;
451 if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
452 curCfg = cfgs[iPixelFormat - 1];
453 hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, &tmp);
454 if (hTest) goto get_error;
456 case GLX_RGBA_BIT: piValues[i] = WGL_TYPE_RGBA_ARB; break;
457 case GLX_COLOR_INDEX_BIT: piValues[i] = WGL_TYPE_COLORINDEX_ARB; break ;
459 ERR("unexpected RenderType(%x)\n", tmp);
460 piValues[i] = WGL_TYPE_RGBA_ARB;
464 case WGL_COLOR_BITS_ARB:
465 curGLXAttr = GLX_BUFFER_SIZE;
467 case WGL_BLUE_BITS_ARB:
468 curGLXAttr = GLX_BLUE_SIZE;
470 case WGL_RED_BITS_ARB:
471 curGLXAttr = GLX_RED_SIZE;
473 case WGL_GREEN_BITS_ARB:
474 curGLXAttr = GLX_GREEN_SIZE;
476 case WGL_ALPHA_BITS_ARB:
477 curGLXAttr = GLX_ALPHA_SIZE;
479 case WGL_DEPTH_BITS_ARB:
480 curGLXAttr = GLX_DEPTH_SIZE;
482 case WGL_STENCIL_BITS_ARB:
483 curGLXAttr = GLX_STENCIL_SIZE;
485 case WGL_DOUBLE_BUFFER_ARB:
486 curGLXAttr = GLX_DOUBLEBUFFER;
489 curGLXAttr = GLX_STEREO;
491 case WGL_AUX_BUFFERS_ARB:
492 curGLXAttr = GLX_AUX_BUFFERS;
495 case WGL_SUPPORT_GDI_ARB:
496 case WGL_DRAW_TO_WINDOW_ARB:
497 case WGL_DRAW_TO_BITMAP_ARB:
498 case WGL_DRAW_TO_PBUFFER_ARB:
499 curGLXAttr = GLX_X_RENDERABLE;
502 case WGL_PBUFFER_LARGEST_ARB:
503 curGLXAttr = GLX_LARGEST_PBUFFER;
506 case WGL_SAMPLE_BUFFERS_ARB:
507 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
510 case WGL_SAMPLES_ARB:
511 curGLXAttr = GLX_SAMPLES_ARB;
515 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
518 if (0 != curGLXAttr) {
519 if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
520 curCfg = cfgs[iPixelFormat - 1];
521 hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, piValues + i);
522 if (hTest) goto get_error;
524 piValues[i] = GL_FALSE;
531 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
536 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nCfgs);
541 GLboolean WINAPI wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
543 FIXME("(%p, %d, %d, %d, %p, %p): stub\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
547 * http://publib.boulder.ibm.com/infocenter/pseries/index.jsp?topic=/com.ibm.aix.doc/libs/openglrf/glXChooseFBConfig.htm
549 GLboolean WINAPI wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
551 Display* display = get_display( hdc );
554 unsigned nAttribs = 0;
556 GLXFBConfig* cfgs = NULL;
561 GLXFBConfig* cfgs_fmt = NULL;
568 TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
569 if (NULL != pfAttribFList) {
570 FIXME("unused pfAttribFList\n");
573 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs);
574 PUSH1(attribs, None);
576 cfgs = glXChooseFBConfig(display, DefaultScreen(display), attribs, &nCfgs);
578 WARN("Compatible Pixel Format not found\n");
582 cfgs_fmt = glXGetFBConfigs(display, DefaultScreen(display), &nCfgs_fmt);
583 if (NULL == cfgs_fmt) {
584 ERR("Failed to get All FB Configs\n");
589 for (it = 0; it < nMaxFormats && it < nCfgs; ++it) {
590 gl_test = glXGetFBConfigAttrib(display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
592 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
595 for (it_fmt = 0; it_fmt < nCfgs_fmt; ++it_fmt) {
596 gl_test = glXGetFBConfigAttrib(display, cfgs_fmt[it_fmt], GLX_FBCONFIG_ID, &tmp_fmt_id);
598 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
601 if (fmt_id == tmp_fmt_id) {
602 piFormats[pfmt_it] = it_fmt + 1;
607 if (it_fmt == nCfgs_fmt) {
608 ERR("Failed to get valid fmt for %d. Try next.\n", it);
611 TRACE("at %d/%d found FBCONFIG_ID(%d/%d)\n", it + 1, nCfgs, piFormats[it], nCfgs_fmt);
614 *nNumFormats = pfmt_it;
621 #define HPBUFFERARB void *
622 HPBUFFERARB WINAPI wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
624 Wine_GLPBuffer* object = NULL;
625 Display* display = get_display( hdc );
626 GLXFBConfig* cfgs = NULL;
629 unsigned nAttribs = 0;
631 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
633 if (0 >= iPixelFormat) {
634 ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
635 return NULL; /* unespected error */
638 /*nAttribs = ConvertAttribWGLtoGLX(piAttribList, attribs);*/
641 PUSH2(attribs, GLX_FBCONFIG_ID, iPixelFormat);
642 PUSH1(attribs, None);
643 cfgs = glXChooseFBConfig(display, DefaultScreen(display), attribs, &nCfgs);
646 cfgs = glXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
648 if (NULL == cfgs || 0 == nCfgs) {
649 ERR("(%p): Cannot get FB Configs for iPixelFormat(%d), returns NULL\n", hdc, iPixelFormat);
650 return NULL; /* unespected error */
652 if (nCfgs < iPixelFormat) {
653 ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
655 return NULL; /* unespected error */
658 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
660 object->display = display;
661 object->width = iWidth;
662 object->height = iHeight;
663 object->pixelFormat = iPixelFormat;
665 nAttribs = ConvertAttribWGLtoGLX(piAttribList, attribs);
666 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
667 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
668 PUSH1(attribs, None);
670 object->drawable = glXCreatePbuffer(display, cfgs[iPixelFormat - 1], attribs);
671 TRACE("drawable as %p\n", (void*) object->drawable);
673 TRACE("->(%p)\n", object);
678 return (HPBUFFERARB) object;
681 HDC WINAPI wglGetPbufferDCARB(HPBUFFERARB hPbuffer)
683 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
685 hDC = CreateCompatibleDC(object->hdc);
686 set_drawable(hDC, object->drawable); /* works ?? */
687 TRACE("(%p)\n", hPbuffer);
691 int WINAPI wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
693 TRACE("(%p, %p)\n", hPbuffer, hdc);
698 GLboolean WINAPI wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
700 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
701 TRACE("(%p)\n", hPbuffer);
703 glXDestroyPbuffer(object->display, object->drawable);
704 HeapFree(GetProcessHeap(), 0, object);
709 GLboolean WINAPI wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
711 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
712 TRACE("(%p, %d, %p)\n", hPbuffer, iAttribute, piValue);
714 /*glXQueryDrawable(object->display, object->drawable);*/
716 switch (iAttribute) {
717 case WGL_PBUFFER_WIDTH_ARB:
718 glXQueryDrawable(object->display, object->drawable, GLX_WIDTH, piValue);
720 case WGL_PBUFFER_HEIGHT_ARB:
721 glXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, piValue);
724 case WGL_PBUFFER_LOST_ARB:
725 FIXME("unsupported WGL_PBUFFER_LOST_ARB (need glXSelectEvent/GLX_DAMAGED work)\n");
729 FIXME("unexpected attribute %x\n", iAttribute);
736 GLboolean WINAPI wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
738 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
739 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
740 return p_glXBindTexImageARB(object->display, object->drawable, iBuffer);
743 GLboolean WINAPI wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
745 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
746 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
747 return p_glXReleaseTexImageARB(object->display, object->drawable, iBuffer);
750 GLboolean WINAPI wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
752 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
753 WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
754 return p_glXDrawableAttribARB(object->display, object->drawable, piAttribList);
757 static const struct {
759 BOOL (*query_function)(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions,
760 const char *glx_version, const char *glx_extensions,
761 const char *server_glx_extensions, const char *client_glx_extensions);
762 } extension_list[] = {
763 { "WGL_ARB_make_current_read", query_function_make_current_read },
764 { "WGL_ARB_multisample", query_function_multisample },
765 { "WGL_ARB_pbuffer", query_function_pbuffer },
766 { "WGL_ARB_pixel_format" , query_function_pixel_format },
767 { "WGL_ARB_render_texture", query_function_render_texture },
768 { "WGL_EXT_swap_control", query_function_swap_control }
771 /* Used to initialize the WGL extension string at DLL loading */
772 void wgl_ext_initialize_extensions(Display *display, int screen, glXGetProcAddressARB_t proc, const char* disabled_extensions)
774 int size = strlen(WGL_extensions_base);
775 const char *glx_extensions = glXQueryExtensionsString(display, screen);
776 const char *server_glx_extensions = glXQueryServerString(display, screen, GLX_EXTENSIONS);
777 const char *client_glx_extensions = glXGetClientString(display, GLX_EXTENSIONS);
778 const char *gl_extensions = (const char *) glGetString(GL_EXTENSIONS);
779 const char *gl_version = (const char *) glGetString(GL_VERSION);
780 const char *glx_version = glXGetClientString(display, GLX_VERSION);
783 TRACE("GL version : %s.\n", debugstr_a(gl_version));
784 TRACE("GL exts : %s.\n", debugstr_a(gl_extensions));
785 TRACE("GLX exts : %s.\n", debugstr_a(glx_extensions));
786 TRACE("Server GLX exts : %s.\n", debugstr_a(server_glx_extensions));
787 TRACE("Client GLX exts : %s.\n", debugstr_a(client_glx_extensions));
789 for (i = 0; i < (sizeof(extension_list) / sizeof(extension_list[0])); i++) {
790 if (strstr(disabled_extensions, extension_list[i].name)) continue ; /* disabled by config, next */
791 if (extension_list[i].query_function(proc,
792 gl_version, gl_extensions,
793 glx_version, glx_extensions,
794 server_glx_extensions, client_glx_extensions)) {
795 size += strlen(extension_list[i].name) + 1;
799 /* For the moment, only 'base' extensions are supported. */
800 WGL_extensions = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + 1);
801 if (WGL_extensions == NULL) {
802 WGL_extensions = (char *) WGL_extensions_base;
804 strcpy(WGL_extensions, WGL_extensions_base);
805 for (i = 0; i < (sizeof(extension_list) / sizeof(extension_list[0])); i++) {
806 if (strstr(disabled_extensions, extension_list[i].name)) continue ; /* disabled by config, next */
807 if (extension_list[i].query_function(proc,
808 gl_version, gl_extensions,
809 glx_version, glx_extensions,
810 server_glx_extensions, client_glx_extensions)) {
811 strcat(WGL_extensions, " ");
812 strcat(WGL_extensions, extension_list[i].name);
817 TRACE("Supporting following WGL extensions : %s.\n", debugstr_a(WGL_extensions));
820 void wgl_ext_finalize_extensions(void)
822 if (WGL_extensions != WGL_extensions_base) {
823 HeapFree(GetProcessHeap(), 0, WGL_extensions);
828 * Putting this at the end to prevent having to write the prototypes :-)
830 * @WARNING: this list must be ordered by name
832 * @TODO: real handle caps on providing some func_init functions (third param, ex: to check extensions)
834 WGL_extension wgl_extension_registry[] = {
835 { "wglBindTexImageARB", (void *) wglBindTexImageARB, NULL, NULL},
836 { "wglChoosePixelFormatARB", (void *) wglChoosePixelFormatARB, NULL, NULL},
837 { "wglCreatePbufferARB", (void *) wglCreatePbufferARB, NULL, NULL},
838 { "wglDestroyPbufferARB", (void *) wglDestroyPbufferARB, NULL, NULL},
839 { "wglGetCurrentReadDCARB", (void *) wglGetCurrentReadDCARB, NULL, NULL},
840 { "wglGetExtensionsStringARB", (void *) wglGetExtensionsStringARB, NULL, NULL},
841 { "wglGetExtensionsStringEXT", (void *) wglGetExtensionsStringEXT, NULL, NULL},
842 { "wglGetPbufferDCARB", (void *) wglGetPbufferDCARB, NULL, NULL},
843 { "wglGetPixelFormatAttribfvARB", (void *) wglGetPixelFormatAttribfvARB, NULL, NULL},
844 { "wglGetPixelFormatAttribivARB", (void *) wglGetPixelFormatAttribivARB, NULL, NULL},
845 { "wglGetSwapIntervalEXT", (void *) wglGetSwapIntervalEXT, NULL, NULL},
846 { "wglMakeContextCurrentARB", (void *) wglMakeContextCurrentARB, NULL, NULL },
847 { "wglQueryPbufferARB", (void *) wglQueryPbufferARB, NULL, NULL},
848 { "wglReleasePbufferDCARB", (void *) wglReleasePbufferDCARB, NULL, NULL},
849 { "wglReleaseTexImageARB", (void *) wglReleaseTexImageARB, NULL, NULL},
850 { "wglSetPbufferAttribARB", (void *) wglSetPbufferAttribARB, NULL, NULL},
851 { "wglSwapIntervalEXT", (void *) wglSwapIntervalEXT, NULL, NULL}
853 int wgl_extension_registry_size = sizeof(wgl_extension_registry) / sizeof(wgl_extension_registry[0]);