user32: Fix error handling in EndDeferWindowPos.
[wine.git] / dlls / opengl32 / wgl.c
blob863dea2cb7f8623d5a07d5f41a167953e4e34cf6
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <string.h>
28 #include "opengl_ext.h"
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "winreg.h"
33 #include "wingdi.h"
34 #include "winternl.h"
35 #include "winnt.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 extern struct opengl_funcs null_opengl_funcs;
48 /* handle management */
50 #define MAX_WGL_HANDLES 1024
52 enum wgl_handle_type
54 HANDLE_PBUFFER = 0 << 12,
55 HANDLE_CONTEXT = 1 << 12,
56 HANDLE_CONTEXT_V3 = 3 << 12,
57 HANDLE_TYPE_MASK = 15 << 12
60 struct opengl_context
62 DWORD tid; /* thread that the context is current in */
63 HDC draw_dc; /* current drawing DC */
64 HDC read_dc; /* current reading DC */
65 GLubyte *extensions; /* extension string */
66 GLuint *disabled_exts; /* indices of disabled extensions */
67 struct wgl_context *drv_ctx; /* driver context */
70 struct wgl_handle
72 UINT handle;
73 struct opengl_funcs *funcs;
74 union
76 struct opengl_context *context; /* for HANDLE_CONTEXT */
77 struct wgl_pbuffer *pbuffer; /* for HANDLE_PBUFFER */
78 struct wgl_handle *next; /* for free handles */
79 } u;
82 static struct wgl_handle wgl_handles[MAX_WGL_HANDLES];
83 static struct wgl_handle *next_free;
84 static unsigned int handle_count;
86 static CRITICAL_SECTION wgl_section;
87 static CRITICAL_SECTION_DEBUG critsect_debug =
89 0, 0, &wgl_section,
90 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
91 0, 0, { (DWORD_PTR)(__FILE__ ": wgl_section") }
93 static CRITICAL_SECTION wgl_section = { &critsect_debug, -1, 0, 0, 0, 0 };
95 static const MAT2 identity = { {0,1},{0,0},{0,0},{0,1} };
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;
101 return 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 );
129 return NULL;
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 )
139 HANDLE handle = 0;
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++];
148 if (ptr)
150 ptr->funcs = funcs;
151 ptr->u.context = user_ptr;
152 handle = next_handle( ptr, type );
154 else SetLastError( ERROR_NOT_ENOUGH_MEMORY );
155 LeaveCriticalSection( &wgl_section );
156 return handle;
159 static void free_handle_ptr( struct wgl_handle *ptr )
161 ptr->handle |= 0xffff;
162 ptr->u.next = next_free;
163 ptr->funcs = NULL;
164 next_free = ptr;
165 LeaveCriticalSection( &wgl_section );
168 static inline enum wgl_handle_type get_current_context_type(void)
170 if (!NtCurrentTeb()->glCurrentRC) return HANDLE_CONTEXT;
171 return LOWORD(NtCurrentTeb()->glCurrentRC) & HANDLE_TYPE_MASK;
174 /***********************************************************************
175 * wglCopyContext (OPENGL32.@)
177 BOOL WINAPI wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
179 struct wgl_handle *src, *dst;
180 BOOL ret = FALSE;
182 if (!(src = get_handle_ptr( hglrcSrc, HANDLE_CONTEXT ))) return FALSE;
183 if ((dst = get_handle_ptr( hglrcDst, HANDLE_CONTEXT )))
185 if (src->funcs != dst->funcs) SetLastError( ERROR_INVALID_HANDLE );
186 else ret = src->funcs->wgl.p_wglCopyContext( src->u.context->drv_ctx,
187 dst->u.context->drv_ctx, mask );
189 release_handle_ptr( dst );
190 release_handle_ptr( src );
191 return ret;
194 /***********************************************************************
195 * wglDeleteContext (OPENGL32.@)
197 BOOL WINAPI wglDeleteContext(HGLRC hglrc)
199 struct wgl_handle *ptr = get_handle_ptr( hglrc, HANDLE_CONTEXT );
201 if (!ptr) return FALSE;
203 if (ptr->u.context->tid && ptr->u.context->tid != GetCurrentThreadId())
205 SetLastError( ERROR_BUSY );
206 release_handle_ptr( ptr );
207 return FALSE;
209 if (hglrc == NtCurrentTeb()->glCurrentRC) wglMakeCurrent( 0, 0 );
210 ptr->funcs->wgl.p_wglDeleteContext( ptr->u.context->drv_ctx );
211 HeapFree( GetProcessHeap(), 0, ptr->u.context->disabled_exts );
212 HeapFree( GetProcessHeap(), 0, ptr->u.context->extensions );
213 HeapFree( GetProcessHeap(), 0, ptr->u.context );
214 free_handle_ptr( ptr );
215 return TRUE;
218 /***********************************************************************
219 * wglMakeCurrent (OPENGL32.@)
221 BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
223 BOOL ret = TRUE;
224 struct wgl_handle *ptr, *prev = get_current_context_ptr();
226 if (hglrc)
228 if (!(ptr = get_handle_ptr( hglrc, HANDLE_CONTEXT ))) return FALSE;
229 if (!ptr->u.context->tid || ptr->u.context->tid == GetCurrentThreadId())
231 ret = ptr->funcs->wgl.p_wglMakeCurrent( hdc, ptr->u.context->drv_ctx );
232 if (ret)
234 if (prev) prev->u.context->tid = 0;
235 ptr->u.context->tid = GetCurrentThreadId();
236 ptr->u.context->draw_dc = hdc;
237 ptr->u.context->read_dc = hdc;
238 NtCurrentTeb()->glCurrentRC = hglrc;
239 NtCurrentTeb()->glTable = ptr->funcs;
242 else
244 SetLastError( ERROR_BUSY );
245 ret = FALSE;
247 release_handle_ptr( ptr );
249 else if (prev)
251 if (!prev->funcs->wgl.p_wglMakeCurrent( 0, NULL )) return FALSE;
252 prev->u.context->tid = 0;
253 NtCurrentTeb()->glCurrentRC = 0;
254 NtCurrentTeb()->glTable = &null_opengl_funcs;
256 else if (!hdc)
258 SetLastError( ERROR_INVALID_HANDLE );
259 ret = FALSE;
261 return ret;
264 /***********************************************************************
265 * wglCreateContextAttribsARB
267 * Provided by the WGL_ARB_create_context extension.
269 HGLRC WINAPI wglCreateContextAttribsARB( HDC hdc, HGLRC share, const int *attribs )
271 HGLRC ret = 0;
272 struct wgl_context *drv_ctx;
273 struct wgl_handle *share_ptr = NULL;
274 struct opengl_context *context;
275 struct opengl_funcs *funcs = get_dc_funcs( hdc );
277 if (!funcs)
279 SetLastError( ERROR_DC_NOT_FOUND );
280 return 0;
282 if (!funcs->ext.p_wglCreateContextAttribsARB) return 0;
283 if (share && !(share_ptr = get_handle_ptr( share, HANDLE_CONTEXT )))
285 SetLastError( ERROR_INVALID_OPERATION );
286 return 0;
288 if ((drv_ctx = funcs->ext.p_wglCreateContextAttribsARB( hdc,
289 share_ptr ? share_ptr->u.context->drv_ctx : NULL, attribs )))
291 if ((context = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*context) )))
293 enum wgl_handle_type type = HANDLE_CONTEXT;
295 if (attribs)
297 while (*attribs)
299 if (attribs[0] == WGL_CONTEXT_MAJOR_VERSION_ARB)
301 if (attribs[1] >= 3)
302 type = HANDLE_CONTEXT_V3;
303 break;
305 attribs += 2;
309 context->drv_ctx = drv_ctx;
310 if (!(ret = alloc_handle( type, funcs, context )))
311 HeapFree( GetProcessHeap(), 0, context );
313 if (!ret) funcs->wgl.p_wglDeleteContext( drv_ctx );
315 release_handle_ptr( share_ptr );
316 return ret;
320 /***********************************************************************
321 * wglMakeContextCurrentARB
323 * Provided by the WGL_ARB_make_current_read extension.
325 BOOL WINAPI wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, HGLRC hglrc )
327 BOOL ret = TRUE;
328 struct wgl_handle *ptr, *prev = get_current_context_ptr();
330 if (hglrc)
332 if (!(ptr = get_handle_ptr( hglrc, HANDLE_CONTEXT ))) return FALSE;
333 if (!ptr->u.context->tid || ptr->u.context->tid == GetCurrentThreadId())
335 ret = (ptr->funcs->ext.p_wglMakeContextCurrentARB &&
336 ptr->funcs->ext.p_wglMakeContextCurrentARB( draw_hdc, read_hdc,
337 ptr->u.context->drv_ctx ));
338 if (ret)
340 if (prev) prev->u.context->tid = 0;
341 ptr->u.context->tid = GetCurrentThreadId();
342 ptr->u.context->draw_dc = draw_hdc;
343 ptr->u.context->read_dc = read_hdc;
344 NtCurrentTeb()->glCurrentRC = hglrc;
345 NtCurrentTeb()->glTable = ptr->funcs;
348 else
350 SetLastError( ERROR_BUSY );
351 ret = FALSE;
353 release_handle_ptr( ptr );
355 else if (prev)
357 if (!prev->funcs->wgl.p_wglMakeCurrent( 0, NULL )) return FALSE;
358 prev->u.context->tid = 0;
359 NtCurrentTeb()->glCurrentRC = 0;
360 NtCurrentTeb()->glTable = &null_opengl_funcs;
362 return ret;
365 /***********************************************************************
366 * wglGetCurrentReadDCARB
368 * Provided by the WGL_ARB_make_current_read extension.
370 HDC WINAPI wglGetCurrentReadDCARB(void)
372 struct wgl_handle *ptr = get_current_context_ptr();
374 if (!ptr) return 0;
375 return ptr->u.context->read_dc;
378 /***********************************************************************
379 * wglShareLists (OPENGL32.@)
381 BOOL WINAPI wglShareLists(HGLRC hglrcSrc, HGLRC hglrcDst)
383 BOOL ret = FALSE;
384 struct wgl_handle *src, *dst;
386 if (!(src = get_handle_ptr( hglrcSrc, HANDLE_CONTEXT ))) return FALSE;
387 if ((dst = get_handle_ptr( hglrcDst, HANDLE_CONTEXT )))
389 if (src->funcs != dst->funcs) SetLastError( ERROR_INVALID_HANDLE );
390 else ret = src->funcs->wgl.p_wglShareLists( src->u.context->drv_ctx, dst->u.context->drv_ctx );
392 release_handle_ptr( dst );
393 release_handle_ptr( src );
394 return ret;
397 /***********************************************************************
398 * wglGetCurrentDC (OPENGL32.@)
400 HDC WINAPI wglGetCurrentDC(void)
402 struct wgl_handle *ptr = get_current_context_ptr();
404 if (!ptr) return 0;
405 return ptr->u.context->draw_dc;
408 /***********************************************************************
409 * wglCreateContext (OPENGL32.@)
411 HGLRC WINAPI wglCreateContext(HDC hdc)
413 HGLRC ret = 0;
414 struct wgl_context *drv_ctx;
415 struct opengl_context *context;
416 struct opengl_funcs *funcs = get_dc_funcs( hdc );
418 if (!funcs) return 0;
419 if (!(drv_ctx = funcs->wgl.p_wglCreateContext( hdc ))) return 0;
420 if ((context = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*context) )))
422 context->drv_ctx = drv_ctx;
423 if (!(ret = alloc_handle( HANDLE_CONTEXT, funcs, context )))
424 HeapFree( GetProcessHeap(), 0, context );
426 if (!ret) funcs->wgl.p_wglDeleteContext( drv_ctx );
427 return ret;
430 /***********************************************************************
431 * wglGetCurrentContext (OPENGL32.@)
433 HGLRC WINAPI wglGetCurrentContext(void)
435 return NtCurrentTeb()->glCurrentRC;
438 /***********************************************************************
439 * wglDescribePixelFormat (OPENGL32.@)
441 INT WINAPI wglDescribePixelFormat(HDC hdc, INT format, UINT size, PIXELFORMATDESCRIPTOR *descr )
443 struct opengl_funcs *funcs = get_dc_funcs( hdc );
444 if (!funcs) return 0;
445 return funcs->wgl.p_wglDescribePixelFormat( hdc, format, size, descr );
448 /***********************************************************************
449 * wglChoosePixelFormat (OPENGL32.@)
451 INT WINAPI wglChoosePixelFormat(HDC hdc, const PIXELFORMATDESCRIPTOR* ppfd)
453 PIXELFORMATDESCRIPTOR format, best;
454 int i, count, best_format;
455 int bestDBuffer = -1, bestStereo = -1;
457 TRACE_(wgl)( "%p %p: size %u version %u flags %u type %u color %u %u,%u,%u,%u "
458 "accum %u depth %u stencil %u aux %u\n",
459 hdc, ppfd, ppfd->nSize, ppfd->nVersion, ppfd->dwFlags, ppfd->iPixelType,
460 ppfd->cColorBits, ppfd->cRedBits, ppfd->cGreenBits, ppfd->cBlueBits, ppfd->cAlphaBits,
461 ppfd->cAccumBits, ppfd->cDepthBits, ppfd->cStencilBits, ppfd->cAuxBuffers );
463 count = wglDescribePixelFormat( hdc, 0, 0, NULL );
464 if (!count) return 0;
466 best_format = 0;
467 best.dwFlags = 0;
468 best.cAlphaBits = -1;
469 best.cColorBits = -1;
470 best.cDepthBits = -1;
471 best.cStencilBits = -1;
472 best.cAuxBuffers = -1;
474 for (i = 1; i <= count; i++)
476 if (!wglDescribePixelFormat( hdc, i, sizeof(format), &format )) continue;
478 if (ppfd->iPixelType != format.iPixelType)
480 TRACE( "pixel type mismatch for iPixelFormat=%d\n", i );
481 continue;
484 /* only use bitmap capable for formats for bitmap rendering */
485 if( (ppfd->dwFlags & PFD_DRAW_TO_BITMAP) != (format.dwFlags & PFD_DRAW_TO_BITMAP))
487 TRACE( "PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i );
488 continue;
491 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
492 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
493 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
494 * formats without the given flag set.
495 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
496 * has indicated that a format without stereo is returned when stereo is unavailable.
497 * So in case PFD_STEREO is set, formats that support it should have priority above formats
498 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
500 * To summarize the following is most likely the correct behavior:
501 * stereo not set -> prefer non-stereo formats, but also accept stereo formats
502 * stereo set -> prefer stereo formats, but also accept non-stereo formats
503 * stereo don't care -> it doesn't matter whether we get stereo or not
505 * In Wine we will treat non-stereo the same way as don't care because it makes
506 * format selection even more complicated and second drivers with Stereo advertise
507 * each format twice anyway.
510 /* Doublebuffer, see the comments above */
511 if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE))
513 if (((ppfd->dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) &&
514 ((format.dwFlags & PFD_DOUBLEBUFFER) == (ppfd->dwFlags & PFD_DOUBLEBUFFER)))
515 goto found;
517 if (bestDBuffer != -1 && (format.dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) continue;
520 /* Stereo, see the comments above. */
521 if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE))
523 if (((ppfd->dwFlags & PFD_STEREO) != bestStereo) &&
524 ((format.dwFlags & PFD_STEREO) == (ppfd->dwFlags & PFD_STEREO)))
525 goto found;
527 if (bestStereo != -1 && (format.dwFlags & PFD_STEREO) != bestStereo) continue;
530 /* Below we will do a number of checks to select the 'best' pixelformat.
531 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
532 * The code works by trying to match the most important options as close as possible.
533 * When a reasonable format is found, we will try to match more options.
534 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
535 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
536 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
538 if (ppfd->cColorBits)
540 if (((ppfd->cColorBits > best.cColorBits) && (format.cColorBits > best.cColorBits)) ||
541 ((format.cColorBits >= ppfd->cColorBits) && (format.cColorBits < best.cColorBits)))
542 goto found;
544 if (best.cColorBits != format.cColorBits) /* Do further checks if the format is compatible */
546 TRACE( "color mismatch for iPixelFormat=%d\n", i );
547 continue;
550 if (ppfd->cAlphaBits)
552 if (((ppfd->cAlphaBits > best.cAlphaBits) && (format.cAlphaBits > best.cAlphaBits)) ||
553 ((format.cAlphaBits >= ppfd->cAlphaBits) && (format.cAlphaBits < best.cAlphaBits)))
554 goto found;
556 if (best.cAlphaBits != format.cAlphaBits)
558 TRACE( "alpha mismatch for iPixelFormat=%d\n", i );
559 continue;
562 if (ppfd->cDepthBits)
564 if (((ppfd->cDepthBits > best.cDepthBits) && (format.cDepthBits > best.cDepthBits)) ||
565 ((format.cDepthBits >= ppfd->cDepthBits) && (format.cDepthBits < best.cDepthBits)))
566 goto found;
568 if (best.cDepthBits != format.cDepthBits)
570 TRACE( "depth mismatch for iPixelFormat=%d\n", i );
571 continue;
574 if (ppfd->cStencilBits)
576 if (((ppfd->cStencilBits > best.cStencilBits) && (format.cStencilBits > best.cStencilBits)) ||
577 ((format.cStencilBits >= ppfd->cStencilBits) && (format.cStencilBits < best.cStencilBits)))
578 goto found;
580 if (best.cStencilBits != format.cStencilBits)
582 TRACE( "stencil mismatch for iPixelFormat=%d\n", i );
583 continue;
586 if (ppfd->cAuxBuffers)
588 if (((ppfd->cAuxBuffers > best.cAuxBuffers) && (format.cAuxBuffers > best.cAuxBuffers)) ||
589 ((format.cAuxBuffers >= ppfd->cAuxBuffers) && (format.cAuxBuffers < best.cAuxBuffers)))
590 goto found;
592 if (best.cAuxBuffers != format.cAuxBuffers)
594 TRACE( "aux mismatch for iPixelFormat=%d\n", i );
595 continue;
598 continue;
600 found:
601 best_format = i;
602 best = format;
603 bestDBuffer = format.dwFlags & PFD_DOUBLEBUFFER;
604 bestStereo = format.dwFlags & PFD_STEREO;
607 TRACE( "returning %u\n", best_format );
608 return best_format;
611 /***********************************************************************
612 * wglGetPixelFormat (OPENGL32.@)
614 INT WINAPI wglGetPixelFormat(HDC hdc)
616 struct opengl_funcs *funcs = get_dc_funcs( hdc );
617 if (!funcs) return 0;
618 return funcs->wgl.p_wglGetPixelFormat( hdc );
621 /***********************************************************************
622 * wglSetPixelFormat(OPENGL32.@)
624 BOOL WINAPI wglSetPixelFormat( HDC hdc, INT format, const PIXELFORMATDESCRIPTOR *descr )
626 struct opengl_funcs *funcs = get_dc_funcs( hdc );
627 if (!funcs) return FALSE;
628 return funcs->wgl.p_wglSetPixelFormat( hdc, format, descr );
631 /***********************************************************************
632 * wglSwapBuffers (OPENGL32.@)
634 BOOL WINAPI DECLSPEC_HOTPATCH wglSwapBuffers( HDC hdc )
636 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
638 if (!funcs || !funcs->wgl.p_wglSwapBuffers) return FALSE;
639 if (!funcs->wgl.p_wglSwapBuffers( hdc )) return FALSE;
641 if (TRACE_ON(fps))
643 static long prev_time, start_time;
644 static unsigned long frames, frames_total;
646 DWORD time = GetTickCount();
647 frames++;
648 frames_total++;
649 /* every 1.5 seconds */
650 if (time - prev_time > 1500)
652 TRACE_(fps)("@ approx %.2ffps, total %.2ffps\n",
653 1000.0*frames/(time - prev_time), 1000.0*frames_total/(time - start_time));
654 prev_time = time;
655 frames = 0;
656 if (start_time == 0) start_time = time;
659 return TRUE;
662 /***********************************************************************
663 * wglCreateLayerContext (OPENGL32.@)
665 HGLRC WINAPI wglCreateLayerContext(HDC hdc,
666 int iLayerPlane) {
667 TRACE("(%p,%d)\n", hdc, iLayerPlane);
669 if (iLayerPlane == 0) {
670 return wglCreateContext(hdc);
672 FIXME("no handler for layer %d\n", iLayerPlane);
674 return NULL;
677 /***********************************************************************
678 * wglDescribeLayerPlane (OPENGL32.@)
680 BOOL WINAPI wglDescribeLayerPlane(HDC hdc,
681 int iPixelFormat,
682 int iLayerPlane,
683 UINT nBytes,
684 LPLAYERPLANEDESCRIPTOR plpd) {
685 FIXME("(%p,%d,%d,%d,%p)\n", hdc, iPixelFormat, iLayerPlane, nBytes, plpd);
687 return FALSE;
690 /***********************************************************************
691 * wglGetLayerPaletteEntries (OPENGL32.@)
693 int WINAPI wglGetLayerPaletteEntries(HDC hdc,
694 int iLayerPlane,
695 int iStart,
696 int cEntries,
697 const COLORREF *pcr) {
698 FIXME("(): stub!\n");
700 return 0;
703 static BOOL filter_extensions(const char *extensions, GLubyte **exts_list, GLuint **disabled_exts);
705 void WINAPI glGetIntegerv(GLenum pname, GLint *data)
707 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
709 TRACE("(%d, %p)\n", pname, data);
710 if (pname == GL_NUM_EXTENSIONS)
712 struct wgl_handle *ptr = get_current_context_ptr();
714 if (ptr->u.context->disabled_exts ||
715 filter_extensions(NULL, NULL, &ptr->u.context->disabled_exts))
717 const GLuint *disabled_exts = ptr->u.context->disabled_exts;
718 GLint count, disabled_count = 0;
720 funcs->gl.p_glGetIntegerv(pname, &count);
721 while (*disabled_exts++ != ~0u)
722 disabled_count++;
723 *data = count - disabled_count;
724 return;
727 funcs->gl.p_glGetIntegerv(pname, data);
730 const GLubyte * WINAPI glGetStringi(GLenum name, GLuint index)
732 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
734 TRACE("(%d, %d)\n", name, index);
735 if (!funcs->ext.p_glGetStringi)
737 void **func_ptr = (void **)&funcs->ext.p_glGetStringi;
739 *func_ptr = funcs->wgl.p_wglGetProcAddress("glGetStringi");
742 if (name == GL_EXTENSIONS)
744 struct wgl_handle *ptr = get_current_context_ptr();
746 if (ptr->u.context->disabled_exts ||
747 filter_extensions(NULL, NULL, &ptr->u.context->disabled_exts))
749 const GLuint *disabled_exts = ptr->u.context->disabled_exts;
750 unsigned int disabled_count = 0;
752 while (index + disabled_count >= *disabled_exts++)
753 disabled_count++;
754 return funcs->ext.p_glGetStringi(name, index + disabled_count);
757 return funcs->ext.p_glGetStringi(name, index);
760 /* check if the extension is present in the list */
761 static BOOL has_extension( const char *list, const char *ext, size_t len )
763 if (!list)
765 const char *gl_ext;
766 unsigned int i;
767 GLint extensions_count;
769 glGetIntegerv(GL_NUM_EXTENSIONS, &extensions_count);
770 for (i = 0; i < extensions_count; ++i)
772 gl_ext = (const char *)glGetStringi(GL_EXTENSIONS, i);
773 if (!strncmp(gl_ext, ext, len) && !gl_ext[len])
774 return TRUE;
776 return FALSE;
779 while (list)
781 while (*list == ' ') list++;
782 if (!strncmp( list, ext, len ) && (!list[len] || list[len] == ' ')) return TRUE;
783 list = strchr( list, ' ' );
785 return FALSE;
788 static int compar(const void *elt_a, const void *elt_b) {
789 return strcmp(((const OpenGL_extension *) elt_a)->name,
790 ((const OpenGL_extension *) elt_b)->name);
793 /* Check if a GL extension is supported */
794 static BOOL is_extension_supported(const char* extension)
796 enum wgl_handle_type type = get_current_context_type();
797 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
798 const char *gl_ext_string = NULL;
799 size_t len;
801 TRACE("Checking for extension '%s'\n", extension);
803 if (type == HANDLE_CONTEXT)
805 gl_ext_string = (const char*)glGetString(GL_EXTENSIONS);
806 if (!gl_ext_string)
808 ERR("No OpenGL extensions found, check if your OpenGL setup is correct!\n");
809 return FALSE;
813 /* We use the GetProcAddress function from the display driver to retrieve function pointers
814 * for OpenGL and WGL extensions. In case of winex11.drv the OpenGL extension lookup is done
815 * using glXGetProcAddress. This function is quite unreliable in the sense that its specs don't
816 * require the function to return NULL when an extension isn't found. For this reason we check
817 * if the OpenGL extension required for the function we are looking up is supported. */
819 while ((len = strcspn(extension, " ")) != 0)
821 /* Check if the extension is part of the GL extension string to see if it is supported. */
822 if (has_extension(gl_ext_string, extension, len))
823 return TRUE;
825 /* In general an OpenGL function starts as an ARB/EXT extension and at some stage
826 * it becomes part of the core OpenGL library and can be reached without the ARB/EXT
827 * suffix as well. In the extension table, these functions contain GL_VERSION_major_minor.
828 * Check if we are searching for a core GL function */
829 if(strncmp(extension, "GL_VERSION_", 11) == 0)
831 const GLubyte *gl_version = funcs->gl.p_glGetString(GL_VERSION);
832 const char *version = extension + 11; /* Move past 'GL_VERSION_' */
834 if(!gl_version) {
835 ERR("No OpenGL version found!\n");
836 return FALSE;
839 /* Compare the major/minor version numbers of the native OpenGL library and what is required by the function.
840 * The gl_version string is guaranteed to have at least a major/minor and sometimes it has a release number as well. */
841 if( (gl_version[0] > version[0]) || ((gl_version[0] == version[0]) && (gl_version[2] >= version[2])) ) {
842 return TRUE;
844 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]);
847 if (extension[len] == ' ') len++;
848 extension += len;
851 return FALSE;
854 /***********************************************************************
855 * wglGetProcAddress (OPENGL32.@)
857 PROC WINAPI wglGetProcAddress( LPCSTR name )
859 struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
860 void **func_ptr;
861 OpenGL_extension ext;
862 const OpenGL_extension *ext_ret;
864 if (!name) return NULL;
866 /* Without an active context opengl32 doesn't know to what
867 * driver it has to dispatch wglGetProcAddress.
869 if (!get_current_context_ptr())
871 WARN("No active WGL context found\n");
872 return NULL;
875 ext.name = name;
876 ext_ret = bsearch(&ext, extension_registry, extension_registry_size, sizeof(ext), compar);
877 if (!ext_ret)
879 WARN("Function %s unknown\n", name);
880 return NULL;
883 func_ptr = (void **)&funcs->ext + (ext_ret - extension_registry);
884 if (!*func_ptr)
886 void *driver_func = funcs->wgl.p_wglGetProcAddress( name );
888 if (!is_extension_supported(ext_ret->extension))
890 unsigned int i;
891 static const struct { const char *name, *alt; } alternatives[] =
893 { "glCopyTexSubImage3DEXT", "glCopyTexSubImage3D" }, /* needed by RuneScape */
894 { "glVertexAttribDivisor", "glVertexAttribDivisorARB"}, /* needed by Caffeine */
897 for (i = 0; i < sizeof(alternatives)/sizeof(alternatives[0]); i++)
899 if (strcmp( name, alternatives[i].name )) continue;
900 WARN("Extension %s required for %s not supported, trying %s\n",
901 ext_ret->extension, name, alternatives[i].alt );
902 return wglGetProcAddress( alternatives[i].alt );
904 WARN("Extension %s required for %s not supported\n", ext_ret->extension, name);
905 return NULL;
908 if (driver_func == NULL)
910 WARN("Function %s not supported by driver\n", name);
911 return NULL;
913 *func_ptr = driver_func;
916 TRACE("returning %s -> %p\n", name, ext_ret->func);
917 return ext_ret->func;
920 /***********************************************************************
921 * wglRealizeLayerPalette (OPENGL32.@)
923 BOOL WINAPI wglRealizeLayerPalette(HDC hdc,
924 int iLayerPlane,
925 BOOL bRealize) {
926 FIXME("()\n");
928 return FALSE;
931 /***********************************************************************
932 * wglSetLayerPaletteEntries (OPENGL32.@)
934 int WINAPI wglSetLayerPaletteEntries(HDC hdc,
935 int iLayerPlane,
936 int iStart,
937 int cEntries,
938 const COLORREF *pcr) {
939 FIXME("(): stub!\n");
941 return 0;
944 /***********************************************************************
945 * wglSwapLayerBuffers (OPENGL32.@)
947 BOOL WINAPI wglSwapLayerBuffers(HDC hdc,
948 UINT fuPlanes) {
949 TRACE("(%p, %08x)\n", hdc, fuPlanes);
951 if (fuPlanes & WGL_SWAP_MAIN_PLANE) {
952 if (!wglSwapBuffers( hdc )) return FALSE;
953 fuPlanes &= ~WGL_SWAP_MAIN_PLANE;
956 if (fuPlanes) {
957 WARN("Following layers unhandled: %08x\n", fuPlanes);
960 return TRUE;
963 /***********************************************************************
964 * wglAllocateMemoryNV
966 * Provided by the WGL_NV_vertex_array_range extension.
968 void * WINAPI wglAllocateMemoryNV( GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority )
970 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
972 if (!funcs->ext.p_wglAllocateMemoryNV) return NULL;
973 return funcs->ext.p_wglAllocateMemoryNV( size, readfreq, writefreq, priority );
976 /***********************************************************************
977 * wglFreeMemoryNV
979 * Provided by the WGL_NV_vertex_array_range extension.
981 void WINAPI wglFreeMemoryNV( void *pointer )
983 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
985 if (funcs->ext.p_wglFreeMemoryNV) funcs->ext.p_wglFreeMemoryNV( pointer );
988 /***********************************************************************
989 * wglBindTexImageARB
991 * Provided by the WGL_ARB_render_texture extension.
993 BOOL WINAPI wglBindTexImageARB( HPBUFFERARB handle, int buffer )
995 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
996 BOOL ret;
998 if (!ptr) return FALSE;
999 ret = ptr->funcs->ext.p_wglBindTexImageARB( ptr->u.pbuffer, buffer );
1000 release_handle_ptr( ptr );
1001 return ret;
1004 /***********************************************************************
1005 * wglReleaseTexImageARB
1007 * Provided by the WGL_ARB_render_texture extension.
1009 BOOL WINAPI wglReleaseTexImageARB( HPBUFFERARB handle, int buffer )
1011 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
1012 BOOL ret;
1014 if (!ptr) return FALSE;
1015 ret = ptr->funcs->ext.p_wglReleaseTexImageARB( ptr->u.pbuffer, buffer );
1016 release_handle_ptr( ptr );
1017 return ret;
1020 /***********************************************************************
1021 * wglSetPbufferAttribARB
1023 * Provided by the WGL_ARB_render_texture extension.
1025 BOOL WINAPI wglSetPbufferAttribARB( HPBUFFERARB handle, const int *attribs )
1027 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
1028 BOOL ret;
1030 if (!ptr) return FALSE;
1031 ret = ptr->funcs->ext.p_wglSetPbufferAttribARB( ptr->u.pbuffer, attribs );
1032 release_handle_ptr( ptr );
1033 return ret;
1036 /***********************************************************************
1037 * wglChoosePixelFormatARB
1039 * Provided by the WGL_ARB_pixel_format extension.
1041 BOOL WINAPI wglChoosePixelFormatARB( HDC hdc, const int *iattribs, const FLOAT *fattribs,
1042 UINT max, int *formats, UINT *count )
1044 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
1046 if (!funcs || !funcs->ext.p_wglChoosePixelFormatARB) return FALSE;
1047 return funcs->ext.p_wglChoosePixelFormatARB( hdc, iattribs, fattribs, max, formats, count );
1050 /***********************************************************************
1051 * wglGetPixelFormatAttribivARB
1053 * Provided by the WGL_ARB_pixel_format extension.
1055 BOOL WINAPI wglGetPixelFormatAttribivARB( HDC hdc, int format, int layer, UINT count, const int *attribs,
1056 int *values )
1058 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
1060 if (!funcs || !funcs->ext.p_wglGetPixelFormatAttribivARB) return FALSE;
1061 return funcs->ext.p_wglGetPixelFormatAttribivARB( hdc, format, layer, count, attribs, values );
1064 /***********************************************************************
1065 * wglGetPixelFormatAttribfvARB
1067 * Provided by the WGL_ARB_pixel_format extension.
1069 BOOL WINAPI wglGetPixelFormatAttribfvARB( HDC hdc, int format, int layer, UINT count, const int *attribs,
1070 FLOAT *values )
1072 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
1074 if (!funcs || !funcs->ext.p_wglGetPixelFormatAttribfvARB) return FALSE;
1075 return funcs->ext.p_wglGetPixelFormatAttribfvARB( hdc, format, layer, count, attribs, values );
1078 /***********************************************************************
1079 * wglCreatePbufferARB
1081 * Provided by the WGL_ARB_pbuffer extension.
1083 HPBUFFERARB WINAPI wglCreatePbufferARB( HDC hdc, int format, int width, int height, const int *attribs )
1085 HPBUFFERARB ret;
1086 struct wgl_pbuffer *pbuffer;
1087 struct opengl_funcs *funcs = get_dc_funcs( hdc );
1089 if (!funcs || !funcs->ext.p_wglCreatePbufferARB) return 0;
1090 if (!(pbuffer = funcs->ext.p_wglCreatePbufferARB( hdc, format, width, height, attribs ))) return 0;
1091 ret = alloc_handle( HANDLE_PBUFFER, funcs, pbuffer );
1092 if (!ret) funcs->ext.p_wglDestroyPbufferARB( pbuffer );
1093 return ret;
1096 /***********************************************************************
1097 * wglGetPbufferDCARB
1099 * Provided by the WGL_ARB_pbuffer extension.
1101 HDC WINAPI wglGetPbufferDCARB( HPBUFFERARB handle )
1103 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
1104 HDC ret;
1106 if (!ptr) return 0;
1107 ret = ptr->funcs->ext.p_wglGetPbufferDCARB( ptr->u.pbuffer );
1108 release_handle_ptr( ptr );
1109 return ret;
1112 /***********************************************************************
1113 * wglReleasePbufferDCARB
1115 * Provided by the WGL_ARB_pbuffer extension.
1117 int WINAPI wglReleasePbufferDCARB( HPBUFFERARB handle, HDC hdc )
1119 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
1120 BOOL ret;
1122 if (!ptr) return FALSE;
1123 ret = ptr->funcs->ext.p_wglReleasePbufferDCARB( ptr->u.pbuffer, hdc );
1124 release_handle_ptr( ptr );
1125 return ret;
1128 /***********************************************************************
1129 * wglDestroyPbufferARB
1131 * Provided by the WGL_ARB_pbuffer extension.
1133 BOOL WINAPI wglDestroyPbufferARB( HPBUFFERARB handle )
1135 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
1137 if (!ptr) return FALSE;
1138 ptr->funcs->ext.p_wglDestroyPbufferARB( ptr->u.pbuffer );
1139 free_handle_ptr( ptr );
1140 return TRUE;
1143 /***********************************************************************
1144 * wglQueryPbufferARB
1146 * Provided by the WGL_ARB_pbuffer extension.
1148 BOOL WINAPI wglQueryPbufferARB( HPBUFFERARB handle, int attrib, int *value )
1150 struct wgl_handle *ptr = get_handle_ptr( handle, HANDLE_PBUFFER );
1151 BOOL ret;
1153 if (!ptr) return FALSE;
1154 ret = ptr->funcs->ext.p_wglQueryPbufferARB( ptr->u.pbuffer, attrib, value );
1155 release_handle_ptr( ptr );
1156 return ret;
1159 /***********************************************************************
1160 * wglGetExtensionsStringARB
1162 * Provided by the WGL_ARB_extensions_string extension.
1164 const char * WINAPI wglGetExtensionsStringARB( HDC hdc )
1166 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
1168 if (!funcs || !funcs->ext.p_wglGetExtensionsStringARB) return NULL;
1169 return (const char *)funcs->ext.p_wglGetExtensionsStringARB( hdc );
1172 /***********************************************************************
1173 * wglGetExtensionsStringEXT
1175 * Provided by the WGL_EXT_extensions_string extension.
1177 const char * WINAPI wglGetExtensionsStringEXT(void)
1179 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1181 if (!funcs->ext.p_wglGetExtensionsStringEXT) return NULL;
1182 return (const char *)funcs->ext.p_wglGetExtensionsStringEXT();
1185 /***********************************************************************
1186 * wglSwapIntervalEXT
1188 * Provided by the WGL_EXT_swap_control extension.
1190 BOOL WINAPI wglSwapIntervalEXT( int interval )
1192 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1194 if (!funcs->ext.p_wglSwapIntervalEXT) return FALSE;
1195 return funcs->ext.p_wglSwapIntervalEXT( interval );
1198 /***********************************************************************
1199 * wglGetSwapIntervalEXT
1201 * Provided by the WGL_EXT_swap_control extension.
1203 int WINAPI wglGetSwapIntervalEXT(void)
1205 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1207 if (!funcs->ext.p_wglGetSwapIntervalEXT) return FALSE;
1208 return funcs->ext.p_wglGetSwapIntervalEXT();
1211 /***********************************************************************
1212 * wglSetPixelFormatWINE
1214 * Provided by the WGL_WINE_pixel_format_passthrough extension.
1216 BOOL WINAPI wglSetPixelFormatWINE( HDC hdc, int format )
1218 const struct opengl_funcs *funcs = get_dc_funcs( hdc );
1220 if (!funcs || !funcs->ext.p_wglSetPixelFormatWINE) return FALSE;
1221 return funcs->ext.p_wglSetPixelFormatWINE( hdc, format );
1224 /***********************************************************************
1225 * wglQueryCurrentRendererIntegerWINE
1227 * Provided by the WGL_WINE_query_renderer extension.
1229 BOOL WINAPI wglQueryCurrentRendererIntegerWINE( GLenum attribute, GLuint *value )
1231 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1233 if (!funcs->ext.p_wglQueryCurrentRendererIntegerWINE) return FALSE;
1234 return funcs->ext.p_wglQueryCurrentRendererIntegerWINE( attribute, value );
1237 /***********************************************************************
1238 * wglQueryCurrentRendererStringWINE
1240 * Provided by the WGL_WINE_query_renderer extension.
1242 const GLchar * WINAPI wglQueryCurrentRendererStringWINE( GLenum attribute )
1244 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1246 if (!funcs->ext.p_wglQueryCurrentRendererStringWINE) return NULL;
1247 return funcs->ext.p_wglQueryCurrentRendererStringWINE( attribute );
1250 /***********************************************************************
1251 * wglQueryRendererIntegerWINE
1253 * Provided by the WGL_WINE_query_renderer extension.
1255 BOOL WINAPI wglQueryRendererIntegerWINE( HDC dc, GLint renderer, GLenum attribute, GLuint *value )
1257 const struct opengl_funcs *funcs = get_dc_funcs( dc );
1259 if (!funcs || !funcs->ext.p_wglQueryRendererIntegerWINE) return FALSE;
1260 return funcs->ext.p_wglQueryRendererIntegerWINE( dc, renderer, attribute, value );
1263 /***********************************************************************
1264 * wglQueryRendererStringWINE
1266 * Provided by the WGL_WINE_query_renderer extension.
1268 const GLchar * WINAPI wglQueryRendererStringWINE( HDC dc, GLint renderer, GLenum attribute )
1270 const struct opengl_funcs *funcs = get_dc_funcs( dc );
1272 if (!funcs || !funcs->ext.p_wglQueryRendererStringWINE) return NULL;
1273 return funcs->ext.p_wglQueryRendererStringWINE( dc, renderer, attribute );
1276 /***********************************************************************
1277 * wglUseFontBitmaps_common
1279 static BOOL wglUseFontBitmaps_common( HDC hdc, DWORD first, DWORD count, DWORD listBase, BOOL unicode )
1281 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1282 GLYPHMETRICS gm;
1283 unsigned int glyph, size = 0;
1284 void *bitmap = NULL, *gl_bitmap = NULL;
1285 int org_alignment;
1286 BOOL ret = TRUE;
1288 funcs->gl.p_glGetIntegerv(GL_UNPACK_ALIGNMENT, &org_alignment);
1289 funcs->gl.p_glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
1291 for (glyph = first; glyph < first + count; glyph++) {
1292 unsigned int needed_size, height, width, width_int;
1294 if (unicode)
1295 needed_size = GetGlyphOutlineW(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, &identity);
1296 else
1297 needed_size = GetGlyphOutlineA(hdc, glyph, GGO_BITMAP, &gm, 0, NULL, &identity);
1299 TRACE("Glyph: %3d / List: %d size %d\n", glyph, listBase, needed_size);
1300 if (needed_size == GDI_ERROR) {
1301 ret = FALSE;
1302 break;
1305 if (needed_size > size) {
1306 size = needed_size;
1307 HeapFree(GetProcessHeap(), 0, bitmap);
1308 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1309 bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1310 gl_bitmap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
1312 if (needed_size != 0) {
1313 if (unicode)
1314 ret = (GetGlyphOutlineW(hdc, glyph, GGO_BITMAP, &gm,
1315 size, bitmap, &identity) != GDI_ERROR);
1316 else
1317 ret = (GetGlyphOutlineA(hdc, glyph, GGO_BITMAP, &gm,
1318 size, bitmap, &identity) != GDI_ERROR);
1319 if (!ret) break;
1322 if (TRACE_ON(wgl)) {
1323 unsigned int bitmask;
1324 unsigned char *bitmap_ = bitmap;
1326 TRACE(" - bbox: %d x %d\n", gm.gmBlackBoxX, gm.gmBlackBoxY);
1327 TRACE(" - origin: (%d, %d)\n", gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
1328 TRACE(" - increment: %d - %d\n", gm.gmCellIncX, gm.gmCellIncY);
1329 if (needed_size != 0) {
1330 TRACE(" - bitmap:\n");
1331 for (height = 0; height < gm.gmBlackBoxY; height++) {
1332 TRACE(" ");
1333 for (width = 0, bitmask = 0x80; width < gm.gmBlackBoxX; width++, bitmask >>= 1) {
1334 if (bitmask == 0) {
1335 bitmap_ += 1;
1336 bitmask = 0x80;
1338 if (*bitmap_ & bitmask)
1339 TRACE("*");
1340 else
1341 TRACE(" ");
1343 bitmap_ += (4 - ((UINT_PTR)bitmap_ & 0x03));
1344 TRACE("\n");
1349 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1350 * glyph for it to be drawn properly.
1352 if (needed_size != 0) {
1353 width_int = (gm.gmBlackBoxX + 31) / 32;
1354 for (height = 0; height < gm.gmBlackBoxY; height++) {
1355 for (width = 0; width < width_int; width++) {
1356 ((int *) gl_bitmap)[(gm.gmBlackBoxY - height - 1) * width_int + width] =
1357 ((int *) bitmap)[height * width_int + width];
1362 funcs->gl.p_glNewList(listBase++, GL_COMPILE);
1363 if (needed_size != 0) {
1364 funcs->gl.p_glBitmap(gm.gmBlackBoxX, gm.gmBlackBoxY,
1365 0 - gm.gmptGlyphOrigin.x, (int) gm.gmBlackBoxY - gm.gmptGlyphOrigin.y,
1366 gm.gmCellIncX, gm.gmCellIncY,
1367 gl_bitmap);
1368 } else {
1369 /* This is the case of 'empty' glyphs like the space character */
1370 funcs->gl.p_glBitmap(0, 0, 0, 0, gm.gmCellIncX, gm.gmCellIncY, NULL);
1372 funcs->gl.p_glEndList();
1375 funcs->gl.p_glPixelStorei(GL_UNPACK_ALIGNMENT, org_alignment);
1376 HeapFree(GetProcessHeap(), 0, bitmap);
1377 HeapFree(GetProcessHeap(), 0, gl_bitmap);
1378 return ret;
1381 /***********************************************************************
1382 * wglUseFontBitmapsA (OPENGL32.@)
1384 BOOL WINAPI wglUseFontBitmapsA(HDC hdc, DWORD first, DWORD count, DWORD listBase)
1386 return wglUseFontBitmaps_common( hdc, first, count, listBase, FALSE );
1389 /***********************************************************************
1390 * wglUseFontBitmapsW (OPENGL32.@)
1392 BOOL WINAPI wglUseFontBitmapsW(HDC hdc, DWORD first, DWORD count, DWORD listBase)
1394 return wglUseFontBitmaps_common( hdc, first, count, listBase, TRUE );
1397 /* FIXME: should probably have a glu.h header */
1399 typedef struct GLUtesselator GLUtesselator;
1400 typedef void (WINAPI *_GLUfuncptr)(void);
1402 #define GLU_TESS_BEGIN 100100
1403 #define GLU_TESS_VERTEX 100101
1404 #define GLU_TESS_END 100102
1406 static GLUtesselator * (WINAPI *pgluNewTess)(void);
1407 static void (WINAPI *pgluDeleteTess)(GLUtesselator *tess);
1408 static void (WINAPI *pgluTessNormal)(GLUtesselator *tess, GLdouble x, GLdouble y, GLdouble z);
1409 static void (WINAPI *pgluTessBeginPolygon)(GLUtesselator *tess, void *polygon_data);
1410 static void (WINAPI *pgluTessEndPolygon)(GLUtesselator *tess);
1411 static void (WINAPI *pgluTessCallback)(GLUtesselator *tess, GLenum which, _GLUfuncptr fn);
1412 static void (WINAPI *pgluTessBeginContour)(GLUtesselator *tess);
1413 static void (WINAPI *pgluTessEndContour)(GLUtesselator *tess);
1414 static void (WINAPI *pgluTessVertex)(GLUtesselator *tess, GLdouble *location, GLvoid* data);
1416 static HMODULE load_libglu(void)
1418 static const WCHAR glu32W[] = {'g','l','u','3','2','.','d','l','l',0};
1419 static BOOL already_loaded;
1420 static HMODULE module;
1422 if (already_loaded) return module;
1423 already_loaded = TRUE;
1425 TRACE("Trying to load GLU library\n");
1426 module = LoadLibraryW( glu32W );
1427 if (!module)
1429 WARN("Failed to load glu32\n");
1430 return NULL;
1432 #define LOAD_FUNCPTR(f) p##f = (void *)GetProcAddress( module, #f )
1433 LOAD_FUNCPTR(gluNewTess);
1434 LOAD_FUNCPTR(gluDeleteTess);
1435 LOAD_FUNCPTR(gluTessBeginContour);
1436 LOAD_FUNCPTR(gluTessNormal);
1437 LOAD_FUNCPTR(gluTessBeginPolygon);
1438 LOAD_FUNCPTR(gluTessCallback);
1439 LOAD_FUNCPTR(gluTessEndContour);
1440 LOAD_FUNCPTR(gluTessEndPolygon);
1441 LOAD_FUNCPTR(gluTessVertex);
1442 #undef LOAD_FUNCPTR
1443 return module;
1446 static void fixed_to_double(POINTFX fixed, UINT em_size, GLdouble vertex[3])
1448 vertex[0] = (fixed.x.value + (GLdouble)fixed.x.fract / (1 << 16)) / em_size;
1449 vertex[1] = (fixed.y.value + (GLdouble)fixed.y.fract / (1 << 16)) / em_size;
1450 vertex[2] = 0.0;
1453 static void WINAPI tess_callback_vertex(GLvoid *vertex)
1455 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1456 GLdouble *dbl = vertex;
1457 TRACE("%f, %f, %f\n", dbl[0], dbl[1], dbl[2]);
1458 funcs->gl.p_glVertex3dv(vertex);
1461 static void WINAPI tess_callback_begin(GLenum which)
1463 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1464 TRACE("%d\n", which);
1465 funcs->gl.p_glBegin(which);
1468 static void WINAPI tess_callback_end(void)
1470 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1471 TRACE("\n");
1472 funcs->gl.p_glEnd();
1475 typedef struct _bezier_vector {
1476 GLdouble x;
1477 GLdouble y;
1478 } bezier_vector;
1480 static double bezier_deviation_squared(const bezier_vector *p)
1482 bezier_vector deviation;
1483 bezier_vector vertex;
1484 bezier_vector base;
1485 double base_length;
1486 double dot;
1488 vertex.x = (p[0].x + p[1].x*2 + p[2].x)/4 - p[0].x;
1489 vertex.y = (p[0].y + p[1].y*2 + p[2].y)/4 - p[0].y;
1491 base.x = p[2].x - p[0].x;
1492 base.y = p[2].y - p[0].y;
1494 base_length = sqrt(base.x*base.x + base.y*base.y);
1495 base.x /= base_length;
1496 base.y /= base_length;
1498 dot = base.x*vertex.x + base.y*vertex.y;
1499 dot = min(max(dot, 0.0), base_length);
1500 base.x *= dot;
1501 base.y *= dot;
1503 deviation.x = vertex.x-base.x;
1504 deviation.y = vertex.y-base.y;
1506 return deviation.x*deviation.x + deviation.y*deviation.y;
1509 static int bezier_approximate(const bezier_vector *p, bezier_vector *points, FLOAT deviation)
1511 bezier_vector first_curve[3];
1512 bezier_vector second_curve[3];
1513 bezier_vector vertex;
1514 int total_vertices;
1516 if(bezier_deviation_squared(p) <= deviation*deviation)
1518 if(points)
1519 *points = p[2];
1520 return 1;
1523 vertex.x = (p[0].x + p[1].x*2 + p[2].x)/4;
1524 vertex.y = (p[0].y + p[1].y*2 + p[2].y)/4;
1526 first_curve[0] = p[0];
1527 first_curve[1].x = (p[0].x + p[1].x)/2;
1528 first_curve[1].y = (p[0].y + p[1].y)/2;
1529 first_curve[2] = vertex;
1531 second_curve[0] = vertex;
1532 second_curve[1].x = (p[2].x + p[1].x)/2;
1533 second_curve[1].y = (p[2].y + p[1].y)/2;
1534 second_curve[2] = p[2];
1536 total_vertices = bezier_approximate(first_curve, points, deviation);
1537 if(points)
1538 points += total_vertices;
1539 total_vertices += bezier_approximate(second_curve, points, deviation);
1540 return total_vertices;
1543 /***********************************************************************
1544 * wglUseFontOutlines_common
1546 static BOOL wglUseFontOutlines_common(HDC hdc,
1547 DWORD first,
1548 DWORD count,
1549 DWORD listBase,
1550 FLOAT deviation,
1551 FLOAT extrusion,
1552 int format,
1553 LPGLYPHMETRICSFLOAT lpgmf,
1554 BOOL unicode)
1556 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1557 UINT glyph;
1558 GLUtesselator *tess = NULL;
1559 LOGFONTW lf;
1560 HFONT old_font, unscaled_font;
1561 UINT em_size = 1024;
1562 RECT rc;
1564 TRACE("(%p, %d, %d, %d, %f, %f, %d, %p, %s)\n", hdc, first, count,
1565 listBase, deviation, extrusion, format, lpgmf, unicode ? "W" : "A");
1567 if(deviation <= 0.0)
1568 deviation = 1.0/em_size;
1570 if(format == WGL_FONT_POLYGONS)
1572 if (!load_libglu())
1574 ERR("glu32 is required for this function but isn't available\n");
1575 return FALSE;
1578 tess = pgluNewTess();
1579 if(!tess) return FALSE;
1580 pgluTessCallback(tess, GLU_TESS_VERTEX, (_GLUfuncptr)tess_callback_vertex);
1581 pgluTessCallback(tess, GLU_TESS_BEGIN, (_GLUfuncptr)tess_callback_begin);
1582 pgluTessCallback(tess, GLU_TESS_END, tess_callback_end);
1585 GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), &lf);
1586 rc.left = rc.right = rc.bottom = 0;
1587 rc.top = em_size;
1588 DPtoLP(hdc, (POINT*)&rc, 2);
1589 lf.lfHeight = -abs(rc.top - rc.bottom);
1590 lf.lfOrientation = lf.lfEscapement = 0;
1591 unscaled_font = CreateFontIndirectW(&lf);
1592 old_font = SelectObject(hdc, unscaled_font);
1594 for (glyph = first; glyph < first + count; glyph++)
1596 DWORD needed;
1597 GLYPHMETRICS gm;
1598 BYTE *buf;
1599 TTPOLYGONHEADER *pph;
1600 TTPOLYCURVE *ppc;
1601 GLdouble *vertices = NULL;
1602 int vertex_total = -1;
1604 if(unicode)
1605 needed = GetGlyphOutlineW(hdc, glyph, GGO_NATIVE, &gm, 0, NULL, &identity);
1606 else
1607 needed = GetGlyphOutlineA(hdc, glyph, GGO_NATIVE, &gm, 0, NULL, &identity);
1609 if(needed == GDI_ERROR)
1610 goto error;
1612 buf = HeapAlloc(GetProcessHeap(), 0, needed);
1614 if(unicode)
1615 GetGlyphOutlineW(hdc, glyph, GGO_NATIVE, &gm, needed, buf, &identity);
1616 else
1617 GetGlyphOutlineA(hdc, glyph, GGO_NATIVE, &gm, needed, buf, &identity);
1619 TRACE("glyph %d\n", glyph);
1621 if(lpgmf)
1623 lpgmf->gmfBlackBoxX = (float)gm.gmBlackBoxX / em_size;
1624 lpgmf->gmfBlackBoxY = (float)gm.gmBlackBoxY / em_size;
1625 lpgmf->gmfptGlyphOrigin.x = (float)gm.gmptGlyphOrigin.x / em_size;
1626 lpgmf->gmfptGlyphOrigin.y = (float)gm.gmptGlyphOrigin.y / em_size;
1627 lpgmf->gmfCellIncX = (float)gm.gmCellIncX / em_size;
1628 lpgmf->gmfCellIncY = (float)gm.gmCellIncY / em_size;
1630 TRACE("%fx%f at %f,%f inc %f,%f\n", lpgmf->gmfBlackBoxX, lpgmf->gmfBlackBoxY,
1631 lpgmf->gmfptGlyphOrigin.x, lpgmf->gmfptGlyphOrigin.y, lpgmf->gmfCellIncX, lpgmf->gmfCellIncY);
1632 lpgmf++;
1635 funcs->gl.p_glNewList(listBase++, GL_COMPILE);
1636 funcs->gl.p_glFrontFace(GL_CCW);
1637 if(format == WGL_FONT_POLYGONS)
1639 funcs->gl.p_glNormal3d(0.0, 0.0, 1.0);
1640 pgluTessNormal(tess, 0, 0, 1);
1641 pgluTessBeginPolygon(tess, NULL);
1644 while(!vertices)
1646 if(vertex_total != -1)
1647 vertices = HeapAlloc(GetProcessHeap(), 0, vertex_total * 3 * sizeof(GLdouble));
1648 vertex_total = 0;
1650 pph = (TTPOLYGONHEADER*)buf;
1651 while((BYTE*)pph < buf + needed)
1653 GLdouble previous[3];
1654 fixed_to_double(pph->pfxStart, em_size, previous);
1656 if(vertices)
1657 TRACE("\tstart %d, %d\n", pph->pfxStart.x.value, pph->pfxStart.y.value);
1659 if(format == WGL_FONT_POLYGONS)
1660 pgluTessBeginContour(tess);
1661 else
1662 funcs->gl.p_glBegin(GL_LINE_LOOP);
1664 if(vertices)
1666 fixed_to_double(pph->pfxStart, em_size, vertices);
1667 if(format == WGL_FONT_POLYGONS)
1668 pgluTessVertex(tess, vertices, vertices);
1669 else
1670 funcs->gl.p_glVertex3d(vertices[0], vertices[1], vertices[2]);
1671 vertices += 3;
1673 vertex_total++;
1675 ppc = (TTPOLYCURVE*)((char*)pph + sizeof(*pph));
1676 while((char*)ppc < (char*)pph + pph->cb)
1678 int i, j;
1679 int num;
1681 switch(ppc->wType) {
1682 case TT_PRIM_LINE:
1683 for(i = 0; i < ppc->cpfx; i++)
1685 if(vertices)
1687 TRACE("\t\tline to %d, %d\n",
1688 ppc->apfx[i].x.value, ppc->apfx[i].y.value);
1689 fixed_to_double(ppc->apfx[i], em_size, vertices);
1690 if(format == WGL_FONT_POLYGONS)
1691 pgluTessVertex(tess, vertices, vertices);
1692 else
1693 funcs->gl.p_glVertex3d(vertices[0], vertices[1], vertices[2]);
1694 vertices += 3;
1696 fixed_to_double(ppc->apfx[i], em_size, previous);
1697 vertex_total++;
1699 break;
1701 case TT_PRIM_QSPLINE:
1702 for(i = 0; i < ppc->cpfx-1; i++)
1704 bezier_vector curve[3];
1705 bezier_vector *points;
1706 GLdouble curve_vertex[3];
1708 if(vertices)
1709 TRACE("\t\tcurve %d,%d %d,%d\n",
1710 ppc->apfx[i].x.value, ppc->apfx[i].y.value,
1711 ppc->apfx[i + 1].x.value, ppc->apfx[i + 1].y.value);
1713 curve[0].x = previous[0];
1714 curve[0].y = previous[1];
1715 fixed_to_double(ppc->apfx[i], em_size, curve_vertex);
1716 curve[1].x = curve_vertex[0];
1717 curve[1].y = curve_vertex[1];
1718 fixed_to_double(ppc->apfx[i + 1], em_size, curve_vertex);
1719 curve[2].x = curve_vertex[0];
1720 curve[2].y = curve_vertex[1];
1721 if(i < ppc->cpfx-2)
1723 curve[2].x = (curve[1].x + curve[2].x)/2;
1724 curve[2].y = (curve[1].y + curve[2].y)/2;
1726 num = bezier_approximate(curve, NULL, deviation);
1727 points = HeapAlloc(GetProcessHeap(), 0, num*sizeof(bezier_vector));
1728 num = bezier_approximate(curve, points, deviation);
1729 vertex_total += num;
1730 if(vertices)
1732 for(j=0; j<num; j++)
1734 TRACE("\t\t\tvertex at %f,%f\n", points[j].x, points[j].y);
1735 vertices[0] = points[j].x;
1736 vertices[1] = points[j].y;
1737 vertices[2] = 0.0;
1738 if(format == WGL_FONT_POLYGONS)
1739 pgluTessVertex(tess, vertices, vertices);
1740 else
1741 funcs->gl.p_glVertex3d(vertices[0], vertices[1], vertices[2]);
1742 vertices += 3;
1745 HeapFree(GetProcessHeap(), 0, points);
1746 previous[0] = curve[2].x;
1747 previous[1] = curve[2].y;
1749 break;
1750 default:
1751 ERR("\t\tcurve type = %d\n", ppc->wType);
1752 if(format == WGL_FONT_POLYGONS)
1753 pgluTessEndContour(tess);
1754 else
1755 funcs->gl.p_glEnd();
1756 goto error_in_list;
1759 ppc = (TTPOLYCURVE*)((char*)ppc + sizeof(*ppc) +
1760 (ppc->cpfx - 1) * sizeof(POINTFX));
1762 if(format == WGL_FONT_POLYGONS)
1763 pgluTessEndContour(tess);
1764 else
1765 funcs->gl.p_glEnd();
1766 pph = (TTPOLYGONHEADER*)((char*)pph + pph->cb);
1770 error_in_list:
1771 if(format == WGL_FONT_POLYGONS)
1772 pgluTessEndPolygon(tess);
1773 funcs->gl.p_glTranslated((GLdouble)gm.gmCellIncX / em_size, (GLdouble)gm.gmCellIncY / em_size, 0.0);
1774 funcs->gl.p_glEndList();
1775 HeapFree(GetProcessHeap(), 0, buf);
1776 HeapFree(GetProcessHeap(), 0, vertices);
1779 error:
1780 DeleteObject(SelectObject(hdc, old_font));
1781 if(format == WGL_FONT_POLYGONS)
1782 pgluDeleteTess(tess);
1783 return TRUE;
1787 /***********************************************************************
1788 * wglUseFontOutlinesA (OPENGL32.@)
1790 BOOL WINAPI wglUseFontOutlinesA(HDC hdc,
1791 DWORD first,
1792 DWORD count,
1793 DWORD listBase,
1794 FLOAT deviation,
1795 FLOAT extrusion,
1796 int format,
1797 LPGLYPHMETRICSFLOAT lpgmf)
1799 return wglUseFontOutlines_common(hdc, first, count, listBase, deviation, extrusion, format, lpgmf, FALSE);
1802 /***********************************************************************
1803 * wglUseFontOutlinesW (OPENGL32.@)
1805 BOOL WINAPI wglUseFontOutlinesW(HDC hdc,
1806 DWORD first,
1807 DWORD count,
1808 DWORD listBase,
1809 FLOAT deviation,
1810 FLOAT extrusion,
1811 int format,
1812 LPGLYPHMETRICSFLOAT lpgmf)
1814 return wglUseFontOutlines_common(hdc, first, count, listBase, deviation, extrusion, format, lpgmf, TRUE);
1817 /***********************************************************************
1818 * glDebugEntry (OPENGL32.@)
1820 GLint WINAPI glDebugEntry( GLint unknown1, GLint unknown2 )
1822 return 0;
1825 static GLubyte *filter_extensions_list(const char *extensions, const char *disabled)
1827 char *p, *str;
1828 const char *end;
1830 p = str = HeapAlloc(GetProcessHeap(), 0, strlen(extensions) + 2);
1831 if (!str)
1832 return NULL;
1834 TRACE( "GL_EXTENSIONS:\n" );
1836 for (;;)
1838 while (*extensions == ' ')
1839 extensions++;
1840 if (!*extensions)
1841 break;
1842 if (!(end = strchr(extensions, ' ')))
1843 end = extensions + strlen(extensions);
1844 memcpy(p, extensions, end - extensions);
1845 p[end - extensions] = 0;
1846 if (!has_extension(disabled, p, strlen(p)))
1848 TRACE("++ %s\n", p);
1849 p += end - extensions;
1850 *p++ = ' ';
1852 else
1854 TRACE("-- %s (disabled by config)\n", p);
1856 extensions = end;
1858 *p = 0;
1859 return (GLubyte *)str;
1862 static GLuint *filter_extensions_index(const char *disabled)
1864 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1865 const char *ext, *end, *gl_ext;
1866 GLuint *disabled_exts, *new_disabled_exts;
1867 unsigned int i = 0, j, disabled_size;
1868 GLint extensions_count;
1870 if (!funcs->ext.p_glGetStringi)
1872 void **func_ptr = (void **)&funcs->ext.p_glGetStringi;
1874 *func_ptr = funcs->wgl.p_wglGetProcAddress("glGetStringi");
1875 if (!funcs->ext.p_glGetStringi)
1876 return NULL;
1879 funcs->gl.p_glGetIntegerv(GL_NUM_EXTENSIONS, &extensions_count);
1880 disabled_size = 2;
1881 disabled_exts = HeapAlloc(GetProcessHeap(), 0, disabled_size * sizeof(*disabled_exts));
1882 if (!disabled_exts)
1883 return NULL;
1885 TRACE( "GL_EXTENSIONS:\n" );
1887 for (j = 0; j < extensions_count; ++j)
1889 gl_ext = (const char *)funcs->ext.p_glGetStringi(GL_EXTENSIONS, j);
1890 ext = disabled;
1891 for (;;)
1893 while (*ext == ' ')
1894 ext++;
1895 if (!*ext)
1897 TRACE("++ %s\n", gl_ext);
1898 break;
1900 if (!(end = strchr(ext, ' ')))
1901 end = ext + strlen(ext);
1903 if (!strncmp(gl_ext, ext, end - ext) && !gl_ext[end - ext])
1905 if (i + 1 == disabled_size)
1907 disabled_size *= 2;
1908 new_disabled_exts = HeapReAlloc(GetProcessHeap(), 0, disabled_exts,
1909 disabled_size * sizeof(*disabled_exts));
1910 if (!new_disabled_exts)
1912 disabled_exts[i] = ~0u;
1913 return disabled_exts;
1915 disabled_exts = new_disabled_exts;
1917 TRACE("-- %s (disabled by config)\n", gl_ext);
1918 disabled_exts[i++] = j;
1919 break;
1921 ext = end;
1924 disabled_exts[i] = ~0u;
1925 return disabled_exts;
1928 /* build the extension string by filtering out the disabled extensions */
1929 static BOOL filter_extensions(const char *extensions, GLubyte **exts_list, GLuint **disabled_exts)
1931 static const char *disabled;
1933 if (!disabled)
1935 HKEY hkey;
1936 DWORD size;
1937 char *str = NULL;
1939 /* @@ Wine registry key: HKCU\Software\Wine\OpenGL */
1940 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\OpenGL", &hkey ))
1942 if (!RegQueryValueExA( hkey, "DisabledExtensions", 0, NULL, NULL, &size ))
1944 str = HeapAlloc( GetProcessHeap(), 0, size );
1945 if (RegQueryValueExA( hkey, "DisabledExtensions", 0, NULL, (BYTE *)str, &size )) *str = 0;
1947 RegCloseKey( hkey );
1949 if (str)
1951 if (InterlockedCompareExchangePointer( (void **)&disabled, str, NULL ))
1952 HeapFree( GetProcessHeap(), 0, str );
1954 else disabled = "";
1957 if (!disabled[0])
1958 return FALSE;
1960 if (extensions && !*exts_list)
1961 *exts_list = filter_extensions_list(extensions, disabled);
1963 if (!*disabled_exts)
1964 *disabled_exts = filter_extensions_index(disabled);
1966 return (exts_list && *exts_list) || *disabled_exts;
1969 /***********************************************************************
1970 * glGetString (OPENGL32.@)
1972 const GLubyte * WINAPI glGetString( GLenum name )
1974 const struct opengl_funcs *funcs = NtCurrentTeb()->glTable;
1975 const GLubyte *ret = funcs->gl.p_glGetString( name );
1977 if (name == GL_EXTENSIONS && ret)
1979 struct wgl_handle *ptr = get_current_context_ptr();
1980 if (ptr->u.context->extensions ||
1981 filter_extensions((const char *)ret, &ptr->u.context->extensions, &ptr->u.context->disabled_exts))
1982 ret = ptr->u.context->extensions;
1984 return ret;
1987 /***********************************************************************
1988 * OpenGL initialisation routine
1990 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
1992 switch(reason)
1994 case DLL_PROCESS_ATTACH:
1995 NtCurrentTeb()->glTable = &null_opengl_funcs;
1996 break;
1997 case DLL_THREAD_ATTACH:
1998 NtCurrentTeb()->glTable = &null_opengl_funcs;
1999 break;
2001 return TRUE;