/** * GPU-accelerated renderer for orthogonal TMX tile layers (WebGL2). Draws * the visible region of a layer as one screen-aligned quad per tileset * referenced by the layer — the fragment shader samples a per-layer GID * index texture and the tileset atlas, eliminating the per-tile draw * loop. The visible rect, GID range, tile size, opacity, and tint are * pushed as uniforms; the index texture is uploaded once at activation * and re-uploaded only when `layer.dataVersion` changes (mutations from * `setTile`/`clearTile`). * * The per-layer index texture is a `BufferTextureResource` flowing * through the standard `TextureCache` / batcher path — same lane as * every other texture in the engine. Dynamic unit allocation, correct * `boundTextures` bookkeeping, and per-resource premultiplied-alpha / * filter all come for free; nothing here pokes `gl.bindTexture` or * `gl.activeTexture` directly. * * Cache lifecycle: one `BufferTextureResource` per `TMXLayer`. Tile * layers don't come and go individually — they only churn on game reset * — so the cache is freed in bulk via `reset()`, called from * `WebGLRenderer.reset()` (which the `GAME_RESET` event already * triggers). * * @ignore */ export default class OrthogonalTMXLayerGPURenderer { /** * @param {WebGLRenderer} renderer - the WebGL renderer instance */ constructor(renderer: WebGLRenderer); renderer: WebGLRenderer; gl: WebGLRenderingContext; shader: GLShader; resources: Map; animLookups: Map; _v2: Float32Array; _v4: Float32Array; /** * Free every cached per-layer index texture and empty the local * resource map. Called from `WebGLRenderer.reset()` (which * `GAME_RESET` triggers) so each level transition starts clean. * @ignore */ reset(): void; /** * Write a `vec2` uniform without allocating a fresh Float32Array per * call. Both components flow into the shared `_v2` scratch buffer, * which `setUniform` reads synchronously and forwards to * `gl.uniform2fv` — so reusing the buffer across calls is safe. * @param {string} name * @param {number} x * @param {number} y * @private */ private _setV2; /** * `vec4` counterpart to {@link _setV2}. * @param {string} name * @param {number} x * @param {number} y * @param {number} z * @param {number} w * @private */ private _setV4; /** * Get-or-create the per-tileset animation-lookup entry. Returns * `undefined` for tilesets that have no animated tiles (the shader's * `uAnimEnabled` uniform is then set to 0 and the lookup texture is * not bound). * * The entry holds a `tileCount × 1` RGBA8 `BufferTextureResource` * where texel `localId` encodes the CURRENT frame's local id as * `R = lo byte, G = hi byte` (same encoding as the GID index * texture). Each call walks `tileset.animations` and rewrites * dirty texels — `tileset.update(dt)` (driven by the layer) advances * `anim.cur.tileid` independently of this renderer. * * @param {object} tileset * @param {number} tileCount - tiles in the tileset's atlas grid * (`atlasCols * atlasRows`) * @returns {{resource: BufferTextureResource, data: Uint8Array, * tileCount: number, dirty: boolean}|undefined} */ _getOrUpdateAnimLookup(tileset: object, tileCount: number): { resource: BufferTextureResource; data: Uint8Array; tileCount: number; dirty: boolean; } | undefined; /** * Get-or-create the per-layer index `BufferTextureResource`. * @param {TMXLayer} layer * @returns {BufferTextureResource} */ _getResource(layer: TMXLayer): BufferTextureResource; /** * Draw an orthogonal TMX layer through the shader path. * @param {TMXLayer} layer * @param {object} rect - the visible viewport rect (world coords) */ draw(layer: TMXLayer, rect: object): void; } import type { default as WebGLRenderer } from "../../webgl_renderer.js"; import GLShader from "../../glshader.js"; import { BufferTextureResource } from "../../../texture/resource.js"; import type { default as TMXLayer } from "../../../../level/tiled/TMXLayer.js"; //# sourceMappingURL=orthogonal.d.ts.map