Vulkan: Use references in Swapchain.

This commit is contained in:
BearOso 2024-10-03 14:32:55 -05:00
parent 08403d47d1
commit 14c434d40d
2 changed files with 15 additions and 13 deletions

View File

@ -5,12 +5,13 @@ namespace Vulkan
{ {
Swapchain::Swapchain(Context &context_) Swapchain::Swapchain(Context &context_)
: context(context_) : context(context_),
device(context.device),
queue(context.queue),
physical_device(context.physical_device),
command_pool(context.command_pool.get()),
surface(context.surface.get())
{ {
device = context.device;
queue = context.queue;
physical_device = context.physical_device;
command_pool = context.command_pool.get();
create_render_pass(); create_render_pass();
end_render_pass_function = nullptr; end_render_pass_function = nullptr;
} }
@ -76,7 +77,7 @@ void Swapchain::create_render_pass()
.setDependencies(subpass_dependency) .setDependencies(subpass_dependency)
.setAttachments(attachment_description); .setAttachments(attachment_description);
render_pass = context.device.createRenderPassUnique(render_pass_create_info).value; render_pass = device.createRenderPassUnique(render_pass_create_info).value;
} }
bool Swapchain::recreate() bool Swapchain::recreate()
@ -122,7 +123,7 @@ bool Swapchain::check_and_resize(int width, int height)
if (width == -1 && height == -1) if (width == -1 && height == -1)
{ {
surface_capabilities = physical_device.getSurfaceCapabilitiesKHR(context.surface.get()).value; surface_capabilities = physical_device.getSurfaceCapabilitiesKHR(surface).value;
width = surface_capabilities.currentExtent.width; width = surface_capabilities.currentExtent.width;
height = surface_capabilities.currentExtent.height; height = surface_capabilities.currentExtent.height;
} }
@ -154,7 +155,7 @@ bool Swapchain::create()
frames.clear(); frames.clear();
image_data.clear(); image_data.clear();
auto surface_capabilities = physical_device.getSurfaceCapabilitiesKHR(context.surface.get()).value; auto surface_capabilities = physical_device.getSurfaceCapabilitiesKHR(surface).value;
if (desired_latency == - 1 || (int)surface_capabilities.minImageCount > desired_latency) if (desired_latency == - 1 || (int)surface_capabilities.minImageCount > desired_latency)
num_swapchain_images = surface_capabilities.minImageCount; num_swapchain_images = surface_capabilities.minImageCount;
@ -210,7 +211,7 @@ bool Swapchain::create()
.setCompositeAlpha(vk::CompositeAlphaFlagBitsKHR::eOpaque) .setCompositeAlpha(vk::CompositeAlphaFlagBitsKHR::eOpaque)
.setClipped(true) .setClipped(true)
.setPresentMode(get_present_mode()) .setPresentMode(get_present_mode())
.setSurface(context.surface.get()) .setSurface(surface)
.setPreTransform(vk::SurfaceTransformFlagBitsKHR::eIdentity) .setPreTransform(vk::SurfaceTransformFlagBitsKHR::eIdentity)
.setImageArrayLayers(1) .setImageArrayLayers(1)
.setQueueFamilyIndices(graphics_queue_index); .setQueueFamilyIndices(graphics_queue_index);

View File

@ -79,10 +79,11 @@ class Swapchain
std::vector<ImageData> image_data; std::vector<ImageData> image_data;
Vulkan::Context &context; Vulkan::Context &context;
vk::Device device; vk::SurfaceKHR &surface;
vk::CommandPool command_pool; vk::Device &device;
vk::PhysicalDevice physical_device; vk::CommandPool &command_pool;
vk::Queue queue; vk::PhysicalDevice &physical_device;
vk::Queue &queue;
}; };
} // namespace Vulkan } // namespace Vulkan