From 26e53cce9829d6e5a3e35e1ddb621113748b3196 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 25 Apr 2023 22:16:52 +0200 Subject: [PATCH] Remove autoproperties from Color4 and Viewport types --- src/Vortice.Win32/Numerics/Color4.cs | 40 ++++++----- src/Vortice.Win32/Numerics/Viewport.cs | 93 ++++++++++++++------------ 2 files changed, 74 insertions(+), 59 deletions(-) diff --git a/src/Vortice.Win32/Numerics/Color4.cs b/src/Vortice.Win32/Numerics/Color4.cs index 07d3988..06c955f 100644 --- a/src/Vortice.Win32/Numerics/Color4.cs +++ b/src/Vortice.Win32/Numerics/Color4.cs @@ -20,6 +20,12 @@ public readonly struct Color4 { #if NET6_0_OR_GREATER private readonly Vector128 _value; +#else + // Note: intentionally using fields, as autoproperties fail to compile on .NET Native (UWP) + private readonly float _a; + private readonly float _r; + private readonly float _g; + private readonly float _b; #endif /// @@ -31,7 +37,7 @@ public readonly struct Color4 #if NET6_0_OR_GREATER _value = Vector128.Create(value, value, value, value); #else - A = R = G = B = value; + _a = _r = _g = _b = value; #endif } @@ -47,10 +53,10 @@ public readonly struct Color4 #if NET6_0_OR_GREATER _value = Vector128.Create(red, green, blue, alpha); #else - R = red; - G = green; - B = blue; - A = alpha; + _r = red; + _g = green; + _b = blue; + _a = alpha; #endif } @@ -63,10 +69,10 @@ public readonly struct Color4 #if NET6_0_OR_GREATER _value = value.AsVector128(); #else - R = value.X; - G = value.Y; - B = value.Z; - A = value.W; + _r = value.X; + _g = value.Y; + _b = value.Z; + _a = value.W; #endif } @@ -80,10 +86,10 @@ public readonly struct Color4 #if NET6_0_OR_GREATER _value = Vector128.Create(value.X, value.Y, value.Z, alpha); #else - R = value.X; - G = value.Y; - B = value.Z; - A = alpha; + _r = value.X; + _g = value.Y; + _b = value.Z; + _a = alpha; #endif } @@ -140,16 +146,16 @@ public readonly struct Color4 } #else /// Gets the value of the red component. - public float R { get; } + public float R => _r; /// Gets the value of the green component. - public float G { get; } + public float G => _g; /// Gets the value of the blue component. - public float B { get; } + public float B => _b; /// Gets the value of the alpha component. - public float A { get; } + public float A => _a; #endif public readonly float this[int index] diff --git a/src/Vortice.Win32/Numerics/Viewport.cs b/src/Vortice.Win32/Numerics/Viewport.cs index 85397b4..7570b15 100644 --- a/src/Vortice.Win32/Numerics/Viewport.cs +++ b/src/Vortice.Win32/Numerics/Viewport.cs @@ -19,6 +19,15 @@ namespace Win32.Numerics; [StructLayout(LayoutKind.Sequential, Pack = 4)] public readonly struct Viewport : IEquatable { + // Note: intentionally using fields, as autoproperties fail to compile on .NET Native (UWP). + // This applies to all targets (including .NET NET 6+), as there's no performance difference. + private readonly float _x; + private readonly float _y; + private readonly float _width; + private readonly float _height; + private readonly float _minDepth; + private readonly float _maxDepth; + /// /// Initializes a new instance of the struct. /// @@ -26,12 +35,12 @@ public readonly struct Viewport : IEquatable /// The height of the viewport in pixels. public Viewport(float width, float height) { - X = 0.0f; - Y = 0.0f; - Width = width; - Height = height; - MinDepth = 0.0f; - MaxDepth = 1.0f; + _x = 0.0f; + _y = 0.0f; + _width = width; + _height = height; + _minDepth = 0.0f; + _maxDepth = 1.0f; } /// @@ -43,12 +52,12 @@ public readonly struct Viewport : IEquatable /// The height of the viewport in pixels. public Viewport(float x, float y, float width, float height) { - X = x; - Y = y; - Width = width; - Height = height; - MinDepth = 0.0f; - MaxDepth = 1.0f; + _x = x; + _y = y; + _width = width; + _height = height; + _minDepth = 0.0f; + _maxDepth = 1.0f; } /// @@ -62,12 +71,12 @@ public readonly struct Viewport : IEquatable /// The maximum depth of the clip volume. public Viewport(float x, float y, float width, float height, float minDepth, float maxDepth) { - X = x; - Y = y; - Width = width; - Height = height; - MinDepth = minDepth; - MaxDepth = maxDepth; + _x = x; + _y = y; + _width = width; + _height = height; + _minDepth = minDepth; + _maxDepth = maxDepth; } /// @@ -76,12 +85,12 @@ public readonly struct Viewport : IEquatable /// A that defines the location and size of the viewport in a render target. public Viewport(in RectangleF bounds) { - X = bounds.X; - Y = bounds.Y; - Width = bounds.Width; - Height = bounds.Height; - MinDepth = 0.0f; - MaxDepth = 1.0f; + _x = bounds.X; + _y = bounds.Y; + _width = bounds.Width; + _height = bounds.Height; + _minDepth = 0.0f; + _maxDepth = 1.0f; } /// @@ -90,12 +99,12 @@ public readonly struct Viewport : IEquatable /// A that defines the location and size of the viewport in a render target. public Viewport(in Rectangle bounds) { - X = bounds.X; - Y = bounds.Y; - Width = bounds.Width; - Height = bounds.Height; - MinDepth = 0.0f; - MaxDepth = 1.0f; + _x = bounds.X; + _y = bounds.Y; + _width = bounds.Width; + _height = bounds.Height; + _minDepth = 0.0f; + _maxDepth = 1.0f; } /// @@ -104,43 +113,43 @@ public readonly struct Viewport : IEquatable /// A that defines the location and size of the viewport in a render target. public Viewport(in Vector4 bounds) { - X = bounds.X; - Y = bounds.Y; - Width = bounds.Z; - Height = bounds.W; - MinDepth = 0.0f; - MaxDepth = 1.0f; + _x = bounds.X; + _y = bounds.Y; + _width = bounds.Z; + _height = bounds.W; + _minDepth = 0.0f; + _maxDepth = 1.0f; } /// /// Position of the pixel coordinate of the upper-left corner of the viewport. /// - public float X { get; } + public float X => _x; /// /// Position of the pixel coordinate of the upper-left corner of the viewport. /// - public float Y { get; } + public float Y => _y; /// /// Width dimension of the viewport. /// - public float Width { get; } + public float Width => _width; /// /// Height dimension of the viewport. /// - public float Height { get; } + public float Height => _height; /// /// Gets or sets the minimum depth of the clip volume. /// - public float MinDepth { get; } + public float MinDepth => _minDepth; /// /// Gets or sets the maximum depth of the clip volume. /// - public float MaxDepth { get; } + public float MaxDepth => _maxDepth; /// /// Gets or sets the bounds of the viewport.