diff --git a/kraken/KRMeshManager.cpp b/kraken/KRMeshManager.cpp index b617107..f98480e 100755 --- a/kraken/KRMeshManager.cpp +++ b/kraken/KRMeshManager.cpp @@ -865,3 +865,16 @@ void KRMeshManager::primeVBO(KRVBOData *vbo_data) m_vbosActive[vbo_data->m_data] = vbo_data; } } + + +VkBuffer& KRMeshManager::KRVBOData::getVertexBuffer() +{ + assert(m_is_vbo_ready); + return m_allocations->vertex_buffer; +} + +VkBuffer& KRMeshManager::KRVBOData::getIndexBuffer() +{ + assert(m_is_vbo_ready); + return m_allocations->index_buffer; +} diff --git a/kraken/KRMeshManager.h b/kraken/KRMeshManager.h index a4a9a63..479c9c7 100755 --- a/kraken/KRMeshManager.h +++ b/kraken/KRMeshManager.h @@ -111,6 +111,9 @@ public: float getStreamPriority(); void _swapHandles(); + + VkBuffer& getVertexBuffer(); + VkBuffer& getIndexBuffer(); private: KRMeshManager *m_manager; diff --git a/kraken/KRPipeline.cpp b/kraken/KRPipeline.cpp index 189ae86..b890cda 100644 --- a/kraken/KRPipeline.cpp +++ b/kraken/KRPipeline.cpp @@ -184,12 +184,32 @@ KRPipeline::KRPipeline(KRContext& context, KrDeviceHandle deviceHandle, VkFormat // failed! TODO - Error handling } + // TODO - Make bindings dynamic... + VkVertexInputBindingDescription bindingDescription{}; + bindingDescription.binding = 0; + bindingDescription.stride = sizeof(float) * 3 + sizeof(uint16_t) * 2; + bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; + + const int kMaxVertexDescriptions = 16; + VkVertexInputAttributeDescription vertexAttributeDescriptions[kMaxVertexDescriptions]{}; + // position + vertexAttributeDescriptions[0].binding = 0; + vertexAttributeDescriptions[0].location = 0; + vertexAttributeDescriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT; + vertexAttributeDescriptions[0].offset = 0; + + // uv + vertexAttributeDescriptions[1].binding = 0; + vertexAttributeDescriptions[1].location = 1; + vertexAttributeDescriptions[1].format = VK_FORMAT_R32G32_SFLOAT; + vertexAttributeDescriptions[1].offset = sizeof(float) * 3; + VkPipelineVertexInputStateCreateInfo vertexInputInfo{}; vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; - vertexInputInfo.vertexBindingDescriptionCount = 0; - vertexInputInfo.pVertexBindingDescriptions = nullptr; // TODO - vertexInputInfo.vertexAttributeDescriptionCount = 0; - vertexInputInfo.pVertexAttributeDescriptions = nullptr; // TODO + vertexInputInfo.vertexBindingDescriptionCount = 1; + vertexInputInfo.pVertexBindingDescriptions = &bindingDescription; + vertexInputInfo.vertexAttributeDescriptionCount = 2; + vertexInputInfo.pVertexAttributeDescriptions = vertexAttributeDescriptions; VkPipelineInputAssemblyStateCreateInfo inputAssembly{}; inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; diff --git a/kraken/KRPresentationThread.cpp b/kraken/KRPresentationThread.cpp index ea3e7f4..214107b 100644 --- a/kraken/KRPresentationThread.cpp +++ b/kraken/KRPresentationThread.cpp @@ -141,6 +141,9 @@ void KRPresentationThread::renderFrame() VkCommandBuffer commandBuffer = device.m_graphicsCommandBuffers[imageIndex]; KRPipeline* testPipeline = m_pContext->getPipelineManager()->get("vulkan_test"); + KRMeshManager::KRVBOData& testVertices = getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES; + bool haveMesh = testVertices.isVBOReady(); + VkCommandBufferBeginInfo beginInfo{}; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; beginInfo.flags = 0; @@ -164,7 +167,14 @@ void KRPresentationThread::renderFrame() vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, testPipeline->getPipeline()); - vkCmdDraw(commandBuffer, 3, 1, 0, 0); + if (haveMesh) { + + VkBuffer vertexBuffers[] = { testVertices.getVertexBuffer() }; + VkDeviceSize offsets[] = { 0 }; + vkCmdBindVertexBuffers(commandBuffer, 0, 1, vertexBuffers, offsets); + vkCmdDraw(commandBuffer, 3, 1, 0, 0); + } + vkCmdEndRenderPass(commandBuffer); if (vkEndCommandBuffer(commandBuffer) != VK_SUCCESS) { m_activeState = PresentThreadState::error;