Browse Source

Batching is working! (only in singethreaded mode though)

sdf
A.Olokhtonov 2 weeks ago
parent
commit
500fd71d3e
  1. 10
      client/client_recv.js
  2. 4
      client/wasm/lod.c
  3. BIN
      client/wasm/lod.wasm
  4. 5
      client/webgl_geometry.js

10
client/client_recv.js

@ -364,7 +364,7 @@ function handle_event(state, context, event, options = {}) {
} }
case EVENT.UNDO: { case EVENT.UNDO: {
geometry_add_dummy_stroke(context); geometry_add_dummy_stroke(state, context);
need_draw = undo(state, context, event, options); need_draw = undo(state, context, event, options);
break; break;
} }
@ -372,7 +372,7 @@ function handle_event(state, context, event, options = {}) {
case EVENT.IMAGE: { case EVENT.IMAGE: {
const p = {'x': event.x, 'y': event.y}; const p = {'x': event.x, 'y': event.y};
geometry_add_dummy_stroke(context); geometry_add_dummy_stroke(state, context);
add_image(context, event.image_id, null, p, event.width, event.height); add_image(context, event.image_id, null, p, event.width, event.height);
try { try {
@ -401,7 +401,7 @@ function handle_event(state, context, event, options = {}) {
} }
case EVENT.IMAGE_MOVE: { case EVENT.IMAGE_MOVE: {
geometry_add_dummy_stroke(context); geometry_add_dummy_stroke(state, context);
const image_id = event.image_id; const image_id = event.image_id;
const image = get_image(context, image_id); const image = get_image(context, image_id);
@ -415,7 +415,7 @@ function handle_event(state, context, event, options = {}) {
} }
case EVENT.IMAGE_SCALE: { case EVENT.IMAGE_SCALE: {
geometry_add_dummy_stroke(context); geometry_add_dummy_stroke(state, context);
const image_id = event.image_id; const image_id = event.image_id;
const image = get_image(context, image_id); const image = get_image(context, image_id);
@ -428,7 +428,7 @@ function handle_event(state, context, event, options = {}) {
} }
case EVENT.ERASER: { case EVENT.ERASER: {
geometry_add_dummy_stroke(context); geometry_add_dummy_stroke(state, context);
need_draw = true; need_draw = true;
const stroke = state.events[event.stroke_id]; const stroke = state.events[event.stroke_id];
stroke.deleted = true; stroke.deleted = true;

4
client/wasm/lod.c

@ -323,11 +323,11 @@ do_lod(int *clipped_indices, int clipped_count, float zoom,
// Compute recommended LOD level, add to current batch or start new batch // Compute recommended LOD level, add to current batch or start new batch
float sqrt_width = __builtin_sqrtf(width[stroke_index]); float sqrt_width = __builtin_sqrtf(width[stroke_index]);
int lod = __builtin_ceil(sqrt_zoom * sqrt_width * 0.3333f); // TODO: round int lod = __builtin_roundeven(sqrt_zoom * sqrt_width); // NOTE: there is no regular round, but is shouldn't matt:er
if (lod > 7) lod = 7; if (lod > 7) lod = 7;
if (batch_size > 0 && __builtin_abs(lod - last_lod) > 2) { if (batch_size > 0 && lod != last_lod) {
// Start new batch // Start new batch
batches[batch_count * 2 + 0] = batch_size; batches[batch_count * 2 + 0] = batch_size;
batches[batch_count * 2 + 1] = last_lod; batches[batch_count * 2 + 1] = last_lod;

BIN
client/wasm/lod.wasm

Binary file not shown.

5
client/webgl_geometry.js

@ -31,12 +31,15 @@ async function geometry_write_instances(state, context, callback) {
return segment_count; return segment_count;
} }
function geometry_add_dummy_stroke(context) { function geometry_add_dummy_stroke(state, context) {
context.stroke_data = ser_ensure_by(context.stroke_data, config.bytes_per_stroke); context.stroke_data = ser_ensure_by(context.stroke_data, config.bytes_per_stroke);
ser_u16(context.stroke_data, 0); ser_u16(context.stroke_data, 0);
ser_u16(context.stroke_data, 0); ser_u16(context.stroke_data, 0);
ser_u16(context.stroke_data, 0); ser_u16(context.stroke_data, 0);
ser_u16(context.stroke_data, 0); ser_u16(context.stroke_data, 0);
tv_add(state.wasm.buffers['width'].tv, 0);
state.wasm.buffers['width'].used += 4;
} }
// Real stroke, add forever // Real stroke, add forever

Loading…
Cancel
Save