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"
28 #include "opengl_ext.h"
37 #define WGL_WGLEXT_PROTOTYPES
38 #include "wine/wglext.h"
39 #include "wine/gdi_driver.h"
40 #include "wine/wgl_driver.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(wgl);
44 WINE_DECLARE_DEBUG_CHANNEL(fps);
46 static HMODULE opengl32_handle;
48 extern struct opengl_funcs null_opengl_funcs;
50 const GLubyte * WINAPI wine_glGetString( GLenum name );
52 /* handle management */
54 #define MAX_WGL_HANDLES 1024
58 HANDLE_CONTEXT = 0 << 12,
59 HANDLE_PBUFFER = 1 << 12,
60 HANDLE_TYPE_MASK = 15 << 12
65 DWORD tid; /* thread that the context is current in */
66 HDC draw_dc; /* current drawing DC */
67 HDC read_dc; /* current reading DC */
68 GLubyte *extensions; /* extension string */
69 struct wgl_context *drv_ctx; /* driver context */
75 struct opengl_funcs *funcs;
78 struct opengl_context *context; /* for HANDLE_CONTEXT */
79 struct wgl_pbuffer *pbuffer; /* for HANDLE_PBUFFER */
80 struct wgl_handle *next; /* for free handles */
84 static struct wgl_handle wgl_handles[MAX_WGL_HANDLES];
85 static struct wgl_handle *next_free;
86 static unsigned int handle_count;
88 static CRITICAL_SECTION wgl_section;
89 static CRITICAL_SECTION_DEBUG critsect_debug =
92 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
93 0, 0, { (DWORD_PTR)(__FILE__ ": wgl_section") }
95 static CRITICAL_SECTION wgl_section = { &critsect_debug, -1, 0, 0, 0, 0 };
97 static inline struct opengl_funcs *get_dc_funcs( HDC hdc )
99 struct opengl_funcs *funcs = __wine_get_wgl_driver( hdc, WINE_WGL_DRIVER_VERSION );
100 if (funcs == (void *)-1) funcs = &null_opengl_funcs;
104 static inline HANDLE next_handle( struct wgl_handle *ptr, enum wgl_handle_type type )
106 WORD generation = HIWORD( ptr->handle ) + 1;
107 if (!generation) generation++;
108 ptr->handle = MAKELONG( ptr - wgl_handles, generation ) | type;
109 return ULongToHandle( ptr->handle );
112 /* the current context is assumed valid and doesn't need locking */
113 static inline struct wgl_handle *get_current_context_ptr(void)
115 if (!NtCurrentTeb()->glCurrentRC) return NULL;
116 return &wgl_handles[LOWORD(NtCurrentTeb()->glCurrentRC) & ~HANDLE_TYPE_MASK];
119 static struct wgl_handle *get_handle_ptr( HANDLE handle, enum wgl_handle_type type )
121 unsigned int index = LOWORD( handle ) & ~HANDLE_TYPE_MASK;
123 EnterCriticalSection( &wgl_section );
124 if (index < handle_count && ULongToHandle(wgl_handles[index].handle) == handle)
125 return &wgl_handles[index];
127 LeaveCriticalSection( &wgl_section );
128 SetLastError( ERROR_INVALID_HANDLE );
132 static void release_handle_ptr( struct wgl_handle *ptr )
134 if (ptr) LeaveCriticalSection( &wgl_section );
137 static HANDLE alloc_handle( enum wgl_handle_type type, struct opengl_funcs *funcs, void *user_ptr )
140 struct wgl_handle *ptr = NULL;
142 EnterCriticalSection( &wgl_section );
143 if ((ptr = next_free))
144 next_free = next_free->u.next;
145 else if (handle_count < MAX_WGL_HANDLES)
146 ptr = &wgl_handles[handle_count++];
151 ptr->u.context = user_ptr;
152 handle = next_handle( ptr, type );
154 else SetLastError( ERROR_NOT_ENOUGH_MEMORY );
155 LeaveCriticalSection( &wgl_section );
159 static void free_handle_ptr( struct wgl_handle *ptr )
161 ptr->handle |= 0xffff;
162 ptr->u.next = next_free;
165 LeaveCriticalSection( &wgl_section );
168 /***********************************************************************
169 * wglCopyContext (OPENGL32.@)
171 BOOL WINAPI wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
173 struct wgl_handle *src, *dst;
176 if (!(src = get_handle_ptr( hglrcSrc, HANDLE_CONTEXT ))) return FALSE;
177 if ((dst = get_handle_ptr( hglrcDst, HANDLE_CONTEXT )))
179 if (src->funcs != dst->funcs) SetLastError( ERROR_INVALID_HANDLE );
180 else ret = src->funcs->wgl.p_wglCopyContext( src->u.context->drv_ctx,
181 dst->u.context->drv_ctx, mask );
183 release_handle_ptr( dst );
184 release_handle_ptr( src );
188 /***********************************************************************
189 * wglDeleteContext (OPENGL32.@)
191 BOOL WINAPI wglDeleteContext(HGLRC hglrc)
193 struct wgl_handle *ptr = get_handle_ptr( hglrc, HANDLE_CONTEXT );
195 if (!ptr) return FALSE;
197 if (ptr->u.context->tid && ptr->u.context->tid != GetCurrentThreadId())
199 SetLastError( ERROR_BUSY );
200 release_handle_ptr( ptr );
203 if (hglrc == NtCurrentTeb()->glCurrentRC) wglMakeCurrent( 0, 0 );
204 ptr->funcs->wgl.p_wglDeleteContext( ptr->u.context->drv_ctx );
205 HeapFree( GetProcessHeap(), 0, ptr->u.context->extensions );
206 HeapFree( GetProcessHeap(), 0, ptr->u.context );
207 free_handle_ptr( ptr );
211 /***********************************************************************
212 * wglMakeCurrent (OPENGL32.@)
214 BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
217 struct wgl_handle *ptr, *prev = get_current_context_ptr();
221 if (!(ptr = get_handle_ptr( hglrc, HANDLE_CONTEXT ))) return FALSE;
222 if (!ptr->u.context->tid || ptr->u.context->tid == GetCurrentThreadId())
224 ret = ptr->funcs->wgl.p_wglMakeCurrent( hdc, ptr->u.context->drv_ctx );
227 if (prev) prev->u.context->tid = 0;
228 ptr->u.context->tid = GetCurrentThreadId();
229 ptr->u.context->draw_dc = hdc;
230 ptr->u.context->read_dc = hdc;
231 NtCurrentTeb()->glCurrentRC = hglrc;
232 NtCurrentTeb()->glTable = ptr->funcs;
237 SetLastError( ERROR_BUSY );
240 release_handle_ptr( ptr );
244 if (!prev->funcs->wgl.p_wglMakeCurrent( 0, NULL )) return FALSE;
245 prev->u.context->tid = 0;
246 NtCurrentTeb()->glCurrentRC = 0;
247 NtCurrentTeb()->glTable = &null_opengl_funcs;
251 SetLastError( ERROR_INVALID_HANDLE );
257 /***********************************************************************
258 * wglCreateContextAttribsARB
260 * Provided by the WGL_ARB_create_context extension.
262 HGLRC WINAPI wglCreateContextAttribsARB( HDC hdc, HGLRC share, const int *attribs )
265 struct wgl_context *drv_ctx;
266 struct wgl_handle *share_ptr = NULL;
267 struct opengl_context *context;
268 struct opengl_funcs *funcs = get_dc_funcs( hdc );
270 if (!funcs || !funcs->ext.p_wglCreateContextAttribsARB) return 0;
271 if (share && !(share_ptr = get_handle_ptr( share, HANDLE_CONTEXT ))) return 0;
272 if ((drv_ctx = funcs->ext.p_wglCreateContextAttribsARB( hdc,
273 share_ptr ? share_ptr->u.context->drv_ctx : NULL, attribs )))
275 if ((context = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*context) )))
277 context->drv_ctx = drv_ctx;
278 if (!(ret = alloc_handle( HANDLE_CONTEXT, funcs, context )))
279 HeapFree( GetProcessHeap(), 0, context );
281 if (!ret) funcs->wgl.p_wglDeleteContext( drv_ctx );
283 release_handle_ptr( share_ptr );
288 /***********************************************************************
289 * wglMakeContextCurrentARB
291 * Provided by the WGL_ARB_make_current_read extension.
293 BOOL WINAPI wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, HGLRC hglrc )
296 struct wgl_handle *ptr, *prev = get_current_context_ptr();
300 if (!(ptr = get_handle_ptr( hglrc, HANDLE_CONTEXT ))) return FALSE;
301 if (!ptr->u.context->tid || ptr->u.context->tid == GetCurrentThreadId())
303 ret = (ptr->funcs->ext.p_wglMakeContextCurrentARB &&
304 ptr->funcs->ext.p_wglMakeContextCurrentARB( draw_hdc, read_hdc,
305 ptr->u.context->drv_ctx ));
308 if (prev) prev->u.context->tid = 0;
309 ptr->u.context->tid = GetCurrentThreadId();
310 ptr->u.context->draw_dc = draw_hdc;
311 ptr->u.context->read_dc = read_hdc;
312 NtCurrentTeb()->glCurrentRC = hglrc;
313 NtCurrentTeb()->glTable = ptr->funcs;
318 SetLastError( ERROR_BUSY );
321 release_handle_ptr( ptr );
325 if (!prev->funcs->wgl.p_wglMakeCurrent( 0, NULL )) return FALSE;
326 prev->u.context->tid = 0;
327 NtCurrentTeb()->glCurrentRC = 0;
328 NtCurrentTeb()->glTable = &null_opengl_funcs;
333 /***********************************************************************
334 * wglGetCurrentReadDCARB
336 * Provided by the WGL_ARB_make_current_read extension.
338 HDC WINAPI wglGetCurrentReadDCARB(void)
340 struct wgl_handle *ptr = get_current_context_ptr();
343 return ptr->u.context->read_dc;
346 /***********************************************************************
347 * wglShareLists (OPENGL32.@)
349 BOOL WINAPI wglShareLists(HGLRC hglrcSrc, HGLRC hglrcDst)
352 struct wgl_handle *src, *dst;
354 if (!(src = get_handle_ptr( hglrcSrc, HANDLE_CONTEXT ))) return FALSE;
355 if ((dst = get_handle_ptr( hglrcDst, HANDLE_CONTEXT )))
357 if (src->funcs != dst->funcs) SetLastError( ERROR_INVALID_HANDLE );
358 else ret = src->funcs->wgl.p_wglShareLists( src->u.context->drv_ctx, dst->u.context->drv_ctx );
360 release_handle_ptr( dst );
361 release_handle_ptr( src );
365 /***********************************************************************
366 * wglGetCurrentDC (OPENGL32.@)
368 HDC WINAPI wglGetCurrentDC(void)
370 struct wgl_handle *ptr = get_current_context_ptr();
373 return ptr->u.context->draw_dc;
376 /***********************************************************************
377 * wglCreateContext (OPENGL32.@)
379 HGLRC WINAPI wglCreateContext(HDC hdc)
382 struct wgl_context *drv_ctx;
383 struct opengl_context *context;
384 struct opengl_funcs *funcs = get_dc_funcs( hdc );
386 if (!funcs) return 0;
387 if (!(drv_ctx = funcs->wgl.p_wglCreateContext( hdc ))) return 0;
388 if ((context = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*context) )))
390 context->drv_ctx = drv_ctx;
391 if (!(ret = alloc_handle( HANDLE_CONTEXT, funcs, context )))
392 HeapFree( GetProcessHeap(), 0, context );
394 if (!ret) funcs->wgl.p_wglDeleteContext( drv_ctx );
398 /***********************************************************************
399 * wglGetCurrentContext (OPENGL32.@)
401 HGLRC WINAPI wglGetCurrentContext(void)
403 return NtCurrentTeb()->glCurrentRC;
406 /***********************************************************************
407 * wglDescribePixelFormat (OPENGL32.@)
409 INT WINAPI wglDescribePixelFormat(HDC hdc, INT format, UINT size, PIXELFORMATDESCRIPTOR *descr )
411 struct opengl_funcs *funcs = get_dc_funcs( hdc );
412 if (!funcs) return 0;
413 return funcs->wgl.p_wglDescribePixelFormat( hdc, format, size, descr );
416 /***********************************************************************
417 * wglChoosePixelFormat (OPENGL32.@)
419 INT WINAPI wglChoosePixelFormat(HDC hdc, const PIXELFORMATDESCRIPTOR* ppfd)
421 PIXELFORMATDESCRIPTOR format, best;
422 int i, count, best_format;
423 int bestDBuffer = -1, bestStereo = -1;
425 TRACE_(wgl)( "%p %p: size %u version %u flags %u type %u color %u %u,%u,%u,%u "
426 "accum %u depth %u stencil %u aux %u\n",
427 hdc, ppfd, ppfd->nSize, ppfd->nVersion, ppfd->dwFlags, ppfd->iPixelType,
428 ppfd->cColorBits, ppfd->cRedBits, ppfd->cGreenBits, ppfd->cBlueBits, ppfd->cAlphaBits,
429 ppfd->cAccumBits, ppfd->cDepthBits, ppfd->cStencilBits, ppfd->cAuxBuffers );
431 count = wglDescribePixelFormat( hdc, 0, 0, NULL );
432 if (!count) return 0;
436 best.cAlphaBits = -1;
437 best.cColorBits = -1;
438 best.cDepthBits = -1;
439 best.cStencilBits = -1;
440 best.cAuxBuffers = -1;
442 for (i = 1; i <= count; i++)
444 if (!wglDescribePixelFormat( hdc, i, sizeof(format), &format )) continue;
446 if (ppfd->iPixelType != format.iPixelType)
448 TRACE( "pixel type mismatch for iPixelFormat=%d\n", i );
452 /* only use bitmap capable for formats for bitmap rendering */
453 if( (ppfd->dwFlags & PFD_DRAW_TO_BITMAP) != (format.dwFlags & PFD_DRAW_TO_BITMAP))
455 TRACE( "PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i );
459 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
460 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
461 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
462 * formats without the given flag set.
463 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
464 * has indicated that a format without stereo is returned when stereo is unavailable.
465 * So in case PFD_STEREO is set, formats that support it should have priority above formats
466 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
468 * To summarize the following is most likely the correct behavior:
469 * stereo not set -> prefer non-stereo formats, but also accept stereo formats
470 * stereo set -> prefer stereo formats, but also accept non-stereo formats
471 * stereo don't care -> it doesn't matter whether we get stereo or not
473 * In Wine we will treat non-stereo the same way as don't care because it makes
474 * format selection even more complicated and second drivers with Stereo advertise
475 * each format twice anyway.
478 /* Doublebuffer, see the comments above */
479 if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE))
481 if (((ppfd->dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) &&
482 ((format.dwFlags & PFD_DOUBLEBUFFER) == (ppfd->dwFlags & PFD_DOUBLEBUFFER)))
485 if (bestDBuffer != -1 && (format.dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) continue;
488 /* Stereo, see the comments above. */
489 if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE))
491 if (((ppfd->dwFlags & PFD_STEREO) != bestStereo) &&
492 ((format.dwFlags & PFD_STEREO) == (ppfd->dwFlags & PFD_STEREO)))
495 if (bestStereo != -1 && (format.dwFlags & PFD_STEREO) != bestStereo) continue;
498 /* Below we will do a number of checks to select the 'best' pixelformat.
499 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
500 * The code works by trying to match the most important options as close as possible.
501 * When a reasonable format is found, we will try to match more options.
502 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
503 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
504 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
506 if (ppfd->cColorBits)
508 if (((ppfd->cColorBits > best.cColorBits) && (format.cColorBits > best.cColorBits)) ||
509 ((format.cColorBits >= ppfd->cColorBits) && (format.cColorBits < best.cColorBits)))
512 if (best.cColorBits != format.cColorBits) /* Do further checks if the format is compatible */
514 TRACE( "color mismatch for iPixelFormat=%d\n", i );
518 if (ppfd->cAlphaBits)
520 if (((ppfd->cAlphaBits > best.cAlphaBits) && (format.cAlphaBits > best.cAlphaBits)) ||
521 ((format.cAlphaBits >= ppfd->cAlphaBits) && (format.cAlphaBits < best.cAlphaBits)))
524 if (best.cAlphaBits != format.cAlphaBits)
526 TRACE( "alpha mismatch for iPixelFormat=%d\n", i );
530 if (ppfd->cDepthBits)
532 if (((ppfd->cDepthBits > best.cDepthBits) && (format.cDepthBits > best.cDepthBits)) ||
533 ((format.cDepthBits >= ppfd->cDepthBits) && (format.cDepthBits < best.cDepthBits)))
536 if (best.cDepthBits != format.cDepthBits)
538 TRACE( "depth mismatch for iPixelFormat=%d\n", i );
542 if (ppfd->cStencilBits)
544 if (((ppfd->cStencilBits > best.cStencilBits) && (format.cStencilBits > best.cStencilBits)) ||
545 ((format.cStencilBits >= ppfd->cStencilBits) && (format.cStencilBits < best.cStencilBits)))
548 if (best.cStencilBits != format.cStencilBits)
550 TRACE( "stencil mismatch for iPixelFormat=%d\n", i );
554 if (ppfd->cAuxBuffers)
556 if (((ppfd->cAuxBuffers > best.cAuxBuffers) && (format.cAuxBuffers > best.cAuxBuffers)) ||
557 ((format.cAuxBuffers >= ppfd->cAuxBuffers) && (format.cAuxBuffers < best.cAuxBuffers)))
560 if (best.cAuxBuffers != format.cAuxBuffers)
562 TRACE( "aux mismatch for iPixelFormat=%d\n", i );
571 bestDBuffer = format.dwFlags & PFD_DOUBLEBUFFER;
572 bestStereo = format.dwFlags & PFD_STEREO;
575 TRACE( "returning %u\n", best_format );
579 /***********************************************************************
580 * wglGetPixelFormat (OPENGL32.@)
582 INT WINAPI wglGetPixelFormat(HDC hdc)
584 struct opengl_funcs *funcs = get_dc_funcs( hdc );
585 if (!funcs) return 0;
586 return funcs->wgl.p_wglGetPixelFormat( hdc );
589 /***********************************************************************
590 * wglSetPixelFormat(OPENGL32.@)
592 BOOL WINAPI wglSetPixelFormat( HDC hdc, INT format, const PIXELFORMATDESCRIPTOR *descr )
594 struct opengl_funcs *funcs = get_dc_funcs( hdc );
595 if (!funcs) return 0;
596 return funcs->wgl.p_wglSetPixelFormat( hdc, format, descr );
599 /***********************************************************************
600 * wglSwapBuffers (OPENGL32.@)
602 BOOL WINAPI DECLSPEC_HOTPATCH wglSwapBuffers( HDC hdc )
604 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
606 if (!funcs || !funcs->wgl.p_wglSwapBuffers) return FALSE;
607 if (!funcs->wgl.p_wglSwapBuffers( hdc )) return FALSE;
611 static long prev_time, start_time;
612 static unsigned long frames, frames_total;
614 DWORD time = GetTickCount();
617 /* every 1.5 seconds */
618 if (time - prev_time > 1500)
620 TRACE_(fps)("@ approx %.2ffps, total %.2ffps\n",
621 1000.0*frames/(time - prev_time), 1000.0*frames_total/(time - start_time));
624 if (start_time == 0) start_time = time;
630 /***********************************************************************
631 * wglCreateLayerContext (OPENGL32.@)
633 HGLRC WINAPI wglCreateLayerContext(HDC hdc,
635 TRACE("(%p,%d)\n", hdc, iLayerPlane);
637 if (iLayerPlane == 0) {
638 return wglCreateContext(hdc);
640 FIXME("no handler for layer %d\n", iLayerPlane);
645 /***********************************************************************
646 * wglDescribeLayerPlane (OPENGL32.@)
648 BOOL WINAPI wglDescribeLayerPlane(HDC hdc,
652 LPLAYERPLANEDESCRIPTOR plpd) {
653 FIXME("(%p,%d,%d,%d,%p)\n", hdc, iPixelFormat, iLayerPlane, nBytes, plpd);
658 /***********************************************************************
659 * wglGetLayerPaletteEntries (OPENGL32.@)
661 int WINAPI wglGetLayerPaletteEntries(HDC hdc,
665 const COLORREF *pcr) {
666 FIXME("(): stub!\n");
671 /* check if the extension is present in the list */
672 static BOOL has_extension( const char *list, const char *ext )
674 size_t len = strlen( ext );
678 while (*list == ' ') list++;
679 if (!strncmp( list, ext, len ) && (!list[len] || list[len] == ' ')) return TRUE;
680 list = strchr( list, ' ' );
685 static int compar(const void *elt_a, const void *elt_b) {
686 return strcmp(((const OpenGL_extension *) elt_a)->name,
687 ((const OpenGL_extension *) elt_b)->name);
690 /* Check if a GL extension is supported */
691 static BOOL is_extension_supported(const char* extension)
693 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
694 const char *gl_ext_string = (const char*)wine_glGetString(GL_EXTENSIONS);
696 TRACE("Checking for extension '%s'\n", extension);
699 ERR("No OpenGL extensions found, check if your OpenGL setup is correct!\n");
703 /* We use the GetProcAddress function from the display driver to retrieve function pointers
704 * for OpenGL and WGL extensions. In case of winex11.drv the OpenGL extension lookup is done
705 * using glXGetProcAddress. This function is quite unreliable in the sense that its specs don't
706 * require the function to return NULL when an extension isn't found. For this reason we check
707 * if the OpenGL extension required for the function we are looking up is supported. */
709 /* Check if the extension is part of the GL extension string to see if it is supported. */
710 if (has_extension(gl_ext_string, extension))
713 /* In general an OpenGL function starts as an ARB/EXT extension and at some stage
714 * it becomes part of the core OpenGL library and can be reached without the ARB/EXT
715 * suffix as well. In the extension table, these functions contain GL_VERSION_major_minor.
716 * Check if we are searching for a core GL function */
717 if(strncmp(extension, "GL_VERSION_", 11) == 0)
719 const GLubyte *gl_version = funcs->gl.p_glGetString(GL_VERSION);
720 const char *version = extension + 11; /* Move past 'GL_VERSION_' */
723 ERR("No OpenGL version found!\n");
727 /* Compare the major/minor version numbers of the native OpenGL library and what is required by the function.
728 * The gl_version string is guaranteed to have at least a major/minor and sometimes it has a release number as well. */
729 if( (gl_version[0] >= version[0]) || ((gl_version[0] == version[0]) && (gl_version[2] >= version[2])) ) {
732 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]);
738 /***********************************************************************
739 * wglGetProcAddress (OPENGL32.@)
741 PROC WINAPI wglGetProcAddress(LPCSTR lpszProc)
743 struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
746 OpenGL_extension ext;
747 const OpenGL_extension *ext_ret;
748 struct wgl_handle *context = get_current_context_ptr();
750 TRACE("(%s)\n", lpszProc);
752 if (lpszProc == NULL)
755 /* Without an active context opengl32 doesn't know to what
756 * driver it has to dispatch wglGetProcAddress.
760 WARN("No active WGL context found\n");
764 /* Search in the thunks to find the real name of the extension */
766 ext_ret = bsearch(&ext, extension_registry, extension_registry_size,
767 sizeof(OpenGL_extension), compar);
770 WARN("Extension '%s' not defined in opengl32.dll's function table!\n", lpszProc);
774 func_ptr = (void **)&funcs->ext + (ext_ret - extension_registry);
777 /* Check if the GL extension required by the function is available */
778 if(!is_extension_supported(ext_ret->extension)) {
779 WARN("Extension '%s' required by function '%s' not supported!\n", ext_ret->extension, lpszProc);
782 local_func = context->funcs->wgl.p_wglGetProcAddress( ext_ret->name );
784 /* After that, look at the extensions defined in the Linux OpenGL library */
785 if (local_func == NULL) {
789 /* Remove the last 3 letters (EXT, ARB, ...).
791 I know that some extensions have more than 3 letters (MESA, NV,
792 INTEL, ...), but this is only a stop-gap measure to fix buggy
793 OpenGL drivers (moreover, it is only useful for old 1.0 apps
794 that query the glBindTextureEXT extension).
796 memcpy(buf, ext_ret->name, strlen(ext_ret->name) - 3);
797 buf[strlen(ext_ret->name) - 3] = '\0';
798 TRACE("Extension not found in the Linux OpenGL library, checking against libGL bug with %s..\n", buf);
800 ret = GetProcAddress(opengl32_handle, buf);
802 TRACE("Found function in main OpenGL library (%p)!\n", ret);
804 WARN("Did not find function %s (%s) in your OpenGL library!\n", lpszProc, ext_ret->name);
809 *func_ptr = local_func;
812 TRACE("returning function (%p)\n", ext_ret->func);
813 return ext_ret->func;
816 /***********************************************************************
817 * wglRealizeLayerPalette (OPENGL32.@)
819 BOOL WINAPI wglRealizeLayerPalette(HDC hdc,
827 /***********************************************************************
828 * wglSetLayerPaletteEntries (OPENGL32.@)
830 int WINAPI wglSetLayerPaletteEntries(HDC hdc,
834 const COLORREF *pcr) {
835 FIXME("(): stub!\n");
840 /***********************************************************************
841 * wglSwapLayerBuffers (OPENGL32.@)
843 BOOL WINAPI wglSwapLayerBuffers(HDC hdc,
845 TRACE("(%p, %08x)\n", hdc, fuPlanes);
847 if (fuPlanes & WGL_SWAP_MAIN_PLANE) {
848 if (!wglSwapBuffers( hdc )) return FALSE;
849 fuPlanes &= ~WGL_SWAP_MAIN_PLANE;
853 WARN("Following layers unhandled: %08x\n", fuPlanes);
859 /***********************************************************************
860 * wglAllocateMemoryNV
862 * Provided by the WGL_NV_vertex_array_range extension.
864 void * WINAPI wglAllocateMemoryNV( GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority )
866 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
868 if (!funcs->ext.p_wglAllocateMemoryNV) return NULL;
869 return funcs->ext.p_wglAllocateMemoryNV( size, readfreq, writefreq, priority );
872 /***********************************************************************
875 * Provided by the WGL_NV_vertex_array_range extension.
877 void WINAPI wglFreeMemoryNV( void *pointer )
879 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
881 if (funcs->ext.p_wglFreeMemoryNV) funcs->ext.p_wglFreeMemoryNV( pointer );
884 /***********************************************************************
887 * Provided by the WGL_ARB_render_texture extension.
889 BOOL WINAPI wglBindTexImageARB( HPBUFFERARB handle, int buffer )
891 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
894 if (!ptr) return FALSE;
895 ret = ptr->funcs->ext.p_wglBindTexImageARB( ptr->u.pbuffer, buffer );
896 release_handle_ptr( ptr );
900 /***********************************************************************
901 * wglReleaseTexImageARB
903 * Provided by the WGL_ARB_render_texture extension.
905 BOOL WINAPI wglReleaseTexImageARB( HPBUFFERARB handle, int buffer )
907 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
910 if (!ptr) return FALSE;
911 ret = ptr->funcs->ext.p_wglReleaseTexImageARB( ptr->u.pbuffer, buffer );
912 release_handle_ptr( ptr );
916 /***********************************************************************
917 * wglSetPbufferAttribARB
919 * Provided by the WGL_ARB_render_texture extension.
921 BOOL WINAPI wglSetPbufferAttribARB( HPBUFFERARB handle, const int *attribs )
923 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
926 if (!ptr) return FALSE;
927 ret = ptr->funcs->ext.p_wglSetPbufferAttribARB( ptr->u.pbuffer, attribs );
928 release_handle_ptr( ptr );
932 /***********************************************************************
933 * wglChoosePixelFormatARB
935 * Provided by the WGL_ARB_pixel_format extension.
937 BOOL WINAPI wglChoosePixelFormatARB( HDC hdc, const int *iattribs, const FLOAT *fattribs,
938 UINT max, int *formats, UINT *count )
940 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
942 if (!funcs || !funcs->ext.p_wglChoosePixelFormatARB) return FALSE;
943 return funcs->ext.p_wglChoosePixelFormatARB( hdc, iattribs, fattribs, max, formats, count );
946 /***********************************************************************
947 * wglGetPixelFormatAttribivARB
949 * Provided by the WGL_ARB_pixel_format extension.
951 BOOL WINAPI wglGetPixelFormatAttribivARB( HDC hdc, int format, int layer, UINT count, const int *attribs,
954 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
956 if (!funcs || !funcs->ext.p_wglGetPixelFormatAttribivARB) return FALSE;
957 return funcs->ext.p_wglGetPixelFormatAttribivARB( hdc, format, layer, count, attribs, values );
960 /***********************************************************************
961 * wglGetPixelFormatAttribfvARB
963 * Provided by the WGL_ARB_pixel_format extension.
965 BOOL WINAPI wglGetPixelFormatAttribfvARB( HDC hdc, int format, int layer, UINT count, const int *attribs,
968 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
970 if (!funcs || !funcs->ext.p_wglGetPixelFormatAttribfvARB) return FALSE;
971 return funcs->ext.p_wglGetPixelFormatAttribfvARB( hdc, format, layer, count, attribs, values );
974 /***********************************************************************
975 * wglCreatePbufferARB
977 * Provided by the WGL_ARB_pbuffer extension.
979 HPBUFFERARB WINAPI wglCreatePbufferARB( HDC hdc, int format, int width, int height, const int *attribs )
982 struct wgl_pbuffer *pbuffer;
983 struct opengl_funcs *funcs = get_dc_funcs( hdc );
985 if (!funcs || !funcs->ext.p_wglCreatePbufferARB) return 0;
986 if (!(pbuffer = funcs->ext.p_wglCreatePbufferARB( hdc, format, width, height, attribs ))) return 0;
987 ret = alloc_handle( HANDLE_PBUFFER, funcs, pbuffer );
988 if (!ret) funcs->ext.p_wglDestroyPbufferARB( pbuffer );
992 /***********************************************************************
995 * Provided by the WGL_ARB_pbuffer extension.
997 HDC WINAPI wglGetPbufferDCARB( HPBUFFERARB handle )
999 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
1003 ret = ptr->funcs->ext.p_wglGetPbufferDCARB( ptr->u.pbuffer );
1004 release_handle_ptr( ptr );
1008 /***********************************************************************
1009 * wglReleasePbufferDCARB
1011 * Provided by the WGL_ARB_pbuffer extension.
1013 int WINAPI wglReleasePbufferDCARB( HPBUFFERARB handle, HDC hdc )
1015 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
1018 if (!ptr) return FALSE;
1019 ret = ptr->funcs->ext.p_wglReleasePbufferDCARB( ptr->u.pbuffer, hdc );
1020 release_handle_ptr( ptr );
1024 /***********************************************************************
1025 * wglDestroyPbufferARB
1027 * Provided by the WGL_ARB_pbuffer extension.
1029 BOOL WINAPI wglDestroyPbufferARB( HPBUFFERARB handle )
1031 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
1033 if (!ptr) return FALSE;
1034 ptr->funcs->ext.p_wglDestroyPbufferARB( ptr->u.pbuffer );
1035 free_handle_ptr( ptr );
1039 /***********************************************************************
1040 * wglQueryPbufferARB
1042 * Provided by the WGL_ARB_pbuffer extension.
1044 BOOL WINAPI wglQueryPbufferARB( HPBUFFERARB handle, int attrib, int *value )
1046 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
1049 if (!ptr) return FALSE;
1050 ret = ptr->funcs->ext.p_wglQueryPbufferARB( ptr->u.pbuffer, attrib, value );
1051 release_handle_ptr( ptr );
1055 /***********************************************************************
1056 * wglGetExtensionsStringARB
1058 * Provided by the WGL_ARB_extensions_string extension.
1060 const char * WINAPI wglGetExtensionsStringARB( HDC hdc )
1062 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
1064 if (!funcs || !funcs->ext.p_wglGetExtensionsStringARB) return NULL;
1065 return (const char *)funcs->ext.p_wglGetExtensionsStringARB( hdc );
1068 /***********************************************************************
1069 * wglGetExtensionsStringEXT
1071 * Provided by the WGL_EXT_extensions_string extension.
1073 const char * WINAPI wglGetExtensionsStringEXT(void)
1075 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1077 if (!funcs->ext.p_wglGetExtensionsStringEXT) return NULL;
1078 return (const char *)funcs->ext.p_wglGetExtensionsStringEXT();
1081 /***********************************************************************
1082 * wglSwapIntervalEXT
1084 * Provided by the WGL_EXT_swap_control extension.
1086 BOOL WINAPI wglSwapIntervalEXT( int interval )
1088 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1090 if (!funcs->ext.p_wglSwapIntervalEXT) return FALSE;
1091 return funcs->ext.p_wglSwapIntervalEXT( interval );
1094 /***********************************************************************
1095 * wglGetSwapIntervalEXT
1097 * Provided by the WGL_EXT_swap_control extension.
1099 int WINAPI wglGetSwapIntervalEXT(void)
1101 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1103 if (!funcs->ext.p_wglGetSwapIntervalEXT) return FALSE;
1104 return funcs->ext.p_wglGetSwapIntervalEXT();
1107 /***********************************************************************
1108 * wglSetPixelFormatWINE
1110 * Provided by the WGL_WINE_pixel_format_passthrough extension.
1112 BOOL WINAPI wglSetPixelFormatWINE( HDC hdc, int format )
1114 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
1116 if (!funcs || !funcs->ext.p_wglSetPixelFormatWINE) return FALSE;
1117 return funcs->ext.p_wglSetPixelFormatWINE( hdc, format );
1120 /***********************************************************************
1121 * wglUseFontBitmaps_common
1123 static BOOL wglUseFontBitmaps_common( HDC hdc, DWORD first, DWORD count, DWORD listBase, BOOL unicode )
1125 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1127 unsigned int glyph, size = 0;
1128 void *bitmap = NULL, *gl_bitmap = NULL;
1132 funcs->gl.p_glGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1133 funcs->gl.p_glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1135 for (glyph = first; glyph < first + count; glyph++) {
1136 static const MAT2 identity = { {0,1},{0,0},{0,0},{0,1} };
1137 unsigned int needed_size, height, width, width_int;
1140 needed_size = GetGlyphOutlineW(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, &identity);
1142 needed_size = GetGlyphOutlineA(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, &identity);
1144 TRACE("Glyph: %3d / List: %d size %d\n", glyph, listBase, needed_size);
1145 if (needed_size == GDI_ERROR) {
1150 if (needed_size > size) {
1152 HeapFree(GetProcessHeap(), 0, bitmap);
1153 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1154 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1155 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1158 ret = (GetGlyphOutlineW(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, &identity) != GDI_ERROR);
1160 ret = (GetGlyphOutlineA(hdc, glyph, GGO_BITMAP, &gm, size, bitmap, &identity) != GDI_ERROR);
1163 if (TRACE_ON(wgl)) {
1164 unsigned int bitmask;
1165 unsigned char *bitmap_ = bitmap;
1167 TRACE(" - bbox: %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
1168 TRACE(" - origin: (%d, %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
1169 TRACE(" - increment: %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
1170 if (needed_size != 0) {
1171 TRACE(" - bitmap:\n");
1172 for (height = 0; height < gm.gmBlackBoxY; height++) {
1174 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
1179 if (*bitmap_ & bitmask)
1184 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
1190 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1191 * glyph for it to be drawn properly.
1193 if (needed_size != 0) {
1194 width_int = (gm.gmBlackBoxX + 31) / 32;
1195 for (height = 0; height < gm.gmBlackBoxY; height++) {
1196 for (width = 0; width < width_int; width++) {
1197 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
1198 ((int *) bitmap)[height * width_int + width];
1203 funcs->gl.p_glNewList(listBase++, GL_COMPILE);
1204 if (needed_size != 0) {
1205 funcs->gl.p_glBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
1206 0 - gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - gm.gmptGlyphOrigin.y,
1207 gm.gmCellIncX, gm.gmCellIncY,
1210 /* This is the case of 'empty' glyphs like the space character */
1211 funcs->gl.p_glBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
1213 funcs->gl.p_glEndList();
1216 funcs->gl.p_glPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1217 HeapFree(GetProcessHeap(), 0, bitmap);
1218 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1222 /***********************************************************************
1223 * wglUseFontBitmapsA (OPENGL32.@)
1225 BOOL WINAPI wglUseFontBitmapsA(HDC hdc, DWORD first, DWORD count, DWORD listBase)
1227 return wglUseFontBitmaps_common( hdc, first, count, listBase, FALSE );
1230 /***********************************************************************
1231 * wglUseFontBitmapsW (OPENGL32.@)
1233 BOOL WINAPI wglUseFontBitmapsW(HDC hdc, DWORD first, DWORD count, DWORD listBase)
1235 return wglUseFontBitmaps_common( hdc, first, count, listBase, TRUE );
1238 /* FIXME: should probably have a glu.h header */
1240 typedef struct GLUtesselator GLUtesselator;
1241 typedef void (WINAPI *_GLUfuncptr)(void);
1243 #define GLU_TESS_BEGIN 100100
1244 #define GLU_TESS_VERTEX 100101
1245 #define GLU_TESS_END 100102
1247 static GLUtesselator * (WINAPI *pgluNewTess)(void);
1248 static void (WINAPI *pgluDeleteTess)(GLUtesselator *tess);
1249 static void (WINAPI *pgluTessBeginPolygon)(GLUtesselator *tess, void *polygon_data);
1250 static void (WINAPI *pgluTessEndPolygon)(GLUtesselator *tess);
1251 static void (WINAPI *pgluTessCallback)(GLUtesselator *tess, GLenum which, _GLUfuncptr fn);
1252 static void (WINAPI *pgluTessBeginContour)(GLUtesselator *tess);
1253 static void (WINAPI *pgluTessEndContour)(GLUtesselator *tess);
1254 static void (WINAPI *pgluTessVertex)(GLUtesselator *tess, GLdouble *location, GLvoid* data);
1256 static HMODULE load_libglu(void)
1258 static const WCHAR glu32W[] = {'g','l','u','3','2','.','d','l','l',0};
1259 static int already_loaded;
1260 static HMODULE module;
1262 if (already_loaded) return module;
1265 TRACE("Trying to load GLU library\n");
1266 module = LoadLibraryW( glu32W );
1269 WARN("Failed to load glu32\n");
1272 #define LOAD_FUNCPTR(f) p##f = (void *)GetProcAddress( module, #f )
1273 LOAD_FUNCPTR(gluNewTess);
1274 LOAD_FUNCPTR(gluDeleteTess);
1275 LOAD_FUNCPTR(gluTessBeginContour);
1276 LOAD_FUNCPTR(gluTessBeginPolygon);
1277 LOAD_FUNCPTR(gluTessCallback);
1278 LOAD_FUNCPTR(gluTessEndContour);
1279 LOAD_FUNCPTR(gluTessEndPolygon);
1280 LOAD_FUNCPTR(gluTessVertex);
1285 static void fixed_to_double(POINTFX fixed, UINT em_size, GLdouble vertex[3])
1287 vertex[0] = (fixed.x.value + (GLdouble)fixed.x.fract / (1 << 16)) / em_size;
1288 vertex[1] = (fixed.y.value + (GLdouble)fixed.y.fract / (1 << 16)) / em_size;
1292 static void WINAPI tess_callback_vertex(GLvoid *vertex)
1294 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1295 GLdouble *dbl = vertex;
1296 TRACE("%f, %f, %f\n", dbl[0], dbl[1], dbl[2]);
1297 funcs->gl.p_glVertex3dv(vertex);
1300 static void WINAPI tess_callback_begin(GLenum which)
1302 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1303 TRACE("%d\n", which);
1304 funcs->gl.p_glBegin(which);
1307 static void WINAPI tess_callback_end(void)
1309 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1311 funcs->gl.p_glEnd();
1314 /***********************************************************************
1315 * wglUseFontOutlines_common
1317 static BOOL wglUseFontOutlines_common(HDC hdc,
1324 LPGLYPHMETRICSFLOAT lpgmf,
1327 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1329 const MAT2 identity = {{0,1},{0,0},{0,0},{0,1}};
1330 GLUtesselator *tess;
1332 HFONT old_font, unscaled_font;
1333 UINT em_size = 1024;
1336 TRACE("(%p, %d, %d, %d, %f, %f, %d, %p, %s)\n", hdc, first, count,
1337 listBase, deviation, extrusion, format, lpgmf, unicode ? "W" : "A");
1341 ERR("glu32 is required for this function but isn't available\n");
1345 tess = pgluNewTess();
1346 if(!tess) return FALSE;
1347 pgluTessCallback(tess, GLU_TESS_VERTEX, (_GLUfuncptr)tess_callback_vertex);
1348 pgluTessCallback(tess, GLU_TESS_BEGIN, (_GLUfuncptr)tess_callback_begin);
1349 pgluTessCallback(tess, GLU_TESS_END, tess_callback_end);
1351 GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), &lf);
1352 rc.left = rc.right = rc.bottom = 0;
1354 DPtoLP(hdc, (POINT*)&rc, 2);
1355 lf.lfHeight = -abs(rc.top - rc.bottom);
1356 lf.lfOrientation = lf.lfEscapement = 0;
1357 unscaled_font = CreateFontIndirectW(&lf);
1358 old_font = SelectObject(hdc, unscaled_font);
1360 for (glyph = first; glyph < first + count; glyph++)
1365 TTPOLYGONHEADER *pph;
1370 needed = GetGlyphOutlineW(hdc, glyph, GGO_NATIVE, &gm, 0, NULL, &identity);
1372 needed = GetGlyphOutlineA(hdc, glyph, GGO_NATIVE, &gm, 0, NULL, &identity);
1374 if(needed == GDI_ERROR)
1377 buf = HeapAlloc(GetProcessHeap(), 0, needed);
1378 vertices = HeapAlloc(GetProcessHeap(), 0, needed / sizeof(POINTFX) * 3 * sizeof(GLdouble));
1381 GetGlyphOutlineW(hdc, glyph, GGO_NATIVE, &gm, needed, buf, &identity);
1383 GetGlyphOutlineA(hdc, glyph, GGO_NATIVE, &gm, needed, buf, &identity);
1385 TRACE("glyph %d\n", glyph);
1389 lpgmf->gmfBlackBoxX = (float)gm.gmBlackBoxX / em_size;
1390 lpgmf->gmfBlackBoxY = (float)gm.gmBlackBoxY / em_size;
1391 lpgmf->gmfptGlyphOrigin.x = (float)gm.gmptGlyphOrigin.x / em_size;
1392 lpgmf->gmfptGlyphOrigin.y = (float)gm.gmptGlyphOrigin.y / em_size;
1393 lpgmf->gmfCellIncX = (float)gm.gmCellIncX / em_size;
1394 lpgmf->gmfCellIncY = (float)gm.gmCellIncY / em_size;
1396 TRACE("%fx%f at %f,%f inc %f,%f\n", lpgmf->gmfBlackBoxX, lpgmf->gmfBlackBoxY,
1397 lpgmf->gmfptGlyphOrigin.x, lpgmf->gmfptGlyphOrigin.y, lpgmf->gmfCellIncX, lpgmf->gmfCellIncY);
1401 funcs->gl.p_glNewList(listBase++, GL_COMPILE);
1402 pgluTessBeginPolygon(tess, NULL);
1404 pph = (TTPOLYGONHEADER*)buf;
1405 while((BYTE*)pph < buf + needed)
1407 TRACE("\tstart %d, %d\n", pph->pfxStart.x.value, pph->pfxStart.y.value);
1409 pgluTessBeginContour(tess);
1411 fixed_to_double(pph->pfxStart, em_size, vertices);
1412 pgluTessVertex(tess, vertices, vertices);
1415 ppc = (TTPOLYCURVE*)((char*)pph + sizeof(*pph));
1416 while((char*)ppc < (char*)pph + pph->cb)
1420 switch(ppc->wType) {
1422 for(i = 0; i < ppc->cpfx; i++)
1424 TRACE("\t\tline to %d, %d\n", ppc->apfx[i].x.value, ppc->apfx[i].y.value);
1425 fixed_to_double(ppc->apfx[i], em_size, vertices);
1426 pgluTessVertex(tess, vertices, vertices);
1431 case TT_PRIM_QSPLINE:
1432 for(i = 0; i < ppc->cpfx/2; i++)
1434 /* FIXME: just connecting the control points for now */
1435 TRACE("\t\tcurve %d,%d %d,%d\n",
1436 ppc->apfx[i * 2].x.value, ppc->apfx[i * 3].y.value,
1437 ppc->apfx[i * 2 + 1].x.value, ppc->apfx[i * 3 + 1].y.value);
1438 fixed_to_double(ppc->apfx[i * 2], em_size, vertices);
1439 pgluTessVertex(tess, vertices, vertices);
1441 fixed_to_double(ppc->apfx[i * 2 + 1], em_size, vertices);
1442 pgluTessVertex(tess, vertices, vertices);
1447 ERR("\t\tcurve type = %d\n", ppc->wType);
1448 pgluTessEndContour(tess);
1452 ppc = (TTPOLYCURVE*)((char*)ppc + sizeof(*ppc) +
1453 (ppc->cpfx - 1) * sizeof(POINTFX));
1455 pgluTessEndContour(tess);
1456 pph = (TTPOLYGONHEADER*)((char*)pph + pph->cb);
1460 pgluTessEndPolygon(tess);
1461 funcs->gl.p_glTranslated((GLdouble)gm.gmCellIncX / em_size, (GLdouble)gm.gmCellIncY / em_size, 0.0);
1462 funcs->gl.p_glEndList();
1463 HeapFree(GetProcessHeap(), 0, buf);
1464 HeapFree(GetProcessHeap(), 0, vertices);
1468 DeleteObject(SelectObject(hdc, old_font));
1469 pgluDeleteTess(tess);
1474 /***********************************************************************
1475 * wglUseFontOutlinesA (OPENGL32.@)
1477 BOOL WINAPI wglUseFontOutlinesA(HDC hdc,
1484 LPGLYPHMETRICSFLOAT lpgmf)
1486 return wglUseFontOutlines_common(hdc, first, count, listBase, deviation, extrusion, format, lpgmf, FALSE);
1489 /***********************************************************************
1490 * wglUseFontOutlinesW (OPENGL32.@)
1492 BOOL WINAPI wglUseFontOutlinesW(HDC hdc,
1499 LPGLYPHMETRICSFLOAT lpgmf)
1501 return wglUseFontOutlines_common(hdc, first, count, listBase, deviation, extrusion, format, lpgmf, TRUE);
1504 /***********************************************************************
1505 * glDebugEntry (OPENGL32.@)
1507 GLint WINAPI wine_glDebugEntry( GLint unknown1, GLint unknown2 )
1512 /* build the extension string by filtering out the disabled extensions */
1513 static GLubyte *filter_extensions( const char *extensions )
1515 static const char *disabled;
1519 TRACE( "GL_EXTENSIONS:\n" );
1521 if (!extensions) extensions = "";
1529 /* @@ Wine registry key: HKCU\Software\Wine\OpenGL */
1530 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\OpenGL", &hkey ))
1532 if (!RegQueryValueExA( hkey, "DisabledExtensions", 0, NULL, NULL, &size ))
1534 str = HeapAlloc( GetProcessHeap(), 0, size );
1535 if (RegQueryValueExA( hkey, "DisabledExtensions", 0, NULL, (BYTE *)str, &size )) *str = 0;
1537 RegCloseKey( hkey );
1541 if (InterlockedCompareExchangePointer( (void **)&disabled, str, NULL ))
1542 HeapFree( GetProcessHeap(), 0, str );
1547 if (!disabled[0]) return NULL;
1548 if ((str = HeapAlloc( GetProcessHeap(), 0, strlen(extensions) + 2 )))
1553 while (*extensions == ' ') extensions++;
1554 if (!*extensions) break;
1555 if (!(end = strchr( extensions, ' ' ))) end = extensions + strlen( extensions );
1556 memcpy( p, extensions, end - extensions );
1557 p[end - extensions] = 0;
1558 if (!has_extension( disabled, p ))
1560 TRACE("++ %s\n", p );
1561 p += end - extensions;
1564 else TRACE("-- %s (disabled by config)\n", p );
1569 return (GLubyte *)str;
1572 /***********************************************************************
1573 * glGetString (OPENGL32.@)
1575 const GLubyte * WINAPI wine_glGetString( GLenum name )
1577 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1578 const GLubyte *ret = funcs->gl.p_glGetString( name );
1580 if (name == GL_EXTENSIONS && ret)
1582 struct wgl_handle *ptr = get_current_context_ptr();
1583 if (ptr->u.context->extensions ||
1584 ((ptr->u.context->extensions = filter_extensions( (const char *)ret ))))
1585 ret = ptr->u.context->extensions;
1590 /***********************************************************************
1591 * OpenGL initialisation routine
1593 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
1597 case DLL_PROCESS_ATTACH:
1598 opengl32_handle = hinst;
1599 DisableThreadLibraryCalls(hinst);
1600 NtCurrentTeb()->glTable = &null_opengl_funcs;
1602 case DLL_THREAD_ATTACH:
1603 NtCurrentTeb()->glTable = &null_opengl_funcs;