public GraphicsContext(GraphicsMode mode, IWindowInfo window, int major, int minor, GraphicsContextFlags flags) { lock (GraphicsContext.SyncRoot) { bool local_0 = false; if (mode == null && window == null) { local_0 = true; } else { if (mode == null) { throw new ArgumentNullException("mode", "Must be a valid GraphicsMode."); } if (window == null) { throw new ArgumentNullException("window", "Must point to a valid window."); } } if (major <= 0) { major = 1; } if (minor < 0) { minor = 0; } IGraphicsContext local_1_1 = GraphicsContext.FindSharedContext(); if (local_0) { this.implementation = (IGraphicsContext) new DummyGLContext(); } else { IPlatformFactory local_2 = (IPlatformFactory)null; switch ((flags & GraphicsContextFlags.Embedded) == GraphicsContextFlags.Embedded) { case false: local_2 = Factory.Default; break; case true: local_2 = Factory.Embedded; break; } this.implementation = local_2.CreateGLContext(mode, window, local_1_1, GraphicsContext.direct_rendering, major, minor, flags); if (GraphicsContext.GetCurrentContext == null) { GraphicsContext.GetCurrentContextDelegate local_3 = local_2.CreateGetCurrentGraphicsContext(); if (local_3 != null) { GraphicsContext.GetCurrentContext = local_3; } } } GraphicsContext.available_contexts.Add(this.Context, new WeakReference((object)this)); } }
public GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext() { return(default_implementation.CreateGetCurrentGraphicsContext()); }
/// <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 { } } }
/// <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="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, 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; } 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); IGraphicsContext shareContext = shareContext = FindSharedContext(); // 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 = Factory.Embedded; break; } implementation = factory.CreateGLContext(mode, window, shareContext, direct_rendering, major, minor, flags); // 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) { GetCurrentContextDelegate temp = factory.CreateGetCurrentGraphicsContext(); if (temp != null) { GetCurrentContext = temp; } } } available_contexts.Add((this as IGraphicsContextInternal).Context, new WeakReference(this)); } finally { Debug.Unindent(); } } }
/// <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(); } } }