diff options
author | tcmal <me@aria.rip> | 2024-08-25 17:44:19 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-25 17:44:19 +0100 |
commit | 9d96c45d822b181d4ec145d6c73cf3a2da499c24 (patch) | |
tree | dcbe688ff8295cbd0122c89722bb0c44f393293b /stockton-render | |
parent | 2a90de8796c7d1d4ae8aa7f2c48f7a8b38dac387 (diff) |
fix(render): add vulkan context code
Diffstat (limited to 'stockton-render')
-rw-r--r-- | stockton-render/Cargo.toml | 2 | ||||
-rw-r--r-- | stockton-render/src/draw/context.rs | 31 |
2 files changed, 28 insertions, 5 deletions
diff --git a/stockton-render/Cargo.toml b/stockton-render/Cargo.toml index 99ac8e2..62c4742 100644 --- a/stockton-render/Cargo.toml +++ b/stockton-render/Cargo.toml @@ -13,7 +13,7 @@ nalgebra-glm = "0.4.0" shaderc = "0.5.0" [features] -default = [] +default = ["vulkan"] metal = ["gfx-backend-metal"] gl = ["gfx-backend-gl"] dx11 = ["gfx-backend-dx11"] diff --git a/stockton-render/src/draw/context.rs b/stockton-render/src/draw/context.rs index 9d54cae..489ddca 100644 --- a/stockton-render/src/draw/context.rs +++ b/stockton-render/src/draw/context.rs @@ -63,6 +63,15 @@ impl From<Tri2> for [f32; 15] { const TRI2_SIZE_F32: usize = 15; const TRI2_SIZE_BYTES: usize = size_of::<f32>() * TRI2_SIZE_F32; +#[cfg(not(feature = "gl"))] +type Instance = back::Instance; + +#[cfg(feature = "gl")] +type Instance = (); + +#[cfg(not(feature = "gl"))] +type WindowType = winit::Window; + /// Contains all the hal related stuff. /// In the end, this takes some 3D points and puts it on the screen. // TODO: Settings for clear colour, buffer sizes, etc @@ -70,6 +79,8 @@ pub struct RenderingContext { pub events_loop: winit::EventsLoop, surface: <Backend as hal::Backend>::Surface, + window: WindowType, + pub (crate) instance: ManuallyDrop<Instance>, pub (crate) device: ManuallyDrop<<Backend as hal::Backend>::Device>, swapchain: ManuallyDrop<<Backend as hal::Backend>::Swapchain>, @@ -110,9 +121,19 @@ impl RenderingContext { let wb = WindowBuilder::new(); // Create surface - // TODO: Vulkan version + #[cfg(not(feature = "gl"))] + let (window, instance, mut surface, mut adapters) = { + use hal::Instance; + let window = wb.build(&events_loop).map_err(|_| CreationError::WindowError)?; + let instance = back::Instance::create("stockton", 1); + let surface = instance.create_surface(&window); + let adapters = instance.enumerate_adapters(); + + (window, instance, surface, adapters) + }; + #[cfg(feature = "gl")] - let (mut surface, mut adapters) = { + let (window, instance, mut surface, mut adapters) = { let window = unsafe { let builder = back::config_context(glutin::ContextBuilder::new(), ColorFormat::SELF, None); @@ -124,7 +145,7 @@ impl RenderingContext { let surface = back::Surface::from_window(window); let adapters = surface.enumerate_adapters(); - (surface, adapters) + ((), (), surface, adapters) }; // TODO: Properly figure out which adapter to use @@ -277,7 +298,7 @@ impl RenderingContext { ).map_err(|e| CreationError::ImageViewError (e))?); framebuffers.push(device.create_framebuffer( &renderpass, - Some(imageviews[i]), + Some(&imageviews[i]), extent ).map_err(|_| CreationError::OutOfMemoryError)?); } @@ -290,6 +311,8 @@ impl RenderingContext { let (descriptor_set_layouts, pipeline_layout, pipeline) = Self::create_pipeline(&mut device, extent, &subpass)?; Ok(RenderingContext { + window, + instance: ManuallyDrop::new(instance), events_loop, surface, |