@luma.gl/webgl 9.3.0-alpha.2 → 9.3.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/helpers/get-shader-layout-from-glsl.js +11 -8
- package/dist/adapter/helpers/get-shader-layout-from-glsl.js.map +1 -1
- package/dist/adapter/helpers/parse-shader-compiler-log.d.ts +1 -1
- package/dist/adapter/helpers/parse-shader-compiler-log.d.ts.map +1 -1
- package/dist/adapter/helpers/parse-shader-compiler-log.js +20 -0
- package/dist/adapter/helpers/parse-shader-compiler-log.js.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.d.ts +2 -3
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +9 -5
- package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +5 -0
- package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +1 -2
- package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
- package/dist/adapter/resources/webgl-transform-feedback.js +5 -5
- package/dist/adapter/resources/webgl-transform-feedback.js.map +1 -1
- package/dist/adapter/webgl-adapter.d.ts.map +1 -1
- package/dist/adapter/webgl-adapter.js +3 -4
- package/dist/adapter/webgl-adapter.js.map +1 -1
- package/dist/adapter/webgl-device.d.ts +2 -1
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +25 -11
- package/dist/adapter/webgl-device.js.map +1 -1
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/spector.js +4 -4
- package/dist/context/debug/spector.js.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +2 -0
- package/dist/context/debug/webgl-developer-tools.js.map +1 -1
- package/dist/context/helpers/create-browser-context.d.ts.map +1 -1
- package/dist/context/helpers/create-browser-context.js +6 -8
- package/dist/context/helpers/create-browser-context.js.map +1 -1
- package/dist/context/helpers/webgl-context-data.d.ts +5 -1
- package/dist/context/helpers/webgl-context-data.d.ts.map +1 -1
- package/dist/context/helpers/webgl-context-data.js +9 -10
- package/dist/context/helpers/webgl-context-data.js.map +1 -1
- package/dist/context/parameters/unified-parameter-api.d.ts +1 -1
- package/dist/context/parameters/unified-parameter-api.js +2 -2
- package/dist/context/parameters/unified-parameter-api.js.map +1 -1
- package/dist/context/state-tracker/webgl-state-tracker.js +2 -2
- package/dist/context/state-tracker/webgl-state-tracker.js.map +1 -1
- package/dist/dist.dev.js +104 -49
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +108 -44
- package/dist/index.cjs.map +4 -4
- package/dist/utils/fill-array.js +1 -1
- package/dist/utils/fill-array.js.map +1 -1
- package/package.json +4 -4
- package/src/adapter/helpers/get-shader-layout-from-glsl.ts +11 -9
- package/src/adapter/helpers/parse-shader-compiler-log.ts +23 -1
- package/src/adapter/resources/webgl-command-buffer.ts +18 -22
- package/src/adapter/resources/webgl-render-pass.ts +6 -0
- package/src/adapter/resources/webgl-render-pipeline.ts +1 -2
- package/src/adapter/resources/webgl-transform-feedback.ts +5 -5
- package/src/adapter/webgl-adapter.ts +3 -4
- package/src/adapter/webgl-device.ts +26 -15
- package/src/context/debug/spector.ts +4 -4
- package/src/context/debug/webgl-developer-tools.ts +2 -0
- package/src/context/helpers/create-browser-context.ts +8 -8
- package/src/context/helpers/webgl-context-data.ts +17 -11
- package/src/context/parameters/unified-parameter-api.ts +2 -2
- package/src/context/state-tracker/webgl-state-tracker.ts +2 -2
- package/src/utils/fill-array.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -155,6 +155,24 @@ var init_load_script = __esm({
|
|
|
155
155
|
}
|
|
156
156
|
});
|
|
157
157
|
|
|
158
|
+
// dist/context/helpers/webgl-context-data.js
|
|
159
|
+
function getWebGLContextData(gl) {
|
|
160
|
+
const contextData = gl.luma || {
|
|
161
|
+
_polyfilled: false,
|
|
162
|
+
extensions: {},
|
|
163
|
+
softwareRenderer: false
|
|
164
|
+
};
|
|
165
|
+
contextData._polyfilled ??= false;
|
|
166
|
+
contextData.extensions ||= {};
|
|
167
|
+
gl.luma = contextData;
|
|
168
|
+
return contextData;
|
|
169
|
+
}
|
|
170
|
+
var init_webgl_context_data = __esm({
|
|
171
|
+
"dist/context/helpers/webgl-context-data.js"() {
|
|
172
|
+
"use strict";
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
158
176
|
// dist/context/debug/spector.js
|
|
159
177
|
async function loadSpectorJS(props) {
|
|
160
178
|
if (!globalThis.SPECTOR) {
|
|
@@ -195,9 +213,10 @@ function initializeSpectorJS(props) {
|
|
|
195
213
|
}
|
|
196
214
|
if (props.gl) {
|
|
197
215
|
const gl = props.gl;
|
|
198
|
-
const
|
|
216
|
+
const contextData = getWebGLContextData(gl);
|
|
217
|
+
const device = contextData.device;
|
|
199
218
|
spector == null ? void 0 : spector.startCapture(props.gl, 500);
|
|
200
|
-
|
|
219
|
+
contextData.device = device;
|
|
201
220
|
new Promise((resolve) => setTimeout(resolve, 2e3)).then((_) => {
|
|
202
221
|
import_core.log.info("Spector capture stopped after 2 seconds")();
|
|
203
222
|
spector == null ? void 0 : spector.stopCapture();
|
|
@@ -211,6 +230,7 @@ var init_spector = __esm({
|
|
|
211
230
|
"use strict";
|
|
212
231
|
import_core = require("@luma.gl/core");
|
|
213
232
|
init_load_script();
|
|
233
|
+
init_webgl_context_data();
|
|
214
234
|
LOG_LEVEL = 1;
|
|
215
235
|
spector = null;
|
|
216
236
|
initialized = false;
|
|
@@ -226,7 +246,7 @@ var init_spector = __esm({
|
|
|
226
246
|
});
|
|
227
247
|
|
|
228
248
|
// dist/context/debug/webgl-developer-tools.js
|
|
229
|
-
function
|
|
249
|
+
function getWebGLContextData2(gl) {
|
|
230
250
|
gl.luma = gl.luma || {};
|
|
231
251
|
return gl.luma;
|
|
232
252
|
}
|
|
@@ -241,7 +261,7 @@ function makeDebugContext(gl, props = {}) {
|
|
|
241
261
|
return props.debugWebGL || props.traceWebGL ? getDebugContext(gl, props) : getRealContext(gl);
|
|
242
262
|
}
|
|
243
263
|
function getRealContext(gl) {
|
|
244
|
-
const data =
|
|
264
|
+
const data = getWebGLContextData2(gl);
|
|
245
265
|
return data.realContext ? data.realContext : gl;
|
|
246
266
|
}
|
|
247
267
|
function getDebugContext(gl, props) {
|
|
@@ -249,7 +269,7 @@ function getDebugContext(gl, props) {
|
|
|
249
269
|
import_core2.log.warn("webgl-debug not loaded")();
|
|
250
270
|
return gl;
|
|
251
271
|
}
|
|
252
|
-
const data =
|
|
272
|
+
const data = getWebGLContextData2(gl);
|
|
253
273
|
if (data.debugContext) {
|
|
254
274
|
return data.debugContext;
|
|
255
275
|
}
|
|
@@ -267,6 +287,7 @@ function getDebugContext(gl, props) {
|
|
|
267
287
|
const debugContext = Object.create(WebGLDebugContext);
|
|
268
288
|
data.realContext = gl;
|
|
269
289
|
data.debugContext = debugContext;
|
|
290
|
+
debugContext.luma = data;
|
|
270
291
|
debugContext.debug = true;
|
|
271
292
|
return debugContext;
|
|
272
293
|
}
|
|
@@ -791,6 +812,7 @@ var init_webgl_parameter_tables = __esm({
|
|
|
791
812
|
|
|
792
813
|
// dist/context/parameters/unified-parameter-api.js
|
|
793
814
|
function setGLParameters(gl, parameters) {
|
|
815
|
+
var _a;
|
|
794
816
|
if (isObjectEmpty(parameters)) {
|
|
795
817
|
return;
|
|
796
818
|
}
|
|
@@ -806,7 +828,7 @@ function setGLParameters(gl, parameters) {
|
|
|
806
828
|
}
|
|
807
829
|
}
|
|
808
830
|
}
|
|
809
|
-
const cache = gl.
|
|
831
|
+
const cache = (_a = gl.lumaState) == null ? void 0 : _a.cache;
|
|
810
832
|
if (cache) {
|
|
811
833
|
for (const key in compositeSetters) {
|
|
812
834
|
const compositeSetter = GL_COMPOSITE_PARAMETER_SETTERS[key];
|
|
@@ -929,7 +951,7 @@ var init_webgl_state_tracker = __esm({
|
|
|
929
951
|
init_webgl_parameter_tables();
|
|
930
952
|
WebGLStateTracker = class {
|
|
931
953
|
static get(gl) {
|
|
932
|
-
return gl.
|
|
954
|
+
return gl.lumaState;
|
|
933
955
|
}
|
|
934
956
|
gl;
|
|
935
957
|
program = null;
|
|
@@ -967,7 +989,7 @@ var init_webgl_state_tracker = __esm({
|
|
|
967
989
|
throw new Error("WebGLStateTracker");
|
|
968
990
|
}
|
|
969
991
|
this.initialized = true;
|
|
970
|
-
this.gl.
|
|
992
|
+
this.gl.lumaState = this;
|
|
971
993
|
installProgramSpy(gl);
|
|
972
994
|
for (const key in GL_HOOKED_SETTERS) {
|
|
973
995
|
const setter = GL_HOOKED_SETTERS[key];
|
|
@@ -1027,13 +1049,11 @@ function createBrowserContext(canvas, props, webglContextAttributes) {
|
|
|
1027
1049
|
if (!gl && webglProps.failIfMajorPerformanceCaveat) {
|
|
1028
1050
|
errorMessage ||= "Only software GPU is available. Set `failIfMajorPerformanceCaveat: false` to allow.";
|
|
1029
1051
|
}
|
|
1052
|
+
let softwareRenderer = false;
|
|
1030
1053
|
if (!gl && allowSoftwareRenderer) {
|
|
1031
1054
|
webglProps.failIfMajorPerformanceCaveat = false;
|
|
1032
1055
|
gl = canvas.getContext("webgl2", webglProps);
|
|
1033
|
-
|
|
1034
|
-
gl.luma ||= {};
|
|
1035
|
-
gl.luma.softwareRenderer = true;
|
|
1036
|
-
}
|
|
1056
|
+
softwareRenderer = true;
|
|
1037
1057
|
}
|
|
1038
1058
|
if (!gl) {
|
|
1039
1059
|
gl = canvas.getContext("webgl", {});
|
|
@@ -1046,10 +1066,11 @@ function createBrowserContext(canvas, props, webglContextAttributes) {
|
|
|
1046
1066
|
errorMessage ||= "Your browser does not support WebGL";
|
|
1047
1067
|
throw new Error(`Failed to create WebGL context: ${errorMessage}`);
|
|
1048
1068
|
}
|
|
1069
|
+
const luma = getWebGLContextData(gl);
|
|
1070
|
+
luma.softwareRenderer = softwareRenderer;
|
|
1049
1071
|
const { onContextLost, onContextRestored } = props;
|
|
1050
1072
|
canvas.addEventListener("webglcontextlost", (event) => onContextLost(event), false);
|
|
1051
1073
|
canvas.addEventListener("webglcontextrestored", (event) => onContextRestored(event), false);
|
|
1052
|
-
gl.luma ||= {};
|
|
1053
1074
|
return gl;
|
|
1054
1075
|
} finally {
|
|
1055
1076
|
canvas.removeEventListener("webglcontextcreationerror", onCreateError, false);
|
|
@@ -1058,6 +1079,7 @@ function createBrowserContext(canvas, props, webglContextAttributes) {
|
|
|
1058
1079
|
var init_create_browser_context = __esm({
|
|
1059
1080
|
"dist/context/helpers/create-browser-context.js"() {
|
|
1060
1081
|
"use strict";
|
|
1082
|
+
init_webgl_context_data();
|
|
1061
1083
|
}
|
|
1062
1084
|
});
|
|
1063
1085
|
|
|
@@ -1988,15 +2010,27 @@ var init_webgl_buffer = __esm({
|
|
|
1988
2010
|
|
|
1989
2011
|
// dist/adapter/helpers/parse-shader-compiler-log.js
|
|
1990
2012
|
function parseShaderCompilerLog(errLog) {
|
|
2013
|
+
var _a;
|
|
1991
2014
|
const lines = errLog.split(/\r?\n/);
|
|
1992
2015
|
const messages = [];
|
|
1993
2016
|
for (const line of lines) {
|
|
1994
2017
|
if (line.length <= 1) {
|
|
1995
2018
|
continue;
|
|
1996
2019
|
}
|
|
2020
|
+
const lineWithTrimmedWhitespace = line.trim();
|
|
1997
2021
|
const segments = line.split(":");
|
|
2022
|
+
const trimmedMessageType = (_a = segments[0]) == null ? void 0 : _a.trim();
|
|
1998
2023
|
if (segments.length === 2) {
|
|
1999
2024
|
const [messageType2, message2] = segments;
|
|
2025
|
+
if (!messageType2 || !message2) {
|
|
2026
|
+
messages.push({
|
|
2027
|
+
message: lineWithTrimmedWhitespace,
|
|
2028
|
+
type: getMessageType(trimmedMessageType || "info"),
|
|
2029
|
+
lineNum: 0,
|
|
2030
|
+
linePos: 0
|
|
2031
|
+
});
|
|
2032
|
+
continue;
|
|
2033
|
+
}
|
|
2000
2034
|
messages.push({
|
|
2001
2035
|
message: message2.trim(),
|
|
2002
2036
|
type: getMessageType(messageType2),
|
|
@@ -2006,6 +2040,15 @@ function parseShaderCompilerLog(errLog) {
|
|
|
2006
2040
|
continue;
|
|
2007
2041
|
}
|
|
2008
2042
|
const [messageType, linePosition, lineNumber, ...rest] = segments;
|
|
2043
|
+
if (!messageType || !linePosition || !lineNumber) {
|
|
2044
|
+
messages.push({
|
|
2045
|
+
message: segments.slice(1).join(":").trim() || lineWithTrimmedWhitespace,
|
|
2046
|
+
type: getMessageType(trimmedMessageType || "info"),
|
|
2047
|
+
lineNum: 0,
|
|
2048
|
+
linePos: 0
|
|
2049
|
+
});
|
|
2050
|
+
continue;
|
|
2051
|
+
}
|
|
2009
2052
|
let lineNum = parseInt(lineNumber, 10);
|
|
2010
2053
|
if (isNaN(lineNum)) {
|
|
2011
2054
|
lineNum = 0;
|
|
@@ -3203,7 +3246,11 @@ function readUniformBlocks(gl, program) {
|
|
|
3203
3246
|
const uniformOffset = gl.getActiveUniforms(program, uniformIndices, 35387);
|
|
3204
3247
|
const uniformStride = gl.getActiveUniforms(program, uniformIndices, 35388);
|
|
3205
3248
|
for (let i = 0; i < blockInfo.uniformCount; ++i) {
|
|
3206
|
-
const
|
|
3249
|
+
const uniformIndex = uniformIndices[i];
|
|
3250
|
+
if (uniformIndex === void 0) {
|
|
3251
|
+
continue;
|
|
3252
|
+
}
|
|
3253
|
+
const activeInfo = gl.getActiveUniform(program, uniformIndex);
|
|
3207
3254
|
if (!activeInfo) {
|
|
3208
3255
|
throw new Error("activeInfo");
|
|
3209
3256
|
}
|
|
@@ -3234,13 +3281,12 @@ function parseUniformName(name) {
|
|
|
3234
3281
|
}
|
|
3235
3282
|
const UNIFORM_NAME_REGEXP = /([^[]*)(\[[0-9]+\])?/;
|
|
3236
3283
|
const matches = UNIFORM_NAME_REGEXP.exec(name);
|
|
3237
|
-
|
|
3238
|
-
throw new Error(`Failed to parse GLSL uniform name ${name}`);
|
|
3239
|
-
}
|
|
3284
|
+
const uniformName = (0, import_core15.assertDefined)(matches == null ? void 0 : matches[1], `Failed to parse GLSL uniform name ${name}`);
|
|
3240
3285
|
return {
|
|
3241
|
-
name:
|
|
3242
|
-
|
|
3243
|
-
|
|
3286
|
+
name: uniformName,
|
|
3287
|
+
// TODO - is this a bug, shouldn't we return the value?
|
|
3288
|
+
length: (matches == null ? void 0 : matches[2]) ? 1 : 0,
|
|
3289
|
+
isArray: Boolean(matches == null ? void 0 : matches[2])
|
|
3244
3290
|
};
|
|
3245
3291
|
}
|
|
3246
3292
|
var import_core15, import_constants17;
|
|
@@ -3701,7 +3747,7 @@ var init_webgl_render_pipeline = __esm({
|
|
|
3701
3747
|
if (location === 4294967295) {
|
|
3702
3748
|
throw new Error(`Invalid uniform block name ${name}`);
|
|
3703
3749
|
}
|
|
3704
|
-
gl.uniformBlockBinding(this.handle,
|
|
3750
|
+
gl.uniformBlockBinding(this.handle, location, uniformBufferIndex);
|
|
3705
3751
|
if (value instanceof WEBGLBuffer) {
|
|
3706
3752
|
gl.bindBufferBase(35345, uniformBufferIndex, value.handle);
|
|
3707
3753
|
} else {
|
|
@@ -3789,7 +3835,7 @@ function _copyTextureToBuffer(device, options) {
|
|
|
3789
3835
|
height = options.sourceTexture.height,
|
|
3790
3836
|
depthOrArrayLayers = 0,
|
|
3791
3837
|
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
|
|
3792
|
-
origin = [0, 0],
|
|
3838
|
+
origin = [0, 0, 0],
|
|
3793
3839
|
/** Destination buffer */
|
|
3794
3840
|
destinationBuffer,
|
|
3795
3841
|
/** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */
|
|
@@ -3818,7 +3864,8 @@ function _copyTextureToBuffer(device, options) {
|
|
|
3818
3864
|
const webglBuffer = destinationBuffer;
|
|
3819
3865
|
const sourceWidth = width || framebuffer.width;
|
|
3820
3866
|
const sourceHeight = height || framebuffer.height;
|
|
3821
|
-
const
|
|
3867
|
+
const colorAttachment0 = (0, import_core17.assertDefined)(framebuffer.colorAttachments[0]);
|
|
3868
|
+
const sourceParams = getTextureFormatWebGL(colorAttachment0.texture.props.format);
|
|
3822
3869
|
const sourceFormat = sourceParams.format;
|
|
3823
3870
|
const sourceType = sourceParams.type;
|
|
3824
3871
|
device.gl.bindBuffer(35051, webglBuffer.handle);
|
|
@@ -3845,7 +3892,7 @@ function _copyTextureToTexture(device, options) {
|
|
|
3845
3892
|
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy from. */
|
|
3846
3893
|
origin = [0, 0],
|
|
3847
3894
|
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to. */
|
|
3848
|
-
destinationOrigin = [0, 0],
|
|
3895
|
+
destinationOrigin = [0, 0, 0],
|
|
3849
3896
|
/** Texture to copy to/from. */
|
|
3850
3897
|
destinationTexture
|
|
3851
3898
|
/** Mip-map level of the texture to copy to/from. (Default 0) */
|
|
@@ -3861,7 +3908,7 @@ function _copyTextureToTexture(device, options) {
|
|
|
3861
3908
|
// depthOrArrayLayers = 0
|
|
3862
3909
|
} = options;
|
|
3863
3910
|
const { framebuffer, destroyFramebuffer } = getFramebuffer(sourceTexture);
|
|
3864
|
-
const [sourceX, sourceY] = origin;
|
|
3911
|
+
const [sourceX = 0, sourceY = 0] = origin;
|
|
3865
3912
|
const [destinationX, destinationY, destinationZ] = destinationOrigin;
|
|
3866
3913
|
const prevHandle = device.gl.bindFramebuffer(36160, framebuffer.handle);
|
|
3867
3914
|
let texture;
|
|
@@ -3966,6 +4013,9 @@ var init_webgl_render_pass = __esm({
|
|
|
3966
4013
|
var _a;
|
|
3967
4014
|
super(device, props);
|
|
3968
4015
|
this.device = device;
|
|
4016
|
+
if (!(props == null ? void 0 : props.framebuffer)) {
|
|
4017
|
+
device.getDefaultCanvasContext()._resizeDrawingBufferIfNeeded();
|
|
4018
|
+
}
|
|
3969
4019
|
let viewport;
|
|
3970
4020
|
if (!((_a = props == null ? void 0 : props.parameters) == null ? void 0 : _a.viewport)) {
|
|
3971
4021
|
if (props == null ? void 0 : props.framebuffer) {
|
|
@@ -4169,7 +4219,7 @@ function fillArray(options) {
|
|
|
4169
4219
|
const total = count * length;
|
|
4170
4220
|
let copied = 0;
|
|
4171
4221
|
for (let i = start; copied < length; copied++) {
|
|
4172
|
-
target2[i++] = source[copied];
|
|
4222
|
+
target2[i++] = source[copied] ?? 0;
|
|
4173
4223
|
}
|
|
4174
4224
|
while (copied < total) {
|
|
4175
4225
|
if (copied < total - copied) {
|
|
@@ -4461,8 +4511,8 @@ var init_webgl_transform_feedback = __esm({
|
|
|
4461
4511
|
this.buffers = {};
|
|
4462
4512
|
this.unusedBuffers = {};
|
|
4463
4513
|
this.bind(() => {
|
|
4464
|
-
for (const bufferName
|
|
4465
|
-
this.setBuffer(bufferName,
|
|
4514
|
+
for (const [bufferName, buffer] of Object.entries(buffers)) {
|
|
4515
|
+
this.setBuffer(bufferName, buffer);
|
|
4466
4516
|
}
|
|
4467
4517
|
});
|
|
4468
4518
|
}
|
|
@@ -4484,7 +4534,7 @@ var init_webgl_transform_feedback = __esm({
|
|
|
4484
4534
|
return this.buffers[locationOrName] || null;
|
|
4485
4535
|
}
|
|
4486
4536
|
const location = this._getVaryingIndex(locationOrName);
|
|
4487
|
-
return
|
|
4537
|
+
return this.buffers[location] ?? null;
|
|
4488
4538
|
}
|
|
4489
4539
|
bind(funcOrHandle = this.handle) {
|
|
4490
4540
|
if (typeof funcOrHandle !== "function") {
|
|
@@ -4531,8 +4581,8 @@ var init_webgl_transform_feedback = __esm({
|
|
|
4531
4581
|
* cannot be bound to 'TRANSFORM_FEEDBACK_BUFFER' target.
|
|
4532
4582
|
*/
|
|
4533
4583
|
_bindBuffers() {
|
|
4534
|
-
for (const bufferIndex
|
|
4535
|
-
const { buffer, byteLength, byteOffset } = this._getBufferRange(
|
|
4584
|
+
for (const [bufferIndex, bufferEntry] of Object.entries(this.buffers)) {
|
|
4585
|
+
const { buffer, byteLength, byteOffset } = this._getBufferRange(bufferEntry);
|
|
4536
4586
|
this._bindBuffer(Number(bufferIndex), buffer, byteOffset, byteLength);
|
|
4537
4587
|
}
|
|
4538
4588
|
}
|
|
@@ -4949,6 +4999,7 @@ var init_webgl_device = __esm({
|
|
|
4949
4999
|
import_core25 = require("@luma.gl/core");
|
|
4950
5000
|
init_webgl_state_tracker();
|
|
4951
5001
|
init_create_browser_context();
|
|
5002
|
+
init_webgl_context_data();
|
|
4952
5003
|
init_webgl_device_info();
|
|
4953
5004
|
init_webgl_device_features();
|
|
4954
5005
|
init_webgl_device_limits();
|
|
@@ -4973,6 +5024,13 @@ var init_webgl_device = __esm({
|
|
|
4973
5024
|
init_with_parameters();
|
|
4974
5025
|
init_webgl_extensions();
|
|
4975
5026
|
WebGLDevice = class extends import_core25.Device {
|
|
5027
|
+
static getDeviceFromContext(gl) {
|
|
5028
|
+
var _a;
|
|
5029
|
+
if (!gl) {
|
|
5030
|
+
return null;
|
|
5031
|
+
}
|
|
5032
|
+
return ((_a = gl.luma) == null ? void 0 : _a.device) ?? null;
|
|
5033
|
+
}
|
|
4976
5034
|
// Public `Device` API
|
|
4977
5035
|
/** type of this device */
|
|
4978
5036
|
type = "webgl";
|
|
@@ -4994,7 +5052,7 @@ var init_webgl_device = __esm({
|
|
|
4994
5052
|
// @ts-ignore TODO fix
|
|
4995
5053
|
_constants;
|
|
4996
5054
|
/** State used by luma.gl classes - TODO - not used? */
|
|
4997
|
-
|
|
5055
|
+
extensions;
|
|
4998
5056
|
_polyfilled = false;
|
|
4999
5057
|
/** Instance of Spector.js (if initialized) */
|
|
5000
5058
|
spectorJS;
|
|
@@ -5016,13 +5074,14 @@ var init_webgl_device = __esm({
|
|
|
5016
5074
|
}
|
|
5017
5075
|
}
|
|
5018
5076
|
constructor(props) {
|
|
5019
|
-
var _a
|
|
5077
|
+
var _a;
|
|
5020
5078
|
super({ ...props, id: props.id || uid("webgl-device") });
|
|
5021
5079
|
const canvasContextProps = import_core25.Device._getCanvasContextProps(props);
|
|
5022
5080
|
if (!canvasContextProps) {
|
|
5023
5081
|
throw new Error("WebGLDevice requires props.createCanvasContext to be set");
|
|
5024
5082
|
}
|
|
5025
|
-
|
|
5083
|
+
const existingContext = ((_a = canvasContextProps.canvas) == null ? void 0 : _a.gl) ?? null;
|
|
5084
|
+
let device = WebGLDevice.getDeviceFromContext(existingContext);
|
|
5026
5085
|
if (device) {
|
|
5027
5086
|
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
5028
5087
|
}
|
|
@@ -5055,10 +5114,11 @@ var init_webgl_device = __esm({
|
|
|
5055
5114
|
if (!gl) {
|
|
5056
5115
|
throw new Error("WebGL context creation failed");
|
|
5057
5116
|
}
|
|
5058
|
-
device = gl
|
|
5117
|
+
device = WebGLDevice.getDeviceFromContext(gl);
|
|
5059
5118
|
if (device) {
|
|
5060
5119
|
if (props._reuseDevices) {
|
|
5061
5120
|
import_core25.log.log(1, `Not creating a new Device, instead returning a reference to Device ${device.id} already attached to WebGL context`, device)();
|
|
5121
|
+
this.canvasContext.destroy();
|
|
5062
5122
|
device._reused = true;
|
|
5063
5123
|
return device;
|
|
5064
5124
|
}
|
|
@@ -5067,10 +5127,12 @@ var init_webgl_device = __esm({
|
|
|
5067
5127
|
this.handle = gl;
|
|
5068
5128
|
this.gl = gl;
|
|
5069
5129
|
this.spectorJS = initializeSpectorJS({ ...this.props, gl: this.handle });
|
|
5070
|
-
|
|
5071
|
-
|
|
5130
|
+
const contextData = getWebGLContextData(this.handle);
|
|
5131
|
+
contextData.device = this;
|
|
5132
|
+
this.extensions = contextData.extensions || (contextData.extensions = {});
|
|
5133
|
+
this.info = getDeviceInfo(this.gl, this.extensions);
|
|
5072
5134
|
this.limits = new WebGLDeviceLimits(this.gl);
|
|
5073
|
-
this.features = new WebGLDeviceFeatures(this.gl, this.
|
|
5135
|
+
this.features = new WebGLDeviceFeatures(this.gl, this.extensions, this.props._disabledFeatures);
|
|
5074
5136
|
if (this.props._initializeFeatures) {
|
|
5075
5137
|
this.features.initializeFeatures();
|
|
5076
5138
|
}
|
|
@@ -5099,7 +5161,8 @@ var init_webgl_device = __esm({
|
|
|
5099
5161
|
*/
|
|
5100
5162
|
destroy() {
|
|
5101
5163
|
if (!this.props._reuseDevices && !this._reused) {
|
|
5102
|
-
|
|
5164
|
+
const contextData = getWebGLContextData(this.handle);
|
|
5165
|
+
contextData.device = null;
|
|
5103
5166
|
}
|
|
5104
5167
|
}
|
|
5105
5168
|
get isLost() {
|
|
@@ -5187,7 +5250,7 @@ var init_webgl_device = __esm({
|
|
|
5187
5250
|
resetGLParameters(this.gl);
|
|
5188
5251
|
}
|
|
5189
5252
|
_getDeviceSpecificTextureFormatCapabilities(capabilities) {
|
|
5190
|
-
return getTextureFormatCapabilitiesWebGL(this.gl, capabilities, this.
|
|
5253
|
+
return getTextureFormatCapabilitiesWebGL(this.gl, capabilities, this.extensions);
|
|
5191
5254
|
}
|
|
5192
5255
|
//
|
|
5193
5256
|
// WebGL-only API (not part of `Device` API)
|
|
@@ -5275,8 +5338,8 @@ var init_webgl_device = __esm({
|
|
|
5275
5338
|
}
|
|
5276
5339
|
/** Ensure extensions are only requested once */
|
|
5277
5340
|
getExtension(name) {
|
|
5278
|
-
getWebGLExtension(this.gl, name, this.
|
|
5279
|
-
return this.
|
|
5341
|
+
getWebGLExtension(this.gl, name, this.extensions);
|
|
5342
|
+
return this.extensions;
|
|
5280
5343
|
}
|
|
5281
5344
|
// INTERNAL SUPPORT METHODS FOR WEBGL RESOURCES
|
|
5282
5345
|
/**
|
|
@@ -5344,8 +5407,9 @@ var init_webgl_adapter = __esm({
|
|
|
5344
5407
|
if (gl instanceof WebGLDevice2) {
|
|
5345
5408
|
return gl;
|
|
5346
5409
|
}
|
|
5347
|
-
|
|
5348
|
-
|
|
5410
|
+
const existingDevice = WebGLDevice2.getDeviceFromContext(gl);
|
|
5411
|
+
if (existingDevice) {
|
|
5412
|
+
return existingDevice;
|
|
5349
5413
|
}
|
|
5350
5414
|
if (!isWebGL(gl)) {
|
|
5351
5415
|
throw new Error("Invalid WebGL2RenderingContext");
|