diff --git a/shiny/driver/gldriver/egl.go b/shiny/driver/gldriver/egl.go index 257fc27..6f5d3d7 100755 --- a/shiny/driver/gldriver/egl.go +++ b/shiny/driver/gldriver/egl.go @@ -30,13 +30,25 @@ const ( _EGL_CONFIG_CAVEAT = 0x3027 _EGL_NONE = 0x3038 + _EGL_CONTEXT_CLIENT_VERSION = 0x3098 +) + +// ANGLE specific options found in eglext.h +const ( _EGL_PLATFORM_ANGLE_ANGLE = 0x3202 _EGL_PLATFORM_ANGLE_TYPE_ANGLE = 0x3203 _EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE = 0x3204 _EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE = 0x3205 _EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE = 0x3206 - _EGL_CONTEXT_CLIENT_VERSION = 0x3098 + _EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE = 0x3207 + _EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE = 0x3208 + _EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE = 0x3209 + _EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE = 0x320A + _EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE = 0x320B + + _EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE = 0x320D + _EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE = 0x320E ) const ( diff --git a/shiny/driver/gldriver/win32.go b/shiny/driver/gldriver/win32.go index d4a88f5..7e5438e 100755 --- a/shiny/driver/gldriver/win32.go +++ b/shiny/driver/gldriver/win32.go @@ -222,28 +222,72 @@ func eglErr() error { } func createEGLSurface(hwnd syscall.Handle, w *windowImpl) error { - displayAttrib := [...]eglInt{ - _EGL_PLATFORM_ANGLE_TYPE_ANGLE, - _EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE, - _EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, _EGL_DONT_CARE, - _EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, _EGL_DONT_CARE, - _EGL_NONE, + var displayAttribPlatforms = [][]eglInt{ + // Default + []eglInt{ + _EGL_PLATFORM_ANGLE_TYPE_ANGLE, + _EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE, + _EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, _EGL_DONT_CARE, + _EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, _EGL_DONT_CARE, + _EGL_NONE, + }, + // Direct3D 11 + []eglInt{ + _EGL_PLATFORM_ANGLE_TYPE_ANGLE, + _EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, + _EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, _EGL_DONT_CARE, + _EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, _EGL_DONT_CARE, + _EGL_NONE, + }, + // Direct3D 9 + []eglInt{ + _EGL_PLATFORM_ANGLE_TYPE_ANGLE, + _EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, + _EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, _EGL_DONT_CARE, + _EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, _EGL_DONT_CARE, + _EGL_NONE, + }, + // Direct3D 11 with WARP + // https://msdn.microsoft.com/en-us/library/windows/desktop/gg615082.aspx + []eglInt{ + _EGL_PLATFORM_ANGLE_TYPE_ANGLE, + _EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, + _EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, + _EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE, + _EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, _EGL_DONT_CARE, + _EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, _EGL_DONT_CARE, + _EGL_NONE, + }, } dc, err := win32.GetDC(hwnd) if err != nil { return fmt.Errorf("win32.GetDC failed: %v", err) } - display, _, _ := eglGetPlatformDisplayEXT.Call( - _EGL_PLATFORM_ANGLE_ANGLE, - uintptr(dc), - uintptr(unsafe.Pointer(&displayAttrib)), - ) - if display == _EGL_NO_DISPLAY { - return fmt.Errorf("eglGetPlatformDisplayEXT failed: %v", eglErr()) - } - if ret, _, _ := eglInitialize.Call(display, 0, 0); ret == 0 { - return fmt.Errorf("eglInitialize failed: %v", eglErr()) + + var display uintptr = _EGL_NO_DISPLAY + for i, displayAttrib := range displayAttribPlatforms { + lastTry := i == len(displayAttribPlatforms)-1 + + display, _, _ = eglGetPlatformDisplayEXT.Call( + _EGL_PLATFORM_ANGLE_ANGLE, + uintptr(dc), + uintptr(unsafe.Pointer(&displayAttrib[0])), + ) + + if display == _EGL_NO_DISPLAY { + if !lastTry { + continue + } + return fmt.Errorf("eglGetPlatformDisplayEXT failed: %v", eglErr()) + } + + if ret, _, _ := eglInitialize.Call(display, 0, 0); ret == 0 { + if !lastTry { + continue + } + return fmt.Errorf("eglInitialize failed: %v", eglErr()) + } } eglBindAPI.Call(_EGL_OPENGL_ES_API)