wgl_ext.c 36.8 KB
Newer Older
1 2 3
/* Support for window-specific OpenGL extensions.
 *
 * Copyright (c) 2004 Lionel Ulmer
4 5
 * Copyright (c) 2005 Alex Woods
 * Copyright (c) 2005 Raphael Junqueira
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"
#include "wine/port.h"

#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "winerror.h"

34
#include "gdi.h"
35 36 37 38 39 40 41 42
#include "wgl.h"
#include "wgl_ext.h"
#include "opengl_ext.h"
#include "wine/library.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(opengl);

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

/* x11drv GDI escapes */
#define X11DRV_ESCAPE 6789
enum x11drv_escape_codes
{
    X11DRV_GET_DISPLAY,   /* get X11 display for a DC */
    X11DRV_GET_DRAWABLE,  /* get current drawable for a DC */
    X11DRV_GET_FONT,      /* get current X font for a DC */
    X11DRV_SET_DRAWABLE,     /* set current drawable for a DC */
};
struct x11drv_escape_set_drawable
{
    enum x11drv_escape_codes code;         /* escape code (X11DRV_SET_DRAWABLE) */
    Drawable                 drawable;     /* X drawable */
    int                      mode;         /* ClipByChildren or IncludeInferiors */
    POINT                    org;          /* origin of DC relative to drawable */
    POINT                    drawable_org; /* origin of drawable relative to screen */
};

/* retrieve the X display to use on a given DC */
inline static Display *get_display( HDC hdc )
{
    Display *display;
    enum x11drv_escape_codes escape = X11DRV_GET_DISPLAY;

    if (!ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape,
                    sizeof(display), (LPSTR)&display )) display = NULL;
    return display;
}
inline static void set_drawable( HDC hdc, Drawable drawable )
{
    struct x11drv_escape_set_drawable escape;

    escape.code = X11DRV_SET_DRAWABLE;
    escape.drawable = drawable;
    escape.mode = IncludeInferiors;
    escape.org.x = escape.org.y = 0;
    escape.drawable_org.x = escape.drawable_org.y = 0;

    ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape, 0, NULL );
}

85 86 87 88
/* Some WGL extensions... */
static const char *WGL_extensions_base = "WGL_ARB_extensions_string WGL_EXT_extensions_string";
static char *WGL_extensions = NULL;

89 90 91 92 93
/**
 * Extensions-query functions 
 *
 * @TODO: use a struct to handle parameters 
 */
94 95 96 97 98 99 100
BOOL query_function_make_current_read(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions, 
				      const char* glx_version, const char *glx_extensions,
				      const char *server_glx_extensions, const char *client_glx_extensions)
{
  return 0 <= strcmp("1.3", glx_version);
}

101
BOOL query_function_multisample(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions, 
102 103
				const char* glx_version, const char *glx_extensions,
				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 110 111
			    const char* glx_version, const char *glx_extensions,
			    const char *server_glx_extensions, const char *client_glx_extensions)
{
112 113
  TRACE("gl_version is: \"%s\"\n", gl_version);
  TRACE("glx_exts is: \"%s\"\n", glx_extensions);
114 115 116 117

  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 120 121 122 123 124
				 const char* glx_version, const char *glx_extensions,
				 const char *server_glx_extensions, const char *client_glx_extensions)
{
  return TRUE;
}

125
/** GLX_ARB_render_texture */
126 127 128 129
/**
 * http://oss.sgi.com/projects/ogl-sample/registry/ARB/wgl_render_texture.txt
 * ~/tmp/ogl/ogl_offscreen_rendering_3
 */
130 131 132
Bool (*p_glXBindTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
Bool (*p_glXReleaseTexImageARB)(Display *dpy, GLXPbuffer pbuffer, int buffer);
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 136 137
				   const char* glx_version, const char *glx_extensions,
				   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"));
139
  if (bTest) {
140
    if (NULL != strstr(glx_extensions, "GLX_ARB_render_texture")) {
Mike McCormack's avatar
Mike McCormack committed
141 142 143
      p_glXBindTexImageARB = proc( (const GLubyte *) "glXBindTexImageARB");
      p_glXReleaseTexImageARB = proc( (const GLubyte *) "glXReleaseTexImageARB");
      p_glXDrawableAttribARB = proc( (const GLubyte *) "glXDrawableAttribARB");
144 145 146 147
      bTest = (NULL != p_glXBindTexImageARB && NULL != p_glXReleaseTexImageARB && NULL != p_glXDrawableAttribARB);
    } else {
      use_render_texture_emulation = 0;
    }
148 149
  }
  return bTest;
150 151
}

152 153 154 155 156 157 158
int (*p_glXSwapIntervalSGI)(int);
BOOL query_function_swap_control(glXGetProcAddressARB_t proc, const char *gl_version, const char *gl_extensions, 
				 const char* glx_version, const char *glx_extensions,
				 const char *server_glx_extensions, const char *client_glx_extensions)
{
  BOOL bTest = (0 <= strcmp("1.3", glx_version) || NULL != strstr(glx_extensions, "GLX_SGI_swap_control"));
  if (bTest) {
Mike McCormack's avatar
Mike McCormack committed
159
    p_glXSwapIntervalSGI = proc( (const GLubyte *) "glXSwapIntervalSGI");
160 161 162 163 164
    bTest = (NULL != p_glXSwapIntervalSGI);
  }
  return bTest;
}

165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
/***********************************************************************
 *              wglGetExtensionsStringEXT(OPENGL32.@)
 */
const char * WINAPI wglGetExtensionsStringEXT(void) {
    TRACE("() returning \"%s\"\n", WGL_extensions);

    return WGL_extensions;
}

/***********************************************************************
 *              wglGetExtensionsStringARB(OPENGL32.@)
 */
const char * WINAPI wglGetExtensionsStringARB(HDC hdc) {
    TRACE("() returning \"%s\"\n", WGL_extensions);

    return WGL_extensions;    
}

183 184 185 186 187 188
static int swap_interval = 1;

/***********************************************************************
 *              wglSwapIntervalEXT(OPENGL32.@)
 */
