[Feat] (MG_Impl/Texture): Decouple texture internal format and input format

This commit is contained in:
2025-12-15 14:16:36 +08:00
parent 02a2f4af4a
commit b220c8baab
7 changed files with 77 additions and 42 deletions
+32 -4
View File
@@ -85,6 +85,34 @@ namespace MobileGL {
}
}
SizeT GetBaseInputFormatComponentCount(TextureInputFormat format) {
switch (format) {
case TextureInputFormat::Red:
case TextureInputFormat::RInteger:
return 1;
case TextureInputFormat::RG:
case TextureInputFormat::RGInteger:
return 2;
case TextureInputFormat::RGB:
case TextureInputFormat::BGR:
case TextureInputFormat::RGBInteger:
case TextureInputFormat::BGRInteger:
return 3;
case TextureInputFormat::RGBA:
case TextureInputFormat::BGRA:
case TextureInputFormat::RGBAInteger:
case TextureInputFormat::BGRAInteger:
return 4;
case TextureInputFormat::StencilIndex:
case TextureInputFormat::DepthComponent:
case TextureInputFormat::DepthStencil:
return 1;
default:
MGLOG_D("%s: Unknown input format!", __func__);
return 0;
}
}
SizeT GetBaseInternalFormatComponentCount(TextureInternalFormat format) {
switch (format) {
case TextureInternalFormat::DepthComponent:
@@ -208,17 +236,17 @@ namespace MobileGL {
return chCount * bytesPerChannel;
}
SizeT GetInputBytesPerPixel(TextureInternalFormat internalformat, TexturePixelDataType type) {
SizeT GetInputBytesPerPixel(TextureInputFormat inputFormat, TexturePixelDataType type) {
SizeT sizedPixelFormatSize = GetSizedTexturePixelDataTypeSize(type);
if (sizedPixelFormatSize > 0) return sizedPixelFormatSize;
SizeT bytesPerChannel = GetBaseTexturePixelDataTypeSize(type);
SizeT chCount = GetBaseInternalFormatComponentCount(internalformat);
SizeT chCount = GetBaseInputFormatComponentCount(inputFormat);
return chCount * bytesPerChannel;
}
SizeT CalculateInputTextureImageSize(TextureInternalFormat internalFormat, TexturePixelDataType pixelDataType,
SizeT CalculateInputTextureImageSize(TextureInputFormat inputFormat, TexturePixelDataType pixelDataType,
IntVec3 size) {
return GetInputBytesPerPixel(internalFormat, pixelDataType) * size.x() * size.y() * size.z();
return GetInputBytesPerPixel(inputFormat, pixelDataType) * size.x() * size.y() * size.z();
}
ComponentSizes GetComponentSizesForInternalFormat(TextureInternalFormat internal) {