Ejemplo n.º 1
0
        IntPtr TryInitEglDisplay(IWindowInfo window, ref int major, ref int minor, ref GraphicsContextFlags flags)
        {
            //see https://github.com/Microsoft/angle/wiki/Initializing-ANGLE-on-D3D11-Feature-Level-9
            //IntPtr egl_display1 = Egl.GetPlatformDisplayEXT(Egl.PLATFORM_ANGLE_ANGLE, IntPtr.Zero, new int[]{
            //    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,
            //});
            //if (!Egl.Initialize(egl_display1, out int m1, out int m2))
            //{
            //}
            //1. use default openTK default
            WinWindowInfo win_win = (WinWindowInfo)window;
            bool          success = false;
            int           eglMajor, eglMinor;
            IntPtr        egl_display = IntPtr.Zero;

            if (isFirstTimeEval)
            {
                isFirstTimeEval = false;
                egl_display     = GetDisplay(win_win.DeviceContext);
                success         = Egl.Initialize(egl_display, out eglMajor, out eglMinor);

                //-------------------
                //we found that some old machine can't init with D3D11
                //so ... we use D3D9 instead
                if (!success)
                {
                    egl_display = Egl.GetPlatformDisplayEXT(Egl.PLATFORM_ANGLE_ANGLE, IntPtr.Zero, new int[] {
                        Egl.PLATFORM_ANGLE_TYPE_ANGLE,
                        Egl.PLATFORM_ANGLE_TYPE_D3D9_ANGLE,
                        Egl.NONE,
                    });
                    if (Egl.Initialize(egl_display, out eglMajor, out eglMinor))
                    {
                        useD3D9Only = true;
                        success     = true;
                        //in this case
                        major = 2;                                        //GLES2
                        minor = 1;
                        flags = flags & ~GraphicsContextFlags.AngleD3D11; //can't use D3D11
                    }
                    else
                    {
                        throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError()));
                    }
                }
            }
            else
            {
                //not first time
                if (useD3D9Only)
                {
                    //no D3D11
                    egl_display = Egl.GetPlatformDisplayEXT(Egl.PLATFORM_ANGLE_ANGLE, IntPtr.Zero, new int[] {
                        Egl.PLATFORM_ANGLE_TYPE_ANGLE,
                        Egl.PLATFORM_ANGLE_TYPE_D3D9_ANGLE,
                        Egl.NONE,
                    });
                    if (Egl.Initialize(egl_display, out eglMajor, out eglMinor))
                    {
                        useD3D9Only = true;
                        success     = true;
                        //in this case
                        major = 2;                                        //GLES2
                        minor = 1;
                        flags = flags & ~GraphicsContextFlags.AngleD3D11; //can't use D3D11
                    }
                    else
                    {
                        throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError()));
                    }
                }
                else
                {
                    //use D3D11
                    egl_display = GetDisplay(win_win.DeviceContext);
                    success     = Egl.Initialize(egl_display, out eglMajor, out eglMinor);

                    //-------------------
                    //we found that some old machine can't init with D3D11
                    //so ... we use D3D9 instead
                    if (!success)
                    {
                        //???
                        throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError()));
                    }
                }
            }
            return(egl_display);
        }