BOOL WINAPI wglSwapIntervalEXT(int interval) {
189 190 191 192 193
  TRACE("(%d)\n", interval);
  swap_interval = interval;
  if (NULL != p_glXSwapIntervalSGI) {
    return 0 == p_glXSwapIntervalSGI(interval);
  }
194
  WARN("(): GLX_SGI_swap_control extension seems not supported\n");
195
  return TRUE;
196 197 198 199 200 201 202 203 204 205
}

/***********************************************************************
 *              wglGetSwapIntervalEXT(OPENGL32.@)
 */
int WINAPI wglGetSwapIntervalEXT(VOID) {
    FIXME("(),stub!\n");
    return swap_interval;
}

206 207 208 209 210 211 212 213
typedef struct wine_glpbuffer {
  Drawable   drawable;
  Display*   display;
  int        pixelFormat;
  int        width;
  int        height;
  int*       attribList;
  HDC        hdc;
214 215 216 217 218 219

  int        use_render_texture;
  GLuint     texture_target;
  GLuint     texture_bind_target;
  GLuint     texture;
  int        texture_level;
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
} Wine_GLPBuffer;

#define PUSH1(attribs,att)        attribs[nAttribs++] = (att); 
#define PUSH2(attribs,att,value)  attribs[nAttribs++] = (att); attribs[nAttribs++] = (value);

#define WGL_NUMBER_PIXEL_FORMATS_ARB		0x2000
#define WGL_DRAW_TO_WINDOW_ARB			0x2001
#define WGL_DRAW_TO_BITMAP_ARB			0x2002
#define WGL_ACCELERATION_ARB			0x2003
#define WGL_NEED_PALETTE_ARB			0x2004
#define WGL_NEED_SYSTEM_PALETTE_ARB		0x2005
#define WGL_SWAP_LAYER_BUFFERS_ARB		0x2006
#define WGL_SWAP_METHOD_ARB			0x2007
#define WGL_NUMBER_OVERLAYS_ARB			0x2008
#define WGL_NUMBER_UNDERLAYS_ARB		0x2009
#define WGL_TRANSPARENT_ARB			0x200A
#define WGL_TRANSPARENT_RED_VALUE_ARB		0x2037
#define WGL_TRANSPARENT_GREEN_VALUE_ARB		0x2038
#define WGL_TRANSPARENT_BLUE_VALUE_ARB		0x2039
#define WGL_TRANSPARENT_ALPHA_VALUE_ARB		0x203A
#define WGL_TRANSPARENT_INDEX_VALUE_ARB		0x203B
#define WGL_SHARE_DEPTH_ARB			0x200C
#define WGL_SHARE_STENCIL_ARB			0x200D
#define WGL_SHARE_ACCUM_ARB			0x200E
#define WGL_SUPPORT_GDI_ARB			0x200F
#define WGL_SUPPORT_OPENGL_ARB			0x2010
#define WGL_DOUBLE_BUFFER_ARB			0x2011
#define WGL_STEREO_ARB				0x2012
#define WGL_PIXEL_TYPE_ARB			0x2013
#define WGL_COLOR_BITS_ARB			0x2014
#define WGL_RED_BITS_ARB			0x2015
#define WGL_RED_SHIFT_ARB			0x2016
#define WGL_GREEN_BITS_ARB			0x2017
#define WGL_GREEN_SHIFT_ARB			0x2018
#define WGL_BLUE_BITS_ARB			0x2019
#define WGL_BLUE_SHIFT_ARB			0x201A
#define WGL_ALPHA_BITS_ARB			0x201B
#define WGL_ALPHA_SHIFT_ARB			0x201C
#define WGL_ACCUM_BITS_ARB			0x201D
#define WGL_ACCUM_RED_BITS_ARB			0x201E
#define WGL_ACCUM_GREEN_BITS_ARB		0x201F
#define WGL_ACCUM_BLUE_BITS_ARB			0x2020
#define WGL_ACCUM_ALPHA_BITS_ARB		0x2021
#define WGL_DEPTH_BITS_ARB			0x2022
#define WGL_STENCIL_BITS_ARB			0x2023
#define WGL_AUX_BUFFERS_ARB			0x2024

267 268 269 270
#define WGL_NO_ACCELERATION_ARB			0x2025
#define WGL_GENERIC_ACCELERATION_ARB		0x2026
#define WGL_FULL_ACCELERATION_ARB		0x2027

271 272 273 274 275 276 277 278 279 280 281 282 283 284
#define WGL_PBUFFER_WIDTH_ARB                   0x2034
#define WGL_PBUFFER_HEIGHT_ARB                  0x2035
#define WGL_PBUFFER_LOST_ARB                    0x2036
#define WGL_DRAW_TO_PBUFFER_ARB		        0x202D
#define WGL_MAX_PBUFFER_PIXELS_ARB	        0x202E
#define WGL_MAX_PBUFFER_WIDTH_ARB		0x202F
#define WGL_MAX_PBUFFER_HEIGHT_ARB	        0x2030
#define WGL_PBUFFER_LARGEST_ARB                 0x2033

#define WGL_TYPE_RGBA_ARB			0x202B
#define WGL_TYPE_COLORINDEX_ARB			0x202C

#define WGL_SAMPLE_BUFFERS_ARB		        0x2041
#define WGL_SAMPLES_ARB	                        0x2042
285

286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
/**
 * WGL_render_texture 
 */
