|
|
@ -52,7 +52,6 @@ function do_lod_wasm(state, context) { |
|
|
|
const segments_from = state.wasm.exports.alloc((context.clipped_indices.size + 1) * 4); |
|
|
|
const segments_from = state.wasm.exports.alloc((context.clipped_indices.size + 1) * 4); |
|
|
|
const segments = state.wasm.exports.alloc(state.segments.capacity * 4); |
|
|
|
const segments = state.wasm.exports.alloc(state.segments.capacity * 4); |
|
|
|
const coordinates = state.wasm.exports.alloc(state.coordinates.size * 4); |
|
|
|
const coordinates = state.wasm.exports.alloc(state.coordinates.size * 4); |
|
|
|
|
|
|
|
|
|
|
|
const mem = new Uint8Array(state.wasm.exports.memory.buffer); |
|
|
|
const mem = new Uint8Array(state.wasm.exports.memory.buffer); |
|
|
|
|
|
|
|
|
|
|
|
mem.set(tv_bytes(context.clipped_indices), clipped_indices); |
|
|
|
mem.set(tv_bytes(context.clipped_indices), clipped_indices); |
|
|
@ -71,6 +70,8 @@ function do_lod_wasm(state, context) { |
|
|
|
// copy result back
|
|
|
|
// copy result back
|
|
|
|
const wasm_segments = new Uint32Array(state.wasm.exports.memory.buffer, segments, segment_count); |
|
|
|
const wasm_segments = new Uint32Array(state.wasm.exports.memory.buffer, segments, segment_count); |
|
|
|
const wasm_segments_from = new Uint32Array(state.wasm.exports.memory.buffer, segments_from, context.clipped_indices.size + 1); |
|
|
|
const wasm_segments_from = new Uint32Array(state.wasm.exports.memory.buffer, segments_from, context.clipped_indices.size + 1); |
|
|
|
|
|
|
|
const wasm_points = new Float32Array(state.wasm.exports.memory.buffer, coordinates + state.coordinates.size * 4, segment_count * 2); |
|
|
|
|
|
|
|
const wasm_ids = new Uint32Array(state.wasm.exports.memory.buffer, coordinates + (state.coordinates.size + segment_count * 2) * 4, segment_count); |
|
|
|
|
|
|
|
|
|
|
|
state.segments.data.set(wasm_segments); |
|
|
|
state.segments.data.set(wasm_segments); |
|
|
|
state.segments.size = segment_count; |
|
|
|
state.segments.size = segment_count; |
|
|
@ -78,8 +79,16 @@ function do_lod_wasm(state, context) { |
|
|
|
state.segments_from.data.set(wasm_segments_from); |
|
|
|
state.segments_from.data.set(wasm_segments_from); |
|
|
|
state.segments_from.size = context.clipped_indices.size + 1; |
|
|
|
state.segments_from.size = context.clipped_indices.size + 1; |
|
|
|
|
|
|
|
|
|
|
|
state.wasm.exports.total_free(); |
|
|
|
tv_ensure(context.instance_data_points, segment_count * 2); |
|
|
|
|
|
|
|
tv_ensure(context.instance_data_ids, segment_count); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.instance_data_points.data.set(wasm_points); |
|
|
|
|
|
|
|
context.instance_data_points.size = segment_count * 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.instance_data_ids.data.set(wasm_ids); |
|
|
|
|
|
|
|
context.instance_data_ids.size = segment_count; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state.wasm.exports.total_free(); |
|
|
|
|
|
|
|
|
|
|
|
return segment_count; |
|
|
|
return segment_count; |
|
|
|
} |
|
|
|
} |
|
|
@ -164,5 +173,47 @@ function do_lod(state, context) { |
|
|
|
state.segments_from.size = context.clipped_indices.size + 1; |
|
|
|
state.segments_from.size = context.clipped_indices.size + 1; |
|
|
|
state.segments.size = segments_head; |
|
|
|
state.segments.size = segments_head; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
write_coordinates(state, context); |
|
|
|
|
|
|
|
|
|
|
|
return segments_head; |
|
|
|
return segments_head; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function write_coordinates(state, context) { |
|
|
|
|
|
|
|
tv_ensure(context.instance_data_points, state.segments.size * 2); |
|
|
|
|
|
|
|
tv_ensure(context.instance_data_ids, state.segments.size); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tv_clear(context.instance_data_points); |
|
|
|
|
|
|
|
tv_clear(context.instance_data_ids); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const clipped = context.clipped_indices.data; |
|
|
|
|
|
|
|
const segments_from = state.segments_from.data; |
|
|
|
|
|
|
|
const segments = state.segments.data; |
|
|
|
|
|
|
|
const coords = state.coordinates.data; |
|
|
|
|
|
|
|
const events = state.events; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: move this loop to WASM
|
|
|
|
|
|
|
|
for (let i = 0; i < state.segments_from.size - 1; ++i) { |
|
|
|
|
|
|
|
const stroke_index = clipped[i]; |
|
|
|
|
|
|
|
const coords_from = state.events[stroke_index].coords_from; |
|
|
|
|
|
|
|
const from = segments_from[i]; |
|
|
|
|
|
|
|
const to = segments_from[i + 1]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (let j = from; j < to; ++j) { |
|
|
|
|
|
|
|
const base_this = segments[j]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ax = coords[coords_from + base_this * 2 + 0]; |
|
|
|
|
|
|
|
const ay = coords[coords_from + base_this * 2 + 1]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tv_add(context.instance_data_points, ax); |
|
|
|
|
|
|
|
tv_add(context.instance_data_points, ay); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Pack 1 into highest bit of stroke_index if we should not draw a segemtn from this
|
|
|
|
|
|
|
|
// point to the next one
|
|
|
|
|
|
|
|
if (j != to - 1) { |
|
|
|
|
|
|
|
tv_add(context.instance_data_ids, stroke_index); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
tv_add(context.instance_data_ids, stroke_index | (1 << 31)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|