wininet: Use proc instead of enum in FTPFINDNEXTW request.
[wine] / dlls / opengl32 / wgl.c
1 /* Window-specific OpenGL functions implementation.
2  *
3  * Copyright (c) 1999 Lionel Ulmer
4  * Copyright (c) 2005 Raphael Junqueira
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * 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  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winuser.h"
31 #include "winerror.h"
32 #include "winreg.h"
33 #include "wingdi.h"
34 #include "winternl.h"
35 #include "winnt.h"
36
37 #include "opengl_ext.h"
38 #ifdef HAVE_GL_GLU_H
39 #undef far
40 #undef near
41 #include <GL/glu.h>
42 #endif
43 #include "wine/library.h"
44 #include "wine/debug.h"
45
46 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
47 WINE_DECLARE_DEBUG_CHANNEL(opengl);
48
49 typedef struct wine_wgl_s {
50     PROC WINAPI  (*p_wglGetProcAddress)(LPCSTR  lpszProc);
51
52     void WINAPI  (*p_wglDisable)(GLenum cap);
53     void WINAPI  (*p_wglEnable)(GLenum cap);
54     void WINAPI  (*p_wglGetIntegerv)(GLenum pname, GLint* params);
55     GLboolean WINAPI (*p_wglIsEnabled)(GLenum cap);
56     void WINAPI  (*p_wglScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
57     void WINAPI  (*p_wglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
58 } wine_wgl_t;
59
60 /** global wgl object */
61 static wine_wgl_t wine_wgl;
62
63 /* x11drv GDI escapes */
64 #define X11DRV_ESCAPE 6789
65 enum x11drv_escape_codes
66 {
67     X11DRV_GET_DISPLAY,         /* get X11 display for a DC */
68     X11DRV_GET_DRAWABLE,        /* get current drawable for a DC */
69     X11DRV_GET_FONT,            /* get current X font for a DC */
70     X11DRV_SET_DRAWABLE,        /* set current drawable for a DC */
71     X11DRV_START_EXPOSURES,     /* start graphics exposures */
72     X11DRV_END_EXPOSURES,       /* end graphics exposures */
73     X11DRV_GET_DCE,             /* get the DCE pointer */
74     X11DRV_SET_DCE,             /* set the DCE pointer */
75     X11DRV_GET_GLX_DRAWABLE,    /* get current glx drawable for a DC */
76     X11DRV_SYNC_PIXMAP          /* sync the dibsection to its pixmap */
77 };
78
79 void (*wine_tsx11_lock_ptr)(void) = NULL;
80 void (*wine_tsx11_unlock_ptr)(void) = NULL;
81
82 static HMODULE opengl32_handle;
83
84 static char  internal_gl_disabled_extensions[512];
85 static char* internal_gl_extensions = NULL;
86
87 typedef struct wine_glcontext {
88   HDC hdc;
89   XVisualInfo *vis;
90   GLXFBConfig fb_conf;
91   GLXContext ctx;
92   BOOL do_escape;
93   /* ... more stuff here */
94 } Wine_GLContext;
95
96 void enter_gl(void)
97 {
98     Wine_GLContext *curctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
99     
100     if (curctx && curctx->do_escape)
101     {
102         enum x11drv_escape_codes escape = X11DRV_SYNC_PIXMAP;
103         ExtEscape(curctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape, 0, NULL);
104     }
105
106     wine_tsx11_lock_ptr();
107     return;
108 }
109
110 const GLubyte * WINAPI wine_glGetString( GLenum name );
111
112 /***********************************************************************
113  *              wglCreateLayerContext (OPENGL32.@)
114  */
115 HGLRC WINAPI wglCreateLayerContext(HDC hdc,
116                                    int iLayerPlane) {
117   TRACE("(%p,%d)\n", hdc, iLayerPlane);
118
119   if (iLayerPlane == 0) {
120       return wglCreateContext(hdc);
121   }
122   FIXME(" no handler for layer %d\n", iLayerPlane);
123
124   return NULL;
125 }
126
127 /***********************************************************************
128  *              wglCopyContext (OPENGL32.@)
129  */
130 BOOL WINAPI wglCopyContext(HGLRC hglrcSrc,
131                            HGLRC hglrcDst,
132                            UINT mask) {
133   FIXME("(%p,%p,%d)\n", hglrcSrc, hglrcDst, mask);
134
135   return FALSE;
136 }
137
138 /***********************************************************************
139  *              wglDescribeLayerPlane (OPENGL32.@)
140  */
141 BOOL WINAPI wglDescribeLayerPlane(HDC hdc,
142                                   int iPixelFormat,
143                                   int iLayerPlane,
144                                   UINT nBytes,
145                                   LPLAYERPLANEDESCRIPTOR plpd) {
146   FIXME("(%p,%d,%d,%d,%p)\n", hdc, iPixelFormat, iLayerPlane, nBytes, plpd);
147
148   return FALSE;
149 }
150
151 /***********************************************************************
152  *              wglGetLayerPaletteEntries (OPENGL32.@)
153  */
154 int WINAPI wglGetLayerPaletteEntries(HDC hdc,
155                                      int iLayerPlane,
156                                      int iStart,
157                                      int cEntries,
158                                      const COLORREF *pcr) {
159   FIXME("(): stub !\n");
160
161   return 0;
162 }
163
164 static int compar(const void *elt_a, const void *elt_b) {
165   return strcmp(((const OpenGL_extension *) elt_a)->name,
166                 ((const OpenGL_extension *) elt_b)->name);
167 }
168
169 /* Check if a GL extension is supported */
170 static BOOL is_extension_supported(const char* extension)
171 {
172     const char *gl_ext_string = (const char*)wine_glGetString(GL_EXTENSIONS);
173
174     TRACE("Checking for extension '%s'\n", extension);
175
176     if(!gl_ext_string) {
177         ERR("No OpenGL extensions found, check if your OpenGL setup is correct!\n");
178         return FALSE;
179     }
180
181     /* We use the GetProcAddress function from the display driver to retrieve function pointers
182      * for OpenGL and WGL extensions. In case of winex11.drv the OpenGL extension lookup is done
183      * using glXGetProcAddress. This function is quite unreliable in the sense that its specs don't
184      * require the function to return NULL when a extension isn't found. For this reason we check
185      * if the OpenGL extension required for the function we are looking up is supported. */
186
187     /* Check if the extension is part of the GL extension string to see if it is supported. */
188     if(strstr(gl_ext_string, extension) != NULL)
189         return TRUE;
190
191     /* In general an OpenGL function starts as an ARB/EXT extension and at some stage
192      * 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      * Check if we are searching for a core GL function */
195     if(strncmp(extension, "GL_VERSION_", 11) == 0)
196     {
197         const GLubyte *gl_version = glGetString(GL_VERSION);
198         const const char *version = extension + 11; /* Move past 'GL_VERSION_' */
199
200         if(!gl_version) {
201             ERR("Error no OpenGL version found,\n");
202             return FALSE;
203         }
204
205         /* 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         if( (gl_version[0] >= version[0]) || ((gl_version[0] == version[0]) && (gl_version[2] >= version[2])) ) {
208             return TRUE;
209         }
210         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]);
211     }
212
213     return FALSE;
214 }
215
216 /***********************************************************************
217  *              wglGetProcAddress (OPENGL32.@)
218  */
219 PROC WINAPI wglGetProcAddress(LPCSTR  lpszProc) {
220   void *local_func;
221   OpenGL_extension  ext;
222   const OpenGL_extension *ext_ret;
223
224   TRACE("(%s)\n", lpszProc);
225
226   /* First, look if it's not already defined in the 'standard' OpenGL functions */
227   if ((local_func = GetProcAddress(opengl32_handle, lpszProc)) != NULL) {
228     TRACE(" found function in 'standard' OpenGL functions (%p)\n", local_func);
229     return local_func;
230   }
231
232   /* After that, search in the thunks to find the real name of the extension */
233   ext.name = lpszProc;
234   ext_ret = (const OpenGL_extension *) bsearch(&ext, extension_registry,
235                                          extension_registry_size, sizeof(OpenGL_extension), compar);
236
237   /* If nothing was found, we are looking for a WGL extension */
238   if (ext_ret == NULL) {
239     WARN("Extension '%s' not defined in opengl32.dll's function table!\n", lpszProc);
240     return wine_wgl.p_wglGetProcAddress(lpszProc);
241   } else { /* We are looking for an OpenGL extension */
242
243     /* Check if the GL extension required by the function is available */
244     if(!is_extension_supported(ext_ret->extension)) {
245         WARN("Extension '%s' required by function '%s' not supported!\n", ext_ret->extension, lpszProc);
246         return NULL;
247     }
248
249     local_func = wine_wgl.p_wglGetProcAddress(ext_ret->name);
250
251     /* After that, look at the extensions defined in the Linux OpenGL library */
252     if (local_func == NULL) {
253       char buf[256];
254       void *ret = NULL;
255
256       /* Remove the 3 last letters (EXT, ARB, ...).
257
258          I know that some extensions have more than 3 letters (MESA, NV,
259          INTEL, ...), but this is only a stop-gap measure to fix buggy
260          OpenGL drivers (moreover, it is only useful for old 1.0 apps
261          that query the glBindTextureEXT extension).
262       */
263       memcpy(buf, ext_ret->name, strlen(ext_ret->name) - 3);
264       buf[strlen(ext_ret->name) - 3] = '\0';
265       TRACE(" extension not found in the Linux OpenGL library, checking against libGL bug with %s..\n", buf);
266
267       ret = GetProcAddress(opengl32_handle, buf);
268       if (ret != NULL) {
269         TRACE(" found function in main OpenGL library (%p) !\n", ret);
270       } else {
271         WARN("Did not find function %s (%s) in your OpenGL library !\n", lpszProc, ext_ret->name);
272       }
273
274       return ret;
275     } else {
276       TRACE(" returning function  (%p)\n", ext_ret->func);
277       extension_funcs[ext_ret - extension_registry] = local_func;
278
279       return ext_ret->func;
280     }
281   }
282 }
283
284 /***********************************************************************
285  *              wglRealizeLayerPalette (OPENGL32.@)
286  */
287 BOOL WINAPI wglRealizeLayerPalette(HDC hdc,
288                                    int iLayerPlane,
289                                    BOOL bRealize) {
290   FIXME("()\n");
291
292   return FALSE;
293 }
294
295 /***********************************************************************
296  *              wglSetLayerPaletteEntries (OPENGL32.@)
297  */
298 int WINAPI wglSetLayerPaletteEntries(HDC hdc,
299                                      int iLayerPlane,
300                                      int iStart,
301                                      int cEntries,
302                                      const COLORREF *pcr) {
303   FIXME("(): stub !\n");
304
305   return 0;
306 }
307
308 /***********************************************************************
309  *              wglSwapLayerBuffers (OPENGL32.@)
310  */
311 BOOL WINAPI wglSwapLayerBuffers(HDC hdc,
312                                 UINT fuPlanes) {
313   TRACE_(opengl)("(%p, %08x)\n", hdc, fuPlanes);
314
315   if (fuPlanes & WGL_SWAP_MAIN_PLANE) {
316     if (!SwapBuffers(hdc)) return FALSE;
317     fuPlanes &= ~WGL_SWAP_MAIN_PLANE;
318   }
319
320   if (fuPlanes) {
321     WARN("Following layers unhandled : %08x\n", fuPlanes);
322   }
323
324   return TRUE;
325 }
326
327 #ifdef HAVE_GL_GLU_H
328
329 static void fixed_to_double(POINTFX fixed, UINT em_size, GLdouble vertex[3])
330 {
331     vertex[0] = (fixed.x.value + (GLdouble)fixed.x.fract / (1 << 16)) / em_size;  
332     vertex[1] = (fixed.y.value + (GLdouble)fixed.y.fract / (1 << 16)) / em_size;  
333     vertex[2] = 0.0;
334 }
335
336 static void tess_callback_vertex(GLvoid *vertex)
337 {
338     GLdouble *dbl = vertex;
339     TRACE("%f, %f, %f\n", dbl[0], dbl[1], dbl[2]);
340     glVertex3dv(vertex);
341 }
342
343 static void tess_callback_begin(GLenum which)
344 {
345     TRACE("%d\n", which);
346     glBegin(which);
347 }
348
349 static void tess_callback_end(void)
350 {
351     TRACE("\n");
352     glEnd();
353 }
354
355 /***********************************************************************
356  *              wglUseFontOutlines_common
357  */
358 BOOL WINAPI wglUseFontOutlines_common(HDC hdc,
359                                       DWORD first,
360                                       DWORD count,
361                                       DWORD listBase,
362                                       FLOAT deviation,
363                                       FLOAT extrusion,
364                                       int format,
365                                       LPGLYPHMETRICSFLOAT lpgmf,
366                                       BOOL unicode)
367 {
368     UINT glyph;
369     const MAT2 identity = {{0,1},{0,0},{0,0},{0,1}};
370     GLUtesselator *tess;
371     LOGFONTW lf;
372     HFONT old_font, unscaled_font;
373     UINT em_size = 1024;
374     RECT rc;
375
376     TRACE("(%p, %d, %d, %d, %f, %f, %d, %p, %s)\n", hdc, first, count,
377           listBase, deviation, extrusion, format, lpgmf, unicode ? "W" : "A");
378
379
380     ENTER_GL();
381     tess = gluNewTess();
382     if(tess)
383     {
384         gluTessCallback(tess, GLU_TESS_VERTEX, (_GLUfuncptr)tess_callback_vertex);
385         gluTessCallback(tess, GLU_TESS_BEGIN, (_GLUfuncptr)tess_callback_begin);
386         gluTessCallback(tess, GLU_TESS_END, tess_callback_end);
387     }
388     LEAVE_GL();
389
390     if(!tess) return FALSE;
391
392     GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), &lf);
393     rc.left = rc.right = rc.bottom = 0;
394     rc.top = em_size;
395     DPtoLP(hdc, (POINT*)&rc, 2);
396     lf.lfHeight = -abs(rc.top - rc.bottom);
397     lf.lfOrientation = lf.lfEscapement = 0;
398     unscaled_font = CreateFontIndirectW(&lf);
399     old_font = SelectObject(hdc, unscaled_font);
400
401     for (glyph = first; glyph < first + count; glyph++)
402     {
403         DWORD needed;
404         GLYPHMETRICS gm;
405         BYTE *buf;
406         TTPOLYGONHEADER *pph;
407         TTPOLYCURVE *ppc;
408         GLdouble *vertices;
409
410         if(unicode)
411             needed = GetGlyphOutlineW(hdc, glyph, GGO_NATIVE, &gm, 0, NULL, &identity);
412         else
413             needed = GetGlyphOutlineA(hdc, glyph, GGO_NATIVE, &gm, 0, NULL, &identity);
414
415         if(needed == GDI_ERROR)
416             goto error;
417
418         buf = HeapAlloc(GetProcessHeap(), 0, needed);
419         vertices = HeapAlloc(GetProcessHeap(), 0, needed / sizeof(POINTFX) * 3 * sizeof(GLdouble));
420
421         if(unicode)
422             GetGlyphOutlineW(hdc, glyph, GGO_NATIVE, &gm, needed, buf, &identity);
423         else
424             GetGlyphOutlineA(hdc, glyph, GGO_NATIVE, &gm, needed, buf, &identity);
425
426         TRACE("glyph %d\n", glyph);
427
428         if(lpgmf)
429         {
430             lpgmf->gmfBlackBoxX = (float)gm.gmBlackBoxX / em_size;
431             lpgmf->gmfBlackBoxY = (float)gm.gmBlackBoxY / em_size;
432             lpgmf->gmfptGlyphOrigin.x = (float)gm.gmptGlyphOrigin.x / em_size;
433             lpgmf->gmfptGlyphOrigin.y = (float)gm.gmptGlyphOrigin.y / em_size;
434             lpgmf->gmfCellIncX = (float)gm.gmCellIncX / em_size;
435             lpgmf->gmfCellIncY = (float)gm.gmCellIncY / em_size;
436
437             TRACE("%fx%f at %f,%f inc %f,%f\n", lpgmf->gmfBlackBoxX, lpgmf->gmfBlackBoxY,
438                   lpgmf->gmfptGlyphOrigin.x, lpgmf->gmfptGlyphOrigin.y, lpgmf->gmfCellIncX, lpgmf->gmfCellIncY); 
439             lpgmf++;
440         }
441
442         ENTER_GL();
443         glNewList(listBase++, GL_COMPILE);
444         gluTessBeginPolygon(tess, NULL);
445
446         pph = (TTPOLYGONHEADER*)buf;
447         while((BYTE*)pph < buf + needed)
448         {
449             TRACE("\tstart %d, %d\n", pph->pfxStart.x.value, pph->pfxStart.y.value);
450
451             gluTessBeginContour(tess);
452
453             fixed_to_double(pph->pfxStart, em_size, vertices);
454             gluTessVertex(tess, vertices, vertices);
455             vertices += 3;
456
457             ppc = (TTPOLYCURVE*)((char*)pph + sizeof(*pph));
458             while((char*)ppc < (char*)pph + pph->cb)
459             {
460                 int i;
461
462                 switch(ppc->wType) {
463                 case TT_PRIM_LINE:
464                     for(i = 0; i < ppc->cpfx; i++)
465                     {
466                         TRACE("\t\tline to %d, %d\n", ppc->apfx[i].x.value, ppc->apfx[i].y.value);
467                         fixed_to_double(ppc->apfx[i], em_size, vertices); 
468                         gluTessVertex(tess, vertices, vertices);
469                         vertices += 3;
470                     }
471                     break;
472
473                 case TT_PRIM_QSPLINE:
474                     for(i = 0; i < ppc->cpfx/2; i++)
475                     {
476                         /* FIXME just connecting the control points for now */
477                         TRACE("\t\tcurve  %d,%d %d,%d\n",
478                               ppc->apfx[i * 2].x.value,     ppc->apfx[i * 3].y.value,
479                               ppc->apfx[i * 2 + 1].x.value, ppc->apfx[i * 3 + 1].y.value);
480                         fixed_to_double(ppc->apfx[i * 2], em_size, vertices); 
481                         gluTessVertex(tess, vertices, vertices);
482                         vertices += 3;
483                         fixed_to_double(ppc->apfx[i * 2 + 1], em_size, vertices); 
484                         gluTessVertex(tess, vertices, vertices);
485                         vertices += 3;
486                     }
487                     break;
488                 default:
489                     ERR("\t\tcurve type = %d\n", ppc->wType);
490                     gluTessEndContour(tess);
491                     goto error_in_list;
492                 }
493
494                 ppc = (TTPOLYCURVE*)((char*)ppc + sizeof(*ppc) +
495                                      (ppc->cpfx - 1) * sizeof(POINTFX));
496             }
497             gluTessEndContour(tess);
498             pph = (TTPOLYGONHEADER*)((char*)pph + pph->cb);
499         }
500
501 error_in_list:
502         gluTessEndPolygon(tess);
503         glTranslated((GLdouble)gm.gmCellIncX / em_size, (GLdouble)gm.gmCellIncY / em_size, 0.0);
504         glEndList();
505         LEAVE_GL();
506         HeapFree(GetProcessHeap(), 0, buf);
507         HeapFree(GetProcessHeap(), 0, vertices);
508     }
509
510  error:
511     DeleteObject(SelectObject(hdc, old_font));
512     gluDeleteTess(tess);
513     return TRUE;
514
515 }
516
517 #else /* HAVE_GL_GLU_H */
518
519 BOOL WINAPI wglUseFontOutlines_common(HDC hdc,
520                                       DWORD first,
521                                       DWORD count,
522                                       DWORD listBase,
523                                       FLOAT deviation,
524                                       FLOAT extrusion,
525                                       int format,
526                                       LPGLYPHMETRICSFLOAT lpgmf,
527                                       BOOL unicode)
528 {
529     FIXME("Unable to compile in wglUseFontOutlines support without GL/glu.h\n");
530     return FALSE;
531 }
532
533 #endif /* HAVE_GL_GLU_H */
534
535 /***********************************************************************
536  *              wglUseFontOutlinesA (OPENGL32.@)
537  */
538 BOOL WINAPI wglUseFontOutlinesA(HDC hdc,
539                                 DWORD first,
540                                 DWORD count,
541                                 DWORD listBase,
542                                 FLOAT deviation,
543                                 FLOAT extrusion,
544                                 int format,
545                                 LPGLYPHMETRICSFLOAT lpgmf)
546 {
547     return wglUseFontOutlines_common(hdc, first, count, listBase, deviation, extrusion, format, lpgmf, FALSE);
548 }
549
550 /***********************************************************************
551  *              wglUseFontOutlinesW (OPENGL32.@)
552  */
553 BOOL WINAPI wglUseFontOutlinesW(HDC hdc,
554                                 DWORD first,
555                                 DWORD count,
556                                 DWORD listBase,
557                                 FLOAT deviation,
558                                 FLOAT extrusion,
559                                 int format,
560                                 LPGLYPHMETRICSFLOAT lpgmf)
561 {
562     return wglUseFontOutlines_common(hdc, first, count, listBase, deviation, extrusion, format, lpgmf, TRUE);
563 }
564
565 /***********************************************************************
566  *              glEnable (OPENGL32.@)
567  */
568 void WINAPI wine_glEnable( GLenum cap )
569 {
570     TRACE("(%d)\n", cap );
571     wine_wgl.p_wglEnable(cap);
572 }
573
574 /***********************************************************************
575  *              glIsEnabled (OPENGL32.@)
576  */
577 GLboolean WINAPI wine_glIsEnabled( GLenum cap )
578 {
579     TRACE("(%d)\n", cap );
580     return wine_wgl.p_wglIsEnabled(cap);
581 }
582
583 /***********************************************************************
584  *              glDisable (OPENGL32.@)
585  */
586 void WINAPI wine_glDisable( GLenum cap )
587 {
588     TRACE("(%d)\n", cap );
589     wine_wgl.p_wglDisable(cap);
590 }
591
592 /***********************************************************************
593  *              glScissor (OPENGL32.@)
594  */
595 void WINAPI wine_glScissor( GLint x, GLint y, GLsizei width, GLsizei height )
596 {
597     TRACE("(%d, %d, %d, %d)\n", x, y, width, height );
598     wine_wgl.p_wglScissor(x, y, width, height);
599 }
600
601 /***********************************************************************
602  *              glViewport (OPENGL32.@)
603  */
604 void WINAPI wine_glViewport( GLint x, GLint y, GLsizei width, GLsizei height )
605 {
606     TRACE("(%d, %d, %d, %d)\n", x, y, width, height );
607     wine_wgl.p_wglViewport(x, y, width, height);
608 }
609
610 /***********************************************************************
611  *              glGetString (OPENGL32.@)
612  */
613 const GLubyte * WINAPI wine_glGetString( GLenum name )
614 {
615   const GLubyte *ret;
616   const char* GL_Extensions = NULL;
617
618   if (GL_EXTENSIONS != name) {
619     ENTER_GL();
620     ret = glGetString(name);
621     LEAVE_GL();
622     return ret;
623   }
624
625   if (NULL == internal_gl_extensions) {
626     ENTER_GL();
627     GL_Extensions = (const char *) glGetString(GL_EXTENSIONS);
628
629     if (GL_Extensions)
630     {
631       size_t len = strlen(GL_Extensions);
632       internal_gl_extensions = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len + 2);
633
634       TRACE("GL_EXTENSIONS reported:\n");
635       while (*GL_Extensions != 0x00) {
636         const char* Start = GL_Extensions;
637         char        ThisExtn[256];
638
639         while (*GL_Extensions != ' ' && *GL_Extensions != 0x00) {
640           GL_Extensions++;
641         }
642         memcpy(ThisExtn, Start, (GL_Extensions - Start));
643         ThisExtn[GL_Extensions - Start] = 0;
644         TRACE("- %s:", ThisExtn);
645         
646         /* test if supported API is disabled by config */
647         if (NULL == strstr(internal_gl_disabled_extensions, ThisExtn)) {
648           strcat(internal_gl_extensions, " ");
649           strcat(internal_gl_extensions, ThisExtn);
650           TRACE(" active\n");
651         } else {
652           TRACE(" deactived (by config)\n");
653         }
654
655         if (*GL_Extensions == ' ') GL_Extensions++;
656       }
657     }
658     LEAVE_GL();
659   }
660   return (const GLubyte *) internal_gl_extensions;
661 }
662
663 /***********************************************************************
664  *              glGetIntegerv (OPENGL32.@)
665  */
666 void WINAPI wine_glGetIntegerv( GLenum pname, GLint* params )
667 {
668     wine_wgl.p_wglGetIntegerv(pname, params);
669 }
670
671
672 /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient and
673    include all dependencies
674 */
675 #ifndef SONAME_LIBGL
676 #define SONAME_LIBGL "libGL.so"
677 #endif
678
679 /* This is for brain-dead applications that use OpenGL functions before even
680    creating a rendering context.... */
681 static BOOL process_attach(void)
682 {
683   HMODULE mod_x11, mod_gdi32;
684   DWORD size = sizeof(internal_gl_disabled_extensions);
685   HKEY hkey = 0;
686
687   GetDesktopWindow();  /* make sure winex11 is loaded (FIXME) */
688   mod_x11 = GetModuleHandleA( "winex11.drv" );
689   mod_gdi32 = GetModuleHandleA( "gdi32.dll" );
690
691   if (!mod_x11 || !mod_gdi32)
692   {
693       ERR("X11DRV or GDI32 not loaded. Cannot create default context.\n");
694       return FALSE;
695   }
696
697   wine_tsx11_lock_ptr   = (void *)GetProcAddress( mod_x11, "wine_tsx11_lock" );
698   wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod_x11, "wine_tsx11_unlock" );
699
700   wine_wgl.p_wglGetProcAddress = (void *)GetProcAddress(mod_gdi32, "wglGetProcAddress");
701
702   /* Interal WGL function */
703   wine_wgl.p_wglDisable = (void *)wine_wgl.p_wglGetProcAddress("wglDisable");
704   wine_wgl.p_wglEnable = (void *)wine_wgl.p_wglGetProcAddress("wglEnable");
705   wine_wgl.p_wglGetIntegerv = (void *)wine_wgl.p_wglGetProcAddress("wglGetIntegerv");
706   wine_wgl.p_wglIsEnabled = (void *)wine_wgl.p_wglGetProcAddress("wglIsEnabled");
707   wine_wgl.p_wglScissor = (void *)wine_wgl.p_wglGetProcAddress("wglScissor");
708   wine_wgl.p_wglViewport = (void *)wine_wgl.p_wglGetProcAddress("wglViewport");
709
710   internal_gl_disabled_extensions[0] = 0;
711   if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\OpenGL", &hkey)) {
712     if (!RegQueryValueExA( hkey, "DisabledExtensions", 0, NULL, (LPBYTE)internal_gl_disabled_extensions, &size)) {
713       TRACE("found DisabledExtensions=\"%s\"\n", internal_gl_disabled_extensions);
714     }
715     RegCloseKey(hkey);
716   }
717
718   return TRUE;
719 }
720
721
722 /**********************************************************************/
723
724 static void process_detach(void)
725 {
726   HeapFree(GetProcessHeap(), 0, internal_gl_extensions);
727 }
728
729 /***********************************************************************
730  *           OpenGL initialisation routine
731  */
732 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
733 {
734     switch(reason)
735     {
736     case DLL_PROCESS_ATTACH:
737         opengl32_handle = hinst;
738         DisableThreadLibraryCalls(hinst);
739         return process_attach();
740     case DLL_PROCESS_DETACH:
741         process_detach();
742         break;
743     }
744     return TRUE;
745 }