twgl.js 5.5.4 → 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 +1 -1
- package/dist/{5.x → 6.x}/twgl-full.d.ts +140 -3
- package/dist/{5.x → 6.x}/twgl-full.js +330 -137
- package/dist/{5.x → 6.x}/twgl-full.module.js +309 -130
- package/dist/{5.x → 6.x}/twgl.d.ts +140 -3
- package/dist/{5.x → 6.x}/twgl.js +330 -137
- package/package.json +9 -9
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/
|
|
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
|
|
@@ -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.
|
|
@@ -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
|
|
@@ -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
|
/**
|