-
Notifications
You must be signed in to change notification settings - Fork 322
/
regl.d.ts
executable file
Β·1747 lines (1554 loc) Β· 61.1 KB
/
regl.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for regl 2.0.0
// Project: regl
// Definitions by: Stepan Stolyarov <stepan.stolyarov@gmail.com>, David Schneider <github.com/davschne>
/*~ Note that ES6 modules cannot directly export callable functions.
*~ This file should be imported using the CommonJS-style:
*~
*~ ```typescript
*~ import REGL = require('regl');
*~ ```
*~
*~ Refer to the documentation to understand common
*~ workarounds for this limitation of ES6 modules.
*/
/*~ This module is a UMD module that exposes a global function `createREGL`. */
export as namespace createREGL;
export = REGL;
/**
* Creates a full screen canvas element and a WebGL rendering context.
*/
declare function REGL(): REGL.Regl;
/**
* Creates a WebGL rendering context using an element selected by `selector`.
* This may be:
* 1) an existing HTMLCanvasElement
* 2) an element that contains a canvas
* 3) an element in which you'd like `regl` to create a canvas
*
* @param selector an argument to `document.querySelector`
*/
declare function REGL(selector: string): REGL.Regl;
/**
* Creates a canvas element and a WebGL rendering context in a given container element.
*
* @param container an HTML element
*/
declare function REGL(container: HTMLElement): REGL.Regl;
/**
* Creates a WebGL rendering context using a `<canvas>` element.
*
* @param canvas HTML canvas element
*/
declare function REGL(canvas: HTMLCanvasElement): REGL.Regl;
/**
* Wraps an existing WebGL rendering context.
*
* @param gl WebGL rendering context
*/
declare function REGL(gl: WebGLRenderingContext): REGL.Regl;
/**
* Creates a WebGL according to specified `options`
*/
declare function REGL(options: REGL.InitializationOptions): REGL.Regl;
declare namespace REGL {
/**
* `Regl` represents the object/function returned from the `REGL` constructor. It exposes the
* entire public interface of the `regl` library.
*/
export interface Regl {
/**
* The context creation attributes passed to the WebGL context constructor.
*/
readonly attributes: WebGLContextAttributes;
/**
* `regl` is designed in such a way that you should never have to directly access the underlying
* WebGL context. However, if you really absolutely need to do this for some reason (for example
* to interface with an external library), you can still get a reference to the WebGL context
* via the property `_gl`.
*/
readonly _gl: WebGLRenderingContext;
/**
* `regl` exposes info about the WebGL context limits and capabilities via the `limits` object.
*/
readonly limits: REGL.Limits;
/**
* `regl` tracks several metrics for performance monitoring. These can be read using the `stats` object.
*/
readonly stats: REGL.Stats;
/**
* Creates a new REGL command. The resulting command, when executed,
* will set a WebGL state machine to a specified `state`.
*/
<
Uniforms extends {} = {},
Attributes extends {} = {},
Props extends {} = {},
OwnContext extends {} = {},
ParentContext extends REGL.DefaultContext = REGL.DefaultContext
>(
drawConfig: REGL.DrawConfig<Uniforms, Attributes, Props, OwnContext, ParentContext>,
): REGL.DrawCommand<ParentContext & OwnContext, Props>;
/**
* Clears selected buffers to specified values.
* If an option is not present, then the corresponding buffer is not cleared.
* Relevant WebGL API: `gl.clear`
*/
clear(options: REGL.ClearOptions): void;
/* Reading pixels */
/**
* Read entire screen.
* NB: Reading into a Float32Array requires OES_texture_float.
*/
read<T extends Uint8Array | Float32Array = Uint8Array>(): T;
/**
* Read entire screen into an existing TypedArray.
* NB: Reading into a Float32Array requires OES_texture_float.
*/
read<T extends Uint8Array | Float32Array>(data: T): T;
/**
* Read a selected region of screen or framebuffer.
* NB: Reading into a Float32Array requires OES_texture_float.
*/
read<T extends Uint8Array | Float32Array = Uint8Array>(options: REGL.ReadOptions<T>): T;
/**
* Dynamic variable binding
*
* `prop`, `context`, and `this` generate DynamicVariables, which can be used as values in a
* REGL.DrawConfig object. A DynamicVariable is an abstraction that will render a value only
* when the DrawCommand with which it's associated is invoked.
*/
/* Retrieve the property `name` passed when the draw command is executed. */
prop<Props extends {}, Key extends keyof Props>(name: Key): DynamicVariable<Props[Key]>;
/* Retrieve the context property `name` when the draw command is executed. */
context<Context extends REGL.DefaultContext, K extends keyof Context>(name: K): DynamicVariable<Context[K]>;
/* Retrieve the property `name` of the object in whose context the draw command is executing. */
this<This extends {}, Key extends keyof This>(name: Key): DynamicVariable<This[Key]>;
/* Drawing */
/** Executes an empty draw command. */
draw(): void;
/* Resource creation */
/** Creates an empty buffer of length `length`. */
buffer(length: number): REGL.Buffer;
/** Creates a buffer with the provided `data`. */
buffer(data: REGL.BufferData): REGL.Buffer;
/** Creates a buffer using creation `options`. */
buffer(options: REGL.BufferOptions): REGL.Buffer;
/* Creates an Elements object with the provided `data`. */
elements(data: REGL.ElementsData): REGL.Elements;
/* Creates an Elements object using creation `options`. */
elements(options: REGL.ElementsOptions): REGL.Elements;
/* Creates a 2D Texture of dimensions 1 x 1. */
texture(): REGL.Texture2D;
/* Creates a 2D Texture of dimensions `radius` x `radius`. */
texture(radius: number): REGL.Texture2D;
/* Creates a 2D Texture of dimensions `width` x `height`. */
texture(width: number, height: number): REGL.Texture2D;
/* Creates a 2D Texture using the provided `data`. */
texture(data: REGL.TextureImageData): REGL.Texture2D;
/* Creates a 2D Texture using creation `options`. */
texture(options: REGL.Texture2DOptions): REGL.Texture2D;
/* Creates a cube-map texture with faces of dimensions 1 x 1. */
cube(): REGL.TextureCube;
/* Creates a cube-map texture with faces of dimensions `radius` x `radius`. */
cube(radius: number): REGL.TextureCube;
/* Creates a cube-map texture using the provided image data for the six faces. */
cube(
posXData: REGL.TextureImageData, negXData: REGL.TextureImageData,
posYData: REGL.TextureImageData, negYData: REGL.TextureImageData,
posZData: REGL.TextureImageData, negZData: REGL.TextureImageData
): REGL.TextureCube;
/* Creates a cube-map texture using the provided creation options for the six faces. */
cube(
posXOptions: REGL.Texture2DOptions, negXOptions: REGL.Texture2DOptions,
posYOptions: REGL.Texture2DOptions, negYOptions: REGL.Texture2DOptions,
posZOptions: REGL.Texture2DOptions, negZOptions: REGL.Texture2DOptions,
): REGL.TextureCube;
/* Creates a cube-map texture using creation `options`. */
cube(options: REGL.TextureCubeOptions): REGL.TextureCube;
/* Creates a Renderbuffer of dimensions 1 x 1. */
renderbuffer(): REGL.Renderbuffer;
/* Creates a Renderbuffer of dimensions `radius` x `radius`. */
renderbuffer(radius: number): REGL.Renderbuffer;
/* Creates a Renderbuffer of dimensions `width` x `height`. */
renderbuffer(width: number, height: number): REGL.Renderbuffer;
/* Creates a Renderbuffer using creation `options`. */
renderbuffer(options: REGL.RenderbufferOptions): REGL.Renderbuffer;
/* Creates a Framebuffer of dimensions 1 x 1. */
framebuffer(): REGL.Framebuffer2D;
/* Creates a Framebuffer of dimensions `radius` x `radius`. */
framebuffer(radius: number): REGL.Framebuffer2D;
/* Creates a Framebuffer of dimensions `width` x `height`. */
framebuffer(width: number, height: number): REGL.Framebuffer2D;
/* Creates a Framebuffer using creation `options`. */
framebuffer(options: REGL.FramebufferOptions): REGL.Framebuffer2D;
/* Creates a FramebufferCube whose faces have dimensions 1 x 1. */
framebufferCube(): REGL.FramebufferCube;
/* Creates a FramebufferCube whose faces have dimensions `radius` x `radius`. */
framebufferCube(radius: number): REGL.FramebufferCube;
/* Creates a FramebufferCube using creation `options`. */
framebufferCube(options: REGL.FramebufferCubeOptions): REGL.FramebufferCube;
/* Creates a vertex array object */
vao(attributes: REGL.AttributeState[] | REGL.VertexArrayOptions) : REGL.VertexArrayObject;
/* Events and listeners */
/**
* Registers a `callback` to be called on each animation frame.
*
* This method integrates with `requestAnimationFrame` and context loss
* events. It also calls `gl.flush` and drains several internal buffers,
* so you should try to do all your rendering to the drawing buffer within
* the frame callback.
*/
frame(callback: REGL.FrameCallback): REGL.Cancellable;
/**
* Registers a handler function to be called when the associated `regl` event is fired.
*/
on(type: 'frame', callback: REGL.FrameCallback): REGL.Cancellable
on(type: 'lost' | 'restore' | 'destroy', callback: () => void): REGL.Cancellable;
/**
* Test if an extension is present. Argument is case insensitive.
*
* For more information on WebGL extensions, see the WebGL extension registry.
*
* Relevant WebGL APIs
*
* - [WebGL Extension Registry](https://www.khronos.org/registry/webgl/extensions/)
* - gl.getExtension
* - gl.getSupportedExtensions
*
* @param name case-insensitive name of WebGL extension
*/
hasExtension(name: string): boolean;
/**
* Updates the values of internal times and recalculates the size of viewports.
*/
poll(): void;
/**
* Returns Total time elapsed since regl was initialized in seconds.
*/
now(): number;
/**
* Destroys the gl context and releases all associated resources.
*/
destroy(): void;
/**
* `regl` is designed in such a way that you should never have to directly access the underlying
* WebGL context. However, if you really absolutely need to do this for some reason (for example
* to interface with an external library), you can still get a reference to the WebGL context
* via the property `REGL._gl`. Note, though, that if you have changed the WebGL state, you must
* call `_refresh` to restore the `regl` state in order to prevent rendering errors.
*/
_refresh(): void;
}
interface InitializationOptions {
/** A reference to a WebGL rendering context. (Default created from canvas) */
gl?: WebGLRenderingContext;
/** An HTML canvas element or a selector string to find this element. (Default created and appended to container)*/
canvas?: string | HTMLCanvasElement;
/** A container element into which regl inserts a canvas or a selector string to find this element. (Default document.body) */
container?: string | HTMLElement;
/** The context creation attributes passed to the WebGL context constructor. */
attributes?: WebGLContextAttributes;
/** A multiplier which is used to scale the canvas size relative to the container. (Default window.devicePixelRatio) */
pixelRatio?: number;
/** A list of extensions that must be supported by WebGL context. Default [] */
extensions?: string | string[];
/** A list of extensions which are loaded opportunistically. Default [] */
optionalExtensions?: string | string[];
/** If set, turns on profiling for all commands by default. (Default false) */
profile?: boolean;
/** An optional callback which accepts a pair of arguments, (err, regl) that is called after the application loads. If not specified, context creation errors throw */
onDone?: (err: Error | null, regl?: Regl) => void;
}
interface DefaultContext {
/** The number of frames rendered */
readonly tick: number;
/** Total time elapsed since regl was initialized in seconds */
readonly time: number;
/** Width of the current viewport in pixels */
readonly viewportWidth: number;
/** Height of the current viewport in pixels */
readonly viewportHeight: number;
/** Width of the WebGL context drawing buffer */
readonly drawingBufferWidth: number;
/** Height of the WebGL context drawing buffer */
readonly drawingBufferHeight: number;
/** The pixel ratio of the drawing buffer */
readonly pixelRatio: number;
}
type UserContext<
ParentContext extends REGL.DefaultContext,
OwnContext extends {},
Props extends {}
> = {
[Key in keyof OwnContext]: MaybeDynamic<OwnContext[Key], ParentContext, Props>;
};
interface Cancellable {
cancel(): void;
}
/**
* A handler function invoked when `regl` fires the "frame" event. It is passed the default Context.
*/
type FrameCallback = (context: REGL.DefaultContext) => void;
interface DynamicVariable<Return> {
/**
* This type is supposed to be opaque. Properties are listed only because TS casts _anything_ to `DynamicVariable`.
* The type parameter `Return`, though unused in the body of the interface, is useful as a
* marker to ensure the correct type is rendered when the associated `DrawCommand` is invoked.
*/
readonly id: number;
readonly type: number;
readonly data: string;
}
type DynamicVariableFn<
Return,
Context extends REGL.DefaultContext = REGL.DefaultContext,
Props extends {} = {}
> =
(context: Context, props: Props, batchId: number) => Return;
type MaybeDynamic<Type, Context extends REGL.DefaultContext, Props extends {}> =
Type |
DynamicVariable<Type> |
DynamicVariableFn<Type, Context, Props>;
type MaybeNestedDynamic<Type, Context extends REGL.DefaultContext, Props extends {}> =
{ [K in keyof Type]: MaybeDynamic<Type[K], Context, Props> };
interface ClearOptions {
/**
* RGBA values (range 0-1) to use when the color buffer is cleared. Initial value: [0, 0, 0, 0].
* Relevant WebGL API: `gl.clearColor`
*/
color?: REGL.Vec4;
/**
* Depth value (range 0-1) to use when the depth buffer is cleared. Initial value: 1.
* Relevant WebGL API: `gl.clearDepth`
*/
depth?: number;
/**
* The index used when the stencil buffer is cleared. Initial value: 0.
* Relevant WebGL API: `gl.clearStencil`
*/
stencil?: number;
/**
* Sets the target framebuffer to clear (if unspecified, uses the current framebuffer object).
* Relevant WebGL API: `gl.bindFrameBuffer`
*/
framebuffer?: REGL.Framebuffer | null;
}
interface ReadOptions<T = Uint8Array> {
/** An optional TypedArray which gets the result of reading the pixels. (Default: `null`, i.e. return a new TypedArray) */
data?: T | null;
/** The x-offset of the upper-left corner of the rectangle in pixels. (Default: `0`) */
x?: number;
/** The y-offset of the upper-left corner of the rectangle in pixels. (Default: `0`) */
y?: number;
/** The width of the rectangle in pixels. (Default: current framebuffer width) */
width?: number;
/** The height of the rectangle in pixels (Default: current framebuffer height) */
height?: number;
/** Sets the framebuffer to read pixels from. (Default: currently bound framebuffer) */
framebuffer?: REGL.Framebuffer;
}
/**
* Commands can be nested using scoping. If a `DrawCommand` is passed a `CommandBodyFn`, then the
* `DrawCommand` is evaluated and its state variables are saved as the defaults for all
* `DrawCommand`s invoked within the `CommandBodyFn`.
*
* @param context REGL context
* @param props additional parameters of a draw call
* @param batchId index of a command in a batch call
*/
type CommandBodyFn<
Context extends REGL.DefaultContext = REGL.DefaultContext,
Props extends {} = {}
> = (context: Context, props: Props, batchId: number) => void;
/**
* Draw commands are the fundamental abstraction in regl. A draw command wraps up all of the WebGL
* state associated with a draw call (either drawArrays or drawElements) and packages it into a
* single reusable function.
*/
interface DrawCommand<
Context extends REGL.DefaultContext = REGL.DefaultContext,
Props extends {} = {}
> {
readonly stats: REGL.CommandStats;
/** Run a command once. */
(body?: REGL.CommandBodyFn<Context, Props>): void;
/** Run a command `count` times. */
(count: number, body?: REGL.CommandBodyFn<Context, Props>): void;
/** Run a command with props. */
(props: Partial<Props>, body?: REGL.CommandBodyFn<Context, Props>): void;
/** Run a command batch. */
(props: Array<Partial<Props>>, body?: REGL.CommandBodyFn<Context, Props>): void;
}
interface DrawConfig<
Uniforms extends {} = {},
Attributes extends {} = {},
Props extends {} = {},
OwnContext extends {} = {},
ParentContext extends REGL.DefaultContext = REGL.DefaultContext
> {
/* Shaders */
/** Source code of vertex shader */
vert?: MaybeDynamic<string, ParentContext & OwnContext, Props>;
/** Source code of fragment shader */
frag?: MaybeDynamic<string, ParentContext & OwnContext, Props>;
/**
* Object mapping user-defined keys to user-defined values to be accessed via `DynamicVariable`s
* or `DynamicVariableFn`s elsewhere in the `DrawConfig` or in scoped `DrawCommand`s.
* Context variables in `regl` are computed before any other parameters and can also be passed
* from a scoped command to any sub-commands.
* Both `DynamicVariable`s and `DynamicVariableFn`s can be used as values in the context object,
* making it possible to define new context properties derived from existing context properties
* or from `props`.
*/
context?: REGL.UserContext<ParentContext, OwnContext, Props>,
/**
* Object mapping names of uniform variables to their values.
* To specify uniforms in GLSL structs use the fully qualified path with dot notation.
* example: `'nested.value': 5.3`
* To specify uniforms in GLSL arrays use the fully qualified path with bracket notation.
* example: `'colors[0]': [0, 1, 0, 1]`
*
* Related WebGL APIs
*
* - gl.getUniformLocation
* - gl.uniform
*/
uniforms?: REGL.MaybeDynamicUniforms<Uniforms, ParentContext & OwnContext, Props>,
/**
* Object mapping names of attribute variables to their values.
*
* Related WebGL APIs
*
* - gl.vertexAttribPointer
* - gl.vertexAttrib
* - gl.getAttribLocation
* - gl.vertexAttibDivisor
* - gl.enableVertexAttribArray, gl.disableVertexAttribArray
*/
attributes?: REGL.MaybeDynamicAttributes<Attributes, ParentContext & OwnContext, Props>,
/**
* Configuration of vertex array object
*/
vao?: REGL.MaybeDynamic<REGL.VertexArrayObject | AttributeState[], ParentContext & OwnContext, Props>,
/* Drawing */
/**
* Sets the primitive type. (Default: 'triangles', or inferred from `elements`)
*/
primitive?: MaybeDynamic<REGL.PrimitiveType, ParentContext & OwnContext, Props>;
/**
* Number of vertices to draw. (Default: 0, or inferred from `elements`)
*/
count?: MaybeDynamic<number, ParentContext & OwnContext, Props>;
/**
* Offset of primitives to draw. (Default: 0, or inferred from `elements`)
*/
offset?: MaybeDynamic<number, ParentContext & OwnContext, Props>;
/**
* Number of instances to draw. (Default: 0)
*
* Only applicable if the `ANGLE_instanced_arrays` extension is present.
*/
instances?: MaybeDynamic<number, ParentContext & OwnContext, Props>;
/**
* Element array buffer. (Default: `null`)
*
* Elements must be either an instance of REGL.Elements or else the arguments to REGL.Elements.
* If `elements` is specified while `primitive`, `count` and `offset` are not,
* then these values may be inferred from the state of the element array buffer.
*/
elements?: MaybeDynamic<
REGL.Elements | ElementsData | ElementsOptions | null,
ParentContext & OwnContext,
Props
>;
/* Render target */
/**
* A framebuffer to be used as a target for drawing. (Default: `null`)
* Passing null sets the framebuffer to the drawing buffer.
* Updating the render target will modify the viewport.
*
* Related WebGL APIs
*
* - [gl.bindFramebuffer](https://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindFramebuffer.xml)
*/
framebuffer?: MaybeDynamic<REGL.Framebuffer | null, ParentContext & OwnContext, Props>;
/* Profiling */
/**
* If set, turns on profiling for this command. (Default: `false`)
* Profiling stats can be accessed via the `stats` property of the `DrawCommand`.
*/
profile?: MaybeDynamic<boolean, ParentContext & OwnContext, Props>;
/* Depth buffer */
/**
* Related WebGL APIs
*
* - gl.depthFunc
* - gl.depthMask
* - gl.depthRange
*/
depth?: MaybeDynamic<REGL.DepthTestOptions, ParentContext & OwnContext, Props>;
/* Blending */
/**
* Related WebGL APIs
*
* - gl.blendEquationSeparate
* - gl.blendFuncSeparate
* - gl.blendColor
*/
blend?: MaybeDynamic<REGL.BlendingOptions, ParentContext & OwnContext, Props>;
/* Stencil */
/**
* Related WebGL APIs
*
* - gl.stencilFunc
* - gl.stencilMask
* - gl.stencilOpSeparate
*/
stencil?: MaybeDynamic<REGL.StencilOptions, ParentContext & OwnContext, Props>;
/* Polygon offset */
/**
* Related WebGL APIs
*
* - gl.polygonOffset
*/
polygonOffset?: MaybeDynamic<REGL.PolygonOffsetOptions, ParentContext & OwnContext, Props>;
/* Culling */
cull?: MaybeDynamic<REGL.CullingOptions, ParentContext & OwnContext, Props>;
/* Front face */
/* Sets gl.frontFace. Default: 'ccw' */
frontFace?: MaybeDynamic<REGL.FaceWindingType, ParentContext & OwnContext, Props>;
/* Dithering */
/* Toggles `gl.DITHER`. Default: false */
dither?: MaybeDynamic<boolean, ParentContext & OwnContext, Props>;
/* Line width */
/* Sets `gl.lineWidth`. Default: 1 */
lineWidth?: MaybeDynamic<number, ParentContext & OwnContext, Props>;
/* Color mask */
/* Sets `gl.colorMask`. Default: [true, true, true, true] */
colorMask?: MaybeDynamic<REGL.BVec4, ParentContext & OwnContext, Props>;
/* Sample coverage */
sample?: MaybeDynamic<REGL.SamplingOptions, ParentContext & OwnContext, Props>;
/* Scissor */
scissor?: MaybeNestedDynamic<REGL.ScissorOptions, ParentContext & OwnContext, Props>;
/* Viewport */
/**
* Sets `gl.viewport`. Default: {}
* Updating `viewport` will modify the context variables `viewportWidth` and `viewportHeight`.
*/
viewport?: MaybeDynamic<REGL.BoundingBox, ParentContext & OwnContext, Props>;
}
type PrimitiveType =
/** gl.POINTS */
"points" |
/** gl.LINES */
"lines" |
/** gl.LINE_STRIP */
"line strip" |
/** gl.LINE_LOOP */
"line loop" |
/** gl.TRIANGLES */
"triangles" |
/** gl.TRIANGLE_STRIP */
"triangle strip" |
/** gl.TRIANGLE_FAN */
"triangle fan";
type Uniform =
boolean |
number |
boolean[] |
number[] |
Float32Array |
Int32Array;
interface Uniforms {
[name: string]: Uniform;
}
type MaybeDynamicUniforms<
Uniforms extends REGL.Uniforms,
Context extends REGL.DefaultContext,
Props extends {}
> = {
[Key in keyof Uniforms]: MaybeDynamic<Uniforms[Key], Context, Props>|MaybeDynamic<Uniforms[Key], Context, Props>[];
}
type AttributeState =
ConstantAttribute |
AttributeConfig |
REGL.Buffer |
REGL.BufferData;
type Attribute =
number |
AttributeState;
interface Attributes {
[name: string]: Attribute;
}
type MaybeDynamicAttributes<
Attributes extends REGL.Attributes,
Context extends REGL.DefaultContext,
Props extends {}
> = {
[Key in keyof Attributes]: MaybeDynamic<Attributes[Key], Context, Props>;
}
interface ConstantAttribute {
constant: number | number[];
}
interface AttributeConfig {
/** A REGLBuffer wrapping the buffer object. (Default: null) */
buffer?: REGL.Buffer|undefined|null|false;
/** The offset of the vertexAttribPointer in bytes. (Default: 0) */
offset?: number|undefined;
/** The stride of the vertexAttribPointer in bytes. (Default: 0) */
stride?: number|undefined;
/** Whether the pointer is normalized. (Default: false) */
normalized?: boolean;
/** The size of the vertex attribute. (Default: Inferred from shader) */
size?: number|undefined;
/** Sets gl.vertexAttribDivisorANGLE. Only supported if the ANGLE_instanced_arrays extension is available. (Default: 0) */
divisor?: number|undefined;
/** Data type for attribute */
type?: 'uint8'|'uint16'|'uint32'|'float'|'int8'|'int16'|'int32';
}
interface DepthTestOptions {
/* Toggles `gl.enable(gl.DEPTH_TEST)`. Default: true */
enable?: boolean;
/* Sets `gl.depthMask`. Default: true */
mask?: boolean;
/* Sets `gl.depthRange`. Default: [0, 1] */
range?: [number, number];
/* Sets `gl.depthFunc`. Default: 'less' */
func?: REGL.ComparisonOperatorType;
}
type ComparisonOperatorType =
/* `gl.NEVER` */
"never" |
/* `gl.ALWAYS` */
"always" |
/* `gl.LESS` */
"less" | "<" |
/* `gl.LEQUAL` */
"lequal" | "<=" |
/* `gl.GREATER` */
"greater" | ">" |
/* `gl.GEQUAL` */
"gequal" | ">=" |
/* `gl.EQUAL` */
"equal" | "=" |
/* `gl.NOTEQUAL` */
"notequal" | "!=";
interface BlendingOptions {
/* Toggles `gl.enable(gl.BLEND)`. Default: false */
enable?: boolean;
/**
* `equation` can be either a string or an object with the fields {rgb, alpha}.
* The former corresponds to `gl.blendEquation` and the latter to `gl.blendEquationSeparate`.
* Default: 'add'
*/
equation?: REGL.BlendingEquation | REGL.BlendingEquationSeparate;
/**
* `func` can be an object with the fields {src, dst} or {srcRGB, srcAlpha, dstRGB, dstAlpha},
* with the former corresponding to gl.blendFunc and the latter to gl.blendFuncSeparate.
* Default: { src: 'src alpha', dst: 'one minus src alpha' }
*/
func?: REGL.BlendingFunctionCombined | REGL.BlendingFunctionSeparate;
/* Sets `gl.blendColor` */
color?: REGL.Vec4;
}
interface BlendingEquationSeparate {
rgb: REGL.BlendingEquation;
alpha: REGL.BlendingEquation;
}
type BlendingEquation =
/* `gl.FUNC_ADD` */
"add" |
/* `gl.FUNC_SUBTRACT` */
"subtract" |
/* `gl.FUNC_REVERSE_SUBTRACT` */
"reverse subtract" |
/* `gl.MIN_EXT`, requires `EXT_blend_minmax` */
"min" |
/* `gl.MAX_EXT`, requires `EXT_blend_minmax` */
"max";
interface BlendingFunctionCombined {
src: REGL.BlendingFunction;
dst: REGL.BlendingFunction;
}
interface BlendingFunctionSeparate {
srcRGB: REGL.BlendingFunction;
srcAlpha: REGL.BlendingFunction;
dstRGB: REGL.BlendingFunction;
dstAlpha: REGL.BlendingFunction;
}
type BlendingFunction =
/* `gl.ZERO` */
"zero" | 0 |
/* `gl.ONE` */
"one" | 1 |
/* `gl.SRC_COLOR` */
"src color" |
/* `gl.ONE_MINUS_SRC_COLOR` */
"one minus src color" |
/* `gl.SRC_ALPHA` */
"src alpha" |
/* `gl.ONE_MINUS_SRC_ALPHA` */
"one minus src alpha" |
/* `gl.DST_COLOR` */
"dst color" |
/* `gl.ONE_MINUS_DST_COLOR` */
"one minus dst color" |
/* `gl.DST_ALPHA` */
"dst alpha" |
/* `gl.ONE_MINUS_DST_ALPHA` */
"one minus dst alpha" |
/* `gl.CONSTANT_COLOR` */
"constant color" |
/* `gl.ONE_MINUS_CONSTANT_COLOR` */
"one minus constant color" |
/* `gl.CONSTANT_ALPHA` */
"constant alpha" |
/* `gl.ONE_MINUS_CONSTANT_ALPHA` */
"one minus constant alpha" |
/* `gl.SRC_ALPHA_SATURATE` */
"src alpha saturate";
interface StencilOptions {
/* Toggles `gl.enable(gl.STENCIL_TEST)`. Default: false */
enable?: boolean;
/* Sets `gl.stencilMask`. Default: -1 */
mask?: number;
/* Sets `gl.stencilFunc`. Default: { cmp: 'always', ref: 0, mask: -1 } */
func?: REGL.StencilFunction;
/**
* Sets `gl.stencilOpSeparate` for front face.
* Default: { fail: 'keep', zfail: 'keep', zpass: 'keep' }
*/
opFront?: REGL.StencilOperation;
/**
* Sets `gl.stencilOpSeparate` for back face.
* Default: { fail: 'keep', zfail: 'keep', zpass: 'keep' }
*/
opBack?: REGL.StencilOperation;
/* Sets opFront and opBack simultaneously (`gl.stencilOp`). */
op?: REGL.StencilOperation;
}
interface StencilFunction {
/* comparison function */
cmp: REGL.ComparisonOperatorType;
/* reference value */
ref: number;
/* comparison mask */
mask: number;
}
interface StencilOperation {
/* The stencil operation applied when the stencil test fails. */
fail: REGL.StencilOperationType;
/* The stencil operation applied when the stencil test passes and the depth test fails. */
zfail: REGL.StencilOperationType;
/* The stencil operation applied when when both stencil and depth tests pass. */
zpass: REGL.StencilOperationType;
}
type StencilOperationType =
/* `gl.ZERO` */
"zero" |
/* `gl.KEEP` */
"keep" |
/* `gl.REPLACE` */
"replace" |
/* `gl.INVERT` */
"invert" |
/* `gl.INCR` */
"increment" |
/* `gl.DECR` */
"decrement" |
/* `gl.INCR_WRAP` */
"increment wrap" |
/* `gl.DECR_WRAP` */
"decrement wrap";
interface PolygonOffsetOptions {
/* Toggles `gl.enable(gl.POLYGON_OFFSET_FILL)`. Default: false */
enable?: boolean;
/* Sets `gl.polygonOffset`. Default: { factor: 0, units: 0 } */
offset?: REGL.PolygonOffset;
}
interface PolygonOffset {
factor: number;
units: number;
}
interface CullingOptions {
/* Toggles `gl.enable(gl.CULL_FACE)`. Default: false */
enable?: boolean;
/* Sets `gl.cullFace`. Default: 'back' */
face?: REGL.FaceOrientationType;
}
type FaceOrientationType =
/* `gl.FRONT` */
"front" |
/* `gl.BACK` */
"back";
type FaceWindingType =
/* `gl.CW` */
"cw" |
/* `gl.CCW` */
"ccw";
interface SamplingOptions {
/** Toggles `gl.enable(gl.SAMPLE_COVERAGE)`. Default: false */
enable?: boolean;
/** Toggles `gl.enable(gl.SAMPLE_ALPHA_TO_COVERAGE)`. Default: false */
alpha?: boolean;
/** Sets `gl.sampleCoverage`. Default: { value: 1, invert: false } */
coverage?: REGL.SampleCoverage;
}
interface SampleCoverage {
value: number;
invert: boolean;
}
interface ScissorOptions {
/* Toggles gl.enable(gl.SCISSOR). Default: false */
enable?: boolean;
/* Sets `gl.SCISSOR`. Default: {} */
box?: REGL.BoundingBox;
}
interface BoundingBox {
/* left coordinate of the box; Default: 0 */
x?: number;
/* top coordiante of the box; Default: 0 */
y?: number;
/* width of the box; Default: framebuffer width - `x` */
width?: number;
/* height of the box; Default: framebuffer height - `y` */
height?: number;
}
/*
* Resources
*/
/**
* A *resource* is a handle to a GPU resident object, like a texture, FBO or buffer.
*/
interface Resource {
/**
* relevant WebGL APIs:
* - `gl.deleteBuffer`
* - `gl.deleteTexture`
* - `gl.deleteRenderbuffer`
* - `gl.deleteFramebuffer`
*/
destroy(): void;
}
interface VertexArrayObject extends REGL.Resource {
(attributes:REGL.AttributeState[] | REGL.VertexArrayOptions) : REGL.VertexArrayObject;
}
interface Buffer extends REGL.Resource {
/**
* Wraps a WebGL array buffer object.
*/
readonly stats: {
/** The size of the buffer in bytes. */
size: number;
}
/**
* Reinitializes the buffer with the new content.
* Relevant WebGL API: `gl.bufferData`
*/
(data: REGL.BufferData): REGL.Buffer;
(options: REGL.BufferOptions): REGL.Buffer;
/**
* Update a portion of the buffer, optionally starting at byte offset `offset`.
* Relevant WebGL API: `gl.bufferSubData`
*/
subdata(data: REGL.BufferData, offset?: number): REGL.Buffer;
subdata(options: REGL.BufferOptions, offset?: number): REGL.Buffer;
}
interface BufferOptions {
/** The data for the vertex buffer. Default: null */
data?: REGL.BufferData | null;
/** If `data` is `null` or not present reserves space for the buffer. Default: 0 */
length?: number;
/** Sets array buffer usage hint. Default: 'static' */
usage?: REGL.BufferUsageHint;
/** Data type for vertex buffer. Default: 'uint8' */
type?: REGL.BufferDataType;
}
type BufferData =
number[] |
number[][] |
Uint8Array |
Int8Array |
Uint16Array |
Int16Array |