@luma.gl/core 9.2.6 → 9.3.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/canvas-context.d.ts +23 -3
- package/dist/adapter/canvas-context.d.ts.map +1 -1
- package/dist/adapter/canvas-context.js +77 -15
- package/dist/adapter/canvas-context.js.map +1 -1
- package/dist/adapter/device.d.ts +5 -5
- package/dist/adapter/device.d.ts.map +1 -1
- package/dist/adapter/device.js +12 -2
- package/dist/adapter/device.js.map +1 -1
- package/dist/adapter/luma.js +1 -1
- package/dist/adapter/luma.js.map +1 -1
- package/dist/adapter/resources/command-encoder.d.ts +5 -5
- package/dist/adapter/resources/command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/fence.d.ts +16 -0
- package/dist/adapter/resources/fence.d.ts.map +1 -0
- package/dist/adapter/resources/fence.js +15 -0
- package/dist/adapter/resources/fence.js.map +1 -0
- package/dist/adapter/resources/framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/framebuffer.js +15 -12
- package/dist/adapter/resources/framebuffer.js.map +1 -1
- package/dist/adapter/resources/resource.d.ts +5 -0
- package/dist/adapter/resources/resource.d.ts.map +1 -1
- package/dist/adapter/resources/resource.js +3 -0
- package/dist/adapter/resources/resource.js.map +1 -1
- package/dist/adapter/resources/shader.js +27 -25
- package/dist/adapter/resources/shader.js.map +1 -1
- package/dist/adapter/resources/texture.d.ts +97 -24
- package/dist/adapter/resources/texture.d.ts.map +1 -1
- package/dist/adapter/resources/texture.js +116 -10
- package/dist/adapter/resources/texture.js.map +1 -1
- package/dist/adapter-utils/format-compiler-log.d.ts.map +1 -1
- package/dist/adapter-utils/format-compiler-log.js +23 -15
- package/dist/adapter-utils/format-compiler-log.js.map +1 -1
- package/dist/dist.dev.js +695 -279
- package/dist/dist.min.js +10 -9
- package/dist/index.cjs +481 -161
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/portable/uniform-buffer-layout.d.ts +13 -4
- package/dist/portable/uniform-buffer-layout.d.ts.map +1 -1
- package/dist/portable/uniform-buffer-layout.js +88 -55
- package/dist/portable/uniform-buffer-layout.js.map +1 -1
- package/dist/shadertypes/data-types/decode-data-types.d.ts.map +1 -1
- package/dist/shadertypes/data-types/decode-data-types.js +2 -1
- package/dist/shadertypes/data-types/decode-data-types.js.map +1 -1
- package/dist/shadertypes/data-types/shader-types.d.ts +5 -7
- package/dist/shadertypes/data-types/shader-types.d.ts.map +1 -1
- package/dist/shadertypes/textures/pixel-utils.js +4 -4
- package/dist/shadertypes/textures/pixel-utils.js.map +1 -1
- package/dist/shadertypes/textures/texture-format-decoder.d.ts +25 -8
- package/dist/shadertypes/textures/texture-format-decoder.d.ts.map +1 -1
- package/dist/shadertypes/textures/texture-format-decoder.js +60 -34
- package/dist/shadertypes/textures/texture-format-decoder.js.map +1 -1
- package/dist/shadertypes/textures/texture-formats.d.ts +43 -16
- package/dist/shadertypes/textures/texture-formats.d.ts.map +1 -1
- package/dist/shadertypes/textures/texture-formats.js.map +1 -1
- package/dist/shadertypes/textures/texture-layout.d.ts +5 -0
- package/dist/shadertypes/textures/texture-layout.d.ts.map +1 -0
- package/dist/shadertypes/textures/texture-layout.js +41 -0
- package/dist/shadertypes/textures/texture-layout.js.map +1 -0
- package/dist/utils/assert.d.ts +5 -0
- package/dist/utils/assert.d.ts.map +1 -0
- package/dist/utils/assert.js +17 -0
- package/dist/utils/assert.js.map +1 -0
- package/package.json +5 -5
- package/src/adapter/canvas-context.ts +87 -20
- package/src/adapter/device.ts +23 -5
- package/src/adapter/resources/command-buffer.ts +1 -1
- package/src/adapter/resources/command-encoder.ts +7 -7
- package/src/adapter/resources/fence.ts +30 -0
- package/src/adapter/resources/framebuffer.ts +15 -12
- package/src/adapter/resources/resource.ts +5 -0
- package/src/adapter/resources/shader.ts +28 -28
- package/src/adapter/resources/texture.ts +176 -28
- package/src/adapter-utils/format-compiler-log.ts +23 -15
- package/src/index.ts +12 -2
- package/src/portable/uniform-buffer-layout.ts +122 -63
- package/src/shadertypes/data-types/decode-data-types.ts +2 -1
- package/src/shadertypes/data-types/shader-types.ts +14 -7
- package/src/shadertypes/textures/pixel-utils.ts +4 -4
- package/src/shadertypes/textures/texture-format-decoder.ts +97 -42
- package/src/shadertypes/textures/texture-formats.ts +54 -15
- package/src/shadertypes/textures/texture-layout.ts +60 -0
- package/src/utils/assert.ts +18 -0
|
@@ -3,60 +3,86 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { getDataTypeInfo } from "../data-types/decode-data-types.js";
|
|
5
5
|
import { getTextureFormatDefinition } from "./texture-format-table.js";
|
|
6
|
+
const RGB_FORMAT_REGEX = /^(r|rg|rgb|rgba|bgra)([0-9]*)([a-z]*)(-srgb)?(-webgl)?$/;
|
|
7
|
+
const COLOR_FORMAT_PREFIXES = ['rgb', 'rgba', 'bgra'];
|
|
8
|
+
const DEPTH_FORMAT_PREFIXES = ['depth', 'stencil'];
|
|
6
9
|
// prettier-ignore
|
|
7
10
|
const COMPRESSED_TEXTURE_FORMAT_PREFIXES = [
|
|
8
11
|
'bc1', 'bc2', 'bc3', 'bc4', 'bc5', 'bc6', 'bc7', 'etc1', 'etc2', 'eac', 'atc', 'astc', 'pvrtc'
|
|
9
12
|
];
|
|
10
|
-
|
|
13
|
+
/** Class that helps applications work with texture formats */
|
|
11
14
|
export class TextureFormatDecoder {
|
|
12
|
-
/** Returns information about a texture format, e.g. attatchment type, components, byte length and flags (integer, signed, normalized) */
|
|
13
|
-
getInfo(format) {
|
|
14
|
-
return getTextureFormatInfo(format);
|
|
15
|
-
}
|
|
16
15
|
/** Checks if a texture format is color */
|
|
17
16
|
isColor(format) {
|
|
18
|
-
return
|
|
17
|
+
return COLOR_FORMAT_PREFIXES.some(prefix => format.startsWith(prefix));
|
|
19
18
|
}
|
|
20
19
|
/** Checks if a texture format is depth or stencil */
|
|
21
20
|
isDepthStencil(format) {
|
|
22
|
-
return
|
|
21
|
+
return DEPTH_FORMAT_PREFIXES.some(prefix => format.startsWith(prefix));
|
|
23
22
|
}
|
|
24
23
|
/** Checks if a texture format is compressed */
|
|
25
24
|
isCompressed(format) {
|
|
26
25
|
return COMPRESSED_TEXTURE_FORMAT_PREFIXES.some(prefix => format.startsWith(prefix));
|
|
27
26
|
}
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
/** Returns information about a texture format, e.g. attachment type, components, byte length and flags (integer, signed, normalized) */
|
|
28
|
+
getInfo(format) {
|
|
29
|
+
return getTextureFormatInfo(format);
|
|
30
|
+
}
|
|
31
|
+
/** "static" capabilities of a texture format. @note Needs to be adjusted against current device */
|
|
32
32
|
getCapabilities(format) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
filter: info.filter ?? true,
|
|
39
|
-
blend: info.blend ?? true,
|
|
40
|
-
store: info.store ?? true
|
|
41
|
-
};
|
|
42
|
-
const formatInfo = getTextureFormatInfo(format);
|
|
43
|
-
const isDepthStencil = format.startsWith('depth') || format.startsWith('stencil');
|
|
44
|
-
const isSigned = formatInfo?.signed;
|
|
45
|
-
const isInteger = formatInfo?.integer;
|
|
46
|
-
const isWebGLSpecific = formatInfo?.webgl;
|
|
47
|
-
// signed formats are not renderable
|
|
48
|
-
formatCapabilities.render &&= !isSigned;
|
|
49
|
-
// signed and integer formats are not filterable
|
|
50
|
-
formatCapabilities.filter &&= !isDepthStencil && !isSigned && !isInteger && !isWebGLSpecific;
|
|
51
|
-
return formatCapabilities;
|
|
33
|
+
return getTextureFormatCapabilities(format);
|
|
34
|
+
}
|
|
35
|
+
/** Computes the memory layout for a texture, in particular including row byte alignment */
|
|
36
|
+
computeMemoryLayout(opts) {
|
|
37
|
+
return computeTextureMemoryLayout(opts);
|
|
52
38
|
}
|
|
53
39
|
}
|
|
54
40
|
export const textureFormatDecoder = new TextureFormatDecoder();
|
|
55
|
-
// HELPERS
|
|
41
|
+
// HELPERS - MEMORY LAYOUT
|
|
42
|
+
/** Get the memory layout of a texture */
|
|
43
|
+
function computeTextureMemoryLayout({ format, width, height, depth, byteAlignment }) {
|
|
44
|
+
const { bytesPerPixel } = textureFormatDecoder.getInfo(format);
|
|
45
|
+
// WebGPU requires bytesPerRow to be a multiple of 256.
|
|
46
|
+
const unpaddedBytesPerRow = width * bytesPerPixel;
|
|
47
|
+
const bytesPerRow = Math.ceil(unpaddedBytesPerRow / byteAlignment) * byteAlignment;
|
|
48
|
+
const rowsPerImage = height;
|
|
49
|
+
const byteLength = bytesPerRow * rowsPerImage * depth;
|
|
50
|
+
return {
|
|
51
|
+
bytesPerPixel,
|
|
52
|
+
bytesPerRow,
|
|
53
|
+
rowsPerImage,
|
|
54
|
+
depthOrArrayLayers: depth,
|
|
55
|
+
bytesPerImage: bytesPerRow * rowsPerImage,
|
|
56
|
+
byteLength
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// HELPERS - CAPABILITIES
|
|
60
|
+
function getTextureFormatCapabilities(format) {
|
|
61
|
+
const info = getTextureFormatDefinition(format);
|
|
62
|
+
const formatCapabilities = {
|
|
63
|
+
format,
|
|
64
|
+
create: info.f ?? true,
|
|
65
|
+
render: info.render ?? true,
|
|
66
|
+
filter: info.filter ?? true,
|
|
67
|
+
blend: info.blend ?? true,
|
|
68
|
+
store: info.store ?? true
|
|
69
|
+
};
|
|
70
|
+
const formatInfo = getTextureFormatInfo(format);
|
|
71
|
+
const isDepthStencil = format.startsWith('depth') || format.startsWith('stencil');
|
|
72
|
+
const isSigned = formatInfo?.signed;
|
|
73
|
+
const isInteger = formatInfo?.integer;
|
|
74
|
+
const isWebGLSpecific = formatInfo?.webgl;
|
|
75
|
+
// signed formats are not renderable
|
|
76
|
+
formatCapabilities.render &&= !isSigned;
|
|
77
|
+
// signed and integer formats are not filterable
|
|
78
|
+
formatCapabilities.filter &&= !isDepthStencil && !isSigned && !isInteger && !isWebGLSpecific;
|
|
79
|
+
return formatCapabilities;
|
|
80
|
+
}
|
|
81
|
+
// HELPER - FORMAT INFO
|
|
56
82
|
/**
|
|
57
83
|
* Decodes a texture format, returning e.g. attatchment type, components, byte length and flags (integer, signed, normalized)
|
|
58
84
|
*/
|
|
59
|
-
function getTextureFormatInfo(format) {
|
|
85
|
+
export function getTextureFormatInfo(format) {
|
|
60
86
|
let formatInfo = getTextureFormatInfoUsingTable(format);
|
|
61
87
|
if (textureFormatDecoder.isCompressed(format)) {
|
|
62
88
|
formatInfo.channels = 'rgb';
|
|
@@ -77,7 +103,7 @@ function getTextureFormatInfo(format) {
|
|
|
77
103
|
const dataType = `${type}${length}`;
|
|
78
104
|
const decodedType = getDataTypeInfo(dataType);
|
|
79
105
|
const bits = decodedType.byteLength * 8;
|
|
80
|
-
const components = channels
|
|
106
|
+
const components = (channels?.length ?? 1);
|
|
81
107
|
const bitsPerChannel = [
|
|
82
108
|
bits,
|
|
83
109
|
components >= 2 ? bits : 0,
|
|
@@ -94,7 +120,7 @@ function getTextureFormatInfo(format) {
|
|
|
94
120
|
signed: decodedType.signed,
|
|
95
121
|
normalized: decodedType.normalized,
|
|
96
122
|
bitsPerChannel,
|
|
97
|
-
bytesPerPixel: decodedType.byteLength *
|
|
123
|
+
bytesPerPixel: decodedType.byteLength * components,
|
|
98
124
|
packed: formatInfo.packed,
|
|
99
125
|
srgb: formatInfo.srgb
|
|
100
126
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"texture-format-decoder.js","sourceRoot":"","sources":["../../../src/shadertypes/textures/texture-format-decoder.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAGpC,OAAO,EAAC,eAAe,EAAC,2CAAwC;
|
|
1
|
+
{"version":3,"file":"texture-format-decoder.js","sourceRoot":"","sources":["../../../src/shadertypes/textures/texture-format-decoder.ts"],"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,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,KAAK;QAC1B,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,KAAK;QAC9B,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,KAAK;QAC5B,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,KAAK;QACpC,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,KAAK;KACrC,CAAC;IAEF,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,kDAAkD;AAClD,SAAS,6BAA6B,CACpC,MAA+B;IAE/B,MAAM,KAAK,GAAG,mBAAmB,CAAC;IAClC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;IAC7C,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,CAAC,EAAE,UAAU,EAAE,WAAW,CAAC,GAAG,OAAO,CAAC;QAC5C,OAAO,EAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,EAAC,CAAC;IAC5E,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2GE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NormalizedDataType } from "../data-types/data-types.js";
|
|
1
|
+
import { NormalizedDataType, DataTypeArray, NormalizedDataTypeArray } from "../data-types/data-types.js";
|
|
2
2
|
/** Information about the structure of a texture format */
|
|
3
3
|
export type TextureFormatInfo = {
|
|
4
4
|
/** The format that is described */
|
|
@@ -51,6 +51,32 @@ export type TextureFormatCapabilities = {
|
|
|
51
51
|
/** If a feature string, the specified device feature determines if format is storeable. */
|
|
52
52
|
store: TextureFeature | boolean;
|
|
53
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* Memory layout for reading/writing data to a texture's memory.
|
|
56
|
+
*
|
|
57
|
+
* @note Due to alignment, GPU texture data is typically not contiguous.
|
|
58
|
+
*
|
|
59
|
+
* @note GPU texure data must be accessed according to this layout.
|
|
60
|
+
* - On CPU, only the range of rows that are actually read or written need to be allocated.
|
|
61
|
+
* - However, space for the full, padded/aligned rows must be allocated in the buffer,
|
|
62
|
+
* even if just a partial horizontal range `{x, width}` is actually read or written.
|
|
63
|
+
*
|
|
64
|
+
* @note byteLength = bytesPerRow * rowsPerImage * depthOrArrayLayers.
|
|
65
|
+
*/
|
|
66
|
+
export type TextureMemoryLayout = {
|
|
67
|
+
/** Total length in bytes */
|
|
68
|
+
byteLength: number;
|
|
69
|
+
/** Number of images */
|
|
70
|
+
depthOrArrayLayers: number;
|
|
71
|
+
/** Stride between successive images (Use when depthOrArrayLayers > 1) */
|
|
72
|
+
bytesPerImage: number;
|
|
73
|
+
/** Number of rows per image */
|
|
74
|
+
rowsPerImage: number;
|
|
75
|
+
/** Number of bytes per row (padded) */
|
|
76
|
+
bytesPerRow: number;
|
|
77
|
+
/** Number of bytes per pixel */
|
|
78
|
+
bytesPerPixel: number;
|
|
79
|
+
};
|
|
54
80
|
/**
|
|
55
81
|
* These represent the main compressed texture formats
|
|
56
82
|
* Each format typically has a number of more specific subformats
|
|
@@ -70,21 +96,22 @@ export type TextureFormatDepthStencil = 'stencil8' | 'depth16unorm' | 'depth24pl
|
|
|
70
96
|
/** Texture formats for color attachments */
|
|
71
97
|
export type TextureFormatColor = TextureFormatColorUncompressed | TextureFormatCompressed;
|
|
72
98
|
export type TextureFormatColorUncompressed = TextureFormatUnorm8 | TextureFormatSnorm8 | TextureFormatUint8 | TextureFormatSint8 | TextureFormatUnorm16 | TextureFormatSnorm16 | TextureFormatUint16 | TextureFormatSint16 | TextureFormatFloat16 | TextureFormatUint32 | TextureFormatSint32 | TextureFormatFloat32 | TextureFormatPacked16 | TextureFormatPacked32;
|
|
73
|
-
type TextureFormatUnorm8 = 'r8unorm' | 'rg8unorm' | 'rgb8unorm-webgl' | 'rgba8unorm' | 'rgba8unorm-srgb' | 'bgra8unorm' | 'bgra8unorm-srgb';
|
|
74
|
-
type TextureFormatSnorm8 = 'r8snorm' | 'rg8snorm' | 'rgb8snorm-webgl' | 'rgba8snorm';
|
|
75
|
-
type TextureFormatUint8 = 'r8uint' | 'rg8uint' | 'rgba8uint';
|
|
76
|
-
type TextureFormatSint8 = 'r8sint' | 'rg8sint' | 'rgba8sint';
|
|
77
|
-
type TextureFormatUnorm16 = 'r16unorm' | 'rg16unorm' | 'rgb16unorm-webgl' | 'rgba16unorm';
|
|
78
|
-
type TextureFormatSnorm16 = 'r16snorm' | 'rg16snorm' | 'rgb16snorm-webgl' | 'rgba16snorm';
|
|
79
|
-
type TextureFormatUint16 = 'r16uint' | 'rg16uint' | 'rgba16uint';
|
|
80
|
-
type TextureFormatSint16 = 'r16sint' | 'rg16sint' | 'rgba16sint';
|
|
81
|
-
type TextureFormatFloat16 = 'r16float' | 'rg16float' | 'rgba16float';
|
|
82
|
-
type TextureFormatUint32 = 'r32uint' | 'rg32uint' | 'rgba32uint';
|
|
83
|
-
type TextureFormatSint32 = 'r32sint' | 'rg32sint' | 'rgba32sint';
|
|
84
|
-
type TextureFormatFloat32 = 'r32float' | 'rg32float' | 'rgb32float-webgl' | 'rgba32float';
|
|
85
|
-
type TextureFormatPacked16 = 'rgba4unorm-webgl' | 'rgb565unorm-webgl' | 'rgb5a1unorm-webgl';
|
|
86
|
-
type TextureFormatPacked32 = 'rgb9e5ufloat' | 'rg11b10ufloat' | 'rgb10a2unorm' | 'rgb10a2uint';
|
|
99
|
+
export type TextureFormatUnorm8 = 'r8unorm' | 'rg8unorm' | 'rgb8unorm-webgl' | 'rgba8unorm' | 'rgba8unorm-srgb' | 'bgra8unorm' | 'bgra8unorm-srgb';
|
|
100
|
+
export type TextureFormatSnorm8 = 'r8snorm' | 'rg8snorm' | 'rgb8snorm-webgl' | 'rgba8snorm';
|
|
101
|
+
export type TextureFormatUint8 = 'r8uint' | 'rg8uint' | 'rgba8uint';
|
|
102
|
+
export type TextureFormatSint8 = 'r8sint' | 'rg8sint' | 'rgba8sint';
|
|
103
|
+
export type TextureFormatUnorm16 = 'r16unorm' | 'rg16unorm' | 'rgb16unorm-webgl' | 'rgba16unorm';
|
|
104
|
+
export type TextureFormatSnorm16 = 'r16snorm' | 'rg16snorm' | 'rgb16snorm-webgl' | 'rgba16snorm';
|
|
105
|
+
export type TextureFormatUint16 = 'r16uint' | 'rg16uint' | 'rgba16uint';
|
|
106
|
+
export type TextureFormatSint16 = 'r16sint' | 'rg16sint' | 'rgba16sint';
|
|
107
|
+
export type TextureFormatFloat16 = 'r16float' | 'rg16float' | 'rgba16float';
|
|
108
|
+
export type TextureFormatUint32 = 'r32uint' | 'rg32uint' | 'rgba32uint';
|
|
109
|
+
export type TextureFormatSint32 = 'r32sint' | 'rg32sint' | 'rgba32sint';
|
|
110
|
+
export type TextureFormatFloat32 = 'r32float' | 'rg32float' | 'rgb32float-webgl' | 'rgba32float';
|
|
111
|
+
export type TextureFormatPacked16 = 'rgba4unorm-webgl' | 'rgb565unorm-webgl' | 'rgb5a1unorm-webgl';
|
|
112
|
+
export type TextureFormatPacked32 = 'rgb9e5ufloat' | 'rg11b10ufloat' | 'rgb10a2unorm' | 'rgb10a2uint';
|
|
87
113
|
export type TextureFormatCompressed = 'bc1-rgb-unorm-webgl' | 'bc1-rgb-unorm-srgb-webgl' | 'pvrtc-rgb4unorm-webgl' | 'pvrtc-rgba4unorm-webgl' | 'pvrtc-rbg2unorm-webgl' | 'pvrtc-rgba2unorm-webgl' | 'etc1-rbg-unorm-webgl' | 'atc-rgb-unorm-webgl' | 'atc-rgba-unorm-webgl' | 'atc-rgbai-unorm-webgl' | 'bc1-rgba-unorm' | 'bc1-rgba-unorm-srgb' | 'bc2-rgba-unorm' | 'bc2-rgba-unorm-srgb' | 'bc3-rgba-unorm' | 'bc3-rgba-unorm-srgb' | 'bc4-r-unorm' | 'bc4-r-snorm' | 'bc5-rg-unorm' | 'bc5-rg-snorm' | 'bc6h-rgb-ufloat' | 'bc6h-rgb-float' | 'bc7-rgba-unorm' | 'bc7-rgba-unorm-srgb' | 'etc2-rgb8unorm' | 'etc2-rgb8unorm-srgb' | 'etc2-rgb8a1unorm' | 'etc2-rgb8a1unorm-srgb' | 'etc2-rgba8unorm' | 'etc2-rgba8unorm-srgb' | 'eac-r11unorm' | 'eac-r11snorm' | 'eac-rg11unorm' | 'eac-rg11snorm' | 'astc-4x4-unorm' | 'astc-4x4-unorm-srgb' | 'astc-5x4-unorm' | 'astc-5x4-unorm-srgb' | 'astc-5x5-unorm' | 'astc-5x5-unorm-srgb' | 'astc-6x5-unorm' | 'astc-6x5-unorm-srgb' | 'astc-6x6-unorm' | 'astc-6x6-unorm-srgb' | 'astc-8x5-unorm' | 'astc-8x5-unorm-srgb' | 'astc-8x6-unorm' | 'astc-8x6-unorm-srgb' | 'astc-8x8-unorm' | 'astc-8x8-unorm-srgb' | 'astc-10x5-unorm' | 'astc-10x5-unorm-srgb' | 'astc-10x6-unorm' | 'astc-10x6-unorm-srgb' | 'astc-10x8-unorm' | 'astc-10x8-unorm-srgb' | 'astc-10x10-unorm' | 'astc-10x10-unorm-srgb' | 'astc-12x10-unorm' | 'astc-12x10-unorm-srgb' | 'astc-12x12-unorm' | 'astc-12x12-unorm-srgb';
|
|
114
|
+
export type TextureFormatTypedArray<T extends TextureFormat> = DataTypeArray<TextureFormatDataType<T>>;
|
|
115
|
+
export type TextureFormatNormalizedTypedArray<T extends TextureFormat> = NormalizedDataTypeArray<TextureFormatDataType<T>>;
|
|
88
116
|
export type TextureFormatDataType<T extends TextureFormat> = T extends TextureFormatUint8 ? 'uint8' : T extends TextureFormatSint8 ? 'sint8' : T extends TextureFormatUnorm8 ? 'unorm8' : T extends TextureFormatSnorm8 ? 'snorm8' : T extends TextureFormatUint16 ? 'uint16' : T extends TextureFormatSint16 ? 'sint16' : T extends TextureFormatUnorm16 ? 'unorm16' : T extends TextureFormatSnorm16 ? 'snorm16' : T extends TextureFormatUint32 ? 'uint32' : T extends TextureFormatSint32 ? 'sint32' : T extends TextureFormatFloat16 ? 'float16' : T extends TextureFormatFloat32 ? 'float32' : T extends TextureFormatDepthStencil ? 'uint32' : T extends TextureFormatCompressed ? 'uint8' : T extends TextureFormatPacked16 ? 'uint16' : T extends TextureFormatPacked32 ? 'uint32' : never;
|
|
89
|
-
export {};
|
|
90
117
|
//# sourceMappingURL=texture-formats.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"texture-formats.d.ts","sourceRoot":"","sources":["../../../src/shadertypes/textures/texture-formats.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,kBAAkB,EAAC,oCAAiC;
|
|
1
|
+
{"version":3,"file":"texture-formats.d.ts","sourceRoot":"","sources":["../../../src/shadertypes/textures/texture-formats.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,kBAAkB,EAAE,aAAa,EAAE,uBAAuB,EAAC,oCAAiC;AAEpG,0DAA0D;AAC1D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,mCAAmC;IACnC,MAAM,EAAE,aAAa,CAAC;IACtB,gDAAgD;IAChD,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,eAAe,CAAC;IAC7D,wDAAwD;IACxD,QAAQ,EAAE,GAAG,GAAG,IAAI,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;IAC/C,4DAA4D;IAC5D,UAAU,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1B,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,gCAAgC;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,wEAAwE;IACxE,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,oCAAoC;IACpC,MAAM,CAAC,EAAE,OAAO,CAA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,CAAC,SAAS,qBAAqB,GAC7B,QAAQ,GACR,CAAC,SAAS,qBAAqB,GAC7B,QAAQ,GACR,KAAK,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"texture-formats.js","sourceRoot":"","sources":["../../../src/shadertypes/textures/texture-formats.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;;
|
|
1
|
+
{"version":3,"file":"texture-formats.js","sourceRoot":"","sources":["../../../src/shadertypes/textures/texture-formats.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;;AA8TpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoDE"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TypedArray } from '@math.gl/types';
|
|
2
|
+
import { type TextureFormat, type TextureMemoryLayout } from "./texture-formats.js";
|
|
3
|
+
export declare function getTextureImageView<T extends TextureFormat>(arrayBuffer: ArrayBuffer, memoryLayout: TextureMemoryLayout, format: T, image?: number): Uint32Array<ArrayBuffer> | Uint16Array<ArrayBuffer> | Uint8Array<ArrayBuffer> | Float32Array<ArrayBuffer>;
|
|
4
|
+
export declare function setTextureImageData<T extends TextureFormat>(arrayBuffer: ArrayBuffer, memoryLayout: TextureMemoryLayout, format: T, data: TypedArray, image?: number): void;
|
|
5
|
+
//# sourceMappingURL=texture-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"texture-layout.d.ts","sourceRoot":"","sources":["../../../src/shadertypes/textures/texture-layout.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAC,KAAK,aAAa,EAAE,KAAK,mBAAmB,EAAC,6BAA0B;AAG/E,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,aAAa,EACzD,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,mBAAmB,EACjC,MAAM,EAAE,CAAC,EACT,KAAK,SAAI,6GA8BV;AAED,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,aAAa,EACzD,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,mBAAmB,EACjC,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,UAAU,EAChB,KAAK,SAAI,GACR,IAAI,CASN"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { textureFormatDecoder } from "./texture-format-decoder.js";
|
|
5
|
+
export function getTextureImageView(arrayBuffer, memoryLayout, format, image = 0) {
|
|
6
|
+
const formatInfo = textureFormatDecoder.getInfo(format);
|
|
7
|
+
const bytesPerComponent = formatInfo.bytesPerPixel / formatInfo.components;
|
|
8
|
+
const { bytesPerImage } = memoryLayout;
|
|
9
|
+
const offset = bytesPerImage * image;
|
|
10
|
+
const totalPixels = memoryLayout.bytesPerImage / bytesPerComponent;
|
|
11
|
+
switch (format) {
|
|
12
|
+
case 'rgba8unorm':
|
|
13
|
+
case 'bgra8unorm':
|
|
14
|
+
case 'rgba8uint':
|
|
15
|
+
return new Uint8Array(arrayBuffer, offset, totalPixels);
|
|
16
|
+
case 'r8unorm':
|
|
17
|
+
return new Uint8Array(arrayBuffer, offset, totalPixels);
|
|
18
|
+
case 'r16uint':
|
|
19
|
+
case 'rgba16uint':
|
|
20
|
+
return new Uint16Array(arrayBuffer, offset, totalPixels);
|
|
21
|
+
case 'r32uint':
|
|
22
|
+
case 'rgba32uint':
|
|
23
|
+
return new Uint32Array(arrayBuffer, offset, totalPixels);
|
|
24
|
+
case 'r32float':
|
|
25
|
+
return new Float32Array(arrayBuffer, offset, totalPixels);
|
|
26
|
+
case 'rgba16float':
|
|
27
|
+
return new Uint16Array(arrayBuffer, offset, totalPixels); // 4 channels
|
|
28
|
+
case 'rgba32float':
|
|
29
|
+
return new Float32Array(arrayBuffer, offset, totalPixels);
|
|
30
|
+
default:
|
|
31
|
+
throw new Error(`Unsupported format: ${format}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function setTextureImageData(arrayBuffer, memoryLayout, format, data, image = 0) {
|
|
35
|
+
const offset = 0; // memoryLayout.bytesPerImage * image;
|
|
36
|
+
const totalPixels = memoryLayout.bytesPerImage / memoryLayout.bytesPerPixel;
|
|
37
|
+
const subArray = data.subarray(0, totalPixels);
|
|
38
|
+
const typedArray = getTextureImageView(arrayBuffer, memoryLayout, format, image);
|
|
39
|
+
typedArray.set(subArray, offset);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=texture-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"texture-layout.js","sourceRoot":"","sources":["../../../src/shadertypes/textures/texture-layout.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,OAAO,EAAC,oBAAoB,EAAC,oCAAiC;AAE9D,MAAM,UAAU,mBAAmB,CACjC,WAAwB,EACxB,YAAiC,EACjC,MAAS,EACT,KAAK,GAAG,CAAC;IAET,MAAM,UAAU,GAAG,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxD,MAAM,iBAAiB,GAAG,UAAU,CAAC,aAAa,GAAG,UAAU,CAAC,UAAU,CAAC;IAC3E,MAAM,EAAC,aAAa,EAAC,GAAG,YAAY,CAAC;IACrC,MAAM,MAAM,GAAG,aAAa,GAAG,KAAK,CAAC;IACrC,MAAM,WAAW,GAAG,YAAY,CAAC,aAAa,GAAG,iBAAiB,CAAC;IAEnE,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,YAAY,CAAC;QAClB,KAAK,YAAY,CAAC;QAClB,KAAK,WAAW;YACd,OAAO,IAAI,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC1D,KAAK,SAAS;YACZ,OAAO,IAAI,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC1D,KAAK,SAAS,CAAC;QACf,KAAK,YAAY;YACf,OAAO,IAAI,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC3D,KAAK,SAAS,CAAC;QACf,KAAK,YAAY;YACf,OAAO,IAAI,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC3D,KAAK,UAAU;YACb,OAAO,IAAI,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC5D,KAAK,aAAa;YAChB,OAAO,IAAI,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,aAAa;QACzE,KAAK,aAAa;YAChB,OAAO,IAAI,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC5D;YACE,MAAM,IAAI,KAAK,CAAC,uBAAuB,MAAM,EAAE,CAAC,CAAC;IACrD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,WAAwB,EACxB,YAAiC,EACjC,MAAS,EACT,IAAgB,EAChB,KAAK,GAAG,CAAC;IAET,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,sCAAsC;IAExD,MAAM,WAAW,GAAG,YAAY,CAAC,aAAa,GAAG,YAAY,CAAC,aAAa,CAAC;IAC5E,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IAE/C,MAAM,UAAU,GAAG,mBAAmB,CAAC,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAEjF,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Throws if condition is true and narrows type */
|
|
2
|
+
export declare function assert(condition: unknown, message?: string): asserts condition;
|
|
3
|
+
/** Throws if value is not defined, narrows type */
|
|
4
|
+
export declare function assertDefined<T>(value: T | undefined, message?: string): T;
|
|
5
|
+
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/utils/assert.ts"],"names":[],"mappings":"AAIA,mDAAmD;AACnD,wBAAgB,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAM9E;AAED,mDAAmD;AACnD,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAG1E"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/** Throws if condition is true and narrows type */
|
|
5
|
+
export function assert(condition, message) {
|
|
6
|
+
if (!condition) {
|
|
7
|
+
const error = new Error(message ?? 'luma.gl assertion failed.');
|
|
8
|
+
Error.captureStackTrace?.(error, assert);
|
|
9
|
+
throw error;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** Throws if value is not defined, narrows type */
|
|
13
|
+
export function assertDefined(value, message) {
|
|
14
|
+
assert(value, message);
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=assert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../src/utils/assert.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,mDAAmD;AACnD,MAAM,UAAU,MAAM,CAAC,SAAkB,EAAE,OAAgB;IACzD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,IAAI,2BAA2B,CAAC,CAAC;QAChE,KAAK,CAAC,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACzC,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,mDAAmD;AACnD,MAAM,UAAU,aAAa,CAAI,KAAoB,EAAE,OAAgB;IACrE,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACvB,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/core",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.3.0-alpha.4",
|
|
4
4
|
"description": "The luma.gl core Device API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@math.gl/types": "^4.1.0",
|
|
44
|
-
"@probe.gl/env": "^4.
|
|
45
|
-
"@probe.gl/log": "^4.
|
|
46
|
-
"@probe.gl/stats": "^4.
|
|
44
|
+
"@probe.gl/env": "^4.1.1",
|
|
45
|
+
"@probe.gl/log": "^4.1.1",
|
|
46
|
+
"@probe.gl/stats": "^4.1.1",
|
|
47
47
|
"@types/offscreencanvas": "^2019.6.4"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "7486e7b0377fb6ab961b4499828681bede60f3b1"
|
|
50
50
|
}
|
|
@@ -8,6 +8,7 @@ import type {Framebuffer} from './resources/framebuffer';
|
|
|
8
8
|
import type {TextureFormatDepthStencil} from '../shadertypes/textures/texture-formats';
|
|
9
9
|
import {uid} from '../utils/uid';
|
|
10
10
|
import {withResolvers} from '../utils/promise-utils';
|
|
11
|
+
import {assertDefined} from '../utils/assert';
|
|
11
12
|
|
|
12
13
|
/** Properties for a CanvasContext */
|
|
13
14
|
export type CanvasContextProps = {
|
|
@@ -106,11 +107,19 @@ export abstract class CanvasContext {
|
|
|
106
107
|
/** Height of drawing buffer: automatically tracks this.pixelHeight if props.autoResize is true */
|
|
107
108
|
drawingBufferHeight: number;
|
|
108
109
|
|
|
110
|
+
/** Resolves when the canvas is initialized, i.e. when the ResizeObserver has updated the pixel size */
|
|
109
111
|
protected _initializedResolvers = withResolvers<void>();
|
|
112
|
+
/** ResizeObserver to track canvas size changes */
|
|
110
113
|
protected readonly _resizeObserver: ResizeObserver | undefined;
|
|
114
|
+
/** IntersectionObserver to track canvas visibility changes */
|
|
111
115
|
protected readonly _intersectionObserver: IntersectionObserver | undefined;
|
|
112
|
-
|
|
116
|
+
private _observeDevicePixelRatioTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
117
|
+
/** Position of the canvas in the document, updated by a timer */
|
|
118
|
+
protected _position: [number, number] = [0, 0];
|
|
119
|
+
/** Whether this canvas context has been destroyed */
|
|
113
120
|
protected destroyed = false;
|
|
121
|
+
/** Whether the drawing buffer size needs to be resized (deferred resizing to avoid flicker) */
|
|
122
|
+
protected _needsDrawingBufferResize: boolean = true;
|
|
114
123
|
|
|
115
124
|
abstract get [Symbol.toStringTag](): string;
|
|
116
125
|
|
|
@@ -178,7 +187,7 @@ export abstract class CanvasContext {
|
|
|
178
187
|
|
|
179
188
|
// Track device pixel ratio changes.
|
|
180
189
|
// Defer call to after construction completes to ensure `this.device` is available.
|
|
181
|
-
setTimeout(() => this._observeDevicePixelRatio(), 0);
|
|
190
|
+
this._observeDevicePixelRatioTimeout = setTimeout(() => this._observeDevicePixelRatio(), 0);
|
|
182
191
|
|
|
183
192
|
// Track top/left position changes
|
|
184
193
|
if (this.props.trackPosition) {
|
|
@@ -188,7 +197,18 @@ export abstract class CanvasContext {
|
|
|
188
197
|
}
|
|
189
198
|
|
|
190
199
|
destroy() {
|
|
191
|
-
this.destroyed
|
|
200
|
+
if (!this.destroyed) {
|
|
201
|
+
this.destroyed = true;
|
|
202
|
+
if (this._observeDevicePixelRatioTimeout) {
|
|
203
|
+
clearTimeout(this._observeDevicePixelRatioTimeout);
|
|
204
|
+
this._observeDevicePixelRatioTimeout = null;
|
|
205
|
+
}
|
|
206
|
+
// @ts-expect-error Clear the device to make sure we don't access it after destruction.
|
|
207
|
+
this.device = null;
|
|
208
|
+
// Disconnect observers to prevent callbacks from firing after destruction
|
|
209
|
+
this._resizeObserver?.disconnect();
|
|
210
|
+
this._intersectionObserver?.disconnect();
|
|
211
|
+
}
|
|
192
212
|
}
|
|
193
213
|
|
|
194
214
|
setProps(props: MutableCanvasContextProps): this {
|
|
@@ -200,9 +220,12 @@ export abstract class CanvasContext {
|
|
|
200
220
|
}
|
|
201
221
|
|
|
202
222
|
/** Returns a framebuffer with properly resized current 'swap chain' textures */
|
|
203
|
-
|
|
223
|
+
getCurrentFramebuffer(options?: {
|
|
204
224
|
depthStencilFormat?: TextureFormatDepthStencil | false;
|
|
205
|
-
}): Framebuffer
|
|
225
|
+
}): Framebuffer {
|
|
226
|
+
this._resizeDrawingBufferIfNeeded();
|
|
227
|
+
return this._getCurrentFramebuffer(options);
|
|
228
|
+
}
|
|
206
229
|
|
|
207
230
|
// SIZE METHODS
|
|
208
231
|
|
|
@@ -239,13 +262,22 @@ export abstract class CanvasContext {
|
|
|
239
262
|
return [maxTextureDimension, maxTextureDimension];
|
|
240
263
|
}
|
|
241
264
|
|
|
242
|
-
/**
|
|
265
|
+
/**
|
|
266
|
+
* Update the canvas drawing buffer size.
|
|
267
|
+
* @note - Called automatically if props.autoResize is true.
|
|
268
|
+
* @note - Defers update of drawing buffer size until framebuffer is requested to avoid flicker
|
|
269
|
+
* (resizing clears the drawing buffer)!
|
|
270
|
+
*/
|
|
243
271
|
setDrawingBufferSize(width: number, height: number) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
272
|
+
width = Math.floor(width);
|
|
273
|
+
height = Math.floor(height);
|
|
274
|
+
if (this.drawingBufferWidth === width && this.drawingBufferHeight === height) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
// TODO(ib) - temporarily makes drawingBufferWidth/Height out of sync with canvas.width/height, could that cause issues?
|
|
247
278
|
this.drawingBufferWidth = width;
|
|
248
279
|
this.drawingBufferHeight = height;
|
|
280
|
+
this._needsDrawingBufferResize = true;
|
|
249
281
|
}
|
|
250
282
|
|
|
251
283
|
/**
|
|
@@ -311,7 +343,12 @@ export abstract class CanvasContext {
|
|
|
311
343
|
* Can be called after changes to size or props,
|
|
312
344
|
* to give implementation an opportunity to update configurations.
|
|
313
345
|
*/
|
|
314
|
-
protected abstract
|
|
346
|
+
protected abstract _configureDevice(): void;
|
|
347
|
+
|
|
348
|
+
/** Returns a framebuffer with properly resized current 'swap chain' textures */
|
|
349
|
+
protected abstract _getCurrentFramebuffer(options?: {
|
|
350
|
+
depthStencilFormat?: TextureFormatDepthStencil | false;
|
|
351
|
+
}): Framebuffer;
|
|
315
352
|
|
|
316
353
|
// IMPLEMENTATION
|
|
317
354
|
|
|
@@ -327,6 +364,10 @@ export abstract class CanvasContext {
|
|
|
327
364
|
|
|
328
365
|
/** reacts to an observed intersection */
|
|
329
366
|
protected _handleIntersection(entries: IntersectionObserverEntry[]) {
|
|
367
|
+
if (this.destroyed) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
|
|
330
371
|
const entry = entries.find(entry_ => entry_.target === this.canvas);
|
|
331
372
|
if (!entry) {
|
|
332
373
|
return;
|
|
@@ -345,14 +386,19 @@ export abstract class CanvasContext {
|
|
|
345
386
|
* @see https://webgpufundamentals.org/webgpu/lessons/webgpu-resizing-the-canvas.html
|
|
346
387
|
*/
|
|
347
388
|
protected _handleResize(entries: ResizeObserverEntry[]) {
|
|
389
|
+
if (this.destroyed) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
|
|
348
393
|
const entry = entries.find(entry_ => entry_.target === this.canvas);
|
|
349
394
|
if (!entry) {
|
|
350
395
|
return;
|
|
351
396
|
}
|
|
352
397
|
|
|
398
|
+
const contentBoxSize = assertDefined(entry.contentBoxSize?.[0]);
|
|
353
399
|
// Update CSS size using content box size
|
|
354
|
-
this.cssWidth =
|
|
355
|
-
this.cssHeight =
|
|
400
|
+
this.cssWidth = contentBoxSize.inlineSize;
|
|
401
|
+
this.cssHeight = contentBoxSize.blockSize;
|
|
356
402
|
|
|
357
403
|
// Update our drawing buffer size variables, saving the old values for logging
|
|
358
404
|
const oldPixelSize = this.getDevicePixelSize();
|
|
@@ -361,12 +407,12 @@ export abstract class CanvasContext {
|
|
|
361
407
|
// Note: content box sizes are guaranteed to be integers
|
|
362
408
|
// Note: Safari falls back to contentBoxSize
|
|
363
409
|
const devicePixelWidth =
|
|
364
|
-
entry.devicePixelContentBoxSize?.[0]
|
|
365
|
-
|
|
410
|
+
entry.devicePixelContentBoxSize?.[0]?.inlineSize ||
|
|
411
|
+
contentBoxSize.inlineSize * devicePixelRatio;
|
|
366
412
|
|
|
367
413
|
const devicePixelHeight =
|
|
368
|
-
entry.devicePixelContentBoxSize?.[0]
|
|
369
|
-
|
|
414
|
+
entry.devicePixelContentBoxSize?.[0]?.blockSize ||
|
|
415
|
+
contentBoxSize.blockSize * devicePixelRatio;
|
|
370
416
|
|
|
371
417
|
// Make sure we don't overflow the maximum supported texture size
|
|
372
418
|
const [maxDevicePixelWidth, maxDevicePixelHeight] = this.getMaxDrawingBufferSize();
|
|
@@ -379,6 +425,7 @@ export abstract class CanvasContext {
|
|
|
379
425
|
this.device.props.onResize(this, {oldPixelSize});
|
|
380
426
|
}
|
|
381
427
|
|
|
428
|
+
/** Initiate a deferred update for the canvas drawing buffer size */
|
|
382
429
|
protected _updateDrawingBufferSize() {
|
|
383
430
|
// Update the canvas drawing buffer size
|
|
384
431
|
if (this.props.autoResize) {
|
|
@@ -390,9 +437,6 @@ export abstract class CanvasContext {
|
|
|
390
437
|
} else {
|
|
391
438
|
this.setDrawingBufferSize(this.cssWidth, this.cssHeight);
|
|
392
439
|
}
|
|
393
|
-
|
|
394
|
-
// Inform the subclass
|
|
395
|
-
this._updateDevice();
|
|
396
440
|
}
|
|
397
441
|
|
|
398
442
|
// Resolve the initialized promise
|
|
@@ -402,15 +446,35 @@ export abstract class CanvasContext {
|
|
|
402
446
|
this.updatePosition();
|
|
403
447
|
}
|
|
404
448
|
|
|
449
|
+
/** Perform a deferred resize of the drawing buffer if needed */
|
|
450
|
+
_resizeDrawingBufferIfNeeded() {
|
|
451
|
+
if (this._needsDrawingBufferResize) {
|
|
452
|
+
this._needsDrawingBufferResize = false;
|
|
453
|
+
const sizeChanged =
|
|
454
|
+
this.drawingBufferWidth !== this.canvas.width ||
|
|
455
|
+
this.drawingBufferHeight !== this.canvas.height;
|
|
456
|
+
if (sizeChanged) {
|
|
457
|
+
// Update the canvas size
|
|
458
|
+
this.canvas.width = this.drawingBufferWidth;
|
|
459
|
+
this.canvas.height = this.drawingBufferHeight;
|
|
460
|
+
// Inform the subclass: WebGPU needs to call canvascontext.configure()
|
|
461
|
+
this._configureDevice();
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
405
466
|
/** Monitor DPR changes */
|
|
406
467
|
_observeDevicePixelRatio() {
|
|
468
|
+
if (this.destroyed) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
407
471
|
const oldRatio = this.devicePixelRatio;
|
|
408
472
|
this.devicePixelRatio = window.devicePixelRatio;
|
|
409
473
|
|
|
410
474
|
this.updatePosition();
|
|
411
475
|
|
|
412
476
|
// Inform the device
|
|
413
|
-
this.device.props.onDevicePixelRatioChange(this, {oldRatio});
|
|
477
|
+
this.device.props.onDevicePixelRatioChange?.(this, {oldRatio});
|
|
414
478
|
// Set up a one time query against the current resolution.
|
|
415
479
|
matchMedia(`(resolution: ${this.devicePixelRatio}dppx)`).addEventListener(
|
|
416
480
|
'change',
|
|
@@ -436,6 +500,9 @@ export abstract class CanvasContext {
|
|
|
436
500
|
* if called before browser has finished a reflow. Should not be the case here.
|
|
437
501
|
*/
|
|
438
502
|
updatePosition() {
|
|
503
|
+
if (this.destroyed) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
439
506
|
const newRect = this.htmlCanvas?.getBoundingClientRect();
|
|
440
507
|
if (newRect) {
|
|
441
508
|
// We only track position since we rely on the more precise ResizeObserver for size
|