diff --git a/src/app.rs b/src/app.rs index 3864a0d..c1574b6 100644 --- a/src/app.rs +++ b/src/app.rs @@ -117,21 +117,21 @@ impl App { Output::FlipHorizontal => { let view = self.image_view.as_mut().unwrap(); if view.rotation() % 2 != 0 { - view.flip_horizontal(); - stack.push(UndoFrame::FlipHorizontal); - } else { view.flip_vertical(); stack.push(UndoFrame::FlipVertical); + } else { + view.flip_horizontal(); + stack.push(UndoFrame::FlipHorizontal); } } Output::FlipVertical => { let view = self.image_view.as_mut().unwrap(); if view.rotation() % 2 != 0 { view.flip_horizontal(); - stack.push(UndoFrame::FlipVertical); + stack.push(UndoFrame::FlipHorizontal); } else { view.flip_vertical(); - stack.push(UndoFrame::FlipHorizontal); + stack.push(UndoFrame::FlipVertical); } } Output::Rotate(dir) => { diff --git a/src/app/image_view.rs b/src/app/image_view.rs index 5c9d07b..c7195de 100644 --- a/src/app/image_view.rs +++ b/src/app/image_view.rs @@ -91,6 +91,22 @@ impl ImageView { (pre_rotation * rotation) * post_rotation } + pub fn get_flip_mat(&self) -> Matrix4 { + let hori = if self.horizontal_flip { -1.0 } else { 1.0 }; + + let vert = if self.vertical_flip { -1.0 } else { 1.0 }; + + let flip = Matrix4::from_nonuniform_scale(hori, vert, 1.0); + let pre_rotation = + Matrix4::from_translation(Vector3::new(self.size.x() / 2.0, self.size.y() / 2.0, 0.0)); + let post_rotation = Matrix4::from_translation(Vector3::new( + -self.size.x() / 2.0, + -self.size.y() / 2.0, + 0.0, + )); + (pre_rotation * flip) * post_rotation + } + pub fn get_uniform(&self, size: Vec2) -> image_renderer::Uniform { let ortho: Matrix4 = Ortho { left: 0.0, @@ -106,13 +122,12 @@ impl ImageView { let scale = Matrix4::from_scale(self.scale); let translation = Matrix4::from_translation(Vector3::new(position.x(), position.y(), 0.0)); + let flip = self.get_flip_mat(); let rotation = self.get_rotation_mat(); - let matrix = OPENGL_TO_WGPU_MATRIX * ortho * translation * scale * rotation; + let matrix = OPENGL_TO_WGPU_MATRIX * ortho * translation * scale * flip * rotation; image_renderer::Uniform { matrix, - flip_horizontal: self.horizontal_flip as u32, - flip_vertical: self.vertical_flip as u32, size, padding: Default::default(), hue: self.hue, diff --git a/src/app/image_view/image_renderer.rs b/src/app/image_view/image_renderer.rs index 60efb72..73e8902 100644 --- a/src/app/image_view/image_renderer.rs +++ b/src/app/image_view/image_renderer.rs @@ -49,8 +49,6 @@ pub struct Uniform { pub matrix: Matrix4, pub size: Vec2, pub padding: Vec2, // Padding because glsl is adding dumb padding - pub flip_horizontal: u32, - pub flip_vertical: u32, pub hue: f32, pub contrast: f32, pub brightness: f32, @@ -63,8 +61,6 @@ impl Default for Uniform { fn default() -> Self { Self { matrix: Matrix4::identity(), - flip_horizontal: Default::default(), - flip_vertical: Default::default(), size: Default::default(), padding: Default::default(), hue: Default::default(), @@ -162,7 +158,7 @@ impl Renderer { topology: wgpu::PrimitiveTopology::TriangleList, strip_index_format: None, front_face: wgpu::FrontFace::Ccw, - cull_mode: Some(wgpu::Face::Back), + cull_mode: None, polygon_mode: wgpu::PolygonMode::Fill, unclipped_depth: false, conservative: false, diff --git a/src/app/image_view/mosaic.rs b/src/app/image_view/mosaic.rs index b4aac94..729c814 100644 --- a/src/app/image_view/mosaic.rs +++ b/src/app/image_view/mosaic.rs @@ -127,10 +127,10 @@ fn get_vertex_buffer( Vec2::new(0.0, 0.0), ); let shape = [ - Vertex::new(start_x, start_y, texture_cords.0.x(), texture_cords.0.y()), - Vertex::new(start_x, end_y, texture_cords.1.x(), texture_cords.1.y()), - Vertex::new(end_x, start_y, texture_cords.2.x(), texture_cords.2.y()), - Vertex::new(end_x, end_y, texture_cords.3.x(), texture_cords.3.y()), + Vertex::new(start_x, start_y, texture_cords.3.x(), texture_cords.3.y()), + Vertex::new(start_x, end_y, texture_cords.2.x(), texture_cords.2.y()), + Vertex::new(end_x, start_y, texture_cords.1.x(), texture_cords.1.y()), + Vertex::new(end_x, end_y, texture_cords.0.x(), texture_cords.0.y()), ]; wgpu.device diff --git a/src/shader/image.frag b/src/shader/image.frag index ee6d527..6071a93 100644 --- a/src/shader/image.frag +++ b/src/shader/image.frag @@ -6,8 +6,6 @@ layout(location = 0) out vec4 color; struct InputUniform { mat4 matrix; vec2 size; - uint flip_horizontal; - uint flip_vertical; float hue; float contrast; float brightness; diff --git a/src/shader/image.vert b/src/shader/image.vert index e6a9e7a..4aca82d 100644 --- a/src/shader/image.vert +++ b/src/shader/image.vert @@ -6,8 +6,7 @@ layout(location = 0) out vec2 v_tex_coords; struct InputUniform { mat4 matrix; - uint flip_horizontal; - uint flip_vertical; + vec2 size; float hue; float contrast; float brightness; @@ -16,18 +15,9 @@ struct InputUniform { uint invert; }; -vec2 size = vec2(1920, 1080); - - layout(set = 0, binding = 0) uniform InputUniform input; void main() { v_tex_coords = tex_coords; - if(bool(input.flip_horizontal)) { - v_tex_coords.x = 1 - v_tex_coords.x; - } - if(bool(input.flip_vertical)) { - v_tex_coords.y = 1 - v_tex_coords.y; - } gl_Position = input.matrix * vec4(position, 0.0, 1.0); }