@zephyr3d/device 0.1.0

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.
Files changed (40) hide show
  1. package/dist/base_types.js +602 -0
  2. package/dist/base_types.js.map +1 -0
  3. package/dist/builder/ast.js +2135 -0
  4. package/dist/builder/ast.js.map +1 -0
  5. package/dist/builder/base.js +477 -0
  6. package/dist/builder/base.js.map +1 -0
  7. package/dist/builder/builtinfunc.js +4101 -0
  8. package/dist/builder/builtinfunc.js.map +1 -0
  9. package/dist/builder/constructors.js +173 -0
  10. package/dist/builder/constructors.js.map +1 -0
  11. package/dist/builder/errors.js +148 -0
  12. package/dist/builder/errors.js.map +1 -0
  13. package/dist/builder/programbuilder.js +2323 -0
  14. package/dist/builder/programbuilder.js.map +1 -0
  15. package/dist/builder/reflection.js +60 -0
  16. package/dist/builder/reflection.js.map +1 -0
  17. package/dist/builder/types.js +1563 -0
  18. package/dist/builder/types.js.map +1 -0
  19. package/dist/device.js +515 -0
  20. package/dist/device.js.map +1 -0
  21. package/dist/gpuobject.js +2047 -0
  22. package/dist/gpuobject.js.map +1 -0
  23. package/dist/helpers/drawtext.js +187 -0
  24. package/dist/helpers/drawtext.js.map +1 -0
  25. package/dist/helpers/font.js +189 -0
  26. package/dist/helpers/font.js.map +1 -0
  27. package/dist/helpers/glyphmanager.js +121 -0
  28. package/dist/helpers/glyphmanager.js.map +1 -0
  29. package/dist/helpers/textureatlas.js +170 -0
  30. package/dist/helpers/textureatlas.js.map +1 -0
  31. package/dist/index.d.ts +3873 -0
  32. package/dist/index.js +16 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/timer.js +38 -0
  35. package/dist/timer.js.map +1 -0
  36. package/dist/uniformdata.js +147 -0
  37. package/dist/uniformdata.js.map +1 -0
  38. package/dist/vertexdata.js +135 -0
  39. package/dist/vertexdata.js.map +1 -0
  40. package/package.json +69 -0
