From f6ce7e345d7d875918a1c56a45d79775e9c202b4 Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Tue, 27 Mar 2018 11:26:50 -0700 Subject: [PATCH] Keep our byte-writing within bounds. Now that we're writing both 16-bit and 32-bit integers, it's starting to matter a little more how we slam even scalars into memory. This is maybe not the fastest way to accomplish this, and I'm not crazy about the way GLType works in general, but it does have the virtues of clarity and expediency. --- src/Raw2Gltf.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Raw2Gltf.h b/src/Raw2Gltf.h index 9127061..142e242 100644 --- a/src/Raw2Gltf.h +++ b/src/Raw2Gltf.h @@ -65,7 +65,19 @@ struct GLType { unsigned int byteStride() const { return componentType.size * count; } void write(uint8_t *buf, const float scalar) const { *((float *) buf) = scalar; } - void write(uint8_t *buf, const uint32_t scalar) const { *((uint32_t *) buf) = scalar; } + void write(uint8_t *buf, const uint32_t scalar) const { + switch(componentType.size) { + case 1: + *buf = (uint8_t)scalar; + break; + case 2: + *((uint16_t *) buf) = (uint16_t)scalar; + break; + case 4: + *((uint32_t *) buf) = scalar; + break; + } + } template void write(uint8_t *buf, const mathfu::Vector &vector) const {