wgl.c 23.7 KB
Newer Older
Lionel Ulmer's avatar
Lionel Ulmer committed
1
/* Window-specific OpenGL functions implementation.
2 3
 *
 * Copyright (c) 1999 Lionel Ulmer
4
 * Copyright (c) 2005 Raphael Junqueira
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19
 */
Lionel Ulmer's avatar
Lionel Ulmer committed
20

21
#include "config.h"
22
#include "wine/port.h"
23

24
#include <stdarg.h>
Lionel Ulmer's avatar
Lionel Ulmer committed
25
#include <stdlib.h>
26
#include <string.h>
Lionel Ulmer's avatar
Lionel Ulmer committed
27 28

#include "windef.h"
29 30
#include "winbase.h"
#include "winuser.h"
31
#include "winerror.h"
32
#include "winreg.h"
33
#include "wingdi.h"
34 35
#include "winternl.h"
#include "winnt.h"
Lionel Ulmer's avatar
Lionel Ulmer committed
36 37

#include "opengl_ext.h"
38 39 40 41 42
#ifdef HAVE_GL_GLU_H
#undef far
#undef near
#include <GL/glu.h>
#endif
43
#include "wine/library.h"
44
#include "wine/debug.h"
Lionel Ulmer's avatar
Lionel Ulmer committed
45

46 47
WINE_DEFAULT_DEBUG_CHANNEL(wgl);
WINE_DECLARE_DEBUG_CHANNEL(opengl);
Lionel Ulmer's avatar
Lionel Ulmer committed
48

