internal ILOGLPanel() : base(GraphicDeviceType.OpenGL) { #if TRACE Trace.TraceInformation("{0},{1} ILOGLPanel.ctor(mode) start", DateTime.Now, Environment.TickCount); Trace.Indent(); #endif this.SetStyle(ControlStyles.Opaque, true); this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); m_format = GraphicsMode.Default; if (Configuration.RunningOnWindows) { m_implementation = new OpenTK.Platform.Windows.WinGLControl(m_format, this); } else if (Configuration.RunningOnX11) { m_implementation = new OpenTK.Platform.X11.X11GLControl(m_format, this); } else if (Configuration.RunningOnOSX) { throw new PlatformNotSupportedException("Refer to http://www.opentk.com for more information."); } this.CreateControl(); #if TRACE Trace.Unindent(); Trace.TraceInformation("{0},{1} ILPanel.ctor(mode) end", DateTime.Now, Environment.TickCount); #endif }
/// <summary> /// Raises the HandleCreated event. /// </summary> /// <param name="e">Not used.</param> protected override void OnHandleCreated(EventArgs e) { if (!(_implementation is DummyGLControl)) { // No need to recreate our DummyGLControl _context?.Dispose(); _implementation?.WindowInfo.Dispose(); if (_designMode) { _implementation = new DummyGLControl(); _context = _implementation.CreateContext(_major, _minor, _flags); HasValidContext = false; } else { try { _implementation = new GLControlFactory().CreateGLControl(_format, this); _context = _implementation.CreateContext(_major, _minor, _flags); HasValidContext = true; } catch (GraphicsModeException) { _implementation = new DummyGLControl(); _context = _implementation.CreateContext(_major, _minor, _flags); HasValidContext = false; } } MakeCurrent(); if (HasValidContext) { ((IGraphicsContextInternal)_context).LoadAll(); } // Deferred setting of vsync mode. See VSync property for more information. if (_initialVsyncValue.HasValue) { _context.SwapInterval = _initialVsyncValue.Value ? 1 : 0; _initialVsyncValue = null; } } base.OnHandleCreated(e); if (_resizeEventSuppressed) { OnResize(EventArgs.Empty); _resizeEventSuppressed = false; } }
/// <summary>Raises the HandleCreated event.</summary> /// <param name="e">Not used.</param> protected override void OnHandleCreated(EventArgs e) { if (UseOpenGL) { if (context != null) { context.Dispose(); } if (implementation != null) { implementation.WindowInfo.Dispose(); } if (design_mode) { implementation = new DummyGLControl(); } else { implementation = new GLControlFactory().CreateGLControl(format, this); } context = implementation.CreateContext(major, minor, flags); MakeCurrent(); if (!design_mode) { ((IGraphicsContextInternal)Context).LoadAll(); } // Deferred setting of vsync mode. See VSync property for more information. if (initial_vsync_value.HasValue) { Context.VSync = initial_vsync_value.Value; initial_vsync_value = null; } } base.OnHandleCreated(e); if (UseOpenGL) { if (resize_event_suppressed) { OnResize(EventArgs.Empty); resize_event_suppressed = false; } } }
/// <summary>Raises the HandleDestroyed event.</summary> /// <param name="e">Not used.</param> protected override void OnHandleDestroyed(EventArgs e) { if (context != null) { context.Dispose(); context = null; } if (implementation != null) { implementation.WindowInfo.Dispose(); implementation = null; } base.OnHandleDestroyed(e); }
/// <summary>Raises the HandleCreated event.</summary> /// <param name="e">Not used.</param> protected override void OnHandleCreated(EventArgs e) { context?.Dispose(); implementation?.WindowInfo?.Dispose(); // Test the current flags flags = GetUsableContextFlags(flags); if ((flags & GraphicsContextFlags.AngleD3D9) > 0) { if (ConfigManager.sFullscreen) { ForcedWindowed = false; flags |= GraphicsContextFlags.AngleFullscreen; } else { ForcedWindowed = true; } } implementation = design_mode ? new DummyGLControl() : new GLControlFactory().CreateGLControl(format, this, flags); context = implementation.CreateContext(major, minor, flags); MakeCurrent(); if (!design_mode) { ((IGraphicsContextInternal)context).LoadAll(); } // Deferred setting of vsync mode. See VSync property for more information. if (initial_vsync_value.HasValue) { Context.SwapInterval = initial_vsync_value.Value ? 1 : 0; initial_vsync_value = null; } base.OnHandleCreated(e); if (resize_event_suppressed) { OnResize(EventArgs.Empty); resize_event_suppressed = false; } }
/// <summary>Raises the HandleCreated event.</summary> /// <param name="e">Not used.</param> protected override void OnHandleCreated(EventArgs e) { if (_dummyContext != null) { _dummyContext.Dispose(); } if (implementation != null) { implementation.WindowInfo.Dispose(); } if (Configuration.RunningOnWindows) { implementation = new WinGLControl(_graphics.Mode, this); } //else if (Configuration.RunningOnMacOS) return new CarbonGLControl(mode, control); //else if (Configuration.RunningOnX11) return new X11GLControl(mode, control); else { throw new PlatformNotSupportedException(); } _dummyContext = implementation.CreateContext(1, 1, GraphicsContextFlags.Default); MakeCurrent(); if (!design_mode) { ((IGraphicsContextInternal)Context).LoadAll(); } // Deferred setting of vsync mode. See VSync property for more information. if (initial_vsync_value.HasValue) { _graphics.GraphicsContext.SwapInterval = initial_vsync_value.Value ? 1 : 0; initial_vsync_value = null; } base.OnHandleCreated(e); if (resize_event_suppressed) { OnResize(EventArgs.Empty); resize_event_suppressed = false; } }
/// <summary>Raises the HandleDestroyed event.</summary> /// <param name="e">Not used.</param> protected override void OnHandleDestroyed(EventArgs e) { // Ensure that context is still alive when passing to events // => This allows to perform cleanup operations in OnHandleDestroyed handlers base.OnHandleDestroyed(e); if (context != null) { context.Dispose(); context = null; } if (implementation != null) { implementation.WindowInfo.Dispose(); implementation = null; } }
/// <summary>Raises the HandleDestroyed event.</summary> /// <param name="e">Not used.</param> protected override void OnHandleDestroyed(EventArgs e) { // Ensure that context is still alive when passing to events // => This allows to perform cleanup operations in OnHandleDestroyed handlers base.OnHandleDestroyed(e); if (_implementation is DummyGLControl) { // No need to destroy our DummyGLControl return; } if (_context != null) { _context.Dispose(); _context = null; } if (_implementation != null) { _implementation.WindowInfo.Dispose(); _implementation = null; } }
/// <summary>Raises the HandleDestroyed event.</summary> /// <param name="e">Not used.</param> protected override void OnHandleDestroyed(EventArgs e) { if (context != null) { context.Dispose(); context = null; } if (implementation != null) { implementation.WindowInfo.Dispose(); implementation = null; } base.OnHandleDestroyed(e); }
/// <summary>Raises the HandleCreated event.</summary> /// <param name="e">Not used.</param> protected override void OnHandleCreated(EventArgs e) { if (context != null) context.Dispose(); if (implementation != null) implementation.WindowInfo.Dispose(); if (DesignMode) implementation = new DummyGLControl(); else implementation = GLControlFactory.CreateGLControl(format, this); context = implementation.CreateContext(major, minor, flags); MakeCurrent(); if (!DesignMode) ((IGraphicsContextInternal)Context).LoadAll(); // Deferred setting of vsync mode. See VSync property for more information. if (initial_vsync_value.HasValue) { Context.VSync = initial_vsync_value.Value; initial_vsync_value = null; } base.OnHandleCreated(e); if (resize_event_suppressed) { OnResize(EventArgs.Empty); resize_event_suppressed = false; } }
internal ILOGLPanel() : base( GraphicDeviceType.OpenGL ) { #if TRACE Trace.TraceInformation("{0},{1} ILOGLPanel.ctor(mode) start",DateTime.Now, Environment.TickCount); Trace.Indent(); #endif this.SetStyle(ControlStyles.Opaque, true); this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); m_format = GraphicsMode.Default; if (Configuration.RunningOnWindows) m_implementation = new OpenTK.Platform.Windows.WinGLControl(m_format, this); else if (Configuration.RunningOnX11) m_implementation = new OpenTK.Platform.X11.X11GLControl(m_format, this); else if (Configuration.RunningOnOSX) throw new PlatformNotSupportedException("Refer to http://www.opentk.com for more information."); this.CreateControl(); #if TRACE Trace.Unindent(); Trace.TraceInformation("{0},{1} ILPanel.ctor(mode) end",DateTime.Now, Environment.TickCount); #endif }
/// <summary>Raises the HandleCreated event.</summary> /// <param name="e">Not used.</param> protected override void OnHandleCreated(EventArgs e) { if (_dummyContext != null) _dummyContext.Dispose(); if (implementation != null) implementation.WindowInfo.Dispose(); if (Configuration.RunningOnWindows) implementation = new WinGLControl(_graphics.Mode, this); //else if (Configuration.RunningOnMacOS) return new CarbonGLControl(mode, control); //else if (Configuration.RunningOnX11) return new X11GLControl(mode, control); else throw new PlatformNotSupportedException(); _dummyContext = implementation.CreateContext(1, 1, GraphicsContextFlags.Default); MakeCurrent(); if (!design_mode) ((IGraphicsContextInternal)Context).LoadAll(); // Deferred setting of vsync mode. See VSync property for more information. if (initial_vsync_value.HasValue) { _graphics.GraphicsContext.SwapInterval = initial_vsync_value.Value ? 1 : 0; initial_vsync_value = null; } base.OnHandleCreated(e); if (resize_event_suppressed) { OnResize(EventArgs.Empty); resize_event_suppressed = false; } }
/// <summary>Raises the HandleDestroyed event.</summary> /// <param name="e">Not used.</param> protected override void OnHandleDestroyed(EventArgs e) { // Ensure that context is still alive when passing to events // => This allows to perform cleanup operations in OnHandleDestroyed handlers base.OnHandleDestroyed(e); if (context != null) { context.Dispose(); context = null; } if (implementation != null) { implementation.WindowInfo.Dispose(); implementation = null; } }
GraphicsContextFlags GetUsableContextFlags(GraphicsContextFlags flags) { Control temp_control = null; IGraphicsContext temp_context = null; IGLControl temp_implementation = null; Exception exc = null; switch (flags) { default: { return(GetUsableContextFlags(GraphicsContextFlags.Default)); } case GraphicsContextFlags.Angle: { return(GetUsableContextFlags(GraphicsContextFlags.AngleD3D9)); } case GraphicsContextFlags.Default: case GraphicsContextFlags.AngleD3D11: case GraphicsContextFlags.AngleD3D9: { try { temp_control = new Control(); temp_control.CreateControl(); if (flags == GraphicsContextFlags.AngleD3D11) { major = 3; } if (flags == GraphicsContextFlags.AngleD3D9) { major = 2; } temp_implementation = design_mode ? new DummyGLControl() : new GLControlFactory().CreateGLControl(format, temp_control, flags); temp_context = temp_implementation.CreateContext(major, minor, flags); temp_context.MakeCurrent(temp_implementation.WindowInfo); if (!design_mode) { ((IGraphicsContextInternal)temp_context).LoadAll(); } // Enforce a minimum version for default renderer for maximum compatibility if (flags == GraphicsContextFlags.Default && new Version(GL.GetString(StringName.Version).Split(' ')[0]) < new Version(major, minor)) { throw new Exception("Unsupported version, using ANGLE."); } } catch (Exception e) { exc = e; } } break; } temp_control?.Dispose(); temp_context?.Dispose(); temp_implementation?.WindowInfo?.Dispose(); if (exc != null) { switch (flags) { case GraphicsContextFlags.Default: return(GetUsableContextFlags(GraphicsContextFlags.Angle)); case GraphicsContextFlags.AngleD3D11: return(GetUsableContextFlags(GraphicsContextFlags.AngleD3D9)); case GraphicsContextFlags.AngleD3D9: throw new NoGLContextAvailable(exc); } } return(flags); }
IGraphicsContext GetContext() { if (context != null) { context.Dispose(); } if (implementation == null) { Log.AppendLine("Attempting to create native OpenGL context."); implementation = design_mode ? new DummyGLControl() : new GLControlFactory().CreateGLControl(format, this, GraphicsContextFlags.Default); try { context = implementation.CreateContext(major, minor, GraphicsContextFlags.Default); MakeCurrent(); } catch (Exception e) { Log.AppendLine("Failed to create native OpenGL context."); Log.AppendLine(e.ToString()); Log.AppendLine("Reverting to ANGLE."); flags = GraphicsContextFlags.Angle; return(GetContext()); } if (!design_mode) { ((IGraphicsContextInternal)Context).LoadAll(); Log.AppendLine("Loaded all endpoints."); } // Check if version < required version if (new Version(GL.GetString(StringName.Version).Split(' ')[0]) < new Version(major, minor)) { Log.AppendLine("Native OpenGL context version is incompatible, reverting to ANGLE."); flags = GraphicsContextFlags.Angle; return(GetContext()); } Log.AppendLine("Successfully created native OpenGL context."); if (flags == GraphicsContextFlags.Default) { Log.AppendLine("Using native OpenGL context."); // We're using the default OpenGL renderer, exit early return(context); } } // If we reach this point, we need to use Angle if (flags == GraphicsContextFlags.Angle) { try { Log.AppendLine("Attempting to create ANGLED3D11 context."); // Try D3D11 major = 3; minor = 0; flags = GraphicsContextFlags.AngleD3D11; return(GetContext()); } catch (Exception e) { Log.AppendLine("Failed to create ANGLED3D11 context."); Log.AppendLine(e.ToString()); Log.AppendLine("Reverting to ANGLED3D9."); try { Log.AppendLine("Attempting to create ANGLED3D9 context."); // Default to D3D9 (this should never fail) major = 2; minor = 0; flags = GraphicsContextFlags.AngleD3D9; return(GetContext()); } catch (Exception e2) { Log.AppendLine("Failed to create ANGLED3D9 context. Oops."); Log.AppendLine(e.ToString()); return(null); } } } implementation = design_mode ? new DummyGLControl() : new GLControlFactory().CreateGLControl(format, this, flags); context = implementation.CreateContext(major, minor, flags); MakeCurrent(); if (!design_mode) { ((IGraphicsContextInternal)Context).LoadAll(); Log.AppendLine("Loaded all endpoints."); } Log.AppendLine($"Using {(flags == GraphicsContextFlags.AngleD3D11 ? "ANGLED3D11" : "ANGLED3D9")} context."); return(context); }