Merge pull request #607 from Nihlus/purge-regions-mobile

Correct mobile projects for StyleCop compliance.
This commit is contained in:
Jarl Gullberg 2017-07-28 12:13:53 +02:00 committed by GitHub
commit 6ea763c821
16 changed files with 250 additions and 180 deletions

View file

@ -9,7 +9,7 @@ namespace OpenTK.Graphics.ES11
public sealed partial class GL : GraphicsBindingsBase
{
#if IPHONE
const string Library = "/System/Library/Frameworks/OpenGLES.framework/OpenGLES";
private const string Library = "/System/Library/Frameworks/OpenGLES.framework/OpenGLES";
#else
private const string Library = "GLESv1_CM";
#endif

View file

@ -38,7 +38,7 @@ namespace OpenTK.Graphics.ES20
public sealed partial class GL : GraphicsBindingsBase
{
#if IPHONE
const string Library = "/System/Library/Frameworks/OpenGLES.framework/OpenGLES";
private const string Library = "/System/Library/Frameworks/OpenGLES.framework/OpenGLES";
#else
private const string Library = "libGLESv2.dll";
#endif

View file

@ -38,7 +38,7 @@ namespace OpenTK.Graphics.ES30
public sealed partial class GL : GraphicsBindingsBase
{
#if IPHONE
const string Library = "/System/Library/Frameworks/OpenGLES.framework/OpenGLES";
private const string Library = "/System/Library/Frameworks/OpenGLES.framework/OpenGLES";
#else
private const string Library = "libGLESv2.dll";
#endif

View file

@ -86,25 +86,25 @@ namespace OpenTK
#endif
// System.Xml.XmlIgnoreAttribute
class XmlIgnoreAttribute : Attribute
internal class XmlIgnoreAttribute : Attribute
{
}
// System.ComponentModel.EditorBrowrableAttribute
class EditorBrowsableAttribute : Attribute
internal class EditorBrowsableAttribute : Attribute
{
public EditorBrowsableAttribute(EditorBrowsableState state) { }
}
// System.ComponentModel.EditorBrowsableState
enum EditorBrowsableState
internal enum EditorBrowsableState
{
Always = 0,
Never = 1,
Advanced = 2,
}
class RegistryKey
internal class RegistryKey
{
public RegistryKey OpenSubKey(string name)
{
@ -117,14 +117,14 @@ namespace OpenTK
}
}
class Registry
internal class Registry
{
public static readonly RegistryKey LocalMachine = new RegistryKey();
}
public struct PointF : IEquatable<PointF>
{
float x, y;
private float x, y;
/// <summary>
/// Constructs a new PointF instance.
@ -227,7 +227,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (obj is PointF)
{
return Equals((PointF)obj);
}
return false;
}
@ -263,7 +265,7 @@ namespace OpenTK
public struct SizeF : IEquatable<SizeF>
{
float width, height;
private float width, height;
/// <summary>
/// Constructs a new SizeF instance.
@ -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;
}
@ -389,8 +397,8 @@ namespace OpenTK
public struct RectangleF : IEquatable<RectangleF>
{
PointF location;
SizeF size;
private PointF location;
private SizeF size;
/// <summary>
/// Constructs a new RectangleF instance.
@ -578,7 +586,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (obj is RectangleF)
{
return Equals((RectangleF)obj);
}
return false;
}
@ -615,7 +625,7 @@ namespace OpenTK
public sealed class Icon : IDisposable
{
IntPtr handle;
private IntPtr handle;
public Icon(Icon icon, int width, int height)
{
@ -655,8 +665,8 @@ namespace OpenTK
public sealed class Bitmap : Image
{
int width;
int height;
private int width;
private int height;
public Bitmap() { }
@ -789,7 +799,9 @@ namespace OpenTK
public override bool Equals(object obj)
{
if (!(obj is Color))
{
return false;
}
return Equals((Color)obj);
}
@ -1537,7 +1549,7 @@ namespace OpenTK
}
}
sealed class BitmapData
internal sealed class BitmapData
{
internal BitmapData(int width, int height, int stride)
{
@ -1552,7 +1564,7 @@ namespace OpenTK
public int Stride { get; private set; }
}
enum ImageLockMode
internal enum ImageLockMode
{
ReadOnly,
WriteOnly,
@ -1560,16 +1572,16 @@ namespace OpenTK
UserInputBuffer
}
enum PixelFormat
internal enum PixelFormat
{
Format32bppArgb
}
enum ImageFormat {
internal enum ImageFormat {
Png
}
sealed class SystemEvents
internal sealed class SystemEvents
{
public static event EventHandler DisplaySettingsChanged;
}
@ -1578,7 +1590,7 @@ namespace OpenTK
// Need a different namespace to avoid clash with OpenTK.Graphics.
namespace OpenTK.Minimal
{
sealed class Graphics : IDisposable
internal sealed class Graphics : IDisposable
{
public static Graphics FromImage(OpenTK.Image img)
{

View file

@ -1,19 +1,17 @@
#region --- License ---
/* Licensed under the MIT/X11 license.
* Copyright (c) 2011 Xamarin, 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;
namespace OpenTK.Platform.Android
{
class AndroidDisplayDeviceDriver : IDisplayDeviceDriver
internal class AndroidDisplayDeviceDriver : IDisplayDeviceDriver
{
static DisplayDevice dev;
private static DisplayDevice dev;
static AndroidDisplayDeviceDriver ()
{
dev = new DisplayDevice ();

View file

@ -1,21 +1,17 @@
#region --- License ---
/* Licensed under the MIT/X11 license.
* Copyright (c) 2011 Xamarin, 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;
using OpenTK.Graphics;
namespace OpenTK.Platform.Android
{
sealed class AndroidFactory : PlatformFactoryBase
internal sealed class AndroidFactory : PlatformFactoryBase
{
#region IPlatformFactory Members
public override IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
{
AndroidWindow android_win = (AndroidWindow)window;
@ -60,7 +56,5 @@ namespace OpenTK.Platform.Android
{
throw new NotImplementedException();
}
#endregion
}
}

View file

@ -1,11 +1,9 @@
#region --- License ---
/* Licensed under the MIT/X11 license.
* Copyright (c) 2011 Xamarin 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;
using System.ComponentModel;
@ -34,28 +32,28 @@ namespace OpenTK.Platform.Android
[Register ("opentk_1_1/platform/android/AndroidGameView")]
public partial class AndroidGameView : GameViewBase, ISurfaceHolderCallback
{
bool disposed;
System.Timers.Timer timer;
Java.Util.Timer j_timer;
ISurfaceHolder mHolder;
GLCalls gl;
AndroidWindow windowInfo;
Object ticking = new Object ();
bool stopped = true;
bool renderOn = false;
bool sizeChanged = false;
bool requestRender = false;
bool autoSetContextOnRenderFrame = true;
bool renderOnUIThread = true;
bool callMakeCurrent = false;
CancellationTokenSource source;
Task renderTask;
Thread renderingThread;
ManualResetEvent pauseSignal;
global::Android.Graphics.Rect surfaceRect;
Size size;
System.Diagnostics.Stopwatch stopWatch;
double tick = 0;
private bool disposed;
private System.Timers.Timer timer;
private Java.Util.Timer j_timer;
private ISurfaceHolder mHolder;
private GLCalls gl;
private AndroidWindow windowInfo;
private Object ticking = new Object ();
private bool stopped = true;
private bool renderOn = false;
private bool sizeChanged = false;
private bool requestRender = false;
private bool autoSetContextOnRenderFrame = true;
private bool renderOnUIThread = true;
private bool callMakeCurrent = false;
private CancellationTokenSource source;
private Task renderTask;
private Thread renderingThread;
private ManualResetEvent pauseSignal;
private global::Android.Graphics.Rect surfaceRect;
private Size size;
private System.Diagnostics.Stopwatch stopWatch;
private double tick = 0;
[Register (".ctor", "(Landroid/content/Context;)V", "")]
public AndroidGameView (Context context) : base (context)
@ -204,7 +202,7 @@ namespace OpenTK.Platform.Android
GraphicsContext.SwapBuffers ();
}
double updates;
private double updates;
public override void Run ()
{
EnsureUndisposed ();
@ -250,19 +248,18 @@ namespace OpenTK.Platform.Android
ResumeThread ();
}
#region Private
void LoadInternal (EventArgs e)
private void LoadInternal (EventArgs e)
{
OnLoad (e);
}
void UnloadInternal (EventArgs e)
private void UnloadInternal (EventArgs e)
{
OnUnload (e);
DestroyFrameBuffer ();
}
void RenderFrameInternal (FrameEventArgs e)
private void RenderFrameInternal (FrameEventArgs e)
{
#if TIMING
Mark ();
@ -304,7 +301,7 @@ namespace OpenTK.Platform.Android
}
#endif
void UpdateFrameInternal (FrameEventArgs e)
private void UpdateFrameInternal (FrameEventArgs e)
{
if (!ReadyToRender)
return;
@ -312,19 +309,19 @@ namespace OpenTK.Platform.Android
OnUpdateFrame (e);
}
void EnsureUndisposed ()
private void EnsureUndisposed ()
{
if (disposed)
throw new ObjectDisposedException ("");
}
void AssertContext ()
private void AssertContext ()
{
if (GraphicsContext == null)
throw new InvalidOperationException ("Operation requires a GraphicsContext, which hasn't been created yet.");
}
void CreateSurface()
private void CreateSurface()
{
if (GraphicsContext == null)
{
@ -340,13 +337,13 @@ namespace OpenTK.Platform.Android
MakeCurrent();
}
void DestroySurface()
private void DestroySurface()
{
log("DestroySurface");
windowInfo.DestroySurface();
}
void CreateContext ()
private void CreateContext ()
{
log ("CreateContext");
@ -357,7 +354,7 @@ namespace OpenTK.Platform.Android
GraphicsContext = new GraphicsContext(GraphicsMode, WindowInfo, (int)ContextRenderingApi, 0, GraphicsContextFlags.Embedded);
}
void DestroyContext ()
private void DestroyContext ()
{
if (GraphicsContext != null) {
GraphicsContext.Dispose ();
@ -365,11 +362,11 @@ namespace OpenTK.Platform.Android
}
}
int restartCounter = 0;
private int restartCounter = 0;
public int RenderThreadRestartRetries { get; set; }
public Exception RenderThreadException;
void StartThread ()
private void StartThread ()
{
log ("StartThread");
@ -444,7 +441,7 @@ namespace OpenTK.Platform.Android
});
}
void StopThread ()
private void StopThread ()
{
log ("StopThread");
restartCounter = 0;
@ -461,7 +458,7 @@ namespace OpenTK.Platform.Android
if (stopWatch != null) stopWatch.Stop ();
}
void PauseThread ()
private void PauseThread ()
{
log ("PauseThread");
restartCounter = 0;
@ -472,7 +469,7 @@ namespace OpenTK.Platform.Android
renderOn = false;
}
void ResumeThread ()
private void ResumeThread ()
{
log ("ResumeThread");
restartCounter = 0;
@ -486,19 +483,19 @@ namespace OpenTK.Platform.Android
}
}
bool ReadyToRender {
private bool ReadyToRender {
get { return windowInfo.HasSurface && renderOn && !stopped; }
}
DateTime prevUpdateTime;
DateTime prevRenderTime;
DateTime curUpdateTime;
DateTime curRenderTime;
FrameEventArgs updateEventArgs = new FrameEventArgs();
FrameEventArgs renderEventArgs = new FrameEventArgs();
private DateTime prevUpdateTime;
private DateTime prevRenderTime;
private DateTime curUpdateTime;
private DateTime curRenderTime;
private FrameEventArgs updateEventArgs = new FrameEventArgs();
private FrameEventArgs renderEventArgs = new FrameEventArgs();
// this method is called on the main thread if RenderOnUIThread is true
void RunIteration (CancellationToken token)
private void RunIteration (CancellationToken token)
{
if (token.IsCancellationRequested)
return;
@ -541,9 +538,6 @@ namespace OpenTK.Platform.Android
global::Android.Util.Log.Debug ("AndroidGameView", String.Format("width:{0} height:{1} size:{2} surfaceRect:{3}", Width, Height, size, surfaceRect));
}
#endif
#endregion
#region Properties
public bool AutoSetContextOnRenderFrame {
@ -564,7 +558,7 @@ namespace OpenTK.Platform.Android
}
}
GLCalls GLCalls {
private GLCalls GLCalls {
get {
if (gl == null || gl.Version != ContextRenderingApi)
gl = GLCalls.GetGLCalls (ContextRenderingApi);
@ -572,7 +566,7 @@ namespace OpenTK.Platform.Android
}
}
IGraphicsContext Context {
private IGraphicsContext Context {
get { return GraphicsContext; }
}
@ -594,7 +588,7 @@ namespace OpenTK.Platform.Android
}
}
GLVersion api;
private GLVersion api;
public GLVersion ContextRenderingApi
{
get {
@ -670,6 +664,5 @@ namespace OpenTK.Platform.Android
}
}
}
#endregion
}
}

View file

@ -1,11 +1,9 @@
#region --- License ---
/* Licensed under the MIT/X11 license.
* Copyright (c) 2011 Xamarin, 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;
using System.Runtime.InteropServices;
@ -18,8 +16,7 @@ using OpenTK.Graphics;
using OpenTK.Platform.Egl;
namespace OpenTK.Platform.Android {
class AndroidGraphicsContext : EglContext
internal class AndroidGraphicsContext : EglContext
{
public AndroidGraphicsContext(GraphicsMode mode, EglWindowInfo window, IGraphicsContext sharedContext,
int major, int minor, GraphicsContextFlags flags)
@ -41,8 +38,8 @@ namespace OpenTK.Platform.Android {
public class AndroidWindow : IWindowInfo, IDisposable
{
bool disposed;
WeakReference refHolder;
private bool disposed;
private WeakReference refHolder;
private EglWindowInfo eglWindowInfo;
// Get native window from surface
@ -132,15 +129,13 @@ namespace OpenTK.Platform.Android {
eglWindowInfo.TerminateDisplay();
}
#region IDisposable Members
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
void Dispose (bool disposing)
private void Dispose (bool disposing)
{
if (!disposed)
{
@ -157,7 +152,5 @@ namespace OpenTK.Platform.Android {
{
Dispose (false);
}
#endregion
}
}

View file

@ -1,11 +1,9 @@
#region --- License ---
/* Licensed under the MIT/X11 license.
* Copyright (c) 2011 Xamarin, 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;

View file

@ -1,11 +1,9 @@
#region --- License ---
/* Licensed under the MIT/X11 license.
* Copyright (c) 2011 Xamarin, 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;
using OpenTK;
@ -21,7 +19,7 @@ using ES30 = OpenTK.Graphics.ES30;
namespace OpenTK
{
sealed class GLCalls
internal sealed class GLCalls
{
public GLVersion Version;

View file

@ -1,11 +1,9 @@
#region --- License ---
/* Licensed under the MIT/X11 license.
* Copyright (c) 2011 Xamarin 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;
using System.ComponentModel;
@ -89,8 +87,6 @@ namespace OpenTK
return point;
}
#region IGameWindow implementation
/// <summary>
/// Occurs before the run loop starts.
/// </summary>
@ -454,9 +450,6 @@ namespace OpenTK
/// invoked on it.
/// </exception>
public abstract void SwapBuffers ();
#endregion
#region INativeWindow implementation
/// <summary>This member is not supported.</summary>
/// <value>To be added.</value>
@ -1193,7 +1186,5 @@ namespace OpenTK
add { throw new NotSupportedException(); }
remove { throw new NotSupportedException(); }
}
#endregion
}
}

View file

@ -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)
{

View file

@ -5,9 +5,9 @@ using OpenTK.Platform;
namespace OpenTK.Platform.iPhoneOS
{
class AndroidDisplayDeviceDriver : IDisplayDeviceDriver
internal class AndroidDisplayDeviceDriver : IDisplayDeviceDriver
{
static DisplayDevice dev;
private static DisplayDevice dev;
static AndroidDisplayDeviceDriver()
{
dev = new DisplayDevice();

View file

@ -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;
@ -36,10 +34,8 @@ using OpenTK.Graphics;
namespace OpenTK.Platform.iPhoneOS
{
class iPhoneFactory : PlatformFactoryBase
internal 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
}
}

View file

@ -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;
@ -32,7 +30,7 @@ using ES30 = OpenTK.Graphics.ES30;
namespace OpenTK.Platform.iPhoneOS
{
sealed class GLCalls {
internal sealed class GLCalls {
public delegate void glBindFramebuffer(All target, int framebuffer);
public delegate void glBindRenderbuffer(All target, int renderbuffer);
public delegate void glDeleteFramebuffers(int n, ref int framebuffers);
@ -71,7 +69,7 @@ namespace OpenTK.Platform.iPhoneOS
throw new ArgumentException("api");
}
static GLCalls CreateES1()
private static GLCalls CreateES1()
{
return new GLCalls() {
BindFramebuffer = (t, f) => ES11.GL.Oes.BindFramebuffer(t, f),
@ -90,7 +88,7 @@ namespace OpenTK.Platform.iPhoneOS
};
}
static GLCalls CreateES2()
private static GLCalls CreateES2()
{
return new GLCalls() {
BindFramebuffer = (t, f) => ES20.GL.BindFramebuffer((ES20.FramebufferTarget) t, f),
@ -109,7 +107,7 @@ namespace OpenTK.Platform.iPhoneOS
};
}
static GLCalls CreateES3()
private static GLCalls CreateES3()
{
return new GLCalls() {
BindFramebuffer = (t, f) => ES30.GL.BindFramebuffer((ES30.FramebufferTarget) t, f),
@ -129,7 +127,7 @@ namespace OpenTK.Platform.iPhoneOS
}
}
interface ITimeSource {
internal interface ITimeSource {
void Suspend ();
void Resume ();
@ -137,19 +135,21 @@ namespace OpenTK.Platform.iPhoneOS
}
[Register]
class CADisplayLinkTimeSource : NSObject, ITimeSource {
const string selectorName = "runIteration:";
static Selector selRunIteration = new Selector (selectorName);
internal class CADisplayLinkTimeSource : NSObject, ITimeSource {
private const string selectorName = "runIteration:";
private static Selector selRunIteration = new Selector (selectorName);
iPhoneOSGameView view;
CADisplayLink displayLink;
private iPhoneOSGameView view;
private CADisplayLink displayLink;
public CADisplayLinkTimeSource (iPhoneOSGameView view, int frameInterval)
{
this.view = view;
if (displayLink != null)
{
displayLink.Invalidate ();
}
displayLink = CADisplayLink.Create (this, selRunIteration);
displayLink.FrameInterval = frameInterval;
@ -177,18 +177,17 @@ namespace OpenTK.Platform.iPhoneOS
[Export (selectorName)]
[Preserve (Conditional = true)]
void RunIteration (NSObject parameter)
private void RunIteration (NSObject parameter)
{
view.RunIteration (null);
}
}
class NSTimerTimeSource : ITimeSource {
internal class NSTimerTimeSource : ITimeSource {
private TimeSpan timeout;
private NSTimer timer;
TimeSpan timeout;
NSTimer timer;
iPhoneOSGameView view;
private iPhoneOSGameView view;
public NSTimerTimeSource (iPhoneOSGameView view, double updatesPerSecond)
{
@ -211,7 +210,9 @@ namespace OpenTK.Platform.iPhoneOS
public void Resume ()
{
if (timeout != new TimeSpan (-1))
{
timer = NSTimer.CreateRepeatingScheduledTimer (timeout, view.RunIteration);
}
}
public void Invalidate ()
@ -225,19 +226,19 @@ namespace OpenTK.Platform.iPhoneOS
public class iPhoneOSGameView : UIView, IGameWindow
{
bool suspended;
bool disposed;
private bool suspended;
private bool disposed;
int framebuffer, renderbuffer;
private int framebuffer, renderbuffer;
GLCalls gl;
private GLCalls gl;
ITimeSource timesource;
System.Diagnostics.Stopwatch stopwatch;
TimeSpan prevUpdateTime;
TimeSpan prevRenderTime;
private ITimeSource timesource;
private System.Diagnostics.Stopwatch stopwatch;
private TimeSpan prevUpdateTime;
private TimeSpan prevRenderTime;
IWindowInfo windowInfo = Utilities.CreateDummyWindowInfo();
private IWindowInfo windowInfo = Utilities.CreateDummyWindowInfo();
[Export("initWithCoder:")]
public iPhoneOSGameView(NSCoder coder)
@ -259,19 +260,23 @@ namespace OpenTK.Platform.iPhoneOS
return new Class (typeof (CAEAGLLayer));
}
void AssertValid()
private void AssertValid()
{
if (disposed)
{
throw new ObjectDisposedException("");
}
}
void AssertContext()
private void AssertContext()
{
if (GraphicsContext == null)
{
throw new InvalidOperationException("Operation requires a GraphicsContext, which hasn't been created yet.");
}
}
EAGLRenderingAPI api;
private EAGLRenderingAPI api;
public EAGLRenderingAPI ContextRenderingApi {
get {
AssertValid();
@ -280,7 +285,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,18 +299,22 @@ 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;
}
}
bool retainedBacking;
private bool retainedBacking;
public bool LayerRetainsBacking {
get {
AssertValid();
@ -312,12 +323,14 @@ namespace OpenTK.Platform.iPhoneOS
set {
AssertValid();
if (GraphicsContext != null)
{
throw new NotSupportedException("Can't change LayerRetainsBacking after GraphicsContext is constructed.");
}
retainedBacking = value;
}
}
NSString colorFormat;
private NSString colorFormat;
public NSString LayerColorFormat {
get {
AssertValid();
@ -326,7 +339,9 @@ namespace OpenTK.Platform.iPhoneOS
set {
AssertValid();
if (GraphicsContext != null)
{
throw new NotSupportedException("Can't change LayerColorFormat after GraphicsContext is constructed.");
}
colorFormat = value;
}
}
@ -341,13 +356,15 @@ namespace OpenTK.Platform.iPhoneOS
public bool AutoResize {get; set;}
UIViewController GetViewController()
private UIViewController GetViewController()
{
UIResponder r = this;
while (r != null) {
var c = r as UIViewController;
if (c != null)
{
return c;
}
r = r.NextResponder;
}
return null;
@ -358,7 +375,9 @@ namespace OpenTK.Platform.iPhoneOS
AssertValid();
var c = GetViewController();
if (c != null)
{
return c.Title;
}
throw new NotSupportedException();
}
set {
@ -371,7 +390,9 @@ namespace OpenTK.Platform.iPhoneOS
}
}
else
{
throw new NotSupportedException();
}
}
}
@ -379,7 +400,9 @@ namespace OpenTK.Platform.iPhoneOS
{
var h = TitleChanged;
if (h != null)
{
h (this, EventArgs.Empty);
}
}
bool INativeWindow.Focused {
@ -404,7 +427,9 @@ namespace OpenTK.Platform.iPhoneOS
{
var h = VisibleChanged;
if (h != null)
{
h (this, EventArgs.Empty);
}
}
bool INativeWindow.Exists {
@ -427,7 +452,9 @@ namespace OpenTK.Platform.iPhoneOS
#else
if (c != null && c.WantsFullScreenLayout)
#endif
{
return WindowState.Fullscreen;
}
return WindowState.Normal;
}
set {
@ -454,7 +481,9 @@ namespace OpenTK.Platform.iPhoneOS
{
var h = WindowStateChanged;
if (h != null)
{
h (this, EventArgs.Empty);
}
}
public virtual WindowBorder WindowBorder {
@ -475,7 +504,7 @@ namespace OpenTK.Platform.iPhoneOS
set {throw new NotSupportedException();}
}
Size size;
private Size size;
public Size Size {
get {
AssertValid();
@ -494,7 +523,9 @@ namespace OpenTK.Platform.iPhoneOS
{
var h = Resize;
if (h != null)
{
h (this, e);
}
}
int INativeWindow.X {
@ -531,7 +562,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 +606,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;
@ -608,7 +647,7 @@ namespace OpenTK.Platform.iPhoneOS
CreateFrameBuffer(eaglLayer);
}
void CreateFrameBuffer(CAEAGLLayer eaglLayer)
private void CreateFrameBuffer(CAEAGLLayer eaglLayer)
{
int oldRenderbuffer = 1;
gl.GetInteger(All.RenderbufferBindingOes, out oldRenderbuffer);
@ -646,33 +685,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 +745,9 @@ namespace OpenTK.Platform.iPhoneOS
{
base.LayoutSubviews ();
if (GraphicsContext == null)
{
return;
}
var bounds = Bounds;
if (AutoResize && (Math.Round(bounds.Width) != Size.Width ||
@ -719,8 +772,8 @@ namespace OpenTK.Platform.iPhoneOS
GraphicsContext.SwapBuffers();
}
WeakReference frameBufferWindow;
WeakReference frameBufferLayer;
private WeakReference frameBufferWindow;
private WeakReference frameBufferLayer;
public void Run()
{
@ -730,17 +783,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,21 +813,25 @@ 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);
Start ();
}
void Start ()
private void Start ()
{
prevUpdateTime = TimeSpan.Zero;
prevRenderTime = TimeSpan.Zero;
@ -788,18 +849,22 @@ namespace OpenTK.Platform.iPhoneOS
OnUnload(EventArgs.Empty);
}
void Suspend ()
private void Suspend ()
{
if (timesource != null)
{
timesource.Suspend ();
}
stopwatch.Stop();
suspended = true;
}
void Resume ()
private void Resume ()
{
if (timesource != null)
{
timesource.Resume ();
}
stopwatch.Start();
suspended = false;
}
@ -833,7 +898,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 +934,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) {
@ -882,8 +949,8 @@ namespace OpenTK.Platform.iPhoneOS
}
}
FrameEventArgs updateEventArgs = new FrameEventArgs();
FrameEventArgs renderEventArgs = new FrameEventArgs();
private FrameEventArgs updateEventArgs = new FrameEventArgs();
private FrameEventArgs renderEventArgs = new FrameEventArgs();
internal void RunIteration (NSTimer timer)
{
@ -910,7 +977,9 @@ namespace OpenTK.Platform.iPhoneOS
{
var h = Load;
if (h != null)
{
h (this, e);
}
}
protected virtual void OnUnload(EventArgs e)
@ -918,21 +987,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<EventArgs> INativeWindow.Move {

View file

@ -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;
@ -15,8 +13,7 @@ using OpenGLES;
using OpenTK.Graphics;
namespace OpenTK.Platform.iPhoneOS {
class iPhoneOSGraphicsContext : EmbeddedGraphicsContext
internal class iPhoneOSGraphicsContext : EmbeddedGraphicsContext
{
public EAGLContext EAGLContext {get; private set;}
@ -33,13 +30,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 +65,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 +90,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 +128,9 @@ namespace OpenTK.Platform.iPhoneOS {
if (disposing)
{
if (EAGLContext != null)
{
EAGLContext.Dispose();
}
EAGLContext = null;
}
IsDisposed = true;