Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/web/js/orrery.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ function requestReferenceTextures() {
const previous=referenceTextures[asset.id];
if(previous?.ready && (previous.plan.width>=plan.width || previous.failedWidth>=plan.width))continue;
if(entries.reduce((sum,e)=>sum+(e.loading?(e.pendingPlan||e.plan).decodedBytes:0),0)+plan.decodedBytes>MAX_REFERENCE_PENDING_BYTES)continue;
const attempt={tex:previous?.tex||null,ready:!!previous?.ready,loading:true,used:++referenceUseSerial,abort:new AbortController(),bitmap:null,plan:previous?.plan||plan,pendingPlan:plan,previous};
const attempt={tex:previous?.tex||null,linearFilter:previous?.linearFilter,ready:!!previous?.ready,loading:true,used:++referenceUseSerial,abort:new AbortController(),bitmap:null,plan:previous?.plan||plan,pendingPlan:plan,previous};
referenceTextures[asset.id]=attempt;state.appearanceStatus[asset.id]='loading';changed=true;
const current=()=>generation===textureGeneration && referenceTextures[asset.id]===attempt && attempt.loading && !attempt.abort.signal.aborted;
requestReferenceImage(asset,{plan,signal:attempt.abort.signal,onReady:bitmap=>{
Expand Down
2 changes: 1 addition & 1 deletion tests/web/helpers/orreryHarness.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function orreryHarness(t, options = {}) {
NEAREST: 9728, LINEAR: 9729, LINEAR_MIPMAP_LINEAR: 9987,
REPEAT: 10497, CLAMP_TO_EDGE: 33071,
UNPACK_ALIGNMENT: 3317, UNPACK_FLIP_Y_WEBGL: 37440, UNPACK_PREMULTIPLY_ALPHA_WEBGL: 37441,
R8: 33321, RED: 6403, UNSIGNED_BYTE: 5121,
R8: 33321, RED: 6403, RGBA: 6408, SRGB8_ALPHA8: 35907, UNSIGNED_BYTE: 5121,
ZERO:0,ONE:1,SRC_ALPHA:770,ONE_MINUS_SRC_ALPHA:771,TRIANGLES:4,LINES:1,LINE_STRIP:3,POINTS:0,
COMPILE_STATUS:35713,LINK_STATUS:35714,VERTEX_SHADER:35633,FRAGMENT_SHADER:35632,
MAX_TEXTURE_IMAGE_UNITS:34930,MAX_COMBINED_TEXTURE_IMAGE_UNITS:35661,ACTIVE_TEXTURE:34016,
Expand Down
26 changes: 22 additions & 4 deletions tests/web/referenceLoadingPolicy.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,34 @@ test('an inspected Earth uploads a bounded full-extent display grid instead of i
assert.equal(h.state.appearanceStatus[asset.id],'ready');
});

test('larger inspection upgrades a cached small map while retaining its ready texture',async t=>{
for(const outcome of ['ready','failed'])test(`larger inspection preserves reference color while its texture upgrade is pending and ${outcome}`,async t=>{
const h=await orreryHarness(t,{controls:true,reducedMotion:true});await h.enterOrrery();h.resize(240,160);h.input('orreryAnchor','Earth','change');
const asset=appearanceReference('Earth'),first=h.images.findLast(i=>i.src===asset.path);[first.width,first.height]=asset.dimensions;first.onload();await h.settle();
for(const role of ['night-lights','cloud-composite']){const a=appearanceReference('Earth',role),i=h.images.findLast(i=>i.src===a.path);[i.width,i.height]=a.dimensions;i.onload();}
assert.equal(first.width,512);const old=h.textureRecords.findLast(r=>r.pixels===first).texture;
assert.equal(first.width,512);const upload=h.textureRecords.findLast(r=>r.pixels===first),old=upload.texture;
assert.equal(upload.args[2],h.gl.SRGB8_ALPHA8,'the retained texture already decodes sRGB during sampling');
const assertLinearDraw=(texture,start=0)=>{
const draw=h.gpuDraws.slice(start).findLast(draw=>draw.uniforms.u_texMode===3&&draw.textures.get(0)===texture);
assert.ok(draw,'the registered surface is drawn with the expected texture');
assert.equal(draw.uniforms.u_textureLinear,1,'sRGB textures must not be decoded a second time by the shader');
};
assertLinearDraw(old);
const pendingStart=h.gpuDraws.length;
h.resize(800,600);const next=h.images.findLast(i=>i.src===asset.path);
assert.notEqual(next,first,'a larger projected globe requests a larger display variant');
assert.ok(!h.deletedTextures.includes(old),'the ready map remains until replacement is uploaded');
[next.width,next.height]=asset.dimensions;next.onload();await h.settle();
assert.ok(next.width>512&&next.width<=2048);assert.ok(h.deletedTextures.includes(old));
h.check('orreryShowLabels',false);
assertLinearDraw(old,pendingStart);
const settledStart=h.gpuDraws.length;
if(outcome==='ready'){
[next.width,next.height]=asset.dimensions;next.onload();await h.settle();
assert.ok(next.width>512&&next.width<=2048);assert.ok(h.deletedTextures.includes(old));
assertLinearDraw(h.textureRecords.findLast(r=>r.pixels===next).texture,settledStart);
}else{
next.onerror();await h.settle();
assert.ok(!h.deletedTextures.includes(old),'a failed upgrade retains the ready map');
assertLinearDraw(old,settledStart);
}
});

test('simultaneous decodes upload one per frame and stale bitmaps are closed',async t=>{
Expand Down
Loading