1
Fork 0

Don't overwrite vertex data and other vertex-related changes

It's not rendering vertices correctly yet, but it's almost there! :-)
This commit is contained in:
Joshua Goins 2022-10-05 10:03:54 -04:00
parent 9f184efaf2
commit b9bb20c398

View file

@ -257,17 +257,6 @@ static std::pair<VkPipeline, VkPipelineLayout> gfx_vulkan_create_pipeline(const
attributes.push_back(uv_attribute);
}
if(needs_screenpos) {
VkVertexInputAttributeDescription screenpos_attribute = {};
screenpos_attribute.format = VK_FORMAT_R32G32B32A32_SFLOAT;
screenpos_attribute.location = current_location++;
screenpos_attribute.offset = num_floats * sizeof(float);
num_floats += 4;
attributes.push_back(screenpos_attribute);
}
if(uses_fog) {
VkVertexInputAttributeDescription fog_attribute = {};
fog_attribute.format = VK_FORMAT_R32G32B32A32_SFLOAT;
@ -281,11 +270,16 @@ static std::pair<VkPipeline, VkPipelineLayout> gfx_vulkan_create_pipeline(const
for(int i = 0; i < features.num_inputs; i++) {
VkVertexInputAttributeDescription extra_attribute = {};
extra_attribute.format = VK_FORMAT_R32G32B32A32_SFLOAT;
extra_attribute.location = current_location++;
extra_attribute.offset = num_floats * sizeof(float);
if(uses_alpha) {
extra_attribute.format = VK_FORMAT_R32G32B32A32_SFLOAT;
num_floats += 4;
} else {
extra_attribute.format = VK_FORMAT_R32G32B32_SFLOAT;
num_floats += 3;
}
attributes.push_back(extra_attribute);
}
@ -889,6 +883,8 @@ static void gfx_vulkan_renderer_on_resize(void) {
// doesn't seem to be called?
}
static int buf_vbo_offset = 0;
static void gfx_vulkan_renderer_start_frame(void) {
vkWaitForFences(
device, 1,
@ -933,6 +929,8 @@ static void gfx_vulkan_renderer_start_frame(void) {
render_pass_begin.renderArea.extent.height = 480;
vkCmdBeginRenderPass(current_cmd, &render_pass_begin, VK_SUBPASS_CONTENTS_INLINE);
buf_vbo_offset = 0;
}
/* draw commands */
@ -971,35 +969,34 @@ static void gfx_vulkan_renderer_unload_shader(struct ShaderProgram *old_prg) {
static void gfx_vulkan_renderer_load_shader(struct ShaderProgram *new_prg) {
ShaderProgramVulkan* vulkan = (ShaderProgramVulkan*)new_prg;
if(current_cmd != VK_NULL_HANDLE) {
vkCmdBindPipeline(current_cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, vulkan->pipeline);
}
last_program = vulkan;
}
static void gfx_vulkan_renderer_draw_triangles(float buf_vbo[], size_t buf_vbo_len, size_t buf_vbo_num_tris) {
if(last_program != nullptr) {
gfx_vulkan_renderer_load_shader(reinterpret_cast<ShaderProgram *>(last_program));
vkCmdBindPipeline(current_cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, last_program->pipeline);
}
void* mapped_data = nullptr;
vkMapMemory(device, vertex_memory, 0, buf_vbo_len, 0, &mapped_data);
vkMapMemory(device, vertex_memory, buf_vbo_offset, buf_vbo_len * sizeof(float), 0, &mapped_data);
memcpy(mapped_data, buf_vbo, buf_vbo_len * sizeof(float));
VkMappedMemoryRange range = {};
range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
range.memory = vertex_memory;
range.size = buf_vbo_len;
range.size = buf_vbo_len * sizeof(float);
range.offset = buf_vbo_offset;
vkFlushMappedMemoryRanges(device, 1, &range);
vkUnmapMemory(device, vertex_memory);
VkDeviceSize offsets[] = {0};
VkDeviceSize offsets[] = {static_cast<VkDeviceSize>(buf_vbo_offset)};
vkCmdBindVertexBuffers(current_cmd, 0, 1, &vertex_buffer, offsets);
vkCmdDraw(current_cmd, buf_vbo_num_tris * 3, 1, 0, 0);
buf_vbo_offset += buf_vbo_len * sizeof(float);
}
/* end draw commands */