summaryrefslogtreecommitdiff
path: root/src/entities.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/entities.cpp')
-rw-r--r--src/entities.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/entities.cpp b/src/entities.cpp
new file mode 100644
index 0000000..fb2bc60
--- /dev/null
+++ b/src/entities.cpp
@@ -0,0 +1,41 @@
+
+#include "entities.hpp"
+#include "ecs.hpp"
+#include <vulkan/vulkan_core.h>
+
+void EntityType_Init() {}
+
+void EntityType_Load(EntityType &et) {
+ if (et.modelFile != nullptr && et.modelFile != CAFE_BABE(char)) {
+ assert(et.vkPipelineLayoutCreateInfo != nullptr && et.vkPipelineLayoutCreateInfo != CAFE_BABE(VkPipelineLayoutCreateInfo) && "EntityType with a defined model must also contain appropriate Vulkan CreateInfos");
+ AssetHandle assetHandle{AM_Register(et.modelFile)};
+ const Asset *asset = AM_Get(assetHandle);
+
+ CompGrBinds &grBinds = ECS_CreateGrBinds(et.entityHandle);
+ auto vkResult = vkCreatePipelineLayout(vkDevice, et.vkPipelineLayoutCreateInfo, vkAllocator, &grBinds.vkPipelineLayout);
+ assert(vkResult == VK_SUCCESS);
+ // TODO grBinds.vkDescriptorSet
+
+ cgltf_options options{};
+ cgltf_data *gltfData = nullptr;
+ cgltf_result result = cgltf_parse(&options, asset->ptr, asset->size, &gltfData);
+ assert(result == cgltf_result_success);
+ result = cgltf_validate(gltfData);
+ assert(result == cgltf_result_success);
+
+ // create buffers
+ // TODO
+
+ // create VkDeviceMemory
+ VkMemoryAllocateInfo vkMemoryAllocateInfo;
+ vkMemoryAllocateInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
+ vkMemoryAllocateInfo.pNext = nullptr;
+ vkMemoryAllocateInfo.allocationSize = gltfData->buffers[0].size;;
+ vkMemoryAllocateInfo.memoryTypeIndex = FindMemoryTypeIndex(0, 0); // TODO
+
+ vkAllocateMemory(vkDevice, &vkMemoryAllocateInfo, vkAllocator, &grBinds.deviceMemory);
+
+ // TODO bind buffers to memory
+ }
+
+}