BindVertexBuffers and BindIndexBuffer

pull/8/head
cosmonaut 2020-12-19 23:31:55 -08:00
parent 47823c67ac
commit 7d2018e712
3 changed files with 83 additions and 0 deletions

View File

@ -1233,6 +1233,21 @@ REFRESHAPI void REFRESH_BindGraphicsPipeline(
REFRESH_GraphicsPipeline *graphicsPipeline
);
REFRESHAPI void REFRESH_BindVertexBuffers(
REFRESH_Device *device,
uint32_t firstBinding,
uint32_t bindingCount,
REFRESH_Buffer **pBuffers,
uint64_t *pOffsets
);
REFRESHAPI void REFRESH_BindIndexBuffer(
REFRESH_Device *device,
REFRESH_Buffer *buffer,
uint64_t offset,
REFRESH_IndexElementSize indexElementSize
);
/* Presentation */
REFRESHAPI void REFRESH_Present(

View File

@ -481,6 +481,21 @@ struct REFRESH_Device
REFRESH_GraphicsPipeline *graphicsPipeline
);
void(*BindVertexBuffers)(
REFRESH_Renderer *driverData,
uint32_t firstBinding,
uint32_t bindingCount,
REFRESH_Buffer **pBuffers,
uint64_t *pOffsets
);
void(*BindIndexBuffer)(
REFRESH_Renderer *driverData,
REFRESH_Buffer *buffer,
uint64_t offset,
REFRESH_IndexElementSize indexElementSize
);
void(*Present)(
REFRESH_Renderer *driverData,
REFRESH_Rect *sourceRectangle,
@ -536,6 +551,8 @@ struct REFRESH_Device
ASSIGN_DRIVER_FUNC(BeginRenderPass, name) \
ASSIGN_DRIVER_FUNC(EndRenderPass, name) \
ASSIGN_DRIVER_FUNC(BindGraphicsPipeline, name) \
ASSIGN_DRIVER_FUNC(BindVertexBuffers, name) \
ASSIGN_DRIVER_FUNC(BindIndexBuffer, name) \
ASSIGN_DRIVER_FUNC(Present, name)
typedef struct REFRESH_Driver

View File

@ -183,6 +183,12 @@ static VkFormat RefreshToVK_VertexFormat[] =
VK_FORMAT_R16G16B16A16_SFLOAT /* HALFVECTOR4 */
};
static VkIndexType RefreshToVK_IndexType[] =
{
VK_INDEX_TYPE_UINT16,
VK_INDEX_TYPE_UINT32
};
static VkPrimitiveTopology RefreshToVK_PrimitiveType[] =
{
VK_PRIMITIVE_TOPOLOGY_POINT_LIST,
@ -3887,6 +3893,51 @@ static void VULKAN_BindGraphicsPipeline(
SDL_assert(0);
}
static void VULKAN_BindVertexBuffers(
REFRESH_Renderer *driverData,
uint32_t firstBinding,
uint32_t bindingCount,
REFRESH_Buffer **pBuffers,
uint64_t *pOffsets
) {
VkBuffer *buffers = SDL_stack_alloc(VkBuffer, bindingCount);
VulkanBuffer* currentBuffer;
VulkanRenderer* renderer = (VulkanRenderer*) driverData;
for (int i = 0; i < bindingCount; i += 1)
{
currentBuffer = (VulkanBuffer*) pBuffers[i];
buffers[i] = currentBuffer->subBuffers[currentBuffer->currentSubBufferIndex]->buffer;
}
RECORD_CMD(renderer->vkCmdBindVertexBuffers(
renderer->currentCommandBuffer,
firstBinding,
bindingCount,
buffers,
pOffsets
));
SDL_stack_free(buffers);
}
static void VULKAN_BindIndexBuffer(
REFRESH_Renderer *driverData,
REFRESH_Buffer *buffer,
uint64_t offset,
REFRESH_IndexElementSize indexElementSize
) {
VulkanRenderer* renderer = (VulkanRenderer*) driverData;
VulkanBuffer* vulkanBuffer = (VulkanBuffer*) buffer;
RECORD_CMD(renderer->vkCmdBindIndexBuffer(
renderer->currentCommandBuffer,
vulkanBuffer->subBuffers[vulkanBuffer->currentSubBufferIndex]->buffer,
offset,
RefreshToVK_IndexType[indexElementSize]
));
}
static void VULKAN_Present(
REFRESH_Renderer *driverData,
REFRESH_Rect *sourceRectangle,