aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Texture/SizeInfo.cs
diff options
context:
space:
mode:
authorgdk <gab.dark.100@gmail.com>2019-10-13 03:02:07 -0300
committerThog <thog@protonmail.com>2020-01-09 02:13:00 +0100
commit1876b346fea647e8284a66bb6d62c38801035cff (patch)
tree6eeff094298cda84d1613dc5ec0691e51d7b35f1 /Ryujinx.Graphics.Texture/SizeInfo.cs
parentf617fb542a0e3d36012d77a4b5acbde7b08902f2 (diff)
Initial work
Diffstat (limited to 'Ryujinx.Graphics.Texture/SizeInfo.cs')
-rw-r--r--Ryujinx.Graphics.Texture/SizeInfo.cs58
1 files changed, 58 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.Texture/SizeInfo.cs b/Ryujinx.Graphics.Texture/SizeInfo.cs
new file mode 100644
index 00000000..37d824cc
--- /dev/null
+++ b/Ryujinx.Graphics.Texture/SizeInfo.cs
@@ -0,0 +1,58 @@
+using Ryujinx.Common;
+using System;
+
+namespace Ryujinx.Graphics.Texture
+{
+ public struct SizeInfo
+ {
+ private int[] _mipOffsets;
+ private int[] _allOffsets;
+
+ private int _levels;
+
+ public int LayerSize { get; }
+ public int TotalSize { get; }
+
+ public SizeInfo(
+ int[] mipOffsets,
+ int[] allOffsets,
+ int levels,
+ int layerSize,
+ int totalSize)
+ {
+ _mipOffsets = mipOffsets;
+ _allOffsets = allOffsets;
+ _levels = levels;
+ LayerSize = layerSize;
+ TotalSize = totalSize;
+ }
+
+ public int GetMipOffset(int level)
+ {
+ if ((uint)level > _mipOffsets.Length)
+ {
+ throw new ArgumentOutOfRangeException(nameof(level));
+ }
+
+ return _mipOffsets[level];
+ }
+
+ public bool FindView(int offset, int size, out int firstLayer, out int firstLevel)
+ {
+ int index = Array.BinarySearch(_allOffsets, offset);
+
+ if (index < 0)
+ {
+ firstLayer = 0;
+ firstLevel = 0;
+
+ return false;
+ }
+
+ firstLayer = index / _levels;
+ firstLevel = index - (firstLayer * _levels);
+
+ return true;
+ }
+ }
+} \ No newline at end of file