@luma.gl/core 9.0.0-beta.4 → 9.0.0-beta.5
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/attribute-utils/get-attribute-from-layouts.js +140 -109
- package/dist/adapter/canvas-context.js +305 -233
- package/dist/adapter/device.d.ts +9 -11
- package/dist/adapter/device.d.ts.map +1 -1
- package/dist/adapter/device.js +114 -95
- package/dist/adapter/resources/buffer.d.ts +1 -1
- package/dist/adapter/resources/buffer.d.ts.map +1 -1
- package/dist/adapter/resources/buffer.js +65 -57
- package/dist/adapter/resources/command-buffer.js +13 -13
- package/dist/adapter/resources/command-encoder.js +17 -17
- package/dist/adapter/resources/compute-pass.js +10 -13
- package/dist/adapter/resources/compute-pipeline.js +19 -18
- package/dist/adapter/resources/external-texture.js +10 -15
- package/dist/adapter/resources/framebuffer.js +155 -94
- package/dist/adapter/resources/render-pass.js +28 -21
- package/dist/adapter/resources/render-pipeline.d.ts +3 -1
- package/dist/adapter/resources/render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/render-pipeline.js +37 -34
- package/dist/adapter/resources/resource.js +131 -93
- package/dist/adapter/resources/sampler.js +24 -24
- package/dist/adapter/resources/shader.d.ts +2 -2
- package/dist/adapter/resources/shader.d.ts.map +1 -1
- package/dist/adapter/resources/shader.js +90 -78
- package/dist/adapter/resources/texture.js +49 -43
- package/dist/adapter/resources/transform-feedback.d.ts +2 -2
- package/dist/adapter/resources/transform-feedback.d.ts.map +1 -1
- package/dist/adapter/resources/transform-feedback.js +13 -15
- package/dist/adapter/resources/vertex-array.js +30 -22
- package/dist/adapter/type-utils/decode-attribute-type.js +56 -52
- package/dist/adapter/type-utils/decode-data-type.js +36 -35
- package/dist/adapter/type-utils/decode-shader-types.js +36 -97
- package/dist/adapter/type-utils/decode-texture-format.js +160 -93
- package/dist/adapter/type-utils/decode-vertex-format.js +28 -23
- package/dist/adapter/type-utils/vertex-format-from-attribute.js +69 -65
- package/dist/adapter/type-utils/wgsl-utils.js +14 -13
- package/dist/adapter/types/accessor.js +0 -1
- package/dist/adapter/types/buffer-layout.js +0 -1
- package/dist/adapter/types/parameters.js +31 -26
- package/dist/adapter/types/shader-layout.js +0 -1
- package/dist/adapter/types/shader-types.js +2 -1
- package/dist/adapter/types/texture-formats.d.ts +1 -1
- package/dist/adapter/types/texture-formats.d.ts.map +1 -1
- package/dist/adapter/types/texture-formats.js +2 -1
- package/dist/adapter/types/types.js +0 -1
- package/dist/adapter/types/vertex-formats.js +2 -1
- package/dist/dist.dev.js +453 -270
- package/dist/index.cjs +66 -168
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -46
- package/dist/init.js +29 -19
- package/dist/lib/compiler-log/compiler-message.js +2 -1
- package/dist/lib/compiler-log/format-compiler-log.js +66 -48
- package/dist/lib/compiler-log/get-shader-info.js +22 -19
- package/dist/lib/luma.d.ts.map +1 -1
- package/dist/lib/luma.js +60 -55
- package/dist/lib/uniforms/uniform-block.d.ts +0 -1
- package/dist/lib/uniforms/uniform-block.d.ts.map +1 -1
- package/dist/lib/uniforms/uniform-block.js +50 -43
- package/dist/lib/uniforms/uniform-buffer-layout.js +87 -70
- package/dist/lib/uniforms/uniform-store.js +112 -79
- package/dist/lib/uniforms/uniform.js +13 -16
- package/dist/types.js +1 -3
- package/dist/utils/array-equal.js +25 -23
- package/dist/utils/array-utils-flat.js +28 -28
- package/dist/utils/assert.js +5 -4
- package/dist/utils/cast.js +2 -2
- package/dist/utils/check-props.js +28 -27
- package/dist/utils/deep-equal.js +39 -32
- package/dist/utils/format-value.js +33 -39
- package/dist/utils/is-array.js +17 -6
- package/dist/utils/load-file.js +62 -37
- package/dist/utils/log.js +2 -4
- package/dist/utils/random.js +10 -9
- package/dist/utils/request-animation-frame.js +9 -3
- package/dist/utils/stats-manager.js +13 -14
- package/dist/utils/stub-methods.js +13 -13
- package/dist/utils/utils.d.ts +0 -6
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +20 -15
- package/dist.min.js +8 -23
- package/package.json +6 -6
- package/src/adapter/device.ts +38 -59
- package/src/adapter/resources/buffer.ts +1 -1
- package/src/adapter/resources/render-pipeline.ts +3 -1
- package/src/adapter/resources/shader.ts +2 -2
- package/src/adapter/resources/transform-feedback.ts +2 -2
- package/src/adapter/types/texture-formats.ts +1 -1
- package/src/index.ts +1 -1
- package/src/lib/luma.ts +0 -2
- package/src/lib/uniforms/uniform-block.ts +0 -1
- package/src/utils/utils.ts +0 -9
- package/dist/adapter/attribute-utils/get-attribute-from-layouts.js.map +0 -1
- package/dist/adapter/canvas-context.js.map +0 -1
- package/dist/adapter/device.js.map +0 -1
- package/dist/adapter/resources/buffer.js.map +0 -1
- package/dist/adapter/resources/command-buffer.js.map +0 -1
- package/dist/adapter/resources/command-encoder.js.map +0 -1
- package/dist/adapter/resources/compute-pass.js.map +0 -1
- package/dist/adapter/resources/compute-pipeline.js.map +0 -1
- package/dist/adapter/resources/external-texture.js.map +0 -1
- package/dist/adapter/resources/framebuffer.js.map +0 -1
- package/dist/adapter/resources/render-pass.js.map +0 -1
- package/dist/adapter/resources/render-pipeline.js.map +0 -1
- package/dist/adapter/resources/resource.js.map +0 -1
- package/dist/adapter/resources/sampler.js.map +0 -1
- package/dist/adapter/resources/shader.js.map +0 -1
- package/dist/adapter/resources/texture.js.map +0 -1
- package/dist/adapter/resources/transform-feedback.js.map +0 -1
- package/dist/adapter/resources/vertex-array.js.map +0 -1
- package/dist/adapter/type-utils/decode-attribute-type.js.map +0 -1
- package/dist/adapter/type-utils/decode-data-type.js.map +0 -1
- package/dist/adapter/type-utils/decode-shader-types.js.map +0 -1
- package/dist/adapter/type-utils/decode-texture-format.js.map +0 -1
- package/dist/adapter/type-utils/decode-vertex-format.js.map +0 -1
- package/dist/adapter/type-utils/vertex-format-from-attribute.js.map +0 -1
- package/dist/adapter/type-utils/wgsl-utils.js.map +0 -1
- package/dist/adapter/types/accessor.js.map +0 -1
- package/dist/adapter/types/buffer-layout.js.map +0 -1
- package/dist/adapter/types/parameters.js.map +0 -1
- package/dist/adapter/types/shader-layout.js.map +0 -1
- package/dist/adapter/types/shader-types.js.map +0 -1
- package/dist/adapter/types/texture-formats.js.map +0 -1
- package/dist/adapter/types/types.js.map +0 -1
- package/dist/adapter/types/vertex-formats.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/init.js.map +0 -1
- package/dist/lib/compiler-log/compiler-message.js.map +0 -1
- package/dist/lib/compiler-log/format-compiler-log.js.map +0 -1
- package/dist/lib/compiler-log/get-shader-info.js.map +0 -1
- package/dist/lib/luma.js.map +0 -1
- package/dist/lib/uniforms/uniform-block.js.map +0 -1
- package/dist/lib/uniforms/uniform-buffer-layout.js.map +0 -1
- package/dist/lib/uniforms/uniform-store.js.map +0 -1
- package/dist/lib/uniforms/uniform.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/array-equal.js.map +0 -1
- package/dist/utils/array-utils-flat.js.map +0 -1
- package/dist/utils/assert.js.map +0 -1
- package/dist/utils/cast.js.map +0 -1
- package/dist/utils/check-props.js.map +0 -1
- package/dist/utils/deep-equal.js.map +0 -1
- package/dist/utils/format-value.js.map +0 -1
- package/dist/utils/is-array.js.map +0 -1
- package/dist/utils/load-file.js.map +0 -1
- package/dist/utils/log.js.map +0 -1
- package/dist/utils/random.js.map +0 -1
- package/dist/utils/request-animation-frame.js.map +0 -1
- package/dist/utils/stats-manager.js.map +0 -1
- package/dist/utils/stub-methods.js.map +0 -1
- package/dist/utils/utils.js.map +0 -1
package/src/adapter/device.ts
CHANGED
|
@@ -24,7 +24,7 @@ import type {TransformFeedback, TransformFeedbackProps} from './resources/transf
|
|
|
24
24
|
export type DeviceProps = {
|
|
25
25
|
id?: string;
|
|
26
26
|
|
|
27
|
-
type?: 'webgl' | '
|
|
27
|
+
type?: 'webgl' | 'webgpu' | 'best-available';
|
|
28
28
|
|
|
29
29
|
// Common parameters
|
|
30
30
|
canvas?: HTMLCanvasElement | OffscreenCanvas | string | null; // A canvas element or a canvas string id
|
|
@@ -32,10 +32,6 @@ export type DeviceProps = {
|
|
|
32
32
|
width?: number /** width is only used when creating a new canvas */;
|
|
33
33
|
height?: number /** height is only used when creating a new canvas */;
|
|
34
34
|
|
|
35
|
-
// WebGLDevice parameters
|
|
36
|
-
webgl2?: boolean; // Set to false to not create a WebGL2 context (force webgl1)
|
|
37
|
-
webgl1?: boolean; // set to false to not create a WebGL1 context (fails if webgl2 not available)
|
|
38
|
-
|
|
39
35
|
// WebGLContext PARAMETERS - Can only be set on context creation...
|
|
40
36
|
// alpha?: boolean; // Default render target has an alpha buffer.
|
|
41
37
|
// depth?: boolean; // Default render target has a depth buffer of at least 16 bits.
|
|
@@ -51,7 +47,7 @@ export type DeviceProps = {
|
|
|
51
47
|
break?: string[]; // TODO: types
|
|
52
48
|
|
|
53
49
|
// @deprecated Attach to existing context
|
|
54
|
-
gl?:
|
|
50
|
+
gl?: WebGL2RenderingContext | null;
|
|
55
51
|
};
|
|
56
52
|
|
|
57
53
|
/**
|
|
@@ -62,7 +58,7 @@ export type DeviceProps = {
|
|
|
62
58
|
*/
|
|
63
59
|
export type DeviceInfo = {
|
|
64
60
|
/** Type of device */
|
|
65
|
-
type: 'webgl' | '
|
|
61
|
+
type: 'webgl' | 'webgpu';
|
|
66
62
|
/** Vendor (name of GPU vendor, Apple, nVidia etc */
|
|
67
63
|
vendor: string;
|
|
68
64
|
/** Renderer (usually driver name) */
|
|
@@ -81,7 +77,7 @@ export type DeviceInfo = {
|
|
|
81
77
|
fallback?: boolean;
|
|
82
78
|
/** Shader language supported by device.createShader() */
|
|
83
79
|
shadingLanguage: 'wgsl' | 'glsl';
|
|
84
|
-
/** Highest supported shader language version
|
|
80
|
+
/** Highest supported shader language version: GLSL 3.00 = 300, WGSL 1.00 = 100 */
|
|
85
81
|
shadingLanguageVersion: number;
|
|
86
82
|
};
|
|
87
83
|
|
|
@@ -117,68 +113,51 @@ export type DeviceLimits = {
|
|
|
117
113
|
|
|
118
114
|
export type WebGPUDeviceFeature =
|
|
119
115
|
| 'depth-clip-control'
|
|
116
|
+
| 'indirect-first-instance'
|
|
117
|
+
| 'timestamp-query'
|
|
118
|
+
| 'shader-f16'
|
|
120
119
|
| 'depth24unorm-stencil8'
|
|
121
120
|
| 'depth32float-stencil8'
|
|
122
|
-
| '
|
|
123
|
-
| '
|
|
121
|
+
| 'rg11b10ufloat-renderable' // Is the rg11b10ufloat texture format renderable?
|
|
122
|
+
| 'float32-filterable' // Is the float32 format filterable?
|
|
123
|
+
| 'bgra8unorm-storage' // Can the bgra8unorm texture format be used in storage buffers?
|
|
124
124
|
| 'texture-compression-bc'
|
|
125
125
|
| 'texture-compression-etc2'
|
|
126
126
|
| 'texture-compression-astc';
|
|
127
127
|
|
|
128
128
|
// obsolete...
|
|
129
129
|
// 'depth-clamping' |
|
|
130
|
-
// 'depth24unorm-stencil8' |
|
|
131
|
-
// 'depth32float-stencil8' |
|
|
132
130
|
// 'pipeline-statistics-query' |
|
|
133
|
-
// 'timestamp-query' |
|
|
134
|
-
// 'texture-compression-bc'
|
|
135
131
|
|
|
136
132
|
export type WebGLDeviceFeature =
|
|
137
|
-
|
|
138
|
-
| '
|
|
139
|
-
| 'webgl'
|
|
140
|
-
|
|
141
|
-
// api support (unify with WebGPU timestamp-query?)
|
|
142
|
-
| 'timer-query-webgl'
|
|
143
|
-
| 'uniform-buffers-webgl'
|
|
144
|
-
| 'uniforms-webgl'
|
|
133
|
+
// webgl unique features
|
|
134
|
+
| 'uniforms-webgl' // Supports non-UBO uniforms: renderPipeline.setUniforms()
|
|
135
|
+
| 'transform-feedback-webgl' // device.createTransformFeedback()
|
|
136
|
+
| 'constant-attributes-webgl' // vertexArray.setConstant()
|
|
145
137
|
|
|
146
|
-
//
|
|
147
|
-
| '
|
|
148
|
-
| '
|
|
149
|
-
| 'texture-filter-anisotropic-webgl'
|
|
138
|
+
// api support
|
|
139
|
+
| 'timer-query-webgl' // unify with WebGPU timestamp-query?
|
|
140
|
+
| 'shader-status-async-webgl' // Non-blocking shader compile/link status query available
|
|
150
141
|
|
|
151
142
|
// texture rendering
|
|
152
|
-
| '
|
|
153
|
-
| '
|
|
154
|
-
| '
|
|
143
|
+
| 'float32-renderable-webgl'
|
|
144
|
+
| 'float16-renderable-webgl'
|
|
145
|
+
| 'norm16-renderable-webgl'
|
|
155
146
|
|
|
156
|
-
// texture
|
|
157
|
-
| '
|
|
147
|
+
// texture filtering
|
|
148
|
+
| 'float32-filterable-linear-webgl'
|
|
149
|
+
| 'float16-filterable-linear-webgl'
|
|
150
|
+
| 'texture-filterable-anisotropic-webgl'
|
|
158
151
|
|
|
159
|
-
// texture
|
|
160
|
-
| '
|
|
161
|
-
| 'texture-formats-srgb-webgl1'
|
|
162
|
-
| 'texture-formats-depth-webgl1'
|
|
163
|
-
| 'texture-formats-float32-webgl1'
|
|
164
|
-
| 'texture-formats-float16-webgl1'
|
|
152
|
+
// texture storage bindings
|
|
153
|
+
| 'bgra8unorm-storage'
|
|
165
154
|
|
|
166
|
-
//
|
|
167
|
-
| '
|
|
168
|
-
| 'instanced-rendering-webgl1'
|
|
169
|
-
| 'multiple-render-targets-webgl1'
|
|
170
|
-
| 'index-uint32-webgl1'
|
|
171
|
-
| 'blend-minmax-webgl1'
|
|
172
|
-
| 'transform-feedback-webgl2'
|
|
173
|
-
|
|
174
|
-
// glsl extensions
|
|
175
|
-
| 'glsl-frag-data'
|
|
176
|
-
| 'glsl-frag-depth'
|
|
177
|
-
| 'glsl-derivatives'
|
|
178
|
-
| 'glsl-texture-lod';
|
|
155
|
+
// texture blending
|
|
156
|
+
| 'texture-blend-float-webgl';
|
|
179
157
|
|
|
180
158
|
type WebGLCompressedTextureFeatures =
|
|
181
159
|
| 'texture-compression-bc5-webgl'
|
|
160
|
+
| 'texture-compression-bc7-webgl'
|
|
182
161
|
| 'texture-compression-etc1-webgl'
|
|
183
162
|
| 'texture-compression-pvrtc-webgl'
|
|
184
163
|
| 'texture-compression-atc-webgl';
|
|
@@ -187,26 +166,27 @@ type WebGLCompressedTextureFeatures =
|
|
|
187
166
|
export type DeviceFeature =
|
|
188
167
|
| WebGPUDeviceFeature
|
|
189
168
|
| WebGLDeviceFeature
|
|
190
|
-
| WebGLCompressedTextureFeatures
|
|
169
|
+
| WebGLCompressedTextureFeatures
|
|
170
|
+
| 'webgl'
|
|
171
|
+
| 'glsl'
|
|
172
|
+
| 'webgpu'
|
|
173
|
+
| 'wgsl';
|
|
191
174
|
|
|
192
175
|
/**
|
|
193
176
|
* WebGPU Device/WebGL context abstraction
|
|
194
177
|
*/
|
|
195
178
|
export abstract class Device {
|
|
196
|
-
|
|
197
179
|
static defaultProps: Required<DeviceProps> = {
|
|
198
180
|
id: null!,
|
|
199
181
|
type: 'best-available',
|
|
200
182
|
canvas: null,
|
|
201
183
|
container: null,
|
|
202
|
-
webgl2: true, // Attempt to create a WebGL2 context
|
|
203
|
-
webgl1: true, // Attempt to create a WebGL1 context (false to fail if webgl2 not available)
|
|
204
184
|
manageState: true,
|
|
205
185
|
width: 800, // width are height are only used by headless gl
|
|
206
186
|
height: 600,
|
|
207
187
|
debug: Boolean(log.get('debug')), // Instrument context (at the expense of performance)
|
|
208
188
|
break: [],
|
|
209
|
-
|
|
189
|
+
|
|
210
190
|
// alpha: undefined,
|
|
211
191
|
// depth: undefined,
|
|
212
192
|
// stencil: undefined,
|
|
@@ -214,10 +194,9 @@ export abstract class Device {
|
|
|
214
194
|
// premultipliedAlpha: undefined,
|
|
215
195
|
// preserveDrawingBuffer: undefined,
|
|
216
196
|
// failIfMajorPerformanceCaveat: undefined
|
|
217
|
-
|
|
197
|
+
|
|
218
198
|
gl: null
|
|
219
199
|
};
|
|
220
|
-
|
|
221
200
|
|
|
222
201
|
get [Symbol.toStringTag](): string {
|
|
223
202
|
return 'Device';
|
|
@@ -348,7 +327,7 @@ export abstract class Device {
|
|
|
348
327
|
/** Get a renderpass that is set up to render to the primary CanvasContext */
|
|
349
328
|
abstract getDefaultRenderPass(): RenderPass;
|
|
350
329
|
|
|
351
|
-
/** Create a transform feedback (immutable set of output buffer bindings). WebGL
|
|
330
|
+
/** Create a transform feedback (immutable set of output buffer bindings). WebGL only. */
|
|
352
331
|
abstract createTransformFeedback(props: TransformFeedbackProps): TransformFeedback;
|
|
353
332
|
|
|
354
333
|
createCommandEncoder(props: CommandEncoderProps = {}): CommandEncoder {
|
|
@@ -375,7 +354,7 @@ export abstract class Device {
|
|
|
375
354
|
): Uint8Array | Uint16Array | Float32Array {
|
|
376
355
|
throw new Error('not implemented');
|
|
377
356
|
}
|
|
378
|
-
|
|
357
|
+
|
|
379
358
|
/** @deprecated - will be removed - should use command encoder */
|
|
380
359
|
readPixelsToBufferWebGL(
|
|
381
360
|
source: Framebuffer | Texture,
|
|
@@ -82,7 +82,7 @@ export abstract class Buffer extends Resource<BufferProps> {
|
|
|
82
82
|
abstract readAsync(byteOffset?: number, byteLength?: number): Promise<Uint8Array>;
|
|
83
83
|
|
|
84
84
|
/** Read data synchronously. @note WebGL2 only */
|
|
85
|
-
|
|
85
|
+
readSyncWebGL(byteOffset?: number, byteLength?: number): Uint8Array { throw new Error('not implemented'); }
|
|
86
86
|
|
|
87
87
|
// PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY)
|
|
88
88
|
|
|
@@ -92,6 +92,8 @@ export abstract class RenderPipeline extends Resource<RenderPipelineProps> {
|
|
|
92
92
|
shaderLayout: ShaderLayout;
|
|
93
93
|
/** Buffer map describing buffer interleaving etc */
|
|
94
94
|
readonly bufferLayout: BufferLayout[];
|
|
95
|
+
/** The linking status of the pipeline. 'pending' if linking is asynchronous, and on production */
|
|
96
|
+
linkStatus: 'pending' | 'success' | 'error' = 'pending';
|
|
95
97
|
|
|
96
98
|
constructor(device: Device, props: RenderPipelineProps) {
|
|
97
99
|
super(device, props, RenderPipeline.defaultProps);
|
|
@@ -127,7 +129,7 @@ export abstract class RenderPipeline extends Resource<RenderPipelineProps> {
|
|
|
127
129
|
/** First instance to draw from */
|
|
128
130
|
firstInstance?: number;
|
|
129
131
|
baseVertex?: number;
|
|
130
|
-
/** Transform feedback. WebGL
|
|
132
|
+
/** Transform feedback. WebGL only. */
|
|
131
133
|
transformFeedback?: TransformFeedback;
|
|
132
134
|
}): void;
|
|
133
135
|
}
|
|
@@ -48,8 +48,8 @@ export abstract class Shader extends Resource<ShaderProps> {
|
|
|
48
48
|
readonly stage: 'vertex' | 'fragment' | 'compute';
|
|
49
49
|
/** The source code of this shader */
|
|
50
50
|
readonly source: string;
|
|
51
|
-
/** The compilation status of
|
|
52
|
-
compilationStatus: '
|
|
51
|
+
/** The compilation status of the shader. 'pending' if compilation is asynchronous, and on production */
|
|
52
|
+
compilationStatus: 'pending' | 'success' | 'error' = 'pending';
|
|
53
53
|
|
|
54
54
|
/** Create a new Shader instance */
|
|
55
55
|
constructor(device: Device, props: ShaderProps) {
|
|
@@ -12,7 +12,7 @@ export type BufferRange = {
|
|
|
12
12
|
byteLength?: number;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
/** Configures a set of output buffers for pipeline (WebGL
|
|
15
|
+
/** Configures a set of output buffers for pipeline (WebGL only) */
|
|
16
16
|
export type TransformFeedbackProps = ResourceProps & {
|
|
17
17
|
/** Layout of shader (for varyings) */
|
|
18
18
|
layout: ShaderLayout;
|
|
@@ -20,7 +20,7 @@ export type TransformFeedbackProps = ResourceProps & {
|
|
|
20
20
|
buffers: Record<string, Buffer | BufferRange>;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
/** Holds a set of output buffers for pipeline (WebGL
|
|
23
|
+
/** Holds a set of output buffers for pipeline (WebGL only) */
|
|
24
24
|
export abstract class TransformFeedback extends Resource<TransformFeedbackProps> {
|
|
25
25
|
static override defaultProps: Required<TransformFeedbackProps> = {
|
|
26
26
|
...Resource.defaultProps,
|
|
@@ -139,7 +139,7 @@ export type UnsizedColorTextureFormat =
|
|
|
139
139
|
// 'rgba8unorm-srgb-unsized'
|
|
140
140
|
;
|
|
141
141
|
|
|
142
|
-
/** Sized formats unique to WebGL 2.
|
|
142
|
+
/** Sized formats unique to WebGL 2. Some will perhaps be added to WebGPU standard? */
|
|
143
143
|
export type WebGL2ColorTextureFormat =
|
|
144
144
|
'r16unorm-webgl' |
|
|
145
145
|
'r16snorm-webgl' |
|
package/src/index.ts
CHANGED
|
@@ -136,7 +136,7 @@ export {StatsManager} from './utils/stats-manager';
|
|
|
136
136
|
export {assert} from './utils/assert';
|
|
137
137
|
export {cast} from './utils/cast';
|
|
138
138
|
export {log} from './utils/log';
|
|
139
|
-
export {uid,
|
|
139
|
+
export {uid, isObjectEmpty} from './utils/utils';
|
|
140
140
|
export {isUniformValue, splitUniformsAndBindings} from './lib/uniforms/uniform';
|
|
141
141
|
export {formatValue} from './utils/format-value';
|
|
142
142
|
export {stubRemovedMethods} from './utils/stub-methods';
|
package/src/lib/luma.ts
CHANGED
|
@@ -11,7 +11,6 @@ import {arrayEqual, arrayCopy} from '../../utils/array-equal';
|
|
|
11
11
|
/**
|
|
12
12
|
* A uniform block holds values of the of uniform values for one uniform block / buffer.
|
|
13
13
|
* It also does some book keeping on what has changed, to minimize unnecessary writes to uniform buffers.
|
|
14
|
-
* @todo - Track changes to individual uniforms (for WebGL1)
|
|
15
14
|
*/
|
|
16
15
|
export class UniformBlock<TUniforms extends Record<string, UniformValue> = Record<string, UniformValue>> {
|
|
17
16
|
name: string;
|
package/src/utils/utils.ts
CHANGED
|
@@ -14,15 +14,6 @@ export function uid(id: string = 'id'): string {
|
|
|
14
14
|
return `${id}-${count}`;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* Verifies if a given number is power of two or not.
|
|
19
|
-
* @param n - The number to check.
|
|
20
|
-
* @return Returns true if the given number is power of 2, false otherwise.
|
|
21
|
-
**/
|
|
22
|
-
export function isPowerOfTwo(n: number): boolean {
|
|
23
|
-
return (n > 0) && (n & (n - 1)) === 0;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
17
|
/** Returns true if given object is empty, false otherwise. */
|
|
27
18
|
export function isObjectEmpty(obj: object): boolean {
|
|
28
19
|
let isEmpty = true;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-attribute-from-layouts.js","names":["log","decodeShaderAttributeType","decodeVertexFormat","getAttributeInfosFromLayouts","shaderLayout","bufferLayout","attributeInfos","attribute","attributes","name","getAttributeInfoFromLayouts","getAttributeInfosByLocation","maxVertexAttributes","arguments","length","undefined","locationInfos","Array","fill","attributeInfo","Object","values","location","shaderDeclaration","getAttributeFromShaderLayout","bufferMapping","getAttributeFromBufferLayout","attributeTypeInfo","type","vertexFormat","defaultVertexFormat","vertexFormatInfo","attributeName","bufferName","shaderType","shaderDataType","dataType","shaderComponents","components","bufferDataType","bufferComponents","normalized","integer","stepMode","byteOffset","byteStride","find","attr","warn","bufferLayouts","checkBufferLayouts","bufferLayoutInfo","getAttributeFromShortHand","getAttributeFromAttributesList","format","_bufferLayout$attribu","attributeMapping","info","byteLength","mapping","mergeShaderLayout","baseLayout","overrideLayout","mergedLayout","map","baseAttribute"],"sources":["../../../src/adapter/attribute-utils/get-attribute-from-layouts.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {log} from '../../utils/log';\nimport type {ShaderLayout, AttributeDeclaration} from '../types/shader-layout';\nimport type {BufferLayout} from '../types/buffer-layout';\nimport type {ShaderDataType, ShaderAttributeType} from '../types/shader-types';\nimport {decodeShaderAttributeType} from '../type-utils/decode-attribute-type';\nimport type {VertexFormat, VertexType} from '../types/vertex-formats';\nimport {decodeVertexFormat} from '../type-utils/decode-vertex-format';\n\n/** Resolved info for a buffer / attribute combination to help backend configure it correctly */\nexport type AttributeInfo = {\n /** Attribute name */\n attributeName: string;\n /** Location in shader */\n location: number;\n /** Type / precision used in shader (buffer values may be converted) */\n shaderType: ShaderAttributeType;\n /** Calculations are done in this type in the shader's attribute declaration */\n shaderDataType: ShaderDataType;\n /** Components refer to the number of components in the shader's attribute declaration */\n shaderComponents: 1 | 2 | 3 | 4;\n /** It is the shader attribute declaration that determines whether GPU will process as integer or float */\n integer: boolean;\n\n /** BufferName */\n bufferName: string;\n /** Format of buffer data */\n vertexFormat: VertexFormat;\n /** Memory data type refers to the data type in the buffer */\n bufferDataType: VertexType;\n /** Components refer to the number of components in the buffer's vertex format */\n bufferComponents: 1 | 2 | 3 | 4;\n /** Normalization is encoded in the buffer layout's vertex format... */\n normalized: boolean;\n\n /** If not specified, the step mode is inferred from the attribute name in the shader (contains string instance) */\n stepMode: 'vertex' | 'instance';\n\n /** The byteOffset is encoded in or calculated from the buffer layout */\n byteOffset: number;\n /** The byteStride is encoded in or calculated from the buffer layout */\n byteStride: number;\n};\n\ntype BufferAttributeInfo = {\n attributeName: string;\n bufferName: string;\n stepMode?: 'vertex' | 'instance';\n vertexFormat: VertexFormat;\n byteOffset: number;\n byteStride: number;\n};\n\n/** \n * Map from \"attribute names\" to \"resolved attribute infos\" \n * containing information about both buffer layouts and shader attribute declarations\n */\nexport function getAttributeInfosFromLayouts(\n shaderLayout: ShaderLayout,\n bufferLayout: BufferLayout[]\n): Record<string, AttributeInfo> {\n const attributeInfos: Record<string, AttributeInfo> = {};\n for (const attribute of shaderLayout.attributes) {\n attributeInfos[attribute.name] = getAttributeInfoFromLayouts(\n shaderLayout,\n bufferLayout,\n attribute.name\n );\n }\n return attributeInfos;\n}\n\n/** \n * Array indexed by \"location\" holding \"resolved attribute infos\" \n */\nexport function getAttributeInfosByLocation(\n shaderLayout: ShaderLayout,\n bufferLayout: BufferLayout[],\n maxVertexAttributes: number = 16\n): AttributeInfo[] {\n const attributeInfos = getAttributeInfosFromLayouts(shaderLayout, bufferLayout);\n const locationInfos: AttributeInfo[] = new Array(maxVertexAttributes).fill(null);\n for (const attributeInfo of Object.values(attributeInfos)) {\n locationInfos[attributeInfo.location] = attributeInfo;\n }\n return locationInfos;\n}\n\n/**\n * Get the combined information from a shader layout and a buffer layout for a specific attribute\n */\nfunction getAttributeInfoFromLayouts(\n shaderLayout: ShaderLayout,\n bufferLayout: BufferLayout[],\n name: string\n): AttributeInfo | null {\n const shaderDeclaration = getAttributeFromShaderLayout(shaderLayout, name);\n const bufferMapping: BufferAttributeInfo = getAttributeFromBufferLayout(bufferLayout, name);\n\n // TODO should no longer happen\n if (!shaderDeclaration) {\n // || !bufferMapping\n return null;\n }\n\n const attributeTypeInfo = decodeShaderAttributeType(shaderDeclaration.type);\n const vertexFormat = bufferMapping?.vertexFormat || attributeTypeInfo.defaultVertexFormat;\n const vertexFormatInfo = decodeVertexFormat(vertexFormat);\n\n return {\n attributeName: bufferMapping?.attributeName || shaderDeclaration.name,\n bufferName: bufferMapping?.bufferName || shaderDeclaration.name,\n location: shaderDeclaration.location,\n shaderType: shaderDeclaration.type,\n shaderDataType: attributeTypeInfo.dataType,\n shaderComponents: attributeTypeInfo.components,\n vertexFormat,\n bufferDataType: vertexFormatInfo.type,\n bufferComponents: vertexFormatInfo.components,\n // normalized is a property of the buffer's vertex format\n normalized: vertexFormatInfo.normalized,\n // integer is a property of the shader declaration\n integer: attributeTypeInfo.integer,\n stepMode: bufferMapping?.stepMode || shaderDeclaration.stepMode,\n byteOffset: bufferMapping?.byteOffset || 0,\n byteStride: bufferMapping?.byteStride || 0\n };\n}\n\nfunction getAttributeFromShaderLayout(\n shaderLayout: ShaderLayout,\n name: string\n): AttributeDeclaration | null {\n const attribute = shaderLayout.attributes.find(attr => attr.name === name);\n if (!attribute) {\n log.warn(`shader layout attribute \"${name}\" not present in shader`);\n }\n return attribute || null;\n}\n\nfunction getAttributeFromBufferLayout(\n bufferLayouts: BufferLayout[],\n name: string\n): BufferAttributeInfo | null {\n // Check that bufferLayouts are valid (each either has format or attribute)\n checkBufferLayouts(bufferLayouts);\n\n let bufferLayoutInfo = getAttributeFromShortHand(bufferLayouts, name);\n if (bufferLayoutInfo) {\n return bufferLayoutInfo;\n }\n\n bufferLayoutInfo = getAttributeFromAttributesList(bufferLayouts, name);\n if (bufferLayoutInfo) {\n return bufferLayoutInfo;\n }\n\n // Didn't find...\n log.warn(`layout for attribute \"${name}\" not present in buffer layout`);\n return null;\n}\n\n/** Check that bufferLayouts are valid (each either has format or attribute) */\nfunction checkBufferLayouts(bufferLayouts: BufferLayout[]) {\n for (const bufferLayout of bufferLayouts) {\n if (\n (bufferLayout.attributes && bufferLayout.format) ||\n (!bufferLayout.attributes && !bufferLayout.format)\n ) {\n log.warn(`BufferLayout ${name} must have either 'attributes' or 'format' field`);\n }\n }\n}\n\n/** Get attribute from format shorthand if specified */\nfunction getAttributeFromShortHand(\n bufferLayouts: BufferLayout[],\n name: string\n): BufferAttributeInfo | null {\n for (const bufferLayout of bufferLayouts) {\n if (bufferLayout.format && bufferLayout.name === name) {\n return {\n attributeName: bufferLayout.name,\n bufferName: name,\n stepMode: bufferLayout.stepMode,\n vertexFormat: bufferLayout.format,\n // If offset is needed, use `attributes` field.\n byteOffset: 0,\n byteStride: bufferLayout.byteStride || 0\n };\n }\n }\n return null;\n}\n\n/**\n * Search attribute mappings (e.g. interleaved attributes) for buffer mapping.\n * Not the name of the buffer might be the same as one of the interleaved attributes.\n */\nfunction getAttributeFromAttributesList(\n bufferLayouts: BufferLayout[],\n name: string\n): BufferAttributeInfo | null {\n for (const bufferLayout of bufferLayouts) {\n let byteStride: number | undefined = bufferLayout.byteStride;\n\n // Calculate a default byte stride if not provided\n if (typeof bufferLayout.byteStride !== 'number') {\n for (const attributeMapping of bufferLayout.attributes || []) {\n const info = decodeVertexFormat(attributeMapping.format);\n byteStride += info.byteLength;\n }\n }\n\n const attributeMapping = bufferLayout.attributes?.find(mapping => mapping.attribute === name);\n if (attributeMapping) {\n return {\n attributeName: attributeMapping.attribute,\n bufferName: bufferLayout.name,\n stepMode: bufferLayout.stepMode,\n vertexFormat: attributeMapping.format,\n byteOffset: attributeMapping.byteOffset,\n byteStride\n };\n }\n }\n\n return null;\n}\n\n/**\n * Merges an provided shader layout into a base shader layout\n * In WebGL, this allows the auto generated shader layout to be overridden by the application\n * Typically to change the format of the vertex attributes (from float32x4 to uint8x4 etc).\n * @todo Drop this? Aren't all use cases covered by mergeBufferLayout()?\n */\nexport function mergeShaderLayout(\n baseLayout: ShaderLayout,\n overrideLayout: ShaderLayout\n): ShaderLayout {\n // Deep clone the base layout\n const mergedLayout: ShaderLayout = {\n ...baseLayout,\n attributes: baseLayout.attributes.map(attribute => ({...attribute}))\n };\n // Merge the attributes\n for (const attribute of overrideLayout?.attributes || []) {\n const baseAttribute = mergedLayout.attributes.find(attr => attr.name === attribute.name);\n if (!baseAttribute) {\n log.warn(`shader layout attribute ${attribute.name} not present in shader`);\n } else {\n baseAttribute.type = attribute.type || baseAttribute.type;\n baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;\n }\n }\n return mergedLayout;\n}\n"],"mappings":"SAGQA,GAAG;AAAA,SAIHC,yBAAyB;AAAA,SAEzBC,kBAAkB;AAkD1B,OAAO,SAASC,4BAA4BA,CAC1CC,YAA0B,EAC1BC,YAA4B,EACG;EAC/B,MAAMC,cAA6C,GAAG,CAAC,CAAC;EACxD,KAAK,MAAMC,SAAS,IAAIH,YAAY,CAACI,UAAU,EAAE;IAC/CF,cAAc,CAACC,SAAS,CAACE,IAAI,CAAC,GAAGC,2BAA2B,CAC1DN,YAAY,EACZC,YAAY,EACZE,SAAS,CAACE,IACZ,CAAC;EACH;EACA,OAAOH,cAAc;AACvB;AAKA,OAAO,SAASK,2BAA2BA,CACzCP,YAA0B,EAC1BC,YAA4B,EAEX;EAAA,IADjBO,mBAA2B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EAEhC,MAAMP,cAAc,GAAGH,4BAA4B,CAACC,YAAY,EAAEC,YAAY,CAAC;EAC/E,MAAMW,aAA8B,GAAG,IAAIC,KAAK,CAACL,mBAAmB,CAAC,CAACM,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E;MACpB,OAAO;QACLxB,aAAa,EAAEwB,gBAAgB,CAACjD,SAAS;QACzC0B,UAAU,EAAE5B,YAAY,CAACI,IAAI;QAC7BkC,QAAQ,EAAEtC,YAAY,CAACsC,QAAQ;QAC/Bd,YAAY,EAAE2B,gBAAgB,CAACF,MAAM;QACrCV,UAAU,EAAEY,gBAAgB,CAACZ,UAAU;QACvCC;MACF,CAAC;IACH;EACF;EAEA,OAAO,IAAI;AACb;AAQA,OAAO,SAASe,iBAAiBA,CAC/BC,UAAwB,EACxBC,cAA4B,EACd;EAEd,MAAMC,YAA0B,GAAG;IACjC,GAAGF,UAAU;IACbrD,UAAU,EAAEqD,UAAU,CAACrD,UAAU,CAACwD,GAAG,CAACzD,SAAS,KAAK;MAAC,GAAGA;IAAS,CAAC,CAAC;EACrE,CAAC;EAED,KAAK,MAAMA,SAAS,IAAI,CAAAuD,cAAc,aAAdA,cAAc,uBAAdA,cAAc,CAAEtD,UAAU,KAAI,EAAE,EAAE;IACxD,MAAMyD,aAAa,GAAGF,YAAY,CAACvD,UAAU,CAACsC,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACtC,IAAI,KAAKF,SAAS,CAACE,IAAI,CAAC;IACxF,IAAI,CAACwD,aAAa,EAAE;MAClBjE,GAAG,CAACgD,IAAI,CAAE,2BAA0BzC,SAAS,CAACE,IAAK,wBAAuB,CAAC;IAC7E,CAAC,MAAM;MACLwD,aAAa,CAACrC,IAAI,GAAGrB,SAAS,CAACqB,IAAI,IAAIqC,aAAa,CAACrC,IAAI;MACzDqC,aAAa,CAACtB,QAAQ,GAAGpC,SAAS,CAACoC,QAAQ,IAAIsB,aAAa,CAACtB,QAAQ;IACvE;EACF;EACA,OAAOoB,YAAY;AACrB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-context.js","names":["isBrowser","log","isPage","document","isPageLoaded","readyState","DEFAULT_CANVAS_CONTEXT_PROPS","canvas","width","height","useDevicePixels","autoResize","container","visible","colorSpace","alphaMode","CanvasContext","constructor","props","device","id","htmlCanvas","offscreenCanvas","type","resizeObserver","_canvasSizeInfo","clientWidth","clientHeight","devicePixelRatio","_props","_props2","createCanvas","getContainer","insertBefore","firstChild","style","visibility","getCanvasFromDOM","HTMLCanvasElement","ResizeObserver","entries","entry","target","update","observe","getDevicePixelRatio","OffscreenCanvas","undefined","dpr","window","getPixelSize","parentElement","Error","getAspect","cssToDeviceRatio","drawingBufferWidth","getDrawingBufferSize","cssToDevicePixels","cssPixel","yInvert","arguments","length","ratio","scalePixels","setDevicePixelRatio","options","cachedSize","clampedPixelRatio","canvasWidth","Math","floor","canvasHeight","drawingBufferHeight","min","warn","gl","_setAutoCreatedCanvasId","_this$htmlCanvas","pageLoaded","getPageLoadPromise","Promise","resolve","addEventListener","element","getElementById","body","canvasId","targetCanvas","createElement","Number","isFinite","pixel","point","x","scaleX","y","scaleY","t","xHigh","yHigh","max","r","round"],"sources":["../../src/adapter/canvas-context.ts"],"sourcesContent":["// luma.gl, MIT license\nimport {isBrowser} from '@probe.gl/env';\nimport type {Device} from './device';\nimport type {Framebuffer} from './resources/framebuffer';\nimport {log} from '../utils/log';\n\nconst isPage: boolean = isBrowser() && typeof document !== 'undefined';\nconst isPageLoaded: () => boolean = () => isPage && document.readyState === 'complete';\n\n/** Properties for a CanvasContext */\nexport type CanvasContextProps = {\n /** If canvas not supplied, will be created and added to the DOM. If string, will be looked up in the DOM */\n canvas?: HTMLCanvasElement | OffscreenCanvas | string | null;\n /** If new canvas is created, it will be created in the specified container, otherwise appended to body */\n container?: HTMLElement | string | null;\n /** Width in pixels of the canvas */\n width?: number;\n /** Height in pixels of the canvas */\n height?: number;\n /** Whether to apply a device pixels scale factor (`true` uses browser DPI) */\n useDevicePixels?: boolean | number;\n /** Whether to track resizes (if not ) */\n autoResize?: boolean;\n /** Visibility (only used if new canvas is created). */\n visible?: boolean;\n /** WebGPU only https://www.w3.org/TR/webgpu/#canvas-configuration */\n colorSpace?: 'srgb'; // GPUPredefinedColorSpace\n /** WebGPU only https://www.w3.org/TR/webgpu/#canvas-configuration */\n alphaMode?: 'opaque' | 'premultiplied';\n};\n\nconst DEFAULT_CANVAS_CONTEXT_PROPS: Required<CanvasContextProps> = {\n canvas: null,\n width: 800, // width are height are only used by headless gl\n height: 600,\n useDevicePixels: true,\n autoResize: true,\n container: null,\n visible: true,\n colorSpace: 'srgb',\n alphaMode: 'opaque'\n};\n\n/**\n * Manages a canvas. Supports both HTML or offscreen canvas\n * - Creates a new canvas or looks up a canvas from the DOM\n * - Provides check for DOM loaded\n * @todo commit(): https://github.com/w3ctag/design-reviews/issues/288\n * @todo transferControlToOffscreen: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/transferControlToOffscreen\n */\nexport abstract class CanvasContext {\n abstract readonly device: Device;\n readonly id: string;\n readonly props: Required<CanvasContextProps>;\n readonly canvas: HTMLCanvasElement | OffscreenCanvas;\n readonly htmlCanvas?: HTMLCanvasElement;\n readonly offscreenCanvas?: OffscreenCanvas;\n readonly type: 'html-canvas' | 'offscreen-canvas' | 'node';\n\n width: number = 1;\n height: number = 1;\n\n readonly resizeObserver: ResizeObserver | undefined;\n\n /** State used by luma.gl classes: TODO - move to canvasContext*/\n readonly _canvasSizeInfo = {clientWidth: 0, clientHeight: 0, devicePixelRatio: 1};\n\n /** Check if the DOM is loaded */\n static get isPageLoaded(): boolean {\n return isPageLoaded();\n }\n\n /**\n * Get a 'lazy' promise that resolves when the DOM is loaded.\n * @note Since there may be limitations on number of `load` event listeners,\n * it is recommended avoid calling this function until actually needed.\n * I.e. don't call it until you know that you will be looking up a string in the DOM.\n */\n static pageLoaded: Promise<void> = getPageLoadPromise();\n\n constructor(props?: CanvasContextProps) {\n this.props = {...DEFAULT_CANVAS_CONTEXT_PROPS, ...props};\n props = this.props;\n\n if (!isBrowser()) {\n this.id = 'node-canvas-context';\n this.type = 'node';\n this.width = this.props.width;\n this.height = this.props.height;\n // TODO - does this prevent app from using jsdom style polyfills?\n this.canvas = null!;\n return;\n }\n\n if (!props.canvas) {\n const canvas = createCanvas(props);\n const container = getContainer(props?.container || null);\n container.insertBefore(canvas, container.firstChild);\n\n this.canvas = canvas;\n\n if (!props?.visible) {\n this.canvas.style.visibility = 'hidden';\n }\n } else if (typeof props.canvas === 'string') {\n this.canvas = getCanvasFromDOM(props.canvas);\n } else {\n this.canvas = props.canvas;\n }\n\n if (this.canvas instanceof HTMLCanvasElement) {\n this.id = this.canvas.id;\n this.type = 'html-canvas';\n this.htmlCanvas = this.canvas;\n } else {\n this.id = 'offscreen-canvas';\n this.type = 'offscreen-canvas';\n this.offscreenCanvas = this.canvas;\n }\n\n // React to size changes\n if (this.canvas instanceof HTMLCanvasElement && props.autoResize) {\n this.resizeObserver = new ResizeObserver((entries) => {\n for (const entry of entries) {\n if (entry.target === this.canvas) {\n this.update();\n }\n }\n });\n this.resizeObserver.observe(this.canvas);\n }\n }\n\n /** Returns a framebuffer with properly resized current 'swap chain' textures */\n abstract getCurrentFramebuffer(): Framebuffer;\n\n /**\n * Returns the current DPR, if props.useDevicePixels is true\n * Device refers to physical\n */\n getDevicePixelRatio(useDevicePixels?: boolean | number): number {\n if (typeof OffscreenCanvas !== 'undefined' && this.canvas instanceof OffscreenCanvas) {\n return 1;\n }\n\n useDevicePixels = useDevicePixels === undefined ? this.props.useDevicePixels : useDevicePixels;\n\n if (!useDevicePixels || useDevicePixels as number <= 0) {\n return 1;\n }\n\n // The param was mainly provide to support the test cases, could be removed\n if (useDevicePixels === true) {\n const dpr = typeof window !== 'undefined' && window.devicePixelRatio;\n return dpr || 1;\n }\n\n return useDevicePixels;\n }\n\n /**\n * Returns the size of drawing buffer in device pixels.\n * @note This can be different from the 'CSS' size of a canvas, and also from the\n * canvas' internal drawing buffer size (.width, .height).\n * This is the size required to cover the canvas, adjusted for DPR\n */\n getPixelSize(): [number, number] {\n switch (this.type) {\n case 'node':\n return [this.width, this.height];\n case 'offscreen-canvas':\n return [this.canvas.width, this.canvas.height];\n case 'html-canvas':\n const dpr = this.getDevicePixelRatio();\n const canvas = this.canvas as HTMLCanvasElement;\n // If not attached to DOM client size can be 0\n return canvas.parentElement\n ? [canvas.clientWidth * dpr, canvas.clientHeight * dpr]\n : [this.canvas.width, this.canvas.height];\n default:\n throw new Error(this.type);\n }\n }\n\n getAspect(): number {\n const [width, height] = this.getPixelSize();\n return width / height;\n }\n\n /**\n * Returns multiplier need to convert CSS size to Device size\n */\n cssToDeviceRatio(): number {\n try {\n // For headless gl we might have used custom width and height\n // hence use cached clientWidth\n const [drawingBufferWidth] = this.getDrawingBufferSize();\n const {clientWidth} = this._canvasSizeInfo;\n return clientWidth ? drawingBufferWidth / clientWidth : 1;\n } catch {\n return 1;\n }\n }\n\n /**\n * Maps CSS pixel position to device pixel position\n */\n cssToDevicePixels(\n cssPixel: number[],\n yInvert: boolean = true\n ): {\n x: number;\n y: number;\n width: number;\n height: number;\n } {\n const ratio = this.cssToDeviceRatio();\n const [width, height] = this.getDrawingBufferSize();\n return scalePixels(cssPixel, ratio, width, height, yInvert);\n }\n\n /**\n * Use devicePixelRatio to set canvas width and height\n * @note this is a raw port of luma.gl v8 code. Might be worth a review\n */\n setDevicePixelRatio(\n devicePixelRatio: number,\n options: {width?: number; height?: number} = {}\n ): void {\n if (!this.htmlCanvas) {\n return;\n }\n\n // NOTE: if options.width and options.height not used remove in v8\n let clientWidth = 'width' in options ? options.width : this.htmlCanvas.clientWidth;\n let clientHeight = 'height' in options ? options.height : this.htmlCanvas.clientHeight;\n\n if (!clientWidth || !clientHeight) {\n log.log(1, 'Canvas clientWidth/clientHeight is 0')();\n // by forcing devicePixel ratio to 1, we do not scale canvas.width and height in each frame.\n devicePixelRatio = 1;\n clientWidth = this.htmlCanvas.width || 1;\n clientHeight = this.htmlCanvas.height || 1;\n }\n\n const cachedSize = this._canvasSizeInfo;\n // Check if canvas needs to be resized\n if (\n cachedSize.clientWidth !== clientWidth ||\n cachedSize.clientHeight !== clientHeight ||\n cachedSize.devicePixelRatio !== devicePixelRatio\n ) {\n let clampedPixelRatio = devicePixelRatio;\n\n const canvasWidth = Math.floor(clientWidth * clampedPixelRatio);\n const canvasHeight = Math.floor(clientHeight * clampedPixelRatio);\n this.htmlCanvas.width = canvasWidth;\n this.htmlCanvas.height = canvasHeight;\n\n // Note: when devicePixelRatio is too high, it is possible we might hit system limit for\n // drawing buffer width and hight, in those cases they get clamped and resulting aspect ration may not be maintained\n // for those cases, reduce devicePixelRatio.\n const [drawingBufferWidth, drawingBufferHeight] = this.getDrawingBufferSize();\n\n if (drawingBufferWidth !== canvasWidth || drawingBufferHeight !== canvasHeight) {\n clampedPixelRatio = Math.min(\n drawingBufferWidth / clientWidth,\n drawingBufferHeight / clientHeight\n );\n\n this.htmlCanvas.width = Math.floor(clientWidth * clampedPixelRatio);\n this.htmlCanvas.height = Math.floor(clientHeight * clampedPixelRatio);\n\n log.warn('Device pixel ratio clamped')();\n }\n\n this._canvasSizeInfo.clientWidth = clientWidth;\n this._canvasSizeInfo.clientHeight = clientHeight;\n this._canvasSizeInfo.devicePixelRatio = devicePixelRatio;\n }\n }\n\n // PRIVATE\n\n /** @todo Major hack done to port the CSS methods above, base canvas context should not depend on WebGL */\n getDrawingBufferSize(): [number, number] {\n // @ts-expect-error This only works for WebGL\n const gl = this.device.gl;\n if (!gl) {\n // use default device pixel ratio\n throw new Error('canvas size');\n }\n return [gl.drawingBufferWidth, gl.drawingBufferHeight];\n }\n\n abstract resize(options?: {\n width?: number;\n height?: number;\n useDevicePixels?: boolean | number;\n }): void;\n\n /** Perform platform specific updates (WebGPU vs WebGL) */\n protected abstract update(): void;\n\n /**\n * Allows subclass constructor to override the canvas id for auto created canvases.\n * This can really help when debugging DOM in apps that create multiple devices\n */\n protected _setAutoCreatedCanvasId(id: string) {\n if (this.htmlCanvas?.id === 'lumagl-auto-created-canvas') {\n this.htmlCanvas.id = id;\n }\n }\n}\n\n// HELPER FUNCTIONS\n\n/** Returns a promise that resolves when the page is loaded */\nfunction getPageLoadPromise(): Promise<void> {\n if (isPageLoaded() || typeof window === 'undefined') {\n return Promise.resolve();\n }\n return new Promise((resolve) => {\n window.addEventListener('load', () => resolve());\n });\n}\n\nfunction getContainer(container: HTMLElement | string | null): HTMLElement {\n if (typeof container === 'string') {\n const element = document.getElementById(container);\n if (!element && !isPageLoaded()) {\n throw new Error(`Accessing '${container}' before page was loaded`);\n }\n if (!element) {\n throw new Error(`${container} is not an HTML element`);\n }\n return element;\n } else if (container) {\n return container;\n }\n return document.body;\n}\n\n/** Get a Canvas element from DOM id */\nfunction getCanvasFromDOM(canvasId: string): HTMLCanvasElement {\n const canvas = document.getElementById(canvasId);\n if (!canvas && !isPageLoaded()) {\n throw new Error(`Accessing '${canvasId}' before page was loaded`);\n }\n if (!(canvas instanceof HTMLCanvasElement)) {\n throw new Error('Object is not a canvas element');\n }\n return canvas;\n}\n\n/** Create a new canvas */\nfunction createCanvas(props: CanvasContextProps) {\n const {width, height} = props;\n const targetCanvas = document.createElement('canvas');\n targetCanvas.id = 'lumagl-auto-created-canvas';\n targetCanvas.width = width || 1;\n targetCanvas.height = height || 1;\n targetCanvas.style.width = Number.isFinite(width) ? `${width}px` : '100%';\n targetCanvas.style.height = Number.isFinite(height) ? `${height}px` : '100%';\n return targetCanvas;\n}\n\n/**\n *\n * @param pixel\n * @param ratio\n * @param width\n * @param height\n * @param yInvert\n * @returns\n */\nfunction scalePixels(\n pixel: number[],\n ratio: number,\n width: number,\n height: number,\n yInvert: boolean\n): {\n x: number;\n y: number;\n width: number;\n height: number;\n} {\n const point = pixel as [number, number];\n \n const x = scaleX(point[0], ratio, width);\n let y = scaleY(point[1], ratio, height, yInvert);\n\n // Find boundaries of next pixel to provide valid range of device pixel locations\n\n let t = scaleX(point[0] + 1, ratio, width);\n // If next pixel's position is clamped to boundary, use it as is, otherwise subtract 1 for current pixel boundary\n const xHigh = t === width - 1 ? t : t - 1;\n\n t = scaleY(point[1] + 1, ratio, height, yInvert);\n let yHigh;\n if (yInvert) {\n // If next pixel's position is clamped to boundary, use it as is, otherwise clamp it to valid range\n t = t === 0 ? t : t + 1;\n // swap y and yHigh\n yHigh = y;\n y = t;\n } else {\n // If next pixel's position is clamped to boundary, use it as is, otherwise clamp it to valid range\n yHigh = t === height - 1 ? t : t - 1;\n // y remains same\n }\n return {\n x,\n y,\n // when ratio < 1, current css pixel and next css pixel may point to same device pixel, set width/height to 1 in those cases.\n width: Math.max(xHigh - x + 1, 1),\n height: Math.max(yHigh - y + 1, 1)\n };\n}\n\nfunction scaleX(x: number, ratio: number, width: number): number {\n // since we are rounding to nearest, when ratio > 1, edge pixels may point to out of bounds value, clamp to the limit\n const r = Math.min(Math.round(x * ratio), width - 1);\n return r;\n}\n\nfunction scaleY(y: number, ratio: number, height: number, yInvert: boolean): number {\n // since we are rounding to nearest, when ratio > 1, edge pixels may point to out of bounds value, clamp to the limit\n return yInvert\n ? Math.max(0, height - 1 - Math.round(y * ratio))\n : Math.min(Math.round(y * ratio), height - 1);\n}\n"],"mappings":"AACA,SAAQA,SAAS,QAAO,eAAe;AAAC,SAGhCC,GAAG;AAEX,MAAMC,MAAe,GAAGF,SAAS,CAAC,CAAC,IAAI,OAAOG,QAAQ,KAAK,WAAW;AACtE,MAAMC,YAA2B,GAAGA,CAAA,KAAMF,MAAM,IAAIC,QAAQ,CAACE,UAAU,KAAK,UAAU;AAwBtF,MAAMC,4BAA0D,GAAG;EACjEC,MAAM,EAAE,IAAI;EACZC,KAAK,EAAE,GAAG;EACVC,MAAM,EAAE,GAAG;EACXC,eAAe,EAAE,IAAI;EACrBC,UAAU,EAAE,IAAI;EAChBC,SAAS,EAAE,IAAI;EACfC,OAAO,EAAE,IAAI;EACbC,UAAU,EAAE,MAAM;EAClBC,SAAS,EAAE;AACb,CAAC;AASD,OAAO,MAAeC,aAAa,CAAC;EAkBlC,WAAWZ,YAAYA,CAAA,EAAY;IACjC,OAAOA,YAAY,CAAC,CAAC;EACvB;EAUAa,WAAWA,CAACC,KAA0B,EAAE;IAAA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AC;EACpD,OAAO6F,CAAC;AACV;AAEA,SAASL,MAAMA,CAACD,CAAS,EAAEjC,KAAa,EAAErD,MAAc,EAAEkD,OAAgB,EAAU;EAElF,OAAOA,OAAO,GACVU,IAAI,CAAC+B,GAAG,CAAC,CAAC,EAAE3F,MAAM,GAAG,CAAC,GAAG4D,IAAI,CAACiC,KAAK,CAACP,CAAC,GAAGjC,KAAK,CAAC,CAAC,GAC/CO,IAAI,CAACI,GAAG,CAACJ,IAAI,CAACiC,KAAK,CAACP,CAAC,GAAGjC,KAAK,CAAC,EAAErD,MAAM,GAAG,CAAC,CAAC;AACjD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"device.js","names":["VERSION","lumaStats","log","uid","Buffer","_Symbol$toStringTag","Symbol","toStringTag","Device","constructor","props","id","statsManager","userData","_lumaData","info","lost","canvasContext","defaultProps","toLowerCase","loseDevice","getCanvasContext","Error","createTexture","Promise","data","_createTexture","createCommandEncoder","arguments","length","undefined","readPixelsToArrayWebGL","source","options","readPixelsToBufferWebGL","setParametersWebGL","parameters","getParametersWebGL","withParametersWebGL","func","clearWebGL","_getBufferProps","ArrayBuffer","isView","newProps","usage","INDEX","indexType","Uint32Array","Uint16Array","warn","type","canvas","container","webgl2","webgl1","manageState","width","height","debug","Boolean","get","break","gl"],"sources":["../../src/adapter/device.ts"],"sourcesContent":["// luma.gl, MIT license\nimport {VERSION} from '../init';\nimport {StatsManager, lumaStats} from '../utils/stats-manager';\nimport {log} from '../utils/log';\nimport {uid} from '../utils/utils';\nimport type {TextureFormat} from './types/texture-formats';\nimport type {CanvasContext, CanvasContextProps} from './canvas-context';\nimport type {BufferProps} from './resources/buffer';\nimport {Buffer} from './resources/buffer';\nimport type {RenderPipeline, RenderPipelineProps} from './resources/render-pipeline';\nimport type {ComputePipeline, ComputePipelineProps} from './resources/compute-pipeline';\nimport type {Sampler, SamplerProps} from './resources/sampler';\nimport type {Shader, ShaderProps} from './resources/shader';\nimport type {Texture, TextureProps, TextureData} from './resources/texture';\nimport type {ExternalTexture, ExternalTextureProps} from './resources/external-texture';\nimport type {Framebuffer, FramebufferProps} from './resources/framebuffer';\nimport type {RenderPass, RenderPassProps} from './resources/render-pass';\nimport type {ComputePass, ComputePassProps} from './resources/compute-pass';\nimport type {CommandEncoder, CommandEncoderProps} from './resources/command-encoder';\nimport type {VertexArray, VertexArrayProps} from './resources/vertex-array';\nimport type {TransformFeedback, TransformFeedbackProps} from './resources/transform-feedback';\n\n/** Device properties */\nexport type DeviceProps = {\n id?: string;\n\n type?: 'webgl' | 'webgl1' | 'webgl2' | 'webgpu' | 'best-available';\n\n // Common parameters\n canvas?: HTMLCanvasElement | OffscreenCanvas | string | null; // A canvas element or a canvas string id\n container?: HTMLElement | string | null;\n width?: number /** width is only used when creating a new canvas */;\n height?: number /** height is only used when creating a new canvas */;\n\n // WebGLDevice parameters\n webgl2?: boolean; // Set to false to not create a WebGL2 context (force webgl1)\n webgl1?: boolean; // set to false to not create a WebGL1 context (fails if webgl2 not available)\n\n // WebGLContext PARAMETERS - Can only be set on context creation...\n // alpha?: boolean; // Default render target has an alpha buffer.\n // depth?: boolean; // Default render target has a depth buffer of at least 16 bits.\n // stencil?: boolean; // Default render target has a stencil buffer of at least 8 bits.\n // antialias?: boolean; // Boolean that indicates whether or not to perform anti-aliasing.\n // premultipliedAlpha?: boolean; // Boolean that indicates that the page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.\n // preserveDrawingBuffer?: boolean; // Default render target buffers will not be automatically cleared and will preserve their values until cleared or overwritten\n // failIfMajorPerformanceCaveat?: boolean; // Do not create if the system performance is low.\n\n // Unclear if these are still supported\n debug?: boolean; // Instrument context (at the expense of performance)\n manageState?: boolean; // Set to false to disable WebGL state management instrumentation\n break?: string[]; // TODO: types\n\n // @deprecated Attach to existing context\n gl?: WebGLRenderingContext | WebGL2RenderingContext | null;\n};\n\n/**\n * Identifies the GPU vendor and driver.\n * @note Chrome WebGPU does not provide much information, though more can be enabled with\n * @see https://developer.chrome.com/blog/new-in-webgpu-120#adapter_information_updates\n * chrome://flags/#enable-webgpu-developer-features\n */\nexport type DeviceInfo = {\n /** Type of device */\n type: 'webgl' | 'webgl2' | 'webgpu';\n /** Vendor (name of GPU vendor, Apple, nVidia etc */\n vendor: string;\n /** Renderer (usually driver name) */\n renderer: string;\n /** version of driver */\n version: string;\n /** family of GPU */\n gpu: 'nvidia' | 'amd' | 'intel' | 'apple' | 'software' | 'unknown';\n /** Type of GPU () */\n gpuType: 'discrete' | 'integrated' | 'cpu' | 'unknown';\n /** GPU architecture */\n gpuArchitecture?: string; // 'common-3' on Apple\n /** GPU driver backend. Can sometimes be sniffed */\n gpuBackend?: 'opengl' | 'opengles' | 'metal' | 'd3d11' | 'd3d12' | 'vulkan' | 'unknown';\n /** If this is a fallback adapter */\n fallback?: boolean;\n /** Shader language supported by device.createShader() */\n shadingLanguage: 'wgsl' | 'glsl';\n /** Highest supported shader language version (GLSL 3.00 = 300, GLSL 1.00 = 100) */\n shadingLanguageVersion: number;\n};\n\n/** Limits for a device */\nexport type DeviceLimits = {\n readonly maxTextureDimension1D?: number;\n readonly maxTextureDimension2D?: number;\n readonly maxTextureDimension3D?: number;\n readonly maxTextureArrayLayers?: number;\n readonly maxBindGroups: number;\n readonly maxDynamicUniformBuffersPerPipelineLayout: number;\n readonly maxDynamicStorageBuffersPerPipelineLayout: number;\n readonly maxSampledTexturesPerShaderStage: number;\n readonly maxSamplersPerShaderStage: number;\n readonly maxStorageBuffersPerShaderStage: number;\n readonly maxStorageTexturesPerShaderStage: number;\n readonly maxUniformBuffersPerShaderStage: number;\n readonly maxUniformBufferBindingSize: number;\n readonly maxStorageBufferBindingSize?: number;\n readonly minUniformBufferOffsetAlignment?: number;\n readonly minStorageBufferOffsetAlignment?: number;\n readonly maxVertexBuffers?: number;\n readonly maxVertexAttributes: number;\n readonly maxVertexBufferArrayStride?: number;\n readonly maxInterStageShaderComponents?: number;\n readonly maxComputeWorkgroupStorageSize?: number;\n readonly maxComputeInvocationsPerWorkgroup?: number;\n readonly maxComputeWorkgroupSizeX?: number;\n readonly maxComputeWorkgroupSizeY?: number;\n readonly maxComputeWorkgroupSizeZ?: number;\n readonly maxComputeWorkgroupsPerDimension?: number;\n};\n\nexport type WebGPUDeviceFeature =\n | 'depth-clip-control'\n | 'depth24unorm-stencil8'\n | 'depth32float-stencil8'\n | 'timestamp-query'\n | 'indirect-first-instance'\n | 'texture-compression-bc'\n | 'texture-compression-etc2'\n | 'texture-compression-astc';\n\n// obsolete...\n// 'depth-clamping' |\n// 'depth24unorm-stencil8' |\n// 'depth32float-stencil8' |\n// 'pipeline-statistics-query' |\n// 'timestamp-query' |\n// 'texture-compression-bc'\n\nexport type WebGLDeviceFeature =\n | 'webgpu'\n | 'webgl2'\n | 'webgl'\n\n // api support (unify with WebGPU timestamp-query?)\n | 'timer-query-webgl'\n | 'uniform-buffers-webgl'\n | 'uniforms-webgl'\n\n // texture filtering\n | 'texture-filter-linear-float32-webgl'\n | 'texture-filter-linear-float16-webgl'\n | 'texture-filter-anisotropic-webgl'\n\n // texture rendering\n | 'texture-renderable-float32-webgl'\n | 'texture-renderable-float16-webgl'\n | 'texture-renderable-rgba32float-webgl' // TODO - remove\n\n // texture blending\n | 'texture-blend-float-webgl1'\n\n // texture format support\n | 'texture-formats-norm16-webgl'\n | 'texture-formats-srgb-webgl1'\n | 'texture-formats-depth-webgl1'\n | 'texture-formats-float32-webgl1'\n | 'texture-formats-float16-webgl1'\n\n // api support\n | 'vertex-array-object-webgl1'\n | 'instanced-rendering-webgl1'\n | 'multiple-render-targets-webgl1'\n | 'index-uint32-webgl1'\n | 'blend-minmax-webgl1'\n | 'transform-feedback-webgl2'\n\n // glsl extensions\n | 'glsl-frag-data'\n | 'glsl-frag-depth'\n | 'glsl-derivatives'\n | 'glsl-texture-lod';\n\ntype WebGLCompressedTextureFeatures =\n | 'texture-compression-bc5-webgl'\n | 'texture-compression-etc1-webgl'\n | 'texture-compression-pvrtc-webgl'\n | 'texture-compression-atc-webgl';\n\n/** Valid feature strings */\nexport type DeviceFeature =\n | WebGPUDeviceFeature\n | WebGLDeviceFeature\n | WebGLCompressedTextureFeatures;\n\n/**\n * WebGPU Device/WebGL context abstraction\n */\nexport abstract class Device {\n\n static defaultProps: Required<DeviceProps> = {\n id: null!,\n type: 'best-available',\n canvas: null,\n container: null,\n webgl2: true, // Attempt to create a WebGL2 context\n webgl1: true, // Attempt to create a WebGL1 context (false to fail if webgl2 not available)\n manageState: true,\n width: 800, // width are height are only used by headless gl\n height: 600,\n debug: Boolean(log.get('debug')), // Instrument context (at the expense of performance)\n break: [],\n \n // alpha: undefined,\n // depth: undefined,\n // stencil: undefined,\n // antialias: undefined,\n // premultipliedAlpha: undefined,\n // preserveDrawingBuffer: undefined,\n // failIfMajorPerformanceCaveat: undefined\n \n gl: null\n };\n \n\n get [Symbol.toStringTag](): string {\n return 'Device';\n }\n\n static VERSION = VERSION;\n\n constructor(props: DeviceProps) {\n this.props = {...Device.defaultProps, ...props};\n this.id = this.props.id || uid(this[Symbol.toStringTag].toLowerCase());\n }\n\n /** id of this device, primarily for debugging */\n readonly id: string;\n /** stats */\n readonly statsManager: StatsManager = lumaStats;\n /** A copy of the device props */\n readonly props: Required<DeviceProps>;\n /** Available for the application to store data on the device */\n userData: {[key: string]: unknown} = {};\n /** Used by other luma.gl modules to store data on the device */\n _lumaData: {[key: string]: unknown} = {};\n\n abstract destroy(): void;\n\n // Capabilities\n\n /** Information about the device (vendor, versions etc) */\n abstract info: DeviceInfo;\n\n /** Optional capability discovery */\n abstract get features(): Set<DeviceFeature>;\n\n /** WebGPU style device limits */\n abstract get limits(): DeviceLimits;\n\n /** Check if device supports a specific texture format (creation and `nearest` sampling) */\n abstract isTextureFormatSupported(format: TextureFormat): boolean;\n\n /** Check if linear filtering (sampler interpolation) is supported for a specific texture format */\n abstract isTextureFormatFilterable(format: TextureFormat): boolean;\n\n /** Check if device supports rendering to a specific texture format */\n abstract isTextureFormatRenderable(format: TextureFormat): boolean;\n\n // Device loss\n\n /** `true` if device is already lost */\n abstract get isLost(): boolean;\n\n /** Promise that resolves when device is lost */\n abstract readonly lost: Promise<{reason: 'destroyed'; message: string}>;\n\n /**\n * Trigger device loss.\n * @returns `true` if context loss could actually be triggered.\n * @note primarily intended for testing how application reacts to device loss\n */\n loseDevice(): boolean {\n return false;\n }\n\n // Canvas context\n\n /** Default / primary canvas context. Can be null as WebGPU devices can be created without a CanvasContext */\n abstract canvasContext: CanvasContext | null;\n\n /** Returns the default / primary canvas context. Throws an error if no canvas context is available (a WebGPU compute device) */\n getCanvasContext(): CanvasContext {\n if (!this.canvasContext) {\n throw new Error('Device has no CanvasContext');\n }\n return this.canvasContext;\n }\n\n /** Creates a new CanvasContext (WebGPU only) */\n abstract createCanvasContext(props?: CanvasContextProps): CanvasContext;\n\n /** Call after rendering a frame (necessary e.g. on WebGL OffscreenCanvas) */\n abstract submit(): void;\n\n // Resource creation\n\n /** Create a buffer */\n abstract createBuffer(props: BufferProps | ArrayBuffer | ArrayBufferView): Buffer;\n\n /** Create a texture */\n abstract _createTexture(props: TextureProps): Texture;\n createTexture(props: TextureProps): Texture;\n createTexture(data: Promise<TextureData>): Texture;\n createTexture(url: string): Texture;\n\n createTexture(props: TextureProps | Promise<TextureData> | string): Texture {\n // Signature: new Texture2D(gl, url | Promise)\n if (props instanceof Promise || typeof props === 'string') {\n props = {data: props};\n }\n return this._createTexture(props);\n }\n\n /** Create a temporary texture view of a video source */\n abstract createExternalTexture(props: ExternalTextureProps): ExternalTexture;\n\n /** Create a sampler */\n abstract createSampler(props: SamplerProps): Sampler;\n\n /** Create a Framebuffer. Must have at least one attachment. */\n abstract createFramebuffer(props: FramebufferProps): Framebuffer;\n\n /** Create a shader */\n abstract createShader(props: ShaderProps): Shader;\n\n /** Create a render pipeline (aka program) */\n abstract createRenderPipeline(props: RenderPipelineProps): RenderPipeline;\n\n /** Create a compute pipeline (aka program). WebGPU only. */\n abstract createComputePipeline(props: ComputePipelineProps): ComputePipeline;\n\n /** Create a vertex array */\n abstract createVertexArray(props: VertexArrayProps): VertexArray;\n\n /** Create a RenderPass */\n abstract beginRenderPass(props?: RenderPassProps): RenderPass;\n\n /** Create a ComputePass */\n abstract beginComputePass(props?: ComputePassProps): ComputePass;\n\n /** Get a renderpass that is set up to render to the primary CanvasContext */\n abstract getDefaultRenderPass(): RenderPass;\n\n /** Create a transform feedback (immutable set of output buffer bindings). WebGL 2 only. */\n abstract createTransformFeedback(props: TransformFeedbackProps): TransformFeedback;\n\n createCommandEncoder(props: CommandEncoderProps = {}): CommandEncoder {\n throw new Error('not implemented');\n }\n\n // WebGL specific HACKS - enables app to remove webgl import\n // Use until we have a better way to handle these\n\n /** @deprecated - will be removed - should use command encoder */\n readPixelsToArrayWebGL(\n source: Framebuffer | Texture,\n options?: {\n sourceX?: number;\n sourceY?: number;\n sourceFormat?: number;\n sourceAttachment?: number;\n target?: Uint8Array | Uint16Array | Float32Array;\n // following parameters are auto deduced if not provided\n sourceWidth?: number;\n sourceHeight?: number;\n sourceType?: number;\n }\n ): Uint8Array | Uint16Array | Float32Array {\n throw new Error('not implemented');\n }\n \n /** @deprecated - will be removed - should use command encoder */\n readPixelsToBufferWebGL(\n source: Framebuffer | Texture,\n options?: {\n sourceX?: number;\n sourceY?: number;\n sourceFormat?: number;\n target?: Buffer; // A new Buffer object is created when not provided.\n targetByteOffset?: number; // byte offset in buffer object\n // following parameters are auto deduced if not provided\n sourceWidth?: number;\n sourceHeight?: number;\n sourceType?: number;\n }\n ): Buffer {\n throw new Error('not implemented');\n }\n\n /** @deprecated - will be removed - should use WebGPU parameters (pipeline) */\n setParametersWebGL(parameters: any): void {\n throw new Error('not implemented');\n }\n\n /** @deprecated - will be removed - should use WebGPU parameters (pipeline) */\n getParametersWebGL(parameters: any): void {\n throw new Error('not implemented');\n }\n\n /** @deprecated - will be removed - should use WebGPU parameters (pipeline) */\n withParametersWebGL(parameters: any, func: any): any {\n throw new Error('not implemented');\n }\n\n /** @deprecated - will be removed - should use clear arguments in RenderPass */\n clearWebGL(options?: {framebuffer?: Framebuffer; color?: any; depth?: any; stencil?: any}): void {\n throw new Error('not implemented');\n }\n\n // Implementation\n\n protected _getBufferProps(props: BufferProps | ArrayBuffer | ArrayBufferView): BufferProps {\n if (props instanceof ArrayBuffer || ArrayBuffer.isView(props)) {\n props = {data: props};\n }\n\n // TODO - fragile, as this is done before we merge with default options\n // inside the Buffer constructor\n\n const newProps = {...props};\n // Deduce indexType\n if ((props.usage || 0) & Buffer.INDEX && !props.indexType) {\n if (props.data instanceof Uint32Array) {\n newProps.indexType = 'uint32';\n } else if (props.data instanceof Uint16Array) {\n newProps.indexType = 'uint16';\n } else {\n log.warn('indices buffer content must be of integer type')();\n }\n }\n return newProps;\n }\n}\n"],"mappings":";SACQA,OAAO;AAAA,SACOC,SAAS;AAAA,SACvBC,GAAG;AAAA,SACHC,GAAG;AAAA,SAIHC,MAAM;AAAAC,mBAAA,GAqNPC,MAAM,CAACC,WAAW;AA3BzB,OAAO,MAAeC,MAAM,CAAC;EA2B3B,KAAAH,mBAAA,IAAmC;IACjC,OAAO,QAAQ;EACjB;EAIAI,WAAWA,CAACC,KAAkB,EAAE;IAAA,KAMvBC,EAAE;IAAA,KAEFC,YAAY,GAAiBX,SAAS;IAAA,KAEtCS,KAAK;IAAA,KAEdG,QAAQ,GAA6B,CAAC,CAAC;IAAA,KAEvCC,SAAS,GAA6B,CAAC,CAAC;IAAA,KAO/BC,IAAI;IAAA,KAuBKC,IAAI;IAAA,KAcbC,aAAa;IAzDpB,IAAI,CAACP,KAAK,GAAG;MAAC,GAAGF,MAAM,CAACU,YAAY;MAAE,GAAGR;IAAK,CAAC;IAC/C,IAAI,CAACC,EAAE,GAAG,IAAI,CAACD,KAAK,CAACC,EAAE,IAAIR,GAAG,CAAC,IAAI,CAACG,MAAM,CAACC,WAAW,CAAC,CAACY,WAAW,CAAC,CAAC,CAAC;EACxE;EAgDAC,UAAUA,CAAA,EAAY;IAC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,IAAIA,WAAW,CAACC,MAAM,CAACjC,KAAK,CAAC,EAAE;MAC7DA,KAAK,GAAG;QAACe,IAAI,EAAEf;MAAK,CAAC;IACvB;IAKA,MAAMkC,QAAQ,GAAG;MAAC,GAAGlC;IAAK,CAAC;IAE3B,IAAI,CAACA,KAAK,CAACmC,KAAK,IAAI,CAAC,IAAIzC,MAAM,CAAC0C,KAAK,IAAI,CAACpC,KAAK,CAACqC,SAAS,EAAE;MACzD,IAAIrC,KAAK,CAACe,IAAI,YAAYuB,WAAW,EAAE;QACrCJ,QAAQ,CAACG,SAAS,GAAG,QAAQ;MAC/B,CAAC,MAAM,IAAIrC,KAAK,CAACe,IAAI,YAAYwB,WAAW,EAAE;QAC5CL,QAAQ,CAACG,SAAS,GAAG,QAAQ;MAC/B,CAAC,MAAM;QACL7C,GAAG,CAACgD,IAAI,CAAC,gDAAgD,CAAC,CAAC,CAAC;MAC9D;IACF;IACA,OAAON,QAAQ;EACjB;AACF;AArPsBpC,MAAM,CAEnBU,YAAY,GAA0B;EAC3CP,EAAE,EAAE,IAAK;EACTwC,IAAI,EAAE,gBAAgB;EACtBC,MAAM,EAAE,IAAI;EACZC,SAAS,EAAE,IAAI;EACfC,MAAM,EAAE,IAAI;EACZC,MAAM,EAAE,IAAI;EACZC,WAAW,EAAE,IAAI;EACjBC,KAAK,EAAE,GAAG;EACVC,MAAM,EAAE,GAAG;EACXC,KAAK,EAAEC,OAAO,CAAC1D,GAAG,CAAC2D,GAAG,CAAC,OAAO,CAAC,CAAC;EAChCC,KAAK,EAAE,EAAE;EAUTC,EAAE,EAAE;AACN,CAAC;AAxBmBvD,MAAM,CA+BnBR,OAAO,GAAGA,OAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.js","names":["Resource","_Symbol$toStringTag","Symbol","toStringTag","Buffer","constructor","device","props","deducedProps","usage","INDEX","indexType","data","Uint32Array","Uint16Array","defaultProps","byteLength","debugData","ArrayBuffer","readSyncWebGL2","byteOffset","Error","_setDebugData","buffer","isView","debugDataLength","Math","min","DEBUG_DATA_MAX_LENGTH","slice","mappedAtCreation","MAP_READ","MAP_WRITE","COPY_SRC","COPY_DST","VERTEX","UNIFORM","STORAGE","INDIRECT","QUERY_RESOLVE"],"sources":["../../../src/adapter/resources/buffer.ts"],"sourcesContent":["// luma.gl, MIT license\n\nimport type {Device} from '../device';\nimport {Resource, ResourceProps} from './resource';\n\nexport type BufferProps = ResourceProps & {\n /** Supply a handle to connect to an existing device-specific buffer */\n handle?: WebGLBuffer;\n /** Specifies how this buffer can be used */\n usage?: number;\n /** Length in bytes of memory to be allocated. If not specified, `byteLength` of `props.data` will be used. */\n byteLength?: number;\n /** Data to initialize the buffer with. */\n data?: ArrayBuffer | ArrayBufferView | null;\n /** Byte offset into the newly created Buffer to store data at */\n byteOffset?: number;\n /** If props.usage includes Buffer.INDEX */\n indexType?: 'uint16' | 'uint32';\n\n // TBD\n mappedAtCreation?: boolean;\n}\n\n/** Abstract GPU buffer */\nexport abstract class Buffer extends Resource<BufferProps> {\n static override defaultProps: Required<BufferProps> = {\n ...Resource.defaultProps,\n usage: 0, // Buffer.COPY_DST | Buffer.COPY_SRC\n byteLength: 0,\n byteOffset: 0,\n data: null,\n indexType: 'uint16',\n mappedAtCreation: false\n };\n\n // Usage Flags\n static MAP_READ = 0x01;\n static MAP_WRITE = 0x02;\n static COPY_SRC = 0x0004;\n static COPY_DST = 0x0008;\n /** Index buffer */\n static INDEX = 0x0010;\n /** Vertex buffer */\n static VERTEX = 0x0020;\n /** Uniform buffer */\n static UNIFORM = 0x0040;\n /** Storage buffer */\n static STORAGE = 0x0080;\n static INDIRECT = 0x0100;\n static QUERY_RESOLVE = 0x0200;\n\n override get [Symbol.toStringTag](): string { return 'Buffer'; }\n\n /** The usage with which this buffer was created */\n readonly usage: number;\n /** For index buffers, whether indices are 16 or 32 bit */\n readonly indexType?: 'uint16' | 'uint32';\n /** Length of buffer in bytes */\n abstract byteLength: number;\n\n constructor(device: Device, props: BufferProps) {\n const deducedProps = {...props};\n\n // Deduce indexType\n if ((props.usage || 0) & Buffer.INDEX && !props.indexType) {\n if (props.data instanceof Uint32Array) {\n deducedProps.indexType = 'uint32';\n } else if (props.data instanceof Uint16Array) {\n deducedProps.indexType = 'uint16';\n }\n }\n\n super(device, deducedProps, Buffer.defaultProps);\n\n this.usage = props.usage || 0;\n this.indexType = deducedProps.indexType;\n }\n\n /** Write data to buffer */\n abstract write(data: ArrayBufferView, byteOffset?: number): void;\n /** Read data asynchronoursly */\n abstract readAsync(byteOffset?: number, byteLength?: number): Promise<Uint8Array>;\n\n /** Read data synchronously. @note WebGL2 only */\n readSyncWebGL2(byteOffset?: number, byteLength?: number): Uint8Array { throw new Error('not implemented'); }\n\n // PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY)\n\n /** Max amount of debug data saved. Two vec4's */\n static DEBUG_DATA_MAX_LENGTH = 32;\n /** A partial CPU-side copy of the data in this buffer, for debugging purposes */\n debugData: ArrayBuffer = new ArrayBuffer(0);\n\n /** This doesn't handle partial non-zero offset updates correctly */\n protected _setDebugData(data: ArrayBufferView | ArrayBuffer | null, byteOffset: number, byteLength: number): void {\n const buffer: ArrayBuffer | null = ArrayBuffer.isView(data) ? data.buffer : data;\n const debugDataLength = Math.min(data ? data.byteLength : byteLength, Buffer.DEBUG_DATA_MAX_LENGTH);\n if (data === null) {\n this.debugData = new ArrayBuffer(debugDataLength);\n } else if (byteOffset === 0 && byteLength === data.byteLength) {\n this.debugData = buffer.slice(0, debugDataLength);\n } else {\n this.debugData = buffer.slice(byteOffset, byteOffset + debugDataLength);\n }\n }\n}\n"],"mappings":";SAGQA,QAAQ;AAAAC,mBAAA,GAgDAC,MAAM,CAACC,WAAW;AA3BlC,OAAO,MAAeC,MAAM,SAASJ,QAAQ,CAAc;EA2BzD,KAAAC,mBAAA,IAA4C;IAAE,OAAO,QAAQ;EAAE;EAS/DI,WAAWA,CAACC,MAAc,EAAEC,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AC,IAAIJ,UAAU,KAAKJ,IAAI,CAACI,UAAU,EAAE;MAC7D,IAAI,CAACC,SAAS,GAAGM,MAAM,CAACM,KAAK,CAAC,CAAC,EAAEJ,eAAe,CAAC;IACnD,CAAC,MAAM;MACL,IAAI,CAACR,SAAS,GAAGM,MAAM,CAACM,KAAK,CAACT,UAAU,EAAEA,UAAU,GAAGK,eAAe,CAAC;IACzE;EACF;AACF;AAjFsBrB,MAAM,CACVW,YAAY,GAA0B;EACpD,GAAGf,QAAQ,CAACe,YAAY;EACxBN,KAAK,EAAE,CAAC;EACRO,UAAU,EAAE,CAAC;EACbI,UAAU,EAAE,CAAC;EACbR,IAAI,EAAE,IAAI;EACVD,SAAS,EAAE,QAAQ;EACnBmB,gBAAgB,EAAE;AACpB,CAAC;AATmB1B,MAAM,CAYnB2B,QAAQ,GAAG,IAAI;AAZF3B,MAAM,CAanB4B,SAAS,GAAG,IAAI;AAbH5B,MAAM,CAcnB6B,QAAQ,GAAG,MAAM;AAdJ7B,MAAM,CAenB8B,QAAQ,GAAG,MAAM;AAfJ9B,MAAM,CAiBnBM,KAAK,GAAG,MAAM;AAjBDN,MAAM,CAmBnB+B,MAAM,GAAG,MAAM;AAnBF/B,MAAM,CAqBnBgC,OAAO,GAAG,MAAM;AArBHhC,MAAM,CAuBnBiC,OAAO,GAAG,MAAM;AAvBHjC,MAAM,CAwBnBkC,QAAQ,GAAG,MAAM;AAxBJlC,MAAM,CAyBnBmC,aAAa,GAAG,MAAM;AAzBTnC,MAAM,CAiEnBwB,qBAAqB,GAAG,EAAE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-buffer.js","names":["Resource","_Symbol$toStringTag","Symbol","toStringTag","CommandBuffer","constructor","device","props","defaultProps"],"sources":["../../../src/adapter/resources/command-buffer.ts"],"sourcesContent":["// luma.gl, MIT license\nimport { Device } from '../device';\nimport {Resource, ResourceProps} from './resource';\n\n// interface Queue {\n// submit(commandBuffers);\n\n// // onSubmittedWorkDone(): Promise<undefined>;\n\n// writeBuffer(options: WriteBufferOptions): void;\n// writeTexture(options: WriteTextureOptions): void;\n\n// // copyExternalImageToTexture(\n// // GPUImageCopyExternalImage source,\n// // GPUImageCopyTextureTagged destination,\n// // GPUExtent3D copySize\n// // ): void;\n// }\n\nexport type CommandBufferProps = ResourceProps & {\n};\n\n/**\n * Encodes commands to queue that can be executed later\n */\nexport abstract class CommandBuffer extends Resource<CommandBufferProps> {\n static override defaultProps: Required<CommandBufferProps> = {\n ...Resource.defaultProps\n };\n \n override get [Symbol.toStringTag](): string {\n return 'CommandBuffer';\n }\n\n constructor(device: Device, props: CommandBufferProps) {\n super(device, props, CommandBuffer.defaultProps);\n }\n}\n"],"mappings":";SAEQA,QAAQ;AAAAC,mBAAA,GA4BAC,MAAM,CAACC,WAAW;AALlC,OAAO,MAAeC,aAAa,SAASJ,QAAQ,CAAqB;EAKvE,KAAAC,mBAAA,IAA4C;IAC1C,OAAO,eAAe;EACxB;EAEAI,WAAWA,CAACC,MAAc,EAAEC,KAAyB,EAAE;IACrD,KAAK,CAACD,MAAM,EAAEC,KAAK,EAAEH,aAAa,CAACI,YAAY,CAAC;EAClD;AACF;AAZsBJ,aAAa,CACjBI,YAAY,GAAiC;EAC3D,GAAGR,QAAQ,CAACQ;AACd,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-encoder.js","names":["Resource","_Symbol$toStringTag","Symbol","toStringTag","CommandEncoder","constructor","device","props","defaultProps","pushDebugGroup","groupLabel","popDebugGroup","insertDebugMarker","markerLabel","measureExecutionTime","undefined"],"sources":["../../../src/adapter/resources/command-encoder.ts"],"sourcesContent":["// luma.gl, MIT license\nimport {Device} from '../device';\nimport {Resource, ResourceProps} from './resource';\nimport {Buffer} from './buffer';\nimport {Texture} from './texture';\n\nexport type WriteBufferOptions = {\n buffer: Buffer,\n bufferOffset?: number,\n data: BufferSource,\n dataOffset?: number,\n size?: number\n};\n\nexport type WriteTextureOptions = {\n destination: Texture;\n mipLevel?: number; // = 0;\n origin?: [number, number, number] | number[];\n aspect?: 'all' | 'stencil-only' | 'depth-only';\n data: BufferSource;\n // dataLayout;\n offset: number;\n bytesPerRow: number;\n rowsPerImage: number;\n size: [number, number, number] | number[];\n}\n\nexport type CopyBufferToBufferOptions = {\n source: Buffer;\n sourceOffset?: number;\n destination: Buffer;\n destinationOffset?: number;\n size: number;\n};\n\nexport type CopyBufferToTextureOptions = {\n source: Buffer;\n byteOffset?: number;\n destination: Texture;\n mipLevel?: number // = 0;\n origin?: [number, number, number] | number[];\n aspect?: 'all' | 'stencil-only' | 'depth-only';\n bytesPerRow: number;\n rowsPerImage: number;\n size: [number, number, number] | number[];\n};\n\nexport type CopyTextureToBufferOptions = {\n /** Texture to copy to/from. */\n source: Texture;\n /** Mip-map level of the texture to copy to/from. (Default 0) */\n mipLevel?: number;\n /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from.\n * Together with `copySize`, defines the full copy sub-region.\n */\n /** Defines which aspects of the texture to copy to/from. */\n aspect?: 'all' | 'stencil-only' | 'depth-only';\n\n /** Width to copy */\n width?: number;\n height?: number;\n depthOrArrayLayers?: number;\n origin?: number[];\n\n /** Destination buffer */\n destination: Buffer;\n /** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */\n byteOffset?: number;\n /**\n * The stride, in bytes, between the beginning of each block row and the subsequent block row.\n * Required if there are multiple block rows (i.e. the copy height or depth is more than one block).\n */\n bytesPerRow?: number;\n /**\n * Number of block rows per single image of the texture.\n * rowsPerImage × bytesPerRow is the stride, in bytes, between the beginning of each image of data and the subsequent image.\n * Required if there are multiple images (i.e. the copy depth is more than one).\n */\n rowsPerImage?: number;\n};\n\nexport type CopyTextureToTextureOptions = {\n /** Texture to copy to/from. */\n source: Texture;\n /** Mip-map level of the texture to copy to/from. (Default 0) */\n mipLevel?: number;\n /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy from. */\n /** Defines which aspects of the {@link GPUImageCopyTexture#texture} to copy to/from. */\n aspect?: 'all' | 'stencil-only' | 'depth-only';\n\n /** Texture to copy to/from. */\n destination: Texture;\n /** Mip-map level of the texture to copy to/from. (Default 0) */\n destinationMipLevel?: number;\n /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to. */\n destinationOrigin?: number[];\n /** Defines which aspects of the {@link GPUImageCopyTexture#texture} to copy to/from. */\n destinationAspect?: 'all' | 'stencil-only' | 'depth-only';\n\n origin?: number[];\n /** Width to copy */\n width?: number;\n height?: number;\n depthOrArrayLayers?: number;\n};\n\n// interface Queue {\n// submit(commandBuffers);\n\n// // onSubmittedWorkDone(): Promise<undefined>;\n\n// writeBuffer(options: WriteBufferOptions): void;\n// writeTexture(options: WriteTextureOptions): void;\n\n// // copyExternalImageToTexture(\n// // GPUImageCopyExternalImage source,\n// // GPUImageCopyTextureTagged destination,\n// // GPUExtent3D copySize\n// // ): void;\n// }\n\nexport type CommandEncoderProps = ResourceProps & {\n measureExecutionTime?: boolean;\n};\n\n/**\n * Encodes commands to queue that can be executed later\n */\nexport abstract class CommandEncoder extends Resource<CommandEncoderProps> {\n static override defaultProps: Required<CommandEncoderProps> = {\n ...Resource.defaultProps,\n measureExecutionTime: undefined\n };\n \n override get [Symbol.toStringTag](): string {\n return 'CommandEncoder';\n }\n\n constructor(device: Device, props: CommandEncoderProps) {\n super(device, props, CommandEncoder.defaultProps);\n }\n \n abstract finish(): void; // TODO - return the CommandBuffer?\n\n // beginRenderPass(GPURenderPassDescriptor descriptor): GPURenderPassEncoder;\n // beginComputePass(optional GPUComputePassDescriptor descriptor = {}): GPUComputePassEncoder;\n // finish(options?: {id?: string}): GPUCommandBuffer;\n\n abstract copyBufferToBuffer(options: CopyBufferToBufferOptions): void;\n\n abstract copyBufferToTexture(options: CopyBufferToTextureOptions): void;\n\n abstract copyTextureToBuffer(options: CopyTextureToBufferOptions): void;\n\n abstract copyTextureToTexture(options: CopyTextureToTextureOptions): void;\n\n pushDebugGroup(groupLabel: string): void {}\n\n popDebugGroup() {}\n\n insertDebugMarker(markerLabel: string): void {}\n\n // writeTimestamp(querySet: Query, queryIndex: number): void;\n\n // resolveQuerySet(options: {\n // querySet: GPUQuerySet,\n // firstQuery: number,\n // queryCount: number,\n // destination: Buffer,\n // destinationOffset?: number;\n // }): void;\n}\n"],"mappings":";SAEQA,QAAQ;AAAAC,mBAAA,GAoIAC,MAAM,CAACC,WAAW;AANlC,OAAO,MAAeC,cAAc,SAASJ,QAAQ,CAAsB;EAMzE,KAAAC,mBAAA,IAA4C;IAC1C,OAAO,gBAAgB;EACzB;EAEAI,WAAWA,CAACC,MAAc,EAAEC,KAA0B,EAAE;IACtD,KAAK,CAACD,MAAM,EAAEC,KAAK,EAAEH,cAAc,CAACI,YAAY,CAAC;EACnD;EAgBAC,cAAcA,CAACC,UAAkB,EAAQ,CAAC;EAE1CC,aAAaA,CAAA,EAAG,CAAC;EAEjBC,iBAAiBA,CAACC,WAAmB,EAAQ,CAAC;AAWhD;AA3CsBT,cAAc,CAClBI,YAAY,GAAkC;EAC5D,GAAGR,QAAQ,CAACQ,YAAY;EACxBM,oBAAoB,EAAEC;AACxB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compute-pass.js","names":["Resource","_Symbol$toStringTag","Symbol","toStringTag","ComputePass","constructor","device","props","defaultProps"],"sources":["../../../src/adapter/resources/compute-pass.ts"],"sourcesContent":["import {Resource, ResourceProps} from './resource';\nimport {ComputePipeline} from './compute-pipeline';\nimport {Buffer} from './buffer';\nimport type {Device} from '../device';\n\nexport type ComputePassProps = ResourceProps & {};\n\nexport abstract class ComputePass extends Resource<ComputePassProps> {\n static override defaultProps: Required<ComputePassProps> = {\n ...Resource.defaultProps\n }\n\n override get [Symbol.toStringTag](): string {\n return 'ComputePass';\n }\n\n constructor(device: Device, props: ComputePassProps) {\n super(device, props, Resource.defaultProps);\n }\n\n abstract override destroy(): void;\n\n abstract end(): void;\n\n abstract setPipeline(pipeline: ComputePipeline): void;\n\n /** Sets an array of bindings (uniform buffers, samplers, textures, ...) */\n // abstract setBindings(bindings: Binding[]): void;\n\n /**\n * Dispatch work to be performed with the current ComputePipeline.\n * @param x X dimension of the grid of workgroups to dispatch.\n * @param y Y dimension of the grid of workgroups to dispatch.\n * @param z Z dimension of the grid of workgroups to dispatch.\n */\n abstract dispatch(x: number, y?: number, z?: number): void;\n\n /**\n * Dispatch work to be performed with the current ComputePipeline.\n * @param indirectBuffer buffer must be a tightly packed block of three 32-bit unsigned integer values (12 bytes total), given in the same order as the arguments for dispatch()\n * @param indirectOffset\n */\n abstract dispatchIndirect(indirectBuffer: Buffer, indirectOffset?: number): void;\n\n abstract pushDebugGroup(groupLabel: string): void;\n abstract popDebugGroup(): void;\n abstract insertDebugMarker(markerLabel: string): void;\n\n // writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;\n // beginPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;\n // endPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;\n}\n"],"mappings":";SAAQA,QAAQ;AAAAC,mBAAA,GAYAC,MAAM,CAACC,WAAW;AALlC,OAAO,MAAeC,WAAW,SAASJ,QAAQ,CAAmB;EAKnE,KAAAC,mBAAA,IAA4C;IAC1C,OAAO,aAAa;EACtB;EAEAI,WAAWA,CAACC,MAAc,EAAEC,KAAuB,EAAE;IACnD,KAAK,CAACD,MAAM,EAAEC,KAAK,EAAEP,QAAQ,CAACQ,YAAY,CAAC;EAC7C;AAiCF;AA5CsBJ,WAAW,CACfI,YAAY,GAA+B;EACzD,GAAGR,QAAQ,CAACQ;AACd,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compute-pipeline.js","names":["Resource","_Symbol$toStringTag","Symbol","toStringTag","ComputePipeline","constructor","device","props","defaultProps","hash","cs","undefined","csEntryPoint","csConstants","shaderLayout"],"sources":["../../../src/adapter/resources/compute-pipeline.ts"],"sourcesContent":["//\nimport {Resource, ResourceProps} from './resource';\nimport {BindingDeclaration} from '../types/shader-layout';\nimport type {Device} from '../device';\nimport type {Shader} from './shader';\n\n/**\n * Properties for a compute pipeline\n */\nexport type ComputePipelineProps = ResourceProps & {\n handle?: unknown;\n cs: Shader;\n csEntryPoint?: string;\n csConstants?: Record<string, number>; // WGSL only\n shaderLayout?: BindingDeclaration[];\n};\n\n/**\n * A compiled and linked shader program for compute\n */\nexport abstract class ComputePipeline extends Resource<ComputePipelineProps> {\n static override defaultProps: Required<ComputePipelineProps> = {\n ...Resource.defaultProps,\n cs: undefined,\n csEntryPoint: undefined,\n csConstants: {},\n shaderLayout: []\n }; \n\n override get [Symbol.toStringTag](): string {\n return 'ComputePipeline';\n }\n\n hash: string = '';\n\n constructor(device: Device, props: ComputePipelineProps) {\n super(device, props, ComputePipeline.defaultProps);\n }\n}\n"],"mappings":";SACQA,QAAQ;AAAAC,mBAAA,GA4BAC,MAAM,CAACC,WAAW;AATlC,OAAO,MAAeC,eAAe,SAASJ,QAAQ,CAAuB;EAS3E,KAAAC,mBAAA,IAA4C;IAC1C,OAAO,iBAAiB;EAC1B;EAIAI,WAAWA,CAACC,MAAc,EAAEC,KAA2B,EAAE;IACvD,KAAK,CAACD,MAAM,EAAEC,KAAK,EAAEH,eAAe,CAACI,YAAY,CAAC;IAAC,KAHrDC,IAAI,GAAW,EAAE;EAIjB;AACF;AAlBsBL,eAAe,CACnBI,YAAY,GAAmC;EAC7D,GAAGR,QAAQ,CAACQ,YAAY;EACxBE,EAAE,EAAEC,SAAS;EACbC,YAAY,EAAED,SAAS;EACvBE,WAAW,EAAE,CAAC,CAAC;EACfC,YAAY,EAAE;AAChB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"external-texture.js","names":["Resource","_Symbol$toStringTag","Symbol","toStringTag","ExternalTexture","constructor","device","props","defaultProps","source","colorSpace"],"sources":["../../../src/adapter/resources/external-texture.ts"],"sourcesContent":["import type {Device} from '../device';\nimport {Resource, ResourceProps} from './resource';\n\nexport type ExternalTextureProps = ResourceProps & {\n source: HTMLVideoElement | null;\n colorSpace?: 'srgb';\n}\nexport abstract class ExternalTexture extends Resource<ExternalTextureProps> {\n static override defaultProps: Required<ExternalTextureProps> = {\n ...Resource.defaultProps,\n source: null,\n colorSpace: 'srgb'\n };\n\n override get [Symbol.toStringTag](): string { return 'ExternalTexture'; }\n\n constructor(device: Device, props: ExternalTextureProps) {\n super(device, props, ExternalTexture.defaultProps);\n }\n}\n"],"mappings":";SACQA,QAAQ;AAAAC,mBAAA,GAaAC,MAAM,CAACC,WAAW;AAPlC,OAAO,MAAeC,eAAe,SAASJ,QAAQ,CAAuB;EAO3E,KAAAC,mBAAA,IAA4C;IAAE,OAAO,iBAAiB;EAAE;EAExEI,WAAWA,CAACC,MAAc,EAAEC,KAA2B,EAAE;IACvD,KAAK,CAACD,MAAM,EAAEC,KAAK,EAAEH,eAAe,CAACI,YAAY,CAAC;EACpD;AACF;AAZsBJ,eAAe,CACnBI,YAAY,GAAmC;EAC7D,GAAGR,QAAQ,CAACQ,YAAY;EACxBC,MAAM,EAAE,IAAI;EACZC,UAAU,EAAE;AACd,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"framebuffer.js","names":["Resource","Texture","log","_Symbol$toStringTag","Symbol","toStringTag","Framebuffer","constructor","device","props","arguments","length","undefined","defaultProps","width","height","colorAttachments","depthStencilAttachment","resize","size","updateSize","Array","isArray","id","resizeAttachments","autoCreateAttachmentTextures","map","attachment","texture","createColorTexture","attachResource","createDepthStencilTexture","format","createTexture","usage","RENDER_ATTACHMENT","i","resizedTexture","_createTexture","destroyAttachedResource"],"sources":["../../../src/adapter/resources/framebuffer.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {ColorTextureFormat, DepthStencilTextureFormat, TextureFormat} from '../types/texture-formats';\nimport type {Device} from '../device';\nimport {Resource, ResourceProps} from './resource';\nimport {Texture} from './texture';\nimport {log} from '../../utils/log';\n\nexport type FramebufferProps = ResourceProps & {\n width?: number;\n height?: number;\n colorAttachments?: (Texture | ColorTextureFormat)[];\n depthStencilAttachment?: (Texture | DepthStencilTextureFormat) | null;\n};\n\n/**\n * Create new textures with correct size for all attachments.\n * @note resize() destroys existing textures (if size has changed).\n */\nexport abstract class Framebuffer extends Resource<FramebufferProps> {\n static override defaultProps: Required<FramebufferProps> = {\n ...Resource.defaultProps,\n width: 1,\n height: 1,\n colorAttachments: [], // ['rgba8unorm-unsized'],\n depthStencilAttachment: null // 'depth24plus-stencil8'\n }; \n\n override get [Symbol.toStringTag](): string {\n return 'Framebuffer';\n }\n\n /** Width of all attachments in this framebuffer */\n width: number;\n /** Height of all attachments in this framebuffer */\n height: number;\n /** Color attachments */\n colorAttachments: Texture[] = [];\n /** Depth-stencil attachment, if provided */\n depthStencilAttachment: Texture | null = null;\n\n constructor(device: Device, props: FramebufferProps = {}) {\n super(device, props, Framebuffer.defaultProps);\n this.width = this.props.width;\n this.height = this.props.height;\n\n // NOTE: call from subclass constructor as we cannot call overridden methods here (subclass not yet constructed)\n // this.autoCreateAttachmentTextures();\n }\n\n /**\n * Resizes all attachments\n * @note resize() destroys existing textures (if size has changed).\n */\n resize(size: {width: number; height: number;}): void;\n resize(size: [width: number, height: number]): void;\n resize(): void;\n resize(size?: {width: number; height: number} | [width: number, height: number]): void {\n let updateSize: boolean = !size;\n if (size) {\n const [width, height] = Array.isArray(size) ? size : [size.width, size.height];\n updateSize = updateSize || height !== this.height || width !== this.width;\n this.width = width;\n this.height = height;\n }\n if (updateSize) {\n log.log(2, `Resizing framebuffer ${this.id} to ${this.width}x${this.height}`)();\n this.resizeAttachments(this.width, this.height);\n }\n }\n\n // /** Returns fully populated attachment object. */\n // protected normalizeColorAttachment(\n // attachment: Texture | ColorTextureFormat\n // ): Required<ColorAttachment> {\n\n // const COLOR_ATTACHMENT_DEFAULTS: Required<ColorAttachment> = {\n // texture: undefined!,\n // format: undefined!,\n // clearValue: [0.0, 0.0, 0.0, 0.0],\n // loadOp: 'clear',\n // storeOp: 'store'\n // };\n\n // if (attachment instanceof Texture) {\n // return {...COLOR_ATTACHMENT_DEFAULTS, texture: attachment};\n // }\n // if (typeof attachment === 'string') {\n // return {...COLOR_ATTACHMENT_DEFAULTS, format: attachment};\n // }\n // return {...COLOR_ATTACHMENT_DEFAULTS, ...attachment};\n // }\n\n // /** Wraps texture inside fully populated attachment object. */\n // protected normalizeDepthStencilAttachment(\n // attachment: DepthStencilAttachment | Texture | DepthStencilTextureFormat\n // ): Required<DepthStencilAttachment> {\n // const DEPTH_STENCIL_ATTACHMENT_DEFAULTS: Required<DepthStencilAttachment> = {\n // texture: undefined!,\n // format: undefined!,\n\n // depthClearValue: 1.0,\n // depthLoadOp: 'clear',\n // depthStoreOp: 'store',\n // depthReadOnly: false,\n\n // stencilClearValue: 0,\n // stencilLoadOp: 'clear',\n // stencilStoreOp: 'store',\n // stencilReadOnly: false\n // };\n\n // if (typeof attachment === 'string') {\n // return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, format: attachment};\n // }\n // // @ts-expect-error attachment instanceof Texture doesn't cover Renderbuffer\n // if (attachment.handle || attachment instanceof Texture) {\n // return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, texture: attachment as Texture};\n // }\n // return {...DEPTH_STENCIL_ATTACHMENT_DEFAULTS, ...attachment};\n // }\n\n /** Auto creates any textures */\n protected autoCreateAttachmentTextures(){\n this.colorAttachments = this.props.colorAttachments.map(attachment => {\n if (typeof attachment === 'string') {\n const texture = this.createColorTexture(attachment);\n this.attachResource(texture);\n return texture;\n }\n return attachment;\n });\n\n if (this.props.depthStencilAttachment) {\n if (typeof this.props.depthStencilAttachment === 'string') {\n const texture = this.createDepthStencilTexture(this.props.depthStencilAttachment);\n this.attachResource(texture);\n this.depthStencilAttachment = texture;\n } else {\n this.depthStencilAttachment = this.props.depthStencilAttachment;\n }\n }\n }\n\n /** Create a color texture */\n protected createColorTexture(format: TextureFormat): Texture {\n return this.device.createTexture({\n id: 'color-attachment',\n usage: Texture.RENDER_ATTACHMENT,\n format,\n width: this.width,\n height: this.height,\n });\n }\n\n /** Create depth stencil texture */\n protected createDepthStencilTexture(format: TextureFormat): Texture {\n return this.device.createTexture({\n id: 'depth-stencil-attachment',\n usage: Texture.RENDER_ATTACHMENT,\n format,\n width: this.width,\n height: this.height\n });\n }\n\n /**\n * Default implementation of resize\n * Creates new textures with correct size for all attachments.\n * and destroys existing textures if owned\n */\n protected resizeAttachments(width: number, height: number): void {\n for (let i = 0; i < this.colorAttachments.length; ++i) {\n if (this.colorAttachments[i]) {\n const resizedTexture = this.device._createTexture({\n ...this.colorAttachments[i].props,\n width,\n height\n });\n this.destroyAttachedResource(this.colorAttachments[i]);\n this.colorAttachments[i] = resizedTexture;\n this.attachResource(resizedTexture);\n }\n }\n\n if (this.depthStencilAttachment) {\n const resizedTexture = this.device._createTexture({\n ...this.depthStencilAttachment.props,\n width,\n height\n });\n this.destroyAttachedResource(this.depthStencilAttachment);\n this.depthStencilAttachment = resizedTexture;\n this.attachResource(resizedTexture);\n }\n }\n\n /** Create a color attachment for WebGL *\n protected override createColorTexture(colorAttachment: Required<ColorAttachment>): Required<ColorAttachment> {\n return this.device._createTexture({\n id: `${this.id}-color`,\n data: null, // reserves texture memory, but texels are undefined\n format,\n // type: GL.UNSIGNED_BYTE,\n width: this.width,\n height: this.height,\n // Note: Mipmapping can be disabled by texture resource when we resize the texture\n // to a non-power-of-two dimenstion (NPOT texture) under WebGL1. To have consistant\n // behavior we always disable mipmaps.\n mipmaps: false,\n // Set MIN and MAG filtering parameters so mipmaps are not used in sampling.\n // Use LINEAR so subpixel algos like fxaa work.\n // Set WRAP modes that support NPOT textures too.\n sampler: {\n minFilter: 'linear',\n magFilter: 'linear',\n addressModeU: 'clamp-to-edge',\n addressModeV: 'clamp-to-edge'\n }\n // parameters: {\n // [GL.TEXTURE_MIN_FILTER]: GL.LINEAR,\n // [GL.TEXTUR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AjNsB/B,WAAW,CACfO,YAAY,GAA+B;EACzD,GAAGb,QAAQ,CAACa,YAAY;EACxBC,KAAK,EAAE,CAAC;EACRC,MAAM,EAAE,CAAC;EACTC,gBAAgB,EAAE,EAAE;EACpBC,sBAAsB,EAAE;AAC1B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"render-pass.js","names":["Resource","_Symbol$toStringTag","Symbol","toStringTag","RenderPass","constructor","device","props","defaultProps","framebuffer","parameters","undefined","clearColor","clearDepth","clearStencil","depthReadOnly","stencilReadOnly","discard"],"sources":["../../../src/adapter/resources/render-pass.ts"],"sourcesContent":["// luma.gl, MIT license\nimport type {Device} from '../device'\nimport type { RenderPassParameters } from '../types/parameters';\n// import {Binding} from '../types/shader-layout';\nimport {Resource, ResourceProps} from './resource';\n// import {Buffer} from './buffer';\n// import {RenderPipeline} from './render-pipeline';\n// import {CommandEncoder} from './command-encoder';\nimport {Framebuffer} from './framebuffer';\nimport {NumberArray} from '../..';\n\n/**\n * Properties for a RenderPass instance is a required parameter to all draw calls.\n */\nexport type RenderPassProps = ResourceProps & {\n /** Framebuffer specifies which textures to render into. Default gets framebuffer from canvas context. */\n framebuffer?: Framebuffer | null;\n /** Control viewport, scissor rect, blend constant and stencil ref */\n parameters?: RenderPassParameters;\n /** Clear value for color attachment, or `load` to preserve the previous value */\n clearColor?: NumberArray | false;\n /** Clear value for depth attachment, or `load` to preserve the previous value */\n clearDepth?: number | false;\n /** Clear value for stencil attachment, or `load` to preserve the previous value */\n clearStencil?: number | false;\n /** Indicates that the depth component is read only. */\n depthReadOnly?: boolean;\n /** Indicates that the stencil component is read only. */\n stencilReadOnly?: boolean;\n /** Whether to disable / discard the output of the rasterizer */\n discard?: boolean; \n};\n\n/**\n * A RenderPass instance is a required parameter to all draw calls.\n * \n * It holds a combination of \n * - render targets (specified via a framebuffer)\n * - clear colors, read/write, discard information for the framebuffer attachments\n * - a couple of mutable parameters ()\n */\nexport abstract class RenderPass extends Resource<RenderPassProps> {\n\n /** Default properties for RenderPass */\n static override defaultProps: Required<RenderPassProps> = {\n ...Resource.defaultProps,\n framebuffer: null,\n parameters: undefined,\n clearColor: [0, 0, 0, 0],\n clearDepth: 1,\n clearStencil: 0,\n depthReadOnly: false,\n stencilReadOnly: false,\n discard: false\n };\n\n override get [Symbol.toStringTag](): string {\n return 'RenderPass';\n }\n\n constructor(device: Device, props: RenderPassProps) {\n super(device, props, RenderPass.defaultProps);\n }\n\n /** Call when rendering is done in this pass. */\n abstract end(): void;\n\n /** \n * A small set of parameters can be changed between every draw call \n * (viewport, scissorRect, blendColor, stencilReference) \n */\n abstract setParameters(parameters: RenderPassParameters): void;\n\n abstract pushDebugGroup(groupLabel: string): void;\n abstract popDebugGroup(): void;\n abstract insertDebugMarker(markerLabel: string): void;\n\n // writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;\n\n // beginOcclusionQuery(queryIndex: number): void;\n // endOcclusionQuery(): void;\n\n // executeBundles(bundles: Iterable<GPURenderBundle>): void;\n\n // In WebGPU the following methods are on the renderpass.\n // luma.gl keeps them on the pipeline for now\n\n /*\n setPipeline(pipeline: RenderPipeline): void {}\n\n setIndexBuffer(\n buffer: Buffer,\n indexFormat: 'uint16' | 'uint32',\n offset?: number,\n size?: number\n ): void {}\n\n abstract setVertexBuffer(slot: number, buffer: Buffer, offset: number): void;\n\n abstract setBindings(bindings: Record<string, Binding>): void;\n\n abstract setParameters(parameters: RenderPassParameters);\n\n draw(options: {\n vertexCount?: number; // Either vertexCount or indexCount must be provided\n indexCount?: number; // Activates indexed drawing (call setIndexBuffer())\n instanceCount?: number; //\n firstVertex?: number;\n firstIndex?: number; // requires device.features.has('indirect-first-instance')?\n firstInstance?: number;\n baseVertex?: number;\n }): void {}\n\n drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void;\n drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void;\n */\n}\n"],"mappings":";SAIQA,QAAQ;AAAAC,mBAAA,GAoDAC,MAAM,CAACC,WAAW;AAflC,OAAO,MAAeC,UAAU,SAASJ,QAAQ,CAAkB;EAejE,KAAAC,mBAAA,IAA4C;IAC1C,OAAO,YAAY;EACrB;EAEAI,WAAWA,CAACC,MAAc,EAAEC,KAAsB,EAAE;IAClD,KAAK,CAACD,MAAM,EAAEC,KAAK,EAAEH,UAAU,CAACI,YAAY,CAAC;EAC/C;AAsDF;AA3EsBJ,UAAU,CAGdI,YAAY,GAA8B;EACxD,GAAGR,QAAQ,CAACQ,YAAY;EACxBC,WAAW,EAAE,IAAI;EACjBC,UAAU,EAAEC,SAAS;EACrBC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;EACxBC,UAAU,EAAE,CAAC;EACbC,YAAY,EAAE,CAAC;EACfC,aAAa,EAAE,KAAK;EACpBC,eAAe,EAAE,KAAK;EACtBC,OAAO,EAAE;AACX,CAAC"}
|