1 /* Window-specific OpenGL functions implementation.
3 * Copyright (c) 1999 Lionel Ulmer
4 * Copyright (c) 2005 Raphael Junqueira
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.
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.
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
22 #include "wine/port.h"
36 #include "opengl_ext.h"
42 #define WGL_WGLEXT_PROTOTYPES
43 #include "wine/wglext.h"
44 #include "wine/gdi_driver.h"
45 #include "wine/wgl_driver.h"
46 #include "wine/library.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
50 WINE_DECLARE_DEBUG_CHANNEL(opengl);
53 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
54 MAKE_FUNCPTR(gluNewTess)
55 MAKE_FUNCPTR(gluDeleteTess)
56 MAKE_FUNCPTR(gluTessBeginContour)
57 MAKE_FUNCPTR(gluTessBeginPolygon)
58 MAKE_FUNCPTR(gluTessCallback)
59 MAKE_FUNCPTR(gluTessEndContour)
60 MAKE_FUNCPTR(gluTessEndPolygon)
61 MAKE_FUNCPTR(gluTessVertex)
63 #endif /* SONAME_LIBGLU */
65 static HMODULE opengl32_handle;
66 static void* libglu_handle = NULL;
68 extern struct opengl_funcs null_opengl_funcs;
70 const GLubyte * WINAPI wine_glGetString( GLenum name );
72 /* internal GDI functions */
73 extern INT WINAPI GdiDescribePixelFormat( HDC hdc, INT fmt, UINT size, PIXELFORMATDESCRIPTOR *pfd );
74 extern BOOL WINAPI GdiSetPixelFormat( HDC hdc, INT fmt, const PIXELFORMATDESCRIPTOR *pfd );
75 extern BOOL WINAPI GdiSwapBuffers( HDC hdc );
77 /* handle management */
79 #define MAX_WGL_HANDLES 1024
83 HANDLE_CONTEXT = 0 << 12,
84 HANDLE_PBUFFER = 1 << 12,
85 HANDLE_TYPE_MASK = 15 << 12
92 struct opengl_funcs *funcs;
95 struct wgl_context *context; /* for HANDLE_CONTEXT */
96 struct wgl_pbuffer *pbuffer; /* for HANDLE_PBUFFER */
97 struct wgl_handle *next; /* for free handles */
101 static struct wgl_handle wgl_handles[MAX_WGL_HANDLES];
102 static struct wgl_handle *next_free;
103 static unsigned int handle_count;
105 static CRITICAL_SECTION wgl_section;
106 static CRITICAL_SECTION_DEBUG critsect_debug =
109 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
110 0, 0, { (DWORD_PTR)(__FILE__ ": wgl_section") }
112 static CRITICAL_SECTION wgl_section = { &critsect_debug, -1, 0, 0, 0, 0 };
114 static inline struct opengl_funcs *get_dc_funcs( HDC hdc )
116 struct opengl_funcs *funcs = __wine_get_wgl_driver( hdc, WINE_WGL_DRIVER_VERSION );
117 if (funcs == (void *)-1) funcs = &null_opengl_funcs;
121 static inline HANDLE next_handle( struct wgl_handle *ptr, enum wgl_handle_type type )
123 WORD generation = HIWORD( ptr->handle ) + 1;
124 if (!generation) generation++;
125 ptr->handle = MAKELONG( ptr - wgl_handles, generation ) | type;
126 return ULongToHandle( ptr->handle );
129 /* the current context is assumed valid and doesn't need locking */
130 static inline struct wgl_handle *get_current_context_ptr(void)
132 if (!NtCurrentTeb()->glCurrentRC) return NULL;
133 return &wgl_handles[LOWORD(NtCurrentTeb()->glCurrentRC) & ~HANDLE_TYPE_MASK];
136 static struct wgl_handle *get_handle_ptr( HANDLE handle, enum wgl_handle_type type )
138 unsigned int index = LOWORD( handle ) & ~HANDLE_TYPE_MASK;
140 EnterCriticalSection( &wgl_section );
141 if (index < handle_count && ULongToHandle(wgl_handles[index].handle) == handle)
142 return &wgl_handles[index];
144 LeaveCriticalSection( &wgl_section );
145 SetLastError( ERROR_INVALID_HANDLE );
149 static void release_handle_ptr( struct wgl_handle *ptr )
151 if (ptr) LeaveCriticalSection( &wgl_section );
154 static HANDLE alloc_handle( enum wgl_handle_type type, struct opengl_funcs *funcs, void *user_ptr )
157 struct wgl_handle *ptr = NULL;
159 EnterCriticalSection( &wgl_section );
160 if ((ptr = next_free))
161 next_free = next_free->u.next;
162 else if (handle_count < MAX_WGL_HANDLES)
163 ptr = &wgl_handles[handle_count++];
168 ptr->u.context = user_ptr;
169 handle = next_handle( ptr, type );
171 else SetLastError( ERROR_NOT_ENOUGH_MEMORY );
172 LeaveCriticalSection( &wgl_section );
176 static void free_handle_ptr( struct wgl_handle *ptr )
178 ptr->handle |= 0xffff;
179 ptr->u.next = next_free;
182 LeaveCriticalSection( &wgl_section );
185 /***********************************************************************
186 * wglSetPixelFormat(OPENGL32.@)
188 BOOL WINAPI wglSetPixelFormat( HDC hdc, INT iPixelFormat,
189 const PIXELFORMATDESCRIPTOR *ppfd)
191 return GdiSetPixelFormat(hdc, iPixelFormat, ppfd);
194 /***********************************************************************
195 * wglCopyContext (OPENGL32.@)
197 BOOL WINAPI wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
199 struct wgl_handle *src, *dst;
202 if (!(src = get_handle_ptr( hglrcSrc, HANDLE_CONTEXT ))) return FALSE;
203 if ((dst = get_handle_ptr( hglrcDst, HANDLE_CONTEXT )))
205 if (src->funcs != dst->funcs) SetLastError( ERROR_INVALID_HANDLE );
206 else ret = src->funcs->wgl.p_wglCopyContext( src->u.context, dst->u.context, mask );
208 release_handle_ptr( dst );
209 release_handle_ptr( src );
213 /***********************************************************************
214 * wglDeleteContext (OPENGL32.@)
216 BOOL WINAPI wglDeleteContext(HGLRC hglrc)
218 struct wgl_handle *ptr = get_handle_ptr( hglrc, HANDLE_CONTEXT );
220 if (!ptr) return FALSE;
222 if (ptr->tid && ptr->tid != GetCurrentThreadId())
224 SetLastError( ERROR_BUSY );
225 release_handle_ptr( ptr );
228 if (hglrc == NtCurrentTeb()->glCurrentRC) wglMakeCurrent( 0, 0 );
229 ptr->funcs->wgl.p_wglDeleteContext( ptr->u.context );
230 free_handle_ptr( ptr );
234 /***********************************************************************
235 * wglMakeCurrent (OPENGL32.@)
237 BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
240 struct wgl_handle *ptr, *prev = get_current_context_ptr();
244 if (!(ptr = get_handle_ptr( hglrc, HANDLE_CONTEXT ))) return FALSE;
245 if (!ptr->tid || ptr->tid == GetCurrentThreadId())
247 ret = ptr->funcs->wgl.p_wglMakeCurrent( hdc, ptr->u.context );
250 if (prev) prev->tid = 0;
251 ptr->tid = GetCurrentThreadId();
252 NtCurrentTeb()->glCurrentRC = hglrc;
253 NtCurrentTeb()->glTable = ptr->funcs;
258 SetLastError( ERROR_BUSY );
261 release_handle_ptr( ptr );
265 if (!prev->funcs->wgl.p_wglMakeCurrent( 0, NULL )) return FALSE;
267 NtCurrentTeb()->glCurrentRC = 0;
268 NtCurrentTeb()->glTable = &null_opengl_funcs;
272 SetLastError( ERROR_INVALID_HANDLE );
278 /***********************************************************************
279 * wglCreateContextAttribsARB
281 * Provided by the WGL_ARB_create_context extension.
283 HGLRC WINAPI wglCreateContextAttribsARB( HDC hdc, HGLRC share, const int *attribs )
286 struct wgl_context *context;
287 struct wgl_handle *share_ptr = NULL;
288 struct opengl_funcs *funcs = get_dc_funcs( hdc );
290 if (!funcs || !funcs->ext.p_wglCreateContextAttribsARB) return 0;
291 if (share && !(share_ptr = get_handle_ptr( share, HANDLE_CONTEXT ))) return 0;
292 if ((context = funcs->ext.p_wglCreateContextAttribsARB( hdc, share_ptr ? share_ptr->u.context : NULL,
295 ret = alloc_handle( HANDLE_CONTEXT, funcs, context );
296 if (!ret) funcs->wgl.p_wglDeleteContext( context );
298 release_handle_ptr( share_ptr );
303 /***********************************************************************
304 * wglMakeContextCurrentARB
306 * Provided by the WGL_ARB_make_current_read extension.
308 BOOL WINAPI wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, HGLRC hglrc )
311 struct wgl_handle *ptr, *prev = get_current_context_ptr();
315 if (!(ptr = get_handle_ptr( hglrc, HANDLE_CONTEXT ))) return FALSE;
316 if (!ptr->tid || ptr->tid == GetCurrentThreadId())
318 ret = (ptr->funcs->ext.p_wglMakeContextCurrentARB &&
319 ptr->funcs->ext.p_wglMakeContextCurrentARB( draw_hdc, read_hdc, ptr->u.context ));
322 if (prev) prev->tid = 0;
323 ptr->tid = GetCurrentThreadId();
324 NtCurrentTeb()->glCurrentRC = hglrc;
325 NtCurrentTeb()->glTable = ptr->funcs;
330 SetLastError( ERROR_BUSY );
333 release_handle_ptr( ptr );
337 if (!prev->funcs->wgl.p_wglMakeCurrent( 0, NULL )) return FALSE;
339 NtCurrentTeb()->glCurrentRC = 0;
340 NtCurrentTeb()->glTable = &null_opengl_funcs;
345 /***********************************************************************
346 * wglGetCurrentReadDCARB
348 * Provided by the WGL_ARB_make_current_read extension.
350 HDC WINAPI wglGetCurrentReadDCARB(void)
352 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
354 if (!funcs->ext.p_wglGetCurrentReadDCARB) return 0;
355 return funcs->ext.p_wglGetCurrentReadDCARB();
358 /***********************************************************************
359 * wglShareLists (OPENGL32.@)
361 BOOL WINAPI wglShareLists(HGLRC hglrcSrc, HGLRC hglrcDst)
364 struct wgl_handle *src, *dst;
366 if (!(src = get_handle_ptr( hglrcSrc, HANDLE_CONTEXT ))) return FALSE;
367 if ((dst = get_handle_ptr( hglrcDst, HANDLE_CONTEXT )))
369 if (src->funcs != dst->funcs) SetLastError( ERROR_INVALID_HANDLE );
370 else ret = src->funcs->wgl.p_wglShareLists( src->u.context, dst->u.context );
372 release_handle_ptr( dst );
373 release_handle_ptr( src );
377 /***********************************************************************
378 * wglGetCurrentDC (OPENGL32.@)
380 HDC WINAPI wglGetCurrentDC(void)
382 struct wgl_handle *context = get_current_context_ptr();
383 if (!context) return 0;
384 return context->funcs->wgl.p_wglGetCurrentDC( context->u.context );
387 /***********************************************************************
388 * wglCreateContext (OPENGL32.@)
390 HGLRC WINAPI wglCreateContext(HDC hdc)
393 struct wgl_context *context;
394 struct opengl_funcs *funcs = get_dc_funcs( hdc );
396 if (!funcs) return 0;
397 if (!(context = funcs->wgl.p_wglCreateContext( hdc ))) return 0;
398 ret = alloc_handle( HANDLE_CONTEXT, funcs, context );
399 if (!ret) funcs->wgl.p_wglDeleteContext( context );
403 /***********************************************************************
404 * wglGetCurrentContext (OPENGL32.@)
406 HGLRC WINAPI wglGetCurrentContext(void)
408 return NtCurrentTeb()->glCurrentRC;
411 /***********************************************************************
412 * wglChoosePixelFormat (OPENGL32.@)
414 INT WINAPI wglChoosePixelFormat(HDC hdc, const PIXELFORMATDESCRIPTOR* ppfd)
416 PIXELFORMATDESCRIPTOR format, best;
417 int i, count, best_format;
418 int bestDBuffer = -1, bestStereo = -1;
420 TRACE_(wgl)( "%p %p: size %u version %u flags %u type %u color %u %u,%u,%u,%u "
421 "accum %u depth %u stencil %u aux %u\n",
422 hdc, ppfd, ppfd->nSize, ppfd->nVersion, ppfd->dwFlags, ppfd->iPixelType,
423 ppfd->cColorBits, ppfd->cRedBits, ppfd->cGreenBits, ppfd->cBlueBits, ppfd->cAlphaBits,
424 ppfd->cAccumBits, ppfd->cDepthBits, ppfd->cStencilBits, ppfd->cAuxBuffers );
426 count = GdiDescribePixelFormat( hdc, 0, 0, NULL );
427 if (!count) return 0;
431 best.cAlphaBits = -1;
432 best.cColorBits = -1;
433 best.cDepthBits = -1;
434 best.cStencilBits = -1;
435 best.cAuxBuffers = -1;
437 for (i = 1; i <= count; i++)
439 if (!GdiDescribePixelFormat( hdc, i, sizeof(format), &format )) continue;
441 if (ppfd->iPixelType != format.iPixelType)
443 TRACE( "pixel type mismatch for iPixelFormat=%d\n", i );
447 /* only use bitmap capable for formats for bitmap rendering */
448 if( (ppfd->dwFlags & PFD_DRAW_TO_BITMAP) != (format.dwFlags & PFD_DRAW_TO_BITMAP))
450 TRACE( "PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i );
454 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
455 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
456 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
457 * formats without the given flag set.
458 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
459 * has indicated that a format without stereo is returned when stereo is unavailable.
460 * So in case PFD_STEREO is set, formats that support it should have priority above formats
461 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
463 * To summarize the following is most likely the correct behavior:
464 * stereo not set -> prefer non-stereo formats, but also accept stereo formats
465 * stereo set -> prefer stereo formats, but also accept non-stereo formats
466 * stereo don't care -> it doesn't matter whether we get stereo or not
468 * In Wine we will treat non-stereo the same way as don't care because it makes
469 * format selection even more complicated and second drivers with Stereo advertise
470 * each format twice anyway.
473 /* Doublebuffer, see the comments above */
474 if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE))
476 if (((ppfd->dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) &&
477 ((format.dwFlags & PFD_DOUBLEBUFFER) == (ppfd->dwFlags & PFD_DOUBLEBUFFER)))
480 if (bestDBuffer != -1 && (format.dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) continue;
483 /* Stereo, see the comments above. */
484 if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE))
486 if (((ppfd->dwFlags & PFD_STEREO) != bestStereo) &&
487 ((format.dwFlags & PFD_STEREO) == (ppfd->dwFlags & PFD_STEREO)))
490 if (bestStereo != -1 && (format.dwFlags & PFD_STEREO) != bestStereo) continue;
493 /* Below we will do a number of checks to select the 'best' pixelformat.
494 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
495 * The code works by trying to match the most important options as close as possible.
496 * When a reasonable format is found, we will try to match more options.
497 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
498 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
499 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
501 if (ppfd->cColorBits)
503 if (((ppfd->cColorBits > best.cColorBits) && (format.cColorBits > best.cColorBits)) ||
504 ((format.cColorBits >= ppfd->cColorBits) && (format.cColorBits < best.cColorBits)))
507 if (best.cColorBits != format.cColorBits) /* Do further checks if the format is compatible */
509 TRACE( "color mismatch for iPixelFormat=%d\n", i );
513 if (ppfd->cAlphaBits)
515 if (((ppfd->cAlphaBits > best.cAlphaBits) && (format.cAlphaBits > best.cAlphaBits)) ||
516 ((format.cAlphaBits >= ppfd->cAlphaBits) && (format.cAlphaBits < best.cAlphaBits)))
519 if (best.cAlphaBits != format.cAlphaBits)
521 TRACE( "alpha mismatch for iPixelFormat=%d\n", i );
525 if (ppfd->cDepthBits)
527 if (((ppfd->cDepthBits > best.cDepthBits) && (format.cDepthBits > best.cDepthBits)) ||
528 ((format.cDepthBits >= ppfd->cDepthBits) && (format.cDepthBits < best.cDepthBits)))
531 if (best.cDepthBits != format.cDepthBits)
533 TRACE( "depth mismatch for iPixelFormat=%d\n", i );
537 if (ppfd->cStencilBits)
539 if (((ppfd->cStencilBits > best.cStencilBits) && (format.cStencilBits > best.cStencilBits)) ||
540 ((format.cStencilBits >= ppfd->cStencilBits) && (format.cStencilBits < best.cStencilBits)))
543 if (best.cStencilBits != format.cStencilBits)
545 TRACE( "stencil mismatch for iPixelFormat=%d\n", i );
549 if (ppfd->cAuxBuffers)
551 if (((ppfd->cAuxBuffers > best.cAuxBuffers) && (format.cAuxBuffers > best.cAuxBuffers)) ||
552 ((format.cAuxBuffers >= ppfd->cAuxBuffers) && (format.cAuxBuffers < best.cAuxBuffers)))
555 if (best.cAuxBuffers != format.cAuxBuffers)
557 TRACE( "aux mismatch for iPixelFormat=%d\n", i );
566 bestDBuffer = format.dwFlags & PFD_DOUBLEBUFFER;
567 bestStereo = format.dwFlags & PFD_STEREO;
570 TRACE( "returning %u\n", best_format );
574 /***********************************************************************
575 * wglDescribePixelFormat (OPENGL32.@)
577 INT WINAPI wglDescribePixelFormat(HDC hdc, INT iPixelFormat, UINT nBytes,
578 LPPIXELFORMATDESCRIPTOR ppfd)
580 return GdiDescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd);
583 /***********************************************************************
584 * wglGetPixelFormat (OPENGL32.@)
586 INT WINAPI wglGetPixelFormat(HDC hdc)
588 struct opengl_funcs *funcs = get_dc_funcs( hdc );
589 if (!funcs) return 0;
590 return funcs->wgl.p_wglGetPixelFormat( hdc );
593 /***********************************************************************
594 * wglCreateLayerContext (OPENGL32.@)
596 HGLRC WINAPI wglCreateLayerContext(HDC hdc,
598 TRACE("(%p,%d)\n", hdc, iLayerPlane);
600 if (iLayerPlane == 0) {
601 return wglCreateContext(hdc);
603 FIXME("no handler for layer %d\n", iLayerPlane);
608 /***********************************************************************
609 * wglDescribeLayerPlane (OPENGL32.@)
611 BOOL WINAPI wglDescribeLayerPlane(HDC hdc,
615 LPLAYERPLANEDESCRIPTOR plpd) {
616 FIXME("(%p,%d,%d,%d,%p)\n", hdc, iPixelFormat, iLayerPlane, nBytes, plpd);
621 /***********************************************************************
622 * wglGetLayerPaletteEntries (OPENGL32.@)
624 int WINAPI wglGetLayerPaletteEntries(HDC hdc,
628 const COLORREF *pcr) {
629 FIXME("(): stub!\n");
634 /* check if the extension is present in the list */
635 static BOOL has_extension( const char *list, const char *ext )
637 size_t len = strlen( ext );
641 while (*list == ' ') list++;
642 if (!strncmp( list, ext, len ) && (!list[len] || list[len] == ' ')) return TRUE;
643 list = strchr( list, ' ' );
648 static int compar(const void *elt_a, const void *elt_b) {
649 return strcmp(((const OpenGL_extension *) elt_a)->name,
650 ((const OpenGL_extension *) elt_b)->name);
653 /* Check if a GL extension is supported */
654 static BOOL is_extension_supported(const char* extension)
656 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
657 const char *gl_ext_string = (const char*)wine_glGetString(GL_EXTENSIONS);
659 TRACE("Checking for extension '%s'\n", extension);
662 ERR("No OpenGL extensions found, check if your OpenGL setup is correct!\n");
666 /* We use the GetProcAddress function from the display driver to retrieve function pointers
667 * for OpenGL and WGL extensions. In case of winex11.drv the OpenGL extension lookup is done
668 * using glXGetProcAddress. This function is quite unreliable in the sense that its specs don't
669 * require the function to return NULL when an extension isn't found. For this reason we check
670 * if the OpenGL extension required for the function we are looking up is supported. */
672 /* Check if the extension is part of the GL extension string to see if it is supported. */
673 if (has_extension(gl_ext_string, extension))
676 /* In general an OpenGL function starts as an ARB/EXT extension and at some stage
677 * it becomes part of the core OpenGL library and can be reached without the ARB/EXT
678 * suffix as well. In the extension table, these functions contain GL_VERSION_major_minor.
679 * Check if we are searching for a core GL function */
680 if(strncmp(extension, "GL_VERSION_", 11) == 0)
682 const GLubyte *gl_version = funcs->gl.p_glGetString(GL_VERSION);
683 const char *version = extension + 11; /* Move past 'GL_VERSION_' */
686 ERR("No OpenGL version found!\n");
690 /* Compare the major/minor version numbers of the native OpenGL library and what is required by the function.
691 * The gl_version string is guaranteed to have at least a major/minor and sometimes it has a release number as well. */
692 if( (gl_version[0] >= version[0]) || ((gl_version[0] == version[0]) && (gl_version[2] >= version[2])) ) {
695 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]);
701 /***********************************************************************
702 * wglGetProcAddress (OPENGL32.@)
704 PROC WINAPI wglGetProcAddress(LPCSTR lpszProc)
706 struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
709 OpenGL_extension ext;
710 const OpenGL_extension *ext_ret;
711 struct wgl_handle *context = get_current_context_ptr();
713 TRACE("(%s)\n", lpszProc);
715 if (lpszProc == NULL)
718 /* Without an active context opengl32 doesn't know to what
719 * driver it has to dispatch wglGetProcAddress.
723 WARN("No active WGL context found\n");
727 /* Search in the thunks to find the real name of the extension */
729 ext_ret = bsearch(&ext, extension_registry, extension_registry_size,
730 sizeof(OpenGL_extension), compar);
733 WARN("Extension '%s' not defined in opengl32.dll's function table!\n", lpszProc);
737 func_ptr = (void **)&funcs->ext + (ext_ret - extension_registry);
740 /* Check if the GL extension required by the function is available */
741 if(!is_extension_supported(ext_ret->extension)) {
742 WARN("Extension '%s' required by function '%s' not supported!\n", ext_ret->extension, lpszProc);
745 local_func = context->funcs->wgl.p_wglGetProcAddress( ext_ret->name );
747 /* After that, look at the extensions defined in the Linux OpenGL library */
748 if (local_func == NULL) {
752 /* Remove the last 3 letters (EXT, ARB, ...).
754 I know that some extensions have more than 3 letters (MESA, NV,
755 INTEL, ...), but this is only a stop-gap measure to fix buggy
756 OpenGL drivers (moreover, it is only useful for old 1.0 apps
757 that query the glBindTextureEXT extension).
759 memcpy(buf, ext_ret->name, strlen(ext_ret->name) - 3);
760 buf[strlen(ext_ret->name) - 3] = '\0';
761 TRACE("Extension not found in the Linux OpenGL library, checking against libGL bug with %s..\n", buf);
763 ret = GetProcAddress(opengl32_handle, buf);
765 TRACE("Found function in main OpenGL library (%p)!\n", ret);
767 WARN("Did not find function %s (%s) in your OpenGL library!\n", lpszProc, ext_ret->name);
772 *func_ptr = local_func;
775 TRACE("returning function (%p)\n", ext_ret->func);
776 return ext_ret->func;
779 /***********************************************************************
780 * wglRealizeLayerPalette (OPENGL32.@)
782 BOOL WINAPI wglRealizeLayerPalette(HDC hdc,
790 /***********************************************************************
791 * wglSetLayerPaletteEntries (OPENGL32.@)
793 int WINAPI wglSetLayerPaletteEntries(HDC hdc,
797 const COLORREF *pcr) {
798 FIXME("(): stub!\n");
803 /***********************************************************************
804 * wglSwapLayerBuffers (OPENGL32.@)
806 BOOL WINAPI wglSwapLayerBuffers(HDC hdc,
808 TRACE_(opengl)("(%p, %08x)\n", hdc, fuPlanes);
810 if (fuPlanes & WGL_SWAP_MAIN_PLANE) {
811 if (!GdiSwapBuffers(hdc)) return FALSE;
812 fuPlanes &= ~WGL_SWAP_MAIN_PLANE;
816 WARN("Following layers unhandled: %08x\n", fuPlanes);
822 /***********************************************************************
823 * wglAllocateMemoryNV
825 * Provided by the WGL_NV_vertex_array_range extension.
827 void * WINAPI wglAllocateMemoryNV( GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority )
829 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
831 if (!funcs->ext.p_wglAllocateMemoryNV) return NULL;
832 return funcs->ext.p_wglAllocateMemoryNV( size, readfreq, writefreq, priority );
835 /***********************************************************************
838 * Provided by the WGL_NV_vertex_array_range extension.
840 void WINAPI wglFreeMemoryNV( void *pointer )
842 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
844 if (funcs->ext.p_wglFreeMemoryNV) funcs->ext.p_wglFreeMemoryNV( pointer );
847 /***********************************************************************
850 * Provided by the WGL_ARB_render_texture extension.
852 BOOL WINAPI wglBindTexImageARB( HPBUFFERARB handle, int buffer )
854 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
857 if (!ptr) return FALSE;
858 ret = ptr->funcs->ext.p_wglBindTexImageARB( ptr->u.pbuffer, buffer );
859 release_handle_ptr( ptr );
863 /***********************************************************************
864 * wglReleaseTexImageARB
866 * Provided by the WGL_ARB_render_texture extension.
868 BOOL WINAPI wglReleaseTexImageARB( HPBUFFERARB handle, int buffer )
870 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
873 if (!ptr) return FALSE;
874 ret = ptr->funcs->ext.p_wglReleaseTexImageARB( ptr->u.pbuffer, buffer );
875 release_handle_ptr( ptr );
879 /***********************************************************************
880 * wglSetPbufferAttribARB
882 * Provided by the WGL_ARB_render_texture extension.
884 BOOL WINAPI wglSetPbufferAttribARB( HPBUFFERARB handle, const int *attribs )
886 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
889 if (!ptr) return FALSE;
890 ret = ptr->funcs->ext.p_wglSetPbufferAttribARB( ptr->u.pbuffer, attribs );
891 release_handle_ptr( ptr );
895 /***********************************************************************
896 * wglChoosePixelFormatARB
898 * Provided by the WGL_ARB_pixel_format extension.
900 BOOL WINAPI wglChoosePixelFormatARB( HDC hdc, const int *iattribs, const FLOAT *fattribs,
901 UINT max, int *formats, UINT *count )
903 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
905 if (!funcs || !funcs->ext.p_wglChoosePixelFormatARB) return FALSE;
906 return funcs->ext.p_wglChoosePixelFormatARB( hdc, iattribs, fattribs, max, formats, count );
909 /***********************************************************************
910 * wglGetPixelFormatAttribivARB
912 * Provided by the WGL_ARB_pixel_format extension.
914 BOOL WINAPI wglGetPixelFormatAttribivARB( HDC hdc, int format, int layer, UINT count, const int *attribs,
917 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
919 if (!funcs || !funcs->ext.p_wglGetPixelFormatAttribivARB) return FALSE;
920 return funcs->ext.p_wglGetPixelFormatAttribivARB( hdc, format, layer, count, attribs, values );
923 /***********************************************************************
924 * wglGetPixelFormatAttribfvARB
926 * Provided by the WGL_ARB_pixel_format extension.
928 BOOL WINAPI wglGetPixelFormatAttribfvARB( HDC hdc, int format, int layer, UINT count, const int *attribs,
931 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
933 if (!funcs || !funcs->ext.p_wglGetPixelFormatAttribfvARB) return FALSE;
934 return funcs->ext.p_wglGetPixelFormatAttribfvARB( hdc, format, layer, count, attribs, values );
937 /***********************************************************************
938 * wglCreatePbufferARB
940 * Provided by the WGL_ARB_pbuffer extension.
942 HPBUFFERARB WINAPI wglCreatePbufferARB( HDC hdc, int format, int width, int height, const int *attribs )
945 struct wgl_pbuffer *pbuffer;
946 struct opengl_funcs *funcs = get_dc_funcs( hdc );
948 if (!funcs || !funcs->ext.p_wglCreatePbufferARB) return 0;
949 if (!(pbuffer = funcs->ext.p_wglCreatePbufferARB( hdc, format, width, height, attribs ))) return 0;
950 ret = alloc_handle( HANDLE_PBUFFER, funcs, pbuffer );
951 if (!ret) funcs->ext.p_wglDestroyPbufferARB( pbuffer );
955 /***********************************************************************
958 * Provided by the WGL_ARB_pbuffer extension.
960 HDC WINAPI wglGetPbufferDCARB( HPBUFFERARB handle )
962 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
966 ret = ptr->funcs->ext.p_wglGetPbufferDCARB( ptr->u.pbuffer );
967 release_handle_ptr( ptr );
971 /***********************************************************************
972 * wglReleasePbufferDCARB
974 * Provided by the WGL_ARB_pbuffer extension.
976 int WINAPI wglReleasePbufferDCARB( HPBUFFERARB handle, HDC hdc )
978 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
981 if (!ptr) return FALSE;
982 ret = ptr->funcs->ext.p_wglReleasePbufferDCARB( ptr->u.pbuffer, hdc );
983 release_handle_ptr( ptr );
987 /***********************************************************************
988 * wglDestroyPbufferARB
990 * Provided by the WGL_ARB_pbuffer extension.
992 BOOL WINAPI wglDestroyPbufferARB( HPBUFFERARB handle )
994 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
996 if (!ptr) return FALSE;
997 ptr->funcs->ext.p_wglDestroyPbufferARB( ptr->u.pbuffer );
998 free_handle_ptr( ptr );
1002 /***********************************************************************
1003 * wglQueryPbufferARB
1005 * Provided by the WGL_ARB_pbuffer extension.
1007 BOOL WINAPI wglQueryPbufferARB( HPBUFFERARB handle, int attrib, int *value )
1009 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
1012 if (!ptr) return FALSE;
1013 ret = ptr->funcs->ext.p_wglQueryPbufferARB( ptr->u.pbuffer, attrib, value );
1014 release_handle_ptr( ptr );
1018 /***********************************************************************
1019 * wglGetExtensionsStringARB
1021 * Provided by the WGL_ARB_extensions_string extension.
1023 const char * WINAPI wglGetExtensionsStringARB( HDC hdc )
1025 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
1027 if (!funcs || !funcs->ext.p_wglGetExtensionsStringARB) return NULL;
1028 return (const char *)funcs->ext.p_wglGetExtensionsStringARB( hdc );
1031 /***********************************************************************
1032 * wglGetExtensionsStringEXT
1034 * Provided by the WGL_EXT_extensions_string extension.
1036 const char * WINAPI wglGetExtensionsStringEXT(void)
1038 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1040 if (!funcs->ext.p_wglGetExtensionsStringEXT) return NULL;
1041 return (const char *)funcs->ext.p_wglGetExtensionsStringEXT();
1044 /***********************************************************************
1045 * wglSwapIntervalEXT
1047 * Provided by the WGL_EXT_swap_control extension.
1049 BOOL WINAPI wglSwapIntervalEXT( int interval )
1051 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1053 if (!funcs->ext.p_wglSwapIntervalEXT) return FALSE;
1054 return funcs->ext.p_wglSwapIntervalEXT( interval );
1057 /***********************************************************************
1058 * wglGetSwapIntervalEXT
1060 * Provided by the WGL_EXT_swap_control extension.
1062 int WINAPI wglGetSwapIntervalEXT(void)
1064 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1066 if (!funcs->ext.p_wglGetSwapIntervalEXT) return FALSE;
1067 return funcs->ext.p_wglGetSwapIntervalEXT();
1070 /***********************************************************************
1071 * wglSetPixelFormatWINE
1073 * Provided by the WGL_WINE_pixel_format_passthrough extension.
1075 BOOL WINAPI wglSetPixelFormatWINE( HDC hdc, int format )
1077 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
1079 if (!funcs || !funcs->ext.p_wglSetPixelFormatWINE) return FALSE;
1080 return funcs->ext.p_wglSetPixelFormatWINE( hdc, format );
1083 /***********************************************************************
1084 * wglUseFontBitmaps_common
1086 static BOOL wglUseFontBitmaps_common( HDC hdc, DWORD first, DWORD count, DWORD listBase, BOOL unicode )
1088 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1090 unsigned int glyph, size = 0;
1091 void *bitmap = NULL, *gl_bitmap = NULL;
1095 funcs->gl.p_glGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1096 funcs->gl.p_glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1098 for (glyph = first; glyph < first + count; glyph++) {
1099 static const MAT2 identity = { {0,1},{0,0},{0,0},{0,1} };
1100 unsigned int needed_size, height, width, width_int;
1103 needed_size = GetGlyphOutlineW(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, &identity);
1105 needed_size = GetGlyphOutlineA(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, &identity);
1107 TRACE("Glyph: %3d / List: %d size %d\n", glyph, listBase, needed_size);
1108 if (needed_size == GDI_ERROR) {
1113 if (needed_size > size) {
1115 HeapFree(GetProcessHeap(), 0, bitmap);
1116 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1117 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1118 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1121 ret = (GetGlyphOutlineW(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, &identity) != GDI_ERROR);
1123 ret = (GetGlyphOutlineA(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, &identity) != GDI_ERROR);
1126 if (TRACE_ON(wgl)) {
1127 unsigned int bitmask;
1128 unsigned char *bitmap_ = bitmap;
1130 TRACE(" - bbox: %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
1131 TRACE(" - origin: (%d, %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
1132 TRACE(" - increment: %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
1133 if (needed_size != 0) {
1134 TRACE(" - bitmap:\n");
1135 for (height = 0; height < gm.gmBlackBoxY; height++) {
1137 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
1142 if (*bitmap_ & bitmask)
1147 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
1153 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1154 * glyph for it to be drawn properly.
1156 if (needed_size != 0) {
1157 width_int = (gm.gmBlackBoxX + 31) / 32;
1158 for (height = 0; height < gm.gmBlackBoxY; height++) {
1159 for (width = 0; width < width_int; width++) {
1160 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
1161 ((int *) bitmap)[height * width_int + width];
1166 funcs->gl.p_glNewList(listBase++, GL_COMPILE);
1167 if (needed_size != 0) {
1168 funcs->gl.p_glBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
1169 0 - gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - gm.gmptGlyphOrigin.y,
1170 gm.gmCellIncX, gm.gmCellIncY,
1173 /* This is the case of 'empty' glyphs like the space character */
1174 funcs->gl.p_glBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
1176 funcs->gl.p_glEndList();
1179 funcs->gl.p_glPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1180 HeapFree(GetProcessHeap(), 0, bitmap);
1181 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1185 /***********************************************************************
1186 * wglUseFontBitmapsA (OPENGL32.@)
1188 BOOL WINAPI wglUseFontBitmapsA(HDC hdc, DWORD first, DWORD count, DWORD listBase)
1190 return wglUseFontBitmaps_common( hdc, first, count, listBase, FALSE );
1193 /***********************************************************************
1194 * wglUseFontBitmapsW (OPENGL32.@)
1196 BOOL WINAPI wglUseFontBitmapsW(HDC hdc, DWORD first, DWORD count, DWORD listBase)
1198 return wglUseFontBitmaps_common( hdc, first, count, listBase, TRUE );
1201 #ifdef SONAME_LIBGLU
1203 static void *load_libglu(void)
1205 static int already_loaded;
1208 if (already_loaded) return libglu_handle;
1211 TRACE("Trying to load GLU library: %s\n", SONAME_LIBGLU);
1212 handle = wine_dlopen(SONAME_LIBGLU, RTLD_NOW, NULL, 0);
1215 WARN("Failed to load %s\n", SONAME_LIBGLU);
1219 #define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(handle, #f, NULL, 0)) == NULL) goto sym_not_found;
1220 LOAD_FUNCPTR(gluNewTess)
1221 LOAD_FUNCPTR(gluDeleteTess)
1222 LOAD_FUNCPTR(gluTessBeginContour)
1223 LOAD_FUNCPTR(gluTessBeginPolygon)
1224 LOAD_FUNCPTR(gluTessCallback)
1225 LOAD_FUNCPTR(gluTessEndContour)
1226 LOAD_FUNCPTR(gluTessEndPolygon)
1227 LOAD_FUNCPTR(gluTessVertex)
1229 libglu_handle = handle;
1233 WARN("Unable to load function ptrs from libGLU\n");
1234 /* Close the library as we won't use it */
1235 wine_dlclose(handle, NULL, 0);
1239 static void fixed_to_double(POINTFX fixed, UINT em_size, GLdouble vertex[3])
1241 vertex[0] = (fixed.x.value + (GLdouble)fixed.x.fract / (1 << 16)) / em_size;
1242 vertex[1] = (fixed.y.value + (GLdouble)fixed.y.fract / (1 << 16)) / em_size;
1246 static void tess_callback_vertex(GLvoid *vertex)
1248 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1249 GLdouble *dbl = vertex;
1250 TRACE("%f, %f, %f\n", dbl[0], dbl[1], dbl[2]);
1251 funcs->gl.p_glVertex3dv(vertex);
1254 static void tess_callback_begin(GLenum which)
1256 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1257 TRACE("%d\n", which);
1258 funcs->gl.p_glBegin(which);
1261 static void tess_callback_end(void)
1263 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1265 funcs->gl.p_glEnd();
1268 /***********************************************************************
1269 * wglUseFontOutlines_common
1271 static BOOL wglUseFontOutlines_common(HDC hdc,
1278 LPGLYPHMETRICSFLOAT lpgmf,
1281 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1283 const MAT2 identity = {{0,1},{0,0},{0,0},{0,1}};
1284 GLUtesselator *tess;
1286 HFONT old_font, unscaled_font;
1287 UINT em_size = 1024;
1290 TRACE("(%p, %d, %d, %d, %f, %f, %d, %p, %s)\n", hdc, first, count,
1291 listBase, deviation, extrusion, format, lpgmf, unicode ? "W" : "A");
1295 ERR("libGLU is required for this function but isn't loaded\n");
1299 tess = pgluNewTess();
1300 if(!tess) return FALSE;
1301 pgluTessCallback(tess, GLU_TESS_VERTEX, (_GLUfuncptr)tess_callback_vertex);
1302 pgluTessCallback(tess, GLU_TESS_BEGIN, (_GLUfuncptr)tess_callback_begin);
1303 pgluTessCallback(tess, GLU_TESS_END, tess_callback_end);
1305 GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), &lf);
1306 rc.left = rc.right = rc.bottom = 0;
1308 DPtoLP(hdc, (POINT*)&rc, 2);
1309 lf.lfHeight = -abs(rc.top - rc.bottom);
1310 lf.lfOrientation = lf.lfEscapement = 0;
1311 unscaled_font = CreateFontIndirectW(&lf);
1312 old_font = SelectObject(hdc, unscaled_font);
1314 for (glyph = first; glyph < first + count; glyph++)
1319 TTPOLYGONHEADER *pph;
1324 needed = GetGlyphOutlineW(hdc, glyph, GGO_NATIVE, &gm, 0, NULL, &identity);
1326 needed = GetGlyphOutlineA(hdc, glyph, GGO_NATIVE, &gm, 0, NULL, &identity);
1328 if(needed == GDI_ERROR)
1331 buf = HeapAlloc(GetProcessHeap(), 0, needed);
1332 vertices = HeapAlloc(GetProcessHeap(), 0, needed / sizeof(POINTFX) * 3 * sizeof(GLdouble));
1335 GetGlyphOutlineW(hdc, glyph, GGO_NATIVE, &gm, needed, buf, &identity);
1337 GetGlyphOutlineA(hdc, glyph, GGO_NATIVE, &gm, needed, buf, &identity);
1339 TRACE("glyph %d\n", glyph);
1343 lpgmf->gmfBlackBoxX = (float)gm.gmBlackBoxX / em_size;
1344 lpgmf->gmfBlackBoxY = (float)gm.gmBlackBoxY / em_size;
1345 lpgmf->gmfptGlyphOrigin.x = (float)gm.gmptGlyphOrigin.x / em_size;
1346 lpgmf->gmfptGlyphOrigin.y = (float)gm.gmptGlyphOrigin.y / em_size;
1347 lpgmf->gmfCellIncX = (float)gm.gmCellIncX / em_size;
1348 lpgmf->gmfCellIncY = (float)gm.gmCellIncY / em_size;
1350 TRACE("%fx%f at %f,%f inc %f,%f\n", lpgmf->gmfBlackBoxX, lpgmf->gmfBlackBoxY,
1351 lpgmf->gmfptGlyphOrigin.x, lpgmf->gmfptGlyphOrigin.y, lpgmf->gmfCellIncX, lpgmf->gmfCellIncY);
1355 funcs->gl.p_glNewList(listBase++, GL_COMPILE);
1356 pgluTessBeginPolygon(tess, NULL);
1358 pph = (TTPOLYGONHEADER*)buf;
1359 while((BYTE*)pph < buf + needed)
1361 TRACE("\tstart %d, %d\n", pph->pfxStart.x.value, pph->pfxStart.y.value);
1363 pgluTessBeginContour(tess);
1365 fixed_to_double(pph->pfxStart, em_size, vertices);
1366 pgluTessVertex(tess, vertices, vertices);
1369 ppc = (TTPOLYCURVE*)((char*)pph + sizeof(*pph));
1370 while((char*)ppc < (char*)pph + pph->cb)
1374 switch(ppc->wType) {
1376 for(i = 0; i < ppc->cpfx; i++)
1378 TRACE("\t\tline to %d, %d\n", ppc->apfx[i].x.value, ppc->apfx[i].y.value);
1379 fixed_to_double(ppc->apfx[i], em_size, vertices);
1380 pgluTessVertex(tess, vertices, vertices);
1385 case TT_PRIM_QSPLINE:
1386 for(i = 0; i < ppc->cpfx/2; i++)
1388 /* FIXME: just connecting the control points for now */
1389 TRACE("\t\tcurve %d,%d %d,%d\n",
1390 ppc->apfx[i * 2].x.value, ppc->apfx[i * 3].y.value,
1391 ppc->apfx[i * 2 + 1].x.value, ppc->apfx[i * 3 + 1].y.value);
1392 fixed_to_double(ppc->apfx[i * 2], em_size, vertices);
1393 pgluTessVertex(tess, vertices, vertices);
1395 fixed_to_double(ppc->apfx[i * 2 + 1], em_size, vertices);
1396 pgluTessVertex(tess, vertices, vertices);
1401 ERR("\t\tcurve type = %d\n", ppc->wType);
1402 pgluTessEndContour(tess);
1406 ppc = (TTPOLYCURVE*)((char*)ppc + sizeof(*ppc) +
1407 (ppc->cpfx - 1) * sizeof(POINTFX));
1409 pgluTessEndContour(tess);
1410 pph = (TTPOLYGONHEADER*)((char*)pph + pph->cb);
1414 pgluTessEndPolygon(tess);
1415 funcs->gl.p_glTranslated((GLdouble)gm.gmCellIncX / em_size, (GLdouble)gm.gmCellIncY / em_size, 0.0);
1416 funcs->gl.p_glEndList();
1417 HeapFree(GetProcessHeap(), 0, buf);
1418 HeapFree(GetProcessHeap(), 0, vertices);
1422 DeleteObject(SelectObject(hdc, old_font));
1423 pgluDeleteTess(tess);
1428 #else /* SONAME_LIBGLU */
1430 static BOOL wglUseFontOutlines_common(HDC hdc,
1437 LPGLYPHMETRICSFLOAT lpgmf,
1440 FIXME("Unable to compile in wglUseFontOutlines support without GL/glu.h\n");
1444 #endif /* SONAME_LIBGLU */
1446 /***********************************************************************
1447 * wglUseFontOutlinesA (OPENGL32.@)
1449 BOOL WINAPI wglUseFontOutlinesA(HDC hdc,
1456 LPGLYPHMETRICSFLOAT lpgmf)
1458 return wglUseFontOutlines_common(hdc, first, count, listBase, deviation, extrusion, format, lpgmf, FALSE);
1461 /***********************************************************************
1462 * wglUseFontOutlinesW (OPENGL32.@)
1464 BOOL WINAPI wglUseFontOutlinesW(HDC hdc,
1471 LPGLYPHMETRICSFLOAT lpgmf)
1473 return wglUseFontOutlines_common(hdc, first, count, listBase, deviation, extrusion, format, lpgmf, TRUE);
1476 /***********************************************************************
1477 * glDebugEntry (OPENGL32.@)
1479 GLint WINAPI wine_glDebugEntry( GLint unknown1, GLint unknown2 )
1484 /* build the extension string by filtering out the disabled extensions */
1485 static char *build_gl_extensions( const char *extensions )
1487 char *p, *str, *disabled = NULL;
1491 TRACE( "GL_EXTENSIONS:\n" );
1493 if (!extensions) extensions = "";
1495 /* @@ Wine registry key: HKCU\Software\Wine\OpenGL */
1496 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\OpenGL", &hkey ))
1498 DWORD size, ret = RegQueryValueExA( hkey, "DisabledExtensions", 0, NULL, NULL, &size );
1499 if (!ret && (disabled = HeapAlloc( GetProcessHeap(), 0, size )))
1500 ret = RegQueryValueExA( hkey, "DisabledExtensions", 0, NULL, (BYTE *)disabled, &size );
1501 RegCloseKey( hkey );
1502 if (ret) *disabled = 0;
1505 if ((str = HeapAlloc( GetProcessHeap(), 0, strlen(extensions) + 2 )))
1510 while (*extensions == ' ') extensions++;
1511 if (!*extensions) break;
1512 if (!(end = strchr( extensions, ' ' ))) end = extensions + strlen( extensions );
1513 memcpy( p, extensions, end - extensions );
1514 p[end - extensions] = 0;
1515 if (!has_extension( disabled, p ))
1517 TRACE("++ %s\n", p );
1518 p += end - extensions;
1521 else TRACE("-- %s (disabled by config)\n", p );
1526 HeapFree( GetProcessHeap(), 0, disabled );
1530 /***********************************************************************
1531 * glGetString (OPENGL32.@)
1533 const GLubyte * WINAPI wine_glGetString( GLenum name )
1535 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1536 static const GLubyte *gl_extensions;
1538 /* this is for buggy nvidia driver, crashing if called from a different
1539 thread with no context */
1540 if(wglGetCurrentContext() == NULL)
1543 if (name != GL_EXTENSIONS) return funcs->gl.p_glGetString(name);
1547 const char *orig_ext = (const char *)funcs->gl.p_glGetString(GL_EXTENSIONS);
1548 char *new_ext = build_gl_extensions( orig_ext );
1549 if (InterlockedCompareExchangePointer( (void **)&gl_extensions, new_ext, NULL ))
1550 HeapFree( GetProcessHeap(), 0, new_ext );
1552 return gl_extensions;
1555 /***********************************************************************
1556 * wglSwapBuffers (OPENGL32.@)
1558 BOOL WINAPI DECLSPEC_HOTPATCH wglSwapBuffers( HDC hdc )
1560 return GdiSwapBuffers(hdc);
1563 /**********************************************************************/
1565 static void process_detach(void)
1567 if (libglu_handle) wine_dlclose(libglu_handle, NULL, 0);
1570 /***********************************************************************
1571 * OpenGL initialisation routine
1573 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
1577 case DLL_PROCESS_ATTACH:
1578 opengl32_handle = hinst;
1579 DisableThreadLibraryCalls(hinst);
1580 NtCurrentTeb()->glTable = &null_opengl_funcs;
1582 case DLL_THREAD_ATTACH:
1583 NtCurrentTeb()->glTable = &null_opengl_funcs;
1585 case DLL_PROCESS_DETACH: