@bigmistqke/view.gl 0.1.19 → 0.2.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/dist/{chunk-ZP4HP5H7.mjs → chunk-EYXOSM7B.mjs} +168 -67
- package/dist/chunk-EYXOSM7B.mjs.map +1 -0
- package/dist/gl.d.mts +1 -1
- package/dist/index.d.mts +13 -5
- package/dist/index.mjs +3 -1
- package/dist/tag.d.mts +1 -1
- package/dist/tag.mjs +1 -1
- package/dist/{types-DTSPQclW.d.mts → types-CyGyGi18.d.mts} +88 -5
- package/package.json +1 -1
- package/src/index.ts +243 -87
- package/src/types.ts +94 -4
- package/test/index.test.ts +228 -55
- package/test/mocks/webgl.ts +6 -0
- package/dist/chunk-ZP4HP5H7.mjs.map +0 -1
|
@@ -112,9 +112,62 @@ function view(gl, program, schema, options) {
|
|
|
112
112
|
uniforms: !schema.uniforms ? void 0 : uniformView(gl, program, schema.uniforms),
|
|
113
113
|
attributes: !schema.attributes ? void 0 : attributeView(gl, program, schema.attributes, options),
|
|
114
114
|
interleavedAttributes: !schema.interleavedAttributes ? void 0 : interleavedAttributeView(gl, program, schema.interleavedAttributes, options),
|
|
115
|
-
buffers: !schema.buffers ? void 0 : bufferView(gl, schema.buffers)
|
|
115
|
+
buffers: !schema.buffers ? void 0 : bufferView(gl, schema.buffers),
|
|
116
|
+
vao(participants) {
|
|
117
|
+
return vaoView(gl, participants, options);
|
|
118
|
+
}
|
|
116
119
|
};
|
|
117
120
|
}
|
|
121
|
+
function bindDefaultVertexArray(gl) {
|
|
122
|
+
const feature = getVertexArrayObject(gl);
|
|
123
|
+
if (!feature) {
|
|
124
|
+
return () => {
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const previous = gl.getParameter(VERTEX_ARRAY_BINDING);
|
|
128
|
+
feature.bindVertexArray(null);
|
|
129
|
+
return () => feature.bindVertexArray(previous);
|
|
130
|
+
}
|
|
131
|
+
function vaoView(gl, participants, { signal } = {}) {
|
|
132
|
+
const feature = getVertexArrayObject(gl);
|
|
133
|
+
const methods = !feature ? {
|
|
134
|
+
bind() {
|
|
135
|
+
const restores = participants.map((participant) => participant.applyToVertexArray());
|
|
136
|
+
participants.forEach((participant) => participant.applyToContext?.());
|
|
137
|
+
return once(() => restores.forEach((restore) => restore()));
|
|
138
|
+
},
|
|
139
|
+
unbind() {
|
|
140
|
+
},
|
|
141
|
+
dispose() {
|
|
142
|
+
}
|
|
143
|
+
} : (() => {
|
|
144
|
+
const vertexArray = assertedNotNullish(feature.createVertexArray());
|
|
145
|
+
const previous = gl.getParameter(VERTEX_ARRAY_BINDING);
|
|
146
|
+
feature.bindVertexArray(vertexArray);
|
|
147
|
+
for (const participant of participants) {
|
|
148
|
+
participant.applyToVertexArray();
|
|
149
|
+
}
|
|
150
|
+
feature.bindVertexArray(previous);
|
|
151
|
+
return {
|
|
152
|
+
bind() {
|
|
153
|
+
const previousVertexArray = gl.getParameter(
|
|
154
|
+
VERTEX_ARRAY_BINDING
|
|
155
|
+
);
|
|
156
|
+
feature.bindVertexArray(vertexArray);
|
|
157
|
+
participants.forEach((participant) => participant.applyToContext?.());
|
|
158
|
+
return once(() => feature.bindVertexArray(previousVertexArray));
|
|
159
|
+
},
|
|
160
|
+
unbind() {
|
|
161
|
+
feature.bindVertexArray(null);
|
|
162
|
+
},
|
|
163
|
+
dispose() {
|
|
164
|
+
feature.deleteVertexArray(vertexArray);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
})();
|
|
168
|
+
signal?.addEventListener("abort", () => methods.dispose());
|
|
169
|
+
return methods;
|
|
170
|
+
}
|
|
118
171
|
function uniformView(gl, program, schema) {
|
|
119
172
|
return mapObject(schema, ({ kind, size }, key) => {
|
|
120
173
|
const name2 = toID(key);
|
|
@@ -234,14 +287,23 @@ function attributeView(gl, program, schema, { signal } = {}) {
|
|
|
234
287
|
const resolvedFormat = format ?? defaultFormat(kind);
|
|
235
288
|
const glType = FORMAT_TO_GL_TYPE[resolvedFormat];
|
|
236
289
|
const isIntKind = kind.startsWith("i") || kind.startsWith("u");
|
|
290
|
+
function applyToVertexArray() {
|
|
291
|
+
const previousDivisor = readDivisor(gl, location);
|
|
292
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
293
|
+
handleAttribute(gl, location, size, 0, 0, glType, isIntKind, normalized, instanced);
|
|
294
|
+
return once(() => {
|
|
295
|
+
getInstancedArrays(gl)?.vertexAttribDivisor(location, previousDivisor);
|
|
296
|
+
});
|
|
297
|
+
}
|
|
237
298
|
return {
|
|
238
299
|
buffer,
|
|
300
|
+
applyToVertexArray,
|
|
239
301
|
bind() {
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
handleAttribute(gl, location, size, 0, 0, glType, isIntKind, normalized, instanced);
|
|
302
|
+
const restoreVertexArray = bindDefaultVertexArray(gl);
|
|
303
|
+
const restore = applyToVertexArray();
|
|
243
304
|
return once(() => {
|
|
244
|
-
|
|
305
|
+
restore();
|
|
306
|
+
restoreVertexArray();
|
|
245
307
|
});
|
|
246
308
|
},
|
|
247
309
|
dispose() {
|
|
@@ -260,8 +322,58 @@ function attributeView(gl, program, schema, { signal } = {}) {
|
|
|
260
322
|
});
|
|
261
323
|
return attributes;
|
|
262
324
|
}
|
|
325
|
+
function constantSource(gl, layout, locations) {
|
|
326
|
+
const setters = layout.map((entry, index2) => {
|
|
327
|
+
const size = kindToSize(entry.kind);
|
|
328
|
+
const name2 = toID(entry.key);
|
|
329
|
+
if (isMatKind(entry.kind) || size > 4) {
|
|
330
|
+
throw new Error(
|
|
331
|
+
`'${name2}' is a ${entry.kind}, which cannot be a constant attribute: vertexAttrib* takes at most 4 floats and has no matrix form. Use the buffer source for it.`
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
let values = [];
|
|
335
|
+
const fn = gl[`vertexAttrib${size}f`].bind(gl);
|
|
336
|
+
return {
|
|
337
|
+
name: name2,
|
|
338
|
+
location: locations[index2],
|
|
339
|
+
write: () => {
|
|
340
|
+
if (values.length) {
|
|
341
|
+
;
|
|
342
|
+
fn(locations[index2], ...values);
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
methods: {
|
|
346
|
+
set(...args) {
|
|
347
|
+
values = args;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
});
|
|
352
|
+
return Object.assign(Object.fromEntries(setters.map((setter) => [setter.name, setter.methods])), {
|
|
353
|
+
applyToVertexArray() {
|
|
354
|
+
const restores = setters.map(({ location }) => {
|
|
355
|
+
const wasEnabled = gl.getVertexAttrib(location, gl.VERTEX_ATTRIB_ARRAY_ENABLED);
|
|
356
|
+
gl.disableVertexAttribArray(location);
|
|
357
|
+
return () => wasEnabled ? gl.enableVertexAttribArray(location) : void 0;
|
|
358
|
+
});
|
|
359
|
+
return once(() => restores.forEach((restore) => restore()));
|
|
360
|
+
},
|
|
361
|
+
applyToContext() {
|
|
362
|
+
setters.forEach((setter) => setter.write());
|
|
363
|
+
},
|
|
364
|
+
bind() {
|
|
365
|
+
const restoreVertexArray = bindDefaultVertexArray(gl);
|
|
366
|
+
const restore = this.applyToVertexArray();
|
|
367
|
+
this.applyToContext();
|
|
368
|
+
return once(() => {
|
|
369
|
+
restore();
|
|
370
|
+
restoreVertexArray();
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
}
|
|
263
375
|
function interleavedAttributeView(gl, program, schema, { signal } = {}) {
|
|
264
|
-
const interleavedAttributes = mapObject(schema, ({ layout
|
|
376
|
+
const interleavedAttributes = mapObject(schema, ({ layout }) => {
|
|
265
377
|
let index2 = 0;
|
|
266
378
|
const locations = [];
|
|
267
379
|
const handles = layout.map((layout2) => {
|
|
@@ -278,7 +390,7 @@ function interleavedAttributeView(gl, program, schema, { signal } = {}) {
|
|
|
278
390
|
const isIntKind = layout2.kind.startsWith("i") || layout2.kind.startsWith("u");
|
|
279
391
|
const normalized = layout2.normalized ?? false;
|
|
280
392
|
index2 += size * FORMAT_BYTE_SIZE[resolvedFormat];
|
|
281
|
-
return () => handleAttribute(
|
|
393
|
+
return (divisor) => handleAttribute(
|
|
282
394
|
gl,
|
|
283
395
|
location,
|
|
284
396
|
size,
|
|
@@ -287,78 +399,57 @@ function interleavedAttributeView(gl, program, schema, { signal } = {}) {
|
|
|
287
399
|
glType,
|
|
288
400
|
isIntKind,
|
|
289
401
|
normalized,
|
|
290
|
-
|
|
402
|
+
divisor === 1
|
|
291
403
|
);
|
|
292
404
|
});
|
|
293
405
|
const stride = index2;
|
|
294
406
|
const buffer = assertedNotNullish(gl.createBuffer());
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
feature.bindVertexArray(vertexArray);
|
|
407
|
+
function applyToVertexArray(divisor) {
|
|
408
|
+
const previousDivisors = locations.map(
|
|
409
|
+
(location) => [location, readDivisor(gl, location)]
|
|
410
|
+
);
|
|
300
411
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
301
412
|
for (const handle of handles) {
|
|
302
|
-
handle();
|
|
413
|
+
handle(divisor);
|
|
303
414
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
415
|
+
return once(() => {
|
|
416
|
+
const instancedArrays = getInstancedArrays(gl);
|
|
417
|
+
previousDivisors.forEach(([location, previous]) => {
|
|
418
|
+
instancedArrays?.vertexAttribDivisor(location, previous);
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
let constant;
|
|
423
|
+
function bufferSource(divisor) {
|
|
424
|
+
const apply = () => applyToVertexArray(divisor);
|
|
425
|
+
return {
|
|
426
|
+
applyToVertexArray: apply,
|
|
309
427
|
bind() {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
428
|
+
const restoreVertexArray = bindDefaultVertexArray(gl);
|
|
429
|
+
const restore = apply();
|
|
430
|
+
return once(() => {
|
|
431
|
+
restore();
|
|
432
|
+
restoreVertexArray();
|
|
433
|
+
});
|
|
314
434
|
}
|
|
315
435
|
};
|
|
316
436
|
}
|
|
317
|
-
const unbind = () => {
|
|
318
|
-
if (vao) {
|
|
319
|
-
vao.unbind();
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
437
|
return {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
} else {
|
|
330
|
-
for (const handle of handles) {
|
|
331
|
-
handle();
|
|
332
|
-
}
|
|
438
|
+
buffer: Object.assign(bufferSource(0), {
|
|
439
|
+
/** The same buffer, stepped once per instance instead of once per vertex. */
|
|
440
|
+
perInstance: bufferSource(1),
|
|
441
|
+
set(value, usage = "STATIC_DRAW") {
|
|
442
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
443
|
+
gl.bufferData(gl.ARRAY_BUFFER, value, gl[usage]);
|
|
333
444
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const instancedArrays = getInstancedArrays(gl);
|
|
340
|
-
previousDivisors.forEach(([location, divisor]) => {
|
|
341
|
-
instancedArrays?.vertexAttribDivisor(location, divisor);
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
});
|
|
445
|
+
}),
|
|
446
|
+
// Lazy: a layout key can be perfectly good in a buffer and impossible as
|
|
447
|
+
// a constant, and finding that out should wait until someone asks for one.
|
|
448
|
+
get constant() {
|
|
449
|
+
return constant ??= constantSource(gl, layout, locations);
|
|
345
450
|
},
|
|
346
|
-
unbind,
|
|
347
451
|
dispose() {
|
|
348
452
|
gl.deleteBuffer(buffer);
|
|
349
|
-
if (vao) {
|
|
350
|
-
vao.dispose();
|
|
351
|
-
}
|
|
352
|
-
},
|
|
353
|
-
set(value, usage = "STATIC_DRAW") {
|
|
354
|
-
if (vao) {
|
|
355
|
-
vao.bind();
|
|
356
|
-
}
|
|
357
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
358
|
-
gl.bufferData(gl.ARRAY_BUFFER, value, gl[usage]);
|
|
359
|
-
if (vao) {
|
|
360
|
-
vao.unbind();
|
|
361
|
-
}
|
|
362
453
|
}
|
|
363
454
|
};
|
|
364
455
|
});
|
|
@@ -370,12 +461,21 @@ function interleavedAttributeView(gl, program, schema, { signal } = {}) {
|
|
|
370
461
|
function bufferView(gl, schema, { signal } = {}) {
|
|
371
462
|
const buffers = mapObject(schema, ({ target = "ARRAY_BUFFER", usage = "STATIC_DRAW" }) => {
|
|
372
463
|
const buffer = assertedNotNullish(gl.createBuffer());
|
|
464
|
+
function applyToVertexArray() {
|
|
465
|
+
const previousBuffer = gl.getParameter(gl[`${target}_BINDING`]);
|
|
466
|
+
gl.bindBuffer(gl[target], buffer);
|
|
467
|
+
return once(() => {
|
|
468
|
+
gl.bindBuffer(gl[target], previousBuffer);
|
|
469
|
+
});
|
|
470
|
+
}
|
|
373
471
|
return {
|
|
472
|
+
applyToVertexArray,
|
|
374
473
|
bind() {
|
|
375
|
-
const
|
|
376
|
-
|
|
474
|
+
const restoreVertexArray = bindDefaultVertexArray(gl);
|
|
475
|
+
const restore = applyToVertexArray();
|
|
377
476
|
return once(() => {
|
|
378
|
-
|
|
477
|
+
restore();
|
|
478
|
+
restoreVertexArray();
|
|
379
479
|
});
|
|
380
480
|
},
|
|
381
481
|
dispose() {
|
|
@@ -397,9 +497,10 @@ export {
|
|
|
397
497
|
createUpsertMap,
|
|
398
498
|
toID,
|
|
399
499
|
view,
|
|
500
|
+
vaoView,
|
|
400
501
|
uniformView,
|
|
401
502
|
attributeView,
|
|
402
503
|
interleavedAttributeView,
|
|
403
504
|
bufferView
|
|
404
505
|
};
|
|
405
|
-
//# sourceMappingURL=chunk-
|
|
506
|
+
//# sourceMappingURL=chunk-EYXOSM7B.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/index.ts"],"sourcesContent":["import type {\n AttributeKind,\n FramebufferDefinition,\n GL,\n KIND_TO_SIZE_MAP,\n KIND_TO_UNIFORM_FN_NAME_MAP,\n TextureDefinition,\n UniformKind,\n} from './types'\n\nexport function assertedNotNullish<T>(value: T, message?: string): NonNullable<T> {\n if (value === undefined || value === null) throw new Error(message)\n return value\n}\n\n/**********************************************************************************/\n/* */\n/* Kind To Uniform Name */\n/* */\n/**********************************************************************************/\n\nexport const kindToUniformFnName = <T extends UniformKind>(\n kind: T,\n): KIND_TO_UNIFORM_FN_NAME_MAP[T] => {\n switch (kind[0]) {\n // mat\n case 'm':\n return ('Matrix' + kind.slice(3) + 'fv') as KIND_TO_UNIFORM_FN_NAME_MAP[T]\n // sampler/booleans/integer\n case 's':\n case 'b':\n case 'i':\n return ((kind.match(/\\d/)?.[0] ?? '1') + 'i') as KIND_TO_UNIFORM_FN_NAME_MAP[T]\n // unsigned integers\n case 'u':\n return ((kind[4] || '1') + 'ui') as KIND_TO_UNIFORM_FN_NAME_MAP[T]\n // vec\n case 'v':\n return (kind[3] + 'f') as KIND_TO_UNIFORM_FN_NAME_MAP[T]\n default:\n switch (kind) {\n case 'float':\n return '1f' as KIND_TO_UNIFORM_FN_NAME_MAP[T]\n case 'uint':\n return '1ui' as KIND_TO_UNIFORM_FN_NAME_MAP[T]\n default:\n return '1i' as KIND_TO_UNIFORM_FN_NAME_MAP[T]\n }\n }\n}\n\n/**********************************************************************************/\n/* */\n/* Kind To Size */\n/* */\n/**********************************************************************************/\n\nexport const kindToSize = <T extends UniformKind>(kind: T): KIND_TO_SIZE_MAP[T] => {\n switch (kind[0]) {\n case 'm':\n const [a, b] = kind.match(/\\d+/g)!.map(Number) as [number, number?]\n return (a * (b ?? a)) as KIND_TO_SIZE_MAP[T]\n case 'v':\n case 'i':\n case 'b':\n case 'u':\n const match = kind.match(/\\d/) as [string] | undefined\n return (match ? +match[0] : 1) as KIND_TO_SIZE_MAP[T]\n default:\n return 1 as KIND_TO_SIZE_MAP[T]\n }\n}\n\n/**********************************************************************************/\n/* */\n/* Guards */\n/* */\n/**********************************************************************************/\n\nexport const isMatKind = <\n T extends UniformKind | AttributeKind,\n TPrefix extends string,\n TPostfix extends string,\n>(\n kind: T,\n): kind is T & `${TPrefix}mat${TPostfix}` => kind.includes('mat')\n\nexport const isSamplerKind = <TPrefix extends string, TPostfix extends string>(\n kind: UniformKind,\n): kind is UniformKind & `${TPrefix}sampler${TPostfix}` => kind.includes('sampler')\n\nexport const isVecKind = <TPrefix extends string, TPostfix extends string>(\n kind: UniformKind,\n): kind is UniformKind & `${TPrefix}vec${TPostfix}` => kind.includes('vec')\n\n/**********************************************************************************/\n/* */\n/* Create Texture */\n/* */\n/**********************************************************************************/\n\nexport function createTexture(\n gl: GL,\n {\n target = 'TEXTURE_2D',\n internalFormat = 'RGBA',\n format = 'RGBA',\n type = 'UNSIGNED_BYTE',\n minFilter = 'NEAREST',\n magFilter = 'NEAREST',\n wrapS = 'CLAMP_TO_EDGE',\n wrapT = 'CLAMP_TO_EDGE',\n width,\n height,\n }: TextureDefinition,\n data?: ArrayBufferView | null,\n): WebGLTexture {\n const texture = gl.createTexture()\n\n function getTextureConstant(name: string) {\n if (!(name in gl)) {\n throw new Error(`Attempted to create webgl2-only texture (${name}) in webgl1`)\n }\n return gl[name as keyof typeof gl] as any\n }\n\n gl.bindTexture(gl[target], texture)\n gl.texImage2D(\n gl[target],\n 0,\n getTextureConstant(internalFormat),\n width,\n height,\n 0,\n getTextureConstant(format),\n getTextureConstant(type),\n data ?? null,\n )\n\n console.log(minFilter)\n // Set texture parameters\n gl.texParameteri(gl[target], gl.TEXTURE_MIN_FILTER, gl[minFilter])\n gl.texParameteri(gl[target], gl.TEXTURE_MAG_FILTER, gl[magFilter])\n gl.texParameteri(gl[target], gl.TEXTURE_WRAP_S, gl[wrapS])\n gl.texParameteri(gl[target], gl.TEXTURE_WRAP_T, gl[wrapT])\n\n return texture\n}\n\n/**********************************************************************************/\n/* */\n/* Create Framebuffer */\n/* */\n/**********************************************************************************/\n\nconst FRAMEBUFFER_ATTACHMENT_MAP = {\n color: 'COLOR_ATTACHMENT0',\n depth: 'DEPTH_ATTACHMENT',\n stencil: 'STENCIL_ATTACHMENT',\n depthStencil: 'DEPTH_STENCIL_ATTACHMENT',\n} as const\n\nclass FramebufferError extends Error {\n constructor(gl: GL, status: number) {\n let errorMessage = `Framebuffer '${name}' not complete. Status: `\n switch (status) {\n case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:\n errorMessage += 'FRAMEBUFFER_INCOMPLETE_ATTACHMENT'\n break\n case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:\n errorMessage += 'FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT'\n break\n case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:\n errorMessage += 'FRAMEBUFFER_INCOMPLETE_DIMENSIONS'\n break\n case gl.FRAMEBUFFER_UNSUPPORTED:\n errorMessage += 'FRAMEBUFFER_UNSUPPORTED'\n break\n default:\n errorMessage += `Unknown (${status})`\n }\n super(errorMessage)\n }\n}\n\nexport function createFramebuffer(\n gl: GL,\n { attachment, texture, ...options }: FramebufferDefinition,\n) {\n // Create texture for the framebuffer\n texture ??= createTexture(gl, options)\n\n // Create framebuffer\n const framebuffer = assertedNotNullish(\n gl.createFramebuffer(),\n `Failed to create framebuffer: ${name}`,\n )\n\n gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer)\n\n gl.framebufferTexture2D(\n gl.FRAMEBUFFER,\n // Determine attachment point based on attachment kind\n gl[FRAMEBUFFER_ATTACHMENT_MAP[attachment]],\n gl.TEXTURE_2D,\n texture,\n 0,\n )\n\n // Check framebuffer completeness\n const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER)\n if (status !== gl.FRAMEBUFFER_COMPLETE) {\n throw new FramebufferError(gl, status)\n }\n\n return {\n texture,\n framebuffer,\n }\n}\n\n/**********************************************************************************/\n/* */\n/* Create Upsert */\n/* */\n/**********************************************************************************/\n\ntype UpsertMapKind<T, U> = Map<T, U> | (T extends WeakKey ? WeakMap<T, U> : never)\n\nexport function createUpsertMap<T extends UpsertMapKind<any, any> = Map<any, any>>(\n constructor?: new () => T,\n) {\n const map = new (constructor ?? Map)() as T\n return Object.assign(map, {\n getOrInsert(\n key: T extends UpsertMapKind<infer U, any> ? U : never,\n value: T extends UpsertMapKind<any, infer U> ? () => U : never,\n ) {\n let result = map.get(key)\n if (result) {\n return result\n }\n result = value()\n map.set(key, result)\n return result\n },\n })\n}\n\nexport function forEachObject<T extends Record<string, any>>(\n value: T,\n callback: (value: T[keyof T], key: keyof T, index: number) => void,\n) {\n let index = 0\n for (const key in value) {\n callback(value[key], key, index)\n index++\n }\n for (const key of Object.getOwnPropertySymbols(value)) {\n callback(value[key as keyof T], key as keyof T, index)\n index++\n }\n}\n\nexport function mapObject<T extends Record<string, any>, TReturn>(\n value: T,\n callback: (value: T[keyof T], key: keyof T, index: number) => TReturn,\n): { [TKey in keyof T]: TReturn } {\n const result = {} as { [TKey in keyof T]: TReturn }\n\n forEachObject(value, (value, key, index) => {\n result[key] = callback(value, key, index)\n })\n\n return result\n}\n","import { getInstancedArrays, getVertexArrayObject } from './gl'\nimport type {\n AttributeFormat,\n AttributeKind,\n AttributeMethods,\n AttributeSchema,\n AttributeView,\n BufferSchema,\n BufferView,\n GL,\n UniformView as InferUniformView,\n GLUsage,\n InterleavedAttributeLayout,\n InterleavedAttributeMethods,\n InterleavedAttributeSchema,\n InterleavedAttributeView,\n UniformSchema,\n VertexArrayMethods,\n VertexArrayParticipant,\n View,\n ViewOptions,\n ViewSchema,\n} from './types'\nimport {\n isSamplerKind,\n kindToUniformFnName,\n isMatKind,\n assertedNotNullish,\n kindToSize,\n forEachObject,\n} from './utils'\nimport { createUpsertMap, mapObject } from './utils'\nexport * from './types'\n\n/**********************************************************************************/\n/* */\n/* To ID */\n/* */\n/**********************************************************************************/\n\nlet index = 0\nconst PREFIX = 'VIEW_GL_ALIAS'\n// Firefox has currently a bug where it can not handle symbol as WeakRef / key for WeakMap\n// see https://bugzilla.mozilla.org/show_bug.cgi?id=1710433\nconst HAS_WEAK_SYMBOL = (() => {\n try {\n const symbol = Symbol()\n new WeakMap().set(symbol, '')\n return true\n } catch {\n return false\n }\n})()\n// NOTE: fallback to Map will currently cause a minor memory leak.\nconst SYMBOL_MAP = createUpsertMap(HAS_WEAK_SYMBOL ? WeakMap<symbol, string> : Map<symbol, string>)\n\nexport function toID(key: string | number | symbol) {\n if (typeof key === 'string') {\n return key\n }\n if (typeof key === 'symbol') {\n return SYMBOL_MAP.getOrInsert(key, () => `${PREFIX}_${index++}`)\n }\n return key.toString()\n}\n\n/**********************************************************************************/\n/* */\n/* View */\n/* */\n/**********************************************************************************/\n\nexport function view<TSchema extends ViewSchema>(\n gl: GL,\n program: WebGLProgram,\n schema: TSchema,\n options?: ViewOptions,\n): View<TSchema> {\n return {\n uniforms: !schema.uniforms ? undefined : uniformView(gl, program, schema.uniforms),\n attributes: !schema.attributes\n ? undefined\n : attributeView(gl, program, schema.attributes, options),\n interleavedAttributes: !schema.interleavedAttributes\n ? undefined\n : interleavedAttributeView(gl, program, schema.interleavedAttributes, options),\n buffers: !schema.buffers ? undefined : bufferView(gl, schema.buffers),\n vao(participants: VertexArrayParticipant[]) {\n return vaoView(gl, participants, options)\n },\n } as View<TSchema>\n}\n\n/**********************************************************************************/\n/* */\n/* Vertex Array */\n/* */\n/**********************************************************************************/\n\n/**\n * Bind the default vertex array, returning a disposer that puts the previous\n * one back. The pointer calls name no destination, so anything applied without\n * a vertex array of its own has to say which one it means — and a vertex array\n * keeps what it is given, so writing into a caller's array by accident would\n * outlive the call that did it.\n */\nfunction bindDefaultVertexArray(gl: GL): () => void {\n const feature = getVertexArrayObject(gl)\n if (!feature) {\n return () => {}\n }\n const previous = gl.getParameter(VERTEX_ARRAY_BINDING) as WebGLVertexArrayObject | null\n feature.bindVertexArray(null)\n return () => feature.bindVertexArray(previous)\n}\n\n/**\n * A vertex array over the participants one draw needs.\n *\n * Where the context has vertex arrays, each participant writes itself in once,\n * here, and `bind()` is a single `bindVertexArray`. Where it does not — WebGL1\n * without `OES_vertex_array_object` — there is nowhere to keep the state, so\n * `bind()` re-applies every participant and the disposer puts back what they\n * displaced. Same contract, and the emulation is why the name still fits.\n */\nexport function vaoView(\n gl: GL,\n participants: VertexArrayParticipant[],\n { signal }: ViewOptions = {},\n): VertexArrayMethods {\n const feature = getVertexArrayObject(gl)\n\n const methods: VertexArrayMethods = !feature\n ? {\n bind() {\n const restores = participants.map(participant => participant.applyToVertexArray())\n participants.forEach(participant => participant.applyToContext?.())\n return once(() => restores.forEach(restore => restore()))\n },\n unbind() {},\n dispose() {},\n }\n : (() => {\n const vertexArray = assertedNotNullish(feature.createVertexArray())\n const previous = gl.getParameter(VERTEX_ARRAY_BINDING) as WebGLVertexArrayObject | null\n feature.bindVertexArray(vertexArray)\n // Discarding the restorers is the point: the state lives in this array\n // now, and the array is thrown away whole.\n for (const participant of participants) {\n participant.applyToVertexArray()\n }\n feature.bindVertexArray(previous)\n\n return {\n bind() {\n const previousVertexArray = gl.getParameter(\n VERTEX_ARRAY_BINDING,\n ) as WebGLVertexArrayObject | null\n feature.bindVertexArray(vertexArray)\n // Context state the array cannot hold — see applyToContext.\n participants.forEach(participant => participant.applyToContext?.())\n return once(() => feature.bindVertexArray(previousVertexArray))\n },\n unbind() {\n feature.bindVertexArray(null)\n },\n dispose() {\n feature.deleteVertexArray(vertexArray)\n },\n }\n })()\n\n signal?.addEventListener('abort', () => methods.dispose())\n\n return methods\n}\n\n/**********************************************************************************/\n/* */\n/* Uniform View */\n/* */\n/**********************************************************************************/\n\nexport function uniformView<T extends UniformSchema>(\n gl: GL,\n program: WebGLProgram,\n schema: T,\n): InferUniformView<T> {\n // @ts-expect-error - conditional return type based on size is hard to infer\n return mapObject(schema, ({ kind, size }, key) => {\n const name = toID(key)\n\n if (isSamplerKind(kind)) {\n const location = gl.getUniformLocation(program, name)\n return {\n set(arg: number) {\n gl.uniform1i(location, arg)\n },\n }\n }\n\n // Array uniform - support both bulk set and indexed access\n if (size) {\n const bulkFnName = `uniform${kindToUniformFnName(kind)}v`\n // @ts-ignore FIX WEBGL/WEBGL2 TYPES\n const bulkFn = gl[bulkFnName].bind(gl)\n const bulkLocation = gl.getUniformLocation(program, name)\n\n const elementFnName = `uniform${kindToUniformFnName(kind)}`\n // @ts-ignore FIX WEBGL/WEBGL2 TYPES\n const elementFn = gl[elementFnName].bind(gl)\n\n // Build array of element setters\n const elements: Array<{ set(...args: any[]): void }> = []\n for (let i = 0; i < size; i++) {\n const location = gl.getUniformLocation(program, `${name}[${i}]`)\n elements[i] = {\n set(...args: any[]) {\n elementFn(location, ...args)\n },\n }\n }\n\n // Return array-like object with bulk set\n return Object.assign(elements, {\n set(arg: Float32Array) {\n bulkFn(bulkLocation, arg)\n },\n })\n }\n\n // Non-array uniform\n const location = gl.getUniformLocation(program, name)\n const fnName = `uniform${kindToUniformFnName(kind)}`\n\n // @ts-ignore FIX WEBGL/WEBGL2 TYPES\n const fn = gl[fnName].bind(gl)\n\n if (isMatKind(kind)) {\n return {\n set(...args: any[]) {\n fn(location, false, args[0])\n },\n }\n }\n\n return {\n set(...args: any[]) {\n fn(location, ...args)\n },\n }\n })\n}\n\n/**********************************************************************************/\n/* */\n/* Attribute View */\n/* */\n/**********************************************************************************/\n\ntype GLType =\n | 'FLOAT'\n | 'INT'\n | 'UNSIGNED_INT'\n | 'SHORT'\n | 'UNSIGNED_SHORT'\n | 'BYTE'\n | 'UNSIGNED_BYTE'\n\nconst FORMAT_TO_GL_TYPE: Record<AttributeFormat, GLType> = {\n float32: 'FLOAT',\n int32: 'INT',\n uint32: 'UNSIGNED_INT',\n int16: 'SHORT',\n uint16: 'UNSIGNED_SHORT',\n int8: 'BYTE',\n uint8: 'UNSIGNED_BYTE',\n}\n\nconst FORMAT_BYTE_SIZE: Record<AttributeFormat, number> = {\n float32: 4,\n int32: 4,\n uint32: 4,\n int16: 2,\n uint16: 2,\n int8: 1,\n uint8: 1,\n}\n\nfunction defaultFormat(kind: AttributeKind): AttributeFormat {\n if (kind.startsWith('u')) return 'uint32'\n if (kind.startsWith('i')) return 'int32'\n return 'float32'\n}\n\n// Shared attribute helper functions\n// between attributeView and interleavedAttributeView\nfunction handleAttribute(\n gl: GL,\n location: number,\n size: number,\n stride: number,\n offset: number,\n glType: GLType,\n isIntegerKind: boolean,\n normalized: boolean,\n instanced?: boolean,\n) {\n gl.enableVertexAttribArray(location)\n if (isIntegerKind) {\n ;(gl as WebGL2RenderingContext).vertexAttribIPointer(location, size, gl[glType], stride, offset)\n } else {\n gl.vertexAttribPointer(location, size, gl[glType], normalized, stride, offset)\n }\n\n // Always stated, never inherited: the divisor belongs to the location rather\n // than to the program, so a location left at 1 by an earlier instanced\n // attribute would feed one value to every vertex here.\n // Get instanced-arrays-feature: extension if webgl, gl if webgl2\n const instancedArrays = getInstancedArrays(gl)\n if (instanced) {\n assertedNotNullish(instancedArrays).vertexAttribDivisor(location, 1)\n } else if (instancedArrays) {\n instancedArrays.vertexAttribDivisor(location, 0)\n }\n}\n\n// Same enum in webgl2 and in the webgl1 extensions, which expose no constants\nconst VERTEX_ATTRIB_ARRAY_DIVISOR = 0x88fe\nconst VERTEX_ARRAY_BINDING = 0x85b5\n\n// Reads the divisor currently attached to a location, 0 where instancing is\n// unavailable and nothing can have set one\nfunction readDivisor(gl: GL, location: number): number {\n return getInstancedArrays(gl)\n ? (gl.getVertexAttrib(location, VERTEX_ATTRIB_ARRAY_DIVISOR) as number)\n : 0\n}\n\n// Wraps a restore so it runs once: a disposer is per bind() and undoing twice\n// would put back state a later bind() is relying on\nfunction once(restore: () => void): () => void {\n let done = false\n return () => {\n if (done) return\n done = true\n restore()\n }\n}\n\nexport function attributeView<T extends AttributeSchema>(\n gl: GL,\n program: WebGLProgram,\n schema: T,\n { signal }: ViewOptions = {},\n): AttributeView<T> {\n const attributes = mapObject(\n schema,\n (\n {\n kind,\n format,\n normalized = false,\n instanced,\n buffer = assertedNotNullish(gl.createBuffer()),\n },\n key,\n ): AttributeMethods => {\n const name = toID(key)\n\n const location = gl.getAttribLocation(program, name)\n if (location < 0) {\n throw new Error(`Attribute '${name}' not found`)\n }\n\n const size = kindToSize(kind)\n const resolvedFormat = format ?? defaultFormat(kind)\n const glType = FORMAT_TO_GL_TYPE[resolvedFormat]\n const isIntKind = kind.startsWith('i') || kind.startsWith('u')\n\n function applyToVertexArray() {\n // Snapshot before the change, restore in the disposer\n const previousDivisor = readDivisor(gl, location)\n // vertexAttribPointer captures whatever is bound to ARRAY_BUFFER when\n // it runs, so this binding is the setup for the pointer, not a lasting\n // part of the vertex array's state.\n gl.bindBuffer(gl.ARRAY_BUFFER, buffer)\n handleAttribute(gl, location, size, 0, 0, glType, isIntKind, normalized, instanced)\n return once(() => {\n getInstancedArrays(gl)?.vertexAttribDivisor(location, previousDivisor)\n })\n }\n\n return {\n buffer,\n applyToVertexArray,\n bind() {\n const restoreVertexArray = bindDefaultVertexArray(gl)\n const restore = applyToVertexArray()\n return once(() => {\n restore()\n restoreVertexArray()\n })\n },\n dispose() {\n gl.deleteBuffer(buffer)\n },\n set(data, usage = 'STATIC_DRAW') {\n gl.bindBuffer(gl.ARRAY_BUFFER, buffer)\n gl.bufferData(gl.ARRAY_BUFFER, data, gl[usage])\n return this\n },\n }\n },\n )\n\n signal?.addEventListener('abort', function dispose() {\n forEachObject(attributes, value => value.dispose())\n })\n\n return attributes\n}\n\n/**********************************************************************************/\n/* */\n/* Interleaved Attribute View */\n/* */\n/**********************************************************************************/\n\n/**\n * The other place an attribute's value can come from: not a buffer, but the\n * context's current generic vertex attribute values, which an attribute reads\n * for every vertex when its array is disabled.\n *\n * A constant is a uniform in all but name — one value for the whole draw, set\n * by a function chosen from the kind — so it gets the setters a uniform gets,\n * off the same layout the buffer source uses.\n *\n * `vertexAttrib*` tops out at four floats and has no matrix form, so a layout\n * key that is fine in a buffer can be impossible as a constant. That is a hard\n * limit of the API rather than a choice, and it is worth saying so out loud at\n * the point someone reaches for it.\n */\nfunction constantSource(gl: GL, layout: InterleavedAttributeLayout[], locations: number[]) {\n const setters = layout.map((entry, index) => {\n const size = kindToSize(entry.kind)\n const name = toID(entry.key)\n if (isMatKind(entry.kind) || size > 4) {\n throw new Error(\n `'${name}' is a ${entry.kind}, which cannot be a constant attribute: vertexAttrib* takes at most 4 floats and has no matrix form. Use the buffer source for it.`,\n )\n }\n // The values are context state, not vertex-array state, so they are held\n // here and written again on every bind — see applyToContext.\n let values: number[] = []\n const fn = gl[`vertexAttrib${size as 1 | 2 | 3 | 4}f`].bind(gl)\n return {\n name,\n location: locations[index]!,\n write: () => {\n if (values.length) {\n ;(fn as (location: number, ...args: number[]) => void)(locations[index]!, ...values)\n }\n },\n methods: {\n set(...args: number[]) {\n values = args\n },\n },\n }\n })\n\n return Object.assign(Object.fromEntries(setters.map(setter => [setter.name, setter.methods])), {\n applyToVertexArray() {\n const restores = setters.map(({ location }) => {\n const wasEnabled = gl.getVertexAttrib(location, gl.VERTEX_ATTRIB_ARRAY_ENABLED) as boolean\n gl.disableVertexAttribArray(location)\n return () => (wasEnabled ? gl.enableVertexAttribArray(location) : undefined)\n })\n return once(() => restores.forEach(restore => restore()))\n },\n applyToContext() {\n setters.forEach(setter => setter.write())\n },\n bind() {\n const restoreVertexArray = bindDefaultVertexArray(gl)\n const restore = this.applyToVertexArray()\n this.applyToContext()\n return once(() => {\n restore()\n restoreVertexArray()\n })\n },\n })\n}\n\nexport function interleavedAttributeView<T extends InterleavedAttributeSchema>(\n gl: GL,\n program: WebGLProgram,\n schema: T,\n { signal }: ViewOptions = {},\n): InterleavedAttributeView<T> {\n // Initialize interleaved attributes\n const interleavedAttributes = mapObject(schema, ({ layout }) => {\n // Increment number to keep track of offset\n let index = 0\n\n // Calculate layout information\n const locations: number[] = []\n const handles = layout.map(layout => {\n const name = toID(layout.key)\n\n const location = gl.getAttribLocation(program, name)\n\n if (location < 0) {\n throw new Error(`Attribute '${name}' not found`)\n }\n\n locations.push(location)\n\n const size = kindToSize(layout.kind)\n const offset = index\n const resolvedFormat = layout.format ?? defaultFormat(layout.kind)\n const glType = FORMAT_TO_GL_TYPE[resolvedFormat]\n const isIntKind = layout.kind.startsWith('i') || layout.kind.startsWith('u')\n const normalized = layout.normalized ?? false\n index += size * FORMAT_BYTE_SIZE[resolvedFormat]\n\n return (divisor: 0 | 1) =>\n handleAttribute(\n gl,\n location,\n size,\n stride,\n offset,\n glType,\n isIntKind,\n normalized,\n divisor === 1,\n )\n })\n\n // Set stride to final index\n const stride = index\n\n // Create a buffer\n const buffer = assertedNotNullish(gl.createBuffer())\n\n // This layout used to create a vertex array of its own, here, which is why\n // the other participants in a draw had to be bound after it to be included\n // — the array they landed in was whichever one happened to be current.\n // Arrays are `vao()`'s job now; a layout is a layout and a buffer.\n function applyToVertexArray(divisor: 0 | 1) {\n const previousDivisors = locations.map(\n location => [location, readDivisor(gl, location)] as const,\n )\n gl.bindBuffer(gl.ARRAY_BUFFER, buffer)\n for (const handle of handles) {\n handle(divisor)\n }\n return once(() => {\n const instancedArrays = getInstancedArrays(gl)\n previousDivisors.forEach(([location, previous]) => {\n instancedArrays?.vertexAttribDivisor(location, previous)\n })\n })\n }\n\n let constant: ReturnType<typeof constantSource> | undefined\n\n /** One layout, one buffer, but a divisor per draw rather than per schema. */\n function bufferSource(divisor: 0 | 1) {\n const apply = () => applyToVertexArray(divisor)\n return {\n applyToVertexArray: apply,\n bind() {\n const restoreVertexArray = bindDefaultVertexArray(gl)\n const restore = apply()\n return once(() => {\n restore()\n restoreVertexArray()\n })\n },\n }\n }\n\n return {\n buffer: Object.assign(bufferSource(0), {\n /** The same buffer, stepped once per instance instead of once per vertex. */\n perInstance: bufferSource(1),\n set(value: Float32Array, usage: GLUsage = 'STATIC_DRAW') {\n // Uploading is storage, not binding: ARRAY_BUFFER is not vertex-array\n // state, so this touches no array, whichever one is bound.\n gl.bindBuffer(gl.ARRAY_BUFFER, buffer)\n gl.bufferData(gl.ARRAY_BUFFER, value, gl[usage])\n },\n }),\n // Lazy: a layout key can be perfectly good in a buffer and impossible as\n // a constant, and finding that out should wait until someone asks for one.\n get constant() {\n return (constant ??= constantSource(gl, layout, locations))\n },\n dispose() {\n gl.deleteBuffer(buffer)\n },\n } satisfies InterleavedAttributeMethods\n })\n\n signal?.addEventListener('abort', function dispose() {\n forEachObject(interleavedAttributes, value => value.dispose())\n })\n\n return interleavedAttributes\n}\n\n/**********************************************************************************/\n/* */\n/* Buffer View */\n/* */\n/**********************************************************************************/\n\nexport function bufferView<T extends BufferSchema>(\n gl: GL,\n schema: T,\n { signal }: ViewOptions = {},\n): BufferView<T> {\n // Initialize buffers\n const buffers = mapObject(schema, ({ target = 'ARRAY_BUFFER', usage = 'STATIC_DRAW' }) => {\n const buffer = assertedNotNullish(gl.createBuffer())\n\n function applyToVertexArray() {\n // Snapshot before the change, restore in the disposer. Restoring the\n // previous buffer rather than null matters for ELEMENT_ARRAY_BUFFER,\n // whose binding is recorded in the bound vertex array: clearing it\n // would strip the index buffer from an array the caller may not own.\n const previousBuffer = gl.getParameter(gl[`${target}_BINDING`]) as WebGLBuffer | null\n gl.bindBuffer(gl[target], buffer)\n return once(() => {\n gl.bindBuffer(gl[target], previousBuffer)\n })\n }\n\n return {\n applyToVertexArray,\n bind() {\n // ELEMENT_ARRAY_BUFFER's binding belongs to the bound vertex array, so\n // like the attributes this has to say which array it means. ARRAY_BUFFER\n // is context state and unaffected either way.\n const restoreVertexArray = bindDefaultVertexArray(gl)\n const restore = applyToVertexArray()\n return once(() => {\n restore()\n restoreVertexArray()\n })\n },\n dispose() {\n gl.deleteBuffer(buffer)\n },\n set(data: Float32Array) {\n gl.bindBuffer(gl[target], buffer)\n gl.bufferData(gl[target], data, gl[usage])\n },\n }\n })\n\n signal?.addEventListener('abort', function dispose() {\n forEachObject(buffers, value => value.dispose())\n })\n\n return buffers\n}\n"],"mappings":";;;;;;AAUO,SAAS,mBAAs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1,4 +1,4 @@
|
|
|
1
|
-
import { G as GL, R as RemoveSuffix } from './types-
|
|
1
|
+
import { G as GL, R as RemoveSuffix } from './types-CyGyGi18.mjs';
|
|
2
2
|
|
|
3
3
|
/**********************************************************************************/
|
|
4
4
|
/**********************************************************************************/
|
package/dist/index.d.mts
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
|
-
import { V as ViewSchema, G as GL, a as ViewOptions, b as View, U as UniformSchema,
|
|
2
|
-
export {
|
|
1
|
+
import { V as ViewSchema, G as GL, a as ViewOptions, b as View, c as VertexArrayParticipant, d as VertexArrayMethods, U as UniformSchema, e as UniformView, A as AttributeSchema, f as AttributeView, I as InterleavedAttributeSchema, g as InterleavedAttributeView, B as BufferSchema, h as BufferView } from './types-CyGyGi18.mjs';
|
|
2
|
+
export { D as AttributeDefinition, C as AttributeFormat, z as AttributeKind, E as AttributeMethods, y as AttributeShortHand, ac as AttributeToken, ad as AttributeTokenFn, O as BufferDefinition, P as BufferMethods, J as BufferSource, ak as CompileResult, L as ConstantAttributeMethods, M as ConstantSource, ai as FlattenSlots, a3 as Format, W as Framebuffer, Q as FramebufferDefinition, a9 as GLSL, a7 as GLSLResult, a8 as GLSLSlot, ah as GLSLSlotsToSchema, af as GLSLToSchema, ag as GLSLToView, i as GLTarget, n as GLTextureFilter, l as GLTextureFormat, k as GLTextureTarget, m as GLTextureType, o as GLTextureWrap, j as GLUsage, ae as InterleaveToken, H as InterleavedAttributeDefinition, F as InterleavedAttributeLayout, N as InterleavedAttributeMethods, a2 as InternalFormat, p as KIND_TO_SIZE_MAP, K as KIND_TO_UNIFORM_FN_NAME_MAP, aj as MergeGLSLSchema, a4 as PixelType, S as Source, a5 as TexImage2DOptions, T as TextureDefinition, Z as TextureMethods, $ as TextureParameterName, a0 as TextureParameterValue, a1 as TextureParameters, Y as TextureSchema, X as TextureTarget, _ as TextureView, v as UniformArrayMethods, t as UniformDefinition, u as UniformElementMethods, q as UniformFnName, r as UniformKind, s as UniformKindMap, w as UniformMethods, aa as UniformToken, ab as UniformTokenFn, x as UniformValue, a6 as ViewSchemaPartial } from './types-CyGyGi18.mjs';
|
|
3
3
|
|
|
4
4
|
declare function toID(key: string | number | symbol): any;
|
|
5
5
|
/**********************************************************************************/
|
|
6
6
|
/**********************************************************************************/
|
|
7
7
|
declare function view<TSchema extends ViewSchema>(gl: GL, program: WebGLProgram, schema: TSchema, options?: ViewOptions): View<TSchema>;
|
|
8
|
+
/**
|
|
9
|
+
* A vertex array over the participants one draw needs.
|
|
10
|
+
*
|
|
11
|
+
* Where the context has vertex arrays, each participant writes itself in once,
|
|
12
|
+
* here, and `bind()` is a single `bindVertexArray`. Where it does not — WebGL1
|
|
13
|
+
* without `OES_vertex_array_object` — there is nowhere to keep the state, so
|
|
14
|
+
* `bind()` re-applies every participant and the disposer puts back what they
|
|
15
|
+
* displaced. Same contract, and the emulation is why the name still fits.
|
|
16
|
+
*/
|
|
17
|
+
declare function vaoView(gl: GL, participants: VertexArrayParticipant[], { signal }?: ViewOptions): VertexArrayMethods;
|
|
8
18
|
/**********************************************************************************/
|
|
9
19
|
/**********************************************************************************/
|
|
10
20
|
declare function uniformView<T extends UniformSchema>(gl: GL, program: WebGLProgram, schema: T): UniformView<T>;
|
|
11
21
|
declare function attributeView<T extends AttributeSchema>(gl: GL, program: WebGLProgram, schema: T, { signal }?: ViewOptions): AttributeView<T>;
|
|
12
|
-
/**********************************************************************************/
|
|
13
|
-
/**********************************************************************************/
|
|
14
22
|
declare function interleavedAttributeView<T extends InterleavedAttributeSchema>(gl: GL, program: WebGLProgram, schema: T, { signal }?: ViewOptions): InterleavedAttributeView<T>;
|
|
15
23
|
/**********************************************************************************/
|
|
16
24
|
/**********************************************************************************/
|
|
17
25
|
declare function bufferView<T extends BufferSchema>(gl: GL, schema: T, { signal }?: ViewOptions): BufferView<T>;
|
|
18
26
|
|
|
19
|
-
export { AttributeSchema, AttributeView, BufferSchema, BufferView, GL, InterleavedAttributeSchema, InterleavedAttributeView, UniformSchema, UniformView, View, ViewOptions, ViewSchema, attributeView, bufferView, interleavedAttributeView, toID, uniformView, view };
|
|
27
|
+
export { AttributeSchema, AttributeView, BufferSchema, BufferView, GL, InterleavedAttributeSchema, InterleavedAttributeView, UniformSchema, UniformView, VertexArrayMethods, VertexArrayParticipant, View, ViewOptions, ViewSchema, attributeView, bufferView, interleavedAttributeView, toID, uniformView, vaoView, view };
|
package/dist/index.mjs
CHANGED
|
@@ -4,8 +4,9 @@ import {
|
|
|
4
4
|
interleavedAttributeView,
|
|
5
5
|
toID,
|
|
6
6
|
uniformView,
|
|
7
|
+
vaoView,
|
|
7
8
|
view
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-EYXOSM7B.mjs";
|
|
9
10
|
import "./chunk-CJTT7WPV.mjs";
|
|
10
11
|
export {
|
|
11
12
|
attributeView,
|
|
@@ -13,6 +14,7 @@ export {
|
|
|
13
14
|
interleavedAttributeView,
|
|
14
15
|
toID,
|
|
15
16
|
uniformView,
|
|
17
|
+
vaoView,
|
|
16
18
|
view
|
|
17
19
|
};
|
|
18
20
|
//# sourceMappingURL=index.mjs.map
|
package/dist/tag.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a8 as GLSLSlot, a9 as GLSL, ab as UniformTokenFn, ad as AttributeTokenFn, ac as AttributeToken, z as AttributeKind, D as AttributeDefinition, ae as InterleaveToken, a6 as ViewSchemaPartial, ak as CompileResult, al as Prettify, af as GLSLToSchema, G as GL } from './types-CyGyGi18.mjs';
|
|
2
2
|
|
|
3
3
|
declare function glsl<TSlot extends GLSLSlot, const TSlots extends TSlot[]>(template: TemplateStringsArray, ...slots: [...TSlots]): GLSL<TSlots>;
|
|
4
4
|
declare const uniform: {
|
package/dist/tag.mjs
CHANGED
|
@@ -210,9 +210,45 @@ type FormatToArray = {
|
|
|
210
210
|
int8: Int8Array;
|
|
211
211
|
uint8: Uint8Array;
|
|
212
212
|
};
|
|
213
|
-
|
|
213
|
+
/**
|
|
214
|
+
* What a participant contributes to a vertex array.
|
|
215
|
+
*
|
|
216
|
+
* `enableVertexAttribArray`, `vertexAttribPointer`, `vertexAttribDivisor` and
|
|
217
|
+
* the `ELEMENT_ARRAY_BUFFER` binding all write into whichever vertex array is
|
|
218
|
+
* bound when they run — they name no destination of their own. That is what
|
|
219
|
+
* makes them a participant in something rather than a property of themselves,
|
|
220
|
+
* and why `vao()` exists: it binds the array first, then asks each participant
|
|
221
|
+
* to write itself in.
|
|
222
|
+
*
|
|
223
|
+
* The returned function undoes the write. It is only used where there is no
|
|
224
|
+
* vertex array to hold the state — a WebGL1 context without
|
|
225
|
+
* `OES_vertex_array_object` — since a real vertex array is thrown away whole.
|
|
226
|
+
*/
|
|
227
|
+
interface VertexArrayParticipant {
|
|
228
|
+
applyToVertexArray(): () => void;
|
|
229
|
+
/**
|
|
230
|
+
* State the CONTEXT holds rather than the vertex array, re-applied on every
|
|
231
|
+
* bind because no array can keep it.
|
|
232
|
+
*
|
|
233
|
+
* There is exactly one such thing: the current generic vertex attribute
|
|
234
|
+
* values, which an attribute reads when its array is disabled. The enable
|
|
235
|
+
* flag saying to read them is vertex-array state; the values themselves are
|
|
236
|
+
* not. So a constant source splits across the two hooks — and the tempting
|
|
237
|
+
* optimisation of skipping this when nothing changed would let one draw's
|
|
238
|
+
* constants leak into the next.
|
|
239
|
+
*/
|
|
240
|
+
applyToContext?(): void;
|
|
241
|
+
}
|
|
242
|
+
interface AttributeMethods<T extends AttributeDefinition = AttributeDefinition> extends VertexArrayParticipant {
|
|
214
243
|
buffer: WebGLBuffer;
|
|
215
|
-
/**
|
|
244
|
+
/**
|
|
245
|
+
* Apply this attribute to the DEFAULT vertex array, returning a disposer.
|
|
246
|
+
*
|
|
247
|
+
* Explicitly the default one: these calls have no destination of their own,
|
|
248
|
+
* so without binding first this would edit whichever array happened to be
|
|
249
|
+
* bound — and a vertex array keeps what it is given, so the damage would
|
|
250
|
+
* outlive the call. Use `vao()` to build an array of your own.
|
|
251
|
+
*/
|
|
216
252
|
bind(): () => void;
|
|
217
253
|
set(data: FormatToArray[ResolvedFormat<T>], usage?: GLUsage): {
|
|
218
254
|
bind(): () => void;
|
|
@@ -235,11 +271,48 @@ interface InterleavedAttributeDefinition {
|
|
|
235
271
|
instanced?: boolean;
|
|
236
272
|
}
|
|
237
273
|
type InterleavedAttributeSchema = Record<string | symbol, InterleavedAttributeDefinition>;
|
|
274
|
+
/**
|
|
275
|
+
* A source is where one draw's values for a layout come from. Both kinds are
|
|
276
|
+
* participants, so either can go into a `vao()`.
|
|
277
|
+
*/
|
|
278
|
+
interface Source extends VertexArrayParticipant {
|
|
279
|
+
/**
|
|
280
|
+
* Apply this source to the DEFAULT vertex array, returning a disposer. See
|
|
281
|
+
* `AttributeMethods.bind` — and prefer `vao()`, which is the only way to get
|
|
282
|
+
* a source and its fellow participants into an array of their own.
|
|
283
|
+
*/
|
|
284
|
+
bind(): () => void;
|
|
285
|
+
}
|
|
286
|
+
interface BufferSource extends Source {
|
|
287
|
+
/**
|
|
288
|
+
* The same buffer, stepped once per instance rather than once per vertex.
|
|
289
|
+
*
|
|
290
|
+
* A divisor is a property of the draw, not of the data — the same markers
|
|
291
|
+
* are an instanced fleet in one draw and a single mesh in the next — so it
|
|
292
|
+
* is chosen here rather than declared in the schema.
|
|
293
|
+
*/
|
|
294
|
+
perInstance: Source;
|
|
295
|
+
set(data: Float32Array, usage?: GLUsage): void;
|
|
296
|
+
}
|
|
297
|
+
interface ConstantAttributeMethods {
|
|
298
|
+
set(...values: number[]): void;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Per-key setters over the same layout the buffer source uses — a constant
|
|
302
|
+
* attribute is a uniform in all but name, so it is written like one.
|
|
303
|
+
*/
|
|
304
|
+
type ConstantSource<T extends InterleavedAttributeLayout[]> = Source & {
|
|
305
|
+
[K in T[number] as K['key'] extends string ? K['key'] : never]: ConstantAttributeMethods;
|
|
306
|
+
};
|
|
238
307
|
interface InterleavedAttributeMethods<T extends InterleavedAttributeLayout[] = InterleavedAttributeLayout[]> {
|
|
308
|
+
buffer: BufferSource;
|
|
309
|
+
constant: ConstantSource<T>;
|
|
310
|
+
dispose(): void;
|
|
311
|
+
}
|
|
312
|
+
interface VertexArrayMethods {
|
|
239
313
|
/** Binds the vertex array, returning a disposer that restores the previous one */
|
|
240
314
|
bind(): () => void;
|
|
241
315
|
unbind(): void;
|
|
242
|
-
set(data: Float32Array, usage?: GLUsage): void;
|
|
243
316
|
dispose(): void;
|
|
244
317
|
}
|
|
245
318
|
type InterleavedAttributeView<T extends InterleavedAttributeSchema> = {
|
|
@@ -252,7 +325,7 @@ interface BufferDefinition {
|
|
|
252
325
|
usage?: GLUsage;
|
|
253
326
|
}
|
|
254
327
|
type BufferSchema = Record<string | symbol, BufferDefinition>;
|
|
255
|
-
interface BufferMethods {
|
|
328
|
+
interface BufferMethods extends VertexArrayParticipant {
|
|
256
329
|
set(data: Float32Array | Uint16Array | Uint32Array): void;
|
|
257
330
|
/** Binds the buffer, returning a disposer that restores the previous binding */
|
|
258
331
|
bind(): () => void;
|
|
@@ -338,6 +411,16 @@ type View<T extends ViewSchema = ViewSchema> = {
|
|
|
338
411
|
interleavedAttributes: T['interleavedAttributes'] extends InterleavedAttributeSchema ? Prettify<InterleavedAttributeView<T['interleavedAttributes']>> : {};
|
|
339
412
|
buffers: T['buffers'] extends BufferSchema ? Prettify<BufferView<T['buffers']>> : {};
|
|
340
413
|
uniforms: T['uniforms'] extends UniformSchema ? Prettify<UniformView<T['uniforms']>> : {};
|
|
414
|
+
/**
|
|
415
|
+
* Build a vertex array from the participants one draw needs — its attributes,
|
|
416
|
+
* its interleaved layouts, its element buffer.
|
|
417
|
+
*
|
|
418
|
+
* This is the one member the schema cannot declare, because its input is the
|
|
419
|
+
* schema's own output. It is also the only place a vertex array is created:
|
|
420
|
+
* the participants no longer make one each, so which array they end up in is
|
|
421
|
+
* something you say rather than something you inherit from call order.
|
|
422
|
+
*/
|
|
423
|
+
vao(participants: VertexArrayParticipant[]): VertexArrayMethods;
|
|
341
424
|
};
|
|
342
425
|
/**********************************************************************************/
|
|
343
426
|
/**********************************************************************************/
|
|
@@ -439,4 +522,4 @@ type CompileResult<TVertex extends GLSL, TFragment extends GLSL, TOverrideSchema
|
|
|
439
522
|
fragment: string;
|
|
440
523
|
} : never;
|
|
441
524
|
|
|
442
|
-
export type {
|
|
525
|
+
export type { TextureParameterName as $, AttributeSchema as A, BufferSchema as B, AttributeFormat as C, AttributeDefinition as D, AttributeMethods as E, InterleavedAttributeLayout as F, GL as G, InterleavedAttributeDefinition as H, InterleavedAttributeSchema as I, BufferSource as J, KIND_TO_UNIFORM_FN_NAME_MAP as K, ConstantAttributeMethods as L, ConstantSource as M, InterleavedAttributeMethods as N, BufferDefinition as O, BufferMethods as P, FramebufferDefinition as Q, RemoveSuffix as R, Source as S, TextureDefinition as T, UniformSchema as U, ViewSchema as V, Framebuffer as W, TextureTarget as X, TextureSchema as Y, TextureMethods as Z, TextureView as _, ViewOptions as a, TextureParameterValue as a0, TextureParameters as a1, InternalFormat as a2, Format as a3, PixelType as a4, TexImage2DOptions as a5, ViewSchemaPartial as a6, GLSLResult as a7, GLSLSlot as a8, GLSL as a9, UniformToken as aa, UniformTokenFn as ab, AttributeToken as ac, AttributeTokenFn as ad, InterleaveToken as ae, GLSLToSchema as af, GLSLToView as ag, GLSLSlotsToSchema as ah, FlattenSlots as ai, MergeGLSLSchema as aj, CompileResult as ak, Prettify as al, View as b, VertexArrayParticipant as c, VertexArrayMethods as d, UniformView as e, AttributeView as f, InterleavedAttributeView as g, BufferView as h, GLTarget as i, GLUsage as j, GLTextureTarget as k, GLTextureFormat as l, GLTextureType as m, GLTextureFilter as n, GLTextureWrap as o, KIND_TO_SIZE_MAP as p, UniformFnName as q, UniformKind as r, UniformKindMap as s, UniformDefinition as t, UniformElementMethods as u, UniformArrayMethods as v, UniformMethods as w, UniformValue as x, AttributeShortHand as y, AttributeKind as z };
|