/** GetPixelFormat/ChoosePixelFormat */
#define WGL_BIND_TO_TEXTURE_RGB_ARB             0x2070
#define WGL_BIND_TO_TEXTURE_RGBA_ARB            0x2071
/** CreatePbuffer / QueryPbuffer */
#define WGL_TEXTURE_FORMAT_ARB                  0x2072
#define WGL_TEXTURE_TARGET_ARB                  0x2073
#define WGL_MIPMAP_TEXTURE_ARB                  0x2074
/** CreatePbuffer / QueryPbuffer */
#define WGL_TEXTURE_RGB_ARB                     0x2075
#define WGL_TEXTURE_RGBA_ARB                    0x2076
#define WGL_NO_TEXTURE_ARB                      0x2077
/** CreatePbuffer / QueryPbuffer */
#define WGL_TEXTURE_CUBE_MAP_ARB                0x2078
#define WGL_TEXTURE_1D_ARB                      0x2079
#define WGL_TEXTURE_2D_ARB                      0x207A
#define WGL_NO_TEXTURE_ARB                      0x2077
/** SetPbufferAttribARB/QueryPbufferARB parameters */
#define WGL_MIPMAP_LEVEL_ARB                    0x207B
#define WGL_CUBE_MAP_FACE_ARB                   0x207C
/** SetPbufferAttribARB/QueryPbufferARB attribs */
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB     0x207D
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB     0x207E
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB     0x207F
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB     0x2080
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB     0x2081 
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB     0x2082
/** BindTexImageARB/ReleaseTexImageARB */
#define WGL_FRONT_LEFT_ARB                  0x2083
#define WGL_FRONT_RIGHT_ARB                 0x2084
#define WGL_BACK_LEFT_ARB                   0x2085
#define WGL_BACK_RIGHT_ARB                  0x2086
#define WGL_AUX0_ARB                        0x2087 
#define WGL_AUX1_ARB                        0x2088 
#define WGL_AUX2_ARB                        0x2089 
#define WGL_AUX3_ARB                        0x208A 
#define WGL_AUX4_ARB                        0x208B 
#define WGL_AUX5_ARB                        0x208C 
#define WGL_AUX6_ARB                        0x208D
#define WGL_AUX7_ARB                        0x208E 
#define WGL_AUX8_ARB                        0x208F 
#define WGL_AUX9_ARB                        0x2090

331 332 333 334 335 336 337 338
#if 0 /* not used yet */
static unsigned ConvertAttribGLXtoWGL(const int* iWGLAttr, int* oGLXAttr) {
  unsigned nAttribs = 0;
  FIXME("not yet implemented!\n");
  return nAttribs;
}
#endif

339
static unsigned ConvertAttribWGLtoGLX(const int* iWGLAttr, int* oGLXAttr, Wine_GLPBuffer* pbuf) {
340 341 342 343 344
  unsigned nAttribs = 0;
  unsigned cur = 0; 
  int pop;

  while (0 != iWGLAttr[cur]) {
345 346
    TRACE("pAttr[%d] = %x\n", cur, iWGLAttr[cur]);

347 348 349 350
    switch (iWGLAttr[cur]) {
    case WGL_COLOR_BITS_ARB:
      pop = iWGLAttr[++cur];
      PUSH2(oGLXAttr, GLX_BUFFER_SIZE, pop);
351 352 353 354 355 356 357 358 359 360
      TRACE("pAttr[%d] = WGL_COLOR_BITS_ARB: %d\n", cur, pop);
      break;
    case WGL_BLUE_BITS_ARB:
      pop = iWGLAttr[++cur];
      PUSH2(oGLXAttr, GLX_BLUE_SIZE, pop);
      TRACE("pAttr[%d] = GLX_BLUE_SIZE: %d\n", cur, pop);
      break;
    case WGL_RED_BITS_ARB:
      pop = iWGLAttr[++cur];
      PUSH2(oGLXAttr, GLX_RED_SIZE, pop);
361
      TRACE("pAttr[%d] = GLX_RED_SIZE: %d\n", cur, pop);
362 363 364 365
      break;
    case WGL_GREEN_BITS_ARB:
      pop = iWGLAttr[++cur];
      PUSH2(oGLXAttr, GLX_GREEN_SIZE, pop);
366
      TRACE("pAttr[%d] = GLX_GREEN_SIZE: %d\n", cur, pop);
367 368 369 370
      break;
    case WGL_ALPHA_BITS_ARB:
      pop = iWGLAttr[++cur];
      PUSH2(oGLXAttr, GLX_ALPHA_SIZE, pop);
371
      TRACE("pAttr[%d] = GLX_ALPHA_SIZE: %d\n", cur, pop);
372 373 374 375
      break;
    case WGL_DEPTH_BITS_ARB:
      pop = iWGLAttr[++cur];
      PUSH2(oGLXAttr, GLX_DEPTH_SIZE, pop);
376
      TRACE("pAttr[%d] = GLX_DEPTH_SIZE: %d\n", cur, pop);
377 378 379 380
      break;
    case WGL_STENCIL_BITS_ARB:
      pop = iWGLAttr[++cur];
      PUSH2(oGLXAttr, GLX_STENCIL_SIZE, pop);
381
      TRACE("pAttr[%d] = GLX_STENCIL_SIZE: %d\n", cur, pop);
382 383 384 385
      break;
    case WGL_DOUBLE_BUFFER_ARB:
      pop = iWGLAttr[++cur];
      PUSH2(oGLXAttr, GLX_DOUBLEBUFFER, pop);
386
      TRACE("pAttr[%d] = GLX_DOUBLEBUFFER: %d\n", cur, pop);
387
      break;
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402

    case WGL_PIXEL_TYPE_ARB:
      pop = iWGLAttr[++cur];
      switch (pop) {
      case WGL_TYPE_RGBA_ARB:  pop = GLX_RGBA_BIT; break ; 
      case WGL_TYPE_COLORINDEX_ARB: pop = GLX_COLOR_INDEX_BIT; break ;
      default:
	ERR("unexpected PixelType(%x)\n", pop);	
	pop = 0;
      }
      PUSH2(oGLXAttr, GLX_RENDER_TYPE, pop);
      TRACE("pAttr[%d] = GLX_RENDER_TYPE: %d\n", cur, pop);
      break;

    case WGL_SUPPORT_GDI_ARB:
403
    case WGL_DRAW_TO_WINDOW_ARB:
404 405 406 407 408 409 410
    case WGL_DRAW_TO_BITMAP_ARB:
    case WGL_DRAW_TO_PBUFFER_ARB:
      pop = iWGLAttr[++cur];
      PUSH2(oGLXAttr, GLX_X_RENDERABLE, pop);
      TRACE("pAttr[%d] = GLX_RENDERABLE: %d\n", cur, pop);
      break;

411
    case WGL_ACCELERATION_ARB:
412 413 414 415 416 417 418 419 420 421 422 423
    case WGL_SUPPORT_OPENGL_ARB:
      pop = iWGLAttr[++cur];
      /** nothing to do, if we are here, supposing support Accelerated OpenGL */
      TRACE("pAttr[%d] = WGL_SUPPORT_OPENGL_ARB: %d\n", cur, pop);
      break;

    case WGL_PBUFFER_LARGEST_ARB:
      pop = iWGLAttr[++cur];
      PUSH2(oGLXAttr, GLX_LARGEST_PBUFFER, pop);
      TRACE("pAttr[%d] = GLX_LARGEST_PBUFFER: %x\n", cur, pop);
      break;

424
    case WGL_SAMPLE_BUFFERS_ARB:
425 426 427 428 429
      pop = iWGLAttr[++cur];
      PUSH2(oGLXAttr, GLX_SAMPLE_BUFFERS_ARB, pop);
      TRACE("pAttr[%d] = GLX_SAMPLE_BUFFERS_ARB: %x\n", cur, pop);
      break;
      
430
    case WGL_SAMPLES_ARB:
431 432 433 434 435
      pop = iWGLAttr[++cur];
      PUSH2(oGLXAttr, GLX_SAMPLES_ARB, pop);
      TRACE("pAttr[%d] = GLX_SAMPLES_ARB: %x\n", cur, pop);
      break;

436 437 438 439 440 441 442 443 444 445 446 447 448
    case WGL_TEXTURE_FORMAT_ARB:
    case WGL_TEXTURE_TARGET_ARB:
    case WGL_MIPMAP_TEXTURE_ARB:
      TRACE("WGL_render_texture Attributes: %x as %x\n", iWGLAttr[cur], iWGLAttr[cur + 1]);
      if (NULL == pbuf) {
	ERR("trying to use GLX_Pbuffer Attributes without Pbuffer (was %x)\n", iWGLAttr[cur]);
      }
      if (!use_render_texture_emulation) {
	ERR("trying to use WGL_render_texture Attributes without support (was %x)\n", iWGLAttr[cur]);
      }
      pop = iWGLAttr[++cur];
      break ;

449
    default:
450
      FIXME("unsupported %x WGL Attribute\n", iWGLAttr[cur]);
451 452 453 454 455 456 457 458 459
      break;
    }
    ++cur;
  }
  return nAttribs;
}

