diff options
Diffstat (limited to 'src/vk/graphics_pipeline_3d.cpp')
-rw-r--r-- | src/vk/graphics_pipeline_3d.cpp | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/src/vk/graphics_pipeline_3d.cpp b/src/vk/graphics_pipeline_3d.cpp index 4eacc9d..6639d99 100644 --- a/src/vk/graphics_pipeline_3d.cpp +++ b/src/vk/graphics_pipeline_3d.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022 Frederico de Oliveira Linhares + * Copyright 2022-2023 Frederico de Oliveira Linhares * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ #include "../core.hpp" #include "core.hpp" #include "image.hpp" -#include "vertex_3d.hpp" +#include "static_mesh_vertex.hpp" #include "uniform_data_object.hpp" namespace @@ -330,7 +330,7 @@ load_pipeline(void *obj) VkVertexInputBindingDescription vertex_input_binding{}; vertex_input_binding.binding = 0; - vertex_input_binding.stride = sizeof(VK::Vertex3D); + vertex_input_binding.stride = sizeof(VK::StaticMeshVertex); vertex_input_binding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; std::array<VkVertexInputAttributeDescription, 3> vertex_attribute{}; @@ -338,17 +338,17 @@ load_pipeline(void *obj) vertex_attribute[0].location = 0; vertex_attribute[0].binding = 0; vertex_attribute[0].format = VK_FORMAT_R32G32B32_SFLOAT; - vertex_attribute[0].offset = offsetof(VK::Vertex3D, position); + vertex_attribute[0].offset = offsetof(VK::StaticMeshVertex, position); // Normal. vertex_attribute[1].location = 1; vertex_attribute[1].binding = 0; vertex_attribute[1].format = VK_FORMAT_R32G32B32_SFLOAT; - vertex_attribute[1].offset = offsetof(VK::Vertex3D, normal); + vertex_attribute[1].offset = offsetof(VK::StaticMeshVertex, normal); // Texture coordinate. vertex_attribute[2].location = 2; vertex_attribute[2].binding = 0; vertex_attribute[2].format = VK_FORMAT_R32G32_SFLOAT; - vertex_attribute[2].offset = offsetof(VK::Vertex3D, texture_coord); + vertex_attribute[2].offset = offsetof(VK::StaticMeshVertex, texture_coord); VkPipelineVertexInputStateCreateInfo vertex_input_info = {}; vertex_input_info.sType = @@ -557,49 +557,48 @@ GraphicsPipeline3D::draw( } // Draw models - for(auto& [model, instances]: - cg_core.vk_renderer->models_to_draw[current_frame]) + for(auto& [static_mesh, instances]: + cg_core.vk_renderer->static_models_to_draw[current_frame]) { - std::array<VkDescriptorSet, 3> vk_descriptor_sets{ - this->descriptor_sets_world[image_index], - view->descriptor_sets_3d[image_index], - model->descriptor_sets[image_index]}; - VkBuffer vertex_buffers[]{model->mesh->vertex_buffer->buffer}; + VkBuffer vertex_buffers[]{static_mesh->vertex_buffer->buffer}; VkDeviceSize offsets[]{0}; - vkCmdBindDescriptorSets( - draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, - cg_core.vk_graphics_pipeline_3d_layout->pipeline, 0, - vk_descriptor_sets.size(), vk_descriptor_sets.data(), 0, nullptr); vkCmdBindPipeline( draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, this->graphic_pipeline); vkCmdBindVertexBuffers( draw_command_buffer, 0, 1, vertex_buffers, offsets); vkCmdBindIndexBuffer( - draw_command_buffer, model->mesh->index_buffer->buffer, 0, + draw_command_buffer, static_mesh->index_buffer->buffer, 0, VK_INDEX_TYPE_UINT32); for(auto &instance: instances) { // Object matrix. - glm::mat4 instance_matrix{1.0f}; - instance_matrix = glm::translate( - instance_matrix, instance.position); - instance_matrix = glm::rotate( - instance_matrix, instance.rotation.x, glm::vec3{1.0, 0.0, 0.0}); - instance_matrix = glm::rotate( - instance_matrix, instance.rotation.y, glm::vec3{0.0, 1.0, 0.0}); - instance_matrix = glm::rotate( - instance_matrix, instance.rotation.z, glm::vec3{0.0, 0.0, 1.0}); - - ODOModelInstance model_instance{instance_matrix}; - vkCmdPushConstants( - draw_command_buffer, - cg_core.vk_graphics_pipeline_3d_layout->pipeline, - VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(ODOModelInstance), - &model_instance); + glm::mat4 base_matrix{1.0f}; + base_matrix = glm::translate(base_matrix, *instance->position); + base_matrix = glm::rotate( + base_matrix, instance->rotation->x, glm::vec3{1.0, 0.0, 0.0}); + base_matrix = glm::rotate( + base_matrix, instance->rotation->y, glm::vec3{0.0, 1.0, 0.0}); + base_matrix = glm::rotate( + base_matrix, instance->rotation->z, glm::vec3{0.0, 0.0, 1.0}); + + std::array<VkDescriptorSet, 3> vk_descriptor_sets{ + this->descriptor_sets_world[image_index], + view->descriptor_sets_3d[image_index], + instance->descriptor_sets[image_index]}; + + vkCmdBindDescriptorSets( + draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, + cg_core.vk_graphics_pipeline_3d_layout->pipeline, 0, + vk_descriptor_sets.size(), vk_descriptor_sets.data(), 0, nullptr); + vkCmdDrawIndexed( - draw_command_buffer, model->mesh->index_count, 1, 0, 0, 0); + draw_command_buffer, static_mesh->index_count, 1, 0, 0, 0); + + VK::ODOStaticModel odo_static_model{}; + odo_static_model.base_matrix = base_matrix; + instance->uniform_buffers[image_index].copy_data(&odo_static_model); } } @@ -627,6 +626,7 @@ GraphicsPipeline3D::draw( view->ub_3d[image_index].copy_data(&ubo_view_3d); } + // TODO: Do not update this for each view. All views use the same data. { // Update world uniform buffer ODOWorld3D_Vert ubo_world_3d_vert{}; ubo_world_3d_vert.ambient_light_color = glm::vec4{0.25, 0.25, 0.25, 1.0}; |