|
|
@ -61,7 +61,7 @@ function upload_square_rgba16ui_texture(gl, serializer, texture_size) { |
|
|
|
// Upload last row
|
|
|
|
// Upload last row
|
|
|
|
if (last_row > 0) { |
|
|
|
if (last_row > 0) { |
|
|
|
const last_row_upload = last_row * bpp; |
|
|
|
const last_row_upload = last_row * bpp; |
|
|
|
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, rows_uploaded, last_row, 1, gl.RGBA_INTEGER, gl.UNSIGNED_SHORT, new Uint16Array(serializer.buffer, whole_upload, last_row_upload)); |
|
|
|
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, rows_uploaded, last_row, 1, gl.RGBA_INTEGER, gl.UNSIGNED_SHORT, new Uint16Array(serializer.buffer, whole_upload, last_row_upload / 2)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
serializer.gpu_upload_from = serializer.offset; |
|
|
|
serializer.gpu_upload_from = serializer.offset; |
|
|
@ -105,6 +105,7 @@ function draw_strokes(state, width, height, programs, gl, lod_levels, segment_co |
|
|
|
vbo, |
|
|
|
vbo, |
|
|
|
ebo, |
|
|
|
ebo, |
|
|
|
stroke_texture, |
|
|
|
stroke_texture, |
|
|
|
|
|
|
|
stroke_texture_size, |
|
|
|
stroke_data, |
|
|
|
stroke_data, |
|
|
|
stroke_count, |
|
|
|
stroke_count, |
|
|
|
) { |
|
|
|
) { |
|
|
@ -143,7 +144,7 @@ function draw_strokes(state, width, height, programs, gl, lod_levels, segment_co |
|
|
|
|
|
|
|
|
|
|
|
// Per-stroke data (base width, color)
|
|
|
|
// Per-stroke data (base width, color)
|
|
|
|
gl.bindTexture(gl.TEXTURE_2D, stroke_texture); |
|
|
|
gl.bindTexture(gl.TEXTURE_2D, stroke_texture); |
|
|
|
upload_square_rgba16ui_texture(gl, stroke_data, config.stroke_texture_size); |
|
|
|
upload_square_rgba16ui_texture(gl, stroke_data, stroke_texture_size); |
|
|
|
|
|
|
|
|
|
|
|
gl.uniform2f(pr.locations['u_res'], width, height); |
|
|
|
gl.uniform2f(pr.locations['u_res'], width, height); |
|
|
|
gl.uniform2f(pr.locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
gl.uniform2f(pr.locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
@ -414,6 +415,7 @@ async function draw(state, context, animate, ts) { |
|
|
|
buffers['b_strokes_static'], |
|
|
|
buffers['b_strokes_static'], |
|
|
|
buffers['i_strokes_static'], |
|
|
|
buffers['i_strokes_static'], |
|
|
|
textures['stroke_data'], |
|
|
|
textures['stroke_data'], |
|
|
|
|
|
|
|
config.stroke_texture_size, |
|
|
|
context.stroke_data, |
|
|
|
context.stroke_data, |
|
|
|
state.events.length, // not really
|
|
|
|
state.events.length, // not really
|
|
|
|
); |
|
|
|
); |
|
|
@ -435,6 +437,7 @@ async function draw(state, context, animate, ts) { |
|
|
|
buffers['b_strokes_dynamic'], |
|
|
|
buffers['b_strokes_dynamic'], |
|
|
|
buffers['i_strokes_dynamic'], |
|
|
|
buffers['i_strokes_dynamic'], |
|
|
|
textures['dynamic_stroke_data'], |
|
|
|
textures['dynamic_stroke_data'], |
|
|
|
|
|
|
|
config.stroke_texture_size, |
|
|
|
context.dynamic_stroke_data, |
|
|
|
context.dynamic_stroke_data, |
|
|
|
context.dynamic_stroke_count, |
|
|
|
context.dynamic_stroke_count, |
|
|
|
); |
|
|
|
); |
|
|
@ -442,50 +445,31 @@ async function draw(state, context, animate, ts) { |
|
|
|
|
|
|
|
|
|
|
|
// HUD: resize handles, etc
|
|
|
|
// HUD: resize handles, etc
|
|
|
|
if (state.active_image !== null) { |
|
|
|
if (state.active_image !== null) { |
|
|
|
const pr = programs['main']; // same as static
|
|
|
|
gl.clear(gl.DEPTH_BUFFER_BIT); |
|
|
|
|
|
|
|
|
|
|
|
const handles = geometry_generate_handles(state, context, state.active_image); |
|
|
|
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
|
|
|
|
const ui_segments = 7 * 4 - 1; // each square = 4, each line = 1, square->line = 1, line->square = 1
|
|
|
|
|
|
|
|
const hud_batches = tv_create(Uint32Array, 4); |
|
|
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_hud']); |
|
|
|
tv_add(hud_batches, 0); |
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, handles.points.byteLength + handles.ids.byteLength + handles.pressures.byteLength, gl.STREAM_DRAW); |
|
|
|
tv_add(hud_batches, compute_circle_lod(state.canvas.zoom * 2)); |
|
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, 0, handles.points); |
|
|
|
tv_add(hud_batches, ui_segments); |
|
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, handles.points.byteLength, handles.ids); |
|
|
|
tv_add(hud_batches, -1); |
|
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, handles.points.byteLength + handles.ids.byteLength, handles.pressures); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gl.bindTexture(gl.TEXTURE_2D, textures['ui']); |
|
|
|
|
|
|
|
upload_square_rgba16ui_texture(gl, handles.stroke_data, config.ui_texture_size); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gl.uniform2f(pr.locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
draw_strokes(state, context.canvas.width, context.canvas.height, programs, gl, lod_levels, ui_segments, |
|
|
|
gl.uniform2f(pr.locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
total_lod_floats, |
|
|
|
gl.uniform2f(pr.locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
total_lod_indices, |
|
|
|
gl.uniform1i(pr.locations['u_stroke_count'], 8); |
|
|
|
hud_batches, |
|
|
|
gl.uniform1i(pr.locations['u_debug_mode'], 0); |
|
|
|
handles.points, |
|
|
|
gl.uniform1i(pr.locations['u_stroke_data'], 0); |
|
|
|
handles.ids, |
|
|
|
gl.uniform1i(pr.locations['u_stroke_texture_size'], config.ui_texture_size); |
|
|
|
handles.pressures, |
|
|
|
|
|
|
|
buffers['b_hud'], |
|
|
|
gl.enableVertexAttribArray(pr.locations['a_a']); |
|
|
|
buffers['i_hud'], |
|
|
|
gl.enableVertexAttribArray(pr.locations['a_b']); |
|
|
|
textures['ui'], |
|
|
|
gl.enableVertexAttribArray(pr.locations['a_stroke_id']); |
|
|
|
config.ui_texture_size, |
|
|
|
gl.enableVertexAttribArray(pr.locations['a_pressure']); |
|
|
|
handles.stroke_data, |
|
|
|
|
|
|
|
8 |
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, 32 * 3 + 6 + 32 * 3, ui_segments); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// I don't really know why I need to do this, but it
|
|
|
|
|
|
|
|
// makes background patter drawcall work properly
|
|
|
|
|
|
|
|
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) { |
|
|
|
if (config.draw_bvh) { |
|
|
|