GLboolean WINAPI wglGetPixelFormatAttribivARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues)
{
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
  Display* display = get_display( hdc );
  UINT i;
  GLXFBConfig* cfgs = NULL;
  GLXFBConfig  curCfg = NULL;
  int nCfgs = 0;
  int hTest;
  int tmp;
  int curGLXAttr = 0;

  TRACE("(%p, %d, %d, %d, %p, %p)\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, piValues);
  
  if (0 < iLayerPlane) {
    FIXME("unsupported iLayerPlane(%d) > 0, returns FALSE\n", iLayerPlane);
    return GL_FALSE;
  }

  cfgs = glXGetFBConfigs(display, DefaultScreen(display), &nCfgs);
  if (NULL == cfgs) {
    ERR("no FB Configs found for display(%p)\n", display);
    return GL_FALSE;
  }

  for (i = 0; i < nAttributes; ++i) {
    const int curWGLAttr = piAttributes[i];
    TRACE("pAttr[%d] = %x\n", i, curWGLAttr);
    
    switch (curWGLAttr) {
    case WGL_NUMBER_PIXEL_FORMATS_ARB:
      piValues[i] = nCfgs; 
      continue ;

    case WGL_SUPPORT_OPENGL_ARB:
      piValues[i] = GL_TRUE; 
      continue ;

    case WGL_ACCELERATION_ARB:
      curGLXAttr = GLX_CONFIG_CAVEAT;
      if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
      curCfg = cfgs[iPixelFormat - 1];
      hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, &tmp);
      if (hTest) goto get_error;
      switch (tmp) {
502 503 504
      case GLX_NONE: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
      case GLX_SLOW_CONFIG: piValues[i] = WGL_NO_ACCELERATION_ARB; break;
      case GLX_NON_CONFORMANT_CONFIG: piValues[i] = WGL_FULL_ACCELERATION_ARB; break;
505 506
      default:
	ERR("unexpected Config Caveat(%x)\n", tmp);
507
	piValues[i] = WGL_NO_ACCELERATION_ARB;
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585
      }
      continue ;

    case WGL_TRANSPARENT_ARB:
      curGLXAttr = GLX_TRANSPARENT_TYPE;
      if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
      curCfg = cfgs[iPixelFormat - 1];
      hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, &tmp);
      if (hTest) goto get_error;
      piValues[i] = GL_FALSE;
      if (GLX_NONE != tmp) piValues[i] = GL_TRUE;
      continue ;

    case WGL_PIXEL_TYPE_ARB:
      curGLXAttr = GLX_RENDER_TYPE;
      if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
      curCfg = cfgs[iPixelFormat - 1];
      hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, &tmp);
      if (hTest) goto get_error;
      switch (tmp) {
      case GLX_RGBA_BIT: piValues[i] = WGL_TYPE_RGBA_ARB; break;
      case GLX_COLOR_INDEX_BIT: piValues[i] = WGL_TYPE_COLORINDEX_ARB; break ;
      default:
	ERR("unexpected RenderType(%x)\n", tmp);
	piValues[i] = WGL_TYPE_RGBA_ARB;
      }
      continue ;
      
    case WGL_COLOR_BITS_ARB:
      curGLXAttr = GLX_BUFFER_SIZE;
      break;
    case WGL_BLUE_BITS_ARB:
      curGLXAttr = GLX_BLUE_SIZE;
      break;
    case WGL_RED_BITS_ARB:
      curGLXAttr = GLX_RED_SIZE;
      break;
    case WGL_GREEN_BITS_ARB:
      curGLXAttr = GLX_GREEN_SIZE;
      break;
    case WGL_ALPHA_BITS_ARB:
      curGLXAttr = GLX_ALPHA_SIZE;
      break;
    case WGL_DEPTH_BITS_ARB:
      curGLXAttr = GLX_DEPTH_SIZE;
      break;
    case WGL_STENCIL_BITS_ARB:
      curGLXAttr = GLX_STENCIL_SIZE;
      break;
    case WGL_DOUBLE_BUFFER_ARB:
      curGLXAttr = GLX_DOUBLEBUFFER;
      break;
    case WGL_STEREO_ARB:
      curGLXAttr = GLX_STEREO;
      break;
    case WGL_AUX_BUFFERS_ARB:
      curGLXAttr = GLX_AUX_BUFFERS;
      break;

    case WGL_SUPPORT_GDI_ARB:
    case WGL_DRAW_TO_WINDOW_ARB:
    case WGL_DRAW_TO_BITMAP_ARB:
    case WGL_DRAW_TO_PBUFFER_ARB:
      curGLXAttr = GLX_X_RENDERABLE;
      break;

    case WGL_PBUFFER_LARGEST_ARB:
      curGLXAttr = GLX_LARGEST_PBUFFER;
      break;

    case WGL_SAMPLE_BUFFERS_ARB:
      curGLXAttr = GLX_SAMPLE_BUFFERS_ARB;
      break;
      
    case WGL_SAMPLES_ARB:
      curGLXAttr = GLX_SAMPLES_ARB;
      break;

586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
    case WGL_BIND_TO_TEXTURE_RGB_ARB: 
    case WGL_BIND_TO_TEXTURE_RGBA_ARB:
      if (!use_render_texture_emulation) {
	piValues[i] = GL_FALSE;
	continue ;	
      }
      curGLXAttr = GLX_RENDER_TYPE;
      if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
      curCfg = cfgs[iPixelFormat - 1];
      hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, &tmp);
      if (hTest) goto get_error;
      if (GLX_COLOR_INDEX_BIT == tmp) {
	piValues[i] = GL_FALSE;  
	continue ;
      }
      curGLXAttr = GLX_X_RENDERABLE;
      break;

