1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-28 14:42:03 +00:00
Ryujinx/Ryujinx.Graphics.GAL/TextureCreateInfo.cs

121 lines
3.6 KiB
C#
Raw Normal View History

2019-10-13 07:02:07 +01:00
using Ryujinx.Common;
using System;
2019-12-29 17:41:50 +00:00
namespace Ryujinx.Graphics.GAL
2019-10-13 07:02:07 +01:00
{
public struct TextureCreateInfo
{
public int Width { get; }
public int Height { get; }
public int Depth { get; }
public int Levels { get; }
public int Samples { get; }
public int BlockWidth { get; }
public int BlockHeight { get; }
public int BytesPerPixel { get; }
public bool IsCompressed => (BlockWidth | BlockHeight) != 1;
public Format Format { get; }
public DepthStencilMode DepthStencilMode { get; }
public Target Target { get; }
public SwizzleComponent SwizzleR { get; }
public SwizzleComponent SwizzleG { get; }
public SwizzleComponent SwizzleB { get; }
public SwizzleComponent SwizzleA { get; }
public TextureCreateInfo(
int width,
int height,
int depth,
int levels,
int samples,
int blockWidth,
int blockHeight,
int bytesPerPixel,
Format format,
DepthStencilMode depthStencilMode,
Target target,
SwizzleComponent swizzleR,
SwizzleComponent swizzleG,
SwizzleComponent swizzleB,
SwizzleComponent swizzleA)
{
Width = width;
Height = height;
Depth = depth;
Levels = levels;
Samples = samples;
BlockWidth = blockWidth;
BlockHeight = blockHeight;
BytesPerPixel = bytesPerPixel;
Format = format;
DepthStencilMode = depthStencilMode;
Target = target;
SwizzleR = swizzleR;
SwizzleG = swizzleG;
SwizzleB = swizzleB;
SwizzleA = swizzleA;
}
public readonly int GetMipSize(int level)
2019-10-13 07:02:07 +01:00
{
return GetMipStride(level) * GetLevelHeight(level) * GetLevelDepth(level);
}
public readonly int GetMipSize2D(int level)
{
return GetMipStride(level) * GetLevelHeight(level);
}
public readonly int GetMipStride(int level)
2019-10-13 07:02:07 +01:00
{
return BitUtils.AlignUp(GetLevelWidth(level) * BytesPerPixel, 4);
}
private readonly int GetLevelWidth(int level)
2019-10-13 07:02:07 +01:00
{
return BitUtils.DivRoundUp(GetLevelSize(Width, level), BlockWidth);
}
private readonly int GetLevelHeight(int level)
2019-10-13 07:02:07 +01:00
{
return BitUtils.DivRoundUp(GetLevelSize(Height, level), BlockHeight);
}
private readonly int GetLevelDepth(int level)
2019-10-13 07:02:07 +01:00
{
return Target == Target.Texture3D ? GetLevelSize(Depth, level) : GetLayers();
}
public readonly int GetDepthOrLayers()
2019-10-13 07:02:07 +01:00
{
return Target == Target.Texture3D ? Depth : GetLayers();
}
public readonly int GetLayers()
2019-10-13 07:02:07 +01:00
{
if (Target == Target.Texture2DArray ||
Target == Target.Texture2DMultisampleArray ||
Target == Target.CubemapArray)
{
return Depth;
}
else if (Target == Target.Cubemap)
{
return 6;
}
return 1;
}
private static int GetLevelSize(int size, int level)
{
return Math.Max(1, size >> level);
}
}
}