[Feat] (MG_Util/Types): Add ComponentSizes.

This commit is contained in:
BZLZHH
2025-12-14 11:15:27 +08:00
parent 711e427b76
commit 100d5bca99
3 changed files with 196 additions and 0 deletions
+186
View File
@@ -1,4 +1,5 @@
#include "TextureMetrics.h"
#include "Defines.h"
#include "MG_Util/Math/VectorTypes.h"
namespace MobileGL {
@@ -220,5 +221,190 @@ namespace MobileGL {
return GetInputBytesPerPixel(internalFormat, pixelDataType) * size.x() * size.y() * size.z();
}
ComponentSizes GetComponentSizesForInternalFormat(TextureInternalFormat internal) {
ComponentSizes s = {};
switch (internal) {
case TextureInternalFormat::R8:
case TextureInternalFormat::Red:
case TextureInternalFormat::R8Snorm:
case TextureInternalFormat::R8I:
case TextureInternalFormat::R8UI:
s.Red = 8;
break;
case TextureInternalFormat::R16:
case TextureInternalFormat::R16Snorm:
case TextureInternalFormat::R16I:
case TextureInternalFormat::R16UI:
case TextureInternalFormat::R16F:
s.Red = 16;
break;
case TextureInternalFormat::RG8:
case TextureInternalFormat::RG8Snorm:
case TextureInternalFormat::RG8I:
case TextureInternalFormat::RG8UI:
case TextureInternalFormat::RG:
s.Red = 8;
s.Green = 8;
break;
case TextureInternalFormat::RG16:
case TextureInternalFormat::RG16Snorm:
case TextureInternalFormat::RG16I:
case TextureInternalFormat::RG16UI:
case TextureInternalFormat::RG16F:
s.Red = 16;
s.Green = 16;
break;
case TextureInternalFormat::RGB4:
case TextureInternalFormat::RGB5:
case TextureInternalFormat::RGB8:
case TextureInternalFormat::RGB8Snorm:
case TextureInternalFormat::SRGB8:
case TextureInternalFormat::RGB8I:
case TextureInternalFormat::RGB8UI:
case TextureInternalFormat::RGB:
s.Red = 8;
s.Green = 8;
s.Blue = 8;
break;
case TextureInternalFormat::R3G3B2:
s.Red = 3;
s.Green = 3;
s.Blue = 2;
break;
case TextureInternalFormat::RGBA2:
s.Red = 2;
s.Green = 2;
s.Blue = 2;
s.Alpha = 2;
break;
case TextureInternalFormat::RGBA4:
s.Red = 4;
s.Green = 4;
s.Blue = 4;
s.Alpha = 4;
break;
case TextureInternalFormat::RGB5A1:
s.Red = 5;
s.Green = 5;
s.Blue = 5;
s.Alpha = 1;
break;
case TextureInternalFormat::RGBA8:
case TextureInternalFormat::RGBA8Snorm:
case TextureInternalFormat::RGBA8I:
case TextureInternalFormat::RGBA8UI:
case TextureInternalFormat::SRGB8Alpha8:
case TextureInternalFormat::RGBA:
break;
s.Red = 8;
s.Green = 8;
s.Blue = 8;
s.Alpha = 8;
break;
case TextureInternalFormat::RGB10A2:
case TextureInternalFormat::RGB10A2UI:
s.Red = 10;
s.Green = 10;
s.Blue = 10;
s.Alpha = 2;
break;
case TextureInternalFormat::R32F:
s.Red = 32;
break;
case TextureInternalFormat::RG32F:
case TextureInternalFormat::RG32I:
case TextureInternalFormat::RG32UI:
s.Red = 32;
s.Green = 32;
break;
case TextureInternalFormat::RGBA12:
s.Red = 12;
s.Green = 12;
s.Blue = 12;
s.Alpha = 12;
break;
case TextureInternalFormat::RGBA16:
case TextureInternalFormat::RGBA16I:
case TextureInternalFormat::RGBA16UI:
case TextureInternalFormat::RGBA16F:
s.Red = 16;
s.Green = 16;
s.Blue = 16;
s.Alpha = 16;
break;
case TextureInternalFormat::RGB16F:
case TextureInternalFormat::RGB16I:
case TextureInternalFormat::RGB16UI:
s.Red = 16;
s.Green = 16;
s.Blue = 16;
break;
case TextureInternalFormat::RGB32F:
case TextureInternalFormat::RGB32I:
case TextureInternalFormat::RGB32UI:
s.Red = 32;
s.Green = 32;
s.Blue = 32;
break;
case TextureInternalFormat::RGBA32F:
case TextureInternalFormat::RGBA32I:
case TextureInternalFormat::RGBA32UI:
s.Red = 32;
s.Green = 32;
s.Blue = 32;
s.Alpha = 32;
break;
case TextureInternalFormat::R11FG11FB10F:
s.Red = 11;
s.Green = 11;
s.Blue = 10;
break;
case TextureInternalFormat::RGB9E5:
s.Red = 9;
s.Green = 9;
s.Blue = 9;
break;
case TextureInternalFormat::DepthComponent:
case TextureInternalFormat::DepthComponent16:
s.Depth = 16;
break;
case TextureInternalFormat::DepthComponent24:
s.Depth = 24;
break;
case TextureInternalFormat::DepthComponent32:
case TextureInternalFormat::DepthComponent32F:
s.Depth = 32;
break;
case TextureInternalFormat::DepthStencil:
case TextureInternalFormat::Depth24Stencil8:
s.Depth = 24;
s.Stencil = 8;
break;
case TextureInternalFormat::Depth32FStencil8:
s.Depth = 32;
s.Stencil = 8;
break;
default:
MOBILEGL_ASSERT(false, "Unimplemented internal format in GetComponentSizesForInternalFormat: %d",
static_cast<Int>(internal));
break;
}
return s;
}
} // namespace MG_Util
} // namespace MobileGL
@@ -14,5 +14,6 @@ namespace MobileGL {
SizeT GetInputBytesPerPixel(TextureInternalFormat internalformat, TexturePixelDataType type);
SizeT CalculateInputTextureImageSize(TextureInternalFormat internalFormat, TexturePixelDataType pixelDataType,
IntVec3 size);
ComponentSizes GetComponentSizesForInternalFormat(TextureInternalFormat internal);
} // namespace MG_Util
} // namespace MobileGL
+9
View File
@@ -170,6 +170,15 @@ namespace MobileGL {
Range1D m_range;
};
struct ComponentSizes {
Int Red = 0;
Int Green = 0;
Int Blue = 0;
Int Alpha = 0;
Int Depth = 0;
Int Stencil = 0;
};
enum class VersionType {
Release,
Unstable,