twgl.js 5.5.3 → 6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,7 +16,7 @@ Not including the shaders (which is a simple quad shader) here's the entire code
16
16
 
17
17
  ```html
18
18
  <canvas id="c"></canvas>
19
- <script src="../dist/5.x/twgl-full.min.js"></script>
19
+ <script src="../dist/6.x/twgl-full.min.js"></script>
20
20
  <script>
21
21
  const gl = document.getElementById("c").getContext("webgl");
22
22
  const programInfo = twgl.createProgramInfo(gl, ["vs", "fs"]);
@@ -591,6 +591,7 @@ export type UniformBlockSpec = {
591
591
  * @property {ArrayBuffer} array The array buffer that contains the uniform values
592
592
  * @property {Float32Array} asFloat A float view on the array buffer. This is useful
593
593
  * inspecting the contents of the buffer in the debugger.
594
+ * @property {Uint8Array} asUint8t A uint8 view on the array buffer.
594
595
  * @property {WebGLBuffer} buffer A WebGL buffer that will hold a copy of the uniform values for rendering.
595
596
  * @property {number} [offset] offset into buffer
596
597
  * @property {Object<string, ArrayBufferView>} uniforms A uniform name to ArrayBufferView map.
@@ -612,6 +613,7 @@ export type UniformBlockInfo = {
612
613
  name: string;
613
614
  array: ArrayBuffer;
614
615
  asFloat: Float32Array;
616
+ asUint8t: Uint8Array;
615
617
  buffer: WebGLBuffer;
616
618
  offset?: number;
617
619
  uniforms: {
@@ -624,6 +626,8 @@ export type UniformBlockInfo = {
624
626
  /**
625
627
  * @typedef {Object} ProgramInfo
626
628
  * @property {WebGLProgram} program A shader program
629
+ * @property {Object<string, WebGLUniformLocation>} uniformLocations The uniform locations of each uniform
630
+ * @property {Object<string, number>} attribLocations The locations of each attribute
627
631
  * @property {Object<string, function>} uniformSetters object of setters as returned from createUniformSetters,
628
632
  * @property {Object<string, function>} attribSetters object of setters as returned from createAttribSetters,
629
633
  * @property {UniformBlockSpec} [uniformBlockSpec] a uniform block spec for making UniformBlockInfos with createUniformBlockInfo etc..
@@ -632,6 +636,12 @@ export type UniformBlockInfo = {
632
636
  */
633
637
  export type ProgramInfo = {
634
638
  program: WebGLProgram;
639
+ uniformLocations: {
640
+ [key: string]: WebGLUniformLocation;
641
+ };
642
+ attribLocations: {
643
+ [key: string]: number;
644
+ };
635
645
  uniformSetters: {
636
646
  [key: string]: (...params: any[]) => any;
637
647
  };
@@ -830,6 +840,24 @@ export type CubemapReadyCallback = (err: any, tex: WebGLTexture, imgs: HTMLImage
830
840
  * @memberOf module:twgl
831
841
  */
832
842
  export type ThreeDReadyCallback = (err: any, tex: WebGLTexture, imgs: HTMLImageElement[]) => void;
843
+ /**
844
+ * Value returned by createTextureAsync
845
+ *
846
+ * @typedef {Object} CreateTextureInfo
847
+ * @param {WebGLTexture} texture the texture.
848
+ * @param {TextureSrc} source image(s) used to as the src for the texture
849
+ * @memberOf module:twgl
850
+ */
851
+ export type CreateTextureInfo = any;
852
+ /**
853
+ * Value returned by createTextureAsync
854
+ *
855
+ * @typedef {Object} CreateTexturesInfo
856
+ * @param {Object.<string, WebGLTexture>} textures the created textures by name. Same as returned by {@link createTextures}.
857
+ * @param {Object.<string, TextureSrc>} sources the image(s) used for the texture by name.
858
+ * @memberOf module:twgl
859
+ */
860
+ export type CreateTexturesInfo = any;
833
861
  /**
834
862
  * Check if context is WebGL 2.0
835
863
  * @param {WebGLRenderingContext} gl A WebGLRenderingContext
@@ -1191,13 +1219,13 @@ export function bindFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo?:
1191
1219
  * shaders or ids. The first is assumed to be the vertex shader,
1192
1220
  * the second the fragment shader.
1193
1221
  * @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
1194
- * @param {number[]} [opt_locations|ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
1222
+ * @param {number[]|ErrorCallback} [opt_locations] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
1195
1223
  * @param {ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
1196
1224
  * on error. If you want something else pass an callback. It's passed an error message.
1197
1225
  * @return {ProgramInfo?} The created ProgramInfo or null if it failed to link or compile
1198
1226
  * @memberOf module:twgl/programs
1199
1227
  */
1200
- export function createProgramInfo(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): ProgramInfo;
1228
+ export function createProgramInfo(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_locations?: number[] | ErrorCallback, opt_errorCallback?: ErrorCallback): ProgramInfo;
1201
1229
  /**
1202
1230
  * Creates a `UniformBlockInfo` for the specified block
1203
1231
  *
@@ -1211,10 +1239,11 @@ export function createProgramInfo(gl: WebGLRenderingContext, shaderSources: stri
1211
1239
  * @param {ProgramInfo} programInfo a `ProgramInfo`
1212
1240
  * as returned from {@link createProgramInfo}
1213
1241
  * @param {string} blockName The name of the block.
1242
+ * @param {UniformBlockInfoOptions} [options] Optional options for using existing an existing buffer and arrayBuffer
1214
1243
  * @return {UniformBlockInfo} The created UniformBlockInfo
1215
1244
  * @memberOf module:twgl/programs
1216
1245
  */
1217
- export function createUniformBlockInfo(gl: WebGL2RenderingContext, programInfo: ProgramInfo, blockName: string): UniformBlockInfo;
1246
+ export function createUniformBlockInfo(gl: WebGL2RenderingContext, programInfo: ProgramInfo, blockName: string, options?: UniformBlockInfoOptions): UniformBlockInfo;
1218
1247
  /**
1219
1248
  * Binds a uniform block to the matching uniform block point.
1220
1249
  * Matches by blocks by name so blocks must have the same name not just the same
@@ -1555,9 +1584,30 @@ export function setTextureFromArray(gl: WebGLRenderingContext, tex: WebGLTexture
1555
1584
  /**
1556
1585
  * Creates a texture based on the options passed in.
1557
1586
  *
1587
+ * See {@link TextureOptions}
1588
+ *
1558
1589
  * Note: may reset UNPACK_ALIGNMENT, UNPACK_ROW_LENGTH, UNPACK_IMAGE_HEIGHT, UNPACK_SKIP_IMAGES
1559
1590
  * UNPACK_SKIP_PIXELS, and UNPACK_SKIP_ROWS
1560
1591
  *
1592
+ * UNPACK_FLIP_Y_WEBGL, UNPACK_PREMULTIPLY_ALPHA_WEBGL, UNPACK_COLORSPACE_CONVERSION_WEBGL
1593
+ * are left as is though you can pass in options for flipY, premultiplyAlpha, and colorspaceConversion
1594
+ * to override them.
1595
+ *
1596
+ * As for the behavior of these settings
1597
+ *
1598
+ * ```js
1599
+ * gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
1600
+ * t1 = twgl.createTexture({src: someImage }); // flipped
1601
+ * t2 = twgl.createTexture({src: someImage, flipY: true }); // flipped
1602
+ * t3 = twgl.createTexture({src: someImage, flipY: false }); // not flipped
1603
+ * t4 = twgl.createTexture({src: someImage }); // flipped
1604
+ * ```
1605
+ *
1606
+ * * t1 is flipped because UNPACK_FLIP_Y_WEBGL is true
1607
+ * * t2 is flipped because it was requested
1608
+ * * t3 is not flipped because it was requested
1609
+ * * t4 is flipped because UNPACK_FLIP_Y_WEBGL has been restored to true
1610
+ *
1561
1611
  * @param {WebGLRenderingContext} gl the WebGLRenderingContext
1562
1612
  * @param {TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
1563
1613
  * @param {TextureReadyCallback} [callback] A callback called when an image has been downloaded and uploaded to the texture.
@@ -2106,13 +2156,13 @@ export type ProgramCallback = (err?: string, result?: WebGLProgram | ProgramInfo
2106
2156
  * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
2107
2157
  * @param {WebGLShader[]|string[]} shaders The shaders to attach, or element ids for their source, or strings that contain their source
2108
2158
  * @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
2109
- * @param {number[]} [opt_locations|ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2159
+ * @param {number[]|ErrorCallback} [opt_locations] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2110
2160
  * @param {ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
2111
2161
  * on error. If you want something else pass an callback. It's passed an error message.
2112
2162
  * @return {WebGLProgram?} the created program or null if error of a callback was provided.
2113
2163
  * @memberOf module:twgl/programs
2114
2164
  */
2115
- export function createProgram(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
2165
+ export function createProgram(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_locations?: number[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
2116
2166
  /**
2117
2167
  * Same as createProgram but returns a promise
2118
2168
  *
@@ -2127,13 +2177,13 @@ export function createProgram(gl: WebGLRenderingContext, shaders: WebGLShader[]
2127
2177
  * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
2128
2178
  * @param {WebGLShader[]|string[]} shaders The shaders to attach, or element ids for their source, or strings that contain their source
2129
2179
  * @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
2130
- * @param {number[]} [opt_locations|ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2180
+ * @param {number[]|ErrorCallback} [opt_locations] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2131
2181
  * @param {ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
2132
2182
  * on error. If you want something else pass an callback. It's passed an error message.
2133
2183
  * @return {Promise<WebGLProgram>} The created program
2134
2184
  * @memberOf module:twgl/programs
2135
2185
  */
2136
- export function createProgramAsync(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<WebGLProgram>;
2186
+ export function createProgramAsync(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_locations?: number[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<WebGLProgram>;
2137
2187
  /**
2138
2188
  * Same as createProgramInfo but returns a promise
2139
2189
  * @function
@@ -2143,13 +2193,13 @@ export function createProgramAsync(gl: WebGLRenderingContext, shaders: WebGLShad
2143
2193
  * shaders or ids. The first is assumed to be the vertex shader,
2144
2194
  * the second the fragment shader.
2145
2195
  * @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
2146
- * @param {number[]} [opt_locations|ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2196
+ * @param {number[]|ErrorCallback} [opt_locations] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2147
2197
  * @param {ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
2148
2198
  * on error. If you want something else pass an callback. It's passed an error message.
2149
2199
  * @return {Promise<ProgramInfo>} The created ProgramInfo
2150
2200
  * @memberOf module:twgl/programs
2151
2201
  */
2152
- export function createProgramInfoAsync(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<ProgramInfo>;
2202
+ export function createProgramInfoAsync(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_locations?: number[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<ProgramInfo>;
2153
2203
  /**
2154
2204
  * Creates a program from 2 script tags.
2155
2205
  *
@@ -2166,13 +2216,13 @@ export function createProgramInfoAsync(gl: WebGLRenderingContext, shaderSources:
2166
2216
  * tags for the shaders. The first is assumed to be the
2167
2217
  * vertex shader, the second the fragment shader.
2168
2218
  * @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
2169
- * @param {number[]} [opt_locations|ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2219
+ * @param {number[]|ErrorCallback} [opt_locations] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2170
2220
  * @param {ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
2171
2221
  * on error. If you want something else pass an callback. It's passed an error message.
2172
2222
  * @return {WebGLProgram?} the created program or null if error or a callback was provided.
2173
2223
  * @memberOf module:twgl/programs
2174
2224
  */
2175
- export function createProgramFromScripts(gl: WebGLRenderingContext, shaderScriptIds: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
2225
+ export function createProgramFromScripts(gl: WebGLRenderingContext, shaderScriptIds: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_locations?: number[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
2176
2226
  /**
2177
2227
  * Creates a program from 2 sources.
2178
2228
  *
@@ -2189,13 +2239,13 @@ export function createProgramFromScripts(gl: WebGLRenderingContext, shaderScript
2189
2239
  * shaders. The first is assumed to be the vertex shader,
2190
2240
  * the second the fragment shader.
2191
2241
  * @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
2192
- * @param {number[]} [opt_locations|ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2242
+ * @param {number[]|ErrorCallback} [opt_locations] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2193
2243
  * @param {ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
2194
2244
  * on error. If you want something else pass an callback. It's passed an error message.
2195
2245
  * @return {WebGLProgram?} the created program or null if error or a callback was provided.
2196
2246
  * @memberOf module:twgl/programs
2197
2247
  */
2198
- export function createProgramFromSources(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
2248
+ export function createProgramFromSources(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_locations?: number[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
2199
2249
  /**
2200
2250
  * Creates setter functions for all uniforms of a shader
2201
2251
  * program.
@@ -2222,6 +2272,20 @@ export function createUniformSetters(gl: WebGLRenderingContext, program: WebGLPr
2222
2272
  * @memberOf module:twgl/programs
2223
2273
  */
2224
2274
  export function createUniformBlockSpecFromProgram(gl: WebGL2RenderingContext, program: WebGLProgram): UniformBlockSpec;
2275
+ /**
2276
+ * Options to allow createUniformBlockInfo to use an existing buffer and arrayBuffer at an offset
2277
+ * @typedef {Object} UniformBlockInfoOptions
2278
+ * @property {ArrayBuffer} [array] an existing array buffer to use for values
2279
+ * @property {number} [offset] the offset in bytes to use in the array buffer (default = 0)
2280
+ * @property {WebGLBuffer} [buffer] the buffer to use for this uniform block info
2281
+ * @property {number} [bufferOffset] the offset in bytes in the buffer to use (default = use offset above)
2282
+ */
2283
+ export type UniformBlockInfoOptions = {
2284
+ array?: ArrayBuffer;
2285
+ offset?: number;
2286
+ buffer?: WebGLBuffer;
2287
+ bufferOffset?: number;
2288
+ };
2225
2289
  /**
2226
2290
  * Creates a `UniformBlockInfo` for the specified block
2227
2291
  *
@@ -2236,10 +2300,11 @@ export function createUniformBlockSpecFromProgram(gl: WebGL2RenderingContext, pr
2236
2300
  * @param {UniformBlockSpec} uniformBlockSpec. A UniformBlockSpec as returned
2237
2301
  * from {@link createUniformBlockSpecFromProgram}.
2238
2302
  * @param {string} blockName The name of the block.
2303
+ * @param {UniformBlockInfoOptions} [options] Optional options for using existing an existing buffer and arrayBuffer
2239
2304
  * @return {UniformBlockInfo} The created UniformBlockInfo
2240
2305
  * @memberOf module:twgl/programs
2241
2306
  */
2242
- export function createUniformBlockInfoFromProgram(gl: WebGL2RenderingContext, program: WebGLProgram, blockName: string): UniformBlockInfo;
2307
+ export function createUniformBlockInfoFromProgram(gl: WebGL2RenderingContext, program: WebGLProgram, blockName: string, options?: UniformBlockInfoOptions): UniformBlockInfo;
2243
2308
  /**
2244
2309
  * Creates a `UniformBlockInfo` for the specified block
2245
2310
  *
@@ -2253,10 +2318,11 @@ export function createUniformBlockInfoFromProgram(gl: WebGL2RenderingContext, pr
2253
2318
  * @param {ProgramInfo} programInfo a `ProgramInfo`
2254
2319
  * as returned from {@link createProgramInfo}
2255
2320
  * @param {string} blockName The name of the block.
2321
+ * @param {UniformBlockInfoOptions} [options] Optional options for using existing an existing buffer and arrayBuffer
2256
2322
  * @return {UniformBlockInfo} The created UniformBlockInfo
2257
2323
  * @memberOf module:twgl/programs
2258
2324
  */
2259
- export function createUniformBlockInfo(gl: WebGL2RenderingContext, programInfo: ProgramInfo, blockName: string): UniformBlockInfo;
2325
+ export function createUniformBlockInfo(gl: WebGL2RenderingContext, programInfo: ProgramInfo, blockName: string, options?: UniformBlockInfoOptions): UniformBlockInfo;
2260
2326
  /**
2261
2327
  * Binds a uniform block to the matching uniform block point.
2262
2328
  * Matches by blocks by name so blocks must have the same name not just the same
@@ -2651,13 +2717,13 @@ export function createProgramInfoFromProgram(gl: WebGLRenderingContext, program:
2651
2717
  * shaders or ids. The first is assumed to be the vertex shader,
2652
2718
  * the second the fragment shader.
2653
2719
  * @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
2654
- * @param {number[]} [opt_locations|ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2720
+ * @param {number[]|ErrorCallback} [opt_locations] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
2655
2721
  * @param {ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
2656
2722
  * on error. If you want something else pass an callback. It's passed an error message.
2657
2723
  * @return {ProgramInfo?} The created ProgramInfo or null if it failed to link or compile
2658
2724
  * @memberOf module:twgl/programs
2659
2725
  */
2660
- export function createProgramInfo(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): ProgramInfo;
2726
+ export function createProgramInfo(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_locations?: number[] | ErrorCallback, opt_errorCallback?: ErrorCallback): ProgramInfo;
2661
2727
  /**
2662
2728
  * Creates multiple programs
2663
2729
  *
@@ -2855,6 +2921,22 @@ export function getNumComponentsForFormat(format: number): number;
2855
2921
  * @memberOf module:twgl/textures
2856
2922
  */
2857
2923
  export function setDefaultTextureColor(color: number[]): void;
2924
+ /**
2925
+ * returns the property if set or the corresponding state if undefined
2926
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2927
+ * @param {TextureOptions} options
2928
+ * @param {string} property the name of the property to copy
2929
+ * @param {number} pname
2930
+ * @return {TextureOptions}
2931
+ */
2932
+ export function getPackStateOption(gl: WebGLRenderingContext, options: TextureOptions, property: string, pname: number): TextureOptions;
2933
+ /**
2934
+ * Copy the options object and apply pack state
2935
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2936
+ * @param {TextureOptions} options
2937
+ * @return {TextureOptions}
2938
+ */
2939
+ export function copyOptionsAndApplyPackState(gl: WebGLRenderingContext, options: TextureOptions): TextureOptions;
2858
2940
  /**
2859
2941
  * Sets the texture parameters of a texture.
2860
2942
  * @param {WebGLRenderingContext} gl the WebGLRenderingContext
@@ -2937,9 +3019,30 @@ export function setEmptyTexture(gl: WebGLRenderingContext, tex: WebGLTexture, op
2937
3019
  /**
2938
3020
  * Creates a texture based on the options passed in.
2939
3021
  *
3022
+ * See {@link TextureOptions}
3023
+ *
2940
3024
  * Note: may reset UNPACK_ALIGNMENT, UNPACK_ROW_LENGTH, UNPACK_IMAGE_HEIGHT, UNPACK_SKIP_IMAGES
2941
3025
  * UNPACK_SKIP_PIXELS, and UNPACK_SKIP_ROWS
2942
3026
  *
3027
+ * UNPACK_FLIP_Y_WEBGL, UNPACK_PREMULTIPLY_ALPHA_WEBGL, UNPACK_COLORSPACE_CONVERSION_WEBGL
3028
+ * are left as is though you can pass in options for flipY, premultiplyAlpha, and colorspaceConversion
3029
+ * to override them.
3030
+ *
3031
+ * As for the behavior of these settings
3032
+ *
3033
+ * ```js
3034
+ * gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
3035
+ * t1 = twgl.createTexture({src: someImage }); // flipped
3036
+ * t2 = twgl.createTexture({src: someImage, flipY: true }); // flipped
3037
+ * t3 = twgl.createTexture({src: someImage, flipY: false }); // not flipped
3038
+ * t4 = twgl.createTexture({src: someImage }); // flipped
3039
+ * ```
3040
+ *
3041
+ * * t1 is flipped because UNPACK_FLIP_Y_WEBGL is true
3042
+ * * t2 is flipped because it was requested
3043
+ * * t3 is not flipped because it was requested
3044
+ * * t4 is flipped because UNPACK_FLIP_Y_WEBGL has been restored to true
3045
+ *
2943
3046
  * @param {WebGLRenderingContext} gl the WebGLRenderingContext
2944
3047
  * @param {TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
2945
3048
  * @param {TextureReadyCallback} [callback] A callback called when an image has been downloaded and uploaded to the texture.
@@ -2947,6 +3050,22 @@ export function setEmptyTexture(gl: WebGLRenderingContext, tex: WebGLTexture, op
2947
3050
  * @memberOf module:twgl/textures
2948
3051
  */
2949
3052
  export function createTexture(gl: WebGLRenderingContext, options?: TextureOptions, callback?: TextureReadyCallback): WebGLTexture;
3053
+ /**
3054
+ * Creates a texture based on the options passed in.
3055
+ *
3056
+ * see {@link createTexture}.
3057
+ * The only difference is this function returns a promise
3058
+ * where as the other returns a texture and takes a callback.
3059
+ *
3060
+ * Note: this is here for completeness. It is probably better to use
3061
+ * the non-async version as it returns a usable texture immediately
3062
+ * where as this one you have to wait for it to load.
3063
+ *
3064
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
3065
+ * @param {TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
3066
+ * @return {Promise<CreateTextureInfo>} The created texture and source.
3067
+ */
3068
+ export function createTextureAsync(gl: WebGLRenderingContext, options?: TextureOptions): Promise<CreateTextureInfo>;
2950
3069
  /**
2951
3070
  * Resizes a texture based on the options passed in.
2952
3071
  *
@@ -3045,6 +3164,24 @@ export function createTextures(gl: WebGLRenderingContext, options: {
3045
3164
  }, callback?: TexturesReadyCallback): {
3046
3165
  [key: string]: WebGLTexture;
3047
3166
  };
3167
+ /**
3168
+ * Creates textures based on the options passed in.
3169
+ *
3170
+ * see {@link createTextures}.
3171
+ * The only difference is this function returns a promise
3172
+ * where as the other returns a texture and takes a callback.
3173
+ *
3174
+ * Note: this is here for completeness. It is probably better to use
3175
+ * the non-async version as it returns usable textures immediately
3176
+ * where as this one you have to wait for them to load.
3177
+ *
3178
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
3179
+ * @param {Object.<string,TextureOptions>} options A object of TextureOptions one per texture.
3180
+ * @return {Promise<CreateTexturesInfo>} The created textures and sources.
3181
+ */
3182
+ export function createTexturesAsync(gl: WebGLRenderingContext, options: {
3183
+ [key: string]: TextureOptions;
3184
+ }): Promise<CreateTexturesInfo>;
3048
3185
 
3049
3186
 
3050
3187
  /**