Remove regions from iOS and correct brace style.

This commit is contained in:
Jarl Gullberg 2017-07-28 12:01:28 +02:00
parent 15a0d86fe0
commit e7620a11b4
No known key found for this signature in database
GPG key ID: 750FF6F6BDA72D23
5 changed files with 129 additions and 22 deletions

View file

@ -227,7 +227,9 @@ namespace OpenTK
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is PointF) if (obj is PointF)
{
return Equals((PointF)obj); return Equals((PointF)obj);
}
return false; return false;
} }
@ -286,7 +288,9 @@ namespace OpenTK
set set
{ {
if (width < 0) if (width < 0)
{
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
}
width = value; width = value;
} }
} }
@ -300,7 +304,9 @@ namespace OpenTK
set set
{ {
if (height < 0) if (height < 0)
{
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
}
height = value; height = value;
} }
} }
@ -353,7 +359,9 @@ namespace OpenTK
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is SizeF) if (obj is SizeF)
{
return Equals((SizeF)obj); return Equals((SizeF)obj);
}
return false; return false;
} }
@ -578,7 +586,9 @@ namespace OpenTK
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is RectangleF) if (obj is RectangleF)
{
return Equals((RectangleF)obj); return Equals((RectangleF)obj);
}
return false; return false;
} }
@ -789,7 +799,9 @@ namespace OpenTK
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Color)) if (!(obj is Color))
{
return false; return false;
}
return Equals((Color)obj); return Equals((Color)obj);
} }

View file

@ -90,7 +90,10 @@ namespace OpenTK.Platform
Embedded = Default; Embedded = Default;
} }
#if IPHONE #if IPHONE
else if (Configuration.RunningOnIOS) Embedded = new iPhoneOS.iPhoneFactory(); else if (Configuration.RunningOnIOS)
{
Embedded = new iPhoneOS.iPhoneFactory();
}
#else #else
else if (Egl.Egl.IsSupported) else if (Egl.Egl.IsSupported)
{ {

View file

@ -1,4 +1,3 @@
#region License
// //
// The Open Toolkit Library License // The Open Toolkit Library License
// //
@ -24,7 +23,6 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// //
#endregion
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -38,8 +36,6 @@ namespace OpenTK.Platform.iPhoneOS
{ {
class iPhoneFactory : PlatformFactoryBase class iPhoneFactory : PlatformFactoryBase
{ {
#region IPlatformFactory Members
public override IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) 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); return new iPhoneOS.iPhoneOSGraphicsContext(mode, window, shareContext, major, minor, flags);
@ -56,7 +52,9 @@ namespace OpenTK.Platform.iPhoneOS
EAGLContext c = EAGLContext.CurrentContext; EAGLContext c = EAGLContext.CurrentContext;
IntPtr h = IntPtr.Zero; IntPtr h = IntPtr.Zero;
if (c != null) if (c != null)
{
h = c.Handle; h = c.Handle;
}
return new ContextHandle(h); return new ContextHandle(h);
}; };
} }
@ -85,7 +83,5 @@ namespace OpenTK.Platform.iPhoneOS
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
#endregion
} }
} }

View file

