diff --git a/src/OpenTK/Minimal.cs b/src/OpenTK/Minimal.cs index 5a61ea6c..66986613 100644 --- a/src/OpenTK/Minimal.cs +++ b/src/OpenTK/Minimal.cs @@ -227,7 +227,9 @@ namespace OpenTK public override bool Equals(object obj) { if (obj is PointF) + { return Equals((PointF)obj); + } return false; } @@ -286,7 +288,9 @@ namespace OpenTK set { if (width < 0) + { throw new ArgumentOutOfRangeException(); + } width = value; } } @@ -300,7 +304,9 @@ namespace OpenTK set { if (height < 0) + { throw new ArgumentOutOfRangeException(); + } height = value; } } @@ -353,7 +359,9 @@ namespace OpenTK public override bool Equals(object obj) { if (obj is SizeF) + { return Equals((SizeF)obj); + } return false; } @@ -578,7 +586,9 @@ namespace OpenTK public override bool Equals(object obj) { if (obj is RectangleF) + { return Equals((RectangleF)obj); + } return false; } @@ -789,7 +799,9 @@ namespace OpenTK public override bool Equals(object obj) { if (!(obj is Color)) + { return false; + } return Equals((Color)obj); } diff --git a/src/OpenTK/Platform/Factory.cs b/src/OpenTK/Platform/Factory.cs index 7c0f430a..5274bcf8 100644 --- a/src/OpenTK/Platform/Factory.cs +++ b/src/OpenTK/Platform/Factory.cs @@ -90,7 +90,10 @@ namespace OpenTK.Platform Embedded = Default; } #if IPHONE - else if (Configuration.RunningOnIOS) Embedded = new iPhoneOS.iPhoneFactory(); + else if (Configuration.RunningOnIOS) + { + Embedded = new iPhoneOS.iPhoneFactory(); + } #else else if (Egl.Egl.IsSupported) { diff --git a/src/OpenTK/Platform/iPhoneOS/iPhoneFactory.cs b/src/OpenTK/Platform/iPhoneOS/iPhoneFactory.cs index 76d8aedd..7887bfd2 100644 --- a/src/OpenTK/Platform/iPhoneOS/iPhoneFactory.cs +++ b/src/OpenTK/Platform/iPhoneOS/iPhoneFactory.cs @@ -1,4 +1,3 @@ -#region License // // The Open Toolkit Library License // @@ -7,7 +6,7 @@ // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights to +// in the Software without restriction, including without limitation the rights to // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of // the Software, and to permit persons to whom the Software is furnished to do // so, subject to the following conditions: @@ -24,7 +23,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. // -#endregion using System; using System.Collections.Generic; @@ -38,8 +36,6 @@ namespace OpenTK.Platform.iPhoneOS { class iPhoneFactory : PlatformFactoryBase { - #region IPlatformFactory Members - public override IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) { return new iPhoneOS.iPhoneOSGraphicsContext(mode, window, shareContext, major, minor, flags); @@ -56,7 +52,9 @@ namespace OpenTK.Platform.iPhoneOS EAGLContext c = EAGLContext.CurrentContext; IntPtr h = IntPtr.Zero; if (c != null) + { h = c.Handle; + } return new ContextHandle(h); }; } @@ -85,7 +83,5 @@ namespace OpenTK.Platform.iPhoneOS { throw new NotImplementedException(); } - - #endregion } } diff --git a/src/OpenTK/Platform/iPhoneOS/iPhoneOSGameView.cs b/src/OpenTK/Platform/iPhoneOS/iPhoneOSGameView.cs index ea42e3ca..ecc58757 100644 --- a/src/OpenTK/Platform/iPhoneOS/iPhoneOSGameView.cs +++ b/src/OpenTK/Platform/iPhoneOS/iPhoneOSGameView.cs @@ -1,4 +1,3 @@ -#region --- License --- /* Licensed under the MIT/X11 license. * Copyright (c) 2009 Novell, Inc. * Copyright 2013 Xamarin Inc @@ -6,7 +5,6 @@ * See license.txt for licensing detailed licensing details. */ // Copyright 2011 Xamarin Inc. All rights reserved. -#endregion using System; using System.ComponentModel; @@ -149,7 +147,9 @@ namespace OpenTK.Platform.iPhoneOS this.view = view; if (displayLink != null) + { displayLink.Invalidate (); + } displayLink = CADisplayLink.Create (this, selRunIteration); displayLink.FrameInterval = frameInterval; @@ -211,7 +211,9 @@ namespace OpenTK.Platform.iPhoneOS public void Resume () { if (timeout != new TimeSpan (-1)) + { timer = NSTimer.CreateRepeatingScheduledTimer (timeout, view.RunIteration); + } } public void Invalidate () @@ -262,13 +264,17 @@ namespace OpenTK.Platform.iPhoneOS void AssertValid() { if (disposed) + { throw new ObjectDisposedException(""); + } } void AssertContext() { if (GraphicsContext == null) + { throw new InvalidOperationException("Operation requires a GraphicsContext, which hasn't been created yet."); + } } EAGLRenderingAPI api; @@ -280,7 +286,9 @@ namespace OpenTK.Platform.iPhoneOS set { AssertValid(); if (GraphicsContext != null) + { throw new NotSupportedException("Can't change RenderingApi after GraphicsContext is constructed."); + } this.api = value; } } @@ -292,12 +300,16 @@ namespace OpenTK.Platform.iPhoneOS if (GraphicsContext != null) { iPhoneOSGraphicsContext c = GraphicsContext as iPhoneOSGraphicsContext; if (c != null) + { return c.EAGLContext; + } var i = GraphicsContext as IGraphicsContextInternal; IGraphicsContext ic = i == null ? null : i.Implementation; c = ic as iPhoneOSGraphicsContext; if (c != null) + { return c.EAGLContext; + } } return null; } @@ -312,7 +324,9 @@ namespace OpenTK.Platform.iPhoneOS set { AssertValid(); if (GraphicsContext != null) + { throw new NotSupportedException("Can't change LayerRetainsBacking after GraphicsContext is constructed."); + } retainedBacking = value; } } @@ -326,7 +340,9 @@ namespace OpenTK.Platform.iPhoneOS set { AssertValid(); if (GraphicsContext != null) + { throw new NotSupportedException("Can't change LayerColorFormat after GraphicsContext is constructed."); + } colorFormat = value; } } @@ -347,7 +363,9 @@ namespace OpenTK.Platform.iPhoneOS while (r != null) { var c = r as UIViewController; if (c != null) + { return c; + } r = r.NextResponder; } return null; @@ -358,7 +376,9 @@ namespace OpenTK.Platform.iPhoneOS AssertValid(); var c = GetViewController(); if (c != null) + { return c.Title; + } throw new NotSupportedException(); } set { @@ -371,7 +391,9 @@ namespace OpenTK.Platform.iPhoneOS } } else + { throw new NotSupportedException(); + } } } @@ -379,7 +401,9 @@ namespace OpenTK.Platform.iPhoneOS { var h = TitleChanged; if (h != null) + { h (this, EventArgs.Empty); + } } bool INativeWindow.Focused { @@ -404,7 +428,9 @@ namespace OpenTK.Platform.iPhoneOS { var h = VisibleChanged; if (h != null) + { h (this, EventArgs.Empty); + } } bool INativeWindow.Exists { @@ -427,7 +453,9 @@ namespace OpenTK.Platform.iPhoneOS #else if (c != null && c.WantsFullScreenLayout) #endif + { return WindowState.Fullscreen; + } return WindowState.Normal; } set { @@ -454,7 +482,9 @@ namespace OpenTK.Platform.iPhoneOS { var h = WindowStateChanged; if (h != null) + { h (this, EventArgs.Empty); + } } public virtual WindowBorder WindowBorder { @@ -494,7 +524,9 @@ namespace OpenTK.Platform.iPhoneOS { var h = Resize; if (h != null) + { h (this, e); + } } int INativeWindow.X { @@ -531,7 +563,9 @@ namespace OpenTK.Platform.iPhoneOS { AssertValid(); if (LayerColorFormat == null) + { throw new InvalidOperationException("Set the LayerColorFormat property to an EAGLColorFormat value before calling Run()."); + } CAEAGLLayer eaglLayer = (CAEAGLLayer) Layer; eaglLayer.DrawableProperties = NSDictionary.FromObjectsAndKeys ( @@ -573,16 +607,22 @@ namespace OpenTK.Platform.iPhoneOS AssertContext(); EAGLContext oldContext = EAGLContext.CurrentContext; if (!GraphicsContext.IsCurrent) + { MakeCurrent(); + } gl.DeleteFramebuffers (1, ref framebuffer); gl.DeleteRenderbuffers (1, ref renderbuffer); framebuffer = renderbuffer = 0; if (oldContext != EAGLContext) + { EAGLContext.SetCurrentContext(oldContext); + } else + { EAGLContext.SetCurrentContext(null); + } GraphicsContext.Dispose(); GraphicsContext = null; @@ -646,33 +686,45 @@ namespace OpenTK.Platform.iPhoneOS { var h = Closed; if (h != null) + { h (this, e); + } } protected override void Dispose(bool disposing) { if (disposed) + { return; + } if (disposing) { if (timesource != null) + { timesource.Invalidate (); + } timesource = null; if (stopwatch != null) + { stopwatch.Stop(); + } stopwatch = null; DestroyFrameBuffer(); } base.Dispose (disposing); disposed = true; if (disposing) + { OnDisposed(EventArgs.Empty); + } } protected virtual void OnDisposed(EventArgs e) { var h = Disposed; if (h != null) + { h (this, e); + } } void INativeWindow.ProcessEvents() @@ -694,7 +746,9 @@ namespace OpenTK.Platform.iPhoneOS { base.LayoutSubviews (); if (GraphicsContext == null) + { return; + } var bounds = Bounds; if (AutoResize && (Math.Round(bounds.Width) != Size.Width || @@ -730,17 +784,21 @@ namespace OpenTK.Platform.iPhoneOS public void Run (double updatesPerSecond) { if (updatesPerSecond < 0.0) + { throw new ArgumentException ("updatesPerSecond"); - + } + if (updatesPerSecond == 0.0) { RunWithFrameInterval (1); return; } - - if (timesource != null) - timesource.Invalidate (); - timesource = new NSTimerTimeSource (this, updatesPerSecond); + if (timesource != null) + { + timesource.Invalidate (); + } + + timesource = new NSTimerTimeSource (this, updatesPerSecond); CreateFrameBuffer (); OnLoad (EventArgs.Empty); @@ -756,14 +814,18 @@ namespace OpenTK.Platform.iPhoneOS public void RunWithFrameInterval (int frameInterval) { AssertValid (); - + if (frameInterval < 1) + { throw new ArgumentException ("frameInterval"); + } - if (timesource != null) - timesource.Invalidate (); + if (timesource != null) + { + timesource.Invalidate (); + } - timesource = new CADisplayLinkTimeSource (this, frameInterval); + timesource = new CADisplayLinkTimeSource (this, frameInterval); CreateFrameBuffer (); OnLoad (EventArgs.Empty); @@ -791,7 +853,9 @@ namespace OpenTK.Platform.iPhoneOS void Suspend () { if (timesource != null) + { timesource.Suspend (); + } stopwatch.Stop(); suspended = true; } @@ -799,7 +863,9 @@ namespace OpenTK.Platform.iPhoneOS void Resume () { if (timesource != null) + { timesource.Resume (); + } stopwatch.Start(); suspended = false; } @@ -833,7 +899,7 @@ namespace OpenTK.Platform.iPhoneOS // otherwise, use kCGImageAlphaPremultipliedLast using (var data_provider = new CGDataProvider (data, 0, data.Length)) { using (var colorspace = CGColorSpace.CreateDeviceRGB ()) { - using (var iref = new CGImage (width, height, 8, 32, width * 4, colorspace, + using (var iref = new CGImage (width, height, 8, 32, width * 4, colorspace, (CGImageAlphaInfo) ((int) CGBitmapFlags.ByteOrder32Big | (int) CGImageAlphaInfo.PremultipliedLast), data_provider, null, true, CGColorRenderingIntent.Default)) { @@ -869,7 +935,9 @@ namespace OpenTK.Platform.iPhoneOS public override void WillMoveToWindow(UIWindow window) { if (window == null && !suspended) + { Suspend(); + } else if (window != null && suspended) { if (frameBufferLayer != null && ((CALayer)frameBufferLayer.Target) != Layer || frameBufferWindow != null && ((UIWindow)frameBufferWindow.Target) != window) { @@ -910,7 +978,9 @@ namespace OpenTK.Platform.iPhoneOS { var h = Load; if (h != null) + { h (this, e); + } } protected virtual void OnUnload(EventArgs e) @@ -918,21 +988,27 @@ namespace OpenTK.Platform.iPhoneOS var h = Unload; DestroyFrameBuffer(); if (h != null) + { h (this, e); + } } protected virtual void OnUpdateFrame(FrameEventArgs e) { var h = UpdateFrame; if (h != null) + { h (this, e); + } } protected virtual void OnRenderFrame(FrameEventArgs e) { var h = RenderFrame; if (h != null) + { h (this, e); + } } event EventHandler INativeWindow.Move { diff --git a/src/OpenTK/Platform/iPhoneOS/iPhoneOSGraphicsContext.cs b/src/OpenTK/Platform/iPhoneOS/iPhoneOSGraphicsContext.cs index 83ce1c39..ee1a349d 100644 --- a/src/OpenTK/Platform/iPhoneOS/iPhoneOSGraphicsContext.cs +++ b/src/OpenTK/Platform/iPhoneOS/iPhoneOSGraphicsContext.cs @@ -1,11 +1,9 @@ -#region --- License --- /* Licensed under the MIT/X11 license. * Copyright (c) 2009 Novell, Inc. * Copyright 2013 Xamarin Inc * This notice may not be removed from any source distribution. * See license.txt for licensing detailed licensing details. */ -#endregion using System; @@ -33,13 +31,21 @@ namespace OpenTK.Platform.iPhoneOS { EAGLRenderingAPI version = 0; if (major == 1 && minor == 1) + { version = EAGLRenderingAPI.OpenGLES1; + } else if (major == 2 && minor == 0) + { version = EAGLRenderingAPI.OpenGLES2; + } else if (major == 3 && minor == 0) + { version = EAGLRenderingAPI.OpenGLES3; + } else + { throw new ArgumentException (string.Format("Unsupported GLES version {0}.{1}.", major, minor)); + } if (handle.Handle == IntPtr.Zero) { EAGLContext = shared != null && shared.EAGLContext != null @@ -60,13 +66,21 @@ namespace OpenTK.Platform.iPhoneOS { EAGLRenderingAPI version = 0; if (major == 1 && minor == 1) + { version = EAGLRenderingAPI.OpenGLES1; + } else if (major == 2 && minor == 0) + { version = EAGLRenderingAPI.OpenGLES2; + } else if (major == 3 && minor == 0) + { version = EAGLRenderingAPI.OpenGLES3; + } else + { throw new ArgumentException (string.Format("Unsupported GLES version {0}.{1}.", major, minor)); + } EAGLContext = shared != null && shared.EAGLContext != null ? new EAGLContext(version, shared.EAGLContext.ShareGroup) @@ -77,13 +91,17 @@ namespace OpenTK.Platform.iPhoneOS { public override void SwapBuffers() { if (!EAGLContext.PresentRenderBuffer((uint) OpenTK.Graphics.ES11.All.RenderbufferOes)) + { throw new InvalidOperationException ("EAGLContext.PresentRenderbuffer failed."); + } } public override void MakeCurrent(IWindowInfo window) { if (!EAGLContext.SetCurrentContext(window != null ? EAGLContext : null)) + { throw new InvalidOperationException("Unable to change current EAGLContext."); + } } public override bool IsCurrent @@ -111,7 +129,9 @@ namespace OpenTK.Platform.iPhoneOS { if (disposing) { if (EAGLContext != null) + { EAGLContext.Dispose(); + } EAGLContext = null; } IsDisposed = true;