Adds linear gradient support to 2D meshes in the canvas widget.
This commit is contained in:
parent
97f385e093
commit
40f45d7b7e
40 changed files with 2041 additions and 655 deletions
67
glow/src/triangle/solid.rs
Normal file
67
glow/src/triangle/solid.rs
Normal file
|
|
@ -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: <Context as HasContext>::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<Transformation>,
|
||||
) {
|
||||
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: <Context as HasContext>::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."),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue