summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/vk/graphics_pipeline_3d.cpp37
-rw-r--r--src/vk/graphics_pipeline_3d_skeletal.cpp36
-rw-r--r--src/vk/graphics_pipeline_sprite_3d.cpp19
-rw-r--r--src/vk/renderer.cpp55
4 files changed, 46 insertions, 101 deletions
diff --git a/src/vk/graphics_pipeline_3d.cpp b/src/vk/graphics_pipeline_3d.cpp
index 2b6812d..2a1fec1 100644
--- a/src/vk/graphics_pipeline_3d.cpp
+++ b/src/vk/graphics_pipeline_3d.cpp
@@ -259,24 +259,6 @@ GraphicsPipeline3D::draw(
std::shared_ptr<View3D> view, const VkCommandBuffer draw_command_buffer,
const size_t current_frame, const uint32_t image_index)
{
- { // Set viewport
- VkViewport vk_viewport{};
- vk_viewport.x = view->region.x;
- vk_viewport.y = view->region.y;
- vk_viewport.width = view->region.z;
- vk_viewport.height = view->region.w;
- vk_viewport.minDepth = 0.0f;
- vk_viewport.maxDepth = 1.0f;
- vkCmdSetViewport(draw_command_buffer, 0, 1, &vk_viewport);
-
- VkRect2D vk_scissor{};
- vk_scissor.offset.x = static_cast<int32_t>(view->region.x);
- vk_scissor.offset.y = static_cast<int32_t>(view->region.y);
- vk_scissor.extent.width = static_cast<uint32_t>(view->region.z);
- vk_scissor.extent.height = static_cast<uint32_t>(view->region.w);
- vkCmdSetScissor(draw_command_buffer, 0, 1, &vk_scissor);
- }
-
vkCmdBindPipeline(
draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
this->graphic_pipeline);
@@ -320,25 +302,6 @@ GraphicsPipeline3D::draw(
instance->uniform_buffers[image_index].copy_data(&udo_static_model);
}
}
-
- { // Update view uniform buffers
- VK::UDOView3D ubo_view_3d{};
-
- // View matrix.
- glm::mat4 translation_matrix{1.0f};
- translation_matrix = glm::translate(
- translation_matrix, *view->camera_position);
- glm::mat4 rotation_matrix{glm::toMat4(*view->camera_orientation)};
- ubo_view_3d.view = glm::inverse(translation_matrix * rotation_matrix);
-
- // Projection matrix.
- ubo_view_3d.proj = glm::perspective(
- glm::radians(view->field_of_view),
- view->region.z / view->region.w,
- 0.1f, 100.0f);
-
- view->ub_3d[image_index].copy_data(&ubo_view_3d);
- }
}
}
diff --git a/src/vk/graphics_pipeline_3d_skeletal.cpp b/src/vk/graphics_pipeline_3d_skeletal.cpp
index b000d89..6bd1713 100644
--- a/src/vk/graphics_pipeline_3d_skeletal.cpp
+++ b/src/vk/graphics_pipeline_3d_skeletal.cpp
@@ -269,24 +269,6 @@ GraphicsPipeline3DSkeletal::draw(
std::shared_ptr<View3D> view, const VkCommandBuffer draw_command_buffer,
const size_t current_frame, const uint32_t image_index)
{
- { // Set viewport
- VkViewport vk_viewport{};
- vk_viewport.x = view->region.x;
- vk_viewport.y = view->region.y;
- vk_viewport.width = view->region.z;
- vk_viewport.height = view->region.w;
- vk_viewport.minDepth = 0.0f;
- vk_viewport.maxDepth = 1.0f;
- vkCmdSetViewport(draw_command_buffer, 0, 1, &vk_viewport);
-
- VkRect2D vk_scissor{};
- vk_scissor.offset.x = static_cast<int32_t>(view->region.x);
- vk_scissor.offset.y = static_cast<int32_t>(view->region.y);
- vk_scissor.extent.width = static_cast<uint32_t>(view->region.z);
- vk_scissor.extent.height = static_cast<uint32_t>(view->region.w);
- vkCmdSetScissor(draw_command_buffer, 0, 1, &vk_scissor);
- }
-
vkCmdBindPipeline(
draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
this->graphic_pipeline);
@@ -335,24 +317,6 @@ GraphicsPipeline3DSkeletal::draw(
}
}
- { // Update view uniform buffers
- VK::UDOView3D ubo_view_3d{};
-
- // View matrix.
- glm::mat4 translation_matrix{1.0f};
- translation_matrix = glm::translate(
- translation_matrix, *view->camera_position);
- glm::mat4 rotation_matrix{glm::toMat4(*view->camera_orientation)};
- ubo_view_3d.view = glm::inverse(translation_matrix * rotation_matrix);
-
- // Projection matrix.
- ubo_view_3d.proj = glm::perspective(
- glm::radians(45.0f),
- view->region.z / view->region.w,
- 0.1f, 100.0f);
-
- view->ub_3d[image_index].copy_data(&ubo_view_3d);
- }
}
}
diff --git a/src/vk/graphics_pipeline_sprite_3d.cpp b/src/vk/graphics_pipeline_sprite_3d.cpp
index 577824a..0a4d520 100644
--- a/src/vk/graphics_pipeline_sprite_3d.cpp
+++ b/src/vk/graphics_pipeline_sprite_3d.cpp
@@ -268,25 +268,6 @@ GraphicsPipelineSprite3D::draw(
std::shared_ptr<View3D> view, const VkCommandBuffer draw_command_buffer,
const size_t current_frame, const uint32_t image_index)
{
- // TODO set viewport just once per view, not once per pipeline.
- { // Set viewport
- VkViewport vk_viewport{};
- vk_viewport.x = view->region.x;
- vk_viewport.y = view->region.y;
- vk_viewport.width = view->region.z;
- vk_viewport.height = view->region.w;
- vk_viewport.minDepth = 0.0f;
- vk_viewport.maxDepth = 1.0f;
- vkCmdSetViewport(draw_command_buffer, 0, 1, &vk_viewport);
-
- VkRect2D vk_scissor{};
- vk_scissor.offset.x = static_cast<int32_t>(view->region.x);
- vk_scissor.offset.y = static_cast<int32_t>(view->region.y);
- vk_scissor.extent.width = static_cast<uint32_t>(view->region.z);
- vk_scissor.extent.height = static_cast<uint32_t>(view->region.w);
- vkCmdSetScissor(draw_command_buffer, 0, 1, &vk_scissor);
- }
-
vkCmdBindPipeline(
draw_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
this->graphic_pipeline);
diff --git a/src/vk/renderer.cpp b/src/vk/renderer.cpp
index 21e0421..0f7f804 100644
--- a/src/vk/renderer.cpp
+++ b/src/vk/renderer.cpp
@@ -242,21 +242,58 @@ Renderer::draw()
draw_command_buffer, &render_pass_begin, VK_SUBPASS_CONTENTS_INLINE);
}
- for(auto &view: this->views_3d)
- cg_core.vk_graphics_pipeline_3d->draw(
- view, draw_command_buffer, cg_core.vk_swapchain->current_frame,
- image_index);
+ for(auto &view: this->views_3d)
+ {
+ { // Set viewport
+ VkViewport vk_viewport{};
+ vk_viewport.x = view->region.x;
+ vk_viewport.y = view->region.y;
+ vk_viewport.width = view->region.z;
+ vk_viewport.height = view->region.w;
+ vk_viewport.minDepth = 0.0f;
+ vk_viewport.maxDepth = 1.0f;
+ vkCmdSetViewport(draw_command_buffer, 0, 1, &vk_viewport);
+
+ VkRect2D vk_scissor{};
+ vk_scissor.offset.x = static_cast<int32_t>(view->region.x);
+ vk_scissor.offset.y = static_cast<int32_t>(view->region.y);
+ vk_scissor.extent.width = static_cast<uint32_t>(view->region.z);
+ vk_scissor.extent.height = static_cast<uint32_t>(view->region.w);
+ vkCmdSetScissor(draw_command_buffer, 0, 1, &vk_scissor);
+ }
+
+ cg_core.vk_graphics_pipeline_3d->draw(
+ view, draw_command_buffer, cg_core.vk_swapchain->current_frame,
+ image_index);
- for(auto &view: this->views_3d)
- cg_core.vk_graphics_pipeline_sprite_3d->draw(
- view, draw_command_buffer, cg_core.vk_swapchain->current_frame,
- image_index);
+ cg_core.vk_graphics_pipeline_sprite_3d->draw(
+ view, draw_command_buffer, cg_core.vk_swapchain->current_frame,
+ image_index);
- for(auto &view: this->views_3d)
cg_core.vk_graphics_pipeline_3d_skeletal->draw(
view, draw_command_buffer, cg_core.vk_swapchain->current_frame,
image_index);
+ { // Update view uniform buffers
+ VK::UDOView3D ubo_view_3d{};
+
+ // View matrix.
+ glm::mat4 translation_matrix{1.0f};
+ translation_matrix = glm::translate(
+ translation_matrix, *view->camera_position);
+ glm::mat4 rotation_matrix{glm::toMat4(*view->camera_orientation)};
+ ubo_view_3d.view = glm::inverse(translation_matrix * rotation_matrix);
+
+ // Projection matrix.
+ ubo_view_3d.proj = glm::perspective(
+ glm::radians(view->field_of_view),
+ view->region.z / view->region.w,
+ 0.1f, 100.0f);
+
+ view->ub_3d[image_index].copy_data(&ubo_view_3d);
+ }
+ }
+
vkCmdEndRenderPass(draw_command_buffer);
{ // 2D render pass