|
|
@ -72,17 +72,18 @@ function draw(state, context) { |
|
|
|
gl.useProgram(context.programs['sdf'].main); |
|
|
|
gl.useProgram(context.programs['sdf'].main); |
|
|
|
|
|
|
|
|
|
|
|
bvh_clip(state, context); |
|
|
|
bvh_clip(state, context); |
|
|
|
|
|
|
|
|
|
|
|
const segment_count = geometry_write_instances(state, context); |
|
|
|
const segment_count = geometry_write_instances(state, context); |
|
|
|
const dynamic_segment_count = context.dynamic_segment_count; |
|
|
|
const dynamic_segment_count = context.dynamic_segment_count; |
|
|
|
const dynamic_stroke_count = context.dynamic_stroke_count; |
|
|
|
const dynamic_stroke_count = context.dynamic_stroke_count; |
|
|
|
|
|
|
|
|
|
|
|
// "Static" data upload
|
|
|
|
// "Static" data upload
|
|
|
|
|
|
|
|
if (segment_count > 0) { |
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance']); |
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance']); |
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, context.instance_data_points.size * 4 + context.instance_data_ids.size * 4, gl.STREAM_DRAW); |
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, context.instance_data_points.size * 4 + context.instance_data_ids.size * 4, gl.STREAM_DRAW); |
|
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, 0, tv_data(context.instance_data_points)); |
|
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, 0, tv_data(context.instance_data_points)); |
|
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, context.instance_data_points.size * 4, tv_data(context.instance_data_ids)); |
|
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, context.instance_data_points.size * 4, tv_data(context.instance_data_ids)); |
|
|
|
gl.bindTexture(gl.TEXTURE_2D, context.textures['stroke_data']); |
|
|
|
gl.bindTexture(gl.TEXTURE_2D, context.textures['stroke_data']); |
|
|
|
// TODO: this is stable data, only upload new strokes as they arrive
|
|
|
|
|
|
|
|
upload_square_rgba16ui_texture(gl, context.stroke_data, config.stroke_texture_size); |
|
|
|
upload_square_rgba16ui_texture(gl, context.stroke_data, config.stroke_texture_size); |
|
|
|
|
|
|
|
|
|
|
|
gl.uniform2f(locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
gl.uniform2f(locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
@ -108,11 +109,13 @@ function draw(state, context) { |
|
|
|
|
|
|
|
|
|
|
|
// Static draw (everything already bound)
|
|
|
|
// Static draw (everything already bound)
|
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, segment_count); |
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, segment_count); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Dynamic strokes should be drawn above static strokes
|
|
|
|
// Dynamic strokes should be drawn above static strokes
|
|
|
|
gl.clear(gl.DEPTH_BUFFER_BIT); |
|
|
|
gl.clear(gl.DEPTH_BUFFER_BIT); |
|
|
|
|
|
|
|
|
|
|
|
// Dynamic draw (strokes currently being drawn)
|
|
|
|
// Dynamic draw (strokes currently being drawn)
|
|
|
|
|
|
|
|
if (dynamic_segment_count > 0) { |
|
|
|
gl.uniform1i(locations['u_stroke_count'], dynamic_stroke_count); |
|
|
|
gl.uniform1i(locations['u_stroke_count'], dynamic_stroke_count); |
|
|
|
gl.uniform1i(locations['u_stroke_data'], 0); |
|
|
|
gl.uniform1i(locations['u_stroke_data'], 0); |
|
|
|
gl.uniform1i(locations['u_stroke_texture_size'], config.dynamic_stroke_texture_size); |
|
|
|
gl.uniform1i(locations['u_stroke_texture_size'], config.dynamic_stroke_texture_size); |
|
|
@ -140,6 +143,7 @@ function draw(state, context) { |
|
|
|
gl.vertexAttribDivisor(locations['a_stroke_id'], 1); |
|
|
|
gl.vertexAttribDivisor(locations['a_stroke_id'], 1); |
|
|
|
|
|
|
|
|
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, dynamic_segment_count); |
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, dynamic_segment_count); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
document.getElementById('debug-stats').innerHTML = ` |
|
|
|
document.getElementById('debug-stats').innerHTML = ` |
|
|
|
<span>Segments onscreen: ${segment_count}</span> |
|
|
|
<span>Segments onscreen: ${segment_count}</span> |
|
|
|