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/gradient.rs | 189 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 glow/src/triangle/gradient.rs (limited to 'glow/src/triangle/gradient.rs') diff --git a/glow/src/triangle/gradient.rs b/glow/src/triangle/gradient.rs new file mode 100644 index 00000000..d1b10d77 --- /dev/null +++ b/glow/src/triangle/gradient.rs @@ -0,0 +1,189 @@ +use crate::program::Version; +use crate::triangle::{simple_triangle_program, update_transform}; +use glow::{Context, HasContext, NativeProgram}; +use iced_graphics::gradient::Gradient; +use iced_graphics::widget::canvas::gradient::Linear; +use iced_graphics::Transformation; + +#[derive(Debug)] +pub(super) struct GradientProgram { + pub(super) program: ::Program, + pub(super) uniform_data: GradientUniformData, +} + +impl GradientProgram { + pub(super) fn new(gl: &Context, shader_version: &Version) -> Self { + let program = simple_triangle_program( + gl, + shader_version, + include_str!("../shader/common/gradient.frag"), + ); + + Self { + program, + uniform_data: GradientUniformData::new(gl, program), + } + } + + pub(super) fn set_uniforms<'a>( + &mut self, + gl: &Context, + gradient: &Gradient, + transform: Option, + ) { + update_transform(gl, self.program, transform); + + if &self.uniform_data.current_gradient != gradient { + match gradient { + Gradient::Linear(linear) => { + let gradient_start: [f32; 2] = (linear.start).into(); + let gradient_end: [f32; 2] = (linear.end).into(); + + unsafe { + gl.uniform_2_f32( + Some( + &self + .uniform_data + .uniform_locations + .gradient_start_location, + ), + gradient_start[0], + gradient_start[1], + ); + + gl.uniform_2_f32( + Some( + &self + .uniform_data + .uniform_locations + .gradient_end_location, + ), + gradient_end[0], + gradient_end[1], + ); + + gl.uniform_1_u32( + Some( + &self + .uniform_data + .uniform_locations + .color_stops_size_location, + ), + linear.color_stops.len() as u32, + ); + + for (index, stop) in + linear.color_stops.iter().enumerate() + { + gl.uniform_1_f32( + Some( + &self + .uniform_data + .uniform_locations + .color_stops_locations[index] + .offset, + ), + stop.offset, + ); + + gl.uniform_4_f32( + Some( + &self + .uniform_data + .uniform_locations + .color_stops_locations[index] + .color, + ), + stop.color.r, + stop.color.g, + stop.color.b, + stop.color.a, + ); + } + } + } + } + + self.uniform_data.current_gradient = gradient.clone(); + } + } +} + +#[derive(Debug)] +pub(super) struct GradientUniformData { + current_gradient: Gradient, + uniform_locations: GradientUniformLocations, +} + +#[derive(Debug)] +struct GradientUniformLocations { + gradient_start_location: ::UniformLocation, + gradient_end_location: ::UniformLocation, + color_stops_size_location: ::UniformLocation, + //currently the maximum number of stops is 64 due to needing to allocate the + //memory for the array of stops with a const value in GLSL + color_stops_locations: [ColorStopLocation; 64], +} + +#[derive(Copy, Debug, Clone)] +struct ColorStopLocation { + color: ::UniformLocation, + offset: ::UniformLocation, +} + +impl GradientUniformData { + fn new(gl: &Context, program: NativeProgram) -> Self { + let gradient_start_location = + unsafe { gl.get_uniform_location(program, "gradient_start") } + .expect("Gradient - Get gradient_start."); + + let gradient_end_location = + unsafe { gl.get_uniform_location(program, "gradient_end") } + .expect("Gradient - Get gradient_end."); + + let color_stops_size_location = + unsafe { gl.get_uniform_location(program, "color_stops_size") } + .expect("Gradient - Get color_stops_size."); + + let color_stops_locations: [ColorStopLocation; 64] = + core::array::from_fn(|index| { + let offset = unsafe { + gl.get_uniform_location( + program, + &format!("color_stop_offsets[{}]", index), + ) + } + .expect(&format!( + "Gradient - Color stop offset with index {}", + index + )); + + let color = unsafe { + gl.get_uniform_location( + program, + &format!("color_stop_colors[{}]", index), + ) + } + .expect(&format!( + "Gradient - Color stop colors with index {}", + index + )); + + ColorStopLocation { color, offset } + }); + + GradientUniformData { + current_gradient: Gradient::Linear(Linear { + start: Default::default(), + end: Default::default(), + color_stops: vec![], + }), + uniform_locations: GradientUniformLocations { + gradient_start_location, + gradient_end_location, + color_stops_size_location, + color_stops_locations, + }, + } + } +} -- 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/gradient.rs | 92 ++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 40 deletions(-) (limited to 'glow/src/triangle/gradient.rs') diff --git a/glow/src/triangle/gradient.rs b/glow/src/triangle/gradient.rs index d1b10d77..547871e2 100644 --- a/glow/src/triangle/gradient.rs +++ b/glow/src/triangle/gradient.rs @@ -1,18 +1,42 @@ use crate::program::Version; -use crate::triangle::{simple_triangle_program, update_transform}; +use crate::triangle::{simple_triangle_program, set_transform}; use glow::{Context, HasContext, NativeProgram}; +use iced_graphics::gradient::Linear; use iced_graphics::gradient::Gradient; -use iced_graphics::widget::canvas::gradient::Linear; use iced_graphics::Transformation; #[derive(Debug)] -pub(super) struct GradientProgram { - pub(super) program: ::Program, - pub(super) uniform_data: GradientUniformData, +pub struct GradientProgram { + pub program: ::Program, + pub uniform_data: GradientUniformData, +} + +#[derive(Debug)] +pub struct GradientUniformData { + gradient: Gradient, + transform: Transformation, + uniform_locations: GradientUniformLocations, +} + +#[derive(Debug)] +struct GradientUniformLocations { + gradient_start_location: ::UniformLocation, + gradient_end_location: ::UniformLocation, + color_stops_size_location: ::UniformLocation, + //currently the maximum number of stops is 64 due to needing to allocate the + //memory for the array of stops with a const value in GLSL + color_stops_locations: [ColorStopLocation; 64], + transform_location: ::UniformLocation, +} + +#[derive(Copy, Debug, Clone)] +struct ColorStopLocation { + color: ::UniformLocation, + offset: ::UniformLocation, } impl GradientProgram { - pub(super) fn new(gl: &Context, shader_version: &Version) -> Self { + pub fn new(gl: &Context, shader_version: &Version) -> Self { let program = simple_triangle_program( gl, shader_version, @@ -25,15 +49,17 @@ impl GradientProgram { } } - pub(super) fn set_uniforms<'a>( + pub fn write_uniforms( &mut self, gl: &Context, gradient: &Gradient, - transform: Option, + transform: &Transformation, ) { - update_transform(gl, self.program, transform); + if transform != &self.uniform_data.transform { + set_transform(gl, self.uniform_data.uniform_locations.transform_location, *transform); + } - if &self.uniform_data.current_gradient != gradient { + if &self.uniform_data.gradient != gradient { match gradient { Gradient::Linear(linear) => { let gradient_start: [f32; 2] = (linear.start).into(); @@ -104,31 +130,17 @@ impl GradientProgram { } } - self.uniform_data.current_gradient = gradient.clone(); + self.uniform_data.gradient = gradient.clone(); } } -} - -#[derive(Debug)] -pub(super) struct GradientUniformData { - current_gradient: Gradient, - uniform_locations: GradientUniformLocations, -} -#[derive(Debug)] -struct GradientUniformLocations { - gradient_start_location: ::UniformLocation, - gradient_end_location: ::UniformLocation, - color_stops_size_location: ::UniformLocation, - //currently the maximum number of stops is 64 due to needing to allocate the - //memory for the array of stops with a const value in GLSL - color_stops_locations: [ColorStopLocation; 64], -} + pub fn use_program(&mut self, gl: &glow::Context, gradient: &Gradient, transform: &Transformation) { + unsafe { + gl.use_program(Some(self.program)) + } -#[derive(Copy, Debug, Clone)] -struct ColorStopLocation { - color: ::UniformLocation, - offset: ::UniformLocation, + self.write_uniforms(gl, gradient, transform); + } } impl GradientUniformData { @@ -153,10 +165,7 @@ impl GradientUniformData { &format!("color_stop_offsets[{}]", index), ) } - .expect(&format!( - "Gradient - Color stop offset with index {}", - index - )); + .expect("Gradient - Color stop offset location."); let color = unsafe { gl.get_uniform_location( @@ -164,25 +173,28 @@ impl GradientUniformData { &format!("color_stop_colors[{}]", index), ) } - .expect(&format!( - "Gradient - Color stop colors with index {}", - index - )); + .expect("Gradient - Color stop color location."); ColorStopLocation { color, offset } }); + let transform_location = + unsafe { gl.get_uniform_location(program, "u_Transform") } + .expect("Get transform location."); + GradientUniformData { - current_gradient: Gradient::Linear(Linear { + gradient: Gradient::Linear(Linear { start: Default::default(), end: Default::default(), color_stops: vec![], }), + transform: Transformation::identity(), uniform_locations: GradientUniformLocations { gradient_start_location, gradient_end_location, color_stops_size_location, color_stops_locations, + transform_location, }, } } -- cgit From 1eb8d972ba60592da7bfc27fe7ec80138e64dd7b Mon Sep 17 00:00:00 2001 From: shan Date: Wed, 5 Oct 2022 16:07:43 -0700 Subject: Reduced memory transfer of OpenGL gradient uniform upload. Rearranged gradient uniforms on OpenGL side to be more performant. --- glow/src/triangle/gradient.rs | 143 +++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 92 deletions(-) (limited to 'glow/src/triangle/gradient.rs') diff --git a/glow/src/triangle/gradient.rs b/glow/src/triangle/gradient.rs index 547871e2..4b157890 100644 --- a/glow/src/triangle/gradient.rs +++ b/glow/src/triangle/gradient.rs @@ -1,8 +1,8 @@ use crate::program::Version; -use crate::triangle::{simple_triangle_program, set_transform}; +use crate::triangle::{set_transform, simple_triangle_program}; use glow::{Context, HasContext, NativeProgram}; -use iced_graphics::gradient::Linear; use iced_graphics::gradient::Gradient; +use iced_graphics::gradient::Linear; use iced_graphics::Transformation; #[derive(Debug)] @@ -20,21 +20,14 @@ pub struct GradientUniformData { #[derive(Debug)] struct GradientUniformLocations { - gradient_start_location: ::UniformLocation, - gradient_end_location: ::UniformLocation, + gradient_direction_location: ::UniformLocation, color_stops_size_location: ::UniformLocation, //currently the maximum number of stops is 64 due to needing to allocate the //memory for the array of stops with a const value in GLSL - color_stops_locations: [ColorStopLocation; 64], + color_stops_location: ::UniformLocation, transform_location: ::UniformLocation, } -#[derive(Copy, Debug, Clone)] -struct ColorStopLocation { - color: ::UniformLocation, - offset: ::UniformLocation, -} - impl GradientProgram { pub fn new(gl: &Context, shader_version: &Version) -> Self { let program = simple_triangle_program( @@ -56,76 +49,60 @@ impl GradientProgram { transform: &Transformation, ) { if transform != &self.uniform_data.transform { - set_transform(gl, self.uniform_data.uniform_locations.transform_location, *transform); + set_transform( + gl, + self.uniform_data.uniform_locations.transform_location, + *transform, + ); } if &self.uniform_data.gradient != gradient { match gradient { Gradient::Linear(linear) => { - let gradient_start: [f32; 2] = (linear.start).into(); - let gradient_end: [f32; 2] = (linear.end).into(); - unsafe { - gl.uniform_2_f32( + gl.uniform_4_f32( Some( - &self - .uniform_data - .uniform_locations - .gradient_start_location, + &self.uniform_data.uniform_locations.gradient_direction_location ), - gradient_start[0], - gradient_start[1], + linear.start.x, + linear.start.y, + linear.end.x, + linear.end.y ); - gl.uniform_2_f32( + gl.uniform_1_u32( Some( &self .uniform_data .uniform_locations - .gradient_end_location, + .color_stops_size_location, ), - gradient_end[0], - gradient_end[1], + (linear.color_stops.len() * 2) as u32, ); - gl.uniform_1_u32( + let mut stops = [0.0; 128]; + + for (index, stop) in linear.color_stops.iter().enumerate() { + if index == 16 { break; } + stops[index*8] = stop.color.r; + stops[(index*8)+1] = stop.color.g; + stops[(index*8)+2] = stop.color.b; + stops[(index*8)+3] = stop.color.a; + stops[(index*8)+4] = stop.offset; + stops[(index*8)+5] = 0.; + stops[(index*8)+6] = 0.; + stops[(index*8)+7] = 0.; + } + + gl.uniform_4_f32_slice( Some( &self .uniform_data .uniform_locations - .color_stops_size_location, + .color_stops_location, ), - linear.color_stops.len() as u32, + &stops, ); - - for (index, stop) in - linear.color_stops.iter().enumerate() - { - gl.uniform_1_f32( - Some( - &self - .uniform_data - .uniform_locations - .color_stops_locations[index] - .offset, - ), - stop.offset, - ); - - gl.uniform_4_f32( - Some( - &self - .uniform_data - .uniform_locations - .color_stops_locations[index] - .color, - ), - stop.color.r, - stop.color.g, - stop.color.b, - stop.color.a, - ); - } } } } @@ -134,10 +111,13 @@ impl GradientProgram { } } - pub fn use_program(&mut self, gl: &glow::Context, gradient: &Gradient, transform: &Transformation) { - unsafe { - gl.use_program(Some(self.program)) - } + pub fn use_program( + &mut self, + gl: &Context, + gradient: &Gradient, + transform: &Transformation, + ) { + unsafe { gl.use_program(Some(self.program)) } self.write_uniforms(gl, gradient, transform); } @@ -145,38 +125,18 @@ impl GradientProgram { impl GradientUniformData { fn new(gl: &Context, program: NativeProgram) -> Self { - let gradient_start_location = - unsafe { gl.get_uniform_location(program, "gradient_start") } - .expect("Gradient - Get gradient_start."); - - let gradient_end_location = - unsafe { gl.get_uniform_location(program, "gradient_end") } - .expect("Gradient - Get gradient_end."); + let gradient_direction_location = + unsafe { gl.get_uniform_location(program, "gradient_direction") } + .expect("Gradient - Get gradient_direction."); let color_stops_size_location = unsafe { gl.get_uniform_location(program, "color_stops_size") } .expect("Gradient - Get color_stops_size."); - let color_stops_locations: [ColorStopLocation; 64] = - core::array::from_fn(|index| { - let offset = unsafe { - gl.get_uniform_location( - program, - &format!("color_stop_offsets[{}]", index), - ) - } - .expect("Gradient - Color stop offset location."); - - let color = unsafe { - gl.get_uniform_location( - program, - &format!("color_stop_colors[{}]", index), - ) - } - .expect("Gradient - Color stop color location."); - - ColorStopLocation { color, offset } - }); + let color_stops_location = unsafe { + gl.get_uniform_location(program, "color_stops") + .expect("Gradient - Get color_stops.") + }; let transform_location = unsafe { gl.get_uniform_location(program, "u_Transform") } @@ -190,10 +150,9 @@ impl GradientUniformData { }), transform: Transformation::identity(), uniform_locations: GradientUniformLocations { - gradient_start_location, - gradient_end_location, + gradient_direction_location, color_stops_size_location, - color_stops_locations, + color_stops_location, transform_location, }, } -- 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/gradient.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'glow/src/triangle/gradient.rs') diff --git a/glow/src/triangle/gradient.rs b/glow/src/triangle/gradient.rs index 4b157890..a8bb5ec5 100644 --- a/glow/src/triangle/gradient.rs +++ b/glow/src/triangle/gradient.rs @@ -22,8 +22,7 @@ pub struct GradientUniformData { struct GradientUniformLocations { gradient_direction_location: ::UniformLocation, color_stops_size_location: ::UniformLocation, - //currently the maximum number of stops is 64 due to needing to allocate the - //memory for the array of stops with a const value in GLSL + //currently the maximum number of stops is 16 due to lack of SSBO in GL2.1 color_stops_location: ::UniformLocation, transform_location: ::UniformLocation, } @@ -140,7 +139,7 @@ impl GradientUniformData { let transform_location = unsafe { gl.get_uniform_location(program, "u_Transform") } - .expect("Get transform location."); + .expect("Gradient - Get u_Transform."); GradientUniformData { gradient: Gradient::Linear(Linear { -- 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/gradient.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'glow/src/triangle/gradient.rs') diff --git a/glow/src/triangle/gradient.rs b/glow/src/triangle/gradient.rs index a8bb5ec5..6bca44ee 100644 --- a/glow/src/triangle/gradient.rs +++ b/glow/src/triangle/gradient.rs @@ -1,25 +1,25 @@ use crate::program::Version; -use crate::triangle::{set_transform, simple_triangle_program}; +use crate::triangle; use glow::{Context, HasContext, NativeProgram}; use iced_graphics::gradient::Gradient; use iced_graphics::gradient::Linear; use iced_graphics::Transformation; #[derive(Debug)] -pub struct GradientProgram { +pub struct Program { pub program: ::Program, - pub uniform_data: GradientUniformData, + pub uniform_data: UniformData, } #[derive(Debug)] -pub struct GradientUniformData { +pub struct UniformData { gradient: Gradient, transform: Transformation, - uniform_locations: GradientUniformLocations, + uniform_locations: UniformLocations, } #[derive(Debug)] -struct GradientUniformLocations { +struct UniformLocations { gradient_direction_location: ::UniformLocation, color_stops_size_location: ::UniformLocation, //currently the maximum number of stops is 16 due to lack of SSBO in GL2.1 @@ -27,9 +27,9 @@ struct GradientUniformLocations { transform_location: ::UniformLocation, } -impl GradientProgram { +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/gradient.frag"), @@ -37,7 +37,7 @@ impl GradientProgram { Self { program, - uniform_data: GradientUniformData::new(gl, program), + uniform_data: UniformData::new(gl, program), } } @@ -48,7 +48,7 @@ impl GradientProgram { transform: &Transformation, ) { if transform != &self.uniform_data.transform { - set_transform( + triangle::set_transform( gl, self.uniform_data.uniform_locations.transform_location, *transform, @@ -117,12 +117,11 @@ impl GradientProgram { transform: &Transformation, ) { unsafe { gl.use_program(Some(self.program)) } - self.write_uniforms(gl, gradient, transform); } } -impl GradientUniformData { +impl UniformData { fn new(gl: &Context, program: NativeProgram) -> Self { let gradient_direction_location = unsafe { gl.get_uniform_location(program, "gradient_direction") } @@ -141,14 +140,14 @@ impl GradientUniformData { unsafe { gl.get_uniform_location(program, "u_Transform") } .expect("Gradient - Get u_Transform."); - GradientUniformData { + Self { gradient: Gradient::Linear(Linear { start: Default::default(), end: Default::default(), color_stops: vec![], }), transform: Transformation::identity(), - uniform_locations: GradientUniformLocations { + uniform_locations: UniformLocations { gradient_direction_location, color_stops_size_location, color_stops_location, -- cgit From 67ab4fd8c0ebd0e1e638307c6b303cce5cc13e9c Mon Sep 17 00:00:00 2001 From: bungoboingo Date: Tue, 18 Oct 2022 18:05:53 -0700 Subject: Updated syntax for color stop iteration re: PR comments. --- glow/src/triangle/gradient.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'glow/src/triangle/gradient.rs') diff --git a/glow/src/triangle/gradient.rs b/glow/src/triangle/gradient.rs index 6bca44ee..36e434e3 100644 --- a/glow/src/triangle/gradient.rs +++ b/glow/src/triangle/gradient.rs @@ -81,8 +81,7 @@ impl Program { let mut stops = [0.0; 128]; - for (index, stop) in linear.color_stops.iter().enumerate() { - if index == 16 { break; } + for (index, stop) in linear.color_stops.iter().enumerate().take(16) { stops[index*8] = stop.color.r; stops[(index*8)+1] = stop.color.g; stops[(index*8)+2] = stop.color.b; -- cgit From b95745340441835bd25b5cadc2342254631f8c05 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 3 Nov 2022 04:35:16 +0100 Subject: Run `cargo fmt` --- glow/src/triangle/gradient.rs | 93 ++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 45 deletions(-) (limited to 'glow/src/triangle/gradient.rs') diff --git a/glow/src/triangle/gradient.rs b/glow/src/triangle/gradient.rs index 36e434e3..ad41dffd 100644 --- a/glow/src/triangle/gradient.rs +++ b/glow/src/triangle/gradient.rs @@ -57,52 +57,55 @@ impl Program { if &self.uniform_data.gradient != gradient { match gradient { - Gradient::Linear(linear) => { - unsafe { - gl.uniform_4_f32( - Some( - &self.uniform_data.uniform_locations.gradient_direction_location - ), - linear.start.x, - linear.start.y, - linear.end.x, - linear.end.y - ); - - gl.uniform_1_u32( - Some( - &self - .uniform_data - .uniform_locations - .color_stops_size_location, - ), - (linear.color_stops.len() * 2) as u32, - ); - - let mut stops = [0.0; 128]; - - for (index, stop) in linear.color_stops.iter().enumerate().take(16) { - stops[index*8] = stop.color.r; - stops[(index*8)+1] = stop.color.g; - stops[(index*8)+2] = stop.color.b; - stops[(index*8)+3] = stop.color.a; - stops[(index*8)+4] = stop.offset; - stops[(index*8)+5] = 0.; - stops[(index*8)+6] = 0.; - stops[(index*8)+7] = 0.; - } - - gl.uniform_4_f32_slice( - Some( - &self - .uniform_data - .uniform_locations - .color_stops_location, - ), - &stops, - ); + Gradient::Linear(linear) => unsafe { + gl.uniform_4_f32( + Some( + &self + .uniform_data + .uniform_locations + .gradient_direction_location, + ), + linear.start.x, + linear.start.y, + linear.end.x, + linear.end.y, + ); + + gl.uniform_1_u32( + Some( + &self + .uniform_data + .uniform_locations + .color_stops_size_location, + ), + (linear.color_stops.len() * 2) as u32, + ); + + let mut stops = [0.0; 128]; + + for (index, stop) in + linear.color_stops.iter().enumerate().take(16) + { + stops[index * 8] = stop.color.r; + stops[(index * 8) + 1] = stop.color.g; + stops[(index * 8) + 2] = stop.color.b; + stops[(index * 8) + 3] = stop.color.a; + stops[(index * 8) + 4] = stop.offset; + stops[(index * 8) + 5] = 0.; + stops[(index * 8) + 6] = 0.; + stops[(index * 8) + 7] = 0.; } - } + + gl.uniform_4_f32_slice( + Some( + &self + .uniform_data + .uniform_locations + .color_stops_location, + ), + &stops, + ); + }, } self.uniform_data.gradient = gradient.clone(); -- cgit From 9a02d60ba51a91049466caa46db73d741520e051 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 3 Nov 2022 04:41:27 +0100 Subject: Convert colors to linear RGB in `gradient` pipelines --- glow/src/triangle/gradient.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'glow/src/triangle/gradient.rs') diff --git a/glow/src/triangle/gradient.rs b/glow/src/triangle/gradient.rs index ad41dffd..5225612e 100644 --- a/glow/src/triangle/gradient.rs +++ b/glow/src/triangle/gradient.rs @@ -86,10 +86,12 @@ impl Program { for (index, stop) in linear.color_stops.iter().enumerate().take(16) { - stops[index * 8] = stop.color.r; - stops[(index * 8) + 1] = stop.color.g; - stops[(index * 8) + 2] = stop.color.b; - stops[(index * 8) + 3] = stop.color.a; + let [r, g, b, a] = stop.color.into_linear(); + + stops[index * 8] = r; + stops[(index * 8) + 1] = g; + stops[(index * 8) + 2] = b; + stops[(index * 8) + 3] = a; stops[(index * 8) + 4] = stop.offset; stops[(index * 8) + 5] = 0.; stops[(index * 8) + 6] = 0.; -- cgit