Skip to content

Commit 8129e89

Browse files
committed
[update] events to include the instant they were issued at alongside a new structure, refactor some of the events.
1 parent b96f1a8 commit 8129e89

7 files changed

Lines changed: 125 additions & 190 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ impl FramebufferBuilder {
4949
render_pass: &RenderPass<RenderBackend>,
5050
surface: &Surface<RenderBackend>,
5151
) -> Framebuffer<RenderBackend> {
52+
use super::surface::internal::frame_buffer_attachment_from;
53+
5254
let [width, height] = surface.size().expect("A surface without a swapchain cannot be used in a framebeen configured with a swapchain");
53-
let image =
54-
super::surface::internal::frame_buffer_attachment_from(surface).unwrap();
55+
let image = frame_buffer_attachment_from(surface).unwrap();
5556

5657
let frame_buffer = unsafe {
5758
super::gpu::internal::logical_device_for(gpu)

lambda/src/core/events.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1-
/// Lambda specific events.
2-
pub enum LambdaEvents {
3-
Attach,
4-
Detach,
5-
}
1+
use std::time::Instant;
62

73
pub enum ComponentEvent {
84
Attached { name: String },
95
Detached { name: String },
106
}
117

12-
/// Generic Event Enum
13-
pub enum Event {
14-
Lambda(LambdaEvents),
15-
ComponentEvent(ComponentEvent),
8+
pub enum WindowEvent {
9+
Close,
10+
Resize { width: u32, height: u32 },
11+
}
12+
13+
pub enum KernelEvent {
1614
Initialized,
1715
Shutdown,
18-
Resized { new_width: u32, new_height: u32 },
16+
}
17+
18+
/// Generic Event Enum which encapsulates all possible events that will be emitted
19+
/// by the LambdaKernel
20+
pub enum Events {
21+
Component {
22+
event: ComponentEvent,
23+
issued_at: Instant,
24+
},
25+
Window {
26+
event: WindowEvent,
27+
issued_at: Instant,
28+
},
29+
Kernel {
30+
event: KernelEvent,
31+
issued_at: Instant,
32+
},
1933
}

lambda/src/core/render/command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
use lambda_platform::gfx::viewport::ViewPort as PlatformViewPort;
77

88
use super::{
9-
internal::surface_for_context,
9+
internal::surface_from_context,
1010
PlatformRenderCommand,
1111
RenderContext,
1212
};
@@ -68,7 +68,7 @@ impl RenderCommand {
6868
render_pass,
6969
viewport,
7070
} => {
71-
let surface = surface_for_context(render_context);
71+
let surface = surface_from_context(render_context);
7272
let render_pass = render_pass.into_gfx_render_pass();
7373
let frame_buffer =
7474
render_context.allocate_and_get_frame_buffer(render_pass.as_ref());

lambda/src/core/render/mod.rs

Lines changed: 2 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ pub mod viewport;
66
pub mod window;
77

88
pub mod internal {
9-
use std::{
10-
borrow::Borrow,
11-
rc::Rc,
12-
};
9+
use std::rc::Rc;
1310

1411
use lambda_platform::gfx::api::RenderingAPI as RenderContext;
1512
pub type RenderBackend = RenderContext::Backend;
@@ -64,7 +61,7 @@ pub mod internal {
6461
}
6562

6663
/// Gets the surface for the given render context.
67-
pub fn surface_for_context(
64+
pub fn surface_from_context(
6865
context: &super::RenderContext,
6966
) -> Rc<Surface<RenderBackend>> {
7067
return context.surface.clone();
@@ -300,110 +297,3 @@ impl RenderContext {
300297
}
301298

302299
type PlatformRenderCommand = Command<internal::RenderBackend>;
303-
304-
// TODO(vmarcella): This process could use a more consistent abstraction
305-
// for getting a pipeline created.
306-
// let assembler = create_vertex_assembler(vertex_entry);
307-
// let pipeline_layout = self.gpu.create_pipeline_layout();
308-
// let mut logical_pipeline = gfx::pipeline::create_graphics_pipeline(
309-
// assembler,
310-
// &pipeline_layout,
311-
// render_pass,
312-
// Some(fragment_entry),
313-
// );
314-
315-
// let physical_pipeline =
316-
// self.gpu.create_graphics_pipeline(&mut logical_pipeline);
317-
318-
// return (vertex_module, pipeline_layout, physical_pipeline);
319-
320-
// let render_pass = self.gpu.create_render_pass(None, None, None);
321-
322-
// let (module, pipeline_layout, pipeline) =
323-
// self.create_gpu_pipeline(vertex_shader, fragment_shader, &render_pass);
324-
// self.gpu.destroy_shader_module(module);
325-
// self.pipeline_layouts = Some(vec![pipeline_layout]);
326-
// self.graphic_pipelines = Some(vec![pipeline]);
327-
328-
// let surface = self.surface.as_mut().unwrap();
329-
330-
// let acquire_timeout_ns = 1_000_000_000;
331-
// let image = unsafe {
332-
// let i = match surface.acquire_image(acquire_timeout_ns) {
333-
// Ok((image, _)) => Some(image),
334-
// Err(_) => None,
335-
// };
336-
// i.unwrap()
337-
// };
338-
339-
// TODO(vmarcella): This code will fail if there are no render passes
340-
// attached to the renderer.
341-
342-
// TODO(vmarcella): Investigate into abstracting the viewport behind a
343-
// camera.
344-
// let viewport = {
345-
// gfx_hal_exports::Viewport {
346-
// rect: gfx_hal_exports::Rect {
347-
// x: 0,
348-
// y: 0,
349-
// w: self.extent.as_ref().unwrap().width as i16,
350-
// h: self.extent.as_ref().unwrap().height as i16,
351-
// },
352-
// depth: 0.0..1.0,
353-
// }
354-
// };
355-
356-
// unsafe {
357-
// let command_buffer = self.command_buffer.as_mut().unwrap();
358-
// command_buffer
359-
// .begin_primary(gfx_hal_exports::CommandBufferFlags::ONE_TIME_SUBMIT);
360-
//
361-
// Configure the vieports & the scissor rectangles for the rasterizer
362-
// let viewports = vec![viewport.clone()].into_iter();
363-
// let rect = vec![viewport.rect].into_iter();
364-
// command_buffer.set_viewports(0, viewports);
365-
// command_buffer.set_scissors(0, rect);
366-
367-
// Render attachments to specify for the current render pass.
368-
// let render_attachments = vec![gfx_hal_exports::RenderAttachmentInfo {
369-
// image_view: image.borrow(),
370-
// clear_value: gfx_hal_exports::ClearValue {
371-
// color: gfx_hal_exports::ClearColor {
372-
// float32: [0.0, 0.0, 0.0, 1.0],
373-
// },
374-
//},
375-
//}]
376-
//.into_iter();
377-
378-
// Initialize the render pass on the command buffer & inline the subpass
379-
// contents.
380-
// command_buffer.begin_render_pass(
381-
// &render_pass,
382-
// &framebuffer,
383-
// viewport.rect,
384-
// render_attachments,
385-
// gfx_hal_exports::SubpassContents::Inline,
386-
// );
387-
388-
// Bind graphical pipeline and submit commands to the GPU.
389-
// let pipeline = &self.graphic_pipelines.as_ref().unwrap()[0];
390-
// command_buffer.bind_graphics_pipeline(pipeline);
391-
// command_buffer.draw(0..3, 0..1);
392-
// command_buffer.end_render_pass();
393-
// command_buffer.finish();
394-
395-
// Submit the command buffer for rendering on the GPU.
396-
// self.gpu.submit_command_buffer(
397-
// &command_buffer,
398-
// self.rendering_complete_semaphore.as_ref().unwrap(),
399-
// self.submission_complete_fence.as_mut().unwrap(),
400-
// );
401-
402-
// let result = self.gpu.render_to_surface(
403-
// surface,
404-
// image,
405-
// self.rendering_complete_semaphore.as_mut().unwrap(),
406-
// );
407-
// if result.is_err() {
408-
// todo!("Publish an event from the renderer that the swapchain needs to be reconfigured")
409-
// }

lambda/src/core/render/window.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use lambda_platform::winit::{
44
WindowProperties,
55
};
66

7-
use crate::core::events::Event;
7+
use crate::core::events::Events;
88

99
pub struct WindowBuilder {
1010
name: String,
@@ -33,7 +33,7 @@ impl WindowBuilder {
3333
}
3434

3535
// TODO(vmarcella): Remove new call for window and construct the window directly.
36-
pub fn build(self, event_loop: &mut Loop<Event>) -> Window {
36+
pub fn build(self, event_loop: &mut Loop<Events>) -> Window {
3737
return Window::new(self.name.as_str(), self.dimensions, event_loop);
3838
}
3939
}
@@ -47,7 +47,7 @@ impl Window {
4747
fn new(
4848
name: &str,
4949
dimensions: [u32; 2],
50-
event_loop: &mut Loop<Event>,
50+
event_loop: &mut Loop<Events>,
5151
) -> Self {
5252
let monitor_handle = event_loop
5353
.get_primary_monitor()

0 commit comments

Comments
 (0)