"Inline" some vector and matrix operations
This commit is contained in:
parent
3dd03495e2
commit
337b054042
|
@ -233,7 +233,7 @@ namespace BizHawk.Bizware.BizwareGL
|
|||
//projection is always identity, so who cares i guess
|
||||
//Matrix4 mat = Projection.Top * Modelview.Top;
|
||||
Matrix4 mat = Modelview.Top;
|
||||
g.Transform = new sd.Drawing2D.Matrix(mat.M11, mat.M12, mat.M21, mat.M22, mat.M41, mat.M42);
|
||||
g.Transform = new sd.Drawing2D.Matrix(mat.Row0.X, mat.Row0.Y, mat.Row1.X, mat.Row1.Y, mat.Row3.X, mat.Row3.Y);
|
||||
}
|
||||
|
||||
private unsafe void DrawInternal(Art art, float x, float y, float w, float h)
|
||||
|
|
|
@ -92,8 +92,7 @@ namespace BizHawk.Bizware.BizwareGL
|
|||
|
||||
var Projection = Owner.CreateGuiProjectionMatrix(OutputSize);
|
||||
var Modelview = Owner.CreateGuiViewMatrix(OutputSize);
|
||||
var mat = Modelview * Projection;
|
||||
mat.Transpose();
|
||||
var mat = Matrix4.Transpose(Modelview * Projection);
|
||||
Pipeline["modelViewProj"].Set(mat, true);
|
||||
|
||||
Owner.SetTextureWrapMode(tex, true);
|
||||
|
|
|
@ -754,17 +754,17 @@ namespace BizHawk.Bizware.DirectX
|
|||
public Matrix4 CreateGuiProjectionMatrix(Size dims)
|
||||
{
|
||||
Matrix4 ret = Matrix4.Identity;
|
||||
ret.M11 = 2.0f / (float)dims.Width;
|
||||
ret.M22 = 2.0f / (float)dims.Height;
|
||||
ret.Row0.X = 2.0f / (float)dims.Width;
|
||||
ret.Row1.Y = 2.0f / (float)dims.Height;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Matrix4 CreateGuiViewMatrix(Size dims, bool autoFlip)
|
||||
{
|
||||
Matrix4 ret = Matrix4.Identity;
|
||||
ret.M22 = -1.0f;
|
||||
ret.M41 = -(float)dims.Width * 0.5f - 0.5f;
|
||||
ret.M42 = (float)dims.Height * 0.5f + 0.5f;
|
||||
ret.Row1.Y = -1.0f;
|
||||
ret.Row3.X = -(float)dims.Width * 0.5f - 0.5f;
|
||||
ret.Row3.Y = (float)dims.Height * 0.5f + 0.5f;
|
||||
|
||||
// auto-flipping isn't needed on d3d
|
||||
return ret;
|
||||
|
|
|
@ -1,46 +1,24 @@
|
|||
namespace BizHawk.Bizware.DirectX
|
||||
using SlimDX;
|
||||
|
||||
namespace BizHawk.Bizware.DirectX
|
||||
{
|
||||
internal static class Extensions
|
||||
{
|
||||
public static global::SlimDX.Matrix ToSlimDXMatrix(this OpenTK.Matrix4 m, bool transpose)
|
||||
public static Matrix ToSlimDXMatrix(this OpenTK.Matrix4 m, bool transpose)
|
||||
{
|
||||
global::SlimDX.Matrix ret = new global::SlimDX.Matrix
|
||||
Matrix ret = new()
|
||||
{
|
||||
M11 = m.M11,
|
||||
M12 = m.M12,
|
||||
M13 = m.M13,
|
||||
M14 = m.M14,
|
||||
M21 = m.M21,
|
||||
M22 = m.M22,
|
||||
M23 = m.M23,
|
||||
M24 = m.M24,
|
||||
M31 = m.M31,
|
||||
M32 = m.M32,
|
||||
M33 = m.M33,
|
||||
M34 = m.M34,
|
||||
M41 = m.M41,
|
||||
M42 = m.M42,
|
||||
M43 = m.M43,
|
||||
M44 = m.M44
|
||||
M11 = m.Row0.X, M12 = m.Row0.Y, M13 = m.Row0.Z, M14 = m.Row0.W,
|
||||
M21 = m.Row1.X, M22 = m.Row1.Y, M23 = m.Row1.Z, M24 = m.Row1.W,
|
||||
M31 = m.Row2.X, M32 = m.Row2.Y, M33 = m.Row2.Z, M34 = m.Row2.W,
|
||||
M41 = m.Row3.X, M42 = m.Row3.Y, M43 = m.Row3.Z, M44 = m.Row3.W
|
||||
};
|
||||
|
||||
//could be optimized later into the above copies
|
||||
if (transpose)
|
||||
{
|
||||
ret = global::SlimDX.Matrix.Transpose(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
// Transpose call could be inlined to reduce 2 sets of copies to 1
|
||||
return transpose ? Matrix.Transpose(ret) : ret;
|
||||
}
|
||||
|
||||
public static global::SlimDX.Vector4 ToSlimDXVector4(this OpenTK.Vector4 v)
|
||||
{
|
||||
return new global::SlimDX.Vector4(v.X, v.Y, v.Z, v.W);
|
||||
}
|
||||
public static Vector2 ToSlimDXVector2(this OpenTK.Vector2 v) => new(v.X, v.Y);
|
||||
|
||||
public static global::SlimDX.Vector2 ToSlimDXVector2(this OpenTK.Vector2 v)
|
||||
{
|
||||
return new global::SlimDX.Vector2(v.X, v.Y);
|
||||
}
|
||||
public static Vector4 ToSlimDXVector4(this OpenTK.Vector4 v) => new(v.X, v.Y, v.Z, v.W);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,9 +67,7 @@ namespace BizHawk.Client.Common.Filters
|
|||
// apply the zooming algorithm (pasted and reworked, for now)
|
||||
// ALERT COPYPASTE LAUNDROMAT
|
||||
|
||||
Vector2 VS = new Vector2(virtualWidth, virtualHeight);
|
||||
Vector2 BS = new Vector2(textureWidth, textureHeight);
|
||||
Vector2 AR = Vector2.Divide(VS, BS);
|
||||
Vector2 AR = new(virtualWidth / (float) textureWidth, virtualHeight / (float) textureHeight);
|
||||
float targetPar = (AR.X / AR.Y);
|
||||
Vector2 PS = new Vector2(1, 1); //this would malfunction for AR <= 0.5 or AR >= 2.0
|
||||
|
||||
|
@ -352,8 +350,7 @@ namespace BizHawk.Client.Common.Filters
|
|||
|
||||
//in case we're in this layout, we get confused, so fix it
|
||||
var settings = nds.GetSettings();
|
||||
if (settings.ScreenLayout == MelonDS.ScreenLayoutKind.Top)
|
||||
point = Vector2.Zero;
|
||||
if (settings.ScreenLayout == MelonDS.ScreenLayoutKind.Top) point = new(0.0f, 0.0f);
|
||||
|
||||
//TODO: we probably need more subtle logic here.
|
||||
//some capability to return -1,-1 perhaps in case the cursor is nowhere.
|
||||
|
|
|
@ -668,9 +668,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (arInteger)
|
||||
{
|
||||
// ALERT COPYPASTE LAUNDROMAT
|
||||
Vector2 VS = new Vector2(virtualWidth, virtualHeight);
|
||||
Vector2 BS = new Vector2(bufferWidth, bufferHeight);
|
||||
Vector2 AR = Vector2.Divide(VS, BS);
|
||||
Vector2 AR = new(virtualWidth / (float) bufferWidth, virtualHeight / (float) bufferHeight);
|
||||
float targetPar = AR.X / AR.Y;
|
||||
|
||||
// this would malfunction for AR <= 0.5 or AR >= 2.0
|
||||
|
|
|
@ -604,25 +604,25 @@ namespace BizHawk.Client.EmuHawk
|
|||
public Matrix4 CreateGuiProjectionMatrix(sd.Size dims)
|
||||
{
|
||||
Matrix4 ret = Matrix4.Identity;
|
||||
ret.M11 = 2.0f / (float)dims.Width;
|
||||
ret.M22 = 2.0f / (float)dims.Height;
|
||||
ret.Row0.X = 2.0f / (float)dims.Width;
|
||||
ret.Row1.Y = 2.0f / (float)dims.Height;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Matrix4 CreateGuiViewMatrix(sd.Size dims, bool autoflip)
|
||||
{
|
||||
Matrix4 ret = Matrix4.Identity;
|
||||
ret.M22 = -1.0f;
|
||||
ret.M41 = -(float)dims.Width * 0.5f;
|
||||
ret.M42 = (float)dims.Height * 0.5f;
|
||||
ret.Row1.Y = -1.0f;
|
||||
ret.Row3.X = -(float)dims.Width * 0.5f;
|
||||
ret.Row3.Y = (float)dims.Height * 0.5f;
|
||||
if (autoflip)
|
||||
{
|
||||
if (_currRenderTarget == null) { }
|
||||
else
|
||||
{
|
||||
//flip as long as we're not a final render target
|
||||
ret.M22 = 1.0f;
|
||||
ret.M42 *= -1;
|
||||
ret.Row1.Y = 1.0f;
|
||||
ret.Row3.Y *= -1;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
Loading…
Reference in New Issue