@luma.gl/webgl 9.0.0-alpha.21 → 9.0.0-alpha.24
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/converters/device-parameters.d.ts +1 -1
- package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/device-parameters.js +9 -9
- package/dist/adapter/converters/device-parameters.js.map +1 -1
- package/dist/adapter/converters/sampler-parameters.d.ts +1 -1
- package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/sampler-parameters.js +1 -1
- package/dist/adapter/converters/sampler-parameters.js.map +1 -1
- package/dist/adapter/converters/texture-formats.d.ts +29 -40
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +152 -114
- package/dist/adapter/converters/texture-formats.js.map +1 -1
- package/dist/adapter/device-helpers/device-limits.d.ts +1 -1
- package/dist/adapter/device-helpers/device-limits.d.ts.map +1 -1
- package/dist/adapter/helpers/attribute-utils.d.ts +1 -1
- package/dist/adapter/helpers/attribute-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/attribute-utils.js +1 -1
- package/dist/adapter/helpers/attribute-utils.js.map +1 -1
- package/dist/adapter/helpers/get-shader-info.d.ts +1 -1
- package/dist/adapter/helpers/get-shader-info.d.ts.map +1 -1
- package/dist/adapter/helpers/get-shader-info.js.map +1 -1
- package/dist/adapter/helpers/uniforms.d.ts +7 -8
- package/dist/adapter/helpers/uniforms.d.ts.map +1 -1
- package/dist/adapter/helpers/uniforms.js +4 -4
- package/dist/adapter/helpers/uniforms.js.map +1 -1
- package/dist/adapter/objects/constants-to-keys.d.ts +0 -2
- package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
- package/dist/adapter/objects/constants-to-keys.js +0 -20
- package/dist/adapter/objects/constants-to-keys.js.map +1 -1
- package/dist/adapter/objects/webgl-renderbuffer.d.ts +12 -9
- package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-renderbuffer.js +29 -19
- package/dist/adapter/objects/webgl-renderbuffer.js.map +1 -1
- package/dist/adapter/objects/webgl-resource.d.ts +0 -1
- package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-resource.js +4 -7
- package/dist/adapter/objects/webgl-resource.js.map +1 -1
- package/dist/adapter/objects/webgl-vertex-array-object.d.ts +1 -1
- package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +3 -2
- package/dist/adapter/resources/webgl-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.d.ts +13 -7
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +168 -25
- package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.d.ts +3 -2
- package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js +6 -2
- package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.d.ts +11 -14
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +29 -79
- package/dist/adapter/resources/webgl-framebuffer.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.d.ts +16 -1
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +80 -0
- package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +5 -5
- package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
- package/dist/adapter/resources/webgl-sampler.d.ts +1 -1
- package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-sampler.js +1 -1
- package/dist/adapter/resources/webgl-sampler.js.map +1 -1
- package/dist/adapter/resources/webgl-texture.d.ts +43 -23
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +32 -30
- package/dist/adapter/resources/webgl-texture.js.map +1 -1
- package/dist/adapter/webgl-canvas-context.d.ts +1 -2
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js.map +1 -1
- package/dist/adapter/webgl-device.d.ts +13 -6
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +20 -2
- package/dist/adapter/webgl-device.js.map +1 -1
- package/dist/classic/buffer.d.ts +1 -2
- package/dist/classic/buffer.d.ts.map +1 -1
- package/dist/classic/buffer.js +0 -6
- package/dist/classic/buffer.js.map +1 -1
- package/dist/classic/clear.d.ts +22 -0
- package/dist/classic/clear.d.ts.map +1 -0
- package/dist/classic/clear.js +88 -0
- package/dist/classic/clear.js.map +1 -0
- package/dist/classic/copy-and-blit.d.ts +45 -0
- package/dist/classic/copy-and-blit.d.ts.map +1 -0
- package/dist/classic/copy-and-blit.js +136 -0
- package/dist/classic/copy-and-blit.js.map +1 -0
- package/dist/classic/format-utils.d.ts +3 -0
- package/dist/classic/format-utils.d.ts.map +1 -0
- package/dist/classic/format-utils.js +38 -0
- package/dist/classic/format-utils.js.map +1 -0
- package/dist/classic/typed-array-utils.d.ts +15 -17
- package/dist/classic/typed-array-utils.d.ts.map +1 -1
- package/dist/classic/typed-array-utils.js +1 -1
- package/dist/classic/typed-array-utils.js.map +1 -1
- package/dist/context/context/create-browser-context.d.ts +17 -19
- package/dist/context/context/create-browser-context.d.ts.map +1 -1
- package/dist/context/context/create-browser-context.js +4 -4
- package/dist/context/context/create-browser-context.js.map +1 -1
- package/dist/context/context/create-headless-context.d.ts +1 -1
- package/dist/context/context/create-headless-context.d.ts.map +1 -1
- package/dist/context/debug/spector.d.ts +1 -3
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.d.ts +1 -1
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/parameters/unified-parameter-api.d.ts +1 -1
- package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
- package/dist/context/parameters/unified-parameter-api.js.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.d.ts +2 -3
- package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
- package/dist/dist.dev.js +1306 -659
- package/dist/index.cjs +1269 -897
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist.min.js +22 -21
- package/package.json +7 -4
- package/src/adapter/converters/device-parameters.ts +46 -22
- package/src/adapter/converters/sampler-parameters.ts +1 -2
- package/src/adapter/converters/texture-formats.ts +242 -161
- package/src/adapter/helpers/attribute-utils.ts +1 -2
- package/src/adapter/helpers/get-shader-info.ts +3 -0
- package/src/adapter/helpers/uniforms.ts +9 -10
- package/src/adapter/objects/constants-to-keys.ts +0 -25
- package/src/adapter/objects/webgl-renderbuffer.ts +32 -29
- package/src/adapter/objects/webgl-resource.ts +4 -8
- package/src/adapter/resources/webgl-buffer.ts +4 -5
- package/src/adapter/resources/webgl-command-buffer.ts +328 -21
- package/src/adapter/resources/webgl-command-encoder.ts +7 -2
- package/src/adapter/resources/webgl-framebuffer.ts +63 -111
- package/src/adapter/resources/webgl-render-pass.ts +146 -2
- package/src/adapter/resources/webgl-render-pipeline.ts +7 -4
- package/src/adapter/resources/webgl-sampler.ts +1 -2
- package/src/adapter/resources/webgl-texture.ts +61 -43
- package/src/adapter/webgl-canvas-context.ts +2 -2
- package/src/adapter/webgl-device.ts +37 -8
- package/src/classic/buffer.ts +3 -3
- package/src/classic/clear.ts +110 -0
- package/src/classic/copy-and-blit.ts +189 -0
- package/src/classic/format-utils.ts +43 -0
- package/src/classic/typed-array-utils.ts +15 -26
- package/src/context/context/create-browser-context.ts +37 -30
- package/src/context/parameters/unified-parameter-api.ts +1 -1
- package/src/context/parameters/webgl-parameter-tables.ts +2 -2
- package/src/index.ts +10 -3
- package/dist/adapter/converters/renderbuffer-formats.d.ts +0 -16
- package/dist/adapter/converters/renderbuffer-formats.d.ts.map +0 -1
- package/dist/adapter/converters/renderbuffer-formats.js +0 -180
- package/dist/adapter/converters/renderbuffer-formats.js.map +0 -1
- package/dist/types/webgl.d.ts +0 -145
- package/dist/types/webgl.d.ts.map +0 -1
- package/dist/types/webgl.js +0 -2
- package/dist/types/webgl.js.map +0 -1
- package/src/.DS_Store +0 -0
- package/src/adapter/.DS_Store +0 -0
- package/src/adapter/converters/renderbuffer-formats.ts +0 -90
- package/src/context/.DS_Store +0 -0
- package/src/types/webgl.ts +0 -286
|
@@ -1,29 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import {assert, ResourceProps} from '@luma.gl/api';
|
|
1
|
+
import {assert, ResourceProps, TextureFormat} from '@luma.gl/api';
|
|
3
2
|
import GL from '@luma.gl/constants';
|
|
4
3
|
import {WebGLDevice} from '../webgl-device';
|
|
5
4
|
import {WebGLResource} from './webgl-resource';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
} from '../converters/renderbuffer-formats';
|
|
5
|
+
import {isRenderbufferFormatSupported} from '../converters/texture-formats';
|
|
6
|
+
import {convertTextureFormatToGL, getTextureFormatBytesPerPixel} from '../converters/texture-formats';
|
|
9
7
|
|
|
10
8
|
export type RenderbufferProps = ResourceProps & {
|
|
11
|
-
format:
|
|
9
|
+
format: TextureFormat;
|
|
12
10
|
width?: number;
|
|
13
11
|
height?: number;
|
|
14
12
|
samples?: number;
|
|
15
13
|
};
|
|
16
14
|
|
|
17
|
-
const DEFAULT_RENDERBUFFER_PROPS: Required<RenderbufferProps> = {
|
|
18
|
-
id: undefined,
|
|
19
|
-
handle: undefined,
|
|
20
|
-
userData: undefined,
|
|
21
|
-
format: 0,
|
|
22
|
-
width: 1,
|
|
23
|
-
height: 1,
|
|
24
|
-
samples: 0
|
|
25
|
-
};
|
|
26
|
-
|
|
27
15
|
/**
|
|
28
16
|
* Renderbuffers are GPU objects that contain images.
|
|
29
17
|
* In contrast to Textures they are optimized for use as render targets, with Framebuffers.
|
|
@@ -35,35 +23,53 @@ const DEFAULT_RENDERBUFFER_PROPS: Required<RenderbufferProps> = {
|
|
|
35
23
|
* Renderbuffer objects also natively accommodate Multisampling (MSAA).
|
|
36
24
|
*/
|
|
37
25
|
export class WEBGLRenderbuffer extends WebGLResource<RenderbufferProps> {
|
|
26
|
+
static override readonly defaultProps: Required<RenderbufferProps> = {
|
|
27
|
+
id: undefined,
|
|
28
|
+
handle: undefined,
|
|
29
|
+
userData: undefined,
|
|
30
|
+
format: undefined, // 'depth16unorm'
|
|
31
|
+
width: 1,
|
|
32
|
+
height: 1,
|
|
33
|
+
samples: 0
|
|
34
|
+
};
|
|
35
|
+
|
|
38
36
|
override get [Symbol.toStringTag](): string { return 'Renderbuffer'; }
|
|
39
37
|
|
|
40
38
|
get width(): number { return this.props.width; }
|
|
41
39
|
get height(): number { return this.props.height; }
|
|
42
|
-
get format():
|
|
40
|
+
get format(): TextureFormat { return this.props.format; }
|
|
43
41
|
get samples(): number { return this.props.samples; }
|
|
42
|
+
get attachment() { return }
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
/** WebGL format constant */
|
|
45
|
+
glFormat: GL;
|
|
46
|
+
|
|
47
|
+
static isTextureFormatSupported(device: WebGLDevice, format: TextureFormat): boolean {
|
|
48
|
+
return isRenderbufferFormatSupported(device.gl, format);
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
constructor(device: WebGLDevice, props: RenderbufferProps) {
|
|
50
|
-
|
|
52
|
+
// TODO - remove temporary sanity check
|
|
53
|
+
if (typeof props.format === 'number') {
|
|
54
|
+
throw new Error('Renderbuffer');
|
|
55
|
+
}
|
|
56
|
+
super(device, props, WEBGLRenderbuffer.defaultProps);
|
|
57
|
+
this.glFormat = convertTextureFormatToGL(this.props.format, device.isWebGL2);
|
|
51
58
|
this._initialize(this.props);
|
|
52
59
|
}
|
|
53
60
|
|
|
54
|
-
resize(size: {width: number, height: number}):
|
|
61
|
+
resize(size: {width: number, height: number}): void {
|
|
55
62
|
// Don't resize if width/height haven't changed
|
|
56
63
|
if (size.width !== this.width || size.height !== this.height) {
|
|
57
64
|
Object.assign(this.props, {...size, format: this.format, samples: this.samples});
|
|
58
65
|
this._initialize(this.props);
|
|
59
66
|
}
|
|
60
|
-
return this;
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
// PRIVATE METHODS
|
|
64
70
|
|
|
65
71
|
/** Creates and initializes a renderbuffer object's data store */
|
|
66
|
-
protected _initialize(props: Required<RenderbufferProps>) {
|
|
72
|
+
protected _initialize(props: Required<RenderbufferProps>): void {
|
|
67
73
|
const {format, width, height, samples} = props;
|
|
68
74
|
assert(format, 'Needs format');
|
|
69
75
|
|
|
@@ -72,19 +78,16 @@ export class WEBGLRenderbuffer extends WebGLResource<RenderbufferProps> {
|
|
|
72
78
|
this.gl.bindRenderbuffer(GL.RENDERBUFFER, this.handle);
|
|
73
79
|
|
|
74
80
|
if (samples !== 0 && this.device.isWebGL2) {
|
|
75
|
-
|
|
76
|
-
this.gl.renderbufferStorageMultisample(GL.RENDERBUFFER, samples, format, width, height);
|
|
81
|
+
this.gl2.renderbufferStorageMultisample(GL.RENDERBUFFER, samples, this.glFormat, width, height);
|
|
77
82
|
} else {
|
|
78
|
-
this.gl.renderbufferStorage(GL.RENDERBUFFER,
|
|
83
|
+
this.gl.renderbufferStorage(GL.RENDERBUFFER, this.glFormat, width, height);
|
|
79
84
|
}
|
|
80
85
|
|
|
81
86
|
this.gl.bindRenderbuffer(GL.RENDERBUFFER, null);
|
|
82
87
|
|
|
83
88
|
this.trackAllocatedMemory(
|
|
84
|
-
width * height * (samples || 1) *
|
|
89
|
+
width * height * (samples || 1) * getTextureFormatBytesPerPixel(this.glFormat, this.device.isWebGL2)
|
|
85
90
|
);
|
|
86
|
-
|
|
87
|
-
return this;
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
// RESOURCE IMPLEMENTATION
|
|
@@ -6,7 +6,7 @@ import {isWebGL2, assertWebGLContext} from '../../context/context/webgl-checks';
|
|
|
6
6
|
import {WebGLDevice} from '../webgl-device';
|
|
7
7
|
|
|
8
8
|
// Requires full GL enum to be bundled... Make these bindings dependent on dynamic import (debug)?
|
|
9
|
-
import {
|
|
9
|
+
import {getKeyValue} from './constants-to-keys';
|
|
10
10
|
|
|
11
11
|
const ERR_RESOURCE_METHOD_UNDEFINED = 'Resource subclass must define virtual methods';
|
|
12
12
|
|
|
@@ -69,10 +69,6 @@ export abstract class WebGLResource<Props extends ResourceProps> extends Resourc
|
|
|
69
69
|
return this._handle;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
override destroy(): void {
|
|
73
|
-
this.delete();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
72
|
override delete({deleteChildren = false} = {}) {
|
|
77
73
|
// Delete this object, and get refs to any children
|
|
78
74
|
// @ts-expect-error
|
|
@@ -86,7 +82,7 @@ export abstract class WebGLResource<Props extends ResourceProps> extends Resourc
|
|
|
86
82
|
// @ts-expect-error
|
|
87
83
|
if (children && deleteChildren) {
|
|
88
84
|
// @ts-expect-error
|
|
89
|
-
children.filter(Boolean).forEach((child) => child.
|
|
85
|
+
children.filter(Boolean).forEach((child) => child.destroy());
|
|
90
86
|
}
|
|
91
87
|
|
|
92
88
|
return this;
|
|
@@ -183,10 +179,10 @@ export abstract class WebGLResource<Props extends ResourceProps> extends Resourc
|
|
|
183
179
|
(!('extension' in parameter) || this.gl.getExtension(parameter.extension));
|
|
184
180
|
|
|
185
181
|
if (parameterAvailable) {
|
|
186
|
-
const key = keys ?
|
|
182
|
+
const key = keys ? this.device.getGLKey(pname) : pname;
|
|
187
183
|
values[key] = this.getParameter(pname, options);
|
|
188
184
|
if (keys && parameter.type === 'GLenum') {
|
|
189
|
-
values[key] =
|
|
185
|
+
values[key] = this.device.getGLKey(values[key]);
|
|
190
186
|
}
|
|
191
187
|
}
|
|
192
188
|
}
|
|
@@ -107,13 +107,14 @@ export class WEBGLBuffer extends Buffer {
|
|
|
107
107
|
this.trackDeallocatedMemory();
|
|
108
108
|
this.gl.deleteBuffer(this.handle);
|
|
109
109
|
this.destroyed = true;
|
|
110
|
-
//
|
|
110
|
+
// @ts-expect-error
|
|
111
|
+
this.handle = null;
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
override write(data: ArrayBufferView, byteOffset: number = 0): void {
|
|
115
116
|
const srcOffset = 0;
|
|
116
|
-
const byteLength = data.byteLength;
|
|
117
|
+
const byteLength = undefined; // data.byteLength;
|
|
117
118
|
|
|
118
119
|
// Create the buffer - binding it here for the first time locks the type
|
|
119
120
|
// In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type
|
|
@@ -122,9 +123,7 @@ export class WEBGLBuffer extends Buffer {
|
|
|
122
123
|
// WebGL2: subData supports additional srcOffset and length parameters
|
|
123
124
|
if (srcOffset !== 0 || byteLength !== undefined) {
|
|
124
125
|
this.device.assertWebGL2();
|
|
125
|
-
|
|
126
|
-
// @ts-expect-error
|
|
127
|
-
this.gl.bufferSubData(this.target, byteOffset, data, srcOffset, byteLength);
|
|
126
|
+
this.gl2.bufferSubData(target, byteOffset, data, srcOffset, byteLength);
|
|
128
127
|
} else {
|
|
129
128
|
this.gl.bufferSubData(target, byteOffset, data);
|
|
130
129
|
}
|
|
@@ -1,12 +1,24 @@
|
|
|
1
|
+
// luma.gl, MIT license
|
|
2
|
+
|
|
1
3
|
import type {
|
|
2
4
|
CopyBufferToBufferOptions,
|
|
3
5
|
CopyBufferToTextureOptions,
|
|
4
6
|
CopyTextureToBufferOptions,
|
|
5
7
|
CopyTextureToTextureOptions
|
|
6
8
|
} from '@luma.gl/api';
|
|
9
|
+
import {
|
|
10
|
+
CommandBuffer,
|
|
11
|
+
Texture,
|
|
12
|
+
// Buffer,
|
|
13
|
+
Framebuffer
|
|
14
|
+
} from '@luma.gl/api';
|
|
7
15
|
import GL from '@luma.gl/constants';
|
|
16
|
+
|
|
17
|
+
// import {getTypedArrayFromGLType, getGLTypeFromTypedArray} from '../../classic/typed-array-utils';
|
|
8
18
|
import {WebGLDevice} from '../webgl-device';
|
|
9
19
|
import {WEBGLBuffer} from './webgl-buffer';
|
|
20
|
+
import {WEBGLTexture} from './webgl-texture';
|
|
21
|
+
import {WEBGLFramebuffer} from './webgl-framebuffer';
|
|
10
22
|
|
|
11
23
|
function cast<T>(value: unknown): T {
|
|
12
24
|
return value as T;
|
|
@@ -38,25 +50,31 @@ type Command =
|
|
|
38
50
|
| CopyTextureToBufferCommand
|
|
39
51
|
| CopyTextureToTextureCommand;
|
|
40
52
|
|
|
41
|
-
export class CommandBuffer {
|
|
53
|
+
export class WEBGLCommandBuffer extends CommandBuffer {
|
|
54
|
+
device: WebGLDevice;
|
|
42
55
|
commands: Command[] = [];
|
|
43
|
-
}
|
|
44
56
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
constructor(device: WebGLDevice) {
|
|
58
|
+
super({});
|
|
59
|
+
this.device = device;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
submitCommands(commands: Command[] = this.commands) {
|
|
63
|
+
for (const command of commands) {
|
|
64
|
+
switch (command.name) {
|
|
65
|
+
case 'copy-buffer-to-buffer':
|
|
66
|
+
_copyBufferToBuffer(this.device, command.options);
|
|
67
|
+
break;
|
|
68
|
+
case 'copy-buffer-to-texture':
|
|
69
|
+
_copyBufferToTexture(this.device, command.options);
|
|
70
|
+
break;
|
|
71
|
+
case 'copy-texture-to-buffer':
|
|
72
|
+
_copyTextureToBuffer(this.device, command.options);
|
|
73
|
+
break;
|
|
74
|
+
case 'copy-texture-to-texture':
|
|
75
|
+
_copyTextureToTexture(this.device, command.options);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
60
78
|
}
|
|
61
79
|
}
|
|
62
80
|
}
|
|
@@ -65,7 +83,7 @@ function _copyBufferToBuffer(device: WebGLDevice, options: CopyBufferToBufferOpt
|
|
|
65
83
|
const source = cast<WEBGLBuffer>(options.source);
|
|
66
84
|
const destination = cast<WEBGLBuffer>(options.destination);
|
|
67
85
|
|
|
68
|
-
const
|
|
86
|
+
const gl2 = device.assertWebGL2();
|
|
69
87
|
if (gl2) {
|
|
70
88
|
// In WebGL2 we can perform the copy on the GPU
|
|
71
89
|
// Use GL.COPY_READ_BUFFER+GL.COPY_WRITE_BUFFER avoid disturbing other targets and locking type
|
|
@@ -87,8 +105,297 @@ function _copyBufferToBuffer(device: WebGLDevice, options: CopyBufferToBufferOpt
|
|
|
87
105
|
}
|
|
88
106
|
}
|
|
89
107
|
|
|
90
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Copies data from a Buffer object into a Texture object
|
|
110
|
+
* NOTE: doesn't wait for copy to be complete
|
|
111
|
+
*/
|
|
112
|
+
function _copyBufferToTexture(device: WebGLDevice, options: CopyBufferToTextureOptions): void {
|
|
113
|
+
throw new Error('Not implemented');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Copies data from a Texture object into a Buffer object.
|
|
118
|
+
* NOTE: doesn't wait for copy to be complete
|
|
119
|
+
*/
|
|
120
|
+
function _copyTextureToBuffer(device: WebGLDevice, options: CopyTextureToBufferOptions): void {
|
|
121
|
+
const {
|
|
122
|
+
/** Texture to copy to/from. */
|
|
123
|
+
source,
|
|
124
|
+
/** Mip-map level of the texture to copy to/from. (Default 0) */
|
|
125
|
+
mipLevel = 0,
|
|
126
|
+
/** Defines which aspects of the texture to copy to/from. */
|
|
127
|
+
aspect = 'all',
|
|
128
|
+
|
|
129
|
+
/** Width to copy */
|
|
130
|
+
width = options.source.width,
|
|
131
|
+
/** Height to copy */
|
|
132
|
+
height = options.source.height,
|
|
133
|
+
depthOrArrayLayers = 0,
|
|
134
|
+
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
|
|
135
|
+
origin = [0, 0],
|
|
136
|
+
|
|
137
|
+
/** Destination buffer */
|
|
138
|
+
destination,
|
|
139
|
+
/** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */
|
|
140
|
+
byteOffset = 0,
|
|
141
|
+
/**
|
|
142
|
+
* The stride, in bytes, between the beginning of each block row and the subsequent block row.
|
|
143
|
+
* Required if there are multiple block rows (i.e. the copy height or depth is more than one block).
|
|
144
|
+
*/
|
|
145
|
+
bytesPerRow,
|
|
146
|
+
/**
|
|
147
|
+
* Number of block rows per single image of the texture.
|
|
148
|
+
* rowsPerImage × bytesPerRow is the stride, in bytes, between the beginning of each image of data and the subsequent image.
|
|
149
|
+
* Required if there are multiple images (i.e. the copy depth is more than one).
|
|
150
|
+
*/
|
|
151
|
+
rowsPerImage
|
|
152
|
+
} = options;
|
|
153
|
+
|
|
154
|
+
// TODO - Not possible to read just stencil or depth part in WebGL?
|
|
155
|
+
if (aspect !== 'all') {
|
|
156
|
+
throw new Error('not supported');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// TODO - mipLevels are set when attaching texture to framebuffer
|
|
160
|
+
if (mipLevel !== 0 || depthOrArrayLayers !== undefined || bytesPerRow || rowsPerImage) {
|
|
161
|
+
throw new Error('not implemented');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature
|
|
165
|
+
const gl2 = device.assertWebGL2();
|
|
166
|
+
|
|
167
|
+
const {framebuffer, destroyFramebuffer} = getFramebuffer(source);
|
|
168
|
+
try {
|
|
169
|
+
const webglBuffer = destination as WEBGLBuffer;
|
|
170
|
+
const sourceWidth = width || framebuffer.width;
|
|
171
|
+
const sourceHeight = height || framebuffer.height;
|
|
172
|
+
|
|
173
|
+
// TODO - hack - should be deduced
|
|
174
|
+
const sourceFormat = GL.RGBA;
|
|
175
|
+
const sourceType = GL.UNSIGNED_BYTE;
|
|
176
|
+
|
|
177
|
+
// if (!target) {
|
|
178
|
+
// // Create new buffer with enough size
|
|
179
|
+
// const components = glFormatToComponents(sourceFormat);
|
|
180
|
+
// const byteCount = glTypeToBytes(sourceType);
|
|
181
|
+
// const byteLength = byteOffset + sourceWidth * sourceHeight * components * byteCount;
|
|
182
|
+
// target = device.createBuffer({byteLength});
|
|
183
|
+
// }
|
|
184
|
+
|
|
185
|
+
gl2.bindBuffer(GL.PIXEL_PACK_BUFFER, webglBuffer.handle);
|
|
186
|
+
gl2.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);
|
|
187
|
+
|
|
188
|
+
gl2.readPixels(
|
|
189
|
+
origin[0],
|
|
190
|
+
origin[1],
|
|
191
|
+
sourceWidth,
|
|
192
|
+
sourceHeight,
|
|
193
|
+
sourceFormat,
|
|
194
|
+
sourceType,
|
|
195
|
+
byteOffset
|
|
196
|
+
);
|
|
197
|
+
} finally {
|
|
198
|
+
gl2.bindBuffer(GL.PIXEL_PACK_BUFFER, null);
|
|
199
|
+
gl2.bindFramebuffer(GL.FRAMEBUFFER, null);
|
|
200
|
+
|
|
201
|
+
if (destroyFramebuffer) {
|
|
202
|
+
framebuffer.destroy();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Copies data from a Framebuffer or a Texture object into a Buffer object.
|
|
209
|
+
* NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transfer.
|
|
210
|
+
export function readPixelsToBuffer(
|
|
211
|
+
source: Framebuffer | Texture,
|
|
212
|
+
options?: {
|
|
213
|
+
sourceX?: number;
|
|
214
|
+
sourceY?: number;
|
|
215
|
+
sourceFormat?: number;
|
|
216
|
+
target?: Buffer; // A new Buffer object is created when not provided.
|
|
217
|
+
targetByteOffset?: number; // byte offset in buffer object
|
|
218
|
+
// following parameters are auto deduced if not provided
|
|
219
|
+
sourceWidth?: number;
|
|
220
|
+
sourceHeight?: number;
|
|
221
|
+
sourceType?: number;
|
|
222
|
+
}
|
|
223
|
+
): Buffer
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Copy a rectangle from a Framebuffer or Texture object into a texture (at an offset)
|
|
228
|
+
*/
|
|
229
|
+
// eslint-disable-next-line complexity, max-statements
|
|
230
|
+
function _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextureOptions): void {
|
|
231
|
+
const {
|
|
232
|
+
/** Texture to copy to/from. */
|
|
233
|
+
source,
|
|
234
|
+
/** Mip-map level of the texture to copy to/from. (Default 0) */
|
|
235
|
+
// mipLevel = 0,
|
|
236
|
+
/** Defines which aspects of the texture to copy to/from. */
|
|
237
|
+
// aspect = 'all',
|
|
238
|
+
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
|
|
239
|
+
origin = [0, 0],
|
|
240
|
+
|
|
241
|
+
/** Texture to copy to/from. */
|
|
242
|
+
destination,
|
|
243
|
+
/** Mip-map level of the texture to copy to/from. (Default 0) */
|
|
244
|
+
// destinationMipLevel = options.mipLevel,
|
|
245
|
+
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
|
|
246
|
+
// destinationOrigin = [0, 0],
|
|
247
|
+
/** Defines which aspects of the texture to copy to/from. */
|
|
248
|
+
// destinationAspect = options.aspect,
|
|
249
|
+
|
|
250
|
+
} = options;
|
|
251
|
+
|
|
252
|
+
let {
|
|
253
|
+
width = options.destination.width,
|
|
254
|
+
height = options.destination.width,
|
|
255
|
+
// depthOrArrayLayers = 0
|
|
256
|
+
} = options;
|
|
257
|
+
|
|
258
|
+
const destinationMipmaplevel = 0;
|
|
259
|
+
const destinationInternalFormat = GL.RGBA;
|
|
260
|
+
|
|
261
|
+
const {framebuffer, destroyFramebuffer} = getFramebuffer(source);
|
|
262
|
+
const [sourceX, sourceY] = origin;
|
|
263
|
+
|
|
264
|
+
const isSubCopy = false;
|
|
265
|
+
// typeof destinationX !== 'undefined' ||
|
|
266
|
+
// typeof destinationY !== 'undefined' ||
|
|
267
|
+
// typeof destinationZ !== 'undefined';
|
|
268
|
+
|
|
269
|
+
// destinationX = destinationX || 0;
|
|
270
|
+
// destinationY = destinationY || 0;
|
|
271
|
+
// destinationZ = destinationZ || 0;
|
|
272
|
+
device.gl.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);
|
|
273
|
+
// TODO - support gl.readBuffer (WebGL2 only)
|
|
274
|
+
// const prevBuffer = gl.readBuffer(attachment);
|
|
275
|
+
|
|
276
|
+
let texture = null;
|
|
277
|
+
let textureTarget: GL;
|
|
278
|
+
if (destination instanceof WEBGLTexture) {
|
|
279
|
+
texture = destination;
|
|
280
|
+
width = Number.isFinite(width) ? width : texture.width;
|
|
281
|
+
height = Number.isFinite(height) ? height : texture.height;
|
|
282
|
+
texture.bind(0);
|
|
283
|
+
textureTarget = texture.destination;
|
|
284
|
+
} else {
|
|
285
|
+
throw new Error('whoops');
|
|
286
|
+
// textureTarget = destination;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (!isSubCopy) {
|
|
290
|
+
device.gl.copyTexImage2D(
|
|
291
|
+
textureTarget,
|
|
292
|
+
destinationMipmaplevel,
|
|
293
|
+
destinationInternalFormat,
|
|
294
|
+
sourceX,
|
|
295
|
+
sourceY,
|
|
296
|
+
width,
|
|
297
|
+
height,
|
|
298
|
+
0 /* border must be 0 */
|
|
299
|
+
);
|
|
300
|
+
} else {
|
|
301
|
+
// switch (textureTarget) {
|
|
302
|
+
// case GL.TEXTURE_2D:
|
|
303
|
+
// case GL.TEXTURE_CUBE_MAP:
|
|
304
|
+
// device.gl.copyTexSubImage2D(
|
|
305
|
+
// textureTarget,
|
|
306
|
+
// destinationMipmaplevel,
|
|
307
|
+
// destinationX,
|
|
308
|
+
// destinationY,
|
|
309
|
+
// sourceX,
|
|
310
|
+
// sourceY,
|
|
311
|
+
// width,
|
|
312
|
+
// height
|
|
313
|
+
// );
|
|
314
|
+
// break;
|
|
315
|
+
// case GL.TEXTURE_2D_ARRAY:
|
|
316
|
+
// case GL.TEXTURE_3D:
|
|
317
|
+
// const gl2 = device.assertWebGL2();
|
|
318
|
+
// gl2.copyTexSubImage3D(
|
|
319
|
+
// textureTarget,
|
|
320
|
+
// destinationMipmaplevel,
|
|
321
|
+
// destinationX,
|
|
322
|
+
// destinationY,
|
|
323
|
+
// destinationZ,
|
|
324
|
+
// sourceX,
|
|
325
|
+
// sourceY,
|
|
326
|
+
// width,
|
|
327
|
+
// height
|
|
328
|
+
// );
|
|
329
|
+
// break;
|
|
330
|
+
// default:
|
|
331
|
+
// }
|
|
332
|
+
}
|
|
333
|
+
if (texture) {
|
|
334
|
+
texture.unbind();
|
|
335
|
+
}
|
|
336
|
+
// @ts-expect-error
|
|
337
|
+
device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
|
|
338
|
+
if (destroyFramebuffer) {
|
|
339
|
+
framebuffer.destroy();
|
|
340
|
+
}
|
|
341
|
+
return texture;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Returns number of components in a specific readPixels WebGL format
|
|
345
|
+
export function glFormatToComponents(format): 1 | 2 | 3 | 4 {
|
|
346
|
+
switch (format) {
|
|
347
|
+
case GL.ALPHA:
|
|
348
|
+
case GL.R32F:
|
|
349
|
+
case GL.RED:
|
|
350
|
+
return 1;
|
|
351
|
+
case GL.RG32F:
|
|
352
|
+
case GL.RG:
|
|
353
|
+
return 2;
|
|
354
|
+
case GL.RGB:
|
|
355
|
+
case GL.RGB32F:
|
|
356
|
+
return 3;
|
|
357
|
+
case GL.RGBA:
|
|
358
|
+
case GL.RGBA32F:
|
|
359
|
+
return 4;
|
|
360
|
+
// TODO: Add support for additional WebGL2 formats
|
|
361
|
+
default:
|
|
362
|
+
throw new Error('GLFormat');
|
|
363
|
+
}
|
|
364
|
+
}
|
|
91
365
|
|
|
92
|
-
|
|
366
|
+
// Return byte count for given readPixels WebGL type
|
|
367
|
+
export function glTypeToBytes(type: GL): 1 | 2 | 4 {
|
|
368
|
+
switch (type) {
|
|
369
|
+
case GL.UNSIGNED_BYTE:
|
|
370
|
+
return 1;
|
|
371
|
+
case GL.UNSIGNED_SHORT_5_6_5:
|
|
372
|
+
case GL.UNSIGNED_SHORT_4_4_4_4:
|
|
373
|
+
case GL.UNSIGNED_SHORT_5_5_5_1:
|
|
374
|
+
return 2;
|
|
375
|
+
case GL.FLOAT:
|
|
376
|
+
return 4;
|
|
377
|
+
// TODO: Add support for additional WebGL2 types
|
|
378
|
+
default:
|
|
379
|
+
throw new Error('GLType');
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// Helper methods
|
|
93
384
|
|
|
94
|
-
function
|
|
385
|
+
function getFramebuffer(source: Texture | Framebuffer): {
|
|
386
|
+
framebuffer: WEBGLFramebuffer;
|
|
387
|
+
destroyFramebuffer: boolean;
|
|
388
|
+
} {
|
|
389
|
+
if (source instanceof Texture) {
|
|
390
|
+
const {width, height, id} = source;
|
|
391
|
+
const framebuffer = source.device.createFramebuffer({
|
|
392
|
+
id: `framebuffer-for-${id}`,
|
|
393
|
+
width,
|
|
394
|
+
height,
|
|
395
|
+
colorAttachments: [source]
|
|
396
|
+
}) as unknown as WEBGLFramebuffer;
|
|
397
|
+
|
|
398
|
+
return {framebuffer, destroyFramebuffer: true};
|
|
399
|
+
}
|
|
400
|
+
return {framebuffer: source as unknown as WEBGLFramebuffer, destroyFramebuffer: false};
|
|
401
|
+
}
|
|
@@ -6,21 +6,26 @@ import type {
|
|
|
6
6
|
CopyTextureToTextureOptions
|
|
7
7
|
} from '@luma.gl/api';
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import {WEBGLCommandBuffer} from './webgl-command-buffer';
|
|
10
10
|
import {WebGLDevice} from '../webgl-device';
|
|
11
11
|
|
|
12
12
|
export class WEBGLCommandEncoder extends CommandEncoder {
|
|
13
13
|
readonly device: WebGLDevice;
|
|
14
14
|
|
|
15
|
-
readonly commandBuffer
|
|
15
|
+
readonly commandBuffer: WEBGLCommandBuffer;
|
|
16
16
|
|
|
17
17
|
constructor(device: WebGLDevice, props: CommandEncoderProps) {
|
|
18
18
|
super(props);
|
|
19
19
|
this.device = device;
|
|
20
|
+
this.commandBuffer = new WEBGLCommandBuffer(device);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
override destroy(): void {}
|
|
23
24
|
|
|
25
|
+
override finish(): void {
|
|
26
|
+
this.commandBuffer.submitCommands();
|
|
27
|
+
}
|
|
28
|
+
|
|
24
29
|
// beginRenderPass(GPURenderPassDescriptor descriptor): GPURenderPassEncoder;
|
|
25
30
|
// beginComputePass(optional GPUComputePassDescriptor descriptor = {}): GPUComputePassEncoder;
|
|
26
31
|
// finish(options?: {id?: string}): GPUCommandBuffer;
|