|
|
|
@ -11,9 +11,13 @@ function draw(state, context) {
@@ -11,9 +11,13 @@ function draw(state, context) {
|
|
|
|
|
const gl = context.gl; |
|
|
|
|
const width = window.innerWidth; |
|
|
|
|
const height = window.innerHeight; |
|
|
|
|
|
|
|
|
|
let query = null; |
|
|
|
|
|
|
|
|
|
const frame_start = performance.now(); |
|
|
|
|
const sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0); |
|
|
|
|
if (context.gpu_timer_ext !== null) { |
|
|
|
|
query = gl.createQuery(); |
|
|
|
|
gl.beginQuery(context.gpu_timer_ext.TIME_ELAPSED_EXT, query); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let locations; |
|
|
|
|
let buffers; |
|
|
|
@ -64,11 +68,17 @@ function draw(state, context) {
@@ -64,11 +68,17 @@ function draw(state, context) {
|
|
|
|
|
context.static_upload_from = context.static_serializer.offset; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const indices = segments_onscreen(state, context); |
|
|
|
|
const before_clip = performance.now(); |
|
|
|
|
segments_onscreen(state, context); |
|
|
|
|
const after_clip = performance.now(); |
|
|
|
|
console.debug('clip', after_clip - before_clip); |
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffers['b_packed_static_index']); |
|
|
|
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint32Array(indices), gl.DYNAMIC_DRAW); |
|
|
|
|
gl.drawElements(gl.TRIANGLES, indices.length, gl.UNSIGNED_INT, 0); |
|
|
|
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint32Array(state.onscreen_segments), gl.DYNAMIC_DRAW); |
|
|
|
|
const after_index_uploads = performance.now(); |
|
|
|
|
console.debug('index upload', after_index_uploads - after_clip); |
|
|
|
|
|
|
|
|
|
gl.drawElements(gl.TRIANGLES, state.onscreen_segments.length, gl.UNSIGNED_INT, 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (dynamic_points > 0) { |
|
|
|
@ -89,7 +99,7 @@ function draw(state, context) {
@@ -89,7 +99,7 @@ function draw(state, context) {
|
|
|
|
|
|
|
|
|
|
gl.drawArrays(gl.TRIANGLES, 0, dynamic_points); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
const next_tick = () => { |
|
|
|
|
const wait_status = gl.clientWaitSync(sync, 0, 0); |
|
|
|
|
const frame_end = performance.now(); |
|
|
|
@ -104,8 +114,36 @@ function draw(state, context) {
@@ -104,8 +114,36 @@ function draw(state, context) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setTimeout(next_tick, 0); |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
if (context.gpu_timer_ext) { |
|
|
|
|
gl.endQuery(context.gpu_timer_ext.TIME_ELAPSED_EXT); |
|
|
|
|
|
|
|
|
|
const next_tick = () => { |
|
|
|
|
if (query) { |
|
|
|
|
// At some point in the future, after returning control to the browser
|
|
|
|
|
const available = gl.getQueryParameter(query, gl.QUERY_RESULT_AVAILABLE); |
|
|
|
|
const disjoint = gl.getParameter(context.gpu_timer_ext.GPU_DISJOINT_EXT); |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (available || disjoint) { |
|
|
|
|
// Clean up the query object.
|
|
|
|
|
gl.deleteQuery(query); |
|
|
|
|
// Don't re-enter this polling loop.
|
|
|
|
|
query = null; |
|
|
|
|
} else { |
|
|
|
|
setTimeout(next_tick, 0); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(next_tick, 0); |
|
|
|
|
} |
|
|
|
|
// Images
|
|
|
|
|
// locations = context.locations['image'];
|
|
|
|
|
// buffers = context.buffers['image'];
|
|
|
|
|