Skip to content

Initializing ANGLE on D3D11 Feature Level 9

Shawn Hargreaves edited this page Jun 16, 2016 · 3 revisions

EGL initialization on some D3D11 Feature Level 9 hardware (e.g. Windows Phones, Surface RT) requires more than a call to eglGetDisplay(). This wiki page explains how to initialize EGL on these devices.

Short answer

To initialize your Windows Store App for OpenGL ES using ANGLE, we highly recommend using our Visual Studio templates. These templates perform all of the OpenGL ES API calls necessary to initialize your Windows Store app on any supported hardware, ranging from desktop PCs to Surface RTs and Windows Phones.

Long answer

By default, EGL APIs such as eglGetDisplay do not expose D3D11 Feature Level 9. We have collaborated with Google to design a mechanism to expose D3D11 Feature Level 9 to an app when it specifically requests it via the ANGLE extension procedure eglGetPlatformDisplayEXT.

Here’s a snippet of code showing how to initialize an EGL display to D3D11 Feature Level 9.3:

const EGLint displayAttributes[] =
{
    EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
    EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, 9,
    EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, 3,
    EGL_NONE,
};

PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(eglGetProcAddress("eglGetPlatformDisplayEXT"));

if (!eglGetPlatformDisplayEXT)
{
    throw Exception::CreateException(E_FAIL, L"Failed to get function eglGetPlatformDisplayEXT");
}

mEglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, displayAttributes);
if (mEglDisplay == EGL_NO_DISPLAY)
{
    throw Exception::CreateException(E_FAIL, L"Failed to get EGL display");
}

if (eglInitialize(mEglDisplay, NULL, NULL) == EGL_FALSE)
{
    throw Exception::CreateException(E_FAIL, L"Failed to initialize EGL");
}

To get Feature Level 9.3, the EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE attribute has been set to 9 and the EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE attribute has been set to 3.

The ms-master branch of ANGLE supports D3D11 Feature Levels 9.3 and above. To initialize EGL on a platform whose default GPU doesn’t support 9.3 or above (such as a Surface RT), you must use WARP. WARP is a fully-featured software rasterizer for D3D11 which supports D3D11 Feature Level 11_0. To use WARP, you should set the EGL_PLATFORM_ANGLE_USE_WARP_ANGLE attribute to EGL_TRUE in your display attributes list.