@luma.gl/webgl 9.0.0-beta.6 → 9.0.0-beta.8
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.d.ts.map +1 -1
- package/dist/adapter/converters/device-parameters.js +81 -84
- package/dist/adapter/converters/sampler-parameters.js +17 -17
- package/dist/adapter/converters/shader-formats.js +12 -12
- package/dist/adapter/converters/texture-formats.d.ts +10 -8
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +175 -168
- package/dist/adapter/converters/vertex-formats.js +20 -20
- package/dist/adapter/device-helpers/webgl-device-features.d.ts +2 -1
- package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-features.js +14 -2
- package/dist/adapter/device-helpers/webgl-device-info.js +5 -5
- package/dist/adapter/device-helpers/webgl-device-limits.js +10 -10
- package/dist/adapter/helpers/decode-webgl-types.js +45 -45
- package/dist/adapter/helpers/get-shader-layout.js +29 -29
- package/dist/adapter/helpers/set-uniform.js +40 -40
- package/dist/adapter/helpers/webgl-topology-utils.js +38 -38
- package/dist/adapter/objects/webgl-renderbuffer.js +6 -6
- package/dist/adapter/objects/webgl-resource.js +1 -2
- package/dist/adapter/resources/webgl-buffer.js +14 -14
- package/dist/adapter/resources/webgl-command-buffer.js +25 -25
- package/dist/adapter/resources/webgl-external-texture.js +3 -3
- package/dist/adapter/resources/webgl-framebuffer.d.ts +2 -4
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +41 -36
- package/dist/adapter/resources/webgl-query-set.js +6 -6
- package/dist/adapter/resources/webgl-render-pass.js +5 -5
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +19 -13
- package/dist/adapter/resources/webgl-sampler.js +2 -2
- package/dist/adapter/resources/webgl-shader.js +4 -4
- package/dist/adapter/resources/webgl-texture.d.ts +2 -1
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +29 -27
- package/dist/adapter/resources/webgl-transform-feedback.js +8 -8
- package/dist/adapter/resources/webgl-vertex-array.d.ts +1 -1
- package/dist/adapter/resources/webgl-vertex-array.js +5 -5
- package/dist/adapter/webgl-device.d.ts +6 -3
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +22 -17
- package/dist/classic/accessor.js +4 -4
- package/dist/classic/clear.js +2 -2
- package/dist/classic/copy-and-blit.js +15 -16
- package/dist/classic/format-utils.d.ts +2 -2
- package/dist/classic/format-utils.js +14 -14
- package/dist/classic/typed-array-utils.js +18 -18
- package/dist/context/parameters/unified-parameter-api.d.ts +3 -4
- package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
- package/dist/context/parameters/unified-parameter-api.js +4 -9
- package/dist/context/parameters/webgl-parameter-tables.d.ts +2 -13
- package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js +292 -298
- package/dist/context/state-tracker/with-parameters.d.ts +1 -2
- package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
- package/dist/context/state-tracker/with-parameters.js +2 -5
- package/dist/dist.dev.js +3796 -5522
- package/dist/dist.min.js +10 -0
- package/dist/index.cjs +1253 -1188
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +6 -7
- package/src/.DS_Store +0 -0
- package/src/adapter/.DS_Store +0 -0
- package/src/adapter/converters/device-parameters.ts +9 -11
- package/src/adapter/converters/texture-formats.ts +64 -61
- package/src/adapter/device-helpers/webgl-device-features.ts +22 -2
- package/src/adapter/objects/webgl-renderbuffer.ts +1 -1
- package/src/adapter/objects/webgl-resource.ts +1 -1
- package/src/adapter/resources/webgl-external-texture.ts +3 -3
- package/src/adapter/resources/webgl-framebuffer.ts +29 -26
- package/src/adapter/resources/webgl-render-pass.ts +3 -3
- package/src/adapter/resources/webgl-render-pipeline.ts +13 -6
- package/src/adapter/resources/webgl-texture.ts +7 -3
- package/src/adapter/webgl-device.ts +24 -19
- package/src/classic/clear.ts +2 -2
- package/src/context/.DS_Store +0 -0
- package/src/context/parameters/unified-parameter-api.ts +4 -16
- package/src/context/state-tracker/with-parameters.ts +2 -7
- package/src/index.ts +4 -4
- package/dist/adapter/device-helpers/device-features.d.ts +0 -6
- package/dist/adapter/device-helpers/device-features.d.ts.map +0 -1
- package/dist/adapter/device-helpers/device-features.js +0 -65
- package/dist/adapter/device-helpers/device-limits.d.ts +0 -50
- package/dist/adapter/device-helpers/device-limits.d.ts.map +0 -1
- package/dist/adapter/device-helpers/device-limits.js +0 -92
- package/dist/adapter/device-helpers/get-device-info.d.ts +0 -4
- package/dist/adapter/device-helpers/get-device-info.d.ts.map +0 -1
- package/dist/adapter/device-helpers/get-device-info.js +0 -87
- package/dist/context/context/context-data.d.ts +0 -14
- package/dist/context/context/context-data.d.ts.map +0 -1
- package/dist/context/context/context-data.js +0 -33
- package/dist/context/context/create-browser-context.d.ts +0 -35
- package/dist/context/context/create-browser-context.d.ts.map +0 -1
- package/dist/context/context/create-browser-context.js +0 -66
- package/dist.min.js +0 -19
|
@@ -23,12 +23,12 @@ export const DEFAULT_WEBGL_TEXTURE_PROPS = {
|
|
|
23
23
|
export class WEBGLTexture extends Texture {
|
|
24
24
|
// TODO - remove?
|
|
25
25
|
static FACES = [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
34069,
|
|
27
|
+
34070,
|
|
28
|
+
34071,
|
|
29
|
+
34072,
|
|
30
|
+
34073,
|
|
31
|
+
34074
|
|
32
32
|
];
|
|
33
33
|
MAX_ATTRIBUTES;
|
|
34
34
|
device;
|
|
@@ -66,7 +66,7 @@ export class WEBGLTexture extends Texture {
|
|
|
66
66
|
this.gl = this.device.gl;
|
|
67
67
|
this.handle = this.props.handle || this.gl.createTexture();
|
|
68
68
|
this.device.setSpectorMetadata(this.handle, { ...this.props, data: typeof this.props.data }); // {name: this.props.id};
|
|
69
|
-
this.glFormat =
|
|
69
|
+
this.glFormat = 6408;
|
|
70
70
|
this.target = getWebGLTextureTarget(this.props);
|
|
71
71
|
// Program.draw() checks the loaded flag of all textures
|
|
72
72
|
this.loaded = false;
|
|
@@ -89,6 +89,9 @@ export class WEBGLTexture extends Texture {
|
|
|
89
89
|
toString() {
|
|
90
90
|
return `Texture(${this.id},${this.width}x${this.height})`;
|
|
91
91
|
}
|
|
92
|
+
createView(props) {
|
|
93
|
+
return new WEBGLTextureView(this.device, { ...props, texture: this });
|
|
94
|
+
}
|
|
92
95
|
// eslint-disable-next-line max-statements
|
|
93
96
|
initialize(props = {}) {
|
|
94
97
|
// Cube textures
|
|
@@ -142,7 +145,7 @@ export class WEBGLTexture extends Texture {
|
|
|
142
145
|
this.dataFormat = dataFormat;
|
|
143
146
|
this.textureUnit = textureUnit;
|
|
144
147
|
if (Number.isFinite(this.textureUnit)) {
|
|
145
|
-
this.gl.activeTexture(
|
|
148
|
+
this.gl.activeTexture(33984 + this.textureUnit);
|
|
146
149
|
this.gl.bindTexture(this.target, this.handle);
|
|
147
150
|
}
|
|
148
151
|
this.mipmaps = mipmaps;
|
|
@@ -161,9 +164,8 @@ export class WEBGLTexture extends Texture {
|
|
|
161
164
|
// Set texture sampler parameters
|
|
162
165
|
this.setSampler(props.sampler);
|
|
163
166
|
this._setSamplerParameters(parameters);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (mipmaps) {
|
|
167
|
+
this.view = this.createView({ ...this.props, mipLevelCount: 1, arrayLayerCount: 1 });
|
|
168
|
+
if (mipmaps && this.device.isTextureFormatFilterable(props.format)) {
|
|
167
169
|
this.generateMipmap();
|
|
168
170
|
}
|
|
169
171
|
if (isVideo) {
|
|
@@ -309,9 +311,9 @@ export class WEBGLTexture extends Texture {
|
|
|
309
311
|
break;
|
|
310
312
|
case 'buffer':
|
|
311
313
|
// WebGL2 enables creating textures directly from a WebGL buffer
|
|
312
|
-
this.device.gl.bindBuffer(
|
|
314
|
+
this.device.gl.bindBuffer(35052, data.handle || data);
|
|
313
315
|
this.device.gl.texImage2D(target, level, glFormat, width, height, 0 /* border*/, dataFormat, type, offset);
|
|
314
|
-
this.device.gl.bindBuffer(
|
|
316
|
+
this.device.gl.bindBuffer(35052, null);
|
|
315
317
|
break;
|
|
316
318
|
case 'browser-object':
|
|
317
319
|
gl.texImage2D(target, level, glFormat, width, height, 0 /* border*/, dataFormat, type, data);
|
|
@@ -381,9 +383,9 @@ export class WEBGLTexture extends Texture {
|
|
|
381
383
|
else if (typeof WebGLBuffer !== 'undefined' && data instanceof WebGLBuffer) {
|
|
382
384
|
// WebGL2 allows us to create texture directly from a WebGL buffer
|
|
383
385
|
// This texImage2D signature uses currently bound GL.PIXEL_UNPACK_BUFFER
|
|
384
|
-
this.device.gl.bindBuffer(
|
|
386
|
+
this.device.gl.bindBuffer(35052, data);
|
|
385
387
|
this.device.gl.texSubImage2D(target, level, x, y, width, height, dataFormat, type, offset);
|
|
386
|
-
this.device.gl.bindBuffer(
|
|
388
|
+
this.device.gl.bindBuffer(35052, null);
|
|
387
389
|
}
|
|
388
390
|
else {
|
|
389
391
|
// Assume data is a browser supported object (ImageData, Canvas, ...)
|
|
@@ -405,13 +407,13 @@ export class WEBGLTexture extends Texture {
|
|
|
405
407
|
return null;
|
|
406
408
|
}
|
|
407
409
|
getActiveUnit() {
|
|
408
|
-
return this.gl.getParameter(
|
|
410
|
+
return this.gl.getParameter(34016) - 33984;
|
|
409
411
|
}
|
|
410
412
|
bind(textureUnit = this.textureUnit) {
|
|
411
413
|
const { gl } = this;
|
|
412
414
|
if (textureUnit !== undefined) {
|
|
413
415
|
this.textureUnit = textureUnit;
|
|
414
|
-
gl.activeTexture(
|
|
416
|
+
gl.activeTexture(33984 + textureUnit);
|
|
415
417
|
}
|
|
416
418
|
gl.bindTexture(this.target, this.handle);
|
|
417
419
|
return textureUnit;
|
|
@@ -420,7 +422,7 @@ export class WEBGLTexture extends Texture {
|
|
|
420
422
|
const { gl } = this;
|
|
421
423
|
if (textureUnit !== undefined) {
|
|
422
424
|
this.textureUnit = textureUnit;
|
|
423
|
-
gl.activeTexture(
|
|
425
|
+
gl.activeTexture(33984 + textureUnit);
|
|
424
426
|
}
|
|
425
427
|
gl.bindTexture(this.target, null);
|
|
426
428
|
return textureUnit;
|
|
@@ -491,7 +493,7 @@ export class WEBGLTexture extends Texture {
|
|
|
491
493
|
/* eslint-disable max-statements, max-len */
|
|
492
494
|
async setCubeMapImageData(options) {
|
|
493
495
|
const { gl } = this;
|
|
494
|
-
const { width, height, pixels, data, format =
|
|
496
|
+
const { width, height, pixels, data, format = 6408, type = 5121 } = options;
|
|
495
497
|
const imageDataMap = pixels || data;
|
|
496
498
|
// pixel data (imageDataMap) is an Object from Face to Image or Promise.
|
|
497
499
|
// For example:
|
|
@@ -530,7 +532,7 @@ export class WEBGLTexture extends Texture {
|
|
|
530
532
|
}
|
|
531
533
|
/** @todo update this method to accept LODs */
|
|
532
534
|
setImageDataForFace(options) {
|
|
533
|
-
const { face, width, height, pixels, data, format =
|
|
535
|
+
const { face, width, height, pixels, data, format = 6408, type = 5121
|
|
534
536
|
// generateMipmap = false // TODO
|
|
535
537
|
} = options;
|
|
536
538
|
const { gl } = this;
|
|
@@ -564,7 +566,7 @@ export class WEBGLTexture extends Texture {
|
|
|
564
566
|
data);
|
|
565
567
|
}
|
|
566
568
|
if (data instanceof WEBGLBuffer) {
|
|
567
|
-
this.gl.bindBuffer(
|
|
569
|
+
this.gl.bindBuffer(35052, data.handle);
|
|
568
570
|
this.gl.texImage3D(this.target, level, dataFormat, width, height, depth, 0 /* border, must be 0 */, format, type, offset);
|
|
569
571
|
}
|
|
570
572
|
});
|
|
@@ -595,8 +597,8 @@ export class WEBGLTexture extends Texture {
|
|
|
595
597
|
// Apparently there are integer/float conversion issues requires two parameter setting functions in JavaScript.
|
|
596
598
|
// For now, pick the float version for parameters specified as GLfloat.
|
|
597
599
|
switch (param) {
|
|
598
|
-
case
|
|
599
|
-
case
|
|
600
|
+
case 33082:
|
|
601
|
+
case 33083:
|
|
600
602
|
this.gl.texParameterf(this.target, param, value);
|
|
601
603
|
break;
|
|
602
604
|
default:
|
|
@@ -613,14 +615,14 @@ function getWebGLTextureTarget(props) {
|
|
|
613
615
|
switch (props.dimension) {
|
|
614
616
|
// supported in WebGL
|
|
615
617
|
case '2d':
|
|
616
|
-
return
|
|
618
|
+
return 3553;
|
|
617
619
|
case 'cube':
|
|
618
|
-
return
|
|
620
|
+
return 34067;
|
|
619
621
|
// supported in WebGL2
|
|
620
622
|
case '2d-array':
|
|
621
|
-
return
|
|
623
|
+
return 35866;
|
|
622
624
|
case '3d':
|
|
623
|
-
return
|
|
625
|
+
return 32879;
|
|
624
626
|
// not supported in any WebGL version
|
|
625
627
|
case '1d':
|
|
626
628
|
case 'cube-array':
|
|
@@ -37,7 +37,7 @@ export class WEBGLTransformFeedback extends TransformFeedback {
|
|
|
37
37
|
super.destroy();
|
|
38
38
|
}
|
|
39
39
|
begin(topology = 'point-list') {
|
|
40
|
-
this.gl.bindTransformFeedback(
|
|
40
|
+
this.gl.bindTransformFeedback(36386, this.handle);
|
|
41
41
|
if (this.bindOnUse) {
|
|
42
42
|
this._bindBuffers();
|
|
43
43
|
}
|
|
@@ -48,7 +48,7 @@ export class WEBGLTransformFeedback extends TransformFeedback {
|
|
|
48
48
|
if (!this.bindOnUse) {
|
|
49
49
|
this._unbindBuffers();
|
|
50
50
|
}
|
|
51
|
-
this.gl.bindTransformFeedback(
|
|
51
|
+
this.gl.bindTransformFeedback(36386, null);
|
|
52
52
|
}
|
|
53
53
|
// SUBCLASS
|
|
54
54
|
setBuffers(buffers) {
|
|
@@ -84,16 +84,16 @@ export class WEBGLTransformFeedback extends TransformFeedback {
|
|
|
84
84
|
}
|
|
85
85
|
bind(funcOrHandle = this.handle) {
|
|
86
86
|
if (typeof funcOrHandle !== 'function') {
|
|
87
|
-
this.gl.bindTransformFeedback(
|
|
87
|
+
this.gl.bindTransformFeedback(36386, funcOrHandle);
|
|
88
88
|
return this;
|
|
89
89
|
}
|
|
90
90
|
let value;
|
|
91
91
|
if (!this._bound) {
|
|
92
|
-
this.gl.bindTransformFeedback(
|
|
92
|
+
this.gl.bindTransformFeedback(36386, this.handle);
|
|
93
93
|
this._bound = true;
|
|
94
94
|
value = funcOrHandle();
|
|
95
95
|
this._bound = false;
|
|
96
|
-
this.gl.bindTransformFeedback(
|
|
96
|
+
this.gl.bindTransformFeedback(36386, null);
|
|
97
97
|
}
|
|
98
98
|
else {
|
|
99
99
|
value = funcOrHandle();
|
|
@@ -137,16 +137,16 @@ export class WEBGLTransformFeedback extends TransformFeedback {
|
|
|
137
137
|
}
|
|
138
138
|
_unbindBuffers() {
|
|
139
139
|
for (const bufferIndex in this.buffers) {
|
|
140
|
-
this.gl.bindBufferBase(
|
|
140
|
+
this.gl.bindBufferBase(35982, Number(bufferIndex), null);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
_bindBuffer(index, buffer, byteOffset = 0, byteLength) {
|
|
144
144
|
const handle = buffer && buffer.handle;
|
|
145
145
|
if (!handle || byteLength === undefined) {
|
|
146
|
-
this.gl.bindBufferBase(
|
|
146
|
+
this.gl.bindBufferBase(35982, index, handle);
|
|
147
147
|
}
|
|
148
148
|
else {
|
|
149
|
-
this.gl.bindBufferRange(
|
|
149
|
+
this.gl.bindBufferRange(35982, index, handle, byteOffset, byteLength);
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
}
|
|
@@ -41,7 +41,7 @@ export declare class WEBGLVertexArray extends VertexArray {
|
|
|
41
41
|
*/
|
|
42
42
|
/** Get an accessor from the */
|
|
43
43
|
protected _getAccessor(location: number): {
|
|
44
|
-
size: 1 | 2 | 3
|
|
44
|
+
size: 4 | 1 | 2 | 3;
|
|
45
45
|
type: GL.BYTE | GL.UNSIGNED_BYTE | GL.SHORT | GL.UNSIGNED_SHORT | GL.INT | GL.UNSIGNED_INT | GL.FLOAT | GL.HALF_FLOAT;
|
|
46
46
|
stride: number;
|
|
47
47
|
offset: number;
|
|
@@ -49,13 +49,13 @@ export class WEBGLVertexArray extends VertexArray {
|
|
|
49
49
|
setIndexBuffer(indexBuffer) {
|
|
50
50
|
const buffer = indexBuffer;
|
|
51
51
|
// Explicitly allow `null` to support clearing the index buffer
|
|
52
|
-
if (buffer && buffer.glTarget !==
|
|
52
|
+
if (buffer && buffer.glTarget !== 34963) {
|
|
53
53
|
throw new Error('Use .setBuffer()');
|
|
54
54
|
}
|
|
55
55
|
// In WebGL The GL.ELEMENT_ARRAY_BUFFER_BINDING is stored on the VertexArrayObject
|
|
56
56
|
this.device.gl.bindVertexArray(this.handle);
|
|
57
57
|
// TODO - this initial binding does not seem to take effect? see bindBeforeRender()
|
|
58
|
-
this.device.gl.bindBuffer(
|
|
58
|
+
this.device.gl.bindBuffer(34963, buffer ? buffer.handle : null);
|
|
59
59
|
// log.log(1, 'VertexArray.setIndexBuffer', indexBuffer)();
|
|
60
60
|
// log.log(1, `Binding vertex array ${this.id}`, buffer?.id)();
|
|
61
61
|
this.indexBuffer = buffer;
|
|
@@ -64,13 +64,13 @@ export class WEBGLVertexArray extends VertexArray {
|
|
|
64
64
|
setBuffer(location, attributeBuffer) {
|
|
65
65
|
const buffer = attributeBuffer;
|
|
66
66
|
// Sanity check target
|
|
67
|
-
if (buffer.glTarget ===
|
|
67
|
+
if (buffer.glTarget === 34963) {
|
|
68
68
|
throw new Error('Use .setIndexBuffer()');
|
|
69
69
|
}
|
|
70
70
|
const { size, type, stride, offset, normalized, integer, divisor } = this._getAccessor(location);
|
|
71
71
|
this.device.gl.bindVertexArray(this.handle);
|
|
72
72
|
// A non-zero buffer object must be bound to the GL_ARRAY_BUFFER target
|
|
73
|
-
this.device.gl.bindBuffer(
|
|
73
|
+
this.device.gl.bindBuffer(34962, buffer.handle);
|
|
74
74
|
// WebGL2 supports *integer* data formats, i.e. GPU will see integer values
|
|
75
75
|
if (integer) {
|
|
76
76
|
this.device.gl.vertexAttribIPointer(location, size, type, stride, offset);
|
|
@@ -97,7 +97,7 @@ export class WEBGLVertexArray extends VertexArray {
|
|
|
97
97
|
if (!this.init) {
|
|
98
98
|
// log.log(1, `Binding vertex array ${this.id}`, this.indexBuffer?.id)();
|
|
99
99
|
const webglBuffer = this.indexBuffer;
|
|
100
|
-
this.device.gl.bindBuffer(
|
|
100
|
+
this.device.gl.bindBuffer(34963, webglBuffer?.handle || null);
|
|
101
101
|
this.init = true;
|
|
102
102
|
}
|
|
103
103
|
this._applyConstantAttributes();
|
|
@@ -17,8 +17,10 @@ import { WEBGLTransformFeedback } from "./resources/webgl-transform-feedback.js"
|
|
|
17
17
|
import { WEBGLQuerySet } from "./resources/webgl-query-set.js";
|
|
18
18
|
/** WebGPU style Device API for a WebGL context */
|
|
19
19
|
export declare class WebGLDevice extends Device {
|
|
20
|
-
|
|
21
|
-
static
|
|
20
|
+
/** type of this device */
|
|
21
|
+
static readonly type: string;
|
|
22
|
+
/** type of this device */
|
|
23
|
+
readonly type = "webgl";
|
|
22
24
|
/** The underlying WebGL context */
|
|
23
25
|
readonly handle: WebGL2RenderingContext;
|
|
24
26
|
features: WebGLDeviceFeatures;
|
|
@@ -30,6 +32,8 @@ export declare class WebGLDevice extends Device {
|
|
|
30
32
|
message: string;
|
|
31
33
|
}>;
|
|
32
34
|
private _resolveContextLost?;
|
|
35
|
+
/** Check if WebGL 2 is available */
|
|
36
|
+
static isSupported(): boolean;
|
|
33
37
|
/**
|
|
34
38
|
* Get a device instance from a GL context
|
|
35
39
|
* Creates and instruments the device if not already created
|
|
@@ -64,7 +68,6 @@ export declare class WebGLDevice extends Device {
|
|
|
64
68
|
createComputePipeline(props?: ComputePipelineProps): ComputePipeline;
|
|
65
69
|
beginComputePass(props: ComputePassProps): ComputePass;
|
|
66
70
|
private renderPass;
|
|
67
|
-
getDefaultRenderPass(): WEBGLRenderPass;
|
|
68
71
|
createCommandEncoder(props?: CommandEncoderProps): WEBGLCommandEncoder;
|
|
69
72
|
/**
|
|
70
73
|
* Offscreen Canvas Support: Commit the frame
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgl-device.d.ts","sourceRoot":"","sources":["../../src/adapter/webgl-device.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,MAAM,EACN,OAAO,EACP,UAAU,EACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,MAAM,EAAE,aAAa,EAAmB,MAAM,eAAe,CAAC;AACtE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAQrD,OAAO,EAAC,mBAAmB,EAAC,kDAA+C;AAC3E,OAAO,EAAC,iBAAiB,EAAC,gDAA6C;AACvE,OAAO,EAAC,kBAAkB,EAAC,kCAA+B;AAU1D,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EAEX,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAEhB,mBAAmB,EACnB,eAAe,EACf,oBAAoB,EAEpB,eAAe,EACf,WAAW,EACX,gBAAgB,EAEhB,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACd,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAC,WAAW,EAAC,oCAAiC;AACrD,OAAO,EAAC,WAAW,EAAC,oCAAiC;AACrD,OAAO,EAAC,YAAY,EAAC,qCAAkC;AACvD,OAAO,EAAC,YAAY,EAAC,qCAAkC;AACvD,OAAO,EAAC,gBAAgB,EAAC,yCAAsC;AAC/D,OAAO,EAAC,eAAe,EAAC,yCAAsC;AAC9D,OAAO,EAAC,mBAAmB,EAAC,6CAA0C;AACtE,O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C;IAC9C,QAAQ,IAAI,IAAI;IAIhB;;;OAGG;IACH,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAMlE;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,sBAAsB,GAAG,MAAM;IAc7D,sBAAsB;IACtB,UAAU,EAAE,CAAC,UAAU,GAAG,IAAI,CAAC,EAAE,CAAC;IAElC;;;;;OAKG;IACH,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,GAAG,IAAI;IA2BvE,gDAAgD;IAChD,YAAY,CAAC,IAAI,EAAE,MAAM,YAAY,GAAG,YAAY;CAIrD"}
|
|
@@ -33,10 +33,10 @@ export class WebGLDevice extends Device {
|
|
|
33
33
|
//
|
|
34
34
|
// Public `Device` API
|
|
35
35
|
//
|
|
36
|
+
/** type of this device */
|
|
36
37
|
static type = 'webgl';
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
38
|
+
/** type of this device */
|
|
39
|
+
type = 'webgl';
|
|
40
40
|
/** The underlying WebGL context */
|
|
41
41
|
handle;
|
|
42
42
|
features;
|
|
@@ -48,6 +48,10 @@ export class WebGLDevice extends Device {
|
|
|
48
48
|
//
|
|
49
49
|
// Static methods, expected to be present by `luma.createDevice()`
|
|
50
50
|
//
|
|
51
|
+
/** Check if WebGL 2 is available */
|
|
52
|
+
static isSupported() {
|
|
53
|
+
return typeof WebGL2RenderingContext !== 'undefined';
|
|
54
|
+
}
|
|
51
55
|
/**
|
|
52
56
|
* Get a device instance from a GL context
|
|
53
57
|
* Creates and instruments the device if not already created
|
|
@@ -85,16 +89,22 @@ export class WebGLDevice extends Device {
|
|
|
85
89
|
}
|
|
86
90
|
// Wait for all the loads to settle before creating the context.
|
|
87
91
|
// The Device.create() functions are async, so in contrast to the constructor, we can `await` here.
|
|
88
|
-
await Promise.
|
|
92
|
+
const results = await Promise.allSettled(promises);
|
|
93
|
+
for (const result of results) {
|
|
94
|
+
if (result.status === 'rejected') {
|
|
95
|
+
log.error(`Failed to initialize debug libraries ${result.reason}`)();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
89
98
|
log.probe(LOG_LEVEL + 1, 'DOM is loaded')();
|
|
90
99
|
// @ts-expect-error
|
|
91
100
|
if (props.gl?.device) {
|
|
101
|
+
log.warn('reattaching existing device')();
|
|
92
102
|
return WebGLDevice.attach(props.gl);
|
|
93
103
|
}
|
|
94
104
|
const device = new WebGLDevice(props);
|
|
95
105
|
// Log some debug info about the newly created context
|
|
96
106
|
const message = `\
|
|
97
|
-
Created ${device.
|
|
107
|
+
Created ${device.type}${device.debug ? ' debug' : ''} context: \
|
|
98
108
|
${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
99
109
|
log.probe(LOG_LEVEL, message)();
|
|
100
110
|
log.table(LOG_LEVEL, device.info)();
|
|
@@ -135,8 +145,11 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
135
145
|
this.gl._version = 2; // Update GL context: Store WebGL version field on gl context (HACK to identify debug contexts)
|
|
136
146
|
// luma Device fields
|
|
137
147
|
this.info = getDeviceInfo(this.gl, this._extensions);
|
|
138
|
-
this.features = new WebGLDeviceFeatures(this.gl, this._extensions);
|
|
139
148
|
this.limits = new WebGLDeviceLimits(this.gl);
|
|
149
|
+
this.features = new WebGLDeviceFeatures(this.gl, this._extensions, this.props.disabledFeatures);
|
|
150
|
+
if (this.props.initalizeFeatures) {
|
|
151
|
+
this.features.initializeFeatures();
|
|
152
|
+
}
|
|
140
153
|
this.canvasContext.resize();
|
|
141
154
|
// Install context state tracking
|
|
142
155
|
// @ts-expect-error - hidden parameters
|
|
@@ -222,14 +235,6 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
222
235
|
throw new Error('ComputePass not supported in WebGL');
|
|
223
236
|
}
|
|
224
237
|
renderPass = null;
|
|
225
|
-
getDefaultRenderPass() {
|
|
226
|
-
this.renderPass =
|
|
227
|
-
this.renderPass ||
|
|
228
|
-
this.beginRenderPass({
|
|
229
|
-
framebuffer: this.canvasContext.getCurrentFramebuffer()
|
|
230
|
-
});
|
|
231
|
-
return this.renderPass;
|
|
232
|
-
}
|
|
233
238
|
createCommandEncoder(props) {
|
|
234
239
|
return new WEBGLCommandEncoder(this, props);
|
|
235
240
|
}
|
|
@@ -255,13 +260,13 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
|
|
|
255
260
|
return readPixelsToBuffer(source, options);
|
|
256
261
|
}
|
|
257
262
|
setParametersWebGL(parameters) {
|
|
258
|
-
setGLParameters(this, parameters);
|
|
263
|
+
setGLParameters(this.gl, parameters);
|
|
259
264
|
}
|
|
260
265
|
getParametersWebGL(parameters) {
|
|
261
|
-
return getGLParameters(this, parameters);
|
|
266
|
+
return getGLParameters(this.gl, parameters);
|
|
262
267
|
}
|
|
263
268
|
withParametersWebGL(parameters, func) {
|
|
264
|
-
withGLParameters(this, parameters, func);
|
|
269
|
+
withGLParameters(this.gl, parameters, func);
|
|
265
270
|
}
|
|
266
271
|
clearWebGL(options) {
|
|
267
272
|
clear(this, options);
|
package/dist/classic/accessor.js
CHANGED
|
@@ -7,7 +7,7 @@ import { getTypedArrayFromGLType } from "./typed-array-utils.js";
|
|
|
7
7
|
const DEFAULT_ACCESSOR_VALUES = {
|
|
8
8
|
offset: 0,
|
|
9
9
|
stride: 0,
|
|
10
|
-
type:
|
|
10
|
+
type: 5126,
|
|
11
11
|
size: 1,
|
|
12
12
|
divisor: 0,
|
|
13
13
|
normalized: false,
|
|
@@ -32,14 +32,14 @@ export class Accessor {
|
|
|
32
32
|
static getBytesPerElement(accessor) {
|
|
33
33
|
// TODO: using `FLOAT` when type is not specified,
|
|
34
34
|
// ensure this assumption is valid or force API to specify type.
|
|
35
|
-
const ArrayType = getTypedArrayFromGLType(accessor.type ||
|
|
35
|
+
const ArrayType = getTypedArrayFromGLType(accessor.type || 5126);
|
|
36
36
|
return ArrayType.BYTES_PER_ELEMENT;
|
|
37
37
|
}
|
|
38
38
|
static getBytesPerVertex(accessor) {
|
|
39
39
|
assert(accessor.size);
|
|
40
40
|
// TODO: using `FLOAT` when type is not specified,
|
|
41
41
|
// ensure this assumption is valid or force API to specify type.
|
|
42
|
-
const ArrayType = getTypedArrayFromGLType(accessor.type ||
|
|
42
|
+
const ArrayType = getTypedArrayFromGLType(accessor.type || 5126);
|
|
43
43
|
return ArrayType.BYTES_PER_ELEMENT * accessor.size;
|
|
44
44
|
}
|
|
45
45
|
// Combines (merges) a list of accessors. On top of default values
|
|
@@ -71,7 +71,7 @@ export class Accessor {
|
|
|
71
71
|
if (props.type !== undefined) {
|
|
72
72
|
this.type = props.type;
|
|
73
73
|
// Auto-deduce integer type?
|
|
74
|
-
if (props.type ===
|
|
74
|
+
if (props.type === 5124 || props.type === 5125) {
|
|
75
75
|
this.integer = true;
|
|
76
76
|
}
|
|
77
77
|
}
|
package/dist/classic/clear.js
CHANGED
|
@@ -44,8 +44,8 @@ export function clear(device, options) {
|
|
|
44
44
|
}
|
|
45
45
|
assert(clearFlags !== 0, ERR_ARGUMENTS);
|
|
46
46
|
// Temporarily set any clear "colors" and call clear
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
const gl = device.gl;
|
|
48
|
+
withGLParameters(gl, parameters, () => {
|
|
49
49
|
gl.clear(clearFlags);
|
|
50
50
|
});
|
|
51
51
|
}
|
|
@@ -17,7 +17,7 @@ import { glFormatToComponents, glTypeToBytes } from "./format-utils.js";
|
|
|
17
17
|
* @returns pixel array,
|
|
18
18
|
*/
|
|
19
19
|
export function readPixelsToArray(source, options) {
|
|
20
|
-
const { sourceX = 0, sourceY = 0, sourceFormat =
|
|
20
|
+
const { sourceX = 0, sourceY = 0, sourceFormat = 6408, sourceAttachment = 36064 // TODO - support gl.readBuffer
|
|
21
21
|
} = options || {};
|
|
22
22
|
let { target = null,
|
|
23
23
|
// following parameters are auto deduced if not provided
|
|
@@ -31,21 +31,20 @@ export function readPixelsToArray(source, options) {
|
|
|
31
31
|
// if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {
|
|
32
32
|
// sourceAttachment = GL.FRONT;
|
|
33
33
|
// }
|
|
34
|
-
const attachment = sourceAttachment -
|
|
34
|
+
const attachment = sourceAttachment - 36064;
|
|
35
35
|
// assert(attachments[sourceAttachment]);
|
|
36
36
|
// Deduce the type from color attachment if not provided.
|
|
37
37
|
sourceType =
|
|
38
38
|
sourceType ||
|
|
39
|
-
framebuffer.colorAttachments[attachment]?.texture?.type ||
|
|
40
|
-
GL.UNSIGNED_BYTE;
|
|
39
|
+
framebuffer.colorAttachments[attachment]?.texture?.type || 5121;
|
|
41
40
|
// Deduce type and allocated pixelArray if needed
|
|
42
41
|
target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
|
|
43
42
|
// Pixel array available, if necessary, deduce type from it.
|
|
44
43
|
sourceType = sourceType || getGLTypeFromTypedArray(target);
|
|
45
|
-
const prevHandle = gl.bindFramebuffer(
|
|
44
|
+
const prevHandle = gl.bindFramebuffer(36160, handle);
|
|
46
45
|
gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
|
|
47
46
|
// @ts-expect-error
|
|
48
|
-
gl.bindFramebuffer(
|
|
47
|
+
gl.bindFramebuffer(36160, prevHandle || null);
|
|
49
48
|
if (deleteFramebuffer) {
|
|
50
49
|
framebuffer.destroy();
|
|
51
50
|
}
|
|
@@ -59,7 +58,7 @@ export function readPixelsToArray(source, options) {
|
|
|
59
58
|
* @param options
|
|
60
59
|
*/
|
|
61
60
|
export function readPixelsToBuffer(source, options) {
|
|
62
|
-
const { target, sourceX = 0, sourceY = 0, sourceFormat =
|
|
61
|
+
const { target, sourceX = 0, sourceY = 0, sourceFormat = 6408, targetByteOffset = 0 } = options || {};
|
|
63
62
|
// following parameters are auto deduced if not provided
|
|
64
63
|
let { sourceWidth, sourceHeight, sourceType } = options || {};
|
|
65
64
|
const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
|
|
@@ -69,7 +68,7 @@ export function readPixelsToBuffer(source, options) {
|
|
|
69
68
|
// Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature
|
|
70
69
|
const webglFramebuffer = framebuffer;
|
|
71
70
|
// deduce type if not available.
|
|
72
|
-
sourceType = sourceType ||
|
|
71
|
+
sourceType = sourceType || 5121;
|
|
73
72
|
let webglBufferTarget = target;
|
|
74
73
|
if (!webglBufferTarget) {
|
|
75
74
|
// Create new buffer with enough size
|
|
@@ -102,7 +101,7 @@ export function readPixelsToBuffer(source, options) {
|
|
|
102
101
|
export function copyToTexture(source, target, options) {
|
|
103
102
|
const { sourceX = 0, sourceY = 0,
|
|
104
103
|
// attachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
|
|
105
|
-
targetMipmaplevel = 0, targetInternalFormat =
|
|
104
|
+
targetMipmaplevel = 0, targetInternalFormat = 6408 } = options || {};
|
|
106
105
|
let { targetX, targetY, targetZ, width, // defaults to target width
|
|
107
106
|
height // defaults to target height
|
|
108
107
|
} = options || {};
|
|
@@ -116,7 +115,7 @@ export function copyToTexture(source, target, options) {
|
|
|
116
115
|
targetX = targetX || 0;
|
|
117
116
|
targetY = targetY || 0;
|
|
118
117
|
targetZ = targetZ || 0;
|
|
119
|
-
const prevHandle = device.gl.bindFramebuffer(
|
|
118
|
+
const prevHandle = device.gl.bindFramebuffer(36160, handle);
|
|
120
119
|
// TODO - support gl.readBuffer (WebGL2 only)
|
|
121
120
|
// const prevBuffer = gl.readBuffer(attachment);
|
|
122
121
|
assert(target);
|
|
@@ -137,12 +136,12 @@ export function copyToTexture(source, target, options) {
|
|
|
137
136
|
}
|
|
138
137
|
else {
|
|
139
138
|
switch (textureTarget) {
|
|
140
|
-
case
|
|
141
|
-
case
|
|
139
|
+
case 3553:
|
|
140
|
+
case 34067:
|
|
142
141
|
device.gl.copyTexSubImage2D(textureTarget, targetMipmaplevel, targetX, targetY, sourceX, sourceY, width, height);
|
|
143
142
|
break;
|
|
144
|
-
case
|
|
145
|
-
case
|
|
143
|
+
case 35866:
|
|
144
|
+
case 32879:
|
|
146
145
|
device.gl.copyTexSubImage3D(textureTarget, targetMipmaplevel, targetX, targetY, targetZ, sourceX, sourceY, width, height);
|
|
147
146
|
break;
|
|
148
147
|
default:
|
|
@@ -152,7 +151,7 @@ export function copyToTexture(source, target, options) {
|
|
|
152
151
|
texture.unbind();
|
|
153
152
|
}
|
|
154
153
|
// @ts-expect-error
|
|
155
|
-
device.gl.bindFramebuffer(
|
|
154
|
+
device.gl.bindFramebuffer(36160, prevHandle || null);
|
|
156
155
|
if (deleteFramebuffer) {
|
|
157
156
|
framebuffer.destroy();
|
|
158
157
|
}
|
|
@@ -184,7 +183,7 @@ function getPixelArray(pixelArray, type, format, width, height) {
|
|
|
184
183
|
return pixelArray;
|
|
185
184
|
}
|
|
186
185
|
// Allocate pixel array if not already available, using supplied type
|
|
187
|
-
type = type ||
|
|
186
|
+
type = type || 5121;
|
|
188
187
|
const ArrayType = getTypedArrayFromGLType(type, { clamped: false });
|
|
189
188
|
const components = glFormatToComponents(format);
|
|
190
189
|
// TODO - check for composite type (components = 1).
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function glFormatToComponents(format: any):
|
|
2
|
-
export declare function glTypeToBytes(type: any):
|
|
1
|
+
export declare function glFormatToComponents(format: any): 0 | 1 | 4 | 2 | 3;
|
|
2
|
+
export declare function glTypeToBytes(type: any): 0 | 1 | 4 | 2;
|
|
3
3
|
//# sourceMappingURL=format-utils.d.ts.map
|
|
@@ -6,18 +6,18 @@ import { GL } from '@luma.gl/constants';
|
|
|
6
6
|
// Returns number of components in a specific readPixels WebGL format
|
|
7
7
|
export function glFormatToComponents(format) {
|
|
8
8
|
switch (format) {
|
|
9
|
-
case
|
|
10
|
-
case
|
|
11
|
-
case
|
|
9
|
+
case 6406:
|
|
10
|
+
case 33326:
|
|
11
|
+
case 6403:
|
|
12
12
|
return 1;
|
|
13
|
-
case
|
|
14
|
-
case
|
|
13
|
+
case 33328:
|
|
14
|
+
case 33319:
|
|
15
15
|
return 2;
|
|
16
|
-
case
|
|
17
|
-
case
|
|
16
|
+
case 6407:
|
|
17
|
+
case 34837:
|
|
18
18
|
return 3;
|
|
19
|
-
case
|
|
20
|
-
case
|
|
19
|
+
case 6408:
|
|
20
|
+
case 34836:
|
|
21
21
|
return 4;
|
|
22
22
|
// TODO: Add support for additional WebGL2 formats
|
|
23
23
|
default:
|
|
@@ -28,13 +28,13 @@ export function glFormatToComponents(format) {
|
|
|
28
28
|
// Return byte count for given readPixels WebGL type
|
|
29
29
|
export function glTypeToBytes(type) {
|
|
30
30
|
switch (type) {
|
|
31
|
-
case
|
|
31
|
+
case 5121:
|
|
32
32
|
return 1;
|
|
33
|
-
case
|
|
34
|
-
case
|
|
35
|
-
case
|
|
33
|
+
case 33635:
|
|
34
|
+
case 32819:
|
|
35
|
+
case 32820:
|
|
36
36
|
return 2;
|
|
37
|
-
case
|
|
37
|
+
case 5126:
|
|
38
38
|
return 4;
|
|
39
39
|
// TODO: Add support for additional WebGL2 types
|
|
40
40
|
default:
|