From 38ea2919c2b813ae90f91def049a4d15abd19dab Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 19 Sep 2017 23:41:32 +1000 Subject: [PATCH] eliminate pointless M11-M44 get/set in Matrix4 --- ClassicalSharp/GraphicsAPI/Direct3D9Api.cs | 7 ++- OpenTK/Math/Matrix4.cs | 62 +++------------------- OpenTK/Platform/MacOS/AglContext.cs | 6 +-- OpenTK/Platform/MacOS/CarbonGLNative.cs | 23 ++++---- 4 files changed, 23 insertions(+), 75 deletions(-) diff --git a/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs b/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs index 06a31114e..d750195c3 100644 --- a/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs +++ b/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs @@ -371,7 +371,7 @@ namespace ClassicalSharp.GraphicsAPI { public unsafe override void LoadMatrix(ref Matrix4 matrix) { if (curStack == texStack) { - matrix.M31 = matrix.M41; // NOTE: this hack fixes the texture movements. + matrix.Row2.X = matrix.Row3.X; // NOTE: this hack fixes the texture movements. device.SetTextureStageState(0, TextureStage.TextureTransformFlags, (int)TextureTransform.Count2); } curStack.SetTop(ref matrix); @@ -567,9 +567,8 @@ namespace ClassicalSharp.GraphicsAPI { Matrix4 matrix; Matrix4.CreateOrthographicOffCenter(0, width, height, 0, -10000, 10000, out matrix); const float zN = -10000, zF = 10000; - matrix.M33 = 1 / (zN - zF); - matrix.M43 = zN / (zN - zF); - matrix.M44 = 1; + matrix.Row2.Z = 1 / (zN - zF); + matrix.Row3.Z = zN / (zN - zF); curStack.SetTop(ref matrix); } diff --git a/OpenTK/Math/Matrix4.cs b/OpenTK/Math/Matrix4.cs index 90ebfbc7c..c3ad601d3 100644 --- a/OpenTK/Math/Matrix4.cs +++ b/OpenTK/Math/Matrix4.cs @@ -60,54 +60,6 @@ namespace OpenTK { Row3 = new Vector4(m30, m31, m32, m33); } - /// Gets or sets the value at row 1, column 1 of this instance. - public float M11 { get { return Row0.X; } set { Row0.X = value; } } - - /// Gets or sets the value at row 1, column 2 of this instance. - public float M12 { get { return Row0.Y; } set { Row0.Y = value; } } - - /// Gets or sets the value at row 1, column 3 of this instance. - public float M13 { get { return Row0.Z; } set { Row0.Z = value; } } - - /// Gets or sets the value at row 1, column 4 of this instance. - public float M14 { get { return Row0.W; } set { Row0.W = value; } } - - /// Gets or sets the value at row 2, column 1 of this instance. - public float M21 { get { return Row1.X; } set { Row1.X = value; } } - - /// Gets or sets the value at row 2, column 2 of this instance. - public float M22 { get { return Row1.Y; } set { Row1.Y = value; } } - - /// Gets or sets the value at row 2, column 3 of this instance. - public float M23 { get { return Row1.Z; } set { Row1.Z = value; } } - - /// Gets or sets the value at row 2, column 4 of this instance. - public float M24 { get { return Row1.W; } set { Row1.W = value; } } - - /// Gets or sets the value at row 3, column 1 of this instance. - public float M31 { get { return Row2.X; } set { Row2.X = value; } } - - /// Gets or sets the value at row 3, column 2 of this instance. - public float M32 { get { return Row2.Y; } set { Row2.Y = value; } } - - /// Gets or sets the value at row 3, column 3 of this instance. - public float M33 { get { return Row2.Z; } set { Row2.Z = value; } } - - /// Gets or sets the value at row 3, column 4 of this instance. - public float M34 { get { return Row2.W; } set { Row2.W = value; } } - - /// Gets or sets the value at row 4, column 1 of this instance. - public float M41 { get { return Row3.X; } set { Row3.X = value; } } - - /// Gets or sets the value at row 4, column 2 of this instance. - public float M42 { get { return Row3.Y; } set { Row3.Y = value; } } - - /// Gets or sets the value at row 4, column 3 of this instance. - public float M43 { get { return Row3.Z; } set { Row3.Z = value; } } - - /// Gets or sets the value at row 4, column 4 of this instance. - public float M44 { get { return Row3.W; } set { Row3.W = value; } } - public static void RotateX(out Matrix4 result, float angle) { float cos = (float)Math.Cos(angle); float sin = (float)Math.Sin(angle); @@ -157,14 +109,14 @@ namespace OpenTK { float invTB = 1 / (top - bottom); float invFN = 1 / (zFar - zNear); - result.M11 = 2 * invRL; - result.M22 = 2 * invTB; - result.M33 = -2 * invFN; + result.Row0.X = 2 * invRL; + result.Row1.Y = 2 * invTB; + result.Row2.Z = -2 * invFN; - result.M41 = -(right + left) * invRL; - result.M42 = -(top + bottom) * invTB; - result.M43 = -(zFar + zNear) * invFN; - result.M44 = 1; + result.Row3.X = -(right + left) * invRL; + result.Row3.Y = -(top + bottom) * invTB; + result.Row3.Z = -(zFar + zNear) * invFN; + result.Row3.W = 1; } public static void CreatePerspectiveFieldOfView(float fovy, float aspect, float zNear, float zFar, out Matrix4 result) { diff --git a/OpenTK/Platform/MacOS/AglContext.cs b/OpenTK/Platform/MacOS/AglContext.cs index 1ddecad4f..07b4a0bbc 100644 --- a/OpenTK/Platform/MacOS/AglContext.cs +++ b/OpenTK/Platform/MacOS/AglContext.cs @@ -114,10 +114,10 @@ namespace OpenTK.Platform.MacOS { { IntPtr windowRef = carbonWindow.WindowRef; - if (!CarbonGLNative.WindowRefMap.ContainsKey(windowRef)) + if (!CarbonGLNative.WindowRefs.ContainsKey(windowRef)) return IntPtr.Zero; - WeakReference nativeRef = CarbonGLNative.WindowRefMap[windowRef]; + WeakReference nativeRef = CarbonGLNative.WindowRefs[windowRef]; if (!nativeRef.IsAlive) return IntPtr.Zero; @@ -176,7 +176,7 @@ namespace OpenTK.Platform.MacOS { private CarbonGLNative GetCarbonWindow(CarbonWindowInfo carbonWindow) { - WeakReference r = CarbonGLNative.WindowRefMap[carbonWindow.WindowRef]; + WeakReference r = CarbonGLNative.WindowRefs[carbonWindow.WindowRef]; return r.IsAlive ? (CarbonGLNative)r.Target : null; } diff --git a/OpenTK/Platform/MacOS/CarbonGLNative.cs b/OpenTK/Platform/MacOS/CarbonGLNative.cs index 4c924ad15..05d7e864b 100644 --- a/OpenTK/Platform/MacOS/CarbonGLNative.cs +++ b/OpenTK/Platform/MacOS/CarbonGLNative.cs @@ -48,20 +48,17 @@ namespace OpenTK.Platform.MacOS Rectangle windowedBounds; bool mIsDisposed = false; bool mExists = true; - DisplayDevice mDisplayDevice; + internal DisplayDevice TargetDisplayDevice; WindowPositionMethod mPositionMethod = WindowPositionMethod.CenterOnMainScreen; int mTitlebarHeight; - private WindowState windowState = WindowState.Normal; - static Dictionary mWindows = new Dictionary(); + WindowState windowState = WindowState.Normal; + internal static Dictionary WindowRefs = new Dictionary(); KeyPressEventArgs mKeyPressArgs = new KeyPressEventArgs(); bool mMouseIn = false; bool mIsActive = false; Icon mIcon; - static internal Dictionary WindowRefMap { get { return mWindows; } } - internal DisplayDevice TargetDisplayDevice { get { return mDisplayDevice; } } - static CarbonGLNative() { Application.Initialize(); } @@ -74,7 +71,7 @@ namespace OpenTK.Platform.MacOS WindowAttributes.InWindowMenu | WindowAttributes.LiveResize, new Rect((short)x, (short)y, (short)width, (short)height)); - mDisplayDevice = device; + TargetDisplayDevice = device; } #region IDisposable @@ -95,7 +92,7 @@ namespace OpenTK.Platform.MacOS mExists = false; if (disposing) { - mWindows.Remove(window.WindowRef); + WindowRefs.Remove(window.WindowRef); window = null; } DisposeUPP(); @@ -132,7 +129,7 @@ namespace OpenTK.Platform.MacOS window = new CarbonWindowInfo(windowRef); SetLocation(r.X, r.Y); SetSize(r.Width, r.Height); - mWindows.Add(windowRef, new WeakReference(this)); + WindowRefs.Add(windowRef, new WeakReference(this)); LoadSize(); Rect titleSize = API.GetWindowBounds(window.WindowRef, WindowRegionCode.TitleBarRegion); @@ -196,7 +193,7 @@ namespace OpenTK.Platform.MacOS Debug.Print("New Size: {0}, {1}", ClientRectangle.Width, ClientRectangle.Height); // TODO: if we go full screen we need to make this use the device specified. - bounds = mDisplayDevice.Bounds; + bounds = TargetDisplayDevice.Bounds; windowState = WindowState.Fullscreen; } @@ -231,14 +228,14 @@ namespace OpenTK.Platform.MacOS { // bail out if the window passed in is not actually our window. // I think this happens if using winforms with a GameWindow sometimes. - if (!mWindows.ContainsKey(userData)) + if (!WindowRefs.ContainsKey(userData)) return OSStatus.EventNotHandled; - WeakReference reference = mWindows[userData]; + WeakReference reference = WindowRefs[userData]; // bail out if the CarbonGLNative window has been garbage collected. if (!reference.IsAlive) { - mWindows.Remove(userData); + WindowRefs.Remove(userData); return OSStatus.EventNotHandled; }