49
typedef struct wine_wgl_s {
50
    PROC WINAPI  (*p_wglGetProcAddress)(LPCSTR  lpszProc);
51

52 53
    void WINAPI  (*p_wglDisable)(GLenum cap);
    void WINAPI  (*p_wglEnable)(GLenum cap);
54
    void WINAPI  (*p_wglGetIntegerv)(GLenum pname, GLint* params);
55 56 57
    GLboolean WINAPI (*p_wglIsEnabled)(GLenum cap);
    void WINAPI  (*p_wglScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
    void WINAPI  (*p_wglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
58 59 60 61
} wine_wgl_t;

/** global wgl object */
static wine_wgl_t wine_wgl;
62

63 64 65 66
/* x11drv GDI escapes */
#define X11DRV_ESCAPE 6789
enum x11drv_escape_codes
{
67 68 69 70 71 72 73 74
    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 */
    X11DRV_START_EXPOSURES,     /* start graphics exposures */
    X11DRV_END_EXPOSURES,       /* end graphics exposures */
    X11DRV_GET_DCE,             /* get the DCE pointer */
    X11DRV_SET_DCE,             /* set the DCE pointer */
75 76
    X11DRV_GET_GLX_DRAWABLE,    /* get current glx drawable for a DC */
    X11DRV_SYNC_PIXMAP          /* sync the dibsection to its pixmap */
77 78
};

79 80 81
void (*wine_tsx11_lock_ptr)(void) = NULL;
void (*wine_tsx11_unlock_ptr)(void) = NULL;

82 83
static HMODULE opengl32_handle;

84 85 86
static char  internal_gl_disabled_extensions[512];
static char* internal_gl_extensions = NULL;

87 88 89
typedef struct wine_glcontext {
  HDC hdc;
  XVisualInfo *vis;
90 91
  GLXFBConfig fb_conf;
  GLXContext ctx;
92
  BOOL do_escape;
93
  /* ... more stuff here */
94
} Wine_GLContext;
95

96 97
void enter_gl(void)
{
98 99 100 101 102 103 104
    Wine_GLContext *curctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
    
    if (curctx && curctx->do_escape)
    {
        enum x11drv_escape_codes escape = X11DRV_SYNC_PIXMAP;
        ExtEscape(curctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape, 0, NULL);
    }
105 106 107 108 109

    wine_tsx11_lock_ptr();
    return;
}

110 111
const GLubyte * WINAPI wine_glGetString( GLenum name );

112
/***********************************************************************
113
 *		wglCreateLayerContext (OPENGL32.@)
114
 */
Lionel Ulmer's avatar
Lionel Ulmer committed
115 116
HGLRC WINAPI wglCreateLayerContext(HDC hdc,
				   int iLayerPlane) {
117 118 119 120 121 122
  TRACE("(%p,%d)\n", hdc, iLayerPlane);

  if (iLayerPlane == 0) {
      return wglCreateContext(hdc);
  }
  FIXME(" no handler for layer %d\n", iLayerPlane);
Lionel Ulmer's avatar
Lionel Ulmer committed
123 124 125 126

  return NULL;
}

127
/***********************************************************************
128
 *		wglCopyContext (OPENGL32.@)
129
 */
Lionel Ulmer's avatar
Lionel Ulmer committed
130 131 132 133 134 135 136 137
BOOL WINAPI wglCopyContext(HGLRC hglrcSrc,
			   HGLRC hglrcDst,
			   UINT mask) {
  FIXME("(%p,%p,%d)\n", hglrcSrc, hglrcDst, mask);

  return FALSE;
}

138
/***********************************************************************
139
 *		wglDescribeLayerPlane (OPENGL32.@)
140
 */
Lionel Ulmer's avatar
Lionel Ulmer committed
141 142 143 144 145
BOOL WINAPI wglDescribeLayerPlane(HDC hdc,
				  int iPixelFormat,
				  int iLayerPlane,
				  UINT nBytes,
				  LPLAYERPLANEDESCRIPTOR plpd) {
146
  FIXME("(%p,%d,%d,%d,%p)\n", hdc, iPixelFormat, iLayerPlane, nBytes, plpd);
Lionel Ulmer's avatar
Lionel Ulmer committed
147 148 149 150

  return FALSE;
}

151
/***********************************************************************
152
 *		wglGetLayerPaletteEntries (OPENGL32.@)
153
 */
Lionel Ulmer's avatar
Lionel Ulmer committed
154 155 156 157 158 159 160 161 162 163 164
int WINAPI wglGetLayerPaletteEntries(HDC hdc,
				     int iLayerPlane,
				     int iStart,
				     int cEntries,
				     const COLORREF *pcr) {
  FIXME("(): stub !\n");

  return 0;
}

static int compar(const void *elt_a, const void *elt_b) {
Eric Pouech's avatar
Eric Pouech committed
165 166
  return strcmp(((const OpenGL_extension *) elt_a)->name,
		((const OpenGL_extension *) elt_b)->name);
Lionel Ulmer's avatar
Lionel Ulmer committed
167 168
}

169 170 171
/* Check if a GL extension is supported */
static BOOL is_extension_supported(const char* extension)
{
172
    const char *gl_ext_string = (const char*)wine_glGetString(GL_EXTENSIONS);
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192

    TRACE("Checking for extension '%s'\n", extension);

    if(!gl_ext_string) {
        ERR("No OpenGL extensions found, check if your OpenGL setup is correct!\n");
        return FALSE;
    }

    /* We use the GetProcAddress function from the display driver to retrieve function pointers
     * for OpenGL and WGL extensions. In case of winex11.drv the OpenGL extension lookup is done
     * using glXGetProcAddress. This function is quite unreliable in the sense that its specs don't
     * require the function to return NULL when a extension isn't found. For this reason we check
     * if the OpenGL extension required for the function we are looking up is supported. */

    /* Check if the extension is part of the GL extension string to see if it is supported. */
    if(strstr(gl_ext_string, extension) != NULL)
        return TRUE;

    /* In general an OpenGL function starts as an ARB/EXT extension and at some stage
     * it becomes part of the core OpenGL library and can be reached without the ARB/EXT
193
     * suffix as well. In the extension table, these functions contain GL_VERSION_major_minor.
194 195 196 197 198 199 200 201 202 203 204 205
     * Check if we are searching for a core GL function */
    if(strncmp(extension, "GL_VERSION_", 11) == 0)
    {
        const GLubyte *gl_version = glGetString(GL_VERSION);
        const const char *version = extension + 11; /* Move past 'GL_VERSION_' */

        if(!gl_version) {
            ERR("Error no OpenGL version found,\n");
            return FALSE;
        }

        /* Compare the major/minor version numbers of the native OpenGL library and what is required by the function.
206
         * The gl_version string is guaranteed to have at least a major/minor and sometimes it has a release number as well. */
207 208 209 210 211 212 213 214 215
        if( (gl_version[0] >= version[0]) || ((gl_version[0] == version[0]) && (gl_version[2] >= version[2])) ) {
            return TRUE;
        }
        WARN("The function requires OpenGL version '%c.%c' while your drivers only provide '%c.%c'\n", version[0], version[2], gl_version[0], gl_version[2]);
    }

    return FALSE;
}

216 217 218
/***********************************************************************
 *		wglGetProcAddress (OPENGL32.@)
 */
219
PROC WINAPI wglGetProcAddress(LPCSTR  lpszProc) {
Lionel Ulmer's avatar
Lionel Ulmer committed
220
  void *local_func;
221
  OpenGL_extension  ext;
222
  const OpenGL_extension *ext_ret;
223

Lionel Ulmer's avatar
Lionel Ulmer committed
224 225
  TRACE("(%s)\n", lpszProc);

226
  if(lpszProc == NULL)
227 228
    return NULL;

Lionel Ulmer's avatar
Lionel Ulmer committed
229
  /* First, look if it's not already defined in the 'standard' OpenGL functions */
230
  if ((local_func = GetProcAddress(opengl32_handle, lpszProc)) != NULL) {
231
    TRACE(" found function in 'standard' OpenGL functions (%p)\n", local_func);
Lionel Ulmer's avatar
Lionel Ulmer committed
232 233 234
    return local_func;
  }

235
  /* After that, search in the thunks to find the real name of the extension */
236 237
  ext.name = lpszProc;
  ext_ret = (const OpenGL_extension *) bsearch(&ext, extension_registry,
238 239
					 extension_registry_size, sizeof(OpenGL_extension), compar);

240
  /* If nothing was found, we are looking for a WGL extension or an unknown GL extension. */
241
  if (ext_ret == NULL) {
242 243 244 245 246
    /* If the function name starts with a w it is a WGL extension */
    if(lpszProc[0] == 'w')
      return wine_wgl.p_wglGetProcAddress(lpszProc);

    /* We are dealing with an unknown GL extension. */
247
    WARN("Extension '%s' not defined in opengl32.dll's function table!\n", lpszProc);
248
    return NULL;
249
  } else { /* We are looking for an OpenGL extension */
250 251 252 253 254 255 256

    /* Check if the GL extension required by the function is available */
    if(!is_extension_supported(ext_ret->extension)) {
        WARN("Extension '%s' required by function '%s' not supported!\n", ext_ret->extension, lpszProc);
        return NULL;
    }

257 258
    local_func = wine_wgl.p_wglGetProcAddress(ext_ret->name);

259
    /* After that, look at the extensions defined in the Linux OpenGL library */
260
    if (local_func == NULL) {
261 262
      char buf[256];
      void *ret = NULL;
263

264
      /* Remove the 3 last letters (EXT, ARB, ...).
265

266 267 268 269 270
	 I know that some extensions have more than 3 letters (MESA, NV,
	 INTEL, ...), but this is only a stop-gap measure to fix buggy
	 OpenGL drivers (moreover, it is only useful for old 1.0 apps
	 that query the glBindTextureEXT extension).
      */
271 272
      memcpy(buf, ext_ret->name, strlen(ext_ret->name) - 3);
      buf[strlen(ext_ret->name) - 3] = '\0';
273
      TRACE(" extension not found in the Linux OpenGL library, checking against libGL bug with %s..\n", buf);
274

275
      ret = GetProcAddress(opengl32_handle, buf);
276
      if (ret != NULL) {
277
        TRACE(" found function in main OpenGL library (%p) !\n", ret);
278
      } else {
279
        WARN("Did not find function %s (%s) in your OpenGL library !\n", lpszProc, ext_ret->name);
280 281
      }

282
      return ret;
Lionel Ulmer's avatar
Lionel Ulmer committed
283
    } else {
284
      TRACE(" returning function  (%p)\n", ext_ret->func);
285
      extension_funcs[ext_ret - extension_registry] = local_func;
286

287
      return ext_ret->func;
Lionel Ulmer's avatar
Lionel Ulmer committed
288 289 290 291
    }
  }
}

292
/***********************************************************************
293
 *		wglRealizeLayerPalette (OPENGL32.@)
294
 */
Lionel Ulmer's avatar
Lionel Ulmer committed
295 296 297 298 299 300 301 302
BOOL WINAPI wglRealizeLayerPalette(HDC hdc,
				   int iLayerPlane,
				   BOOL bRealize) {
  FIXME("()\n");

  return FALSE;
}

303
/***********************************************************************
304
 *		wglSetLayerPaletteEntries (OPENGL32.@)
305
 */
Lionel Ulmer's avatar
Lionel Ulmer committed
306 307 308 309 310 311 312 313 314 315
int WINAPI wglSetLayerPaletteEntries(HDC hdc,
				     int iLayerPlane,
				     int iStart,
				     int cEntries,
				     const COLORREF *pcr) {
  FIXME("(): stub !\n");

  return 0;
}

316
/***********************************************************************
317
 *		wglSwapLayerBuffers (OPENGL32.@)
318
 */
Lionel Ulmer's avatar
Lionel Ulmer committed
319 320
BOOL WINAPI wglSwapLayerBuffers(HDC hdc,
				UINT fuPlanes) {
321
  TRACE_(opengl)("(%p, %08x)\n", hdc, fuPlanes);
Lionel Ulmer's avatar
Lionel Ulmer committed
322

323 324 325 326 327 328 329 330
  if (fuPlanes & WGL_SWAP_MAIN_PLANE) {
    if (!SwapBuffers(hdc)) return FALSE;
    fuPlanes &= ~WGL_SWAP_MAIN_PLANE;
  }

  if (fuPlanes) {
    WARN("Following layers unhandled : %08x\n", fuPlanes);
  }
331

332
  return TRUE;
Lionel Ulmer's avatar
Lionel Ulmer committed
333 334
}

335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
#ifdef HAVE_GL_GLU_H

static void fixed_to_double(POINTFX fixed, UINT em_size, GLdouble vertex[3])
{
    vertex[0] = (fixed.x.value + (GLdouble)fixed.x.fract / (1 << 16)) / em_size;  
    vertex[1] = (fixed.y.value + (GLdouble)fixed.y.fract / (1 << 16)) / em_size;  
    vertex[2] = 0.0;
}

static void tess_callback_vertex(GLvoid *vertex)
{
    GLdouble *dbl = vertex;
    TRACE("%f, %f, %f\n", dbl[0], dbl[1], dbl[2]);
    glVertex3dv(vertex);
}

static void tess_callback_begin(GLenum which)
{
    TRACE("%d\n", which);
    glBegin(which);
}

static void tess_callback_end(void)
{
    TRACE("\n");
    glEnd();
}

/***********************************************************************
 *		wglUseFontOutlines_common
 */
BOOL WINAPI wglUseFontOutlines_common(HDC hdc,
                                      DWORD first,
                                      DWORD count,
                                      DWORD listBase,
                                      FLOAT deviation,
                                      FLOAT extrusion,
                                      int format,
                                      LPGLYPHMETRICSFLOAT lpgmf,
                                      BOOL unicode)
{
    UINT glyph;
    const MAT2 identity = {{0,1},{0,0},{0,0},{0,1}};
    GLUtesselator *tess;
    LOGFONTW lf;
    HFONT old_font, unscaled_font;
    UINT em_size = 1024;
    RECT rc;

384
    TRACE("(%p, %d, %d, %d, %f, %f, %d, %p, %s)\n", hdc, first, count,
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
          listBase, deviation, extrusion, format, lpgmf, unicode ? "W" : "A");


    ENTER_GL();
    tess = gluNewTess();
    if(tess)
    {
        gluTessCallback(tess, GLU_TESS_VERTEX, (_GLUfuncptr)tess_callback_vertex);
        gluTessCallback(tess, GLU_TESS_BEGIN, (_GLUfuncptr)tess_callback_begin);
        gluTessCallback(tess, GLU_TESS_END, tess_callback_end);
    }
    LEAVE_GL();

    if(!tess) return FALSE;

    GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), &lf);
    rc.left = rc.right = rc.bottom = 0;
    rc.top = em_size;
    DPtoLP(hdc, (POINT*)&rc, 2);
    lf.lfHeight = -abs(rc.top - rc.bottom);
    lf.lfOrientation = lf.lfEscapement = 0;
    unscaled_font = CreateFontIndirectW(&lf);
    old_font = SelectObject(hdc, unscaled_font);

    for (glyph = first; glyph < first + count; glyph++)
    {
        DWORD needed;
        GLYPHMETRICS gm;
        BYTE *buf;
        TTPOLYGONHEADER *pph;
        TTPOLYCURVE *ppc;
        GLdouble *vertices;

        if(unicode)
            needed = GetGlyphOutlineW(hdc, glyph, GGO_NATIVE, &gm, 0, NULL, &identity);
        else
            needed = GetGlyphOutlineA(hdc, glyph, GGO_NATIVE, &gm, 0, NULL, &identity);

        if(needed == GDI_ERROR)
            goto error;

        buf = HeapAlloc(GetProcessHeap(), 0, needed);
        vertices = HeapAlloc(GetProcessHeap(), 0, needed / sizeof(POINTFX) * 3 * sizeof(GLdouble));

        if(unicode)
            GetGlyphOutlineW(hdc, glyph, GGO_NATIVE, &gm, needed, buf, &identity);
        else
            GetGlyphOutlineA(hdc, glyph, GGO_NATIVE, &gm, needed, buf, &identity);

        TRACE("glyph %d\n", glyph);

        if(lpgmf)
        {
438 439 440 441 442 443 444
            lpgmf->gmfBlackBoxX = (float)gm.gmBlackBoxX / em_size;
            lpgmf->gmfBlackBoxY = (float)gm.gmBlackBoxY / em_size;
            lpgmf->gmfptGlyphOrigin.x = (float)gm.gmptGlyphOrigin.x / em_size;
            lpgmf->gmfptGlyphOrigin.y = (float)gm.gmptGlyphOrigin.y / em_size;
            lpgmf->gmfCellIncX = (float)gm.gmCellIncX / em_size;
            lpgmf->gmfCellIncY = (float)gm.gmCellIncY / em_size;

445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 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 502 503 504 505 506 507 508 509 510
            TRACE("%fx%f at %f,%f inc %f,%f\n", lpgmf->gmfBlackBoxX, lpgmf->gmfBlackBoxY,
                  lpgmf->gmfptGlyphOrigin.x, lpgmf->gmfptGlyphOrigin.y, lpgmf->gmfCellIncX, lpgmf->gmfCellIncY); 
            lpgmf++;
        }

	ENTER_GL();
	glNewList(listBase++, GL_COMPILE);
        gluTessBeginPolygon(tess, NULL);

        pph = (TTPOLYGONHEADER*)buf;
        while((BYTE*)pph < buf + needed)
        {
            TRACE("\tstart %d, %d\n", pph->pfxStart.x.value, pph->pfxStart.y.value);

            gluTessBeginContour(tess);

            fixed_to_double(pph->pfxStart, em_size, vertices);
            gluTessVertex(tess, vertices, vertices);
            vertices += 3;

            ppc = (TTPOLYCURVE*)((char*)pph + sizeof(*pph));
            while((char*)ppc < (char*)pph + pph->cb)
            {
                int i;

                switch(ppc->wType) {
                case TT_PRIM_LINE:
                    for(i = 0; i < ppc->cpfx; i++)
                    {
                        TRACE("\t\tline to %d, %d\n", ppc->apfx[i].x.value, ppc->apfx[i].y.value);
                        fixed_to_double(ppc->apfx[i], em_size, vertices); 
                        gluTessVertex(tess, vertices, vertices);
                        vertices += 3;
                    }
                    break;

                case TT_PRIM_QSPLINE:
                    for(i = 0; i < ppc->cpfx/2; i++)
                    {
                        /* FIXME just connecting the control points for now */
                        TRACE("\t\tcurve  %d,%d %d,%d\n",
                              ppc->apfx[i * 2].x.value,     ppc->apfx[i * 3].y.value,
                              ppc->apfx[i * 2 + 1].x.value, ppc->apfx[i * 3 + 1].y.value);
                        fixed_to_double(ppc->apfx[i * 2], em_size, vertices); 
                        gluTessVertex(tess, vertices, vertices);
                        vertices += 3;
                        fixed_to_double(ppc->apfx[i * 2 + 1], em_size, vertices); 
                        gluTessVertex(tess, vertices, vertices);
                        vertices += 3;
                    }
                    break;
                default:
                    ERR("\t\tcurve type = %d\n", ppc->wType);
                    gluTessEndContour(tess);
                    goto error_in_list;
                }

                ppc = (TTPOLYCURVE*)((char*)ppc + sizeof(*ppc) +
                                     (ppc->cpfx - 1) * sizeof(POINTFX));
            }
            gluTessEndContour(tess);
            pph = (TTPOLYGONHEADER*)((char*)pph + pph->cb);
        }

error_in_list:
        gluTessEndPolygon(tess);
511
        glTranslated((GLdouble)gm.gmCellIncX / em_size, (GLdouble)gm.gmCellIncY / em_size, 0.0);
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
        glEndList();
        LEAVE_GL();
        HeapFree(GetProcessHeap(), 0, buf);
        HeapFree(GetProcessHeap(), 0, vertices);
    }

 error:
    DeleteObject(SelectObject(hdc, old_font));
    gluDeleteTess(tess);
    return TRUE;

}

