mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-10 01:28:41 -06:00
It compiles but obviously doesn't work yet
This commit is contained in:
parent
3b752dfbf8
commit
34b9398e80
|
@ -1,5 +1,6 @@
|
|||
[workspace]
|
||||
members = ["kubi", "kubi-server", "kubi-shared", "kubi-logging"]
|
||||
default-members = ["kubi"]
|
||||
resolver = "2"
|
||||
|
||||
[profile.release-with-debug]
|
||||
|
@ -15,7 +16,7 @@ opt-level = 1
|
|||
[profile.dev.package.uflow]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev.package.glium]
|
||||
[profile.dev.package.wgpu]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev.package.bracket-noise]
|
||||
|
|
|
@ -47,7 +47,7 @@ pub fn load_asset_texture_array<
|
|||
|
||||
//Ensure same size (skip if 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) {
|
||||
assert!(dim_nonzero == current_size, "image dimensions do not match");
|
||||
}
|
||||
|
|
|
@ -81,10 +81,13 @@ pub fn process_glutin_events(world: &mut World, event: &Event<'_, ()>) {
|
|||
pub fn initial_resize_event(
|
||||
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((
|
||||
EventComponent,
|
||||
WindowResizedEvent(UVec2::new(renderer.size.width, renderer.size.height))
|
||||
WindowResizedEvent(size)
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -213,6 +213,10 @@ pub fn kubi_main() {
|
|||
#[allow(clippy::collapsible_match, clippy::single_match)]
|
||||
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 => {
|
||||
log::info!("exit requested");
|
||||
*control_flow = ControlFlow::Exit;
|
||||
|
@ -234,16 +238,19 @@ pub fn kubi_main() {
|
|||
//Start rendering (maybe use custom views for this?)
|
||||
let target = {
|
||||
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
|
||||
world.run_workload(render).unwrap();
|
||||
|
||||
//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
|
||||
world.run_workload(after_frame_end).unwrap();
|
||||
|
|
|
@ -18,8 +18,11 @@ pub mod selection_box;
|
|||
pub mod entities;
|
||||
|
||||
#[derive(Unique)]
|
||||
#[repr(transparent)]
|
||||
pub struct RenderTarget(pub ());
|
||||
pub struct RenderTarget {
|
||||
pub output: wgpu::SurfaceTexture,
|
||||
pub view: wgpu::TextureView,
|
||||
pub encoder: wgpu::CommandEncoder,
|
||||
}
|
||||
|
||||
#[derive(Unique)]
|
||||
#[repr(transparent)]
|
||||
|
@ -116,7 +119,7 @@ impl Renderer {
|
|||
},
|
||||
None,
|
||||
).await.unwrap();
|
||||
|
||||
|
||||
// surf. format
|
||||
|
||||
let surface_capabilities = surface.get_capabilities(&adapter);
|
||||
|
@ -141,7 +144,9 @@ impl Renderer {
|
|||
};
|
||||
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
|
||||
|
@ -150,14 +155,27 @@ impl Renderer {
|
|||
}
|
||||
|
||||
/// Start a new frame
|
||||
pub fn render() -> RenderTarget {
|
||||
todo!()
|
||||
pub fn begin(&self) -> RenderTarget {
|
||||
//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
|
||||
/// ## Panics:
|
||||
/// - ...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?
|
||||
assert!(new_size.width > 0, "width cannot be zero");
|
||||
assert!(new_size.height > 0, "height cannot be zero");
|
||||
|
|
Loading…
Reference in a new issue