/** * A texture data source that knows how to upload itself to a GPU * texture. Subclasses provide the actual upload logic for their kind * of source (raw buffer, image, compressed data, etc.). * * Resources flow through the same `TextureCache` / batcher machinery * as image-backed `TextureAtlas` instances: they expose the minimal * shape (`sources`, `activeAtlas`, `getTexture()`, plus `width` / * `height` / `premultipliedAlpha` / `repeat` / `filter`) the cache * uses for unit allocation and the batcher uses for `boundTextures` * bookkeeping. The cache therefore owns every backend bind call, * which keeps the JS-side binding state in lockstep with the actual * backend state across all texture kinds — image atlases included. * * Subclasses MUST implement `upload(context, target)`. The framework * calls it once per texture on first use (and again on forced re-upload * via `batcher.uploadTexture(resource, w, h, true)`). `context` is the * renderer's backend context (the value returned by * `renderer.getContext()`) — a `WebGLRenderingContext` / * `WebGL2RenderingContext` today, the WebGPU equivalent once that * renderer lands. The signature stays the same; each concrete * subclass uses whatever the context happens to be. * * @category Rendering */ export class TextureResource { /** * @param {object} options * @param {number} options.width - pixel width of the texture * @param {number} options.height - pixel height of the texture * @param {boolean} [options.premultipliedAlpha=false] * @param {string} [options.repeat="no-repeat"] - "no-repeat" | "repeat" | "repeat-x" | "repeat-y" * @param {number} [options.filter] - `gl.NEAREST` or `gl.LINEAR`; when * omitted the batcher falls back to the renderer's `antiAlias` setting */ constructor({ width, height, premultipliedAlpha, repeat, filter, }?: { width: number; height: number; premultipliedAlpha?: boolean | undefined; repeat?: string | undefined; filter?: number | undefined; }); /** @type {number} */ width: number; /** @type {number} */ height: number; /** @type {boolean} */ premultipliedAlpha: boolean; /** @type {string} */ repeat: string; /** @type {number|undefined} */ filter: number | undefined; sources: Map; activeAtlas: string; /** * Returns the upload "source" the batcher hands to `createTexture2D`. * For a resource this is the resource itself — `createTexture2D` * dispatches to `resource.upload(context, target)`. * @ignore */ getTexture(): this; /** * Issue the backend-specific upload call (`gl.texImage2D` on WebGL, * the WebGPU equivalent once that renderer lands) that places this * resource's data into the currently-bound texture slot. Subclasses * MUST override. * @abstract * @param {WebGLRenderingContext|WebGL2RenderingContext} context - the * renderer's backend context, as returned by `renderer.getContext()` * @param {number} target - the target to upload into (`TEXTURE_2D` on * WebGL today, the WebGPU equivalent once that lands) */ upload(context: WebGLRenderingContext | WebGL2RenderingContext, target: number): void; } /** * A texture sourced from a raw byte buffer. Used for synthesized * textures (TMX layer GID index, font atlases, color LUTs, signed- * distance fields, palette tables, etc.) — any case where the texture * data isn't an image file. * * The buffer is uploaded as-is; the resource's `premultipliedAlpha` * flag is applied at upload time so a raw-data texture (typical: * `premultipliedAlpha = false`) doesn't get its RGB wiped by the * driver when the alpha channel is zero. * * @category Rendering */ export class BufferTextureResource extends TextureResource { /** * @param {ArrayBufferView} data - the pixel data; size must be * `width * height * 4` bytes for the default RGBA / UNSIGNED_BYTE * format * @param {object} options * @param {number} options.width * @param {number} options.height * @param {boolean} [options.premultipliedAlpha=false] * @param {string} [options.repeat="no-repeat"] * @param {number} [options.filter] * @param {"rgba8"|"rgba8ui"} [options.format="rgba8"] - storage format. * `"rgba8"` (default): normalized RGBA, sampled via `sampler2D` / * `texture()`. `"rgba8ui"`: unsigned-integer RGBA, sampled via * `usampler2D` / `texelFetch()` — requires WebGL2. Use the integer * form for raw-data lookups (GID tables, palette indices, etc.) to * skip the float-decode round trip and gain exact integer reads. */ constructor(data: ArrayBufferView, options: { width: number; height: number; premultipliedAlpha?: boolean | undefined; repeat?: string | undefined; filter?: number | undefined; format?: "rgba8" | "rgba8ui" | undefined; }); /** @type {ArrayBufferView} */ data: ArrayBufferView; /** @type {string} */ format: string; /** @ignore */ upload(context: any, target: any): void; } //# sourceMappingURL=resource.d.ts.map