WIP Binding vertex buffers

This commit is contained in:
2022-02-13 22:22:51 -08:00
parent 8414c1c0bb
commit 400a7e0061
4 changed files with 51 additions and 5 deletions

View File

@@ -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;
}

View File

@@ -112,6 +112,9 @@ public:
void _swapHandles();
VkBuffer& getVertexBuffer();
VkBuffer& getIndexBuffer();
private:
KRMeshManager *m_manager;
int m_vertex_attrib_flags;

View File

@@ -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;

View File

@@ -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());
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;