@aardworx/wombat.rendering 0.7.0 → 0.7.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/dist/core/bufferView.d.ts +18 -17
- package/dist/core/bufferView.d.ts.map +1 -1
- package/dist/core/bufferView.js +56 -94
- package/dist/core/bufferView.js.map +1 -1
- package/dist/core/elementType.d.ts +78 -13
- package/dist/core/elementType.d.ts.map +1 -1
- package/dist/core/elementType.js +147 -76
- package/dist/core/elementType.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/resources/preparedRenderObject.d.ts.map +1 -1
- package/dist/resources/preparedRenderObject.js +10 -2
- package/dist/resources/preparedRenderObject.js.map +1 -1
- package/package.json +2 -2
- package/src/core/bufferView.ts +64 -105
- package/src/core/elementType.ts +174 -80
- package/src/core/index.ts +1 -0
- package/src/resources/preparedRenderObject.ts +10 -2
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { aval } from "@aardworx/wombat.adaptive";
|
|
2
2
|
import { IBuffer } from "./buffer.js";
|
|
3
|
-
import
|
|
3
|
+
import { ElementType } from "./elementType.js";
|
|
4
|
+
import type { ElementKind } from "./elementType.js";
|
|
4
5
|
export interface BufferView {
|
|
5
6
|
/** Adaptive buffer source — content changes flow through this aval. */
|
|
6
7
|
readonly buffer: aval<IBuffer>;
|
|
7
|
-
/** Element kind
|
|
8
|
+
/** Element kind (singleton from the `ElementType` namespace). */
|
|
8
9
|
readonly elementType: ElementType;
|
|
9
10
|
/** Byte offset into `buffer` where the view starts. Default 0. */
|
|
10
11
|
readonly offset?: number;
|
|
11
|
-
/** Stride between consecutive elements in bytes. 0 = tight (= `byteSize
|
|
12
|
+
/** Stride between consecutive elements in bytes. 0 = tight (= `elementType.byteSize`). */
|
|
12
13
|
readonly stride?: number;
|
|
13
14
|
/** Integer attributes treated as normalized fixed-point floats. Default false. */
|
|
14
15
|
readonly normalized?: boolean;
|
|
@@ -20,17 +21,13 @@ export interface BufferView {
|
|
|
20
21
|
*/
|
|
21
22
|
readonly singleValue?: aval<unknown>;
|
|
22
23
|
}
|
|
23
|
-
interface WombatArrayLike {
|
|
24
|
-
readonly buffer: ArrayBufferLike;
|
|
25
|
-
readonly length: number;
|
|
26
|
-
}
|
|
27
24
|
interface OfArrayOptions {
|
|
28
25
|
readonly elementType?: ElementType;
|
|
29
26
|
readonly offset?: number;
|
|
30
27
|
readonly stride?: number;
|
|
31
28
|
readonly normalized?: boolean;
|
|
32
29
|
}
|
|
33
|
-
interface
|
|
30
|
+
interface OfBufferOptions {
|
|
34
31
|
readonly offset?: number;
|
|
35
32
|
readonly stride?: number;
|
|
36
33
|
readonly normalized?: boolean;
|
|
@@ -38,35 +35,39 @@ interface OfGPUOptions {
|
|
|
38
35
|
export declare const BufferView: {
|
|
39
36
|
/**
|
|
40
37
|
* Build a view from a wombat.base packed array (`V3fArray`,
|
|
41
|
-
* `Uint16Array`, …) or an `aval<…>` of one. The element
|
|
42
|
-
* inferred from the array constructor; pass it
|
|
43
|
-
* `opts.elementType` for unusual cases.
|
|
38
|
+
* `Uint16Array`, …) or an `aval<…>` of one. The element kind is
|
|
39
|
+
* inferred from the array's constructor identity; pass it
|
|
40
|
+
* explicitly via `opts.elementType` for unusual cases (e.g. a
|
|
41
|
+
* `Float32Array` interpreted as packed `V4f` with `ElementType.V4f`).
|
|
44
42
|
*/
|
|
45
|
-
readonly ofArray: <T
|
|
43
|
+
readonly ofArray: <T>(a: aval<T> | T, opts?: OfArrayOptions) => BufferView;
|
|
46
44
|
/**
|
|
47
45
|
* Build a view that broadcasts a single adaptive value to every
|
|
48
46
|
* vertex / instance. The runtime detects the `singleValue` field
|
|
49
47
|
* and lowers it to a uniform binding instead of a per-element
|
|
50
48
|
* attribute. The `buffer` aval still carries packed bytes for
|
|
51
49
|
* backends that don't recognize the fast path.
|
|
50
|
+
*
|
|
51
|
+
* The `T` parameter on `ElementKind<T>` flows through to the
|
|
52
|
+
* value type — passing `ElementType.V4f` requires `T = V4f` here.
|
|
52
53
|
*/
|
|
53
|
-
readonly ofValue: <T>(v: aval<T> | T, elementType:
|
|
54
|
+
readonly ofValue: <T>(v: aval<T> | T, elementType: ElementKind<T>) => BufferView;
|
|
54
55
|
/**
|
|
55
56
|
* Build a view backed by a user-supplied `GPUBuffer`. The
|
|
56
57
|
* runtime binds it directly without an upload step.
|
|
57
58
|
*/
|
|
58
|
-
readonly ofGPU: (buffer: aval<GPUBuffer> | GPUBuffer, elementType: ElementType, opts?:
|
|
59
|
+
readonly ofGPU: (buffer: aval<GPUBuffer> | GPUBuffer, elementType: ElementType, opts?: OfBufferOptions) => BufferView;
|
|
59
60
|
/**
|
|
60
61
|
* Wrap an already-built `aval<IBuffer>` with explicit element
|
|
61
|
-
*
|
|
62
|
+
* kind. Used by callers that compute their own `IBuffer` (e.g.
|
|
62
63
|
* compositing multiple attributes into one packed buffer).
|
|
63
64
|
*/
|
|
64
|
-
readonly ofBuffer: (buffer: aval<IBuffer>, elementType: ElementType, opts?:
|
|
65
|
+
readonly ofBuffer: (buffer: aval<IBuffer>, elementType: ElementType, opts?: OfBufferOptions) => BufferView;
|
|
65
66
|
/** Byte offset, defaulting to 0. */
|
|
66
67
|
readonly offsetOf: (v: BufferView) => number;
|
|
67
68
|
/**
|
|
68
69
|
* Stride in bytes — `v.stride` if set and non-zero, otherwise
|
|
69
|
-
* tight from `elementType`.
|
|
70
|
+
* tight from `elementType.byteSize`.
|
|
70
71
|
*/
|
|
71
72
|
readonly strideOf: (v: BufferView) => number;
|
|
72
73
|
/** Whether this view is a single-value broadcast. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bufferView.d.ts","sourceRoot":"","sources":["../../src/core/bufferView.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAEtD,OAAO,EAAE,O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AO,MAAM,UAAU;IACrB;;;;;;OAMG;uBACK,CAAC,KACJ,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,SACR,cAAc,KACnB,UAAU;IAmBb;;;;;;;;;OASG;uBACK,CAAC,KACJ,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,eACD,WAAW,CAAC,CAAC,CAAC,KAC1B,UAAU;IAeb;;;OAGG;6BAEO,IAAI,CAAC,SAAS,CAAC,GAAG,SAAS,eACtB,WAAW,SAClB,eAAe,KACpB,UAAU;IAYb;;;;OAIG;gCAEO,IAAI,CAAC,OAAO,CAAC,eACR,WAAW,SAClB,eAAe,KACpB,UAAU;IAYb,oCAAoC;2BACxB,UAAU,KAAG,MAAM;IAC/B;;;OAGG;2BACS,UAAU,KAAG,MAAM;IAK/B,qDAAqD;gCACpC,UAAU,KAAG,OAAO;CAG7B,CAAC"}
|
package/dist/core/bufferView.js
CHANGED
|
@@ -4,79 +4,50 @@
|
|
|
4
4
|
//
|
|
5
5
|
// - `buffer` is `aval<IBuffer>` so per-frame content changes flow
|
|
6
6
|
// through normal aval marking without reshaping the view.
|
|
7
|
-
// - `elementType`
|
|
8
|
-
//
|
|
9
|
-
//
|
|
7
|
+
// - `elementType` is a singleton token from the `ElementType`
|
|
8
|
+
// namespace (e.g. `ElementType.V3f`, `ElementType.U16`); the
|
|
9
|
+
// backend reads `byteSize` / `vertexFormat` / `indexFormat`
|
|
10
|
+
// directly off it.
|
|
10
11
|
// - `singleValue` is set when the view was constructed from a
|
|
11
12
|
// single adaptive value broadcast to all instances/vertices —
|
|
12
13
|
// the runtime can lower it to a uniform binding instead of a
|
|
13
14
|
// per-vertex/per-instance attribute.
|
|
14
15
|
//
|
|
15
16
|
// The view itself is plain (not wrapped in `aval`). Structural
|
|
16
|
-
// fields
|
|
17
|
-
//
|
|
18
|
-
// without forcing.
|
|
17
|
+
// fields are eager so the binding plan / pipeline layout can be
|
|
18
|
+
// computed without forcing.
|
|
19
19
|
import { AVal } from "@aardworx/wombat.adaptive";
|
|
20
20
|
import { IBuffer } from "./buffer.js";
|
|
21
|
-
import { ElementType
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// backing field.
|
|
26
|
-
const ctor = arr.constructor;
|
|
27
|
-
const name = ctor?.name;
|
|
28
|
-
switch (name) {
|
|
29
|
-
case "V2fArray": return "v2f";
|
|
30
|
-
case "V3fArray": return "v3f";
|
|
31
|
-
case "V4fArray": return "v4f";
|
|
32
|
-
case "V2iArray": return "v2i";
|
|
33
|
-
case "V3iArray": return "v3i";
|
|
34
|
-
case "V4iArray": return "v4i";
|
|
35
|
-
case "V2uiArray": return "v2u";
|
|
36
|
-
case "V3uiArray": return "v3u";
|
|
37
|
-
case "V4uiArray": return "v4u";
|
|
38
|
-
// Native typed arrays.
|
|
39
|
-
case "Float32Array": return "f32";
|
|
40
|
-
case "Uint32Array": return "u32";
|
|
41
|
-
case "Int32Array": return "i32";
|
|
42
|
-
case "Uint16Array": return "u16";
|
|
43
|
-
case "Int16Array": return "i16";
|
|
44
|
-
case "Uint8Array": return "u8";
|
|
45
|
-
case "Int8Array": return "i8";
|
|
46
|
-
}
|
|
47
|
-
throw new Error(`BufferView.ofArray: cannot infer ElementType from ${name ?? "unknown type"}; ` +
|
|
48
|
-
`pass elementType explicitly`);
|
|
21
|
+
import { ElementType } from "./elementType.js";
|
|
22
|
+
function isAval(v) {
|
|
23
|
+
return typeof v === "object" && v !== null
|
|
24
|
+
&& typeof v.getValue === "function";
|
|
49
25
|
}
|
|
50
26
|
function arrayToHostBytes(arr) {
|
|
51
|
-
// wombat.base packed types expose `.buffer: ArrayBuffer
|
|
52
|
-
// exactly the packed bytes.
|
|
27
|
+
// wombat.base packed array types expose `.buffer: ArrayBuffer`.
|
|
53
28
|
const a = arr;
|
|
54
29
|
if (a.buffer instanceof ArrayBuffer)
|
|
55
30
|
return a.buffer;
|
|
56
|
-
// Native
|
|
31
|
+
// Native TypedArray.
|
|
57
32
|
if (ArrayBuffer.isView(arr))
|
|
58
33
|
return arr;
|
|
59
34
|
throw new Error("BufferView.ofArray: unsupported array source");
|
|
60
35
|
}
|
|
61
|
-
function isAval(v) {
|
|
62
|
-
return typeof v === "object" && v !== null
|
|
63
|
-
&& typeof v.getValue === "function";
|
|
64
|
-
}
|
|
65
36
|
export const BufferView = {
|
|
66
37
|
/**
|
|
67
38
|
* Build a view from a wombat.base packed array (`V3fArray`,
|
|
68
|
-
* `Uint16Array`, …) or an `aval<…>` of one. The element
|
|
69
|
-
* inferred from the array constructor; pass it
|
|
70
|
-
* `opts.elementType` for unusual cases.
|
|
39
|
+
* `Uint16Array`, …) or an `aval<…>` of one. The element kind is
|
|
40
|
+
* inferred from the array's constructor identity; pass it
|
|
41
|
+
* explicitly via `opts.elementType` for unusual cases (e.g. a
|
|
42
|
+
* `Float32Array` interpreted as packed `V4f` with `ElementType.V4f`).
|
|
71
43
|
*/
|
|
72
44
|
ofArray(a, opts = {}) {
|
|
73
45
|
const adaptive = isAval(a) ? a : AVal.constant(a);
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
/* allow-force */
|
|
78
|
-
const
|
|
79
|
-
const elementType = opts.elementType ?? inferElementType(sample);
|
|
46
|
+
// One-time element-kind discovery from the source's constructor.
|
|
47
|
+
// Marked allow-force: structural-eager, runs at construction only;
|
|
48
|
+
// per-frame content changes flow through `buffer` without re-running.
|
|
49
|
+
const sample = adaptive.force( /* allow-force */);
|
|
50
|
+
const elementType = opts.elementType ?? ElementType.fromArray(sample);
|
|
80
51
|
const buffer = adaptive.map((arr) => IBuffer.fromHost(arrayToHostBytes(arr)));
|
|
81
52
|
return {
|
|
82
53
|
buffer,
|
|
@@ -92,11 +63,14 @@ export const BufferView = {
|
|
|
92
63
|
* and lowers it to a uniform binding instead of a per-element
|
|
93
64
|
* attribute. The `buffer` aval still carries packed bytes for
|
|
94
65
|
* backends that don't recognize the fast path.
|
|
66
|
+
*
|
|
67
|
+
* The `T` parameter on `ElementKind<T>` flows through to the
|
|
68
|
+
* value type — passing `ElementType.V4f` requires `T = V4f` here.
|
|
95
69
|
*/
|
|
96
70
|
ofValue(v, elementType) {
|
|
97
71
|
const adaptive = isAval(v) ? v : AVal.constant(v);
|
|
98
72
|
const buffer = adaptive.map((value) => {
|
|
99
|
-
const bytes =
|
|
73
|
+
const bytes = elementType.byteSize;
|
|
100
74
|
const ab = new ArrayBuffer(bytes);
|
|
101
75
|
packSingle(value, elementType, ab);
|
|
102
76
|
return IBuffer.fromHost(ab);
|
|
@@ -124,7 +98,7 @@ export const BufferView = {
|
|
|
124
98
|
},
|
|
125
99
|
/**
|
|
126
100
|
* Wrap an already-built `aval<IBuffer>` with explicit element
|
|
127
|
-
*
|
|
101
|
+
* kind. Used by callers that compute their own `IBuffer` (e.g.
|
|
128
102
|
* compositing multiple attributes into one packed buffer).
|
|
129
103
|
*/
|
|
130
104
|
ofBuffer(buffer, elementType, opts = {}) {
|
|
@@ -141,12 +115,12 @@ export const BufferView = {
|
|
|
141
115
|
offsetOf(v) { return v.offset ?? 0; },
|
|
142
116
|
/**
|
|
143
117
|
* Stride in bytes — `v.stride` if set and non-zero, otherwise
|
|
144
|
-
* tight from `elementType`.
|
|
118
|
+
* tight from `elementType.byteSize`.
|
|
145
119
|
*/
|
|
146
120
|
strideOf(v) {
|
|
147
121
|
return v.stride !== undefined && v.stride > 0
|
|
148
122
|
? v.stride
|
|
149
|
-
:
|
|
123
|
+
: v.elementType.byteSize;
|
|
150
124
|
},
|
|
151
125
|
/** Whether this view is a single-value broadcast. */
|
|
152
126
|
isSingleValue(v) {
|
|
@@ -154,53 +128,41 @@ export const BufferView = {
|
|
|
154
128
|
},
|
|
155
129
|
};
|
|
156
130
|
// ---------------------------------------------------------------------------
|
|
157
|
-
// Single-value packing — write one element of `
|
|
158
|
-
//
|
|
159
|
-
//
|
|
160
|
-
//
|
|
131
|
+
// Single-value packing — write one element of `t` into a fresh
|
|
132
|
+
// ArrayBuffer. The runtime usually shortcuts this via `singleValue`
|
|
133
|
+
// (lifted to a uniform); this path runs only for backends that
|
|
134
|
+
// don't recognise the broadcast.
|
|
161
135
|
// ---------------------------------------------------------------------------
|
|
162
136
|
function packSingle(value, t, dst) {
|
|
163
|
-
// Lazy import to avoid a hard dep on wombat.base shapes here. We
|
|
164
|
-
// peek at `_data` (the typed-array view exposed by every wombat
|
|
165
|
-
// math type) and copy its bytes into the destination.
|
|
166
137
|
const v = value;
|
|
167
138
|
if (v._data !== undefined) {
|
|
168
139
|
const src = v._data;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
case "v2u":
|
|
192
|
-
case "v3u":
|
|
193
|
-
case "v4u":
|
|
194
|
-
case "u32": {
|
|
195
|
-
const out = new Uint32Array(dst);
|
|
196
|
-
for (let i = 0; i < src.length; i++)
|
|
197
|
-
out[i] = src[i];
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
140
|
+
// Match by name on the singleton — concise and minifier-safe
|
|
141
|
+
// since the names are baked at the singleton's construction.
|
|
142
|
+
const name = t.name;
|
|
143
|
+
if (name === "f32"
|
|
144
|
+
|| name.startsWith("v") && name.endsWith("f")
|
|
145
|
+
|| name.startsWith("m") && name.endsWith("f")) {
|
|
146
|
+
const out = new Float32Array(dst);
|
|
147
|
+
for (let i = 0; i < src.length; i++)
|
|
148
|
+
out[i] = src[i];
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (name === "i32" || (name.startsWith("v") && name.endsWith("i"))) {
|
|
152
|
+
const out = new Int32Array(dst);
|
|
153
|
+
for (let i = 0; i < src.length; i++)
|
|
154
|
+
out[i] = src[i];
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (name === "u32" || (name.startsWith("v") && name.endsWith("u"))) {
|
|
158
|
+
const out = new Uint32Array(dst);
|
|
159
|
+
for (let i = 0; i < src.length; i++)
|
|
160
|
+
out[i] = src[i];
|
|
161
|
+
return;
|
|
200
162
|
}
|
|
201
163
|
}
|
|
202
164
|
// Scalars and unbranded values.
|
|
203
|
-
switch (t) {
|
|
165
|
+
switch (t.name) {
|
|
204
166
|
case "f32":
|
|
205
167
|
new Float32Array(dst)[0] = value;
|
|
206
168
|
return;
|
|
@@ -223,6 +185,6 @@ function packSingle(value, t, dst) {
|
|
|
223
185
|
new Int8Array(dst)[0] = value;
|
|
224
186
|
return;
|
|
225
187
|
}
|
|
226
|
-
throw new Error(`BufferView.ofValue: cannot pack ${typeof value} as ${t}`);
|
|
188
|
+
throw new Error(`BufferView.ofValue: cannot pack ${typeof value} as ${t.name}`);
|
|
227
189
|
}
|
|
228
190
|
//# sourceMappingURL=bufferView.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bufferView.js","sourceRoot":"","sources":["../../src/core/bufferView.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,0DAA0D;AAC1D,qCAAqC;AACrC,EAAE;AACF,oEAAoE;AACpE,8DAA8D;AAC9D,
|
|
1
|
+
{"version":3,"file":"bufferView.js","sourceRoot":"","sources":["../../src/core/bufferView.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,0DAA0D;AAC1D,qCAAqC;AACrC,EAAE;AACF,oEAAoE;AACpE,8DAA8D;AAC9D,gEAAgE;AAChE,iEAAiE;AACjE,gEAAgE;AAChE,uBAAuB;AACvB,gEAAgE;AAChE,kEAAkE;AAClE,iEAAiE;AACjE,yCAAyC;AACzC,EAAE;AACF,+DAA+D;AAC/D,gEAAgE;AAChE,4BAA4B;AAG5B,OAAO,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AACjD,OAAO,EA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,CAAC;YAAC,OAAO;QAC/D,KAAK,IAAI;YAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAK,KAAe,CAAC;YAAC,OAAO;QAC/D,KAAK,IAAI;YAAG,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAM,KAAe,CAAC;YAAC,OAAO;IACjE,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,mCAAmC,OAAO,KAAK,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAClF,CAAC"}
|
|
@@ -1,16 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { V2f, V3f, V4f, M22f, M33f, M44f, V2i, V3i, V4i } from "@aardworx/wombat.base";
|
|
2
|
+
/**
|
|
3
|
+
* Phantom-typed token describing a single element's data type. The
|
|
4
|
+
* `T` parameter is a brand only — it carries the source-side type
|
|
5
|
+
* (V3f, M44f, number, …) into the type system at zero runtime cost.
|
|
6
|
+
*
|
|
7
|
+
* Identity equality is the equality used everywhere in the renderer
|
|
8
|
+
* (group keys, bind plans). All instances are singletons under the
|
|
9
|
+
* `ElementType` namespace below.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ElementKind<T> {
|
|
12
|
+
/** Short human-readable tag (e.g. `"v3f"`, `"u16"`). */
|
|
13
|
+
readonly name: string;
|
|
14
|
+
/** Size of one element in bytes. */
|
|
15
|
+
readonly byteSize: number;
|
|
16
|
+
/** GPUVertexFormat for use as a vertex attribute. `undefined` for matrix and non-vertex types. */
|
|
17
|
+
readonly vertexFormat: GPUVertexFormat | undefined;
|
|
18
|
+
/** GPUIndexFormat when used as an index buffer. `undefined` unless the type is `u16` / `u32`. */
|
|
19
|
+
readonly indexFormat: GPUIndexFormat | undefined;
|
|
20
|
+
constructor(
|
|
21
|
+
/** Short human-readable tag (e.g. `"v3f"`, `"u16"`). */
|
|
22
|
+
name: string,
|
|
3
23
|
/** Size of one element in bytes. */
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
24
|
+
byteSize: number,
|
|
25
|
+
/** GPUVertexFormat for use as a vertex attribute. `undefined` for matrix and non-vertex types. */
|
|
26
|
+
vertexFormat: GPUVertexFormat | undefined,
|
|
27
|
+
/** GPUIndexFormat when used as an index buffer. `undefined` unless the type is `u16` / `u32`. */
|
|
28
|
+
indexFormat: GPUIndexFormat | undefined);
|
|
29
|
+
/** Phantom — never read at runtime. Forces TS to track T. */
|
|
30
|
+
readonly _brand: T;
|
|
31
|
+
toString(): string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `ElementType` doubles as a type alias (the structural shape) and
|
|
35
|
+
* a value namespace (the singleton tokens). `ElementType` in type
|
|
36
|
+
* position is `ElementKind<unknown>`; in value position it's the
|
|
37
|
+
* collection of singletons below.
|
|
38
|
+
*/
|
|
39
|
+
export type ElementType = ElementKind<unknown>;
|
|
40
|
+
/**
|
|
41
|
+
* Construct a vertex view; throws if the kind has no vertex format
|
|
42
|
+
* (matrix / unsupported type).
|
|
43
|
+
*/
|
|
44
|
+
declare function asVertexFormat(t: ElementType): GPUVertexFormat;
|
|
45
|
+
declare function asIndexFormat(t: ElementType): GPUIndexFormat;
|
|
46
|
+
declare function fromArray(arr: unknown): ElementType;
|
|
47
|
+
/**
|
|
48
|
+
* Singleton tokens + helpers. Most call sites use the singleton
|
|
49
|
+
* directly (`ElementType.V3f`); the helpers are kept on the
|
|
50
|
+
* namespace so `import { ElementType }` is the only import you
|
|
51
|
+
* need.
|
|
52
|
+
*/
|
|
53
|
+
export declare const ElementType: {
|
|
54
|
+
readonly V2f: ElementKind<V2f>;
|
|
55
|
+
readonly V3f: ElementKind<V3f>;
|
|
56
|
+
readonly V4f: ElementKind<V4f>;
|
|
57
|
+
readonly M22f: ElementKind<M22f>;
|
|
58
|
+
readonly M33f: ElementKind<M33f>;
|
|
59
|
+
readonly M44f: ElementKind<M44f>;
|
|
60
|
+
readonly V2i: ElementKind<V2i>;
|
|
61
|
+
readonly V3i: ElementKind<V3i>;
|
|
62
|
+
readonly V4i: ElementKind<V4i>;
|
|
63
|
+
readonly V2u: ElementKind<V2i>;
|
|
64
|
+
readonly V3u: ElementKind<V3i>;
|
|
65
|
+
readonly V4u: ElementKind<V4i>;
|
|
66
|
+
readonly F32: ElementKind<number>;
|
|
67
|
+
readonly U32: ElementKind<number>;
|
|
68
|
+
readonly I32: ElementKind<number>;
|
|
69
|
+
readonly U16: ElementKind<number>;
|
|
70
|
+
readonly I16: ElementKind<number>;
|
|
71
|
+
readonly U8: ElementKind<number>;
|
|
72
|
+
readonly I8: ElementKind<number>;
|
|
73
|
+
/** Infer from a wombat.base packed array or a native TypedArray. */
|
|
74
|
+
readonly fromArray: typeof fromArray;
|
|
75
|
+
/** GPUVertexFormat for `t`; throws if `t` has no vertex form. */
|
|
76
|
+
readonly toVertexFormat: typeof asVertexFormat;
|
|
77
|
+
/** GPUIndexFormat for `t`; throws if `t` is not `u16` / `u32`. */
|
|
78
|
+
readonly toIndexFormat: typeof asIndexFormat;
|
|
15
79
|
};
|
|
80
|
+
export {};
|
|
16
81
|
//# sourceMappingURL=elementType.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elementType.d.ts","sourceRoot":"","sources":["../../src/core/elementType.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"elementType.d.ts","sourceRoot":"","sources":["../../src/core/elementType.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EACV,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAC/C,MAAM,uBAAuB,CAAC;AAW/B;;;;;;;;GAQG;AACH,qBAAa,WAAW,CAAC,CAAC;IAEtB,wDAAwD;IACxD,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,oCAAoC;IACpC,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,kGAAkG;IAClG,QAAQ,CAAC,YAAY,EAAE,eAAe,GAAG,SAAS;IAClD,iGAAiG;IACjG,QAAQ,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS;;IAPhD,wDAAwD;IAC/C,IAAI,EAAE,MAAM;IACrB,oCAAoC;IAC3B,QAAQ,EAAE,MAAM;IACzB,kGAAkG;IACzF,YAAY,EAAE,eAAe,GAAG,SAAS;IAClD,iGAAiG;IACxF,WAAW,EAAE,cAAc,GAAG,SAAS;IAGlD,6DAA6D;IAC7D,SAAiB,MAAM,EAAE,CAAC,CAAC;IAE3B,QAAQ,IAAI,MAAM;CACnB;AAED;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;AA0B/C;;;GAGG;AACH,iBAAS,cAAc,CAAC,CAAC,EAAE,WAAW,GAAG,eAAe,CAQvD;AAED,iBAAS,aAAa,CAAC,CAAC,EAAE,WAAW,GAAG,cAAc,CAKrD;AAuBD,iBAAS,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,WAAW,CAc5C;AAMD;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;IAatB,oEAAoE;;IAEpE,iEAAiE;;IAEjE,kEAAkE;;CAE1D,CAAC"}
|