aports/testing/tinygltf/0006-Big-endian-fix.patch
2025-01-19 01:33:08 +00:00

74 lines
2.8 KiB
Diff

From: =?utf-8?q?Timo_R=C3=B6hling?= <roehling@debian.org>
Date: Mon, 26 Sep 2022 22:30:21 +0200
Subject: Big endian fix
---
tiny_gltf.h | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/tiny_gltf.h b/tiny_gltf.h
index 4d633e3..3960cba 100644
--- a/tiny_gltf.h
+++ b/tiny_gltf.h
@@ -1805,13 +1805,9 @@ class TinyGLTF {
// #include <wordexp.h>
#endif
-#if defined(__sparcv9) || defined(__powerpc__)
-// Big endian
-#else
-#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define TINYGLTF_LITTLE_ENDIAN 1
#endif
-#endif
namespace tinygltf {
namespace detail {
@@ -8495,7 +8491,8 @@ static bool WriteBinaryGltfStream(std::ostream &stream,
const std::string &content,
const std::vector<unsigned char> &binBuffer) {
const std::string header = "glTF";
- const int version = 2;
+ uint32_t version = 2;
+ swap4(&version);
const uint32_t content_size = uint32_t(content.size());
const uint32_t binBuffer_size = uint32_t(binBuffer.size());
@@ -8507,17 +8504,20 @@ static bool WriteBinaryGltfStream(std::ostream &stream,
// 12 bytes for header, JSON content length, 8 bytes for JSON chunk info.
// Chunk data must be located at 4-byte boundary, which may require padding
- const uint32_t length =
+ uint32_t length =
12 + 8 + content_size + content_padding_size +
(binBuffer_size ? (8 + binBuffer_size + bin_padding_size) : 0);
+ swap4(&length);
stream.write(header.c_str(), std::streamsize(header.size()));
stream.write(reinterpret_cast<const char *>(&version), sizeof(version));
stream.write(reinterpret_cast<const char *>(&length), sizeof(length));
// JSON chunk info, then JSON data
- const uint32_t model_length = uint32_t(content.size()) + content_padding_size;
- const uint32_t model_format = 0x4E4F534A;
+ uint32_t model_length = uint32_t(content.size()) + content_padding_size;
+ swap4(&model_length);
+ uint32_t model_format = 0x4E4F534A;
+ swap4(&model_format);
stream.write(reinterpret_cast<const char *>(&model_length),
sizeof(model_length));
stream.write(reinterpret_cast<const char *>(&model_format),
@@ -8531,8 +8531,10 @@ static bool WriteBinaryGltfStream(std::ostream &stream,
}
if (binBuffer.size() > 0) {
// BIN chunk info, then BIN data
- const uint32_t bin_length = uint32_t(binBuffer.size()) + bin_padding_size;
- const uint32_t bin_format = 0x004e4942;
+ uint32_t bin_length = uint32_t(binBuffer.size()) + bin_padding_size;
+ swap4(&bin_length);
+ uint32_t bin_format = 0x004e4942;
+ swap4(&bin_format);
stream.write(reinterpret_cast<const char *>(&bin_length),
sizeof(bin_length));
stream.write(reinterpret_cast<const char *>(&bin_format),