@luma.gl/core 9.0.0-alpha.9 → 9.0.0-beta.2
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/LICENSE +3 -1
- package/README.md +4 -4
- package/dist/adapter/attribute-utils/get-attribute-from-layouts.d.ts +52 -0
- package/dist/adapter/attribute-utils/get-attribute-from-layouts.d.ts.map +1 -0
- package/dist/adapter/attribute-utils/get-attribute-from-layouts.js +130 -0
- package/dist/adapter/attribute-utils/get-attribute-from-layouts.js.map +1 -0
- package/dist/adapter/canvas-context.d.ts +109 -0
- package/dist/adapter/canvas-context.d.ts.map +1 -0
- package/dist/adapter/canvas-context.js +254 -0
- package/dist/adapter/canvas-context.js.map +1 -0
- package/dist/adapter/device.d.ts +219 -0
- package/dist/adapter/device.d.ts.map +1 -0
- package/dist/adapter/device.js +99 -0
- package/dist/adapter/device.js.map +1 -0
- package/dist/adapter/resources/buffer.d.ts +56 -0
- package/dist/adapter/resources/buffer.d.ts.map +1 -0
- package/dist/adapter/resources/buffer.js +62 -0
- package/dist/adapter/resources/buffer.js.map +1 -0
- package/dist/adapter/resources/command-buffer.d.ts +12 -0
- package/dist/adapter/resources/command-buffer.d.ts.map +1 -0
- package/dist/adapter/resources/command-buffer.js +15 -0
- package/dist/adapter/resources/command-buffer.js.map +1 -0
- package/dist/adapter/resources/command-encoder.d.ts +113 -0
- package/dist/adapter/resources/command-encoder.d.ts.map +1 -0
- package/dist/adapter/resources/command-encoder.js +19 -0
- package/dist/adapter/resources/command-encoder.js.map +1 -0
- package/dist/adapter/resources/compute-pass.d.ts +31 -0
- package/dist/adapter/resources/compute-pass.d.ts.map +1 -0
- package/dist/adapter/resources/compute-pass.js +15 -0
- package/dist/adapter/resources/compute-pass.js.map +1 -0
- package/dist/adapter/resources/compute-pipeline.d.ts +24 -0
- package/dist/adapter/resources/compute-pipeline.d.ts.map +1 -0
- package/dist/adapter/resources/compute-pipeline.js +20 -0
- package/dist/adapter/resources/compute-pipeline.js.map +1 -0
- package/dist/adapter/resources/external-texture.d.ts +12 -0
- package/dist/adapter/resources/external-texture.d.ts.map +1 -0
- package/dist/adapter/resources/external-texture.js +17 -0
- package/dist/adapter/resources/external-texture.js.map +1 -0
- package/dist/adapter/resources/framebuffer.d.ts +50 -0
- package/dist/adapter/resources/framebuffer.d.ts.map +1 -0
- package/dist/adapter/resources/framebuffer.js +102 -0
- package/dist/adapter/resources/framebuffer.js.map +1 -0
- package/dist/adapter/resources/render-pass.d.ts +51 -0
- package/dist/adapter/resources/render-pass.d.ts.map +1 -0
- package/dist/adapter/resources/render-pass.js +23 -0
- package/dist/adapter/resources/render-pass.js.map +1 -0
- package/dist/adapter/resources/render-pipeline.d.ts +89 -0
- package/dist/adapter/resources/render-pipeline.d.ts.map +1 -0
- package/dist/adapter/resources/render-pipeline.js +36 -0
- package/dist/adapter/resources/render-pipeline.js.map +1 -0
- package/dist/adapter/resources/resource.d.ts +73 -0
- package/dist/adapter/resources/resource.d.ts.map +1 -0
- package/dist/adapter/resources/resource.js +101 -0
- package/dist/adapter/resources/resource.js.map +1 -0
- package/dist/adapter/resources/sampler.d.ts +42 -0
- package/dist/adapter/resources/sampler.d.ts.map +1 -0
- package/dist/adapter/resources/sampler.js +26 -0
- package/dist/adapter/resources/sampler.js.map +1 -0
- package/dist/adapter/resources/shader.d.ts +45 -0
- package/dist/adapter/resources/shader.d.ts.map +1 -0
- package/dist/adapter/resources/shader.js +90 -0
- package/dist/adapter/resources/shader.js.map +1 -0
- package/dist/adapter/resources/texture.d.ts +90 -0
- package/dist/adapter/resources/texture.d.ts.map +1 -0
- package/dist/adapter/resources/texture.js +45 -0
- package/dist/adapter/resources/texture.js.map +1 -0
- package/dist/adapter/resources/transform-feedback.d.ts +30 -0
- package/dist/adapter/resources/transform-feedback.d.ts.map +1 -0
- package/dist/adapter/resources/transform-feedback.js +17 -0
- package/dist/adapter/resources/transform-feedback.js.map +1 -0
- package/dist/adapter/resources/vertex-array.d.ts +40 -0
- package/dist/adapter/resources/vertex-array.d.ts.map +1 -0
- package/dist/adapter/resources/vertex-array.js +24 -0
- package/dist/adapter/resources/vertex-array.js.map +1 -0
- package/dist/adapter/type-utils/decode-attribute-type.d.ts +20 -0
- package/dist/adapter/type-utils/decode-attribute-type.d.ts.map +1 -0
- package/dist/adapter/type-utils/decode-attribute-type.js +60 -0
- package/dist/adapter/type-utils/decode-attribute-type.js.map +1 -0
- package/dist/adapter/type-utils/decode-data-type.d.ts +16 -0
- package/dist/adapter/type-utils/decode-data-type.d.ts.map +1 -0
- package/dist/adapter/type-utils/decode-data-type.js +43 -0
- package/dist/adapter/type-utils/decode-data-type.js.map +1 -0
- package/dist/adapter/type-utils/decode-shader-types.d.ts +9 -0
- package/dist/adapter/type-utils/decode-shader-types.d.ts.map +1 -0
- package/dist/adapter/type-utils/decode-shader-types.js +103 -0
- package/dist/adapter/type-utils/decode-shader-types.js.map +1 -0
- package/dist/adapter/type-utils/decode-texture-format.d.ts +19 -0
- package/dist/adapter/type-utils/decode-texture-format.d.ts.map +1 -0
- package/dist/adapter/type-utils/decode-texture-format.js +101 -0
- package/dist/adapter/type-utils/decode-texture-format.js.map +1 -0
- package/dist/adapter/type-utils/decode-vertex-format.d.ts +22 -0
- package/dist/adapter/type-utils/decode-vertex-format.d.ts.map +1 -0
- package/dist/adapter/type-utils/decode-vertex-format.js +25 -0
- package/dist/adapter/type-utils/decode-vertex-format.js.map +1 -0
- package/dist/adapter/type-utils/vertex-format-from-attribute.d.ts +10 -0
- package/dist/adapter/type-utils/vertex-format-from-attribute.d.ts.map +1 -0
- package/dist/adapter/type-utils/vertex-format-from-attribute.js +76 -0
- package/dist/adapter/type-utils/vertex-format-from-attribute.js.map +1 -0
- package/dist/adapter/type-utils/wgsl-utils.d.ts +4 -0
- package/dist/adapter/type-utils/wgsl-utils.d.ts.map +1 -0
- package/dist/adapter/type-utils/wgsl-utils.js +15 -0
- package/dist/adapter/type-utils/wgsl-utils.js.map +1 -0
- package/dist/adapter/types/accessor.d.ts +23 -0
- package/dist/adapter/types/accessor.d.ts.map +1 -0
- package/dist/adapter/types/accessor.js +2 -0
- package/dist/adapter/types/accessor.js.map +1 -0
- package/dist/adapter/types/buffer-layout.d.ts +59 -0
- package/dist/adapter/types/buffer-layout.d.ts.map +1 -0
- package/dist/adapter/types/buffer-layout.js +2 -0
- package/dist/adapter/types/buffer-layout.js.map +1 -0
- package/dist/adapter/types/parameters.d.ts +97 -0
- package/dist/adapter/types/parameters.d.ts.map +1 -0
- package/dist/adapter/types/parameters.js +28 -0
- package/dist/adapter/types/parameters.js.map +1 -0
- package/dist/adapter/types/shader-layout.d.ts +145 -0
- package/dist/adapter/types/shader-layout.d.ts.map +1 -0
- package/dist/adapter/types/shader-layout.js +2 -0
- package/dist/adapter/types/shader-layout.js.map +1 -0
- package/dist/adapter/types/shader-types.d.ts +21 -0
- package/dist/adapter/types/shader-types.d.ts.map +1 -0
- package/dist/adapter/types/shader-types.js +2 -0
- package/dist/adapter/types/shader-types.js.map +1 -0
- package/dist/adapter/types/texture-formats.d.ts +12 -0
- package/dist/adapter/types/texture-formats.d.ts.map +1 -0
- package/dist/adapter/types/texture-formats.js +2 -0
- package/dist/adapter/types/texture-formats.js.map +1 -0
- package/dist/adapter/types/types.d.ts +90 -0
- package/dist/adapter/types/types.d.ts.map +1 -0
- package/dist/adapter/types/types.js +2 -0
- package/dist/adapter/types/types.js.map +1 -0
- package/dist/adapter/types/vertex-formats.d.ts +14 -0
- package/dist/adapter/types/vertex-formats.d.ts.map +1 -0
- package/dist/adapter/types/vertex-formats.js +2 -0
- package/dist/adapter/types/vertex-formats.js.map +1 -0
- package/dist/dist.dev.js +2976 -0
- package/dist/index.cjs +2445 -0
- package/dist/index.d.ts +81 -128
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -18
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +5 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +24 -0
- package/dist/init.js.map +1 -0
- package/dist/lib/compiler-log/compiler-message.d.ts +8 -0
- package/dist/lib/compiler-log/compiler-message.d.ts.map +1 -0
- package/dist/lib/compiler-log/compiler-message.js +2 -0
- package/dist/lib/compiler-log/compiler-message.js.map +1 -0
- package/dist/lib/compiler-log/format-compiler-log.d.ts +8 -0
- package/dist/lib/compiler-log/format-compiler-log.d.ts.map +1 -0
- package/dist/lib/compiler-log/format-compiler-log.js +64 -0
- package/dist/lib/compiler-log/format-compiler-log.js.map +1 -0
- package/dist/lib/compiler-log/get-shader-info.d.ts +9 -0
- package/dist/lib/compiler-log/get-shader-info.d.ts.map +1 -0
- package/dist/lib/compiler-log/get-shader-info.js +25 -0
- package/dist/lib/compiler-log/get-shader-info.js.map +1 -0
- package/dist/lib/luma.d.ts +22 -0
- package/dist/lib/luma.d.ts.map +1 -0
- package/dist/lib/luma.js +63 -0
- package/dist/lib/luma.js.map +1 -0
- package/dist/lib/uniforms/uniform-block.d.ts +29 -0
- package/dist/lib/uniforms/uniform-block.d.ts.map +1 -0
- package/dist/lib/uniforms/uniform-block.js +48 -0
- package/dist/lib/uniforms/uniform-block.js.map +1 -0
- package/dist/lib/uniforms/uniform-buffer-layout.d.ts +27 -0
- package/dist/lib/uniforms/uniform-buffer-layout.d.ts.map +1 -0
- package/dist/lib/uniforms/uniform-buffer-layout.js +76 -0
- package/dist/lib/uniforms/uniform-buffer-layout.js.map +1 -0
- package/dist/lib/uniforms/uniform-store.d.ts +62 -0
- package/dist/lib/uniforms/uniform-store.d.ts.map +1 -0
- package/dist/lib/uniforms/uniform-store.js +89 -0
- package/dist/lib/uniforms/uniform-store.js.map +1 -0
- package/dist/lib/uniforms/uniform.d.ts +10 -0
- package/dist/lib/uniforms/uniform.d.ts.map +1 -0
- package/dist/lib/uniforms/uniform.js +20 -0
- package/dist/lib/uniforms/uniform.js.map +1 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/array-equal.d.ts +5 -0
- package/dist/utils/array-equal.d.ts.map +1 -0
- package/dist/utils/array-equal.js +28 -0
- package/dist/utils/array-equal.js.map +1 -0
- package/dist/utils/array-utils-flat.d.ts +10 -0
- package/dist/utils/array-utils-flat.d.ts.map +1 -0
- package/dist/utils/array-utils-flat.js +36 -0
- package/dist/utils/array-utils-flat.js.map +1 -0
- package/dist/utils/assert.d.ts +2 -0
- package/dist/utils/assert.d.ts.map +1 -0
- package/dist/utils/assert.js +6 -0
- package/dist/utils/assert.js.map +1 -0
- package/dist/utils/cast.d.ts +3 -0
- package/dist/utils/cast.d.ts.map +1 -0
- package/dist/utils/cast.js +4 -0
- package/dist/utils/cast.js.map +1 -0
- package/dist/utils/check-props.d.ts +7 -0
- package/dist/utils/check-props.d.ts.map +1 -0
- package/dist/utils/check-props.js +32 -0
- package/dist/utils/check-props.js.map +1 -0
- package/dist/utils/deep-equal.d.ts +9 -0
- package/dist/utils/deep-equal.d.ts.map +1 -0
- package/dist/utils/deep-equal.js +40 -0
- package/dist/utils/deep-equal.js.map +1 -0
- package/dist/utils/format-value.d.ts +7 -0
- package/dist/utils/format-value.d.ts.map +1 -0
- package/dist/utils/format-value.js +42 -0
- package/dist/utils/format-value.js.map +1 -0
- package/dist/utils/is-array.d.ts +16 -0
- package/dist/utils/is-array.d.ts.map +1 -0
- package/dist/utils/is-array.js +10 -0
- package/dist/utils/is-array.js.map +1 -0
- package/dist/utils/load-file.d.ts +35 -0
- package/dist/utils/load-file.d.ts.map +1 -0
- package/dist/utils/load-file.js +48 -0
- package/dist/utils/load-file.js.map +1 -0
- package/dist/utils/log.d.ts +4 -0
- package/dist/utils/log.d.ts.map +1 -0
- package/dist/utils/log.js +5 -0
- package/dist/utils/log.js.map +1 -0
- package/dist/utils/random.d.ts +5 -0
- package/dist/utils/random.d.ts.map +1 -0
- package/dist/utils/random.js +14 -0
- package/dist/utils/random.js.map +1 -0
- package/dist/utils/request-animation-frame.d.ts +3 -0
- package/dist/utils/request-animation-frame.d.ts.map +1 -0
- package/dist/utils/request-animation-frame.js +7 -0
- package/dist/utils/request-animation-frame.js.map +1 -0
- package/dist/utils/stats-manager.d.ts +12 -0
- package/dist/utils/stats-manager.d.ts.map +1 -0
- package/dist/utils/stats-manager.js +19 -0
- package/dist/utils/stats-manager.js.map +1 -0
- package/dist/utils/stub-methods.d.ts +2 -0
- package/dist/utils/stub-methods.d.ts.map +1 -0
- package/dist/utils/stub-methods.js +16 -0
- package/dist/utils/stub-methods.js.map +1 -0
- package/dist/utils/utils.d.ts +15 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +19 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist.min.js +33 -0
- package/package.json +17 -12
- package/src/adapter/attribute-utils/get-attribute-from-layouts.ts +259 -0
- package/src/adapter/canvas-context.ts +433 -0
- package/src/adapter/device.ts +435 -0
- package/src/adapter/resources/buffer.ts +106 -0
- package/src/adapter/resources/command-buffer.ts +38 -0
- package/src/adapter/resources/command-encoder.ts +172 -0
- package/src/adapter/resources/compute-pass.ts +52 -0
- package/src/adapter/resources/compute-pipeline.ts +39 -0
- package/src/adapter/resources/external-texture.ts +20 -0
- package/src/adapter/resources/framebuffer.ts +230 -0
- package/src/adapter/resources/render-pass.ts +117 -0
- package/src/adapter/resources/render-pipeline.ts +133 -0
- package/src/adapter/resources/resource.ts +176 -0
- package/src/adapter/resources/sampler.ts +69 -0
- package/src/adapter/resources/shader.ts +143 -0
- package/src/adapter/resources/texture.ts +140 -0
- package/src/adapter/resources/transform-feedback.ts +45 -0
- package/src/adapter/resources/vertex-array.ts +65 -0
- package/src/adapter/type-utils/decode-attribute-type.ts +82 -0
- package/src/adapter/type-utils/decode-data-type.ts +62 -0
- package/src/adapter/type-utils/decode-shader-types.ts +48 -0
- package/src/adapter/type-utils/decode-texture-format.ts +190 -0
- package/src/adapter/type-utils/decode-vertex-format.ts +49 -0
- package/src/adapter/type-utils/vertex-format-from-attribute.ts +103 -0
- package/src/adapter/type-utils/wgsl-utils.ts +18 -0
- package/src/adapter/types/accessor.ts +34 -0
- package/src/adapter/types/buffer-layout.ts +62 -0
- package/src/adapter/types/parameters.ts +250 -0
- package/src/adapter/types/shader-layout.ts +193 -0
- package/src/adapter/types/shader-types.ts +77 -0
- package/src/adapter/types/texture-formats.ts +168 -0
- package/src/adapter/types/types.ts +109 -0
- package/src/adapter/types/vertex-formats.ts +91 -0
- package/src/index.ts +160 -92
- package/src/init.ts +47 -0
- package/src/lib/compiler-log/compiler-message.ts +10 -0
- package/src/lib/compiler-log/format-compiler-log.ts +113 -0
- package/src/lib/compiler-log/get-shader-info.ts +41 -0
- package/src/lib/luma.ts +84 -0
- package/src/lib/uniforms/uniform-block.ts +80 -0
- package/src/lib/uniforms/uniform-buffer-layout.ts +109 -0
- package/src/lib/uniforms/uniform-store.ts +173 -0
- package/src/lib/uniforms/uniform.ts +25 -0
- package/src/types.ts +33 -0
- package/src/utils/array-equal.ts +33 -0
- package/src/utils/array-utils-flat.ts +43 -0
- package/src/utils/assert.ts +7 -0
- package/src/utils/cast.ts +4 -0
- package/src/utils/check-props.ts +74 -0
- package/src/utils/deep-equal.ts +47 -0
- package/src/utils/format-value.ts +40 -0
- package/src/utils/is-array.ts +24 -0
- package/src/utils/load-file.ts +89 -0
- package/src/utils/log.ts +4 -0
- package/src/utils/random.ts +17 -0
- package/src/utils/request-animation-frame.ts +15 -0
- package/src/utils/stats-manager.ts +23 -0
- package/src/utils/stub-methods.ts +20 -0
- package/src/utils/utils.ts +36 -0
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/bundle.js +0 -5
- package/dist/bundle.js.map +0 -1
- package/src/bundle.ts +0 -4
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// luma.gl, MIT license
|
|
2
|
+
import type {Device} from '../device';
|
|
3
|
+
import type {UniformValue} from '../types/types';
|
|
4
|
+
import type {PrimitiveTopology, RenderPipelineParameters} from '../types/parameters';
|
|
5
|
+
import type {ShaderLayout, Binding} from '../types/shader-layout';
|
|
6
|
+
import type {BufferLayout} from '../types/buffer-layout';
|
|
7
|
+
// import {normalizeAttributeMap} from '../helpers/attribute-bindings';
|
|
8
|
+
import {Resource, ResourceProps} from './resource';
|
|
9
|
+
import type {Shader} from './shader';
|
|
10
|
+
import type {RenderPass} from './render-pass';
|
|
11
|
+
import {VertexArray} from './vertex-array';
|
|
12
|
+
import {TransformFeedback} from './transform-feedback';
|
|
13
|
+
|
|
14
|
+
export type RenderPipelineProps = ResourceProps & {
|
|
15
|
+
// Shaders and shader layout
|
|
16
|
+
|
|
17
|
+
/** Compiled vertex shader */
|
|
18
|
+
vs?: Shader | null;
|
|
19
|
+
/** Vertex shader entry point (defaults to 'main'). WGSL only */
|
|
20
|
+
vsEntryPoint?: string; //
|
|
21
|
+
/** Constants to apply to compiled vertex shader (WGSL only) */
|
|
22
|
+
vsConstants?: Record<string, number>; // WGSL only
|
|
23
|
+
/** Compiled fragment shader */
|
|
24
|
+
fs?: Shader | null;
|
|
25
|
+
/** Fragment shader entry point (defaults to 'main'). WGSL only */
|
|
26
|
+
fsEntryPoint?: string; // WGSL only
|
|
27
|
+
/** Constants to apply to compiled fragment shader (WGSL only) */
|
|
28
|
+
fsConstants?: Record<string, number>;
|
|
29
|
+
|
|
30
|
+
/** Describes the attributes and bindings exposed by the pipeline shader(s). */
|
|
31
|
+
shaderLayout?: ShaderLayout | null;
|
|
32
|
+
/**
|
|
33
|
+
* Describes the buffers accepted by this pipeline and how they are mapped to shader attributes.
|
|
34
|
+
* A default mapping of one buffer per attribute is always created.
|
|
35
|
+
*/
|
|
36
|
+
bufferLayout?: BufferLayout[]; // Record<string, Omit<BufferLayout, 'name'>
|
|
37
|
+
|
|
38
|
+
/** Determines how vertices are read from the 'vertex' attributes */
|
|
39
|
+
topology?: PrimitiveTopology;
|
|
40
|
+
/** Parameters that are controlled by pipeline */
|
|
41
|
+
parameters?: RenderPipelineParameters;
|
|
42
|
+
|
|
43
|
+
// Can be changed after creation
|
|
44
|
+
// TODO make pipeline immutable? these could be supplied to draw as parameters, in WebGPU they are set on the render pass
|
|
45
|
+
|
|
46
|
+
/** Number of vertices */
|
|
47
|
+
vertexCount?: number;
|
|
48
|
+
/** Number of instances */
|
|
49
|
+
instanceCount?: number;
|
|
50
|
+
|
|
51
|
+
/** Buffers, Textures, Samplers for the shader bindings */
|
|
52
|
+
bindings?: Record<string, Binding>;
|
|
53
|
+
/** @deprecated uniforms (WebGL only) */
|
|
54
|
+
uniforms?: Record<string, UniformValue>;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A compiled and linked shader program
|
|
59
|
+
*/
|
|
60
|
+
export abstract class RenderPipeline extends Resource<RenderPipelineProps> {
|
|
61
|
+
static override defaultProps: Required<RenderPipelineProps> = {
|
|
62
|
+
...Resource.defaultProps,
|
|
63
|
+
|
|
64
|
+
vs: null,
|
|
65
|
+
vsEntryPoint: '', // main
|
|
66
|
+
vsConstants: {},
|
|
67
|
+
|
|
68
|
+
fs: null,
|
|
69
|
+
fsEntryPoint: '', // main
|
|
70
|
+
fsConstants: {},
|
|
71
|
+
|
|
72
|
+
shaderLayout: null,
|
|
73
|
+
bufferLayout: [],
|
|
74
|
+
topology: 'triangle-list',
|
|
75
|
+
parameters: {},
|
|
76
|
+
|
|
77
|
+
vertexCount: 0,
|
|
78
|
+
instanceCount: 0,
|
|
79
|
+
|
|
80
|
+
bindings: {},
|
|
81
|
+
uniforms: {}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
override get [Symbol.toStringTag](): string {
|
|
85
|
+
return 'RenderPipeline';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
hash: string = '';
|
|
89
|
+
abstract readonly vs: Shader;
|
|
90
|
+
abstract readonly fs: Shader | null;
|
|
91
|
+
/** The merged layout */
|
|
92
|
+
shaderLayout: ShaderLayout;
|
|
93
|
+
/** Buffer map describing buffer interleaving etc */
|
|
94
|
+
readonly bufferLayout: BufferLayout[];
|
|
95
|
+
|
|
96
|
+
constructor(device: Device, props: RenderPipelineProps) {
|
|
97
|
+
super(device, props, RenderPipeline.defaultProps);
|
|
98
|
+
this.shaderLayout = this.props.shaderLayout;
|
|
99
|
+
this.bufferLayout = this.props.bufferLayout || [];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Set bindings (stored on pipeline and set before each call) */
|
|
103
|
+
abstract setBindings(bindings: Record<string, Binding>): void;
|
|
104
|
+
/** Uniforms
|
|
105
|
+
* @deprecated Only supported on WebGL devices.
|
|
106
|
+
* @note textures, samplers and uniform buffers should be set via `setBindings()`, these are not considered uniforms.
|
|
107
|
+
* @note In WebGL uniforms have a performance penalty, they are reset before each call to enable pipeline sharing.
|
|
108
|
+
*/
|
|
109
|
+
abstract setUniforms(bindings: Record<string, UniformValue>): void;
|
|
110
|
+
|
|
111
|
+
/** Draw call */
|
|
112
|
+
abstract draw(options: {
|
|
113
|
+
/** Render pass to draw into (targeting screen or framebuffer) */
|
|
114
|
+
renderPass?: RenderPass;
|
|
115
|
+
/** vertex attributes */
|
|
116
|
+
vertexArray: VertexArray;
|
|
117
|
+
/** Number of "rows" in index buffer */
|
|
118
|
+
indexCount?: number;
|
|
119
|
+
/** Number of "rows" in 'vertex' buffers */
|
|
120
|
+
vertexCount?: number;
|
|
121
|
+
/** Number of "rows" in 'instance' buffers */
|
|
122
|
+
instanceCount?: number;
|
|
123
|
+
/** First vertex to draw from */
|
|
124
|
+
firstVertex?: number;
|
|
125
|
+
/** First index to draw from */
|
|
126
|
+
firstIndex?: number;
|
|
127
|
+
/** First instance to draw from */
|
|
128
|
+
firstInstance?: number;
|
|
129
|
+
baseVertex?: number;
|
|
130
|
+
/** Transform feedback. WebGL 2 only. */
|
|
131
|
+
transformFeedback?: TransformFeedback;
|
|
132
|
+
}): void;
|
|
133
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// luma.gl, MIT license
|
|
2
|
+
import type {Device} from '../device';
|
|
3
|
+
import {uid} from '../../utils/utils';
|
|
4
|
+
|
|
5
|
+
export type ResourceProps = {
|
|
6
|
+
/** Name of resource, mainly for debugging purposes. A unique name will be assigned if not provided */
|
|
7
|
+
id?: string;
|
|
8
|
+
/** Handle for the underlying resources (WebGL object or WebGPU handle) */
|
|
9
|
+
handle?: any;
|
|
10
|
+
/** User provided data stored on this resource */
|
|
11
|
+
userData?: {[key: string]: any};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Base class for GPU (WebGPU/WebGL) Resources
|
|
16
|
+
*/
|
|
17
|
+
export abstract class Resource<Props extends ResourceProps> {
|
|
18
|
+
/** Default properties for resource */
|
|
19
|
+
static defaultProps: Required<ResourceProps> = {
|
|
20
|
+
id: 'undefined',
|
|
21
|
+
handle: undefined,
|
|
22
|
+
userData: undefined,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
abstract get [Symbol.toStringTag](): string;
|
|
26
|
+
|
|
27
|
+
/** props.id, for debugging. */
|
|
28
|
+
id: string;
|
|
29
|
+
readonly props: Required<Props>;
|
|
30
|
+
readonly userData: Record<string, unknown> = {};
|
|
31
|
+
abstract readonly device: Device;
|
|
32
|
+
private _device: Device;
|
|
33
|
+
|
|
34
|
+
/** Whether this resource has been destroyed */
|
|
35
|
+
destroyed: boolean = false;
|
|
36
|
+
/** For resources that allocate GPU memory */
|
|
37
|
+
private allocatedBytes: number = 0;
|
|
38
|
+
/** Attached resources will be destroyed when this resource is destroyed. Tracks auto-created "sub" resources. */
|
|
39
|
+
private _attachedResources = new Set<Resource<unknown>>();
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create a new Resource. Called from Subclass
|
|
44
|
+
*/
|
|
45
|
+
constructor(device: Device, props: Props, defaultProps: Required<Props>) {
|
|
46
|
+
if (!device) {
|
|
47
|
+
throw new Error('no device');
|
|
48
|
+
}
|
|
49
|
+
this._device = device;
|
|
50
|
+
this.props = selectivelyMerge<Props>(props, defaultProps);
|
|
51
|
+
|
|
52
|
+
const id = this.props.id !== 'undefined' ? this.props.id as string : uid(this[Symbol.toStringTag]);
|
|
53
|
+
this.props.id = id;
|
|
54
|
+
this.id = id;
|
|
55
|
+
this.userData = this.props.userData || {};
|
|
56
|
+
|
|
57
|
+
this.addStats();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* destroy can be called on any resource to release it before it is garbage collected.
|
|
62
|
+
*/
|
|
63
|
+
destroy(): void {
|
|
64
|
+
this.destroyResource();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @deprecated Use destroy() */
|
|
68
|
+
delete(): this {
|
|
69
|
+
this.destroy();
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
toString(): string {
|
|
74
|
+
return `${this[Symbol.toStringTag] || this.constructor.name}(${this.id})`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Combines a map of user props and default props, only including props from defaultProps
|
|
79
|
+
* @returns returns a map of overridden default props
|
|
80
|
+
*/
|
|
81
|
+
getProps(): object {
|
|
82
|
+
return this.props;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ATTACHED RESOURCES
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Attaches a resource. Attached resources are auto destroyed when this resource is destroyed
|
|
89
|
+
* Called automatically when sub resources are auto created but can be called by application
|
|
90
|
+
*/
|
|
91
|
+
attachResource(resource: Resource<unknown>): void {
|
|
92
|
+
this._attachedResources.add(resource);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Detach an attached resource. The resource will no longer be auto-destroyed when this resource is destroyed.
|
|
97
|
+
*/
|
|
98
|
+
detachResource(resource: Resource<unknown>): void {
|
|
99
|
+
this._attachedResources.delete(resource);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Destroys a resource (only if owned), and removes from the owned (auto-destroy) list for this resource.
|
|
104
|
+
*/
|
|
105
|
+
destroyAttachedResource(resource: Resource<unknown>): void {
|
|
106
|
+
if (this._attachedResources.delete(resource)) {
|
|
107
|
+
resource.destroy();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Destroy all owned resources. Make sure the resources are no longer needed before calling. */
|
|
112
|
+
destroyAttachedResources(): void {
|
|
113
|
+
for (const resource of Object.values(this._attachedResources)) {
|
|
114
|
+
resource.destroy();
|
|
115
|
+
}
|
|
116
|
+
// don't remove while we are iterating
|
|
117
|
+
this._attachedResources = new Set<Resource<unknown>>();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// PROTECTED METHODS
|
|
121
|
+
|
|
122
|
+
/** Perform all destroy steps. Can be called by derived resources when overriding destroy() */
|
|
123
|
+
protected destroyResource(): void {
|
|
124
|
+
this.destroyAttachedResources();
|
|
125
|
+
this.removeStats();
|
|
126
|
+
this.destroyed = true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Called by .destroy() to track object destruction. Subclass must call if overriding destroy() */
|
|
130
|
+
protected removeStats(): void {
|
|
131
|
+
const stats = this._device.statsManager.getStats('Resource Counts');
|
|
132
|
+
const name = this[Symbol.toStringTag];
|
|
133
|
+
stats.get(`${name}s Active`).decrementCount();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Called by subclass to track memory allocations */
|
|
137
|
+
protected trackAllocatedMemory(bytes: number, name = this[Symbol.toStringTag]): void {
|
|
138
|
+
const stats = this._device.statsManager.getStats('Resource Counts');
|
|
139
|
+
stats.get('GPU Memory').addCount(bytes);
|
|
140
|
+
stats.get(`${name} Memory`).addCount(bytes);
|
|
141
|
+
this.allocatedBytes = bytes;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Called by subclass to track memory deallocations */
|
|
145
|
+
protected trackDeallocatedMemory(name = this[Symbol.toStringTag]): void {
|
|
146
|
+
const stats = this._device.statsManager.getStats('Resource Counts');
|
|
147
|
+
stats.get('GPU Memory').subtractCount(this.allocatedBytes);
|
|
148
|
+
stats.get(`${name} Memory`).subtractCount(this.allocatedBytes);
|
|
149
|
+
this.allocatedBytes = 0;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Called by resource constructor to track object creation */
|
|
153
|
+
private addStats(): void {
|
|
154
|
+
const stats = this._device.statsManager.getStats('Resource Counts');
|
|
155
|
+
const name = this[Symbol.toStringTag];
|
|
156
|
+
stats.get('Resources Created').incrementCount();
|
|
157
|
+
stats.get(`${name}s Created`).incrementCount();
|
|
158
|
+
stats.get(`${name}s Active`).incrementCount();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Combines a map of user props and default props, only including props from defaultProps
|
|
164
|
+
* @param props
|
|
165
|
+
* @param defaultProps
|
|
166
|
+
* @returns returns a map of overridden default props
|
|
167
|
+
*/
|
|
168
|
+
function selectivelyMerge<Props>(props: Props, defaultProps: Required<Props>): Required<Props> {
|
|
169
|
+
const mergedProps = {...defaultProps};
|
|
170
|
+
for (const key in props) {
|
|
171
|
+
if (props[key] !== undefined) {
|
|
172
|
+
mergedProps[key] = props[key];
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return mergedProps;
|
|
176
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// luma.gl, MIT license
|
|
2
|
+
// Copyright (c) vis.gl contributors
|
|
3
|
+
|
|
4
|
+
import type {Device} from '../device';
|
|
5
|
+
import {CompareFunction} from '../types/parameters';
|
|
6
|
+
import {Resource, ResourceProps} from './resource';
|
|
7
|
+
|
|
8
|
+
/** Edge values sampling mode */
|
|
9
|
+
export type SamplerAddressMode = 'clamp-to-edge' | 'repeat' | 'mirror-repeat';
|
|
10
|
+
|
|
11
|
+
/** Sampler filtering mode */
|
|
12
|
+
export type SamplerFilterMode = 'nearest' | 'linear';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Properties for initializing a sampler
|
|
16
|
+
*/
|
|
17
|
+
export type SamplerProps = ResourceProps & {
|
|
18
|
+
/** Comparison / shadow samplers are used with depth textures. See the `Sampler.compare` field */
|
|
19
|
+
type?: 'color-sampler' | 'comparison-sampler';
|
|
20
|
+
/** Edge value sampling in X direction */
|
|
21
|
+
addressModeU?: 'clamp-to-edge' | 'repeat' | 'mirror-repeat';
|
|
22
|
+
/** Edge value sampling in Y direction */
|
|
23
|
+
addressModeV?: 'clamp-to-edge' | 'repeat' | 'mirror-repeat';
|
|
24
|
+
/** Edge value sampling in Z direction */
|
|
25
|
+
addressModeW?: 'clamp-to-edge' | 'repeat' | 'mirror-repeat';
|
|
26
|
+
|
|
27
|
+
/** Magnification: the area of the fragment in texture space is smaller than a texel */
|
|
28
|
+
magFilter?: 'nearest' | 'linear';
|
|
29
|
+
/** Minification: the area of the fragment in texture space is larger than a texel */
|
|
30
|
+
minFilter?: 'nearest' | 'linear';
|
|
31
|
+
/** mipmapping: select between multiple mipmaps based on angle and size of the texture relative to the screen. */
|
|
32
|
+
mipmapFilter?: 'nearest' | 'linear';
|
|
33
|
+
/** Affects the mipmap image selection */
|
|
34
|
+
lodMinClamp?: number;
|
|
35
|
+
/** Affects the mipmap image selection */
|
|
36
|
+
lodMaxClamp?: number;
|
|
37
|
+
/** Maximum number of samples that can be taken of the texture during any one texture fetch */
|
|
38
|
+
maxAnisotropy?: number;
|
|
39
|
+
/** How to compare reference values provided in shader shadow sampler calls with those pulled from the texture */
|
|
40
|
+
compare?: CompareFunction;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type SamplerParameters = Omit<SamplerProps, keyof ResourceProps>;
|
|
44
|
+
|
|
45
|
+
/** Immutable Sampler object */
|
|
46
|
+
export abstract class Sampler extends Resource<SamplerProps> {
|
|
47
|
+
static override defaultProps: Required<SamplerProps> = {
|
|
48
|
+
...Resource.defaultProps,
|
|
49
|
+
type: 'color-sampler',
|
|
50
|
+
addressModeU: 'clamp-to-edge',
|
|
51
|
+
addressModeV: 'clamp-to-edge',
|
|
52
|
+
addressModeW: 'clamp-to-edge',
|
|
53
|
+
magFilter: 'nearest',
|
|
54
|
+
minFilter: 'nearest',
|
|
55
|
+
mipmapFilter: 'nearest',
|
|
56
|
+
lodMinClamp: 0,
|
|
57
|
+
lodMaxClamp: 32, // Per WebGPU spec
|
|
58
|
+
compare: 'less-equal',
|
|
59
|
+
maxAnisotropy: 1
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
override get [Symbol.toStringTag](): string {
|
|
63
|
+
return 'Sampler';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
constructor(device: Device, props: SamplerProps) {
|
|
67
|
+
super(device, props, Sampler.defaultProps);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// luma.gl, MIT license
|
|
2
|
+
import type {Device} from '../device';
|
|
3
|
+
import {Resource, ResourceProps} from './resource';
|
|
4
|
+
// import { log } from '../../utils/log';
|
|
5
|
+
import {uid} from '../../utils/utils';
|
|
6
|
+
import {CompilerMessage} from '../../lib/compiler-log/compiler-message';
|
|
7
|
+
import {formatCompilerLog} from '../../lib/compiler-log/format-compiler-log';
|
|
8
|
+
import {getShaderInfo} from '../../lib/compiler-log/get-shader-info';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Properties for a Shader
|
|
12
|
+
*/
|
|
13
|
+
export type ShaderProps = ResourceProps & {
|
|
14
|
+
/** Shader language (defaults to auto) */
|
|
15
|
+
language?: 'glsl' | 'wgsl' | 'auto';
|
|
16
|
+
/** Which stage are we compiling? Required by WebGL and GLSL transpiler */
|
|
17
|
+
stage: 'vertex' | 'fragment' | 'compute';
|
|
18
|
+
/** Shader source code */
|
|
19
|
+
source: string;
|
|
20
|
+
/** Optional shader source map (WebGPU only) */
|
|
21
|
+
sourceMap?: string | null;
|
|
22
|
+
/** Optional shader entry point (WebGPU only) */
|
|
23
|
+
entryPoint?: string;
|
|
24
|
+
/** Show shader source in browser? */
|
|
25
|
+
debug?: 'never' | 'errors' | 'warnings' | 'always';
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Immutable Shader object
|
|
30
|
+
* In WebGPU the handle can be copied between threads
|
|
31
|
+
*/
|
|
32
|
+
export abstract class Shader extends Resource<ShaderProps> {
|
|
33
|
+
static override defaultProps: Required<ShaderProps> = {
|
|
34
|
+
...Resource.defaultProps,
|
|
35
|
+
language: 'auto',
|
|
36
|
+
stage: 'vertex',
|
|
37
|
+
source: '',
|
|
38
|
+
sourceMap: null,
|
|
39
|
+
entryPoint: 'main',
|
|
40
|
+
debug: 'errors'
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
override get [Symbol.toStringTag](): string {
|
|
44
|
+
return 'Shader';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The stage of this shader */
|
|
48
|
+
readonly stage: 'vertex' | 'fragment' | 'compute';
|
|
49
|
+
/** The source code of this shader */
|
|
50
|
+
readonly source: string;
|
|
51
|
+
/** The compilation status of this shader. May be 'pending' if compilation is done asynchronously */
|
|
52
|
+
compilationStatus: 'success' | 'error' | 'pending' = 'pending';
|
|
53
|
+
|
|
54
|
+
/** Create a new Shader instance */
|
|
55
|
+
constructor(device: Device, props: ShaderProps) {
|
|
56
|
+
super(device, {id: getShaderIdFromProps(props), ...props}, Shader.defaultProps);
|
|
57
|
+
this.stage = this.props.stage;
|
|
58
|
+
this.source = this.props.source;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Get compiler log asynchronously */
|
|
62
|
+
abstract getCompilationInfo(): Promise<readonly CompilerMessage[]>;
|
|
63
|
+
|
|
64
|
+
/** Get compiler log synchronously (WebGL only) */
|
|
65
|
+
getCompilationInfoSync(): readonly CompilerMessage[] | null {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// PORTABLE HELPERS
|
|
70
|
+
|
|
71
|
+
/** In browser logging of errors */
|
|
72
|
+
async debugShader(): Promise<void> {
|
|
73
|
+
switch (this.props.debug) {
|
|
74
|
+
case 'never':
|
|
75
|
+
return;
|
|
76
|
+
case 'errors':
|
|
77
|
+
// On WebGL - Don't extract the log unless errors
|
|
78
|
+
if (this.compilationStatus === 'success') {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
case 'warnings':
|
|
83
|
+
case 'always':
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const messages = await this.getCompilationInfo();
|
|
88
|
+
if (this.props.debug === 'warnings' && messages?.length === 0) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
this._displayShaderLog(messages);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// PRIVATE
|
|
95
|
+
|
|
96
|
+
/** In-browser UI logging of errors */
|
|
97
|
+
protected _displayShaderLog(messages: readonly CompilerMessage[]): void {
|
|
98
|
+
// Return if under Node.js / incomplete `document` polyfills
|
|
99
|
+
if (typeof document === 'undefined' || !document?.createElement) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const shaderName: string = getShaderInfo(this.source).name;
|
|
104
|
+
const shaderTitle: string = `${this.stage} ${shaderName}`;
|
|
105
|
+
const htmlLog = formatCompilerLog(messages, this.source, {showSourceCode: 'all', html: true});
|
|
106
|
+
|
|
107
|
+
// Make it clickable so we can copy to clipboard
|
|
108
|
+
const button = document.createElement('Button');
|
|
109
|
+
button.innerHTML = `
|
|
110
|
+
<h1>Shader Compilation Error in ${shaderTitle}</h1><br /><br />
|
|
111
|
+
<code style="user-select:text;"><pre>
|
|
112
|
+
${htmlLog}
|
|
113
|
+
</pre></code>`;
|
|
114
|
+
button.style.top = '10px';
|
|
115
|
+
button.style.left = '10px';
|
|
116
|
+
button.style.position = 'absolute';
|
|
117
|
+
button.style.zIndex = '9999';
|
|
118
|
+
button.style.width = '100%';
|
|
119
|
+
button.style.textAlign = 'left';
|
|
120
|
+
document.body.appendChild(button);
|
|
121
|
+
|
|
122
|
+
const errors = document.getElementsByClassName('luma-compiler-log-error');
|
|
123
|
+
if (errors[0]?.scrollIntoView) {
|
|
124
|
+
errors[0].scrollIntoView();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// TODO - add a small embedded copy button (instead of main button)
|
|
128
|
+
button.onclick = () => {
|
|
129
|
+
// const source = this.source.replaceAll('\n', '<br />');
|
|
130
|
+
const dataURI = `data:text/plain,${encodeURIComponent(this.source)}`;
|
|
131
|
+
navigator.clipboard.writeText(dataURI);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// TODO - add a small embedded close button
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// HELPERS
|
|
139
|
+
|
|
140
|
+
/** Deduce an id, from shader source, or supplied id, or shader type */
|
|
141
|
+
function getShaderIdFromProps(props: ShaderProps): string {
|
|
142
|
+
return getShaderInfo(props.source).name || props.id || uid(`unnamed ${props.stage}-shader`);
|
|
143
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// luma.gl, MIT license
|
|
2
|
+
import type {Device} from '../device';
|
|
3
|
+
import type {TypedArray} from '../../types';
|
|
4
|
+
import type {TextureFormat} from '../types/texture-formats';
|
|
5
|
+
import {Resource, ResourceProps} from './resource';
|
|
6
|
+
import {Sampler, SamplerProps} from './sampler';
|
|
7
|
+
|
|
8
|
+
// required GPUExtent3D size;
|
|
9
|
+
// GPUIntegerCoordinate mipLevelCount = 1;
|
|
10
|
+
// GPUSize32 sampleCount = 1;
|
|
11
|
+
// GPUTextureDimension dimension = "2d";
|
|
12
|
+
// required GPUTextureFormat format;
|
|
13
|
+
// required GPUTextureUsageFlags usage;
|
|
14
|
+
|
|
15
|
+
/** Data types that can be used to initialize textures */
|
|
16
|
+
export type TextureData =
|
|
17
|
+
TypedArray | ArrayBuffer | Buffer | ImageBitmap | HTMLImageElement
|
|
18
|
+
;
|
|
19
|
+
|
|
20
|
+
export type CubeTextureData =
|
|
21
|
+
Record<string, TextureData> |
|
|
22
|
+
Record<string, Promise<TextureData>>
|
|
23
|
+
;
|
|
24
|
+
|
|
25
|
+
export type ExternalTextureData = HTMLVideoElement;
|
|
26
|
+
|
|
27
|
+
/** Abstract Texture interface */
|
|
28
|
+
export type TextureProps = ResourceProps & {
|
|
29
|
+
format?: TextureFormat;
|
|
30
|
+
dimension?: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
|
|
31
|
+
width?: number | undefined;
|
|
32
|
+
height?: number | undefined;
|
|
33
|
+
depth?: number;
|
|
34
|
+
usage?: number;
|
|
35
|
+
|
|
36
|
+
data?: TextureData | Promise<TextureData> | CubeTextureData | string | HTMLVideoElement | null;
|
|
37
|
+
mipmaps?: boolean;
|
|
38
|
+
sampler?: Sampler | SamplerProps;
|
|
39
|
+
|
|
40
|
+
mipLevels?: number;
|
|
41
|
+
samples?: number;
|
|
42
|
+
type?: number;
|
|
43
|
+
compressed?: boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type WebGPUTextureProps = ResourceProps & {
|
|
47
|
+
width: number;
|
|
48
|
+
height: number;
|
|
49
|
+
depth?: number;
|
|
50
|
+
mipLevels?: number;
|
|
51
|
+
format?: string;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type TextureViewProps = {
|
|
55
|
+
format: string;
|
|
56
|
+
dimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
|
|
57
|
+
aspect?: 'all' | 'stencil-only' | 'depth-only';
|
|
58
|
+
arrayLayerCount: number;
|
|
59
|
+
baseArrayLayer?: number;
|
|
60
|
+
mipLevels?: number;
|
|
61
|
+
baseMipLevel?: number;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated
|
|
66
|
+
* @todo remove, are these even used anymore?
|
|
67
|
+
*/
|
|
68
|
+
export type DeprecatedWebGLTextureProps = {
|
|
69
|
+
/** @deprecated use props.sampler */
|
|
70
|
+
parameters?: Record<number, number>;
|
|
71
|
+
/** @deprecated use props.data */
|
|
72
|
+
pixels?: any;
|
|
73
|
+
/** @deprecated use props.format */
|
|
74
|
+
dataFormat?: number | null;
|
|
75
|
+
/** @deprecated rarely supported */
|
|
76
|
+
border?: number;
|
|
77
|
+
/** @deprecated WebGL only. */
|
|
78
|
+
pixelStore?: object;
|
|
79
|
+
/** @deprecated WebGL only. */
|
|
80
|
+
textureUnit?: number;
|
|
81
|
+
/** @deprecated WebGL only. Use dimension. */
|
|
82
|
+
target?: number;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Abstract Texture interface
|
|
87
|
+
* Texture Object
|
|
88
|
+
* https://gpuweb.github.io/gpuweb/#gputexture
|
|
89
|
+
*/
|
|
90
|
+
export abstract class Texture<Props extends TextureProps = TextureProps> extends Resource<Props> {
|
|
91
|
+
static override defaultProps: Required<TextureProps> = {
|
|
92
|
+
...Resource.defaultProps,
|
|
93
|
+
data: null,
|
|
94
|
+
dimension: '2d',
|
|
95
|
+
format: 'rgba8unorm',
|
|
96
|
+
width: undefined!,
|
|
97
|
+
height: undefined!,
|
|
98
|
+
depth: 1,
|
|
99
|
+
mipmaps: true,
|
|
100
|
+
sampler: {},
|
|
101
|
+
// type: undefined,
|
|
102
|
+
compressed: false,
|
|
103
|
+
// mipLevels: 1,
|
|
104
|
+
usage: 0,
|
|
105
|
+
// usage: GPUTextureUsage.COPY_DST
|
|
106
|
+
mipLevels: undefined!,
|
|
107
|
+
samples: undefined!,
|
|
108
|
+
type: undefined!
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
static COPY_SRC = 0x01;
|
|
112
|
+
static COPY_DST = 0x02;
|
|
113
|
+
static TEXTURE_BINDING = 0x04;
|
|
114
|
+
static STORAGE_BINDING = 0x08;
|
|
115
|
+
static RENDER_ATTACHMENT = 0x10;
|
|
116
|
+
|
|
117
|
+
override get [Symbol.toStringTag](): string { return 'Texture'; }
|
|
118
|
+
|
|
119
|
+
/** dimension of this texture */
|
|
120
|
+
readonly dimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
|
|
121
|
+
/** format of this texture */
|
|
122
|
+
readonly format: TextureFormat;
|
|
123
|
+
/** width in pixels of this texture */
|
|
124
|
+
width: number;
|
|
125
|
+
/** height in pixels of this texture */
|
|
126
|
+
height: number;
|
|
127
|
+
/** depth of this texture */
|
|
128
|
+
readonly depth: number;
|
|
129
|
+
/** Default sampler for this texture */
|
|
130
|
+
abstract sampler: Sampler;
|
|
131
|
+
|
|
132
|
+
constructor(device: Device, props: Props, defaultProps = Texture.defaultProps as Required<Props>) {
|
|
133
|
+
super(device, props, defaultProps);
|
|
134
|
+
this.dimension = this.props.dimension;
|
|
135
|
+
this.format = this.props.format ;
|
|
136
|
+
this.width = this.props.width;
|
|
137
|
+
this.height = this.props.height;
|
|
138
|
+
this.depth = this.props.depth;
|
|
139
|
+
}
|
|
140
|
+
}
|