@ -1,4 +1,3 @@
#region --- License ---
/* Licensed under the MIT/X11 license. /* Licensed under the MIT/X11 license.
* Copyright (c) 2009 Novell, Inc. * Copyright (c) 2009 Novell, Inc.
* Copyright 2013 Xamarin Inc * Copyright 2013 Xamarin Inc
@ -6,7 +5,6 @@
* See license.txt for licensing detailed licensing details. * See license.txt for licensing detailed licensing details.
*/ */
// Copyright 2011 Xamarin Inc. All rights reserved. // Copyright 2011 Xamarin Inc. All rights reserved.
#endregion
using System; using System;
using System.ComponentModel; using System.ComponentModel;
@ -149,7 +147,9 @@ namespace OpenTK.Platform.iPhoneOS
this.view = view; this.view = view;
if (displayLink != null) if (displayLink != null)
{
displayLink.Invalidate (); displayLink.Invalidate ();
}
displayLink = CADisplayLink.Create (this, selRunIteration); displayLink = CADisplayLink.Create (this, selRunIteration);
displayLink.FrameInterval = frameInterval; displayLink.FrameInterval = frameInterval;
@ -211,8 +211,10 @@ namespace OpenTK.Platform.iPhoneOS
public void Resume () public void Resume ()
{ {
if (timeout != new TimeSpan (-1)) if (timeout != new TimeSpan (-1))
{
timer = NSTimer.CreateRepeatingScheduledTimer (timeout, view.RunIteration); timer = NSTimer.CreateRepeatingScheduledTimer (timeout, view.RunIteration);
} }
}
public void Invalidate () public void Invalidate ()
{ {
@ -262,14 +264,18 @@ namespace OpenTK.Platform.iPhoneOS
void AssertValid() void AssertValid()
{ {
if (disposed) if (disposed)
{
throw new ObjectDisposedException(""); throw new ObjectDisposedException("");
} }
}
void AssertContext() void AssertContext()
{ {
if (GraphicsContext == null) if (GraphicsContext == null)
{
throw new InvalidOperationException("Operation requires a GraphicsContext, which hasn't been created yet."); throw new InvalidOperationException("Operation requires a GraphicsContext, which hasn't been created yet.");
} }
}
EAGLRenderingAPI api; EAGLRenderingAPI api;
public EAGLRenderingAPI ContextRenderingApi { public EAGLRenderingAPI ContextRenderingApi {
@ -280,7 +286,9 @@ namespace OpenTK.Platform.iPhoneOS
set { set {
AssertValid(); AssertValid();
if (GraphicsContext != null) if (GraphicsContext != null)
{
throw new NotSupportedException("Can't change RenderingApi after GraphicsContext is constructed."); throw new NotSupportedException("Can't change RenderingApi after GraphicsContext is constructed.");
}
this.api = value; this.api = value;
} }
} }
@ -292,13 +300,17 @@ namespace OpenTK.Platform.iPhoneOS
if (GraphicsContext != null) { if (GraphicsContext != null) {
iPhoneOSGraphicsContext c = GraphicsContext as iPhoneOSGraphicsContext; iPhoneOSGraphicsContext c = GraphicsContext as iPhoneOSGraphicsContext;
if (c != null) if (c != null)
{
return c.EAGLContext; return c.EAGLContext;
}
var i = GraphicsContext as IGraphicsContextInternal; var i = GraphicsContext as IGraphicsContextInternal;
IGraphicsContext ic = i == null ? null : i.Implementation; IGraphicsContext ic = i == null ? null : i.Implementation;
c = ic as iPhoneOSGraphicsContext; c = ic as iPhoneOSGraphicsContext;
if (c != null) if (c != null)
{
return c.EAGLContext; return c.EAGLContext;
} }
}
return null; return null;
} }
} }
@ -312,7 +324,9 @@ namespace OpenTK.Platform.iPhoneOS
set { set {
AssertValid(); AssertValid();
if (GraphicsContext != null) if (GraphicsContext != null)
{
throw new NotSupportedException("Can't change LayerRetainsBacking after GraphicsContext is constructed."); throw new NotSupportedException("Can't change LayerRetainsBacking after GraphicsContext is constructed.");
}
retainedBacking = value; retainedBacking = value;
} }
} }
@ -326,7 +340,9 @@ namespace OpenTK.Platform.iPhoneOS
set { set {
AssertValid(); AssertValid();
if (GraphicsContext != null) if (GraphicsContext != null)
{
throw new NotSupportedException("Can't change LayerColorFormat after GraphicsContext is constructed."); throw new NotSupportedException("Can't change LayerColorFormat after GraphicsContext is constructed.");
}
colorFormat = value; colorFormat = value;
} }
} }
@ -347,7 +363,9 @@ namespace OpenTK.Platform.iPhoneOS
while (r != null) { while (r != null) {
var c = r as UIViewController; var c = r as UIViewController;
if (c != null) if (c != null)
{
return c; return c;
}
r = r.NextResponder; r = r.NextResponder;
} }
return null; return null;
@ -358,7 +376,9 @@ namespace OpenTK.Platform.iPhoneOS
AssertValid(); AssertValid();
var c = GetViewController(); var c = GetViewController();
if (c != null) if (c != null)
{
return c.Title; return c.Title;
}
throw new NotSupportedException(); throw new NotSupportedException();
} }
set { set {
@ -371,16 +391,20 @@ namespace OpenTK.Platform.iPhoneOS
} }
} }
else else
{
throw new NotSupportedException(); throw new NotSupportedException();
} }
} }
}
protected virtual void OnTitleChanged(EventArgs e) protected virtual void OnTitleChanged(EventArgs e)
{ {
var h = TitleChanged; var h = TitleChanged;
if (h != null) if (h != null)
{
h (this, EventArgs.Empty); h (this, EventArgs.Empty);
} }
}
bool INativeWindow.Focused { bool INativeWindow.Focused {
get {throw new NotImplementedException();} get {throw new NotImplementedException();}
@ -404,8 +428,10 @@ namespace OpenTK.Platform.iPhoneOS
{ {
var h = VisibleChanged; var h = VisibleChanged;
if (h != null) if (h != null)
{
h (this, EventArgs.Empty); h (this, EventArgs.Empty);
} }
}
bool INativeWindow.Exists { bool INativeWindow.Exists {
get {throw new NotImplementedException();} get {throw new NotImplementedException();}
@ -427,7 +453,9 @@ namespace OpenTK.Platform.iPhoneOS
#else #else
if (c != null && c.WantsFullScreenLayout) if (c != null && c.WantsFullScreenLayout)
#endif #endif
{
return WindowState.Fullscreen; return WindowState.Fullscreen;
}
return WindowState.Normal; return WindowState.Normal;
} }
set { set {
@ -454,8 +482,10 @@ namespace OpenTK.Platform.iPhoneOS
{ {
var h = WindowStateChanged; var h = WindowStateChanged;
if (h != null) if (h != null)
{
h (this, EventArgs.Empty); h (this, EventArgs.Empty);
} }
}
public virtual WindowBorder WindowBorder { public virtual WindowBorder WindowBorder {
get { get {
@ -494,8 +524,10 @@ namespace OpenTK.Platform.iPhoneOS
{ {
var h = Resize; var h = Resize;
if (h != null) if (h != null)
{
h (this, e); h (this, e);
} }
}
int INativeWindow.X { int INativeWindow.X {
get {throw new NotSupportedException();} get {throw new NotSupportedException();}
@ -531,7 +563,9 @@ namespace OpenTK.Platform.iPhoneOS
{ {
AssertValid(); AssertValid();
if (LayerColorFormat == null) if (LayerColorFormat == null)
{
throw new InvalidOperationException("Set the LayerColorFormat property to an EAGLColorFormat value before calling Run()."); throw new InvalidOperationException("Set the LayerColorFormat property to an EAGLColorFormat value before calling Run().");
}
CAEAGLLayer eaglLayer = (CAEAGLLayer) Layer; CAEAGLLayer eaglLayer = (CAEAGLLayer) Layer;
eaglLayer.DrawableProperties = NSDictionary.FromObjectsAndKeys ( eaglLayer.DrawableProperties = NSDictionary.FromObjectsAndKeys (
@ -573,16 +607,22 @@ namespace OpenTK.Platform.iPhoneOS
AssertContext(); AssertContext();
EAGLContext oldContext = EAGLContext.CurrentContext; EAGLContext oldContext = EAGLContext.CurrentContext;
if (!GraphicsContext.IsCurrent) if (!GraphicsContext.IsCurrent)
{
MakeCurrent(); MakeCurrent();
}
gl.DeleteFramebuffers (1, ref framebuffer); gl.DeleteFramebuffers (1, ref framebuffer);
gl.DeleteRenderbuffers (1, ref renderbuffer); gl.DeleteRenderbuffers (1, ref renderbuffer);
framebuffer = renderbuffer = 0; framebuffer = renderbuffer = 0;
if (oldContext != EAGLContext) if (oldContext != EAGLContext)
{
EAGLContext.SetCurrentContext(oldContext); EAGLContext.SetCurrentContext(oldContext);
}
else else
{
EAGLContext.SetCurrentContext(null); EAGLContext.SetCurrentContext(null);
}
GraphicsContext.Dispose(); GraphicsContext.Dispose();
GraphicsContext = null; GraphicsContext = null;
@ -646,34 +686,46 @@ namespace OpenTK.Platform.iPhoneOS
{ {
var h = Closed; var h = Closed;
if (h != null) if (h != null)
{
h (this, e); h (this, e);
} }
}
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposed) if (disposed)
{
return; return;
}
if (disposing) { if (disposing) {
if (timesource != null) if (timesource != null)
{
timesource.Invalidate (); timesource.Invalidate ();
}
timesource = null; timesource = null;
if (stopwatch != null) if (stopwatch != null)
{
stopwatch.Stop(); stopwatch.Stop();
}
stopwatch = null; stopwatch = null;
DestroyFrameBuffer(); DestroyFrameBuffer();
} }
base.Dispose (disposing); base.Dispose (disposing);
disposed = true; disposed = true;
if (disposing) if (disposing)
{
OnDisposed(EventArgs.Empty); OnDisposed(EventArgs.Empty);
} }
}
protected virtual void OnDisposed(EventArgs e) protected virtual void OnDisposed(EventArgs e)
{ {
var h = Disposed; var h = Disposed;
if (h != null) if (h != null)
{
h (this, e); h (this, e);
} }
}
void INativeWindow.ProcessEvents() void INativeWindow.ProcessEvents()
{ {
@ -694,7 +746,9 @@ namespace OpenTK.Platform.iPhoneOS
{ {
base.LayoutSubviews (); base.LayoutSubviews ();
if (GraphicsContext == null) if (GraphicsContext == null)
{
return; return;
}
var bounds = Bounds; var bounds = Bounds;
if (AutoResize && (Math.Round(bounds.Width) != Size.Width || if (AutoResize && (Math.Round(bounds.Width) != Size.Width ||
@ -730,7 +784,9 @@ namespace OpenTK.Platform.iPhoneOS
public void Run (double updatesPerSecond) public void Run (double updatesPerSecond)
{ {
if (updatesPerSecond < 0.0) if (updatesPerSecond < 0.0)
{
throw new ArgumentException ("updatesPerSecond"); throw new ArgumentException ("updatesPerSecond");
}
if (updatesPerSecond == 0.0) { if (updatesPerSecond == 0.0) {
RunWithFrameInterval (1); RunWithFrameInterval (1);
@ -738,7 +794,9 @@ namespace OpenTK.Platform.iPhoneOS
} }
if (timesource != null) if (timesource != null)
{
timesource.Invalidate (); timesource.Invalidate ();
}
timesource = new NSTimerTimeSource (this, updatesPerSecond); timesource = new NSTimerTimeSource (this, updatesPerSecond);
@ -758,10 +816,14 @@ namespace OpenTK.Platform.iPhoneOS
AssertValid (); AssertValid ();
if (frameInterval < 1) if (frameInterval < 1)
{
throw new ArgumentException ("frameInterval"); throw new ArgumentException ("frameInterval");
}
if (timesource != null) if (timesource != null)
{
timesource.Invalidate (); timesource.Invalidate ();
}
timesource = new CADisplayLinkTimeSource (this, frameInterval); timesource = new CADisplayLinkTimeSource (this, frameInterval);
@ -791,7 +853,9 @@ namespace OpenTK.Platform.iPhoneOS
void Suspend () void Suspend ()
{ {
if (timesource != null) if (timesource != null)
{
timesource.Suspend (); timesource.Suspend ();
}
stopwatch.Stop(); stopwatch.Stop();
suspended = true; suspended = true;
} }
@ -799,7 +863,9 @@ namespace OpenTK.Platform.iPhoneOS
void Resume () void Resume ()
{ {
if (timesource != null) if (timesource != null)
{
timesource.Resume (); timesource.Resume ();
}
stopwatch.Start(); stopwatch.Start();
suspended = false; suspended = false;
} }
@ -869,7 +935,9 @@ namespace OpenTK.Platform.iPhoneOS
public override void WillMoveToWindow(UIWindow window) public override void WillMoveToWindow(UIWindow window)
{ {
if (window == null && !suspended) if (window == null && !suspended)
{
Suspend(); Suspend();
}
else if (window != null && suspended) { else if (window != null && suspended) {
if (frameBufferLayer != null && ((CALayer)frameBufferLayer.Target) != Layer || if (frameBufferLayer != null && ((CALayer)frameBufferLayer.Target) != Layer ||
frameBufferWindow != null && ((UIWindow)frameBufferWindow.Target) != window) { frameBufferWindow != null && ((UIWindow)frameBufferWindow.Target) != window) {
@ -910,30 +978,38 @@ namespace OpenTK.Platform.iPhoneOS
{ {
var h = Load; var h = Load;
if (h != null) if (h != null)
{
h (this, e); h (this, e);
} }
}
protected virtual void OnUnload(EventArgs e) protected virtual void OnUnload(EventArgs e)
{ {
var h = Unload; var h = Unload;
DestroyFrameBuffer(); DestroyFrameBuffer();
if (h != null) if (h != null)
{
h (this, e); h (this, e);
} }
}
protected virtual void OnUpdateFrame(FrameEventArgs e) protected virtual void OnUpdateFrame(FrameEventArgs e)
{ {
var h = UpdateFrame; var h = UpdateFrame;
if (h != null) if (h != null)
{
h (this, e); h (this, e);
} }
}
protected virtual void OnRenderFrame(FrameEventArgs e) protected virtual void OnRenderFrame(FrameEventArgs e)
{ {
var h = RenderFrame; var h = RenderFrame;
if (h != null) if (h != null)
{
h (this, e); h (this, e);
} }
}
event EventHandler<EventArgs> INativeWindow.Move { event EventHandler<EventArgs> INativeWindow.Move {
add {throw new NotSupportedException();} add {throw new NotSupportedException();}

View file

@ -1,11 +1,9 @@
#region --- License ---
/* Licensed under the MIT/X11 license. /* Licensed under the MIT/X11 license.
* Copyright (c) 2009 Novell, Inc. * Copyright (c) 2009 Novell, Inc.
* Copyright 2013 Xamarin Inc * Copyright 2013 Xamarin Inc
* This notice may not be removed from any source distribution. * This notice may not be removed from any source distribution.
* See license.txt for licensing detailed licensing details. * See license.txt for licensing detailed licensing details.
*/ */
#endregion
using System; using System;
@ -33,13 +31,21 @@ namespace OpenTK.Platform.iPhoneOS {
EAGLRenderingAPI version = 0; EAGLRenderingAPI version = 0;
if (major == 1 && minor == 1) if (major == 1 && minor == 1)
{
version = EAGLRenderingAPI.OpenGLES1; version = EAGLRenderingAPI.OpenGLES1;
}
else if (major == 2 && minor == 0) else if (major == 2 && minor == 0)
{
version = EAGLRenderingAPI.OpenGLES2; version = EAGLRenderingAPI.OpenGLES2;
}
else if (major == 3 && minor == 0) else if (major == 3 && minor == 0)
{
version = EAGLRenderingAPI.OpenGLES3; version = EAGLRenderingAPI.OpenGLES3;
}
else else
{
throw new ArgumentException (string.Format("Unsupported GLES version {0}.{1}.", major, minor)); throw new ArgumentException (string.Format("Unsupported GLES version {0}.{1}.", major, minor));
}
if (handle.Handle == IntPtr.Zero) { if (handle.Handle == IntPtr.Zero) {
EAGLContext = shared != null && shared.EAGLContext != null EAGLContext = shared != null && shared.EAGLContext != null
@ -60,13 +66,21 @@ namespace OpenTK.Platform.iPhoneOS {
EAGLRenderingAPI version = 0; EAGLRenderingAPI version = 0;
if (major == 1 && minor == 1) if (major == 1 && minor == 1)
{
version = EAGLRenderingAPI.OpenGLES1; version = EAGLRenderingAPI.OpenGLES1;
}
else if (major == 2 && minor == 0) else if (major == 2 && minor == 0)
{
version = EAGLRenderingAPI.OpenGLES2; version = EAGLRenderingAPI.OpenGLES2;
}
else if (major == 3 && minor == 0) else if (major == 3 && minor == 0)
{
version = EAGLRenderingAPI.OpenGLES3; version = EAGLRenderingAPI.OpenGLES3;
}
else else
{
throw new ArgumentException (string.Format("Unsupported GLES version {0}.{1}.", major, minor)); throw new ArgumentException (string.Format("Unsupported GLES version {0}.{1}.", major, minor));
}
EAGLContext = shared != null && shared.EAGLContext != null EAGLContext = shared != null && shared.EAGLContext != null
? new EAGLContext(version, shared.EAGLContext.ShareGroup) ? new EAGLContext(version, shared.EAGLContext.ShareGroup)
@ -77,14 +91,18 @@ namespace OpenTK.Platform.iPhoneOS {
public override void SwapBuffers() public override void SwapBuffers()
{ {
if (!EAGLContext.PresentRenderBuffer((uint) OpenTK.Graphics.ES11.All.RenderbufferOes)) if (!EAGLContext.PresentRenderBuffer((uint) OpenTK.Graphics.ES11.All.RenderbufferOes))
{
throw new InvalidOperationException ("EAGLContext.PresentRenderbuffer failed."); throw new InvalidOperationException ("EAGLContext.PresentRenderbuffer failed.");
} }
}
public override void MakeCurrent(IWindowInfo window) public override void MakeCurrent(IWindowInfo window)
{ {
if (!EAGLContext.SetCurrentContext(window != null ? EAGLContext : null)) if (!EAGLContext.SetCurrentContext(window != null ? EAGLContext : null))
{
throw new InvalidOperationException("Unable to change current EAGLContext."); throw new InvalidOperationException("Unable to change current EAGLContext.");
} }
}
public override bool IsCurrent public override bool IsCurrent
{ {
@ -111,7 +129,9 @@ namespace OpenTK.Platform.iPhoneOS {
if (disposing) if (disposing)
{ {
if (EAGLContext != null) if (EAGLContext != null)
{
EAGLContext.Dispose(); EAGLContext.Dispose();
}
EAGLContext = null; EAGLContext = null;
} }
IsDisposed = true; IsDisposed = true;