@luma.gl/test-utils 9.0.0-beta.5 → 9.0.0-beta.7

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.
Files changed (106) hide show
  1. package/dist/create-test-device.d.ts +5 -5
  2. package/dist/create-test-device.d.ts.map +1 -1
  3. package/dist/create-test-device.js +30 -23
  4. package/dist/engine/classic-animation-loop.d.ts.map +1 -1
  5. package/dist/engine/classic-animation-loop.js +5 -2
  6. package/dist/index.cjs +554 -20
  7. package/dist/index.cjs.map +4 -4
  8. package/dist/index.d.ts +12 -11
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +10 -9
  11. package/dist/null-device/null-canvas-context.d.ts +24 -0
  12. package/dist/null-device/null-canvas-context.d.ts.map +1 -0
  13. package/dist/null-device/null-canvas-context.js +47 -0
  14. package/dist/null-device/null-device-features.d.ts +30 -0
  15. package/dist/null-device/null-device-features.d.ts.map +1 -0
  16. package/dist/null-device/null-device-features.js +32 -0
  17. package/dist/null-device/null-device-info.d.ts +3 -0
  18. package/dist/null-device/null-device-info.d.ts.map +1 -0
  19. package/dist/null-device/null-device-info.js +14 -0
  20. package/dist/null-device/null-device.d.ts +62 -0
  21. package/dist/null-device/null-device.d.ts.map +1 -0
  22. package/dist/null-device/null-device.js +134 -0
  23. package/dist/null-device/resources/null-buffer.d.ts +12 -0
  24. package/dist/null-device/resources/null-buffer.d.ts.map +1 -0
  25. package/dist/null-device/resources/null-buffer.js +30 -0
  26. package/dist/null-device/resources/null-command-buffer.d.ts +17 -0
  27. package/dist/null-device/resources/null-command-buffer.d.ts.map +1 -0
  28. package/dist/null-device/resources/null-command-buffer.js +20 -0
  29. package/dist/null-device/resources/null-framebuffer.d.ts +8 -0
  30. package/dist/null-device/resources/null-framebuffer.d.ts.map +1 -0
  31. package/dist/null-device/resources/null-framebuffer.js +11 -0
  32. package/dist/null-device/resources/null-query-set.d.ts +7 -0
  33. package/dist/null-device/resources/null-query-set.d.ts.map +1 -0
  34. package/dist/null-device/resources/null-query-set.js +11 -0
  35. package/dist/null-device/resources/null-render-pass.d.ts +14 -0
  36. package/dist/null-device/resources/null-render-pass.d.ts.map +1 -0
  37. package/dist/null-device/resources/null-render-pass.js +18 -0
  38. package/dist/null-device/resources/null-render-pipeline.d.ts +23 -0
  39. package/dist/null-device/resources/null-render-pipeline.d.ts.map +1 -0
  40. package/dist/null-device/resources/null-render-pipeline.js +38 -0
  41. package/dist/null-device/resources/null-sampler.d.ts +7 -0
  42. package/dist/null-device/resources/null-sampler.d.ts.map +1 -0
  43. package/dist/null-device/resources/null-sampler.js +11 -0
  44. package/dist/null-device/resources/null-shader.d.ts +8 -0
  45. package/dist/null-device/resources/null-shader.d.ts.map +1 -0
  46. package/dist/null-device/resources/null-shader.js +14 -0
  47. package/dist/null-device/resources/null-texture-view.d.ts +12 -0
  48. package/dist/null-device/resources/null-texture-view.d.ts.map +1 -0
  49. package/dist/null-device/resources/null-texture-view.js +13 -0
  50. package/dist/null-device/resources/null-texture.d.ts +33 -0
  51. package/dist/null-device/resources/null-texture.d.ts.map +1 -0
  52. package/dist/null-device/resources/null-texture.js +91 -0
  53. package/dist/null-device/resources/null-transform-feedback.d.ts +15 -0
  54. package/dist/null-device/resources/null-transform-feedback.d.ts.map +1 -0
  55. package/dist/null-device/resources/null-transform-feedback.js +32 -0
  56. package/dist/null-device/resources/null-vertex-array.d.ts +14 -0
  57. package/dist/null-device/resources/null-vertex-array.d.ts.map +1 -0
  58. package/dist/null-device/resources/null-vertex-array.js +26 -0
  59. package/dist/performance-test-runner.d.ts +1 -1
  60. package/dist/performance-test-runner.d.ts.map +1 -1
  61. package/dist/performance-test-runner.js +3 -2
  62. package/dist/register-devices.js +2 -1
  63. package/dist/snapshot-test-runner.d.ts +1 -1
  64. package/dist/snapshot-test-runner.d.ts.map +1 -1
  65. package/dist/snapshot-test-runner.js +5 -2
  66. package/dist/test-runner.d.ts +3 -3
  67. package/dist/test-runner.d.ts.map +1 -1
  68. package/dist/test-runner.js +8 -7
  69. package/dist/utils/check-type.d.ts.map +1 -1
  70. package/dist/utils/deep-copy.js +1 -1
  71. package/dist/utils/get-bounding-box.d.ts.map +1 -1
  72. package/dist/utils/resource-tracker.d.ts.map +1 -1
  73. package/package.json +6 -6
  74. package/src/create-test-device.ts +30 -24
  75. package/src/engine/classic-animation-loop.ts +15 -11
  76. package/src/index.ts +2 -1
  77. package/src/null-device/null-canvas-context.ts +58 -0
  78. package/src/null-device/null-device-features.ts +34 -0
  79. package/src/null-device/null-device-info.ts +17 -0
  80. package/src/null-device/null-device.ts +194 -0
  81. package/src/null-device/resources/null-buffer.ts +42 -0
  82. package/src/null-device/resources/null-command-buffer.ts +38 -0
  83. package/src/null-device/resources/null-framebuffer.ts +16 -0
  84. package/src/null-device/resources/null-query-set.ts +15 -0
  85. package/src/null-device/resources/null-render-pass.ts +26 -0
  86. package/src/null-device/resources/null-render-pipeline.ts +62 -0
  87. package/src/null-device/resources/null-sampler.ts +15 -0
  88. package/src/null-device/resources/null-shader.ts +19 -0
  89. package/src/null-device/resources/null-texture-view.ts +21 -0
  90. package/src/null-device/resources/null-texture.ts +121 -0
  91. package/src/null-device/resources/null-transform-feedback.ts +46 -0
  92. package/src/null-device/resources/null-vertex-array.ts +37 -0
  93. package/src/performance-test-runner.ts +2 -1
  94. package/src/register-devices.ts +2 -1
  95. package/src/snapshot-test-runner.ts +6 -2
  96. package/src/test-runner.ts +14 -8
  97. package/src/utils/check-type.ts +0 -1
  98. package/src/utils/deep-copy.ts +1 -1
  99. package/src/utils/get-bounding-box.ts +6 -1
  100. package/src/utils/resource-tracker.ts +4 -1
  101. package/dist/check-type.d.ts +0 -6
  102. package/dist/check-type.d.ts.map +0 -1
  103. package/dist/check-type.js +0 -5
  104. package/dist/utils.d.ts +0 -7
  105. package/dist/utils.d.ts.map +0 -1
  106. package/dist/utils.js +0 -10
