Skip to content

Commit 2dd2d8b

Browse files
committed
[update] Instance implementation.
1 parent dd8badf commit 2dd2d8b

3 files changed

Lines changed: 31 additions & 41 deletions

File tree

crates/lambda-platform/src/gfx/gpu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl GpuBuilder {
4949
) -> Result<Gpu<RenderBackend>, String> {
5050
match (surface, self.render_queue_type) {
5151
(Some(surface), RenderQueueType::Graphical) => {
52-
let adapter = super::internal::get_adapter(instance, 0);
52+
let adapter = instance.first_adapter();
5353

5454
let queue_family = adapter
5555
.queue_families

crates/lambda-platform/src/gfx/mod.rs

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,55 +54,45 @@ impl<RenderBackend: internal::Backend> Instance<RenderBackend> {
5454
}
5555
}
5656

57-
// ----------------------- INTERNAL INSTANCE OPERATIONS ------------------------
58-
59-
pub mod internal {
60-
use gfx_hal::{
61-
adapter::Adapter,
62-
Instance as _,
63-
};
57+
impl<RenderBackend: internal::Backend> Instance<RenderBackend> {
58+
/// Returns a list of all available adapters.
59+
pub(super) fn enumerate_adapters(
60+
&self,
61+
) -> Vec<gfx_hal::adapter::Adapter<RenderBackend>> {
62+
return self.gfx_hal_instance.enumerate_adapters();
63+
}
6464

65-
pub use super::{
66-
pipeline::internal::*,
67-
shader::internal::*,
68-
Instance,
69-
};
65+
pub(super) fn first_adapter(
66+
&self,
67+
) -> gfx_hal::adapter::Adapter<RenderBackend> {
68+
return self.gfx_hal_instance.enumerate_adapters().remove(0);
69+
}
7070

71-
/// Helper function to create a low level gfx_hal surface. Not meant to be
72-
/// used outside of lambda-platform.
73-
#[inline]
74-
pub fn create_surface<RenderBackend: gfx_hal::Backend>(
75-
instance: &Instance<RenderBackend>,
71+
pub(super) fn create_surface(
72+
&self,
7673
window_handle: &crate::winit::WindowHandle,
7774
) -> RenderBackend::Surface {
78-
unsafe {
79-
let surface = instance
75+
return unsafe {
76+
self
8077
.gfx_hal_instance
8178
.create_surface(&window_handle.window_handle)
82-
.expect("Failed to create a surface using the current instance and window handle.");
83-
84-
return surface;
79+
.expect("Failed to create a surface using the current instance and window handle.")
8580
};
8681
}
8782

88-
/// Destroy a low level gfx_hal surface using the instance abstraction.
89-
pub fn destroy_surface<RenderBackend: gfx_hal::Backend>(
90-
instance: &Instance<RenderBackend>,
91-
surface: RenderBackend::Surface,
92-
) {
83+
pub(super) fn destroy_surface(&self, surface: RenderBackend::Surface) {
9384
unsafe {
94-
instance.gfx_hal_instance.destroy_surface(surface);
85+
self.gfx_hal_instance.destroy_surface(surface);
9586
}
9687
}
88+
}
9789

98-
/// Returns a graphical adapter from an instance.
99-
pub fn get_adapter<RenderBackend: gfx_hal::Backend>(
100-
instance: &mut Instance<RenderBackend>,
101-
adapter_num: usize,
102-
) -> Adapter<RenderBackend> {
103-
return instance
104-
.gfx_hal_instance
105-
.enumerate_adapters()
106-
.remove(adapter_num);
107-
}
90+
// ----------------------- INTERNAL INSTANCE OPERATIONS ------------------------
91+
92+
pub mod internal {
93+
94+
pub use super::{
95+
pipeline::internal::*,
96+
shader::internal::*,
97+
};
10898
}

crates/lambda-platform/src/gfx/surface.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl SurfaceBuilder {
3636
instance: &super::Instance<RenderBackend>,
3737
window: &crate::winit::WindowHandle,
3838
) -> Surface<RenderBackend> {
39-
let gfx_hal_surface = super::internal::create_surface(instance, window);
39+
let gfx_hal_surface = instance.create_surface(window);
4040
let name = match self.name {
4141
Some(name) => name,
4242
None => "RenderSurface".to_string(),
@@ -137,7 +137,7 @@ impl<RenderBackend: gfx_hal::Backend> Surface<RenderBackend> {
137137
pub fn destroy(self, instance: &Instance<RenderBackend>) {
138138
println!("Destroying the surface: {}", self.name);
139139

140-
super::internal::destroy_surface(&instance, self.gfx_hal_surface);
140+
instance.destroy_surface(self.gfx_hal_surface);
141141
}
142142

143143
/// Get the size of the surface's extent. Will only return a size if a

0 commit comments

Comments
 (0)