|
|
|
@ -105,20 +105,24 @@ async function draw(state, context, animate, ts) {
@@ -105,20 +105,24 @@ async function draw(state, context, animate, ts) {
|
|
|
|
|
gl.clearDepth(0.0); |
|
|
|
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
|
|
|
|
|
|
|
|
|
const locations = context.locations; |
|
|
|
|
const buffers = context.buffers; |
|
|
|
|
const programs = context.programs; |
|
|
|
|
const textures = context.textures; |
|
|
|
|
|
|
|
|
|
// Draw the background pattern
|
|
|
|
|
if (state.background_pattern === 'dots') { |
|
|
|
|
gl.useProgram(context.programs['pattern'].dots); |
|
|
|
|
buffers = context.buffers['pattern']; |
|
|
|
|
locations = context.locations['pattern'].dots; |
|
|
|
|
const pr = programs['dots']; |
|
|
|
|
gl.useProgram(pr.program); |
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance_dot']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_center']); |
|
|
|
|
gl.vertexAttribPointer(locations['a_center'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_center'], 1); |
|
|
|
|
gl.enableVertexAttribArray(pr.locations['a_center']); |
|
|
|
|
gl.vertexAttribPointer(pr.locations['a_center'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_center'], 1); |
|
|
|
|
|
|
|
|
|
gl.uniform2f(locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
|
gl.uniform2f(locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
|
gl.uniform2f(locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
|
gl.uniform2f(pr.locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
|
gl.uniform2f(pr.locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
|
gl.uniform2f(pr.locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
|
|
|
|
|
|
const zoom = state.canvas.zoom; |
|
|
|
|
const zoom_log2 = Math.log2(zoom); |
|
|
|
@ -131,7 +135,7 @@ async function draw(state, context, animate, ts) {
@@ -131,7 +135,7 @@ async function draw(state, context, animate, ts) {
|
|
|
|
|
const dot_instances = new Float32Array(geometry_gen_fullscreen_grid(state, context, 32 / zoom_previous, 32 / zoom_previous)); |
|
|
|
|
const t = Math.min(1.0, 1.0 - (zoom / zoom_previous) / 2.0); |
|
|
|
|
|
|
|
|
|
gl.uniform1f(locations['u_fadeout'], t); |
|
|
|
|
gl.uniform1f(pr.locations['u_fadeout'], t); |
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance_dot']); |
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, dot_instances, gl.STREAM_DRAW); |
|
|
|
@ -144,7 +148,7 @@ async function draw(state, context, animate, ts) {
@@ -144,7 +148,7 @@ async function draw(state, context, animate, ts) {
|
|
|
|
|
const dot_instances = new Float32Array(geometry_gen_fullscreen_grid(state, context, 32 / zoom_next, 32 / zoom_next)); |
|
|
|
|
const t = Math.min(1.0, 1.0 - (zoom_next / zoom) / 2.0); |
|
|
|
|
|
|
|
|
|
gl.uniform1f(locations['u_fadeout'], t); |
|
|
|
|
gl.uniform1f(pr.locations['u_fadeout'], t); |
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance_dot']); |
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, dot_instances, gl.STREAM_DRAW); |
|
|
|
@ -152,6 +156,7 @@ async function draw(state, context, animate, ts) {
@@ -152,6 +156,7 @@ async function draw(state, context, animate, ts) {
|
|
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, dot_instances.length / 2); |
|
|
|
|
} |
|
|
|
|
} else if (state.background_pattern === 'grid') { |
|
|
|
|
const pr = programs['grid']; |
|
|
|
|
const zoom = state.canvas.zoom; |
|
|
|
|
|
|
|
|
|
let zoom_log8 = Math.log(zoom) / Math.log(8); |
|
|
|
@ -166,19 +171,17 @@ async function draw(state, context, animate, ts) {
@@ -166,19 +171,17 @@ async function draw(state, context, animate, ts) {
|
|
|
|
|
zoom_next = zoom_previous * 8; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gl.useProgram(context.programs['pattern'].grid); |
|
|
|
|
buffers = context.buffers['pattern']; |
|
|
|
|
locations = context.locations['pattern'].grid; |
|
|
|
|
gl.useProgram(pr.program); |
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance_grid']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_data']); |
|
|
|
|
gl.vertexAttribPointer(locations['a_data'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_data'], 1); |
|
|
|
|
gl.enableVertexAttribArray(pr.locations['a_data']); |
|
|
|
|
gl.vertexAttribPointer(pr.locations['a_data'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_data'], 1); |
|
|
|
|
|
|
|
|
|
gl.uniform2f(locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
|
gl.uniform2f(locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
|
gl.uniform2f(locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
|
gl.uniform1f(locations['u_fadeout'], 1.0); |
|
|
|
|
gl.uniform2f(pr.locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
|
gl.uniform2f(pr.locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
|
gl.uniform2f(pr.locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
|
gl.uniform1f(pr.locations['u_fadeout'], 1.0); |
|
|
|
|
|
|
|
|
|
// Previous level (major lines)
|
|
|
|
|
{ |
|
|
|
@ -186,7 +189,7 @@ async function draw(state, context, animate, ts) {
@@ -186,7 +189,7 @@ async function draw(state, context, animate, ts) {
|
|
|
|
|
let t = (zoom / zoom_previous - 1) / -7 + 1; |
|
|
|
|
t = 0.25; |
|
|
|
|
|
|
|
|
|
gl.uniform1f(locations['u_fadeout'], t); |
|
|
|
|
gl.uniform1f(pr.locations['u_fadeout'], t); |
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance_grid']); |
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, grid_instances, gl.STREAM_DRAW); |
|
|
|
@ -200,7 +203,7 @@ async function draw(state, context, animate, ts) {
@@ -200,7 +203,7 @@ async function draw(state, context, animate, ts) {
|
|
|
|
|
let t = (zoom_next / zoom - 1) / 7; |
|
|
|
|
t = Math.min(0.1, -t + 1); // slight fade-in
|
|
|
|
|
|
|
|
|
|
gl.uniform1f(locations['u_fadeout'], t); |
|
|
|
|
gl.uniform1f(pr.locations['u_fadeout'], t); |
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance_grid']); |
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, grid_instances, gl.STREAM_DRAW); |
|
|
|
@ -209,37 +212,39 @@ async function draw(state, context, animate, ts) {
@@ -209,37 +212,39 @@ async function draw(state, context, animate, ts) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gl.clear(gl.DEPTH_BUFFER_BIT); // draw images above the background pattern
|
|
|
|
|
gl.useProgram(context.programs['image']); |
|
|
|
|
buffers = context.buffers['image']; |
|
|
|
|
locations = context.locations['image']; |
|
|
|
|
// Images
|
|
|
|
|
{ |
|
|
|
|
const pr = programs['image']; |
|
|
|
|
|
|
|
|
|
gl.clear(gl.DEPTH_BUFFER_BIT); // draw images above the background pattern
|
|
|
|
|
gl.useProgram(pr.program); |
|
|
|
|
|
|
|
|
|
let offset = 0; |
|
|
|
|
|
|
|
|
|
const quads = geometry_image_quads(state, context); |
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_quads']); |
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_images']); |
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, quads, gl.STATIC_DRAW); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_pos'], 0); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_pos'], 0); |
|
|
|
|
|
|
|
|
|
gl.enableVertexAttribArray(locations['a_pos']); |
|
|
|
|
gl.vertexAttribPointer(locations['a_pos'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
|
gl.enableVertexAttribArray(pr.locations['a_pos']); |
|
|
|
|
gl.vertexAttribPointer(pr.locations['a_pos'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
|
|
|
|
|
|
for (const entry of context.images) { |
|
|
|
|
if (!entry.deleted) { |
|
|
|
|
gl.uniform2f(locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
|
gl.uniform2f(locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
|
gl.uniform2f(locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
|
gl.uniform1i(locations['u_texture'], 0); // Only 1 active texture for each drawcall
|
|
|
|
|
gl.uniform1i(locations['u_solid'], 0); |
|
|
|
|
gl.uniform2f(pr.locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
|
gl.uniform2f(pr.locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
|
gl.uniform2f(pr.locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
|
gl.uniform1i(pr.locations['u_texture'], 0); // Only 1 active texture for each drawcall
|
|
|
|
|
gl.uniform1i(pr.locations['u_solid'], 0); |
|
|
|
|
|
|
|
|
|
gl.bindTexture(gl.TEXTURE_2D, entry.texture); |
|
|
|
|
gl.drawArrays(gl.TRIANGLES, offset, 6); |
|
|
|
|
|
|
|
|
|
// Highlight active image
|
|
|
|
|
if (entry.key === state.active_image) { |
|
|
|
|
gl.uniform1i(locations['u_solid'], 1); |
|
|
|
|
gl.uniform4f(locations['u_color'], 0.133 * 0.5, 0.545 * 0.5, 0.902 * 0.5, 0.5); |
|
|
|
|
gl.uniform1i(pr.locations['u_solid'], 1); |
|
|
|
|
gl.uniform4f(pr.locations['u_color'], 0.133 * 0.5, 0.545 * 0.5, 0.902 * 0.5, 0.5); |
|
|
|
|
gl.drawArrays(gl.TRIANGLES, offset, 6); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -248,72 +253,76 @@ async function draw(state, context, animate, ts) {
@@ -248,72 +253,76 @@ async function draw(state, context, animate, ts) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gl.clear(gl.DEPTH_BUFFER_BIT); // draw strokes above the images
|
|
|
|
|
gl.useProgram(context.programs['sdf'].main); |
|
|
|
|
buffers = context.buffers['sdf']; |
|
|
|
|
locations = context.locations['sdf'].main; |
|
|
|
|
|
|
|
|
|
// "Static" data upload
|
|
|
|
|
if (segment_count > 0) { |
|
|
|
|
const pr = programs['main']; |
|
|
|
|
|
|
|
|
|
gl.clear(gl.DEPTH_BUFFER_BIT); // draw strokes above the images
|
|
|
|
|
gl.useProgram(pr.program); |
|
|
|
|
|
|
|
|
|
const total_static_size = context.instance_data_points.size * 4 + |
|
|
|
|
context.instance_data_ids.size * 4 + |
|
|
|
|
context.instance_data_pressures.size; |
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance']); |
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_strokes_static']); |
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, total_static_size, gl.STREAM_DRAW); |
|
|
|
|
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 + context.instance_data_ids.size * 4, |
|
|
|
|
tv_data(context.instance_data_pressures)); |
|
|
|
|
gl.bindTexture(gl.TEXTURE_2D, context.textures['stroke_data']); |
|
|
|
|
gl.bindTexture(gl.TEXTURE_2D, textures['stroke_data']); |
|
|
|
|
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_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
|
gl.uniform2f(locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
|
gl.uniform1i(locations['u_stroke_count'], state.events.length); |
|
|
|
|
gl.uniform1i(locations['u_debug_mode'], state.debug.red); |
|
|
|
|
gl.uniform1i(locations['u_stroke_data'], 0); |
|
|
|
|
gl.uniform1i(locations['u_stroke_texture_size'], config.stroke_texture_size); |
|
|
|
|
gl.uniform1f(locations['u_fixed_pixel_width'], 0); |
|
|
|
|
gl.uniform2f(pr.locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
|
gl.uniform2f(pr.locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
|
gl.uniform2f(pr.locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
|
gl.uniform1i(pr.locations['u_stroke_count'], state.events.length); |
|
|
|
|
gl.uniform1i(pr.locations['u_debug_mode'], state.debug.red); |
|
|
|
|
gl.uniform1i(pr.locations['u_stroke_data'], 0); |
|
|
|
|
gl.uniform1i(pr.locations['u_stroke_texture_size'], config.stroke_texture_size); |
|
|
|
|
gl.uniform1f(pr.locations['u_fixed_pixel_width'], 0); |
|
|
|
|
|
|
|
|
|
gl.enableVertexAttribArray(locations['a_a']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_b']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_stroke_id']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_pressure']); |
|
|
|
|
gl.enableVertexAttribArray(pr.locations['a_a']); |
|
|
|
|
gl.enableVertexAttribArray(pr.locations['a_b']); |
|
|
|
|
gl.enableVertexAttribArray(pr.locations['a_stroke_id']); |
|
|
|
|
gl.enableVertexAttribArray(pr.locations['a_pressure']); |
|
|
|
|
|
|
|
|
|
// Points (a, b) and stroke ids are stored in separate cpu buffers so that points can be reused (look at stride and offset values)
|
|
|
|
|
gl.vertexAttribPointer(locations['a_a'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
|
gl.vertexAttribPointer(locations['a_b'], 2, gl.FLOAT, false, 2 * 4, 2 * 4); |
|
|
|
|
gl.vertexAttribIPointer(locations['a_stroke_id'], 1, gl.INT, 4, context.instance_data_points.size * 4); |
|
|
|
|
gl.vertexAttribPointer(locations['a_pressure'], 2, gl.UNSIGNED_BYTE, true, 1, context.instance_data_points.size * 4 + context.instance_data_ids.size * 4); |
|
|
|
|
gl.vertexAttribPointer(pr.locations['a_a'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
|
gl.vertexAttribPointer(pr.locations['a_b'], 2, gl.FLOAT, false, 2 * 4, 2 * 4); |
|
|
|
|
gl.vertexAttribIPointer(pr.locations['a_stroke_id'], 1, gl.INT, 4, context.instance_data_points.size * 4); |
|
|
|
|
gl.vertexAttribPointer(pr.locations['a_pressure'], 2, gl.UNSIGNED_BYTE, true, 1, context.instance_data_points.size * 4 + context.instance_data_ids.size * 4); |
|
|
|
|
|
|
|
|
|
gl.vertexAttribDivisor(locations['a_a'], 1); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_b'], 1); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_stroke_id'], 1); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_pressure'], 1); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_a'], 1); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_b'], 1); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_stroke_id'], 1); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_pressure'], 1); |
|
|
|
|
|
|
|
|
|
// Static draw (everything already bound)
|
|
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, segment_count); |
|
|
|
|
|
|
|
|
|
// I don't really know why I need to do this, but it
|
|
|
|
|
// makes background patter drawcall work properly
|
|
|
|
|
gl.vertexAttribDivisor(locations['a_a'], 0); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_b'], 0); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_stroke_id'], 0); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_pressure'], 0); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_a'], 0); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_b'], 0); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_stroke_id'], 0); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_pressure'], 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Dynamic strokes should be drawn above static strokes
|
|
|
|
|
gl.clear(gl.DEPTH_BUFFER_BIT); |
|
|
|
|
|
|
|
|
|
// 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_data'], 0); |
|
|
|
|
gl.uniform1i(locations['u_stroke_texture_size'], config.dynamic_stroke_texture_size); |
|
|
|
|
const pr = programs['main']; // same as static
|
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_dynamic_instance']); |
|
|
|
|
// Dynamic strokes should be drawn above static strokes
|
|
|
|
|
gl.clear(gl.DEPTH_BUFFER_BIT); |
|
|
|
|
|
|
|
|
|
gl.uniform1i(pr.locations['u_stroke_count'], dynamic_stroke_count); |
|
|
|
|
gl.uniform1i(pr.locations['u_stroke_data'], 0); |
|
|
|
|
gl.uniform1i(pr.locations['u_stroke_texture_size'], config.dynamic_stroke_texture_size); |
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_strokes_dynamic']); |
|
|
|
|
|
|
|
|
|
// Dynamic data upload
|
|
|
|
|
const total_dynamic_size = |
|
|
|
@ -325,92 +334,107 @@ async function draw(state, context, animate, ts) {
@@ -325,92 +334,107 @@ async function draw(state, context, animate, ts) {
|
|
|
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, context.dynamic_instance_points.size * 4, tv_data(context.dynamic_instance_ids)); |
|
|
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, context.dynamic_instance_points.size * 4 + context.dynamic_instance_ids.size * 4, |
|
|
|
|
tv_data(context.dynamic_instance_pressure)); |
|
|
|
|
gl.bindTexture(gl.TEXTURE_2D, context.textures['dynamic_stroke_data']); |
|
|
|
|
gl.bindTexture(gl.TEXTURE_2D, textures['dynamic_stroke_data']); |
|
|
|
|
upload_square_rgba16ui_texture(gl, context.dynamic_stroke_data, config.dynamic_stroke_texture_size); |
|
|
|
|
|
|
|
|
|
gl.uniform2f(locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
|
gl.uniform2f(locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
|
gl.uniform2f(locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
|
gl.uniform2f(pr.locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
|
gl.uniform2f(pr.locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
|
gl.uniform2f(pr.locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
|
|
|
|
|
|
gl.uniform1i(locations['u_stroke_count'], context.dynamic_stroke_count); |
|
|
|
|
gl.uniform1i(locations['u_debug_mode'], state.debug.red); |
|
|
|
|
gl.uniform1i(locations['u_stroke_data'], 0); |
|
|
|
|
gl.uniform1i(locations['u_stroke_texture_size'], config.dynamic_stroke_texture_size); |
|
|
|
|
gl.uniform1f(locations['u_fixed_pixel_width'], 0); |
|
|
|
|
gl.uniform1i(pr.locations['u_stroke_count'], context.dynamic_stroke_count); |
|
|
|
|
gl.uniform1i(pr.locations['u_debug_mode'], state.debug.red); |
|
|
|
|
gl.uniform1i(pr.locations['u_stroke_data'], 0); |
|
|
|
|
gl.uniform1i(pr.locations['u_stroke_texture_size'], config.dynamic_stroke_texture_size); |
|
|
|
|
gl.uniform1f(pr.locations['u_fixed_pixel_width'], 0); |
|
|
|
|
|
|
|
|
|
gl.enableVertexAttribArray(locations['a_a']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_b']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_stroke_id']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_pressure']); |
|
|
|
|
gl.enableVertexAttribArray(pr.locations['a_a']); |
|
|
|
|
gl.enableVertexAttribArray(pr.locations['a_b']); |
|
|
|
|
gl.enableVertexAttribArray(pr.locations['a_stroke_id']); |
|
|
|
|
gl.enableVertexAttribArray(pr.locations['a_pressure']); |
|
|
|
|
|
|
|
|
|
// Points (a, b) and stroke ids are stored in separate cpu buffers so that points can be reused (look at stride and offset values)
|
|
|
|
|
gl.vertexAttribPointer(locations['a_a'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
|
gl.vertexAttribPointer(locations['a_b'], 2, gl.FLOAT, false, 2 * 4, 2 * 4); |
|
|
|
|
gl.vertexAttribIPointer(locations['a_stroke_id'], 1, gl.INT, 4, context.dynamic_instance_points.size * 4); |
|
|
|
|
gl.vertexAttribPointer(locations['a_pressure'], 2, gl.UNSIGNED_BYTE, true, 1, context.dynamic_instance_points.size * 4 + context.dynamic_instance_ids.size * 4); |
|
|
|
|
gl.vertexAttribPointer(pr.locations['a_a'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
|
gl.vertexAttribPointer(pr.locations['a_b'], 2, gl.FLOAT, false, 2 * 4, 2 * 4); |
|
|
|
|
gl.vertexAttribIPointer(pr.locations['a_stroke_id'], 1, gl.INT, 4, context.dynamic_instance_points.size * 4); |
|
|
|
|
gl.vertexAttribPointer(pr.locations['a_pressure'], 2, gl.UNSIGNED_BYTE, true, 1, context.dynamic_instance_points.size * 4 + context.dynamic_instance_ids.size * 4); |
|
|
|
|
|
|
|
|
|
gl.vertexAttribDivisor(locations['a_a'], 1); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_b'], 1); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_stroke_id'], 1); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_pressure'], 1); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_a'], 1); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_b'], 1); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_stroke_id'], 1); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_pressure'], 1); |
|
|
|
|
|
|
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, dynamic_segment_count); |
|
|
|
|
|
|
|
|
|
gl.vertexAttribDivisor(locations['a_a'], 0); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_b'], 0); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_stroke_id'], 0); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_pressure'], 0); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_a'], 0); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_b'], 0); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_stroke_id'], 0); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_pressure'], 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// HUD: resize handles, etc
|
|
|
|
|
if (state.active_image !== null) { |
|
|
|
|
const pr = programs['main']; // same as static
|
|
|
|
|
const handles = geometry_generate_handles(state, context, state.active_image); |
|
|
|
|
const ui_segments = 7 * 4 - 1; // each square = 4, each line = 1, square->line = 1, line->square = 1
|
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance']); |
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_hud']); |
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, handles.points.byteLength + handles.ids.byteLength + handles.pressures.byteLength, gl.STREAM_DRAW); |
|
|
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, 0, handles.points); |
|
|
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, handles.points.byteLength, handles.ids); |
|
|
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, handles.points.byteLength + handles.ids.byteLength, handles.pressures); |
|
|
|
|
|
|
|
|
|
gl.bindTexture(gl.TEXTURE_2D, context.textures['ui']); |
|
|
|
|
gl.bindTexture(gl.TEXTURE_2D, textures['ui']); |
|
|
|
|
upload_square_rgba16ui_texture(gl, handles.stroke_data, config.ui_texture_size); |
|
|
|
|
|
|
|
|
|
gl.uniform2f(locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
|
gl.uniform2f(locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
|
gl.uniform2f(locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
|
gl.uniform1i(locations['u_stroke_count'], 8); |
|
|
|
|
gl.uniform1i(locations['u_debug_mode'], 0); |
|
|
|
|
gl.uniform1i(locations['u_stroke_data'], 0); |
|
|
|
|
gl.uniform1i(locations['u_stroke_texture_size'], config.ui_texture_size); |
|
|
|
|
gl.uniform1f(locations['u_fixed_pixel_width'], 2); |
|
|
|
|
|
|
|
|
|
gl.enableVertexAttribArray(locations['a_a']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_b']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_stroke_id']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_pressure']); |
|
|
|
|
|
|
|
|
|
gl.vertexAttribPointer(locations['a_a'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
|
gl.vertexAttribPointer(locations['a_b'], 2, gl.FLOAT, false, 2 * 4, 2 * 4); |
|
|
|
|
gl.vertexAttribIPointer(locations['a_stroke_id'], 1, gl.INT, 4, handles.points.byteLength); |
|
|
|
|
gl.vertexAttribPointer(locations['a_pressure'], 2, gl.UNSIGNED_BYTE, true, 1, handles.points.byteLength + handles.ids.byteLength); |
|
|
|
|
|
|
|
|
|
gl.vertexAttribDivisor(locations['a_a'], 1); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_b'], 1); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_stroke_id'], 1); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_pressure'], 1); |
|
|
|
|
gl.uniform2f(pr.locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
|
gl.uniform2f(pr.locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
|
gl.uniform2f(pr.locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
|
gl.uniform1i(pr.locations['u_stroke_count'], 8); |
|
|
|
|
gl.uniform1i(pr.locations['u_debug_mode'], 0); |
|
|
|
|
gl.uniform1i(pr.locations['u_stroke_data'], 0); |
|
|
|
|
gl.uniform1i(pr.locations['u_stroke_texture_size'], config.ui_texture_size); |
|
|
|
|
gl.uniform1f(pr.locations['u_fixed_pixel_width'], 2); |
|
|
|
|
|
|
|
|
|
gl.enableVertexAttribArray(pr.locations['a_a']); |
|
|
|
|
gl.enableVertexAttribArray(pr.locations['a_b']); |
|
|
|
|
gl.enableVertexAttribArray(pr.locations['a_stroke_id']); |
|
|
|
|
gl.enableVertexAttribArray(pr.locations['a_pressure']); |
|
|
|
|
|
|
|
|
|
gl.vertexAttribPointer(pr.locations['a_a'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
|
gl.vertexAttribPointer(pr.locations['a_b'], 2, gl.FLOAT, false, 2 * 4, 2 * 4); |
|
|
|
|
gl.vertexAttribIPointer(pr.locations['a_stroke_id'], 1, gl.INT, 4, handles.points.byteLength); |
|
|
|
|
gl.vertexAttribPointer(pr.locations['a_pressure'], 2, gl.UNSIGNED_BYTE, true, 1, handles.points.byteLength + handles.ids.byteLength); |
|
|
|
|
|
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_a'], 1); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_b'], 1); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_stroke_id'], 1); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_pressure'], 1); |
|
|
|
|
|
|
|
|
|
// Static draw (everything already bound)
|
|
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, ui_segments); |
|
|
|
|
|
|
|
|
|
// I don't really know why I need to do this, but it
|
|
|
|
|
// makes background patter drawcall work properly
|
|
|
|
|
gl.vertexAttribDivisor(locations['a_a'], 0); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_b'], 0); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_stroke_id'], 0); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_pressure'], 0); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_a'], 0); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_b'], 0); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_stroke_id'], 0); |
|
|
|
|
gl.vertexAttribDivisor(pr.locations['a_pressure'], 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (config.draw_bvh) { |
|
|
|
|
const bboxes = tv_create(Float32Array, context.clipped_indices.size * 4); |
|
|
|
|
// Debug BVH viz
|
|
|
|
|
for (let i = 0; i < context.clipped_indices.size; ++i) { |
|
|
|
|
const stroke_id = context.clipped_indices.data[i]; |
|
|
|
|
const stroke = state.events[stroke_id]; |
|
|
|
|
const stroke_bbox = state.bvh.nodes[stroke.bvh_node].bbox; |
|
|
|
|
tv_add(bboxes, stroke.bbox.x1); |
|
|
|
|
tv_add(bboxes, stroke.bbox.x2); |
|
|
|
|
tv_add(bboxes, stroke.bbox.y1); |
|
|
|
|
tv_add(bboxes, stroke.bbox.y2); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
document.getElementById('debug-stats').innerHTML = ` |
|
|
|
|
<span>Strokes onscreen: ${context.clipped_indices.size}</span> |
|
|
|
|
<span>Segments onscreen: ${segment_count}</span> |
|
|
|
|