It compiles but obviously doesn't work yet

This commit is contained in:
griffi-gh 2023-07-17 00:25:19 +02:00
parent 3b752dfbf8
commit 34b9398e80
5 changed files with 44 additions and 15 deletions

View file

@ -1,5 +1,6 @@
[workspace] [workspace]
members = ["kubi", "kubi-server", "kubi-shared", "kubi-logging"] members = ["kubi", "kubi-server", "kubi-shared", "kubi-logging"]
default-members = ["kubi"]
resolver = "2" resolver = "2"
[profile.release-with-debug] [profile.release-with-debug]
@ -15,7 +16,7 @@ opt-level = 1
[profile.dev.package.uflow] [profile.dev.package.uflow]
opt-level = 3 opt-level = 3
[profile.dev.package.glium] [profile.dev.package.wgpu]
opt-level = 3 opt-level = 3
[profile.dev.package.bracket-noise] [profile.dev.package.bracket-noise]

View file

@ -47,7 +47,7 @@ pub fn load_asset_texture_array<
//Ensure same size (skip if poisoned) //Ensure same size (skip if poisoned)
if !img_dim.is_poisoned() { if !img_dim.is_poisoned() {
let img_dim = img_dim.lock().unwrap(); let mut img_dim = img_dim.lock().unwrap();
if let Some(current_size) = img_dim.replace(dim_nonzero) { if let Some(current_size) = img_dim.replace(dim_nonzero) {
assert!(dim_nonzero == current_size, "image dimensions do not match"); assert!(dim_nonzero == current_size, "image dimensions do not match");
} }

View file

@ -81,10 +81,13 @@ pub fn process_glutin_events(world: &mut World, event: &Event<'_, ()>) {
pub fn initial_resize_event( pub fn initial_resize_event(
mut storages: AllStoragesViewMut, mut storages: AllStoragesViewMut,
) { ) {
let renderer = storages.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap(); let size = {
let renderer = storages.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
UVec2::new(renderer.size.width, renderer.size.height)
};
storages.add_entity(( storages.add_entity((
EventComponent, EventComponent,
WindowResizedEvent(UVec2::new(renderer.size.width, renderer.size.height)) WindowResizedEvent(size)
)); ));
} }

View file

@ -213,6 +213,10 @@ pub fn kubi_main() {
#[allow(clippy::collapsible_match, clippy::single_match)] #[allow(clippy::collapsible_match, clippy::single_match)]
match event { match event {
Event::WindowEvent { event, .. } => match event { Event::WindowEvent { event, .. } => match event {
WindowEvent::Resized(new_size) => {
//this can be in a system but I don't care
world.borrow::<NonSendSync<UniqueViewMut<Renderer>>>().unwrap().resize(new_size);
}
WindowEvent::CloseRequested => { WindowEvent::CloseRequested => {
log::info!("exit requested"); log::info!("exit requested");
*control_flow = ControlFlow::Exit; *control_flow = ControlFlow::Exit;
@ -234,16 +238,19 @@ pub fn kubi_main() {
//Start rendering (maybe use custom views for this?) //Start rendering (maybe use custom views for this?)
let target = { let target = {
let renderer = world.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap(); let renderer = world.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
renderer.render() renderer.begin()
}; };
world.add_unique_non_send_sync(RenderTarget(target)); world.add_unique_non_send_sync(target);
//Run render workflow //Run render workflow
world.run_workload(render).unwrap(); world.run_workload(render).unwrap();
//Finish rendering //Finish rendering
let target = world.remove_unique::<RenderTarget>().unwrap(); {
target.0.finish().unwrap(); let target = world.remove_unique::<RenderTarget>().unwrap();
let renderer = world.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
renderer.end(target);
}
//After frame end //After frame end
world.run_workload(after_frame_end).unwrap(); world.run_workload(after_frame_end).unwrap();

View file

@ -18,8 +18,11 @@ pub mod selection_box;
pub mod entities; pub mod entities;
#[derive(Unique)] #[derive(Unique)]
#[repr(transparent)] pub struct RenderTarget {
pub struct RenderTarget(pub ()); pub output: wgpu::SurfaceTexture,
pub view: wgpu::TextureView,
pub encoder: wgpu::CommandEncoder,
}
#[derive(Unique)] #[derive(Unique)]
#[repr(transparent)] #[repr(transparent)]
@ -141,7 +144,9 @@ impl Renderer {
}; };
surface.configure(&device, &config); surface.configure(&device, &config);
Self { window, instance, surface, adapter, device, queue, size, config } Self {
window, instance, surface, adapter, device, queue, size, config,
}
} }
/// do not call from async functions /// do not call from async functions
@ -150,14 +155,27 @@ impl Renderer {
} }
/// Start a new frame /// Start a new frame
pub fn render() -> RenderTarget { pub fn begin(&self) -> RenderTarget {
todo!() //Surface texture
let output = self.surface.get_current_texture().unwrap();
//View
let view = output.texture.create_view(&wgpu::TextureViewDescriptor::default());
//Encoder
let encoder = self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("RenderEncoder"),
});
RenderTarget { output, view, encoder }
}
pub fn end(&self, target: RenderTarget) {
self.queue.submit([target.encoder.finish()]);
target.output.present();
} }
/// Resize the surface /// Resize the surface
/// ## Panics: /// ## Panics:
/// - ...if any dimension is equal to zero /// - ...if any dimension is equal to zero
pub fn resize(&self, new_size: PhysicalSize<u32>) { pub fn resize(&mut self, new_size: PhysicalSize<u32>) {
//XXX: just check instead? //XXX: just check instead?
assert!(new_size.width > 0, "width cannot be zero"); assert!(new_size.width > 0, "width cannot be zero");
assert!(new_size.height > 0, "height cannot be zero"); assert!(new_size.height > 0, "height cannot be zero");