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 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 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 f897668..ad54543 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -470,8 +470,16 @@ struct Image { // "image/bmp", "image/gif"] std::string uri; // (required if no mimeType) Value extras; + ExtensionMap extensions; - Image() { bufferView = -1; width = -1; height = -1; component = -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; width = -1; height = -1; component = -1; } bool operator==(const Image&) const; }; @@ -994,7 +1002,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" @@ -1006,6 +1013,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 @@ -1654,14 +1664,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) { @@ -1700,9 +1715,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); @@ -2459,6 +2474,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; @@ -4348,6 +4364,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) {