Do color lookups in a separate table

This commit is contained in:
Patrick Walton 2018-12-30 14:07:39 -08:00
parent 6e0e621d19
commit 028de44023
2 changed files with 22 additions and 4 deletions

View File

@ -312,7 +312,7 @@ class App {
redraw(): void { redraw(): void {
const gl = this.gl, canvas = this.canvas; const gl = this.gl, canvas = this.canvas;
console.log("viewBox", this.viewBox); //console.log("viewBox", this.viewBox);
// Start timer. // Start timer.
let timerQuery = null; let timerQuery = null;
@ -479,6 +479,10 @@ class App {
this.objectCount = subchunk.length() / 4; this.objectCount = subchunk.length() / 4;
gl.activeTexture(gl.TEXTURE0); gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, this.fillColorsTexture); gl.bindTexture(gl.TEXTURE_2D, this.fillColorsTexture);
const textureDataView = subchunk.contents();
const textureData = new Uint8Array(textureDataView.buffer,
textureDataView.byteOffset,
textureDataView.byteLength);
gl.texImage2D(gl.TEXTURE_2D, gl.texImage2D(gl.TEXTURE_2D,
0, 0,
gl.RGBA, gl.RGBA,
@ -487,7 +491,7 @@ class App {
0, 0,
gl.RGBA, gl.RGBA,
gl.UNSIGNED_BYTE, gl.UNSIGNED_BYTE,
subchunk.contents()); textureData);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);

View File

@ -1010,6 +1010,8 @@ impl<'o> Tiler<'o> {
for strip_origin_y in tile_rect.origin.y..tile_rect.max_y() { for strip_origin_y in tile_rect.origin.y..tile_rect.max_y() {
self.generate_strip(strip_origin_y); self.generate_strip(strip_origin_y);
} }
//println!("{:#?}", self.built_object);
} }
#[inline(never)] #[inline(never)]
@ -1029,6 +1031,8 @@ impl<'o> Tiler<'o> {
#[inline(never)] #[inline(never)]
fn process_old_active_edges(&mut self, tile_y: i16) { fn process_old_active_edges(&mut self, tile_y: i16) {
let tile_origin_y = tile_y as f32 * TILE_HEIGHT;
let mut current_tile_x = self.built_object.tile_rect.origin.x; let mut current_tile_x = self.built_object.tile_rect.origin.x;
let mut current_subtile_x = 0.0; let mut current_subtile_x = 0.0;
let mut current_winding = 0; let mut current_winding = 0;
@ -1058,7 +1062,8 @@ impl<'o> Tiler<'o> {
debug_assert!(current_tile_x < self.built_object.tile_rect.max_x()); debug_assert!(current_tile_x < self.built_object.tile_rect.max_x());
let current_x = (current_tile_x as f32) * TILE_WIDTH + current_subtile_x; let current_x = (current_tile_x as f32) * TILE_WIDTH + current_subtile_x;
if segment_x >= current_x { if segment_x >= current_x {
let (left, right) = (Point2D::new(current_x, 0.0), Point2D::new(segment_x, 0.0)); let left = Point2D::new(current_x, tile_origin_y);
let right = Point2D::new(segment_x, tile_origin_y);
self.built_object.add_fill(if edge_winding < 0 { &left } else { &right }, self.built_object.add_fill(if edge_winding < 0 { &left } else { &right },
if edge_winding < 0 { &right } else { &left }, if edge_winding < 0 { &right } else { &left },
current_tile_x, current_tile_x,
@ -1240,6 +1245,9 @@ impl BuiltScene {
} }
} }
} }
// Copy shader.
scene.shaders[object_index as usize] = object.shader;
} }
scene scene
@ -1349,8 +1357,14 @@ impl BuiltObject {
} }
fn add_fill(&mut self, from: &Point2D<f32>, to: &Point2D<f32>, tile_x: i16, tile_y: i16) { fn add_fill(&mut self, from: &Point2D<f32>, to: &Point2D<f32>, tile_x: i16, tile_y: i16) {
let tile_origin = Vector2D::new(tile_x as f32 * TILE_WIDTH, tile_y as f32 * TILE_HEIGHT);
let tile_index = self.tile_coords_to_index(tile_x, tile_y); let tile_index = self.tile_coords_to_index(tile_x, tile_y);
self.fills.push(FillObjectPrimitive { from: *from, to: *to, tile_x, tile_y }); self.fills.push(FillObjectPrimitive {
from: *from - tile_origin,
to: *to - tile_origin,
tile_x,
tile_y,
});
self.mask_tiles.insert(tile_index as usize); self.mask_tiles.insert(tile_index as usize);
} }