typegpu 0.10.1 → 0.10.2
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/{chunk-BYypO7fO.js → _virtual/_rolldown/runtime.js} +1 -1
- package/builtin.d.ts +50 -0
- package/builtin.js +37 -0
- package/common/fullScreenTriangle.d.ts +26 -0
- package/common/fullScreenTriangle.js +36 -0
- package/common/index.d.ts +2 -3
- package/common/index.js +3 -4
- package/core/buffer/buffer.d.ts +74 -0
- package/core/buffer/buffer.js +197 -0
- package/core/buffer/bufferShorthand.d.ts +48 -0
- package/core/buffer/bufferShorthand.js +49 -0
- package/core/buffer/bufferUsage.d.ts +45 -0
- package/core/buffer/bufferUsage.js +163 -0
- package/core/constant/tgpuConstant.d.ts +28 -0
- package/core/constant/tgpuConstant.js +67 -0
- package/core/declare/tgpuDeclare.d.ts +18 -0
- package/core/declare/tgpuDeclare.js +40 -0
- package/core/function/autoIO.d.ts +37 -0
- package/core/function/autoIO.js +87 -0
- package/core/function/comptime.d.ts +39 -0
- package/core/function/comptime.js +51 -0
- package/core/function/createCallableSchema.js +42 -0
- package/core/function/dualImpl.js +54 -0
- package/core/function/extractArgs.js +204 -0
- package/core/function/fnCore.js +79 -0
- package/core/function/fnTypes.d.ts +34 -0
- package/core/function/ioSchema.d.ts +10 -0
- package/core/function/ioSchema.js +30 -0
- package/core/function/shelllessImpl.d.ts +28 -0
- package/core/function/shelllessImpl.js +23 -0
- package/core/function/templateUtils.js +13 -0
- package/core/function/tgpuComputeFn.d.ts +49 -0
- package/core/function/tgpuComputeFn.js +62 -0
- package/core/function/tgpuFn.d.ts +52 -0
- package/core/function/tgpuFn.js +170 -0
- package/core/function/tgpuFragmentFn.d.ts +68 -0
- package/core/function/tgpuFragmentFn.js +68 -0
- package/core/function/tgpuVertexFn.d.ts +55 -0
- package/core/function/tgpuVertexFn.js +65 -0
- package/core/pipeline/applyPipelineState.js +37 -0
- package/core/pipeline/computePipeline.d.ts +58 -0
- package/core/pipeline/computePipeline.js +226 -0
- package/core/pipeline/connectAttachmentToShader.js +26 -0
- package/core/pipeline/connectTargetsToShader.js +29 -0
- package/core/pipeline/limitsOverflow.js +13 -0
- package/core/pipeline/renderPipeline.d.ts +266 -0
- package/core/pipeline/renderPipeline.js +471 -0
- package/core/pipeline/timeable.d.ts +23 -0
- package/core/pipeline/timeable.js +61 -0
- package/core/pipeline/typeGuards.js +29 -0
- package/core/querySet/querySet.d.ts +22 -0
- package/core/querySet/querySet.js +103 -0
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +59 -0
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +96 -0
- package/core/resolve/externals.d.ts +10 -0
- package/core/resolve/externals.js +58 -0
- package/core/resolve/namespace.d.ts +38 -0
- package/core/resolve/namespace.js +41 -0
- package/core/resolve/resolveData.js +146 -0
- package/core/resolve/stitch.js +25 -0
- package/core/resolve/tgpuResolve.d.ts +151 -0
- package/core/resolve/tgpuResolve.js +68 -0
- package/core/root/configurableImpl.js +18 -0
- package/core/root/init.d.ts +69 -0
- package/core/root/init.js +457 -0
- package/core/root/rootTypes.d.ts +622 -0
- package/core/sampler/sampler.d.ts +35 -0
- package/core/sampler/sampler.js +116 -0
- package/core/simulate/tgpuSimulate.d.ts +36 -0
- package/core/simulate/tgpuSimulate.js +76 -0
- package/core/slot/accessor.d.ts +13 -0
- package/core/slot/accessor.js +97 -0
- package/core/slot/internalSlots.js +7 -0
- package/core/slot/lazy.d.ts +6 -0
- package/core/slot/lazy.js +42 -0
- package/core/slot/slot.d.ts +6 -0
- package/core/slot/slot.js +40 -0
- package/core/slot/slotTypes.d.ts +92 -0
- package/core/slot/slotTypes.js +21 -0
- package/core/texture/externalTexture.d.ts +12 -0
- package/core/texture/externalTexture.js +48 -0
- package/core/texture/texture.d.ts +118 -0
- package/core/texture/texture.js +312 -0
- package/core/texture/textureFormats.d.ts +29 -0
- package/core/texture/textureFormats.js +99 -0
- package/core/texture/textureProps.d.ts +11 -0
- package/core/texture/textureUtils.js +224 -0
- package/core/texture/usageExtension.d.ts +21 -0
- package/core/texture/usageExtension.js +21 -0
- package/core/unroll/tgpuUnroll.d.ts +13 -0
- package/core/unroll/tgpuUnroll.js +36 -0
- package/core/valueProxyUtils.js +44 -0
- package/core/variable/tgpuVariable.d.ts +38 -0
- package/core/variable/tgpuVariable.js +101 -0
- package/core/vertexLayout/connectAttributesToShader.js +59 -0
- package/core/vertexLayout/vertexAttribute.d.ts +29 -0
- package/core/vertexLayout/vertexLayout.d.ts +19 -0
- package/core/vertexLayout/vertexLayout.js +103 -0
- package/data/alignIO.js +15 -0
- package/data/alignmentOf.d.ts +10 -0
- package/data/alignmentOf.js +88 -0
- package/data/array.d.ts +28 -0
- package/data/array.js +48 -0
- package/data/atomic.d.ts +15 -0
- package/data/atomic.js +25 -0
- package/data/attributes.d.ts +121 -0
- package/data/attributes.js +145 -0
- package/data/autoStruct.d.ts +3 -0
- package/data/autoStruct.js +83 -0
- package/data/compiledIO.js +231 -0
- package/data/dataIO.js +549 -0
- package/data/dataTypes.d.ts +115 -0
- package/data/dataTypes.js +97 -0
- package/data/deepEqual.d.ts +25 -0
- package/data/deepEqual.js +58 -0
- package/data/disarray.d.ts +34 -0
- package/data/disarray.js +52 -0
- package/data/getLongestContiguousPrefix.d.ts +10 -0
- package/data/getLongestContiguousPrefix.js +15 -0
- package/data/index.d.ts +26 -4
- package/data/index.js +27 -7
- package/data/instanceToSchema.d.ts +33 -0
- package/data/isContiguous.d.ts +10 -0
- package/data/isContiguous.js +15 -0
- package/data/matrix.d.ts +126 -0
- package/data/matrix.js +517 -0
- package/data/numberOps.js +24 -0
- package/data/numeric.d.ts +81 -0
- package/data/numeric.js +234 -0
- package/data/offsetUtils.d.ts +33 -0
- package/data/offsetUtils.js +167 -0
- package/data/offsets.js +36 -0
- package/data/partialIO.js +68 -0
- package/data/ptr.d.ts +12 -0
- package/data/ptr.js +46 -0
- package/data/ref.d.ts +37 -0
- package/data/ref.js +96 -0
- package/data/sampler.d.ts +107 -0
- package/data/sampler.js +26 -0
- package/data/schemaCallWrapper.js +32 -0
- package/data/schemaMemoryLayout.js +200 -0
- package/data/sizeOf.d.ts +10 -0
- package/data/sizeOf.js +15 -0
- package/data/snippet.d.ts +26 -0
- package/data/snippet.js +61 -0
- package/data/struct.d.ts +17 -0
- package/data/struct.js +46 -0
- package/data/texture.d.ts +292 -0
- package/{texture-BagDrrks.js → data/texture.js} +6 -3
- package/data/unstruct.d.ts +24 -0
- package/data/unstruct.js +43 -0
- package/data/vector.d.ts +191 -0
- package/data/vector.js +247 -0
- package/data/vectorImpl.js +516 -0
- package/data/vectorOps.js +664 -0
- package/data/vertexFormatData.d.ts +190 -0
- package/data/vertexFormatData.js +110 -0
- package/data/wgslTypes.d.ts +896 -0
- package/data/wgslTypes.js +215 -0
- package/errors.d.ts +44 -0
- package/errors.js +128 -0
- package/execMode.js +51 -0
- package/extension.d.ts +11 -0
- package/extension.js +18 -0
- package/getGPUValue.js +9 -0
- package/index.d.ts +40 -243
- package/index.js +19 -6318
- package/indexNamedExports.d.ts +38 -0
- package/mathUtils.js +13 -0
- package/memo.js +22 -0
- package/nameRegistry.d.ts +30 -0
- package/nameRegistry.js +449 -0
- package/package.js +5 -0
- package/package.json +23 -23
- package/resolutionCtx.d.ts +29 -0
- package/resolutionCtx.js +546 -0
- package/shared/env.js +13 -0
- package/shared/generators.js +14 -0
- package/shared/meta.d.ts +39 -0
- package/shared/meta.js +63 -0
- package/shared/repr.d.ts +108 -0
- package/shared/stringify.js +22 -0
- package/shared/symbols.d.ts +61 -0
- package/shared/symbols.js +71 -0
- package/shared/utilityTypes.d.ts +29 -0
- package/shared/utilityTypes.js +7 -0
- package/shared/vertexFormat.d.ts +70 -0
- package/shared/vertexFormat.js +64 -0
- package/std/array.d.ts +7 -0
- package/std/array.js +27 -0
- package/std/atomic.d.ts +19 -0
- package/std/atomic.js +113 -0
- package/std/bitcast.d.ts +10 -0
- package/std/bitcast.js +43 -0
- package/std/boolean.d.ts +127 -0
- package/std/boolean.js +274 -0
- package/std/derivative.d.ts +16 -0
- package/std/derivative.js +89 -0
- package/std/discard.d.ts +6 -0
- package/std/discard.js +16 -0
- package/std/extensions.d.ts +8 -0
- package/std/extensions.js +14 -0
- package/std/index.d.ts +15 -3
- package/std/index.js +16 -5
- package/std/matrix.d.ts +41 -0
- package/std/matrix.js +87 -0
- package/std/numeric.d.ts +254 -0
- package/std/numeric.js +847 -0
- package/std/operators.d.ts +48 -0
- package/std/operators.js +153 -0
- package/std/packing.d.ts +26 -0
- package/std/packing.js +86 -0
- package/std/subgroup.d.ts +47 -0
- package/std/subgroup.js +220 -0
- package/std/texture.d.ts +108 -0
- package/std/texture.js +197 -0
- package/tgpu.js +44 -0
- package/tgpuBindGroupLayout.d.ts +161 -0
- package/tgpuBindGroupLayout.js +271 -0
- package/tgpuUnstable.d.ts +48 -0
- package/tgpuUnstable.js +66 -0
- package/tgsl/accessIndex.js +45 -0
- package/tgsl/accessProp.js +113 -0
- package/tgsl/consoleLog/deserializers.js +117 -0
- package/tgsl/consoleLog/logGenerator.js +86 -0
- package/tgsl/consoleLog/serializers.js +225 -0
- package/tgsl/consoleLog/types.d.ts +54 -0
- package/tgsl/consoleLog/types.js +12 -0
- package/tgsl/conversion.js +200 -0
- package/tgsl/forOfUtils.js +45 -0
- package/tgsl/generationHelpers.d.ts +37 -0
- package/tgsl/generationHelpers.js +67 -0
- package/tgsl/math.js +45 -0
- package/tgsl/shaderGenerator.d.ts +18 -0
- package/tgsl/shellless.d.ts +11 -0
- package/tgsl/shellless.js +53 -0
- package/tgsl/wgslGenerator.js +585 -0
- package/types.d.ts +255 -0
- package/types.js +43 -0
- package/unwrapper.d.ts +27 -0
- package/wgslExtensions.d.ts +5 -0
- package/wgslExtensions.js +18 -0
- package/builtin-DdtWpk2t.js +0 -818
- package/builtin-DdtWpk2t.js.map +0 -1
- package/common/index.d.ts.map +0 -1
- package/common/index.js.map +0 -1
- package/data/index.d.ts.map +0 -1
- package/data/index.js.map +0 -1
- package/deepEqual-DQxK4vdp.js +0 -413
- package/deepEqual-DQxK4vdp.js.map +0 -1
- package/extensions-DIVuAfBM.js +0 -2032
- package/extensions-DIVuAfBM.js.map +0 -1
- package/fullScreenTriangle-CfFyQd_0.js +0 -543
- package/fullScreenTriangle-CfFyQd_0.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/indexNamedExports-oL6tyaJ9.d.ts +0 -5697
- package/indexNamedExports-oL6tyaJ9.d.ts.map +0 -1
- package/operators-d-PMVTo7.js +0 -4158
- package/operators-d-PMVTo7.js.map +0 -1
- package/std/index.d.ts.map +0 -1
- package/std/index.js.map +0 -1
- package/texture-BagDrrks.js.map +0 -1
package/data/vector.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { $internal, $repr } from "../shared/symbols.js";
|
|
2
|
+
import { isVec } from "./wgslTypes.js";
|
|
3
|
+
import { stitch } from "../core/resolve/stitch.js";
|
|
4
|
+
import { callableSchema } from "../core/function/createCallableSchema.js";
|
|
5
|
+
import { bool, f16, f32, i32, u32 } from "./numeric.js";
|
|
6
|
+
import { Vec2bImpl, Vec2fImpl, Vec2hImpl, Vec2iImpl, Vec2uImpl, Vec3bImpl, Vec3fImpl, Vec3hImpl, Vec3iImpl, Vec3uImpl, Vec4bImpl, Vec4fImpl, Vec4hImpl, Vec4iImpl, Vec4uImpl } from "./vectorImpl.js";
|
|
7
|
+
|
|
8
|
+
//#region src/data/vector.ts
|
|
9
|
+
/**
|
|
10
|
+
* Schema representing vec2f - a vector with 2 elements of type f32.
|
|
11
|
+
* Also a constructor function for this vector value.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const vector = d.vec2f(); // (0.0, 0.0)
|
|
15
|
+
* const vector = d.vec2f(1); // (1.0, 1.0)
|
|
16
|
+
* const vector = d.vec2f(0.5, 0.1); // (0.5, 0.1)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const buffer = root.createBuffer(d.vec2f, d.vec2f(0, 1)); // buffer holding a d.vec2f value, with an initial value of vec2f(0, 1);
|
|
20
|
+
*/
|
|
21
|
+
const vec2f = makeVecSchema(Vec2fImpl, f32);
|
|
22
|
+
/**
|
|
23
|
+
* Schema representing vec2h - a vector with 2 elements of type f16.
|
|
24
|
+
* Also a constructor function for this vector value.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const vector = d.vec2h(); // (0.0, 0.0)
|
|
28
|
+
* const vector = d.vec2h(1); // (1.0, 1.0)
|
|
29
|
+
* const vector = d.vec2h(0.5, 0.1); // (0.5, 0.1)
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const buffer = root.createBuffer(d.vec2h, d.vec2h(0, 1)); // buffer holding a d.vec2h value, with an initial value of vec2h(0, 1);
|
|
33
|
+
*/
|
|
34
|
+
const vec2h = makeVecSchema(Vec2hImpl, f16);
|
|
35
|
+
/**
|
|
36
|
+
* Schema representing vec2i - a vector with 2 elements of type i32.
|
|
37
|
+
* Also a constructor function for this vector value.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* const vector = d.vec2i(); // (0, 0)
|
|
41
|
+
* const vector = d.vec2i(1); // (1, 1)
|
|
42
|
+
* const vector = d.vec2i(-1, 1); // (-1, 1)
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* const buffer = root.createBuffer(d.vec2i, d.vec2i(0, 1)); // buffer holding a d.vec2i value, with an initial value of vec2i(0, 1);
|
|
46
|
+
*/
|
|
47
|
+
const vec2i = makeVecSchema(Vec2iImpl, i32);
|
|
48
|
+
/**
|
|
49
|
+
* Schema representing vec2u - a vector with 2 elements of type u32.
|
|
50
|
+
* Also a constructor function for this vector value.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* const vector = d.vec2u(); // (0, 0)
|
|
54
|
+
* const vector = d.vec2u(1); // (1, 1)
|
|
55
|
+
* const vector = d.vec2u(1, 2); // (1, 2)
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const buffer = root.createBuffer(d.vec2u, d.vec2u(0, 1)); // buffer holding a d.vec2u value, with an initial value of vec2u(0, 1);
|
|
59
|
+
*/
|
|
60
|
+
const vec2u = makeVecSchema(Vec2uImpl, u32);
|
|
61
|
+
/**
|
|
62
|
+
* Schema representing `vec2<bool>` - a vector with 2 elements of type `bool`.
|
|
63
|
+
* Also a constructor function for this vector value.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* const vector = d.vec2b(); // (false, false)
|
|
67
|
+
* const vector = d.vec2b(true); // (true, true)
|
|
68
|
+
* const vector = d.vec2b(false, true); // (false, true)
|
|
69
|
+
*/
|
|
70
|
+
const vec2b = makeVecSchema(Vec2bImpl, bool);
|
|
71
|
+
/**
|
|
72
|
+
* Schema representing vec3f - a vector with 3 elements of type f32.
|
|
73
|
+
* Also a constructor function for this vector value.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* const vector = d.vec3f(); // (0.0, 0.0, 0.0)
|
|
77
|
+
* const vector = d.vec3f(1); // (1.0, 1.0, 1.0)
|
|
78
|
+
* const vector = d.vec3f(1, 2, 3.5); // (1.0, 2.0, 3.5)
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* const buffer = root.createBuffer(d.vec3f, d.vec3f(0, 1, 2)); // buffer holding a d.vec3f value, with an initial value of vec3f(0, 1, 2);
|
|
82
|
+
*/
|
|
83
|
+
const vec3f = makeVecSchema(Vec3fImpl, f32);
|
|
84
|
+
/**
|
|
85
|
+
* Schema representing vec3h - a vector with 3 elements of type f16.
|
|
86
|
+
* Also a constructor function for this vector value.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* const vector = d.vec3h(); // (0.0, 0.0, 0.0)
|
|
90
|
+
* const vector = d.vec3h(1); // (1.0, 1.0, 1.0)
|
|
91
|
+
* const vector = d.vec3h(1, 2, 3.5); // (1.0, 2.0, 3.5)
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* const buffer = root.createBuffer(d.vec3h, d.vec3h(0, 1, 2)); // buffer holding a d.vec3h value, with an initial value of vec3h(0, 1, 2);
|
|
95
|
+
*/
|
|
96
|
+
const vec3h = makeVecSchema(Vec3hImpl, f16);
|
|
97
|
+
/**
|
|
98
|
+
* Schema representing vec3i - a vector with 3 elements of type i32.
|
|
99
|
+
* Also a constructor function for this vector value.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* const vector = d.vec3i(); // (0, 0, 0)
|
|
103
|
+
* const vector = d.vec3i(1); // (1, 1, 1)
|
|
104
|
+
* const vector = d.vec3i(1, 2, -3); // (1, 2, -3)
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* const buffer = root.createBuffer(d.vec3i, d.vec3i(0, 1, 2)); // buffer holding a d.vec3i value, with an initial value of vec3i(0, 1, 2);
|
|
108
|
+
*/
|
|
109
|
+
const vec3i = makeVecSchema(Vec3iImpl, i32);
|
|
110
|
+
/**
|
|
111
|
+
* Schema representing vec3u - a vector with 3 elements of type u32.
|
|
112
|
+
* Also a constructor function for this vector value.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* const vector = d.vec3u(); // (0, 0, 0)
|
|
116
|
+
* const vector = d.vec3u(1); // (1, 1, 1)
|
|
117
|
+
* const vector = d.vec3u(1, 2, 3); // (1, 2, 3)
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* const buffer = root.createBuffer(d.vec3u, d.vec3u(0, 1, 2)); // buffer holding a d.vec3u value, with an initial value of vec3u(0, 1, 2);
|
|
121
|
+
*/
|
|
122
|
+
const vec3u = makeVecSchema(Vec3uImpl, u32);
|
|
123
|
+
/**
|
|
124
|
+
* Schema representing `vec3<bool>` - a vector with 3 elements of type `bool`.
|
|
125
|
+
* Also a constructor function for this vector value.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* const vector = d.vec3b(); // (false, false, false)
|
|
129
|
+
* const vector = d.vec3b(true); // (true, true, true)
|
|
130
|
+
* const vector = d.vec3b(false, true, false); // (false, true, false)
|
|
131
|
+
*/
|
|
132
|
+
const vec3b = makeVecSchema(Vec3bImpl, bool);
|
|
133
|
+
/**
|
|
134
|
+
* Schema representing vec4f - a vector with 4 elements of type f32.
|
|
135
|
+
* Also a constructor function for this vector value.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* const vector = d.vec4f(); // (0.0, 0.0, 0.0, 0.0)
|
|
139
|
+
* const vector = d.vec4f(1); // (1.0, 1.0, 1.0, 1.0)
|
|
140
|
+
* const vector = d.vec4f(1, 2, 3, 4.5); // (1.0, 2.0, 3.0, 4.5)
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* const buffer = root.createBuffer(d.vec4f, d.vec4f(0, 1, 2, 3)); // buffer holding a d.vec4f value, with an initial value of vec4f(0, 1, 2, 3);
|
|
144
|
+
*/
|
|
145
|
+
const vec4f = makeVecSchema(Vec4fImpl, f32);
|
|
146
|
+
/**
|
|
147
|
+
* Schema representing vec4h - a vector with 4 elements of type f16.
|
|
148
|
+
* Also a constructor function for this vector value.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* const vector = d.vec4h(); // (0.0, 0.0, 0.0, 0.0)
|
|
152
|
+
* const vector = d.vec4h(1); // (1.0, 1.0, 1.0, 1.0)
|
|
153
|
+
* const vector = d.vec4h(1, 2, 3, 4.5); // (1.0, 2.0, 3.0, 4.5)
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* const buffer = root.createBuffer(d.vec4h, d.vec4h(0, 1, 2, 3)); // buffer holding a d.vec4h value, with an initial value of vec4h(0, 1, 2, 3);
|
|
157
|
+
*/
|
|
158
|
+
const vec4h = makeVecSchema(Vec4hImpl, f16);
|
|
159
|
+
/**
|
|
160
|
+
* Schema representing vec4i - a vector with 4 elements of type i32.
|
|
161
|
+
* Also a constructor function for this vector value.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* const vector = d.vec4i(); // (0, 0, 0, 0)
|
|
165
|
+
* const vector = d.vec4i(1); // (1, 1, 1, 1)
|
|
166
|
+
* const vector = d.vec4i(1, 2, 3, -4); // (1, 2, 3, -4)
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* const buffer = root.createBuffer(d.vec4i, d.vec4i(0, 1, 2, 3)); // buffer holding a d.vec4i value, with an initial value of vec4i(0, 1, 2, 3);
|
|
170
|
+
*/
|
|
171
|
+
const vec4i = makeVecSchema(Vec4iImpl, i32);
|
|
172
|
+
/**
|
|
173
|
+
* Schema representing vec4u - a vector with 4 elements of type u32.
|
|
174
|
+
* Also a constructor function for this vector value.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* const vector = d.vec4u(); // (0, 0, 0, 0)
|
|
178
|
+
* const vector = d.vec4u(1); // (1, 1, 1, 1)
|
|
179
|
+
* const vector = d.vec4u(1, 2, 3, 4); // (1, 2, 3, 4)
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* const buffer = root.createBuffer(d.vec4u, d.vec4u(0, 1, 2, 3)); // buffer holding a d.vec4u value, with an initial value of vec4u(0, 1, 2, 3);
|
|
183
|
+
*/
|
|
184
|
+
const vec4u = makeVecSchema(Vec4uImpl, u32);
|
|
185
|
+
/**
|
|
186
|
+
* Schema representing `vec4<bool>` - a vector with 4 elements of type `bool`.
|
|
187
|
+
* Also a constructor function for this vector value.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* const vector = d.vec4b(); // (false, false, false, false)
|
|
191
|
+
* const vector = d.vec4b(true); // (true, true, true, true)
|
|
192
|
+
* const vector = d.vec4b(false, true, false, true); // (false, true, false, true)
|
|
193
|
+
*/
|
|
194
|
+
const vec4b = makeVecSchema(Vec4bImpl, bool);
|
|
195
|
+
const vecTypeToConstructor = {
|
|
196
|
+
vec2f,
|
|
197
|
+
vec2h,
|
|
198
|
+
vec2i,
|
|
199
|
+
vec2u,
|
|
200
|
+
"vec2<bool>": vec2b,
|
|
201
|
+
vec3f,
|
|
202
|
+
vec3h,
|
|
203
|
+
vec3i,
|
|
204
|
+
vec3u,
|
|
205
|
+
"vec3<bool>": vec3b,
|
|
206
|
+
vec4f,
|
|
207
|
+
vec4h,
|
|
208
|
+
vec4i,
|
|
209
|
+
vec4u,
|
|
210
|
+
"vec4<bool>": vec4b
|
|
211
|
+
};
|
|
212
|
+
function makeVecSchema(VecImpl, primitive) {
|
|
213
|
+
const { kind: type, length } = new VecImpl();
|
|
214
|
+
const componentCount = length;
|
|
215
|
+
const cpuConstruct = (...args) => {
|
|
216
|
+
const values = Array.from({ length: args.length });
|
|
217
|
+
let j = 0;
|
|
218
|
+
for (const arg of args) if (typeof arg === "number" || typeof arg === "boolean") values[j++] = arg;
|
|
219
|
+
else for (let c = 0; c < arg.length; ++c) values[j++] = arg[c];
|
|
220
|
+
if (values.length <= 1 || values.length === componentCount) return new VecImpl(...values);
|
|
221
|
+
throw new Error(`'${type}' constructor called with invalid number of arguments.`);
|
|
222
|
+
};
|
|
223
|
+
const construct = callableSchema({
|
|
224
|
+
name: type,
|
|
225
|
+
signature: (...args) => ({
|
|
226
|
+
argTypes: args.map((arg) => isVec(arg) ? arg : primitive),
|
|
227
|
+
returnType: schema
|
|
228
|
+
}),
|
|
229
|
+
normalImpl: cpuConstruct,
|
|
230
|
+
codegenImpl: (_ctx, args) => {
|
|
231
|
+
if (args.length === 1 && args[0]?.dataType === schema) return stitch`${args[0]}`;
|
|
232
|
+
return stitch`${type}(${args})`;
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
const schema = Object.assign(construct, {
|
|
236
|
+
[$internal]: {},
|
|
237
|
+
type,
|
|
238
|
+
primitive,
|
|
239
|
+
componentCount,
|
|
240
|
+
[$repr]: void 0
|
|
241
|
+
});
|
|
242
|
+
VecImpl.prototype.schema = schema;
|
|
243
|
+
return schema;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
//#endregion
|
|
247
|
+
export { vec2b, vec2f, vec2h, vec2i, vec2u, vec3b, vec3f, vec3h, vec3i, vec3u, vec4b, vec4f, vec4h, vec4i, vec4u, vecTypeToConstructor };
|