@luma.gl/webgl 9.1.0-alpha.2 → 9.1.0-beta.1
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 +3 -3
- package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/device-parameters.js +19 -11
- package/dist/adapter/converters/device-parameters.js.map +1 -0
- package/dist/adapter/converters/sampler-parameters.js +7 -4
- package/dist/adapter/converters/sampler-parameters.js.map +1 -0
- package/dist/adapter/converters/shader-formats.js +1 -0
- package/dist/adapter/converters/shader-formats.js.map +1 -0
- package/dist/adapter/converters/vertex-formats.js +1 -0
- package/dist/adapter/converters/vertex-formats.js.map +1 -0
- package/dist/adapter/converters/webgl-texture-table.d.ts +40 -0
- package/dist/adapter/converters/webgl-texture-table.d.ts.map +1 -0
- package/dist/adapter/converters/webgl-texture-table.js +304 -0
- package/dist/adapter/converters/webgl-texture-table.js.map +1 -0
- package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
- package/dist/adapter/device-helpers/webgl-device-features.js +2 -3
- package/dist/adapter/device-helpers/webgl-device-features.js.map +1 -0
- package/dist/adapter/device-helpers/webgl-device-info.js +1 -0
- package/dist/adapter/device-helpers/webgl-device-info.js.map +1 -0
- package/dist/adapter/device-helpers/webgl-device-limits.js +1 -0
- package/dist/adapter/device-helpers/webgl-device-limits.js.map +1 -0
- package/dist/adapter/helpers/decode-webgl-types.js +1 -0
- package/dist/adapter/helpers/decode-webgl-types.js.map +1 -0
- package/dist/adapter/helpers/format-utils.d.ts.map +1 -0
- package/dist/{classic → adapter/helpers}/format-utils.js +7 -0
- package/dist/adapter/helpers/format-utils.js.map +1 -0
- package/dist/adapter/helpers/get-shader-layout.d.ts +1 -1
- package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-shader-layout.js +5 -4
- package/dist/adapter/helpers/get-shader-layout.js.map +1 -0
- package/dist/adapter/helpers/parse-shader-compiler-log.js +1 -0
- package/dist/adapter/helpers/parse-shader-compiler-log.js.map +1 -0
- package/dist/adapter/helpers/set-uniform.js +1 -0
- package/dist/adapter/helpers/set-uniform.js.map +1 -0
- package/dist/adapter/helpers/typed-array-utils.d.ts.map +1 -0
- package/dist/{classic → adapter/helpers}/typed-array-utils.js +1 -0
- package/dist/adapter/helpers/typed-array-utils.js.map +1 -0
- package/dist/adapter/helpers/webgl-texture-utils.d.ts +100 -29
- package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.js +231 -240
- package/dist/adapter/helpers/webgl-texture-utils.js.map +1 -0
- package/dist/adapter/helpers/webgl-topology-utils.js +1 -0
- package/dist/adapter/helpers/webgl-topology-utils.js.map +1 -0
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +4 -1
- package/dist/adapter/resources/webgl-buffer.js.map +1 -0
- package/dist/adapter/resources/webgl-command-buffer.d.ts +59 -2
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +89 -32
- package/dist/adapter/resources/webgl-command-buffer.js.map +1 -0
- package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js +4 -0
- package/dist/adapter/resources/webgl-command-encoder.js.map +1 -0
- package/dist/adapter/resources/webgl-external-texture.js +15 -0
- package/dist/adapter/resources/webgl-external-texture.js.map +1 -0
- package/dist/adapter/resources/webgl-framebuffer.d.ts +33 -35
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +71 -76
- package/dist/adapter/resources/webgl-framebuffer.js.map +1 -0
- package/dist/adapter/resources/webgl-query-set.js +1 -0
- package/dist/adapter/resources/webgl-query-set.js.map +1 -0
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +49 -21
- package/dist/adapter/resources/webgl-render-pass.js.map +1 -0
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +3 -4
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +45 -23
- package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -0
- package/dist/adapter/resources/webgl-sampler.js +1 -0
- package/dist/adapter/resources/webgl-sampler.js.map +1 -0
- package/dist/adapter/resources/webgl-shader.d.ts +1 -0
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +13 -6
- package/dist/adapter/resources/webgl-shader.js.map +1 -0
- package/dist/adapter/resources/webgl-texture-view.js +1 -0
- package/dist/adapter/resources/webgl-texture-view.js.map +1 -0
- package/dist/adapter/resources/webgl-texture.d.ts +33 -21
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +172 -242
- package/dist/adapter/resources/webgl-texture.js.map +1 -0
- package/dist/adapter/resources/webgl-transform-feedback.js +1 -0
- package/dist/adapter/resources/webgl-transform-feedback.js.map +1 -0
- package/dist/adapter/resources/webgl-vertex-array.js +1 -0
- package/dist/adapter/resources/webgl-vertex-array.js.map +1 -0
- package/dist/adapter/webgl-adapter.d.ts +21 -0
- package/dist/adapter/webgl-adapter.d.ts.map +1 -0
- package/dist/adapter/webgl-adapter.js +86 -0
- package/dist/adapter/webgl-adapter.js.map +1 -0
- package/dist/adapter/webgl-canvas-context.d.ts +4 -6
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +13 -17
- package/dist/adapter/webgl-canvas-context.js.map +1 -0
- package/dist/adapter/webgl-device.d.ts +35 -46
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +100 -156
- package/dist/adapter/webgl-device.js.map +1 -0
- package/dist/context/debug/spector-types.d.ts +1108 -0
- package/dist/context/debug/spector-types.d.ts.map +1 -0
- package/dist/context/debug/spector-types.js +698 -0
- package/dist/context/debug/spector-types.js.map +1 -0
- package/dist/context/debug/spector.d.ts +12 -8
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/spector.js +24 -17
- package/dist/context/debug/spector.js.map +1 -0
- package/dist/context/debug/webgl-developer-tools.d.ts +2 -3
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +7 -19
- package/dist/context/debug/webgl-developer-tools.js.map +1 -0
- package/dist/context/helpers/create-browser-context.d.ts +6 -22
- package/dist/context/helpers/create-browser-context.d.ts.map +1 -1
- package/dist/context/helpers/create-browser-context.js +41 -32
- package/dist/context/helpers/create-browser-context.js.map +1 -0
- package/dist/context/helpers/webgl-context-data.js +1 -0
- package/dist/context/helpers/webgl-context-data.js.map +1 -0
- package/dist/context/helpers/webgl-extensions.js +1 -0
- package/dist/context/helpers/webgl-extensions.js.map +1 -0
- package/dist/context/parameters/unified-parameter-api.js +1 -0
- package/dist/context/parameters/unified-parameter-api.js.map +1 -0
- package/dist/context/parameters/webgl-parameter-tables.d.ts +1 -1
- package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js +3 -2
- package/dist/context/parameters/webgl-parameter-tables.js.map +1 -0
- package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts +9 -0
- package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts.map +1 -0
- package/dist/context/polyfills/polyfill-webgl1-extensions.js +182 -0
- package/dist/context/polyfills/polyfill-webgl1-extensions.js.map +1 -0
- package/dist/context/state-tracker/deep-array-equal.js +1 -0
- package/dist/context/state-tracker/deep-array-equal.js.map +1 -0
- package/dist/context/state-tracker/webgl-state-tracker.d.ts +43 -0
- package/dist/context/state-tracker/webgl-state-tracker.d.ts.map +1 -0
- package/dist/context/state-tracker/{track-context-state.js → webgl-state-tracker.js} +45 -74
- package/dist/context/state-tracker/webgl-state-tracker.js.map +1 -0
- package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
- package/dist/context/state-tracker/with-parameters.js +6 -4
- package/dist/context/state-tracker/with-parameters.js.map +1 -0
- package/dist/deprecated/accessor.d.ts.map +1 -0
- package/dist/{classic → deprecated}/accessor.js +37 -1
- package/dist/deprecated/accessor.js.map +1 -0
- package/dist/dist.dev.js +2397 -2430
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +2273 -2298
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/fill-array.d.ts +4 -4
- package/dist/utils/fill-array.d.ts.map +1 -1
- package/dist/utils/fill-array.js +1 -0
- package/dist/utils/fill-array.js.map +1 -0
- package/dist/utils/load-script.js +1 -0
- package/dist/utils/load-script.js.map +1 -0
- package/dist/utils/split-uniforms-and-bindings.d.ts +1 -1
- package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -1
- package/dist/utils/split-uniforms-and-bindings.js +1 -0
- package/dist/utils/split-uniforms-and-bindings.js.map +1 -0
- package/dist/utils/uid.d.ts +7 -0
- package/dist/utils/uid.d.ts.map +1 -0
- package/dist/utils/uid.js +15 -0
- package/dist/utils/uid.js.map +1 -0
- package/package.json +5 -5
- package/src/adapter/converters/device-parameters.ts +21 -15
- package/src/adapter/converters/sampler-parameters.ts +6 -4
- package/src/adapter/converters/webgl-texture-table.ts +404 -0
- package/src/adapter/device-helpers/webgl-device-features.ts +5 -3
- package/src/{classic → adapter/helpers}/format-utils.ts +6 -0
- package/src/adapter/helpers/get-shader-layout.ts +7 -4
- package/src/adapter/helpers/webgl-texture-utils.ts +410 -64
- package/src/adapter/resources/webgl-buffer.ts +3 -1
- package/src/adapter/resources/webgl-command-buffer.ts +125 -41
- package/src/adapter/resources/webgl-command-encoder.ts +6 -0
- package/src/adapter/resources/webgl-external-texture.ts +14 -0
- package/src/adapter/resources/webgl-framebuffer.ts +80 -86
- package/src/adapter/resources/webgl-render-pass.ts +72 -45
- package/src/adapter/resources/webgl-render-pipeline.ts +58 -27
- package/src/adapter/resources/webgl-shader.ts +15 -7
- package/src/adapter/resources/webgl-texture.ts +202 -274
- package/src/adapter/webgl-adapter.ts +105 -0
- package/src/adapter/webgl-canvas-context.ts +16 -19
- package/src/adapter/webgl-device.ts +144 -210
- package/src/context/debug/spector-types.ts +1154 -0
- package/src/context/debug/spector.ts +38 -29
- package/src/context/debug/webgl-developer-tools.ts +8 -31
- package/src/context/helpers/create-browser-context.ts +53 -63
- package/src/context/parameters/webgl-parameter-tables.ts +2 -2
- package/src/context/polyfills/polyfill-webgl1-extensions.ts +202 -0
- package/src/context/state-tracker/{track-context-state.ts → webgl-state-tracker.ts} +55 -94
- package/src/context/state-tracker/with-parameters.ts +5 -4
- package/src/{classic → deprecated}/accessor.ts +44 -3
- package/src/index.ts +7 -12
- package/src/utils/fill-array.ts +4 -4
- package/src/utils/split-uniforms-and-bindings.ts +3 -3
- package/src/utils/uid.ts +16 -0
- package/dist/adapter/converters/texture-formats.d.ts +0 -83
- package/dist/adapter/converters/texture-formats.d.ts.map +0 -1
- package/dist/adapter/converters/texture-formats.js +0 -518
- package/dist/classic/accessor.d.ts.map +0 -1
- package/dist/classic/clear.d.ts +0 -22
- package/dist/classic/clear.d.ts.map +0 -1
- package/dist/classic/clear.js +0 -86
- package/dist/classic/copy-and-blit.d.ts +0 -63
- package/dist/classic/copy-and-blit.d.ts.map +0 -1
- package/dist/classic/copy-and-blit.js +0 -193
- package/dist/classic/format-utils.d.ts.map +0 -1
- package/dist/classic/typed-array-utils.d.ts.map +0 -1
- package/dist/context/state-tracker/track-context-state.d.ts +0 -22
- package/dist/context/state-tracker/track-context-state.d.ts.map +0 -1
- package/src/adapter/converters/texture-formats.ts +0 -665
- package/src/classic/clear.ts +0 -115
- package/src/classic/copy-and-blit.ts +0 -318
- /package/dist/{classic → adapter/helpers}/format-utils.d.ts +0 -0
- /package/dist/{classic → adapter/helpers}/typed-array-utils.d.ts +0 -0
- /package/dist/{classic → deprecated}/accessor.d.ts +0 -0
- /package/src/{classic → adapter/helpers}/typed-array-utils.ts +0 -0
|
@@ -7,15 +7,24 @@ import type {
|
|
|
7
7
|
CopyBufferToTextureOptions,
|
|
8
8
|
CopyTextureToBufferOptions,
|
|
9
9
|
CopyTextureToTextureOptions
|
|
10
|
+
// ClearTextureOptions,
|
|
11
|
+
// ReadTextureOptions
|
|
10
12
|
} from '@luma.gl/core';
|
|
11
13
|
import {CommandBuffer, Texture, Framebuffer} from '@luma.gl/core';
|
|
12
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
GL,
|
|
16
|
+
GLTextureTarget,
|
|
17
|
+
GLTextureCubeMapTarget
|
|
18
|
+
// GLTexelDataFormat,
|
|
19
|
+
// GLPixelType,
|
|
20
|
+
// GLDataType
|
|
21
|
+
} from '@luma.gl/constants';
|
|
13
22
|
|
|
14
23
|
import {WebGLDevice} from '../webgl-device';
|
|
15
24
|
import {WEBGLBuffer} from './webgl-buffer';
|
|
16
25
|
import {WEBGLTexture} from './webgl-texture';
|
|
17
26
|
import {WEBGLFramebuffer} from './webgl-framebuffer';
|
|
18
|
-
import {getTextureFormatWebGL} from '../converters/texture-
|
|
27
|
+
import {getTextureFormatWebGL} from '../converters/webgl-texture-table';
|
|
19
28
|
|
|
20
29
|
type CopyBufferToBufferCommand = {
|
|
21
30
|
name: 'copy-buffer-to-buffer';
|
|
@@ -37,11 +46,23 @@ type CopyTextureToTextureCommand = {
|
|
|
37
46
|
options: CopyTextureToTextureOptions;
|
|
38
47
|
};
|
|
39
48
|
|
|
49
|
+
type ClearTextureCommand = {
|
|
50
|
+
name: 'clear-texture';
|
|
51
|
+
options: {}; // ClearTextureOptions;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type ReadTextureCommand = {
|
|
55
|
+
name: 'read-texture';
|
|
56
|
+
options: {}; // ReadTextureOptions;
|
|
57
|
+
};
|
|
58
|
+
|
|
40
59
|
type Command =
|
|
41
60
|
| CopyBufferToBufferCommand
|
|
42
61
|
| CopyBufferToTextureCommand
|
|
43
62
|
| CopyTextureToBufferCommand
|
|
44
|
-
| CopyTextureToTextureCommand
|
|
63
|
+
| CopyTextureToTextureCommand
|
|
64
|
+
| ClearTextureCommand
|
|
65
|
+
| ReadTextureCommand;
|
|
45
66
|
|
|
46
67
|
export class WEBGLCommandBuffer extends CommandBuffer {
|
|
47
68
|
device: WebGLDevice;
|
|
@@ -67,14 +88,19 @@ export class WEBGLCommandBuffer extends CommandBuffer {
|
|
|
67
88
|
case 'copy-texture-to-texture':
|
|
68
89
|
_copyTextureToTexture(this.device, command.options);
|
|
69
90
|
break;
|
|
91
|
+
// case 'clear-texture':
|
|
92
|
+
// _clearTexture(this.device, command.options);
|
|
93
|
+
// break;
|
|
94
|
+
default:
|
|
95
|
+
throw new Error(command.name);
|
|
70
96
|
}
|
|
71
97
|
}
|
|
72
98
|
}
|
|
73
99
|
}
|
|
74
100
|
|
|
75
101
|
function _copyBufferToBuffer(device: WebGLDevice, options: CopyBufferToBufferOptions): void {
|
|
76
|
-
const source = options.
|
|
77
|
-
const destination = options.
|
|
102
|
+
const source = options.sourceBuffer as WEBGLBuffer;
|
|
103
|
+
const destination = options.destinationBuffer as WEBGLBuffer;
|
|
78
104
|
|
|
79
105
|
// {In WebGL2 we can p}erform the copy on the GPU
|
|
80
106
|
// Use GL.COPY_READ_BUFFER+GL.COPY_WRITE_BUFFER avoid disturbing other targets and locking type
|
|
@@ -106,22 +132,22 @@ function _copyBufferToTexture(device: WebGLDevice, options: CopyBufferToTextureO
|
|
|
106
132
|
function _copyTextureToBuffer(device: WebGLDevice, options: CopyTextureToBufferOptions): void {
|
|
107
133
|
const {
|
|
108
134
|
/** Texture to copy to/from. */
|
|
109
|
-
|
|
135
|
+
sourceTexture,
|
|
110
136
|
/** Mip-map level of the texture to copy to/from. (Default 0) */
|
|
111
137
|
mipLevel = 0,
|
|
112
138
|
/** Defines which aspects of the texture to copy to/from. */
|
|
113
139
|
aspect = 'all',
|
|
114
140
|
|
|
115
141
|
/** Width to copy */
|
|
116
|
-
width = options.
|
|
142
|
+
width = options.sourceTexture.width,
|
|
117
143
|
/** Height to copy */
|
|
118
|
-
height = options.
|
|
144
|
+
height = options.sourceTexture.height,
|
|
119
145
|
depthOrArrayLayers = 0,
|
|
120
146
|
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
|
|
121
147
|
origin = [0, 0],
|
|
122
148
|
|
|
123
149
|
/** Destination buffer */
|
|
124
|
-
|
|
150
|
+
destinationBuffer,
|
|
125
151
|
/** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */
|
|
126
152
|
byteOffset = 0,
|
|
127
153
|
/**
|
|
@@ -139,7 +165,7 @@ function _copyTextureToBuffer(device: WebGLDevice, options: CopyTextureToBufferO
|
|
|
139
165
|
|
|
140
166
|
// TODO - Not possible to read just stencil or depth part in WebGL?
|
|
141
167
|
if (aspect !== 'all') {
|
|
142
|
-
throw new Error('not supported');
|
|
168
|
+
throw new Error('aspect not supported in WebGL');
|
|
143
169
|
}
|
|
144
170
|
|
|
145
171
|
// TODO - mipLevels are set when attaching texture to framebuffer
|
|
@@ -148,10 +174,10 @@ function _copyTextureToBuffer(device: WebGLDevice, options: CopyTextureToBufferO
|
|
|
148
174
|
}
|
|
149
175
|
|
|
150
176
|
// Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature
|
|
151
|
-
const {framebuffer, destroyFramebuffer} = getFramebuffer(
|
|
177
|
+
const {framebuffer, destroyFramebuffer} = getFramebuffer(sourceTexture);
|
|
152
178
|
let prevHandle: WebGLFramebuffer | null | undefined;
|
|
153
179
|
try {
|
|
154
|
-
const webglBuffer =
|
|
180
|
+
const webglBuffer = destinationBuffer as WEBGLBuffer;
|
|
155
181
|
const sourceWidth = width || framebuffer.width;
|
|
156
182
|
const sourceHeight = height || framebuffer.height;
|
|
157
183
|
const sourceParams = getTextureFormatWebGL(
|
|
@@ -220,7 +246,7 @@ export function readPixelsToBuffer(
|
|
|
220
246
|
function _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextureOptions): void {
|
|
221
247
|
const {
|
|
222
248
|
/** Texture to copy to/from. */
|
|
223
|
-
|
|
249
|
+
sourceTexture,
|
|
224
250
|
/** Mip-map level of the texture to copy to (Default 0) */
|
|
225
251
|
destinationMipLevel = 0,
|
|
226
252
|
/** Defines which aspects of the texture to copy to/from. */
|
|
@@ -232,7 +258,7 @@ function _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextur
|
|
|
232
258
|
destinationOrigin = [0, 0],
|
|
233
259
|
|
|
234
260
|
/** Texture to copy to/from. */
|
|
235
|
-
|
|
261
|
+
destinationTexture
|
|
236
262
|
/** Mip-map level of the texture to copy to/from. (Default 0) */
|
|
237
263
|
// destinationMipLevel = options.mipLevel,
|
|
238
264
|
/** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
|
|
@@ -242,12 +268,12 @@ function _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextur
|
|
|
242
268
|
} = options;
|
|
243
269
|
|
|
244
270
|
let {
|
|
245
|
-
width = options.
|
|
246
|
-
height = options.
|
|
271
|
+
width = options.destinationTexture.width,
|
|
272
|
+
height = options.destinationTexture.height
|
|
247
273
|
// depthOrArrayLayers = 0
|
|
248
274
|
} = options;
|
|
249
275
|
|
|
250
|
-
const {framebuffer, destroyFramebuffer} = getFramebuffer(
|
|
276
|
+
const {framebuffer, destroyFramebuffer} = getFramebuffer(sourceTexture);
|
|
251
277
|
const [sourceX, sourceY] = origin;
|
|
252
278
|
const [destinationX, destinationY, destinationZ] = destinationOrigin;
|
|
253
279
|
|
|
@@ -261,8 +287,8 @@ function _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextur
|
|
|
261
287
|
|
|
262
288
|
let texture: WEBGLTexture = null;
|
|
263
289
|
let textureTarget: GL;
|
|
264
|
-
if (
|
|
265
|
-
texture =
|
|
290
|
+
if (destinationTexture instanceof WEBGLTexture) {
|
|
291
|
+
texture = destinationTexture;
|
|
266
292
|
width = Number.isFinite(width) ? width : texture.width;
|
|
267
293
|
height = Number.isFinite(height) ? height : texture.height;
|
|
268
294
|
texture.bind(0);
|
|
@@ -311,7 +337,82 @@ function _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextur
|
|
|
311
337
|
}
|
|
312
338
|
}
|
|
313
339
|
|
|
314
|
-
|
|
340
|
+
/** Clear one mip level of a texture *
|
|
341
|
+
function _clearTexture(device: WebGLDevice, options: ClearTextureOptions) {
|
|
342
|
+
const BORDER = 0;
|
|
343
|
+
const {dimension, width, height, depth = 0, mipLevel = 0} = options;
|
|
344
|
+
const {glInternalFormat, glFormat, glType, compressed} = options;
|
|
345
|
+
const glTarget = getWebGLCubeFaceTarget(options.glTarget, dimension, depth);
|
|
346
|
+
|
|
347
|
+
switch (dimension) {
|
|
348
|
+
case '2d-array':
|
|
349
|
+
case '3d':
|
|
350
|
+
if (compressed) {
|
|
351
|
+
// prettier-ignore
|
|
352
|
+
device.gl.compressedTexImage3D(glTarget, mipLevel, glInternalFormat, width, height, depth, BORDER, null);
|
|
353
|
+
} else {
|
|
354
|
+
// prettier-ignore
|
|
355
|
+
device.gl.texImage3D( glTarget, mipLevel, glInternalFormat, width, height, depth, BORDER, glFormat, glType, null);
|
|
356
|
+
}
|
|
357
|
+
break;
|
|
358
|
+
|
|
359
|
+
case '2d':
|
|
360
|
+
case 'cube':
|
|
361
|
+
if (compressed) {
|
|
362
|
+
// prettier-ignore
|
|
363
|
+
device.gl.compressedTexImage2D(glTarget, mipLevel, glInternalFormat, width, height, BORDER, null);
|
|
364
|
+
} else {
|
|
365
|
+
// prettier-ignore
|
|
366
|
+
device.gl.texImage2D(glTarget, mipLevel, glInternalFormat, width, height, BORDER, glFormat, glType, null);
|
|
367
|
+
}
|
|
368
|
+
break;
|
|
369
|
+
|
|
370
|
+
default:
|
|
371
|
+
throw new Error(dimension);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
*/
|
|
375
|
+
|
|
376
|
+
// function _readTexture(device: WebGLDevice, options: CopyTextureToBufferOptions) {}
|
|
377
|
+
|
|
378
|
+
// HELPERS
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* In WebGL, cube maps specify faces by overriding target instead of using the depth parameter.
|
|
382
|
+
* @note We still bind the texture using GL.TEXTURE_CUBE_MAP, but we need to use the face-specific target when setting mip levels.
|
|
383
|
+
* @returns glTarget unchanged, if dimension !== 'cube'.
|
|
384
|
+
*/
|
|
385
|
+
export function getWebGLCubeFaceTarget(
|
|
386
|
+
glTarget: GLTextureTarget,
|
|
387
|
+
dimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d',
|
|
388
|
+
level: number
|
|
389
|
+
): GLTextureTarget | GLTextureCubeMapTarget {
|
|
390
|
+
return dimension === 'cube' ? GL.TEXTURE_CUBE_MAP_POSITIVE_X + level : glTarget;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** Wrap a texture in a framebuffer so that we can use WebGL APIs that work on framebuffers */
|
|
394
|
+
function getFramebuffer(source: Texture | Framebuffer): {
|
|
395
|
+
framebuffer: WEBGLFramebuffer;
|
|
396
|
+
destroyFramebuffer: boolean;
|
|
397
|
+
} {
|
|
398
|
+
if (source instanceof Texture) {
|
|
399
|
+
const {width, height, id} = source;
|
|
400
|
+
const framebuffer = source.device.createFramebuffer({
|
|
401
|
+
id: `framebuffer-for-${id}`,
|
|
402
|
+
width,
|
|
403
|
+
height,
|
|
404
|
+
colorAttachments: [source]
|
|
405
|
+
}) as unknown as WEBGLFramebuffer;
|
|
406
|
+
|
|
407
|
+
return {framebuffer, destroyFramebuffer: true};
|
|
408
|
+
}
|
|
409
|
+
return {framebuffer: source as unknown as WEBGLFramebuffer, destroyFramebuffer: false};
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Returns number of components in a specific readPixels WebGL format
|
|
414
|
+
* @todo use shadertypes utils instead?
|
|
415
|
+
*/
|
|
315
416
|
export function glFormatToComponents(format): 1 | 2 | 3 | 4 {
|
|
316
417
|
switch (format) {
|
|
317
418
|
case GL.ALPHA:
|
|
@@ -333,7 +434,10 @@ export function glFormatToComponents(format): 1 | 2 | 3 | 4 {
|
|
|
333
434
|
}
|
|
334
435
|
}
|
|
335
436
|
|
|
336
|
-
|
|
437
|
+
/**
|
|
438
|
+
* Return byte count for given readPixels WebGL type
|
|
439
|
+
* @todo use shadertypes utils instead?
|
|
440
|
+
*/
|
|
337
441
|
export function glTypeToBytes(type: GL): 1 | 2 | 4 {
|
|
338
442
|
switch (type) {
|
|
339
443
|
case GL.UNSIGNED_BYTE:
|
|
@@ -349,23 +453,3 @@ export function glTypeToBytes(type: GL): 1 | 2 | 4 {
|
|
|
349
453
|
throw new Error('GLType');
|
|
350
454
|
}
|
|
351
455
|
}
|
|
352
|
-
|
|
353
|
-
// Helper methods
|
|
354
|
-
|
|
355
|
-
function getFramebuffer(source: Texture | Framebuffer): {
|
|
356
|
-
framebuffer: WEBGLFramebuffer;
|
|
357
|
-
destroyFramebuffer: boolean;
|
|
358
|
-
} {
|
|
359
|
-
if (source instanceof Texture) {
|
|
360
|
-
const {width, height, id} = source;
|
|
361
|
-
const framebuffer = source.device.createFramebuffer({
|
|
362
|
-
id: `framebuffer-for-${id}`,
|
|
363
|
-
width,
|
|
364
|
-
height,
|
|
365
|
-
colorAttachments: [source]
|
|
366
|
-
}) as unknown as WEBGLFramebuffer;
|
|
367
|
-
|
|
368
|
-
return {framebuffer, destroyFramebuffer: true};
|
|
369
|
-
}
|
|
370
|
-
return {framebuffer: source as unknown as WEBGLFramebuffer, destroyFramebuffer: false};
|
|
371
|
-
}
|
|
@@ -8,6 +8,8 @@ import type {
|
|
|
8
8
|
CopyBufferToTextureOptions,
|
|
9
9
|
CopyTextureToBufferOptions,
|
|
10
10
|
CopyTextureToTextureOptions,
|
|
11
|
+
// ClearTextureOptions,
|
|
12
|
+
// ReadTextureOptions,
|
|
11
13
|
QuerySet,
|
|
12
14
|
Buffer
|
|
13
15
|
} from '@luma.gl/core';
|
|
@@ -52,6 +54,10 @@ export class WEBGLCommandEncoder extends CommandEncoder {
|
|
|
52
54
|
this.commandBuffer.commands.push({name: 'copy-texture-to-texture', options});
|
|
53
55
|
}
|
|
54
56
|
|
|
57
|
+
// clearTexture(options: ClearTextureOptions): void {
|
|
58
|
+
// this.commandBuffer.commands.push({name: 'copy-texture-to-texture', options});
|
|
59
|
+
// }
|
|
60
|
+
|
|
55
61
|
override pushDebugGroup(groupLabel: string): void {}
|
|
56
62
|
override popDebugGroup() {}
|
|
57
63
|
|
|
@@ -72,6 +72,20 @@ export class WEBGLExternalTexture extends WEBGLTexture {
|
|
|
72
72
|
data.addEventListener('loadeddata', () => this.initialize(props));
|
|
73
73
|
return this;
|
|
74
74
|
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
initialize() {
|
|
78
|
+
// TODO - Video handling, move to ExternalTexture?
|
|
79
|
+
// if (isVideo) {
|
|
80
|
+
// this._video = {
|
|
81
|
+
// video: data,
|
|
82
|
+
// // TODO - should we be using the sampler parameters here?
|
|
83
|
+
// parameters: {},
|
|
84
|
+
// // @ts-expect-error HTMLVideoElement.HAVE_CURRENT_DATA is not declared
|
|
85
|
+
// lastTime: data.readyState >= HTMLVideoElement.HAVE_CURRENT_DATA ? data.currentTime : -1
|
|
86
|
+
// };
|
|
87
|
+
// }
|
|
88
|
+
}
|
|
75
89
|
|
|
76
90
|
update(): this {
|
|
77
91
|
if (this._video) {
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {FramebufferProps
|
|
6
|
-
import {Framebuffer
|
|
5
|
+
import type {FramebufferProps} from '@luma.gl/core';
|
|
6
|
+
import {Framebuffer} from '@luma.gl/core';
|
|
7
7
|
import {GL} from '@luma.gl/constants';
|
|
8
8
|
import {WebGLDevice} from '../webgl-device';
|
|
9
9
|
import {WEBGLTexture} from './webgl-texture';
|
|
10
10
|
import {WEBGLTextureView} from './webgl-texture-view';
|
|
11
|
-
import {getDepthStencilAttachmentWebGL} from '../converters/texture-
|
|
11
|
+
import {getDepthStencilAttachmentWebGL} from '../converters/webgl-texture-table';
|
|
12
12
|
|
|
13
13
|
export type Attachment = WEBGLTextureView | WEBGLTexture; // | WEBGLRenderbuffer;
|
|
14
14
|
|
|
@@ -33,45 +33,13 @@ export class WEBGLFramebuffer extends Framebuffer {
|
|
|
33
33
|
this.props.handle || isDefaultFramebuffer ? this.props.handle : this.gl.createFramebuffer();
|
|
34
34
|
|
|
35
35
|
if (!isDefaultFramebuffer) {
|
|
36
|
-
// default framebuffer handle is null, so we can't set
|
|
37
|
-
device.
|
|
36
|
+
// default framebuffer handle is null, so we can't set debug metadata...
|
|
37
|
+
device._setWebGLDebugMetadata(this.handle, this, {spector: this.props});
|
|
38
38
|
|
|
39
39
|
// Auto create textures for attachments if needed
|
|
40
40
|
this.autoCreateAttachmentTextures();
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
// @ts-expect-error native bindFramebuffer is overridden by our state tracker
|
|
44
|
-
const prevHandle: WebGLFramebuffer | null = this.gl.bindFramebuffer(
|
|
45
|
-
GL.FRAMEBUFFER,
|
|
46
|
-
this.handle
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
// Walk the attachments
|
|
50
|
-
for (let i = 0; i < this.colorAttachments.length; ++i) {
|
|
51
|
-
const attachment = this.colorAttachments[i];
|
|
52
|
-
const attachmentPoint = GL.COLOR_ATTACHMENT0 + i;
|
|
53
|
-
if (attachment) {
|
|
54
|
-
this._attachTexture(attachmentPoint, attachment);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (this.depthStencilAttachment) {
|
|
59
|
-
this._attachTexture(
|
|
60
|
-
getDepthStencilAttachmentWebGL(this.depthStencilAttachment.props.format),
|
|
61
|
-
this.depthStencilAttachment
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Check the status */
|
|
66
|
-
// @ts-expect-error
|
|
67
|
-
if (props.check !== false) {
|
|
68
|
-
const status = this.gl.checkFramebufferStatus(GL.FRAMEBUFFER) as GL;
|
|
69
|
-
if (status !== GL.FRAMEBUFFER_COMPLETE) {
|
|
70
|
-
throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
this.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle);
|
|
42
|
+
this.updateAttachments();
|
|
75
43
|
}
|
|
76
44
|
}
|
|
77
45
|
|
|
@@ -84,60 +52,55 @@ export class WEBGLFramebuffer extends Framebuffer {
|
|
|
84
52
|
}
|
|
85
53
|
}
|
|
86
54
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
* Attachment resize is expected to be a noop if size is same
|
|
103
|
-
*
|
|
104
|
-
protected override resizeAttachments(width: number, height: number): this {
|
|
105
|
-
// for default framebuffer, just update the stored size
|
|
106
|
-
if (this.handle === null) {
|
|
107
|
-
// assert(width === undefined && height === undefined);
|
|
108
|
-
this.width = this.gl.drawingBufferWidth;
|
|
109
|
-
this.height = this.gl.drawingBufferHeight;
|
|
110
|
-
return this;
|
|
55
|
+
protected updateAttachments(): void {
|
|
56
|
+
/** Attach from a map of attachments */
|
|
57
|
+
// @ts-expect-error native bindFramebuffer is overridden by our state tracker
|
|
58
|
+
const prevHandle: WebGLFramebuffer | null = this.gl.bindFramebuffer(
|
|
59
|
+
GL.FRAMEBUFFER,
|
|
60
|
+
this.handle
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// Walk the attachments
|
|
64
|
+
for (let i = 0; i < this.colorAttachments.length; ++i) {
|
|
65
|
+
const attachment = this.colorAttachments[i];
|
|
66
|
+
if (attachment) {
|
|
67
|
+
const attachmentPoint = GL.COLOR_ATTACHMENT0 + i;
|
|
68
|
+
this._attachTextureView(attachmentPoint, attachment);
|
|
69
|
+
}
|
|
111
70
|
}
|
|
112
71
|
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
72
|
+
if (this.depthStencilAttachment) {
|
|
73
|
+
const attachmentPoint = getDepthStencilAttachmentWebGL(
|
|
74
|
+
this.depthStencilAttachment.props.format
|
|
75
|
+
);
|
|
76
|
+
this._attachTextureView(attachmentPoint, this.depthStencilAttachment);
|
|
118
77
|
}
|
|
119
78
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this.depthStencilAttachment.texture.resize({width, height});
|
|
79
|
+
/** Check the status */
|
|
80
|
+
if (this.device.props.debug) {
|
|
81
|
+
const status = this.gl.checkFramebufferStatus(GL.FRAMEBUFFER) as GL;
|
|
82
|
+
if (status !== GL.FRAMEBUFFER_COMPLETE) {
|
|
83
|
+
throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
|
|
84
|
+
}
|
|
127
85
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
*/
|
|
131
|
-
|
|
132
|
-
/** Attach one attachment */
|
|
133
|
-
protected _attachTexture(attachmentPoint: GL, textureView: WEBGLTextureView): void {
|
|
134
|
-
// if (attachment instanceof WEBGLRenderbuffer) {
|
|
135
|
-
// this._attachWEBGLRenderbuffer(attachmentPoint, attachment);
|
|
136
|
-
// return attachment;
|
|
137
|
-
// }
|
|
138
|
-
this._attachTextureView(attachmentPoint, textureView);
|
|
86
|
+
|
|
87
|
+
this.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle);
|
|
139
88
|
}
|
|
140
89
|
|
|
90
|
+
// PRIVATE
|
|
91
|
+
|
|
92
|
+
/** In WebGL we must use renderbuffers for depth/stencil attachments (unless we have extensions) */
|
|
93
|
+
// protected override createDepthStencilTexture(format: TextureFormat): Texture {
|
|
94
|
+
// // return new WEBGLRenderbuffer(this.device, {
|
|
95
|
+
// return new WEBGLTexture(this.device, {
|
|
96
|
+
// id: `${this.id}-depth-stencil`,
|
|
97
|
+
// format,
|
|
98
|
+
// width: this.width,
|
|
99
|
+
// height: this.height,
|
|
100
|
+
// mipmaps: false
|
|
101
|
+
// });
|
|
102
|
+
// }
|
|
103
|
+
|
|
141
104
|
/**
|
|
142
105
|
* @param attachment
|
|
143
106
|
* @param texture
|
|
@@ -155,7 +118,7 @@ export class WEBGLFramebuffer extends Framebuffer {
|
|
|
155
118
|
switch (texture.glTarget) {
|
|
156
119
|
case GL.TEXTURE_2D_ARRAY:
|
|
157
120
|
case GL.TEXTURE_3D:
|
|
158
|
-
gl.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.
|
|
121
|
+
gl.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.handle, level, layer);
|
|
159
122
|
break;
|
|
160
123
|
|
|
161
124
|
case GL.TEXTURE_CUBE_MAP:
|
|
@@ -210,3 +173,34 @@ function _getFrameBufferStatus(status: GL) {
|
|
|
210
173
|
return `${status}`;
|
|
211
174
|
}
|
|
212
175
|
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Attachment resize is expected to be a noop if size is same
|
|
179
|
+
*
|
|
180
|
+
protected override resizeAttachments(width: number, height: number): this {
|
|
181
|
+
// for default framebuffer, just update the stored size
|
|
182
|
+
if (this.handle === null) {
|
|
183
|
+
// assert(width === undefined && height === undefined);
|
|
184
|
+
this.width = this.gl.drawingBufferWidth;
|
|
185
|
+
this.height = this.gl.drawingBufferHeight;
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (width === undefined) {
|
|
190
|
+
width = this.gl.drawingBufferWidth;
|
|
191
|
+
}
|
|
192
|
+
if (height === undefined) {
|
|
193
|
+
height = this.gl.drawingBufferHeight;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// TODO Not clear that this is better than default destroy/create implementation
|
|
197
|
+
|
|
198
|
+
for (const colorAttachment of this.colorAttachments) {
|
|
199
|
+
colorAttachment.texture.clone({width, height});
|
|
200
|
+
}
|
|
201
|
+
if (this.depthStencilAttachment) {
|
|
202
|
+
this.depthStencilAttachment.texture.resize({width, height});
|
|
203
|
+
}
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
*/
|