|
|
@ -1,7 +1,7 @@ |
|
|
|
async function init_wasm(state) { |
|
|
|
async function init_wasm(state) { |
|
|
|
const results = await WebAssembly.instantiateStreaming(fetch('wasm/lod.wasm')); |
|
|
|
const results = await WebAssembly.instantiateStreaming(fetch('wasm/lod.wasm')); |
|
|
|
state.wasm.exports = results.instance.exports; |
|
|
|
state.wasm.exports = results.instance.exports; |
|
|
|
state.wasm.exports.memory.grow(1024); |
|
|
|
state.wasm.exports.memory.grow(4096); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function rdp_find_max(state, zoom, coords_from, start, end) { |
|
|
|
function rdp_find_max(state, zoom, coords_from, start, end) { |
|
|
@ -45,6 +45,8 @@ function rdp_find_max(state, zoom, coords_from, start, end) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function do_lod_wasm(state, context) { |
|
|
|
function do_lod_wasm(state, context) { |
|
|
|
|
|
|
|
state.wasm.exports.total_free(); |
|
|
|
|
|
|
|
|
|
|
|
const clipped_indices = state.wasm.exports.alloc(context.clipped_indices.size * 4); |
|
|
|
const clipped_indices = state.wasm.exports.alloc(context.clipped_indices.size * 4); |
|
|
|
const stroke_coords_from = state.wasm.exports.alloc(state.coords_from.size * 4); |
|
|
|
const stroke_coords_from = state.wasm.exports.alloc(state.coords_from.size * 4); |
|
|
|
const stroke_coords_to = state.wasm.exports.alloc(state.coords_to.size * 4); |
|
|
|
const stroke_coords_to = state.wasm.exports.alloc(state.coords_to.size * 4); |
|
|
@ -68,28 +70,15 @@ 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_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_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); |
|
|
|
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.size = segment_count; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state.segments_from.data.set(wasm_segments_from); |
|
|
|
context.instance_data_points.data = wasm_points; |
|
|
|
state.segments_from.size = context.clipped_indices.size + 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_points.size = segment_count * 2; |
|
|
|
|
|
|
|
|
|
|
|
context.instance_data_ids.data.set(wasm_ids); |
|
|
|
context.instance_data_ids.data = wasm_ids; |
|
|
|
context.instance_data_ids.size = segment_count; |
|
|
|
context.instance_data_ids.size = segment_count; |
|
|
|
|
|
|
|
|
|
|
|
state.wasm.exports.total_free(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return segment_count; |
|
|
|
return segment_count; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|