|
|
|
@ -172,7 +172,6 @@ typedef struct SceneContextStruct {
|
|
|
|
|
VkDescriptorSet* descriptors;
|
|
|
|
|
GPUBuffer* ubos;
|
|
|
|
|
void** ubo_ptrs;
|
|
|
|
|
uint32_t pcr_size;
|
|
|
|
|
} SceneContext;
|
|
|
|
|
|
|
|
|
|
struct TextureVertex {
|
|
|
|
@ -187,10 +186,6 @@ struct Vertex {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SceneUBO {
|
|
|
|
|
uint32_t test;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ScenePC {
|
|
|
|
|
mat4 view;
|
|
|
|
|
mat4 proj;
|
|
|
|
|
};
|
|
|
|
@ -1312,7 +1307,7 @@ VkResult create_scene(){
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult command_draw_scene(uint32_t pipelines_count, GraphicsPipeline* pipelines, uint32_t* object_counts, Object** objects, uint32_t frame_num, VkDescriptorSet* scene_descriptors, struct ScenePC* scene_constants, VkCommandBuffer command_buffer, VkRenderPass render_pass, VkFramebuffer framebuffer, VkExtent2D extent, VkDeviceAddress object_buffer_addr, int offscreen) {
|
|
|
|
|
VkResult command_draw_scene(uint32_t pipelines_count, GraphicsPipeline* pipelines, uint32_t* object_counts, Object** objects, uint32_t frame_num, VkDescriptorSet* scene_descriptors, VkCommandBuffer command_buffer, VkRenderPass render_pass, VkFramebuffer framebuffer, VkExtent2D extent, VkDeviceAddress object_buffer_addr, int offscreen) {
|
|
|
|
|
VkCommandBufferBeginInfo begin_info = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
|
|
|
|
.flags = 0,
|
|
|
|
@ -1371,10 +1366,8 @@ VkResult command_draw_scene(uint32_t pipelines_count, GraphicsPipeline* pipeline
|
|
|
|
|
};
|
|
|
|
|
vkCmdSetScissor(command_buffer, 0, 1, &scissor);
|
|
|
|
|
|
|
|
|
|
vkCmdPushConstants(command_buffer, pipelines[0].layout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(struct ScenePC), scene_constants);
|
|
|
|
|
vkCmdPushConstants(command_buffer, pipelines[0].layout, VK_SHADER_STAGE_VERTEX_BIT, sizeof(struct ScenePC), sizeof(VkDeviceAddress), &object_buffer_addr);
|
|
|
|
|
vkCmdPushConstants(command_buffer, pipelines[0].layout, VK_SHADER_STAGE_ALL, 0, sizeof(VkDeviceAddress), &object_buffer_addr);
|
|
|
|
|
|
|
|
|
|
// Bind the scene descriptor
|
|
|
|
|
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines[0].layout, 0, 1, &scene_descriptors[frame_num], 0, 0);
|
|
|
|
|
|
|
|
|
|
for(uint i = 0; i < pipelines_count; i++) {
|
|
|
|
@ -1727,9 +1720,9 @@ VkResult create_graphics_pipeline(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkPushConstantRange pcr = {
|
|
|
|
|
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
|
|
|
|
|
.stageFlags = VK_SHADER_STAGE_ALL,
|
|
|
|
|
.offset = 0,
|
|
|
|
|
.size = sizeof(struct ScenePC) + sizeof(VkDeviceAddress),
|
|
|
|
|
.size = sizeof(VkDeviceAddress),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VkPipelineLayoutCreateInfo layout_info = {
|
|
|
|
@ -2706,7 +2699,6 @@ SceneContext create_scene_context(VkDevice device, VkPhysicalDeviceMemoryPropert
|
|
|
|
|
.descriptors = sets,
|
|
|
|
|
.ubos = ubos,
|
|
|
|
|
.ubo_ptrs = ubo_ptrs,
|
|
|
|
|
.pcr_size = sizeof(struct ScenePC),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return scene;
|
|
|
|
@ -2846,7 +2838,7 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
|
|
|
|
|
vec3 world_position = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
versor world_rotation = {-1.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
|
|
|
|
struct ScenePC get_scene_constants(vec3 world_position, versor world_rotation, float aspect_ratio, float time_delta) {
|
|
|
|
|
struct SceneUBO get_scene_ubo(vec3 world_position, versor world_rotation, float aspect_ratio, float time_delta) {
|
|
|
|
|
vec3 movement_sum = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
|
|
|
|
if(key_flags.forward) {
|
|
|
|
@ -2923,16 +2915,17 @@ struct ScenePC get_scene_constants(vec3 world_position, versor world_rotation, f
|
|
|
|
|
glm_quat_rotatev(world_rotation, movement_sum, movement_rot);
|
|
|
|
|
glm_vec3_add(movement_rot, world_position, world_position);
|
|
|
|
|
|
|
|
|
|
struct ScenePC constants = {};
|
|
|
|
|
struct SceneUBO ubo = {};
|
|
|
|
|
|
|
|
|
|
glm_perspective(1.5708f, aspect_ratio, 0.01, 1000, constants.proj);
|
|
|
|
|
glm_quat_look(world_position, world_rotation, constants.view);
|
|
|
|
|
glm_perspective(1.5708f, aspect_ratio, 0.01, 1000, ubo.proj);
|
|
|
|
|
glm_quat_look(world_position, world_rotation, ubo.view);
|
|
|
|
|
|
|
|
|
|
return constants;
|
|
|
|
|
return ubo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult draw_frame(VulkanContext* context, SceneContext* scene, uint32_t pipelines_count, GraphicsPipeline* pipelines, uint32_t* objects_counts, Object** objects, VkDeviceAddress object_buffer_addr) {
|
|
|
|
|
struct ScenePC scene_constants = get_scene_constants(world_position, world_rotation, (float)context->swapchain_extent.width/(float)context->swapchain_extent.height, 0.01);
|
|
|
|
|
struct SceneUBO scene_ubo = get_scene_ubo(world_position, world_rotation, (float)context->swapchain_extent.width/(float)context->swapchain_extent.height, 0.01);
|
|
|
|
|
memcpy(scene->ubo_ptrs[context->current_frame], &scene_ubo, sizeof(struct SceneUBO));
|
|
|
|
|
|
|
|
|
|
VkResult result;
|
|
|
|
|
result = vkWaitForFences(context->device, 1, &context->in_flight_fences[context->current_frame], VK_TRUE, UINT64_MAX);
|
|
|
|
@ -2956,7 +2949,7 @@ VkResult draw_frame(VulkanContext* context, SceneContext* scene, uint32_t pipeli
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = command_draw_scene(pipelines_count, pipelines, objects_counts, objects, context->current_frame, scene->descriptors, &scene_constants, context->swapchain_command_buffers[context->current_frame], context->render_pass, context->swapchain_framebuffers[image_index], context->swapchain_extent, object_buffer_addr, 0);
|
|
|
|
|
result = command_draw_scene(pipelines_count, pipelines, objects_counts, objects, context->current_frame, scene->descriptors, context->swapchain_command_buffers[context->current_frame], context->render_pass, context->swapchain_framebuffers[image_index], context->swapchain_extent, object_buffer_addr, 0);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
@ -2966,7 +2959,7 @@ VkResult draw_frame(VulkanContext* context, SceneContext* scene, uint32_t pipeli
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = command_draw_scene(pipelines_count, pipelines, objects_counts, objects, context->current_frame, scene->descriptors, &scene_constants, context->offscreen_command_buffers[context->current_frame], context->g_renderpass, context->g_framebuffer, context->swapchain_extent, object_buffer_addr, 1);
|
|
|
|
|
result = command_draw_scene(pipelines_count, pipelines, objects_counts, objects, context->current_frame, scene->descriptors, context->offscreen_command_buffers[context->current_frame], context->g_renderpass, context->g_framebuffer, context->swapchain_extent, object_buffer_addr, 1);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|