WinRT: improved OpenGL ES compatibility on WinPhone/ARM and Surface RT
authorDavid Ludwig <dludwig@pobox.com>
Sun, 15 Feb 2015 11:53:24 -0500
changeset 9350419c75bb3cd4
parent 9349 7674af9a59c8
child 9351 483c411e8e11
WinRT: improved OpenGL ES compatibility on WinPhone/ARM and Surface RT

This change integrates initialization settings for ANGLE/WinRT, as suggested in
MSOpenTech's latest ANGLE template-projects (for MSVC).

This should fix some OpenGL initialization issues on WinPhone 8.1 on ARM, and
on the 1st-generation Surface RT.
src/video/winrt/SDL_winrtopengles.cpp
     1.1 --- a/src/video/winrt/SDL_winrtopengles.cpp	Sun Feb 15 11:35:07 2015 +0100
     1.2 +++ b/src/video/winrt/SDL_winrtopengles.cpp	Sun Feb 15 11:53:24 2015 -0500
     1.3 @@ -36,10 +36,15 @@
     1.4  
     1.5  /* ANGLE/WinRT constants */
     1.6  static const int ANGLE_D3D_FEATURE_LEVEL_ANY = 0;
     1.7 -#define EGL_PLATFORM_ANGLE_ANGLE                0x3201
     1.8 -#define EGL_PLATFORM_ANGLE_TYPE_ANGLE           0x3202
     1.9 -#define EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE   0x3205
    1.10 -#define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE     0x3207
    1.11 +#define EGL_PLATFORM_ANGLE_ANGLE                        0x3201
    1.12 +#define EGL_PLATFORM_ANGLE_TYPE_ANGLE                   0x3202
    1.13 +#define EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE      0x3204
    1.14 +#define EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE      0x3203
    1.15 +#define EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE           0x3205
    1.16 +#define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE             0x3207
    1.17 +#define EGL_PLATFORM_ANGLE_USE_WARP_ANGLE               0x3208
    1.18 +#define EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER   0x320B
    1.19 +
    1.20  
    1.21  /*
    1.22   * SDL/EGL top-level implementation
    1.23 @@ -82,9 +87,35 @@
    1.24          if (!_this->egl_data->egl_display) {
    1.25              return SDL_SetError("Could not get EGL display");
    1.26          }
    1.27 +
    1.28 +        if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
    1.29 +            return SDL_SetError("Could not initialize EGL");
    1.30 +        }
    1.31      } else {
    1.32 -        const EGLint displayAttributes[] = {
    1.33 +        /* Declare some ANGLE/EGL initialization property-sets, as suggested by
    1.34 +         * MSOpenTech's ANGLE-for-WinRT template apps:
    1.35 +         */
    1.36 +        const EGLint defaultDisplayAttributes[] =
    1.37 +        {
    1.38              EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
    1.39 +            EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE, 
    1.40 +            EGL_NONE,
    1.41 +        };
    1.42 +
    1.43 +        const EGLint fl9_3DisplayAttributes[] =
    1.44 +        {
    1.45 +            EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
    1.46 +            EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, 9,
    1.47 +            EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, 3,
    1.48 +            EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE, 
    1.49 +            EGL_NONE,
    1.50 +        };
    1.51 +
    1.52 +        const EGLint warpDisplayAttributes[] =
    1.53 +        {
    1.54 +            EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
    1.55 +            EGL_PLATFORM_ANGLE_USE_WARP_ANGLE, EGL_TRUE,
    1.56 +            EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE, 
    1.57              EGL_NONE,
    1.58          };
    1.59  
    1.60 @@ -99,14 +130,41 @@
    1.61              return SDL_SetError("Could not retrieve ANGLE/WinRT display function(s)");
    1.62          }
    1.63  
    1.64 -        _this->egl_data->egl_display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, displayAttributes);
    1.65 +#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP)
    1.66 +        /* Try initializing EGL at D3D11 Feature Level 10_0+ (which is not
    1.67 +         * supported on WinPhone 8.x.
    1.68 +         */
    1.69 +        _this->egl_data->egl_display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, defaultDisplayAttributes);
    1.70          if (!_this->egl_data->egl_display) {
    1.71              return SDL_SetError("Could not get EGL display");
    1.72          }
    1.73 -    }
    1.74  
    1.75 -    if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
    1.76 -        return SDL_SetError("Could not initialize EGL");
    1.77 +        if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE)
    1.78 +#endif
    1.79 +        {
    1.80 +            /* Try initializing EGL at D3D11 Feature Level 9_3, in case the
    1.81 +             * 10_0 init fails, or we're on Windows Phone (which only supports
    1.82 +             * 9_3).
    1.83 +             */
    1.84 +            _this->egl_data->egl_display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, fl9_3DisplayAttributes);
    1.85 +            if (!_this->egl_data->egl_display) {
    1.86 +                return SDL_SetError("Could not get 9_3 EGL display");
    1.87 +            }
    1.88 +
    1.89 +            if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
    1.90 +                /* Try initializing EGL at D3D11 Feature Level 11_0 on WARP
    1.91 +                 * (a Windows-provided, software rasterizer) if all else fails.
    1.92 +                 */
    1.93 +                _this->egl_data->egl_display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, warpDisplayAttributes);
    1.94 +                if (!_this->egl_data->egl_display) {
    1.95 +                    return SDL_SetError("Could not get WARP EGL display");
    1.96 +                }
    1.97 +
    1.98 +                if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
    1.99 +                    return SDL_SetError("Could not initialize EGL");
   1.100 +                }
   1.101 +            }
   1.102 +        }
   1.103      }
   1.104  
   1.105      return 0;