Skip to content

Commit 9948be4

Browse files
committed
[update] the surface size to use a tuple.
1 parent 579d666 commit 9948be4

3 files changed

Lines changed: 12 additions & 18 deletions

File tree

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
use std::borrow::Borrow;
2-
31
use gfx_hal::{
42
device::Device,
5-
image::{
6-
Extent,
7-
FramebufferAttachment,
8-
},
3+
image::Extent,
94
};
105

116
use super::{
@@ -43,6 +38,7 @@ impl FramebufferBuilder {
4338
return Self {};
4439
}
4540

41+
/// Build a frame buffer on a given GPU for the given surface.
4642
pub fn build<RenderBackend: gfx_hal::Backend>(
4743
self,
4844
gpu: &mut Gpu<RenderBackend>,
@@ -51,7 +47,7 @@ impl FramebufferBuilder {
5147
) -> Framebuffer<RenderBackend> {
5248
use super::surface::internal::frame_buffer_attachment_from;
5349

54-
let [width, height] = surface.size().expect("A surface without a swapchain cannot be used in a framebeen configured with a swapchain");
50+
let (width, height) = surface.size().expect("A surface without a swapchain cannot be used in a framebeen configured with a swapchain");
5551
let image = frame_buffer_attachment_from(surface).unwrap();
5652

5753
let frame_buffer = unsafe {

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ impl<RenderBackend: gfx_hal::Backend> Surface<RenderBackend> {
238238

239239
/// Get the size of the surface's extent. Will only return a size if a
240240
/// swapchain has been applied to the surface to render with.
241-
pub fn size(&self) -> Option<[u32; 2]> {
241+
pub fn size(&self) -> Option<(u32, u32)> {
242242
return match self.extent {
243-
Some(extent) => Some([extent.width, extent.height]),
243+
Some(extent) => Some((extent.width, extent.height)),
244244
None => None,
245245
};
246246
}
@@ -249,16 +249,16 @@ impl<RenderBackend: gfx_hal::Backend> Surface<RenderBackend> {
249249
// ------------------------------ SWAPCHAIN BUILDER ----------------------------
250250

251251
pub struct SwapchainBuilder {
252-
size: [u32; 2],
252+
size: (u32, u32),
253253
}
254254

255255
impl SwapchainBuilder {
256256
pub fn new() -> Self {
257-
return Self { size: [480, 360] };
257+
return Self { size: (480, 360) };
258258
}
259259

260260
pub fn with_size(mut self, width: u32, height: u32) -> Self {
261-
self.size = [width, height];
261+
self.size = (width, height);
262262
return self;
263263
}
264264

@@ -270,14 +270,12 @@ impl SwapchainBuilder {
270270
let physical_device = super::gpu::internal::physical_device_for(gpu);
271271
let caps = surface.gfx_hal_surface.capabilities(physical_device);
272272
let format = internal::get_first_supported_format(surface, physical_device);
273+
let (width, height) = self.size;
273274

274275
let mut swapchain_config = gfx_hal::window::SwapchainConfig::from_caps(
275276
&caps,
276277
format,
277-
gfx_hal::window::Extent2D {
278-
width: self.size[0],
279-
height: self.size[1],
280-
},
278+
gfx_hal::window::Extent2D { width, height },
281279
);
282280

283281
// TODO(vmarcella) Profile the performance on MacOS to see if this slows

lambda/src/core/render/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,13 @@ impl RenderContext {
264264

265265
/// Allocates a command buffer and records commands to the GPU.
266266
pub fn render(&mut self, commands: Vec<RenderCommand>) {
267-
let dimensions = self
267+
let (width, height) = self
268268
.surface
269269
.size()
270270
.expect("Surface has no size configured.");
271271

272272
let swapchain = SwapchainBuilder::new()
273-
.with_size(dimensions[0], dimensions[1])
273+
.with_size(width, height)
274274
.build(&self.gpu, &self.surface);
275275

276276
Rc::get_mut(&mut self.surface)

0 commit comments

Comments
 (0)