mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Every image kind draws on the Cesium port, atlas slots wherever an image is taken
Icons on billboards and on the GPU, line patterns, shape fills, quads and raster shells take a URL, SVG, a blob (one object URL per blob), a keyed canvas (packed into the GPU icon atlas as it is, by its key) and an atlas slot as the image it holds. Blobs and canvases were refused on the GPU path, blobs on billboards, and atlas slots everywhere but billboards. The new conformance check draw.icons.images draws each kind on still and receding icons; Cesium runs it.
This commit is contained in:
1 parent
0e8be0fb78
commit
71f0945635
10 files changed
+229
-45
No files matched your search
+27
-14
@@ -81,12 +81,15 @@ function createAtlas() {
|
||||
},
|
||||
|
||||
/**
|
||||
* The slot for `url` rasterised at `sizePx` square.
|
||||
* The slot for `url` rasterised at `sizePx` square. Given a `source` (a
|
||||
* canvas, or anything else `drawImage` takes), `url` is only its key:
|
||||
* the source is packed at once, as it is now, and never loaded.
|
||||
* @param {string} url
|
||||
* @param {number} sizePx
|
||||
* @param {CanvasImageSource} [source]
|
||||
* @returns {number}
|
||||
*/
|
||||
slot(url, sizePx) {
|
||||
slot(url, sizePx, source) {
|
||||
const key = `${sizePx}|${url}`;
|
||||
const known = slotOfKey.get(key);
|
||||
if (known !== undefined) return known;
|
||||
@@ -98,7 +101,8 @@ function createAtlas() {
|
||||
const entry = { url, sizePx, image: null, x: 0, y: 0 };
|
||||
entries.push(entry);
|
||||
slotOfKey.set(key, slot);
|
||||
load(entry);
|
||||
if (source) placeLoaded(entry, source);
|
||||
else load(entry);
|
||||
return slot;
|
||||
},
|
||||
|
||||
@@ -129,23 +133,32 @@ function createAtlas() {
|
||||
},
|
||||
};
|
||||
|
||||
/** Pack an entry's loaded image, or leave its slot empty when it does not fit. */
|
||||
function placeLoaded(entry, image) {
|
||||
entry.image = image;
|
||||
// Node: nothing to pack into.
|
||||
if (
|
||||
typeof document === 'undefined' &&
|
||||
typeof OffscreenCanvas === 'undefined'
|
||||
)
|
||||
return;
|
||||
if (!pack()) {
|
||||
entry.image = null; // does not fit: leave its slot empty, keep the rest
|
||||
entry.failed = true;
|
||||
console.warn(
|
||||
`[iconAtlas] No room for ${entry.sizePx} px icon; slot stays empty`,
|
||||
);
|
||||
pack();
|
||||
}
|
||||
}
|
||||
|
||||
function load(entry) {
|
||||
if (typeof Image === 'undefined') return; // Node: slots only
|
||||
const image = new Image(entry.sizePx, entry.sizePx);
|
||||
image.decoding = 'async';
|
||||
// A cross-origin image would taint the canvas and every texture upload.
|
||||
image.crossOrigin = 'anonymous';
|
||||
image.onload = () => {
|
||||
entry.image = image;
|
||||
if (!pack()) {
|
||||
entry.image = null; // does not fit: leave its slot empty, keep the rest
|
||||
entry.failed = true;
|
||||
console.warn(
|
||||
`[iconAtlas] No room for ${entry.sizePx} px icon; slot stays empty`,
|
||||
);
|
||||
pack();
|
||||
}
|
||||
};
|
||||
image.onload = () => placeLoaded(entry, image);
|
||||
image.onerror = () => {
|
||||
entry.failed = true;
|
||||
console.warn(
|
||||
|
||||
Reference in new issue
Block a user