KtxUtility improvements.
This makes it easier for C++ clients to use KTX files and simplifies the JavaScript bindings.
This commit is contained in:
@@ -28,6 +28,7 @@ namespace KtxUtility {
|
||||
using TextureFormat = filament::driver::TextureFormat;
|
||||
using CompressedPixelDataType = filament::driver::CompressedPixelDataType;
|
||||
using PixelDataType = filament::driver::PixelDataType;
|
||||
using PixelDataFormat = filament::driver::PixelDataFormat;
|
||||
|
||||
template<typename T>
|
||||
T toCompressedFilamentEnum(uint32_t format) {
|
||||
@@ -78,12 +79,12 @@ namespace KtxUtility {
|
||||
return (T) 0xffff;
|
||||
}
|
||||
|
||||
CompressedPixelDataType toCompressedPixelDataType(uint32_t format) {
|
||||
return toCompressedFilamentEnum<CompressedPixelDataType>(format);
|
||||
CompressedPixelDataType toCompressedPixelDataType(const KtxInfo& info) {
|
||||
return toCompressedFilamentEnum<CompressedPixelDataType>(info.glInternalFormat);
|
||||
}
|
||||
|
||||
PixelDataType toPixelDataType(uint32_t dtype) {
|
||||
switch (dtype) {
|
||||
PixelDataType toPixelDataType(const KtxInfo& info) {
|
||||
switch (info.glType) {
|
||||
case KtxBundle::UNSIGNED_BYTE: return PixelDataType::UBYTE;
|
||||
case KtxBundle::UNSIGNED_SHORT: return PixelDataType::USHORT;
|
||||
case KtxBundle::HALF_FLOAT: return PixelDataType::HALF;
|
||||
@@ -92,8 +93,22 @@ namespace KtxUtility {
|
||||
return (PixelDataType) 0xff;
|
||||
}
|
||||
|
||||
TextureFormat toTextureFormat(uint32_t format) {
|
||||
switch (format) {
|
||||
PixelDataFormat toPixelDataFormat(const KtxInfo& info, bool rgbm = false) {
|
||||
switch (info.glTypeSize) {
|
||||
case 1: return PixelDataFormat::R;
|
||||
case 2: return PixelDataFormat::RG;
|
||||
case 3: return PixelDataFormat::RGB;
|
||||
case 4: return rgbm ? PixelDataFormat::RGBM : PixelDataFormat::RGBA;
|
||||
}
|
||||
return (PixelDataFormat) 0xff;
|
||||
}
|
||||
|
||||
bool isCompressed(const KtxInfo& info) {
|
||||
return info.glFormat == 0;
|
||||
}
|
||||
|
||||
TextureFormat toTextureFormat(const KtxInfo& info) {
|
||||
switch (info.glInternalFormat) {
|
||||
case KtxBundle::RED: return TextureFormat::R8;
|
||||
case KtxBundle::RG: return TextureFormat::RG8;
|
||||
case KtxBundle::RGB: return TextureFormat::RGB8;
|
||||
@@ -153,7 +168,7 @@ namespace KtxUtility {
|
||||
case KtxBundle::RGBA32UI: return TextureFormat::RGBA32UI;
|
||||
case KtxBundle::RGBA32I: return TextureFormat::RGBA32I;
|
||||
}
|
||||
return toCompressedFilamentEnum<TextureFormat>(format);
|
||||
return toCompressedFilamentEnum<TextureFormat>(info.glInternalFormat);
|
||||
}
|
||||
|
||||
} // namespace KtxUtility
|
||||
|
||||
@@ -787,7 +787,7 @@ class_<KtxBundle>("KtxBundle")
|
||||
/// Returns "undefined" if no valid Filament enumerant exists.
|
||||
.function("getInternalFormat",
|
||||
EMBIND_LAMBDA(Texture::InternalFormat, (KtxBundle* self, bool srgb), {
|
||||
auto result = KtxUtility::toTextureFormat(self->info().glInternalFormat);
|
||||
auto result = KtxUtility::toTextureFormat(self->info());
|
||||
if (srgb) {
|
||||
if (result == Texture::InternalFormat::RGB8) {
|
||||
result = Texture::InternalFormat::SRGB8;
|
||||
@@ -805,14 +805,7 @@ class_<KtxBundle>("KtxBundle")
|
||||
/// Returns "undefined" if no valid Filament enumerant exists.
|
||||
.function("getPixelDataFormat",
|
||||
EMBIND_LAMBDA(driver::PixelDataFormat, (KtxBundle* self, bool rgbm), {
|
||||
switch (self->info().glTypeSize) {
|
||||
case 1: return driver::PixelDataFormat::R;
|
||||
case 2: return driver::PixelDataFormat::RG;
|
||||
case 3: return driver::PixelDataFormat::RGB;
|
||||
case 4: return rgbm ? driver::PixelDataFormat::RGBA : driver::PixelDataFormat::RGBM;
|
||||
}
|
||||
assert(false && "Unknown pixel data format.");
|
||||
return (driver::PixelDataFormat) 0xff;
|
||||
return KtxUtility::toPixelDataFormat(self->getInfo());
|
||||
}), allow_raw_pointers())
|
||||
|
||||
/// getPixelDataType ::method::
|
||||
@@ -820,7 +813,7 @@ class_<KtxBundle>("KtxBundle")
|
||||
/// Returns "undefined" if no valid Filament enumerant exists.
|
||||
.function("getPixelDataType",
|
||||
EMBIND_LAMBDA(driver::PixelDataType, (KtxBundle* self), {
|
||||
return KtxUtility::toPixelDataType(self->info().glType);
|
||||
return KtxUtility::toPixelDataType(self->getInfo());
|
||||
}), allow_raw_pointers())
|
||||
|
||||
/// getCompressedPixelDataType ::method::
|
||||
@@ -828,14 +821,14 @@ class_<KtxBundle>("KtxBundle")
|
||||
/// Returns "undefined" if no valid Filament enumerant exists.
|
||||
.function("getCompressedPixelDataType",
|
||||
EMBIND_LAMBDA(driver::CompressedPixelDataType, (KtxBundle* self), {
|
||||
return KtxUtility::toCompressedPixelDataType(self->info().glInternalFormat);
|
||||
return KtxUtility::toCompressedPixelDataType(self->getInfo());
|
||||
}), allow_raw_pointers())
|
||||
|
||||
/// isCompressed ::method::
|
||||
/// Per spec, compressed textures in KTX always have their glFormat field set to 0.
|
||||
/// ::retval:: boolean
|
||||
.function("isCompressed", EMBIND_LAMBDA(bool, (KtxBundle* self), {
|
||||
return self->info().glFormat == 0;
|
||||
return KtxUtility::isCompressed(self->getInfo());
|
||||
}), allow_raw_pointers())
|
||||
|
||||
.function("isCubemap", &KtxBundle::isCubemap)
|
||||
|
||||
Reference in New Issue
Block a user