public override IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
        {
            WinWindowInfo win_win     = (WinWindowInfo)window;
            IntPtr        egl_display = GetDisplay(win_win.DeviceContext);
            EglWindowInfo egl_win     = new OpenTK.Platform.Egl.EglWindowInfo(win_win.Handle, egl_display);

            return(new EglWinContext(handle, egl_win, shareContext, major, minor, flags));
        }
        public override IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
        {
            WinWindowInfo win_win     = (WinWindowInfo)window;
            EGLDisplay    egl_display = Egl.GetDisplay(EGLNativeDisplayType.Default); // Egl.GetDisplay(new EGLNativeDisplayType(win_win.DeviceContext));
            EglWindowInfo egl_win     = new OpenTK.Platform.Egl.EglWindowInfo(win_win.WindowHandle, egl_display);

            return(new EglContext(mode, egl_win, shareContext, major, minor, flags));
        }
Exemple #3
0
        public override IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
        {
            WinWindowInfo winWindowInfo = (WinWindowInfo)window;
            IntPtr        display       = this.GetDisplay(winWindowInfo.DeviceContext);
            EglWindowInfo window1       = new EglWindowInfo(winWindowInfo.WindowHandle, display);

            return((IGraphicsContext) new EglContext(handle, window1, shareContext, major, minor, flags));
        }
        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);
        }