@luma.gl/webgl 9.1.9 → 9.2.0-alpha.2
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/adapter/converters/device-parameters.js +14 -9
- package/dist/adapter/converters/device-parameters.js.map +1 -1
- package/dist/adapter/converters/sampler-parameters.js +13 -2
- package/dist/adapter/converters/sampler-parameters.js.map +1 -1
- package/dist/adapter/converters/shader-formats.d.ts +67 -8
- package/dist/adapter/converters/shader-formats.d.ts.map +1 -1
- package/dist/adapter/converters/shader-formats.js +82 -52
- package/dist/adapter/converters/shader-formats.js.map +1 -1
- package/dist/adapter/converters/webgl-shadertypes.d.ts +20 -0
- package/dist/adapter/converters/webgl-shadertypes.d.ts.map +1 -0
- package/dist/adapter/converters/webgl-shadertypes.js +122 -0
- package/dist/adapter/converters/webgl-shadertypes.js.map +1 -0
- package/dist/adapter/converters/webgl-texture-table.d.ts.map +1 -1
- package/dist/adapter/converters/webgl-texture-table.js +17 -13
- package/dist/adapter/converters/webgl-texture-table.js.map +1 -1
- package/dist/adapter/converters/{vertex-formats.d.ts → webgl-vertex-formats.d.ts} +4 -4
- package/dist/adapter/converters/webgl-vertex-formats.d.ts.map +1 -0
- package/dist/adapter/converters/{vertex-formats.js → webgl-vertex-formats.js} +2 -3
- package/dist/adapter/converters/webgl-vertex-formats.js.map +1 -0
- package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-features.js.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-limits.d.ts +1 -1
- package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-limits.js +1 -1
- package/dist/adapter/device-helpers/webgl-device-limits.js.map +1 -1
- package/dist/adapter/helpers/format-utils.d.ts +3 -2
- package/dist/adapter/helpers/format-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/format-utils.js.map +1 -1
- package/dist/adapter/helpers/{get-shader-layout.d.ts → get-shader-layout-from-glsl.d.ts} +1 -1
- package/dist/adapter/helpers/get-shader-layout-from-glsl.d.ts.map +1 -0
- package/dist/adapter/helpers/{get-shader-layout.js → get-shader-layout-from-glsl.js} +12 -35
- package/dist/adapter/helpers/get-shader-layout-from-glsl.js.map +1 -0
- package/dist/adapter/helpers/set-uniform.d.ts +2 -2
- package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
- package/dist/adapter/helpers/set-uniform.js.map +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.d.ts +2 -242
- package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.js +10 -99
- package/dist/adapter/helpers/webgl-texture-utils.js.map +1 -1
- package/dist/adapter/resources/webgl-buffer.d.ts +7 -7
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +29 -18
- package/dist/adapter/resources/webgl-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.d.ts +4 -3
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +5 -4
- package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.d.ts +6 -2
- package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js +9 -4
- package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
- package/dist/adapter/resources/webgl-external-texture.js +1 -0
- package/dist/adapter/resources/webgl-external-texture.js.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.d.ts +2 -2
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +2 -2
- package/dist/adapter/resources/webgl-framebuffer.js.map +1 -1
- package/dist/adapter/resources/webgl-query-set.d.ts +2 -2
- package/dist/adapter/resources/webgl-query-set.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-query-set.js +5 -1
- package/dist/adapter/resources/webgl-query-set.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.d.ts +1 -0
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +16 -13
- package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +5 -5
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +28 -24
- package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
- package/dist/adapter/resources/webgl-sampler.js +1 -1
- package/dist/adapter/resources/webgl-sampler.js.map +1 -1
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +9 -2
- package/dist/adapter/resources/webgl-shader.js.map +1 -1
- package/dist/adapter/resources/webgl-texture-view.js +1 -1
- package/dist/adapter/resources/webgl-texture-view.js.map +1 -1
- package/dist/adapter/resources/webgl-texture.d.ts +21 -66
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +152 -320
- package/dist/adapter/resources/webgl-texture.js.map +1 -1
- package/dist/adapter/resources/webgl-transform-feedback.d.ts +1 -1
- package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-transform-feedback.js +1 -1
- package/dist/adapter/resources/webgl-transform-feedback.js.map +1 -1
- package/dist/adapter/resources/webgl-vertex-array.d.ts +1 -1
- package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-vertex-array.js +3 -2
- package/dist/adapter/resources/webgl-vertex-array.js.map +1 -1
- package/dist/adapter/webgl-adapter.d.ts +4 -3
- package/dist/adapter/webgl-adapter.d.ts.map +1 -1
- package/dist/adapter/webgl-adapter.js +43 -30
- package/dist/adapter/webgl-adapter.js.map +1 -1
- package/dist/adapter/webgl-canvas-context.d.ts +3 -24
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +5 -44
- package/dist/adapter/webgl-canvas-context.js.map +1 -1
- package/dist/adapter/webgl-device.d.ts +19 -20
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +44 -31
- package/dist/adapter/webgl-device.js.map +1 -1
- package/dist/context/debug/spector-types.d.ts.map +1 -1
- package/dist/context/debug/spector-types.js +3 -0
- package/dist/context/debug/spector-types.js.map +1 -1
- package/dist/context/debug/spector.js.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +1 -0
- package/dist/context/debug/webgl-developer-tools.js.map +1 -1
- package/dist/context/helpers/webgl-extensions.d.ts.map +1 -1
- package/dist/context/helpers/webgl-extensions.js +3 -0
- package/dist/context/helpers/webgl-extensions.js.map +1 -1
- package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
- package/dist/context/parameters/unified-parameter-api.js +7 -0
- package/dist/context/parameters/unified-parameter-api.js.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.d.ts +1 -1
- package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js +1 -0
- package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
- package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts.map +1 -1
- package/dist/context/polyfills/polyfill-webgl1-extensions.js +1 -0
- package/dist/context/polyfills/polyfill-webgl1-extensions.js.map +1 -1
- package/dist/context/state-tracker/deep-array-equal.d.ts +2 -1
- package/dist/context/state-tracker/deep-array-equal.d.ts.map +1 -1
- package/dist/context/state-tracker/deep-array-equal.js +4 -5
- package/dist/context/state-tracker/deep-array-equal.js.map +1 -1
- package/dist/context/state-tracker/webgl-state-tracker.d.ts.map +1 -1
- package/dist/context/state-tracker/webgl-state-tracker.js +4 -1
- package/dist/context/state-tracker/webgl-state-tracker.js.map +1 -1
- package/dist/context/state-tracker/with-parameters.js.map +1 -1
- package/dist/dist.dev.js +4788 -4801
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +3906 -3960
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/adapter/converters/device-parameters.ts +19 -9
- package/src/adapter/converters/sampler-parameters.ts +13 -2
- package/src/adapter/converters/shader-formats.ts +50 -24
- package/src/adapter/converters/webgl-shadertypes.ts +151 -0
- package/src/adapter/converters/webgl-texture-table.ts +21 -15
- package/src/adapter/converters/{vertex-formats.ts → webgl-vertex-formats.ts} +4 -5
- package/src/adapter/device-helpers/webgl-device-features.ts +1 -1
- package/src/adapter/device-helpers/webgl-device-limits.ts +1 -1
- package/src/adapter/helpers/format-utils.ts +2 -2
- package/src/adapter/helpers/{get-shader-layout.ts → get-shader-layout-from-glsl.ts} +20 -50
- package/src/adapter/helpers/set-uniform.ts +2 -2
- package/src/adapter/helpers/webgl-texture-utils.ts +12 -348
- package/src/adapter/resources/webgl-buffer.ts +43 -23
- package/src/adapter/resources/webgl-command-buffer.ts +9 -8
- package/src/adapter/resources/webgl-command-encoder.ts +18 -9
- package/src/adapter/resources/webgl-framebuffer.ts +4 -4
- package/src/adapter/resources/webgl-query-set.ts +7 -3
- package/src/adapter/resources/webgl-render-pass.ts +20 -17
- package/src/adapter/resources/webgl-render-pipeline.ts +38 -37
- package/src/adapter/resources/webgl-sampler.ts +1 -1
- package/src/adapter/resources/webgl-shader.ts +11 -2
- package/src/adapter/resources/webgl-texture-view.ts +1 -1
- package/src/adapter/resources/webgl-texture.ts +184 -394
- package/src/adapter/resources/webgl-transform-feedback.ts +2 -2
- package/src/adapter/resources/webgl-vertex-array.ts +4 -3
- package/src/adapter/webgl-adapter.ts +46 -33
- package/src/adapter/webgl-canvas-context.ts +7 -47
- package/src/adapter/webgl-device.ts +64 -44
- package/src/context/debug/spector-types.ts +5 -0
- package/src/context/debug/spector.ts +1 -1
- package/src/context/debug/webgl-developer-tools.ts +9 -3
- package/src/context/helpers/webgl-extensions.ts +3 -0
- package/src/context/parameters/unified-parameter-api.ts +9 -2
- package/src/context/parameters/webgl-parameter-tables.ts +2 -0
- package/src/context/polyfills/polyfill-webgl1-extensions.ts +1 -0
- package/src/context/state-tracker/deep-array-equal.ts +11 -6
- package/src/context/state-tracker/webgl-state-tracker.ts +5 -1
- package/src/context/state-tracker/with-parameters.ts +1 -1
- package/src/index.ts +1 -5
- package/dist/adapter/converters/vertex-formats.d.ts.map +0 -1
- package/dist/adapter/converters/vertex-formats.js.map +0 -1
- package/dist/adapter/helpers/decode-webgl-types.d.ts +0 -26
- package/dist/adapter/helpers/decode-webgl-types.d.ts.map +0 -1
- package/dist/adapter/helpers/decode-webgl-types.js +0 -102
- package/dist/adapter/helpers/decode-webgl-types.js.map +0 -1
- package/dist/adapter/helpers/get-shader-layout.d.ts.map +0 -1
- package/dist/adapter/helpers/get-shader-layout.js.map +0 -1
- package/dist/adapter/helpers/typed-array-utils.d.ts +0 -44
- package/dist/adapter/helpers/typed-array-utils.d.ts.map +0 -1
- package/dist/adapter/helpers/typed-array-utils.js +0 -107
- package/dist/adapter/helpers/typed-array-utils.js.map +0 -1
- package/dist/deprecated/accessor.d.ts +0 -53
- package/dist/deprecated/accessor.d.ts.map +0 -1
- package/dist/deprecated/accessor.js +0 -177
- package/dist/deprecated/accessor.js.map +0 -1
- package/dist/utils/split-uniforms-and-bindings.d.ts +0 -9
- package/dist/utils/split-uniforms-and-bindings.d.ts.map +0 -1
- package/dist/utils/split-uniforms-and-bindings.js +0 -21
- package/dist/utils/split-uniforms-and-bindings.js.map +0 -1
- package/src/adapter/helpers/decode-webgl-types.ts +0 -134
- package/src/adapter/helpers/typed-array-utils.ts +0 -129
- package/src/deprecated/accessor.ts +0 -225
- package/src/utils/split-uniforms-and-bindings.ts +0 -31
|
@@ -7,11 +7,17 @@ import type {
|
|
|
7
7
|
UniformBinding,
|
|
8
8
|
UniformBlockBinding,
|
|
9
9
|
AttributeDeclaration,
|
|
10
|
-
VaryingBinding
|
|
10
|
+
VaryingBinding,
|
|
11
|
+
AttributeShaderType
|
|
11
12
|
} from '@luma.gl/core';
|
|
13
|
+
import {getVariableShaderTypeInfo} from '@luma.gl/core';
|
|
12
14
|
|
|
13
|
-
import {GL} from '@luma.gl/constants';
|
|
14
|
-
import {
|
|
15
|
+
import {GL, GLUniformType} from '@luma.gl/constants';
|
|
16
|
+
import {
|
|
17
|
+
isGLSamplerType,
|
|
18
|
+
getTextureBindingFromGLSamplerType,
|
|
19
|
+
convertGLUniformTypeToShaderVariableType
|
|
20
|
+
} from '../converters/webgl-shadertypes';
|
|
15
21
|
|
|
16
22
|
/**
|
|
17
23
|
* Extract metadata describing binding information for a program's shaders
|
|
@@ -53,8 +59,8 @@ export function getShaderLayoutFromGLSL(
|
|
|
53
59
|
const uniforms: UniformBinding[] = readUniformBindings(gl, program);
|
|
54
60
|
let textureUnit = 0;
|
|
55
61
|
for (const uniform of uniforms) {
|
|
56
|
-
if (
|
|
57
|
-
const {viewDimension, sampleType} =
|
|
62
|
+
if (isGLSamplerType(uniform.type)) {
|
|
63
|
+
const {viewDimension, sampleType} = getTextureBindingFromGLSamplerType(uniform.type);
|
|
58
64
|
shaderLayout.bindings.push({
|
|
59
65
|
type: 'texture',
|
|
60
66
|
name: uniform.name,
|
|
@@ -108,7 +114,7 @@ function readAttributeDeclarations(
|
|
|
108
114
|
const location = gl.getAttribLocation(program, name);
|
|
109
115
|
// Add only user provided attributes, for built-in attributes like `gl_InstanceID` location will be < 0
|
|
110
116
|
if (location >= 0) {
|
|
111
|
-
const
|
|
117
|
+
const attributeType = convertGLUniformTypeToShaderVariableType(compositeType);
|
|
112
118
|
|
|
113
119
|
// Whether an attribute is instanced is essentially fixed by the structure of the shader code,
|
|
114
120
|
// so it is arguably a static property of the shader.
|
|
@@ -120,7 +126,7 @@ function readAttributeDeclarations(
|
|
|
120
126
|
name,
|
|
121
127
|
location,
|
|
122
128
|
stepMode,
|
|
123
|
-
type: attributeType
|
|
129
|
+
type: attributeType as AttributeShaderType
|
|
124
130
|
// size - for arrays, size is the number of elements in the array
|
|
125
131
|
});
|
|
126
132
|
}
|
|
@@ -145,10 +151,10 @@ function readVaryings(gl: WebGL2RenderingContext, program: WebGLProgram): Varyin
|
|
|
145
151
|
if (!activeInfo) {
|
|
146
152
|
throw new Error('activeInfo');
|
|
147
153
|
}
|
|
148
|
-
const {name, type:
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
varyings.push(
|
|
154
|
+
const {name, type: glUniformType, size} = activeInfo;
|
|
155
|
+
const uniformType = convertGLUniformTypeToShaderVariableType(glUniformType as GLUniformType);
|
|
156
|
+
const {type, components} = getVariableShaderTypeInfo(uniformType);
|
|
157
|
+
varyings.push({location, name, type, size: size * components});
|
|
152
158
|
}
|
|
153
159
|
|
|
154
160
|
varyings.sort((a, b) => a.location - b.location);
|
|
@@ -251,9 +257,11 @@ function readUniformBlocks(
|
|
|
251
257
|
throw new Error('activeInfo');
|
|
252
258
|
}
|
|
253
259
|
|
|
260
|
+
const format = convertGLUniformTypeToShaderVariableType(uniformType[i]);
|
|
261
|
+
|
|
254
262
|
blockInfo.uniforms.push({
|
|
255
263
|
name: activeInfo.name,
|
|
256
|
-
format
|
|
264
|
+
format,
|
|
257
265
|
type: uniformType[i],
|
|
258
266
|
arrayLength: uniformArrayLength[i],
|
|
259
267
|
byteOffset: uniformOffset[i],
|
|
@@ -291,44 +299,6 @@ function readUniformBlocks(
|
|
|
291
299
|
}
|
|
292
300
|
*/
|
|
293
301
|
|
|
294
|
-
const SAMPLER_UNIFORMS_GL_TO_GPU: Record<
|
|
295
|
-
number,
|
|
296
|
-
[
|
|
297
|
-
'1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d',
|
|
298
|
-
'float' | 'unfilterable-float' | 'depth' | 'sint' | 'uint'
|
|
299
|
-
]
|
|
300
|
-
> = {
|
|
301
|
-
[GL.SAMPLER_2D]: ['2d', 'float'],
|
|
302
|
-
[GL.SAMPLER_CUBE]: ['cube', 'float'],
|
|
303
|
-
[GL.SAMPLER_3D]: ['3d', 'float'],
|
|
304
|
-
[GL.SAMPLER_2D_SHADOW]: ['3d', 'depth'],
|
|
305
|
-
[GL.SAMPLER_2D_ARRAY]: ['2d-array', 'float'],
|
|
306
|
-
[GL.SAMPLER_2D_ARRAY_SHADOW]: ['2d-array', 'depth'],
|
|
307
|
-
[GL.SAMPLER_CUBE_SHADOW]: ['cube', 'float'],
|
|
308
|
-
[GL.INT_SAMPLER_2D]: ['2d', 'sint'],
|
|
309
|
-
[GL.INT_SAMPLER_3D]: ['3d', 'sint'],
|
|
310
|
-
[GL.INT_SAMPLER_CUBE]: ['cube', 'sint'],
|
|
311
|
-
[GL.INT_SAMPLER_2D_ARRAY]: ['2d-array', 'uint'],
|
|
312
|
-
[GL.UNSIGNED_INT_SAMPLER_2D]: ['2d', 'uint'],
|
|
313
|
-
[GL.UNSIGNED_INT_SAMPLER_3D]: ['3d', 'uint'],
|
|
314
|
-
[GL.UNSIGNED_INT_SAMPLER_CUBE]: ['cube', 'uint'],
|
|
315
|
-
[GL.UNSIGNED_INT_SAMPLER_2D_ARRAY]: ['2d-array', 'uint']
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
type SamplerInfo = {
|
|
319
|
-
viewDimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
|
|
320
|
-
sampleType: 'float' | 'unfilterable-float' | 'depth' | 'sint' | 'uint';
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
function getSamplerInfo(type: GL): SamplerInfo {
|
|
324
|
-
const sampler = SAMPLER_UNIFORMS_GL_TO_GPU[type];
|
|
325
|
-
if (!sampler) {
|
|
326
|
-
throw new Error('sampler');
|
|
327
|
-
}
|
|
328
|
-
const [viewDimension, sampleType] = sampler;
|
|
329
|
-
return {viewDimension, sampleType};
|
|
330
|
-
}
|
|
331
|
-
|
|
332
302
|
// HELPERS
|
|
333
303
|
|
|
334
304
|
function parseUniformName(name: string): {name: string; length: number; isArray: boolean} {
|
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
|
|
7
7
|
// Uniforms
|
|
8
8
|
import type {UniformValue} from '@luma.gl/core';
|
|
9
|
-
import {GL,
|
|
9
|
+
import {GL, GLUniformType, GLSamplerType} from '@luma.gl/constants';
|
|
10
10
|
|
|
11
11
|
/** Set a raw uniform (without type conversion and caching) */
|
|
12
12
|
/* eslint-disable max-len */
|
|
13
13
|
export function setUniform(
|
|
14
14
|
gl: WebGL2RenderingContext,
|
|
15
15
|
location: WebGLUniformLocation,
|
|
16
|
-
type:
|
|
16
|
+
type: GLUniformType | GLSamplerType,
|
|
17
17
|
value: UniformValue
|
|
18
18
|
): void {
|
|
19
19
|
const gl2 = gl as WebGL2RenderingContext;
|
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
//
|
|
6
|
-
// WebGL... the texture API from hell... hopefully made simpler
|
|
7
|
-
//
|
|
5
|
+
// @ts-nocheck This file will be deleted in upcoming refactor
|
|
8
6
|
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import {Buffer, Texture, Framebuffer, FramebufferProps} from '@luma.gl/core';
|
|
7
|
+
import type {Buffer, Texture, FramebufferProps} from '@luma.gl/core';
|
|
8
|
+
import {Framebuffer, getTypedArrayConstructor, getDataType} from '@luma.gl/core';
|
|
12
9
|
import {
|
|
13
10
|
GL,
|
|
14
11
|
GLTextureTarget,
|
|
@@ -18,12 +15,12 @@ import {
|
|
|
18
15
|
GLDataType
|
|
19
16
|
} from '@luma.gl/constants';
|
|
20
17
|
|
|
18
|
+
import {convertDataTypeToGLDataType} from '../converters/webgl-shadertypes';
|
|
21
19
|
import {WEBGLFramebuffer} from '../resources/webgl-framebuffer';
|
|
22
|
-
import {getGLTypeFromTypedArray, getTypedArrayFromGLType} from './typed-array-utils';
|
|
23
20
|
import {glFormatToComponents, glTypeToBytes} from './format-utils';
|
|
24
21
|
import {WEBGLBuffer} from '../resources/webgl-buffer';
|
|
25
22
|
import {WEBGLTexture} from '../resources/webgl-texture';
|
|
26
|
-
import {
|
|
23
|
+
import {convertGLDataTypeToDataType} from '../converters/shader-formats';
|
|
27
24
|
|
|
28
25
|
/** A "border" parameter is required in many WebGL texture APIs, but must always be 0... */
|
|
29
26
|
const BORDER = 0;
|
|
@@ -83,120 +80,6 @@ export type WebGLCopyTextureOptions = {
|
|
|
83
80
|
byteLength?: number;
|
|
84
81
|
};
|
|
85
82
|
|
|
86
|
-
/**
|
|
87
|
-
* Initializes a texture memory space
|
|
88
|
-
* Clear all the textures and mip levels of a two-dimensional or array texture at the same time.
|
|
89
|
-
* On some implementations faster than repeatedly setting levels
|
|
90
|
-
*
|
|
91
|
-
* @note From WebGL 2 spec section 3.7.6:
|
|
92
|
-
* @see https://registry.khronos.org/webgl/specs/latest/2.0/
|
|
93
|
-
* - The image contents are set as if a buffer of sufficient size initialized to 0 would be passed to each level's texImage2D/3D
|
|
94
|
-
* - texStorage2D should be considered a preferred alternative to texImage2D. It may have lower memory costs than texImage2D in some implementations.
|
|
95
|
-
* - Once texStorage*D has been called, the texture is immutable and can only be updated with texSubImage*(), not texImage()
|
|
96
|
-
*/
|
|
97
|
-
export function initializeTextureStorage(
|
|
98
|
-
gl: WebGL2RenderingContext,
|
|
99
|
-
levels: number,
|
|
100
|
-
options: WebGLSetTextureOptions
|
|
101
|
-
): void {
|
|
102
|
-
const {dimension, width, height, depth = 0} = options;
|
|
103
|
-
const {glInternalFormat} = options;
|
|
104
|
-
const glTarget = options.glTarget; // getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
105
|
-
switch (dimension) {
|
|
106
|
-
case '2d-array':
|
|
107
|
-
case '3d':
|
|
108
|
-
gl.texStorage3D(glTarget, levels, glInternalFormat, width, height, depth);
|
|
109
|
-
break;
|
|
110
|
-
|
|
111
|
-
default:
|
|
112
|
-
gl.texStorage2D(glTarget, levels, glInternalFormat, width, height);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Copy a region of compressed data from a GPU memory buffer into this texture.
|
|
118
|
-
*/
|
|
119
|
-
export function copyExternalImageToMipLevel(
|
|
120
|
-
gl: WebGL2RenderingContext,
|
|
121
|
-
handle: WebGLTexture,
|
|
122
|
-
image: ExternalImage,
|
|
123
|
-
options: WebGLCopyTextureOptions & {flipY?: boolean}
|
|
124
|
-
): void {
|
|
125
|
-
const {width, height} = options;
|
|
126
|
-
const {dimension, depth = 0, mipLevel = 0} = options;
|
|
127
|
-
const {x = 0, y = 0, z = 0} = options;
|
|
128
|
-
const {glFormat, glType} = options;
|
|
129
|
-
|
|
130
|
-
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
131
|
-
|
|
132
|
-
const glParameters = options.flipY ? {[GL.UNPACK_FLIP_Y_WEBGL]: true} : {};
|
|
133
|
-
withGLParameters(gl, glParameters, () => {
|
|
134
|
-
switch (dimension) {
|
|
135
|
-
case '2d-array':
|
|
136
|
-
case '3d':
|
|
137
|
-
gl.bindTexture(glTarget, handle);
|
|
138
|
-
// prettier-ignore
|
|
139
|
-
gl.texSubImage3D(glTarget, mipLevel, x, y, z, width, height, depth, glFormat, glType, image);
|
|
140
|
-
gl.bindTexture(glTarget, null);
|
|
141
|
-
break;
|
|
142
|
-
|
|
143
|
-
case '2d':
|
|
144
|
-
case 'cube':
|
|
145
|
-
gl.bindTexture(glTarget, handle);
|
|
146
|
-
// prettier-ignore
|
|
147
|
-
gl.texSubImage2D(glTarget, mipLevel, x, y, width, height, glFormat, glType, image);
|
|
148
|
-
gl.bindTexture(glTarget, null);
|
|
149
|
-
break;
|
|
150
|
-
|
|
151
|
-
default:
|
|
152
|
-
throw new Error(dimension);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Copy a region of data from a CPU memory buffer into this texture.
|
|
159
|
-
*/
|
|
160
|
-
export function copyCPUDataToMipLevel(
|
|
161
|
-
gl: WebGL2RenderingContext,
|
|
162
|
-
typedArray: TypedArray,
|
|
163
|
-
options: WebGLCopyTextureOptions
|
|
164
|
-
): void {
|
|
165
|
-
const {dimension, width, height, depth = 0, mipLevel = 0, byteOffset = 0} = options;
|
|
166
|
-
const {x = 0, y = 0, z = 0} = options;
|
|
167
|
-
const {glFormat, glType, compressed} = options;
|
|
168
|
-
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
169
|
-
|
|
170
|
-
// gl.bindTexture(glTarget, null);
|
|
171
|
-
|
|
172
|
-
switch (dimension) {
|
|
173
|
-
case '2d-array':
|
|
174
|
-
case '3d':
|
|
175
|
-
if (compressed) {
|
|
176
|
-
// prettier-ignore
|
|
177
|
-
gl.compressedTexSubImage3D(glTarget, mipLevel, x, y, z, width, height, depth, glFormat, typedArray, byteOffset); // , byteLength
|
|
178
|
-
} else {
|
|
179
|
-
// prettier-ignore
|
|
180
|
-
gl.texSubImage3D(glTarget, mipLevel, x, y, z, width, height, depth, glFormat, glType, typedArray, byteOffset); // , byteLength
|
|
181
|
-
}
|
|
182
|
-
break;
|
|
183
|
-
|
|
184
|
-
case '2d':
|
|
185
|
-
case 'cube':
|
|
186
|
-
if (compressed) {
|
|
187
|
-
// prettier-ignore
|
|
188
|
-
gl.compressedTexSubImage2D(glTarget, mipLevel, x, y, width, height, glFormat, typedArray, byteOffset); // , byteLength
|
|
189
|
-
} else {
|
|
190
|
-
// prettier-ignore
|
|
191
|
-
gl.texSubImage2D(glTarget, mipLevel, x, y, width, height, glFormat, glType, typedArray, byteOffset); // , byteLength
|
|
192
|
-
}
|
|
193
|
-
break;
|
|
194
|
-
|
|
195
|
-
default:
|
|
196
|
-
throw new Error(dimension);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
83
|
/**
|
|
201
84
|
* Copy a region of compressed data from a GPU memory buffer into this texture.
|
|
202
85
|
*/
|
|
@@ -273,227 +156,6 @@ export function getWebGLCubeFaceTarget(
|
|
|
273
156
|
): GLTextureTarget | GLTextureCubeMapTarget {
|
|
274
157
|
return dimension === 'cube' ? GL.TEXTURE_CUBE_MAP_POSITIVE_X + level : glTarget;
|
|
275
158
|
}
|
|
276
|
-
|
|
277
|
-
// texImage methods
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Clear a texture mip level.
|
|
281
|
-
* Wrapper for the messy WebGL texture API
|
|
282
|
-
*
|
|
283
|
-
export function clearMipLevel(gl: WebGL2RenderingContext, options: WebGLSetTextureOptions): void {
|
|
284
|
-
const {dimension, width, height, depth = 0, mipLevel = 0} = options;
|
|
285
|
-
const {glInternalFormat, glFormat, glType, compressed} = options;
|
|
286
|
-
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
287
|
-
|
|
288
|
-
switch (dimension) {
|
|
289
|
-
case '2d-array':
|
|
290
|
-
case '3d':
|
|
291
|
-
if (compressed) {
|
|
292
|
-
// prettier-ignore
|
|
293
|
-
gl.compressedTexImage3D(glTarget, mipLevel, glInternalFormat, width, height, depth, BORDER, null);
|
|
294
|
-
} else {
|
|
295
|
-
// prettier-ignore
|
|
296
|
-
gl.texImage3D( glTarget, mipLevel, glInternalFormat, width, height, depth, BORDER, glFormat, glType, null);
|
|
297
|
-
}
|
|
298
|
-
break;
|
|
299
|
-
|
|
300
|
-
case '2d':
|
|
301
|
-
case 'cube':
|
|
302
|
-
if (compressed) {
|
|
303
|
-
// prettier-ignore
|
|
304
|
-
gl.compressedTexImage2D(glTarget, mipLevel, glInternalFormat, width, height, BORDER, null);
|
|
305
|
-
} else {
|
|
306
|
-
// prettier-ignore
|
|
307
|
-
gl.texImage2D(glTarget, mipLevel, glInternalFormat, width, height, BORDER, glFormat, glType, null);
|
|
308
|
-
}
|
|
309
|
-
break;
|
|
310
|
-
|
|
311
|
-
default:
|
|
312
|
-
throw new Error(dimension);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
*/
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Set a texture mip level to the contents of an external image.
|
|
319
|
-
* Wrapper for the messy WebGL texture API
|
|
320
|
-
* @note Corresponds to WebGPU device.queue.copyExternalImageToTexture()
|
|
321
|
-
*
|
|
322
|
-
export function setMipLevelFromExternalImage(
|
|
323
|
-
gl: WebGL2RenderingContext,
|
|
324
|
-
image: ExternalImage,
|
|
325
|
-
options: WebGLSetTextureOptions
|
|
326
|
-
): void {
|
|
327
|
-
const {dimension, width, height, depth = 0, level = 0} = options;
|
|
328
|
-
const {glInternalFormat, glType} = options;
|
|
329
|
-
|
|
330
|
-
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
331
|
-
|
|
332
|
-
// TODO - we can't change texture width (due to WebGPU limitations) -
|
|
333
|
-
// and the width/heigh of an external image is implicit, so why do we need to extract it?
|
|
334
|
-
// So what width height do we supply? The image size or the texture size?
|
|
335
|
-
// const {width, height} = Texture.getExternalImageSize(image);
|
|
336
|
-
|
|
337
|
-
switch (dimension) {
|
|
338
|
-
case '2d-array':
|
|
339
|
-
case '3d':
|
|
340
|
-
// prettier-ignore
|
|
341
|
-
gl.texImage3D(glTarget, level, glInternalFormat, width, height, depth, BORDER, glInternalFormat, glType, image);
|
|
342
|
-
break;
|
|
343
|
-
|
|
344
|
-
case '2d':
|
|
345
|
-
case 'cube':
|
|
346
|
-
// prettier-ignore
|
|
347
|
-
gl.texImage2D(glTarget, level, glInternalFormat, width, height, BORDER, glInternalFormat, glType, image);
|
|
348
|
-
break;
|
|
349
|
-
|
|
350
|
-
default:
|
|
351
|
-
throw new Error(dimension);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Set a texture mip level from CPU memory
|
|
357
|
-
* Wrapper for the messy WebGL texture API
|
|
358
|
-
* @note Not available (directly) in WebGPU
|
|
359
|
-
*
|
|
360
|
-
export function setMipLevelFromTypedArray(
|
|
361
|
-
gl: WebGL2RenderingContext,
|
|
362
|
-
data: TypedArray,
|
|
363
|
-
parameters: {},
|
|
364
|
-
options: {
|
|
365
|
-
dimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
|
|
366
|
-
height: number;
|
|
367
|
-
width: number;
|
|
368
|
-
depth?: number;
|
|
369
|
-
level?: number;
|
|
370
|
-
offset?: number;
|
|
371
|
-
glTarget: GLTextureTarget;
|
|
372
|
-
glInternalFormat: GL;
|
|
373
|
-
glFormat: GL;
|
|
374
|
-
glType: GL;
|
|
375
|
-
compressed?: boolean;
|
|
376
|
-
}
|
|
377
|
-
): void {
|
|
378
|
-
const {dimension, width, height, depth = 0, level = 0, offset = 0} = options;
|
|
379
|
-
const {glInternalFormat, glFormat, glType, compressed} = options;
|
|
380
|
-
|
|
381
|
-
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
382
|
-
|
|
383
|
-
withGLParameters(gl, parameters, () => {
|
|
384
|
-
switch (dimension) {
|
|
385
|
-
case '2d-array':
|
|
386
|
-
case '3d':
|
|
387
|
-
if (compressed) {
|
|
388
|
-
// prettier-ignore
|
|
389
|
-
gl.compressedTexImage3D(glTarget, level, glInternalFormat, width, height, depth, BORDER, data);
|
|
390
|
-
} else {
|
|
391
|
-
// prettier-ignore
|
|
392
|
-
gl.texImage3D( glTarget, level, glInternalFormat, width, height, depth, BORDER, glFormat, glType, data);
|
|
393
|
-
}
|
|
394
|
-
break;
|
|
395
|
-
|
|
396
|
-
case '2d':
|
|
397
|
-
if (compressed) {
|
|
398
|
-
// prettier-ignore
|
|
399
|
-
gl.compressedTexImage2D(glTarget, level, glInternalFormat, width, height, BORDER, data);
|
|
400
|
-
} else {
|
|
401
|
-
// prettier-ignore
|
|
402
|
-
gl.texImage2D( glTarget, level, glInternalFormat, width, height, BORDER, glFormat, glType, data, offset);
|
|
403
|
-
}
|
|
404
|
-
break;
|
|
405
|
-
|
|
406
|
-
default:
|
|
407
|
-
throw new Error(dimension);
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* Set a texture level from CPU memory
|
|
414
|
-
* @note Not available (directly) in WebGPU
|
|
415
|
-
_setMipLevelFromTypedArray(
|
|
416
|
-
depth: number,
|
|
417
|
-
level: number,
|
|
418
|
-
data: TextureLevelData,
|
|
419
|
-
offset = 0,
|
|
420
|
-
parameters
|
|
421
|
-
): void {
|
|
422
|
-
withGLParameters(this.gl, parameters, () => {
|
|
423
|
-
switch (this.props.dimension) {
|
|
424
|
-
case '2d-array':
|
|
425
|
-
case '3d':
|
|
426
|
-
if (this.compressed) {
|
|
427
|
-
// prettier-ignore
|
|
428
|
-
this.device.gl.compressedTexImage3D(this.glTarget, level, this.glInternalFormat, data.width, data.height, depth, BORDER, data.data);
|
|
429
|
-
} else {
|
|
430
|
-
// prettier-ignore
|
|
431
|
-
this.gl.texImage3D( this.glTarget, level, this.glInternalFormat, this.width, this.height, depth, BORDER, this.glFormat, this.glType, data.data);
|
|
432
|
-
}
|
|
433
|
-
break;
|
|
434
|
-
|
|
435
|
-
case '2d':
|
|
436
|
-
if (this.compressed) {
|
|
437
|
-
// prettier-ignore
|
|
438
|
-
this.device.gl.compressedTexImage2D(this.glTarget, level, this.glInternalFormat, data.width, data.height, BORDER, data.data);
|
|
439
|
-
} else {
|
|
440
|
-
// prettier-ignore
|
|
441
|
-
this.device.gl.texImage2D( this.glTarget, level, this.glInternalFormat, this.width, this.height, BORDER, this.glFormat, this.glType, data.data, offset);
|
|
442
|
-
}
|
|
443
|
-
break;
|
|
444
|
-
|
|
445
|
-
default:
|
|
446
|
-
throw new Error(this.props.dimension);
|
|
447
|
-
}
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
* Set a texture level from a GPU buffer
|
|
452
|
-
*
|
|
453
|
-
export function setMipLevelFromGPUBuffer(
|
|
454
|
-
gl: WebGL2RenderingContext,
|
|
455
|
-
buffer: Buffer,
|
|
456
|
-
options: WebGLSetTextureOptions
|
|
457
|
-
): void {
|
|
458
|
-
const {dimension, width, height, depth = 0, level = 0, byteOffset = 0} = options;
|
|
459
|
-
const {glInternalFormat, glFormat, glType, compressed} = options;
|
|
460
|
-
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
461
|
-
|
|
462
|
-
const webglBuffer = buffer as WEBGLBuffer;
|
|
463
|
-
const imageSize = buffer.byteLength;
|
|
464
|
-
|
|
465
|
-
// In WebGL the source buffer is not a parameter. Instead it needs to be bound to a special bind point
|
|
466
|
-
gl.bindBuffer(GL.PIXEL_UNPACK_BUFFER, webglBuffer.handle);
|
|
467
|
-
|
|
468
|
-
switch (dimension) {
|
|
469
|
-
case '2d-array':
|
|
470
|
-
case '3d':
|
|
471
|
-
if (compressed) {
|
|
472
|
-
// prettier-ignore
|
|
473
|
-
gl.compressedTexImage3D(glTarget, level, glInternalFormat, width, height, depth, BORDER, imageSize, byteOffset);
|
|
474
|
-
} else {
|
|
475
|
-
// prettier-ignore
|
|
476
|
-
gl.texImage3D(glTarget, level, glInternalFormat, width, height, depth, BORDER, glFormat, glType, byteOffset);
|
|
477
|
-
}
|
|
478
|
-
break;
|
|
479
|
-
|
|
480
|
-
case '2d':
|
|
481
|
-
if (compressed) {
|
|
482
|
-
// prettier-ignore
|
|
483
|
-
gl.compressedTexImage2D(glTarget, level, glInternalFormat, width, height, BORDER, imageSize, byteOffset);
|
|
484
|
-
} else {
|
|
485
|
-
// prettier-ignore
|
|
486
|
-
gl.texImage2D(glTarget, level, glInternalFormat, width, height, BORDER, glFormat, glType, byteOffset);
|
|
487
|
-
}
|
|
488
|
-
break;
|
|
489
|
-
|
|
490
|
-
default:
|
|
491
|
-
throw new Error(dimension);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
gl.bindBuffer(GL.PIXEL_UNPACK_BUFFER, null);
|
|
495
|
-
}
|
|
496
|
-
*/
|
|
497
159
|
export type ReadPixelsToArrayOptions = {
|
|
498
160
|
sourceX?: number;
|
|
499
161
|
sourceY?: number;
|
|
@@ -570,7 +232,8 @@ export function readPixelsToArray(
|
|
|
570
232
|
target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight, sourceDepth);
|
|
571
233
|
|
|
572
234
|
// Pixel array available, if necessary, deduce type from it.
|
|
573
|
-
|
|
235
|
+
const signedType = getDataType(target);
|
|
236
|
+
sourceType = sourceType || convertDataTypeToGLDataType(signedType);
|
|
574
237
|
|
|
575
238
|
// Note: luma.gl overrides bindFramebuffer so that we can reliably restore the previous framebuffer (this is the only function for which we do that)
|
|
576
239
|
const prevHandle = gl.bindFramebuffer(
|
|
@@ -717,7 +380,7 @@ export function copyToTexture(
|
|
|
717
380
|
texture = destinationTexture;
|
|
718
381
|
width = Number.isFinite(width) ? width : texture.width;
|
|
719
382
|
height = Number.isFinite(height) ? height : texture.height;
|
|
720
|
-
texture?.
|
|
383
|
+
texture?._bind(0);
|
|
721
384
|
// @ts-ignore
|
|
722
385
|
textureTarget = texture.target;
|
|
723
386
|
} else {
|
|
@@ -769,7 +432,7 @@ export function copyToTexture(
|
|
|
769
432
|
}
|
|
770
433
|
}
|
|
771
434
|
if (texture) {
|
|
772
|
-
texture.
|
|
435
|
+
texture._unbind();
|
|
773
436
|
}
|
|
774
437
|
// @ts-expect-error
|
|
775
438
|
device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
|
|
@@ -817,10 +480,11 @@ function getPixelArray(
|
|
|
817
480
|
if (pixelArray) {
|
|
818
481
|
return pixelArray;
|
|
819
482
|
}
|
|
820
|
-
// const formatInfo =
|
|
483
|
+
// const formatInfo = getTextureFormatInfo(format);
|
|
821
484
|
// Allocate pixel array if not already available, using supplied type
|
|
822
485
|
glType ||= GL.UNSIGNED_BYTE;
|
|
823
|
-
const
|
|
486
|
+
const shaderType = convertGLDataTypeToDataType(glType);
|
|
487
|
+
const ArrayType = getTypedArrayConstructor(shaderType);
|
|
824
488
|
const components = glFormatToComponents(glFormat);
|
|
825
489
|
// TODO - check for composite type (components = 1).
|
|
826
490
|
return new ArrayType(width * height * components) as Uint8Array | Uint16Array | Float32Array;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {BufferProps} from '@luma.gl/core';
|
|
5
|
+
import type {BufferMapCallback, BufferProps} from '@luma.gl/core';
|
|
6
6
|
import {Buffer} from '@luma.gl/core';
|
|
7
7
|
import {GL} from '@luma.gl/constants';
|
|
8
8
|
import {WebGLDevice} from '../webgl-device';
|
|
@@ -21,9 +21,9 @@ export class WEBGLBuffer extends Buffer {
|
|
|
21
21
|
readonly glIndexType: GL.UNSIGNED_SHORT | GL.UNSIGNED_INT = GL.UNSIGNED_SHORT;
|
|
22
22
|
|
|
23
23
|
/** Number of bytes allocated on the GPU for this buffer */
|
|
24
|
-
byteLength: number;
|
|
24
|
+
byteLength: number = 0;
|
|
25
25
|
/** Number of bytes used */
|
|
26
|
-
bytesUsed: number;
|
|
26
|
+
bytesUsed: number = 0;
|
|
27
27
|
|
|
28
28
|
constructor(device: WebGLDevice, props: BufferProps = {}) {
|
|
29
29
|
super(device, props);
|
|
@@ -33,7 +33,9 @@ export class WEBGLBuffer extends Buffer {
|
|
|
33
33
|
|
|
34
34
|
const handle = typeof props === 'object' ? props.handle : undefined;
|
|
35
35
|
this.handle = handle || this.gl.createBuffer();
|
|
36
|
-
device.
|
|
36
|
+
device._setWebGLDebugMetadata(this.handle, this, {
|
|
37
|
+
spector: {...this.props, data: typeof this.props.data}
|
|
38
|
+
});
|
|
37
39
|
|
|
38
40
|
// - In WebGL1, need to make sure we use GL.ELEMENT_ARRAY_BUFFER when initializing element buffers
|
|
39
41
|
// otherwise buffer type will lock to generic (non-element) buffer
|
|
@@ -50,7 +52,16 @@ export class WEBGLBuffer extends Buffer {
|
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
override destroy(): void {
|
|
56
|
+
if (!this.destroyed && this.handle) {
|
|
57
|
+
this.removeStats();
|
|
58
|
+
this.trackDeallocatedMemory();
|
|
59
|
+
this.gl.deleteBuffer(this.handle);
|
|
60
|
+
this.destroyed = true;
|
|
61
|
+
// @ts-expect-error
|
|
62
|
+
this.handle = null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
54
65
|
|
|
55
66
|
/** Allocate a new buffer and initialize to contents of typed array */
|
|
56
67
|
_initWithData(
|
|
@@ -100,18 +111,8 @@ export class WEBGLBuffer extends Buffer {
|
|
|
100
111
|
return this;
|
|
101
112
|
}
|
|
102
113
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.removeStats();
|
|
106
|
-
this.trackDeallocatedMemory();
|
|
107
|
-
this.gl.deleteBuffer(this.handle);
|
|
108
|
-
this.destroyed = true;
|
|
109
|
-
// @ts-expect-error
|
|
110
|
-
this.handle = null;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
override write(data: ArrayBufferView, byteOffset: number = 0): void {
|
|
114
|
+
write(data: ArrayBufferLike | ArrayBufferView, byteOffset: number = 0): void {
|
|
115
|
+
const dataView = ArrayBuffer.isView(data) ? data : new Uint8Array(data);
|
|
115
116
|
const srcOffset = 0;
|
|
116
117
|
const byteLength = undefined; // data.byteLength;
|
|
117
118
|
|
|
@@ -121,22 +122,41 @@ export class WEBGLBuffer extends Buffer {
|
|
|
121
122
|
this.gl.bindBuffer(glTarget, this.handle);
|
|
122
123
|
// WebGL2: subData supports additional srcOffset and length parameters
|
|
123
124
|
if (srcOffset !== 0 || byteLength !== undefined) {
|
|
124
|
-
this.gl.bufferSubData(glTarget, byteOffset,
|
|
125
|
+
this.gl.bufferSubData(glTarget, byteOffset, dataView, srcOffset, byteLength);
|
|
125
126
|
} else {
|
|
126
|
-
this.gl.bufferSubData(glTarget, byteOffset,
|
|
127
|
+
this.gl.bufferSubData(glTarget, byteOffset, dataView);
|
|
127
128
|
}
|
|
128
129
|
this.gl.bindBuffer(glTarget, null);
|
|
129
130
|
|
|
130
131
|
this._setDebugData(data, byteOffset, data.byteLength);
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
async mapAndWriteAsync(
|
|
135
|
+
callback: BufferMapCallback<void>,
|
|
136
|
+
byteOffset: number = 0,
|
|
137
|
+
byteLength: number = this.byteLength - byteOffset
|
|
138
|
+
): Promise<void> {
|
|
139
|
+
const arrayBuffer = new ArrayBuffer(byteLength);
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
141
|
+
await callback(arrayBuffer, 'copied');
|
|
142
|
+
this.write(arrayBuffer, byteOffset);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async readAsync(byteOffset = 0, byteLength?: number): Promise<Uint8Array<ArrayBuffer>> {
|
|
135
146
|
return this.readSyncWebGL(byteOffset, byteLength);
|
|
136
147
|
}
|
|
137
148
|
|
|
138
|
-
|
|
139
|
-
|
|
149
|
+
async mapAndReadAsync<T>(
|
|
150
|
+
callback: BufferMapCallback<T>,
|
|
151
|
+
byteOffset = 0,
|
|
152
|
+
byteLength?: number
|
|
153
|
+
): Promise<T> {
|
|
154
|
+
const data = await this.readAsync(byteOffset, byteLength);
|
|
155
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
156
|
+
return await callback(data.buffer, 'copied');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
readSyncWebGL(byteOffset = 0, byteLength?: number): Uint8Array<ArrayBuffer> {
|
|
140
160
|
byteLength = byteLength ?? this.byteLength - byteOffset;
|
|
141
161
|
const data = new Uint8Array(byteLength);
|
|
142
162
|
const dstOffset = 0;
|