#include "entities.hpp" #include "ecs.hpp" #include 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{}; // TODO allocator 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 // cleanup cgltf_free(gltfData); } } void EntityType_Teardown() { long entityTypeCount = globalEntityTypes.Count(); for (long i = 0; i < entityTypeCount; ++i) { if (globalEntityTypes[i].modelFile == nullptr) continue; auto *grBinds = ECS_GetGrBinds(globalEntityTypes[i].entityHandle); vkDestroyPipelineLayout(vkDevice, grBinds->vkPipelineLayout, vkAllocator); vkDestroyBuffer(vkDevice, grBinds->vertexBuffer, vkAllocator); vkDestroyBuffer(vkDevice, grBinds->vertexBuffer, vkAllocator); vkDestroyBuffer(vkDevice, grBinds->vertexBuffer, vkAllocator); } }