|
|
|
@ -1,10 +1,6 @@
@@ -1,10 +1,6 @@
|
|
|
|
|
function schedule_draw(state, context) { |
|
|
|
|
if (!state.timers.raf) { |
|
|
|
|
window.requestAnimationFrame(() => { |
|
|
|
|
context._DRAW_TO_TEXTURE = true; |
|
|
|
|
draw(state, context); |
|
|
|
|
|
|
|
|
|
context._DRAW_TO_TEXTURE = false; |
|
|
|
|
draw(state, context) |
|
|
|
|
}); |
|
|
|
|
state.timers.raf = true; |
|
|
|
@ -58,11 +54,29 @@ function draw(state, context) {
@@ -58,11 +54,29 @@ function draw(state, context) {
|
|
|
|
|
gl.clearDepth(0.0); |
|
|
|
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
|
|
|
|
|
|
|
|
|
const before_clip = performance.now(); |
|
|
|
|
const index_count = segments_onscreen(state, context); |
|
|
|
|
const after_clip = performance.now(); |
|
|
|
|
let index_count; |
|
|
|
|
const do_clip = (state.canvas.zoom > config.clip_zoom_threshold); |
|
|
|
|
|
|
|
|
|
if (do_clip) { |
|
|
|
|
context.need_index_upload = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (do_clip || context.need_index_upload) { |
|
|
|
|
const before_clip = performance.now(); |
|
|
|
|
index_count = segments_onscreen(state, context, do_clip); |
|
|
|
|
const after_clip = performance.now(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!do_clip && !context.need_index_upload) { |
|
|
|
|
index_count = context.full_index_count; |
|
|
|
|
} |
|
|
|
|
//console.debug('clip', after_clip - before_clip);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.getElementById('debug-stats').innerHTML = ` |
|
|
|
|
<span>Segments onscreen: ${index_count}</span> |
|
|
|
|
<span>Canvas offset: (${state.canvas.offset.x}, ${state.canvas.offset.y})</span> |
|
|
|
|
<span>Canvas zoom: ${Math.round(state.canvas.zoom * 100) / 100}</span>`; |
|
|
|
|
|
|
|
|
|
if (index_count > 0) { |
|
|
|
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffers['b_packed_static_index']); |
|
|
|
|
|
|
|
|
@ -70,12 +84,18 @@ function draw(state, context) {
@@ -70,12 +84,18 @@ function draw(state, context) {
|
|
|
|
|
const static_points = context.static_serializer.offset / config.bytes_per_point; |
|
|
|
|
//const dynamic_points = context.dynamic_serializer.offset / config.bytes_per_point;
|
|
|
|
|
|
|
|
|
|
if (!do_clip) { |
|
|
|
|
// Almost everything on screen anyways. Only upload indices once
|
|
|
|
|
if (context.need_index_upload) { |
|
|
|
|
context.full_index_count = index_count; |
|
|
|
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, index_buffer, gl.STATIC_DRAW); |
|
|
|
|
context.need_index_upload = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (static_points > 0) { |
|
|
|
|
// DEPTH PREPASS
|
|
|
|
|
|
|
|
|
|
index_buffer.reverse(); |
|
|
|
|
|
|
|
|
|
if (context.do_prepass) { |
|
|
|
|
if (state.debug.do_prepass && do_clip) { |
|
|
|
|
gl.drawBuffers([gl.NONE]); |
|
|
|
|
|
|
|
|
|
locations = context.locations['sdf'].opaque; |
|
|
|
@ -95,11 +115,14 @@ function draw(state, context) {
@@ -95,11 +115,14 @@ function draw(state, context) {
|
|
|
|
|
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.bufferData(gl.ELEMENT_ARRAY_BUFFER, index_buffer, gl.DYNAMIC_DRAW); |
|
|
|
|
if (do_clip) { |
|
|
|
|
index_buffer.reverse(); |
|
|
|
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, index_buffer, gl.DYNAMIC_DRAW); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gl.drawElements(gl.TRIANGLES, index_count, gl.UNSIGNED_INT, 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MAIN PASS
|
|
|
|
|
gl.drawBuffers([gl.BACK]); |
|
|
|
|
|
|
|
|
@ -111,6 +134,7 @@ function draw(state, context) {
@@ -111,6 +134,7 @@ function draw(state, context) {
|
|
|
|
|
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']); |
|
|
|
@ -122,8 +146,13 @@ function draw(state, context) {
@@ -122,8 +146,13 @@ function draw(state, context) {
|
|
|
|
|
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.bufferData(gl.ELEMENT_ARRAY_BUFFER, index_buffer, gl.DYNAMIC_DRAW); |
|
|
|
|
if (do_clip) { |
|
|
|
|
if (state.debug.do_prepass) { |
|
|
|
|
index_buffer.reverse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, index_buffer, gl.DYNAMIC_DRAW); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gl.drawElements(gl.TRIANGLES, index_count, gl.UNSIGNED_INT, 0); |
|
|
|
|
} |
|
|
|
@ -162,7 +191,8 @@ function draw(state, context) {
@@ -162,7 +191,8 @@ function draw(state, context) {
|
|
|
|
|
if (available && !disjoint) { |
|
|
|
|
// See how much time the rendering of the object took in nanoseconds.
|
|
|
|
|
const timeElapsed = gl.getQueryParameter(query, gl.QUERY_RESULT); |
|
|
|
|
console.debug(timeElapsed / 1000000); |
|
|
|
|
//console.debug(timeElapsed / 1000000);
|
|
|
|
|
document.getElementById('debug-timings').innerHTML = 'Frametime: ' + Math.round(timeElapsed / 10000) / 100 + 'ms'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (available || disjoint) { |
|
|
|
|