#else /* HAVE_GL_GLU_H */

BOOL WINAPI wglUseFontOutlines_common(HDC hdc,
                                      DWORD first,
                                      DWORD count,
                                      DWORD listBase,
                                      FLOAT deviation,
                                      FLOAT extrusion,
                                      int format,
                                      LPGLYPHMETRICSFLOAT lpgmf,
                                      BOOL unicode)
{
    FIXME("Unable to compile in wglUseFontOutlines support without GL/glu.h\n");
    return FALSE;
}

#endif /* HAVE_GL_GLU_H */

543
/***********************************************************************
544
 *		wglUseFontOutlinesA (OPENGL32.@)
545
 */
546 547 548 549 550 551 552
BOOL WINAPI wglUseFontOutlinesA(HDC hdc,
				DWORD first,
				DWORD count,
				DWORD listBase,
				FLOAT deviation,
				FLOAT extrusion,
				int format,
553 554 555 556
				LPGLYPHMETRICSFLOAT lpgmf)
{
    return wglUseFontOutlines_common(hdc, first, count, listBase, deviation, extrusion, format, lpgmf, FALSE);
}
Lionel Ulmer's avatar
Lionel Ulmer committed
557

558 559 560 561 562 563 564 565 566 567 568 569 570
/***********************************************************************
 *		wglUseFontOutlinesW (OPENGL32.@)
 */
