Fix coordinate system so it renders like before wgpu upgrade

This commit is contained in:
Keavon Chambers 2020-05-02 17:46:34 -07:00
parent 323a951362
commit 2ab74f7ba1
5 changed files with 27 additions and 35 deletions

View File

@ -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);
}

View File

@ -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 {

View File

@ -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,

View File

@ -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();

View File

@ -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();