@luma.gl/webgl 9.0.17 → 9.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/device-parameters.js +30 -12
- package/dist/adapter/converters/texture-formats.d.ts +22 -16
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +39 -47
- package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-features.js +1 -2
- package/dist/adapter/device-helpers/webgl-device-limits.js +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.d.ts +300 -0
- package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -0
- package/dist/adapter/helpers/webgl-texture-utils.js +370 -0
- package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.js +0 -4
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +2 -2
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +6 -9
- package/dist/adapter/resources/webgl-framebuffer.d.ts +32 -5
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +42 -60
- package/dist/adapter/resources/webgl-render-pass.d.ts +3 -2
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +18 -7
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +46 -21
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +3 -3
- package/dist/adapter/resources/webgl-texture-view.d.ts +1 -1
- package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture-view.js +1 -1
- package/dist/adapter/resources/webgl-texture.d.ts +76 -172
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +397 -511
- package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -2
- package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-vertex-array.js +2 -2
- package/dist/adapter/webgl-adapter.d.ts +21 -0
- package/dist/adapter/webgl-adapter.d.ts.map +1 -0
- package/dist/adapter/webgl-adapter.js +91 -0
- package/dist/adapter/webgl-canvas-context.d.ts +3 -1
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +2 -0
- package/dist/adapter/webgl-device.d.ts +19 -30
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +35 -114
- package/dist/classic/accessor.d.ts +22 -1
- package/dist/classic/accessor.d.ts.map +1 -1
- package/dist/classic/accessor.js +1 -9
- package/dist/classic/clear.d.ts.map +1 -1
- package/dist/classic/clear.js +2 -5
- package/dist/classic/copy-and-blit.d.ts +3 -1
- package/dist/classic/copy-and-blit.d.ts.map +1 -1
- package/dist/classic/copy-and-blit.js +21 -18
- package/dist/classic/format-utils.d.ts.map +1 -1
- package/dist/classic/format-utils.js +0 -3
- package/dist/classic/typed-array-utils.d.ts +1 -1
- package/dist/classic/typed-array-utils.d.ts.map +1 -1
- package/dist/context/debug/spector-types.d.ts +1108 -0
- package/dist/context/debug/spector-types.d.ts.map +1 -0
- package/dist/context/debug/spector-types.js +697 -0
- package/dist/context/debug/spector.d.ts +12 -8
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/spector.js +25 -18
- 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/debug/webgl-developer-tools.js +2 -5
- package/dist/context/parameters/webgl-parameter-tables.js +1 -1
- package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts +9 -0
- package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts.map +1 -0
- package/dist/context/polyfills/polyfill-webgl1-extensions.js +181 -0
- package/dist/context/state-tracker/webgl-state-tracker.d.ts +43 -0
- package/dist/context/state-tracker/webgl-state-tracker.d.ts.map +1 -0
- package/dist/context/state-tracker/{track-context-state.js → webgl-state-tracker.js} +46 -77
- package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
- package/dist/context/state-tracker/with-parameters.js +5 -4
- package/dist/dist.dev.js +1112 -1380
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +1122 -1284
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5
- package/dist/utils/fill-array.d.ts +8 -0
- package/dist/utils/fill-array.d.ts.map +1 -0
- package/dist/utils/fill-array.js +26 -0
- package/dist/utils/load-script.d.ts +8 -0
- package/dist/utils/load-script.d.ts.map +1 -0
- package/dist/utils/load-script.js +26 -0
- package/dist/utils/split-uniforms-and-bindings.d.ts +9 -0
- package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -0
- package/dist/utils/split-uniforms-and-bindings.js +20 -0
- package/dist/utils/uid.d.ts +7 -0
- package/dist/utils/uid.d.ts.map +1 -0
- package/dist/utils/uid.js +14 -0
- package/package.json +6 -5
- package/src/adapter/converters/device-parameters.ts +31 -13
- package/src/adapter/converters/texture-formats.ts +51 -56
- package/src/adapter/device-helpers/webgl-device-features.ts +1 -2
- package/src/adapter/device-helpers/webgl-device-limits.ts +1 -1
- package/src/adapter/helpers/webgl-texture-utils.ts +484 -0
- package/src/adapter/helpers/webgl-topology-utils.ts +0 -4
- package/src/adapter/resources/webgl-buffer.ts +2 -2
- package/src/adapter/resources/webgl-command-buffer.ts +8 -10
- package/src/adapter/resources/webgl-framebuffer.ts +22 -56
- package/src/adapter/resources/webgl-render-pass.ts +21 -9
- package/src/adapter/resources/webgl-render-pipeline.ts +50 -24
- package/src/adapter/resources/webgl-shader.ts +4 -4
- package/src/adapter/resources/webgl-texture-view.ts +1 -3
- package/src/adapter/resources/webgl-texture.ts +445 -784
- package/src/adapter/resources/webgl-vertex-array.ts +8 -7
- package/src/adapter/webgl-adapter.ts +113 -0
- package/src/adapter/webgl-canvas-context.ts +4 -1
- package/src/adapter/webgl-device.ts +40 -151
- package/src/classic/accessor.ts +31 -11
- package/src/classic/clear.ts +3 -6
- package/src/classic/copy-and-blit.ts +32 -27
- package/src/classic/format-utils.ts +0 -3
- package/src/classic/typed-array-utils.ts +1 -1
- package/src/context/debug/spector-types.ts +1154 -0
- package/src/context/debug/spector.ts +40 -30
- package/src/context/debug/webgl-developer-tools.ts +3 -7
- package/src/context/parameters/webgl-parameter-tables.ts +3 -3
- package/src/context/polyfills/polyfill-webgl1-extensions.ts +202 -0
- package/src/context/state-tracker/{track-context-state.ts → webgl-state-tracker.ts} +57 -97
- package/src/context/state-tracker/with-parameters.ts +5 -4
- package/src/index.ts +5 -13
- package/src/utils/fill-array.ts +35 -0
- package/src/utils/load-script.ts +30 -0
- package/src/utils/split-uniforms-and-bindings.ts +31 -0
- package/src/utils/uid.ts +16 -0
- package/dist/adapter/objects/constants-to-keys.d.ts +0 -3
- package/dist/adapter/objects/constants-to-keys.d.ts.map +0 -1
- package/dist/adapter/objects/constants-to-keys.js +0 -22
- package/dist/adapter/objects/webgl-renderbuffer.d.ts +0 -43
- package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +0 -1
- package/dist/adapter/objects/webgl-renderbuffer.js +0 -95
- package/dist/adapter/objects/webgl-resource.d.ts +0 -32
- package/dist/adapter/objects/webgl-resource.d.ts.map +0 -1
- package/dist/adapter/objects/webgl-resource.js +0 -114
- package/dist/context/state-tracker/track-context-state.d.ts +0 -22
- package/dist/context/state-tracker/track-context-state.d.ts.map +0 -1
- package/src/adapter/objects/constants-to-keys.ts +0 -27
- package/src/adapter/objects/webgl-renderbuffer.ts +0 -132
- package/src/adapter/objects/webgl-resource.ts +0 -183
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device-parameters.d.ts","sourceRoot":"","sources":["../../../src/adapter/converters/device-parameters.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,eAAe,EAAgD,MAAM,eAAe,CAAC;AAClG,OAAO,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"device-parameters.d.ts","sourceRoot":"","sources":["../../../src/adapter/converters/device-parameters.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,eAAe,EAAgD,MAAM,eAAe,CAAC;AAClG,OAAO,EAAC,MAAM,EAAO,UAAU,EAA+B,MAAM,eAAe,CAAC;AAEpF,OAAO,KAAK,EAGV,UAAU,EACV,YAAY,EAIb,MAAM,oBAAoB,CAAC;AAM5B;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,GAAG,OAAO,EACnD,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,YAAY,EAC1B,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,CAAC,GAC3B,CAAC,CAgBH;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,GAAG,OAAO,EAC1C,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,YAAY,EACxB,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,CAAC,GAC3B,CAAC,CAeH;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,GAAG,OAAO,EAC9C,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,CAAC,GAC3B,CAAC,CAeH;AAED,kCAAkC;AAClC,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,QAgNzE;AAyBD,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,GAAG,UAAU,CAW5F;AAED,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,eAAe,CAW9F"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { log
|
|
4
|
+
import { log } from '@luma.gl/core';
|
|
5
5
|
import { GL } from '@luma.gl/constants';
|
|
6
|
-
import { pushContextState, popContextState } from "../../context/state-tracker/track-context-state.js";
|
|
7
6
|
import { setGLParameters } from "../../context/parameters/unified-parameter-api.js";
|
|
8
7
|
/* eslint-disable no-unused-expressions */ // For expression ? gl.enable() : gl.disable()
|
|
9
8
|
/**
|
|
@@ -21,14 +20,14 @@ export function withDeviceAndGLParameters(device, parameters, glParameters, func
|
|
|
21
20
|
}
|
|
22
21
|
// Wrap in a try-catch to ensure that parameters are restored on exceptions
|
|
23
22
|
const webglDevice = device;
|
|
24
|
-
|
|
23
|
+
webglDevice.pushState();
|
|
25
24
|
try {
|
|
26
25
|
setDeviceParameters(device, parameters);
|
|
27
26
|
setGLParameters(webglDevice.gl, glParameters);
|
|
28
27
|
return func(device);
|
|
29
28
|
}
|
|
30
29
|
finally {
|
|
31
|
-
|
|
30
|
+
webglDevice.popState();
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
/**
|
|
@@ -47,13 +46,13 @@ export function withGLParameters(device, parameters, func) {
|
|
|
47
46
|
}
|
|
48
47
|
// Wrap in a try-catch to ensure that parameters are restored on exceptions
|
|
49
48
|
const webglDevice = device;
|
|
50
|
-
|
|
49
|
+
webglDevice.pushState();
|
|
51
50
|
try {
|
|
52
51
|
setGLParameters(webglDevice.gl, parameters);
|
|
53
52
|
return func(device);
|
|
54
53
|
}
|
|
55
54
|
finally {
|
|
56
|
-
|
|
55
|
+
webglDevice.popState();
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
/**
|
|
@@ -69,16 +68,15 @@ export function withDeviceParameters(device, parameters, func) {
|
|
|
69
68
|
// Avoid setting state if no parameters provided. Just call and return
|
|
70
69
|
return func(device);
|
|
71
70
|
}
|
|
72
|
-
// Wrap in a try-catch to ensure that parameters are restored on exceptions
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
// Wrap in a try-catch to ensure that parameters are restored on exceptions'
|
|
72
|
+
const webglDevice = device;
|
|
73
|
+
webglDevice.pushState();
|
|
75
74
|
try {
|
|
76
75
|
setDeviceParameters(device, parameters);
|
|
77
76
|
return func(device);
|
|
78
77
|
}
|
|
79
78
|
finally {
|
|
80
|
-
|
|
81
|
-
popContextState(device.gl);
|
|
79
|
+
webglDevice.popState();
|
|
82
80
|
}
|
|
83
81
|
}
|
|
84
82
|
/** Set WebGPU Style Parameters */
|
|
@@ -218,8 +216,17 @@ export function setDeviceParameters(device, parameters) {
|
|
|
218
216
|
// // handled by stencilPassOperation
|
|
219
217
|
// },
|
|
220
218
|
// COLOR STATE
|
|
219
|
+
switch (parameters.blend) {
|
|
220
|
+
case true:
|
|
221
|
+
gl.enable(3042);
|
|
222
|
+
break;
|
|
223
|
+
case false:
|
|
224
|
+
gl.disable(3042);
|
|
225
|
+
break;
|
|
226
|
+
default:
|
|
227
|
+
// leave WebGL blend state unchanged if `parameters.blend` is not set
|
|
228
|
+
}
|
|
221
229
|
if (parameters.blendColorOperation || parameters.blendAlphaOperation) {
|
|
222
|
-
gl.enable(3042);
|
|
223
230
|
const colorEquation = convertBlendOperationToEquation('blendColorOperation', parameters.blendColorOperation || 'add');
|
|
224
231
|
const alphaEquation = convertBlendOperationToEquation('blendAlphaOperation', parameters.blendAlphaOperation || 'add');
|
|
225
232
|
gl.blendEquationSeparate(colorEquation, alphaEquation);
|
|
@@ -328,3 +335,14 @@ function map(parameter, value, valueMap) {
|
|
|
328
335
|
function mapBoolean(parameter, value) {
|
|
329
336
|
return value;
|
|
330
337
|
}
|
|
338
|
+
/** Returns true if given object is empty, false otherwise. */
|
|
339
|
+
function isObjectEmpty(obj) {
|
|
340
|
+
let isEmpty = true;
|
|
341
|
+
// @ts-ignore key is unused
|
|
342
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
343
|
+
for (const key in obj) {
|
|
344
|
+
isEmpty = false;
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
return isEmpty;
|
|
348
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TextureFormat, DeviceFeature } from '@luma.gl/core';
|
|
2
|
-
import { GL, GLExtensions } from '@luma.gl/constants';
|
|
2
|
+
import { GL, GLPixelType, GLExtensions, GLTexelDataFormat } from '@luma.gl/constants';
|
|
3
3
|
export declare const TEXTURE_FEATURES: Partial<Record<DeviceFeature, string[]>>;
|
|
4
4
|
/** Return a list of texture feature strings (for Device.features). Mainly compressed texture support */
|
|
5
5
|
export declare function isTextureFeature(feature: DeviceFeature): boolean;
|
|
@@ -27,8 +27,8 @@ type Format = {
|
|
|
27
27
|
filter?: DeviceFeature;
|
|
28
28
|
/** If not supported on WebGPU */
|
|
29
29
|
wgpu?: false;
|
|
30
|
-
types?:
|
|
31
|
-
dataFormat?:
|
|
30
|
+
types?: GLPixelType[];
|
|
31
|
+
dataFormat?: GLTexelDataFormat;
|
|
32
32
|
/** Depth and stencil format attachment points. If set, needs to be a Renderbuffer unless depthTexture is set */
|
|
33
33
|
attachment?: GL.DEPTH_ATTACHMENT | GL.STENCIL_ATTACHMENT | GL.DEPTH_STENCIL_ATTACHMENT;
|
|
34
34
|
/** if depthTexture is set this is a depth/stencil format that can be set to a texture */
|
|
@@ -44,14 +44,6 @@ export declare const TEXTURE_FORMATS: Record<TextureFormat, Format>;
|
|
|
44
44
|
/** Checks if a texture format is supported */
|
|
45
45
|
export declare function isTextureFormatSupported(gl: WebGL2RenderingContext, format: TextureFormat, extensions: GLExtensions): boolean;
|
|
46
46
|
export declare function isRenderbufferFormatSupported(gl: WebGL2RenderingContext, format: TextureFormat, extensions: GLExtensions): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Map WebGL texture formats (GL constants) to WebGPU-style TextureFormat strings
|
|
49
|
-
*/
|
|
50
|
-
export declare function convertGLToTextureFormat(format: GL | TextureFormat): TextureFormat;
|
|
51
|
-
/**
|
|
52
|
-
* Map WebGPU style texture format strings to GL constants
|
|
53
|
-
*/
|
|
54
|
-
export declare function convertTextureFormatToGL(format: TextureFormat): GL | undefined;
|
|
55
47
|
/** Checks if a texture format is supported */
|
|
56
48
|
export declare function getTextureFormatSupport(gl: WebGL2RenderingContext, format: TextureFormat, extensions: GLExtensions): {
|
|
57
49
|
supported: boolean;
|
|
@@ -64,14 +56,28 @@ export declare function getTextureFormatSupport(gl: WebGL2RenderingContext, form
|
|
|
64
56
|
export declare function isTextureFormatFilterable(gl: WebGL2RenderingContext, format: TextureFormat, extensions: GLExtensions): boolean;
|
|
65
57
|
export declare function isTextureFormatRenderable(gl: WebGL2RenderingContext, format: TextureFormat, extensions: GLExtensions): boolean;
|
|
66
58
|
/** Get parameters necessary to work with format in WebGL: internalFormat, dataFormat, type, compressed, */
|
|
67
|
-
export declare function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
type:
|
|
71
|
-
compressed:
|
|
59
|
+
export declare function getTextureFormatWebGL(format: TextureFormat): {
|
|
60
|
+
internalFormat: GL;
|
|
61
|
+
format: GLTexelDataFormat;
|
|
62
|
+
type: GLPixelType;
|
|
63
|
+
compressed: boolean;
|
|
72
64
|
};
|
|
73
65
|
export declare function getDepthStencilAttachmentWebGL(format: TextureFormat): GL.DEPTH_ATTACHMENT | GL.STENCIL_ATTACHMENT | GL.DEPTH_STENCIL_ATTACHMENT;
|
|
74
66
|
/** TODO - VERY roundabout legacy way of calculating bytes per pixel */
|
|
75
67
|
export declare function getTextureFormatBytesPerPixel(format: TextureFormat): number;
|
|
68
|
+
export declare function getWebGLPixelDataFormat(channels: 'r' | 'rg' | 'rgb' | 'rgba' | 'bgra', integer: boolean, normalized: boolean, format: GL): GLTexelDataFormat;
|
|
76
69
|
export {};
|
|
70
|
+
/**
|
|
71
|
+
* Map WebGL texture formats (GL constants) to WebGPU-style TextureFormat strings
|
|
72
|
+
export function convertGLToTextureFormat(format: GL | TextureFormat): TextureFormat {
|
|
73
|
+
if (typeof format === 'string') {
|
|
74
|
+
return format;
|
|
75
|
+
}
|
|
76
|
+
const entry = Object.entries(TEXTURE_FORMATS).find(([, entry]) => entry.gl === format);
|
|
77
|
+
if (!entry) {
|
|
78
|
+
throw new Error(`Unknown texture format ${format}`);
|
|
79
|
+
}
|
|
80
|
+
return entry[0] as TextureFormat;
|
|
81
|
+
}
|
|
82
|
+
*/
|
|
77
83
|
//# sourceMappingURL=texture-formats.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"texture-formats.d.ts","sourceRoot":"","sources":["../../../src/adapter/converters/texture-formats.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,eAAe,CAAC;AAEhE,OAAO,EAAC,EAAE,EAAE,YAAY,EAAC,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"texture-formats.d.ts","sourceRoot":"","sources":["../../../src/adapter/converters/texture-formats.ts"],"names":[],"mappings":"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"}
|
|
@@ -82,14 +82,6 @@ export function checkTextureFeature(gl, feature, extensions) {
|
|
|
82
82
|
*/
|
|
83
83
|
// prettier-ignore
|
|
84
84
|
export const TEXTURE_FORMATS = {
|
|
85
|
-
// Unsized formats that leave the precision up to the driver. TODO - Fix bpp constants
|
|
86
|
-
'rgb8unorm-unsized': { gl: 6407, b: 4, c: 2, bpp: 4,
|
|
87
|
-
dataFormat: 6407, types: [5121, 33635] },
|
|
88
|
-
'rgba8unorm-unsized': { gl: 6408, b: 4, c: 2, bpp: 4,
|
|
89
|
-
dataFormat: 6408, types: [5121, 32819, 32820] },
|
|
90
|
-
// 'r8unorm-unsized': {gl: GL.LUMINANCE, b: 4, c: 2, bpp: 4},
|
|
91
|
-
// 'rgb8unorm-srgb-unsized': {gl: GL.SRGB_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
|
|
92
|
-
// 'rgba8unorm-srgb-unsized': {gl: GL.SRGB_ALPHA_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
|
|
93
85
|
// 8-bit formats
|
|
94
86
|
'r8unorm': { gl: 33321, b: 1, c: 1, rb: true },
|
|
95
87
|
'r8snorm': { gl: 36756, b: 1, c: 1, render: snorm8_renderable },
|
|
@@ -123,7 +115,6 @@ export const TEXTURE_FORMATS = {
|
|
|
123
115
|
'bgra8unorm-srgb': { b: 4, c: 4 },
|
|
124
116
|
'rg16uint': { gl: 33338, b: 4, c: 1, bpp: 4 },
|
|
125
117
|
'rg16sint': { gl: 33337, b: 4, c: 2, bpp: 4 },
|
|
126
|
-
// When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
|
|
127
118
|
'rg16float': { gl: 33327, bpp: 4, b: 4, c: 2, render: float16_renderable, filter: float16_filterable, rb: true },
|
|
128
119
|
'rg16unorm-webgl': { gl: 33324, b: 2, c: 2, render: norm16_renderable },
|
|
129
120
|
'rg16snorm-webgl': { gl: 36761, b: 2, c: 2, render: snorm16_renderable },
|
|
@@ -165,9 +156,6 @@ export const TEXTURE_FORMATS = {
|
|
|
165
156
|
// The depth component of the "depth24plus" and "depth24plus-stencil8" formats may be implemented as either a 24-bit depth value or a "depth32float" value.
|
|
166
157
|
'depth24plus-stencil8': { gl: 35056, b: 4, c: 2, p: 1, attachment: 33306, rb: true, depthTexture: true,
|
|
167
158
|
dataFormat: 34041, types: [34042] },
|
|
168
|
-
// "depth24unorm-stencil8" feature
|
|
169
|
-
'depth24unorm-stencil8': { gl: 35056, b: 4, c: 2, p: 1, attachment: 33306,
|
|
170
|
-
dataFormat: 34041, types: [34042], rb: true },
|
|
171
159
|
// "depth32float-stencil8" feature - TODO below is render buffer only?
|
|
172
160
|
'depth32float-stencil8': { gl: 36013, b: 5, c: 2, p: 1, attachment: 33306,
|
|
173
161
|
dataFormat: 34041, types: [36269], rb: true },
|
|
@@ -371,6 +359,10 @@ export function isTextureFormatSupported(gl, format, extensions) {
|
|
|
371
359
|
if (info.gl === undefined) {
|
|
372
360
|
return false;
|
|
373
361
|
}
|
|
362
|
+
const feature = info.f;
|
|
363
|
+
if (feature) {
|
|
364
|
+
return checkTextureFeature(gl, feature, extensions);
|
|
365
|
+
}
|
|
374
366
|
// Check extensions
|
|
375
367
|
const extension = info.x || info.gl2ext;
|
|
376
368
|
if (extension) {
|
|
@@ -380,31 +372,7 @@ export function isTextureFormatSupported(gl, format, extensions) {
|
|
|
380
372
|
}
|
|
381
373
|
export function isRenderbufferFormatSupported(gl, format, extensions) {
|
|
382
374
|
// Note: Order is important since the function call initializes extensions.
|
|
383
|
-
return isTextureFormatSupported(gl, format, extensions) && TEXTURE_FORMATS[format]?.rb;
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Map WebGL texture formats (GL constants) to WebGPU-style TextureFormat strings
|
|
387
|
-
*/
|
|
388
|
-
export function convertGLToTextureFormat(format) {
|
|
389
|
-
if (typeof format === 'string') {
|
|
390
|
-
return format;
|
|
391
|
-
}
|
|
392
|
-
const entry = Object.entries(TEXTURE_FORMATS).find(([, entry]) => entry.gl === format);
|
|
393
|
-
if (!entry) {
|
|
394
|
-
throw new Error(`Unknown texture format ${format}`);
|
|
395
|
-
}
|
|
396
|
-
return entry[0];
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* Map WebGPU style texture format strings to GL constants
|
|
400
|
-
*/
|
|
401
|
-
export function convertTextureFormatToGL(format) {
|
|
402
|
-
const formatInfo = TEXTURE_FORMATS[format];
|
|
403
|
-
const webglFormat = formatInfo?.gl;
|
|
404
|
-
if (webglFormat === undefined) {
|
|
405
|
-
throw new Error(`Unsupported texture format ${format}`);
|
|
406
|
-
}
|
|
407
|
-
return webglFormat;
|
|
375
|
+
return isTextureFormatSupported(gl, format, extensions) && Boolean(TEXTURE_FORMATS[format]?.rb);
|
|
408
376
|
}
|
|
409
377
|
/** Checks if a texture format is supported */
|
|
410
378
|
export function getTextureFormatSupport(gl, format, extensions) {
|
|
@@ -470,20 +438,19 @@ export function isTextureFormatRenderable(gl, format, extensions) {
|
|
|
470
438
|
return true;
|
|
471
439
|
}
|
|
472
440
|
/** Get parameters necessary to work with format in WebGL: internalFormat, dataFormat, type, compressed, */
|
|
473
|
-
export function
|
|
441
|
+
export function getTextureFormatWebGL(format) {
|
|
474
442
|
const formatData = TEXTURE_FORMATS[format];
|
|
475
443
|
const webglFormat = convertTextureFormatToGL(format);
|
|
476
444
|
const decoded = decodeTextureFormat(format);
|
|
477
445
|
return {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
getWebGLPixelDataFormat(decoded.
|
|
446
|
+
internalFormat: webglFormat,
|
|
447
|
+
format: formatData?.dataFormat ||
|
|
448
|
+
getWebGLPixelDataFormat(decoded.channels, decoded.integer, decoded.normalized, webglFormat),
|
|
481
449
|
// depth formats don't have a type
|
|
482
450
|
type: decoded.dataType
|
|
483
451
|
? getGLFromVertexType(decoded.dataType)
|
|
484
452
|
: formatData?.types?.[0] || 5121,
|
|
485
|
-
|
|
486
|
-
compressed: decoded.compressed
|
|
453
|
+
compressed: decoded.compressed || false
|
|
487
454
|
};
|
|
488
455
|
}
|
|
489
456
|
export function getDepthStencilAttachmentWebGL(format) {
|
|
@@ -496,24 +463,49 @@ export function getDepthStencilAttachmentWebGL(format) {
|
|
|
496
463
|
/** TODO - VERY roundabout legacy way of calculating bytes per pixel */
|
|
497
464
|
export function getTextureFormatBytesPerPixel(format) {
|
|
498
465
|
// TODO remove webgl1 support
|
|
499
|
-
const params =
|
|
466
|
+
const params = getTextureFormatWebGL(format);
|
|
500
467
|
// NOTE(Tarek): Default to RGBA bytes
|
|
501
|
-
const channels = DATA_FORMAT_CHANNELS[params.
|
|
468
|
+
const channels = DATA_FORMAT_CHANNELS[params.format] || 4;
|
|
502
469
|
const channelSize = TYPE_SIZES[params.type] || 1;
|
|
503
470
|
return channels * channelSize;
|
|
504
471
|
}
|
|
505
472
|
// DATA TYPE HELPERS
|
|
506
|
-
function getWebGLPixelDataFormat(
|
|
473
|
+
export function getWebGLPixelDataFormat(channels, integer, normalized, format) {
|
|
507
474
|
// WebGL1 formats use same internalFormat
|
|
508
475
|
if (format === 6408 || format === 6407) {
|
|
509
476
|
return format;
|
|
510
477
|
}
|
|
511
478
|
// prettier-ignore
|
|
512
|
-
switch (
|
|
479
|
+
switch (channels) {
|
|
513
480
|
case 'r': return integer && !normalized ? 36244 : 6403;
|
|
514
481
|
case 'rg': return integer && !normalized ? 33320 : 33319;
|
|
515
482
|
case 'rgb': return integer && !normalized ? 36248 : 6407;
|
|
516
483
|
case 'rgba': return integer && !normalized ? 36249 : 6408;
|
|
484
|
+
case 'bgra': throw new Error('bgra pixels not supported by WebGL');
|
|
517
485
|
default: return 6408;
|
|
518
486
|
}
|
|
519
487
|
}
|
|
488
|
+
/**
|
|
489
|
+
* Map WebGPU style texture format strings to GL constants
|
|
490
|
+
*/
|
|
491
|
+
function convertTextureFormatToGL(format) {
|
|
492
|
+
const formatInfo = TEXTURE_FORMATS[format];
|
|
493
|
+
const webglFormat = formatInfo?.gl;
|
|
494
|
+
if (webglFormat === undefined) {
|
|
495
|
+
throw new Error(`Unsupported texture format ${format}`);
|
|
496
|
+
}
|
|
497
|
+
return webglFormat;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Map WebGL texture formats (GL constants) to WebGPU-style TextureFormat strings
|
|
501
|
+
export function convertGLToTextureFormat(format: GL | TextureFormat): TextureFormat {
|
|
502
|
+
if (typeof format === 'string') {
|
|
503
|
+
return format;
|
|
504
|
+
}
|
|
505
|
+
const entry = Object.entries(TEXTURE_FORMATS).find(([, entry]) => entry.gl === format);
|
|
506
|
+
if (!entry) {
|
|
507
|
+
throw new Error(`Unknown texture format ${format}`);
|
|
508
|
+
}
|
|
509
|
+
return entry[0] as TextureFormat;
|
|
510
|
+
}
|
|
511
|
+
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgl-device-features.d.ts","sourceRoot":"","sources":["../../../src/adapter/device-helpers/webgl-device-features.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,aAAa,EAAE,cAAc,EAAC,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"webgl-device-features.d.ts","sourceRoot":"","sources":["../../../src/adapter/device-helpers/webgl-device-features.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,aAAa,EAAE,cAAc,EAAC,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AA6BhD;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,cAAc;IACrD,SAAS,CAAC,EAAE,EAAE,sBAAsB,CAAC;IACrC,SAAS,CAAC,UAAU,EAAE,YAAY,CAAC;IACnC,SAAS,CAAC,cAAc,qBAA4B;gBAGlD,EAAE,EAAE,sBAAsB,EAC1B,UAAU,EAAE,YAAY,EACxB,gBAAgB,EAAE,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAU1D,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,aAAa,CAAC;IAU5C,GAAG,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO;IAuB7C,kBAAkB;IAWlB,WAAW,IACoE,aAAa,EAAE;IAG9F,iCAAiC;IACjC,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO;CAU3D"}
|
|
@@ -17,7 +17,6 @@ const WEBGL_FEATURES = {
|
|
|
17
17
|
// 'timestamp-query' // GPUQueryType "timestamp-query"
|
|
18
18
|
// "indirect-first-instance"
|
|
19
19
|
// Textures are handled by getTextureFeatures()
|
|
20
|
-
// 'depth24unorm-stencil8' // GPUTextureFormat 'depth24unorm-stencil8'
|
|
21
20
|
// 'depth32float-stencil8' // GPUTextureFormat 'depth32float-stencil8'
|
|
22
21
|
// optional WebGL features
|
|
23
22
|
'timer-query-webgl': 'EXT_disjoint_timer_query_webgl2',
|
|
@@ -57,7 +56,7 @@ export class WebGLDeviceFeatures extends DeviceFeatures {
|
|
|
57
56
|
return [];
|
|
58
57
|
}
|
|
59
58
|
has(feature) {
|
|
60
|
-
if (this.disabledFeatures[feature]) {
|
|
59
|
+
if (this.disabledFeatures?.[feature]) {
|
|
61
60
|
return false;
|
|
62
61
|
}
|
|
63
62
|
// We have already tested this feature
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import type { ExternalImage } from '@luma.gl/core';
|
|
2
|
+
import { GL, GLTextureTarget, GLTexelDataFormat, GLPixelType } from '@luma.gl/constants';
|
|
3
|
+
import { TypedArray } from '@math.gl/types';
|
|
4
|
+
export type WebGLSetTextureOptions = {
|
|
5
|
+
dimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
|
|
6
|
+
height: number;
|
|
7
|
+
width: number;
|
|
8
|
+
depth?: number;
|
|
9
|
+
level?: number;
|
|
10
|
+
glTarget: GLTextureTarget;
|
|
11
|
+
glInternalFormat: GL;
|
|
12
|
+
glFormat: GLTexelDataFormat;
|
|
13
|
+
glType: GLPixelType;
|
|
14
|
+
compressed?: boolean;
|
|
15
|
+
byteOffset?: number;
|
|
16
|
+
byteLength?: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* @param {*} pixels, data -
|
|
20
|
+
* null - create empty texture of specified format
|
|
21
|
+
* Typed array - init from image data in typed array
|
|
22
|
+
* Buffer|WebGLBuffer - (WEBGL2) init from image data in WebGLBuffer
|
|
23
|
+
* HTMLImageElement|Image - Inits with content of image. Auto width/height
|
|
24
|
+
* HTMLCanvasElement - Inits with contents of canvas. Auto width/height
|
|
25
|
+
* HTMLVideoElement - Creates video texture. Auto width/height
|
|
26
|
+
*
|
|
27
|
+
* @param x - xOffset from where texture to be updated
|
|
28
|
+
* @param y - yOffset from where texture to be updated
|
|
29
|
+
* @param width - width of the sub image to be updated
|
|
30
|
+
* @param height - height of the sub image to be updated
|
|
31
|
+
* @param level - mip level to be updated
|
|
32
|
+
* @param {GLenum} format - internal format of image data.
|
|
33
|
+
* @param {GLenum} type
|
|
34
|
+
* - format of array (autodetect from type) or
|
|
35
|
+
* - (WEBGL2) format of buffer or ArrayBufferView
|
|
36
|
+
* @param {GLenum} dataFormat - format of image data.
|
|
37
|
+
* @param {Number} offset - (WEBGL2) offset from start of buffer
|
|
38
|
+
* @parameters - temporary settings to be applied, can be used to supply pixel store settings.
|
|
39
|
+
*/
|
|
40
|
+
export type WebGLCopyTextureOptions = {
|
|
41
|
+
dimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
|
|
42
|
+
level?: number;
|
|
43
|
+
height: number;
|
|
44
|
+
width: number;
|
|
45
|
+
depth?: number;
|
|
46
|
+
x?: number;
|
|
47
|
+
y?: number;
|
|
48
|
+
z?: number;
|
|
49
|
+
glTarget: GLTextureTarget;
|
|
50
|
+
glInternalFormat: GL;
|
|
51
|
+
glFormat: GL;
|
|
52
|
+
glType: GL;
|
|
53
|
+
compressed?: boolean;
|
|
54
|
+
byteOffset?: number;
|
|
55
|
+
byteLength?: number;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Initializes a texture memory space
|
|
59
|
+
* Clear all the textures and mip levels of a two-dimensional or array texture at the same time.
|
|
60
|
+
* On some implementations faster than repeatedly setting levels
|
|
61
|
+
*
|
|
62
|
+
* @note From WebGL 2 spec section 3.7.6:
|
|
63
|
+
* @see https://registry.khronos.org/webgl/specs/latest/2.0/
|
|
64
|
+
* - The image contents are set as if a buffer of sufficient size initialized to 0 would be passed to each level's texImage2D/3D
|
|
65
|
+
* - texStorage2D should be considered a preferred alternative to texImage2D. It may have lower memory costs than texImage2D in some implementations.
|
|
66
|
+
* - Once texStorage*D has been called, the texture is immutable and can only be updated with texSubImage*(), not texImage()
|
|
67
|
+
*/
|
|
68
|
+
export declare function initializeTextureStorage(gl: WebGL2RenderingContext, levels: number, options: WebGLSetTextureOptions): void;
|
|
69
|
+
/**
|
|
70
|
+
* Copy a region of compressed data from a GPU memory buffer into this texture.
|
|
71
|
+
*/
|
|
72
|
+
export declare function copyCPUImageToMipLevel(gl: WebGL2RenderingContext, image: ExternalImage, options: WebGLCopyTextureOptions): void;
|
|
73
|
+
/**
|
|
74
|
+
* Copy a region of data from a CPU memory buffer into this texture.
|
|
75
|
+
*/
|
|
76
|
+
export declare function copyCPUDataToMipLevel(gl: WebGL2RenderingContext, typedArray: TypedArray, options: WebGLCopyTextureOptions): void;
|
|
77
|
+
/**
|
|
78
|
+
* Copy a region of compressed data from a GPU memory buffer into this texture.
|
|
79
|
+
*/
|
|
80
|
+
export declare function copyGPUBufferToMipLevel(gl: WebGL2RenderingContext, webglBuffer: WebGLBuffer, byteLength: number, options: WebGLCopyTextureOptions): void;
|
|
81
|
+
/** Convert a WebGPU style texture constant to a WebGL style texture constant */
|
|
82
|
+
export declare function getWebGLTextureTarget(dimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d'): GLTextureTarget;
|
|
83
|
+
/**
|
|
84
|
+
* Clear a texture mip level.
|
|
85
|
+
* Wrapper for the messy WebGL texture API
|
|
86
|
+
*
|
|
87
|
+
export function clearMipLevel(gl: WebGL2RenderingContext, options: WebGLSetTextureOptions): void {
|
|
88
|
+
const {dimension, width, height, depth = 0, level = 0} = options;
|
|
89
|
+
const {glInternalFormat, glFormat, glType, compressed} = options;
|
|
90
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
91
|
+
|
|
92
|
+
switch (dimension) {
|
|
93
|
+
case '2d-array':
|
|
94
|
+
case '3d':
|
|
95
|
+
if (compressed) {
|
|
96
|
+
// prettier-ignore
|
|
97
|
+
gl.compressedTexImage3D(glTarget, level, glInternalFormat, width, height, depth, BORDER, null);
|
|
98
|
+
} else {
|
|
99
|
+
// prettier-ignore
|
|
100
|
+
gl.texImage3D( glTarget, level, glInternalFormat, width, height, depth, BORDER, glFormat, glType, null);
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
|
|
104
|
+
case '2d':
|
|
105
|
+
case 'cube':
|
|
106
|
+
if (compressed) {
|
|
107
|
+
// prettier-ignore
|
|
108
|
+
gl.compressedTexImage2D(glTarget, level, glInternalFormat, width, height, BORDER, null);
|
|
109
|
+
} else {
|
|
110
|
+
// prettier-ignore
|
|
111
|
+
gl.texImage2D(glTarget, level, glInternalFormat, width, height, BORDER, glFormat, glType, null);
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
|
|
115
|
+
default:
|
|
116
|
+
throw new Error(dimension);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Set a texture mip level to the contents of an external image.
|
|
122
|
+
* Wrapper for the messy WebGL texture API
|
|
123
|
+
* @note Corresponds to WebGPU device.queue.copyExternalImageToTexture()
|
|
124
|
+
*
|
|
125
|
+
export function setMipLevelFromExternalImage(
|
|
126
|
+
gl: WebGL2RenderingContext,
|
|
127
|
+
image: ExternalImage,
|
|
128
|
+
options: WebGLSetTextureOptions
|
|
129
|
+
): void {
|
|
130
|
+
const {dimension, width, height, depth = 0, level = 0} = options;
|
|
131
|
+
const {glInternalFormat, glType} = options;
|
|
132
|
+
|
|
133
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
134
|
+
|
|
135
|
+
// TODO - we can't change texture width (due to WebGPU limitations) -
|
|
136
|
+
// and the width/heigh of an external image is implicit, so why do we need to extract it?
|
|
137
|
+
// So what width height do we supply? The image size or the texture size?
|
|
138
|
+
// const {width, height} = Texture.getExternalImageSize(image);
|
|
139
|
+
|
|
140
|
+
switch (dimension) {
|
|
141
|
+
case '2d-array':
|
|
142
|
+
case '3d':
|
|
143
|
+
// prettier-ignore
|
|
144
|
+
gl.texImage3D(glTarget, level, glInternalFormat, width, height, depth, BORDER, glInternalFormat, glType, image);
|
|
145
|
+
break;
|
|
146
|
+
|
|
147
|
+
case '2d':
|
|
148
|
+
case 'cube':
|
|
149
|
+
// prettier-ignore
|
|
150
|
+
gl.texImage2D(glTarget, level, glInternalFormat, width, height, BORDER, glInternalFormat, glType, image);
|
|
151
|
+
break;
|
|
152
|
+
|
|
153
|
+
default:
|
|
154
|
+
throw new Error(dimension);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Set a texture mip level from CPU memory
|
|
160
|
+
* Wrapper for the messy WebGL texture API
|
|
161
|
+
* @note Not available (directly) in WebGPU
|
|
162
|
+
*
|
|
163
|
+
export function setMipLevelFromTypedArray(
|
|
164
|
+
gl: WebGL2RenderingContext,
|
|
165
|
+
data: TypedArray,
|
|
166
|
+
parameters: {},
|
|
167
|
+
options: {
|
|
168
|
+
dimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
|
|
169
|
+
height: number;
|
|
170
|
+
width: number;
|
|
171
|
+
depth?: number;
|
|
172
|
+
level?: number;
|
|
173
|
+
offset?: number;
|
|
174
|
+
glTarget: GLTextureTarget;
|
|
175
|
+
glInternalFormat: GL;
|
|
176
|
+
glFormat: GL;
|
|
177
|
+
glType: GL;
|
|
178
|
+
compressed?: boolean;
|
|
179
|
+
}
|
|
180
|
+
): void {
|
|
181
|
+
const {dimension, width, height, depth = 0, level = 0, offset = 0} = options;
|
|
182
|
+
const {glInternalFormat, glFormat, glType, compressed} = options;
|
|
183
|
+
|
|
184
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
185
|
+
|
|
186
|
+
withGLParameters(gl, parameters, () => {
|
|
187
|
+
switch (dimension) {
|
|
188
|
+
case '2d-array':
|
|
189
|
+
case '3d':
|
|
190
|
+
if (compressed) {
|
|
191
|
+
// prettier-ignore
|
|
192
|
+
gl.compressedTexImage3D(glTarget, level, glInternalFormat, width, height, depth, BORDER, data);
|
|
193
|
+
} else {
|
|
194
|
+
// prettier-ignore
|
|
195
|
+
gl.texImage3D( glTarget, level, glInternalFormat, width, height, depth, BORDER, glFormat, glType, data);
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
|
|
199
|
+
case '2d':
|
|
200
|
+
if (compressed) {
|
|
201
|
+
// prettier-ignore
|
|
202
|
+
gl.compressedTexImage2D(glTarget, level, glInternalFormat, width, height, BORDER, data);
|
|
203
|
+
} else {
|
|
204
|
+
// prettier-ignore
|
|
205
|
+
gl.texImage2D( glTarget, level, glInternalFormat, width, height, BORDER, glFormat, glType, data, offset);
|
|
206
|
+
}
|
|
207
|
+
break;
|
|
208
|
+
|
|
209
|
+
default:
|
|
210
|
+
throw new Error(dimension);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Set a texture level from CPU memory
|
|
217
|
+
* @note Not available (directly) in WebGPU
|
|
218
|
+
_setMipLevelFromTypedArray(
|
|
219
|
+
depth: number,
|
|
220
|
+
level: number,
|
|
221
|
+
data: TextureLevelData,
|
|
222
|
+
offset = 0,
|
|
223
|
+
parameters
|
|
224
|
+
): void {
|
|
225
|
+
withGLParameters(this.gl, parameters, () => {
|
|
226
|
+
switch (this.props.dimension) {
|
|
227
|
+
case '2d-array':
|
|
228
|
+
case '3d':
|
|
229
|
+
if (this.compressed) {
|
|
230
|
+
// prettier-ignore
|
|
231
|
+
this.device.gl.compressedTexImage3D(this.glTarget, level, this.glInternalFormat, data.width, data.height, depth, BORDER, data.data);
|
|
232
|
+
} else {
|
|
233
|
+
// prettier-ignore
|
|
234
|
+
this.gl.texImage3D( this.glTarget, level, this.glInternalFormat, this.width, this.height, depth, BORDER, this.glFormat, this.glType, data.data);
|
|
235
|
+
}
|
|
236
|
+
break;
|
|
237
|
+
|
|
238
|
+
case '2d':
|
|
239
|
+
if (this.compressed) {
|
|
240
|
+
// prettier-ignore
|
|
241
|
+
this.device.gl.compressedTexImage2D(this.glTarget, level, this.glInternalFormat, data.width, data.height, BORDER, data.data);
|
|
242
|
+
} else {
|
|
243
|
+
// prettier-ignore
|
|
244
|
+
this.device.gl.texImage2D( this.glTarget, level, this.glInternalFormat, this.width, this.height, BORDER, this.glFormat, this.glType, data.data, offset);
|
|
245
|
+
}
|
|
246
|
+
break;
|
|
247
|
+
|
|
248
|
+
default:
|
|
249
|
+
throw new Error(this.props.dimension);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
* Set a texture level from a GPU buffer
|
|
255
|
+
*
|
|
256
|
+
export function setMipLevelFromGPUBuffer(
|
|
257
|
+
gl: WebGL2RenderingContext,
|
|
258
|
+
buffer: Buffer,
|
|
259
|
+
options: WebGLSetTextureOptions
|
|
260
|
+
): void {
|
|
261
|
+
const {dimension, width, height, depth = 0, level = 0, byteOffset = 0} = options;
|
|
262
|
+
const {glInternalFormat, glFormat, glType, compressed} = options;
|
|
263
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
264
|
+
|
|
265
|
+
const webglBuffer = buffer as WEBGLBuffer;
|
|
266
|
+
const imageSize = buffer.byteLength;
|
|
267
|
+
|
|
268
|
+
// In WebGL the source buffer is not a parameter. Instead it needs to be bound to a special bind point
|
|
269
|
+
gl.bindBuffer(GL.PIXEL_UNPACK_BUFFER, webglBuffer.handle);
|
|
270
|
+
|
|
271
|
+
switch (dimension) {
|
|
272
|
+
case '2d-array':
|
|
273
|
+
case '3d':
|
|
274
|
+
if (compressed) {
|
|
275
|
+
// prettier-ignore
|
|
276
|
+
gl.compressedTexImage3D(glTarget, level, glInternalFormat, width, height, depth, BORDER, imageSize, byteOffset);
|
|
277
|
+
} else {
|
|
278
|
+
// prettier-ignore
|
|
279
|
+
gl.texImage3D(glTarget, level, glInternalFormat, width, height, depth, BORDER, glFormat, glType, byteOffset);
|
|
280
|
+
}
|
|
281
|
+
break;
|
|
282
|
+
|
|
283
|
+
case '2d':
|
|
284
|
+
if (compressed) {
|
|
285
|
+
// prettier-ignore
|
|
286
|
+
gl.compressedTexImage2D(glTarget, level, glInternalFormat, width, height, BORDER, imageSize, byteOffset);
|
|
287
|
+
} else {
|
|
288
|
+
// prettier-ignore
|
|
289
|
+
gl.texImage2D(glTarget, level, glInternalFormat, width, height, BORDER, glFormat, glType, byteOffset);
|
|
290
|
+
}
|
|
291
|
+
break;
|
|
292
|
+
|
|
293
|
+
default:
|
|
294
|
+
throw new Error(dimension);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
gl.bindBuffer(GL.PIXEL_UNPACK_BUFFER, null);
|
|
298
|
+
}
|
|
299
|
+
*/
|
|
300
|
+
//# sourceMappingURL=webgl-texture-utils.d.ts.map
|