604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
    default:
      FIXME("unsupported %x WGL Attribute\n", curWGLAttr);
    }
    
    if (0 != curGLXAttr) {
      if (nCfgs < iPixelFormat || 0 >= iPixelFormat) goto pix_error;
      curCfg = cfgs[iPixelFormat - 1];
      hTest = glXGetFBConfigAttrib(display, curCfg, curGLXAttr, piValues + i);
      if (hTest) goto get_error;
    } else { 
      piValues[i] = GL_FALSE; 
    }
  }
  
  return GL_TRUE;

get_error:
  ERR("(%p): unexpected failure on GetFBConfigAttrib(%x) returns FALSE\n", hdc, curGLXAttr);
  XFree(cfgs);
  return GL_FALSE;

pix_error:
  ERR("(%p): unexpected iPixelFormat(%d) vs nFormats(%d), returns FALSE\n", hdc, iPixelFormat, nCfgs);
  XFree(cfgs);
  return GL_FALSE;
629 630 631 632
}

GLboolean WINAPI wglGetPixelFormatAttribfvARB(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues)
{
633 634
    FIXME("(%p, %d, %d, %d, %p, %p): stub\n", hdc, iPixelFormat, iLayerPlane, nAttributes, piAttributes, pfValues);
    return GL_FALSE;
635
}
636 637 638
/**
 * http://publib.boulder.ibm.com/infocenter/pseries/index.jsp?topic=/com.ibm.aix.doc/libs/openglrf/glXChooseFBConfig.htm
 */
639 640 641
GLboolean WINAPI wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats)
{
  Display* display = get_display( hdc );
642 643 644 645
  int gl_test = 0;
  int attribs[256];
  unsigned nAttribs = 0;

646 647 648
  GLXFBConfig* cfgs = NULL;
  int nCfgs = 0;
  UINT it;
649 650 651 652 653 654 655 656
  int fmt_id;

  GLXFBConfig* cfgs_fmt = NULL;
  int nCfgs_fmt = 0;
  UINT it_fmt;
  int tmp_fmt_id;

  int pfmt_it = 0;
657 658 659 660 661 662

  TRACE("(%p, %p, %p, %d, %p, %p): hackish\n", hdc, piAttribIList, pfAttribFList, nMaxFormats, piFormats, nNumFormats);
  if (NULL != pfAttribFList) {
    FIXME("unused pfAttribFList\n");
  }

663
  nAttribs = ConvertAttribWGLtoGLX(piAttribIList, attribs, NULL);
664 665 666
  PUSH1(attribs, None);

  cfgs = glXChooseFBConfig(display, DefaultScreen(display), attribs, &nCfgs);
667 668 669 670 671 672 673 674 675 676 677 678
  if (NULL == cfgs) {
    WARN("Compatible Pixel Format not found\n");
    return GL_FALSE;
  }

  cfgs_fmt = glXGetFBConfigs(display, DefaultScreen(display), &nCfgs_fmt);
  if (NULL == cfgs_fmt) {
    ERR("Failed to get All FB Configs\n");
    XFree(cfgs);
    return GL_FALSE;
  }

679
  for (it = 0; it < nMaxFormats && it < nCfgs; ++it) {
680 681 682 683 684 685 686 687 688 689 690 691
    gl_test = glXGetFBConfigAttrib(display, cfgs[it], GLX_FBCONFIG_ID, &fmt_id);
    if (gl_test) {
      ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
      continue ;
    }
    for (it_fmt = 0; it_fmt < nCfgs_fmt; ++it_fmt) {
      gl_test = glXGetFBConfigAttrib(display, cfgs_fmt[it_fmt], GLX_FBCONFIG_ID, &tmp_fmt_id);
      if (gl_test) {
	ERR("Failed to retrieve FBCONFIG_ID from GLXFBConfig, expect problems.\n");
	continue ;
      }
      if (fmt_id == tmp_fmt_id) {
692
	int tmp;
693 694
	piFormats[pfmt_it] = it_fmt + 1;
	++pfmt_it;
695 696
	glXGetFBConfigAttrib(display, cfgs_fmt[it_fmt], GLX_ALPHA_SIZE, &tmp);
	TRACE("for FBCONFIG_ID(%d/%d) found '%d'\n", it_fmt + 1, nCfgs_fmt, tmp);
697 698 699 700 701 702 703 704
	break ;
      }
    }
    if (it_fmt == nCfgs_fmt) {
      ERR("Failed to get valid fmt for %d. Try next.\n", it);
      continue ;
    }
    TRACE("at %d/%d found FBCONFIG_ID(%d/%d)\n", it + 1, nCfgs, piFormats[it], nCfgs_fmt);
705
  }
706 707 708 709 710
  
  *nNumFormats = pfmt_it;
  /** free list */
  XFree(cfgs);
  XFree(cfgs_fmt);
711 712 713 714 715 716 717 718 719 720 721
  return GL_TRUE;
}

