summaryrefslogtreecommitdiffstats
path: root/glow/src/triangle/solid.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2022-11-28 20:29:01 +0100
committerLibravatar GitHub <noreply@github.com>2022-11-28 20:29:01 +0100
commit8d67e21d48dcefbbb675cfad07849607ce0fe1b7 (patch)
tree58072c44539d4b7009fff3defe97834438234b1b /glow/src/triangle/solid.rs
parent457d0560caf91884b148422e1ace3d64a38e0e33 (diff)
parentbb2bf063b472396d44f9f3114a87ba79dfd5f62e (diff)
downloadiced-8d67e21d48dcefbbb675cfad07849607ce0fe1b7.tar.gz
iced-8d67e21d48dcefbbb675cfad07849607ce0fe1b7.tar.bz2
iced-8d67e21d48dcefbbb675cfad07849607ce0fe1b7.zip
Merge pull request #1538 from iced-rs/group-solid-triangles
Group all solid triangles independently of color
Diffstat (limited to '')
-rw-r--r--glow/src/triangle/solid.rs91
1 files changed, 0 insertions, 91 deletions
diff --git a/glow/src/triangle/solid.rs b/glow/src/triangle/solid.rs
deleted file mode 100644
index fb3d40c3..00000000
--- a/glow/src/triangle/solid.rs
+++ /dev/null
@@ -1,91 +0,0 @@
-use crate::program::Version;
-use crate::{triangle, Color};
-use glow::{Context, HasContext, NativeProgram};
-use iced_graphics::Transformation;
-
-#[derive(Debug)]
-pub struct Program {
- program: <Context as HasContext>::Program,
- uniform_data: UniformData,
-}
-
-#[derive(Debug)]
-struct UniformData {
- pub color: Color,
- pub color_location: <Context as HasContext>::UniformLocation,
- pub transform: Transformation,
- pub transform_location: <Context as HasContext>::UniformLocation,
-}
-
-impl UniformData {
- fn new(gl: &Context, program: NativeProgram) -> Self {
- Self {
- color: Color::TRANSPARENT,
- color_location: unsafe {
- gl.get_uniform_location(program, "color")
- }
- .expect("Solid - Get color."),
- transform: Transformation::identity(),
- transform_location: unsafe {
- gl.get_uniform_location(program, "u_Transform")
- }
- .expect("Solid - Get u_Transform."),
- }
- }
-}
-
-impl Program {
- pub fn new(gl: &Context, shader_version: &Version) -> Self {
- let program = triangle::program(
- gl,
- shader_version,
- include_str!("../shader/common/triangle.frag"),
- );
-
- Self {
- program,
- uniform_data: UniformData::new(gl, program),
- }
- }
-
- pub fn write_uniforms(
- &mut self,
- gl: &Context,
- color: &Color,
- transform: &Transformation,
- ) {
- if transform != &self.uniform_data.transform {
- triangle::set_transform(
- gl,
- self.uniform_data.transform_location,
- *transform,
- )
- }
-
- 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),
- r,
- g,
- b,
- a,
- );
- }
-
- self.uniform_data.color = *color;
- }
- }
-
- 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)
- }
-}