BOOL WINAPI wglUseFontOutlinesW(HDC hdc,
				DWORD first,
				DWORD count,
				DWORD listBase,
				FLOAT deviation,
				FLOAT extrusion,
				int format,
				LPGLYPHMETRICSFLOAT lpgmf)
{
    return wglUseFontOutlines_common(hdc, first, count, listBase, deviation, extrusion, format, lpgmf, TRUE);
Lionel Ulmer's avatar
Lionel Ulmer committed
571 572
}

573 574 575 576
/***********************************************************************
 *              glEnable (OPENGL32.@)
 */
void WINAPI wine_glEnable( GLenum cap )
577
{
578 579
    TRACE("(%d)\n", cap );
    wine_wgl.p_wglEnable(cap);
580 581
}

582 583 584 585
/***********************************************************************
 *              glIsEnabled (OPENGL32.@)
 */
GLboolean WINAPI wine_glIsEnabled( GLenum cap )
586
{
587
    TRACE("(%d)\n", cap );
588
    return wine_wgl.p_wglIsEnabled(cap);
589 590
}

591 592 593 594
/***********************************************************************
 *              glDisable (OPENGL32.@)
 */
void WINAPI wine_glDisable( GLenum cap )
595
{
596
    TRACE("(%d)\n", cap );
597 598 599
    wine_wgl.p_wglDisable(cap);
}

