@luma.gl/engine 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/animation-loop/animation-loop.d.ts +3 -1
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +10 -4
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/compute/computation.d.ts.map +1 -1
- package/dist/compute/computation.js +3 -2
- package/dist/compute/computation.js.map +1 -1
- package/dist/compute/swap.d.ts +2 -0
- package/dist/compute/swap.d.ts.map +1 -1
- package/dist/compute/swap.js +10 -5
- package/dist/compute/swap.js.map +1 -1
- package/dist/dist.dev.js +1251 -574
- package/dist/dist.min.js +216 -48
- package/dist/dynamic-texture/dynamic-texture.d.ts +95 -0
- package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -0
- package/dist/dynamic-texture/dynamic-texture.js +389 -0
- package/dist/dynamic-texture/dynamic-texture.js.map +1 -0
- package/dist/dynamic-texture/mipmaps.d.ts +6 -0
- package/dist/dynamic-texture/mipmaps.d.ts.map +1 -0
- package/dist/dynamic-texture/mipmaps.js +441 -0
- package/dist/dynamic-texture/mipmaps.js.map +1 -0
- package/dist/dynamic-texture/texture-data.d.ts +137 -0
- package/dist/dynamic-texture/texture-data.d.ts.map +1 -0
- package/dist/dynamic-texture/texture-data.js +183 -0
- package/dist/dynamic-texture/texture-data.js.map +1 -0
- package/dist/factories/pipeline-factory.d.ts.map +1 -1
- package/dist/factories/pipeline-factory.js +3 -3
- package/dist/factories/pipeline-factory.js.map +1 -1
- package/dist/factories/shader-factory.d.ts.map +1 -1
- package/dist/factories/shader-factory.js +3 -2
- package/dist/factories/shader-factory.js.map +1 -1
- package/dist/index.cjs +1243 -583
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/model/model.d.ts +31 -10
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +34 -14
- package/dist/model/model.js.map +1 -1
- package/dist/models/billboard-texture-model.d.ts +8 -5
- package/dist/models/billboard-texture-model.d.ts.map +1 -1
- package/dist/models/billboard-texture-model.js +70 -18
- package/dist/models/billboard-texture-model.js.map +1 -1
- package/dist/passes/get-fragment-shader.js +15 -11
- package/dist/passes/get-fragment-shader.js.map +1 -1
- package/dist/passes/shader-pass-renderer.d.ts +5 -5
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
- package/dist/passes/shader-pass-renderer.js +13 -12
- package/dist/passes/shader-pass-renderer.js.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/buffer-layout-order.d.ts.map +1 -1
- package/dist/utils/buffer-layout-order.js +12 -2
- package/dist/utils/buffer-layout-order.js.map +1 -1
- package/package.json +6 -6
- package/src/animation-loop/animation-loop.ts +11 -4
- package/src/compute/computation.ts +3 -2
- package/src/compute/swap.ts +13 -7
- package/src/dynamic-texture/dynamic-texture.ts +499 -0
- package/src/dynamic-texture/mipmaps.ts +517 -0
- package/src/dynamic-texture/texture-data.ts +301 -0
- package/src/factories/pipeline-factory.ts +4 -3
- package/src/factories/shader-factory.ts +4 -2
- package/src/index.ts +9 -4
- package/src/model/model.ts +37 -18
- package/src/models/billboard-texture-model.ts +81 -22
- package/src/passes/get-fragment-shader.ts +15 -11
- package/src/passes/shader-pass-renderer.ts +22 -16
- package/src/types.ts +11 -0
- package/src/utils/buffer-layout-order.ts +18 -2
- package/dist/async-texture/async-texture.d.ts +0 -166
- package/dist/async-texture/async-texture.d.ts.map +0 -1
- package/dist/async-texture/async-texture.js +0 -386
- package/dist/async-texture/async-texture.js.map +0 -1
- package/src/async-texture/async-texture.ts +0 -551
- /package/src/{async-texture/texture-setters.ts.disabled → dynamic-texture/texture-data.ts.disabled} +0 -0
|
@@ -3,24 +3,35 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {Device, Texture} from '@luma.gl/core';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import type {ShaderModule} from '@luma.gl/shadertools';
|
|
7
|
+
import {DynamicTexture} from '../dynamic-texture/dynamic-texture';
|
|
8
|
+
import {ClipSpace, ClipSpaceProps} from './clip-space';
|
|
9
|
+
|
|
10
|
+
const backgroundModule = {
|
|
11
|
+
name: 'background',
|
|
12
|
+
uniformTypes: {
|
|
13
|
+
scale: 'vec2<f32>'
|
|
14
|
+
}
|
|
15
|
+
} as const satisfies ShaderModule<{}, {scale: [number, number]}>;
|
|
8
16
|
|
|
9
17
|
const BACKGROUND_FS_WGSL = /* wgsl */ `\
|
|
10
18
|
@group(0) @binding(0) var backgroundTexture: texture_2d<f32>;
|
|
11
19
|
@group(0) @binding(1) var backgroundTextureSampler: sampler;
|
|
20
|
+
struct backgroundUniforms {
|
|
21
|
+
scale: vec2<f32>,
|
|
22
|
+
};
|
|
23
|
+
@group(0) @binding(2) var<uniform> background: backgroundUniforms;
|
|
12
24
|
|
|
13
25
|
fn billboardTexture_getTextureUV(coordinates: vec2<f32>) -> vec2<f32> {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
26
|
+
let scale: vec2<f32> = background.scale;
|
|
27
|
+
var position: vec2<f32> = (coordinates - vec2<f32>(0.5, 0.5)) / scale + vec2<f32>(0.5, 0.5);
|
|
28
|
+
return position;
|
|
29
|
+
}
|
|
19
30
|
|
|
20
31
|
@fragment
|
|
21
32
|
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {
|
|
22
|
-
|
|
23
|
-
|
|
33
|
+
let position: vec2<f32> = billboardTexture_getTextureUV(inputs.coordinate);
|
|
34
|
+
return textureSample(backgroundTexture, backgroundTextureSampler, position);
|
|
24
35
|
}
|
|
25
36
|
`;
|
|
26
37
|
|
|
@@ -29,17 +40,21 @@ const BACKGROUND_FS = /* glsl */ `\
|
|
|
29
40
|
precision highp float;
|
|
30
41
|
|
|
31
42
|
uniform sampler2D backgroundTexture;
|
|
43
|
+
|
|
44
|
+
uniform backgroundUniforms {
|
|
45
|
+
vec2 scale;
|
|
46
|
+
} background;
|
|
47
|
+
|
|
48
|
+
in vec2 coordinate;
|
|
32
49
|
out vec4 fragColor;
|
|
33
50
|
|
|
34
|
-
vec2 billboardTexture_getTextureUV() {
|
|
35
|
-
|
|
36
|
-
vec2 texSize = vec2(float(iTexSize.x), float(iTexSize.y));
|
|
37
|
-
vec2 position = gl_FragCoord.xy / texSize;
|
|
51
|
+
vec2 billboardTexture_getTextureUV(vec2 coord) {
|
|
52
|
+
vec2 position = (coord - 0.5) / background.scale + 0.5;
|
|
38
53
|
return position;
|
|
39
54
|
}
|
|
40
55
|
|
|
41
56
|
void main(void) {
|
|
42
|
-
vec2 position = billboardTexture_getTextureUV();
|
|
57
|
+
vec2 position = billboardTexture_getTextureUV(coordinate);
|
|
43
58
|
fragColor = texture(backgroundTexture, position);
|
|
44
59
|
}
|
|
45
60
|
`;
|
|
@@ -47,11 +62,11 @@ void main(void) {
|
|
|
47
62
|
/**
|
|
48
63
|
* Props for a Model that renders a bitmap into the "background", i.e covering the screen
|
|
49
64
|
*/
|
|
50
|
-
export type BackgroundTextureModelProps = {
|
|
65
|
+
export type BackgroundTextureModelProps = ClipSpaceProps & {
|
|
51
66
|
/** id of this model */
|
|
52
67
|
id?: string;
|
|
53
68
|
/** The texture to render */
|
|
54
|
-
backgroundTexture: Texture |
|
|
69
|
+
backgroundTexture: Texture | DynamicTexture;
|
|
55
70
|
/** If true, the texture is rendered into transparent areas of the screen only, i.e blended in where background alpha is small */
|
|
56
71
|
blend?: boolean;
|
|
57
72
|
};
|
|
@@ -60,11 +75,14 @@ export type BackgroundTextureModelProps = {
|
|
|
60
75
|
* Model that renders a bitmap into the "background", i.e covering the screen
|
|
61
76
|
*/
|
|
62
77
|
export class BackgroundTextureModel extends ClipSpace {
|
|
78
|
+
backgroundTexture: Texture = null!;
|
|
79
|
+
|
|
63
80
|
constructor(device: Device, props: BackgroundTextureModelProps) {
|
|
64
81
|
super(device, {
|
|
65
82
|
id: props.id || 'background-texture-model',
|
|
66
83
|
source: BACKGROUND_FS_WGSL,
|
|
67
84
|
fs: BACKGROUND_FS,
|
|
85
|
+
modules: [backgroundModule],
|
|
68
86
|
parameters: {
|
|
69
87
|
depthWriteEnabled: false,
|
|
70
88
|
...(props.blend
|
|
@@ -84,17 +102,58 @@ export class BackgroundTextureModel extends ClipSpace {
|
|
|
84
102
|
if (!props.backgroundTexture) {
|
|
85
103
|
throw new Error('BackgroundTextureModel requires a backgroundTexture prop');
|
|
86
104
|
}
|
|
87
|
-
this.
|
|
105
|
+
this.setProps(props);
|
|
88
106
|
}
|
|
89
107
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
108
|
+
/** Update the background texture */
|
|
109
|
+
setProps(props: Partial<BackgroundTextureModelProps>): void {
|
|
110
|
+
const {backgroundTexture} = props;
|
|
111
|
+
if (backgroundTexture) {
|
|
112
|
+
this.setBindings({backgroundTexture});
|
|
113
|
+
|
|
114
|
+
if (backgroundTexture.isReady) {
|
|
115
|
+
const texture =
|
|
116
|
+
backgroundTexture instanceof DynamicTexture
|
|
117
|
+
? backgroundTexture.texture
|
|
118
|
+
: backgroundTexture;
|
|
119
|
+
this.backgroundTexture = texture;
|
|
120
|
+
this.updateScale(texture);
|
|
121
|
+
} else {
|
|
122
|
+
backgroundTexture.ready.then(texture => {
|
|
123
|
+
this.backgroundTexture = texture;
|
|
124
|
+
this.updateScale(texture);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
94
128
|
}
|
|
95
129
|
|
|
96
130
|
override predraw(): void {
|
|
97
|
-
this.
|
|
131
|
+
// this.updateScale(this.backgroundTexture);
|
|
98
132
|
super.predraw();
|
|
99
133
|
}
|
|
134
|
+
|
|
135
|
+
updateScale(texture: Texture): void {
|
|
136
|
+
if (!texture) {
|
|
137
|
+
// Initial scale to avoid rendering issues before texture is loaded
|
|
138
|
+
this.shaderInputs.setProps({background: {scale: [1, 1]}});
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const [screenWidth, screenHeight] = this.device.getCanvasContext().getDrawingBufferSize();
|
|
142
|
+
|
|
143
|
+
const textureWidth = texture.width;
|
|
144
|
+
const textureHeight = texture.height;
|
|
145
|
+
|
|
146
|
+
const screenAspect = screenWidth / screenHeight;
|
|
147
|
+
const textureAspect = textureWidth / textureHeight;
|
|
148
|
+
|
|
149
|
+
let scaleX = 1;
|
|
150
|
+
let scaleY = 1;
|
|
151
|
+
if (screenAspect > textureAspect) {
|
|
152
|
+
scaleY = screenAspect / textureAspect;
|
|
153
|
+
} else {
|
|
154
|
+
scaleX = textureAspect / screenAspect;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
this.shaderInputs.setProps({background: {scale: [scaleX, scaleY]}});
|
|
158
|
+
}
|
|
100
159
|
}
|
|
@@ -39,19 +39,23 @@ function getFilterShaderWGSL(func: string) {
|
|
|
39
39
|
// Binding 0:1 is reserved for shader passes
|
|
40
40
|
// @group(0) @binding(0) var<uniform> brightnessContrast : brightnessContrastUniforms;
|
|
41
41
|
@group(0) @binding(1) var texture: texture_2d<f32>;
|
|
42
|
-
@group(0) @binding(2) var
|
|
42
|
+
@group(0) @binding(2) var textureSampler: sampler;
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
// This needs to be aligned with
|
|
45
|
+
// struct FragmentInputs {
|
|
46
|
+
// @location(0) fragUV: vec2f,
|
|
47
|
+
// @location(1) fragPosition: vec4f,
|
|
48
|
+
// @location(2) fragCoordinate: vec4f
|
|
49
|
+
// };
|
|
49
50
|
|
|
50
51
|
@fragment
|
|
51
52
|
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {
|
|
52
|
-
let
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
let fragUV = inputs.uv;
|
|
54
|
+
let fragCoordinate = inputs.coordinate;
|
|
55
|
+
let texSize = vec2f(textureDimensions(texture, 0));
|
|
56
|
+
|
|
57
|
+
var fragColor = textureSample(texture, textureSampler, fragUV);
|
|
58
|
+
fragColor = ${func}(fragColor, texSize, fragCoordinate);
|
|
55
59
|
return fragColor;
|
|
56
60
|
}
|
|
57
61
|
`;
|
|
@@ -73,9 +77,9 @@ struct FragmentInputs = {
|
|
|
73
77
|
|
|
74
78
|
@fragment
|
|
75
79
|
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {
|
|
76
|
-
let texSize = textureDimensions(texture, 0);
|
|
80
|
+
let texSize = vec2f(textureDimensions(texture, 0));
|
|
77
81
|
var fragColor = textureSample(texture, sampler, fragUV);
|
|
78
|
-
fragColor = ${func}(
|
|
82
|
+
fragColor = ${func}(fragColor, texSize, texCoord);
|
|
79
83
|
return fragColor;
|
|
80
84
|
}
|
|
81
85
|
`;
|
|
@@ -6,7 +6,7 @@ import {Device, RenderPass, Texture} from '@luma.gl/core';
|
|
|
6
6
|
import type {ShaderPass} from '@luma.gl/shadertools';
|
|
7
7
|
import {initializeShaderModule} from '@luma.gl/shadertools';
|
|
8
8
|
import {ShaderInputs} from '../shader-inputs';
|
|
9
|
-
import {
|
|
9
|
+
import {DynamicTexture} from '../dynamic-texture/dynamic-texture';
|
|
10
10
|
import {ClipSpace} from '../models/clip-space';
|
|
11
11
|
import {SwapFramebuffers} from '../compute/swap';
|
|
12
12
|
import {BackgroundTextureModel} from '../models/billboard-texture-model';
|
|
@@ -20,7 +20,7 @@ export type ShaderPassRendererProps = {
|
|
|
20
20
|
/** List of ShaderPasses to apply to the sourceTexture */
|
|
21
21
|
shaderPasses: ShaderPass[];
|
|
22
22
|
/** Optional typed ShaderInputs object for setting uniforms */
|
|
23
|
-
shaderInputs
|
|
23
|
+
shaderInputs?: ShaderInputs;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
/** A pass that renders a given texture into screen space */
|
|
@@ -72,12 +72,10 @@ fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {
|
|
|
72
72
|
|
|
73
73
|
uniform sampler2D sourceTexture;
|
|
74
74
|
in vec2 uv;
|
|
75
|
-
in vec2 coordinate;
|
|
76
75
|
out vec4 fragColor;
|
|
77
76
|
|
|
78
77
|
void main() {
|
|
79
|
-
|
|
80
|
-
fragColor = texture(sourceTexture, coordinate);
|
|
78
|
+
fragColor = texture(sourceTexture, uv);
|
|
81
79
|
}
|
|
82
80
|
`
|
|
83
81
|
});
|
|
@@ -92,14 +90,19 @@ void main() {
|
|
|
92
90
|
}
|
|
93
91
|
this.swapFramebuffers.destroy();
|
|
94
92
|
this.clipSpace.destroy();
|
|
93
|
+
this.textureModel.destroy();
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
resize(width: number, height: number): void {
|
|
98
|
-
this.
|
|
99
|
-
|
|
96
|
+
resize(size?: [width: number, height: number]): void {
|
|
97
|
+
size ||= this.device.getCanvasContext().getDrawingBufferSize();
|
|
98
|
+
this.swapFramebuffers.resize({width: size[0], height: size[1]});
|
|
100
99
|
}
|
|
101
100
|
|
|
102
|
-
renderToScreen(options: {
|
|
101
|
+
renderToScreen(options: {
|
|
102
|
+
sourceTexture: DynamicTexture;
|
|
103
|
+
uniforms?: any;
|
|
104
|
+
bindings?: any;
|
|
105
|
+
}): boolean {
|
|
103
106
|
// Run the shader passes and generate an output texture
|
|
104
107
|
const outputTexture = this.renderToTexture(options);
|
|
105
108
|
if (!outputTexture) {
|
|
@@ -114,7 +117,7 @@ void main() {
|
|
|
114
117
|
const renderPass = this.device.beginRenderPass({
|
|
115
118
|
id: 'shader-pass-renderer-to-screen',
|
|
116
119
|
framebuffer,
|
|
117
|
-
clearColor: [
|
|
120
|
+
// clearColor: [1, 1, 0, 1],
|
|
118
121
|
clearDepth: 1
|
|
119
122
|
});
|
|
120
123
|
this.clipSpace.setBindings({sourceTexture: outputTexture});
|
|
@@ -127,7 +130,7 @@ void main() {
|
|
|
127
130
|
* @returns null if the the sourceTexture has not yet been loaded
|
|
128
131
|
*/
|
|
129
132
|
renderToTexture(options: {
|
|
130
|
-
sourceTexture:
|
|
133
|
+
sourceTexture: DynamicTexture;
|
|
131
134
|
uniforms?: any;
|
|
132
135
|
bindings?: any;
|
|
133
136
|
}): Texture | null {
|
|
@@ -136,20 +139,23 @@ void main() {
|
|
|
136
139
|
return null;
|
|
137
140
|
}
|
|
138
141
|
|
|
139
|
-
|
|
140
|
-
this.
|
|
141
|
-
|
|
142
|
-
}
|
|
142
|
+
// If no shader passes are provided, just return the original texture
|
|
143
|
+
if (this.passRenderers.length === 0) {
|
|
144
|
+
return sourceTexture.texture;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
this.textureModel.setProps({backgroundTexture: sourceTexture});
|
|
143
148
|
|
|
144
149
|
// Clear the current texture before we begin
|
|
145
150
|
const clearTexturePass = this.device.beginRenderPass({
|
|
146
151
|
id: 'shader-pass-renderer-clear-texture',
|
|
147
152
|
framebuffer: this.swapFramebuffers.current,
|
|
148
|
-
clearColor: [
|
|
153
|
+
clearColor: [1, 0, 0, 1]
|
|
149
154
|
});
|
|
150
155
|
this.textureModel.draw(clearTexturePass);
|
|
151
156
|
clearTexturePass.end();
|
|
152
157
|
|
|
158
|
+
// Copy the texture contents
|
|
153
159
|
// const commandEncoder = this.device.createCommandEncoder();
|
|
154
160
|
// commandEncoder.copyTextureToTexture({
|
|
155
161
|
// sourceTexture: sourceTexture.texture,
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {PipelineFactory} from './factories/pipeline-factory';
|
|
6
|
+
import type {ShaderFactory} from './factories/shader-factory';
|
|
7
|
+
|
|
8
|
+
export type EngineModuleState = {
|
|
9
|
+
defaultPipelineFactory?: PipelineFactory;
|
|
10
|
+
defaultShaderFactory?: ShaderFactory;
|
|
11
|
+
};
|
|
@@ -4,6 +4,22 @@
|
|
|
4
4
|
|
|
5
5
|
import {type BufferLayout, type ShaderLayout} from '@luma.gl/core';
|
|
6
6
|
|
|
7
|
+
function getMinLocation(
|
|
8
|
+
attributeNames: string[],
|
|
9
|
+
shaderLayoutMap: Record<string, number | undefined>
|
|
10
|
+
): number {
|
|
11
|
+
let minLocation = Infinity;
|
|
12
|
+
|
|
13
|
+
for (const name of attributeNames) {
|
|
14
|
+
const location = shaderLayoutMap[name];
|
|
15
|
+
if (location !== undefined) {
|
|
16
|
+
minLocation = Math.min(minLocation, location);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return minLocation;
|
|
21
|
+
}
|
|
22
|
+
|
|
7
23
|
export function sortedBufferLayoutByShaderSourceLocations(
|
|
8
24
|
shaderLayout: ShaderLayout,
|
|
9
25
|
bufferLayout: BufferLayout[]
|
|
@@ -16,8 +32,8 @@ export function sortedBufferLayoutByShaderSourceLocations(
|
|
|
16
32
|
sortedLayout.sort((a, b) => {
|
|
17
33
|
const attributeNamesA = a.attributes ? a.attributes.map(attr => attr.attribute) : [a.name];
|
|
18
34
|
const attributeNamesB = b.attributes ? b.attributes.map(attr => attr.attribute) : [b.name];
|
|
19
|
-
const minLocationA =
|
|
20
|
-
const minLocationB =
|
|
35
|
+
const minLocationA = getMinLocation(attributeNamesA, shaderLayoutMap);
|
|
36
|
+
const minLocationB = getMinLocation(attributeNamesB, shaderLayoutMap);
|
|
21
37
|
|
|
22
38
|
return minLocationA - minLocationB;
|
|
23
39
|
});
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import type { TextureProps, SamplerProps, TextureView, Device, TypedArray, TextureFormat, ExternalImage } from '@luma.gl/core';
|
|
2
|
-
import { Texture, Sampler } from '@luma.gl/core';
|
|
3
|
-
type AsyncTextureDataProps = AsyncTexture1DProps | AsyncTexture2DProps | AsyncTexture3DProps | AsyncTextureArrayProps | AsyncTextureCubeProps | AsyncTextureCubeArrayProps;
|
|
4
|
-
type AsyncTexture1DProps = {
|
|
5
|
-
dimension: '1d';
|
|
6
|
-
data: Promise<Texture1DData> | Texture1DData | null;
|
|
7
|
-
};
|
|
8
|
-
type AsyncTexture2DProps = {
|
|
9
|
-
dimension?: '2d';
|
|
10
|
-
data: Promise<Texture2DData> | Texture2DData | null;
|
|
11
|
-
};
|
|
12
|
-
type AsyncTexture3DProps = {
|
|
13
|
-
dimension: '3d';
|
|
14
|
-
data: Promise<Texture3DData> | Texture3DData | null;
|
|
15
|
-
};
|
|
16
|
-
type AsyncTextureArrayProps = {
|
|
17
|
-
dimension: '2d-array';
|
|
18
|
-
data: Promise<TextureArrayData> | TextureArrayData | null;
|
|
19
|
-
};
|
|
20
|
-
type AsyncTextureCubeProps = {
|
|
21
|
-
dimension: 'cube';
|
|
22
|
-
data: Promise<TextureCubeData> | TextureCubeData | null;
|
|
23
|
-
};
|
|
24
|
-
type AsyncTextureCubeArrayProps = {
|
|
25
|
-
dimension: 'cube-array';
|
|
26
|
-
data: Promise<TextureCubeArrayData> | TextureCubeArrayData | null;
|
|
27
|
-
};
|
|
28
|
-
/** Names of cube texture faces */
|
|
29
|
-
export type TextureCubeFace = '+X' | '-X' | '+Y' | '-Y' | '+Z' | '-Z';
|
|
30
|
-
export declare const TextureCubeFaces: TextureCubeFace[];
|
|
31
|
-
export declare const TextureCubeFaceMap: {
|
|
32
|
-
'+X': number;
|
|
33
|
-
'-X': number;
|
|
34
|
-
'+Y': number;
|
|
35
|
-
'-Y': number;
|
|
36
|
-
'+Z': number;
|
|
37
|
-
'-Z': number;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* One mip level
|
|
41
|
-
* Basic data structure is similar to `ImageData`
|
|
42
|
-
* additional optional fields can describe compressed texture data.
|
|
43
|
-
*/
|
|
44
|
-
export type TextureImageData = {
|
|
45
|
-
/** WebGPU style format string. Defaults to 'rgba8unorm' */
|
|
46
|
-
format?: TextureFormat;
|
|
47
|
-
data: TypedArray;
|
|
48
|
-
width: number;
|
|
49
|
-
height: number;
|
|
50
|
-
compressed?: boolean;
|
|
51
|
-
byteLength?: number;
|
|
52
|
-
hasAlpha?: boolean;
|
|
53
|
-
};
|
|
54
|
-
export type TextureLevelSource = TextureImageData | ExternalImage;
|
|
55
|
-
/** Texture data can be one or more mip levels */
|
|
56
|
-
export type TextureData = TextureImageData | ExternalImage | (TextureImageData | ExternalImage)[];
|
|
57
|
-
/** @todo - define what data type is supported for 1D textures */
|
|
58
|
-
export type Texture1DData = TypedArray | TextureImageData;
|
|
59
|
-
/** Texture data can be one or more mip levels */
|
|
60
|
-
export type Texture2DData = TypedArray | TextureImageData | ExternalImage | (TextureImageData | ExternalImage)[];
|
|
61
|
-
/** 6 face textures */
|
|
62
|
-
export type TextureCubeData = Record<TextureCubeFace, TextureData>;
|
|
63
|
-
/** Array of textures */
|
|
64
|
-
export type Texture3DData = TextureData[];
|
|
65
|
-
/** Array of textures */
|
|
66
|
-
export type TextureArrayData = TextureData[];
|
|
67
|
-
/** Array of 6 face textures */
|
|
68
|
-
export type TextureCubeArrayData = Record<TextureCubeFace, TextureData>[];
|
|
69
|
-
export declare const CubeFaces: TextureCubeFace[];
|
|
70
|
-
/** Properties for an async texture */
|
|
71
|
-
export type AsyncTextureProps = Omit<TextureProps, 'data' | 'mipLevels' | 'width' | 'height'> & AsyncTextureDataProps & {
|
|
72
|
-
/** Generate mipmaps after creating textures and setting data */
|
|
73
|
-
mipmaps?: boolean;
|
|
74
|
-
/** nipLevels can be set to 'auto' to generate max number of mipLevels */
|
|
75
|
-
mipLevels?: number | 'auto';
|
|
76
|
-
/** Width - can be auto-calculated when initializing from ExternalImage */
|
|
77
|
-
width?: number;
|
|
78
|
-
/** Height - can be auto-calculated when initializing from ExternalImage */
|
|
79
|
-
height?: number;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* It is very convenient to be able to initialize textures with promises
|
|
83
|
-
* This can add considerable complexity to the Texture class, and doesn't
|
|
84
|
-
* fit with the immutable nature of WebGPU resources.
|
|
85
|
-
* Instead, luma.gl offers async textures as a separate class.
|
|
86
|
-
*/
|
|
87
|
-
export declare class AsyncTexture {
|
|
88
|
-
readonly device: Device;
|
|
89
|
-
readonly id: string;
|
|
90
|
-
props: Required<Omit<AsyncTextureProps, 'data'>>;
|
|
91
|
-
texture: Texture;
|
|
92
|
-
sampler: Sampler;
|
|
93
|
-
view: TextureView;
|
|
94
|
-
readonly ready: Promise<void>;
|
|
95
|
-
isReady: boolean;
|
|
96
|
-
destroyed: boolean;
|
|
97
|
-
protected resolveReady: () => void;
|
|
98
|
-
protected rejectReady: (error: Error) => void;
|
|
99
|
-
get [Symbol.toStringTag](): string;
|
|
100
|
-
toString(): string;
|
|
101
|
-
constructor(device: Device, props: AsyncTextureProps);
|
|
102
|
-
initAsync(props: AsyncTextureProps): Promise<void>;
|
|
103
|
-
destroy(): void;
|
|
104
|
-
generateMipmaps(): void;
|
|
105
|
-
/** Set sampler or create and set new Sampler from SamplerProps */
|
|
106
|
-
setSampler(sampler?: Sampler | SamplerProps): void;
|
|
107
|
-
/**
|
|
108
|
-
* Textures are immutable and cannot be resized after creation,
|
|
109
|
-
* but we can create a similar texture with the same parameters but a new size.
|
|
110
|
-
* @note Does not copy contents of the texture
|
|
111
|
-
* @note Mipmaps may need to be regenerated after resizing / setting new data
|
|
112
|
-
* @todo Abort pending promise and create a texture with the new size?
|
|
113
|
-
*/
|
|
114
|
-
resize(size: {
|
|
115
|
-
width: number;
|
|
116
|
-
height: number;
|
|
117
|
-
}): boolean;
|
|
118
|
-
/** Check if texture data is a typed array */
|
|
119
|
-
isTextureLevelData(data: TextureData): data is TextureImageData;
|
|
120
|
-
/** Get the size of the texture described by the provided TextureData */
|
|
121
|
-
getTextureDataSize(data: TextureData | TextureCubeData | TextureArrayData | TextureCubeArrayData | TypedArray | null): {
|
|
122
|
-
width: number;
|
|
123
|
-
height: number;
|
|
124
|
-
} | null;
|
|
125
|
-
/** Convert luma.gl cubemap face constants to depth index */
|
|
126
|
-
getCubeFaceDepth(face: TextureCubeFace): number;
|
|
127
|
-
setTextureData(data: TextureData): void;
|
|
128
|
-
/** Experimental: Set multiple mip levels */
|
|
129
|
-
_setTexture1DData(texture: Texture, data: Texture1DData): void;
|
|
130
|
-
/** Experimental: Set multiple mip levels */
|
|
131
|
-
_setTexture2DData(lodData: Texture2DData, depth?: number): void;
|
|
132
|
-
/**
|
|
133
|
-
* Experimental: Sets 3D texture data: multiple depth slices, multiple mip levels
|
|
134
|
-
* @param data
|
|
135
|
-
*/
|
|
136
|
-
_setTexture3DData(texture: Texture, data: Texture3DData): void;
|
|
137
|
-
/**
|
|
138
|
-
* Experimental: Set Cube texture data, multiple faces, multiple mip levels
|
|
139
|
-
* @todo - could support TextureCubeArray with depth
|
|
140
|
-
* @param data
|
|
141
|
-
* @param index
|
|
142
|
-
*/
|
|
143
|
-
_setTextureCubeData(texture: Texture, data: TextureCubeData): void;
|
|
144
|
-
/**
|
|
145
|
-
* Experimental: Sets texture array data, multiple levels, multiple depth slices
|
|
146
|
-
* @param data
|
|
147
|
-
*/
|
|
148
|
-
_setTextureArrayData(texture: Texture, data: TextureArrayData): void;
|
|
149
|
-
/**
|
|
150
|
-
* Experimental: Sets texture cube array, multiple faces, multiple levels, multiple mip levels
|
|
151
|
-
* @param data
|
|
152
|
-
*/
|
|
153
|
-
_setTextureCubeArrayData(texture: Texture, data: TextureCubeArrayData): void;
|
|
154
|
-
/** Experimental */
|
|
155
|
-
_setTextureCubeFaceData(texture: Texture, lodData: Texture2DData, face: TextureCubeFace, depth?: number): void;
|
|
156
|
-
/**
|
|
157
|
-
* Normalize TextureData to an array of TextureImageData / ExternalImages
|
|
158
|
-
* @param data
|
|
159
|
-
* @param options
|
|
160
|
-
* @returns array of TextureImageData / ExternalImages
|
|
161
|
-
*/
|
|
162
|
-
_normalizeTextureData(data: Texture2DData): (TextureImageData | ExternalImage)[];
|
|
163
|
-
static defaultProps: Required<AsyncTextureProps>;
|
|
164
|
-
}
|
|
165
|
-
export {};
|
|
166
|
-
//# sourceMappingURL=async-texture.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async-texture.d.ts","sourceRoot":"","sources":["../../src/async-texture/async-texture.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,MAAM,EACN,UAAU,EACV,aAAa,EACb,aAAa,EACd,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAC,OAAO,EAAE,OAAO,EAAM,MAAM,eAAe,CAAC;AAKpD,KAAK,qBAAqB,GACtB,mBAAmB,GACnB,mBAAmB,GACnB,mBAAmB,GACnB,sBAAsB,GACtB,qBAAqB,GACrB,0BAA0B,CAAC;AAE/B,KAAK,mBAAmB,GAAG;IAAC,SAAS,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,GAAG,IAAI,CAAA;CAAC,CAAC;AAClG,KAAK,mBAAmB,GAAG;IAAC,SAAS,CAAC,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,GAAG,IAAI,CAAA;CAAC,CAAC;AACnG,KAAK,mBAAmB,GAAG;IAAC,SAAS,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,GAAG,IAAI,CAAA;CAAC,CAAC;AAClG,KAAK,sBAAsB,GAAG;IAC5B,SAAS,EAAE,UAAU,CAAC;IACtB,IAAI,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,gBAAgB,GAAG,IAAI,CAAC;CAC3D,CAAC;AACF,KAAK,qBAAqB,GAAG;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB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