@luma.gl/webgl 9.0.0-alpha.25 → 9.0.0-alpha.27
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/objects/webgl-vertex-array-object.d.ts +35 -8
- package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-vertex-array-object.js +114 -14
- package/dist/adapter/objects/webgl-vertex-array-object.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +12 -2
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +10 -0
- package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +1 -0
- package/dist/adapter/webgl-canvas-context.js.map +1 -1
- package/dist/classic/copy-and-blit.d.ts +17 -0
- package/dist/classic/copy-and-blit.d.ts.map +1 -1
- package/dist/classic/copy-and-blit.js +67 -1
- package/dist/classic/copy-and-blit.js.map +1 -1
- package/dist/dist.dev.js +841 -586
- package/dist/index.cjs +792 -573
- 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/objects/webgl-vertex-array-object.ts +190 -26
- package/src/adapter/resources/webgl-render-pipeline.ts +23 -2
- package/src/adapter/webgl-canvas-context.ts +2 -1
- package/src/classic/copy-and-blit.ts +120 -0
- package/src/index.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -78,6 +78,7 @@ __export(src_exports, {
|
|
|
78
78
|
assertWebGLContext: () => assertWebGLContext,
|
|
79
79
|
clear: () => clear,
|
|
80
80
|
convertGLToTextureFormat: () => convertGLToTextureFormat,
|
|
81
|
+
copyToTexture: () => copyToTexture,
|
|
81
82
|
getParameters: () => getParameters,
|
|
82
83
|
getProgramBindings: () => getProgramBindings,
|
|
83
84
|
getShaderLayout: () => getShaderLayout,
|
|
@@ -124,11 +125,11 @@ function createHeadlessContext(options) {
|
|
|
124
125
|
if (!headlessGL) {
|
|
125
126
|
throw new Error(ERR_HEADLESSGL_LOAD);
|
|
126
127
|
}
|
|
127
|
-
const
|
|
128
|
-
if (!
|
|
128
|
+
const gl2 = headlessGL(width, height, options);
|
|
129
|
+
if (!gl2) {
|
|
129
130
|
throw new Error(ERR_HEADLESSGL_FAILED);
|
|
130
131
|
}
|
|
131
|
-
return
|
|
132
|
+
return gl2;
|
|
132
133
|
}
|
|
133
134
|
|
|
134
135
|
// src/adapter/webgl-device.ts
|
|
@@ -156,43 +157,43 @@ function synthesizeGLError(err, opt_msg) {
|
|
|
156
157
|
error(opt_msg);
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
|
-
function wrapGLError(
|
|
160
|
-
const f =
|
|
161
|
-
|
|
160
|
+
function wrapGLError(gl2) {
|
|
161
|
+
const f = gl2.getError;
|
|
162
|
+
gl2.getError = function getError() {
|
|
162
163
|
let err;
|
|
163
164
|
do {
|
|
164
|
-
err = f.apply(
|
|
165
|
-
if (err !==
|
|
165
|
+
err = f.apply(gl2);
|
|
166
|
+
if (err !== gl2.NO_ERROR) {
|
|
166
167
|
glErrorShadow[err] = true;
|
|
167
168
|
}
|
|
168
|
-
} while (err !==
|
|
169
|
+
} while (err !== gl2.NO_ERROR);
|
|
169
170
|
for (err in glErrorShadow) {
|
|
170
171
|
if (glErrorShadow[err]) {
|
|
171
172
|
delete glErrorShadow[err];
|
|
172
173
|
return parseInt(err, 10);
|
|
173
174
|
}
|
|
174
175
|
}
|
|
175
|
-
return
|
|
176
|
+
return gl2.NO_ERROR;
|
|
176
177
|
};
|
|
177
178
|
}
|
|
178
179
|
var WebGLVertexArrayObjectOES = function WebGLVertexArrayObjectOES2(ext) {
|
|
179
|
-
const
|
|
180
|
+
const gl2 = ext.gl;
|
|
180
181
|
this.ext = ext;
|
|
181
182
|
this.isAlive = true;
|
|
182
183
|
this.hasBeenBound = false;
|
|
183
184
|
this.elementArrayBuffer = null;
|
|
184
185
|
this.attribs = new Array(ext.maxVertexAttribs);
|
|
185
186
|
for (let n = 0; n < this.attribs.length; n++) {
|
|
186
|
-
const attrib = new WebGLVertexArrayObjectOES2.VertexAttrib(
|
|
187
|
+
const attrib = new WebGLVertexArrayObjectOES2.VertexAttrib(gl2);
|
|
187
188
|
this.attribs[n] = attrib;
|
|
188
189
|
}
|
|
189
190
|
this.maxAttrib = 0;
|
|
190
191
|
};
|
|
191
|
-
WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(
|
|
192
|
+
WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl2) {
|
|
192
193
|
this.enabled = false;
|
|
193
194
|
this.buffer = null;
|
|
194
195
|
this.size = 4;
|
|
195
|
-
this.type =
|
|
196
|
+
this.type = gl2.FLOAT;
|
|
196
197
|
this.normalized = false;
|
|
197
198
|
this.stride = 16;
|
|
198
199
|
this.offset = 0;
|
|
@@ -202,19 +203,19 @@ WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl) {
|
|
|
202
203
|
WebGLVertexArrayObjectOES.VertexAttrib.prototype.recache = function recache() {
|
|
203
204
|
this.cached = [this.size, this.type, this.normalized, this.stride, this.offset].join(":");
|
|
204
205
|
};
|
|
205
|
-
var OESVertexArrayObject = function OESVertexArrayObject2(
|
|
206
|
+
var OESVertexArrayObject = function OESVertexArrayObject2(gl2) {
|
|
206
207
|
const self = this;
|
|
207
|
-
this.gl =
|
|
208
|
-
wrapGLError(
|
|
208
|
+
this.gl = gl2;
|
|
209
|
+
wrapGLError(gl2);
|
|
209
210
|
const original = this.original = {
|
|
210
|
-
getParameter:
|
|
211
|
-
enableVertexAttribArray:
|
|
212
|
-
disableVertexAttribArray:
|
|
213
|
-
bindBuffer:
|
|
214
|
-
getVertexAttrib:
|
|
215
|
-
vertexAttribPointer:
|
|
211
|
+
getParameter: gl2.getParameter,
|
|
212
|
+
enableVertexAttribArray: gl2.enableVertexAttribArray,
|
|
213
|
+
disableVertexAttribArray: gl2.disableVertexAttribArray,
|
|
214
|
+
bindBuffer: gl2.bindBuffer,
|
|
215
|
+
getVertexAttrib: gl2.getVertexAttrib,
|
|
216
|
+
vertexAttribPointer: gl2.vertexAttribPointer
|
|
216
217
|
};
|
|
217
|
-
|
|
218
|
+
gl2.getParameter = function getParameter(pname) {
|
|
218
219
|
if (pname === self.VERTEX_ARRAY_BINDING_OES) {
|
|
219
220
|
if (self.currentVertexArrayObject === self.defaultVertexArrayObject) {
|
|
220
221
|
return null;
|
|
@@ -223,53 +224,53 @@ var OESVertexArrayObject = function OESVertexArrayObject2(gl) {
|
|
|
223
224
|
}
|
|
224
225
|
return original.getParameter.apply(this, arguments);
|
|
225
226
|
};
|
|
226
|
-
|
|
227
|
+
gl2.enableVertexAttribArray = function enableVertexAttribArray(index) {
|
|
227
228
|
const vao = self.currentVertexArrayObject;
|
|
228
229
|
vao.maxAttrib = Math.max(vao.maxAttrib, index);
|
|
229
230
|
const attrib = vao.attribs[index];
|
|
230
231
|
attrib.enabled = true;
|
|
231
232
|
return original.enableVertexAttribArray.apply(this, arguments);
|
|
232
233
|
};
|
|
233
|
-
|
|
234
|
+
gl2.disableVertexAttribArray = function disableVertexAttribArray(index) {
|
|
234
235
|
const vao = self.currentVertexArrayObject;
|
|
235
236
|
vao.maxAttrib = Math.max(vao.maxAttrib, index);
|
|
236
237
|
const attrib = vao.attribs[index];
|
|
237
238
|
attrib.enabled = false;
|
|
238
239
|
return original.disableVertexAttribArray.apply(this, arguments);
|
|
239
240
|
};
|
|
240
|
-
|
|
241
|
+
gl2.bindBuffer = function bindBuffer2(target, buffer) {
|
|
241
242
|
switch (target) {
|
|
242
|
-
case
|
|
243
|
+
case gl2.ARRAY_BUFFER:
|
|
243
244
|
self.currentArrayBuffer = buffer;
|
|
244
245
|
break;
|
|
245
|
-
case
|
|
246
|
+
case gl2.ELEMENT_ARRAY_BUFFER:
|
|
246
247
|
self.currentVertexArrayObject.elementArrayBuffer = buffer;
|
|
247
248
|
break;
|
|
248
249
|
default:
|
|
249
250
|
}
|
|
250
251
|
return original.bindBuffer.apply(this, arguments);
|
|
251
252
|
};
|
|
252
|
-
|
|
253
|
+
gl2.getVertexAttrib = function getVertexAttrib(index, pname) {
|
|
253
254
|
const vao = self.currentVertexArrayObject;
|
|
254
255
|
const attrib = vao.attribs[index];
|
|
255
256
|
switch (pname) {
|
|
256
|
-
case
|
|
257
|
+
case gl2.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
|
|
257
258
|
return attrib.buffer;
|
|
258
|
-
case
|
|
259
|
+
case gl2.VERTEX_ATTRIB_ARRAY_ENABLED:
|
|
259
260
|
return attrib.enabled;
|
|
260
|
-
case
|
|
261
|
+
case gl2.VERTEX_ATTRIB_ARRAY_SIZE:
|
|
261
262
|
return attrib.size;
|
|
262
|
-
case
|
|
263
|
+
case gl2.VERTEX_ATTRIB_ARRAY_STRIDE:
|
|
263
264
|
return attrib.stride;
|
|
264
|
-
case
|
|
265
|
+
case gl2.VERTEX_ATTRIB_ARRAY_TYPE:
|
|
265
266
|
return attrib.type;
|
|
266
|
-
case
|
|
267
|
+
case gl2.VERTEX_ATTRIB_ARRAY_NORMALIZED:
|
|
267
268
|
return attrib.normalized;
|
|
268
269
|
default:
|
|
269
270
|
return original.getVertexAttrib.apply(this, arguments);
|
|
270
271
|
}
|
|
271
272
|
};
|
|
272
|
-
|
|
273
|
+
gl2.vertexAttribPointer = function vertexAttribPointer(indx, size, type, normalized, stride, offset) {
|
|
273
274
|
const vao = self.currentVertexArrayObject;
|
|
274
275
|
vao.maxAttrib = Math.max(vao.maxAttrib, indx);
|
|
275
276
|
const attrib = vao.attribs[indx];
|
|
@@ -282,11 +283,11 @@ var OESVertexArrayObject = function OESVertexArrayObject2(gl) {
|
|
|
282
283
|
attrib.recache();
|
|
283
284
|
return original.vertexAttribPointer.apply(this, arguments);
|
|
284
285
|
};
|
|
285
|
-
if (
|
|
286
|
-
|
|
286
|
+
if (gl2.instrumentExtension) {
|
|
287
|
+
gl2.instrumentExtension(this, "OES_vertex_array_object");
|
|
287
288
|
}
|
|
288
|
-
if (
|
|
289
|
-
|
|
289
|
+
if (gl2.canvas) {
|
|
290
|
+
gl2.canvas.addEventListener(
|
|
290
291
|
"webglcontextrestored",
|
|
291
292
|
() => {
|
|
292
293
|
log("OESVertexArrayObject emulation library context restored");
|
|
@@ -305,8 +306,8 @@ OESVertexArrayObject.prototype.reset_ = function reset_() {
|
|
|
305
306
|
this.vertexArrayObjects.isAlive = false;
|
|
306
307
|
}
|
|
307
308
|
}
|
|
308
|
-
const
|
|
309
|
-
this.maxVertexAttribs =
|
|
309
|
+
const gl2 = this.gl;
|
|
310
|
+
this.maxVertexAttribs = gl2.getParameter(gl2.MAX_VERTEX_ATTRIBS);
|
|
310
311
|
this.defaultVertexArrayObject = new WebGLVertexArrayObjectOES(this);
|
|
311
312
|
this.currentVertexArrayObject = null;
|
|
312
313
|
this.currentArrayBuffer = null;
|
|
@@ -334,10 +335,10 @@ OESVertexArrayObject.prototype.isVertexArrayOES = function isVertexArrayOES(arra
|
|
|
334
335
|
return false;
|
|
335
336
|
};
|
|
336
337
|
OESVertexArrayObject.prototype.bindVertexArrayOES = function bindVertexArrayOES(arrayObject) {
|
|
337
|
-
const
|
|
338
|
+
const gl2 = this.gl;
|
|
338
339
|
if (arrayObject && !arrayObject.isAlive) {
|
|
339
340
|
synthesizeGLError(
|
|
340
|
-
|
|
341
|
+
gl2.INVALID_OPERATION,
|
|
341
342
|
"bindVertexArrayOES: attempt to bind deleted arrayObject"
|
|
342
343
|
);
|
|
343
344
|
return;
|
|
@@ -351,7 +352,7 @@ OESVertexArrayObject.prototype.bindVertexArrayOES = function bindVertexArrayOES(
|
|
|
351
352
|
return;
|
|
352
353
|
}
|
|
353
354
|
if (!oldVAO || newVAO.elementArrayBuffer !== oldVAO.elementArrayBuffer) {
|
|
354
|
-
original.bindBuffer.call(
|
|
355
|
+
original.bindBuffer.call(gl2, gl2.ELEMENT_ARRAY_BUFFER, newVAO.elementArrayBuffer);
|
|
355
356
|
}
|
|
356
357
|
let currentBinding = this.currentArrayBuffer;
|
|
357
358
|
const maxAttrib = Math.max(oldVAO ? oldVAO.maxAttrib : 0, newVAO.maxAttrib);
|
|
@@ -360,23 +361,23 @@ OESVertexArrayObject.prototype.bindVertexArrayOES = function bindVertexArrayOES(
|
|
|
360
361
|
const oldAttrib = oldVAO ? oldVAO.attribs[n] : null;
|
|
361
362
|
if (!oldVAO || attrib.enabled !== oldAttrib.enabled) {
|
|
362
363
|
if (attrib.enabled) {
|
|
363
|
-
original.enableVertexAttribArray.call(
|
|
364
|
+
original.enableVertexAttribArray.call(gl2, n);
|
|
364
365
|
} else {
|
|
365
|
-
original.disableVertexAttribArray.call(
|
|
366
|
+
original.disableVertexAttribArray.call(gl2, n);
|
|
366
367
|
}
|
|
367
368
|
}
|
|
368
369
|
if (attrib.enabled) {
|
|
369
370
|
let bufferChanged = false;
|
|
370
371
|
if (!oldVAO || attrib.buffer !== oldAttrib.buffer) {
|
|
371
372
|
if (currentBinding !== attrib.buffer) {
|
|
372
|
-
original.bindBuffer.call(
|
|
373
|
+
original.bindBuffer.call(gl2, gl2.ARRAY_BUFFER, attrib.buffer);
|
|
373
374
|
currentBinding = attrib.buffer;
|
|
374
375
|
}
|
|
375
376
|
bufferChanged = true;
|
|
376
377
|
}
|
|
377
378
|
if (bufferChanged || attrib.cached !== oldAttrib.cached) {
|
|
378
379
|
original.vertexAttribPointer.call(
|
|
379
|
-
|
|
380
|
+
gl2,
|
|
380
381
|
n,
|
|
381
382
|
attrib.size,
|
|
382
383
|
attrib.type,
|
|
@@ -388,23 +389,23 @@ OESVertexArrayObject.prototype.bindVertexArrayOES = function bindVertexArrayOES(
|
|
|
388
389
|
}
|
|
389
390
|
}
|
|
390
391
|
if (this.currentArrayBuffer !== currentBinding) {
|
|
391
|
-
original.bindBuffer.call(
|
|
392
|
+
original.bindBuffer.call(gl2, gl2.ARRAY_BUFFER, this.currentArrayBuffer);
|
|
392
393
|
}
|
|
393
394
|
};
|
|
394
|
-
function polyfillVertexArrayObject(
|
|
395
|
-
if (typeof
|
|
395
|
+
function polyfillVertexArrayObject(gl2) {
|
|
396
|
+
if (typeof gl2.createVertexArray === "function") {
|
|
396
397
|
return;
|
|
397
398
|
}
|
|
398
|
-
const original_getSupportedExtensions =
|
|
399
|
-
|
|
399
|
+
const original_getSupportedExtensions = gl2.getSupportedExtensions;
|
|
400
|
+
gl2.getSupportedExtensions = function getSupportedExtensions() {
|
|
400
401
|
const list = original_getSupportedExtensions.call(this) || [];
|
|
401
402
|
if (list.indexOf("OES_vertex_array_object") < 0) {
|
|
402
403
|
list.push("OES_vertex_array_object");
|
|
403
404
|
}
|
|
404
405
|
return list;
|
|
405
406
|
};
|
|
406
|
-
const original_getExtension =
|
|
407
|
-
|
|
407
|
+
const original_getExtension = gl2.getExtension;
|
|
408
|
+
gl2.getExtension = function getExtension(name) {
|
|
408
409
|
const ext = original_getExtension.call(this, name);
|
|
409
410
|
if (ext) {
|
|
410
411
|
return ext;
|
|
@@ -412,7 +413,7 @@ function polyfillVertexArrayObject(gl) {
|
|
|
412
413
|
if (name !== "OES_vertex_array_object") {
|
|
413
414
|
return null;
|
|
414
415
|
}
|
|
415
|
-
if (!
|
|
416
|
+
if (!gl2.__OESVertexArrayObject) {
|
|
416
417
|
this.__OESVertexArrayObject = new OESVertexArrayObject(this);
|
|
417
418
|
}
|
|
418
419
|
return this.__OESVertexArrayObject;
|
|
@@ -427,31 +428,31 @@ var import_constants2 = require("@luma.gl/constants");
|
|
|
427
428
|
var import_api = require("@luma.gl/api");
|
|
428
429
|
var ERR_CONTEXT = "Invalid WebGLRenderingContext";
|
|
429
430
|
var ERR_WEBGL2 = "Requires WebGL2";
|
|
430
|
-
function isWebGL(
|
|
431
|
-
if (typeof WebGLRenderingContext !== "undefined" &&
|
|
431
|
+
function isWebGL(gl2) {
|
|
432
|
+
if (typeof WebGLRenderingContext !== "undefined" && gl2 instanceof WebGLRenderingContext) {
|
|
432
433
|
return true;
|
|
433
434
|
}
|
|
434
|
-
if (typeof WebGL2RenderingContext !== "undefined" &&
|
|
435
|
+
if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
|
|
435
436
|
return true;
|
|
436
437
|
}
|
|
437
|
-
return Boolean(
|
|
438
|
+
return Boolean(gl2 && Number.isFinite(gl2._version));
|
|
438
439
|
}
|
|
439
|
-
function isWebGL2(
|
|
440
|
-
if (typeof WebGL2RenderingContext !== "undefined" &&
|
|
440
|
+
function isWebGL2(gl2) {
|
|
441
|
+
if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
|
|
441
442
|
return true;
|
|
442
443
|
}
|
|
443
|
-
return Boolean(
|
|
444
|
+
return Boolean(gl2 && gl2._version === 2);
|
|
444
445
|
}
|
|
445
|
-
function getWebGL2Context(
|
|
446
|
-
return isWebGL2(
|
|
446
|
+
function getWebGL2Context(gl2) {
|
|
447
|
+
return isWebGL2(gl2) ? gl2 : null;
|
|
447
448
|
}
|
|
448
|
-
function assertWebGLContext(
|
|
449
|
-
(0, import_api.assert)(isWebGL(
|
|
450
|
-
return
|
|
449
|
+
function assertWebGLContext(gl2) {
|
|
450
|
+
(0, import_api.assert)(isWebGL(gl2), ERR_CONTEXT);
|
|
451
|
+
return gl2;
|
|
451
452
|
}
|
|
452
|
-
function assertWebGL2Context(
|
|
453
|
-
(0, import_api.assert)(isWebGL2(
|
|
454
|
-
return
|
|
453
|
+
function assertWebGL2Context(gl2) {
|
|
454
|
+
(0, import_api.assert)(isWebGL2(gl2), ERR_WEBGL2);
|
|
455
|
+
return gl2;
|
|
455
456
|
}
|
|
456
457
|
|
|
457
458
|
// src/context/polyfill/get-parameter-polyfill.ts
|
|
@@ -468,40 +469,40 @@ var GL_GPU_DISJOINT_EXT = 36795;
|
|
|
468
469
|
var GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 34047;
|
|
469
470
|
var GL_UNMASKED_VENDOR_WEBGL = 37445;
|
|
470
471
|
var GL_UNMASKED_RENDERER_WEBGL = 37446;
|
|
471
|
-
var getWebGL2ValueOrZero = (
|
|
472
|
+
var getWebGL2ValueOrZero = (gl2) => !isWebGL2(gl2) ? 0 : void 0;
|
|
472
473
|
var WEBGL_PARAMETERS = {
|
|
473
|
-
[import_constants.GL.READ_BUFFER]: (
|
|
474
|
+
[import_constants.GL.READ_BUFFER]: (gl2) => !isWebGL2(gl2) ? import_constants.GL.COLOR_ATTACHMENT0 : void 0,
|
|
474
475
|
// WebGL2 context parameters
|
|
475
|
-
[GL_FRAGMENT_SHADER_DERIVATIVE_HINT]: (
|
|
476
|
+
[GL_FRAGMENT_SHADER_DERIVATIVE_HINT]: (gl2) => !isWebGL2(gl2) ? GL_DONT_CARE : void 0,
|
|
476
477
|
[import_constants.GL.RASTERIZER_DISCARD]: getWebGL2ValueOrZero,
|
|
477
478
|
[import_constants.GL.SAMPLES]: getWebGL2ValueOrZero,
|
|
478
479
|
// WebGL2 extension context parameters
|
|
479
|
-
[GL_GPU_DISJOINT_EXT]: (
|
|
480
|
-
const ext = isWebGL2(
|
|
480
|
+
[GL_GPU_DISJOINT_EXT]: (gl2, getParameter) => {
|
|
481
|
+
const ext = isWebGL2(gl2) ? gl2.getExtension(EXT_disjoint_timer_query_webgl2) : gl2.getExtension(EXT_disjoint_timer_query);
|
|
481
482
|
return ext && ext.GPU_DISJOINT_EXT ? getParameter(ext.GPU_DISJOINT_EXT) : 0;
|
|
482
483
|
},
|
|
483
484
|
// Extension fixed values
|
|
484
|
-
[GL_UNMASKED_VENDOR_WEBGL]: (
|
|
485
|
-
const ext =
|
|
485
|
+
[GL_UNMASKED_VENDOR_WEBGL]: (gl2, getParameter) => {
|
|
486
|
+
const ext = gl2.getExtension(WEBGL_debug_renderer_info);
|
|
486
487
|
return getParameter(ext && ext.UNMASKED_VENDOR_WEBGL || import_constants.GL.VENDOR);
|
|
487
488
|
},
|
|
488
|
-
[GL_UNMASKED_RENDERER_WEBGL]: (
|
|
489
|
-
const ext =
|
|
489
|
+
[GL_UNMASKED_RENDERER_WEBGL]: (gl2, getParameter) => {
|
|
490
|
+
const ext = gl2.getExtension(WEBGL_debug_renderer_info);
|
|
490
491
|
return getParameter(ext && ext.UNMASKED_RENDERER_WEBGL || import_constants.GL.RENDERER);
|
|
491
492
|
},
|
|
492
493
|
// Extension LIMITS
|
|
493
|
-
[GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT]: (
|
|
494
|
+
[GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT]: (gl2, getParameter) => {
|
|
494
495
|
var _a, _b;
|
|
495
|
-
const ext = ((_b = (_a =
|
|
496
|
+
const ext = ((_b = (_a = gl2.luma) == null ? void 0 : _a.extensions) == null ? void 0 : _b[EXT_texture_filter_anisotropic]) || gl2.getExtension("EXT_texture_filter_anisotropic");
|
|
496
497
|
return ext ? getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 1;
|
|
497
498
|
},
|
|
498
499
|
// WebGL2 Limits
|
|
499
500
|
[import_constants.GL.MAX_3D_TEXTURE_SIZE]: getWebGL2ValueOrZero,
|
|
500
501
|
[import_constants.GL.MAX_ARRAY_TEXTURE_LAYERS]: getWebGL2ValueOrZero,
|
|
501
502
|
[import_constants.GL.MAX_CLIENT_WAIT_TIMEOUT_WEBGL]: getWebGL2ValueOrZero,
|
|
502
|
-
[import_constants.GL.MAX_COLOR_ATTACHMENTS]: (
|
|
503
|
-
if (!isWebGL2(
|
|
504
|
-
const ext =
|
|
503
|
+
[import_constants.GL.MAX_COLOR_ATTACHMENTS]: (gl2, getParameter) => {
|
|
504
|
+
if (!isWebGL2(gl2)) {
|
|
505
|
+
const ext = gl2.getExtension(WEBGL_draw_buffers);
|
|
505
506
|
return ext ? getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL) : 0;
|
|
506
507
|
}
|
|
507
508
|
return void 0;
|
|
@@ -509,24 +510,24 @@ var WEBGL_PARAMETERS = {
|
|
|
509
510
|
[import_constants.GL.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
|
|
510
511
|
[import_constants.GL.MAX_COMBINED_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
|
|
511
512
|
[import_constants.GL.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
|
|
512
|
-
[import_constants.GL.MAX_DRAW_BUFFERS]: (
|
|
513
|
-
if (!isWebGL2(
|
|
514
|
-
const ext =
|
|
513
|
+
[import_constants.GL.MAX_DRAW_BUFFERS]: (gl2) => {
|
|
514
|
+
if (!isWebGL2(gl2)) {
|
|
515
|
+
const ext = gl2.getExtension(WEBGL_draw_buffers);
|
|
515
516
|
return ext ? ext.MAX_DRAW_BUFFERS_WEBGL : 0;
|
|
516
517
|
}
|
|
517
518
|
return void 0;
|
|
518
519
|
},
|
|
519
520
|
[import_constants.GL.MAX_ELEMENT_INDEX]: (
|
|
520
521
|
// Guess: per webglstats.com 99.6% of webgl2 supports 2147483647
|
|
521
|
-
(
|
|
522
|
+
(gl2) => gl2.getExtension(OES_element_index) ? 2147483647 : 65535
|
|
522
523
|
),
|
|
523
524
|
[import_constants.GL.MAX_ELEMENTS_INDICES]: (
|
|
524
525
|
// Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
|
|
525
|
-
(
|
|
526
|
+
(gl2) => gl2.getExtension(OES_element_index) ? 16777216 : 65535
|
|
526
527
|
),
|
|
527
528
|
[import_constants.GL.MAX_ELEMENTS_VERTICES]: (
|
|
528
529
|
// Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
|
|
529
|
-
(
|
|
530
|
+
(gl2) => 16777216
|
|
530
531
|
),
|
|
531
532
|
[import_constants.GL.MAX_FRAGMENT_INPUT_COMPONENTS]: getWebGL2ValueOrZero,
|
|
532
533
|
[import_constants.GL.MAX_FRAGMENT_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
|
|
@@ -547,24 +548,24 @@ var WEBGL_PARAMETERS = {
|
|
|
547
548
|
[import_constants.GL.MAX_PROGRAM_TEXEL_OFFSET]: getWebGL2ValueOrZero,
|
|
548
549
|
[import_constants.GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT]: getWebGL2ValueOrZero
|
|
549
550
|
};
|
|
550
|
-
function getParameterPolyfill(
|
|
551
|
+
function getParameterPolyfill(gl2, originalGetParameter, pname) {
|
|
551
552
|
const limit = WEBGL_PARAMETERS[pname];
|
|
552
|
-
const value = typeof limit === "function" ? limit(
|
|
553
|
+
const value = typeof limit === "function" ? limit(gl2, originalGetParameter, pname) : limit;
|
|
553
554
|
const result = value !== void 0 ? value : originalGetParameter(pname);
|
|
554
555
|
return result;
|
|
555
556
|
}
|
|
556
557
|
|
|
557
558
|
// src/context/polyfill/context-data.ts
|
|
558
|
-
function getContextData(
|
|
559
|
-
const luma =
|
|
559
|
+
function getContextData(gl2) {
|
|
560
|
+
const luma = gl2.luma;
|
|
560
561
|
if (!luma) {
|
|
561
562
|
const contextState = {
|
|
562
563
|
_polyfilled: false,
|
|
563
564
|
_extensions: {}
|
|
564
565
|
};
|
|
565
|
-
|
|
566
|
+
gl2.luma = contextState;
|
|
566
567
|
}
|
|
567
|
-
return
|
|
568
|
+
return gl2.luma;
|
|
568
569
|
}
|
|
569
570
|
|
|
570
571
|
// src/context/polyfill/polyfill-table.ts
|
|
@@ -574,10 +575,10 @@ var WEBGL_draw_buffers2 = "WEBGL_draw_buffers";
|
|
|
574
575
|
var EXT_disjoint_timer_query2 = "EXT_disjoint_timer_query";
|
|
575
576
|
var EXT_texture_filter_anisotropic2 = "EXT_texture_filter_anisotropic";
|
|
576
577
|
var ERR_VAO_NOT_SUPPORTED = "VertexArray requires WebGL2 or OES_vertex_array_object extension";
|
|
577
|
-
function getExtensionData(
|
|
578
|
+
function getExtensionData(gl2, extension) {
|
|
578
579
|
return {
|
|
579
|
-
webgl2: isWebGL2(
|
|
580
|
-
ext:
|
|
580
|
+
webgl2: isWebGL2(gl2),
|
|
581
|
+
ext: gl2.getExtension(extension)
|
|
581
582
|
};
|
|
582
583
|
}
|
|
583
584
|
var WEBGL2_CONTEXT_POLYFILLS = {
|
|
@@ -644,15 +645,15 @@ var WEBGL2_CONTEXT_POLYFILLS = {
|
|
|
644
645
|
};
|
|
645
646
|
var WEBGL2_CONTEXT_OVERRIDES = {
|
|
646
647
|
// Ensure readBuffer is a no-op
|
|
647
|
-
readBuffer: (
|
|
648
|
-
if (isWebGL2(
|
|
648
|
+
readBuffer: (gl2, originalFunc, attachment) => {
|
|
649
|
+
if (isWebGL2(gl2)) {
|
|
649
650
|
originalFunc(attachment);
|
|
650
651
|
} else {
|
|
651
652
|
}
|
|
652
653
|
},
|
|
653
654
|
// Override for getVertexAttrib that returns sane values for non-WebGL1 constants
|
|
654
|
-
getVertexAttrib: (
|
|
655
|
-
const { webgl2, ext } = getExtensionData(
|
|
655
|
+
getVertexAttrib: (gl2, originalFunc, location, pname) => {
|
|
656
|
+
const { webgl2, ext } = getExtensionData(gl2, ANGLE_instanced_arrays);
|
|
656
657
|
let result;
|
|
657
658
|
switch (pname) {
|
|
658
659
|
case import_constants2.GL.VERTEX_ATTRIB_ARRAY_INTEGER:
|
|
@@ -666,8 +667,8 @@ var WEBGL2_CONTEXT_OVERRIDES = {
|
|
|
666
667
|
return result !== void 0 ? result : originalFunc(location, pname);
|
|
667
668
|
},
|
|
668
669
|
// Handle transform feedback and uniform block queries in WebGL1
|
|
669
|
-
getProgramParameter: (
|
|
670
|
-
if (!isWebGL2(
|
|
670
|
+
getProgramParameter: (gl2, originalFunc, program, pname) => {
|
|
671
|
+
if (!isWebGL2(gl2)) {
|
|
671
672
|
switch (pname) {
|
|
672
673
|
case import_constants2.GL.TRANSFORM_FEEDBACK_BUFFER_MODE:
|
|
673
674
|
return import_constants2.GL.SEPARATE_ATTRIBS;
|
|
@@ -680,21 +681,21 @@ var WEBGL2_CONTEXT_OVERRIDES = {
|
|
|
680
681
|
}
|
|
681
682
|
return originalFunc(program, pname);
|
|
682
683
|
},
|
|
683
|
-
getInternalformatParameter: (
|
|
684
|
-
if (!isWebGL2(
|
|
684
|
+
getInternalformatParameter: (gl2, originalFunc, target, format, pname) => {
|
|
685
|
+
if (!isWebGL2(gl2)) {
|
|
685
686
|
switch (pname) {
|
|
686
687
|
case import_constants2.GL.SAMPLES:
|
|
687
688
|
return new Int32Array([0]);
|
|
688
689
|
default:
|
|
689
690
|
}
|
|
690
691
|
}
|
|
691
|
-
const
|
|
692
|
-
return
|
|
692
|
+
const gl22 = gl2;
|
|
693
|
+
return gl22.getInternalformatParameter(target, format, pname);
|
|
693
694
|
},
|
|
694
|
-
getTexParameter(
|
|
695
|
+
getTexParameter(gl2, originalFunc, target, pname) {
|
|
695
696
|
switch (pname) {
|
|
696
697
|
case import_constants2.GL.TEXTURE_MAX_ANISOTROPY_EXT:
|
|
697
|
-
const contextData = getContextData(
|
|
698
|
+
const contextData = getContextData(gl2);
|
|
698
699
|
const { _extensions } = contextData;
|
|
699
700
|
const ext = _extensions[EXT_texture_filter_anisotropic2];
|
|
700
701
|
pname = ext && ext.TEXTURE_MAX_ANISOTROPY_EXT || import_constants2.GL.TEXTURE_MAX_ANISOTROPY_EXT;
|
|
@@ -704,50 +705,50 @@ var WEBGL2_CONTEXT_OVERRIDES = {
|
|
|
704
705
|
return originalFunc(target, pname);
|
|
705
706
|
},
|
|
706
707
|
getParameter: getParameterPolyfill,
|
|
707
|
-
hint(
|
|
708
|
+
hint(gl2, originalFunc, pname, value) {
|
|
708
709
|
return originalFunc(pname, value);
|
|
709
710
|
}
|
|
710
711
|
};
|
|
711
712
|
|
|
712
713
|
// src/context/polyfill/polyfill-context.ts
|
|
713
|
-
function polyfillContext(
|
|
714
|
-
const contextState = getContextData(
|
|
714
|
+
function polyfillContext(gl2) {
|
|
715
|
+
const contextState = getContextData(gl2);
|
|
715
716
|
if (!contextState._polyfilled) {
|
|
716
|
-
polyfillVertexArrayObject(
|
|
717
|
-
initializeExtensions(
|
|
718
|
-
installPolyfills(
|
|
719
|
-
installOverrides(
|
|
717
|
+
polyfillVertexArrayObject(gl2);
|
|
718
|
+
initializeExtensions(gl2);
|
|
719
|
+
installPolyfills(gl2, WEBGL2_CONTEXT_POLYFILLS);
|
|
720
|
+
installOverrides(gl2, { target: contextState, target2: gl2 });
|
|
720
721
|
contextState._polyfilled = true;
|
|
721
722
|
}
|
|
722
|
-
return
|
|
723
|
+
return gl2;
|
|
723
724
|
}
|
|
724
|
-
function initializeExtensions(
|
|
725
|
-
const contextState = getContextData(
|
|
726
|
-
const EXTENSIONS =
|
|
725
|
+
function initializeExtensions(gl2) {
|
|
726
|
+
const contextState = getContextData(gl2);
|
|
727
|
+
const EXTENSIONS = gl2.getSupportedExtensions() || [];
|
|
727
728
|
for (const extensionName of EXTENSIONS) {
|
|
728
|
-
const extension =
|
|
729
|
+
const extension = gl2.getExtension(extensionName);
|
|
729
730
|
contextState._extensions[extensionName] = extension;
|
|
730
731
|
}
|
|
731
732
|
}
|
|
732
|
-
function installPolyfills(
|
|
733
|
-
const contextState = getContextData(
|
|
733
|
+
function installPolyfills(gl2, polyfills) {
|
|
734
|
+
const contextState = getContextData(gl2);
|
|
734
735
|
for (const extension of Object.getOwnPropertyNames(polyfills)) {
|
|
735
736
|
if (extension !== "overrides") {
|
|
736
|
-
polyfillExtension(
|
|
737
|
+
polyfillExtension(gl2, { extension, target: contextState, target2: gl2 });
|
|
737
738
|
}
|
|
738
739
|
}
|
|
739
740
|
}
|
|
740
|
-
function polyfillExtension(
|
|
741
|
+
function polyfillExtension(gl2, { extension, target, target2 }) {
|
|
741
742
|
const defaults = WEBGL2_CONTEXT_POLYFILLS[extension];
|
|
742
743
|
(0, import_api3.assert)(defaults);
|
|
743
744
|
const { meta = {} } = defaults;
|
|
744
745
|
const { suffix = "" } = meta;
|
|
745
|
-
const ext =
|
|
746
|
+
const ext = gl2.getExtension(extension);
|
|
746
747
|
for (const key of Object.keys(defaults)) {
|
|
747
748
|
const extKey = `${key}${suffix}`;
|
|
748
749
|
let polyfill = null;
|
|
749
750
|
if (key === "meta") {
|
|
750
|
-
} else if (typeof
|
|
751
|
+
} else if (typeof gl2[key] === "function") {
|
|
751
752
|
} else if (ext && typeof ext[extKey] === "function") {
|
|
752
753
|
polyfill = (...args) => ext[extKey](...args);
|
|
753
754
|
} else if (typeof defaults[key] === "function") {
|
|
@@ -759,12 +760,12 @@ function polyfillExtension(gl, { extension, target, target2 }) {
|
|
|
759
760
|
}
|
|
760
761
|
}
|
|
761
762
|
}
|
|
762
|
-
function installOverrides(
|
|
763
|
+
function installOverrides(gl2, { target, target2 }) {
|
|
763
764
|
Object.keys(WEBGL2_CONTEXT_OVERRIDES).forEach((key) => {
|
|
764
765
|
if (typeof WEBGL2_CONTEXT_OVERRIDES[key] === "function") {
|
|
765
|
-
const originalFunc =
|
|
766
|
+
const originalFunc = gl2[key] ? gl2[key].bind(gl2) : () => {
|
|
766
767
|
};
|
|
767
|
-
const polyfill = WEBGL2_CONTEXT_OVERRIDES[key].bind(null,
|
|
768
|
+
const polyfill = WEBGL2_CONTEXT_OVERRIDES[key].bind(null, gl2, originalFunc);
|
|
768
769
|
target[key] = polyfill;
|
|
769
770
|
target2[key] = polyfill;
|
|
770
771
|
}
|
|
@@ -859,19 +860,19 @@ var GL_PARAMETER_DEFAULTS = {
|
|
|
859
860
|
[import_constants3.GL.UNPACK_SKIP_ROWS]: 0,
|
|
860
861
|
[import_constants3.GL.UNPACK_SKIP_IMAGES]: 0
|
|
861
862
|
};
|
|
862
|
-
var enable = (
|
|
863
|
-
var hint = (
|
|
864
|
-
var pixelStorei = (
|
|
865
|
-
var bindFramebuffer = (
|
|
863
|
+
var enable = (gl2, value, key) => value ? gl2.enable(key) : gl2.disable(key);
|
|
864
|
+
var hint = (gl2, value, key) => gl2.hint(key, value);
|
|
865
|
+
var pixelStorei = (gl2, value, key) => gl2.pixelStorei(key, value);
|
|
866
|
+
var bindFramebuffer = (gl2, value, key) => {
|
|
866
867
|
let target;
|
|
867
868
|
if (key === import_constants3.GL.FRAMEBUFFER_BINDING) {
|
|
868
|
-
target = isWebGL2(
|
|
869
|
+
target = isWebGL2(gl2) ? import_constants3.GL.DRAW_FRAMEBUFFER : import_constants3.GL.FRAMEBUFFER;
|
|
869
870
|
} else {
|
|
870
871
|
target = import_constants3.GL.READ_FRAMEBUFFER;
|
|
871
872
|
}
|
|
872
|
-
return
|
|
873
|
+
return gl2.bindFramebuffer(target, value);
|
|
873
874
|
};
|
|
874
|
-
var bindBuffer = (
|
|
875
|
+
var bindBuffer = (gl2, value, key) => {
|
|
875
876
|
const bindingMap = {
|
|
876
877
|
[import_constants3.GL.ARRAY_BUFFER_BINDING]: import_constants3.GL.ARRAY_BUFFER,
|
|
877
878
|
[import_constants3.GL.COPY_READ_BUFFER_BINDING]: import_constants3.GL.COPY_READ_BUFFER,
|
|
@@ -880,38 +881,38 @@ var bindBuffer = (gl, value, key) => {
|
|
|
880
881
|
[import_constants3.GL.PIXEL_UNPACK_BUFFER_BINDING]: import_constants3.GL.PIXEL_UNPACK_BUFFER
|
|
881
882
|
};
|
|
882
883
|
const target = bindingMap[key];
|
|
883
|
-
|
|
884
|
+
gl2.bindBuffer(target, value);
|
|
884
885
|
};
|
|
885
886
|
function isArray(array) {
|
|
886
887
|
return Array.isArray(array) || ArrayBuffer.isView(array) && !(array instanceof DataView);
|
|
887
888
|
}
|
|
888
889
|
var GL_PARAMETER_SETTERS = {
|
|
889
890
|
[import_constants3.GL.BLEND]: enable,
|
|
890
|
-
[import_constants3.GL.BLEND_COLOR]: (
|
|
891
|
+
[import_constants3.GL.BLEND_COLOR]: (gl2, value) => gl2.blendColor(...value),
|
|
891
892
|
[import_constants3.GL.BLEND_EQUATION_RGB]: "blendEquation",
|
|
892
893
|
[import_constants3.GL.BLEND_EQUATION_ALPHA]: "blendEquation",
|
|
893
894
|
[import_constants3.GL.BLEND_SRC_RGB]: "blendFunc",
|
|
894
895
|
[import_constants3.GL.BLEND_DST_RGB]: "blendFunc",
|
|
895
896
|
[import_constants3.GL.BLEND_SRC_ALPHA]: "blendFunc",
|
|
896
897
|
[import_constants3.GL.BLEND_DST_ALPHA]: "blendFunc",
|
|
897
|
-
[import_constants3.GL.COLOR_CLEAR_VALUE]: (
|
|
898
|
-
[import_constants3.GL.COLOR_WRITEMASK]: (
|
|
898
|
+
[import_constants3.GL.COLOR_CLEAR_VALUE]: (gl2, value) => gl2.clearColor(...value),
|
|
899
|
+
[import_constants3.GL.COLOR_WRITEMASK]: (gl2, value) => gl2.colorMask(...value),
|
|
899
900
|
[import_constants3.GL.CULL_FACE]: enable,
|
|
900
|
-
[import_constants3.GL.CULL_FACE_MODE]: (
|
|
901
|
+
[import_constants3.GL.CULL_FACE_MODE]: (gl2, value) => gl2.cullFace(value),
|
|
901
902
|
[import_constants3.GL.DEPTH_TEST]: enable,
|
|
902
|
-
[import_constants3.GL.DEPTH_CLEAR_VALUE]: (
|
|
903
|
-
[import_constants3.GL.DEPTH_FUNC]: (
|
|
904
|
-
[import_constants3.GL.DEPTH_RANGE]: (
|
|
905
|
-
[import_constants3.GL.DEPTH_WRITEMASK]: (
|
|
903
|
+
[import_constants3.GL.DEPTH_CLEAR_VALUE]: (gl2, value) => gl2.clearDepth(value),
|
|
904
|
+
[import_constants3.GL.DEPTH_FUNC]: (gl2, value) => gl2.depthFunc(value),
|
|
905
|
+
[import_constants3.GL.DEPTH_RANGE]: (gl2, value) => gl2.depthRange(...value),
|
|
906
|
+
[import_constants3.GL.DEPTH_WRITEMASK]: (gl2, value) => gl2.depthMask(value),
|
|
906
907
|
[import_constants3.GL.DITHER]: enable,
|
|
907
908
|
[import_constants3.GL.FRAGMENT_SHADER_DERIVATIVE_HINT]: hint,
|
|
908
|
-
[import_constants3.GL.CURRENT_PROGRAM]: (
|
|
909
|
-
[import_constants3.GL.RENDERBUFFER_BINDING]: (
|
|
910
|
-
[import_constants3.GL.TRANSFORM_FEEDBACK_BINDING]: (
|
|
909
|
+
[import_constants3.GL.CURRENT_PROGRAM]: (gl2, value) => gl2.useProgram(value),
|
|
910
|
+
[import_constants3.GL.RENDERBUFFER_BINDING]: (gl2, value) => gl2.bindRenderbuffer(import_constants3.GL.RENDERBUFFER, value),
|
|
911
|
+
[import_constants3.GL.TRANSFORM_FEEDBACK_BINDING]: (gl2, value) => {
|
|
911
912
|
var _a;
|
|
912
|
-
return (_a =
|
|
913
|
+
return (_a = gl2.bindTransformFeedback) == null ? void 0 : _a.call(gl2, import_constants3.GL.TRANSFORM_FEEDBACK, value);
|
|
913
914
|
},
|
|
914
|
-
[import_constants3.GL.VERTEX_ARRAY_BINDING]: (
|
|
915
|
+
[import_constants3.GL.VERTEX_ARRAY_BINDING]: (gl2, value) => gl2.bindVertexArray(value),
|
|
915
916
|
// NOTE: FRAMEBUFFER_BINDING and DRAW_FRAMEBUFFER_BINDING(WebGL2) refer same state.
|
|
916
917
|
[import_constants3.GL.FRAMEBUFFER_BINDING]: bindFramebuffer,
|
|
917
918
|
[import_constants3.GL.READ_FRAMEBUFFER_BINDING]: bindFramebuffer,
|
|
@@ -921,9 +922,9 @@ var GL_PARAMETER_SETTERS = {
|
|
|
921
922
|
[import_constants3.GL.COPY_WRITE_BUFFER_BINDING]: bindBuffer,
|
|
922
923
|
[import_constants3.GL.PIXEL_PACK_BUFFER_BINDING]: bindBuffer,
|
|
923
924
|
[import_constants3.GL.PIXEL_UNPACK_BUFFER_BINDING]: bindBuffer,
|
|
924
|
-
[import_constants3.GL.FRONT_FACE]: (
|
|
925
|
+
[import_constants3.GL.FRONT_FACE]: (gl2, value) => gl2.frontFace(value),
|
|
925
926
|
[import_constants3.GL.GENERATE_MIPMAP_HINT]: hint,
|
|
926
|
-
[import_constants3.GL.LINE_WIDTH]: (
|
|
927
|
+
[import_constants3.GL.LINE_WIDTH]: (gl2, value) => gl2.lineWidth(value),
|
|
927
928
|
[import_constants3.GL.POLYGON_OFFSET_FILL]: enable,
|
|
928
929
|
[import_constants3.GL.POLYGON_OFFSET_FACTOR]: "polygonOffset",
|
|
929
930
|
[import_constants3.GL.POLYGON_OFFSET_UNITS]: "polygonOffset",
|
|
@@ -933,11 +934,11 @@ var GL_PARAMETER_SETTERS = {
|
|
|
933
934
|
[import_constants3.GL.SAMPLE_COVERAGE_VALUE]: "sampleCoverage",
|
|
934
935
|
[import_constants3.GL.SAMPLE_COVERAGE_INVERT]: "sampleCoverage",
|
|
935
936
|
[import_constants3.GL.SCISSOR_TEST]: enable,
|
|
936
|
-
[import_constants3.GL.SCISSOR_BOX]: (
|
|
937
|
+
[import_constants3.GL.SCISSOR_BOX]: (gl2, value) => gl2.scissor(...value),
|
|
937
938
|
[import_constants3.GL.STENCIL_TEST]: enable,
|
|
938
|
-
[import_constants3.GL.STENCIL_CLEAR_VALUE]: (
|
|
939
|
-
[import_constants3.GL.STENCIL_WRITEMASK]: (
|
|
940
|
-
[import_constants3.GL.STENCIL_BACK_WRITEMASK]: (
|
|
939
|
+
[import_constants3.GL.STENCIL_CLEAR_VALUE]: (gl2, value) => gl2.clearStencil(value),
|
|
940
|
+
[import_constants3.GL.STENCIL_WRITEMASK]: (gl2, value) => gl2.stencilMaskSeparate(import_constants3.GL.FRONT, value),
|
|
941
|
+
[import_constants3.GL.STENCIL_BACK_WRITEMASK]: (gl2, value) => gl2.stencilMaskSeparate(import_constants3.GL.BACK, value),
|
|
941
942
|
[import_constants3.GL.STENCIL_FUNC]: "stencilFuncFront",
|
|
942
943
|
[import_constants3.GL.STENCIL_REF]: "stencilFuncFront",
|
|
943
944
|
[import_constants3.GL.STENCIL_VALUE_MASK]: "stencilFuncFront",
|
|
@@ -950,7 +951,7 @@ var GL_PARAMETER_SETTERS = {
|
|
|
950
951
|
[import_constants3.GL.STENCIL_BACK_FAIL]: "stencilOpBack",
|
|
951
952
|
[import_constants3.GL.STENCIL_BACK_PASS_DEPTH_FAIL]: "stencilOpBack",
|
|
952
953
|
[import_constants3.GL.STENCIL_BACK_PASS_DEPTH_PASS]: "stencilOpBack",
|
|
953
|
-
[import_constants3.GL.VIEWPORT]: (
|
|
954
|
+
[import_constants3.GL.VIEWPORT]: (gl2, value) => gl2.viewport(...value),
|
|
954
955
|
// WEBGL1 PIXEL PACK/UNPACK MODES
|
|
955
956
|
[import_constants3.GL.PACK_ALIGNMENT]: pixelStorei,
|
|
956
957
|
[import_constants3.GL.UNPACK_ALIGNMENT]: pixelStorei,
|
|
@@ -968,104 +969,104 @@ var GL_PARAMETER_SETTERS = {
|
|
|
968
969
|
[import_constants3.GL.UNPACK_SKIP_ROWS]: pixelStorei,
|
|
969
970
|
[import_constants3.GL.UNPACK_SKIP_IMAGES]: pixelStorei,
|
|
970
971
|
// Function-style setters
|
|
971
|
-
framebuffer: (
|
|
972
|
+
framebuffer: (gl2, framebuffer) => {
|
|
972
973
|
const handle = framebuffer && "handle" in framebuffer ? framebuffer.handle : framebuffer;
|
|
973
|
-
return
|
|
974
|
+
return gl2.bindFramebuffer(import_constants3.GL.FRAMEBUFFER, handle);
|
|
974
975
|
},
|
|
975
|
-
blend: (
|
|
976
|
-
blendColor: (
|
|
977
|
-
blendEquation: (
|
|
976
|
+
blend: (gl2, value) => value ? gl2.enable(import_constants3.GL.BLEND) : gl2.disable(import_constants3.GL.BLEND),
|
|
977
|
+
blendColor: (gl2, value) => gl2.blendColor(...value),
|
|
978
|
+
blendEquation: (gl2, args) => {
|
|
978
979
|
const separateModes = typeof args === "number" ? [args, args] : args;
|
|
979
|
-
|
|
980
|
+
gl2.blendEquationSeparate(...separateModes);
|
|
980
981
|
},
|
|
981
|
-
blendFunc: (
|
|
982
|
+
blendFunc: (gl2, args) => {
|
|
982
983
|
const separateFuncs = (args == null ? void 0 : args.length) === 2 ? [...args, ...args] : args;
|
|
983
|
-
|
|
984
|
+
gl2.blendFuncSeparate(...separateFuncs);
|
|
984
985
|
},
|
|
985
|
-
clearColor: (
|
|
986
|
-
clearDepth: (
|
|
987
|
-
clearStencil: (
|
|
988
|
-
colorMask: (
|
|
989
|
-
cull: (
|
|
990
|
-
cullFace: (
|
|
991
|
-
depthTest: (
|
|
992
|
-
depthFunc: (
|
|
993
|
-
depthMask: (
|
|
994
|
-
depthRange: (
|
|
995
|
-
dither: (
|
|
996
|
-
derivativeHint: (
|
|
997
|
-
|
|
986
|
+
clearColor: (gl2, value) => gl2.clearColor(...value),
|
|
987
|
+
clearDepth: (gl2, value) => gl2.clearDepth(value),
|
|
988
|
+
clearStencil: (gl2, value) => gl2.clearStencil(value),
|
|
989
|
+
colorMask: (gl2, value) => gl2.colorMask(...value),
|
|
990
|
+
cull: (gl2, value) => value ? gl2.enable(import_constants3.GL.CULL_FACE) : gl2.disable(import_constants3.GL.CULL_FACE),
|
|
991
|
+
cullFace: (gl2, value) => gl2.cullFace(value),
|
|
992
|
+
depthTest: (gl2, value) => value ? gl2.enable(import_constants3.GL.DEPTH_TEST) : gl2.disable(import_constants3.GL.DEPTH_TEST),
|
|
993
|
+
depthFunc: (gl2, value) => gl2.depthFunc(value),
|
|
994
|
+
depthMask: (gl2, value) => gl2.depthMask(value),
|
|
995
|
+
depthRange: (gl2, value) => gl2.depthRange(...value),
|
|
996
|
+
dither: (gl2, value) => value ? gl2.enable(import_constants3.GL.DITHER) : gl2.disable(import_constants3.GL.DITHER),
|
|
997
|
+
derivativeHint: (gl2, value) => {
|
|
998
|
+
gl2.hint(import_constants3.GL.FRAGMENT_SHADER_DERIVATIVE_HINT, value);
|
|
998
999
|
},
|
|
999
|
-
frontFace: (
|
|
1000
|
-
mipmapHint: (
|
|
1001
|
-
lineWidth: (
|
|
1002
|
-
polygonOffsetFill: (
|
|
1003
|
-
polygonOffset: (
|
|
1004
|
-
sampleCoverage: (
|
|
1005
|
-
scissorTest: (
|
|
1006
|
-
scissor: (
|
|
1007
|
-
stencilTest: (
|
|
1008
|
-
stencilMask: (
|
|
1000
|
+
frontFace: (gl2, value) => gl2.frontFace(value),
|
|
1001
|
+
mipmapHint: (gl2, value) => gl2.hint(import_constants3.GL.GENERATE_MIPMAP_HINT, value),
|
|
1002
|
+
lineWidth: (gl2, value) => gl2.lineWidth(value),
|
|
1003
|
+
polygonOffsetFill: (gl2, value) => value ? gl2.enable(import_constants3.GL.POLYGON_OFFSET_FILL) : gl2.disable(import_constants3.GL.POLYGON_OFFSET_FILL),
|
|
1004
|
+
polygonOffset: (gl2, value) => gl2.polygonOffset(...value),
|
|
1005
|
+
sampleCoverage: (gl2, value) => gl2.sampleCoverage(...value),
|
|
1006
|
+
scissorTest: (gl2, value) => value ? gl2.enable(import_constants3.GL.SCISSOR_TEST) : gl2.disable(import_constants3.GL.SCISSOR_TEST),
|
|
1007
|
+
scissor: (gl2, value) => gl2.scissor(...value),
|
|
1008
|
+
stencilTest: (gl2, value) => value ? gl2.enable(import_constants3.GL.STENCIL_TEST) : gl2.disable(import_constants3.GL.STENCIL_TEST),
|
|
1009
|
+
stencilMask: (gl2, value) => {
|
|
1009
1010
|
value = isArray(value) ? value : [value, value];
|
|
1010
1011
|
const [mask, backMask] = value;
|
|
1011
|
-
|
|
1012
|
-
|
|
1012
|
+
gl2.stencilMaskSeparate(import_constants3.GL.FRONT, mask);
|
|
1013
|
+
gl2.stencilMaskSeparate(import_constants3.GL.BACK, backMask);
|
|
1013
1014
|
},
|
|
1014
|
-
stencilFunc: (
|
|
1015
|
+
stencilFunc: (gl2, args) => {
|
|
1015
1016
|
args = isArray(args) && args.length === 3 ? [...args, ...args] : args;
|
|
1016
1017
|
const [func, ref, mask, backFunc, backRef, backMask] = args;
|
|
1017
|
-
|
|
1018
|
-
|
|
1018
|
+
gl2.stencilFuncSeparate(import_constants3.GL.FRONT, func, ref, mask);
|
|
1019
|
+
gl2.stencilFuncSeparate(import_constants3.GL.BACK, backFunc, backRef, backMask);
|
|
1019
1020
|
},
|
|
1020
|
-
stencilOp: (
|
|
1021
|
+
stencilOp: (gl2, args) => {
|
|
1021
1022
|
args = isArray(args) && args.length === 3 ? [...args, ...args] : args;
|
|
1022
1023
|
const [sfail, dpfail, dppass, backSfail, backDpfail, backDppass] = args;
|
|
1023
|
-
|
|
1024
|
-
|
|
1024
|
+
gl2.stencilOpSeparate(import_constants3.GL.FRONT, sfail, dpfail, dppass);
|
|
1025
|
+
gl2.stencilOpSeparate(import_constants3.GL.BACK, backSfail, backDpfail, backDppass);
|
|
1025
1026
|
},
|
|
1026
|
-
viewport: (
|
|
1027
|
+
viewport: (gl2, value) => gl2.viewport(...value)
|
|
1027
1028
|
};
|
|
1028
1029
|
function getValue(glEnum, values, cache) {
|
|
1029
1030
|
return values[glEnum] !== void 0 ? values[glEnum] : cache[glEnum];
|
|
1030
1031
|
}
|
|
1031
1032
|
var GL_COMPOSITE_PARAMETER_SETTERS = {
|
|
1032
|
-
blendEquation: (
|
|
1033
|
+
blendEquation: (gl2, values, cache) => gl2.blendEquationSeparate(
|
|
1033
1034
|
getValue(import_constants3.GL.BLEND_EQUATION_RGB, values, cache),
|
|
1034
1035
|
getValue(import_constants3.GL.BLEND_EQUATION_ALPHA, values, cache)
|
|
1035
1036
|
),
|
|
1036
|
-
blendFunc: (
|
|
1037
|
+
blendFunc: (gl2, values, cache) => gl2.blendFuncSeparate(
|
|
1037
1038
|
getValue(import_constants3.GL.BLEND_SRC_RGB, values, cache),
|
|
1038
1039
|
getValue(import_constants3.GL.BLEND_DST_RGB, values, cache),
|
|
1039
1040
|
getValue(import_constants3.GL.BLEND_SRC_ALPHA, values, cache),
|
|
1040
1041
|
getValue(import_constants3.GL.BLEND_DST_ALPHA, values, cache)
|
|
1041
1042
|
),
|
|
1042
|
-
polygonOffset: (
|
|
1043
|
+
polygonOffset: (gl2, values, cache) => gl2.polygonOffset(
|
|
1043
1044
|
getValue(import_constants3.GL.POLYGON_OFFSET_FACTOR, values, cache),
|
|
1044
1045
|
getValue(import_constants3.GL.POLYGON_OFFSET_UNITS, values, cache)
|
|
1045
1046
|
),
|
|
1046
|
-
sampleCoverage: (
|
|
1047
|
+
sampleCoverage: (gl2, values, cache) => gl2.sampleCoverage(
|
|
1047
1048
|
getValue(import_constants3.GL.SAMPLE_COVERAGE_VALUE, values, cache),
|
|
1048
1049
|
getValue(import_constants3.GL.SAMPLE_COVERAGE_INVERT, values, cache)
|
|
1049
1050
|
),
|
|
1050
|
-
stencilFuncFront: (
|
|
1051
|
+
stencilFuncFront: (gl2, values, cache) => gl2.stencilFuncSeparate(
|
|
1051
1052
|
import_constants3.GL.FRONT,
|
|
1052
1053
|
getValue(import_constants3.GL.STENCIL_FUNC, values, cache),
|
|
1053
1054
|
getValue(import_constants3.GL.STENCIL_REF, values, cache),
|
|
1054
1055
|
getValue(import_constants3.GL.STENCIL_VALUE_MASK, values, cache)
|
|
1055
1056
|
),
|
|
1056
|
-
stencilFuncBack: (
|
|
1057
|
+
stencilFuncBack: (gl2, values, cache) => gl2.stencilFuncSeparate(
|
|
1057
1058
|
import_constants3.GL.BACK,
|
|
1058
1059
|
getValue(import_constants3.GL.STENCIL_BACK_FUNC, values, cache),
|
|
1059
1060
|
getValue(import_constants3.GL.STENCIL_BACK_REF, values, cache),
|
|
1060
1061
|
getValue(import_constants3.GL.STENCIL_BACK_VALUE_MASK, values, cache)
|
|
1061
1062
|
),
|
|
1062
|
-
stencilOpFront: (
|
|
1063
|
+
stencilOpFront: (gl2, values, cache) => gl2.stencilOpSeparate(
|
|
1063
1064
|
import_constants3.GL.FRONT,
|
|
1064
1065
|
getValue(import_constants3.GL.STENCIL_FAIL, values, cache),
|
|
1065
1066
|
getValue(import_constants3.GL.STENCIL_PASS_DEPTH_FAIL, values, cache),
|
|
1066
1067
|
getValue(import_constants3.GL.STENCIL_PASS_DEPTH_PASS, values, cache)
|
|
1067
1068
|
),
|
|
1068
|
-
stencilOpBack: (
|
|
1069
|
+
stencilOpBack: (gl2, values, cache) => gl2.stencilOpSeparate(
|
|
1069
1070
|
import_constants3.GL.BACK,
|
|
1070
1071
|
getValue(import_constants3.GL.STENCIL_BACK_FAIL, values, cache),
|
|
1071
1072
|
getValue(import_constants3.GL.STENCIL_BACK_PASS_DEPTH_FAIL, values, cache),
|
|
@@ -1228,7 +1229,7 @@ var GL_HOOKED_SETTERS = {
|
|
|
1228
1229
|
[import_constants3.GL.VIEWPORT]: [x, y, width, height]
|
|
1229
1230
|
})
|
|
1230
1231
|
};
|
|
1231
|
-
var isEnabled = (
|
|
1232
|
+
var isEnabled = (gl2, key) => gl2.isEnabled(key);
|
|
1232
1233
|
var GL_PARAMETER_GETTERS = {
|
|
1233
1234
|
[import_constants3.GL.BLEND]: isEnabled,
|
|
1234
1235
|
[import_constants3.GL.CULL_FACE]: isEnabled,
|
|
@@ -1284,7 +1285,7 @@ var NON_CACHE_PARAMETERS = /* @__PURE__ */ new Set([
|
|
|
1284
1285
|
// src/context/parameters/unified-parameter-api.ts
|
|
1285
1286
|
function setParameters(device, parameters) {
|
|
1286
1287
|
const webglDevice = WebGLDevice.attach(device);
|
|
1287
|
-
const
|
|
1288
|
+
const gl2 = webglDevice.gl;
|
|
1288
1289
|
if (isObjectEmpty(parameters)) {
|
|
1289
1290
|
return;
|
|
1290
1291
|
}
|
|
@@ -1296,31 +1297,31 @@ function setParameters(device, parameters) {
|
|
|
1296
1297
|
if (typeof setter === "string") {
|
|
1297
1298
|
compositeSetters[setter] = true;
|
|
1298
1299
|
} else {
|
|
1299
|
-
setter(
|
|
1300
|
+
setter(gl2, parameters[key], glConstant);
|
|
1300
1301
|
}
|
|
1301
1302
|
}
|
|
1302
1303
|
}
|
|
1303
|
-
const cache =
|
|
1304
|
+
const cache = gl2.state && gl2.state.cache;
|
|
1304
1305
|
if (cache) {
|
|
1305
1306
|
for (const key in compositeSetters) {
|
|
1306
1307
|
const compositeSetter = GL_COMPOSITE_PARAMETER_SETTERS[key];
|
|
1307
|
-
compositeSetter(
|
|
1308
|
+
compositeSetter(gl2, parameters, cache);
|
|
1308
1309
|
}
|
|
1309
1310
|
}
|
|
1310
1311
|
}
|
|
1311
1312
|
function getParameters(device, parameters = GL_PARAMETER_DEFAULTS) {
|
|
1312
1313
|
const webglDevice = WebGLDevice.attach(device);
|
|
1313
|
-
const
|
|
1314
|
+
const gl2 = webglDevice.gl;
|
|
1314
1315
|
if (typeof parameters === "number") {
|
|
1315
1316
|
const key = parameters;
|
|
1316
1317
|
const getter = GL_PARAMETER_GETTERS[key];
|
|
1317
|
-
return getter ? getter(
|
|
1318
|
+
return getter ? getter(gl2, key) : gl2.getParameter(key);
|
|
1318
1319
|
}
|
|
1319
1320
|
const parameterKeys = Array.isArray(parameters) ? parameters : Object.keys(parameters);
|
|
1320
1321
|
const state = {};
|
|
1321
1322
|
for (const key of parameterKeys) {
|
|
1322
1323
|
const getter = GL_PARAMETER_GETTERS[key];
|
|
1323
|
-
state[key] = getter ? getter(
|
|
1324
|
+
state[key] = getter ? getter(gl2, Number(key)) : gl2.getParameter(Number(key));
|
|
1324
1325
|
}
|
|
1325
1326
|
return state;
|
|
1326
1327
|
}
|
|
@@ -1354,7 +1355,7 @@ function deepArrayEqual(x, y) {
|
|
|
1354
1355
|
|
|
1355
1356
|
// src/context/state-tracker/track-context-state.ts
|
|
1356
1357
|
var GLState = class {
|
|
1357
|
-
constructor(
|
|
1358
|
+
constructor(gl2, {
|
|
1358
1359
|
copyState = false,
|
|
1359
1360
|
// Copy cache from params (slow) or initialize from WebGL defaults (fast)
|
|
1360
1361
|
log: log9 = () => {
|
|
@@ -1364,8 +1365,8 @@ var GLState = class {
|
|
|
1364
1365
|
this.program = null;
|
|
1365
1366
|
this.stateStack = [];
|
|
1366
1367
|
this.enable = true;
|
|
1367
|
-
this.gl =
|
|
1368
|
-
this.cache = copyState ? getParameters(
|
|
1368
|
+
this.gl = gl2;
|
|
1369
|
+
this.cache = copyState ? getParameters(gl2) : Object.assign({}, GL_PARAMETER_DEFAULTS);
|
|
1369
1370
|
this.log = log9;
|
|
1370
1371
|
this._updateCache = this._updateCache.bind(this);
|
|
1371
1372
|
Object.seal(this);
|
|
@@ -1405,46 +1406,46 @@ var GLState = class {
|
|
|
1405
1406
|
return { valueChanged, oldValue };
|
|
1406
1407
|
}
|
|
1407
1408
|
};
|
|
1408
|
-
function getContextState(
|
|
1409
|
-
return
|
|
1409
|
+
function getContextState(gl2) {
|
|
1410
|
+
return gl2.state;
|
|
1410
1411
|
}
|
|
1411
|
-
function trackContextState(
|
|
1412
|
+
function trackContextState(gl2, options) {
|
|
1412
1413
|
const { enable: enable2 = true, copyState } = options;
|
|
1413
1414
|
(0, import_api4.assert)(copyState !== void 0);
|
|
1414
|
-
if (!
|
|
1415
|
-
|
|
1416
|
-
installProgramSpy(
|
|
1415
|
+
if (!gl2.state) {
|
|
1416
|
+
gl2.state = new GLState(gl2, { copyState });
|
|
1417
|
+
installProgramSpy(gl2);
|
|
1417
1418
|
for (const key in GL_HOOKED_SETTERS) {
|
|
1418
1419
|
const setter = GL_HOOKED_SETTERS[key];
|
|
1419
|
-
installSetterSpy(
|
|
1420
|
+
installSetterSpy(gl2, key, setter);
|
|
1420
1421
|
}
|
|
1421
|
-
installGetterOverride(
|
|
1422
|
-
installGetterOverride(
|
|
1422
|
+
installGetterOverride(gl2, "getParameter");
|
|
1423
|
+
installGetterOverride(gl2, "isEnabled");
|
|
1423
1424
|
}
|
|
1424
|
-
const glState = getContextState(
|
|
1425
|
+
const glState = getContextState(gl2);
|
|
1425
1426
|
glState.enable = enable2;
|
|
1426
|
-
return
|
|
1427
|
+
return gl2;
|
|
1427
1428
|
}
|
|
1428
|
-
function pushContextState(
|
|
1429
|
-
let glState = getContextState(
|
|
1429
|
+
function pushContextState(gl2) {
|
|
1430
|
+
let glState = getContextState(gl2);
|
|
1430
1431
|
if (!glState) {
|
|
1431
|
-
trackContextState(
|
|
1432
|
-
glState = getContextState(
|
|
1432
|
+
trackContextState(gl2, { copyState: false });
|
|
1433
|
+
glState = getContextState(gl2);
|
|
1433
1434
|
}
|
|
1434
1435
|
glState.push();
|
|
1435
1436
|
}
|
|
1436
|
-
function popContextState(
|
|
1437
|
-
const glState = getContextState(
|
|
1437
|
+
function popContextState(gl2) {
|
|
1438
|
+
const glState = getContextState(gl2);
|
|
1438
1439
|
(0, import_api4.assert)(glState);
|
|
1439
1440
|
glState.pop();
|
|
1440
1441
|
}
|
|
1441
|
-
function installGetterOverride(
|
|
1442
|
-
const originalGetterFunc =
|
|
1443
|
-
|
|
1442
|
+
function installGetterOverride(gl2, functionName) {
|
|
1443
|
+
const originalGetterFunc = gl2[functionName].bind(gl2);
|
|
1444
|
+
gl2[functionName] = function get(pname) {
|
|
1444
1445
|
if (pname === void 0 || NON_CACHE_PARAMETERS.has(pname)) {
|
|
1445
1446
|
return originalGetterFunc(pname);
|
|
1446
1447
|
}
|
|
1447
|
-
const glState = getContextState(
|
|
1448
|
+
const glState = getContextState(gl2);
|
|
1448
1449
|
if (!(pname in glState.cache)) {
|
|
1449
1450
|
glState.cache[pname] = originalGetterFunc(pname);
|
|
1450
1451
|
}
|
|
@@ -1456,33 +1457,33 @@ function installGetterOverride(gl, functionName) {
|
|
|
1456
1457
|
originalGetterFunc(pname)
|
|
1457
1458
|
);
|
|
1458
1459
|
};
|
|
1459
|
-
Object.defineProperty(
|
|
1460
|
+
Object.defineProperty(gl2[functionName], "name", {
|
|
1460
1461
|
value: `${functionName}-from-cache`,
|
|
1461
1462
|
configurable: false
|
|
1462
1463
|
});
|
|
1463
1464
|
}
|
|
1464
|
-
function installSetterSpy(
|
|
1465
|
-
if (!
|
|
1465
|
+
function installSetterSpy(gl2, functionName, setter) {
|
|
1466
|
+
if (!gl2[functionName]) {
|
|
1466
1467
|
return;
|
|
1467
1468
|
}
|
|
1468
|
-
const originalSetterFunc =
|
|
1469
|
-
|
|
1470
|
-
const glState = getContextState(
|
|
1469
|
+
const originalSetterFunc = gl2[functionName].bind(gl2);
|
|
1470
|
+
gl2[functionName] = function set(...params) {
|
|
1471
|
+
const glState = getContextState(gl2);
|
|
1471
1472
|
const { valueChanged, oldValue } = setter(glState._updateCache, ...params);
|
|
1472
1473
|
if (valueChanged) {
|
|
1473
1474
|
originalSetterFunc(...params);
|
|
1474
1475
|
}
|
|
1475
1476
|
return oldValue;
|
|
1476
1477
|
};
|
|
1477
|
-
Object.defineProperty(
|
|
1478
|
+
Object.defineProperty(gl2[functionName], "name", {
|
|
1478
1479
|
value: `${functionName}-to-cache`,
|
|
1479
1480
|
configurable: false
|
|
1480
1481
|
});
|
|
1481
1482
|
}
|
|
1482
|
-
function installProgramSpy(
|
|
1483
|
-
const originalUseProgram =
|
|
1484
|
-
|
|
1485
|
-
const glState = getContextState(
|
|
1483
|
+
function installProgramSpy(gl2) {
|
|
1484
|
+
const originalUseProgram = gl2.useProgram.bind(gl2);
|
|
1485
|
+
gl2.useProgram = function useProgramLuma(handle) {
|
|
1486
|
+
const glState = getContextState(gl2);
|
|
1486
1487
|
if (glState.program !== handle) {
|
|
1487
1488
|
originalUseProgram(handle);
|
|
1488
1489
|
glState.program = handle;
|
|
@@ -1508,21 +1509,21 @@ function createBrowserContext(canvas, props) {
|
|
|
1508
1509
|
let errorMessage = null;
|
|
1509
1510
|
const onCreateError = (error2) => errorMessage = error2.statusMessage || errorMessage;
|
|
1510
1511
|
canvas.addEventListener("webglcontextcreationerror", onCreateError, false);
|
|
1511
|
-
let
|
|
1512
|
+
let gl2 = null;
|
|
1512
1513
|
if (props.type === "webgl2") {
|
|
1513
1514
|
props = __spreadProps(__spreadValues({}, props), { webgl1: false });
|
|
1514
1515
|
}
|
|
1515
1516
|
if (props.type === "webgl1") {
|
|
1516
1517
|
props = __spreadProps(__spreadValues({}, props), { webgl2: false });
|
|
1517
1518
|
}
|
|
1518
|
-
if (!
|
|
1519
|
-
|
|
1519
|
+
if (!gl2 && props.webgl2) {
|
|
1520
|
+
gl2 = canvas.getContext("webgl2", props);
|
|
1520
1521
|
}
|
|
1521
|
-
if (!
|
|
1522
|
-
|
|
1522
|
+
if (!gl2 && props.webgl1) {
|
|
1523
|
+
gl2 = canvas.getContext("webgl", props);
|
|
1523
1524
|
}
|
|
1524
1525
|
canvas.removeEventListener("webglcontextcreationerror", onCreateError, false);
|
|
1525
|
-
if (!
|
|
1526
|
+
if (!gl2) {
|
|
1526
1527
|
throw new Error(
|
|
1527
1528
|
`Failed to create ${props.webgl2 && !props.webgl1 ? "WebGL2" : "WebGL"} context: ${errorMessage || "Unknown error"}`
|
|
1528
1529
|
);
|
|
@@ -1539,29 +1540,29 @@ function createBrowserContext(canvas, props) {
|
|
|
1539
1540
|
false
|
|
1540
1541
|
);
|
|
1541
1542
|
}
|
|
1542
|
-
return
|
|
1543
|
+
return gl2;
|
|
1543
1544
|
}
|
|
1544
1545
|
|
|
1545
1546
|
// src/adapter/device-helpers/get-device-info.ts
|
|
1546
1547
|
var import_constants4 = require("@luma.gl/constants");
|
|
1547
|
-
function getDeviceInfo(
|
|
1548
|
-
const vendorMasked =
|
|
1549
|
-
const rendererMasked =
|
|
1550
|
-
const ext =
|
|
1551
|
-
const vendorUnmasked =
|
|
1552
|
-
const rendererUnmasked =
|
|
1548
|
+
function getDeviceInfo(gl2) {
|
|
1549
|
+
const vendorMasked = gl2.getParameter(import_constants4.GL.VENDOR);
|
|
1550
|
+
const rendererMasked = gl2.getParameter(import_constants4.GL.RENDERER);
|
|
1551
|
+
const ext = gl2.getExtension("WEBGL_debug_renderer_info");
|
|
1552
|
+
const vendorUnmasked = gl2.getParameter(ext ? ext.UNMASKED_VENDOR_WEBGL : import_constants4.GL.VENDOR);
|
|
1553
|
+
const rendererUnmasked = gl2.getParameter(ext ? ext.UNMASKED_RENDERER_WEBGL : import_constants4.GL.RENDERER);
|
|
1553
1554
|
const vendor = vendorUnmasked || vendorMasked;
|
|
1554
1555
|
const renderer = rendererUnmasked || rendererMasked;
|
|
1555
1556
|
const gpu = identifyGPUVendor(vendor, renderer);
|
|
1556
1557
|
return {
|
|
1557
|
-
type: isWebGL2(
|
|
1558
|
+
type: isWebGL2(gl2) ? "webgl2" : "webgl",
|
|
1558
1559
|
gpu,
|
|
1559
1560
|
vendor: vendorUnmasked || vendorMasked,
|
|
1560
1561
|
renderer: rendererUnmasked || rendererMasked,
|
|
1561
|
-
version:
|
|
1562
|
+
version: gl2.getParameter(import_constants4.GL.VERSION),
|
|
1562
1563
|
shadingLanguages: ["glsl"],
|
|
1563
1564
|
shadingLanguageVersions: {
|
|
1564
|
-
"glsl":
|
|
1565
|
+
"glsl": gl2.getParameter(import_constants4.GL.SHADING_LANGUAGE_VERSION)
|
|
1565
1566
|
}
|
|
1566
1567
|
};
|
|
1567
1568
|
}
|
|
@@ -1615,39 +1616,39 @@ var EXT_SRGB = "EXT_sRGB";
|
|
|
1615
1616
|
var EXT_TEXTURE_NORM16 = "EXT_texture_norm16";
|
|
1616
1617
|
var EXT_FLOAT_WEBGL1 = "WEBGL_color_buffer_float";
|
|
1617
1618
|
var EXT_FLOAT_RENDER_WEBGL2 = "EXT_color_buffer_float";
|
|
1618
|
-
var checkExtension = (
|
|
1619
|
-
var checkExtensions = (
|
|
1619
|
+
var checkExtension = (gl2, extension) => gl2.getExtension(extension);
|
|
1620
|
+
var checkExtensions = (gl2, extensions) => extensions.every((extension) => gl2.getExtension(extension));
|
|
1620
1621
|
var TEXTURE_FEATURE_CHECKS = {
|
|
1621
|
-
"texture-blend-float-webgl1": (
|
|
1622
|
-
"texture-formats-srgb-webgl1": (
|
|
1623
|
-
"texture-formats-depth-webgl1": (
|
|
1624
|
-
"texture-formats-float32-webgl1": (
|
|
1625
|
-
"texture-formats-float16-webgl1": (
|
|
1626
|
-
"texture-formats-norm16-webgl": (
|
|
1627
|
-
"texture-filter-linear-float32-webgl": (
|
|
1628
|
-
"texture-filter-linear-float16-webgl": (
|
|
1629
|
-
"texture-filter-anisotropic-webgl": (
|
|
1630
|
-
"texture-renderable-float32-webgl": (
|
|
1622
|
+
"texture-blend-float-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "EXT_float_blend"),
|
|
1623
|
+
"texture-formats-srgb-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, EXT_SRGB),
|
|
1624
|
+
"texture-formats-depth-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "WEBGL_depth_texture"),
|
|
1625
|
+
"texture-formats-float32-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "OES_texture_float"),
|
|
1626
|
+
"texture-formats-float16-webgl1": (gl2) => isWebGL2(gl2) ? true : checkExtension(gl2, "OES_texture_half_float"),
|
|
1627
|
+
"texture-formats-norm16-webgl": (gl2) => isWebGL2(gl2) ? checkExtension(gl2, EXT_TEXTURE_NORM16) : false,
|
|
1628
|
+
"texture-filter-linear-float32-webgl": (gl2) => checkExtension(gl2, "OES_texture_float_linear"),
|
|
1629
|
+
"texture-filter-linear-float16-webgl": (gl2) => checkExtension(gl2, "OES_texture_half_float_linear"),
|
|
1630
|
+
"texture-filter-anisotropic-webgl": (gl2) => checkExtension(gl2, "EXT_texture_filter_anisotropic"),
|
|
1631
|
+
"texture-renderable-float32-webgl": (gl2) => checkExtension(gl2, "EXT_color_buffer_float"),
|
|
1631
1632
|
// [false, 'EXT_color_buffer_float'],
|
|
1632
|
-
"texture-renderable-float16-webgl": (
|
|
1633
|
-
"texture-compression-bc": (
|
|
1634
|
-
"texture-compression-bc5-webgl": (
|
|
1633
|
+
"texture-renderable-float16-webgl": (gl2) => checkExtension(gl2, "EXT_color_buffer_half_float"),
|
|
1634
|
+
"texture-compression-bc": (gl2) => checkExtensions(gl2, [X_S3TC, X_S3TC_SRGB, X_RGTC, X_BPTC]),
|
|
1635
|
+
"texture-compression-bc5-webgl": (gl2) => checkExtensions(gl2, [X_RGTC]),
|
|
1635
1636
|
// 'texture-compression-bc7-webgl': gl => checkExtensions(gl, [X_BPTC]),
|
|
1636
1637
|
// 'texture-compression-bc3-srgb-webgl': gl => checkExtensions(gl, [X_S3TC_SRGB]),
|
|
1637
1638
|
// 'texture-compression-bc3-webgl': gl => checkExtensions(gl, [X_S3TC]),
|
|
1638
|
-
"texture-compression-etc2": (
|
|
1639
|
-
"texture-compression-astc": (
|
|
1640
|
-
"texture-compression-etc1-webgl": (
|
|
1641
|
-
"texture-compression-pvrtc-webgl": (
|
|
1642
|
-
"texture-compression-atc-webgl": (
|
|
1639
|
+
"texture-compression-etc2": (gl2) => checkExtensions(gl2, [X_ETC2]),
|
|
1640
|
+
"texture-compression-astc": (gl2) => checkExtensions(gl2, [X_ASTC]),
|
|
1641
|
+
"texture-compression-etc1-webgl": (gl2) => checkExtensions(gl2, [X_ETC1]),
|
|
1642
|
+
"texture-compression-pvrtc-webgl": (gl2) => checkExtensions(gl2, [X_PVRTC]),
|
|
1643
|
+
"texture-compression-atc-webgl": (gl2) => checkExtensions(gl2, [X_ATC])
|
|
1643
1644
|
};
|
|
1644
|
-
function checkTextureFeature(
|
|
1645
|
+
function checkTextureFeature(gl2, feature) {
|
|
1645
1646
|
var _a;
|
|
1646
|
-
return ((_a = TEXTURE_FEATURE_CHECKS[feature]) == null ? void 0 : _a.call(TEXTURE_FEATURE_CHECKS,
|
|
1647
|
+
return ((_a = TEXTURE_FEATURE_CHECKS[feature]) == null ? void 0 : _a.call(TEXTURE_FEATURE_CHECKS, gl2)) || false;
|
|
1647
1648
|
}
|
|
1648
|
-
function getTextureFeatures(
|
|
1649
|
+
function getTextureFeatures(gl2) {
|
|
1649
1650
|
const textureFeatures = Object.keys(TEXTURE_FEATURE_CHECKS);
|
|
1650
|
-
return textureFeatures.filter((feature) => checkTextureFeature(
|
|
1651
|
+
return textureFeatures.filter((feature) => checkTextureFeature(gl2, feature));
|
|
1651
1652
|
}
|
|
1652
1653
|
var TEXTURE_FORMATS = {
|
|
1653
1654
|
// Unsized formats that leave the precision up to the driver.
|
|
@@ -1855,24 +1856,24 @@ var TYPE_SIZES = {
|
|
|
1855
1856
|
[import_constants5.GL.BYTE]: 1,
|
|
1856
1857
|
[import_constants5.GL.UNSIGNED_BYTE]: 1
|
|
1857
1858
|
};
|
|
1858
|
-
function isTextureFormatSupported(
|
|
1859
|
+
function isTextureFormatSupported(gl2, formatOrGL) {
|
|
1859
1860
|
const format = convertGLToTextureFormat(formatOrGL);
|
|
1860
1861
|
const info = TEXTURE_FORMATS[format];
|
|
1861
1862
|
if (!info) {
|
|
1862
1863
|
return false;
|
|
1863
1864
|
}
|
|
1864
|
-
if (isWebGL2(
|
|
1865
|
+
if (isWebGL2(gl2) ? info.gl === void 0 : info.gl1 === void 0) {
|
|
1865
1866
|
return false;
|
|
1866
1867
|
}
|
|
1867
|
-
const extension = info.x || (isWebGL2(
|
|
1868
|
+
const extension = info.x || (isWebGL2(gl2) ? info.gl2ext || info.gl1ext : info.gl1ext);
|
|
1868
1869
|
if (extension) {
|
|
1869
|
-
return Boolean(
|
|
1870
|
+
return Boolean(gl2.getExtension(extension));
|
|
1870
1871
|
}
|
|
1871
1872
|
return true;
|
|
1872
1873
|
}
|
|
1873
|
-
function isRenderbufferFormatSupported(
|
|
1874
|
+
function isRenderbufferFormatSupported(gl2, format) {
|
|
1874
1875
|
var _a;
|
|
1875
|
-
return isTextureFormatSupported(
|
|
1876
|
+
return isTextureFormatSupported(gl2, format) && ((_a = TEXTURE_FORMATS[format]) == null ? void 0 : _a.renderbuffer);
|
|
1876
1877
|
}
|
|
1877
1878
|
function convertGLToTextureFormat(format) {
|
|
1878
1879
|
if (typeof format === "string") {
|
|
@@ -1894,9 +1895,9 @@ function convertTextureFormatToGL(format, isWebGL23) {
|
|
|
1894
1895
|
}
|
|
1895
1896
|
return webglFormat;
|
|
1896
1897
|
}
|
|
1897
|
-
function isTextureFormatFilterable(
|
|
1898
|
+
function isTextureFormatFilterable(gl2, formatOrGL) {
|
|
1898
1899
|
const format = convertGLToTextureFormat(formatOrGL);
|
|
1899
|
-
if (!isTextureFormatSupported(
|
|
1900
|
+
if (!isTextureFormatSupported(gl2, format)) {
|
|
1900
1901
|
return false;
|
|
1901
1902
|
}
|
|
1902
1903
|
try {
|
|
@@ -1908,16 +1909,16 @@ function isTextureFormatFilterable(gl, formatOrGL) {
|
|
|
1908
1909
|
return false;
|
|
1909
1910
|
}
|
|
1910
1911
|
if (format.endsWith("32float")) {
|
|
1911
|
-
return Boolean(
|
|
1912
|
+
return Boolean(gl2.getExtension("OES_texture_float_linear"));
|
|
1912
1913
|
}
|
|
1913
1914
|
if (format.endsWith("16float")) {
|
|
1914
|
-
return Boolean(
|
|
1915
|
+
return Boolean(gl2.getExtension("OES_texture_half_float_linear"));
|
|
1915
1916
|
}
|
|
1916
1917
|
return true;
|
|
1917
1918
|
}
|
|
1918
|
-
function isTextureFormatRenderable(
|
|
1919
|
+
function isTextureFormatRenderable(gl2, formatOrGL) {
|
|
1919
1920
|
const format = convertGLToTextureFormat(formatOrGL);
|
|
1920
|
-
if (!isTextureFormatSupported(
|
|
1921
|
+
if (!isTextureFormatSupported(gl2, format)) {
|
|
1921
1922
|
return false;
|
|
1922
1923
|
}
|
|
1923
1924
|
if (typeof format === "number") {
|
|
@@ -1949,19 +1950,19 @@ function getDepthStencilAttachmentWebGL(format) {
|
|
|
1949
1950
|
}
|
|
1950
1951
|
return info.attachment;
|
|
1951
1952
|
}
|
|
1952
|
-
function _checkFloat32ColorAttachment(
|
|
1953
|
+
function _checkFloat32ColorAttachment(gl2, internalFormat = gl2.RGBA, srcFormat = import_constants5.GL.RGBA, srcType = import_constants5.GL.UNSIGNED_BYTE) {
|
|
1953
1954
|
let texture = null;
|
|
1954
1955
|
let framebuffer = null;
|
|
1955
1956
|
try {
|
|
1956
|
-
texture =
|
|
1957
|
-
|
|
1957
|
+
texture = gl2.createTexture();
|
|
1958
|
+
gl2.bindTexture(import_constants5.GL.TEXTURE_2D, texture);
|
|
1958
1959
|
const level = 0;
|
|
1959
1960
|
const width = 1;
|
|
1960
1961
|
const height = 1;
|
|
1961
1962
|
const border = 0;
|
|
1962
1963
|
const pixel = new Uint8Array([0, 0, 255, 255]);
|
|
1963
|
-
|
|
1964
|
-
|
|
1964
|
+
gl2.texImage2D(
|
|
1965
|
+
gl2.TEXTURE_2D,
|
|
1965
1966
|
level,
|
|
1966
1967
|
internalFormat,
|
|
1967
1968
|
width,
|
|
@@ -1971,15 +1972,15 @@ function _checkFloat32ColorAttachment(gl, internalFormat = gl.RGBA, srcFormat =
|
|
|
1971
1972
|
srcType,
|
|
1972
1973
|
pixel
|
|
1973
1974
|
);
|
|
1974
|
-
framebuffer =
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
const status =
|
|
1978
|
-
|
|
1975
|
+
framebuffer = gl2.createFramebuffer();
|
|
1976
|
+
gl2.bindFramebuffer(import_constants5.GL.FRAMEBUFFER, framebuffer);
|
|
1977
|
+
gl2.framebufferTexture2D(import_constants5.GL.FRAMEBUFFER, import_constants5.GL.COLOR_ATTACHMENT0, import_constants5.GL.TEXTURE_2D, texture, 0);
|
|
1978
|
+
const status = gl2.checkFramebufferStatus(import_constants5.GL.FRAMEBUFFER) === import_constants5.GL.FRAMEBUFFER_COMPLETE;
|
|
1979
|
+
gl2.bindTexture(import_constants5.GL.TEXTURE_2D, null);
|
|
1979
1980
|
return status;
|
|
1980
1981
|
} finally {
|
|
1981
|
-
|
|
1982
|
-
|
|
1982
|
+
gl2.deleteTexture(texture);
|
|
1983
|
+
gl2.deleteFramebuffer(framebuffer);
|
|
1983
1984
|
}
|
|
1984
1985
|
}
|
|
1985
1986
|
function getTextureFormatBytesPerPixel(formatOrGL, isWebGL23) {
|
|
@@ -2030,50 +2031,50 @@ function getWebGLDataType(dataType) {
|
|
|
2030
2031
|
}
|
|
2031
2032
|
|
|
2032
2033
|
// src/adapter/device-helpers/device-features.ts
|
|
2033
|
-
function getDeviceFeatures(
|
|
2034
|
-
const features = getWebGLFeatures(
|
|
2035
|
-
for (const textureFeature of getTextureFeatures(
|
|
2034
|
+
function getDeviceFeatures(gl2) {
|
|
2035
|
+
const features = getWebGLFeatures(gl2);
|
|
2036
|
+
for (const textureFeature of getTextureFeatures(gl2)) {
|
|
2036
2037
|
features.add(textureFeature);
|
|
2037
2038
|
}
|
|
2038
2039
|
return features;
|
|
2039
2040
|
}
|
|
2040
|
-
function getWebGLFeatures(
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2041
|
+
function getWebGLFeatures(gl2) {
|
|
2042
|
+
gl2.getExtension("EXT_color_buffer_float");
|
|
2043
|
+
gl2.getExtension("WEBGL_color_buffer_float");
|
|
2044
|
+
gl2.getExtension("EXT_float_blend");
|
|
2044
2045
|
const features = /* @__PURE__ */ new Set();
|
|
2045
2046
|
for (const feature of Object.keys(WEBGL_FEATURES)) {
|
|
2046
|
-
if (isFeatureSupported(
|
|
2047
|
+
if (isFeatureSupported(gl2, feature)) {
|
|
2047
2048
|
features.add(feature);
|
|
2048
2049
|
}
|
|
2049
2050
|
}
|
|
2050
2051
|
return features;
|
|
2051
2052
|
}
|
|
2052
|
-
function isFeatureSupported(
|
|
2053
|
+
function isFeatureSupported(gl2, feature) {
|
|
2053
2054
|
const featureInfo = WEBGL_FEATURES[feature];
|
|
2054
2055
|
if (!featureInfo) {
|
|
2055
2056
|
return false;
|
|
2056
2057
|
}
|
|
2057
2058
|
const [webgl1Feature, webgl2Feature] = featureInfo || [];
|
|
2058
|
-
const featureDefinition = isWebGL2(
|
|
2059
|
+
const featureDefinition = isWebGL2(gl2) ? webgl2Feature : webgl1Feature;
|
|
2059
2060
|
if (typeof featureDefinition === "boolean") {
|
|
2060
2061
|
return featureDefinition;
|
|
2061
2062
|
}
|
|
2062
2063
|
switch (feature) {
|
|
2063
2064
|
case "texture-renderable-rgba32float-webgl":
|
|
2064
|
-
return isWebGL2(
|
|
2065
|
+
return isWebGL2(gl2) ? Boolean(gl2.getExtension(featureDefinition)) : _checkFloat32ColorAttachment(gl2);
|
|
2065
2066
|
case "glsl-derivatives":
|
|
2066
|
-
return canCompileGLSLExtension(
|
|
2067
|
+
return canCompileGLSLExtension(gl2, featureDefinition);
|
|
2067
2068
|
case "glsl-frag-data":
|
|
2068
|
-
return canCompileGLSLExtension(
|
|
2069
|
+
return canCompileGLSLExtension(gl2, featureDefinition, { behavior: "require" });
|
|
2069
2070
|
case "glsl-frag-depth":
|
|
2070
|
-
return canCompileGLSLExtension(
|
|
2071
|
+
return canCompileGLSLExtension(gl2, featureDefinition);
|
|
2071
2072
|
default:
|
|
2072
|
-
return Boolean(
|
|
2073
|
+
return Boolean(gl2.getExtension(featureDefinition));
|
|
2073
2074
|
}
|
|
2074
2075
|
}
|
|
2075
2076
|
var compiledGLSLExtensions = {};
|
|
2076
|
-
function canCompileGLSLExtension(
|
|
2077
|
+
function canCompileGLSLExtension(gl2, extensionName, opts = {}) {
|
|
2077
2078
|
if (!isOldIE(opts)) {
|
|
2078
2079
|
return true;
|
|
2079
2080
|
}
|
|
@@ -2083,14 +2084,14 @@ function canCompileGLSLExtension(gl, extensionName, opts = {}) {
|
|
|
2083
2084
|
const behavior = opts.behavior || "enable";
|
|
2084
2085
|
const source = `#extension GL_${extensionName} : ${behavior}
|
|
2085
2086
|
void main(void) {}`;
|
|
2086
|
-
const shader =
|
|
2087
|
+
const shader = gl2.createShader(gl2.VERTEX_SHADER);
|
|
2087
2088
|
if (!shader) {
|
|
2088
2089
|
throw new Error("shader");
|
|
2089
2090
|
}
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
const canCompile =
|
|
2093
|
-
|
|
2091
|
+
gl2.shaderSource(shader, source);
|
|
2092
|
+
gl2.compileShader(shader);
|
|
2093
|
+
const canCompile = gl2.getShaderParameter(shader, gl2.COMPILE_STATUS);
|
|
2094
|
+
gl2.deleteShader(shader);
|
|
2094
2095
|
compiledGLSLExtensions[extensionName] = canCompile;
|
|
2095
2096
|
return canCompile;
|
|
2096
2097
|
}
|
|
@@ -2128,38 +2129,38 @@ var WEBGL_FEATURES = {
|
|
|
2128
2129
|
|
|
2129
2130
|
// src/adapter/device-helpers/device-limits.ts
|
|
2130
2131
|
var import_constants6 = require("@luma.gl/constants");
|
|
2131
|
-
function getDeviceLimits(
|
|
2132
|
-
const
|
|
2132
|
+
function getDeviceLimits(gl2) {
|
|
2133
|
+
const gl22 = getWebGL2Context(gl2);
|
|
2133
2134
|
return {
|
|
2134
2135
|
maxTextureDimension1D: 0,
|
|
2135
2136
|
// WebGL does not support 1D textures
|
|
2136
|
-
maxTextureDimension2D:
|
|
2137
|
-
maxTextureDimension3D:
|
|
2138
|
-
maxTextureArrayLayers:
|
|
2137
|
+
maxTextureDimension2D: gl2.getParameter(import_constants6.GL.MAX_TEXTURE_SIZE),
|
|
2138
|
+
maxTextureDimension3D: gl22 ? gl22.getParameter(import_constants6.GL.MAX_3D_TEXTURE_SIZE) : 0,
|
|
2139
|
+
maxTextureArrayLayers: gl22 ? gl22.getParameter(import_constants6.GL.MAX_ARRAY_TEXTURE_LAYERS) : 0,
|
|
2139
2140
|
maxBindGroups: 1,
|
|
2140
2141
|
// TBD
|
|
2141
2142
|
maxDynamicUniformBuffersPerPipelineLayout: 0,
|
|
2142
2143
|
// TBD
|
|
2143
2144
|
maxDynamicStorageBuffersPerPipelineLayout: 0,
|
|
2144
2145
|
// TBD
|
|
2145
|
-
maxSampledTexturesPerShaderStage:
|
|
2146
|
+
maxSampledTexturesPerShaderStage: gl2.getParameter(import_constants6.GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
|
|
2146
2147
|
// TBD
|
|
2147
|
-
maxSamplersPerShaderStage:
|
|
2148
|
+
maxSamplersPerShaderStage: gl2.getParameter(import_constants6.GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
|
|
2148
2149
|
maxStorageBuffersPerShaderStage: 0,
|
|
2149
2150
|
// TBD
|
|
2150
2151
|
maxStorageTexturesPerShaderStage: 0,
|
|
2151
2152
|
// TBD
|
|
2152
|
-
maxUniformBuffersPerShaderStage:
|
|
2153
|
-
maxUniformBufferBindingSize:
|
|
2153
|
+
maxUniformBuffersPerShaderStage: gl22 ? gl22.getParameter(import_constants6.GL.MAX_UNIFORM_BUFFER_BINDINGS) : 0,
|
|
2154
|
+
maxUniformBufferBindingSize: gl22 ? gl22.getParameter(import_constants6.GL.MAX_UNIFORM_BLOCK_SIZE) : 0,
|
|
2154
2155
|
maxStorageBufferBindingSize: 0,
|
|
2155
|
-
minUniformBufferOffsetAlignment:
|
|
2156
|
+
minUniformBufferOffsetAlignment: gl22 ? gl22.getParameter(import_constants6.GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT) : 0,
|
|
2156
2157
|
minStorageBufferOffsetAlignment: 0,
|
|
2157
2158
|
// TBD
|
|
2158
2159
|
maxVertexBuffers: 0,
|
|
2159
|
-
maxVertexAttributes:
|
|
2160
|
+
maxVertexAttributes: gl2.getParameter(import_constants6.GL.MAX_VERTEX_ATTRIBS),
|
|
2160
2161
|
maxVertexBufferArrayStride: 2048,
|
|
2161
2162
|
// TBD, this is just the default value from WebGPU
|
|
2162
|
-
maxInterStageShaderComponents:
|
|
2163
|
+
maxInterStageShaderComponents: gl22 ? gl22.getParameter(import_constants6.GL.MAX_VARYING_COMPONENTS) : 0,
|
|
2163
2164
|
maxComputeWorkgroupStorageSize: 0,
|
|
2164
2165
|
// WebGL does not support compute shaders
|
|
2165
2166
|
maxComputeInvocationsPerWorkgroup: 0,
|
|
@@ -2174,13 +2175,13 @@ function getDeviceLimits(gl) {
|
|
|
2174
2175
|
// WebGL does not support compute shaders
|
|
2175
2176
|
};
|
|
2176
2177
|
}
|
|
2177
|
-
function getWebGLLimits(
|
|
2178
|
-
const
|
|
2178
|
+
function getWebGLLimits(gl2) {
|
|
2179
|
+
const gl22 = getWebGL2Context(gl2);
|
|
2179
2180
|
function get(pname) {
|
|
2180
|
-
return
|
|
2181
|
+
return gl2.getParameter(pname);
|
|
2181
2182
|
}
|
|
2182
2183
|
function get2(pname, defaultValue) {
|
|
2183
|
-
return
|
|
2184
|
+
return gl22 ? gl22.getParameter(pname) : defaultValue || 0;
|
|
2184
2185
|
}
|
|
2185
2186
|
return {
|
|
2186
2187
|
[import_constants6.GL.ALIASED_LINE_WIDTH_RANGE]: get(import_constants6.GL.ALIASED_LINE_WIDTH_RANGE),
|
|
@@ -2285,22 +2286,22 @@ var import_constants11 = require("@luma.gl/constants");
|
|
|
2285
2286
|
// src/context/state-tracker/with-parameters.ts
|
|
2286
2287
|
function withParameters(device, parameters, func) {
|
|
2287
2288
|
const webglDevice = WebGLDevice.attach(device);
|
|
2288
|
-
const
|
|
2289
|
+
const gl2 = webglDevice.gl;
|
|
2289
2290
|
if (isObjectEmpty2(parameters)) {
|
|
2290
2291
|
return func(device);
|
|
2291
2292
|
}
|
|
2292
2293
|
const { nocatch = true } = parameters;
|
|
2293
|
-
pushContextState(
|
|
2294
|
-
setParameters(
|
|
2294
|
+
pushContextState(gl2);
|
|
2295
|
+
setParameters(gl2, parameters);
|
|
2295
2296
|
let value;
|
|
2296
2297
|
if (nocatch) {
|
|
2297
|
-
value = func(
|
|
2298
|
-
popContextState(
|
|
2298
|
+
value = func(gl2);
|
|
2299
|
+
popContextState(gl2);
|
|
2299
2300
|
} else {
|
|
2300
2301
|
try {
|
|
2301
|
-
value = func(
|
|
2302
|
+
value = func(gl2);
|
|
2302
2303
|
} finally {
|
|
2303
|
-
popContextState(
|
|
2304
|
+
popContextState(gl2);
|
|
2304
2305
|
}
|
|
2305
2306
|
}
|
|
2306
2307
|
return value;
|
|
@@ -2344,24 +2345,24 @@ function withDeviceParameters(device, parameters, func) {
|
|
|
2344
2345
|
}
|
|
2345
2346
|
function setDeviceParameters(device, parameters) {
|
|
2346
2347
|
const webglDevice = WebGLDevice.attach(device);
|
|
2347
|
-
const { gl } = webglDevice;
|
|
2348
|
+
const { gl: gl2 } = webglDevice;
|
|
2348
2349
|
if (parameters.cullMode) {
|
|
2349
2350
|
switch (parameters.cullMode) {
|
|
2350
2351
|
case "none":
|
|
2351
|
-
|
|
2352
|
+
gl2.disable(import_constants7.GL.CULL_FACE);
|
|
2352
2353
|
break;
|
|
2353
2354
|
case "front":
|
|
2354
|
-
|
|
2355
|
-
|
|
2355
|
+
gl2.enable(import_constants7.GL.CULL_FACE);
|
|
2356
|
+
gl2.cullFace(import_constants7.GL.FRONT);
|
|
2356
2357
|
break;
|
|
2357
2358
|
case "back":
|
|
2358
|
-
|
|
2359
|
-
|
|
2359
|
+
gl2.enable(import_constants7.GL.CULL_FACE);
|
|
2360
|
+
gl2.cullFace(import_constants7.GL.BACK);
|
|
2360
2361
|
break;
|
|
2361
2362
|
}
|
|
2362
2363
|
}
|
|
2363
2364
|
if (parameters.frontFace) {
|
|
2364
|
-
|
|
2365
|
+
gl2.frontFace(
|
|
2365
2366
|
map("frontFace", parameters.frontFace, {
|
|
2366
2367
|
ccw: import_constants7.GL.CCW,
|
|
2367
2368
|
cw: import_constants7.GL.CW
|
|
@@ -2369,19 +2370,19 @@ function setDeviceParameters(device, parameters) {
|
|
|
2369
2370
|
);
|
|
2370
2371
|
}
|
|
2371
2372
|
if (parameters.depthBias !== void 0) {
|
|
2372
|
-
|
|
2373
|
+
gl2.polygonOffset(parameters.depthBias, parameters.depthBiasSlopeScale || 0);
|
|
2373
2374
|
}
|
|
2374
2375
|
if (parameters.depthWriteEnabled !== void 0) {
|
|
2375
|
-
|
|
2376
|
+
gl2.depthMask(mapBoolean("depthWriteEnabled", parameters.depthWriteEnabled));
|
|
2376
2377
|
}
|
|
2377
2378
|
if (parameters.depthCompare) {
|
|
2378
|
-
parameters.depthCompare !== "always" ?
|
|
2379
|
-
|
|
2379
|
+
parameters.depthCompare !== "always" ? gl2.enable(import_constants7.GL.DEPTH_TEST) : gl2.disable(import_constants7.GL.DEPTH_TEST);
|
|
2380
|
+
gl2.depthFunc(convertCompareFunction("depthCompare", parameters.depthCompare));
|
|
2380
2381
|
}
|
|
2381
2382
|
if (parameters.stencilWriteMask) {
|
|
2382
2383
|
const mask = parameters.stencilWriteMask;
|
|
2383
|
-
|
|
2384
|
-
|
|
2384
|
+
gl2.stencilMaskSeparate(import_constants7.GL.FRONT, mask);
|
|
2385
|
+
gl2.stencilMaskSeparate(import_constants7.GL.BACK, mask);
|
|
2385
2386
|
}
|
|
2386
2387
|
if (parameters.stencilReadMask) {
|
|
2387
2388
|
import_api6.log.warn("stencilReadMask not supported under WebGL");
|
|
@@ -2389,9 +2390,9 @@ function setDeviceParameters(device, parameters) {
|
|
|
2389
2390
|
if (parameters.stencilCompare) {
|
|
2390
2391
|
const mask = parameters.stencilReadMask || 4294967295;
|
|
2391
2392
|
const glValue = convertCompareFunction("depthCompare", parameters.stencilCompare);
|
|
2392
|
-
parameters.stencilCompare !== "always" ?
|
|
2393
|
-
|
|
2394
|
-
|
|
2393
|
+
parameters.stencilCompare !== "always" ? gl2.enable(import_constants7.GL.STENCIL_TEST) : gl2.disable(import_constants7.GL.STENCIL_TEST);
|
|
2394
|
+
gl2.stencilFuncSeparate(import_constants7.GL.FRONT, glValue, 0, mask);
|
|
2395
|
+
gl2.stencilFuncSeparate(import_constants7.GL.BACK, glValue, 0, mask);
|
|
2395
2396
|
}
|
|
2396
2397
|
if (parameters.stencilPassOperation && parameters.stencilFailOperation && parameters.stencilDepthFailOperation) {
|
|
2397
2398
|
const dppass = convertStencilOperation("stencilPassOperation", parameters.stencilPassOperation);
|
|
@@ -2400,8 +2401,8 @@ function setDeviceParameters(device, parameters) {
|
|
|
2400
2401
|
"stencilDepthFailOperation",
|
|
2401
2402
|
parameters.stencilDepthFailOperation
|
|
2402
2403
|
);
|
|
2403
|
-
|
|
2404
|
-
|
|
2404
|
+
gl2.stencilOpSeparate(import_constants7.GL.FRONT, sfail, dpfail, dppass);
|
|
2405
|
+
gl2.stencilOpSeparate(import_constants7.GL.BACK, sfail, dpfail, dppass);
|
|
2405
2406
|
}
|
|
2406
2407
|
}
|
|
2407
2408
|
function convertCompareFunction(parameter, value) {
|
|
@@ -2947,18 +2948,18 @@ var _WEBGLTexture = class extends import_api10.Texture {
|
|
|
2947
2948
|
width,
|
|
2948
2949
|
height
|
|
2949
2950
|
}));
|
|
2950
|
-
const { gl } = this;
|
|
2951
|
-
|
|
2951
|
+
const { gl: gl2 } = this;
|
|
2952
|
+
gl2.bindTexture(this.target, this.handle);
|
|
2952
2953
|
let dataType = null;
|
|
2953
2954
|
({ data, dataType } = this._getDataType({ data, compressed }));
|
|
2954
|
-
let
|
|
2955
|
+
let gl22;
|
|
2955
2956
|
withParameters(this.gl, parameters, () => {
|
|
2956
2957
|
switch (dataType) {
|
|
2957
2958
|
case "null":
|
|
2958
|
-
|
|
2959
|
+
gl2.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
|
|
2959
2960
|
break;
|
|
2960
2961
|
case "typed-array":
|
|
2961
|
-
|
|
2962
|
+
gl2.texImage2D(
|
|
2962
2963
|
target,
|
|
2963
2964
|
level,
|
|
2964
2965
|
glFormat,
|
|
@@ -2974,9 +2975,9 @@ var _WEBGLTexture = class extends import_api10.Texture {
|
|
|
2974
2975
|
);
|
|
2975
2976
|
break;
|
|
2976
2977
|
case "buffer":
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2978
|
+
gl22 = this.device.assertWebGL2();
|
|
2979
|
+
gl22.bindBuffer(import_constants11.GL.PIXEL_UNPACK_BUFFER, data.handle || data);
|
|
2980
|
+
gl22.texImage2D(
|
|
2980
2981
|
target,
|
|
2981
2982
|
level,
|
|
2982
2983
|
glFormat,
|
|
@@ -2987,11 +2988,11 @@ var _WEBGLTexture = class extends import_api10.Texture {
|
|
|
2987
2988
|
type,
|
|
2988
2989
|
offset
|
|
2989
2990
|
);
|
|
2990
|
-
|
|
2991
|
+
gl22.bindBuffer(import_constants11.GL.PIXEL_UNPACK_BUFFER, null);
|
|
2991
2992
|
break;
|
|
2992
2993
|
case "browser-object":
|
|
2993
2994
|
if (this.device.isWebGL2) {
|
|
2994
|
-
|
|
2995
|
+
gl2.texImage2D(
|
|
2995
2996
|
target,
|
|
2996
2997
|
level,
|
|
2997
2998
|
glFormat,
|
|
@@ -3003,12 +3004,12 @@ var _WEBGLTexture = class extends import_api10.Texture {
|
|
|
3003
3004
|
data
|
|
3004
3005
|
);
|
|
3005
3006
|
} else {
|
|
3006
|
-
|
|
3007
|
+
gl2.texImage2D(target, level, glFormat, dataFormat, type, data);
|
|
3007
3008
|
}
|
|
3008
3009
|
break;
|
|
3009
3010
|
case "compressed":
|
|
3010
3011
|
for (const [levelIndex, levelData] of data.entries()) {
|
|
3011
|
-
|
|
3012
|
+
gl2.compressedTexImage2D(
|
|
3012
3013
|
target,
|
|
3013
3014
|
levelIndex,
|
|
3014
3015
|
levelData.format,
|
|
@@ -3115,21 +3116,21 @@ var _WEBGLTexture = class extends import_api10.Texture {
|
|
|
3115
3116
|
return this.gl.getParameter(import_constants11.GL.ACTIVE_TEXTURE) - import_constants11.GL.TEXTURE0;
|
|
3116
3117
|
}
|
|
3117
3118
|
bind(textureUnit = this.textureUnit) {
|
|
3118
|
-
const { gl } = this;
|
|
3119
|
+
const { gl: gl2 } = this;
|
|
3119
3120
|
if (textureUnit !== void 0) {
|
|
3120
3121
|
this.textureUnit = textureUnit;
|
|
3121
|
-
|
|
3122
|
+
gl2.activeTexture(gl2.TEXTURE0 + textureUnit);
|
|
3122
3123
|
}
|
|
3123
|
-
|
|
3124
|
+
gl2.bindTexture(this.target, this.handle);
|
|
3124
3125
|
return textureUnit;
|
|
3125
3126
|
}
|
|
3126
3127
|
unbind(textureUnit = this.textureUnit) {
|
|
3127
|
-
const { gl } = this;
|
|
3128
|
+
const { gl: gl2 } = this;
|
|
3128
3129
|
if (textureUnit !== void 0) {
|
|
3129
3130
|
this.textureUnit = textureUnit;
|
|
3130
|
-
|
|
3131
|
+
gl2.activeTexture(gl2.TEXTURE0 + textureUnit);
|
|
3131
3132
|
}
|
|
3132
|
-
|
|
3133
|
+
gl2.bindTexture(this.target, null);
|
|
3133
3134
|
return textureUnit;
|
|
3134
3135
|
}
|
|
3135
3136
|
// PRIVATE METHODS
|
|
@@ -3195,7 +3196,7 @@ var _WEBGLTexture = class extends import_api10.Texture {
|
|
|
3195
3196
|
/* eslint-disable max-statements, max-len */
|
|
3196
3197
|
setCubeMapImageData(options) {
|
|
3197
3198
|
return __async(this, null, function* () {
|
|
3198
|
-
const { gl } = this;
|
|
3199
|
+
const { gl: gl2 } = this;
|
|
3199
3200
|
const { width, height, pixels, data, format = import_constants11.GL.RGBA, type = import_constants11.GL.UNSIGNED_BYTE } = options;
|
|
3200
3201
|
const imageDataMap = pixels || data;
|
|
3201
3202
|
const resolvedFaces = yield Promise.all(
|
|
@@ -3211,9 +3212,9 @@ var _WEBGLTexture = class extends import_api10.Texture {
|
|
|
3211
3212
|
}
|
|
3212
3213
|
resolvedFaces[index].forEach((image, lodLevel) => {
|
|
3213
3214
|
if (width && height) {
|
|
3214
|
-
|
|
3215
|
+
gl2.texImage2D(face, lodLevel, format, width, height, 0, format, type, image);
|
|
3215
3216
|
} else {
|
|
3216
|
-
|
|
3217
|
+
gl2.texImage2D(face, lodLevel, format, format, type, image);
|
|
3217
3218
|
}
|
|
3218
3219
|
});
|
|
3219
3220
|
});
|
|
@@ -3232,7 +3233,7 @@ var _WEBGLTexture = class extends import_api10.Texture {
|
|
|
3232
3233
|
type = import_constants11.GL.UNSIGNED_BYTE
|
|
3233
3234
|
// generateMipmap = false // TODO
|
|
3234
3235
|
} = options;
|
|
3235
|
-
const { gl } = this;
|
|
3236
|
+
const { gl: gl2 } = this;
|
|
3236
3237
|
const imageData = pixels || data;
|
|
3237
3238
|
this.bind();
|
|
3238
3239
|
if (imageData instanceof Promise) {
|
|
@@ -3246,9 +3247,9 @@ var _WEBGLTexture = class extends import_api10.Texture {
|
|
|
3246
3247
|
)
|
|
3247
3248
|
);
|
|
3248
3249
|
} else if (this.width || this.height) {
|
|
3249
|
-
|
|
3250
|
+
gl2.texImage2D(face, 0, format, width, height, 0, format, type, imageData);
|
|
3250
3251
|
} else {
|
|
3251
|
-
|
|
3252
|
+
gl2.texImage2D(face, 0, format, format, type, imageData);
|
|
3252
3253
|
}
|
|
3253
3254
|
return this;
|
|
3254
3255
|
}
|
|
@@ -3406,7 +3407,7 @@ var import_api12 = require("@luma.gl/api");
|
|
|
3406
3407
|
|
|
3407
3408
|
// src/adapter/objects/constants-to-keys.ts
|
|
3408
3409
|
var import_api11 = require("@luma.gl/api");
|
|
3409
|
-
function getKeyValue(
|
|
3410
|
+
function getKeyValue(gl2, name) {
|
|
3410
3411
|
if (typeof name !== "string") {
|
|
3411
3412
|
return name;
|
|
3412
3413
|
}
|
|
@@ -3415,7 +3416,7 @@ function getKeyValue(gl, name) {
|
|
|
3415
3416
|
return number;
|
|
3416
3417
|
}
|
|
3417
3418
|
name = name.replace(/^.*\./, "");
|
|
3418
|
-
const value =
|
|
3419
|
+
const value = gl2[name];
|
|
3419
3420
|
(0, import_api11.assert)(value !== void 0, `Accessing undefined constant GL.${name}`);
|
|
3420
3421
|
return value;
|
|
3421
3422
|
}
|
|
@@ -3429,11 +3430,11 @@ var WebGLResource = class extends import_api12.Resource {
|
|
|
3429
3430
|
// Only meaningful for resources that allocate GPU memory
|
|
3430
3431
|
this.byteLength = 0;
|
|
3431
3432
|
this.device = WebGLDevice.attach(device);
|
|
3432
|
-
const
|
|
3433
|
-
assertWebGLContext(
|
|
3433
|
+
const gl2 = this.device.gl;
|
|
3434
|
+
assertWebGLContext(gl2);
|
|
3434
3435
|
const { id } = props || {};
|
|
3435
|
-
this.gl =
|
|
3436
|
-
this.gl2 =
|
|
3436
|
+
this.gl = gl2;
|
|
3437
|
+
this.gl2 = gl2;
|
|
3437
3438
|
this.id = id || (0, import_api12.uid)(this.constructor.name);
|
|
3438
3439
|
this._handle = props == null ? void 0 : props.handle;
|
|
3439
3440
|
if (this._handle === void 0) {
|
|
@@ -3744,11 +3745,11 @@ var WEBGLFramebuffer = class extends import_api14.Framebuffer {
|
|
|
3744
3745
|
// PRIVATE
|
|
3745
3746
|
/** Check the status */
|
|
3746
3747
|
_checkStatus() {
|
|
3747
|
-
const { gl } = this;
|
|
3748
|
-
const prevHandle2 =
|
|
3749
|
-
const status =
|
|
3750
|
-
|
|
3751
|
-
if (status !==
|
|
3748
|
+
const { gl: gl2 } = this;
|
|
3749
|
+
const prevHandle2 = gl2.bindFramebuffer(import_constants13.GL.FRAMEBUFFER, this.handle);
|
|
3750
|
+
const status = gl2.checkFramebufferStatus(import_constants13.GL.FRAMEBUFFER);
|
|
3751
|
+
gl2.bindFramebuffer(import_constants13.GL.FRAMEBUFFER, prevHandle2 || null);
|
|
3752
|
+
if (status !== gl2.FRAMEBUFFER_COMPLETE) {
|
|
3752
3753
|
throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
|
|
3753
3754
|
}
|
|
3754
3755
|
}
|
|
@@ -3817,25 +3818,25 @@ var WEBGLFramebuffer = class extends import_api14.Framebuffer {
|
|
|
3817
3818
|
* @param level = 0 - mipmapLevel (must be 0 in WebGL1)
|
|
3818
3819
|
*/
|
|
3819
3820
|
_attachTexture(attachment, texture, layer, level) {
|
|
3820
|
-
const { gl, gl2 } = this.device;
|
|
3821
|
-
|
|
3821
|
+
const { gl: gl2, gl2: gl22 } = this.device;
|
|
3822
|
+
gl2.bindTexture(texture.target, texture.handle);
|
|
3822
3823
|
switch (texture.target) {
|
|
3823
3824
|
case import_constants13.GL.TEXTURE_2D_ARRAY:
|
|
3824
3825
|
case import_constants13.GL.TEXTURE_3D:
|
|
3825
3826
|
this.device.assertWebGL2();
|
|
3826
|
-
|
|
3827
|
+
gl22 == null ? void 0 : gl22.framebufferTextureLayer(import_constants13.GL.FRAMEBUFFER, attachment, texture.target, level, layer);
|
|
3827
3828
|
break;
|
|
3828
3829
|
case import_constants13.GL.TEXTURE_CUBE_MAP:
|
|
3829
3830
|
const face = mapIndexToCubeMapFace(layer);
|
|
3830
|
-
|
|
3831
|
+
gl2.framebufferTexture2D(import_constants13.GL.FRAMEBUFFER, attachment, face, texture.handle, level);
|
|
3831
3832
|
break;
|
|
3832
3833
|
case import_constants13.GL.TEXTURE_2D:
|
|
3833
|
-
|
|
3834
|
+
gl2.framebufferTexture2D(import_constants13.GL.FRAMEBUFFER, attachment, import_constants13.GL.TEXTURE_2D, texture.handle, level);
|
|
3834
3835
|
break;
|
|
3835
3836
|
default:
|
|
3836
3837
|
(0, import_api14.assert)(false, "Illegal texture type");
|
|
3837
3838
|
}
|
|
3838
|
-
|
|
3839
|
+
gl2.bindTexture(texture.target, null);
|
|
3839
3840
|
}
|
|
3840
3841
|
};
|
|
3841
3842
|
function mapIndexToCubeMapFace(layer) {
|
|
@@ -3897,6 +3898,7 @@ var WebGLCanvasContext = class extends import_api15.CanvasContext {
|
|
|
3897
3898
|
*/
|
|
3898
3899
|
resize(options) {
|
|
3899
3900
|
if (this.canvas) {
|
|
3901
|
+
const devicePixelRatio = this.getDevicePixelRatio(options == null ? void 0 : options.useDevicePixels);
|
|
3900
3902
|
this.setDevicePixelRatio(devicePixelRatio, options);
|
|
3901
3903
|
return;
|
|
3902
3904
|
}
|
|
@@ -3972,9 +3974,9 @@ function initializeSpectorJS(props) {
|
|
|
3972
3974
|
var import_api17 = require("@luma.gl/api");
|
|
3973
3975
|
var import_constants14 = require("@luma.gl/constants");
|
|
3974
3976
|
var WEBGL_DEBUG_CDN_URL = "https://unpkg.com/webgl-debug@2.0.1/index.js";
|
|
3975
|
-
function getContextData2(
|
|
3976
|
-
|
|
3977
|
-
return
|
|
3977
|
+
function getContextData2(gl2) {
|
|
3978
|
+
gl2.luma = gl2.luma || {};
|
|
3979
|
+
return gl2.luma;
|
|
3978
3980
|
}
|
|
3979
3981
|
function loadWebGLDeveloperTools() {
|
|
3980
3982
|
return __async(this, null, function* () {
|
|
@@ -3985,28 +3987,28 @@ function loadWebGLDeveloperTools() {
|
|
|
3985
3987
|
}
|
|
3986
3988
|
});
|
|
3987
3989
|
}
|
|
3988
|
-
function makeDebugContext(
|
|
3989
|
-
if (!
|
|
3990
|
+
function makeDebugContext(gl2, props = {}) {
|
|
3991
|
+
if (!gl2) {
|
|
3990
3992
|
return null;
|
|
3991
3993
|
}
|
|
3992
|
-
return props.debug ? getDebugContext(
|
|
3994
|
+
return props.debug ? getDebugContext(gl2, props) : getRealContext(gl2);
|
|
3993
3995
|
}
|
|
3994
|
-
function getRealContext(
|
|
3995
|
-
const data = getContextData2(
|
|
3996
|
-
return data.realContext ? data.realContext :
|
|
3996
|
+
function getRealContext(gl2) {
|
|
3997
|
+
const data = getContextData2(gl2);
|
|
3998
|
+
return data.realContext ? data.realContext : gl2;
|
|
3997
3999
|
}
|
|
3998
|
-
function getDebugContext(
|
|
4000
|
+
function getDebugContext(gl2, props) {
|
|
3999
4001
|
if (!globalThis.WebGLDebugUtils) {
|
|
4000
4002
|
import_api17.log.warn("webgl-debug not loaded")();
|
|
4001
|
-
return
|
|
4003
|
+
return gl2;
|
|
4002
4004
|
}
|
|
4003
|
-
const data = getContextData2(
|
|
4005
|
+
const data = getContextData2(gl2);
|
|
4004
4006
|
if (data.debugContext) {
|
|
4005
4007
|
return data.debugContext;
|
|
4006
4008
|
}
|
|
4007
|
-
globalThis.WebGLDebugUtils.init(__spreadValues(__spreadValues({}, import_constants14.GL),
|
|
4009
|
+
globalThis.WebGLDebugUtils.init(__spreadValues(__spreadValues({}, import_constants14.GL), gl2));
|
|
4008
4010
|
const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(
|
|
4009
|
-
|
|
4011
|
+
gl2,
|
|
4010
4012
|
onGLError.bind(null, props),
|
|
4011
4013
|
onValidateGLFunc.bind(null, props)
|
|
4012
4014
|
);
|
|
@@ -4017,10 +4019,10 @@ function getDebugContext(gl, props) {
|
|
|
4017
4019
|
}
|
|
4018
4020
|
class WebGLDebugContext {
|
|
4019
4021
|
}
|
|
4020
|
-
Object.setPrototypeOf(glDebug, Object.getPrototypeOf(
|
|
4022
|
+
Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl2));
|
|
4021
4023
|
Object.setPrototypeOf(WebGLDebugContext, glDebug);
|
|
4022
4024
|
const debugContext = Object.create(WebGLDebugContext);
|
|
4023
|
-
data.realContext =
|
|
4025
|
+
data.realContext = gl2;
|
|
4024
4026
|
data.debugContext = debugContext;
|
|
4025
4027
|
debugContext.debug = true;
|
|
4026
4028
|
return debugContext;
|
|
@@ -4390,13 +4392,13 @@ var BufferWithAccessor = class extends WEBGLBuffer {
|
|
|
4390
4392
|
*/
|
|
4391
4393
|
copyData(options) {
|
|
4392
4394
|
const { sourceBuffer, readOffset = 0, writeOffset = 0, size } = options;
|
|
4393
|
-
const { gl, gl2 } = this;
|
|
4394
|
-
assertWebGL2Context(
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4395
|
+
const { gl: gl2, gl2: gl22 } = this;
|
|
4396
|
+
assertWebGL2Context(gl2);
|
|
4397
|
+
gl2.bindBuffer(import_constants17.GL.COPY_READ_BUFFER, sourceBuffer.handle);
|
|
4398
|
+
gl2.bindBuffer(import_constants17.GL.COPY_WRITE_BUFFER, this.handle);
|
|
4399
|
+
gl22 == null ? void 0 : gl22.copyBufferSubData(import_constants17.GL.COPY_READ_BUFFER, import_constants17.GL.COPY_WRITE_BUFFER, readOffset, writeOffset, size);
|
|
4400
|
+
gl2.bindBuffer(import_constants17.GL.COPY_READ_BUFFER, null);
|
|
4401
|
+
gl2.bindBuffer(import_constants17.GL.COPY_WRITE_BUFFER, null);
|
|
4400
4402
|
this.debugData = null;
|
|
4401
4403
|
return this;
|
|
4402
4404
|
}
|
|
@@ -4650,12 +4652,12 @@ var WEBGLShader = class extends import_api20.Shader {
|
|
|
4650
4652
|
const addGLSLVersion = (source2) => source2.startsWith("#version ") ? source2 : `#version 100
|
|
4651
4653
|
${source2}`;
|
|
4652
4654
|
source = addGLSLVersion(source);
|
|
4653
|
-
const { gl } = this.device;
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
const compileStatus =
|
|
4655
|
+
const { gl: gl2 } = this.device;
|
|
4656
|
+
gl2.shaderSource(this.handle, source);
|
|
4657
|
+
gl2.compileShader(this.handle);
|
|
4658
|
+
const compileStatus = gl2.getShaderParameter(this.handle, import_constants18.GL.COMPILE_STATUS);
|
|
4657
4659
|
if (!compileStatus) {
|
|
4658
|
-
const shaderLog =
|
|
4660
|
+
const shaderLog = gl2.getShaderInfoLog(this.handle);
|
|
4659
4661
|
const parsedLog = shaderLog ? parseShaderCompilerLog(shaderLog) : [];
|
|
4660
4662
|
const messages = parsedLog.filter((message2) => message2.type === "error");
|
|
4661
4663
|
const formattedLog = (0, import_api20.formatCompilerLog)(messages, source);
|
|
@@ -4904,9 +4906,9 @@ function getDataFormat(type) {
|
|
|
4904
4906
|
}
|
|
4905
4907
|
|
|
4906
4908
|
// src/adapter/helpers/get-shader-layout.ts
|
|
4907
|
-
function getShaderLayout(
|
|
4909
|
+
function getShaderLayout(gl2, program) {
|
|
4908
4910
|
var _a, _b;
|
|
4909
|
-
const programBindings = getProgramBindings(
|
|
4911
|
+
const programBindings = getProgramBindings(gl2, program);
|
|
4910
4912
|
const shaderLayout = {
|
|
4911
4913
|
attributes: [],
|
|
4912
4914
|
bindings: []
|
|
@@ -4965,26 +4967,26 @@ function getShaderLayout(gl, program) {
|
|
|
4965
4967
|
}
|
|
4966
4968
|
return shaderLayout;
|
|
4967
4969
|
}
|
|
4968
|
-
function getProgramBindings(
|
|
4970
|
+
function getProgramBindings(gl2, program) {
|
|
4969
4971
|
const config = {
|
|
4970
|
-
attributes: readAttributeBindings(
|
|
4971
|
-
uniforms: readUniformBindings(
|
|
4972
|
-
uniformBlocks: readUniformBlocks(
|
|
4973
|
-
varyings: readVaryings(
|
|
4972
|
+
attributes: readAttributeBindings(gl2, program),
|
|
4973
|
+
uniforms: readUniformBindings(gl2, program),
|
|
4974
|
+
uniformBlocks: readUniformBlocks(gl2, program),
|
|
4975
|
+
varyings: readVaryings(gl2, program)
|
|
4974
4976
|
};
|
|
4975
4977
|
Object.seal(config);
|
|
4976
4978
|
return config;
|
|
4977
4979
|
}
|
|
4978
|
-
function readAttributeBindings(
|
|
4980
|
+
function readAttributeBindings(gl2, program) {
|
|
4979
4981
|
const attributes = [];
|
|
4980
|
-
const count =
|
|
4982
|
+
const count = gl2.getProgramParameter(program, gl2.ACTIVE_ATTRIBUTES);
|
|
4981
4983
|
for (let index = 0; index < count; index++) {
|
|
4982
|
-
const activeInfo =
|
|
4984
|
+
const activeInfo = gl2.getActiveAttrib(program, index);
|
|
4983
4985
|
if (!activeInfo) {
|
|
4984
4986
|
throw new Error("activeInfo");
|
|
4985
4987
|
}
|
|
4986
4988
|
const { name, type: compositeType, size } = activeInfo;
|
|
4987
|
-
const location =
|
|
4989
|
+
const location = gl2.getAttribLocation(program, name);
|
|
4988
4990
|
if (location >= 0) {
|
|
4989
4991
|
const { glType, components } = decodeAttributeType(compositeType);
|
|
4990
4992
|
const accessor = { type: glType, size: size * components };
|
|
@@ -4998,15 +5000,15 @@ function readAttributeBindings(gl, program) {
|
|
|
4998
5000
|
attributes.sort((a, b) => a.location - b.location);
|
|
4999
5001
|
return attributes;
|
|
5000
5002
|
}
|
|
5001
|
-
function readVaryings(
|
|
5002
|
-
if (!isWebGL2(
|
|
5003
|
+
function readVaryings(gl2, program) {
|
|
5004
|
+
if (!isWebGL2(gl2)) {
|
|
5003
5005
|
return [];
|
|
5004
5006
|
}
|
|
5005
|
-
const
|
|
5007
|
+
const gl22 = gl2;
|
|
5006
5008
|
const varyings = [];
|
|
5007
|
-
const count =
|
|
5009
|
+
const count = gl2.getProgramParameter(program, import_constants22.GL.TRANSFORM_FEEDBACK_VARYINGS);
|
|
5008
5010
|
for (let location = 0; location < count; location++) {
|
|
5009
|
-
const activeInfo =
|
|
5011
|
+
const activeInfo = gl22.getTransformFeedbackVarying(program, location);
|
|
5010
5012
|
if (!activeInfo) {
|
|
5011
5013
|
throw new Error("activeInfo");
|
|
5012
5014
|
}
|
|
@@ -5019,17 +5021,17 @@ function readVaryings(gl, program) {
|
|
|
5019
5021
|
varyings.sort((a, b) => a.location - b.location);
|
|
5020
5022
|
return varyings;
|
|
5021
5023
|
}
|
|
5022
|
-
function readUniformBindings(
|
|
5024
|
+
function readUniformBindings(gl2, program) {
|
|
5023
5025
|
const uniforms = [];
|
|
5024
|
-
const uniformCount =
|
|
5026
|
+
const uniformCount = gl2.getProgramParameter(program, import_constants22.GL.ACTIVE_UNIFORMS);
|
|
5025
5027
|
for (let i = 0; i < uniformCount; i++) {
|
|
5026
|
-
const activeInfo =
|
|
5028
|
+
const activeInfo = gl2.getActiveUniform(program, i);
|
|
5027
5029
|
if (!activeInfo) {
|
|
5028
5030
|
throw new Error("activeInfo");
|
|
5029
5031
|
}
|
|
5030
5032
|
const { name: rawName, size, type } = activeInfo;
|
|
5031
5033
|
const { name, isArray: isArray2 } = parseUniformName(rawName);
|
|
5032
|
-
let webglLocation =
|
|
5034
|
+
let webglLocation = gl2.getUniformLocation(program, name);
|
|
5033
5035
|
const uniformInfo = {
|
|
5034
5036
|
// WebGL locations are uniquely typed but just numbers
|
|
5035
5037
|
location: webglLocation,
|
|
@@ -5042,7 +5044,7 @@ function readUniformBindings(gl, program) {
|
|
|
5042
5044
|
if (uniformInfo.size > 1) {
|
|
5043
5045
|
for (let j = 0; j < uniformInfo.size; j++) {
|
|
5044
5046
|
const elementName = `${name}[${j}]`;
|
|
5045
|
-
webglLocation =
|
|
5047
|
+
webglLocation = gl2.getUniformLocation(program, elementName);
|
|
5046
5048
|
const arrayElementUniformInfo = __spreadProps(__spreadValues({}, uniformInfo), {
|
|
5047
5049
|
name: elementName,
|
|
5048
5050
|
location: webglLocation
|
|
@@ -5053,17 +5055,17 @@ function readUniformBindings(gl, program) {
|
|
|
5053
5055
|
}
|
|
5054
5056
|
return uniforms;
|
|
5055
5057
|
}
|
|
5056
|
-
function readUniformBlocks(
|
|
5057
|
-
if (!isWebGL2(
|
|
5058
|
+
function readUniformBlocks(gl2, program) {
|
|
5059
|
+
if (!isWebGL2(gl2)) {
|
|
5058
5060
|
return [];
|
|
5059
5061
|
}
|
|
5060
|
-
const
|
|
5061
|
-
const getBlockParameter = (blockIndex, pname) =>
|
|
5062
|
+
const gl22 = gl2;
|
|
5063
|
+
const getBlockParameter = (blockIndex, pname) => gl22.getActiveUniformBlockParameter(program, blockIndex, pname);
|
|
5062
5064
|
const uniformBlocks = [];
|
|
5063
|
-
const blockCount =
|
|
5065
|
+
const blockCount = gl22.getProgramParameter(program, import_constants22.GL.ACTIVE_UNIFORM_BLOCKS);
|
|
5064
5066
|
for (let blockIndex = 0; blockIndex < blockCount; blockIndex++) {
|
|
5065
5067
|
const blockInfo = {
|
|
5066
|
-
name:
|
|
5068
|
+
name: gl22.getActiveUniformBlockName(program, blockIndex) || "",
|
|
5067
5069
|
location: getBlockParameter(blockIndex, import_constants22.GL.UNIFORM_BLOCK_BINDING),
|
|
5068
5070
|
byteLength: getBlockParameter(blockIndex, import_constants22.GL.UNIFORM_BLOCK_DATA_SIZE),
|
|
5069
5071
|
vertex: getBlockParameter(blockIndex, import_constants22.GL.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),
|
|
@@ -5072,12 +5074,12 @@ function readUniformBlocks(gl, program) {
|
|
|
5072
5074
|
uniforms: []
|
|
5073
5075
|
};
|
|
5074
5076
|
const uniformIndices = getBlockParameter(blockIndex, import_constants22.GL.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) || [];
|
|
5075
|
-
const uniformType =
|
|
5076
|
-
const uniformArrayLength =
|
|
5077
|
-
const uniformOffset =
|
|
5078
|
-
const uniformStride =
|
|
5077
|
+
const uniformType = gl22.getActiveUniforms(program, uniformIndices, import_constants22.GL.UNIFORM_TYPE);
|
|
5078
|
+
const uniformArrayLength = gl22.getActiveUniforms(program, uniformIndices, import_constants22.GL.UNIFORM_SIZE);
|
|
5079
|
+
const uniformOffset = gl22.getActiveUniforms(program, uniformIndices, import_constants22.GL.UNIFORM_OFFSET);
|
|
5080
|
+
const uniformStride = gl22.getActiveUniforms(program, uniformIndices, import_constants22.GL.UNIFORM_ARRAY_STRIDE);
|
|
5079
5081
|
for (let i = 0; i < blockInfo.uniformCount; ++i) {
|
|
5080
|
-
const activeInfo =
|
|
5082
|
+
const activeInfo = gl22.getActiveUniform(program, uniformIndices[i]);
|
|
5081
5083
|
if (!activeInfo) {
|
|
5082
5084
|
throw new Error("activeInfo");
|
|
5083
5085
|
}
|
|
@@ -5144,8 +5146,8 @@ function parseUniformName(name) {
|
|
|
5144
5146
|
|
|
5145
5147
|
// src/adapter/helpers/set-uniform.ts
|
|
5146
5148
|
var import_constants23 = require("@luma.gl/constants");
|
|
5147
|
-
function setUniform(
|
|
5148
|
-
const
|
|
5149
|
+
function setUniform(gl2, location, type, value) {
|
|
5150
|
+
const gl22 = gl2;
|
|
5149
5151
|
if (typeof value === "number") {
|
|
5150
5152
|
switch (type) {
|
|
5151
5153
|
case import_constants23.GL.SAMPLER_2D:
|
|
@@ -5163,7 +5165,7 @@ function setUniform(gl, location, type, value) {
|
|
|
5163
5165
|
case import_constants23.GL.UNSIGNED_INT_SAMPLER_3D:
|
|
5164
5166
|
case import_constants23.GL.UNSIGNED_INT_SAMPLER_CUBE:
|
|
5165
5167
|
case import_constants23.GL.UNSIGNED_INT_SAMPLER_2D_ARRAY:
|
|
5166
|
-
return
|
|
5168
|
+
return gl2.uniform1i(location, value);
|
|
5167
5169
|
}
|
|
5168
5170
|
}
|
|
5169
5171
|
if (value === true) {
|
|
@@ -5175,55 +5177,55 @@ function setUniform(gl, location, type, value) {
|
|
|
5175
5177
|
const arrayValue = typeof value === "number" ? [value] : value;
|
|
5176
5178
|
switch (type) {
|
|
5177
5179
|
case import_constants23.GL.FLOAT:
|
|
5178
|
-
return
|
|
5180
|
+
return gl2.uniform1fv(location, arrayValue);
|
|
5179
5181
|
case import_constants23.GL.FLOAT_VEC2:
|
|
5180
|
-
return
|
|
5182
|
+
return gl2.uniform2fv(location, arrayValue);
|
|
5181
5183
|
case import_constants23.GL.FLOAT_VEC3:
|
|
5182
|
-
return
|
|
5184
|
+
return gl2.uniform3fv(location, arrayValue);
|
|
5183
5185
|
case import_constants23.GL.FLOAT_VEC4:
|
|
5184
|
-
return
|
|
5186
|
+
return gl2.uniform4fv(location, arrayValue);
|
|
5185
5187
|
case import_constants23.GL.INT:
|
|
5186
|
-
return
|
|
5188
|
+
return gl2.uniform1iv(location, arrayValue);
|
|
5187
5189
|
case import_constants23.GL.INT_VEC2:
|
|
5188
|
-
return
|
|
5190
|
+
return gl2.uniform2iv(location, arrayValue);
|
|
5189
5191
|
case import_constants23.GL.INT_VEC3:
|
|
5190
|
-
return
|
|
5192
|
+
return gl2.uniform3iv(location, arrayValue);
|
|
5191
5193
|
case import_constants23.GL.INT_VEC4:
|
|
5192
|
-
return
|
|
5194
|
+
return gl2.uniform4iv(location, arrayValue);
|
|
5193
5195
|
case import_constants23.GL.BOOL:
|
|
5194
|
-
return
|
|
5196
|
+
return gl2.uniform1iv(location, arrayValue);
|
|
5195
5197
|
case import_constants23.GL.BOOL_VEC2:
|
|
5196
|
-
return
|
|
5198
|
+
return gl2.uniform2iv(location, arrayValue);
|
|
5197
5199
|
case import_constants23.GL.BOOL_VEC3:
|
|
5198
|
-
return
|
|
5200
|
+
return gl2.uniform3iv(location, arrayValue);
|
|
5199
5201
|
case import_constants23.GL.BOOL_VEC4:
|
|
5200
|
-
return
|
|
5202
|
+
return gl2.uniform4iv(location, arrayValue);
|
|
5201
5203
|
case import_constants23.GL.UNSIGNED_INT:
|
|
5202
|
-
return
|
|
5204
|
+
return gl22.uniform1uiv(location, arrayValue, 1);
|
|
5203
5205
|
case import_constants23.GL.UNSIGNED_INT_VEC2:
|
|
5204
|
-
return
|
|
5206
|
+
return gl22.uniform2uiv(location, arrayValue, 2);
|
|
5205
5207
|
case import_constants23.GL.UNSIGNED_INT_VEC3:
|
|
5206
|
-
return
|
|
5208
|
+
return gl22.uniform3uiv(location, arrayValue, 3);
|
|
5207
5209
|
case import_constants23.GL.UNSIGNED_INT_VEC4:
|
|
5208
|
-
return
|
|
5210
|
+
return gl22.uniform4uiv(location, arrayValue, 4);
|
|
5209
5211
|
case import_constants23.GL.FLOAT_MAT2:
|
|
5210
|
-
return
|
|
5212
|
+
return gl2.uniformMatrix2fv(location, false, arrayValue);
|
|
5211
5213
|
case import_constants23.GL.FLOAT_MAT3:
|
|
5212
|
-
return
|
|
5214
|
+
return gl2.uniformMatrix3fv(location, false, arrayValue);
|
|
5213
5215
|
case import_constants23.GL.FLOAT_MAT4:
|
|
5214
|
-
return
|
|
5216
|
+
return gl2.uniformMatrix4fv(location, false, arrayValue);
|
|
5215
5217
|
case import_constants23.GL.FLOAT_MAT2x3:
|
|
5216
|
-
return
|
|
5218
|
+
return gl22.uniformMatrix2x3fv(location, false, arrayValue);
|
|
5217
5219
|
case import_constants23.GL.FLOAT_MAT2x4:
|
|
5218
|
-
return
|
|
5220
|
+
return gl22.uniformMatrix2x4fv(location, false, arrayValue);
|
|
5219
5221
|
case import_constants23.GL.FLOAT_MAT3x2:
|
|
5220
|
-
return
|
|
5222
|
+
return gl22.uniformMatrix3x2fv(location, false, arrayValue);
|
|
5221
5223
|
case import_constants23.GL.FLOAT_MAT3x4:
|
|
5222
|
-
return
|
|
5224
|
+
return gl22.uniformMatrix3x4fv(location, false, arrayValue);
|
|
5223
5225
|
case import_constants23.GL.FLOAT_MAT4x2:
|
|
5224
|
-
return
|
|
5226
|
+
return gl22.uniformMatrix4x2fv(location, false, arrayValue);
|
|
5225
5227
|
case import_constants23.GL.FLOAT_MAT4x3:
|
|
5226
|
-
return
|
|
5228
|
+
return gl22.uniformMatrix4x3fv(location, false, arrayValue);
|
|
5227
5229
|
}
|
|
5228
5230
|
throw new Error("Illegal uniform");
|
|
5229
5231
|
}
|
|
@@ -5234,11 +5236,26 @@ var import_constants24 = require("@luma.gl/constants");
|
|
|
5234
5236
|
var import_env = require("@probe.gl/env");
|
|
5235
5237
|
var ERR_ELEMENTS = "elements must be GL.ELEMENT_ARRAY_BUFFER";
|
|
5236
5238
|
var WEBGLVertexArrayObject = class extends WebGLResource {
|
|
5239
|
+
// Create a VertexArray
|
|
5240
|
+
constructor(device, props) {
|
|
5241
|
+
super(device, props, __spreadProps(__spreadValues({}, import_api22.Resource.defaultProps), { constantAttributeZero: false }));
|
|
5242
|
+
/** Buffer constant */
|
|
5243
|
+
this.buffer = null;
|
|
5244
|
+
this.bufferValue = null;
|
|
5245
|
+
Object.seal(this);
|
|
5246
|
+
}
|
|
5237
5247
|
get [Symbol.toStringTag]() {
|
|
5238
5248
|
return "BaseVertexArrayObject";
|
|
5239
5249
|
}
|
|
5240
|
-
|
|
5241
|
-
|
|
5250
|
+
static isConstantAttributeZeroSupported(device) {
|
|
5251
|
+
return device.info.type === "webgl2" || (0, import_env.getBrowser)() === "Chrome";
|
|
5252
|
+
}
|
|
5253
|
+
destroy() {
|
|
5254
|
+
var _a;
|
|
5255
|
+
super.destroy();
|
|
5256
|
+
if (this.buffer) {
|
|
5257
|
+
(_a = this.buffer) == null ? void 0 : _a.destroy();
|
|
5258
|
+
}
|
|
5242
5259
|
}
|
|
5243
5260
|
_createHandle() {
|
|
5244
5261
|
return this.gl2.createVertexArray();
|
|
@@ -5250,6 +5267,22 @@ var WEBGLVertexArrayObject = class extends WebGLResource {
|
|
|
5250
5267
|
_bindHandle(handle) {
|
|
5251
5268
|
this.gl2.bindVertexArray(handle);
|
|
5252
5269
|
}
|
|
5270
|
+
/**
|
|
5271
|
+
* Enabling an attribute location makes it reference the currently bound buffer
|
|
5272
|
+
* Disabling an attribute location makes it reference the global constant value
|
|
5273
|
+
* TODO - handle single values for size 1 attributes?
|
|
5274
|
+
* TODO - convert classic arrays based on known type?
|
|
5275
|
+
*/
|
|
5276
|
+
enable(location, enable2 = true) {
|
|
5277
|
+
const canDisableAttributeZero = this.device.isWebGL2 || (0, import_env.getBrowser)() === "Chrome";
|
|
5278
|
+
const canDisableAttribute = canDisableAttributeZero || location !== 0;
|
|
5279
|
+
if (enable2 || canDisableAttribute) {
|
|
5280
|
+
location = Number(location);
|
|
5281
|
+
this.bind(
|
|
5282
|
+
() => enable2 ? this.gl.enableVertexAttribArray(location) : this.gl.disableVertexAttribArray(location)
|
|
5283
|
+
);
|
|
5284
|
+
}
|
|
5285
|
+
}
|
|
5253
5286
|
// Set (bind) an elements buffer, for indexed rendering.
|
|
5254
5287
|
// Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER. Constants not supported
|
|
5255
5288
|
setElementBuffer(elementBuffer = null, opts = {}) {
|
|
@@ -5257,47 +5290,122 @@ var WEBGLVertexArrayObject = class extends WebGLResource {
|
|
|
5257
5290
|
this.bind(() => {
|
|
5258
5291
|
this.gl.bindBuffer(import_constants24.GL.ELEMENT_ARRAY_BUFFER, elementBuffer ? elementBuffer.handle : null);
|
|
5259
5292
|
});
|
|
5260
|
-
return this;
|
|
5261
5293
|
}
|
|
5262
5294
|
/** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
|
|
5263
5295
|
setBuffer(location, buffer, accessor) {
|
|
5264
5296
|
if (buffer.target === import_constants24.GL.ELEMENT_ARRAY_BUFFER) {
|
|
5265
|
-
|
|
5297
|
+
this.setElementBuffer(buffer, accessor);
|
|
5298
|
+
return;
|
|
5266
5299
|
}
|
|
5267
5300
|
const { size, type, stride, offset, normalized, integer, divisor } = accessor;
|
|
5268
|
-
const { gl, gl2 } = this;
|
|
5301
|
+
const { gl: gl2, gl2: gl22 } = this;
|
|
5269
5302
|
location = Number(location);
|
|
5270
5303
|
this.bind(() => {
|
|
5271
|
-
|
|
5304
|
+
gl2.bindBuffer(gl2.ARRAY_BUFFER, buffer.handle);
|
|
5272
5305
|
if (integer) {
|
|
5273
5306
|
this.device.assertWebGL2();
|
|
5274
|
-
|
|
5307
|
+
gl22.vertexAttribIPointer(location, size, type, stride, offset);
|
|
5275
5308
|
} else {
|
|
5276
|
-
|
|
5309
|
+
gl2.vertexAttribPointer(location, size, type, normalized, stride, offset);
|
|
5277
5310
|
}
|
|
5278
|
-
|
|
5279
|
-
|
|
5311
|
+
gl2.enableVertexAttribArray(location);
|
|
5312
|
+
gl22.vertexAttribDivisor(location, divisor || 0);
|
|
5280
5313
|
});
|
|
5281
|
-
return this;
|
|
5282
5314
|
}
|
|
5283
5315
|
/**
|
|
5284
|
-
*
|
|
5285
|
-
*
|
|
5286
|
-
*
|
|
5287
|
-
*
|
|
5316
|
+
* Set an attribute to a constant value
|
|
5317
|
+
* @param device
|
|
5318
|
+
* @param location
|
|
5319
|
+
* @param array
|
|
5320
|
+
*
|
|
5321
|
+
* @note Constants are stored globally on the WebGL context, not the VAO
|
|
5322
|
+
* so they need to be updated before every render
|
|
5323
|
+
* @todo - use known type (in configuration or passed in) to allow non-typed arrays?
|
|
5324
|
+
* @todo - remember/cache values to avoid setting them unnecessarily?
|
|
5288
5325
|
*/
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
(
|
|
5296
|
-
|
|
5326
|
+
setConstant(location, array) {
|
|
5327
|
+
switch (array.constructor) {
|
|
5328
|
+
case Float32Array:
|
|
5329
|
+
setConstantFloatArray(this.device, location, array);
|
|
5330
|
+
break;
|
|
5331
|
+
case Int32Array:
|
|
5332
|
+
setConstantIntArray(this.device, location, array);
|
|
5333
|
+
break;
|
|
5334
|
+
case Uint32Array:
|
|
5335
|
+
setConstantUintArray(this.device, location, array);
|
|
5336
|
+
break;
|
|
5337
|
+
default:
|
|
5338
|
+
(0, import_api22.assert)(false);
|
|
5297
5339
|
}
|
|
5298
|
-
|
|
5340
|
+
}
|
|
5341
|
+
/**
|
|
5342
|
+
* Provide a means to create a buffer that is equivalent to a constant.
|
|
5343
|
+
* NOTE: Desktop OpenGL cannot disable attribute 0.
|
|
5344
|
+
* https://stackoverflow.com/questions/20305231/webgl-warning-attribute-0-is-disabled-
|
|
5345
|
+
* this-has-significant-performance-penalty
|
|
5346
|
+
*/
|
|
5347
|
+
getConstantBuffer(elementCount, value) {
|
|
5348
|
+
const constantValue = normalizeConstantArrayValue(value);
|
|
5349
|
+
const byteLength = constantValue.byteLength * elementCount;
|
|
5350
|
+
const length = constantValue.length * elementCount;
|
|
5351
|
+
let updateNeeded = !this.buffer;
|
|
5352
|
+
this.buffer = this.buffer || this.device.createBuffer({ byteLength });
|
|
5353
|
+
updateNeeded = updateNeeded || this.buffer.reallocate(byteLength);
|
|
5354
|
+
updateNeeded = updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);
|
|
5355
|
+
if (updateNeeded) {
|
|
5356
|
+
const typedArray = (0, import_api22.getScratchArray)(value.constructor, length);
|
|
5357
|
+
(0, import_api22.fillArray)({ target: typedArray, source: constantValue, start: 0, count: length });
|
|
5358
|
+
this.buffer.subData(typedArray);
|
|
5359
|
+
this.bufferValue = value;
|
|
5360
|
+
}
|
|
5361
|
+
return this.buffer;
|
|
5299
5362
|
}
|
|
5300
5363
|
};
|
|
5364
|
+
function setConstantFloatArray(device, location, array) {
|
|
5365
|
+
switch (array.length) {
|
|
5366
|
+
case 1:
|
|
5367
|
+
device.gl.vertexAttrib1fv(location, array);
|
|
5368
|
+
break;
|
|
5369
|
+
case 2:
|
|
5370
|
+
device.gl.vertexAttrib2fv(location, array);
|
|
5371
|
+
break;
|
|
5372
|
+
case 3:
|
|
5373
|
+
device.gl.vertexAttrib3fv(location, array);
|
|
5374
|
+
break;
|
|
5375
|
+
case 4:
|
|
5376
|
+
device.gl.vertexAttrib4fv(location, array);
|
|
5377
|
+
break;
|
|
5378
|
+
default:
|
|
5379
|
+
(0, import_api22.assert)(false);
|
|
5380
|
+
}
|
|
5381
|
+
}
|
|
5382
|
+
function setConstantIntArray(device, location, array) {
|
|
5383
|
+
var _a;
|
|
5384
|
+
device.assertWebGL2();
|
|
5385
|
+
(_a = device.gl2) == null ? void 0 : _a.vertexAttribI4iv(location, array);
|
|
5386
|
+
}
|
|
5387
|
+
function setConstantUintArray(device, location, array) {
|
|
5388
|
+
var _a;
|
|
5389
|
+
device.assertWebGL2();
|
|
5390
|
+
(_a = device.gl2) == null ? void 0 : _a.vertexAttribI4uiv(location, array);
|
|
5391
|
+
}
|
|
5392
|
+
function normalizeConstantArrayValue(arrayValue) {
|
|
5393
|
+
if (Array.isArray(arrayValue)) {
|
|
5394
|
+
return new Float32Array(arrayValue);
|
|
5395
|
+
}
|
|
5396
|
+
return arrayValue;
|
|
5397
|
+
}
|
|
5398
|
+
function compareConstantArrayValues(v1, v2) {
|
|
5399
|
+
if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
|
|
5400
|
+
return false;
|
|
5401
|
+
}
|
|
5402
|
+
for (let i = 0; i < v1.length; ++i) {
|
|
5403
|
+
if (v1[i] !== v2[i]) {
|
|
5404
|
+
return false;
|
|
5405
|
+
}
|
|
5406
|
+
}
|
|
5407
|
+
return true;
|
|
5408
|
+
}
|
|
5301
5409
|
|
|
5302
5410
|
// src/adapter/resources/webgl-render-pipeline.ts
|
|
5303
5411
|
var LOG_PROGRAM_PERF_PRIORITY = 4;
|
|
@@ -5365,7 +5473,26 @@ var WEBGLRenderPipeline = class extends import_api23.RenderPipeline {
|
|
|
5365
5473
|
});
|
|
5366
5474
|
}
|
|
5367
5475
|
}
|
|
5368
|
-
/**
|
|
5476
|
+
/**
|
|
5477
|
+
* Constant attributes are only supported in WebGL, not in WebGPU
|
|
5478
|
+
* Any attribute that is disabled in the current vertex array object
|
|
5479
|
+
* is read from the context's global constant value for that attribute location.
|
|
5480
|
+
* @param attributes
|
|
5481
|
+
*/
|
|
5482
|
+
setConstantAttributes(attributes) {
|
|
5483
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
5484
|
+
const attribute = getAttributeLayout(this.layout, name);
|
|
5485
|
+
if (!attribute) {
|
|
5486
|
+
import_api23.log.warn(`Ignoring constant value supplied for unknown attribute "${name}" in pipeline "${this.id}"`)();
|
|
5487
|
+
continue;
|
|
5488
|
+
}
|
|
5489
|
+
this.vertexArrayObject.setConstant(attribute.location, value);
|
|
5490
|
+
}
|
|
5491
|
+
}
|
|
5492
|
+
/**
|
|
5493
|
+
* Bindings include: textures, samplers and uniform buffers
|
|
5494
|
+
* @todo needed for portable model
|
|
5495
|
+
*/
|
|
5369
5496
|
setBindings(bindings) {
|
|
5370
5497
|
for (const [name, value] of Object.entries(bindings)) {
|
|
5371
5498
|
const binding = this.layout.bindings.find((binding2) => binding2.name === name);
|
|
@@ -5462,21 +5589,21 @@ var WEBGLRenderPipeline = class extends import_api23.RenderPipeline {
|
|
|
5462
5589
|
// setAttributes(attributes: Record<string, Buffer>): void {}
|
|
5463
5590
|
// setBindings(bindings: Record<string, Binding>): void {}
|
|
5464
5591
|
_compileAndLink() {
|
|
5465
|
-
const { gl } = this.device;
|
|
5466
|
-
|
|
5467
|
-
|
|
5592
|
+
const { gl: gl2 } = this.device;
|
|
5593
|
+
gl2.attachShader(this.handle, this.vs.handle);
|
|
5594
|
+
gl2.attachShader(this.handle, this.fs.handle);
|
|
5468
5595
|
import_api23.log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
|
|
5469
|
-
|
|
5596
|
+
gl2.linkProgram(this.handle);
|
|
5470
5597
|
import_api23.log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();
|
|
5471
|
-
if (
|
|
5472
|
-
const linked =
|
|
5598
|
+
if (gl2.debug || import_api23.log.level > 0) {
|
|
5599
|
+
const linked = gl2.getProgramParameter(this.handle, gl2.LINK_STATUS);
|
|
5473
5600
|
if (!linked) {
|
|
5474
|
-
throw new Error(`Error linking: ${
|
|
5601
|
+
throw new Error(`Error linking: ${gl2.getProgramInfoLog(this.handle)}`);
|
|
5475
5602
|
}
|
|
5476
|
-
|
|
5477
|
-
const validated =
|
|
5603
|
+
gl2.validateProgram(this.handle);
|
|
5604
|
+
const validated = gl2.getProgramParameter(this.handle, gl2.VALIDATE_STATUS);
|
|
5478
5605
|
if (!validated) {
|
|
5479
|
-
throw new Error(`Error validating: ${
|
|
5606
|
+
throw new Error(`Error validating: ${gl2.getProgramInfoLog(this.handle)}`);
|
|
5480
5607
|
}
|
|
5481
5608
|
}
|
|
5482
5609
|
}
|
|
@@ -5882,13 +6009,13 @@ var _WebGLDevice = class extends import_api26.Device {
|
|
|
5882
6009
|
message: "Computer entered sleep mode, or too many apps or browser tabs are using the GPU."
|
|
5883
6010
|
});
|
|
5884
6011
|
};
|
|
5885
|
-
let
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
if (!
|
|
6012
|
+
let gl2 = props.gl || null;
|
|
6013
|
+
gl2 = gl2 || ((0, import_env2.isBrowser)() ? createBrowserContext(this.canvasContext.canvas, __spreadProps(__spreadValues({}, props), { onContextLost })) : null);
|
|
6014
|
+
gl2 = gl2 || (!(0, import_env2.isBrowser)() ? createHeadlessContext(__spreadProps(__spreadValues({}, props), { onContextLost })) : null);
|
|
6015
|
+
if (!gl2) {
|
|
5889
6016
|
throw new Error("WebGL context creation failed");
|
|
5890
6017
|
}
|
|
5891
|
-
this.handle =
|
|
6018
|
+
this.handle = gl2;
|
|
5892
6019
|
this.gl = this.handle;
|
|
5893
6020
|
this.gl2 = this.gl;
|
|
5894
6021
|
this.isWebGL2 = isWebGL22(this.gl);
|
|
@@ -5938,17 +6065,17 @@ var _WebGLDevice = class extends import_api26.Device {
|
|
|
5938
6065
|
* @param gl
|
|
5939
6066
|
* @returns
|
|
5940
6067
|
*/
|
|
5941
|
-
static attach(
|
|
5942
|
-
if (
|
|
5943
|
-
return
|
|
6068
|
+
static attach(gl2) {
|
|
6069
|
+
if (gl2 instanceof _WebGLDevice) {
|
|
6070
|
+
return gl2;
|
|
5944
6071
|
}
|
|
5945
|
-
if ((
|
|
5946
|
-
return
|
|
6072
|
+
if ((gl2 == null ? void 0 : gl2.device) instanceof import_api26.Device) {
|
|
6073
|
+
return gl2.device;
|
|
5947
6074
|
}
|
|
5948
|
-
if (!isWebGL3(
|
|
6075
|
+
if (!isWebGL3(gl2)) {
|
|
5949
6076
|
throw new Error("Invalid WebGLRenderingContext");
|
|
5950
6077
|
}
|
|
5951
|
-
return new _WebGLDevice({ gl });
|
|
6078
|
+
return new _WebGLDevice({ gl: gl2 });
|
|
5952
6079
|
}
|
|
5953
6080
|
static create() {
|
|
5954
6081
|
return __async(this, arguments, function* (props = {}) {
|
|
@@ -6099,11 +6226,11 @@ var _WebGLDevice = class extends import_api26.Device {
|
|
|
6099
6226
|
* Be aware that there are some duplicates especially for constants that are 0,
|
|
6100
6227
|
* so this isn't guaranteed to return the right key in all cases.
|
|
6101
6228
|
*/
|
|
6102
|
-
getGLKey(value,
|
|
6103
|
-
|
|
6229
|
+
getGLKey(value, gl2) {
|
|
6230
|
+
gl2 = gl2 || this.gl2 || this.gl;
|
|
6104
6231
|
const number = Number(value);
|
|
6105
|
-
for (const key in
|
|
6106
|
-
if (
|
|
6232
|
+
for (const key in gl2) {
|
|
6233
|
+
if (gl2[key] === number) {
|
|
6107
6234
|
return `GL.${key}`;
|
|
6108
6235
|
}
|
|
6109
6236
|
}
|
|
@@ -6115,20 +6242,20 @@ var WebGLDevice = _WebGLDevice;
|
|
|
6115
6242
|
// Public `Device` API
|
|
6116
6243
|
//
|
|
6117
6244
|
WebGLDevice.type = "webgl";
|
|
6118
|
-
function isWebGL3(
|
|
6119
|
-
if (typeof WebGLRenderingContext !== "undefined" &&
|
|
6245
|
+
function isWebGL3(gl2) {
|
|
6246
|
+
if (typeof WebGLRenderingContext !== "undefined" && gl2 instanceof WebGLRenderingContext) {
|
|
6120
6247
|
return true;
|
|
6121
6248
|
}
|
|
6122
|
-
if (typeof WebGL2RenderingContext !== "undefined" &&
|
|
6249
|
+
if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
|
|
6123
6250
|
return true;
|
|
6124
6251
|
}
|
|
6125
|
-
return Boolean(
|
|
6252
|
+
return Boolean(gl2 && Number.isFinite(gl2._version));
|
|
6126
6253
|
}
|
|
6127
|
-
function isWebGL22(
|
|
6128
|
-
if (typeof WebGL2RenderingContext !== "undefined" &&
|
|
6254
|
+
function isWebGL22(gl2) {
|
|
6255
|
+
if (typeof WebGL2RenderingContext !== "undefined" && gl2 instanceof WebGL2RenderingContext) {
|
|
6129
6256
|
return true;
|
|
6130
6257
|
}
|
|
6131
|
-
return Boolean(
|
|
6258
|
+
return Boolean(gl2 && gl2._version === 2);
|
|
6132
6259
|
}
|
|
6133
6260
|
|
|
6134
6261
|
// src/classic/clear.ts
|
|
@@ -6137,8 +6264,8 @@ var GL_DEPTH_BUFFER_BIT2 = 256;
|
|
|
6137
6264
|
var GL_STENCIL_BUFFER_BIT2 = 1024;
|
|
6138
6265
|
var GL_COLOR_BUFFER_BIT2 = 16384;
|
|
6139
6266
|
var ERR_ARGUMENTS = "clear: bad arguments";
|
|
6140
|
-
function clear(
|
|
6141
|
-
const device = WebGLDevice.attach(
|
|
6267
|
+
function clear(gl2, options) {
|
|
6268
|
+
const device = WebGLDevice.attach(gl2);
|
|
6142
6269
|
const { framebuffer = null, color = null, depth = null, stencil = null } = options || {};
|
|
6143
6270
|
const parameters = {};
|
|
6144
6271
|
if (framebuffer) {
|
|
@@ -6226,7 +6353,7 @@ function readPixelsToArray(source, options) {
|
|
|
6226
6353
|
} = options || {};
|
|
6227
6354
|
const { framebuffer, deleteFramebuffer } = getFramebuffer2(source);
|
|
6228
6355
|
(0, import_api29.assert)(framebuffer);
|
|
6229
|
-
const { gl, handle } = framebuffer;
|
|
6356
|
+
const { gl: gl2, handle } = framebuffer;
|
|
6230
6357
|
sourceWidth = sourceWidth || framebuffer.width;
|
|
6231
6358
|
sourceHeight = sourceHeight || framebuffer.height;
|
|
6232
6359
|
if (sourceAttachment === import_constants28.GL.COLOR_ATTACHMENT0 && handle === null) {
|
|
@@ -6236,9 +6363,9 @@ function readPixelsToArray(source, options) {
|
|
|
6236
6363
|
sourceType = sourceType || framebuffer.colorAttachments[attachment].type;
|
|
6237
6364
|
target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
|
|
6238
6365
|
sourceType = sourceType || getGLTypeFromTypedArray(target);
|
|
6239
|
-
const prevHandle2 =
|
|
6240
|
-
|
|
6241
|
-
|
|
6366
|
+
const prevHandle2 = gl2.bindFramebuffer(import_constants28.GL.FRAMEBUFFER, handle);
|
|
6367
|
+
gl2.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
|
|
6368
|
+
gl2.bindFramebuffer(import_constants28.GL.FRAMEBUFFER, prevHandle2 || null);
|
|
6242
6369
|
if (deleteFramebuffer) {
|
|
6243
6370
|
framebuffer.destroy();
|
|
6244
6371
|
}
|
|
@@ -6278,6 +6405,98 @@ function readPixelsToBuffer(source, options) {
|
|
|
6278
6405
|
}
|
|
6279
6406
|
return target;
|
|
6280
6407
|
}
|
|
6408
|
+
function copyToTexture(source, target, options) {
|
|
6409
|
+
const {
|
|
6410
|
+
sourceX = 0,
|
|
6411
|
+
sourceY = 0,
|
|
6412
|
+
// attachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
|
|
6413
|
+
targetMipmaplevel = 0,
|
|
6414
|
+
targetInternalFormat = import_constants28.GL.RGBA
|
|
6415
|
+
} = options || {};
|
|
6416
|
+
let {
|
|
6417
|
+
targetX,
|
|
6418
|
+
targetY,
|
|
6419
|
+
targetZ,
|
|
6420
|
+
width,
|
|
6421
|
+
// defaults to target width
|
|
6422
|
+
height
|
|
6423
|
+
// defaults to target height
|
|
6424
|
+
} = options || {};
|
|
6425
|
+
const { framebuffer, deleteFramebuffer } = getFramebuffer2(source);
|
|
6426
|
+
(0, import_api29.assert)(framebuffer);
|
|
6427
|
+
const webglFramebuffer = framebuffer;
|
|
6428
|
+
const { device, handle } = webglFramebuffer;
|
|
6429
|
+
const isSubCopy = typeof targetX !== "undefined" || typeof targetY !== "undefined" || typeof targetZ !== "undefined";
|
|
6430
|
+
targetX = targetX || 0;
|
|
6431
|
+
targetY = targetY || 0;
|
|
6432
|
+
targetZ = targetZ || 0;
|
|
6433
|
+
const prevHandle2 = device.gl.bindFramebuffer(import_constants28.GL.FRAMEBUFFER, handle);
|
|
6434
|
+
(0, import_api29.assert)(target);
|
|
6435
|
+
let texture = null;
|
|
6436
|
+
let textureTarget;
|
|
6437
|
+
if (target instanceof import_api29.Texture) {
|
|
6438
|
+
texture = target;
|
|
6439
|
+
width = Number.isFinite(width) ? width : texture.width;
|
|
6440
|
+
height = Number.isFinite(height) ? height : texture.height;
|
|
6441
|
+
texture.bind(0);
|
|
6442
|
+
textureTarget = texture.target;
|
|
6443
|
+
} else {
|
|
6444
|
+
textureTarget = target;
|
|
6445
|
+
}
|
|
6446
|
+
if (!isSubCopy) {
|
|
6447
|
+
device.gl.copyTexImage2D(
|
|
6448
|
+
textureTarget,
|
|
6449
|
+
targetMipmaplevel,
|
|
6450
|
+
targetInternalFormat,
|
|
6451
|
+
sourceX,
|
|
6452
|
+
sourceY,
|
|
6453
|
+
width,
|
|
6454
|
+
height,
|
|
6455
|
+
0
|
|
6456
|
+
/* border must be 0 */
|
|
6457
|
+
);
|
|
6458
|
+
} else {
|
|
6459
|
+
switch (textureTarget) {
|
|
6460
|
+
case import_constants28.GL.TEXTURE_2D:
|
|
6461
|
+
case import_constants28.GL.TEXTURE_CUBE_MAP:
|
|
6462
|
+
device.gl.copyTexSubImage2D(
|
|
6463
|
+
textureTarget,
|
|
6464
|
+
targetMipmaplevel,
|
|
6465
|
+
targetX,
|
|
6466
|
+
targetY,
|
|
6467
|
+
sourceX,
|
|
6468
|
+
sourceY,
|
|
6469
|
+
width,
|
|
6470
|
+
height
|
|
6471
|
+
);
|
|
6472
|
+
break;
|
|
6473
|
+
case import_constants28.GL.TEXTURE_2D_ARRAY:
|
|
6474
|
+
case import_constants28.GL.TEXTURE_3D:
|
|
6475
|
+
device.assertWebGL2();
|
|
6476
|
+
device.gl2.copyTexSubImage3D(
|
|
6477
|
+
textureTarget,
|
|
6478
|
+
targetMipmaplevel,
|
|
6479
|
+
targetX,
|
|
6480
|
+
targetY,
|
|
6481
|
+
targetZ,
|
|
6482
|
+
sourceX,
|
|
6483
|
+
sourceY,
|
|
6484
|
+
width,
|
|
6485
|
+
height
|
|
6486
|
+
);
|
|
6487
|
+
break;
|
|
6488
|
+
default:
|
|
6489
|
+
}
|
|
6490
|
+
}
|
|
6491
|
+
if (texture) {
|
|
6492
|
+
texture.unbind();
|
|
6493
|
+
}
|
|
6494
|
+
gl.bindFramebuffer(import_constants28.GL.FRAMEBUFFER, prevHandle2 || null);
|
|
6495
|
+
if (deleteFramebuffer) {
|
|
6496
|
+
framebuffer.destroy();
|
|
6497
|
+
}
|
|
6498
|
+
return texture;
|
|
6499
|
+
}
|
|
6281
6500
|
function getFramebuffer2(source) {
|
|
6282
6501
|
if (!(source instanceof import_api29.Framebuffer)) {
|
|
6283
6502
|
return { framebuffer: toFramebuffer(source), deleteFramebuffer: true };
|