600 601 602 603
/***********************************************************************
 *              glScissor (OPENGL32.@)
 */
void WINAPI wine_glScissor( GLint x, GLint y, GLsizei width, GLsizei height )
604
{
605
    TRACE("(%d, %d, %d, %d)\n", x, y, width, height );
606 607 608
    wine_wgl.p_wglScissor(x, y, width, height);
}

609 610 611 612
/***********************************************************************
 *              glViewport (OPENGL32.@)
 */
void WINAPI wine_glViewport( GLint x, GLint y, GLsizei width, GLsizei height )
613
{
614
    TRACE("(%d, %d, %d, %d)\n", x, y, width, height );
615 616 617
    wine_wgl.p_wglViewport(x, y, width, height);
}

618 619 620 621 622 623
/***********************************************************************
 *              glGetString (OPENGL32.@)
 */
const GLubyte * WINAPI wine_glGetString( GLenum name )
{
  const GLubyte *ret;
624
  const char* GL_Extensions = NULL;
625

626
  if (GL_EXTENSIONS != name) {
627 628 629 630
    ENTER_GL();
    ret = glGetString(name);
    LEAVE_GL();
    return ret;
631 632 633
  }

  if (NULL == internal_gl_extensions) {
634
    ENTER_GL();
Mike McCormack's avatar
Mike McCormack committed
635
    GL_Extensions = (const char *) glGetString(GL_EXTENSIONS);
636

637 638
    if (GL_Extensions)
    {
639
      size_t len = strlen(GL_Extensions);
640
      internal_gl_extensions = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len + 2);
641

642
      TRACE("GL_EXTENSIONS reported:\n");
643 644 645
      while (*GL_Extensions != 0x00) {
	const char* Start = GL_Extensions;
	char        ThisExtn[256];
646

647 648 649 650
	while (*GL_Extensions != ' ' && *GL_Extensions != 0x00) {
	  GL_Extensions++;
	}
	memcpy(ThisExtn, Start, (GL_Extensions - Start));
651
        ThisExtn[GL_Extensions - Start] = 0;
652 653 654 655 656
	TRACE("- %s:", ThisExtn);
	
	/* test if supported API is disabled by config */
	if (NULL == strstr(internal_gl_disabled_extensions, ThisExtn)) {
	  strcat(internal_gl_extensions, " ");
657
	  strcat(internal_gl_extensions, ThisExtn);
658 659 660 661 662 663 664 665
	  TRACE(" active\n");
	} else {
	  TRACE(" deactived (by config)\n");
	}

	if (*GL_Extensions == ' ') GL_Extensions++;
      }
    }
666
    LEAVE_GL();
667
  }
