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 TRACE("gl_version is: \"%s\"\n", gl_version);
113 TRACE("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 */
127 * http://oss.sgi.com/projects/ogl-sample/registry/ARB/wgl_render_texture.txt
128 * ~/tmp/ogl/ogl_offscreen_rendering_3
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)
138 BOOL bTest = (0 <= strcmp("1.3", glx_version) || NULL != strstr(glx_extensions, "GLX_SGIX_pbuffer"));
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);
146 use_render_texture_emulation = 0;
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)
157 BOOL bTest = (0 <= strcmp("1.3", glx_version) || NULL != strstr(glx_extensions, "GLX_SGI_swap_control"));
159 p_glXSwapIntervalSGI = proc( (const GLubyte *) "glXSwapIntervalSGI");
160 bTest = (NULL != p_glXSwapIntervalSGI);
165 /***********************************************************************
166 * wglGetExtensionsStringEXT(OPENGL32.@)
168 const char * WINAPI wglGetExtensionsStringEXT(void) {
169 TRACE("() returning \"%s\"\n", WGL_extensions);
171 return WGL_extensions;
174 /***********************************************************************
175 * wglGetExtensionsStringARB(OPENGL32.@)
177 const char * WINAPI wglGetExtensionsStringARB(HDC hdc) {
178 TRACE("() returning \"%s\"\n", WGL_extensions);
180 return WGL_extensions;
183 static int swap_interval = 1;
185 /***********************************************************************
186 * wglSwapIntervalEXT(OPENGL32.@)
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);
194 WARN("(): GLX_SGI_swap_control extension seems not supported\n");
198 /***********************************************************************
199 * wglGetSwapIntervalEXT(OPENGL32.@)
201 int WINAPI wglGetSwapIntervalEXT(VOID) {
203 return swap_interval;
206 typedef struct wine_glpbuffer {
215 int use_render_texture;
216 GLuint texture_target;
217 GLuint texture_bind_target;
222 #define PUSH1(attribs,att) attribs[nAttribs++] = (att);
223 #define PUSH2(attribs,att,value) attribs[nAttribs++] = (att); attribs[nAttribs++] = (value);
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
267 #define WGL_NO_ACCELERATION_ARB 0x2025
268 #define WGL_GENERIC_ACCELERATION_ARB 0x2026
269 #define WGL_FULL_ACCELERATION_ARB 0x2027
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
280 #define WGL_TYPE_RGBA_ARB 0x202B
281 #define WGL_TYPE_COLORINDEX_ARB 0x202C
283 #define WGL_SAMPLE_BUFFERS_ARB 0x2041
284 #define WGL_SAMPLES_ARB 0x2042
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
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");
339 static unsigned ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
340 unsigned nAttribs = 0;
344 int wantColorBits = 0;
347 while (0 != iWGLAttr[cur]) {
348 TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);
350 switch (iWGLAttr[cur]) {
351 case WGL_COLOR_BITS_ARB:
352 pop = iWGLAttr[++cur];
353 wantColorBits = pop; /** see end */
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);
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);
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);
370 case WGL_ALPHA_BITS_ARB:
371 pop = iWGLAttr[++cur];
373 PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
374 TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
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);
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);
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);
392 case WGL_PIXEL_TYPE_ARB:
393 pop = iWGLAttr[++cur];
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 ;
398 ERR("unexpected PixelType(%x)\n", pop);
401 PUSH2(oGLXAttr, GLX_RENDER_TYPE, pop);
402 TRACE("pAttr[%d] = GLX_RENDER_TYPE: %d\n", cur, pop);
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);
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);
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);
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);
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);
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]);
444 ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
446 if (!use_render_texture_emulation) {
447 ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
449 pop = iWGLAttr[++cur];
453 FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
460 * Trick as WGL_COLOR_BITS_ARB != GLX_BUFFER_SIZE
461 * WGL_COLOR_BITS_ARB + WGL_ALPHA_BITS_ARB == GLX_BUFFER_SIZE
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.
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.
477 if (0 < wantColorBits) {
479 wantColorBits += sz_alpha;
481 if (32 < wantColorBits) {
482 ERR("buggy %d GLX_BUFFER_SIZE default to 32\n", wantColorBits);
485 PUSH2(oGLXAttr, GLX_BUFFER_SIZE, wantColorBits);
486 TRACE("pAttr[%d] = WGL_COLOR_BITS_ARB: %d\n", cur, wantColorBits);
492 GLboolean WINAPI wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
494 Display* display = get_display( hdc );
496 GLXFBConfig* cfgs = NULL;
497 GLXFBConfig curCfg = NULL;
503 TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
505 if (0 < iLayerPlane) {
506 FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
510 cfgs = glXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
512 ERR("no FB Configs found for display(%p)\n", display);
516 for (i = 0; i < nAttributes; ++i) {
517 const int curWGLAttr = piAttributes[i];
518 TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
520 switch (curWGLAttr) {
521 case WGL_NUMBER_PIXEL_FORMATS_ARB:
525 case WGL_SUPPORT_OPENGL_ARB:
526 piValues[i] = GL_TRUE;
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;
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;
540 ERR("unexpected Config Caveat(%x)\n", tmp);
541 piValues[i] = WGL_NO_ACCELERATION_ARB;
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;
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;
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 ;
565 ERR("unexpected RenderType(%x)\n", tmp);
566 piValues[i] = WGL_TYPE_RGBA_ARB;
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;
581 case WGL_BLUE_BITS_ARB:
582 curGLXAttr = GLX_BLUE_SIZE;
584 case WGL_RED_BITS_ARB:
585 curGLXAttr = GLX_RED_SIZE;
587 case WGL_GREEN_BITS_ARB:
588 curGLXAttr = GLX_GREEN_SIZE;
590 case WGL_ALPHA_BITS_ARB:
591 curGLXAttr = GLX_ALPHA_SIZE;
593 case WGL_DEPTH_BITS_ARB:
594 curGLXAttr = GLX_DEPTH_SIZE;
596 case WGL_STENCIL_BITS_ARB:
597 curGLXAttr = GLX_STENCIL_SIZE;
599 case WGL_DOUBLE_BUFFER_ARB:
600 curGLXAttr = GLX_DOUBLEBUFFER;
603 curGLXAttr = GLX_STEREO;
605 case WGL_AUX_BUFFERS_ARB:
606 curGLXAttr = GLX_AUX_BUFFERS;
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;
616 case WGL_PBUFFER_LARGEST_ARB:
617 curGLXAttr = GLX_LARGEST_PBUFFER;
620 case WGL_SAMPLE_BUFFERS_ARB:
621 curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
624 case WGL_SAMPLES_ARB:
625 curGLXAttr = GLX_SAMPLES_ARB;
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;
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;
643 curGLXAttr = GLX_X_RENDERABLE;
647 FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
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;
656 piValues[i] = GL_FALSE;
663 ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
668 ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nCfgs);
673 GLboolean WINAPI wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
675 FIXME("(%p, %d, %d, %d, %p, %p): stub\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
679 * http://publib.boulder.ibm.com/infocenter/pseries/index.jsp?topic=/com.ibm.aix.doc/libs/openglrf/glXChooseFBConfig.htm
681 GLboolean WINAPI wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
683 Display* display = get_display( hdc );
686 unsigned nAttribs = 0;
688 GLXFBConfig* cfgs = NULL;
693 GLXFBConfig* cfgs_fmt = NULL;
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");
705 nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
706 PUSH1(attribs, None);
708 cfgs = glXChooseFBConfig(display, DefaultScreen(display), attribs, &nCfgs);
710 WARN("Compatible Pixel Format not found\n");
714 cfgs_fmt = glXGetFBConfigs(display, DefaultScreen(display), &nCfgs_fmt);
715 if (NULL == cfgs_fmt) {
716 ERR("Failed to get All FB Configs\n");
721 for (it = 0; it < nMaxFormats && it < nCfgs; ++it) {
722 gl_test = glXGetFBConfigAttrib(display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
724 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
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);
730 ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
733 if (fmt_id == tmp_fmt_id) {
735 piFormats[pfmt_it] = it_fmt + 1;
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);
742 if (it_fmt == nCfgs_fmt) {
743 ERR("Failed to get valid fmt for %d. Try next.\n", it);
746 TRACE("at %d/%d found FBCONFIG_ID(%d/%d)\n", it + 1, nCfgs, piFormats[it], nCfgs_fmt);
749 *nNumFormats = pfmt_it;
756 #define HPBUFFERARB void *
757 HPBUFFERARB WINAPI wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
759 Wine_GLPBuffer* object = NULL;
760 Display* display = get_display( hdc );
761 GLXFBConfig* cfgs = NULL;
764 unsigned nAttribs = 0;
766 TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);
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 */
774 cfgs = glXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
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 */
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 */
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 */
793 object->display = display;
794 object->width = iWidth;
795 object->height = iHeight;
796 object->pixelFormat = iPixelFormat;
798 nAttribs = ConvertAttribWGLtoGLX(piAttribList, attribs, object);
799 PUSH2(attribs, GLX_PBUFFER_WIDTH, iWidth);
800 PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight);
801 PUSH1(attribs, None);
803 while (0 != *piAttribList) {
805 switch (*piAttribList) {
806 case WGL_TEXTURE_FORMAT_ARB: {
807 if (!use_render_texture_emulation) {
808 SetLastError(ERROR_INVALID_DATA);
812 attr_v = *piAttribList;
813 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
815 case WGL_TEXTURE_RGB_ARB:
816 case WGL_TEXTURE_RGBA_ARB:
817 case WGL_NO_TEXTURE_ARB:
820 SetLastError(ERROR_INVALID_DATA);
826 case WGL_TEXTURE_TARGET_ARB: {
827 if (!use_render_texture_emulation) {
828 SetLastError(ERROR_INVALID_DATA);
832 attr_v = *piAttribList;
833 TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
835 case WGL_TEXTURE_CUBE_MAP_ARB: {
836 if (iWidth != iHeight) {
837 SetLastError(ERROR_INVALID_DATA);
840 object->texture_target = GL_TEXTURE_CUBE_MAP;
841 object->texture_bind_target = GL_TEXTURE_CUBE_MAP;
844 case WGL_TEXTURE_1D_ARB: {
846 SetLastError(ERROR_INVALID_DATA);
849 object->texture_target = GL_TEXTURE_1D;
850 object->texture_bind_target = GL_TEXTURE_1D;
853 case WGL_TEXTURE_2D_ARB: {
854 object->texture_target = GL_TEXTURE_2D;
855 object->texture_bind_target = GL_TEXTURE_2D;
858 case WGL_NO_TEXTURE_ARB:
861 SetLastError(ERROR_INVALID_DATA);
867 case WGL_MIPMAP_TEXTURE_ARB: {
868 if (!use_render_texture_emulation) {
869 SetLastError(ERROR_INVALID_DATA);
873 attr_v = *piAttribList;
874 TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
876 SetLastError(ERROR_INVALID_DATA);
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 */
892 TRACE("->(%p)\n", object);
896 return (HPBUFFERARB) object;
899 if (NULL != cfgs) XFree(cfgs);
900 if (NULL != object) HeapFree(GetProcessHeap(), 0, object);
901 TRACE("->(FAILED)\n");
902 return (HPBUFFERARB) NULL;
905 HDC WINAPI wglGetPbufferDCARB(HPBUFFERARB hPbuffer)
907 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
909 if (NULL == object) {
910 SetLastError(ERROR_INVALID_HANDLE);
913 hDC = CreateCompatibleDC(object->hdc);
914 set_drawable(hDC, object->drawable); /* works ?? */
915 TRACE("(%p)->(%p)\n", hPbuffer, hDC);
919 int WINAPI wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
921 TRACE("(%p, %p)\n", hPbuffer, hdc);
926 GLboolean WINAPI wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
928 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
929 TRACE("(%p)\n", hPbuffer);
930 if (NULL == object) {
931 SetLastError(ERROR_INVALID_HANDLE);
934 glXDestroyPbuffer(object->display, object->drawable);
935 HeapFree(GetProcessHeap(), 0, object);
939 GLboolean WINAPI wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
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);
947 switch (iAttribute) {
948 case WGL_PBUFFER_WIDTH_ARB:
949 glXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
951 case WGL_PBUFFER_HEIGHT_ARB:
952 glXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
955 case WGL_PBUFFER_LOST_ARB:
956 FIXME("unsupported WGL_PBUFFER_LOST_ARB (need glXSelectEvent/GLX_DAMAGED work)\n");
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);
966 if (!use_render_texture_emulation) {
967 SetLastError(ERROR_INVALID_DATA);
968 return GL_FALSE; /** how to FIX ? */
970 FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
974 FIXME("unexpected attribute %x\n", iAttribute);
981 GLboolean WINAPI wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
983 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
984 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
985 if (NULL == object) {
986 SetLastError(ERROR_INVALID_HANDLE);
989 if (!object->use_render_texture) {
990 SetLastError(ERROR_INVALID_HANDLE);
993 if (1 == use_render_texture_emulation) {
996 if (NULL != p_glXBindTexImageARB) {
997 return p_glXBindTexImageARB(object->display, object->drawable, iBuffer);
1002 GLboolean WINAPI wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
1004 Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
1005 TRACE("(%p, %d)\n", hPbuffer, iBuffer);
1006 if (NULL == object) {
1007 SetLastError(ERROR_INVALID_HANDLE);
1010 if (!object->use_render_texture) {
1011 SetLastError(ERROR_INVALID_HANDLE);
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);
1021 glCopyTexSubImage2D(object->texture_bind_target, object->texture_level, 0, 0, 0, 0, object->width, object->height);
1023 glBindTexture(object->texture_target, prev_binded_tex);
1026 if (NULL != p_glXReleaseTexImageARB) {
1027 return p_glXReleaseTexImageARB(object->display, object->drawable, iBuffer);
1032 GLboolean WINAPI wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
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);
1040 if (!object->use_render_texture) {
1041 SetLastError(ERROR_INVALID_HANDLE);
1044 if (1 == use_render_texture_emulation) {
1047 if (NULL != p_glXDrawableAttribARB) {
1048 return p_glXDrawableAttribARB(object->display, object->drawable, piAttribList);
1053 static const struct {
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 }
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)
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);
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));
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;
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;
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);
1113 TRACE("Supporting following WGL extensions : %s.\n", debugstr_a(WGL_extensions));
1116 void wgl_ext_finalize_extensions(void)
1118 if (WGL_extensions != WGL_extensions_base) {
1119 HeapFree(GetProcessHeap(), 0, WGL_extensions);
1124 * Putting this at the end to prevent having to write the prototypes :-)
1126 * @WARNING: this list must be ordered by name
1128 * @TODO: real handle caps on providing some func_init functions (third param, ex: to check extensions)
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}
1149 int wgl_extension_registry_size = sizeof(wgl_extension_registry) / sizeof(wgl_extension_registry[0]);