|
|
|
@ -66,19 +66,18 @@ function draw(state, context) {
@@ -66,19 +66,18 @@ function draw(state, context) {
|
|
|
|
|
gl.clearDepth(0.0); |
|
|
|
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
locations = context.locations['sdf'].main; |
|
|
|
|
buffers = context.buffers['sdf']; |
|
|
|
|
|
|
|
|
|
gl.useProgram(context.programs['sdf'].main); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bvh_clip(state, context); |
|
|
|
|
const segment_count = geometry_write_instances(state, context); |
|
|
|
|
|
|
|
|
|
// TODO: maybe have a pool of buffers (pow2?) and select an appropriate one
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance']); |
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array(context.instance_data.buffer, 0, segment_count * config.bytes_per_instance), gl.DYNAMIC_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, context.instance_data_points.size * 4, tv_data(context.instance_data_ids)); |
|
|
|
|
|
|
|
|
|
gl.uniform2f(locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
|
gl.uniform2f(locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
@ -88,13 +87,17 @@ function draw(state, context) {
@@ -88,13 +87,17 @@ function draw(state, context) {
|
|
|
|
|
gl.uniform1i(locations['u_stroke_data'], 0); |
|
|
|
|
gl.uniform1i(locations['u_stroke_texture_size'], config.stroke_texture_size); |
|
|
|
|
|
|
|
|
|
gl.enableVertexAttribArray(locations['a_ab']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_a']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_b']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_stroke_id']); |
|
|
|
|
|
|
|
|
|
// Points (a, b) and stroke ids are not stored in separate cpu buffers so that points can be resued
|
|
|
|
|
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_ab'], 4, gl.FLOAT, false, config.bytes_per_instance, 0); |
|
|
|
|
gl.vertexAttribIPointer(locations['a_stroke_id'], 1, gl.INT, config.bytes_per_instance, 4 * 4); |
|
|
|
|
|
|
|
|
|
gl.vertexAttribDivisor(locations['a_ab'], 1); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_a'], 1); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_b'], 1); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_stroke_id'], 1); |
|
|
|
|
|
|
|
|
|
gl.bindTexture(gl.TEXTURE_2D, context.textures['stroke_data']); |
|
|
|
@ -109,69 +112,6 @@ function draw(state, context) {
@@ -109,69 +112,6 @@ function draw(state, context) {
|
|
|
|
|
<span>Canvas offset: (${state.canvas.offset.x}, ${state.canvas.offset.y})</span> |
|
|
|
|
<span>Canvas zoom: ${Math.round(state.canvas.zoom * 100000) / 100000}</span>`; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
const after_clip = performance.now(); |
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, lod.data_buffer); |
|
|
|
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, lod.index_buffer); |
|
|
|
|
|
|
|
|
|
upload_if_needed(gl, gl.ARRAY_BUFFER, lod.vertices); |
|
|
|
|
upload_if_needed(gl, gl.ELEMENT_ARRAY_BUFFER, lod.indices); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (index_count > 0) { |
|
|
|
|
// DEPTH PREPASS
|
|
|
|
|
if (state.debug.do_prepass) { |
|
|
|
|
gl.drawBuffers([gl.NONE]); |
|
|
|
|
|
|
|
|
|
locations = context.locations['sdf'].opaque; |
|
|
|
|
|
|
|
|
|
gl.useProgram(context.programs['sdf'].opaque); |
|
|
|
|
|
|
|
|
|
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.stroke_count); |
|
|
|
|
|
|
|
|
|
gl.enableVertexAttribArray(locations['a_pos']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_line']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_stroke_id']); |
|
|
|
|
|
|
|
|
|
gl.vertexAttribPointer(locations['a_pos'], 3, gl.FLOAT, false, config.bytes_per_point, 0); |
|
|
|
|
gl.vertexAttribPointer(locations['a_line'], 4, gl.FLOAT, false, config.bytes_per_point, 4 * 3); |
|
|
|
|
gl.vertexAttribIPointer(locations['a_stroke_id'], 1, gl.INT, config.bytes_per_point, 4 * 3 + 4 * 4 + 4); |
|
|
|
|
|
|
|
|
|
gl.drawElements(gl.TRIANGLES, index_count, gl.UNSIGNED_INT, 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// MAIN PASS
|
|
|
|
|
gl.drawBuffers([gl.BACK]); |
|
|
|
|
|
|
|
|
|
locations = context.locations['sdf'].main; |
|
|
|
|
|
|
|
|
|
gl.useProgram(context.programs['sdf'].main); |
|
|
|
|
|
|
|
|
|
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.stroke_count); |
|
|
|
|
gl.uniform1i(locations['u_debug_mode'], state.debug.red); |
|
|
|
|
|
|
|
|
|
gl.enableVertexAttribArray(locations['a_pos']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_line']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_color']); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_stroke_id']); |
|
|
|
|
|
|
|
|
|
gl.vertexAttribPointer(locations['a_pos'], 3, gl.FLOAT, false, config.bytes_per_point, 0); |
|
|
|
|
gl.vertexAttribPointer(locations['a_line'], 4, gl.FLOAT, false, config.bytes_per_point, 4 * 3); |
|
|
|
|
gl.vertexAttribPointer(locations['a_color'], 3, gl.UNSIGNED_BYTE, true, config.bytes_per_point, 4 * 3 + 4 * 4); |
|
|
|
|
gl.vertexAttribIPointer(locations['a_stroke_id'], 1, gl.INT, config.bytes_per_point, 4 * 3 + 4 * 4 + 4); |
|
|
|
|
|
|
|
|
|
//index_buffer.reverse();
|
|
|
|
|
gl.drawElements(gl.TRIANGLES, index_count, gl.UNSIGNED_INT, 0); |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
/* |
|
|
|
|
// Dynamic data (stroke previews that are currently in progress)
|
|
|
|
|
const dynamic_points = context.dynamic_serializer.offset / config.bytes_per_point; |
|
|
|
@ -234,46 +174,6 @@ function draw(state, context) {
@@ -234,46 +174,6 @@ function draw(state, context) {
|
|
|
|
|
gl.drawElements(gl.TRIANGLES, dynamic_indices.length, gl.UNSIGNED_INT, 0); |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
if (state.debug.draw_bvh) { |
|
|
|
|
const points = new Float32Array(state.bvh.nodes.length * 6 * 2); |
|
|
|
|
|
|
|
|
|
for (let i = 0; i < state.bvh.nodes.length; ++i) { |
|
|
|
|
const box = state.bvh.nodes[i].bbox; |
|
|
|
|
|
|
|
|
|
points[i * 12 + 0] = box.x1; |
|
|
|
|
points[i * 12 + 1] = box.y1; |
|
|
|
|
points[i * 12 + 2] = box.x2; |
|
|
|
|
points[i * 12 + 3] = box.y1; |
|
|
|
|
points[i * 12 + 4] = box.x1; |
|
|
|
|
points[i * 12 + 5] = box.y2; |
|
|
|
|
|
|
|
|
|
points[i * 12 + 6] = box.x2; |
|
|
|
|
points[i * 12 + 7] = box.y2; |
|
|
|
|
points[i * 12 + 8] = box.x1; |
|
|
|
|
points[i * 12 + 9] = box.y2; |
|
|
|
|
points[i * 12 + 10] = box.x2; |
|
|
|
|
points[i * 12 + 11] = box.y1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
locations = context.locations['debug']; |
|
|
|
|
buffers = context.buffers['debug']; |
|
|
|
|
|
|
|
|
|
gl.useProgram(context.programs['debug']); |
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_packed']); |
|
|
|
|
|
|
|
|
|
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.enableVertexAttribArray(locations['a_pos']); |
|
|
|
|
gl.vertexAttribPointer(locations['a_pos'], 2, gl.FLOAT, false, 8, 0); |
|
|
|
|
|
|
|
|
|
gl.clear(gl.DEPTH_BUFFER_BIT); |
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, points, gl.STATIC_DRAW); |
|
|
|
|
gl.drawArrays(gl.TRIANGLES, 0, points.length / 2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (context.gpu_timer_ext) { |
|
|
|
|
gl.endQuery(context.gpu_timer_ext.TIME_ELAPSED_EXT); |
|
|
|
|
|
|
|
|
@ -308,4 +208,11 @@ function draw(state, context) {
@@ -308,4 +208,11 @@ function draw(state, context) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.querySelector('.debug-timings .cpu').innerHTML = 'Last CPU Frametime: ' + Math.round((cpu_after - cpu_before) * 100) / 100 + 'ms'; |
|
|
|
|
|
|
|
|
|
if (state.debug.benchmark_mode) { |
|
|
|
|
const redraw = state.debug.on_benchmark(); |
|
|
|
|
if (redraw) { |
|
|
|
|
schedule_draw(state, context); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|