#define HPBUFFERARB void *
HPBUFFERARB WINAPI wglCreatePbufferARB(HDC hdc, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList)
{
  Wine_GLPBuffer* object = NULL;
  Display* display = get_display( hdc );
  GLXFBConfig* cfgs = NULL;
  int nCfgs = 0;
  int attribs[256];
722
  unsigned nAttribs = 0;
723 724 725

  TRACE("(%p, %d, %d, %d, %p)\n", hdc, iPixelFormat, iWidth, iHeight, piAttribList);

726 727
  if (0 >= iPixelFormat) {
    ERR("(%p): unexpected iPixelFormat(%d) <= 0, returns NULL\n", hdc, iPixelFormat);
728
    SetLastError(ERROR_INVALID_PIXEL_FORMAT);
729 730 731 732 733 734 735
    return NULL; /* unespected error */
  }

  cfgs = glXGetFBConfigs(display, DefaultScreen(display), &nCfgs);

  if (NULL == cfgs || 0 == nCfgs) {
    ERR("(%p): Cannot get FB Configs for iPixelFormat(%d), returns NULL\n", hdc, iPixelFormat);
736
    SetLastError(ERROR_INVALID_PIXEL_FORMAT);
737 738 739 740
    return NULL; /* unespected error */
  }
  if (nCfgs < iPixelFormat) {
    ERR("(%p): unexpected iPixelFormat(%d) > nFormats(%d), returns NULL\n", hdc, iPixelFormat, nCfgs);
741 742
    SetLastError(ERROR_INVALID_PIXEL_FORMAT);
    goto create_failed; /* unespected error */
743 744
  }

745
  object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Wine_GLPBuffer));
746 747 748 749
  if (NULL == object) {
    SetLastError(ERROR_NO_SYSTEM_RESOURCES);
    goto create_failed; /* unespected error */
  }
750 751 752 753 754 755
  object->hdc = hdc;
  object->display = display;
  object->width = iWidth;
  object->height = iHeight;
  object->pixelFormat = iPixelFormat;

756
  nAttribs = ConvertAttribWGLtoGLX(piAttribList, attribs, object);
757
  PUSH2(attribs, GLX_PBUFFER_WIDTH,  iWidth);
758
  PUSH2(attribs, GLX_PBUFFER_HEIGHT, iHeight); 
759 760
  PUSH1(attribs, None);

761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842
  while (0 != *piAttribList) {
    int attr_v;
    switch (*piAttribList) {
    case WGL_TEXTURE_FORMAT_ARB: {
      if (!use_render_texture_emulation) {
	SetLastError(ERROR_INVALID_DATA);	  
	goto create_failed;
      }
      ++piAttribList;
      attr_v = *piAttribList;
      TRACE("WGL_render_texture Attribute: WGL_TEXTURE_FORMAT_ARB as %x\n", attr_v);
      switch (attr_v) {
      case WGL_TEXTURE_RGB_ARB:
      case WGL_TEXTURE_RGBA_ARB:
      case WGL_NO_TEXTURE_ARB:
	break;
      default:
	SetLastError(ERROR_INVALID_DATA);	  
	goto create_failed;
      }
      break;
    }
    
    case WGL_TEXTURE_TARGET_ARB: {
      if (!use_render_texture_emulation) {
	SetLastError(ERROR_INVALID_DATA);	  
	goto create_failed;
      }
      ++piAttribList;
      attr_v = *piAttribList;
      TRACE("WGL_render_texture Attribute: WGL_TEXTURE_TARGET_ARB as %x\n", attr_v);
      switch (attr_v) {
      case WGL_TEXTURE_CUBE_MAP_ARB: {
	if (iWidth != iHeight) {
	  SetLastError(ERROR_INVALID_DATA);	  
	  goto create_failed;
	}
	object->texture_target = GL_TEXTURE_CUBE_MAP;
	object->texture_bind_target = GL_TEXTURE_CUBE_MAP;
	break;
      }
      case WGL_TEXTURE_1D_ARB: {
	if (1 != iHeight) {
	  SetLastError(ERROR_INVALID_DATA);	  
	  goto create_failed;
	}
	object->texture_target = GL_TEXTURE_1D;
	object->texture_bind_target = GL_TEXTURE_1D;
	break;
      }
      case WGL_TEXTURE_2D_ARB: {
	object->texture_target = GL_TEXTURE_2D;
	object->texture_bind_target = GL_TEXTURE_2D;
	break;
      }
      case WGL_NO_TEXTURE_ARB:
	break;
      default:
	SetLastError(ERROR_INVALID_DATA);	  
	goto create_failed;
      }
      break;
    }

    case WGL_MIPMAP_TEXTURE_ARB: {
      if (!use_render_texture_emulation) {
	SetLastError(ERROR_INVALID_DATA);	  
	goto create_failed;
      }
      ++piAttribList;
      attr_v = *piAttribList;
      TRACE("WGL_render_texture Attribute: WGL_MIPMAP_TEXTURE_ARB as %x\n", attr_v);
      if (0 != attr_v) {
	SetLastError(ERROR_INVALID_DATA);	  
	goto create_failed;	
      }
      break ;
    }

    }
    ++piAttribList;
  }
843

