WIP Binding vertex buffers
This commit is contained in:
@@ -865,3 +865,16 @@ void KRMeshManager::primeVBO(KRVBOData *vbo_data)
|
|||||||
m_vbosActive[vbo_data->m_data] = 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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -111,6 +111,9 @@ public:
|
|||||||
float getStreamPriority();
|
float getStreamPriority();
|
||||||
|
|
||||||
void _swapHandles();
|
void _swapHandles();
|
||||||
|
|
||||||
|
VkBuffer& getVertexBuffer();
|
||||||
|
VkBuffer& getIndexBuffer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KRMeshManager *m_manager;
|
KRMeshManager *m_manager;
|
||||||
|
|||||||
@@ -184,12 +184,32 @@ KRPipeline::KRPipeline(KRContext& context, KrDeviceHandle deviceHandle, VkFormat
|
|||||||
// failed! TODO - Error handling
|
// 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{};
|
VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
|
||||||
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||||
vertexInputInfo.vertexBindingDescriptionCount = 0;
|
vertexInputInfo.vertexBindingDescriptionCount = 1;
|
||||||
vertexInputInfo.pVertexBindingDescriptions = nullptr; // TODO
|
vertexInputInfo.pVertexBindingDescriptions = &bindingDescription;
|
||||||
vertexInputInfo.vertexAttributeDescriptionCount = 0;
|
vertexInputInfo.vertexAttributeDescriptionCount = 2;
|
||||||
vertexInputInfo.pVertexAttributeDescriptions = nullptr; // TODO
|
vertexInputInfo.pVertexAttributeDescriptions = vertexAttributeDescriptions;
|
||||||
|
|
||||||
VkPipelineInputAssemblyStateCreateInfo inputAssembly{};
|
VkPipelineInputAssemblyStateCreateInfo inputAssembly{};
|
||||||
inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
||||||
|
|||||||
@@ -141,6 +141,9 @@ void KRPresentationThread::renderFrame()
|
|||||||
VkCommandBuffer commandBuffer = device.m_graphicsCommandBuffers[imageIndex];
|
VkCommandBuffer commandBuffer = device.m_graphicsCommandBuffers[imageIndex];
|
||||||
KRPipeline* testPipeline = m_pContext->getPipelineManager()->get("vulkan_test");
|
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{};
|
VkCommandBufferBeginInfo beginInfo{};
|
||||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||||
beginInfo.flags = 0;
|
beginInfo.flags = 0;
|
||||||
@@ -164,7 +167,14 @@ void KRPresentationThread::renderFrame()
|
|||||||
|
|
||||||
vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
|
vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||||
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, testPipeline->getPipeline());
|
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);
|
vkCmdEndRenderPass(commandBuffer);
|
||||||
if (vkEndCommandBuffer(commandBuffer) != VK_SUCCESS) {
|
if (vkEndCommandBuffer(commandBuffer) != VK_SUCCESS) {
|
||||||
m_activeState = PresentThreadState::error;
|
m_activeState = PresentThreadState::error;
|
||||||
|
|||||||
Reference in New Issue
Block a user