summaryrefslogtreecommitdiff
path: root/src/vk/graphics_pipeline_3d.cpp
diff options
context:
space:
mode:
authorFrederico Linhares <fred@linhares.blue>2023-01-12 15:23:16 -0300
committerFrederico Linhares <fred@linhares.blue>2023-01-12 15:23:16 -0300
commit704858045b4f7defb977adb8344ae4428cd02081 (patch)
treea21dfcdbd7836b0a55bdeaf99001e615ada98e0a /src/vk/graphics_pipeline_3d.cpp
parent62367a0bcca75c45eb3e7d1582c4fff18827ddc7 (diff)
refa Use Push constants for 3D models
Diffstat (limited to 'src/vk/graphics_pipeline_3d.cpp')
-rw-r--r--src/vk/graphics_pipeline_3d.cpp57
1 files changed, 25 insertions, 32 deletions
diff --git a/src/vk/graphics_pipeline_3d.cpp b/src/vk/graphics_pipeline_3d.cpp
index f915c00..4eacc9d 100644
--- a/src/vk/graphics_pipeline_3d.cpp
+++ b/src/vk/graphics_pipeline_3d.cpp
@@ -538,8 +538,7 @@ GraphicsPipeline3D::draw(
std::shared_ptr<View3D> view, const VkCommandBuffer draw_command_buffer,
const size_t current_frame, const uint32_t image_index)
{
- // Set viewport
- {
+ { // Set viewport
VkViewport vk_viewport{};
vk_viewport.x = view->region.x;
vk_viewport.y = view->region.y;
@@ -561,8 +560,6 @@ GraphicsPipeline3D::draw(
for(auto& [model, instances]:
cg_core.vk_renderer->models_to_draw[current_frame])
{
- // Commands
- {
std::array<VkDescriptorSet, 3> vk_descriptor_sets{
this->descriptor_sets_world[image_index],
view->descriptor_sets_3d[image_index],
@@ -582,34 +579,31 @@ GraphicsPipeline3D::draw(
vkCmdBindIndexBuffer(
draw_command_buffer, model->mesh->index_buffer->buffer, 0,
VK_INDEX_TYPE_UINT32);
- vkCmdDrawIndexed(
- draw_command_buffer, model->mesh->index_count, instances.size(),
- 0, 0, 0);
- }
-
- VK::ODOModelInstance ubo_model_instance;
-
- for(int i{0}; i < instances.size(); i++)
- {
- // Object matrix.
- glm::mat4 instance_matrix{1.0f};
- instance_matrix = glm::translate(
- instance_matrix, instances[i].position);
- instance_matrix = glm::rotate(
- instance_matrix, instances[i].rotation.x, glm::vec3{1.0, 0.0, 0.0});
- instance_matrix = glm::rotate(
- instance_matrix, instances[i].rotation.y, glm::vec3{0.0, 1.0, 0.0});
- instance_matrix = glm::rotate(
- instance_matrix, instances[i].rotation.z, glm::vec3{0.0, 0.0, 1.0});
-
- ubo_model_instance.instances[i] = instance_matrix;
- }
-
- model->ub_model_instance[image_index].copy_data(&ubo_model_instance);
+
+ 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);
+ vkCmdDrawIndexed(
+ draw_command_buffer, model->mesh->index_count, 1, 0, 0, 0);
+ }
}
- // Update view uniform buffers
- {
+ { // Update view uniform buffers
VK::ODOView3D ubo_view_3d{};
// View matrix.
@@ -633,8 +627,7 @@ GraphicsPipeline3D::draw(
view->ub_3d[image_index].copy_data(&ubo_view_3d);
}
- // Update world uniform buffer
- {
+ { // 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};
this->ub_world_vert[image_index].copy_data(&ubo_world_3d_vert);