844 845 846 847 848 849
  object->drawable = glXCreatePbuffer(display, cfgs[iPixelFormat - 1], attribs);
  TRACE("new Pbuffer drawable as %p\n", (void*) object->drawable);
  if (!object->drawable) {
    SetLastError(ERROR_NO_SYSTEM_RESOURCES);
    goto create_failed; /* unespected error */
  }
850
  TRACE("->(%p)\n", object);
851 852 853

  /** free list */
  XFree(cfgs);
854
  return (HPBUFFERARB) object;
855 856 857 858 859 860

create_failed:
  if (NULL != cfgs) XFree(cfgs);
  if (NULL != object) HeapFree(GetProcessHeap(), 0, object);
  TRACE("->(FAILED)\n");
  return (HPBUFFERARB) NULL;
861 862 863 864 865 866
}

HDC WINAPI wglGetPbufferDCARB(HPBUFFERARB hPbuffer)
{
  Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
  HDC hDC;
867 868 869 870
  if (NULL == object) {
    SetLastError(ERROR_INVALID_HANDLE);
    return NULL;
  }
871 872
  hDC = CreateCompatibleDC(object->hdc);
  set_drawable(hDC, object->drawable); /* works ?? */
873
  TRACE("(%p)->(%p)\n", hPbuffer, hDC);
874 875 876 877 878 879 880 881 882 883 884 885 886 887
  return hDC;
}

int WINAPI wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, HDC hdc)
{
  TRACE("(%p, %p)\n", hPbuffer, hdc);
  DeleteDC(hdc);
  return 0;
}

GLboolean WINAPI wglDestroyPbufferARB(HPBUFFERARB hPbuffer)
{
  Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
  TRACE("(%p)\n", hPbuffer);
888 889 890 891
  if (NULL == object) {
    SetLastError(ERROR_INVALID_HANDLE);
    return GL_FALSE;
  }
892 893 894 895 896 897 898 899
  glXDestroyPbuffer(object->display, object->drawable);
  HeapFree(GetProcessHeap(), 0, object);
  return GL_TRUE;
}

GLboolean WINAPI wglQueryPbufferARB(HPBUFFERARB hPbuffer, int iAttribute, int *piValue)
{
  Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
900 901 902 903 904
  TRACE("(%p, 0x%x, %p)\n", hPbuffer, iAttribute, piValue);
  if (NULL == object) {
    SetLastError(ERROR_INVALID_HANDLE);
    return GL_FALSE;
  }
905 906
  switch (iAttribute) {
  case WGL_PBUFFER_WIDTH_ARB:
Mike McCormack's avatar
Mike McCormack committed
907
    glXQueryDrawable(object->display, object->drawable, GLX_WIDTH, (unsigned int*) piValue);
908 909
    break;
  case WGL_PBUFFER_HEIGHT_ARB:
Mike McCormack's avatar
Mike McCormack committed
910
    glXQueryDrawable(object->display, object->drawable, GLX_HEIGHT, (unsigned int*) piValue);
911 912
    break;

913 914 915 916
  case WGL_PBUFFER_LOST_ARB:
    FIXME("unsupported WGL_PBUFFER_LOST_ARB (need glXSelectEvent/GLX_DAMAGED work)\n");
    break;

917 918 919 920 921 922 923 924 925 926 927 928 929 930
  case WGL_TEXTURE_FORMAT_ARB:
  case WGL_TEXTURE_TARGET_ARB:
  case WGL_MIPMAP_TEXTURE_ARB:
    if (!object->use_render_texture) {
      SetLastError(ERROR_INVALID_HANDLE);
      return GL_FALSE;
    }
    if (!use_render_texture_emulation) {
      SetLastError(ERROR_INVALID_DATA);      
      return GL_FALSE; /** how to FIX ? */
    }
    FIXME("unsupported WGL_ARB_render_texture attribute query for 0x%x\n", iAttribute);
    break;

931
  default:
932
    FIXME("unexpected attribute %x\n", iAttribute);
933 934 935 936 937 938 939 940
    break;
  }

  return GL_TRUE;
}

GLboolean WINAPI wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
{
941
  Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
942
  TRACE("(%p, %d)\n", hPbuffer, iBuffer);
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
  if (NULL == object) {
    SetLastError(ERROR_INVALID_HANDLE);
    return GL_FALSE;
  }
  if (!object->use_render_texture) {
    SetLastError(ERROR_INVALID_HANDLE);
    return GL_FALSE;
  }
  if (1 == use_render_texture_emulation) {
    return GL_TRUE;
  }
  if (NULL != p_glXBindTexImageARB) {
    return p_glXBindTexImageARB(object->display, object->drawable, iBuffer);
  }
  return GL_FALSE;
958 959 960 961
}

GLboolean WINAPI wglReleaseTexImageARB(HPBUFFERARB hPbuffer, int iBuffer)
{
962
  Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
963
  TRACE("(%p, %d)\n", hPbuffer, iBuffer);
964 965 966 967 968 969 970 971 972
  if (NULL == object) {
    SetLastError(ERROR_INVALID_HANDLE);
    return GL_FALSE;
  }
  if (!object->use_render_texture) {
    SetLastError(ERROR_INVALID_HANDLE);
    return GL_FALSE;
  }
  if (1 == use_render_texture_emulation) {
Mike McCormack's avatar
Mike McCormack committed
973
    GLint prev_binded_tex;
974 975 976 977 978 979 980 981 982 983 984 985 986 987
    glGetIntegerv(object->texture_target, &prev_binded_tex);
    glBindTexture(object->texture_target, object->texture);
    if (GL_TEXTURE_1D == object->texture_target) {
      glCopyTexSubImage1D(object->texture_bind_target, object->texture_level, 0, 0, 0, object->width);
    } else {
      glCopyTexSubImage2D(object->texture_bind_target, object->texture_level, 0, 0, 0, 0, object->width, object->height);
    }
    glBindTexture(object->texture_target, prev_binded_tex);
    return GL_TRUE;
  }
  if (NULL != p_glXReleaseTexImageARB) {
    return p_glXReleaseTexImageARB(object->display, object->drawable, iBuffer);
  }
  return GL_FALSE;
988 989 990 991
}

