2 * Android OpenGL functions
4 * Copyright 2000 Lionel Ulmer
5 * Copyright 2005 Alex Woods
6 * Copyright 2005 Raphael Junqueira
7 * Copyright 2006-2009 Roderick Colenbrander
8 * Copyright 2006 Tomas Carnecky
9 * Copyright 2013 Matteo Bruni
10 * Copyright 2012, 2013, 2014, 2017 Alexandre Julliard
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
41 #define GLAPIENTRY /* nothing */
44 #include "wine/wgl_driver.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(android
);
49 #define DECL_FUNCPTR(f) typeof(f) * p_##f = NULL
50 DECL_FUNCPTR( eglCreateContext
);
51 DECL_FUNCPTR( eglCreateWindowSurface
);
52 DECL_FUNCPTR( eglCreatePbufferSurface
);
53 DECL_FUNCPTR( eglDestroyContext
);
54 DECL_FUNCPTR( eglDestroySurface
);
55 DECL_FUNCPTR( eglGetConfigAttrib
);
56 DECL_FUNCPTR( eglGetConfigs
);
57 DECL_FUNCPTR( eglGetDisplay
);
58 DECL_FUNCPTR( eglGetProcAddress
);
59 DECL_FUNCPTR( eglInitialize
);
60 DECL_FUNCPTR( eglMakeCurrent
);
61 DECL_FUNCPTR( eglSwapBuffers
);
62 DECL_FUNCPTR( eglSwapInterval
);
65 static const int egl_client_version
= 2;
67 struct wgl_pixel_format
88 ANativeWindow
*window
;
93 static void *egl_handle
;
94 static void *opengl_handle
;
95 static struct wgl_pixel_format
*pixel_formats
;
96 static int nb_pixel_formats
, nb_onscreen_formats
;
97 static EGLDisplay display
;
98 static int swap_interval
;
99 static char wgl_extensions
[4096];
100 static struct opengl_funcs egl_funcs
;
102 static struct list gl_contexts
= LIST_INIT( gl_contexts
);
103 static struct list gl_drawables
= LIST_INIT( gl_drawables
);
105 static void (*pglFinish
)(void);
106 static void (*pglFlush
)(void);
108 static CRITICAL_SECTION drawable_section
;
109 static CRITICAL_SECTION_DEBUG critsect_debug
=
111 0, 0, &drawable_section
,
112 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
113 0, 0, { (DWORD_PTR
)(__FILE__
": drawable_section") }
115 static CRITICAL_SECTION drawable_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
117 static inline BOOL
is_onscreen_pixel_format( int format
)
119 return format
> 0 && format
<= nb_onscreen_formats
;
122 static struct gl_drawable
*create_gl_drawable( HWND hwnd
, HDC hdc
, int format
)
124 static const int attribs
[] = { EGL_WIDTH
, 1, EGL_HEIGHT
, 1, EGL_NONE
};
125 struct gl_drawable
*gl
= HeapAlloc( GetProcessHeap(), 0, sizeof(*gl
) );
130 gl
->window
= create_ioctl_window( hwnd
, TRUE
, 1.0f
);
132 gl
->pbuffer
= p_eglCreatePbufferSurface( display
, pixel_formats
[gl
->format
- 1].config
, attribs
);
133 EnterCriticalSection( &drawable_section
);
134 list_add_head( &gl_drawables
, &gl
->entry
);
138 static struct gl_drawable
*get_gl_drawable( HWND hwnd
, HDC hdc
)
140 struct gl_drawable
*gl
;
142 EnterCriticalSection( &drawable_section
);
143 LIST_FOR_EACH_ENTRY( gl
, &gl_drawables
, struct gl_drawable
, entry
)
145 if (hwnd
&& gl
->hwnd
== hwnd
) return gl
;
146 if (hdc
&& gl
->hdc
== hdc
) return gl
;
148 LeaveCriticalSection( &drawable_section
);
152 static void release_gl_drawable( struct gl_drawable
*gl
)
154 if (gl
) LeaveCriticalSection( &drawable_section
);
157 void destroy_gl_drawable( HWND hwnd
)
159 struct gl_drawable
*gl
;
161 EnterCriticalSection( &drawable_section
);
162 LIST_FOR_EACH_ENTRY( gl
, &gl_drawables
, struct gl_drawable
, entry
)
164 if (gl
->hwnd
!= hwnd
) continue;
165 list_remove( &gl
->entry
);
166 if (gl
->surface
) p_eglDestroySurface( display
, gl
->surface
);
167 if (gl
->pbuffer
) p_eglDestroySurface( display
, gl
->pbuffer
);
168 release_ioctl_window( gl
->window
);
169 HeapFree( GetProcessHeap(), 0, gl
);
172 LeaveCriticalSection( &drawable_section
);
175 static BOOL
refresh_context( struct wgl_context
*ctx
)
177 BOOL ret
= InterlockedExchange( &ctx
->refresh
, FALSE
);
181 TRACE( "refreshing hwnd %p context %p surface %p\n", ctx
->hwnd
, ctx
->context
, ctx
->surface
);
182 p_eglMakeCurrent( display
, ctx
->surface
, ctx
->surface
, ctx
->context
);
183 RedrawWindow( ctx
->hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
);
188 void update_gl_drawable( HWND hwnd
)
190 struct gl_drawable
*gl
;
191 struct wgl_context
*ctx
;
193 if ((gl
= get_gl_drawable( hwnd
, 0 )))
196 (gl
->surface
= p_eglCreateWindowSurface( display
, pixel_formats
[gl
->format
- 1].config
, gl
->window
, NULL
)))
198 LIST_FOR_EACH_ENTRY( ctx
, &gl_contexts
, struct wgl_context
, entry
)
200 if (ctx
->hwnd
!= hwnd
) continue;
201 TRACE( "hwnd %p refreshing %p %scurrent\n", hwnd
, ctx
, NtCurrentTeb()->glContext
== ctx
? "" : "not " );
202 ctx
->surface
= gl
->surface
;
203 if (NtCurrentTeb()->glContext
== ctx
)
204 p_eglMakeCurrent( display
, ctx
->surface
, ctx
->surface
, ctx
->context
);
206 InterlockedExchange( &ctx
->refresh
, TRUE
);
209 release_gl_drawable( gl
);
210 RedrawWindow( hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
);
214 static BOOL
set_pixel_format( HDC hdc
, int format
, BOOL allow_change
)
216 struct gl_drawable
*gl
;
217 HWND hwnd
= WindowFromDC( hdc
);
220 if (!hwnd
|| hwnd
== GetDesktopWindow())
222 WARN( "not a proper window DC %p/%p\n", hdc
, hwnd
);
225 if (!is_onscreen_pixel_format( format
))
227 WARN( "Invalid format %d\n", format
);
230 TRACE( "%p/%p format %d\n", hdc
, hwnd
, format
);
232 if ((gl
= get_gl_drawable( hwnd
, 0 )))
238 p_eglGetConfigAttrib( display
, pixel_formats
[format
- 1].config
, EGL_NATIVE_VISUAL_ID
, &pf
);
239 gl
->window
->perform( gl
->window
, NATIVE_WINDOW_SET_BUFFERS_FORMAT
, pf
);
243 else gl
= create_gl_drawable( hwnd
, 0, format
);
245 release_gl_drawable( gl
);
247 if (prev
&& prev
!= format
&& !allow_change
) return FALSE
;
248 if (__wine_set_pixel_format( hwnd
, format
)) return TRUE
;
249 destroy_gl_drawable( hwnd
);
253 static struct wgl_context
*create_context( HDC hdc
, struct wgl_context
*share
, const int *attribs
)
255 struct gl_drawable
*gl
;
256 struct wgl_context
*ctx
;
258 if (!(gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
))) return NULL
;
260 ctx
= HeapAlloc( GetProcessHeap(), 0, sizeof(*ctx
) );
262 ctx
->config
= pixel_formats
[gl
->format
- 1].config
;
264 ctx
->refresh
= FALSE
;
265 ctx
->context
= p_eglCreateContext( display
, ctx
->config
,
266 share
? share
->context
: EGL_NO_CONTEXT
, attribs
);
267 TRACE( "%p fmt %d ctx %p\n", hdc
, gl
->format
, ctx
->context
);
268 list_add_head( &gl_contexts
, &ctx
->entry
);
269 release_gl_drawable( gl
);
273 /***********************************************************************
274 * android_wglGetExtensionsStringARB
276 static const char *android_wglGetExtensionsStringARB( HDC hdc
)
278 TRACE( "() returning \"%s\"\n", wgl_extensions
);
279 return wgl_extensions
;
282 /***********************************************************************
283 * android_wglGetExtensionsStringEXT
285 static const char *android_wglGetExtensionsStringEXT(void)
287 TRACE( "() returning \"%s\"\n", wgl_extensions
);
288 return wgl_extensions
;
291 /***********************************************************************
292 * android_wglCreateContextAttribsARB
294 static struct wgl_context
*android_wglCreateContextAttribsARB( HDC hdc
, struct wgl_context
*share
,
297 int count
= 0, egl_attribs
[3];
298 BOOL opengl_es
= FALSE
;
300 while (attribs
&& *attribs
&& count
< 2)
304 case WGL_CONTEXT_PROFILE_MASK_ARB
:
305 if (attribs
[1] == WGL_CONTEXT_ES2_PROFILE_BIT_EXT
)
308 case WGL_CONTEXT_MAJOR_VERSION_ARB
:
309 egl_attribs
[count
++] = EGL_CONTEXT_CLIENT_VERSION
;
310 egl_attribs
[count
++] = attribs
[1];
313 FIXME("Unhandled attributes: %#x %#x\n", attribs
[0], attribs
[1]);
319 WARN("Requested creation of an OpenGL (non ES) context, that's not supported.\n");
322 if (!count
) /* FIXME: force version if not specified */
324 egl_attribs
[count
++] = EGL_CONTEXT_CLIENT_VERSION
;
325 egl_attribs
[count
++] = egl_client_version
;
327 egl_attribs
[count
] = EGL_NONE
;
329 return create_context( hdc
, share
, egl_attribs
);
332 /***********************************************************************
333 * android_wglMakeContextCurrentARB
335 static BOOL
android_wglMakeContextCurrentARB( HDC draw_hdc
, HDC read_hdc
, struct wgl_context
*ctx
)
338 struct gl_drawable
*draw_gl
, *read_gl
= NULL
;
339 EGLSurface draw_surface
, read_surface
;
342 TRACE( "%p %p %p\n", draw_hdc
, read_hdc
, ctx
);
346 p_eglMakeCurrent( display
, EGL_NO_SURFACE
, EGL_NO_SURFACE
, EGL_NO_CONTEXT
);
347 NtCurrentTeb()->glContext
= NULL
;
351 draw_hwnd
= WindowFromDC( draw_hdc
);
352 if ((draw_gl
= get_gl_drawable( draw_hwnd
, draw_hdc
)))
354 read_gl
= get_gl_drawable( WindowFromDC( read_hdc
), read_hdc
);
355 draw_surface
= draw_gl
->surface
? draw_gl
->surface
: draw_gl
->pbuffer
;
356 read_surface
= read_gl
->surface
? read_gl
->surface
: read_gl
->pbuffer
;
357 TRACE( "%p/%p context %p surface %p/%p\n",
358 draw_hdc
, read_hdc
, ctx
->context
, draw_surface
, read_surface
);
359 ret
= p_eglMakeCurrent( display
, draw_surface
, read_surface
, ctx
->context
);
362 ctx
->surface
= draw_gl
->surface
;
363 ctx
->hwnd
= draw_hwnd
;
364 ctx
->refresh
= FALSE
;
365 NtCurrentTeb()->glContext
= ctx
;
369 SetLastError( ERROR_INVALID_HANDLE
);
372 release_gl_drawable( read_gl
);
373 release_gl_drawable( draw_gl
);
377 /***********************************************************************
378 * android_wglSwapIntervalEXT
380 static BOOL
android_wglSwapIntervalEXT( int interval
)
384 TRACE("(%d)\n", interval
);
388 SetLastError(ERROR_INVALID_DATA
);
392 ret
= p_eglSwapInterval( display
, interval
);
395 swap_interval
= interval
;
397 SetLastError( ERROR_DC_NOT_FOUND
);
402 /***********************************************************************
403 * android_wglGetSwapIntervalEXT
405 static int android_wglGetSwapIntervalEXT(void)
407 return swap_interval
;
410 /***********************************************************************
411 * android_wglSetPixelFormatWINE
413 static BOOL
android_wglSetPixelFormatWINE( HDC hdc
, int format
)
415 return set_pixel_format( hdc
, format
, TRUE
);
418 /***********************************************************************
419 * android_wglCopyContext
421 static BOOL WINAPI
android_wglCopyContext( struct wgl_context
*src
, struct wgl_context
*dst
, UINT mask
)
423 FIXME( "%p -> %p mask %#x unsupported\n", src
, dst
, mask
);
427 /***********************************************************************
428 * android_wglCreateContext
430 static struct wgl_context
* WINAPI
android_wglCreateContext( HDC hdc
)
432 int egl_attribs
[3] = { EGL_CONTEXT_CLIENT_VERSION
, egl_client_version
, EGL_NONE
};
434 return create_context( hdc
, NULL
, egl_attribs
);
437 /***********************************************************************
438 * android_wglDeleteContext
440 static BOOL WINAPI
android_wglDeleteContext( struct wgl_context
*ctx
)
442 EnterCriticalSection( &drawable_section
);
443 list_remove( &ctx
->entry
);
444 LeaveCriticalSection( &drawable_section
);
445 p_eglDestroyContext( display
, ctx
->context
);
446 return HeapFree( GetProcessHeap(), 0, ctx
);
449 /***********************************************************************
450 * android_wglDescribePixelFormat
452 static int WINAPI
android_wglDescribePixelFormat( HDC hdc
, int fmt
, UINT size
, PIXELFORMATDESCRIPTOR
*pfd
)
457 if (!pfd
) return nb_onscreen_formats
;
458 if (!is_onscreen_pixel_format( fmt
)) return 0;
459 if (size
< sizeof(*pfd
)) return 0;
460 config
= pixel_formats
[fmt
- 1].config
;
462 memset( pfd
, 0, sizeof(*pfd
) );
463 pfd
->nSize
= sizeof(*pfd
);
465 pfd
->dwFlags
= PFD_SUPPORT_OPENGL
| PFD_DRAW_TO_WINDOW
| PFD_DOUBLEBUFFER
;
466 pfd
->iPixelType
= PFD_TYPE_RGBA
;
467 pfd
->iLayerType
= PFD_MAIN_PLANE
;
469 p_eglGetConfigAttrib( display
, config
, EGL_BUFFER_SIZE
, &val
);
470 pfd
->cColorBits
= val
;
471 p_eglGetConfigAttrib( display
, config
, EGL_RED_SIZE
, &val
);
473 p_eglGetConfigAttrib( display
, config
, EGL_GREEN_SIZE
, &val
);
474 pfd
->cGreenBits
= val
;
475 p_eglGetConfigAttrib( display
, config
, EGL_BLUE_SIZE
, &val
);
476 pfd
->cBlueBits
= val
;
477 p_eglGetConfigAttrib( display
, config
, EGL_ALPHA_SIZE
, &val
);
478 pfd
->cAlphaBits
= val
;
479 p_eglGetConfigAttrib( display
, config
, EGL_DEPTH_SIZE
, &val
);
480 pfd
->cDepthBits
= val
;
481 p_eglGetConfigAttrib( display
, config
, EGL_STENCIL_SIZE
, &val
);
482 pfd
->cStencilBits
= val
;
484 pfd
->cAlphaShift
= 0;
485 pfd
->cBlueShift
= pfd
->cAlphaShift
+ pfd
->cAlphaBits
;
486 pfd
->cGreenShift
= pfd
->cBlueShift
+ pfd
->cBlueBits
;
487 pfd
->cRedShift
= pfd
->cGreenShift
+ pfd
->cGreenBits
;
489 TRACE( "fmt %u color %u %u/%u/%u/%u depth %u stencil %u\n",
490 fmt
, pfd
->cColorBits
, pfd
->cRedBits
, pfd
->cGreenBits
, pfd
->cBlueBits
,
491 pfd
->cAlphaBits
, pfd
->cDepthBits
, pfd
->cStencilBits
);
492 return nb_onscreen_formats
;
495 /***********************************************************************
496 * android_wglGetPixelFormat
498 static int WINAPI
android_wglGetPixelFormat( HDC hdc
)
500 struct gl_drawable
*gl
;
503 if ((gl
= get_gl_drawable( WindowFromDC( hdc
), hdc
)))
506 /* offscreen formats can't be used with traditional WGL calls */
507 if (!is_onscreen_pixel_format( ret
)) ret
= 1;
508 release_gl_drawable( gl
);
513 /***********************************************************************
514 * android_wglGetProcAddress
516 static PROC WINAPI
android_wglGetProcAddress( LPCSTR name
)
519 if (!strncmp( name
, "wgl", 3 )) return NULL
;
520 ret
= (PROC
)p_eglGetProcAddress( name
);
521 TRACE( "%s -> %p\n", name
, ret
);
525 /***********************************************************************
526 * android_wglMakeCurrent
528 static BOOL WINAPI
android_wglMakeCurrent( HDC hdc
, struct wgl_context
*ctx
)
531 struct gl_drawable
*gl
;
534 TRACE( "%p %p\n", hdc
, ctx
);
538 p_eglMakeCurrent( display
, EGL_NO_SURFACE
, EGL_NO_SURFACE
, EGL_NO_CONTEXT
);
539 NtCurrentTeb()->glContext
= NULL
;
543 hwnd
= WindowFromDC( hdc
);
544 if ((gl
= get_gl_drawable( hwnd
, hdc
)))
546 EGLSurface surface
= gl
->surface
? gl
->surface
: gl
->pbuffer
;
547 TRACE( "%p hwnd %p context %p surface %p\n", hdc
, gl
->hwnd
, ctx
->context
, surface
);
548 ret
= p_eglMakeCurrent( display
, surface
, surface
, ctx
->context
);
551 ctx
->surface
= gl
->surface
;
553 ctx
->refresh
= FALSE
;
554 NtCurrentTeb()->glContext
= ctx
;
558 SetLastError( ERROR_INVALID_HANDLE
);
561 release_gl_drawable( gl
);
565 /***********************************************************************
566 * android_wglSetPixelFormat
568 static BOOL WINAPI
android_wglSetPixelFormat( HDC hdc
, int format
, const PIXELFORMATDESCRIPTOR
*pfd
)
570 return set_pixel_format( hdc
, format
, FALSE
);
573 /***********************************************************************
574 * android_wglShareLists
576 static BOOL WINAPI
android_wglShareLists( struct wgl_context
*org
, struct wgl_context
*dest
)
578 FIXME( "%p %p\n", org
, dest
);
582 /***********************************************************************
583 * android_wglSwapBuffers
585 static BOOL WINAPI
android_wglSwapBuffers( HDC hdc
)
587 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
589 if (!ctx
) return FALSE
;
591 TRACE( "%p hwnd %p context %p surface %p\n", hdc
, ctx
->hwnd
, ctx
->context
, ctx
->surface
);
593 if (refresh_context( ctx
)) return TRUE
;
594 if (ctx
->surface
) p_eglSwapBuffers( display
, ctx
->surface
);
598 static void wglFinish(void)
600 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
603 TRACE( "hwnd %p context %p\n", ctx
->hwnd
, ctx
->context
);
604 refresh_context( ctx
);
608 static void wglFlush(void)
610 struct wgl_context
*ctx
= NtCurrentTeb()->glContext
;
613 TRACE( "hwnd %p context %p\n", ctx
->hwnd
, ctx
->context
);
614 refresh_context( ctx
);
618 static void register_extension( const char *ext
)
620 if (wgl_extensions
[0]) strcat( wgl_extensions
, " " );
621 strcat( wgl_extensions
, ext
);
622 TRACE( "%s\n", ext
);
625 static void init_extensions(void)
629 register_extension("WGL_ARB_create_context");
630 register_extension("WGL_ARB_create_context_profile");
631 egl_funcs
.ext
.p_wglCreateContextAttribsARB
= android_wglCreateContextAttribsARB
;
633 register_extension("WGL_ARB_extensions_string");
634 egl_funcs
.ext
.p_wglGetExtensionsStringARB
= android_wglGetExtensionsStringARB
;
636 register_extension("WGL_ARB_make_current_read");
637 egl_funcs
.ext
.p_wglGetCurrentReadDCARB
= (void *)1; /* never called */
638 egl_funcs
.ext
.p_wglMakeContextCurrentARB
= android_wglMakeContextCurrentARB
;
640 register_extension("WGL_EXT_extensions_string");
641 egl_funcs
.ext
.p_wglGetExtensionsStringEXT
= android_wglGetExtensionsStringEXT
;
643 register_extension("WGL_EXT_swap_control");
644 egl_funcs
.ext
.p_wglSwapIntervalEXT
= android_wglSwapIntervalEXT
;
645 egl_funcs
.ext
.p_wglGetSwapIntervalEXT
= android_wglGetSwapIntervalEXT
;
647 register_extension("WGL_EXT_framebuffer_sRGB");
649 /* In WineD3D we need the ability to set the pixel format more than once (e.g. after a device reset).
650 * The default wglSetPixelFormat doesn't allow this, so add our own which allows it.
652 register_extension("WGL_WINE_pixel_format_passthrough");
653 egl_funcs
.ext
.p_wglSetPixelFormatWINE
= android_wglSetPixelFormatWINE
;
655 /* load standard functions and extensions exported from the OpenGL library */
657 #define USE_GL_FUNC(func) if ((ptr = dlsym( opengl_handle, #func ))) egl_funcs.gl.p_##func = ptr;
661 #define LOAD_FUNCPTR(func) egl_funcs.ext.p_##func = dlsym( opengl_handle, #func )
662 LOAD_FUNCPTR( glActiveShaderProgram
);
663 LOAD_FUNCPTR( glActiveTexture
);
664 LOAD_FUNCPTR( glAttachShader
);
665 LOAD_FUNCPTR( glBeginQuery
);
666 LOAD_FUNCPTR( glBeginTransformFeedback
);
667 LOAD_FUNCPTR( glBindAttribLocation
);
668 LOAD_FUNCPTR( glBindBuffer
);
669 LOAD_FUNCPTR( glBindBufferBase
);
670 LOAD_FUNCPTR( glBindBufferRange
);
671 LOAD_FUNCPTR( glBindFramebuffer
);
672 LOAD_FUNCPTR( glBindImageTexture
);
673 LOAD_FUNCPTR( glBindProgramPipeline
);
674 LOAD_FUNCPTR( glBindRenderbuffer
);
675 LOAD_FUNCPTR( glBindSampler
);
676 LOAD_FUNCPTR( glBindTransformFeedback
);
677 LOAD_FUNCPTR( glBindVertexArray
);
678 LOAD_FUNCPTR( glBindVertexBuffer
);
679 LOAD_FUNCPTR( glBlendBarrierKHR
);
680 LOAD_FUNCPTR( glBlendColor
);
681 LOAD_FUNCPTR( glBlendEquation
);
682 LOAD_FUNCPTR( glBlendEquationSeparate
);
683 LOAD_FUNCPTR( glBlendFuncSeparate
);
684 LOAD_FUNCPTR( glBlitFramebuffer
);
685 LOAD_FUNCPTR( glBufferData
);
686 LOAD_FUNCPTR( glBufferSubData
);
687 LOAD_FUNCPTR( glCheckFramebufferStatus
);
688 LOAD_FUNCPTR( glClearBufferfi
);
689 LOAD_FUNCPTR( glClearBufferfv
);
690 LOAD_FUNCPTR( glClearBufferiv
);
691 LOAD_FUNCPTR( glClearBufferuiv
);
692 LOAD_FUNCPTR( glClearDepthf
);
693 LOAD_FUNCPTR( glClientWaitSync
);
694 LOAD_FUNCPTR( glCompileShader
);
695 LOAD_FUNCPTR( glCompressedTexImage2D
);
696 LOAD_FUNCPTR( glCompressedTexImage3D
);
697 LOAD_FUNCPTR( glCompressedTexSubImage2D
);
698 LOAD_FUNCPTR( glCompressedTexSubImage3D
);
699 LOAD_FUNCPTR( glCopyBufferSubData
);
700 LOAD_FUNCPTR( glCopyTexSubImage3D
);
701 LOAD_FUNCPTR( glCreateProgram
);
702 LOAD_FUNCPTR( glCreateShader
);
703 LOAD_FUNCPTR( glCreateShaderProgramv
);
704 LOAD_FUNCPTR( glDeleteBuffers
);
705 LOAD_FUNCPTR( glDeleteFramebuffers
);
706 LOAD_FUNCPTR( glDeleteProgram
);
707 LOAD_FUNCPTR( glDeleteProgramPipelines
);
708 LOAD_FUNCPTR( glDeleteQueries
);
709 LOAD_FUNCPTR( glDeleteRenderbuffers
);
710 LOAD_FUNCPTR( glDeleteSamplers
);
711 LOAD_FUNCPTR( glDeleteShader
);
712 LOAD_FUNCPTR( glDeleteSync
);
713 LOAD_FUNCPTR( glDeleteTransformFeedbacks
);
714 LOAD_FUNCPTR( glDeleteVertexArrays
);
715 LOAD_FUNCPTR( glDepthRangef
);
716 LOAD_FUNCPTR( glDetachShader
);
717 LOAD_FUNCPTR( glDisableVertexAttribArray
);
718 LOAD_FUNCPTR( glDispatchCompute
);
719 LOAD_FUNCPTR( glDispatchComputeIndirect
);
720 LOAD_FUNCPTR( glDrawArraysIndirect
);
721 LOAD_FUNCPTR( glDrawArraysInstanced
);
722 LOAD_FUNCPTR( glDrawBuffers
);
723 LOAD_FUNCPTR( glDrawElementsIndirect
);
724 LOAD_FUNCPTR( glDrawElementsInstanced
);
725 LOAD_FUNCPTR( glDrawRangeElements
);
726 LOAD_FUNCPTR( glEnableVertexAttribArray
);
727 LOAD_FUNCPTR( glEndQuery
);
728 LOAD_FUNCPTR( glEndTransformFeedback
);
729 LOAD_FUNCPTR( glFenceSync
);
730 LOAD_FUNCPTR( glFlushMappedBufferRange
);
731 LOAD_FUNCPTR( glFramebufferParameteri
);
732 LOAD_FUNCPTR( glFramebufferRenderbuffer
);
733 LOAD_FUNCPTR( glFramebufferTexture2D
);
734 LOAD_FUNCPTR( glFramebufferTextureEXT
);
735 LOAD_FUNCPTR( glFramebufferTextureLayer
);
736 LOAD_FUNCPTR( glGenBuffers
);
737 LOAD_FUNCPTR( glGenFramebuffers
);
738 LOAD_FUNCPTR( glGenProgramPipelines
);
739 LOAD_FUNCPTR( glGenQueries
);
740 LOAD_FUNCPTR( glGenRenderbuffers
);
741 LOAD_FUNCPTR( glGenSamplers
);
742 LOAD_FUNCPTR( glGenTransformFeedbacks
);
743 LOAD_FUNCPTR( glGenVertexArrays
);
744 LOAD_FUNCPTR( glGenerateMipmap
);
745 LOAD_FUNCPTR( glGetActiveAttrib
);
746 LOAD_FUNCPTR( glGetActiveUniform
);
747 LOAD_FUNCPTR( glGetActiveUniformBlockName
);
748 LOAD_FUNCPTR( glGetActiveUniformBlockiv
);
749 LOAD_FUNCPTR( glGetActiveUniformsiv
);
750 LOAD_FUNCPTR( glGetAttachedShaders
);
751 LOAD_FUNCPTR( glGetAttribLocation
);
752 LOAD_FUNCPTR( glGetBooleani_v
);
753 LOAD_FUNCPTR( glGetBufferParameteri64v
);
754 LOAD_FUNCPTR( glGetBufferParameteriv
);
755 LOAD_FUNCPTR( glGetBufferPointerv
);
756 LOAD_FUNCPTR( glGetFragDataLocation
);
757 LOAD_FUNCPTR( glGetFramebufferAttachmentParameteriv
);
758 LOAD_FUNCPTR( glGetFramebufferParameteriv
);
759 LOAD_FUNCPTR( glGetInteger64i_v
);
760 LOAD_FUNCPTR( glGetInteger64v
);
761 LOAD_FUNCPTR( glGetIntegeri_v
);
762 LOAD_FUNCPTR( glGetInternalformativ
);
763 LOAD_FUNCPTR( glGetMultisamplefv
);
764 LOAD_FUNCPTR( glGetProgramBinary
);
765 LOAD_FUNCPTR( glGetProgramInfoLog
);
766 LOAD_FUNCPTR( glGetProgramInterfaceiv
);
767 LOAD_FUNCPTR( glGetProgramPipelineInfoLog
);
768 LOAD_FUNCPTR( glGetProgramPipelineiv
);
769 LOAD_FUNCPTR( glGetProgramResourceIndex
);
770 LOAD_FUNCPTR( glGetProgramResourceLocation
);
771 LOAD_FUNCPTR( glGetProgramResourceName
);
772 LOAD_FUNCPTR( glGetProgramResourceiv
);
773 LOAD_FUNCPTR( glGetProgramiv
);
774 LOAD_FUNCPTR( glGetQueryObjectuiv
);
775 LOAD_FUNCPTR( glGetQueryiv
);
776 LOAD_FUNCPTR( glGetRenderbufferParameteriv
);
777 LOAD_FUNCPTR( glGetSamplerParameterfv
);
778 LOAD_FUNCPTR( glGetSamplerParameteriv
);
779 LOAD_FUNCPTR( glGetShaderInfoLog
);
780 LOAD_FUNCPTR( glGetShaderPrecisionFormat
);
781 LOAD_FUNCPTR( glGetShaderSource
);
782 LOAD_FUNCPTR( glGetShaderiv
);
783 LOAD_FUNCPTR( glGetStringi
);
784 LOAD_FUNCPTR( glGetSynciv
);
785 LOAD_FUNCPTR( glGetTexParameterIivEXT
);
786 LOAD_FUNCPTR( glGetTexParameterIuivEXT
);
787 LOAD_FUNCPTR( glGetTransformFeedbackVarying
);
788 LOAD_FUNCPTR( glGetUniformBlockIndex
);
789 LOAD_FUNCPTR( glGetUniformIndices
);
790 LOAD_FUNCPTR( glGetUniformLocation
);
791 LOAD_FUNCPTR( glGetUniformfv
);
792 LOAD_FUNCPTR( glGetUniformiv
);
793 LOAD_FUNCPTR( glGetUniformuiv
);
794 LOAD_FUNCPTR( glGetVertexAttribIiv
);
795 LOAD_FUNCPTR( glGetVertexAttribIuiv
);
796 LOAD_FUNCPTR( glGetVertexAttribPointerv
);
797 LOAD_FUNCPTR( glGetVertexAttribfv
);
798 LOAD_FUNCPTR( glGetVertexAttribiv
);
799 LOAD_FUNCPTR( glInvalidateFramebuffer
);
800 LOAD_FUNCPTR( glInvalidateSubFramebuffer
);
801 LOAD_FUNCPTR( glIsBuffer
);
802 LOAD_FUNCPTR( glIsFramebuffer
);
803 LOAD_FUNCPTR( glIsProgram
);
804 LOAD_FUNCPTR( glIsProgramPipeline
);
805 LOAD_FUNCPTR( glIsQuery
);
806 LOAD_FUNCPTR( glIsRenderbuffer
);
807 LOAD_FUNCPTR( glIsSampler
);
808 LOAD_FUNCPTR( glIsShader
);
809 LOAD_FUNCPTR( glIsSync
);
810 LOAD_FUNCPTR( glIsTransformFeedback
);
811 LOAD_FUNCPTR( glIsVertexArray
);
812 LOAD_FUNCPTR( glLinkProgram
);
813 LOAD_FUNCPTR( glMapBufferRange
);
814 LOAD_FUNCPTR( glMemoryBarrier
);
815 LOAD_FUNCPTR( glMemoryBarrierByRegion
);
816 LOAD_FUNCPTR( glPauseTransformFeedback
);
817 LOAD_FUNCPTR( glProgramBinary
);
818 LOAD_FUNCPTR( glProgramParameteri
);
819 LOAD_FUNCPTR( glProgramUniform1f
);
820 LOAD_FUNCPTR( glProgramUniform1fv
);
821 LOAD_FUNCPTR( glProgramUniform1i
);
822 LOAD_FUNCPTR( glProgramUniform1iv
);
823 LOAD_FUNCPTR( glProgramUniform1ui
);
824 LOAD_FUNCPTR( glProgramUniform1uiv
);
825 LOAD_FUNCPTR( glProgramUniform2f
);
826 LOAD_FUNCPTR( glProgramUniform2fv
);
827 LOAD_FUNCPTR( glProgramUniform2i
);
828 LOAD_FUNCPTR( glProgramUniform2iv
);
829 LOAD_FUNCPTR( glProgramUniform2ui
);
830 LOAD_FUNCPTR( glProgramUniform2uiv
);
831 LOAD_FUNCPTR( glProgramUniform3f
);
832 LOAD_FUNCPTR( glProgramUniform3fv
);
833 LOAD_FUNCPTR( glProgramUniform3i
);
834 LOAD_FUNCPTR( glProgramUniform3iv
);
835 LOAD_FUNCPTR( glProgramUniform3ui
);
836 LOAD_FUNCPTR( glProgramUniform3uiv
);
837 LOAD_FUNCPTR( glProgramUniform4f
);
838 LOAD_FUNCPTR( glProgramUniform4fv
);
839 LOAD_FUNCPTR( glProgramUniform4i
);
840 LOAD_FUNCPTR( glProgramUniform4iv
);
841 LOAD_FUNCPTR( glProgramUniform4ui
);
842 LOAD_FUNCPTR( glProgramUniform4uiv
);
843 LOAD_FUNCPTR( glProgramUniformMatrix2fv
);
844 LOAD_FUNCPTR( glProgramUniformMatrix2x3fv
);
845 LOAD_FUNCPTR( glProgramUniformMatrix2x4fv
);
846 LOAD_FUNCPTR( glProgramUniformMatrix3fv
);
847 LOAD_FUNCPTR( glProgramUniformMatrix3x2fv
);
848 LOAD_FUNCPTR( glProgramUniformMatrix3x4fv
);
849 LOAD_FUNCPTR( glProgramUniformMatrix4fv
);
850 LOAD_FUNCPTR( glProgramUniformMatrix4x2fv
);
851 LOAD_FUNCPTR( glProgramUniformMatrix4x3fv
);
852 LOAD_FUNCPTR( glReleaseShaderCompiler
);
853 LOAD_FUNCPTR( glRenderbufferStorage
);
854 LOAD_FUNCPTR( glRenderbufferStorageMultisample
);
855 LOAD_FUNCPTR( glResumeTransformFeedback
);
856 LOAD_FUNCPTR( glSampleCoverage
);
857 LOAD_FUNCPTR( glSampleMaski
);
858 LOAD_FUNCPTR( glSamplerParameterf
);
859 LOAD_FUNCPTR( glSamplerParameterfv
);
860 LOAD_FUNCPTR( glSamplerParameteri
);
861 LOAD_FUNCPTR( glSamplerParameteriv
);
862 LOAD_FUNCPTR( glShaderBinary
);
863 LOAD_FUNCPTR( glShaderSource
);
864 LOAD_FUNCPTR( glStencilFuncSeparate
);
865 LOAD_FUNCPTR( glStencilMaskSeparate
);
866 LOAD_FUNCPTR( glStencilOpSeparate
);
867 LOAD_FUNCPTR( glTexBufferEXT
);
868 LOAD_FUNCPTR( glTexImage3D
);
869 LOAD_FUNCPTR( glTexParameterIivEXT
);
870 LOAD_FUNCPTR( glTexParameterIuivEXT
);
871 LOAD_FUNCPTR( glTexStorage2D
);
872 LOAD_FUNCPTR( glTexStorage2DMultisample
);
873 LOAD_FUNCPTR( glTexStorage3D
);
874 LOAD_FUNCPTR( glTexSubImage3D
);
875 LOAD_FUNCPTR( glTransformFeedbackVaryings
);
876 LOAD_FUNCPTR( glUniform1f
);
877 LOAD_FUNCPTR( glUniform1fv
);
878 LOAD_FUNCPTR( glUniform1i
);
879 LOAD_FUNCPTR( glUniform1iv
);
880 LOAD_FUNCPTR( glUniform1ui
);
881 LOAD_FUNCPTR( glUniform1uiv
);
882 LOAD_FUNCPTR( glUniform2f
);
883 LOAD_FUNCPTR( glUniform2fv
);
884 LOAD_FUNCPTR( glUniform2i
);
885 LOAD_FUNCPTR( glUniform2iv
);
886 LOAD_FUNCPTR( glUniform2ui
);
887 LOAD_FUNCPTR( glUniform2uiv
);
888 LOAD_FUNCPTR( glUniform3f
);
889 LOAD_FUNCPTR( glUniform3fv
);
890 LOAD_FUNCPTR( glUniform3i
);
891 LOAD_FUNCPTR( glUniform3iv
);
892 LOAD_FUNCPTR( glUniform3ui
);
893 LOAD_FUNCPTR( glUniform3uiv
);
894 LOAD_FUNCPTR( glUniform4f
);
895 LOAD_FUNCPTR( glUniform4fv
);
896 LOAD_FUNCPTR( glUniform4i
);
897 LOAD_FUNCPTR( glUniform4iv
);
898 LOAD_FUNCPTR( glUniform4ui
);
899 LOAD_FUNCPTR( glUniform4uiv
);
900 LOAD_FUNCPTR( glUniformBlockBinding
);
901 LOAD_FUNCPTR( glUniformMatrix2fv
);
902 LOAD_FUNCPTR( glUniformMatrix2x3fv
);
903 LOAD_FUNCPTR( glUniformMatrix2x4fv
);
904 LOAD_FUNCPTR( glUniformMatrix3fv
);
905 LOAD_FUNCPTR( glUniformMatrix3x2fv
);
906 LOAD_FUNCPTR( glUniformMatrix3x4fv
);
907 LOAD_FUNCPTR( glUniformMatrix4fv
);
908 LOAD_FUNCPTR( glUniformMatrix4x2fv
);
909 LOAD_FUNCPTR( glUniformMatrix4x3fv
);
910 LOAD_FUNCPTR( glUnmapBuffer
);
911 LOAD_FUNCPTR( glUseProgram
);
912 LOAD_FUNCPTR( glUseProgramStages
);
913 LOAD_FUNCPTR( glValidateProgram
);
914 LOAD_FUNCPTR( glValidateProgramPipeline
);
915 LOAD_FUNCPTR( glVertexAttrib1f
);
916 LOAD_FUNCPTR( glVertexAttrib1fv
);
917 LOAD_FUNCPTR( glVertexAttrib2f
);
918 LOAD_FUNCPTR( glVertexAttrib2fv
);
919 LOAD_FUNCPTR( glVertexAttrib3f
);
920 LOAD_FUNCPTR( glVertexAttrib3fv
);
921 LOAD_FUNCPTR( glVertexAttrib4f
);
922 LOAD_FUNCPTR( glVertexAttrib4fv
);
923 LOAD_FUNCPTR( glVertexAttribBinding
);
924 LOAD_FUNCPTR( glVertexAttribDivisor
);
925 LOAD_FUNCPTR( glVertexAttribFormat
);
926 LOAD_FUNCPTR( glVertexAttribI4i
);
927 LOAD_FUNCPTR( glVertexAttribI4iv
);
928 LOAD_FUNCPTR( glVertexAttribI4ui
);
929 LOAD_FUNCPTR( glVertexAttribI4uiv
);
930 LOAD_FUNCPTR( glVertexAttribIFormat
);
931 LOAD_FUNCPTR( glVertexAttribIPointer
);
932 LOAD_FUNCPTR( glVertexAttribPointer
);
933 LOAD_FUNCPTR( glVertexBindingDivisor
);
934 LOAD_FUNCPTR( glWaitSync
);
937 /* redirect some standard OpenGL functions */
939 #define REDIRECT(func) \
940 do { p##func = egl_funcs.gl.p_##func; egl_funcs.gl.p_##func = w##func; } while(0)
946 static BOOL
egl_init(void)
948 static int retval
= -1;
950 EGLint major
, minor
, count
, i
, pass
;
952 if (retval
!= -1) return retval
;
955 if (!(egl_handle
= dlopen( SONAME_LIBEGL
, RTLD_NOW
|RTLD_GLOBAL
)))
957 ERR( "failed to load %s: %s\n", SONAME_LIBEGL
, dlerror() );
960 if (!(opengl_handle
= dlopen( SONAME_LIBGLESV2
, RTLD_NOW
|RTLD_GLOBAL
)))
962 ERR( "failed to load %s: %s\n", SONAME_LIBGLESV2
, dlerror() );
966 #define LOAD_FUNCPTR(func) do { \
967 if (!(p_##func = dlsym( egl_handle, #func ))) \
968 { ERR( "can't find symbol %s\n", #func); return FALSE; } \
970 LOAD_FUNCPTR( eglCreateContext
);
971 LOAD_FUNCPTR( eglCreateWindowSurface
);
972 LOAD_FUNCPTR( eglCreatePbufferSurface
);
973 LOAD_FUNCPTR( eglDestroyContext
);
974 LOAD_FUNCPTR( eglDestroySurface
);
975 LOAD_FUNCPTR( eglGetConfigAttrib
);
976 LOAD_FUNCPTR( eglGetConfigs
);
977 LOAD_FUNCPTR( eglGetDisplay
);
978 LOAD_FUNCPTR( eglGetProcAddress
);
979 LOAD_FUNCPTR( eglInitialize
);
980 LOAD_FUNCPTR( eglMakeCurrent
);
981 LOAD_FUNCPTR( eglSwapBuffers
);
982 LOAD_FUNCPTR( eglSwapInterval
);
985 display
= p_eglGetDisplay( EGL_DEFAULT_DISPLAY
);
986 if (!p_eglInitialize( display
, &major
, &minor
)) return 0;
987 TRACE( "display %p version %u.%u\n", display
, major
, minor
);
989 p_eglGetConfigs( display
, NULL
, 0, &count
);
990 configs
= HeapAlloc( GetProcessHeap(), 0, count
* sizeof(*configs
) );
991 pixel_formats
= HeapAlloc( GetProcessHeap(), 0, count
* sizeof(*pixel_formats
) );
992 p_eglGetConfigs( display
, configs
, count
, &count
);
993 if (!count
|| !configs
|| !pixel_formats
)
995 HeapFree( GetProcessHeap(), 0, configs
);
996 HeapFree( GetProcessHeap(), 0, pixel_formats
);
997 ERR( "eglGetConfigs returned no configs\n" );
1001 for (pass
= 0; pass
< 2; pass
++)
1003 for (i
= 0; i
< count
; i
++)
1005 EGLint id
, type
, visual_id
, native
, render
, color
, r
, g
, b
, d
, s
;
1007 p_eglGetConfigAttrib( display
, configs
[i
], EGL_SURFACE_TYPE
, &type
);
1008 if (!(type
& EGL_WINDOW_BIT
) == !pass
) continue;
1009 p_eglGetConfigAttrib( display
, configs
[i
], EGL_RENDERABLE_TYPE
, &render
);
1010 if (egl_client_version
== 2 && !(render
& EGL_OPENGL_ES2_BIT
)) continue;
1012 pixel_formats
[nb_pixel_formats
++].config
= configs
[i
];
1014 p_eglGetConfigAttrib( display
, configs
[i
], EGL_CONFIG_ID
, &id
);
1015 p_eglGetConfigAttrib( display
, configs
[i
], EGL_NATIVE_VISUAL_ID
, &visual_id
);
1016 p_eglGetConfigAttrib( display
, configs
[i
], EGL_NATIVE_RENDERABLE
, &native
);
1017 p_eglGetConfigAttrib( display
, configs
[i
], EGL_COLOR_BUFFER_TYPE
, &color
);
1018 p_eglGetConfigAttrib( display
, configs
[i
], EGL_RED_SIZE
, &r
);
1019 p_eglGetConfigAttrib( display
, configs
[i
], EGL_GREEN_SIZE
, &g
);
1020 p_eglGetConfigAttrib( display
, configs
[i
], EGL_BLUE_SIZE
, &b
);
1021 p_eglGetConfigAttrib( display
, configs
[i
], EGL_DEPTH_SIZE
, &d
);
1022 p_eglGetConfigAttrib( display
, configs
[i
], EGL_STENCIL_SIZE
, &s
);
1023 TRACE( "%u: config %u id %u type %x visual %u native %u render %x colortype %u rgb %u,%u,%u depth %u stencil %u\n",
1024 nb_pixel_formats
, i
, id
, type
, visual_id
, native
, render
, color
, r
, g
, b
, d
, s
);
1026 if (!pass
) nb_onscreen_formats
= nb_pixel_formats
;
1035 /* generate stubs for GL functions that are not exported on Android */
1037 #define USE_GL_FUNC(name) \
1038 static void glstub_##name(void) \
1040 ERR( #name " called\n" ); \
1048 static struct opengl_funcs egl_funcs
=
1051 android_wglCopyContext
,
1052 android_wglCreateContext
,
1053 android_wglDeleteContext
,
1054 android_wglDescribePixelFormat
,
1055 android_wglGetPixelFormat
,
1056 android_wglGetProcAddress
,
1057 android_wglMakeCurrent
,
1058 android_wglSetPixelFormat
,
1059 android_wglShareLists
,
1060 android_wglSwapBuffers
,
1062 #define USE_GL_FUNC(name) (void *)glstub_##name,
1067 struct opengl_funcs
*get_wgl_driver( UINT version
)
1069 if (version
!= WINE_WGL_DRIVER_VERSION
)
1071 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version
, WINE_WGL_DRIVER_VERSION
);
1074 if (!egl_init()) return NULL
;