Shapes on glium backend

This commit is contained in:
Mike Welsh 2019-04-27 20:58:33 -07:00
parent b7ac6dc2ce
commit 2609d8c00d
2 changed files with 40 additions and 36 deletions

View File

@ -1,5 +1,5 @@
[package] [package]
name = "fluster" name = "fluster_desktop"
version = "0.1.0" version = "0.1.0"
authors = ["Mike Welsh <mwelsh@gmail.com>"] authors = ["Mike Welsh <mwelsh@gmail.com>"]
edition = "2018" edition = "2018"

View File

@ -37,42 +37,44 @@ impl RenderBackend for GliumRenderBackend {
use lyon::tessellation::FillOptions; use lyon::tessellation::FillOptions;
// let mut mesh: VertexBuffers<_, u16> = VertexBuffers::new(); let mut mesh: VertexBuffers<_, u32> = VertexBuffers::new();
// let paths = swf_shape_to_lyon_paths(shape); let paths = swf_shape_to_lyon_paths(shape);
// let fill_tess = FillTessellator::new(); let mut fill_tess = FillTessellator::new();
// for path in paths {
// let mut buffers_builder = BuffersBuilder::new(&mut mesh, ());
// fill_tess.tessellate_path(
// path.into_iter(),
// &FillOptions::even_odd(),
// &mut buffers_builder,
// );
// }
let vertices = vec![ for (cmd, path) in paths {
Vertex { if let &PathCommandType::Stroke(_) = &cmd {
position: [0.0, 0.0], continue;
color: [1.0, 0.0, 0.0, 1.0], }
}, let color = match cmd {
Vertex { PathCommandType::Fill(FillStyle::Color(color)) => [
position: [100.0, 0.0], f32::from(color.r) / 255.0,
color: [1.0, 0.0, 0.0, 1.0], f32::from(color.g) / 255.0,
}, f32::from(color.b) / 255.0,
Vertex { f32::from(color.a) / 255.0,
position: [100.0, 100.0], ],
color: [1.0, 0.0, 0.0, 1.0], PathCommandType::Fill(_) => [1.0, 0.0, 0.0, 1.0],
}, PathCommandType::Stroke(_) => unreachable!(),
Vertex { };
position: [0.0, 100.0], let vertex_ctor = move |vertex: tessellation::FillVertex| Vertex {
color: [1.0, 0.0, 0.0, 1.0], position: [vertex.position.x, vertex.position.y],
}, color,
]; };
let indices = vec![0, 1, 2, 0, 2, 3];
let vertex_buffer = glium::VertexBuffer::new(&self.display, &vertices).unwrap(); let mut buffers_builder = BuffersBuilder::new(&mut mesh, vertex_ctor);
fill_tess
.tessellate_path(
path.into_iter(),
&FillOptions::even_odd(),
&mut buffers_builder,
)
.expect("Tessellation error");
}
let vertex_buffer = glium::VertexBuffer::new(&self.display, &mesh.vertices[..]).unwrap();
let index_buffer = glium::IndexBuffer::new( let index_buffer = glium::IndexBuffer::new(
&self.display, &self.display,
glium::index::PrimitiveType::TrianglesList, glium::index::PrimitiveType::TrianglesList,
&indices, &mesh.indices[..],
) )
.unwrap(); .unwrap();
@ -178,13 +180,15 @@ fn point(x: f32, y: f32) -> lyon::math::Point {
lyon::math::Point::new(x, y) lyon::math::Point::new(x, y)
} }
fn swf_shape_to_lyon_paths(shape: &swf::Shape) -> Vec<Vec<lyon::path::PathEvent>> { fn swf_shape_to_lyon_paths(
shape: &swf::Shape,
) -> Vec<(PathCommandType, Vec<lyon::path::PathEvent>)> {
let cmds = get_paths(shape); let cmds = get_paths(shape);
let mut out_paths = vec![]; let mut out_paths = vec![];
let mut prev; let mut prev;
use lyon::geom::{LineSegment, QuadraticBezierSegment}; use lyon::geom::{LineSegment, QuadraticBezierSegment};
for cmd in cmds { for cmd in cmds {
if let PathCommandType::Fill(fill_style) = cmd.command_type { if let PathCommandType::Fill(fill_style) = &cmd.command_type {
let mut out_path = vec![PathEvent::MoveTo(point(cmd.path.start.0, cmd.path.start.1))]; let mut out_path = vec![PathEvent::MoveTo(point(cmd.path.start.0, cmd.path.start.1))];
prev = point(cmd.path.start.0, cmd.path.start.1); prev = point(cmd.path.start.0, cmd.path.start.1);
for edge in cmd.path.edges { for edge in cmd.path.edges {
@ -213,7 +217,7 @@ fn swf_shape_to_lyon_paths(shape: &swf::Shape) -> Vec<Vec<lyon::path::PathEvent>
from: prev, from: prev,
to: prev, to: prev,
})); }));
out_paths.push(out_path); out_paths.push((cmd.command_type, out_path));
} }
} }
out_paths out_paths