Mike McCormack's avatar
Mike McCormack committed
668
  return (const GLubyte *) internal_gl_extensions;
669 670
}

671 672 673 674 675 676
/***********************************************************************
 *              glGetIntegerv (OPENGL32.@)
 */
void WINAPI wine_glGetIntegerv( GLenum pname, GLint* params )
{
    wine_wgl.p_wglGetIntegerv(pname, params);
677 678
}

679

680 681 682 683 684 685
/* No need to load any other libraries as according to the ABI, libGL should be self-sufficient and
   include all dependencies
*/
#ifndef SONAME_LIBGL
#define SONAME_LIBGL "libGL.so"
#endif
686

Lionel Ulmer's avatar
Lionel Ulmer committed
687 688
/* This is for brain-dead applications that use OpenGL functions before even
   creating a rendering context.... */
689 690
static BOOL process_attach(void)
{
691
  HMODULE mod_x11, mod_gdi32;
692 693
  DWORD size = sizeof(internal_gl_disabled_extensions);
  HKEY hkey = 0;
694

695 696 697 698 699
  GetDesktopWindow();  /* make sure winex11 is loaded (FIXME) */
  mod_x11 = GetModuleHandleA( "winex11.drv" );
  mod_gdi32 = GetModuleHandleA( "gdi32.dll" );

  if (!mod_x11 || !mod_gdi32)
700
  {
701
      ERR("X11DRV or GDI32 not loaded. Cannot create default context.\n");
702 703 704
      return FALSE;
  }

705 706
  wine_tsx11_lock_ptr   = (void *)GetProcAddress( mod_x11, "wine_tsx11_lock" );
  wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod_x11, "wine_tsx11_unlock" );
