/** * additional import for TypeScript * @import WebGLRenderer from "./../webgl_renderer.js"; * @import {Matrix3d} from "../../../math/matrix3d.ts"; * @import {VertexFormat} from "../../gpu/vertexformat.ts"; * @import {Topology} from "../../gpu/topology.ts"; */ /** * The base WebGL Batcher — manages shader programs, vertex attribute * definitions, and vertex buffer batching for efficient GPU draw calls, * realizing the backend-neutral {@link Batcher} lifecycle on GL state. * Custom WebGL batchers extend this class. * @augments Batcher * @category Rendering */ export class WebGLBatcher extends Batcher { /** * @param {WebGLRenderer} renderer - the current WebGL renderer session * @param {object} settings - additional settings to initialize this batcher (see {@link WebGLBatcher#init}) */ constructor(renderer: WebGLRenderer, settings: object); /** * Initialize the batcher (called by the constructor) * @param {WebGLRenderer} renderer - the current WebGL renderer session * @param {object} settings - additional settings to initialize this batcher * @param {object[]} settings.attributes - an array of attributes definition * @param {string} settings.attributes.name - name of the attribute in the vertex shader * @param {number} settings.attributes.size - number of components per vertex attribute. Must be 1, 2, 3, or 4. * @param {GLenum} settings.attributes.type - data type of each component in the array * @param {boolean} settings.attributes.normalized - whether integer data values should be normalized into a certain range when being cast to a float * @param {number} settings.attributes.offset - offset in bytes of the first component in the vertex attribute array * @param {object} settings.shader - shader definition * @param {string} settings.shader.vertex - a string containing the GLSL source code to set * @param {string} settings.shader.fragment - a string containing the GLSL source code to set * @param {number} [settings.maxVertices=4096] - the maximum number of vertices this batcher can hold * @param {boolean} [settings.indexed=false] - whether this batcher uses an index buffer for indexed drawing (drawElements) * @param {string} [settings.projectionUniform="uProjectionMatrix"] - the name of the projection matrix uniform in the shader */ init(renderer: WebGLRenderer, settings: { attributes: { name: string; size: number; type: GLenum; normalized: boolean; offset: number; }; shader: { vertex: string; fragment: string; }; maxVertices?: number | undefined; indexed?: boolean | undefined; projectionUniform?: string | undefined; }): void; gl: any; viewMatrix: Matrix3d | undefined; /** * the default shader created by this batcher * @type {GLShader} */ defaultShader: GLShader | undefined; /** * the shader currently used by this batcher * @type {GLShader} */ currentShader: GLShader | undefined; /** * @param {Topology|number} value - a topology name or a GL primitive mode */ set mode(value: Topology | number); /** * Primitive type to render, as a GL enum (`gl.TRIANGLES`, `gl.LINES`, …). * * Assignable from either vocabulary — `batcher.mode = "line-list"` and * `batcher.mode = gl.LINES` are equivalent — but always reads back as the * GL enum, so existing comparisons keep working. Read * {@link WebGLBatcher#topology} for the portable name. * @type {number} * @default gl.TRIANGLES */ get mode(): number; vertexState: WebGLVertexState | null | undefined; /** * an array of vertex attribute properties * @see WebGLBatcher.addAttribute * @type {Array.} */ attributes: Object[] | undefined; /** * the stride of a single vertex in bytes * (will automatically be calculated as attributes definitions are added) * @see WebGLBatcher.addAttribute * @type {number} */ stride: number | undefined; /** * the size of a single vertex in floats * (will automatically be calculated as attributes definitions are added) * @see WebGLBatcher.addAttribute * @type {number} */ vertexSize: number | undefined; /** * the vertex data buffer used by this batcher * @type {VertexArrayBuffer} */ vertexData: VertexArrayBuffer | undefined; /** * the name of the projection matrix uniform in the shader * @type {string} */ projectionUniform: string | undefined; /** * whether this batcher uses indexed drawing * @type {boolean} */ useIndexBuffer: boolean | undefined; validatedShaders: WeakSet | undefined; /** * Select the shader to use for compositing * @see GLShader * @param {GLShader} shader - a reference to a GLShader instance */ useShader(shader: GLShader): void; currentSamplerUnit: number | undefined; /** * @param {Topology|number} value - a topology name or a GL primitive mode */ set topology(value: Topology | number); /** * How this batcher assembles vertices into primitives, in the * backend-neutral vocabulary. * * `"line-loop"` and `"triangle-fan"` are engine extensions with no * equivalent in modern GPU APIs — prefer the others for anything that must * survive a backend change. * @type {Topology} * @default "triangle-list" */ get topology(): Topology; /** * Add a vertex attribute to this batcher's layout. * * Accepts either vocabulary. The backend-neutral form names the component * type and count in one token, which is what a non-WebGL backend can * consume directly and what lets a layout be written without a live * rendering context: * * ```js * batcher.addAttribute({ name: "aColor", format: "unorm8x4", offset: 20 }); * batcher.addAttribute("aColor", "unorm8x4", 20); * ``` * * The GL form is supported indefinitely and behaves exactly as before: * * ```js * batcher.addAttribute("aColor", 4, gl.UNSIGNED_BYTE, true, 20); * ``` * * Records keep both spellings, so existing readers of `size` / `type` / * `normalized` are unaffected. A GL combination with no portable name — * three-component 8- and 16-bit types, which the neutral vocabulary does * not define — is stored with `format: undefined` rather than an invented * name that a backend could not honour. * * The layout is frozen once `init()` has built the vertex state, and each * record is frozen on insertion: a batcher rebuilds its vertex state from * these records after a context loss, so a later mutation would take * effect at restore time rather than where it was written. * @param {string|object} name - attribute name, or a descriptor object * @param {number|VertexFormat} [size] - component count (GL form), or the format (neutral form) * @param {GLenum|number} [type] - component type (GL form), or the byte offset (neutral form) * @param {boolean} [normalized] - whether integers are scaled into `[0, 1]` / `[-1, 1]` (GL form only) * @param {number} [offset] - byte offset of the attribute within a vertex (GL form) * @throws {Error} when the layout is frozen, the format or GL type is unknown, or a descriptor contradicts itself */ addAttribute(name: string | object, size?: number | VertexFormat, type?: GLenum | number, normalized?: boolean, offset?: number, ...args: any[]): void; /** * set/change the current projection matrix * @param {Matrix3d} matrix - the new projection matrix */ setProjection(matrix: Matrix3d): void; /** * Add index values to the index buffer (only for indexed batchers). * Indices are rebased relative to the current vertex count. * @param {number[]} indices - array of index values to add */ addIndices(indices: number[]): void; /** * Flush batched vertex data to the GPU * @param {number} [mode=gl.TRIANGLES] - the GL drawing mode */ flush(mode?: number): void; #private; } export default WebGLBatcher; import { Batcher } from "../../gpu/batcher.js"; import type WebGLRenderer from "./../webgl_renderer.js"; import type { Matrix3d } from "../../../math/matrix3d.ts"; import GLShader from "../glshader.js"; import type { Topology } from "../../gpu/topology.ts"; import WebGLVertexState from "../buffer/vertexstate.js"; import VertexArrayBuffer from "../../buffer/vertex.js"; import WebGLIndexBuffer from "../buffer/index.js"; import type { VertexFormat } from "../../gpu/vertexformat.ts"; //# sourceMappingURL=batcher.d.ts.map