Use TINYGLTF_ENABLE_SERIALIZER ifdef to enable/disable serialization code.

This commit is contained in:
Syoyo Fujita 2020-06-08 16:46:33 +09:00
parent 3d939fd3ee
commit bafde6a53e
2 changed files with 18 additions and 0 deletions

View File

@ -153,6 +153,7 @@ if (!ret) {
## Compile options
* `TINYGLTF_ENABLE_SERIALIZER` : Enable glTF serialization feature.
* `TINYGLTF_NOEXCEPTION` : Disable C++ exception in JSON parsing. You can use `-fno-exceptions` or by defining the symbol `JSON_NOEXCEPTION` and `TINYGLTF_NOEXCEPTION` to fully remove C++ exception codes when compiling TinyGLTF.
* `TINYGLTF_NO_STB_IMAGE` : Do not load images with stb_image. Instead use `TinyGLTF::SetImageLoader(LoadimageDataFunction LoadImageData, void *user_data)` to set a callback for loading images.
* `TINYGLTF_NO_STB_IMAGE_WRITE` : Do not write images with stb_image_write. Instead use `TinyGLTF::SetImageWriter(WriteimageDataFunction WriteImageData, void *user_data)` to set a callback for writing images.

View File

@ -26,6 +26,7 @@
// THE SOFTWARE.
// Version:
// - v2.4.3 Introduce TINYGLTF_ENABLE_SERIALIZER.
// - v2.4.2 Decode percent-encoded URI.
// - v2.4.1 Fix some glTF object class does not have `extensions` and/or
// `extras` property.
@ -1323,6 +1324,8 @@ class TinyGLTF {
const std::string &base_dir = "",
unsigned int check_sections = REQUIRE_VERSION);
#if defined(TINYGLTF_ENABLE_SERIALIZER)
///
/// Write glTF to stream, buffers and images will be embeded
///
@ -1336,16 +1339,22 @@ class TinyGLTF {
bool embedImages, bool embedBuffers,
bool prettyPrint, bool writeBinary);
#endif
///
/// Set callback to use for loading image data
///
void SetImageLoader(LoadImageDataFunction LoadImageData, void *user_data);
#if defined(TINYGLTF_ENABLE_SERIALIZER)
///
/// Set callback to use for writing image data
///
void SetImageWriter(WriteImageDataFunction WriteImageData, void *user_data);
#endif
///
/// Set callbacks to use for filesystem (fs) access and their user data
///
@ -2393,11 +2402,15 @@ bool LoadImageData(Image *image, const int image_idx, std::string *err,
}
#endif
#if defined(TINYGLTF_ENABLE_SERIALIZER)
void TinyGLTF::SetImageWriter(WriteImageDataFunction func, void *user_data) {
WriteImageData = func;
write_image_user_data_ = user_data;
}
#endif
#ifndef TINYGLTF_NO_STB_IMAGE_WRITE
static void WriteToMemory_stbi(void *context, void *data, int size) {
std::vector<unsigned char> *buffer =
@ -6214,6 +6227,8 @@ bool TinyGLTF::LoadBinaryFromFile(Model *model, std::string *err,
return ret;
}
#if defined(TINYGLTF_ENABLE_SERIALIZER)
///////////////////////
// GLTF Serialization
///////////////////////
@ -7619,6 +7634,8 @@ bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename,
return true;
}
#endif // TINYGLTF_ENABLE_SERIALIZER
} // namespace tinygltf
#ifdef __clang__