707

708
  wine_wgl.p_wglGetProcAddress = (void *)GetProcAddress(mod_gdi32, "wglGetProcAddress");
709

710
  /* Interal WGL function */
711 712
  wine_wgl.p_wglDisable = (void *)wine_wgl.p_wglGetProcAddress("wglDisable");
  wine_wgl.p_wglEnable = (void *)wine_wgl.p_wglGetProcAddress("wglEnable");
713
  wine_wgl.p_wglGetIntegerv = (void *)wine_wgl.p_wglGetProcAddress("wglGetIntegerv");
714 715 716
  wine_wgl.p_wglIsEnabled = (void *)wine_wgl.p_wglGetProcAddress("wglIsEnabled");
  wine_wgl.p_wglScissor = (void *)wine_wgl.p_wglGetProcAddress("wglScissor");
  wine_wgl.p_wglViewport = (void *)wine_wgl.p_wglGetProcAddress("wglViewport");
717

718
  internal_gl_disabled_extensions[0] = 0;
719
  if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\OpenGL", &hkey)) {
720
    if (!RegQueryValueExA( hkey, "DisabledExtensions", 0, NULL, (LPBYTE)internal_gl_disabled_extensions, &size)) {
721 722 723 724 725
      TRACE("found DisabledExtensions=\"%s\"\n", internal_gl_disabled_extensions);
    }
    RegCloseKey(hkey);
  }

726
  return TRUE;
Lionel Ulmer's avatar
Lionel Ulmer committed
727
}
728

729

730 731
/**********************************************************************/

732 733
static void process_detach(void)
{
734
  HeapFree(GetProcessHeap(), 0, internal_gl_extensions);
735 736
}

737 738 739
/***********************************************************************
 *           OpenGL initialisation routine
 */
740
BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
741
{
742 743 744
    switch(reason)
    {
    case DLL_PROCESS_ATTACH:
745
        opengl32_handle = hinst;
746
        DisableThreadLibraryCalls(hinst);
747 748 749 750 751 752
        return process_attach();
    case DLL_PROCESS_DETACH:
        process_detach();
        break;
    }
    return TRUE;
753
}