From 18ef338ff5a1875e0bdbc2550a8c9460d3c2e4bc Mon Sep 17 00:00:00 2001 From: Victor Bushong Date: Wed, 22 Aug 2018 22:03:30 -0500 Subject: [PATCH 1/6] Force default image loader to use 32-bit images for Vulkan compatibility. --- tiny_gltf.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index 3d18c48..b12827b 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -1314,14 +1314,19 @@ bool LoadImageData(Image *image, std::string *err, std::string *warn, int size, void *) { (void)warn; - int w, h, comp; + int w, h, comp, req_comp; + + // force 32-bit textures for common Vulkan compatibility. It appears that + // some GPU drivers do not support 24-bit images for Vulkan + req_comp = 4; + // if image cannot be decoded, ignore parsing and keep it by its path // don't break in this case // FIXME we should only enter this function if the image is embedded. If // image->uri references // an image file, it should be left as it is. Image loading should not be // mandatory (to support other formats) - unsigned char *data = stbi_load_from_memory(bytes, size, &w, &h, &comp, 0); + unsigned char *data = stbi_load_from_memory(bytes, size, &w, &h, &comp, req_comp); if (!data) { // NOTE: you can use `warn` instead of `err` if (err) { @@ -1360,9 +1365,9 @@ bool LoadImageData(Image *image, std::string *err, std::string *warn, image->width = w; image->height = h; - image->component = comp; - image->image.resize(static_cast(w * h * comp)); - std::copy(data, data + w * h * comp, image->image.begin()); + image->component = req_comp; + image->image.resize(static_cast(w * h * req_comp)); + std::copy(data, data + w * h * req_comp, image->image.begin()); free(data); From a8f0b1c3833603ba14f9ed9f0ae248882d38e868 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Tue, 28 Aug 2018 21:33:40 +0900 Subject: [PATCH 2/6] Suppress unknown pragma warning on clang 3.7 --- tiny_gltf.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index e253fce..05624a9 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -954,7 +954,6 @@ class TinyGLTF { #pragma clang diagnostic ignored "-Wexit-time-destructors" #pragma clang diagnostic ignored "-Wconversion" #pragma clang diagnostic ignored "-Wold-style-cast" -#pragma clang diagnostic ignored "-Wdouble-promotion" #pragma clang diagnostic ignored "-Wglobal-constructors" #pragma clang diagnostic ignored "-Wreserved-id-macro" #pragma clang diagnostic ignored "-Wdisabled-macro-expansion" @@ -966,6 +965,9 @@ class TinyGLTF { #pragma clang diagnostic ignored "-Wimplicit-fallthrough" #pragma clang diagnostic ignored "-Wweak-vtables" #pragma clang diagnostic ignored "-Wcovered-switch-default" +#if __has_warning("-Wdouble-promotion") +#pragma clang diagnostic ignored "-Wdouble-promotion" +#endif #if __has_warning("-Wcomma") #pragma clang diagnostic ignored "-Wcomma" #endif From 9ec710908963ae05f83d619908365e882efa9ccf Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Thu, 30 Aug 2018 21:27:11 +0900 Subject: [PATCH 3/6] Bump clang version from 3.7 to 3.9 since clang-3.7 apt source is untrusted. --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6e731e5..37779f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,15 +7,15 @@ matrix: sources: - george-edison55-precise-backports - ubuntu-toolchain-r-test - - llvm-toolchain-precise-3.7 + - llvm-toolchain-trusty-3.9 packages: - g++-4.9 - - clang-3.7 + - clang-3.9 compiler: clang - env: COMPILER_VERSION=3.7 BUILD_TYPE=Debug + env: COMPILER_VERSION=3.9 BUILD_TYPE=Debug - addons: *1 compiler: clang - env: COMPILER_VERSION=3.7 BUILD_TYPE=Release + env: COMPILER_VERSION=3.9 BUILD_TYPE=Release - addons: &2 apt: sources: @@ -30,7 +30,7 @@ matrix: env: COMPILER_VERSION=4.9 BUILD_TYPE=Release EXTRA_CXXFLAGS="-fsanitize=address" - addons: *1 compiler: clang - env: COMPILER_VERSION=3.7 BUILD_TYPE=Debug CFLAGS="-O0" CXXFLAGS="-O0" + env: COMPILER_VERSION=3.9 BUILD_TYPE=Debug CFLAGS="-O0" CXXFLAGS="-O0" before_install: - ./.travis-before-install.sh From 3e53feb04642aab9a58fce32ef8e2417f8ed608f Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Sun, 2 Sep 2018 15:36:17 +0900 Subject: [PATCH 4/6] Parse `extensions` property of Image. --- loader_example.cc | 5 +++++ tiny_gltf.h | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/loader_example.cc b/loader_example.cc index 8ae20bc..7f8a426 100644 --- a/loader_example.cc +++ b/loader_example.cc @@ -1,3 +1,6 @@ +// +// TODO(syoyo): Print extensions and extras for each glTF object. +// #define TINYGLTF_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_WRITE_IMPLEMENTATION @@ -514,6 +517,7 @@ static void Dump(const tinygltf::Model &model) { std::cout << Indent(2) << "width : " << image.width << std::endl; std::cout << Indent(2) << "height : " << image.height << std::endl; std::cout << Indent(2) << "component : " << image.component << std::endl; + DumpExtensions(image.extensions, 1); } } @@ -525,6 +529,7 @@ static void Dump(const tinygltf::Model &model) { << std::endl; std::cout << Indent(1) << "source : " << texture.source << std::endl; + DumpExtensions(texture.extensions, 1); } } diff --git a/tiny_gltf.h b/tiny_gltf.h index 9b6494d..6f2855c 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -456,6 +456,7 @@ struct Image { // "image/bmp", "image/gif"] std::string uri; // (required if no mimeType) Value extras; + ExtensionMap extensions; Image() { bufferView = -1; } }; @@ -2126,6 +2127,7 @@ static bool ParseImage(Image *image, std::string *err, std::string *warn, } ParseStringProperty(&image->name, err, o, "name", false); + ParseExtensionsProperty(&image->extensions, err, o); if (hasBufferView) { double bufferView = -1; @@ -4014,6 +4016,8 @@ static void SerializeGltfImage(Image &image, json &o) { if (image.extras.Type() != NULL_TYPE) { SerializeValue("extras", image.extras, o); } + + SerializeExtensionMap(image.extensions, o); } static void SerializeGltfMaterial(Material &material, json &o) { From e66d8c992fa406e8086fb23192e1915630d9dd08 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Sun, 2 Sep 2018 16:58:43 +0900 Subject: [PATCH 5/6] Add as-is flag to Image. Tentative solution for issue #82 --- tiny_gltf.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index 6f2855c..05d7097 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -458,7 +458,14 @@ struct Image { Value extras; ExtensionMap extensions; - Image() { bufferView = -1; } + // When this flag is true, data is stored to `image` in as-is format(e.g. jpeg compressed for "image/jpeg" mime) + // This feature is good if you use custom image loader function. + // (e.g. delayed decoding of images for faster glTF parsing) + // Default parser for Image does not provide as-is loading feature at the moment. + // (You can manipulate this by providing your own LoadImageData function) + bool as_is; + + Image() : as_is(false) { bufferView = -1; } }; struct Texture { From e59dd6a5c0fc982b82f3f376e13068c4cedd904a Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Tue, 25 Sep 2018 03:03:49 +0900 Subject: [PATCH 6/6] Update TODOs. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5b357aa..4e68225 100644 --- a/README.md +++ b/README.md @@ -57,13 +57,13 @@ v2.0.0 release(22 Aug, 2018)! ## TODOs -* [ ] Write C++ code generator from jSON schema for robust parsing. -* [x] Serialization -* [ ] Compression/decompression(Open3DGC, etc) +* [ ] Write C++ code generator which emits C++ code from JSON schema for robust parsing. +* [ ] Mesh Compression/decompression(Open3DGC, etc) + * [ ] Load Draco compressed mesh * [ ] Support `extensions` and `extras` property * [ ] HDR image? * [ ] OpenEXR extension through TinyEXR. -* [ ] Write tests for `animation` and `skin` +* [ ] Write exampple and tests for `animation` and `skin` ## Licenses