Store paints in the paint texture indexed by paint ID, not object index

This commit is contained in:
Patrick Walton 2019-05-14 15:21:15 -07:00
parent 7a02b78b3d
commit 86f5bdb44a
4 changed files with 21 additions and 15 deletions

View File

@ -81,8 +81,9 @@ impl<'a> SceneBuilder<'a> {
) -> Vec<AlphaTileBatchPrimitive> {
let path_object = &scene.paths[path_index];
let outline = scene.apply_render_options(path_object.outline(), built_options);
let paint_id = path_object.paint();
let mut tiler = Tiler::new(self, &outline, view_box, path_index as u16);
let mut tiler = Tiler::new(self, &outline, view_box, paint_id, path_index as u16);
tiler.generate_tiles();
self.listener.send(RenderCommand::AddFills(tiler.built_object.fills));
@ -108,7 +109,7 @@ impl<'a> SceneBuilder<'a> {
fn pack_alpha_tiles(&mut self, alpha_tiles: Vec<AlphaTileBatchPrimitive>) {
let path_count = self.scene.paths.len() as u32;
let solid_tiles = self.z_buffer.build_solid_tiles(0..path_count);
let solid_tiles = self.z_buffer.build_solid_tiles(&self.scene.paths, 0..path_count);
if !solid_tiles.is_empty() {
self.listener.send(RenderCommand::SolidTile(solid_tiles));
}

View File

@ -9,7 +9,7 @@
// except according to those terms.
use crate::gpu_data::PaintData;
use crate::scene::Scene;
use crate::scene::{PaintId, Scene};
use pathfinder_geometry::basic::point::Point2DI32;
const PAINT_TEXTURE_WIDTH: i32 = 256;
@ -19,19 +19,18 @@ impl Scene {
pub fn build_paint_data(&self) -> PaintData {
let size = Point2DI32::new(PAINT_TEXTURE_WIDTH, PAINT_TEXTURE_HEIGHT);
let mut texels = vec![0; size.x() as usize * size.y() as usize * 4];
for (path_object_index, path_object) in self.paths.iter().enumerate() {
let paint = &self.paints[path_object.paint().0 as usize];
texels[path_object_index * 4 + 0] = paint.color.r;
texels[path_object_index * 4 + 1] = paint.color.g;
texels[path_object_index * 4 + 2] = paint.color.b;
texels[path_object_index * 4 + 3] = paint.color.a;
for (paint_index, paint) in self.paints.iter().enumerate() {
texels[paint_index * 4 + 0] = paint.color.r;
texels[paint_index * 4 + 1] = paint.color.g;
texels[paint_index * 4 + 2] = paint.color.b;
texels[paint_index * 4 + 3] = paint.color.a;
}
PaintData { size, texels }
}
}
pub(crate) fn object_index_to_paint_coords(object_index: u16) -> Point2DI32 {
let tex_coords = Point2DI32::new(object_index as i32 % PAINT_TEXTURE_WIDTH,
object_index as i32 / PAINT_TEXTURE_WIDTH);
pub(crate) fn paint_id_to_tex_coords(paint_id: PaintId) -> Point2DI32 {
let tex_coords = Point2DI32::new(paint_id.0 as i32 % PAINT_TEXTURE_WIDTH,
paint_id.0 as i32 / PAINT_TEXTURE_WIDTH);
tex_coords.scale(256) + Point2DI32::new(128, 128)
}

View File

@ -11,6 +11,7 @@
use crate::builder::SceneBuilder;
use crate::gpu_data::{AlphaTileBatchPrimitive, BuiltObject, TileObjectPrimitive};
use crate::paint;
use crate::scene::PaintId;
use crate::sorted_vector::SortedVector;
use pathfinder_geometry::basic::line_segment::LineSegmentF32;
use pathfinder_geometry::basic::point::{Point2DF32, Point2DI32};
@ -30,6 +31,7 @@ pub(crate) struct Tiler<'a> {
builder: &'a SceneBuilder<'a>,
outline: &'a Outline,
pub built_object: BuiltObject,
paint_id: PaintId,
object_index: u16,
point_queue: SortedVector<QueuedEndpoint>,
@ -43,6 +45,7 @@ impl<'a> Tiler<'a> {
builder: &'a SceneBuilder<'a>,
outline: &'a Outline,
view_box: RectF32,
paint_id: PaintId,
object_index: u16,
) -> Tiler<'a> {
let bounds = outline
@ -55,6 +58,7 @@ impl<'a> Tiler<'a> {
builder,
outline,
built_object,
paint_id,
object_index,
point_queue: SortedVector::new(),
@ -115,7 +119,7 @@ impl<'a> Tiler<'a> {
continue;
}
let origin_uv = paint::object_index_to_paint_coords(self.object_index);
let origin_uv = paint::paint_id_to_tex_coords(self.paint_id);
let alpha_tile = AlphaTileBatchPrimitive::new(
tile_coords,

View File

@ -12,6 +12,7 @@
use crate::gpu_data::SolidTileBatchPrimitive;
use crate::paint;
use crate::scene::PathObject;
use crate::tile_map::DenseTileMap;
use crate::tiles;
use pathfinder_geometry::basic::point::Point2DI32;
@ -55,7 +56,8 @@ impl ZBuffer {
}
}
pub fn build_solid_tiles(&self, object_range: Range<u32>) -> Vec<SolidTileBatchPrimitive> {
pub fn build_solid_tiles(&self, paths: &[PathObject], object_range: Range<u32>)
-> Vec<SolidTileBatchPrimitive> {
let mut solid_tiles = vec![];
for tile_index in 0..self.buffer.data.len() {
let depth = self.buffer.data[tile_index].load(AtomicOrdering::Relaxed);
@ -69,7 +71,7 @@ impl ZBuffer {
continue;
}
let origin_uv = paint::object_index_to_paint_coords(object_index as u16);
let origin_uv = paint::paint_id_to_tex_coords(paths[object_index as usize].paint());
solid_tiles.push(SolidTileBatchPrimitive::new(tile_coords + self.buffer.rect.origin(),
object_index as u16,