diff --git a/shaders/shader.frag b/shaders/shader.frag index d3ecc1b1..2327b894 100644 --- a/shaders/shader.frag +++ b/shaders/shader.frag @@ -7,6 +7,5 @@ layout(location=0) out vec4 f_color; layout(set = 0, binding = 0) uniform sampler2D t_texture; void main() { - // f_color = texture(t_texture, v_uv / textureSize(t_texture, 0) * 100); - f_color = vec4(0.0, 1.0, 0.0, 1.0); + f_color = texture(t_texture, v_uv / textureSize(t_texture, 0) * 100); } \ No newline at end of file diff --git a/src/application.rs b/src/application.rs index 37da95cf..bffa2fa8 100644 --- a/src/application.rs +++ b/src/application.rs @@ -92,11 +92,11 @@ impl Application { pub fn example(&mut self) { // Example vertex data const VERTICES: &[[f32; 2]] = &[ - [-0.0868241, -0.49240386], - [-0.49513406, -0.06958647], - [-0.21918549, 0.44939706], - [0.35966998, 0.3473291], - [0.44147372, -0.2347359], + [-0.0868241, 0.49240386], + [-0.49513406, 0.06958647], + [-0.21918549, -0.44939706], + [0.35966998, -0.3473291], + [0.44147372, 0.2347359], ]; const INDICES: &[u16] = &[ 0, 1, 4, @@ -153,7 +153,7 @@ impl Application { // Once every event is handled and the GUI structure is updated, this requests a new sequence of draw commands Event::MainEventsCleared => { // Turn the GUI changes into draw commands added to the render pipeline queue - self.redraw(); + self.redraw_gui(); // If any draw commands were actually added, ask the window to dispatch a redraw event if !self.draw_command_queue.is_empty() { @@ -165,30 +165,17 @@ impl Application { self.render(); }, // Catch extraneous events - _ => { - }, + _ => {}, } } pub fn window_event(&mut self, event: &WindowEvent, control_flow: &mut ControlFlow) { match event { - WindowEvent::CloseRequested => { - self.quit(control_flow); - }, - WindowEvent::KeyboardInput { input, .. } => { - self.keyboard_event(input, control_flow); - }, - WindowEvent::Resized(physical_size) => { - self.resize(*physical_size); - *control_flow = ControlFlow::Wait; - }, - WindowEvent::ScaleFactorChanged { new_inner_size, .. } => { - self.resize(**new_inner_size); - *control_flow = ControlFlow::Wait; - }, - _ => { - *control_flow = ControlFlow::Wait; - }, + WindowEvent::CloseRequested => self.quit(control_flow), + WindowEvent::KeyboardInput { input, .. } => self.keyboard_event(input, control_flow), + WindowEvent::Resized(physical_size) => self.resize(*physical_size), + WindowEvent::ScaleFactorChanged { new_inner_size, .. } => self.resize(**new_inner_size), + _ => {}, } } @@ -220,17 +207,17 @@ impl Application { } // Traverse the dirty GUI elements and queue up pipelines to render each GUI rectangle (box/sprite) - pub fn redraw(&mut self) { + pub fn redraw_gui(&mut self) { } // Render the queue of pipeline draw commands over the current window pub fn render(&mut self) { // Get a frame buffer to render on - let frame = self.swap_chain.get_next_texture().unwrap(); + let frame = self.swap_chain.get_next_texture().expect("Timeout getting frame buffer texture"); // Generates a render pass that commands are applied to, then generates a command buffer when finished - let mut command_encoder = self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); + let mut command_encoder = self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("Render Encoder") }); // Temporary way to swap clear color every render let color = match self.temp_color_toggle { diff --git a/src/pipeline.rs b/src/pipeline.rs index d1e45888..9b5256b1 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -48,7 +48,7 @@ impl Pipeline { primitive_topology: wgpu::PrimitiveTopology::TriangleList, color_states: &[ wgpu::ColorStateDescriptor { - format: wgpu::TextureFormat::Bgra8UnormSrgb, + format: wgpu::TextureFormat::Bgra8UnormSrgb, // TODO: Make this match Application.swap_chain_descriptor color_blend: wgpu::BlendDescriptor::REPLACE, alpha_blend: wgpu::BlendDescriptor::REPLACE, write_mask: wgpu::ColorWrite::ALL, diff --git a/src/shader_cache.rs b/src/shader_cache.rs index 510ff552..ec5be77d 100644 --- a/src/shader_cache.rs +++ b/src/shader_cache.rs @@ -38,11 +38,17 @@ impl ShaderCache { // self.shaders.get(id.index) // } - pub fn load(&mut self, device: &wgpu::Device, path: &str, shader_type: glsl_to_spirv::ShaderType) -> Result<(), std::io::Error> { + pub fn load(&mut self, device: &wgpu::Device, path: &str, shader_type: glsl_to_spirv::ShaderType) -> std::io::Result<()> { if self.path_to_id.get(path).is_none() { let source = std::fs::read_to_string(path)?; - let spirv = glsl_to_spirv::compile(&source[..], shader_type).unwrap(); - let compiled = wgpu::read_spirv(spirv).unwrap(); + let spirv = match glsl_to_spirv::compile(&source[..], shader_type) { + Ok(spirv_output) => spirv_output, + Err(message) => { + println!("Error compiling GLSL to SPIRV shader: {}", message); + panic!("{}", message); + } + }; + let compiled = wgpu::read_spirv(spirv)?; let shader = device.create_shader_module(&compiled); let last_index = self.path_to_id.len(); diff --git a/src/texture_cache.rs b/src/texture_cache.rs index 5ef3ed8d..976bc3c4 100644 --- a/src/texture_cache.rs +++ b/src/texture_cache.rs @@ -33,7 +33,7 @@ impl ShaderCache { self.shaders.get(id.index) } - pub fn load(&mut self, device: &wgpu::Device, path: &str, shader_type: glsl_to_spirv::ShaderType) -> Result<(), std::io::Error> { + pub fn load(&mut self, device: &wgpu::Device, path: &str, shader_type: glsl_to_spirv::ShaderType) -> std::io::Result<()> { if self.name_to_id.get(path).is_none() { let source = std::fs::read_to_string(path)?; let spirv = glsl_to_spirv::compile(&source[..], shader_type).unwrap();