summaryrefslogtreecommitdiff
path: root/src/blucat/renderer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/blucat/renderer.cpp')
-rw-r--r--src/blucat/renderer.cpp120
1 files changed, 62 insertions, 58 deletions
diff --git a/src/blucat/renderer.cpp b/src/blucat/renderer.cpp
index 75822e0..5777203 100644
--- a/src/blucat/renderer.cpp
+++ b/src/blucat/renderer.cpp
@@ -18,7 +18,7 @@
#include <array>
-#include "../core.hpp"
+#include "core.hpp"
#include "uniform_data_object.hpp"
namespace
@@ -48,7 +48,7 @@ load_descriptor_pool(void *obj)
pool_info.pPoolSizes = &descriptor_pool_size;
if(vkCreateDescriptorPool(
- cg_core.vk_device_with_swapchain->device, &pool_info, nullptr,
+ BluCat::core.vk_device_with_swapchain->device, &pool_info, nullptr,
&self->descriptor_pool) != VK_SUCCESS)
throw CommandError{"Failed to create a Vulkan descriptor pool."};
@@ -67,7 +67,7 @@ unload_descriptor_pool(void *obj)
for(auto &view : self->views_2d) view->unload_descriptor_sets();
vkDestroyDescriptorPool(
- cg_core.vk_device_with_swapchain->device, self->descriptor_pool,
+ BluCat::core.vk_device_with_swapchain->device, self->descriptor_pool,
nullptr);
}
@@ -77,7 +77,7 @@ load_queue_family(void *obj)
auto self = static_cast<BluCat::Renderer*>(obj);
self->queue_family =
- cg_core.vk_device_with_swapchain->get_queue_family_with_presentation();
+ BluCat::core.vk_device_with_swapchain->get_queue_family_with_presentation();
}
void
@@ -101,9 +101,9 @@ unload_command_pool(void *obj)
{
auto self = static_cast<BluCat::Renderer*>(obj);
- vkWaitForFences(cg_core.vk_device_with_swapchain->device,
+ vkWaitForFences(BluCat::core.vk_device_with_swapchain->device,
BluCat::Swapchain::max_frames_in_flight,
- cg_core.vk_swapchain->in_flight_fences.data(), VK_TRUE,
+ BluCat::core.vk_swapchain->in_flight_fences.data(), VK_TRUE,
std::numeric_limits<uint64_t>::max());
vkDestroyCommandPool(
self->queue_family->device->device, self->command_pool, nullptr);
@@ -144,9 +144,9 @@ namespace BluCat
Renderer::Renderer(std::vector<std::shared_ptr<View2D>> views_2d,
std::vector<std::shared_ptr<View3D>> views_3d):
- skeletal_models_to_draw{cg_core.vk_swapchain->images_count},
- static_models_to_draw{cg_core.vk_swapchain->images_count},
- sprites_3d_to_draw{cg_core.vk_swapchain->images_count},
+ skeletal_models_to_draw{BluCat::core.vk_swapchain->images_count},
+ static_models_to_draw{BluCat::core.vk_swapchain->images_count},
+ sprites_3d_to_draw{BluCat::core.vk_swapchain->images_count},
views_2d{views_2d},
views_3d{views_3d}
{
@@ -168,28 +168,29 @@ void
Renderer::draw()
{
auto fence_status = vkGetFenceStatus(
- cg_core.vk_device_with_swapchain->device,
- cg_core.vk_swapchain->in_flight_fences[
- cg_core.vk_swapchain->current_frame]);
+ BluCat::core.vk_device_with_swapchain->device,
+ BluCat::core.vk_swapchain->in_flight_fences[
+ BluCat::core.vk_swapchain->current_frame]);
if(fence_status == VK_SUCCESS)
{
- auto next_frame = cg_core.vk_swapchain->current_frame + 1;
+ auto next_frame = BluCat::core.vk_swapchain->current_frame + 1;
if(next_frame == Swapchain::max_frames_in_flight) next_frame = 0;
- vkResetFences(cg_core.vk_device_with_swapchain->device, 1,
- &cg_core.vk_swapchain->in_flight_fences[
- cg_core.vk_swapchain->current_frame]);
+ vkResetFences(core.vk_device_with_swapchain->device, 1,
+ &BluCat::core.vk_swapchain->in_flight_fences[
+ BluCat::core.vk_swapchain->current_frame]);
uint32_t image_index;
vkAcquireNextImageKHR(
- cg_core.vk_device_with_swapchain->device,
- cg_core.vk_swapchain->swapchain, std::numeric_limits<uint64_t>::max(),
- cg_core.vk_swapchain->image_available_semaphores[
- cg_core.vk_swapchain->current_frame], VK_NULL_HANDLE, &image_index);
+ BluCat::core.vk_device_with_swapchain->device,
+ BluCat::core.vk_swapchain->swapchain,
+ std::numeric_limits<uint64_t>::max(),
+ BluCat::core.vk_swapchain->image_available_semaphores[
+ BluCat::core.vk_swapchain->current_frame], VK_NULL_HANDLE, &image_index);
VkCommandBuffer draw_command_buffer =
- this->draw_command_buffers[cg_core.vk_swapchain->current_frame];
+ this->draw_command_buffers[BluCat::core.vk_swapchain->current_frame];
vkResetCommandBuffer(draw_command_buffer, 0);
// Begin command buffer.
@@ -213,7 +214,7 @@ Renderer::draw()
UDOWorld3D_Vert ubo_world_3d_vert{};
ubo_world_3d_vert.ambient_light_color =
glm::vec4{0.25, 0.25, 0.25, 1.0};
- cg_core.vk_light->ub_world_vert[image_index].copy_data(
+ BluCat::core.vk_light->ub_world_vert[image_index].copy_data(
&ubo_world_3d_vert);
UDOWorld3D_Frag ubo_world_3d_frag{};
@@ -221,20 +222,20 @@ Renderer::draw()
glm::vec3{-0.57735, 0.57735, -0.57735};
ubo_world_3d_frag.directional_light_color =
glm::vec4{0.8, 0.8, 0.8, 1.0};
- cg_core.vk_light->ub_world_frag[image_index].copy_data(
+ BluCat::core.vk_light->ub_world_frag[image_index].copy_data(
&ubo_world_3d_frag);
}
VkRenderPassBeginInfo render_pass_begin{};
render_pass_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
render_pass_begin.pNext = nullptr;
- render_pass_begin.renderPass = cg_core.vk_render_pass->pipeline_3d;
+ render_pass_begin.renderPass = BluCat::core.vk_render_pass->pipeline_3d;
render_pass_begin.framebuffer =
- cg_core.vk_framebuffer->pipeline_3d[image_index];
+ BluCat::core.vk_framebuffer->pipeline_3d[image_index];
render_pass_begin.renderArea.offset = {0, 0};
render_pass_begin.renderArea.extent = {
- static_cast<uint32_t>(cg_core.display_width),
- static_cast<uint32_t>(cg_core.display_height)};
+ static_cast<uint32_t>(BluCat::core.display_width),
+ static_cast<uint32_t>(BluCat::core.display_height)};
render_pass_begin.clearValueCount = clear_values.size();
render_pass_begin.pClearValues = clear_values.data();
@@ -262,16 +263,16 @@ Renderer::draw()
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,
+ BluCat::core.vk_graphics_pipeline_3d->draw(
+ view, draw_command_buffer, BluCat::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,
+ BluCat::core.vk_graphics_pipeline_sprite_3d->draw(
+ view, draw_command_buffer, BluCat::core.vk_swapchain->current_frame,
image_index);
- cg_core.vk_graphics_pipeline_3d_skeletal->draw(
- view, draw_command_buffer, cg_core.vk_swapchain->current_frame,
+ BluCat::core.vk_graphics_pipeline_3d_skeletal->draw(
+ view, draw_command_buffer, BluCat::core.vk_swapchain->current_frame,
image_index);
{ // Update view uniform buffers
@@ -300,13 +301,13 @@ Renderer::draw()
VkRenderPassBeginInfo render_pass_begin{};
render_pass_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
render_pass_begin.pNext = nullptr;
- render_pass_begin.renderPass = cg_core.vk_render_pass->pipeline_2d;
+ render_pass_begin.renderPass = BluCat::core.vk_render_pass->pipeline_2d;
render_pass_begin.framebuffer =
- cg_core.vk_framebuffer->pipeline_2d[image_index];
+ BluCat::core.vk_framebuffer->pipeline_2d[image_index];
render_pass_begin.renderArea.offset = {0, 0};
render_pass_begin.renderArea.extent = {
- static_cast<uint32_t>(cg_core.display_width),
- static_cast<uint32_t>(cg_core.display_height)};
+ static_cast<uint32_t>(BluCat::core.display_width),
+ static_cast<uint32_t>(BluCat::core.display_height)};
render_pass_begin.clearValueCount = 0;
render_pass_begin.pClearValues = nullptr;
@@ -317,25 +318,25 @@ Renderer::draw()
{ // 2D solid drawing
for(auto &view: this->views_2d)
- cg_core.vk_graphics_pipeline_2d_solid->draw(
- view, draw_command_buffer, cg_core.vk_swapchain->current_frame,
+ BluCat::core.vk_graphics_pipeline_2d_solid->draw(
+ view, draw_command_buffer, BluCat::core.vk_swapchain->current_frame,
next_frame, image_index);
for(auto &view: this->views_3d)
- cg_core.vk_graphics_pipeline_2d_solid->draw(
- view, draw_command_buffer, cg_core.vk_swapchain->current_frame,
+ BluCat::core.vk_graphics_pipeline_2d_solid->draw(
+ view, draw_command_buffer, BluCat::core.vk_swapchain->current_frame,
next_frame, image_index);
}
{ // 2D wired drawing
for(auto &view: this->views_2d)
- cg_core.vk_graphics_pipeline_2d_wired->draw(
- view, draw_command_buffer, cg_core.vk_swapchain->current_frame,
+ BluCat::core.vk_graphics_pipeline_2d_wired->draw(
+ view, draw_command_buffer, BluCat::core.vk_swapchain->current_frame,
next_frame, image_index);
for(auto &view: this->views_3d)
- cg_core.vk_graphics_pipeline_2d_wired->draw(
- view, draw_command_buffer, cg_core.vk_swapchain->current_frame,
+ BluCat::core.vk_graphics_pipeline_2d_wired->draw(
+ view, draw_command_buffer, BluCat::core.vk_swapchain->current_frame,
next_frame, image_index);
}
@@ -350,13 +351,13 @@ Renderer::draw()
auto queue{this->queue_family->get_queue()};
VkSemaphore wait_semaphores[]{
- cg_core.vk_swapchain->image_available_semaphores[
- cg_core.vk_swapchain->current_frame]};
+ BluCat::core.vk_swapchain->image_available_semaphores[
+ BluCat::core.vk_swapchain->current_frame]};
VkPipelineStageFlags wait_stages[] =
{VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT};
VkSemaphore signal_semaphores[]{
- cg_core.vk_swapchain->render_finished_semaphores[
- cg_core.vk_swapchain->current_frame]};
+ BluCat::core.vk_swapchain->render_finished_semaphores[
+ BluCat::core.vk_swapchain->current_frame]};
VkSubmitInfo submit_info{};
submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
@@ -370,11 +371,11 @@ Renderer::draw()
submit_info.pSignalSemaphores = signal_semaphores;
if(vkQueueSubmit(
- queue.queue, 1, &submit_info, cg_core.vk_swapchain->in_flight_fences[
- cg_core.vk_swapchain->current_frame]) != VK_SUCCESS)
+ queue.queue, 1, &submit_info, BluCat::core.vk_swapchain->in_flight_fences[
+ BluCat::core.vk_swapchain->current_frame]) != VK_SUCCESS)
throw std::runtime_error{"Failed to submit draw command buffer."};
- VkSwapchainKHR swap_chains[]{cg_core.vk_swapchain->swapchain};
+ VkSwapchainKHR swap_chains[]{BluCat::core.vk_swapchain->swapchain};
VkPresentInfoKHR present_info{};
present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
@@ -394,19 +395,22 @@ Renderer::draw()
this->skeletal_models_to_draw[next_frame].clear();
this->static_models_to_draw[next_frame].clear();
this->sprites_3d_to_draw[next_frame].clear();
- cg_core.vk_swapchain->current_frame = next_frame;
+ BluCat::core.vk_swapchain->current_frame = next_frame;
}
}
else
{
// Clear images for the current frame because we are skipping this frame.
- this->skeletal_models_to_draw[cg_core.vk_swapchain->current_frame].clear();
- this->static_models_to_draw[cg_core.vk_swapchain->current_frame].clear();
- this->sprites_3d_to_draw[cg_core.vk_swapchain->current_frame].clear();
+ this->skeletal_models_to_draw[
+ BluCat::core.vk_swapchain->current_frame].clear();
+ this->static_models_to_draw[
+ BluCat::core.vk_swapchain->current_frame].clear();
+ this->sprites_3d_to_draw[
+ BluCat::core.vk_swapchain->current_frame].clear();
for(auto &view: this->views_2d)
- view->sprites_to_draw[cg_core.vk_swapchain->current_frame].clear();
+ view->sprites_to_draw[BluCat::core.vk_swapchain->current_frame].clear();
for(auto &view: this->views_3d)
- view->sprites_to_draw[cg_core.vk_swapchain->current_frame].clear();
+ view->sprites_to_draw[BluCat::core.vk_swapchain->current_frame].clear();
}
}