Skip to content

Commit a0a9ea6

Browse files
committed
[update] internal surface implementations.
1 parent 4b95b57 commit a0a9ea6

4 files changed

Lines changed: 22 additions & 60 deletions

File tree

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,10 @@ impl<'command_pool, RenderBackend: gfx_hal::Backend>
157157
frame_buffer.internal_frame_buffer(),
158158
viewport.internal_viewport().rect,
159159
vec![gfx_hal::command::RenderAttachmentInfo::<RenderBackend> {
160-
image_view: super::surface::internal::borrow_surface_image_for(
161-
&surface,
162-
)
163-
.unwrap()
164-
.borrow(),
160+
image_view: surface
161+
.internal_surface_image()
162+
.expect("No internal surface set when beginning the render pass.")
163+
.borrow(),
165164
clear_value: ClearValue {
166165
color: gfx_hal::command::ClearColor {
167166
float32: [0.0, 0.0, 0.0, 1.0],

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ impl FramebufferBuilder {
4646
render_pass: &RenderPass<RenderBackend>,
4747
surface: &Surface<RenderBackend>,
4848
) -> Framebuffer<RenderBackend> {
49-
use super::surface::internal::frame_buffer_attachment_from;
50-
5149
let (width, height) = surface.size().expect("A surface without a swapchain cannot be used in a framebeen configured with a swapchain");
52-
let image = frame_buffer_attachment_from(surface).unwrap();
50+
let image = surface
51+
.internal_frame_buffer_attachment()
52+
.expect("A surface without a swapchain cannot be used in a frame.");
5353

5454
let frame_buffer = unsafe {
5555
gpu

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ impl<RenderBackend: gfx_hal::Backend> Gpu<RenderBackend> {
152152
surface: &mut surface::Surface<RenderBackend>,
153153
semaphore: &mut RenderSemaphore<RenderBackend>,
154154
) -> Result<(), &str> {
155-
let (render_surface, render_image) =
156-
super::surface::internal::borrow_surface_and_take_image(surface);
155+
let (render_surface, render_image) = surface.internal_surface_and_image();
157156

158157
let result = unsafe {
159158
self.queue_group.queues[0].present(

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

Lines changed: 14 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -264,64 +264,28 @@ impl<RenderBackend: Backend> Surface<RenderBackend> {
264264
.unwrap_or(&gfx_hal::format::Format::Rgba8Srgb)
265265
.clone();
266266
}
267-
}
268-
269-
/// Internal functions to work with the gfx-hal surface components
270-
pub mod internal {
271-
use gfx_hal::window::{
272-
PresentationSurface,
273-
Surface as _,
274-
};
275267

276-
/// Helper function to retrieve the first supported format given a physical
277-
/// GPU device.
278-
pub fn get_first_supported_format<RenderBackend: gfx_hal::Backend>(
279-
surface: &super::Surface<RenderBackend>,
280-
physical_device: &RenderBackend::PhysicalDevice,
281-
) -> gfx_hal::format::Format {
282-
let supported_formats = surface.get_supported_formats(physical_device);
283-
284-
let default_format = *supported_formats
285-
.get(0)
286-
.unwrap_or(&gfx_hal::format::Format::Rgba8Srgb);
287-
288-
return supported_formats
289-
.into_iter()
290-
.find(|format| -> bool {
291-
format.base_format().1 == gfx_hal::format::ChannelType::Srgb
292-
})
293-
.unwrap_or(default_format);
294-
}
295-
296-
/// Acquires a surface image for attaching to a framebuffer.
297-
pub fn take_surface_image_for<RenderBackend: gfx_hal::Backend>(
298-
surface: &mut super::Surface<RenderBackend>,
299-
) -> Option<<RenderBackend::Surface as PresentationSurface<RenderBackend>>::SwapchainImage>{
300-
return surface.image.take();
301-
}
302-
303-
/// Acquires a surface image for attaching to a framebuffer.
304-
pub fn borrow_surface_image_for<RenderBackend: gfx_hal::Backend>(
305-
surface: &super::Surface<RenderBackend>,
268+
pub(super) fn internal_surface_image(
269+
&self,
306270
) -> Option<&<RenderBackend::Surface as PresentationSurface<RenderBackend>>::SwapchainImage>{
307-
return surface.image.as_ref();
271+
return self.image.as_ref();
308272
}
309273

310-
/// FrameBuffer Attachment
311-
pub fn frame_buffer_attachment_from<RenderBackend: gfx_hal::Backend>(
312-
surface: &super::Surface<RenderBackend>,
274+
pub(super) fn internal_frame_buffer_attachment(
275+
&self,
313276
) -> Option<gfx_hal::image::FramebufferAttachment> {
314-
return surface.frame_buffer_attachment.clone();
277+
return self.frame_buffer_attachment.clone();
315278
}
316279

317-
/// Borrow the surface and take the image. This internal function is used for
318-
/// rendering and composes surface_for + take image.
319-
pub fn borrow_surface_and_take_image<RenderBackend: gfx_hal::Backend>(
320-
surface: &mut super::Surface<RenderBackend>,
321-
) -> (&mut RenderBackend::Surface, <RenderBackend::Surface as PresentationSurface<RenderBackend>>::SwapchainImage){
280+
pub(super) fn internal_surface_and_image(
281+
&mut self,
282+
) -> (
283+
&mut RenderBackend::Surface,
284+
<RenderBackend::Surface as PresentationSurface<RenderBackend>>::SwapchainImage,
285+
){
322286
return (
323-
&mut surface.gfx_hal_surface,
324-
surface.image.take().expect("Surface image is not present"),
287+
&mut self.gfx_hal_surface,
288+
self.image.take().expect("Surface image is not present"),
325289
);
326290
}
327291
}

0 commit comments

Comments
 (0)