From 471e696f71eebda5f6231e3bfa87c47d24d70492 Mon Sep 17 00:00:00 2001 From: Joshua T Corbin Date: Mon, 16 Oct 2023 22:00:34 -0400 Subject: [PATCH] [gltiles] add dirty tracking with send flush in bind --- gldemo.js | 7 ------- gltiles.js | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/gldemo.js b/gldemo.js index 6d90baad..7b7d19dc 100644 --- a/gldemo.js +++ b/gldemo.js @@ -130,12 +130,6 @@ export default async function runDemo(opts) { lastCurveClip ? clippedBaseCellQuery(bg, landCurveTiles) : extendedBaseCellQuery(bg, landCurveTiles)); - - // send layer data to gpu; NOTE this needs to be called going forward after any update - bg.send(); - fg.send(); - bgCurved.send(); - }; generateWorld(); @@ -153,7 +147,6 @@ export default async function runDemo(opts) { shouldClipCurvyTiles() ? clippedBaseCellQuery(bg, landCurveTiles) : extendedBaseCellQuery(bg, landCurveTiles)); - bgCurved.send(); } gl.enable(gl.BLEND); diff --git a/gltiles.js b/gltiles.js index 5878aa2a..ef29c31b 100644 --- a/gltiles.js +++ b/gltiles.js @@ -224,6 +224,7 @@ export default async function makeTileRenderer(gl) { const tileBuffer = gl.createBuffer(); const cap = width * height; + let dirty = true; const spinData = new Float32Array(cap); const tileData = new Uint16Array(cap); const index = makeElementIndex(gl, cap); @@ -240,6 +241,7 @@ export default async function makeTileRenderer(gl) { spinData.fill(0); tileData.fill(0); index.clear(); + dirty = true; }, /** @@ -255,6 +257,7 @@ export default async function makeTileRenderer(gl) { spinData[id] = spin; if (layerID === 0) index.delete(id); else index.add(id); + dirty = true; }, /** @@ -280,11 +283,11 @@ export default async function makeTileRenderer(gl) { gl.bindBuffer(gl.ARRAY_BUFFER, null); index.send(); + dirty = false; }, - draw() { - gl.useProgram(prog); - + bind() { + if (dirty) this.send(); viewParams.bind(); layerParams.bind(); @@ -301,6 +304,12 @@ export default async function makeTileRenderer(gl) { gl.vertexAttribIPointer(attrLayerID, 1, gl.UNSIGNED_SHORT, 0, 0); gl.bindBuffer(gl.ARRAY_BUFFER, null); + }, + + draw() { + gl.useProgram(prog); + + this.bind(); index.draw();