From 9533c352a1352d17a1eac72e699c70d1c28e6ef5 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Thu, 31 Oct 2019 01:02:43 +0900 Subject: [PATCH 1/7] Add gcc-4.8 build on Travis. --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.travis.yml b/.travis.yml index 87e777a..38a6584 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,17 @@ matrix: - addons: *1 compiler: clang env: COMPILER_VERSION=3.9 BUILD_TYPE=Debug CFLAGS="-O0" CXXFLAGS="-O0" + - addons: &3 + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 + compiler: gcc + env: COMPILER_VERSION=4.8 BUILD_TYPE=Debug + - addons: *1 + compiler: gcc + env: COMPILER_VERSION=4.8 BUILD_TYPE=Release before_install: - ./.travis-before-install.sh From 30f333c607ed025b64c879dde8ebe322cf519789 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Thu, 31 Oct 2019 02:17:22 +0900 Subject: [PATCH 2/7] Fix travis script. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 38a6584..70f7679 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ matrix: - g++-4.8 compiler: gcc env: COMPILER_VERSION=4.8 BUILD_TYPE=Debug - - addons: *1 + - addons: *3 compiler: gcc env: COMPILER_VERSION=4.8 BUILD_TYPE=Release From 58ab95be2f9a645c2d4c98474b03fa3da4bc1bc4 Mon Sep 17 00:00:00 2001 From: Selmar Kok Date: Thu, 31 Oct 2019 15:08:03 +0100 Subject: [PATCH 3/7] only serialize doublesided if it is not the default value --- tiny_gltf.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index d09d83b..06f77f1 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -6002,7 +6002,8 @@ static void SerializeGltfMaterial(Material &material, json &o) { SerializeStringProperty("alphaMode", material.alphaMode, o); } - JsonAddMember(o, "doubleSided", json(material.doubleSided)); + if(material.doubleSided != false) + JsonAddMember(o, "doubleSided", json(material.doubleSided)); if (material.normalTexture.index > -1) { json texinfo; From a9d86c1af4e5a75a18eb69c60a11e99767614582 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Fri, 8 Nov 2019 14:45:16 +0900 Subject: [PATCH 4/7] Add URL of Vulkan-Samples. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a4c33c..7b32797 100644 --- a/README.md +++ b/README.md @@ -75,9 +75,10 @@ In extension(`ExtensionMap`), JSON number value is parsed as int or float(number * GLTF loader plugin for OGRE 2.1. Support for PBR materials via HLMS/PBS https://github.com/Ybalrid/Ogre_glTF * [TinyGltfImporter](http://doc.magnum.graphics/magnum/classMagnum_1_1Trade_1_1TinyGltfImporter.html) plugin for [Magnum](https://github.com/mosra/magnum), a lightweight and modular C++11/C++14 graphics middleware for games and data visualization. * [Diligent Engine](https://github.com/DiligentGraphics/DiligentEngine) - A modern cross-platform low-level graphics library and rendering framework -* Lighthouse 2: a rendering framework for real-time ray tracing / path tracing experiments. https://github.com/jbikker/lighthouse2 +* Lighthouse 2: a rendering framework for real-time ray tracing / path tracing experiments. https://github.com/jbikker/lighthouse2 * [QuickLook GLTF](https://github.com/toshiks/glTF-quicklook) - quicklook plugin for macos. Also SceneKit wrapper for tinygltf. * [GlslViewer](https://github.com/patriciogonzalezvivo/glslViewer) - live GLSL coding for MacOS and Linux +* [Vulkan-Samples](https://github.com/KhronosGroup/Vulkan-Samples) - The Vulkan Samples is collection of resources to help you develop optimized Vulkan applications. * Your projects here! (Please send PR) ## TODOs From 45cac787091451e7471c0fbcb21c261cec2fed30 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Sat, 9 Nov 2019 20:42:55 +0900 Subject: [PATCH 5/7] Fix utf8 filepath on MinGW based on PR 222. --- tiny_gltf.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 67 insertions(+), 7 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index 36b10d1..d327b1b 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -1541,6 +1541,13 @@ class TinyGLTF { #undef NOMINMAX #endif +#if defined(__GLIBCXX__) // mingw + +#include // fstream (all sorts of IO stuff) + stdio_filebuf (=streambuf) +#include // _O_RDONLY + +#endif + #elif !defined(__ANDROID__) #include #endif @@ -2392,13 +2399,26 @@ bool FileExists(const std::string &abs_filename, void *) { } #else #ifdef _WIN32 - FILE *fp; +#if defined(_MSC_VER) || defined(__GLIBCXX__) + FILE *fp = nullptr; errno_t err = _wfopen_s(&fp, UTF8ToWchar(abs_filename).c_str(), L"rb"); if (err != 0) { return false; } #else - FILE *fp = fopen(abs_filename.c_str(), "rb"); + FILE *fp = nullptr; + errno_t err = fopen_s(&fp, abs_filename.c_str(), "rb"); + if (err != 0) { + return false; + } +#endif + +#else + FILE *fp = nullptr; + errno_t err = fopen_s(&fp, abs_filename.c_str(), "rb"); + if (err != 0) { + return false; + } #endif if (fp) { ret = true; @@ -2489,7 +2509,15 @@ bool ReadWholeFile(std::vector *out, std::string *err, } #else #ifdef _WIN32 +#if defined(__GLIBCXX__) // mingw + int file_descriptor = _wopen(UTF8ToWchar(filepath).c_str(), _O_RDONLY | _O_BINARY); + __gnu_cxx::stdio_filebuf wfile_buf(file_descriptor, std::ios_base::in); + std::istream f(&wfile_buf); +#elif defined(_MSC_VER) std::ifstream f(UTF8ToWchar(filepath).c_str(), std::ifstream::binary); +#else // clang? + std::ifstream f(filepath.c_str(), std::ifstream::binary); +#endif #else std::ifstream f(filepath.c_str(), std::ifstream::binary); #endif @@ -2520,7 +2548,6 @@ bool ReadWholeFile(std::vector *out, std::string *err, out->resize(sz); f.read(reinterpret_cast(&out->at(0)), static_cast(sz)); - f.close(); return true; #endif @@ -2529,7 +2556,15 @@ bool ReadWholeFile(std::vector *out, std::string *err, bool WriteWholeFile(std::string *err, const std::string &filepath, const std::vector &contents, void *) { #ifdef _WIN32 +#if defined(__GLIBCXX__) // mingw + int file_descriptor = _wopen(UTF8ToWchar(filepath).c_str(), _O_WRONLY | _O_BINARY); + __gnu_cxx::stdio_filebuf wfile_buf(file_descriptor, std::ios_base::in); + std::ostream f(&wfile_buf); +#elif defined(_MSC_VER) std::ofstream f(UTF8ToWchar(filepath).c_str(), std::ofstream::binary); +#else // clang? + std::ofstream f(filepath.c_str(), std::ofstream::binary); +#endif #else std::ofstream f(filepath.c_str(), std::ofstream::binary); #endif @@ -2549,7 +2584,6 @@ bool WriteWholeFile(std::string *err, const std::string &filepath, return false; } - f.close(); return true; } @@ -6250,14 +6284,24 @@ static void SerializeGltfBufferData(const std::vector &data, static bool SerializeGltfBufferData(const std::vector &data, const std::string &binFilename) { #ifdef _WIN32 +#if defined(__GLIBCXX__) // mingw + int file_descriptor = _wopen(UTF8ToWchar(binFilename).c_str(), _O_WRONLY | _O_BINARY); + __gnu_cxx::stdio_filebuf wfile_buf(file_descriptor, std::ios_base::in); + std::ostream output(&wfile_buf); + if (!wfile_buf.is_open()) return false; +#elif defined(_MSC_VER) std::ofstream output(UTF8ToWchar(binFilename).c_str(), std::ofstream::binary); + if (!output.is_open()) return false; #else std::ofstream output(binFilename.c_str(), std::ofstream::binary); -#endif if (!output.is_open()) return false; +#endif +#else + std::ofstream output(binFilename.c_str(), std::ofstream::binary); + if (!output.is_open()) return false; +#endif output.write(reinterpret_cast(&data[0]), std::streamsize(data.size())); - output.close(); return true; } @@ -7113,11 +7157,21 @@ static bool WriteGltfStream(std::ostream &stream, const std::string &content) { static bool WriteGltfFile(const std::string &output, const std::string &content) { #ifdef _WIN32 +#if defined(_MSC_VER) std::ofstream gltfFile(UTF8ToWchar(output).c_str()); +#elif defined(__GLIBCXX__) + int file_descriptor = _wopen(UTF8ToWchar(output).c_str(), _O_WRONLY | _O_BINARY); + __gnu_cxx::stdio_filebuf wfile_buf(file_descriptor, std::ios_base::in); + std::ostream gltfFile(&wfile_buf); + if (!wfile_buf.is_open()) return false; #else std::ofstream gltfFile(output.c_str()); -#endif if (!gltfFile.is_open()) return false; +#endif +#else + std::ofstream gltfFile(output.c_str()); + if (!gltfFile.is_open()) return false; +#endif return WriteGltfStream(gltfFile, content); } @@ -7154,7 +7208,13 @@ static void WriteBinaryGltfStream(std::ostream &stream, static void WriteBinaryGltfFile(const std::string &output, const std::string &content) { #ifdef _WIN32 +#if defined(_MSC_VER) std::ofstream gltfFile(UTF8ToWchar(output).c_str(), std::ios::binary); +#elif defined(__GLIBCXX__) + std::ofstream gltfFile(output.c_str(), std::ios::binary); +#else + std::ofstream gltfFile(output.c_str(), std::ios::binary); +#endif #else std::ofstream gltfFile(output.c_str(), std::ios::binary); #endif From 125d8e50a967f8b2958b491f9d51b09f52ed0de9 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Sat, 9 Nov 2019 20:52:56 +0900 Subject: [PATCH 6/7] fopen_s -> fopen in linux(posix) code path. --- tiny_gltf.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index d327b1b..e84725a 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -1415,6 +1415,7 @@ class TinyGLTF { #include //#include #ifndef TINYGLTF_NO_FS +#include #include #endif #include @@ -2414,11 +2415,7 @@ bool FileExists(const std::string &abs_filename, void *) { #endif #else - FILE *fp = nullptr; - errno_t err = fopen_s(&fp, abs_filename.c_str(), "rb"); - if (err != 0) { - return false; - } + FILE *fp = fopen(abs_filename.c_str(), "rb"); #endif if (fp) { ret = true; From 4ab0386d0926aa4e0630a0e1ade1dee6f2aa92a6 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Sun, 10 Nov 2019 15:31:17 +0900 Subject: [PATCH 7/7] Fix MinGW code path reused linux code path. --- tiny_gltf.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index e84725a..f9ef35d 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -7208,7 +7208,9 @@ static void WriteBinaryGltfFile(const std::string &output, #if defined(_MSC_VER) std::ofstream gltfFile(UTF8ToWchar(output).c_str(), std::ios::binary); #elif defined(__GLIBCXX__) - std::ofstream gltfFile(output.c_str(), std::ios::binary); + int file_descriptor = _wopen(UTF8ToWchar(output).c_str(), _O_WRONLY | _O_BINARY); + __gnu_cxx::stdio_filebuf wfile_buf(file_descriptor, std::ios_base::in); + std::ostream gltfFile(&wfile_buf); #else std::ofstream gltfFile(output.c_str(), std::ios::binary); #endif