1 /* Window-specific OpenGL functions implementation.
3 * Copyright (c) 1999 Lionel Ulmer
4 * Copyright (c) 2005 Raphael Junqueira
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
36 #include "opengl_ext.h"
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(opengl
);
46 static HMODULE opengl32_handle
;
48 extern struct opengl_funcs null_opengl_funcs
;
50 const GLubyte
* WINAPI
wine_glGetString( GLenum name
);
52 /* internal GDI functions */
53 extern INT WINAPI
GdiDescribePixelFormat( HDC hdc
, INT fmt
, UINT size
, PIXELFORMATDESCRIPTOR
*pfd
);
54 extern BOOL WINAPI
GdiSetPixelFormat( HDC hdc
, INT fmt
, const PIXELFORMATDESCRIPTOR
*pfd
);
55 extern BOOL WINAPI
GdiSwapBuffers( HDC hdc
);
57 /* handle management */
59 #define MAX_WGL_HANDLES 1024
63 HANDLE_CONTEXT
= 0 << 12,
64 HANDLE_PBUFFER
= 1 << 12,
65 HANDLE_TYPE_MASK
= 15 << 12
72 struct opengl_funcs
*funcs
;
75 struct wgl_context
*context
; /* for HANDLE_CONTEXT */
76 struct wgl_pbuffer
*pbuffer
; /* for HANDLE_PBUFFER */
77 struct wgl_handle
*next
; /* for free handles */
81 static struct wgl_handle wgl_handles
[MAX_WGL_HANDLES
];
82 static struct wgl_handle
*next_free
;
83 static unsigned int handle_count
;
85 static CRITICAL_SECTION wgl_section
;
86 static CRITICAL_SECTION_DEBUG critsect_debug
=
89 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
90 0, 0, { (DWORD_PTR
)(__FILE__
": wgl_section") }
92 static CRITICAL_SECTION wgl_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
94 static inline struct opengl_funcs
*get_dc_funcs( HDC hdc
)
96 struct opengl_funcs
*funcs
= __wine_get_wgl_driver( hdc
, WINE_WGL_DRIVER_VERSION
);
97 if (funcs
== (void *)-1) funcs
= &null_opengl_funcs
;
101 static inline HANDLE
next_handle( struct wgl_handle
*ptr
, enum wgl_handle_type type
)
103 WORD generation
= HIWORD( ptr
->handle
) + 1;
104 if (!generation
) generation
++;
105 ptr
->handle
= MAKELONG( ptr
- wgl_handles
, generation
) | type
;
106 return ULongToHandle( ptr
->handle
);
109 /* the current context is assumed valid and doesn't need locking */
110 static inline struct wgl_handle
*get_current_context_ptr(void)
112 if (!NtCurrentTeb()->glCurrentRC
) return NULL
;
113 return &wgl_handles
[LOWORD(NtCurrentTeb()->glCurrentRC
) & ~HANDLE_TYPE_MASK
];
116 static struct wgl_handle
*get_handle_ptr( HANDLE handle
, enum wgl_handle_type type
)
118 unsigned int index
= LOWORD( handle
) & ~HANDLE_TYPE_MASK
;
120 EnterCriticalSection( &wgl_section
);
121 if (index
< handle_count
&& ULongToHandle(wgl_handles
[index
].handle
) == handle
)
122 return &wgl_handles
[index
];
124 LeaveCriticalSection( &wgl_section
);
125 SetLastError( ERROR_INVALID_HANDLE
);
129 static void release_handle_ptr( struct wgl_handle
*ptr
)
131 if (ptr
) LeaveCriticalSection( &wgl_section
);
134 static HANDLE
alloc_handle( enum wgl_handle_type type
, struct opengl_funcs
*funcs
, void *user_ptr
)
137 struct wgl_handle
*ptr
= NULL
;
139 EnterCriticalSection( &wgl_section
);
140 if ((ptr
= next_free
))
141 next_free
= next_free
->u
.next
;
142 else if (handle_count
< MAX_WGL_HANDLES
)
143 ptr
= &wgl_handles
[handle_count
++];
148 ptr
->u
.context
= user_ptr
;
149 handle
= next_handle( ptr
, type
);
151 else SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
152 LeaveCriticalSection( &wgl_section
);
156 static void free_handle_ptr( struct wgl_handle
*ptr
)
158 ptr
->handle
|= 0xffff;
159 ptr
->u
.next
= next_free
;
162 LeaveCriticalSection( &wgl_section
);
165 /***********************************************************************
166 * wglSetPixelFormat(OPENGL32.@)
168 BOOL WINAPI
wglSetPixelFormat( HDC hdc
, INT iPixelFormat
,
169 const PIXELFORMATDESCRIPTOR
*ppfd
)
171 return GdiSetPixelFormat(hdc
, iPixelFormat
, ppfd
);
174 /***********************************************************************
175 * wglCopyContext (OPENGL32.@)
177 BOOL WINAPI
wglCopyContext(HGLRC hglrcSrc
, HGLRC hglrcDst
, UINT mask
)
179 struct wgl_handle
*src
, *dst
;
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
, dst
->u
.context
, mask
);
188 release_handle_ptr( dst
);
189 release_handle_ptr( src
);
193 /***********************************************************************
194 * wglDeleteContext (OPENGL32.@)
196 BOOL WINAPI
wglDeleteContext(HGLRC hglrc
)
198 struct wgl_handle
*ptr
= get_handle_ptr( hglrc
, HANDLE_CONTEXT
);
200 if (!ptr
) return FALSE
;
202 if (ptr
->tid
&& ptr
->tid
!= GetCurrentThreadId())
204 SetLastError( ERROR_BUSY
);
205 release_handle_ptr( ptr
);
208 if (hglrc
== NtCurrentTeb()->glCurrentRC
) wglMakeCurrent( 0, 0 );
209 ptr
->funcs
->wgl
.p_wglDeleteContext( ptr
->u
.context
);
210 free_handle_ptr( ptr
);
214 /***********************************************************************
215 * wglMakeCurrent (OPENGL32.@)
217 BOOL WINAPI
wglMakeCurrent(HDC hdc
, HGLRC hglrc
)
220 struct wgl_handle
*ptr
, *prev
= get_current_context_ptr();
224 if (!(ptr
= get_handle_ptr( hglrc
, HANDLE_CONTEXT
))) return FALSE
;
225 if (!ptr
->tid
|| ptr
->tid
== GetCurrentThreadId())
227 ret
= ptr
->funcs
->wgl
.p_wglMakeCurrent( hdc
, ptr
->u
.context
);
230 if (prev
) prev
->tid
= 0;
231 ptr
->tid
= GetCurrentThreadId();
232 NtCurrentTeb()->glCurrentRC
= hglrc
;
233 NtCurrentTeb()->glTable
= ptr
->funcs
;
238 SetLastError( ERROR_BUSY
);
241 release_handle_ptr( ptr
);
245 if (!prev
->funcs
->wgl
.p_wglMakeCurrent( 0, NULL
)) return FALSE
;
247 NtCurrentTeb()->glCurrentRC
= 0;
248 NtCurrentTeb()->glTable
= &null_opengl_funcs
;
252 SetLastError( ERROR_INVALID_HANDLE
);
258 /***********************************************************************
259 * wglCreateContextAttribsARB
261 * Provided by the WGL_ARB_create_context extension.
263 HGLRC WINAPI
wglCreateContextAttribsARB( HDC hdc
, HGLRC share
, const int *attribs
)
266 struct wgl_context
*context
;
267 struct wgl_handle
*share_ptr
= NULL
;
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 ((context
= funcs
->ext
.p_wglCreateContextAttribsARB( hdc
, share_ptr
? share_ptr
->u
.context
: NULL
,
275 ret
= alloc_handle( HANDLE_CONTEXT
, funcs
, context
);
276 if (!ret
) funcs
->wgl
.p_wglDeleteContext( context
);
278 release_handle_ptr( share_ptr
);
283 /***********************************************************************
284 * wglMakeContextCurrentARB
286 * Provided by the WGL_ARB_make_current_read extension.
288 BOOL WINAPI
wglMakeContextCurrentARB( HDC draw_hdc
, HDC read_hdc
, HGLRC hglrc
)
291 struct wgl_handle
*ptr
, *prev
= get_current_context_ptr();
295 if (!(ptr
= get_handle_ptr( hglrc
, HANDLE_CONTEXT
))) return FALSE
;
296 if (!ptr
->tid
|| ptr
->tid
== GetCurrentThreadId())
298 ret
= (ptr
->funcs
->ext
.p_wglMakeContextCurrentARB
&&
299 ptr
->funcs
->ext
.p_wglMakeContextCurrentARB( draw_hdc
, read_hdc
, ptr
->u
.context
));
302 if (prev
) prev
->tid
= 0;
303 ptr
->tid
= GetCurrentThreadId();
304 NtCurrentTeb()->glCurrentRC
= hglrc
;
305 NtCurrentTeb()->glTable
= ptr
->funcs
;
310 SetLastError( ERROR_BUSY
);
313 release_handle_ptr( ptr
);
317 if (!prev
->funcs
->wgl
.p_wglMakeCurrent( 0, NULL
)) return FALSE
;
319 NtCurrentTeb()->glCurrentRC
= 0;
320 NtCurrentTeb()->glTable
= &null_opengl_funcs
;
325 /***********************************************************************
326 * wglGetCurrentReadDCARB
328 * Provided by the WGL_ARB_make_current_read extension.
330 HDC WINAPI
wglGetCurrentReadDCARB(void)
332 const struct opengl_funcs
*funcs
= NtCurrentTeb()->glTable
;
334 if (!funcs
->ext
.p_wglGetCurrentReadDCARB
) return 0;
335 return funcs
->ext
.p_wglGetCurrentReadDCARB();
338 /***********************************************************************
339 * wglShareLists (OPENGL32.@)
341 BOOL WINAPI
wglShareLists(HGLRC hglrcSrc
, HGLRC hglrcDst
)
344 struct wgl_handle
*src
, *dst
;
346 if (!(src
= get_handle_ptr( hglrcSrc
, HANDLE_CONTEXT
))) return FALSE
;
347 if ((dst
= get_handle_ptr( hglrcDst
, HANDLE_CONTEXT
)))
349 if (src
->funcs
!= dst
->funcs
) SetLastError( ERROR_INVALID_HANDLE
);
350 else ret
= src
->funcs
->wgl
.p_wglShareLists( src
->u
.context
, dst
->u
.context
);
352 release_handle_ptr( dst
);
353 release_handle_ptr( src
);
357 /***********************************************************************
358 * wglGetCurrentDC (OPENGL32.@)
360 HDC WINAPI
wglGetCurrentDC(void)
362 struct wgl_handle
*context
= get_current_context_ptr();
363 if (!context
) return 0;
364 return context
->funcs
->wgl
.p_wglGetCurrentDC( context
->u
.context
);
367 /***********************************************************************
368 * wglCreateContext (OPENGL32.@)
370 HGLRC WINAPI
wglCreateContext(HDC hdc
)
373 struct wgl_context
*context
;
374 struct opengl_funcs
*funcs
= get_dc_funcs( hdc
);
376 if (!funcs
) return 0;
377 if (!(context
= funcs
->wgl
.p_wglCreateContext( hdc
))) return 0;
378 ret
= alloc_handle( HANDLE_CONTEXT
, funcs
, context
);
379 if (!ret
) funcs
->wgl
.p_wglDeleteContext( context
);
383 /***********************************************************************
384 * wglGetCurrentContext (OPENGL32.@)
386 HGLRC WINAPI
wglGetCurrentContext(void)
388 return NtCurrentTeb()->glCurrentRC
;
391 /***********************************************************************
392 * wglChoosePixelFormat (OPENGL32.@)
394 INT WINAPI
wglChoosePixelFormat(HDC hdc
, const PIXELFORMATDESCRIPTOR
* ppfd
)
396 PIXELFORMATDESCRIPTOR format
, best
;
397 int i
, count
, best_format
;
398 int bestDBuffer
= -1, bestStereo
= -1;
400 TRACE_(wgl
)( "%p %p: size %u version %u flags %u type %u color %u %u,%u,%u,%u "
401 "accum %u depth %u stencil %u aux %u\n",
402 hdc
, ppfd
, ppfd
->nSize
, ppfd
->nVersion
, ppfd
->dwFlags
, ppfd
->iPixelType
,
403 ppfd
->cColorBits
, ppfd
->cRedBits
, ppfd
->cGreenBits
, ppfd
->cBlueBits
, ppfd
->cAlphaBits
,
404 ppfd
->cAccumBits
, ppfd
->cDepthBits
, ppfd
->cStencilBits
, ppfd
->cAuxBuffers
);
406 count
= GdiDescribePixelFormat( hdc
, 0, 0, NULL
);
407 if (!count
) return 0;
411 best
.cAlphaBits
= -1;
412 best
.cColorBits
= -1;
413 best
.cDepthBits
= -1;
414 best
.cStencilBits
= -1;
415 best
.cAuxBuffers
= -1;
417 for (i
= 1; i
<= count
; i
++)
419 if (!GdiDescribePixelFormat( hdc
, i
, sizeof(format
), &format
)) continue;
421 if (ppfd
->iPixelType
!= format
.iPixelType
)
423 TRACE( "pixel type mismatch for iPixelFormat=%d\n", i
);
427 /* only use bitmap capable for formats for bitmap rendering */
428 if( (ppfd
->dwFlags
& PFD_DRAW_TO_BITMAP
) != (format
.dwFlags
& PFD_DRAW_TO_BITMAP
))
430 TRACE( "PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i
);
434 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
435 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
436 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
437 * formats without the given flag set.
438 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
439 * has indicated that a format without stereo is returned when stereo is unavailable.
440 * So in case PFD_STEREO is set, formats that support it should have priority above formats
441 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
443 * To summarize the following is most likely the correct behavior:
444 * stereo not set -> prefer non-stereo formats, but also accept stereo formats
445 * stereo set -> prefer stereo formats, but also accept non-stereo formats
446 * stereo don't care -> it doesn't matter whether we get stereo or not
448 * In Wine we will treat non-stereo the same way as don't care because it makes
449 * format selection even more complicated and second drivers with Stereo advertise
450 * each format twice anyway.
453 /* Doublebuffer, see the comments above */
454 if (!(ppfd
->dwFlags
& PFD_DOUBLEBUFFER_DONTCARE
))
456 if (((ppfd
->dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) &&
457 ((format
.dwFlags
& PFD_DOUBLEBUFFER
) == (ppfd
->dwFlags
& PFD_DOUBLEBUFFER
)))
460 if (bestDBuffer
!= -1 && (format
.dwFlags
& PFD_DOUBLEBUFFER
) != bestDBuffer
) continue;
463 /* Stereo, see the comments above. */
464 if (!(ppfd
->dwFlags
& PFD_STEREO_DONTCARE
))
466 if (((ppfd
->dwFlags
& PFD_STEREO
) != bestStereo
) &&
467 ((format
.dwFlags
& PFD_STEREO
) == (ppfd
->dwFlags
& PFD_STEREO
)))
470 if (bestStereo
!= -1 && (format
.dwFlags
& PFD_STEREO
) != bestStereo
) continue;
473 /* Below we will do a number of checks to select the 'best' pixelformat.
474 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
475 * The code works by trying to match the most important options as close as possible.
476 * When a reasonable format is found, we will try to match more options.
477 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
478 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
479 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
481 if (ppfd
->cColorBits
)
483 if (((ppfd
->cColorBits
> best
.cColorBits
) && (format
.cColorBits
> best
.cColorBits
)) ||
484 ((format
.cColorBits
>= ppfd
->cColorBits
) && (format
.cColorBits
< best
.cColorBits
)))
487 if (best
.cColorBits
!= format
.cColorBits
) /* Do further checks if the format is compatible */
489 TRACE( "color mismatch for iPixelFormat=%d\n", i
);
493 if (ppfd
->cAlphaBits
)
495 if (((ppfd
->cAlphaBits
> best
.cAlphaBits
) && (format
.cAlphaBits
> best
.cAlphaBits
)) ||
496 ((format
.cAlphaBits
>= ppfd
->cAlphaBits
) && (format
.cAlphaBits
< best
.cAlphaBits
)))
499 if (best
.cAlphaBits
!= format
.cAlphaBits
)
501 TRACE( "alpha mismatch for iPixelFormat=%d\n", i
);
505 if (ppfd
->cDepthBits
)
507 if (((ppfd
->cDepthBits
> best
.cDepthBits
) && (format
.cDepthBits
> best
.cDepthBits
)) ||
508 ((format
.cDepthBits
>= ppfd
->cDepthBits
) && (format
.cDepthBits
< best
.cDepthBits
)))
511 if (best
.cDepthBits
!= format
.cDepthBits
)
513 TRACE( "depth mismatch for iPixelFormat=%d\n", i
);
517 if (ppfd
->cStencilBits
)
519 if (((ppfd
->cStencilBits
> best
.cStencilBits
) && (format
.cStencilBits
> best
.cStencilBits
)) ||
520 ((format
.cStencilBits
>= ppfd
->cStencilBits
) && (format
.cStencilBits
< best
.cStencilBits
)))
523 if (best
.cStencilBits
!= format
.cStencilBits
)
525 TRACE( "stencil mismatch for iPixelFormat=%d\n", i
);
529 if (ppfd
->cAuxBuffers
)
531 if (((ppfd
->cAuxBuffers
> best
.cAuxBuffers
) && (format
.cAuxBuffers
> best
.cAuxBuffers
)) ||
532 ((format
.cAuxBuffers
>= ppfd
->cAuxBuffers
) && (format
.cAuxBuffers
< best
.cAuxBuffers
)))
535 if (best
.cAuxBuffers
!= format
.cAuxBuffers
)
537 TRACE( "aux mismatch for iPixelFormat=%d\n", i
);
546 bestDBuffer
= format
.dwFlags
& PFD_DOUBLEBUFFER
;
547 bestStereo
= format
.dwFlags
& PFD_STEREO
;
550 TRACE( "returning %u\n", best_format
);
554 /***********************************************************************
555 * wglDescribePixelFormat (OPENGL32.@)
557 INT WINAPI
wglDescribePixelFormat(HDC hdc
, INT iPixelFormat
, UINT nBytes
,
558 LPPIXELFORMATDESCRIPTOR ppfd
)
560 return GdiDescribePixelFormat(hdc
, iPixelFormat
, nBytes
, ppfd
);
563 /***********************************************************************
564 * wglGetPixelFormat (OPENGL32.@)
566 INT WINAPI
wglGetPixelFormat(HDC hdc
)
568 struct opengl_funcs
*funcs
= get_dc_funcs( hdc
);
569 if (!funcs
) return 0;
570 return funcs
->wgl
.p_wglGetPixelFormat( hdc
);
573 /***********************************************************************
574 * wglCreateLayerContext (OPENGL32.@)
576 HGLRC WINAPI
wglCreateLayerContext(HDC hdc
,
578 TRACE("(%p,%d)\n", hdc
, iLayerPlane
);
580 if (iLayerPlane
== 0) {
581 return wglCreateContext(hdc
);
583 FIXME("no handler for layer %d\n", iLayerPlane
);
588 /***********************************************************************
589 * wglDescribeLayerPlane (OPENGL32.@)
591 BOOL WINAPI
wglDescribeLayerPlane(HDC hdc
,
595 LPLAYERPLANEDESCRIPTOR plpd
) {
596 FIXME("(%p,%d,%d,%d,%p)\n", hdc
, iPixelFormat
, iLayerPlane
, nBytes
, plpd
);
601 /***********************************************************************
602 * wglGetLayerPaletteEntries (OPENGL32.@)
604 int WINAPI
wglGetLayerPaletteEntries(HDC hdc
,
608 const COLORREF
*pcr
) {
609 FIXME("(): stub!\n");
614 /* check if the extension is present in the list */
615 static BOOL
has_extension( const char *list
, const char *ext
)
617 size_t len
= strlen( ext
);
621 while (*list
== ' ') list
++;
622 if (!strncmp( list
, ext
, len
) && (!list
[len
] || list
[len
] == ' ')) return TRUE
;
623 list
= strchr( list
, ' ' );
628 static int compar(const void *elt_a
, const void *elt_b
) {
629 return strcmp(((const OpenGL_extension
*) elt_a
)->name
,
630 ((const OpenGL_extension
*) elt_b
)->name
);
633 /* Check if a GL extension is supported */
634 static BOOL
is_extension_supported(const char* extension
)
636 const struct opengl_funcs
*funcs
= NtCurrentTeb()->glTable
;
637 const char *gl_ext_string
= (const char*)wine_glGetString(GL_EXTENSIONS
);
639 TRACE("Checking for extension '%s'\n", extension
);
642 ERR("No OpenGL extensions found, check if your OpenGL setup is correct!\n");
646 /* We use the GetProcAddress function from the display driver to retrieve function pointers
647 * for OpenGL and WGL extensions. In case of winex11.drv the OpenGL extension lookup is done
648 * using glXGetProcAddress. This function is quite unreliable in the sense that its specs don't
649 * require the function to return NULL when an extension isn't found. For this reason we check
650 * if the OpenGL extension required for the function we are looking up is supported. */
652 /* Check if the extension is part of the GL extension string to see if it is supported. */
653 if (has_extension(gl_ext_string
, extension
))
656 /* In general an OpenGL function starts as an ARB/EXT extension and at some stage
657 * it becomes part of the core OpenGL library and can be reached without the ARB/EXT
658 * suffix as well. In the extension table, these functions contain GL_VERSION_major_minor.
659 * Check if we are searching for a core GL function */
660 if(strncmp(extension
, "GL_VERSION_", 11) == 0)
662 const GLubyte
*gl_version
= funcs
->gl
.p_glGetString(GL_VERSION
);
663 const char *version
= extension
+ 11; /* Move past 'GL_VERSION_' */
666 ERR("No OpenGL version found!\n");
670 /* Compare the major/minor version numbers of the native OpenGL library and what is required by the function.
671 * The gl_version string is guaranteed to have at least a major/minor and sometimes it has a release number as well. */
672 if( (gl_version
[0] >= version
[0]) || ((gl_version
[0] == version
[0]) && (gl_version
[2] >= version
[2])) ) {
675 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]);
681 /***********************************************************************
682 * wglGetProcAddress (OPENGL32.@)
684 PROC WINAPI
wglGetProcAddress(LPCSTR lpszProc
)
686 struct opengl_funcs
*funcs
= NtCurrentTeb()->glTable
;
689 OpenGL_extension ext
;
690 const OpenGL_extension
*ext_ret
;
691 struct wgl_handle
*context
= get_current_context_ptr();
693 TRACE("(%s)\n", lpszProc
);
695 if (lpszProc
== NULL
)
698 /* Without an active context opengl32 doesn't know to what
699 * driver it has to dispatch wglGetProcAddress.
703 WARN("No active WGL context found\n");
707 /* Search in the thunks to find the real name of the extension */
709 ext_ret
= bsearch(&ext
, extension_registry
, extension_registry_size
,
710 sizeof(OpenGL_extension
), compar
);
713 WARN("Extension '%s' not defined in opengl32.dll's function table!\n", lpszProc
);
717 func_ptr
= (void **)&funcs
->ext
+ (ext_ret
- extension_registry
);
720 /* Check if the GL extension required by the function is available */
721 if(!is_extension_supported(ext_ret
->extension
)) {
722 WARN("Extension '%s' required by function '%s' not supported!\n", ext_ret
->extension
, lpszProc
);
725 local_func
= context
->funcs
->wgl
.p_wglGetProcAddress( ext_ret
->name
);
727 /* After that, look at the extensions defined in the Linux OpenGL library */
728 if (local_func
== NULL
) {
732 /* Remove the last 3 letters (EXT, ARB, ...).
734 I know that some extensions have more than 3 letters (MESA, NV,
735 INTEL, ...), but this is only a stop-gap measure to fix buggy
736 OpenGL drivers (moreover, it is only useful for old 1.0 apps
737 that query the glBindTextureEXT extension).
739 memcpy(buf
, ext_ret
->name
, strlen(ext_ret
->name
) - 3);
740 buf
[strlen(ext_ret
->name
) - 3] = '\0';
741 TRACE("Extension not found in the Linux OpenGL library, checking against libGL bug with %s..\n", buf
);
743 ret
= GetProcAddress(opengl32_handle
, buf
);
745 TRACE("Found function in main OpenGL library (%p)!\n", ret
);
747 WARN("Did not find function %s (%s) in your OpenGL library!\n", lpszProc
, ext_ret
->name
);
752 *func_ptr
= local_func
;
755 TRACE("returning function (%p)\n", ext_ret
->func
);
756 return ext_ret
->func
;
759 /***********************************************************************
760 * wglRealizeLayerPalette (OPENGL32.@)
762 BOOL WINAPI
wglRealizeLayerPalette(HDC hdc
,
770 /***********************************************************************
771 * wglSetLayerPaletteEntries (OPENGL32.@)
773 int WINAPI
wglSetLayerPaletteEntries(HDC hdc
,
777 const COLORREF
*pcr
) {
778 FIXME("(): stub!\n");
783 /***********************************************************************
784 * wglSwapLayerBuffers (OPENGL32.@)
786 BOOL WINAPI
wglSwapLayerBuffers(HDC hdc
,
788 TRACE_(opengl
)("(%p, %08x)\n", hdc
, fuPlanes
);
790 if (fuPlanes
& WGL_SWAP_MAIN_PLANE
) {
791 if (!GdiSwapBuffers(hdc
)) return FALSE
;
792 fuPlanes
&= ~WGL_SWAP_MAIN_PLANE
;
796 WARN("Following layers unhandled: %08x\n", fuPlanes
);
802 /***********************************************************************
803 * wglAllocateMemoryNV
805 * Provided by the WGL_NV_vertex_array_range extension.
807 void * WINAPI
wglAllocateMemoryNV( GLsizei size
, GLfloat readfreq
, GLfloat writefreq
, GLfloat priority
)
809 const struct opengl_funcs
*funcs
= NtCurrentTeb()->glTable
;
811 if (!funcs
->ext
.p_wglAllocateMemoryNV
) return NULL
;
812 return funcs
->ext
.p_wglAllocateMemoryNV( size
, readfreq
, writefreq
, priority
);
815 /***********************************************************************
818 * Provided by the WGL_NV_vertex_array_range extension.
820 void WINAPI
wglFreeMemoryNV( void *pointer
)
822 const struct opengl_funcs
*funcs
= NtCurrentTeb()->glTable
;
824 if (funcs
->ext
.p_wglFreeMemoryNV
) funcs
->ext
.p_wglFreeMemoryNV( pointer
);
827 /***********************************************************************
830 * Provided by the WGL_ARB_render_texture extension.
832 BOOL WINAPI
wglBindTexImageARB( HPBUFFERARB handle
, int buffer
)
834 struct wgl_handle
*ptr
= get_handle_ptr( handle
, HANDLE_PBUFFER
);
837 if (!ptr
) return FALSE
;
838 ret
= ptr
->funcs
->ext
.p_wglBindTexImageARB( ptr
->u
.pbuffer
, buffer
);
839 release_handle_ptr( ptr
);
843 /***********************************************************************
844 * wglReleaseTexImageARB
846 * Provided by the WGL_ARB_render_texture extension.
848 BOOL WINAPI
wglReleaseTexImageARB( HPBUFFERARB handle
, int buffer
)
850 struct wgl_handle
*ptr
= get_handle_ptr( handle
, HANDLE_PBUFFER
);
853 if (!ptr
) return FALSE
;
854 ret
= ptr
->funcs
->ext
.p_wglReleaseTexImageARB( ptr
->u
.pbuffer
, buffer
);
855 release_handle_ptr( ptr
);
859 /***********************************************************************
860 * wglSetPbufferAttribARB
862 * Provided by the WGL_ARB_render_texture extension.
864 BOOL WINAPI
wglSetPbufferAttribARB( HPBUFFERARB handle
, const int *attribs
)
866 struct wgl_handle
*ptr
= get_handle_ptr( handle
, HANDLE_PBUFFER
);
869 if (!ptr
) return FALSE
;
870 ret
= ptr
->funcs
->ext
.p_wglSetPbufferAttribARB( ptr
->u
.pbuffer
, attribs
);
871 release_handle_ptr( ptr
);
875 /***********************************************************************
876 * wglChoosePixelFormatARB
878 * Provided by the WGL_ARB_pixel_format extension.
880 BOOL WINAPI
wglChoosePixelFormatARB( HDC hdc
, const int *iattribs
, const FLOAT
*fattribs
,
881 UINT max
, int *formats
, UINT
*count
)
883 const struct opengl_funcs
*funcs
= get_dc_funcs( hdc
);
885 if (!funcs
|| !funcs
->ext
.p_wglChoosePixelFormatARB
) return FALSE
;
886 return funcs
->ext
.p_wglChoosePixelFormatARB( hdc
, iattribs
, fattribs
, max
, formats
, count
);
889 /***********************************************************************
890 * wglGetPixelFormatAttribivARB
892 * Provided by the WGL_ARB_pixel_format extension.
894 BOOL WINAPI
wglGetPixelFormatAttribivARB( HDC hdc
, int format
, int layer
, UINT count
, const int *attribs
,
897 const struct opengl_funcs
*funcs
= get_dc_funcs( hdc
);
899 if (!funcs
|| !funcs
->ext
.p_wglGetPixelFormatAttribivARB
) return FALSE
;
900 return funcs
->ext
.p_wglGetPixelFormatAttribivARB( hdc
, format
, layer
, count
, attribs
, values
);
903 /***********************************************************************
904 * wglGetPixelFormatAttribfvARB
906 * Provided by the WGL_ARB_pixel_format extension.
908 BOOL WINAPI
wglGetPixelFormatAttribfvARB( HDC hdc
, int format
, int layer
, UINT count
, const int *attribs
,
911 const struct opengl_funcs
*funcs
= get_dc_funcs( hdc
);
913 if (!funcs
|| !funcs
->ext
.p_wglGetPixelFormatAttribfvARB
) return FALSE
;
914 return funcs
->ext
.p_wglGetPixelFormatAttribfvARB( hdc
, format
, layer
, count
, attribs
, values
);
917 /***********************************************************************
918 * wglCreatePbufferARB
920 * Provided by the WGL_ARB_pbuffer extension.
922 HPBUFFERARB WINAPI
wglCreatePbufferARB( HDC hdc
, int format
, int width
, int height
, const int *attribs
)
925 struct wgl_pbuffer
*pbuffer
;
926 struct opengl_funcs
*funcs
= get_dc_funcs( hdc
);
928 if (!funcs
|| !funcs
->ext
.p_wglCreatePbufferARB
) return 0;
929 if (!(pbuffer
= funcs
->ext
.p_wglCreatePbufferARB( hdc
, format
, width
, height
, attribs
))) return 0;
930 ret
= alloc_handle( HANDLE_PBUFFER
, funcs
, pbuffer
);
931 if (!ret
) funcs
->ext
.p_wglDestroyPbufferARB( pbuffer
);
935 /***********************************************************************
938 * Provided by the WGL_ARB_pbuffer extension.
940 HDC WINAPI
wglGetPbufferDCARB( HPBUFFERARB handle
)
942 struct wgl_handle
*ptr
= get_handle_ptr( handle
, HANDLE_PBUFFER
);
946 ret
= ptr
->funcs
->ext
.p_wglGetPbufferDCARB( ptr
->u
.pbuffer
);
947 release_handle_ptr( ptr
);
951 /***********************************************************************
952 * wglReleasePbufferDCARB
954 * Provided by the WGL_ARB_pbuffer extension.
956 int WINAPI
wglReleasePbufferDCARB( HPBUFFERARB handle
, HDC hdc
)
958 struct wgl_handle
*ptr
= get_handle_ptr( handle
, HANDLE_PBUFFER
);
961 if (!ptr
) return FALSE
;
962 ret
= ptr
->funcs
->ext
.p_wglReleasePbufferDCARB( ptr
->u
.pbuffer
, hdc
);
963 release_handle_ptr( ptr
);
967 /***********************************************************************
968 * wglDestroyPbufferARB
970 * Provided by the WGL_ARB_pbuffer extension.
972 BOOL WINAPI
wglDestroyPbufferARB( HPBUFFERARB handle
)
974 struct wgl_handle
*ptr
= get_handle_ptr( handle
, HANDLE_PBUFFER
);
976 if (!ptr
) return FALSE
;
977 ptr
->funcs
->ext
.p_wglDestroyPbufferARB( ptr
->u
.pbuffer
);
978 free_handle_ptr( ptr
);
982 /***********************************************************************
985 * Provided by the WGL_ARB_pbuffer extension.
987 BOOL WINAPI
wglQueryPbufferARB( HPBUFFERARB handle
, int attrib
, int *value
)
989 struct wgl_handle
*ptr
= get_handle_ptr( handle
, HANDLE_PBUFFER
);
992 if (!ptr
) return FALSE
;
993 ret
= ptr
->funcs
->ext
.p_wglQueryPbufferARB( ptr
->u
.pbuffer
, attrib
, value
);
994 release_handle_ptr( ptr
);
998 /***********************************************************************
999 * wglGetExtensionsStringARB
1001 * Provided by the WGL_ARB_extensions_string extension.
1003 const char * WINAPI
wglGetExtensionsStringARB( HDC hdc
)
1005 const struct opengl_funcs
*funcs
= get_dc_funcs( hdc
);
1007 if (!funcs
|| !funcs
->ext
.p_wglGetExtensionsStringARB
) return NULL
;
1008 return (const char *)funcs
->ext
.p_wglGetExtensionsStringARB( hdc
);
1011 /***********************************************************************
1012 * wglGetExtensionsStringEXT
1014 * Provided by the WGL_EXT_extensions_string extension.
1016 const char * WINAPI
wglGetExtensionsStringEXT(void)
1018 const struct opengl_funcs
*funcs
= NtCurrentTeb()->glTable
;
1020 if (!funcs
->ext
.p_wglGetExtensionsStringEXT
) return NULL
;
1021 return (const char *)funcs
->ext
.p_wglGetExtensionsStringEXT();
1024 /***********************************************************************
1025 * wglSwapIntervalEXT
1027 * Provided by the WGL_EXT_swap_control extension.
1029 BOOL WINAPI
wglSwapIntervalEXT( int interval
)
1031 const struct opengl_funcs
*funcs
= NtCurrentTeb()->glTable
;
1033 if (!funcs
->ext
.p_wglSwapIntervalEXT
) return FALSE
;
1034 return funcs
->ext
.p_wglSwapIntervalEXT( interval
);
1037 /***********************************************************************
1038 * wglGetSwapIntervalEXT
1040 * Provided by the WGL_EXT_swap_control extension.
1042 int WINAPI
wglGetSwapIntervalEXT(void)
1044 const struct opengl_funcs
*funcs
= NtCurrentTeb()->glTable
;
1046 if (!funcs
->ext
.p_wglGetSwapIntervalEXT
) return FALSE
;
1047 return funcs
->ext
.p_wglGetSwapIntervalEXT();
1050 /***********************************************************************
1051 * wglSetPixelFormatWINE
1053 * Provided by the WGL_WINE_pixel_format_passthrough extension.
1055 BOOL WINAPI
wglSetPixelFormatWINE( HDC hdc
, int format
)
1057 const struct opengl_funcs
*funcs
= get_dc_funcs( hdc
);
1059 if (!funcs
|| !funcs
->ext
.p_wglSetPixelFormatWINE
) return FALSE
;
1060 return funcs
->ext
.p_wglSetPixelFormatWINE( hdc
, format
);
1063 /***********************************************************************
1064 * wglUseFontBitmaps_common
1066 static BOOL
wglUseFontBitmaps_common( HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
, BOOL unicode
)
1068 const struct opengl_funcs
*funcs
= NtCurrentTeb()->glTable
;
1070 unsigned int glyph
, size
= 0;
1071 void *bitmap
= NULL
, *gl_bitmap
= NULL
;
1075 funcs
->gl
.p_glGetIntegerv(GL_UNPACK_ALIGNMENT
, &org_alignment
);
1076 funcs
->gl
.p_glPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
1078 for (glyph
= first
; glyph
< first
+ count
; glyph
++) {
1079 static const MAT2 identity
= { {0,1},{0,0},{0,0},{0,1} };
1080 unsigned int needed_size
, height
, width
, width_int
;
1083 needed_size
= GetGlyphOutlineW(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, &identity
);
1085 needed_size
= GetGlyphOutlineA(hdc
, glyph
, GGO_BITMAP
, &gm
, 0, NULL
, &identity
);
1087 TRACE("Glyph: %3d / List: %d size %d\n", glyph
, listBase
, needed_size
);
1088 if (needed_size
== GDI_ERROR
) {
1093 if (needed_size
> size
) {
1095 HeapFree(GetProcessHeap(), 0, bitmap
);
1096 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1097 bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1098 gl_bitmap
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1101 ret
= (GetGlyphOutlineW(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, &identity
) != GDI_ERROR
);
1103 ret
= (GetGlyphOutlineA(hdc
, glyph
, GGO_BITMAP
, &gm
, size
, bitmap
, &identity
) != GDI_ERROR
);
1106 if (TRACE_ON(wgl
)) {
1107 unsigned int bitmask
;
1108 unsigned char *bitmap_
= bitmap
;
1110 TRACE(" - bbox: %d x %d\n", gm
.gmBlackBoxX
, gm
.gmBlackBoxY
);
1111 TRACE(" - origin: (%d, %d)\n", gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
1112 TRACE(" - increment: %d - %d\n", gm
.gmCellIncX
, gm
.gmCellIncY
);
1113 if (needed_size
!= 0) {
1114 TRACE(" - bitmap:\n");
1115 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1117 for (width
= 0, bitmask
= 0x80; width
< gm
.gmBlackBoxX
; width
++, bitmask
>>= 1) {
1122 if (*bitmap_
& bitmask
)
1127 bitmap_
+= (4 - ((UINT_PTR
)bitmap_
& 0x03));
1133 /* In OpenGL, the bitmap is drawn from the bottom to the top... So we need to invert the
1134 * glyph for it to be drawn properly.
1136 if (needed_size
!= 0) {
1137 width_int
= (gm
.gmBlackBoxX
+ 31) / 32;
1138 for (height
= 0; height
< gm
.gmBlackBoxY
; height
++) {
1139 for (width
= 0; width
< width_int
; width
++) {
1140 ((int *) gl_bitmap
)[(gm
.gmBlackBoxY
- height
- 1) * width_int
+ width
] =
1141 ((int *) bitmap
)[height
* width_int
+ width
];
1146 funcs
->gl
.p_glNewList(listBase
++, GL_COMPILE
);
1147 if (needed_size
!= 0) {
1148 funcs
->gl
.p_glBitmap(gm
.gmBlackBoxX
, gm
.gmBlackBoxY
,
1149 0 - gm
.gmptGlyphOrigin
.x
, (int) gm
.gmBlackBoxY
- gm
.gmptGlyphOrigin
.y
,
1150 gm
.gmCellIncX
, gm
.gmCellIncY
,
1153 /* This is the case of 'empty' glyphs like the space character */
1154 funcs
->gl
.p_glBitmap(0, 0, 0, 0, gm
.gmCellIncX
, gm
.gmCellIncY
, NULL
);
1156 funcs
->gl
.p_glEndList();
1159 funcs
->gl
.p_glPixelStorei(GL_UNPACK_ALIGNMENT
, org_alignment
);
1160 HeapFree(GetProcessHeap(), 0, bitmap
);
1161 HeapFree(GetProcessHeap(), 0, gl_bitmap
);
1165 /***********************************************************************
1166 * wglUseFontBitmapsA (OPENGL32.@)
1168 BOOL WINAPI
wglUseFontBitmapsA(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
)
1170 return wglUseFontBitmaps_common( hdc
, first
, count
, listBase
, FALSE
);
1173 /***********************************************************************
1174 * wglUseFontBitmapsW (OPENGL32.@)
1176 BOOL WINAPI
wglUseFontBitmapsW(HDC hdc
, DWORD first
, DWORD count
, DWORD listBase
)
1178 return wglUseFontBitmaps_common( hdc
, first
, count
, listBase
, TRUE
);
1181 /* FIXME: should probably have a glu.h header */
1183 typedef struct GLUtesselator GLUtesselator
;
1184 typedef void (WINAPI
*_GLUfuncptr
)(void);
1186 #define GLU_TESS_BEGIN 100100
1187 #define GLU_TESS_VERTEX 100101
1188 #define GLU_TESS_END 100102
1190 static GLUtesselator
* (WINAPI
*pgluNewTess
)(void);
1191 static void (WINAPI
*pgluDeleteTess
)(GLUtesselator
*tess
);
1192 static void (WINAPI
*pgluTessBeginPolygon
)(GLUtesselator
*tess
, void *polygon_data
);
1193 static void (WINAPI
*pgluTessEndPolygon
)(GLUtesselator
*tess
);
1194 static void (WINAPI
*pgluTessCallback
)(GLUtesselator
*tess
, GLenum which
, _GLUfuncptr fn
);
1195 static void (WINAPI
*pgluTessBeginContour
)(GLUtesselator
*tess
);
1196 static void (WINAPI
*pgluTessEndContour
)(GLUtesselator
*tess
);
1197 static void (WINAPI
*pgluTessVertex
)(GLUtesselator
*tess
, GLdouble
*location
, GLvoid
* data
);
1199 static HMODULE
load_libglu(void)
1201 static const WCHAR glu32W
[] = {'g','l','u','3','2','.','d','l','l',0};
1202 static int already_loaded
;
1203 static HMODULE module
;
1205 if (already_loaded
) return module
;
1208 TRACE("Trying to load GLU library\n");
1209 module
= LoadLibraryW( glu32W
);
1212 WARN("Failed to load glu32\n");
1215 #define LOAD_FUNCPTR(f) p##f = (void *)GetProcAddress( module, #f )
1216 LOAD_FUNCPTR(gluNewTess
);
1217 LOAD_FUNCPTR(gluDeleteTess
);
1218 LOAD_FUNCPTR(gluTessBeginContour
);
1219 LOAD_FUNCPTR(gluTessBeginPolygon
);
1220 LOAD_FUNCPTR(gluTessCallback
);
1221 LOAD_FUNCPTR(gluTessEndContour
);
1222 LOAD_FUNCPTR(gluTessEndPolygon
);
1223 LOAD_FUNCPTR(gluTessVertex
);
1228 static void fixed_to_double(POINTFX fixed
, UINT em_size
, GLdouble vertex
[3])
1230 vertex
[0] = (fixed
.x
.value
+ (GLdouble
)fixed
.x
.fract
/ (1 << 16)) / em_size
;
1231 vertex
[1] = (fixed
.y
.value
+ (GLdouble
)fixed
.y
.fract
/ (1 << 16)) / em_size
;
1235 static void WINAPI
tess_callback_vertex(GLvoid
*vertex
)
1237 const struct opengl_funcs
*funcs
= NtCurrentTeb()->glTable
;
1238 GLdouble
*dbl
= vertex
;
1239 TRACE("%f, %f, %f\n", dbl
[0], dbl
[1], dbl
[2]);
1240 funcs
->gl
.p_glVertex3dv(vertex
);
1243 static void WINAPI
tess_callback_begin(GLenum which
)
1245 const struct opengl_funcs
*funcs
= NtCurrentTeb()->glTable
;
1246 TRACE("%d\n", which
);
1247 funcs
->gl
.p_glBegin(which
);
1250 static void WINAPI
tess_callback_end(void)
1252 const struct opengl_funcs
*funcs
= NtCurrentTeb()->glTable
;
1254 funcs
->gl
.p_glEnd();
1257 /***********************************************************************
1258 * wglUseFontOutlines_common
1260 static BOOL
wglUseFontOutlines_common(HDC hdc
,
1267 LPGLYPHMETRICSFLOAT lpgmf
,
1270 const struct opengl_funcs
*funcs
= NtCurrentTeb()->glTable
;
1272 const MAT2 identity
= {{0,1},{0,0},{0,0},{0,1}};
1273 GLUtesselator
*tess
;
1275 HFONT old_font
, unscaled_font
;
1276 UINT em_size
= 1024;
1279 TRACE("(%p, %d, %d, %d, %f, %f, %d, %p, %s)\n", hdc
, first
, count
,
1280 listBase
, deviation
, extrusion
, format
, lpgmf
, unicode
? "W" : "A");
1284 ERR("glu32 is required for this function but isn't available\n");
1288 tess
= pgluNewTess();
1289 if(!tess
) return FALSE
;
1290 pgluTessCallback(tess
, GLU_TESS_VERTEX
, (_GLUfuncptr
)tess_callback_vertex
);
1291 pgluTessCallback(tess
, GLU_TESS_BEGIN
, (_GLUfuncptr
)tess_callback_begin
);
1292 pgluTessCallback(tess
, GLU_TESS_END
, tess_callback_end
);
1294 GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(lf
), &lf
);
1295 rc
.left
= rc
.right
= rc
.bottom
= 0;
1297 DPtoLP(hdc
, (POINT
*)&rc
, 2);
1298 lf
.lfHeight
= -abs(rc
.top
- rc
.bottom
);
1299 lf
.lfOrientation
= lf
.lfEscapement
= 0;
1300 unscaled_font
= CreateFontIndirectW(&lf
);
1301 old_font
= SelectObject(hdc
, unscaled_font
);
1303 for (glyph
= first
; glyph
< first
+ count
; glyph
++)
1308 TTPOLYGONHEADER
*pph
;
1313 needed
= GetGlyphOutlineW(hdc
, glyph
, GGO_NATIVE
, &gm
, 0, NULL
, &identity
);
1315 needed
= GetGlyphOutlineA(hdc
, glyph
, GGO_NATIVE
, &gm
, 0, NULL
, &identity
);
1317 if(needed
== GDI_ERROR
)
1320 buf
= HeapAlloc(GetProcessHeap(), 0, needed
);
1321 vertices
= HeapAlloc(GetProcessHeap(), 0, needed
/ sizeof(POINTFX
) * 3 * sizeof(GLdouble
));
1324 GetGlyphOutlineW(hdc
, glyph
, GGO_NATIVE
, &gm
, needed
, buf
, &identity
);
1326 GetGlyphOutlineA(hdc
, glyph
, GGO_NATIVE
, &gm
, needed
, buf
, &identity
);
1328 TRACE("glyph %d\n", glyph
);
1332 lpgmf
->gmfBlackBoxX
= (float)gm
.gmBlackBoxX
/ em_size
;
1333 lpgmf
->gmfBlackBoxY
= (float)gm
.gmBlackBoxY
/ em_size
;
1334 lpgmf
->gmfptGlyphOrigin
.x
= (float)gm
.gmptGlyphOrigin
.x
/ em_size
;
1335 lpgmf
->gmfptGlyphOrigin
.y
= (float)gm
.gmptGlyphOrigin
.y
/ em_size
;
1336 lpgmf
->gmfCellIncX
= (float)gm
.gmCellIncX
/ em_size
;
1337 lpgmf
->gmfCellIncY
= (float)gm
.gmCellIncY
/ em_size
;
1339 TRACE("%fx%f at %f,%f inc %f,%f\n", lpgmf
->gmfBlackBoxX
, lpgmf
->gmfBlackBoxY
,
1340 lpgmf
->gmfptGlyphOrigin
.x
, lpgmf
->gmfptGlyphOrigin
.y
, lpgmf
->gmfCellIncX
, lpgmf
->gmfCellIncY
);
1344 funcs
->gl
.p_glNewList(listBase
++, GL_COMPILE
);
1345 pgluTessBeginPolygon(tess
, NULL
);
1347 pph
= (TTPOLYGONHEADER
*)buf
;
1348 while((BYTE
*)pph
< buf
+ needed
)
1350 TRACE("\tstart %d, %d\n", pph
->pfxStart
.x
.value
, pph
->pfxStart
.y
.value
);
1352 pgluTessBeginContour(tess
);
1354 fixed_to_double(pph
->pfxStart
, em_size
, vertices
);
1355 pgluTessVertex(tess
, vertices
, vertices
);
1358 ppc
= (TTPOLYCURVE
*)((char*)pph
+ sizeof(*pph
));
1359 while((char*)ppc
< (char*)pph
+ pph
->cb
)
1363 switch(ppc
->wType
) {
1365 for(i
= 0; i
< ppc
->cpfx
; i
++)
1367 TRACE("\t\tline to %d, %d\n", ppc
->apfx
[i
].x
.value
, ppc
->apfx
[i
].y
.value
);
1368 fixed_to_double(ppc
->apfx
[i
], em_size
, vertices
);
1369 pgluTessVertex(tess
, vertices
, vertices
);
1374 case TT_PRIM_QSPLINE
:
1375 for(i
= 0; i
< ppc
->cpfx
/2; i
++)
1377 /* FIXME: just connecting the control points for now */
1378 TRACE("\t\tcurve %d,%d %d,%d\n",
1379 ppc
->apfx
[i
* 2].x
.value
, ppc
->apfx
[i
* 3].y
.value
,
1380 ppc
->apfx
[i
* 2 + 1].x
.value
, ppc
->apfx
[i
* 3 + 1].y
.value
);
1381 fixed_to_double(ppc
->apfx
[i
* 2], em_size
, vertices
);
1382 pgluTessVertex(tess
, vertices
, vertices
);
1384 fixed_to_double(ppc
->apfx
[i
* 2 + 1], em_size
, vertices
);
1385 pgluTessVertex(tess
, vertices
, vertices
);
1390 ERR("\t\tcurve type = %d\n", ppc
->wType
);
1391 pgluTessEndContour(tess
);
1395 ppc
= (TTPOLYCURVE
*)((char*)ppc
+ sizeof(*ppc
) +
1396 (ppc
->cpfx
- 1) * sizeof(POINTFX
));
1398 pgluTessEndContour(tess
);
1399 pph
= (TTPOLYGONHEADER
*)((char*)pph
+ pph
->cb
);
1403 pgluTessEndPolygon(tess
);
1404 funcs
->gl
.p_glTranslated((GLdouble
)gm
.gmCellIncX
/ em_size
, (GLdouble
)gm
.gmCellIncY
/ em_size
, 0.0);
1405 funcs
->gl
.p_glEndList();
1406 HeapFree(GetProcessHeap(), 0, buf
);
1407 HeapFree(GetProcessHeap(), 0, vertices
);
1411 DeleteObject(SelectObject(hdc
, old_font
));
1412 pgluDeleteTess(tess
);
1417 /***********************************************************************
1418 * wglUseFontOutlinesA (OPENGL32.@)
1420 BOOL WINAPI
wglUseFontOutlinesA(HDC hdc
,
1427 LPGLYPHMETRICSFLOAT lpgmf
)
1429 return wglUseFontOutlines_common(hdc
, first
, count
, listBase
, deviation
, extrusion
, format
, lpgmf
, FALSE
);
1432 /***********************************************************************
1433 * wglUseFontOutlinesW (OPENGL32.@)
1435 BOOL WINAPI
wglUseFontOutlinesW(HDC hdc
,
1442 LPGLYPHMETRICSFLOAT lpgmf
)
1444 return wglUseFontOutlines_common(hdc
, first
, count
, listBase
, deviation
, extrusion
, format
, lpgmf
, TRUE
);
1447 /***********************************************************************
1448 * glDebugEntry (OPENGL32.@)
1450 GLint WINAPI
wine_glDebugEntry( GLint unknown1
, GLint unknown2
)
1455 /* build the extension string by filtering out the disabled extensions */
1456 static char *build_gl_extensions( const char *extensions
)
1458 char *p
, *str
, *disabled
= NULL
;
1462 TRACE( "GL_EXTENSIONS:\n" );
1464 if (!extensions
) extensions
= "";
1466 /* @@ Wine registry key: HKCU\Software\Wine\OpenGL */
1467 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\OpenGL", &hkey
))
1469 DWORD size
, ret
= RegQueryValueExA( hkey
, "DisabledExtensions", 0, NULL
, NULL
, &size
);
1470 if (!ret
&& (disabled
= HeapAlloc( GetProcessHeap(), 0, size
)))
1471 ret
= RegQueryValueExA( hkey
, "DisabledExtensions", 0, NULL
, (BYTE
*)disabled
, &size
);
1472 RegCloseKey( hkey
);
1473 if (ret
) *disabled
= 0;
1476 if ((str
= HeapAlloc( GetProcessHeap(), 0, strlen(extensions
) + 2 )))
1481 while (*extensions
== ' ') extensions
++;
1482 if (!*extensions
) break;
1483 if (!(end
= strchr( extensions
, ' ' ))) end
= extensions
+ strlen( extensions
);
1484 memcpy( p
, extensions
, end
- extensions
);
1485 p
[end
- extensions
] = 0;
1486 if (!has_extension( disabled
, p
))
1488 TRACE("++ %s\n", p
);
1489 p
+= end
- extensions
;
1492 else TRACE("-- %s (disabled by config)\n", p
);
1497 HeapFree( GetProcessHeap(), 0, disabled
);
1501 /***********************************************************************
1502 * glGetString (OPENGL32.@)
1504 const GLubyte
* WINAPI
wine_glGetString( GLenum name
)
1506 const struct opengl_funcs
*funcs
= NtCurrentTeb()->glTable
;
1507 static const GLubyte
*gl_extensions
;
1509 /* this is for buggy nvidia driver, crashing if called from a different
1510 thread with no context */
1511 if(wglGetCurrentContext() == NULL
)
1514 if (name
!= GL_EXTENSIONS
) return funcs
->gl
.p_glGetString(name
);
1518 const char *orig_ext
= (const char *)funcs
->gl
.p_glGetString(GL_EXTENSIONS
);
1519 char *new_ext
= build_gl_extensions( orig_ext
);
1520 if (InterlockedCompareExchangePointer( (void **)&gl_extensions
, new_ext
, NULL
))
1521 HeapFree( GetProcessHeap(), 0, new_ext
);
1523 return gl_extensions
;
1526 /***********************************************************************
1527 * wglSwapBuffers (OPENGL32.@)
1529 BOOL WINAPI DECLSPEC_HOTPATCH
wglSwapBuffers( HDC hdc
)
1531 return GdiSwapBuffers(hdc
);
1534 /***********************************************************************
1535 * OpenGL initialisation routine
1537 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
1541 case DLL_PROCESS_ATTACH
:
1542 opengl32_handle
= hinst
;
1543 DisableThreadLibraryCalls(hinst
);
1544 NtCurrentTeb()->glTable
= &null_opengl_funcs
;
1546 case DLL_THREAD_ATTACH
:
1547 NtCurrentTeb()->glTable
= &null_opengl_funcs
;