@luma.gl/webgl 9.0.0-alpha.27 → 9.0.0-alpha.29
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/helpers/get-shader-layout.d.ts +8 -5
- package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-shader-layout.js +59 -16
- package/dist/adapter/helpers/get-shader-layout.js.map +1 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +12 -0
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -0
- package/dist/adapter/helpers/get-vertex-buffer-layout.js +84 -0
- package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -0
- package/dist/adapter/objects/webgl-vertex-array-object.js +2 -2
- package/dist/adapter/objects/webgl-vertex-array-object.js.map +1 -1
- package/dist/adapter/resources/webgl-buffer.d.ts +13 -4
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +23 -21
- package/dist/adapter/resources/webgl-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-external-texture.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +27 -4
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +25 -7
- package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +5 -2
- package/dist/adapter/webgl-device.js.map +1 -1
- package/dist/classic/buffer-with-accessor.d.ts +5 -15
- package/dist/classic/buffer-with-accessor.d.ts.map +1 -1
- package/dist/classic/buffer-with-accessor.js +25 -30
- package/dist/classic/buffer-with-accessor.js.map +1 -1
- package/dist/classic/copy-and-blit.d.ts.map +1 -1
- package/dist/classic/copy-and-blit.js +2 -2
- package/dist/classic/copy-and-blit.js.map +1 -1
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +2 -1
- package/dist/context/debug/webgl-developer-tools.js.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js +2 -2
- package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
- package/dist/dist.dev.js +164 -83
- package/dist/index.cjs +207 -146
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist.min.js +22 -22
- package/package.json +5 -5
- package/src/adapter/helpers/get-shader-layout.ts +93 -33
- package/src/adapter/helpers/get-vertex-buffer-layout.ts +123 -0
- package/src/adapter/objects/webgl-vertex-array-object.ts +2 -2
- package/src/adapter/resources/webgl-buffer.ts +40 -41
- package/src/adapter/resources/webgl-external-texture.ts +1 -1
- package/src/adapter/resources/webgl-render-pipeline.ts +51 -35
- package/src/adapter/webgl-device.ts +4 -2
- package/src/classic/buffer-with-accessor.ts +42 -43
- package/src/classic/copy-and-blit.ts +2 -3
- package/src/context/debug/webgl-developer-tools.ts +8 -2
- package/src/context/parameters/webgl-parameter-tables.ts +2 -2
- package/src/index.ts +1 -1
|
@@ -7,13 +7,14 @@ import type {
|
|
|
7
7
|
PrimitiveTopology,
|
|
8
8
|
// BindingLayout,
|
|
9
9
|
AttributeLayout,
|
|
10
|
-
TypedArray
|
|
10
|
+
TypedArray,
|
|
11
|
+
BufferMapping
|
|
11
12
|
} from '@luma.gl/api';
|
|
12
13
|
import {RenderPipeline, cast, log, decodeVertexFormat} from '@luma.gl/api';
|
|
13
14
|
import {GL} from '@luma.gl/constants';
|
|
14
15
|
|
|
15
16
|
import {getWebGLDataType} from '../converters/texture-formats';
|
|
16
|
-
import {getShaderLayout} from '../helpers/get-shader-layout';
|
|
17
|
+
import {getShaderLayout, mergeShaderLayout, mergeBufferMap} from '../helpers/get-shader-layout';
|
|
17
18
|
import {withDeviceParameters, withGLParameters} from '../converters/device-parameters';
|
|
18
19
|
import {setUniform} from '../helpers/set-uniform';
|
|
19
20
|
// import {copyUniform, checkUniformValues} from '../../classes/uniforms';
|
|
@@ -29,19 +30,35 @@ const LOG_PROGRAM_PERF_PRIORITY = 4;
|
|
|
29
30
|
|
|
30
31
|
/** Creates a new render pipeline */
|
|
31
32
|
export class WEBGLRenderPipeline extends RenderPipeline {
|
|
33
|
+
/** The WebGL device that created this render pipeline */
|
|
32
34
|
device: WebGLDevice;
|
|
35
|
+
/** Handle to underlying WebGL program */
|
|
33
36
|
handle: WebGLProgram;
|
|
37
|
+
/** vertex shader */
|
|
34
38
|
vs: WEBGLShader;
|
|
39
|
+
/** fragment shader */
|
|
35
40
|
fs: WEBGLShader;
|
|
41
|
+
/** The merged layout */
|
|
36
42
|
layout: ShaderLayout;
|
|
43
|
+
/** The layout extracted from shader by WebGL introspection APIs */
|
|
44
|
+
introspectedLayout: ShaderLayout;
|
|
45
|
+
/** Buffer map describing buffer interleaving etc */
|
|
46
|
+
bufferMap: BufferMapping[];
|
|
37
47
|
|
|
38
|
-
|
|
39
|
-
// Experimental flag to avoid deleting Program object while it is cached
|
|
40
|
-
varyings: string[] | null = null;
|
|
41
|
-
vertexArrayObject: WEBGLVertexArrayObject;
|
|
42
|
-
_indexBuffer?: Buffer;
|
|
48
|
+
/** Uniforms set on this model */
|
|
43
49
|
uniforms: Record<string, any> = {};
|
|
50
|
+
/** Bindings set on this model */
|
|
44
51
|
bindings: Record<string, any> = {};
|
|
52
|
+
/** Any constant attributes */
|
|
53
|
+
constantAttributes: Record<string, TypedArray> = {};
|
|
54
|
+
/** Index buffer is stored separately */
|
|
55
|
+
_indexBuffer?: WEBGLBuffer;
|
|
56
|
+
/** WebGL varyings */
|
|
57
|
+
varyings: string[] | null = null;
|
|
58
|
+
|
|
59
|
+
/** Stores attribute bindings */
|
|
60
|
+
vertexArrayObject: WEBGLVertexArrayObject;
|
|
61
|
+
|
|
45
62
|
_textureUniforms: Record<string, any> = {};
|
|
46
63
|
_textureIndexCounter: number = 0;
|
|
47
64
|
_uniformCount: number = 0;
|
|
@@ -70,7 +87,12 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
70
87
|
|
|
71
88
|
this._compileAndLink();
|
|
72
89
|
|
|
73
|
-
this.
|
|
90
|
+
this.introspectedLayout = getShaderLayout(this.device.gl, this.handle);
|
|
91
|
+
// Merge provided layout with introspected layout
|
|
92
|
+
this.layout = mergeShaderLayout(this.introspectedLayout, props.layout);
|
|
93
|
+
// Merge layout with any buffer map overrides
|
|
94
|
+
this.bufferMap = props.bufferMap || [];
|
|
95
|
+
this.layout = mergeBufferMap(this.layout, this.bufferMap);
|
|
74
96
|
this.vertexArrayObject = new WEBGLVertexArrayObject(this.device);
|
|
75
97
|
}
|
|
76
98
|
|
|
@@ -85,7 +107,7 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
85
107
|
setIndexBuffer(indexBuffer: Buffer): void {
|
|
86
108
|
const webglBuffer = cast<WEBGLBuffer>(indexBuffer);
|
|
87
109
|
this.vertexArrayObject.setElementBuffer(webglBuffer);
|
|
88
|
-
this._indexBuffer =
|
|
110
|
+
this._indexBuffer = webglBuffer;
|
|
89
111
|
}
|
|
90
112
|
|
|
91
113
|
/** @todo needed for portable model */
|
|
@@ -128,6 +150,7 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
128
150
|
}
|
|
129
151
|
this.vertexArrayObject.setConstant(attribute.location, value);
|
|
130
152
|
}
|
|
153
|
+
Object.assign(this.constantAttributes, attributes);
|
|
131
154
|
}
|
|
132
155
|
|
|
133
156
|
/**
|
|
@@ -203,7 +226,7 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
203
226
|
|
|
204
227
|
const drawMode = getDrawMode(this.props.topology);
|
|
205
228
|
const isIndexed: boolean = Boolean(this._indexBuffer);
|
|
206
|
-
const indexType = this._indexBuffer?.
|
|
229
|
+
const indexType = this._indexBuffer?.glIndexType;
|
|
207
230
|
const isInstanced: boolean = Number(options.instanceCount) > 0;
|
|
208
231
|
|
|
209
232
|
// Avoid WebGL draw call when not rendering any data or values are incomplete
|
|
@@ -227,6 +250,7 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
227
250
|
// We have to apply bindings before every draw call since other draw calls will overwrite
|
|
228
251
|
this._applyBindings();
|
|
229
252
|
this._applyUniforms();
|
|
253
|
+
this._applyConstantAttributes();
|
|
230
254
|
|
|
231
255
|
const webglRenderPass = renderPass as WEBGLRenderPass;
|
|
232
256
|
|
|
@@ -386,9 +410,25 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
386
410
|
}
|
|
387
411
|
}
|
|
388
412
|
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Constant attributes are only supported in WebGL, not in WebGPU
|
|
416
|
+
* Any attribute that is disabled in the current vertex array object
|
|
417
|
+
* is read from the context's global constant value for that attribute location.
|
|
418
|
+
*/
|
|
419
|
+
_applyConstantAttributes(): void {
|
|
420
|
+
for (const [name, value] of Object.entries(this.constantAttributes)) {
|
|
421
|
+
const attribute = getAttributeLayout(this.layout, name);
|
|
422
|
+
if (!attribute) {
|
|
423
|
+
log.warn(`Ignoring constant value supplied for unknown attribute "${name}" in pipeline "${this.id}"`)();
|
|
424
|
+
continue; // eslint-disable-line no-continue
|
|
425
|
+
}
|
|
426
|
+
this.vertexArrayObject.setConstant(attribute.location, value);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
389
429
|
}
|
|
390
430
|
|
|
391
|
-
/** Get the primitive type for
|
|
431
|
+
/** Get the primitive type for draw */
|
|
392
432
|
function getDrawMode(
|
|
393
433
|
topology: PrimitiveTopology
|
|
394
434
|
): GL.POINTS | GL.LINES | GL.LINE_STRIP | GL.LINE_LOOP | GL.TRIANGLES | GL.TRIANGLE_STRIP | GL.TRIANGLE_FAN {
|
|
@@ -420,30 +460,6 @@ function getGLPrimitive(topology: PrimitiveTopology): GL.POINTS | GL.LINES | GL.
|
|
|
420
460
|
}
|
|
421
461
|
}
|
|
422
462
|
|
|
423
|
-
// function getAttributesByLocation(
|
|
424
|
-
// attributes: Record<string, Buffer>,
|
|
425
|
-
// layout: ShaderLayout
|
|
426
|
-
// ): Record<number, Buffer> {
|
|
427
|
-
// const byLocation: Record<number, Buffer> = {};
|
|
428
|
-
// for (const [name, buffer] of Object.entries(attributes)) {
|
|
429
|
-
// const attribute = getAttributeLayout(layout, name);
|
|
430
|
-
// if (attribute) {
|
|
431
|
-
// byLocation[attribute.location] = buffer;
|
|
432
|
-
// }
|
|
433
|
-
// }
|
|
434
|
-
// return byLocation;
|
|
435
|
-
// }
|
|
436
|
-
|
|
437
463
|
function getAttributeLayout(layout: ShaderLayout, name: string): AttributeLayout | null {
|
|
438
464
|
return layout.attributes.find((binding) => binding.name === name) || null;
|
|
439
465
|
}
|
|
440
|
-
|
|
441
|
-
/* TODO
|
|
442
|
-
function getBindingLayout(layout: ShaderLayout, name: string): BindingLayout {
|
|
443
|
-
const binding = layout.bindings.find((binding) => binding.name === name);
|
|
444
|
-
if (!binding) {
|
|
445
|
-
throw new Error(`Unknown binding ${name}`);
|
|
446
|
-
}
|
|
447
|
-
return binding;
|
|
448
|
-
}
|
|
449
|
-
*/
|
|
@@ -130,11 +130,13 @@ export class WebGLDevice extends Device {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
// Load webgl and spector debug scripts from CDN if requested
|
|
133
|
-
if (props.debug) {
|
|
133
|
+
if (log.get('debug') || props.debug) {
|
|
134
134
|
await loadWebGLDeveloperTools();
|
|
135
135
|
}
|
|
136
|
+
|
|
136
137
|
// @ts-expect-error spector not on props
|
|
137
|
-
|
|
138
|
+
const {spector} = props;
|
|
139
|
+
if (log.get('spector') || spector) {
|
|
138
140
|
await loadSpectorJS();
|
|
139
141
|
}
|
|
140
142
|
|
|
@@ -55,9 +55,9 @@ function getWEBGLBufferProps(props: BufferWithAccessorProps | ArrayBufferView |
|
|
|
55
55
|
|
|
56
56
|
props = checkProps('Buffer', props, PROP_CHECKS_INITIALIZE);
|
|
57
57
|
const bufferProps = {...props };
|
|
58
|
-
if (bufferProps.offset) {
|
|
59
|
-
|
|
60
|
-
}
|
|
58
|
+
// if (bufferProps.offset) {
|
|
59
|
+
// bufferProps.byteOffset = bufferProps.offset;
|
|
60
|
+
// }
|
|
61
61
|
return bufferProps;
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -65,19 +65,18 @@ function getWEBGLBufferProps(props: BufferWithAccessorProps | ArrayBufferView |
|
|
|
65
65
|
export type BufferWithAccessorProps = BufferProps & {
|
|
66
66
|
handle?: WebGLBuffer;
|
|
67
67
|
|
|
68
|
-
target?: number;
|
|
69
|
-
webglUsage?: number;
|
|
70
|
-
|
|
71
68
|
accessor?: AccessorObject;
|
|
72
69
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
/** @deprecated */
|
|
76
|
-
|
|
77
|
-
/** @deprecated */
|
|
78
|
-
|
|
79
|
-
/** @deprecated */
|
|
80
|
-
|
|
70
|
+
// target?: number;
|
|
71
|
+
// glUsage?: number;
|
|
72
|
+
// /** @deprecated */
|
|
73
|
+
// index?: number;
|
|
74
|
+
// /** @deprecated */
|
|
75
|
+
// offset?: number;
|
|
76
|
+
// /** @deprecated */
|
|
77
|
+
// size?: number;
|
|
78
|
+
// /** @deprecated */
|
|
79
|
+
// type?: number
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
/** WebGL Buffer interface */
|
|
@@ -141,7 +140,8 @@ export class BufferWithAccessor extends WEBGLBuffer {
|
|
|
141
140
|
props = checkProps('Buffer', props, PROP_CHECKS_INITIALIZE);
|
|
142
141
|
|
|
143
142
|
// Initialize member fields
|
|
144
|
-
|
|
143
|
+
// @ts-expect-error readonly field
|
|
144
|
+
this.glUsage = props.glUsage || GL.STATIC_DRAW;
|
|
145
145
|
this.debugData = null;
|
|
146
146
|
|
|
147
147
|
// Deprecated: Merge main props and accessor
|
|
@@ -149,7 +149,7 @@ export class BufferWithAccessor extends WEBGLBuffer {
|
|
|
149
149
|
|
|
150
150
|
// Set data: (re)initializes the buffer
|
|
151
151
|
if (props.data) {
|
|
152
|
-
this._setData(props.data, props.
|
|
152
|
+
this._setData(props.data, props.byteOffset, props.byteLength);
|
|
153
153
|
} else {
|
|
154
154
|
this._setByteLength(props.byteLength || 0);
|
|
155
155
|
}
|
|
@@ -220,17 +220,17 @@ export class BufferWithAccessor extends WEBGLBuffer {
|
|
|
220
220
|
// Create the buffer - binding it here for the first time locks the type
|
|
221
221
|
// In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type
|
|
222
222
|
// @ts-expect-error
|
|
223
|
-
const
|
|
224
|
-
this.gl.bindBuffer(
|
|
223
|
+
const glTarget = this.gl.webgl2 ? GL.COPY_WRITE_BUFFER : this.glTarget;
|
|
224
|
+
this.gl.bindBuffer(glTarget, this.handle);
|
|
225
225
|
// WebGL2: subData supports additional srcOffset and length parameters
|
|
226
226
|
if (srcOffset !== 0 || byteLength !== undefined) {
|
|
227
227
|
assertWebGL2Context(this.gl);
|
|
228
228
|
// @ts-expect-error
|
|
229
|
-
this.gl.bufferSubData(this.
|
|
229
|
+
this.gl.bufferSubData(this.glTarget, offset, data, srcOffset, byteLength);
|
|
230
230
|
} else {
|
|
231
|
-
this.gl.bufferSubData(
|
|
231
|
+
this.gl.bufferSubData(glTarget, offset, data);
|
|
232
232
|
}
|
|
233
|
-
this.gl.bindBuffer(
|
|
233
|
+
this.gl.bindBuffer(glTarget, null);
|
|
234
234
|
|
|
235
235
|
// TODO - update local `data` if offsets are right
|
|
236
236
|
this.debugData = null;
|
|
@@ -321,9 +321,9 @@ export class BufferWithAccessor extends WEBGLBuffer {
|
|
|
321
321
|
* - GL.UNIFORM_BUFFER: `offset` must be aligned to GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT.
|
|
322
322
|
* - GL.UNIFORM_BUFFER: `size` must be a minimum of GL.UNIFORM_BLOCK_SIZE_DATA.
|
|
323
323
|
*/
|
|
324
|
-
bind(options?: {
|
|
324
|
+
bind(options?: {glTarget?: number; index?: any; offset?: number; size?: any}): this {
|
|
325
325
|
const {
|
|
326
|
-
|
|
326
|
+
glTarget = this.glTarget, // target for the bind operation
|
|
327
327
|
index = this.accessor && this.accessor.index, // index = index of target (indexed bind point)
|
|
328
328
|
offset = 0,
|
|
329
329
|
size
|
|
@@ -331,27 +331,27 @@ export class BufferWithAccessor extends WEBGLBuffer {
|
|
|
331
331
|
// NOTE: While GL.TRANSFORM_FEEDBACK_BUFFER and GL.UNIFORM_BUFFER could
|
|
332
332
|
// be used as direct binding points, they will not affect transform feedback or
|
|
333
333
|
// uniform buffer state. Instead indexed bindings need to be made.
|
|
334
|
-
if (
|
|
334
|
+
if (glTarget === GL.UNIFORM_BUFFER || glTarget === GL.TRANSFORM_FEEDBACK_BUFFER) {
|
|
335
335
|
if (size !== undefined) {
|
|
336
|
-
this.gl2?.bindBufferRange(
|
|
336
|
+
this.gl2?.bindBufferRange(glTarget, index, this.handle, offset, size);
|
|
337
337
|
} else {
|
|
338
338
|
assert(offset === 0); // Make sure offset wasn't supplied
|
|
339
|
-
this.gl2?.bindBufferBase(
|
|
339
|
+
this.gl2?.bindBufferBase(glTarget, index, this.handle);
|
|
340
340
|
}
|
|
341
341
|
} else {
|
|
342
|
-
this.gl.bindBuffer(
|
|
342
|
+
this.gl.bindBuffer(glTarget, this.handle);
|
|
343
343
|
}
|
|
344
344
|
|
|
345
345
|
return this;
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
-
unbind(options?: {
|
|
349
|
-
const {
|
|
350
|
-
const isIndexedBuffer =
|
|
348
|
+
unbind(options?: {glTarget?: any; index?: any}): this {
|
|
349
|
+
const {glTarget = this.glTarget, index = this.accessor && this.accessor.index} = options || {};
|
|
350
|
+
const isIndexedBuffer = glTarget === GL.UNIFORM_BUFFER || glTarget === GL.TRANSFORM_FEEDBACK_BUFFER;
|
|
351
351
|
if (isIndexedBuffer) {
|
|
352
|
-
this.gl2?.bindBufferBase(
|
|
352
|
+
this.gl2?.bindBufferBase(glTarget, index, null);
|
|
353
353
|
} else {
|
|
354
|
-
this.gl.bindBuffer(
|
|
354
|
+
this.gl.bindBuffer(glTarget, null);
|
|
355
355
|
}
|
|
356
356
|
return this;
|
|
357
357
|
}
|
|
@@ -384,7 +384,7 @@ export class BufferWithAccessor extends WEBGLBuffer {
|
|
|
384
384
|
|
|
385
385
|
const target = this._getTarget();
|
|
386
386
|
this.gl.bindBuffer(target, this.handle);
|
|
387
|
-
this.gl.bufferData(target, byteLength, this.
|
|
387
|
+
this.gl.bufferData(target, byteLength, this.glUsage);
|
|
388
388
|
this.gl.bufferSubData(target, offset, data);
|
|
389
389
|
this.gl.bindBuffer(target, null);
|
|
390
390
|
|
|
@@ -401,7 +401,7 @@ export class BufferWithAccessor extends WEBGLBuffer {
|
|
|
401
401
|
}
|
|
402
402
|
|
|
403
403
|
// Allocate a GPU buffer of specified size.
|
|
404
|
-
_setByteLength(byteLength: number
|
|
404
|
+
_setByteLength(byteLength: number): this {
|
|
405
405
|
assert(byteLength >= 0);
|
|
406
406
|
|
|
407
407
|
this.trackDeallocatedMemory();
|
|
@@ -414,12 +414,11 @@ export class BufferWithAccessor extends WEBGLBuffer {
|
|
|
414
414
|
data = new Float32Array(0);
|
|
415
415
|
}
|
|
416
416
|
|
|
417
|
-
const
|
|
418
|
-
this.gl.bindBuffer(
|
|
419
|
-
this.gl.bufferData(
|
|
420
|
-
this.gl.bindBuffer(
|
|
417
|
+
const glTarget = this._getTarget();
|
|
418
|
+
this.gl.bindBuffer(glTarget, this.handle);
|
|
419
|
+
this.gl.bufferData(glTarget, data, this.glUsage);
|
|
420
|
+
this.gl.bindBuffer(glTarget, null);
|
|
421
421
|
|
|
422
|
-
this.webglUsage = webglUsage;
|
|
423
422
|
this.debugData = null;
|
|
424
423
|
this.bytesUsed = byteLength;
|
|
425
424
|
this.byteLength = byteLength;
|
|
@@ -433,7 +432,7 @@ export class BufferWithAccessor extends WEBGLBuffer {
|
|
|
433
432
|
// In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type
|
|
434
433
|
_getTarget() {
|
|
435
434
|
// @ts-expect-error
|
|
436
|
-
return this.gl.webgl2 ? GL.COPY_WRITE_BUFFER : this.
|
|
435
|
+
return this.gl.webgl2 ? GL.COPY_WRITE_BUFFER : this.glTarget;
|
|
437
436
|
}
|
|
438
437
|
|
|
439
438
|
_getAvailableElementCount(srcByteOffset: number) {
|
|
@@ -453,9 +452,9 @@ export class BufferWithAccessor extends WEBGLBuffer {
|
|
|
453
452
|
// RESOURCE METHODS
|
|
454
453
|
|
|
455
454
|
getParameter(pname: GL): any {
|
|
456
|
-
this.gl.bindBuffer(this.
|
|
457
|
-
const value = this.gl.getBufferParameter(this.
|
|
458
|
-
this.gl.bindBuffer(this.
|
|
455
|
+
this.gl.bindBuffer(this.glTarget, this.handle);
|
|
456
|
+
const value = this.gl.getBufferParameter(this.glTarget, pname);
|
|
457
|
+
this.gl.bindBuffer(this.glTarget, null);
|
|
459
458
|
return value;
|
|
460
459
|
}
|
|
461
460
|
|
|
@@ -121,8 +121,7 @@ export function readPixelsToBuffer(
|
|
|
121
121
|
target = new Buffer(gl2, {byteLength, accessor: {type: sourceType, size: components}});
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
target.bind({target: GL.PIXEL_PACK_BUFFER});
|
|
124
|
+
target.bind({glTarget: GL.PIXEL_PACK_BUFFER});
|
|
126
125
|
withParameters(gl2, {framebuffer}, () => {
|
|
127
126
|
gl2.readPixels(
|
|
128
127
|
sourceX,
|
|
@@ -134,7 +133,7 @@ export function readPixelsToBuffer(
|
|
|
134
133
|
targetByteOffset
|
|
135
134
|
);
|
|
136
135
|
});
|
|
137
|
-
target.unbind({
|
|
136
|
+
target.unbind({glTarget: GL.PIXEL_PACK_BUFFER});
|
|
138
137
|
if (deleteFramebuffer) {
|
|
139
138
|
framebuffer.destroy();
|
|
140
139
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// luma.gl, MIT license
|
|
2
2
|
import {log, loadScript} from '@luma.gl/api';
|
|
3
3
|
import {GL} from '@luma.gl/constants';
|
|
4
|
+
import {isBrowser} from '@probe.gl/env'
|
|
4
5
|
|
|
5
6
|
const WEBGL_DEBUG_CDN_URL = 'https://unpkg.com/webgl-debug@2.0.1/index.js';
|
|
6
7
|
|
|
@@ -18,8 +19,13 @@ type DebugContextProps = {
|
|
|
18
19
|
// webgl2: false,
|
|
19
20
|
// }
|
|
20
21
|
|
|
22
|
+
type ContextData = {
|
|
23
|
+
realContext?: WebGLRenderingContext;
|
|
24
|
+
debugContext?: WebGLRenderingContext;
|
|
25
|
+
}
|
|
26
|
+
|
|
21
27
|
// Helper to get shared context data
|
|
22
|
-
function getContextData(gl: any) {
|
|
28
|
+
function getContextData(gl: any): ContextData {
|
|
23
29
|
gl.luma = gl.luma || {};
|
|
24
30
|
return gl.luma;
|
|
25
31
|
}
|
|
@@ -36,7 +42,7 @@ declare global {
|
|
|
36
42
|
* @see https://github.com/vorg/webgl-debug
|
|
37
43
|
*/
|
|
38
44
|
export async function loadWebGLDeveloperTools(): Promise<void> {
|
|
39
|
-
if (!globalThis.WebGLDebugUtils) {
|
|
45
|
+
if (isBrowser() && !globalThis.WebGLDebugUtils) {
|
|
40
46
|
globalThis.global = globalThis.global || globalThis;
|
|
41
47
|
// @ts-expect-error Developer tools expects global to be set
|
|
42
48
|
globalThis.global.module = {};
|
|
@@ -116,9 +116,9 @@ const bindBuffer = (gl: WebGLRenderingContext, value: unknown, key: GL) => {
|
|
|
116
116
|
[GL.PIXEL_PACK_BUFFER_BINDING]: GL.PIXEL_PACK_BUFFER,
|
|
117
117
|
[GL.PIXEL_UNPACK_BUFFER_BINDING]: GL.PIXEL_UNPACK_BUFFER
|
|
118
118
|
};
|
|
119
|
-
const
|
|
119
|
+
const glTarget = bindingMap[key];
|
|
120
120
|
|
|
121
|
-
gl.bindBuffer(
|
|
121
|
+
gl.bindBuffer(glTarget, value);
|
|
122
122
|
};
|
|
123
123
|
|
|
124
124
|
// Utility
|
package/src/index.ts
CHANGED
|
@@ -73,7 +73,7 @@ export {
|
|
|
73
73
|
export {polyfillContext} from './context/polyfill/polyfill-context';
|
|
74
74
|
|
|
75
75
|
// HELPERS - EXPERIMENTAL
|
|
76
|
-
export {getShaderLayout,
|
|
76
|
+
export {getShaderLayout, mergeShaderLayout} from './adapter/helpers/get-shader-layout';
|
|
77
77
|
export {convertGLToTextureFormat, _checkFloat32ColorAttachment} from './adapter/converters/texture-formats';
|
|
78
78
|
|
|
79
79
|
// TEST EXPORTS
|