@@ -0,0 +1,194 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {
6
+ DeviceProps,
7
+ CanvasContextProps,
8
+ TextureFormat,
9
+ VertexArray,
10
+ VertexArrayProps
11
+ } from '@luma.gl/core';
12
+ import {Device, CanvasContext, uid, DeviceFeatures} from '@luma.gl/core';
13
+
14
+ import type {
15
+ BufferProps,
16
+ ShaderProps,
17
+ SamplerProps,
18
+ TextureProps,
19
+ ExternalTexture,
20
+ ExternalTextureProps,
21
+ FramebufferProps,
22
+ RenderPipelineProps,
23
+ ComputePipeline,
24
+ ComputePipelineProps,
25
+ RenderPassProps,
26
+ ComputePass,
27
+ ComputePassProps,
28
+ CommandEncoderProps,
29
+ TransformFeedbackProps,
30
+ QuerySetProps
31
+ } from '@luma.gl/core';
32
+
33
+ import {NullDeviceInfo} from './null-device-info';
34
+ import {NullDeviceLimits} from './null-device-features';
35
+ import {NullCanvasContext} from './null-canvas-context';
36
+ import {NullBuffer} from './resources/null-buffer';
37
+ import {NullFramebuffer} from './resources/null-framebuffer';
38
+ import {NullShader} from './resources/null-shader';
39
+ import {NullCommandEncoder} from './resources/null-command-buffer';
40
+ import {NullSampler} from './resources/null-sampler';
41
+ import {NullTexture} from './resources/null-texture';
42
+ import {NullRenderPass} from './resources/null-render-pass';
43
+ import {NullRenderPipeline} from './resources/null-render-pipeline';
44
+ import {NullVertexArray} from './resources/null-vertex-array';
45
+ import {NullTransformFeedback} from './resources/null-transform-feedback';
46
+ import {NullQuerySet} from './resources/null-query-set';
47
+
48
+ /** Do-nothing device implementation for testing */
49
+ export class NullDevice extends Device {
50
+ static isSupported(): boolean {
51
+ return true;
52
+ }
53
+ static type: string = 'unknown';
54
+ readonly type = 'unknown';
55
+ features: DeviceFeatures = new DeviceFeatures([], this.props.disabledFeatures);
56
+ limits: NullDeviceLimits = new NullDeviceLimits();
57
+ readonly info = NullDeviceInfo;
58
+
59
+ readonly canvasContext: NullCanvasContext;
60
+ readonly lost: Promise<{reason: 'destroyed'; message: string}>;
61
+
62
+ static async create(props: DeviceProps = {}): Promise<NullDevice> {
63
+ // Wait for page to load: if canvas is a string we need to query the DOM for the canvas element.
64
+ // We only wait when props.canvas is string to avoids setting the global page onload callback unless necessary.
65
+ if (typeof props.canvas === 'string') {
66
+ await CanvasContext.pageLoaded;
67
+ }
68
+
69
+ return new NullDevice(props);
70
+ }
71
+
72
+ constructor(props: DeviceProps) {
73
+ super({...props, id: props.id || uid('dummy-device')});
74
+
75
+ this.canvasContext = new NullCanvasContext(this, props);
76
+ this.lost = new Promise(resolve => {});
77
+ this.canvasContext.resize();
78
+ }
79
+
80
+ /**
81
+ * Destroys the context
82
+ * @note Has no effect for WebGL browser contexts, there is no browser API for destroying contexts
83
+ */
84
+ destroy(): void {}
85
+
86
+ get isLost(): boolean {
87
+ return false;
88
+ }
89
+
90
+ getSize(): [number, number] {
91
+ return [this.canvasContext.width, this.canvasContext.height];
92
+ }
93
+
94
+ isTextureFormatSupported(format: TextureFormat): boolean {
95
+ return true;
96
+ }
97
+
98
+ isTextureFormatFilterable(format: TextureFormat): boolean {
99
+ return true;
100
+ }
101
+
102
+ isTextureFormatRenderable(format: TextureFormat): boolean {
103
+ return true;
104
+ }
105
+
106
+ // IMPLEMENTATION OF ABSTRACT DEVICE
107
+
108
+ createCanvasContext(props: CanvasContextProps): NullCanvasContext {
109
+ return new NullCanvasContext(this, props);
110
+ }
111
+
112
+ createBuffer(props: BufferProps | ArrayBuffer | ArrayBufferView): NullBuffer {
113
+ const newProps = this._getBufferProps(props);
114
+ return new NullBuffer(this, newProps);
115
+ }
116
+
117
+ getDefaultRenderPass(): NullRenderPass {
118
+ return new NullRenderPass(this, {});
119
+ }
120
+
121
+ _createTexture(props: TextureProps): NullTexture {
122
+ return new NullTexture(this, props);
123
+ }
124
+
125
+ createExternalTexture(props: ExternalTextureProps): ExternalTexture {
126
+ throw new Error('createExternalTexture() not implemented'); // return new Program(props);
127
+ }
128
+
129
+ createSampler(props: SamplerProps): NullSampler {
130
+ return new NullSampler(this, props);
131
+ }
132
+
133
+ createShader(props: ShaderProps): NullShader {
134
+ return new NullShader(this, props);
135
+ }
136
+
137
+ createFramebuffer(props: FramebufferProps): NullFramebuffer {
138
+ return new NullFramebuffer(this, props);
139
+ }
140
+
141
+ createVertexArray(props: VertexArrayProps): VertexArray {
142
+ return new NullVertexArray(this, props);
143
+ }
144
+
145
+ createTransformFeedback(props: TransformFeedbackProps): NullTransformFeedback {
146
+ return new NullTransformFeedback(this, props);
147
+ }
148
+
149
+ createQuerySet(props: QuerySetProps): NullQuerySet {
150
+ return new NullQuerySet(this, props);
151
+ }
152
+
153
+ createRenderPipeline(props: RenderPipelineProps): NullRenderPipeline {
154
+ return new NullRenderPipeline(this, props);
155
+ }
156
+
157
+ beginRenderPass(props: RenderPassProps): NullRenderPass {
158
+ return new NullRenderPass(this, props);
159
+ }
160
+
161
+ createComputePipeline(props?: ComputePipelineProps): ComputePipeline {
162
+ throw new Error('ComputePipeline not supported in WebGL');
163
+ }
164
+
165
+ beginComputePass(props: ComputePassProps): ComputePass {
166
+ throw new Error('ComputePass not supported in WebGL');
167
+ }
168
+
169
+ override createCommandEncoder(props: CommandEncoderProps = {}): NullCommandEncoder {
170
+ return new NullCommandEncoder(this, props);
171
+ }
172
+
173
+ submit(): void {}
174
+
175
+ override setParametersWebGL(parameters: any): void {}
176
+
177
+ override getParametersWebGL(parameters: any): any {}
178
+
179
+ override withParametersWebGL(parameters: any, func: any): any {
180
+ const {nocatch = true} = parameters;
181
+ let value: any;
182
+ if (nocatch) {
183
+ // Avoid try catch to minimize stack size impact for safe execution paths
184
+ return func();
185
+ }
186
+ // Wrap in a try-catch to ensure that parameters are restored on exceptions
187
+ try {
188
+ value = func();
189
+ } catch {
190
+ // ignore
191
+ }
192
+ return value;
193
+ }
194
+ }
@@ -0,0 +1,42 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {BufferProps} from '@luma.gl/core';
6
+ import {Buffer, assert} from '@luma.gl/core';
7
+ import type {NullDevice} from '../null-device';
8
+
9
+ export class NullBuffer extends Buffer {
10
+ device: NullDevice;
11
+
12
+ byteLength: number;
13
+
14
+ constructor(device: NullDevice, props: BufferProps = {}) {
15
+ super(device, props);
16
+ this.device = device;
17
+
18
+ const byteOffset = props.byteOffset || 0;
19
+ const byteLength = props.byteLength ?? (props.data ? props.data.byteLength + byteOffset : 0);
20
+
21
+ assert(byteLength >= 0);
22
+
23
+ this.byteLength = byteLength;
24
+ this.trackAllocatedMemory(byteLength);
25
+ }
26
+
27
+ override destroy(): void {
28
+ if (!this.destroyed) {
29
+ super.destroy();
30
+ this.trackDeallocatedMemory();
31
+ }
32
+ }
33
+
34
+ async readAsync(byteOffset = 0, byteLength?: number): Promise<Uint8Array> {
35
+ byteLength = byteLength ?? this.byteLength - byteOffset;
36
+ return new Uint8Array(byteLength);
37
+ }
38
+
39
+ write(data: ArrayBufferView, byteOffset: number = 0): void {
40
+ assert(data.byteLength + byteOffset <= this.byteLength);
41
+ }
42
+ }
@@ -0,0 +1,38 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {CommandEncoder, CommandEncoderProps} from '@luma.gl/core';
6
+ import type {
7
+ CopyBufferToBufferOptions,
8
+ CopyBufferToTextureOptions,
9
+ CopyTextureToBufferOptions,
10
+ CopyTextureToTextureOptions,
11
+ QuerySet
12
+ } from '@luma.gl/core';
13
+ import type {NullDevice} from '../null-device';
14
+
15
+ export class NullCommandEncoder extends CommandEncoder {
16
+ device: NullDevice;
17
+
18
+ constructor(device: NullDevice, props: CommandEncoderProps) {
19
+ super(device, props);
20
+ this.device = device;
21
+ }
22
+
23
+ finish(): void {}
24
+
25
+ copyBufferToBuffer(options: CopyBufferToBufferOptions): void {}
26
+
27
+ copyBufferToTexture(options: CopyBufferToTextureOptions) {}
28
+
29
+ copyTextureToBuffer(options: CopyTextureToBufferOptions): void {}
30
+
31
+ copyTextureToTexture(options: CopyTextureToTextureOptions): void {}
32
+
33
+ pushDebugGroup(groupLabel: string): void {}
34
+ popDebugGroup() {}
35
+
36
+ insertDebugMarker(markerLabel: string): void {}
37
+ resolveQuerySet(querySet: QuerySet): void {}
38
+ }
@@ -0,0 +1,16 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {FramebufferProps} from '@luma.gl/core';
6
+ import {Framebuffer} from '@luma.gl/core';
7
+ import type {NullDevice} from '../null-device';
8
+
9
+ export class NullFramebuffer extends Framebuffer {
10
+ device: NullDevice;
11
+
12
+ constructor(device: NullDevice, props: FramebufferProps) {
13
+ super(device, props);
14
+ this.device = device;
15
+ }
16
+ }
@@ -0,0 +1,15 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {QuerySet, QuerySetProps} from '@luma.gl/core';
6
+ import {NullDevice} from '../null-device';
7
+
8
+ export class NullQuerySet extends QuerySet {
9
+ device: NullDevice;
10
+
11
+ constructor(device: NullDevice, props: QuerySetProps) {
12
+ super(device, props);
13
+ this.device = device;
14
+ }
15
+ }
@@ -0,0 +1,26 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {RenderPass, RenderPassProps, RenderPassParameters} from '@luma.gl/core';
6
+ import {NullDevice} from '../null-device';
7
+
8
+ export class NullRenderPass extends RenderPass {
9
+ readonly device: NullDevice;
10
+
11
+ constructor(device: NullDevice, props: RenderPassProps) {
12
+ super(device, props);
13
+ this.device = device;
14
+ }
15
+
16
+ end(): void {}
17
+
18
+ pushDebugGroup(groupLabel: string): void {}
19
+ popDebugGroup(): void {}
20
+ insertDebugMarker(markerLabel: string): void {}
21
+
22
+ setParameters(parameters: RenderPassParameters = {}): void {}
23
+
24
+ beginOcclusionQuery(queryIndex: number): void {}
25
+ endOcclusionQuery(): void {}
26
+ }
@@ -0,0 +1,62 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {UniformValue, RenderPipelineProps, Binding} from '@luma.gl/core';
6
+ import type {RenderPass, VertexArray} from '@luma.gl/core';
7
+ import {RenderPipeline, cast} from '@luma.gl/core';
8
+
9
+ import type {NullDevice} from '../null-device';
10
+ import {NullShader} from './null-shader';
11
+
12
+ /** Creates a new render pipeline */
13
+ export class NullRenderPipeline extends RenderPipeline {
14
+ device: NullDevice;
15
+ vs: NullShader;
16
+ fs: NullShader;
17
+
18
+ uniforms: Record<string, UniformValue> = {};
19
+ bindings: Record<string, Binding> = {};
20
+
21
+ constructor(device: NullDevice, props: RenderPipelineProps) {
22
+ super(device, props);
23
+ this.device = device;
24
+
25
+ this.vs = cast<NullShader>(props.vs);
26
+ this.fs = cast<NullShader>(props.fs);
27
+
28
+ this.shaderLayout = props.shaderLayout || {
29
+ attributes: [],
30
+ bindings: [],
31
+ uniforms: []
32
+ };
33
+ }
34
+
35
+ setBindings(bindings: Record<string, Binding>): void {
36
+ Object.assign(this.bindings, bindings);
37
+ }
38
+
39
+ override setUniformsWebGL(uniforms: Record<string, UniformValue>): void {
40
+ Object.assign(this.uniforms, uniforms);
41
+ }
42
+
43
+ draw(options: {
44
+ renderPass: RenderPass;
45
+ vertexArray: VertexArray;
46
+ vertexCount?: number;
47
+ instanceCount?: number;
48
+ }): boolean {
49
+ const {renderPass, vertexArray} = options;
50
+
51
+ // const isIndexed: boolean = Boolean(vertexArray.indexBuffer);
52
+ // const isInstanced: boolean = Number(instanceCount) > 0;
53
+
54
+ vertexArray.bindBeforeRender(renderPass);
55
+
56
+ // TODO - verify buffer size
57
+
58
+ vertexArray.unbindAfterRender(renderPass);
59
+
60
+ return true;
61
+ }
62
+ }
@@ -0,0 +1,15 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {Sampler, SamplerProps} from '@luma.gl/core';
6
+ import type {NullDevice} from '../null-device';
7
+
8
+ export class NullSampler extends Sampler {
9
+ readonly device: NullDevice;
10
+
11
+ constructor(device: NullDevice, props: SamplerProps) {
12
+ super(device, props);
13
+ this.device = device;
14
+ }
15
+ }
@@ -0,0 +1,19 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {Shader, ShaderProps, CompilerMessage} from '@luma.gl/core';
6
+ import {NullDevice} from '../null-device';
7
+
8
+ export class NullShader extends Shader {
9
+ readonly device: NullDevice;
10
+
11
+ constructor(device: NullDevice, props: ShaderProps) {
12
+ super(device, props);
13
+ this.device = device;
14
+ }
15
+
16
+ async getCompilationInfo(): Promise<readonly CompilerMessage[]> {
17
+ return [];
18
+ }
19
+ }
@@ -0,0 +1,21 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {TextureViewProps} from '@luma.gl/core';
6
+ import {TextureView, Texture} from '@luma.gl/core';
7
+
8
+ import type {NullDevice} from '../null-device';
9
+ import type {NullTexture} from './null-texture';
10
+
11
+ export class NullTextureView extends TextureView {
12
+ readonly device: NullDevice;
13
+ readonly texture: NullTexture;
14
+
15
+ constructor(device: NullDevice, props: TextureViewProps & {texture: NullTexture}) {
16
+ super(device, {...Texture.defaultProps, ...props});
17
+
18
+ this.device = device;
19
+ this.texture = props.texture;
20
+ }
21
+ }
@@ -0,0 +1,121 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {TextureProps, Sampler, SamplerProps, TextureViewProps} from '@luma.gl/core';
6
+ import {Texture, assert, loadImage} from '@luma.gl/core';
7
+ import {NullDevice} from '../null-device';
8
+ import {NullSampler} from './null-sampler';
9
+ import {NullTextureView} from './null-texture-view';
10
+
11
+ export class NullTexture extends Texture<TextureProps> {
12
+ readonly device: NullDevice;
13
+
14
+ sampler!: NullSampler;
15
+ view!: NullTextureView;
16
+
17
+ constructor(device: NullDevice, props: TextureProps) {
18
+ super(device, props);
19
+
20
+ this.device = device;
21
+
22
+ // Signature: new Texture2D(gl, {data: url})
23
+ if (typeof this.props?.data === 'string') {
24
+ Object.assign(this.props, {data: loadImage(this.props.data)});
25
+ }
26
+
27
+ this.initialize(this.props);
28
+
29
+ Object.seal(this);
30
+ }
31
+
32
+ override destroy(): void {
33
+ if (!this.destroyed) {
34
+ super.destroy();
35
+ this.trackDeallocatedMemory('Texture');
36
+ }
37
+ }
38
+
39
+ createView(props: TextureViewProps): NullTextureView {
40
+ return new NullTextureView(this.device, {...props, texture: this});
41
+ }
42
+
43
+ initialize(props: TextureProps = {}): this {
44
+ const data = props.data;
45
+
46
+ if (data instanceof Promise) {
47
+ data.then(resolvedImageData =>
48
+ this.initialize(
49
+ Object.assign({}, props, {
50
+ pixels: resolvedImageData,
51
+ data: resolvedImageData
52
+ })
53
+ )
54
+ );
55
+ return this;
56
+ }
57
+
58
+ this.setImageData(props);
59
+
60
+ this.setSampler(props.sampler);
61
+
62
+ this.view = new NullTextureView(this.device, {
63
+ ...props,
64
+ texture: this,
65
+ mipLevelCount: 1,
66
+ arrayLayerCount: 1
67
+ });
68
+
69
+ return this;
70
+ }
71
+
72
+ setSampler(sampler: Sampler | SamplerProps = {}): this {
73
+ if (sampler instanceof NullSampler) {
74
+ this.sampler = sampler;
75
+ } else {
76
+ this.sampler = new NullSampler(this.device, sampler);
77
+ }
78
+
79
+ return this;
80
+ }
81
+
82
+ resize(options: {height: number; width: number; mipmaps?: boolean}): this {
83
+ const {height, width, mipmaps = false} = options;
84
+ if (width !== this.width || height !== this.height) {
85
+ return this.initialize({
86
+ width,
87
+ height,
88
+ mipmaps
89
+ });
90
+ }
91
+ return this;
92
+ }
93
+
94
+ setImageData(options: {data?: any; width?: number; height?: number}) {
95
+ this.trackDeallocatedMemory('Texture');
96
+
97
+ const {data} = options;
98
+
99
+ if (data && data.byteLength) {
100
+ this.trackAllocatedMemory(data.byteLength, 'Texture');
101
+ } else {
102
+ const bytesPerPixel = 4;
103
+ this.trackAllocatedMemory(this.width * this.height * bytesPerPixel, 'Texture');
104
+ }
105
+
106
+ const width = options.width ?? (data as ImageBitmap).width;
107
+ const height = options.height ?? (data as ImageBitmap).height;
108
+
109
+ this.width = width;
110
+ this.height = height;
111
+
112
+ return this;
113
+ }
114
+
115
+ setSubImageData(options: {data: any; width?: number; height?: number; x?: number; y?: number}) {
116
+ const {data, x = 0, y = 0} = options;
117
+ const width = options.width ?? (data as ImageBitmap).width;
118
+ const height = options.height ?? (data as ImageBitmap).height;
119
+ assert(width + x <= this.width && height + y <= this.height);
120
+ }
121
+ }
@@ -0,0 +1,46 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {PrimitiveTopology, ShaderLayout, TransformFeedbackProps} from '@luma.gl/core';
6
+ import {TransformFeedback, Buffer, BufferRange} from '@luma.gl/core';
7
+ import type {NullDevice} from '../null-device';
8
+
9
+ export class NullTransformFeedback extends TransformFeedback {
10
+ readonly device: NullDevice;
11
+
12
+ readonly layout: ShaderLayout;
13
+ buffers: Record<string, Buffer | BufferRange> = {};
14
+
15
+ constructor(device: NullDevice, props: TransformFeedbackProps) {
16
+ super(device, props);
17
+ this.device = device;
18
+ this.layout = this.props.layout;
19
+
20
+ if (props.buffers) {
21
+ this.setBuffers(props.buffers);
22
+ }
23
+
24
+ Object.seal(this);
25
+ }
26
+
27
+ begin(topology: PrimitiveTopology = 'point-list'): void {}
28
+
29
+ end(): void {}
30
+
31
+ setBuffers(buffers: Record<string, Buffer | BufferRange>): void {
32
+ this.buffers = {};
33
+
34
+ for (const bufferName in buffers) {
35
+ this.setBuffer(bufferName, buffers[bufferName]);
36
+ }
37
+ }
38
+
39
+ setBuffer(locationOrName: string | number, bufferOrRange: Buffer | BufferRange): void {
40
+ this.buffers[locationOrName] = bufferOrRange;
41
+ }
42
+
43
+ getBuffer(locationOrName: string | number): Buffer | BufferRange | null {
44
+ return this.buffers[locationOrName] || null;
45
+ }
46
+ }
@@ -0,0 +1,37 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {Buffer, VertexArrayProps, TypedArray} from '@luma.gl/core';
6
+ import {VertexArray} from '@luma.gl/core';
7
+
8
+ import type {NullDevice} from '../null-device';
9
+
10
+ export class NullVertexArray extends VertexArray {
11
+ device: NullDevice;
12
+
13
+ // Create a VertexArray
14
+ constructor(device: NullDevice, props: VertexArrayProps) {
15
+ super(device, props);
16
+ this.device = device;
17
+ }
18
+
19
+ setIndexBuffer(indexBuffer: Buffer | null): void {
20
+ this.indexBuffer = indexBuffer;
21
+ }
22
+
23
+ /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
24
+ setBuffer(location: number, attributeBuffer: Buffer): void {
25
+ const attributeInfo = this.attributeInfos[location];
26
+ if (!attributeInfo) {
27
+ throw new Error(`Unknown attribute location ${location}`);
28
+ }
29
+ this.attributes[location] = attributeBuffer;
30
+ }
31
+
32
+ bindBeforeRender(): void {}
33
+
34
+ unbindAfterRender(): void {}
35
+
36
+ override setConstantWebGL(location: number, value: TypedArray | null): void {}
37
+ }
@@ -1,4 +1,5 @@
1
- // luma.gl, MIT license
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
2
3
  // Copyright (c) vis.gl contributors
3
4
 
4
5
  import {Stats, Stat} from '@probe.gl/stats';
@@ -1,4 +1,5 @@
1
- // luma.gl, MIT license
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
2
3
  // Copyright (c) vis.gl contributors
3
4
 
4
5
  import {luma} from '@luma.gl/core';