Skip to content

Commit 944cb16

Browse files
committed
[Olympus] Allow decoding textures externally
- allow TextureProvider to work directly with cgltf_texture - change ResourceLoader to call TextureProvider with cgltf_texture
1 parent 0192d8e commit 944cb16

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

libs/gltfio/include/gltfio/TextureProvider.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include <utils/compiler.h>
2424

25+
class cgltf_texture;
26+
2527
namespace filament {
2628
class Engine;
2729
class Texture;
@@ -86,7 +88,16 @@ class UTILS_PUBLIC TextureProvider {
8688
* Texture object, but it is only safe to do so after it has been popped from the queue.
8789
*/
8890
virtual Texture* pushTexture(const uint8_t* data, size_t byteCount,
89-
const char* mimeType, FlagBits flags) = 0;
91+
const char* mimeType, FlagBits flags) {
92+
return nullptr;
93+
}
94+
95+
/**
96+
* Alternate version of pushTexture, takes raw cgltf_texture data to allow more control.
97+
*/
98+
virtual Texture* pushTexture(const cgltf_texture* srcTexture, FlagBits flags) {
99+
return nullptr;
100+
}
90101

91102
/**
92103
* Checks if any texture is ready to be removed from the asynchronous decoding queue, and if so

libs/gltfio/src/ResourceLoader.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -616,16 +616,26 @@ void ResourceLoader::asyncUpdateLoad() {
616616

617617
Texture* ResourceLoader::Impl::getOrCreateTexture(FFilamentAsset* asset, const TextureSlot& tb) {
618618
const cgltf_texture* srcTexture = tb.texture;
619-
const cgltf_image* image = srcTexture->basisu_image ?
620-
srcTexture->basisu_image : srcTexture->image;
621-
const cgltf_buffer_view* bv = image->buffer_view;
622-
const char* uri = image->uri;
623-
624619
TextureProvider::FlagBits flags = {};
625620
if (tb.srgb) {
626621
flags |= int(TextureProvider::Flags::sRGB);
627622
}
628623

624+
// Check if there is a texture provider that can work with cgtlf_texture.
625+
if (auto iter = mTextureProviders.find("cgltf_texture"); iter != mTextureProviders.end()) {
626+
TextureProvider* provider = iter->second;
627+
Texture* texture = provider->pushTexture(srcTexture, flags);
628+
if (texture) {
629+
// Note we didn't pass ownership to asset. Caller is responsible for cleaning up.
630+
return texture;
631+
}
632+
}
633+
634+
const cgltf_image* image = srcTexture->basisu_image ?
635+
srcTexture->basisu_image : srcTexture->image;
636+
const cgltf_buffer_view* bv = image->buffer_view;
637+
const char* uri = image->uri;
638+
629639
std::string mime = image->mime_type ? image->mime_type : "";
630640
size_t dataUriSize;
631641
const uint8_t* dataUriContent = uri ? parseDataUri(uri, &mime, &dataUriSize) : nullptr;

0 commit comments

Comments
 (0)