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 | |
parent | 2a90de8796c7d1d4ae8aa7f2c48f7a8b38dac387 (diff) |
fix(render): add vulkan context code
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | examples/render-triangles/Cargo.toml | 21 | ||||
-rw-r--r-- | stockton-render/Cargo.toml | 2 | ||||
-rw-r--r-- | stockton-render/src/draw/context.rs | 31 |
4 files changed, 34 insertions, 21 deletions
@@ -8,4 +8,5 @@ members = [ [patch.crates-io] gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx" } +gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx" } gfx-hal = { git = "https://github.com/gfx-rs/gfx" }
\ No newline at end of file diff --git a/examples/render-triangles/Cargo.toml b/examples/render-triangles/Cargo.toml index dd2c189..59d6e19 100644 --- a/examples/render-triangles/Cargo.toml +++ b/examples/render-triangles/Cargo.toml @@ -4,6 +4,11 @@ version = "0.1.0" authors = ["Oscar <oscar.shrimpton.personal@gmail.com>"] edition = "2018" +[features] +default = [] +gl = ["stockton-render/gl"] +vulkan = ["stockton-render/vulkan"] + [dependencies] stockton-render = { path = "../../stockton-render" } stockton-types = { path = "../../stockton-types" } @@ -12,19 +17,3 @@ winit = "0.19.1" log = "0.4.0" simple_logger = "1.0" rand = "0.7" - -[target.'cfg(feature = "gl")'.dependencies.stockton-render] -path = "../../stockton-render" -features = ["gl"] - -# [target.'cfg(feature = "dx11")'.dependencies.stockton-render] -# path = "../../stockton-render" -# features = ["dx11"] - -# [target.'cfg(feature = "dx12")'.dependencies.stockton-render] -# path = "../../stockton-render" -# features = ["dx12"] - -# [target.'cfg(feature = "vulkan")'.dependencies.stockton-render] -# path = "../../stockton-render" -# features = ["vulkan"]
\ No newline at end of file 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, |