mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Hold up to 176 icon images in the shared atlas, addressed by the context's uniform room
The GPU icon shader sizes its slot array to what the context can address: the vertex uniform vectors it has, less 80 kept for the shader's other uniforms, between 64 and 176. A WebGL 2 context addresses all 176; a context with little room keeps the old 64, refuses sets that would need more, and warns once if the atlas outgrows it. Slots past the array are never read.
This commit is contained in:
1 parent
ef61be2b3b
commit
7a9c7b4d96
4 files changed
+119
-8
No files matched your search
+27
-2
@@ -32,8 +32,33 @@ export function nearImageSwitchPx(pixelRatio = 1) {
|
||||
return NEAR_IMAGE_DEVICE_PX / ratio;
|
||||
}
|
||||
|
||||
/** Slots a renderer can address (one vec4 uniform each). */
|
||||
export const MAX_ICON_SLOTS = 64;
|
||||
/**
|
||||
* Slots the atlas holds. A renderer addresses each through one vec4
|
||||
* uniform, as many as its context has room for (`addressableIconSlots`):
|
||||
* every WebGL 2 context has room for all of them.
|
||||
*/
|
||||
export const MAX_ICON_SLOTS = 176;
|
||||
/** Slots the renderer addresses, however few uniforms its context has. */
|
||||
export const MIN_ICON_SLOTS = 64;
|
||||
/**
|
||||
* Vertex uniform vectors the icon shader keeps for everything else: its own
|
||||
* and the renderer's (about 34), with room for drivers that keep constants
|
||||
* in uniforms.
|
||||
*/
|
||||
const OTHER_VERTEX_UNIFORMS = 80;
|
||||
|
||||
/**
|
||||
* How many slots a context with `maxVertexUniformVectors` addresses: all of
|
||||
* them on WebGL 2 (at least 256 vectors), at least `MIN_ICON_SLOTS`.
|
||||
* @param {number} maxVertexUniformVectors
|
||||
*/
|
||||
export function addressableIconSlots(maxVertexUniformVectors) {
|
||||
const room = Math.floor(maxVertexUniformVectors) - OTHER_VERTEX_UNIFORMS;
|
||||
return Math.max(
|
||||
MIN_ICON_SLOTS,
|
||||
Math.min(MAX_ICON_SLOTS, Number.isFinite(room) ? room : 0),
|
||||
);
|
||||
}
|
||||
|
||||
const PADDING_PX = 2;
|
||||
const START_SIZE_PX = 1024;
|
||||
|
||||
Reference in new issue
Block a user