0
0
Fork 0
This repository has been archived on 2024-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
ryujinx-final/Ryujinx.Graphics.Texture/OffsetCalculator.cs
2020-01-09 02:13:00 +01:00

55 lines
No EOL
1.3 KiB
C#

using Ryujinx.Common;
using static Ryujinx.Graphics.Texture.BlockLinearConstants;
namespace Ryujinx.Graphics.Texture
{
public class OffsetCalculator
{
private int _stride;
private bool _isLinear;
private int _bytesPerPixel;
private BlockLinearLayout _layoutConverter;
public OffsetCalculator(
int width,
int height,
int stride,
bool isLinear,
int gobBlocksInY,
int bytesPerPixel)
{
_stride = stride;
_isLinear = isLinear;
_bytesPerPixel = bytesPerPixel;
int wAlignment = GobStride / bytesPerPixel;
int wAligned = BitUtils.AlignUp(width, wAlignment);
if (!isLinear)
{
_layoutConverter = new BlockLinearLayout(
wAligned,
height,
1,
gobBlocksInY,
1,
bytesPerPixel);
}
}
public int GetOffset(int x, int y)
{
if (_isLinear)
{
return x * _bytesPerPixel + y * _stride;
}
else
{
return _layoutConverter.GetOffset(x, y, 0);
}
}
}
}