GLboolean WINAPI wglSetPbufferAttribARB(HPBUFFERARB hPbuffer, const int *piAttribList)
{
992 993
  Wine_GLPBuffer* object = (Wine_GLPBuffer*) hPbuffer;
  WARN("(%p, %p): alpha-testing, report any problem\n", hPbuffer, piAttribList);
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
  if (NULL == object) {
    SetLastError(ERROR_INVALID_HANDLE);
    return GL_FALSE;
  }
  if (!object->use_render_texture) {
    SetLastError(ERROR_INVALID_HANDLE);
    return GL_FALSE;
  }
  if (1 == use_render_texture_emulation) {
    return GL_TRUE;
  }
  if (NULL != p_glXDrawableAttribARB) {
    return p_glXDrawableAttribARB(object->display, object->drawable, piAttribList); 
  }
  return GL_FALSE;
1009 1010
}

1011 1012
static const struct {
    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 1016
			   const char *server_glx_extensions, const char *client_glx_extensions);
} extension_list[] = {
1017 1018 1019 1020 1021 1022
  { "WGL_ARB_make_current_read", query_function_make_current_read },
  { "WGL_ARB_multisample",       query_function_multisample },
  { "WGL_ARB_pbuffer",           query_function_pbuffer },
  { "WGL_ARB_pixel_format" ,     query_function_pixel_format },
  { "WGL_ARB_render_texture",    query_function_render_texture },
  { "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 1029 1030 1031 1032 1033
{
    int size = strlen(WGL_extensions_base);
    const char *glx_extensions = glXQueryExtensionsString(display, screen);
    const char *server_glx_extensions = glXQueryServerString(display, screen, GLX_EXTENSIONS);
    const char *client_glx_extensions = glXGetClientString(display, GLX_EXTENSIONS);
    const char *gl_extensions = (const char *) glGetString(GL_EXTENSIONS);
    const char *gl_version = (const char *) glGetString(GL_VERSION);
1034
    const char *glx_version = glXGetClientString(display, GLX_VERSION);
1035 1036 1037 1038 1039 1040 1041 1042 1043
    int i;

    TRACE("GL version      : %s.\n", debugstr_a(gl_version));
    TRACE("GL exts         : %s.\n", debugstr_a(gl_extensions));
    TRACE("GLX exts        : %s.\n", debugstr_a(glx_extensions));
    TRACE("Server GLX exts : %s.\n", debugstr_a(server_glx_extensions));
    TRACE("Client GLX exts : %s.\n", debugstr_a(client_glx_extensions));

    for (i = 0; i < (sizeof(extension_list) / sizeof(extension_list[0])); i++) {
1044 1045 1046
        if (strstr(disabled_extensions, extension_list[i].name)) continue ; /* disabled by config, next */
	if (extension_list[i].query_function(proc, 
					     gl_version, gl_extensions, 
1047
					     glx_version, glx_extensions,
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
					     server_glx_extensions, client_glx_extensions)) {
	    size += strlen(extension_list[i].name) + 1;
	}
    }

    /* For the moment, only 'base' extensions are supported. */
    WGL_extensions = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + 1);
    if (WGL_extensions == NULL) {
	WGL_extensions = (char *) WGL_extensions_base;
    } else {
	strcpy(WGL_extensions, WGL_extensions_base);
	for (i = 0; i < (sizeof(extension_list) / sizeof(extension_list[0])); i++) {
1060 1061 1062
	    if (strstr(disabled_extensions, extension_list[i].name)) continue ; /* disabled by config, next */
	    if (extension_list[i].query_function(proc, 
						 gl_version, gl_extensions, 
1063
						 glx_version, glx_extensions,
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
						 server_glx_extensions, client_glx_extensions)) {
		strcat(WGL_extensions, " ");
		strcat(WGL_extensions, extension_list[i].name);
	    }
	}
    }

    TRACE("Supporting following WGL extensions : %s.\n", debugstr_a(WGL_extensions));
}

void wgl_ext_finalize_extensions(void)
{
    if (WGL_extensions != WGL_extensions_base) {
	HeapFree(GetProcessHeap(), 0, WGL_extensions);
    }
}

1081 1082 1083 1084
/*
 * Putting this at the end to prevent having to write the prototypes :-) 
 *
 * @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 1090 1091 1092
    { "wglBindTexImageARB", (void *) wglBindTexImageARB, NULL, NULL},
    { "wglChoosePixelFormatARB", (void *) wglChoosePixelFormatARB, NULL, NULL},
    { "wglCreatePbufferARB", (void *) wglCreatePbufferARB, NULL, NULL},
    { "wglDestroyPbufferARB", (void *) wglDestroyPbufferARB, NULL, NULL},
1093
    { "wglGetCurrentReadDCARB", (void *) wglGetCurrentReadDCARB, NULL, NULL},
1094
    { "wglGetExtensionsStringARB", (void *) wglGetExtensionsStringARB, NULL, NULL},
1095
    { "wglGetExtensionsStringEXT", (void *) wglGetExtensionsStringEXT, NULL, NULL},
1096 1097 1098 1099
    { "wglGetPbufferDCARB", (void *) wglGetPbufferDCARB, NULL, NULL},
    { "wglGetPixelFormatAttribfvARB", (void *) wglGetPixelFormatAttribfvARB, NULL, NULL},
    { "wglGetPixelFormatAttribivARB", (void *) wglGetPixelFormatAttribivARB, NULL, NULL},
    { "wglGetSwapIntervalEXT", (void *) wglGetSwapIntervalEXT, NULL, NULL},
1100
    { "wglMakeContextCurrentARB", (void *) wglMakeContextCurrentARB, NULL, NULL },
1101 1102 1103 1104
    { "wglQueryPbufferARB", (void *) wglQueryPbufferARB, NULL, NULL},
    { "wglReleasePbufferDCARB", (void *) wglReleasePbufferDCARB, NULL, NULL},
    { "wglReleaseTexImageARB", (void *) wglReleaseTexImageARB, NULL, NULL},
    { "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]);