twgl.js 5.3.0 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,192 @@
1
1
 
2
+ /**
3
+ * Various default settings for twgl.
4
+ *
5
+ * Note: You can call this any number of times. Example:
6
+ *
7
+ * twgl.setDefaults({ textureColor: [1, 0, 0, 1] });
8
+ * twgl.setDefaults({ attribPrefix: 'a_' });
9
+ *
10
+ * is equivalent to
11
+ *
12
+ * twgl.setDefaults({
13
+ * textureColor: [1, 0, 0, 1],
14
+ * attribPrefix: 'a_',
15
+ * });
16
+ *
17
+ * @typedef {Object} Defaults
18
+ * @property {string} [attribPrefix] The prefix to stick on attributes
19
+ *
20
+ * When writing shaders I prefer to name attributes with `a_`, uniforms with `u_` and varyings with `v_`
21
+ * as it makes it clear where they came from. But, when building geometry I prefer using un-prefixed names.
22
+ *
23
+ * In other words I'll create arrays of geometry like this
24
+ *
25
+ * const arrays = {
26
+ * position: ...
27
+ * normal: ...
28
+ * texcoord: ...
29
+ * };
30
+ *
31
+ * But need those mapped to attributes and my attributes start with `a_`.
32
+ *
33
+ * Default: `""`
34
+ *
35
+ * @property {number[]} [textureColor] Array of 4 values in the range 0 to 1
36
+ *
37
+ * The default texture color is used when loading textures from
38
+ * urls. Because the URL will be loaded async we'd like to be
39
+ * able to use the texture immediately. By putting a 1x1 pixel
40
+ * color in the texture we can start using the texture before
41
+ * the URL has loaded.
42
+ *
43
+ * Default: `[0.5, 0.75, 1, 1]`
44
+ *
45
+ * @property {string} [crossOrigin]
46
+ *
47
+ * If not undefined sets the crossOrigin attribute on images
48
+ * that twgl creates when downloading images for textures.
49
+ *
50
+ * Also see {@link TextureOptions}.
51
+ *
52
+ * @property {bool} [addExtensionsToContext]
53
+ *
54
+ * If true, then, when twgl will try to add any supported WebGL extensions
55
+ * directly to the context under their normal GL names. For example
56
+ * if ANGLE_instances_arrays exists then twgl would enable it,
57
+ * add the functions `vertexAttribDivisor`, `drawArraysInstanced`,
58
+ * `drawElementsInstanced`, and the constant `VERTEX_ATTRIB_ARRAY_DIVISOR`
59
+ * to the `WebGLRenderingContext`.
60
+ *
61
+ * @memberOf module:twgl
62
+ */
2
63
  export type Defaults = {
3
64
  attribPrefix?: string;
4
65
  textureColor?: number[];
5
66
  crossOrigin?: string;
6
67
  addExtensionsToContext?: boolean;
7
68
  };
69
+ /**
70
+ * Sets various defaults for twgl.
71
+ *
72
+ * In the interest of terseness which is kind of the point
73
+ * of twgl I've integrated a few of the older functions here
74
+ *
75
+ * @param {Defaults} newDefaults The default settings.
76
+ * @memberOf module:twgl
77
+ */
8
78
  export function setDefaults(newDefaults: Defaults): void;
79
+ /**
80
+ * Attempts to enable all of the following extensions
81
+ * and add their functions and constants to the
82
+ * `WebGLRenderingContext` using their normal non-extension like names.
83
+ *
84
+ * ANGLE_instanced_arrays
85
+ * EXT_blend_minmax
86
+ * EXT_color_buffer_float
87
+ * EXT_color_buffer_half_float
88
+ * EXT_disjoint_timer_query
89
+ * EXT_disjoint_timer_query_webgl2
90
+ * EXT_frag_depth
91
+ * EXT_sRGB
92
+ * EXT_shader_texture_lod
93
+ * EXT_texture_filter_anisotropic
94
+ * OES_element_index_uint
95
+ * OES_standard_derivatives
96
+ * OES_texture_float
97
+ * OES_texture_float_linear
98
+ * OES_texture_half_float
99
+ * OES_texture_half_float_linear
100
+ * OES_vertex_array_object
101
+ * WEBGL_color_buffer_float
102
+ * WEBGL_compressed_texture_atc
103
+ * WEBGL_compressed_texture_etc1
104
+ * WEBGL_compressed_texture_pvrtc
105
+ * WEBGL_compressed_texture_s3tc
106
+ * WEBGL_compressed_texture_s3tc_srgb
107
+ * WEBGL_depth_texture
108
+ * WEBGL_draw_buffers
109
+ *
110
+ * For example if `ANGLE_instanced_arrays` exists then the functions
111
+ * `drawArraysInstanced`, `drawElementsInstanced`, `vertexAttribDivisor`
112
+ * and the constant `VERTEX_ATTRIB_ARRAY_DIVISOR` are added to the
113
+ * `WebGLRenderingContext`.
114
+ *
115
+ * Note that if you want to know if the extension exists you should
116
+ * probably call `gl.getExtension` for each extension. Alternatively
117
+ * you can check for the existence of the functions or constants that
118
+ * are expected to be added. For example
119
+ *
120
+ * if (gl.drawBuffers) {
121
+ * // Either WEBGL_draw_buffers was enabled OR you're running in WebGL2
122
+ * ....
123
+ *
124
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
125
+ * @memberOf module:twgl
126
+ */
9
127
  export function addExtensionsToContext(gl: WebGLRenderingContext): void;
128
+ /**
129
+ * Creates a webgl context.
130
+ *
131
+ * Will return a WebGL2 context if possible.
132
+ *
133
+ * You can check if it's WebGL2 with
134
+ *
135
+ * twgl.isWebGL2(gl);
136
+ *
137
+ * @param {HTMLCanvasElement} canvas The canvas tag to get
138
+ * context from. If one is not passed in one will be
139
+ * created.
140
+ * @return {WebGLRenderingContext} The created context.
141
+ */
10
142
  export function createContext(canvas: HTMLCanvasElement): WebGLRenderingContext;
143
+ /**
144
+ * Gets a WebGL context. Will create a WebGL2 context if possible.
145
+ *
146
+ * You can check if it's WebGL2 with
147
+ *
148
+ * function isWebGL2(gl) {
149
+ * return gl.getParameter(gl.VERSION).indexOf("WebGL 2.0 ") == 0;
150
+ * }
151
+ *
152
+ * Note: For a WebGL1 context will attempt to enable Vertex Array Objects
153
+ * and add WebGL2 entry points. (unless you first set defaults with
154
+ * `twgl.setDefaults({enableVertexArrayObjects: false})`;
155
+ *
156
+ * @param {HTMLCanvasElement} canvas a canvas element.
157
+ * @param {WebGLContextAttributes} [opt_attribs] optional webgl context creation attributes
158
+ * @return {WebGLRenderingContext} The created context.
159
+ * @memberOf module:twgl
160
+ */
11
161
  export function getContext(canvas: HTMLCanvasElement, opt_attribs?: WebGLContextAttributes): WebGLRenderingContext;
162
+ /**
163
+ * Resize a canvas to match the size it's displayed.
164
+ * @param {HTMLCanvasElement} canvas The canvas to resize.
165
+ * @param {number} [multiplier] So you can pass in `window.devicePixelRatio` or other scale value if you want to.
166
+ * @return {boolean} true if the canvas was resized.
167
+ * @memberOf module:twgl
168
+ */
12
169
  export function resizeCanvasToDisplaySize(canvas: HTMLCanvasElement, multiplier?: number): boolean;
