OffsetCalculator.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Ryujinx.Common;
  2. using static Ryujinx.Graphics.Texture.BlockLinearConstants;
  3. namespace Ryujinx.Graphics.Texture
  4. {
  5. public class OffsetCalculator
  6. {
  7. private int _stride;
  8. private bool _isLinear;
  9. private int _bytesPerPixel;
  10. private BlockLinearLayout _layoutConverter;
  11. public OffsetCalculator(
  12. int width,
  13. int height,
  14. int stride,
  15. bool isLinear,
  16. int gobBlocksInY,
  17. int bytesPerPixel)
  18. {
  19. _stride = stride;
  20. _isLinear = isLinear;
  21. _bytesPerPixel = bytesPerPixel;
  22. int wAlignment = GobStride / bytesPerPixel;
  23. int wAligned = BitUtils.AlignUp(width, wAlignment);
  24. if (!isLinear)
  25. {
  26. _layoutConverter = new BlockLinearLayout(
  27. wAligned,
  28. height,
  29. 1,
  30. gobBlocksInY,
  31. 1,
  32. bytesPerPixel);
  33. }
  34. }
  35. public int GetOffset(int x, int y)
  36. {
  37. if (_isLinear)
  38. {
  39. return x * _bytesPerPixel + y * _stride;
  40. }
  41. else
  42. {
  43. return _layoutConverter.GetOffset(x, y, 0);
  44. }
  45. }
  46. }
  47. }