Esempio n. 1
0
        GraphicsContext(OpenTK.Platform.External.ExternalGraphicsContext externalGraphicsContext)
        {
            implementation = externalGraphicsContext;

            lock (SyncRoot)
            {
                // Angle needs an embedded context
                //const GraphicsContextFlags useAngleFlag = GraphicsContextFlags.Angle
                //                                          | GraphicsContextFlags.AngleD3D9
                //                                          | GraphicsContextFlags.AngleD3D11
                //                                          | GraphicsContextFlags.AngleOpenGL;

                bool useAngle = true;
                try
                {
                    IsExternal = true;
                    IPlatformFactory factory = Factory.Embedded;

                    // Note: this approach does not allow us to mix native and EGL contexts in the same process.
                    // This should not be a problem, as this use-case is not interesting for regular applications.
                    // Note 2: some platforms may not support a direct way of getting the current context
                    // (this happens e.g. with DummyGLContext). In that case, we use a slow fallback which
                    // iterates through all known contexts and checks if any is current (check GetCurrentContext
                    // declaration).

                    if (GetCurrentContext == null)
                    {
                        GetCurrentContext = externalGraphicsContext.CreateCurrentContextDel(); // factory.CreateGetCurrentGraphicsContext();
                    }

                    available_contexts.Add((implementation as IGraphicsContextInternal).Context, this);
                    (this as IGraphicsContextInternal).LoadAll();


                    handle_cached = ((IGraphicsContextInternal)implementation).Context;
                    factory.RegisterResource(this);
                }
                catch (Exception ex)
                {
                }
            }
        }
