@luma.gl/webgl 9.0.0-alpha.21 → 9.0.0-alpha.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/converters/device-parameters.d.ts +1 -1
- package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/device-parameters.js +9 -9
- package/dist/adapter/converters/device-parameters.js.map +1 -1
- package/dist/adapter/converters/sampler-parameters.d.ts +1 -1
- package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/sampler-parameters.js +1 -1
- package/dist/adapter/converters/sampler-parameters.js.map +1 -1
- package/dist/adapter/converters/texture-formats.d.ts +29 -40
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +152 -114
- package/dist/adapter/converters/texture-formats.js.map +1 -1
- package/dist/adapter/device-helpers/device-limits.d.ts +1 -1
- package/dist/adapter/device-helpers/device-limits.d.ts.map +1 -1
- package/dist/adapter/helpers/attribute-utils.d.ts +1 -1
- package/dist/adapter/helpers/attribute-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/attribute-utils.js +1 -1
- package/dist/adapter/helpers/attribute-utils.js.map +1 -1
- package/dist/adapter/helpers/get-shader-info.d.ts +1 -1
- package/dist/adapter/helpers/get-shader-info.d.ts.map +1 -1
- package/dist/adapter/helpers/get-shader-info.js.map +1 -1
- package/dist/adapter/helpers/uniforms.d.ts +7 -8
- package/dist/adapter/helpers/uniforms.d.ts.map +1 -1
- package/dist/adapter/helpers/uniforms.js +4 -4
- package/dist/adapter/helpers/uniforms.js.map +1 -1
- package/dist/adapter/objects/constants-to-keys.d.ts +0 -2
- package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
- package/dist/adapter/objects/constants-to-keys.js +0 -20
- package/dist/adapter/objects/constants-to-keys.js.map +1 -1
- package/dist/adapter/objects/webgl-renderbuffer.d.ts +12 -9
- package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-renderbuffer.js +29 -19
- package/dist/adapter/objects/webgl-renderbuffer.js.map +1 -1
- package/dist/adapter/objects/webgl-resource.d.ts +0 -1
- package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-resource.js +4 -7
- package/dist/adapter/objects/webgl-resource.js.map +1 -1
- package/dist/adapter/objects/webgl-vertex-array-object.d.ts +1 -1
- package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +3 -2
- package/dist/adapter/resources/webgl-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.d.ts +13 -7
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +168 -25
- package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.d.ts +3 -2
- package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js +6 -2
- package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.d.ts +11 -14
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +29 -79
- package/dist/adapter/resources/webgl-framebuffer.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.d.ts +16 -1
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +80 -0
- package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +5 -5
- package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
- package/dist/adapter/resources/webgl-sampler.d.ts +1 -1
- package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-sampler.js +1 -1
- package/dist/adapter/resources/webgl-sampler.js.map +1 -1
- package/dist/adapter/resources/webgl-texture.d.ts +43 -23
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +32 -30
- package/dist/adapter/resources/webgl-texture.js.map +1 -1
- package/dist/adapter/webgl-canvas-context.d.ts +1 -2
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js.map +1 -1
- package/dist/adapter/webgl-device.d.ts +13 -6
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +20 -2
- package/dist/adapter/webgl-device.js.map +1 -1
- package/dist/classic/buffer.d.ts +1 -2
- package/dist/classic/buffer.d.ts.map +1 -1
- package/dist/classic/buffer.js +0 -6
- package/dist/classic/buffer.js.map +1 -1
- package/dist/classic/clear.d.ts +22 -0
- package/dist/classic/clear.d.ts.map +1 -0
- package/dist/classic/clear.js +88 -0
- package/dist/classic/clear.js.map +1 -0
- package/dist/classic/copy-and-blit.d.ts +45 -0
- package/dist/classic/copy-and-blit.d.ts.map +1 -0
- package/dist/classic/copy-and-blit.js +136 -0
- package/dist/classic/copy-and-blit.js.map +1 -0
- package/dist/classic/format-utils.d.ts +3 -0
- package/dist/classic/format-utils.d.ts.map +1 -0
- package/dist/classic/format-utils.js +38 -0
- package/dist/classic/format-utils.js.map +1 -0
- package/dist/classic/typed-array-utils.d.ts +15 -17
- package/dist/classic/typed-array-utils.d.ts.map +1 -1
- package/dist/classic/typed-array-utils.js +1 -1
- package/dist/classic/typed-array-utils.js.map +1 -1
- package/dist/context/context/create-browser-context.d.ts +17 -19
- package/dist/context/context/create-browser-context.d.ts.map +1 -1
- package/dist/context/context/create-browser-context.js +4 -4
- package/dist/context/context/create-browser-context.js.map +1 -1
- package/dist/context/context/create-headless-context.d.ts +1 -1
- package/dist/context/context/create-headless-context.d.ts.map +1 -1
- package/dist/context/debug/spector.d.ts +1 -3
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.d.ts +1 -1
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/parameters/unified-parameter-api.d.ts +1 -1
- package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
- package/dist/context/parameters/unified-parameter-api.js.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.d.ts +2 -3
- package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
- package/dist/dist.dev.js +1306 -659
- package/dist/index.cjs +1269 -897
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist.min.js +22 -21
- package/package.json +7 -4
- package/src/adapter/converters/device-parameters.ts +46 -22
- package/src/adapter/converters/sampler-parameters.ts +1 -2
- package/src/adapter/converters/texture-formats.ts +242 -161
- package/src/adapter/helpers/attribute-utils.ts +1 -2
- package/src/adapter/helpers/get-shader-info.ts +3 -0
- package/src/adapter/helpers/uniforms.ts +9 -10
- package/src/adapter/objects/constants-to-keys.ts +0 -25
- package/src/adapter/objects/webgl-renderbuffer.ts +32 -29
- package/src/adapter/objects/webgl-resource.ts +4 -8
- package/src/adapter/resources/webgl-buffer.ts +4 -5
- package/src/adapter/resources/webgl-command-buffer.ts +328 -21
- package/src/adapter/resources/webgl-command-encoder.ts +7 -2
- package/src/adapter/resources/webgl-framebuffer.ts +63 -111
- package/src/adapter/resources/webgl-render-pass.ts +146 -2
- package/src/adapter/resources/webgl-render-pipeline.ts +7 -4
- package/src/adapter/resources/webgl-sampler.ts +1 -2
- package/src/adapter/resources/webgl-texture.ts +61 -43
- package/src/adapter/webgl-canvas-context.ts +2 -2
- package/src/adapter/webgl-device.ts +37 -8
- package/src/classic/buffer.ts +3 -3
- package/src/classic/clear.ts +110 -0
- package/src/classic/copy-and-blit.ts +189 -0
- package/src/classic/format-utils.ts +43 -0
- package/src/classic/typed-array-utils.ts +15 -26
- package/src/context/context/create-browser-context.ts +37 -30
- package/src/context/parameters/unified-parameter-api.ts +1 -1
- package/src/context/parameters/webgl-parameter-tables.ts +2 -2
- package/src/index.ts +10 -3
- package/dist/adapter/converters/renderbuffer-formats.d.ts +0 -16
- package/dist/adapter/converters/renderbuffer-formats.d.ts.map +0 -1
- package/dist/adapter/converters/renderbuffer-formats.js +0 -180
- package/dist/adapter/converters/renderbuffer-formats.js.map +0 -1
- package/dist/types/webgl.d.ts +0 -145
- package/dist/types/webgl.d.ts.map +0 -1
- package/dist/types/webgl.js +0 -2
- package/dist/types/webgl.js.map +0 -1
- package/src/.DS_Store +0 -0
- package/src/adapter/.DS_Store +0 -0
- package/src/adapter/converters/renderbuffer-formats.ts +0 -90
- package/src/context/.DS_Store +0 -0
- package/src/types/webgl.ts +0 -286
package/dist/dist.dev.js
CHANGED
|
@@ -48,9 +48,12 @@ var __exports__ = (() => {
|
|
|
48
48
|
WebGLCanvasContext: () => WebGLCanvasContext,
|
|
49
49
|
WebGLDevice: () => WebGLDevice,
|
|
50
50
|
WebGLResource: () => WebGLResource,
|
|
51
|
+
_TEXTURE_FORMATS: () => TEXTURE_FORMATS,
|
|
51
52
|
_checkFloat32ColorAttachment: () => _checkFloat32ColorAttachment,
|
|
52
53
|
assertWebGL2Context: () => assertWebGL2Context,
|
|
53
54
|
assertWebGLContext: () => assertWebGLContext,
|
|
55
|
+
clear: () => clear,
|
|
56
|
+
convertGLToTextureFormat: () => convertGLToTextureFormat,
|
|
54
57
|
getParameters: () => getParameters,
|
|
55
58
|
getProgramBindings: () => getProgramBindings,
|
|
56
59
|
getShaderLayout: () => getShaderLayout,
|
|
@@ -60,6 +63,8 @@ var __exports__ = (() => {
|
|
|
60
63
|
polyfillContext: () => polyfillContext,
|
|
61
64
|
popContextState: () => popContextState,
|
|
62
65
|
pushContextState: () => pushContextState,
|
|
66
|
+
readPixelsToArray: () => readPixelsToArray,
|
|
67
|
+
readPixelsToBuffer: () => readPixelsToBuffer,
|
|
63
68
|
registerHeadlessGL: () => registerHeadlessGL,
|
|
64
69
|
resetParameters: () => resetParameters,
|
|
65
70
|
setDeviceParameters: () => setDeviceParameters,
|
|
@@ -973,14 +978,17 @@ var __exports__ = (() => {
|
|
|
973
978
|
var DEFAULT_RESOURCE_PROPS = {
|
|
974
979
|
id: "undefined",
|
|
975
980
|
handle: void 0,
|
|
976
|
-
userData:
|
|
981
|
+
userData: void 0
|
|
977
982
|
};
|
|
978
983
|
var Resource = class {
|
|
979
984
|
/** props.id, for debugging. */
|
|
980
985
|
userData = {};
|
|
986
|
+
/** Whether this resource has been destroyed */
|
|
981
987
|
destroyed = false;
|
|
982
988
|
/** For resources that allocate GPU memory */
|
|
983
989
|
allocatedBytes = 0;
|
|
990
|
+
/** Attached resources will be destroyed when this resource is destroyed. Tracks auto-created "sub" resources. */
|
|
991
|
+
_attachedResources = /* @__PURE__ */ new Set();
|
|
984
992
|
/**
|
|
985
993
|
* Create a new Resource. Called from Subclass
|
|
986
994
|
*/
|
|
@@ -1000,7 +1008,7 @@ var __exports__ = (() => {
|
|
|
1000
1008
|
* destroy can be called on any resource to release it before it is garbage collected.
|
|
1001
1009
|
*/
|
|
1002
1010
|
destroy() {
|
|
1003
|
-
this.
|
|
1011
|
+
this.destroyResource();
|
|
1004
1012
|
}
|
|
1005
1013
|
/** @deprecated Use destroy() */
|
|
1006
1014
|
delete() {
|
|
@@ -1017,14 +1025,41 @@ var __exports__ = (() => {
|
|
|
1017
1025
|
getProps() {
|
|
1018
1026
|
return this.props;
|
|
1019
1027
|
}
|
|
1028
|
+
// ATTACHED RESOURCES
|
|
1029
|
+
/**
|
|
1030
|
+
* Attaches a resource. Attached resources are auto destroyed when this resource is destroyed
|
|
1031
|
+
* Called automatically when sub resources are auto created but can be called by application
|
|
1032
|
+
*/
|
|
1033
|
+
attachResource(resource) {
|
|
1034
|
+
this._attachedResources.add(resource);
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* Detach an attached resource. The resource will no longer be auto-destroyed when this resource is destroyed.
|
|
1038
|
+
*/
|
|
1039
|
+
detachResource(resource) {
|
|
1040
|
+
this._attachedResources.delete(resource);
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Destroys a resource (only if owned), and removes from the owned (auto-destroy) list for this resource.
|
|
1044
|
+
*/
|
|
1045
|
+
destroyAttachedResource(resource) {
|
|
1046
|
+
if (this._attachedResources.delete(resource)) {
|
|
1047
|
+
resource.destroy();
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
/** Destroy all owned resources. Make sure the resources are no longer needed before calling. */
|
|
1051
|
+
destroyAttachedResources() {
|
|
1052
|
+
for (const resource of Object.values(this._attachedResources)) {
|
|
1053
|
+
resource.destroy();
|
|
1054
|
+
}
|
|
1055
|
+
this._attachedResources = /* @__PURE__ */ new Set();
|
|
1056
|
+
}
|
|
1020
1057
|
// PROTECTED METHODS
|
|
1021
|
-
/**
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
stats.get(`${name}s Created`).incrementCount();
|
|
1027
|
-
stats.get(`${name}s Active`).incrementCount();
|
|
1058
|
+
/** Perform all destroy steps. Can be called by derived resources when overriding destroy() */
|
|
1059
|
+
destroyResource() {
|
|
1060
|
+
this.destroyAttachedResources();
|
|
1061
|
+
this.removeStats();
|
|
1062
|
+
this.destroyed = true;
|
|
1028
1063
|
}
|
|
1029
1064
|
/** Called by .destroy() to track object destruction. Subclass must call if overriding destroy() */
|
|
1030
1065
|
removeStats() {
|
|
@@ -1046,7 +1081,17 @@ var __exports__ = (() => {
|
|
|
1046
1081
|
stats.get(`${name} Memory`).subtractCount(this.allocatedBytes);
|
|
1047
1082
|
this.allocatedBytes = 0;
|
|
1048
1083
|
}
|
|
1084
|
+
/** Called by resource constructor to track object creation */
|
|
1085
|
+
addStats() {
|
|
1086
|
+
const stats = this._device.statsManager.getStats("Resource Counts");
|
|
1087
|
+
const name = this[Symbol.toStringTag];
|
|
1088
|
+
stats.get("Resources Created").incrementCount();
|
|
1089
|
+
stats.get(`${name}s Created`).incrementCount();
|
|
1090
|
+
stats.get(`${name}s Active`).incrementCount();
|
|
1091
|
+
}
|
|
1049
1092
|
};
|
|
1093
|
+
/** Default properties for resource */
|
|
1094
|
+
__publicField(Resource, "defaultProps", DEFAULT_RESOURCE_PROPS);
|
|
1050
1095
|
function selectivelyMerge(props, defaultProps) {
|
|
1051
1096
|
const mergedProps = {
|
|
1052
1097
|
...defaultProps
|
|
@@ -1074,6 +1119,7 @@ var __exports__ = (() => {
|
|
|
1074
1119
|
get [Symbol.toStringTag]() {
|
|
1075
1120
|
return "Buffer";
|
|
1076
1121
|
}
|
|
1122
|
+
/** Length of buffer in bytes */
|
|
1077
1123
|
constructor(device, props) {
|
|
1078
1124
|
const deducedProps = {
|
|
1079
1125
|
...props
|
|
@@ -1194,34 +1240,30 @@ var __exports__ = (() => {
|
|
|
1194
1240
|
}
|
|
1195
1241
|
statsManager = lumaStats;
|
|
1196
1242
|
userData = {};
|
|
1243
|
+
// Capabilities
|
|
1197
1244
|
/** Information about the device (vendor, versions etc) */
|
|
1198
1245
|
/** Optional capability discovery */
|
|
1199
1246
|
/** WebGPU style device limits */
|
|
1200
1247
|
/** Check if device supports a specific texture format (creation and `nearest` sampling) */
|
|
1201
1248
|
/** Check if linear filtering (sampler interpolation) is supported for a specific texture format */
|
|
1202
1249
|
/** Check if device supports rendering to a specific texture format */
|
|
1203
|
-
|
|
1204
|
-
/**
|
|
1205
|
-
/**
|
|
1250
|
+
// Device loss
|
|
1251
|
+
/** `true` if device is already lost */
|
|
1252
|
+
/** Promise that resolves when device is lost */
|
|
1253
|
+
/**
|
|
1254
|
+
* Trigger device loss.
|
|
1255
|
+
* @returns `true` if context loss could actually be triggered.
|
|
1256
|
+
* @note primarily intended for testing how application reacts to device loss
|
|
1257
|
+
*/
|
|
1258
|
+
loseDevice() {
|
|
1259
|
+
return false;
|
|
1260
|
+
}
|
|
1261
|
+
// Canvas context
|
|
1262
|
+
/** Default / primary canvas context. Can be null as WebGPU devices can be created without a CanvasContext */
|
|
1206
1263
|
/** Creates a new CanvasContext (WebGPU only) */
|
|
1207
1264
|
/** Call after rendering a frame (necessary e.g. on WebGL OffscreenCanvas) */
|
|
1208
1265
|
// Resource creation
|
|
1209
1266
|
/** Create a buffer */
|
|
1210
|
-
createBuffer(props) {
|
|
1211
|
-
if (props instanceof ArrayBuffer || ArrayBuffer.isView(props)) {
|
|
1212
|
-
return this._createBuffer({
|
|
1213
|
-
data: props
|
|
1214
|
-
});
|
|
1215
|
-
}
|
|
1216
|
-
if ((props.usage || 0) & Buffer2.INDEX && !props.indexType) {
|
|
1217
|
-
if (props.data instanceof Uint32Array) {
|
|
1218
|
-
props.indexType = "uint32";
|
|
1219
|
-
} else if (props.data instanceof Uint16Array) {
|
|
1220
|
-
props.indexType = "uint16";
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
return this._createBuffer(props);
|
|
1224
|
-
}
|
|
1225
1267
|
/** Create a texture */
|
|
1226
1268
|
createTexture(props) {
|
|
1227
1269
|
if (props instanceof Promise || typeof props === "string") {
|
|
@@ -1236,9 +1278,31 @@ var __exports__ = (() => {
|
|
|
1236
1278
|
/** Create a shader */
|
|
1237
1279
|
/** Create a render pipeline (aka program) */
|
|
1238
1280
|
/** Create a compute pipeline (aka program) */
|
|
1281
|
+
createCommandEncoder(props = {}) {
|
|
1282
|
+
throw new Error("not implemented");
|
|
1283
|
+
}
|
|
1239
1284
|
/** Create a RenderPass */
|
|
1240
1285
|
/** Create a ComputePass */
|
|
1241
|
-
|
|
1286
|
+
/** Get a renderpass that is set up to render to the primary CanvasContext */
|
|
1287
|
+
// Resource creation helpers
|
|
1288
|
+
_getBufferProps(props) {
|
|
1289
|
+
if (props instanceof ArrayBuffer || ArrayBuffer.isView(props)) {
|
|
1290
|
+
return {
|
|
1291
|
+
data: props
|
|
1292
|
+
};
|
|
1293
|
+
}
|
|
1294
|
+
const newProps = {
|
|
1295
|
+
...props
|
|
1296
|
+
};
|
|
1297
|
+
if ((props.usage || 0) & Buffer2.INDEX && !props.indexType) {
|
|
1298
|
+
if (props.data instanceof Uint32Array) {
|
|
1299
|
+
props.indexType = "uint32";
|
|
1300
|
+
} else if (props.data instanceof Uint16Array) {
|
|
1301
|
+
props.indexType = "uint16";
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
return newProps;
|
|
1305
|
+
}
|
|
1242
1306
|
};
|
|
1243
1307
|
__publicField(Device, "VERSION", VERSION2);
|
|
1244
1308
|
|
|
@@ -1326,13 +1390,15 @@ var __exports__ = (() => {
|
|
|
1326
1390
|
if (typeof OffscreenCanvas !== "undefined" && this.canvas instanceof OffscreenCanvas) {
|
|
1327
1391
|
return 1;
|
|
1328
1392
|
}
|
|
1329
|
-
|
|
1330
|
-
|
|
1393
|
+
useDevicePixels = useDevicePixels === void 0 ? this.props.useDevicePixels : useDevicePixels;
|
|
1394
|
+
if (!useDevicePixels || useDevicePixels <= 0) {
|
|
1395
|
+
return 1;
|
|
1331
1396
|
}
|
|
1332
|
-
if (
|
|
1333
|
-
|
|
1397
|
+
if (useDevicePixels === true) {
|
|
1398
|
+
const dpr = typeof window !== "undefined" && window.devicePixelRatio;
|
|
1399
|
+
return dpr || 1;
|
|
1334
1400
|
}
|
|
1335
|
-
return useDevicePixels
|
|
1401
|
+
return useDevicePixels;
|
|
1336
1402
|
}
|
|
1337
1403
|
/**
|
|
1338
1404
|
* Returns the size of drawing buffer in device pixels.
|
|
@@ -1525,8 +1591,8 @@ var __exports__ = (() => {
|
|
|
1525
1591
|
data: null,
|
|
1526
1592
|
dimension: "2d",
|
|
1527
1593
|
format: "rgba8unorm",
|
|
1528
|
-
|
|
1529
|
-
|
|
1594
|
+
width: void 0,
|
|
1595
|
+
height: void 0,
|
|
1530
1596
|
depth: 1,
|
|
1531
1597
|
mipmaps: true,
|
|
1532
1598
|
sampler: {},
|
|
@@ -1534,20 +1600,28 @@ var __exports__ = (() => {
|
|
|
1534
1600
|
compressed: false,
|
|
1535
1601
|
// mipLevels: 1,
|
|
1536
1602
|
usage: 0,
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
border: 0,
|
|
1541
|
-
recreate: false
|
|
1603
|
+
mipLevels: void 0,
|
|
1604
|
+
samples: void 0,
|
|
1605
|
+
type: void 0
|
|
1542
1606
|
};
|
|
1543
1607
|
var Texture = class extends Resource {
|
|
1544
1608
|
get [Symbol.toStringTag]() {
|
|
1545
1609
|
return "Texture";
|
|
1546
1610
|
}
|
|
1547
|
-
|
|
1548
|
-
|
|
1611
|
+
/** dimension of this texture */
|
|
1612
|
+
/** format of this texture */
|
|
1613
|
+
/** width in pixels of this texture */
|
|
1614
|
+
/** height in pixels of this texture */
|
|
1615
|
+
/** depth of this texture */
|
|
1616
|
+
/** Default sampler for this texture */
|
|
1617
|
+
constructor(device, props, defaultProps = DEFAULT_TEXTURE_PROPS) {
|
|
1618
|
+
super(device, props, defaultProps);
|
|
1619
|
+
this.dimension = this.props.dimension;
|
|
1620
|
+
this.format = this.props.format;
|
|
1621
|
+
this.width = this.props.width;
|
|
1622
|
+
this.height = this.props.height;
|
|
1623
|
+
this.depth = this.props.depth;
|
|
1549
1624
|
}
|
|
1550
|
-
/** Default sampler for this device */
|
|
1551
1625
|
};
|
|
1552
1626
|
__publicField(Texture, "COPY_SRC", 1);
|
|
1553
1627
|
__publicField(Texture, "COPY_DST", 2);
|
|
@@ -1616,6 +1690,10 @@ var __exports__ = (() => {
|
|
|
1616
1690
|
}
|
|
1617
1691
|
/** Width of all attachments in this framebuffer */
|
|
1618
1692
|
/** Height of all attachments in this framebuffer */
|
|
1693
|
+
/** Color attachments */
|
|
1694
|
+
colorAttachments = [];
|
|
1695
|
+
/** Depth-stencil attachment, if provided */
|
|
1696
|
+
depthStencilAttachment = null;
|
|
1619
1697
|
constructor(device, props = {}) {
|
|
1620
1698
|
super(device, props, DEFAULT_FRAMEBUFFER_PROPS);
|
|
1621
1699
|
this.width = this.props.width;
|
|
@@ -1626,16 +1704,162 @@ var __exports__ = (() => {
|
|
|
1626
1704
|
* @note resize() destroys existing textures (if size has changed).
|
|
1627
1705
|
*/
|
|
1628
1706
|
resize(size) {
|
|
1629
|
-
|
|
1707
|
+
let updateSize = !size;
|
|
1630
1708
|
if (size) {
|
|
1631
|
-
|
|
1632
|
-
this.height
|
|
1709
|
+
const [width, height] = Array.isArray(size) ? size : [size.width, size.height];
|
|
1710
|
+
updateSize = updateSize || height !== this.height || width !== this.width;
|
|
1711
|
+
this.width = width;
|
|
1712
|
+
this.height = height;
|
|
1633
1713
|
}
|
|
1634
1714
|
if (updateSize) {
|
|
1635
|
-
|
|
1715
|
+
log.log(2, `Resizing framebuffer ${this.id} to ${this.width}x${this.height}`)();
|
|
1716
|
+
this.resizeAttachments(this.width, this.height);
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
// /** Returns fully populated attachment object. */
|
|
1720
|
+
// protected normalizeColorAttachment(
|
|
1721
|
+
// attachment: Texture | ColorTextureFormat
|
|
1722
|
+
// ): Required<ColorAttachment> {
|
|
1723
|
+
// const COLOR_ATTACHMENT_DEFAULTS: Required<ColorAttachment> = {
|
|
1724
|
+
// texture: undefined!,
|
|
1725
|
+
// format: undefined!,
|
|
1726
|
+
// clearValue: [0.0, 0.0, 0.0, 0.0],
|
|
1727
|
+
// loadOp: 'clear',
|
|
1728
|
+
// storeOp: 'store'
|
|
1729
|
+
// };
|
|
1730
|
+
// if (attachment instanceof Texture) {
|
|
1731
|
+
// return {...COLOR_ATTACHMENT_DEFAULTS, texture: attachment};
|
|
1732
|
+
// }
|
|
1733
|
+
// if (typeof attachment === 'string') {
|
|
1734
|
+
// return {...COLOR_ATTACHMENT_DEFAULTS, format: attachment};
|
|
1735
|
+
// }
|
|
1736
|
+
// return {...COLOR_ATTACHMENT_DEFAULTS, ...attachment};
|
|
1737
|
+
// }
|
|
1738
|
+
// /** Wraps texture inside fully populated attachment object. */
|
|
1739
|
+
// protected normalizeDepthStencilAttachment(
|
|
1740
|
+
// attachment: DepthStencilAttachment | Texture | DepthStencilTextureFormat
|
|
1741
|
+
// ): Required<DepthStencilAttachment> {
|
|
1742
|
+
// const DEPTH_STENCIL_ATTACHMENT_DEFAULTS: Required<DepthStencilAttachment> = {
|
|
1743
|
+
// texture: undefined!,
|
|
1744
|
+
// format: undefined!,
|
|
1745
|
+
// depthClearValue: 1.0,
|
|
1746
|
+
// depthLoadOp: 'clear',
|
|
1747
|
+
// depthStoreOp: 'store',
|
|
1748
|
+
// depthReadOnly: false,
|
|
1749
|
+
// stencilClearValue: 0,
|
|
1750
|
+
// stencilLoadOp: 'clear',
|
|
1751
|
+
// stencilStoreOp: 'store',
|
|
1752
|
+
// stencilReadOnly: false
|
|
1753
|
+
// };
|
|
1754
|
+
// if (typeof attachment === 'string') {
|
|
1755
|
+
// return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, format: attachment};
|
|
1756
|
+
// }
|
|
1757
|
+
// // @ts-expect-error attachment instanceof Texture doesn't cover Renderbuffer
|
|
1758
|
+
// if (attachment.handle || attachment instanceof Texture) {
|
|
1759
|
+
// return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, texture: attachment as Texture};
|
|
1760
|
+
// }
|
|
1761
|
+
// return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, ...attachment};
|
|
1762
|
+
// }
|
|
1763
|
+
/** Auto creates any textures */
|
|
1764
|
+
autoCreateAttachmentTextures() {
|
|
1765
|
+
this.colorAttachments = this.props.colorAttachments.map((attachment) => {
|
|
1766
|
+
if (typeof attachment === "string") {
|
|
1767
|
+
const texture = this.createColorTexture(attachment);
|
|
1768
|
+
this.attachResource(texture);
|
|
1769
|
+
return texture;
|
|
1770
|
+
}
|
|
1771
|
+
return attachment;
|
|
1772
|
+
});
|
|
1773
|
+
if (this.props.depthStencilAttachment) {
|
|
1774
|
+
if (typeof this.props.depthStencilAttachment === "string") {
|
|
1775
|
+
const texture = this.createDepthStencilTexture(this.props.depthStencilAttachment);
|
|
1776
|
+
this.attachResource(texture);
|
|
1777
|
+
this.depthStencilAttachment = texture;
|
|
1778
|
+
} else {
|
|
1779
|
+
this.depthStencilAttachment = this.props.depthStencilAttachment;
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
/** Create a color texture */
|
|
1784
|
+
createColorTexture(format) {
|
|
1785
|
+
return this.device.createTexture({
|
|
1786
|
+
id: "color-attachment",
|
|
1787
|
+
usage: Texture.RENDER_ATTACHMENT,
|
|
1788
|
+
format,
|
|
1789
|
+
width: this.width,
|
|
1790
|
+
height: this.height
|
|
1791
|
+
});
|
|
1792
|
+
}
|
|
1793
|
+
/** Create depth stencil texture */
|
|
1794
|
+
createDepthStencilTexture(format) {
|
|
1795
|
+
return this.device.createTexture({
|
|
1796
|
+
id: "depth-stencil-attachment",
|
|
1797
|
+
usage: Texture.RENDER_ATTACHMENT,
|
|
1798
|
+
format,
|
|
1799
|
+
width: this.width,
|
|
1800
|
+
height: this.height
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
/**
|
|
1804
|
+
* Default implementation of resize
|
|
1805
|
+
* Creates new textures with correct size for all attachments.
|
|
1806
|
+
* and destroys existing textures if owned
|
|
1807
|
+
*/
|
|
1808
|
+
resizeAttachments(width, height) {
|
|
1809
|
+
for (let i = 0; i < this.colorAttachments.length; ++i) {
|
|
1810
|
+
if (this.colorAttachments[i]) {
|
|
1811
|
+
const resizedTexture = this.device._createTexture({
|
|
1812
|
+
...this.colorAttachments[i].props,
|
|
1813
|
+
width,
|
|
1814
|
+
height
|
|
1815
|
+
});
|
|
1816
|
+
this.destroyAttachedResource(this.colorAttachments[i]);
|
|
1817
|
+
this.colorAttachments[i] = resizedTexture;
|
|
1818
|
+
this.attachResource(resizedTexture);
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
if (this.depthStencilAttachment) {
|
|
1822
|
+
const resizedTexture = this.device._createTexture({
|
|
1823
|
+
...this.depthStencilAttachment.props,
|
|
1824
|
+
width,
|
|
1825
|
+
height
|
|
1826
|
+
});
|
|
1827
|
+
this.destroyAttachedResource(this.depthStencilAttachment);
|
|
1828
|
+
this.depthStencilAttachment = resizedTexture;
|
|
1829
|
+
this.attachResource(resizedTexture);
|
|
1636
1830
|
}
|
|
1637
1831
|
}
|
|
1638
|
-
/**
|
|
1832
|
+
/** Create a color attachment for WebGL *
|
|
1833
|
+
protected override createColorTexture(colorAttachment: Required<ColorAttachment>): Required<ColorAttachment> {
|
|
1834
|
+
return this.device._createTexture({
|
|
1835
|
+
id: `${this.id}-color`,
|
|
1836
|
+
data: null, // reserves texture memory, but texels are undefined
|
|
1837
|
+
format,
|
|
1838
|
+
// type: GL.UNSIGNED_BYTE,
|
|
1839
|
+
width: this.width,
|
|
1840
|
+
height: this.height,
|
|
1841
|
+
// Note: Mipmapping can be disabled by texture resource when we resize the texture
|
|
1842
|
+
// to a non-power-of-two dimenstion (NPOT texture) under WebGL1. To have consistant
|
|
1843
|
+
// behavior we always disable mipmaps.
|
|
1844
|
+
mipmaps: false,
|
|
1845
|
+
// Set MIN and MAG filtering parameters so mipmaps are not used in sampling.
|
|
1846
|
+
// Use LINEAR so subpixel algos like fxaa work.
|
|
1847
|
+
// Set WRAP modes that support NPOT textures too.
|
|
1848
|
+
sampler: {
|
|
1849
|
+
minFilter: 'linear',
|
|
1850
|
+
magFilter: 'linear',
|
|
1851
|
+
addressModeU: 'clamp-to-edge',
|
|
1852
|
+
addressModeV: 'clamp-to-edge'
|
|
1853
|
+
}
|
|
1854
|
+
// parameters: {
|
|
1855
|
+
// [GL.TEXTURE_MIN_FILTER]: GL.LINEAR,
|
|
1856
|
+
// [GL.TEXTURE_MAG_FILTER]: GL.LINEAR,
|
|
1857
|
+
// [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
|
|
1858
|
+
// [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE
|
|
1859
|
+
// }
|
|
1860
|
+
});
|
|
1861
|
+
}
|
|
1862
|
+
*/
|
|
1639
1863
|
};
|
|
1640
1864
|
|
|
1641
1865
|
// ../api/src/adapter/resources/render-pipeline.ts
|
|
@@ -1679,49 +1903,15 @@ var __exports__ = (() => {
|
|
|
1679
1903
|
/** Private "export" for Model class */
|
|
1680
1904
|
__publicField(RenderPipeline, "_DEFAULT_PROPS", DEFAULT_RENDER_PIPELINE_PROPS);
|
|
1681
1905
|
|
|
1682
|
-
// ../api/src/adapter/resources/command-encoder.ts
|
|
1683
|
-
var DEFAULT_COMMAND_ENCODER_PROPS = {
|
|
1684
|
-
...DEFAULT_RESOURCE_PROPS
|
|
1685
|
-
};
|
|
1686
|
-
var CommandEncoder = class extends Resource {
|
|
1687
|
-
get [Symbol.toStringTag]() {
|
|
1688
|
-
return "CommandEncoder";
|
|
1689
|
-
}
|
|
1690
|
-
constructor(props) {
|
|
1691
|
-
super(props, DEFAULT_COMMAND_ENCODER_PROPS);
|
|
1692
|
-
}
|
|
1693
|
-
// beginRenderPass(GPURenderPassDescriptor descriptor): GPURenderPassEncoder;
|
|
1694
|
-
// beginComputePass(optional GPUComputePassDescriptor descriptor = {}): GPUComputePassEncoder;
|
|
1695
|
-
// finish(options?: {id?: string}): GPUCommandBuffer;
|
|
1696
|
-
pushDebugGroup(groupLabel) {
|
|
1697
|
-
}
|
|
1698
|
-
popDebugGroup() {
|
|
1699
|
-
}
|
|
1700
|
-
insertDebugMarker(markerLabel) {
|
|
1701
|
-
}
|
|
1702
|
-
// writeTimestamp(querySet: Query, queryIndex: number): void;
|
|
1703
|
-
// resolveQuerySet(options: {
|
|
1704
|
-
// querySet: GPUQuerySet,
|
|
1705
|
-
// firstQuery: number,
|
|
1706
|
-
// queryCount: number,
|
|
1707
|
-
// destination: Buffer,
|
|
1708
|
-
// destinationOffset?: number;
|
|
1709
|
-
// }): void;
|
|
1710
|
-
};
|
|
1711
|
-
|
|
1712
1906
|
// ../api/src/adapter/resources/render-pass.ts
|
|
1713
|
-
var
|
|
1714
|
-
...DEFAULT_RESOURCE_PROPS,
|
|
1715
|
-
framebuffer: null,
|
|
1716
|
-
parameters: null
|
|
1717
|
-
};
|
|
1718
|
-
var RenderPass = class extends Resource {
|
|
1907
|
+
var _RenderPass = class extends Resource {
|
|
1719
1908
|
get [Symbol.toStringTag]() {
|
|
1720
1909
|
return "RenderPass";
|
|
1721
1910
|
}
|
|
1722
1911
|
constructor(device, props) {
|
|
1723
|
-
super(device, props,
|
|
1912
|
+
super(device, props, _RenderPass.defaultProps);
|
|
1724
1913
|
}
|
|
1914
|
+
/** A small set of parameters can be changed between every draw call (viewport, scissorRect, blendColor, stencilReference) */
|
|
1725
1915
|
// writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;
|
|
1726
1916
|
// beginOcclusionQuery(queryIndex: number): void;
|
|
1727
1917
|
// endOcclusionQuery(): void;
|
|
@@ -1752,6 +1942,63 @@ var __exports__ = (() => {
|
|
|
1752
1942
|
drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void;
|
|
1753
1943
|
*/
|
|
1754
1944
|
};
|
|
1945
|
+
var RenderPass = _RenderPass;
|
|
1946
|
+
/** Default properties for RenderPass */
|
|
1947
|
+
__publicField(RenderPass, "defaultProps", {
|
|
1948
|
+
...Resource.defaultProps,
|
|
1949
|
+
framebuffer: null,
|
|
1950
|
+
parameters: void 0,
|
|
1951
|
+
clearColor: [0, 0, 0, 0],
|
|
1952
|
+
clearDepth: 1,
|
|
1953
|
+
clearStencil: 0,
|
|
1954
|
+
depthReadOnly: false,
|
|
1955
|
+
stencilReadOnly: false,
|
|
1956
|
+
discard: false
|
|
1957
|
+
});
|
|
1958
|
+
|
|
1959
|
+
// ../api/src/adapter/resources/command-encoder.ts
|
|
1960
|
+
var DEFAULT_COMMAND_ENCODER_PROPS = {
|
|
1961
|
+
...DEFAULT_RESOURCE_PROPS
|
|
1962
|
+
};
|
|
1963
|
+
var CommandEncoder = class extends Resource {
|
|
1964
|
+
get [Symbol.toStringTag]() {
|
|
1965
|
+
return "CommandEncoder";
|
|
1966
|
+
}
|
|
1967
|
+
constructor(props) {
|
|
1968
|
+
super(props, DEFAULT_COMMAND_ENCODER_PROPS);
|
|
1969
|
+
}
|
|
1970
|
+
// TODO - return the CommandBuffer?
|
|
1971
|
+
// beginRenderPass(GPURenderPassDescriptor descriptor): GPURenderPassEncoder;
|
|
1972
|
+
// beginComputePass(optional GPUComputePassDescriptor descriptor = {}): GPUComputePassEncoder;
|
|
1973
|
+
// finish(options?: {id?: string}): GPUCommandBuffer;
|
|
1974
|
+
pushDebugGroup(groupLabel) {
|
|
1975
|
+
}
|
|
1976
|
+
popDebugGroup() {
|
|
1977
|
+
}
|
|
1978
|
+
insertDebugMarker(markerLabel) {
|
|
1979
|
+
}
|
|
1980
|
+
// writeTimestamp(querySet: Query, queryIndex: number): void;
|
|
1981
|
+
// resolveQuerySet(options: {
|
|
1982
|
+
// querySet: GPUQuerySet,
|
|
1983
|
+
// firstQuery: number,
|
|
1984
|
+
// queryCount: number,
|
|
1985
|
+
// destination: Buffer,
|
|
1986
|
+
// destinationOffset?: number;
|
|
1987
|
+
// }): void;
|
|
1988
|
+
};
|
|
1989
|
+
|
|
1990
|
+
// ../api/src/adapter/resources/command-buffer.ts
|
|
1991
|
+
var DEFAULT_COMMAND_ENCODER_PROPS2 = {
|
|
1992
|
+
...DEFAULT_RESOURCE_PROPS
|
|
1993
|
+
};
|
|
1994
|
+
var CommandBuffer = class extends Resource {
|
|
1995
|
+
get [Symbol.toStringTag]() {
|
|
1996
|
+
return "CommandBuffer";
|
|
1997
|
+
}
|
|
1998
|
+
constructor(props) {
|
|
1999
|
+
super(props, DEFAULT_COMMAND_ENCODER_PROPS2);
|
|
2000
|
+
}
|
|
2001
|
+
};
|
|
1755
2002
|
|
|
1756
2003
|
// ../api/src/lib/utils/assert.ts
|
|
1757
2004
|
function assert2(condition, message2) {
|
|
@@ -1840,7 +2087,130 @@ var __exports__ = (() => {
|
|
|
1840
2087
|
};
|
|
1841
2088
|
}
|
|
1842
2089
|
}
|
|
1843
|
-
|
|
2090
|
+
return decodeNonStandardFormat(format);
|
|
2091
|
+
}
|
|
2092
|
+
var EXCEPTIONS = {
|
|
2093
|
+
// Packed 16 bit formats
|
|
2094
|
+
"rgba4unorm-webgl": {
|
|
2095
|
+
format: "rgba",
|
|
2096
|
+
bpp: 2
|
|
2097
|
+
},
|
|
2098
|
+
"rgb565unorm-webgl": {
|
|
2099
|
+
format: "rgb",
|
|
2100
|
+
bpp: 2
|
|
2101
|
+
},
|
|
2102
|
+
"rgb5a1unorm-webgl": {
|
|
2103
|
+
format: "rgba",
|
|
2104
|
+
bbp: 2
|
|
2105
|
+
},
|
|
2106
|
+
// Packed 32 bit formats
|
|
2107
|
+
"rgb9e5ufloat": {
|
|
2108
|
+
format: "rgb",
|
|
2109
|
+
bbp: 4
|
|
2110
|
+
},
|
|
2111
|
+
"rg11b10ufloat": {
|
|
2112
|
+
format: "rgb",
|
|
2113
|
+
bbp: 4
|
|
2114
|
+
},
|
|
2115
|
+
"rgb10a2unorm": {
|
|
2116
|
+
format: "rgba",
|
|
2117
|
+
bbp: 4
|
|
2118
|
+
},
|
|
2119
|
+
"rgb10a2unorm-webgl": {
|
|
2120
|
+
format: "rgba",
|
|
2121
|
+
bbp: 4
|
|
2122
|
+
},
|
|
2123
|
+
// Depth/stencil
|
|
2124
|
+
"stencil8": {
|
|
2125
|
+
components: 1,
|
|
2126
|
+
bpp: 1,
|
|
2127
|
+
a: "stencil"
|
|
2128
|
+
},
|
|
2129
|
+
"depth16unorm": {
|
|
2130
|
+
components: 1,
|
|
2131
|
+
bpp: 2,
|
|
2132
|
+
a: "depth"
|
|
2133
|
+
},
|
|
2134
|
+
"depth24plus": {
|
|
2135
|
+
components: 1,
|
|
2136
|
+
bpp: 3,
|
|
2137
|
+
a: "depth"
|
|
2138
|
+
},
|
|
2139
|
+
"depth32float": {
|
|
2140
|
+
components: 1,
|
|
2141
|
+
bpp: 4,
|
|
2142
|
+
a: "depth"
|
|
2143
|
+
},
|
|
2144
|
+
"depth24plus-stencil8": {
|
|
2145
|
+
components: 2,
|
|
2146
|
+
bpp: 4,
|
|
2147
|
+
a: "depth-stencil"
|
|
2148
|
+
},
|
|
2149
|
+
// "depth24unorm-stencil8" feature
|
|
2150
|
+
"depth24unorm-stencil8": {
|
|
2151
|
+
components: 2,
|
|
2152
|
+
bpp: 4,
|
|
2153
|
+
a: "depth-stencil"
|
|
2154
|
+
},
|
|
2155
|
+
// "depth32float-stencil8" feature
|
|
2156
|
+
"depth32float-stencil8": {
|
|
2157
|
+
components: 2,
|
|
2158
|
+
bpp: 4,
|
|
2159
|
+
a: "depth-stencil"
|
|
2160
|
+
}
|
|
2161
|
+
};
|
|
2162
|
+
function decodeNonStandardFormat(format) {
|
|
2163
|
+
const data = EXCEPTIONS[format];
|
|
2164
|
+
if (!data) {
|
|
2165
|
+
throw new Error(`Unknown format ${format}`);
|
|
2166
|
+
}
|
|
2167
|
+
return {
|
|
2168
|
+
format: data.format || "",
|
|
2169
|
+
components: data.components || 1,
|
|
2170
|
+
byteLength: data.bpp || 1,
|
|
2171
|
+
srgb: false,
|
|
2172
|
+
unsized: false
|
|
2173
|
+
};
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
// ../api/src/lib/compiler-log/format-compiler-log.ts
|
|
2177
|
+
function formatCompilerLog(shaderLog, source, options) {
|
|
2178
|
+
const lines = source.split(/\r?\n/);
|
|
2179
|
+
let formattedLog = "";
|
|
2180
|
+
for (const message2 of shaderLog) {
|
|
2181
|
+
formattedLog += formatCompilerMessage(message2, lines, message2.lineNum, options);
|
|
2182
|
+
}
|
|
2183
|
+
return formattedLog;
|
|
2184
|
+
}
|
|
2185
|
+
function formatCompilerMessage(message2, lines, lineNum, options) {
|
|
2186
|
+
if (options?.showSourceCode) {
|
|
2187
|
+
const positionIndicator = message2.linePos > 0 ? `${" ".repeat(message2.linePos + 5)}^^^
|
|
2188
|
+
` : "";
|
|
2189
|
+
const numberedLines = getNumberedLines(lines, lineNum);
|
|
2190
|
+
return `${numberedLines}${positionIndicator}${message2.type.toUpperCase()}: ${message2.message}
|
|
2191
|
+
|
|
2192
|
+
`;
|
|
2193
|
+
}
|
|
2194
|
+
return `${message2.type.toUpperCase()}: ${message2.message}
|
|
2195
|
+
`;
|
|
2196
|
+
}
|
|
2197
|
+
function getNumberedLines(lines, lineNum) {
|
|
2198
|
+
let numberedLines = "";
|
|
2199
|
+
for (let line = lineNum - 2; line <= lineNum; line++) {
|
|
2200
|
+
const sourceLine = lines[line];
|
|
2201
|
+
if (sourceLine !== void 0) {
|
|
2202
|
+
numberedLines += `${padLeft(String(line), 4)}: ${sourceLine}
|
|
2203
|
+
`;
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
return numberedLines;
|
|
2207
|
+
}
|
|
2208
|
+
function padLeft(string, paddedLength) {
|
|
2209
|
+
let result = "";
|
|
2210
|
+
for (let i = string.length; i < paddedLength; ++i) {
|
|
2211
|
+
result += " ";
|
|
2212
|
+
}
|
|
2213
|
+
return result + string;
|
|
1844
2214
|
}
|
|
1845
2215
|
|
|
1846
2216
|
// ../api/src/lib/utils/cast.ts
|
|
@@ -1928,46 +2298,6 @@ var __exports__ = (() => {
|
|
|
1928
2298
|
});
|
|
1929
2299
|
}
|
|
1930
2300
|
|
|
1931
|
-
// ../api/src/lib/compiler-log/format-compiler-log.ts
|
|
1932
|
-
function formatCompilerLog(shaderLog, source, options) {
|
|
1933
|
-
const lines = source.split(/\r?\n/);
|
|
1934
|
-
let formattedLog = "";
|
|
1935
|
-
for (const message2 of shaderLog) {
|
|
1936
|
-
formattedLog += formatCompilerMessage(message2, lines, message2.lineNum, options);
|
|
1937
|
-
}
|
|
1938
|
-
return formattedLog;
|
|
1939
|
-
}
|
|
1940
|
-
function formatCompilerMessage(message2, lines, lineNum, options) {
|
|
1941
|
-
if (options?.showSourceCode) {
|
|
1942
|
-
const positionIndicator = message2.linePos > 0 ? `${" ".repeat(message2.linePos + 5)}^^^
|
|
1943
|
-
` : "";
|
|
1944
|
-
const numberedLines = getNumberedLines(lines, lineNum);
|
|
1945
|
-
return `${numberedLines}${positionIndicator}${message2.type.toUpperCase()}: ${message2.message}
|
|
1946
|
-
|
|
1947
|
-
`;
|
|
1948
|
-
}
|
|
1949
|
-
return `${message2.type.toUpperCase()}: ${message2.message}
|
|
1950
|
-
`;
|
|
1951
|
-
}
|
|
1952
|
-
function getNumberedLines(lines, lineNum) {
|
|
1953
|
-
let numberedLines = "";
|
|
1954
|
-
for (let line = lineNum - 2; line <= lineNum; line++) {
|
|
1955
|
-
const sourceLine = lines[line];
|
|
1956
|
-
if (sourceLine !== void 0) {
|
|
1957
|
-
numberedLines += `${padLeft(String(line), 4)}: ${sourceLine}
|
|
1958
|
-
`;
|
|
1959
|
-
}
|
|
1960
|
-
}
|
|
1961
|
-
return numberedLines;
|
|
1962
|
-
}
|
|
1963
|
-
function padLeft(string, paddedLength) {
|
|
1964
|
-
let result = "";
|
|
1965
|
-
for (let i = string.length; i < paddedLength; ++i) {
|
|
1966
|
-
result += " ";
|
|
1967
|
-
}
|
|
1968
|
-
return result + string;
|
|
1969
|
-
}
|
|
1970
|
-
|
|
1971
2301
|
// src/context/polyfill/polyfill-vertex-array-object.ts
|
|
1972
2302
|
var glErrorShadow = {};
|
|
1973
2303
|
function error(msg) {
|
|
@@ -2403,13 +2733,13 @@ var __exports__ = (() => {
|
|
|
2403
2733
|
GL2[GL2["SHADING_LANGUAGE_VERSION"] = 35724] = "SHADING_LANGUAGE_VERSION";
|
|
2404
2734
|
GL2[GL2["CURRENT_PROGRAM"] = 35725] = "CURRENT_PROGRAM";
|
|
2405
2735
|
GL2[GL2["NEVER"] = 512] = "NEVER";
|
|
2406
|
-
GL2[GL2["ALWAYS"] = 519] = "ALWAYS";
|
|
2407
2736
|
GL2[GL2["LESS"] = 513] = "LESS";
|
|
2408
2737
|
GL2[GL2["EQUAL"] = 514] = "EQUAL";
|
|
2409
2738
|
GL2[GL2["LEQUAL"] = 515] = "LEQUAL";
|
|
2410
2739
|
GL2[GL2["GREATER"] = 516] = "GREATER";
|
|
2411
|
-
GL2[GL2["GEQUAL"] = 518] = "GEQUAL";
|
|
2412
2740
|
GL2[GL2["NOTEQUAL"] = 517] = "NOTEQUAL";
|
|
2741
|
+
GL2[GL2["GEQUAL"] = 518] = "GEQUAL";
|
|
2742
|
+
GL2[GL2["ALWAYS"] = 519] = "ALWAYS";
|
|
2413
2743
|
GL2[GL2["KEEP"] = 7680] = "KEEP";
|
|
2414
2744
|
GL2[GL2["REPLACE"] = 7681] = "REPLACE";
|
|
2415
2745
|
GL2[GL2["INCR"] = 7682] = "INCR";
|
|
@@ -4006,11 +4336,11 @@ var __exports__ = (() => {
|
|
|
4006
4336
|
webgl2: false
|
|
4007
4337
|
};
|
|
4008
4338
|
}
|
|
4009
|
-
if (props.webgl2) {
|
|
4010
|
-
gl =
|
|
4339
|
+
if (!gl && props.webgl2) {
|
|
4340
|
+
gl = canvas.getContext("webgl2", props);
|
|
4011
4341
|
}
|
|
4012
|
-
if (props.webgl1) {
|
|
4013
|
-
gl =
|
|
4342
|
+
if (!gl && props.webgl1) {
|
|
4343
|
+
gl = canvas.getContext("webgl", props);
|
|
4014
4344
|
}
|
|
4015
4345
|
canvas.removeEventListener("webglcontextcreationerror", onCreateError, false);
|
|
4016
4346
|
if (!gl) {
|
|
@@ -4162,7 +4492,8 @@ var __exports__ = (() => {
|
|
|
4162
4492
|
"r8unorm": {
|
|
4163
4493
|
gl: GL.R8,
|
|
4164
4494
|
b: 1,
|
|
4165
|
-
c: 1
|
|
4495
|
+
c: 1,
|
|
4496
|
+
renderbuffer: true
|
|
4166
4497
|
},
|
|
4167
4498
|
"r8snorm": {
|
|
4168
4499
|
gl: GL.R8_SNORM,
|
|
@@ -4172,18 +4503,21 @@ var __exports__ = (() => {
|
|
|
4172
4503
|
"r8uint": {
|
|
4173
4504
|
gl: GL.R8UI,
|
|
4174
4505
|
b: 1,
|
|
4175
|
-
c: 1
|
|
4506
|
+
c: 1,
|
|
4507
|
+
renderbuffer: true
|
|
4176
4508
|
},
|
|
4177
4509
|
"r8sint": {
|
|
4178
4510
|
gl: GL.R8I,
|
|
4179
4511
|
b: 1,
|
|
4180
|
-
c: 1
|
|
4512
|
+
c: 1,
|
|
4513
|
+
renderbuffer: true
|
|
4181
4514
|
},
|
|
4182
4515
|
// 16-bit formats
|
|
4183
4516
|
"rg8unorm": {
|
|
4184
4517
|
gl: GL.RG8,
|
|
4185
4518
|
b: 2,
|
|
4186
|
-
c: 2
|
|
4519
|
+
c: 2,
|
|
4520
|
+
renderbuffer: true
|
|
4187
4521
|
},
|
|
4188
4522
|
"rg8snorm": {
|
|
4189
4523
|
gl: GL.RG8_SNORM,
|
|
@@ -4193,69 +4527,80 @@ var __exports__ = (() => {
|
|
|
4193
4527
|
"rg8uint": {
|
|
4194
4528
|
gl: GL.RG8UI,
|
|
4195
4529
|
b: 2,
|
|
4196
|
-
c: 2
|
|
4530
|
+
c: 2,
|
|
4531
|
+
renderbuffer: true
|
|
4197
4532
|
},
|
|
4198
4533
|
"rg8sint": {
|
|
4199
4534
|
gl: GL.RG8I,
|
|
4200
4535
|
b: 2,
|
|
4201
|
-
c: 2
|
|
4536
|
+
c: 2,
|
|
4537
|
+
renderbuffer: true
|
|
4202
4538
|
},
|
|
4203
4539
|
"r16uint": {
|
|
4204
4540
|
gl: GL.R16UI,
|
|
4205
4541
|
b: 2,
|
|
4206
|
-
c: 1
|
|
4542
|
+
c: 1,
|
|
4543
|
+
renderbuffer: true
|
|
4207
4544
|
},
|
|
4208
4545
|
"r16sint": {
|
|
4209
4546
|
gl: GL.R16I,
|
|
4210
4547
|
b: 2,
|
|
4211
|
-
c: 1
|
|
4548
|
+
c: 1,
|
|
4549
|
+
renderbuffer: true
|
|
4212
4550
|
},
|
|
4213
4551
|
"r16float": {
|
|
4214
4552
|
gl: GL.R16F,
|
|
4215
4553
|
b: 2,
|
|
4216
4554
|
c: 1,
|
|
4217
4555
|
render: "texture-renderable-float16-webgl",
|
|
4218
|
-
filter: "texture-filter-linear-float16-webgl"
|
|
4556
|
+
filter: "texture-filter-linear-float16-webgl",
|
|
4557
|
+
renderbuffer: true
|
|
4219
4558
|
},
|
|
4220
4559
|
"r16unorm-webgl": {
|
|
4221
4560
|
gl: GL.R16_EXT,
|
|
4222
4561
|
b: 2,
|
|
4223
4562
|
c: 1,
|
|
4224
|
-
f: "texture-formats-norm16-webgl"
|
|
4563
|
+
f: "texture-formats-norm16-webgl",
|
|
4564
|
+
renderbuffer: true,
|
|
4565
|
+
x: EXT_TEXTURE_NORM16
|
|
4225
4566
|
},
|
|
4226
4567
|
"r16snorm-webgl": {
|
|
4227
4568
|
gl: GL.R16_SNORM_EXT,
|
|
4228
4569
|
b: 2,
|
|
4229
4570
|
c: 1,
|
|
4230
|
-
f: "texture-formats-norm16-webgl"
|
|
4571
|
+
f: "texture-formats-norm16-webgl",
|
|
4572
|
+
x: EXT_TEXTURE_NORM16
|
|
4231
4573
|
},
|
|
4232
4574
|
// Packed 16-bit formats
|
|
4233
4575
|
"rgba4unorm-webgl": {
|
|
4234
4576
|
gl: GL.RGBA4,
|
|
4235
4577
|
b: 2,
|
|
4236
4578
|
c: 4,
|
|
4237
|
-
wgpu: false
|
|
4579
|
+
wgpu: false,
|
|
4580
|
+
renderbuffer: true
|
|
4238
4581
|
},
|
|
4239
4582
|
"rgb565unorm-webgl": {
|
|
4240
4583
|
gl: GL.RGB565,
|
|
4241
4584
|
b: 2,
|
|
4242
4585
|
c: 4,
|
|
4243
|
-
wgpu: false
|
|
4586
|
+
wgpu: false,
|
|
4587
|
+
renderbuffer: true
|
|
4244
4588
|
},
|
|
4245
4589
|
"rgb5a1unorm-webgl": {
|
|
4246
4590
|
gl: GL.RGB5_A1,
|
|
4247
4591
|
b: 2,
|
|
4248
4592
|
c: 4,
|
|
4249
|
-
wgpu: false
|
|
4593
|
+
wgpu: false,
|
|
4594
|
+
renderbuffer: true
|
|
4250
4595
|
},
|
|
4251
4596
|
// 24-bit formats
|
|
4252
|
-
"
|
|
4597
|
+
"rgb8unorm-webgl": {
|
|
4253
4598
|
gl: GL.RGB8,
|
|
4254
4599
|
b: 3,
|
|
4255
4600
|
c: 3,
|
|
4256
4601
|
wgpu: false
|
|
4257
4602
|
},
|
|
4258
|
-
"
|
|
4603
|
+
"rgb8snorm-webgl": {
|
|
4259
4604
|
gl: GL.RGB8_SNORM,
|
|
4260
4605
|
b: 3,
|
|
4261
4606
|
c: 3,
|
|
@@ -4322,31 +4667,36 @@ var __exports__ = (() => {
|
|
|
4322
4667
|
b: 4,
|
|
4323
4668
|
c: 2,
|
|
4324
4669
|
render: "texture-renderable-float16-webgl",
|
|
4325
|
-
filter: "texture-filter-linear-float16-webgl"
|
|
4670
|
+
filter: "texture-filter-linear-float16-webgl",
|
|
4671
|
+
renderbuffer: true
|
|
4326
4672
|
},
|
|
4327
4673
|
"rg16unorm-webgl": {
|
|
4328
4674
|
gl: GL.RG16_EXT,
|
|
4329
4675
|
b: 2,
|
|
4330
4676
|
c: 2,
|
|
4331
|
-
f: "texture-formats-norm16-webgl"
|
|
4677
|
+
f: "texture-formats-norm16-webgl",
|
|
4678
|
+
x: EXT_TEXTURE_NORM16
|
|
4332
4679
|
},
|
|
4333
4680
|
"rg16snorm-webgl": {
|
|
4334
4681
|
gl: GL.RG16_SNORM_EXT,
|
|
4335
4682
|
b: 2,
|
|
4336
4683
|
c: 2,
|
|
4337
|
-
f: "texture-formats-norm16-webgl"
|
|
4684
|
+
f: "texture-formats-norm16-webgl",
|
|
4685
|
+
x: EXT_TEXTURE_NORM16
|
|
4338
4686
|
},
|
|
4339
4687
|
"r32uint": {
|
|
4340
4688
|
gl: GL.R32UI,
|
|
4341
4689
|
b: 4,
|
|
4342
4690
|
c: 1,
|
|
4343
|
-
bpp: 4
|
|
4691
|
+
bpp: 4,
|
|
4692
|
+
renderbuffer: true
|
|
4344
4693
|
},
|
|
4345
4694
|
"r32sint": {
|
|
4346
4695
|
gl: GL.R32I,
|
|
4347
4696
|
b: 4,
|
|
4348
4697
|
c: 1,
|
|
4349
|
-
bpp: 4
|
|
4698
|
+
bpp: 4,
|
|
4699
|
+
renderbuffer: true
|
|
4350
4700
|
},
|
|
4351
4701
|
"r32float": {
|
|
4352
4702
|
gl: GL.R32F,
|
|
@@ -4370,13 +4720,15 @@ var __exports__ = (() => {
|
|
|
4370
4720
|
b: 4,
|
|
4371
4721
|
c: 3,
|
|
4372
4722
|
p: 1,
|
|
4373
|
-
render: "texture-renderable-float32-webgl"
|
|
4723
|
+
render: "texture-renderable-float32-webgl",
|
|
4724
|
+
renderbuffer: true
|
|
4374
4725
|
},
|
|
4375
4726
|
"rgb10a2unorm": {
|
|
4376
4727
|
gl: GL.RGB10_A2,
|
|
4377
4728
|
b: 4,
|
|
4378
4729
|
c: 4,
|
|
4379
|
-
p: 1
|
|
4730
|
+
p: 1,
|
|
4731
|
+
renderbuffer: true
|
|
4380
4732
|
},
|
|
4381
4733
|
// webgl2 only
|
|
4382
4734
|
"rgb10a2unorm-webgl": {
|
|
@@ -4385,48 +4737,56 @@ var __exports__ = (() => {
|
|
|
4385
4737
|
gl: GL.RGB10_A2UI,
|
|
4386
4738
|
p: 1,
|
|
4387
4739
|
wgpu: false,
|
|
4388
|
-
bpp: 4
|
|
4740
|
+
bpp: 4,
|
|
4741
|
+
renderbuffer: true
|
|
4389
4742
|
},
|
|
4390
4743
|
// 48-bit formats
|
|
4391
4744
|
"rgb16unorm-webgl": {
|
|
4392
4745
|
gl: GL.RGB16_EXT,
|
|
4393
4746
|
b: 2,
|
|
4394
4747
|
c: 3,
|
|
4395
|
-
f: "texture-formats-norm16-webgl"
|
|
4748
|
+
f: "texture-formats-norm16-webgl",
|
|
4749
|
+
x: EXT_TEXTURE_NORM16
|
|
4396
4750
|
},
|
|
4397
4751
|
"rgb16snorm-webgl": {
|
|
4398
4752
|
gl: GL.RGB16_SNORM_EXT,
|
|
4399
4753
|
b: 2,
|
|
4400
4754
|
c: 3,
|
|
4401
|
-
f: "texture-formats-norm16-webgl"
|
|
4755
|
+
f: "texture-formats-norm16-webgl",
|
|
4756
|
+
x: EXT_TEXTURE_NORM16
|
|
4402
4757
|
},
|
|
4403
4758
|
// 64-bit formats
|
|
4404
4759
|
"rg32uint": {
|
|
4405
4760
|
gl: GL.RG32UI,
|
|
4406
4761
|
b: 8,
|
|
4407
|
-
c: 2
|
|
4762
|
+
c: 2,
|
|
4763
|
+
renderbuffer: true
|
|
4408
4764
|
},
|
|
4409
4765
|
"rg32sint": {
|
|
4410
4766
|
gl: GL.RG32I,
|
|
4411
4767
|
b: 8,
|
|
4412
|
-
c: 2
|
|
4768
|
+
c: 2,
|
|
4769
|
+
renderbuffer: true
|
|
4413
4770
|
},
|
|
4414
4771
|
"rg32float": {
|
|
4415
4772
|
gl: GL.RG32F,
|
|
4416
4773
|
b: 8,
|
|
4417
4774
|
c: 2,
|
|
4418
4775
|
render: "texture-renderable-float32-webgl",
|
|
4419
|
-
filter: "texture-filter-linear-float32-webgl"
|
|
4776
|
+
filter: "texture-filter-linear-float32-webgl",
|
|
4777
|
+
renderbuffer: true
|
|
4420
4778
|
},
|
|
4421
4779
|
"rgba16uint": {
|
|
4422
4780
|
gl: GL.RGBA16UI,
|
|
4423
4781
|
b: 8,
|
|
4424
|
-
c: 4
|
|
4782
|
+
c: 4,
|
|
4783
|
+
renderbuffer: true
|
|
4425
4784
|
},
|
|
4426
4785
|
"rgba16sint": {
|
|
4427
4786
|
gl: GL.RGBA16I,
|
|
4428
4787
|
b: 8,
|
|
4429
|
-
c: 4
|
|
4788
|
+
c: 4,
|
|
4789
|
+
renderbuffer: true
|
|
4430
4790
|
},
|
|
4431
4791
|
"rgba16float": {
|
|
4432
4792
|
gl: GL.RGBA16F,
|
|
@@ -4440,13 +4800,16 @@ var __exports__ = (() => {
|
|
|
4440
4800
|
gl: GL.RGBA16_EXT,
|
|
4441
4801
|
b: 2,
|
|
4442
4802
|
c: 4,
|
|
4443
|
-
f: "texture-formats-norm16-webgl"
|
|
4803
|
+
f: "texture-formats-norm16-webgl",
|
|
4804
|
+
renderbuffer: true,
|
|
4805
|
+
x: EXT_TEXTURE_NORM16
|
|
4444
4806
|
},
|
|
4445
4807
|
"rgba16snorm-webgl": {
|
|
4446
4808
|
gl: GL.RGBA16_SNORM_EXT,
|
|
4447
4809
|
b: 2,
|
|
4448
4810
|
c: 4,
|
|
4449
|
-
f: "texture-formats-norm16-webgl"
|
|
4811
|
+
f: "texture-formats-norm16-webgl",
|
|
4812
|
+
x: EXT_TEXTURE_NORM16
|
|
4450
4813
|
},
|
|
4451
4814
|
// 96-bit formats (deprecated!)
|
|
4452
4815
|
"rgb32float-webgl": {
|
|
@@ -4464,27 +4827,31 @@ var __exports__ = (() => {
|
|
|
4464
4827
|
"rgba32uint": {
|
|
4465
4828
|
gl: GL.RGBA32UI,
|
|
4466
4829
|
b: 16,
|
|
4467
|
-
c: 4
|
|
4830
|
+
c: 4,
|
|
4831
|
+
renderbuffer: true
|
|
4468
4832
|
},
|
|
4469
4833
|
"rgba32sint": {
|
|
4470
4834
|
gl: GL.RGBA32I,
|
|
4471
4835
|
b: 16,
|
|
4472
|
-
c: 4
|
|
4836
|
+
c: 4,
|
|
4837
|
+
renderbuffer: true
|
|
4473
4838
|
},
|
|
4474
4839
|
"rgba32float": {
|
|
4475
4840
|
gl: GL.RGBA32F,
|
|
4476
|
-
gl1: GL.RGBA,
|
|
4477
4841
|
b: 16,
|
|
4478
4842
|
c: 4,
|
|
4479
4843
|
render: "texture-renderable-float32-webgl",
|
|
4480
|
-
filter: "texture-filter-linear-float32-webgl"
|
|
4844
|
+
filter: "texture-filter-linear-float32-webgl",
|
|
4845
|
+
renderbuffer: true
|
|
4481
4846
|
},
|
|
4482
4847
|
// Depth and stencil formats
|
|
4483
4848
|
"stencil8": {
|
|
4484
4849
|
gl: GL.STENCIL_INDEX8,
|
|
4850
|
+
gl1: GL.STENCIL_INDEX8,
|
|
4485
4851
|
b: 1,
|
|
4486
4852
|
c: 1,
|
|
4487
|
-
attachment: GL.STENCIL_ATTACHMENT
|
|
4853
|
+
attachment: GL.STENCIL_ATTACHMENT,
|
|
4854
|
+
renderbuffer: true
|
|
4488
4855
|
},
|
|
4489
4856
|
// 8 stencil bits
|
|
4490
4857
|
"depth16unorm": {
|
|
@@ -4492,7 +4859,8 @@ var __exports__ = (() => {
|
|
|
4492
4859
|
gl1: GL.DEPTH_COMPONENT16,
|
|
4493
4860
|
b: 2,
|
|
4494
4861
|
c: 1,
|
|
4495
|
-
attachment: GL.DEPTH_ATTACHMENT
|
|
4862
|
+
attachment: GL.DEPTH_ATTACHMENT,
|
|
4863
|
+
renderbuffer: true
|
|
4496
4864
|
},
|
|
4497
4865
|
// 16 depth bits
|
|
4498
4866
|
"depth24plus": {
|
|
@@ -4505,15 +4873,19 @@ var __exports__ = (() => {
|
|
|
4505
4873
|
gl: GL.DEPTH_COMPONENT32F,
|
|
4506
4874
|
b: 4,
|
|
4507
4875
|
c: 1,
|
|
4508
|
-
attachment: GL.DEPTH_ATTACHMENT
|
|
4876
|
+
attachment: GL.DEPTH_ATTACHMENT,
|
|
4877
|
+
renderbuffer: true
|
|
4509
4878
|
},
|
|
4879
|
+
// The depth component of the "depth24plus" and "depth24plus-stencil8" formats may be implemented as either a 24-bit depth value or a "depth32float" value.
|
|
4510
4880
|
"depth24plus-stencil8": {
|
|
4511
|
-
|
|
4512
|
-
gl: GL.UNSIGNED_INT_24_8,
|
|
4881
|
+
gl: GL.DEPTH_STENCIL,
|
|
4513
4882
|
gl1: GL.DEPTH_STENCIL,
|
|
4883
|
+
b: 4,
|
|
4514
4884
|
c: 2,
|
|
4515
4885
|
p: 1,
|
|
4516
|
-
attachment: GL.DEPTH_STENCIL_ATTACHMENT
|
|
4886
|
+
attachment: GL.DEPTH_STENCIL_ATTACHMENT,
|
|
4887
|
+
renderbuffer: true,
|
|
4888
|
+
depthTexture: true
|
|
4517
4889
|
},
|
|
4518
4890
|
// "depth24unorm-stencil8" feature
|
|
4519
4891
|
"depth24unorm-stencil8": {
|
|
@@ -4521,7 +4893,8 @@ var __exports__ = (() => {
|
|
|
4521
4893
|
b: 4,
|
|
4522
4894
|
c: 2,
|
|
4523
4895
|
p: 1,
|
|
4524
|
-
attachment: GL.DEPTH_STENCIL_ATTACHMENT
|
|
4896
|
+
attachment: GL.DEPTH_STENCIL_ATTACHMENT,
|
|
4897
|
+
renderbuffer: true
|
|
4525
4898
|
},
|
|
4526
4899
|
// "depth32float-stencil8" feature
|
|
4527
4900
|
"depth32float-stencil8": {
|
|
@@ -4529,7 +4902,8 @@ var __exports__ = (() => {
|
|
|
4529
4902
|
b: 5,
|
|
4530
4903
|
c: 2,
|
|
4531
4904
|
p: 1,
|
|
4532
|
-
attachment: GL.DEPTH_STENCIL_ATTACHMENT
|
|
4905
|
+
attachment: GL.DEPTH_STENCIL_ATTACHMENT,
|
|
4906
|
+
renderbuffer: true
|
|
4533
4907
|
},
|
|
4534
4908
|
// BC compressed formats: check device.features.has("texture-compression-bc");
|
|
4535
4909
|
"bc1-rgb-unorm-webgl": {
|
|
@@ -4803,18 +5177,33 @@ var __exports__ = (() => {
|
|
|
4803
5177
|
f: texture_compression_atc_webgl
|
|
4804
5178
|
}
|
|
4805
5179
|
};
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
5180
|
+
var DATA_FORMAT_CHANNELS = {
|
|
5181
|
+
[GL.RED]: 1,
|
|
5182
|
+
[GL.RED_INTEGER]: 1,
|
|
5183
|
+
[GL.RG]: 2,
|
|
5184
|
+
[GL.RG_INTEGER]: 2,
|
|
5185
|
+
[GL.RGB]: 3,
|
|
5186
|
+
[GL.RGB_INTEGER]: 3,
|
|
5187
|
+
[GL.RGBA]: 4,
|
|
5188
|
+
[GL.RGBA_INTEGER]: 4,
|
|
5189
|
+
[GL.DEPTH_COMPONENT]: 1,
|
|
5190
|
+
[GL.DEPTH_STENCIL]: 1,
|
|
5191
|
+
[GL.ALPHA]: 1,
|
|
5192
|
+
[GL.LUMINANCE]: 1,
|
|
5193
|
+
[GL.LUMINANCE_ALPHA]: 2
|
|
5194
|
+
};
|
|
5195
|
+
var TYPE_SIZES2 = {
|
|
5196
|
+
[GL.FLOAT]: 4,
|
|
5197
|
+
[GL.UNSIGNED_INT]: 4,
|
|
5198
|
+
[GL.INT]: 4,
|
|
5199
|
+
[GL.UNSIGNED_SHORT]: 2,
|
|
5200
|
+
[GL.SHORT]: 2,
|
|
5201
|
+
[GL.HALF_FLOAT]: 2,
|
|
5202
|
+
[GL.BYTE]: 1,
|
|
5203
|
+
[GL.UNSIGNED_BYTE]: 1
|
|
5204
|
+
};
|
|
4816
5205
|
function isTextureFormatSupported(gl, formatOrGL) {
|
|
4817
|
-
const format =
|
|
5206
|
+
const format = convertGLToTextureFormat(formatOrGL);
|
|
4818
5207
|
const info = TEXTURE_FORMATS[format];
|
|
4819
5208
|
if (!info) {
|
|
4820
5209
|
return false;
|
|
@@ -4828,8 +5217,29 @@ var __exports__ = (() => {
|
|
|
4828
5217
|
}
|
|
4829
5218
|
return true;
|
|
4830
5219
|
}
|
|
5220
|
+
function isRenderbufferFormatSupported(gl, format) {
|
|
5221
|
+
return isTextureFormatSupported(gl, format) && TEXTURE_FORMATS[format]?.renderbuffer;
|
|
5222
|
+
}
|
|
5223
|
+
function convertGLToTextureFormat(format) {
|
|
5224
|
+
if (typeof format === "string") {
|
|
5225
|
+
return format;
|
|
5226
|
+
}
|
|
5227
|
+
const entry = Object.entries(TEXTURE_FORMATS).find(([, entry2]) => entry2.gl === format || entry2.gl1 === format);
|
|
5228
|
+
if (!entry) {
|
|
5229
|
+
throw new Error(`Unknown texture format ${format}`);
|
|
5230
|
+
}
|
|
5231
|
+
return entry[0];
|
|
5232
|
+
}
|
|
5233
|
+
function convertTextureFormatToGL(format, isWebGL23) {
|
|
5234
|
+
const formatInfo = TEXTURE_FORMATS[format];
|
|
5235
|
+
const webglFormat = isWebGL23 ? formatInfo?.gl : formatInfo?.gl1;
|
|
5236
|
+
if (webglFormat === void 0) {
|
|
5237
|
+
throw new Error(`Unsupported texture format ${format}`);
|
|
5238
|
+
}
|
|
5239
|
+
return webglFormat;
|
|
5240
|
+
}
|
|
4831
5241
|
function isTextureFormatFilterable(gl, formatOrGL) {
|
|
4832
|
-
const format =
|
|
5242
|
+
const format = convertGLToTextureFormat(formatOrGL);
|
|
4833
5243
|
if (!isTextureFormatSupported(gl, format)) {
|
|
4834
5244
|
return false;
|
|
4835
5245
|
}
|
|
@@ -4850,7 +5260,7 @@ var __exports__ = (() => {
|
|
|
4850
5260
|
return true;
|
|
4851
5261
|
}
|
|
4852
5262
|
function isTextureFormatRenderable(gl, formatOrGL) {
|
|
4853
|
-
const format =
|
|
5263
|
+
const format = convertGLToTextureFormat(formatOrGL);
|
|
4854
5264
|
if (!isTextureFormatSupported(gl, format)) {
|
|
4855
5265
|
return false;
|
|
4856
5266
|
}
|
|
@@ -4859,21 +5269,9 @@ var __exports__ = (() => {
|
|
|
4859
5269
|
}
|
|
4860
5270
|
return true;
|
|
4861
5271
|
}
|
|
4862
|
-
function
|
|
4863
|
-
const format =
|
|
4864
|
-
const
|
|
4865
|
-
const webglFormat = isWebGL2(gl) ? formatInfo?.gl : formatInfo?.gl1;
|
|
4866
|
-
if (typeof format === "number") {
|
|
4867
|
-
return webglFormat || format;
|
|
4868
|
-
}
|
|
4869
|
-
if (webglFormat === void 0) {
|
|
4870
|
-
throw new Error(`Unsupported texture format ${format}`);
|
|
4871
|
-
}
|
|
4872
|
-
return webglFormat;
|
|
4873
|
-
}
|
|
4874
|
-
function getWebGLTextureParameters(gl, formatOrGL) {
|
|
4875
|
-
const format = getTextureFormat(formatOrGL);
|
|
4876
|
-
const webglFormat = getWebGLTextureFormat(gl, format);
|
|
5272
|
+
function getWebGLTextureParameters(formatOrGL, isWebGL23) {
|
|
5273
|
+
const format = convertGLToTextureFormat(formatOrGL);
|
|
5274
|
+
const webglFormat = convertTextureFormatToGL(format, isWebGL23);
|
|
4877
5275
|
const decoded = decodeTextureFormat(format);
|
|
4878
5276
|
return {
|
|
4879
5277
|
format: webglFormat,
|
|
@@ -4883,17 +5281,12 @@ var __exports__ = (() => {
|
|
|
4883
5281
|
compressed: decoded.compressed
|
|
4884
5282
|
};
|
|
4885
5283
|
}
|
|
4886
|
-
function
|
|
4887
|
-
const format = getTextureFormat(formatOrGL);
|
|
4888
|
-
if (typeof format === "number") {
|
|
4889
|
-
throw new Error("unsupported depth stencil format");
|
|
4890
|
-
}
|
|
5284
|
+
function getDepthStencilAttachmentWebGL(format) {
|
|
4891
5285
|
const info = TEXTURE_FORMATS[format];
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
throw new Error("not a depth stencil format");
|
|
5286
|
+
if (!info?.attachment) {
|
|
5287
|
+
throw new Error(`${format} is not a depth stencil format`);
|
|
4895
5288
|
}
|
|
4896
|
-
return attachment;
|
|
5289
|
+
return info.attachment;
|
|
4897
5290
|
}
|
|
4898
5291
|
function _checkFloat32ColorAttachment(gl, internalFormat = gl.RGBA, srcFormat = GL.RGBA, srcType = GL.UNSIGNED_BYTE) {
|
|
4899
5292
|
let texture = null;
|
|
@@ -4918,34 +5311,9 @@ var __exports__ = (() => {
|
|
|
4918
5311
|
gl.deleteFramebuffer(framebuffer);
|
|
4919
5312
|
}
|
|
4920
5313
|
}
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
[GL.RG]: 2,
|
|
4925
|
-
[GL.RG_INTEGER]: 2,
|
|
4926
|
-
[GL.RGB]: 3,
|
|
4927
|
-
[GL.RGB_INTEGER]: 3,
|
|
4928
|
-
[GL.RGBA]: 4,
|
|
4929
|
-
[GL.RGBA_INTEGER]: 4,
|
|
4930
|
-
[GL.DEPTH_COMPONENT]: 1,
|
|
4931
|
-
[GL.DEPTH_STENCIL]: 1,
|
|
4932
|
-
[GL.ALPHA]: 1,
|
|
4933
|
-
[GL.LUMINANCE]: 1,
|
|
4934
|
-
[GL.LUMINANCE_ALPHA]: 2
|
|
4935
|
-
};
|
|
4936
|
-
var TYPE_SIZES2 = {
|
|
4937
|
-
[GL.FLOAT]: 4,
|
|
4938
|
-
[GL.UNSIGNED_INT]: 4,
|
|
4939
|
-
[GL.INT]: 4,
|
|
4940
|
-
[GL.UNSIGNED_SHORT]: 2,
|
|
4941
|
-
[GL.SHORT]: 2,
|
|
4942
|
-
[GL.HALF_FLOAT]: 2,
|
|
4943
|
-
[GL.BYTE]: 1,
|
|
4944
|
-
[GL.UNSIGNED_BYTE]: 1
|
|
4945
|
-
};
|
|
4946
|
-
function getTextureFormatBytesPerPixel(gl, formatOrGL) {
|
|
4947
|
-
const format = getTextureFormat(formatOrGL);
|
|
4948
|
-
const params = getWebGLTextureParameters(gl, format);
|
|
5314
|
+
function getTextureFormatBytesPerPixel(formatOrGL, isWebGL23) {
|
|
5315
|
+
const format = convertGLToTextureFormat(formatOrGL);
|
|
5316
|
+
const params = getWebGLTextureParameters(format, isWebGL23);
|
|
4949
5317
|
const channels = DATA_FORMAT_CHANNELS[params.dataFormat] || 4;
|
|
4950
5318
|
const channelSize = TYPE_SIZES2[params.type] || 1;
|
|
4951
5319
|
return channels * channelSize;
|
|
@@ -5350,22 +5718,22 @@ void main(void) {}`;
|
|
|
5350
5718
|
}
|
|
5351
5719
|
function convertCompareFunction(parameter, value) {
|
|
5352
5720
|
return map(parameter, value, {
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5721
|
+
never: GL.NEVER,
|
|
5722
|
+
less: GL.LESS,
|
|
5723
|
+
equal: GL.EQUAL,
|
|
5356
5724
|
"less-equal": GL.LEQUAL,
|
|
5357
|
-
|
|
5725
|
+
greater: GL.GREATER,
|
|
5358
5726
|
"not-equal": GL.NOTEQUAL,
|
|
5359
5727
|
"greater-equal": GL.GEQUAL,
|
|
5360
|
-
|
|
5728
|
+
always: GL.ALWAYS
|
|
5361
5729
|
});
|
|
5362
5730
|
}
|
|
5363
5731
|
function convertStencilOperation(parameter, value) {
|
|
5364
5732
|
return map(parameter, value, {
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5733
|
+
keep: GL.KEEP,
|
|
5734
|
+
zero: GL.ZERO,
|
|
5735
|
+
replace: GL.REPLACE,
|
|
5736
|
+
invert: GL.INVERT,
|
|
5369
5737
|
"increment-clamp": GL.INCR,
|
|
5370
5738
|
"decrement-clamp": GL.DECR,
|
|
5371
5739
|
"increment-wrap": GL.INCR_WRAP,
|
|
@@ -5523,16 +5891,17 @@ void main(void) {}`;
|
|
|
5523
5891
|
this.trackDeallocatedMemory();
|
|
5524
5892
|
this.gl.deleteBuffer(this.handle);
|
|
5525
5893
|
this.destroyed = true;
|
|
5894
|
+
this.handle = null;
|
|
5526
5895
|
}
|
|
5527
5896
|
}
|
|
5528
5897
|
write(data, byteOffset = 0) {
|
|
5529
5898
|
const srcOffset = 0;
|
|
5530
|
-
const byteLength =
|
|
5899
|
+
const byteLength = void 0;
|
|
5531
5900
|
const target = this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.target;
|
|
5532
5901
|
this.gl.bindBuffer(target, this.handle);
|
|
5533
5902
|
if (srcOffset !== 0 || byteLength !== void 0) {
|
|
5534
5903
|
this.device.assertWebGL2();
|
|
5535
|
-
this.
|
|
5904
|
+
this.gl2.bufferSubData(target, byteOffset, data, srcOffset, byteLength);
|
|
5536
5905
|
} else {
|
|
5537
5906
|
this.gl.bufferSubData(target, byteOffset, data);
|
|
5538
5907
|
}
|
|
@@ -5622,11 +5991,21 @@ void main(void) {}`;
|
|
|
5622
5991
|
};
|
|
5623
5992
|
|
|
5624
5993
|
// src/adapter/resources/webgl-texture.ts
|
|
5994
|
+
var DEFAULT_WEBGL_TEXTURE_PROPS = {
|
|
5995
|
+
// deprecated
|
|
5996
|
+
parameters: {},
|
|
5997
|
+
pixelStore: {},
|
|
5998
|
+
pixels: null,
|
|
5999
|
+
border: 0,
|
|
6000
|
+
dataFormat: void 0,
|
|
6001
|
+
textureUnit: void 0,
|
|
6002
|
+
target: void 0
|
|
6003
|
+
};
|
|
5625
6004
|
var _WEBGLTexture = class extends Texture {
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
6005
|
+
/** Sampler object (currently unused) */
|
|
6006
|
+
sampler = void 0;
|
|
6007
|
+
// data;
|
|
6008
|
+
glFormat = void 0;
|
|
5630
6009
|
type = void 0;
|
|
5631
6010
|
dataFormat = void 0;
|
|
5632
6011
|
mipmaps = void 0;
|
|
@@ -5640,8 +6019,6 @@ void main(void) {}`;
|
|
|
5640
6019
|
* attempting to bind it as GL_TEXTURE_3D will give rise to a run-time error
|
|
5641
6020
|
* */
|
|
5642
6021
|
textureUnit = void 0;
|
|
5643
|
-
/** Sampler object (currently unused) */
|
|
5644
|
-
sampler = void 0;
|
|
5645
6022
|
/**
|
|
5646
6023
|
* Program.draw() checks the loaded flag of all textures to avoid
|
|
5647
6024
|
* Textures that are still loading from promises
|
|
@@ -5650,7 +6027,8 @@ void main(void) {}`;
|
|
|
5650
6027
|
loaded = false;
|
|
5651
6028
|
constructor(device, props) {
|
|
5652
6029
|
super(device, {
|
|
5653
|
-
|
|
6030
|
+
...DEFAULT_WEBGL_TEXTURE_PROPS,
|
|
6031
|
+
format: "rgba8unorm",
|
|
5654
6032
|
...props
|
|
5655
6033
|
});
|
|
5656
6034
|
this.device = cast(device);
|
|
@@ -5661,6 +6039,7 @@ void main(void) {}`;
|
|
|
5661
6039
|
...this.props,
|
|
5662
6040
|
data: typeof this.props.data
|
|
5663
6041
|
});
|
|
6042
|
+
this.glFormat = GL.RGBA;
|
|
5664
6043
|
this.target = getWebGLTextureTarget(this.props);
|
|
5665
6044
|
this.loaded = false;
|
|
5666
6045
|
if (typeof this.props?.data === "string") {
|
|
@@ -5706,7 +6085,6 @@ void main(void) {}`;
|
|
|
5706
6085
|
} = props;
|
|
5707
6086
|
const {
|
|
5708
6087
|
pixels = null,
|
|
5709
|
-
recreate = false,
|
|
5710
6088
|
pixelStore = {},
|
|
5711
6089
|
textureUnit = void 0
|
|
5712
6090
|
} = props;
|
|
@@ -5724,6 +6102,7 @@ void main(void) {}`;
|
|
|
5724
6102
|
const {
|
|
5725
6103
|
depth = 0
|
|
5726
6104
|
} = props;
|
|
6105
|
+
const glFormat = convertTextureFormatToGL(props.format, this.device.isWebGL2);
|
|
5727
6106
|
({
|
|
5728
6107
|
width,
|
|
5729
6108
|
height,
|
|
@@ -5739,11 +6118,9 @@ void main(void) {}`;
|
|
|
5739
6118
|
width,
|
|
5740
6119
|
height
|
|
5741
6120
|
}));
|
|
5742
|
-
const format = getWebGLTextureFormat(this.gl, props.format);
|
|
5743
6121
|
this.width = width;
|
|
5744
6122
|
this.height = height;
|
|
5745
|
-
this.
|
|
5746
|
-
this.format = format;
|
|
6123
|
+
this.glFormat = glFormat;
|
|
5747
6124
|
this.type = type;
|
|
5748
6125
|
this.dataFormat = dataFormat;
|
|
5749
6126
|
this.textureUnit = textureUnit;
|
|
@@ -5761,7 +6138,7 @@ void main(void) {}`;
|
|
|
5761
6138
|
width,
|
|
5762
6139
|
height,
|
|
5763
6140
|
depth,
|
|
5764
|
-
format,
|
|
6141
|
+
format: glFormat,
|
|
5765
6142
|
type,
|
|
5766
6143
|
dataFormat,
|
|
5767
6144
|
// @ts-expect-error
|
|
@@ -5773,9 +6150,6 @@ void main(void) {}`;
|
|
|
5773
6150
|
if (mipmaps) {
|
|
5774
6151
|
this.generateMipmap();
|
|
5775
6152
|
}
|
|
5776
|
-
if (recreate) {
|
|
5777
|
-
this.data = data;
|
|
5778
|
-
}
|
|
5779
6153
|
if (isVideo) {
|
|
5780
6154
|
this._video = {
|
|
5781
6155
|
video: data,
|
|
@@ -5893,7 +6267,7 @@ void main(void) {}`;
|
|
|
5893
6267
|
*/
|
|
5894
6268
|
// eslint-disable-next-line max-statements, complexity
|
|
5895
6269
|
setImageData(options) {
|
|
5896
|
-
if (this.props.dimension === "3d") {
|
|
6270
|
+
if (this.props.dimension === "3d" || this.props.dimension === "2d-array") {
|
|
5897
6271
|
return this.setImageData3D(options);
|
|
5898
6272
|
}
|
|
5899
6273
|
this.trackDeallocatedMemory("Texture");
|
|
@@ -5901,7 +6275,7 @@ void main(void) {}`;
|
|
|
5901
6275
|
target = this.target,
|
|
5902
6276
|
pixels = null,
|
|
5903
6277
|
level = 0,
|
|
5904
|
-
|
|
6278
|
+
glFormat = this.glFormat,
|
|
5905
6279
|
offset = 0,
|
|
5906
6280
|
parameters = {}
|
|
5907
6281
|
} = options;
|
|
@@ -5947,13 +6321,13 @@ void main(void) {}`;
|
|
|
5947
6321
|
withParameters(this.gl, parameters, () => {
|
|
5948
6322
|
switch (dataType) {
|
|
5949
6323
|
case "null":
|
|
5950
|
-
gl.texImage2D(target, level,
|
|
6324
|
+
gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
|
|
5951
6325
|
break;
|
|
5952
6326
|
case "typed-array":
|
|
5953
6327
|
gl.texImage2D(
|
|
5954
6328
|
target,
|
|
5955
6329
|
level,
|
|
5956
|
-
|
|
6330
|
+
glFormat,
|
|
5957
6331
|
width,
|
|
5958
6332
|
height,
|
|
5959
6333
|
0,
|
|
@@ -5968,14 +6342,14 @@ void main(void) {}`;
|
|
|
5968
6342
|
case "buffer":
|
|
5969
6343
|
gl2 = this.device.assertWebGL2();
|
|
5970
6344
|
gl2.bindBuffer(GL.PIXEL_UNPACK_BUFFER, data.handle || data);
|
|
5971
|
-
gl2.texImage2D(target, level,
|
|
6345
|
+
gl2.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, offset);
|
|
5972
6346
|
gl2.bindBuffer(GL.PIXEL_UNPACK_BUFFER, null);
|
|
5973
6347
|
break;
|
|
5974
6348
|
case "browser-object":
|
|
5975
6349
|
if (this.device.isWebGL2) {
|
|
5976
|
-
gl.texImage2D(target, level,
|
|
6350
|
+
gl.texImage2D(target, level, glFormat, width, height, 0, dataFormat, type, data);
|
|
5977
6351
|
} else {
|
|
5978
|
-
gl.texImage2D(target, level,
|
|
6352
|
+
gl.texImage2D(target, level, glFormat, dataFormat, type, data);
|
|
5979
6353
|
}
|
|
5980
6354
|
break;
|
|
5981
6355
|
case "compressed":
|
|
@@ -5990,7 +6364,7 @@ void main(void) {}`;
|
|
|
5990
6364
|
if (data && data.byteLength) {
|
|
5991
6365
|
this.trackAllocatedMemory(data.byteLength, "Texture");
|
|
5992
6366
|
} else {
|
|
5993
|
-
const bytesPerPixel = getTextureFormatBytesPerPixel(this.
|
|
6367
|
+
const bytesPerPixel = getTextureFormatBytesPerPixel(this.props.format, this.device.isWebGL2);
|
|
5994
6368
|
this.trackAllocatedMemory(this.width * this.height * bytesPerPixel, "Texture");
|
|
5995
6369
|
}
|
|
5996
6370
|
this.loaded = true;
|
|
@@ -6010,7 +6384,7 @@ void main(void) {}`;
|
|
|
6010
6384
|
width = this.width,
|
|
6011
6385
|
height = this.height,
|
|
6012
6386
|
level = 0,
|
|
6013
|
-
|
|
6387
|
+
glFormat = this.glFormat,
|
|
6014
6388
|
type = this.type,
|
|
6015
6389
|
dataFormat = this.dataFormat,
|
|
6016
6390
|
compressed = false,
|
|
@@ -6048,7 +6422,7 @@ void main(void) {}`;
|
|
|
6048
6422
|
this.gl.bindTexture(this.target, this.handle);
|
|
6049
6423
|
withParameters(this.gl, parameters, () => {
|
|
6050
6424
|
if (compressed) {
|
|
6051
|
-
this.gl.compressedTexSubImage2D(target, level, x, y, width, height,
|
|
6425
|
+
this.gl.compressedTexSubImage2D(target, level, x, y, width, height, glFormat, data);
|
|
6052
6426
|
} else if (data === null) {
|
|
6053
6427
|
this.gl.texSubImage2D(target, level, x, y, width, height, dataFormat, type, null);
|
|
6054
6428
|
} else if (ArrayBuffer.isView(data)) {
|
|
@@ -6157,7 +6531,7 @@ void main(void) {}`;
|
|
|
6157
6531
|
type,
|
|
6158
6532
|
compressed
|
|
6159
6533
|
} = opts;
|
|
6160
|
-
const parameters = getWebGLTextureParameters(this.
|
|
6534
|
+
const parameters = getWebGLTextureParameters(format, this.device.isWebGL2);
|
|
6161
6535
|
dataFormat = dataFormat || parameters.dataFormat;
|
|
6162
6536
|
type = type || parameters.type;
|
|
6163
6537
|
compressed = compressed || parameters.compressed;
|
|
@@ -6300,7 +6674,7 @@ void main(void) {}`;
|
|
|
6300
6674
|
} = options;
|
|
6301
6675
|
this.trackDeallocatedMemory("Texture");
|
|
6302
6676
|
this.gl.bindTexture(this.target, this.handle);
|
|
6303
|
-
const webglTextureFormat = getWebGLTextureParameters(this.
|
|
6677
|
+
const webglTextureFormat = getWebGLTextureParameters(format, this.device.isWebGL2);
|
|
6304
6678
|
withParameters(this.gl, parameters, () => {
|
|
6305
6679
|
if (ArrayBuffer.isView(data)) {
|
|
6306
6680
|
this.gl.texImage3D(
|
|
@@ -6325,7 +6699,7 @@ void main(void) {}`;
|
|
|
6325
6699
|
if (data && data.byteLength) {
|
|
6326
6700
|
this.trackAllocatedMemory(data.byteLength, "Texture");
|
|
6327
6701
|
} else {
|
|
6328
|
-
const bytesPerPixel = getTextureFormatBytesPerPixel(this.
|
|
6702
|
+
const bytesPerPixel = getTextureFormatBytesPerPixel(this.props.format, this.device.isWebGL2);
|
|
6329
6703
|
this.trackAllocatedMemory(this.width * this.height * this.depth * bytesPerPixel, "Texture");
|
|
6330
6704
|
}
|
|
6331
6705
|
this.loaded = true;
|
|
@@ -6424,16 +6798,6 @@ void main(void) {}`;
|
|
|
6424
6798
|
assert2(value !== void 0, `Accessing undefined constant GL.${name}`);
|
|
6425
6799
|
return value;
|
|
6426
6800
|
}
|
|
6427
|
-
function getKey(gl, value) {
|
|
6428
|
-
gl = gl.gl || gl;
|
|
6429
|
-
value = Number(value);
|
|
6430
|
-
for (const key in gl) {
|
|
6431
|
-
if (gl[key] === value) {
|
|
6432
|
-
return `GL.${key}`;
|
|
6433
|
-
}
|
|
6434
|
-
}
|
|
6435
|
-
return String(value);
|
|
6436
|
-
}
|
|
6437
6801
|
|
|
6438
6802
|
// src/adapter/objects/webgl-resource.ts
|
|
6439
6803
|
var ERR_RESOURCE_METHOD_UNDEFINED = "Resource subclass must define virtual methods";
|
|
@@ -6464,9 +6828,6 @@ void main(void) {}`;
|
|
|
6464
6828
|
get handle() {
|
|
6465
6829
|
return this._handle;
|
|
6466
6830
|
}
|
|
6467
|
-
destroy() {
|
|
6468
|
-
this.delete();
|
|
6469
|
-
}
|
|
6470
6831
|
delete({
|
|
6471
6832
|
deleteChildren = false
|
|
6472
6833
|
} = {}) {
|
|
@@ -6476,7 +6837,7 @@ void main(void) {}`;
|
|
|
6476
6837
|
}
|
|
6477
6838
|
this._handle = null;
|
|
6478
6839
|
if (children && deleteChildren) {
|
|
6479
|
-
children.filter(Boolean).forEach((child) => child.
|
|
6840
|
+
children.filter(Boolean).forEach((child) => child.destroy());
|
|
6480
6841
|
}
|
|
6481
6842
|
return this;
|
|
6482
6843
|
}
|
|
@@ -6539,10 +6900,10 @@ void main(void) {}`;
|
|
|
6539
6900
|
const parameter = PARAMETERS[pname];
|
|
6540
6901
|
const parameterAvailable = parameter && (!("webgl2" in parameter) || isWebgl2) && (!("extension" in parameter) || this.gl.getExtension(parameter.extension));
|
|
6541
6902
|
if (parameterAvailable) {
|
|
6542
|
-
const key = keys ?
|
|
6903
|
+
const key = keys ? this.device.getGLKey(pname) : pname;
|
|
6543
6904
|
values[key] = this.getParameter(pname, options);
|
|
6544
6905
|
if (keys && parameter.type === "GLenum") {
|
|
6545
|
-
values[key] =
|
|
6906
|
+
values[key] = this.device.getGLKey(values[key]);
|
|
6546
6907
|
}
|
|
6547
6908
|
}
|
|
6548
6909
|
}
|
|
@@ -6640,204 +7001,8 @@ void main(void) {}`;
|
|
|
6640
7001
|
*/
|
|
6641
7002
|
};
|
|
6642
7003
|
|
|
6643
|
-
// src/adapter/converters/renderbuffer-formats.ts
|
|
6644
|
-
function isRenderbufferFormatSupported(gl, format) {
|
|
6645
|
-
const info = RENDERBUFFER_FORMATS[format];
|
|
6646
|
-
if (!info) {
|
|
6647
|
-
return false;
|
|
6648
|
-
}
|
|
6649
|
-
if (info.ext) {
|
|
6650
|
-
return Boolean(gl.getExtension(info.ext));
|
|
6651
|
-
}
|
|
6652
|
-
if (info.gl2) {
|
|
6653
|
-
return isWebGL2(gl);
|
|
6654
|
-
}
|
|
6655
|
-
return true;
|
|
6656
|
-
}
|
|
6657
|
-
function getRenderbufferFormatBytesPerPixel(format) {
|
|
6658
|
-
return RENDERBUFFER_FORMATS[format].bpp;
|
|
6659
|
-
}
|
|
6660
|
-
var EXT_FLOAT_WEBGL2 = "EXT_color_buffer_float";
|
|
6661
|
-
var RENDERBUFFER_FORMATS = {
|
|
6662
|
-
[GL.DEPTH_COMPONENT16]: {
|
|
6663
|
-
bpp: 2
|
|
6664
|
-
},
|
|
6665
|
-
// 16 depth bits.
|
|
6666
|
-
[GL.DEPTH_COMPONENT24]: {
|
|
6667
|
-
gl2: true,
|
|
6668
|
-
bpp: 3
|
|
6669
|
-
},
|
|
6670
|
-
[GL.DEPTH_COMPONENT32F]: {
|
|
6671
|
-
gl2: true,
|
|
6672
|
-
bpp: 4
|
|
6673
|
-
},
|
|
6674
|
-
[GL.STENCIL_INDEX8]: {
|
|
6675
|
-
bpp: 1
|
|
6676
|
-
},
|
|
6677
|
-
// 8 stencil bits.
|
|
6678
|
-
[GL.DEPTH_STENCIL]: {
|
|
6679
|
-
bpp: 4
|
|
6680
|
-
},
|
|
6681
|
-
[GL.DEPTH24_STENCIL8]: {
|
|
6682
|
-
gl2: true,
|
|
6683
|
-
bpp: 4
|
|
6684
|
-
},
|
|
6685
|
-
[GL.DEPTH32F_STENCIL8]: {
|
|
6686
|
-
gl2: true,
|
|
6687
|
-
bpp: 5
|
|
6688
|
-
},
|
|
6689
|
-
// When using a WebGL 1 context, color renderbuffer formats are limited
|
|
6690
|
-
[GL.RGBA4]: {
|
|
6691
|
-
bpp: 2
|
|
6692
|
-
},
|
|
6693
|
-
[GL.RGB565]: {
|
|
6694
|
-
bpp: 2
|
|
6695
|
-
},
|
|
6696
|
-
[GL.RGB5_A1]: {
|
|
6697
|
-
bpp: 2
|
|
6698
|
-
},
|
|
6699
|
-
// When using a WebGL 2 context, the following values are available additionally:
|
|
6700
|
-
[GL.R8]: {
|
|
6701
|
-
gl2: true,
|
|
6702
|
-
bpp: 1
|
|
6703
|
-
},
|
|
6704
|
-
[GL.R8UI]: {
|
|
6705
|
-
gl2: true,
|
|
6706
|
-
bpp: 1
|
|
6707
|
-
},
|
|
6708
|
-
[GL.R8I]: {
|
|
6709
|
-
gl2: true,
|
|
6710
|
-
bpp: 1
|
|
6711
|
-
},
|
|
6712
|
-
[GL.R16UI]: {
|
|
6713
|
-
gl2: true,
|
|
6714
|
-
bpp: 2
|
|
6715
|
-
},
|
|
6716
|
-
[GL.R16I]: {
|
|
6717
|
-
gl2: true,
|
|
6718
|
-
bpp: 2
|
|
6719
|
-
},
|
|
6720
|
-
[GL.R32UI]: {
|
|
6721
|
-
gl2: true,
|
|
6722
|
-
bpp: 4
|
|
6723
|
-
},
|
|
6724
|
-
[GL.R32I]: {
|
|
6725
|
-
gl2: true,
|
|
6726
|
-
bpp: 4
|
|
6727
|
-
},
|
|
6728
|
-
[GL.RG8]: {
|
|
6729
|
-
gl2: true,
|
|
6730
|
-
bpp: 2
|
|
6731
|
-
},
|
|
6732
|
-
[GL.RG8UI]: {
|
|
6733
|
-
gl2: true,
|
|
6734
|
-
bpp: 2
|
|
6735
|
-
},
|
|
6736
|
-
[GL.RG8I]: {
|
|
6737
|
-
gl2: true,
|
|
6738
|
-
bpp: 2
|
|
6739
|
-
},
|
|
6740
|
-
[GL.RG16UI]: {
|
|
6741
|
-
gl2: true,
|
|
6742
|
-
bpp: 4
|
|
6743
|
-
},
|
|
6744
|
-
[GL.RG16I]: {
|
|
6745
|
-
gl2: true,
|
|
6746
|
-
bpp: 4
|
|
6747
|
-
},
|
|
6748
|
-
[GL.RG32UI]: {
|
|
6749
|
-
gl2: true,
|
|
6750
|
-
bpp: 8
|
|
6751
|
-
},
|
|
6752
|
-
[GL.RG32I]: {
|
|
6753
|
-
gl2: true,
|
|
6754
|
-
bpp: 8
|
|
6755
|
-
},
|
|
6756
|
-
[GL.RGB8]: {
|
|
6757
|
-
gl2: true,
|
|
6758
|
-
bpp: 3
|
|
6759
|
-
},
|
|
6760
|
-
[GL.RGBA8]: {
|
|
6761
|
-
gl2: true,
|
|
6762
|
-
bpp: 4
|
|
6763
|
-
},
|
|
6764
|
-
// [GL.SRGB8_ALPHA8]: {gl2: true, gl1: SRGB}, // When using the EXT_sRGB WebGL1 extension
|
|
6765
|
-
[GL.RGB10_A2]: {
|
|
6766
|
-
gl2: true,
|
|
6767
|
-
bpp: 4
|
|
6768
|
-
},
|
|
6769
|
-
[GL.RGBA8UI]: {
|
|
6770
|
-
gl2: true,
|
|
6771
|
-
bpp: 4
|
|
6772
|
-
},
|
|
6773
|
-
[GL.RGBA8I]: {
|
|
6774
|
-
gl2: true,
|
|
6775
|
-
bpp: 4
|
|
6776
|
-
},
|
|
6777
|
-
[GL.RGB10_A2UI]: {
|
|
6778
|
-
gl2: true,
|
|
6779
|
-
bpp: 4
|
|
6780
|
-
},
|
|
6781
|
-
[GL.RGBA16UI]: {
|
|
6782
|
-
gl2: true,
|
|
6783
|
-
bpp: 8
|
|
6784
|
-
},
|
|
6785
|
-
[GL.RGBA16I]: {
|
|
6786
|
-
gl2: true,
|
|
6787
|
-
bpp: 8
|
|
6788
|
-
},
|
|
6789
|
-
[GL.RGBA32I]: {
|
|
6790
|
-
gl2: true,
|
|
6791
|
-
bpp: 16
|
|
6792
|
-
},
|
|
6793
|
-
[GL.RGBA32UI]: {
|
|
6794
|
-
gl2: true,
|
|
6795
|
-
bpp: 16
|
|
6796
|
-
},
|
|
6797
|
-
// When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
|
|
6798
|
-
[GL.R16F]: {
|
|
6799
|
-
ext: EXT_FLOAT_WEBGL2,
|
|
6800
|
-
bpp: 2
|
|
6801
|
-
},
|
|
6802
|
-
[GL.RG16F]: {
|
|
6803
|
-
ext: EXT_FLOAT_WEBGL2,
|
|
6804
|
-
bpp: 4
|
|
6805
|
-
},
|
|
6806
|
-
[GL.RGBA16F]: {
|
|
6807
|
-
ext: EXT_FLOAT_WEBGL2,
|
|
6808
|
-
bpp: 8
|
|
6809
|
-
},
|
|
6810
|
-
[GL.R32F]: {
|
|
6811
|
-
ext: EXT_FLOAT_WEBGL2,
|
|
6812
|
-
bpp: 4
|
|
6813
|
-
},
|
|
6814
|
-
[GL.RG32F]: {
|
|
6815
|
-
ext: EXT_FLOAT_WEBGL2,
|
|
6816
|
-
bpp: 8
|
|
6817
|
-
},
|
|
6818
|
-
// TODO - can't get WEBGL_color_buffer_float to work on renderbuffers
|
|
6819
|
-
[GL.RGBA32F]: {
|
|
6820
|
-
ext: EXT_FLOAT_WEBGL2,
|
|
6821
|
-
bpp: 16
|
|
6822
|
-
},
|
|
6823
|
-
// [GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2, gl1: EXT_FLOAT_WEBGL1},
|
|
6824
|
-
[GL.R11F_G11F_B10F]: {
|
|
6825
|
-
ext: EXT_FLOAT_WEBGL2,
|
|
6826
|
-
bpp: 4
|
|
6827
|
-
}
|
|
6828
|
-
};
|
|
6829
|
-
|
|
6830
7004
|
// src/adapter/objects/webgl-renderbuffer.ts
|
|
6831
|
-
var
|
|
6832
|
-
id: void 0,
|
|
6833
|
-
handle: void 0,
|
|
6834
|
-
userData: void 0,
|
|
6835
|
-
format: 0,
|
|
6836
|
-
width: 1,
|
|
6837
|
-
height: 1,
|
|
6838
|
-
samples: 0
|
|
6839
|
-
};
|
|
6840
|
-
var WEBGLRenderbuffer = class extends WebGLResource {
|
|
7005
|
+
var _WEBGLRenderbuffer = class extends WebGLResource {
|
|
6841
7006
|
get [Symbol.toStringTag]() {
|
|
6842
7007
|
return "Renderbuffer";
|
|
6843
7008
|
}
|
|
@@ -6853,11 +7018,19 @@ void main(void) {}`;
|
|
|
6853
7018
|
get samples() {
|
|
6854
7019
|
return this.props.samples;
|
|
6855
7020
|
}
|
|
6856
|
-
|
|
6857
|
-
return
|
|
7021
|
+
get attachment() {
|
|
7022
|
+
return;
|
|
7023
|
+
}
|
|
7024
|
+
/** WebGL format constant */
|
|
7025
|
+
static isTextureFormatSupported(device, format) {
|
|
7026
|
+
return isRenderbufferFormatSupported(device.gl, format);
|
|
6858
7027
|
}
|
|
6859
7028
|
constructor(device, props) {
|
|
6860
|
-
|
|
7029
|
+
if (typeof props.format === "number") {
|
|
7030
|
+
throw new Error("Renderbuffer");
|
|
7031
|
+
}
|
|
7032
|
+
super(device, props, _WEBGLRenderbuffer.defaultProps);
|
|
7033
|
+
this.glFormat = convertTextureFormatToGL(this.props.format, device.isWebGL2);
|
|
6861
7034
|
this._initialize(this.props);
|
|
6862
7035
|
}
|
|
6863
7036
|
resize(size) {
|
|
@@ -6869,7 +7042,6 @@ void main(void) {}`;
|
|
|
6869
7042
|
});
|
|
6870
7043
|
this._initialize(this.props);
|
|
6871
7044
|
}
|
|
6872
|
-
return this;
|
|
6873
7045
|
}
|
|
6874
7046
|
// PRIVATE METHODS
|
|
6875
7047
|
/** Creates and initializes a renderbuffer object's data store */
|
|
@@ -6884,13 +7056,12 @@ void main(void) {}`;
|
|
|
6884
7056
|
this.trackDeallocatedMemory();
|
|
6885
7057
|
this.gl.bindRenderbuffer(GL.RENDERBUFFER, this.handle);
|
|
6886
7058
|
if (samples !== 0 && this.device.isWebGL2) {
|
|
6887
|
-
this.
|
|
7059
|
+
this.gl2.renderbufferStorageMultisample(GL.RENDERBUFFER, samples, this.glFormat, width, height);
|
|
6888
7060
|
} else {
|
|
6889
|
-
this.gl.renderbufferStorage(GL.RENDERBUFFER,
|
|
7061
|
+
this.gl.renderbufferStorage(GL.RENDERBUFFER, this.glFormat, width, height);
|
|
6890
7062
|
}
|
|
6891
7063
|
this.gl.bindRenderbuffer(GL.RENDERBUFFER, null);
|
|
6892
|
-
this.trackAllocatedMemory(width * height * (samples || 1) *
|
|
6893
|
-
return this;
|
|
7064
|
+
this.trackAllocatedMemory(width * height * (samples || 1) * getTextureFormatBytesPerPixel(this.glFormat, this.device.isWebGL2));
|
|
6894
7065
|
}
|
|
6895
7066
|
// RESOURCE IMPLEMENTATION
|
|
6896
7067
|
_createHandle() {
|
|
@@ -6904,51 +7075,57 @@ void main(void) {}`;
|
|
|
6904
7075
|
this.gl.bindRenderbuffer(GL.RENDERBUFFER, handle);
|
|
6905
7076
|
}
|
|
6906
7077
|
};
|
|
7078
|
+
var WEBGLRenderbuffer = _WEBGLRenderbuffer;
|
|
7079
|
+
__publicField(WEBGLRenderbuffer, "defaultProps", {
|
|
7080
|
+
id: void 0,
|
|
7081
|
+
handle: void 0,
|
|
7082
|
+
userData: void 0,
|
|
7083
|
+
format: void 0,
|
|
7084
|
+
// 'depth16unorm'
|
|
7085
|
+
width: 1,
|
|
7086
|
+
height: 1,
|
|
7087
|
+
samples: 0
|
|
7088
|
+
});
|
|
6907
7089
|
|
|
6908
7090
|
// src/adapter/resources/webgl-framebuffer.ts
|
|
6909
7091
|
var WEBGLFramebuffer = class extends Framebuffer {
|
|
6910
7092
|
get texture() {
|
|
6911
7093
|
return this.colorAttachments[0];
|
|
6912
7094
|
}
|
|
6913
|
-
colorAttachments = [];
|
|
6914
|
-
depthStencilAttachment = null;
|
|
6915
|
-
_ownResources = [];
|
|
6916
7095
|
constructor(device, props) {
|
|
6917
7096
|
super(device, props);
|
|
7097
|
+
const isDefaultFramebuffer = props.handle === null;
|
|
6918
7098
|
this.device = device;
|
|
6919
7099
|
this.gl = device.gl;
|
|
6920
|
-
this.handle = this.props.handle
|
|
6921
|
-
if (
|
|
7100
|
+
this.handle = this.props.handle || isDefaultFramebuffer ? this.props.handle : this.gl.createFramebuffer();
|
|
7101
|
+
if (!isDefaultFramebuffer) {
|
|
6922
7102
|
device.setSpectorMetadata(this.handle, {
|
|
6923
7103
|
id: this.props.id,
|
|
6924
7104
|
props: this.props
|
|
6925
7105
|
});
|
|
6926
|
-
|
|
6927
|
-
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
this._attachOne(attachmentPoint, attachment);
|
|
7106
|
+
this.autoCreateAttachmentTextures();
|
|
7107
|
+
this.gl.bindFramebuffer(GL.FRAMEBUFFER, this.handle);
|
|
7108
|
+
for (let i = 0; i < this.colorAttachments.length; ++i) {
|
|
7109
|
+
const attachment = this.colorAttachments[i];
|
|
7110
|
+
const attachmentPoint = GL.COLOR_ATTACHMENT0 + i;
|
|
7111
|
+
if (attachment) {
|
|
7112
|
+
this._attachOne(attachmentPoint, attachment);
|
|
7113
|
+
}
|
|
6935
7114
|
}
|
|
7115
|
+
if (this.depthStencilAttachment) {
|
|
7116
|
+
this._attachOne(getDepthStencilAttachmentWebGL(this.depthStencilAttachment.format), this.depthStencilAttachment);
|
|
7117
|
+
}
|
|
7118
|
+
this.gl.bindFramebuffer(GL.FRAMEBUFFER, null);
|
|
6936
7119
|
}
|
|
6937
|
-
if (this.props.depthStencilAttachment) {
|
|
6938
|
-
this._attachOne(getWebGLDepthStencilAttachment(this.depthStencilAttachment.format), this.depthStencilAttachment);
|
|
6939
|
-
}
|
|
6940
|
-
this.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
|
|
6941
7120
|
if (props.check !== false) {
|
|
6942
7121
|
this._checkStatus();
|
|
6943
7122
|
}
|
|
6944
7123
|
}
|
|
7124
|
+
/** destroys any auto created resources etc. */
|
|
6945
7125
|
destroy() {
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
resource.destroy();
|
|
6949
|
-
}
|
|
7126
|
+
super.destroy();
|
|
7127
|
+
if (!this.destroyed && this.handle !== null) {
|
|
6950
7128
|
this.gl.deleteFramebuffer(this.handle);
|
|
6951
|
-
this.destroyed = true;
|
|
6952
7129
|
}
|
|
6953
7130
|
}
|
|
6954
7131
|
// PRIVATE
|
|
@@ -6957,84 +7134,29 @@ void main(void) {}`;
|
|
|
6957
7134
|
const {
|
|
6958
7135
|
gl
|
|
6959
7136
|
} = this;
|
|
6960
|
-
const
|
|
7137
|
+
const prevHandle2 = gl.bindFramebuffer(GL.FRAMEBUFFER, this.handle);
|
|
6961
7138
|
const status = gl.checkFramebufferStatus(GL.FRAMEBUFFER);
|
|
6962
|
-
gl.bindFramebuffer(GL.FRAMEBUFFER,
|
|
7139
|
+
gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
|
|
6963
7140
|
if (status !== gl.FRAMEBUFFER_COMPLETE) {
|
|
6964
7141
|
throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
|
|
6965
7142
|
}
|
|
6966
7143
|
}
|
|
6967
|
-
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
return void 0;
|
|
6971
|
-
}
|
|
6972
|
-
if (colorAttachment instanceof WEBGLTexture) {
|
|
6973
|
-
return colorAttachment;
|
|
6974
|
-
}
|
|
6975
|
-
return this._createColorAttachment(colorAttachment, this.width, this.height);
|
|
6976
|
-
});
|
|
6977
|
-
}
|
|
6978
|
-
/** Create a color attachment */
|
|
6979
|
-
_createColorAttachment(format, width, height) {
|
|
6980
|
-
const texture = this.device._createTexture({
|
|
6981
|
-
id: `${this.id}-color`,
|
|
6982
|
-
data: null,
|
|
6983
|
-
// reserves texture memory, but texels are undefined
|
|
6984
|
-
format,
|
|
6985
|
-
// type: GL.UNSIGNED_BYTE,
|
|
6986
|
-
width,
|
|
6987
|
-
height,
|
|
6988
|
-
// Note: Mipmapping can be disabled by texture resource when we resize the texture
|
|
6989
|
-
// to a non-power-of-two dimenstion (NPOT texture) under WebGL1. To have consistant
|
|
6990
|
-
// behavior we always disable mipmaps.
|
|
6991
|
-
mipmaps: false,
|
|
6992
|
-
// Set MIN and MAG filtering parameters so mipmaps are not used in sampling.
|
|
6993
|
-
// Use LINEAR so subpixel algos like fxaa work.
|
|
6994
|
-
// Set WRAP modes that support NPOT textures too.
|
|
6995
|
-
sampler: {
|
|
6996
|
-
minFilter: "linear",
|
|
6997
|
-
magFilter: "linear",
|
|
6998
|
-
addressModeU: "clamp-to-edge",
|
|
6999
|
-
addressModeV: "clamp-to-edge"
|
|
7000
|
-
}
|
|
7001
|
-
// parameters: {
|
|
7002
|
-
// [GL.TEXTURE_MIN_FILTER]: GL.LINEAR,
|
|
7003
|
-
// [GL.TEXTURE_MAG_FILTER]: GL.LINEAR,
|
|
7004
|
-
// [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
|
|
7005
|
-
// [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE
|
|
7006
|
-
// }
|
|
7007
|
-
});
|
|
7008
|
-
this._ownResources.push(texture);
|
|
7009
|
-
return texture;
|
|
7010
|
-
}
|
|
7011
|
-
/** Create a depth stencil attachment GL.DEPTH24_STENCIL8 */
|
|
7012
|
-
_createDepthStencilAttachment() {
|
|
7013
|
-
if (!this.props.depthStencilAttachment) {
|
|
7014
|
-
return void 0;
|
|
7015
|
-
}
|
|
7016
|
-
if (this.props.depthStencilAttachment instanceof WEBGLRenderbuffer) {
|
|
7017
|
-
return this.props.depthStencilAttachment;
|
|
7018
|
-
}
|
|
7019
|
-
if (this.props.depthStencilAttachment instanceof Texture) {
|
|
7020
|
-
return this.props.depthStencilAttachment;
|
|
7021
|
-
}
|
|
7022
|
-
const format = this.props.depthStencilAttachment;
|
|
7023
|
-
const webglFormat = getWebGLTextureFormat(this.gl, format);
|
|
7024
|
-
const texture = new WEBGLRenderbuffer(this.device, {
|
|
7144
|
+
/** In WebGL we must use renderbuffers for depth/stencil attachments (unless we have extensions) */
|
|
7145
|
+
createDepthStencilTexture(format) {
|
|
7146
|
+
return new WEBGLRenderbuffer(this.device, {
|
|
7025
7147
|
id: `${this.id}-depth-stencil`,
|
|
7026
7148
|
// TODO misleading if not depth and stencil?
|
|
7027
|
-
format
|
|
7149
|
+
format,
|
|
7028
7150
|
// dataFormat: GL.DEPTH_STENCIL,
|
|
7029
7151
|
// type: GL.UNSIGNED_INT_24_8,
|
|
7030
7152
|
width: this.width,
|
|
7031
7153
|
height: this.height
|
|
7032
7154
|
});
|
|
7033
|
-
this._ownResources.push(texture);
|
|
7034
|
-
return texture;
|
|
7035
7155
|
}
|
|
7036
|
-
/**
|
|
7037
|
-
|
|
7156
|
+
/**
|
|
7157
|
+
* Attachment resize is expected to be a noop if size is same
|
|
7158
|
+
*/
|
|
7159
|
+
resizeAttachments(width, height) {
|
|
7038
7160
|
if (this.handle === null) {
|
|
7039
7161
|
this.width = this.gl.drawingBufferWidth;
|
|
7040
7162
|
this.height = this.gl.drawingBufferHeight;
|
|
@@ -7046,19 +7168,18 @@ void main(void) {}`;
|
|
|
7046
7168
|
if (height === void 0) {
|
|
7047
7169
|
height = this.gl.drawingBufferHeight;
|
|
7048
7170
|
}
|
|
7049
|
-
if (width !== this.width && height !== this.height) {
|
|
7050
|
-
log.log(2, `Resizing framebuffer ${this.id} to ${width}x${height}`)();
|
|
7051
|
-
}
|
|
7052
7171
|
for (const colorAttachment of this.colorAttachments) {
|
|
7053
7172
|
colorAttachment.resize({
|
|
7054
7173
|
width,
|
|
7055
7174
|
height
|
|
7056
7175
|
});
|
|
7057
7176
|
}
|
|
7058
|
-
this.depthStencilAttachment
|
|
7059
|
-
|
|
7060
|
-
|
|
7061
|
-
|
|
7177
|
+
if (this.depthStencilAttachment) {
|
|
7178
|
+
this.depthStencilAttachment.resize({
|
|
7179
|
+
width,
|
|
7180
|
+
height
|
|
7181
|
+
});
|
|
7182
|
+
}
|
|
7062
7183
|
return this;
|
|
7063
7184
|
}
|
|
7064
7185
|
/** Attach one attachment */
|
|
@@ -7564,12 +7685,9 @@ void main(void) {}`;
|
|
|
7564
7685
|
}
|
|
7565
7686
|
Object.seal(this);
|
|
7566
7687
|
}
|
|
7567
|
-
write(data, byteOffset) {
|
|
7568
|
-
|
|
7569
|
-
|
|
7570
|
-
offset: byteOffset
|
|
7571
|
-
});
|
|
7572
|
-
}
|
|
7688
|
+
// override write(data: TypedArray, byteOffset: number = 0): void {
|
|
7689
|
+
// this.subData({data, offset: byteOffset});
|
|
7690
|
+
// }
|
|
7573
7691
|
// returns number of elements in the buffer (assuming that the full buffer is used)
|
|
7574
7692
|
getElementCount(accessor = this.accessor) {
|
|
7575
7693
|
return Math.round(this.byteLength / Accessor.getBytesPerElement(accessor));
|
|
@@ -7981,10 +8099,17 @@ ${formattedLog}`)();
|
|
|
7981
8099
|
}
|
|
7982
8100
|
|
|
7983
8101
|
// src/adapter/resources/webgl-render-pass.ts
|
|
8102
|
+
var GL_DEPTH_BUFFER_BIT = 256;
|
|
8103
|
+
var GL_STENCIL_BUFFER_BIT = 1024;
|
|
8104
|
+
var GL_COLOR_BUFFER_BIT = 16384;
|
|
8105
|
+
var GL_COLOR = 6144;
|
|
7984
8106
|
var WEBGLRenderPass = class extends RenderPass {
|
|
8107
|
+
/** Parameters that should be applied before each draw call */
|
|
7985
8108
|
constructor(device, props) {
|
|
7986
8109
|
super(device, props);
|
|
7987
8110
|
this.device = device;
|
|
8111
|
+
this.setParameters(this.props.parameters);
|
|
8112
|
+
this.clear();
|
|
7988
8113
|
}
|
|
7989
8114
|
end() {
|
|
7990
8115
|
}
|
|
@@ -7998,6 +8123,102 @@ ${formattedLog}`)();
|
|
|
7998
8123
|
// beginOcclusionQuery(queryIndex: number): void;
|
|
7999
8124
|
// endOcclusionQuery(): void;
|
|
8000
8125
|
// executeBundles(bundles: Iterable<GPURenderBundle>): void;
|
|
8126
|
+
/**
|
|
8127
|
+
* Maps RenderPass parameters to GL parameters
|
|
8128
|
+
*/
|
|
8129
|
+
setParameters(parameters = {}) {
|
|
8130
|
+
const glParameters = {};
|
|
8131
|
+
if (this.props.framebuffer) {
|
|
8132
|
+
glParameters.framebuffer = this.props.framebuffer;
|
|
8133
|
+
}
|
|
8134
|
+
if (this.props.depthReadOnly) {
|
|
8135
|
+
glParameters.depthMask = !this.props.depthReadOnly;
|
|
8136
|
+
}
|
|
8137
|
+
glParameters.stencilMask = this.props.stencilReadOnly ? 0 : 1;
|
|
8138
|
+
glParameters[GL.RASTERIZER_DISCARD] = this.props.discard;
|
|
8139
|
+
if (parameters.viewport) {
|
|
8140
|
+
glParameters.viewport = parameters.viewport;
|
|
8141
|
+
glParameters.depthRange = [parameters.viewport[4], parameters.viewport[5]];
|
|
8142
|
+
}
|
|
8143
|
+
glParameters.scissorTest = Boolean(parameters.scissorRect);
|
|
8144
|
+
if (parameters.scissorRect) {
|
|
8145
|
+
glParameters.scissor = parameters.scissorRect;
|
|
8146
|
+
}
|
|
8147
|
+
if (parameters.blendConstant) {
|
|
8148
|
+
glParameters.blendColor = parameters.blendConstant;
|
|
8149
|
+
}
|
|
8150
|
+
if (parameters.stencilReference) {
|
|
8151
|
+
console.warn("RenderPassParameters.stencilReference not yet implemented in WebGL");
|
|
8152
|
+
parameters[GL.STENCIL_REF] = parameters.stencilReference;
|
|
8153
|
+
}
|
|
8154
|
+
this.glParameters = glParameters;
|
|
8155
|
+
}
|
|
8156
|
+
// Internal
|
|
8157
|
+
/**
|
|
8158
|
+
* Optionally clears depth, color and stencil buffers based on parameters
|
|
8159
|
+
*/
|
|
8160
|
+
clear() {
|
|
8161
|
+
const glParameters = {
|
|
8162
|
+
...this.glParameters
|
|
8163
|
+
};
|
|
8164
|
+
let clearMask = 0;
|
|
8165
|
+
if (this.props.clearColor !== false) {
|
|
8166
|
+
clearMask |= GL_COLOR_BUFFER_BIT;
|
|
8167
|
+
glParameters.clearColor = this.props.clearColor;
|
|
8168
|
+
}
|
|
8169
|
+
if (this.props.clearDepth !== false) {
|
|
8170
|
+
clearMask |= GL_DEPTH_BUFFER_BIT;
|
|
8171
|
+
glParameters.clearDepth = this.props.clearDepth;
|
|
8172
|
+
}
|
|
8173
|
+
if (this.props.clearStencil !== false) {
|
|
8174
|
+
clearMask |= GL_STENCIL_BUFFER_BIT;
|
|
8175
|
+
glParameters.clearStencil = this.props.clearStencil;
|
|
8176
|
+
}
|
|
8177
|
+
if (clearMask !== 0) {
|
|
8178
|
+
withParameters(this.device, glParameters, () => {
|
|
8179
|
+
this.device.gl.clear(clearMask);
|
|
8180
|
+
});
|
|
8181
|
+
}
|
|
8182
|
+
}
|
|
8183
|
+
/**
|
|
8184
|
+
* WebGL2 - clear a specific color buffer
|
|
8185
|
+
*/
|
|
8186
|
+
clearColorBuffer(drawBuffer = 0, value = [0, 0, 0, 0]) {
|
|
8187
|
+
withParameters(this.device.gl2, {
|
|
8188
|
+
framebuffer: this.props.framebuffer
|
|
8189
|
+
}, () => {
|
|
8190
|
+
switch (value.constructor) {
|
|
8191
|
+
case Int32Array:
|
|
8192
|
+
this.device.gl2.clearBufferiv(GL_COLOR, drawBuffer, value);
|
|
8193
|
+
break;
|
|
8194
|
+
case Uint32Array:
|
|
8195
|
+
this.device.gl2.clearBufferuiv(GL_COLOR, drawBuffer, value);
|
|
8196
|
+
break;
|
|
8197
|
+
case Float32Array:
|
|
8198
|
+
default:
|
|
8199
|
+
this.device.gl2.clearBufferfv(GL_COLOR, drawBuffer, value);
|
|
8200
|
+
break;
|
|
8201
|
+
}
|
|
8202
|
+
});
|
|
8203
|
+
}
|
|
8204
|
+
// clearDepthStencil() {
|
|
8205
|
+
// const GL_DEPTH = 0x1801;
|
|
8206
|
+
// const GL_STENCIL = 0x1802;
|
|
8207
|
+
// const GL_DEPTH_STENCIL = 0x84f9;
|
|
8208
|
+
// case GL_DEPTH:
|
|
8209
|
+
// this.device.gl2.clearBufferfv(GL_DEPTH, 0, [value]);
|
|
8210
|
+
// break;
|
|
8211
|
+
// case GL_STENCIL:
|
|
8212
|
+
// this.device.gl2.clearBufferiv(GL_STENCIL, 0, [value]);
|
|
8213
|
+
// break;
|
|
8214
|
+
// case GL_DEPTH_STENCIL:
|
|
8215
|
+
// const [depth, stencil] = value;
|
|
8216
|
+
// this.device.gl2.clearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);
|
|
8217
|
+
// break;
|
|
8218
|
+
// default:
|
|
8219
|
+
// assert(false, ERR_ARGUMENTS);
|
|
8220
|
+
// }
|
|
8221
|
+
// });
|
|
8001
8222
|
};
|
|
8002
8223
|
|
|
8003
8224
|
// src/adapter/helpers/uniforms.ts
|
|
@@ -8653,7 +8874,7 @@ ${formattedLog}`)();
|
|
|
8653
8874
|
*/
|
|
8654
8875
|
draw(options) {
|
|
8655
8876
|
const {
|
|
8656
|
-
renderPass
|
|
8877
|
+
renderPass,
|
|
8657
8878
|
vertexCount,
|
|
8658
8879
|
// indexCount,
|
|
8659
8880
|
instanceCount,
|
|
@@ -8678,10 +8899,9 @@ ${formattedLog}`)();
|
|
|
8678
8899
|
}
|
|
8679
8900
|
this._applyBindings();
|
|
8680
8901
|
this._applyUniforms();
|
|
8902
|
+
const webglRenderPass = renderPass;
|
|
8681
8903
|
withDeviceParameters(this.device, this.props.parameters, () => {
|
|
8682
|
-
withGLParameters(this.device, {
|
|
8683
|
-
framebuffer: renderPass.props.framebuffer
|
|
8684
|
-
}, () => {
|
|
8904
|
+
withGLParameters(this.device, webglRenderPass.glParameters, () => {
|
|
8685
8905
|
if (isIndexed && isInstanced) {
|
|
8686
8906
|
this.device.gl2?.drawElementsInstanced(
|
|
8687
8907
|
drawMode,
|
|
@@ -8806,7 +9026,7 @@ ${formattedLog}`)();
|
|
|
8806
9026
|
type,
|
|
8807
9027
|
textureUnit
|
|
8808
9028
|
} = uniformLayout;
|
|
8809
|
-
const value = this.uniforms[name]
|
|
9029
|
+
const value = this.uniforms[name] ?? textureUnit;
|
|
8810
9030
|
if (value !== void 0) {
|
|
8811
9031
|
setUniform(this.device.gl, location, type, value);
|
|
8812
9032
|
}
|
|
@@ -8857,6 +9077,257 @@ ${formattedLog}`)();
|
|
|
8857
9077
|
return layout.attributes.find((binding) => binding.name === name) || null;
|
|
8858
9078
|
}
|
|
8859
9079
|
|
|
9080
|
+
// src/adapter/resources/webgl-command-buffer.ts
|
|
9081
|
+
function cast2(value) {
|
|
9082
|
+
return value;
|
|
9083
|
+
}
|
|
9084
|
+
var WEBGLCommandBuffer = class extends CommandBuffer {
|
|
9085
|
+
commands = [];
|
|
9086
|
+
constructor(device) {
|
|
9087
|
+
super({});
|
|
9088
|
+
this.device = device;
|
|
9089
|
+
}
|
|
9090
|
+
submitCommands(commands = this.commands) {
|
|
9091
|
+
for (const command of commands) {
|
|
9092
|
+
switch (command.name) {
|
|
9093
|
+
case "copy-buffer-to-buffer":
|
|
9094
|
+
_copyBufferToBuffer(this.device, command.options);
|
|
9095
|
+
break;
|
|
9096
|
+
case "copy-buffer-to-texture":
|
|
9097
|
+
_copyBufferToTexture(this.device, command.options);
|
|
9098
|
+
break;
|
|
9099
|
+
case "copy-texture-to-buffer":
|
|
9100
|
+
_copyTextureToBuffer(this.device, command.options);
|
|
9101
|
+
break;
|
|
9102
|
+
case "copy-texture-to-texture":
|
|
9103
|
+
_copyTextureToTexture(this.device, command.options);
|
|
9104
|
+
break;
|
|
9105
|
+
}
|
|
9106
|
+
}
|
|
9107
|
+
}
|
|
9108
|
+
};
|
|
9109
|
+
function _copyBufferToBuffer(device, options) {
|
|
9110
|
+
const source = cast2(options.source);
|
|
9111
|
+
const destination = cast2(options.destination);
|
|
9112
|
+
const gl2 = device.assertWebGL2();
|
|
9113
|
+
if (gl2) {
|
|
9114
|
+
gl2.bindBuffer(GL.COPY_READ_BUFFER, source.handle);
|
|
9115
|
+
gl2.bindBuffer(GL.COPY_WRITE_BUFFER, destination.handle);
|
|
9116
|
+
gl2.copyBufferSubData(GL.COPY_READ_BUFFER, GL.COPY_WRITE_BUFFER, options.sourceOffset ?? 0, options.destinationOffset ?? 0, options.size);
|
|
9117
|
+
gl2.bindBuffer(GL.COPY_READ_BUFFER, null);
|
|
9118
|
+
gl2.bindBuffer(GL.COPY_WRITE_BUFFER, null);
|
|
9119
|
+
} else {
|
|
9120
|
+
throw new Error("copyBufferToBuffer not implemented in WebGL1");
|
|
9121
|
+
}
|
|
9122
|
+
}
|
|
9123
|
+
function _copyBufferToTexture(device, options) {
|
|
9124
|
+
throw new Error("Not implemented");
|
|
9125
|
+
}
|
|
9126
|
+
function _copyTextureToBuffer(device, options) {
|
|
9127
|
+
const {
|
|
9128
|
+
/** Texture to copy to/from. */
|
|
9129
|
+
source,
|
|
9130
|
+
/** Mip-map level of the texture to copy to/from. (Default 0) */
|
|
9131
|
+
mipLevel = 0,
|
|
9132
|
+
/** Defines which aspects of the texture to copy to/from. */
|
|
9133
|
+
aspect = "all",
|
|
9134
|
+
/** Width to copy */
|
|
9135
|
+
width = options.source.width,
|
|
9136
|
+
/** Height to copy */
|
|
9137
|
+
height = options.source.height,
|
|
9138
|
+
depthOrArrayLayers = 0,
|
|
9139
|
+
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
|
|
9140
|
+
origin = [0, 0],
|
|
9141
|
+
/** Destination buffer */
|
|
9142
|
+
destination,
|
|
9143
|
+
/** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */
|
|
9144
|
+
byteOffset = 0,
|
|
9145
|
+
/**
|
|
9146
|
+
* The stride, in bytes, between the beginning of each block row and the subsequent block row.
|
|
9147
|
+
* Required if there are multiple block rows (i.e. the copy height or depth is more than one block).
|
|
9148
|
+
*/
|
|
9149
|
+
bytesPerRow,
|
|
9150
|
+
/**
|
|
9151
|
+
* Number of block rows per single image of the texture.
|
|
9152
|
+
* rowsPerImage × bytesPerRow is the stride, in bytes, between the beginning of each image of data and the subsequent image.
|
|
9153
|
+
* Required if there are multiple images (i.e. the copy depth is more than one).
|
|
9154
|
+
*/
|
|
9155
|
+
rowsPerImage
|
|
9156
|
+
} = options;
|
|
9157
|
+
if (aspect !== "all") {
|
|
9158
|
+
throw new Error("not supported");
|
|
9159
|
+
}
|
|
9160
|
+
if (mipLevel !== 0 || depthOrArrayLayers !== void 0 || bytesPerRow || rowsPerImage) {
|
|
9161
|
+
throw new Error("not implemented");
|
|
9162
|
+
}
|
|
9163
|
+
const gl2 = device.assertWebGL2();
|
|
9164
|
+
const {
|
|
9165
|
+
framebuffer,
|
|
9166
|
+
destroyFramebuffer
|
|
9167
|
+
} = getFramebuffer(source);
|
|
9168
|
+
try {
|
|
9169
|
+
const webglBuffer = destination;
|
|
9170
|
+
const sourceWidth = width || framebuffer.width;
|
|
9171
|
+
const sourceHeight = height || framebuffer.height;
|
|
9172
|
+
const sourceFormat = GL.RGBA;
|
|
9173
|
+
const sourceType = GL.UNSIGNED_BYTE;
|
|
9174
|
+
gl2.bindBuffer(GL.PIXEL_PACK_BUFFER, webglBuffer.handle);
|
|
9175
|
+
gl2.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);
|
|
9176
|
+
gl2.readPixels(origin[0], origin[1], sourceWidth, sourceHeight, sourceFormat, sourceType, byteOffset);
|
|
9177
|
+
} finally {
|
|
9178
|
+
gl2.bindBuffer(GL.PIXEL_PACK_BUFFER, null);
|
|
9179
|
+
gl2.bindFramebuffer(GL.FRAMEBUFFER, null);
|
|
9180
|
+
if (destroyFramebuffer) {
|
|
9181
|
+
framebuffer.destroy();
|
|
9182
|
+
}
|
|
9183
|
+
}
|
|
9184
|
+
}
|
|
9185
|
+
function _copyTextureToTexture(device, options) {
|
|
9186
|
+
const {
|
|
9187
|
+
/** Texture to copy to/from. */
|
|
9188
|
+
source,
|
|
9189
|
+
/** Mip-map level of the texture to copy to/from. (Default 0) */
|
|
9190
|
+
// mipLevel = 0,
|
|
9191
|
+
/** Defines which aspects of the texture to copy to/from. */
|
|
9192
|
+
// aspect = 'all',
|
|
9193
|
+
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
|
|
9194
|
+
origin = [0, 0],
|
|
9195
|
+
/** Texture to copy to/from. */
|
|
9196
|
+
destination
|
|
9197
|
+
/** Mip-map level of the texture to copy to/from. (Default 0) */
|
|
9198
|
+
// destinationMipLevel = options.mipLevel,
|
|
9199
|
+
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
|
|
9200
|
+
// destinationOrigin = [0, 0],
|
|
9201
|
+
/** Defines which aspects of the texture to copy to/from. */
|
|
9202
|
+
// destinationAspect = options.aspect,
|
|
9203
|
+
} = options;
|
|
9204
|
+
let {
|
|
9205
|
+
width = options.destination.width,
|
|
9206
|
+
height = options.destination.width
|
|
9207
|
+
// depthOrArrayLayers = 0
|
|
9208
|
+
} = options;
|
|
9209
|
+
const destinationMipmaplevel = 0;
|
|
9210
|
+
const destinationInternalFormat = GL.RGBA;
|
|
9211
|
+
const {
|
|
9212
|
+
framebuffer,
|
|
9213
|
+
destroyFramebuffer
|
|
9214
|
+
} = getFramebuffer(source);
|
|
9215
|
+
const [sourceX, sourceY] = origin;
|
|
9216
|
+
const isSubCopy = false;
|
|
9217
|
+
device.gl.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);
|
|
9218
|
+
let texture = null;
|
|
9219
|
+
let textureTarget;
|
|
9220
|
+
if (destination instanceof WEBGLTexture) {
|
|
9221
|
+
texture = destination;
|
|
9222
|
+
width = Number.isFinite(width) ? width : texture.width;
|
|
9223
|
+
height = Number.isFinite(height) ? height : texture.height;
|
|
9224
|
+
texture.bind(0);
|
|
9225
|
+
textureTarget = texture.destination;
|
|
9226
|
+
} else {
|
|
9227
|
+
throw new Error("whoops");
|
|
9228
|
+
}
|
|
9229
|
+
if (!isSubCopy) {
|
|
9230
|
+
device.gl.copyTexImage2D(
|
|
9231
|
+
textureTarget,
|
|
9232
|
+
destinationMipmaplevel,
|
|
9233
|
+
destinationInternalFormat,
|
|
9234
|
+
sourceX,
|
|
9235
|
+
sourceY,
|
|
9236
|
+
width,
|
|
9237
|
+
height,
|
|
9238
|
+
0
|
|
9239
|
+
/* border must be 0 */
|
|
9240
|
+
);
|
|
9241
|
+
} else {
|
|
9242
|
+
}
|
|
9243
|
+
if (texture) {
|
|
9244
|
+
texture.unbind();
|
|
9245
|
+
}
|
|
9246
|
+
device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
|
|
9247
|
+
if (destroyFramebuffer) {
|
|
9248
|
+
framebuffer.destroy();
|
|
9249
|
+
}
|
|
9250
|
+
return texture;
|
|
9251
|
+
}
|
|
9252
|
+
function getFramebuffer(source) {
|
|
9253
|
+
if (source instanceof Texture) {
|
|
9254
|
+
const {
|
|
9255
|
+
width,
|
|
9256
|
+
height,
|
|
9257
|
+
id
|
|
9258
|
+
} = source;
|
|
9259
|
+
const framebuffer = source.device.createFramebuffer({
|
|
9260
|
+
id: `framebuffer-for-${id}`,
|
|
9261
|
+
width,
|
|
9262
|
+
height,
|
|
9263
|
+
colorAttachments: [source]
|
|
9264
|
+
});
|
|
9265
|
+
return {
|
|
9266
|
+
framebuffer,
|
|
9267
|
+
destroyFramebuffer: true
|
|
9268
|
+
};
|
|
9269
|
+
}
|
|
9270
|
+
return {
|
|
9271
|
+
framebuffer: source,
|
|
9272
|
+
destroyFramebuffer: false
|
|
9273
|
+
};
|
|
9274
|
+
}
|
|
9275
|
+
|
|
9276
|
+
// src/adapter/resources/webgl-command-encoder.ts
|
|
9277
|
+
var WEBGLCommandEncoder = class extends CommandEncoder {
|
|
9278
|
+
constructor(device, props) {
|
|
9279
|
+
super(props);
|
|
9280
|
+
this.device = device;
|
|
9281
|
+
this.commandBuffer = new WEBGLCommandBuffer(device);
|
|
9282
|
+
}
|
|
9283
|
+
destroy() {
|
|
9284
|
+
}
|
|
9285
|
+
finish() {
|
|
9286
|
+
this.commandBuffer.submitCommands();
|
|
9287
|
+
}
|
|
9288
|
+
// beginRenderPass(GPURenderPassDescriptor descriptor): GPURenderPassEncoder;
|
|
9289
|
+
// beginComputePass(optional GPUComputePassDescriptor descriptor = {}): GPUComputePassEncoder;
|
|
9290
|
+
// finish(options?: {id?: string}): GPUCommandBuffer;
|
|
9291
|
+
copyBufferToBuffer(options) {
|
|
9292
|
+
this.commandBuffer.commands.push({
|
|
9293
|
+
name: "copy-buffer-to-buffer",
|
|
9294
|
+
options
|
|
9295
|
+
});
|
|
9296
|
+
}
|
|
9297
|
+
copyBufferToTexture(options) {
|
|
9298
|
+
this.commandBuffer.commands.push({
|
|
9299
|
+
name: "copy-buffer-to-texture",
|
|
9300
|
+
options
|
|
9301
|
+
});
|
|
9302
|
+
}
|
|
9303
|
+
copyTextureToBuffer(options) {
|
|
9304
|
+
this.commandBuffer.commands.push({
|
|
9305
|
+
name: "copy-texture-to-buffer",
|
|
9306
|
+
options
|
|
9307
|
+
});
|
|
9308
|
+
}
|
|
9309
|
+
copyTextureToTexture(options) {
|
|
9310
|
+
this.commandBuffer.commands.push({
|
|
9311
|
+
name: "copy-texture-to-texture",
|
|
9312
|
+
options
|
|
9313
|
+
});
|
|
9314
|
+
}
|
|
9315
|
+
pushDebugGroup(groupLabel) {
|
|
9316
|
+
}
|
|
9317
|
+
popDebugGroup() {
|
|
9318
|
+
}
|
|
9319
|
+
insertDebugMarker(markerLabel) {
|
|
9320
|
+
}
|
|
9321
|
+
// writeTimestamp(querySet: Query, queryIndex: number): void {}
|
|
9322
|
+
// resolveQuerySet(options: {
|
|
9323
|
+
// querySet: GPUQuerySet,
|
|
9324
|
+
// firstQuery: number,
|
|
9325
|
+
// queryCount: number,
|
|
9326
|
+
// destination: Buffer,
|
|
9327
|
+
// destinationOffset?: number;
|
|
9328
|
+
// }): void;
|
|
9329
|
+
};
|
|
9330
|
+
|
|
8860
9331
|
// src/adapter/webgl-device.ts
|
|
8861
9332
|
var LOG_LEVEL2 = 1;
|
|
8862
9333
|
var _WebGLDevice = class extends Device {
|
|
@@ -9020,8 +9491,9 @@ ${formattedLog}`)();
|
|
|
9020
9491
|
createCanvasContext(props) {
|
|
9021
9492
|
throw new Error("WebGL only supports a single canvas");
|
|
9022
9493
|
}
|
|
9023
|
-
|
|
9024
|
-
|
|
9494
|
+
createBuffer(props) {
|
|
9495
|
+
const newProps = this._getBufferProps(props);
|
|
9496
|
+
return new ClassicBuffer(this, newProps);
|
|
9025
9497
|
}
|
|
9026
9498
|
_createTexture(props) {
|
|
9027
9499
|
return new WEBGLTexture(this, props);
|
|
@@ -9057,6 +9529,9 @@ ${formattedLog}`)();
|
|
|
9057
9529
|
});
|
|
9058
9530
|
return this.renderPass;
|
|
9059
9531
|
}
|
|
9532
|
+
createCommandEncoder(props) {
|
|
9533
|
+
return new WEBGLCommandEncoder(this, props);
|
|
9534
|
+
}
|
|
9060
9535
|
/**
|
|
9061
9536
|
* Offscreen Canvas Support: Commit the frame
|
|
9062
9537
|
* https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/commit
|
|
@@ -9091,19 +9566,21 @@ ${formattedLog}`)();
|
|
|
9091
9566
|
return this._webglLimits;
|
|
9092
9567
|
}
|
|
9093
9568
|
/**
|
|
9094
|
-
*
|
|
9095
|
-
* @note
|
|
9096
|
-
* @todo Promote to `Device` API?
|
|
9569
|
+
* Triggers device (or WebGL context) loss.
|
|
9570
|
+
* @note primarily intended for testing how application reacts to device loss
|
|
9097
9571
|
*/
|
|
9098
9572
|
loseDevice() {
|
|
9573
|
+
let deviceLossTriggered = false;
|
|
9099
9574
|
const ext = this.gl.getExtension("WEBGL_lose_context");
|
|
9100
9575
|
if (ext) {
|
|
9576
|
+
deviceLossTriggered = true;
|
|
9101
9577
|
ext.loseContext();
|
|
9102
9578
|
}
|
|
9103
9579
|
this._resolveContextLost?.({
|
|
9104
9580
|
reason: "destroyed",
|
|
9105
9581
|
message: "Application triggered context loss"
|
|
9106
9582
|
});
|
|
9583
|
+
return deviceLossTriggered;
|
|
9107
9584
|
}
|
|
9108
9585
|
/** Save current WebGL context state onto an internal stack */
|
|
9109
9586
|
pushState() {
|
|
@@ -9120,6 +9597,21 @@ ${formattedLog}`)();
|
|
|
9120
9597
|
setSpectorMetadata(handle, props) {
|
|
9121
9598
|
handle.__SPECTOR_Metadata = props;
|
|
9122
9599
|
}
|
|
9600
|
+
/**
|
|
9601
|
+
* Returns the GL.<KEY> constant that corresponds to a numeric value of a GL constant
|
|
9602
|
+
* Be aware that there are some duplicates especially for constants that are 0,
|
|
9603
|
+
* so this isn't guaranteed to return the right key in all cases.
|
|
9604
|
+
*/
|
|
9605
|
+
getGLKey(value, gl) {
|
|
9606
|
+
gl = gl || this.gl2 || this.gl;
|
|
9607
|
+
const number = Number(value);
|
|
9608
|
+
for (const key in gl) {
|
|
9609
|
+
if (gl[key] === number) {
|
|
9610
|
+
return `GL.${key}`;
|
|
9611
|
+
}
|
|
9612
|
+
}
|
|
9613
|
+
return String(value);
|
|
9614
|
+
}
|
|
9123
9615
|
};
|
|
9124
9616
|
var WebGLDevice = _WebGLDevice;
|
|
9125
9617
|
//
|
|
@@ -9142,62 +9634,217 @@ ${formattedLog}`)();
|
|
|
9142
9634
|
return Boolean(gl && gl._version === 2);
|
|
9143
9635
|
}
|
|
9144
9636
|
|
|
9145
|
-
// src/
|
|
9146
|
-
var
|
|
9147
|
-
|
|
9148
|
-
|
|
9149
|
-
|
|
9150
|
-
|
|
9151
|
-
|
|
9152
|
-
|
|
9153
|
-
|
|
9154
|
-
|
|
9155
|
-
|
|
9637
|
+
// src/classic/clear.ts
|
|
9638
|
+
var GL_DEPTH_BUFFER_BIT2 = 256;
|
|
9639
|
+
var GL_STENCIL_BUFFER_BIT2 = 1024;
|
|
9640
|
+
var GL_COLOR_BUFFER_BIT2 = 16384;
|
|
9641
|
+
var ERR_ARGUMENTS = "clear: bad arguments";
|
|
9642
|
+
function clear(gl, options) {
|
|
9643
|
+
const device = WebGLDevice.attach(gl);
|
|
9644
|
+
const {
|
|
9645
|
+
framebuffer = null,
|
|
9646
|
+
color = null,
|
|
9647
|
+
depth = null,
|
|
9648
|
+
stencil = null
|
|
9649
|
+
} = options || {};
|
|
9650
|
+
const parameters = {};
|
|
9651
|
+
if (framebuffer) {
|
|
9652
|
+
parameters.framebuffer = framebuffer;
|
|
9156
9653
|
}
|
|
9157
|
-
|
|
9654
|
+
let clearFlags = 0;
|
|
9655
|
+
if (color) {
|
|
9656
|
+
clearFlags |= GL_COLOR_BUFFER_BIT2;
|
|
9657
|
+
if (color !== true) {
|
|
9658
|
+
parameters.clearColor = color;
|
|
9659
|
+
}
|
|
9158
9660
|
}
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
name: "copy-buffer-to-buffer",
|
|
9165
|
-
options
|
|
9166
|
-
});
|
|
9661
|
+
if (depth) {
|
|
9662
|
+
clearFlags |= GL_DEPTH_BUFFER_BIT2;
|
|
9663
|
+
if (depth !== true) {
|
|
9664
|
+
parameters.clearDepth = depth;
|
|
9665
|
+
}
|
|
9167
9666
|
}
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9171
|
-
|
|
9172
|
-
}
|
|
9667
|
+
if (stencil) {
|
|
9668
|
+
clearFlags |= GL_STENCIL_BUFFER_BIT2;
|
|
9669
|
+
if (depth !== true) {
|
|
9670
|
+
parameters.clearStencil = depth;
|
|
9671
|
+
}
|
|
9173
9672
|
}
|
|
9174
|
-
|
|
9175
|
-
|
|
9176
|
-
|
|
9177
|
-
|
|
9178
|
-
|
|
9673
|
+
assert2(clearFlags !== 0, ERR_ARGUMENTS);
|
|
9674
|
+
withParameters(device.gl, parameters, () => {
|
|
9675
|
+
device.gl.clear(clearFlags);
|
|
9676
|
+
});
|
|
9677
|
+
}
|
|
9678
|
+
|
|
9679
|
+
// src/classic/format-utils.ts
|
|
9680
|
+
function glFormatToComponents(format) {
|
|
9681
|
+
switch (format) {
|
|
9682
|
+
case GL.ALPHA:
|
|
9683
|
+
case GL.R32F:
|
|
9684
|
+
case GL.RED:
|
|
9685
|
+
return 1;
|
|
9686
|
+
case GL.RG32F:
|
|
9687
|
+
case GL.RG:
|
|
9688
|
+
return 2;
|
|
9689
|
+
case GL.RGB:
|
|
9690
|
+
case GL.RGB32F:
|
|
9691
|
+
return 3;
|
|
9692
|
+
case GL.RGBA:
|
|
9693
|
+
case GL.RGBA32F:
|
|
9694
|
+
return 4;
|
|
9695
|
+
default:
|
|
9696
|
+
assert2(false);
|
|
9697
|
+
return 0;
|
|
9179
9698
|
}
|
|
9180
|
-
|
|
9181
|
-
|
|
9182
|
-
|
|
9183
|
-
|
|
9699
|
+
}
|
|
9700
|
+
function glTypeToBytes(type) {
|
|
9701
|
+
switch (type) {
|
|
9702
|
+
case GL.UNSIGNED_BYTE:
|
|
9703
|
+
return 1;
|
|
9704
|
+
case GL.UNSIGNED_SHORT_5_6_5:
|
|
9705
|
+
case GL.UNSIGNED_SHORT_4_4_4_4:
|
|
9706
|
+
case GL.UNSIGNED_SHORT_5_5_5_1:
|
|
9707
|
+
return 2;
|
|
9708
|
+
case GL.FLOAT:
|
|
9709
|
+
return 4;
|
|
9710
|
+
default:
|
|
9711
|
+
assert2(false);
|
|
9712
|
+
return 0;
|
|
9713
|
+
}
|
|
9714
|
+
}
|
|
9715
|
+
|
|
9716
|
+
// src/classic/copy-and-blit.ts
|
|
9717
|
+
function readPixelsToArray(source, options) {
|
|
9718
|
+
const {
|
|
9719
|
+
sourceX = 0,
|
|
9720
|
+
sourceY = 0,
|
|
9721
|
+
sourceFormat = GL.RGBA
|
|
9722
|
+
} = options || {};
|
|
9723
|
+
let {
|
|
9724
|
+
sourceAttachment = GL.COLOR_ATTACHMENT0,
|
|
9725
|
+
// TODO - support gl.readBuffer
|
|
9726
|
+
target = null,
|
|
9727
|
+
// following parameters are auto deduced if not provided
|
|
9728
|
+
sourceWidth,
|
|
9729
|
+
sourceHeight,
|
|
9730
|
+
sourceType
|
|
9731
|
+
} = options || {};
|
|
9732
|
+
const {
|
|
9733
|
+
framebuffer,
|
|
9734
|
+
deleteFramebuffer
|
|
9735
|
+
} = getFramebuffer2(source);
|
|
9736
|
+
assert2(framebuffer);
|
|
9737
|
+
const {
|
|
9738
|
+
gl,
|
|
9739
|
+
handle
|
|
9740
|
+
} = framebuffer;
|
|
9741
|
+
sourceWidth = sourceWidth || framebuffer.width;
|
|
9742
|
+
sourceHeight = sourceHeight || framebuffer.height;
|
|
9743
|
+
if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {
|
|
9744
|
+
sourceAttachment = GL.FRONT;
|
|
9745
|
+
}
|
|
9746
|
+
const attachment = sourceAttachment - GL.COLOR_ATTACHMENT0;
|
|
9747
|
+
sourceType = sourceType || framebuffer.colorAttachments[attachment].type;
|
|
9748
|
+
target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
|
|
9749
|
+
sourceType = sourceType || getGLTypeFromTypedArray(target);
|
|
9750
|
+
const prevHandle2 = gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
|
|
9751
|
+
gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
|
|
9752
|
+
gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle2 || null);
|
|
9753
|
+
if (deleteFramebuffer) {
|
|
9754
|
+
framebuffer.destroy();
|
|
9755
|
+
}
|
|
9756
|
+
return target;
|
|
9757
|
+
}
|
|
9758
|
+
function readPixelsToBuffer(source, options) {
|
|
9759
|
+
const {
|
|
9760
|
+
sourceX = 0,
|
|
9761
|
+
sourceY = 0,
|
|
9762
|
+
sourceFormat = GL.RGBA,
|
|
9763
|
+
targetByteOffset = 0
|
|
9764
|
+
} = options || {};
|
|
9765
|
+
let {
|
|
9766
|
+
target,
|
|
9767
|
+
sourceWidth,
|
|
9768
|
+
sourceHeight,
|
|
9769
|
+
sourceType
|
|
9770
|
+
} = options || {};
|
|
9771
|
+
const {
|
|
9772
|
+
framebuffer,
|
|
9773
|
+
deleteFramebuffer
|
|
9774
|
+
} = getFramebuffer2(source);
|
|
9775
|
+
assert2(framebuffer);
|
|
9776
|
+
sourceWidth = sourceWidth || framebuffer.width;
|
|
9777
|
+
sourceHeight = sourceHeight || framebuffer.height;
|
|
9778
|
+
const webglFramebuffer = framebuffer;
|
|
9779
|
+
const gl2 = webglFramebuffer.device.assertWebGL2();
|
|
9780
|
+
sourceType = sourceType || (target ? target.type : GL.UNSIGNED_BYTE);
|
|
9781
|
+
if (!target) {
|
|
9782
|
+
const components = glFormatToComponents(sourceFormat);
|
|
9783
|
+
const byteCount = glTypeToBytes(sourceType);
|
|
9784
|
+
const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
|
|
9785
|
+
target = new ClassicBuffer(gl2, {
|
|
9786
|
+
byteLength,
|
|
9787
|
+
accessor: {
|
|
9788
|
+
type: sourceType,
|
|
9789
|
+
size: components
|
|
9790
|
+
}
|
|
9184
9791
|
});
|
|
9185
9792
|
}
|
|
9186
|
-
|
|
9793
|
+
target.bind({
|
|
9794
|
+
target: GL.PIXEL_PACK_BUFFER
|
|
9795
|
+
});
|
|
9796
|
+
withParameters(gl2, {
|
|
9797
|
+
framebuffer
|
|
9798
|
+
}, () => {
|
|
9799
|
+
gl2.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, targetByteOffset);
|
|
9800
|
+
});
|
|
9801
|
+
target.unbind({
|
|
9802
|
+
target: GL.PIXEL_PACK_BUFFER
|
|
9803
|
+
});
|
|
9804
|
+
if (deleteFramebuffer) {
|
|
9805
|
+
framebuffer.destroy();
|
|
9187
9806
|
}
|
|
9188
|
-
|
|
9807
|
+
return target;
|
|
9808
|
+
}
|
|
9809
|
+
function getFramebuffer2(source) {
|
|
9810
|
+
if (!(source instanceof Framebuffer)) {
|
|
9811
|
+
return {
|
|
9812
|
+
framebuffer: toFramebuffer(source),
|
|
9813
|
+
deleteFramebuffer: true
|
|
9814
|
+
};
|
|
9189
9815
|
}
|
|
9190
|
-
|
|
9816
|
+
return {
|
|
9817
|
+
framebuffer: source,
|
|
9818
|
+
deleteFramebuffer: false
|
|
9819
|
+
};
|
|
9820
|
+
}
|
|
9821
|
+
function toFramebuffer(texture, props) {
|
|
9822
|
+
const {
|
|
9823
|
+
device,
|
|
9824
|
+
width,
|
|
9825
|
+
height,
|
|
9826
|
+
id
|
|
9827
|
+
} = texture;
|
|
9828
|
+
const framebuffer = device.createFramebuffer({
|
|
9829
|
+
...props,
|
|
9830
|
+
id: `framebuffer-for-${id}`,
|
|
9831
|
+
width,
|
|
9832
|
+
height,
|
|
9833
|
+
colorAttachments: [texture]
|
|
9834
|
+
});
|
|
9835
|
+
return framebuffer;
|
|
9836
|
+
}
|
|
9837
|
+
function getPixelArray(pixelArray, type, format, width, height) {
|
|
9838
|
+
if (pixelArray) {
|
|
9839
|
+
return pixelArray;
|
|
9191
9840
|
}
|
|
9192
|
-
|
|
9193
|
-
|
|
9194
|
-
|
|
9195
|
-
|
|
9196
|
-
|
|
9197
|
-
|
|
9198
|
-
|
|
9199
|
-
// }): void;
|
|
9200
|
-
};
|
|
9841
|
+
type = type || GL.UNSIGNED_BYTE;
|
|
9842
|
+
const ArrayType = getTypedArrayFromGLType(type, {
|
|
9843
|
+
clamped: false
|
|
9844
|
+
});
|
|
9845
|
+
const components = glFormatToComponents(format);
|
|
9846
|
+
return new ArrayType(width * height * components);
|
|
9847
|
+
}
|
|
9201
9848
|
return __toCommonJS(src_exports);
|
|
9202
9849
|
})();
|
|
9203
9850
|
return __exports__;
|