Skip to content

Commit

Permalink
[gltiles] add dirty tracking with send flush in bind
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorbin committed Oct 17, 2023
1 parent c3c11f3 commit 471e696
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
7 changes: 0 additions & 7 deletions gldemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -153,7 +147,6 @@ export default async function runDemo(opts) {
shouldClipCurvyTiles()
? clippedBaseCellQuery(bg, landCurveTiles)
: extendedBaseCellQuery(bg, landCurveTiles));
bgCurved.send();
}

gl.enable(gl.BLEND);
Expand Down
15 changes: 12 additions & 3 deletions gltiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -240,6 +241,7 @@ export default async function makeTileRenderer(gl) {
spinData.fill(0);
tileData.fill(0);
index.clear();
dirty = true;
},

/**
Expand All @@ -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;
},

/**
Expand All @@ -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();

Expand All @@ -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();

Expand Down

0 comments on commit 471e696

Please sign in to comment.