From 40f45d7b7e35dd4937abe6b5ce16b6256b4f1eeb Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 29 Sep 2022 10:52:58 -0700 Subject: Adds linear gradient support to 2D meshes in the canvas widget. --- glow/src/triangle/solid.rs | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 glow/src/triangle/solid.rs (limited to 'glow/src/triangle/solid.rs') diff --git a/glow/src/triangle/solid.rs b/glow/src/triangle/solid.rs new file mode 100644 index 00000000..3a33cea8 --- /dev/null +++ b/glow/src/triangle/solid.rs @@ -0,0 +1,67 @@ +use crate::program::Version; +use crate::triangle::{simple_triangle_program, update_transform}; +use crate::Color; +use glow::{Context, HasContext, NativeProgram}; +use iced_graphics::Transformation; + +#[derive(Debug)] +pub struct SolidProgram { + pub(crate) program: ::Program, + pub(crate) uniform_data: SolidUniformData, +} + +impl SolidProgram { + pub fn new(gl: &Context, shader_version: &Version) -> Self { + let program = simple_triangle_program( + gl, + shader_version, + include_str!("../shader/common/triangle.frag"), + ); + + Self { + program, + uniform_data: SolidUniformData::new(gl, program), + } + } + + pub fn set_uniforms<'a>( + &mut self, + gl: &Context, + color: &Color, + transform: Option, + ) { + update_transform(gl, self.program, transform); + + if &self.uniform_data.color != color { + unsafe { + gl.uniform_4_f32( + Some(&self.uniform_data.color_location), + color.r, + color.g, + color.b, + color.a, + ); + } + + self.uniform_data.color = *color; + } + } +} + +#[derive(Debug)] +pub(crate) struct SolidUniformData { + pub color: Color, + pub color_location: ::UniformLocation, +} + +impl SolidUniformData { + fn new(gl: &Context, program: NativeProgram) -> Self { + Self { + color: Color::TRANSPARENT, + color_location: unsafe { + gl.get_uniform_location(program, "color") + } + .expect("Solid - Color uniform location."), + } + } +} -- cgit From 6e7b3ced0b1daf368e44e181ecdb4ae529877eb6 Mon Sep 17 00:00:00 2001 From: shan Date: Tue, 4 Oct 2022 18:24:46 -0700 Subject: Reworked wgpu buffers, updated glow side to have proper transform location storage, attempting to fix visibility modifiers, implemented some of the feedback received in initial PR. --- glow/src/triangle/solid.rs | 62 +++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 23 deletions(-) (limited to 'glow/src/triangle/solid.rs') diff --git a/glow/src/triangle/solid.rs b/glow/src/triangle/solid.rs index 3a33cea8..d5b73eb9 100644 --- a/glow/src/triangle/solid.rs +++ b/glow/src/triangle/solid.rs @@ -1,13 +1,38 @@ use crate::program::Version; -use crate::triangle::{simple_triangle_program, update_transform}; +use crate::triangle::{set_transform, simple_triangle_program}; use crate::Color; use glow::{Context, HasContext, NativeProgram}; use iced_graphics::Transformation; #[derive(Debug)] pub struct SolidProgram { - pub(crate) program: ::Program, - pub(crate) uniform_data: SolidUniformData, + program: ::Program, + uniform_data: SolidUniformData, +} + +#[derive(Debug)] +pub(crate) struct SolidUniformData { + pub color: Color, + pub color_location: ::UniformLocation, + pub transform: Transformation, + pub transform_location: ::UniformLocation, +} + +impl SolidUniformData { + fn new(gl: &Context, program: NativeProgram) -> Self { + Self { + color: Color::TRANSPARENT, + color_location: unsafe { + gl.get_uniform_location(program, "color") + } + .expect("Solid - Color uniform location."), + transform: Transformation::identity(), + transform_location: unsafe { + gl.get_uniform_location(program, "u_Transform") + } + .expect("Get transform location."), + } + } } impl SolidProgram { @@ -24,15 +49,17 @@ impl SolidProgram { } } - pub fn set_uniforms<'a>( + pub fn write_uniforms( &mut self, gl: &Context, color: &Color, - transform: Option, + transform: &Transformation, ) { - update_transform(gl, self.program, transform); + if transform != &self.uniform_data.transform { + set_transform(gl, self.uniform_data.transform_location, *transform) + } - if &self.uniform_data.color != color { + if color != &self.uniform_data.color { unsafe { gl.uniform_4_f32( Some(&self.uniform_data.color_location), @@ -46,22 +73,11 @@ impl SolidProgram { self.uniform_data.color = *color; } } -} - -#[derive(Debug)] -pub(crate) struct SolidUniformData { - pub color: Color, - pub color_location: ::UniformLocation, -} -impl SolidUniformData { - fn new(gl: &Context, program: NativeProgram) -> Self { - Self { - color: Color::TRANSPARENT, - color_location: unsafe { - gl.get_uniform_location(program, "color") - } - .expect("Solid - Color uniform location."), + pub fn use_program(&mut self, gl: &glow::Context, color: &Color, transform: &Transformation) { + unsafe { + gl.use_program(Some(self.program)) } + self.write_uniforms(gl, color, transform) } -} +} \ No newline at end of file -- cgit From cb7c4676543cd508dfae8d4dcbd9cc8b61b1a94e Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 6 Oct 2022 07:28:05 -0700 Subject: Fixed lint issues & cleaned up some documentation. --- glow/src/triangle/solid.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'glow/src/triangle/solid.rs') diff --git a/glow/src/triangle/solid.rs b/glow/src/triangle/solid.rs index d5b73eb9..3d4d1968 100644 --- a/glow/src/triangle/solid.rs +++ b/glow/src/triangle/solid.rs @@ -11,7 +11,7 @@ pub struct SolidProgram { } #[derive(Debug)] -pub(crate) struct SolidUniformData { +struct SolidUniformData { pub color: Color, pub color_location: ::UniformLocation, pub transform: Transformation, @@ -74,10 +74,10 @@ impl SolidProgram { } } - pub fn use_program(&mut self, gl: &glow::Context, color: &Color, transform: &Transformation) { + pub fn use_program(&mut self, gl: &Context, color: &Color, transform: &Transformation) { unsafe { gl.use_program(Some(self.program)) } self.write_uniforms(gl, color, transform) } -} \ No newline at end of file +} -- cgit From f9a6efcaa03728f43aaa105af8936c1ed4778388 Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 6 Oct 2022 19:41:00 -0700 Subject: Fixed some more imports/documentation. --- glow/src/triangle/solid.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'glow/src/triangle/solid.rs') diff --git a/glow/src/triangle/solid.rs b/glow/src/triangle/solid.rs index 3d4d1968..5ba7f91c 100644 --- a/glow/src/triangle/solid.rs +++ b/glow/src/triangle/solid.rs @@ -25,12 +25,12 @@ impl SolidUniformData { color_location: unsafe { gl.get_uniform_location(program, "color") } - .expect("Solid - Color uniform location."), + .expect("Solid - Get color."), transform: Transformation::identity(), transform_location: unsafe { gl.get_uniform_location(program, "u_Transform") } - .expect("Get transform location."), + .expect("Solid - Get u_Transform."), } } } @@ -74,10 +74,13 @@ impl SolidProgram { } } - pub fn use_program(&mut self, gl: &Context, color: &Color, transform: &Transformation) { - unsafe { - gl.use_program(Some(self.program)) - } + pub fn use_program( + &mut self, + gl: &Context, + color: &Color, + transform: &Transformation, + ) { + unsafe { gl.use_program(Some(self.program)) } self.write_uniforms(gl, color, transform) } } -- cgit From c4565759e4294540f54a81e4d91ddea7a769d3d4 Mon Sep 17 00:00:00 2001 From: bungoboingo Date: Tue, 18 Oct 2022 15:18:37 -0700 Subject: Cleaned up namespaces re: PR comments. --- glow/src/triangle/solid.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'glow/src/triangle/solid.rs') diff --git a/glow/src/triangle/solid.rs b/glow/src/triangle/solid.rs index 5ba7f91c..311e3704 100644 --- a/glow/src/triangle/solid.rs +++ b/glow/src/triangle/solid.rs @@ -1,24 +1,23 @@ use crate::program::Version; -use crate::triangle::{set_transform, simple_triangle_program}; -use crate::Color; +use crate::{triangle, Color}; use glow::{Context, HasContext, NativeProgram}; use iced_graphics::Transformation; #[derive(Debug)] -pub struct SolidProgram { +pub struct Program { program: ::Program, - uniform_data: SolidUniformData, + uniform_data: UniformData, } #[derive(Debug)] -struct SolidUniformData { +struct UniformData { pub color: Color, pub color_location: ::UniformLocation, pub transform: Transformation, pub transform_location: ::UniformLocation, } -impl SolidUniformData { +impl UniformData { fn new(gl: &Context, program: NativeProgram) -> Self { Self { color: Color::TRANSPARENT, @@ -35,9 +34,9 @@ impl SolidUniformData { } } -impl SolidProgram { +impl Program { pub fn new(gl: &Context, shader_version: &Version) -> Self { - let program = simple_triangle_program( + let program = triangle::program( gl, shader_version, include_str!("../shader/common/triangle.frag"), @@ -45,7 +44,7 @@ impl SolidProgram { Self { program, - uniform_data: SolidUniformData::new(gl, program), + uniform_data: UniformData::new(gl, program), } } @@ -56,7 +55,11 @@ impl SolidProgram { transform: &Transformation, ) { if transform != &self.uniform_data.transform { - set_transform(gl, self.uniform_data.transform_location, *transform) + triangle::set_transform( + gl, + self.uniform_data.transform_location, + *transform, + ) } if color != &self.uniform_data.color { -- cgit From 62465842099908f9e50b8edabfec709b37b1ade3 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 3 Nov 2022 04:37:23 +0100 Subject: Convert colors to linear RGB before uploading in `solid` pipelines --- glow/src/triangle/solid.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'glow/src/triangle/solid.rs') diff --git a/glow/src/triangle/solid.rs b/glow/src/triangle/solid.rs index 311e3704..fb3d40c3 100644 --- a/glow/src/triangle/solid.rs +++ b/glow/src/triangle/solid.rs @@ -63,13 +63,15 @@ impl Program { } if color != &self.uniform_data.color { + let [r, g, b, a] = color.into_linear(); + unsafe { gl.uniform_4_f32( Some(&self.uniform_data.color_location), - color.r, - color.g, - color.b, - color.a, + r, + g, + b, + a, ); } -- cgit