@vcollab/shader-webgl2 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/README.md +86 -42
- package/dist/errors.d.ts +4 -0
- package/dist/geometry.d.ts +81 -0
- package/dist/index.cjs +488 -292
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -7
- package/dist/index.js +489 -294
- package/dist/index.js.map +1 -1
- package/dist/pick.d.ts +44 -27
- package/dist/pipeline.d.ts +60 -57
- package/package.json +3 -3
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/pipeline.ts","../src/pick.ts","../src/version.ts"],"names":["ShaderSet","ResourceBindings","UniformBlock","PICK_EMPTY","decodePick"],"mappings":";;;;;AAiCO,IAAM,kBAAA,GAAqB;AAG3B,IAAM,qBAAA,GAAwB;AA2B9B,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA,EACvB,IAAA,GAAO,iBAAA;AAC3B;AASA,SAAS,eAAe,KAAA,EAA2D;AACjF,EAAA,MAAM,KAAA,GAAQ,kBAAA,CAAmB,IAAA,CAAK,KAAA,CAAM,IAAI,CAAA;AAChD,EAAA,IAAI,KAAA,KAAU,IAAA,EAAM,OAAO,EAAE,SAAS,KAAA,CAAM,CAAC,CAAA,KAAM,GAAA,EAAK,KAAA,EAAO,MAAA,CAAO,KAAA,CAAM,CAAC,CAAC,CAAA,EAAE;AAChF,EAAA,IAAI,KAAA,CAAM,SAAS,OAAA,EAAS,OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,OAAO,CAAA,EAAE;AAC9D,EAAA,IAAI,KAAA,CAAM,SAAS,KAAA,EAAO,OAAO,EAAE,OAAA,EAAS,IAAA,EAAM,OAAO,CAAA,EAAE;AAC3D,EAAA,MAAM,IAAI,eAAA;AAAA,IACR,CAAA,EAAG,KAAA,CAAM,IAAI,CAAA,aAA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AAA,GAAU,MAAM,CAAA;AAAA,MAC9B,GAAG,MAAA,CAAO,MAAA,GAAS,IAAI,IAAA,CAAK,KAAA,CAAM,UAAU,MAAM;AAAA,KACpD;AAAA,EACF;AAAA;AAAA,EAGA,OAAA,GAAgB;AACd,IAAA,IAAA,CAAK,GAAA,CAAI,iBAAA,CAAkB,IAAA,CAAK,YAAY,CAAA;AAC5C,IAAA,IAAA,CAAK,QAAA,EAAS;AAAA,EAChB;AAAA,EAEA,QAAA,GAAiB;AACf,IAAA,MAAM,KAAK,IAAA,CAAK,GAAA;AAChB,IAAA,IAAI,KAAK,OAAA,KAAY,IAAA,EAAM,EAAA,CAAG,aAAA,CAAc,KAAK,OAAO,CAAA;AACxD,IAAA,IAAI,KAAK,MAAA,KAAW,IAAA,EAAM,EAAA,CAAG,kBAAA,CAAmB,KAAK,MAAM,CAAA;AAC3D,IAAA,IAAA,CAAK,OAAA,GAAU,IAAA;AACf,IAAA,IAAA,CAAK,MAAA,GAAS,IAAA;AACd,IAAA,IAAA,CAAK,MAAA,GAAS,CAAA;AACd,IAAA,IAAA,CAAK,OAAA,GAAU,CAAA;AAAA,EACjB;AACF;;;ACnQO,IAAM,OAAA,GAAkB","file":"index.cjs","sourcesContent":["// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n/**\n * One pipeline envelope, bound to a WebGL2 context.\n *\n * Everything here is driven by the envelope and nothing by knowledge of a\n * particular shader: the contract says which attributes to supply and which\n * uniforms exist, the layout says where each uniform sits, and the bindings\n * say which sampler uniform and texture unit each resource takes. A pipeline\n * this file has never heard of binds correctly as long as the set describes it.\n *\n * **What it deliberately does not do is decide values.** Which uniforms to\n * write, what to put in them, and what a table or image contains are the\n * caller's; this owns the GL objects and the wiring between them. That split is\n * what keeps a viewer's policy out of the binding layer and the binding layer\n * out of every viewer.\n *\n * Input it cannot use is refused with a {@link GLPipelineError} rather than\n * skipped: a draw that leaves a sampler unbound or reads an attribute with the\n * wrong type shows a plausible wrong picture, which is harder to find than an\n * exception.\n */\n\nimport type {\n AttributeSpec,\n Envelope,\n LanguageBlock,\n ShaderLanguage,\n} from \"@vcollab/shader-library\";\nimport { ResourceBindings, ShaderSet, UniformBlock } from \"@vcollab/shader-library\";\n\n/** The std140 block every emitted stage declares. */\nexport const UNIFORM_BLOCK_NAME = \"GlobalParams_std140\";\n\n/** The binding point the block is bound to. */\nexport const UNIFORM_BLOCK_BINDING = 0;\n\n/** One attribute's data, as the caller holds it. */\nexport interface AttributeSource {\n /**\n * Tightly packed, `components` values per vertex. `Int32Array` for an\n * attribute the contract declares `int`/`ivecN`, `Float32Array` for\n * `float`/`vecN`.\n */\n readonly data: Float32Array | Int32Array;\n /** How many values one vertex carries in `data`; at least the declared width. */\n readonly components: number;\n /**\n * Whether the shader reads it as an integer attribute. Checked against the\n * contract: a source that disagrees is refused.\n */\n readonly integer: boolean;\n}\n\n/** The geometry a pipeline draws. */\nexport interface Geometry {\n /** Attribute data by the contract's **semantic**, not by its declared name. */\n readonly attributes: ReadonlyMap<string, AttributeSource>;\n readonly indices: Uint32Array;\n}\n\n/** Raised for anything this context would not accept. */\nexport class GLPipelineError extends Error {\n override readonly name = \"GLPipelineError\";\n}\n\n/** An attribute the caller did not supply, held at a constant. */\ninterface AbsentAttribute {\n readonly location: number;\n readonly integer: boolean;\n}\n\n/** How a contract attribute type is fed: integer or float, and how wide. */\nfunction attributeShape(input: AttributeSpec): { integer: boolean; width: number } {\n const match = /^(i?)vec([234])$/.exec(input.type);\n if (match !== null) return { integer: match[1] === \"i\", width: Number(match[2]) };\n if (input.type === \"float\") return { integer: false, width: 1 };\n if (input.type === \"int\") return { integer: true, width: 1 };\n throw new GLPipelineError(\n `${input.name} is declared ${input.type}; only float, vecN, int and ivecN attributes ` +\n \"are supported\",\n );\n}\n\nfunction compile(\n gl: WebGL2RenderingContext,\n type: number,\n source: string,\n stage: string,\n): WebGLShader {\n const shader = gl.createShader(type);\n if (shader === null) throw new GLPipelineError(`could not create a ${stage} shader`);\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n const log = gl.getShaderInfoLog(shader);\n gl.deleteShader(shader);\n throw new GLPipelineError(`the ${stage} stage did not compile on this driver:\\n${log}`);\n }\n return shader;\n}\n\n/**\n * Compile and link one pipeline's two stages.\n *\n * The text is the build's output and is handed to the driver as it stands —\n * nothing is patched on the way. The only thing added is the report when a\n * driver disagrees, which is the one failure offline validation cannot rule\n * out. Every GL object made on the way is freed if a later step fails.\n */\nexport function linkProgram(\n gl: WebGL2RenderingContext,\n vertex: string,\n fragment: string,\n): WebGLProgram {\n const vertexShader = compile(gl, gl.VERTEX_SHADER, vertex, \"vertex\");\n let fragmentShader: WebGLShader;\n try {\n fragmentShader = compile(gl, gl.FRAGMENT_SHADER, fragment, \"fragment\");\n } catch (error) {\n gl.deleteShader(vertexShader);\n throw error;\n }\n const program = gl.createProgram();\n if (program === null) {\n gl.deleteShader(vertexShader);\n gl.deleteShader(fragmentShader);\n throw new GLPipelineError(\"could not create a program\");\n }\n gl.attachShader(program, vertexShader);\n gl.attachShader(program, fragmentShader);\n gl.linkProgram(program);\n // The shaders belong to the program once attached; deleting the handles here\n // frees them when the program goes.\n gl.deleteShader(vertexShader);\n gl.deleteShader(fragmentShader);\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n const log = gl.getProgramInfoLog(program);\n gl.deleteProgram(program);\n throw new GLPipelineError(`the stage pair did not link on this driver:\\n${log}`);\n }\n\n const blockIndex = gl.getUniformBlockIndex(program, UNIFORM_BLOCK_NAME);\n if (blockIndex !== gl.INVALID_INDEX) {\n gl.uniformBlockBinding(program, blockIndex, UNIFORM_BLOCK_BINDING);\n }\n return program;\n}\n\n/** A pipeline with its program, geometry, uniform buffer and resources. */\nexport class GLPipeline {\n readonly #gl: WebGL2RenderingContext;\n readonly #program: WebGLProgram;\n readonly #ubo: WebGLBuffer;\n readonly #vao: WebGLVertexArrayObject;\n /** The current geometry's vertex and index buffers; replaced by each setGeometry. */\n #buffers: WebGLBuffer[] = [];\n /** Attributes held at a constant, set again every draw (the constant is not VAO state). */\n #absent: AbsentAttribute[] = [];\n readonly #textures = new Map<string, WebGLTexture>();\n /** Each binding's sampler uniform location, in `bindings.all` order. */\n readonly #samplerLocations: (WebGLUniformLocation | null)[];\n /** A byte view of `uniforms.buffer`, made once. */\n readonly #uniformBytes: Uint8Array;\n #indexCount = 0;\n\n /** The envelope this was built from. */\n readonly envelope: Envelope;\n /** Its language block: layout, bindings and sources. */\n readonly block: LanguageBlock;\n /** Its sampler bindings, by semantic. */\n readonly bindings: ResourceBindings;\n /**\n * The uniform block to write into. The caller sets whatever the pipeline\n * declares; {@link draw} uploads it.\n */\n readonly uniforms: UniformBlock;\n\n /**\n * @throws {GLPipelineError} if the envelope lacks a stage, the driver rejects\n * the text, a GL object cannot be created, or the driver's size for the\n * uniform block differs from the size the build reflected. Anything created\n * before the failure is freed.\n */\n constructor(gl: WebGL2RenderingContext, envelope: Envelope, language: ShaderLanguage = \"glsl\") {\n this.#gl = gl;\n this.envelope = envelope;\n this.block = ShaderSet.language(envelope, language);\n const stages = this.block.stages;\n if (stages.vertex === undefined || stages.fragment === undefined) {\n throw new GLPipelineError(`${envelope.pipeline.id} does not carry both stages`);\n }\n const program = linkProgram(gl, stages.vertex.source, stages.fragment.source);\n let ubo: WebGLBuffer | null = null;\n try {\n this.bindings = new ResourceBindings(this.block);\n this.uniforms = new UniformBlock(this.block);\n this.#uniformBytes = new Uint8Array(this.uniforms.buffer);\n\n // The buffer bound to a block must be at least the size the driver\n // reports for it. std140 fixes every member's offset, so a driver may\n // report more than the reflected blockSize (trailing padding) and the\n // buffer simply grows to match. A driver block too small to hold the\n // last member the envelope records is a different layout, and refused.\n let bufferSize = this.block.blockSize;\n const blockIndex = gl.getUniformBlockIndex(program, UNIFORM_BLOCK_NAME);\n if (blockIndex !== gl.INVALID_INDEX) {\n const size: unknown = gl.getActiveUniformBlockParameter(\n program,\n blockIndex,\n gl.UNIFORM_BLOCK_DATA_SIZE,\n );\n const end = Math.max(\n 0,\n ...Object.values(this.block.layout).map((member) => member.offset + member.size),\n );\n if (typeof size !== \"number\" || size < end) {\n throw new GLPipelineError(\n `${envelope.pipeline.id}: the driver sizes ${UNIFORM_BLOCK_NAME} at ${String(size)} ` +\n `bytes, too small for the layout the build reflected, which ends at byte ${end}`,\n );\n }\n bufferSize = Math.max(bufferSize, size);\n }\n\n ubo = gl.createBuffer();\n if (ubo === null) throw new GLPipelineError(\"could not create a uniform buffer\");\n gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);\n gl.bufferData(gl.UNIFORM_BUFFER, bufferSize, gl.DYNAMIC_DRAW);\n\n const vao = gl.createVertexArray();\n if (vao === null) throw new GLPipelineError(\"could not create a vertex array\");\n\n this.#samplerLocations = this.bindings.all.map((record) =>\n gl.getUniformLocation(program, record.uniform),\n );\n this.#program = program;\n this.#ubo = ubo;\n this.#vao = vao;\n } catch (error) {\n if (ubo !== null) gl.deleteBuffer(ubo);\n gl.deleteProgram(program);\n throw error;\n }\n }\n\n /** The linked program, for a caller that needs it directly. */\n get program(): WebGLProgram {\n return this.#program;\n }\n\n /**\n * Upload the geometry, matching the contract's attributes by semantic.\n *\n * An attribute the caller cannot supply is left as a **disabled array with a\n * constant**, which is what a viewer does for data a draw does not have —\n * the same \"off state is data\" the always-present features rely on. The\n * constant is context state rather than vertex-array state, so {@link draw}\n * sets it again each time. The contract's declared width wins over the\n * source's, so a `vec3` read from a wider field takes the first three values\n * of each vertex.\n *\n * Calling it again replaces the previous geometry and frees its buffers.\n *\n * @throws {GLPipelineError} if a source's data type or `integer` flag does\n * not match the declared type, its `components` is narrower than the\n * declared width, or a buffer cannot be created. A refused source changes\n * nothing; when buffer creation fails the pipeline is left with no geometry.\n */\n setGeometry(geometry: Geometry): void {\n const gl = this.#gl;\n\n // Check everything before touching GL, so refused input changes nothing.\n const plan = this.envelope.pipeline.inputs.map((input) => {\n const shape = attributeShape(input);\n const source = geometry.attributes.get(input.semantic);\n if (source !== undefined) {\n const label = `${input.semantic} (${input.name}, ${input.type})`;\n if (source.integer !== shape.integer) {\n throw new GLPipelineError(\n `${label} is ${shape.integer ? \"an integer\" : \"a float\"} attribute; the source ` +\n `says integer: ${source.integer}`,\n );\n }\n const wanted = shape.integer ? Int32Array : Float32Array;\n if (!(source.data instanceof wanted)) {\n throw new GLPipelineError(`${label} needs ${wanted.name} data`);\n }\n if (!Number.isInteger(source.components) || source.components < shape.width) {\n throw new GLPipelineError(\n `${label} reads ${shape.width} values per vertex; the source carries ` +\n `${source.components}`,\n );\n }\n }\n return { input, shape, source, location: gl.getAttribLocation(this.#program, input.name) };\n });\n\n for (const buffer of this.#buffers) gl.deleteBuffer(buffer);\n this.#buffers = [];\n this.#absent = [];\n this.#indexCount = 0;\n\n const buffers: WebGLBuffer[] = [];\n const absent: AbsentAttribute[] = [];\n gl.bindVertexArray(this.#vao);\n try {\n for (const { input, shape, source, location } of plan) {\n if (location < 0) continue;\n if (source === undefined) {\n gl.disableVertexAttribArray(location);\n absent.push({ location, integer: shape.integer });\n continue;\n }\n const buffer = gl.createBuffer();\n if (buffer === null)\n throw new GLPipelineError(`could not create a buffer for ${input.name}`);\n buffers.push(buffer);\n gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\n gl.bufferData(gl.ARRAY_BUFFER, source.data, gl.STATIC_DRAW);\n gl.enableVertexAttribArray(location);\n const stride = source.components * 4;\n if (shape.integer) gl.vertexAttribIPointer(location, shape.width, gl.INT, stride, 0);\n else gl.vertexAttribPointer(location, shape.width, gl.FLOAT, false, stride, 0);\n }\n\n const elements = gl.createBuffer();\n if (elements === null) throw new GLPipelineError(\"could not create an index buffer\");\n buffers.push(elements);\n gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements);\n gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, geometry.indices, gl.STATIC_DRAW);\n } catch (error) {\n for (const buffer of buffers) gl.deleteBuffer(buffer);\n throw error;\n } finally {\n gl.bindVertexArray(null);\n }\n this.#buffers = buffers;\n this.#absent = absent;\n this.#indexCount = geometry.indices.length;\n }\n\n /**\n * Give a semantic its texture.\n *\n * By semantic, because the name a table or texture is declared under never\n * reaches the linked program: GLSL ES 3.00 has no binding qualifier for\n * samplers, so the cross-compiler pairs each texture with a sampler and names\n * the combination itself. The envelope's record is the only route across.\n *\n * An integer table (`usampler2D`) must use `NEAREST` filtering and no\n * mipmaps, or the texture is incomplete and every fetch returns zero.\n */\n setTexture(semantic: string, texture: WebGLTexture | null): void {\n if (texture === null) this.#textures.delete(semantic);\n else this.#textures.set(semantic, texture);\n }\n\n /** Every semantic this pipeline expects a texture for. */\n get requiredSemantics(): string[] {\n return this.bindings.semantics;\n }\n\n /**\n * Draw, after uploading the uniform block and binding every resource.\n *\n * A no-op without geometry. Leaves the current program, the active texture\n * unit and the texture bound on each of the pipeline's units changed.\n *\n * @throws {GLPipelineError} if any semantic in {@link requiredSemantics} has\n * no texture; the message names every one missing.\n */\n draw(): void {\n const gl = this.#gl;\n if (this.#indexCount === 0) return;\n\n const missing = this.requiredSemantics.filter((semantic) => !this.#textures.has(semantic));\n if (missing.length > 0) {\n throw new GLPipelineError(\n `${this.envelope.pipeline.id} has no texture for: ${missing.join(\", \")}`,\n );\n }\n\n gl.useProgram(this.#program);\n gl.bindBuffer(gl.UNIFORM_BUFFER, this.#ubo);\n gl.bufferSubData(gl.UNIFORM_BUFFER, 0, this.#uniformBytes);\n gl.bindBufferBase(gl.UNIFORM_BUFFER, UNIFORM_BLOCK_BINDING, this.#ubo);\n\n this.bindings.all.forEach((record, index) => {\n gl.activeTexture(gl.TEXTURE0 + record.unit);\n gl.bindTexture(gl.TEXTURE_2D, this.#textures.get(record.semantic) as WebGLTexture);\n const location = this.#samplerLocations[index] as WebGLUniformLocation | null;\n if (location !== null) gl.uniform1i(location, record.unit);\n });\n\n // The constant for a disabled array is context state, not VAO state, and\n // the same location can be a vec3 in one pipeline and an int in another.\n for (const { location, integer } of this.#absent) {\n if (integer) gl.vertexAttribI4i(location, 0, 0, 0, 0);\n else gl.vertexAttrib4f(location, 0, 0, 0, 0);\n }\n\n gl.bindVertexArray(this.#vao);\n gl.drawElements(gl.TRIANGLES, this.#indexCount, gl.UNSIGNED_INT, 0);\n gl.bindVertexArray(null);\n }\n\n /** Release the GL objects this owns. Textures given to it are the caller's. */\n dispose(): void {\n const gl = this.#gl;\n gl.deleteProgram(this.#program);\n gl.deleteBuffer(this.#ubo);\n gl.deleteVertexArray(this.#vao);\n for (const buffer of this.#buffers) gl.deleteBuffer(buffer);\n this.#buffers = [];\n this.#absent = [];\n this.#indexCount = 0;\n this.#textures.clear();\n }\n}\n","// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n/**\n * Hit-testing: the pick pipeline drawn into an offscreen integer target.\n *\n * The pick shape is exclusive — it writes identifiers *instead of* a color —\n * so picking is a second draw of the same geometry, not a feature added to the\n * color pipeline. That is the cheaper arrangement by some distance: the extra\n * draw happens when someone clicks, where making the color pipeline write a\n * second attachment would cost bandwidth on every frame, force every consumer\n * off the default framebuffer, and give up multisampling — an integer\n * attachment cannot be multisampled, and every attachment of a framebuffer\n * shares its sample count.\n *\n * Keeping the two passes in agreement is the price. The camera, the mask, the\n * placements and the deform scale must match what is on screen, or the pick\n * names something the viewer cannot see. {@link PickPass.pick} takes a callback\n * to write the uniforms for exactly that reason: the caller writes them from\n * the same state it used for the color pass, rather than this holding a\n * second copy that could drift.\n */\n\nimport type { Pick, UniformBlock } from \"@vcollab/shader-library\";\nimport { decodePick, PICK_EMPTY } from \"@vcollab/shader-library\";\nimport type { GLPipeline } from \"./pipeline.ts\";\nimport { GLPipelineError } from \"./pipeline.ts\";\n\n/** A hit, with the pixel it was found at. */\nexport interface PickHit extends Pick {\n /** Where the pick was taken, in framebuffer pixels. */\n readonly x: number;\n readonly y: number;\n}\n\nconst EMPTY_COLOR = new Uint32Array([PICK_EMPTY, PICK_EMPTY, PICK_EMPTY, PICK_EMPTY]);\nconst FAR_DEPTH = new Float32Array([1]);\n\n/**\n * An offscreen integer target and the pipeline that draws into it.\n *\n * The pass owns its framebuffer and resizes it with the viewport; the pipeline\n * is the caller's, built from a `pick` envelope whose vertex variant matches\n * the color pipeline's — `deform3.pick` for a `deform3` color pass, so that\n * deformed geometry is picked where it is drawn.\n */\nexport class PickPass {\n readonly #gl: WebGL2RenderingContext;\n readonly #pipeline: GLPipeline;\n readonly #framebuffer: WebGLFramebuffer;\n #target: WebGLTexture | null = null;\n #depth: WebGLRenderbuffer | null = null;\n #width = 0;\n #height = 0;\n readonly #readback = new Uint32Array(4);\n\n constructor(gl: WebGL2RenderingContext, pipeline: GLPipeline) {\n this.#gl = gl;\n this.#pipeline = pipeline;\n const framebuffer = gl.createFramebuffer();\n if (framebuffer === null) throw new GLPipelineError(\"could not create a pick framebuffer\");\n this.#framebuffer = framebuffer;\n }\n\n /** The pipeline drawing into the target, for setting its geometry and textures. */\n get pipeline(): GLPipeline {\n return this.#pipeline;\n }\n\n /**\n * Match the target to the viewport.\n *\n * `rgba32ui` for the attachment, with a depth buffer beside it so the\n * nearest primitive wins exactly as it does on screen. Neither is\n * multisampled: an integer attachment cannot be. Sizes are floored, and a\n * call at the current floored size does nothing. The caller's texture,\n * renderbuffer and framebuffer bindings are put back afterwards.\n *\n * @throws {GLPipelineError} if the texture or renderbuffer cannot be created\n * or the framebuffer is not complete; the pass is then left with no target.\n */\n resize(width: number, height: number): void {\n const gl = this.#gl;\n const w = Math.max(1, Math.floor(width));\n const h = Math.max(1, Math.floor(height));\n if (this.#target !== null && w === this.#width && h === this.#height) return;\n this.#release();\n\n const savedTexture = gl.getParameter(gl.TEXTURE_BINDING_2D) as WebGLTexture | null;\n const savedRenderbuffer = gl.getParameter(gl.RENDERBUFFER_BINDING) as WebGLRenderbuffer | null;\n const savedDraw = gl.getParameter(gl.DRAW_FRAMEBUFFER_BINDING) as WebGLFramebuffer | null;\n const savedRead = gl.getParameter(gl.READ_FRAMEBUFFER_BINDING) as WebGLFramebuffer | null;\n let target: WebGLTexture | null = null;\n let depth: WebGLRenderbuffer | null = null;\n try {\n target = gl.createTexture();\n if (target === null) throw new GLPipelineError(\"could not create a pick target texture\");\n gl.bindTexture(gl.TEXTURE_2D, target);\n gl.texImage2D(\n gl.TEXTURE_2D,\n 0,\n gl.RGBA32UI,\n w,\n h,\n 0,\n gl.RGBA_INTEGER,\n gl.UNSIGNED_INT,\n null,\n );\n // An integer texture can only be fetched, never filtered.\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);\n\n depth = gl.createRenderbuffer();\n if (depth === null) throw new GLPipelineError(\"could not create a pick depth buffer\");\n gl.bindRenderbuffer(gl.RENDERBUFFER, depth);\n gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT24, w, h);\n\n gl.bindFramebuffer(gl.FRAMEBUFFER, this.#framebuffer);\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, target, 0);\n gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depth);\n const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);\n if (status !== gl.FRAMEBUFFER_COMPLETE) {\n throw new GLPipelineError(\n `the pick framebuffer is not complete: 0x${status.toString(16)}`,\n );\n }\n\n this.#target = target;\n this.#depth = depth;\n this.#width = w;\n this.#height = h;\n target = null;\n depth = null;\n } finally {\n // Still set only if something above threw: free the half-built target.\n if (target !== null) gl.deleteTexture(target);\n if (depth !== null) gl.deleteRenderbuffer(depth);\n gl.bindTexture(gl.TEXTURE_2D, savedTexture);\n gl.bindRenderbuffer(gl.RENDERBUFFER, savedRenderbuffer);\n gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, savedDraw);\n gl.bindFramebuffer(gl.READ_FRAMEBUFFER, savedRead);\n }\n }\n\n /**\n * Draw the pick pass and read one pixel.\n *\n * The pass sets the state it depends on — no scissor, every color channel\n * and depth writable, `LESS` depth testing, no blending — and afterwards\n * puts back each of those, the viewport and the caller's framebuffers, even\n * if the draw throws. Face culling is left as the caller set it, so the pick\n * honours winding exactly as the color pass does. The pipeline's draw also\n * changes the current program and texture bindings (see\n * {@link GLPipeline.draw}).\n *\n * @param x horizontal position in framebuffer pixels, from the left.\n * @param y vertical position in framebuffer pixels, from the **bottom** —\n * GL's origin, not the DOM's. {@link fromCanvasPoint} converts.\n * @param writeUniforms fills the pipeline's block from the same state the\n * color pass used.\n * @returns the hit, or `null` where nothing was drawn or the point is outside.\n * @throws {GLPipelineError} before {@link resize} has been called, or if the\n * pipeline refuses to draw (a texture missing).\n */\n pick(x: number, y: number, writeUniforms: (uniforms: UniformBlock) => void): PickHit | null {\n const gl = this.#gl;\n if (this.#target === null)\n throw new GLPipelineError(\"the pick pass has no target; call resize first\");\n\n const px = Math.floor(x);\n const py = Math.floor(y);\n if (px < 0 || py < 0 || px >= this.#width || py >= this.#height) return null;\n\n writeUniforms(this.#pipeline.uniforms);\n\n const saved = {\n draw: gl.getParameter(gl.DRAW_FRAMEBUFFER_BINDING) as WebGLFramebuffer | null,\n read: gl.getParameter(gl.READ_FRAMEBUFFER_BINDING) as WebGLFramebuffer | null,\n viewport: gl.getParameter(gl.VIEWPORT) as Int32Array,\n blend: gl.isEnabled(gl.BLEND),\n depthTest: gl.isEnabled(gl.DEPTH_TEST),\n scissorTest: gl.isEnabled(gl.SCISSOR_TEST),\n depthMask: gl.getParameter(gl.DEPTH_WRITEMASK) as boolean,\n colorMask: gl.getParameter(gl.COLOR_WRITEMASK) as boolean[],\n depthFunc: gl.getParameter(gl.DEPTH_FUNC) as number,\n };\n\n // Failed or skipped reads must not return the previous hit.\n this.#readback.fill(PICK_EMPTY);\n try {\n gl.bindFramebuffer(gl.FRAMEBUFFER, this.#framebuffer);\n gl.viewport(0, 0, this.#width, this.#height);\n // The clears honour the scissor and the write masks, so set them first.\n gl.disable(gl.SCISSOR_TEST);\n gl.colorMask(true, true, true, true);\n gl.depthMask(true);\n // An integer attachment is not cleared by clearColor: that path is for\n // fixed- and floating-point buffers and leaves an integer target\n // untouched. Clearing to zero instead of PICK_EMPTY would make every\n // empty pixel decode as primitive 0.\n gl.clearBufferuiv(gl.COLOR, 0, EMPTY_COLOR);\n gl.clearBufferfv(gl.DEPTH, 0, FAR_DEPTH);\n gl.enable(gl.DEPTH_TEST);\n gl.depthFunc(gl.LESS);\n // Blending is ignored for an integer attachment, but a caller that left\n // it on for the color pass should not have to know that.\n gl.disable(gl.BLEND);\n\n this.#pipeline.draw();\n\n gl.readPixels(px, py, 1, 1, gl.RGBA_INTEGER, gl.UNSIGNED_INT, this.#readback);\n } finally {\n gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, saved.draw);\n gl.bindFramebuffer(gl.READ_FRAMEBUFFER, saved.read);\n const [vx, vy, vw, vh] = saved.viewport as unknown as [number, number, number, number];\n gl.viewport(vx, vy, vw, vh);\n const toggle = (cap: number, on: boolean) => (on ? gl.enable(cap) : gl.disable(cap));\n toggle(gl.BLEND, saved.blend);\n toggle(gl.DEPTH_TEST, saved.depthTest);\n toggle(gl.SCISSOR_TEST, saved.scissorTest);\n gl.depthMask(saved.depthMask);\n const [r, g, b, a] = saved.colorMask as [boolean, boolean, boolean, boolean];\n gl.colorMask(r, g, b, a);\n gl.depthFunc(saved.depthFunc);\n }\n\n const hit = decodePick(this.#readback);\n return hit === null ? null : { ...hit, x: px, y: py };\n }\n\n /**\n * A canvas point as {@link pick} wants it: the integer device pixel under\n * the point, counted from the bottom-left.\n *\n * A DOM event gives CSS pixels from the top-left of the element; GL reads\n * device pixels from the bottom-left. Getting this wrong picks a mirrored\n * point, which looks plausible near the middle and wrong everywhere else.\n * The top CSS row maps to row `height - 1`; a point on or past an edge maps\n * outside the target, where {@link pick} returns `null`.\n */\n static fromCanvasPoint(\n canvas: { clientWidth: number; clientHeight: number; width: number; height: number },\n offsetX: number,\n offsetY: number,\n ): { x: number; y: number } {\n const scaleX = canvas.width / Math.max(1, canvas.clientWidth);\n const scaleY = canvas.height / Math.max(1, canvas.clientHeight);\n return {\n x: Math.floor(offsetX * scaleX),\n y: canvas.height - 1 - Math.floor(offsetY * scaleY),\n };\n }\n\n /** Release the target, its depth buffer and the framebuffer. */\n dispose(): void {\n this.#gl.deleteFramebuffer(this.#framebuffer);\n this.#release();\n }\n\n #release(): void {\n const gl = this.#gl;\n if (this.#target !== null) gl.deleteTexture(this.#target);\n if (this.#depth !== null) gl.deleteRenderbuffer(this.#depth);\n this.#target = null;\n this.#depth = null;\n this.#width = 0;\n this.#height = 0;\n }\n}\n","// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n// __PKG_VERSION__ is replaced with the package.json version at build time by\n// tsup (see tsup.config.ts) and by vitest during tests (see vitest.config.ts).\n// package.json remains the single source of truth; it stays out of the TS\n// program so tsc can emit declarations cleanly (see tsconfig.build.json).\ndeclare const __PKG_VERSION__: string;\n\n/** The package version, injected from package.json at build time. */\nexport const VERSION: string = __PKG_VERSION__;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/geometry.ts","../src/pick.ts","../src/pipeline.ts","../src/version.ts"],"names":["PICK_EMPTY","PICK_CAPABILITY","decodePick","ShaderSet","ResourceBindings","UniformBlock"],"mappings":";;;;;AAIO,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA,EACvB,IAAA,GAAO,iBAAA;AAC3B;;;AC2DA,IAAM,SAAA,uBAAgB,OAAA,EAAkC;AASjD,SAAS,SAAA,CAAU,UAAsB,OAAA,EAA8B;AAC5E,EAAA,IAAI,GAAA,GAAM,SAAA,CAAU,GAAA,CAAI,QAAQ,CAAA;AAChC,EAAA,IAAI,QAAQ,MAAA,EAAW;AACrB,IAAA,GAAA,uBAAU,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OAAA,CAAQ,QAAQ,CAAC;AAAA,KAC1D;AACA,IAAA,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,QAAA,EAAU,OAAO,CAAA;AACpC,IAAA,OAAO,OAAA;AAAA,EACT;AACF;;;ACjbO,IAAM,OAAA,GAAkB","file":"index.cjs","sourcesContent":["// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n/** Raised for anything this context would not accept. */\nexport class GLPipelineError extends Error {\n override readonly name = \"GLPipelineError\";\n}\n","// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n/**\n * One slab's vertex and index data, uploaded once.\n *\n * Geometry and program change at different rates. A slab's positions, normals\n * and atom ids are fixed for as long as the model is loaded; the pipeline that\n * draws them changes whenever someone switches the result, the fringe, the\n * deformation or capping, and a pick pass draws the same slab through a pipeline\n * of its own. So the buffers live here, independent of any program, and every\n * {@link GLPipeline} that draws a geometry reads these buffers through a vertex\n * array it builds for itself. Switching pipelines uploads nothing.\n *\n * A geometry can **share** another's buffers and add or replace a few of its\n * own — the occurrences of one mesh drawn with different results, where the\n * positions, normals, ids and indices are the mesh's and only the result\n * buffer is the occurrence's. A shared geometry owns only what it uploaded, and\n * is disposed with the geometry it shares.\n */\n\nimport { GLPipelineError } from \"./errors.ts\";\n\n/** One attribute's data, as the caller holds it. */\nexport interface AttributeSource {\n /**\n * Tightly packed, `components` values per vertex. `Int32Array` for an\n * attribute the contract declares `int`/`ivecN`, `Float32Array` for\n * `float`/`vecN`.\n */\n readonly data: Float32Array | Int32Array;\n /** How many values one vertex carries in `data`; at least the declared width. */\n readonly components: number;\n /**\n * Whether the shader reads it as an integer attribute. Checked against the\n * contract when a pipeline first draws the geometry: a source that disagrees\n * is refused there.\n */\n readonly integer: boolean;\n}\n\n/** The data a geometry is made from. */\nexport interface GeometrySource {\n /** Attribute data by the contract's **semantic**, not by its declared name. */\n readonly attributes: ReadonlyMap<string, AttributeSource>;\n /**\n * Triangle indices. Required unless the geometry shares another's, whose\n * indices it then uses.\n */\n readonly indices?: Uint32Array;\n}\n\n/** One uploaded attribute, as a pipeline binds it. */\nexport interface GeometryAttribute {\n readonly buffer: WebGLBuffer;\n readonly components: number;\n readonly integer: boolean;\n /** The element type the buffer holds. */\n readonly type: \"float\" | \"int\";\n}\n\n/** Called when a geometry is disposed, so whoever built on it can let go. */\ntype Release = () => void;\n\n/** What is told when each geometry goes; module-private, for {@link GLPipeline}. */\nconst listeners = new WeakMap<GLGeometry, Set<Release>>();\n\n/**\n * Be told when a geometry is disposed. Returns the call that stops it.\n *\n * Not exported from the package: a pipeline uses it to drop the vertex array\n * it built over a geometry's buffers, so disposing a geometry never leaves a\n * pipeline holding one that points at deleted buffers.\n */\nexport function onDispose(geometry: GLGeometry, release: Release): () => void {\n let set = listeners.get(geometry);\n if (set === undefined) {\n set = new Set();\n listeners.set(geometry, set);\n }\n set.add(release);\n return () => set.delete(release);\n}\n\n/** A slab's buffers on the GPU, independent of any program. */\nexport class GLGeometry {\n readonly #gl: WebGL2RenderingContext;\n readonly #attributes = new Map<string, GeometryAttribute>();\n /** The buffers this geometry uploaded, and so deletes. */\n #owned: WebGLBuffer[] = [];\n #indexBuffer: WebGLBuffer | null;\n #disposed = false;\n #stopSharing: (() => void) | null = null;\n\n /** Vertices per attribute: every attribute, its own or shared, holds this many. */\n readonly vertexCount: number;\n /** How many indices a draw reads. */\n readonly indexCount: number;\n\n /**\n * Upload the attributes, and the indices unless shared.\n *\n * @param shares a geometry whose buffers this one reads for every semantic\n * it does not supply itself, and whose indices it draws with. It must\n * outlive this one; disposing it disposes this.\n * @throws {GLPipelineError} if an attribute's `components` is not a positive\n * integer, its data is not a whole number of vertices, two attributes\n * disagree on the vertex count, there are no indices to draw with, the\n * shared geometry is disposed, or a buffer cannot be created. Nothing is\n * left allocated.\n */\n constructor(gl: WebGL2RenderingContext, source: GeometrySource, shares?: GLGeometry) {\n this.#gl = gl;\n if (shares?.disposed) {\n throw new GLPipelineError(\"cannot share the buffers of a disposed geometry\");\n }\n\n // Check everything before touching GL, so refused input allocates nothing.\n let vertexCount = shares?.vertexCount;\n for (const [semantic, attribute] of source.attributes) {\n const { data, components } = attribute;\n if (!(data instanceof Float32Array || data instanceof Int32Array)) {\n throw new GLPipelineError(`${semantic}: data must be a Float32Array or an Int32Array`);\n }\n if (!Number.isInteger(components) || components < 1) {\n throw new GLPipelineError(\n `${semantic}: components is ${String(components)}, not a positive integer`,\n );\n }\n if (data.length % components !== 0) {\n throw new GLPipelineError(\n `${semantic}: ${data.length} values is not a whole number of ${components}-value vertices`,\n );\n }\n const count = data.length / components;\n if (vertexCount !== undefined && count !== vertexCount) {\n throw new GLPipelineError(\n `${semantic} holds ${count} vertices; the geometry has ${vertexCount}`,\n );\n }\n vertexCount = count;\n }\n const indices = source.indices;\n if (indices === undefined && shares === undefined) {\n throw new GLPipelineError(\"a geometry needs indices, or another geometry to share\");\n }\n this.vertexCount = vertexCount ?? 0;\n // One of the two is present: checked just above.\n this.indexCount = indices?.length ?? (shares as GLGeometry).indexCount;\n\n const owned: WebGLBuffer[] = [];\n // Uploading binds buffers; the caller's bindings are put back afterwards.\n const savedVertexArray = gl.getParameter(\n gl.VERTEX_ARRAY_BINDING,\n ) as WebGLVertexArrayObject | null;\n const savedArrayBuffer = gl.getParameter(gl.ARRAY_BUFFER_BINDING) as WebGLBuffer | null;\n try {\n for (const [semantic, attribute] of source.attributes) {\n const buffer = gl.createBuffer();\n if (buffer === null)\n throw new GLPipelineError(`could not create a buffer for ${semantic}`);\n owned.push(buffer);\n gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\n gl.bufferData(gl.ARRAY_BUFFER, attribute.data, gl.STATIC_DRAW);\n this.#attributes.set(semantic, {\n buffer,\n components: attribute.components,\n integer: attribute.integer,\n type: attribute.data instanceof Int32Array ? \"int\" : \"float\",\n });\n }\n if (indices !== undefined) {\n const buffer = gl.createBuffer();\n if (buffer === null) throw new GLPipelineError(\"could not create an index buffer\");\n owned.push(buffer);\n // WebGL fixes a buffer's kind at its first binding, so an index buffer\n // must be bound as ELEMENT_ARRAY_BUFFER from the start. That binding is\n // vertex-array state: with the caller's vertex array current it would\n // replace that array's indices, so none is current while it is made.\n gl.bindVertexArray(null);\n gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer);\n gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);\n gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);\n this.#indexBuffer = buffer;\n } else {\n this.#indexBuffer = null;\n }\n } catch (error) {\n for (const buffer of owned) gl.deleteBuffer(buffer);\n throw error;\n } finally {\n gl.bindBuffer(gl.ARRAY_BUFFER, savedArrayBuffer);\n gl.bindVertexArray(savedVertexArray);\n }\n this.#owned = owned;\n\n if (shares !== undefined) {\n for (const semantic of shares.semantics) {\n if (!this.#attributes.has(semantic)) {\n this.#attributes.set(semantic, shares.attribute(semantic) as GeometryAttribute);\n }\n }\n if (this.#indexBuffer === null) this.#indexBuffer = shares.indexBuffer;\n this.#stopSharing = onDispose(shares, () => this.dispose());\n }\n }\n\n /** Every semantic this geometry can feed, its own and shared. */\n get semantics(): string[] {\n return [...this.#attributes.keys()];\n }\n\n /** One semantic's buffer and layout, or undefined where it has none. */\n attribute(semantic: string): GeometryAttribute | undefined {\n return this.#attributes.get(semantic);\n }\n\n /** The index buffer a draw reads, its own or shared. */\n get indexBuffer(): WebGLBuffer {\n return this.#indexBuffer as WebGLBuffer;\n }\n\n /** Whether {@link dispose} has been called, here or on a geometry this shares. */\n get disposed(): boolean {\n return this.#disposed;\n }\n\n /**\n * Delete the buffers this geometry uploaded, and tell every pipeline that\n * drew it, so each drops the vertex array it built here. Geometries sharing\n * this one are disposed too. Calling it again does nothing.\n */\n dispose(): void {\n if (this.#disposed) return;\n this.#disposed = true;\n this.#stopSharing?.();\n this.#stopSharing = null;\n const waiting = listeners.get(this);\n listeners.delete(this);\n for (const release of waiting ?? []) release();\n for (const buffer of this.#owned) this.#gl.deleteBuffer(buffer);\n this.#owned = [];\n this.#attributes.clear();\n }\n}\n","// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n/**\n * Hit-testing: the pick pipeline drawn into an offscreen integer target.\n *\n * The pick shape is exclusive — it writes identifiers *instead of* a color —\n * so picking is a second draw of the same geometry, not a feature added to the\n * color pipeline. That is the cheaper arrangement by some distance: the extra\n * draw happens when someone clicks, where making the color pipeline write a\n * second attachment would cost bandwidth on every frame, force every consumer\n * off the default framebuffer, and give up multisampling — an integer\n * attachment cannot be multisampled, and every attachment of a framebuffer\n * shares its sample count.\n *\n * Keeping the two passes in agreement is the price. The camera, the mask, the\n * placements, the bases and the deform scale must match what is on screen, or\n * the pick names something the viewer cannot see. {@link PickPass.pick} takes\n * a callback that issues the draws for exactly that reason: the caller walks\n * its own scene and writes each draw's uniforms from the same state it used\n * for the color pass, rather than this holding a second copy that could drift.\n * One pick can draw through several pick pipelines — a scene mixes deformed\n * and undeformed slabs, capped and uncapped — so the pass owns no pipeline.\n */\n\nimport type { Pick } from \"@vcollab/shader-library\";\nimport { decodePick, PICK_CAPABILITY, PICK_EMPTY } from \"@vcollab/shader-library\";\nimport { GLPipelineError } from \"./errors.ts\";\nimport type { GLGeometry } from \"./geometry.ts\";\nimport type { GLPipeline } from \"./pipeline.ts\";\n\n/** A hit, with the pixel it was found at. */\nexport interface PickHit extends Pick {\n /** Where the pick was taken, in framebuffer pixels. */\n readonly x: number;\n readonly y: number;\n}\n\n/**\n * Draws one geometry through one pick pipeline into the pick target, with\n * that pipeline's uniforms and textures as the caller last set them.\n */\nexport type PickDraw = (pipeline: GLPipeline, geometry: GLGeometry) => void;\n\nconst EMPTY_COLOR = new Uint32Array([PICK_EMPTY, PICK_EMPTY, PICK_EMPTY, PICK_EMPTY]);\nconst FAR_DEPTH = new Float32Array([1]);\n\n/**\n * An offscreen integer target, drawn into by pick pipelines and read one pixel\n * at a time.\n *\n * The pass owns its framebuffer and resizes it with the viewport. The\n * pipelines are the caller's, each built from a `pick` envelope whose vertex\n * variant matches the color pipeline of what it draws — `deform3.pick` for a\n * `deform3` color pass, so that deformed geometry is picked where it is drawn\n * (`pickPipelineFor` in `@vcollab/shader-library` finds it).\n */\nexport class PickPass {\n readonly #gl: WebGL2RenderingContext;\n readonly #framebuffer: WebGLFramebuffer;\n #target: WebGLTexture | null = null;\n #depth: WebGLRenderbuffer | null = null;\n #width = 0;\n #height = 0;\n readonly #readback = new Uint32Array(4);\n\n constructor(gl: WebGL2RenderingContext) {\n this.#gl = gl;\n const framebuffer = gl.createFramebuffer();\n if (framebuffer === null) throw new GLPipelineError(\"could not create a pick framebuffer\");\n this.#framebuffer = framebuffer;\n }\n\n /**\n * Match the target to the viewport.\n *\n * `rgba32ui` for the attachment, with a depth buffer beside it so the\n * nearest primitive wins exactly as it does on screen. Neither is\n * multisampled: an integer attachment cannot be. Sizes are floored, and a\n * call at the current floored size does nothing. The caller's texture,\n * renderbuffer and framebuffer bindings are put back afterwards.\n *\n * @throws {GLPipelineError} if the texture or renderbuffer cannot be created\n * or the framebuffer is not complete; the pass is then left with no target.\n */\n resize(width: number, height: number): void {\n const gl = this.#gl;\n const w = Math.max(1, Math.floor(width));\n const h = Math.max(1, Math.floor(height));\n if (this.#target !== null && w === this.#width && h === this.#height) return;\n this.#release();\n\n const savedTexture = gl.getParameter(gl.TEXTURE_BINDING_2D) as WebGLTexture | null;\n const savedRenderbuffer = gl.getParameter(gl.RENDERBUFFER_BINDING) as WebGLRenderbuffer | null;\n const savedDraw = gl.getParameter(gl.DRAW_FRAMEBUFFER_BINDING) as WebGLFramebuffer | null;\n const savedRead = gl.getParameter(gl.READ_FRAMEBUFFER_BINDING) as WebGLFramebuffer | null;\n let target: WebGLTexture | null = null;\n let depth: WebGLRenderbuffer | null = null;\n try {\n target = gl.createTexture();\n if (target === null) throw new GLPipelineError(\"could not create a pick target texture\");\n gl.bindTexture(gl.TEXTURE_2D, target);\n gl.texImage2D(\n gl.TEXTURE_2D,\n 0,\n gl.RGBA32UI,\n w,\n h,\n 0,\n gl.RGBA_INTEGER,\n gl.UNSIGNED_INT,\n null,\n );\n // An integer texture can only be fetched, never filtered.\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);\n\n depth = gl.createRenderbuffer();\n if (depth === null) throw new GLPipelineError(\"could not create a pick depth buffer\");\n gl.bindRenderbuffer(gl.RENDERBUFFER, depth);\n gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT24, w, h);\n\n gl.bindFramebuffer(gl.FRAMEBUFFER, this.#framebuffer);\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, target, 0);\n gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depth);\n const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);\n if (status !== gl.FRAMEBUFFER_COMPLETE) {\n throw new GLPipelineError(\n `the pick framebuffer is not complete: 0x${status.toString(16)}`,\n );\n }\n\n this.#target = target;\n this.#depth = depth;\n this.#width = w;\n this.#height = h;\n target = null;\n depth = null;\n } finally {\n // Still set only if something above threw: free the half-built target.\n if (target !== null) gl.deleteTexture(target);\n if (depth !== null) gl.deleteRenderbuffer(depth);\n gl.bindTexture(gl.TEXTURE_2D, savedTexture);\n gl.bindRenderbuffer(gl.RENDERBUFFER, savedRenderbuffer);\n gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, savedDraw);\n gl.bindFramebuffer(gl.READ_FRAMEBUFFER, savedRead);\n }\n }\n\n /**\n * Draw the scene's pick pass and read one pixel.\n *\n * The target is cleared, then `drawScene` is called once with a {@link PickDraw}\n * and issues every draw the pick should see: for each occurrence, set its\n * pick pipeline's uniforms and textures as the color pass had them, then\n * `draw(pipeline, geometry)`. Nearest wins, as on screen.\n *\n * Only the pixel asked for is drawn: after the clear the scissor is set to\n * that one pixel, so a scene of thousands of draws shades one fragment each.\n * The pass sets the state it depends on — every color channel and depth\n * writable, `LESS` depth testing, no blending — and afterwards puts back\n * each of those, the scissor test and box, the viewport and the caller's\n * framebuffers, even if a draw throws. Face culling is left as the caller set\n * it, so the pick honors winding exactly as the color pass does. The draws\n * also change the current program and texture bindings (see\n * {@link GLPipeline.draw}).\n *\n * @param x horizontal position in framebuffer pixels, from the left.\n * @param y vertical position in framebuffer pixels, from the **bottom** —\n * GL's origin, not the DOM's. {@link fromCanvasPoint} converts.\n * @param drawScene issues the draws, through the `draw` it is given.\n * @returns the hit, or `null` where nothing was drawn or the point is\n * outside — in which case `drawScene` is not called.\n * @throws {GLPipelineError} before {@link resize} has been called, if a draw\n * names a pipeline that is not a pick pipeline (one writing a color into\n * this integer target would read back as garbage), or if a pipeline\n * refuses to draw. Anything `drawScene` throws is rethrown.\n */\n pick(x: number, y: number, drawScene: (draw: PickDraw) => void): PickHit | null {\n const gl = this.#gl;\n if (this.#target === null)\n throw new GLPipelineError(\"the pick pass has no target; call resize first\");\n\n const px = Math.floor(x);\n const py = Math.floor(y);\n if (px < 0 || py < 0 || px >= this.#width || py >= this.#height) return null;\n\n const saved = {\n draw: gl.getParameter(gl.DRAW_FRAMEBUFFER_BINDING) as WebGLFramebuffer | null,\n read: gl.getParameter(gl.READ_FRAMEBUFFER_BINDING) as WebGLFramebuffer | null,\n viewport: gl.getParameter(gl.VIEWPORT) as Int32Array,\n blend: gl.isEnabled(gl.BLEND),\n depthTest: gl.isEnabled(gl.DEPTH_TEST),\n scissorTest: gl.isEnabled(gl.SCISSOR_TEST),\n scissorBox: gl.getParameter(gl.SCISSOR_BOX) as Int32Array,\n depthMask: gl.getParameter(gl.DEPTH_WRITEMASK) as boolean,\n colorMask: gl.getParameter(gl.COLOR_WRITEMASK) as boolean[],\n depthFunc: gl.getParameter(gl.DEPTH_FUNC) as number,\n };\n\n // Failed or skipped reads must not return the previous hit.\n this.#readback.fill(PICK_EMPTY);\n try {\n gl.bindFramebuffer(gl.FRAMEBUFFER, this.#framebuffer);\n gl.viewport(0, 0, this.#width, this.#height);\n // The clears honour the scissor and the write masks, so set them first.\n gl.disable(gl.SCISSOR_TEST);\n gl.colorMask(true, true, true, true);\n gl.depthMask(true);\n // An integer attachment is not cleared by clearColor: that path is for\n // fixed- and floating-point buffers and leaves an integer target\n // untouched. Clearing to zero instead of PICK_EMPTY would make every\n // empty pixel decode as primitive 0.\n gl.clearBufferuiv(gl.COLOR, 0, EMPTY_COLOR);\n gl.clearBufferfv(gl.DEPTH, 0, FAR_DEPTH);\n gl.enable(gl.DEPTH_TEST);\n gl.depthFunc(gl.LESS);\n // Blending is ignored for an integer attachment, but a caller that left\n // it on for the color pass should not have to know that.\n gl.disable(gl.BLEND);\n // Every draw after the clear touches the one pixel read back.\n gl.enable(gl.SCISSOR_TEST);\n gl.scissor(px, py, 1, 1);\n\n drawScene((pipeline, geometry) => {\n if (!pipeline.envelope.pipeline.capabilities.includes(PICK_CAPABILITY)) {\n throw new GLPipelineError(\n `${pipeline.envelope.pipeline.id} is not a pick pipeline; the pick target ` +\n \"holds identifiers, and a color written into it reads back as garbage\",\n );\n }\n pipeline.draw(geometry);\n });\n\n gl.readPixels(px, py, 1, 1, gl.RGBA_INTEGER, gl.UNSIGNED_INT, this.#readback);\n } finally {\n gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, saved.draw);\n gl.bindFramebuffer(gl.READ_FRAMEBUFFER, saved.read);\n const [vx, vy, vw, vh] = saved.viewport as unknown as [number, number, number, number];\n gl.viewport(vx, vy, vw, vh);\n const toggle = (cap: number, on: boolean) => (on ? gl.enable(cap) : gl.disable(cap));\n toggle(gl.BLEND, saved.blend);\n toggle(gl.DEPTH_TEST, saved.depthTest);\n toggle(gl.SCISSOR_TEST, saved.scissorTest);\n const [sx, sy, sw, sh] = saved.scissorBox as unknown as [number, number, number, number];\n gl.scissor(sx, sy, sw, sh);\n gl.depthMask(saved.depthMask);\n const [r, g, b, a] = saved.colorMask as [boolean, boolean, boolean, boolean];\n gl.colorMask(r, g, b, a);\n gl.depthFunc(saved.depthFunc);\n }\n\n const hit = decodePick(this.#readback);\n return hit === null ? null : { ...hit, x: px, y: py };\n }\n\n /**\n * A canvas point as {@link pick} wants it: the integer device pixel under\n * the point, counted from the bottom-left.\n *\n * A DOM event gives CSS pixels from the top-left of the element; GL reads\n * device pixels from the bottom-left. Getting this wrong picks a mirrored\n * point, which looks plausible near the middle and wrong everywhere else.\n * The top CSS row maps to row `height - 1`; a point on or past an edge maps\n * outside the target, where {@link pick} returns `null`.\n */\n static fromCanvasPoint(\n canvas: { clientWidth: number; clientHeight: number; width: number; height: number },\n offsetX: number,\n offsetY: number,\n ): { x: number; y: number } {\n const scaleX = canvas.width / Math.max(1, canvas.clientWidth);\n const scaleY = canvas.height / Math.max(1, canvas.clientHeight);\n return {\n x: Math.floor(offsetX * scaleX),\n y: canvas.height - 1 - Math.floor(offsetY * scaleY),\n };\n }\n\n /** Release the target, its depth buffer and the framebuffer. */\n dispose(): void {\n this.#gl.deleteFramebuffer(this.#framebuffer);\n this.#release();\n }\n\n #release(): void {\n const gl = this.#gl;\n if (this.#target !== null) gl.deleteTexture(this.#target);\n if (this.#depth !== null) gl.deleteRenderbuffer(this.#depth);\n this.#target = null;\n this.#depth = null;\n this.#width = 0;\n this.#height = 0;\n }\n}\n","// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n/**\n * One pipeline envelope, bound to a WebGL2 context.\n *\n * A pipeline is one compiled program — one combination of features — and is\n * compiled once. It draws any {@link GLGeometry}: the geometry's buffers are\n * uploaded once, and the pipeline reads them through a vertex array it builds\n * for that geometry the first time it draws it and keeps until the geometry or\n * the pipeline is disposed. So a scene of many slabs needs one pipeline per\n * combination in use, and switching combination uploads nothing.\n *\n * Everything here is driven by the envelope and nothing by knowledge of a\n * particular shader: the contract says which attributes to supply and which\n * uniforms exist, the layout says where each uniform sits, and the bindings\n * say which sampler uniform and texture unit each resource takes. A pipeline\n * this file has never heard of binds correctly as long as the set describes it.\n *\n * **What it deliberately does not do is decide values.** Which uniforms to\n * write, what to put in them, and what a table or image contains are the\n * caller's; this owns the GL objects and the wiring between them. That split is\n * what keeps a viewer's policy out of the binding layer and the binding layer\n * out of every viewer.\n *\n * Input it cannot use is refused with a {@link GLPipelineError} rather than\n * skipped: a draw that leaves a sampler unbound or reads an attribute with the\n * wrong type shows a plausible wrong picture, which is harder to find than an\n * exception.\n */\n\nimport type {\n AttributeSpec,\n Envelope,\n LanguageBlock,\n ShaderLanguage,\n} from \"@vcollab/shader-library\";\nimport { ResourceBindings, ShaderSet, UniformBlock } from \"@vcollab/shader-library\";\nimport { GLPipelineError } from \"./errors.ts\";\nimport type { GLGeometry } from \"./geometry.ts\";\nimport { onDispose } from \"./geometry.ts\";\n\n/** The std140 block every emitted stage declares. */\nexport const UNIFORM_BLOCK_NAME = \"GlobalParams_std140\";\n\n/** The binding point the block is bound to. */\nexport const UNIFORM_BLOCK_BINDING = 0;\n\n/** An attribute the geometry does not supply, held at a constant. */\ninterface AbsentAttribute {\n readonly location: number;\n readonly integer: boolean;\n}\n\n/** What this pipeline built over one geometry. */\ninterface Binding {\n readonly vao: WebGLVertexArrayObject;\n readonly absent: readonly AbsentAttribute[];\n /** Stops the geometry telling this pipeline when it is disposed. */\n readonly forget: () => void;\n}\n\n/** How a contract attribute type is fed: integer or float, and how wide. */\nfunction attributeShape(input: AttributeSpec): { integer: boolean; width: number } {\n const match = /^(i?)vec([234])$/.exec(input.type);\n if (match !== null) return { integer: match[1] === \"i\", width: Number(match[2]) };\n if (input.type === \"float\") return { integer: false, width: 1 };\n if (input.type === \"int\") return { integer: true, width: 1 };\n throw new GLPipelineError(\n `${input.name} is declared ${input.type}; only float, vecN, int and ivecN attributes ` +\n \"are supported\",\n );\n}\n\nfunction compile(\n gl: WebGL2RenderingContext,\n type: number,\n source: string,\n stage: string,\n): WebGLShader {\n const shader = gl.createShader(type);\n if (shader === null) throw new GLPipelineError(`could not create a ${stage} shader`);\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n const log = gl.getShaderInfoLog(shader);\n gl.deleteShader(shader);\n throw new GLPipelineError(`the ${stage} stage did not compile on this driver:\\n${log}`);\n }\n return shader;\n}\n\n/**\n * Compile and link one pipeline's two stages.\n *\n * The text is the build's output and is handed to the driver as it stands —\n * nothing is patched on the way. The only thing added is the report when a\n * driver disagrees, which is the one failure offline validation cannot rule\n * out. Every GL object made on the way is freed if a later step fails.\n */\nexport function linkProgram(\n gl: WebGL2RenderingContext,\n vertex: string,\n fragment: string,\n): WebGLProgram {\n const vertexShader = compile(gl, gl.VERTEX_SHADER, vertex, \"vertex\");\n let fragmentShader: WebGLShader;\n try {\n fragmentShader = compile(gl, gl.FRAGMENT_SHADER, fragment, \"fragment\");\n } catch (error) {\n gl.deleteShader(vertexShader);\n throw error;\n }\n const program = gl.createProgram();\n if (program === null) {\n gl.deleteShader(vertexShader);\n gl.deleteShader(fragmentShader);\n throw new GLPipelineError(\"could not create a program\");\n }\n gl.attachShader(program, vertexShader);\n gl.attachShader(program, fragmentShader);\n gl.linkProgram(program);\n // The shaders belong to the program once attached; deleting the handles here\n // frees them when the program goes.\n gl.deleteShader(vertexShader);\n gl.deleteShader(fragmentShader);\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n const log = gl.getProgramInfoLog(program);\n gl.deleteProgram(program);\n throw new GLPipelineError(`the stage pair did not link on this driver:\\n${log}`);\n }\n\n const blockIndex = gl.getUniformBlockIndex(program, UNIFORM_BLOCK_NAME);\n if (blockIndex !== gl.INVALID_INDEX) {\n gl.uniformBlockBinding(program, blockIndex, UNIFORM_BLOCK_BINDING);\n }\n return program;\n}\n\n/** A compiled pipeline with its uniform buffer and resources, drawing any geometry. */\nexport class GLPipeline {\n readonly #gl: WebGL2RenderingContext;\n readonly #program: WebGLProgram;\n readonly #ubo: WebGLBuffer;\n /** The vertex array built over each geometry this has drawn. */\n readonly #bindings = new Map<GLGeometry, Binding>();\n /** Each contract input's shape and its location in this program, read once. */\n readonly #inputs: readonly {\n readonly input: AttributeSpec;\n readonly shape: { integer: boolean; width: number };\n readonly location: number;\n }[];\n readonly #textures = new Map<string, WebGLTexture>();\n /** Each binding's sampler uniform location, in `bindings.all` order. */\n readonly #samplerLocations: (WebGLUniformLocation | null)[];\n /** A byte view of `uniforms.buffer`, made once. */\n readonly #uniformBytes: Uint8Array;\n #disposed = false;\n\n /** The envelope this was built from. */\n readonly envelope: Envelope;\n /** Its language block: layout, bindings and sources. */\n readonly block: LanguageBlock;\n /** Its sampler bindings, by semantic. */\n readonly bindings: ResourceBindings;\n /**\n * The uniform block to write into. The caller sets whatever the pipeline\n * declares before each draw that needs different values; {@link draw}\n * uploads it.\n */\n readonly uniforms: UniformBlock;\n\n /**\n * @throws {GLPipelineError} if the envelope lacks a stage, declares an\n * attribute type this cannot feed, the driver rejects the text, a GL\n * object cannot be created, or the driver sizes the uniform block too\n * small for the layout the build reflected. Anything created before the\n * failure is freed.\n */\n constructor(gl: WebGL2RenderingContext, envelope: Envelope, language: ShaderLanguage = \"glsl\") {\n this.#gl = gl;\n this.envelope = envelope;\n this.block = ShaderSet.language(envelope, language);\n const stages = this.block.stages;\n if (stages.vertex === undefined || stages.fragment === undefined) {\n throw new GLPipelineError(`${envelope.pipeline.id} does not carry both stages`);\n }\n // Before compiling, so a contract this cannot feed costs no GL objects.\n const shapes = envelope.pipeline.inputs.map((input) => ({\n input,\n shape: attributeShape(input),\n }));\n const program = linkProgram(gl, stages.vertex.source, stages.fragment.source);\n try {\n this.bindings = new ResourceBindings(this.block);\n this.uniforms = new UniformBlock(this.block);\n this.#uniformBytes = new Uint8Array(this.uniforms.buffer);\n\n // The buffer bound to a block must be at least the size the driver\n // reports for it. std140 fixes every member's offset, so a driver may\n // report more than the reflected blockSize (trailing padding) and the\n // buffer simply grows to match. A driver block too small to hold the\n // last member the envelope records is a different layout, and refused.\n let bufferSize = this.block.blockSize;\n const blockIndex = gl.getUniformBlockIndex(program, UNIFORM_BLOCK_NAME);\n if (blockIndex !== gl.INVALID_INDEX) {\n const size: unknown = gl.getActiveUniformBlockParameter(\n program,\n blockIndex,\n gl.UNIFORM_BLOCK_DATA_SIZE,\n );\n const end = Math.max(\n 0,\n ...Object.values(this.block.layout).map((member) => member.offset + member.size),\n );\n if (typeof size !== \"number\" || size < end) {\n throw new GLPipelineError(\n `${envelope.pipeline.id}: the driver sizes ${UNIFORM_BLOCK_NAME} at ${String(size)} ` +\n `bytes, too small for the layout the build reflected, which ends at byte ${end}`,\n );\n }\n bufferSize = Math.max(bufferSize, size);\n }\n\n this.#samplerLocations = this.bindings.all.map((record) =>\n gl.getUniformLocation(program, record.uniform),\n );\n this.#inputs = shapes.map(({ input, shape }) => ({\n input,\n shape,\n location: gl.getAttribLocation(program, input.name),\n }));\n\n // Last, so nothing after it can fail and leave it allocated.\n const ubo = gl.createBuffer();\n if (ubo === null) throw new GLPipelineError(\"could not create a uniform buffer\");\n gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);\n gl.bufferData(gl.UNIFORM_BUFFER, bufferSize, gl.DYNAMIC_DRAW);\n this.#program = program;\n this.#ubo = ubo;\n } catch (error) {\n gl.deleteProgram(program);\n throw error;\n }\n }\n\n /** The linked program, for a caller that needs it directly. */\n get program(): WebGLProgram {\n return this.#program;\n }\n\n /**\n * Give a semantic its texture.\n *\n * By semantic, because the name a table or texture is declared under never\n * reaches the linked program: GLSL ES 3.00 has no binding qualifier for\n * samplers, so the cross-compiler pairs each texture with a sampler and names\n * the combination itself. The envelope's record is the only route across.\n *\n * The texture is used by every draw until it is replaced, so a caller giving\n * each occurrence a table of its own sets it before that occurrence's draw.\n * An integer table (`usampler2D`) must use `NEAREST` filtering and no\n * mipmaps, or the texture is incomplete and every fetch returns zero.\n */\n setTexture(semantic: string, texture: WebGLTexture | null): void {\n if (texture === null) this.#textures.delete(semantic);\n else this.#textures.set(semantic, texture);\n }\n\n /** Every semantic this pipeline expects a texture for. */\n get requiredSemantics(): string[] {\n return this.bindings.semantics;\n }\n\n /**\n * Check a geometry against this pipeline's contract and build the vertex\n * array that reads it, without drawing.\n *\n * {@link draw} does this on first use; calling it ahead moves a refusal to\n * where the geometry is made rather than the first frame. An attribute the\n * geometry does not supply is left as a **disabled array with a constant**,\n * which is what a viewer does for data a draw does not have — the same \"off\n * state is data\" the always-present features rely on. The contract's\n * declared width wins over the source's, so a `vec3` read from a wider field\n * takes the first three values of each vertex.\n *\n * @throws {GLPipelineError} if the geometry or this pipeline is disposed, a\n * source's element type or `integer` flag does not match the declared\n * type, its `components` is narrower than the declared width, or the\n * vertex array cannot be created. Nothing is kept for the geometry then.\n */\n prepare(geometry: GLGeometry): void {\n this.#binding(geometry);\n }\n\n /**\n * Forget the vertex array built over one geometry, as when it will not be\n * drawn by this pipeline again. Disposing the geometry does this for every\n * pipeline that drew it.\n */\n release(geometry: GLGeometry): void {\n const binding = this.#bindings.get(geometry);\n if (binding === undefined) return;\n this.#bindings.delete(geometry);\n binding.forget();\n this.#gl.deleteVertexArray(binding.vao);\n }\n\n /**\n * Draw a geometry, after uploading the uniform block and binding every\n * resource.\n *\n * The uniforms and textures are whatever was last set, so drawing one\n * geometry at several places — the occurrences of one mesh — is a loop of\n * \"set this occurrence's values, draw\". A geometry with no indices draws\n * nothing. Leaves the current program, the active texture unit, the texture\n * bound on each of the pipeline's units and the array buffer binding\n * changed, and no vertex array bound.\n *\n * @throws {GLPipelineError} if any semantic in {@link requiredSemantics} has\n * no texture (the message names every one missing), or for anything\n * {@link prepare} refuses.\n */\n draw(geometry: GLGeometry): void {\n const gl = this.#gl;\n if (this.#disposed) throw new GLPipelineError(`${this.envelope.pipeline.id} is disposed`);\n const missing = this.requiredSemantics.filter((semantic) => !this.#textures.has(semantic));\n if (missing.length > 0) {\n throw new GLPipelineError(\n `${this.envelope.pipeline.id} has no texture for: ${missing.join(\", \")}`,\n );\n }\n const binding = this.#binding(geometry);\n if (geometry.indexCount === 0) return;\n\n gl.useProgram(this.#program);\n gl.bindBuffer(gl.UNIFORM_BUFFER, this.#ubo);\n gl.bufferSubData(gl.UNIFORM_BUFFER, 0, this.#uniformBytes);\n gl.bindBufferBase(gl.UNIFORM_BUFFER, UNIFORM_BLOCK_BINDING, this.#ubo);\n\n this.bindings.all.forEach((record, index) => {\n gl.activeTexture(gl.TEXTURE0 + record.unit);\n gl.bindTexture(gl.TEXTURE_2D, this.#textures.get(record.semantic) as WebGLTexture);\n const location = this.#samplerLocations[index] as WebGLUniformLocation | null;\n if (location !== null) gl.uniform1i(location, record.unit);\n });\n\n // The constant for a disabled array is context state, not VAO state, and\n // the same location can be a vec3 in one pipeline and an int in another.\n for (const { location, integer } of binding.absent) {\n if (integer) gl.vertexAttribI4i(location, 0, 0, 0, 0);\n else gl.vertexAttrib4f(location, 0, 0, 0, 0);\n }\n\n gl.bindVertexArray(binding.vao);\n gl.drawElements(gl.TRIANGLES, geometry.indexCount, gl.UNSIGNED_INT, 0);\n gl.bindVertexArray(null);\n }\n\n /** Whether {@link dispose} has been called. */\n get disposed(): boolean {\n return this.#disposed;\n }\n\n /**\n * Release the GL objects this owns: the program, the uniform buffer and\n * every vertex array it built. Geometries and textures given to it are the\n * caller's and are left alone. Calling it again does nothing.\n */\n dispose(): void {\n if (this.#disposed) return;\n this.#disposed = true;\n for (const geometry of [...this.#bindings.keys()]) this.release(geometry);\n const gl = this.#gl;\n gl.deleteProgram(this.#program);\n gl.deleteBuffer(this.#ubo);\n this.#textures.clear();\n }\n\n /** The vertex array over a geometry: the one built before, or a new one. */\n #binding(geometry: GLGeometry): Binding {\n if (this.#disposed) {\n throw new GLPipelineError(`${this.envelope.pipeline.id} is disposed`);\n }\n if (geometry.disposed) throw new GLPipelineError(\"the geometry is disposed\");\n const known = this.#bindings.get(geometry);\n if (known !== undefined) return known;\n\n const gl = this.#gl;\n // Check everything before touching GL, so a refused geometry costs nothing.\n const plan = this.#inputs.map(({ input, shape, location }) => {\n const source = geometry.attribute(input.semantic);\n if (source !== undefined) {\n const label = `${input.semantic} (${input.name}, ${input.type})`;\n if (source.integer !== shape.integer) {\n throw new GLPipelineError(\n `${label} is ${shape.integer ? \"an integer\" : \"a float\"} attribute; the source ` +\n `says integer: ${source.integer}`,\n );\n }\n if (source.type !== (shape.integer ? \"int\" : \"float\")) {\n throw new GLPipelineError(\n `${label} needs ${shape.integer ? \"Int32Array\" : \"Float32Array\"} data`,\n );\n }\n if (source.components < shape.width) {\n throw new GLPipelineError(\n `${label} reads ${shape.width} values per vertex; the source carries ` +\n `${source.components}`,\n );\n }\n }\n return { shape, source, location };\n });\n\n const vao = gl.createVertexArray();\n if (vao === null) throw new GLPipelineError(\"could not create a vertex array\");\n const absent: AbsentAttribute[] = [];\n gl.bindVertexArray(vao);\n for (const { shape, source, location } of plan) {\n if (location < 0) continue;\n if (source === undefined) {\n gl.disableVertexAttribArray(location);\n absent.push({ location, integer: shape.integer });\n continue;\n }\n gl.bindBuffer(gl.ARRAY_BUFFER, source.buffer);\n gl.enableVertexAttribArray(location);\n const stride = source.components * 4;\n if (shape.integer) gl.vertexAttribIPointer(location, shape.width, gl.INT, stride, 0);\n else gl.vertexAttribPointer(location, shape.width, gl.FLOAT, false, stride, 0);\n }\n gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, geometry.indexBuffer);\n gl.bindVertexArray(null);\n\n const binding: Binding = {\n vao,\n absent,\n forget: onDispose(geometry, () => this.release(geometry)),\n };\n this.#bindings.set(geometry, binding);\n return binding;\n }\n}\n","// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n// __PKG_VERSION__ is replaced with the package.json version at build time by\n// tsup (see tsup.config.ts) and by vitest during tests (see vitest.config.ts).\n// package.json remains the single source of truth; it stays out of the TS\n// program so tsc can emit declarations cleanly (see tsconfig.build.json).\ndeclare const __PKG_VERSION__: string;\n\n/** The package version, injected from package.json at build time. */\nexport const VERSION: string = __PKG_VERSION__;\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,16 +6,21 @@
|
|
|
6
6
|
* and where. This is the renderer half for WebGL2: it owns the GL objects and
|
|
7
7
|
* the wiring, driven entirely by the envelope.
|
|
8
8
|
*
|
|
9
|
-
* - {@link
|
|
10
|
-
*
|
|
11
|
-
* - {@link
|
|
12
|
-
*
|
|
9
|
+
* - {@link GLGeometry} — one slab's buffers, uploaded once and drawn by any
|
|
10
|
+
* number of pipelines.
|
|
11
|
+
* - {@link GLPipeline} — one compiled stage pair: binds its resources by
|
|
12
|
+
* semantic, uploads its uniform block, and draws any geometry, reading it
|
|
13
|
+
* through a vertex array it keeps per geometry.
|
|
14
|
+
* - {@link PickPass} — an offscreen integer target that a scene's pick
|
|
15
|
+
* pipelines draw into, and one pixel read back.
|
|
13
16
|
*
|
|
14
17
|
* It decides no values. Which uniforms to write and what a table holds are the
|
|
15
18
|
* caller's; that split keeps a viewer's policy out of the binding layer.
|
|
16
19
|
*/
|
|
17
|
-
export
|
|
20
|
+
export { GLPipelineError } from "./errors.ts";
|
|
21
|
+
export type { AttributeSource, GeometryAttribute, GeometrySource } from "./geometry.ts";
|
|
22
|
+
export { GLGeometry } from "./geometry.ts";
|
|
23
|
+
export type { PickDraw, PickHit } from "./pick.ts";
|
|
18
24
|
export { PickPass } from "./pick.ts";
|
|
19
|
-
export
|
|
20
|
-
export { GLPipeline, GLPipelineError, linkProgram, UNIFORM_BLOCK_BINDING, UNIFORM_BLOCK_NAME, } from "./pipeline.ts";
|
|
25
|
+
export { GLPipeline, linkProgram, UNIFORM_BLOCK_BINDING, UNIFORM_BLOCK_NAME, } from "./pipeline.ts";
|
|
21
26
|
export { VERSION } from "./version.ts";
|