From f85a24e3d651344a0cd497cc6b2c8ba6ffb3d38b Mon Sep 17 00:00:00 2001
From: Tobias Frisch <tfrisch@uni-koblenz.de>
Date: Mon, 19 Jul 2021 22:49:53 +0200
Subject: [PATCH] [#79] Fix for stride zero

Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de>
---
 .../src/vkcv/asset/asset_loader.cpp           | 23 ++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/modules/asset_loader/src/vkcv/asset/asset_loader.cpp b/modules/asset_loader/src/vkcv/asset/asset_loader.cpp
index 599b1eaf..3e7207e4 100644
--- a/modules/asset_loader/src/vkcv/asset/asset_loader.cpp
+++ b/modules/asset_loader/src/vkcv/asset/asset_loader.cpp
@@ -32,7 +32,7 @@ namespace vkcv::asset {
 	 * @param type	The accessor type
 	 * @return	An unsigned integer count
 	 */
-	static uint8_t getComponentCount(const fx::gltf::Accessor::Type type) {
+	static uint32_t getComponentCount(const fx::gltf::Accessor::Type type) {
 		switch (type) {
 		case fx::gltf::Accessor::Type::Scalar:
 			return 1;
@@ -52,6 +52,22 @@ namespace vkcv::asset {
 			return 0;
 		}
 	}
+	
+	static uint32_t getComponentSize(ComponentType type) {
+		switch (type) {
+			case ComponentType::INT8:
+			case ComponentType::UINT8:
+				return 1;
+			case ComponentType::INT16:
+			case ComponentType::UINT16:
+				return 2;
+			case ComponentType::UINT32:
+			case ComponentType::FLOAT32:
+				return 4;
+			default:
+				return 0;
+		}
+	}
 
 	/**
 	 * Translate the component type used in the index accessor of fx-gltf to our
@@ -124,6 +140,11 @@ namespace vkcv::asset {
 				att.stride = buf.byteStride;
 				att.componentType = static_cast<ComponentType>(accessor.componentType);
 				att.componentCount = getComponentCount(accessor.type);
+				
+				/* Assume tightly packed stride as not explicitly provided */
+				if (att.stride == 0) {
+					att.stride = att.componentCount * getComponentSize(att.componentType);
+				}
 			}
 			
 			if ((att.type == PrimitiveType::UNDEFINED) ||
-- 
GitLab