public OpenGLES() { mEglConfig = null; mEglDisplay = EGL.NO_DISPLAY; mEglContext = EGL.NO_CONTEXT; Initialize(); }
public static EGLSurface CreateWindowSurface( EGLDisplay dpy, EGLConfig config, object win, int[] attrib_list) { return(new EGLSurface(eglCreateWindowSurface(dpy.Ptr, config.Ptr, win, attrib_list))); }
public static int ChooseConfig(EGLDisplay dpy, int[] attrib_list, EGLConfig[] configs, ref int num_config) { var configPtrs = new IntPtr[configs.Length]; var result = eglChooseConfig(dpy.Ptr, attrib_list, configPtrs, configPtrs.Length, ref num_config); for (var i = 0; i < configPtrs.Length; i++) { configs[i] = new EGLConfig(configPtrs[i]); } return(result); }
public static EGLContext CreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, int[] attrib_list) { return(new EGLContext(eglCreateContext(dpy.Ptr, config.Ptr, share_context.Ptr, attrib_list))); }
void Initialize() { int[] configAttributes = { EGL.RED_SIZE, 8, EGL.GREEN_SIZE, 8, EGL.BLUE_SIZE, 8, EGL.ALPHA_SIZE, 8, EGL.DEPTH_SIZE, 8, EGL.STENCIL_SIZE, 8, EGL.NONE }; int[] contextAttributes = { EGL.CONTEXT_CLIENT_VERSION, 3, EGL.NONE }; int[] defaultDisplayAttributes = { // These are the default display attributes, used to request ANGLE's D3D11 renderer. // eglInitialize will only succeed with these attributes if the hardware supports D3D11 Feature Level 10_0+. EGL.PLATFORM_ANGLE_TYPE_ANGLE, EGL.PLATFORM_ANGLE_TYPE_D3D11_ANGLE, // EGL.ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER is an optimization that can have large performance benefits on mobile devices. // Its syntax is subject to change, though. Please update your Visual Studio templates if you experience compilation issues with it. EGL.ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL.TRUE, // EGL.PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE is an option that enables ANGLE to automatically call // the IDXGIDevice3::Trim method on behalf of the application when it gets suspended. // Calling IDXGIDevice3::Trim when an application is suspended is a Windows Store application certification requirement. EGL.PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL.TRUE, EGL.NONE, }; int[] fl9_3DisplayAttributes = { // These can be used to request ANGLE's D3D11 renderer, with D3D11 Feature Level 9_3. // These attributes are used if the call to eglInitialize fails with the default display attributes. 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.ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL.TRUE, EGL.PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL.TRUE, EGL.NONE, }; int[] warpDisplayAttributes = { // These attributes can be used to request D3D11 WARP. // They are used if eglInitialize fails with both the default display attributes and the 9_3 display attributes. 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.ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL.TRUE, EGL.PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL.TRUE, EGL.NONE, }; // // To initialize the display, we make three sets of calls to eglGetPlatformDisplayEXT and eglInitialize, with varying // parameters passed to eglGetPlatformDisplayEXT: // 1) The first calls uses "defaultDisplayAttributes" as a parameter. This corresponds to D3D11 Feature Level 10_0+. // 2) If eglInitialize fails for step 1 (e.g. because 10_0+ isn't supported by the default GPU), then we try again // using "fl9_3DisplayAttributes". This corresponds to D3D11 Feature Level 9_3. // 3) If eglInitialize fails for step 2 (e.g. because 9_3+ isn't supported by the default GPU), then we try again // using "warpDisplayAttributes". This corresponds to D3D11 Feature Level 11_0 on WARP, a D3D11 software rasterizer. // // This tries to initialize EGL to D3D11 Feature Level 10_0+. See above comment for details. mEglDisplay = EGL.GetPlatformDisplayEXT(EGL.PLATFORM_ANGLE_ANGLE, EGL.DEFAULT_DISPLAY, defaultDisplayAttributes); if (mEglDisplay == EGL.NO_DISPLAY) { throw new ApplicationException("Failed to get EGL display"); } int major = 0, minor = 0; if (EGL.Initialize(mEglDisplay, ref major, ref minor) == EGL.FALSE) { // This tries to initialize EGL to D3D11 Feature Level 9_3, if 10_0+ is unavailable (e.g. on some mobile devices). mEglDisplay = EGL.GetPlatformDisplayEXT(EGL.PLATFORM_ANGLE_ANGLE, EGL.DEFAULT_DISPLAY, fl9_3DisplayAttributes); if (mEglDisplay == EGL.NO_DISPLAY) { throw new ApplicationException("Failed to get EGL display"); } if (EGL.Initialize(mEglDisplay, ref major, ref minor) == EGL.FALSE) { // This initializes EGL to D3D11 Feature Level 11_0 on WARP, if 9_3+ is unavailable on the default GPU. mEglDisplay = EGL.GetPlatformDisplayEXT(EGL.PLATFORM_ANGLE_ANGLE, EGL.DEFAULT_DISPLAY, warpDisplayAttributes); if (mEglDisplay == EGL.NO_DISPLAY) { throw new ApplicationException("Failed to get EGL display"); } if (EGL.Initialize(mEglDisplay, ref major, ref minor) == EGL.FALSE) { // If all of the calls to eglInitialize returned EGL.FALSE then an error has occurred. throw new ApplicationException("Failed to initialize EGL"); } } } int numConfigs = 0; var eglConfig = new EGLConfig[1]; if ((EGL.ChooseConfig(mEglDisplay, configAttributes, eglConfig, ref numConfigs) == EGL.FALSE) || (numConfigs == 0)) { throw new ApplicationException("Failed to choose first EGLConfig"); } else { mEglConfig = eglConfig[0]; } mEglContext = EGL.CreateContext(mEglDisplay, mEglConfig, EGL.NO_CONTEXT, contextAttributes); if (mEglContext == EGL.NO_CONTEXT) { throw new ApplicationException("Failed to create EGL context"); } }