summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core.cpp22
-rw-r--r--src/core.hpp2
-rw-r--r--src/vk/framebuffer.cpp198
-rw-r--r--src/vk/framebuffer.hpp43
-rw-r--r--src/vk/graphics_pipeline_2d_solid.cpp40
-rw-r--r--src/vk/graphics_pipeline_2d_solid.hpp7
-rw-r--r--src/vk/graphics_pipeline_2d_wired.cpp40
-rw-r--r--src/vk/graphics_pipeline_2d_wired.hpp3
-rw-r--r--src/vk/graphics_pipeline_3d.cpp117
-rw-r--r--src/vk/graphics_pipeline_3d.hpp7
-rw-r--r--src/vk/graphics_pipeline_3d_skeletal.cpp117
-rw-r--r--src/vk/graphics_pipeline_3d_skeletal.hpp7
-rw-r--r--src/vk/renderer.cpp5
13 files changed, 268 insertions, 340 deletions
diff --git a/src/core.cpp b/src/core.cpp
index 0197e97..591eaba 100644
--- a/src/core.cpp
+++ b/src/core.cpp
@@ -525,6 +525,25 @@ unload_vk_swapchain(void *obj)
}
void
+load_vk_framebuffer(void *obj)
+{
+ try
+ {
+ cg_core.vk_framebuffer = new VK::Framebuffer();
+ }
+ catch(const CommandError &e)
+ {
+ throw CommandError{"Failed to create framebuffer."};
+ }
+}
+
+void
+unload_vk_framebuffer(void *obj)
+{
+ delete cg_core.vk_framebuffer;
+}
+
+void
load_vk_render_pass(void *obj)
{
try
@@ -533,7 +552,7 @@ load_vk_render_pass(void *obj)
}
catch(const CommandError &e)
{
- throw CommandError{"Failed to create descriptor set layouts."};
+ throw CommandError{"Failed to create render pass."};
}
}
@@ -786,6 +805,7 @@ const CommandChain cg_sCore::loader{
{&load_vk_swapchain, &unload_vk_swapchain},
{&load_vk_render_pass, &unload_vk_render_pass},
+ {&load_vk_framebuffer, &unload_vk_framebuffer},
{&load_vk_descriptor_set_layout, &unload_vk_descriptor_set_layout},
{&load_vk_graphics_pipeline_3d_layout,
&unload_vk_graphics_pipeline_3d_layout},
diff --git a/src/core.hpp b/src/core.hpp
index 917920b..9566a52 100644
--- a/src/core.hpp
+++ b/src/core.hpp
@@ -50,6 +50,7 @@
#include "vk/device.hpp"
#include "vk/descriptor_set_layout.hpp"
#include "vk/render_pass.hpp"
+#include "vk/framebuffer.hpp"
#include "vk/graphics_pipeline_2d_solid_layout.hpp"
#include "vk/graphics_pipeline_2d_wired_layout.hpp"
#include "vk/light.hpp"
@@ -120,6 +121,7 @@ struct cg_sCore
VK::Device *vk_device_with_swapchain;
VK::Swapchain *vk_swapchain;
+ VK::Framebuffer *vk_framebuffer;
VK::RenderPass *vk_render_pass;
VK::DescriptorSetLayout *vk_descriptor_set_layout;
VK::GraphicsPipeline3DLayout *vk_graphics_pipeline_3d_layout;
diff --git a/src/vk/framebuffer.cpp b/src/vk/framebuffer.cpp
new file mode 100644
index 0000000..4104554
--- /dev/null
+++ b/src/vk/framebuffer.cpp
@@ -0,0 +1,198 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "framebuffer.hpp"
+
+#include "../core.hpp"
+#include "image.hpp"
+
+namespace
+{
+void
+load_depth_image(void *obj)
+{
+ auto self = static_cast<VK::Framebuffer*>(obj);
+
+ VkExtent3D extent3d{};
+ extent3d.width = cg_core.display_width;
+ extent3d.height = cg_core.display_height;
+ extent3d.depth = 1;
+
+ try
+ {
+ VK::Image::create(
+ cg_core.vk_device_with_swapchain,
+ &self->depth_image,
+ &self->depth_image_memory,
+ VK_FORMAT_D32_SFLOAT,
+ extent3d,
+ 1,
+ VK_IMAGE_TILING_OPTIMAL,
+ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
+ );
+ }
+ catch(VK::Image::Error error)
+ {
+ std::string error_message{"Failed to create depth image → "};
+ error_message += error.what();
+ throw CommandError{error_message};
+ }
+}
+
+void
+unload_depth_image(void *obj)
+{
+ auto self = static_cast<VK::Framebuffer*>(obj);
+
+ vkDestroyImage(
+ cg_core.vk_device_with_swapchain->device, self->depth_image,
+ nullptr);
+ vkFreeMemory(
+ cg_core.vk_device_with_swapchain->device,
+ self->depth_image_memory, nullptr);
+}
+
+void
+load_depth_image_view(void *obj)
+{
+ auto self = static_cast<VK::Framebuffer*>(obj);
+
+ try
+ {
+ VK::Image::create_view(
+ cg_core.vk_device_with_swapchain, &self->depth_image_view,
+ self->depth_image,
+ VK_FORMAT_D32_SFLOAT, VK_IMAGE_ASPECT_DEPTH_BIT);
+ }
+ catch(VK::Image::Error error)
+ {
+ std::string error_message{"Failed to create depth image view → "};
+ error_message += error.what();
+ throw CommandError{error_message};
+ }
+}
+
+void
+unload_depth_image_view(void *obj)
+{
+ auto self = static_cast<VK::Framebuffer*>(obj);
+
+ vkDestroyImageView(
+ cg_core.vk_device_with_swapchain->device, self->depth_image_view, nullptr);
+}
+
+void
+load_3d(void *obj)
+{
+ auto self = static_cast<VK::Framebuffer*>(obj);
+
+ self->pipeline_3d.resize(cg_core.vk_swapchain->images_count);
+ for (auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
+ {
+ std::array<VkImageView, 2> attachments = {
+ cg_core.vk_swapchain->image_views[i],
+ self->depth_image_view
+ };
+
+ VkFramebufferCreateInfo framebuffer_info{};
+ framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
+ framebuffer_info.renderPass = cg_core.vk_render_pass->pipeline_3d;
+ framebuffer_info.attachmentCount = attachments.size();
+ framebuffer_info.pAttachments = attachments.data();
+ framebuffer_info.width = cg_core.display_width;
+ framebuffer_info.height = cg_core.display_height;
+
+ framebuffer_info.layers = 1;
+
+ if(vkCreateFramebuffer(
+ cg_core.vk_device_with_swapchain->device, &framebuffer_info, nullptr,
+ &self->pipeline_3d[i]) != VK_SUCCESS)
+ throw CommandError{"Failed to create Vulkan Framebuffer."};
+ }
+}
+
+void
+unload_3d(void *obj)
+{
+ auto self = static_cast<VK::Framebuffer*>(obj);
+
+ for(auto framebuffer: self->pipeline_3d)
+ vkDestroyFramebuffer(
+ cg_core.vk_device_with_swapchain->device, framebuffer, nullptr);
+}
+
+void
+load_2d(void *obj)
+{
+ auto self = static_cast<VK::Framebuffer*>(obj);
+
+ self->pipeline_2d.resize(cg_core.vk_swapchain->images_count);
+ for (auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
+ {
+ std::array<VkImageView, 1> attachments = {
+ cg_core.vk_swapchain->image_views[i]
+ };
+
+ VkFramebufferCreateInfo framebuffer_info{};
+ framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
+ framebuffer_info.renderPass = cg_core.vk_render_pass->pipeline_2d;
+ framebuffer_info.attachmentCount = attachments.size();
+ framebuffer_info.pAttachments = attachments.data();
+ framebuffer_info.width = cg_core.display_width;
+ framebuffer_info.height = cg_core.display_height;
+ framebuffer_info.layers = 1;
+
+ if(vkCreateFramebuffer(
+ cg_core.vk_device_with_swapchain->device, &framebuffer_info, nullptr,
+ &self->pipeline_2d[i])
+ != VK_SUCCESS)
+ throw CommandError{"Failed to create Vulkan Framebuffer."};
+ }
+}
+
+void
+unload_2d(void *obj)
+{
+ auto self = static_cast<VK::Framebuffer*>(obj);
+
+ for(auto framebuffer: self->pipeline_2d)
+ vkDestroyFramebuffer(
+ cg_core.vk_device_with_swapchain->device, framebuffer, nullptr);
+}
+
+const CommandChain loader{
+ {&load_depth_image, &unload_depth_image},
+ {&load_depth_image_view, &unload_depth_image_view},
+ {&load_3d, &unload_3d},
+ {&load_2d, &unload_2d}
+};
+
+}
+
+namespace VK
+{
+
+Framebuffer::Framebuffer()
+{
+ loader.execute(this);
+}
+
+Framebuffer::~Framebuffer()
+{
+ loader.revert(this);
+}
+
+}
diff --git a/src/vk/framebuffer.hpp b/src/vk/framebuffer.hpp
new file mode 100644
index 0000000..2867fa1
--- /dev/null
+++ b/src/vk/framebuffer.hpp
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CANDY_GEAR_VK_FRAMEBUFFER_H
+#define CANDY_GEAR_VK_FRAMEBUFFER_H 1
+
+#include <vector>
+
+#include "core.hpp"
+
+namespace VK
+{
+
+struct Framebuffer
+{
+ // Depth image.
+ VkImage depth_image;
+ VkDeviceMemory depth_image_memory;
+ VkImageView depth_image_view;
+
+ std::vector<VkFramebuffer> pipeline_3d;
+ std::vector<VkFramebuffer> pipeline_2d;
+
+ Framebuffer();
+ ~Framebuffer();
+};
+
+}
+
+#endif /* CANDY_GEAR_VK_FRAMEBUFFER_H */
diff --git a/src/vk/graphics_pipeline_2d_solid.cpp b/src/vk/graphics_pipeline_2d_solid.cpp
index 8432a8a..d0c1768 100644
--- a/src/vk/graphics_pipeline_2d_solid.cpp
+++ b/src/vk/graphics_pipeline_2d_solid.cpp
@@ -26,45 +26,6 @@ namespace
{
void
-load_framebuffer(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline2DSolid*>(obj);
-
- self->swapchain_framebuffers.resize(cg_core.vk_swapchain->images_count);
- for (auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
- {
- std::array<VkImageView, 1> attachments = {
- cg_core.vk_swapchain->image_views[i]
- };
-
- VkFramebufferCreateInfo framebuffer_info{};
- framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
- framebuffer_info.renderPass = cg_core.vk_render_pass->pipeline_2d;
- framebuffer_info.attachmentCount = attachments.size();
- framebuffer_info.pAttachments = attachments.data();
- framebuffer_info.width = cg_core.display_width;
- framebuffer_info.height = cg_core.display_height;
- framebuffer_info.layers = 1;
-
- if(vkCreateFramebuffer(
- cg_core.vk_device_with_swapchain->device, &framebuffer_info, nullptr,
- &self->swapchain_framebuffers[i])
- != VK_SUCCESS)
- throw CommandError{"Failed to create Vulkan Framebuffer."};
- }
-}
-
-void
-unload_framebuffer(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline2DSolid*>(obj);
-
- for(auto framebuffer: self->swapchain_framebuffers)
- vkDestroyFramebuffer(
- cg_core.vk_device_with_swapchain->device, framebuffer, nullptr);
-}
-
-void
load_pipeline(void *obj)
{
auto self = static_cast<VK::GraphicsPipeline2DSolid*>(obj);
@@ -253,7 +214,6 @@ unload_pipeline(void *obj)
}
const CommandChain loader{
- {&load_framebuffer, &unload_framebuffer},
{&load_pipeline, &unload_pipeline}
};
diff --git a/src/vk/graphics_pipeline_2d_solid.hpp b/src/vk/graphics_pipeline_2d_solid.hpp
index ec3c744..eac825f 100644
--- a/src/vk/graphics_pipeline_2d_solid.hpp
+++ b/src/vk/graphics_pipeline_2d_solid.hpp
@@ -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.
@@ -18,11 +18,9 @@
#define CANDY_GEAR_VK_GRAPHICS_PIPELINE_2D_SOLID_H 1
#include <memory>
-#include <unordered_map>
-#include <vector>
#include "core.hpp"
-#include "sprite.hpp"
+#include "command_pool.hpp"
#include "view_2d.hpp"
namespace VK
@@ -30,7 +28,6 @@ namespace VK
struct GraphicsPipeline2DSolid
{
- std::vector<VkFramebuffer> swapchain_framebuffers;
VkPipeline graphic_pipeline;
GraphicsPipeline2DSolid();
diff --git a/src/vk/graphics_pipeline_2d_wired.cpp b/src/vk/graphics_pipeline_2d_wired.cpp
index 6590508..ef43cd1 100644
--- a/src/vk/graphics_pipeline_2d_wired.cpp
+++ b/src/vk/graphics_pipeline_2d_wired.cpp
@@ -53,45 +53,6 @@ unload_indexes(void *obj)
}
void
-load_framebuffer(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline2DWired*>(obj);
-
- self->swapchain_framebuffers.resize(
- cg_core.vk_swapchain->images_count);
- for (auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
- {
- std::array<VkImageView, 1> attachments = {
- cg_core.vk_swapchain->image_views[i]
- };
-
- VkFramebufferCreateInfo framebuffer_info{};
- framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
- framebuffer_info.renderPass = cg_core.vk_render_pass->pipeline_2d;
- framebuffer_info.attachmentCount = attachments.size();
- framebuffer_info.pAttachments = attachments.data();
- framebuffer_info.width = cg_core.display_width;
- framebuffer_info.height = cg_core.display_height;
- framebuffer_info.layers = 1;
-
- if(vkCreateFramebuffer(
- cg_core.vk_device_with_swapchain->device, &framebuffer_info, nullptr,
- &self->swapchain_framebuffers[i]) != VK_SUCCESS)
- throw CommandError{"Failed to create Vulkan Framebuffer."};
- }
-}
-
-void
-unload_framebuffer(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline2DWired*>(obj);
-
- for(auto framebuffer: self->swapchain_framebuffers)
- vkDestroyFramebuffer(
- cg_core.vk_device_with_swapchain->device, framebuffer, nullptr);
-}
-
-void
load_pipeline(void *obj)
{
auto self = static_cast<VK::GraphicsPipeline2DWired*>(obj);
@@ -265,7 +226,6 @@ unload_pipeline(void *obj)
const CommandChain loader{
{&load_indexes, &unload_indexes},
- {&load_framebuffer, &unload_framebuffer},
{&load_pipeline, &unload_pipeline}
};
diff --git a/src/vk/graphics_pipeline_2d_wired.hpp b/src/vk/graphics_pipeline_2d_wired.hpp
index 8c7765d..932ed61 100644
--- a/src/vk/graphics_pipeline_2d_wired.hpp
+++ b/src/vk/graphics_pipeline_2d_wired.hpp
@@ -18,8 +18,6 @@
#define CANDY_GEAR_VK_GRAPHICS_PIPELINE_2D_WIRED_H 1
#include <memory>
-#include <unordered_map>
-#include <vector>
#include "core.hpp"
#include "view_2d.hpp"
@@ -31,7 +29,6 @@ struct GraphicsPipeline2DWired
{
QueueFamily *queue_family;
- std::vector<VkFramebuffer> swapchain_framebuffers;
VkPipeline graphic_pipeline;
DestinationBuffer *index_buffer;
diff --git a/src/vk/graphics_pipeline_3d.cpp b/src/vk/graphics_pipeline_3d.cpp
index a98db2c..43ab734 100644
--- a/src/vk/graphics_pipeline_3d.cpp
+++ b/src/vk/graphics_pipeline_3d.cpp
@@ -21,7 +21,6 @@
#include "../core.hpp"
#include "core.hpp"
-#include "image.hpp"
#include "static_mesh_vertex.hpp"
#include "uniform_data_object.hpp"
@@ -29,119 +28,6 @@ namespace
{
void
-load_depth_image(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline3D*>(obj);
-
- VkExtent3D extent3d{};
- extent3d.width = cg_core.display_width;
- extent3d.height = cg_core.display_height;
- extent3d.depth = 1;
-
- try
- {
- VK::Image::create(
- cg_core.vk_device_with_swapchain,
- &self->depth_image,
- &self->depth_image_memory,
- VK_FORMAT_D32_SFLOAT,
- extent3d,
- 1,
- VK_IMAGE_TILING_OPTIMAL,
- VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
- );
- }
- catch(VK::Image::Error error)
- {
- std::string error_message{"Failed to create depth image → "};
- error_message += error.what();
- throw CommandError{error_message};
- }
-}
-
-void
-unload_depth_image(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline3D*>(obj);
-
- vkDestroyImage(
- cg_core.vk_device_with_swapchain->device, self->depth_image,
- nullptr);
- vkFreeMemory(
- cg_core.vk_device_with_swapchain->device,
- self->depth_image_memory, nullptr);
-}
-
-void
-load_depth_image_view(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline3D*>(obj);
-
- try
- {
- VK::Image::create_view(
- cg_core.vk_device_with_swapchain, &self->depth_image_view,
- self->depth_image,
- VK_FORMAT_D32_SFLOAT, VK_IMAGE_ASPECT_DEPTH_BIT);
- }
- catch(VK::Image::Error error)
- {
- std::string error_message{"Failed to create depth image view → "};
- error_message += error.what();
- throw CommandError{error_message};
- }
-}
-
-void
-unload_depth_image_view(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline3D*>(obj);
-
- vkDestroyImageView(
- cg_core.vk_device_with_swapchain->device, self->depth_image_view, nullptr);
-}
-
-void
-load_framebuffer(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline3D*>(obj);
-
- self->swapchain_framebuffers.resize(cg_core.vk_swapchain->images_count);
- for (auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
- {
- std::array<VkImageView, 2> attachments = {
- cg_core.vk_swapchain->image_views[i],
- self->depth_image_view
- };
-
- VkFramebufferCreateInfo framebuffer_info{};
- framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
- framebuffer_info.renderPass = cg_core.vk_render_pass->pipeline_3d;
- framebuffer_info.attachmentCount = attachments.size();
- framebuffer_info.pAttachments = attachments.data();
- framebuffer_info.width = cg_core.display_width;
- framebuffer_info.height = cg_core.display_height;
-
- framebuffer_info.layers = 1;
-
- if(vkCreateFramebuffer(
- cg_core.vk_device_with_swapchain->device, &framebuffer_info, nullptr,
- &self->swapchain_framebuffers[i]) != VK_SUCCESS)
- throw CommandError{"Failed to create Vulkan Framebuffer."};
- }
-}
-
-void
-unload_framebuffer(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline3D*>(obj);
-
- for(auto framebuffer: self->swapchain_framebuffers)
- vkDestroyFramebuffer(
- cg_core.vk_device_with_swapchain->device, framebuffer, nullptr);
-}
-
-void
load_pipeline(void *obj)
{
auto self = static_cast<VK::GraphicsPipeline3D*>(obj);
@@ -350,9 +236,6 @@ unload_pipeline(void *obj)
}
const CommandChain loader{
- {&load_depth_image, &unload_depth_image},
- {&load_depth_image_view, &unload_depth_image_view},
- {&load_framebuffer, &unload_framebuffer},
{&load_pipeline, &unload_pipeline}
};
diff --git a/src/vk/graphics_pipeline_3d.hpp b/src/vk/graphics_pipeline_3d.hpp
index af09d28..bfe034d 100644
--- a/src/vk/graphics_pipeline_3d.hpp
+++ b/src/vk/graphics_pipeline_3d.hpp
@@ -18,7 +18,6 @@
#define CANDY_GEAR_VK_GRAPHICS_PIPELINE_3D_H 1
#include <memory>
-#include <unordered_map>
#include "core.hpp"
#include "command_pool.hpp"
@@ -29,12 +28,6 @@ namespace VK
struct GraphicsPipeline3D
{
- // Depth image.
- VkImage depth_image;
- VkDeviceMemory depth_image_memory;
- VkImageView depth_image_view;
-
- std::vector<VkFramebuffer> swapchain_framebuffers;
VkPipeline graphic_pipeline;
GraphicsPipeline3D();
diff --git a/src/vk/graphics_pipeline_3d_skeletal.cpp b/src/vk/graphics_pipeline_3d_skeletal.cpp
index 3386352..e0e75a9 100644
--- a/src/vk/graphics_pipeline_3d_skeletal.cpp
+++ b/src/vk/graphics_pipeline_3d_skeletal.cpp
@@ -21,7 +21,6 @@
#include "../core.hpp"
#include "core.hpp"
-#include "image.hpp"
#include "skeletal_mesh_vertex.hpp"
#include "uniform_data_object.hpp"
@@ -29,119 +28,6 @@ namespace
{
void
-load_depth_image(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline3DSkeletal*>(obj);
-
- VkExtent3D extent3d{};
- extent3d.width = cg_core.display_width;
- extent3d.height = cg_core.display_height;
- extent3d.depth = 1;
-
- try
- {
- VK::Image::create(
- cg_core.vk_device_with_swapchain,
- &self->depth_image,
- &self->depth_image_memory,
- VK_FORMAT_D32_SFLOAT,
- extent3d,
- 1,
- VK_IMAGE_TILING_OPTIMAL,
- VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
- );
- }
- catch(VK::Image::Error error)
- {
- std::string error_message{"Failed to create depth image → "};
- error_message += error.what();
- throw CommandError{error_message};
- }
-}
-
-void
-unload_depth_image(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline3DSkeletal*>(obj);
-
- vkDestroyImage(
- cg_core.vk_device_with_swapchain->device, self->depth_image,
- nullptr);
- vkFreeMemory(
- cg_core.vk_device_with_swapchain->device,
- self->depth_image_memory, nullptr);
-}
-
-void
-load_depth_image_view(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline3DSkeletal*>(obj);
-
- try
- {
- VK::Image::create_view(
- cg_core.vk_device_with_swapchain, &self->depth_image_view,
- self->depth_image,
- VK_FORMAT_D32_SFLOAT, VK_IMAGE_ASPECT_DEPTH_BIT);
- }
- catch(VK::Image::Error error)
- {
- std::string error_message{"Failed to create depth image view → "};
- error_message += error.what();
- throw CommandError{error_message};
- }
-}
-
-void
-unload_depth_image_view(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline3DSkeletal*>(obj);
-
- vkDestroyImageView(
- cg_core.vk_device_with_swapchain->device, self->depth_image_view, nullptr);
-}
-
-void
-load_framebuffer(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline3DSkeletal*>(obj);
-
- self->swapchain_framebuffers.resize(cg_core.vk_swapchain->images_count);
- for (auto i{0}; i < cg_core.vk_swapchain->images_count; i++)
- {
- std::array<VkImageView, 2> attachments = {
- cg_core.vk_swapchain->image_views[i],
- self->depth_image_view
- };
-
- VkFramebufferCreateInfo framebuffer_info{};
- framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
- framebuffer_info.renderPass = cg_core.vk_render_pass->pipeline_3d;
- framebuffer_info.attachmentCount = attachments.size();
- framebuffer_info.pAttachments = attachments.data();
- framebuffer_info.width = cg_core.display_width;
- framebuffer_info.height = cg_core.display_height;
-
- framebuffer_info.layers = 1;
-
- if(vkCreateFramebuffer(
- cg_core.vk_device_with_swapchain->device, &framebuffer_info, nullptr,
- &self->swapchain_framebuffers[i]) != VK_SUCCESS)
- throw CommandError{"Failed to create Vulkan Framebuffer."};
- }
-}
-
-void
-unload_framebuffer(void *obj)
-{
- auto self = static_cast<VK::GraphicsPipeline3DSkeletal*>(obj);
-
- for(auto framebuffer: self->swapchain_framebuffers)
- vkDestroyFramebuffer(
- cg_core.vk_device_with_swapchain->device, framebuffer, nullptr);
-}
-
-void
load_pipeline(void *obj)
{
auto self = static_cast<VK::GraphicsPipeline3DSkeletal*>(obj);
@@ -360,9 +246,6 @@ unload_pipeline(void *obj)
}
const CommandChain loader{
- {&load_depth_image, &unload_depth_image},
- {&load_depth_image_view, &unload_depth_image_view},
- {&load_framebuffer, &unload_framebuffer},
{&load_pipeline, &unload_pipeline}
};
diff --git a/src/vk/graphics_pipeline_3d_skeletal.hpp b/src/vk/graphics_pipeline_3d_skeletal.hpp
index fa9226a..027b42e 100644
--- a/src/vk/graphics_pipeline_3d_skeletal.hpp
+++ b/src/vk/graphics_pipeline_3d_skeletal.hpp
@@ -18,7 +18,6 @@
#define CANDY_GEAR_VK_GRAPHICS_PIPELINE_3D_SKELETAL_H 1
#include <memory>
-#include <unordered_map>
#include "core.hpp"
#include "command_pool.hpp"
@@ -29,12 +28,6 @@ namespace VK
struct GraphicsPipeline3DSkeletal
{
- // Depth image.
- VkImage depth_image;
- VkDeviceMemory depth_image_memory;
- VkImageView depth_image_view;
-
- std::vector<VkFramebuffer> swapchain_framebuffers;
VkPipeline graphic_pipeline;
GraphicsPipeline3DSkeletal();
diff --git a/src/vk/renderer.cpp b/src/vk/renderer.cpp
index 3497db9..766690f 100644
--- a/src/vk/renderer.cpp
+++ b/src/vk/renderer.cpp
@@ -229,7 +229,7 @@ Renderer::draw()
render_pass_begin.pNext = nullptr;
render_pass_begin.renderPass = cg_core.vk_render_pass->pipeline_3d;
render_pass_begin.framebuffer =
- cg_core.vk_graphics_pipeline_3d->swapchain_framebuffers[image_index];
+ cg_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),
@@ -254,8 +254,7 @@ Renderer::draw()
render_pass_begin.pNext = nullptr;
render_pass_begin.renderPass = cg_core.vk_render_pass->pipeline_2d;
render_pass_begin.framebuffer =
- cg_core.vk_graphics_pipeline_2d_solid->swapchain_framebuffers[
- image_index];
+ cg_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),