170
+ /**
171
+ * The info for an attribute. This is effectively just the arguments to `gl.vertexAttribPointer` plus the WebGLBuffer
172
+ * for the attribute.
173
+ *
174
+ * @typedef {Object} AttribInfo
175
+ * @property {number[]|ArrayBufferView} [value] a constant value for the attribute. Note: if this is set the attribute will be
176
+ * disabled and set to this constant value and all other values will be ignored.
177
+ * @property {number} [numComponents] the number of components for this attribute.
178
+ * @property {number} [size] synonym for `numComponents`.
179
+ * @property {number} [type] the type of the attribute (eg. `gl.FLOAT`, `gl.UNSIGNED_BYTE`, etc...) Default = `gl.FLOAT`
180
+ * @property {boolean} [normalize] whether or not to normalize the data. Default = false
181
+ * @property {number} [offset] offset into buffer in bytes. Default = 0
182
+ * @property {number} [stride] the stride in bytes per element. Default = 0
183
+ * @property {number} [divisor] the divisor in instances. Default = 0.
184
+ * Requires WebGL2 or the ANGLE_instanced_arrays extension.
185
+ * and, if you're using WebGL1 you must have called {@link addExtensionsToContext}
186
+ * @property {WebGLBuffer} buffer the buffer that contains the data for this attribute
187
+ * @property {number} [drawType] the draw type passed to gl.bufferData. Default = gl.STATIC_DRAW
188
+ * @memberOf module:twgl
189
+ */
13
190
  export type AttribInfo = {
14
191
  value?: number[] | ArrayBufferView;
15
192
  numComponents?: number;
@@ -22,6 +199,43 @@ export type AttribInfo = {
22
199
  buffer: WebGLBuffer;
23
200
  drawType?: number;
24
201
  };
202
+ /**
203
+ * Use this type of array spec when TWGL can't guess the type or number of components of an array
204
+ * @typedef {Object} FullArraySpec
205
+ * @property {number[]|ArrayBufferView} [value] a constant value for the attribute. Note: if this is set the attribute will be
206
+ * disabled and set to this constant value and all other values will be ignored.
207
+ * @property {(number|number[]|ArrayBufferView)} [data] The data of the array. A number alone becomes the number of elements of type.
208
+ * @property {number} [numComponents] number of components for `vertexAttribPointer`. Default is based on the name of the array.
209
+ * If `coord` is in the name assumes `numComponents = 2`.
210
+ * If `color` is in the name assumes `numComponents = 4`.
211
+ * otherwise assumes `numComponents = 3`
212
+ * @property {number|TypedArrayConstructor} [type] type. This is used if `data` is a JavaScript array, or `buffer` is passed in, or `data` is a number.
213
+ * It can either be the constructor for a typedarray. (eg. `Uint8Array`) OR a WebGL type, (eg `gl.UNSIGNED_BYTE`).
214
+ * For example if you want colors in a `Uint8Array` you might have a `FullArraySpec` like `{ type: gl.UNSIGNED_BYTE, data: [255,0,255,255, ...], }`.
215
+ * @property {number} [size] synonym for `numComponents`.
216
+ * @property {boolean} [normalize] normalize for `vertexAttribPointer`. Default is true if type is `Int8Array` or `Uint8Array` otherwise false.
217
+ * @property {number} [stride] stride for `vertexAttribPointer`. Default = 0
218
+ * @property {number} [offset] offset for `vertexAttribPointer`. Default = 0
219
+ * @property {number} [divisor] divisor for `vertexAttribDivisor`. Default = 0.
220
+ * Requires WebGL2 or the ANGLE_instanced_arrays extension.
221
+ * and, if you using WebGL1 you must have called {@link addExtensionsToContext}
222
+ * @property {string} [attrib] name of attribute this array maps to. Defaults to same name as array prefixed by the default attribPrefix.
223
+ * @property {string} [name] synonym for `attrib`.
224
+ * @property {string} [attribName] synonym for `attrib`.
225
+ * @property {WebGLBuffer} [buffer] Buffer to use for this attribute. This lets you use your own buffer
226
+ * but you will need to supply `numComponents` and `type`. You can effectively pass an `AttribInfo`
227
+ * to provide this. Example:
228
+ *
229
+ * const bufferInfo1 = twgl.createBufferInfoFromArrays(gl, {
230
+ * position: [1, 2, 3, ... ],
231
+ * });
232
+ * const bufferInfo2 = twgl.createBufferInfoFromArrays(gl, {
233
+ * position: bufferInfo1.attribs.position, // use the same buffer from bufferInfo1
234
+ * });
235
+ *
236
+ * @property {number} [drawType] the draw type passed to gl.bufferData. Default = gl.STATIC_DRAW
237
+ * @memberOf module:twgl
238
+ */
25
239
  export type FullArraySpec = {
26
240
  value?: number[] | ArrayBufferView;
27
241
  data?: number | number[] | ArrayBufferView;
@@ -36,11 +250,70 @@ export type FullArraySpec = {
36
250
  name?: string;
37
251
  attribName?: string;
38
252
  buffer?: WebGLBuffer;
253
+ drawType?: number;
39
254
  };
255
+ /**
256
+ * An individual array in {@link Arrays}
257
+ *
258
+ * When passed to {@link createBufferInfoFromArrays} if an ArraySpec is `number[]` or `ArrayBufferView`
259
+ * the types will be guessed based on the name. `indices` will be `Uint16Array`, everything else will
260
+ * be `Float32Array`. If an ArraySpec is a number it's the number of floats for an empty (zeroed) buffer.
261
+ *
262
+ * @typedef {(number|number[]|ArrayBufferView|FullArraySpec)} ArraySpec
263
+ * @memberOf module:twgl
264
+ */
40
265
  export type ArraySpec = number | number[] | ArrayBufferView | FullArraySpec;
266
+ /**
267
+ * This is a JavaScript object of arrays by name. The names should match your shader's attributes. If your
268
+ * attributes have a common prefix you can specify it by calling {@link setAttributePrefix}.
269
+ *
270
+ * Bare JavaScript Arrays
271
+ *
272
+ * var arrays = {
273
+ * position: [-1, 1, 0],
274
+ * normal: [0, 1, 0],
275
+ * ...
276
+ * }
277
+ *
278
+ * Bare TypedArrays
279
+ *
280
+ * var arrays = {
281
+ * position: new Float32Array([-1, 1, 0]),
282
+ * color: new Uint8Array([255, 128, 64, 255]),
283
+ * ...
284
+ * }
285
+ *
286
+ * * Will guess at `numComponents` if not specified based on name.
287
+ *
288
+ * If `coord` is in the name assumes `numComponents = 2`
289
+ *
290
+ * If `color` is in the name assumes `numComponents = 4`
291
+ *
292
+ * otherwise assumes `numComponents = 3`
293
+ *
294
+ * Objects with various fields. See {@link FullArraySpec}.
295
+ *
296
+ * var arrays = {
297
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
298
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
299
+ * normal: { numComponents: 3, data: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], },
300
+ * indices: { numComponents: 3, data: [0, 1, 2, 1, 2, 3], },
301
+ * };
302
+ *
303
+ * @typedef {Object.<string, ArraySpec>} Arrays
304
+ * @memberOf module:twgl
305
+ */
41
306
  export type Arrays = {
42
307
  [key: string]: ArraySpec;
43
308
  };
309
+ /**
310
+ * @typedef {Object} BufferInfo
311
+ * @property {number} numElements The number of elements to pass to `gl.drawArrays` or `gl.drawElements`.
312
+ * @property {number} [elementType] The type of indices `UNSIGNED_BYTE`, `UNSIGNED_SHORT` etc..
313
+ * @property {WebGLBuffer} [indices] The indices `ELEMENT_ARRAY_BUFFER` if any indices exist.
314
+ * @property {Object.<string, AttribInfo>} [attribs] The attribs appropriate to call `setAttributes`
315
+ * @memberOf module:twgl
316
+ */
44
317
  export type BufferInfo = {
45
318
  numElements: number;
46
319
  elementType?: number;
@@ -49,6 +322,41 @@ export type BufferInfo = {
49
322
  [key: string]: AttribInfo;
50
323
  };
51
324
  };
325
+ /**
326
+ * A DrawObject is useful for putting objects in to an array and passing them to {@link drawObjectList}.
327
+ *
328
+ * You need either a `BufferInfo` or a `VertexArrayInfo`.
329
+ *
330
+ * @typedef {Object} DrawObject
331
+ * @property {boolean} [active] whether or not to draw. Default = `true` (must be `false` to be not true). In other words `undefined` = `true`
332
+ * @property {number} [type] type to draw eg. `gl.TRIANGLES`, `gl.LINES`, etc...
333
+ * @property {ProgramInfo} programInfo A ProgramInfo as returned from {@link createProgramInfo}
334
+ * @property {BufferInfo} [bufferInfo] A BufferInfo as returned from {@link createBufferInfoFromArrays}
335
+ * @property {VertexArrayInfo} [vertexArrayInfo] A VertexArrayInfo as returned from {@link createVertexArrayInfo}
336
+ * @property {Object<string, ?>} uniforms The values for the uniforms.
337
+ * You can pass multiple objects by putting them in an array. For example
338
+ *
339
+ * var sharedUniforms = {
340
+ * u_fogNear: 10,
341
+ * u_projection: ...
342
+ * ...
343
+ * };
344
+ *
345
+ * var localUniforms = {
346
+ * u_world: ...
347
+ * u_diffuseColor: ...
348
+ * };
349
+ *
350
+ * var drawObj = {
351
+ * ...
352
+ * uniforms: [sharedUniforms, localUniforms],
353
+ * };
354
+ *
355
+ * @property {number} [offset] the offset to pass to `gl.drawArrays` or `gl.drawElements`. Defaults to 0.
356
+ * @property {number} [count] the count to pass to `gl.drawArrays` or `gl.drawElements`. Defaults to bufferInfo.numElements.
357
+ * @property {number} [instanceCount] the number of instances. Defaults to undefined.
358
+ * @memberOf module:twgl
359
+ */
52
360
  export type DrawObject = {
53
361
  active?: boolean;
54
362
  type?: number;
@@ -62,6 +370,37 @@ export type DrawObject = {
62
370
  count?: number;
63
371
  instanceCount?: number;
64
372
  };
373
+ /**
374
+ * The options for a framebuffer attachment.
375
+ *
376
+ * Note: For a `format` that is a texture include all the texture
377
+ * options from {@link TextureOptions} for example
378
+ * `min`, `mag`, `clamp`, etc... Note that unlike {@link TextureOptions}
379
+ * `auto` defaults to `false` for attachment textures but `min` and `mag` default
380
+ * to `gl.LINEAR` and `wrap` defaults to `CLAMP_TO_EDGE`
381
+ *
382
+ * @typedef {Object} AttachmentOptions
383
+ * @property {number} [attachmentPoint] The attachment point. Defaults
384
+ * to `gl.COLOR_ATTACHMENT0 + ndx` unless type is a depth or stencil type
385
+ * then it's gl.DEPTH_ATTACHMENT or `gl.DEPTH_STENCIL_ATTACHMENT` depending
386
+ * on the format or attachment type.
387
+ * @property {number} [format] The format. If one of `gl.RGBA4`,
388
+ * `gl.RGB565`, `gl.RGB5_A1`, `gl.DEPTH_COMPONENT16`,
389
+ * `gl.STENCIL_INDEX8` or `gl.DEPTH_STENCIL` then will create a
390
+ * renderbuffer. Otherwise will create a texture. Default = `gl.RGBA`
391
+ * @property {number} [type] The type. Used for texture. Default = `gl.UNSIGNED_BYTE`.
392
+ * @property {number} [target] The texture target for `gl.framebufferTexture2D`.
393
+ * Defaults to `gl.TEXTURE_2D`. Set to appropriate face for cube maps.
394
+ * @property {number} [samples] The number of samples. Default = 1
395
+ * @property {number} [level] level for `gl.framebufferTexture2D`. Defaults to 0.
396
+ * @property {number} [layer] layer for `gl.framebufferTextureLayer`. Defaults to undefined.
397
+ * If set then `gl.framebufferTextureLayer` is called, if not then `gl.framebufferTexture2D`
398
+ * @property {(WebGLRenderbuffer | WebGLTexture)} [attachment] An existing renderbuffer or texture.
399
+ * If provided will attach this Object. This allows you to share
400
+ * attachments across framebuffers.
401
+ * @memberOf module:twgl
402
+ * @mixes TextureOptions
403
+ */
65
404
  export type AttachmentOptions = TextureOptions & {
66
405
  attachmentPoint?: number;
67
406
  format?: number;
@@ -72,13 +411,40 @@ export type AttachmentOptions = TextureOptions & {
72
411
  layer?: number;
73
412
  attachment?: WebGLRenderbuffer | WebGLTexture;
74
413
  };
414
+ /**
415
+ * @typedef {Object} FramebufferInfo
416
+ * @property {WebGLFramebuffer} framebuffer The WebGLFramebuffer for this framebufferInfo
417
+ * @property {Array.<(WebGLRenderbuffer | WebGLTexture)>} attachments The created attachments in the same order as passed in to {@link createFramebufferInfo}.
418
+ * @property {number} width The width of the framebuffer and its attachments
419
+ * @property {number} height The width of the framebuffer and its attachments
420
+ * @memberOf module:twgl
421
+ */
75
422
  export type FramebufferInfo = {
76
423
  framebuffer: WebGLFramebuffer;
77
424
  attachments: (WebGLRenderbuffer | WebGLTexture)[];
78
425
  width: number;
79
426
  height: number;
80
427
  };
428
+ /**
429
+ * Error Callback
430
+ * @callback ErrorCallback
431
+ * @param {string} msg error message.
432
+ * @param {number} [lineOffset] amount to add to line number
433
+ * @memberOf module:twgl
434
+ */
81
435
  export type ErrorCallback = (msg: string, lineOffset?: number) => void;
436
+ /**
437
+ * @typedef {Object} FullProgramSpec
438
+ * @property {string[]} shaders the shader source or element ids.
439
+ * @property {function(string)} [errorCallback] callback for errors
440
+ * @property {Object.<string,number>|string[]} [attribLocations] a attribute name to location map, or array of attribute names where index = location.
441
+ * @property {(BufferInfo|Object.<string,AttribInfo>|string[])} [transformFeedbackVaryings] If passed
442
+ * a BufferInfo will use the attribs names inside. If passed an object of AttribInfos will use the names from that object. Otherwise
443
+ * you can pass an array of names.
444
+ * @property {number} [transformFeedbackMode] the mode to pass `gl.transformFeedbackVaryings`. Defaults to `SEPARATE_ATTRIBS`.
445
+ * @property {ProgramCallback} [callback] callback for async program compilation.
446
+ * @memberOf module:twgl
447
+ */
82
448
  export type FullProgramSpec = {
83
449
  shaders: string[];
84
450
  errorCallback?: (...params: any[]) => any;
@@ -91,7 +457,22 @@ export type FullProgramSpec = {
91
457
  transformFeedbackMode?: number;
92
458
  callback?: ProgramCallback;
93
459
  };
460
+ /**
461
+ * @typedef {string[]|FullProgramSpec} ProgramSpec
462
+ * @memberOf module:twgl
463
+ */
94
464
  export type ProgramSpec = string[] | FullProgramSpec;
465
+ /**
466
+ * @typedef {Object} ProgramOptions
467
+ * @property {function(string)} [errorCallback] callback for errors
468
+ * @property {Object.<string,number>|string[]} [attribLocations] a attribute name to location map, or array of attribute names where index = location.
469
+ * @property {(BufferInfo|Object.<string,AttribInfo>|string[])} [transformFeedbackVaryings] If passed
470
+ * a BufferInfo will use the attribs names inside. If passed an object of AttribInfos will use the names from that object. Otherwise
471
+ * you can pass an array of names.
472
+ * @property {number} [transformFeedbackMode] the mode to pass `gl.transformFeedbackVaryings`. Defaults to `SEPARATE_ATTRIBS`.
473
+ * @property {ProgramCallback} [callback] callback for async program compilation.
474
+ * @memberOf module:twgl
475
+ */
95
476
  export type ProgramOptions = {
96
477
  errorCallback?: (...params: any[]) => any;
97
478
  attribLocations?: {
@@ -103,22 +484,61 @@ export type ProgramOptions = {
103
484
  transformFeedbackMode?: number;
104
485
  callback?: ProgramCallback;
105
486
  };
487
+ /**
488
+ * @typedef {Object} TransformFeedbackInfo
489
+ * @property {number} index index of transform feedback
490
+ * @property {number} type GL type
491
+ * @property {number} size 1 - 4
492
+ * @memberOf module:twgl
493
+ */
106
494
  export type TransformFeedbackInfo = {
107
495
  index: number;
108
496
  type: number;
109
497
  size: number;
110
498
  };
499
+ /**
500
+ * Create TransformFeedbackInfo for passing to bindTransformFeedbackInfo.
501
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
502
+ * @param {WebGLProgram} program an existing WebGLProgram.
503
+ * @return {Object<string, TransformFeedbackInfo>}
504
+ * @memberOf module:twgl
505
+ */
111
506
  export function createTransformFeedbackInfo(gl: WebGLRenderingContext, program: WebGLProgram): {
112
507
  [key: string]: TransformFeedbackInfo;
113
508
  };
509
+ /**
510
+ * Binds buffers for transform feedback.
511
+ *
512
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
513
+ * @param {(ProgramInfo|Object<string, TransformFeedbackInfo>)} transformFeedbackInfo A ProgramInfo or TransformFeedbackInfo.
514
+ * @param {(BufferInfo|Object<string, AttribInfo>)} [bufferInfo] A BufferInfo or set of AttribInfos.
515
+ * @memberOf module:twgl
516
+ */
114
517
  export function bindTransformFeedbackInfo(gl: WebGLRenderingContext, transformFeedbackInfo: ProgramInfo | {
115
518
  [key: string]: TransformFeedbackInfo;
116
519
  }, bufferInfo?: BufferInfo | {
117
520
  [key: string]: AttribInfo;
118
521
  }): void;
522
+ /**
523
+ * Creates a transform feedback and sets the buffers
524
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
525
+ * @param {ProgramInfo} programInfo A ProgramInfo as returned from {@link createProgramInfo}
526
+ * @param {(BufferInfo|Object<string, AttribInfo>)} [bufferInfo] A BufferInfo or set of AttribInfos.
527
+ * @return {WebGLTransformFeedback} the created transform feedback
528
+ * @memberOf module:twgl
529
+ */
119
530
  export function createTransformFeedback(gl: WebGLRenderingContext, programInfo: ProgramInfo, bufferInfo?: BufferInfo | {
120
531
  [key: string]: AttribInfo;
121
532
  }): WebGLTransformFeedback;
533
+ /**
534
+ * @typedef {Object} UniformData
535
+ * @property {string} name The name of the uniform
536
+ * @property {number} type The WebGL type enum for this uniform
537
+ * @property {number} size The number of elements for this uniform
538
+ * @property {number} blockNdx The block index this uniform appears in
539
+ * @property {number} offset The byte offset in the block for this uniform's value
540
+ * @memberOf module:twgl
541
+ */
122
542
  export type UniformData = {
123
543
  name: string;
124
544
  type: number;
@@ -126,6 +546,19 @@ export type UniformData = {
126
546
  blockNdx: number;
127
547
  offset: number;
128
548
  };
549
+ /**
550
+ * The specification for one UniformBlockObject
551
+ *
552
+ * @typedef {Object} BlockSpec
553
+ * @property {number} index The index of the block.
554
+ * @property {number} size The size in bytes needed for the block
555
+ * @property {number[]} uniformIndices The indices of the uniforms used by the block. These indices
556
+ * correspond to entries in a UniformData array in the {@link UniformBlockSpec}.
557
+ * @property {bool} usedByVertexShader Self explanatory
558
+ * @property {bool} usedByFragmentShader Self explanatory
559
+ * @property {bool} used Self explanatory
560
+ * @memberOf module:twgl
561
+ */
129
562
  export type BlockSpec = {
130
563
  index: number;
131
564
  size: number;
@@ -134,12 +567,47 @@ export type BlockSpec = {
134
567
  usedByFragmentShader: boolean;
135
568
  used: boolean;
136
569
  };
570
+ /**
571
+ * A `UniformBlockSpec` represents the data needed to create and bind
572
+ * UniformBlockObjects for a given program
573
+ *
574
+ * @typedef {Object} UniformBlockSpec
575
+ * @property {Object.<string, BlockSpec>} blockSpecs The BlockSpec for each block by block name
576
+ * @property {UniformData[]} uniformData An array of data for each uniform by uniform index.
577
+ * @memberOf module:twgl
578
+ */
137
579
  export type UniformBlockSpec = {
138
580
  blockSpecs: {
139
581
  [key: string]: BlockSpec;
140
582
  };
141
583
  uniformData: UniformData[];
142
584
  };
585
+ /**
586
+ * Represents a UniformBlockObject including an ArrayBuffer with all the uniform values
587
+ * and a corresponding WebGLBuffer to hold those values on the GPU
588
+ *
589
+ * @typedef {Object} UniformBlockInfo
590
+ * @property {string} name The name of the block
591
+ * @property {ArrayBuffer} array The array buffer that contains the uniform values
592
+ * @property {Float32Array} asFloat A float view on the array buffer. This is useful
593
+ * inspecting the contents of the buffer in the debugger.
594
+ * @property {WebGLBuffer} buffer A WebGL buffer that will hold a copy of the uniform values for rendering.
595
+ * @property {number} [offset] offset into buffer
596
+ * @property {Object<string, ArrayBufferView>} uniforms A uniform name to ArrayBufferView map.
597
+ * each Uniform has a correctly typed `ArrayBufferView` into array at the correct offset
598
+ * and length of that uniform. So for example a float uniform would have a 1 float `Float32Array`
599
+ * view. A single mat4 would have a 16 element `Float32Array` view. An ivec2 would have an
600
+ * `Int32Array` view, etc.
601
+ * @property {Object<string, function>} setters A setter for this uniform.
602
+ * The reason to use setters is elements of arrays are padded to vec4 sizes which
603
+ * means if you want to set an array of 4 floats you'd need to set 16 values
604
+ * (or set elements 0, 4, 8, 12). In other words
605
+ * `someBlockInfo.uniforms.some4FloatArrayUniform.set([0, , , , 1, , , , 2, , , , 3])`
606
+ * where as the setter handles just passing in [0, 1, 2, 3] either directly as in
607
+ * `someBlockInfo.setter.some4FloatArrayUniform.set([0, 1, 2, 3])` (not recommended)
608
+ * or via {@link setBlockUniforms}
609
+ * @memberOf module:twgl
610
+ */
143
611
  export type UniformBlockInfo = {
144
612
  name: string;
145
613
  array: ArrayBuffer;
@@ -153,6 +621,15 @@ export type UniformBlockInfo = {
153
621
  [key: string]: (...params: any[]) => any;
154
622
  };
155
623
  };
624
+ /**
625
+ * @typedef {Object} ProgramInfo
626
+ * @property {WebGLProgram} program A shader program
627
+ * @property {Object<string, function>} uniformSetters object of setters as returned from createUniformSetters,
628
+ * @property {Object<string, function>} attribSetters object of setters as returned from createAttribSetters,
629
+ * @property {UniformBlockSpec} [uniformBlockSpec] a uniform block spec for making UniformBlockInfos with createUniformBlockInfo etc..
630
+ * @property {Object<string, TransformFeedbackInfo>} [transformFeedbackInfo] info for transform feedbacks
631
+ * @memberOf module:twgl
632
+ */
156
633
  export type ProgramInfo = {
157
634
  program: WebGLProgram;
158
635
  uniformSetters: {
@@ -166,7 +643,107 @@ export type ProgramInfo = {
166
643
  [key: string]: TransformFeedbackInfo;
167
644
  };
168
645
  };
646
+ /**
647
+ * A function to generate the source for a texture.
648
+ * @callback TextureFunc
649
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
650
+ * @param {TextureOptions} options the texture options
651
+ * @return {*} Returns any of the things documented for `src` for {@link TextureOptions}.
652
+ * @memberOf module:twgl
653
+ */
169
654
  export type TextureFunc = (gl: WebGLRenderingContext, options: TextureOptions) => any;
655
+ /**
656
+ * Texture options passed to most texture functions. Each function will use whatever options
657
+ * are appropriate for its needs. This lets you pass the same options to all functions.
658
+ *
659
+ * Note: A `TexImageSource` is defined in the WebGL spec as a `HTMLImageElement`, `HTMLVideoElement`,
660
+ * `HTMLCanvasElement`, `ImageBitmap`, or `ImageData`.
661
+ *
662
+ * @typedef {Object} TextureOptions
663
+ * @property {number} [target] the type of texture `gl.TEXTURE_2D` or `gl.TEXTURE_CUBE_MAP`. Defaults to `gl.TEXTURE_2D`.
664
+ * @property {number} [level] the mip level to affect. Defaults to 0. Note, if set auto will be considered false unless explicitly set to true.
665
+ * @property {number} [width] the width of the texture. Only used if src is an array or typed array or null.
666
+ * @property {number} [height] the height of a texture. Only used if src is an array or typed array or null.
667
+ * @property {number} [depth] the depth of a texture. Only used if src is an array or type array or null and target is `TEXTURE_3D` .
668
+ * @property {number} [min] the min filter setting (eg. `gl.LINEAR`). Defaults to `gl.NEAREST_MIPMAP_LINEAR`
669
+ * or if texture is not a power of 2 on both dimensions then defaults to `gl.LINEAR`.
670
+ * @property {number} [mag] the mag filter setting (eg. `gl.LINEAR`). Defaults to `gl.LINEAR`
671
+ * @property {number} [minMag] both the min and mag filter settings.
672
+ * @property {number} [internalFormat] internal format for texture. Defaults to `gl.RGBA`
673
+ * @property {number} [format] format for texture. Defaults to `gl.RGBA`.
674
+ * @property {number} [type] type for texture. Defaults to `gl.UNSIGNED_BYTE` unless `src` is ArrayBufferView. If `src`
675
+ * is ArrayBufferView defaults to type that matches ArrayBufferView type.
676
+ * @property {number} [wrap] Texture wrapping for both S and T (and R if TEXTURE_3D or WebGLSampler). Defaults to `gl.REPEAT` for 2D unless src is WebGL1 and src not npot and `gl.CLAMP_TO_EDGE` for cube
677
+ * @property {number} [wrapS] Texture wrapping for S. Defaults to `gl.REPEAT` and `gl.CLAMP_TO_EDGE` for cube. If set takes precedence over `wrap`.
678
+ * @property {number} [wrapT] Texture wrapping for T. Defaults to `gl.REPEAT` and `gl.CLAMP_TO_EDGE` for cube. If set takes precedence over `wrap`.
679
+ * @property {number} [wrapR] Texture wrapping for R. Defaults to `gl.REPEAT` and `gl.CLAMP_TO_EDGE` for cube. If set takes precedence over `wrap`.
680
+ * @property {number} [minLod] TEXTURE_MIN_LOD setting
681
+ * @property {number} [maxLod] TEXTURE_MAX_LOD setting
682
+ * @property {number} [baseLevel] TEXTURE_BASE_LEVEL setting
683
+ * @property {number} [maxLevel] TEXTURE_MAX_LEVEL setting
684
+ * @property {number} [unpackAlignment] The `gl.UNPACK_ALIGNMENT` used when uploading an array. Defaults to 1.
685
+ * @property {number[]|ArrayBufferView} [color] Color to initialize this texture with if loading an image asynchronously.
686
+ * The default use a blue 1x1 pixel texture. You can set another default by calling `twgl.setDefaults`
687
+ * or you can set an individual texture's initial color by setting this property. Example: `[1, .5, .5, 1]` = pink
688
+ * @property {number} [premultiplyAlpha] Whether or not to premultiply alpha. Defaults to whatever the current setting is.
689
+ * This lets you set it once before calling `twgl.createTexture` or `twgl.createTextures` and only override
690
+ * the current setting for specific textures.
691
+ * @property {number} [flipY] Whether or not to flip the texture vertically on upload. Defaults to whatever the current setting is.
692
+ * This lets you set it once before calling `twgl.createTexture` or `twgl.createTextures` and only override
693
+ * the current setting for specific textures.
694
+ * @property {number} [colorspaceConversion] Whether or not to let the browser do colorspace conversion of the texture on upload. Defaults to whatever the current setting is.
695
+ * This lets you set it once before calling `twgl.createTexture` or `twgl.createTextures` and only override
696
+ * the current setting for specific textures.
697
+ * @property {boolean} [auto] If `undefined` or `true`, in WebGL1, texture filtering is set automatically for non-power of 2 images and
698
+ * mips are generated for power of 2 images. In WebGL2 mips are generated if they can be. Note: if `level` is set above
699
+ * then then `auto` is assumed to be `false` unless explicity set to `true`.
700
+ * @property {number[]} [cubeFaceOrder] The order that cube faces are pulled out of an img or set of images. The default is
701
+ *
702
+ * [gl.TEXTURE_CUBE_MAP_POSITIVE_X,
703
+ * gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
704
+ * gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
705
+ * gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
706
+ * gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
707
+ * gl.TEXTURE_CUBE_MAP_NEGATIVE_Z]
708
+ *
709
+ * @property {(number[]|ArrayBufferView|TexImageSource|TexImageSource[]|string|string[]|TextureFunc)} [src] source for texture
710
+ *
711
+ * If `string` then it's assumed to be a URL to an image. The image will be downloaded async. A usable
712
+ * 1x1 pixel texture will be returned immediately. The texture will be updated once the image has downloaded.
713
+ * If `target` is `gl.TEXTURE_CUBE_MAP` will attempt to divide image into 6 square pieces. 1x6, 6x1, 3x2, 2x3.
714
+ * The pieces will be uploaded in `cubeFaceOrder`
715
+ *
716
+ * If `string[]` or `TexImageSource[]` and target is `gl.TEXTURE_CUBE_MAP` then it must have 6 entries, one for each face of a cube map.
717
+ *
718
+ * If `string[]` or `TexImageSource[]` and target is `gl.TEXTURE_2D_ARRAY` then each entry is a slice of the a 2d array texture
719
+ * and will be scaled to the specified width and height OR to the size of the first image that loads.
720
+ *
721
+ * If `TexImageSource` then it wil be used immediately to create the contents of the texture. Examples `HTMLImageElement`,
722
+ * `HTMLCanvasElement`, `HTMLVideoElement`.
723
+ *
724
+ * If `number[]` or `ArrayBufferView` it's assumed to be data for a texture. If `width` or `height` is
725
+ * not specified it is guessed as follows. First the number of elements is computed by `src.length / numComponents`
726
+ * where `numComponents` is derived from `format`. If `target` is `gl.TEXTURE_CUBE_MAP` then `numElements` is divided
727
+ * by 6. Then
728
+ *
729
+ * * If neither `width` nor `height` are specified and `sqrt(numElements)` is an integer then width and height
730
+ * are set to `sqrt(numElements)`. Otherwise `width = numElements` and `height = 1`.
731
+ *
732
+ * * If only one of `width` or `height` is specified then the other equals `numElements / specifiedDimension`.
733
+ *
734
+ * If `number[]` will be converted to `type`.
735
+ *
736
+ * If `src` is a function it will be called with a `WebGLRenderingContext` and these options.
737
+ * Whatever it returns is subject to these rules. So it can return a string url, an `HTMLElement`
738
+ * an array etc...
739
+ *
740
+ * If `src` is undefined then an empty texture will be created of size `width` by `height`.
741
+ *
742
+ * @property {string} [crossOrigin] What to set the crossOrigin property of images when they are downloaded.
743
+ * default: undefined. Also see {@link setDefaults}.
744
+ *
745
+ * @memberOf module:twgl
746
+ */
170
747
  export type TextureOptions = {
171
748
  target?: number;
172
749
  level?: number;
@@ -197,48 +774,886 @@ export type TextureOptions = {
197
774
  src?: number[] | ArrayBufferView | TexImageSource | TexImageSource[] | string | string[] | TextureFunc;
198
775
  crossOrigin?: string;
199
776
  };
777
+ /**
778
+ * The src image(s) used to create a texture.
779
+ *
780
+ * When you call {@link createTexture} or {@link createTextures}
781
+ * you can pass in urls for images to load into the textures. If it's a single url
782
+ * then this will be a single HTMLImageElement. If it's an array of urls used for a cubemap
783
+ * this will be a corresponding array of images for the cubemap.
784
+ *
785
+ * @typedef {HTMLImageElement|HTMLImageElement[]} TextureSrc
786
+ * @memberOf module:twgl
787
+ */
200
788
  export type TextureSrc = HTMLImageElement | HTMLImageElement[];
789
+ /**
790
+ * A callback for when an image finished downloading and been uploaded into a texture
791
+ * @callback TextureReadyCallback
792
+ * @param {*} err If truthy there was an error.
793
+ * @param {WebGLTexture} texture the texture.
794
+ * @param {TextureSrc} source image(s) used to as the src for the texture
795
+ * @memberOf module:twgl
796
+ */
201
797
  export type TextureReadyCallback = (err: any, texture: WebGLTexture, source: TextureSrc) => void;
798
+ /**
799
+ * A callback for when all images have finished downloading and been uploaded into their respective textures
800
+ * @callback TexturesReadyCallback
801
+ * @param {*} err If truthy there was an error.
802
+ * @param {Object.<string, WebGLTexture>} textures the created textures by name. Same as returned by {@link createTextures}.
803
+ * @param {Object.<string, TextureSrc>} sources the image(s) used for the texture by name.
804
+ * @memberOf module:twgl
805
+ */
202
806
  export type TexturesReadyCallback = (err: any, textures: {
203
807
  [key: string]: WebGLTexture;
204
808
  }, sources: {
205
809
  [key: string]: TextureSrc;
206
810
  }) => void;
811
+ /**
812
+ * A callback for when an image finished downloading and been uploaded into a texture
813
+ * @callback CubemapReadyCallback
814
+ * @param {*} err If truthy there was an error.
815
+ * @param {WebGLTexture} tex the texture.
816
+ * @param {HTMLImageElement[]} imgs the images for each face.
817
+ * @memberOf module:twgl
818
+ */
207
819
  export type CubemapReadyCallback = (err: any, tex: WebGLTexture, imgs: HTMLImageElement[]) => void;
820
+ /**
821
+ * A callback for when an image finished downloading and been uploaded into a texture
822
+ * @callback ThreeDReadyCallback
823
+ * @param {*} err If truthy there was an error.
824
+ * @param {WebGLTexture} tex the texture.
825
+ * @param {HTMLImageElement[]} imgs the images for each slice.
826
+ * @memberOf module:twgl
827
+ */
208
828
  export type ThreeDReadyCallback = (err: any, tex: WebGLTexture, imgs: HTMLImageElement[]) => void;
829
+ /**
830
+ * Check if context is WebGL 2.0
831
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
832
+ * @return {bool} true if it's WebGL 2.0
833
+ * @memberOf module:twgl
834
+ */
209
835
  export function isWebGL2(gl: WebGLRenderingContext): boolean;
836
+ /**
837
+ * Check if context is WebGL 1.0
838
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
839
+ * @return {bool} true if it's WebGL 1.0
840
+ * @memberOf module:twgl
841
+ */
210
842
  export function isWebGL1(gl: WebGLRenderingContext): boolean;
843
+ /**
844
+ * Gets a string for WebGL enum
845
+ *
846
+ * Note: Several enums are the same. Without more
847
+ * context (which function) it's impossible to always
848
+ * give the correct enum. As it is, for matching values
849
+ * it gives all enums. Checking the WebGL2RenderingContext
850
+ * that means
851
+ *
852
+ * 0 = ZERO | POINT | NONE | NO_ERROR
853
+ * 1 = ONE | LINES | SYNC_FLUSH_COMMANDS_BIT
854
+ * 32777 = BLEND_EQUATION_RGB | BLEND_EQUATION_RGB
855
+ * 36662 = COPY_READ_BUFFER | COPY_READ_BUFFER_BINDING
856
+ * 36663 = COPY_WRITE_BUFFER | COPY_WRITE_BUFFER_BINDING
857
+ * 36006 = FRAMEBUFFER_BINDING | DRAW_FRAMEBUFFER_BINDING
858
+ *
859
+ * It's also not useful for bits really unless you pass in individual bits.
860
+ * In other words
861
+ *
862
+ * const bits = gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT;
863
+ * twgl.glEnumToString(gl, bits); // not going to work
864
+ *
865
+ * Note that some enums only exist on extensions. If you
866
+ * want them to show up you need to pass the extension at least
867
+ * once. For example
868
+ *
869
+ * const ext = gl.getExtension('WEBGL_compressed_texture_s3tc');
870
+ * if (ext) {
871
+ * twgl.glEnumToString(ext, 0); // just prime the function
872
+ *
873
+ * ..later..
874
+ *
875
+ * const internalFormat = ext.COMPRESSED_RGB_S3TC_DXT1_EXT;
876
+ * console.log(twgl.glEnumToString(gl, internalFormat));
877
+ *
878
+ * Notice I didn't have to pass the extension the second time. This means
879
+ * you can have place that generically gets an enum for texture formats for example.
880
+ * and as long as you primed the function with the extensions
881
+ *
882
+ * If you're using `twgl.addExtensionsToContext` to enable your extensions
883
+ * then twgl will automatically get the extension's enums.
884
+ *
885
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext or any extension object
886
+ * @param {number} value the value of the enum you want to look up.
887
+ * @return {string} enum string or hex value
888
+ * @memberOf module:twgl
889
+ * @function glEnumToString
890
+ */
211
891
  export function glEnumToString(gl: WebGLRenderingContext, value: number): string;
892
+ /**
893
+ * @typedef {Object} VertexArrayInfo
894
+ * @property {number} numElements The number of elements to pass to `gl.drawArrays` or `gl.drawElements`.
895
+ * @property {number} [elementType] The type of indices `UNSIGNED_BYTE`, `UNSIGNED_SHORT` etc..
896
+ * @property {WebGLVertexArrayObject} [vertexArrayObject] a vertex array object
897
+ * @memberOf module:twgl
898
+ */
212
899
  export type VertexArrayInfo = {
213
900
  numElements: number;
214
901
  elementType?: number;
215
902
  vertexArrayObject?: WebGLVertexArrayObject;
216
903
  };
904
+ /**
905
+ * Sets the contents of a buffer attached to an attribInfo
906
+ *
907
+ * This is helper function to dynamically update a buffer.
908
+ *
909
+ * Let's say you make a bufferInfo
910
+ *
911
+ * var arrays = {
912
+ * position: new Float32Array([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]),
913
+ * texcoord: new Float32Array([0, 0, 0, 1, 1, 0, 1, 1]),
914
+ * normal: new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]),
915
+ * indices: new Uint16Array([0, 1, 2, 1, 2, 3]),
916
+ * };
917
+ * var bufferInfo = twgl.createBufferInfoFromArrays(gl, arrays);
918
+ *
919
+ * And you want to dynamically update the positions. You could do this
920
+ *
921
+ * // assuming arrays.position has already been updated with new data.
922
+ * twgl.setAttribInfoBufferFromArray(gl, bufferInfo.attribs.position, arrays.position);
923
+ *
924
+ * @param {WebGLRenderingContext} gl
925
+ * @param {AttribInfo} attribInfo The attribInfo who's buffer contents to set. NOTE: If you have an attribute prefix
926
+ * the name of the attribute will include the prefix.
927
+ * @param {ArraySpec} array Note: it is arguably inefficient to pass in anything but a typed array because anything
928
+ * else will have to be converted to a typed array before it can be used by WebGL. During init time that
929
+ * inefficiency is usually not important but if you're updating data dynamically best to be efficient.
930
+ * @param {number} [offset] an optional offset into the buffer. This is only an offset into the WebGL buffer
931
+ * not the array. To pass in an offset into the array itself use a typed array and create an `ArrayBufferView`
932
+ * for the portion of the array you want to use.
933
+ *
934
+ * var someArray = new Float32Array(1000); // an array with 1000 floats
935
+ * var someSubArray = new Float32Array(someArray.buffer, offsetInBytes, sizeInUnits); // a view into someArray
936
+ *
937
+ * Now you can pass `someSubArray` into setAttribInfoBufferFromArray`
938
+ * @memberOf module:twgl/attributes
939
+ */
217
940
  export function setAttribInfoBufferFromArray(gl: WebGLRenderingContext, attribInfo: AttribInfo, array: ArraySpec, offset?: number): void;
941
+ /**
942
+ * Creates a BufferInfo from an object of arrays.
943
+ *
944
+ * This can be passed to {@link setBuffersAndAttributes} and to
945
+ * {@link module:twgl:drawBufferInfo}.
946
+ *
947
+ * Given an object like
948
+ *
949
+ * var arrays = {
950
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
951
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
952
+ * normal: { numComponents: 3, data: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], },
953
+ * indices: { numComponents: 3, data: [0, 1, 2, 1, 2, 3], },
954
+ * };
955
+ *
956
+ * Creates an BufferInfo like this
957
+ *
958
+ * bufferInfo = {
959
+ * numElements: 4, // or whatever the number of elements is
960
+ * indices: WebGLBuffer, // this property will not exist if there are no indices
961
+ * attribs: {
962
+ * position: { buffer: WebGLBuffer, numComponents: 3, },
963
+ * normal: { buffer: WebGLBuffer, numComponents: 3, },
964
+ * texcoord: { buffer: WebGLBuffer, numComponents: 2, },
965
+ * },
966
+ * };
967
+ *
968
+ * The properties of arrays can be JavaScript arrays in which case the number of components
969
+ * will be guessed.
970
+ *
971
+ * var arrays = {
972
+ * position: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0],
973
+ * texcoord: [0, 0, 0, 1, 1, 0, 1, 1],
974
+ * normal: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],
975
+ * indices: [0, 1, 2, 1, 2, 3],
976
+ * };
977
+ *
978
+ * They can also be TypedArrays
979
+ *
980
+ * var arrays = {
981
+ * position: new Float32Array([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]),
982
+ * texcoord: new Float32Array([0, 0, 0, 1, 1, 0, 1, 1]),
983
+ * normal: new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]),
984
+ * indices: new Uint16Array([0, 1, 2, 1, 2, 3]),
985
+ * };
986
+ *
987
+ * Or AugmentedTypedArrays
988
+ *
989
+ * var positions = createAugmentedTypedArray(3, 4);
990
+ * var texcoords = createAugmentedTypedArray(2, 4);
991
+ * var normals = createAugmentedTypedArray(3, 4);
992
+ * var indices = createAugmentedTypedArray(3, 2, Uint16Array);
993
+ *
994
+ * positions.push([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]);
995
+ * texcoords.push([0, 0, 0, 1, 1, 0, 1, 1]);
996
+ * normals.push([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]);
997
+ * indices.push([0, 1, 2, 1, 2, 3]);
998
+ *
999
+ * var arrays = {
1000
+ * position: positions,
1001
+ * texcoord: texcoords,
1002
+ * normal: normals,
1003
+ * indices: indices,
1004
+ * };
1005
+ *
1006
+ * For the last example it is equivalent to
1007
+ *
1008
+ * var bufferInfo = {
1009
+ * attribs: {
1010
+ * position: { numComponents: 3, buffer: gl.createBuffer(), },
1011
+ * texcoord: { numComponents: 2, buffer: gl.createBuffer(), },
1012
+ * normal: { numComponents: 3, buffer: gl.createBuffer(), },
1013
+ * },
1014
+ * indices: gl.createBuffer(),
1015
+ * numElements: 6,
1016
+ * };
1017
+ *
1018
+ * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.position.buffer);
1019
+ * gl.bufferData(gl.ARRAY_BUFFER, arrays.position, gl.STATIC_DRAW);
1020
+ * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.texcoord.buffer);
1021
+ * gl.bufferData(gl.ARRAY_BUFFER, arrays.texcoord, gl.STATIC_DRAW);
1022
+ * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.normal.buffer);
1023
+ * gl.bufferData(gl.ARRAY_BUFFER, arrays.normal, gl.STATIC_DRAW);
1024
+ * gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, bufferInfo.indices);
1025
+ * gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, arrays.indices, gl.STATIC_DRAW);
1026
+ *
1027
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
1028
+ * @param {Arrays} arrays Your data
1029
+ * @param {BufferInfo} [srcBufferInfo] An existing
1030
+ * buffer info to start from. WebGLBuffers etc specified
1031
+ * in the srcBufferInfo will be used in a new BufferInfo
1032
+ * with any arrays specified overriding the ones in
1033
+ * srcBufferInfo.
1034
+ * @return {BufferInfo} A BufferInfo
1035
+ * @memberOf module:twgl/attributes
1036
+ */
218
1037
  export function createBufferInfoFromArrays(gl: WebGLRenderingContext, arrays: Arrays, srcBufferInfo?: BufferInfo): BufferInfo;
1038
+ /**
1039
+ * Calls `gl.drawElements` or `gl.drawArrays`, whichever is appropriate
1040
+ *
1041
+ * normally you'd call `gl.drawElements` or `gl.drawArrays` yourself
1042
+ * but calling this means if you switch from indexed data to non-indexed
1043
+ * data you don't have to remember to update your draw call.
1044
+ *
1045
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
1046
+ * @param {(BufferInfo|VertexArrayInfo)} bufferInfo A BufferInfo as returned from {@link createBufferInfoFromArrays} or
1047
+ * a VertexArrayInfo as returned from {@link createVertexArrayInfo}
1048
+ * @param {number} [type] eg (gl.TRIANGLES, gl.LINES, gl.POINTS, gl.TRIANGLE_STRIP, ...). Defaults to `gl.TRIANGLES`
1049
+ * @param {number} [count] An optional count. Defaults to bufferInfo.numElements
1050
+ * @param {number} [offset] An optional offset. Defaults to 0.
1051
+ * @param {number} [instanceCount] An optional instanceCount. if set then `drawArraysInstanced` or `drawElementsInstanced` will be called
1052
+ * @memberOf module:twgl/draw
1053
+ */
219
1054
  export function drawBufferInfo(gl: WebGLRenderingContext, bufferInfo: BufferInfo | VertexArrayInfo, type?: number, count?: number, offset?: number, instanceCount?: number): void;
1055
+ /**
1056
+ * Draws a list of objects
1057
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
1058
+ * @param {DrawObject[]} objectsToDraw an array of objects to draw.
1059
+ * @memberOf module:twgl/draw
1060
+ */
220
1061
  export function drawObjectList(gl: WebGLRenderingContext, objectsToDraw: DrawObject[]): void;
1062
+ /**
1063
+ * Creates a framebuffer and attachments.
1064
+ *
1065
+ * This returns a {@link FramebufferInfo} because it needs to return the attachments as well as the framebuffer.
1066
+ * It also leaves the framebuffer it just created as the currently bound `FRAMEBUFFER`.
1067
+ * Note: If this is WebGL2 or if you called {@link addExtensionsToContext} then it will set the drawBuffers
1068
+ * to `[COLOR_ATTACHMENT0, COLOR_ATTACHMENT1, ...]` for how ever many color attachments were created.
1069
+ *
1070
+ * The simplest usage
1071
+ *
1072
+ * // create an RGBA/UNSIGNED_BYTE texture and DEPTH_STENCIL renderbuffer
1073
+ * const fbi = twgl.createFramebufferInfo(gl);
1074
+ *
1075
+ * More complex usage
1076
+ *
1077
+ * // create an RGB565 renderbuffer and a STENCIL_INDEX8 renderbuffer
1078
+ * const attachments = [
1079
+ * { format: RGB565, mag: NEAREST },
1080
+ * { format: STENCIL_INDEX8 },
1081
+ * ]
1082
+ * const fbi = twgl.createFramebufferInfo(gl, attachments);
1083
+ *
1084
+ * Passing in a specific size
1085
+ *
1086
+ * const width = 256;
1087
+ * const height = 256;
1088
+ * const fbi = twgl.createFramebufferInfo(gl, attachments, width, height);
1089
+ *
1090
+ * **Note!!** It is up to you to check if the framebuffer is renderable by calling `gl.checkFramebufferStatus`.
1091
+ * [WebGL1 only guarantees 3 combinations of attachments work](https://www.khronos.org/registry/webgl/specs/latest/1.0/#6.6).
1092
+ *
1093
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
1094
+ * @param {AttachmentOptions[]} [attachments] which attachments to create. If not provided the default is a framebuffer with an
1095
+ * `RGBA`, `UNSIGNED_BYTE` texture `COLOR_ATTACHMENT0` and a `DEPTH_STENCIL` renderbuffer `DEPTH_STENCIL_ATTACHMENT`.
1096
+ * @param {number} [width] the width for the attachments. Default = size of drawingBuffer
1097
+ * @param {number} [height] the height for the attachments. Default = size of drawingBuffer
1098
+ * @return {FramebufferInfo} the framebuffer and attachments.
1099
+ * @memberOf module:twgl/framebuffers
1100
+ */
221
1101
  export function createFramebufferInfo(gl: WebGLRenderingContext, attachments?: AttachmentOptions[], width?: number, height?: number): FramebufferInfo;
1102
+ /**
1103
+ * Resizes the attachments of a framebuffer.
1104
+ *
1105
+ * You need to pass in the same `attachments` as you passed in {@link createFramebufferInfo}
1106
+ * because TWGL has no idea the format/type of each attachment.
1107
+ *
1108
+ * The simplest usage
1109
+ *
1110
+ * // create an RGBA/UNSIGNED_BYTE texture and DEPTH_STENCIL renderbuffer
1111
+ * const fbi = twgl.createFramebufferInfo(gl);
1112
+ *
1113
+ * ...
1114
+ *
1115
+ * function render() {
1116
+ * if (twgl.resizeCanvasToDisplaySize(gl.canvas)) {
1117
+ * // resize the attachments
1118
+ * twgl.resizeFramebufferInfo(gl, fbi);
1119
+ * }
1120
+ *
1121
+ * More complex usage
1122
+ *
1123
+ * // create an RGB565 renderbuffer and a STENCIL_INDEX8 renderbuffer
1124
+ * const attachments = [
1125
+ * { format: RGB565, mag: NEAREST },
1126
+ * { format: STENCIL_INDEX8 },
1127
+ * ]
1128
+ * const fbi = twgl.createFramebufferInfo(gl, attachments);
1129
+ *
1130
+ * ...
1131
+ *
1132
+ * function render() {
1133
+ * if (twgl.resizeCanvasToDisplaySize(gl.canvas)) {
1134
+ * // resize the attachments to match
1135
+ * twgl.resizeFramebufferInfo(gl, fbi, attachments);
1136
+ * }
1137
+ *
1138
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
1139
+ * @param {FramebufferInfo} framebufferInfo a framebufferInfo as returned from {@link createFramebufferInfo}.
1140
+ * @param {AttachmentOptions[]} [attachments] the same attachments options as passed to {@link createFramebufferInfo}.
1141
+ * @param {number} [width] the width for the attachments. Default = size of drawingBuffer
1142
+ * @param {number} [height] the height for the attachments. Default = size of drawingBuffer
1143
+ * @memberOf module:twgl/framebuffers
1144
+ */
222
1145
  export function resizeFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo: FramebufferInfo, attachments?: AttachmentOptions[], width?: number, height?: number): void;
1146
+ /**
1147
+ * Binds a framebuffer
1148
+ *
1149
+ * This function pretty much solely exists because I spent hours
1150
+ * trying to figure out why something I wrote wasn't working only
1151
+ * to realize I forget to set the viewport dimensions.
1152
+ * My hope is this function will fix that.
1153
+ *
1154
+ * It is effectively the same as
1155
+ *
1156
+ * gl.bindFramebuffer(gl.FRAMEBUFFER, someFramebufferInfo.framebuffer);
1157
+ * gl.viewport(0, 0, someFramebufferInfo.width, someFramebufferInfo.height);
1158
+ *
1159
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
1160
+ * @param {FramebufferInfo|null} [framebufferInfo] a framebufferInfo as returned from {@link createFramebufferInfo}.
1161
+ * If falsy will bind the canvas.
1162
+ * @param {number} [target] The target. If not passed `gl.FRAMEBUFFER` will be used.
1163
+ * @memberOf module:twgl/framebuffers
1164
+ */
223
1165
  export function bindFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo?: FramebufferInfo | null, target?: number): void;
1166
+ /**
1167
+ * Creates a ProgramInfo from 2 sources.
1168
+ *
1169
+ * A ProgramInfo contains
1170
+ *
1171
+ * programInfo = {
1172
+ * program: WebGLProgram,
1173
+ * uniformSetters: object of setters as returned from createUniformSetters,
1174
+ * attribSetters: object of setters as returned from createAttribSetters,
1175
+ * }
1176
+ *
1177
+ * NOTE: There are 4 signatures for this function
1178
+ *
1179
+ * twgl.createProgramInfo(gl, [vs, fs], options);
1180
+ * twgl.createProgramInfo(gl, [vs, fs], opt_errFunc);
1181
+ * twgl.createProgramInfo(gl, [vs, fs], opt_attribs, opt_errFunc);
1182
+ * twgl.createProgramInfo(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
1183
+ *
1184
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
1185
+ * to use.
1186
+ * @param {string[]} shaderSources Array of sources for the
1187
+ * shaders or ids. The first is assumed to be the vertex shader,
1188
+ * the second the fragment shader.
1189
+ * @param {ProgramOptions|string[]|ErrorCallback} [opt_attribs] Options for the program or an array of attribs names or an error callback. Locations will be assigned by index if not passed in
1190
+ * @param {number[]} [opt_locations|ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
1191
+ * @param {ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
1192
+ * on error. If you want something else pass an callback. It's passed an error message.
1193
+ * @return {ProgramInfo?} The created ProgramInfo or null if it failed to link or compile
1194
+ * @memberOf module:twgl/programs
1195
+ */
224
1196
  export function createProgramInfo(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): ProgramInfo;
1197
+ /**
1198
+ * Creates a `UniformBlockInfo` for the specified block
1199
+ *
1200
+ * Note: **If the blockName matches no existing blocks a warning is printed to the console and a dummy
1201
+ * `UniformBlockInfo` is returned**. This is because when debugging GLSL
1202
+ * it is common to comment out large portions of a shader or for example set
1203
+ * the final output to a constant. When that happens blocks get optimized out.
1204
+ * If this function did not create dummy blocks your code would crash when debugging.
1205
+ *
1206
+ * @param {WebGL2RenderingContext} gl A WebGL2RenderingContext
1207
+ * @param {ProgramInfo} programInfo a `ProgramInfo`
1208
+ * as returned from {@link createProgramInfo}
1209
+ * @param {string} blockName The name of the block.
1210
+ * @return {UniformBlockInfo} The created UniformBlockInfo
1211
+ * @memberOf module:twgl/programs
1212
+ */
225
1213
  export function createUniformBlockInfo(gl: WebGL2RenderingContext, programInfo: ProgramInfo, blockName: string): UniformBlockInfo;
1214
+ /**
1215
+ * Binds a uniform block to the matching uniform block point.
1216
+ * Matches by blocks by name so blocks must have the same name not just the same
1217
+ * structure.
1218
+ *
1219
+ * If you have changed any values and you upload the values into the corresponding WebGLBuffer
1220
+ * call {@link setUniformBlock} instead.
1221
+ *
1222
+ * @param {WebGL2RenderingContext} gl A WebGL 2 rendering context.
1223
+ * @param {(ProgramInfo|UniformBlockSpec)} programInfo a `ProgramInfo`
1224
+ * as returned from {@link createProgramInfo} or or `UniformBlockSpec` as
1225
+ * returned from {@link createUniformBlockSpecFromProgram}.
1226
+ * @param {UniformBlockInfo} uniformBlockInfo a `UniformBlockInfo` as returned from
1227
+ * {@link createUniformBlockInfo}.
1228
+ * @return {bool} true if buffer was bound. If the programInfo has no block with the same block name
1229
+ * no buffer is bound.
1230
+ * @memberOf module:twgl/programs
1231
+ */
226
1232
  export function bindUniformBlock(gl: WebGL2RenderingContext, programInfo: ProgramInfo | UniformBlockSpec, uniformBlockInfo: UniformBlockInfo): boolean;
1233
+ /**
1234
+ * Uploads the current uniform values to the corresponding WebGLBuffer
1235
+ * and binds that buffer to the program's corresponding bind point for the uniform block object.
1236
+ *
1237
+ * If you haven't changed any values and you only need to bind the uniform block object
1238
+ * call {@link bindUniformBlock} instead.
1239
+ *
1240
+ * @param {WebGL2RenderingContext} gl A WebGL 2 rendering context.
1241
+ * @param {(ProgramInfo|UniformBlockSpec)} programInfo a `ProgramInfo`
1242
+ * as returned from {@link createProgramInfo} or or `UniformBlockSpec` as
1243
+ * returned from {@link createUniformBlockSpecFromProgram}.
1244
+ * @param {UniformBlockInfo} uniformBlockInfo a `UniformBlockInfo` as returned from
1245
+ * {@link createUniformBlockInfo}.
1246
+ * @memberOf module:twgl/programs
1247
+ */
227
1248
  export function setUniformBlock(gl: WebGL2RenderingContext, programInfo: ProgramInfo | UniformBlockSpec, uniformBlockInfo: UniformBlockInfo): void;
1249
+ /**
1250
+ * Sets values of a uniform block object
1251
+ *
1252
+ * @param {UniformBlockInfo} uniformBlockInfo A UniformBlockInfo as returned by {@link createUniformBlockInfo}.
1253
+ * @param {Object.<string, ?>} values A uniform name to value map where the value is correct for the given
1254
+ * type of uniform. So for example given a block like
1255
+ *
1256
+ * uniform SomeBlock {
1257
+ * float someFloat;
1258
+ * vec2 someVec2;
1259
+ * vec3 someVec3Array[2];
1260
+ * int someInt;
1261
+ * }
1262
+ *
1263
+ * You can set the values of the uniform block with
1264
+ *
1265
+ * twgl.setBlockUniforms(someBlockInfo, {
1266
+ * someFloat: 12.3,
1267
+ * someVec2: [1, 2],
1268
+ * someVec3Array: [1, 2, 3, 4, 5, 6],
1269
+ * someInt: 5,
1270
+ * }
1271
+ *
1272
+ * Arrays can be JavaScript arrays or typed arrays
1273
+ *
1274
+ * You can also fill out structure and array values either via
1275
+ * shortcut. Example
1276
+ *
1277
+ * // -- in shader --
1278
+ * struct Light {
1279
+ * float intensity;
1280
+ * vec4 color;
1281
+ * float nearFar[2];
1282
+ * };
1283
+ * uniform Lights {
1284
+ * Light lights[2];
1285
+ * };
1286
+ *
1287
+ * // in JavaScript
1288
+ *
1289
+ * twgl.setBlockUniforms(someBlockInfo, {
1290
+ * lights: [
1291
+ * { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.1, 10] },
1292
+ * { intensity: 2.0, color: [0, 0, 1, 1], nearFar[0.2, 15] },
1293
+ * ],
1294
+ * });
1295
+ *
1296
+ * or the more traditional way
1297
+ *
1298
+ * twgl.setBlockUniforms(someBlockInfo, {
1299
+ * "lights[0].intensity": 5.0,
1300
+ * "lights[0].color": [1, 0, 0, 1],
1301
+ * "lights[0].nearFar": [0.1, 10],
1302
+ * "lights[1].intensity": 2.0,
1303
+ * "lights[1].color": [0, 0, 1, 1],
1304
+ * "lights[1].nearFar": [0.2, 15],
1305
+ * });
1306
+ *
1307
+ * You can also specify partial paths
1308
+ *
1309
+ * twgl.setBlockUniforms(someBlockInfo, {
1310
+ * 'lights[1]': { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.2, 15] },
1311
+ * });
1312
+ *
1313
+ * But you can not specify leaf array indices.
1314
+ *
1315
+ * twgl.setBlockUniforms(someBlockInfo, {
1316
+ * 'lights[1].nearFar[1]': 15, // BAD! nearFar is a leaf
1317
+ * 'lights[1].nearFar': [0.2, 15], // GOOD
1318
+ * });
1319
+ *
1320
+ * **IMPORTANT!**, packing in a UniformBlock is unintuitive.
1321
+ * For example the actual layout of `someVec3Array` above in memory
1322
+ * is `1, 2, 3, unused, 4, 5, 6, unused`. twgl takes in 6 values
1323
+ * as shown about and copies them, skipping the padding. This might
1324
+ * be confusing if you're already familiar with Uniform blocks.
1325
+ *
1326
+ * If you want to deal with the padding yourself you can access the array
1327
+ * buffer views directly. eg:
1328
+ *
1329
+ * someBlockInfo.someVec3Array.set([1, 2, 3, 0, 4, 5, 6, 0]);
1330
+ *
1331
+ * Any name that doesn't match will be ignored
1332
+ * @memberOf module:twgl/programs
1333
+ */
228
1334
  export function setBlockUniforms(uniformBlockInfo: UniformBlockInfo, values: {
229
1335
  [key: string]: any;
230
1336
  }): void;
1337
+ /**
1338
+ * Set uniforms and binds related textures.
1339
+ *
1340
+ * example:
1341
+ *
1342
+ * const programInfo = createProgramInfo(
1343
+ * gl, ["some-vs", "some-fs"]);
1344
+ *
1345
+ * const tex1 = gl.createTexture();
1346
+ * const tex2 = gl.createTexture();
1347
+ *
1348
+ * ... assume we setup the textures with data ...
1349
+ *
1350
+ * const uniforms = {
1351
+ * u_someSampler: tex1,
1352
+ * u_someOtherSampler: tex2,
1353
+ * u_someColor: [1,0,0,1],
1354
+ * u_somePosition: [0,1,1],
1355
+ * u_someMatrix: [
1356
+ * 1,0,0,0,
1357
+ * 0,1,0,0,
1358
+ * 0,0,1,0,
1359
+ * 0,0,0,0,
1360
+ * ],
1361
+ * };
1362
+ *
1363
+ * gl.useProgram(programInfo.program);
1364
+ *
1365
+ * This will automatically bind the textures AND set the
1366
+ * uniforms.
1367
+ *
1368
+ * twgl.setUniforms(programInfo, uniforms);
1369
+ *
1370
+ * For the example above it is equivalent to
1371
+ *
1372
+ * let texUnit = 0;
1373
+ * gl.activeTexture(gl.TEXTURE0 + texUnit);
1374
+ * gl.bindTexture(gl.TEXTURE_2D, tex1);
1375
+ * gl.uniform1i(u_someSamplerLocation, texUnit++);
1376
+ * gl.activeTexture(gl.TEXTURE0 + texUnit);
1377
+ * gl.bindTexture(gl.TEXTURE_2D, tex2);
1378
+ * gl.uniform1i(u_someSamplerLocation, texUnit++);
1379
+ * gl.uniform4fv(u_someColorLocation, [1, 0, 0, 1]);
1380
+ * gl.uniform3fv(u_somePositionLocation, [0, 1, 1]);
1381
+ * gl.uniformMatrix4fv(u_someMatrix, false, [
1382
+ * 1,0,0,0,
1383
+ * 0,1,0,0,
1384
+ * 0,0,1,0,
1385
+ * 0,0,0,0,
1386
+ * ]);
1387
+ *
1388
+ * Note it is perfectly reasonable to call `setUniforms` multiple times. For example
1389
+ *
1390
+ * const uniforms = {
1391
+ * u_someSampler: tex1,
1392
+ * u_someOtherSampler: tex2,
1393
+ * };
1394
+ *
1395
+ * const moreUniforms {
1396
+ * u_someColor: [1,0,0,1],
1397
+ * u_somePosition: [0,1,1],
1398
+ * u_someMatrix: [
1399
+ * 1,0,0,0,
1400
+ * 0,1,0,0,
1401
+ * 0,0,1,0,
1402
+ * 0,0,0,0,
1403
+ * ],
1404
+ * };
1405
+ *
1406
+ * twgl.setUniforms(programInfo, uniforms);
1407
+ * twgl.setUniforms(programInfo, moreUniforms);
1408
+ *
1409
+ * You can also add WebGLSamplers to uniform samplers as in
1410
+ *
1411
+ * const uniforms = {
1412
+ * u_someSampler: {
1413
+ * texture: someWebGLTexture,
1414
+ * sampler: someWebGLSampler,
1415
+ * },
1416
+ * };
1417
+ *
1418
+ * In which case both the sampler and texture will be bound to the
1419
+ * same unit.
1420
+ *
1421
+ * @param {(ProgramInfo|Object.<string, function>)} setters a `ProgramInfo` as returned from `createProgramInfo` or the setters returned from
1422
+ * `createUniformSetters`.
1423
+ * @param {Object.<string, ?>} values an object with values for the
1424
+ * uniforms.
1425
+ * You can pass multiple objects by putting them in an array or by calling with more arguments.For example
1426
+ *
1427
+ * const sharedUniforms = {
1428
+ * u_fogNear: 10,
1429
+ * u_projection: ...
1430
+ * ...
1431
+ * };
1432
+ *
1433
+ * const localUniforms = {
1434
+ * u_world: ...
1435
+ * u_diffuseColor: ...
1436
+ * };
1437
+ *
1438
+ * twgl.setUniforms(programInfo, sharedUniforms, localUniforms);
1439
+ *
1440
+ * // is the same as
1441
+ *
1442
+ * twgl.setUniforms(programInfo, [sharedUniforms, localUniforms]);
1443
+ *
1444
+ * // is the same as
1445
+ *
1446
+ * twgl.setUniforms(programInfo, sharedUniforms);
1447
+ * twgl.setUniforms(programInfo, localUniforms};
1448
+ *
1449
+ * You can also fill out structure and array values either via
1450
+ * shortcut. Example
1451
+ *
1452
+ * // -- in shader --
1453
+ * struct Light {
1454
+ * float intensity;
1455
+ * vec4 color;
1456
+ * float nearFar[2];
1457
+ * };
1458
+ * uniform Light lights[2];
1459
+ *
1460
+ * // in JavaScript
1461
+ *
1462
+ * twgl.setUniforms(programInfo, {
1463
+ * lights: [
1464
+ * { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.1, 10] },
1465
+ * { intensity: 2.0, color: [0, 0, 1, 1], nearFar[0.2, 15] },
1466
+ * ],
1467
+ * });
1468
+ *
1469
+ * or the more traditional way
1470
+ *
1471
+ * twgl.setUniforms(programInfo, {
1472
+ * "lights[0].intensity": 5.0,
1473
+ * "lights[0].color": [1, 0, 0, 1],
1474
+ * "lights[0].nearFar": [0.1, 10],
1475
+ * "lights[1].intensity": 2.0,
1476
+ * "lights[1].color": [0, 0, 1, 1],
1477
+ * "lights[1].nearFar": [0.2, 15],
1478
+ * });
1479
+ *
1480
+ * You can also specify partial paths
1481
+ *
1482
+ * twgl.setUniforms(programInfo, {
1483
+ * 'lights[1]': { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.2, 15] },
1484
+ * });
1485
+ *
1486
+ * But you can not specify leaf array indices
1487
+ *
1488
+ * twgl.setUniforms(programInfo, {
1489
+ * 'lights[1].nearFar[1]': 15, // BAD! nearFar is a leaf
1490
+ * 'lights[1].nearFar': [0.2, 15], // GOOD
1491
+ * });
1492
+ *
1493
+ * @memberOf module:twgl/programs
1494
+ */
231
1495
  export function setUniforms(setters: ProgramInfo | {
232
1496
  [key: string]: (...params: any[]) => any;
233
1497
  }, values: {
234
1498
  [key: string]: any;
235
1499
  }): void;
1500
+ /**
1501
+ * Sets attributes and buffers including the `ELEMENT_ARRAY_BUFFER` if appropriate
1502
+ *
1503
+ * Example:
1504
+ *
1505
+ * const programInfo = createProgramInfo(
1506
+ * gl, ["some-vs", "some-fs");
1507
+ *
1508
+ * const arrays = {
1509
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
1510
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
1511
+ * };
1512
+ *
1513
+ * const bufferInfo = createBufferInfoFromArrays(gl, arrays);
1514
+ *
1515
+ * gl.useProgram(programInfo.program);
1516
+ *
1517
+ * This will automatically bind the buffers AND set the
1518
+ * attributes.
1519
+ *
1520
+ * setBuffersAndAttributes(gl, programInfo, bufferInfo);
1521
+ *
1522
+ * For the example above it is equivalent to
1523
+ *
1524
+ * gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
1525
+ * gl.enableVertexAttribArray(a_positionLocation);
1526
+ * gl.vertexAttribPointer(a_positionLocation, 3, gl.FLOAT, false, 0, 0);
1527
+ * gl.bindBuffer(gl.ARRAY_BUFFER, texcoordBuffer);
1528
+ * gl.enableVertexAttribArray(a_texcoordLocation);
1529
+ * gl.vertexAttribPointer(a_texcoordLocation, 4, gl.FLOAT, false, 0, 0);
1530
+ *
1531
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext.
1532
+ * @param {(ProgramInfo|Object.<string, function>)} setters A `ProgramInfo` as returned from {@link createProgramInfo} or Attribute setters as returned from {@link createAttributeSetters}
1533
+ * @param {(BufferInfo|VertexArrayInfo)} buffers a `BufferInfo` as returned from {@link createBufferInfoFromArrays}.
1534
+ * or a `VertexArrayInfo` as returned from {@link createVertexArrayInfo}
1535
+ * @memberOf module:twgl/programs
1536
+ */
236
1537
  export function setBuffersAndAttributes(gl: WebGLRenderingContext, setters: ProgramInfo | {
237
1538
  [key: string]: (...params: any[]) => any;
238
1539
  }, buffers: BufferInfo | VertexArrayInfo): void;
1540
+ /**
1541
+ * Sets a texture from an array or typed array. If the width or height is not provided will attempt to
1542
+ * guess the size. See {@link TextureOptions}.
1543
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
1544
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
1545
+ * @param {(number[]|ArrayBufferView)} src An array or typed arry with texture data.
1546
+ * @param {TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
1547
+ * This is often the same options you passed in when you created the texture.
1548
+ * @memberOf module:twgl/textures
1549
+ */
239
1550
  export function setTextureFromArray(gl: WebGLRenderingContext, tex: WebGLTexture, src: number[] | ArrayBufferView, options?: TextureOptions): void;
1551
+ /**
1552
+ * Creates a texture based on the options passed in.
1553
+ *
1554
+ * Note: may reset UNPACK_ALIGNMENT, UNPACK_ROW_LENGTH, UNPACK_IMAGE_HEIGHT, UNPACK_SKIP_IMAGES
1555
+ * UNPACK_SKIP_PIXELS, and UNPACK_SKIP_ROWS
1556
+ *
1557
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
1558
+ * @param {TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
1559
+ * @param {TextureReadyCallback} [callback] A callback called when an image has been downloaded and uploaded to the texture.
1560
+ * @return {WebGLTexture} the created texture.
1561
+ * @memberOf module:twgl/textures
1562
+ */
240
1563
  export function createTexture(gl: WebGLRenderingContext, options?: TextureOptions, callback?: TextureReadyCallback): WebGLTexture;
1564
+ /**
1565
+ * Resizes a texture based on the options passed in.
1566
+ *
1567
+ * Note: This is not a generic resize anything function.
1568
+ * It's mostly used by {@link resizeFramebufferInfo}
1569
+ * It will use `options.src` if it exists to try to determine a `type`
1570
+ * otherwise it will assume `gl.UNSIGNED_BYTE`. No data is provided
1571
+ * for the texture. Texture parameters will be set accordingly
1572
+ *
1573
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
1574
+ * @param {WebGLTexture} tex the texture to resize
1575
+ * @param {TextureOptions} options A TextureOptions object with whatever parameters you want set.
1576
+ * @param {number} [width] the new width. If not passed in will use `options.width`
1577
+ * @param {number} [height] the new height. If not passed in will use `options.height`
1578
+ * @param {number} [depth] the new depth. If not passed in will use `options.depth`
1579
+ * @memberOf module:twgl/textures
1580
+ */
241
1581
  export function resizeTexture(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, width?: number, height?: number, depth?: number): void;
1582
+ /**
1583
+ * Creates a bunch of textures based on the passed in options.
1584
+ *
1585
+ * Example:
1586
+ *
1587
+ * const textures = twgl.createTextures(gl, {
1588
+ * // a power of 2 image
1589
+ * hftIcon: { src: "images/hft-icon-16.png", mag: gl.NEAREST },
1590
+ * // a non-power of 2 image
1591
+ * clover: { src: "images/clover.jpg" },
1592
+ * // From a canvas
1593
+ * fromCanvas: { src: ctx.canvas },
1594
+ * // A cubemap from 6 images
1595
+ * yokohama: {
1596
+ * target: gl.TEXTURE_CUBE_MAP,
1597
+ * src: [
1598
+ * 'images/yokohama/posx.jpg',
1599
+ * 'images/yokohama/negx.jpg',
1600
+ * 'images/yokohama/posy.jpg',
1601
+ * 'images/yokohama/negy.jpg',
1602
+ * 'images/yokohama/posz.jpg',
1603
+ * 'images/yokohama/negz.jpg',
1604
+ * ],
1605
+ * },
1606
+ * // A cubemap from 1 image (can be 1x6, 2x3, 3x2, 6x1)
1607
+ * goldengate: {
1608
+ * target: gl.TEXTURE_CUBE_MAP,
1609
+ * src: 'images/goldengate.jpg',
1610
+ * },
1611
+ * // A 2x2 pixel texture from a JavaScript array
1612
+ * checker: {
1613
+ * mag: gl.NEAREST,
1614
+ * min: gl.LINEAR,
1615
+ * src: [
1616
+ * 255,255,255,255,
1617
+ * 192,192,192,255,
1618
+ * 192,192,192,255,
1619
+ * 255,255,255,255,
1620
+ * ],
1621
+ * },
1622
+ * // a 1x2 pixel texture from a typed array.
1623
+ * stripe: {
1624
+ * mag: gl.NEAREST,
1625
+ * min: gl.LINEAR,
1626
+ * format: gl.LUMINANCE,
1627
+ * src: new Uint8Array([
1628
+ * 255,
1629
+ * 128,
1630
+ * 255,
1631
+ * 128,
1632
+ * 255,
1633
+ * 128,
1634
+ * 255,
1635
+ * 128,
1636
+ * ]),
1637
+ * width: 1,
1638
+ * },
1639
+ * });
1640
+ *
1641
+ * Now
1642
+ *
1643
+ * * `textures.hftIcon` will be a 2d texture
1644
+ * * `textures.clover` will be a 2d texture
1645
+ * * `textures.fromCanvas` will be a 2d texture
1646
+ * * `textures.yohohama` will be a cubemap texture
1647
+ * * `textures.goldengate` will be a cubemap texture
1648
+ * * `textures.checker` will be a 2d texture
1649
+ * * `textures.stripe` will be a 2d texture
1650
+ *
1651
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
1652
+ * @param {Object.<string,TextureOptions>} options A object of TextureOptions one per texture.
1653
+ * @param {TexturesReadyCallback} [callback] A callback called when all textures have been downloaded.
1654
+ * @return {Object.<string,WebGLTexture>} the created textures by name
1655
+ * @memberOf module:twgl/textures
1656
+ */
242
1657
  export function createTextures(gl: WebGLRenderingContext, options: {
243
1658
  [key: string]: TextureOptions;
244
1659
  }, callback?: TexturesReadyCallback): {
@@ -246,79 +1661,1120 @@ export function createTextures(gl: WebGLRenderingContext, options: {
246
1661
  };
247
1662
 
248
1663
 
1664
+ /**
1665
+ * Sets the default attrib prefix
1666
+ *
1667
+ * When writing shaders I prefer to name attributes with `a_`, uniforms with `u_` and varyings with `v_`
1668
+ * as it makes it clear where they came from. But, when building geometry I prefer using un-prefixed names.
1669
+ *
1670
+ * In other words I'll create arrays of geometry like this
1671
+ *
1672
+ * var arrays = {
1673
+ * position: ...
1674
+ * normal: ...
1675
+ * texcoord: ...
1676
+ * };
1677
+ *
1678
+ * But need those mapped to attributes and my attributes start with `a_`.
1679
+ *
1680
+ * @deprecated see {@link setDefaults}
1681
+ * @param {string} prefix prefix for attribs
1682
+ * @memberOf module:twgl/attributes
1683
+ */
249
1684
  export function setAttributePrefix(prefix: string): void;
1685
+ /**
1686
+ * Given typed array creates a WebGLBuffer and copies the typed array
1687
+ * into it.
1688
+ *
1689
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
1690
+ * @param {ArrayBuffer|SharedArrayBuffer|ArrayBufferView|WebGLBuffer} typedArray the typed array. Note: If a WebGLBuffer is passed in it will just be returned. No action will be taken
1691
+ * @param {number} [type] the GL bind type for the buffer. Default = `gl.ARRAY_BUFFER`.
1692
+ * @param {number} [drawType] the GL draw type for the buffer. Default = 'gl.STATIC_DRAW`.
1693
+ * @return {WebGLBuffer} the created WebGLBuffer
1694
+ * @memberOf module:twgl/attributes
1695
+ */
250
1696
  export function createBufferFromTypedArray(gl: WebGLRenderingContext, typedArray: ArrayBuffer | SharedArrayBuffer | ArrayBufferView | WebGLBuffer, type?: number, drawType?: number): WebGLBuffer;
1697
+ /**
1698
+ * @typedef {(Int8ArrayConstructor|Uint8ArrayConstructor|Int16ArrayConstructor|Uint16ArrayConstructor|Int32ArrayConstructor|Uint32ArrayConstructor|Float32ArrayConstructor)} TypedArrayConstructor
1699
+ */
251
1700
  export type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor;
1701
+ /**
1702
+ * Creates a set of attribute data and WebGLBuffers from set of arrays
1703
+ *
1704
+ * Given
1705
+ *
1706
+ * var arrays = {
1707
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
1708
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
1709
+ * normal: { numComponents: 3, data: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], },
1710
+ * color: { numComponents: 4, data: [255, 255, 255, 255, 255, 0, 0, 255, 0, 0, 255, 255], type: Uint8Array, },
1711
+ * indices: { numComponents: 3, data: [0, 1, 2, 1, 2, 3], },
1712
+ * };
1713
+ *
1714
+ * returns something like
1715
+ *
1716
+ * var attribs = {
1717
+ * position: { numComponents: 3, type: gl.FLOAT, normalize: false, buffer: WebGLBuffer, },
1718
+ * texcoord: { numComponents: 2, type: gl.FLOAT, normalize: false, buffer: WebGLBuffer, },
1719
+ * normal: { numComponents: 3, type: gl.FLOAT, normalize: false, buffer: WebGLBuffer, },
1720
+ * color: { numComponents: 4, type: gl.UNSIGNED_BYTE, normalize: true, buffer: WebGLBuffer, },
1721
+ * };
1722
+ *
1723
+ * notes:
1724
+ *
1725
+ * * Arrays can take various forms
1726
+ *
1727
+ * Bare JavaScript Arrays
1728
+ *
1729
+ * var arrays = {
1730
+ * position: [-1, 1, 0],
1731
+ * normal: [0, 1, 0],
1732
+ * ...
1733
+ * }
1734
+ *
1735
+ * Bare TypedArrays
1736
+ *
1737
+ * var arrays = {
1738
+ * position: new Float32Array([-1, 1, 0]),
1739
+ * color: new Uint8Array([255, 128, 64, 255]),
1740
+ * ...
1741
+ * }
1742
+ *
1743
+ * * Will guess at `numComponents` if not specified based on name.
1744
+ *
1745
+ * If `coord` is in the name assumes `numComponents = 2`
1746
+ *
1747
+ * If `color` is in the name assumes `numComponents = 4`
1748
+ *
1749
+ * otherwise assumes `numComponents = 3`
1750
+ *
1751
+ * @param {WebGLRenderingContext} gl The webgl rendering context.
1752
+ * @param {Arrays} arrays The arrays
1753
+ * @param {BufferInfo} [srcBufferInfo] a BufferInfo to copy from
1754
+ * This lets you share buffers. Any arrays you supply will override
1755
+ * the buffers from srcBufferInfo.
1756
+ * @return {Object.<string, AttribInfo>} the attribs
1757
+ * @memberOf module:twgl/attributes
1758
+ */
252
1759
  export function createAttribsFromArrays(gl: WebGLRenderingContext, arrays: Arrays, srcBufferInfo?: BufferInfo): {
253
1760
  [key: string]: AttribInfo;
254
1761
  };
1762
+ /**
1763
+ * Sets the contents of a buffer attached to an attribInfo
1764
+ *
1765
+ * This is helper function to dynamically update a buffer.
1766
+ *
1767
+ * Let's say you make a bufferInfo
1768
+ *
1769
+ * var arrays = {
1770
+ * position: new Float32Array([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]),
1771
+ * texcoord: new Float32Array([0, 0, 0, 1, 1, 0, 1, 1]),
1772
+ * normal: new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]),
1773
+ * indices: new Uint16Array([0, 1, 2, 1, 2, 3]),
1774
+ * };
1775
+ * var bufferInfo = twgl.createBufferInfoFromArrays(gl, arrays);
1776
+ *
1777
+ * And you want to dynamically update the positions. You could do this
1778
+ *
1779
+ * // assuming arrays.position has already been updated with new data.
1780
+ * twgl.setAttribInfoBufferFromArray(gl, bufferInfo.attribs.position, arrays.position);
1781
+ *
1782
+ * @param {WebGLRenderingContext} gl
1783
+ * @param {AttribInfo} attribInfo The attribInfo who's buffer contents to set. NOTE: If you have an attribute prefix
1784
+ * the name of the attribute will include the prefix.
1785
+ * @param {ArraySpec} array Note: it is arguably inefficient to pass in anything but a typed array because anything
1786
+ * else will have to be converted to a typed array before it can be used by WebGL. During init time that
1787
+ * inefficiency is usually not important but if you're updating data dynamically best to be efficient.
1788
+ * @param {number} [offset] an optional offset into the buffer. This is only an offset into the WebGL buffer
1789
+ * not the array. To pass in an offset into the array itself use a typed array and create an `ArrayBufferView`
1790
+ * for the portion of the array you want to use.
1791
+ *
1792
+ * var someArray = new Float32Array(1000); // an array with 1000 floats
1793
+ * var someSubArray = new Float32Array(someArray.buffer, offsetInBytes, sizeInUnits); // a view into someArray
1794
+ *
1795
+ * Now you can pass `someSubArray` into setAttribInfoBufferFromArray`
1796
+ * @memberOf module:twgl/attributes
1797
+ */
255
1798
  export function setAttribInfoBufferFromArray(gl: WebGLRenderingContext, attribInfo: AttribInfo, array: ArraySpec, offset?: number): void;
1799
+ /**
1800
+ * Creates a BufferInfo from an object of arrays.
1801
+ *
1802
+ * This can be passed to {@link setBuffersAndAttributes} and to
1803
+ * {@link module:twgl:drawBufferInfo}.
1804
+ *
1805
+ * Given an object like
1806
+ *
1807
+ * var arrays = {
1808
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
1809
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
1810
+ * normal: { numComponents: 3, data: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], },
1811
+ * indices: { numComponents: 3, data: [0, 1, 2, 1, 2, 3], },
1812
+ * };
1813
+ *
1814
+ * Creates an BufferInfo like this
1815
+ *
1816
+ * bufferInfo = {
1817
+ * numElements: 4, // or whatever the number of elements is
1818
+ * indices: WebGLBuffer, // this property will not exist if there are no indices
1819
+ * attribs: {
1820
+ * position: { buffer: WebGLBuffer, numComponents: 3, },
1821
+ * normal: { buffer: WebGLBuffer, numComponents: 3, },
1822
+ * texcoord: { buffer: WebGLBuffer, numComponents: 2, },
1823
+ * },
1824
+ * };
1825
+ *
1826
+ * The properties of arrays can be JavaScript arrays in which case the number of components
1827
+ * will be guessed.
1828
+ *
1829
+ * var arrays = {
1830
+ * position: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0],
1831
+ * texcoord: [0, 0, 0, 1, 1, 0, 1, 1],
1832
+ * normal: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],
1833
+ * indices: [0, 1, 2, 1, 2, 3],
1834
+ * };
1835
+ *
1836
+ * They can also be TypedArrays
1837
+ *
1838
+ * var arrays = {
1839
+ * position: new Float32Array([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]),
1840
+ * texcoord: new Float32Array([0, 0, 0, 1, 1, 0, 1, 1]),
1841
+ * normal: new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]),
1842
+ * indices: new Uint16Array([0, 1, 2, 1, 2, 3]),
1843
+ * };
1844
+ *
1845
+ * Or AugmentedTypedArrays
1846
+ *
1847
+ * var positions = createAugmentedTypedArray(3, 4);
1848
+ * var texcoords = createAugmentedTypedArray(2, 4);
1849
+ * var normals = createAugmentedTypedArray(3, 4);
1850
+ * var indices = createAugmentedTypedArray(3, 2, Uint16Array);
1851
+ *
1852
+ * positions.push([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]);
1853
+ * texcoords.push([0, 0, 0, 1, 1, 0, 1, 1]);
1854
+ * normals.push([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]);
1855
+ * indices.push([0, 1, 2, 1, 2, 3]);
1856
+ *
1857
+ * var arrays = {
1858
+ * position: positions,
1859
+ * texcoord: texcoords,
1860
+ * normal: normals,
1861
+ * indices: indices,
1862
+ * };
1863
+ *
1864
+ * For the last example it is equivalent to
1865
+ *
1866
+ * var bufferInfo = {
1867
+ * attribs: {
1868
+ * position: { numComponents: 3, buffer: gl.createBuffer(), },
1869
+ * texcoord: { numComponents: 2, buffer: gl.createBuffer(), },
1870
+ * normal: { numComponents: 3, buffer: gl.createBuffer(), },
1871
+ * },
1872
+ * indices: gl.createBuffer(),
1873
+ * numElements: 6,
1874
+ * };
1875
+ *
1876
+ * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.position.buffer);
1877
+ * gl.bufferData(gl.ARRAY_BUFFER, arrays.position, gl.STATIC_DRAW);
1878
+ * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.texcoord.buffer);
1879
+ * gl.bufferData(gl.ARRAY_BUFFER, arrays.texcoord, gl.STATIC_DRAW);
1880
+ * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.normal.buffer);
1881
+ * gl.bufferData(gl.ARRAY_BUFFER, arrays.normal, gl.STATIC_DRAW);
1882
+ * gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, bufferInfo.indices);
1883
+ * gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, arrays.indices, gl.STATIC_DRAW);
1884
+ *
1885
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
1886
+ * @param {Arrays} arrays Your data
1887
+ * @param {BufferInfo} [srcBufferInfo] An existing
1888
+ * buffer info to start from. WebGLBuffers etc specified
1889
+ * in the srcBufferInfo will be used in a new BufferInfo
1890
+ * with any arrays specified overriding the ones in
1891
+ * srcBufferInfo.
1892
+ * @return {BufferInfo} A BufferInfo
1893
+ * @memberOf module:twgl/attributes
1894
+ */
256
1895
  export function createBufferInfoFromArrays(gl: WebGLRenderingContext, arrays: Arrays, srcBufferInfo?: BufferInfo): BufferInfo;
1896
+ /**
1897
+ * Creates a buffer from an array, typed array, or array spec
1898
+ *
1899
+ * Given something like this
1900
+ *
1901
+ * [1, 2, 3],
1902
+ *
1903
+ * or
1904
+ *
1905
+ * new Uint16Array([1,2,3]);
1906
+ *
1907
+ * or
1908
+ *
1909
+ * {
1910
+ * data: [1, 2, 3],
1911
+ * type: Uint8Array,
1912
+ * }
1913
+ *
1914
+ * returns a WebGLBuffer that contains the given data.
1915
+ *
1916
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext.
1917
+ * @param {ArraySpec} array an array, typed array, or array spec.
1918
+ * @param {string} arrayName name of array. Used to guess the type if type can not be derived otherwise.
1919
+ * @return {WebGLBuffer} a WebGLBuffer containing the data in array.
1920
+ * @memberOf module:twgl/attributes
1921
+ */
257
1922
  export function createBufferFromArray(gl: WebGLRenderingContext, array: ArraySpec, arrayName: string): WebGLBuffer;
1923
+ /**
1924
+ * Creates buffers from arrays or typed arrays
1925
+ *
1926
+ * Given something like this
1927
+ *
1928
+ * var arrays = {
1929
+ * positions: [1, 2, 3],
1930
+ * normals: [0, 0, 1],
1931
+ * }
1932
+ *
1933
+ * returns something like
1934
+ *
1935
+ * buffers = {
1936
+ * positions: WebGLBuffer,
1937
+ * normals: WebGLBuffer,
1938
+ * }
1939
+ *
1940
+ * If the buffer is named 'indices' it will be made an ELEMENT_ARRAY_BUFFER.
1941
+ *
1942
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext.
1943
+ * @param {Arrays} arrays
1944
+ * @return {Object<string, WebGLBuffer>} returns an object with one WebGLBuffer per array
1945
+ * @memberOf module:twgl/attributes
1946
+ */
258
1947
  export function createBuffersFromArrays(gl: WebGLRenderingContext, arrays: Arrays): {
259
1948
  [key: string]: WebGLBuffer;
260
1949
  };
261
1950
 
262
1951
 
1952
+ /**
1953
+ * Calls `gl.drawElements` or `gl.drawArrays`, whichever is appropriate
1954
+ *
1955
+ * normally you'd call `gl.drawElements` or `gl.drawArrays` yourself
1956
+ * but calling this means if you switch from indexed data to non-indexed
1957
+ * data you don't have to remember to update your draw call.
1958
+ *
1959
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
1960
+ * @param {(BufferInfo|VertexArrayInfo)} bufferInfo A BufferInfo as returned from {@link createBufferInfoFromArrays} or
1961
+ * a VertexArrayInfo as returned from {@link createVertexArrayInfo}
1962
+ * @param {number} [type] eg (gl.TRIANGLES, gl.LINES, gl.POINTS, gl.TRIANGLE_STRIP, ...). Defaults to `gl.TRIANGLES`
1963
+ * @param {number} [count] An optional count. Defaults to bufferInfo.numElements
1964
+ * @param {number} [offset] An optional offset. Defaults to 0.
1965
+ * @param {number} [instanceCount] An optional instanceCount. if set then `drawArraysInstanced` or `drawElementsInstanced` will be called
1966
+ * @memberOf module:twgl/draw
1967
+ */
263
1968
  export function drawBufferInfo(gl: WebGLRenderingContext, bufferInfo: BufferInfo | VertexArrayInfo, type?: number, count?: number, offset?: number, instanceCount?: number): void;
1969
+ /**
1970
+ * Draws a list of objects
1971
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
1972
+ * @param {DrawObject[]} objectsToDraw an array of objects to draw.
1973
+ * @memberOf module:twgl/draw
1974
+ */
264
1975
  export function drawObjectList(gl: WebGLRenderingContext, objectsToDraw: DrawObject[]): void;
265
1976
 
266
1977
 
1978
+ /**
1979
+ * Creates a framebuffer and attachments.
1980
+ *
1981
+ * This returns a {@link FramebufferInfo} because it needs to return the attachments as well as the framebuffer.
1982
+ * It also leaves the framebuffer it just created as the currently bound `FRAMEBUFFER`.
1983
+ * Note: If this is WebGL2 or if you called {@link addExtensionsToContext} then it will set the drawBuffers
1984
+ * to `[COLOR_ATTACHMENT0, COLOR_ATTACHMENT1, ...]` for how ever many color attachments were created.
1985
+ *
1986
+ * The simplest usage
1987
+ *
1988
+ * // create an RGBA/UNSIGNED_BYTE texture and DEPTH_STENCIL renderbuffer
1989
+ * const fbi = twgl.createFramebufferInfo(gl);
1990
+ *
1991
+ * More complex usage
1992
+ *
1993
+ * // create an RGB565 renderbuffer and a STENCIL_INDEX8 renderbuffer
1994
+ * const attachments = [
1995
+ * { format: RGB565, mag: NEAREST },
1996
+ * { format: STENCIL_INDEX8 },
1997
+ * ]
1998
+ * const fbi = twgl.createFramebufferInfo(gl, attachments);
1999
+ *
2000
+ * Passing in a specific size
2001
+ *
2002
+ * const width = 256;
2003
+ * const height = 256;
2004
+ * const fbi = twgl.createFramebufferInfo(gl, attachments, width, height);
2005
+ *
2006
+ * **Note!!** It is up to you to check if the framebuffer is renderable by calling `gl.checkFramebufferStatus`.
2007
+ * [WebGL1 only guarantees 3 combinations of attachments work](https://www.khronos.org/registry/webgl/specs/latest/1.0/#6.6).
2008
+ *
2009
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2010
+ * @param {AttachmentOptions[]} [attachments] which attachments to create. If not provided the default is a framebuffer with an
2011
+ * `RGBA`, `UNSIGNED_BYTE` texture `COLOR_ATTACHMENT0` and a `DEPTH_STENCIL` renderbuffer `DEPTH_STENCIL_ATTACHMENT`.
2012
+ * @param {number} [width] the width for the attachments. Default = size of drawingBuffer
2013
+ * @param {number} [height] the height for the attachments. Default = size of drawingBuffer
2014
+ * @return {FramebufferInfo} the framebuffer and attachments.
2015
+ * @memberOf module:twgl/framebuffers
2016
+ */
267
2017
  export function createFramebufferInfo(gl: WebGLRenderingContext, attachments?: AttachmentOptions[], width?: number, height?: number): FramebufferInfo;
2018
+ /**
2019
+ * Resizes the attachments of a framebuffer.
2020
+ *
2021
+ * You need to pass in the same `attachments` as you passed in {@link createFramebufferInfo}
2022
+ * because TWGL has no idea the format/type of each attachment.
2023
+ *
2024
+ * The simplest usage
2025
+ *
2026
+ * // create an RGBA/UNSIGNED_BYTE texture and DEPTH_STENCIL renderbuffer
2027
+ * const fbi = twgl.createFramebufferInfo(gl);
2028
+ *
2029
+ * ...
2030
+ *
2031
+ * function render() {
2032
+ * if (twgl.resizeCanvasToDisplaySize(gl.canvas)) {
2033
+ * // resize the attachments
2034
+ * twgl.resizeFramebufferInfo(gl, fbi);
2035
+ * }
2036
+ *
2037
+ * More complex usage
2038
+ *
2039
+ * // create an RGB565 renderbuffer and a STENCIL_INDEX8 renderbuffer
2040
+ * const attachments = [
2041
+ * { format: RGB565, mag: NEAREST },
2042
+ * { format: STENCIL_INDEX8 },
2043
+ * ]
2044
+ * const fbi = twgl.createFramebufferInfo(gl, attachments);
2045
+ *
2046
+ * ...
2047
+ *
2048
+ * function render() {
2049
+ * if (twgl.resizeCanvasToDisplaySize(gl.canvas)) {
2050
+ * // resize the attachments to match
2051
+ * twgl.resizeFramebufferInfo(gl, fbi, attachments);
2052
+ * }
2053
+ *
2054
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2055
+ * @param {FramebufferInfo} framebufferInfo a framebufferInfo as returned from {@link createFramebufferInfo}.
2056
+ * @param {AttachmentOptions[]} [attachments] the same attachments options as passed to {@link createFramebufferInfo}.
2057
+ * @param {number} [width] the width for the attachments. Default = size of drawingBuffer
2058
+ * @param {number} [height] the height for the attachments. Default = size of drawingBuffer
2059
+ * @memberOf module:twgl/framebuffers
2060
+ */
268
2061
  export function resizeFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo: FramebufferInfo, attachments?: AttachmentOptions[], width?: number, height?: number): void;
2062
+ /**
2063
+ * Binds a framebuffer
2064
+ *
2065
+ * This function pretty much solely exists because I spent hours
2066
+ * trying to figure out why something I wrote wasn't working only
2067
+ * to realize I forget to set the viewport dimensions.
2068
+ * My hope is this function will fix that.
2069
+ *
2070
+ * It is effectively the same as
2071
+ *
2072
+ * gl.bindFramebuffer(gl.FRAMEBUFFER, someFramebufferInfo.framebuffer);
2073
+ * gl.viewport(0, 0, someFramebufferInfo.width, someFramebufferInfo.height);
2074
+ *
2075
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2076
+ * @param {FramebufferInfo|null} [framebufferInfo] a framebufferInfo as returned from {@link createFramebufferInfo}.
2077
+ * If falsy will bind the canvas.
2078
+ * @param {number} [target] The target. If not passed `gl.FRAMEBUFFER` will be used.
2079
+ * @memberOf module:twgl/framebuffers
2080
+ */
269
2081
  export function bindFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo?: FramebufferInfo | null, target?: number): void;
270
2082
 
271
2083
 
2084
+ /**
2085
+ * Program Callback
2086
+ * @callback ProgramCallback
2087
+ * @param {string} [err] error message, falsy if no error
2088
+ * @param {WebGLProgram|ProgramInfo} [result] the program or programInfo
2089
+ */
272
2090
  export type ProgramCallback = (err?: string, result?: WebGLProgram | ProgramInfo) => void;
2091
+ /**
2092
+ * Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
2093
+ * program.
2094
+ *
2095
+ * NOTE: There are 4 signatures for this function
2096
+ *
2097
+ * twgl.createProgram(gl, [vs, fs], options);
2098
+ * twgl.createProgram(gl, [vs, fs], opt_errFunc);
2099
+ * twgl.createProgram(gl, [vs, fs], opt_attribs, opt_errFunc);
2100
+ * twgl.createProgram(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
2101
+ *
2102
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
2103
+ * @param {WebGLShader[]|string[]} shaders The shaders to attach, or element ids for their source, or strings that contain their source
2104
+ * @param {ProgramOptions|string[]|ErrorCallback} [opt_attribs] Options for the program or an array of attribs names or an error callback. Locations will be assigned by index if not passed in
2105
+ * @param {number[]} [opt_locations|ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2106
+ * @param {ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
2107
+ * on error. If you want something else pass an callback. It's passed an error message.
2108
+ * @return {WebGLProgram?} the created program or null if error of a callback was provided.
2109
+ * @memberOf module:twgl/programs
2110
+ */
273
2111
  export function createProgram(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
2112
+ /**
2113
+ * Same as createProgram but returns a promise
2114
+ *
2115
+ * NOTE: There are 4 signatures for this function
2116
+ *
2117
+ * twgl.createProgramAsync(gl, [vs, fs], options);
2118
+ * twgl.createProgramAsync(gl, [vs, fs], opt_errFunc);
2119
+ * twgl.createProgramAsync(gl, [vs, fs], opt_attribs, opt_errFunc);
2120
+ * twgl.createProgramAsync(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
2121
+ *
2122
+ * @function
2123
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
2124
+ * @param {WebGLShader[]|string[]} shaders The shaders to attach, or element ids for their source, or strings that contain their source
2125
+ * @param {ProgramOptions|string[]|ErrorCallback} [opt_attribs] Options for the program or an array of attribs names or an error callback. Locations will be assigned by index if not passed in
2126
+ * @param {number[]} [opt_locations|ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2127
+ * @param {ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
2128
+ * on error. If you want something else pass an callback. It's passed an error message.
2129
+ * @return {Promise<WebGLProgram>} The created program
2130
+ * @memberOf module:twgl/programs
2131
+ */
274
2132
  export function createProgramAsync(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<WebGLProgram>;
2133
+ /**
2134
+ * Same as createProgramInfo but returns a promise
2135
+ * @function
2136
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
2137
+ * to use.
2138
+ * @param {string[]} shaderSources Array of sources for the
2139
+ * shaders or ids. The first is assumed to be the vertex shader,
2140
+ * the second the fragment shader.
2141
+ * @param {ProgramOptions|string[]|ErrorCallback} [opt_attribs] Options for the program or an array of attribs names or an error callback. Locations will be assigned by index if not passed in
2142
+ * @param {number[]} [opt_locations|ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2143
+ * @param {ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
2144
+ * on error. If you want something else pass an callback. It's passed an error message.
2145
+ * @return {Promise<ProgramInfo>} The created ProgramInfo
2146
+ * @memberOf module:twgl/programs
2147
+ */
275
2148
  export function createProgramInfoAsync(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<ProgramInfo>;
2149
+ /**
2150
+ * Creates a program from 2 script tags.
2151
+ *
2152
+ * NOTE: There are 4 signatures for this function
2153
+ *
2154
+ * twgl.createProgramFromScripts(gl, [vs, fs], opt_options);
2155
+ * twgl.createProgramFromScripts(gl, [vs, fs], opt_errFunc);
2156
+ * twgl.createProgramFromScripts(gl, [vs, fs], opt_attribs, opt_errFunc);
2157
+ * twgl.createProgramFromScripts(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
2158
+ *
2159
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
2160
+ * to use.
2161
+ * @param {string[]} shaderScriptIds Array of ids of the script
2162
+ * tags for the shaders. The first is assumed to be the
2163
+ * vertex shader, the second the fragment shader.
2164
+ * @param {ProgramOptions|string[]|ErrorCallback} [opt_attribs] Options for the program or an array of attribs names or an error callback. Locations will be assigned by index if not passed in
2165
+ * @param {number[]} [opt_locations|ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2166
+ * @param {ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
2167
+ * on error. If you want something else pass an callback. It's passed an error message.
2168
+ * @return {WebGLProgram?} the created program or null if error or a callback was provided.
2169
+ * @memberOf module:twgl/programs
2170
+ */
276
2171
  export function createProgramFromScripts(gl: WebGLRenderingContext, shaderScriptIds: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
2172
+ /**
2173
+ * Creates a program from 2 sources.
2174
+ *
2175
+ * NOTE: There are 4 signatures for this function
2176
+ *
2177
+ * twgl.createProgramFromSource(gl, [vs, fs], opt_options);
2178
+ * twgl.createProgramFromSource(gl, [vs, fs], opt_errFunc);
2179
+ * twgl.createProgramFromSource(gl, [vs, fs], opt_attribs, opt_errFunc);
2180
+ * twgl.createProgramFromSource(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
2181
+ *
2182
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
2183
+ * to use.
2184
+ * @param {string[]} shaderSources Array of sources for the
2185
+ * shaders. The first is assumed to be the vertex shader,
2186
+ * the second the fragment shader.
2187
+ * @param {ProgramOptions|string[]|ErrorCallback} [opt_attribs] Options for the program or an array of attribs names or an error callback. Locations will be assigned by index if not passed in
2188
+ * @param {number[]} [opt_locations|ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2189
+ * @param {ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
2190
+ * on error. If you want something else pass an callback. It's passed an error message.
2191
+ * @return {WebGLProgram?} the created program or null if error or a callback was provided.
2192
+ * @memberOf module:twgl/programs
2193
+ */
277
2194
  export function createProgramFromSources(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
2195
+ /**
2196
+ * Creates setter functions for all uniforms of a shader
2197
+ * program.
2198
+ *
2199
+ * @see {@link setUniforms}
2200
+ *
2201
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
2202
+ * @param {WebGLProgram} program the program to create setters for.
2203
+ * @returns {Object.<string, function>} an object with a setter by name for each uniform
2204
+ * @memberOf module:twgl/programs
2205
+ */
278
2206
  export function createUniformSetters(gl: WebGLRenderingContext, program: WebGLProgram): {
279
2207
  [key: string]: (...params: any[]) => any;
280
2208
  };
2209
+ /**
2210
+ * Creates a UniformBlockSpec for the given program.
2211
+ *
2212
+ * A UniformBlockSpec represents the data needed to create and bind
2213
+ * UniformBlockObjects
2214
+ *
2215
+ * @param {WebGL2RenderingContext} gl A WebGL2 Rendering Context
2216
+ * @param {WebGLProgram} program A WebGLProgram for a successfully linked program
2217
+ * @return {UniformBlockSpec} The created UniformBlockSpec
2218
+ * @memberOf module:twgl/programs
2219
+ */
281
2220
  export function createUniformBlockSpecFromProgram(gl: WebGL2RenderingContext, program: WebGLProgram): UniformBlockSpec;
2221
+ /**
2222
+ * Creates a `UniformBlockInfo` for the specified block
2223
+ *
2224
+ * Note: **If the blockName matches no existing blocks a warning is printed to the console and a dummy
2225
+ * `UniformBlockInfo` is returned**. This is because when debugging GLSL
2226
+ * it is common to comment out large portions of a shader or for example set
2227
+ * the final output to a constant. When that happens blocks get optimized out.
2228
+ * If this function did not create dummy blocks your code would crash when debugging.
2229
+ *
2230
+ * @param {WebGL2RenderingContext} gl A WebGL2RenderingContext
2231
+ * @param {WebGLProgram} program A WebGLProgram
2232
+ * @param {UniformBlockSpec} uniformBlockSpec. A UniformBlockSpec as returned
2233
+ * from {@link createUniformBlockSpecFromProgram}.
2234
+ * @param {string} blockName The name of the block.
2235
+ * @return {UniformBlockInfo} The created UniformBlockInfo
2236
+ * @memberOf module:twgl/programs
2237
+ */
282
2238
  export function createUniformBlockInfoFromProgram(gl: WebGL2RenderingContext, program: WebGLProgram, blockName: string): UniformBlockInfo;
2239
+ /**
2240
+ * Creates a `UniformBlockInfo` for the specified block
2241
+ *
2242
+ * Note: **If the blockName matches no existing blocks a warning is printed to the console and a dummy
2243
+ * `UniformBlockInfo` is returned**. This is because when debugging GLSL
2244
+ * it is common to comment out large portions of a shader or for example set
2245
+ * the final output to a constant. When that happens blocks get optimized out.
2246
+ * If this function did not create dummy blocks your code would crash when debugging.
2247
+ *
2248
+ * @param {WebGL2RenderingContext} gl A WebGL2RenderingContext
2249
+ * @param {ProgramInfo} programInfo a `ProgramInfo`
2250
+ * as returned from {@link createProgramInfo}
2251
+ * @param {string} blockName The name of the block.
2252
+ * @return {UniformBlockInfo} The created UniformBlockInfo
2253
+ * @memberOf module:twgl/programs
2254
+ */
283
2255
  export function createUniformBlockInfo(gl: WebGL2RenderingContext, programInfo: ProgramInfo, blockName: string): UniformBlockInfo;
2256
+ /**
2257
+ * Binds a uniform block to the matching uniform block point.
2258
+ * Matches by blocks by name so blocks must have the same name not just the same
2259
+ * structure.
2260
+ *
2261
+ * If you have changed any values and you upload the values into the corresponding WebGLBuffer
2262
+ * call {@link setUniformBlock} instead.
2263
+ *
2264
+ * @param {WebGL2RenderingContext} gl A WebGL 2 rendering context.
2265
+ * @param {(ProgramInfo|UniformBlockSpec)} programInfo a `ProgramInfo`
2266
+ * as returned from {@link createProgramInfo} or or `UniformBlockSpec` as
2267
+ * returned from {@link createUniformBlockSpecFromProgram}.
2268
+ * @param {UniformBlockInfo} uniformBlockInfo a `UniformBlockInfo` as returned from
2269
+ * {@link createUniformBlockInfo}.
2270
+ * @return {bool} true if buffer was bound. If the programInfo has no block with the same block name
2271
+ * no buffer is bound.
2272
+ * @memberOf module:twgl/programs
2273
+ */
284
2274
  export function bindUniformBlock(gl: WebGL2RenderingContext, programInfo: ProgramInfo | UniformBlockSpec, uniformBlockInfo: UniformBlockInfo): boolean;
2275
+ /**
2276
+ * Uploads the current uniform values to the corresponding WebGLBuffer
2277
+ * and binds that buffer to the program's corresponding bind point for the uniform block object.
2278
+ *
2279
+ * If you haven't changed any values and you only need to bind the uniform block object
2280
+ * call {@link bindUniformBlock} instead.
2281
+ *
2282
+ * @param {WebGL2RenderingContext} gl A WebGL 2 rendering context.
2283
+ * @param {(ProgramInfo|UniformBlockSpec)} programInfo a `ProgramInfo`
2284
+ * as returned from {@link createProgramInfo} or or `UniformBlockSpec` as
2285
+ * returned from {@link createUniformBlockSpecFromProgram}.
2286
+ * @param {UniformBlockInfo} uniformBlockInfo a `UniformBlockInfo` as returned from
2287
+ * {@link createUniformBlockInfo}.
2288
+ * @memberOf module:twgl/programs
2289
+ */
285
2290
  export function setUniformBlock(gl: WebGL2RenderingContext, programInfo: ProgramInfo | UniformBlockSpec, uniformBlockInfo: UniformBlockInfo): void;
2291
+ /**
2292
+ * Sets values of a uniform block object
2293
+ *
2294
+ * @param {UniformBlockInfo} uniformBlockInfo A UniformBlockInfo as returned by {@link createUniformBlockInfo}.
2295
+ * @param {Object.<string, ?>} values A uniform name to value map where the value is correct for the given
2296
+ * type of uniform. So for example given a block like
2297
+ *
2298
+ * uniform SomeBlock {
2299
+ * float someFloat;
2300
+ * vec2 someVec2;
2301
+ * vec3 someVec3Array[2];
2302
+ * int someInt;
2303
+ * }
2304
+ *
2305
+ * You can set the values of the uniform block with
2306
+ *
2307
+ * twgl.setBlockUniforms(someBlockInfo, {
2308
+ * someFloat: 12.3,
2309
+ * someVec2: [1, 2],
2310
+ * someVec3Array: [1, 2, 3, 4, 5, 6],
2311
+ * someInt: 5,
2312
+ * }
2313
+ *
2314
+ * Arrays can be JavaScript arrays or typed arrays
2315
+ *
2316
+ * You can also fill out structure and array values either via
2317
+ * shortcut. Example
2318
+ *
2319
+ * // -- in shader --
2320
+ * struct Light {
2321
+ * float intensity;
2322
+ * vec4 color;
2323
+ * float nearFar[2];
2324
+ * };
2325
+ * uniform Lights {
2326
+ * Light lights[2];
2327
+ * };
2328
+ *
2329
+ * // in JavaScript
2330
+ *
2331
+ * twgl.setBlockUniforms(someBlockInfo, {
2332
+ * lights: [
2333
+ * { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.1, 10] },
2334
+ * { intensity: 2.0, color: [0, 0, 1, 1], nearFar[0.2, 15] },
2335
+ * ],
2336
+ * });
2337
+ *
2338
+ * or the more traditional way
2339
+ *
2340
+ * twgl.setBlockUniforms(someBlockInfo, {
2341
+ * "lights[0].intensity": 5.0,
2342
+ * "lights[0].color": [1, 0, 0, 1],
2343
+ * "lights[0].nearFar": [0.1, 10],
2344
+ * "lights[1].intensity": 2.0,
2345
+ * "lights[1].color": [0, 0, 1, 1],
2346
+ * "lights[1].nearFar": [0.2, 15],
2347
+ * });
2348
+ *
2349
+ * You can also specify partial paths
2350
+ *
2351
+ * twgl.setBlockUniforms(someBlockInfo, {
2352
+ * 'lights[1]': { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.2, 15] },
2353
+ * });
2354
+ *
2355
+ * But you can not specify leaf array indices.
2356
+ *
2357
+ * twgl.setBlockUniforms(someBlockInfo, {
2358
+ * 'lights[1].nearFar[1]': 15, // BAD! nearFar is a leaf
2359
+ * 'lights[1].nearFar': [0.2, 15], // GOOD
2360
+ * });
2361
+ *
2362
+ * **IMPORTANT!**, packing in a UniformBlock is unintuitive.
2363
+ * For example the actual layout of `someVec3Array` above in memory
2364
+ * is `1, 2, 3, unused, 4, 5, 6, unused`. twgl takes in 6 values
2365
+ * as shown about and copies them, skipping the padding. This might
2366
+ * be confusing if you're already familiar with Uniform blocks.
2367
+ *
2368
+ * If you want to deal with the padding yourself you can access the array
2369
+ * buffer views directly. eg:
2370
+ *
2371
+ * someBlockInfo.someVec3Array.set([1, 2, 3, 0, 4, 5, 6, 0]);
2372
+ *
2373
+ * Any name that doesn't match will be ignored
2374
+ * @memberOf module:twgl/programs
2375
+ */
286
2376
  export function setBlockUniforms(uniformBlockInfo: UniformBlockInfo, values: {
287
2377
  [key: string]: any;
288
2378
  }): void;
2379
+ /**
2380
+ * Set uniforms and binds related textures.
2381
+ *
2382
+ * example:
2383
+ *
2384
+ * const programInfo = createProgramInfo(
2385
+ * gl, ["some-vs", "some-fs"]);
2386
+ *
2387
+ * const tex1 = gl.createTexture();
2388
+ * const tex2 = gl.createTexture();
2389
+ *
2390
+ * ... assume we setup the textures with data ...
2391
+ *
2392
+ * const uniforms = {
2393
+ * u_someSampler: tex1,
2394
+ * u_someOtherSampler: tex2,
2395
+ * u_someColor: [1,0,0,1],
2396
+ * u_somePosition: [0,1,1],
2397
+ * u_someMatrix: [
2398
+ * 1,0,0,0,
2399
+ * 0,1,0,0,
2400
+ * 0,0,1,0,
2401
+ * 0,0,0,0,
2402
+ * ],
2403
+ * };
2404
+ *
2405
+ * gl.useProgram(programInfo.program);
2406
+ *
2407
+ * This will automatically bind the textures AND set the
2408
+ * uniforms.
2409
+ *
2410
+ * twgl.setUniforms(programInfo, uniforms);
2411
+ *
2412
+ * For the example above it is equivalent to
2413
+ *
2414
+ * let texUnit = 0;
2415
+ * gl.activeTexture(gl.TEXTURE0 + texUnit);
2416
+ * gl.bindTexture(gl.TEXTURE_2D, tex1);
2417
+ * gl.uniform1i(u_someSamplerLocation, texUnit++);
2418
+ * gl.activeTexture(gl.TEXTURE0 + texUnit);
2419
+ * gl.bindTexture(gl.TEXTURE_2D, tex2);
2420
+ * gl.uniform1i(u_someSamplerLocation, texUnit++);
2421
+ * gl.uniform4fv(u_someColorLocation, [1, 0, 0, 1]);
2422
+ * gl.uniform3fv(u_somePositionLocation, [0, 1, 1]);
2423
+ * gl.uniformMatrix4fv(u_someMatrix, false, [
2424
+ * 1,0,0,0,
2425
+ * 0,1,0,0,
2426
+ * 0,0,1,0,
2427
+ * 0,0,0,0,
2428
+ * ]);
2429
+ *
2430
+ * Note it is perfectly reasonable to call `setUniforms` multiple times. For example
2431
+ *
2432
+ * const uniforms = {
2433
+ * u_someSampler: tex1,
2434
+ * u_someOtherSampler: tex2,
2435
+ * };
2436
+ *
2437
+ * const moreUniforms {
2438
+ * u_someColor: [1,0,0,1],
2439
+ * u_somePosition: [0,1,1],
2440
+ * u_someMatrix: [
2441
+ * 1,0,0,0,
2442
+ * 0,1,0,0,
2443
+ * 0,0,1,0,
2444
+ * 0,0,0,0,
2445
+ * ],
2446
+ * };
2447
+ *
2448
+ * twgl.setUniforms(programInfo, uniforms);
2449
+ * twgl.setUniforms(programInfo, moreUniforms);
2450
+ *
2451
+ * You can also add WebGLSamplers to uniform samplers as in
2452
+ *
2453
+ * const uniforms = {
2454
+ * u_someSampler: {
2455
+ * texture: someWebGLTexture,
2456
+ * sampler: someWebGLSampler,
2457
+ * },
2458
+ * };
2459
+ *
2460
+ * In which case both the sampler and texture will be bound to the
2461
+ * same unit.
2462
+ *
2463
+ * @param {(ProgramInfo|Object.<string, function>)} setters a `ProgramInfo` as returned from `createProgramInfo` or the setters returned from
2464
+ * `createUniformSetters`.
2465
+ * @param {Object.<string, ?>} values an object with values for the
2466
+ * uniforms.
2467
+ * You can pass multiple objects by putting them in an array or by calling with more arguments.For example
2468
+ *
2469
+ * const sharedUniforms = {
2470
+ * u_fogNear: 10,
2471
+ * u_projection: ...
2472
+ * ...
2473
+ * };
2474
+ *
2475
+ * const localUniforms = {
2476
+ * u_world: ...
2477
+ * u_diffuseColor: ...
2478
+ * };
2479
+ *
2480
+ * twgl.setUniforms(programInfo, sharedUniforms, localUniforms);
2481
+ *
2482
+ * // is the same as
2483
+ *
2484
+ * twgl.setUniforms(programInfo, [sharedUniforms, localUniforms]);
2485
+ *
2486
+ * // is the same as
2487
+ *
2488
+ * twgl.setUniforms(programInfo, sharedUniforms);
2489
+ * twgl.setUniforms(programInfo, localUniforms};
2490
+ *
2491
+ * You can also fill out structure and array values either via
2492
+ * shortcut. Example
2493
+ *
2494
+ * // -- in shader --
2495
+ * struct Light {
2496
+ * float intensity;
2497
+ * vec4 color;
2498
+ * float nearFar[2];
2499
+ * };
2500
+ * uniform Light lights[2];
2501
+ *
2502
+ * // in JavaScript
2503
+ *
2504
+ * twgl.setUniforms(programInfo, {
2505
+ * lights: [
2506
+ * { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.1, 10] },
2507
+ * { intensity: 2.0, color: [0, 0, 1, 1], nearFar[0.2, 15] },
2508
+ * ],
2509
+ * });
2510
+ *
2511
+ * or the more traditional way
2512
+ *
2513
+ * twgl.setUniforms(programInfo, {
2514
+ * "lights[0].intensity": 5.0,
2515
+ * "lights[0].color": [1, 0, 0, 1],
2516
+ * "lights[0].nearFar": [0.1, 10],
2517
+ * "lights[1].intensity": 2.0,
2518
+ * "lights[1].color": [0, 0, 1, 1],
2519
+ * "lights[1].nearFar": [0.2, 15],
2520
+ * });
2521
+ *
2522
+ * You can also specify partial paths
2523
+ *
2524
+ * twgl.setUniforms(programInfo, {
2525
+ * 'lights[1]': { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.2, 15] },
2526
+ * });
2527
+ *
2528
+ * But you can not specify leaf array indices
2529
+ *
2530
+ * twgl.setUniforms(programInfo, {
2531
+ * 'lights[1].nearFar[1]': 15, // BAD! nearFar is a leaf
2532
+ * 'lights[1].nearFar': [0.2, 15], // GOOD
2533
+ * });
2534
+ *
2535
+ * @memberOf module:twgl/programs
2536
+ */
289
2537
  export function setUniforms(setters: ProgramInfo | {
290
2538
  [key: string]: (...params: any[]) => any;
291
2539
  }, values: {
292
2540
  [key: string]: any;
293
2541
  }): void;
2542
+ /**
2543
+ * Alias for `setUniforms`
2544
+ * @function
2545
+ * @param {(ProgramInfo|Object.<string, function>)} setters a `ProgramInfo` as returned from `createProgramInfo` or the setters returned from
2546
+ * `createUniformSetters`.
2547
+ * @param {Object.<string, ?>} values an object with values for the
2548
+ * @memberOf module:twgl/programs
2549
+ */
294
2550
  export function setUniformsAndBindTextures(setters: ProgramInfo | {
295
2551
  [key: string]: (...params: any[]) => any;
296
2552
  }, values: {
297
2553
  [key: string]: any;
298
2554
  }): void;
2555
+ /**
2556
+ * Creates setter functions for all attributes of a shader
2557
+ * program. You can pass this to {@link setBuffersAndAttributes} to set all your buffers and attributes.
2558
+ *
2559
+ * @see {@link setAttributes} for example
2560
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
2561
+ * @param {WebGLProgram} program the program to create setters for.
2562
+ * @return {Object.<string, function>} an object with a setter for each attribute by name.
2563
+ * @memberOf module:twgl/programs
2564
+ */
299
2565
  export function createAttributeSetters(gl: WebGLRenderingContext, program: WebGLProgram): {
300
2566
  [key: string]: (...params: any[]) => any;
301
2567
  };
2568
+ /**
2569
+ * Sets attributes and buffers including the `ELEMENT_ARRAY_BUFFER` if appropriate
2570
+ *
2571
+ * Example:
2572
+ *
2573
+ * const programInfo = createProgramInfo(
2574
+ * gl, ["some-vs", "some-fs");
2575
+ *
2576
+ * const arrays = {
2577
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
2578
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
2579
+ * };
2580
+ *
2581
+ * const bufferInfo = createBufferInfoFromArrays(gl, arrays);
2582
+ *
2583
+ * gl.useProgram(programInfo.program);
2584
+ *
2585
+ * This will automatically bind the buffers AND set the
2586
+ * attributes.
2587
+ *
2588
+ * setBuffersAndAttributes(gl, programInfo, bufferInfo);
2589
+ *
2590
+ * For the example above it is equivalent to
2591
+ *
2592
+ * gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
2593
+ * gl.enableVertexAttribArray(a_positionLocation);
2594
+ * gl.vertexAttribPointer(a_positionLocation, 3, gl.FLOAT, false, 0, 0);
2595
+ * gl.bindBuffer(gl.ARRAY_BUFFER, texcoordBuffer);
2596
+ * gl.enableVertexAttribArray(a_texcoordLocation);
2597
+ * gl.vertexAttribPointer(a_texcoordLocation, 4, gl.FLOAT, false, 0, 0);
2598
+ *
2599
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext.
2600
+ * @param {(ProgramInfo|Object.<string, function>)} setters A `ProgramInfo` as returned from {@link createProgramInfo} or Attribute setters as returned from {@link createAttributeSetters}
2601
+ * @param {(BufferInfo|VertexArrayInfo)} buffers a `BufferInfo` as returned from {@link createBufferInfoFromArrays}.
2602
+ * or a `VertexArrayInfo` as returned from {@link createVertexArrayInfo}
2603
+ * @memberOf module:twgl/programs
2604
+ */
302
2605
  export function setBuffersAndAttributes(gl: WebGLRenderingContext, setters: ProgramInfo | {
303
2606
  [key: string]: (...params: any[]) => any;
304
2607
  }, buffers: BufferInfo | VertexArrayInfo): void;
2608
+ /**
2609
+ * Creates a ProgramInfo from an existing program.
2610
+ *
2611
+ * A ProgramInfo contains
2612
+ *
2613
+ * programInfo = {
2614
+ * program: WebGLProgram,
2615
+ * uniformSetters: object of setters as returned from createUniformSetters,
2616
+ * attribSetters: object of setters as returned from createAttribSetters,
2617
+ * }
2618
+ *
2619
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
2620
+ * to use.
2621
+ * @param {WebGLProgram} program an existing WebGLProgram.
2622
+ * @return {ProgramInfo} The created ProgramInfo.
2623
+ * @memberOf module:twgl/programs
2624
+ */
305
2625
  export function createProgramInfoFromProgram(gl: WebGLRenderingContext, program: WebGLProgram): ProgramInfo;
2626
+ /**
2627
+ * Creates a ProgramInfo from 2 sources.
2628
+ *
2629
+ * A ProgramInfo contains
2630
+ *
2631
+ * programInfo = {
2632
+ * program: WebGLProgram,
2633
+ * uniformSetters: object of setters as returned from createUniformSetters,
2634
+ * attribSetters: object of setters as returned from createAttribSetters,
2635
+ * }
2636
+ *
2637
+ * NOTE: There are 4 signatures for this function
2638
+ *
2639
+ * twgl.createProgramInfo(gl, [vs, fs], options);
2640
+ * twgl.createProgramInfo(gl, [vs, fs], opt_errFunc);
2641
+ * twgl.createProgramInfo(gl, [vs, fs], opt_attribs, opt_errFunc);
2642
+ * twgl.createProgramInfo(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
2643
+ *
2644
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
2645
+ * to use.
2646
+ * @param {string[]} shaderSources Array of sources for the
2647
+ * shaders or ids. The first is assumed to be the vertex shader,
2648
+ * the second the fragment shader.
2649
+ * @param {ProgramOptions|string[]|ErrorCallback} [opt_attribs] Options for the program or an array of attribs names or an error callback. Locations will be assigned by index if not passed in
2650
+ * @param {number[]} [opt_locations|ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2651
+ * @param {ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
2652
+ * on error. If you want something else pass an callback. It's passed an error message.
2653
+ * @return {ProgramInfo?} The created ProgramInfo or null if it failed to link or compile
2654
+ * @memberOf module:twgl/programs
2655
+ */
306
2656
  export function createProgramInfo(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): ProgramInfo;
2657
+ /**
2658
+ * Creates multiple programs
2659
+ *
2660
+ * Note: the reason this function exists is because the fastest way to create multiple
2661
+ * programs in WebGL is to create and compile all shaders and link all programs and only
2662
+ * afterwards check if they succeeded. In that way, giving all your shaders
2663
+ *
2664
+ * @see {@link createProgram}
2665
+ *
2666
+ * Example:
2667
+ *
2668
+ * const programs = twgl.createPrograms(gl, {
2669
+ * lambert: [lambertVS, lambertFS],
2670
+ * phong: [phongVS, phoneFS],
2671
+ * particles: {
2672
+ * shaders: [particlesVS, particlesFS],
2673
+ * transformFeedbackVaryings: ['position', 'velocity'],
2674
+ * },
2675
+ * });
2676
+ *
2677
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2678
+ * @param {Object.<string, ProgramSpec>} programSpecs An object of ProgramSpecs, one per program.
2679
+ * @param {ProgramOptions} [programOptions] options to apply to all programs
2680
+ * @return {Object.<string, WebGLProgram>?} the created programInfos by name
2681
+ */
307
2682
  export function createPrograms(gl: WebGLRenderingContext, programSpecs: {
308
2683
  [key: string]: ProgramSpec;
309
2684
  }, programOptions?: ProgramOptions): {
310
2685
  [key: string]: WebGLProgram;
311
2686
  };
2687
+ /**
2688
+ * Creates multiple programInfos
2689
+ *
2690
+ * Note: the reason this function exists is because the fastest way to create multiple
2691
+ * programs in WebGL is to create and compile all shaders and link all programs and only
2692
+ * afterwards check if they succeeded. In that way, giving all your shaders
2693
+ *
2694
+ * @see {@link createProgramInfo}
2695
+ *
2696
+ * Examples:
2697
+ *
2698
+ * const programInfos = twgl.createProgramInfos(gl, {
2699
+ * lambert: [lambertVS, lambertFS],
2700
+ * phong: [phongVS, phoneFS],
2701
+ * particles: {
2702
+ * shaders: [particlesVS, particlesFS],
2703
+ * transformFeedbackVaryings: ['position', 'velocity'],
2704
+ * },
2705
+ * });
2706
+ *
2707
+ * or
2708
+ *
2709
+ * const {lambert, phong, particles} = twgl.createProgramInfos(gl, {
2710
+ * lambert: [lambertVS, lambertFS],
2711
+ * phong: [phongVS, phoneFS],
2712
+ * particles: {
2713
+ * shaders: [particlesVS, particlesFS],
2714
+ * transformFeedbackVaryings: ['position', 'velocity'],
2715
+ * },
2716
+ * });
2717
+ *
2718
+ *
2719
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2720
+ * @param {Object.<string, ProgramSpec>} programSpecs An object of ProgramSpecs, one per program.
2721
+ * @param {ProgramOptions} [programOptions] options to apply to all programs
2722
+ * @return {Object.<string, ProgramInfo>?} the created programInfos by name
2723
+ */
312
2724
  export function createProgramInfos(gl: WebGLRenderingContext, programSpecs: {
313
2725
  [key: string]: ProgramSpec;
314
2726
  }, programOptions?: ProgramOptions): {
315
2727
  [key: string]: ProgramInfo;
316
2728
  };
2729
+ /**
2730
+ * Creates multiple programs asynchronously
2731
+ *
2732
+ * @see {@link createProgramAsync}
2733
+ *
2734
+ * Example:
2735
+ *
2736
+ * const programs = await twgl.createProgramsAsync(gl, {
2737
+ * lambert: [lambertVS, lambertFS],
2738
+ * phong: [phongVS, phoneFS],
2739
+ * particles: {
2740
+ * shaders: [particlesVS, particlesFS],
2741
+ * transformFeedbackVaryings: ['position', 'velocity'],
2742
+ * },
2743
+ * });
2744
+ *
2745
+ * @function
2746
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2747
+ * @param {Object.<string, ProgramSpec>} programSpecs An object of ProgramSpecs, one per program.
2748
+ * @param {ProgramOptions} [programOptions] options to apply to all programs
2749
+ * @return {Object.<string, WebGLProgram>?} the created programInfos by name
2750
+ */
317
2751
  export function createProgramsAsync(gl: WebGLRenderingContext, programSpecs: {
318
2752
  [key: string]: ProgramSpec;
319
2753
  }, programOptions?: ProgramOptions): {
320
2754
  [key: string]: WebGLProgram;
321
2755
  };
2756
+ /**
2757
+ * Creates multiple programInfos asynchronously
2758
+ *
2759
+ * @see {@link createProgramInfoAsync}
2760
+ *
2761
+ * Example:
2762
+ *
2763
+ * const programInfos = await twgl.createProgramInfosAsync(gl, {
2764
+ * lambert: [lambertVS, lambertFS],
2765
+ * phong: [phongVS, phoneFS],
2766
+ * particles: {
2767
+ * shaders: [particlesVS, particlesFS],
2768
+ * transformFeedbackVaryings: ['position', 'velocity'],
2769
+ * },
2770
+ * });
2771
+ *
2772
+ * @function
2773
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2774
+ * @param {Object.<string, ProgramSpec>} programSpecs An object of ProgramSpecs, one per program.
2775
+ * @param {ProgramOptions} [programOptions] options to apply to all programs
2776
+ * @return {Promise<Object.<string, ProgramInfo>>} the created programInfos by name
2777
+ */
322
2778
  export function createProgramInfosAsync(gl: WebGLRenderingContext, programSpecs: {
323
2779
  [key: string]: ProgramSpec;
324
2780
  }, programOptions?: ProgramOptions): Promise<{
@@ -326,25 +2782,260 @@ export function createProgramInfosAsync(gl: WebGLRenderingContext, programSpecs:
326
2782
  }>;
327
2783
 
328
2784
 
2785
+ /**
2786
+ * Gets the number of bytes per element for a given internalFormat / type
2787
+ * @param {number} internalFormat The internalFormat parameter from texImage2D etc..
2788
+ * @param {number} type The type parameter for texImage2D etc..
2789
+ * @return {number} the number of bytes per element for the given internalFormat, type combo
2790
+ * @memberOf module:twgl/textures
2791
+ */
329
2792
  export function getBytesPerElementForInternalFormat(internalFormat: number, type: number): number;
2793
+ /**
2794
+ * Info related to a specific texture internalFormat as returned
2795
+ * from {@link getFormatAndTypeForInternalFormat}.
2796
+ *
2797
+ * @typedef {Object} TextureFormatInfo
2798
+ * @property {number} format Format to pass to texImage2D and related functions
2799
+ * @property {number} type Type to pass to texImage2D and related functions
2800
+ * @memberOf module:twgl/textures
2801
+ */
330
2802
  export type TextureFormatInfo = {
331
2803
  format: number;
332
2804
  type: number;
333
2805
  };
2806
+ /**
2807
+ * Gets the format and type for a given internalFormat
2808
+ *
2809
+ * @param {number} internalFormat The internal format
2810
+ * @return {TextureFormatInfo} the corresponding format and type,
2811
+ * @memberOf module:twgl/textures
2812
+ */
334
2813
  export function getFormatAndTypeForInternalFormat(internalFormat: number): TextureFormatInfo;
2814
+ /**
2815
+ * Gets whether or not we can generate mips for the given
2816
+ * internal format.
2817
+ *
2818
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2819
+ * @param {number} width The width parameter from texImage2D etc..
2820
+ * @param {number} height The height parameter from texImage2D etc..
2821
+ * @param {number} internalFormat The internalFormat parameter from texImage2D etc..
2822
+ * @return {boolean} true if we can generate mips
2823
+ * @memberOf module:twgl/textures
2824
+ */
335
2825
  export function canGenerateMipmap(gl: WebGLRenderingContext, width: number, height: number, internalFormat: number): boolean;
2826
+ /**
2827
+ * Gets whether or not we can generate mips for the given format
2828
+ * @param {number} internalFormat The internalFormat parameter from texImage2D etc..
2829
+ * @return {boolean} true if we can generate mips
2830
+ * @memberOf module:twgl/textures
2831
+ */
336
2832
  export function canFilter(internalFormat: number): boolean;
2833
+ /**
2834
+ * Gets the number of components for a given image format.
2835
+ * @param {number} format the format.
2836
+ * @return {number} the number of components for the format.
2837
+ * @memberOf module:twgl/textures
2838
+ */
337
2839
  export function getNumComponentsForFormat(format: number): number;
2840
+ /**
2841
+ * Sets the default texture color.
2842
+ *
2843
+ * The default texture color is used when loading textures from
2844
+ * urls. Because the URL will be loaded async we'd like to be
2845
+ * able to use the texture immediately. By putting a 1x1 pixel
2846
+ * color in the texture we can start using the texture before
2847
+ * the URL has loaded.
2848
+ *
2849
+ * @param {number[]} color Array of 4 values in the range 0 to 1
2850
+ * @deprecated see {@link setDefaults}
2851
+ * @memberOf module:twgl/textures
2852
+ */
338
2853
  export function setDefaultTextureColor(color: number[]): void;
2854
+ /**
2855
+ * Sets the texture parameters of a texture.
2856
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2857
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
2858
+ * @param {TextureOptions} options A TextureOptions object with whatever parameters you want set.
2859
+ * This is often the same options you passed in when you created the texture.
2860
+ * @memberOf module:twgl/textures
2861
+ */
339
2862
  export function setTextureParameters(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions): void;
2863
+ /**
2864
+ * Sets the sampler parameters of a sampler.
2865
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2866
+ * @param {WebGLSampler} sampler the WebGLSampler to set parameters for
2867
+ * @param {TextureOptions} options A TextureOptions object with whatever parameters you want set.
2868
+ * @memberOf module:twgl/textures
2869
+ */
340
2870
  export function setSamplerParameters(gl: WebGLRenderingContext, sampler: WebGLSampler, options: TextureOptions): void;
2871
+ /**
2872
+ * Sets filtering or generates mips for texture based on width or height
2873
+ * If width or height is not passed in uses `options.width` and//or `options.height`
2874
+ *
2875
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2876
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
2877
+ * @param {TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
2878
+ * This is often the same options you passed in when you created the texture.
2879
+ * @param {number} [width] width of texture
2880
+ * @param {number} [height] height of texture
2881
+ * @param {number} [internalFormat] The internalFormat parameter from texImage2D etc..
2882
+ * @memberOf module:twgl/textures
2883
+ */
341
2884
  export function setTextureFilteringForSize(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions, width?: number, height?: number, internalFormat?: number): void;
2885
+ /**
2886
+ * Set a texture from the contents of an element. Will also set
2887
+ * texture filtering or generate mips based on the dimensions of the element
2888
+ * unless `options.auto === false`. If `target === gl.TEXTURE_CUBE_MAP` will
2889
+ * attempt to slice image into 1x6, 2x3, 3x2, or 6x1 images, one for each face.
2890
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2891
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
2892
+ * @param {HTMLElement} element a canvas, img, or video element.
2893
+ * @param {TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
2894
+ * This is often the same options you passed in when you created the texture.
2895
+ * @memberOf module:twgl/textures
2896
+ * @kind function
2897
+ */
342
2898
  export function setTextureFromElement(gl: WebGLRenderingContext, tex: WebGLTexture, element: HTMLElement, options?: TextureOptions): void;
2899
+ /**
2900
+ * Loads a texture from an image from a Url as specified in `options.src`
2901
+ * If `options.color !== false` will set the texture to a 1x1 pixel color so that the texture is
2902
+ * immediately useable. It will be updated with the contents of the image once the image has finished
2903
+ * downloading. Filtering options will be set as appropriate for image unless `options.auto === false`.
2904
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2905
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
2906
+ * @param {TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
2907
+ * @param {TextureReadyCallback} [callback] A function to be called when the image has finished loading. err will
2908
+ * be non null if there was an error.
2909
+ * @return {HTMLImageElement} the image being downloaded.
2910
+ * @memberOf module:twgl/textures
2911
+ */
343
2912
  export function loadTextureFromUrl(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions, callback?: TextureReadyCallback): HTMLImageElement;
2913
+ /**
2914
+ * Sets a texture from an array or typed array. If the width or height is not provided will attempt to
2915
+ * guess the size. See {@link TextureOptions}.
2916
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2917
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
2918
+ * @param {(number[]|ArrayBufferView)} src An array or typed arry with texture data.
2919
+ * @param {TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
2920
+ * This is often the same options you passed in when you created the texture.
2921
+ * @memberOf module:twgl/textures
2922
+ */
344
2923
  export function setTextureFromArray(gl: WebGLRenderingContext, tex: WebGLTexture, src: number[] | ArrayBufferView, options?: TextureOptions): void;
2924
+ /**
2925
+ * Sets a texture with no contents of a certain size. In other words calls `gl.texImage2D` with `null`.
2926
+ * You must set `options.width` and `options.height`.
2927
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2928
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
2929
+ * @param {TextureOptions} options A TextureOptions object with whatever parameters you want set.
2930
+ * @memberOf module:twgl/textures
2931
+ */
345
2932
  export function setEmptyTexture(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions): void;
2933
+ /**
2934
+ * Creates a texture based on the options passed in.
2935
+ *
2936
+ * Note: may reset UNPACK_ALIGNMENT, UNPACK_ROW_LENGTH, UNPACK_IMAGE_HEIGHT, UNPACK_SKIP_IMAGES
2937
+ * UNPACK_SKIP_PIXELS, and UNPACK_SKIP_ROWS
2938
+ *
2939
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2940
+ * @param {TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
2941
+ * @param {TextureReadyCallback} [callback] A callback called when an image has been downloaded and uploaded to the texture.
2942
+ * @return {WebGLTexture} the created texture.
2943
+ * @memberOf module:twgl/textures
2944
+ */
346
2945
  export function createTexture(gl: WebGLRenderingContext, options?: TextureOptions, callback?: TextureReadyCallback): WebGLTexture;
2946
+ /**
2947
+ * Resizes a texture based on the options passed in.
2948
+ *
2949
+ * Note: This is not a generic resize anything function.
2950
+ * It's mostly used by {@link resizeFramebufferInfo}
2951
+ * It will use `options.src` if it exists to try to determine a `type`
2952
+ * otherwise it will assume `gl.UNSIGNED_BYTE`. No data is provided
2953
+ * for the texture. Texture parameters will be set accordingly
2954
+ *
2955
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2956
+ * @param {WebGLTexture} tex the texture to resize
2957
+ * @param {TextureOptions} options A TextureOptions object with whatever parameters you want set.
2958
+ * @param {number} [width] the new width. If not passed in will use `options.width`
2959
+ * @param {number} [height] the new height. If not passed in will use `options.height`
2960
+ * @param {number} [depth] the new depth. If not passed in will use `options.depth`
2961
+ * @memberOf module:twgl/textures
2962
+ */
347
2963
  export function resizeTexture(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, width?: number, height?: number, depth?: number): void;
2964
+ /**
2965
+ * Creates a bunch of textures based on the passed in options.
2966
+ *
2967
+ * Example:
2968
+ *
2969
+ * const textures = twgl.createTextures(gl, {
2970
+ * // a power of 2 image
2971
+ * hftIcon: { src: "images/hft-icon-16.png", mag: gl.NEAREST },
2972
+ * // a non-power of 2 image
2973
+ * clover: { src: "images/clover.jpg" },
2974
+ * // From a canvas
2975
+ * fromCanvas: { src: ctx.canvas },
2976
+ * // A cubemap from 6 images
2977
+ * yokohama: {
2978
+ * target: gl.TEXTURE_CUBE_MAP,
2979
+ * src: [
2980
+ * 'images/yokohama/posx.jpg',
2981
+ * 'images/yokohama/negx.jpg',
2982
+ * 'images/yokohama/posy.jpg',
2983
+ * 'images/yokohama/negy.jpg',
2984
+ * 'images/yokohama/posz.jpg',
2985
+ * 'images/yokohama/negz.jpg',
2986
+ * ],
2987
+ * },
2988
+ * // A cubemap from 1 image (can be 1x6, 2x3, 3x2, 6x1)
2989
+ * goldengate: {
2990
+ * target: gl.TEXTURE_CUBE_MAP,
2991
+ * src: 'images/goldengate.jpg',
2992
+ * },
2993
+ * // A 2x2 pixel texture from a JavaScript array
2994
+ * checker: {
2995
+ * mag: gl.NEAREST,
2996
+ * min: gl.LINEAR,
2997
+ * src: [
2998
+ * 255,255,255,255,
2999
+ * 192,192,192,255,
3000
+ * 192,192,192,255,
3001
+ * 255,255,255,255,
3002
+ * ],
3003
+ * },
3004
+ * // a 1x2 pixel texture from a typed array.
3005
+ * stripe: {
3006
+ * mag: gl.NEAREST,
3007
+ * min: gl.LINEAR,
3008
+ * format: gl.LUMINANCE,
3009
+ * src: new Uint8Array([
3010
+ * 255,
3011
+ * 128,
3012
+ * 255,
3013
+ * 128,
3014
+ * 255,
3015
+ * 128,
3016
+ * 255,
3017
+ * 128,
3018
+ * ]),
3019
+ * width: 1,
3020
+ * },
3021
+ * });
3022
+ *
3023
+ * Now
3024
+ *
3025
+ * * `textures.hftIcon` will be a 2d texture
3026
+ * * `textures.clover` will be a 2d texture
3027
+ * * `textures.fromCanvas` will be a 2d texture
3028
+ * * `textures.yohohama` will be a cubemap texture
3029
+ * * `textures.goldengate` will be a cubemap texture
3030
+ * * `textures.checker` will be a 2d texture
3031
+ * * `textures.stripe` will be a 2d texture
3032
+ *
3033
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
3034
+ * @param {Object.<string,TextureOptions>} options A object of TextureOptions one per texture.
3035
+ * @param {TexturesReadyCallback} [callback] A callback called when all textures have been downloaded.
3036
+ * @return {Object.<string,WebGLTexture>} the created textures by name
3037
+ * @memberOf module:twgl/textures
3038
+ */
348
3039
  export function createTextures(gl: WebGLRenderingContext, options: {
349
3040
  [key: string]: TextureOptions;
350
3041
  }, callback?: TexturesReadyCallback): {
@@ -352,188 +3043,1424 @@ export function createTextures(gl: WebGLRenderingContext, options: {
352
3043
  };
353
3044
 
354
3045
 
3046
+ /**
3047
+ * Get the GL type for a typedArray
3048
+ * @param {ArrayBufferView} typedArray a typedArray
3049
+ * @return {number} the GL type for array. For example pass in an `Int8Array` and `gl.BYTE` will
3050
+ * be returned. Pass in a `Uint32Array` and `gl.UNSIGNED_INT` will be returned
3051
+ * @memberOf module:twgl/typedArray
3052
+ */
355
3053
  export function getGLTypeForTypedArray(typedArray: ArrayBufferView): number;
3054
+ /**
3055
+ * Get the GL type for a typedArray type
3056
+ * @param {ArrayBufferView} typedArrayType a typedArray constructor
3057
+ * @return {number} the GL type for type. For example pass in `Int8Array` and `gl.BYTE` will
3058
+ * be returned. Pass in `Uint32Array` and `gl.UNSIGNED_INT` will be returned
3059
+ * @memberOf module:twgl/typedArray
3060
+ */
356
3061
  export function getGLTypeForTypedArrayType(typedArrayType: ArrayBufferView): number;
3062
+ /**
3063
+ * Get the typed array constructor for a given GL type
3064
+ * @param {number} type the GL type. (eg: `gl.UNSIGNED_INT`)
3065
+ * @return {function} the constructor for a the corresponding typed array. (eg. `Uint32Array`).
3066
+ * @memberOf module:twgl/typedArray
3067
+ */
357
3068
  export function getTypedArrayTypeForGLType(type: number): (...params: any[]) => any;
358
3069
 
359
3070
 
3071
+ /**
3072
+ * Creates a VertexArrayInfo from a BufferInfo and one or more ProgramInfos
3073
+ *
3074
+ * This can be passed to {@link setBuffersAndAttributes} and to
3075
+ * {@link module:twgl:drawBufferInfo}.
3076
+ *
3077
+ * > **IMPORTANT:** Vertex Array Objects are **not** a direct analog for a BufferInfo. Vertex Array Objects
3078
+ * assign buffers to specific attributes at creation time. That means they can only be used with programs
3079
+ * who's attributes use the same attribute locations for the same purposes.
3080
+ *
3081
+ * > Bind your attribute locations by passing an array of attribute names to {@link createProgramInfo}
3082
+ * or use WebGL 2's GLSL ES 3's `layout(location = <num>)` to make sure locations match.
3083
+ *
3084
+ * also
3085
+ *
3086
+ * > **IMPORTANT:** After calling twgl.setBuffersAndAttribute with a BufferInfo that uses a Vertex Array Object
3087
+ * that Vertex Array Object will be bound. That means **ANY MANIPULATION OF ELEMENT_ARRAY_BUFFER or ATTRIBUTES**
3088
+ * will affect the Vertex Array Object state.
3089
+ *
3090
+ * > Call `gl.bindVertexArray(null)` to get back manipulating the global attributes and ELEMENT_ARRAY_BUFFER.
3091
+ *
3092
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
3093
+ * @param {ProgramInfo|ProgramInfo[]} programInfo a programInfo or array of programInfos
3094
+ * @param {BufferInfo} bufferInfo BufferInfo as returned from createBufferInfoFromArrays etc...
3095
+ *
3096
+ * You need to make sure every attribute that will be used is bound. So for example assume shader 1
3097
+ * uses attributes A, B, C and shader 2 uses attributes A, B, D. If you only pass in the programInfo
3098
+ * for shader 1 then only attributes A, B, and C will have their attributes set because TWGL doesn't
3099
+ * now attribute D's location.
3100
+ *
3101
+ * So, you can pass in both shader 1 and shader 2's programInfo
3102
+ *
3103
+ * @return {VertexArrayInfo} The created VertexArrayInfo
3104
+ *
3105
+ * @memberOf module:twgl/vertexArrays
3106
+ */
360
3107
  export function createVertexArrayInfo(gl: WebGLRenderingContext, programInfo: ProgramInfo | ProgramInfo[], bufferInfo: BufferInfo): VertexArrayInfo;
3108
+ /**
3109
+ * Creates a vertex array object and then sets the attributes on it
3110
+ *
3111
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
3112
+ * @param {Object.<string, function>} setters Attribute setters as returned from createAttributeSetters
3113
+ * @param {Object.<string, AttribInfo>} attribs AttribInfos mapped by attribute name.
3114
+ * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices
3115
+ *
3116
+ * @return {WebGLVertexArrayObject|null} The created WebGLVertexArrayObject
3117
+ *
3118
+ * @memberOf module:twgl/vertexArrays
3119
+ */
361
3120
  export function createVAOAndSetAttributes(gl: WebGLRenderingContext, setters: {
362
3121
  [key: string]: (...params: any[]) => any;
363
3122
  }, attribs: {
364
3123
  [key: string]: AttribInfo;
365
3124
  }, indices?: WebGLBuffer): WebGLVertexArrayObject | null;
3125
+ /**
3126
+ * Creates a vertex array object and then sets the attributes
3127
+ * on it
3128
+ *
3129
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
3130
+ * to use.
3131
+ * @param {Object.<string, function>| ProgramInfo} programInfo as returned from createProgramInfo or Attribute setters as returned from createAttributeSetters
3132
+ * @param {BufferInfo} bufferInfo BufferInfo as returned from createBufferInfoFromArrays etc...
3133
+ * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices
3134
+ *
3135
+ * @return {WebGLVertexArrayObject|null} The created WebGLVertexArrayObject
3136
+ *
3137
+ * @memberOf module:twgl/vertexArrays
3138
+ */
366
3139
  export function createVAOFromBufferInfo(gl: WebGLRenderingContext, programInfo: {
367
3140
  [key: string]: (...params: any[]) => any;
368
3141
  } | ProgramInfo, bufferInfo: BufferInfo, indices?: WebGLBuffer): WebGLVertexArrayObject | null;
369
3142
 
370
3143
  declare module v3 {
3144
+ /**
3145
+ * A JavaScript array with 3 values or a Float32Array with 3 values.
3146
+ * When created by the library will create the default type which is `Float32Array`
3147
+ * but can be set by calling {@link v3.setDefaultType}.
3148
+ * @typedef {(number[]|Float32Array)} Vec3
3149
+ * @memberOf module:twgl/v3
3150
+ */
371
3151
  export type Vec3 = number[] | Float32Array;
3152
+ /**
3153
+ * Sets the type this library creates for a Vec3
3154
+ * @param {constructor} ctor the constructor for the type. Either `Float32Array` or `Array`
3155
+ * @return {constructor} previous constructor for Vec3
3156
+ * @memberOf module:twgl/v3
3157
+ */
372
3158
  export function setDefaultType(ctor: Function): Function;
3159
+ /**
3160
+ * Creates a vec3; may be called with x, y, z to set initial values.
3161
+ * @param {number} [x] Initial x value.
3162
+ * @param {number} [y] Initial y value.
3163
+ * @param {number} [z] Initial z value.
3164
+ * @return {v3.Vec3} the created vector
3165
+ * @memberOf module:twgl/v3
3166
+ */
373
3167
  export function create(x?: number, y?: number, z?: number): v3.Vec3;
3168
+ /**
3169
+ * Adds two vectors; assumes a and b have the same dimension.
3170
+ * @param {v3.Vec3} a Operand vector.
3171
+ * @param {v3.Vec3} b Operand vector.
3172
+ * @param {v3.Vec3} [dst] vector to hold result. If not new one is created.
3173
+ * @return {v3.Vec3} A vector tha tis the sum of a and b.
3174
+ * @memberOf module:twgl/v3
3175
+ */
374
3176
  export function add(a: v3.Vec3, b: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
3177
+ /**
3178
+ * Subtracts two vectors.
3179
+ * @param {v3.Vec3} a Operand vector.
3180
+ * @param {v3.Vec3} b Operand vector.
3181
+ * @param {v3.Vec3} [dst] vector to hold result. If not new one is created.
3182
+ * @return {v3.Vec3} A vector that is the difference of a and b.
3183
+ * @memberOf module:twgl/v3
3184
+ */
375
3185
  export function subtract(a: v3.Vec3, b: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
3186
+ /**
3187
+ * Performs linear interpolation on two vectors.
3188
+ * Given vectors a and b and interpolation coefficient t, returns
3189
+ * a + t * (b - a).
3190
+ * @param {v3.Vec3} a Operand vector.
3191
+ * @param {v3.Vec3} b Operand vector.
3192
+ * @param {number} t Interpolation coefficient.
3193
+ * @param {v3.Vec3} [dst] vector to hold result. If not new one is created.
3194
+ * @return {v3.Vec3} The linear interpolated result.
3195
+ * @memberOf module:twgl/v3
3196
+ */
376
3197
  export function lerp(a: v3.Vec3, b: v3.Vec3, t: number, dst?: v3.Vec3): v3.Vec3;
3198
+ /**
3199
+ * Performs linear interpolation on two vectors.
3200
+ * Given vectors a and b and interpolation coefficient vector t, returns
3201
+ * a + t * (b - a).
3202
+ * @param {v3.Vec3} a Operand vector.
3203
+ * @param {v3.Vec3} b Operand vector.
3204
+ * @param {v3.Vec3} t Interpolation coefficients vector.
3205
+ * @param {v3.Vec3} [dst] vector to hold result. If not new one is created.
3206
+ * @return {v3.Vec3} the linear interpolated result.
3207
+ * @memberOf module:twgl/v3
3208
+ */
377
3209
  export function lerpV(a: v3.Vec3, b: v3.Vec3, t: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
3210
+ /**
3211
+ * Return max values of two vectors.
3212
+ * Given vectors a and b returns
3213
+ * [max(a[0], b[0]), max(a[1], b[1]), max(a[2], b[2])].
3214
+ * @param {v3.Vec3} a Operand vector.
3215
+ * @param {v3.Vec3} b Operand vector.
3216
+ * @param {v3.Vec3} [dst] vector to hold result. If not new one is created.
3217
+ * @return {v3.Vec3} The max components vector.
3218
+ * @memberOf module:twgl/v3
3219
+ */
378
3220
  export function max(a: v3.Vec3, b: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
3221
+ /**
3222
+ * Return min values of two vectors.
3223
+ * Given vectors a and b returns
3224
+ * [min(a[0], b[0]), min(a[1], b[1]), min(a[2], b[2])].
3225
+ * @param {v3.Vec3} a Operand vector.
3226
+ * @param {v3.Vec3} b Operand vector.
3227
+ * @param {v3.Vec3} [dst] vector to hold result. If not new one is created.
3228
+ * @return {v3.Vec3} The min components vector.
3229
+ * @memberOf module:twgl/v3
3230
+ */
379
3231
  export function min(a: v3.Vec3, b: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
3232
+ /**
3233
+ * Multiplies a vector by a scalar.
3234
+ * @param {v3.Vec3} v The vector.
3235
+ * @param {number} k The scalar.
3236
+ * @param {v3.Vec3} [dst] vector to hold result. If not new one is created.
3237
+ * @return {v3.Vec3} The scaled vector.
3238
+ * @memberOf module:twgl/v3
3239
+ */
380
3240
  export function mulScalar(v: v3.Vec3, k: number, dst?: v3.Vec3): v3.Vec3;
3241
+ /**
3242
+ * Divides a vector by a scalar.
3243
+ * @param {v3.Vec3} v The vector.
3244
+ * @param {number} k The scalar.
3245
+ * @param {v3.Vec3} [dst] vector to hold result. If not new one is created.
3246
+ * @return {v3.Vec3} The scaled vector.
3247
+ * @memberOf module:twgl/v3
3248
+ */
381
3249
  export function divScalar(v: v3.Vec3, k: number, dst?: v3.Vec3): v3.Vec3;
3250
+ /**
3251
+ * Computes the cross product of two vectors; assumes both vectors have
3252
+ * three entries.
3253
+ * @param {v3.Vec3} a Operand vector.
3254
+ * @param {v3.Vec3} b Operand vector.
3255
+ * @param {v3.Vec3} [dst] vector to hold result. If not new one is created.
3256
+ * @return {v3.Vec3} The vector of a cross b.
3257
+ * @memberOf module:twgl/v3
3258
+ */
382
3259
  export function cross(a: v3.Vec3, b: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
3260
+ /**
3261
+ * Computes the dot product of two vectors; assumes both vectors have
3262
+ * three entries.
3263
+ * @param {v3.Vec3} a Operand vector.
3264
+ * @param {v3.Vec3} b Operand vector.
3265
+ * @return {number} dot product
3266
+ * @memberOf module:twgl/v3
3267
+ */
383
3268
  export function dot(a: v3.Vec3, b: v3.Vec3): number;
3269
+ /**
3270
+ * Computes the length of vector
3271
+ * @param {v3.Vec3} v vector.
3272
+ * @return {number} length of vector.
3273
+ * @memberOf module:twgl/v3
3274
+ */
384
3275
  export function length(v: v3.Vec3): number;
3276
+ /**
3277
+ * Computes the square of the length of vector
3278
+ * @param {v3.Vec3} v vector.
3279
+ * @return {number} square of the length of vector.
3280
+ * @memberOf module:twgl/v3
3281
+ */
385
3282
  export function lengthSq(v: v3.Vec3): number;
3283
+ /**
3284
+ * Computes the distance between 2 points
3285
+ * @param {v3.Vec3} a vector.
3286
+ * @param {v3.Vec3} b vector.
3287
+ * @return {number} distance between a and b
3288
+ * @memberOf module:twgl/v3
3289
+ */
386
3290
  export function distance(a: v3.Vec3, b: v3.Vec3): number;
3291
+ /**
3292
+ * Computes the square of the distance between 2 points
3293
+ * @param {v3.Vec3} a vector.
3294
+ * @param {v3.Vec3} b vector.
3295
+ * @return {number} square of the distance between a and b
3296
+ * @memberOf module:twgl/v3
3297
+ */
387
3298
  export function distanceSq(a: v3.Vec3, b: v3.Vec3): number;
3299
+ /**
3300
+ * Divides a vector by its Euclidean length and returns the quotient.
3301
+ * @param {v3.Vec3} a The vector.
3302
+ * @param {v3.Vec3} [dst] vector to hold result. If not new one is created.
3303
+ * @return {v3.Vec3} The normalized vector.
3304
+ * @memberOf module:twgl/v3
3305
+ */
388
3306
  export function normalize(a: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
3307
+ /**
3308
+ * Negates a vector.
3309
+ * @param {v3.Vec3} v The vector.
3310
+ * @param {v3.Vec3} [dst] vector to hold result. If not new one is created.
3311
+ * @return {v3.Vec3} -v.
3312
+ * @memberOf module:twgl/v3
3313
+ */
389
3314
  export function negate(v: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
3315
+ /**
3316
+ * Copies a vector.
3317
+ * @param {v3.Vec3} v The vector.
3318
+ * @param {v3.Vec3} [dst] vector to hold result. If not new one is created.
3319
+ * @return {v3.Vec3} A copy of v.
3320
+ * @memberOf module:twgl/v3
3321
+ */
390
3322
  export function copy(v: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
3323
+ /**
3324
+ * Multiplies a vector by another vector (component-wise); assumes a and
3325
+ * b have the same length.
3326
+ * @param {v3.Vec3} a Operand vector.
3327
+ * @param {v3.Vec3} b Operand vector.
3328
+ * @param {v3.Vec3} [dst] vector to hold result. If not new one is created.
3329
+ * @return {v3.Vec3} The vector of products of entries of a and
3330
+ * b.
3331
+ * @memberOf module:twgl/v3
3332
+ */
391
3333
  export function multiply(a: v3.Vec3, b: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
3334
+ /**
3335
+ * Divides a vector by another vector (component-wise); assumes a and
3336
+ * b have the same length.
3337
+ * @param {v3.Vec3} a Operand vector.
3338
+ * @param {v3.Vec3} b Operand vector.
3339
+ * @param {v3.Vec3} [dst] vector to hold result. If not new one is created.
3340
+ * @return {v3.Vec3} The vector of quotients of entries of a and
3341
+ * b.
3342
+ * @memberOf module:twgl/v3
3343
+ */
392
3344
  export function divide(a: v3.Vec3, b: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
393
3345
  }
394
3346
  declare module m4 {
3347
+ /**
3348
+ * A JavaScript array with 16 values or a Float32Array with 16 values.
3349
+ * When created by the library will create the default type which is `Float32Array`
3350
+ * but can be set by calling {@link m4.setDefaultType}.
3351
+ * @typedef {(number[]|Float32Array)} Mat4
3352
+ * @memberOf module:twgl/m4
3353
+ */
395
3354
  export type Mat4 = number[] | Float32Array;
3355
+ /**
3356
+ * Sets the type this library creates for a Mat4
3357
+ * @param {constructor} ctor the constructor for the type. Either `Float32Array` or `Array`
3358
+ * @return {constructor} previous constructor for Mat4
3359
+ * @memberOf module:twgl/m4
3360
+ */
396
3361
  export function setDefaultType(ctor: Function): Function;
3362
+ /**
3363
+ * Negates a matrix.
3364
+ * @param {m4.Mat4} m The matrix.
3365
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3366
+ * @return {m4.Mat4} -m.
3367
+ * @memberOf module:twgl/m4
3368
+ */
397
3369
  export function negate(m: m4.Mat4, dst?: m4.Mat4): m4.Mat4;
3370
+ /**
3371
+ * Creates a matrix.
3372
+ * @return {m4.Mat4} A new matrix.
3373
+ * @memberOf module:twgl/m4
3374
+ */
398
3375
  export function create(): m4.Mat4;
3376
+ /**
3377
+ * Copies a matrix.
3378
+ * @param {m4.Mat4} m The matrix.
3379
+ * @param {m4.Mat4} [dst] The matrix. If not passed a new one is created.
3380
+ * @return {m4.Mat4} A copy of m.
3381
+ * @memberOf module:twgl/m4
3382
+ */
399
3383
  export function copy(m: m4.Mat4, dst?: m4.Mat4): m4.Mat4;
3384
+ /**
3385
+ * Creates an n-by-n identity matrix.
3386
+ *
3387
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3388
+ * @return {m4.Mat4} An n-by-n identity matrix.
3389
+ * @memberOf module:twgl/m4
3390
+ */
400
3391
  export function identity(dst?: m4.Mat4): m4.Mat4;
3392
+ /**
3393
+ * Takes the transpose of a matrix.
3394
+ * @param {m4.Mat4} m The matrix.
3395
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3396
+ * @return {m4.Mat4} The transpose of m.
3397
+ * @memberOf module:twgl/m4
3398
+ */
401
3399
  export function transpose(m: m4.Mat4, dst?: m4.Mat4): m4.Mat4;
3400
+ /**
3401
+ * Computes the inverse of a 4-by-4 matrix.
3402
+ * @param {m4.Mat4} m The matrix.
3403
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3404
+ * @return {m4.Mat4} The inverse of m.
3405
+ * @memberOf module:twgl/m4
3406
+ */
402
3407
  export function inverse(m: m4.Mat4, dst?: m4.Mat4): m4.Mat4;
3408
+ /**
3409
+ * Multiplies two 4-by-4 matrices with a on the left and b on the right
3410
+ * @param {m4.Mat4} a The matrix on the left.
3411
+ * @param {m4.Mat4} b The matrix on the right.
3412
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3413
+ * @return {m4.Mat4} The matrix product of a and b.
3414
+ * @memberOf module:twgl/m4
3415
+ */
403
3416
  export function multiply(a: m4.Mat4, b: m4.Mat4, dst?: m4.Mat4): m4.Mat4;
3417
+ /**
3418
+ * Sets the translation component of a 4-by-4 matrix to the given
3419
+ * vector.
3420
+ * @param {m4.Mat4} a The matrix.
3421
+ * @param {v3.Vec3} v The vector.
3422
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3423
+ * @return {m4.Mat4} The matrix with translation set.
3424
+ * @memberOf module:twgl/m4
3425
+ */
404
3426
  export function setTranslation(a: m4.Mat4, v: v3.Vec3, dst?: m4.Mat4): m4.Mat4;
3427
+ /**
3428
+ * Returns the translation component of a 4-by-4 matrix as a vector with 3
3429
+ * entries.
3430
+ * @param {m4.Mat4} m The matrix.
3431
+ * @param {v3.Vec3} [dst] vector to hold result. If not passed a new one is created.
3432
+ * @return {v3.Vec3} The translation component of m.
3433
+ * @memberOf module:twgl/m4
3434
+ */
405
3435
  export function getTranslation(m: m4.Mat4, dst?: v3.Vec3): v3.Vec3;
3436
+ /**
3437
+ * Returns an axis of a 4x4 matrix as a vector with 3 entries
3438
+ * @param {m4.Mat4} m The matrix.
3439
+ * @param {number} axis The axis 0 = x, 1 = y, 2 = z;
3440
+ * @return {v3.Vec3} [dst] vector.
3441
+ * @return {v3.Vec3} The axis component of m.
3442
+ * @memberOf module:twgl/m4
3443
+ */
406
3444
  export function getAxis(m: m4.Mat4, axis: number): void;
3445
+ /**
3446
+ * Sets an axis of a 4x4 matrix as a vector with 3 entries
3447
+ * @param {m4.Mat4} m The matrix.
3448
+ * @param {v3.Vec3} v the axis vector
3449
+ * @param {number} axis The axis 0 = x, 1 = y, 2 = z;
3450
+ * @param {m4.Mat4} [dst] The matrix to set. If not passed a new one is created.
3451
+ * @return {m4.Mat4} The matrix with axis set.
3452
+ * @memberOf module:twgl/m4
3453
+ */
407
3454
  export function setAxis(m: m4.Mat4, v: v3.Vec3, axis: number, dst?: m4.Mat4): m4.Mat4;
3455
+ /**
3456
+ * Computes a 4-by-4 perspective transformation matrix given the angular height
3457
+ * of the frustum, the aspect ratio, and the near and far clipping planes. The
3458
+ * arguments define a frustum extending in the negative z direction. The given
3459
+ * angle is the vertical angle of the frustum, and the horizontal angle is
3460
+ * determined to produce the given aspect ratio. The arguments near and far are
3461
+ * the distances to the near and far clipping planes. Note that near and far
3462
+ * are not z coordinates, but rather they are distances along the negative
3463
+ * z-axis. The matrix generated sends the viewing frustum to the unit box.
3464
+ * We assume a unit box extending from -1 to 1 in the x and y dimensions and
3465
+ * from 0 to 1 in the z dimension.
3466
+ * @param {number} fieldOfViewYInRadians The camera angle from top to bottom (in radians).
3467
+ * @param {number} aspect The aspect ratio width / height.
3468
+ * @param {number} zNear The depth (negative z coordinate)
3469
+ * of the near clipping plane.
3470
+ * @param {number} zFar The depth (negative z coordinate)
3471
+ * of the far clipping plane.
3472
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3473
+ * @return {m4.Mat4} The perspective matrix.
3474
+ * @memberOf module:twgl/m4
3475
+ */
408
3476
  export function perspective(fieldOfViewYInRadians: number, aspect: number, zNear: number, zFar: number, dst?: m4.Mat4): m4.Mat4;
3477
+ /**
3478
+ * Computes a 4-by-4 orthogonal transformation matrix given the left, right,
3479
+ * bottom, and top dimensions of the near clipping plane as well as the
3480
+ * near and far clipping plane distances.
3481
+ * @param {number} left Left side of the near clipping plane viewport.
3482
+ * @param {number} right Right side of the near clipping plane viewport.
3483
+ * @param {number} bottom Bottom of the near clipping plane viewport.
3484
+ * @param {number} top Top of the near clipping plane viewport.
3485
+ * @param {number} near The depth (negative z coordinate)
3486
+ * of the near clipping plane.
3487
+ * @param {number} far The depth (negative z coordinate)
3488
+ * of the far clipping plane.
3489
+ * @param {m4.Mat4} [dst] Output matrix. If not passed a new one is created.
3490
+ * @return {m4.Mat4} The perspective matrix.
3491
+ * @memberOf module:twgl/m4
3492
+ */
409
3493
  export function ortho(left: number, right: number, bottom: number, top: number, near: number, far: number, dst?: m4.Mat4): m4.Mat4;
3494
+ /**
3495
+ * Computes a 4-by-4 perspective transformation matrix given the left, right,
3496
+ * top, bottom, near and far clipping planes. The arguments define a frustum
3497
+ * extending in the negative z direction. The arguments near and far are the
3498
+ * distances to the near and far clipping planes. Note that near and far are not
3499
+ * z coordinates, but rather they are distances along the negative z-axis. The
3500
+ * matrix generated sends the viewing frustum to the unit box. We assume a unit
3501
+ * box extending from -1 to 1 in the x and y dimensions and from 0 to 1 in the z
3502
+ * dimension.
3503
+ * @param {number} left The x coordinate of the left plane of the box.
3504
+ * @param {number} right The x coordinate of the right plane of the box.
3505
+ * @param {number} bottom The y coordinate of the bottom plane of the box.
3506
+ * @param {number} top The y coordinate of the right plane of the box.
3507
+ * @param {number} near The negative z coordinate of the near plane of the box.
3508
+ * @param {number} far The negative z coordinate of the far plane of the box.
3509
+ * @param {m4.Mat4} [dst] Output matrix. If not passed a new one is created.
3510
+ * @return {m4.Mat4} The perspective projection matrix.
3511
+ * @memberOf module:twgl/m4
3512
+ */
410
3513
  export function frustum(left: number, right: number, bottom: number, top: number, near: number, far: number, dst?: m4.Mat4): m4.Mat4;
3514
+ /**
3515
+ * Computes a 4-by-4 look-at transformation.
3516
+ *
3517
+ * This is a matrix which positions the camera itself. If you want
3518
+ * a view matrix (a matrix which moves things in front of the camera)
3519
+ * take the inverse of this.
3520
+ *
3521
+ * @param {v3.Vec3} eye The position of the eye.
3522
+ * @param {v3.Vec3} target The position meant to be viewed.
3523
+ * @param {v3.Vec3} up A vector pointing up.
3524
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3525
+ * @return {m4.Mat4} The look-at matrix.
3526
+ * @memberOf module:twgl/m4
3527
+ */
411
3528
  export function lookAt(eye: v3.Vec3, target: v3.Vec3, up: v3.Vec3, dst?: m4.Mat4): m4.Mat4;
3529
+ /**
3530
+ * Creates a 4-by-4 matrix which translates by the given vector v.
3531
+ * @param {v3.Vec3} v The vector by
3532
+ * which to translate.
3533
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3534
+ * @return {m4.Mat4} The translation matrix.
3535
+ * @memberOf module:twgl/m4
3536
+ */
412
3537
  export function translation(v: v3.Vec3, dst?: m4.Mat4): m4.Mat4;
3538
+ /**
3539
+ * Translates the given 4-by-4 matrix by the given vector v.
3540
+ * @param {m4.Mat4} m The matrix.
3541
+ * @param {v3.Vec3} v The vector by
3542
+ * which to translate.
3543
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3544
+ * @return {m4.Mat4} The translated matrix.
3545
+ * @memberOf module:twgl/m4
3546
+ */
413
3547
  export function translate(m: m4.Mat4, v: v3.Vec3, dst?: m4.Mat4): m4.Mat4;
3548
+ /**
3549
+ * Creates a 4-by-4 matrix which rotates around the x-axis by the given angle.
3550
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
3551
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3552
+ * @return {m4.Mat4} The rotation matrix.
3553
+ * @memberOf module:twgl/m4
3554
+ */
414
3555
  export function rotationX(angleInRadians: number, dst?: m4.Mat4): m4.Mat4;
3556
+ /**
3557
+ * Rotates the given 4-by-4 matrix around the x-axis by the given
3558
+ * angle.
3559
+ * @param {m4.Mat4} m The matrix.
3560
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
3561
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3562
+ * @return {m4.Mat4} The rotated matrix.
3563
+ * @memberOf module:twgl/m4
3564
+ */
415
3565
  export function rotateX(m: m4.Mat4, angleInRadians: number, dst?: m4.Mat4): m4.Mat4;
3566
+ /**
3567
+ * Creates a 4-by-4 matrix which rotates around the y-axis by the given angle.
3568
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
3569
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3570
+ * @return {m4.Mat4} The rotation matrix.
3571
+ * @memberOf module:twgl/m4
3572
+ */
416
3573
  export function rotationY(angleInRadians: number, dst?: m4.Mat4): m4.Mat4;
3574
+ /**
3575
+ * Rotates the given 4-by-4 matrix around the y-axis by the given
3576
+ * angle.
3577
+ * @param {m4.Mat4} m The matrix.
3578
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
3579
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3580
+ * @return {m4.Mat4} The rotated matrix.
3581
+ * @memberOf module:twgl/m4
3582
+ */
417
3583
  export function rotateY(m: m4.Mat4, angleInRadians: number, dst?: m4.Mat4): m4.Mat4;
3584
+ /**
3585
+ * Creates a 4-by-4 matrix which rotates around the z-axis by the given angle.
3586
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
3587
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3588
+ * @return {m4.Mat4} The rotation matrix.
3589
+ * @memberOf module:twgl/m4
3590
+ */
418
3591
  export function rotationZ(angleInRadians: number, dst?: m4.Mat4): m4.Mat4;
3592
+ /**
3593
+ * Rotates the given 4-by-4 matrix around the z-axis by the given
3594
+ * angle.
3595
+ * @param {m4.Mat4} m The matrix.
3596
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
3597
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3598
+ * @return {m4.Mat4} The rotated matrix.
3599
+ * @memberOf module:twgl/m4
3600
+ */
419
3601
  export function rotateZ(m: m4.Mat4, angleInRadians: number, dst?: m4.Mat4): m4.Mat4;
3602
+ /**
3603
+ * Creates a 4-by-4 matrix which rotates around the given axis by the given
3604
+ * angle.
3605
+ * @param {v3.Vec3} axis The axis
3606
+ * about which to rotate.
3607
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
3608
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3609
+ * @return {m4.Mat4} A matrix which rotates angle radians
3610
+ * around the axis.
3611
+ * @memberOf module:twgl/m4
3612
+ */
420
3613
  export function axisRotation(axis: v3.Vec3, angleInRadians: number, dst?: m4.Mat4): m4.Mat4;
3614
+ /**
3615
+ * Rotates the given 4-by-4 matrix around the given axis by the
3616
+ * given angle.
3617
+ * @param {m4.Mat4} m The matrix.
3618
+ * @param {v3.Vec3} axis The axis
3619
+ * about which to rotate.
3620
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
3621
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3622
+ * @return {m4.Mat4} The rotated matrix.
3623
+ * @memberOf module:twgl/m4
3624
+ */
421
3625
  export function axisRotate(m: m4.Mat4, axis: v3.Vec3, angleInRadians: number, dst?: m4.Mat4): m4.Mat4;
3626
+ /**
3627
+ * Creates a 4-by-4 matrix which scales in each dimension by an amount given by
3628
+ * the corresponding entry in the given vector; assumes the vector has three
3629
+ * entries.
3630
+ * @param {v3.Vec3} v A vector of
3631
+ * three entries specifying the factor by which to scale in each dimension.
3632
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3633
+ * @return {m4.Mat4} The scaling matrix.
3634
+ * @memberOf module:twgl/m4
3635
+ */
422
3636
  export function scaling(v: v3.Vec3, dst?: m4.Mat4): m4.Mat4;
3637
+ /**
3638
+ * Scales the given 4-by-4 matrix in each dimension by an amount
3639
+ * given by the corresponding entry in the given vector; assumes the vector has
3640
+ * three entries.
3641
+ * @param {m4.Mat4} m The matrix to be modified.
3642
+ * @param {v3.Vec3} v A vector of three entries specifying the
3643
+ * factor by which to scale in each dimension.
3644
+ * @param {m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
3645
+ * @return {m4.Mat4} The scaled matrix.
3646
+ * @memberOf module:twgl/m4
3647
+ */
423
3648
  export function scale(m: m4.Mat4, v: v3.Vec3, dst?: m4.Mat4): m4.Mat4;
3649
+ /**
3650
+ * Takes a 4-by-4 matrix and a vector with 3 entries,
3651
+ * interprets the vector as a point, transforms that point by the matrix, and
3652
+ * returns the result as a vector with 3 entries.
3653
+ * @param {m4.Mat4} m The matrix.
3654
+ * @param {v3.Vec3} v The point.
3655
+ * @param {v3.Vec3} [dst] optional vec3 to store result. If not passed a new one is created.
3656
+ * @return {v3.Vec3} The transformed point.
3657
+ * @memberOf module:twgl/m4
3658
+ */
424
3659
  export function transformPoint(m: m4.Mat4, v: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
3660
+ /**
3661
+ * Takes a 4-by-4 matrix and a vector with 3 entries, interprets the vector as a
3662
+ * direction, transforms that direction by the matrix, and returns the result;
3663
+ * assumes the transformation of 3-dimensional space represented by the matrix
3664
+ * is parallel-preserving, i.e. any combination of rotation, scaling and
3665
+ * translation, but not a perspective distortion. Returns a vector with 3
3666
+ * entries.
3667
+ * @param {m4.Mat4} m The matrix.
3668
+ * @param {v3.Vec3} v The direction.
3669
+ * @param {v3.Vec3} [dst] optional Vec3 to store result. If not passed a new one is created.
3670
+ * @return {v3.Vec3} The transformed direction.
3671
+ * @memberOf module:twgl/m4
3672
+ */
425
3673
  export function transformDirection(m: m4.Mat4, v: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
3674
+ /**
3675
+ * Takes a 4-by-4 matrix m and a vector v with 3 entries, interprets the vector
3676
+ * as a normal to a surface, and computes a vector which is normal upon
3677
+ * transforming that surface by the matrix. The effect of this function is the
3678
+ * same as transforming v (as a direction) by the inverse-transpose of m. This
3679
+ * function assumes the transformation of 3-dimensional space represented by the
3680
+ * matrix is parallel-preserving, i.e. any combination of rotation, scaling and
3681
+ * translation, but not a perspective distortion. Returns a vector with 3
3682
+ * entries.
3683
+ * @param {m4.Mat4} m The matrix.
3684
+ * @param {v3.Vec3} v The normal.
3685
+ * @param {v3.Vec3} [dst] The direction. If not passed a new one is created.
3686
+ * @return {v3.Vec3} The transformed normal.
3687
+ * @memberOf module:twgl/m4
3688
+ */
426
3689
  export function transformNormal(m: m4.Mat4, v: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
427
3690
  }
428
3691
  declare module primitives {
3692
+ /**
3693
+ * @typedef {(Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array)} TypedArray
3694
+ */
429
3695
  export type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array;
3696
+ /**
3697
+ * creates a typed array with a `push` function attached
3698
+ * so that you can easily *push* values.
3699
+ *
3700
+ * `push` can take multiple arguments. If an argument is an array each element
3701
+ * of the array will be added to the typed array.
3702
+ *
3703
+ * Example:
3704
+ *
3705
+ * const array = createAugmentedTypedArray(3, 2); // creates a Float32Array with 6 values
3706
+ * array.push(1, 2, 3);
3707
+ * array.push([4, 5, 6]);
3708
+ * // array now contains [1, 2, 3, 4, 5, 6]
3709
+ *
3710
+ * Also has `numComponents` and `numElements` properties.
3711
+ *
3712
+ * @param {number} numComponents number of components
3713
+ * @param {number} numElements number of elements. The total size of the array will be `numComponents * numElements`.
3714
+ * @param {constructor} opt_type A constructor for the type. Default = `Float32Array`.
3715
+ * @return {ArrayBufferView} A typed array.
3716
+ * @memberOf module:twgl/primitives
3717
+ */
430
3718
  export function createAugmentedTypedArray(numComponents: number, numElements: number, opt_type: Function): ArrayBufferView;
3719
+ /**
3720
+ * Given indexed vertices creates a new set of vertices un-indexed by expanding the indexed vertices.
3721
+ * @param {Object.<string, TypedArray>} vertices The indexed vertices to deindex
3722
+ * @return {Object.<string, TypedArray>} The deindexed vertices
3723
+ * @memberOf module:twgl/primitives
3724
+ */
431
3725
  export function deindexVertices(vertices: {
432
3726
  [key: string]: TypedArray;
433
3727
  }): {
434
3728
  [key: string]: TypedArray;
435
3729
  };
3730
+ /**
3731
+ * flattens the normals of deindexed vertices in place.
3732
+ * @param {Object.<string, TypedArray>} vertices The deindexed vertices who's normals to flatten
3733
+ * @return {Object.<string, TypedArray>} The flattened vertices (same as was passed in)
3734
+ * @memberOf module:twgl/primitives
3735
+ */
436
3736
  export function flattenNormals(vertices: {
437
3737
  [key: string]: TypedArray;
438
3738
  }): {
439
3739
  [key: string]: TypedArray;
440
3740
  };
3741
+ /**
3742
+ * Reorients directions by the given matrix..
3743
+ * @param {(number[]|TypedArray)} array The array. Assumes value floats per element.
3744
+ * @param {m4.Mat4} matrix A matrix to multiply by.
3745
+ * @return {(number[]|TypedArray)} the same array that was passed in
3746
+ * @memberOf module:twgl/primitives
3747
+ */
441
3748
  export function reorientDirections(array: number[] | TypedArray, matrix: m4.Mat4): number[] | TypedArray;
3749
+ /**
3750
+ * Reorients normals by the inverse-transpose of the given
3751
+ * matrix..
3752
+ * @param {(number[]|TypedArray)} array The array. Assumes value floats per element.
3753
+ * @param {m4.Mat4} matrix A matrix to multiply by.
3754
+ * @return {(number[]|TypedArray)} the same array that was passed in
3755
+ * @memberOf module:twgl/primitives
3756
+ */
442
3757
  export function reorientNormals(array: number[] | TypedArray, matrix: m4.Mat4): number[] | TypedArray;
3758
+ /**
3759
+ * Reorients positions by the given matrix. In other words, it
3760
+ * multiplies each vertex by the given matrix.
3761
+ * @param {(number[]|TypedArray)} array The array. Assumes value floats per element.
3762
+ * @param {m4.Mat4} matrix A matrix to multiply by.
3763
+ * @return {(number[]|TypedArray)} the same array that was passed in
3764
+ * @memberOf module:twgl/primitives
3765
+ */
443
3766
  export function reorientPositions(array: number[] | TypedArray, matrix: m4.Mat4): number[] | TypedArray;
3767
+ /**
3768
+ * @typedef {(number[]|TypedArray)} NativeArrayOrTypedArray
3769
+ */
444
3770
  export type NativeArrayOrTypedArray = number[] | TypedArray;
3771
+ /**
3772
+ * Reorients arrays by the given matrix. Assumes arrays have
3773
+ * names that contains 'pos' could be reoriented as positions,
3774
+ * 'binorm' or 'tan' as directions, and 'norm' as normals.
3775
+ *
3776
+ * @param {Object.<string, NativeArrayOrTypedArray>} arrays The vertices to reorient
3777
+ * @param {m4.Mat4} matrix matrix to reorient by.
3778
+ * @return {Object.<string, NativeArrayOrTypedArray>} same arrays that were passed in.
3779
+ * @memberOf module:twgl/primitives
3780
+ */
445
3781
  export function reorientVertices(arrays: {
446
3782
  [key: string]: NativeArrayOrTypedArray;
447
3783
  }, matrix: m4.Mat4): {
448
3784
  [key: string]: NativeArrayOrTypedArray;
449
3785
  };
3786
+ /**
3787
+ * Creates XY quad BufferInfo
3788
+ *
3789
+ * The default with no parameters will return a 2x2 quad with values from -1 to +1.
3790
+ * If you want a unit quad with that goes from 0 to 1 you'd call it with
3791
+ *
3792
+ * twgl.primitives.createXYQuadBufferInfo(gl, 1, 0.5, 0.5);
3793
+ *
3794
+ * If you want a unit quad centered above 0,0 you'd call it with
3795
+ *
3796
+ * twgl.primitives.createXYQuadBufferInfo(gl, 1, 0, 0.5);
3797
+ *
3798
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
3799
+ * @param {number} [size] the size across the quad. Defaults to 2 which means vertices will go from -1 to +1
3800
+ * @param {number} [xOffset] the amount to offset the quad in X
3801
+ * @param {number} [yOffset] the amount to offset the quad in Y
3802
+ * @return {Object.<string, WebGLBuffer>} the created XY Quad BufferInfo
3803
+ * @memberOf module:twgl/primitives
3804
+ * @function createXYQuadBuffers
3805
+ */
450
3806
  export function createXYQuadBuffers(gl: WebGLRenderingContext, size?: number, xOffset?: number, yOffset?: number): {
451
3807
  [key: string]: WebGLBuffer;
452
3808
  };
3809
+ /**
3810
+ * Creates XY quad Buffers
3811
+ *
3812
+ * The default with no parameters will return a 2x2 quad with values from -1 to +1.
3813
+ * If you want a unit quad with that goes from 0 to 1 you'd call it with
3814
+ *
3815
+ * twgl.primitives.createXYQuadBufferInfo(gl, 1, 0.5, 0.5);
3816
+ *
3817
+ * If you want a unit quad centered above 0,0 you'd call it with
3818
+ *
3819
+ * twgl.primitives.createXYQuadBufferInfo(gl, 1, 0, 0.5);
3820
+ *
3821
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
3822
+ * @param {number} [size] the size across the quad. Defaults to 2 which means vertices will go from -1 to +1
3823
+ * @param {number} [xOffset] the amount to offset the quad in X
3824
+ * @param {number} [yOffset] the amount to offset the quad in Y
3825
+ * @return {BufferInfo} the created XY Quad buffers
3826
+ * @memberOf module:twgl/primitives
3827
+ * @function createXYQuadBufferInfo
3828
+ */
453
3829
  export function createXYQuadBufferInfo(gl: WebGLRenderingContext, size?: number, xOffset?: number, yOffset?: number): BufferInfo;
3830
+ /**
3831
+ * Creates XY quad vertices
3832
+ *
3833
+ * The default with no parameters will return a 2x2 quad with values from -1 to +1.
3834
+ * If you want a unit quad with that goes from 0 to 1 you'd call it with
3835
+ *
3836
+ * twgl.primitives.createXYQuadVertices(1, 0.5, 0.5);
3837
+ *
3838
+ * If you want a unit quad centered above 0,0 you'd call it with
3839
+ *
3840
+ * twgl.primitives.createXYQuadVertices(1, 0, 0.5);
3841
+ *
3842
+ * @param {number} [size] the size across the quad. Defaults to 2 which means vertices will go from -1 to +1
3843
+ * @param {number} [xOffset] the amount to offset the quad in X
3844
+ * @param {number} [yOffset] the amount to offset the quad in Y
3845
+ * @return {Object.<string, TypedArray>} the created XY Quad vertices
3846
+ * @memberOf module:twgl/primitives
3847
+ */
454
3848
  export function createXYQuadVertices(size?: number, xOffset?: number, yOffset?: number): {
455
3849
  [key: string]: TypedArray;
456
3850
  };
3851
+ /**
3852
+ * Creates XZ plane BufferInfo.
3853
+ *
3854
+ * The created plane has position, normal, and texcoord data
3855
+ *
3856
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
3857
+ * @param {number} [width] Width of the plane. Default = 1
3858
+ * @param {number} [depth] Depth of the plane. Default = 1
3859
+ * @param {number} [subdivisionsWidth] Number of steps across the plane. Default = 1
3860
+ * @param {number} [subdivisionsDepth] Number of steps down the plane. Default = 1
3861
+ * @param {m4.Mat4} [matrix] A matrix by which to multiply all the vertices.
3862
+ * @return {BufferInfo} The created plane BufferInfo.
3863
+ * @memberOf module:twgl/primitives
3864
+ * @function createPlaneBufferInfo
3865
+ */
457
3866
  export function createPlaneBufferInfo(gl: WebGLRenderingContext, width?: number, depth?: number, subdivisionsWidth?: number, subdivisionsDepth?: number, matrix?: m4.Mat4): BufferInfo;
3867
+ /**
3868
+ * Creates XZ plane buffers.
3869
+ *
3870
+ * The created plane has position, normal, and texcoord data
3871
+ *
3872
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
3873
+ * @param {number} [width] Width of the plane. Default = 1
3874
+ * @param {number} [depth] Depth of the plane. Default = 1
3875
+ * @param {number} [subdivisionsWidth] Number of steps across the plane. Default = 1
3876
+ * @param {number} [subdivisionsDepth] Number of steps down the plane. Default = 1
3877
+ * @param {m4.Mat4} [matrix] A matrix by which to multiply all the vertices.
3878
+ * @return {Object.<string, WebGLBuffer>} The created plane buffers.
3879
+ * @memberOf module:twgl/primitives
3880
+ * @function createPlaneBuffers
3881
+ */
458
3882
  export function createPlaneBuffers(gl: WebGLRenderingContext, width?: number, depth?: number, subdivisionsWidth?: number, subdivisionsDepth?: number, matrix?: m4.Mat4): {
459
3883
  [key: string]: WebGLBuffer;
460
3884
  };
3885
+ /**
3886
+ * Creates XZ plane vertices.
3887
+ *
3888
+ * The created plane has position, normal, and texcoord data
3889
+ *
3890
+ * @param {number} [width] Width of the plane. Default = 1
3891
+ * @param {number} [depth] Depth of the plane. Default = 1
3892
+ * @param {number} [subdivisionsWidth] Number of steps across the plane. Default = 1
3893
+ * @param {number} [subdivisionsDepth] Number of steps down the plane. Default = 1
3894
+ * @param {m4.Mat4} [matrix] A matrix by which to multiply all the vertices.
3895
+ * @return {Object.<string, TypedArray>} The created plane vertices.
3896
+ * @memberOf module:twgl/primitives
3897
+ */
461
3898
  export function createPlaneVertices(width?: number, depth?: number, subdivisionsWidth?: number, subdivisionsDepth?: number, matrix?: m4.Mat4): {
462
3899
  [key: string]: TypedArray;
463
3900
  };
3901
+ /**
3902
+ * Creates sphere BufferInfo.
3903
+ *
3904
+ * The created sphere has position, normal, and texcoord data
3905
+ *
3906
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
3907
+ * @param {number} radius radius of the sphere.
3908
+ * @param {number} subdivisionsAxis number of steps around the sphere.
3909
+ * @param {number} subdivisionsHeight number of vertically on the sphere.
3910
+ * @param {number} [opt_startLatitudeInRadians] where to start the
3911
+ * top of the sphere. Default = 0.
3912
+ * @param {number} [opt_endLatitudeInRadians] Where to end the
3913
+ * bottom of the sphere. Default = Math.PI.
3914
+ * @param {number} [opt_startLongitudeInRadians] where to start
3915
+ * wrapping the sphere. Default = 0.
3916
+ * @param {number} [opt_endLongitudeInRadians] where to end
3917
+ * wrapping the sphere. Default = 2 * Math.PI.
3918
+ * @return {BufferInfo} The created sphere BufferInfo.
3919
+ * @memberOf module:twgl/primitives
3920
+ * @function createSphereBufferInfo
3921
+ */
464
3922
  export function createSphereBufferInfo(gl: WebGLRenderingContext, radius: number, subdivisionsAxis: number, subdivisionsHeight: number, opt_startLatitudeInRadians?: number, opt_endLatitudeInRadians?: number, opt_startLongitudeInRadians?: number, opt_endLongitudeInRadians?: number): BufferInfo;
3923
+ /**
3924
+ * Creates sphere buffers.
3925
+ *
3926
+ * The created sphere has position, normal, and texcoord data
3927
+ *
3928
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
3929
+ * @param {number} radius radius of the sphere.
3930
+ * @param {number} subdivisionsAxis number of steps around the sphere.
3931
+ * @param {number} subdivisionsHeight number of vertically on the sphere.
3932
+ * @param {number} [opt_startLatitudeInRadians] where to start the
3933
+ * top of the sphere. Default = 0.
3934
+ * @param {number} [opt_endLatitudeInRadians] Where to end the
3935
+ * bottom of the sphere. Default = Math.PI.
3936
+ * @param {number} [opt_startLongitudeInRadians] where to start
3937
+ * wrapping the sphere. Default = 0.
3938
+ * @param {number} [opt_endLongitudeInRadians] where to end
3939
+ * wrapping the sphere. Default = 2 * Math.PI.
3940
+ * @return {Object.<string, WebGLBuffer>} The created sphere buffers.
3941
+ * @memberOf module:twgl/primitives
3942
+ * @function createSphereBuffers
3943
+ */
465
3944
  export function createSphereBuffers(gl: WebGLRenderingContext, radius: number, subdivisionsAxis: number, subdivisionsHeight: number, opt_startLatitudeInRadians?: number, opt_endLatitudeInRadians?: number, opt_startLongitudeInRadians?: number, opt_endLongitudeInRadians?: number): {
466
3945
  [key: string]: WebGLBuffer;
467
3946
  };
3947
+ /**
3948
+ * Creates sphere vertices.
3949
+ *
3950
+ * The created sphere has position, normal, and texcoord data
3951
+ *
3952
+ * @param {number} radius radius of the sphere.
3953
+ * @param {number} subdivisionsAxis number of steps around the sphere.
3954
+ * @param {number} subdivisionsHeight number of vertically on the sphere.
3955
+ * @param {number} [opt_startLatitudeInRadians] where to start the
3956
+ * top of the sphere. Default = 0.
3957
+ * @param {number} [opt_endLatitudeInRadians] Where to end the
3958
+ * bottom of the sphere. Default = Math.PI.
3959
+ * @param {number} [opt_startLongitudeInRadians] where to start
3960
+ * wrapping the sphere. Default = 0.
3961
+ * @param {number} [opt_endLongitudeInRadians] where to end
3962
+ * wrapping the sphere. Default = 2 * Math.PI.
3963
+ * @return {Object.<string, TypedArray>} The created sphere vertices.
3964
+ * @memberOf module:twgl/primitives
3965
+ */
468
3966
  export function createSphereVertices(radius: number, subdivisionsAxis: number, subdivisionsHeight: number, opt_startLatitudeInRadians?: number, opt_endLatitudeInRadians?: number, opt_startLongitudeInRadians?: number, opt_endLongitudeInRadians?: number): {
469
3967
  [key: string]: TypedArray;
470
3968
  };
3969
+ /**
3970
+ * Creates a BufferInfo for a cube.
3971
+ *
3972
+ * The cube is created around the origin. (-size / 2, size / 2).
3973
+ *
3974
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
3975
+ * @param {number} [size] width, height and depth of the cube.
3976
+ * @return {BufferInfo} The created BufferInfo.
3977
+ * @memberOf module:twgl/primitives
3978
+ * @function createCubeBufferInfo
3979
+ */
471
3980
  export function createCubeBufferInfo(gl: WebGLRenderingContext, size?: number): BufferInfo;
3981
+ /**
3982
+ * Creates the buffers and indices for a cube.
3983
+ *
3984
+ * The cube is created around the origin. (-size / 2, size / 2).
3985
+ *
3986
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
3987
+ * @param {number} [size] width, height and depth of the cube.
3988
+ * @return {Object.<string, WebGLBuffer>} The created buffers.
3989
+ * @memberOf module:twgl/primitives
3990
+ * @function createCubeBuffers
3991
+ */
472
3992
  export function createCubeBuffers(gl: WebGLRenderingContext, size?: number): {
473
3993
  [key: string]: WebGLBuffer;
474
3994
  };
3995
+ /**
3996
+ * Creates the vertices and indices for a cube.
3997
+ *
3998
+ * The cube is created around the origin. (-size / 2, size / 2).
3999
+ *
4000
+ * @param {number} [size] width, height and depth of the cube.
4001
+ * @return {Object.<string, TypedArray>} The created vertices.
4002
+ * @memberOf module:twgl/primitives
4003
+ */
475
4004
  export function createCubeVertices(size?: number): {
476
4005
  [key: string]: TypedArray;
477
4006
  };
4007
+ /**
4008
+ * Creates a BufferInfo for a truncated cone, which is like a cylinder
4009
+ * except that it has different top and bottom radii. A truncated cone
4010
+ * can also be used to create cylinders and regular cones. The
4011
+ * truncated cone will be created centered about the origin, with the
4012
+ * y axis as its vertical axis.
4013
+ *
4014
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
4015
+ * @param {number} bottomRadius Bottom radius of truncated cone.
4016
+ * @param {number} topRadius Top radius of truncated cone.
4017
+ * @param {number} height Height of truncated cone.
4018
+ * @param {number} radialSubdivisions The number of subdivisions around the
4019
+ * truncated cone.
4020
+ * @param {number} verticalSubdivisions The number of subdivisions down the
4021
+ * truncated cone.
4022
+ * @param {boolean} [opt_topCap] Create top cap. Default = true.
4023
+ * @param {boolean} [opt_bottomCap] Create bottom cap. Default = true.
4024
+ * @return {BufferInfo} The created cone BufferInfo.
4025
+ * @memberOf module:twgl/primitives
4026
+ * @function createTruncatedConeBufferInfo
4027
+ */
478
4028
  export function createTruncatedConeBufferInfo(gl: WebGLRenderingContext, bottomRadius: number, topRadius: number, height: number, radialSubdivisions: number, verticalSubdivisions: number, opt_topCap?: boolean, opt_bottomCap?: boolean): BufferInfo;
4029
+ /**
4030
+ * Creates buffers for a truncated cone, which is like a cylinder
4031
+ * except that it has different top and bottom radii. A truncated cone
4032
+ * can also be used to create cylinders and regular cones. The
4033
+ * truncated cone will be created centered about the origin, with the
4034
+ * y axis as its vertical axis.
4035
+ *
4036
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
4037
+ * @param {number} bottomRadius Bottom radius of truncated cone.
4038
+ * @param {number} topRadius Top radius of truncated cone.
4039
+ * @param {number} height Height of truncated cone.
4040
+ * @param {number} radialSubdivisions The number of subdivisions around the
4041
+ * truncated cone.
4042
+ * @param {number} verticalSubdivisions The number of subdivisions down the
4043
+ * truncated cone.
4044
+ * @param {boolean} [opt_topCap] Create top cap. Default = true.
4045
+ * @param {boolean} [opt_bottomCap] Create bottom cap. Default = true.
4046
+ * @return {Object.<string, WebGLBuffer>} The created cone buffers.
4047
+ * @memberOf module:twgl/primitives
4048
+ * @function createTruncatedConeBuffers
4049
+ */
479
4050
  export function createTruncatedConeBuffers(gl: WebGLRenderingContext, bottomRadius: number, topRadius: number, height: number, radialSubdivisions: number, verticalSubdivisions: number, opt_topCap?: boolean, opt_bottomCap?: boolean): {
480
4051
  [key: string]: WebGLBuffer;
481
4052
  };
4053
+ /**
4054
+ * Creates vertices for a truncated cone, which is like a cylinder
4055
+ * except that it has different top and bottom radii. A truncated cone
4056
+ * can also be used to create cylinders and regular cones. The
4057
+ * truncated cone will be created centered about the origin, with the
4058
+ * y axis as its vertical axis. .
4059
+ *
4060
+ * @param {number} bottomRadius Bottom radius of truncated cone.
4061
+ * @param {number} topRadius Top radius of truncated cone.
4062
+ * @param {number} height Height of truncated cone.
4063
+ * @param {number} radialSubdivisions The number of subdivisions around the
4064
+ * truncated cone.
4065
+ * @param {number} verticalSubdivisions The number of subdivisions down the
4066
+ * truncated cone.
4067
+ * @param {boolean} [opt_topCap] Create top cap. Default = true.
4068
+ * @param {boolean} [opt_bottomCap] Create bottom cap. Default = true.
4069
+ * @return {Object.<string, TypedArray>} The created cone vertices.
4070
+ * @memberOf module:twgl/primitives
4071
+ */
482
4072
  export function createTruncatedConeVertices(bottomRadius: number, topRadius: number, height: number, radialSubdivisions: number, verticalSubdivisions: number, opt_topCap?: boolean, opt_bottomCap?: boolean): {
483
4073
  [key: string]: TypedArray;
484
4074
  };
4075
+ /**
4076
+ * Creates 3D 'F' BufferInfo.
4077
+ * An 'F' is useful because you can easily tell which way it is oriented.
4078
+ * The created 'F' has position, normal, texcoord, and color buffers.
4079
+ *
4080
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
4081
+ * @return {BufferInfo} The created BufferInfo.
4082
+ * @memberOf module:twgl/primitives
4083
+ * @function create3DFBufferInfo
4084
+ */
485
4085
  export function create3DFBufferInfo(gl: WebGLRenderingContext): BufferInfo;
4086
+ /**
4087
+ * Creates 3D 'F' buffers.
4088
+ * An 'F' is useful because you can easily tell which way it is oriented.
4089
+ * The created 'F' has position, normal, texcoord, and color buffers.
4090
+ *
4091
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
4092
+ * @return {Object.<string, WebGLBuffer>} The created buffers.
4093
+ * @memberOf module:twgl/primitives
4094
+ * @function create3DFBuffers
4095
+ */
486
4096
  export function create3DFBuffers(gl: WebGLRenderingContext): {
487
4097
  [key: string]: WebGLBuffer;
488
4098
  };
4099
+ /**
4100
+ * Creates 3D 'F' vertices.
4101
+ * An 'F' is useful because you can easily tell which way it is oriented.
4102
+ * The created 'F' has position, normal, texcoord, and color arrays.
4103
+ *
4104
+ * @return {Object.<string, TypedArray>} The created vertices.
4105
+ * @memberOf module:twgl/primitives
4106
+ */
489
4107
  export function create3DFVertices(): {
490
4108
  [key: string]: TypedArray;
491
4109
  };
4110
+ /**
4111
+ * Creates crescent BufferInfo.
4112
+ *
4113
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
4114
+ * @param {number} verticalRadius The vertical radius of the crescent.
4115
+ * @param {number} outerRadius The outer radius of the crescent.
4116
+ * @param {number} innerRadius The inner radius of the crescent.
4117
+ * @param {number} thickness The thickness of the crescent.
4118
+ * @param {number} subdivisionsDown number of steps around the crescent.
4119
+ * @param {number} [startOffset] Where to start arc. Default 0.
4120
+ * @param {number} [endOffset] Where to end arg. Default 1.
4121
+ * @return {BufferInfo} The created BufferInfo.
4122
+ * @memberOf module:twgl/primitives
4123
+ * @function createCresentBufferInfo
4124
+ */
492
4125
  export function createCresentBufferInfo(gl: WebGLRenderingContext, verticalRadius: number, outerRadius: number, innerRadius: number, thickness: number, subdivisionsDown: number, startOffset?: number, endOffset?: number): BufferInfo;
4126
+ /**
4127
+ * Creates crescent buffers.
4128
+ *
4129
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
4130
+ * @param {number} verticalRadius The vertical radius of the crescent.
4131
+ * @param {number} outerRadius The outer radius of the crescent.
4132
+ * @param {number} innerRadius The inner radius of the crescent.
4133
+ * @param {number} thickness The thickness of the crescent.
4134
+ * @param {number} subdivisionsDown number of steps around the crescent.
4135
+ * @param {number} [startOffset] Where to start arc. Default 0.
4136
+ * @param {number} [endOffset] Where to end arg. Default 1.
4137
+ * @return {Object.<string, WebGLBuffer>} The created buffers.
4138
+ * @memberOf module:twgl/primitives
4139
+ * @function createCresentBuffers
4140
+ */
493
4141
  export function createCresentBuffers(gl: WebGLRenderingContext, verticalRadius: number, outerRadius: number, innerRadius: number, thickness: number, subdivisionsDown: number, startOffset?: number, endOffset?: number): {
494
4142
  [key: string]: WebGLBuffer;
495
4143
  };
4144
+ /**
4145
+ * Creates crescent buffers.
4146
+ *
4147
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
4148
+ * @param {number} verticalRadius The vertical radius of the crescent.
4149
+ * @param {number} outerRadius The outer radius of the crescent.
4150
+ * @param {number} innerRadius The inner radius of the crescent.
4151
+ * @param {number} thickness The thickness of the crescent.
4152
+ * @param {number} subdivisionsDown number of steps around the crescent.
4153
+ * @param {number} [startOffset] Where to start arc. Default 0.
4154
+ * @param {number} [endOffset] Where to end arg. Default 1.
4155
+ * @return {Object.<string, WebGLBuffer>} The created buffers.
4156
+ * @memberOf module:twgl/primitives
4157
+ * @function createCresentBuffers
4158
+ */
496
4159
  export function createCresentBuffers(gl: WebGLRenderingContext, verticalRadius: number, outerRadius: number, innerRadius: number, thickness: number, subdivisionsDown: number, startOffset?: number, endOffset?: number): {
497
4160
  [key: string]: WebGLBuffer;
498
4161
  };
4162
+ /**
4163
+ * Creates crescent BufferInfo.
4164
+ *
4165
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
4166
+ * @param {number} verticalRadius The vertical radius of the crescent.
4167
+ * @param {number} outerRadius The outer radius of the crescent.
4168
+ * @param {number} innerRadius The inner radius of the crescent.
4169
+ * @param {number} thickness The thickness of the crescent.
4170
+ * @param {number} subdivisionsDown number of steps around the crescent.
4171
+ * @param {number} [startOffset] Where to start arc. Default 0.
4172
+ * @param {number} [endOffset] Where to end arg. Default 1.
4173
+ * @return {BufferInfo} The created BufferInfo.
4174
+ * @memberOf module:twgl/primitives
4175
+ * @function createCrescentBufferInfo
4176
+ */
499
4177
  export function createCrescentBufferInfo(gl: WebGLRenderingContext, verticalRadius: number, outerRadius: number, innerRadius: number, thickness: number, subdivisionsDown: number, startOffset?: number, endOffset?: number): BufferInfo;
4178
+ /**
4179
+ * Creates crescent buffers.
4180
+ *
4181
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
4182
+ * @param {number} verticalRadius The vertical radius of the crescent.
4183
+ * @param {number} outerRadius The outer radius of the crescent.
4184
+ * @param {number} innerRadius The inner radius of the crescent.
4185
+ * @param {number} thickness The thickness of the crescent.
4186
+ * @param {number} subdivisionsDown number of steps around the crescent.
4187
+ * @param {number} [startOffset] Where to start arc. Default 0.
4188
+ * @param {number} [endOffset] Where to end arg. Default 1.
4189
+ * @return {Object.<string, WebGLBuffer>} The created buffers.
4190
+ * @memberOf module:twgl/primitives
4191
+ * @function createCrescentBuffers
4192
+ */
500
4193
  export function createCrescentBuffers(gl: WebGLRenderingContext, verticalRadius: number, outerRadius: number, innerRadius: number, thickness: number, subdivisionsDown: number, startOffset?: number, endOffset?: number): {
501
4194
  [key: string]: WebGLBuffer;
502
4195
  };
4196
+ /**
4197
+ * Creates crescent vertices.
4198
+ *
4199
+ * @param {number} verticalRadius The vertical radius of the crescent.
4200
+ * @param {number} outerRadius The outer radius of the crescent.
4201
+ * @param {number} innerRadius The inner radius of the crescent.
4202
+ * @param {number} thickness The thickness of the crescent.
4203
+ * @param {number} subdivisionsDown number of steps around the crescent.
4204
+ * @param {number} [startOffset] Where to start arc. Default 0.
4205
+ * @param {number} [endOffset] Where to end arg. Default 1.
4206
+ * @return {Object.<string, TypedArray>} The created vertices.
4207
+ * @memberOf module:twgl/primitives
4208
+ */
503
4209
  export function createCrescentVertices(verticalRadius: number, outerRadius: number, innerRadius: number, thickness: number, subdivisionsDown: number, startOffset?: number, endOffset?: number): {
504
4210
  [key: string]: TypedArray;
505
4211
  };
4212
+ /**
4213
+ * Creates cylinder BufferInfo. The cylinder will be created around the origin
4214
+ * along the y-axis.
4215
+ *
4216
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
4217
+ * @param {number} radius Radius of cylinder.
4218
+ * @param {number} height Height of cylinder.
4219
+ * @param {number} radialSubdivisions The number of subdivisions around the cylinder.
4220
+ * @param {number} verticalSubdivisions The number of subdivisions down the cylinder.
4221
+ * @param {boolean} [topCap] Create top cap. Default = true.
4222
+ * @param {boolean} [bottomCap] Create bottom cap. Default = true.
4223
+ * @return {BufferInfo} The created BufferInfo.
4224
+ * @memberOf module:twgl/primitives
4225
+ * @function createCylinderBufferInfo
4226
+ */
506
4227
  export function createCylinderBufferInfo(gl: WebGLRenderingContext, radius: number, height: number, radialSubdivisions: number, verticalSubdivisions: number, topCap?: boolean, bottomCap?: boolean): BufferInfo;
4228
+ /**
4229
+ * Creates cylinder buffers. The cylinder will be created around the origin
4230
+ * along the y-axis.
4231
+ *
4232
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
4233
+ * @param {number} radius Radius of cylinder.
4234
+ * @param {number} height Height of cylinder.
4235
+ * @param {number} radialSubdivisions The number of subdivisions around the cylinder.
4236
+ * @param {number} verticalSubdivisions The number of subdivisions down the cylinder.
4237
+ * @param {boolean} [topCap] Create top cap. Default = true.
4238
+ * @param {boolean} [bottomCap] Create bottom cap. Default = true.
4239
+ * @return {Object.<string, WebGLBuffer>} The created buffers.
4240
+ * @memberOf module:twgl/primitives
4241
+ * @function createCylinderBuffers
4242
+ */
507
4243
  export function createCylinderBuffers(gl: WebGLRenderingContext, radius: number, height: number, radialSubdivisions: number, verticalSubdivisions: number, topCap?: boolean, bottomCap?: boolean): {
508
4244
  [key: string]: WebGLBuffer;
509
4245
  };
4246
+ /**
4247
+ * Creates cylinder vertices. The cylinder will be created around the origin
4248
+ * along the y-axis.
4249
+ *
4250
+ * @param {number} radius Radius of cylinder.
4251
+ * @param {number} height Height of cylinder.
4252
+ * @param {number} radialSubdivisions The number of subdivisions around the cylinder.
4253
+ * @param {number} verticalSubdivisions The number of subdivisions down the cylinder.
4254
+ * @param {boolean} [topCap] Create top cap. Default = true.
4255
+ * @param {boolean} [bottomCap] Create bottom cap. Default = true.
4256
+ * @return {Object.<string, TypedArray>} The created vertices.
4257
+ * @memberOf module:twgl/primitives
4258
+ */
510
4259
  export function createCylinderVertices(radius: number, height: number, radialSubdivisions: number, verticalSubdivisions: number, topCap?: boolean, bottomCap?: boolean): {
511
4260
  [key: string]: TypedArray;
512
4261
  };
4262
+ /**
4263
+ * Creates BufferInfo for a torus
4264
+ *
4265
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
4266
+ * @param {number} radius radius of center of torus circle.
4267
+ * @param {number} thickness radius of torus ring.
4268
+ * @param {number} radialSubdivisions The number of subdivisions around the torus.
4269
+ * @param {number} bodySubdivisions The number of subdivisions around the body torus.
4270
+ * @param {boolean} [startAngle] start angle in radians. Default = 0.
4271
+ * @param {boolean} [endAngle] end angle in radians. Default = Math.PI * 2.
4272
+ * @return {BufferInfo} The created BufferInfo.
4273
+ * @memberOf module:twgl/primitives
4274
+ * @function createTorusBufferInfo
4275
+ */
513
4276
  export function createTorusBufferInfo(gl: WebGLRenderingContext, radius: number, thickness: number, radialSubdivisions: number, bodySubdivisions: number, startAngle?: boolean, endAngle?: boolean): BufferInfo;
4277
+ /**
4278
+ * Creates buffers for a torus
4279
+ *
4280
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
4281
+ * @param {number} radius radius of center of torus circle.
4282
+ * @param {number} thickness radius of torus ring.
4283
+ * @param {number} radialSubdivisions The number of subdivisions around the torus.
4284
+ * @param {number} bodySubdivisions The number of subdivisions around the body torus.
4285
+ * @param {boolean} [startAngle] start angle in radians. Default = 0.
4286
+ * @param {boolean} [endAngle] end angle in radians. Default = Math.PI * 2.
4287
+ * @return {Object.<string, WebGLBuffer>} The created buffers.
4288
+ * @memberOf module:twgl/primitives
4289
+ * @function createTorusBuffers
4290
+ */
514
4291
  export function createTorusBuffers(gl: WebGLRenderingContext, radius: number, thickness: number, radialSubdivisions: number, bodySubdivisions: number, startAngle?: boolean, endAngle?: boolean): {
515
4292
  [key: string]: WebGLBuffer;
516
4293
  };
4294
+ /**
4295
+ * Creates vertices for a torus
4296
+ *
4297
+ * @param {number} radius radius of center of torus circle.
4298
+ * @param {number} thickness radius of torus ring.
4299
+ * @param {number} radialSubdivisions The number of subdivisions around the torus.
4300
+ * @param {number} bodySubdivisions The number of subdivisions around the body torus.
4301
+ * @param {boolean} [startAngle] start angle in radians. Default = 0.
4302
+ * @param {boolean} [endAngle] end angle in radians. Default = Math.PI * 2.
4303
+ * @return {Object.<string, TypedArray>} The created vertices.
4304
+ * @memberOf module:twgl/primitives
4305
+ */
517
4306
  export function createTorusVertices(radius: number, thickness: number, radialSubdivisions: number, bodySubdivisions: number, startAngle?: boolean, endAngle?: boolean): {
518
4307
  [key: string]: TypedArray;
519
4308
  };
4309
+ /**
4310
+ * Creates a disc BufferInfo. The disc will be in the xz plane, centered at
4311
+ * the origin. When creating, at least 3 divisions, or pie
4312
+ * pieces, need to be specified, otherwise the triangles making
4313
+ * up the disc will be degenerate. You can also specify the
4314
+ * number of radial pieces `stacks`. A value of 1 for
4315
+ * stacks will give you a simple disc of pie pieces. If you
4316
+ * want to create an annulus you can set `innerRadius` to a
4317
+ * value > 0. Finally, `stackPower` allows you to have the widths
4318
+ * increase or decrease as you move away from the center. This
4319
+ * is particularly useful when using the disc as a ground plane
4320
+ * with a fixed camera such that you don't need the resolution
4321
+ * of small triangles near the perimeter. For example, a value
4322
+ * of 2 will produce stacks whose outside radius increases with
4323
+ * the square of the stack index. A value of 1 will give uniform
4324
+ * stacks.
4325
+ *
4326
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
4327
+ * @param {number} radius Radius of the ground plane.
4328
+ * @param {number} divisions Number of triangles in the ground plane (at least 3).
4329
+ * @param {number} [stacks] Number of radial divisions (default=1).
4330
+ * @param {number} [innerRadius] Default 0.
4331
+ * @param {number} [stackPower] Power to raise stack size to for decreasing width.
4332
+ * @return {BufferInfo} The created BufferInfo.
4333
+ * @memberOf module:twgl/primitives
4334
+ * @function createDiscBufferInfo
4335
+ */
520
4336
  export function createDiscBufferInfo(gl: WebGLRenderingContext, radius: number, divisions: number, stacks?: number, innerRadius?: number, stackPower?: number): BufferInfo;
4337
+ /**
4338
+ * Creates disc buffers. The disc will be in the xz plane, centered at
4339
+ * the origin. When creating, at least 3 divisions, or pie
4340
+ * pieces, need to be specified, otherwise the triangles making
4341
+ * up the disc will be degenerate. You can also specify the
4342
+ * number of radial pieces `stacks`. A value of 1 for
4343
+ * stacks will give you a simple disc of pie pieces. If you
4344
+ * want to create an annulus you can set `innerRadius` to a
4345
+ * value > 0. Finally, `stackPower` allows you to have the widths
4346
+ * increase or decrease as you move away from the center. This
4347
+ * is particularly useful when using the disc as a ground plane
4348
+ * with a fixed camera such that you don't need the resolution
4349
+ * of small triangles near the perimeter. For example, a value
4350
+ * of 2 will produce stacks whose outside radius increases with
4351
+ * the square of the stack index. A value of 1 will give uniform
4352
+ * stacks.
4353
+ *
4354
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
4355
+ * @param {number} radius Radius of the ground plane.
4356
+ * @param {number} divisions Number of triangles in the ground plane (at least 3).
4357
+ * @param {number} [stacks] Number of radial divisions (default=1).
4358
+ * @param {number} [innerRadius] Default 0.
4359
+ * @param {number} [stackPower] Power to raise stack size to for decreasing width.
4360
+ * @return {Object.<string, WebGLBuffer>} The created buffers.
4361
+ * @memberOf module:twgl/primitives
4362
+ * @function createDiscBuffers
4363
+ */
521
4364
  export function createDiscBuffers(gl: WebGLRenderingContext, radius: number, divisions: number, stacks?: number, innerRadius?: number, stackPower?: number): {
522
4365
  [key: string]: WebGLBuffer;
523
4366
  };
4367
+ /**
4368
+ * Creates disc vertices. The disc will be in the xz plane, centered at
4369
+ * the origin. When creating, at least 3 divisions, or pie
4370
+ * pieces, need to be specified, otherwise the triangles making
4371
+ * up the disc will be degenerate. You can also specify the
4372
+ * number of radial pieces `stacks`. A value of 1 for
4373
+ * stacks will give you a simple disc of pie pieces. If you
4374
+ * want to create an annulus you can set `innerRadius` to a
4375
+ * value > 0. Finally, `stackPower` allows you to have the widths
4376
+ * increase or decrease as you move away from the center. This
4377
+ * is particularly useful when using the disc as a ground plane
4378
+ * with a fixed camera such that you don't need the resolution
4379
+ * of small triangles near the perimeter. For example, a value
4380
+ * of 2 will produce stacks whose outside radius increases with
4381
+ * the square of the stack index. A value of 1 will give uniform
4382
+ * stacks.
4383
+ *
4384
+ * @param {number} radius Radius of the ground plane.
4385
+ * @param {number} divisions Number of triangles in the ground plane (at least 3).
4386
+ * @param {number} [stacks] Number of radial divisions (default=1).
4387
+ * @param {number} [innerRadius] Default 0.
4388
+ * @param {number} [stackPower] Power to raise stack size to for decreasing width.
4389
+ * @return {Object.<string, TypedArray>} The created vertices.
4390
+ * @memberOf module:twgl/primitives
4391
+ */
524
4392
  export function createDiscVertices(radius: number, divisions: number, stacks?: number, innerRadius?: number, stackPower?: number): {
525
4393
  [key: string]: TypedArray;
526
4394
  };
4395
+ /**
4396
+ * Used to supply random colors
4397
+ * @callback RandomColorFunc
4398
+ * @param {number} ndx index of triangle/quad if unindexed or index of vertex if indexed
4399
+ * @param {number} channel 0 = red, 1 = green, 2 = blue, 3 = alpha
4400
+ * @return {number} a number from 0 to 255
4401
+ * @memberOf module:twgl/primitives
4402
+ */
527
4403
  export type RandomColorFunc = (ndx: number, channel: number) => number;
4404
+ /**
4405
+ * @typedef {Object} RandomVerticesOptions
4406
+ * @property {number} [vertsPerColor] Defaults to 3 for non-indexed vertices
4407
+ * @property {primitives.RandomColorFunc} [rand] A function to generate random numbers
4408
+ * @memberOf module:twgl/primitives
4409
+ */
528
4410
  export type RandomVerticesOptions = {
529
4411
  vertsPerColor?: number;
530
4412
  rand?: primitives.RandomColorFunc;
531
4413
  };
4414
+ /**
4415
+ * Creates an augmentedTypedArray of random vertex colors.
4416
+ * If the vertices are indexed (have an indices array) then will
4417
+ * just make random colors. Otherwise assumes they are triangles
4418
+ * and makes one random color for every 3 vertices.
4419
+ * @param {Object.<string, ArrayBufferView>} vertices Vertices as returned from one of the createXXXVertices functions.
4420
+ * @param {primitives.RandomVerticesOptions} [options] options.
4421
+ * @return {Object.<string, ArrayBufferView>} same vertices as passed in with `color` added.
4422
+ * @memberOf module:twgl/primitives
4423
+ */
532
4424
  export function makeRandomVertexColors(vertices: {
533
4425
  [key: string]: ArrayBufferView;
534
4426
  }, options?: primitives.RandomVerticesOptions): {
535
4427
  [key: string]: ArrayBufferView;
536
4428
  };
4429
+ /**
4430
+ * Concatenates sets of vertices
4431
+ *
4432
+ * Assumes the vertices match in composition. For example
4433
+ * if one set of vertices has positions, normals, and indices
4434
+ * all sets of vertices must have positions, normals, and indices
4435
+ * and of the same type.
4436
+ *
4437
+ * Example:
4438
+ *
4439
+ * const cubeVertices = twgl.primitives.createCubeVertices(2);
4440
+ * const sphereVertices = twgl.primitives.createSphereVertices(1, 10, 10);
4441
+ * // move the sphere 2 units up
4442
+ * twgl.primitives.reorientVertices(
4443
+ * sphereVertices, twgl.m4.translation([0, 2, 0]));
4444
+ * // merge the sphere with the cube
4445
+ * const cubeSphereVertices = twgl.primitives.concatVertices(
4446
+ * [cubeVertices, sphereVertices]);
4447
+ * // turn them into WebGL buffers and attrib data
4448
+ * const bufferInfo = twgl.createBufferInfoFromArrays(gl, cubeSphereVertices);
4449
+ *
4450
+ * @param {Arrays[]} arrays Array of arrays of vertices
4451
+ * @return {Arrays} The concatenated vertices.
4452
+ * @memberOf module:twgl/primitives
4453
+ */
537
4454
  export function concatVertices(arrays: Arrays[]): Arrays;
4455
+ /**
4456
+ * Creates a duplicate set of vertices
4457
+ *
4458
+ * This is useful for calling reorientVertices when you
4459
+ * also want to keep the original available
4460
+ *
4461
+ * @param {Arrays} arrays of vertices
4462
+ * @return {Arrays} The duplicated vertices.
4463
+ * @memberOf module:twgl/primitives
4464
+ */
538
4465
  export function duplicateVertices(arrays: Arrays): Arrays;
539
4466
  }