|
|
|
@ -61,7 +61,7 @@ function upload_square_rgba16ui_texture(gl, serializer, texture_size) {
@@ -61,7 +61,7 @@ function upload_square_rgba16ui_texture(gl, serializer, texture_size) {
|
|
|
|
|
// Upload last row
|
|
|
|
|
if (last_row > 0) { |
|
|
|
|
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; |
|
|
|
@ -105,6 +105,7 @@ function draw_strokes(state, width, height, programs, gl, lod_levels, segment_co
@@ -105,6 +105,7 @@ function draw_strokes(state, width, height, programs, gl, lod_levels, segment_co
|
|
|
|
|
vbo, |
|
|
|
|
ebo, |
|
|
|
|
stroke_texture, |
|
|
|
|
stroke_texture_size, |
|
|
|
|
stroke_data, |
|
|
|
|
stroke_count, |
|
|
|
|
) { |
|
|
|
@ -143,7 +144,7 @@ function draw_strokes(state, width, height, programs, gl, lod_levels, segment_co
@@ -143,7 +144,7 @@ function draw_strokes(state, width, height, programs, gl, lod_levels, segment_co
|
|
|
|
|
|
|
|
|
|
// Per-stroke data (base width, color)
|
|
|
|
|
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_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
@ -414,6 +415,7 @@ async function draw(state, context, animate, ts) {
@@ -414,6 +415,7 @@ async function draw(state, context, animate, ts) {
|
|
|
|
|
buffers['b_strokes_static'], |
|
|
|
|
buffers['i_strokes_static'], |
|
|
|
|
textures['stroke_data'], |
|
|
|
|
config.stroke_texture_size, |
|
|
|
|
context.stroke_data, |
|
|
|
|
state.events.length, // not really
|
|
|
|
|
); |
|
|
|
@ -435,6 +437,7 @@ async function draw(state, context, animate, ts) {
@@ -435,6 +437,7 @@ async function draw(state, context, animate, ts) {
|
|
|
|
|
buffers['b_strokes_dynamic'], |
|
|
|
|
buffers['i_strokes_dynamic'], |
|
|
|
|
textures['dynamic_stroke_data'], |
|
|
|
|
config.stroke_texture_size, |
|
|
|
|
context.dynamic_stroke_data, |
|
|
|
|
context.dynamic_stroke_count, |
|
|
|
|
); |
|
|
|
@ -442,50 +445,31 @@ async function draw(state, context, animate, ts) {
@@ -442,50 +445,31 @@ async function draw(state, context, animate, ts) {
|
|
|
|
|
|
|
|
|
|
// HUD: resize handles, etc
|
|
|
|
|
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 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']); |
|
|
|
|
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, textures['ui']); |
|
|
|
|
upload_square_rgba16ui_texture(gl, handles.stroke_data, config.ui_texture_size); |
|
|
|
|
tv_add(hud_batches, 0); |
|
|
|
|
tv_add(hud_batches, compute_circle_lod(state.canvas.zoom * 2)); |
|
|
|
|
tv_add(hud_batches, ui_segments); |
|
|
|
|
tv_add(hud_batches, -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.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); |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
draw_strokes(state, context.canvas.width, context.canvas.height, programs, gl, lod_levels, ui_segments, |
|
|
|
|
total_lod_floats, |
|
|
|
|
total_lod_indices, |
|
|
|
|
hud_batches, |
|
|
|
|
handles.points, |
|
|
|
|
handles.ids, |
|
|
|
|
handles.pressures, |
|
|
|
|
buffers['b_hud'], |
|
|
|
|
buffers['i_hud'], |
|
|
|
|
textures['ui'], |
|
|
|
|
config.ui_texture_size, |
|
|
|
|
handles.stroke_data, |
|
|
|
|
8 |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (config.draw_bvh) { |
|
|
|
|