mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-03 10:28:11 +08:00
Fix coordinate system so it renders like before wgpu upgrade
This commit is contained in:
+1
-2
@@ -7,6 +7,5 @@ layout(location=0) out vec4 f_color;
|
|||||||
layout(set = 0, binding = 0) uniform sampler2D t_texture;
|
layout(set = 0, binding = 0) uniform sampler2D t_texture;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// f_color = texture(t_texture, v_uv / textureSize(t_texture, 0) * 100);
|
f_color = texture(t_texture, v_uv / textureSize(t_texture, 0) * 100);
|
||||||
f_color = vec4(0.0, 1.0, 0.0, 1.0);
|
|
||||||
}
|
}
|
||||||
+15
-28
@@ -92,11 +92,11 @@ impl Application {
|
|||||||
pub fn example(&mut self) {
|
pub fn example(&mut self) {
|
||||||
// Example vertex data
|
// Example vertex data
|
||||||
const VERTICES: &[[f32; 2]] = &[
|
const VERTICES: &[[f32; 2]] = &[
|
||||||
[-0.0868241, -0.49240386],
|
[-0.0868241, 0.49240386],
|
||||||
[-0.49513406, -0.06958647],
|
[-0.49513406, 0.06958647],
|
||||||
[-0.21918549, 0.44939706],
|
[-0.21918549, -0.44939706],
|
||||||
[0.35966998, 0.3473291],
|
[0.35966998, -0.3473291],
|
||||||
[0.44147372, -0.2347359],
|
[0.44147372, 0.2347359],
|
||||||
];
|
];
|
||||||
const INDICES: &[u16] = &[
|
const INDICES: &[u16] = &[
|
||||||
0, 1, 4,
|
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
|
// Once every event is handled and the GUI structure is updated, this requests a new sequence of draw commands
|
||||||
Event::MainEventsCleared => {
|
Event::MainEventsCleared => {
|
||||||
// Turn the GUI changes into draw commands added to the render pipeline queue
|
// 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 any draw commands were actually added, ask the window to dispatch a redraw event
|
||||||
if !self.draw_command_queue.is_empty() {
|
if !self.draw_command_queue.is_empty() {
|
||||||
@@ -165,30 +165,17 @@ impl Application {
|
|||||||
self.render();
|
self.render();
|
||||||
},
|
},
|
||||||
// Catch extraneous events
|
// Catch extraneous events
|
||||||
_ => {
|
_ => {},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn window_event(&mut self, event: &WindowEvent, control_flow: &mut ControlFlow) {
|
pub fn window_event(&mut self, event: &WindowEvent, control_flow: &mut ControlFlow) {
|
||||||
match event {
|
match event {
|
||||||
WindowEvent::CloseRequested => {
|
WindowEvent::CloseRequested => self.quit(control_flow),
|
||||||
self.quit(control_flow);
|
WindowEvent::KeyboardInput { input, .. } => self.keyboard_event(input, control_flow),
|
||||||
},
|
WindowEvent::Resized(physical_size) => self.resize(*physical_size),
|
||||||
WindowEvent::KeyboardInput { input, .. } => {
|
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => self.resize(**new_inner_size),
|
||||||
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;
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,17 +207,17 @@ impl Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Traverse the dirty GUI elements and queue up pipelines to render each GUI rectangle (box/sprite)
|
// 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
|
// Render the queue of pipeline draw commands over the current window
|
||||||
pub fn render(&mut self) {
|
pub fn render(&mut self) {
|
||||||
// Get a frame buffer to render on
|
// 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
|
// 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
|
// Temporary way to swap clear color every render
|
||||||
let color = match self.temp_color_toggle {
|
let color = match self.temp_color_toggle {
|
||||||
|
|||||||
+1
-1
@@ -48,7 +48,7 @@ impl Pipeline {
|
|||||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||||
color_states: &[
|
color_states: &[
|
||||||
wgpu::ColorStateDescriptor {
|
wgpu::ColorStateDescriptor {
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
format: wgpu::TextureFormat::Bgra8UnormSrgb, // TODO: Make this match Application.swap_chain_descriptor
|
||||||
color_blend: wgpu::BlendDescriptor::REPLACE,
|
color_blend: wgpu::BlendDescriptor::REPLACE,
|
||||||
alpha_blend: wgpu::BlendDescriptor::REPLACE,
|
alpha_blend: wgpu::BlendDescriptor::REPLACE,
|
||||||
write_mask: wgpu::ColorWrite::ALL,
|
write_mask: wgpu::ColorWrite::ALL,
|
||||||
|
|||||||
+9
-3
@@ -38,11 +38,17 @@ impl ShaderCache {
|
|||||||
// self.shaders.get(id.index)
|
// 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() {
|
if self.path_to_id.get(path).is_none() {
|
||||||
let source = std::fs::read_to_string(path)?;
|
let source = std::fs::read_to_string(path)?;
|
||||||
let spirv = glsl_to_spirv::compile(&source[..], shader_type).unwrap();
|
let spirv = match glsl_to_spirv::compile(&source[..], shader_type) {
|
||||||
let compiled = wgpu::read_spirv(spirv).unwrap();
|
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 shader = device.create_shader_module(&compiled);
|
||||||
|
|
||||||
let last_index = self.path_to_id.len();
|
let last_index = self.path_to_id.len();
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ impl ShaderCache {
|
|||||||
self.shaders.get(id.index)
|
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() {
|
if self.name_to_id.get(path).is_none() {
|
||||||
let source = std::fs::read_to_string(path)?;
|
let source = std::fs::read_to_string(path)?;
|
||||||
let spirv = glsl_to_spirv::compile(&source[..], shader_type).unwrap();
|
let spirv = glsl_to_spirv::compile(&source[..], shader_type).unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user