@luma.gl/webgl 9.0.0-beta.1 → 9.0.0-beta.10
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.map +1 -1
- package/dist/adapter/converters/device-parameters.js +295 -156
- package/dist/adapter/converters/sampler-parameters.d.ts +0 -4
- package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/sampler-parameters.js +73 -67
- package/dist/adapter/converters/shader-formats.d.ts.map +1 -1
- package/dist/adapter/converters/shader-formats.js +53 -46
- package/dist/adapter/converters/texture-formats.d.ts +17 -21
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +481 -879
- package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
- package/dist/adapter/converters/vertex-formats.js +53 -61
- package/dist/adapter/device-helpers/webgl-device-features.d.ts +20 -0
- package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -0
- package/dist/adapter/device-helpers/webgl-device-features.js +98 -0
- package/dist/adapter/device-helpers/webgl-device-info.d.ts +5 -0
- package/dist/adapter/device-helpers/webgl-device-info.d.ts.map +1 -0
- package/dist/adapter/device-helpers/webgl-device-info.js +90 -0
- package/dist/adapter/device-helpers/webgl-device-limits.d.ts +35 -0
- package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -0
- package/dist/adapter/device-helpers/webgl-device-limits.js +47 -0
- package/dist/adapter/helpers/decode-webgl-types.d.ts.map +1 -1
- package/dist/adapter/helpers/decode-webgl-types.js +88 -76
- 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 +261 -225
- package/dist/adapter/helpers/parse-shader-compiler-log.d.ts.map +1 -1
- package/dist/adapter/helpers/parse-shader-compiler-log.js +47 -37
- package/dist/adapter/helpers/set-uniform.d.ts +1 -1
- package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
- package/dist/adapter/helpers/set-uniform.js +68 -82
- package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.js +78 -93
- package/dist/adapter/objects/constants-to-keys.d.ts +1 -1
- package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
- package/dist/adapter/objects/constants-to-keys.js +19 -12
- package/dist/adapter/objects/webgl-renderbuffer.d.ts +2 -2
- package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-renderbuffer.js +86 -77
- package/dist/adapter/objects/webgl-resource.d.ts +3 -25
- package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-resource.js +102 -147
- package/dist/adapter/resources/webgl-buffer.d.ts +3 -4
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +159 -117
- package/dist/adapter/resources/webgl-command-buffer.d.ts +1 -1
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +266 -168
- package/dist/adapter/resources/webgl-command-encoder.d.ts +8 -3
- package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js +33 -39
- package/dist/adapter/resources/webgl-external-texture.js +93 -1
- package/dist/adapter/resources/webgl-framebuffer.d.ts +8 -12
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +174 -139
- package/dist/adapter/resources/webgl-query-set.d.ts +44 -0
- package/dist/adapter/resources/webgl-query-set.d.ts.map +1 -0
- package/dist/adapter/resources/webgl-query-set.js +136 -0
- package/dist/adapter/resources/webgl-render-pass.d.ts +3 -1
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +124 -90
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +15 -6
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +362 -221
- package/dist/adapter/resources/webgl-sampler.d.ts +1 -3
- package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-sampler.js +43 -33
- package/dist/adapter/resources/webgl-shader.d.ts +12 -2
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +114 -47
- package/dist/adapter/resources/webgl-texture-view.d.ts +14 -0
- package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -0
- package/dist/adapter/resources/webgl-texture-view.js +18 -0
- package/dist/adapter/resources/webgl-texture.d.ts +8 -10
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +616 -694
- package/dist/adapter/resources/webgl-transform-feedback.d.ts +2 -2
- package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-transform-feedback.js +141 -143
- package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -3
- package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-vertex-array.js +229 -157
- package/dist/adapter/webgl-canvas-context.d.ts +2 -2
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +58 -36
- package/dist/adapter/webgl-device.d.ts +50 -44
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +427 -352
- package/dist/classic/accessor.d.ts.map +1 -1
- package/dist/classic/accessor.js +132 -101
- package/dist/classic/clear.d.ts +2 -2
- package/dist/classic/clear.d.ts.map +1 -1
- package/dist/classic/clear.js +73 -72
- package/dist/classic/copy-and-blit.d.ts +1 -1
- package/dist/classic/copy-and-blit.d.ts.map +1 -1
- package/dist/classic/copy-and-blit.js +174 -175
- package/dist/classic/format-utils.d.ts +2 -2
- package/dist/classic/format-utils.d.ts.map +1 -1
- package/dist/classic/format-utils.js +39 -32
- package/dist/classic/typed-array-utils.d.ts.map +1 -1
- package/dist/classic/typed-array-utils.js +96 -81
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/spector.js +55 -50
- package/dist/context/debug/webgl-developer-tools.d.ts +1 -2
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +104 -77
- package/dist/context/{context → helpers}/create-browser-context.d.ts +1 -6
- package/dist/context/helpers/create-browser-context.d.ts.map +1 -0
- package/dist/context/helpers/create-browser-context.js +67 -0
- package/dist/context/{polyfill/context-data.d.ts → helpers/webgl-context-data.d.ts} +2 -2
- package/dist/context/helpers/webgl-context-data.d.ts.map +1 -0
- package/dist/context/helpers/webgl-context-data.js +21 -0
- package/dist/context/helpers/webgl-extensions.d.ts +4 -0
- package/dist/context/helpers/webgl-extensions.d.ts.map +1 -0
- package/dist/context/helpers/webgl-extensions.js +10 -0
- package/dist/context/parameters/unified-parameter-api.d.ts +3 -4
- package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
- package/dist/context/parameters/unified-parameter-api.js +92 -47
- package/dist/context/parameters/webgl-parameter-tables.d.ts +109 -99
- package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js +463 -404
- package/dist/context/state-tracker/deep-array-equal.d.ts.map +1 -1
- package/dist/context/state-tracker/deep-array-equal.js +19 -14
- package/dist/context/state-tracker/track-context-state.d.ts +4 -4
- package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
- package/dist/context/state-tracker/track-context-state.js +188 -123
- package/dist/context/state-tracker/with-parameters.d.ts +2 -3
- package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
- package/dist/context/state-tracker/with-parameters.js +42 -28
- package/dist/dist.dev.js +4465 -7235
- package/dist/dist.min.js +10 -0
- package/dist/index.cjs +2146 -3116
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +25 -31
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -1
- package/dist.min.js +9 -42
- package/package.json +10 -15
- package/src/adapter/converters/device-parameters.ts +114 -28
- package/src/adapter/converters/sampler-parameters.ts +12 -20
- package/src/adapter/converters/shader-formats.ts +47 -22
- package/src/adapter/converters/texture-formats.ts +183 -227
- package/src/adapter/converters/vertex-formats.ts +3 -3
- package/src/adapter/device-helpers/webgl-device-features.ts +121 -0
- package/src/adapter/device-helpers/{get-device-info.ts → webgl-device-info.ts} +30 -22
- package/src/adapter/device-helpers/webgl-device-limits.ts +53 -0
- package/src/adapter/helpers/decode-webgl-types.ts +13 -7
- package/src/adapter/helpers/get-shader-layout.ts +21 -31
- package/src/adapter/helpers/parse-shader-compiler-log.ts +10 -6
- package/src/adapter/helpers/set-uniform.ts +3 -4
- package/src/adapter/helpers/webgl-topology-utils.ts +10 -3
- package/src/adapter/objects/constants-to-keys.ts +3 -2
- package/src/adapter/objects/webgl-renderbuffer.ts +38 -16
- package/src/adapter/objects/webgl-resource.ts +8 -141
- package/src/adapter/resources/webgl-buffer.ts +10 -14
- package/src/adapter/resources/webgl-command-buffer.ts +24 -34
- package/src/adapter/resources/webgl-command-encoder.ts +14 -11
- package/src/adapter/resources/webgl-external-texture.ts +7 -7
- package/src/adapter/resources/webgl-framebuffer.ts +65 -58
- package/src/adapter/resources/webgl-query-set.ts +171 -0
- package/src/adapter/resources/webgl-render-pass.ts +27 -18
- package/src/adapter/resources/webgl-render-pipeline.ts +148 -73
- package/src/adapter/resources/webgl-sampler.ts +7 -10
- package/src/adapter/resources/webgl-shader.ts +65 -11
- package/src/adapter/resources/webgl-texture-view.ts +28 -0
- package/src/adapter/resources/webgl-texture.ts +43 -106
- package/src/adapter/resources/webgl-transform-feedback.ts +16 -22
- package/src/adapter/resources/webgl-vertex-array.ts +20 -21
- package/src/adapter/webgl-canvas-context.ts +7 -11
- package/src/adapter/webgl-device.ts +142 -162
- package/src/classic/accessor.ts +5 -4
- package/src/classic/clear.ts +25 -20
- package/src/classic/copy-and-blit.ts +12 -6
- package/src/classic/format-utils.ts +2 -1
- package/src/classic/typed-array-utils.ts +3 -7
- package/src/context/debug/spector.ts +9 -6
- package/src/context/debug/webgl-developer-tools.ts +31 -20
- package/src/context/{context → helpers}/create-browser-context.ts +9 -33
- package/src/context/{polyfill/context-data.ts → helpers/webgl-context-data.ts} +3 -2
- package/src/context/helpers/webgl-extensions.ts +17 -0
- package/src/context/parameters/unified-parameter-api.ts +6 -17
- package/src/context/parameters/webgl-parameter-tables.ts +118 -90
- package/src/context/state-tracker/deep-array-equal.ts +2 -1
- package/src/context/state-tracker/track-context-state.ts +29 -23
- package/src/context/state-tracker/with-parameters.ts +8 -8
- package/src/index.ts +16 -56
- package/src/types.ts +2 -1
- package/dist/adapter/converters/device-parameters.js.map +0 -1
- package/dist/adapter/converters/sampler-parameters.js.map +0 -1
- package/dist/adapter/converters/shader-formats.js.map +0 -1
- package/dist/adapter/converters/texture-formats.js.map +0 -1
- package/dist/adapter/converters/vertex-formats.js.map +0 -1
- package/dist/adapter/device-helpers/device-features.d.ts +0 -9
- package/dist/adapter/device-helpers/device-features.d.ts.map +0 -1
- package/dist/adapter/device-helpers/device-features.js +0 -96
- package/dist/adapter/device-helpers/device-features.js.map +0 -1
- package/dist/adapter/device-helpers/device-limits.d.ts +0 -52
- package/dist/adapter/device-helpers/device-limits.d.ts.map +0 -1
- package/dist/adapter/device-helpers/device-limits.js +0 -87
- package/dist/adapter/device-helpers/device-limits.js.map +0 -1
- package/dist/adapter/device-helpers/get-device-info.d.ts +0 -4
- package/dist/adapter/device-helpers/get-device-info.d.ts.map +0 -1
- package/dist/adapter/device-helpers/get-device-info.js +0 -71
- package/dist/adapter/device-helpers/get-device-info.js.map +0 -1
- package/dist/adapter/device-helpers/is-old-ie.d.ts +0 -2
- package/dist/adapter/device-helpers/is-old-ie.d.ts.map +0 -1
- package/dist/adapter/device-helpers/is-old-ie.js +0 -9
- package/dist/adapter/device-helpers/is-old-ie.js.map +0 -1
- package/dist/adapter/helpers/decode-webgl-types.js.map +0 -1
- package/dist/adapter/helpers/get-shader-layout.js.map +0 -1
- package/dist/adapter/helpers/parse-shader-compiler-log.js.map +0 -1
- package/dist/adapter/helpers/set-uniform.js.map +0 -1
- package/dist/adapter/helpers/webgl-topology-utils.js.map +0 -1
- package/dist/adapter/objects/constants-to-keys.js.map +0 -1
- package/dist/adapter/objects/webgl-renderbuffer.js.map +0 -1
- package/dist/adapter/objects/webgl-resource.js.map +0 -1
- package/dist/adapter/resources/webgl-buffer.js.map +0 -1
- package/dist/adapter/resources/webgl-command-buffer.js.map +0 -1
- package/dist/adapter/resources/webgl-command-encoder.js.map +0 -1
- package/dist/adapter/resources/webgl-external-texture.js.map +0 -1
- package/dist/adapter/resources/webgl-framebuffer.js.map +0 -1
- package/dist/adapter/resources/webgl-render-pass.js.map +0 -1
- package/dist/adapter/resources/webgl-render-pipeline.js.map +0 -1
- package/dist/adapter/resources/webgl-sampler.js.map +0 -1
- package/dist/adapter/resources/webgl-shader.js.map +0 -1
- package/dist/adapter/resources/webgl-texture.js.map +0 -1
- package/dist/adapter/resources/webgl-transform-feedback.js.map +0 -1
- package/dist/adapter/resources/webgl-vertex-array.js.map +0 -1
- package/dist/adapter/webgl-canvas-context.js.map +0 -1
- package/dist/adapter/webgl-device.js.map +0 -1
- package/dist/classic/accessor.js.map +0 -1
- package/dist/classic/clear.js.map +0 -1
- package/dist/classic/copy-and-blit.js.map +0 -1
- package/dist/classic/format-utils.js.map +0 -1
- package/dist/classic/typed-array-utils.js.map +0 -1
- package/dist/context/context/create-browser-context.d.ts.map +0 -1
- package/dist/context/context/create-browser-context.js +0 -53
- package/dist/context/context/create-browser-context.js.map +0 -1
- package/dist/context/context/create-headless-context.d.ts +0 -9
- package/dist/context/context/create-headless-context.d.ts.map +0 -1
- package/dist/context/context/create-headless-context.js +0 -42
- package/dist/context/context/create-headless-context.js.map +0 -1
- package/dist/context/context/webgl-checks.d.ts +0 -13
- package/dist/context/context/webgl-checks.d.ts.map +0 -1
- package/dist/context/context/webgl-checks.js +0 -31
- package/dist/context/context/webgl-checks.js.map +0 -1
- package/dist/context/debug/spector.js.map +0 -1
- package/dist/context/debug/webgl-developer-tools.js.map +0 -1
- package/dist/context/parameters/unified-parameter-api.js.map +0 -1
- package/dist/context/parameters/webgl-parameter-tables.js.map +0 -1
- package/dist/context/polyfill/context-data.d.ts.map +0 -1
- package/dist/context/polyfill/context-data.js +0 -12
- package/dist/context/polyfill/context-data.js.map +0 -1
- package/dist/context/polyfill/get-parameter-polyfill.d.ts +0 -2
- package/dist/context/polyfill/get-parameter-polyfill.d.ts.map +0 -1
- package/dist/context/polyfill/get-parameter-polyfill.js +0 -85
- package/dist/context/polyfill/get-parameter-polyfill.js.map +0 -1
- package/dist/context/polyfill/polyfill-context.d.ts +0 -5
- package/dist/context/polyfill/polyfill-context.d.ts.map +0 -1
- package/dist/context/polyfill/polyfill-context.js +0 -87
- package/dist/context/polyfill/polyfill-context.js.map +0 -1
- package/dist/context/polyfill/polyfill-table.d.ts +0 -48
- package/dist/context/polyfill/polyfill-table.d.ts.map +0 -1
- package/dist/context/polyfill/polyfill-table.js +0 -137
- package/dist/context/polyfill/polyfill-table.js.map +0 -1
- package/dist/context/polyfill/polyfill-vertex-array-object.d.ts +0 -2
- package/dist/context/polyfill/polyfill-vertex-array-object.d.ts.map +0 -1
- package/dist/context/polyfill/polyfill-vertex-array-object.js +0 -265
- package/dist/context/polyfill/polyfill-vertex-array-object.js.map +0 -1
- package/dist/context/state-tracker/deep-array-equal.js.map +0 -1
- package/dist/context/state-tracker/track-context-state.js.map +0 -1
- package/dist/context/state-tracker/with-parameters.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/src/adapter/device-helpers/device-features.ts +0 -161
- package/src/adapter/device-helpers/device-limits.ts +0 -155
- package/src/adapter/device-helpers/is-old-ie.ts +0 -14
- package/src/context/context/create-headless-context.ts +0 -51
- package/src/context/context/webgl-checks.ts +0 -51
- package/src/context/polyfill/get-parameter-polyfill.ts +0 -122
- package/src/context/polyfill/polyfill-context.ts +0 -104
- package/src/context/polyfill/polyfill-table.ts +0 -167
- package/src/context/polyfill/polyfill-vertex-array-object.ts +0 -365
|
@@ -1,192 +1,191 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { assert, Texture, Framebuffer } from '@luma.gl/core';
|
|
5
|
+
import { GL } from '@luma.gl/constants';
|
|
2
6
|
import { getGLTypeFromTypedArray, getTypedArrayFromGLType } from "./typed-array-utils.js";
|
|
3
7
|
import { glFormatToComponents, glTypeToBytes } from "./format-utils.js";
|
|
8
|
+
/**
|
|
9
|
+
* Copies data from a type or a Texture object into ArrayBuffer object.
|
|
10
|
+
* App can provide targetPixelArray or have it auto allocated by this method
|
|
11
|
+
* newly allocated by this method unless provided by app.
|
|
12
|
+
* @deprecated Use CommandEncoder.copyTextureToBuffer and Buffer.read
|
|
13
|
+
* @note Slow requires roundtrip to GPU
|
|
14
|
+
*
|
|
15
|
+
* @param source
|
|
16
|
+
* @param options
|
|
17
|
+
* @returns pixel array,
|
|
18
|
+
*/
|
|
4
19
|
export function readPixelsToArray(source, options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
framebuffer.destroy();
|
|
38
|
-
}
|
|
39
|
-
return target;
|
|
20
|
+
const { sourceX = 0, sourceY = 0, sourceFormat = 6408, sourceAttachment = 36064 // TODO - support gl.readBuffer
|
|
21
|
+
} = options || {};
|
|
22
|
+
let { target = null,
|
|
23
|
+
// following parameters are auto deduced if not provided
|
|
24
|
+
sourceWidth, sourceHeight, sourceType } = options || {};
|
|
25
|
+
const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
|
|
26
|
+
assert(framebuffer);
|
|
27
|
+
const { gl, handle } = framebuffer;
|
|
28
|
+
sourceWidth = sourceWidth || framebuffer.width;
|
|
29
|
+
sourceHeight = sourceHeight || framebuffer.height;
|
|
30
|
+
// TODO - Set and unset gl.readBuffer
|
|
31
|
+
// if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {
|
|
32
|
+
// sourceAttachment = GL.FRONT;
|
|
33
|
+
// }
|
|
34
|
+
const attachment = sourceAttachment - 36064;
|
|
35
|
+
// assert(attachments[sourceAttachment]);
|
|
36
|
+
// Deduce the type from color attachment if not provided.
|
|
37
|
+
sourceType =
|
|
38
|
+
sourceType ||
|
|
39
|
+
framebuffer.colorAttachments[attachment]?.texture?.type || 5121;
|
|
40
|
+
// Deduce type and allocated pixelArray if needed
|
|
41
|
+
target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
|
|
42
|
+
// Pixel array available, if necessary, deduce type from it.
|
|
43
|
+
sourceType = sourceType || getGLTypeFromTypedArray(target);
|
|
44
|
+
const prevHandle = gl.bindFramebuffer(36160, handle);
|
|
45
|
+
gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
|
|
46
|
+
// @ts-expect-error
|
|
47
|
+
gl.bindFramebuffer(36160, prevHandle || null);
|
|
48
|
+
if (deleteFramebuffer) {
|
|
49
|
+
framebuffer.destroy();
|
|
50
|
+
}
|
|
51
|
+
return target;
|
|
40
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Copies data from a Framebuffer or a Texture object into a Buffer object.
|
|
55
|
+
* NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transffer.
|
|
56
|
+
* @deprecated Use CommandEncoder
|
|
57
|
+
* @param source
|
|
58
|
+
* @param options
|
|
59
|
+
*/
|
|
41
60
|
export function readPixelsToBuffer(source, options) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
sourceType
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
61
|
+
const { target, sourceX = 0, sourceY = 0, sourceFormat = 6408, targetByteOffset = 0 } = options || {};
|
|
62
|
+
// following parameters are auto deduced if not provided
|
|
63
|
+
let { sourceWidth, sourceHeight, sourceType } = options || {};
|
|
64
|
+
const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
|
|
65
|
+
assert(framebuffer);
|
|
66
|
+
sourceWidth = sourceWidth || framebuffer.width;
|
|
67
|
+
sourceHeight = sourceHeight || framebuffer.height;
|
|
68
|
+
// Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature
|
|
69
|
+
const webglFramebuffer = framebuffer;
|
|
70
|
+
// deduce type if not available.
|
|
71
|
+
sourceType = sourceType || 5121;
|
|
72
|
+
let webglBufferTarget = target;
|
|
73
|
+
if (!webglBufferTarget) {
|
|
74
|
+
// Create new buffer with enough size
|
|
75
|
+
const components = glFormatToComponents(sourceFormat);
|
|
76
|
+
const byteCount = glTypeToBytes(sourceType);
|
|
77
|
+
const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
|
|
78
|
+
webglBufferTarget = webglFramebuffer.device.createBuffer({ byteLength });
|
|
79
|
+
}
|
|
80
|
+
// TODO(donmccurdy): Do we have tests to confirm this is working?
|
|
81
|
+
const commandEncoder = source.device.createCommandEncoder();
|
|
82
|
+
commandEncoder.copyTextureToBuffer({
|
|
83
|
+
source: source,
|
|
84
|
+
width: sourceWidth,
|
|
85
|
+
height: sourceHeight,
|
|
86
|
+
origin: [sourceX, sourceY],
|
|
87
|
+
destination: webglBufferTarget,
|
|
88
|
+
byteOffset: targetByteOffset
|
|
70
89
|
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
height: sourceHeight,
|
|
77
|
-
origin: [sourceX, sourceY],
|
|
78
|
-
destination: webglBufferTarget,
|
|
79
|
-
byteOffset: targetByteOffset
|
|
80
|
-
});
|
|
81
|
-
commandEncoder.destroy();
|
|
82
|
-
if (deleteFramebuffer) {
|
|
83
|
-
framebuffer.destroy();
|
|
84
|
-
}
|
|
85
|
-
return webglBufferTarget;
|
|
90
|
+
commandEncoder.destroy();
|
|
91
|
+
if (deleteFramebuffer) {
|
|
92
|
+
framebuffer.destroy();
|
|
93
|
+
}
|
|
94
|
+
return webglBufferTarget;
|
|
86
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Copy a rectangle from a Framebuffer or Texture object into a texture (at an offset)
|
|
98
|
+
* @deprecated Use CommandEncoder
|
|
99
|
+
*/
|
|
100
|
+
// eslint-disable-next-line complexity, max-statements
|
|
87
101
|
export function copyToTexture(source, target, options) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
break;
|
|
136
|
-
case 35866:
|
|
137
|
-
case 32879:
|
|
138
|
-
device.assertWebGL2();
|
|
139
|
-
device.gl2.copyTexSubImage3D(textureTarget, targetMipmaplevel, targetX, targetY, targetZ, sourceX, sourceY, width, height);
|
|
140
|
-
break;
|
|
141
|
-
default:
|
|
102
|
+
const { sourceX = 0, sourceY = 0,
|
|
103
|
+
// attachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
|
|
104
|
+
targetMipmaplevel = 0, targetInternalFormat = 6408 } = options || {};
|
|
105
|
+
let { targetX, targetY, targetZ, width, // defaults to target width
|
|
106
|
+
height // defaults to target height
|
|
107
|
+
} = options || {};
|
|
108
|
+
const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
|
|
109
|
+
assert(framebuffer);
|
|
110
|
+
const webglFramebuffer = framebuffer;
|
|
111
|
+
const { device, handle } = webglFramebuffer;
|
|
112
|
+
const isSubCopy = typeof targetX !== 'undefined' ||
|
|
113
|
+
typeof targetY !== 'undefined' ||
|
|
114
|
+
typeof targetZ !== 'undefined';
|
|
115
|
+
targetX = targetX || 0;
|
|
116
|
+
targetY = targetY || 0;
|
|
117
|
+
targetZ = targetZ || 0;
|
|
118
|
+
const prevHandle = device.gl.bindFramebuffer(36160, handle);
|
|
119
|
+
// TODO - support gl.readBuffer (WebGL2 only)
|
|
120
|
+
// const prevBuffer = gl.readBuffer(attachment);
|
|
121
|
+
assert(target);
|
|
122
|
+
let texture = null;
|
|
123
|
+
let textureTarget;
|
|
124
|
+
if (target instanceof Texture) {
|
|
125
|
+
texture = target;
|
|
126
|
+
width = Number.isFinite(width) ? width : texture.width;
|
|
127
|
+
height = Number.isFinite(height) ? height : texture.height;
|
|
128
|
+
texture.bind(0);
|
|
129
|
+
textureTarget = texture.target;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
textureTarget = target;
|
|
133
|
+
}
|
|
134
|
+
if (!isSubCopy) {
|
|
135
|
+
device.gl.copyTexImage2D(textureTarget, targetMipmaplevel, targetInternalFormat, sourceX, sourceY, width, height, 0 /* border must be 0 */);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
switch (textureTarget) {
|
|
139
|
+
case 3553:
|
|
140
|
+
case 34067:
|
|
141
|
+
device.gl.copyTexSubImage2D(textureTarget, targetMipmaplevel, targetX, targetY, sourceX, sourceY, width, height);
|
|
142
|
+
break;
|
|
143
|
+
case 35866:
|
|
144
|
+
case 32879:
|
|
145
|
+
device.gl.copyTexSubImage3D(textureTarget, targetMipmaplevel, targetX, targetY, targetZ, sourceX, sourceY, width, height);
|
|
146
|
+
break;
|
|
147
|
+
default:
|
|
148
|
+
}
|
|
142
149
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
if (texture) {
|
|
151
|
+
texture.unbind();
|
|
152
|
+
}
|
|
153
|
+
// @ts-expect-error
|
|
154
|
+
device.gl.bindFramebuffer(36160, prevHandle || null);
|
|
155
|
+
if (deleteFramebuffer) {
|
|
156
|
+
framebuffer.destroy();
|
|
157
|
+
}
|
|
158
|
+
return texture;
|
|
152
159
|
}
|
|
153
160
|
function getFramebuffer(source) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
framebuffer: source,
|
|
162
|
-
deleteFramebuffer: false
|
|
163
|
-
};
|
|
161
|
+
if (!(source instanceof Framebuffer)) {
|
|
162
|
+
return { framebuffer: toFramebuffer(source), deleteFramebuffer: true };
|
|
163
|
+
}
|
|
164
|
+
return { framebuffer: source, deleteFramebuffer: false };
|
|
164
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Wraps a given texture into a framebuffer object, that can be further used
|
|
168
|
+
* to read data from the texture object.
|
|
169
|
+
*/
|
|
165
170
|
export function toFramebuffer(texture, props) {
|
|
166
|
-
|
|
167
|
-
device
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
width,
|
|
176
|
-
height,
|
|
177
|
-
colorAttachments: [texture]
|
|
178
|
-
});
|
|
179
|
-
return framebuffer;
|
|
171
|
+
const { device, width, height, id } = texture;
|
|
172
|
+
const framebuffer = device.createFramebuffer({
|
|
173
|
+
...props,
|
|
174
|
+
id: `framebuffer-for-${id}`,
|
|
175
|
+
width,
|
|
176
|
+
height,
|
|
177
|
+
colorAttachments: [texture]
|
|
178
|
+
});
|
|
179
|
+
return framebuffer;
|
|
180
180
|
}
|
|
181
181
|
function getPixelArray(pixelArray, type, format, width, height) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
clamped: false
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
182
|
+
if (pixelArray) {
|
|
183
|
+
return pixelArray;
|
|
184
|
+
}
|
|
185
|
+
// Allocate pixel array if not already available, using supplied type
|
|
186
|
+
type = type || 5121;
|
|
187
|
+
const ArrayType = getTypedArrayFromGLType(type, { clamped: false });
|
|
188
|
+
const components = glFormatToComponents(format);
|
|
189
|
+
// TODO - check for composite type (components = 1).
|
|
190
|
+
return new ArrayType(width * height * components);
|
|
191
191
|
}
|
|
192
|
-
//# sourceMappingURL=copy-and-blit.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function glFormatToComponents(format: any):
|
|
2
|
-
export declare function glTypeToBytes(type: any):
|
|
1
|
+
export declare function glFormatToComponents(format: any): 0 | 1 | 4 | 2 | 3;
|
|
2
|
+
export declare function glTypeToBytes(type: any): 0 | 1 | 4 | 2;
|
|
3
3
|
//# sourceMappingURL=format-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-utils.d.ts","sourceRoot":"","sources":["../../src/classic/format-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"format-utils.d.ts","sourceRoot":"","sources":["../../src/classic/format-utils.ts"],"names":[],"mappings":"AAQA,wBAAgB,oBAAoB,CAAC,MAAM,KAAA,qBAoB1C;AAGD,wBAAgB,aAAa,CAAC,IAAI,KAAA,iBAejC"}
|
|
@@ -1,37 +1,44 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { assert } from '@luma.gl/core';
|
|
5
|
+
import { GL } from '@luma.gl/constants';
|
|
6
|
+
// Returns number of components in a specific readPixels WebGL format
|
|
2
7
|
export function glFormatToComponents(format) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
switch (format) {
|
|
9
|
+
case 6406:
|
|
10
|
+
case 33326:
|
|
11
|
+
case 6403:
|
|
12
|
+
return 1;
|
|
13
|
+
case 33328:
|
|
14
|
+
case 33319:
|
|
15
|
+
return 2;
|
|
16
|
+
case 6407:
|
|
17
|
+
case 34837:
|
|
18
|
+
return 3;
|
|
19
|
+
case 6408:
|
|
20
|
+
case 34836:
|
|
21
|
+
return 4;
|
|
22
|
+
// TODO: Add support for additional WebGL2 formats
|
|
23
|
+
default:
|
|
24
|
+
assert(false);
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
21
27
|
}
|
|
28
|
+
// Return byte count for given readPixels WebGL type
|
|
22
29
|
export function glTypeToBytes(type) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
switch (type) {
|
|
31
|
+
case 5121:
|
|
32
|
+
return 1;
|
|
33
|
+
case 33635:
|
|
34
|
+
case 32819:
|
|
35
|
+
case 32820:
|
|
36
|
+
return 2;
|
|
37
|
+
case 5126:
|
|
38
|
+
return 4;
|
|
39
|
+
// TODO: Add support for additional WebGL2 types
|
|
40
|
+
default:
|
|
41
|
+
assert(false);
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
36
44
|
}
|
|
37
|
-
//# sourceMappingURL=format-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed-array-utils.d.ts","sourceRoot":"","sources":["../../src/classic/typed-array-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typed-array-utils.d.ts","sourceRoot":"","sources":["../../src/classic/typed-array-utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,UAAU,EAAE,qBAAqB,EAAC,MAAM,eAAe,CAAC;AAChE,OAAO,EAAK,UAAU,EAAE,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAI/D;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,UAAU,GAAG,UAAU,CAuB3E;AAED;;;;;;;GAOG;AAEH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,UAAU,GAAG,WAAW,EAChC,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GACA,qBAAqB,CAwBvB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE;IAChC,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB,GAAG,IAAI,CAgBP;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE;IAAC,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,GAAG;IACvF,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAaA"}
|
|
@@ -1,91 +1,106 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { GL } from '@luma.gl/constants';
|
|
1
5
|
const ERR_TYPE_DEDUCTION = 'Failed to deduce GL constant from typed array';
|
|
6
|
+
/**
|
|
7
|
+
* Converts TYPED ARRAYS to corresponding GL constant
|
|
8
|
+
* Used to auto deduce gl parameter types
|
|
9
|
+
* @deprecated Use getDataTypeFromTypedArray
|
|
10
|
+
* @param arrayOrType
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
2
13
|
export function getGLTypeFromTypedArray(arrayOrType) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
// If typed array, look up constructor
|
|
15
|
+
const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
|
|
16
|
+
switch (type) {
|
|
17
|
+
case Float32Array:
|
|
18
|
+
return 5126;
|
|
19
|
+
case Uint16Array:
|
|
20
|
+
return 5123;
|
|
21
|
+
case Uint32Array:
|
|
22
|
+
return 5125;
|
|
23
|
+
case Uint8Array:
|
|
24
|
+
return 5121;
|
|
25
|
+
case Uint8ClampedArray:
|
|
26
|
+
return 5121;
|
|
27
|
+
case Int8Array:
|
|
28
|
+
return 5120;
|
|
29
|
+
case Int16Array:
|
|
30
|
+
return 5122;
|
|
31
|
+
case Int32Array:
|
|
32
|
+
return 5124;
|
|
33
|
+
default:
|
|
34
|
+
throw new Error(ERR_TYPE_DEDUCTION);
|
|
35
|
+
}
|
|
24
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Converts GL constant to corresponding TYPED ARRAY
|
|
39
|
+
* Used to auto deduce gl parameter types
|
|
40
|
+
* @deprecated Use getTypedArrayFromDataType
|
|
41
|
+
* @param glType
|
|
42
|
+
* @param param1
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
// eslint-disable-next-line complexity
|
|
25
46
|
export function getTypedArrayFromGLType(glType, options) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
47
|
+
const { clamped = true } = options || {};
|
|
48
|
+
// Sorted in some order of likelihood to reduce amount of comparisons
|
|
49
|
+
switch (glType) {
|
|
50
|
+
case 5126:
|
|
51
|
+
return Float32Array;
|
|
52
|
+
case 5123:
|
|
53
|
+
case 33635:
|
|
54
|
+
case 32819:
|
|
55
|
+
case 32820:
|
|
56
|
+
return Uint16Array;
|
|
57
|
+
case 5125:
|
|
58
|
+
return Uint32Array;
|
|
59
|
+
case 5121:
|
|
60
|
+
return clamped ? Uint8ClampedArray : Uint8Array;
|
|
61
|
+
case 5120:
|
|
62
|
+
return Int8Array;
|
|
63
|
+
case 5122:
|
|
64
|
+
return Int16Array;
|
|
65
|
+
case 5124:
|
|
66
|
+
return Int32Array;
|
|
67
|
+
default:
|
|
68
|
+
throw new Error('Failed to deduce typed array type from GL constant');
|
|
69
|
+
}
|
|
50
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Flip rows (can be used on arrays returned from `Framebuffer.readPixels`)
|
|
73
|
+
* https: *stackoverflow.com/questions/41969562/
|
|
74
|
+
* how-can-i-flip-the-result-of-webglrenderingcontext-readpixels
|
|
75
|
+
* @param param0
|
|
76
|
+
*/
|
|
51
77
|
export function flipRows(options) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
data.set(tempBuffer, bottomOffset);
|
|
67
|
-
}
|
|
78
|
+
const { data, width, height, bytesPerPixel = 4, temp } = options;
|
|
79
|
+
const bytesPerRow = width * bytesPerPixel;
|
|
80
|
+
// make a temp buffer to hold one row
|
|
81
|
+
const tempBuffer = temp || new Uint8Array(bytesPerRow);
|
|
82
|
+
for (let y = 0; y < height / 2; ++y) {
|
|
83
|
+
const topOffset = y * bytesPerRow;
|
|
84
|
+
const bottomOffset = (height - y - 1) * bytesPerRow;
|
|
85
|
+
// make copy of a row on the top half
|
|
86
|
+
tempBuffer.set(data.subarray(topOffset, topOffset + bytesPerRow));
|
|
87
|
+
// copy a row from the bottom half to the top
|
|
88
|
+
data.copyWithin(topOffset, bottomOffset, bottomOffset + bytesPerRow);
|
|
89
|
+
// copy the copy of the top half row to the bottom half
|
|
90
|
+
data.set(tempBuffer, bottomOffset);
|
|
91
|
+
}
|
|
68
92
|
}
|
|
69
93
|
export function scalePixels(options) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
for (let c = 0; c < 4; c++) {
|
|
81
|
-
newData[(y * newWidth + x) * 4 + c] = data[(y * 2 * width + x * 2) * 4 + c];
|
|
82
|
-
}
|
|
94
|
+
const { data, width, height } = options;
|
|
95
|
+
const newWidth = Math.round(width / 2);
|
|
96
|
+
const newHeight = Math.round(height / 2);
|
|
97
|
+
const newData = new Uint8Array(newWidth * newHeight * 4);
|
|
98
|
+
for (let y = 0; y < newHeight; y++) {
|
|
99
|
+
for (let x = 0; x < newWidth; x++) {
|
|
100
|
+
for (let c = 0; c < 4; c++) {
|
|
101
|
+
newData[(y * newWidth + x) * 4 + c] = data[(y * 2 * width + x * 2) * 4 + c];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
83
104
|
}
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
data: newData,
|
|
87
|
-
width: newWidth,
|
|
88
|
-
height: newHeight
|
|
89
|
-
};
|
|
105
|
+
return { data: newData, width: newWidth, height: newHeight };
|
|
90
106
|
}
|
|
91
|
-
//# sourceMappingURL=typed-array-utils.js.map
|