|
|
|
@ -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) {
|
|
|
|
|