mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-13 22:58:30 +09:00
[Chore] (MG_Impl/Texture): convert base internal format to sized ones (on a best-effort basis)
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
// End of Source File Header
|
||||
|
||||
#include "TextureEnumConverter.h"
|
||||
#include "MG_Util/Converters/MGToStr/TextureEnumConverter.h"
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_Util {
|
||||
@@ -50,5 +51,145 @@ namespace MobileGL {
|
||||
return TextureTarget::Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
TextureInternalFormat ConvertInternalFormatToSized(TextureInternalFormat internalformat, TextureInputFormat format, TexturePixelDataType type) {
|
||||
switch (internalformat) {
|
||||
case TextureInternalFormat::R8:
|
||||
case TextureInternalFormat::R8Snorm:
|
||||
case TextureInternalFormat::R16:
|
||||
case TextureInternalFormat::R16Snorm:
|
||||
case TextureInternalFormat::RG8:
|
||||
case TextureInternalFormat::RG8Snorm:
|
||||
case TextureInternalFormat::RG16:
|
||||
case TextureInternalFormat::RG16Snorm:
|
||||
case TextureInternalFormat::R3G3B2:
|
||||
case TextureInternalFormat::RGB4:
|
||||
case TextureInternalFormat::RGB5:
|
||||
case TextureInternalFormat::RGB8:
|
||||
case TextureInternalFormat::RGB8Snorm:
|
||||
case TextureInternalFormat::RGB10:
|
||||
case TextureInternalFormat::RGB12:
|
||||
case TextureInternalFormat::RGB16Snorm:
|
||||
case TextureInternalFormat::RGBA2:
|
||||
case TextureInternalFormat::RGBA4:
|
||||
case TextureInternalFormat::RGB5A1:
|
||||
case TextureInternalFormat::RGBA8:
|
||||
case TextureInternalFormat::RGBA8Snorm:
|
||||
case TextureInternalFormat::RGB10A2:
|
||||
case TextureInternalFormat::RGB10A2UI:
|
||||
case TextureInternalFormat::RGBA12:
|
||||
case TextureInternalFormat::RGBA16:
|
||||
case TextureInternalFormat::SRGB8:
|
||||
case TextureInternalFormat::SRGB8Alpha8:
|
||||
case TextureInternalFormat::R16F:
|
||||
case TextureInternalFormat::RG16F:
|
||||
case TextureInternalFormat::RGB16F:
|
||||
case TextureInternalFormat::RGBA16F:
|
||||
case TextureInternalFormat::R32F:
|
||||
case TextureInternalFormat::RG32F:
|
||||
case TextureInternalFormat::RGB32F:
|
||||
case TextureInternalFormat::RGBA32F:
|
||||
case TextureInternalFormat::R11FG11FB10F:
|
||||
case TextureInternalFormat::RGB9E5:
|
||||
case TextureInternalFormat::R8I:
|
||||
case TextureInternalFormat::R8UI:
|
||||
case TextureInternalFormat::R16I:
|
||||
case TextureInternalFormat::R16UI:
|
||||
case TextureInternalFormat::R32I:
|
||||
case TextureInternalFormat::R32UI:
|
||||
case TextureInternalFormat::RG8I:
|
||||
case TextureInternalFormat::RG8UI:
|
||||
case TextureInternalFormat::RG16I:
|
||||
case TextureInternalFormat::RG16UI:
|
||||
case TextureInternalFormat::RG32I:
|
||||
case TextureInternalFormat::RG32UI:
|
||||
case TextureInternalFormat::RGB8I:
|
||||
case TextureInternalFormat::RGB8UI:
|
||||
case TextureInternalFormat::RGB16I:
|
||||
case TextureInternalFormat::RGB16UI:
|
||||
case TextureInternalFormat::RGB32I:
|
||||
case TextureInternalFormat::RGB32UI:
|
||||
case TextureInternalFormat::RGBA8I:
|
||||
case TextureInternalFormat::RGBA8UI:
|
||||
case TextureInternalFormat::RGBA16I:
|
||||
case TextureInternalFormat::RGBA16UI:
|
||||
case TextureInternalFormat::RGBA32I:
|
||||
case TextureInternalFormat::RGBA32UI:
|
||||
case TextureInternalFormat::DepthComponent16:
|
||||
case TextureInternalFormat::DepthComponent24:
|
||||
case TextureInternalFormat::DepthComponent32: // not a standard format in OpenGL core profile
|
||||
case TextureInternalFormat::DepthComponent32F:
|
||||
case TextureInternalFormat::Depth24Stencil8:
|
||||
case TextureInternalFormat::Depth32FStencil8:
|
||||
return internalformat;
|
||||
// probably we should assume unorm here?
|
||||
case TextureInternalFormat::RGBA: {
|
||||
switch (type) {
|
||||
case TexturePixelDataType::UnsignedByte:
|
||||
return TextureInternalFormat::RGBA8;
|
||||
case TexturePixelDataType::UnsignedShort:
|
||||
return TextureInternalFormat::RGBA16;
|
||||
default:
|
||||
MGLOG_W("%s: Can't infer sized internal format from internalformat=%s, format=%s, type=%s, returning original.",
|
||||
__func__,
|
||||
MG_Util::ConvertTextureInternalFormatToString(internalformat).c_str(),
|
||||
MG_Util::ConvertTextureInputFormatToString(format).c_str(),
|
||||
MG_Util::ConvertTexturePixelDataTypeToString(type).c_str());
|
||||
return internalformat;
|
||||
}
|
||||
}
|
||||
case TextureInternalFormat::RGB: {
|
||||
switch (type) {
|
||||
case TexturePixelDataType::UnsignedByte:
|
||||
return TextureInternalFormat::RGB8;
|
||||
default:
|
||||
MGLOG_W("%s: Can't infer sized internal format from internalformat=%s, format=%s, type=%s, returning original.",
|
||||
__func__,
|
||||
MG_Util::ConvertTextureInternalFormatToString(internalformat).c_str(),
|
||||
MG_Util::ConvertTextureInputFormatToString(format).c_str(),
|
||||
MG_Util::ConvertTexturePixelDataTypeToString(type).c_str());
|
||||
return internalformat;
|
||||
}
|
||||
}
|
||||
case TextureInternalFormat::RG: {
|
||||
switch (type) {
|
||||
case TexturePixelDataType::UnsignedByte:
|
||||
return TextureInternalFormat::RG8;
|
||||
case TexturePixelDataType::UnsignedShort:
|
||||
return TextureInternalFormat::RG16;
|
||||
default:
|
||||
MGLOG_W("%s: Can't infer sized internal format from internalformat=%s, format=%s, type=%s, returning original.",
|
||||
__func__,
|
||||
MG_Util::ConvertTextureInternalFormatToString(internalformat).c_str(),
|
||||
MG_Util::ConvertTextureInputFormatToString(format).c_str(),
|
||||
MG_Util::ConvertTexturePixelDataTypeToString(type).c_str());
|
||||
return internalformat;
|
||||
}
|
||||
}
|
||||
case TextureInternalFormat::Red: {
|
||||
switch (type) {
|
||||
case TexturePixelDataType::UnsignedByte:
|
||||
return TextureInternalFormat::R8;
|
||||
case TexturePixelDataType::UnsignedShort:
|
||||
return TextureInternalFormat::R16;
|
||||
default:
|
||||
MGLOG_W("%s: Can't infer sized internal format from internalformat=%s, format=%s, type=%s, returning original.",
|
||||
__func__,
|
||||
MG_Util::ConvertTextureInternalFormatToString(internalformat).c_str(),
|
||||
MG_Util::ConvertTextureInputFormatToString(format).c_str(),
|
||||
MG_Util::ConvertTexturePixelDataTypeToString(type).c_str());
|
||||
return internalformat;
|
||||
}
|
||||
}
|
||||
default: {
|
||||
MGLOG_W("%s: Can't infer sized internal format from internalformat=%s, format=%s, type=%s, returning original.",
|
||||
__func__,
|
||||
MG_Util::ConvertTextureInternalFormatToString(internalformat).c_str(),
|
||||
MG_Util::ConvertTextureInputFormatToString(format).c_str(),
|
||||
MG_Util::ConvertTexturePixelDataTypeToString(type).c_str());
|
||||
return internalformat;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace MG_Util
|
||||
} // namespace MobileGL
|
||||
@@ -12,5 +12,6 @@
|
||||
namespace MobileGL {
|
||||
namespace MG_Util {
|
||||
TextureTarget ConvertTextureUploadTargetToTextureTarget(TextureUploadTarget target);
|
||||
TextureInternalFormat ConvertInternalFormatToSized(TextureInternalFormat internalformat, TextureInputFormat format, TexturePixelDataType type);
|
||||
} // namespace MG_Util
|
||||
} // namespace MobileGL
|
||||
Reference in New Issue
Block a user