/** * @import { MeshInstance } from '../mesh-instance.js' */ /** * Sorts lists of mesh instances for rendering, with a stable least significant digit radix sort * over 8 bit digits of any number of unsigned 32 bit integer keys per mesh instance. Its cost * grows linearly with the number of mesh instances, unlike a comparison sort, and the digits all * mesh instances share are skipped, so keys with few distinct values sort in a few passes. * * The buffers grow with the longest list sorted and are reused by all sorts, so the renderer * shares a single instance between its forward and shadow passes. * * @ignore */ export class MeshInstanceSorter { /** * The key buffers, the least significant key first. * * @type {Uint32Array[]} * @private */ private _keys; /** * The order of the items being built, and the buffer each pass writes the new order to. * * @type {Uint32Array} * @private */ private _order; /** @private */ private _orderSwap; /** * The 256 entry histograms of the four digits of a key. * * @private */ private _histograms; /** * The items in their sorted order, before they are copied back to the sorted array. Emptied * after each sort, so that it keeps no mesh instances alive. * * @type {Array} * @private */ private _sorted; /** * Sorts mesh instances by their forward sort key, then by their mesh, both descending, so that * the mesh instances sharing a material and a mesh are drawn together. See * MeshInstance#updateKey. Used for SORTMODE_MATERIALMESH and for shadow casters. * * @param {MeshInstance[]} meshInstances - The mesh instances to sort in place. */ sortMaterialMesh(meshInstances: MeshInstance[]): void; /** * Makes room for `numKeys` keys of `count` items, which the caller writes before calling * {@link MeshInstanceSorter#_sort}. * * @param {number} count - The number of items to sort. * @param {number} numKeys - The number of keys per item. * @returns {Uint32Array[]} The key buffers, the least significant key first. * @private */ private _prepare; /** * Sorts the items by the keys written after {@link MeshInstanceSorter#_prepare}, by the most * significant key, then by the next one, all ascending. Items with equal keys keep their * order. * * @param {MeshInstance[]} items - The items to sort in place. * @param {number} count - The number of items to sort, from the start of the array. * @param {number} numKeys - The number of keys per item. * @private */ private _sort; /** * Orders the item indices in {@link MeshInstanceSorter#_order} by one of the keys. * * @param {Uint32Array} keys - The key of each item. * @param {number} count - The number of items. * @private */ private _sortByKey; } import type { MeshInstance } from '../mesh-instance.js';