[Feat|Fix] (MG_Impl/Texture): Implement TexImage2D & related stuff.

This commit is contained in:
BZLZHH
2025-08-14 18:32:37 +08:00
parent f713a3785b
commit 675ee4915b
16 changed files with 744 additions and 263 deletions
+101 -57
View File
@@ -1,85 +1,129 @@
#include "TextureMetrics.h"
#include "MG_Util/Math/VectorTypes.h"
namespace MobileGL {
namespace MG_Util {
SizeT GetTexturePixelSize(TextureSizedInternalFormat internal) {
SizeT GetTexturePixelSize(TextureInternalFormat internal) {
switch (internal) {
case TextureSizedInternalFormat::R8:
case TextureSizedInternalFormat::R8Snorm:
case TextureSizedInternalFormat::R8I:
case TextureSizedInternalFormat::R8UI:
case TextureInternalFormat::R8:
case TextureInternalFormat::R8Snorm:
case TextureInternalFormat::R8I:
case TextureInternalFormat::R8UI:
return 1;
case TextureSizedInternalFormat::R16:
case TextureSizedInternalFormat::R16Snorm:
case TextureSizedInternalFormat::R16I:
case TextureSizedInternalFormat::R16UI:
case TextureSizedInternalFormat::R16F:
case TextureSizedInternalFormat::RG8:
case TextureSizedInternalFormat::RG8Snorm:
case TextureSizedInternalFormat::RG8I:
case TextureSizedInternalFormat::RG8UI:
case TextureInternalFormat::R16:
case TextureInternalFormat::R16Snorm:
case TextureInternalFormat::R16I:
case TextureInternalFormat::R16UI:
case TextureInternalFormat::R16F:
case TextureInternalFormat::RG8:
case TextureInternalFormat::RG8Snorm:
case TextureInternalFormat::RG8I:
case TextureInternalFormat::RG8UI:
return 2;
case TextureSizedInternalFormat::R3G3B2:
case TextureSizedInternalFormat::RGB4:
case TextureSizedInternalFormat::RGB5:
case TextureSizedInternalFormat::RGB8:
case TextureSizedInternalFormat::RGB8Snorm:
case TextureSizedInternalFormat::SRGB8:
case TextureSizedInternalFormat::RGB8I:
case TextureSizedInternalFormat::RGB8UI:
case TextureInternalFormat::R3G3B2:
case TextureInternalFormat::RGB4:
case TextureInternalFormat::RGB5:
case TextureInternalFormat::RGB8:
case TextureInternalFormat::RGB8Snorm:
case TextureInternalFormat::SRGB8:
case TextureInternalFormat::RGB8I:
case TextureInternalFormat::RGB8UI:
return 3;
case TextureSizedInternalFormat::RGBA2:
case TextureSizedInternalFormat::RGBA4:
case TextureSizedInternalFormat::RGB5A1:
case TextureSizedInternalFormat::RGBA8:
case TextureSizedInternalFormat::RGBA8Snorm:
case TextureSizedInternalFormat::RGBA8I:
case TextureSizedInternalFormat::RGBA8UI:
case TextureSizedInternalFormat::SRGB8Alpha8:
case TextureSizedInternalFormat::RGB10A2:
case TextureSizedInternalFormat::RGB10A2UI:
case TextureSizedInternalFormat::R32F:
case TextureInternalFormat::RGBA2:
case TextureInternalFormat::RGBA4:
case TextureInternalFormat::RGB5A1:
case TextureInternalFormat::RGBA8:
case TextureInternalFormat::RGBA8Snorm:
case TextureInternalFormat::RGBA8I:
case TextureInternalFormat::RGBA8UI:
case TextureInternalFormat::SRGB8Alpha8:
case TextureInternalFormat::RGB10A2:
case TextureInternalFormat::RGB10A2UI:
case TextureInternalFormat::R32F:
case TextureSizedInternalFormat::RG16:
case TextureSizedInternalFormat::RG16Snorm:
case TextureSizedInternalFormat::RG16I:
case TextureSizedInternalFormat::RG16UI:
case TextureSizedInternalFormat::RG16F:
case TextureInternalFormat::RG16:
case TextureInternalFormat::RG16Snorm:
case TextureInternalFormat::RG16I:
case TextureInternalFormat::RG16UI:
case TextureInternalFormat::RG16F:
return 4;
case TextureSizedInternalFormat::RGBA12:
case TextureSizedInternalFormat::RGBA16:
case TextureSizedInternalFormat::RGBA16I:
case TextureSizedInternalFormat::RGBA16UI:
case TextureSizedInternalFormat::RGBA16F:
case TextureSizedInternalFormat::RG32F:
case TextureSizedInternalFormat::RG32I:
case TextureSizedInternalFormat::RG32UI:
case TextureInternalFormat::RGBA12:
case TextureInternalFormat::RGBA16:
case TextureInternalFormat::RGBA16I:
case TextureInternalFormat::RGBA16UI:
case TextureInternalFormat::RGBA16F:
case TextureInternalFormat::RG32F:
case TextureInternalFormat::RG32I:
case TextureInternalFormat::RG32UI:
return 8;
case TextureSizedInternalFormat::RGB16F:
case TextureSizedInternalFormat::RGB32F:
case TextureSizedInternalFormat::RGB16I:
case TextureSizedInternalFormat::RGB16UI:
case TextureSizedInternalFormat::RGB32I:
case TextureSizedInternalFormat::RGB32UI:
case TextureInternalFormat::RGB16F:
case TextureInternalFormat::RGB32F:
case TextureInternalFormat::RGB16I:
case TextureInternalFormat::RGB16UI:
case TextureInternalFormat::RGB32I:
case TextureInternalFormat::RGB32UI:
return 12;
case TextureSizedInternalFormat::RGBA32F:
case TextureSizedInternalFormat::RGBA32I:
case TextureSizedInternalFormat::RGBA32UI:
case TextureInternalFormat::RGBA32F:
case TextureInternalFormat::RGBA32I:
case TextureInternalFormat::RGBA32UI:
return 16;
case TextureSizedInternalFormat::R11FG11FB10F:
case TextureSizedInternalFormat::RGB9E5:
case TextureInternalFormat::R11FG11FB10F:
case TextureInternalFormat::RGB9E5:
return 4;
default:
return 0;
}
}
SizeT GetTexturePixelDataTypeSize(TexturePixelDataType type) {
switch (type) {
case TexturePixelDataType::UnsignedByte:
case TexturePixelDataType::Byte:
case TexturePixelDataType::UnsignedByte332:
case TexturePixelDataType::UnsignedByte233Rev:
return 1;
case TexturePixelDataType::UnsignedShort:
case TexturePixelDataType::Short:
case TexturePixelDataType::UnsignedShort565:
case TexturePixelDataType::UnsignedShort565Rev:
case TexturePixelDataType::UnsignedShort4444:
case TexturePixelDataType::UnsignedShort4444Rev:
case TexturePixelDataType::UnsignedShort5551:
case TexturePixelDataType::UnsignedShort1555Rev:
return 2;
case TexturePixelDataType::UnsignedInt:
case TexturePixelDataType::Int:
case TexturePixelDataType::Float:
case TexturePixelDataType::UnsignedInt8888:
case TexturePixelDataType::UnsignedInt8888Rev:
case TexturePixelDataType::UnsignedInt1010102:
case TexturePixelDataType::UnsignedInt2101010Rev:
case TexturePixelDataType::UnsignedInt101111Rev:
case TexturePixelDataType::UnsignedInt5999Rev:
return 4;
default:
return 0;
}
}
SizeT CalculateTextureImageSize(TextureInternalFormat internalFormat, TexturePixelDataType pixelDataType,
IntVec3 size) {
SizeT pixelSize = GetTexturePixelSize(internalFormat);
if (pixelSize == 0) return 0;
SizeT dataTypeSize = GetTexturePixelDataTypeSize(pixelDataType);
if (dataTypeSize == 0) return 0;
return pixelSize * dataTypeSize * size.x() * size.y() * size.z();
}
} // namespace MG_Util
} // namespace MobileGL