Esempio n. 2
0
        /// <summary>Constructs a new NativeWindow with the specified attributes.</summary>
        /// <param name="x">Horizontal screen space coordinate of the NativeWindow's origin.</param>
        /// <param name="y">Vertical screen space coordinate of the NativeWindow's origin.</param>
        /// <param name="width">The width of the NativeWindow in pixels.</param>
        /// <param name="height">The height of the NativeWindow in pixels.</param>
        /// <param name="title">The title of the NativeWindow.</param>
        /// <param name="options">GameWindow options specifying window appearance and behavior.</param>
        /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the NativeWindow.</param>
        /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
        /// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
        public NativeWindow(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
        {
            // TODO: Should a constraint be added for the position?
            if (width < 1)
            {
                throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
            }
            if (height < 1)
            {
                throw new ArgumentOutOfRangeException("height", "Must be greater than zero.");
            }
            if (mode == null)
            {
                throw new ArgumentNullException("mode");
            }

            this.options = options;
            this.device  = device;

            this.thread_id = System.Threading.Thread.CurrentThread.ManagedThreadId;

            IPlatformFactory factory = Factory.Default;

            implementation = factory.CreateNativeWindow(x, y, width, height, title, mode, options, this.device);
            factory.RegisterResource(this);

            if ((options & GameWindowFlags.Fullscreen) != 0)
            {
                if (this.device != null)
                {
                    this.device.ChangeResolution(width, height, mode.ColorFormat.BitsPerPixel, 0);
                }
                WindowState = WindowState.Fullscreen;
            }

            if ((options & GameWindowFlags.FixedWindow) != 0)
            {
                WindowBorder = WindowBorder.Fixed;
            }
        }
Esempio n. 3
0
 public void RegisterResource(IDisposable resource)
 {
     default_implementation.RegisterResource(resource);
 }
Esempio n. 4
0
        /// <summary>
        /// Constructs a new GraphicsContext with the specified GraphicsMode, version and flags, and attaches it to the specified window. A dummy context will be created if both
        /// the handle and the window are null.
        /// </summary>
        /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GraphicsContext.</param>
        /// <param name="window">The OpenTK.Platform.IWindowInfo to attach the GraphicsContext to.</param>
        /// <param name="shareContext">The GraphicsContext to share resources with, or null for explicit non-sharing.</param>
        /// <param name="major">The major version of the new GraphicsContext.</param>
        /// <param name="minor">The minor version of the new GraphicsContext.</param>
        /// <param name="flags">The GraphicsContextFlags for the GraphicsContext.</param>
        /// <remarks>
        /// Different hardware supports different flags, major and minor versions. Invalid parameters will be silently ignored.
        /// </remarks>
        public GraphicsContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, int major, int minor, GraphicsContextFlags flags)
        {
            lock (SyncRoot)
            {
                bool designMode = false;
                if (mode == null && window == null)
                {
                    designMode = true;
                }
                else if (mode == null)
                {
                    throw new ArgumentNullException("mode", "Must be a valid GraphicsMode.");
                }
                else if (window == null)
                {
                    throw new ArgumentNullException("window", "Must point to a valid window.");
                }

                // Silently ignore invalid major and minor versions.
                if (major <= 0)
                {
                    major = 1;
                }
                if (minor < 0)
                {
                    minor = 0;
                }

                // Angle needs an embedded context
                const GraphicsContextFlags useAngleFlag = GraphicsContextFlags.Angle
                                                          | GraphicsContextFlags.AngleD3D9
                                                          | GraphicsContextFlags.AngleD3D11
                                                          | GraphicsContextFlags.AngleOpenGL;

                flags = useAngleFlag;
                var useAngle = false;
                if ((flags & useAngleFlag) != 0)
                {
                    flags   |= GraphicsContextFlags.Embedded;
                    useAngle = true;
                }

                Debug.WriteLine("Creating GraphicsContext.");
                try
                {
                    Debug.WriteLine("");
                    Debug.WriteLine($"GraphicsMode: {mode}");
                    Debug.WriteLine($"IWindowInfo: {window}");
                    Debug.WriteLine($"GraphicsContextFlags: {flags}");
                    Debug.WriteLine($"Requested version: {major}.{minor}");

                    // Todo: Add a DummyFactory implementing IPlatformFactory.
                    if (designMode)
                    {
                        implementation = new Platform.Dummy.DummyGLContext();
                    }
                    else
                    {
                        IPlatformFactory factory = null;
                        switch ((flags & GraphicsContextFlags.Embedded) == GraphicsContextFlags.Embedded)
                        {
                        case false:
                            factory = Factory.Default;
                            break;

                        case true:
                            factory = useAngle ? Factory.Angle : Factory.Embedded;
                            break;
                        }

                        // Note: this approach does not allow us to mix native and EGL contexts in the same process.
                        // This should not be a problem, as this use-case is not interesting for regular applications.
                        // Note 2: some platforms may not support a direct way of getting the current context
                        // (this happens e.g. with DummyGLContext). In that case, we use a slow fallback which
                        // iterates through all known contexts and checks if any is current (check GetCurrentContext
                        // declaration).
                        if (GetCurrentContext == null)
                        {
                            GetCurrentContext = factory.CreateGetCurrentGraphicsContext();
                        }

                        implementation = factory.CreateGLContext(mode, window, shareContext, DirectRendering, major, minor, flags);
                        handle_cached  = ((IGraphicsContextInternal)implementation).Context;
                        factory.RegisterResource(this);
                    }

                    AddContext(this);
                }
                catch (Exception ex)
                {
                }
                finally
                {
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Constructs a new GraphicsContext with the specified GraphicsMode, version and flags,  and attaches it to the specified window.
        /// </summary>
        /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GraphicsContext.</param>
        /// <param name="window">The OpenTK.Platform.IWindowInfo to attach the GraphicsContext to.</param>
        /// <param name="shareContext">The GraphicsContext to share resources with, or null for explicit non-sharing.</param>
        /// <param name="major">The major version of the new GraphicsContext.</param>
        /// <param name="minor">The minor version of the new GraphicsContext.</param>
        /// <param name="flags">The GraphicsContextFlags for the GraphicsContext.</param>
        /// <remarks>
        /// Different hardware supports different flags, major and minor versions. Invalid parameters will be silently ignored.
        /// </remarks>
        public GraphicsContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, int major, int minor, GraphicsContextFlags flags)
        {
            lock (SyncRoot)
            {
                bool designMode = false;
                if (mode == null && window == null)
                {
                    designMode = true;
                }
                else if (mode == null)
                {
                    throw new ArgumentNullException("mode", "Must be a valid GraphicsMode.");
                }
                else if (window == null)
                {
                    throw new ArgumentNullException("window", "Must point to a valid window.");
                }

                // Silently ignore invalid major and minor versions.
                if (major <= 0)
                {
                    major = 1;
                }
                if (minor < 0)
                {
                    minor = 0;
                }

                // Angle needs an embedded context
                var use_angle_flag = GraphicsContextFlags.Angle
                                     | GraphicsContextFlags.AngleD3D9
                                     | GraphicsContextFlags.AngleD3D11
                                     | GraphicsContextFlags.AngleOpenGL;
                var use_angle = false;
                if ((flags & use_angle_flag) != 0)
                {
                    flags    |= GraphicsContextFlags.Embedded;
                    use_angle = true;
                }

                Debug.Print("Creating GraphicsContext.");
                try
                {
                    Debug.Indent();
                    Debug.Print("GraphicsMode: {0}", mode);
                    Debug.Print("IWindowInfo: {0}", window);
                    Debug.Print("GraphicsContextFlags: {0}", flags);
                    Debug.Print("Requested version: {0}.{1}", major, minor);

                    // Todo: Add a DummyFactory implementing IPlatformFactory.
                    if (designMode)
                    {
                        implementation = new Platform.Dummy.DummyGLContext();
                    }
                    else
                    {
                        IPlatformFactory factory = null;
                        switch ((flags & GraphicsContextFlags.Embedded) == GraphicsContextFlags.Embedded)
                        {
                        case false:
                            factory = Factory.Default;
                            break;

                        case true:
                            factory = use_angle ? Factory.Angle : Factory.Embedded;
                            break;
                        }

                        GetCurrentContext = factory.CreateGetCurrentGraphicsContext();

                        implementation = factory.CreateGLContext(mode, window, shareContext, direct_rendering, major, minor, flags);
                        handle_cached  = ((IGraphicsContextInternal)implementation).Context;
                        factory.RegisterResource(this);
                    }

                    AddContext(this);
                }
                finally
                {
                    Debug.Unindent();
                }
            }
        }
Esempio n. 6
0
        public static void Init()
        {
            ToolkitOptions optionsToolkit = new ToolkitOptions()
            {
                Backend = PlatformBackend.PreferNative //for eglSwapBuffers to SwapBuffers
            };

            Toolkit.Init(optionsToolkit);

            GraphicsContextFlags flags = GraphicsContextFlags.Embedded;
            int             width      = 854;                           //800;
            int             height     = 480;                           //600;
            GraphicsMode    mode       = GraphicsMode.Default;
            string          title      = "PlayStation Suite Simulator"; //"Simple ES 2.0";
            GameWindowFlags options    = GameWindowFlags.FixedWindow;   //GameWindowFlags.Default;
            DisplayDevice   device     = DisplayDevice.Default;
            int             major      = 2;
            int             minor      = 0;

            if (mode == null)
            {
                mode = GraphicsMode.Default;
            }
            if (device == null)
            {
                device = DisplayDevice.Default;
            }
            int x = (device != null ? device.Bounds.Left + (device.Bounds.Width - width) / 2 : 0);
            int y = (device != null ? device.Bounds.Top + (device.Bounds.Height - height) / 2 : 0);

            if (width < 1)
            {
                throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
            }
            if (height < 1)
            {
                throw new ArgumentOutOfRangeException("height", "Must be greater than zero.");
            }
            if (mode == null)
            {
                throw new ArgumentNullException("mode");
            }

            g_ctx.options = options;
            g_ctx.device  = device;

            IPlatformFactory factory = Factory.Default;

            g_ctx.implementation = factory.CreateNativeWindow(x, y, width, height, title, mode, options, g_ctx.device);
            factory.RegisterResource(g_ctx);

            if ((options & GameWindowFlags.Fullscreen) != 0)
            {
                if (g_ctx.device != null)
                {
                    g_ctx.device.ChangeResolution(width, height, mode.ColorFormat.BitsPerPixel, 0);
                }
                setWindowState(WindowState.Fullscreen);
            }

            if ((options & GameWindowFlags.FixedWindow) != 0)
            {
                setWindowBorder(WindowBorder.Fixed);
            }

            try
            {
                g_ctx.glContext = new GraphicsContext(mode == null ? GraphicsMode.Default : mode, getWindowInfo(), major, minor, flags);
                g_ctx.glContext.MakeCurrent(getWindowInfo());
                (g_ctx.glContext as IGraphicsContextInternal).LoadAll();

                setVSync(VSyncMode.On);
            }
            catch (Exception e)
            {
                Debug.Print(e.ToString());
                baseDispose();
                throw;
            }

            Run_1();
        }