@@ -0,0 +1,3873 @@
1
+ import { TypedArray, IEventTarget, CubeFace, VectorBase, Vector4 } from '@zephyr3d/base';
2
+
3
+ /**
4
+ * Struct layout types
5
+ * @public
6
+ */
7
+ type PBStructLayout = 'default' | 'std140' | 'std430' | 'packed';
8
+ /**
9
+ * Primitive types
10
+ * @public
11
+ */
12
+ declare enum PBPrimitiveType {
13
+ NONE = 0,
14
+ F16,
15
+ F16VEC2,
16
+ F16VEC3,
17
+ F16VEC4,
18
+ F32,
19
+ F32VEC2,
20
+ F32VEC3,
21
+ F32VEC4,
22
+ BOOL,
23
+ BVEC2,
24
+ BVEC3,
25
+ BVEC4,
26
+ I8,
27
+ I8VEC2,
28
+ I8VEC3,
29
+ I8VEC4,
30
+ I8_NORM,
31
+ I8VEC2_NORM,
32
+ I8VEC3_NORM,
33
+ I8VEC4_NORM,
34
+ I16,
35
+ I16VEC2,
36
+ I16VEC3,
37
+ I16VEC4,
38
+ I16_NORM,
39
+ I16VEC2_NORM,
40
+ I16VEC3_NORM,
41
+ I16VEC4_NORM,
42
+ I32,
43
+ I32VEC2,
44
+ I32VEC3,
45
+ I32VEC4,
46
+ I32_NORM,
47
+ I32VEC2_NORM,
48
+ I32VEC3_NORM,
49
+ I32VEC4_NORM,
50
+ U8,
51
+ U8VEC2,
52
+ U8VEC3,
53
+ U8VEC4,
54
+ U8_NORM,
55
+ U8VEC2_NORM,
56
+ U8VEC3_NORM,
57
+ U8VEC4_NORM,
58
+ U16,
59
+ U16VEC2,
60
+ U16VEC3,
61
+ U16VEC4,
62
+ U16_NORM,
63
+ U16VEC2_NORM,
64
+ U16VEC3_NORM,
65
+ U16VEC4_NORM,
66
+ U32,
67
+ U32VEC2,
68
+ U32VEC3,
69
+ U32VEC4,
70
+ U32_NORM,
71
+ U32VEC2_NORM,
72
+ U32VEC3_NORM,
73
+ U32VEC4_NORM,
74
+ MAT2,
75
+ MAT2x3,
76
+ MAT2x4,
77
+ MAT3x2,
78
+ MAT3,
79
+ MAT3x4,
80
+ MAT4x2,
81
+ MAT4x3,
82
+ MAT4
83
+ }
84
+ /**
85
+ * Texture types
86
+ * @public
87
+ */
88
+ declare enum PBTextureType {
89
+ TEX_1D = 257,
90
+ ITEX_1D = 513,
91
+ UTEX_1D = 1025,
92
+ TEX_2D = 258,
93
+ ITEX_2D = 514,
94
+ UTEX_2D = 1026,
95
+ TEX_2D_ARRAY = 274,
96
+ ITEX_2D_ARRAY = 530,
97
+ UTEX_2D_ARRAY = 1042,
98
+ TEX_3D = 260,
99
+ ITEX_3D = 516,
100
+ UTEX_3D = 1028,
101
+ TEX_CUBE = 264,
102
+ ITEX_CUBE = 520,
103
+ UTEX_CUBE = 1032,
104
+ TEX_CUBE_ARRAY = 280,
105
+ ITEX_CUBE_ARRAY = 536,
106
+ UTEX_CUBE_ARRAY = 1048,
107
+ TEX_MULTISAMPLED_2D = 290,
108
+ ITEX_MULTISAMPLED_2D = 546,
109
+ UTEX_MULTISAMPLED_2D = 1058,
110
+ TEX_STORAGE_1D = 65,
111
+ TEX_STORAGE_2D = 66,
112
+ TEX_STORAGE_2D_ARRAY = 82,
113
+ TEX_STORAGE_3D = 68,
114
+ TEX_DEPTH_2D = 130,
115
+ TEX_DEPTH_2D_ARRAY = 146,
116
+ TEX_DEPTH_CUBE = 136,
117
+ TEX_DEPTH_CUBE_ARRAY = 152,
118
+ TEX_DEPTH_MULTISAMPLED_2D = 162,
119
+ TEX_EXTERNAL = 2048
120
+ }
121
+ /**
122
+ * Sampler access mode
123
+ * @public
124
+ */
125
+ declare enum PBSamplerAccessMode {
126
+ UNKNOWN = 0,
127
+ SAMPLE = 1,
128
+ COMPARISON = 2
129
+ }
130
+ /**
131
+ * Shader variable address space
132
+ * @public
133
+ */
134
+ declare enum PBAddressSpace {
135
+ UNKNOWN = "unknown",
136
+ FUNCTION = "function",
137
+ PRIVATE = "private",
138
+ WORKGROUP = "workgroup",
139
+ UNIFORM = "uniform",
140
+ STORAGE = "storage"
141
+ }
142
+ /**
143
+ * Type detail information
144
+ * @public
145
+ */
146
+ type TypeDetailInfo = PrimitiveTypeDetail | StructTypeDetail | ArrayTypeDetail | PointerTypeDetail | AtomicTypeInfoDetail | SamplerTypeDetail | TextureTypeDetail | FunctionTypeDetail | null;
147
+ /**
148
+ * Detail informations for primitive type
149
+ * @public
150
+ */
151
+ interface PrimitiveTypeDetail {
152
+ primitiveType?: PBPrimitiveType;
153
+ }
154
+ /**
155
+ * Detail informations for struct type
156
+ * @public
157
+ */
158
+ interface StructTypeDetail {
159
+ /** Layout of the struct type */
160
+ layout: PBStructLayout;
161
+ /** Name of the struct type */
162
+ structName?: string;
163
+ /** Members of the struct type */
164
+ structMembers?: {
165
+ /** Name of the struct member */
166
+ name: string;
167
+ /** Type of the struct member */
168
+ type: PBPrimitiveTypeInfo | PBArrayTypeInfo | PBAtomicI32TypeInfo | PBAtomicU32TypeInfo | PBStructTypeInfo;
169
+ /** Alignment of the struct member */
170
+ alignment: number;
171
+ /** Byte size of the struct member */
172
+ size: number;
173
+ }[];
174
+ }
175
+ /**
176
+ * Detail informations for array type
177
+ * @public
178
+ */
179
+ interface ArrayTypeDetail {
180
+ /** Type of array elements */
181
+ elementType: PBPrimitiveTypeInfo | PBArrayTypeInfo | PBStructTypeInfo | PBAnyTypeInfo;
182
+ /** Array dimension */
183
+ dimension: number;
184
+ }
185
+ /**
186
+ * Detail informations for pointer type
187
+ * @public
188
+ */
189
+ interface PointerTypeDetail {
190
+ /** Type of the pointer */
191
+ pointerType: PBTypeInfo;
192
+ /** Address space of the pointer */
193
+ addressSpace: PBAddressSpace;
194
+ }
195
+ /**
196
+ * Detail information for atomic type
197
+ * @public
198
+ */
199
+ interface AtomicTypeInfoDetail {
200
+ /** Primitive type of the atomic type */
201
+ type: PBPrimitiveType;
202
+ }
203
+ /**
204
+ * Detail informations for sampler type
205
+ * @public
206
+ */
207
+ interface SamplerTypeDetail {
208
+ /** Access mode of the sampler type */
209
+ accessMode: PBSamplerAccessMode;
210
+ }
211
+ /**
212
+ * Detail informations for texture type
213
+ * @public
214
+ */
215
+ interface TextureTypeDetail {
216
+ /** type of the texture */
217
+ textureType: PBTextureType;
218
+ /** texture format if this is a storage texture */
219
+ storageTexelFormat: TextureFormat;
220
+ /** true if this is a readable storage texture type */
221
+ readable: boolean;
222
+ /** true if this is a writable storage texture type */
223
+ writable: boolean;
224
+ }
225
+ /**
226
+ * Detail information for a function type
227
+ * @public
228
+ */
229
+ interface FunctionTypeDetail {
230
+ /** The function name */
231
+ name: string;
232
+ /** Return type of the function */
233
+ returnType: PBTypeInfo;
234
+ /** Type information for function arguments */
235
+ argTypes: {
236
+ /** Type of the argument */
237
+ type: PBTypeInfo;
238
+ /** true if this argument will be passed by reference */
239
+ byRef?: boolean;
240
+ }[];
241
+ }
242
+ /**
243
+ * Abstract base class for any type
244
+ * @public
245
+ */
246
+ declare abstract class PBTypeInfo<DetailType extends TypeDetailInfo = TypeDetailInfo> {
247
+ /** Get unique id for this type */
248
+ get typeId(): string;
249
+ /** returns true if this is a void type */
250
+ isVoidType(): this is PBVoidTypeInfo;
251
+ /** returns true if this is an any type */
252
+ isAnyType(): this is PBAnyTypeInfo;
253
+ /** returns true if this is a primitive type */
254
+ isPrimitiveType(): this is PBPrimitiveTypeInfo;
255
+ /** returns true if this is a struct type */
256
+ isStructType(): this is PBStructTypeInfo;
257
+ /** returns true if this is an array type */
258
+ isArrayType(): this is PBArrayTypeInfo;
259
+ /** returns true if this is a pointer type */
260
+ isPointerType(): this is PBPointerTypeInfo;
261
+ /** returns true if this is an atomic int type */
262
+ isAtomicI32(): this is PBAtomicI32TypeInfo;
263
+ /** returns true if this is an atomic uint type */
264
+ isAtomicU32(): this is PBAtomicU32TypeInfo;
265
+ /** returns true if this is a sampler type */
266
+ isSamplerType(): this is PBSamplerTypeInfo;
267
+ /** returns true if this is a texture type */
268
+ isTextureType(): this is PBTextureTypeInfo;
269
+ /**
270
+ * Check whether a given type is compatible with this type
271
+ * @param other - The type to be checked
272
+ * @returns true if the given type is compatible with this type, othewise false
273
+ */
274
+ isCompatibleType(other: PBTypeInfo): boolean;
275
+ /**
276
+ * Creates a buffer layout from this type
277
+ * @param offset - Byte offset of the layout
278
+ * @param layout - Type of the layout
279
+ * @returns The created buffer layout
280
+ */
281
+ abstract toBufferLayout(offset: number, layout: PBStructLayout): UniformBufferLayout;
282
+ }
283
+ /**
284
+ * The void type info
285
+ * @public
286
+ */
287
+ declare class PBVoidTypeInfo extends PBTypeInfo<null> {
288
+ constructor();
289
+ /** {@inheritDoc PBTypeInfo.isVoidType} */
290
+ isVoidType(): this is PBVoidTypeInfo;
291
+ /** {@inheritDoc PBTypeInfo.toBufferLayout} */
292
+ toBufferLayout(offset: number): UniformBufferLayout;
293
+ }
294
+ /**
295
+ * The void type info
296
+ * @public
297
+ */
298
+ declare class PBAnyTypeInfo extends PBTypeInfo<null> {
299
+ constructor();
300
+ /** {@inheritDoc PBTypeInfo.isAnyType} */
301
+ isAnyType(): this is PBAnyTypeInfo;
302
+ /** {@inheritDoc PBTypeInfo.toBufferLayout} */
303
+ toBufferLayout(offset: number): UniformBufferLayout;
304
+ /** {@inheritDoc PBTypeInfo.isCompatibleType} */
305
+ isCompatibleType(other: PBTypeInfo<TypeDetailInfo>): boolean;
306
+ }
307
+ /**
308
+ * The primitive type info
309
+ * @public
310
+ */
311
+ declare class PBPrimitiveTypeInfo extends PBTypeInfo<PrimitiveTypeDetail> {
312
+ constructor(type: PBPrimitiveType);
313
+ /** Get or create a PBPrimitiveTypeInfo instance for a given prmitive type */
314
+ static getCachedTypeInfo(primitiveType: PBPrimitiveType): PBPrimitiveTypeInfo;
315
+ /** Get the primitive type */
316
+ get primitiveType(): PBPrimitiveType;
317
+ /** Whether the type is signed or unsigned integer scalar or vector */
318
+ isInteger(): boolean;
319
+ /** Get the scalar type */
320
+ get scalarType(): PBPrimitiveType;
321
+ /** Get number of rows */
322
+ get rows(): number;
323
+ /** Get number of columns */
324
+ get cols(): number;
325
+ /** Get if this is a normalized primitive type */
326
+ get normalized(): boolean;
327
+ /**
328
+ * Creates a new primitive type info by changing row and column of this type
329
+ * @param rows - The new value of row
330
+ * @param cols - The new value of column
331
+ * @returns The new primitive type
332
+ */
333
+ resizeType(rows: number, cols: number): PBPrimitiveType;
334
+ /** Returns true if this is a scalar type */
335
+ isScalarType(): boolean;
336
+ /** Returns true if this is a vector type */
337
+ isVectorType(): boolean;
338
+ /** Returns true if this is a matrix type */
339
+ isMatrixType(): boolean;
340
+ /** {@inheritDoc PBTypeInfo.isPrimitiveType} */
341
+ isPrimitiveType(): this is PBPrimitiveTypeInfo;
342
+ /** {@inheritDoc PBTypeInfo.toBufferLayout} */
343
+ toBufferLayout(offset: number): UniformBufferLayout;
344
+ }
345
+ /**
346
+ * The struct type info
347
+ * @public
348
+ */
349
+ declare class PBStructTypeInfo extends PBTypeInfo<StructTypeDetail> {
350
+ constructor(name: string, layout: PBStructLayout, members: {
351
+ name: string;
352
+ type: PBPrimitiveTypeInfo | PBArrayTypeInfo | PBAtomicI32TypeInfo | PBAtomicU32TypeInfo | PBStructTypeInfo;
353
+ }[]);
354
+ /** Get the layout type */
355
+ get layout(): PBStructLayout;
356
+ /** Get name of the struct type */
357
+ get structName(): string;
358
+ set structName(val: string);
359
+ /** Get member types of the struct type */
360
+ get structMembers(): {
361
+ /** Name of the struct member */
362
+ name: string;
363
+ /** Type of the struct member */
364
+ type: PBPrimitiveTypeInfo | PBArrayTypeInfo | PBStructTypeInfo | PBAtomicI32TypeInfo | PBAtomicU32TypeInfo;
365
+ /** Alignment of the struct member */
366
+ alignment: number;
367
+ /** Byte size of the struct member */
368
+ size: number;
369
+ /** @internal */
370
+ defaultAlignment: number;
371
+ /** @internal */
372
+ defaultSize: number;
373
+ }[];
374
+ /**
375
+ * Creates a new struct type by extending this type
376
+ * @param name - Name of the new struct type
377
+ * @param members - additional struct members
378
+ * @returns The new struct type
379
+ */
380
+ extends(name: string, members: {
381
+ name: string;
382
+ type: PBPrimitiveTypeInfo | PBArrayTypeInfo | PBStructTypeInfo;
383
+ }[]): PBStructTypeInfo;
384
+ /** {@inheritDoc PBTypeInfo.isStructType} */
385
+ isStructType(): this is PBStructTypeInfo;
386
+ /** {@inheritDoc PBTypeInfo.toBufferLayout} */
387
+ toBufferLayout(offset: number, layout: PBStructLayout): UniformBufferLayout;
388
+ }
389
+ /**
390
+ * The array type info
391
+ * @public
392
+ */
393
+ declare class PBArrayTypeInfo extends PBTypeInfo<ArrayTypeDetail> {
394
+ constructor(elementType: PBPrimitiveTypeInfo | PBArrayTypeInfo | PBStructTypeInfo | PBAnyTypeInfo, dimension?: number);
395
+ /** Get the element type */
396
+ get elementType(): PBPrimitiveTypeInfo | PBArrayTypeInfo | PBStructTypeInfo | PBAnyTypeInfo;
397
+ /** Get dimension of the array type */
398
+ get dimension(): number;
399
+ /** {@inheritDoc PBTypeInfo.isArrayType} */
400
+ isArrayType(): this is PBArrayTypeInfo;
401
+ /** {@inheritDoc PBTypeInfo.toBufferLayout} */
402
+ toBufferLayout(offset: number): UniformBufferLayout;
403
+ isCompatibleType(other: PBTypeInfo<TypeDetailInfo>): boolean;
404
+ }
405
+ /**
406
+ * The pointer type info
407
+ * @public
408
+ */
409
+ declare class PBPointerTypeInfo extends PBTypeInfo<PointerTypeDetail> {
410
+ constructor(pointerType: PBTypeInfo, addressSpace: PBAddressSpace);
411
+ /** Get type of the pointer */
412
+ get pointerType(): PBTypeInfo;
413
+ /** Get address space of the pointer */
414
+ get addressSpace(): PBAddressSpace;
415
+ set addressSpace(val: PBAddressSpace);
416
+ /** {@inheritDoc PBTypeInfo.isPointerType} */
417
+ isPointerType(): this is PBPointerTypeInfo;
418
+ /** {@inheritDoc PBTypeInfo.toBufferLayout} */
419
+ toBufferLayout(offset: number): UniformBufferLayout;
420
+ }
421
+ /**
422
+ * The atomic int type info
423
+ * @public
424
+ */
425
+ declare class PBAtomicI32TypeInfo extends PBTypeInfo<null> {
426
+ constructor();
427
+ /** {@inheritDoc PBTypeInfo.toBufferLayout} */
428
+ toBufferLayout(offset: number): UniformBufferLayout;
429
+ }
430
+ /**
431
+ * The atomic int type info
432
+ * @public
433
+ */
434
+ declare class PBAtomicU32TypeInfo extends PBTypeInfo<null> {
435
+ constructor();
436
+ /** {@inheritDoc PBTypeInfo.toBufferLayout} */
437
+ toBufferLayout(offset: number): UniformBufferLayout;
438
+ }
439
+ /**
440
+ * The sampler type info
441
+ * @public
442
+ */
443
+ declare class PBSamplerTypeInfo extends PBTypeInfo<SamplerTypeDetail> {
444
+ constructor(accessMode: PBSamplerAccessMode);
445
+ /** Get the access mode */
446
+ get accessMode(): PBSamplerAccessMode;
447
+ /** {@inheritDoc PBTypeInfo.toBufferLayout} */
448
+ toBufferLayout(offset: number): UniformBufferLayout;
449
+ }
450
+ /**
451
+ * The texture type info
452
+ * @public
453
+ */
454
+ declare class PBTextureTypeInfo extends PBTypeInfo<TextureTypeDetail> {
455
+ constructor(textureType: PBTextureType, texelFormat?: TextureFormat, readable?: boolean, writable?: boolean);
456
+ /** Get the texture type */
457
+ get textureType(): PBTextureType;
458
+ /** Get texture format if this is a storage texture */
459
+ get storageTexelFormat(): TextureFormat;
460
+ /** Returns true if this is a readable storage texture type */
461
+ get readable(): boolean;
462
+ /** Returns true if this is a writable storage texture type */
463
+ get writable(): boolean;
464
+ /** Returns true if this is a 2D texture type */
465
+ is2DTexture(): boolean;
466
+ /** Returns true if this is a 3D texture type */
467
+ is3DTexture(): boolean;
468
+ /** Returns true if this is a cube texture type */
469
+ isCubeTexture(): boolean;
470
+ /** Returns true if this is an array texture type */
471
+ isArrayTexture(): boolean;
472
+ /** Returns true if this is a storage texture type */
473
+ isStorageTexture(): boolean;
474
+ /** Return s true if this is a depth texture type */
475
+ isDepthTexture(): boolean;
476
+ /** Returns true if this is a multisampled texture type */
477
+ isMultisampledTexture(): boolean;
478
+ /** Returns true if this is an external texture type */
479
+ isExternalTexture(): boolean;
480
+ /** Returns true if the texture format is of type integer */
481
+ isIntTexture(): boolean;
482
+ /** Returns true if the texture format is of type unsigned integer */
483
+ isUIntTexture(): boolean;
484
+ /** {@inheritDoc PBTypeInfo.toBufferLayout} */
485
+ toBufferLayout(offset: number): UniformBufferLayout;
486
+ }
487
+ /**
488
+ * The function type info
489
+ * @public
490
+ */
491
+ declare class PBFunctionTypeInfo extends PBTypeInfo<FunctionTypeDetail> {
492
+ constructor(name: string, returnType: PBTypeInfo, argTypes: {
493
+ type: PBTypeInfo;
494
+ byRef?: boolean;
495
+ }[]);
496
+ /** Get name of the function */
497
+ get name(): string;
498
+ /** Get return type of the function */
499
+ get returnType(): PBTypeInfo;
500
+ /** Get all the argument types for this function */
501
+ get argTypes(): {
502
+ type: PBTypeInfo;
503
+ byRef?: boolean;
504
+ }[];
505
+ /** Get hash for parameter types */
506
+ get argHash(): string;
507
+ /** {@inheritDoc PBTypeInfo.toBufferLayout} */
508
+ toBufferLayout(offset: number): UniformBufferLayout;
509
+ }
510
+
511
+ /**
512
+ * Vertex buffer information
513
+ * @public
514
+ */
515
+ type VertexBufferInfo = {
516
+ buffer: StructuredBuffer;
517
+ offset: number;
518
+ stride: number;
519
+ drawOffset: number;
520
+ type: PBPrimitiveTypeInfo;
521
+ stepMode: VertexStepMode;
522
+ };
523
+ /**
524
+ * The vertex data class
525
+ * @public
526
+ */
527
+ declare class VertexData {
528
+ constructor();
529
+ /**
530
+ * Creates a new instance of VertexData by copying from this object
531
+ * @returns New instance of VertexData
532
+ */
533
+ clone(): VertexData;
534
+ /** Vertex buffer information list */
535
+ get vertexBuffers(): VertexBufferInfo[];
536
+ /** Index buffer */
537
+ get indexBuffer(): IndexBuffer<unknown>;
538
+ /** Draw offset */
539
+ getDrawOffset(): number;
540
+ setDrawOffset(offset: number): void;
541
+ /**
542
+ * Gets the vertex buffer by specific vertex semantic
543
+ * @param semantic - The vertex semantic
544
+ * @returns Vertex buffer of the given semantic
545
+ */
546
+ getVertexBuffer(semantic: VertexSemantic): StructuredBuffer;
547
+ /**
548
+ * Gets the vertex buffer information by specific vertex semantic
549
+ * @param semantic - The vertex semantic
550
+ * @returns Vertex buffer information of the given semantic
551
+ */
552
+ getVertexBufferInfo(semantic: VertexSemantic): VertexBufferInfo;
553
+ /**
554
+ * Gets the index buffer
555
+ * @returns The index buffer
556
+ */
557
+ getIndexBuffer(): IndexBuffer;
558
+ /**
559
+ * Sets a vertex buffer
560
+ * @param buffer - The vertex buffer object
561
+ * @param stepMode - Step mode of the buffer
562
+ * @returns The buffer that was set
563
+ */
564
+ setVertexBuffer(buffer: StructuredBuffer, stepMode?: VertexStepMode): StructuredBuffer;
565
+ /**
566
+ * Removes a vertex buffer
567
+ * @param buffer - Vertex buffer to be removed
568
+ * @returns true if the buffer was successfully removed, otherwise false
569
+ */
570
+ removeVertexBuffer(buffer: StructuredBuffer): boolean;
571
+ /**
572
+ * Sets the index buffer
573
+ * @param buffer - Index buffer to be set
574
+ * @returns The index buffer that was set
575
+ */
576
+ setIndexBuffer(buffer: IndexBuffer): IndexBuffer;
577
+ }
578
+
579
+ /**
580
+ * The types of image element that can be uploaded to textures
581
+ * @public
582
+ */
583
+ type TextureImageElement = ImageBitmap | HTMLCanvasElement;
584
+ /**
585
+ * The vertex format types
586
+ * @public
587
+ */
588
+ type VertexAttribFormat = 'position_u8normx2' | 'position_u8normx4' | 'position_i8normx2' | 'position_i8normx4' | 'position_u16x2' | 'position_u16x4' | 'position_i16x2' | 'position_i16x4' | 'position_u16normx2' | 'position_u16normx4' | 'position_i16normx2' | 'position_i16normx4' | 'position_f16x2' | 'position_f16x4' | 'position_f32' | 'position_f32x2' | 'position_f32x3' | 'position_f32x4' | 'position_i32' | 'position_i32x2' | 'position_i32x3' | 'position_i32x4' | 'position_u32' | 'position_u32x2' | 'position_u32x3' | 'position_u32x4' | 'normal_f16x4' | 'normal_f32x3' | 'normal_f32x4' | 'diffuse_u8normx4' | 'diffuse_u16x4' | 'diffuse_u16normx4' | 'diffuse_f16x4' | 'diffuse_f32x3' | 'diffuse_f32x4' | 'diffuse_u32x3' | 'diffuse_u32x4' | 'tangent_f16x4' | 'tangent_f32x3' | 'tangent_f32x4' | 'tex0_u8normx2' | 'tex0_u8normx4' | 'tex0_i8normx2' | 'tex0_i8normx4' | 'tex0_u16x2' | 'tex0_u16x4' | 'tex0_i16x2' | 'tex0_i16x4' | 'tex0_u16normx2' | 'tex0_u16normx4' | 'tex0_i16normx2' | 'tex0_i16normx4' | 'tex0_f16x2' | 'tex0_f16x4' | 'tex0_f32' | 'tex0_f32x2' | 'tex0_f32x3' | 'tex0_f32x4' | 'tex0_i32' | 'tex0_i32x2' | 'tex0_i32x3' | 'tex0_i32x4' | 'tex0_u32' | 'tex0_u32x2' | 'tex0_u32x3' | 'tex0_u32x4' | 'tex1_u8normx2' | 'tex1_u8normx4' | 'tex1_i8normx2' | 'tex1_i8normx4' | 'tex1_u16x2' | 'tex1_u16x4' | 'tex1_i16x2' | 'tex1_i16x4' | 'tex1_u16normx2' | 'tex1_u16normx4' | 'tex1_i16normx2' | 'tex1_i16normx4' | 'tex1_f16x2' | 'tex1_f16x4' | 'tex1_f32' | 'tex1_f32x2' | 'tex1_f32x3' | 'tex1_f32x4' | 'tex1_i32' | 'tex1_i32x2' | 'tex1_i32x3' | 'tex1_i32x4' | 'tex1_u32' | 'tex1_u32x2' | 'tex1_u32x3' | 'tex1_u32x4' | 'tex2_u8normx2' | 'tex2_u8normx4' | 'tex2_i8normx2' | 'tex2_i8normx4' | 'tex2_u16x2' | 'tex2_u16x4' | 'tex2_i16x2' | 'tex2_i16x4' | 'tex2_u16normx2' | 'tex2_u16normx4' | 'tex2_i16normx2' | 'tex2_i16normx4' | 'tex2_f16x2' | 'tex2_f16x4' | 'tex2_f32' | 'tex2_f32x2' | 'tex2_f32x3' | 'tex2_f32x4' | 'tex2_i32' | 'tex2_i32x2' | 'tex2_i32x3' | 'tex2_i32x4' | 'tex2_u32' | 'tex2_u32x2' | 'tex2_u32x3' | 'tex2_u32x4' | 'tex3_u8normx2' | 'tex3_u8normx4' | 'tex3_i8normx2' | 'tex3_i8normx4' | 'tex3_u16x2' | 'tex3_u16x4' | 'tex3_i16x2' | 'tex3_i16x4' | 'tex3_u16normx2' | 'tex3_u16normx4' | 'tex3_i16normx2' | 'tex3_i16normx4' | 'tex3_f16x2' | 'tex3_f16x4' | 'tex3_f32' | 'tex3_f32x2' | 'tex3_f32x3' | 'tex3_f32x4' | 'tex3_i32' | 'tex3_i32x2' | 'tex3_i32x3' | 'tex3_i32x4' | 'tex3_u32' | 'tex3_u32x2' | 'tex3_u32x3' | 'tex3_u32x4' | 'tex4_u8normx2' | 'tex4_u8normx4' | 'tex4_i8normx2' | 'tex4_i8normx4' | 'tex4_u16x2' | 'tex4_u16x4' | 'tex4_i16x2' | 'tex4_i16x4' | 'tex4_u16normx2' | 'tex4_u16normx4' | 'tex4_i16normx2' | 'tex4_i16normx4' | 'tex4_f16x2' | 'tex4_f16x4' | 'tex4_f32' | 'tex4_f32x2' | 'tex4_f32x3' | 'tex4_f32x4' | 'tex4_i32' | 'tex4_i32x2' | 'tex4_i32x3' | 'tex4_i32x4' | 'tex4_u32' | 'tex4_u32x2' | 'tex4_u32x3' | 'tex4_u32x4' | 'tex5_u8normx2' | 'tex5_u8normx4' | 'tex5_i8normx2' | 'tex5_i8normx4' | 'tex5_u16x2' | 'tex5_u16x4' | 'tex5_i16x2' | 'tex5_i16x4' | 'tex5_u16normx2' | 'tex5_u16normx4' | 'tex5_i16normx2' | 'tex5_i16normx4' | 'tex5_f16x2' | 'tex5_f16x4' | 'tex5_f32' | 'tex5_f32x2' | 'tex5_f32x3' | 'tex5_f32x4' | 'tex5_i32' | 'tex5_i32x2' | 'tex5_i32x3' | 'tex5_i32x4' | 'tex5_u32' | 'tex5_u32x2' | 'tex5_u32x3' | 'tex5_u32x4' | 'tex6_u8normx2' | 'tex6_u8normx4' | 'tex6_i8normx2' | 'tex6_i8normx4' | 'tex6_u16x2' | 'tex6_u16x4' | 'tex6_i16x2' | 'tex6_i16x4' | 'tex6_u16normx2' | 'tex6_u16normx4' | 'tex6_i16normx2' | 'tex6_i16normx4' | 'tex6_f16x2' | 'tex6_f16x4' | 'tex6_f32' | 'tex6_f32x2' | 'tex6_f32x3' | 'tex6_f32x4' | 'tex6_i32' | 'tex6_i32x2' | 'tex6_i32x3' | 'tex6_i32x4' | 'tex6_u32' | 'tex6_u32x2' | 'tex6_u32x3' | 'tex6_u32x4' | 'tex7_u8normx2' | 'tex7_u8normx4' | 'tex7_i8normx2' | 'tex7_i8normx4' | 'tex7_u16x2' | 'tex7_u16x4' | 'tex7_i16x2' | 'tex7_i16x4' | 'tex7_u16normx2' | 'tex7_u16normx4' | 'tex7_i16normx2' | 'tex7_i16normx4' | 'tex7_f16x2' | 'tex7_f16x4' | 'tex7_f32' | 'tex7_f32x2' | 'tex7_f32x3' | 'tex7_f32x4' | 'tex7_i32' | 'tex7_i32x2' | 'tex7_i32x3' | 'tex7_i32x4' | 'tex7_u32' | 'tex7_u32x2' | 'tex7_u32x3' | 'tex7_u32x4' | 'blendweights_f16x4' | 'blendweights_f32x4' | 'blendindices_u16x4' | 'blendindices_f16x4' | 'blendindices_f32x4' | 'blendindices_u32x4';
589
+ /**
590
+ * The semantic type of vertex
591
+ * @public
592
+ */
593
+ type VertexSemantic = 'position' | 'normal' | 'diffuse' | 'tangent' | 'blendIndices' | 'blendWeights' | 'texCoord0' | 'texCoord1' | 'texCoord2' | 'texCoord3' | 'texCoord4' | 'texCoord5' | 'texCoord6' | 'texCoord7';
594
+ /**
595
+ * Options for creating vertex layout
596
+ * @public
597
+ */
598
+ type VertexLayoutOptions = {
599
+ /**
600
+ * vertex buffers in this vertex layout
601
+ */
602
+ vertexBuffers: {
603
+ /**
604
+ * vertex buffer object created by device
605
+ */
606
+ buffer: StructuredBuffer;
607
+ /**
608
+ * the vertex buffer step mode,
609
+ * value can be 'vertex' or 'instance', default is 'vertex'
610
+ */
611
+ stepMode?: VertexStepMode;
612
+ }[];
613
+ /**
614
+ * optional index buffer in this vertex layout
615
+ */
616
+ indexBuffer?: IndexBuffer;
617
+ };
618
+ /**
619
+ * Supported colorspace types for texture
620
+ * @public
621
+ */
622
+ type TextureColorSpace = 'srgb' | 'linear';
623
+ /**
624
+ * Buffer usage type
625
+ * @public
626
+ */
627
+ type BufferUsage = 'vertex' | 'index' | 'uniform' | 'read' | 'write';
628
+ /**
629
+ * Common options for createing texture or buffer
630
+ * @public
631
+ */
632
+ interface BaseCreationOptions {
633
+ /**
634
+ * Whether the object should be dynamic, default is false
635
+ */
636
+ dynamic?: boolean;
637
+ }
638
+ /**
639
+ * Options for creating texture
640
+ * @public
641
+ */
642
+ interface TextureCreationOptions extends BaseCreationOptions {
643
+ writable?: boolean;
644
+ texture?: BaseTexture;
645
+ samplerOptions?: SamplerOptions;
646
+ }
647
+ /**
648
+ * Options for creating gpu buffer
649
+ * @public
650
+ */
651
+ interface BufferCreationOptions extends BaseCreationOptions {
652
+ /** The buffer usage */
653
+ usage?: BufferUsage;
654
+ /** true if we are creating a storage buffer */
655
+ storage?: boolean;
656
+ /** Whether the object content should be managed, default true for vertex buffer of index buffer */
657
+ managed?: boolean;
658
+ }
659
+ /**
660
+ * The gpu resource usage flags
661
+ * @public
662
+ */
663
+ declare enum GPUResourceUsageFlags {
664
+ TF_LINEAR_COLOR_SPACE = 2,
665
+ TF_NO_MIPMAP = 4,
666
+ TF_WRITABLE = 8,
667
+ TF_NO_GC = 16,
668
+ BF_VERTEX = 32,
669
+ BF_INDEX = 64,
670
+ BF_READ = 128,
671
+ BF_WRITE = 256,
672
+ BF_UNIFORM = 512,
673
+ BF_STORAGE = 1024,
674
+ DYNAMIC = 2048,
675
+ MANAGED = 4096
676
+ }
677
+ /**
678
+ * Get vertex format by semantic and component type and component count
679
+ * @param semantic - The vertex semantic
680
+ * @param type - Data type of vertex component
681
+ * @param count - The count of vertex components
682
+ * @returns Vertex format
683
+ * @public
684
+ */
685
+ declare function getVertexAttribFormat(semantic: VertexSemantic, type: DataType, count: number): VertexAttribFormat;
686
+ /**
687
+ * Get the length of a vertex buffer by specified structure type of the vertex buffer
688
+ * @param vertexBufferType - The structure type of the vertex buffer
689
+ * @returns The length of the vertex buffer
690
+ * @public
691
+ */
692
+ declare function getVertexBufferLength(vertexBufferType: PBStructTypeInfo): number;
693
+ /**
694
+ * Get byte stride of a vertex buffer by specified structure type of the vertex buffer
695
+ * @param vertexBufferType - The structure type of the vertex buffer
696
+ * @returns The byte stride of the vertex buffer
697
+ * @public
698
+ */
699
+ declare function getVertexBufferStride(vertexBufferType: PBStructTypeInfo): number;
700
+ /**
701
+ * Get primitive type of a vertex attribute by specified vertex semantic
702
+ * @param vertexBufferType - The structure type of the vertex buffer
703
+ * @param semantic - The vertex semantic
704
+ * @returns - The primitive type of the vertex attribute
705
+ * @public
706
+ */
707
+ declare function getVertexBufferAttribTypeBySemantic(vertexBufferType: PBStructTypeInfo, semantic: VertexSemantic): PBPrimitiveTypeInfo;
708
+ /**
709
+ * Get primitive type of a vertex attribute by specified vertex attribute index
710
+ * @param vertexBufferType - The structure type of the vertex buffer
711
+ * @param semantic - The vertex attribute index
712
+ * @returns - The primitive type of the vertex attribute
713
+ * @public
714
+ */
715
+ declare function getVertexBufferAttribType(vertexBufferType: PBStructTypeInfo, attrib: number): PBPrimitiveTypeInfo;
716
+ /**
717
+ * Get the structure type of a vertex buffer by specified vertex attribute formats and the length of the vertex buffer
718
+ * @param length - The length of the vertex buffer
719
+ * @param attributes - The vertex attributes
720
+ * @returns The structure type of the vertex buffer
721
+ * @public
722
+ */
723
+ declare function makeVertexBufferType(length: number, ...attributes: VertexAttribFormat[]): PBStructTypeInfo;
724
+ /**
725
+ * Vertex step mode.
726
+ * @public
727
+ */
728
+ type VertexStepMode = 'vertex' | 'instance';
729
+ /**
730
+ * Vertex semantic list
731
+ * @public
732
+ */
733
+ declare const semanticList: string[];
734
+ /**
735
+ * A data structure that holds the texture data of a mipmap level
736
+ * @public
737
+ */
738
+ interface TextureMipmapLevelData {
739
+ /** The texture data */
740
+ data: TypedArray;
741
+ /** Width of the mipmap level */
742
+ width: number;
743
+ /** Height of the mipmap level */
744
+ height: number;
745
+ }
746
+ /**
747
+ * A data structure that holds the texture data of all mipmap levels
748
+ * @public
749
+ */
750
+ interface TextureMipmapData {
751
+ /** Texture width of mipmap level 0 */
752
+ width: number;
753
+ /** Texture height of mipmap level 0 */
754
+ height: number;
755
+ /** Texture depth of mipmap level 0 */
756
+ depth: number;
757
+ /** true if it holds texture data for cube texture */
758
+ isCubemap: boolean;
759
+ /** true if it holds texture data for 3d texture */
760
+ isVolume: boolean;
761
+ /** true if it holds texture array */
762
+ isArray: boolean;
763
+ /** true if the texture data are in compressed format */
764
+ isCompressed: boolean;
765
+ /** The array size if it holds texture data for array texture */
766
+ arraySize: number;
767
+ /** How many mipmap levels in the texture data */
768
+ mipLevels: number;
769
+ /** The texture format */
770
+ format: TextureFormat;
771
+ /** The mipmap level datas */
772
+ mipDatas: TextureMipmapLevelData[][];
773
+ }
774
+ /**
775
+ * Frame buffer texture attachment information
776
+ * @public
777
+ */
778
+ interface FrameBufferTextureAttachment {
779
+ /** Texture for this attachment */
780
+ texture?: BaseTexture;
781
+ /** The attached face index for cube texture */
782
+ face?: number;
783
+ /** The layer index for array texture */
784
+ layer?: number;
785
+ /** Which mipmap level is currently attached */
786
+ level?: number;
787
+ /** Whether automatically generate mipmaps for color attachments */
788
+ generateMipmaps?: boolean;
789
+ }
790
+ /**
791
+ * The frame buffer creation options
792
+ * @public
793
+ */
794
+ interface FrameBufferOptions {
795
+ /** Sample count of the frame buffer */
796
+ sampleCount?: number;
797
+ /** Whether to ignore the depth stencil attachment when resolving multisample frame buffer */
798
+ ignoreDepthStencil?: boolean;
799
+ }
800
+ /**
801
+ * The uniform buffer layout
802
+ * @public
803
+ */
804
+ interface UniformBufferLayout {
805
+ /** Byte size of the uniform buffer */
806
+ byteSize: number;
807
+ /** Entries for the uniform buffer */
808
+ entries: UniformLayout[];
809
+ }
810
+ /**
811
+ * Layout of a uniform in a uniform buffer
812
+ * @public
813
+ */
814
+ interface UniformLayout {
815
+ /** Name of the uniform */
816
+ name: string;
817
+ /** Byte offset of the uniform buffer */
818
+ offset: number;
819
+ /** Byte size of the uniform */
820
+ byteSize: number;
821
+ /** The array length if the uniform is array type */
822
+ arraySize: number;
823
+ /** The primitive type of the uniform */
824
+ type: PBPrimitiveType;
825
+ /** Layout of the members if the uniform is struct type */
826
+ subLayout: UniformBufferLayout;
827
+ }
828
+ /**
829
+ * Binding layout of a uniform buffer or storage buffer
830
+ * @public
831
+ */
832
+ interface BufferBindingLayout {
833
+ /** The bind type */
834
+ type?: 'uniform' | 'storage' | 'read-only-storage';
835
+ /** Whether the buffer should be accessed by a dynamic offset */
836
+ hasDynamicOffset: boolean;
837
+ /** layout for the buffer */
838
+ uniformLayout: UniformBufferLayout;
839
+ /** minimum binding size of the buffer */
840
+ minBindingSize?: number;
841
+ }
842
+ /**
843
+ * Binding layout of a sampler
844
+ * @public
845
+ */
846
+ interface SamplerBindingLayout {
847
+ /** The bind type */
848
+ type: 'filtering' | 'non-filtering' | 'comparison';
849
+ }
850
+ /**
851
+ * Binding layout of a texture for sampling
852
+ * @public
853
+ */
854
+ interface TextureBindingLayout {
855
+ /** Sample type of the texture */
856
+ sampleType: 'float' | 'unfilterable-float' | 'depth' | 'sint' | 'uint';
857
+ /** View dimension for the texture */
858
+ viewDimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
859
+ /** Whether the textur is a multisampled texture */
860
+ multisampled: boolean;
861
+ /** name of the default sampler uniform when using WebGPU device */
862
+ autoBindSampler: string;
863
+ /** name of the default comparison sampler uniform when using WebGPU device */
864
+ autoBindSamplerComparison: string;
865
+ }
866
+ /**
867
+ * Binding layout of a storage texture
868
+ * @public
869
+ */
870
+ interface StorageTextureBindingLayout {
871
+ /** Access mode */
872
+ access: 'write-only';
873
+ /** The texture format */
874
+ format: TextureFormat;
875
+ /** View dimension */
876
+ viewDimension: '1d' | '2d';
877
+ }
878
+ /**
879
+ * Binding layout of an external texture
880
+ * @public
881
+ */
882
+ interface ExternalTextureBindingLayout {
883
+ /** name of the default sampler uniform when using WebGPU device */
884
+ autoBindSampler: string;
885
+ }
886
+ /**
887
+ * Information of bind group entries
888
+ * @public
889
+ */
890
+ interface BindGroupLayoutEntry {
891
+ /** The binding location */
892
+ binding: number;
893
+ /** Name of this binding resource */
894
+ name: string;
895
+ /** Visibility mask */
896
+ visibility: number;
897
+ /** Type of the binding resource */
898
+ type: PBTypeInfo;
899
+ /** Binding layout if the resource is a buffer */
900
+ buffer?: BufferBindingLayout;
901
+ /** Binding layout if the resource is a sampler */
902
+ sampler?: SamplerBindingLayout;
903
+ /** Binding layout if the resource is a texture for sampling */
904
+ texture?: TextureBindingLayout;
905
+ /** Binding layout if the resource is a storage texture */
906
+ storageTexture?: StorageTextureBindingLayout;
907
+ /** Binding layout if the resource is an external texture */
908
+ externalTexture?: ExternalTextureBindingLayout;
909
+ }
910
+ /**
911
+ * Defines how the resources bound in a {@link BindGroup}
912
+ * @public
913
+ */
914
+ interface BindGroupLayout {
915
+ /** Label of the layout */
916
+ label?: string;
917
+ /** The name map */
918
+ nameMap?: Record<string, string>;
919
+ /** A list of {@link BindGroupLayoutEntry} */
920
+ entries: BindGroupLayoutEntry[];
921
+ }
922
+ /**
923
+ * Binding point information for a uniform
924
+ * @public
925
+ */
926
+ interface BindPointInfo {
927
+ group: number;
928
+ binding: number;
929
+ type: PBTypeInfo;
930
+ }
931
+ /**
932
+ * Sampler creation options
933
+ * @public
934
+ */
935
+ interface SamplerOptions {
936
+ addressU?: TextureAddressMode;
937
+ addressV?: TextureAddressMode;
938
+ addressW?: TextureAddressMode;
939
+ magFilter?: TextureFilterMode;
940
+ minFilter?: TextureFilterMode;
941
+ mipFilter?: TextureFilterMode;
942
+ lodMin?: number;
943
+ lodMax?: number;
944
+ compare?: CompareFunc;
945
+ maxAnisotropy?: number;
946
+ }
947
+ /**
948
+ * Base class for a GPU object
949
+ * @public
950
+ */
951
+ interface GPUObject<T = unknown> extends IEventTarget<{
952
+ disposed: null;
953
+ }> {
954
+ /** The object was created by which device */
955
+ readonly device: AbstractDevice;
956
+ /** The internal GPU object */
957
+ readonly object: T;
958
+ /** unique id */
959
+ readonly uid: number;
960
+ readonly cid: number;
961
+ readonly disposed: boolean;
962
+ name: string;
963
+ restoreHandler: (tex: GPUObject) => Promise<void>;
964
+ isVertexLayout(): this is VertexLayout;
965
+ isFramebuffer(): this is FrameBuffer;
966
+ isSampler(): this is TextureSampler;
967
+ isTexture(): this is BaseTexture;
968
+ isTexture2D(): this is Texture2D;
969
+ isTexture2DArray(): this is Texture2DArray;
970
+ isTexture3D(): this is Texture3D;
971
+ isTextureCube(): this is TextureCube;
972
+ isTextureVideo(): this is TextureVideo;
973
+ isProgram(): this is GPUProgram;
974
+ isBuffer(): this is GPUDataBuffer;
975
+ isBindGroup(): this is BindGroup;
976
+ dispose(): void;
977
+ reload(): Promise<void>;
978
+ destroy(): void;
979
+ restore(): Promise<void>;
980
+ }
981
+ /**
982
+ * Abstract interface for texture sampler
983
+ * @public
984
+ */
985
+ interface TextureSampler<T = unknown> extends GPUObject<T> {
986
+ readonly addressModeU: TextureAddressMode;
987
+ readonly addressModeV: TextureAddressMode;
988
+ readonly addressModeW: TextureAddressMode;
989
+ readonly magFilter: TextureFilterMode;
990
+ readonly minFilter: TextureFilterMode;
991
+ readonly mipFilter: TextureFilterMode;
992
+ readonly lodMin: number;
993
+ readonly lodMax: number;
994
+ readonly compare: CompareFunc;
995
+ readonly maxAnisotropy: number;
996
+ }
997
+ /**
998
+ * Abstract interface for texture
999
+ * @public
1000
+ */
1001
+ interface BaseTexture<T = unknown> extends GPUObject<T> {
1002
+ readonly target: TextureType;
1003
+ readonly width: number;
1004
+ readonly height: number;
1005
+ readonly depth: number;
1006
+ readonly format: TextureFormat;
1007
+ readonly mipLevelCount: number;
1008
+ samplerOptions: SamplerOptions;
1009
+ init(): void;
1010
+ generateMipmaps(): void;
1011
+ isSRGBFormat(): boolean;
1012
+ isFloatFormat(): boolean;
1013
+ isIntegerFormat(): boolean;
1014
+ isSignedFormat(): boolean;
1015
+ isCompressedFormat(): boolean;
1016
+ isFilterable(): boolean;
1017
+ isDepth(): boolean;
1018
+ getDefaultSampler(comparison: boolean): TextureSampler;
1019
+ readPixels(x: number, y: number, w: number, h: number, faceOrLayer: number, mipLevel: number, buffer: TypedArray): Promise<void>;
1020
+ readPixelsToBuffer(x: number, y: number, w: number, h: number, faceOrLayer: number, mipLevel: number, buffer: GPUDataBuffer): void;
1021
+ }
1022
+ /**
1023
+ * Abstract interface for 2D texture
1024
+ * @public
1025
+ */
1026
+ interface Texture2D<T = unknown> extends BaseTexture<T> {
1027
+ update(data: TypedArray, xOffset: number, yOffset: number, width: number, height: number): void;
1028
+ updateFromElement(data: TextureImageElement, destX: number, destY: number, srcX: number, srcY: number, width: number, height: number): void;
1029
+ loadFromElement(element: TextureImageElement, sRGB: boolean, creationFlags?: number): void;
1030
+ createWithMipmapData(data: TextureMipmapData, sRGB: boolean, creationFlags?: number): void;
1031
+ }
1032
+ /**
1033
+ * Abstract interface for 2D array texture
1034
+ * @public
1035
+ */
1036
+ interface Texture2DArray<T = unknown> extends BaseTexture<T> {
1037
+ update(data: TypedArray, xOffset: number, yOffset: number, zOffset: number, width: number, height: number, depth: number): void;
1038
+ updateFromElement(data: TextureImageElement, xOffset: number, yOffset: number, layerIndex: number, x: number, y: number, width: number, height: number): void;
1039
+ createWithMipmapData(data: TextureMipmapData, creationFlags?: number): void;
1040
+ }
1041
+ /**
1042
+ * Abstract interface for 3D texture
1043
+ * @public
1044
+ */
1045
+ interface Texture3D<T = unknown> extends BaseTexture<T> {
1046
+ update(data: TypedArray, xOffset: number, yOffset: number, zOffset: number, width: number, height: number, depth: number): void;
1047
+ createWithMipmapData(data: TextureMipmapData, creationFlags?: number): void;
1048
+ }
1049
+ /**
1050
+ * Abstract interface for cube texture
1051
+ * @public
1052
+ */
1053
+ interface TextureCube<T = unknown> extends BaseTexture<T> {
1054
+ update(data: TypedArray, xOffset: number, yOffset: number, width: number, height: number, face: CubeFace): void;
1055
+ updateFromElement(data: TextureImageElement, xOffset: number, yOffset: number, face: number, x: number, y: number, width: number, height: number): void;
1056
+ createWithMipmapData(data: TextureMipmapData, sRGB: boolean, creationFlags?: number): void;
1057
+ }
1058
+ /**
1059
+ * Abstract interface for video texture
1060
+ * @public
1061
+ */
1062
+ interface TextureVideo<T = unknown> extends BaseTexture<T> {
1063
+ readonly source: HTMLVideoElement;
1064
+ updateVideoFrame(): boolean;
1065
+ }
1066
+ /**
1067
+ * Abstract interface for GPU buffer
1068
+ * @public
1069
+ */
1070
+ interface GPUDataBuffer<T = unknown> extends GPUObject<T> {
1071
+ readonly byteLength: number;
1072
+ readonly usage: number;
1073
+ bufferSubData(dstByteOffset: number, data: TypedArray, srcOffset?: number, srcLength?: number): void;
1074
+ getBufferSubData(dstBuffer?: Uint8Array, offsetInBytes?: number, sizeInBytes?: number): Promise<Uint8Array>;
1075
+ }
1076
+ /**
1077
+ * Abstract interface for index buffer
1078
+ * @public
1079
+ */
1080
+ interface IndexBuffer<T = unknown> extends GPUDataBuffer<T> {
1081
+ readonly indexType: PBPrimitiveTypeInfo;
1082
+ readonly length: number;
1083
+ }
1084
+ /**
1085
+ * Abstract interface for structured buffer
1086
+ * @public
1087
+ */
1088
+ interface StructuredBuffer<T = unknown> extends GPUDataBuffer<T> {
1089
+ structure: PBStructTypeInfo;
1090
+ set(name: string, value: StructuredValue): any;
1091
+ }
1092
+ /**
1093
+ * Abstract interface for vertex layout
1094
+ * @public
1095
+ */
1096
+ interface VertexLayout<T = unknown> extends GPUObject<T> {
1097
+ readonly vertexBuffers: {
1098
+ [semantic: number]: {
1099
+ buffer: StructuredBuffer;
1100
+ offset: number;
1101
+ };
1102
+ };
1103
+ readonly indexBuffer: IndexBuffer;
1104
+ setDrawOffset(buffer: StructuredBuffer, byteOffset: number): void;
1105
+ getVertexBuffer(semantic: VertexSemantic): StructuredBuffer;
1106
+ getVertexBufferInfo(semantic: VertexSemantic): VertexBufferInfo;
1107
+ getIndexBuffer(): IndexBuffer;
1108
+ bind(): void;
1109
+ draw(primitiveType: PrimitiveType, first: number, count: number): void;
1110
+ drawInstanced(primitiveType: PrimitiveType, first: number, count: number, numInstances: number): any;
1111
+ }
1112
+ /**
1113
+ * Abstract interface for frame buffer
1114
+ * @public
1115
+ */
1116
+ interface FrameBuffer<T = unknown> extends GPUObject<T> {
1117
+ getWidth(): number;
1118
+ getHeight(): number;
1119
+ getSampleCount(): number;
1120
+ setColorAttachmentCubeFace(index: number, face: CubeFace): void;
1121
+ setColorAttachmentMipLevel(index: number, level: number): void;
1122
+ setColorAttachmentLayer(index: number, layer: number): void;
1123
+ setColorAttachmentGenerateMipmaps(index: number, generateMipmaps: boolean): void;
1124
+ setDepthAttachmentCubeFace(face: CubeFace): void;
1125
+ setDepthAttachmentLayer(layer: number): void;
1126
+ getColorAttachments(): BaseTexture[];
1127
+ getDepthAttachment(): BaseTexture;
1128
+ bind(): boolean;
1129
+ unbind(): void;
1130
+ }
1131
+ /**
1132
+ * Abstract interface for GPU program
1133
+ * @public
1134
+ */
1135
+ interface GPUProgram<T = unknown> extends GPUObject<T> {
1136
+ readonly bindGroupLayouts: BindGroupLayout[];
1137
+ readonly type: 'render' | 'compute';
1138
+ getShaderSource(kind: ShaderKind): string;
1139
+ getCompileError(): string;
1140
+ getBindingInfo(name: string): BindPointInfo;
1141
+ createUniformBuffer(uniform: string): StructuredBuffer;
1142
+ use(): void;
1143
+ }
1144
+ /**
1145
+ * Type of values that can be set to a structured buffer
1146
+ * @public
1147
+ */
1148
+ type StructuredValue = number | TypedArray | VectorBase | {
1149
+ [name: string]: StructuredValue;
1150
+ };
1151
+ /**
1152
+ * Abstract interface for bind group
1153
+ * @public
1154
+ */
1155
+ interface BindGroup extends GPUObject<unknown> {
1156
+ getLayout(): BindGroupLayout;
1157
+ getBuffer(name: string): GPUDataBuffer;
1158
+ getTexture(name: string): BaseTexture;
1159
+ setBuffer(name: string, buffer: GPUDataBuffer): void;
1160
+ setValue(name: string, value: StructuredValue): any;
1161
+ setRawData(name: string, byteOffset: number, data: TypedArray, srcPos?: number, srcLength?: number): any;
1162
+ setTexture(name: string, texture: BaseTexture, sampler?: TextureSampler): any;
1163
+ setTextureView(name: string, value: BaseTexture, level?: number, face?: number, mipCount?: number, sampler?: TextureSampler): any;
1164
+ setSampler(name: string, sampler: TextureSampler): any;
1165
+ }
1166
+ /**
1167
+ * Creates the default name for the type of given gpu object
1168
+ * @param obj - The gpu object
1169
+ * @returns The default name
1170
+ * @public
1171
+ */
1172
+ declare function genDefaultName(obj: GPUObject): "unknown" | "sampler" | "texture_2d" | "texture_2darray" | "texture_3d" | "texture_cube" | "texture_video" | "buffer" | "framebuffer" | "program" | "vbo";
1173
+
1174
+ /** @public */
1175
+ interface ShaderExpTagRecord {
1176
+ [name: string]: ShaderExpTagValue;
1177
+ }
1178
+ /** @public */
1179
+ type ShaderExpTagValue = string[] | string | ShaderExpTagRecord;
1180
+ /**
1181
+ * type of a shader variable constructor
1182
+ * @public
1183
+ */
1184
+ type ShaderTypeFunc = {
1185
+ (...args: any[]): PBShaderExp;
1186
+ ptr: ShaderTypeFunc;
1187
+ [dim: number]: ShaderTypeFunc;
1188
+ };
1189
+ /**
1190
+ * Base class for proxiable object
1191
+ * @public
1192
+ */
1193
+ declare abstract class Proxiable<T> {
1194
+ constructor();
1195
+ get $thisProxy(): T;
1196
+ }
1197
+ /**
1198
+ * Base class for a expression in the shader
1199
+ * @public
1200
+ */
1201
+ declare class PBShaderExp extends Proxiable<PBShaderExp> {
1202
+ [name: string]: any;
1203
+ get $group(): number;
1204
+ set $group(val: number);
1205
+ /**
1206
+ * Point out that the variable should be in uniform address space
1207
+ * @param group - The bind group index
1208
+ * @returns self
1209
+ */
1210
+ uniform(group: number): PBShaderExp;
1211
+ /**
1212
+ * Point out that the variable should be an uniform buffer
1213
+ * @param group - The bind group index
1214
+ * @returns self
1215
+ */
1216
+ uniformBuffer(group: number): PBShaderExp;
1217
+ /**
1218
+ * Point out that the variable should be in workgroup address space
1219
+ *
1220
+ * @remarks
1221
+ * WebGPU device only
1222
+ *
1223
+ * @returns self
1224
+ */
1225
+ workgroup(): PBShaderExp;
1226
+ /**
1227
+ * Point out that the variable should be in storage address space
1228
+ * @param group - The bind group index
1229
+ * @returns self
1230
+ */
1231
+ storage(group: number): PBShaderExp;
1232
+ /**
1233
+ * Point out that the variable should be a storage buffer
1234
+ * @param group - The bind group index
1235
+ * @returns self
1236
+ */
1237
+ storageBuffer(group: number): PBShaderExp;
1238
+ inout(): PBShaderExp;
1239
+ out(): PBShaderExp;
1240
+ /**
1241
+ * Point out that the variable is a input vertex attribute
1242
+ * @param attr - The vertex semantic
1243
+ * @returns self
1244
+ */
1245
+ attrib(attr: VertexSemantic): PBShaderExp;
1246
+ /**
1247
+ * Create tags for the variable
1248
+ * @param args - tags
1249
+ * @returns self
1250
+ */
1251
+ tag(...args: ShaderExpTagValue[]): PBShaderExp;
1252
+ /**
1253
+ * Set sample type for the variable if the variable is of type texture
1254
+ * @param type - sample type
1255
+ * @returns self
1256
+ */
1257
+ sampleType(type: 'float' | 'unfilterable-float' | 'sint' | 'uint' | 'depth'): PBShaderExp;
1258
+ /**
1259
+ * Get element in the array by index
1260
+ * @param index - index of the element
1261
+ * @returns the element variable
1262
+ */
1263
+ at(index: number | PBShaderExp): PBShaderExp;
1264
+ /**
1265
+ * Set element in the array by index
1266
+ * @param index - index of the element
1267
+ * @param val - value to set
1268
+ */
1269
+ setAt(index: number | PBShaderExp, val: number | boolean | PBShaderExp): void;
1270
+ /**
1271
+ * Point out that the variable should be in high precision
1272
+ * @returns self
1273
+ */
1274
+ highp(): PBShaderExp;
1275
+ /**
1276
+ * Points out that the variable should be in medium precision
1277
+ * @returns self
1278
+ */
1279
+ mediump(): PBShaderExp;
1280
+ /**
1281
+ * Points out that the variable should be in low precision
1282
+ * @returns self
1283
+ */
1284
+ lowp(): PBShaderExp;
1285
+ /**
1286
+ * Determine if this variable is of vector type
1287
+ * @returns true if the variable is of vector type, otherwise false
1288
+ */
1289
+ isVector(): boolean;
1290
+ /**
1291
+ * Get vector component count of the variable if this variable is of vector type
1292
+ * @returns the vector component count
1293
+ */
1294
+ numComponents(): number;
1295
+ /**
1296
+ * Get type name of this variable
1297
+ * @returns The type name of this variable
1298
+ */
1299
+ getTypeName(): string;
1300
+ }
1301
+
1302
+ /**
1303
+ * Shader variable getter function type
1304
+ * @public
1305
+ */
1306
+ type PBReflectionTagGetter = (scope: PBGlobalScope) => PBShaderExp;
1307
+ /**
1308
+ * Reflection interface for program builder
1309
+ * @public
1310
+ */
1311
+ declare class PBReflection {
1312
+ constructor(builder: ProgramBuilder);
1313
+ /** Gets all the vertex attributes that was used by the program */
1314
+ get vertexAttributes(): number[];
1315
+ /**
1316
+ * Check if specified vertex attribute was used by the program
1317
+ * @param attrib - The vertex attribute to check
1318
+ */
1319
+ hasVertexAttribute(attrib: number): boolean;
1320
+ /**
1321
+ * Clear all contents
1322
+ */
1323
+ clear(): void;
1324
+ /**
1325
+ * Gets the variable that has tagged with given string
1326
+ * @param name - The tag string
1327
+ */
1328
+ tag(name: string): PBShaderExp;
1329
+ /**
1330
+ * Creates a new tag by specifying a function to get the tagged variable
1331
+ * @param name - The tag name
1332
+ * @param getter - The getter function
1333
+ */
1334
+ tag(name: string, getter: PBReflectionTagGetter): void;
1335
+ /**
1336
+ * Creates multiple tags from an object that contains the tag names and the getter functions
1337
+ * @param values - The object that contains the tag names and the getter functions
1338
+ */
1339
+ tag(values: Record<string, PBReflectionTagGetter>): void;
1340
+ /**
1341
+ * Gets the variable which is the vertex attribute of specified semantic
1342
+ * @param attrib - The vertex semantic
1343
+ */
1344
+ attribute(attrib: VertexSemantic): PBShaderExp;
1345
+ }
1346
+
1347
+ declare const StorageTextureFormatMap: {
1348
+ rgba8unorm: string;
1349
+ rgba8snorm: string;
1350
+ rgba8uint: string;
1351
+ rgba8sint: string;
1352
+ rgba16uint: string;
1353
+ rgba16sint: string;
1354
+ rgba16float: string;
1355
+ r32float: string;
1356
+ r32uint: string;
1357
+ r32sint: string;
1358
+ rg32float: string;
1359
+ rg32uint: string;
1360
+ rg32sint: string;
1361
+ rgba32float: string;
1362
+ rgba32uint: string;
1363
+ rgba32sint: string;
1364
+ };
1365
+ type StorageTextureConstructor = {
1366
+ [k in keyof typeof StorageTextureFormatMap]: (s?: string) => PBShaderExp;
1367
+ };
1368
+
1369
+ /**
1370
+ * Non-array value type of shader expression
1371
+ * @public
1372
+ */
1373
+ type ExpValueNonArrayType = number | boolean | PBShaderExp;
1374
+ /**
1375
+ * Value type for shader of shader expression
1376
+ * @public
1377
+ */
1378
+ type ExpValueType = ExpValueNonArrayType | Array<ExpValueType>;
1379
+ /**
1380
+ * Render program build options
1381
+ * @public
1382
+ */
1383
+ interface PBRenderOptions {
1384
+ /** program label for debugging */
1385
+ label?: string;
1386
+ /**
1387
+ * Vertex shader generator.
1388
+ * @param this - Global scope object of the vertex shader
1389
+ * @param pb - The program builder instance
1390
+ */
1391
+ vertex(this: PBGlobalScope, pb: ProgramBuilder): any;
1392
+ /**
1393
+ * Fragment shader generator.
1394
+ * @param this - Global scope object of the fragment shader
1395
+ * @param pb - The program builder instance
1396
+ */
1397
+ fragment(this: PBGlobalScope, pb: ProgramBuilder): any;
1398
+ }
1399
+ /**
1400
+ * Compute program build options
1401
+ * @public
1402
+ */
1403
+ interface PBComputeOptions {
1404
+ /** program label for debugging */
1405
+ label?: string;
1406
+ /** workgroup size */
1407
+ workgroupSize: [number, number, number];
1408
+ /** compute shader */
1409
+ compute(this: PBGlobalScope, pb: ProgramBuilder): any;
1410
+ }
1411
+ /**
1412
+ * The program builder interface
1413
+ * @public
1414
+ */
1415
+ interface ProgramBuilder {
1416
+ /** Get the device */
1417
+ getDevice(): AbstractDevice;
1418
+ /** Gets the global scope */
1419
+ getGlobalScope(): PBGlobalScope;
1420
+ /** Gets the current scope */
1421
+ getCurrentScope(): PBScope;
1422
+ /**
1423
+ * Query the global variable by the name
1424
+ * @param name - Name of the variable
1425
+ * @returns The variable or null if not exists
1426
+ */
1427
+ queryGlobal(name: string): PBShaderExp;
1428
+ /**
1429
+ * Query the global variable by the name
1430
+ * @param name - Name of the variable
1431
+ * @returns The variable or null if not exists
1432
+ */
1433
+ $query(name: string): PBShaderExp;
1434
+ /**
1435
+ * Generates shader codes for a render program
1436
+ * @param options - The build options
1437
+ * @returns a tuple made by vertex shader source, fragment shader source, bind group layouts and vertex attributes used, or null if build faild
1438
+ */
1439
+ buildRender(options: PBRenderOptions): readonly [string, string, BindGroupLayout[], number[]];
1440
+ /**
1441
+ * Generates shader code for a compute program
1442
+ * @param options - The build programs
1443
+ * @returns a tuple made by compute shader source and bind group layouts, or null if build failed
1444
+ */
1445
+ buildCompute(options: PBComputeOptions): readonly [string, BindGroupLayout[]];
1446
+ /**
1447
+ * Creates a shader program for render
1448
+ * @param options - The build options
1449
+ * @returns The created program or null if build failed
1450
+ */
1451
+ buildRenderProgram(options: PBRenderOptions): GPUProgram;
1452
+ /**
1453
+ * Creates a shader program for compute
1454
+ * @param options - The build options
1455
+ * @returns The created program or null if build failed
1456
+ */
1457
+ buildComputeProgram(options: PBComputeOptions): GPUProgram;
1458
+ /**
1459
+ * Creates a structure type variable
1460
+ * @param structName - Name of the structure type
1461
+ * @param instanceName - Name of the variable
1462
+ * @returns the created variable
1463
+ */
1464
+ struct(structName: string, instanceName: string): PBShaderExp;
1465
+ /**
1466
+ * Defines a structure type
1467
+ * @param members - Members of the structure
1468
+ * @param structName - Name of the type, if not given, the name will be automatically generated
1469
+ * @returns The structure type constructor
1470
+ */
1471
+ defineStruct(members: PBShaderExp[], structName?: string): ShaderTypeFunc;
1472
+ /**
1473
+ * Defines a structure type
1474
+ * @param structType - The structure type info
1475
+ * @returns The structure type constructor
1476
+ */
1477
+ defineStructByType(structType: PBStructTypeInfo): ShaderTypeFunc;
1478
+ /**
1479
+ * Creates a 'discard' statement
1480
+ */
1481
+ discard(): void;
1482
+ /**
1483
+ * Creates a function
1484
+ * @param name - Name of the function
1485
+ * @param params - Parameters of the function
1486
+ * @param body - The generator function
1487
+ */
1488
+ func(name: string, params: PBShaderExp[], body?: (this: PBFunctionScope) => void): void;
1489
+ /**
1490
+ * Create the main entry function of the shader
1491
+ * @param body - The shader generator function
1492
+ */
1493
+ main(body?: (this: PBFunctionScope) => void): void;
1494
+ /**
1495
+ * Create an 'AddressOf' expression for WGSL
1496
+ * @param ref - The reference variable
1497
+ * @returns the 'AddressOf' expression
1498
+ */
1499
+ addressOf(ref: PBShaderExp): PBShaderExp;
1500
+ /**
1501
+ * Creates a 'referenceOf' expression for WGSL
1502
+ * @param ptr - The pointer variable
1503
+ * @returns the 'referenceOf' expression
1504
+ */
1505
+ referenceOf(ptr: PBShaderExp): PBShaderExp;
1506
+ /** float type variable constructors */
1507
+ float: {
1508
+ (): PBShaderExp;
1509
+ (rhs: number): PBShaderExp;
1510
+ (rhs: boolean): PBShaderExp;
1511
+ (rhs: PBShaderExp): PBShaderExp;
1512
+ (name: string): PBShaderExp;
1513
+ ptr: ShaderTypeFunc;
1514
+ [dim: number]: ShaderTypeFunc;
1515
+ };
1516
+ /** int type variable constructors */
1517
+ int: {
1518
+ (): PBShaderExp;
1519
+ (rhs: number | boolean | PBShaderExp | string): PBShaderExp;
1520
+ ptr: ShaderTypeFunc;
1521
+ [dim: number]: ShaderTypeFunc;
1522
+ };
1523
+ /** uint type variable constructors */
1524
+ uint: {
1525
+ (): PBShaderExp;
1526
+ (rhs: number | boolean | PBShaderExp | string): PBShaderExp;
1527
+ ptr: ShaderTypeFunc;
1528
+ [dim: number]: ShaderTypeFunc;
1529
+ };
1530
+ /** boolean type variable constructors */
1531
+ bool: {
1532
+ (): PBShaderExp;
1533
+ (rhs: number | boolean | PBShaderExp | string): PBShaderExp;
1534
+ ptr: ShaderTypeFunc;
1535
+ [dim: number]: ShaderTypeFunc;
1536
+ };
1537
+ /** vec2 type variable constructors */
1538
+ vec2: {
1539
+ (): PBShaderExp;
1540
+ (rhs: number | PBShaderExp | string): PBShaderExp;
1541
+ (x: number | PBShaderExp, y: number | PBShaderExp): PBShaderExp;
1542
+ ptr: ShaderTypeFunc;
1543
+ [dim: number]: ShaderTypeFunc;
1544
+ };
1545
+ /** ivec2 type variable constructors */
1546
+ ivec2: {
1547
+ (): PBShaderExp;
1548
+ (rhs: number | PBShaderExp | string): PBShaderExp;
1549
+ (x: number | PBShaderExp, y: number | PBShaderExp): PBShaderExp;
1550
+ ptr: ShaderTypeFunc;
1551
+ [dim: number]: ShaderTypeFunc;
1552
+ };
1553
+ /** uvec2 type variable constructors */
1554
+ uvec2: {
1555
+ (): PBShaderExp;
1556
+ (rhs: number | PBShaderExp | string): PBShaderExp;
1557
+ (x: number | PBShaderExp, y: number | PBShaderExp): PBShaderExp;
1558
+ ptr: ShaderTypeFunc;
1559
+ [dim: number]: ShaderTypeFunc;
1560
+ };
1561
+ /** bvec2 type variable constructors */
1562
+ bvec2: {
1563
+ (): PBShaderExp;
1564
+ (rhs: number | boolean | PBShaderExp | string): PBShaderExp;
1565
+ (x: number | boolean | PBShaderExp, y: number | boolean | PBShaderExp): PBShaderExp;
1566
+ ptr: ShaderTypeFunc;
1567
+ [dim: number]: ShaderTypeFunc;
1568
+ };
1569
+ /** vec3 type variable constructors */
1570
+ vec3: {
1571
+ (): PBShaderExp;
1572
+ (name: string): PBShaderExp;
1573
+ (x: number | PBShaderExp): PBShaderExp;
1574
+ (x: number | PBShaderExp, y: number | PBShaderExp, z: number | PBShaderExp): PBShaderExp;
1575
+ (x: number | PBShaderExp, yz: PBShaderExp): PBShaderExp;
1576
+ (xy: PBShaderExp, z: number | PBShaderExp): PBShaderExp;
1577
+ ptr: ShaderTypeFunc;
1578
+ [dim: number]: ShaderTypeFunc;
1579
+ };
1580
+ /** ivec3 type variable constructors */
1581
+ ivec3: {
1582
+ (): PBShaderExp;
1583
+ (name: string): PBShaderExp;
1584
+ (x: number | PBShaderExp): PBShaderExp;
1585
+ (x: number | PBShaderExp, y: number | PBShaderExp, z: number | PBShaderExp): PBShaderExp;
1586
+ (x: number | PBShaderExp, yz: PBShaderExp): PBShaderExp;
1587
+ (xy: PBShaderExp, z: number | PBShaderExp): PBShaderExp;
1588
+ ptr: ShaderTypeFunc;
1589
+ [dim: number]: ShaderTypeFunc;
1590
+ };
1591
+ /** uvec3 type variable constructors */
1592
+ uvec3: {
1593
+ (): PBShaderExp;
1594
+ (name: string): PBShaderExp;
1595
+ (x: number | PBShaderExp): PBShaderExp;
1596
+ (x: number | PBShaderExp, y: number | PBShaderExp, z: number | PBShaderExp): PBShaderExp;
1597
+ (x: number | PBShaderExp, yz: PBShaderExp): PBShaderExp;
1598
+ (xy: PBShaderExp, z: number | PBShaderExp): PBShaderExp;
1599
+ ptr: ShaderTypeFunc;
1600
+ [dim: number]: ShaderTypeFunc;
1601
+ };
1602
+ /** bvec3 type variable constructors */
1603
+ bvec3: {
1604
+ (): PBShaderExp;
1605
+ (name: string): PBShaderExp;
1606
+ (x: boolean | PBShaderExp): PBShaderExp;
1607
+ (x: boolean | PBShaderExp, y: boolean | PBShaderExp, z: boolean | PBShaderExp): PBShaderExp;
1608
+ (x: boolean | PBShaderExp, yz: PBShaderExp): PBShaderExp;
1609
+ (xy: PBShaderExp, z: boolean | PBShaderExp): PBShaderExp;
1610
+ ptr: ShaderTypeFunc;
1611
+ [dim: number]: ShaderTypeFunc;
1612
+ };
1613
+ /** vec4 type variable constructors */
1614
+ vec4: {
1615
+ (): PBShaderExp;
1616
+ (name: string): PBShaderExp;
1617
+ (x: number | PBShaderExp): PBShaderExp;
1618
+ (x: number | PBShaderExp, y: number | PBShaderExp, z: number | PBShaderExp, w: number | PBShaderExp): PBShaderExp;
1619
+ (x: number | PBShaderExp, y: number | PBShaderExp, zw: PBShaderExp): PBShaderExp;
1620
+ (x: number | PBShaderExp, yz: PBShaderExp, w: number | PBShaderExp): PBShaderExp;
1621
+ (x: number | PBShaderExp, yzw: PBShaderExp): PBShaderExp;
1622
+ (xy: PBShaderExp, z: number | PBShaderExp, w: number | PBShaderExp): PBShaderExp;
1623
+ (xy: PBShaderExp, zw: PBShaderExp): PBShaderExp;
1624
+ (xyz: PBShaderExp, w: number | PBShaderExp): PBShaderExp;
1625
+ ptr: ShaderTypeFunc;
1626
+ [dim: number]: ShaderTypeFunc;
1627
+ };
1628
+ /** ivec4 type variable constructors */
1629
+ ivec4: {
1630
+ (): PBShaderExp;
1631
+ (name: string): PBShaderExp;
1632
+ (x: number | PBShaderExp): PBShaderExp;
1633
+ (x: number | PBShaderExp, y: number | PBShaderExp, z: number | PBShaderExp, w: number | PBShaderExp): PBShaderExp;
1634
+ (x: number | PBShaderExp, y: number | PBShaderExp, zw: PBShaderExp): PBShaderExp;
1635
+ (x: number | PBShaderExp, yz: PBShaderExp, w: number | PBShaderExp): PBShaderExp;
1636
+ (x: number | PBShaderExp, yzw: PBShaderExp): PBShaderExp;
1637
+ (xy: PBShaderExp, z: number | PBShaderExp, w: number | PBShaderExp): PBShaderExp;
1638
+ (xy: PBShaderExp, zw: PBShaderExp): PBShaderExp;
1639
+ (xyz: PBShaderExp, w: number | PBShaderExp): PBShaderExp;
1640
+ ptr: ShaderTypeFunc;
1641
+ [dim: number]: ShaderTypeFunc;
1642
+ };
1643
+ /** uvec4 type variable constructors */
1644
+ uvec4: {
1645
+ (): PBShaderExp;
1646
+ (name: string): PBShaderExp;
1647
+ (x: number | PBShaderExp): PBShaderExp;
1648
+ (x: number | PBShaderExp, y: number | PBShaderExp, z: number | PBShaderExp, w: number | PBShaderExp): PBShaderExp;
1649
+ (x: number | PBShaderExp, y: number | PBShaderExp, zw: PBShaderExp): PBShaderExp;
1650
+ (x: number | PBShaderExp, yz: PBShaderExp, w: number | PBShaderExp): PBShaderExp;
1651
+ (x: number | PBShaderExp, yzw: PBShaderExp): PBShaderExp;
1652
+ (xy: PBShaderExp, z: number | PBShaderExp, w: number | PBShaderExp): PBShaderExp;
1653
+ (xy: PBShaderExp, zw: PBShaderExp): PBShaderExp;
1654
+ (xyz: PBShaderExp, w: number | PBShaderExp): PBShaderExp;
1655
+ ptr: ShaderTypeFunc;
1656
+ [dim: number]: ShaderTypeFunc;
1657
+ };
1658
+ /** bvec4 type variable constructors */
1659
+ bvec4: {
1660
+ (): PBShaderExp;
1661
+ (name: string): PBShaderExp;
1662
+ (x: boolean | PBShaderExp): PBShaderExp;
1663
+ (x: boolean | PBShaderExp, y: boolean | PBShaderExp, z: boolean | PBShaderExp, w: boolean | PBShaderExp): PBShaderExp;
1664
+ (x: boolean | PBShaderExp, y: boolean | PBShaderExp, zw: PBShaderExp): PBShaderExp;
1665
+ (x: boolean | PBShaderExp, yz: PBShaderExp, w: boolean | PBShaderExp): PBShaderExp;
1666
+ (x: boolean | PBShaderExp, yzw: PBShaderExp): PBShaderExp;
1667
+ (xy: PBShaderExp, z: boolean | PBShaderExp, w: boolean | PBShaderExp): PBShaderExp;
1668
+ (xy: PBShaderExp, zw: PBShaderExp): PBShaderExp;
1669
+ (xyz: PBShaderExp, w: boolean | PBShaderExp): PBShaderExp;
1670
+ ptr: ShaderTypeFunc;
1671
+ [dim: number]: ShaderTypeFunc;
1672
+ };
1673
+ /** mat2 type variable constructors */
1674
+ mat2: {
1675
+ (): PBShaderExp;
1676
+ (name: string): PBShaderExp;
1677
+ (m00: number | PBShaderExp, m01: number | PBShaderExp, m10: number | PBShaderExp, m11: number | PBShaderExp): PBShaderExp;
1678
+ (m0: PBShaderExp, m1: PBShaderExp): PBShaderExp;
1679
+ ptr: ShaderTypeFunc;
1680
+ [dim: number]: ShaderTypeFunc;
1681
+ };
1682
+ /** mat2x3 type variable constructors */
1683
+ mat2x3: {
1684
+ (): PBShaderExp;
1685
+ (name: string): PBShaderExp;
1686
+ (m00: number | PBShaderExp, m01: number | PBShaderExp, m02: number | PBShaderExp, m10: number | PBShaderExp, m11: number | PBShaderExp, m12: number | PBShaderExp): PBShaderExp;
1687
+ (m0: PBShaderExp, m1: PBShaderExp): PBShaderExp;
1688
+ ptr: ShaderTypeFunc;
1689
+ [dim: number]: ShaderTypeFunc;
1690
+ };
1691
+ /** mat2x4 type variable constructors */
1692
+ mat2x4: {
1693
+ (): PBShaderExp;
1694
+ (name: string): PBShaderExp;
1695
+ (m00: number | PBShaderExp, m01: number | PBShaderExp, m02: number | PBShaderExp, m03: number | PBShaderExp, m10: number | PBShaderExp, m11: number | PBShaderExp, m12: number | PBShaderExp, m13: number | PBShaderExp): PBShaderExp;
1696
+ (m0: PBShaderExp, m1: PBShaderExp): PBShaderExp;
1697
+ ptr: ShaderTypeFunc;
1698
+ [dim: number]: ShaderTypeFunc;
1699
+ };
1700
+ /** mat3 type variable constructors */
1701
+ mat3: {
1702
+ (): PBShaderExp;
1703
+ (name: string): PBShaderExp;
1704
+ (m00: number | PBShaderExp, m01: number | PBShaderExp, m02: number | PBShaderExp, m10: number | PBShaderExp, m11: number | PBShaderExp, m12: number | PBShaderExp, m20: number | PBShaderExp, m21: number | PBShaderExp, m22: number | PBShaderExp): PBShaderExp;
1705
+ (m0: PBShaderExp, m1: PBShaderExp, m2: PBShaderExp): PBShaderExp;
1706
+ ptr: ShaderTypeFunc;
1707
+ [dim: number]: ShaderTypeFunc;
1708
+ };
1709
+ /** mat3x2 type variable constructors */
1710
+ mat3x2: {
1711
+ (): PBShaderExp;
1712
+ (name: string): PBShaderExp;
1713
+ (m00: number | PBShaderExp, m01: number | PBShaderExp, m10: number | PBShaderExp, m11: number | PBShaderExp, m20: number | PBShaderExp, m21: number | PBShaderExp): PBShaderExp;
1714
+ (m0: PBShaderExp, m1: PBShaderExp, m2: PBShaderExp): PBShaderExp;
1715
+ ptr: ShaderTypeFunc;
1716
+ [dim: number]: ShaderTypeFunc;
1717
+ };
1718
+ /** mat3x4 type variable constructors */
1719
+ mat3x4: {
1720
+ (): PBShaderExp;
1721
+ (name: string): PBShaderExp;
1722
+ (m00: number | PBShaderExp, m01: number | PBShaderExp, m02: number | PBShaderExp, m03: number | PBShaderExp, m10: number | PBShaderExp, m11: number | PBShaderExp, m12: number | PBShaderExp, m13: number | PBShaderExp, m20: number | PBShaderExp, m21: number | PBShaderExp, m22: number | PBShaderExp, m23: number | PBShaderExp): PBShaderExp;
1723
+ (m0: PBShaderExp, m1: PBShaderExp, m2: PBShaderExp): PBShaderExp;
1724
+ ptr: ShaderTypeFunc;
1725
+ [dim: number]: ShaderTypeFunc;
1726
+ };
1727
+ /** mat4 type variable constructors */
1728
+ mat4: {
1729
+ (): PBShaderExp;
1730
+ (name: string): PBShaderExp;
1731
+ (m00: number | PBShaderExp, m01: number | PBShaderExp, m02: number | PBShaderExp, m03: number | PBShaderExp, m10: number | PBShaderExp, m11: number | PBShaderExp, m12: number | PBShaderExp, m13: number | PBShaderExp, m20: number | PBShaderExp, m21: number | PBShaderExp, m22: number | PBShaderExp, m23: number | PBShaderExp, m30: number | PBShaderExp, m31: number | PBShaderExp, m32: number | PBShaderExp, m33: number | PBShaderExp): PBShaderExp;
1732
+ (m0: PBShaderExp, m1: PBShaderExp, m2: PBShaderExp, m3: PBShaderExp): PBShaderExp;
1733
+ ptr: ShaderTypeFunc;
1734
+ [dim: number]: ShaderTypeFunc;
1735
+ };
1736
+ /** mat4x2 type variable constructors */
1737
+ mat4x2: {
1738
+ (): PBShaderExp;
1739
+ (name: string): PBShaderExp;
1740
+ (m00: number | PBShaderExp, m01: number | PBShaderExp, m10: number | PBShaderExp, m11: number | PBShaderExp, m20: number | PBShaderExp, m21: number | PBShaderExp, m30: number | PBShaderExp, m31: number | PBShaderExp): PBShaderExp;
1741
+ (m0: PBShaderExp, m1: PBShaderExp, m2: PBShaderExp, m3: PBShaderExp): PBShaderExp;
1742
+ ptr: ShaderTypeFunc;
1743
+ [dim: number]: ShaderTypeFunc;
1744
+ };
1745
+ /** mat4x3 type variable constructors */
1746
+ mat4x3: {
1747
+ (): PBShaderExp;
1748
+ (name: string): PBShaderExp;
1749
+ (m00: number | PBShaderExp, m01: number | PBShaderExp, m02: number | PBShaderExp, m10: number | PBShaderExp, m11: number | PBShaderExp, m12: number | PBShaderExp, m20: number | PBShaderExp, m21: number | PBShaderExp, m22: number | PBShaderExp, m30: number | PBShaderExp, m31: number | PBShaderExp, m32: number | PBShaderExp): PBShaderExp;
1750
+ (m0: PBShaderExp, m1: PBShaderExp, m2: PBShaderExp, m3: PBShaderExp): PBShaderExp;
1751
+ ptr: ShaderTypeFunc;
1752
+ [dim: number]: ShaderTypeFunc;
1753
+ };
1754
+ /** tex1D type variable constructors */
1755
+ tex1D(rhs?: string): PBShaderExp;
1756
+ /** tex2D type variable constructors */
1757
+ tex2D(rhs?: string): PBShaderExp;
1758
+ /** tex3D type variable constructors */
1759
+ tex3D(rhs?: string): PBShaderExp;
1760
+ /** texCube type variable constructors */
1761
+ texCube(rhs?: string): PBShaderExp;
1762
+ /** texExternal type variable constructors */
1763
+ texExternal(rhs?: string): PBShaderExp;
1764
+ /** tex2DShadow type variable constructors */
1765
+ tex2DShadow(rhs?: string): PBShaderExp;
1766
+ /** texCubeShadow type variable constructors */
1767
+ texCubeShadow(rhs?: string): PBShaderExp;
1768
+ /** tex2DArray type variable constructors */
1769
+ tex2DArray(rhs?: string): PBShaderExp;
1770
+ /** tex2DArrayShadow type variable constructors */
1771
+ tex2DArrayShadow(rhs?: string): PBShaderExp;
1772
+ /** itex1D type variable constructors */
1773
+ itex1D(rhs?: string): PBShaderExp;
1774
+ /** itex2D type variable constructors */
1775
+ itex2D(rhs?: string): PBShaderExp;
1776
+ /** itex3D type variable constructors */
1777
+ itex3D(rhs?: string): PBShaderExp;
1778
+ /** itexCube type variable constructors */
1779
+ itexCube(rhs?: string): PBShaderExp;
1780
+ /** itex2DArray type variable constructors */
1781
+ itex2DArray(rhs?: string): PBShaderExp;
1782
+ /** utex1D type variable constructors */
1783
+ utex1D(rhs?: string): PBShaderExp;
1784
+ /** utex2D type variable constructors */
1785
+ utex2D(rhs?: string): PBShaderExp;
1786
+ /** utex3D type variable constructors */
1787
+ utex3D(rhs?: string): PBShaderExp;
1788
+ /** utexCube type variable constructors */
1789
+ utexCube(rhs?: string): PBShaderExp;
1790
+ /** utex2DArray type variable constructors */
1791
+ utex2DArray(rhs?: string): PBShaderExp;
1792
+ /** texStorage1D type variable constructors */
1793
+ texStorage1D: StorageTextureConstructor;
1794
+ /** texStorage2D type variable constructors */
1795
+ texStorage2D: StorageTextureConstructor;
1796
+ /** texStorage2DArray type variable constructors */
1797
+ texStorage2DArray: StorageTextureConstructor;
1798
+ /** texStorage3D type variable constructors */
1799
+ texStorage3D: StorageTextureConstructor;
1800
+ /** sampler type variable constructors */
1801
+ sampler(rhs?: string): PBShaderExp;
1802
+ /** samplerComparison type variable constructors */
1803
+ samplerComparison(rhs?: string): PBShaderExp;
1804
+ /** Same as radians builtin function in GLSL and WGSL */
1805
+ radians(val: number | PBShaderExp): PBShaderExp;
1806
+ /** Same as degrees builtin function in GLSL and WGSL */
1807
+ degrees(val: number | PBShaderExp): PBShaderExp;
1808
+ /** Same as sin builtin function in GLSL and WGSL */
1809
+ sin(val: number | PBShaderExp): PBShaderExp;
1810
+ /** Same as cos builtin function in GLSL and WGSL */
1811
+ cos(val: number | PBShaderExp): PBShaderExp;
1812
+ /** Same as tan builtin function in GLSL and WGSL */
1813
+ tan(val: number | PBShaderExp): PBShaderExp;
1814
+ /** Same as asin builtin function in GLSL and WGSL */
1815
+ asin(val: number | PBShaderExp): PBShaderExp;
1816
+ /** Same as acos builtin function in GLSL and WGSL */
1817
+ acos(val: number | PBShaderExp): PBShaderExp;
1818
+ /** Same as atan builtin function in GLSL and WGSL */
1819
+ atan(val: number | PBShaderExp): PBShaderExp;
1820
+ /** Same as atan builtin function in GLSL and atan2 builtin function in WGSL */
1821
+ atan2(y: number | PBShaderExp, x: number | PBShaderExp): PBShaderExp;
1822
+ /** Same as sinh builtin function in GLSL and WGSL */
1823
+ sinh(val: number | PBShaderExp): PBShaderExp;
1824
+ /** Same as cosh builtin function in GLSL and WGSL */
1825
+ cosh(val: number | PBShaderExp): PBShaderExp;
1826
+ /** Same as tanh builtin function in GLSL and WGSL */
1827
+ tanh(val: number | PBShaderExp): PBShaderExp;
1828
+ /** Same as asinh builtin function in GLSL and WGSL */
1829
+ asinh(val: number | PBShaderExp): PBShaderExp;
1830
+ /** Same as acosh builtin function in GLSL and WGSL */
1831
+ acosh(val: number | PBShaderExp): PBShaderExp;
1832
+ /** Same as atanh builtin function in GLSL and WGSL */
1833
+ atanh(val: number | PBShaderExp): PBShaderExp;
1834
+ /** Same as pow builtin function in GLSL and WGSL */
1835
+ pow(x: number | PBShaderExp, y: number | PBShaderExp): PBShaderExp;
1836
+ /** Same as exp builtin function in GLSL and WGSL */
1837
+ exp(val: number | PBShaderExp): PBShaderExp;
1838
+ /** Same as exp2 builtin function in GLSL and WGSL */
1839
+ exp2(val: number | PBShaderExp): PBShaderExp;
1840
+ /** Same as log builtin function in GLSL and WGSL */
1841
+ log(val: number | PBShaderExp): PBShaderExp;
1842
+ /** Same as log2 builtin function in GLSL and WGSL */
1843
+ log2(val: number | PBShaderExp): PBShaderExp;
1844
+ /** Same as sqrt builtin function in GLSL and WGSL */
1845
+ sqrt(val: number | PBShaderExp): PBShaderExp;
1846
+ /** Same as inversesqrt builtin function in GLSL and WGSL */
1847
+ inverseSqrt(val: number | PBShaderExp): PBShaderExp;
1848
+ /** Same as abs builtin function in GLSL and WGSL */
1849
+ abs(val: number | PBShaderExp): PBShaderExp;
1850
+ /** Same as sign builtin function in GLSL and WGSL */
1851
+ sign(val: number | PBShaderExp): PBShaderExp;
1852
+ /** Same as floor builtin function in GLSL and WGSL */
1853
+ floor(val: number | PBShaderExp): PBShaderExp;
1854
+ /** Same as ceil builtin function in GLSL and WGSL */
1855
+ ceil(val: number | PBShaderExp): PBShaderExp;
1856
+ /** Same as fract builtin function in GLSL and WGSL */
1857
+ fract(val: number | PBShaderExp): PBShaderExp;
1858
+ /** Same as mod builtin function in GLSL and WGSL */
1859
+ mod(x: number | PBShaderExp, y: number | PBShaderExp): PBShaderExp;
1860
+ /** Same as fma builtin function in WGSL, only valid for WebGPU device */
1861
+ fma(x: number | PBShaderExp, y: number | PBShaderExp, z: number | PBShaderExp): PBShaderExp;
1862
+ /** Same as round builtin function in WGSL, only valid for WebGPU device */
1863
+ round(val: number | PBShaderExp): PBShaderExp;
1864
+ /** Same as trunc builtin function in WGSL, only valid for WebGPU device */
1865
+ trunc(val: number | PBShaderExp): PBShaderExp;
1866
+ /** Same as min builtin function in GLSL and WGSL */
1867
+ min(x: number | PBShaderExp, y: number | PBShaderExp): PBShaderExp;
1868
+ /** Same as max builtin function in GLSL and WGSL */
1869
+ max(x: number | PBShaderExp, y: number | PBShaderExp): PBShaderExp;
1870
+ /** Same as clamp builtin function in GLSL and WGSL */
1871
+ clamp(x: number | PBShaderExp, y: number | PBShaderExp, z: number | PBShaderExp): PBShaderExp;
1872
+ /** Same as mix builtin function in GLSL and WGSL */
1873
+ mix(x: number | PBShaderExp, y: number | PBShaderExp, z: number | PBShaderExp): PBShaderExp;
1874
+ /** Same as step builtin function in GLSL and WGSL */
1875
+ step(x: number | PBShaderExp, y: number | PBShaderExp): PBShaderExp;
1876
+ /** Same as smoothstep builtin function in GLSL and WGSL */
1877
+ smoothStep(x: number | PBShaderExp, y: number | PBShaderExp, z: number | PBShaderExp): PBShaderExp;
1878
+ /** Same as isnan builtin function in GLSL, only valid for WebGL2 device */
1879
+ isnan(x: number | PBShaderExp): PBShaderExp;
1880
+ /** Same as isinf builtin function in GLSL, only valid for WebGL2 device */
1881
+ isinf(x: number | PBShaderExp): PBShaderExp;
1882
+ /** add two values */
1883
+ add_2(x: number | PBShaderExp, y: number | PBShaderExp): any;
1884
+ /** add a couple of values togeter */
1885
+ add(x: number | PBShaderExp, ...rest: (number | PBShaderExp)[]): any;
1886
+ /** subtract two values */
1887
+ sub(x: number | PBShaderExp, y: number | PBShaderExp): any;
1888
+ /** multiply two values */
1889
+ mul_2(x: number | PBShaderExp, y: number | PBShaderExp): any;
1890
+ /** multiply a couple of values togeter */
1891
+ mul(x: number | PBShaderExp, ...rest: (number | PBShaderExp)[]): any;
1892
+ /** divide the first number by the second number */
1893
+ div(x: number | PBShaderExp, y: number | PBShaderExp): any;
1894
+ /** Same as length builtin function in GLSL and WGSL */
1895
+ length(x: number | PBShaderExp): PBShaderExp;
1896
+ /** Same as distance builtin function in GLSL and WGSL */
1897
+ distance(x: number | PBShaderExp, y: number | PBShaderExp): PBShaderExp;
1898
+ /** Same as dot builtin function in GLSL and WGSL */
1899
+ dot(x: PBShaderExp, y: PBShaderExp): PBShaderExp;
1900
+ /** Same as cross builtin function in GLSL and WGSL */
1901
+ cross(x: PBShaderExp, y: PBShaderExp): PBShaderExp;
1902
+ /** Same as normalize builtin function in GLSL and WGSL. */
1903
+ normalize(x: PBShaderExp): PBShaderExp;
1904
+ /** Same as faceForward builtin function in WGSL, only valid for WebGPU device */
1905
+ faceForward(x: PBShaderExp, y: PBShaderExp, z: PBShaderExp): PBShaderExp;
1906
+ /** Same as reflect builtin function in GLSL and WGSL */
1907
+ reflect(x: PBShaderExp, y: PBShaderExp): PBShaderExp;
1908
+ /** Same as refract builtin function in GLSL and WGSL */
1909
+ refract(x: PBShaderExp, y: PBShaderExp, z: number | PBShaderExp): PBShaderExp;
1910
+ /** Same as frexp builtin function in WGSL, only valid for WebGPU device */
1911
+ frexp(x: number | PBShaderExp): PBShaderExp;
1912
+ /** Same as outerProduct builtin function in GLSL, only valid for WebGL2 device */
1913
+ outerProduct(x: PBShaderExp, y: PBShaderExp): PBShaderExp;
1914
+ /** Same as transpose builtin function in GLSL and WGSL, only valid for WebGL2 and WebGPU device */
1915
+ transpose(mat: PBShaderExp): PBShaderExp;
1916
+ /** Same as determinant builtin function in GLSL and WGSL, only valid for WebGL2 and WebGPU device */
1917
+ determinant(mat: PBShaderExp): PBShaderExp;
1918
+ /** Same as inverse builtin function in GLSL, only valid for WebGL2 device */
1919
+ inverse(mat: PBShaderExp): PBShaderExp;
1920
+ /** return true if x is less than y, otherwise false */
1921
+ lessThan(x: number | PBShaderExp, y: number | PBShaderExp): PBShaderExp;
1922
+ /** return true if x is less than or equals y, otherwise false, per component */
1923
+ lessThanEqual(x: number | PBShaderExp, y: number | PBShaderExp): PBShaderExp;
1924
+ /** return true if x is greater than y, otherwise false, per component */
1925
+ greaterThan(x: number | PBShaderExp, y: number | PBShaderExp): PBShaderExp;
1926
+ /** return true if x is greater than or equals y, otherwise false, per component */
1927
+ greaterThanEqual(x: number | PBShaderExp, y: number | PBShaderExp): PBShaderExp;
1928
+ /** return true if x equals y, otherwise false, per component */
1929
+ compEqual(x: PBShaderExp, y: PBShaderExp): PBShaderExp;
1930
+ /** return true if x is not equal to y, otherwise false, per component */
1931
+ compNotEqual(x: PBShaderExp, y: PBShaderExp): PBShaderExp;
1932
+ /** return true if x equals y, otherwise false */
1933
+ equal(x: PBShaderExp | number, y: PBShaderExp | number): PBShaderExp;
1934
+ /** return true if x is not equal to y, otherwise false */
1935
+ notEqual(x: PBShaderExp | number, y: PBShaderExp | number): PBShaderExp;
1936
+ /** return x && y */
1937
+ and_2(x: PBShaderExp | number | boolean, y: PBShaderExp | number | boolean): PBShaderExp;
1938
+ /** return x && y && ... */
1939
+ and(x: PBShaderExp | number | boolean, y: PBShaderExp | number | boolean, ...rest: (PBShaderExp | number | boolean)[]): any;
1940
+ /** return x & y, per component */
1941
+ compAnd(x: PBShaderExp | number, y: PBShaderExp | number): PBShaderExp;
1942
+ /** return x ^ y, per component */
1943
+ compXor(x: PBShaderExp | number, y: PBShaderExp | number): PBShaderExp;
1944
+ /** return x || y */
1945
+ or_2(x: PBShaderExp | boolean, y: PBShaderExp | boolean): PBShaderExp;
1946
+ /** return x || y */
1947
+ or(x: PBShaderExp | boolean, y: PBShaderExp | boolean, ...rest: (PBShaderExp | boolean)[]): PBShaderExp;
1948
+ /** return x || y, per component */
1949
+ compOr(x: PBShaderExp | number | boolean, y: PBShaderExp | number | boolean): PBShaderExp;
1950
+ /** check whether any element of a boolean vector is true */
1951
+ any(x: PBShaderExp): PBShaderExp;
1952
+ /** check whether all elements of a boolean vector are true */
1953
+ all(x: PBShaderExp): PBShaderExp;
1954
+ /** logically invert a boolean vector */
1955
+ not(x: boolean | PBShaderExp): PBShaderExp;
1956
+ /** return the negate of the given value */
1957
+ neg(x: number | PBShaderExp): PBShaderExp;
1958
+ /** shift arithmetic left, not valid for WebGL1 device */
1959
+ sal(a: number | PBShaderExp, b: number | PBShaderExp): any;
1960
+ /** shift arithmetic right, not valid for WebGL1 device */
1961
+ sar(a: number | PBShaderExp, b: number | PBShaderExp): any;
1962
+ /** Same as the arrayLength builtin function in WGSL, only valid for WebGPU device */
1963
+ arrayLength(x: PBShaderExp): PBShaderExp;
1964
+ /** Same as the select builtin function in WGSL, only valid for WebGPU device */
1965
+ select(x: number | PBShaderExp, y: number | PBShaderExp, cond: boolean | PBShaderExp): PBShaderExp;
1966
+ /** Same as floatBitsToInt builtin function in GLSL, only valid for WebGL2 device */
1967
+ floatBitsToInt(x: number | PBShaderExp): PBShaderExp;
1968
+ /** Same as floatBitsToUint builtin function in GLSL, only valid for WebGL2 device */
1969
+ floatBitsToUint(x: number | PBShaderExp): PBShaderExp;
1970
+ /** Same as intBitsToFloat builtin function in GLSL, only valid for WebGL2 device */
1971
+ intBitsToFloat(x: number | PBShaderExp): PBShaderExp;
1972
+ /** Same as uintBitsToFloat builtin function in GLSL, only valid for WebGL2 device */
1973
+ uintBitsToFloat(x: number | PBShaderExp): PBShaderExp;
1974
+ /** Same as pack4x8snorm builtin function in WGSL, only valid for WebGPU device */
1975
+ pack4x8snorm(x: PBShaderExp): PBShaderExp;
1976
+ /** Same as unpack4x8snorm builtin function in WGSL, only valid for WebGPU device */
1977
+ unpack4x8snorm(x: number | PBShaderExp): PBShaderExp;
1978
+ /** Same as pack4x8unorm builtin function in WGSL, only valid for WebGPU device */
1979
+ pack4x8unorm(x: PBShaderExp): PBShaderExp;
1980
+ /** Same as unpack4x8unorm builtin function in WGSL, only valid for WebGPU device */
1981
+ unpack4x8unorm(x: number | PBShaderExp): PBShaderExp;
1982
+ /** Same as pack2x16snom builtin function in WGSL, only valid for WebGPU device */
1983
+ pack2x16snorm(x: PBShaderExp): PBShaderExp;
1984
+ /** Same as unpack2x16snorm builtin function in WGSL, only valid for WebGPU device */
1985
+ unpack2x16snorm(x: number | PBShaderExp): PBShaderExp;
1986
+ /** Same as pack2x16unorm builtin function in WGSL, only valid for WebGPU device */
1987
+ pack2x16unorm(x: PBShaderExp): PBShaderExp;
1988
+ /** Same as unpack2x16unorm builtin function in WGSL, only valid for WebGPU device */
1989
+ unpack2x16unorm(x: number | PBShaderExp): PBShaderExp;
1990
+ /** Same as pack2x16float builtin function in WGSL, only valid for WebGPU device */
1991
+ pack2x16float(x: PBShaderExp): PBShaderExp;
1992
+ /** Same as unpack2x16float builtin function in WGSL, only valid for WebGPU device */
1993
+ unpack2x16float(x: number | PBShaderExp): PBShaderExp;
1994
+ /** Same as matrixCompMult builtin function in GLSL, only valid for WebGL/WebGL2 device */
1995
+ matrixCompMult(x: PBShaderExp, y: PBShaderExp): PBShaderExp;
1996
+ /** Same as dFdx builtin function in GLSL and dpdx builtin function in WGSL */
1997
+ dpdx(x: PBShaderExp): PBShaderExp;
1998
+ /** Same as dFdy builtin function in GLSL and dpdy builtin function in WGSL */
1999
+ dpdy(x: PBShaderExp): PBShaderExp;
2000
+ /** Same as fwidth builtin function in GLSL and WGSL */
2001
+ fwidth(x: PBShaderExp): PBShaderExp;
2002
+ /** Same as dFdx builtin function in GLSL and dpdxCoarse builtin function in WGSL */
2003
+ dpdxCoarse(x: PBShaderExp): PBShaderExp;
2004
+ /** Same as dFdx builtin function in GLSL and dpdxFine builtin function in WGSL */
2005
+ dpdxFine(x: PBShaderExp): PBShaderExp;
2006
+ /** Same as dFdy builtin function in GLSL and dpdyCoarse builtin function in WGSL */
2007
+ dpdyCoarse(x: PBShaderExp): PBShaderExp;
2008
+ /** Same as dFdy builtin function in GLSL and dpdyFine builtin function in WGSL */
2009
+ dpdyFine(x: PBShaderExp): PBShaderExp;
2010
+ /** Same as textureSize builtin function in GLSL and textureDimensions builtin function in WGSL, only valid for WebGL2 device and WebGPU device */
2011
+ textureDimensions(tex: PBShaderExp, level?: number | PBShaderExp): PBShaderExp;
2012
+ /** Same as textureGather builtin function in WGSL, only valid for WebGPU device */
2013
+ textureGather(tex: PBShaderExp, sampler: PBShaderExp, coords: PBShaderExp): PBShaderExp;
2014
+ /** Same as textureGather builtin function in WGSL, only valid for WebGPU device */
2015
+ textureGather(component: number | PBShaderExp, tex: PBShaderExp, sampler: PBShaderExp, coords: PBShaderExp): PBShaderExp;
2016
+ /** Same as textureGather builtin function in WGSL, only valid for WebGPU device */
2017
+ textureArrayGather(tex: PBShaderExp, sampler: PBShaderExp, coords: PBShaderExp, arrayIndex: number | PBShaderExp): PBShaderExp;
2018
+ /** Same as textureGather builtin function in WGSL, only valid for WebGPU device */
2019
+ textureArrayGather(component: number | PBShaderExp, tex: PBShaderExp, sampler: PBShaderExp, coords: PBShaderExp, arrayIndex: number | PBShaderExp): PBShaderExp;
2020
+ /** Same as textureGatherCompare builtin function in WGSL, only valid for WebGPU device */
2021
+ textureGatherCompare(tex: PBShaderExp, samplerCompare: PBShaderExp, coords: PBShaderExp, depthRef: number | PBShaderExp): PBShaderExp;
2022
+ /** Same as textureGatherCompare builtin function in WGSL, only valid for WebGPU device */
2023
+ textureArrayGatherCompare(tex: PBShaderExp, samplerCompare: PBShaderExp, coords: PBShaderExp, arrayIndex: number | PBShaderExp, depthRef: number | PBShaderExp): PBShaderExp;
2024
+ /** Same as texelFetch builtin function in GLSL and textureLoad builtin function in WGSL, only valid for WebGL2 and WebGPU device */
2025
+ textureLoad(tex: PBShaderExp, coords: number | PBShaderExp, levelOrSampleIndex: number | PBShaderExp): PBShaderExp;
2026
+ /** Same as texelFetch builtin function in GLSL and textureLoad builtin function in WGSL, only valid for WebGL2 and WebGPU device */
2027
+ textureArrayLoad(tex: PBShaderExp, coords: number | PBShaderExp, arrayIndex: number | PBShaderExp, level: number | PBShaderExp): PBShaderExp;
2028
+ /** Same as textureStore builtin function in WGSL, only valid for WebGPU device */
2029
+ textureStore(tex: PBShaderExp, coords: number | PBShaderExp, value: PBShaderExp): void;
2030
+ /** Same as textureStore builtin function in WGSL, only valid for WebGPU device */
2031
+ textureArrayStore(tex: PBShaderExp, coords: PBShaderExp, arrayIndex: number | PBShaderExp, value: PBShaderExp): void;
2032
+ /** Same as textureNumLayers builtin function in WGSL, only valid for WebGPU device */
2033
+ textureNumLayers(tex: PBShaderExp): PBShaderExp;
2034
+ /** Same as textureNumLevels builtin function in WGSL, only valid for WebGPU device */
2035
+ textureNumLevels(tex: PBShaderExp): PBShaderExp;
2036
+ /** Same as textureNumSamples builtin function in WGSL, only valid for WebGPU device */
2037
+ textureNumSamples(tex: PBShaderExp): PBShaderExp;
2038
+ /** Same as textureSample builtin function in WebGPU and texture/texture2D/textureCube builtin function in GLSL */
2039
+ textureSample(tex: PBShaderExp, coords: number | PBShaderExp): PBShaderExp;
2040
+ /** Same as textureSample builtin function in WebGPU and texture builtin function in GLSL, only valid for WebGL2 and WebGPU device */
2041
+ textureArraySample(tex: PBShaderExp, coords: PBShaderExp, arrayIndex: number | PBShaderExp): PBShaderExp;
2042
+ /** Same as textureSampleBias builtin function in WebGPU and texture/texture2D/textureCube builtin function in GLSL */
2043
+ textureSampleBias(tex: PBShaderExp, coords: PBShaderExp, bias: number | PBShaderExp): PBShaderExp;
2044
+ /** Same as textureSampleBias builtin function in WebGPU and texture builtin function in GLSL, only valid for WebGL2 and WebGPU device */
2045
+ textureArraySampleBias(tex: PBShaderExp, coords: PBShaderExp, arrayIndex: number | PBShaderExp, bias: number | PBShaderExp): PBShaderExp;
2046
+ /** Same as textureSampleCompare builtin function in WebGPU and texture builtin function in GLSL, only valid for WebGL2 and WebGPU device */
2047
+ textureSampleCompare(tex: PBShaderExp, coords: PBShaderExp, depthRef: number | PBShaderExp): PBShaderExp;
2048
+ /** Same as textureSampleCompare builtin function in WebGPU and texture builtin function in GLSL, only valid for WebGL2 and WebGPU device */
2049
+ textureArraySampleCompare(tex: PBShaderExp, coords: PBShaderExp, arrayIndex: number | PBShaderExp, depthRef: number | PBShaderExp): PBShaderExp;
2050
+ /** Same as textureSampleLevel builtin function in WebGPU and textureLod/texture2DLodExt/textureCubeLodExt builtin function in GLSL */
2051
+ textureSampleLevel(tex: PBShaderExp, coords: PBShaderExp): PBShaderExp;
2052
+ /** Same as textureSampleLevel builtin function in WebGPU and textureLod/texture2DLodExt/textureCubeLodExt builtin function in GLSL */
2053
+ textureSampleLevel(tex: PBShaderExp, coords: PBShaderExp, level: number | PBShaderExp): PBShaderExp;
2054
+ /** Same as textureSampleLevel builtin function in WebGPU and textureLod builtin function in GLSL, only valid for WebGL2 and WebGPU device */
2055
+ textureArraySampleLevel(tex: PBShaderExp, coords: PBShaderExp, arrayIndex: number | PBShaderExp, level: number | PBShaderExp): PBShaderExp;
2056
+ /** Same as textureSampleCompareLevel builtin function in WebGPU and texture/textureLod builtin function in GLSL, only valid for WebGL2 and WebGPU device */
2057
+ textureSampleCompareLevel(tex: PBShaderExp, coords: PBShaderExp, depthRef: number | PBShaderExp): PBShaderExp;
2058
+ /** Same as textureSampleCompareLevel builtin function in WebGPU and texture builtin function in GLSL, only valid for WebGL2 and WebGPU device */
2059
+ textureArraySampleCompareLevel(tex: PBShaderExp, coords: PBShaderExp, arrayIndex: number | PBShaderExp, depthRef: number | PBShaderExp): PBShaderExp;
2060
+ /** Same as textureSampleGrad builtin function in WebGPU and textureGrad/texture2DGradExt/textureCubeGradExt builtin function in GLSL */
2061
+ textureSampleGrad(tex: PBShaderExp, coords: PBShaderExp, ddx: PBShaderExp, ddy: PBShaderExp): PBShaderExp;
2062
+ /** Same as textureSampleGrad builtin function in WebGPU and textureGrad builtin function in GLSL, only valid for WebGL2 and WebGPU device */
2063
+ textureArraySampleGrad(tex: PBShaderExp, coords: PBShaderExp, arrayIndex: number | PBShaderExp, ddx: PBShaderExp, ddy: PBShaderExp): PBShaderExp;
2064
+ /** Same as storageBarrier builtin function in WebGPU, only valid for WebGPU device */
2065
+ storageBarrier(): void;
2066
+ /** Same as workgroupBarrier builtin function in WebGPU, only valid for WebGPU device */
2067
+ workgroupBarrier(): void;
2068
+ /** atomicLoad, only valid for WebGPU device */
2069
+ atomicLoad(ptr: PBShaderExp): any;
2070
+ /** atomicStore, only valid for WebGPU device */
2071
+ atomicStore(ptr: PBShaderExp, value: number | PBShaderExp): any;
2072
+ /** atomicAdd, only valid for WebGPU device */
2073
+ atomicAdd(ptr: PBShaderExp, value: number | PBShaderExp): PBShaderExp;
2074
+ /** atomicSub, only valid for WebGPU device */
2075
+ atomicSub(ptr: PBShaderExp, value: number | PBShaderExp): PBShaderExp;
2076
+ /** atomicMax, only valid for WebGPU device */
2077
+ atomicMax(ptr: PBShaderExp, value: number | PBShaderExp): PBShaderExp;
2078
+ /** atomicMin, only valid for WebGPU device */
2079
+ atomicMin(ptr: PBShaderExp, value: number | PBShaderExp): PBShaderExp;
2080
+ /** atomicAnd, only valid for WebGPU device */
2081
+ atomicAnd(ptr: PBShaderExp, value: number | PBShaderExp): PBShaderExp;
2082
+ /** atomicOr, only valid for WebGPU device */
2083
+ atomicOr(ptr: PBShaderExp, value: number | PBShaderExp): PBShaderExp;
2084
+ /** atomicXor, only valid for WebGPU device */
2085
+ atomicXor(ptr: PBShaderExp, value: number | PBShaderExp): PBShaderExp;
2086
+ }
2087
+ /**
2088
+ * The program builder class
2089
+ * @public
2090
+ */
2091
+ declare class ProgramBuilder {
2092
+ /**
2093
+ * Creates a program builder for given device
2094
+ * @param device - The device
2095
+ */
2096
+ constructor(device: AbstractDevice);
2097
+ /** Get last error */
2098
+ get lastError(): string;
2099
+ /** Current shader kind */
2100
+ get shaderKind(): ShaderKind;
2101
+ get emulateDepthClamp(): boolean;
2102
+ set emulateDepthClamp(val: boolean);
2103
+ /** Get the shader code reflection interface */
2104
+ getReflection(): PBReflection;
2105
+ }
2106
+ /**
2107
+ * Base class for scope of the shader program
2108
+ * @public
2109
+ */
2110
+ declare class PBScope extends Proxiable<PBScope> {
2111
+ [props: string]: any;
2112
+ /** Get the program builder */
2113
+ get $builder(): ProgramBuilder;
2114
+ /** Returns the scope of the builtin variables */
2115
+ get $builtins(): PBBuiltinScope;
2116
+ /** Returns the scope of the input variables */
2117
+ get $inputs(): PBInputScope;
2118
+ /** Returns the scope of the output variables */
2119
+ get $outputs(): PBOutputScope;
2120
+ /**
2121
+ * Get the input vertex attribute by specified semantic
2122
+ *
2123
+ * @remarks
2124
+ * Can only be called only in vertex shader
2125
+ *
2126
+ * @param semantic - The vertex semantic
2127
+ * @returns The input vertex attribute or null if not exists
2128
+ */
2129
+ $getVertexAttrib(semantic: VertexSemantic): PBShaderExp;
2130
+ /** Get the current local scope */
2131
+ get $l(): PBLocalScope;
2132
+ /** Get the global scope */
2133
+ get $g(): PBGlobalScope;
2134
+ /**
2135
+ * Query the global variable by the name
2136
+ * @param name - Name of the variable
2137
+ * @returns The variable or null if not exists
2138
+ */
2139
+ $query(name: string): PBShaderExp;
2140
+ }
2141
+ /**
2142
+ * The local scope of a shader
2143
+ * @public
2144
+ */
2145
+ declare class PBLocalScope extends PBScope {
2146
+ [props: string]: any;
2147
+ constructor(scope: PBScope);
2148
+ }
2149
+ /**
2150
+ * The builtin scope of a shader
2151
+ * @public
2152
+ */
2153
+ interface PBBuiltinScope {
2154
+ position: PBShaderExp;
2155
+ pointSize: PBShaderExp | number;
2156
+ fragDepth: PBShaderExp;
2157
+ readonly fragCoord: PBShaderExp;
2158
+ readonly frontFacing: PBShaderExp;
2159
+ readonly vertexIndex: PBShaderExp;
2160
+ readonly instanceIndex: PBShaderExp;
2161
+ readonly localInvocationId: PBShaderExp;
2162
+ readonly globalInvocationId: PBShaderExp;
2163
+ readonly workGroupId: PBShaderExp;
2164
+ readonly numWorkGroups: PBShaderExp;
2165
+ readonly sampleMaskIn: PBShaderExp;
2166
+ sampleMaskOut: PBShaderExp;
2167
+ readonly sampleIndex: PBShaderExp;
2168
+ }
2169
+ /**
2170
+ * The builtin scope of a shader
2171
+ * @public
2172
+ */
2173
+ declare class PBBuiltinScope extends PBScope {
2174
+ constructor();
2175
+ }
2176
+ /**
2177
+ * The input scope of a shader
2178
+ * @public
2179
+ */
2180
+ declare class PBInputScope extends PBScope {
2181
+ }
2182
+ /**
2183
+ * The output scope of a shader
2184
+ * @public
2185
+ */
2186
+ declare class PBOutputScope extends PBScope {
2187
+ constructor();
2188
+ }
2189
+ /**
2190
+ * The global scope of a shader
2191
+ * @public
2192
+ */
2193
+ declare class PBGlobalScope extends PBScope {
2194
+ }
2195
+ /**
2196
+ * Scope that is inside a function
2197
+ * @public
2198
+ */
2199
+ declare class PBInsideFunctionScope extends PBScope {
2200
+ /**
2201
+ * Creates a 'return' statement
2202
+ * @param retval - The return value
2203
+ */
2204
+ $return(retval?: ExpValueType): void;
2205
+ /**
2206
+ * Creates a new scope
2207
+ * @param body - Generator function for the scope
2208
+ * @returns The created scope
2209
+ */
2210
+ $scope(body: (this: PBInsideFunctionScope) => void): PBInsideFunctionScope;
2211
+ /**
2212
+ * Creates an 'if' statement
2213
+ * @param condition - Condition expression for the if statement
2214
+ * @param body - Generator function for the scope inside the if statement
2215
+ * @returns The scope inside the if statement
2216
+ */
2217
+ $if(condition: ExpValueNonArrayType, body: (this: PBIfScope) => void): PBIfScope;
2218
+ /**
2219
+ * Creates a select statement: condition ? first : second
2220
+ * @param condition - Condition expression
2221
+ * @param first - The first value
2222
+ * @param second - The second value
2223
+ * @returns The first value if condition evaluates to true, otherwise returns the second value
2224
+ */
2225
+ $choice(condition: ExpValueNonArrayType, first: ExpValueNonArrayType, second: ExpValueNonArrayType): PBShaderExp;
2226
+ /** Creates a 'break' statement */
2227
+ $break(): void;
2228
+ /** Creates a 'continue' statement */
2229
+ $continue(): void;
2230
+ /**
2231
+ * Creates a 'for' statement
2232
+ * @param counter - The repeat counter variable declaration
2233
+ * @param init - initial value of the repeat counter variable
2234
+ * @param end - end value of the counter exclusive
2235
+ * @param body - Generator function for the scope that inside the for statement
2236
+ */
2237
+ $for(counter: PBShaderExp, init: number | PBShaderExp, end: number | PBShaderExp, body: (this: PBForScope) => void): void;
2238
+ /**
2239
+ * Creates a 'do..while' statement
2240
+ * @param body - Generator function for the scope that inside the do..while statment
2241
+ * @returns The scope that inside the do..while statement
2242
+ */
2243
+ $do(body: (this: PBDoWhileScope) => void): PBDoWhileScope;
2244
+ /**
2245
+ * Creates a 'while' statement
2246
+ * @param condition - Condition expression for the while statement
2247
+ * @param body - Generator function for the scope that inside the while statement
2248
+ */
2249
+ $while(condition: ExpValueNonArrayType, body: (this: PBWhileScope) => void): void;
2250
+ }
2251
+ /**
2252
+ * Scope that insides a function
2253
+ * @public
2254
+ */
2255
+ declare class PBFunctionScope extends PBInsideFunctionScope {
2256
+ }
2257
+ /**
2258
+ * Scope that insides a while statement
2259
+ * @public
2260
+ */
2261
+ declare class PBWhileScope extends PBInsideFunctionScope {
2262
+ }
2263
+ /**
2264
+ * Scope that insides a do..while statement
2265
+ * @public
2266
+ */
2267
+ declare class PBDoWhileScope extends PBInsideFunctionScope {
2268
+ $while(condition: ExpValueNonArrayType): void;
2269
+ }
2270
+ /**
2271
+ * Scope that insides a for statement
2272
+ * @public
2273
+ */
2274
+ declare class PBForScope extends PBInsideFunctionScope {
2275
+ }
2276
+ /**
2277
+ * A naked scope
2278
+ * @public
2279
+ */
2280
+ declare class PBNakedScope extends PBInsideFunctionScope {
2281
+ }
2282
+ /**
2283
+ * Scope that insides an if statement
2284
+ * @public
2285
+ */
2286
+ declare class PBIfScope extends PBInsideFunctionScope {
2287
+ /**
2288
+ * Creates an 'else if' branch
2289
+ * @param condition - Condition expression for the else if branch
2290
+ * @param body - Generator function for the scope that insides the else if statement
2291
+ * @returns The scope that insides the else if statement
2292
+ */
2293
+ $elseif(condition: ExpValueNonArrayType, body: (this: PBIfScope) => void): PBIfScope;
2294
+ /**
2295
+ * Creates an 'else' branch
2296
+ * @param body - Generator function for the scope that insides the else statement
2297
+ */
2298
+ $else(body: (this: PBIfScope) => void): void;
2299
+ }
2300
+
2301
+ /**
2302
+ * The render states related to the fragment output
2303
+ * @public
2304
+ */
2305
+ interface ColorState {
2306
+ /** Creates a new ColorState by copying this one */
2307
+ clone(): ColorState;
2308
+ /** true if it is enabled to write to the red channel */
2309
+ redMask: boolean;
2310
+ /** true if it is enabled to write to the green channel */
2311
+ greenMask: boolean;
2312
+ /** true if it is enabled to write to the blue channel */
2313
+ blueMask: boolean;
2314
+ /** true if it is enabled to write to the alpha channel */
2315
+ alphaMask: boolean;
2316
+ /**
2317
+ * Set fragment write mask
2318
+ * @param r - true if writing to the red channel is allowed
2319
+ * @param g - true if writing to the green channel is allowed
2320
+ * @param b - true if writing to the blue channel is allowed
2321
+ * @param a - true if writing to the alpha channel is allowed
2322
+ */
2323
+ setColorMask(r: boolean, g: boolean, b: boolean, a: boolean): this;
2324
+ }
2325
+ /**
2326
+ * Type of the alpha blending equations
2327
+ * @public
2328
+ */
2329
+ type BlendEquation = 'add' | 'subtract' | 'reverse-subtract' | 'min' | 'max';
2330
+ /**
2331
+ * Type of the blending functions
2332
+ * @public
2333
+ */
2334
+ type BlendFunc = 'zero' | 'one' | 'src-alpha' | 'inv-src-alpha' | 'src-alpha-saturate' | 'dst-alpha' | 'inv-dst-alpha' | 'src-color' | 'inv-src-color' | 'dst-color' | 'inv-dst-color' | 'const-color' | 'inv-const-color' | 'const-alpha' | 'inv-const-alpha';
2335
+ /**
2336
+ * The render states related to alpha blending
2337
+ * @public
2338
+ */
2339
+ interface BlendingState {
2340
+ /** Creates a new BlendingState by copying this one */
2341
+ clone(): BlendingState;
2342
+ /** true if alpha blending is enabled */
2343
+ enabled: boolean;
2344
+ /** true if alpha to coverage is enabled */
2345
+ alphaToCoverageEnabled: boolean;
2346
+ /** The source blending factor for RGB channels */
2347
+ srcBlendRGB: BlendFunc;
2348
+ /** The destination blending factor for RGB channels */
2349
+ dstBlendRGB: BlendFunc;
2350
+ /** The source blending factor for alpha channel */
2351
+ srcBlendAlpha: BlendFunc;
2352
+ /** The destination blending factor for alpha channel */
2353
+ dstBlendAlpha: BlendFunc;
2354
+ /** The blending equation for RGB channels */
2355
+ rgbEquation: BlendEquation;
2356
+ /** The blending equation for alpha channel */
2357
+ alphaEquation: BlendEquation;
2358
+ /**
2359
+ * Enable or disable alpha blending
2360
+ * @param b - true if enable
2361
+ * @returns self
2362
+ */
2363
+ enable(b: boolean): this;
2364
+ /**
2365
+ * Enable or disable alpha to coverage
2366
+ * @param b - true if enable
2367
+ * @returns self
2368
+ */
2369
+ enableAlphaToCoverage(b: boolean): this;
2370
+ /**
2371
+ * Sets the blending function for both RGB channels and the alpha channel
2372
+ * @param src - The source blending function
2373
+ * @param dest - The destination blending function
2374
+ * @returns self
2375
+ */
2376
+ setBlendFunc(src: BlendFunc, dest: BlendFunc): this;
2377
+ /**
2378
+ * Sets the blending function for RGB channels
2379
+ * @param src - The source blending function
2380
+ * @param dest - The destination blending function
2381
+ * @returns self
2382
+ */
2383
+ setBlendFuncRGB(src: BlendFunc, dest: BlendFunc): this;
2384
+ /**
2385
+ * Sets the blending function for the alpha channel
2386
+ * @param src - The source blending function
2387
+ * @param dest - The destination blending function
2388
+ * @returns self
2389
+ */
2390
+ setBlendFuncAlpha(src: BlendFunc, dest: BlendFunc): this;
2391
+ /**
2392
+ * Sets the blending equations for RGB channels and the alpha channel
2393
+ * @param rgb - The blending equation for RGB channels
2394
+ * @param alpha - The blending equation for the alpha channel
2395
+ * @returns self
2396
+ */
2397
+ setBlendEquation(rgb: BlendEquation, alpha: BlendEquation): this;
2398
+ }
2399
+ /**
2400
+ * The face mode
2401
+ * @public
2402
+ */
2403
+ type FaceMode = 'none' | 'front' | 'back';
2404
+ /**
2405
+ * The type of face winding
2406
+ * @public
2407
+ */
2408
+ type FaceWinding = 'cw' | 'ccw';
2409
+ /**
2410
+ * The render states related to primitive rasterization
2411
+ * @public
2412
+ */
2413
+ interface RasterizerState {
2414
+ /** Creates a new RasterizerState by copying this one */
2415
+ clone(): RasterizerState;
2416
+ /** Triangle cull mode */
2417
+ cullMode: FaceMode;
2418
+ /** Depth clamp enabled */
2419
+ depthClampEnabled: boolean;
2420
+ /**
2421
+ * Sets the cull mode
2422
+ * @param mode - The cull mode to set
2423
+ * @returns self
2424
+ */
2425
+ setCullMode(mode: FaceMode): this;
2426
+ /**
2427
+ * Enable or disable depth clamp if supported
2428
+ * @param enable - Enables depth clamp if true, otherwise disable
2429
+ */
2430
+ enableDepthClamp(enable: boolean): this;
2431
+ }
2432
+ /**
2433
+ * The render states related to depth buffer
2434
+ * @public
2435
+ */
2436
+ interface DepthState {
2437
+ /** Creates a new DepthState by copying this one */
2438
+ clone(): DepthState;
2439
+ /** true if depth testing should be enabled */
2440
+ testEnabled: boolean;
2441
+ /** true if depth writing should be enabled */
2442
+ writeEnabled: boolean;
2443
+ /** The comparison function for depth testing */
2444
+ compareFunc: CompareFunc;
2445
+ /**
2446
+ * Enable or disable depth testing
2447
+ * @param b - true if enable
2448
+ * @returns self
2449
+ */
2450
+ enableTest(b: boolean): this;
2451
+ /**
2452
+ * Enable or disable depth writing
2453
+ * @param b - true if enable
2454
+ * @returns self
2455
+ */
2456
+ enableWrite(b: boolean): this;
2457
+ /**
2458
+ * Sets the comparison function for depth testing
2459
+ * @param func - The comparison function
2460
+ * @returns self
2461
+ */
2462
+ setCompareFunc(func: CompareFunc): this;
2463
+ }
2464
+ /**
2465
+ * Stencil operations
2466
+ * @public
2467
+ */
2468
+ type StencilOp = 'keep' | 'zero' | 'replace' | 'incr' | 'incr-wrap' | 'decr' | 'decr-wrap' | 'invert';
2469
+ /**
2470
+ * The render states related to the stencil buffer
2471
+ * @public
2472
+ */
2473
+ interface StencilState {
2474
+ /** Creates a new StencilState by copying this one */
2475
+ clone(): StencilState;
2476
+ /** true if stencil testing should be enabled */
2477
+ enabled: boolean;
2478
+ /** The function to use for front stencil state when the stencil test fails */
2479
+ failOp: StencilOp;
2480
+ /** The function to use for back stencil state when the stencil test fails of the back stencil state */
2481
+ failOpBack: StencilOp;
2482
+ /** The function to use for front stencil state when the stencil test passes but depth test fails */
2483
+ zFailOp: StencilOp;
2484
+ /** The function to use for back stencil state when the stencil test passes but depth test fails */
2485
+ zFailOpBack: StencilOp;
2486
+ /** The function to use for front stencil state when both the stencil test and the depth test pass */
2487
+ passOp: StencilOp;
2488
+ /** The function to use for back stencil state when both the stencil test and the depth test pass */
2489
+ passOpBack: StencilOp;
2490
+ /** The test function for front stencil state */
2491
+ func: CompareFunc;
2492
+ /** The test function for back stencil state */
2493
+ funcBack: CompareFunc;
2494
+ /** The reference value for the stencil test */
2495
+ ref: number;
2496
+ /** A bit mask to control which bits can be written while writing to the stencil buffer */
2497
+ writeMask: number;
2498
+ /** A bit mask that is used to AND the reference value and the stored stencil value */
2499
+ readMask: number;
2500
+ /**
2501
+ * Enables or disables the stencil test
2502
+ * @param b - true if stencil test should be enabled
2503
+ * @returns self
2504
+ */
2505
+ enable(b: boolean): this;
2506
+ /**
2507
+ * Sets the stencil operations for front stencil state
2508
+ * @param fail - The function to use when the stencil test fails
2509
+ * @param zfail - The function to use when the stencil test passes bug depth test fails
2510
+ * @param pass - The function to use when both the stencil test and the depth test pass
2511
+ * @returns self
2512
+ */
2513
+ setFrontOp(fail: StencilOp, zfail: StencilOp, pass: StencilOp): this;
2514
+ /**
2515
+ * Sets the stencil operations for back stencil state
2516
+ * @param fail - The function to use when the stencil test fails
2517
+ * @param zfail - The function to use when the stencil test passes bug depth test fails
2518
+ * @param pass - The function to use when both the stencil test and the depth test pass
2519
+ * @returns self
2520
+ */
2521
+ setBackOp(fail: StencilOp, zfail: StencilOp, pass: StencilOp): this;
2522
+ /**
2523
+ * Sets the compare function for front stencil state
2524
+ * @param func - The compare function
2525
+ * @returns self
2526
+ */
2527
+ setFrontCompareFunc(func: CompareFunc): this;
2528
+ /**
2529
+ * Sets the compare function for back stencil state
2530
+ * @param func - The compare function
2531
+ * @returns self
2532
+ */
2533
+ setBackCompareFunc(func: CompareFunc): this;
2534
+ /**
2535
+ * Sets the reference value for the stencil test
2536
+ * @param ref - The reference value
2537
+ * @returns self
2538
+ */
2539
+ setReference(ref: number): this;
2540
+ /**
2541
+ * Sets the bit mask for writing to the stencil buffer
2542
+ * @param mask - The write mask
2543
+ * @returns self
2544
+ */
2545
+ setWriteMask(mask: number): this;
2546
+ /**
2547
+ * Sets the bit mask for reading from the stencil buffer and reference value
2548
+ * @param mask - The read mask
2549
+ * @returns self
2550
+ */
2551
+ setReadMask(mask: number): this;
2552
+ }
2553
+ /**
2554
+ * Set of the render statements
2555
+ * @public
2556
+ */
2557
+ interface RenderStateSet {
2558
+ /** Creates a new RenderStateSet by copying this one */
2559
+ copyFrom(stateSet: RenderStateSet): void;
2560
+ /** Fragment output related render statements or null if the default values should be used */
2561
+ readonly colorState: ColorState;
2562
+ /** Alpha blending related render statements or null if the default values should be used */
2563
+ readonly blendingState: BlendingState;
2564
+ /** Rasterization related render statements or null if the default values should be used */
2565
+ readonly rasterizerState: RasterizerState;
2566
+ /** Depth buffer related render statements or null if the default values should be used */
2567
+ readonly depthState: DepthState;
2568
+ /** Stencil buffer related render statements or null if the default values should be used */
2569
+ readonly stencilState: StencilState;
2570
+ /**
2571
+ * Allocates a ColorState
2572
+ * @returns The created ColorState
2573
+ */
2574
+ useColorState(state?: ColorState): ColorState;
2575
+ /**
2576
+ * Deletes the ColorState that was allocated by {@link RenderStateSet.useColorState}, so that the default value will be used
2577
+ */
2578
+ defaultColorState(): void;
2579
+ /**
2580
+ * Allocates a BlendingState
2581
+ * @returns The created BlendingState
2582
+ */
2583
+ useBlendingState(state?: BlendingState): BlendingState;
2584
+ /**
2585
+ * Deletes the BlendingState that was allocated by {@link RenderStateSet.useBlendingState}, so that the default value will be used
2586
+ */
2587
+ defaultBlendingState(): void;
2588
+ /**
2589
+ * Allocates a RasterizerState
2590
+ * @returns The created RasterizerState
2591
+ */
2592
+ useRasterizerState(state?: RasterizerState): RasterizerState;
2593
+ /**
2594
+ * Deletes the RasterizerState that was allocated by {@link RenderStateSet.useRasterizerState}, so that the default value will be used
2595
+ */
2596
+ defaultRasterizerState(): void;
2597
+ /**
2598
+ * Allocates a DepthState
2599
+ * @returns The created DepthState
2600
+ */
2601
+ useDepthState(state?: DepthState): DepthState;
2602
+ /**
2603
+ * Deletes the DepthState that was allocated by {@link RenderStateSet.useDepthState}, so that the default value will be used
2604
+ */
2605
+ defaultDepthState(): void;
2606
+ /**
2607
+ * Allocates a StencilState
2608
+ * @returns The created StencilState
2609
+ */
2610
+ useStencilState(state?: StencilState): StencilState;
2611
+ /**
2612
+ * Deletes the StencilState that was allocated by {@link RenderStateSet.useStencilState}, so that the default value will be used
2613
+ */
2614
+ defaultStencilState(): void;
2615
+ /**
2616
+ * Applis the render statements to current device
2617
+ * @param force - Force applying all render statements
2618
+ */
2619
+ apply(force?: boolean): void;
2620
+ }
2621
+
2622
+ /**
2623
+ * The webgl context type
2624
+ * @public
2625
+ */
2626
+ type WebGLContext = WebGLRenderingContext | WebGL2RenderingContext;
2627
+ /**
2628
+ * The texture type
2629
+ * @public
2630
+ */
2631
+ type TextureType = '2d' | '3d' | 'cube' | '2darray';
2632
+ /**
2633
+ * The comparison function type
2634
+ * @public
2635
+ */
2636
+ type CompareFunc = 'always' | 'le' | 'ge' | 'lt' | 'gt' | 'eq' | 'ne' | 'never';
2637
+ /**
2638
+ * The texture address mode
2639
+ * @public
2640
+ */
2641
+ type TextureAddressMode = 'repeat' | 'mirrored-repeat' | 'clamp';
2642
+ /**
2643
+ * The texture filter mode
2644
+ * @public
2645
+ */
2646
+ type TextureFilterMode = 'none' | 'nearest' | 'linear';
2647
+ /**
2648
+ * Scalar data type
2649
+ * @public
2650
+ */
2651
+ type DataType = 'u8' | 'u8norm' | 'i8' | 'i8norm' | 'u16' | 'u16norm' | 'i16' | 'i16norm' | 'u32' | 'i32' | 'f16' | 'f32';
2652
+ /**
2653
+ * Texture format type
2654
+ * @public
2655
+ */
2656
+ type TextureFormat = 'unknown' | 'r8unorm' | 'r8snorm' | 'r16f' | 'r32f' | 'r8ui' | 'r8i' | 'r16ui' | 'r16i' | 'r32ui' | 'r32i' | 'rg8unorm' | 'rg8snorm' | 'rg16f' | 'rg32f' | 'rg8ui' | 'rg8i' | 'rg16ui' | 'rg16i' | 'rg32ui' | 'rg32i' | 'rgba8unorm' | 'rgba8unorm-srgb' | 'rgba8snorm' | 'bgra8unorm' | 'bgra8unorm-srgb' | 'rgba16f' | 'rgba32f' | 'rgba8ui' | 'rgba8i' | 'rgba16ui' | 'rgba16i' | 'rgba32ui' | 'rgba32i' | 'rg11b10uf' | 'd16' | 'd24' | 'd32f' | 'd24s8' | 'd32fs8' | 'dxt1' | 'dxt1-srgb' | 'dxt3' | 'dxt3-srgb' | 'dxt5' | 'dxt5-srgb';
2657
+ /**
2658
+ * Converts a non-sRGB texture format to the corresponding sRGB texture format
2659
+ * @param format - The texture format to be converted
2660
+ * @returns The sRGB texture format
2661
+ * @public
2662
+ */
2663
+ declare function linearTextureFormatToSRGB(format: TextureFormat): TextureFormat;
2664
+ /**
2665
+ * Check if a given texture format contains an alpha channel.
2666
+ * @param format - The texture format to be checked.
2667
+ * @returns true if the texture format contains an alpha channel, otherwise false
2668
+ * @public
2669
+ */
2670
+ declare function hasAlphaChannel(format: TextureFormat): boolean;
2671
+ /**
2672
+ * Check if a given texture format contains a red channel.
2673
+ * @param format - The texture format to be checked.
2674
+ * @returns true if the texture format contains a red channel, otherwise false
2675
+ * @public
2676
+ */
2677
+ declare function hasRedChannel(format: TextureFormat): boolean;
2678
+ /**
2679
+ * Check if a given texture format contains a green channel.
2680
+ * @param format - The texture format to be checked.
2681
+ * @returns true if the texture format contains a green channel, otherwise false
2682
+ * @public
2683
+ */
2684
+ declare function hasGreenChannel(format: TextureFormat): boolean;
2685
+ /**
2686
+ * Check if a given texture format contains a blue channel.
2687
+ * @param format - The texture format to be checked.
2688
+ * @returns true if the texture format contains a blue channel, otherwise false
2689
+ * @public
2690
+ */
2691
+ declare function hasBlueChannel(format: TextureFormat): boolean;
2692
+ /**
2693
+ * Check if a given texture format contains a depth channel.
2694
+ * @param format - The texture format to be checked.
2695
+ * @returns true if the texture format contains a depth channel, otherwise false
2696
+ * @public
2697
+ */
2698
+ declare function hasDepthChannel(format: TextureFormat): boolean;
2699
+ /**
2700
+ * Check if a given texture format contains a stencil channel.
2701
+ * @param format - The texture format to be checked.
2702
+ * @returns true if the texture format contains a stencil channel, otherwise false
2703
+ * @public
2704
+ */
2705
+ declare function hasStencilChannel(format: TextureFormat): boolean;
2706
+ /**
2707
+ * Check whether a given texture format is floating-point.
2708
+ * @param format - The texture format to be checked.
2709
+ * @returns true if the texture format is floating-point, otherwise false
2710
+ * @public
2711
+ */
2712
+ declare function isFloatTextureFormat(format: TextureFormat): boolean;
2713
+ /**
2714
+ * Check whether a given texture format is integer.
2715
+ * @param format - The texture format to be checked.
2716
+ * @returns true if the texture format is integer, otherwise false
2717
+ * @public
2718
+ */
2719
+ declare function isIntegerTextureFormat(format: TextureFormat): boolean;
2720
+ /**
2721
+ * Check whether a given texture format is signed.
2722
+ * @param format - The texture format to be checked.
2723
+ * @returns true if the texture format is signed, otherwise false
2724
+ * @public
2725
+ */
2726
+ declare function isSignedTextureFormat(format: TextureFormat): boolean;
2727
+ /**
2728
+ * Check whether a given texture format is a compressed format.
2729
+ * @param format - The texture format to be checked.
2730
+ * @returns true if the texture format is a compressed format, otherwise false
2731
+ * @public
2732
+ */
2733
+ declare function isCompressedTextureFormat(format: TextureFormat): boolean;
2734
+ /**
2735
+ * Check whether a given texture format is sRGB format.
2736
+ * @param format - The texture format to be checked.
2737
+ * @returns true if the texture format is sRGB format, otherwise false
2738
+ * @public
2739
+ */
2740
+ declare function isSRGBTextureFormat(format: TextureFormat): boolean;
2741
+ /**
2742
+ * Get block size of given texture format
2743
+ * @param format - The texture format
2744
+ * @returns The block size
2745
+ * @public
2746
+ */
2747
+ declare function getTextureFormatBlockSize(format: TextureFormat): number;
2748
+ /**
2749
+ * Get block width of given texture format
2750
+ * @param format - The texture format
2751
+ * @returns The block width
2752
+ * @public
2753
+ */
2754
+ declare function getTextureFormatBlockWidth(format: TextureFormat): number;
2755
+ /**
2756
+ * Get block height of given texture format
2757
+ * @param format - The texture format
2758
+ * @returns The block height
2759
+ * @public
2760
+ */
2761
+ declare function getTextureFormatBlockHeight(format: TextureFormat): number;
2762
+ /**
2763
+ * The primitive type
2764
+ * @public
2765
+ */
2766
+ type PrimitiveType = 'triangle-list' | 'triangle-strip' | 'triangle-fan' | 'line-list' | 'line-strip' | 'point-list';
2767
+ /**
2768
+ * Shader type
2769
+ * @public
2770
+ */
2771
+ declare enum ShaderType {
2772
+ Vertex = 1,
2773
+ Fragment = 2,
2774
+ Compute = 4
2775
+ }
2776
+ /**
2777
+ * Shader kind
2778
+ * @public
2779
+ */
2780
+ type ShaderKind = 'vertex' | 'fragment' | 'compute';
2781
+ /**
2782
+ * Frame information
2783
+ * @public
2784
+ */
2785
+ interface FrameInfo {
2786
+ /** counter of frames */
2787
+ frameCounter: number;
2788
+ /** timestamp of current frame, in milliseconds */
2789
+ frameTimestamp: number;
2790
+ /** time spent by the CPU from last frame, in milliseconds */
2791
+ elapsedTimeCPU: number;
2792
+ /** time spent by the GPU from last frame, in milliseconds */
2793
+ elapsedTimeGPU: number;
2794
+ /** time spent from last frame, in milliseconds */
2795
+ elapsedFrame: number;
2796
+ /** time spent from the first frame, in milliseconds */
2797
+ elapsedOverall: number;
2798
+ /** the FPS calculated for the last one second */
2799
+ FPS: number;
2800
+ /** How many draw calls were sent to the GPU in current frame */
2801
+ drawCalls: number;
2802
+ /** How many compute calls were sent to the GPU in current frame */
2803
+ computeCalls: number;
2804
+ }
2805
+ /**
2806
+ * List of all gpu objects
2807
+ * @public
2808
+ */
2809
+ interface GPUObjectList {
2810
+ /** list of textures */
2811
+ textures: BaseTexture[];
2812
+ /** list of samplers */
2813
+ samplers: TextureSampler[];
2814
+ /** list of buffers */
2815
+ buffers: GPUDataBuffer[];
2816
+ /** list of programs */
2817
+ programs: GPUProgram[];
2818
+ /** list of frame buffers */
2819
+ framebuffers: FrameBuffer[];
2820
+ /** list of vertex layouts */
2821
+ vertexArrayObjects: VertexLayout[];
2822
+ /** list of bind groups */
2823
+ bindGroups: BindGroup[];
2824
+ }
2825
+ /**
2826
+ * The device capabilities
2827
+ * @public
2828
+ */
2829
+ interface DeviceCaps {
2830
+ /** Miscellaneous capabilities */
2831
+ miscCaps: MiscCaps;
2832
+ /** Frame buffer related capabilities */
2833
+ framebufferCaps: FramebufferCaps;
2834
+ /** Shader related capabilities */
2835
+ shaderCaps: ShaderCaps;
2836
+ /** Texture related capabilities */
2837
+ textureCaps: TextureCaps;
2838
+ }
2839
+ /**
2840
+ * Frame buffer related capabilities of the device
2841
+ * @public
2842
+ */
2843
+ interface FramebufferCaps {
2844
+ /** The maximum number of framebuffer color attachment points */
2845
+ maxDrawBuffers: number;
2846
+ /** True if device supports multisampled frame buffer */
2847
+ supportMultisampledFramebuffer: boolean;
2848
+ /** True if device supports blending on float point frame buffer */
2849
+ supportFloatBlending: boolean;
2850
+ /** True if device supports 32bits float depth buffer */
2851
+ supportDepth32float: boolean;
2852
+ /** True if device supports 32bits float depth buffer with 8bits stencil */
2853
+ supportDepth32floatStencil8: boolean;
2854
+ /** Maximum color attachment bytes per sample */
2855
+ maxColorAttachmentBytesPerSample: number;
2856
+ }
2857
+ /**
2858
+ * Miscellaneous capabilities of the device
2859
+ * @public
2860
+ */
2861
+ interface MiscCaps {
2862
+ /** True if the device supports oversized viewport */
2863
+ supportOversizedViewport: boolean;
2864
+ /** True if the device supports minimum and maximum blending equations */
2865
+ supportBlendMinMax: boolean;
2866
+ /** True if the device supports 32-bits index buffer */
2867
+ support32BitIndex: boolean;
2868
+ /** The maximum number of {@link BindGroupLayout}'s in a shader program */
2869
+ maxBindGroups: number;
2870
+ /** The maximum number of texture coordinate index */
2871
+ maxTexCoordIndex: number;
2872
+ }
2873
+ /**
2874
+ * Shader related capabilities of the device
2875
+ * @public
2876
+ */
2877
+ interface ShaderCaps {
2878
+ /** True if the device supports writing depth value in a fragment shader */
2879
+ supportFragmentDepth: boolean;
2880
+ /** True if the device supports derivative functions in a fragment shader */
2881
+ supportStandardDerivatives: boolean;
2882
+ /** True if the device supports explicit control of texture LOD in a fragment shader */
2883
+ supportShaderTextureLod: boolean;
2884
+ /** True if the device supports high precison float number for shader programs */
2885
+ supportHighPrecisionFloat: boolean;
2886
+ /** True if the device supports high precison integer number for shader programs */
2887
+ supportHighPrecisionInt: boolean;
2888
+ /** The maximum number of bytes of uniform buffer */
2889
+ maxUniformBufferSize: number;
2890
+ /** The uniform buffer offset alignment */
2891
+ uniformBufferOffsetAlignment: number;
2892
+ }
2893
+ /**
2894
+ * Information of a texture format
2895
+ * @public
2896
+ */
2897
+ interface TextureFormatInfo {
2898
+ /** True if the texture format supports linear filtering */
2899
+ filterable: boolean;
2900
+ /** True if the texture format can be used as a render target */
2901
+ renderable: boolean;
2902
+ /** True if the texture format is a compressed format */
2903
+ compressed: boolean;
2904
+ }
2905
+ /**
2906
+ * Texture related capabilities of the device'
2907
+ * @public
2908
+ */
2909
+ interface TextureCaps {
2910
+ /** The maximum size for 2d texture */
2911
+ maxTextureSize: number;
2912
+ /** The maximum size for cube texture */
2913
+ maxCubeTextureSize: number;
2914
+ /** True if mipmapping is supported for non power of 2 textures */
2915
+ npo2Mipmapping: boolean;
2916
+ /** True if repeat address mode is supported for non power of 2 textures */
2917
+ npo2Repeating: boolean;
2918
+ /** True if device supports dxt1, dxt3, dxt5 texture format */
2919
+ supportS3TC: boolean;
2920
+ /** True if device supports dxt1_srgb, dxt3-srgb, dxt5-srgb texture format */
2921
+ supportS3TCSRGB: boolean;
2922
+ /** True if device supports depth texture */
2923
+ supportDepthTexture: boolean;
2924
+ /** True if device supports 3d texture */
2925
+ support3DTexture: boolean;
2926
+ /** True if device supports sRGB texture */
2927
+ supportSRGBTexture: boolean;
2928
+ /** True if device supports 32bit floating-point texture */
2929
+ supportFloatTexture: boolean;
2930
+ /** True if device supports linear filtering on 32bit floating-point textures */
2931
+ supportLinearFloatTexture: boolean;
2932
+ /** True if device supports 16bit floating-point texture */
2933
+ supportHalfFloatTexture: boolean;
2934
+ /** True if device supports linear filtering on 16bit floating-point textures */
2935
+ supportLinearHalfFloatTexture: boolean;
2936
+ /** True if device supports anisotropic filtering */
2937
+ supportAnisotropicFiltering: boolean;
2938
+ /** True if device supports rendering into a 32bit floating-point frame buffer */
2939
+ supportFloatColorBuffer: boolean;
2940
+ /** True if device supports rendering into a 16bit floating-point frame buffer */
2941
+ supportHalfFloatColorBuffer: boolean;
2942
+ /** True if device supports alpha blending with floating-point frame buffer */
2943
+ supportFloatBlending: boolean;
2944
+ /**
2945
+ * Get information of a given texture format
2946
+ * @param format - The texture format
2947
+ * @returns the texture format infomation
2948
+ */
2949
+ getTextureFormatInfo(format: TextureFormat): TextureFormatInfo;
2950
+ }
2951
+ /**
2952
+ * Creation options of rendering shader program
2953
+ * @public
2954
+ */
2955
+ interface RenderProgramConstructParams {
2956
+ /** The vertex shader source code */
2957
+ vs: string;
2958
+ /** The fragment shader source code */
2959
+ fs: string;
2960
+ /** Bind group layouts for the program */
2961
+ bindGroupLayouts: BindGroupLayout[];
2962
+ /** Vertex attributes used in the program */
2963
+ vertexAttributes: number[];
2964
+ }
2965
+ /**
2966
+ * Creation options of computing shader program
2967
+ * @public
2968
+ */
2969
+ interface ComputeProgramConstructParams {
2970
+ /** The shader source */
2971
+ source: string;
2972
+ /** Bind group layouts for the program */
2973
+ bindGroupLayouts: BindGroupLayout[];
2974
+ }
2975
+ /**
2976
+ * Creation options for shader program
2977
+ * @public
2978
+ */
2979
+ interface GPUProgramConstructParams {
2980
+ /** Type of the program to be created */
2981
+ type: 'render' | 'compute';
2982
+ /** Label of the program */
2983
+ label?: string;
2984
+ /** The creation options */
2985
+ params: RenderProgramConstructParams | ComputeProgramConstructParams;
2986
+ }
2987
+ /**
2988
+ * Event that will be fired when device is lost
2989
+ * @public
2990
+ */
2991
+ declare class DeviceLostEvent {
2992
+ /** The event name */
2993
+ static readonly NAME: "devicelost";
2994
+ type: "devicelost";
2995
+ }
2996
+ /**
2997
+ * Event that will be fired when device has just been restored
2998
+ * @public
2999
+ */
3000
+ declare class DeviceRestoreEvent {
3001
+ /** The event name */
3002
+ static readonly NAME: "devicerestored";
3003
+ type: "devicerestored";
3004
+ }
3005
+ /**
3006
+ * Event that will be fired when size of back buffer has changed
3007
+ * @public
3008
+ */
3009
+ declare class DeviceResizeEvent {
3010
+ /** The event name */
3011
+ static readonly NAME: "resize";
3012
+ width: number;
3013
+ height: number;
3014
+ type: "resize";
3015
+ constructor(width: number, height: number);
3016
+ }
3017
+ /**
3018
+ * Event that will be fired when any gpu object is created
3019
+ * @public
3020
+ */
3021
+ declare class DeviceGPUObjectAddedEvent {
3022
+ /** the event name */
3023
+ static readonly NAME: "gpuobject_added";
3024
+ object: GPUObject;
3025
+ type: "gpuobject_added";
3026
+ constructor(obj: GPUObject);
3027
+ }
3028
+ /**
3029
+ * Event that will be fired when any gpu object is disposed
3030
+ * @public
3031
+ */
3032
+ declare class DeviceGPUObjectRemovedEvent {
3033
+ /** The event name */
3034
+ static readonly NAME: 'gpuobject_removed';
3035
+ object: GPUObject;
3036
+ type: "gpuobject_removed";
3037
+ constructor(obj: GPUObject);
3038
+ }
3039
+ /**
3040
+ * Event that will be fired when any gpu object name is changed
3041
+ * @public
3042
+ */
3043
+ declare class DeviceGPUObjectRenameEvent {
3044
+ /** The event name */
3045
+ static readonly NAME: 'gpuobject_rename';
3046
+ object: GPUObject;
3047
+ lastName: string;
3048
+ type: "gpuobject_rename";
3049
+ constructor(obj: GPUObject, lastName: string);
3050
+ }
3051
+ /**
3052
+ * Creation options for device
3053
+ * @public
3054
+ */
3055
+ interface DeviceOptions {
3056
+ /** True if the device must have a MSAA back buffer */
3057
+ msaa?: boolean;
3058
+ /** The device pixel ratio */
3059
+ dpr?: number;
3060
+ }
3061
+ /**
3062
+ * The device event map
3063
+ * @public
3064
+ */
3065
+ type DeviceEventMap = {
3066
+ [DeviceResizeEvent.NAME]: DeviceResizeEvent;
3067
+ [DeviceLostEvent.NAME]: DeviceLostEvent;
3068
+ [DeviceRestoreEvent.NAME]: DeviceRestoreEvent;
3069
+ [DeviceGPUObjectAddedEvent.NAME]: DeviceGPUObjectAddedEvent;
3070
+ [DeviceGPUObjectRemovedEvent.NAME]: DeviceGPUObjectRemovedEvent;
3071
+ [DeviceGPUObjectRenameEvent.NAME]: DeviceGPUObjectRenameEvent;
3072
+ };
3073
+ /**
3074
+ * Structure that contains the device viewport information
3075
+ * @public
3076
+ */
3077
+ type DeviceViewport = {
3078
+ /** viewport left */
3079
+ x: number;
3080
+ /** viewport top */
3081
+ y: number;
3082
+ /** viewport width */
3083
+ width: number;
3084
+ /** viewport height */
3085
+ height: number;
3086
+ /**
3087
+ * A boolean value that indicates whether this is full screen viewport
3088
+ * @remarks
3089
+ * The full screen viewport will be automatically resized when the screen size chenged
3090
+ */
3091
+ default: boolean;
3092
+ };
3093
+ /**
3094
+ * Abstract interface for the rendering device.
3095
+ * @public
3096
+ */
3097
+ interface AbstractDevice extends IEventTarget<DeviceEventMap> {
3098
+ /** Get sample count of current frame buffer */
3099
+ getFrameBufferSampleCount(): number;
3100
+ /** Returns true if device context is lost. */
3101
+ isContextLost(): boolean;
3102
+ /** Get the value of device pixel ratio */
3103
+ getScale(): number;
3104
+ /** Get the width of current frame buffer */
3105
+ getDrawingBufferWidth(): number;
3106
+ /** Get the height of current frame buffer */
3107
+ getDrawingBufferHeight(): number;
3108
+ /** Get the width of back buffer */
3109
+ getBackBufferWidth(): number;
3110
+ /** Get the height of back buffer */
3111
+ getBackBufferHeight(): number;
3112
+ /** Get the device capabilities */
3113
+ getDeviceCaps(): DeviceCaps;
3114
+ /** Set font for drawText function */
3115
+ setFont(fontName: string): any;
3116
+ /**
3117
+ * Draw a string
3118
+ * @param text - The string that will be drawn
3119
+ * @param x - x coordinate in pixels related to the viewport origin
3120
+ * @param y - y coordinate in pixels related to the viewport origin
3121
+ * @param color - A CSS color value
3122
+ */
3123
+ drawText(text: string, x: number, y: number, color: string): any;
3124
+ /**
3125
+ * Clears the current frame buffer
3126
+ * @param clearColor - If not null, the color buffer will be cleared to this value.
3127
+ * @param clearDepth - If not null, the depth buffer will be cleared to this value.
3128
+ * @param clearStencil - If not null, the stencil buffer will be cleared to this value.
3129
+ */
3130
+ clearFrameBuffer(clearColor: Vector4, clearDepth: number, clearStencil: number): any;
3131
+ /** Creates a render state set object */
3132
+ createRenderStateSet(): RenderStateSet;
3133
+ /**
3134
+ * Creates a texture sampler object
3135
+ * @param options - The creation options
3136
+ */
3137
+ createSampler(options: SamplerOptions): TextureSampler;
3138
+ /**
3139
+ * Creates a texture from given mipmap data
3140
+ * @param data - Mipmap data
3141
+ * @param options - Texture creation options
3142
+ * @returns The created texture
3143
+ */
3144
+ createTextureFromMipmapData<T extends BaseTexture = BaseTexture>(data: TextureMipmapData, sRGB: boolean, options?: TextureCreationOptions): T;
3145
+ /**
3146
+ * Creates a 2d texture
3147
+ * @param format - The texture format
3148
+ * @param width - Pixel width of the texture
3149
+ * @param height - Pixel height of the texture
3150
+ * @param options - The creation options
3151
+ */
3152
+ createTexture2D(format: TextureFormat, width: number, height: number, options?: TextureCreationOptions): Texture2D;
3153
+ /**
3154
+ * Creates a 2d texture from given mipmap data
3155
+ * @param data - The mipmap data
3156
+ * @param options - The creation options
3157
+ */
3158
+ createTexture2DFromMipmapData(data: TextureMipmapData, sRGB: boolean, options?: TextureCreationOptions): Texture2D;
3159
+ /**
3160
+ * Creates a 2d texture from a image element
3161
+ * @param element - The image element
3162
+ * @param options - The creation options
3163
+ */
3164
+ createTexture2DFromImage(element: TextureImageElement, sRGB: boolean, options?: TextureCreationOptions): Texture2D;
3165
+ /**
3166
+ * Creates a 2d array texture
3167
+ * @param format - The texture format
3168
+ * @param width - Pixel width of the texture
3169
+ * @param height - Pixel height of the texture
3170
+ * @param depth - Array length of the texture
3171
+ * @param options - The creation options
3172
+ */
3173
+ createTexture2DArray(format: TextureFormat, width: number, height: number, depth: number, options?: TextureCreationOptions): Texture2DArray;
3174
+ /**
3175
+ * Creates a 2d array texture from mipmap data
3176
+ * @param data - mipmap data
3177
+ * @param sRGB - whether texture should have sRGB texture format
3178
+ * @param options - The creation options
3179
+ */
3180
+ createTexture2DArrayFromMipmapData(data: TextureMipmapData, options?: TextureCreationOptions): Texture2DArray;
3181
+ /**
3182
+ * Creates a 2d array texture from a seris of image elements
3183
+ * @remarks image elements must have the same size.
3184
+ * @param elements - image elements
3185
+ * @param options - The creation options
3186
+ */
3187
+ createTexture2DArrayFromImages(elements: TextureImageElement[], sRGB: boolean, options?: TextureCreationOptions): Texture2DArray;
3188
+ /**
3189
+ * Creates a 3d texture
3190
+ * @param format - The texture format
3191
+ * @param width - Pixel width of the texture
3192
+ * @param height - Pixel height of the texture
3193
+ * @param depth - Pixel depth of the texture
3194
+ * @param options - The creation options
3195
+ */
3196
+ createTexture3D(format: TextureFormat, width: number, height: number, depth: number, options?: TextureCreationOptions): Texture3D;
3197
+ /**
3198
+ * Creates a cube texture
3199
+ * @param format - The texture format
3200
+ * @param size - Pixel width of the texture
3201
+ * @param options - The creation options
3202
+ */
3203
+ createCubeTexture(format: TextureFormat, size: number, options?: TextureCreationOptions): TextureCube;
3204
+ /**
3205
+ * Creates a cube texture from given mipmap data
3206
+ * @param data - The mipmap data
3207
+ * @param options - The creation options
3208
+ */
3209
+ createCubeTextureFromMipmapData(data: TextureMipmapData, sRGB: boolean, options?: TextureCreationOptions): TextureCube;
3210
+ /**
3211
+ * Creates a video texture from a video element
3212
+ * @param el - The video element
3213
+ */
3214
+ createTextureVideo(el: HTMLVideoElement, samplerOptions?: SamplerOptions): TextureVideo;
3215
+ /**
3216
+ * Set wether to reverse the winding order
3217
+ *
3218
+ * @remarks
3219
+ * The default winding order is counter-clockwise.
3220
+ *
3221
+ * @param reverse - true if the winding order should be reversed.
3222
+ */
3223
+ reverseVertexWindingOrder(reverse: boolean): void;
3224
+ /**
3225
+ * Check if the current winding order is reversed.
3226
+ */
3227
+ isWindingOrderReversed(): boolean;
3228
+ /**
3229
+ * Creates a gpu program
3230
+ * @param params - The creation options
3231
+ */
3232
+ createGPUProgram(params: GPUProgramConstructParams): GPUProgram;
3233
+ /**
3234
+ * Creates a bind group
3235
+ * @param layout - Layout of the bind group
3236
+ */
3237
+ createBindGroup(layout: BindGroupLayout): BindGroup;
3238
+ /**
3239
+ * Creates a gpu buffer
3240
+ * @param sizeInBytes - Size of the buffer in bytes
3241
+ * @param options - The creation options
3242
+ */
3243
+ createBuffer(sizeInBytes: number, options: BufferCreationOptions): GPUDataBuffer;
3244
+ /**
3245
+ * Creates an index buffer
3246
+ * @param data - Data of the index buffer
3247
+ * @param options - The creation options
3248
+ */
3249
+ createIndexBuffer(data: Uint16Array | Uint32Array, options?: BufferCreationOptions): IndexBuffer;
3250
+ /**
3251
+ * Creates a structured buffer
3252
+ * @param structureType - The structure type
3253
+ * @param options - The creation options
3254
+ * @param data - Data to be filled with
3255
+ */
3256
+ createStructuredBuffer(structureType: PBStructTypeInfo, options: BufferCreationOptions, data?: TypedArray): StructuredBuffer;
3257
+ /**
3258
+ * Creates a vertex layout
3259
+ * @param options - The creation options
3260
+ */
3261
+ createVertexLayout(options: VertexLayoutOptions): VertexLayout;
3262
+ /**
3263
+ * Creates a frame buffer
3264
+ * @param options - The creation options
3265
+ */
3266
+ createFrameBuffer(colorAttachments: BaseTexture[], depthAttachment: BaseTexture, options?: FrameBufferOptions): FrameBuffer;
3267
+ /**
3268
+ * Set viewport from an array that contains the position and size
3269
+ *
3270
+ * @param vp - The viewport position and size, if not specified, the viewport will be set to [0, 0, drawingBufferWidth, drawingBufferHeight]
3271
+ */
3272
+ setViewport(vp?: DeviceViewport | number[]): void;
3273
+ /** Get current viewport as [x, y, width, height] */
3274
+ getViewport(): DeviceViewport;
3275
+ /**
3276
+ * Set scissor rectangle from an array that contains the position and size
3277
+ * @param scissor - The scissor rectangle position and size, if not specified, the scissor rectangle will be set to [0, 0, drawingBufferWidth,drawingBufferHeight]
3278
+ */
3279
+ setScissor(scissor?: DeviceViewport | number[]): void;
3280
+ /**
3281
+ * Get current scissor rectangle
3282
+ */
3283
+ getScissor(): DeviceViewport;
3284
+ /**
3285
+ * Set current GPU program
3286
+ * @param program - The GPU program to be set
3287
+ */
3288
+ setProgram(program: GPUProgram): void;
3289
+ /**
3290
+ * Get current GPU program
3291
+ */
3292
+ getProgram(): GPUProgram;
3293
+ /**
3294
+ * Set current vertex layout
3295
+ *
3296
+ * @param vertexData - The vertex layout to be set
3297
+ */
3298
+ setVertexLayout(vertexData: VertexLayout): void;
3299
+ /** Get current vertex layout */
3300
+ getVertexLayout(): VertexLayout;
3301
+ /**
3302
+ * Set current render states
3303
+ *
3304
+ * @param renderStates - The render state set
3305
+ */
3306
+ setRenderStates(renderStates: RenderStateSet): void;
3307
+ /** Get current render states */
3308
+ getRenderStates(): RenderStateSet;
3309
+ /**
3310
+ * Set current frame buffer
3311
+ *
3312
+ * @param rt - The frame buffer
3313
+ */
3314
+ setFramebuffer(rt: FrameBuffer): void;
3315
+ /** Get current frame buffer */
3316
+ getFramebuffer(): FrameBuffer;
3317
+ /**
3318
+ * Set current bind group
3319
+ *
3320
+ * @param index - index of the bind group
3321
+ * @param bindGroup - The bind group to be set
3322
+ * @param dynamicOffsets - dynamic uniform buffer offsets of the bind group or null
3323
+ */
3324
+ setBindGroup(index: number, bindGroup: BindGroup, dynamicOffsets?: Iterable<number>): any;
3325
+ /**
3326
+ * Get current bind group
3327
+ * @param index - index of the bind group to get
3328
+ */
3329
+ getBindGroup(index: number): [BindGroup, Iterable<number>];
3330
+ /** Flush the gpu command buffer */
3331
+ flush(): void;
3332
+ /**
3333
+ * Read pixel values from current frame buffer
3334
+ *
3335
+ * @remarks
3336
+ * This method reads the data asynchronously to prevent GPU stall.
3337
+ * For WebGL1 devices, the GPU stall is still inevitable.
3338
+ *
3339
+ * @param index - color attachment index
3340
+ * @param x - x position of the reading area
3341
+ * @param y - y position of the reading area
3342
+ * @param w - width of the reading area
3343
+ * @param h - height of the reading area
3344
+ * @param buffer - The output buffer
3345
+ */
3346
+ readPixels(index: number, x: number, y: number, w: number, h: number, buffer: TypedArray): Promise<void>;
3347
+ /**
3348
+ * Read pixel values from current frame buffer to a GPU buffer
3349
+ *
3350
+ * @remarks
3351
+ * This method does not support WebGL1 device
3352
+ *
3353
+ * @param index - color attachment index
3354
+ * @param x - x position of the reading area
3355
+ * @param y - y position of the reading area
3356
+ * @param w - width of the reading area
3357
+ * @param h - height of the reading area
3358
+ * @param buffer - The output buffer
3359
+ */
3360
+ readPixelsToBuffer(index: number, x: number, y: number, w: number, h: number, buffer: GPUDataBuffer): void;
3361
+ /** Get the video memory usage in bytes */
3362
+ videoMemoryUsage: number;
3363
+ /** Get the current frame information */
3364
+ frameInfo: FrameInfo;
3365
+ /** Check if the device is running a rendering loop by calling {@link AbstractDevice.runLoop} */
3366
+ isRendering: boolean;
3367
+ /** Get the canvas element for this device */
3368
+ canvas: HTMLCanvasElement;
3369
+ /** Get the device type */
3370
+ type: string;
3371
+ /** Get the program builder */
3372
+ programBuilder: ProgramBuilder;
3373
+ /** Get the run loop callback function */
3374
+ runLoopFunction: (device: AbstractDevice) => void;
3375
+ /**
3376
+ * Begins a frame for rendering
3377
+ *
3378
+ * @remarks
3379
+ * All rendering call must occur between the {@link AbstractDevice.beginFrame} and {@link AbstractDevice.endFrame} methods
3380
+ */
3381
+ beginFrame(): boolean;
3382
+ /**
3383
+ * Ends a frame for rendering
3384
+ *
3385
+ * @remarks
3386
+ * All rendering call must occur between the {@link AbstractDevice.beginFrame} and {@link AbstractDevice.endFrame} methods
3387
+ */
3388
+ endFrame(): void;
3389
+ /**
3390
+ * Get the vertex attribute format from vertex semantic and data type
3391
+ *
3392
+ * @param semantic - The vertex semantic
3393
+ * @param dataType - The data type
3394
+ * @param componentCount - The component count
3395
+ */
3396
+ getVertexAttribFormat(semantic: VertexSemantic, dataType: DataType, componentCount: number): VertexAttribFormat;
3397
+ /**
3398
+ * Creates an interleaved vertex buffer
3399
+ *
3400
+ * @param attribFormats - The vertex attribute formats for each vertex stream in the vertex buffer
3401
+ * @param data - Data to be filled with
3402
+ * @param options - The creation options
3403
+ */
3404
+ createInterleavedVertexBuffer(attribFormats: VertexAttribFormat[], data: TypedArray, options?: BufferCreationOptions): StructuredBuffer;
3405
+ /**
3406
+ * Creates a non-interleaved vertex buffer
3407
+ *
3408
+ * @param attribFormat - The vertex attribute format
3409
+ * @param data - Data to be filled with
3410
+ * @param options - The creation options
3411
+ */
3412
+ createVertexBuffer(attribFormat: VertexAttribFormat, data: TypedArray, options?: BufferCreationOptions): StructuredBuffer;
3413
+ /**
3414
+ * Draw primitives
3415
+ *
3416
+ * @param primitiveType - The primitive type
3417
+ * @param first - The vertex offset (or index offset if an index buffer exists)
3418
+ * @param count - The vertex count (or index count if an index buffer exists) to be drawn
3419
+ */
3420
+ draw(primitiveType: PrimitiveType, first: number, count: number): void;
3421
+ /**
3422
+ * Draw multiple instances of primitives
3423
+ *
3424
+ * @param primitiveType - The primitive type
3425
+ * @param first - The vertex offset (or index offset if an index buffer exists)
3426
+ * @param count - The vertex count (or index count if an index buffer exists) to be drawn
3427
+ * @param numInstances - How many instances to be drawn
3428
+ */
3429
+ drawInstanced(primitiveType: PrimitiveType, first: number, count: number, numInstances: number): void;
3430
+ /**
3431
+ * Dispatches a compute task to the GPU
3432
+ *
3433
+ * @param workgroupCountX - X dimension of the grid of workgroups to be dispatch
3434
+ * @param workgroupCountY - Y dimension of the grid of workgroups to be dispatch
3435
+ * @param workgroupCountZ - Z dimension of the grid of workgroups to be dispatch
3436
+ */
3437
+ compute(workgroupCountX: number, workgroupCountY: number, workgroupCountZ: number): void;
3438
+ /**
3439
+ * Schedules a function to be executed at the beginning of the next frame
3440
+ *
3441
+ * @param f - The function to be scheduled
3442
+ */
3443
+ runNextFrame(f: () => void): void;
3444
+ /**
3445
+ * Canels a pre scheduled function
3446
+ *
3447
+ * @param f - The function to be cancled
3448
+ */
3449
+ cancelNextFrameCall(f: () => void): void;
3450
+ /** Exits from current rendering loop */
3451
+ exitLoop(): void;
3452
+ /**
3453
+ * Begins a rendering loop
3454
+ *
3455
+ * @param func - The function to be executed at every frame
3456
+ */
3457
+ runLoop(func: (device: AbstractDevice) => void): void;
3458
+ /** Get all GPU objects */
3459
+ getGPUObjects(): GPUObjectList;
3460
+ /**
3461
+ * Get GPU object by id
3462
+ *
3463
+ * @param uid - id of the GPU object
3464
+ */
3465
+ getGPUObjectById(uid: number): GPUObject;
3466
+ /**
3467
+ * Calculates the actual position of current frame buffer from screen position.
3468
+ *
3469
+ * @remarks
3470
+ * If current frame buffer is the back buffer, the value will be scaled by the device pixel ratio.
3471
+ *
3472
+ * @param val - The screen position in pixels
3473
+ */
3474
+ screenToDevice(val: number): number;
3475
+ /**
3476
+ * Calculates the screen position from position of current frame buffer.
3477
+ *
3478
+ * @remarks
3479
+ * If current frame buffer is the back buffer, the value will be divided by the device pixel ratio.
3480
+ *
3481
+ * @param val - The position of current frame buffer in pixels
3482
+ */
3483
+ deviceToScreen(val: number): number;
3484
+ /** Builds render program */
3485
+ buildRenderProgram(options: PBRenderOptions): GPUProgram;
3486
+ /** Builds compute program */
3487
+ buildComputeProgram(options: PBComputeOptions): GPUProgram;
3488
+ /** Pushes current FrameBuffer state */
3489
+ pushDeviceStates(): any;
3490
+ /** Pops last FrameBuffer state */
3491
+ popDeviceStates(): any;
3492
+ }
3493
+
3494
+ /**
3495
+ * Abstract timer interface
3496
+ * @public
3497
+ */
3498
+ interface ITimer {
3499
+ begin(): void;
3500
+ end(): void;
3501
+ ended(): boolean;
3502
+ elapsed(): number;
3503
+ }
3504
+ /**
3505
+ * CPU timer class
3506
+ * @public
3507
+ */
3508
+ declare class CPUTimer implements ITimer {
3509
+ constructor();
3510
+ now(): number;
3511
+ begin(): void;
3512
+ end(): void;
3513
+ ended(): boolean;
3514
+ elapsed(): number;
3515
+ }
3516
+
3517
+ /**
3518
+ * The device backend interface
3519
+ * @public
3520
+ */
3521
+ interface DeviceBackend {
3522
+ typeName(): string;
3523
+ supported(): boolean;
3524
+ createDevice(cvs: HTMLCanvasElement, options?: DeviceOptions): Promise<AbstractDevice>;
3525
+ }
3526
+ /**
3527
+ * Base class for rendering device
3528
+ * @public
3529
+ */
3530
+ declare abstract class BaseDevice {
3531
+ protected _canvas: HTMLCanvasElement;
3532
+ protected _canvasClientWidth: number;
3533
+ protected _canvasClientHeight: number;
3534
+ protected _gpuObjectList: GPUObjectList;
3535
+ protected _gpuMemCost: number;
3536
+ protected _disposeObjectList: GPUObject[];
3537
+ protected _beginFrameTime: number;
3538
+ protected _endFrameTime: number;
3539
+ protected _frameInfo: FrameInfo;
3540
+ protected _cpuTimer: CPUTimer;
3541
+ protected _gpuTimer: ITimer;
3542
+ protected _runningLoop: number;
3543
+ protected _fpsCounter: {
3544
+ time: number;
3545
+ frame: number;
3546
+ };
3547
+ protected _runLoopFunc: (device: AbstractDevice) => void;
3548
+ protected _backend: DeviceBackend;
3549
+ protected _beginFrameCounter: number;
3550
+ protected _programBuilder: ProgramBuilder;
3551
+ private _stateStack;
3552
+ constructor(cvs: HTMLCanvasElement, backend: DeviceBackend);
3553
+ abstract getFrameBufferSampleCount(): number;
3554
+ abstract isContextLost(): boolean;
3555
+ abstract getScale(): number;
3556
+ abstract getDrawingBufferWidth(): number;
3557
+ abstract getDrawingBufferHeight(): number;
3558
+ abstract getBackBufferWidth(): number;
3559
+ abstract getBackBufferHeight(): number;
3560
+ abstract getDeviceCaps(): DeviceCaps;
3561
+ abstract initContext(): Promise<void>;
3562
+ abstract clearFrameBuffer(clearColor: Vector4, clearDepth: number, clearStencil: number): any;
3563
+ abstract createGPUTimer(): ITimer;
3564
+ abstract createRenderStateSet(): RenderStateSet;
3565
+ abstract createSampler(options: SamplerOptions): TextureSampler;
3566
+ abstract createTextureFromMipmapData<T extends BaseTexture>(data: TextureMipmapData, sRGB: boolean, options?: TextureCreationOptions): T;
3567
+ abstract createTexture2D(format: TextureFormat, width: number, height: number, options?: TextureCreationOptions): Texture2D;
3568
+ abstract createTexture2DFromMipmapData(data: TextureMipmapData, sRGB: boolean, options?: TextureCreationOptions): Texture2D;
3569
+ abstract createTexture2DFromImage(element: TextureImageElement, sRGB: boolean, options?: TextureCreationOptions): Texture2D;
3570
+ abstract createTexture2DArray(format: TextureFormat, width: number, height: number, depth: number, options?: TextureCreationOptions): Texture2DArray;
3571
+ abstract createTexture2DArrayFromMipmapData(data: TextureMipmapData, options?: TextureCreationOptions): Texture2DArray;
3572
+ abstract createTexture2DArrayFromImages(elements: TextureImageElement[], sRGB: boolean, options?: TextureCreationOptions): Texture2DArray;
3573
+ abstract createTexture3D(format: TextureFormat, width: number, height: number, depth: number, options?: TextureCreationOptions): Texture3D;
3574
+ abstract createCubeTexture(format: TextureFormat, size: number, options?: TextureCreationOptions): TextureCube;
3575
+ abstract createCubeTextureFromMipmapData(data: TextureMipmapData, sRGB: boolean, options?: TextureCreationOptions): TextureCube;
3576
+ abstract createTextureVideo(el: HTMLVideoElement, samplerOptions?: SamplerOptions): TextureVideo;
3577
+ abstract reverseVertexWindingOrder(reverse: boolean): void;
3578
+ abstract isWindingOrderReversed(): boolean;
3579
+ abstract createGPUProgram(params: GPUProgramConstructParams): GPUProgram;
3580
+ abstract createBindGroup(layout: BindGroupLayout): BindGroup;
3581
+ abstract createBuffer(sizeInBytes: number, options: BufferCreationOptions): GPUDataBuffer;
3582
+ abstract createIndexBuffer(data: Uint16Array | Uint32Array, options?: BufferCreationOptions): IndexBuffer;
3583
+ abstract createStructuredBuffer(structureType: PBStructTypeInfo, options: BufferCreationOptions, data?: TypedArray): StructuredBuffer;
3584
+ abstract createVertexLayout(options: VertexLayoutOptions): VertexLayout;
3585
+ abstract createFrameBuffer(colorAttachments: BaseTexture[], depthAttachment: BaseTexture, options?: FrameBufferOptions): FrameBuffer;
3586
+ abstract setViewport(vp?: number[] | DeviceViewport): void;
3587
+ abstract getViewport(): DeviceViewport;
3588
+ abstract setScissor(scissor?: number[] | DeviceViewport): void;
3589
+ abstract getScissor(): DeviceViewport;
3590
+ abstract setProgram(program: GPUProgram): void;
3591
+ abstract getProgram(): GPUProgram;
3592
+ abstract setVertexLayout(vertexData: VertexLayout): void;
3593
+ abstract getVertexLayout(): VertexLayout;
3594
+ abstract setRenderStates(renderStates: RenderStateSet): void;
3595
+ abstract getRenderStates(): RenderStateSet;
3596
+ abstract setFramebuffer(rt: FrameBuffer): void;
3597
+ abstract getFramebuffer(): FrameBuffer;
3598
+ abstract setBindGroup(index: number, bindGroup: BindGroup, dynamicOffsets?: Iterable<number>): any;
3599
+ abstract getBindGroup(index: number): [BindGroup, Iterable<number>];
3600
+ abstract flush(): void;
3601
+ abstract readPixels(index: number, x: number, y: number, w: number, h: number, buffer: TypedArray): Promise<void>;
3602
+ abstract readPixelsToBuffer(index: number, x: number, y: number, w: number, h: number, buffer: GPUDataBuffer): void;
3603
+ abstract looseContext(): void;
3604
+ abstract restoreContext(): void;
3605
+ protected abstract _draw(primitiveType: PrimitiveType, first: number, count: number): void;
3606
+ protected abstract _drawInstanced(primitiveType: PrimitiveType, first: number, count: number, numInstances: number): void;
3607
+ protected abstract _compute(workgroupCountX: number, workgroupCountY: number, workgroupCountZ: number): void;
3608
+ get backend(): DeviceBackend;
3609
+ get videoMemoryUsage(): number;
3610
+ get frameInfo(): FrameInfo;
3611
+ get isRendering(): boolean;
3612
+ get canvas(): HTMLCanvasElement;
3613
+ get type(): string;
3614
+ get runLoopFunction(): (device: AbstractDevice) => void;
3615
+ get programBuilder(): ProgramBuilder;
3616
+ setFont(fontName: string): void;
3617
+ drawText(text: string, x: number, y: number, color: string): void;
3618
+ disposeObject(obj: GPUObject, remove?: boolean): void;
3619
+ restoreObject(obj: GPUObject): Promise<void>;
3620
+ enableGPUTimeRecording(enable: boolean): void;
3621
+ beginFrame(): boolean;
3622
+ endFrame(): void;
3623
+ getVertexAttribFormat(semantic: VertexSemantic, dataType: DataType, componentCount: number): VertexAttribFormat;
3624
+ createInterleavedVertexBuffer(attribFormats: VertexAttribFormat[], data: TypedArray, options?: BufferCreationOptions): StructuredBuffer;
3625
+ createVertexBuffer(attribFormat: VertexAttribFormat, data: TypedArray, options?: BufferCreationOptions): StructuredBuffer;
3626
+ draw(primitiveType: PrimitiveType, first: number, count: number): void;
3627
+ drawInstanced(primitiveType: PrimitiveType, first: number, count: number, numInstances: number): void;
3628
+ compute(workgroupCountX: any, workgroupCountY: any, workgroupCountZ: any): void;
3629
+ runNextFrame(f: () => void): void;
3630
+ cancelNextFrameCall(f: () => void): void;
3631
+ exitLoop(): void;
3632
+ runLoop(func: (device: AbstractDevice) => void): void;
3633
+ pushDeviceStates(): void;
3634
+ popDeviceStates(): void;
3635
+ getGPUObjects(): GPUObjectList;
3636
+ getGPUObjectById(uid: number): GPUObject;
3637
+ screenToDevice(val: number): number;
3638
+ deviceToScreen(val: number): number;
3639
+ buildRenderProgram(options: PBRenderOptions): GPUProgram;
3640
+ buildComputeProgram(options: PBComputeOptions): GPUProgram;
3641
+ addGPUObject(obj: GPUObject): void;
3642
+ removeGPUObject(obj: GPUObject): void;
3643
+ updateVideoMemoryCost(delta: number): void;
3644
+ protected abstract onBeginFrame(): boolean;
3645
+ protected abstract onEndFrame(): void;
3646
+ private _onresize;
3647
+ private _registerEventHandlers;
3648
+ private updateFrameInfo;
3649
+ private getGPUObjectList;
3650
+ protected invalidateAll(): void;
3651
+ protected reloadAll(): Promise<void>;
3652
+ protected parseTextureOptions(options?: TextureCreationOptions): number;
3653
+ protected parseBufferOptions(options: BufferCreationOptions, defaultUsage?: BufferUsage): number;
3654
+ }
3655
+ /**
3656
+ * Merge event target interface
3657
+ * @public
3658
+ */
3659
+ interface BaseDevice extends IEventTarget<DeviceEventMap> {
3660
+ }
3661
+
3662
+ /**
3663
+ * Information of a texture atlas
3664
+ * @public
3665
+ */
3666
+ interface AtlasInfo {
3667
+ atlasIndex: number;
3668
+ width: number;
3669
+ height: number;
3670
+ uMin: number;
3671
+ vMin: number;
3672
+ uMax: number;
3673
+ vMax: number;
3674
+ }
3675
+ /**
3676
+ * Texture atlas manager
3677
+ * @public
3678
+ */
3679
+ declare class TextureAtlasManager {
3680
+ /**
3681
+ * Creates a new texture atlas manager instance
3682
+ * @param device - The render device
3683
+ * @param binWidth - Width of an atlas bin
3684
+ * @param binHeight - Height of an atlas bin
3685
+ * @param rectBorderWidth - Border width of an atlas
3686
+ * @param linearSpace - true if the texture space is linear
3687
+ */
3688
+ constructor(device: AbstractDevice, binWidth: number, binHeight: number, rectBorderWidth: number, linearSpace?: boolean);
3689
+ /**
3690
+ * The texture restore handler callback function
3691
+ * This callback function will be called whenever the device has been restored
3692
+ */
3693
+ get atlasTextureRestoreHandler(): (tex: BaseTexture) => Promise<void>;
3694
+ set atlasTextureRestoreHandler(f: (tex: BaseTexture) => Promise<void>);
3695
+ /**
3696
+ * Gets the atlas texture of a given index
3697
+ * @param index - Index of the atlas bin
3698
+ * @returns Atlas texture for given index
3699
+ */
3700
+ getAtlasTexture(index: number): Texture2D;
3701
+ /**
3702
+ * Gets the information about specified atlas
3703
+ * @param key - Key of the atlas
3704
+ * @returns Information of the atlas
3705
+ */
3706
+ getAtlasInfo(key: string): AtlasInfo;
3707
+ /**
3708
+ * Check if no atlas has been created
3709
+ * @returns true if no atlas has been created
3710
+ */
3711
+ isEmpty(): boolean;
3712
+ /**
3713
+ * Removes all created atlases
3714
+ */
3715
+ clear(): void;
3716
+ /**
3717
+ * Inserts a rectangle of a canvas to the atlas texture
3718
+ * @param key - Key of the atlas
3719
+ * @param ctx - The canvas context
3720
+ * @param x - x offset of the rectangle
3721
+ * @param y - y offset of the rectangle
3722
+ * @param w - width of the rectangle
3723
+ * @param h - height of the rectangle
3724
+ * @returns The atals info or null if insert failed
3725
+ */
3726
+ pushCanvas(key: string, ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number): AtlasInfo;
3727
+ /**
3728
+ * Inserts a bitmap to the atlas texture
3729
+ * @param key - Key of the atlas
3730
+ * @param bitmap - The bitmap object
3731
+ * @returns The atals info or null if insert failed
3732
+ */
3733
+ pushBitmap(key: string, bitmap: ImageData | ImageBitmap): AtlasInfo;
3734
+ }
3735
+
3736
+ /**
3737
+ * The font class
3738
+ * @public
3739
+ */
3740
+ declare class Font {
3741
+ /**
3742
+ * Creates a instance of font class from font name and the scale value
3743
+ * @param name - The font name
3744
+ * @param scale - The scale value
3745
+ */
3746
+ constructor(name: string, scale: number);
3747
+ /**
3748
+ * Fetch a font from cache
3749
+ * @param name - The font name
3750
+ * @param scale - The scale value
3751
+ * @returns The font object
3752
+ */
3753
+ static fetchFont(name: string, scale: number): Font;
3754
+ /** Gets the font name */
3755
+ get fontName(): string;
3756
+ set fontName(name: string);
3757
+ /** Gets the scaled font name */
3758
+ get fontNameScaled(): string;
3759
+ /** Gets the font size */
3760
+ get size(): number;
3761
+ /** Gets the font family */
3762
+ get family(): string;
3763
+ /** Gets top position of the font */
3764
+ get top(): number;
3765
+ /** Gets the bottom position of the font */
3766
+ get bottom(): number;
3767
+ /** Gets the scaled top position of the font */
3768
+ get topScaled(): number;
3769
+ /** Gets the scaled bottom position of the font */
3770
+ get bottomScaled(): number;
3771
+ /** Gets the maximum height of the font */
3772
+ get maxHeight(): number;
3773
+ /** Gets the scaled maximum height of the font */
3774
+ get maxHeightScaled(): number;
3775
+ /** Tests if two fonts are the same */
3776
+ equalTo(other: Font): boolean;
3777
+ }
3778
+
3779
+ /**
3780
+ * Manager of texture glyphs
3781
+ * @public
3782
+ */
3783
+ declare class GlyphManager extends TextureAtlasManager {
3784
+ /**
3785
+ * Creates a new glyph manager instance
3786
+ * @param device - The render device
3787
+ * @param binWidth - Width of an atlas bin
3788
+ * @param binHeight - Height of an atlas bin
3789
+ * @param border - Border width of an atlas
3790
+ */
3791
+ constructor(device: AbstractDevice, binWidth: number, binHeight: number, border: number);
3792
+ /**
3793
+ * Gets the atlas information for given character
3794
+ * @param char - The character
3795
+ * @param font - Font of the character
3796
+ * @returns Atlas information for the glyph
3797
+ */
3798
+ getGlyphInfo(char: string, font: Font): AtlasInfo;
3799
+ /**
3800
+ * Measuring the width of a string
3801
+ * @param str - The string to be measured
3802
+ * @param charMargin - margin size between characters
3803
+ * @param font - Font of the string
3804
+ * @returns Width of the string
3805
+ */
3806
+ measureStringWidth(str: string, charMargin: number, font: Font): number;
3807
+ /**
3808
+ * Clips a string so that it's width is not larger than the given value
3809
+ * @param str - The string to be clipped
3810
+ * @param width - The desired maximum width
3811
+ * @param charMargin - Margin size between characters
3812
+ * @param start - Start index of the string to be clipped
3813
+ * @param font - Font of the string
3814
+ * @returns
3815
+ */
3816
+ clipStringToWidth(str: string, width: number, charMargin: number, start: number, font: Font): number;
3817
+ /**
3818
+ * Measuring width of a character
3819
+ * @param char - The character to be measured
3820
+ * @param font - Font of the character
3821
+ * @returns Width of the character
3822
+ */
3823
+ getCharWidth(char: string, font: Font): number;
3824
+ }
3825
+
3826
+ /**
3827
+ * Helper class to draw some text onto the screen
3828
+ * @public
3829
+ */
3830
+ declare class DrawText {
3831
+ /**
3832
+ * Set the font that will be used to draw strings
3833
+ * @param device - The render device
3834
+ * @param name - The font name
3835
+ */
3836
+ static setFont(device: AbstractDevice, name: string): void;
3837
+ /**
3838
+ * Draw text onto the screen
3839
+ * @param device - The render device
3840
+ * @param text - The text to be drawn
3841
+ * @param color - The text color
3842
+ * @param x - X coordinate of the text
3843
+ * @param y - Y coordinate of the text
3844
+ */
3845
+ static drawText(device: AbstractDevice, text: string, color: string, x: number, y: number): void;
3846
+ }
3847
+
3848
+ /**
3849
+ * Structured buffer data
3850
+ * @public
3851
+ */
3852
+ declare class StructuredBufferData {
3853
+ /**
3854
+ * Creates a new structured buffer data
3855
+ * @param layout - Layout of the structure
3856
+ * @param buffer - Buffer that holds the data
3857
+ */
3858
+ constructor(layout: UniformBufferLayout, buffer?: StructuredBuffer | ArrayBuffer);
3859
+ /** The buffer size in bytes */
3860
+ get byteLength(): number;
3861
+ /** Get the data cache buffer */
3862
+ get buffer(): ArrayBuffer;
3863
+ /** Get all the uniform datas */
3864
+ get uniforms(): Record<string, TypedArray>;
3865
+ /**
3866
+ * Sets the value of a structure member
3867
+ * @param name - Name of the member
3868
+ * @param value - Value to set
3869
+ */
3870
+ set(name: string, value: StructuredValue): void;
3871
+ }
3872
+
3873
+ export { AbstractDevice, ArrayTypeDetail, AtlasInfo, AtomicTypeInfoDetail, BaseCreationOptions, BaseDevice, BaseTexture, BindGroup, BindGroupLayout, BindGroupLayoutEntry, BindPointInfo, BlendEquation, BlendFunc, BlendingState, BufferBindingLayout, BufferCreationOptions, BufferUsage, CPUTimer, ColorState, CompareFunc, ComputeProgramConstructParams, DataType, DepthState, DeviceBackend, DeviceCaps, DeviceEventMap, DeviceGPUObjectAddedEvent, DeviceGPUObjectRemovedEvent, DeviceGPUObjectRenameEvent, DeviceLostEvent, DeviceOptions, DeviceResizeEvent, DeviceRestoreEvent, DeviceViewport, DrawText, ExpValueNonArrayType, ExpValueType, ExternalTextureBindingLayout, FaceMode, FaceWinding, Font, FrameBuffer, FrameBufferOptions, FrameBufferTextureAttachment, FrameInfo, FramebufferCaps, FunctionTypeDetail, GPUDataBuffer, GPUObject, GPUObjectList, GPUProgram, GPUProgramConstructParams, GPUResourceUsageFlags, GlyphManager, ITimer, IndexBuffer, MiscCaps, PBAddressSpace, PBAnyTypeInfo, PBArrayTypeInfo, PBAtomicI32TypeInfo, PBAtomicU32TypeInfo, PBBuiltinScope, PBComputeOptions, PBDoWhileScope, PBForScope, PBFunctionScope, PBFunctionTypeInfo, PBGlobalScope, PBIfScope, PBInputScope, PBInsideFunctionScope, PBLocalScope, PBNakedScope, PBOutputScope, PBPointerTypeInfo, PBPrimitiveType, PBPrimitiveTypeInfo, PBReflection, PBReflectionTagGetter, PBRenderOptions, PBSamplerAccessMode, PBSamplerTypeInfo, PBScope, PBShaderExp, PBStructLayout, PBStructTypeInfo, PBTextureType, PBTextureTypeInfo, PBTypeInfo, PBVoidTypeInfo, PBWhileScope, PointerTypeDetail, PrimitiveType, PrimitiveTypeDetail, ProgramBuilder, Proxiable, RasterizerState, RenderProgramConstructParams, RenderStateSet, SamplerBindingLayout, SamplerOptions, SamplerTypeDetail, ShaderCaps, ShaderExpTagRecord, ShaderExpTagValue, ShaderKind, ShaderType, ShaderTypeFunc, StencilOp, StencilState, StorageTextureBindingLayout, StructTypeDetail, StructuredBuffer, StructuredBufferData, StructuredValue, Texture2D, Texture2DArray, Texture3D, TextureAddressMode, TextureAtlasManager, TextureBindingLayout, TextureCaps, TextureColorSpace, TextureCreationOptions, TextureCube, TextureFilterMode, TextureFormat, TextureFormatInfo, TextureImageElement, TextureMipmapData, TextureMipmapLevelData, TextureSampler, TextureType, TextureTypeDetail, TextureVideo, TypeDetailInfo, UniformBufferLayout, UniformLayout, VertexAttribFormat, VertexBufferInfo, VertexData, VertexLayout, VertexLayoutOptions, VertexSemantic, VertexStepMode, WebGLContext, genDefaultName, getTextureFormatBlockHeight, getTextureFormatBlockSize, getTextureFormatBlockWidth, getVertexAttribFormat, getVertexBufferAttribType, getVertexBufferAttribTypeBySemantic, getVertexBufferLength, getVertexBufferStride, hasAlphaChannel, hasBlueChannel, hasDepthChannel, hasGreenChannel, hasRedChannel, hasStencilChannel, isCompressedTextureFormat, isFloatTextureFormat, isIntegerTextureFormat, isSRGBTextureFormat, isSignedTextureFormat, linearTextureFormatToSRGB, makeVertexBufferType, semanticList };