mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-02-21 16:43:35 +00:00
Consolidate UpdateDepthMode and GetDepthMode implementation
This commit is contained in:
parent
dd54eb4be1
commit
39467f7062
1 changed files with 29 additions and 43 deletions
|
@ -682,37 +682,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void UpdateDepthMode()
|
private void UpdateDepthMode()
|
||||||
{
|
{
|
||||||
ref var transform = ref _state.State.ViewportTransform[0];
|
_context.Renderer.Pipeline.SetDepthMode(GetDepthMode());
|
||||||
ref var extents = ref _state.State.ViewportExtents[0];
|
|
||||||
|
|
||||||
DepthMode depthMode;
|
|
||||||
|
|
||||||
if (!float.IsInfinity(extents.DepthNear) &&
|
|
||||||
!float.IsInfinity(extents.DepthFar) &&
|
|
||||||
(extents.DepthFar - extents.DepthNear) != 0)
|
|
||||||
{
|
|
||||||
// Try to guess the depth mode being used on the high level API
|
|
||||||
// based on current transform.
|
|
||||||
// It is setup like so by said APIs:
|
|
||||||
// If depth mode is ZeroToOne:
|
|
||||||
// TranslateZ = Near
|
|
||||||
// ScaleZ = Far - Near
|
|
||||||
// If depth mode is MinusOneToOne:
|
|
||||||
// TranslateZ = (Near + Far) / 2
|
|
||||||
// ScaleZ = (Far - Near) / 2
|
|
||||||
// DepthNear/Far are sorted such as that Near is always less than Far.
|
|
||||||
depthMode = extents.DepthNear != transform.TranslateZ &&
|
|
||||||
extents.DepthFar != transform.TranslateZ
|
|
||||||
? DepthMode.MinusOneToOne
|
|
||||||
: DepthMode.ZeroToOne;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// If we can't guess from the viewport transform, then just use the depth mode register.
|
|
||||||
depthMode = (DepthMode)(_state.State.DepthMode & 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
_context.Renderer.Pipeline.SetDepthMode(depthMode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1301,18 +1271,34 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
||||||
ref var transform = ref _state.State.ViewportTransform[0];
|
ref var transform = ref _state.State.ViewportTransform[0];
|
||||||
ref var extents = ref _state.State.ViewportExtents[0];
|
ref var extents = ref _state.State.ViewportExtents[0];
|
||||||
|
|
||||||
// Try to guess the depth mode being used on the high level API
|
DepthMode depthMode;
|
||||||
// based on current transform.
|
|
||||||
// It is setup like so by said APIs:
|
if (!float.IsInfinity(extents.DepthNear) &&
|
||||||
// If depth mode is ZeroToOne:
|
!float.IsInfinity(extents.DepthFar) &&
|
||||||
// TranslateZ = Near
|
(extents.DepthFar - extents.DepthNear) != 0)
|
||||||
// ScaleZ = Far - Near
|
{
|
||||||
// If depth mode is MinusOneToOne:
|
// Try to guess the depth mode being used on the high level API
|
||||||
// TranslateZ = (Near + Far) / 2
|
// based on current transform.
|
||||||
// ScaleZ = (Far - Near) / 2
|
// It is setup like so by said APIs:
|
||||||
// DepthNear/Far are sorted such as that Near is always less than Far.
|
// If depth mode is ZeroToOne:
|
||||||
return extents.DepthNear != transform.TranslateZ &&
|
// TranslateZ = Near
|
||||||
extents.DepthFar != transform.TranslateZ ? DepthMode.MinusOneToOne : DepthMode.ZeroToOne;
|
// ScaleZ = Far - Near
|
||||||
|
// If depth mode is MinusOneToOne:
|
||||||
|
// TranslateZ = (Near + Far) / 2
|
||||||
|
// ScaleZ = (Far - Near) / 2
|
||||||
|
// DepthNear/Far are sorted such as that Near is always less than Far.
|
||||||
|
depthMode = extents.DepthNear != transform.TranslateZ &&
|
||||||
|
extents.DepthFar != transform.TranslateZ
|
||||||
|
? DepthMode.MinusOneToOne
|
||||||
|
: DepthMode.ZeroToOne;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If we can't guess from the viewport transform, then just use the depth mode register.
|
||||||
|
depthMode = (DepthMode)(_state.State.DepthMode & 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return depthMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in a new issue