rust_vulkan_test/src/vulkan/vk_surface.rs
Florian RICHER caa79270db
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s
Refactor
2024-11-12 13:25:52 +01:00

66 lines
No EOL
1.9 KiB
Rust

use crate::vulkan::{VkPhysicalDevice, LOG_TARGET};
use ash::prelude::VkResult;
use ash::vk;
pub struct VkSurface {
surface_loader: ash::khr::surface::Instance,
surface: vk::SurfaceKHR,
}
impl VkSurface {
pub fn new(
surface_loader: ash::khr::surface::Instance,
surface: vk::SurfaceKHR,
) -> Self {
Self {
surface_loader,
surface,
}
}
pub fn physical_device_queue_supported(&self, physical_device: &VkPhysicalDevice, queue_index: u32) -> VkResult<bool> {
unsafe {
self.surface_loader.get_physical_device_surface_support(
physical_device.handle,
queue_index,
self.surface,
)
}
}
pub fn get_physical_device_surface_formats(&self, physical_device: &VkPhysicalDevice) -> VkResult<Vec<vk::SurfaceFormatKHR>> {
unsafe {
self.surface_loader.get_physical_device_surface_formats(
physical_device.handle,
self.surface,
)
}
}
pub fn get_physical_device_surface_capabilities(&self, physical_device: &VkPhysicalDevice) -> VkResult<vk::SurfaceCapabilitiesKHR> {
unsafe {
self.surface_loader.get_physical_device_surface_capabilities(
physical_device.handle,
self.surface,
)
}
}
pub fn get_physical_device_surface_present_modes(&self, physical_device: &VkPhysicalDevice) -> VkResult<Vec<vk::PresentModeKHR>> {
unsafe {
self.surface_loader.get_physical_device_surface_present_modes(
physical_device.handle,
self.surface,
)
}
}
}
impl Drop for VkSurface {
fn drop(&mut self) {
unsafe {
self.surface_loader.destroy_surface(self.surface, None);
}
log::debug!(target: LOG_TARGET, "Surface destroyed");
}
}