From 2aefdcc26eb98a0fb93f160dbd8f0789e77ae6c7 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Mon, 24 Oct 2022 21:40:34 +0100 Subject: Fix usages of mesh simplification functions in float=64 builds --- core/io/marshalls.cpp | 21 +++++++++++++++++++++ core/io/marshalls.h | 2 ++ 2 files changed, 23 insertions(+) (limited to 'core/io') diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 9ba653e1a9..9f89f5d8c9 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -1813,3 +1813,24 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo return OK; } + +Vector vector3_to_float32_array(const Vector3 *vecs, size_t count) { + // We always allocate a new array, and we don't memcpy. + // We also don't consider returning a pointer to the passed vectors when sizeof(real_t) == 4. + // One reason is that we could decide to put a 4th component in Vector3 for SIMD/mobile performance, + // which would cause trouble with these optimizations. + Vector floats; + if (count == 0) { + return floats; + } + floats.resize(count * 3); + float *floats_w = floats.ptrw(); + for (size_t i = 0; i < count; ++i) { + const Vector3 v = vecs[i]; + floats_w[0] = v.x; + floats_w[1] = v.y; + floats_w[2] = v.z; + floats_w += 3; + } + return floats; +} diff --git a/core/io/marshalls.h b/core/io/marshalls.h index fef3a1c2c1..66e2571066 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -215,4 +215,6 @@ public: Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = nullptr, bool p_allow_objects = false, int p_depth = 0); Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects = false, int p_depth = 0); +Vector vector3_to_float32_array(const Vector3 *vecs, size_t count); + #endif // MARSHALLS_H -- cgit v1.2.3