From 0ee15a1c06c9e6e30db4fdb2b35cfd15957f7c88 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Thu, 25 Apr 2024 20:41:55 +0100 Subject: [PATCH] Basic clear screen --- src/main.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index b2bee52..bd72131 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,47 @@ use anyhow::Result; -use crawl::winit::event::{Event, WindowEvent}; +use crawl::{ + wgpu, + winit::event::{Event, WindowEvent}, +}; + +fn render(ctx: &mut crawl::Context) -> Result<()> { + let frame = ctx.surface.get_current_texture()?; + let view = frame + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); + + let mut encoder = ctx + .device + .create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("Base Render Encoder"), + }); + + let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("Render Pass"), + color_attachments: &[Some(wgpu::RenderPassColorAttachment { + view: &view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color { + r: 0.4, + g: 0.4, + b: 0.4, + a: 1.0, + }), + store: wgpu::StoreOp::Store, + }, + })], + depth_stencil_attachment: None, + occlusion_query_set: None, + timestamp_writes: None, + }); + drop(_render_pass); + + ctx.queue.submit(Some(encoder.finish())); + frame.present(); + + Ok(()) +} fn main() -> Result<()> { env_logger::init(); @@ -17,7 +59,10 @@ fn main() -> Result<()> { } if let WindowEvent::RedrawRequested = event { - log::info!("Epic"); + if let Err(err) = render(&mut context) { + log::error!("{err:?}"); + } + context.window.request_redraw(); } }