Вынес управление VkRenderPass в отдельный класс

This commit is contained in:
Jiga228
2026-06-24 12:10:47 +07:00
parent 93eb08fe9f
commit 2a57a30e29
9 changed files with 85 additions and 57 deletions
@@ -7,7 +7,7 @@ namespace VkObjects
{
class PhysicalDevice;
class Device
class Device final
{
VkDevice device_ = nullptr;
VkQueue graphics_queue_ = nullptr;
@@ -7,7 +7,7 @@ class CoreInstance;
namespace VkObjects
{
class Instance
class Instance final
{
VkInstance instance_ = nullptr;
@@ -9,7 +9,7 @@ namespace VkObjects
class Surface;
class Instance;
class PhysicalDevice
class PhysicalDevice final
{
public:
struct QueueFamilyIndices
@@ -0,0 +1,52 @@
#include "RenderPass.hpp"
#include "DeviceFunctions/DeviceFunctions.hpp"
#include "Swapchain.hpp"
#include "Device.hpp"
VkObjects::RenderPass::RenderPass(const Device& device, const Swapchain& swapchain):device_(device)
{
VkAttachmentDescription attachment_description{};
attachment_description.format = swapchain.get_image_format();
attachment_description.samples = VK_SAMPLE_COUNT_1_BIT;
attachment_description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
attachment_description.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
attachment_description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachment_description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachment_description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
attachment_description.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
VkAttachmentReference attachment_reference;
attachment_reference.attachment = 0;
attachment_reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkSubpassDescription subpass_description{};
subpass_description.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass_description.colorAttachmentCount = 1;
subpass_description.pColorAttachments = &attachment_reference;
VkSubpassDependency dependency{};
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
dependency.dstSubpass = 0;
dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
dependency.srcAccessMask = 0;
dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
VkRenderPassCreateInfo render_pass_info{};
render_pass_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
render_pass_info.attachmentCount = 1;
render_pass_info.pAttachments = &attachment_description;
render_pass_info.subpassCount = 1;
render_pass_info.pSubpasses = &subpass_description;
render_pass_info.dependencyCount = 1;
render_pass_info.pDependencies = &dependency;
VK_CHECK(vkCreateRenderPass(device_.get_native(), &render_pass_info, nullptr, &render_pass_))
}
VkObjects::RenderPass::~RenderPass()
{
if (render_pass_ != VK_NULL_HANDLE)
vkDestroyRenderPass(device_.get_native(), render_pass_, nullptr);
}
@@ -0,0 +1,20 @@
#pragma once
#include <vulkan/vulkan.h>
namespace VkObjects
{
class Swapchain;
class Device;
class RenderPass final
{
const Device& device_;
VkRenderPass render_pass_;
public:
explicit RenderPass(const Device& device, const Swapchain& swapchain);
~RenderPass();
inline VkRenderPass get_native() const { return render_pass_; }
};
}
@@ -8,7 +8,7 @@ namespace VkObjects
{
class Instance;
class Surface
class Surface final
{
VkSurfaceKHR surface_ = nullptr;
const Instance& instance_;
@@ -11,7 +11,7 @@ namespace VkObjects
class PhysicalDevice;
class Surface;
class Swapchain
class Swapchain final
{
struct SwapchainSupportDetails
{