2019-10-13 00:02:07 -06:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Texture
|
|
|
|
{
|
|
|
|
public struct SizeInfo
|
|
|
|
{
|
2020-04-25 07:02:18 -06:00
|
|
|
private readonly int[] _mipOffsets;
|
|
|
|
private readonly int[] _allOffsets;
|
2019-10-13 00:02:07 -06:00
|
|
|
|
2020-04-25 07:02:18 -06:00
|
|
|
private readonly int _levels;
|
2019-10-13 00:02:07 -06:00
|
|
|
|
|
|
|
public int LayerSize { get; }
|
|
|
|
public int TotalSize { get; }
|
|
|
|
|
2020-04-25 07:02:18 -06:00
|
|
|
public SizeInfo(int size)
|
|
|
|
{
|
|
|
|
_mipOffsets = new int[] { 0 };
|
|
|
|
_allOffsets = new int[] { 0 };
|
|
|
|
_levels = 1;
|
|
|
|
LayerSize = size;
|
|
|
|
TotalSize = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal SizeInfo(
|
2019-10-13 00:02:07 -06:00
|
|
|
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)
|
|
|
|
{
|
2020-04-25 07:02:18 -06:00
|
|
|
if ((uint)level >= _mipOffsets.Length)
|
2019-10-13 00:02:07 -06:00
|
|
|
{
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(level));
|
|
|
|
}
|
|
|
|
|
|
|
|
return _mipOffsets[level];
|
|
|
|
}
|
|
|
|
|
2021-01-17 11:44:34 -07:00
|
|
|
public bool FindView(int offset, out int firstLayer, out int firstLevel)
|
2019-10-13 00:02:07 -06:00
|
|
|
{
|
|
|
|
int index = Array.BinarySearch(_allOffsets, offset);
|
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
{
|
|
|
|
firstLayer = 0;
|
|
|
|
firstLevel = 0;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
firstLayer = index / _levels;
|
|
|
|
firstLevel = index - (firstLayer * _levels);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|