Name the aircraft icons' 76 device-pixel image switch, and give it in CSS pixels

The draw contract measures an icon's imageLod switch in CSS pixels; the
aircraft layers' GPU icons switch to their near image past 76 device
(drawing-buffer) pixels. iconAtlas now names that switch, which the icon
shader reads, and nearImageSwitchPx(pixelRatio) gives it in CSS pixels for
a layer moving onto the draw port: 76 over the scene's pixel ratio, the one
the quality port's frame signals report. On the default renderer that is
its pixelRatio setting, or 1 while that is browser-recommended;
devicePixelRatio does not enter it, so the default is 1.
This commit is contained in:
Sameh Khamis committed 2026-11-07 02:36:39 -08:00
1 parent 87395bb733
commit 2cc226c1f9
3 files changed
+61 -5

No files matched your search

+23
View File
@@ -9,6 +9,29 @@
* each slot's texture rectangle from `rects`. * each slot's texture rectangle from `rects`.
*/ */
/**
* Drawn width in device pixels (the drawing buffer's) past which an icon
* row with no switch of its own draws its near image: the aircraft layers'
* switch.
*/
export const NEAR_IMAGE_DEVICE_PX = 76;
/**
* `NEAR_IMAGE_DEVICE_PX` in CSS pixels, for an icon item's
* `imageLod.switchPx`, which the draw contract measures in CSS pixels: the
* device switch divided by the drawing buffer's pixels per CSS pixel. That
* is the scene's pixel ratio, which the quality port's frame signals report
* as `pixelRatio`: on the default renderer its `pixelRatio` setting, or 1
* while that is 0 (browser recommended). `devicePixelRatio` does not enter
* it. A layer drawing through the port passes the ratio its frames report
* and rewrites its rows' switch when that changes.
* @param {number} [pixelRatio] Drawing-buffer pixels per CSS pixel (1).
*/
export function nearImageSwitchPx(pixelRatio = 1) {
const ratio = Number.isFinite(pixelRatio) && pixelRatio > 0 ? pixelRatio : 1;
return NEAR_IMAGE_DEVICE_PX / ratio;
}
/** Slots a renderer can address (one vec4 uniform each). */ /** Slots a renderer can address (one vec4 uniform each). */
export const MAX_ICON_SLOTS = 64; export const MAX_ICON_SLOTS = 64;
+6 -5
View File
@@ -17,15 +17,16 @@
import * as Cesium from 'cesium'; import * as Cesium from 'cesium';
import { ICON_SEGMENT_GLSL, SEGMENT_STRIDE } from './iconSegment.js'; import { ICON_SEGMENT_GLSL, SEGMENT_STRIDE } from './iconSegment.js';
import { ICON_CULL_HEIGHT_M, ICON_CULL_LIFT, STYLE_STRIDE } from './iconSet.js'; import { ICON_CULL_HEIGHT_M, ICON_CULL_LIFT, STYLE_STRIDE } from './iconSet.js';
import { iconAtlas, MAX_ICON_SLOTS } from './iconAtlas.js'; import {
iconAtlas,
MAX_ICON_SLOTS,
NEAR_IMAGE_DEVICE_PX,
} from './iconAtlas.js';
import { import {
cameraLimbDistanceM, cameraLimbDistanceM,
getAircraftRecessionParams, getAircraftRecessionParams,
} from './aircraftRecession.js'; } from './aircraftRecession.js';
/** On-screen device pixels above which a row draws its near (large) image. */
const NEAR_IMAGE_PX = 76;
const ATTRIBUTE_LOCATIONS = Object.freeze({ const ATTRIBUTE_LOCATIONS = Object.freeze({
corner: 0, corner: 0,
seg0: 1, seg0: 1,
@@ -139,7 +140,7 @@ void main() {
float glyphPx = style0.x * scale * distanceScale * czm_pixelRatio; float glyphPx = style0.x * scale * distanceScale * czm_pixelRatio;
bool nearImage = style3.x > 0.0 bool nearImage = style3.x > 0.0
? glyphPx / czm_pixelRatio > style3.x ? glyphPx / czm_pixelRatio > style3.x
: glyphPx > ${NEAR_IMAGE_PX.toFixed(1)}; : glyphPx > ${NEAR_IMAGE_DEVICE_PX.toFixed(1)};
float slot = nearImage ? style1.y : style1.x; float slot = nearImage ? style1.y : style1.x;
if (slot < 0.0) return; // no image set if (slot < 0.0) return; // no image set
vec4 rect = u_slots[int(slot)]; vec4 rect = u_slots[int(slot)];
+32
View File
@@ -749,3 +749,35 @@ test('an SVG takes the atlas at its own size, other images at the item’s', asy
'an svg ref at its own', 'an svg ref at its own',
); );
}); });
test('an image switch in CSS pixels stands for the aircraft layers’ 76 device pixels', async () => {
const { NEAR_IMAGE_DEVICE_PX, nearImageSwitchPx } =
await import('../../data/iconAtlas.js');
assert.equal(NEAR_IMAGE_DEVICE_PX, 76);
assert.equal(nearImageSwitchPx(2), 38);
const display = globalThis.devicePixelRatio;
globalThis.devicePixelRatio = 2;
try {
assert.equal(
nearImageSwitchPx(),
76,
'the scene’s ratio, not the display’s',
);
} finally {
globalThis.devicePixelRatio = display;
}
assert.equal(nearImageSwitchPx(0), 76, 'no ratio: 1');
assert.equal(nearImageSwitchPx(NaN), 76);
const { part, draw } = drawOver();
const set = draw.icons({ id: 'gpu:switch-px' });
set.set([
icon('a', {
motion: { kind: 'hold' },
imageLod: { near: 'near.png', switchPx: nearImageSwitchPx(2) },
}),
]);
const { set: rowsOf } = rows(part, 'gpu:switch-px');
// Stored as given: the shader (not run here) switches past it in CSS
// pixels, the drawn width over the scene's pixel ratio.
assert.equal(rowsOf.imageSwitch(rowsOf.row('a')), 38);
});