1 | // Type definitions for regl 1.3.1
|
2 | // Project: regl
|
3 | // Definitions by: Stepan Stolyarov <stepan.stolyarov@gmail.com>, David Schneider <github.com/davschne>
|
4 |
|
5 | /*~ Note that ES6 modules cannot directly export callable functions.
|
6 | *~ This file should be imported using the CommonJS-style:
|
7 | *~
|
8 | *~ ```typescript
|
9 | *~ import REGL = require('regl');
|
10 | *~ ```
|
11 | *~
|
12 | *~ Refer to the documentation to understand common
|
13 | *~ workarounds for this limitation of ES6 modules.
|
14 | */
|
15 |
|
16 | /*~ This module is a UMD module that exposes a global function `createREGL`. */
|
17 | export as namespace createREGL;
|
18 |
|
19 | export = REGL;
|
20 |
|
21 | /**
|
22 | * Creates a full screen canvas element and a WebGL rendering context.
|
23 | */
|
24 | declare function REGL(): REGL.Regl;
|
25 |
|
26 | /**
|
27 | * Creates a WebGL rendering context using an element selected by `selector`.
|
28 | * This may be:
|
29 | * 1) an existing HTMLCanvasElement
|
30 | * 2) an element that contains a canvas
|
31 | * 3) an element in which you'd like `regl` to create a canvas
|
32 | *
|
33 | * @param selector an argument to `document.querySelector`
|
34 | */
|
35 | declare function REGL(selector: string): REGL.Regl;
|
36 |
|
37 | /**
|
38 | * Creates a canvas element and a WebGL rendering context in a given container element.
|
39 | *
|
40 | * @param container an HTML element
|
41 | */
|
42 | declare function REGL(container: HTMLElement): REGL.Regl;
|
43 |
|
44 | /**
|
45 | * Creates a WebGL rendering context using a `<canvas>` element.
|
46 | *
|
47 | * @param canvas HTML canvas element
|
48 | */
|
49 | declare function REGL(canvas: HTMLCanvasElement): REGL.Regl;
|
50 |
|
51 | /**
|
52 | * Wraps an existing WebGL rendering context.
|
53 | *
|
54 | * @param gl WebGL rendering context
|
55 | */
|
56 | declare function REGL(gl: WebGLRenderingContext): REGL.Regl;
|
57 |
|
58 | /**
|
59 | * Creates a WebGL according to specified `options`
|
60 | */
|
61 | declare function REGL(options: REGL.InitializationOptions): REGL.Regl;
|
62 |
|
63 | declare namespace REGL {
|
64 | /**
|
65 | * `Regl` represents the object/function returned from the `REGL` constructor. It exposes the
|
66 | * entire public interface of the `regl` library.
|
67 | */
|
68 | export interface Regl {
|
69 | /**
|
70 | * The context creation attributes passed to the WebGL context constructor.
|
71 | */
|
72 | readonly attributes: WebGLContextAttributes;
|
73 | /**
|
74 | * `regl` is designed in such a way that you should never have to directly access the underlying
|
75 | * WebGL context. However, if you really absolutely need to do this for some reason (for example
|
76 | * to interface with an external library), you can still get a reference to the WebGL context
|
77 | * via the property `_gl`.
|
78 | */
|
79 | readonly _gl: WebGLRenderingContext;
|
80 | /**
|
81 | * `regl` exposes info about the WebGL context limits and capabilities via the `limits` object.
|
82 | */
|
83 | readonly limits: REGL.Limits;
|
84 | /**
|
85 | * `regl` tracks several metrics for performance monitoring. These can be read using the `stats` object.
|
86 | */
|
87 | readonly stats: REGL.Stats;
|
88 |
|
89 | /**
|
90 | * Creates a new REGL command. The resulting command, when executed,
|
91 | * will set a WebGL state machine to a specified `state`.
|
92 | */
|
93 | <
|
94 | Uniforms extends {} = {},
|
95 | Attributes extends {} = {},
|
96 | Props extends {} = {},
|
97 | OwnContext extends {} = {},
|
98 | ParentContext extends REGL.DefaultContext = REGL.DefaultContext
|
99 | >(
|
100 | drawConfig: REGL.DrawConfig<Uniforms, Attributes, Props, OwnContext, ParentContext>,
|
101 | ): REGL.DrawCommand<ParentContext & OwnContext, Props>;
|
102 |
|
103 | /**
|
104 | * Clears selected buffers to specified values.
|
105 | * If an option is not present, then the corresponding buffer is not cleared.
|
106 | * Relevant WebGL API: `gl.clear`
|
107 | */
|
108 | clear(options: REGL.ClearOptions): void;
|
109 |
|
110 | /* Reading pixels */
|
111 |
|
112 | /**
|
113 | * Read entire screen.
|
114 | * NB: Reading into a Float32Array requires OES_texture_float.
|
115 | */
|
116 | read<T extends Uint8Array | Float32Array = Uint8Array>(): T;
|
117 |
|
118 | /**
|
119 | * Read entire screen into an existing TypedArray.
|
120 | * NB: Reading into a Float32Array requires OES_texture_float.
|
121 | */
|
122 | read<T extends Uint8Array | Float32Array>(data: T): T;
|
123 |
|
124 | /**
|
125 | * Read a selected region of screen or framebuffer.
|
126 | * NB: Reading into a Float32Array requires OES_texture_float.
|
127 | */
|
128 | read<T extends Uint8Array | Float32Array = Uint8Array>(options: REGL.ReadOptions<T>): T;
|
129 |
|
130 | /**
|
131 | * Dynamic variable binding
|
132 | *
|
133 | * `prop`, `context`, and `this` generate DynamicVariables, which can be used as values in a
|
134 | * REGL.DrawConfig object. A DynamicVariable is an abstraction that will render a value only
|
135 | * when the DrawCommand with which it's associated is invoked.
|
136 | */
|
137 |
|
138 | /* Retrieve the property `name` passed when the draw command is executed. */
|
139 | prop<Props extends {}, Key extends keyof Props>(name: Key): DynamicVariable<Props[Key]>;
|
140 | /* Retrieve the context property `name` when the draw command is executed. */
|
141 | context<Context extends REGL.DefaultContext, K extends keyof Context>(name: K): DynamicVariable<Context[K]>;
|
142 | /* Retrieve the property `name` of the object in whose context the draw command is executing. */
|
143 | this<This extends {}, Key extends keyof This>(name: Key): DynamicVariable<This[Key]>;
|
144 |
|
145 | /* Drawing */
|
146 |
|
147 | /** Executes an empty draw command. */
|
148 | draw(): void;
|
149 |
|
150 | /* Resource creation */
|
151 |
|
152 | /** Creates an empty buffer of length `length`. */
|
153 | buffer(length: number): REGL.Buffer;
|
154 | /** Creates a buffer with the provided `data`. */
|
155 | buffer(data: REGL.BufferData): REGL.Buffer;
|
156 | /** Creates a buffer using creation `options`. */
|
157 | buffer(options: REGL.BufferOptions): REGL.Buffer;
|
158 |
|
159 | /* Creates an Elements object with the provided `data`. */
|
160 | elements(data: REGL.ElementsData): REGL.Elements;
|
161 | /* Creates an Elements object using creation `options`. */
|
162 | elements(options: REGL.ElementsOptions): REGL.Elements;
|
163 |
|
164 | /* Creates a 2D Texture of dimensions 1 x 1. */
|
165 | texture(): REGL.Texture2D;
|
166 | /* Creates a 2D Texture of dimensions `radius` x `radius`. */
|
167 | texture(radius: number): REGL.Texture2D;
|
168 | /* Creates a 2D Texture of dimensions `width` x `height`. */
|
169 | texture(width: number, height: number): REGL.Texture2D;
|
170 | /* Creates a 2D Texture using the provided `data`. */
|
171 | texture(data: REGL.TextureImageData): REGL.Texture2D;
|
172 | /* Creates a 2D Texture using creation `options`. */
|
173 | texture(options: REGL.Texture2DOptions): REGL.Texture2D;
|
174 |
|
175 | /* Creates a cube-map texture with faces of dimensions 1 x 1. */
|
176 | cube(): REGL.TextureCube;
|
177 | /* Creates a cube-map texture with faces of dimensions `radius` x `radius`. */
|
178 | cube(radius: number): REGL.TextureCube;
|
179 | /* Creates a cube-map texture using the provided image data for the six faces. */
|
180 | cube(
|
181 | posXData: REGL.TextureImageData, negXData: REGL.TextureImageData,
|
182 | posYData: REGL.TextureImageData, negYData: REGL.TextureImageData,
|
183 | posZData: REGL.TextureImageData, negZData: REGL.TextureImageData
|
184 | ): REGL.TextureCube;
|
185 | /* Creates a cube-map texture using the provided creation options for the six faces. */
|
186 | cube(
|
187 | posXOptions: REGL.Texture2DOptions, negXOptions: REGL.Texture2DOptions,
|
188 | posYOptions: REGL.Texture2DOptions, negYOptions: REGL.Texture2DOptions,
|
189 | posZOptions: REGL.Texture2DOptions, negZOptions: REGL.Texture2DOptions,
|
190 | ): REGL.TextureCube;
|
191 | /* Creates a cube-map texture using creation `options`. */
|
192 | cube(options: REGL.TextureCubeOptions): REGL.TextureCube;
|
193 |
|
194 | /* Creates a Renderbuffer of dimensions 1 x 1. */
|
195 | renderbuffer(): REGL.Renderbuffer;
|
196 | /* Creates a Renderbuffer of dimensions `radius` x `radius`. */
|
197 | renderbuffer(radius: number): REGL.Renderbuffer;
|
198 | /* Creates a Renderbuffer of dimensions `width` x `height`. */
|
199 | renderbuffer(width: number, height: number): REGL.Renderbuffer;
|
200 | /* Creates a Renderbuffer using creation `options`. */
|
201 | renderbuffer(options: REGL.RenderbufferOptions): REGL.Renderbuffer;
|
202 |
|
203 | /* Creates a Framebuffer of dimensions 1 x 1. */
|
204 | framebuffer(): REGL.Framebuffer2D;
|
205 | /* Creates a Framebuffer of dimensions `radius` x `radius`. */
|
206 | framebuffer(radius: number): REGL.Framebuffer2D;
|
207 | /* Creates a Framebuffer of dimensions `width` x `height`. */
|
208 | framebuffer(width: number, height: number): REGL.Framebuffer2D;
|
209 | /* Creates a Framebuffer using creation `options`. */
|
210 | framebuffer(options: REGL.FramebufferOptions): REGL.Framebuffer2D;
|
211 |
|
212 | /* Creates a FramebufferCube whose faces have dimensions 1 x 1. */
|
213 | framebufferCube(): REGL.FramebufferCube;
|
214 | /* Creates a FramebufferCube whose faces have dimensions `radius` x `radius`. */
|
215 | framebufferCube(radius: number): REGL.FramebufferCube;
|
216 | /* Creates a FramebufferCube using creation `options`. */
|
217 | framebufferCube(options: REGL.FramebufferCubeOptions): REGL.FramebufferCube;
|
218 |
|
219 | /* Creates a vertex array object */
|
220 | vao(attributes: REGL.AttributeState[]) : REGL.VertexArrayObject;
|
221 |
|
222 | /* Events and listeners */
|
223 |
|
224 | /**
|
225 | * Registers a `callback` to be called on each animation frame.
|
226 | *
|
227 | * This method integrates with `requestAnimationFrame` and context loss
|
228 | * events. It also calls `gl.flush` and drains several internal buffers,
|
229 | * so you should try to do all your rendering to the drawing buffer within
|
230 | * the frame callback.
|
231 | */
|
232 | frame(callback: REGL.FrameCallback): REGL.Cancellable;
|
233 |
|
234 | /**
|
235 | * Registers a handler function to be called when the associated `regl` event is fired.
|
236 | */
|
237 | on(type: 'frame', callback: REGL.FrameCallback): REGL.Cancellable
|
238 | on(type: 'lost' | 'restore' | 'destroy', callback: () => void): REGL.Cancellable;
|
239 |
|
240 | /**
|
241 | * Test if an extension is present. Argument is case insensitive.
|
242 | *
|
243 | * For more information on WebGL extensions, see the WebGL extension registry.
|
244 | *
|
245 | * Relevant WebGL APIs
|
246 | *
|
247 | * - [WebGL Extension Registry](https://www.khronos.org/registry/webgl/extensions/)
|
248 | * - gl.getExtension
|
249 | * - gl.getSupportedExtensions
|
250 | *
|
251 | * @param name case-insensitive name of WebGL extension
|
252 | */
|
253 | hasExtension(name: string): boolean;
|
254 |
|
255 | /**
|
256 | * Updates the values of internal times and recalculates the size of viewports.
|
257 | */
|
258 | poll(): void;
|
259 |
|
260 | /**
|
261 | * Returns Total time elapsed since regl was initialized in seconds.
|
262 | */
|
263 | now(): number;
|
264 |
|
265 | /**
|
266 | * Destroys the gl context and releases all associated resources.
|
267 | */
|
268 | destroy(): void;
|
269 |
|
270 | /**
|
271 | * `regl` is designed in such a way that you should never have to directly access the underlying
|
272 | * WebGL context. However, if you really absolutely need to do this for some reason (for example
|
273 | * to interface with an external library), you can still get a reference to the WebGL context
|
274 | * via the property `REGL._gl`. Note, though, that if you have changed the WebGL state, you must
|
275 | * call `_refresh` to restore the `regl` state in order to prevent rendering errors.
|
276 | */
|
277 | _refresh(): void;
|
278 | }
|
279 |
|
280 | interface InitializationOptions {
|
281 | /** A reference to a WebGL rendering context. (Default created from canvas) */
|
282 | gl?: WebGLRenderingContext;
|
283 | /** An HTML canvas element or a selector string to find this element. (Default created and appended to container)*/
|
284 | canvas?: string | HTMLCanvasElement;
|
285 | /** A container element into which regl inserts a canvas or a selector string to find this element. (Default document.body) */
|
286 | container?: string | HTMLElement;
|
287 | /** The context creation attributes passed to the WebGL context constructor. */
|
288 | attributes?: WebGLContextAttributes;
|
289 | /** A multiplier which is used to scale the canvas size relative to the container. (Default window.devicePixelRatio) */
|
290 | pixelRatio?: number;
|
291 | /** A list of extensions that must be supported by WebGL context. Default [] */
|
292 | extensions?: string | string[];
|
293 | /** A list of extensions which are loaded opportunistically. Default [] */
|
294 | optionalExtensions?: string | string[];
|
295 | /** If set, turns on profiling for all commands by default. (Default false) */
|
296 | profile?: boolean;
|
297 | /** 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 */
|
298 | onDone?: (err: Error | null, regl?: Regl) => void;
|
299 | }
|
300 |
|
301 | interface DefaultContext {
|
302 | /** The number of frames rendered */
|
303 | readonly tick: number;
|
304 | /** Total time elapsed since regl was initialized in seconds */
|
305 | readonly time: number;
|
306 | /** Width of the current viewport in pixels */
|
307 | readonly viewportWidth: number;
|
308 | /** Height of the current viewport in pixels */
|
309 | readonly viewportHeight: number;
|
310 | /** Width of the WebGL context drawing buffer */
|
311 | readonly drawingBufferWidth: number;
|
312 | /** Height of the WebGL context drawing buffer */
|
313 | readonly drawingBufferHeight: number;
|
314 | /** The pixel ratio of the drawing buffer */
|
315 | readonly pixelRatio: number;
|
316 | }
|
317 |
|
318 | type UserContext<
|
319 | ParentContext extends REGL.DefaultContext,
|
320 | OwnContext extends {},
|
321 | Props extends {}
|
322 | > = {
|
323 | [Key in keyof OwnContext]: MaybeDynamic<OwnContext[Key], ParentContext, Props>;
|
324 | };
|
325 |
|
326 | interface Cancellable {
|
327 | cancel(): void;
|
328 | }
|
329 |
|
330 | /**
|
331 | * A handler function invoked when `regl` fires the "frame" event. It is passed the default Context.
|
332 | */
|
333 | type FrameCallback = (context: REGL.DefaultContext) => void;
|
334 |
|
335 | interface DynamicVariable<Return> {
|
336 | /**
|
337 | * This type is supposed to be opaque. Properties are listed only because TS casts _anything_ to `DynamicVariable`.
|
338 | * The type parameter `Return`, though unused in the body of the interface, is useful as a
|
339 | * marker to ensure the correct type is rendered when the associated `DrawCommand` is invoked.
|
340 | */
|
341 | readonly id: number;
|
342 | readonly type: number;
|
343 | readonly data: string;
|
344 | }
|
345 |
|
346 | type DynamicVariableFn<
|
347 | Return,
|
348 | Context extends REGL.DefaultContext = REGL.DefaultContext,
|
349 | Props extends {} = {}
|
350 | > =
|
351 | (context: Context, props: Props, batchId: number) => Return;
|
352 |
|
353 | type MaybeDynamic<Type, Context extends REGL.DefaultContext, Props extends {}> =
|
354 | Type |
|
355 | DynamicVariable<Type> |
|
356 | DynamicVariableFn<Type, Context, Props>;
|
357 |
|
358 | type MaybeNestedDynamic<Type, Context extends REGL.DefaultContext, Props extends {}> =
|
359 | { [K in keyof Type]: MaybeDynamic<Type[K], Context, Props> };
|
360 |
|
361 | interface ClearOptions {
|
362 | /**
|
363 | * RGBA values (range 0-1) to use when the color buffer is cleared. Initial value: [0, 0, 0, 0].
|
364 | * Relevant WebGL API: `gl.clearColor`
|
365 | */
|
366 | color?: REGL.Vec4;
|
367 | /**
|
368 | * Depth value (range 0-1) to use when the depth buffer is cleared. Initial value: 1.
|
369 | * Relevant WebGL API: `gl.clearDepth`
|
370 | */
|
371 | depth?: number;
|
372 | /**
|
373 | * The index used when the stencil buffer is cleared. Initial value: 0.
|
374 | * Relevant WebGL API: `gl.clearStencil`
|
375 | */
|
376 | stencil?: number;
|
377 | /**
|
378 | * Sets the target framebuffer to clear (if unspecified, uses the current framebuffer object).
|
379 | * Relevant WebGL API: `gl.bindFrameBuffer`
|
380 | */
|
381 | framebuffer?: REGL.Framebuffer | null;
|
382 | }
|
383 |
|
384 | interface ReadOptions<T = Uint8Array> {
|
385 | /** An optional TypedArray which gets the result of reading the pixels. (Default: `null`, i.e. return a new TypedArray) */
|
386 | data?: T | null;
|
387 | /** The x-offset of the upper-left corner of the rectangle in pixels. (Default: `0`) */
|
388 | x?: number;
|
389 | /** The y-offset of the upper-left corner of the rectangle in pixels. (Default: `0`) */
|
390 | y?: number;
|
391 | /** The width of the rectangle in pixels. (Default: current framebuffer width) */
|
392 | width?: number;
|
393 | /** The height of the rectangle in pixels (Default: current framebuffer height) */
|
394 | height?: number;
|
395 | /** Sets the framebuffer to read pixels from. (Default: currently bound framebuffer) */
|
396 | framebuffer?: REGL.Framebuffer;
|
397 | }
|
398 |
|
399 | /**
|
400 | * Commands can be nested using scoping. If a `DrawCommand` is passed a `CommandBodyFn`, then the
|
401 | * `DrawCommand` is evaluated and its state variables are saved as the defaults for all
|
402 | * `DrawCommand`s invoked within the `CommandBodyFn`.
|
403 | *
|
404 | * @param context REGL context
|
405 | * @param props additional parameters of a draw call
|
406 | * @param batchId index of a command in a batch call
|
407 | */
|
408 | type CommandBodyFn<
|
409 | Context extends REGL.DefaultContext = REGL.DefaultContext,
|
410 | Props extends {} = {}
|
411 | > = (context: Context, props: Props, batchId: number) => void;
|
412 |
|
413 | /**
|
414 | * Draw commands are the fundamental abstraction in regl. A draw command wraps up all of the WebGL
|
415 | * state associated with a draw call (either drawArrays or drawElements) and packages it into a
|
416 | * single reusable function.
|
417 | */
|
418 | interface DrawCommand<
|
419 | Context extends REGL.DefaultContext = REGL.DefaultContext,
|
420 | Props extends {} = {}
|
421 | > {
|
422 | readonly stats: REGL.CommandStats;
|
423 |
|
424 | /** Run a command once. */
|
425 | (body?: REGL.CommandBodyFn<Context, Props>): void;
|
426 | /** Run a command `count` times. */
|
427 | (count: number, body?: REGL.CommandBodyFn<Context, Props>): void;
|
428 | /** Run a command with props. */
|
429 | (props: Partial<Props>, body?: REGL.CommandBodyFn<Context, Props>): void;
|
430 | /** Run a command batch. */
|
431 | (props: Array<Partial<Props>>, body?: REGL.CommandBodyFn<Context, Props>): void;
|
432 | }
|
433 |
|
434 | interface DrawConfig<
|
435 | Uniforms extends {} = {},
|
436 | Attributes extends {} = {},
|
437 | Props extends {} = {},
|
438 | OwnContext extends {} = {},
|
439 | ParentContext extends REGL.DefaultContext = REGL.DefaultContext
|
440 | > {
|
441 |
|
442 | /* Shaders */
|
443 |
|
444 | /** Source code of vertex shader */
|
445 | vert?: MaybeDynamic<string, ParentContext & OwnContext, Props>;
|
446 | /** Source code of fragment shader */
|
447 | frag?: MaybeDynamic<string, ParentContext & OwnContext, Props>;
|
448 |
|
449 | /**
|
450 | * Object mapping user-defined keys to user-defined values to be accessed via `DynamicVariable`s
|
451 | * or `DynamicVariableFn`s elsewhere in the `DrawConfig` or in scoped `DrawCommand`s.
|
452 | * Context variables in `regl` are computed before any other parameters and can also be passed
|
453 | * from a scoped command to any sub-commands.
|
454 | * Both `DynamicVariable`s and `DynamicVariableFn`s can be used as values in the context object,
|
455 | * making it possible to define new context properties derived from existing context properties
|
456 | * or from `props`.
|
457 | */
|
458 | context?: REGL.UserContext<ParentContext, OwnContext, Props>,
|
459 |
|
460 | /**
|
461 | * Object mapping names of uniform variables to their values.
|
462 | * To specify uniforms in GLSL structs use the fully qualified path with dot notation.
|
463 | * example: `'nested.value': 5.3`
|
464 | * To specify uniforms in GLSL arrays use the fully qualified path with bracket notation.
|
465 | * example: `'colors[0]': [0, 1, 0, 1]`
|
466 | *
|
467 | * Related WebGL APIs
|
468 | *
|
469 | * - gl.getUniformLocation
|
470 | * - gl.uniform
|
471 | */
|
472 | uniforms?: REGL.MaybeDynamicUniforms<Uniforms, ParentContext & OwnContext, Props>,
|
473 |
|
474 | /**
|
475 | * Object mapping names of attribute variables to their values.
|
476 | *
|
477 | * Related WebGL APIs
|
478 | *
|
479 | * - gl.vertexAttribPointer
|
480 | * - gl.vertexAttrib
|
481 | * - gl.getAttribLocation
|
482 | * - gl.vertexAttibDivisor
|
483 | * - gl.enableVertexAttribArray, gl.disableVertexAttribArray
|
484 | */
|
485 | attributes?: REGL.MaybeDynamicAttributes<Attributes, ParentContext & OwnContext, Props>,
|
486 |
|
487 | /**
|
488 | * Configuration of vertex array object
|
489 | */
|
490 | vao?: REGL.MaybeDynamic<REGL.VertexArrayObject | AttributeState[], ParentContext & OwnContext, Props>,
|
491 |
|
492 | /* Drawing */
|
493 |
|
494 | /**
|
495 | * Sets the primitive type. (Default: 'triangles', or inferred from `elements`)
|
496 | */
|
497 | primitive?: MaybeDynamic<REGL.PrimitiveType, ParentContext & OwnContext, Props>;
|
498 | /**
|
499 | * Number of vertices to draw. (Default: 0, or inferred from `elements`)
|
500 | */
|
501 | count?: MaybeDynamic<number, ParentContext & OwnContext, Props>;
|
502 | /**
|
503 | * Offset of primitives to draw. (Default: 0, or inferred from `elements`)
|
504 | */
|
505 | offset?: MaybeDynamic<number, ParentContext & OwnContext, Props>;
|
506 | /**
|
507 | * Number of instances to draw. (Default: 0)
|
508 | *
|
509 | * Only applicable if the `ANGLE_instanced_arrays` extension is present.
|
510 | */
|
511 | instances?: MaybeDynamic<number, ParentContext & OwnContext, Props>;
|
512 | /**
|
513 | * Element array buffer. (Default: `null`)
|
514 | *
|
515 | * Elements must be either an instance of REGL.Elements or else the arguments to REGL.Elements.
|
516 | * If `elements` is specified while `primitive`, `count` and `offset` are not,
|
517 | * then these values may be inferred from the state of the element array buffer.
|
518 | */
|
519 | elements?: MaybeDynamic<
|
520 | REGL.Elements | ElementsData | ElementsOptions | null,
|
521 | ParentContext & OwnContext,
|
522 | Props
|
523 | >;
|
524 |
|
525 | /* Render target */
|
526 |
|
527 | /**
|
528 | * A framebuffer to be used as a target for drawing. (Default: `null`)
|
529 | * Passing null sets the framebuffer to the drawing buffer.
|
530 | * Updating the render target will modify the viewport.
|
531 | *
|
532 | * Related WebGL APIs
|
533 | *
|
534 | * - [gl.bindFramebuffer](https://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindFramebuffer.xml)
|
535 | */
|
536 | framebuffer?: MaybeDynamic<REGL.Framebuffer | null, ParentContext & OwnContext, Props>;
|
537 |
|
538 | /* Profiling */
|
539 |
|
540 | /**
|
541 | * If set, turns on profiling for this command. (Default: `false`)
|
542 | * Profiling stats can be accessed via the `stats` property of the `DrawCommand`.
|
543 | */
|
544 | profile?: MaybeDynamic<boolean, ParentContext & OwnContext, Props>;
|
545 |
|
546 | /* Depth buffer */
|
547 |
|
548 | /**
|
549 | * Related WebGL APIs
|
550 | *
|
551 | * - gl.depthFunc
|
552 | * - gl.depthMask
|
553 | * - gl.depthRange
|
554 | */
|
555 | depth?: MaybeDynamic<REGL.DepthTestOptions, ParentContext & OwnContext, Props>;
|
556 |
|
557 | /* Blending */
|
558 |
|
559 | /**
|
560 | * Related WebGL APIs
|
561 | *
|
562 | * - gl.blendEquationSeparate
|
563 | * - gl.blendFuncSeparate
|
564 | * - gl.blendColor
|
565 | */
|
566 | blend?: MaybeDynamic<REGL.BlendingOptions, ParentContext & OwnContext, Props>;
|
567 |
|
568 | /* Stencil */
|
569 |
|
570 | /**
|
571 | * Related WebGL APIs
|
572 | *
|
573 | * - gl.stencilFunc
|
574 | * - gl.stencilMask
|
575 | * - gl.stencilOpSeparate
|
576 | */
|
577 | stencil?: MaybeDynamic<REGL.StencilOptions, ParentContext & OwnContext, Props>;
|
578 |
|
579 | /* Polygon offset */
|
580 |
|
581 | /**
|
582 | * Related WebGL APIs
|
583 | *
|
584 | * - gl.polygonOffset
|
585 | */
|
586 | polygonOffset?: MaybeDynamic<REGL.PolygonOffsetOptions, ParentContext & OwnContext, Props>;
|
587 |
|
588 | /* Culling */
|
589 |
|
590 | cull?: MaybeDynamic<REGL.CullingOptions, ParentContext & OwnContext, Props>;
|
591 |
|
592 | /* Front face */
|
593 |
|
594 | /* Sets gl.frontFace. Default: 'ccw' */
|
595 | frontFace?: MaybeDynamic<REGL.FaceWindingType, ParentContext & OwnContext, Props>;
|
596 |
|
597 | /* Dithering */
|
598 |
|
599 | /* Toggles `gl.DITHER`. Default: false */
|
600 | dither?: MaybeDynamic<boolean, ParentContext & OwnContext, Props>;
|
601 |
|
602 | /* Line width */
|
603 |
|
604 | /* Sets `gl.lineWidth`. Default: 1 */
|
605 | lineWidth?: MaybeDynamic<number, ParentContext & OwnContext, Props>;
|
606 |
|
607 | /* Color mask */
|
608 |
|
609 | /* Sets `gl.colorMask`. Default: [true, true, true, true] */
|
610 | colorMask?: MaybeDynamic<REGL.BVec4, ParentContext & OwnContext, Props>;
|
611 |
|
612 | /* Sample coverage */
|
613 |
|
614 | sample?: MaybeDynamic<REGL.SamplingOptions, ParentContext & OwnContext, Props>;
|
615 |
|
616 | /* Scissor */
|
617 |
|
618 | scissor?: MaybeNestedDynamic<REGL.ScissorOptions, ParentContext & OwnContext, Props>;
|
619 |
|
620 | /* Viewport */
|
621 |
|
622 | /**
|
623 | * Sets `gl.viewport`. Default: {}
|
624 | * Updating `viewport` will modify the context variables `viewportWidth` and `viewportHeight`.
|
625 | */
|
626 | viewport?: MaybeDynamic<REGL.BoundingBox, ParentContext & OwnContext, Props>;
|
627 | }
|
628 |
|
629 | type PrimitiveType =
|
630 | /** gl.POINTS */
|
631 | "points" |
|
632 | /** gl.LINES */
|
633 | "lines" |
|
634 | /** gl.LINE_STRIP */
|
635 | "line strip" |
|
636 | /** gl.LINE_LOOP */
|
637 | "line loop" |
|
638 | /** gl.TRIANGLES */
|
639 | "triangles" |
|
640 | /** gl.TRIANGLE_STRIP */
|
641 | "triangle strip" |
|
642 | /** gl.TRIANGLE_FAN */
|
643 | "triangle fan";
|
644 |
|
645 | type Uniform =
|
646 | boolean |
|
647 | number |
|
648 | boolean[] |
|
649 | number[] |
|
650 | Float32Array |
|
651 | Int32Array;
|
652 |
|
653 | interface Uniforms {
|
654 | [name: string]: Uniform;
|
655 | }
|
656 |
|
657 | type MaybeDynamicUniforms<
|
658 | Uniforms extends REGL.Uniforms,
|
659 | Context extends REGL.DefaultContext,
|
660 | Props extends {}
|
661 | > = {
|
662 | [Key in keyof Uniforms]: MaybeDynamic<Uniforms[Key], Context, Props>;
|
663 | }
|
664 |
|
665 | type AttributeState =
|
666 | ConstantAttribute |
|
667 | AttributeConfig |
|
668 | REGL.Buffer |
|
669 | REGL.BufferData;
|
670 |
|
671 | type Attribute =
|
672 | number |
|
673 | AttributeState;
|
674 |
|
675 | interface Attributes {
|
676 | [name: string]: Attribute;
|
677 | }
|
678 |
|
679 | type MaybeDynamicAttributes<
|
680 | Attributes extends REGL.Attributes,
|
681 | Context extends REGL.DefaultContext,
|
682 | Props extends {}
|
683 | > = {
|
684 | [Key in keyof Attributes]: MaybeDynamic<Attributes[Key], Context, Props>;
|
685 | }
|
686 |
|
687 | interface ConstantAttribute {
|
688 | constant: number | number[];
|
689 | }
|
690 |
|
691 | interface AttributeConfig {
|
692 | /** A REGLBuffer wrapping the buffer object. (Default: null) */
|
693 | buffer?: REGL.Buffer|undefined|null|false;
|
694 | /** The offset of the vertexAttribPointer in bytes. (Default: 0) */
|
695 | offset?: number|undefined;
|
696 | /** The stride of the vertexAttribPointer in bytes. (Default: 0) */
|
697 | stride?: number|undefined;
|
698 | /** Whether the pointer is normalized. (Default: false) */
|
699 | normalized?: boolean;
|
700 | /** The size of the vertex attribute. (Default: Inferred from shader) */
|
701 | size?: number|undefined;
|
702 | /** Sets gl.vertexAttribDivisorANGLE. Only supported if the ANGLE_instanced_arrays extension is available. (Default: 0) */
|
703 | divisor?: number|undefined;
|
704 | /** Data type for attribute */
|
705 | type?: 'uint8'|'uint16'|'uint32'|'float'|'int8'|'int16'|'int32';
|
706 | }
|
707 |
|
708 | interface DepthTestOptions {
|
709 | /* Toggles `gl.enable(gl.DEPTH_TEST)`. Default: true */
|
710 | enable?: boolean;
|
711 | /* Sets `gl.depthMask`. Default: true */
|
712 | mask?: boolean;
|
713 | /* Sets `gl.depthRange`. Default: [0, 1] */
|
714 | range?: [number, number];
|
715 | /* Sets `gl.depthFunc`. Default: 'less' */
|
716 | func?: REGL.ComparisonOperatorType;
|
717 | }
|
718 |
|
719 | type ComparisonOperatorType =
|
720 | /* `gl.NEVER` */
|
721 | "never" |
|
722 | /* `gl.ALWAYS` */
|
723 | "always" |
|
724 | /* `gl.LESS` */
|
725 | "less" | "<" |
|
726 | /* `gl.LEQUAL` */
|
727 | "lequal" | "<=" |
|
728 | /* `gl.GREATER` */
|
729 | "greater" | ">" |
|
730 | /* `gl.GEQUAL` */
|
731 | "gequal" | ">=" |
|
732 | /* `gl.EQUAL` */
|
733 | "equal" | "=" |
|
734 | /* `gl.NOTEQUAL` */
|
735 | "notequal" | "!=";
|
736 |
|
737 | interface BlendingOptions {
|
738 | /* Toggles `gl.enable(gl.BLEND)`. Default: false */
|
739 | enable?: boolean;
|
740 | /**
|
741 | * `equation` can be either a string or an object with the fields {rgb, alpha}.
|
742 | * The former corresponds to `gl.blendEquation` and the latter to `gl.blendEquationSeparate`.
|
743 | * Default: 'add'
|
744 | */
|
745 | equation?: REGL.BlendingEquation | REGL.BlendingEquationSeparate;
|
746 | /**
|
747 | * `func` can be an object with the fields {src, dst} or {srcRGB, srcAlpha, dstRGB, dstAlpha},
|
748 | * with the former corresponding to gl.blendFunc and the latter to gl.blendFuncSeparate.
|
749 | * Default: { src: 'src alpha', dst: 'one minus src alpha' }
|
750 | */
|
751 | func?: REGL.BlendingFunctionCombined | REGL.BlendingFunctionSeparate;
|
752 | /* Sets `gl.blendColor` */
|
753 | color?: REGL.Vec4;
|
754 | }
|
755 |
|
756 | interface BlendingEquationSeparate {
|
757 | rgb: REGL.BlendingEquation;
|
758 | alpha: REGL.BlendingEquation;
|
759 | }
|
760 |
|
761 | type BlendingEquation =
|
762 | /* `gl.FUNC_ADD` */
|
763 | "add" |
|
764 | /* `gl.FUNC_SUBTRACT` */
|
765 | "subtract" |
|
766 | /* `gl.FUNC_REVERSE_SUBTRACT` */
|
767 | "reverse subtract" |
|
768 | /* `gl.MIN_EXT`, requires `EXT_blend_minmax` */
|
769 | "min" |
|
770 | /* `gl.MAX_EXT`, requires `EXT_blend_minmax` */
|
771 | "max";
|
772 |
|
773 | interface BlendingFunctionCombined {
|
774 | src: REGL.BlendingFunction;
|
775 | dst: REGL.BlendingFunction;
|
776 | }
|
777 |
|
778 | interface BlendingFunctionSeparate {
|
779 | srcRGB: REGL.BlendingFunction;
|
780 | srcAlpha: REGL.BlendingFunction;
|
781 | dstRGB: REGL.BlendingFunction;
|
782 | dstAlpha: REGL.BlendingFunction;
|
783 | }
|
784 |
|
785 | type BlendingFunction =
|
786 | /* `gl.ZERO` */
|
787 | "zero" | 0 |
|
788 | /* `gl.ONE` */
|
789 | "one" | 1 |
|
790 | /* `gl.SRC_COLOR` */
|
791 | "src color" |
|
792 | /* `gl.ONE_MINUS_SRC_COLOR` */
|
793 | "one minus src color" |
|
794 | /* `gl.SRC_ALPHA` */
|
795 | "src alpha" |
|
796 | /* `gl.ONE_MINUS_SRC_ALPHA` */
|
797 | "one minus src alpha" |
|
798 | /* `gl.DST_COLOR` */
|
799 | "dst color" |
|
800 | /* `gl.ONE_MINUS_DST_COLOR` */
|
801 | "one minus dst color" |
|
802 | /* `gl.DST_ALPHA` */
|
803 | "dst alpha" |
|
804 | /* `gl.ONE_MINUS_DST_ALPHA` */
|
805 | "one minus dst alpha" |
|
806 | /* `gl.CONSTANT_COLOR` */
|
807 | "constant color" |
|
808 | /* `gl.ONE_MINUS_CONSTANT_COLOR` */
|
809 | "one minus constant color" |
|
810 | /* `gl.CONSTANT_ALPHA` */
|
811 | "constant alpha" |
|
812 | /* `gl.ONE_MINUS_CONSTANT_ALPHA` */
|
813 | "one minus constant alpha" |
|
814 | /* `gl.SRC_ALPHA_SATURATE` */
|
815 | "src alpha saturate";
|
816 |
|
817 | interface StencilOptions {
|
818 | /* Toggles `gl.enable(gl.STENCIL_TEST)`. Default: false */
|
819 | enable?: boolean;
|
820 | /* Sets `gl.stencilMask`. Default: -1 */
|
821 | mask?: number;
|
822 | /* Sets `gl.stencilFunc`. Default: { cmp: 'always', ref: 0, mask: -1 } */
|
823 | func?: REGL.StencilFunction;
|
824 | /**
|
825 | * Sets `gl.stencilOpSeparate` for front face.
|
826 | * Default: { fail: 'keep', zfail: 'keep', zpass: 'keep' }
|
827 | */
|
828 | opFront?: REGL.StencilOperation;
|
829 | /**
|
830 | * Sets `gl.stencilOpSeparate` for back face.
|
831 | * Default: { fail: 'keep', zfail: 'keep', zpass: 'keep' }
|
832 | */
|
833 | opBack?: REGL.StencilOperation;
|
834 | /* Sets opFront and opBack simultaneously (`gl.stencilOp`). */
|
835 | op?: REGL.StencilOperation;
|
836 | }
|
837 |
|
838 | interface StencilFunction {
|
839 | /* comparison function */
|
840 | cmp: REGL.ComparisonOperatorType;
|
841 | /* reference value */
|
842 | ref: number;
|
843 | /* comparison mask */
|
844 | mask: number;
|
845 | }
|
846 |
|
847 | interface StencilOperation {
|
848 | /* The stencil operation applied when the stencil test fails. */
|
849 | fail: REGL.StencilOperationType;
|
850 | /* The stencil operation applied when the stencil test passes and the depth test fails. */
|
851 | zfail: REGL.StencilOperationType;
|
852 | /* The stencil operation applied when when both stencil and depth tests pass. */
|
853 | zpass: REGL.StencilOperationType;
|
854 | }
|
855 |
|
856 | type StencilOperationType =
|
857 | /* `gl.ZERO` */
|
858 | "zero" |
|
859 | /* `gl.KEEP` */
|
860 | "keep" |
|
861 | /* `gl.REPLACE` */
|
862 | "replace" |
|
863 | /* `gl.INVERT` */
|
864 | "invert" |
|
865 | /* `gl.INCR` */
|
866 | "increment" |
|
867 | /* `gl.DECR` */
|
868 | "decrement" |
|
869 | /* `gl.INCR_WRAP` */
|
870 | "increment wrap" |
|
871 | /* `gl.DECR_WRAP` */
|
872 | "decrement wrap";
|
873 |
|
874 | interface PolygonOffsetOptions {
|
875 | /* Toggles `gl.enable(gl.POLYGON_OFFSET_FILL)`. Default: false */
|
876 | enable?: boolean;
|
877 | /* Sets `gl.polygonOffset`. Default: { factor: 0, units: 0 } */
|
878 | offset?: REGL.PolygonOffset;
|
879 | }
|
880 |
|
881 | interface PolygonOffset {
|
882 | factor: number;
|
883 | units: number;
|
884 | }
|
885 |
|
886 | interface CullingOptions {
|
887 | /* Toggles `gl.enable(gl.CULL_FACE)`. Default: false */
|
888 | enable?: boolean;
|
889 | /* Sets `gl.cullFace`. Default: 'back' */
|
890 | face?: REGL.FaceOrientationType;
|
891 | }
|
892 |
|
893 | type FaceOrientationType =
|
894 | /* `gl.FRONT` */
|
895 | "front" |
|
896 | /* `gl.BACK` */
|
897 | "back";
|
898 |
|
899 | type FaceWindingType =
|
900 | /* `gl.CW` */
|
901 | "cw" |
|
902 | /* `gl.CCW` */
|
903 | "ccw";
|
904 |
|
905 | interface SamplingOptions {
|
906 | /** Toggles `gl.enable(gl.SAMPLE_COVERAGE)`. Default: false */
|
907 | enable?: boolean;
|
908 | /** Toggles `gl.enable(gl.SAMPLE_ALPHA_TO_COVERAGE)`. Default: false */
|
909 | alpha?: boolean;
|
910 | /** Sets `gl.sampleCoverage`. Default: { value: 1, invert: false } */
|
911 | coverage?: REGL.SampleCoverage;
|
912 | }
|
913 |
|
914 | interface SampleCoverage {
|
915 | value: number;
|
916 | invert: boolean;
|
917 | }
|
918 |
|
919 | interface ScissorOptions {
|
920 | /* Toggles gl.enable(gl.SCISSOR). Default: false */
|
921 | enable?: boolean;
|
922 | /* Sets `gl.SCISSOR`. Default: {} */
|
923 | box?: REGL.BoundingBox;
|
924 | }
|
925 |
|
926 | interface BoundingBox {
|
927 | /* left coordinate of the box; Default: 0 */
|
928 | x?: number;
|
929 | /* top coordiante of the box; Default: 0 */
|
930 | y?: number;
|
931 | /* width of the box; Default: framebuffer width - `x` */
|
932 | width?: number;
|
933 | /* height of the box; Default: framebuffer height - `y` */
|
934 | height?: number;
|
935 | }
|
936 |
|
937 | /*
|
938 | * Resources
|
939 | */
|
940 |
|
941 | /**
|
942 | * A *resource* is a handle to a GPU resident object, like a texture, FBO or buffer.
|
943 | */
|
944 | interface Resource {
|
945 | /**
|
946 | * relevant WebGL APIs:
|
947 | * - `gl.deleteBuffer`
|
948 | * - `gl.deleteTexture`
|
949 | * - `gl.deleteRenderbuffer`
|
950 | * - `gl.deleteFramebuffer`
|
951 | */
|
952 | destroy(): void;
|
953 | }
|
954 |
|
955 | interface VertexArrayObject extends REGL.Resource {
|
956 | (attributes:REGL.AttributeState[]) : REGL.VertexArrayObject;
|
957 | }
|
958 |
|
959 | interface Buffer extends REGL.Resource {
|
960 | /**
|
961 | * Wraps a WebGL array buffer object.
|
962 | */
|
963 | readonly stats: {
|
964 | /** The size of the buffer in bytes. */
|
965 | size: number;
|
966 | }
|
967 |
|
968 | /**
|
969 | * Reinitializes the buffer with the new content.
|
970 | * Relevant WebGL API: `gl.bufferData`
|
971 | */
|
972 | (data: REGL.BufferData): REGL.Buffer;
|
973 | (options: REGL.BufferOptions): REGL.Buffer;
|
974 |
|
975 | /**
|
976 | * Update a portion of the buffer, optionally starting at byte offset `offset`.
|
977 | * Relevant WebGL API: `gl.bufferSubData`
|
978 | */
|
979 | subdata(data: REGL.BufferData, offset?: number): REGL.Buffer;
|
980 | subdata(options: REGL.BufferOptions, offset?: number): REGL.Buffer;
|
981 | }
|
982 |
|
983 | interface BufferOptions {
|
984 | /** The data for the vertex buffer. Default: null */
|
985 | data?: REGL.BufferData | null;
|
986 | /** If `data` is `null` or not present reserves space for the buffer. Default: 0 */
|
987 | length?: number;
|
988 | /** Sets array buffer usage hint. Default: 'static' */
|
989 | usage?: REGL.BufferUsageHint;
|
990 | /** Data type for vertex buffer. Default: 'uint8' */
|
991 | type?: REGL.BufferDataType;
|
992 | }
|
993 |
|
994 | type BufferData =
|
995 | number[] |
|
996 | number[][] |
|
997 | Uint8Array |
|
998 | Int8Array |
|
999 | Uint16Array |
|
1000 | Int16Array |
|
1001 | Uint32Array |
|
1002 | Int32Array |
|
1003 | Float32Array;
|
1004 |
|
1005 | type BufferUsageHint =
|
1006 | /** gl.DRAW_STATIC */
|
1007 | "static" |
|
1008 | /** gl.DYNAMIC_DRAW */
|
1009 | "dynamic" |
|
1010 | /** gl.STREAM_DRAW */
|
1011 | "stream";
|
1012 |
|
1013 | type BufferDataType =
|
1014 | /** gl.UNSIGNED_BYTE */
|
1015 | "uint8" |
|
1016 | /** gl.BYTE */
|
1017 | "int8" |
|
1018 | /** gl.UNSIGNED_SHORT */
|
1019 | "uint16" |
|
1020 | /** gl.SHORT */
|
1021 | "int16" |
|
1022 | /** gl.UNSIGNED_INT */
|
1023 | "uint32" |
|
1024 | /** gl.INT */
|
1025 | "int32" |
|
1026 | /** gl.FLOAT */
|
1027 | "float32" | "float";
|
1028 |
|
1029 | interface Elements extends REGL.Resource {
|
1030 | /**
|
1031 | * Wraps a WebGL element array buffer object.
|
1032 | */
|
1033 |
|
1034 | /**
|
1035 | * Reinitializes the element buffer with the new content.
|
1036 | * Relevant WebGL API: `gl.bufferData`
|
1037 | */
|
1038 | (data: REGL.ElementsData): REGL.Elements;
|
1039 | (options: REGL.ElementsOptions): REGL.Elements;
|
1040 |
|
1041 | /**
|
1042 | * Update a portion of the element buffer, optionally starting at byte offset `offset`.
|
1043 | * Relevant WebGL API: `gl.bufferSubData`
|
1044 | */
|
1045 | subdata(data: REGL.ElementsData, offset?: number): REGL.Elements;
|
1046 | subdata(options: REGL.ElementsOptions, offset?: number): REGL.Elements;
|
1047 | }
|
1048 |
|
1049 | interface ElementsOptions {
|
1050 | /** The data of the element buffer. (Default: null) */
|
1051 | data?: REGL.ElementsData | null;
|
1052 | /** Usage hint (see gl.bufferData). (Default: 'static') */
|
1053 | usage?: REGL.BufferUsageHint;
|
1054 | /** Length of the element buffer in bytes. (Default: 0, or inferred from `data`) */
|
1055 | length?: number;
|
1056 | /** Default primitive type for element buffer. (Default: 0, or inferred from `data`) */
|
1057 | primitive?: REGL.PrimitiveType;
|
1058 | /** Data type for element buffer. (Default: 'uint8') */
|
1059 | type?: REGL.ElementsDataType;
|
1060 | /** Vertex count for element buffer. (Default: 0, or inferred from `data`) */
|
1061 | count?: number;
|
1062 | }
|
1063 |
|
1064 | type ElementsData =
|
1065 | number[] |
|
1066 | number[][] |
|
1067 | Uint8Array |
|
1068 | Uint16Array |
|
1069 | Uint32Array;
|
1070 |
|
1071 | type ElementsDataType =
|
1072 | "uint8" |
|
1073 | "uint16" |
|
1074 | "uint32";
|
1075 |
|
1076 | interface Texture extends Resource {
|
1077 | readonly stats: {
|
1078 | /** Size of the texture in bytes. */
|
1079 | size: number;
|
1080 | }
|
1081 |
|
1082 | /** Width of texture. */
|
1083 | readonly width: number;
|
1084 | /** Height of texture. */
|
1085 | readonly height: number;
|
1086 | /** Texture format. */
|
1087 | readonly format: REGL.TextureFormatType;
|
1088 | /** Texture data type. */
|
1089 | readonly type: REGL.TextureDataType;
|
1090 | /** Texture magnification filter. */
|
1091 | readonly mag: REGL.TextureMagFilterType;
|
1092 | /** Texture minification filter. */
|
1093 | readonly min: REGL.TextureMinFilterType;
|
1094 | /** Texture wrap mode on S axis. */
|
1095 | readonly wrapS: REGL.TextureWrapModeType;
|
1096 | /** Texture wrap mode on T axis. */
|
1097 | readonly wrapT: REGL.TextureWrapModeType;
|
1098 | }
|
1099 |
|
1100 | type TextureFormatType =
|
1101 | /* `gl.ALPHA`; channels: 1; types: 'uint8', 'half float', 'float' */
|
1102 | "alpha" |
|
1103 | /* `gl.LUMINANCE`; channels: 1; types: 'uint8', 'half float', 'float' */
|
1104 | "luminance" |
|
1105 | /* `gl.LUMINANCE_ALPHA`; channels: 2; types: 'uint8', 'half float', 'float' */
|
1106 | "luminance alpha" |
|
1107 | /* `gl.RGB`; channels: 3; types: 'uint8', 'half float', 'float' */
|
1108 | "rgb" |
|
1109 | /* `gl.RGBA`; channels: 4; types: 'uint8', 'half float', 'float' */
|
1110 | "rgba" |
|
1111 | /* `gl.RGBA4`; channels: 4; types: 'rgba4' */
|
1112 | "rgba4" |
|
1113 | /* `gl.RGB5_A1`; channels: 4; types: 'rgba5 a1' */
|
1114 | "rgb5 a1" |
|
1115 | /* `gl.RGB565`; channels: 3; types: 'rgb565' */
|
1116 | "rgb565" |
|
1117 | /* `ext.SRGB`; channels: 3; types: 'uint8', 'half float', 'float' */
|
1118 | "srgb" |
|
1119 | /* `ext.RGBA`; channels: 4; types: 'uint8', 'half float', 'float' */
|
1120 | "srgba" |
|
1121 | /* `gl.DEPTH_COMPONENT`; channels: 1; types: 'uint16', 'uint32' */
|
1122 | "depth" |
|
1123 | /* `gl.DEPTH_STENCIL`; channels: 2; 'depth stencil' */
|
1124 | "depth stencil" |
|
1125 | /* `ext.COMPRESSED_RGB_S3TC_DXT1_EXT`; channels: 3; types: 'uint8' */
|
1126 | "rgb s3tc dxt1" |
|
1127 | /* `ext.COMPRESSED_RGBA_S3TC_DXT1_EXT`; channels: 4; types: 'uint8' */
|
1128 | "rgba s3tc dxt1" |
|
1129 | /* `ext.COMPRESSED_RGBA_S3TC_DXT3_EXT`; channels: 4; types: 'uint8' */
|
1130 | "rgba s3tc dxt3" |
|
1131 | /* `ext.COMPRESSED_RGBA_S3TC_DXT5_EXT`; channels: 4; types: 'uint8' */
|
1132 | "rgba s3tc dxt5" |
|
1133 | /* `ext.COMPRESSED_RGB_ATC_WEBGL`; channels: 3; types: 'uint8' */
|
1134 | "rgb atc" |
|
1135 | /* `ext.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL`; channels: 4; types: 'uint8' */
|
1136 | "rgba atc explicit alpha" |
|
1137 | /* `ext.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL`; channels: 4; types: 'uint8' */
|
1138 | "rgba atc interpolated alpha" |
|
1139 | /* `ext.COMPRESSED_RGB_PVRTC_4BPPV1_IMG`; channels: 3; types: 'uint8' */
|
1140 | "rgb pvrtc 4bppv1" |
|
1141 | /* `ext.COMPRESSED_RGB_PVRTC_2BPPV1_IMG`; channels: 3; types: 'uint8' */
|
1142 | "rgb pvrtc 2bppv1" |
|
1143 | /* `ext.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG`; channels: 4; types: 'uint8' */
|
1144 | "rgba pvrtc 4bppv1" |
|
1145 | /* `ext.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG`; channels: 4; types: 'uint8' */
|
1146 | "rgba pvrtc 2bppv1" |
|
1147 | /* `ext.COMPRESSED_RGB_ETC1_WEBGL`; channels: 3; types: 'uint8' */
|
1148 | "rgb etc1";
|
1149 |
|
1150 | type TextureDataType =
|
1151 | /* `gl.UNSIGNED_BYTE` */
|
1152 | "uint8" |
|
1153 | /* `gl.UNSIGNED_SHORT` */
|
1154 | "uint16" |
|
1155 | /* `gl.UNSIGNED_INT` */
|
1156 | "uint32" |
|
1157 | /* `gl.FLOAT` */
|
1158 | "float" | "float32" |
|
1159 | /* `ext.HALF_FLOAT_OES` */
|
1160 | "half float" | "float16";
|
1161 |
|
1162 | /* Related WebGL API: `gl.MAG_FILTER` */
|
1163 | type TextureMagFilterType =
|
1164 | /* `gl.NEAREST` */
|
1165 | "nearest" |
|
1166 | /* `gl.LINEAR` */
|
1167 | "linear";
|
1168 |
|
1169 | /* Related WebGL API: `gl.MIN_FILTER` */
|
1170 | type TextureMinFilterType =
|
1171 | /* `gl.NEAREST` */
|
1172 | "nearest" |
|
1173 | /* `gl.LINEAR` */
|
1174 | "linear" |
|
1175 | /* `gl.LINEAR_MIPMAP_LINEAR` */
|
1176 | "linear mipmap linear" | "mipmap" |
|
1177 | /* `gl.NEAREST_MIPMAP_LINEAR` */
|
1178 | "nearest mipmap linear" |
|
1179 | /* `gl.LINEAR_MIPMAP_NEAREST` */
|
1180 | "linear mipmap nearest" |
|
1181 | /* `gl.NEAREST_MIPMAP_NEAREST` */
|
1182 | "nearest mipmap nearest";
|
1183 |
|
1184 | type TextureWrapModeType =
|
1185 | /* `gl.REPEAT` */
|
1186 | "repeat" |
|
1187 | /* `gl.CLAMP_TO_EDGE` */
|
1188 | "clamp" |
|
1189 | /* `gl.MIRRORED_REPEAT` */
|
1190 | "mirror";
|
1191 |
|
1192 | interface Texture2D extends Texture {
|
1193 | /* Reinitializes the texture in place with dimensions 1 x 1. */
|
1194 | (): REGL.Texture2D;
|
1195 | /* Reinitializes the texture in place with dimensions `radius` x `radius`. */
|
1196 | (radius: number): REGL.Texture2D;
|
1197 | /* Reinitializes the texture in place with dimensions `width` x `height`. */
|
1198 | (width: number, height: number): REGL.Texture2D;
|
1199 | /* Reinitializes the texture in place using the provided `data`. */
|
1200 | (data: REGL.TextureImageData): REGL.Texture2D;
|
1201 | /* Reinitializes the texture in place using creation `options`. */
|
1202 | (options: REGL.Texture2DOptions): REGL.Texture2D;
|
1203 |
|
1204 | /**
|
1205 | * Replaces the part of texture with new data.
|
1206 | *
|
1207 | * @param data image data object, similar to arguments for the texture constructor
|
1208 | * @param x horizontal offset of the image within the texture (Default: `0`)
|
1209 | * @param y vertical offset of the image within the texture (Default: `0`)
|
1210 | * @param level mipmap level of the texture to modify (Default: `0`)
|
1211 | */
|
1212 | /* Replaces the area at offset `x` (default: 0), `y` (default: 0), with `data`. */
|
1213 | subimage(data: REGL.TextureImageData, x?: number, y?: number, level?: number): REGL.Texture2D;
|
1214 | /* Replaces a subset of the image using creation `options`. */
|
1215 | subimage(options: Texture2DOptions, x?: number, y?: number, level?: number): REGL.Texture2D;
|
1216 |
|
1217 | /** Resizes the texture to `radius` x `radius`. */
|
1218 | resize(radius: number): REGL.Texture2D;
|
1219 | /** Resizes the texture to dimensions `width` x `height`. */
|
1220 | resize(width: number, height: number): REGL.Texture2D;
|
1221 | }
|
1222 |
|
1223 | interface Texture2DOptions {
|
1224 | /* Sets `width`, `height` and, optionally, `channels`. */
|
1225 | shape?: [number, number] | [number, number, REGL.TextureChannelsType];
|
1226 | /* Sets both width and height to the same value. */
|
1227 | radius?: number;
|
1228 | /* Width of texture. Default: 0 */
|
1229 | width?: number;
|
1230 | /* Height of texture. Default: 0 */
|
1231 | height?: number;
|
1232 | /**
|
1233 | * Sets the number of color channels for the texture format.
|
1234 | * It can be used as an alternative to `format`.
|
1235 | * Default: null
|
1236 | */
|
1237 | channels?: REGL.TextureChannelsType | null;
|
1238 | /**
|
1239 | * The following properties, `data` and `copy` are mutually exclusive.
|
1240 | */
|
1241 | /* Image data for the texture. Default: null */
|
1242 | data?: REGL.TextureImageData | null;
|
1243 | /* Create texture by copying the pixels in the current frame buffer. Default: false */
|
1244 | copy?: boolean;
|
1245 |
|
1246 | /* Sets magnification filter. Default: 'nearest' */
|
1247 | mag?: REGL.TextureMagFilterType;
|
1248 | /* Sets minification filter. Default: 'nearest' */
|
1249 | min?: REGL.TextureMinFilterType;
|
1250 | /* Sets wrap mode for both axes, either to the same value, or independently, `[wrapS, wrapT]` */
|
1251 | wrap?: REGL.TextureWrapModeType | [REGL.TextureWrapModeType, REGL.TextureWrapModeType];
|
1252 | /* Sets wrap mode on S axis. Default: 'clamp' */
|
1253 | wrapS?: REGL.TextureWrapModeType;
|
1254 | /* Sets wrap mode on T axis. Default: 'clamp' */
|
1255 | wrapT?: REGL.TextureWrapModeType;
|
1256 | /* Sets number of anisotropic samples; requires `EXT_texture_filter_anisotropic`. Default: 0 */
|
1257 | aniso?: number;
|
1258 | /* Determines the format of the texture and possibly also the type. Default: 'rgba' */
|
1259 | format?: REGL.TextureFormatType;
|
1260 | /**
|
1261 | * Texture type.
|
1262 | * In many cases type can be inferred from the format and other information in the texture.
|
1263 | * However, in some situations it may still be necessary to set it manually.
|
1264 | * Default: 'uint8'
|
1265 | */
|
1266 | type?: REGL.TextureDataType;
|
1267 |
|
1268 | /**
|
1269 | * If boolean, then it sets whether or not we should regenerate the mipmaps.
|
1270 | *
|
1271 | * If a string, it allows you to specify a hint to the mipmap generator.
|
1272 | * If a hint is specified, then also the mipmaps will be regenerated.
|
1273 | *
|
1274 | * Finally, mipmap can also be an array of arrays. In this case, every subarray will be one of
|
1275 | * the mipmaps, and you can thus use this option to manually specify the mipmaps of the image.
|
1276 | *
|
1277 | * Default: false
|
1278 | */
|
1279 | mipmap?: boolean | REGL.TextureMipmapHintType | number[][];
|
1280 | /* Flips textures vertically when uploading. Default: false */
|
1281 | flipY?: boolean;
|
1282 | /* Sets unpack alignment per row. Default: 1 */
|
1283 | alignment?: REGL.TextureUnpackAlignmentType;
|
1284 | /* Premultiply alpha when unpacking. Default: false */
|
1285 | premultiplyAlpha?: boolean;
|
1286 | /* Sets the WebGL color space flag for pixel unpacking. Default: 'none' */
|
1287 | colorSpace?: REGL.TextureColorSpaceType;
|
1288 | }
|
1289 |
|
1290 | type TextureImageData =
|
1291 | number[] |
|
1292 | number[][] |
|
1293 | number[][][] |
|
1294 | ArrayBufferView |
|
1295 | REGL.NDArrayLike |
|
1296 | HTMLImageElement |
|
1297 | HTMLVideoElement |
|
1298 | HTMLCanvasElement |
|
1299 | CanvasRenderingContext2D;
|
1300 |
|
1301 | /**
|
1302 | * An N-dimensional array, as per `scijs/ndarray`.
|
1303 | */
|
1304 | interface NDArrayLike {
|
1305 | shape: number[];
|
1306 | stride: number[];
|
1307 | offset: number;
|
1308 | data: number[] | ArrayBufferView;
|
1309 | }
|
1310 |
|
1311 | type TextureMipmapHintType =
|
1312 | /* `gl.DONT_CARE` */
|
1313 | "don't care" | "dont care" |
|
1314 | /* `gl.NICEST` */
|
1315 | "nice" |
|
1316 | /* `gl.FASTEST` */
|
1317 | "fast";
|
1318 |
|
1319 | type TextureColorSpaceType =
|
1320 | /* `gl.NONE` */
|
1321 | "none" |
|
1322 | /* gl.BROWSER_DEFAULT_WEBGL` */
|
1323 | "browser";
|
1324 |
|
1325 | type TextureChannelsType = 1 | 2 | 3 | 4;
|
1326 |
|
1327 | /* Related WebGL API: `gl.pixelStorei` */
|
1328 | type TextureUnpackAlignmentType =
|
1329 | /* byte-alignment */
|
1330 | 1 |
|
1331 | /* rows aligned to even-numbered bytes */
|
1332 | 2 |
|
1333 | /* word-alignment */
|
1334 | 4 |
|
1335 | /* rows start on double-word boundaries */
|
1336 | 8;
|
1337 |
|
1338 | interface TextureCube extends Texture {
|
1339 | /* Reinitializes the texture in place with faces of dimensions 1 x 1. */
|
1340 | (): REGL.TextureCube;
|
1341 | /* Reinitializes the texture in place with faces of dimensions `radius` x `radius`. */
|
1342 | (radius: number): REGL.TextureCube;
|
1343 | /* Reinitializes the texture in place using the provided image data for the six faces. */
|
1344 | (
|
1345 | posXData: REGL.TextureImageData, negXData: REGL.TextureImageData,
|
1346 | posYData: REGL.TextureImageData, negYData: REGL.TextureImageData,
|
1347 | posZData: REGL.TextureImageData, negZData: REGL.TextureImageData
|
1348 | ): REGL.TextureCube;
|
1349 | /* Reinitializes the texture in place using the provided creation options for the six faces. */
|
1350 | (
|
1351 | posXOptions: REGL.Texture2DOptions, negXOptions: REGL.Texture2DOptions,
|
1352 | posYOptions: REGL.Texture2DOptions, negYOptions: REGL.Texture2DOptions,
|
1353 | posZOptions: REGL.Texture2DOptions, negZOptions: REGL.Texture2DOptions,
|
1354 | ): REGL.TextureCube;
|
1355 | /* Reinitializes the texture in place using creation `options`. */
|
1356 | (options: REGL.TextureCubeOptions): REGL.TextureCube;
|
1357 |
|
1358 | /**
|
1359 | * Replaces the part of texture with new data.
|
1360 | *
|
1361 | * @param face index of the face to modify
|
1362 | * @param data 2D image data object to use for the replacement
|
1363 | * @param x horizontal offset of the image within the face (Default: `0`)
|
1364 | * @param y vertical offset of the image within the face (Default: `0`)
|
1365 | * @param level mipmap level of the texture to modify (Default: `0`)
|
1366 | */
|
1367 | subimage(
|
1368 | face: REGL.TextureCubeFaceIndex,
|
1369 | data: TextureImageData,
|
1370 | x?: number,
|
1371 | y?: number,
|
1372 | level?: number,
|
1373 | ): REGL.TextureCube;
|
1374 |
|
1375 | /** Resizes the cube-map texture, setting the dimensions of each face to `radius` x `radius`. */
|
1376 | resize(radius: number): REGL.TextureCube;
|
1377 | }
|
1378 |
|
1379 | type TextureCubeFaceIndex =
|
1380 | /* positive X face */
|
1381 | 0 |
|
1382 | /* negative X face */
|
1383 | 1 |
|
1384 | /* positive Y face */
|
1385 | 2 |
|
1386 | /* negative Y face */
|
1387 | 3 |
|
1388 | /* positive Z face */
|
1389 | 4 |
|
1390 | /* negative Z face */
|
1391 | 5;
|
1392 |
|
1393 | interface TextureCubeOptions extends Texture2DOptions {
|
1394 | /* Uses the provided texture data for the six faces. */
|
1395 | faces?: [
|
1396 | TextureImageData, TextureImageData,
|
1397 | TextureImageData, TextureImageData,
|
1398 | TextureImageData, TextureImageData
|
1399 | ];
|
1400 | }
|
1401 |
|
1402 | interface Renderbuffer extends REGL.Resource {
|
1403 | readonly stats: {
|
1404 | /** Size of the renderbuffer in bytes. */
|
1405 | size: number;
|
1406 | }
|
1407 |
|
1408 | /** Width of the renderbuffer */
|
1409 | readonly width: number;
|
1410 | /** Height of the renderbuffer */
|
1411 | readonly height: number;
|
1412 | /** Format of the renderbuffer. */
|
1413 | readonly format: number;
|
1414 |
|
1415 | /* Reinitializes the Renderbuffer in place using dimensions: 1 x 1. */
|
1416 | (): REGL.Renderbuffer;
|
1417 | /* Reinitializes the Renderbuffer in place using dimensions: `radius` x `radius`. */
|
1418 | (radius: number): REGL.Renderbuffer;
|
1419 | /* Reinitializes the Renderbuffer in place using dimensions: `width` x `height`. */
|
1420 | (width: number, height: number): REGL.Renderbuffer;
|
1421 | /* Reinitializes the Renderbuffer in place using creation `options`. */
|
1422 | (options: REGL.RenderbufferOptions): REGL.Renderbuffer;
|
1423 |
|
1424 | /* Resizes the Renderbuffer. */
|
1425 | resize(radius: number): REGL.Renderbuffer;
|
1426 | resize(width: number, height: number): REGL.Renderbuffer;
|
1427 | }
|
1428 |
|
1429 | interface RenderbufferOptions {
|
1430 | /* NB: `shape`, `radius`, and `width`/`height` are alternative (and mutually exclusive) means for setting the size of the renderbuffer. */
|
1431 | /* Sets the dimensions [width, height] for the renderbuffer. */
|
1432 | shape?: [number, number];
|
1433 | /* Sets the dimensions `radius` x `radius` for the renderbuffer. */
|
1434 | radius?: number;
|
1435 | /* Sets the width of the renderbuffer. Default: `gl.drawingBufferWidth` */
|
1436 | width?: number;
|
1437 | /* Sets the height of the renderbuffer. Default: `gl.drawingBufferHeight` */
|
1438 | height?: number;
|
1439 | /** Sets the internal format of the render buffer. Default 'rgba4' */
|
1440 | format?: REGL.RenderbufferFormat;
|
1441 | }
|
1442 |
|
1443 | type RenderbufferFormat =
|
1444 | REGL.RenderbufferColorFormat |
|
1445 | /* `gl.DEPTH_COMPONENT16` */
|
1446 | "depth" |
|
1447 | /* `gl.STENCIL_INDEX8` */
|
1448 | "stencil" |
|
1449 | /* `gl.DEPTH_STENCIL` */
|
1450 | "depth stencil";
|
1451 |
|
1452 | type RenderbufferColorFormat =
|
1453 | /* `gl.RGBA4` */
|
1454 | "rgba4" |
|
1455 | /* `gl.RGB565` */
|
1456 | "rgb565" |
|
1457 | /* `gl.RGB5_A1` */
|
1458 | "rgb5 a1" |
|
1459 | /* `gl.RGB16F`, requires EXT_color_buffer_half_float */
|
1460 | "rgb16f" |
|
1461 | /* `gl.RGBA16F`, requires EXT_color_buffer_half_float */
|
1462 | "rgba16f" |
|
1463 | /* `gl.RGBA32F`, requires WEBGL_color_buffer_float */
|
1464 | "rgba32f" |
|
1465 | /* `gl.SRGB8_ALPHA8`, requires EXT_sRGB */
|
1466 | "srgba";
|
1467 |
|
1468 | type Framebuffer = REGL.Framebuffer2D | REGL.FramebufferCube;
|
1469 |
|
1470 | interface Framebuffer2D extends REGL.Resource {
|
1471 | /* Reinitializes the Framebuffer in place using dimensions: 1 x 1. */
|
1472 | (): REGL.Framebuffer2D;
|
1473 | /* Reinitializes the Framebuffer in place using dimensions: `radius` x `radius`. */
|
1474 | (radius: number): REGL.Framebuffer2D;
|
1475 | /* Reinitializes the Framebuffer in place using dimensions: `width` x `height`. */
|
1476 | (width: number, height: number): REGL.Framebuffer2D;
|
1477 | /* Reinitializes the Framebuffer in place using creation `options`. */
|
1478 | (options: REGL.FramebufferOptions): REGL.Framebuffer2D;
|
1479 |
|
1480 | /* Framebuffer binding */
|
1481 |
|
1482 | /* Binds a framebuffer directly. This is a short cut for creating a command which sets the framebuffer. */
|
1483 | use<
|
1484 | Context extends REGL.DefaultContext = REGL.DefaultContext,
|
1485 | Props extends {} = {}
|
1486 | >(body: REGL.CommandBodyFn<Context, Props>): void;
|
1487 |
|
1488 | /* Resizes the Framebuffer and all its attachments. */
|
1489 | resize(radius: number): REGL.Framebuffer2D;
|
1490 | resize(width: number, height: number): REGL.Framebuffer2D;
|
1491 | }
|
1492 |
|
1493 | interface FramebufferOptions {
|
1494 | /* NB: `shape`, `radius`, and `width`/`height` are alternative (and mutually exclusive) means for setting the size of the framebuffer. */
|
1495 | /* Sets the dimensions [width, height] for the framebuffer. */
|
1496 | shape?: [number, number];
|
1497 | /* Sets the dimensions `radius` x `radius` for the framebuffer. */
|
1498 | radius?: number;
|
1499 | /* Sets the width of the framebuffer. Default: `gl.drawingBufferWidth` */
|
1500 | width?: number;
|
1501 | /* Sets the height of the framebuffer. Default: `gl.drawingBufferHeight` */
|
1502 | height?: number;
|
1503 |
|
1504 | /* NB: If neither `color` nor `colors` is specified, color attachments are created automatically. */
|
1505 | /* A texture or renderbuffer for the color attachment. */
|
1506 | color?: REGL.Framebuffer2DAttachment;
|
1507 | /* An array of textures or renderbuffers for the color attachments. */
|
1508 | colors?: REGL.Framebuffer2DAttachment[];
|
1509 | /* Sets the format of the color buffer. Ignored if `color` is specified. Default: 'rgba' */
|
1510 | colorFormat?: REGL.FramebufferTextureColorFormat | REGL.RenderbufferColorFormat;
|
1511 | /* Sets the type of the color buffer if it is a texture. Default: 'uint8' */
|
1512 | colorType?: REGL.FramebufferColorDataType;
|
1513 | /* Sets the number of color buffers. Values > 1 require WEBGL_draw_buffers. Default: 1 */
|
1514 | colorCount?: number;
|
1515 | /* If boolean, toggles the depth attachment. If a renderbuffer or texture, sets the depth attachment. Default: true */
|
1516 | depth?: boolean | REGL.Framebuffer2DAttachment;
|
1517 | /* If boolean, toggles the stencil attachments. If a renderbuffer or texture, sets the stencil attachment. Default: true */
|
1518 | stencil?: boolean | REGL.Framebuffer2DAttachment;
|
1519 | /* If boolean, toggles both the depth and stencil attachments. If a renderbuffer or texture, sets the combined depth/stencil attachment. Default: true */
|
1520 | depthStencil?: boolean | REGL.Framebuffer2DAttachment;
|
1521 | /* Toggles whether depth/stencil attachments should be in texture. Requires WEBGL_depth_texture. Default: false */
|
1522 | depthTexture?: boolean;
|
1523 | }
|
1524 |
|
1525 | type Framebuffer2DAttachment = REGL.Texture2D | REGL.Renderbuffer;
|
1526 |
|
1527 | interface FramebufferCube extends REGL.Resource {
|
1528 | /* Reinitializes the FramebufferCube in place using face dimensions 1 x 1. */
|
1529 | (): REGL.FramebufferCube;
|
1530 | /* Reinitializes the FramebufferCube in place using face dimensions `radius` x `radius`. */
|
1531 | (radius: number): REGL.FramebufferCube;
|
1532 | /* Reinitializes the FramebufferCube in place using creation `options`. */
|
1533 | (options: FramebufferCubeOptions): REGL.FramebufferCube;
|
1534 |
|
1535 | /* Resizes the FramebufferCube and all its attachments. */
|
1536 | resize(radius: number): REGL.FramebufferCube;
|
1537 |
|
1538 | /* Faces of the FramebufferCube */
|
1539 | faces: [
|
1540 | REGL.Framebuffer,
|
1541 | REGL.Framebuffer,
|
1542 | REGL.Framebuffer,
|
1543 | REGL.Framebuffer,
|
1544 | REGL.Framebuffer
|
1545 | ]
|
1546 | }
|
1547 |
|
1548 | interface FramebufferCubeOptions {
|
1549 | /* NB: `shape`, `radius`, and `width`/`height` are alternative (and mutually exclusive) means for setting the size of the cube. */
|
1550 | /* Sets the dimensions [width, height] for each face of the cube. Width must equal height. */
|
1551 | shape?: [number, number];
|
1552 | /* Sets the dimensions `radius` x `radius` for each face of the cube. */
|
1553 | radius?: number;
|
1554 | /* Sets the width dimension for each face of the cube. Must equal `height`. */
|
1555 | width?: number;
|
1556 | /* Sets the height dimension for each face of the cube. Must equal `width`. */
|
1557 | height?: number;
|
1558 |
|
1559 | /* A TextureCube for the color attachment. */
|
1560 | color?: REGL.TextureCube;
|
1561 | /* An array of TextureCubes for the color attachments. */
|
1562 | colors?: REGL.TextureCube[];
|
1563 | /* Sets the format of the color buffer. */
|
1564 | colorFormat?: REGL.FramebufferTextureColorFormat;
|
1565 | /* Sets the type of the color buffer. */
|
1566 | colorType?: REGL.FramebufferColorDataType;
|
1567 | /* Sets the number of color buffers. Values > 1 require WEBGL_draw_buffers. Default: 1 */
|
1568 | colorCount?: number;
|
1569 | /* If boolean, toggles the depth attachment. If texture, sets the depth attachment. Default: true */
|
1570 | depth?: boolean | REGL.TextureCube;
|
1571 | /* If boolean, toggles the stencil attachment. If texture, sets the stencil attachment. Default: true */
|
1572 | stencil?: boolean | REGL.TextureCube;
|
1573 | /* If boolean, toggles both the depth and stencil attachments. If texture, sets the combined depth/stencil attachment. Default: true */
|
1574 | depthStencil?: boolean | REGL.TextureCube;
|
1575 | }
|
1576 |
|
1577 | /* `gl.RGBA` */
|
1578 | type FramebufferTextureColorFormat = "rgba";
|
1579 |
|
1580 | type FramebufferColorDataType =
|
1581 | /* `gl.UNSIGNED_BYTE` */
|
1582 | "uint8" |
|
1583 | /* `ext.HALF_FLOAT_OES` (16-bit float), requires OES_texture_half_float */
|
1584 | "half float" |
|
1585 | /* `gl.FLOAT` (32-bit float), requires OES_texture_float */
|
1586 | "float";
|
1587 |
|
1588 | interface Limits {
|
1589 | /** An array of bits depths for the red, green, blue and alpha channels */
|
1590 | colorBits: [number, number, number, number];
|
1591 | /** Bit depth of drawing buffer */
|
1592 | depthBits: number;
|
1593 | /** Bit depth of stencil buffer */
|
1594 | stencilBits: number;
|
1595 | /** gl.SUBPIXEL_BITS */
|
1596 | subpixelBits: number;
|
1597 | /** A list of all supported extensions */
|
1598 | extensions: string[];
|
1599 | /** Maximum number of anisotropic filtering samples */
|
1600 | maxAnisotropic: number;
|
1601 | /** Maximum number of draw buffers */
|
1602 | maxDrawbuffers: number;
|
1603 | /** Maximum number of color attachments */
|
1604 | maxColorAttachments: number;
|
1605 | /** gl.ALIASED_POINT_SIZE_RANGE */
|
1606 | pointSizeDims: Float32Array;
|
1607 | /** gl.ALIASED_LINE_WIDTH_RANGE */
|
1608 | lineWidthDims: Float32Array;
|
1609 | /** gl.MAX_VIEWPORT_DIMS */
|
1610 | maxViewportDims: Int32Array;
|
1611 | /** gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS */
|
1612 | maxCombinedTextureUnits: number;
|
1613 | /** gl.MAX_CUBE_MAP_TEXTURE_SIZE */
|
1614 | maxCubeMapSize: number;
|
1615 | /** gl.MAX_RENDERBUFFER_SIZE */
|
1616 | maxRenderbufferSize: number;
|
1617 | /** gl.MAX_TEXTURE_IMAGE_UNITS */
|
1618 | maxTextureUnits: number;
|
1619 | /** gl.MAX_TEXTURE_SIZE */
|
1620 | maxTextureSize: number;
|
1621 | /** gl.MAX_VERTEX_ATTRIBS */
|
1622 | maxAttributes: number;
|
1623 | /** gl.MAX_VERTEX_UNIFORM_VECTORS */
|
1624 | maxVertexUniforms: number;
|
1625 | /** gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS */
|
1626 | maxVertexTextureUnits: number;
|
1627 | /** gl.MAX_VARYING_VECTORS */
|
1628 | maxVaryingVectors: number;
|
1629 | /** gl.MAX_FRAGMENT_UNIFORM_VECTORS */
|
1630 | maxFragmentUniforms: number;
|
1631 | /** gl.SHADING_LANGUAGE_VERSION */
|
1632 | glsl: string;
|
1633 | /** gl.RENDERER */
|
1634 | renderer: string;
|
1635 | /** gl.VENDOR */
|
1636 | vendor: string;
|
1637 | /** gl.VERSION */
|
1638 | version: string;
|
1639 | /** A list of all supported texture formats */
|
1640 | textureFormats: TextureFormatType[];
|
1641 | }
|
1642 |
|
1643 | interface Stats {
|
1644 | /** The number of array buffers currently allocated */
|
1645 | bufferCount: number;
|
1646 | /** The number of element buffers currently allocated */
|
1647 | elementsCount: number;
|
1648 | /** The number of framebuffers currently allocated */
|
1649 | framebufferCount: number;
|
1650 | /** The number of shaders currently allocated */
|
1651 | shaderCount: number;
|
1652 | /** The number of textures currently allocated */
|
1653 | textureCount: number;
|
1654 | /** The number of cube maps currently allocated */
|
1655 | cubeCount: number;
|
1656 | /** The number of renderbuffers currently allocated */
|
1657 | renderbufferCount: number;
|
1658 | /** The maximum number of texture units used */
|
1659 | maxTextureUnits: number;
|
1660 | /** Number of vertex array objects */
|
1661 | vaoCount: number;
|
1662 |
|
1663 | // The following functions are only available if regl is initialized with option `profile: true`
|
1664 |
|
1665 | /** The total amount of memory allocated for textures and cube maps */
|
1666 | getTotalTextureSize?: () => number;
|
1667 | /** The total amount of memory allocated for array buffers and element buffers */
|
1668 | getTotalBufferSize?: () => number;
|
1669 | /** The total amount of memory allocated for renderbuffers */
|
1670 | getTotalRenderbufferSize?: () => number;
|
1671 | /** The maximum number of uniforms in any shader */
|
1672 | getMaxUniformsCount?: () => number;
|
1673 | /** The maximum number of attributes in any shader */
|
1674 | getMaxAttributesCount?: () => number;
|
1675 | }
|
1676 |
|
1677 | interface CommandStats {
|
1678 | /** The number of times the command has been called. */
|
1679 | count: number;
|
1680 | /**
|
1681 | * The cumulative CPU time spent executing the command in milliseconds.
|
1682 | * `cpuTime` uses `performance.now` if available. Otherwise it falls back to `Date.now`.
|
1683 | */
|
1684 | cpuTime: number;
|
1685 | /**
|
1686 | * The cumulative GPU time spent executing the command in milliseconds.
|
1687 | * (requires the `EXT_disjoint_timer_query` extension).
|
1688 | * GPU timer queries update asynchronously. If you are not using `regl.frame()` to tick your
|
1689 | * application, then you should periodically call `regl.poll()` each frame to update the timer
|
1690 | * statistics.
|
1691 | */
|
1692 | gpuTime: number;
|
1693 | }
|
1694 |
|
1695 | /**
|
1696 | * The following types are defined for the convenience of clients of this library. They represent
|
1697 | * the most likely forms in which values being passed to shaders (via uniforms and attributes) are
|
1698 | * defined: flat JS arrays for vectors and either flat or two-dimensional JS arrays for matrices.
|
1699 | */
|
1700 |
|
1701 | type Vec2 = [number, number];
|
1702 | type Vec3 = [number, number, number];
|
1703 | type Vec4 = [number, number, number, number];
|
1704 |
|
1705 | type BVec2 = [boolean, boolean];
|
1706 | type BVec3 = [boolean, boolean, boolean];
|
1707 | type BVec4 = [boolean, boolean, boolean, boolean];
|
1708 |
|
1709 | type Mat2 = [
|
1710 | number, number,
|
1711 | number, number
|
1712 | ] | [
|
1713 | REGL.Vec2,
|
1714 | REGL.Vec2
|
1715 | ];
|
1716 |
|
1717 | type Mat3 = [
|
1718 | number, number, number,
|
1719 | number, number, number,
|
1720 | number, number, number
|
1721 | ] | [
|
1722 | REGL.Vec3,
|
1723 | REGL.Vec3,
|
1724 | REGL.Vec3
|
1725 | ];
|
1726 |
|
1727 | type Mat4 = [
|
1728 | number, number, number, number,
|
1729 | number, number, number, number,
|
1730 | number, number, number, number,
|
1731 | number, number, number, number
|
1732 | ] | [
|
1733 | REGL.Vec4,
|
1734 | REGL.Vec4,
|
1735 | REGL.Vec4,
|
1736 | REGL.Vec4
|
1737 | ];
|
1738 | }
|