mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Read a material's held texture through internals.js, pinned to Cesium's Material
dropPendingTexture reads the private material._textures; it now does so through internals.js like every other private field. The internals test fails when the installed Cesium no longer declares _textures or no longer takes a uniform's texture as Material updates.
This commit is contained in:
1 parent
f1817756ed
commit
4972aac345
3 files changed
+31
-1
No files matched your search
@@ -38,6 +38,7 @@ import { provideUnboundDraw } from '../rendererOf.js';
|
||||
import { listenerList, toCartesian, uncaught } from './common.js';
|
||||
import { createGpuIcons, GPU_ICON_CAPABILITIES } from './gpuIcons.js';
|
||||
import { createModelSets } from './drawModels.js';
|
||||
import { materialTexture } from './internals.js';
|
||||
import { createMeshSets } from './drawMeshes.js';
|
||||
import { createQuadSets } from './drawQuads.js';
|
||||
import { createCesiumFields } from './drawFields.js';
|
||||
@@ -3727,7 +3728,7 @@ export function createCesiumDraw({
|
||||
function dropPendingTexture(image) {
|
||||
const texture = image.texture;
|
||||
if (!texture || texture.isDestroyed()) return;
|
||||
if (image.material._textures?.image === texture) return;
|
||||
if (materialTexture(image.material, 'image') === texture) return;
|
||||
texture.destroy();
|
||||
image.texture = null;
|
||||
}
|
||||
|
||||
@@ -205,3 +205,16 @@ export function creditDisplayContents(display) {
|
||||
logo: display?._currentCesiumCredit,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The texture a material holds for an image uniform. A material takes a
|
||||
* texture handed to a uniform (and destroys it when it takes the next one,
|
||||
* or is destroyed) only when it next updates; `draw.js` destroys one handed
|
||||
* over but never taken, so it does not leak.
|
||||
* @param {object} material Cesium Material.
|
||||
* @param {string} uniform The uniform's name.
|
||||
* @returns {object|undefined} Cesium Texture.
|
||||
*/
|
||||
export function materialTexture(material, uniform) {
|
||||
return material?._textures?.[uniform];
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
defaultView,
|
||||
lastRenderTime,
|
||||
lastSeenCamera,
|
||||
materialTexture,
|
||||
onEngineWorkCompleted,
|
||||
pickOffscreenView,
|
||||
renderPending,
|
||||
@@ -59,6 +60,7 @@ test('every private field the app reaches is still declared by the installed Ces
|
||||
[ENGINE, 'Scene/CreditDisplay.js', '_staticCredits'],
|
||||
[ENGINE, 'Scene/CreditDisplay.js', '_currentFrameCredits'],
|
||||
[ENGINE, 'Scene/CreditDisplay.js', '_currentCesiumCredit'],
|
||||
[ENGINE, 'Scene/Material.js', '_textures'],
|
||||
];
|
||||
const missing = fields.filter(
|
||||
([root, file, field]) =>
|
||||
@@ -84,6 +86,14 @@ test('every private field the app reaches is still declared by the installed Ces
|
||||
/\nTaskProcessor\.taskCompletedEvent = /,
|
||||
);
|
||||
assert.match(read('Scene/FrameState.js'), /this\.afterRender = \[\]/);
|
||||
// A material takes a texture handed to a uniform only as it updates,
|
||||
// destroying the one it held: one handed over and replaced first is
|
||||
// no one's (`materialTexture`, draw.js's `dropPendingTexture`).
|
||||
assert.match(
|
||||
read('Scene/Material.js'),
|
||||
/uniformValue instanceof Texture && uniformValue !== texture\) \{[\s\S]{0,200}?tmp\.destroy\(\);[\s\S]{0,40}?material\._textures\[uniformId\] = uniformValue;/,
|
||||
'Material takes a uniform texture on update',
|
||||
);
|
||||
// What makes them matter: each completion redraws the scene.
|
||||
const scene = read('Scene/Scene.js');
|
||||
// Every tick empties the after-render queue, outside its draw.
|
||||
@@ -136,6 +146,12 @@ test('the helpers read and write exactly those fields', () => {
|
||||
const clone = {};
|
||||
assert.equal(lastSeenCamera({ _view: { _cameraClone: clone } }), clone);
|
||||
assert.equal(lastSeenCamera({}), undefined);
|
||||
const texture = {};
|
||||
assert.equal(
|
||||
materialTexture({ _textures: { image: texture } }, 'image'),
|
||||
texture,
|
||||
);
|
||||
assert.equal(materialTexture({}, 'image'), undefined);
|
||||
const error = new Error('404');
|
||||
assert.equal(billboardLoadError({ loadError: error }), error);
|
||||
const gl = {};
|
||||
|
||||
Reference in new issue
Block a user