diff --git a/shader_src/basic.vert b/shader_src/basic.vert index a3f9f94..36ee7e5 100644 --- a/shader_src/basic.vert +++ b/shader_src/basic.vert @@ -1,9 +1,13 @@ #version 450 -layout(binding = 0) uniform UniformBufferObject { +layout(set = 0, binding = 0) uniform SceneUniform { mat4 view; mat4 proj; -} ubo; +} scene; + +layout(set = 2, binding = 0) uniform ModelUniform { + mat4 model; +} model_ubo; layout(location = 0) in vec3 inPosition; layout(location = 1) in vec3 inColor; @@ -11,6 +15,6 @@ layout(location = 1) in vec3 inColor; layout(location = 0) out vec3 fragColor; void main() { - gl_Position = ubo.proj * ubo.view * vec4(inPosition, 1.0); + gl_Position = scene.proj * scene.view * model_ubo.model * vec4(inPosition, 1.0); fragColor = inColor; } diff --git a/src/main.c b/src/main.c index 037e614..86e0ada 100644 --- a/src/main.c +++ b/src/main.c @@ -1829,6 +1829,8 @@ void command_draw_object(Material material, Object object, uint32_t frame_num, V VkDescriptorSet* descriptor_sets = maybe_descriptors.value; vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, material.layout, 2, 1, &descriptor_sets[frame_num], 0, 0); + } else { + fprintf(stderr, "test\n"); } vkCmdDrawIndexed(command_buffer, mesh->index_count, 1, 0, 0, 0); @@ -2289,7 +2291,7 @@ Material create_simple_mesh_material(VkDevice device, VkExtent2D extent, VkRende PipelineLayout simple_layout = { .object_bindings = object_set_bindings, - .object_bindings_count = sizeof(object_set_bindings)/sizeof(*object_set_bindings), + .object_bindings_count = sizeof(object_set_bindings)/sizeof(VkDescriptorSetLayoutBinding), }; Map object_descriptor_mappings = map_create(8, 2); @@ -2329,16 +2331,21 @@ Material create_texture_mesh_material(VkDevice device, VkExtent2D extent, VkRend Material tmp = {}; return tmp; } - VkPipelineShaderStageCreateInfo shader_stages[2] = {}; - shader_stages[0].sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO_EXT; - shader_stages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; - shader_stages[0].module = vert_shader; - shader_stages[0].pName = "main"; + VkPipelineShaderStageCreateInfo shader_stages[2] = { + { + .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO_EXT, + .stage = VK_SHADER_STAGE_VERTEX_BIT, + .module = vert_shader, + .pName = "main", + }, + { + .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO_EXT, + .stage = VK_SHADER_STAGE_FRAGMENT_BIT, + .module = frag_shader, + .pName = "main", + }, + }; - shader_stages[1].sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO_EXT; - shader_stages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; - shader_stages[1].module = frag_shader; - shader_stages[1].pName = "main"; VkVertexInputBindingDescription bindings[] = { { @@ -3119,10 +3126,12 @@ Object create_simple_mesh_object(Material* simple_mesh_material, VkPhysicalDevic return zero; } glm_quat_identity(position->rotation); - glm_vec3_adds(position->scale, 1.0f, position->scale); + position->scale[0] = 1.f; + position->scale[1] = 1.f; + position->scale[2] = 1.f; position->position[0] = 0.0f; position->position[1] = 0.0f; - position->position[2] = 2.0f; + position->position[2] = 0.0f; bool map_result = map_add(&object.attributes, ATTRIBUTE_ID_POSITION, position); if(map_result == 0) { return zero; @@ -3137,6 +3146,7 @@ Object create_simple_mesh_object(Material* simple_mesh_material, VkPhysicalDevic if(maybe_ptrs.has_value == false) { return zero; } + void*** ptrs = maybe_ptrs.value; for(uint32_t i = 0; i < max_frames_in_flight; i++) { VkResult result = vkMapMemory(device, position_buffers[i].memory, 0, sizeof(struct ModelUBO), 0, &ptrs[i][0]); @@ -3156,6 +3166,7 @@ Object create_simple_mesh_object(Material* simple_mesh_material, VkPhysicalDevic .dstBinding = 0, .dstArrayElement = 0, .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, + .descriptorCount = 1, .pBufferInfo = &buffer_info, }; @@ -3209,9 +3220,9 @@ Object create_texture_mesh_object(Material* texture_mesh_material, VkPhysicalDev return zero; } glm_quat_identity(position->rotation); - position->scale[0] = 1.f; - position->scale[1] = 1.f; - position->scale[2] = 1.f; + position->scale[0] = 0.5f; + position->scale[1] = 0.5f; + position->scale[2] = 0.5f; position->position[0] = 0.0f; position->position[1] = 0.0f; position->position[2] = 1.0f; @@ -3389,15 +3400,15 @@ void main_loop(GLFWwindow* window, VulkanContext* context) { return; } - Object* objects[] = {&triangle_object_textured, &triangle_object}; - Material materials[] = {texture_mesh_material, simple_mesh_material}; + Object* objects[] = {&triangle_object, &triangle_object_textured}; + Material materials[] = {simple_mesh_material, texture_mesh_material}; uint32_t objects_counts[] = {1, 1}; context->current_frame = 0; while(!glfwWindowShouldClose(window)) { glfwPollEvents(); - VkResult result = draw_frame(context, &scene, 2, materials, objects_counts, objects); + VkResult result = draw_frame(context, &scene, sizeof(materials)/sizeof(Material), materials, objects_counts, objects); if(result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) { recreate_swap_chain(context); } else if(result != VK_SUCCESS) {