summaryrefslogtreecommitdiffstats
path: root/glow/src/quad.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-05-19 22:55:12 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-05-19 23:19:39 +0200
commit720e7756f2afe30706b6b1a7fbde86b9f15e1d8c (patch)
tree3a55248a4b25654b1d63b8c547fd0f653471606d /glow/src/quad.rs
parente6180912488db4d59fbffcb46c5930282306cb92 (diff)
downloadiced-720e7756f2afe30706b6b1a7fbde86b9f15e1d8c.tar.gz
iced-720e7756f2afe30706b6b1a7fbde86b9f15e1d8c.tar.bz2
iced-720e7756f2afe30706b6b1a7fbde86b9f15e1d8c.zip
Move `Layer` to `iced_graphics`
Diffstat (limited to 'glow/src/quad.rs')
-rw-r--r--glow/src/quad.rs33
1 files changed, 9 insertions, 24 deletions
diff --git a/glow/src/quad.rs b/glow/src/quad.rs
index 744597d2..26424b39 100644
--- a/glow/src/quad.rs
+++ b/glow/src/quad.rs
@@ -1,7 +1,10 @@
use crate::{Transformation, Viewport};
use glow::HasContext;
+use iced_graphics::layer;
use iced_native::Rectangle;
+const MAX_INSTANCES: usize = 100_000;
+
#[derive(Debug)]
pub struct Pipeline {
program: <glow::Context as HasContext>::Program,
@@ -37,7 +40,7 @@ impl Pipeline {
}
let (vertex_array, instances) =
- unsafe { create_instance_buffer(gl, Quad::MAX) };
+ unsafe { create_instance_buffer(gl, MAX_INSTANCES) };
Pipeline {
program,
@@ -52,7 +55,7 @@ impl Pipeline {
&mut self,
gl: &glow::Context,
viewport: &Viewport,
- instances: &[Quad],
+ instances: &[layer::Quad],
transformation: Transformation,
scale: f32,
bounds: Rectangle<u32>,
@@ -97,7 +100,7 @@ impl Pipeline {
let total = instances.len();
while i < total {
- let end = (i + Quad::MAX).min(total);
+ let end = (i + MAX_INSTANCES).min(total);
let amount = end - i;
unsafe {
@@ -115,7 +118,7 @@ impl Pipeline {
);
}
- i += Quad::MAX;
+ i += MAX_INSTANCES;
}
unsafe {
@@ -126,24 +129,6 @@ impl Pipeline {
}
}
-#[derive(Debug, Clone, Copy)]
-#[repr(C)]
-pub struct Quad {
- pub position: [f32; 2],
- pub scale: [f32; 2],
- pub color: [f32; 4],
- pub border_color: [f32; 4],
- pub border_radius: f32,
- pub border_width: f32,
-}
-
-unsafe impl bytemuck::Zeroable for Quad {}
-unsafe impl bytemuck::Pod for Quad {}
-
-impl Quad {
- const MAX: usize = 100_000;
-}
-
unsafe fn create_program(
gl: &glow::Context,
shader_sources: &[(u32, &str)],
@@ -196,11 +181,11 @@ unsafe fn create_instance_buffer(
gl.bind_buffer(glow::ARRAY_BUFFER, Some(buffer));
gl.buffer_data_size(
glow::ARRAY_BUFFER,
- (size * std::mem::size_of::<Quad>()) as i32,
+ (size * std::mem::size_of::<layer::Quad>()) as i32,
glow::DYNAMIC_DRAW,
);
- let stride = std::mem::size_of::<Quad>() as i32;
+ let stride = std::mem::size_of::<layer::Quad>() as i32;
gl.enable_vertex_attrib_array(0);
gl.vertex_attrib_pointer_f32(0, 2, glow::FLOAT, false, stride, 0);