diff --git a/blocks/waves/editor.scss b/blocks/waves/editor.scss
new file mode 100644
index 00000000..83f31785
--- /dev/null
+++ b/blocks/waves/editor.scss
@@ -0,0 +1,21 @@
+/* Editor styles */
+
+.wp-block-a8c-waves {
+ &__inner-container
+ > .block-editor-inner-blocks
+ > .block-editor-block-list__layout {
+ margin-left: 0;
+ margin-right: 0;
+ }
+
+ &__resize-container:not( .is-resizing ) {
+ // Important is used to have higher specificity than the inline style set by re-resizable library.
+ height: auto !important;
+ }
+
+ [data-align='left'] > &,
+ [data-align='right'] > & {
+ max-width: 290px;
+ width: 100%;
+ }
+}
diff --git a/blocks/waves/index.json b/blocks/waves/index.json
new file mode 100644
index 00000000..e1863049
--- /dev/null
+++ b/blocks/waves/index.json
@@ -0,0 +1 @@
+[ "twgl/twgl.js", "waves.js" ]
diff --git a/blocks/waves/index.php b/blocks/waves/index.php
new file mode 100644
index 00000000..a888541e
--- /dev/null
+++ b/blocks/waves/index.php
@@ -0,0 +1,31 @@
+ 'block-experiments',
+ 'style' => 'block-experiments',
+ 'editor_style' => 'block-experiments-editor',
+ 'render_callback' => function( $attribs, $content ) {
+ wp_enqueue_script( 'a8c-waves-js' );
+ return $content;
+ },
+ ] );
+ wp_register_script(
+ 'a8c-twgl-js',
+ plugins_url( 'twgl/twgl.js', __FILE__ ),
+ [], // no dependencies
+ filemtime( plugin_dir_path( __FILE__ ) . 'twgl/twgl.js' ),
+ true // in footer
+ );
+ wp_register_script(
+ 'a8c-waves-js',
+ plugins_url( 'waves.js', __FILE__ ),
+ [ 'a8c-twgl-js', 'wp-dom-ready' ],
+ filemtime( plugin_dir_path( __FILE__ ) . 'waves.js' ),
+ true // in footer
+ );
+} );
+
+add_action( 'enqueue_block_editor_assets', function() {
+ wp_enqueue_script( 'a8c-waves-js' );
+} );
diff --git a/blocks/waves/src/edit.js b/blocks/waves/src/edit.js
new file mode 100644
index 00000000..6152b07a
--- /dev/null
+++ b/blocks/waves/src/edit.js
@@ -0,0 +1,325 @@
+/**
+ * External dependencies
+ */
+import classnames from 'classnames';
+
+/**
+ * WordPress dependencies
+ */
+import {
+ InspectorControls,
+ PanelColorSettings,
+ InnerBlocks,
+ __experimentalUnitControl as UnitControl,
+} from '@wordpress/block-editor';
+import {
+ PanelBody,
+ RangeControl,
+ ResizableBox,
+ BaseControl,
+} from '@wordpress/components';
+import { useInstanceId } from '@wordpress/compose';
+import { useDispatch, useSelect } from '@wordpress/data';
+import { useState, useEffect, useRef } from '@wordpress/element';
+import { __ } from '@wordpress/i18n';
+
+const DEFAULT_COLORS = {
+ color1: '#000',
+ color2: '#555',
+ color3: '#AAA',
+ color4: '#FFF',
+};
+
+const MIN_HEIGHT = 50;
+
+const CSS_UNITS = [
+ { value: 'px', label: 'px', default: 430 },
+ { value: 'em', label: 'em', default: 20 },
+ { value: 'rem', label: 'rem', default: 20 },
+ { value: 'vw', label: 'vw', default: 20 },
+ { value: 'vh', label: 'vh', default: 50 },
+];
+
+const RESIZABLE_BOX_ENABLE_OPTION = {
+ top: false,
+ right: false,
+ bottom: true,
+ left: false,
+ topRight: false,
+ bottomRight: false,
+ bottomLeft: false,
+ topLeft: false,
+};
+
+function HeightInput( { onChange, onUnitChange, unit = 'px', value = '' } ) {
+ const [ temporaryInput, setTemporaryInput ] = useState( null );
+ const instanceId = useInstanceId( UnitControl );
+ const inputId = `a8c-waves-height-input-${ instanceId }`;
+ const isPx = unit === 'px';
+
+ const handleOnChange = ( unprocessedValue ) => {
+ const inputValue =
+ unprocessedValue !== ''
+ ? parseInt( unprocessedValue, 10 )
+ : undefined;
+
+ if ( isNaN( inputValue ) && inputValue !== undefined ) {
+ setTemporaryInput( unprocessedValue );
+ return;
+ }
+ setTemporaryInput( null );
+ onChange( inputValue );
+ };
+
+ const handleOnBlur = () => {
+ if ( temporaryInput !== null ) {
+ setTemporaryInput( null );
+ }
+ };
+
+ const inputValue = temporaryInput !== null ? temporaryInput : value;
+ const min = isPx ? MIN_HEIGHT : 0;
+
+ return (
+
+
+
+ );
+}
+
+function Edit( { attributes, className, isSelected, setAttributes } ) {
+ const { toggleSelection } = useDispatch( 'core/block-editor' );
+ const [ temporaryMinHeight, setTemporaryMinHeight ] = useState( null );
+ const [ isResizing, setIsResizing ] = useState( false );
+
+ const themeColors = useSelect(
+ ( select ) => select( 'core/block-editor' ).getSettings().colors,
+ []
+ );
+ const colors = {
+ color1:
+ attributes.color1 ||
+ themeColors[ 0 ].color ||
+ DEFAULT_COLORS.color1,
+ color2:
+ attributes.color2 ||
+ themeColors[ 0 ].color ||
+ DEFAULT_COLORS.color2,
+ color3:
+ attributes.color3 ||
+ themeColors[ 1 % themeColors.length ].color ||
+ DEFAULT_COLORS.color3,
+ color4:
+ attributes.color4 ||
+ themeColors[ 2 % themeColors.length ].color ||
+ DEFAULT_COLORS.color4,
+ };
+
+ const renderPreview = ( newAttributes = {} ) =>
+ window.a8cColorEffects.renderPreview( {
+ complexity: attributes.complexity,
+ mouseSpeed: 1,
+ fluidSpeed: 1,
+ ...colors,
+ ...newAttributes,
+ } );
+
+ useEffect( () => {
+ // Defaults need to be saved in the attributes because they are dynamic
+ // based on theme, and theme settings are not available from save.
+ Object.entries( colors ).forEach( ( [ key, value ] ) => {
+ if ( attributes[ key ] === undefined ) {
+ setAttributes( { [ key ]: value } );
+ }
+ } );
+
+ // Save the initial preview in the attributes
+ if ( attributes.previewImage === undefined ) {
+ const previewImage = renderPreview();
+ setAttributes( { previewImage } );
+ }
+ }, [] );
+
+ const minHeightWithUnit = attributes.minHeightUnit
+ ? `${ attributes.minHeight }${ attributes.minHeightUnit }`
+ : attributes.minHeight;
+ const style = {
+ minHeight: temporaryMinHeight || minHeightWithUnit || undefined,
+ backgroundImage: `url( "${ attributes.previewImage }" )`,
+ };
+
+ const canvasRef = useRef();
+ useEffect( () => {
+ return window.a8cColorEffects.run( canvasRef.current );
+ }, [ canvasRef.current ] );
+
+ return (
+ <>
+
+
+ {
+ const previewImage = renderPreview( {
+ complexity,
+ } );
+ setAttributes( { complexity, previewImage } );
+ } }
+ min={ 1 }
+ max={ 10 }
+ />
+
+ setAttributes( { mouseSpeed } )
+ }
+ min={ 1 }
+ max={ 100 }
+ />
+
+ setAttributes( { fluidSpeed } )
+ }
+ min={ 1 }
+ max={ 100 }
+ />
+
+ {
+ const previewImage = renderPreview( {
+ color1,
+ } );
+ setAttributes( { color1, previewImage } );
+ },
+ },
+ {
+ label: __( 'Color 2', 'waves' ),
+ value: colors.color2,
+ onChange: ( color2 ) => {
+ const previewImage = renderPreview( {
+ color2,
+ } );
+ setAttributes( { color2, previewImage } );
+ },
+ },
+ {
+ label: __( 'Color 3', 'waves' ),
+ value: colors.color3,
+ onChange: ( color3 ) => {
+ const previewImage = renderPreview( {
+ color3,
+ } );
+ setAttributes( { color3, previewImage } );
+ },
+ },
+ {
+ label: __( 'Color 4', 'waves' ),
+ value: colors.color4,
+ onChange: ( color4 ) => {
+ const previewImage = renderPreview( {
+ color4,
+ } );
+ setAttributes( { color4, previewImage } );
+ },
+ },
+ ] }
+ />
+
+
+ setAttributes( { minHeight } )
+ }
+ onUnitChange={ ( minHeightUnit ) =>
+ setAttributes( { minHeightUnit } )
+ }
+ />
+
+
+ {
+ toggleSelection( false );
+ setAttributes( { minHeightUnit: 'px' } );
+ setTemporaryMinHeight( elt.clientHeight );
+ } }
+ onResize={ ( event, direction, elt ) => {
+ // Setting is-resizing here instead of onResizeStart fixes
+ // an issue with the positioning of the resize bar when
+ // starting a resize after having resized smaller than the
+ // auto height
+ setIsResizing( true );
+ setTemporaryMinHeight( elt.clientHeight );
+ } }
+ onResizeStop={ ( event, direction, elt ) => {
+ toggleSelection( true );
+ setIsResizing( false );
+ setAttributes( { minHeight: elt.clientHeight } );
+ setTemporaryMinHeight( null );
+ } }
+ minHeight={ MIN_HEIGHT }
+ showHandle={ isSelected }
+ >
+
+
+ >
+ );
+}
+
+export default Edit;
diff --git a/blocks/waves/src/icon.js b/blocks/waves/src/icon.js
new file mode 100644
index 00000000..f6615da9
--- /dev/null
+++ b/blocks/waves/src/icon.js
@@ -0,0 +1,22 @@
+/**
+ * WordPress dependencies
+ */
+import { Path, SVG } from '@wordpress/components';
+
+const WavesIcon = ( props ) => {
+ return (
+
+ );
+};
+
+export default WavesIcon;
diff --git a/blocks/waves/src/index.js b/blocks/waves/src/index.js
new file mode 100644
index 00000000..55e7a7e7
--- /dev/null
+++ b/blocks/waves/src/index.js
@@ -0,0 +1,62 @@
+/**
+ * WordPress dependencies
+ */
+import { registerBlockType } from '@wordpress/blocks';
+import { __ } from '@wordpress/i18n';
+
+/**
+ * Internal dependencies
+ */
+import WavesIcon from './icon';
+import Edit from './edit';
+import Save from './save';
+
+export const registerBlock = () => {
+ registerBlockType( 'a8c/waves', {
+ title: __( 'Waves', 'waves' ),
+ description: __( 'Create content with waves in motion.', 'waves' ),
+ icon: ,
+ category: 'widgets',
+ supports: {
+ align: true,
+ html: false,
+ },
+ attributes: {
+ complexity: {
+ type: 'integer',
+ default: 2,
+ },
+ mouseSpeed: {
+ type: 'integer',
+ default: 20,
+ },
+ fluidSpeed: {
+ type: 'integer',
+ default: 20,
+ },
+ color1: {
+ type: 'string',
+ },
+ color2: {
+ type: 'string',
+ },
+ color3: {
+ type: 'string',
+ },
+ color4: {
+ type: 'string',
+ },
+ minHeight: {
+ type: 'number',
+ },
+ minHeightUnit: {
+ type: 'string',
+ },
+ previewImage: {
+ type: 'string',
+ },
+ },
+ edit: Edit,
+ save: Save,
+ } );
+};
diff --git a/blocks/waves/src/save.js b/blocks/waves/src/save.js
new file mode 100644
index 00000000..4ee82c43
--- /dev/null
+++ b/blocks/waves/src/save.js
@@ -0,0 +1,32 @@
+/**
+ * WordPress dependencies
+ */
+import { InnerBlocks } from '@wordpress/block-editor';
+
+const Save = ( { attributes } ) => {
+ const minHeightWithUnit = attributes.minHeightUnit
+ ? `${ attributes.minHeight }${ attributes.minHeightUnit }`
+ : attributes.minHeight;
+ const style = {
+ minHeight: minHeightWithUnit || undefined,
+ backgroundImage: `url( "${ attributes.previewImage }" )`,
+ };
+ return (
+
+ );
+};
+
+export default Save;
diff --git a/blocks/waves/style.scss b/blocks/waves/style.scss
new file mode 100644
index 00000000..d54a5519
--- /dev/null
+++ b/blocks/waves/style.scss
@@ -0,0 +1,55 @@
+/* Editor styles */
+
+.wp-block-a8c-waves {
+ position: relative;
+ min-height: 430px;
+ height: 100%;
+ width: 100%;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ overflow: hidden;
+
+ // Bottom left is consistent with how the WebGL behaves, so this will be the most similar to what is shown in the editor.
+ background: bottom left / cover no-repeat;
+
+ // Using flexbox without an assigned height property breaks vertical center alignment in IE11.
+ // Appending an empty ::after element tricks IE11 into giving the cover image an implicit height, which sidesteps this issue.
+ &::after {
+ display: block;
+ content: '';
+ font-size: 0;
+ min-height: inherit;
+
+ // IE doesn't support flex so omit that.
+ @supports ( position: sticky ) {
+ content: none;
+ }
+ }
+
+ &__inner-container {
+ width: calc( 100% - 70px );
+ padding: 2rem 0;
+ z-index: 1;
+ }
+
+ // Apply max-width to floated items that have no intrinsic width
+ &.alignleft,
+ &.alignright {
+ max-width: 290px;
+ width: 100%;
+ }
+
+ // Aligned cover blocks should not use our global alignment rules
+ &.aligncenter,
+ &.alignleft,
+ &.alignright {
+ display: flex;
+ }
+
+ canvas {
+ position: absolute;
+ width: 100%;
+ height: 100%;
+ }
+}
diff --git a/blocks/waves/twgl/twgl-full.d.ts b/blocks/waves/twgl/twgl-full.d.ts
new file mode 100755
index 00000000..98450f7c
--- /dev/null
+++ b/blocks/waves/twgl/twgl-full.d.ts
@@ -0,0 +1,502 @@
+
+export type Defaults = {
+ attribPrefix?: string;
+ textureColor?: number[];
+ crossOrigin?: string;
+ addExtensionsToContext?: boolean;
+};
+export function setDefaults(newDefaults: Defaults): void;
+export function addExtensionsToContext(gl: WebGLRenderingContext): void;
+export function getWebGLContext(canvas: HTMLCanvasElement, opt_attribs?: WebGLContextAttributes): WebGLRenderingContext;
+export function createContext(canvas: HTMLCanvasElement): WebGLRenderingContext;
+export function getContext(canvas: HTMLCanvasElement, opt_attribs?: WebGLContextAttributes): WebGLRenderingContext;
+export function resizeCanvasToDisplaySize(canvas: HTMLCanvasElement, multiplier?: number): boolean;
+export type AttribInfo = {
+ value?: number[] | ArrayBufferView;
+ numComponents?: number;
+ size?: number;
+ type?: number;
+ normalize?: boolean;
+ offset?: number;
+ stride?: number;
+ divisor?: number;
+ buffer: WebGLBuffer;
+ drawType?: number;
+};
+export type FullArraySpec = {
+ value?: number[] | ArrayBufferView;
+ data: number | number[] | ArrayBufferView;
+ numComponents?: number;
+ type?: Function;
+ size?: number;
+ normalize?: boolean;
+ stride?: number;
+ offset?: number;
+ divisor?: number;
+ attrib?: string;
+ name?: string;
+ attribName?: string;
+ buffer?: WebGLBuffer;
+};
+export type ArraySpec = number | number[] | ArrayBufferView | FullArraySpec;
+export type Arrays = {
+ [key: string]: ArraySpec;
+};
+export type BufferInfo = {
+ numElements: number;
+ elementType?: number;
+ indices?: WebGLBuffer;
+ attribs?: {
+ [key: string]: AttribInfo;
+ };
+};
+export type DrawObject = {
+ active?: boolean;
+ type?: number;
+ programInfo: ProgramInfo;
+ bufferInfo?: BufferInfo;
+ vertexArrayInfo?: VertexArrayInfo;
+ uniforms: {
+ [key: string]: any;
+ };
+ offset?: number;
+ count?: number;
+ instanceCount?: number;
+};
+export type AttachmentOptions = TextureOptions & {
+ attach?: number;
+ format?: number;
+ type?: number;
+ target?: number;
+ level?: number;
+ layer?: number;
+ attachment?: WebGLObject;
+};
+export type FramebufferInfo = {
+ framebuffer: WebGLFramebuffer;
+ attachments: WebGLObject[];
+ width: number;
+ height: number;
+};
+export type ErrorCallback = (msg: string, lineOffset?: number) => void;
+export type ProgramOptions = {
+ errorCallback?: (...params: any[]) => any;
+ attribLocations?: {
+ [key: string]: number;
+ };
+ transformFeedbackVaryings?: BufferInfo | {
+ [key: string]: AttribInfo;
+ } | string[];
+ transformFeedbackMode?: number;
+};
+export type TransformFeedbackInfo = {
+ index: number;
+ type: number;
+ size: number;
+};
+export function createTransformFeedbackInfo(gl: WebGLRenderingContext, program: WebGLProgram): {
+ [key: string]: TransformFeedbackInfo;
+};
+export function bindTransformFeedbackInfo(gl: WebGLRenderingContext, transformFeedbackInfo: ProgramInfo | {
+ [key: string]: TransformFeedbackInfo;
+}, bufferInfo?: BufferInfo | {
+ [key: string]: AttribInfo;
+}): void;
+export function createTransformFeedback(gl: WebGLRenderingContext, programInfo: ProgramInfo, bufferInfo?: BufferInfo | {
+ [key: string]: AttribInfo;
+}): WebGLTransformFeedback;
+export type UniformData = {
+ type: number;
+ size: number;
+ blockNdx: number;
+ offset: number;
+};
+export type BlockSpec = {
+ index: number;
+ size: number;
+ uniformIndices: number[];
+ usedByVertexShader: boolean;
+ usedByFragmentShader: boolean;
+ used: boolean;
+};
+export type UniformBlockSpec = {
+ uniformData: UniformData[];
+};
+export type UniformBlockInfo = {
+ name: string;
+ array: ArrayBuffer;
+ asFloat: Float32Array;
+ buffer: WebGLBuffer;
+ offset?: number;
+ uniforms: {
+ [key: string]: ArrayBufferView;
+ };
+};
+export type ProgramInfo = {
+ program: WebGLProgram;
+ uniformSetters: {
+ [key: string]: (...params: any[]) => any;
+ };
+ attribSetters: {
+ [key: string]: (...params: any[]) => any;
+ };
+ uniformBlockSpace?: UniformBlockSpec;
+ transformFeedbackInfo?: {
+ [key: string]: TransformFeedbackInfo;
+ };
+};
+export type TextureFunc = (gl: WebGLRenderingContext, options: TextureOptions) => any;
+export type TextureOptions = {
+ target?: number;
+ level?: number;
+ width?: number;
+ height?: number;
+ depth?: number;
+ min?: number;
+ mag?: number;
+ minMag?: number;
+ internalFormat?: number;
+ format?: number;
+ type?: number;
+ wrap?: number;
+ wrapS?: number;
+ wrapT?: number;
+ wrapR?: number;
+ minLod?: number;
+ maxLod?: number;
+ baseLevel?: number;
+ maxLevel?: number;
+ unpackAlignment?: number;
+ color?: number[] | ArrayBufferView;
+ premultiplyAlpha?: number;
+ flipY?: number;
+ colorspaceConversion?: number;
+ auto?: boolean;
+ cubeFaceOrder?: number[];
+ src?: number[] | ArrayBufferView | TexImageSource | TexImageSource[] | string | string[] | TextureFunc;
+ crossOrigin?: string;
+};
+export type TextureSrc = HTMLImageElement | HTMLImageElement[];
+export type TextureReadyCallback = (err: any, texture: WebGLTexture, source: TextureSrc) => void;
+export type TexturesReadyCallback = (err: any, textures: {
+ [key: string]: WebGLTexture;
+}, sources: {
+ [key: string]: TextureSrc;
+}) => void;
+export type CubemapReadyCallback = (err: any, tex: WebGLTexture, imgs: HTMLImageElement[]) => void;
+export type ThreeDReadyCallback = (err: any, tex: WebGLTexture, imgs: HTMLImageElement[]) => void;
+export function isWebGL2(gl: WebGLRenderingContext): boolean;
+export function isWebGL1(gl: WebGLRenderingContext): boolean;
+export function glEnumToString(gl: WebGLRenderingContext, value: number): string;
+export type VertexArrayInfo = {
+ numElements: number;
+ elementType?: number;
+ vertexArrayObject?: WebGLVertexArrayObject;
+};
+export function setAttribInfoBufferFromArray(gl: WebGLRenderingContext, attribInfo: AttribInfo, array: ArraySpec, offset?: number): void;
+export function createBufferInfoFromArrays(gl: WebGLRenderingContext, arrays: Arrays, srcBufferInfo?: BufferInfo): BufferInfo;
+export function drawBufferInfo(gl: WebGLRenderingContext, bufferInfo: BufferInfo | VertexArrayInfo, type?: number, count?: number, offset?: number, instanceCount?: number): void;
+export function drawObjectList(gl: WebGLRenderingContext, objectsToDraw: DrawObject[]): void;
+export function createFramebufferInfo(gl: WebGLRenderingContext, attachments?: AttachmentOptions[], width?: number, height?: number): FramebufferInfo;
+export function resizeFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo: FramebufferInfo, attachments?: AttachmentOptions[], width?: number, height?: number): void;
+export function bindFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo?: FramebufferInfo | null, target?: number): void;
+export function createProgramInfo(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): ProgramInfo;
+export function createUniformBlockInfo(gl: WebGL2RenderingContext, programInfo: ProgramInfo, blockName: string): UniformBlockInfo;
+export function bindUniformBlock(gl: WebGL2RenderingContext, programInfo: ProgramInfo | UniformBlockSpec, uniformBlockInfo: UniformBlockInfo): boolean;
+export function setUniformBlock(gl: WebGL2RenderingContext, programInfo: ProgramInfo | UniformBlockSpec, uniformBlockInfo: UniformBlockInfo): void;
+export function setBlockUniforms(uniformBlockInfo: UniformBlockInfo, values: {
+ [key: string]: any;
+}): void;
+export function setUniforms(setters: ProgramInfo | {
+ [key: string]: (...params: any[]) => any;
+}, values: {
+ [key: string]: any;
+}): void;
+export function setBuffersAndAttributes(gl: WebGLRenderingContext, setters: ProgramInfo | {
+ [key: string]: (...params: any[]) => any;
+}, buffers: BufferInfo | VertexArrayInfo): void;
+export function setTextureFromArray(gl: WebGLRenderingContext, tex: WebGLTexture, src: number[] | ArrayBufferView, options?: TextureOptions): void;
+export function createTexture(gl: WebGLRenderingContext, options?: TextureOptions, callback?: TextureReadyCallback): WebGLTexture;
+export function resizeTexture(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, width?: number, height?: number, depth?: number): void;
+export function createTextures(gl: WebGLRenderingContext, options: {
+ [key: string]: TextureOptions;
+}, callback?: TexturesReadyCallback): {
+ [key: string]: WebGLTexture;
+};
+
+
+export function setAttributePrefix(prefix: string): void;
+export function createBufferFromTypedArray(gl: WebGLRenderingContext, typedArray: ArrayBuffer | SharedArrayBuffer | ArrayBufferView | WebGLBuffer, type?: number, drawType?: number): WebGLBuffer;
+export function createAttribsFromArrays(gl: WebGLRenderingContext, arrays: Arrays, srcBufferInfo?: BufferInfo): {
+ [key: string]: AttribInfo;
+};
+export function setAttribInfoBufferFromArray(gl: WebGLRenderingContext, attribInfo: AttribInfo, array: ArraySpec, offset?: number): void;
+export function createBufferInfoFromArrays(gl: WebGLRenderingContext, arrays: Arrays, srcBufferInfo?: BufferInfo): BufferInfo;
+export function createBufferFromArray(gl: WebGLRenderingContext, array: ArraySpec, arrayName: string): WebGLBuffer;
+export function createBuffersFromArrays(gl: WebGLRenderingContext, arrays: Arrays): {
+ [key: string]: WebGLBuffer;
+};
+
+
+export function drawBufferInfo(gl: WebGLRenderingContext, bufferInfo: BufferInfo | VertexArrayInfo, type?: number, count?: number, offset?: number, instanceCount?: number): void;
+export function drawObjectList(gl: WebGLRenderingContext, objectsToDraw: DrawObject[]): void;
+
+
+export function createFramebufferInfo(gl: WebGLRenderingContext, attachments?: AttachmentOptions[], width?: number, height?: number): FramebufferInfo;
+export function resizeFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo: FramebufferInfo, attachments?: AttachmentOptions[], width?: number, height?: number): void;
+export function bindFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo?: FramebufferInfo | null, target?: number): void;
+
+
+export function getBindPointForSamplerType(): void;
+export function createProgram(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
+export function createProgramFromScripts(gl: WebGLRenderingContext, shaderScriptIds: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
+export function createProgramFromSources(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
+export function createUniformSetters(gl: WebGLRenderingContext, program: WebGLProgram): {
+ [key: string]: (...params: any[]) => any;
+};
+export function createUniformBlockSpecFromProgram(gl: WebGL2RenderingContext, program: WebGLProgram): UniformBlockSpec;
+export function createUniformBlockInfoFromProgram(gl: WebGL2RenderingContext, program: WebGLProgram, blockName: string): UniformBlockInfo;
+export function createUniformBlockInfo(gl: WebGL2RenderingContext, programInfo: ProgramInfo, blockName: string): UniformBlockInfo;
+export function bindUniformBlock(gl: WebGL2RenderingContext, programInfo: ProgramInfo | UniformBlockSpec, uniformBlockInfo: UniformBlockInfo): boolean;
+export function setUniformBlock(gl: WebGL2RenderingContext, programInfo: ProgramInfo | UniformBlockSpec, uniformBlockInfo: UniformBlockInfo): void;
+export function setBlockUniforms(uniformBlockInfo: UniformBlockInfo, values: {
+ [key: string]: any;
+}): void;
+export function setUniforms(setters: ProgramInfo | {
+ [key: string]: (...params: any[]) => any;
+}, values: {
+ [key: string]: any;
+}): void;
+export function setUniformsAndBindTextures(setters: ProgramInfo | {
+ [key: string]: (...params: any[]) => any;
+}, values: {
+ [key: string]: any;
+}): void;
+export function createAttributeSetters(gl: WebGLRenderingContext, program: WebGLProgram): {
+ [key: string]: (...params: any[]) => any;
+};
+export function setAttributes(setters: {
+ [key: string]: (...params: any[]) => any;
+}, buffers: {
+ [key: string]: AttribInfo;
+}): void;
+export function setBuffersAndAttributes(gl: WebGLRenderingContext, setters: ProgramInfo | {
+ [key: string]: (...params: any[]) => any;
+}, buffers: BufferInfo | VertexArrayInfo): void;
+export function createProgramInfoFromProgram(gl: WebGLRenderingContext, program: WebGLProgram): ProgramInfo;
+export function createProgramInfo(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): ProgramInfo;
+
+
+export function getBytesPerElementForInternalFormat(internalFormat: number, type: number): number;
+export type TextureFormatInfo = {
+ format: number;
+ type: number;
+};
+export function getFormatAndTypeForInternalFormat(internalFormat: number): TextureFormatInfo;
+export function canGenerateMipmap(gl: WebGLRenderingContext, width: number, height: number, internalFormat: number): boolean;
+export function canFilter(internalFormat: number): boolean;
+export function getNumComponentsForFormat(format: number): number;
+export function setDefaultTextureColor(color: number[]): void;
+export function setTextureParameters(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions): void;
+export function setSamplerParameters(gl: WebGLRenderingContext, sampler: WebGLSampler, options: TextureOptions): void;
+export function setTextureFilteringForSize(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions, width?: number, height?: number, internalFormat?: number): void;
+export function setTextureFromElement(gl: WebGLRenderingContext, tex: WebGLTexture, element: HTMLElement, options?: TextureOptions): void;
+export function setTextureTo1PixelColor(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions): void;
+export function loadTextureFromUrl(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions, callback?: TextureReadyCallback): HTMLImageElement;
+export function loadCubemapFromUrls(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, callback?: CubemapReadyCallback): void;
+export function loadSlicesFromUrls(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, callback?: ThreeDReadyCallback): void;
+export function setTextureFromArray(gl: WebGLRenderingContext, tex: WebGLTexture, src: number[] | ArrayBufferView, options?: TextureOptions): void;
+export function setEmptyTexture(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions): void;
+export function createTexture(gl: WebGLRenderingContext, options?: TextureOptions, callback?: TextureReadyCallback): WebGLTexture;
+export function resizeTexture(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, width?: number, height?: number, depth?: number): void;
+export function createTextures(gl: WebGLRenderingContext, options: {
+ [key: string]: TextureOptions;
+}, callback?: TexturesReadyCallback): {
+ [key: string]: WebGLTexture;
+};
+
+
+export function getGLTypeForTypedArray(typedArray: ArrayBufferView): number;
+export function getGLTypeForTypedArrayType(typedArrayType: ArrayBufferView): number;
+export function getTypedArrayTypeForGLType(type: number): (...params: any[]) => any;
+
+
+export function createVertexArrayInfo(gl: WebGLRenderingContext, programInfo: ProgramInfo | ProgramInfo[], bufferInfo: BufferInfo): VertexArrayInfo;
+export function createVAOAndSetAttributes(gl: WebGLRenderingContext, setters: {
+ [key: string]: (...params: any[]) => any;
+}, attribs: {
+ [key: string]: AttribInfo;
+}, indices?: WebGLBuffer): void;
+export function createVAOFromBufferInfo(gl: WebGLRenderingContext, programInfo: {
+ [key: string]: (...params: any[]) => any;
+} | ProgramInfo, bufferInfo: BufferInfo, indices?: WebGLBuffer): void;
+
+declare module v3 {
+ export type Vec3 = number[] | Float32Array;
+ export function setDefaultType(ctor: Function): Function;
+ export function create(x?: number, y?: number, z?: number): v3.Vec3;
+ export function add(a: v3.Vec3, b: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
+ export function subtract(a: v3.Vec3, b: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
+ export function lerp(a: v3.Vec3, b: v3.Vec3, t: number, dst?: v3.Vec3): v3.Vec3;
+ export function lerpV(a: v3.Vec3, b: v3.Vec3, t: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
+ export function max(a: v3.Vec3, b: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
+ export function min(a: v3.Vec3, b: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
+ export function mulScalar(v: v3.Vec3, k: number, dst?: v3.Vec3): v3.Vec3;
+ export function divScalar(v: v3.Vec3, k: number, dst?: v3.Vec3): v3.Vec3;
+ export function cross(a: v3.Vec3, b: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
+ export function dot(a: v3.Vec3, b: v3.Vec3): number;
+ export function length(v: v3.Vec3): number;
+ export function lengthSq(v: v3.Vec3): number;
+ export function distance(a: v3.Vec3, b: v3.Vec3): number;
+ export function distanceSq(a: v3.Vec3, b: v3.Vec3): number;
+ export function normalize(a: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
+ export function negate(v: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
+ export function copy(v: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
+ export function multiply(a: v3.Vec3, b: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
+ export function divide(a: v3.Vec3, b: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
+}
+declare module m4 {
+ export type Mat4 = number[] | Float32Array;
+ export function setDefaultType(ctor: Function): Function;
+ export function negate(m: m4.Mat4, dst?: m4.Mat4): m4.Mat4;
+ export function copy(m: m4.Mat4, dst?: m4.Mat4): m4.Mat4;
+ export function identity(dst?: m4.Mat4): m4.Mat4;
+ export function transpose(m: m4.Mat4, dst?: m4.Mat4): m4.Mat4;
+ export function inverse(m: m4.Mat4, dst?: m4.Mat4): m4.Mat4;
+ export function multiply(a: m4.Mat4, b: m4.Mat4, dst?: m4.Mat4): m4.Mat4;
+ export function setTranslation(a: m4.Mat4, v: v3.Vec3, dst?: m4.Mat4): m4.Mat4;
+ export function getTranslation(m: m4.Mat4, dst?: v3.Vec3): v3.Vec3;
+ export function getAxis(m: m4.Mat4, axis: number): void;
+ export function setAxis(m: m4.Mat4, v: v3.Vec3, axis: number, dst?: m4.Mat4): m4.Mat4;
+ export function perspective(fieldOfViewYInRadians: number, aspect: number, zNear: number, zFar: number, dst?: m4.Mat4): m4.Mat4;
+ export function ortho(left: number, right: number, bottom: number, top: number, near: number, far: number, dst?: m4.Mat4): m4.Mat4;
+ export function frustum(left: number, right: number, bottom: number, top: number, near: number, far: number, dst?: m4.Mat4): m4.Mat4;
+ export function lookAt(eye: v3.Vec3, target: v3.Vec3, up: v3.Vec3, dst?: m4.Mat4): m4.Mat4;
+ export function translation(v: v3.Vec3, dst?: m4.Mat4): m4.Mat4;
+ export function translate(m: m4.Mat4, v: v3.Vec3, dst?: m4.Mat4): m4.Mat4;
+ export function rotationX(angleInRadians: number, dst?: m4.Mat4): m4.Mat4;
+ export function rotateX(m: m4.Mat4, angleInRadians: number, dst?: m4.Mat4): m4.Mat4;
+ export function rotationY(angleInRadians: number, dst?: m4.Mat4): m4.Mat4;
+ export function rotateY(m: m4.Mat4, angleInRadians: number, dst?: m4.Mat4): m4.Mat4;
+ export function rotationZ(angleInRadians: number, dst?: m4.Mat4): m4.Mat4;
+ export function rotateZ(m: m4.Mat4, angleInRadians: number, dst?: m4.Mat4): m4.Mat4;
+ export function axisRotation(axis: v3.Vec3, angleInRadians: number, dst?: m4.Mat4): m4.Mat4;
+ export function axisRotate(m: m4.Mat4, axis: v3.Vec3, angleInRadians: number, dst?: m4.Mat4): m4.Mat4;
+ export function scaling(v: v3.Vec3, dst?: m4.Mat4): m4.Mat4;
+ export function scale(m: m4.Mat4, v: v3.Vec3, dst?: m4.Mat4): m4.Mat4;
+ export function transformPoint(m: m4.Mat4, v: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
+ export function transformDirection(m: m4.Mat4, v: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
+ export function transformNormal(m: m4.Mat4, v: v3.Vec3, dst?: v3.Vec3): v3.Vec3;
+}
+declare module primitives {
+ export type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array;
+ export function createAugmentedTypedArray(numComponents: number, numElements: number, opt_type: Function): ArrayBufferView;
+ export function deindexVertices(vertices: {
+ [key: string]: TypedArray;
+ }): {
+ [key: string]: TypedArray;
+ };
+ export function flattenNormals(vertices: {
+ [key: string]: TypedArray;
+ }): {
+ [key: string]: TypedArray;
+ };
+ export function reorientDirections(array: number[] | TypedArray, matrix: m4.Mat4): number[] | TypedArray;
+ export function reorientNormals(array: number[] | TypedArray, matrix: m4.Mat4): number[] | TypedArray;
+ export function reorientPositions(array: number[] | TypedArray, matrix: m4.Mat4): number[] | TypedArray;
+ export type NativeArrayOrTypedArray = number[] | TypedArray;
+ export function reorientVertices(arrays: {
+ [key: string]: NativeArrayOrTypedArray;
+ }, matrix: m4.Mat4): {
+ [key: string]: NativeArrayOrTypedArray;
+ };
+ export function createXYQuadBuffers(gl: WebGLRenderingContext, size?: number, xOffset?: number, yOffset?: number): {
+ [key: string]: WebGLBuffer;
+ };
+ export function createXYQuadBufferInfo(gl: WebGLRenderingContext, size?: number, xOffset?: number, yOffset?: number): BufferInfo;
+ export function createXYQuadVertices(size?: number, xOffset?: number, yOffset?: number): {
+ [key: string]: TypedArray;
+ };
+ export function createPlaneBufferInfo(gl: WebGLRenderingContext, width?: number, depth?: number, subdivisionsWidth?: number, subdivisionsDepth?: number, matrix?: m4.Mat4): BufferInfo;
+ export function createPlaneBuffers(gl: WebGLRenderingContext, width?: number, depth?: number, subdivisionsWidth?: number, subdivisionsDepth?: number, matrix?: m4.Mat4): {
+ [key: string]: WebGLBuffer;
+ };
+ export function createPlaneVertices(width?: number, depth?: number, subdivisionsWidth?: number, subdivisionsDepth?: number, matrix?: m4.Mat4): {
+ [key: string]: TypedArray;
+ };
+ export function createSphereBufferInfo(gl: WebGLRenderingContext, radius: number, subdivisionsAxis: number, subdivisionsHeight: number, opt_startLatitudeInRadians?: number, opt_endLatitudeInRadians?: number, opt_startLongitudeInRadians?: number, opt_endLongitudeInRadians?: number): BufferInfo;
+ export function createSphereBuffers(gl: WebGLRenderingContext, radius: number, subdivisionsAxis: number, subdivisionsHeight: number, opt_startLatitudeInRadians?: number, opt_endLatitudeInRadians?: number, opt_startLongitudeInRadians?: number, opt_endLongitudeInRadians?: number): {
+ [key: string]: WebGLBuffer;
+ };
+ export function createSphereVertices(radius: number, subdivisionsAxis: number, subdivisionsHeight: number, opt_startLatitudeInRadians?: number, opt_endLatitudeInRadians?: number, opt_startLongitudeInRadians?: number, opt_endLongitudeInRadians?: number): {
+ [key: string]: TypedArray;
+ };
+ export function createCubeBufferInfo(gl: WebGLRenderingContext, size?: number): BufferInfo;
+ export function createCubeBuffers(gl: WebGLRenderingContext, size?: number): {
+ [key: string]: WebGLBuffer;
+ };
+ export function createCubeVertices(size?: number): {
+ [key: string]: TypedArray;
+ };
+ export function createTruncatedConeBufferInfo(gl: WebGLRenderingContext, bottomRadius: number, topRadius: number, height: number, radialSubdivisions: number, verticalSubdivisions: number, opt_topCap?: boolean, opt_bottomCap?: boolean): BufferInfo;
+ export function createTruncatedConeBuffers(gl: WebGLRenderingContext, bottomRadius: number, topRadius: number, height: number, radialSubdivisions: number, verticalSubdivisions: number, opt_topCap?: boolean, opt_bottomCap?: boolean): {
+ [key: string]: WebGLBuffer;
+ };
+ export function createTruncatedConeVertices(bottomRadius: number, topRadius: number, height: number, radialSubdivisions: number, verticalSubdivisions: number, opt_topCap?: boolean, opt_bottomCap?: boolean): {
+ [key: string]: TypedArray;
+ };
+ export function create3DFBufferInfo(gl: WebGLRenderingContext): BufferInfo;
+ export function create3DFBuffers(gl: WebGLRenderingContext): {
+ [key: string]: WebGLBuffer;
+ };
+ export function create3DFVertices(): {
+ [key: string]: TypedArray;
+ };
+ export function createCresentBufferInfo(gl: WebGLRenderingContext, verticalRadius: number, outerRadius: number, innerRadius: number, thickness: number, subdivisionsDown: number, startOffset?: number, endOffset?: number): BufferInfo;
+ export function createCresentBuffers(gl: WebGLRenderingContext, verticalRadius: number, outerRadius: number, innerRadius: number, thickness: number, subdivisionsDown: number, startOffset?: number, endOffset?: number): {
+ [key: string]: WebGLBuffer;
+ };
+ export function createCresentBuffers(gl: WebGLRenderingContext, verticalRadius: number, outerRadius: number, innerRadius: number, thickness: number, subdivisionsDown: number, startOffset?: number, endOffset?: number): {
+ [key: string]: WebGLBuffer;
+ };
+ export function createCrescentBufferInfo(gl: WebGLRenderingContext, verticalRadius: number, outerRadius: number, innerRadius: number, thickness: number, subdivisionsDown: number, startOffset?: number, endOffset?: number): BufferInfo;
+ export function createCrescentBuffers(gl: WebGLRenderingContext, verticalRadius: number, outerRadius: number, innerRadius: number, thickness: number, subdivisionsDown: number, startOffset?: number, endOffset?: number): {
+ [key: string]: WebGLBuffer;
+ };
+ export function createCrescentVertices(verticalRadius: number, outerRadius: number, innerRadius: number, thickness: number, subdivisionsDown: number, startOffset?: number, endOffset?: number): {
+ [key: string]: TypedArray;
+ };
+ export function createCylinderBufferInfo(gl: WebGLRenderingContext, radius: number, height: number, radialSubdivisions: number, verticalSubdivisions: number, topCap?: boolean, bottomCap?: boolean): BufferInfo;
+ export function createCylinderBuffers(gl: WebGLRenderingContext, radius: number, height: number, radialSubdivisions: number, verticalSubdivisions: number, topCap?: boolean, bottomCap?: boolean): {
+ [key: string]: WebGLBuffer;
+ };
+ export function createCylinderVertices(radius: number, height: number, radialSubdivisions: number, verticalSubdivisions: number, topCap?: boolean, bottomCap?: boolean): {
+ [key: string]: TypedArray;
+ };
+ export function createTorusBufferInfo(gl: WebGLRenderingContext, radius: number, thickness: number, radialSubdivisions: number, bodySubdivisions: number, startAngle?: boolean, endAngle?: boolean): BufferInfo;
+ export function createTorusBuffers(gl: WebGLRenderingContext, radius: number, thickness: number, radialSubdivisions: number, bodySubdivisions: number, startAngle?: boolean, endAngle?: boolean): {
+ [key: string]: WebGLBuffer;
+ };
+ export function createTorusVertices(radius: number, thickness: number, radialSubdivisions: number, bodySubdivisions: number, startAngle?: boolean, endAngle?: boolean): {
+ [key: string]: TypedArray;
+ };
+ export function createDiscBufferInfo(gl: WebGLRenderingContext, radius: number, divisions: number, stacks?: number, innerRadius?: number, stackPower?: number): BufferInfo;
+ export function createDiscBuffers(gl: WebGLRenderingContext, radius: number, divisions: number, stacks?: number, innerRadius?: number, stackPower?: number): {
+ [key: string]: WebGLBuffer;
+ };
+ export function createDiscVertices(radius: number, divisions: number, stacks?: number, innerRadius?: number, stackPower?: number): {
+ [key: string]: TypedArray;
+ };
+ export type RandomColorFunc = (ndx: number, channel: number) => number;
+ export type RandomVerticesOptions = {
+ vertsPerColor?: number;
+ rand?: primitives.RandomColorFunc;
+ };
+ export function makeRandomVertexColors(vertices: {
+ [key: string]: ArrayBufferView;
+ }, options?: primitives.RandomVerticesOptions): {
+ [key: string]: ArrayBufferView;
+ };
+ export function concatVertices(arrays: Arrays[]): Arrays;
+ export function duplicateVertices(arrays: Arrays): Arrays;
+}
\ No newline at end of file
diff --git a/blocks/waves/twgl/twgl-full.js b/blocks/waves/twgl/twgl-full.js
new file mode 100755
index 00000000..8a84195b
--- /dev/null
+++ b/blocks/waves/twgl/twgl-full.js
@@ -0,0 +1,10591 @@
+/*!
+ * @license twgl.js 4.14.2 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
+ * Available via the MIT license.
+ * see: http://github.com/greggman/twgl.js for details
+ */
+(function webpackUniversalModuleDefinition(root, factory) {
+ if(typeof exports === 'object' && typeof module === 'object')
+ module.exports = factory();
+ else if(typeof define === 'function' && define.amd)
+ define([], factory);
+ else if(typeof exports === 'object')
+ exports["twgl"] = factory();
+ else
+ root["twgl"] = factory();
+})(typeof self !== 'undefined' ? self : this, function() {
+return /******/ (function(modules) { // webpackBootstrap
+/******/ // The module cache
+/******/ var installedModules = {};
+/******/
+/******/ // The require function
+/******/ function __webpack_require__(moduleId) {
+/******/
+/******/ // Check if module is in cache
+/******/ if(installedModules[moduleId]) {
+/******/ return installedModules[moduleId].exports;
+/******/ }
+/******/ // Create a new module (and put it into the cache)
+/******/ var module = installedModules[moduleId] = {
+/******/ i: moduleId,
+/******/ l: false,
+/******/ exports: {}
+/******/ };
+/******/
+/******/ // Execute the module function
+/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
+/******/
+/******/ // Flag the module as loaded
+/******/ module.l = true;
+/******/
+/******/ // Return the exports of the module
+/******/ return module.exports;
+/******/ }
+/******/
+/******/
+/******/ // expose the modules object (__webpack_modules__)
+/******/ __webpack_require__.m = modules;
+/******/
+/******/ // expose the module cache
+/******/ __webpack_require__.c = installedModules;
+/******/
+/******/ // define getter function for harmony exports
+/******/ __webpack_require__.d = function(exports, name, getter) {
+/******/ if(!__webpack_require__.o(exports, name)) {
+/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
+/******/ }
+/******/ };
+/******/
+/******/ // define __esModule on exports
+/******/ __webpack_require__.r = function(exports) {
+/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
+/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
+/******/ }
+/******/ Object.defineProperty(exports, '__esModule', { value: true });
+/******/ };
+/******/
+/******/ // create a fake namespace object
+/******/ // mode & 1: value is a module id, require it
+/******/ // mode & 2: merge all properties of value into the ns
+/******/ // mode & 4: return value when already ns object
+/******/ // mode & 8|1: behave like require
+/******/ __webpack_require__.t = function(value, mode) {
+/******/ if(mode & 1) value = __webpack_require__(value);
+/******/ if(mode & 8) return value;
+/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
+/******/ var ns = Object.create(null);
+/******/ __webpack_require__.r(ns);
+/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
+/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
+/******/ return ns;
+/******/ };
+/******/
+/******/ // getDefaultExport function for compatibility with non-harmony modules
+/******/ __webpack_require__.n = function(module) {
+/******/ var getter = module && module.__esModule ?
+/******/ function getDefault() { return module['default']; } :
+/******/ function getModuleExports() { return module; };
+/******/ __webpack_require__.d(getter, 'a', getter);
+/******/ return getter;
+/******/ };
+/******/
+/******/ // Object.prototype.hasOwnProperty.call
+/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
+/******/
+/******/ // __webpack_public_path__
+/******/ __webpack_require__.p = "";
+/******/
+/******/
+/******/ // Load entry module and return exports
+/******/ return __webpack_require__(__webpack_require__.s = "./src/twgl-full.js");
+/******/ })
+/************************************************************************/
+/******/ ({
+
+/***/ "./src/attributes.js":
+/*!***************************!*\
+ !*** ./src/attributes.js ***!
+ \***************************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.createAttribsFromArrays = createAttribsFromArrays;
+exports.createBuffersFromArrays = createBuffersFromArrays;
+exports.createBufferFromArray = createBufferFromArray;
+exports.createBufferFromTypedArray = createBufferFromTypedArray;
+exports.createBufferInfoFromArrays = createBufferInfoFromArrays;
+exports.setAttribInfoBufferFromArray = setAttribInfoBufferFromArray;
+exports.setAttributePrefix = setAttributePrefix;
+exports.setAttributeDefaults_ = setDefaults;
+exports.getNumComponents_ = getNumComponents;
+exports.getArray_ = getArray;
+
+var typedArrays = _interopRequireWildcard(__webpack_require__(/*! ./typedarrays.js */ "./src/typedarrays.js"));
+
+var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
+
+function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+var STATIC_DRAW = 0x88e4;
+var ARRAY_BUFFER = 0x8892;
+var ELEMENT_ARRAY_BUFFER = 0x8893;
+var BUFFER_SIZE = 0x8764;
+var BYTE = 0x1400;
+var UNSIGNED_BYTE = 0x1401;
+var SHORT = 0x1402;
+var UNSIGNED_SHORT = 0x1403;
+var INT = 0x1404;
+var UNSIGNED_INT = 0x1405;
+var FLOAT = 0x1406;
+/**
+ * Low level attribute and buffer related functions
+ *
+ * You should generally not need to use these functions. They are provided
+ * for those cases where you're doing something out of the ordinary
+ * and you need lower level access.
+ *
+ * For backward compatibility they are available at both `twgl.attributes` and `twgl`
+ * itself
+ *
+ * See {@link module:twgl} for core functions
+ *
+ * @module twgl/attributes
+ */
+// make sure we don't see a global gl
+
+var gl = undefined;
+/* eslint-disable-line */
+
+/* lgtm [js/unused-local-variable] */
+
+var defaults = {
+ attribPrefix: ""
+};
+/**
+ * Sets the default attrib prefix
+ *
+ * When writing shaders I prefer to name attributes with `a_`, uniforms with `u_` and varyings with `v_`
+ * as it makes it clear where they came from. But, when building geometry I prefer using un-prefixed names.
+ *
+ * In other words I'll create arrays of geometry like this
+ *
+ * var arrays = {
+ * position: ...
+ * normal: ...
+ * texcoord: ...
+ * };
+ *
+ * But need those mapped to attributes and my attributes start with `a_`.
+ *
+ * @deprecated see {@link module:twgl.setDefaults}
+ * @param {string} prefix prefix for attribs
+ * @memberOf module:twgl/attributes
+ */
+
+function setAttributePrefix(prefix) {
+ defaults.attribPrefix = prefix;
+}
+
+function setDefaults(newDefaults) {
+ helper.copyExistingProperties(newDefaults, defaults);
+}
+
+function setBufferFromTypedArray(gl, type, buffer, array, drawType) {
+ gl.bindBuffer(type, buffer);
+ gl.bufferData(type, array, drawType || STATIC_DRAW);
+}
+/**
+ * Given typed array creates a WebGLBuffer and copies the typed array
+ * into it.
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @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
+ * @param {number} [type] the GL bind type for the buffer. Default = `gl.ARRAY_BUFFER`.
+ * @param {number} [drawType] the GL draw type for the buffer. Default = 'gl.STATIC_DRAW`.
+ * @return {WebGLBuffer} the created WebGLBuffer
+ * @memberOf module:twgl/attributes
+ */
+
+
+function createBufferFromTypedArray(gl, typedArray, type, drawType) {
+ if (helper.isBuffer(gl, typedArray)) {
+ return typedArray;
+ }
+
+ type = type || ARRAY_BUFFER;
+ var buffer = gl.createBuffer();
+ setBufferFromTypedArray(gl, type, buffer, typedArray, drawType);
+ return buffer;
+}
+
+function isIndices(name) {
+ return name === "indices";
+} // This is really just a guess. Though I can't really imagine using
+// anything else? Maybe for some compression?
+
+
+function getNormalizationForTypedArray(typedArray) {
+ if (typedArray instanceof Int8Array) {
+ return true;
+ } // eslint-disable-line
+
+
+ if (typedArray instanceof Uint8Array) {
+ return true;
+ } // eslint-disable-line
+
+
+ return false;
+} // This is really just a guess. Though I can't really imagine using
+// anything else? Maybe for some compression?
+
+
+function getNormalizationForTypedArrayType(typedArrayType) {
+ if (typedArrayType === Int8Array) {
+ return true;
+ } // eslint-disable-line
+
+
+ if (typedArrayType === Uint8Array) {
+ return true;
+ } // eslint-disable-line
+
+
+ return false;
+}
+
+function getArray(array) {
+ return array.length ? array : array.data;
+}
+
+var texcoordRE = /coord|texture/i;
+var colorRE = /color|colour/i;
+
+function guessNumComponentsFromName(name, length) {
+ var numComponents;
+
+ if (texcoordRE.test(name)) {
+ numComponents = 2;
+ } else if (colorRE.test(name)) {
+ numComponents = 4;
+ } else {
+ numComponents = 3; // position, normals, indices ...
+ }
+
+ if (length % numComponents > 0) {
+ throw new Error("Can not guess numComponents for attribute '".concat(name, "'. Tried ").concat(numComponents, " but ").concat(length, " values is not evenly divisible by ").concat(numComponents, ". You should specify it."));
+ }
+
+ return numComponents;
+}
+
+function getNumComponents(array, arrayName) {
+ return array.numComponents || array.size || guessNumComponentsFromName(arrayName, getArray(array).length);
+}
+
+function makeTypedArray(array, name) {
+ if (typedArrays.isArrayBuffer(array)) {
+ return array;
+ }
+
+ if (typedArrays.isArrayBuffer(array.data)) {
+ return array.data;
+ }
+
+ if (Array.isArray(array)) {
+ array = {
+ data: array
+ };
+ }
+
+ var Type = array.type;
+
+ if (!Type) {
+ if (isIndices(name)) {
+ Type = Uint16Array;
+ } else {
+ Type = Float32Array;
+ }
+ }
+
+ return new Type(array.data);
+}
+/**
+ * The info for an attribute. This is effectively just the arguments to `gl.vertexAttribPointer` plus the WebGLBuffer
+ * for the attribute.
+ *
+ * @typedef {Object} AttribInfo
+ * @property {number[]|ArrayBufferView} [value] a constant value for the attribute. Note: if this is set the attribute will be
+ * disabled and set to this constant value and all other values will be ignored.
+ * @property {number} [numComponents] the number of components for this attribute.
+ * @property {number} [size] synonym for `numComponents`.
+ * @property {number} [type] the type of the attribute (eg. `gl.FLOAT`, `gl.UNSIGNED_BYTE`, etc...) Default = `gl.FLOAT`
+ * @property {boolean} [normalize] whether or not to normalize the data. Default = false
+ * @property {number} [offset] offset into buffer in bytes. Default = 0
+ * @property {number} [stride] the stride in bytes per element. Default = 0
+ * @property {number} [divisor] the divisor in instances. Default = undefined. Note: undefined = don't call gl.vertexAttribDivisor
+ * where as anything else = do call it with this value
+ * @property {WebGLBuffer} buffer the buffer that contains the data for this attribute
+ * @property {number} [drawType] the draw type passed to gl.bufferData. Default = gl.STATIC_DRAW
+ * @memberOf module:twgl
+ */
+
+/**
+ * Use this type of array spec when TWGL can't guess the type or number of components of an array
+ * @typedef {Object} FullArraySpec
+ * @property {number[]|ArrayBufferView} [value] a constant value for the attribute. Note: if this is set the attribute will be
+ * disabled and set to this constant value and all other values will be ignored.
+ * @property {(number|number[]|ArrayBufferView)} data The data of the array. A number alone becomes the number of elements of type.
+ * @property {number} [numComponents] number of components for `vertexAttribPointer`. Default is based on the name of the array.
+ * If `coord` is in the name assumes `numComponents = 2`.
+ * If `color` is in the name assumes `numComponents = 4`.
+ * otherwise assumes `numComponents = 3`
+ * @property {constructor} [type] type. This is only used if `data` is a JavaScript array. It is the constructor for the typedarray. (eg. `Uint8Array`).
+ * For example if you want colors in a `Uint8Array` you might have a `FullArraySpec` like `{ type: Uint8Array, data: [255,0,255,255, ...], }`.
+ * @property {number} [size] synonym for `numComponents`.
+ * @property {boolean} [normalize] normalize for `vertexAttribPointer`. Default is true if type is `Int8Array` or `Uint8Array` otherwise false.
+ * @property {number} [stride] stride for `vertexAttribPointer`. Default = 0
+ * @property {number} [offset] offset for `vertexAttribPointer`. Default = 0
+ * @property {number} [divisor] divisor for `vertexAttribDivisor`. Default = undefined. Note: undefined = don't call gl.vertexAttribDivisor
+ * where as anything else = do call it with this value
+ * @property {string} [attrib] name of attribute this array maps to. Defaults to same name as array prefixed by the default attribPrefix.
+ * @property {string} [name] synonym for `attrib`.
+ * @property {string} [attribName] synonym for `attrib`.
+ * @property {WebGLBuffer} [buffer] Buffer to use for this attribute. This lets you use your own buffer
+ * but you will need to supply `numComponents` and `type`. You can effectively pass an `AttribInfo`
+ * to provide this. Example:
+ *
+ * const bufferInfo1 = twgl.createBufferInfoFromArrays(gl, {
+ * position: [1, 2, 3, ... ],
+ * });
+ * const bufferInfo2 = twgl.createBufferInfoFromArrays(gl, {
+ * position: bufferInfo1.attribs.position, // use the same buffer from bufferInfo1
+ * });
+ *
+ * @memberOf module:twgl
+ */
+
+/**
+ * An individual array in {@link module:twgl.Arrays}
+ *
+ * When passed to {@link module:twgl.createBufferInfoFromArrays} if an ArraySpec is `number[]` or `ArrayBufferView`
+ * the types will be guessed based on the name. `indices` will be `Uint16Array`, everything else will
+ * be `Float32Array`. If an ArraySpec is a number it's the number of floats for an empty (zeroed) buffer.
+ *
+ * @typedef {(number|number[]|ArrayBufferView|module:twgl.FullArraySpec)} ArraySpec
+ * @memberOf module:twgl
+ */
+
+/**
+ * This is a JavaScript object of arrays by name. The names should match your shader's attributes. If your
+ * attributes have a common prefix you can specify it by calling {@link module:twgl.setAttributePrefix}.
+ *
+ * Bare JavaScript Arrays
+ *
+ * var arrays = {
+ * position: [-1, 1, 0],
+ * normal: [0, 1, 0],
+ * ...
+ * }
+ *
+ * Bare TypedArrays
+ *
+ * var arrays = {
+ * position: new Float32Array([-1, 1, 0]),
+ * color: new Uint8Array([255, 128, 64, 255]),
+ * ...
+ * }
+ *
+ * * Will guess at `numComponents` if not specified based on name.
+ *
+ * If `coord` is in the name assumes `numComponents = 2`
+ *
+ * If `color` is in the name assumes `numComponents = 4`
+ *
+ * otherwise assumes `numComponents = 3`
+ *
+ * Objects with various fields. See {@link module:twgl.FullArraySpec}.
+ *
+ * var arrays = {
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
+ * normal: { numComponents: 3, data: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], },
+ * indices: { numComponents: 3, data: [0, 1, 2, 1, 2, 3], },
+ * };
+ *
+ * @typedef {Object.} Arrays
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a set of attribute data and WebGLBuffers from set of arrays
+ *
+ * Given
+ *
+ * var arrays = {
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
+ * normal: { numComponents: 3, data: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], },
+ * color: { numComponents: 4, data: [255, 255, 255, 255, 255, 0, 0, 255, 0, 0, 255, 255], type: Uint8Array, },
+ * indices: { numComponents: 3, data: [0, 1, 2, 1, 2, 3], },
+ * };
+ *
+ * returns something like
+ *
+ * var attribs = {
+ * position: { numComponents: 3, type: gl.FLOAT, normalize: false, buffer: WebGLBuffer, },
+ * texcoord: { numComponents: 2, type: gl.FLOAT, normalize: false, buffer: WebGLBuffer, },
+ * normal: { numComponents: 3, type: gl.FLOAT, normalize: false, buffer: WebGLBuffer, },
+ * color: { numComponents: 4, type: gl.UNSIGNED_BYTE, normalize: true, buffer: WebGLBuffer, },
+ * };
+ *
+ * notes:
+ *
+ * * Arrays can take various forms
+ *
+ * Bare JavaScript Arrays
+ *
+ * var arrays = {
+ * position: [-1, 1, 0],
+ * normal: [0, 1, 0],
+ * ...
+ * }
+ *
+ * Bare TypedArrays
+ *
+ * var arrays = {
+ * position: new Float32Array([-1, 1, 0]),
+ * color: new Uint8Array([255, 128, 64, 255]),
+ * ...
+ * }
+ *
+ * * Will guess at `numComponents` if not specified based on name.
+ *
+ * If `coord` is in the name assumes `numComponents = 2`
+ *
+ * If `color` is in the name assumes `numComponents = 4`
+ *
+ * otherwise assumes `numComponents = 3`
+ *
+ * @param {WebGLRenderingContext} gl The webgl rendering context.
+ * @param {module:twgl.Arrays} arrays The arrays
+ * @param {module:twgl.BufferInfo} [srcBufferInfo] a BufferInfo to copy from
+ * This lets you share buffers. Any arrays you supply will override
+ * the buffers from srcBufferInfo.
+ * @return {Object.} the attribs
+ * @memberOf module:twgl/attributes
+ */
+
+
+function createAttribsFromArrays(gl, arrays) {
+ var attribs = {};
+ Object.keys(arrays).forEach(function (arrayName) {
+ if (!isIndices(arrayName)) {
+ var array = arrays[arrayName];
+ var attribName = array.attrib || array.name || array.attribName || defaults.attribPrefix + arrayName;
+
+ if (array.value) {
+ if (!Array.isArray(array.value) && !typedArrays.isArrayBuffer(array.value)) {
+ throw new Error('array.value is not array or typedarray');
+ }
+
+ attribs[attribName] = {
+ value: array.value
+ };
+ } else {
+ var buffer;
+ var type;
+ var normalization;
+ var numComponents;
+
+ if (array.buffer && array.buffer instanceof WebGLBuffer) {
+ buffer = array.buffer;
+ numComponents = array.numComponents || array.size;
+ type = array.type;
+ normalization = array.normalize;
+ } else if (typeof array === "number" || typeof array.data === "number") {
+ var numValues = array.data || array;
+ var arrayType = array.type || Float32Array;
+ var numBytes = numValues * arrayType.BYTES_PER_ELEMENT;
+ type = typedArrays.getGLTypeForTypedArrayType(arrayType);
+ normalization = array.normalize !== undefined ? array.normalize : getNormalizationForTypedArrayType(arrayType);
+ numComponents = array.numComponents || array.size || guessNumComponentsFromName(arrayName, numValues);
+ buffer = gl.createBuffer();
+ gl.bindBuffer(ARRAY_BUFFER, buffer);
+ gl.bufferData(ARRAY_BUFFER, numBytes, array.drawType || STATIC_DRAW);
+ } else {
+ var typedArray = makeTypedArray(array, arrayName);
+ buffer = createBufferFromTypedArray(gl, typedArray, undefined, array.drawType);
+ type = typedArrays.getGLTypeForTypedArray(typedArray);
+ normalization = array.normalize !== undefined ? array.normalize : getNormalizationForTypedArray(typedArray);
+ numComponents = getNumComponents(array, arrayName);
+ }
+
+ attribs[attribName] = {
+ buffer: buffer,
+ numComponents: numComponents,
+ type: type,
+ normalize: normalization,
+ stride: array.stride || 0,
+ offset: array.offset || 0,
+ divisor: array.divisor === undefined ? undefined : array.divisor,
+ drawType: array.drawType
+ };
+ }
+ }
+ });
+ gl.bindBuffer(ARRAY_BUFFER, null);
+ return attribs;
+}
+/**
+ * Sets the contents of a buffer attached to an attribInfo
+ *
+ * This is helper function to dynamically update a buffer.
+ *
+ * Let's say you make a bufferInfo
+ *
+ * var arrays = {
+ * position: new Float32Array([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]),
+ * texcoord: new Float32Array([0, 0, 0, 1, 1, 0, 1, 1]),
+ * normal: new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]),
+ * indices: new Uint16Array([0, 1, 2, 1, 2, 3]),
+ * };
+ * var bufferInfo = twgl.createBufferInfoFromArrays(gl, arrays);
+ *
+ * And you want to dynamically update the positions. You could do this
+ *
+ * // assuming arrays.position has already been updated with new data.
+ * twgl.setAttribInfoBufferFromArray(gl, bufferInfo.attribs.position, arrays.position);
+ *
+ * @param {WebGLRenderingContext} gl
+ * @param {AttribInfo} attribInfo The attribInfo who's buffer contents to set. NOTE: If you have an attribute prefix
+ * the name of the attribute will include the prefix.
+ * @param {ArraySpec} array Note: it is arguably inefficient to pass in anything but a typed array because anything
+ * else will have to be converted to a typed array before it can be used by WebGL. During init time that
+ * inefficiency is usually not important but if you're updating data dynamically best to be efficient.
+ * @param {number} [offset] an optional offset into the buffer. This is only an offset into the WebGL buffer
+ * not the array. To pass in an offset into the array itself use a typed array and create an `ArrayBufferView`
+ * for the portion of the array you want to use.
+ *
+ * var someArray = new Float32Array(1000); // an array with 1000 floats
+ * var someSubArray = new Float32Array(someArray.buffer, offsetInBytes, sizeInUnits); // a view into someArray
+ *
+ * Now you can pass `someSubArray` into setAttribInfoBufferFromArray`
+ * @memberOf module:twgl/attributes
+ */
+
+
+function setAttribInfoBufferFromArray(gl, attribInfo, array, offset) {
+ array = makeTypedArray(array);
+
+ if (offset !== undefined) {
+ gl.bindBuffer(ARRAY_BUFFER, attribInfo.buffer);
+ gl.bufferSubData(ARRAY_BUFFER, offset, array);
+ } else {
+ setBufferFromTypedArray(gl, ARRAY_BUFFER, attribInfo.buffer, array, attribInfo.drawType);
+ }
+}
+
+function getBytesPerValueForGLType(gl, type) {
+ if (type === BYTE) return 1; // eslint-disable-line
+
+ if (type === UNSIGNED_BYTE) return 1; // eslint-disable-line
+
+ if (type === SHORT) return 2; // eslint-disable-line
+
+ if (type === UNSIGNED_SHORT) return 2; // eslint-disable-line
+
+ if (type === INT) return 4; // eslint-disable-line
+
+ if (type === UNSIGNED_INT) return 4; // eslint-disable-line
+
+ if (type === FLOAT) return 4; // eslint-disable-line
+
+ return 0;
+} // Tries to get the number of elements from a set of arrays.
+
+
+var positionKeys = ['position', 'positions', 'a_position'];
+
+function getNumElementsFromNonIndexedArrays(arrays) {
+ var key;
+ var ii;
+
+ for (ii = 0; ii < positionKeys.length; ++ii) {
+ key = positionKeys[ii];
+
+ if (key in arrays) {
+ break;
+ }
+ }
+
+ if (ii === positionKeys.length) {
+ key = Object.keys(arrays)[0];
+ }
+
+ var array = arrays[key];
+ var length = getArray(array).length;
+ var numComponents = getNumComponents(array, key);
+ var numElements = length / numComponents;
+
+ if (length % numComponents > 0) {
+ throw new Error("numComponents ".concat(numComponents, " not correct for length ").concat(length));
+ }
+
+ return numElements;
+}
+
+function getNumElementsFromAttributes(gl, attribs) {
+ var key;
+ var ii;
+
+ for (ii = 0; ii < positionKeys.length; ++ii) {
+ key = positionKeys[ii];
+
+ if (key in attribs) {
+ break;
+ }
+
+ key = defaults.attribPrefix + key;
+
+ if (key in attribs) {
+ break;
+ }
+ }
+
+ if (ii === positionKeys.length) {
+ key = Object.keys(attribs)[0];
+ }
+
+ var attrib = attribs[key];
+ gl.bindBuffer(ARRAY_BUFFER, attrib.buffer);
+ var numBytes = gl.getBufferParameter(ARRAY_BUFFER, BUFFER_SIZE);
+ gl.bindBuffer(ARRAY_BUFFER, null);
+ var bytesPerValue = getBytesPerValueForGLType(gl, attrib.type);
+ var totalElements = numBytes / bytesPerValue;
+ var numComponents = attrib.numComponents || attrib.size; // TODO: check stride
+
+ var numElements = totalElements / numComponents;
+
+ if (numElements % 1 !== 0) {
+ throw new Error("numComponents ".concat(numComponents, " not correct for length ").concat(length));
+ }
+
+ return numElements;
+}
+/**
+ * @typedef {Object} BufferInfo
+ * @property {number} numElements The number of elements to pass to `gl.drawArrays` or `gl.drawElements`.
+ * @property {number} [elementType] The type of indices `UNSIGNED_BYTE`, `UNSIGNED_SHORT` etc..
+ * @property {WebGLBuffer} [indices] The indices `ELEMENT_ARRAY_BUFFER` if any indices exist.
+ * @property {Object.} [attribs] The attribs appropriate to call `setAttributes`
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a BufferInfo from an object of arrays.
+ *
+ * This can be passed to {@link module:twgl.setBuffersAndAttributes} and to
+ * {@link module:twgl:drawBufferInfo}.
+ *
+ * Given an object like
+ *
+ * var arrays = {
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
+ * normal: { numComponents: 3, data: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], },
+ * indices: { numComponents: 3, data: [0, 1, 2, 1, 2, 3], },
+ * };
+ *
+ * Creates an BufferInfo like this
+ *
+ * bufferInfo = {
+ * numElements: 4, // or whatever the number of elements is
+ * indices: WebGLBuffer, // this property will not exist if there are no indices
+ * attribs: {
+ * position: { buffer: WebGLBuffer, numComponents: 3, },
+ * normal: { buffer: WebGLBuffer, numComponents: 3, },
+ * texcoord: { buffer: WebGLBuffer, numComponents: 2, },
+ * },
+ * };
+ *
+ * The properties of arrays can be JavaScript arrays in which case the number of components
+ * will be guessed.
+ *
+ * var arrays = {
+ * position: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0],
+ * texcoord: [0, 0, 0, 1, 1, 0, 1, 1],
+ * normal: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],
+ * indices: [0, 1, 2, 1, 2, 3],
+ * };
+ *
+ * They can also be TypedArrays
+ *
+ * var arrays = {
+ * position: new Float32Array([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]),
+ * texcoord: new Float32Array([0, 0, 0, 1, 1, 0, 1, 1]),
+ * normal: new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]),
+ * indices: new Uint16Array([0, 1, 2, 1, 2, 3]),
+ * };
+ *
+ * Or AugmentedTypedArrays
+ *
+ * var positions = createAugmentedTypedArray(3, 4);
+ * var texcoords = createAugmentedTypedArray(2, 4);
+ * var normals = createAugmentedTypedArray(3, 4);
+ * var indices = createAugmentedTypedArray(3, 2, Uint16Array);
+ *
+ * positions.push([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]);
+ * texcoords.push([0, 0, 0, 1, 1, 0, 1, 1]);
+ * normals.push([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]);
+ * indices.push([0, 1, 2, 1, 2, 3]);
+ *
+ * var arrays = {
+ * position: positions,
+ * texcoord: texcoords,
+ * normal: normals,
+ * indices: indices,
+ * };
+ *
+ * For the last example it is equivalent to
+ *
+ * var bufferInfo = {
+ * attribs: {
+ * position: { numComponents: 3, buffer: gl.createBuffer(), },
+ * texcoord: { numComponents: 2, buffer: gl.createBuffer(), },
+ * normal: { numComponents: 3, buffer: gl.createBuffer(), },
+ * },
+ * indices: gl.createBuffer(),
+ * numElements: 6,
+ * };
+ *
+ * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.position.buffer);
+ * gl.bufferData(gl.ARRAY_BUFFER, arrays.position, gl.STATIC_DRAW);
+ * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.texcoord.buffer);
+ * gl.bufferData(gl.ARRAY_BUFFER, arrays.texcoord, gl.STATIC_DRAW);
+ * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.normal.buffer);
+ * gl.bufferData(gl.ARRAY_BUFFER, arrays.normal, gl.STATIC_DRAW);
+ * gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, bufferInfo.indices);
+ * gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, arrays.indices, gl.STATIC_DRAW);
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @param {module:twgl.Arrays} arrays Your data
+ * @param {module:twgl.BufferInfo} [srcBufferInfo] An existing
+ * buffer info to start from. WebGLBuffers etc specified
+ * in the srcBufferInfo will be used in a new BufferInfo
+ * with any arrays specified overriding the ones in
+ * srcBufferInfo.
+ * @return {module:twgl.BufferInfo} A BufferInfo
+ * @memberOf module:twgl/attributes
+ */
+
+
+function createBufferInfoFromArrays(gl, arrays, srcBufferInfo) {
+ var newAttribs = createAttribsFromArrays(gl, arrays);
+ var bufferInfo = Object.assign({}, srcBufferInfo ? srcBufferInfo : {});
+ bufferInfo.attribs = Object.assign({}, srcBufferInfo ? srcBufferInfo.attribs : {}, newAttribs);
+ var indices = arrays.indices;
+
+ if (indices) {
+ var newIndices = makeTypedArray(indices, "indices");
+ bufferInfo.indices = createBufferFromTypedArray(gl, newIndices, ELEMENT_ARRAY_BUFFER);
+ bufferInfo.numElements = newIndices.length;
+ bufferInfo.elementType = typedArrays.getGLTypeForTypedArray(newIndices);
+ } else if (!bufferInfo.numElements) {
+ bufferInfo.numElements = getNumElementsFromAttributes(gl, bufferInfo.attribs);
+ }
+
+ return bufferInfo;
+}
+/**
+ * Creates a buffer from an array, typed array, or array spec
+ *
+ * Given something like this
+ *
+ * [1, 2, 3],
+ *
+ * or
+ *
+ * new Uint16Array([1,2,3]);
+ *
+ * or
+ *
+ * {
+ * data: [1, 2, 3],
+ * type: Uint8Array,
+ * }
+ *
+ * returns a WebGLBuffer that contains the given data.
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext.
+ * @param {module:twgl.ArraySpec} array an array, typed array, or array spec.
+ * @param {string} arrayName name of array. Used to guess the type if type can not be derived otherwise.
+ * @return {WebGLBuffer} a WebGLBuffer containing the data in array.
+ * @memberOf module:twgl/attributes
+ */
+
+
+function createBufferFromArray(gl, array, arrayName) {
+ var type = arrayName === "indices" ? ELEMENT_ARRAY_BUFFER : ARRAY_BUFFER;
+ var typedArray = makeTypedArray(array, arrayName);
+ return createBufferFromTypedArray(gl, typedArray, type);
+}
+/**
+ * Creates buffers from arrays or typed arrays
+ *
+ * Given something like this
+ *
+ * var arrays = {
+ * positions: [1, 2, 3],
+ * normals: [0, 0, 1],
+ * }
+ *
+ * returns something like
+ *
+ * buffers = {
+ * positions: WebGLBuffer,
+ * normals: WebGLBuffer,
+ * }
+ *
+ * If the buffer is named 'indices' it will be made an ELEMENT_ARRAY_BUFFER.
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext.
+ * @param {module:twgl.Arrays} arrays
+ * @return {Object} returns an object with one WebGLBuffer per array
+ * @memberOf module:twgl/attributes
+ */
+
+
+function createBuffersFromArrays(gl, arrays) {
+ var buffers = {};
+ Object.keys(arrays).forEach(function (key) {
+ buffers[key] = createBufferFromArray(gl, arrays[key], key);
+ }); // Ugh!
+
+ if (arrays.indices) {
+ buffers.numElements = arrays.indices.length;
+ buffers.elementType = typedArrays.getGLTypeForTypedArray(makeTypedArray(arrays.indices), 'indices');
+ } else {
+ buffers.numElements = getNumElementsFromNonIndexedArrays(arrays);
+ }
+
+ return buffers;
+}
+
+/***/ }),
+
+/***/ "./src/draw.js":
+/*!*********************!*\
+ !*** ./src/draw.js ***!
+ \*********************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.drawBufferInfo = drawBufferInfo;
+exports.drawObjectList = drawObjectList;
+
+var programs = _interopRequireWildcard(__webpack_require__(/*! ./programs.js */ "./src/programs.js"));
+
+function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+var TRIANGLES = 0x0004;
+var UNSIGNED_SHORT = 0x1403;
+/**
+ * Drawing related functions
+ *
+ * For backward compatibility they are available at both `twgl.draw` and `twgl`
+ * itself
+ *
+ * See {@link module:twgl} for core functions
+ *
+ * @module twgl/draw
+ */
+
+/**
+ * Calls `gl.drawElements` or `gl.drawArrays`, whichever is appropriate
+ *
+ * normally you'd call `gl.drawElements` or `gl.drawArrays` yourself
+ * but calling this means if you switch from indexed data to non-indexed
+ * data you don't have to remember to update your draw call.
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @param {(module:twgl.BufferInfo|module:twgl.VertexArrayInfo)} bufferInfo A BufferInfo as returned from {@link module:twgl.createBufferInfoFromArrays} or
+ * a VertexArrayInfo as returned from {@link module:twgl.createVertexArrayInfo}
+ * @param {number} [type] eg (gl.TRIANGLES, gl.LINES, gl.POINTS, gl.TRIANGLE_STRIP, ...). Defaults to `gl.TRIANGLES`
+ * @param {number} [count] An optional count. Defaults to bufferInfo.numElements
+ * @param {number} [offset] An optional offset. Defaults to 0.
+ * @param {number} [instanceCount] An optional instanceCount. if set then `drawArraysInstanced` or `drawElementsInstanced` will be called
+ * @memberOf module:twgl/draw
+ */
+
+function drawBufferInfo(gl, bufferInfo, type, count, offset, instanceCount) {
+ type = type === undefined ? TRIANGLES : type;
+ var indices = bufferInfo.indices;
+ var elementType = bufferInfo.elementType;
+ var numElements = count === undefined ? bufferInfo.numElements : count;
+ offset = offset === undefined ? 0 : offset;
+
+ if (elementType || indices) {
+ if (instanceCount !== undefined) {
+ gl.drawElementsInstanced(type, numElements, elementType === undefined ? UNSIGNED_SHORT : bufferInfo.elementType, offset, instanceCount);
+ } else {
+ gl.drawElements(type, numElements, elementType === undefined ? UNSIGNED_SHORT : bufferInfo.elementType, offset);
+ }
+ } else {
+ if (instanceCount !== undefined) {
+ gl.drawArraysInstanced(type, offset, numElements, instanceCount);
+ } else {
+ gl.drawArrays(type, offset, numElements);
+ }
+ }
+}
+/**
+ * A DrawObject is useful for putting objects in to an array and passing them to {@link module:twgl.drawObjectList}.
+ *
+ * You need either a `BufferInfo` or a `VertexArrayInfo`.
+ *
+ * @typedef {Object} DrawObject
+ * @property {boolean} [active] whether or not to draw. Default = `true` (must be `false` to be not true). In other words `undefined` = `true`
+ * @property {number} [type] type to draw eg. `gl.TRIANGLES`, `gl.LINES`, etc...
+ * @property {module:twgl.ProgramInfo} programInfo A ProgramInfo as returned from {@link module:twgl.createProgramInfo}
+ * @property {module:twgl.BufferInfo} [bufferInfo] A BufferInfo as returned from {@link module:twgl.createBufferInfoFromArrays}
+ * @property {module:twgl.VertexArrayInfo} [vertexArrayInfo] A VertexArrayInfo as returned from {@link module:twgl.createVertexArrayInfo}
+ * @property {Object} uniforms The values for the uniforms.
+ * You can pass multiple objects by putting them in an array. For example
+ *
+ * var sharedUniforms = {
+ * u_fogNear: 10,
+ * u_projection: ...
+ * ...
+ * };
+ *
+ * var localUniforms = {
+ * u_world: ...
+ * u_diffuseColor: ...
+ * };
+ *
+ * var drawObj = {
+ * ...
+ * uniforms: [sharedUniforms, localUniforms],
+ * };
+ *
+ * @property {number} [offset] the offset to pass to `gl.drawArrays` or `gl.drawElements`. Defaults to 0.
+ * @property {number} [count] the count to pass to `gl.drawArrays` or `gl.drawElements`. Defaults to bufferInfo.numElements.
+ * @property {number} [instanceCount] the number of instances. Defaults to undefined.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Draws a list of objects
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @param {DrawObject[]} objectsToDraw an array of objects to draw.
+ * @memberOf module:twgl/draw
+ */
+
+
+function drawObjectList(gl, objectsToDraw) {
+ var lastUsedProgramInfo = null;
+ var lastUsedBufferInfo = null;
+ objectsToDraw.forEach(function (object) {
+ if (object.active === false) {
+ return;
+ }
+
+ var programInfo = object.programInfo;
+ var bufferInfo = object.vertexArrayInfo || object.bufferInfo;
+ var bindBuffers = false;
+ var type = object.type === undefined ? TRIANGLES : object.type;
+
+ if (programInfo !== lastUsedProgramInfo) {
+ lastUsedProgramInfo = programInfo;
+ gl.useProgram(programInfo.program); // We have to rebind buffers when changing programs because we
+ // only bind buffers the program uses. So if 2 programs use the same
+ // bufferInfo but the 1st one uses only positions the when the
+ // we switch to the 2nd one some of the attributes will not be on.
+
+ bindBuffers = true;
+ } // Setup all the needed attributes.
+
+
+ if (bindBuffers || bufferInfo !== lastUsedBufferInfo) {
+ if (lastUsedBufferInfo && lastUsedBufferInfo.vertexArrayObject && !bufferInfo.vertexArrayObject) {
+ gl.bindVertexArray(null);
+ }
+
+ lastUsedBufferInfo = bufferInfo;
+ programs.setBuffersAndAttributes(gl, programInfo, bufferInfo);
+ } // Set the uniforms.
+
+
+ programs.setUniforms(programInfo, object.uniforms); // Draw
+
+ drawBufferInfo(gl, bufferInfo, type, object.count, object.offset, object.instanceCount);
+ });
+
+ if (lastUsedBufferInfo && lastUsedBufferInfo.vertexArrayObject) {
+ gl.bindVertexArray(null);
+ }
+}
+
+/***/ }),
+
+/***/ "./src/framebuffers.js":
+/*!*****************************!*\
+ !*** ./src/framebuffers.js ***!
+ \*****************************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.bindFramebufferInfo = bindFramebufferInfo;
+exports.createFramebufferInfo = createFramebufferInfo;
+exports.resizeFramebufferInfo = resizeFramebufferInfo;
+
+var textures = _interopRequireWildcard(__webpack_require__(/*! ./textures.js */ "./src/textures.js"));
+
+var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
+
+function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * Framebuffer related functions
+ *
+ * For backward compatibility they are available at both `twgl.framebuffer` and `twgl`
+ * itself
+ *
+ * See {@link module:twgl} for core functions
+ *
+ * @module twgl/framebuffers
+ */
+// make sure we don't see a global gl
+var gl = undefined;
+/* eslint-disable-line */
+
+/* lgtm [js/unused-local-variable] */
+
+var FRAMEBUFFER = 0x8d40;
+var RENDERBUFFER = 0x8d41;
+var TEXTURE_2D = 0x0de1;
+var UNSIGNED_BYTE = 0x1401;
+/* PixelFormat */
+
+var DEPTH_COMPONENT = 0x1902;
+var RGBA = 0x1908;
+/* Framebuffer Object. */
+
+var RGBA4 = 0x8056;
+var RGB5_A1 = 0x8057;
+var RGB565 = 0x8D62;
+var DEPTH_COMPONENT16 = 0x81A5;
+var STENCIL_INDEX = 0x1901;
+var STENCIL_INDEX8 = 0x8D48;
+var DEPTH_STENCIL = 0x84F9;
+var COLOR_ATTACHMENT0 = 0x8CE0;
+var DEPTH_ATTACHMENT = 0x8D00;
+var STENCIL_ATTACHMENT = 0x8D20;
+var DEPTH_STENCIL_ATTACHMENT = 0x821A;
+/* TextureWrapMode */
+
+var REPEAT = 0x2901; // eslint-disable-line
+
+var CLAMP_TO_EDGE = 0x812F;
+var MIRRORED_REPEAT = 0x8370; // eslint-disable-line
+
+/* TextureMagFilter */
+
+var NEAREST = 0x2600; // eslint-disable-line
+
+var LINEAR = 0x2601;
+/* TextureMinFilter */
+
+var NEAREST_MIPMAP_NEAREST = 0x2700; // eslint-disable-line
+
+var LINEAR_MIPMAP_NEAREST = 0x2701; // eslint-disable-line
+
+var NEAREST_MIPMAP_LINEAR = 0x2702; // eslint-disable-line
+
+var LINEAR_MIPMAP_LINEAR = 0x2703; // eslint-disable-line
+
+/**
+ * The options for a framebuffer attachment.
+ *
+ * Note: For a `format` that is a texture include all the texture
+ * options from {@link module:twgl.TextureOptions} for example
+ * `min`, `mag`, `clamp`, etc... Note that unlike {@link module:twgl.TextureOptions}
+ * `auto` defaults to `false` for attachment textures but `min` and `mag` default
+ * to `gl.LINEAR` and `wrap` defaults to `CLAMP_TO_EDGE`
+ *
+ * @typedef {Object} AttachmentOptions
+ * @property {number} [attach] The attachment point. Defaults
+ * to `gl.COLOR_ATTACHMENT0 + ndx` unless type is a depth or stencil type
+ * then it's gl.DEPTH_ATTACHMENT or `gl.DEPTH_STENCIL_ATTACHMENT` depending
+ * on the format or attachment type.
+ * @property {number} [format] The format. If one of `gl.RGBA4`,
+ * `gl.RGB565`, `gl.RGB5_A1`, `gl.DEPTH_COMPONENT16`,
+ * `gl.STENCIL_INDEX8` or `gl.DEPTH_STENCIL` then will create a
+ * renderbuffer. Otherwise will create a texture. Default = `gl.RGBA`
+ * @property {number} [type] The type. Used for texture. Default = `gl.UNSIGNED_BYTE`.
+ * @property {number} [target] The texture target for `gl.framebufferTexture2D`.
+ * Defaults to `gl.TEXTURE_2D`. Set to appropriate face for cube maps.
+ * @property {number} [level] level for `gl.framebufferTexture2D`. Defaults to 0.
+ * @property {number} [layer] layer for `gl.framebufferTextureLayer`. Defaults to undefined.
+ * If set then `gl.framebufferTextureLayer` is called, if not then `gl.framebufferTexture2D`
+ * @property {WebGLObject} [attachment] An existing renderbuffer or texture.
+ * If provided will attach this Object. This allows you to share
+ * attachments across framebuffers.
+ * @memberOf module:twgl
+ * @mixes module:twgl.TextureOptions
+ */
+
+var defaultAttachments = [{
+ format: RGBA,
+ type: UNSIGNED_BYTE,
+ min: LINEAR,
+ wrap: CLAMP_TO_EDGE
+}, {
+ format: DEPTH_STENCIL
+}];
+var attachmentsByFormat = {};
+attachmentsByFormat[DEPTH_STENCIL] = DEPTH_STENCIL_ATTACHMENT;
+attachmentsByFormat[STENCIL_INDEX] = STENCIL_ATTACHMENT;
+attachmentsByFormat[STENCIL_INDEX8] = STENCIL_ATTACHMENT;
+attachmentsByFormat[DEPTH_COMPONENT] = DEPTH_ATTACHMENT;
+attachmentsByFormat[DEPTH_COMPONENT16] = DEPTH_ATTACHMENT;
+
+function getAttachmentPointForFormat(format) {
+ return attachmentsByFormat[format];
+}
+
+var renderbufferFormats = {};
+renderbufferFormats[RGBA4] = true;
+renderbufferFormats[RGB5_A1] = true;
+renderbufferFormats[RGB565] = true;
+renderbufferFormats[DEPTH_STENCIL] = true;
+renderbufferFormats[DEPTH_COMPONENT16] = true;
+renderbufferFormats[STENCIL_INDEX] = true;
+renderbufferFormats[STENCIL_INDEX8] = true;
+
+function isRenderbufferFormat(format) {
+ return renderbufferFormats[format];
+}
+/**
+ * @typedef {Object} FramebufferInfo
+ * @property {WebGLFramebuffer} framebuffer The WebGLFramebuffer for this framebufferInfo
+ * @property {WebGLObject[]} attachments The created attachments in the same order as passed in to {@link module:twgl.createFramebufferInfo}.
+ * @property {number} width The width of the framebuffer and its attachments
+ * @property {number} height The width of the framebuffer and its attachments
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a framebuffer and attachments.
+ *
+ * This returns a {@link module:twgl.FramebufferInfo} because it needs to return the attachments as well as the framebuffer.
+ *
+ * The simplest usage
+ *
+ * // create an RGBA/UNSIGNED_BYTE texture and DEPTH_STENCIL renderbuffer
+ * const fbi = twgl.createFramebufferInfo(gl);
+ *
+ * More complex usage
+ *
+ * // create an RGB565 renderbuffer and a STENCIL_INDEX8 renderbuffer
+ * const attachments = [
+ * { format: RGB565, mag: NEAREST },
+ * { format: STENCIL_INDEX8 },
+ * ]
+ * const fbi = twgl.createFramebufferInfo(gl, attachments);
+ *
+ * Passing in a specific size
+ *
+ * const width = 256;
+ * const height = 256;
+ * const fbi = twgl.createFramebufferInfo(gl, attachments, width, height);
+ *
+ * **Note!!** It is up to you to check if the framebuffer is renderable by calling `gl.checkFramebufferStatus`.
+ * [WebGL1 only guarantees 3 combinations of attachments work](https://www.khronos.org/registry/webgl/specs/latest/1.0/#6.6).
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.AttachmentOptions[]} [attachments] which attachments to create. If not provided the default is a framebuffer with an
+ * `RGBA`, `UNSIGNED_BYTE` texture `COLOR_ATTACHMENT0` and a `DEPTH_STENCIL` renderbuffer `DEPTH_STENCIL_ATTACHMENT`.
+ * @param {number} [width] the width for the attachments. Default = size of drawingBuffer
+ * @param {number} [height] the height for the attachments. Default = size of drawingBuffer
+ * @return {module:twgl.FramebufferInfo} the framebuffer and attachments.
+ * @memberOf module:twgl/framebuffers
+ */
+
+
+function createFramebufferInfo(gl, attachments, width, height) {
+ var target = FRAMEBUFFER;
+ var fb = gl.createFramebuffer();
+ gl.bindFramebuffer(target, fb);
+ width = width || gl.drawingBufferWidth;
+ height = height || gl.drawingBufferHeight;
+ attachments = attachments || defaultAttachments;
+ var colorAttachmentCount = 0;
+ var framebufferInfo = {
+ framebuffer: fb,
+ attachments: [],
+ width: width,
+ height: height
+ };
+ attachments.forEach(function (attachmentOptions) {
+ var attachment = attachmentOptions.attachment;
+ var format = attachmentOptions.format;
+ var attachmentPoint = getAttachmentPointForFormat(format);
+
+ if (!attachmentPoint) {
+ attachmentPoint = COLOR_ATTACHMENT0 + colorAttachmentCount++;
+ }
+
+ if (!attachment) {
+ if (isRenderbufferFormat(format)) {
+ attachment = gl.createRenderbuffer();
+ gl.bindRenderbuffer(RENDERBUFFER, attachment);
+ gl.renderbufferStorage(RENDERBUFFER, format, width, height);
+ } else {
+ var textureOptions = Object.assign({}, attachmentOptions);
+ textureOptions.width = width;
+ textureOptions.height = height;
+
+ if (textureOptions.auto === undefined) {
+ textureOptions.auto = false;
+ textureOptions.min = textureOptions.min || textureOptions.minMag || LINEAR;
+ textureOptions.mag = textureOptions.mag || textureOptions.minMag || LINEAR;
+ textureOptions.wrapS = textureOptions.wrapS || textureOptions.wrap || CLAMP_TO_EDGE;
+ textureOptions.wrapT = textureOptions.wrapT || textureOptions.wrap || CLAMP_TO_EDGE;
+ }
+
+ attachment = textures.createTexture(gl, textureOptions);
+ }
+ }
+
+ if (helper.isRenderbuffer(gl, attachment)) {
+ gl.framebufferRenderbuffer(target, attachmentPoint, RENDERBUFFER, attachment);
+ } else if (helper.isTexture(gl, attachment)) {
+ if (attachmentOptions.layer !== undefined) {
+ gl.framebufferTextureLayer(target, attachmentPoint, attachment, attachmentOptions.level || 0, attachmentOptions.layer);
+ } else {
+ gl.framebufferTexture2D(target, attachmentPoint, attachmentOptions.texTarget || TEXTURE_2D, attachment, attachmentOptions.level || 0);
+ }
+ } else {
+ throw new Error('unknown attachment type');
+ }
+
+ framebufferInfo.attachments.push(attachment);
+ });
+ return framebufferInfo;
+}
+/**
+ * Resizes the attachments of a framebuffer.
+ *
+ * You need to pass in the same `attachments` as you passed in {@link module:twgl.createFramebufferInfo}
+ * because TWGL has no idea the format/type of each attachment.
+ *
+ * The simplest usage
+ *
+ * // create an RGBA/UNSIGNED_BYTE texture and DEPTH_STENCIL renderbuffer
+ * const fbi = twgl.createFramebufferInfo(gl);
+ *
+ * ...
+ *
+ * function render() {
+ * if (twgl.resizeCanvasToDisplaySize(gl.canvas)) {
+ * // resize the attachments
+ * twgl.resizeFramebufferInfo(gl, fbi);
+ * }
+ *
+ * More complex usage
+ *
+ * // create an RGB565 renderbuffer and a STENCIL_INDEX8 renderbuffer
+ * const attachments = [
+ * { format: RGB565, mag: NEAREST },
+ * { format: STENCIL_INDEX8 },
+ * ]
+ * const fbi = twgl.createFramebufferInfo(gl, attachments);
+ *
+ * ...
+ *
+ * function render() {
+ * if (twgl.resizeCanvasToDisplaySize(gl.canvas)) {
+ * // resize the attachments to match
+ * twgl.resizeFramebufferInfo(gl, fbi, attachments);
+ * }
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.FramebufferInfo} framebufferInfo a framebufferInfo as returned from {@link module:twgl.createFramebufferInfo}.
+ * @param {module:twgl.AttachmentOptions[]} [attachments] the same attachments options as passed to {@link module:twgl.createFramebufferInfo}.
+ * @param {number} [width] the width for the attachments. Default = size of drawingBuffer
+ * @param {number} [height] the height for the attachments. Default = size of drawingBuffer
+ * @memberOf module:twgl/framebuffers
+ */
+
+
+function resizeFramebufferInfo(gl, framebufferInfo, attachments, width, height) {
+ width = width || gl.drawingBufferWidth;
+ height = height || gl.drawingBufferHeight;
+ framebufferInfo.width = width;
+ framebufferInfo.height = height;
+ attachments = attachments || defaultAttachments;
+ attachments.forEach(function (attachmentOptions, ndx) {
+ var attachment = framebufferInfo.attachments[ndx];
+ var format = attachmentOptions.format;
+
+ if (helper.isRenderbuffer(gl, attachment)) {
+ gl.bindRenderbuffer(RENDERBUFFER, attachment);
+ gl.renderbufferStorage(RENDERBUFFER, format, width, height);
+ } else if (helper.isTexture(gl, attachment)) {
+ textures.resizeTexture(gl, attachment, attachmentOptions, width, height);
+ } else {
+ throw new Error('unknown attachment type');
+ }
+ });
+}
+/**
+ * Binds a framebuffer
+ *
+ * This function pretty much solely exists because I spent hours
+ * trying to figure out why something I wrote wasn't working only
+ * to realize I forget to set the viewport dimensions.
+ * My hope is this function will fix that.
+ *
+ * It is effectively the same as
+ *
+ * gl.bindFramebuffer(gl.FRAMEBUFFER, someFramebufferInfo.framebuffer);
+ * gl.viewport(0, 0, someFramebufferInfo.width, someFramebufferInfo.height);
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.FramebufferInfo|null} [framebufferInfo] a framebufferInfo as returned from {@link module:twgl.createFramebufferInfo}.
+ * If falsy will bind the canvas.
+ * @param {number} [target] The target. If not passed `gl.FRAMEBUFFER` will be used.
+ * @memberOf module:twgl/framebuffers
+ */
+
+
+function bindFramebufferInfo(gl, framebufferInfo, target) {
+ target = target || FRAMEBUFFER;
+
+ if (framebufferInfo) {
+ gl.bindFramebuffer(target, framebufferInfo.framebuffer);
+ gl.viewport(0, 0, framebufferInfo.width, framebufferInfo.height);
+ } else {
+ gl.bindFramebuffer(target, null);
+ gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
+ }
+}
+
+/***/ }),
+
+/***/ "./src/helper.js":
+/*!***********************!*\
+ !*** ./src/helper.js ***!
+ \***********************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.copyExistingProperties = copyExistingProperties;
+exports.copyNamedProperties = copyNamedProperties;
+exports.error = error;
+exports.warn = warn;
+exports.isBuffer = isBuffer;
+exports.isRenderbuffer = isRenderbuffer;
+exports.isShader = isShader;
+exports.isTexture = isTexture;
+exports.isSampler = isSampler;
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/* eslint no-console: "off" */
+
+/**
+ * Copy named properties
+ *
+ * @param {string[]} names names of properties to copy
+ * @param {object} src object to copy properties from
+ * @param {object} dst object to copy properties to
+ * @private
+ */
+function copyNamedProperties(names, src, dst) {
+ names.forEach(function (name) {
+ var value = src[name];
+
+ if (value !== undefined) {
+ dst[name] = value;
+ }
+ });
+}
+/**
+ * Copies properties from source to dest only if a matching key is in dest
+ *
+ * @param {Object.} src the source
+ * @param {Object.} dst the dest
+ * @private
+ */
+
+
+function copyExistingProperties(src, dst) {
+ Object.keys(dst).forEach(function (key) {
+ if (dst.hasOwnProperty(key) && src.hasOwnProperty(key)) {
+ /* eslint no-prototype-builtins: 0 */
+ dst[key] = src[key];
+ }
+ });
+}
+
+function error() {
+ var _console;
+
+ (_console = console).error.apply(_console, arguments);
+}
+
+function warn() {
+ var _console2;
+
+ (_console2 = console).warn.apply(_console2, arguments);
+}
+
+function isBuffer(gl, t) {
+ return typeof WebGLBuffer !== 'undefined' && t instanceof WebGLBuffer;
+}
+
+function isRenderbuffer(gl, t) {
+ return typeof WebGLRenderbuffer !== 'undefined' && t instanceof WebGLRenderbuffer;
+}
+
+function isShader(gl, t) {
+ return typeof WebGLShader !== 'undefined' && t instanceof WebGLShader;
+}
+
+function isTexture(gl, t) {
+ return typeof WebGLTexture !== 'undefined' && t instanceof WebGLTexture;
+}
+
+function isSampler(gl, t) {
+ return typeof WebGLSampler !== 'undefined' && t instanceof WebGLSampler;
+}
+
+/***/ }),
+
+/***/ "./src/m4.js":
+/*!*******************!*\
+ !*** ./src/m4.js ***!
+ \*******************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.axisRotate = axisRotate;
+exports.axisRotation = axisRotation;
+exports.copy = copy;
+exports.frustum = frustum;
+exports.getAxis = getAxis;
+exports.getTranslation = getTranslation;
+exports.identity = identity;
+exports.inverse = inverse;
+exports.lookAt = lookAt;
+exports.multiply = multiply;
+exports.negate = negate;
+exports.ortho = ortho;
+exports.perspective = perspective;
+exports.rotateX = rotateX;
+exports.rotateY = rotateY;
+exports.rotateZ = rotateZ;
+exports.rotationX = rotationX;
+exports.rotationY = rotationY;
+exports.rotationZ = rotationZ;
+exports.scale = scale;
+exports.scaling = scaling;
+exports.setAxis = setAxis;
+exports.setDefaultType = setDefaultType;
+exports.setTranslation = setTranslation;
+exports.transformDirection = transformDirection;
+exports.transformNormal = transformNormal;
+exports.transformPoint = transformPoint;
+exports.translate = translate;
+exports.translation = translation;
+exports.transpose = transpose;
+
+var v3 = _interopRequireWildcard(__webpack_require__(/*! ./v3.js */ "./src/v3.js"));
+
+function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * 4x4 Matrix math math functions.
+ *
+ * Almost all functions take an optional `dst` argument. If it is not passed in the
+ * functions will create a new matrix. In other words you can do this
+ *
+ * const mat = m4.translation([1, 2, 3]); // Creates a new translation matrix
+ *
+ * or
+ *
+ * const mat = m4.create();
+ * m4.translation([1, 2, 3], mat); // Puts translation matrix in mat.
+ *
+ * The first style is often easier but depending on where it's used it generates garbage where
+ * as there is almost never allocation with the second style.
+ *
+ * It is always save to pass any matrix as the destination. So for example
+ *
+ * const mat = m4.identity();
+ * const trans = m4.translation([1, 2, 3]);
+ * m4.multiply(mat, trans, mat); // Multiplies mat * trans and puts result in mat.
+ *
+ * @module twgl/m4
+ */
+var MatType = Float32Array;
+/**
+ * A JavaScript array with 16 values or a Float32Array with 16 values.
+ * When created by the library will create the default type which is `Float32Array`
+ * but can be set by calling {@link module:twgl/m4.setDefaultType}.
+ * @typedef {(number[]|Float32Array)} Mat4
+ * @memberOf module:twgl/m4
+ */
+
+/**
+ * Sets the type this library creates for a Mat4
+ * @param {constructor} ctor the constructor for the type. Either `Float32Array` or `Array`
+ * @return {constructor} previous constructor for Mat4
+ * @memberOf module:twgl/m4
+ */
+
+function setDefaultType(ctor) {
+ var oldType = MatType;
+ MatType = ctor;
+ return oldType;
+}
+/**
+ * Negates a matrix.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} -m.
+ * @memberOf module:twgl/m4
+ */
+
+
+function negate(m, dst) {
+ dst = dst || new MatType(16);
+ dst[0] = -m[0];
+ dst[1] = -m[1];
+ dst[2] = -m[2];
+ dst[3] = -m[3];
+ dst[4] = -m[4];
+ dst[5] = -m[5];
+ dst[6] = -m[6];
+ dst[7] = -m[7];
+ dst[8] = -m[8];
+ dst[9] = -m[9];
+ dst[10] = -m[10];
+ dst[11] = -m[11];
+ dst[12] = -m[12];
+ dst[13] = -m[13];
+ dst[14] = -m[14];
+ dst[15] = -m[15];
+ return dst;
+}
+/**
+ * Copies a matrix.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/m4.Mat4} [dst] The matrix. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} A copy of m.
+ * @memberOf module:twgl/m4
+ */
+
+
+function copy(m, dst) {
+ dst = dst || new MatType(16);
+ dst[0] = m[0];
+ dst[1] = m[1];
+ dst[2] = m[2];
+ dst[3] = m[3];
+ dst[4] = m[4];
+ dst[5] = m[5];
+ dst[6] = m[6];
+ dst[7] = m[7];
+ dst[8] = m[8];
+ dst[9] = m[9];
+ dst[10] = m[10];
+ dst[11] = m[11];
+ dst[12] = m[12];
+ dst[13] = m[13];
+ dst[14] = m[14];
+ dst[15] = m[15];
+ return dst;
+}
+/**
+ * Creates an n-by-n identity matrix.
+ *
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} An n-by-n identity matrix.
+ * @memberOf module:twgl/m4
+ */
+
+
+function identity(dst) {
+ dst = dst || new MatType(16);
+ dst[0] = 1;
+ dst[1] = 0;
+ dst[2] = 0;
+ dst[3] = 0;
+ dst[4] = 0;
+ dst[5] = 1;
+ dst[6] = 0;
+ dst[7] = 0;
+ dst[8] = 0;
+ dst[9] = 0;
+ dst[10] = 1;
+ dst[11] = 0;
+ dst[12] = 0;
+ dst[13] = 0;
+ dst[14] = 0;
+ dst[15] = 1;
+ return dst;
+}
+/**
+ * Takes the transpose of a matrix.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The transpose of m.
+ * @memberOf module:twgl/m4
+ */
+
+
+function transpose(m, dst) {
+ dst = dst || new MatType(16);
+
+ if (dst === m) {
+ var t;
+ t = m[1];
+ m[1] = m[4];
+ m[4] = t;
+ t = m[2];
+ m[2] = m[8];
+ m[8] = t;
+ t = m[3];
+ m[3] = m[12];
+ m[12] = t;
+ t = m[6];
+ m[6] = m[9];
+ m[9] = t;
+ t = m[7];
+ m[7] = m[13];
+ m[13] = t;
+ t = m[11];
+ m[11] = m[14];
+ m[14] = t;
+ return dst;
+ }
+
+ var m00 = m[0 * 4 + 0];
+ var m01 = m[0 * 4 + 1];
+ var m02 = m[0 * 4 + 2];
+ var m03 = m[0 * 4 + 3];
+ var m10 = m[1 * 4 + 0];
+ var m11 = m[1 * 4 + 1];
+ var m12 = m[1 * 4 + 2];
+ var m13 = m[1 * 4 + 3];
+ var m20 = m[2 * 4 + 0];
+ var m21 = m[2 * 4 + 1];
+ var m22 = m[2 * 4 + 2];
+ var m23 = m[2 * 4 + 3];
+ var m30 = m[3 * 4 + 0];
+ var m31 = m[3 * 4 + 1];
+ var m32 = m[3 * 4 + 2];
+ var m33 = m[3 * 4 + 3];
+ dst[0] = m00;
+ dst[1] = m10;
+ dst[2] = m20;
+ dst[3] = m30;
+ dst[4] = m01;
+ dst[5] = m11;
+ dst[6] = m21;
+ dst[7] = m31;
+ dst[8] = m02;
+ dst[9] = m12;
+ dst[10] = m22;
+ dst[11] = m32;
+ dst[12] = m03;
+ dst[13] = m13;
+ dst[14] = m23;
+ dst[15] = m33;
+ return dst;
+}
+/**
+ * Computes the inverse of a 4-by-4 matrix.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The inverse of m.
+ * @memberOf module:twgl/m4
+ */
+
+
+function inverse(m, dst) {
+ dst = dst || new MatType(16);
+ var m00 = m[0 * 4 + 0];
+ var m01 = m[0 * 4 + 1];
+ var m02 = m[0 * 4 + 2];
+ var m03 = m[0 * 4 + 3];
+ var m10 = m[1 * 4 + 0];
+ var m11 = m[1 * 4 + 1];
+ var m12 = m[1 * 4 + 2];
+ var m13 = m[1 * 4 + 3];
+ var m20 = m[2 * 4 + 0];
+ var m21 = m[2 * 4 + 1];
+ var m22 = m[2 * 4 + 2];
+ var m23 = m[2 * 4 + 3];
+ var m30 = m[3 * 4 + 0];
+ var m31 = m[3 * 4 + 1];
+ var m32 = m[3 * 4 + 2];
+ var m33 = m[3 * 4 + 3];
+ var tmp_0 = m22 * m33;
+ var tmp_1 = m32 * m23;
+ var tmp_2 = m12 * m33;
+ var tmp_3 = m32 * m13;
+ var tmp_4 = m12 * m23;
+ var tmp_5 = m22 * m13;
+ var tmp_6 = m02 * m33;
+ var tmp_7 = m32 * m03;
+ var tmp_8 = m02 * m23;
+ var tmp_9 = m22 * m03;
+ var tmp_10 = m02 * m13;
+ var tmp_11 = m12 * m03;
+ var tmp_12 = m20 * m31;
+ var tmp_13 = m30 * m21;
+ var tmp_14 = m10 * m31;
+ var tmp_15 = m30 * m11;
+ var tmp_16 = m10 * m21;
+ var tmp_17 = m20 * m11;
+ var tmp_18 = m00 * m31;
+ var tmp_19 = m30 * m01;
+ var tmp_20 = m00 * m21;
+ var tmp_21 = m20 * m01;
+ var tmp_22 = m00 * m11;
+ var tmp_23 = m10 * m01;
+ var t0 = tmp_0 * m11 + tmp_3 * m21 + tmp_4 * m31 - (tmp_1 * m11 + tmp_2 * m21 + tmp_5 * m31);
+ var t1 = tmp_1 * m01 + tmp_6 * m21 + tmp_9 * m31 - (tmp_0 * m01 + tmp_7 * m21 + tmp_8 * m31);
+ var t2 = tmp_2 * m01 + tmp_7 * m11 + tmp_10 * m31 - (tmp_3 * m01 + tmp_6 * m11 + tmp_11 * m31);
+ var t3 = tmp_5 * m01 + tmp_8 * m11 + tmp_11 * m21 - (tmp_4 * m01 + tmp_9 * m11 + tmp_10 * m21);
+ var d = 1.0 / (m00 * t0 + m10 * t1 + m20 * t2 + m30 * t3);
+ dst[0] = d * t0;
+ dst[1] = d * t1;
+ dst[2] = d * t2;
+ dst[3] = d * t3;
+ dst[4] = d * (tmp_1 * m10 + tmp_2 * m20 + tmp_5 * m30 - (tmp_0 * m10 + tmp_3 * m20 + tmp_4 * m30));
+ dst[5] = d * (tmp_0 * m00 + tmp_7 * m20 + tmp_8 * m30 - (tmp_1 * m00 + tmp_6 * m20 + tmp_9 * m30));
+ dst[6] = d * (tmp_3 * m00 + tmp_6 * m10 + tmp_11 * m30 - (tmp_2 * m00 + tmp_7 * m10 + tmp_10 * m30));
+ dst[7] = d * (tmp_4 * m00 + tmp_9 * m10 + tmp_10 * m20 - (tmp_5 * m00 + tmp_8 * m10 + tmp_11 * m20));
+ dst[8] = d * (tmp_12 * m13 + tmp_15 * m23 + tmp_16 * m33 - (tmp_13 * m13 + tmp_14 * m23 + tmp_17 * m33));
+ dst[9] = d * (tmp_13 * m03 + tmp_18 * m23 + tmp_21 * m33 - (tmp_12 * m03 + tmp_19 * m23 + tmp_20 * m33));
+ dst[10] = d * (tmp_14 * m03 + tmp_19 * m13 + tmp_22 * m33 - (tmp_15 * m03 + tmp_18 * m13 + tmp_23 * m33));
+ dst[11] = d * (tmp_17 * m03 + tmp_20 * m13 + tmp_23 * m23 - (tmp_16 * m03 + tmp_21 * m13 + tmp_22 * m23));
+ dst[12] = d * (tmp_14 * m22 + tmp_17 * m32 + tmp_13 * m12 - (tmp_16 * m32 + tmp_12 * m12 + tmp_15 * m22));
+ dst[13] = d * (tmp_20 * m32 + tmp_12 * m02 + tmp_19 * m22 - (tmp_18 * m22 + tmp_21 * m32 + tmp_13 * m02));
+ dst[14] = d * (tmp_18 * m12 + tmp_23 * m32 + tmp_15 * m02 - (tmp_22 * m32 + tmp_14 * m02 + tmp_19 * m12));
+ dst[15] = d * (tmp_22 * m22 + tmp_16 * m02 + tmp_21 * m12 - (tmp_20 * m12 + tmp_23 * m22 + tmp_17 * m02));
+ return dst;
+}
+/**
+ * Multiplies two 4-by-4 matrices with a on the left and b on the right
+ * @param {module:twgl/m4.Mat4} a The matrix on the left.
+ * @param {module:twgl/m4.Mat4} b The matrix on the right.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The matrix product of a and b.
+ * @memberOf module:twgl/m4
+ */
+
+
+function multiply(a, b, dst) {
+ dst = dst || new MatType(16);
+ var a00 = a[0];
+ var a01 = a[1];
+ var a02 = a[2];
+ var a03 = a[3];
+ var a10 = a[4 + 0];
+ var a11 = a[4 + 1];
+ var a12 = a[4 + 2];
+ var a13 = a[4 + 3];
+ var a20 = a[8 + 0];
+ var a21 = a[8 + 1];
+ var a22 = a[8 + 2];
+ var a23 = a[8 + 3];
+ var a30 = a[12 + 0];
+ var a31 = a[12 + 1];
+ var a32 = a[12 + 2];
+ var a33 = a[12 + 3];
+ var b00 = b[0];
+ var b01 = b[1];
+ var b02 = b[2];
+ var b03 = b[3];
+ var b10 = b[4 + 0];
+ var b11 = b[4 + 1];
+ var b12 = b[4 + 2];
+ var b13 = b[4 + 3];
+ var b20 = b[8 + 0];
+ var b21 = b[8 + 1];
+ var b22 = b[8 + 2];
+ var b23 = b[8 + 3];
+ var b30 = b[12 + 0];
+ var b31 = b[12 + 1];
+ var b32 = b[12 + 2];
+ var b33 = b[12 + 3];
+ dst[0] = a00 * b00 + a10 * b01 + a20 * b02 + a30 * b03;
+ dst[1] = a01 * b00 + a11 * b01 + a21 * b02 + a31 * b03;
+ dst[2] = a02 * b00 + a12 * b01 + a22 * b02 + a32 * b03;
+ dst[3] = a03 * b00 + a13 * b01 + a23 * b02 + a33 * b03;
+ dst[4] = a00 * b10 + a10 * b11 + a20 * b12 + a30 * b13;
+ dst[5] = a01 * b10 + a11 * b11 + a21 * b12 + a31 * b13;
+ dst[6] = a02 * b10 + a12 * b11 + a22 * b12 + a32 * b13;
+ dst[7] = a03 * b10 + a13 * b11 + a23 * b12 + a33 * b13;
+ dst[8] = a00 * b20 + a10 * b21 + a20 * b22 + a30 * b23;
+ dst[9] = a01 * b20 + a11 * b21 + a21 * b22 + a31 * b23;
+ dst[10] = a02 * b20 + a12 * b21 + a22 * b22 + a32 * b23;
+ dst[11] = a03 * b20 + a13 * b21 + a23 * b22 + a33 * b23;
+ dst[12] = a00 * b30 + a10 * b31 + a20 * b32 + a30 * b33;
+ dst[13] = a01 * b30 + a11 * b31 + a21 * b32 + a31 * b33;
+ dst[14] = a02 * b30 + a12 * b31 + a22 * b32 + a32 * b33;
+ dst[15] = a03 * b30 + a13 * b31 + a23 * b32 + a33 * b33;
+ return dst;
+}
+/**
+ * Sets the translation component of a 4-by-4 matrix to the given
+ * vector.
+ * @param {module:twgl/m4.Mat4} a The matrix.
+ * @param {module:twgl/v3.Vec3} v The vector.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The matrix with translation set.
+ * @memberOf module:twgl/m4
+ */
+
+
+function setTranslation(a, v, dst) {
+ dst = dst || identity();
+
+ if (a !== dst) {
+ dst[0] = a[0];
+ dst[1] = a[1];
+ dst[2] = a[2];
+ dst[3] = a[3];
+ dst[4] = a[4];
+ dst[5] = a[5];
+ dst[6] = a[6];
+ dst[7] = a[7];
+ dst[8] = a[8];
+ dst[9] = a[9];
+ dst[10] = a[10];
+ dst[11] = a[11];
+ }
+
+ dst[12] = v[0];
+ dst[13] = v[1];
+ dst[14] = v[2];
+ dst[15] = 1;
+ return dst;
+}
+/**
+ * Returns the translation component of a 4-by-4 matrix as a vector with 3
+ * entries.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not passed a new one is created.
+ * @return {module:twgl/v3.Vec3} The translation component of m.
+ * @memberOf module:twgl/m4
+ */
+
+
+function getTranslation(m, dst) {
+ dst = dst || v3.create();
+ dst[0] = m[12];
+ dst[1] = m[13];
+ dst[2] = m[14];
+ return dst;
+}
+/**
+ * Returns an axis of a 4x4 matrix as a vector with 3 entries
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {number} axis The axis 0 = x, 1 = y, 2 = z;
+ * @return {module:twgl/v3.Vec3} [dst] vector.
+ * @return {module:twgl/v3.Vec3} The axis component of m.
+ * @memberOf module:twgl/m4
+ */
+
+
+function getAxis(m, axis, dst) {
+ dst = dst || v3.create();
+ var off = axis * 4;
+ dst[0] = m[off + 0];
+ dst[1] = m[off + 1];
+ dst[2] = m[off + 2];
+ return dst;
+}
+/**
+ * Sets an axis of a 4x4 matrix as a vector with 3 entries
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/v3.Vec3} v the axis vector
+ * @param {number} axis The axis 0 = x, 1 = y, 2 = z;
+ * @param {module:twgl/m4.Mat4} [dst] The matrix to set. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The matrix with axis set.
+ * @memberOf module:twgl/m4
+ */
+
+
+function setAxis(a, v, axis, dst) {
+ if (dst !== a) {
+ dst = copy(a, dst);
+ }
+
+ var off = axis * 4;
+ dst[off + 0] = v[0];
+ dst[off + 1] = v[1];
+ dst[off + 2] = v[2];
+ return dst;
+}
+/**
+ * Computes a 4-by-4 perspective transformation matrix given the angular height
+ * of the frustum, the aspect ratio, and the near and far clipping planes. The
+ * arguments define a frustum extending in the negative z direction. The given
+ * angle is the vertical angle of the frustum, and the horizontal angle is
+ * determined to produce the given aspect ratio. The arguments near and far are
+ * the distances to the near and far clipping planes. Note that near and far
+ * are not z coordinates, but rather they are distances along the negative
+ * z-axis. The matrix generated sends the viewing frustum to the unit box.
+ * We assume a unit box extending from -1 to 1 in the x and y dimensions and
+ * from 0 to 1 in the z dimension.
+ * @param {number} fieldOfViewYInRadians The camera angle from top to bottom (in radians).
+ * @param {number} aspect The aspect ratio width / height.
+ * @param {number} zNear The depth (negative z coordinate)
+ * of the near clipping plane.
+ * @param {number} zFar The depth (negative z coordinate)
+ * of the far clipping plane.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The perspective matrix.
+ * @memberOf module:twgl/m4
+ */
+
+
+function perspective(fieldOfViewYInRadians, aspect, zNear, zFar, dst) {
+ dst = dst || new MatType(16);
+ var f = Math.tan(Math.PI * 0.5 - 0.5 * fieldOfViewYInRadians);
+ var rangeInv = 1.0 / (zNear - zFar);
+ dst[0] = f / aspect;
+ dst[1] = 0;
+ dst[2] = 0;
+ dst[3] = 0;
+ dst[4] = 0;
+ dst[5] = f;
+ dst[6] = 0;
+ dst[7] = 0;
+ dst[8] = 0;
+ dst[9] = 0;
+ dst[10] = (zNear + zFar) * rangeInv;
+ dst[11] = -1;
+ dst[12] = 0;
+ dst[13] = 0;
+ dst[14] = zNear * zFar * rangeInv * 2;
+ dst[15] = 0;
+ return dst;
+}
+/**
+ * Computes a 4-by-4 orthogonal transformation matrix given the left, right,
+ * bottom, and top dimensions of the near clipping plane as well as the
+ * near and far clipping plane distances.
+ * @param {number} left Left side of the near clipping plane viewport.
+ * @param {number} right Right side of the near clipping plane viewport.
+ * @param {number} bottom Bottom of the near clipping plane viewport.
+ * @param {number} top Top of the near clipping plane viewport.
+ * @param {number} near The depth (negative z coordinate)
+ * of the near clipping plane.
+ * @param {number} far The depth (negative z coordinate)
+ * of the far clipping plane.
+ * @param {module:twgl/m4.Mat4} [dst] Output matrix. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The perspective matrix.
+ * @memberOf module:twgl/m4
+ */
+
+
+function ortho(left, right, bottom, top, near, far, dst) {
+ dst = dst || new MatType(16);
+ dst[0] = 2 / (right - left);
+ dst[1] = 0;
+ dst[2] = 0;
+ dst[3] = 0;
+ dst[4] = 0;
+ dst[5] = 2 / (top - bottom);
+ dst[6] = 0;
+ dst[7] = 0;
+ dst[8] = 0;
+ dst[9] = 0;
+ dst[10] = 2 / (near - far);
+ dst[11] = 0;
+ dst[12] = (right + left) / (left - right);
+ dst[13] = (top + bottom) / (bottom - top);
+ dst[14] = (far + near) / (near - far);
+ dst[15] = 1;
+ return dst;
+}
+/**
+ * Computes a 4-by-4 perspective transformation matrix given the left, right,
+ * top, bottom, near and far clipping planes. The arguments define a frustum
+ * extending in the negative z direction. The arguments near and far are the
+ * distances to the near and far clipping planes. Note that near and far are not
+ * z coordinates, but rather they are distances along the negative z-axis. The
+ * matrix generated sends the viewing frustum to the unit box. We assume a unit
+ * box extending from -1 to 1 in the x and y dimensions and from 0 to 1 in the z
+ * dimension.
+ * @param {number} left The x coordinate of the left plane of the box.
+ * @param {number} right The x coordinate of the right plane of the box.
+ * @param {number} bottom The y coordinate of the bottom plane of the box.
+ * @param {number} top The y coordinate of the right plane of the box.
+ * @param {number} near The negative z coordinate of the near plane of the box.
+ * @param {number} far The negative z coordinate of the far plane of the box.
+ * @param {module:twgl/m4.Mat4} [dst] Output matrix. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The perspective projection matrix.
+ * @memberOf module:twgl/m4
+ */
+
+
+function frustum(left, right, bottom, top, near, far, dst) {
+ dst = dst || new MatType(16);
+ var dx = right - left;
+ var dy = top - bottom;
+ var dz = near - far;
+ dst[0] = 2 * near / dx;
+ dst[1] = 0;
+ dst[2] = 0;
+ dst[3] = 0;
+ dst[4] = 0;
+ dst[5] = 2 * near / dy;
+ dst[6] = 0;
+ dst[7] = 0;
+ dst[8] = (left + right) / dx;
+ dst[9] = (top + bottom) / dy;
+ dst[10] = far / dz;
+ dst[11] = -1;
+ dst[12] = 0;
+ dst[13] = 0;
+ dst[14] = near * far / dz;
+ dst[15] = 0;
+ return dst;
+}
+
+var xAxis;
+var yAxis;
+var zAxis;
+/**
+ * Computes a 4-by-4 look-at transformation.
+ *
+ * This is a matrix which positions the camera itself. If you want
+ * a view matrix (a matrix which moves things in front of the camera)
+ * take the inverse of this.
+ *
+ * @param {module:twgl/v3.Vec3} eye The position of the eye.
+ * @param {module:twgl/v3.Vec3} target The position meant to be viewed.
+ * @param {module:twgl/v3.Vec3} up A vector pointing up.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The look-at matrix.
+ * @memberOf module:twgl/m4
+ */
+
+function lookAt(eye, target, up, dst) {
+ dst = dst || new MatType(16);
+ xAxis = xAxis || v3.create();
+ yAxis = yAxis || v3.create();
+ zAxis = zAxis || v3.create();
+ v3.normalize(v3.subtract(eye, target, zAxis), zAxis);
+ v3.normalize(v3.cross(up, zAxis, xAxis), xAxis);
+ v3.normalize(v3.cross(zAxis, xAxis, yAxis), yAxis);
+ dst[0] = xAxis[0];
+ dst[1] = xAxis[1];
+ dst[2] = xAxis[2];
+ dst[3] = 0;
+ dst[4] = yAxis[0];
+ dst[5] = yAxis[1];
+ dst[6] = yAxis[2];
+ dst[7] = 0;
+ dst[8] = zAxis[0];
+ dst[9] = zAxis[1];
+ dst[10] = zAxis[2];
+ dst[11] = 0;
+ dst[12] = eye[0];
+ dst[13] = eye[1];
+ dst[14] = eye[2];
+ dst[15] = 1;
+ return dst;
+}
+/**
+ * Creates a 4-by-4 matrix which translates by the given vector v.
+ * @param {module:twgl/v3.Vec3} v The vector by
+ * which to translate.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The translation matrix.
+ * @memberOf module:twgl/m4
+ */
+
+
+function translation(v, dst) {
+ dst = dst || new MatType(16);
+ dst[0] = 1;
+ dst[1] = 0;
+ dst[2] = 0;
+ dst[3] = 0;
+ dst[4] = 0;
+ dst[5] = 1;
+ dst[6] = 0;
+ dst[7] = 0;
+ dst[8] = 0;
+ dst[9] = 0;
+ dst[10] = 1;
+ dst[11] = 0;
+ dst[12] = v[0];
+ dst[13] = v[1];
+ dst[14] = v[2];
+ dst[15] = 1;
+ return dst;
+}
+/**
+ * Translates the given 4-by-4 matrix by the given vector v.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/v3.Vec3} v The vector by
+ * which to translate.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The translated matrix.
+ * @memberOf module:twgl/m4
+ */
+
+
+function translate(m, v, dst) {
+ dst = dst || new MatType(16);
+ var v0 = v[0];
+ var v1 = v[1];
+ var v2 = v[2];
+ var m00 = m[0];
+ var m01 = m[1];
+ var m02 = m[2];
+ var m03 = m[3];
+ var m10 = m[1 * 4 + 0];
+ var m11 = m[1 * 4 + 1];
+ var m12 = m[1 * 4 + 2];
+ var m13 = m[1 * 4 + 3];
+ var m20 = m[2 * 4 + 0];
+ var m21 = m[2 * 4 + 1];
+ var m22 = m[2 * 4 + 2];
+ var m23 = m[2 * 4 + 3];
+ var m30 = m[3 * 4 + 0];
+ var m31 = m[3 * 4 + 1];
+ var m32 = m[3 * 4 + 2];
+ var m33 = m[3 * 4 + 3];
+
+ if (m !== dst) {
+ dst[0] = m00;
+ dst[1] = m01;
+ dst[2] = m02;
+ dst[3] = m03;
+ dst[4] = m10;
+ dst[5] = m11;
+ dst[6] = m12;
+ dst[7] = m13;
+ dst[8] = m20;
+ dst[9] = m21;
+ dst[10] = m22;
+ dst[11] = m23;
+ }
+
+ dst[12] = m00 * v0 + m10 * v1 + m20 * v2 + m30;
+ dst[13] = m01 * v0 + m11 * v1 + m21 * v2 + m31;
+ dst[14] = m02 * v0 + m12 * v1 + m22 * v2 + m32;
+ dst[15] = m03 * v0 + m13 * v1 + m23 * v2 + m33;
+ return dst;
+}
+/**
+ * Creates a 4-by-4 matrix which rotates around the x-axis by the given angle.
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The rotation matrix.
+ * @memberOf module:twgl/m4
+ */
+
+
+function rotationX(angleInRadians, dst) {
+ dst = dst || new MatType(16);
+ var c = Math.cos(angleInRadians);
+ var s = Math.sin(angleInRadians);
+ dst[0] = 1;
+ dst[1] = 0;
+ dst[2] = 0;
+ dst[3] = 0;
+ dst[4] = 0;
+ dst[5] = c;
+ dst[6] = s;
+ dst[7] = 0;
+ dst[8] = 0;
+ dst[9] = -s;
+ dst[10] = c;
+ dst[11] = 0;
+ dst[12] = 0;
+ dst[13] = 0;
+ dst[14] = 0;
+ dst[15] = 1;
+ return dst;
+}
+/**
+ * Rotates the given 4-by-4 matrix around the x-axis by the given
+ * angle.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The rotated matrix.
+ * @memberOf module:twgl/m4
+ */
+
+
+function rotateX(m, angleInRadians, dst) {
+ dst = dst || new MatType(16);
+ var m10 = m[4];
+ var m11 = m[5];
+ var m12 = m[6];
+ var m13 = m[7];
+ var m20 = m[8];
+ var m21 = m[9];
+ var m22 = m[10];
+ var m23 = m[11];
+ var c = Math.cos(angleInRadians);
+ var s = Math.sin(angleInRadians);
+ dst[4] = c * m10 + s * m20;
+ dst[5] = c * m11 + s * m21;
+ dst[6] = c * m12 + s * m22;
+ dst[7] = c * m13 + s * m23;
+ dst[8] = c * m20 - s * m10;
+ dst[9] = c * m21 - s * m11;
+ dst[10] = c * m22 - s * m12;
+ dst[11] = c * m23 - s * m13;
+
+ if (m !== dst) {
+ dst[0] = m[0];
+ dst[1] = m[1];
+ dst[2] = m[2];
+ dst[3] = m[3];
+ dst[12] = m[12];
+ dst[13] = m[13];
+ dst[14] = m[14];
+ dst[15] = m[15];
+ }
+
+ return dst;
+}
+/**
+ * Creates a 4-by-4 matrix which rotates around the y-axis by the given angle.
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The rotation matrix.
+ * @memberOf module:twgl/m4
+ */
+
+
+function rotationY(angleInRadians, dst) {
+ dst = dst || new MatType(16);
+ var c = Math.cos(angleInRadians);
+ var s = Math.sin(angleInRadians);
+ dst[0] = c;
+ dst[1] = 0;
+ dst[2] = -s;
+ dst[3] = 0;
+ dst[4] = 0;
+ dst[5] = 1;
+ dst[6] = 0;
+ dst[7] = 0;
+ dst[8] = s;
+ dst[9] = 0;
+ dst[10] = c;
+ dst[11] = 0;
+ dst[12] = 0;
+ dst[13] = 0;
+ dst[14] = 0;
+ dst[15] = 1;
+ return dst;
+}
+/**
+ * Rotates the given 4-by-4 matrix around the y-axis by the given
+ * angle.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The rotated matrix.
+ * @memberOf module:twgl/m4
+ */
+
+
+function rotateY(m, angleInRadians, dst) {
+ dst = dst || new MatType(16);
+ var m00 = m[0 * 4 + 0];
+ var m01 = m[0 * 4 + 1];
+ var m02 = m[0 * 4 + 2];
+ var m03 = m[0 * 4 + 3];
+ var m20 = m[2 * 4 + 0];
+ var m21 = m[2 * 4 + 1];
+ var m22 = m[2 * 4 + 2];
+ var m23 = m[2 * 4 + 3];
+ var c = Math.cos(angleInRadians);
+ var s = Math.sin(angleInRadians);
+ dst[0] = c * m00 - s * m20;
+ dst[1] = c * m01 - s * m21;
+ dst[2] = c * m02 - s * m22;
+ dst[3] = c * m03 - s * m23;
+ dst[8] = c * m20 + s * m00;
+ dst[9] = c * m21 + s * m01;
+ dst[10] = c * m22 + s * m02;
+ dst[11] = c * m23 + s * m03;
+
+ if (m !== dst) {
+ dst[4] = m[4];
+ dst[5] = m[5];
+ dst[6] = m[6];
+ dst[7] = m[7];
+ dst[12] = m[12];
+ dst[13] = m[13];
+ dst[14] = m[14];
+ dst[15] = m[15];
+ }
+
+ return dst;
+}
+/**
+ * Creates a 4-by-4 matrix which rotates around the z-axis by the given angle.
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The rotation matrix.
+ * @memberOf module:twgl/m4
+ */
+
+
+function rotationZ(angleInRadians, dst) {
+ dst = dst || new MatType(16);
+ var c = Math.cos(angleInRadians);
+ var s = Math.sin(angleInRadians);
+ dst[0] = c;
+ dst[1] = s;
+ dst[2] = 0;
+ dst[3] = 0;
+ dst[4] = -s;
+ dst[5] = c;
+ dst[6] = 0;
+ dst[7] = 0;
+ dst[8] = 0;
+ dst[9] = 0;
+ dst[10] = 1;
+ dst[11] = 0;
+ dst[12] = 0;
+ dst[13] = 0;
+ dst[14] = 0;
+ dst[15] = 1;
+ return dst;
+}
+/**
+ * Rotates the given 4-by-4 matrix around the z-axis by the given
+ * angle.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The rotated matrix.
+ * @memberOf module:twgl/m4
+ */
+
+
+function rotateZ(m, angleInRadians, dst) {
+ dst = dst || new MatType(16);
+ var m00 = m[0 * 4 + 0];
+ var m01 = m[0 * 4 + 1];
+ var m02 = m[0 * 4 + 2];
+ var m03 = m[0 * 4 + 3];
+ var m10 = m[1 * 4 + 0];
+ var m11 = m[1 * 4 + 1];
+ var m12 = m[1 * 4 + 2];
+ var m13 = m[1 * 4 + 3];
+ var c = Math.cos(angleInRadians);
+ var s = Math.sin(angleInRadians);
+ dst[0] = c * m00 + s * m10;
+ dst[1] = c * m01 + s * m11;
+ dst[2] = c * m02 + s * m12;
+ dst[3] = c * m03 + s * m13;
+ dst[4] = c * m10 - s * m00;
+ dst[5] = c * m11 - s * m01;
+ dst[6] = c * m12 - s * m02;
+ dst[7] = c * m13 - s * m03;
+
+ if (m !== dst) {
+ dst[8] = m[8];
+ dst[9] = m[9];
+ dst[10] = m[10];
+ dst[11] = m[11];
+ dst[12] = m[12];
+ dst[13] = m[13];
+ dst[14] = m[14];
+ dst[15] = m[15];
+ }
+
+ return dst;
+}
+/**
+ * Creates a 4-by-4 matrix which rotates around the given axis by the given
+ * angle.
+ * @param {module:twgl/v3.Vec3} axis The axis
+ * about which to rotate.
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} A matrix which rotates angle radians
+ * around the axis.
+ * @memberOf module:twgl/m4
+ */
+
+
+function axisRotation(axis, angleInRadians, dst) {
+ dst = dst || new MatType(16);
+ var x = axis[0];
+ var y = axis[1];
+ var z = axis[2];
+ var n = Math.sqrt(x * x + y * y + z * z);
+ x /= n;
+ y /= n;
+ z /= n;
+ var xx = x * x;
+ var yy = y * y;
+ var zz = z * z;
+ var c = Math.cos(angleInRadians);
+ var s = Math.sin(angleInRadians);
+ var oneMinusCosine = 1 - c;
+ dst[0] = xx + (1 - xx) * c;
+ dst[1] = x * y * oneMinusCosine + z * s;
+ dst[2] = x * z * oneMinusCosine - y * s;
+ dst[3] = 0;
+ dst[4] = x * y * oneMinusCosine - z * s;
+ dst[5] = yy + (1 - yy) * c;
+ dst[6] = y * z * oneMinusCosine + x * s;
+ dst[7] = 0;
+ dst[8] = x * z * oneMinusCosine + y * s;
+ dst[9] = y * z * oneMinusCosine - x * s;
+ dst[10] = zz + (1 - zz) * c;
+ dst[11] = 0;
+ dst[12] = 0;
+ dst[13] = 0;
+ dst[14] = 0;
+ dst[15] = 1;
+ return dst;
+}
+/**
+ * Rotates the given 4-by-4 matrix around the given axis by the
+ * given angle.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/v3.Vec3} axis The axis
+ * about which to rotate.
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The rotated matrix.
+ * @memberOf module:twgl/m4
+ */
+
+
+function axisRotate(m, axis, angleInRadians, dst) {
+ dst = dst || new MatType(16);
+ var x = axis[0];
+ var y = axis[1];
+ var z = axis[2];
+ var n = Math.sqrt(x * x + y * y + z * z);
+ x /= n;
+ y /= n;
+ z /= n;
+ var xx = x * x;
+ var yy = y * y;
+ var zz = z * z;
+ var c = Math.cos(angleInRadians);
+ var s = Math.sin(angleInRadians);
+ var oneMinusCosine = 1 - c;
+ var r00 = xx + (1 - xx) * c;
+ var r01 = x * y * oneMinusCosine + z * s;
+ var r02 = x * z * oneMinusCosine - y * s;
+ var r10 = x * y * oneMinusCosine - z * s;
+ var r11 = yy + (1 - yy) * c;
+ var r12 = y * z * oneMinusCosine + x * s;
+ var r20 = x * z * oneMinusCosine + y * s;
+ var r21 = y * z * oneMinusCosine - x * s;
+ var r22 = zz + (1 - zz) * c;
+ var m00 = m[0];
+ var m01 = m[1];
+ var m02 = m[2];
+ var m03 = m[3];
+ var m10 = m[4];
+ var m11 = m[5];
+ var m12 = m[6];
+ var m13 = m[7];
+ var m20 = m[8];
+ var m21 = m[9];
+ var m22 = m[10];
+ var m23 = m[11];
+ dst[0] = r00 * m00 + r01 * m10 + r02 * m20;
+ dst[1] = r00 * m01 + r01 * m11 + r02 * m21;
+ dst[2] = r00 * m02 + r01 * m12 + r02 * m22;
+ dst[3] = r00 * m03 + r01 * m13 + r02 * m23;
+ dst[4] = r10 * m00 + r11 * m10 + r12 * m20;
+ dst[5] = r10 * m01 + r11 * m11 + r12 * m21;
+ dst[6] = r10 * m02 + r11 * m12 + r12 * m22;
+ dst[7] = r10 * m03 + r11 * m13 + r12 * m23;
+ dst[8] = r20 * m00 + r21 * m10 + r22 * m20;
+ dst[9] = r20 * m01 + r21 * m11 + r22 * m21;
+ dst[10] = r20 * m02 + r21 * m12 + r22 * m22;
+ dst[11] = r20 * m03 + r21 * m13 + r22 * m23;
+
+ if (m !== dst) {
+ dst[12] = m[12];
+ dst[13] = m[13];
+ dst[14] = m[14];
+ dst[15] = m[15];
+ }
+
+ return dst;
+}
+/**
+ * Creates a 4-by-4 matrix which scales in each dimension by an amount given by
+ * the corresponding entry in the given vector; assumes the vector has three
+ * entries.
+ * @param {module:twgl/v3.Vec3} v A vector of
+ * three entries specifying the factor by which to scale in each dimension.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The scaling matrix.
+ * @memberOf module:twgl/m4
+ */
+
+
+function scaling(v, dst) {
+ dst = dst || new MatType(16);
+ dst[0] = v[0];
+ dst[1] = 0;
+ dst[2] = 0;
+ dst[3] = 0;
+ dst[4] = 0;
+ dst[5] = v[1];
+ dst[6] = 0;
+ dst[7] = 0;
+ dst[8] = 0;
+ dst[9] = 0;
+ dst[10] = v[2];
+ dst[11] = 0;
+ dst[12] = 0;
+ dst[13] = 0;
+ dst[14] = 0;
+ dst[15] = 1;
+ return dst;
+}
+/**
+ * Scales the given 4-by-4 matrix in each dimension by an amount
+ * given by the corresponding entry in the given vector; assumes the vector has
+ * three entries.
+ * @param {module:twgl/m4.Mat4} m The matrix to be modified.
+ * @param {module:twgl/v3.Vec3} v A vector of three entries specifying the
+ * factor by which to scale in each dimension.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The scaled matrix.
+ * @memberOf module:twgl/m4
+ */
+
+
+function scale(m, v, dst) {
+ dst = dst || new MatType(16);
+ var v0 = v[0];
+ var v1 = v[1];
+ var v2 = v[2];
+ dst[0] = v0 * m[0 * 4 + 0];
+ dst[1] = v0 * m[0 * 4 + 1];
+ dst[2] = v0 * m[0 * 4 + 2];
+ dst[3] = v0 * m[0 * 4 + 3];
+ dst[4] = v1 * m[1 * 4 + 0];
+ dst[5] = v1 * m[1 * 4 + 1];
+ dst[6] = v1 * m[1 * 4 + 2];
+ dst[7] = v1 * m[1 * 4 + 3];
+ dst[8] = v2 * m[2 * 4 + 0];
+ dst[9] = v2 * m[2 * 4 + 1];
+ dst[10] = v2 * m[2 * 4 + 2];
+ dst[11] = v2 * m[2 * 4 + 3];
+
+ if (m !== dst) {
+ dst[12] = m[12];
+ dst[13] = m[13];
+ dst[14] = m[14];
+ dst[15] = m[15];
+ }
+
+ return dst;
+}
+/**
+ * Takes a 4-by-4 matrix and a vector with 3 entries,
+ * interprets the vector as a point, transforms that point by the matrix, and
+ * returns the result as a vector with 3 entries.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/v3.Vec3} v The point.
+ * @param {module:twgl/v3.Vec3} [dst] optional vec3 to store result. If not passed a new one is created.
+ * @return {module:twgl/v3.Vec3} The transformed point.
+ * @memberOf module:twgl/m4
+ */
+
+
+function transformPoint(m, v, dst) {
+ dst = dst || v3.create();
+ var v0 = v[0];
+ var v1 = v[1];
+ var v2 = v[2];
+ var d = v0 * m[0 * 4 + 3] + v1 * m[1 * 4 + 3] + v2 * m[2 * 4 + 3] + m[3 * 4 + 3];
+ dst[0] = (v0 * m[0 * 4 + 0] + v1 * m[1 * 4 + 0] + v2 * m[2 * 4 + 0] + m[3 * 4 + 0]) / d;
+ dst[1] = (v0 * m[0 * 4 + 1] + v1 * m[1 * 4 + 1] + v2 * m[2 * 4 + 1] + m[3 * 4 + 1]) / d;
+ dst[2] = (v0 * m[0 * 4 + 2] + v1 * m[1 * 4 + 2] + v2 * m[2 * 4 + 2] + m[3 * 4 + 2]) / d;
+ return dst;
+}
+/**
+ * Takes a 4-by-4 matrix and a vector with 3 entries, interprets the vector as a
+ * direction, transforms that direction by the matrix, and returns the result;
+ * assumes the transformation of 3-dimensional space represented by the matrix
+ * is parallel-preserving, i.e. any combination of rotation, scaling and
+ * translation, but not a perspective distortion. Returns a vector with 3
+ * entries.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/v3.Vec3} v The direction.
+ * @param {module:twgl/v3.Vec3} [dst] optional Vec3 to store result. If not passed a new one is created.
+ * @return {module:twgl/v3.Vec3} The transformed direction.
+ * @memberOf module:twgl/m4
+ */
+
+
+function transformDirection(m, v, dst) {
+ dst = dst || v3.create();
+ var v0 = v[0];
+ var v1 = v[1];
+ var v2 = v[2];
+ dst[0] = v0 * m[0 * 4 + 0] + v1 * m[1 * 4 + 0] + v2 * m[2 * 4 + 0];
+ dst[1] = v0 * m[0 * 4 + 1] + v1 * m[1 * 4 + 1] + v2 * m[2 * 4 + 1];
+ dst[2] = v0 * m[0 * 4 + 2] + v1 * m[1 * 4 + 2] + v2 * m[2 * 4 + 2];
+ return dst;
+}
+/**
+ * Takes a 4-by-4 matrix m and a vector v with 3 entries, interprets the vector
+ * as a normal to a surface, and computes a vector which is normal upon
+ * transforming that surface by the matrix. The effect of this function is the
+ * same as transforming v (as a direction) by the inverse-transpose of m. This
+ * function assumes the transformation of 3-dimensional space represented by the
+ * matrix is parallel-preserving, i.e. any combination of rotation, scaling and
+ * translation, but not a perspective distortion. Returns a vector with 3
+ * entries.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/v3.Vec3} v The normal.
+ * @param {module:twgl/v3.Vec3} [dst] The direction. If not passed a new one is created.
+ * @return {module:twgl/v3.Vec3} The transformed normal.
+ * @memberOf module:twgl/m4
+ */
+
+
+function transformNormal(m, v, dst) {
+ dst = dst || v3.create();
+ var mi = inverse(m);
+ var v0 = v[0];
+ var v1 = v[1];
+ var v2 = v[2];
+ dst[0] = v0 * mi[0 * 4 + 0] + v1 * mi[0 * 4 + 1] + v2 * mi[0 * 4 + 2];
+ dst[1] = v0 * mi[1 * 4 + 0] + v1 * mi[1 * 4 + 1] + v2 * mi[1 * 4 + 2];
+ dst[2] = v0 * mi[2 * 4 + 0] + v1 * mi[2 * 4 + 1] + v2 * mi[2 * 4 + 2];
+ return dst;
+}
+
+/***/ }),
+
+/***/ "./src/primitives.js":
+/*!***************************!*\
+ !*** ./src/primitives.js ***!
+ \***************************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.create3DFVertices = create3DFVertices;
+exports.createAugmentedTypedArray = createAugmentedTypedArray;
+exports.createCubeVertices = createCubeVertices;
+exports.createPlaneVertices = createPlaneVertices;
+exports.createSphereVertices = createSphereVertices;
+exports.createTruncatedConeVertices = createTruncatedConeVertices;
+exports.createXYQuadVertices = createXYQuadVertices;
+exports.createCrescentVertices = createCrescentVertices;
+exports.createCylinderVertices = createCylinderVertices;
+exports.createTorusVertices = createTorusVertices;
+exports.createDiscVertices = createDiscVertices;
+exports.deindexVertices = deindexVertices;
+exports.flattenNormals = flattenNormals;
+exports.makeRandomVertexColors = makeRandomVertexColors;
+exports.reorientDirections = reorientDirections;
+exports.reorientNormals = reorientNormals;
+exports.reorientPositions = reorientPositions;
+exports.reorientVertices = reorientVertices;
+exports.concatVertices = concatVertices;
+exports.duplicateVertices = duplicateVertices;
+exports.createDiscBuffers = exports.createDiscBufferInfo = exports.createTorusBuffers = exports.createTorusBufferInfo = exports.createCylinderBuffers = exports.createCylinderBufferInfo = exports.createCrescentBuffers = exports.createCrescentBufferInfo = exports.createCresentVertices = exports.createCresentBuffers = exports.createCresentBufferInfo = exports.createXYQuadBuffers = exports.createXYQuadBufferInfo = exports.createTruncatedConeBuffers = exports.createTruncatedConeBufferInfo = exports.createSphereBuffers = exports.createSphereBufferInfo = exports.createPlaneBuffers = exports.createPlaneBufferInfo = exports.createCubeBuffers = exports.createCubeBufferInfo = exports.create3DFBuffers = exports.create3DFBufferInfo = void 0;
+
+var attributes = _interopRequireWildcard(__webpack_require__(/*! ./attributes.js */ "./src/attributes.js"));
+
+var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
+
+var typedArrays = _interopRequireWildcard(__webpack_require__(/*! ./typedarrays.js */ "./src/typedarrays.js"));
+
+var m4 = _interopRequireWildcard(__webpack_require__(/*! ./m4.js */ "./src/m4.js"));
+
+var v3 = _interopRequireWildcard(__webpack_require__(/*! ./v3.js */ "./src/v3.js"));
+
+function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * Various functions to make simple primitives
+ *
+ * note: Most primitive functions come in 3 styles
+ *
+ * * `createSomeShapeBufferInfo`
+ *
+ * These functions are almost always the functions you want to call. They
+ * create vertices then make WebGLBuffers and create {@link module:twgl.AttribInfo}s
+ * returning a {@link module:twgl.BufferInfo} you can pass to {@link module:twgl.setBuffersAndAttributes}
+ * and {@link module:twgl.drawBufferInfo} etc...
+ *
+ * * `createSomeShapeBuffers`
+ *
+ * These create WebGLBuffers and put your data in them but nothing else.
+ * It's a shortcut to doing it yourself if you don't want to use
+ * the higher level functions.
+ *
+ * * `createSomeShapeVertices`
+ *
+ * These just create vertices, no buffers. This allows you to manipulate the vertices
+ * or add more data before generating a {@link module:twgl.BufferInfo}. Once you're finished
+ * manipulating the vertices call {@link module:twgl.createBufferInfoFromArrays}.
+ *
+ * example:
+ *
+ * const arrays = twgl.primitives.createPlaneArrays(1);
+ * twgl.primitives.reorientVertices(arrays, m4.rotationX(Math.PI * 0.5));
+ * const bufferInfo = twgl.createBufferInfoFromArrays(gl, arrays);
+ *
+ * @module twgl/primitives
+ */
+var getArray = attributes.getArray_; // eslint-disable-line
+
+var getNumComponents = attributes.getNumComponents_; // eslint-disable-line
+
+/**
+ * @typedef {(Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array)} TypedArray
+ */
+
+/**
+ * Add `push` to a typed array. It just keeps a 'cursor'
+ * and allows use to `push` values into the array so we
+ * don't have to manually compute offsets
+ * @param {TypedArray} typedArray TypedArray to augment
+ * @param {number} numComponents number of components.
+ * @private
+ */
+
+function augmentTypedArray(typedArray, numComponents) {
+ var cursor = 0;
+
+ typedArray.push = function () {
+ for (var ii = 0; ii < arguments.length; ++ii) {
+ var value = arguments[ii];
+
+ if (value instanceof Array || typedArrays.isArrayBuffer(value)) {
+ for (var jj = 0; jj < value.length; ++jj) {
+ typedArray[cursor++] = value[jj];
+ }
+ } else {
+ typedArray[cursor++] = value;
+ }
+ }
+ };
+
+ typedArray.reset = function (opt_index) {
+ cursor = opt_index || 0;
+ };
+
+ typedArray.numComponents = numComponents;
+ Object.defineProperty(typedArray, 'numElements', {
+ get: function get() {
+ return this.length / this.numComponents | 0;
+ }
+ });
+ return typedArray;
+}
+/**
+ * creates a typed array with a `push` function attached
+ * so that you can easily *push* values.
+ *
+ * `push` can take multiple arguments. If an argument is an array each element
+ * of the array will be added to the typed array.
+ *
+ * Example:
+ *
+ * const array = createAugmentedTypedArray(3, 2); // creates a Float32Array with 6 values
+ * array.push(1, 2, 3);
+ * array.push([4, 5, 6]);
+ * // array now contains [1, 2, 3, 4, 5, 6]
+ *
+ * Also has `numComponents` and `numElements` properties.
+ *
+ * @param {number} numComponents number of components
+ * @param {number} numElements number of elements. The total size of the array will be `numComponents * numElements`.
+ * @param {constructor} opt_type A constructor for the type. Default = `Float32Array`.
+ * @return {ArrayBufferView} A typed array.
+ * @memberOf module:twgl/primitives
+ */
+
+
+function createAugmentedTypedArray(numComponents, numElements, opt_type) {
+ var Type = opt_type || Float32Array;
+ return augmentTypedArray(new Type(numComponents * numElements), numComponents);
+}
+
+function allButIndices(name) {
+ return name !== "indices";
+}
+/**
+ * Given indexed vertices creates a new set of vertices un-indexed by expanding the indexed vertices.
+ * @param {Object.} vertices The indexed vertices to deindex
+ * @return {Object.} The deindexed vertices
+ * @memberOf module:twgl/primitives
+ */
+
+
+function deindexVertices(vertices) {
+ var indices = vertices.indices;
+ var newVertices = {};
+ var numElements = indices.length;
+
+ function expandToUnindexed(channel) {
+ var srcBuffer = vertices[channel];
+ var numComponents = srcBuffer.numComponents;
+ var dstBuffer = createAugmentedTypedArray(numComponents, numElements, srcBuffer.constructor);
+
+ for (var ii = 0; ii < numElements; ++ii) {
+ var ndx = indices[ii];
+ var offset = ndx * numComponents;
+
+ for (var jj = 0; jj < numComponents; ++jj) {
+ dstBuffer.push(srcBuffer[offset + jj]);
+ }
+ }
+
+ newVertices[channel] = dstBuffer;
+ }
+
+ Object.keys(vertices).filter(allButIndices).forEach(expandToUnindexed);
+ return newVertices;
+}
+/**
+ * flattens the normals of deindexed vertices in place.
+ * @param {Object.} vertices The deindexed vertices who's normals to flatten
+ * @return {Object.} The flattened vertices (same as was passed in)
+ * @memberOf module:twgl/primitives
+ */
+
+
+function flattenNormals(vertices) {
+ if (vertices.indices) {
+ throw new Error('can not flatten normals of indexed vertices. deindex them first');
+ }
+
+ var normals = vertices.normal;
+ var numNormals = normals.length;
+
+ for (var ii = 0; ii < numNormals; ii += 9) {
+ // pull out the 3 normals for this triangle
+ var nax = normals[ii + 0];
+ var nay = normals[ii + 1];
+ var naz = normals[ii + 2];
+ var nbx = normals[ii + 3];
+ var nby = normals[ii + 4];
+ var nbz = normals[ii + 5];
+ var ncx = normals[ii + 6];
+ var ncy = normals[ii + 7];
+ var ncz = normals[ii + 8]; // add them
+
+ var nx = nax + nbx + ncx;
+ var ny = nay + nby + ncy;
+ var nz = naz + nbz + ncz; // normalize them
+
+ var length = Math.sqrt(nx * nx + ny * ny + nz * nz);
+ nx /= length;
+ ny /= length;
+ nz /= length; // copy them back in
+
+ normals[ii + 0] = nx;
+ normals[ii + 1] = ny;
+ normals[ii + 2] = nz;
+ normals[ii + 3] = nx;
+ normals[ii + 4] = ny;
+ normals[ii + 5] = nz;
+ normals[ii + 6] = nx;
+ normals[ii + 7] = ny;
+ normals[ii + 8] = nz;
+ }
+
+ return vertices;
+}
+
+function applyFuncToV3Array(array, matrix, fn) {
+ var len = array.length;
+ var tmp = new Float32Array(3);
+
+ for (var ii = 0; ii < len; ii += 3) {
+ fn(matrix, [array[ii], array[ii + 1], array[ii + 2]], tmp);
+ array[ii] = tmp[0];
+ array[ii + 1] = tmp[1];
+ array[ii + 2] = tmp[2];
+ }
+}
+
+function transformNormal(mi, v, dst) {
+ dst = dst || v3.create();
+ var v0 = v[0];
+ var v1 = v[1];
+ var v2 = v[2];
+ dst[0] = v0 * mi[0 * 4 + 0] + v1 * mi[0 * 4 + 1] + v2 * mi[0 * 4 + 2];
+ dst[1] = v0 * mi[1 * 4 + 0] + v1 * mi[1 * 4 + 1] + v2 * mi[1 * 4 + 2];
+ dst[2] = v0 * mi[2 * 4 + 0] + v1 * mi[2 * 4 + 1] + v2 * mi[2 * 4 + 2];
+ return dst;
+}
+/**
+ * Reorients directions by the given matrix..
+ * @param {(number[]|TypedArray)} array The array. Assumes value floats per element.
+ * @param {module:twgl/m4.Mat4} matrix A matrix to multiply by.
+ * @return {(number[]|TypedArray)} the same array that was passed in
+ * @memberOf module:twgl/primitives
+ */
+
+
+function reorientDirections(array, matrix) {
+ applyFuncToV3Array(array, matrix, m4.transformDirection);
+ return array;
+}
+/**
+ * Reorients normals by the inverse-transpose of the given
+ * matrix..
+ * @param {(number[]|TypedArray)} array The array. Assumes value floats per element.
+ * @param {module:twgl/m4.Mat4} matrix A matrix to multiply by.
+ * @return {(number[]|TypedArray)} the same array that was passed in
+ * @memberOf module:twgl/primitives
+ */
+
+
+function reorientNormals(array, matrix) {
+ applyFuncToV3Array(array, m4.inverse(matrix), transformNormal);
+ return array;
+}
+/**
+ * Reorients positions by the given matrix. In other words, it
+ * multiplies each vertex by the given matrix.
+ * @param {(number[]|TypedArray)} array The array. Assumes value floats per element.
+ * @param {module:twgl/m4.Mat4} matrix A matrix to multiply by.
+ * @return {(number[]|TypedArray)} the same array that was passed in
+ * @memberOf module:twgl/primitives
+ */
+
+
+function reorientPositions(array, matrix) {
+ applyFuncToV3Array(array, matrix, m4.transformPoint);
+ return array;
+}
+/**
+ * @typedef {(number[]|TypedArray)} NativeArrayOrTypedArray
+ */
+
+/**
+ * Reorients arrays by the given matrix. Assumes arrays have
+ * names that contains 'pos' could be reoriented as positions,
+ * 'binorm' or 'tan' as directions, and 'norm' as normals.
+ *
+ * @param {Object.} arrays The vertices to reorient
+ * @param {module:twgl/m4.Mat4} matrix matrix to reorient by.
+ * @return {Object.} same arrays that were passed in.
+ * @memberOf module:twgl/primitives
+ */
+
+
+function reorientVertices(arrays, matrix) {
+ Object.keys(arrays).forEach(function (name) {
+ var array = arrays[name];
+
+ if (name.indexOf("pos") >= 0) {
+ reorientPositions(array, matrix);
+ } else if (name.indexOf("tan") >= 0 || name.indexOf("binorm") >= 0) {
+ reorientDirections(array, matrix);
+ } else if (name.indexOf("norm") >= 0) {
+ reorientNormals(array, matrix);
+ }
+ });
+ return arrays;
+}
+/**
+ * Creates XY quad BufferInfo
+ *
+ * The default with no parameters will return a 2x2 quad with values from -1 to +1.
+ * If you want a unit quad with that goes from 0 to 1 you'd call it with
+ *
+ * twgl.primitives.createXYQuadBufferInfo(gl, 1, 0.5, 0.5);
+ *
+ * If you want a unit quad centered above 0,0 you'd call it with
+ *
+ * twgl.primitives.createXYQuadBufferInfo(gl, 1, 0, 0.5);
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} [size] the size across the quad. Defaults to 2 which means vertices will go from -1 to +1
+ * @param {number} [xOffset] the amount to offset the quad in X
+ * @param {number} [yOffset] the amount to offset the quad in Y
+ * @return {Object.} the created XY Quad BufferInfo
+ * @memberOf module:twgl/primitives
+ * @function createXYQuadBuffers
+ */
+
+/**
+ * Creates XY quad Buffers
+ *
+ * The default with no parameters will return a 2x2 quad with values from -1 to +1.
+ * If you want a unit quad with that goes from 0 to 1 you'd call it with
+ *
+ * twgl.primitives.createXYQuadBufferInfo(gl, 1, 0.5, 0.5);
+ *
+ * If you want a unit quad centered above 0,0 you'd call it with
+ *
+ * twgl.primitives.createXYQuadBufferInfo(gl, 1, 0, 0.5);
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} [size] the size across the quad. Defaults to 2 which means vertices will go from -1 to +1
+ * @param {number} [xOffset] the amount to offset the quad in X
+ * @param {number} [yOffset] the amount to offset the quad in Y
+ * @return {module:twgl.BufferInfo} the created XY Quad buffers
+ * @memberOf module:twgl/primitives
+ * @function createXYQuadBufferInfo
+ */
+
+/**
+ * Creates XY quad vertices
+ *
+ * The default with no parameters will return a 2x2 quad with values from -1 to +1.
+ * If you want a unit quad with that goes from 0 to 1 you'd call it with
+ *
+ * twgl.primitives.createXYQuadVertices(1, 0.5, 0.5);
+ *
+ * If you want a unit quad centered above 0,0 you'd call it with
+ *
+ * twgl.primitives.createXYQuadVertices(1, 0, 0.5);
+ *
+ * @param {number} [size] the size across the quad. Defaults to 2 which means vertices will go from -1 to +1
+ * @param {number} [xOffset] the amount to offset the quad in X
+ * @param {number} [yOffset] the amount to offset the quad in Y
+ * @return {Object.} the created XY Quad vertices
+ * @memberOf module:twgl/primitives
+ */
+
+
+function createXYQuadVertices(size, xOffset, yOffset) {
+ size = size || 2;
+ xOffset = xOffset || 0;
+ yOffset = yOffset || 0;
+ size *= 0.5;
+ return {
+ position: {
+ numComponents: 2,
+ data: [xOffset + -1 * size, yOffset + -1 * size, xOffset + 1 * size, yOffset + -1 * size, xOffset + -1 * size, yOffset + 1 * size, xOffset + 1 * size, yOffset + 1 * size]
+ },
+ normal: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],
+ texcoord: [0, 0, 1, 0, 0, 1, 1, 1],
+ indices: [0, 1, 2, 2, 1, 3]
+ };
+}
+/**
+ * Creates XZ plane BufferInfo.
+ *
+ * The created plane has position, normal, and texcoord data
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} [width] Width of the plane. Default = 1
+ * @param {number} [depth] Depth of the plane. Default = 1
+ * @param {number} [subdivisionsWidth] Number of steps across the plane. Default = 1
+ * @param {number} [subdivisionsDepth] Number of steps down the plane. Default = 1
+ * @param {module:twgl/m4.Mat4} [matrix] A matrix by which to multiply all the vertices.
+ * @return {module:twgl.BufferInfo} The created plane BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createPlaneBufferInfo
+ */
+
+/**
+ * Creates XZ plane buffers.
+ *
+ * The created plane has position, normal, and texcoord data
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} [width] Width of the plane. Default = 1
+ * @param {number} [depth] Depth of the plane. Default = 1
+ * @param {number} [subdivisionsWidth] Number of steps across the plane. Default = 1
+ * @param {number} [subdivisionsDepth] Number of steps down the plane. Default = 1
+ * @param {module:twgl/m4.Mat4} [matrix] A matrix by which to multiply all the vertices.
+ * @return {Object.} The created plane buffers.
+ * @memberOf module:twgl/primitives
+ * @function createPlaneBuffers
+ */
+
+/**
+ * Creates XZ plane vertices.
+ *
+ * The created plane has position, normal, and texcoord data
+ *
+ * @param {number} [width] Width of the plane. Default = 1
+ * @param {number} [depth] Depth of the plane. Default = 1
+ * @param {number} [subdivisionsWidth] Number of steps across the plane. Default = 1
+ * @param {number} [subdivisionsDepth] Number of steps down the plane. Default = 1
+ * @param {module:twgl/m4.Mat4} [matrix] A matrix by which to multiply all the vertices.
+ * @return {Object.} The created plane vertices.
+ * @memberOf module:twgl/primitives
+ */
+
+
+function createPlaneVertices(width, depth, subdivisionsWidth, subdivisionsDepth, matrix) {
+ width = width || 1;
+ depth = depth || 1;
+ subdivisionsWidth = subdivisionsWidth || 1;
+ subdivisionsDepth = subdivisionsDepth || 1;
+ matrix = matrix || m4.identity();
+ var numVertices = (subdivisionsWidth + 1) * (subdivisionsDepth + 1);
+ var positions = createAugmentedTypedArray(3, numVertices);
+ var normals = createAugmentedTypedArray(3, numVertices);
+ var texcoords = createAugmentedTypedArray(2, numVertices);
+
+ for (var z = 0; z <= subdivisionsDepth; z++) {
+ for (var x = 0; x <= subdivisionsWidth; x++) {
+ var u = x / subdivisionsWidth;
+ var v = z / subdivisionsDepth;
+ positions.push(width * u - width * 0.5, 0, depth * v - depth * 0.5);
+ normals.push(0, 1, 0);
+ texcoords.push(u, v);
+ }
+ }
+
+ var numVertsAcross = subdivisionsWidth + 1;
+ var indices = createAugmentedTypedArray(3, subdivisionsWidth * subdivisionsDepth * 2, Uint16Array);
+
+ for (var _z = 0; _z < subdivisionsDepth; _z++) {
+ // eslint-disable-line
+ for (var _x = 0; _x < subdivisionsWidth; _x++) {
+ // eslint-disable-line
+ // Make triangle 1 of quad.
+ indices.push((_z + 0) * numVertsAcross + _x, (_z + 1) * numVertsAcross + _x, (_z + 0) * numVertsAcross + _x + 1); // Make triangle 2 of quad.
+
+ indices.push((_z + 1) * numVertsAcross + _x, (_z + 1) * numVertsAcross + _x + 1, (_z + 0) * numVertsAcross + _x + 1);
+ }
+ }
+
+ var arrays = reorientVertices({
+ position: positions,
+ normal: normals,
+ texcoord: texcoords,
+ indices: indices
+ }, matrix);
+ return arrays;
+}
+/**
+ * Creates sphere BufferInfo.
+ *
+ * The created sphere has position, normal, and texcoord data
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} radius radius of the sphere.
+ * @param {number} subdivisionsAxis number of steps around the sphere.
+ * @param {number} subdivisionsHeight number of vertically on the sphere.
+ * @param {number} [opt_startLatitudeInRadians] where to start the
+ * top of the sphere. Default = 0.
+ * @param {number} [opt_endLatitudeInRadians] Where to end the
+ * bottom of the sphere. Default = Math.PI.
+ * @param {number} [opt_startLongitudeInRadians] where to start
+ * wrapping the sphere. Default = 0.
+ * @param {number} [opt_endLongitudeInRadians] where to end
+ * wrapping the sphere. Default = 2 * Math.PI.
+ * @return {module:twgl.BufferInfo} The created sphere BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createSphereBufferInfo
+ */
+
+/**
+ * Creates sphere buffers.
+ *
+ * The created sphere has position, normal, and texcoord data
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} radius radius of the sphere.
+ * @param {number} subdivisionsAxis number of steps around the sphere.
+ * @param {number} subdivisionsHeight number of vertically on the sphere.
+ * @param {number} [opt_startLatitudeInRadians] where to start the
+ * top of the sphere. Default = 0.
+ * @param {number} [opt_endLatitudeInRadians] Where to end the
+ * bottom of the sphere. Default = Math.PI.
+ * @param {number} [opt_startLongitudeInRadians] where to start
+ * wrapping the sphere. Default = 0.
+ * @param {number} [opt_endLongitudeInRadians] where to end
+ * wrapping the sphere. Default = 2 * Math.PI.
+ * @return {Object.} The created sphere buffers.
+ * @memberOf module:twgl/primitives
+ * @function createSphereBuffers
+ */
+
+/**
+ * Creates sphere vertices.
+ *
+ * The created sphere has position, normal, and texcoord data
+ *
+ * @param {number} radius radius of the sphere.
+ * @param {number} subdivisionsAxis number of steps around the sphere.
+ * @param {number} subdivisionsHeight number of vertically on the sphere.
+ * @param {number} [opt_startLatitudeInRadians] where to start the
+ * top of the sphere. Default = 0.
+ * @param {number} [opt_endLatitudeInRadians] Where to end the
+ * bottom of the sphere. Default = Math.PI.
+ * @param {number} [opt_startLongitudeInRadians] where to start
+ * wrapping the sphere. Default = 0.
+ * @param {number} [opt_endLongitudeInRadians] where to end
+ * wrapping the sphere. Default = 2 * Math.PI.
+ * @return {Object.} The created sphere vertices.
+ * @memberOf module:twgl/primitives
+ */
+
+
+function createSphereVertices(radius, subdivisionsAxis, subdivisionsHeight, opt_startLatitudeInRadians, opt_endLatitudeInRadians, opt_startLongitudeInRadians, opt_endLongitudeInRadians) {
+ if (subdivisionsAxis <= 0 || subdivisionsHeight <= 0) {
+ throw new Error('subdivisionAxis and subdivisionHeight must be > 0');
+ }
+
+ opt_startLatitudeInRadians = opt_startLatitudeInRadians || 0;
+ opt_endLatitudeInRadians = opt_endLatitudeInRadians || Math.PI;
+ opt_startLongitudeInRadians = opt_startLongitudeInRadians || 0;
+ opt_endLongitudeInRadians = opt_endLongitudeInRadians || Math.PI * 2;
+ var latRange = opt_endLatitudeInRadians - opt_startLatitudeInRadians;
+ var longRange = opt_endLongitudeInRadians - opt_startLongitudeInRadians; // We are going to generate our sphere by iterating through its
+ // spherical coordinates and generating 2 triangles for each quad on a
+ // ring of the sphere.
+
+ var numVertices = (subdivisionsAxis + 1) * (subdivisionsHeight + 1);
+ var positions = createAugmentedTypedArray(3, numVertices);
+ var normals = createAugmentedTypedArray(3, numVertices);
+ var texcoords = createAugmentedTypedArray(2, numVertices); // Generate the individual vertices in our vertex buffer.
+
+ for (var y = 0; y <= subdivisionsHeight; y++) {
+ for (var x = 0; x <= subdivisionsAxis; x++) {
+ // Generate a vertex based on its spherical coordinates
+ var u = x / subdivisionsAxis;
+ var v = y / subdivisionsHeight;
+ var theta = longRange * u + opt_startLongitudeInRadians;
+ var phi = latRange * v + opt_startLatitudeInRadians;
+ var sinTheta = Math.sin(theta);
+ var cosTheta = Math.cos(theta);
+ var sinPhi = Math.sin(phi);
+ var cosPhi = Math.cos(phi);
+ var ux = cosTheta * sinPhi;
+ var uy = cosPhi;
+ var uz = sinTheta * sinPhi;
+ positions.push(radius * ux, radius * uy, radius * uz);
+ normals.push(ux, uy, uz);
+ texcoords.push(1 - u, v);
+ }
+ }
+
+ var numVertsAround = subdivisionsAxis + 1;
+ var indices = createAugmentedTypedArray(3, subdivisionsAxis * subdivisionsHeight * 2, Uint16Array);
+
+ for (var _x2 = 0; _x2 < subdivisionsAxis; _x2++) {
+ // eslint-disable-line
+ for (var _y = 0; _y < subdivisionsHeight; _y++) {
+ // eslint-disable-line
+ // Make triangle 1 of quad.
+ indices.push((_y + 0) * numVertsAround + _x2, (_y + 0) * numVertsAround + _x2 + 1, (_y + 1) * numVertsAround + _x2); // Make triangle 2 of quad.
+
+ indices.push((_y + 1) * numVertsAround + _x2, (_y + 0) * numVertsAround + _x2 + 1, (_y + 1) * numVertsAround + _x2 + 1);
+ }
+ }
+
+ return {
+ position: positions,
+ normal: normals,
+ texcoord: texcoords,
+ indices: indices
+ };
+}
+/**
+ * Array of the indices of corners of each face of a cube.
+ * @type {Array.}
+ * @private
+ */
+
+
+var CUBE_FACE_INDICES = [[3, 7, 5, 1], // right
+[6, 2, 0, 4], // left
+[6, 7, 3, 2], // ??
+[0, 1, 5, 4], // ??
+[7, 6, 4, 5], // front
+[2, 3, 1, 0] // back
+];
+/**
+ * Creates a BufferInfo for a cube.
+ *
+ * The cube is created around the origin. (-size / 2, size / 2).
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} [size] width, height and depth of the cube.
+ * @return {module:twgl.BufferInfo} The created BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createCubeBufferInfo
+ */
+
+/**
+ * Creates the buffers and indices for a cube.
+ *
+ * The cube is created around the origin. (-size / 2, size / 2).
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} [size] width, height and depth of the cube.
+ * @return {Object.} The created buffers.
+ * @memberOf module:twgl/primitives
+ * @function createCubeBuffers
+ */
+
+/**
+ * Creates the vertices and indices for a cube.
+ *
+ * The cube is created around the origin. (-size / 2, size / 2).
+ *
+ * @param {number} [size] width, height and depth of the cube.
+ * @return {Object.} The created vertices.
+ * @memberOf module:twgl/primitives
+ */
+
+function createCubeVertices(size) {
+ size = size || 1;
+ var k = size / 2;
+ var cornerVertices = [[-k, -k, -k], [+k, -k, -k], [-k, +k, -k], [+k, +k, -k], [-k, -k, +k], [+k, -k, +k], [-k, +k, +k], [+k, +k, +k]];
+ var faceNormals = [[+1, +0, +0], [-1, +0, +0], [+0, +1, +0], [+0, -1, +0], [+0, +0, +1], [+0, +0, -1]];
+ var uvCoords = [[1, 0], [0, 0], [0, 1], [1, 1]];
+ var numVertices = 6 * 4;
+ var positions = createAugmentedTypedArray(3, numVertices);
+ var normals = createAugmentedTypedArray(3, numVertices);
+ var texcoords = createAugmentedTypedArray(2, numVertices);
+ var indices = createAugmentedTypedArray(3, 6 * 2, Uint16Array);
+
+ for (var f = 0; f < 6; ++f) {
+ var faceIndices = CUBE_FACE_INDICES[f];
+
+ for (var v = 0; v < 4; ++v) {
+ var position = cornerVertices[faceIndices[v]];
+ var normal = faceNormals[f];
+ var uv = uvCoords[v]; // Each face needs all four vertices because the normals and texture
+ // coordinates are not all the same.
+
+ positions.push(position);
+ normals.push(normal);
+ texcoords.push(uv);
+ } // Two triangles make a square face.
+
+
+ var offset = 4 * f;
+ indices.push(offset + 0, offset + 1, offset + 2);
+ indices.push(offset + 0, offset + 2, offset + 3);
+ }
+
+ return {
+ position: positions,
+ normal: normals,
+ texcoord: texcoords,
+ indices: indices
+ };
+}
+/**
+ * Creates a BufferInfo for a truncated cone, which is like a cylinder
+ * except that it has different top and bottom radii. A truncated cone
+ * can also be used to create cylinders and regular cones. The
+ * truncated cone will be created centered about the origin, with the
+ * y axis as its vertical axis.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} bottomRadius Bottom radius of truncated cone.
+ * @param {number} topRadius Top radius of truncated cone.
+ * @param {number} height Height of truncated cone.
+ * @param {number} radialSubdivisions The number of subdivisions around the
+ * truncated cone.
+ * @param {number} verticalSubdivisions The number of subdivisions down the
+ * truncated cone.
+ * @param {boolean} [opt_topCap] Create top cap. Default = true.
+ * @param {boolean} [opt_bottomCap] Create bottom cap. Default = true.
+ * @return {module:twgl.BufferInfo} The created cone BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createTruncatedConeBufferInfo
+ */
+
+/**
+ * Creates buffers for a truncated cone, which is like a cylinder
+ * except that it has different top and bottom radii. A truncated cone
+ * can also be used to create cylinders and regular cones. The
+ * truncated cone will be created centered about the origin, with the
+ * y axis as its vertical axis.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} bottomRadius Bottom radius of truncated cone.
+ * @param {number} topRadius Top radius of truncated cone.
+ * @param {number} height Height of truncated cone.
+ * @param {number} radialSubdivisions The number of subdivisions around the
+ * truncated cone.
+ * @param {number} verticalSubdivisions The number of subdivisions down the
+ * truncated cone.
+ * @param {boolean} [opt_topCap] Create top cap. Default = true.
+ * @param {boolean} [opt_bottomCap] Create bottom cap. Default = true.
+ * @return {Object.} The created cone buffers.
+ * @memberOf module:twgl/primitives
+ * @function createTruncatedConeBuffers
+ */
+
+/**
+ * Creates vertices for a truncated cone, which is like a cylinder
+ * except that it has different top and bottom radii. A truncated cone
+ * can also be used to create cylinders and regular cones. The
+ * truncated cone will be created centered about the origin, with the
+ * y axis as its vertical axis. .
+ *
+ * @param {number} bottomRadius Bottom radius of truncated cone.
+ * @param {number} topRadius Top radius of truncated cone.
+ * @param {number} height Height of truncated cone.
+ * @param {number} radialSubdivisions The number of subdivisions around the
+ * truncated cone.
+ * @param {number} verticalSubdivisions The number of subdivisions down the
+ * truncated cone.
+ * @param {boolean} [opt_topCap] Create top cap. Default = true.
+ * @param {boolean} [opt_bottomCap] Create bottom cap. Default = true.
+ * @return {Object.} The created cone vertices.
+ * @memberOf module:twgl/primitives
+ */
+
+
+function createTruncatedConeVertices(bottomRadius, topRadius, height, radialSubdivisions, verticalSubdivisions, opt_topCap, opt_bottomCap) {
+ if (radialSubdivisions < 3) {
+ throw new Error('radialSubdivisions must be 3 or greater');
+ }
+
+ if (verticalSubdivisions < 1) {
+ throw new Error('verticalSubdivisions must be 1 or greater');
+ }
+
+ var topCap = opt_topCap === undefined ? true : opt_topCap;
+ var bottomCap = opt_bottomCap === undefined ? true : opt_bottomCap;
+ var extra = (topCap ? 2 : 0) + (bottomCap ? 2 : 0);
+ var numVertices = (radialSubdivisions + 1) * (verticalSubdivisions + 1 + extra);
+ var positions = createAugmentedTypedArray(3, numVertices);
+ var normals = createAugmentedTypedArray(3, numVertices);
+ var texcoords = createAugmentedTypedArray(2, numVertices);
+ var indices = createAugmentedTypedArray(3, radialSubdivisions * (verticalSubdivisions + extra) * 2, Uint16Array);
+ var vertsAroundEdge = radialSubdivisions + 1; // The slant of the cone is constant across its surface
+
+ var slant = Math.atan2(bottomRadius - topRadius, height);
+ var cosSlant = Math.cos(slant);
+ var sinSlant = Math.sin(slant);
+ var start = topCap ? -2 : 0;
+ var end = verticalSubdivisions + (bottomCap ? 2 : 0);
+
+ for (var yy = start; yy <= end; ++yy) {
+ var v = yy / verticalSubdivisions;
+ var y = height * v;
+ var ringRadius = void 0;
+
+ if (yy < 0) {
+ y = 0;
+ v = 1;
+ ringRadius = bottomRadius;
+ } else if (yy > verticalSubdivisions) {
+ y = height;
+ v = 1;
+ ringRadius = topRadius;
+ } else {
+ ringRadius = bottomRadius + (topRadius - bottomRadius) * (yy / verticalSubdivisions);
+ }
+
+ if (yy === -2 || yy === verticalSubdivisions + 2) {
+ ringRadius = 0;
+ v = 0;
+ }
+
+ y -= height / 2;
+
+ for (var ii = 0; ii < vertsAroundEdge; ++ii) {
+ var sin = Math.sin(ii * Math.PI * 2 / radialSubdivisions);
+ var cos = Math.cos(ii * Math.PI * 2 / radialSubdivisions);
+ positions.push(sin * ringRadius, y, cos * ringRadius);
+
+ if (yy < 0) {
+ normals.push(0, -1, 0);
+ } else if (yy > verticalSubdivisions) {
+ normals.push(0, 1, 0);
+ } else if (ringRadius === 0.0) {
+ normals.push(0, 0, 0);
+ } else {
+ normals.push(sin * cosSlant, sinSlant, cos * cosSlant);
+ }
+
+ texcoords.push(ii / radialSubdivisions, 1 - v);
+ }
+ }
+
+ for (var _yy = 0; _yy < verticalSubdivisions + extra; ++_yy) {
+ // eslint-disable-line
+ for (var _ii = 0; _ii < radialSubdivisions; ++_ii) {
+ // eslint-disable-line
+ indices.push(vertsAroundEdge * (_yy + 0) + 0 + _ii, vertsAroundEdge * (_yy + 0) + 1 + _ii, vertsAroundEdge * (_yy + 1) + 1 + _ii);
+ indices.push(vertsAroundEdge * (_yy + 0) + 0 + _ii, vertsAroundEdge * (_yy + 1) + 1 + _ii, vertsAroundEdge * (_yy + 1) + 0 + _ii);
+ }
+ }
+
+ return {
+ position: positions,
+ normal: normals,
+ texcoord: texcoords,
+ indices: indices
+ };
+}
+/**
+ * Expands RLE data
+ * @param {number[]} rleData data in format of run-length, x, y, z, run-length, x, y, z
+ * @param {number[]} [padding] value to add each entry with.
+ * @return {number[]} the expanded rleData
+ * @private
+ */
+
+
+function expandRLEData(rleData, padding) {
+ padding = padding || [];
+ var data = [];
+
+ for (var ii = 0; ii < rleData.length; ii += 4) {
+ var runLength = rleData[ii];
+ var element = rleData.slice(ii + 1, ii + 4);
+ element.push.apply(element, padding);
+
+ for (var jj = 0; jj < runLength; ++jj) {
+ data.push.apply(data, element);
+ }
+ }
+
+ return data;
+}
+/**
+ * Creates 3D 'F' BufferInfo.
+ * An 'F' is useful because you can easily tell which way it is oriented.
+ * The created 'F' has position, normal, texcoord, and color buffers.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @return {module:twgl.BufferInfo} The created BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function create3DFBufferInfo
+ */
+
+/**
+ * Creates 3D 'F' buffers.
+ * An 'F' is useful because you can easily tell which way it is oriented.
+ * The created 'F' has position, normal, texcoord, and color buffers.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @return {Object.} The created buffers.
+ * @memberOf module:twgl/primitives
+ * @function create3DFBuffers
+ */
+
+/**
+ * Creates 3D 'F' vertices.
+ * An 'F' is useful because you can easily tell which way it is oriented.
+ * The created 'F' has position, normal, texcoord, and color arrays.
+ *
+ * @return {Object.} The created vertices.
+ * @memberOf module:twgl/primitives
+ */
+
+
+function create3DFVertices() {
+ var positions = [// left column front
+ 0, 0, 0, 0, 150, 0, 30, 0, 0, 0, 150, 0, 30, 150, 0, 30, 0, 0, // top rung front
+ 30, 0, 0, 30, 30, 0, 100, 0, 0, 30, 30, 0, 100, 30, 0, 100, 0, 0, // middle rung front
+ 30, 60, 0, 30, 90, 0, 67, 60, 0, 30, 90, 0, 67, 90, 0, 67, 60, 0, // left column back
+ 0, 0, 30, 30, 0, 30, 0, 150, 30, 0, 150, 30, 30, 0, 30, 30, 150, 30, // top rung back
+ 30, 0, 30, 100, 0, 30, 30, 30, 30, 30, 30, 30, 100, 0, 30, 100, 30, 30, // middle rung back
+ 30, 60, 30, 67, 60, 30, 30, 90, 30, 30, 90, 30, 67, 60, 30, 67, 90, 30, // top
+ 0, 0, 0, 100, 0, 0, 100, 0, 30, 0, 0, 0, 100, 0, 30, 0, 0, 30, // top rung front
+ 100, 0, 0, 100, 30, 0, 100, 30, 30, 100, 0, 0, 100, 30, 30, 100, 0, 30, // under top rung
+ 30, 30, 0, 30, 30, 30, 100, 30, 30, 30, 30, 0, 100, 30, 30, 100, 30, 0, // between top rung and middle
+ 30, 30, 0, 30, 60, 30, 30, 30, 30, 30, 30, 0, 30, 60, 0, 30, 60, 30, // top of middle rung
+ 30, 60, 0, 67, 60, 30, 30, 60, 30, 30, 60, 0, 67, 60, 0, 67, 60, 30, // front of middle rung
+ 67, 60, 0, 67, 90, 30, 67, 60, 30, 67, 60, 0, 67, 90, 0, 67, 90, 30, // bottom of middle rung.
+ 30, 90, 0, 30, 90, 30, 67, 90, 30, 30, 90, 0, 67, 90, 30, 67, 90, 0, // front of bottom
+ 30, 90, 0, 30, 150, 30, 30, 90, 30, 30, 90, 0, 30, 150, 0, 30, 150, 30, // bottom
+ 0, 150, 0, 0, 150, 30, 30, 150, 30, 0, 150, 0, 30, 150, 30, 30, 150, 0, // left side
+ 0, 0, 0, 0, 0, 30, 0, 150, 30, 0, 0, 0, 0, 150, 30, 0, 150, 0];
+ var texcoords = [// left column front
+ 0.22, 0.19, 0.22, 0.79, 0.34, 0.19, 0.22, 0.79, 0.34, 0.79, 0.34, 0.19, // top rung front
+ 0.34, 0.19, 0.34, 0.31, 0.62, 0.19, 0.34, 0.31, 0.62, 0.31, 0.62, 0.19, // middle rung front
+ 0.34, 0.43, 0.34, 0.55, 0.49, 0.43, 0.34, 0.55, 0.49, 0.55, 0.49, 0.43, // left column back
+ 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, // top rung back
+ 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, // middle rung back
+ 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, // top
+ 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, // top rung front
+ 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, // under top rung
+ 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, // between top rung and middle
+ 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, // top of middle rung
+ 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, // front of middle rung
+ 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, // bottom of middle rung.
+ 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, // front of bottom
+ 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, // bottom
+ 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, // left side
+ 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0];
+ var normals = expandRLEData([// left column front
+ // top rung front
+ // middle rung front
+ 18, 0, 0, 1, // left column back
+ // top rung back
+ // middle rung back
+ 18, 0, 0, -1, // top
+ 6, 0, 1, 0, // top rung front
+ 6, 1, 0, 0, // under top rung
+ 6, 0, -1, 0, // between top rung and middle
+ 6, 1, 0, 0, // top of middle rung
+ 6, 0, 1, 0, // front of middle rung
+ 6, 1, 0, 0, // bottom of middle rung.
+ 6, 0, -1, 0, // front of bottom
+ 6, 1, 0, 0, // bottom
+ 6, 0, -1, 0, // left side
+ 6, -1, 0, 0]);
+ var colors = expandRLEData([// left column front
+ // top rung front
+ // middle rung front
+ 18, 200, 70, 120, // left column back
+ // top rung back
+ // middle rung back
+ 18, 80, 70, 200, // top
+ 6, 70, 200, 210, // top rung front
+ 6, 200, 200, 70, // under top rung
+ 6, 210, 100, 70, // between top rung and middle
+ 6, 210, 160, 70, // top of middle rung
+ 6, 70, 180, 210, // front of middle rung
+ 6, 100, 70, 210, // bottom of middle rung.
+ 6, 76, 210, 100, // front of bottom
+ 6, 140, 210, 80, // bottom
+ 6, 90, 130, 110, // left side
+ 6, 160, 160, 220], [255]);
+ var numVerts = positions.length / 3;
+ var arrays = {
+ position: createAugmentedTypedArray(3, numVerts),
+ texcoord: createAugmentedTypedArray(2, numVerts),
+ normal: createAugmentedTypedArray(3, numVerts),
+ color: createAugmentedTypedArray(4, numVerts, Uint8Array),
+ indices: createAugmentedTypedArray(3, numVerts / 3, Uint16Array)
+ };
+ arrays.position.push(positions);
+ arrays.texcoord.push(texcoords);
+ arrays.normal.push(normals);
+ arrays.color.push(colors);
+
+ for (var ii = 0; ii < numVerts; ++ii) {
+ arrays.indices.push(ii);
+ }
+
+ return arrays;
+}
+/**
+ * Creates crescent BufferInfo.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} verticalRadius The vertical radius of the crescent.
+ * @param {number} outerRadius The outer radius of the crescent.
+ * @param {number} innerRadius The inner radius of the crescent.
+ * @param {number} thickness The thickness of the crescent.
+ * @param {number} subdivisionsDown number of steps around the crescent.
+ * @param {number} [startOffset] Where to start arc. Default 0.
+ * @param {number} [endOffset] Where to end arg. Default 1.
+ * @return {module:twgl.BufferInfo} The created BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createCresentBufferInfo
+ */
+
+/**
+ * Creates crescent buffers.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} verticalRadius The vertical radius of the crescent.
+ * @param {number} outerRadius The outer radius of the crescent.
+ * @param {number} innerRadius The inner radius of the crescent.
+ * @param {number} thickness The thickness of the crescent.
+ * @param {number} subdivisionsDown number of steps around the crescent.
+ * @param {number} [startOffset] Where to start arc. Default 0.
+ * @param {number} [endOffset] Where to end arg. Default 1.
+ * @return {Object.} The created buffers.
+ * @memberOf module:twgl/primitives
+ * @function createCresentBuffers
+ */
+
+/**
+ * Creates crescent vertices.
+ *
+ * @param {number} verticalRadius The vertical radius of the crescent.
+ * @param {number} outerRadius The outer radius of the crescent.
+ * @param {number} innerRadius The inner radius of the crescent.
+ * @param {number} thickness The thickness of the crescent.
+ * @param {number} subdivisionsDown number of steps around the crescent.
+ * @param {number} [startOffset] Where to start arc. Default 0.
+ * @param {number} [endOffset] Where to end arg. Default 1.
+ * @return {Object.} The created vertices.
+ * @memberOf module:twgl/primitives
+ * @function createCresentBuffers
+ */
+
+/**
+ * Creates crescent BufferInfo.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} verticalRadius The vertical radius of the crescent.
+ * @param {number} outerRadius The outer radius of the crescent.
+ * @param {number} innerRadius The inner radius of the crescent.
+ * @param {number} thickness The thickness of the crescent.
+ * @param {number} subdivisionsDown number of steps around the crescent.
+ * @param {number} [startOffset] Where to start arc. Default 0.
+ * @param {number} [endOffset] Where to end arg. Default 1.
+ * @return {module:twgl.BufferInfo} The created BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createCrescentBufferInfo
+ */
+
+/**
+ * Creates crescent buffers.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} verticalRadius The vertical radius of the crescent.
+ * @param {number} outerRadius The outer radius of the crescent.
+ * @param {number} innerRadius The inner radius of the crescent.
+ * @param {number} thickness The thickness of the crescent.
+ * @param {number} subdivisionsDown number of steps around the crescent.
+ * @param {number} [startOffset] Where to start arc. Default 0.
+ * @param {number} [endOffset] Where to end arg. Default 1.
+ * @return {Object.} The created buffers.
+ * @memberOf module:twgl/primitives
+ * @function createCrescentBuffers
+ */
+
+/**
+ * Creates crescent vertices.
+ *
+ * @param {number} verticalRadius The vertical radius of the crescent.
+ * @param {number} outerRadius The outer radius of the crescent.
+ * @param {number} innerRadius The inner radius of the crescent.
+ * @param {number} thickness The thickness of the crescent.
+ * @param {number} subdivisionsDown number of steps around the crescent.
+ * @param {number} [startOffset] Where to start arc. Default 0.
+ * @param {number} [endOffset] Where to end arg. Default 1.
+ * @return {Object.} The created vertices.
+ * @memberOf module:twgl/primitives
+ */
+
+
+function createCrescentVertices(verticalRadius, outerRadius, innerRadius, thickness, subdivisionsDown, startOffset, endOffset) {
+ if (subdivisionsDown <= 0) {
+ throw new Error('subdivisionDown must be > 0');
+ }
+
+ startOffset = startOffset || 0;
+ endOffset = endOffset || 1;
+ var subdivisionsThick = 2;
+ var offsetRange = endOffset - startOffset;
+ var numVertices = (subdivisionsDown + 1) * 2 * (2 + subdivisionsThick);
+ var positions = createAugmentedTypedArray(3, numVertices);
+ var normals = createAugmentedTypedArray(3, numVertices);
+ var texcoords = createAugmentedTypedArray(2, numVertices);
+
+ function lerp(a, b, s) {
+ return a + (b - a) * s;
+ }
+
+ function createArc(arcRadius, x, normalMult, normalAdd, uMult, uAdd) {
+ for (var z = 0; z <= subdivisionsDown; z++) {
+ var uBack = x / (subdivisionsThick - 1);
+ var v = z / subdivisionsDown;
+ var xBack = (uBack - 0.5) * 2;
+ var angle = (startOffset + v * offsetRange) * Math.PI;
+ var s = Math.sin(angle);
+ var c = Math.cos(angle);
+ var radius = lerp(verticalRadius, arcRadius, s);
+ var px = xBack * thickness;
+ var py = c * verticalRadius;
+ var pz = s * radius;
+ positions.push(px, py, pz);
+ var n = v3.add(v3.multiply([0, s, c], normalMult), normalAdd);
+ normals.push(n);
+ texcoords.push(uBack * uMult + uAdd, v);
+ }
+ } // Generate the individual vertices in our vertex buffer.
+
+
+ for (var x = 0; x < subdivisionsThick; x++) {
+ var uBack = (x / (subdivisionsThick - 1) - 0.5) * 2;
+ createArc(outerRadius, x, [1, 1, 1], [0, 0, 0], 1, 0);
+ createArc(outerRadius, x, [0, 0, 0], [uBack, 0, 0], 0, 0);
+ createArc(innerRadius, x, [1, 1, 1], [0, 0, 0], 1, 0);
+ createArc(innerRadius, x, [0, 0, 0], [uBack, 0, 0], 0, 1);
+ } // Do outer surface.
+
+
+ var indices = createAugmentedTypedArray(3, subdivisionsDown * 2 * (2 + subdivisionsThick), Uint16Array);
+
+ function createSurface(leftArcOffset, rightArcOffset) {
+ for (var z = 0; z < subdivisionsDown; ++z) {
+ // Make triangle 1 of quad.
+ indices.push(leftArcOffset + z + 0, leftArcOffset + z + 1, rightArcOffset + z + 0); // Make triangle 2 of quad.
+
+ indices.push(leftArcOffset + z + 1, rightArcOffset + z + 1, rightArcOffset + z + 0);
+ }
+ }
+
+ var numVerticesDown = subdivisionsDown + 1; // front
+
+ createSurface(numVerticesDown * 0, numVerticesDown * 4); // right
+
+ createSurface(numVerticesDown * 5, numVerticesDown * 7); // back
+
+ createSurface(numVerticesDown * 6, numVerticesDown * 2); // left
+
+ createSurface(numVerticesDown * 3, numVerticesDown * 1);
+ return {
+ position: positions,
+ normal: normals,
+ texcoord: texcoords,
+ indices: indices
+ };
+}
+/**
+ * Creates cylinder BufferInfo. The cylinder will be created around the origin
+ * along the y-axis.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} radius Radius of cylinder.
+ * @param {number} height Height of cylinder.
+ * @param {number} radialSubdivisions The number of subdivisions around the cylinder.
+ * @param {number} verticalSubdivisions The number of subdivisions down the cylinder.
+ * @param {boolean} [topCap] Create top cap. Default = true.
+ * @param {boolean} [bottomCap] Create bottom cap. Default = true.
+ * @return {module:twgl.BufferInfo} The created BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createCylinderBufferInfo
+ */
+
+/**
+ * Creates cylinder buffers. The cylinder will be created around the origin
+ * along the y-axis.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} radius Radius of cylinder.
+ * @param {number} height Height of cylinder.
+ * @param {number} radialSubdivisions The number of subdivisions around the cylinder.
+ * @param {number} verticalSubdivisions The number of subdivisions down the cylinder.
+ * @param {boolean} [topCap] Create top cap. Default = true.
+ * @param {boolean} [bottomCap] Create bottom cap. Default = true.
+ * @return {Object.} The created buffers.
+ * @memberOf module:twgl/primitives
+ * @function createCylinderBuffers
+ */
+
+/**
+ * Creates cylinder vertices. The cylinder will be created around the origin
+ * along the y-axis.
+ *
+ * @param {number} radius Radius of cylinder.
+ * @param {number} height Height of cylinder.
+ * @param {number} radialSubdivisions The number of subdivisions around the cylinder.
+ * @param {number} verticalSubdivisions The number of subdivisions down the cylinder.
+ * @param {boolean} [topCap] Create top cap. Default = true.
+ * @param {boolean} [bottomCap] Create bottom cap. Default = true.
+ * @return {Object.} The created vertices.
+ * @memberOf module:twgl/primitives
+ */
+
+
+function createCylinderVertices(radius, height, radialSubdivisions, verticalSubdivisions, topCap, bottomCap) {
+ return createTruncatedConeVertices(radius, radius, height, radialSubdivisions, verticalSubdivisions, topCap, bottomCap);
+}
+/**
+ * Creates BufferInfo for a torus
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} radius radius of center of torus circle.
+ * @param {number} thickness radius of torus ring.
+ * @param {number} radialSubdivisions The number of subdivisions around the torus.
+ * @param {number} bodySubdivisions The number of subdivisions around the body torus.
+ * @param {boolean} [startAngle] start angle in radians. Default = 0.
+ * @param {boolean} [endAngle] end angle in radians. Default = Math.PI * 2.
+ * @return {module:twgl.BufferInfo} The created BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createTorusBufferInfo
+ */
+
+/**
+ * Creates buffers for a torus
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} radius radius of center of torus circle.
+ * @param {number} thickness radius of torus ring.
+ * @param {number} radialSubdivisions The number of subdivisions around the torus.
+ * @param {number} bodySubdivisions The number of subdivisions around the body torus.
+ * @param {boolean} [startAngle] start angle in radians. Default = 0.
+ * @param {boolean} [endAngle] end angle in radians. Default = Math.PI * 2.
+ * @return {Object.} The created buffers.
+ * @memberOf module:twgl/primitives
+ * @function createTorusBuffers
+ */
+
+/**
+ * Creates vertices for a torus
+ *
+ * @param {number} radius radius of center of torus circle.
+ * @param {number} thickness radius of torus ring.
+ * @param {number} radialSubdivisions The number of subdivisions around the torus.
+ * @param {number} bodySubdivisions The number of subdivisions around the body torus.
+ * @param {boolean} [startAngle] start angle in radians. Default = 0.
+ * @param {boolean} [endAngle] end angle in radians. Default = Math.PI * 2.
+ * @return {Object.} The created vertices.
+ * @memberOf module:twgl/primitives
+ */
+
+
+function createTorusVertices(radius, thickness, radialSubdivisions, bodySubdivisions, startAngle, endAngle) {
+ if (radialSubdivisions < 3) {
+ throw new Error('radialSubdivisions must be 3 or greater');
+ }
+
+ if (bodySubdivisions < 3) {
+ throw new Error('verticalSubdivisions must be 3 or greater');
+ }
+
+ startAngle = startAngle || 0;
+ endAngle = endAngle || Math.PI * 2;
+ var range = endAngle - startAngle;
+ var radialParts = radialSubdivisions + 1;
+ var bodyParts = bodySubdivisions + 1;
+ var numVertices = radialParts * bodyParts;
+ var positions = createAugmentedTypedArray(3, numVertices);
+ var normals = createAugmentedTypedArray(3, numVertices);
+ var texcoords = createAugmentedTypedArray(2, numVertices);
+ var indices = createAugmentedTypedArray(3, radialSubdivisions * bodySubdivisions * 2, Uint16Array);
+
+ for (var slice = 0; slice < bodyParts; ++slice) {
+ var v = slice / bodySubdivisions;
+ var sliceAngle = v * Math.PI * 2;
+ var sliceSin = Math.sin(sliceAngle);
+ var ringRadius = radius + sliceSin * thickness;
+ var ny = Math.cos(sliceAngle);
+ var y = ny * thickness;
+
+ for (var ring = 0; ring < radialParts; ++ring) {
+ var u = ring / radialSubdivisions;
+ var ringAngle = startAngle + u * range;
+ var xSin = Math.sin(ringAngle);
+ var zCos = Math.cos(ringAngle);
+ var x = xSin * ringRadius;
+ var z = zCos * ringRadius;
+ var nx = xSin * sliceSin;
+ var nz = zCos * sliceSin;
+ positions.push(x, y, z);
+ normals.push(nx, ny, nz);
+ texcoords.push(u, 1 - v);
+ }
+ }
+
+ for (var _slice = 0; _slice < bodySubdivisions; ++_slice) {
+ // eslint-disable-line
+ for (var _ring = 0; _ring < radialSubdivisions; ++_ring) {
+ // eslint-disable-line
+ var nextRingIndex = 1 + _ring;
+ var nextSliceIndex = 1 + _slice;
+ indices.push(radialParts * _slice + _ring, radialParts * nextSliceIndex + _ring, radialParts * _slice + nextRingIndex);
+ indices.push(radialParts * nextSliceIndex + _ring, radialParts * nextSliceIndex + nextRingIndex, radialParts * _slice + nextRingIndex);
+ }
+ }
+
+ return {
+ position: positions,
+ normal: normals,
+ texcoord: texcoords,
+ indices: indices
+ };
+}
+/**
+ * Creates a disc BufferInfo. The disc will be in the xz plane, centered at
+ * the origin. When creating, at least 3 divisions, or pie
+ * pieces, need to be specified, otherwise the triangles making
+ * up the disc will be degenerate. You can also specify the
+ * number of radial pieces `stacks`. A value of 1 for
+ * stacks will give you a simple disc of pie pieces. If you
+ * want to create an annulus you can set `innerRadius` to a
+ * value > 0. Finally, `stackPower` allows you to have the widths
+ * increase or decrease as you move away from the center. This
+ * is particularly useful when using the disc as a ground plane
+ * with a fixed camera such that you don't need the resolution
+ * of small triangles near the perimeter. For example, a value
+ * of 2 will produce stacks whose outside radius increases with
+ * the square of the stack index. A value of 1 will give uniform
+ * stacks.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} radius Radius of the ground plane.
+ * @param {number} divisions Number of triangles in the ground plane (at least 3).
+ * @param {number} [stacks] Number of radial divisions (default=1).
+ * @param {number} [innerRadius] Default 0.
+ * @param {number} [stackPower] Power to raise stack size to for decreasing width.
+ * @return {module:twgl.BufferInfo} The created BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createDiscBufferInfo
+ */
+
+/**
+ * Creates disc buffers. The disc will be in the xz plane, centered at
+ * the origin. When creating, at least 3 divisions, or pie
+ * pieces, need to be specified, otherwise the triangles making
+ * up the disc will be degenerate. You can also specify the
+ * number of radial pieces `stacks`. A value of 1 for
+ * stacks will give you a simple disc of pie pieces. If you
+ * want to create an annulus you can set `innerRadius` to a
+ * value > 0. Finally, `stackPower` allows you to have the widths
+ * increase or decrease as you move away from the center. This
+ * is particularly useful when using the disc as a ground plane
+ * with a fixed camera such that you don't need the resolution
+ * of small triangles near the perimeter. For example, a value
+ * of 2 will produce stacks whose outside radius increases with
+ * the square of the stack index. A value of 1 will give uniform
+ * stacks.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} radius Radius of the ground plane.
+ * @param {number} divisions Number of triangles in the ground plane (at least 3).
+ * @param {number} [stacks] Number of radial divisions (default=1).
+ * @param {number} [innerRadius] Default 0.
+ * @param {number} [stackPower] Power to raise stack size to for decreasing width.
+ * @return {Object.} The created buffers.
+ * @memberOf module:twgl/primitives
+ * @function createDiscBuffers
+ */
+
+/**
+ * Creates disc vertices. The disc will be in the xz plane, centered at
+ * the origin. When creating, at least 3 divisions, or pie
+ * pieces, need to be specified, otherwise the triangles making
+ * up the disc will be degenerate. You can also specify the
+ * number of radial pieces `stacks`. A value of 1 for
+ * stacks will give you a simple disc of pie pieces. If you
+ * want to create an annulus you can set `innerRadius` to a
+ * value > 0. Finally, `stackPower` allows you to have the widths
+ * increase or decrease as you move away from the center. This
+ * is particularly useful when using the disc as a ground plane
+ * with a fixed camera such that you don't need the resolution
+ * of small triangles near the perimeter. For example, a value
+ * of 2 will produce stacks whose outside radius increases with
+ * the square of the stack index. A value of 1 will give uniform
+ * stacks.
+ *
+ * @param {number} radius Radius of the ground plane.
+ * @param {number} divisions Number of triangles in the ground plane (at least 3).
+ * @param {number} [stacks] Number of radial divisions (default=1).
+ * @param {number} [innerRadius] Default 0.
+ * @param {number} [stackPower] Power to raise stack size to for decreasing width.
+ * @return {Object.} The created vertices.
+ * @memberOf module:twgl/primitives
+ */
+
+
+function createDiscVertices(radius, divisions, stacks, innerRadius, stackPower) {
+ if (divisions < 3) {
+ throw new Error('divisions must be at least 3');
+ }
+
+ stacks = stacks ? stacks : 1;
+ stackPower = stackPower ? stackPower : 1;
+ innerRadius = innerRadius ? innerRadius : 0; // Note: We don't share the center vertex because that would
+ // mess up texture coordinates.
+
+ var numVertices = (divisions + 1) * (stacks + 1);
+ var positions = createAugmentedTypedArray(3, numVertices);
+ var normals = createAugmentedTypedArray(3, numVertices);
+ var texcoords = createAugmentedTypedArray(2, numVertices);
+ var indices = createAugmentedTypedArray(3, stacks * divisions * 2, Uint16Array);
+ var firstIndex = 0;
+ var radiusSpan = radius - innerRadius;
+ var pointsPerStack = divisions + 1; // Build the disk one stack at a time.
+
+ for (var stack = 0; stack <= stacks; ++stack) {
+ var stackRadius = innerRadius + radiusSpan * Math.pow(stack / stacks, stackPower);
+
+ for (var i = 0; i <= divisions; ++i) {
+ var theta = 2.0 * Math.PI * i / divisions;
+ var x = stackRadius * Math.cos(theta);
+ var z = stackRadius * Math.sin(theta);
+ positions.push(x, 0, z);
+ normals.push(0, 1, 0);
+ texcoords.push(1 - i / divisions, stack / stacks);
+
+ if (stack > 0 && i !== divisions) {
+ // a, b, c and d are the indices of the vertices of a quad. unless
+ // the current stack is the one closest to the center, in which case
+ // the vertices a and b connect to the center vertex.
+ var a = firstIndex + (i + 1);
+ var b = firstIndex + i;
+ var c = firstIndex + i - pointsPerStack;
+ var d = firstIndex + (i + 1) - pointsPerStack; // Make a quad of the vertices a, b, c, d.
+
+ indices.push(a, b, c);
+ indices.push(a, c, d);
+ }
+ }
+
+ firstIndex += divisions + 1;
+ }
+
+ return {
+ position: positions,
+ normal: normals,
+ texcoord: texcoords,
+ indices: indices
+ };
+}
+/**
+ * creates a random integer between 0 and range - 1 inclusive.
+ * @param {number} range
+ * @return {number} random value between 0 and range - 1 inclusive.
+ * @private
+ */
+
+
+function randInt(range) {
+ return Math.random() * range | 0;
+}
+/**
+ * Used to supply random colors
+ * @callback RandomColorFunc
+ * @param {number} ndx index of triangle/quad if unindexed or index of vertex if indexed
+ * @param {number} channel 0 = red, 1 = green, 2 = blue, 3 = alpha
+ * @return {number} a number from 0 to 255
+ * @memberOf module:twgl/primitives
+ */
+
+/**
+ * @typedef {Object} RandomVerticesOptions
+ * @property {number} [vertsPerColor] Defaults to 3 for non-indexed vertices
+ * @property {module:twgl/primitives.RandomColorFunc} [rand] A function to generate random numbers
+ * @memberOf module:twgl/primitives
+ */
+
+/**
+ * Creates an augmentedTypedArray of random vertex colors.
+ * If the vertices are indexed (have an indices array) then will
+ * just make random colors. Otherwise assumes they are triangles
+ * and makes one random color for every 3 vertices.
+ * @param {Object.} vertices Vertices as returned from one of the createXXXVertices functions.
+ * @param {module:twgl/primitives.RandomVerticesOptions} [options] options.
+ * @return {Object.} same vertices as passed in with `color` added.
+ * @memberOf module:twgl/primitives
+ */
+
+
+function makeRandomVertexColors(vertices, options) {
+ options = options || {};
+ var numElements = vertices.position.numElements;
+ var vColors = createAugmentedTypedArray(4, numElements, Uint8Array);
+
+ var rand = options.rand || function (ndx, channel) {
+ return channel < 3 ? randInt(256) : 255;
+ };
+
+ vertices.color = vColors;
+
+ if (vertices.indices) {
+ // just make random colors if index
+ for (var ii = 0; ii < numElements; ++ii) {
+ vColors.push(rand(ii, 0), rand(ii, 1), rand(ii, 2), rand(ii, 3));
+ }
+ } else {
+ // make random colors per triangle
+ var numVertsPerColor = options.vertsPerColor || 3;
+ var numSets = numElements / numVertsPerColor;
+
+ for (var _ii2 = 0; _ii2 < numSets; ++_ii2) {
+ // eslint-disable-line
+ var color = [rand(_ii2, 0), rand(_ii2, 1), rand(_ii2, 2), rand(_ii2, 3)];
+
+ for (var jj = 0; jj < numVertsPerColor; ++jj) {
+ vColors.push(color);
+ }
+ }
+ }
+
+ return vertices;
+}
+/**
+ * creates a function that calls fn to create vertices and then
+ * creates a buffers for them
+ * @private
+ */
+
+
+function createBufferFunc(fn) {
+ return function (gl) {
+ var arrays = fn.apply(this, Array.prototype.slice.call(arguments, 1));
+ return attributes.createBuffersFromArrays(gl, arrays);
+ };
+}
+/**
+ * creates a function that calls fn to create vertices and then
+ * creates a bufferInfo object for them
+ * @private
+ */
+
+
+function createBufferInfoFunc(fn) {
+ return function (gl) {
+ var arrays = fn.apply(null, Array.prototype.slice.call(arguments, 1));
+ return attributes.createBufferInfoFromArrays(gl, arrays);
+ };
+}
+
+var arraySpecPropertyNames = ["numComponents", "size", "type", "normalize", "stride", "offset", "attrib", "name", "attribName"];
+/**
+ * Copy elements from one array to another
+ *
+ * @param {Array|TypedArray} src source array
+ * @param {Array|TypedArray} dst dest array
+ * @param {number} dstNdx index in dest to copy src
+ * @param {number} [offset] offset to add to copied values
+ * @private
+ */
+
+function copyElements(src, dst, dstNdx, offset) {
+ offset = offset || 0;
+ var length = src.length;
+
+ for (var ii = 0; ii < length; ++ii) {
+ dst[dstNdx + ii] = src[ii] + offset;
+ }
+}
+/**
+ * Creates an array of the same time
+ *
+ * @param {(number[]|ArrayBufferView|module:twgl.FullArraySpec)} srcArray array who's type to copy
+ * @param {number} length size of new array
+ * @return {(number[]|ArrayBufferView|module:twgl.FullArraySpec)} array with same type as srcArray
+ * @private
+ */
+
+
+function createArrayOfSameType(srcArray, length) {
+ var arraySrc = getArray(srcArray);
+ var newArray = new arraySrc.constructor(length);
+ var newArraySpec = newArray; // If it appears to have been augmented make new one augmented
+
+ if (arraySrc.numComponents && arraySrc.numElements) {
+ augmentTypedArray(newArray, arraySrc.numComponents);
+ } // If it was a full spec make new one a full spec
+
+
+ if (srcArray.data) {
+ newArraySpec = {
+ data: newArray
+ };
+ helper.copyNamedProperties(arraySpecPropertyNames, srcArray, newArraySpec);
+ }
+
+ return newArraySpec;
+}
+/**
+ * Concatenates sets of vertices
+ *
+ * Assumes the vertices match in composition. For example
+ * if one set of vertices has positions, normals, and indices
+ * all sets of vertices must have positions, normals, and indices
+ * and of the same type.
+ *
+ * Example:
+ *
+ * const cubeVertices = twgl.primitives.createCubeVertices(2);
+ * const sphereVertices = twgl.primitives.createSphereVertices(1, 10, 10);
+ * // move the sphere 2 units up
+ * twgl.primitives.reorientVertices(
+ * sphereVertices, twgl.m4.translation([0, 2, 0]));
+ * // merge the sphere with the cube
+ * const cubeSphereVertices = twgl.primitives.concatVertices(
+ * [cubeVertices, sphereVertices]);
+ * // turn them into WebGL buffers and attrib data
+ * const bufferInfo = twgl.createBufferInfoFromArrays(gl, cubeSphereVertices);
+ *
+ * @param {module:twgl.Arrays[]} arrays Array of arrays of vertices
+ * @return {module:twgl.Arrays} The concatenated vertices.
+ * @memberOf module:twgl/primitives
+ */
+
+
+function concatVertices(arrayOfArrays) {
+ var names = {};
+ var baseName; // get names of all arrays.
+ // and numElements for each set of vertices
+
+ var _loop = function _loop(ii) {
+ var arrays = arrayOfArrays[ii];
+ Object.keys(arrays).forEach(function (name) {
+ // eslint-disable-line
+ if (!names[name]) {
+ names[name] = [];
+ }
+
+ if (!baseName && name !== 'indices') {
+ baseName = name;
+ }
+
+ var arrayInfo = arrays[name];
+ var numComponents = getNumComponents(arrayInfo, name);
+ var array = getArray(arrayInfo);
+ var numElements = array.length / numComponents;
+ names[name].push(numElements);
+ });
+ };
+
+ for (var ii = 0; ii < arrayOfArrays.length; ++ii) {
+ _loop(ii);
+ } // compute length of combined array
+ // and return one for reference
+
+
+ function getLengthOfCombinedArrays(name) {
+ var length = 0;
+ var arraySpec;
+
+ for (var _ii3 = 0; _ii3 < arrayOfArrays.length; ++_ii3) {
+ var arrays = arrayOfArrays[_ii3];
+ var arrayInfo = arrays[name];
+ var array = getArray(arrayInfo);
+ length += array.length;
+
+ if (!arraySpec || arrayInfo.data) {
+ arraySpec = arrayInfo;
+ }
+ }
+
+ return {
+ length: length,
+ spec: arraySpec
+ };
+ }
+
+ function copyArraysToNewArray(name, base, newArray) {
+ var baseIndex = 0;
+ var offset = 0;
+
+ for (var _ii4 = 0; _ii4 < arrayOfArrays.length; ++_ii4) {
+ var arrays = arrayOfArrays[_ii4];
+ var arrayInfo = arrays[name];
+ var array = getArray(arrayInfo);
+
+ if (name === 'indices') {
+ copyElements(array, newArray, offset, baseIndex);
+ baseIndex += base[_ii4];
+ } else {
+ copyElements(array, newArray, offset);
+ }
+
+ offset += array.length;
+ }
+ }
+
+ var base = names[baseName];
+ var newArrays = {};
+ Object.keys(names).forEach(function (name) {
+ var info = getLengthOfCombinedArrays(name);
+ var newArraySpec = createArrayOfSameType(info.spec, info.length);
+ copyArraysToNewArray(name, base, getArray(newArraySpec));
+ newArrays[name] = newArraySpec;
+ });
+ return newArrays;
+}
+/**
+ * Creates a duplicate set of vertices
+ *
+ * This is useful for calling reorientVertices when you
+ * also want to keep the original available
+ *
+ * @param {module:twgl.Arrays} arrays of vertices
+ * @return {module:twgl.Arrays} The duplicated vertices.
+ * @memberOf module:twgl/primitives
+ */
+
+
+function duplicateVertices(arrays) {
+ var newArrays = {};
+ Object.keys(arrays).forEach(function (name) {
+ var arraySpec = arrays[name];
+ var srcArray = getArray(arraySpec);
+ var newArraySpec = createArrayOfSameType(arraySpec, srcArray.length);
+ copyElements(srcArray, getArray(newArraySpec), 0);
+ newArrays[name] = newArraySpec;
+ });
+ return newArrays;
+}
+
+var create3DFBufferInfo = createBufferInfoFunc(create3DFVertices);
+exports.create3DFBufferInfo = create3DFBufferInfo;
+var create3DFBuffers = createBufferFunc(create3DFVertices);
+exports.create3DFBuffers = create3DFBuffers;
+var createCubeBufferInfo = createBufferInfoFunc(createCubeVertices);
+exports.createCubeBufferInfo = createCubeBufferInfo;
+var createCubeBuffers = createBufferFunc(createCubeVertices);
+exports.createCubeBuffers = createCubeBuffers;
+var createPlaneBufferInfo = createBufferInfoFunc(createPlaneVertices);
+exports.createPlaneBufferInfo = createPlaneBufferInfo;
+var createPlaneBuffers = createBufferFunc(createPlaneVertices);
+exports.createPlaneBuffers = createPlaneBuffers;
+var createSphereBufferInfo = createBufferInfoFunc(createSphereVertices);
+exports.createSphereBufferInfo = createSphereBufferInfo;
+var createSphereBuffers = createBufferFunc(createSphereVertices);
+exports.createSphereBuffers = createSphereBuffers;
+var createTruncatedConeBufferInfo = createBufferInfoFunc(createTruncatedConeVertices);
+exports.createTruncatedConeBufferInfo = createTruncatedConeBufferInfo;
+var createTruncatedConeBuffers = createBufferFunc(createTruncatedConeVertices);
+exports.createTruncatedConeBuffers = createTruncatedConeBuffers;
+var createXYQuadBufferInfo = createBufferInfoFunc(createXYQuadVertices);
+exports.createXYQuadBufferInfo = createXYQuadBufferInfo;
+var createXYQuadBuffers = createBufferFunc(createXYQuadVertices);
+exports.createXYQuadBuffers = createXYQuadBuffers;
+var createCrescentBufferInfo = createBufferInfoFunc(createCrescentVertices);
+exports.createCrescentBufferInfo = createCrescentBufferInfo;
+var createCrescentBuffers = createBufferFunc(createCrescentVertices);
+exports.createCrescentBuffers = createCrescentBuffers;
+var createCylinderBufferInfo = createBufferInfoFunc(createCylinderVertices);
+exports.createCylinderBufferInfo = createCylinderBufferInfo;
+var createCylinderBuffers = createBufferFunc(createCylinderVertices);
+exports.createCylinderBuffers = createCylinderBuffers;
+var createTorusBufferInfo = createBufferInfoFunc(createTorusVertices);
+exports.createTorusBufferInfo = createTorusBufferInfo;
+var createTorusBuffers = createBufferFunc(createTorusVertices);
+exports.createTorusBuffers = createTorusBuffers;
+var createDiscBufferInfo = createBufferInfoFunc(createDiscVertices);
+exports.createDiscBufferInfo = createDiscBufferInfo;
+var createDiscBuffers = createBufferFunc(createDiscVertices); // these were mis-spelled until 4.12
+
+exports.createDiscBuffers = createDiscBuffers;
+var createCresentBufferInfo = createCrescentBufferInfo;
+exports.createCresentBufferInfo = createCresentBufferInfo;
+var createCresentBuffers = createCrescentBuffers;
+exports.createCresentBuffers = createCresentBuffers;
+var createCresentVertices = createCrescentVertices;
+exports.createCresentVertices = createCresentVertices;
+
+/***/ }),
+
+/***/ "./src/programs.js":
+/*!*************************!*\
+ !*** ./src/programs.js ***!
+ \*************************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.createAttributeSetters = createAttributeSetters;
+exports.createProgram = createProgram;
+exports.createProgramFromScripts = createProgramFromScripts;
+exports.createProgramFromSources = createProgramFromSources;
+exports.createProgramInfo = createProgramInfo;
+exports.createProgramInfoFromProgram = createProgramInfoFromProgram;
+exports.createUniformSetters = createUniformSetters;
+exports.createUniformBlockSpecFromProgram = createUniformBlockSpecFromProgram;
+exports.createUniformBlockInfoFromProgram = createUniformBlockInfoFromProgram;
+exports.createUniformBlockInfo = createUniformBlockInfo;
+exports.createTransformFeedback = createTransformFeedback;
+exports.createTransformFeedbackInfo = createTransformFeedbackInfo;
+exports.bindTransformFeedbackInfo = bindTransformFeedbackInfo;
+exports.setAttributes = setAttributes;
+exports.setBuffersAndAttributes = setBuffersAndAttributes;
+exports.setUniforms = setUniforms;
+exports.setUniformBlock = setUniformBlock;
+exports.setBlockUniforms = setBlockUniforms;
+exports.bindUniformBlock = bindUniformBlock;
+exports.setUniformsAndBindTextures = void 0;
+
+var utils = _interopRequireWildcard(__webpack_require__(/*! ./utils.js */ "./src/utils.js"));
+
+var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
+
+function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * Low level shader program related functions
+ *
+ * You should generally not need to use these functions. They are provided
+ * for those cases where you're doing something out of the ordinary
+ * and you need lower level access.
+ *
+ * For backward compatibility they are available at both `twgl.programs` and `twgl`
+ * itself
+ *
+ * See {@link module:twgl} for core functions
+ *
+ * @module twgl/programs
+ */
+var error = helper.error;
+var warn = helper.warn;
+
+function getElementById(id) {
+ return typeof document !== 'undefined' && document.getElementById ? document.getElementById(id) : null;
+}
+
+var TEXTURE0 = 0x84c0;
+var DYNAMIC_DRAW = 0x88e8;
+var ARRAY_BUFFER = 0x8892;
+var ELEMENT_ARRAY_BUFFER = 0x8893;
+var UNIFORM_BUFFER = 0x8a11;
+var TRANSFORM_FEEDBACK_BUFFER = 0x8c8e;
+var TRANSFORM_FEEDBACK = 0x8e22;
+var COMPILE_STATUS = 0x8b81;
+var LINK_STATUS = 0x8b82;
+var FRAGMENT_SHADER = 0x8b30;
+var VERTEX_SHADER = 0x8b31;
+var SEPARATE_ATTRIBS = 0x8c8d;
+var ACTIVE_UNIFORMS = 0x8b86;
+var ACTIVE_ATTRIBUTES = 0x8b89;
+var TRANSFORM_FEEDBACK_VARYINGS = 0x8c83;
+var ACTIVE_UNIFORM_BLOCKS = 0x8a36;
+var UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER = 0x8a44;
+var UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER = 0x8a46;
+var UNIFORM_BLOCK_DATA_SIZE = 0x8a40;
+var UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES = 0x8a43;
+var FLOAT = 0x1406;
+var FLOAT_VEC2 = 0x8B50;
+var FLOAT_VEC3 = 0x8B51;
+var FLOAT_VEC4 = 0x8B52;
+var INT = 0x1404;
+var INT_VEC2 = 0x8B53;
+var INT_VEC3 = 0x8B54;
+var INT_VEC4 = 0x8B55;
+var BOOL = 0x8B56;
+var BOOL_VEC2 = 0x8B57;
+var BOOL_VEC3 = 0x8B58;
+var BOOL_VEC4 = 0x8B59;
+var FLOAT_MAT2 = 0x8B5A;
+var FLOAT_MAT3 = 0x8B5B;
+var FLOAT_MAT4 = 0x8B5C;
+var SAMPLER_2D = 0x8B5E;
+var SAMPLER_CUBE = 0x8B60;
+var SAMPLER_3D = 0x8B5F;
+var SAMPLER_2D_SHADOW = 0x8B62;
+var FLOAT_MAT2x3 = 0x8B65;
+var FLOAT_MAT2x4 = 0x8B66;
+var FLOAT_MAT3x2 = 0x8B67;
+var FLOAT_MAT3x4 = 0x8B68;
+var FLOAT_MAT4x2 = 0x8B69;
+var FLOAT_MAT4x3 = 0x8B6A;
+var SAMPLER_2D_ARRAY = 0x8DC1;
+var SAMPLER_2D_ARRAY_SHADOW = 0x8DC4;
+var SAMPLER_CUBE_SHADOW = 0x8DC5;
+var UNSIGNED_INT = 0x1405;
+var UNSIGNED_INT_VEC2 = 0x8DC6;
+var UNSIGNED_INT_VEC3 = 0x8DC7;
+var UNSIGNED_INT_VEC4 = 0x8DC8;
+var INT_SAMPLER_2D = 0x8DCA;
+var INT_SAMPLER_3D = 0x8DCB;
+var INT_SAMPLER_CUBE = 0x8DCC;
+var INT_SAMPLER_2D_ARRAY = 0x8DCF;
+var UNSIGNED_INT_SAMPLER_2D = 0x8DD2;
+var UNSIGNED_INT_SAMPLER_3D = 0x8DD3;
+var UNSIGNED_INT_SAMPLER_CUBE = 0x8DD4;
+var UNSIGNED_INT_SAMPLER_2D_ARRAY = 0x8DD7;
+var TEXTURE_2D = 0x0DE1;
+var TEXTURE_CUBE_MAP = 0x8513;
+var TEXTURE_3D = 0x806F;
+var TEXTURE_2D_ARRAY = 0x8C1A;
+var typeMap = {};
+/**
+ * Returns the corresponding bind point for a given sampler type
+ */
+
+function getBindPointForSamplerType(gl, type) {
+ return typeMap[type].bindPoint;
+} // This kind of sucks! If you could compose functions as in `var fn = gl[name];`
+// this code could be a lot smaller but that is sadly really slow (T_T)
+
+
+function floatSetter(gl, location) {
+ return function (v) {
+ gl.uniform1f(location, v);
+ };
+}
+
+function floatArraySetter(gl, location) {
+ return function (v) {
+ gl.uniform1fv(location, v);
+ };
+}
+
+function floatVec2Setter(gl, location) {
+ return function (v) {
+ gl.uniform2fv(location, v);
+ };
+}
+
+function floatVec3Setter(gl, location) {
+ return function (v) {
+ gl.uniform3fv(location, v);
+ };
+}
+
+function floatVec4Setter(gl, location) {
+ return function (v) {
+ gl.uniform4fv(location, v);
+ };
+}
+
+function intSetter(gl, location) {
+ return function (v) {
+ gl.uniform1i(location, v);
+ };
+}
+
+function intArraySetter(gl, location) {
+ return function (v) {
+ gl.uniform1iv(location, v);
+ };
+}
+
+function intVec2Setter(gl, location) {
+ return function (v) {
+ gl.uniform2iv(location, v);
+ };
+}
+
+function intVec3Setter(gl, location) {
+ return function (v) {
+ gl.uniform3iv(location, v);
+ };
+}
+
+function intVec4Setter(gl, location) {
+ return function (v) {
+ gl.uniform4iv(location, v);
+ };
+}
+
+function uintSetter(gl, location) {
+ return function (v) {
+ gl.uniform1ui(location, v);
+ };
+}
+
+function uintArraySetter(gl, location) {
+ return function (v) {
+ gl.uniform1uiv(location, v);
+ };
+}
+
+function uintVec2Setter(gl, location) {
+ return function (v) {
+ gl.uniform2uiv(location, v);
+ };
+}
+
+function uintVec3Setter(gl, location) {
+ return function (v) {
+ gl.uniform3uiv(location, v);
+ };
+}
+
+function uintVec4Setter(gl, location) {
+ return function (v) {
+ gl.uniform4uiv(location, v);
+ };
+}
+
+function floatMat2Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix2fv(location, false, v);
+ };
+}
+
+function floatMat3Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix3fv(location, false, v);
+ };
+}
+
+function floatMat4Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix4fv(location, false, v);
+ };
+}
+
+function floatMat23Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix2x3fv(location, false, v);
+ };
+}
+
+function floatMat32Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix3x2fv(location, false, v);
+ };
+}
+
+function floatMat24Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix2x4fv(location, false, v);
+ };
+}
+
+function floatMat42Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix4x2fv(location, false, v);
+ };
+}
+
+function floatMat34Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix3x4fv(location, false, v);
+ };
+}
+
+function floatMat43Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix4x3fv(location, false, v);
+ };
+}
+
+function samplerSetter(gl, type, unit, location) {
+ var bindPoint = getBindPointForSamplerType(gl, type);
+ return utils.isWebGL2(gl) ? function (textureOrPair) {
+ var texture;
+ var sampler;
+
+ if (helper.isTexture(gl, textureOrPair)) {
+ texture = textureOrPair;
+ sampler = null;
+ } else {
+ texture = textureOrPair.texture;
+ sampler = textureOrPair.sampler;
+ }
+
+ gl.uniform1i(location, unit);
+ gl.activeTexture(TEXTURE0 + unit);
+ gl.bindTexture(bindPoint, texture);
+ gl.bindSampler(unit, sampler);
+ } : function (texture) {
+ gl.uniform1i(location, unit);
+ gl.activeTexture(TEXTURE0 + unit);
+ gl.bindTexture(bindPoint, texture);
+ };
+}
+
+function samplerArraySetter(gl, type, unit, location, size) {
+ var bindPoint = getBindPointForSamplerType(gl, type);
+ var units = new Int32Array(size);
+
+ for (var ii = 0; ii < size; ++ii) {
+ units[ii] = unit + ii;
+ }
+
+ return utils.isWebGL2(gl) ? function (textures) {
+ gl.uniform1iv(location, units);
+ textures.forEach(function (textureOrPair, index) {
+ gl.activeTexture(TEXTURE0 + units[index]);
+ var texture;
+ var sampler;
+
+ if (helper.isTexture(gl, textureOrPair)) {
+ texture = textureOrPair;
+ sampler = null;
+ } else {
+ texture = textureOrPair.texture;
+ sampler = textureOrPair.sampler;
+ }
+
+ gl.bindSampler(unit, sampler);
+ gl.bindTexture(bindPoint, texture);
+ });
+ } : function (textures) {
+ gl.uniform1iv(location, units);
+ textures.forEach(function (texture, index) {
+ gl.activeTexture(TEXTURE0 + units[index]);
+ gl.bindTexture(bindPoint, texture);
+ });
+ };
+}
+
+typeMap[FLOAT] = {
+ Type: Float32Array,
+ size: 4,
+ setter: floatSetter,
+ arraySetter: floatArraySetter
+};
+typeMap[FLOAT_VEC2] = {
+ Type: Float32Array,
+ size: 8,
+ setter: floatVec2Setter
+};
+typeMap[FLOAT_VEC3] = {
+ Type: Float32Array,
+ size: 12,
+ setter: floatVec3Setter
+};
+typeMap[FLOAT_VEC4] = {
+ Type: Float32Array,
+ size: 16,
+ setter: floatVec4Setter
+};
+typeMap[INT] = {
+ Type: Int32Array,
+ size: 4,
+ setter: intSetter,
+ arraySetter: intArraySetter
+};
+typeMap[INT_VEC2] = {
+ Type: Int32Array,
+ size: 8,
+ setter: intVec2Setter
+};
+typeMap[INT_VEC3] = {
+ Type: Int32Array,
+ size: 12,
+ setter: intVec3Setter
+};
+typeMap[INT_VEC4] = {
+ Type: Int32Array,
+ size: 16,
+ setter: intVec4Setter
+};
+typeMap[UNSIGNED_INT] = {
+ Type: Uint32Array,
+ size: 4,
+ setter: uintSetter,
+ arraySetter: uintArraySetter
+};
+typeMap[UNSIGNED_INT_VEC2] = {
+ Type: Uint32Array,
+ size: 8,
+ setter: uintVec2Setter
+};
+typeMap[UNSIGNED_INT_VEC3] = {
+ Type: Uint32Array,
+ size: 12,
+ setter: uintVec3Setter
+};
+typeMap[UNSIGNED_INT_VEC4] = {
+ Type: Uint32Array,
+ size: 16,
+ setter: uintVec4Setter
+};
+typeMap[BOOL] = {
+ Type: Uint32Array,
+ size: 4,
+ setter: intSetter,
+ arraySetter: intArraySetter
+};
+typeMap[BOOL_VEC2] = {
+ Type: Uint32Array,
+ size: 8,
+ setter: intVec2Setter
+};
+typeMap[BOOL_VEC3] = {
+ Type: Uint32Array,
+ size: 12,
+ setter: intVec3Setter
+};
+typeMap[BOOL_VEC4] = {
+ Type: Uint32Array,
+ size: 16,
+ setter: intVec4Setter
+};
+typeMap[FLOAT_MAT2] = {
+ Type: Float32Array,
+ size: 16,
+ setter: floatMat2Setter
+};
+typeMap[FLOAT_MAT3] = {
+ Type: Float32Array,
+ size: 36,
+ setter: floatMat3Setter
+};
+typeMap[FLOAT_MAT4] = {
+ Type: Float32Array,
+ size: 64,
+ setter: floatMat4Setter
+};
+typeMap[FLOAT_MAT2x3] = {
+ Type: Float32Array,
+ size: 24,
+ setter: floatMat23Setter
+};
+typeMap[FLOAT_MAT2x4] = {
+ Type: Float32Array,
+ size: 32,
+ setter: floatMat24Setter
+};
+typeMap[FLOAT_MAT3x2] = {
+ Type: Float32Array,
+ size: 24,
+ setter: floatMat32Setter
+};
+typeMap[FLOAT_MAT3x4] = {
+ Type: Float32Array,
+ size: 48,
+ setter: floatMat34Setter
+};
+typeMap[FLOAT_MAT4x2] = {
+ Type: Float32Array,
+ size: 32,
+ setter: floatMat42Setter
+};
+typeMap[FLOAT_MAT4x3] = {
+ Type: Float32Array,
+ size: 48,
+ setter: floatMat43Setter
+};
+typeMap[SAMPLER_2D] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_2D
+};
+typeMap[SAMPLER_CUBE] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_CUBE_MAP
+};
+typeMap[SAMPLER_3D] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_3D
+};
+typeMap[SAMPLER_2D_SHADOW] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_2D
+};
+typeMap[SAMPLER_2D_ARRAY] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_2D_ARRAY
+};
+typeMap[SAMPLER_2D_ARRAY_SHADOW] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_2D_ARRAY
+};
+typeMap[SAMPLER_CUBE_SHADOW] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_CUBE_MAP
+};
+typeMap[INT_SAMPLER_2D] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_2D
+};
+typeMap[INT_SAMPLER_3D] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_3D
+};
+typeMap[INT_SAMPLER_CUBE] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_CUBE_MAP
+};
+typeMap[INT_SAMPLER_2D_ARRAY] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_2D_ARRAY
+};
+typeMap[UNSIGNED_INT_SAMPLER_2D] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_2D
+};
+typeMap[UNSIGNED_INT_SAMPLER_3D] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_3D
+};
+typeMap[UNSIGNED_INT_SAMPLER_CUBE] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_CUBE_MAP
+};
+typeMap[UNSIGNED_INT_SAMPLER_2D_ARRAY] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_2D_ARRAY
+};
+
+function floatAttribSetter(gl, index) {
+ return function (b) {
+ if (b.value) {
+ gl.disableVertexAttribArray(index);
+
+ switch (b.value.length) {
+ case 4:
+ gl.vertexAttrib4fv(index, b.value);
+ break;
+
+ case 3:
+ gl.vertexAttrib3fv(index, b.value);
+ break;
+
+ case 2:
+ gl.vertexAttrib2fv(index, b.value);
+ break;
+
+ case 1:
+ gl.vertexAttrib1fv(index, b.value);
+ break;
+
+ default:
+ throw new Error('the length of a float constant value must be between 1 and 4!');
+ }
+ } else {
+ gl.bindBuffer(ARRAY_BUFFER, b.buffer);
+ gl.enableVertexAttribArray(index);
+ gl.vertexAttribPointer(index, b.numComponents || b.size, b.type || FLOAT, b.normalize || false, b.stride || 0, b.offset || 0);
+
+ if (b.divisor !== undefined) {
+ gl.vertexAttribDivisor(index, b.divisor);
+ }
+ }
+ };
+}
+
+function intAttribSetter(gl, index) {
+ return function (b) {
+ if (b.value) {
+ gl.disableVertexAttribArray(index);
+
+ if (b.value.length === 4) {
+ gl.vertexAttrib4iv(index, b.value);
+ } else {
+ throw new Error('The length of an integer constant value must be 4!');
+ }
+ } else {
+ gl.bindBuffer(ARRAY_BUFFER, b.buffer);
+ gl.enableVertexAttribArray(index);
+ gl.vertexAttribIPointer(index, b.numComponents || b.size, b.type || INT, b.stride || 0, b.offset || 0);
+
+ if (b.divisor !== undefined) {
+ gl.vertexAttribDivisor(index, b.divisor);
+ }
+ }
+ };
+}
+
+function uintAttribSetter(gl, index) {
+ return function (b) {
+ if (b.value) {
+ gl.disableVertexAttribArray(index);
+
+ if (b.value.length === 4) {
+ gl.vertexAttrib4uiv(index, b.value);
+ } else {
+ throw new Error('The length of an unsigned integer constant value must be 4!');
+ }
+ } else {
+ gl.bindBuffer(ARRAY_BUFFER, b.buffer);
+ gl.enableVertexAttribArray(index);
+ gl.vertexAttribIPointer(index, b.numComponents || b.size, b.type || UNSIGNED_INT, b.stride || 0, b.offset || 0);
+
+ if (b.divisor !== undefined) {
+ gl.vertexAttribDivisor(index, b.divisor);
+ }
+ }
+ };
+}
+
+function matAttribSetter(gl, index, typeInfo) {
+ var defaultSize = typeInfo.size;
+ var count = typeInfo.count;
+ return function (b) {
+ gl.bindBuffer(ARRAY_BUFFER, b.buffer);
+ var numComponents = b.size || b.numComponents || defaultSize;
+ var size = numComponents / count;
+ var type = b.type || FLOAT;
+ var typeInfo = typeMap[type];
+ var stride = typeInfo.size * numComponents;
+ var normalize = b.normalize || false;
+ var offset = b.offset || 0;
+ var rowOffset = stride / count;
+
+ for (var i = 0; i < count; ++i) {
+ gl.enableVertexAttribArray(index + i);
+ gl.vertexAttribPointer(index + i, size, type, normalize, stride, offset + rowOffset * i);
+
+ if (b.divisor !== undefined) {
+ gl.vertexAttribDivisor(index + i, b.divisor);
+ }
+ }
+ };
+}
+
+var attrTypeMap = {};
+attrTypeMap[FLOAT] = {
+ size: 4,
+ setter: floatAttribSetter
+};
+attrTypeMap[FLOAT_VEC2] = {
+ size: 8,
+ setter: floatAttribSetter
+};
+attrTypeMap[FLOAT_VEC3] = {
+ size: 12,
+ setter: floatAttribSetter
+};
+attrTypeMap[FLOAT_VEC4] = {
+ size: 16,
+ setter: floatAttribSetter
+};
+attrTypeMap[INT] = {
+ size: 4,
+ setter: intAttribSetter
+};
+attrTypeMap[INT_VEC2] = {
+ size: 8,
+ setter: intAttribSetter
+};
+attrTypeMap[INT_VEC3] = {
+ size: 12,
+ setter: intAttribSetter
+};
+attrTypeMap[INT_VEC4] = {
+ size: 16,
+ setter: intAttribSetter
+};
+attrTypeMap[UNSIGNED_INT] = {
+ size: 4,
+ setter: uintAttribSetter
+};
+attrTypeMap[UNSIGNED_INT_VEC2] = {
+ size: 8,
+ setter: uintAttribSetter
+};
+attrTypeMap[UNSIGNED_INT_VEC3] = {
+ size: 12,
+ setter: uintAttribSetter
+};
+attrTypeMap[UNSIGNED_INT_VEC4] = {
+ size: 16,
+ setter: uintAttribSetter
+};
+attrTypeMap[BOOL] = {
+ size: 4,
+ setter: intAttribSetter
+};
+attrTypeMap[BOOL_VEC2] = {
+ size: 8,
+ setter: intAttribSetter
+};
+attrTypeMap[BOOL_VEC3] = {
+ size: 12,
+ setter: intAttribSetter
+};
+attrTypeMap[BOOL_VEC4] = {
+ size: 16,
+ setter: intAttribSetter
+};
+attrTypeMap[FLOAT_MAT2] = {
+ size: 4,
+ setter: matAttribSetter,
+ count: 2
+};
+attrTypeMap[FLOAT_MAT3] = {
+ size: 9,
+ setter: matAttribSetter,
+ count: 3
+};
+attrTypeMap[FLOAT_MAT4] = {
+ size: 16,
+ setter: matAttribSetter,
+ count: 4
+}; // make sure we don't see a global gl
+
+var gl = undefined;
+/* eslint-disable-line */
+
+/* lgtm [js/unused-local-variable] */
+
+/**
+ * Error Callback
+ * @callback ErrorCallback
+ * @param {string} msg error message.
+ * @param {number} [lineOffset] amount to add to line number
+ * @memberOf module:twgl
+ */
+
+function addLineNumbers(src, lineOffset) {
+ lineOffset = lineOffset || 0;
+ ++lineOffset;
+ return src.split("\n").map(function (line, ndx) {
+ return ndx + lineOffset + ": " + line;
+ }).join("\n");
+}
+
+var spaceRE = /^[ \t]*\n/;
+/**
+ * Loads a shader.
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {string} shaderSource The shader source.
+ * @param {number} shaderType The type of shader.
+ * @param {module:twgl.ErrorCallback} opt_errorCallback callback for errors.
+ * @return {WebGLShader} The created shader.
+ * @private
+ */
+
+function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
+ var errFn = opt_errorCallback || error; // Create the shader object
+
+ var shader = gl.createShader(shaderType); // Remove the first end of line because WebGL 2.0 requires
+ // #version 300 es
+ // as the first line. No whitespace allowed before that line
+ // so
+ //
+ //
+ //
+ // Has one line before it which is invalid according to GLSL ES 3.00
+ //
+
+ var lineOffset = 0;
+
+ if (spaceRE.test(shaderSource)) {
+ lineOffset = 1;
+ shaderSource = shaderSource.replace(spaceRE, '');
+ } // Load the shader source
+
+
+ gl.shaderSource(shader, shaderSource); // Compile the shader
+
+ gl.compileShader(shader); // Check the compile status
+
+ var compiled = gl.getShaderParameter(shader, COMPILE_STATUS);
+
+ if (!compiled) {
+ // Something went wrong during compilation; get the error
+ var lastError = gl.getShaderInfoLog(shader);
+ errFn(addLineNumbers(shaderSource, lineOffset) + "\n*** Error compiling shader: " + lastError);
+ gl.deleteShader(shader);
+ return null;
+ }
+
+ return shader;
+}
+/**
+ * @typedef {Object} ProgramOptions
+ * @property {function(string)} [errorCallback] callback for errors
+ * @property {Object.} [attribLocations] a attribute name to location map
+ * @property {(module:twgl.BufferInfo|Object.|string[])} [transformFeedbackVaryings] If passed
+ * a BufferInfo will use the attribs names inside. If passed an object of AttribInfos will use the names from that object. Otherwise
+ * you can pass an array of names.
+ * @property {number} [transformFeedbackMode] the mode to pass `gl.transformFeedbackVaryings`. Defaults to `SEPARATE_ATTRIBS`.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Gets the program options based on all these optional arguments
+ * @param {module:twgl.ProgramOptions|string[]} [opt_attribs] Options for the program or an array of attribs names. Locations will be assigned by index if not passed in
+ * @param {number[]} [opt_locations] The locations for the. A parallel array to opt_attribs letting you assign locations.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
+ * on error. If you want something else pass an callback. It's passed an error message.
+ * @return {module:twgl.ProgramOptions} an instance of ProgramOptions based on the arguments passed in
+ * @private
+ */
+
+
+function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
+ var transformFeedbackVaryings;
+ var transformFeedbackMode;
+
+ if (typeof opt_locations === 'function') {
+ opt_errorCallback = opt_locations;
+ opt_locations = undefined;
+ }
+
+ if (typeof opt_attribs === 'function') {
+ opt_errorCallback = opt_attribs;
+ opt_attribs = undefined;
+ } else if (opt_attribs && !Array.isArray(opt_attribs)) {
+ // If we have an errorCallback we can just return this object
+ // Otherwise we need to construct one with default errorCallback
+ if (opt_attribs.errorCallback) {
+ return opt_attribs;
+ }
+
+ var opt = opt_attribs;
+ opt_errorCallback = opt.errorCallback;
+ opt_attribs = opt.attribLocations;
+ transformFeedbackVaryings = opt.transformFeedbackVaryings;
+ transformFeedbackMode = opt.transformFeedbackMode;
+ }
+
+ var options = {
+ errorCallback: opt_errorCallback || error,
+ transformFeedbackVaryings: transformFeedbackVaryings,
+ transformFeedbackMode: transformFeedbackMode
+ };
+
+ if (opt_attribs) {
+ var attribLocations = {};
+
+ if (Array.isArray(opt_attribs)) {
+ opt_attribs.forEach(function (attrib, ndx) {
+ attribLocations[attrib] = opt_locations ? opt_locations[ndx] : ndx;
+ });
+ } else {
+ attribLocations = opt_attribs;
+ }
+
+ options.attribLocations = attribLocations;
+ }
+
+ return options;
+}
+
+var defaultShaderType = ["VERTEX_SHADER", "FRAGMENT_SHADER"];
+
+function getShaderTypeFromScriptType(gl, scriptType) {
+ if (scriptType.indexOf("frag") >= 0) {
+ return FRAGMENT_SHADER;
+ } else if (scriptType.indexOf("vert") >= 0) {
+ return VERTEX_SHADER;
+ }
+
+ return undefined;
+}
+
+function deleteShaders(gl, shaders) {
+ shaders.forEach(function (shader) {
+ gl.deleteShader(shader);
+ });
+}
+/**
+ * Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
+ * program and calls useProgram.
+ *
+ * NOTE: There are 4 signatures for this function
+ *
+ * twgl.createProgram(gl, [vs, fs], options);
+ * twgl.createProgram(gl, [vs, fs], opt_errFunc);
+ * twgl.createProgram(gl, [vs, fs], opt_attribs, opt_errFunc);
+ * twgl.createProgram(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {WebGLShader[]|string[]} shaders The shaders to attach, or element ids for their source, or strings that contain their source
+ * @param {module:twgl.ProgramOptions|string[]|module:twgl.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
+ * @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
+ * on error. If you want something else pass an callback. It's passed an error message.
+ * @return {WebGLProgram?} the created program or null if error.
+ * @memberOf module:twgl/programs
+ */
+
+
+function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallback) {
+ var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
+ var realShaders = [];
+ var newShaders = [];
+
+ for (var ndx = 0; ndx < shaders.length; ++ndx) {
+ var shader = shaders[ndx];
+
+ if (typeof shader === 'string') {
+ var elem = getElementById(shader);
+ var src = elem ? elem.text : shader;
+ var type = gl[defaultShaderType[ndx]];
+
+ if (elem && elem.type) {
+ type = getShaderTypeFromScriptType(gl, elem.type) || type;
+ }
+
+ shader = loadShader(gl, src, type, progOptions.errorCallback);
+ newShaders.push(shader);
+ }
+
+ if (helper.isShader(gl, shader)) {
+ realShaders.push(shader);
+ }
+ }
+
+ if (realShaders.length !== shaders.length) {
+ progOptions.errorCallback("not enough shaders for program");
+ deleteShaders(gl, newShaders);
+ return null;
+ }
+
+ var program = gl.createProgram();
+ realShaders.forEach(function (shader) {
+ gl.attachShader(program, shader);
+ });
+
+ if (progOptions.attribLocations) {
+ Object.keys(progOptions.attribLocations).forEach(function (attrib) {
+ gl.bindAttribLocation(program, progOptions.attribLocations[attrib], attrib);
+ });
+ }
+
+ var varyings = progOptions.transformFeedbackVaryings;
+
+ if (varyings) {
+ if (varyings.attribs) {
+ varyings = varyings.attribs;
+ }
+
+ if (!Array.isArray(varyings)) {
+ varyings = Object.keys(varyings);
+ }
+
+ gl.transformFeedbackVaryings(program, varyings, progOptions.transformFeedbackMode || SEPARATE_ATTRIBS);
+ }
+
+ gl.linkProgram(program); // Check the link status
+
+ var linked = gl.getProgramParameter(program, LINK_STATUS);
+
+ if (!linked) {
+ // something went wrong with the link
+ var lastError = gl.getProgramInfoLog(program);
+ progOptions.errorCallback("Error in program linking:" + lastError);
+ gl.deleteProgram(program);
+ deleteShaders(gl, newShaders);
+ return null;
+ }
+
+ return program;
+}
+/**
+ * Loads a shader from a script tag.
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {string} scriptId The id of the script tag.
+ * @param {number} [opt_shaderType] The type of shader. If not passed in it will
+ * be derived from the type of the script tag.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors.
+ * @return {WebGLShader?} The created shader or null if error.
+ * @private
+ */
+
+
+function createShaderFromScript(gl, scriptId, opt_shaderType, opt_errorCallback) {
+ var shaderSource = "";
+ var shaderScript = getElementById(scriptId);
+
+ if (!shaderScript) {
+ throw new Error("unknown script element: ".concat(scriptId));
+ }
+
+ shaderSource = shaderScript.text;
+ var shaderType = opt_shaderType || getShaderTypeFromScriptType(gl, shaderScript.type);
+
+ if (!shaderType) {
+ throw new Error('unknown shader type');
+ }
+
+ return loadShader(gl, shaderSource, shaderType, opt_errorCallback);
+}
+/**
+ * Creates a program from 2 script tags.
+ *
+ * NOTE: There are 4 signatures for this function
+ *
+ * twgl.createProgramFromScripts(gl, [vs, fs], opt_options);
+ * twgl.createProgramFromScripts(gl, [vs, fs], opt_errFunc);
+ * twgl.createProgramFromScripts(gl, [vs, fs], opt_attribs, opt_errFunc);
+ * twgl.createProgramFromScripts(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
+ * to use.
+ * @param {string[]} shaderScriptIds Array of ids of the script
+ * tags for the shaders. The first is assumed to be the
+ * vertex shader, the second the fragment shader.
+ * @param {module:twgl.ProgramOptions|string[]|module:twgl.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
+ * @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
+ * on error. If you want something else pass an callback. It's passed an error message.
+ * @return {WebGLProgram?} the created program or null if error.
+ * @memberOf module:twgl/programs
+ */
+
+
+function createProgramFromScripts(gl, shaderScriptIds, opt_attribs, opt_locations, opt_errorCallback) {
+ var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
+ var shaders = [];
+
+ for (var ii = 0; ii < shaderScriptIds.length; ++ii) {
+ var shader = createShaderFromScript(gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions.errorCallback);
+
+ if (!shader) {
+ return null;
+ }
+
+ shaders.push(shader);
+ }
+
+ return createProgram(gl, shaders, progOptions);
+}
+/**
+ * Creates a program from 2 sources.
+ *
+ * NOTE: There are 4 signatures for this function
+ *
+ * twgl.createProgramFromSource(gl, [vs, fs], opt_options);
+ * twgl.createProgramFromSource(gl, [vs, fs], opt_errFunc);
+ * twgl.createProgramFromSource(gl, [vs, fs], opt_attribs, opt_errFunc);
+ * twgl.createProgramFromSource(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
+ * to use.
+ * @param {string[]} shaderSources Array of sources for the
+ * shaders. The first is assumed to be the vertex shader,
+ * the second the fragment shader.
+ * @param {module:twgl.ProgramOptions|string[]|module:twgl.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
+ * @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
+ * on error. If you want something else pass an callback. It's passed an error message.
+ * @return {WebGLProgram?} the created program or null if error.
+ * @memberOf module:twgl/programs
+ */
+
+
+function createProgramFromSources(gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
+ var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
+ var shaders = [];
+
+ for (var ii = 0; ii < shaderSources.length; ++ii) {
+ var shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions.errorCallback);
+
+ if (!shader) {
+ return null;
+ }
+
+ shaders.push(shader);
+ }
+
+ return createProgram(gl, shaders, progOptions);
+}
+/**
+ * Returns true if attribute/uniform is a reserved/built in
+ *
+ * It makes no sense to me why GL returns these because it's
+ * illegal to call `gl.getUniformLocation` and `gl.getAttribLocation`
+ * with names that start with `gl_` (and `webgl_` in WebGL)
+ *
+ * I can only assume they are there because they might count
+ * when computing the number of uniforms/attributes used when you want to
+ * know if you are near the limit. That doesn't really make sense
+ * to me but the fact that these get returned are in the spec.
+ *
+ * @param {WebGLActiveInfo} info As returned from `gl.getActiveUniform` or
+ * `gl.getActiveAttrib`.
+ * @return {bool} true if it's reserved
+ * @private
+ */
+
+
+function isBuiltIn(info) {
+ var name = info.name;
+ return name.startsWith("gl_") || name.startsWith("webgl_");
+}
+/**
+ * Creates setter functions for all uniforms of a shader
+ * program.
+ *
+ * @see {@link module:twgl.setUniforms}
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {WebGLProgram} program the program to create setters for.
+ * @returns {Object.} an object with a setter by name for each uniform
+ * @memberOf module:twgl/programs
+ */
+
+
+function createUniformSetters(gl, program) {
+ var textureUnit = 0;
+ /**
+ * Creates a setter for a uniform of the given program with it's
+ * location embedded in the setter.
+ * @param {WebGLProgram} program
+ * @param {WebGLUniformInfo} uniformInfo
+ * @returns {function} the created setter.
+ */
+
+ function createUniformSetter(program, uniformInfo) {
+ var location = gl.getUniformLocation(program, uniformInfo.name);
+ var isArray = uniformInfo.size > 1 && uniformInfo.name.substr(-3) === "[0]";
+ var type = uniformInfo.type;
+ var typeInfo = typeMap[type];
+
+ if (!typeInfo) {
+ throw new Error("unknown type: 0x".concat(type.toString(16))); // we should never get here.
+ }
+
+ var setter;
+
+ if (typeInfo.bindPoint) {
+ // it's a sampler
+ var unit = textureUnit;
+ textureUnit += uniformInfo.size;
+
+ if (isArray) {
+ setter = typeInfo.arraySetter(gl, type, unit, location, uniformInfo.size);
+ } else {
+ setter = typeInfo.setter(gl, type, unit, location, uniformInfo.size);
+ }
+ } else {
+ if (typeInfo.arraySetter && isArray) {
+ setter = typeInfo.arraySetter(gl, location);
+ } else {
+ setter = typeInfo.setter(gl, location);
+ }
+ }
+
+ setter.location = location;
+ return setter;
+ }
+
+ var uniformSetters = {};
+ var numUniforms = gl.getProgramParameter(program, ACTIVE_UNIFORMS);
+
+ for (var ii = 0; ii < numUniforms; ++ii) {
+ var uniformInfo = gl.getActiveUniform(program, ii);
+
+ if (isBuiltIn(uniformInfo)) {
+ continue;
+ }
+
+ var name = uniformInfo.name; // remove the array suffix.
+
+ if (name.substr(-3) === "[0]") {
+ name = name.substr(0, name.length - 3);
+ }
+
+ var setter = createUniformSetter(program, uniformInfo);
+ uniformSetters[name] = setter;
+ }
+
+ return uniformSetters;
+}
+/**
+ * @typedef {Object} TransformFeedbackInfo
+ * @property {number} index index of transform feedback
+ * @property {number} type GL type
+ * @property {number} size 1 - 4
+ * @memberOf module:twgl
+ */
+
+/**
+ * Create TransformFeedbackInfo for passing to bindTransformFeedbackInfo.
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {WebGLProgram} program an existing WebGLProgram.
+ * @return {Object}
+ * @memberOf module:twgl
+ */
+
+
+function createTransformFeedbackInfo(gl, program) {
+ var info = {};
+ var numVaryings = gl.getProgramParameter(program, TRANSFORM_FEEDBACK_VARYINGS);
+
+ for (var ii = 0; ii < numVaryings; ++ii) {
+ var varying = gl.getTransformFeedbackVarying(program, ii);
+ info[varying.name] = {
+ index: ii,
+ type: varying.type,
+ size: varying.size
+ };
+ }
+
+ return info;
+}
+/**
+ * Binds buffers for transform feedback.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {(module:twgl.ProgramInfo|Object)} transformFeedbackInfo A ProgramInfo or TransformFeedbackInfo.
+ * @param {(module:twgl.BufferInfo|Object)} [bufferInfo] A BufferInfo or set of AttribInfos.
+ * @memberOf module:twgl
+ */
+
+
+function bindTransformFeedbackInfo(gl, transformFeedbackInfo, bufferInfo) {
+ if (transformFeedbackInfo.transformFeedbackInfo) {
+ transformFeedbackInfo = transformFeedbackInfo.transformFeedbackInfo;
+ }
+
+ if (bufferInfo.attribs) {
+ bufferInfo = bufferInfo.attribs;
+ }
+
+ for (var name in bufferInfo) {
+ var varying = transformFeedbackInfo[name];
+
+ if (varying) {
+ var buf = bufferInfo[name];
+
+ if (buf.offset) {
+ gl.bindBufferRange(TRANSFORM_FEEDBACK_BUFFER, varying.index, buf.buffer, buf.offset, buf.size);
+ } else {
+ gl.bindBufferBase(TRANSFORM_FEEDBACK_BUFFER, varying.index, buf.buffer);
+ }
+ }
+ }
+}
+/**
+ * Creates a transform feedback and sets the buffers
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {module:twgl.ProgramInfo} programInfo A ProgramInfo as returned from {@link module:twgl.createProgramInfo}
+ * @param {(module:twgl.BufferInfo|Object)} [bufferInfo] A BufferInfo or set of AttribInfos.
+ * @return {WebGLTransformFeedback} the created transform feedback
+ * @memberOf module:twgl
+ */
+
+
+function createTransformFeedback(gl, programInfo, bufferInfo) {
+ var tf = gl.createTransformFeedback();
+ gl.bindTransformFeedback(TRANSFORM_FEEDBACK, tf);
+ gl.useProgram(programInfo.program);
+ bindTransformFeedbackInfo(gl, programInfo, bufferInfo);
+ gl.bindTransformFeedback(TRANSFORM_FEEDBACK, null);
+ return tf;
+}
+/**
+ * @typedef {Object} UniformData
+ * @property {number} type The WebGL type enum for this uniform
+ * @property {number} size The number of elements for this uniform
+ * @property {number} blockNdx The block index this uniform appears in
+ * @property {number} offset The byte offset in the block for this uniform's value
+ * @memberOf module:twgl
+ */
+
+/**
+ * The specification for one UniformBlockObject
+ *
+ * @typedef {Object} BlockSpec
+ * @property {number} index The index of the block.
+ * @property {number} size The size in bytes needed for the block
+ * @property {number[]} uniformIndices The indices of the uniforms used by the block. These indices
+ * correspond to entries in a UniformData array in the {@link module:twgl.UniformBlockSpec}.
+ * @property {bool} usedByVertexShader Self explanatory
+ * @property {bool} usedByFragmentShader Self explanatory
+ * @property {bool} used Self explanatory
+ * @memberOf module:twgl
+ */
+
+/**
+ * A `UniformBlockSpec` represents the data needed to create and bind
+ * UniformBlockObjects for a given program
+ *
+ * @typedef {Object} UniformBlockSpec
+ * @property {Object. blockSpecs The BlockSpec for each block by block name
+ * @property {UniformData[]} uniformData An array of data for each uniform by uniform index.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a UniformBlockSpec for the given program.
+ *
+ * A UniformBlockSpec represents the data needed to create and bind
+ * UniformBlockObjects
+ *
+ * @param {WebGL2RenderingContext} gl A WebGL2 Rendering Context
+ * @param {WebGLProgram} program A WebGLProgram for a successfully linked program
+ * @return {module:twgl.UniformBlockSpec} The created UniformBlockSpec
+ * @memberOf module:twgl/programs
+ */
+
+
+function createUniformBlockSpecFromProgram(gl, program) {
+ var numUniforms = gl.getProgramParameter(program, ACTIVE_UNIFORMS);
+ var uniformData = [];
+ var uniformIndices = [];
+
+ for (var ii = 0; ii < numUniforms; ++ii) {
+ uniformIndices.push(ii);
+ uniformData.push({});
+ var uniformInfo = gl.getActiveUniform(program, ii);
+
+ if (isBuiltIn(uniformInfo)) {
+ break;
+ } // REMOVE [0]?
+
+
+ uniformData[ii].name = uniformInfo.name;
+ }
+
+ [["UNIFORM_TYPE", "type"], ["UNIFORM_SIZE", "size"], // num elements
+ ["UNIFORM_BLOCK_INDEX", "blockNdx"], ["UNIFORM_OFFSET", "offset"]].forEach(function (pair) {
+ var pname = pair[0];
+ var key = pair[1];
+ gl.getActiveUniforms(program, uniformIndices, gl[pname]).forEach(function (value, ndx) {
+ uniformData[ndx][key] = value;
+ });
+ });
+ var blockSpecs = {};
+ var numUniformBlocks = gl.getProgramParameter(program, ACTIVE_UNIFORM_BLOCKS);
+
+ for (var _ii = 0; _ii < numUniformBlocks; ++_ii) {
+ var name = gl.getActiveUniformBlockName(program, _ii);
+ var blockSpec = {
+ index: _ii,
+ usedByVertexShader: gl.getActiveUniformBlockParameter(program, _ii, UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),
+ usedByFragmentShader: gl.getActiveUniformBlockParameter(program, _ii, UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER),
+ size: gl.getActiveUniformBlockParameter(program, _ii, UNIFORM_BLOCK_DATA_SIZE),
+ uniformIndices: gl.getActiveUniformBlockParameter(program, _ii, UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES)
+ };
+ blockSpec.used = blockSpec.usedByVertexShader || blockSpec.usedByFragmentShader;
+ blockSpecs[name] = blockSpec;
+ }
+
+ return {
+ blockSpecs: blockSpecs,
+ uniformData: uniformData
+ };
+}
+
+var arraySuffixRE = /\[\d+\]\.$/; // better way to check?
+
+/**
+ * Represents a UniformBlockObject including an ArrayBuffer with all the uniform values
+ * and a corresponding WebGLBuffer to hold those values on the GPU
+ *
+ * @typedef {Object} UniformBlockInfo
+ * @property {string} name The name of the block
+ * @property {ArrayBuffer} array The array buffer that contains the uniform values
+ * @property {Float32Array} asFloat A float view on the array buffer. This is useful
+ * inspecting the contents of the buffer in the debugger.
+ * @property {WebGLBuffer} buffer A WebGL buffer that will hold a copy of the uniform values for rendering.
+ * @property {number} [offset] offset into buffer
+ * @property {Object.} uniforms A uniform name to ArrayBufferView map.
+ * each Uniform has a correctly typed `ArrayBufferView` into array at the correct offset
+ * and length of that uniform. So for example a float uniform would have a 1 float `Float32Array`
+ * view. A single mat4 would have a 16 element `Float32Array` view. An ivec2 would have an
+ * `Int32Array` view, etc.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a `UniformBlockInfo` for the specified block
+ *
+ * Note: **If the blockName matches no existing blocks a warning is printed to the console and a dummy
+ * `UniformBlockInfo` is returned**. This is because when debugging GLSL
+ * it is common to comment out large portions of a shader or for example set
+ * the final output to a constant. When that happens blocks get optimized out.
+ * If this function did not create dummy blocks your code would crash when debugging.
+ *
+ * @param {WebGL2RenderingContext} gl A WebGL2RenderingContext
+ * @param {WebGLProgram} program A WebGLProgram
+ * @param {module:twgl.UniformBlockSpec} uniformBlockSpec. A UniformBlockSpec as returned
+ * from {@link module:twgl.createUniformBlockSpecFromProgram}.
+ * @param {string} blockName The name of the block.
+ * @return {module:twgl.UniformBlockInfo} The created UniformBlockInfo
+ * @memberOf module:twgl/programs
+ */
+
+function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockName) {
+ var blockSpecs = uniformBlockSpec.blockSpecs;
+ var uniformData = uniformBlockSpec.uniformData;
+ var blockSpec = blockSpecs[blockName];
+
+ if (!blockSpec) {
+ warn("no uniform block object named:", blockName);
+ return {
+ name: blockName,
+ uniforms: {}
+ };
+ }
+
+ var array = new ArrayBuffer(blockSpec.size);
+ var buffer = gl.createBuffer();
+ var uniformBufferIndex = blockSpec.index;
+ gl.bindBuffer(UNIFORM_BUFFER, buffer);
+ gl.uniformBlockBinding(program, blockSpec.index, uniformBufferIndex);
+ var prefix = blockName + ".";
+
+ if (arraySuffixRE.test(prefix)) {
+ prefix = prefix.replace(arraySuffixRE, ".");
+ }
+
+ var uniforms = {};
+ blockSpec.uniformIndices.forEach(function (uniformNdx) {
+ var data = uniformData[uniformNdx];
+ var typeInfo = typeMap[data.type];
+ var Type = typeInfo.Type;
+ var length = data.size * typeInfo.size;
+ var name = data.name;
+
+ if (name.substr(0, prefix.length) === prefix) {
+ name = name.substr(prefix.length);
+ }
+
+ uniforms[name] = new Type(array, data.offset, length / Type.BYTES_PER_ELEMENT);
+ });
+ return {
+ name: blockName,
+ array: array,
+ asFloat: new Float32Array(array),
+ // for debugging
+ buffer: buffer,
+ uniforms: uniforms
+ };
+}
+/**
+ * Creates a `UniformBlockInfo` for the specified block
+ *
+ * Note: **If the blockName matches no existing blocks a warning is printed to the console and a dummy
+ * `UniformBlockInfo` is returned**. This is because when debugging GLSL
+ * it is common to comment out large portions of a shader or for example set
+ * the final output to a constant. When that happens blocks get optimized out.
+ * If this function did not create dummy blocks your code would crash when debugging.
+ *
+ * @param {WebGL2RenderingContext} gl A WebGL2RenderingContext
+ * @param {module:twgl.ProgramInfo} programInfo a `ProgramInfo`
+ * as returned from {@link module:twgl.createProgramInfo}
+ * @param {string} blockName The name of the block.
+ * @return {module:twgl.UniformBlockInfo} The created UniformBlockInfo
+ * @memberOf module:twgl/programs
+ */
+
+
+function createUniformBlockInfo(gl, programInfo, blockName) {
+ return createUniformBlockInfoFromProgram(gl, programInfo.program, programInfo.uniformBlockSpec, blockName);
+}
+/**
+ * Binds a uniform block to the matching uniform block point.
+ * Matches by blocks by name so blocks must have the same name not just the same
+ * structure.
+ *
+ * If you have changed any values and you upload the values into the corresponding WebGLBuffer
+ * call {@link module:twgl.setUniformBlock} instead.
+ *
+ * @param {WebGL2RenderingContext} gl A WebGL 2 rendering context.
+ * @param {(module:twgl.ProgramInfo|module:twgl.UniformBlockSpec)} programInfo a `ProgramInfo`
+ * as returned from {@link module:twgl.createProgramInfo} or or `UniformBlockSpec` as
+ * returned from {@link module:twgl.createUniformBlockSpecFromProgram}.
+ * @param {module:twgl.UniformBlockInfo} uniformBlockInfo a `UniformBlockInfo` as returned from
+ * {@link module:twgl.createUniformBlockInfo}.
+ * @return {bool} true if buffer was bound. If the programInfo has no block with the same block name
+ * no buffer is bound.
+ * @memberOf module:twgl/programs
+ */
+
+
+function bindUniformBlock(gl, programInfo, uniformBlockInfo) {
+ var uniformBlockSpec = programInfo.uniformBlockSpec || programInfo;
+ var blockSpec = uniformBlockSpec.blockSpecs[uniformBlockInfo.name];
+
+ if (blockSpec) {
+ var bufferBindIndex = blockSpec.index;
+ gl.bindBufferRange(UNIFORM_BUFFER, bufferBindIndex, uniformBlockInfo.buffer, uniformBlockInfo.offset || 0, uniformBlockInfo.array.byteLength);
+ return true;
+ }
+
+ return false;
+}
+/**
+ * Uploads the current uniform values to the corresponding WebGLBuffer
+ * and binds that buffer to the program's corresponding bind point for the uniform block object.
+ *
+ * If you haven't changed any values and you only need to bind the uniform block object
+ * call {@link module:twgl.bindUniformBlock} instead.
+ *
+ * @param {WebGL2RenderingContext} gl A WebGL 2 rendering context.
+ * @param {(module:twgl.ProgramInfo|module:twgl.UniformBlockSpec)} programInfo a `ProgramInfo`
+ * as returned from {@link module:twgl.createProgramInfo} or or `UniformBlockSpec` as
+ * returned from {@link module:twgl.createUniformBlockSpecFromProgram}.
+ * @param {module:twgl.UniformBlockInfo} uniformBlockInfo a `UniformBlockInfo` as returned from
+ * {@link module:twgl.createUniformBlockInfo}.
+ * @memberOf module:twgl/programs
+ */
+
+
+function setUniformBlock(gl, programInfo, uniformBlockInfo) {
+ if (bindUniformBlock(gl, programInfo, uniformBlockInfo)) {
+ gl.bufferData(UNIFORM_BUFFER, uniformBlockInfo.array, DYNAMIC_DRAW);
+ }
+}
+/**
+ * Sets values of a uniform block object
+ *
+ * @param {module:twgl.UniformBlockInfo} uniformBlockInfo A UniformBlockInfo as returned by {@link module:twgl.createUniformBlockInfo}.
+ * @param {Object.} values A uniform name to value map where the value is correct for the given
+ * type of uniform. So for example given a block like
+ *
+ * uniform SomeBlock {
+ * float someFloat;
+ * vec2 someVec2;
+ * vec3 someVec3Array[2];
+ * int someInt;
+ * }
+ *
+ * You can set the values of the uniform block with
+ *
+ * twgl.setBlockUniforms(someBlockInfo, {
+ * someFloat: 12.3,
+ * someVec2: [1, 2],
+ * someVec3Array: [1, 2, 3, 4, 5, 6],
+ * someInt: 5,
+ * }
+ *
+ * Arrays can be JavaScript arrays or typed arrays
+ *
+ * Any name that doesn't match will be ignored
+ * @memberOf module:twgl/programs
+ */
+
+
+function setBlockUniforms(uniformBlockInfo, values) {
+ var uniforms = uniformBlockInfo.uniforms;
+
+ for (var name in values) {
+ var array = uniforms[name];
+
+ if (array) {
+ var value = values[name];
+
+ if (value.length) {
+ array.set(value);
+ } else {
+ array[0] = value;
+ }
+ }
+ }
+}
+/**
+ * Set uniforms and binds related textures.
+ *
+ * example:
+ *
+ * const programInfo = createProgramInfo(
+ * gl, ["some-vs", "some-fs"]);
+ *
+ * const tex1 = gl.createTexture();
+ * const tex2 = gl.createTexture();
+ *
+ * ... assume we setup the textures with data ...
+ *
+ * const uniforms = {
+ * u_someSampler: tex1,
+ * u_someOtherSampler: tex2,
+ * u_someColor: [1,0,0,1],
+ * u_somePosition: [0,1,1],
+ * u_someMatrix: [
+ * 1,0,0,0,
+ * 0,1,0,0,
+ * 0,0,1,0,
+ * 0,0,0,0,
+ * ],
+ * };
+ *
+ * gl.useProgram(program);
+ *
+ * This will automatically bind the textures AND set the
+ * uniforms.
+ *
+ * twgl.setUniforms(programInfo, uniforms);
+ *
+ * For the example above it is equivalent to
+ *
+ * var texUnit = 0;
+ * gl.activeTexture(gl.TEXTURE0 + texUnit);
+ * gl.bindTexture(gl.TEXTURE_2D, tex1);
+ * gl.uniform1i(u_someSamplerLocation, texUnit++);
+ * gl.activeTexture(gl.TEXTURE0 + texUnit);
+ * gl.bindTexture(gl.TEXTURE_2D, tex2);
+ * gl.uniform1i(u_someSamplerLocation, texUnit++);
+ * gl.uniform4fv(u_someColorLocation, [1, 0, 0, 1]);
+ * gl.uniform3fv(u_somePositionLocation, [0, 1, 1]);
+ * gl.uniformMatrix4fv(u_someMatrix, false, [
+ * 1,0,0,0,
+ * 0,1,0,0,
+ * 0,0,1,0,
+ * 0,0,0,0,
+ * ]);
+ *
+ * Note it is perfectly reasonable to call `setUniforms` multiple times. For example
+ *
+ * const uniforms = {
+ * u_someSampler: tex1,
+ * u_someOtherSampler: tex2,
+ * };
+ *
+ * const moreUniforms {
+ * u_someColor: [1,0,0,1],
+ * u_somePosition: [0,1,1],
+ * u_someMatrix: [
+ * 1,0,0,0,
+ * 0,1,0,0,
+ * 0,0,1,0,
+ * 0,0,0,0,
+ * ],
+ * };
+ *
+ * twgl.setUniforms(programInfo, uniforms);
+ * twgl.setUniforms(programInfo, moreUniforms);
+ *
+ * You can also add WebGLSamplers to uniform samplers as in
+ *
+ * const uniforms = {
+ * u_someSampler: {
+ * texture: someWebGLTexture,
+ * sampler: someWebGLSampler,
+ * },
+ * };
+ *
+ * In which case both the sampler and texture will be bound to the
+ * same unit.
+ *
+ * @param {(module:twgl.ProgramInfo|Object.)} setters a `ProgramInfo` as returned from `createProgramInfo` or the setters returned from
+ * `createUniformSetters`.
+ * @param {Object.} values an object with values for the
+ * uniforms.
+ * You can pass multiple objects by putting them in an array or by calling with more arguments.For example
+ *
+ * const sharedUniforms = {
+ * u_fogNear: 10,
+ * u_projection: ...
+ * ...
+ * };
+ *
+ * const localUniforms = {
+ * u_world: ...
+ * u_diffuseColor: ...
+ * };
+ *
+ * twgl.setUniforms(programInfo, sharedUniforms, localUniforms);
+ *
+ * // is the same as
+ *
+ * twgl.setUniforms(programInfo, [sharedUniforms, localUniforms]);
+ *
+ * // is the same as
+ *
+ * twgl.setUniforms(programInfo, sharedUniforms);
+ * twgl.setUniforms(programInfo, localUniforms};
+ *
+ * @memberOf module:twgl/programs
+ */
+
+
+function setUniforms(setters, values) {
+ // eslint-disable-line
+ var actualSetters = setters.uniformSetters || setters;
+ var numArgs = arguments.length;
+
+ for (var aNdx = 1; aNdx < numArgs; ++aNdx) {
+ var _values = arguments[aNdx];
+
+ if (Array.isArray(_values)) {
+ var numValues = _values.length;
+
+ for (var ii = 0; ii < numValues; ++ii) {
+ setUniforms(actualSetters, _values[ii]);
+ }
+ } else {
+ for (var name in _values) {
+ var setter = actualSetters[name];
+
+ if (setter) {
+ setter(_values[name]);
+ }
+ }
+ }
+ }
+}
+/**
+ * Alias for `setUniforms`
+ * @function
+ * @param {(module:twgl.ProgramInfo|Object.)} setters a `ProgramInfo` as returned from `createProgramInfo` or the setters returned from
+ * `createUniformSetters`.
+ * @param {Object.} values an object with values for the
+ * @memberOf module:twgl/programs
+ */
+
+
+var setUniformsAndBindTextures = setUniforms;
+/**
+ * Creates setter functions for all attributes of a shader
+ * program. You can pass this to {@link module:twgl.setBuffersAndAttributes} to set all your buffers and attributes.
+ *
+ * @see {@link module:twgl.setAttributes} for example
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {WebGLProgram} program the program to create setters for.
+ * @return {Object.} an object with a setter for each attribute by name.
+ * @memberOf module:twgl/programs
+ */
+
+exports.setUniformsAndBindTextures = setUniformsAndBindTextures;
+
+function createAttributeSetters(gl, program) {
+ var attribSetters = {};
+ var numAttribs = gl.getProgramParameter(program, ACTIVE_ATTRIBUTES);
+
+ for (var ii = 0; ii < numAttribs; ++ii) {
+ var attribInfo = gl.getActiveAttrib(program, ii);
+
+ if (isBuiltIn(attribInfo)) {
+ continue;
+ }
+
+ var index = gl.getAttribLocation(program, attribInfo.name);
+ var typeInfo = attrTypeMap[attribInfo.type];
+ var setter = typeInfo.setter(gl, index, typeInfo);
+ setter.location = index;
+ attribSetters[attribInfo.name] = setter;
+ }
+
+ return attribSetters;
+}
+/**
+ * Sets attributes and binds buffers (deprecated... use {@link module:twgl.setBuffersAndAttributes})
+ *
+ * Example:
+ *
+ * const program = createProgramFromScripts(
+ * gl, ["some-vs", "some-fs");
+ *
+ * const attribSetters = createAttributeSetters(program);
+ *
+ * const positionBuffer = gl.createBuffer();
+ * const texcoordBuffer = gl.createBuffer();
+ *
+ * const attribs = {
+ * a_position: {buffer: positionBuffer, numComponents: 3},
+ * a_texcoord: {buffer: texcoordBuffer, numComponents: 2},
+ * };
+ *
+ * gl.useProgram(program);
+ *
+ * This will automatically bind the buffers AND set the
+ * attributes.
+ *
+ * setAttributes(attribSetters, attribs);
+ *
+ * Properties of attribs. For each attrib you can add
+ * properties:
+ *
+ * * type: the type of data in the buffer. Default = gl.FLOAT
+ * * normalize: whether or not to normalize the data. Default = false
+ * * stride: the stride. Default = 0
+ * * offset: offset into the buffer. Default = 0
+ * * divisor: the divisor for instances. Default = undefined
+ *
+ * For example if you had 3 value float positions, 2 value
+ * float texcoord and 4 value uint8 colors you'd setup your
+ * attribs like this
+ *
+ * const attribs = {
+ * a_position: {buffer: positionBuffer, numComponents: 3},
+ * a_texcoord: {buffer: texcoordBuffer, numComponents: 2},
+ * a_color: {
+ * buffer: colorBuffer,
+ * numComponents: 4,
+ * type: gl.UNSIGNED_BYTE,
+ * normalize: true,
+ * },
+ * };
+ *
+ * @param {Object.} setters Attribute setters as returned from createAttributeSetters
+ * @param {Object.} buffers AttribInfos mapped by attribute name.
+ * @memberOf module:twgl/programs
+ * @deprecated use {@link module:twgl.setBuffersAndAttributes}
+ */
+
+
+function setAttributes(setters, buffers) {
+ for (var name in buffers) {
+ var setter = setters[name];
+
+ if (setter) {
+ setter(buffers[name]);
+ }
+ }
+}
+/**
+ * Sets attributes and buffers including the `ELEMENT_ARRAY_BUFFER` if appropriate
+ *
+ * Example:
+ *
+ * const programInfo = createProgramInfo(
+ * gl, ["some-vs", "some-fs");
+ *
+ * const arrays = {
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
+ * };
+ *
+ * const bufferInfo = createBufferInfoFromArrays(gl, arrays);
+ *
+ * gl.useProgram(programInfo.program);
+ *
+ * This will automatically bind the buffers AND set the
+ * attributes.
+ *
+ * setBuffersAndAttributes(gl, programInfo, bufferInfo);
+ *
+ * For the example above it is equivalent to
+ *
+ * gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
+ * gl.enableVertexAttribArray(a_positionLocation);
+ * gl.vertexAttribPointer(a_positionLocation, 3, gl.FLOAT, false, 0, 0);
+ * gl.bindBuffer(gl.ARRAY_BUFFER, texcoordBuffer);
+ * gl.enableVertexAttribArray(a_texcoordLocation);
+ * gl.vertexAttribPointer(a_texcoordLocation, 4, gl.FLOAT, false, 0, 0);
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext.
+ * @param {(module:twgl.ProgramInfo|Object.)} setters A `ProgramInfo` as returned from {@link module:twgl.createProgramInfo} or Attribute setters as returned from {@link module:twgl.createAttributeSetters}
+ * @param {(module:twgl.BufferInfo|module:twgl.VertexArrayInfo)} buffers a `BufferInfo` as returned from {@link module:twgl.createBufferInfoFromArrays}.
+ * or a `VertexArrayInfo` as returned from {@link module:twgl.createVertexArrayInfo}
+ * @memberOf module:twgl/programs
+ */
+
+
+function setBuffersAndAttributes(gl, programInfo, buffers) {
+ if (buffers.vertexArrayObject) {
+ gl.bindVertexArray(buffers.vertexArrayObject);
+ } else {
+ setAttributes(programInfo.attribSetters || programInfo, buffers.attribs);
+
+ if (buffers.indices) {
+ gl.bindBuffer(ELEMENT_ARRAY_BUFFER, buffers.indices);
+ }
+ }
+}
+/**
+ * @typedef {Object} ProgramInfo
+ * @property {WebGLProgram} program A shader program
+ * @property {Object} uniformSetters object of setters as returned from createUniformSetters,
+ * @property {Object} attribSetters object of setters as returned from createAttribSetters,
+ * @property {module:twgl.UniformBlockSpec} [uniformBlockSpace] a uniform block spec for making UniformBlockInfos with createUniformBlockInfo etc..
+ * @property {Object} [transformFeedbackInfo] info for transform feedbacks
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a ProgramInfo from an existing program.
+ *
+ * A ProgramInfo contains
+ *
+ * programInfo = {
+ * program: WebGLProgram,
+ * uniformSetters: object of setters as returned from createUniformSetters,
+ * attribSetters: object of setters as returned from createAttribSetters,
+ * }
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
+ * to use.
+ * @param {WebGLProgram} program an existing WebGLProgram.
+ * @return {module:twgl.ProgramInfo} The created ProgramInfo.
+ * @memberOf module:twgl/programs
+ */
+
+
+function createProgramInfoFromProgram(gl, program) {
+ var uniformSetters = createUniformSetters(gl, program);
+ var attribSetters = createAttributeSetters(gl, program);
+ var programInfo = {
+ program: program,
+ uniformSetters: uniformSetters,
+ attribSetters: attribSetters
+ };
+
+ if (utils.isWebGL2(gl)) {
+ programInfo.uniformBlockSpec = createUniformBlockSpecFromProgram(gl, program);
+ programInfo.transformFeedbackInfo = createTransformFeedbackInfo(gl, program);
+ }
+
+ return programInfo;
+}
+/**
+ * Creates a ProgramInfo from 2 sources.
+ *
+ * A ProgramInfo contains
+ *
+ * programInfo = {
+ * program: WebGLProgram,
+ * uniformSetters: object of setters as returned from createUniformSetters,
+ * attribSetters: object of setters as returned from createAttribSetters,
+ * }
+ *
+ * NOTE: There are 4 signatures for this function
+ *
+ * twgl.createProgramInfo(gl, [vs, fs], options);
+ * twgl.createProgramInfo(gl, [vs, fs], opt_errFunc);
+ * twgl.createProgramInfo(gl, [vs, fs], opt_attribs, opt_errFunc);
+ * twgl.createProgramInfo(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
+ * to use.
+ * @param {string[]} shaderSources Array of sources for the
+ * shaders or ids. The first is assumed to be the vertex shader,
+ * the second the fragment shader.
+ * @param {module:twgl.ProgramOptions|string[]|module:twgl.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
+ * @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
+ * on error. If you want something else pass an callback. It's passed an error message.
+ * @return {module:twgl.ProgramInfo?} The created ProgramInfo or null if it failed to link or compile
+ * @memberOf module:twgl/programs
+ */
+
+
+function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
+ var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
+ var good = true;
+ shaderSources = shaderSources.map(function (source) {
+ // Lets assume if there is no \n it's an id
+ if (source.indexOf("\n") < 0) {
+ var script = getElementById(source);
+
+ if (!script) {
+ progOptions.errorCallback("no element with id: " + source);
+ good = false;
+ } else {
+ source = script.text;
+ }
+ }
+
+ return source;
+ });
+
+ if (!good) {
+ return null;
+ }
+
+ var program = createProgramFromSources(gl, shaderSources, progOptions);
+
+ if (!program) {
+ return null;
+ }
+
+ return createProgramInfoFromProgram(gl, program);
+}
+
+/***/ }),
+
+/***/ "./src/textures.js":
+/*!*************************!*\
+ !*** ./src/textures.js ***!
+ \*************************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.setTextureDefaults_ = setDefaults;
+exports.createSampler = createSampler;
+exports.createSamplers = createSamplers;
+exports.setSamplerParameters = setSamplerParameters;
+exports.createTexture = createTexture;
+exports.setEmptyTexture = setEmptyTexture;
+exports.setTextureFromArray = setTextureFromArray;
+exports.loadTextureFromUrl = loadTextureFromUrl;
+exports.setTextureFromElement = setTextureFromElement;
+exports.setTextureFilteringForSize = setTextureFilteringForSize;
+exports.setTextureParameters = setTextureParameters;
+exports.setDefaultTextureColor = setDefaultTextureColor;
+exports.createTextures = createTextures;
+exports.resizeTexture = resizeTexture;
+exports.canGenerateMipmap = canGenerateMipmap;
+exports.canFilter = canFilter;
+exports.getNumComponentsForFormat = getNumComponentsForFormat;
+exports.getBytesPerElementForInternalFormat = getBytesPerElementForInternalFormat;
+exports.getFormatAndTypeForInternalFormat = getFormatAndTypeForInternalFormat;
+
+var utils = _interopRequireWildcard(__webpack_require__(/*! ./utils.js */ "./src/utils.js"));
+
+var typedArrays = _interopRequireWildcard(__webpack_require__(/*! ./typedarrays.js */ "./src/typedarrays.js"));
+
+var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
+
+function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * Low level texture related functions
+ *
+ * You should generally not need to use these functions. They are provided
+ * for those cases where you're doing something out of the ordinary
+ * and you need lower level access.
+ *
+ * For backward compatibility they are available at both `twgl.textures` and `twgl`
+ * itself
+ *
+ * See {@link module:twgl} for core functions
+ *
+ * @module twgl/textures
+ */
+// make sure we don't see a global gl
+var gl = undefined;
+/* eslint-disable-line */
+
+/* lgtm [js/unused-local-variable] */
+
+var defaults = {
+ textureColor: new Uint8Array([128, 192, 255, 255]),
+ textureOptions: {},
+ crossOrigin: undefined
+};
+var isArrayBuffer = typedArrays.isArrayBuffer; // Should we make this on demand?
+
+var s_ctx;
+
+function getShared2DContext() {
+ s_ctx = s_ctx || (typeof document !== 'undefined' && document.createElement ? document.createElement("canvas").getContext("2d") : null);
+ return s_ctx;
+} // NOTE: Chrome supports 2D canvas in a Worker (behind flag as of v64 but
+// not only does Firefox NOT support it but Firefox freezes immediately
+// if you try to create one instead of just returning null and continuing.
+// : (global.OffscreenCanvas && (new global.OffscreenCanvas(1, 1)).getContext("2d")); // OffscreenCanvas may not support 2d
+// NOTE: We can maybe remove some of the need for the 2d canvas. In WebGL2
+// we can use the various unpack settings. Otherwise we could try using
+// the ability of an ImageBitmap to be cut. Unfortunately cutting an ImageBitmap
+// is async and the current TWGL code expects a non-Async result though that
+// might not be a problem. ImageBitmap though is not available in Edge or Safari
+// as of 2018-01-02
+
+/* PixelFormat */
+
+
+var ALPHA = 0x1906;
+var RGB = 0x1907;
+var RGBA = 0x1908;
+var LUMINANCE = 0x1909;
+var LUMINANCE_ALPHA = 0x190A;
+var DEPTH_COMPONENT = 0x1902;
+var DEPTH_STENCIL = 0x84F9;
+/* TextureWrapMode */
+// const REPEAT = 0x2901;
+// const MIRRORED_REPEAT = 0x8370;
+
+var CLAMP_TO_EDGE = 0x812f;
+/* TextureMagFilter */
+
+var NEAREST = 0x2600;
+var LINEAR = 0x2601;
+/* TextureMinFilter */
+// const NEAREST_MIPMAP_NEAREST = 0x2700;
+// const LINEAR_MIPMAP_NEAREST = 0x2701;
+// const NEAREST_MIPMAP_LINEAR = 0x2702;
+// const LINEAR_MIPMAP_LINEAR = 0x2703;
+
+/* Texture Target */
+
+var TEXTURE_2D = 0x0de1;
+var TEXTURE_CUBE_MAP = 0x8513;
+var TEXTURE_3D = 0x806f;
+var TEXTURE_2D_ARRAY = 0x8c1a;
+/* Cubemap Targets */
+
+var TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515;
+var TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516;
+var TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517;
+var TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518;
+var TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519;
+var TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851a;
+/* Texture Parameters */
+
+var TEXTURE_MIN_FILTER = 0x2801;
+var TEXTURE_MAG_FILTER = 0x2800;
+var TEXTURE_WRAP_S = 0x2802;
+var TEXTURE_WRAP_T = 0x2803;
+var TEXTURE_WRAP_R = 0x8072;
+var TEXTURE_MIN_LOD = 0x813a;
+var TEXTURE_MAX_LOD = 0x813b;
+var TEXTURE_BASE_LEVEL = 0x813c;
+var TEXTURE_MAX_LEVEL = 0x813d;
+/* Pixel store */
+
+var UNPACK_ALIGNMENT = 0x0cf5;
+var UNPACK_ROW_LENGTH = 0x0cf2;
+var UNPACK_IMAGE_HEIGHT = 0x806e;
+var UNPACK_SKIP_PIXELS = 0x0cf4;
+var UNPACK_SKIP_ROWS = 0x0cf3;
+var UNPACK_SKIP_IMAGES = 0x806d;
+var UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243;
+var UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241;
+var UNPACK_FLIP_Y_WEBGL = 0x9240;
+var R8 = 0x8229;
+var R8_SNORM = 0x8F94;
+var R16F = 0x822D;
+var R32F = 0x822E;
+var R8UI = 0x8232;
+var R8I = 0x8231;
+var RG16UI = 0x823A;
+var RG16I = 0x8239;
+var RG32UI = 0x823C;
+var RG32I = 0x823B;
+var RG8 = 0x822B;
+var RG8_SNORM = 0x8F95;
+var RG16F = 0x822F;
+var RG32F = 0x8230;
+var RG8UI = 0x8238;
+var RG8I = 0x8237;
+var R16UI = 0x8234;
+var R16I = 0x8233;
+var R32UI = 0x8236;
+var R32I = 0x8235;
+var RGB8 = 0x8051;
+var SRGB8 = 0x8C41;
+var RGB565 = 0x8D62;
+var RGB8_SNORM = 0x8F96;
+var R11F_G11F_B10F = 0x8C3A;
+var RGB9_E5 = 0x8C3D;
+var RGB16F = 0x881B;
+var RGB32F = 0x8815;
+var RGB8UI = 0x8D7D;
+var RGB8I = 0x8D8F;
+var RGB16UI = 0x8D77;
+var RGB16I = 0x8D89;
+var RGB32UI = 0x8D71;
+var RGB32I = 0x8D83;
+var RGBA8 = 0x8058;
+var SRGB8_ALPHA8 = 0x8C43;
+var RGBA8_SNORM = 0x8F97;
+var RGB5_A1 = 0x8057;
+var RGBA4 = 0x8056;
+var RGB10_A2 = 0x8059;
+var RGBA16F = 0x881A;
+var RGBA32F = 0x8814;
+var RGBA8UI = 0x8D7C;
+var RGBA8I = 0x8D8E;
+var RGB10_A2UI = 0x906F;
+var RGBA16UI = 0x8D76;
+var RGBA16I = 0x8D88;
+var RGBA32I = 0x8D82;
+var RGBA32UI = 0x8D70;
+var DEPTH_COMPONENT16 = 0x81A5;
+var DEPTH_COMPONENT24 = 0x81A6;
+var DEPTH_COMPONENT32F = 0x8CAC;
+var DEPTH32F_STENCIL8 = 0x8CAD;
+var DEPTH24_STENCIL8 = 0x88F0;
+/* DataType */
+
+var BYTE = 0x1400;
+var UNSIGNED_BYTE = 0x1401;
+var SHORT = 0x1402;
+var UNSIGNED_SHORT = 0x1403;
+var INT = 0x1404;
+var UNSIGNED_INT = 0x1405;
+var FLOAT = 0x1406;
+var UNSIGNED_SHORT_4_4_4_4 = 0x8033;
+var UNSIGNED_SHORT_5_5_5_1 = 0x8034;
+var UNSIGNED_SHORT_5_6_5 = 0x8363;
+var HALF_FLOAT = 0x140B;
+var HALF_FLOAT_OES = 0x8D61; // Thanks Khronos for making this different >:(
+
+var UNSIGNED_INT_2_10_10_10_REV = 0x8368;
+var UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B;
+var UNSIGNED_INT_5_9_9_9_REV = 0x8C3E;
+var FLOAT_32_UNSIGNED_INT_24_8_REV = 0x8DAD;
+var UNSIGNED_INT_24_8 = 0x84FA;
+var RG = 0x8227;
+var RG_INTEGER = 0x8228;
+var RED = 0x1903;
+var RED_INTEGER = 0x8D94;
+var RGB_INTEGER = 0x8D98;
+var RGBA_INTEGER = 0x8D99;
+var formatInfo = {};
+{
+ // NOTE: this is named `numColorComponents` vs `numComponents` so we can let Uglify mangle
+ // the name.
+ var f = formatInfo;
+ f[ALPHA] = {
+ numColorComponents: 1
+ };
+ f[LUMINANCE] = {
+ numColorComponents: 1
+ };
+ f[LUMINANCE_ALPHA] = {
+ numColorComponents: 2
+ };
+ f[RGB] = {
+ numColorComponents: 3
+ };
+ f[RGBA] = {
+ numColorComponents: 4
+ };
+ f[RED] = {
+ numColorComponents: 1
+ };
+ f[RED_INTEGER] = {
+ numColorComponents: 1
+ };
+ f[RG] = {
+ numColorComponents: 2
+ };
+ f[RG_INTEGER] = {
+ numColorComponents: 2
+ };
+ f[RGB] = {
+ numColorComponents: 3
+ };
+ f[RGB_INTEGER] = {
+ numColorComponents: 3
+ };
+ f[RGBA] = {
+ numColorComponents: 4
+ };
+ f[RGBA_INTEGER] = {
+ numColorComponents: 4
+ };
+ f[DEPTH_COMPONENT] = {
+ numColorComponents: 1
+ };
+ f[DEPTH_STENCIL] = {
+ numColorComponents: 2
+ };
+}
+/**
+ * @typedef {Object} TextureFormatDetails
+ * @property {number} textureFormat format to pass texImage2D and similar functions.
+ * @property {boolean} colorRenderable true if you can render to this format of texture.
+ * @property {boolean} textureFilterable true if you can filter the texture, false if you can ony use `NEAREST`.
+ * @property {number[]} type Array of possible types you can pass to texImage2D and similar function
+ * @property {Object.} bytesPerElementMap A map of types to bytes per element
+ * @private
+ */
+
+var s_textureInternalFormatInfo;
+
+function getTextureInternalFormatInfo(internalFormat) {
+ if (!s_textureInternalFormatInfo) {
+ // NOTE: these properties need unique names so we can let Uglify mangle the name.
+ var t = {}; // unsized formats
+
+ t[ALPHA] = {
+ textureFormat: ALPHA,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [1, 2, 2, 4],
+ type: [UNSIGNED_BYTE, HALF_FLOAT, HALF_FLOAT_OES, FLOAT]
+ };
+ t[LUMINANCE] = {
+ textureFormat: LUMINANCE,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [1, 2, 2, 4],
+ type: [UNSIGNED_BYTE, HALF_FLOAT, HALF_FLOAT_OES, FLOAT]
+ };
+ t[LUMINANCE_ALPHA] = {
+ textureFormat: LUMINANCE_ALPHA,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [2, 4, 4, 8],
+ type: [UNSIGNED_BYTE, HALF_FLOAT, HALF_FLOAT_OES, FLOAT]
+ };
+ t[RGB] = {
+ textureFormat: RGB,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [3, 6, 6, 12, 2],
+ type: [UNSIGNED_BYTE, HALF_FLOAT, HALF_FLOAT_OES, FLOAT, UNSIGNED_SHORT_5_6_5]
+ };
+ t[RGBA] = {
+ textureFormat: RGBA,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [4, 8, 8, 16, 2, 2],
+ type: [UNSIGNED_BYTE, HALF_FLOAT, HALF_FLOAT_OES, FLOAT, UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_5_5_5_1]
+ }; // sized formats
+
+ t[R8] = {
+ textureFormat: RED,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [1],
+ type: [UNSIGNED_BYTE]
+ };
+ t[R8_SNORM] = {
+ textureFormat: RED,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [1],
+ type: [BYTE]
+ };
+ t[R16F] = {
+ textureFormat: RED,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [4, 2],
+ type: [FLOAT, HALF_FLOAT]
+ };
+ t[R32F] = {
+ textureFormat: RED,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [FLOAT]
+ };
+ t[R8UI] = {
+ textureFormat: RED_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [1],
+ type: [UNSIGNED_BYTE]
+ };
+ t[R8I] = {
+ textureFormat: RED_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [1],
+ type: [BYTE]
+ };
+ t[R16UI] = {
+ textureFormat: RED_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [2],
+ type: [UNSIGNED_SHORT]
+ };
+ t[R16I] = {
+ textureFormat: RED_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [2],
+ type: [SHORT]
+ };
+ t[R32UI] = {
+ textureFormat: RED_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [UNSIGNED_INT]
+ };
+ t[R32I] = {
+ textureFormat: RED_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [INT]
+ };
+ t[RG8] = {
+ textureFormat: RG,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [2],
+ type: [UNSIGNED_BYTE]
+ };
+ t[RG8_SNORM] = {
+ textureFormat: RG,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [2],
+ type: [BYTE]
+ };
+ t[RG16F] = {
+ textureFormat: RG,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [8, 4],
+ type: [FLOAT, HALF_FLOAT]
+ };
+ t[RG32F] = {
+ textureFormat: RG,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [8],
+ type: [FLOAT]
+ };
+ t[RG8UI] = {
+ textureFormat: RG_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [2],
+ type: [UNSIGNED_BYTE]
+ };
+ t[RG8I] = {
+ textureFormat: RG_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [2],
+ type: [BYTE]
+ };
+ t[RG16UI] = {
+ textureFormat: RG_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [UNSIGNED_SHORT]
+ };
+ t[RG16I] = {
+ textureFormat: RG_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [SHORT]
+ };
+ t[RG32UI] = {
+ textureFormat: RG_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [8],
+ type: [UNSIGNED_INT]
+ };
+ t[RG32I] = {
+ textureFormat: RG_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [8],
+ type: [INT]
+ };
+ t[RGB8] = {
+ textureFormat: RGB,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [3],
+ type: [UNSIGNED_BYTE]
+ };
+ t[SRGB8] = {
+ textureFormat: RGB,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [3],
+ type: [UNSIGNED_BYTE]
+ };
+ t[RGB565] = {
+ textureFormat: RGB,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [3, 2],
+ type: [UNSIGNED_BYTE, UNSIGNED_SHORT_5_6_5]
+ };
+ t[RGB8_SNORM] = {
+ textureFormat: RGB,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [3],
+ type: [BYTE]
+ };
+ t[R11F_G11F_B10F] = {
+ textureFormat: RGB,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [12, 6, 4],
+ type: [FLOAT, HALF_FLOAT, UNSIGNED_INT_10F_11F_11F_REV]
+ };
+ t[RGB9_E5] = {
+ textureFormat: RGB,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [12, 6, 4],
+ type: [FLOAT, HALF_FLOAT, UNSIGNED_INT_5_9_9_9_REV]
+ };
+ t[RGB16F] = {
+ textureFormat: RGB,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [12, 6],
+ type: [FLOAT, HALF_FLOAT]
+ };
+ t[RGB32F] = {
+ textureFormat: RGB,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [12],
+ type: [FLOAT]
+ };
+ t[RGB8UI] = {
+ textureFormat: RGB_INTEGER,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [3],
+ type: [UNSIGNED_BYTE]
+ };
+ t[RGB8I] = {
+ textureFormat: RGB_INTEGER,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [3],
+ type: [BYTE]
+ };
+ t[RGB16UI] = {
+ textureFormat: RGB_INTEGER,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [6],
+ type: [UNSIGNED_SHORT]
+ };
+ t[RGB16I] = {
+ textureFormat: RGB_INTEGER,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [6],
+ type: [SHORT]
+ };
+ t[RGB32UI] = {
+ textureFormat: RGB_INTEGER,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [12],
+ type: [UNSIGNED_INT]
+ };
+ t[RGB32I] = {
+ textureFormat: RGB_INTEGER,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [12],
+ type: [INT]
+ };
+ t[RGBA8] = {
+ textureFormat: RGBA,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [4],
+ type: [UNSIGNED_BYTE]
+ };
+ t[SRGB8_ALPHA8] = {
+ textureFormat: RGBA,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [4],
+ type: [UNSIGNED_BYTE]
+ };
+ t[RGBA8_SNORM] = {
+ textureFormat: RGBA,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [4],
+ type: [BYTE]
+ };
+ t[RGB5_A1] = {
+ textureFormat: RGBA,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [4, 2, 4],
+ type: [UNSIGNED_BYTE, UNSIGNED_SHORT_5_5_5_1, UNSIGNED_INT_2_10_10_10_REV]
+ };
+ t[RGBA4] = {
+ textureFormat: RGBA,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [4, 2],
+ type: [UNSIGNED_BYTE, UNSIGNED_SHORT_4_4_4_4]
+ };
+ t[RGB10_A2] = {
+ textureFormat: RGBA,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [4],
+ type: [UNSIGNED_INT_2_10_10_10_REV]
+ };
+ t[RGBA16F] = {
+ textureFormat: RGBA,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [16, 8],
+ type: [FLOAT, HALF_FLOAT]
+ };
+ t[RGBA32F] = {
+ textureFormat: RGBA,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [16],
+ type: [FLOAT]
+ };
+ t[RGBA8UI] = {
+ textureFormat: RGBA_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [UNSIGNED_BYTE]
+ };
+ t[RGBA8I] = {
+ textureFormat: RGBA_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [BYTE]
+ };
+ t[RGB10_A2UI] = {
+ textureFormat: RGBA_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [UNSIGNED_INT_2_10_10_10_REV]
+ };
+ t[RGBA16UI] = {
+ textureFormat: RGBA_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [8],
+ type: [UNSIGNED_SHORT]
+ };
+ t[RGBA16I] = {
+ textureFormat: RGBA_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [8],
+ type: [SHORT]
+ };
+ t[RGBA32I] = {
+ textureFormat: RGBA_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [16],
+ type: [INT]
+ };
+ t[RGBA32UI] = {
+ textureFormat: RGBA_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [16],
+ type: [UNSIGNED_INT]
+ }; // Sized Internal
+
+ t[DEPTH_COMPONENT16] = {
+ textureFormat: DEPTH_COMPONENT,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [2, 4],
+ type: [UNSIGNED_SHORT, UNSIGNED_INT]
+ };
+ t[DEPTH_COMPONENT24] = {
+ textureFormat: DEPTH_COMPONENT,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [UNSIGNED_INT]
+ };
+ t[DEPTH_COMPONENT32F] = {
+ textureFormat: DEPTH_COMPONENT,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [FLOAT]
+ };
+ t[DEPTH24_STENCIL8] = {
+ textureFormat: DEPTH_STENCIL,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [UNSIGNED_INT_24_8]
+ };
+ t[DEPTH32F_STENCIL8] = {
+ textureFormat: DEPTH_STENCIL,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [FLOAT_32_UNSIGNED_INT_24_8_REV]
+ };
+ Object.keys(t).forEach(function (internalFormat) {
+ var info = t[internalFormat];
+ info.bytesPerElementMap = {};
+ info.bytesPerElement.forEach(function (bytesPerElement, ndx) {
+ var type = info.type[ndx];
+ info.bytesPerElementMap[type] = bytesPerElement;
+ });
+ });
+ s_textureInternalFormatInfo = t;
+ }
+
+ return s_textureInternalFormatInfo[internalFormat];
+}
+/**
+ * Gets the number of bytes per element for a given internalFormat / type
+ * @param {number} internalFormat The internalFormat parameter from texImage2D etc..
+ * @param {number} type The type parameter for texImage2D etc..
+ * @return {number} the number of bytes per element for the given internalFormat, type combo
+ * @memberOf module:twgl/textures
+ */
+
+
+function getBytesPerElementForInternalFormat(internalFormat, type) {
+ var info = getTextureInternalFormatInfo(internalFormat);
+
+ if (!info) {
+ throw "unknown internal format";
+ }
+
+ var bytesPerElement = info.bytesPerElementMap[type];
+
+ if (bytesPerElement === undefined) {
+ throw "unknown internal format";
+ }
+
+ return bytesPerElement;
+}
+/**
+ * Info related to a specific texture internalFormat as returned
+ * from {@link module:twgl/textures.getFormatAndTypeForInternalFormat}.
+ *
+ * @typedef {Object} TextureFormatInfo
+ * @property {number} format Format to pass to texImage2D and related functions
+ * @property {number} type Type to pass to texImage2D and related functions
+ * @memberOf module:twgl/textures
+ */
+
+/**
+ * Gets the format and type for a given internalFormat
+ *
+ * @param {number} internalFormat The internal format
+ * @return {module:twgl/textures.TextureFormatInfo} the corresponding format and type,
+ * @memberOf module:twgl/textures
+ */
+
+
+function getFormatAndTypeForInternalFormat(internalFormat) {
+ var info = getTextureInternalFormatInfo(internalFormat);
+
+ if (!info) {
+ throw "unknown internal format";
+ }
+
+ return {
+ format: info.textureFormat,
+ type: info.type[0]
+ };
+}
+/**
+ * Returns true if value is power of 2
+ * @param {number} value number to check.
+ * @return true if value is power of 2
+ * @private
+ */
+
+
+function isPowerOf2(value) {
+ return (value & value - 1) === 0;
+}
+/**
+ * Gets whether or not we can generate mips for the given
+ * internal format.
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {number} width The width parameter from texImage2D etc..
+ * @param {number} height The height parameter from texImage2D etc..
+ * @param {number} internalFormat The internalFormat parameter from texImage2D etc..
+ * @return {boolean} true if we can generate mips
+ * @memberOf module:twgl/textures
+ */
+
+
+function canGenerateMipmap(gl, width, height, internalFormat) {
+ if (!utils.isWebGL2(gl)) {
+ return isPowerOf2(width) && isPowerOf2(height);
+ }
+
+ var info = getTextureInternalFormatInfo(internalFormat);
+
+ if (!info) {
+ throw "unknown internal format";
+ }
+
+ return info.colorRenderable && info.textureFilterable;
+}
+/**
+ * Gets whether or not we can generate mips for the given format
+ * @param {number} internalFormat The internalFormat parameter from texImage2D etc..
+ * @return {boolean} true if we can generate mips
+ * @memberOf module:twgl/textures
+ */
+
+
+function canFilter(internalFormat) {
+ var info = getTextureInternalFormatInfo(internalFormat);
+
+ if (!info) {
+ throw "unknown internal format";
+ }
+
+ return info.textureFilterable;
+}
+/**
+ * Gets the number of components for a given image format.
+ * @param {number} format the format.
+ * @return {number} the number of components for the format.
+ * @memberOf module:twgl/textures
+ */
+
+
+function getNumComponentsForFormat(format) {
+ var info = formatInfo[format];
+
+ if (!info) {
+ throw "unknown format: " + format;
+ }
+
+ return info.numColorComponents;
+}
+/**
+ * Gets the texture type for a given array type.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @return {number} the gl texture type
+ * @private
+ */
+
+
+function getTextureTypeForArrayType(gl, src, defaultType) {
+ if (isArrayBuffer(src)) {
+ return typedArrays.getGLTypeForTypedArray(src);
+ }
+
+ return defaultType || UNSIGNED_BYTE;
+}
+
+function guessDimensions(gl, target, width, height, numElements) {
+ if (numElements % 1 !== 0) {
+ throw "can't guess dimensions";
+ }
+
+ if (!width && !height) {
+ var size = Math.sqrt(numElements / (target === TEXTURE_CUBE_MAP ? 6 : 1));
+
+ if (size % 1 === 0) {
+ width = size;
+ height = size;
+ } else {
+ width = numElements;
+ height = 1;
+ }
+ } else if (!height) {
+ height = numElements / width;
+
+ if (height % 1) {
+ throw "can't guess dimensions";
+ }
+ } else if (!width) {
+ width = numElements / height;
+
+ if (width % 1) {
+ throw "can't guess dimensions";
+ }
+ }
+
+ return {
+ width: width,
+ height: height
+ };
+}
+/**
+ * Sets the default texture color.
+ *
+ * The default texture color is used when loading textures from
+ * urls. Because the URL will be loaded async we'd like to be
+ * able to use the texture immediately. By putting a 1x1 pixel
+ * color in the texture we can start using the texture before
+ * the URL has loaded.
+ *
+ * @param {number[]} color Array of 4 values in the range 0 to 1
+ * @deprecated see {@link module:twgl.setDefaults}
+ * @memberOf module:twgl/textures
+ */
+
+
+function setDefaultTextureColor(color) {
+ defaults.textureColor = new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);
+}
+
+function setDefaults(newDefaults) {
+ helper.copyExistingProperties(newDefaults, defaults);
+
+ if (newDefaults.textureColor) {
+ setDefaultTextureColor(newDefaults.textureColor);
+ }
+}
+/**
+ * A function to generate the source for a texture.
+ * @callback TextureFunc
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @param {module:twgl.TextureOptions} options the texture options
+ * @return {*} Returns any of the things documented for `src` for {@link module:twgl.TextureOptions}.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Texture options passed to most texture functions. Each function will use whatever options
+ * are appropriate for its needs. This lets you pass the same options to all functions.
+ *
+ * Note: A `TexImageSource` is defined in the WebGL spec as a `HTMLImageElement`, `HTMLVideoElement`,
+ * `HTMLCanvasElement`, `ImageBitmap`, or `ImageData`.
+ *
+ * @typedef {Object} TextureOptions
+ * @property {number} [target] the type of texture `gl.TEXTURE_2D` or `gl.TEXTURE_CUBE_MAP`. Defaults to `gl.TEXTURE_2D`.
+ * @property {number} [level] the mip level to affect. Defaults to 0. Note, if set auto will be considered false unless explicitly set to true.
+ * @property {number} [width] the width of the texture. Only used if src is an array or typed array or null.
+ * @property {number} [height] the height of a texture. Only used if src is an array or typed array or null.
+ * @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` .
+ * @property {number} [min] the min filter setting (eg. `gl.LINEAR`). Defaults to `gl.NEAREST_MIPMAP_LINEAR`
+ * or if texture is not a power of 2 on both dimensions then defaults to `gl.LINEAR`.
+ * @property {number} [mag] the mag filter setting (eg. `gl.LINEAR`). Defaults to `gl.LINEAR`
+ * @property {number} [minMag] both the min and mag filter settings.
+ * @property {number} [internalFormat] internal format for texture. Defaults to `gl.RGBA`
+ * @property {number} [format] format for texture. Defaults to `gl.RGBA`.
+ * @property {number} [type] type for texture. Defaults to `gl.UNSIGNED_BYTE` unless `src` is ArrayBufferView. If `src`
+ * is ArrayBufferView defaults to type that matches ArrayBufferView type.
+ * @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
+ * @property {number} [wrapS] Texture wrapping for S. Defaults to `gl.REPEAT` and `gl.CLAMP_TO_EDGE` for cube. If set takes precedence over `wrap`.
+ * @property {number} [wrapT] Texture wrapping for T. Defaults to `gl.REPEAT` and `gl.CLAMP_TO_EDGE` for cube. If set takes precedence over `wrap`.
+ * @property {number} [wrapR] Texture wrapping for R. Defaults to `gl.REPEAT` and `gl.CLAMP_TO_EDGE` for cube. If set takes precedence over `wrap`.
+ * @property {number} [minLod] TEXTURE_MIN_LOD setting
+ * @property {number} [maxLod] TEXTURE_MAX_LOD setting
+ * @property {number} [baseLevel] TEXTURE_BASE_LEVEL setting
+ * @property {number} [maxLevel] TEXTURE_MAX_LEVEL setting
+ * @property {number} [unpackAlignment] The `gl.UNPACK_ALIGNMENT` used when uploading an array. Defaults to 1.
+ * @property {number[]|ArrayBufferView} [color] Color to initialize this texture with if loading an image asynchronously.
+ * The default use a blue 1x1 pixel texture. You can set another default by calling `twgl.setDefaults`
+ * or you can set an individual texture's initial color by setting this property. Example: `[1, .5, .5, 1]` = pink
+ * @property {number} [premultiplyAlpha] Whether or not to premultiply alpha. Defaults to whatever the current setting is.
+ * This lets you set it once before calling `twgl.createTexture` or `twgl.createTextures` and only override
+ * the current setting for specific textures.
+ * @property {number} [flipY] Whether or not to flip the texture vertically on upload. Defaults to whatever the current setting is.
+ * This lets you set it once before calling `twgl.createTexture` or `twgl.createTextures` and only override
+ * the current setting for specific textures.
+ * @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.
+ * This lets you set it once before calling `twgl.createTexture` or `twgl.createTextures` and only override
+ * the current setting for specific textures.
+ * @property {boolean} [auto] If `undefined` or `true`, in WebGL1, texture filtering is set automatically for non-power of 2 images and
+ * mips are generated for power of 2 images. In WebGL2 mips are generated if they can be. Note: if `level` is set above
+ * then then `auto` is assumed to be `false` unless explicity set to `true`.
+ * @property {number[]} [cubeFaceOrder] The order that cube faces are pulled out of an img or set of images. The default is
+ *
+ * [gl.TEXTURE_CUBE_MAP_POSITIVE_X,
+ * gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
+ * gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
+ * gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
+ * gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
+ * gl.TEXTURE_CUBE_MAP_NEGATIVE_Z]
+ *
+ * @property {(number[]|ArrayBufferView|TexImageSource|TexImageSource[]|string|string[]|module:twgl.TextureFunc)} [src] source for texture
+ *
+ * If `string` then it's assumed to be a URL to an image. The image will be downloaded async. A usable
+ * 1x1 pixel texture will be returned immediately. The texture will be updated once the image has downloaded.
+ * If `target` is `gl.TEXTURE_CUBE_MAP` will attempt to divide image into 6 square pieces. 1x6, 6x1, 3x2, 2x3.
+ * The pieces will be uploaded in `cubeFaceOrder`
+ *
+ * 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.
+ *
+ * If `string[]` or `TexImageSource[]` and target is `gl.TEXTURE_2D_ARRAY` then each entry is a slice of the a 2d array texture
+ * and will be scaled to the specified width and height OR to the size of the first image that loads.
+ *
+ * If `TexImageSource` then it wil be used immediately to create the contents of the texture. Examples `HTMLImageElement`,
+ * `HTMLCanvasElement`, `HTMLVideoElement`.
+ *
+ * If `number[]` or `ArrayBufferView` it's assumed to be data for a texture. If `width` or `height` is
+ * not specified it is guessed as follows. First the number of elements is computed by `src.length / numComponents`
+ * where `numComponents` is derived from `format`. If `target` is `gl.TEXTURE_CUBE_MAP` then `numElements` is divided
+ * by 6. Then
+ *
+ * * If neither `width` nor `height` are specified and `sqrt(numElements)` is an integer then width and height
+ * are set to `sqrt(numElements)`. Otherwise `width = numElements` and `height = 1`.
+ *
+ * * If only one of `width` or `height` is specified then the other equals `numElements / specifiedDimension`.
+ *
+ * If `number[]` will be converted to `type`.
+ *
+ * If `src` is a function it will be called with a `WebGLRenderingContext` and these options.
+ * Whatever it returns is subject to these rules. So it can return a string url, an `HTMLElement`
+ * an array etc...
+ *
+ * If `src` is undefined then an empty texture will be created of size `width` by `height`.
+ *
+ * @property {string} [crossOrigin] What to set the crossOrigin property of images when they are downloaded.
+ * default: undefined. Also see {@link module:twgl.setDefaults}.
+ *
+ * @memberOf module:twgl
+ */
+// NOTE: While querying GL is considered slow it's not remotely as slow
+// as uploading a texture. On top of that you're unlikely to call this in
+// a perf critical loop. Even if upload a texture every frame that's unlikely
+// to be more than 1 or 2 textures a frame. In other words, the benefits of
+// making the API easy to use outweigh any supposed perf benefits
+//
+// Also note I get that having one global of these is bad practice.
+// As long as it's used correctly it means no garbage which probably
+// doesn't matter when dealing with textures but old habits die hard.
+
+
+var lastPackState = {};
+/**
+ * Saves any packing state that will be set based on the options.
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @private
+ */
+
+function savePackState(gl, options) {
+ if (options.colorspaceConversion !== undefined) {
+ lastPackState.colorspaceConversion = gl.getParameter(UNPACK_COLORSPACE_CONVERSION_WEBGL);
+ gl.pixelStorei(UNPACK_COLORSPACE_CONVERSION_WEBGL, options.colorspaceConversion);
+ }
+
+ if (options.premultiplyAlpha !== undefined) {
+ lastPackState.premultiplyAlpha = gl.getParameter(UNPACK_PREMULTIPLY_ALPHA_WEBGL);
+ gl.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL, options.premultiplyAlpha);
+ }
+
+ if (options.flipY !== undefined) {
+ lastPackState.flipY = gl.getParameter(UNPACK_FLIP_Y_WEBGL);
+ gl.pixelStorei(UNPACK_FLIP_Y_WEBGL, options.flipY);
+ }
+}
+/**
+ * Restores any packing state that was set based on the options.
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @private
+ */
+
+
+function restorePackState(gl, options) {
+ if (options.colorspaceConversion !== undefined) {
+ gl.pixelStorei(UNPACK_COLORSPACE_CONVERSION_WEBGL, lastPackState.colorspaceConversion);
+ }
+
+ if (options.premultiplyAlpha !== undefined) {
+ gl.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL, lastPackState.premultiplyAlpha);
+ }
+
+ if (options.flipY !== undefined) {
+ gl.pixelStorei(UNPACK_FLIP_Y_WEBGL, lastPackState.flipY);
+ }
+}
+/**
+ * Saves state related to data size
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @private
+ */
+
+
+function saveSkipState(gl) {
+ lastPackState.unpackAlignment = gl.getParameter(UNPACK_ALIGNMENT);
+
+ if (utils.isWebGL2(gl)) {
+ lastPackState.unpackRowLength = gl.getParameter(UNPACK_ROW_LENGTH);
+ lastPackState.unpackImageHeight = gl.getParameter(UNPACK_IMAGE_HEIGHT);
+ lastPackState.unpackSkipPixels = gl.getParameter(UNPACK_SKIP_PIXELS);
+ lastPackState.unpackSkipRows = gl.getParameter(UNPACK_SKIP_ROWS);
+ lastPackState.unpackSkipImages = gl.getParameter(UNPACK_SKIP_IMAGES);
+ }
+}
+/**
+ * Restores state related to data size
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @private
+ */
+
+
+function restoreSkipState(gl) {
+ gl.pixelStorei(UNPACK_ALIGNMENT, lastPackState.unpackAlignment);
+
+ if (utils.isWebGL2(gl)) {
+ gl.pixelStorei(UNPACK_ROW_LENGTH, lastPackState.unpackRowLength);
+ gl.pixelStorei(UNPACK_IMAGE_HEIGHT, lastPackState.unpackImageHeight);
+ gl.pixelStorei(UNPACK_SKIP_PIXELS, lastPackState.unpackSkipPixels);
+ gl.pixelStorei(UNPACK_SKIP_ROWS, lastPackState.unpackSkipRows);
+ gl.pixelStorei(UNPACK_SKIP_IMAGES, lastPackState.unpackSkipImages);
+ }
+}
+/**
+ * Sets the parameters of a texture or sampler
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {number|WebGLSampler} target texture target or sampler
+ * @param {function()} parameteriFn texParameteri or samplerParameteri fn
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @private
+ */
+
+
+function setTextureSamplerParameters(gl, target, parameteriFn, options) {
+ if (options.minMag) {
+ parameteriFn.call(gl, target, TEXTURE_MIN_FILTER, options.minMag);
+ parameteriFn.call(gl, target, TEXTURE_MAG_FILTER, options.minMag);
+ }
+
+ if (options.min) {
+ parameteriFn.call(gl, target, TEXTURE_MIN_FILTER, options.min);
+ }
+
+ if (options.mag) {
+ parameteriFn.call(gl, target, TEXTURE_MAG_FILTER, options.mag);
+ }
+
+ if (options.wrap) {
+ parameteriFn.call(gl, target, TEXTURE_WRAP_S, options.wrap);
+ parameteriFn.call(gl, target, TEXTURE_WRAP_T, options.wrap);
+
+ if (target === TEXTURE_3D || helper.isSampler(gl, target)) {
+ parameteriFn.call(gl, target, TEXTURE_WRAP_R, options.wrap);
+ }
+ }
+
+ if (options.wrapR) {
+ parameteriFn.call(gl, target, TEXTURE_WRAP_R, options.wrapR);
+ }
+
+ if (options.wrapS) {
+ parameteriFn.call(gl, target, TEXTURE_WRAP_S, options.wrapS);
+ }
+
+ if (options.wrapT) {
+ parameteriFn.call(gl, target, TEXTURE_WRAP_T, options.wrapT);
+ }
+
+ if (options.minLod) {
+ parameteriFn.call(gl, target, TEXTURE_MIN_LOD, options.minLod);
+ }
+
+ if (options.maxLod) {
+ parameteriFn.call(gl, target, TEXTURE_MAX_LOD, options.maxLod);
+ }
+
+ if (options.baseLevel) {
+ parameteriFn.call(gl, target, TEXTURE_BASE_LEVEL, options.baseLevel);
+ }
+
+ if (options.maxLevel) {
+ parameteriFn.call(gl, target, TEXTURE_MAX_LEVEL, options.maxLevel);
+ }
+}
+/**
+ * Sets the texture parameters of a texture.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @memberOf module:twgl/textures
+ */
+
+
+function setTextureParameters(gl, tex, options) {
+ var target = options.target || TEXTURE_2D;
+ gl.bindTexture(target, tex);
+ setTextureSamplerParameters(gl, target, gl.texParameteri, options);
+}
+/**
+ * Sets the sampler parameters of a sampler.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLSampler} sampler the WebGLSampler to set parameters for
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @memberOf module:twgl/textures
+ */
+
+
+function setSamplerParameters(gl, sampler, options) {
+ setTextureSamplerParameters(gl, sampler, gl.samplerParameteri, options);
+}
+/**
+ * Creates a new sampler object and sets parameters.
+ *
+ * Example:
+ *
+ * const sampler = twgl.createSampler(gl, {
+ * minMag: gl.NEAREST, // sets both TEXTURE_MIN_FILTER and TEXTURE_MAG_FILTER
+ * wrap: gl.CLAMP_TO_NEAREST, // sets both TEXTURE_WRAP_S and TEXTURE_WRAP_T and TEXTURE_WRAP_R
+ * });
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {Object.} options A object of TextureOptions one per sampler.
+ * @return {Object.} the created samplers by name
+ * @private
+ */
+
+
+function createSampler(gl, options) {
+ var sampler = gl.createSampler();
+ setSamplerParameters(gl, sampler, options);
+ return sampler;
+}
+/**
+ * Creates a multiple sampler objects and sets parameters on each.
+ *
+ * Example:
+ *
+ * const samplers = twgl.createSamplers(gl, {
+ * nearest: {
+ * minMag: gl.NEAREST,
+ * },
+ * nearestClampS: {
+ * minMag: gl.NEAREST,
+ * wrapS: gl.CLAMP_TO_NEAREST,
+ * },
+ * linear: {
+ * minMag: gl.LINEAR,
+ * },
+ * nearestClamp: {
+ * minMag: gl.NEAREST,
+ * wrap: gl.CLAMP_TO_EDGE,
+ * },
+ * linearClamp: {
+ * minMag: gl.LINEAR,
+ * wrap: gl.CLAMP_TO_EDGE,
+ * },
+ * linearClampT: {
+ * minMag: gl.LINEAR,
+ * wrapT: gl.CLAMP_TO_EDGE,
+ * },
+ * });
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set on the sampler
+ * @private
+ */
+
+
+function createSamplers(gl, samplerOptions) {
+ var samplers = {};
+ Object.keys(samplerOptions).forEach(function (name) {
+ samplers[name] = createSampler(gl, samplerOptions[name]);
+ });
+ return samplers;
+}
+/**
+ * Makes a 1x1 pixel
+ * If no color is passed in uses the default color which can be set by calling `setDefaultTextureColor`.
+ * @param {(number[]|ArrayBufferView)} [color] The color using 0-1 values
+ * @return {Uint8Array} Unit8Array with color.
+ * @private
+ */
+
+
+function make1Pixel(color) {
+ color = color || defaults.textureColor;
+
+ if (isArrayBuffer(color)) {
+ return color;
+ }
+
+ return new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);
+}
+/**
+ * Sets filtering or generates mips for texture based on width or height
+ * If width or height is not passed in uses `options.width` and//or `options.height`
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @param {number} [width] width of texture
+ * @param {number} [height] height of texture
+ * @param {number} [internalFormat] The internalFormat parameter from texImage2D etc..
+ * @memberOf module:twgl/textures
+ */
+
+
+function setTextureFilteringForSize(gl, tex, options, width, height, internalFormat) {
+ options = options || defaults.textureOptions;
+ internalFormat = internalFormat || RGBA;
+ var target = options.target || TEXTURE_2D;
+ width = width || options.width;
+ height = height || options.height;
+ gl.bindTexture(target, tex);
+
+ if (canGenerateMipmap(gl, width, height, internalFormat)) {
+ gl.generateMipmap(target);
+ } else {
+ var filtering = canFilter(internalFormat) ? LINEAR : NEAREST;
+ gl.texParameteri(target, TEXTURE_MIN_FILTER, filtering);
+ gl.texParameteri(target, TEXTURE_MAG_FILTER, filtering);
+ gl.texParameteri(target, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
+ gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
+ }
+}
+
+function shouldAutomaticallySetTextureFilteringForSize(options) {
+ return options.auto === true || options.auto === undefined && options.level === undefined;
+}
+/**
+ * Gets an array of cubemap face enums
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @return {number[]} cubemap face enums
+ * @private
+ */
+
+
+function getCubeFaceOrder(gl, options) {
+ options = options || {};
+ return options.cubeFaceOrder || [TEXTURE_CUBE_MAP_POSITIVE_X, TEXTURE_CUBE_MAP_NEGATIVE_X, TEXTURE_CUBE_MAP_POSITIVE_Y, TEXTURE_CUBE_MAP_NEGATIVE_Y, TEXTURE_CUBE_MAP_POSITIVE_Z, TEXTURE_CUBE_MAP_NEGATIVE_Z];
+}
+/**
+ * @typedef {Object} FaceInfo
+ * @property {number} face gl enum for texImage2D
+ * @property {number} ndx face index (0 - 5) into source data
+ * @ignore
+ */
+
+/**
+ * Gets an array of FaceInfos
+ * There's a bug in some NVidia drivers that will crash the driver if
+ * `gl.TEXTURE_CUBE_MAP_POSITIVE_X` is not uploaded first. So, we take
+ * the user's desired order from his faces to WebGL and make sure we
+ * do the faces in WebGL order
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @return {FaceInfo[]} cubemap face infos. Arguably the `face` property of each element is redundant but
+ * it's needed internally to sort the array of `ndx` properties by `face`.
+ * @private
+ */
+
+
+function getCubeFacesWithNdx(gl, options) {
+ var faces = getCubeFaceOrder(gl, options); // work around bug in NVidia drivers. We have to upload the first face first else the driver crashes :(
+
+ var facesWithNdx = faces.map(function (face, ndx) {
+ return {
+ face: face,
+ ndx: ndx
+ };
+ });
+ facesWithNdx.sort(function (a, b) {
+ return a.face - b.face;
+ });
+ return facesWithNdx;
+}
+/**
+ * Set a texture from the contents of an element. Will also set
+ * texture filtering or generate mips based on the dimensions of the element
+ * unless `options.auto === false`. If `target === gl.TEXTURE_CUBE_MAP` will
+ * attempt to slice image into 1x6, 2x3, 3x2, or 6x1 images, one for each face.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {HTMLElement} element a canvas, img, or video element.
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @memberOf module:twgl/textures
+ * @kind function
+ */
+
+
+function setTextureFromElement(gl, tex, element, options) {
+ options = options || defaults.textureOptions;
+ var target = options.target || TEXTURE_2D;
+ var level = options.level || 0;
+ var width = element.width;
+ var height = element.height;
+ var internalFormat = options.internalFormat || options.format || RGBA;
+ var formatType = getFormatAndTypeForInternalFormat(internalFormat);
+ var format = options.format || formatType.format;
+ var type = options.type || formatType.type;
+ savePackState(gl, options);
+ gl.bindTexture(target, tex);
+
+ if (target === TEXTURE_CUBE_MAP) {
+ // guess the parts
+ var imgWidth = element.width;
+ var imgHeight = element.height;
+ var size;
+ var slices;
+
+ if (imgWidth / 6 === imgHeight) {
+ // It's 6x1
+ size = imgHeight;
+ slices = [0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0];
+ } else if (imgHeight / 6 === imgWidth) {
+ // It's 1x6
+ size = imgWidth;
+ slices = [0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5];
+ } else if (imgWidth / 3 === imgHeight / 2) {
+ // It's 3x2
+ size = imgWidth / 3;
+ slices = [0, 0, 1, 0, 2, 0, 0, 1, 1, 1, 2, 1];
+ } else if (imgWidth / 2 === imgHeight / 3) {
+ // It's 2x3
+ size = imgWidth / 2;
+ slices = [0, 0, 1, 0, 0, 1, 1, 1, 0, 2, 1, 2];
+ } else {
+ throw "can't figure out cube map from element: " + (element.src ? element.src : element.nodeName);
+ }
+
+ var ctx = getShared2DContext();
+
+ if (ctx) {
+ ctx.canvas.width = size;
+ ctx.canvas.height = size;
+ width = size;
+ height = size;
+ getCubeFacesWithNdx(gl, options).forEach(function (f) {
+ var xOffset = slices[f.ndx * 2 + 0] * size;
+ var yOffset = slices[f.ndx * 2 + 1] * size;
+ ctx.drawImage(element, xOffset, yOffset, size, size, 0, 0, size, size);
+ gl.texImage2D(f.face, level, internalFormat, format, type, ctx.canvas);
+ }); // Free up the canvas memory
+
+ ctx.canvas.width = 1;
+ ctx.canvas.height = 1;
+ } else if (typeof createImageBitmap !== 'undefined') {
+ // NOTE: It seems like we should prefer ImageBitmap because unlike canvas it's
+ // note lossy? (alpha is not premultiplied? although I'm not sure what
+ width = size;
+ height = size;
+ getCubeFacesWithNdx(gl, options).forEach(function (f) {
+ var xOffset = slices[f.ndx * 2 + 0] * size;
+ var yOffset = slices[f.ndx * 2 + 1] * size; // We can't easily use a default texture color here as it would have to match
+ // the type across all faces where as with a 2D one there's only one face
+ // so we're replacing everything all at once. It also has to be the correct size.
+ // On the other hand we need all faces to be the same size so as one face loads
+ // the rest match else the texture will be un-renderable.
+
+ gl.texImage2D(f.face, level, internalFormat, size, size, 0, format, type, null);
+ createImageBitmap(element, xOffset, yOffset, size, size, {
+ premultiplyAlpha: 'none',
+ colorSpaceConversion: 'none'
+ }).then(function (imageBitmap) {
+ savePackState(gl, options);
+ gl.bindTexture(target, tex);
+ gl.texImage2D(f.face, level, internalFormat, format, type, imageBitmap);
+ restorePackState(gl, options);
+
+ if (shouldAutomaticallySetTextureFilteringForSize(options)) {
+ setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
+ }
+ });
+ });
+ }
+ } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
+ var smallest = Math.min(element.width, element.height);
+ var largest = Math.max(element.width, element.height);
+ var depth = largest / smallest;
+
+ if (depth % 1 !== 0) {
+ throw "can not compute 3D dimensions of element";
+ }
+
+ var xMult = element.width === largest ? 1 : 0;
+ var yMult = element.height === largest ? 1 : 0;
+ saveSkipState(gl);
+ gl.pixelStorei(UNPACK_ALIGNMENT, 1);
+ gl.pixelStorei(UNPACK_ROW_LENGTH, element.width);
+ gl.pixelStorei(UNPACK_IMAGE_HEIGHT, 0);
+ gl.pixelStorei(UNPACK_SKIP_IMAGES, 0);
+ gl.texImage3D(target, level, internalFormat, smallest, smallest, smallest, 0, format, type, null);
+
+ for (var d = 0; d < depth; ++d) {
+ var srcX = d * smallest * xMult;
+ var srcY = d * smallest * yMult;
+ gl.pixelStorei(UNPACK_SKIP_PIXELS, srcX);
+ gl.pixelStorei(UNPACK_SKIP_ROWS, srcY);
+ gl.texSubImage3D(target, level, 0, 0, d, smallest, smallest, 1, format, type, element);
+ }
+
+ restoreSkipState(gl);
+ } else {
+ gl.texImage2D(target, level, internalFormat, format, type, element);
+ }
+
+ restorePackState(gl, options);
+
+ if (shouldAutomaticallySetTextureFilteringForSize(options)) {
+ setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
+ }
+
+ setTextureParameters(gl, tex, options);
+}
+
+function noop() {}
+/**
+ * Checks whether the url's origin is the same so that we can set the `crossOrigin`
+ * @param {string} url url to image
+ * @returns {boolean} true if the window's origin is the same as image's url
+ * @private
+ */
+
+
+function urlIsSameOrigin(url) {
+ if (typeof document !== 'undefined') {
+ // for IE really
+ var a = document.createElement('a');
+ a.href = url;
+ return a.hostname === location.hostname && a.port === location.port && a.protocol === location.protocol;
+ } else {
+ var localOrigin = new URL(location.href).origin;
+ var urlOrigin = new URL(url, location.href).origin;
+ return urlOrigin === localOrigin;
+ }
+}
+
+function setToAnonymousIfUndefinedAndURLIsNotSameOrigin(url, crossOrigin) {
+ return crossOrigin === undefined && !urlIsSameOrigin(url) ? 'anonymous' : crossOrigin;
+}
+/**
+ * Loads an image
+ * @param {string} url url to image
+ * @param {string} crossOrigin
+ * @param {function(err, img)} [callback] a callback that's passed an error and the image. The error will be non-null
+ * if there was an error
+ * @return {HTMLImageElement} the image being loaded.
+ * @private
+ */
+
+
+function loadImage(url, crossOrigin, callback) {
+ callback = callback || noop;
+ var img;
+ crossOrigin = crossOrigin !== undefined ? crossOrigin : defaults.crossOrigin;
+ crossOrigin = setToAnonymousIfUndefinedAndURLIsNotSameOrigin(url, crossOrigin);
+
+ if (typeof Image !== 'undefined') {
+ img = new Image();
+
+ if (crossOrigin !== undefined) {
+ img.crossOrigin = crossOrigin;
+ }
+
+ var clearEventHandlers = function clearEventHandlers() {
+ img.removeEventListener('error', onError); // eslint-disable-line
+
+ img.removeEventListener('load', onLoad); // eslint-disable-line
+
+ img = null;
+ };
+
+ var onError = function onError() {
+ var msg = "couldn't load image: " + url;
+ helper.error(msg);
+ callback(msg, img);
+ clearEventHandlers();
+ };
+
+ var onLoad = function onLoad() {
+ callback(null, img);
+ clearEventHandlers();
+ };
+
+ img.addEventListener('error', onError);
+ img.addEventListener('load', onLoad);
+ img.src = url;
+ return img;
+ } else if (typeof ImageBitmap !== 'undefined') {
+ var err;
+ var bm;
+
+ var cb = function cb() {
+ callback(err, bm);
+ };
+
+ var options = {};
+
+ if (crossOrigin) {
+ options.mode = 'cors'; // TODO: not sure how to translate image.crossOrigin
+ }
+
+ fetch(url, options).then(function (response) {
+ if (!response.ok) {
+ throw response;
+ }
+
+ return response.blob();
+ }).then(function (blob) {
+ return createImageBitmap(blob, {
+ premultiplyAlpha: 'none',
+ colorSpaceConversion: 'none'
+ });
+ }).then(function (bitmap) {
+ // not sure if this works. We don't want
+ // to catch the user's error. So, call
+ // the callback in a timeout so we're
+ // not in this scope inside the promise.
+ bm = bitmap;
+ setTimeout(cb);
+ })["catch"](function (e) {
+ err = e;
+ setTimeout(cb);
+ });
+ img = null;
+ }
+
+ return img;
+}
+/**
+ * check if object is a TexImageSource
+ *
+ * @param {Object} obj Object to test
+ * @return {boolean} true if object is a TexImageSource
+ * @private
+ */
+
+
+function isTexImageSource(obj) {
+ return typeof ImageBitmap !== 'undefined' && obj instanceof ImageBitmap || typeof ImageData !== 'undefined' && obj instanceof ImageData || typeof HTMLElement !== 'undefined' && obj instanceof HTMLElement;
+}
+/**
+ * if obj is an TexImageSource then just
+ * uses it otherwise if obj is a string
+ * then load it first.
+ *
+ * @param {string|TexImageSource} obj
+ * @param {string} crossOrigin
+ * @param {function(err, img)} [callback] a callback that's passed an error and the image. The error will be non-null
+ * if there was an error
+ * @private
+ */
+
+
+function loadAndUseImage(obj, crossOrigin, callback) {
+ if (isTexImageSource(obj)) {
+ setTimeout(function () {
+ callback(null, obj);
+ });
+ return obj;
+ }
+
+ return loadImage(obj, crossOrigin, callback);
+}
+/**
+ * Sets a texture to a 1x1 pixel color. If `options.color === false` is nothing happens. If it's not set
+ * the default texture color is used which can be set by calling `setDefaultTextureColor`.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @memberOf module:twgl/textures
+ */
+
+
+function setTextureTo1PixelColor(gl, tex, options) {
+ options = options || defaults.textureOptions;
+ var target = options.target || TEXTURE_2D;
+ gl.bindTexture(target, tex);
+
+ if (options.color === false) {
+ return;
+ } // Assume it's a URL
+ // Put 1x1 pixels in texture. That makes it renderable immediately regardless of filtering.
+
+
+ var color = make1Pixel(options.color);
+
+ if (target === TEXTURE_CUBE_MAP) {
+ for (var ii = 0; ii < 6; ++ii) {
+ gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, 0, RGBA, 1, 1, 0, RGBA, UNSIGNED_BYTE, color);
+ }
+ } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
+ gl.texImage3D(target, 0, RGBA, 1, 1, 1, 0, RGBA, UNSIGNED_BYTE, color);
+ } else {
+ gl.texImage2D(target, 0, RGBA, 1, 1, 0, RGBA, UNSIGNED_BYTE, color);
+ }
+}
+/**
+ * The src image(s) used to create a texture.
+ *
+ * When you call {@link module:twgl.createTexture} or {@link module:twgl.createTextures}
+ * you can pass in urls for images to load into the textures. If it's a single url
+ * then this will be a single HTMLImageElement. If it's an array of urls used for a cubemap
+ * this will be a corresponding array of images for the cubemap.
+ *
+ * @typedef {HTMLImageElement|HTMLImageElement[]} TextureSrc
+ * @memberOf module:twgl
+ */
+
+/**
+ * A callback for when an image finished downloading and been uploaded into a texture
+ * @callback TextureReadyCallback
+ * @param {*} err If truthy there was an error.
+ * @param {WebGLTexture} texture the texture.
+ * @param {module:twgl.TextureSrc} source image(s) used to as the src for the texture
+ * @memberOf module:twgl
+ */
+
+/**
+ * A callback for when all images have finished downloading and been uploaded into their respective textures
+ * @callback TexturesReadyCallback
+ * @param {*} err If truthy there was an error.
+ * @param {Object.} textures the created textures by name. Same as returned by {@link module:twgl.createTextures}.
+ * @param {Object.} sources the image(s) used for the texture by name.
+ * @memberOf module:twgl
+ */
+
+/**
+ * A callback for when an image finished downloading and been uploaded into a texture
+ * @callback CubemapReadyCallback
+ * @param {*} err If truthy there was an error.
+ * @param {WebGLTexture} tex the texture.
+ * @param {HTMLImageElement[]} imgs the images for each face.
+ * @memberOf module:twgl
+ */
+
+/**
+ * A callback for when an image finished downloading and been uploaded into a texture
+ * @callback ThreeDReadyCallback
+ * @param {*} err If truthy there was an error.
+ * @param {WebGLTexture} tex the texture.
+ * @param {HTMLImageElement[]} imgs the images for each slice.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Loads a texture from an image from a Url as specified in `options.src`
+ * If `options.color !== false` will set the texture to a 1x1 pixel color so that the texture is
+ * immediately useable. It will be updated with the contents of the image once the image has finished
+ * downloading. Filtering options will be set as appropriate for image unless `options.auto === false`.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
+ * @param {module:twgl.TextureReadyCallback} [callback] A function to be called when the image has finished loading. err will
+ * be non null if there was an error.
+ * @return {HTMLImageElement} the image being downloaded.
+ * @memberOf module:twgl/textures
+ */
+
+
+function loadTextureFromUrl(gl, tex, options, callback) {
+ callback = callback || noop;
+ options = options || defaults.textureOptions;
+ setTextureTo1PixelColor(gl, tex, options); // Because it's async we need to copy the options.
+
+ options = Object.assign({}, options);
+ var img = loadAndUseImage(options.src, options.crossOrigin, function (err, img) {
+ if (err) {
+ callback(err, tex, img);
+ } else {
+ setTextureFromElement(gl, tex, img, options);
+ callback(null, tex, img);
+ }
+ });
+ return img;
+}
+/**
+ * Loads a cubemap from 6 urls or TexImageSources as specified in `options.src`. Will set the cubemap to a 1x1 pixel color
+ * so that it is usable immediately unless `option.color === false`.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @param {module:twgl.CubemapReadyCallback} [callback] A function to be called when all the images have finished loading. err will
+ * be non null if there was an error.
+ * @memberOf module:twgl/textures
+ */
+
+
+function loadCubemapFromUrls(gl, tex, options, callback) {
+ callback = callback || noop;
+ var urls = options.src;
+
+ if (urls.length !== 6) {
+ throw "there must be 6 urls for a cubemap";
+ }
+
+ var level = options.level || 0;
+ var internalFormat = options.internalFormat || options.format || RGBA;
+ var formatType = getFormatAndTypeForInternalFormat(internalFormat);
+ var format = options.format || formatType.format;
+ var type = options.type || UNSIGNED_BYTE;
+ var target = options.target || TEXTURE_2D;
+
+ if (target !== TEXTURE_CUBE_MAP) {
+ throw "target must be TEXTURE_CUBE_MAP";
+ }
+
+ setTextureTo1PixelColor(gl, tex, options); // Because it's async we need to copy the options.
+
+ options = Object.assign({}, options);
+ var numToLoad = 6;
+ var errors = [];
+ var faces = getCubeFaceOrder(gl, options);
+ var imgs; // eslint-disable-line
+
+ function uploadImg(faceTarget) {
+ return function (err, img) {
+ --numToLoad;
+
+ if (err) {
+ errors.push(err);
+ } else {
+ if (img.width !== img.height) {
+ errors.push("cubemap face img is not a square: " + img.src);
+ } else {
+ savePackState(gl, options);
+ gl.bindTexture(target, tex); // So assuming this is the first image we now have one face that's img sized
+ // and 5 faces that are 1x1 pixel so size the other faces
+
+ if (numToLoad === 5) {
+ // use the default order
+ getCubeFaceOrder(gl).forEach(function (otherTarget) {
+ // Should we re-use the same face or a color?
+ gl.texImage2D(otherTarget, level, internalFormat, format, type, img);
+ });
+ } else {
+ gl.texImage2D(faceTarget, level, internalFormat, format, type, img);
+ }
+
+ restorePackState(gl, options);
+
+ if (shouldAutomaticallySetTextureFilteringForSize(options)) {
+ gl.generateMipmap(target);
+ }
+ }
+ }
+
+ if (numToLoad === 0) {
+ callback(errors.length ? errors : undefined, tex, imgs);
+ }
+ };
+ }
+
+ imgs = urls.map(function (url, ndx) {
+ return loadAndUseImage(url, options.crossOrigin, uploadImg(faces[ndx]));
+ });
+}
+/**
+ * Loads a 2d array or 3d texture from urls OR TexImageSources as specified in `options.src`.
+ * Will set the texture to a 1x1 pixel color
+ * so that it is usable immediately unless `option.color === false`.
+ *
+ * If the width and height is not specified the width and height of the first
+ * image loaded will be used. Note that since images are loaded async
+ * which image downloads first is unknown.
+ *
+ * If an image is not the same size as the width and height it will be scaled
+ * to that width and height.
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @param {module:twgl.ThreeDReadyCallback} [callback] A function to be called when all the images have finished loading. err will
+ * be non null if there was an error.
+ * @memberOf module:twgl/textures
+ */
+
+
+function loadSlicesFromUrls(gl, tex, options, callback) {
+ callback = callback || noop;
+ var urls = options.src;
+ var internalFormat = options.internalFormat || options.format || RGBA;
+ var formatType = getFormatAndTypeForInternalFormat(internalFormat);
+ var format = options.format || formatType.format;
+ var type = options.type || UNSIGNED_BYTE;
+ var target = options.target || TEXTURE_2D_ARRAY;
+
+ if (target !== TEXTURE_3D && target !== TEXTURE_2D_ARRAY) {
+ throw "target must be TEXTURE_3D or TEXTURE_2D_ARRAY";
+ }
+
+ setTextureTo1PixelColor(gl, tex, options); // Because it's async we need to copy the options.
+
+ options = Object.assign({}, options);
+ var numToLoad = urls.length;
+ var errors = [];
+ var imgs; // eslint-disable-line
+
+ var level = options.level || 0;
+ var width = options.width;
+ var height = options.height;
+ var depth = urls.length;
+ var firstImage = true;
+
+ function uploadImg(slice) {
+ return function (err, img) {
+ --numToLoad;
+
+ if (err) {
+ errors.push(err);
+ } else {
+ savePackState(gl, options);
+ gl.bindTexture(target, tex);
+
+ if (firstImage) {
+ firstImage = false;
+ width = options.width || img.width;
+ height = options.height || img.height;
+ gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, null); // put it in every slice otherwise some slices will be 0,0,0,0
+
+ for (var s = 0; s < depth; ++s) {
+ gl.texSubImage3D(target, level, 0, 0, s, width, height, 1, format, type, img);
+ }
+ } else {
+ var src = img;
+ var ctx;
+
+ if (img.width !== width || img.height !== height) {
+ // Size the image to fix
+ ctx = getShared2DContext();
+ src = ctx.canvas;
+ ctx.canvas.width = width;
+ ctx.canvas.height = height;
+ ctx.drawImage(img, 0, 0, width, height);
+ }
+
+ gl.texSubImage3D(target, level, 0, 0, slice, width, height, 1, format, type, src); // free the canvas memory
+
+ if (ctx && src === ctx.canvas) {
+ ctx.canvas.width = 0;
+ ctx.canvas.height = 0;
+ }
+ }
+
+ restorePackState(gl, options);
+
+ if (shouldAutomaticallySetTextureFilteringForSize(options)) {
+ gl.generateMipmap(target);
+ }
+ }
+
+ if (numToLoad === 0) {
+ callback(errors.length ? errors : undefined, tex, imgs);
+ }
+ };
+ }
+
+ imgs = urls.map(function (url, ndx) {
+ return loadAndUseImage(url, options.crossOrigin, uploadImg(ndx));
+ });
+}
+/**
+ * Sets a texture from an array or typed array. If the width or height is not provided will attempt to
+ * guess the size. See {@link module:twgl.TextureOptions}.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {(number[]|ArrayBufferView)} src An array or typed arry with texture data.
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @memberOf module:twgl/textures
+ */
+
+
+function setTextureFromArray(gl, tex, src, options) {
+ options = options || defaults.textureOptions;
+ var target = options.target || TEXTURE_2D;
+ gl.bindTexture(target, tex);
+ var width = options.width;
+ var height = options.height;
+ var depth = options.depth;
+ var level = options.level || 0;
+ var internalFormat = options.internalFormat || options.format || RGBA;
+ var formatType = getFormatAndTypeForInternalFormat(internalFormat);
+ var format = options.format || formatType.format;
+ var type = options.type || getTextureTypeForArrayType(gl, src, formatType.type);
+
+ if (!isArrayBuffer(src)) {
+ var Type = typedArrays.getTypedArrayTypeForGLType(type);
+ src = new Type(src);
+ } else if (src instanceof Uint8ClampedArray) {
+ src = new Uint8Array(src.buffer);
+ }
+
+ var bytesPerElement = getBytesPerElementForInternalFormat(internalFormat, type);
+ var numElements = src.byteLength / bytesPerElement; // TODO: check UNPACK_ALIGNMENT?
+
+ if (numElements % 1) {
+ throw "length wrong size for format: " + utils.glEnumToString(gl, format);
+ }
+
+ var dimensions;
+
+ if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
+ if (!width && !height && !depth) {
+ var size = Math.cbrt(numElements);
+
+ if (size % 1 !== 0) {
+ throw "can't guess cube size of array of numElements: " + numElements;
+ }
+
+ width = size;
+ height = size;
+ depth = size;
+ } else if (width && (!height || !depth)) {
+ dimensions = guessDimensions(gl, target, height, depth, numElements / width);
+ height = dimensions.width;
+ depth = dimensions.height;
+ } else if (height && (!width || !depth)) {
+ dimensions = guessDimensions(gl, target, width, depth, numElements / height);
+ width = dimensions.width;
+ depth = dimensions.height;
+ } else {
+ dimensions = guessDimensions(gl, target, width, height, numElements / depth);
+ width = dimensions.width;
+ height = dimensions.height;
+ }
+ } else {
+ dimensions = guessDimensions(gl, target, width, height, numElements);
+ width = dimensions.width;
+ height = dimensions.height;
+ }
+
+ saveSkipState(gl);
+ gl.pixelStorei(UNPACK_ALIGNMENT, options.unpackAlignment || 1);
+ savePackState(gl, options);
+
+ if (target === TEXTURE_CUBE_MAP) {
+ var elementsPerElement = bytesPerElement / src.BYTES_PER_ELEMENT;
+ var faceSize = numElements / 6 * elementsPerElement;
+ getCubeFacesWithNdx(gl, options).forEach(function (f) {
+ var offset = faceSize * f.ndx;
+ var data = src.subarray(offset, offset + faceSize);
+ gl.texImage2D(f.face, level, internalFormat, width, height, 0, format, type, data);
+ });
+ } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
+ gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, src);
+ } else {
+ gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, src);
+ }
+
+ restorePackState(gl, options);
+ restoreSkipState(gl);
+ return {
+ width: width,
+ height: height,
+ depth: depth,
+ type: type
+ };
+}
+/**
+ * Sets a texture with no contents of a certain size. In other words calls `gl.texImage2D` with `null`.
+ * You must set `options.width` and `options.height`.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @memberOf module:twgl/textures
+ */
+
+
+function setEmptyTexture(gl, tex, options) {
+ var target = options.target || TEXTURE_2D;
+ gl.bindTexture(target, tex);
+ var level = options.level || 0;
+ var internalFormat = options.internalFormat || options.format || RGBA;
+ var formatType = getFormatAndTypeForInternalFormat(internalFormat);
+ var format = options.format || formatType.format;
+ var type = options.type || formatType.type;
+ savePackState(gl, options);
+
+ if (target === TEXTURE_CUBE_MAP) {
+ for (var ii = 0; ii < 6; ++ii) {
+ gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, level, internalFormat, options.width, options.height, 0, format, type, null);
+ }
+ } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
+ gl.texImage3D(target, level, internalFormat, options.width, options.height, options.depth, 0, format, type, null);
+ } else {
+ gl.texImage2D(target, level, internalFormat, options.width, options.height, 0, format, type, null);
+ }
+
+ restorePackState(gl, options);
+}
+/**
+ * Creates a texture based on the options passed in.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
+ * @param {module:twgl.TextureReadyCallback} [callback] A callback called when an image has been downloaded and uploaded to the texture.
+ * @return {WebGLTexture} the created texture.
+ * @memberOf module:twgl/textures
+ */
+
+
+function createTexture(gl, options, callback) {
+ callback = callback || noop;
+ options = options || defaults.textureOptions;
+ var tex = gl.createTexture();
+ var target = options.target || TEXTURE_2D;
+ var width = options.width || 1;
+ var height = options.height || 1;
+ var internalFormat = options.internalFormat || RGBA;
+ gl.bindTexture(target, tex);
+
+ if (target === TEXTURE_CUBE_MAP) {
+ // this should have been the default for cubemaps :(
+ gl.texParameteri(target, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
+ gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
+ }
+
+ var src = options.src;
+
+ if (src) {
+ if (typeof src === "function") {
+ src = src(gl, options);
+ }
+
+ if (typeof src === "string") {
+ loadTextureFromUrl(gl, tex, options, callback);
+ } else if (isArrayBuffer(src) || Array.isArray(src) && (typeof src[0] === 'number' || Array.isArray(src[0]) || isArrayBuffer(src[0]))) {
+ var dimensions = setTextureFromArray(gl, tex, src, options);
+ width = dimensions.width;
+ height = dimensions.height;
+ } else if (Array.isArray(src) && (typeof src[0] === 'string' || isTexImageSource(src[0]))) {
+ if (target === TEXTURE_CUBE_MAP) {
+ loadCubemapFromUrls(gl, tex, options, callback);
+ } else {
+ loadSlicesFromUrls(gl, tex, options, callback);
+ }
+ } else if (isTexImageSource(src)) {
+ setTextureFromElement(gl, tex, src, options);
+ width = src.width;
+ height = src.height;
+ } else {
+ throw "unsupported src type";
+ }
+ } else {
+ setEmptyTexture(gl, tex, options);
+ }
+
+ if (shouldAutomaticallySetTextureFilteringForSize(options)) {
+ setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
+ }
+
+ setTextureParameters(gl, tex, options);
+ return tex;
+}
+/**
+ * Resizes a texture based on the options passed in.
+ *
+ * Note: This is not a generic resize anything function.
+ * It's mostly used by {@link module:twgl.resizeFramebufferInfo}
+ * It will use `options.src` if it exists to try to determine a `type`
+ * otherwise it will assume `gl.UNSIGNED_BYTE`. No data is provided
+ * for the texture. Texture parameters will be set accordingly
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the texture to resize
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @param {number} [width] the new width. If not passed in will use `options.width`
+ * @param {number} [height] the new height. If not passed in will use `options.height`
+ * @param {number} [depth] the new depth. If not passed in will use `options.depth`
+ * @memberOf module:twgl/textures
+ */
+
+
+function resizeTexture(gl, tex, options, width, height, depth) {
+ width = width || options.width;
+ height = height || options.height;
+ depth = depth || options.depth;
+ var target = options.target || TEXTURE_2D;
+ gl.bindTexture(target, tex);
+ var level = options.level || 0;
+ var internalFormat = options.internalFormat || options.format || RGBA;
+ var formatType = getFormatAndTypeForInternalFormat(internalFormat);
+ var format = options.format || formatType.format;
+ var type;
+ var src = options.src;
+
+ if (!src) {
+ type = options.type || formatType.type;
+ } else if (isArrayBuffer(src) || Array.isArray(src) && typeof src[0] === 'number') {
+ type = options.type || getTextureTypeForArrayType(gl, src, formatType.type);
+ } else {
+ type = options.type || formatType.type;
+ }
+
+ if (target === TEXTURE_CUBE_MAP) {
+ for (var ii = 0; ii < 6; ++ii) {
+ gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, level, internalFormat, width, height, 0, format, type, null);
+ }
+ } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
+ gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, null);
+ } else {
+ gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, null);
+ }
+}
+/**
+ * Check if a src is an async request.
+ * if src is a string we're going to download an image
+ * if src is an array of strings we're going to download cubemap images
+ * @param {*} src The src from a TextureOptions
+ * @returns {bool} true if src is async.
+ * @private
+ */
+
+
+function isAsyncSrc(src) {
+ return typeof src === 'string' || Array.isArray(src) && typeof src[0] === 'string';
+}
+/**
+ * Creates a bunch of textures based on the passed in options.
+ *
+ * Example:
+ *
+ * const textures = twgl.createTextures(gl, {
+ * // a power of 2 image
+ * hftIcon: { src: "images/hft-icon-16.png", mag: gl.NEAREST },
+ * // a non-power of 2 image
+ * clover: { src: "images/clover.jpg" },
+ * // From a canvas
+ * fromCanvas: { src: ctx.canvas },
+ * // A cubemap from 6 images
+ * yokohama: {
+ * target: gl.TEXTURE_CUBE_MAP,
+ * src: [
+ * 'images/yokohama/posx.jpg',
+ * 'images/yokohama/negx.jpg',
+ * 'images/yokohama/posy.jpg',
+ * 'images/yokohama/negy.jpg',
+ * 'images/yokohama/posz.jpg',
+ * 'images/yokohama/negz.jpg',
+ * ],
+ * },
+ * // A cubemap from 1 image (can be 1x6, 2x3, 3x2, 6x1)
+ * goldengate: {
+ * target: gl.TEXTURE_CUBE_MAP,
+ * src: 'images/goldengate.jpg',
+ * },
+ * // A 2x2 pixel texture from a JavaScript array
+ * checker: {
+ * mag: gl.NEAREST,
+ * min: gl.LINEAR,
+ * src: [
+ * 255,255,255,255,
+ * 192,192,192,255,
+ * 192,192,192,255,
+ * 255,255,255,255,
+ * ],
+ * },
+ * // a 1x2 pixel texture from a typed array.
+ * stripe: {
+ * mag: gl.NEAREST,
+ * min: gl.LINEAR,
+ * format: gl.LUMINANCE,
+ * src: new Uint8Array([
+ * 255,
+ * 128,
+ * 255,
+ * 128,
+ * 255,
+ * 128,
+ * 255,
+ * 128,
+ * ]),
+ * width: 1,
+ * },
+ * });
+ *
+ * Now
+ *
+ * * `textures.hftIcon` will be a 2d texture
+ * * `textures.clover` will be a 2d texture
+ * * `textures.fromCanvas` will be a 2d texture
+ * * `textures.yohohama` will be a cubemap texture
+ * * `textures.goldengate` will be a cubemap texture
+ * * `textures.checker` will be a 2d texture
+ * * `textures.stripe` will be a 2d texture
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {Object.} options A object of TextureOptions one per texture.
+ * @param {module:twgl.TexturesReadyCallback} [callback] A callback called when all textures have been downloaded.
+ * @return {Object.} the created textures by name
+ * @memberOf module:twgl/textures
+ */
+
+
+function createTextures(gl, textureOptions, callback) {
+ callback = callback || noop;
+ var numDownloading = 0;
+ var errors = [];
+ var textures = {};
+ var images = {};
+
+ function callCallbackIfReady() {
+ if (numDownloading === 0) {
+ setTimeout(function () {
+ callback(errors.length ? errors : undefined, textures, images);
+ }, 0);
+ }
+ }
+
+ Object.keys(textureOptions).forEach(function (name) {
+ var options = textureOptions[name];
+ var onLoadFn;
+
+ if (isAsyncSrc(options.src)) {
+ onLoadFn = function onLoadFn(err, tex, img) {
+ images[name] = img;
+ --numDownloading;
+
+ if (err) {
+ errors.push(err);
+ }
+
+ callCallbackIfReady();
+ };
+
+ ++numDownloading;
+ }
+
+ textures[name] = createTexture(gl, options, onLoadFn);
+ }); // queue the callback if there are no images to download.
+ // We do this because if your code is structured to wait for
+ // images to download but then you comment out all the async
+ // images your code would break.
+
+ callCallbackIfReady();
+ return textures;
+}
+
+/***/ }),
+
+/***/ "./src/twgl-full.js":
+/*!**************************!*\
+ !*** ./src/twgl-full.js ***!
+ \**************************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+var _exportNames = {
+ m4: true,
+ v3: true,
+ primitives: true
+};
+exports.primitives = exports.v3 = exports.m4 = void 0;
+
+var m4 = _interopRequireWildcard(__webpack_require__(/*! ./m4.js */ "./src/m4.js"));
+
+exports.m4 = m4;
+
+var v3 = _interopRequireWildcard(__webpack_require__(/*! ./v3.js */ "./src/v3.js"));
+
+exports.v3 = v3;
+
+var primitives = _interopRequireWildcard(__webpack_require__(/*! ./primitives.js */ "./src/primitives.js"));
+
+exports.primitives = primitives;
+
+var _twgl = __webpack_require__(/*! ./twgl.js */ "./src/twgl.js");
+
+Object.keys(_twgl).forEach(function (key) {
+ if (key === "default" || key === "__esModule") return;
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
+ exports[key] = _twgl[key];
+});
+
+function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+
+/***/ }),
+
+/***/ "./src/twgl.js":
+/*!*********************!*\
+ !*** ./src/twgl.js ***!
+ \*********************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+var _exportNames = {
+ addExtensionsToContext: true,
+ getContext: true,
+ getWebGLContext: true,
+ resizeCanvasToDisplaySize: true,
+ setDefaults: true,
+ attributes: true,
+ textures: true,
+ utils: true,
+ draw: true,
+ framebuffers: true,
+ programs: true,
+ typedarrays: true,
+ vertexArrays: true
+};
+exports.addExtensionsToContext = addExtensionsToContext;
+exports.getContext = getContext;
+exports.getWebGLContext = getWebGLContext;
+exports.resizeCanvasToDisplaySize = resizeCanvasToDisplaySize;
+exports.setDefaults = setDefaults;
+exports.vertexArrays = exports.typedarrays = exports.programs = exports.framebuffers = exports.draw = exports.utils = exports.textures = exports.attributes = void 0;
+
+var attributes = _interopRequireWildcard(__webpack_require__(/*! ./attributes.js */ "./src/attributes.js"));
+
+exports.attributes = attributes;
+Object.keys(attributes).forEach(function (key) {
+ if (key === "default" || key === "__esModule") return;
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
+ exports[key] = attributes[key];
+});
+
+var textures = _interopRequireWildcard(__webpack_require__(/*! ./textures.js */ "./src/textures.js"));
+
+exports.textures = textures;
+Object.keys(textures).forEach(function (key) {
+ if (key === "default" || key === "__esModule") return;
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
+ exports[key] = textures[key];
+});
+
+var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
+
+var utils = _interopRequireWildcard(__webpack_require__(/*! ./utils.js */ "./src/utils.js"));
+
+exports.utils = utils;
+Object.keys(utils).forEach(function (key) {
+ if (key === "default" || key === "__esModule") return;
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
+ exports[key] = utils[key];
+});
+
+var draw = _interopRequireWildcard(__webpack_require__(/*! ./draw.js */ "./src/draw.js"));
+
+exports.draw = draw;
+Object.keys(draw).forEach(function (key) {
+ if (key === "default" || key === "__esModule") return;
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
+ exports[key] = draw[key];
+});
+
+var framebuffers = _interopRequireWildcard(__webpack_require__(/*! ./framebuffers.js */ "./src/framebuffers.js"));
+
+exports.framebuffers = framebuffers;
+Object.keys(framebuffers).forEach(function (key) {
+ if (key === "default" || key === "__esModule") return;
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
+ exports[key] = framebuffers[key];
+});
+
+var programs = _interopRequireWildcard(__webpack_require__(/*! ./programs.js */ "./src/programs.js"));
+
+exports.programs = programs;
+Object.keys(programs).forEach(function (key) {
+ if (key === "default" || key === "__esModule") return;
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
+ exports[key] = programs[key];
+});
+
+var typedarrays = _interopRequireWildcard(__webpack_require__(/*! ./typedarrays.js */ "./src/typedarrays.js"));
+
+exports.typedarrays = typedarrays;
+Object.keys(typedarrays).forEach(function (key) {
+ if (key === "default" || key === "__esModule") return;
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
+ exports[key] = typedarrays[key];
+});
+
+var vertexArrays = _interopRequireWildcard(__webpack_require__(/*! ./vertex-arrays.js */ "./src/vertex-arrays.js"));
+
+exports.vertexArrays = vertexArrays;
+Object.keys(vertexArrays).forEach(function (key) {
+ if (key === "default" || key === "__esModule") return;
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
+ exports[key] = vertexArrays[key];
+});
+
+function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * The main TWGL module.
+ *
+ * For most use cases you shouldn't need anything outside this module.
+ * Exceptions between the stuff added to twgl-full (v3, m4, primitives)
+ *
+ * @module twgl
+ * @borrows module:twgl/attributes.setAttribInfoBufferFromArray as setAttribInfoBufferFromArray
+ * @borrows module:twgl/attributes.createBufferInfoFromArrays as createBufferInfoFromArrays
+ * @borrows module:twgl/attributes.createVertexArrayInfo as createVertexArrayInfo
+ * @borrows module:twgl/draw.drawBufferInfo as drawBufferInfo
+ * @borrows module:twgl/draw.drawObjectList as drawObjectList
+ * @borrows module:twgl/framebuffers.createFramebufferInfo as createFramebufferInfo
+ * @borrows module:twgl/framebuffers.resizeFramebufferInfo as resizeFramebufferInfo
+ * @borrows module:twgl/framebuffers.bindFramebufferInfo as bindFramebufferInfo
+ * @borrows module:twgl/programs.createProgramInfo as createProgramInfo
+ * @borrows module:twgl/programs.createUniformBlockInfo as createUniformBlockInfo
+ * @borrows module:twgl/programs.bindUniformBlock as bindUniformBlock
+ * @borrows module:twgl/programs.setUniformBlock as setUniformBlock
+ * @borrows module:twgl/programs.setBlockUniforms as setBlockUniforms
+ * @borrows module:twgl/programs.setUniforms as setUniforms
+ * @borrows module:twgl/programs.setBuffersAndAttributes as setBuffersAndAttributes
+ * @borrows module:twgl/textures.setTextureFromArray as setTextureFromArray
+ * @borrows module:twgl/textures.createTexture as createTexture
+ * @borrows module:twgl/textures.resizeTexture as resizeTexture
+ * @borrows module:twgl/textures.createTextures as createTextures
+ */
+// make sure we don't see a global gl
+var gl = undefined;
+/* eslint-disable-line */
+
+/* lgtm [js/unused-local-variable] */
+
+var defaults = {
+ addExtensionsToContext: true
+};
+/**
+ * Various default settings for twgl.
+ *
+ * Note: You can call this any number of times. Example:
+ *
+ * twgl.setDefaults({ textureColor: [1, 0, 0, 1] });
+ * twgl.setDefaults({ attribPrefix: 'a_' });
+ *
+ * is equivalent to
+ *
+ * twgl.setDefaults({
+ * textureColor: [1, 0, 0, 1],
+ * attribPrefix: 'a_',
+ * });
+ *
+ * @typedef {Object} Defaults
+ * @property {string} [attribPrefix] The prefix to stick on attributes
+ *
+ * When writing shaders I prefer to name attributes with `a_`, uniforms with `u_` and varyings with `v_`
+ * as it makes it clear where they came from. But, when building geometry I prefer using un-prefixed names.
+ *
+ * In other words I'll create arrays of geometry like this
+ *
+ * const arrays = {
+ * position: ...
+ * normal: ...
+ * texcoord: ...
+ * };
+ *
+ * But need those mapped to attributes and my attributes start with `a_`.
+ *
+ * Default: `""`
+ *
+ * @property {number[]} [textureColor] Array of 4 values in the range 0 to 1
+ *
+ * The default texture color is used when loading textures from
+ * urls. Because the URL will be loaded async we'd like to be
+ * able to use the texture immediately. By putting a 1x1 pixel
+ * color in the texture we can start using the texture before
+ * the URL has loaded.
+ *
+ * Default: `[0.5, 0.75, 1, 1]`
+ *
+ * @property {string} [crossOrigin]
+ *
+ * If not undefined sets the crossOrigin attribute on images
+ * that twgl creates when downloading images for textures.
+ *
+ * Also see {@link module:twgl.TextureOptions}.
+ *
+ * @property {bool} [addExtensionsToContext]
+ *
+ * If true, then, when twgl will try to add any supported WebGL extensions
+ * directly to the context under their normal GL names. For example
+ * if ANGLE_instances_arrays exists then twgl would enable it,
+ * add the functions `vertexAttribDivisor`, `drawArraysInstanced`,
+ * `drawElementsInstanced`, and the constant `VERTEX_ATTRIB_ARRAY_DIVISOR`
+ * to the `WebGLRenderingContext`.
+ *
+ * @memberOf module:twgl
+ */
+
+/**
+ * Sets various defaults for twgl.
+ *
+ * In the interest of terseness which is kind of the point
+ * of twgl I've integrated a few of the older functions here
+ *
+ * @param {module:twgl.Defaults} newDefaults The default settings.
+ * @memberOf module:twgl
+ */
+
+function setDefaults(newDefaults) {
+ helper.copyExistingProperties(newDefaults, defaults);
+ attributes.setAttributeDefaults_(newDefaults); // eslint-disable-line
+
+ textures.setTextureDefaults_(newDefaults); // eslint-disable-line
+}
+
+var prefixRE = /^(.*?)_/;
+
+function addExtensionToContext(gl, extensionName) {
+ utils.glEnumToString(gl, 0);
+ var ext = gl.getExtension(extensionName);
+
+ if (ext) {
+ var enums = {};
+ var fnSuffix = prefixRE.exec(extensionName)[1];
+ var enumSuffix = '_' + fnSuffix;
+
+ for (var key in ext) {
+ var value = ext[key];
+ var isFunc = typeof value === 'function';
+ var suffix = isFunc ? fnSuffix : enumSuffix;
+ var name = key; // examples of where this is not true are WEBGL_compressed_texture_s3tc
+ // and WEBGL_compressed_texture_pvrtc
+
+ if (key.endsWith(suffix)) {
+ name = key.substring(0, key.length - suffix.length);
+ }
+
+ if (gl[name] !== undefined) {
+ if (!isFunc && gl[name] !== value) {
+ helper.warn(name, gl[name], value, key);
+ }
+ } else {
+ if (isFunc) {
+ gl[name] = function (origFn) {
+ return function () {
+ return origFn.apply(ext, arguments);
+ };
+ }(value);
+ } else {
+ gl[name] = value;
+ enums[name] = value;
+ }
+ }
+ } // pass the modified enums to glEnumToString
+
+
+ enums.constructor = {
+ name: ext.constructor.name
+ };
+ utils.glEnumToString(enums, 0);
+ }
+
+ return ext;
+}
+/*
+ * If you're wondering why the code doesn't just iterate
+ * over all extensions using `gl.getExtensions` is that it's possible
+ * some future extension is incompatible with this code. Rather than
+ * have thing suddenly break it seems better to manually add to this
+ * list.
+ *
+ */
+
+
+var supportedExtensions = ['ANGLE_instanced_arrays', 'EXT_blend_minmax', 'EXT_color_buffer_float', 'EXT_color_buffer_half_float', 'EXT_disjoint_timer_query', 'EXT_disjoint_timer_query_webgl2', 'EXT_frag_depth', 'EXT_sRGB', 'EXT_shader_texture_lod', 'EXT_texture_filter_anisotropic', 'OES_element_index_uint', 'OES_standard_derivatives', 'OES_texture_float', 'OES_texture_float_linear', 'OES_texture_half_float', 'OES_texture_half_float_linear', 'OES_vertex_array_object', 'WEBGL_color_buffer_float', 'WEBGL_compressed_texture_atc', 'WEBGL_compressed_texture_etc1', 'WEBGL_compressed_texture_pvrtc', 'WEBGL_compressed_texture_s3tc', 'WEBGL_compressed_texture_s3tc_srgb', 'WEBGL_depth_texture', 'WEBGL_draw_buffers'];
+/**
+ * Attempts to enable all of the following extensions
+ * and add their functions and constants to the
+ * `WebGLRenderingContext` using their normal non-extension like names.
+ *
+ * ANGLE_instanced_arrays
+ * EXT_blend_minmax
+ * EXT_color_buffer_float
+ * EXT_color_buffer_half_float
+ * EXT_disjoint_timer_query
+ * EXT_disjoint_timer_query_webgl2
+ * EXT_frag_depth
+ * EXT_sRGB
+ * EXT_shader_texture_lod
+ * EXT_texture_filter_anisotropic
+ * OES_element_index_uint
+ * OES_standard_derivatives
+ * OES_texture_float
+ * OES_texture_float_linear
+ * OES_texture_half_float
+ * OES_texture_half_float_linear
+ * OES_vertex_array_object
+ * WEBGL_color_buffer_float
+ * WEBGL_compressed_texture_atc
+ * WEBGL_compressed_texture_etc1
+ * WEBGL_compressed_texture_pvrtc
+ * WEBGL_compressed_texture_s3tc
+ * WEBGL_compressed_texture_s3tc_srgb
+ * WEBGL_depth_texture
+ * WEBGL_draw_buffers
+ *
+ * For example if `ANGLE_instanced_arrays` exists then the functions
+ * `drawArraysInstanced`, `drawElementsInstanced`, `vertexAttribDivisor`
+ * and the constant `VERTEX_ATTRIB_ARRAY_DIVISOR` are added to the
+ * `WebGLRenderingContext`.
+ *
+ * Note that if you want to know if the extension exists you should
+ * probably call `gl.getExtension` for each extension. Alternatively
+ * you can check for the existence of the functions or constants that
+ * are expected to be added. For example
+ *
+ * if (gl.drawBuffers) {
+ * // Either WEBGL_draw_buffers was enabled OR you're running in WebGL2
+ * ....
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @memberOf module:twgl
+ */
+
+function addExtensionsToContext(gl) {
+ for (var ii = 0; ii < supportedExtensions.length; ++ii) {
+ addExtensionToContext(gl, supportedExtensions[ii]);
+ }
+}
+/**
+ * Creates a webgl context.
+ * @param {HTMLCanvasElement} canvas The canvas tag to get
+ * context from. If one is not passed in one will be
+ * created.
+ * @return {WebGLRenderingContext} The created context.
+ * @private
+ */
+
+
+function create3DContext(canvas, opt_attribs) {
+ var names = ["webgl", "experimental-webgl"];
+ var context = null;
+
+ for (var ii = 0; ii < names.length; ++ii) {
+ context = canvas.getContext(names[ii], opt_attribs);
+
+ if (context) {
+ if (defaults.addExtensionsToContext) {
+ addExtensionsToContext(context);
+ }
+
+ break;
+ }
+ }
+
+ return context;
+}
+/**
+ * Gets a WebGL1 context.
+ *
+ * Note: Will attempt to enable Vertex Array Objects
+ * and add WebGL2 entry points. (unless you first set defaults with
+ * `twgl.setDefaults({enableVertexArrayObjects: false})`;
+ *
+ * @param {HTMLCanvasElement} canvas a canvas element.
+ * @param {WebGLContextAttributes} [opt_attribs] optional webgl context creation attributes
+ * @return {WebGLRenderingContext} The created context.
+ * @memberOf module:twgl
+ */
+
+
+function getWebGLContext(canvas, opt_attribs) {
+ var gl = create3DContext(canvas, opt_attribs);
+ return gl;
+}
+/**
+ * Creates a webgl context.
+ *
+ * Will return a WebGL2 context if possible.
+ *
+ * You can check if it's WebGL2 with
+ *
+ * twgl.isWebGL2(gl);
+ *
+ * @param {HTMLCanvasElement} canvas The canvas tag to get
+ * context from. If one is not passed in one will be
+ * created.
+ * @return {WebGLRenderingContext} The created context.
+ */
+
+
+function createContext(canvas, opt_attribs) {
+ var names = ["webgl2", "webgl", "experimental-webgl"];
+ var context = null;
+
+ for (var ii = 0; ii < names.length; ++ii) {
+ context = canvas.getContext(names[ii], opt_attribs);
+
+ if (context) {
+ if (defaults.addExtensionsToContext) {
+ addExtensionsToContext(context);
+ }
+
+ break;
+ }
+ }
+
+ return context;
+}
+/**
+ * Gets a WebGL context. Will create a WebGL2 context if possible.
+ *
+ * You can check if it's WebGL2 with
+ *
+ * function isWebGL2(gl) {
+ * return gl.getParameter(gl.VERSION).indexOf("WebGL 2.0 ") == 0;
+ * }
+ *
+ * Note: For a WebGL1 context will attempt to enable Vertex Array Objects
+ * and add WebGL2 entry points. (unless you first set defaults with
+ * `twgl.setDefaults({enableVertexArrayObjects: false})`;
+ *
+ * @param {HTMLCanvasElement} canvas a canvas element.
+ * @param {WebGLContextAttributes} [opt_attribs] optional webgl context creation attributes
+ * @return {WebGLRenderingContext} The created context.
+ * @memberOf module:twgl
+ */
+
+
+function getContext(canvas, opt_attribs) {
+ var gl = createContext(canvas, opt_attribs);
+ return gl;
+}
+/**
+ * Resize a canvas to match the size it's displayed.
+ * @param {HTMLCanvasElement} canvas The canvas to resize.
+ * @param {number} [multiplier] So you can pass in `window.devicePixelRatio` or other scale value if you want to.
+ * @return {boolean} true if the canvas was resized.
+ * @memberOf module:twgl
+ */
+
+
+function resizeCanvasToDisplaySize(canvas, multiplier) {
+ multiplier = multiplier || 1;
+ multiplier = Math.max(0, multiplier);
+ var width = canvas.clientWidth * multiplier | 0;
+ var height = canvas.clientHeight * multiplier | 0;
+
+ if (canvas.width !== width || canvas.height !== height) {
+ canvas.width = width;
+ canvas.height = height;
+ return true;
+ }
+
+ return false;
+}
+
+/***/ }),
+
+/***/ "./src/typedarrays.js":
+/*!****************************!*\
+ !*** ./src/typedarrays.js ***!
+ \****************************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.getGLTypeForTypedArray = getGLTypeForTypedArray;
+exports.getGLTypeForTypedArrayType = getGLTypeForTypedArrayType;
+exports.getTypedArrayTypeForGLType = getTypedArrayTypeForGLType;
+exports.isArrayBuffer = void 0;
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * Low level shader typed array related functions
+ *
+ * You should generally not need to use these functions. They are provided
+ * for those cases where you're doing something out of the ordinary
+ * and you need lower level access.
+ *
+ * For backward compatibility they are available at both `twgl.typedArray` and `twgl`
+ * itself
+ *
+ * See {@link module:twgl} for core functions
+ *
+ * @module twgl/typedArray
+ */
+// make sure we don't see a global gl
+var gl = undefined;
+/* eslint-disable-line */
+
+/* lgtm [js/unused-local-variable] */
+
+/* DataType */
+
+var BYTE = 0x1400;
+var UNSIGNED_BYTE = 0x1401;
+var SHORT = 0x1402;
+var UNSIGNED_SHORT = 0x1403;
+var INT = 0x1404;
+var UNSIGNED_INT = 0x1405;
+var FLOAT = 0x1406;
+var UNSIGNED_SHORT_4_4_4_4 = 0x8033;
+var UNSIGNED_SHORT_5_5_5_1 = 0x8034;
+var UNSIGNED_SHORT_5_6_5 = 0x8363;
+var HALF_FLOAT = 0x140B;
+var UNSIGNED_INT_2_10_10_10_REV = 0x8368;
+var UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B;
+var UNSIGNED_INT_5_9_9_9_REV = 0x8C3E;
+var FLOAT_32_UNSIGNED_INT_24_8_REV = 0x8DAD;
+var UNSIGNED_INT_24_8 = 0x84FA;
+var glTypeToTypedArray = {};
+{
+ var tt = glTypeToTypedArray;
+ tt[BYTE] = Int8Array;
+ tt[UNSIGNED_BYTE] = Uint8Array;
+ tt[SHORT] = Int16Array;
+ tt[UNSIGNED_SHORT] = Uint16Array;
+ tt[INT] = Int32Array;
+ tt[UNSIGNED_INT] = Uint32Array;
+ tt[FLOAT] = Float32Array;
+ tt[UNSIGNED_SHORT_4_4_4_4] = Uint16Array;
+ tt[UNSIGNED_SHORT_5_5_5_1] = Uint16Array;
+ tt[UNSIGNED_SHORT_5_6_5] = Uint16Array;
+ tt[HALF_FLOAT] = Uint16Array;
+ tt[UNSIGNED_INT_2_10_10_10_REV] = Uint32Array;
+ tt[UNSIGNED_INT_10F_11F_11F_REV] = Uint32Array;
+ tt[UNSIGNED_INT_5_9_9_9_REV] = Uint32Array;
+ tt[FLOAT_32_UNSIGNED_INT_24_8_REV] = Uint32Array;
+ tt[UNSIGNED_INT_24_8] = Uint32Array;
+}
+/**
+ * Get the GL type for a typedArray
+ * @param {ArrayBufferView} typedArray a typedArray
+ * @return {number} the GL type for array. For example pass in an `Int8Array` and `gl.BYTE` will
+ * be returned. Pass in a `Uint32Array` and `gl.UNSIGNED_INT` will be returned
+ * @memberOf module:twgl/typedArray
+ */
+
+function getGLTypeForTypedArray(typedArray) {
+ if (typedArray instanceof Int8Array) {
+ return BYTE;
+ } // eslint-disable-line
+
+
+ if (typedArray instanceof Uint8Array) {
+ return UNSIGNED_BYTE;
+ } // eslint-disable-line
+
+
+ if (typedArray instanceof Uint8ClampedArray) {
+ return UNSIGNED_BYTE;
+ } // eslint-disable-line
+
+
+ if (typedArray instanceof Int16Array) {
+ return SHORT;
+ } // eslint-disable-line
+
+
+ if (typedArray instanceof Uint16Array) {
+ return UNSIGNED_SHORT;
+ } // eslint-disable-line
+
+
+ if (typedArray instanceof Int32Array) {
+ return INT;
+ } // eslint-disable-line
+
+
+ if (typedArray instanceof Uint32Array) {
+ return UNSIGNED_INT;
+ } // eslint-disable-line
+
+
+ if (typedArray instanceof Float32Array) {
+ return FLOAT;
+ } // eslint-disable-line
+
+
+ throw new Error('unsupported typed array type');
+}
+/**
+ * Get the GL type for a typedArray type
+ * @param {ArrayBufferView} typedArrayType a typedArray constructor
+ * @return {number} the GL type for type. For example pass in `Int8Array` and `gl.BYTE` will
+ * be returned. Pass in `Uint32Array` and `gl.UNSIGNED_INT` will be returned
+ * @memberOf module:twgl/typedArray
+ */
+
+
+function getGLTypeForTypedArrayType(typedArrayType) {
+ if (typedArrayType === Int8Array) {
+ return BYTE;
+ } // eslint-disable-line
+
+
+ if (typedArrayType === Uint8Array) {
+ return UNSIGNED_BYTE;
+ } // eslint-disable-line
+
+
+ if (typedArrayType === Uint8ClampedArray) {
+ return UNSIGNED_BYTE;
+ } // eslint-disable-line
+
+
+ if (typedArrayType === Int16Array) {
+ return SHORT;
+ } // eslint-disable-line
+
+
+ if (typedArrayType === Uint16Array) {
+ return UNSIGNED_SHORT;
+ } // eslint-disable-line
+
+
+ if (typedArrayType === Int32Array) {
+ return INT;
+ } // eslint-disable-line
+
+
+ if (typedArrayType === Uint32Array) {
+ return UNSIGNED_INT;
+ } // eslint-disable-line
+
+
+ if (typedArrayType === Float32Array) {
+ return FLOAT;
+ } // eslint-disable-line
+
+
+ throw new Error('unsupported typed array type');
+}
+/**
+ * Get the typed array constructor for a given GL type
+ * @param {number} type the GL type. (eg: `gl.UNSIGNED_INT`)
+ * @return {function} the constructor for a the corresponding typed array. (eg. `Uint32Array`).
+ * @memberOf module:twgl/typedArray
+ */
+
+
+function getTypedArrayTypeForGLType(type) {
+ var CTOR = glTypeToTypedArray[type];
+
+ if (!CTOR) {
+ throw new Error('unknown gl type');
+ }
+
+ return CTOR;
+}
+
+var isArrayBuffer = typeof SharedArrayBuffer !== 'undefined' ? function isArrayBufferOrSharedArrayBuffer(a) {
+ return a && a.buffer && (a.buffer instanceof ArrayBuffer || a.buffer instanceof SharedArrayBuffer);
+} : function isArrayBuffer(a) {
+ return a && a.buffer && a.buffer instanceof ArrayBuffer;
+};
+exports.isArrayBuffer = isArrayBuffer;
+
+/***/ }),
+
+/***/ "./src/utils.js":
+/*!**********************!*\
+ !*** ./src/utils.js ***!
+ \**********************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.isWebGL1 = isWebGL1;
+exports.isWebGL2 = isWebGL2;
+exports.glEnumToString = void 0;
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * Gets the gl version as a number
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @return {number} version of gl
+ * @private
+ */
+//function getVersionAsNumber(gl) {
+// return parseFloat(gl.getParameter(gl.VERSION).substr(6));
+//}
+
+/**
+ * Check if context is WebGL 2.0
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @return {bool} true if it's WebGL 2.0
+ * @memberOf module:twgl
+ */
+function isWebGL2(gl) {
+ // This is the correct check but it's slow
+ // return gl.getParameter(gl.VERSION).indexOf("WebGL 2.0") === 0;
+ // This might also be the correct check but I'm assuming it's slow-ish
+ // return gl instanceof WebGL2RenderingContext;
+ return !!gl.texStorage2D;
+}
+/**
+ * Check if context is WebGL 1.0
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @return {bool} true if it's WebGL 1.0
+ * @memberOf module:twgl
+ */
+
+
+function isWebGL1(gl) {
+ // This is the correct check but it's slow
+ // const version = getVersionAsNumber(gl);
+ // return version <= 1.0 && version > 0.0; // because as of 2016/5 Edge returns 0.96
+ // This might also be the correct check but I'm assuming it's slow-ish
+ // return gl instanceof WebGLRenderingContext;
+ return !gl.texStorage2D;
+}
+/**
+ * Gets a string for WebGL enum
+ *
+ * Note: Several enums are the same. Without more
+ * context (which function) it's impossible to always
+ * give the correct enum. As it is, for matching values
+ * it gives all enums. Checking the WebGL2RenderingContext
+ * that means
+ *
+ * 0 = ZERO | POINT | NONE | NO_ERROR
+ * 1 = ONE | LINES | SYNC_FLUSH_COMMANDS_BIT
+ * 32777 = BLEND_EQUATION_RGB | BLEND_EQUATION_RGB
+ * 36662 = COPY_READ_BUFFER | COPY_READ_BUFFER_BINDING
+ * 36663 = COPY_WRITE_BUFFER | COPY_WRITE_BUFFER_BINDING
+ * 36006 = FRAMEBUFFER_BINDING | DRAW_FRAMEBUFFER_BINDING
+ *
+ * It's also not useful for bits really unless you pass in individual bits.
+ * In other words
+ *
+ * const bits = gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT;
+ * twgl.glEnumToString(gl, bits); // not going to work
+ *
+ * Note that some enums only exist on extensions. If you
+ * want them to show up you need to pass the extension at least
+ * once. For example
+ *
+ * const ext = gl.getExtension('WEBGL_compressed_texture_s3tc');
+ * if (ext) {
+ * twgl.glEnumToString(ext, 0); // just prime the function
+ *
+ * ..later..
+ *
+ * const internalFormat = ext.COMPRESSED_RGB_S3TC_DXT1_EXT;
+ * console.log(twgl.glEnumToString(gl, internalFormat));
+ *
+ * Notice I didn't have to pass the extension the second time. This means
+ * you can have place that generically gets an enum for texture formats for example.
+ * and as long as you primed the function with the extensions
+ *
+ * If you're using `twgl.addExtensionsToContext` to enable your extensions
+ * then twgl will automatically get the extension's enums.
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext or any extension object
+ * @param {number} value the value of the enum you want to look up.
+ * @return {string} enum string or hex value
+ * @memberOf module:twgl
+ * @function glEnumToString
+ */
+
+
+var glEnumToString = function () {
+ var haveEnumsForType = {};
+ var enums = {};
+
+ function addEnums(gl) {
+ var type = gl.constructor.name;
+
+ if (!haveEnumsForType[type]) {
+ for (var key in gl) {
+ if (typeof gl[key] === 'number') {
+ var existing = enums[gl[key]];
+ enums[gl[key]] = existing ? "".concat(existing, " | ").concat(key) : key;
+ }
+ }
+
+ haveEnumsForType[type] = true;
+ }
+ }
+
+ return function glEnumToString(gl, value) {
+ addEnums(gl);
+ return enums[value] || "0x" + value.toString(16);
+ };
+}();
+
+exports.glEnumToString = glEnumToString;
+
+/***/ }),
+
+/***/ "./src/v3.js":
+/*!*******************!*\
+ !*** ./src/v3.js ***!
+ \*******************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.add = add;
+exports.copy = copy;
+exports.create = create;
+exports.cross = cross;
+exports.distance = distance;
+exports.distanceSq = distanceSq;
+exports.divide = divide;
+exports.divScalar = divScalar;
+exports.dot = dot;
+exports.lerp = lerp;
+exports.lerpV = lerpV;
+exports.length = length;
+exports.lengthSq = lengthSq;
+exports.max = max;
+exports.min = min;
+exports.mulScalar = mulScalar;
+exports.multiply = multiply;
+exports.negate = negate;
+exports.normalize = normalize;
+exports.setDefaultType = setDefaultType;
+exports.subtract = subtract;
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ *
+ * Vec3 math math functions.
+ *
+ * Almost all functions take an optional `dst` argument. If it is not passed in the
+ * functions will create a new Vec3. In other words you can do this
+ *
+ * var v = v3.cross(v1, v2); // Creates a new Vec3 with the cross product of v1 x v2.
+ *
+ * or
+ *
+ * var v = v3.create();
+ * v3.cross(v1, v2, v); // Puts the cross product of v1 x v2 in v
+ *
+ * The first style is often easier but depending on where it's used it generates garbage where
+ * as there is almost never allocation with the second style.
+ *
+ * It is always save to pass any vector as the destination. So for example
+ *
+ * v3.cross(v1, v2, v1); // Puts the cross product of v1 x v2 in v1
+ *
+ * @module twgl/v3
+ */
+var VecType = Float32Array;
+/**
+ * A JavaScript array with 3 values or a Float32Array with 3 values.
+ * When created by the library will create the default type which is `Float32Array`
+ * but can be set by calling {@link module:twgl/v3.setDefaultType}.
+ * @typedef {(number[]|Float32Array)} Vec3
+ * @memberOf module:twgl/v3
+ */
+
+/**
+ * Sets the type this library creates for a Vec3
+ * @param {constructor} ctor the constructor for the type. Either `Float32Array` or `Array`
+ * @return {constructor} previous constructor for Vec3
+ * @memberOf module:twgl/v3
+ */
+
+function setDefaultType(ctor) {
+ var oldType = VecType;
+ VecType = ctor;
+ return oldType;
+}
+/**
+ * Creates a vec3; may be called with x, y, z to set initial values.
+ * @param {number} [x] Initial x value.
+ * @param {number} [y] Initial y value.
+ * @param {number} [z] Initial z value.
+ * @return {module:twgl/v3.Vec3} the created vector
+ * @memberOf module:twgl/v3
+ */
+
+
+function create(x, y, z) {
+ var dst = new VecType(3);
+
+ if (x) {
+ dst[0] = x;
+ }
+
+ if (y) {
+ dst[1] = y;
+ }
+
+ if (z) {
+ dst[2] = z;
+ }
+
+ return dst;
+}
+/**
+ * Adds two vectors; assumes a and b have the same dimension.
+ * @param {module:twgl/v3.Vec3} a Operand vector.
+ * @param {module:twgl/v3.Vec3} b Operand vector.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} A vector tha tis the sum of a and b.
+ * @memberOf module:twgl/v3
+ */
+
+
+function add(a, b, dst) {
+ dst = dst || new VecType(3);
+ dst[0] = a[0] + b[0];
+ dst[1] = a[1] + b[1];
+ dst[2] = a[2] + b[2];
+ return dst;
+}
+/**
+ * Subtracts two vectors.
+ * @param {module:twgl/v3.Vec3} a Operand vector.
+ * @param {module:twgl/v3.Vec3} b Operand vector.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} A vector that is the difference of a and b.
+ * @memberOf module:twgl/v3
+ */
+
+
+function subtract(a, b, dst) {
+ dst = dst || new VecType(3);
+ dst[0] = a[0] - b[0];
+ dst[1] = a[1] - b[1];
+ dst[2] = a[2] - b[2];
+ return dst;
+}
+/**
+ * Performs linear interpolation on two vectors.
+ * Given vectors a and b and interpolation coefficient t, returns
+ * a + t * (b - a).
+ * @param {module:twgl/v3.Vec3} a Operand vector.
+ * @param {module:twgl/v3.Vec3} b Operand vector.
+ * @param {number} t Interpolation coefficient.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} The linear interpolated result.
+ * @memberOf module:twgl/v3
+ */
+
+
+function lerp(a, b, t, dst) {
+ dst = dst || new VecType(3);
+ dst[0] = a[0] + t * (b[0] - a[0]);
+ dst[1] = a[1] + t * (b[1] - a[1]);
+ dst[2] = a[2] + t * (b[2] - a[2]);
+ return dst;
+}
+/**
+ * Performs linear interpolation on two vectors.
+ * Given vectors a and b and interpolation coefficient vector t, returns
+ * a + t * (b - a).
+ * @param {module:twgl/v3.Vec3} a Operand vector.
+ * @param {module:twgl/v3.Vec3} b Operand vector.
+ * @param {module:twgl/v3.Vec3} t Interpolation coefficients vector.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} the linear interpolated result.
+ * @memberOf module:twgl/v3
+ */
+
+
+function lerpV(a, b, t, dst) {
+ dst = dst || new VecType(3);
+ dst[0] = a[0] + t[0] * (b[0] - a[0]);
+ dst[1] = a[1] + t[1] * (b[1] - a[1]);
+ dst[2] = a[2] + t[2] * (b[2] - a[2]);
+ return dst;
+}
+/**
+ * Return max values of two vectors.
+ * Given vectors a and b returns
+ * [max(a[0], b[0]), max(a[1], b[1]), max(a[2], b[2])].
+ * @param {module:twgl/v3.Vec3} a Operand vector.
+ * @param {module:twgl/v3.Vec3} b Operand vector.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} The max components vector.
+ * @memberOf module:twgl/v3
+ */
+
+
+function max(a, b, dst) {
+ dst = dst || new VecType(3);
+ dst[0] = Math.max(a[0], b[0]);
+ dst[1] = Math.max(a[1], b[1]);
+ dst[2] = Math.max(a[2], b[2]);
+ return dst;
+}
+/**
+ * Return min values of two vectors.
+ * Given vectors a and b returns
+ * [min(a[0], b[0]), min(a[1], b[1]), min(a[2], b[2])].
+ * @param {module:twgl/v3.Vec3} a Operand vector.
+ * @param {module:twgl/v3.Vec3} b Operand vector.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} The min components vector.
+ * @memberOf module:twgl/v3
+ */
+
+
+function min(a, b, dst) {
+ dst = dst || new VecType(3);
+ dst[0] = Math.min(a[0], b[0]);
+ dst[1] = Math.min(a[1], b[1]);
+ dst[2] = Math.min(a[2], b[2]);
+ return dst;
+}
+/**
+ * Multiplies a vector by a scalar.
+ * @param {module:twgl/v3.Vec3} v The vector.
+ * @param {number} k The scalar.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} The scaled vector.
+ * @memberOf module:twgl/v3
+ */
+
+
+function mulScalar(v, k, dst) {
+ dst = dst || new VecType(3);
+ dst[0] = v[0] * k;
+ dst[1] = v[1] * k;
+ dst[2] = v[2] * k;
+ return dst;
+}
+/**
+ * Divides a vector by a scalar.
+ * @param {module:twgl/v3.Vec3} v The vector.
+ * @param {number} k The scalar.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} The scaled vector.
+ * @memberOf module:twgl/v3
+ */
+
+
+function divScalar(v, k, dst) {
+ dst = dst || new VecType(3);
+ dst[0] = v[0] / k;
+ dst[1] = v[1] / k;
+ dst[2] = v[2] / k;
+ return dst;
+}
+/**
+ * Computes the cross product of two vectors; assumes both vectors have
+ * three entries.
+ * @param {module:twgl/v3.Vec3} a Operand vector.
+ * @param {module:twgl/v3.Vec3} b Operand vector.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} The vector of a cross b.
+ * @memberOf module:twgl/v3
+ */
+
+
+function cross(a, b, dst) {
+ dst = dst || new VecType(3);
+ var t1 = a[2] * b[0] - a[0] * b[2];
+ var t2 = a[0] * b[1] - a[1] * b[0];
+ dst[0] = a[1] * b[2] - a[2] * b[1];
+ dst[1] = t1;
+ dst[2] = t2;
+ return dst;
+}
+/**
+ * Computes the dot product of two vectors; assumes both vectors have
+ * three entries.
+ * @param {module:twgl/v3.Vec3} a Operand vector.
+ * @param {module:twgl/v3.Vec3} b Operand vector.
+ * @return {number} dot product
+ * @memberOf module:twgl/v3
+ */
+
+
+function dot(a, b) {
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
+}
+/**
+ * Computes the length of vector
+ * @param {module:twgl/v3.Vec3} v vector.
+ * @return {number} length of vector.
+ * @memberOf module:twgl/v3
+ */
+
+
+function length(v) {
+ return Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
+}
+/**
+ * Computes the square of the length of vector
+ * @param {module:twgl/v3.Vec3} v vector.
+ * @return {number} square of the length of vector.
+ * @memberOf module:twgl/v3
+ */
+
+
+function lengthSq(v) {
+ return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
+}
+/**
+ * Computes the distance between 2 points
+ * @param {module:twgl/v3.Vec3} a vector.
+ * @param {module:twgl/v3.Vec3} b vector.
+ * @return {number} distance between a and b
+ * @memberOf module:twgl/v3
+ */
+
+
+function distance(a, b) {
+ var dx = a[0] - b[0];
+ var dy = a[1] - b[1];
+ var dz = a[2] - b[2];
+ return Math.sqrt(dx * dx + dy * dy + dz * dz);
+}
+/**
+ * Computes the square of the distance between 2 points
+ * @param {module:twgl/v3.Vec3} a vector.
+ * @param {module:twgl/v3.Vec3} b vector.
+ * @return {number} square of the distance between a and b
+ * @memberOf module:twgl/v3
+ */
+
+
+function distanceSq(a, b) {
+ var dx = a[0] - b[0];
+ var dy = a[1] - b[1];
+ var dz = a[2] - b[2];
+ return dx * dx + dy * dy + dz * dz;
+}
+/**
+ * Divides a vector by its Euclidean length and returns the quotient.
+ * @param {module:twgl/v3.Vec3} a The vector.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} The normalized vector.
+ * @memberOf module:twgl/v3
+ */
+
+
+function normalize(a, dst) {
+ dst = dst || new VecType(3);
+ var lenSq = a[0] * a[0] + a[1] * a[1] + a[2] * a[2];
+ var len = Math.sqrt(lenSq);
+
+ if (len > 0.00001) {
+ dst[0] = a[0] / len;
+ dst[1] = a[1] / len;
+ dst[2] = a[2] / len;
+ } else {
+ dst[0] = 0;
+ dst[1] = 0;
+ dst[2] = 0;
+ }
+
+ return dst;
+}
+/**
+ * Negates a vector.
+ * @param {module:twgl/v3.Vec3} v The vector.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} -v.
+ * @memberOf module:twgl/v3
+ */
+
+
+function negate(v, dst) {
+ dst = dst || new VecType(3);
+ dst[0] = -v[0];
+ dst[1] = -v[1];
+ dst[2] = -v[2];
+ return dst;
+}
+/**
+ * Copies a vector.
+ * @param {module:twgl/v3.Vec3} v The vector.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} A copy of v.
+ * @memberOf module:twgl/v3
+ */
+
+
+function copy(v, dst) {
+ dst = dst || new VecType(3);
+ dst[0] = v[0];
+ dst[1] = v[1];
+ dst[2] = v[2];
+ return dst;
+}
+/**
+ * Multiplies a vector by another vector (component-wise); assumes a and
+ * b have the same length.
+ * @param {module:twgl/v3.Vec3} a Operand vector.
+ * @param {module:twgl/v3.Vec3} b Operand vector.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} The vector of products of entries of a and
+ * b.
+ * @memberOf module:twgl/v3
+ */
+
+
+function multiply(a, b, dst) {
+ dst = dst || new VecType(3);
+ dst[0] = a[0] * b[0];
+ dst[1] = a[1] * b[1];
+ dst[2] = a[2] * b[2];
+ return dst;
+}
+/**
+ * Divides a vector by another vector (component-wise); assumes a and
+ * b have the same length.
+ * @param {module:twgl/v3.Vec3} a Operand vector.
+ * @param {module:twgl/v3.Vec3} b Operand vector.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} The vector of quotients of entries of a and
+ * b.
+ * @memberOf module:twgl/v3
+ */
+
+
+function divide(a, b, dst) {
+ dst = dst || new VecType(3);
+ dst[0] = a[0] / b[0];
+ dst[1] = a[1] / b[1];
+ dst[2] = a[2] / b[2];
+ return dst;
+}
+
+/***/ }),
+
+/***/ "./src/vertex-arrays.js":
+/*!******************************!*\
+ !*** ./src/vertex-arrays.js ***!
+ \******************************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.createVertexArrayInfo = createVertexArrayInfo;
+exports.createVAOAndSetAttributes = createVAOAndSetAttributes;
+exports.createVAOFromBufferInfo = createVAOFromBufferInfo;
+
+var programs = _interopRequireWildcard(__webpack_require__(/*! ./programs.js */ "./src/programs.js"));
+
+function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * vertex array object related functions
+ *
+ * You should generally not need to use these functions. They are provided
+ * for those cases where you're doing something out of the ordinary
+ * and you need lower level access.
+ *
+ * For backward compatibility they are available at both `twgl.attributes` and `twgl`
+ * itself
+ *
+ * See {@link module:twgl} for core functions
+ *
+ * @module twgl/vertexArrays
+ */
+var ELEMENT_ARRAY_BUFFER = 0x8893;
+/**
+ * @typedef {Object} VertexArrayInfo
+ * @property {number} numElements The number of elements to pass to `gl.drawArrays` or `gl.drawElements`.
+ * @property {number} [elementType] The type of indices `UNSIGNED_BYTE`, `UNSIGNED_SHORT` etc..
+ * @property {WebGLVertexArrayObject} [vertexArrayObject] a vertex array object
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a VertexArrayInfo from a BufferInfo and one or more ProgramInfos
+ *
+ * This can be passed to {@link module:twgl.setBuffersAndAttributes} and to
+ * {@link module:twgl:drawBufferInfo}.
+ *
+ * > **IMPORTANT:** Vertex Array Objects are **not** a direct analog for a BufferInfo. Vertex Array Objects
+ * assign buffers to specific attributes at creation time. That means they can only be used with programs
+ * who's attributes use the same attribute locations for the same purposes.
+ *
+ * > Bind your attribute locations by passing an array of attribute names to {@link module:twgl.createProgramInfo}
+ * or use WebGL 2's GLSL ES 3's `layout(location = )` to make sure locations match.
+ *
+ * also
+ *
+ * > **IMPORTANT:** After calling twgl.setBuffersAndAttribute with a BufferInfo that uses a Vertex Array Object
+ * that Vertex Array Object will be bound. That means **ANY MANIPULATION OF ELEMENT_ARRAY_BUFFER or ATTRIBUTES**
+ * will affect the Vertex Array Object state.
+ *
+ * > Call `gl.bindVertexArray(null)` to get back manipulating the global attributes and ELEMENT_ARRAY_BUFFER.
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @param {module:twgl.ProgramInfo|module:twgl.ProgramInfo[]} programInfo a programInfo or array of programInfos
+ * @param {module:twgl.BufferInfo} bufferInfo BufferInfo as returned from createBufferInfoFromArrays etc...
+ *
+ * You need to make sure every attribute that will be used is bound. So for example assume shader 1
+ * uses attributes A, B, C and shader 2 uses attributes A, B, D. If you only pass in the programInfo
+ * for shader 1 then only attributes A, B, and C will have their attributes set because TWGL doesn't
+ * now attribute D's location.
+ *
+ * So, you can pass in both shader 1 and shader 2's programInfo
+ *
+ * @return {module:twgl.VertexArrayInfo} The created VertexArrayInfo
+ *
+ * @memberOf module:twgl/vertexArrays
+ */
+
+function createVertexArrayInfo(gl, programInfos, bufferInfo) {
+ var vao = gl.createVertexArray();
+ gl.bindVertexArray(vao);
+
+ if (!programInfos.length) {
+ programInfos = [programInfos];
+ }
+
+ programInfos.forEach(function (programInfo) {
+ programs.setBuffersAndAttributes(gl, programInfo, bufferInfo);
+ });
+ gl.bindVertexArray(null);
+ return {
+ numElements: bufferInfo.numElements,
+ elementType: bufferInfo.elementType,
+ vertexArrayObject: vao
+ };
+}
+/**
+ * Creates a vertex array object and then sets the attributes on it
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {Object.} setters Attribute setters as returned from createAttributeSetters
+ * @param {Object.} attribs AttribInfos mapped by attribute name.
+ * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices
+ * @memberOf module:twgl/vertexArrays
+ */
+
+
+function createVAOAndSetAttributes(gl, setters, attribs, indices) {
+ var vao = gl.createVertexArray();
+ gl.bindVertexArray(vao);
+ programs.setAttributes(setters, attribs);
+
+ if (indices) {
+ gl.bindBuffer(ELEMENT_ARRAY_BUFFER, indices);
+ } // We unbind this because otherwise any change to ELEMENT_ARRAY_BUFFER
+ // like when creating buffers for other stuff will mess up this VAO's binding
+
+
+ gl.bindVertexArray(null);
+ return vao;
+}
+/**
+ * Creates a vertex array object and then sets the attributes
+ * on it
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
+ * to use.
+ * @param {Object.| module:twgl.ProgramInfo} programInfo as returned from createProgramInfo or Attribute setters as returned from createAttributeSetters
+ * @param {module:twgl.BufferInfo} bufferInfo BufferInfo as returned from createBufferInfoFromArrays etc...
+ * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices
+ * @memberOf module:twgl/vertexArrays
+ */
+
+
+function createVAOFromBufferInfo(gl, programInfo, bufferInfo) {
+ return createVAOAndSetAttributes(gl, programInfo.attribSetters || programInfo, bufferInfo.attribs, bufferInfo.indices);
+}
+
+/***/ })
+
+/******/ });
+});
+//# sourceMappingURL=twgl-full.js.map
\ No newline at end of file
diff --git a/blocks/waves/twgl/twgl-full.js.map b/blocks/waves/twgl/twgl-full.js.map
new file mode 100755
index 00000000..d64cbaa5
--- /dev/null
+++ b/blocks/waves/twgl/twgl-full.js.map
@@ -0,0 +1 @@
+{"version":3,"sources":["webpack://twgl/webpack/universalModuleDefinition","webpack://twgl/webpack/bootstrap","webpack://twgl/./src/attributes.js","webpack://twgl/./src/draw.js","webpack://twgl/./src/framebuffers.js","webpack://twgl/./src/helper.js","webpack://twgl/./src/m4.js","webpack://twgl/./src/primitives.js","webpack://twgl/./src/programs.js","webpack://twgl/./src/textures.js","webpack://twgl/./src/twgl-full.js","webpack://twgl/./src/twgl.js","webpack://twgl/./src/typedarrays.js","webpack://twgl/./src/utils.js","webpack://twgl/./src/v3.js","webpack://twgl/./src/vertex-arrays.js"],"names":["STATIC_DRAW","ARRAY_BUFFER","ELEMENT_ARRAY_BUFFER","BUFFER_SIZE","BYTE","UNSIGNED_BYTE","SHORT","UNSIGNED_SHORT","INT","UNSIGNED_INT","FLOAT","gl","undefined","defaults","attribPrefix","setAttributePrefix","prefix","setDefaults","newDefaults","helper","copyExistingProperties","setBufferFromTypedArray","type","buffer","array","drawType","bindBuffer","bufferData","createBufferFromTypedArray","typedArray","isBuffer","createBuffer","isIndices","name","getNormalizationForTypedArray","Int8Array","Uint8Array","getNormalizationForTypedArrayType","typedArrayType","getArray","length","data","texcoordRE","colorRE","guessNumComponentsFromName","numComponents","test","Error","getNumComponents","arrayName","size","makeTypedArray","typedArrays","isArrayBuffer","Array","isArray","Type","Uint16Array","Float32Array","createAttribsFromArrays","arrays","attribs","Object","keys","forEach","attribName","attrib","value","normalization","WebGLBuffer","normalize","numValues","arrayType","numBytes","BYTES_PER_ELEMENT","getGLTypeForTypedArrayType","getGLTypeForTypedArray","stride","offset","divisor","setAttribInfoBufferFromArray","attribInfo","bufferSubData","getBytesPerValueForGLType","positionKeys","getNumElementsFromNonIndexedArrays","key","ii","numElements","getNumElementsFromAttributes","getBufferParameter","bytesPerValue","totalElements","createBufferInfoFromArrays","srcBufferInfo","newAttribs","bufferInfo","assign","indices","newIndices","elementType","createBufferFromArray","createBuffersFromArrays","buffers","TRIANGLES","drawBufferInfo","count","instanceCount","drawElementsInstanced","drawElements","drawArraysInstanced","drawArrays","drawObjectList","objectsToDraw","lastUsedProgramInfo","lastUsedBufferInfo","object","active","programInfo","vertexArrayInfo","bindBuffers","useProgram","program","vertexArrayObject","bindVertexArray","programs","setBuffersAndAttributes","setUniforms","uniforms","FRAMEBUFFER","RENDERBUFFER","TEXTURE_2D","DEPTH_COMPONENT","RGBA","RGBA4","RGB5_A1","RGB565","DEPTH_COMPONENT16","STENCIL_INDEX","STENCIL_INDEX8","DEPTH_STENCIL","COLOR_ATTACHMENT0","DEPTH_ATTACHMENT","STENCIL_ATTACHMENT","DEPTH_STENCIL_ATTACHMENT","REPEAT","CLAMP_TO_EDGE","MIRRORED_REPEAT","NEAREST","LINEAR","NEAREST_MIPMAP_NEAREST","LINEAR_MIPMAP_NEAREST","NEAREST_MIPMAP_LINEAR","LINEAR_MIPMAP_LINEAR","defaultAttachments","format","min","wrap","attachmentsByFormat","getAttachmentPointForFormat","renderbufferFormats","isRenderbufferFormat","createFramebufferInfo","attachments","width","height","target","fb","createFramebuffer","bindFramebuffer","drawingBufferWidth","drawingBufferHeight","colorAttachmentCount","framebufferInfo","framebuffer","attachmentOptions","attachment","attachmentPoint","createRenderbuffer","bindRenderbuffer","renderbufferStorage","textureOptions","auto","minMag","mag","wrapS","wrapT","textures","createTexture","isRenderbuffer","framebufferRenderbuffer","isTexture","layer","framebufferTextureLayer","level","framebufferTexture2D","texTarget","push","resizeFramebufferInfo","ndx","resizeTexture","bindFramebufferInfo","viewport","copyNamedProperties","names","src","dst","hasOwnProperty","error","console","warn","t","WebGLRenderbuffer","isShader","WebGLShader","WebGLTexture","isSampler","WebGLSampler","MatType","setDefaultType","ctor","oldType","negate","m","copy","identity","transpose","m00","m01","m02","m03","m10","m11","m12","m13","m20","m21","m22","m23","m30","m31","m32","m33","inverse","tmp_0","tmp_1","tmp_2","tmp_3","tmp_4","tmp_5","tmp_6","tmp_7","tmp_8","tmp_9","tmp_10","tmp_11","tmp_12","tmp_13","tmp_14","tmp_15","tmp_16","tmp_17","tmp_18","tmp_19","tmp_20","tmp_21","tmp_22","tmp_23","t0","t1","t2","t3","d","multiply","a","b","a00","a01","a02","a03","a10","a11","a12","a13","a20","a21","a22","a23","a30","a31","a32","a33","b00","b01","b02","b03","b10","b11","b12","b13","b20","b21","b22","b23","b30","b31","b32","b33","setTranslation","v","getTranslation","v3","create","getAxis","axis","off","setAxis","perspective","fieldOfViewYInRadians","aspect","zNear","zFar","f","Math","tan","PI","rangeInv","ortho","left","right","bottom","top","near","far","frustum","dx","dy","dz","xAxis","yAxis","zAxis","lookAt","eye","up","subtract","cross","translation","translate","v0","v1","v2","rotationX","angleInRadians","c","cos","s","sin","rotateX","rotationY","rotateY","rotationZ","rotateZ","axisRotation","x","y","z","n","sqrt","xx","yy","zz","oneMinusCosine","axisRotate","r00","r01","r02","r10","r11","r12","r20","r21","r22","scaling","scale","transformPoint","transformDirection","transformNormal","mi","attributes","getArray_","getNumComponents_","augmentTypedArray","cursor","arguments","jj","reset","opt_index","defineProperty","get","createAugmentedTypedArray","opt_type","allButIndices","deindexVertices","vertices","newVertices","expandToUnindexed","channel","srcBuffer","dstBuffer","constructor","filter","flattenNormals","normals","normal","numNormals","nax","nay","naz","nbx","nby","nbz","ncx","ncy","ncz","nx","ny","nz","applyFuncToV3Array","matrix","fn","len","tmp","reorientDirections","m4","reorientNormals","reorientPositions","reorientVertices","indexOf","createXYQuadVertices","xOffset","yOffset","position","texcoord","createPlaneVertices","depth","subdivisionsWidth","subdivisionsDepth","numVertices","positions","texcoords","u","numVertsAcross","createSphereVertices","radius","subdivisionsAxis","subdivisionsHeight","opt_startLatitudeInRadians","opt_endLatitudeInRadians","opt_startLongitudeInRadians","opt_endLongitudeInRadians","latRange","longRange","theta","phi","sinTheta","cosTheta","sinPhi","cosPhi","ux","uy","uz","numVertsAround","CUBE_FACE_INDICES","createCubeVertices","k","cornerVertices","faceNormals","uvCoords","faceIndices","uv","createTruncatedConeVertices","bottomRadius","topRadius","radialSubdivisions","verticalSubdivisions","opt_topCap","opt_bottomCap","topCap","bottomCap","extra","vertsAroundEdge","slant","atan2","cosSlant","sinSlant","start","end","ringRadius","expandRLEData","rleData","padding","runLength","element","slice","apply","create3DFVertices","colors","numVerts","color","createCrescentVertices","verticalRadius","outerRadius","innerRadius","thickness","subdivisionsDown","startOffset","endOffset","subdivisionsThick","offsetRange","lerp","createArc","arcRadius","normalMult","normalAdd","uMult","uAdd","uBack","xBack","angle","px","py","pz","add","createSurface","leftArcOffset","rightArcOffset","numVerticesDown","createCylinderVertices","createTorusVertices","bodySubdivisions","startAngle","endAngle","range","radialParts","bodyParts","sliceAngle","sliceSin","ring","ringAngle","xSin","zCos","nextRingIndex","nextSliceIndex","createDiscVertices","divisions","stacks","stackPower","firstIndex","radiusSpan","pointsPerStack","stack","stackRadius","pow","i","randInt","random","makeRandomVertexColors","options","vColors","rand","numVertsPerColor","vertsPerColor","numSets","createBufferFunc","prototype","call","createBufferInfoFunc","arraySpecPropertyNames","copyElements","dstNdx","createArrayOfSameType","srcArray","arraySrc","newArray","newArraySpec","concatVertices","arrayOfArrays","baseName","arrayInfo","getLengthOfCombinedArrays","arraySpec","spec","copyArraysToNewArray","base","baseIndex","newArrays","info","duplicateVertices","create3DFBufferInfo","create3DFBuffers","createCubeBufferInfo","createCubeBuffers","createPlaneBufferInfo","createPlaneBuffers","createSphereBufferInfo","createSphereBuffers","createTruncatedConeBufferInfo","createTruncatedConeBuffers","createXYQuadBufferInfo","createXYQuadBuffers","createCrescentBufferInfo","createCrescentBuffers","createCylinderBufferInfo","createCylinderBuffers","createTorusBufferInfo","createTorusBuffers","createDiscBufferInfo","createDiscBuffers","createCresentBufferInfo","createCresentBuffers","createCresentVertices","getElementById","id","document","TEXTURE0","DYNAMIC_DRAW","UNIFORM_BUFFER","TRANSFORM_FEEDBACK_BUFFER","TRANSFORM_FEEDBACK","COMPILE_STATUS","LINK_STATUS","FRAGMENT_SHADER","VERTEX_SHADER","SEPARATE_ATTRIBS","ACTIVE_UNIFORMS","ACTIVE_ATTRIBUTES","TRANSFORM_FEEDBACK_VARYINGS","ACTIVE_UNIFORM_BLOCKS","UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER","UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER","UNIFORM_BLOCK_DATA_SIZE","UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES","FLOAT_VEC2","FLOAT_VEC3","FLOAT_VEC4","INT_VEC2","INT_VEC3","INT_VEC4","BOOL","BOOL_VEC2","BOOL_VEC3","BOOL_VEC4","FLOAT_MAT2","FLOAT_MAT3","FLOAT_MAT4","SAMPLER_2D","SAMPLER_CUBE","SAMPLER_3D","SAMPLER_2D_SHADOW","FLOAT_MAT2x3","FLOAT_MAT2x4","FLOAT_MAT3x2","FLOAT_MAT3x4","FLOAT_MAT4x2","FLOAT_MAT4x3","SAMPLER_2D_ARRAY","SAMPLER_2D_ARRAY_SHADOW","SAMPLER_CUBE_SHADOW","UNSIGNED_INT_VEC2","UNSIGNED_INT_VEC3","UNSIGNED_INT_VEC4","INT_SAMPLER_2D","INT_SAMPLER_3D","INT_SAMPLER_CUBE","INT_SAMPLER_2D_ARRAY","UNSIGNED_INT_SAMPLER_2D","UNSIGNED_INT_SAMPLER_3D","UNSIGNED_INT_SAMPLER_CUBE","UNSIGNED_INT_SAMPLER_2D_ARRAY","TEXTURE_CUBE_MAP","TEXTURE_3D","TEXTURE_2D_ARRAY","typeMap","getBindPointForSamplerType","bindPoint","floatSetter","location","uniform1f","floatArraySetter","uniform1fv","floatVec2Setter","uniform2fv","floatVec3Setter","uniform3fv","floatVec4Setter","uniform4fv","intSetter","uniform1i","intArraySetter","uniform1iv","intVec2Setter","uniform2iv","intVec3Setter","uniform3iv","intVec4Setter","uniform4iv","uintSetter","uniform1ui","uintArraySetter","uniform1uiv","uintVec2Setter","uniform2uiv","uintVec3Setter","uniform3uiv","uintVec4Setter","uniform4uiv","floatMat2Setter","uniformMatrix2fv","floatMat3Setter","uniformMatrix3fv","floatMat4Setter","uniformMatrix4fv","floatMat23Setter","uniformMatrix2x3fv","floatMat32Setter","uniformMatrix3x2fv","floatMat24Setter","uniformMatrix2x4fv","floatMat42Setter","uniformMatrix4x2fv","floatMat34Setter","uniformMatrix3x4fv","floatMat43Setter","uniformMatrix4x3fv","samplerSetter","unit","utils","isWebGL2","textureOrPair","texture","sampler","activeTexture","bindTexture","bindSampler","samplerArraySetter","units","Int32Array","index","setter","arraySetter","Uint32Array","floatAttribSetter","disableVertexAttribArray","vertexAttrib4fv","vertexAttrib3fv","vertexAttrib2fv","vertexAttrib1fv","enableVertexAttribArray","vertexAttribPointer","vertexAttribDivisor","intAttribSetter","vertexAttrib4iv","vertexAttribIPointer","uintAttribSetter","vertexAttrib4uiv","matAttribSetter","typeInfo","defaultSize","rowOffset","attrTypeMap","addLineNumbers","lineOffset","split","map","line","join","spaceRE","loadShader","shaderSource","shaderType","opt_errorCallback","errFn","shader","createShader","replace","compileShader","compiled","getShaderParameter","lastError","getShaderInfoLog","deleteShader","getProgramOptions","opt_attribs","opt_locations","transformFeedbackVaryings","transformFeedbackMode","errorCallback","opt","attribLocations","defaultShaderType","getShaderTypeFromScriptType","scriptType","deleteShaders","shaders","createProgram","progOptions","realShaders","newShaders","elem","text","attachShader","bindAttribLocation","varyings","linkProgram","linked","getProgramParameter","getProgramInfoLog","deleteProgram","createShaderFromScript","scriptId","opt_shaderType","shaderScript","createProgramFromScripts","shaderScriptIds","createProgramFromSources","shaderSources","isBuiltIn","startsWith","createUniformSetters","textureUnit","createUniformSetter","uniformInfo","getUniformLocation","substr","toString","uniformSetters","numUniforms","getActiveUniform","createTransformFeedbackInfo","numVaryings","varying","getTransformFeedbackVarying","bindTransformFeedbackInfo","transformFeedbackInfo","buf","bindBufferRange","bindBufferBase","createTransformFeedback","tf","bindTransformFeedback","createUniformBlockSpecFromProgram","uniformData","uniformIndices","pair","pname","getActiveUniforms","blockSpecs","numUniformBlocks","getActiveUniformBlockName","blockSpec","usedByVertexShader","getActiveUniformBlockParameter","usedByFragmentShader","used","arraySuffixRE","createUniformBlockInfoFromProgram","uniformBlockSpec","blockName","ArrayBuffer","uniformBufferIndex","uniformBlockBinding","uniformNdx","asFloat","createUniformBlockInfo","bindUniformBlock","uniformBlockInfo","bufferBindIndex","byteLength","setUniformBlock","setBlockUniforms","values","set","setters","actualSetters","numArgs","aNdx","setUniformsAndBindTextures","createAttributeSetters","attribSetters","numAttribs","getActiveAttrib","getAttribLocation","setAttributes","createProgramInfoFromProgram","createProgramInfo","good","source","script","textureColor","crossOrigin","s_ctx","getShared2DContext","createElement","getContext","ALPHA","RGB","LUMINANCE","LUMINANCE_ALPHA","TEXTURE_CUBE_MAP_POSITIVE_X","TEXTURE_CUBE_MAP_NEGATIVE_X","TEXTURE_CUBE_MAP_POSITIVE_Y","TEXTURE_CUBE_MAP_NEGATIVE_Y","TEXTURE_CUBE_MAP_POSITIVE_Z","TEXTURE_CUBE_MAP_NEGATIVE_Z","TEXTURE_MIN_FILTER","TEXTURE_MAG_FILTER","TEXTURE_WRAP_S","TEXTURE_WRAP_T","TEXTURE_WRAP_R","TEXTURE_MIN_LOD","TEXTURE_MAX_LOD","TEXTURE_BASE_LEVEL","TEXTURE_MAX_LEVEL","UNPACK_ALIGNMENT","UNPACK_ROW_LENGTH","UNPACK_IMAGE_HEIGHT","UNPACK_SKIP_PIXELS","UNPACK_SKIP_ROWS","UNPACK_SKIP_IMAGES","UNPACK_COLORSPACE_CONVERSION_WEBGL","UNPACK_PREMULTIPLY_ALPHA_WEBGL","UNPACK_FLIP_Y_WEBGL","R8","R8_SNORM","R16F","R32F","R8UI","R8I","RG16UI","RG16I","RG32UI","RG32I","RG8","RG8_SNORM","RG16F","RG32F","RG8UI","RG8I","R16UI","R16I","R32UI","R32I","RGB8","SRGB8","RGB8_SNORM","R11F_G11F_B10F","RGB9_E5","RGB16F","RGB32F","RGB8UI","RGB8I","RGB16UI","RGB16I","RGB32UI","RGB32I","RGBA8","SRGB8_ALPHA8","RGBA8_SNORM","RGB10_A2","RGBA16F","RGBA32F","RGBA8UI","RGBA8I","RGB10_A2UI","RGBA16UI","RGBA16I","RGBA32I","RGBA32UI","DEPTH_COMPONENT24","DEPTH_COMPONENT32F","DEPTH32F_STENCIL8","DEPTH24_STENCIL8","UNSIGNED_SHORT_4_4_4_4","UNSIGNED_SHORT_5_5_5_1","UNSIGNED_SHORT_5_6_5","HALF_FLOAT","HALF_FLOAT_OES","UNSIGNED_INT_2_10_10_10_REV","UNSIGNED_INT_10F_11F_11F_REV","UNSIGNED_INT_5_9_9_9_REV","FLOAT_32_UNSIGNED_INT_24_8_REV","UNSIGNED_INT_24_8","RG","RG_INTEGER","RED","RED_INTEGER","RGB_INTEGER","RGBA_INTEGER","formatInfo","numColorComponents","s_textureInternalFormatInfo","getTextureInternalFormatInfo","internalFormat","textureFormat","colorRenderable","textureFilterable","bytesPerElement","bytesPerElementMap","getBytesPerElementForInternalFormat","getFormatAndTypeForInternalFormat","isPowerOf2","canGenerateMipmap","canFilter","getNumComponentsForFormat","getTextureTypeForArrayType","defaultType","guessDimensions","setDefaultTextureColor","lastPackState","savePackState","colorspaceConversion","getParameter","pixelStorei","premultiplyAlpha","flipY","restorePackState","saveSkipState","unpackAlignment","unpackRowLength","unpackImageHeight","unpackSkipPixels","unpackSkipRows","unpackSkipImages","restoreSkipState","setTextureSamplerParameters","parameteriFn","wrapR","minLod","maxLod","baseLevel","maxLevel","setTextureParameters","tex","texParameteri","setSamplerParameters","samplerParameteri","createSampler","createSamplers","samplerOptions","samplers","make1Pixel","setTextureFilteringForSize","generateMipmap","filtering","shouldAutomaticallySetTextureFilteringForSize","getCubeFaceOrder","cubeFaceOrder","getCubeFacesWithNdx","faces","facesWithNdx","face","sort","setTextureFromElement","formatType","imgWidth","imgHeight","slices","nodeName","ctx","canvas","drawImage","texImage2D","createImageBitmap","colorSpaceConversion","then","imageBitmap","smallest","largest","max","xMult","yMult","texImage3D","srcX","srcY","texSubImage3D","noop","urlIsSameOrigin","url","href","hostname","port","protocol","localOrigin","URL","origin","urlOrigin","setToAnonymousIfUndefinedAndURLIsNotSameOrigin","loadImage","callback","img","Image","clearEventHandlers","removeEventListener","onError","onLoad","msg","addEventListener","ImageBitmap","err","bm","cb","mode","fetch","response","ok","blob","bitmap","setTimeout","e","isTexImageSource","obj","ImageData","HTMLElement","loadAndUseImage","setTextureTo1PixelColor","loadTextureFromUrl","loadCubemapFromUrls","urls","numToLoad","errors","imgs","uploadImg","faceTarget","otherTarget","loadSlicesFromUrls","firstImage","setTextureFromArray","getTypedArrayTypeForGLType","Uint8ClampedArray","glEnumToString","dimensions","cbrt","elementsPerElement","faceSize","subarray","setEmptyTexture","isAsyncSrc","createTextures","numDownloading","images","callCallbackIfReady","onLoadFn","addExtensionsToContext","setAttributeDefaults_","setTextureDefaults_","prefixRE","addExtensionToContext","extensionName","ext","getExtension","enums","fnSuffix","exec","enumSuffix","isFunc","suffix","endsWith","substring","origFn","supportedExtensions","create3DContext","context","getWebGLContext","createContext","resizeCanvasToDisplaySize","multiplier","clientWidth","clientHeight","glTypeToTypedArray","tt","Int16Array","CTOR","SharedArrayBuffer","isArrayBufferOrSharedArrayBuffer","texStorage2D","isWebGL1","haveEnumsForType","addEnums","existing","VecType","lerpV","mulScalar","divScalar","dot","lengthSq","distance","distanceSq","lenSq","divide","createVertexArrayInfo","programInfos","vao","createVertexArray","createVAOAndSetAttributes","createVAOFromBufferInfo"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;;QAGA;QACA;;;;;;;;;;;;;;;;;;;;;;;;;;;AC5DA;;AACA;;;;;;AAvBA;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAMA,WAAW,GAAoB,MAArC;AACA,IAAMC,YAAY,GAAmB,MAArC;AACA,IAAMC,oBAAoB,GAAW,MAArC;AACA,IAAMC,WAAW,GAAoB,MAArC;AAEA,IAAMC,IAAI,GAA2B,MAArC;AACA,IAAMC,aAAa,GAAkB,MAArC;AACA,IAAMC,KAAK,GAA0B,MAArC;AACA,IAAMC,cAAc,GAAiB,MAArC;AACA,IAAMC,GAAG,GAA4B,MAArC;AACA,IAAMC,YAAY,GAAmB,MAArC;AACA,IAAMC,KAAK,GAA0B,MAArC;AAEA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qB,UAASsD,WAAT,EAAsB;AACzCO,YAAQ,CAACC,uBAAT,CAAiCnH,EAAjC,EAAqC2G,WAArC,EAAkDtB,UAAlD;AACD,GAFD;AAGArF,IAAE,CAACiH,eAAH,CAAmB,IAAnB;AACA,SAAO;AACLpC,eAAW,EAAEQ,UAAU,CAACR,WADnB;AAELY,eAAW,EAAEJ,UAAU,CAACI,WAFnB;AAGLuB,qBAAiB,EAAEsjC;AAHd,GAAP;AAKD;AAED;;;;;;;;;;;AASA,SAASE,yBAAT,CAAmCxqC,EAAnC,EAAuCu2B,OAAvC,EAAgDrzB,OAAhD,EAAyDqC,OAAzD,EAAkE;AAChE,MAAM+kC,GAAG,GAAGtqC,EAAE,CAACuqC,iBAAH,EAAZ;AACAvqC,IAAE,CAACiH,eAAH,CAAmBqjC,GAAnB;AACApjC,UAAQ,CAAC+vB,aAAT,CAAuBV,OAAvB,EAAgCrzB,OAAhC;;AACA,MAAIqC,OAAJ,EAAa;AACXvF,MAAE,CAACe,UAAH,CAAcxB,oBAAd,EAAoCgG,OAApC;AACD,GAN+D,CAOhE;AACA;;;AACAvF,IAAE,CAACiH,eAAH,CAAmB,IAAnB;AACA,SAAOqjC,GAAP;AACD;AAED;;;;;;;;;;;;;AAWA,SAASG,uBAAT,CAAiCzqC,EAAjC,EAAqC2G,WAArC,EAAkDtB,UAAlD,EAA8D;AAC5D,SAAOmlC,yBAAyB,CAACxqC,EAAD,EAAK2G,WAAW,CAACkwB,aAAZ,IAA6BlwB,WAAlC,EAA+CtB,UAAU,CAACnC,OAA1D,EAAmEmC,UAAU,CAACE,OAA9E,CAAhC;AACD,C","file":"twgl-full.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"twgl\"] = factory();\n\telse\n\t\troot[\"twgl\"] = factory();\n})(typeof self !== 'undefined' ? self : this, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./src/twgl-full.js\");\n","/*\n * Copyright 2019 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n\nimport * as typedArrays from './typedarrays.js';\nimport * as helper from './helper.js';\n\nconst STATIC_DRAW = 0x88e4;\nconst ARRAY_BUFFER = 0x8892;\nconst ELEMENT_ARRAY_BUFFER = 0x8893;\nconst BUFFER_SIZE = 0x8764;\n\nconst BYTE = 0x1400;\nconst UNSIGNED_BYTE = 0x1401;\nconst SHORT = 0x1402;\nconst UNSIGNED_SHORT = 0x1403;\nconst INT = 0x1404;\nconst UNSIGNED_INT = 0x1405;\nconst FLOAT = 0x1406;\n\n/**\n * Low level attribute and buffer related functions\n *\n * You should generally not need to use these functions. They are provided\n * for those cases where you're doing something out of the ordinary\n * and you need lower level access.\n *\n * For backward compatibility they are available at both `twgl.attributes` and `twgl`\n * itself\n *\n * See {@link module:twgl} for core functions\n *\n * @module twgl/attributes\n */\n\n// make sure we don't see a global gl\nconst gl = undefined; /* eslint-disable-line */ /* lgtm [js/unused-local-variable] */\nconst defaults = {\n attribPrefix: \"\",\n};\n\n/**\n * Sets the default attrib prefix\n *\n * When writing shaders I prefer to name attributes with `a_`, uniforms with `u_` and varyings with `v_`\n * as it makes it clear where they came from. But, when building geometry I prefer using un-prefixed names.\n *\n * In other words I'll create arrays of geometry like this\n *\n * var arrays = {\n * position: ...\n * normal: ...\n * texcoord: ...\n * };\n *\n * But need those mapped to attributes and my attributes start with `a_`.\n *\n * @deprecated see {@link module:twgl.setDefaults}\n * @param {string} prefix prefix for attribs\n * @memberOf module:twgl/attributes\n */\nfunction setAttributePrefix(prefix) {\n defaults.attribPrefix = prefix;\n}\n\nfunction setDefaults(newDefaults) {\n helper.copyExistingProperties(newDefaults, defaults);\n}\n\nfunction setBufferFromTypedArray(gl, type, buffer, array, drawType) {\n gl.bindBuffer(type, buffer);\n gl.bufferData(type, array, drawType || STATIC_DRAW);\n}\n\n/**\n * Given typed array creates a WebGLBuffer and copies the typed array\n * into it.\n *\n * @param {WebGLRenderingContext} gl A WebGLRenderingContext\n * @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\n * @param {number} [type] the GL bind type for the buffer. Default = `gl.ARRAY_BUFFER`.\n * @param {number} [drawType] the GL draw type for the buffer. Default = 'gl.STATIC_DRAW`.\n * @return {WebGLBuffer} the created WebGLBuffer\n * @memberOf module:twgl/attributes\n */\nfunction createBufferFromTypedArray(gl, typedArray, type, drawType) {\n if (helper.isBuffer(gl, typedArray)) {\n return typedArray;\n }\n type = type || ARRAY_BUFFER;\n const buffer = gl.createBuffer();\n setBufferFromTypedArray(gl, type, buffer, typedArray, drawType);\n return buffer;\n}\n\nfunction isIndices(name) {\n return name === \"indices\";\n}\n\n// This is really just a guess. Though I can't really imagine using\n// anything else? Maybe for some compression?\nfunction getNormalizationForTypedArray(typedArray) {\n if (typedArray instanceof Int8Array) { return true; } // eslint-disable-line\n if (typedArray instanceof Uint8Array) { return true; } // eslint-disable-line\n return false;\n}\n\n// This is really just a guess. Though I can't really imagine using\n// anything else? Maybe for some compression?\nfunction getNormalizationForTypedArrayType(typedArrayType) {\n if (typedArrayType === Int8Array) { return true; } // eslint-disable-line\n if (typedArrayType === Uint8Array) { return true; } // eslint-disable-line\n return false;\n}\n\nfunction getArray(array) {\n return array.length ? array : array.data;\n}\n\nconst texcoordRE = /coord|texture/i;\nconst colorRE = /color|colour/i;\n\nfunction guessNumComponentsFromName(name, length) {\n let numComponents;\n if (texcoordRE.test(name)) {\n numComponents = 2;\n } else if (colorRE.test(name)) {\n numComponents = 4;\n } else {\n numComponents = 3; // position, normals, indices ...\n }\n\n if (length % numComponents > 0) {\n throw new Error(`Can not guess numComponents for attribute '${name}'. Tried ${numComponents} but ${length} values is not evenly divisible by ${numComponents}. You should specify it.`);\n }\n\n return numComponents;\n}\n\nfunction getNumComponents(array, arrayName) {\n return array.numComponents || array.size || guessNumComponentsFromName(arrayName, getArray(array).length);\n}\n\nfunction makeTypedArray(array, name) {\n if (typedArrays.isArrayBuffer(array)) {\n return array;\n }\n\n if (typedArrays.isArrayBuffer(array.data)) {\n return array.data;\n }\n\n if (Array.isArray(array)) {\n array = {\n data: array,\n };\n }\n\n let Type = array.type;\n if (!Type) {\n if (isIndices(name)) {\n Type = Uint16Array;\n } else {\n Type = Float32Array;\n }\n }\n return new Type(array.data);\n}\n\n/**\n * The info for an attribute. This is effectively just the arguments to `gl.vertexAttribPointer` plus the WebGLBuffer\n * for the attribute.\n *\n * @typedef {Object} AttribInfo\n * @property {number[]|ArrayBufferView} [value] a constant value for the attribute. Note: if this is set the attribute will be\n * disabled and set to this constant value and all other values will be ignored.\n * @property {number} [numComponents] the number of components for this attribute.\n * @property {number} [size] synonym for `numComponents`.\n * @property {number} [type] the type of the attribute (eg. `gl.FLOAT`, `gl.UNSIGNED_BYTE`, etc...) Default = `gl.FLOAT`\n * @property {boolean} [normalize] whether or not to normalize the data. Default = false\n * @property {number} [offset] offset into buffer in bytes. Default = 0\n * @property {number} [stride] the stride in bytes per element. Default = 0\n * @property {number} [divisor] the divisor in instances. Default = undefined. Note: undefined = don't call gl.vertexAttribDivisor\n * where as anything else = do call it with this value\n * @property {WebGLBuffer} buffer the buffer that contains the data for this attribute\n * @property {number} [drawType] the draw type passed to gl.bufferData. Default = gl.STATIC_DRAW\n * @memberOf module:twgl\n */\n\n/**\n * Use this type of array spec when TWGL can't guess the type or number of components of an array\n * @typedef {Object} FullArraySpec\n * @property {number[]|ArrayBufferView} [value] a constant value for the attribute. Note: if this is set the attribute will be\n * disabled and set to this constant value and all other values will be ignored.\n * @property {(number|number[]|ArrayBufferView)} data The data of the array. A number alone becomes the number of elements of type.\n * @property {number} [numComponents] number of components for `vertexAttribPointer`. Default is based on the name of the array.\n * If `coord` is in the name assumes `numComponents = 2`.\n * If `color` is in the name assumes `numComponents = 4`.\n * otherwise assumes `numComponents = 3`\n * @property {constructor} [type] type. This is only used if `data` is a JavaScript array. It is the constructor for the typedarray. (eg. `Uint8Array`).\n * For example if you want colors in a `Uint8Array` you might have a `FullArraySpec` like `{ type: Uint8Array, data: [255,0,255,255, ...], }`.\n * @property {number} [size] synonym for `numComponents`.\n * @property {boolean} [normalize] normalize for `vertexAttribPointer`. Default is true if type is `Int8Array` or `Uint8Array` otherwise false.\n * @property {number} [stride] stride for `vertexAttribPointer`. Default = 0\n * @property {number} [offset] offset for `vertexAttribPointer`. Default = 0\n * @property {number} [divisor] divisor for `vertexAttribDivisor`. Default = undefined. Note: undefined = don't call gl.vertexAttribDivisor\n * where as anything else = do call it with this value\n * @property {string} [attrib] name of attribute this array maps to. Defaults to same name as array prefixed by the default attribPrefix.\n * @property {string} [name] synonym for `attrib`.\n * @property {string} [attribName] synonym for `attrib`.\n * @property {WebGLBuffer} [buffer] Buffer to use for this attribute. This lets you use your own buffer\n * but you will need to supply `numComponents` and `type`. You can effectively pass an `AttribInfo`\n * to provide this. Example:\n *\n * const bufferInfo1 = twgl.createBufferInfoFromArrays(gl, {\n * position: [1, 2, 3, ... ],\n * });\n * const bufferInfo2 = twgl.createBufferInfoFromArrays(gl, {\n * position: bufferInfo1.attribs.position, // use the same buffer from bufferInfo1\n * });\n *\n * @memberOf module:twgl\n */\n\n/**\n * An individual array in {@link module:twgl.Arrays}\n *\n * When passed to {@link module:twgl.createBufferInfoFromArrays} if an ArraySpec is `number[]` or `ArrayBufferView`\n * the types will be guessed based on the name. `indices` will be `Uint16Array`, everything else will\n * be `Float32Array`. If an ArraySpec is a number it's the number of floats for an empty (zeroed) buffer.\n *\n * @typedef {(number|number[]|ArrayBufferView|module:twgl.FullArraySpec)} ArraySpec\n * @memberOf module:twgl\n */\n\n/**\n * This is a JavaScript object of arrays by name. The names should match your shader's attributes. If your\n * attributes have a common prefix you can specify it by calling {@link module:twgl.setAttributePrefix}.\n *\n * Bare JavaScript Arrays\n *\n * var arrays = {\n * position: [-1, 1, 0],\n * normal: [0, 1, 0],\n * ...\n * }\n *\n * Bare TypedArrays\n *\n * var arrays = {\n * position: new Float32Array([-1, 1, 0]),\n * color: new Uint8Array([255, 128, 64, 255]),\n * ...\n * }\n *\n * * Will guess at `numComponents` if not specified based on name.\n *\n * If `coord` is in the name assumes `numComponents = 2`\n *\n * If `color` is in the name assumes `numComponents = 4`\n *\n * otherwise assumes `numComponents = 3`\n *\n * Objects with various fields. See {@link module:twgl.FullArraySpec}.\n *\n * var arrays = {\n * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },\n * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },\n * normal: { numComponents: 3, data: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], },\n * indices: { numComponents: 3, data: [0, 1, 2, 1, 2, 3], },\n * };\n *\n * @typedef {Object.} Arrays\n * @memberOf module:twgl\n */\n\n\n/**\n * Creates a set of attribute data and WebGLBuffers from set of arrays\n *\n * Given\n *\n * var arrays = {\n * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },\n * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },\n * normal: { numComponents: 3, data: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], },\n * color: { numComponents: 4, data: [255, 255, 255, 255, 255, 0, 0, 255, 0, 0, 255, 255], type: Uint8Array, },\n * indices: { numComponents: 3, data: [0, 1, 2, 1, 2, 3], },\n * };\n *\n * returns something like\n *\n * var attribs = {\n * position: { numComponents: 3, type: gl.FLOAT, normalize: false, buffer: WebGLBuffer, },\n * texcoord: { numComponents: 2, type: gl.FLOAT, normalize: false, buffer: WebGLBuffer, },\n * normal: { numComponents: 3, type: gl.FLOAT, normalize: false, buffer: WebGLBuffer, },\n * color: { numComponents: 4, type: gl.UNSIGNED_BYTE, normalize: true, buffer: WebGLBuffer, },\n * };\n *\n * notes:\n *\n * * Arrays can take various forms\n *\n * Bare JavaScript Arrays\n *\n * var arrays = {\n * position: [-1, 1, 0],\n * normal: [0, 1, 0],\n * ...\n * }\n *\n * Bare TypedArrays\n *\n * var arrays = {\n * position: new Float32Array([-1, 1, 0]),\n * color: new Uint8Array([255, 128, 64, 255]),\n * ...\n * }\n *\n * * Will guess at `numComponents` if not specified based on name.\n *\n * If `coord` is in the name assumes `numComponents = 2`\n *\n * If `color` is in the name assumes `numComponents = 4`\n *\n * otherwise assumes `numComponents = 3`\n *\n * @param {WebGLRenderingContext} gl The webgl rendering context.\n * @param {module:twgl.Arrays} arrays The arrays\n * @param {module:twgl.BufferInfo} [srcBufferInfo] a BufferInfo to copy from\n * This lets you share buffers. Any arrays you supply will override\n * the buffers from srcBufferInfo.\n * @return {Object.} the attribs\n * @memberOf module:twgl/attributes\n */\nfunction createAttribsFromArrays(gl, arrays) {\n const attribs = {};\n Object.keys(arrays).forEach(function(arrayName) {\n if (!isIndices(arrayName)) {\n const array = arrays[arrayName];\n const attribName = array.attrib || array.name || array.attribName || (defaults.attribPrefix + arrayName);\n if (array.value) {\n if (!Array.isArray(array.value) && !typedArrays.isArrayBuffer(array.value)) {\n throw new Error('array.value is not array or typedarray');\n }\n attribs[attribName] = {\n value: array.value,\n };\n } else {\n let buffer;\n let type;\n let normalization;\n let numComponents;\n if (array.buffer && array.buffer instanceof WebGLBuffer) {\n buffer = array.buffer;\n numComponents = array.numComponents || array.size;\n type = array.type;\n normalization = array.normalize;\n } else if (typeof array === \"number\" || typeof array.data === \"number\") {\n const numValues = array.data || array;\n const arrayType = array.type || Float32Array;\n const numBytes = numValues * arrayType.BYTES_PER_ELEMENT;\n type = typedArrays.getGLTypeForTypedArrayType(arrayType);\n normalization = array.normalize !== undefined ? array.normalize : getNormalizationForTypedArrayType(arrayType);\n numComponents = array.numComponents || array.size || guessNumComponentsFromName(arrayName, numValues);\n buffer = gl.createBuffer();\n gl.bindBuffer(ARRAY_BUFFER, buffer);\n gl.bufferData(ARRAY_BUFFER, numBytes, array.drawType || STATIC_DRAW);\n } else {\n const typedArray = makeTypedArray(array, arrayName);\n buffer = createBufferFromTypedArray(gl, typedArray, undefined, array.drawType);\n type = typedArrays.getGLTypeForTypedArray(typedArray);\n normalization = array.normalize !== undefined ? array.normalize : getNormalizationForTypedArray(typedArray);\n numComponents = getNumComponents(array, arrayName);\n }\n attribs[attribName] = {\n buffer: buffer,\n numComponents: numComponents,\n type: type,\n normalize: normalization,\n stride: array.stride || 0,\n offset: array.offset || 0,\n divisor: array.divisor === undefined ? undefined : array.divisor,\n drawType: array.drawType,\n };\n }\n }\n });\n gl.bindBuffer(ARRAY_BUFFER, null);\n return attribs;\n}\n\n/**\n * Sets the contents of a buffer attached to an attribInfo\n *\n * This is helper function to dynamically update a buffer.\n *\n * Let's say you make a bufferInfo\n *\n * var arrays = {\n * position: new Float32Array([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]),\n * texcoord: new Float32Array([0, 0, 0, 1, 1, 0, 1, 1]),\n * normal: new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]),\n * indices: new Uint16Array([0, 1, 2, 1, 2, 3]),\n * };\n * var bufferInfo = twgl.createBufferInfoFromArrays(gl, arrays);\n *\n * And you want to dynamically update the positions. You could do this\n *\n * // assuming arrays.position has already been updated with new data.\n * twgl.setAttribInfoBufferFromArray(gl, bufferInfo.attribs.position, arrays.position);\n *\n * @param {WebGLRenderingContext} gl\n * @param {AttribInfo} attribInfo The attribInfo who's buffer contents to set. NOTE: If you have an attribute prefix\n * the name of the attribute will include the prefix.\n * @param {ArraySpec} array Note: it is arguably inefficient to pass in anything but a typed array because anything\n * else will have to be converted to a typed array before it can be used by WebGL. During init time that\n * inefficiency is usually not important but if you're updating data dynamically best to be efficient.\n * @param {number} [offset] an optional offset into the buffer. This is only an offset into the WebGL buffer\n * not the array. To pass in an offset into the array itself use a typed array and create an `ArrayBufferView`\n * for the portion of the array you want to use.\n *\n * var someArray = new Float32Array(1000); // an array with 1000 floats\n * var someSubArray = new Float32Array(someArray.buffer, offsetInBytes, sizeInUnits); // a view into someArray\n *\n * Now you can pass `someSubArray` into setAttribInfoBufferFromArray`\n * @memberOf module:twgl/attributes\n */\nfunction setAttribInfoBufferFromArray(gl, attribInfo, array, offset) {\n array = makeTypedArray(array);\n if (offset !== undefined) {\n gl.bindBuffer(ARRAY_BUFFER, attribInfo.buffer);\n gl.bufferSubData(ARRAY_BUFFER, offset, array);\n } else {\n setBufferFromTypedArray(gl, ARRAY_BUFFER, attribInfo.buffer, array, attribInfo.drawType);\n }\n}\n\nfunction getBytesPerValueForGLType(gl, type) {\n if (type === BYTE) return 1; // eslint-disable-line\n if (type === UNSIGNED_BYTE) return 1; // eslint-disable-line\n if (type === SHORT) return 2; // eslint-disable-line\n if (type === UNSIGNED_SHORT) return 2; // eslint-disable-line\n if (type === INT) return 4; // eslint-disable-line\n if (type === UNSIGNED_INT) return 4; // eslint-disable-line\n if (type === FLOAT) return 4; // eslint-disable-line\n return 0;\n}\n\n// Tries to get the number of elements from a set of arrays.\nconst positionKeys = ['position', 'positions', 'a_position'];\nfunction getNumElementsFromNonIndexedArrays(arrays) {\n let key;\n let ii;\n for (ii = 0; ii < positionKeys.length; ++ii) {\n key = positionKeys[ii];\n if (key in arrays) {\n break;\n }\n }\n if (ii === positionKeys.length) {\n key = Object.keys(arrays)[0];\n }\n const array = arrays[key];\n const length = getArray(array).length;\n const numComponents = getNumComponents(array, key);\n const numElements = length / numComponents;\n if (length % numComponents > 0) {\n throw new Error(`numComponents ${numComponents} not correct for length ${length}`);\n }\n return numElements;\n}\n\nfunction getNumElementsFromAttributes(gl, attribs) {\n let key;\n let ii;\n for (ii = 0; ii < positionKeys.length; ++ii) {\n key = positionKeys[ii];\n if (key in attribs) {\n break;\n }\n key = defaults.attribPrefix + key;\n if (key in attribs) {\n break;\n }\n }\n if (ii === positionKeys.length) {\n key = Object.keys(attribs)[0];\n }\n const attrib = attribs[key];\n gl.bindBuffer(ARRAY_BUFFER, attrib.buffer);\n const numBytes = gl.getBufferParameter(ARRAY_BUFFER, BUFFER_SIZE);\n gl.bindBuffer(ARRAY_BUFFER, null);\n\n const bytesPerValue = getBytesPerValueForGLType(gl, attrib.type);\n const totalElements = numBytes / bytesPerValue;\n const numComponents = attrib.numComponents || attrib.size;\n // TODO: check stride\n const numElements = totalElements / numComponents;\n if (numElements % 1 !== 0) {\n throw new Error(`numComponents ${numComponents} not correct for length ${length}`);\n }\n return numElements;\n}\n\n/**\n * @typedef {Object} BufferInfo\n * @property {number} numElements The number of elements to pass to `gl.drawArrays` or `gl.drawElements`.\n * @property {number} [elementType] The type of indices `UNSIGNED_BYTE`, `UNSIGNED_SHORT` etc..\n * @property {WebGLBuffer} [indices] The indices `ELEMENT_ARRAY_BUFFER` if any indices exist.\n * @property {Object.} [attribs] The attribs appropriate to call `setAttributes`\n * @memberOf module:twgl\n */\n\n/**\n * Creates a BufferInfo from an object of arrays.\n *\n * This can be passed to {@link module:twgl.setBuffersAndAttributes} and to\n * {@link module:twgl:drawBufferInfo}.\n *\n * Given an object like\n *\n * var arrays = {\n * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },\n * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },\n * normal: { numComponents: 3, data: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], },\n * indices: { numComponents: 3, data: [0, 1, 2, 1, 2, 3], },\n * };\n *\n * Creates an BufferInfo like this\n *\n * bufferInfo = {\n * numElements: 4, // or whatever the number of elements is\n * indices: WebGLBuffer, // this property will not exist if there are no indices\n * attribs: {\n * position: { buffer: WebGLBuffer, numComponents: 3, },\n * normal: { buffer: WebGLBuffer, numComponents: 3, },\n * texcoord: { buffer: WebGLBuffer, numComponents: 2, },\n * },\n * };\n *\n * The properties of arrays can be JavaScript arrays in which case the number of components\n * will be guessed.\n *\n * var arrays = {\n * position: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0],\n * texcoord: [0, 0, 0, 1, 1, 0, 1, 1],\n * normal: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],\n * indices: [0, 1, 2, 1, 2, 3],\n * };\n *\n * They can also be TypedArrays\n *\n * var arrays = {\n * position: new Float32Array([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]),\n * texcoord: new Float32Array([0, 0, 0, 1, 1, 0, 1, 1]),\n * normal: new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]),\n * indices: new Uint16Array([0, 1, 2, 1, 2, 3]),\n * };\n *\n * Or AugmentedTypedArrays\n *\n * var positions = createAugmentedTypedArray(3, 4);\n * var texcoords = createAugmentedTypedArray(2, 4);\n * var normals = createAugmentedTypedArray(3, 4);\n * var indices = createAugmentedTypedArray(3, 2, Uint16Array);\n *\n * positions.push([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]);\n * texcoords.push([0, 0, 0, 1, 1, 0, 1, 1]);\n * normals.push([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]);\n * indices.push([0, 1, 2, 1, 2, 3]);\n *\n * var arrays = {\n * position: positions,\n * texcoord: texcoords,\n * normal: normals,\n * indices: indices,\n * };\n *\n * For the last example it is equivalent to\n *\n * var bufferInfo = {\n * attribs: {\n * position: { numComponents: 3, buffer: gl.createBuffer(), },\n * texcoord: { numComponents: 2, buffer: gl.createBuffer(), },\n * normal: { numComponents: 3, buffer: gl.createBuffer(), },\n * },\n * indices: gl.createBuffer(),\n * numElements: 6,\n * };\n *\n * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.position.buffer);\n * gl.bufferData(gl.ARRAY_BUFFER, arrays.position, gl.STATIC_DRAW);\n * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.texcoord.buffer);\n * gl.bufferData(gl.ARRAY_BUFFER, arrays.texcoord, gl.STATIC_DRAW);\n * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.normal.buffer);\n * gl.bufferData(gl.ARRAY_BUFFER, arrays.normal, gl.STATIC_DRAW);\n * gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, bufferInfo.indices);\n * gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, arrays.indices, gl.STATIC_DRAW);\n *\n * @param {WebGLRenderingContext} gl A WebGLRenderingContext\n * @param {module:twgl.Arrays} arrays Your data\n * @param {module:twgl.BufferInfo} [srcBufferInfo] An existing\n * buffer info to start from. WebGLBuffers etc specified\n * in the srcBufferInfo will be used in a new BufferInfo\n * with any arrays specified overriding the ones in\n * srcBufferInfo.\n * @return {module:twgl.BufferInfo} A BufferInfo\n * @memberOf module:twgl/attributes\n */\nfunction createBufferInfoFromArrays(gl, arrays, srcBufferInfo) {\n const newAttribs = createAttribsFromArrays(gl, arrays);\n const bufferInfo = Object.assign({}, srcBufferInfo ? srcBufferInfo : {});\n bufferInfo.attribs = Object.assign({}, srcBufferInfo ? srcBufferInfo.attribs : {}, newAttribs);\n const indices = arrays.indices;\n if (indices) {\n const newIndices = makeTypedArray(indices, \"indices\");\n bufferInfo.indices = createBufferFromTypedArray(gl, newIndices, ELEMENT_ARRAY_BUFFER);\n bufferInfo.numElements = newIndices.length;\n bufferInfo.elementType = typedArrays.getGLTypeForTypedArray(newIndices);\n } else if (!bufferInfo.numElements) {\n bufferInfo.numElements = getNumElementsFromAttributes(gl, bufferInfo.attribs);\n }\n\n return bufferInfo;\n}\n\n/**\n * Creates a buffer from an array, typed array, or array spec\n *\n * Given something like this\n *\n * [1, 2, 3],\n *\n * or\n *\n * new Uint16Array([1,2,3]);\n *\n * or\n *\n * {\n * data: [1, 2, 3],\n * type: Uint8Array,\n * }\n *\n * returns a WebGLBuffer that contains the given data.\n *\n * @param {WebGLRenderingContext} gl A WebGLRenderingContext.\n * @param {module:twgl.ArraySpec} array an array, typed array, or array spec.\n * @param {string} arrayName name of array. Used to guess the type if type can not be derived otherwise.\n * @return {WebGLBuffer} a WebGLBuffer containing the data in array.\n * @memberOf module:twgl/attributes\n */\nfunction createBufferFromArray(gl, array, arrayName) {\n const type = arrayName === \"indices\" ? ELEMENT_ARRAY_BUFFER : ARRAY_BUFFER;\n const typedArray = makeTypedArray(array, arrayName);\n return createBufferFromTypedArray(gl, typedArray, type);\n}\n\n/**\n * Creates buffers from arrays or typed arrays\n *\n * Given something like this\n *\n * var arrays = {\n * positions: [1, 2, 3],\n * normals: [0, 0, 1],\n * }\n *\n * returns something like\n *\n * buffers = {\n * positions: WebGLBuffer,\n * normals: WebGLBuffer,\n * }\n *\n * If the buffer is named 'indices' it will be made an ELEMENT_ARRAY_BUFFER.\n *\n * @param {WebGLRenderingContext} gl A WebGLRenderingContext.\n * @param {module:twgl.Arrays} arrays\n * @return {Object} returns an object with one WebGLBuffer per array\n * @memberOf module:twgl/attributes\n */\nfunction createBuffersFromArrays(gl, arrays) {\n const buffers = { };\n Object.keys(arrays).forEach(function(key) {\n buffers[key] = createBufferFromArray(gl, arrays[key], key);\n });\n\n // Ugh!\n if (arrays.indices) {\n buffers.numElements = arrays.indices.length;\n buffers.elementType = typedArrays.getGLTypeForTypedArray(makeTypedArray(arrays.indices), 'indices');\n } else {\n buffers.numElements = getNumElementsFromNonIndexedArrays(arrays);\n }\n\n return buffers;\n}\n\nexport {\n createAttribsFromArrays,\n createBuffersFromArrays,\n createBufferFromArray,\n createBufferFromTypedArray,\n createBufferInfoFromArrays,\n setAttribInfoBufferFromArray,\n\n setAttributePrefix,\n\n setDefaults as setAttributeDefaults_,\n getNumComponents as getNumComponents_,\n getArray as getArray_,\n};\n\n","/*\n * Copyright 2019 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n\nimport * as programs from './programs.js';\n\nconst TRIANGLES = 0x0004;\nconst UNSIGNED_SHORT = 0x1403;\n\n/**\n * Drawing related functions\n *\n * For backward compatibility they are available at both `twgl.draw` and `twgl`\n * itself\n *\n * See {@link module:twgl} for core functions\n *\n * @module twgl/draw\n */\n\n/**\n * Calls `gl.drawElements` or `gl.drawArrays`, whichever is appropriate\n *\n * normally you'd call `gl.drawElements` or `gl.drawArrays` yourself\n * but calling this means if you switch from indexed data to non-indexed\n * data you don't have to remember to update your draw call.\n *\n * @param {WebGLRenderingContext} gl A WebGLRenderingContext\n * @param {(module:twgl.BufferInfo|module:twgl.VertexArrayInfo)} bufferInfo A BufferInfo as returned from {@link module:twgl.createBufferInfoFromArrays} or\n * a VertexArrayInfo as returned from {@link module:twgl.createVertexArrayInfo}\n * @param {number} [type] eg (gl.TRIANGLES, gl.LINES, gl.POINTS, gl.TRIANGLE_STRIP, ...). Defaults to `gl.TRIANGLES`\n * @param {number} [count] An optional count. Defaults to bufferInfo.numElements\n * @param {number} [offset] An optional offset. Defaults to 0.\n * @param {number} [instanceCount] An optional instanceCount. if set then `drawArraysInstanced` or `drawElementsInstanced` will be called\n * @memberOf module:twgl/draw\n */\nfunction drawBufferInfo(gl, bufferInfo, type, count, offset, instanceCount) {\n type = type === undefined ? TRIANGLES : type;\n const indices = bufferInfo.indices;\n const elementType = bufferInfo.elementType;\n const numElements = count === undefined ? bufferInfo.numElements : count;\n offset = offset === undefined ? 0 : offset;\n if (elementType || indices) {\n if (instanceCount !== undefined) {\n gl.drawElementsInstanced(type, numElements, elementType === undefined ? UNSIGNED_SHORT : bufferInfo.elementType, offset, instanceCount);\n } else {\n gl.drawElements(type, numElements, elementType === undefined ? UNSIGNED_SHORT : bufferInfo.elementType, offset);\n }\n } else {\n if (instanceCount !== undefined) {\n gl.drawArraysInstanced(type, offset, numElements, instanceCount);\n } else {\n gl.drawArrays(type, offset, numElements);\n }\n }\n}\n\n/**\n * A DrawObject is useful for putting objects in to an array and passing them to {@link module:twgl.drawObjectList}.\n *\n * You need either a `BufferInfo` or a `VertexArrayInfo`.\n *\n * @typedef {Object} DrawObject\n * @property {boolean} [active] whether or not to draw. Default = `true` (must be `false` to be not true). In other words `undefined` = `true`\n * @property {number} [type] type to draw eg. `gl.TRIANGLES`, `gl.LINES`, etc...\n * @property {module:twgl.ProgramInfo} programInfo A ProgramInfo as returned from {@link module:twgl.createProgramInfo}\n * @property {module:twgl.BufferInfo} [bufferInfo] A BufferInfo as returned from {@link module:twgl.createBufferInfoFromArrays}\n * @property {module:twgl.VertexArrayInfo} [vertexArrayInfo] A VertexArrayInfo as returned from {@link module:twgl.createVertexArrayInfo}\n * @property {Object} uniforms The values for the uniforms.\n * You can pass multiple objects by putting them in an array. For example\n *\n * var sharedUniforms = {\n * u_fogNear: 10,\n * u_projection: ...\n * ...\n * };\n *\n * var localUniforms = {\n * u_world: ...\n * u_diffuseColor: ...\n * };\n *\n * var drawObj = {\n * ...\n * uniforms: [sharedUniforms, localUniforms],\n * };\n *\n * @property {number} [offset] the offset to pass to `gl.drawArrays` or `gl.drawElements`. Defaults to 0.\n * @property {number} [count] the count to pass to `gl.drawArrays` or `gl.drawElements`. Defaults to bufferInfo.numElements.\n * @property {number} [instanceCount] the number of instances. Defaults to undefined.\n * @memberOf module:twgl\n */\n\n/**\n * Draws a list of objects\n * @param {WebGLRenderingContext} gl A WebGLRenderingContext\n * @param {DrawObject[]} objectsToDraw an array of objects to draw.\n * @memberOf module:twgl/draw\n */\nfunction drawObjectList(gl, objectsToDraw) {\n let lastUsedProgramInfo = null;\n let lastUsedBufferInfo = null;\n\n objectsToDraw.forEach(function(object) {\n if (object.active === false) {\n return;\n }\n\n const programInfo = object.programInfo;\n const bufferInfo = object.vertexArrayInfo || object.bufferInfo;\n let bindBuffers = false;\n const type = object.type === undefined ? TRIANGLES : object.type;\n\n if (programInfo !== lastUsedProgramInfo) {\n lastUsedProgramInfo = programInfo;\n gl.useProgram(programInfo.program);\n\n // We have to rebind buffers when changing programs because we\n // only bind buffers the program uses. So if 2 programs use the same\n // bufferInfo but the 1st one uses only positions the when the\n // we switch to the 2nd one some of the attributes will not be on.\n bindBuffers = true;\n }\n\n // Setup all the needed attributes.\n if (bindBuffers || bufferInfo !== lastUsedBufferInfo) {\n if (lastUsedBufferInfo && lastUsedBufferInfo.vertexArrayObject && !bufferInfo.vertexArrayObject) {\n gl.bindVertexArray(null);\n }\n lastUsedBufferInfo = bufferInfo;\n programs.setBuffersAndAttributes(gl, programInfo, bufferInfo);\n }\n\n // Set the uniforms.\n programs.setUniforms(programInfo, object.uniforms);\n\n // Draw\n drawBufferInfo(gl, bufferInfo, type, object.count, object.offset, object.instanceCount);\n });\n\n if (lastUsedBufferInfo && lastUsedBufferInfo.vertexArrayObject) {\n gl.bindVertexArray(null);\n }\n}\n\nexport {\n drawBufferInfo,\n drawObjectList,\n};\n\n","/*\n * Copyright 2019 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n\nimport * as textures from './textures.js';\nimport * as helper from './helper.js';\n\n/**\n * Framebuffer related functions\n *\n * For backward compatibility they are available at both `twgl.framebuffer` and `twgl`\n * itself\n *\n * See {@link module:twgl} for core functions\n *\n * @module twgl/framebuffers\n */\n\n// make sure we don't see a global gl\nconst gl = undefined; /* eslint-disable-line */ /* lgtm [js/unused-local-variable] */\n\nconst FRAMEBUFFER = 0x8d40;\nconst RENDERBUFFER = 0x8d41;\nconst TEXTURE_2D = 0x0de1;\n\nconst UNSIGNED_BYTE = 0x1401;\n\n/* PixelFormat */\nconst DEPTH_COMPONENT = 0x1902;\nconst RGBA = 0x1908;\n\n/* Framebuffer Object. */\nconst RGBA4 = 0x8056;\nconst RGB5_A1 = 0x8057;\nconst RGB565 = 0x8D62;\nconst DEPTH_COMPONENT16 = 0x81A5;\nconst STENCIL_INDEX = 0x1901;\nconst STENCIL_INDEX8 = 0x8D48;\nconst DEPTH_STENCIL = 0x84F9;\nconst COLOR_ATTACHMENT0 = 0x8CE0;\nconst DEPTH_ATTACHMENT = 0x8D00;\nconst STENCIL_ATTACHMENT = 0x8D20;\nconst DEPTH_STENCIL_ATTACHMENT = 0x821A;\n\n/* TextureWrapMode */\nconst REPEAT = 0x2901; // eslint-disable-line\nconst CLAMP_TO_EDGE = 0x812F;\nconst MIRRORED_REPEAT = 0x8370; // eslint-disable-line\n\n/* TextureMagFilter */\nconst NEAREST = 0x2600; // eslint-disable-line\nconst LINEAR = 0x2601;\n\n/* TextureMinFilter */\nconst NEAREST_MIPMAP_NEAREST = 0x2700; // eslint-disable-line\nconst LINEAR_MIPMAP_NEAREST = 0x2701; // eslint-disable-line\nconst NEAREST_MIPMAP_LINEAR = 0x2702; // eslint-disable-line\nconst LINEAR_MIPMAP_LINEAR = 0x2703; // eslint-disable-line\n\n/**\n * The options for a framebuffer attachment.\n *\n * Note: For a `format` that is a texture include all the texture\n * options from {@link module:twgl.TextureOptions} for example\n * `min`, `mag`, `clamp`, etc... Note that unlike {@link module:twgl.TextureOptions}\n * `auto` defaults to `false` for attachment textures but `min` and `mag` default\n * to `gl.LINEAR` and `wrap` defaults to `CLAMP_TO_EDGE`\n *\n * @typedef {Object} AttachmentOptions\n * @property {number} [attach] The attachment point. Defaults\n * to `gl.COLOR_ATTACHMENT0 + ndx` unless type is a depth or stencil type\n * then it's gl.DEPTH_ATTACHMENT or `gl.DEPTH_STENCIL_ATTACHMENT` depending\n * on the format or attachment type.\n * @property {number} [format] The format. If one of `gl.RGBA4`,\n * `gl.RGB565`, `gl.RGB5_A1`, `gl.DEPTH_COMPONENT16`,\n * `gl.STENCIL_INDEX8` or `gl.DEPTH_STENCIL` then will create a\n * renderbuffer. Otherwise will create a texture. Default = `gl.RGBA`\n * @property {number} [type] The type. Used for texture. Default = `gl.UNSIGNED_BYTE`.\n * @property {number} [target] The texture target for `gl.framebufferTexture2D`.\n * Defaults to `gl.TEXTURE_2D`. Set to appropriate face for cube maps.\n * @property {number} [level] level for `gl.framebufferTexture2D`. Defaults to 0.\n * @property {number} [layer] layer for `gl.framebufferTextureLayer`. Defaults to undefined.\n * If set then `gl.framebufferTextureLayer` is called, if not then `gl.framebufferTexture2D`\n * @property {WebGLObject} [attachment] An existing renderbuffer or texture.\n * If provided will attach this Object. This allows you to share\n * attachments across framebuffers.\n * @memberOf module:twgl\n * @mixes module:twgl.TextureOptions\n */\n\nconst defaultAttachments = [\n { format: RGBA, type: UNSIGNED_BYTE, min: LINEAR, wrap: CLAMP_TO_EDGE, },\n { format: DEPTH_STENCIL, },\n];\n\nconst attachmentsByFormat = {};\nattachmentsByFormat[DEPTH_STENCIL] = DEPTH_STENCIL_ATTACHMENT;\nattachmentsByFormat[STENCIL_INDEX] = STENCIL_ATTACHMENT;\nattachmentsByFormat[STENCIL_INDEX8] = STENCIL_ATTACHMENT;\nattachmentsByFormat[DEPTH_COMPONENT] = DEPTH_ATTACHMENT;\nattachmentsByFormat[DEPTH_COMPONENT16] = DEPTH_ATTACHMENT;\n\nfunction getAttachmentPointForFormat(format) {\n return attachmentsByFormat[format];\n}\n\nconst renderbufferFormats = {};\nrenderbufferFormats[RGBA4] = true;\nrenderbufferFormats[RGB5_A1] = true;\nrenderbufferFormats[RGB565] = true;\nrenderbufferFormats[DEPTH_STENCIL] = true;\nrenderbufferFormats[DEPTH_COMPONENT16] = true;\nrenderbufferFormats[STENCIL_INDEX] = true;\nrenderbufferFormats[STENCIL_INDEX8] = true;\n\nfunction isRenderbufferFormat(format) {\n return renderbufferFormats[format];\n}\n\n/**\n * @typedef {Object} FramebufferInfo\n * @property {WebGLFramebuffer} framebuffer The WebGLFramebuffer for this framebufferInfo\n * @property {WebGLObject[]} attachments The created attachments in the same order as passed in to {@link module:twgl.createFramebufferInfo}.\n * @property {number} width The width of the framebuffer and its attachments\n * @property {number} height The width of the framebuffer and its attachments\n * @memberOf module:twgl\n */\n\n/**\n * Creates a framebuffer and attachments.\n *\n * This returns a {@link module:twgl.FramebufferInfo} because it needs to return the attachments as well as the framebuffer.\n *\n * The simplest usage\n *\n * // create an RGBA/UNSIGNED_BYTE texture and DEPTH_STENCIL renderbuffer\n * const fbi = twgl.createFramebufferInfo(gl);\n *\n * More complex usage\n *\n * // create an RGB565 renderbuffer and a STENCIL_INDEX8 renderbuffer\n * const attachments = [\n * { format: RGB565, mag: NEAREST },\n * { format: STENCIL_INDEX8 },\n * ]\n * const fbi = twgl.createFramebufferInfo(gl, attachments);\n *\n * Passing in a specific size\n *\n * const width = 256;\n * const height = 256;\n * const fbi = twgl.createFramebufferInfo(gl, attachments, width, height);\n *\n * **Note!!** It is up to you to check if the framebuffer is renderable by calling `gl.checkFramebufferStatus`.\n * [WebGL1 only guarantees 3 combinations of attachments work](https://www.khronos.org/registry/webgl/specs/latest/1.0/#6.6).\n *\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {module:twgl.AttachmentOptions[]} [attachments] which attachments to create. If not provided the default is a framebuffer with an\n * `RGBA`, `UNSIGNED_BYTE` texture `COLOR_ATTACHMENT0` and a `DEPTH_STENCIL` renderbuffer `DEPTH_STENCIL_ATTACHMENT`.\n * @param {number} [width] the width for the attachments. Default = size of drawingBuffer\n * @param {number} [height] the height for the attachments. Default = size of drawingBuffer\n * @return {module:twgl.FramebufferInfo} the framebuffer and attachments.\n * @memberOf module:twgl/framebuffers\n */\nfunction createFramebufferInfo(gl, attachments, width, height) {\n const target = FRAMEBUFFER;\n const fb = gl.createFramebuffer();\n gl.bindFramebuffer(target, fb);\n width = width || gl.drawingBufferWidth;\n height = height || gl.drawingBufferHeight;\n attachments = attachments || defaultAttachments;\n let colorAttachmentCount = 0;\n const framebufferInfo = {\n framebuffer: fb,\n attachments: [],\n width: width,\n height: height,\n };\n attachments.forEach(function(attachmentOptions) {\n let attachment = attachmentOptions.attachment;\n const format = attachmentOptions.format;\n let attachmentPoint = getAttachmentPointForFormat(format);\n if (!attachmentPoint) {\n attachmentPoint = COLOR_ATTACHMENT0 + colorAttachmentCount++;\n }\n if (!attachment) {\n if (isRenderbufferFormat(format)) {\n attachment = gl.createRenderbuffer();\n gl.bindRenderbuffer(RENDERBUFFER, attachment);\n gl.renderbufferStorage(RENDERBUFFER, format, width, height);\n } else {\n const textureOptions = Object.assign({}, attachmentOptions);\n textureOptions.width = width;\n textureOptions.height = height;\n if (textureOptions.auto === undefined) {\n textureOptions.auto = false;\n textureOptions.min = textureOptions.min || textureOptions.minMag || LINEAR;\n textureOptions.mag = textureOptions.mag || textureOptions.minMag || LINEAR;\n textureOptions.wrapS = textureOptions.wrapS || textureOptions.wrap || CLAMP_TO_EDGE;\n textureOptions.wrapT = textureOptions.wrapT || textureOptions.wrap || CLAMP_TO_EDGE;\n }\n attachment = textures.createTexture(gl, textureOptions);\n }\n }\n if (helper.isRenderbuffer(gl, attachment)) {\n gl.framebufferRenderbuffer(target, attachmentPoint, RENDERBUFFER, attachment);\n } else if (helper.isTexture(gl, attachment)) {\n if (attachmentOptions.layer !== undefined) {\n gl.framebufferTextureLayer(\n target,\n attachmentPoint,\n attachment,\n attachmentOptions.level || 0,\n attachmentOptions.layer);\n } else {\n gl.framebufferTexture2D(\n target,\n attachmentPoint,\n attachmentOptions.texTarget || TEXTURE_2D,\n attachment,\n attachmentOptions.level || 0);\n }\n } else {\n throw new Error('unknown attachment type');\n }\n framebufferInfo.attachments.push(attachment);\n });\n return framebufferInfo;\n}\n\n/**\n * Resizes the attachments of a framebuffer.\n *\n * You need to pass in the same `attachments` as you passed in {@link module:twgl.createFramebufferInfo}\n * because TWGL has no idea the format/type of each attachment.\n *\n * The simplest usage\n *\n * // create an RGBA/UNSIGNED_BYTE texture and DEPTH_STENCIL renderbuffer\n * const fbi = twgl.createFramebufferInfo(gl);\n *\n * ...\n *\n * function render() {\n * if (twgl.resizeCanvasToDisplaySize(gl.canvas)) {\n * // resize the attachments\n * twgl.resizeFramebufferInfo(gl, fbi);\n * }\n *\n * More complex usage\n *\n * // create an RGB565 renderbuffer and a STENCIL_INDEX8 renderbuffer\n * const attachments = [\n * { format: RGB565, mag: NEAREST },\n * { format: STENCIL_INDEX8 },\n * ]\n * const fbi = twgl.createFramebufferInfo(gl, attachments);\n *\n * ...\n *\n * function render() {\n * if (twgl.resizeCanvasToDisplaySize(gl.canvas)) {\n * // resize the attachments to match\n * twgl.resizeFramebufferInfo(gl, fbi, attachments);\n * }\n *\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {module:twgl.FramebufferInfo} framebufferInfo a framebufferInfo as returned from {@link module:twgl.createFramebufferInfo}.\n * @param {module:twgl.AttachmentOptions[]} [attachments] the same attachments options as passed to {@link module:twgl.createFramebufferInfo}.\n * @param {number} [width] the width for the attachments. Default = size of drawingBuffer\n * @param {number} [height] the height for the attachments. Default = size of drawingBuffer\n * @memberOf module:twgl/framebuffers\n */\nfunction resizeFramebufferInfo(gl, framebufferInfo, attachments, width, height) {\n width = width || gl.drawingBufferWidth;\n height = height || gl.drawingBufferHeight;\n framebufferInfo.width = width;\n framebufferInfo.height = height;\n attachments = attachments || defaultAttachments;\n attachments.forEach(function(attachmentOptions, ndx) {\n const attachment = framebufferInfo.attachments[ndx];\n const format = attachmentOptions.format;\n if (helper.isRenderbuffer(gl, attachment)) {\n gl.bindRenderbuffer(RENDERBUFFER, attachment);\n gl.renderbufferStorage(RENDERBUFFER, format, width, height);\n } else if (helper.isTexture(gl, attachment)) {\n textures.resizeTexture(gl, attachment, attachmentOptions, width, height);\n } else {\n throw new Error('unknown attachment type');\n }\n });\n}\n\n/**\n * Binds a framebuffer\n *\n * This function pretty much solely exists because I spent hours\n * trying to figure out why something I wrote wasn't working only\n * to realize I forget to set the viewport dimensions.\n * My hope is this function will fix that.\n *\n * It is effectively the same as\n *\n * gl.bindFramebuffer(gl.FRAMEBUFFER, someFramebufferInfo.framebuffer);\n * gl.viewport(0, 0, someFramebufferInfo.width, someFramebufferInfo.height);\n *\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {module:twgl.FramebufferInfo|null} [framebufferInfo] a framebufferInfo as returned from {@link module:twgl.createFramebufferInfo}.\n * If falsy will bind the canvas.\n * @param {number} [target] The target. If not passed `gl.FRAMEBUFFER` will be used.\n * @memberOf module:twgl/framebuffers\n */\n\nfunction bindFramebufferInfo(gl, framebufferInfo, target) {\n target = target || FRAMEBUFFER;\n if (framebufferInfo) {\n gl.bindFramebuffer(target, framebufferInfo.framebuffer);\n gl.viewport(0, 0, framebufferInfo.width, framebufferInfo.height);\n } else {\n gl.bindFramebuffer(target, null);\n gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);\n }\n}\n\nexport {\n bindFramebufferInfo,\n createFramebufferInfo,\n resizeFramebufferInfo,\n};\n\n\n","/*\n * Copyright 2019 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n\n/* eslint no-console: \"off\" */\n\n/**\n * Copy named properties\n *\n * @param {string[]} names names of properties to copy\n * @param {object} src object to copy properties from\n * @param {object} dst object to copy properties to\n * @private\n */\nfunction copyNamedProperties(names, src, dst) {\n names.forEach(function(name) {\n const value = src[name];\n if (value !== undefined) {\n dst[name] = value;\n }\n });\n}\n\n/**\n * Copies properties from source to dest only if a matching key is in dest\n *\n * @param {Object.} src the source\n * @param {Object.} dst the dest\n * @private\n */\nfunction copyExistingProperties(src, dst) {\n Object.keys(dst).forEach(function(key) {\n if (dst.hasOwnProperty(key) && src.hasOwnProperty(key)) { /* eslint no-prototype-builtins: 0 */\n dst[key] = src[key];\n }\n });\n}\n\nfunction error(...args) {\n console.error(...args);\n}\n\nfunction warn(...args) {\n console.warn(...args);\n}\n\nfunction isBuffer(gl, t) {\n return typeof WebGLBuffer !== 'undefined' && t instanceof WebGLBuffer;\n}\n\nfunction isRenderbuffer(gl, t) {\n return typeof WebGLRenderbuffer !== 'undefined' && t instanceof WebGLRenderbuffer;\n}\n\nfunction isShader(gl, t) {\n return typeof WebGLShader !== 'undefined' && t instanceof WebGLShader;\n}\n\nfunction isTexture(gl, t) {\n return typeof WebGLTexture !== 'undefined' && t instanceof WebGLTexture;\n}\n\nfunction isSampler(gl, t) {\n return typeof WebGLSampler !== 'undefined' && t instanceof WebGLSampler;\n}\n\nexport {\n copyExistingProperties,\n copyNamedProperties,\n error,\n warn,\n isBuffer,\n isRenderbuffer,\n isShader,\n isTexture,\n isSampler,\n};\n\n","/*\n * Copyright 2019 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n\nimport * as v3 from './v3.js';\n\n/**\n * 4x4 Matrix math math functions.\n *\n * Almost all functions take an optional `dst` argument. If it is not passed in the\n * functions will create a new matrix. In other words you can do this\n *\n * const mat = m4.translation([1, 2, 3]); // Creates a new translation matrix\n *\n * or\n *\n * const mat = m4.create();\n * m4.translation([1, 2, 3], mat); // Puts translation matrix in mat.\n *\n * The first style is often easier but depending on where it's used it generates garbage where\n * as there is almost never allocation with the second style.\n *\n * It is always save to pass any matrix as the destination. So for example\n *\n * const mat = m4.identity();\n * const trans = m4.translation([1, 2, 3]);\n * m4.multiply(mat, trans, mat); // Multiplies mat * trans and puts result in mat.\n *\n * @module twgl/m4\n */\nlet MatType = Float32Array;\n\n/**\n * A JavaScript array with 16 values or a Float32Array with 16 values.\n * When created by the library will create the default type which is `Float32Array`\n * but can be set by calling {@link module:twgl/m4.setDefaultType}.\n * @typedef {(number[]|Float32Array)} Mat4\n * @memberOf module:twgl/m4\n */\n\n/**\n * Sets the type this library creates for a Mat4\n * @param {constructor} ctor the constructor for the type. Either `Float32Array` or `Array`\n * @return {constructor} previous constructor for Mat4\n * @memberOf module:twgl/m4\n */\nfunction setDefaultType(ctor) {\n const oldType = MatType;\n MatType = ctor;\n return oldType;\n}\n\n/**\n * Negates a matrix.\n * @param {module:twgl/m4.Mat4} m The matrix.\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} -m.\n * @memberOf module:twgl/m4\n */\nfunction negate(m, dst) {\n dst = dst || new MatType(16);\n\n dst[ 0] = -m[ 0];\n dst[ 1] = -m[ 1];\n dst[ 2] = -m[ 2];\n dst[ 3] = -m[ 3];\n dst[ 4] = -m[ 4];\n dst[ 5] = -m[ 5];\n dst[ 6] = -m[ 6];\n dst[ 7] = -m[ 7];\n dst[ 8] = -m[ 8];\n dst[ 9] = -m[ 9];\n dst[10] = -m[10];\n dst[11] = -m[11];\n dst[12] = -m[12];\n dst[13] = -m[13];\n dst[14] = -m[14];\n dst[15] = -m[15];\n\n return dst;\n}\n\n/**\n * Copies a matrix.\n * @param {module:twgl/m4.Mat4} m The matrix.\n * @param {module:twgl/m4.Mat4} [dst] The matrix. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} A copy of m.\n * @memberOf module:twgl/m4\n */\nfunction copy(m, dst) {\n dst = dst || new MatType(16);\n\n dst[ 0] = m[ 0];\n dst[ 1] = m[ 1];\n dst[ 2] = m[ 2];\n dst[ 3] = m[ 3];\n dst[ 4] = m[ 4];\n dst[ 5] = m[ 5];\n dst[ 6] = m[ 6];\n dst[ 7] = m[ 7];\n dst[ 8] = m[ 8];\n dst[ 9] = m[ 9];\n dst[10] = m[10];\n dst[11] = m[11];\n dst[12] = m[12];\n dst[13] = m[13];\n dst[14] = m[14];\n dst[15] = m[15];\n\n return dst;\n}\n\n/**\n * Creates an n-by-n identity matrix.\n *\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} An n-by-n identity matrix.\n * @memberOf module:twgl/m4\n */\nfunction identity(dst) {\n dst = dst || new MatType(16);\n\n dst[ 0] = 1;\n dst[ 1] = 0;\n dst[ 2] = 0;\n dst[ 3] = 0;\n dst[ 4] = 0;\n dst[ 5] = 1;\n dst[ 6] = 0;\n dst[ 7] = 0;\n dst[ 8] = 0;\n dst[ 9] = 0;\n dst[10] = 1;\n dst[11] = 0;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = 0;\n dst[15] = 1;\n\n return dst;\n}\n\n/**\n * Takes the transpose of a matrix.\n * @param {module:twgl/m4.Mat4} m The matrix.\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The transpose of m.\n * @memberOf module:twgl/m4\n */\n function transpose(m, dst) {\n dst = dst || new MatType(16);\n if (dst === m) {\n let t;\n\n t = m[1];\n m[1] = m[4];\n m[4] = t;\n\n t = m[2];\n m[2] = m[8];\n m[8] = t;\n\n t = m[3];\n m[3] = m[12];\n m[12] = t;\n\n t = m[6];\n m[6] = m[9];\n m[9] = t;\n\n t = m[7];\n m[7] = m[13];\n m[13] = t;\n\n t = m[11];\n m[11] = m[14];\n m[14] = t;\n return dst;\n }\n\n const m00 = m[0 * 4 + 0];\n const m01 = m[0 * 4 + 1];\n const m02 = m[0 * 4 + 2];\n const m03 = m[0 * 4 + 3];\n const m10 = m[1 * 4 + 0];\n const m11 = m[1 * 4 + 1];\n const m12 = m[1 * 4 + 2];\n const m13 = m[1 * 4 + 3];\n const m20 = m[2 * 4 + 0];\n const m21 = m[2 * 4 + 1];\n const m22 = m[2 * 4 + 2];\n const m23 = m[2 * 4 + 3];\n const m30 = m[3 * 4 + 0];\n const m31 = m[3 * 4 + 1];\n const m32 = m[3 * 4 + 2];\n const m33 = m[3 * 4 + 3];\n\n dst[ 0] = m00;\n dst[ 1] = m10;\n dst[ 2] = m20;\n dst[ 3] = m30;\n dst[ 4] = m01;\n dst[ 5] = m11;\n dst[ 6] = m21;\n dst[ 7] = m31;\n dst[ 8] = m02;\n dst[ 9] = m12;\n dst[10] = m22;\n dst[11] = m32;\n dst[12] = m03;\n dst[13] = m13;\n dst[14] = m23;\n dst[15] = m33;\n\n return dst;\n}\n\n/**\n * Computes the inverse of a 4-by-4 matrix.\n * @param {module:twgl/m4.Mat4} m The matrix.\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The inverse of m.\n * @memberOf module:twgl/m4\n */\nfunction inverse(m, dst) {\n dst = dst || new MatType(16);\n\n const m00 = m[0 * 4 + 0];\n const m01 = m[0 * 4 + 1];\n const m02 = m[0 * 4 + 2];\n const m03 = m[0 * 4 + 3];\n const m10 = m[1 * 4 + 0];\n const m11 = m[1 * 4 + 1];\n const m12 = m[1 * 4 + 2];\n const m13 = m[1 * 4 + 3];\n const m20 = m[2 * 4 + 0];\n const m21 = m[2 * 4 + 1];\n const m22 = m[2 * 4 + 2];\n const m23 = m[2 * 4 + 3];\n const m30 = m[3 * 4 + 0];\n const m31 = m[3 * 4 + 1];\n const m32 = m[3 * 4 + 2];\n const m33 = m[3 * 4 + 3];\n const tmp_0 = m22 * m33;\n const tmp_1 = m32 * m23;\n const tmp_2 = m12 * m33;\n const tmp_3 = m32 * m13;\n const tmp_4 = m12 * m23;\n const tmp_5 = m22 * m13;\n const tmp_6 = m02 * m33;\n const tmp_7 = m32 * m03;\n const tmp_8 = m02 * m23;\n const tmp_9 = m22 * m03;\n const tmp_10 = m02 * m13;\n const tmp_11 = m12 * m03;\n const tmp_12 = m20 * m31;\n const tmp_13 = m30 * m21;\n const tmp_14 = m10 * m31;\n const tmp_15 = m30 * m11;\n const tmp_16 = m10 * m21;\n const tmp_17 = m20 * m11;\n const tmp_18 = m00 * m31;\n const tmp_19 = m30 * m01;\n const tmp_20 = m00 * m21;\n const tmp_21 = m20 * m01;\n const tmp_22 = m00 * m11;\n const tmp_23 = m10 * m01;\n\n const t0 = (tmp_0 * m11 + tmp_3 * m21 + tmp_4 * m31) -\n (tmp_1 * m11 + tmp_2 * m21 + tmp_5 * m31);\n const t1 = (tmp_1 * m01 + tmp_6 * m21 + tmp_9 * m31) -\n (tmp_0 * m01 + tmp_7 * m21 + tmp_8 * m31);\n const t2 = (tmp_2 * m01 + tmp_7 * m11 + tmp_10 * m31) -\n (tmp_3 * m01 + tmp_6 * m11 + tmp_11 * m31);\n const t3 = (tmp_5 * m01 + tmp_8 * m11 + tmp_11 * m21) -\n (tmp_4 * m01 + tmp_9 * m11 + tmp_10 * m21);\n\n const d = 1.0 / (m00 * t0 + m10 * t1 + m20 * t2 + m30 * t3);\n\n dst[ 0] = d * t0;\n dst[ 1] = d * t1;\n dst[ 2] = d * t2;\n dst[ 3] = d * t3;\n dst[ 4] = d * ((tmp_1 * m10 + tmp_2 * m20 + tmp_5 * m30) -\n (tmp_0 * m10 + tmp_3 * m20 + tmp_4 * m30));\n dst[ 5] = d * ((tmp_0 * m00 + tmp_7 * m20 + tmp_8 * m30) -\n (tmp_1 * m00 + tmp_6 * m20 + tmp_9 * m30));\n dst[ 6] = d * ((tmp_3 * m00 + tmp_6 * m10 + tmp_11 * m30) -\n (tmp_2 * m00 + tmp_7 * m10 + tmp_10 * m30));\n dst[ 7] = d * ((tmp_4 * m00 + tmp_9 * m10 + tmp_10 * m20) -\n (tmp_5 * m00 + tmp_8 * m10 + tmp_11 * m20));\n dst[ 8] = d * ((tmp_12 * m13 + tmp_15 * m23 + tmp_16 * m33) -\n (tmp_13 * m13 + tmp_14 * m23 + tmp_17 * m33));\n dst[ 9] = d * ((tmp_13 * m03 + tmp_18 * m23 + tmp_21 * m33) -\n (tmp_12 * m03 + tmp_19 * m23 + tmp_20 * m33));\n dst[10] = d * ((tmp_14 * m03 + tmp_19 * m13 + tmp_22 * m33) -\n (tmp_15 * m03 + tmp_18 * m13 + tmp_23 * m33));\n dst[11] = d * ((tmp_17 * m03 + tmp_20 * m13 + tmp_23 * m23) -\n (tmp_16 * m03 + tmp_21 * m13 + tmp_22 * m23));\n dst[12] = d * ((tmp_14 * m22 + tmp_17 * m32 + tmp_13 * m12) -\n (tmp_16 * m32 + tmp_12 * m12 + tmp_15 * m22));\n dst[13] = d * ((tmp_20 * m32 + tmp_12 * m02 + tmp_19 * m22) -\n (tmp_18 * m22 + tmp_21 * m32 + tmp_13 * m02));\n dst[14] = d * ((tmp_18 * m12 + tmp_23 * m32 + tmp_15 * m02) -\n (tmp_22 * m32 + tmp_14 * m02 + tmp_19 * m12));\n dst[15] = d * ((tmp_22 * m22 + tmp_16 * m02 + tmp_21 * m12) -\n (tmp_20 * m12 + tmp_23 * m22 + tmp_17 * m02));\n\n return dst;\n}\n\n/**\n * Multiplies two 4-by-4 matrices with a on the left and b on the right\n * @param {module:twgl/m4.Mat4} a The matrix on the left.\n * @param {module:twgl/m4.Mat4} b The matrix on the right.\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The matrix product of a and b.\n * @memberOf module:twgl/m4\n */\nfunction multiply(a, b, dst) {\n dst = dst || new MatType(16);\n\n const a00 = a[0];\n const a01 = a[1];\n const a02 = a[2];\n const a03 = a[3];\n const a10 = a[ 4 + 0];\n const a11 = a[ 4 + 1];\n const a12 = a[ 4 + 2];\n const a13 = a[ 4 + 3];\n const a20 = a[ 8 + 0];\n const a21 = a[ 8 + 1];\n const a22 = a[ 8 + 2];\n const a23 = a[ 8 + 3];\n const a30 = a[12 + 0];\n const a31 = a[12 + 1];\n const a32 = a[12 + 2];\n const a33 = a[12 + 3];\n const b00 = b[0];\n const b01 = b[1];\n const b02 = b[2];\n const b03 = b[3];\n const b10 = b[ 4 + 0];\n const b11 = b[ 4 + 1];\n const b12 = b[ 4 + 2];\n const b13 = b[ 4 + 3];\n const b20 = b[ 8 + 0];\n const b21 = b[ 8 + 1];\n const b22 = b[ 8 + 2];\n const b23 = b[ 8 + 3];\n const b30 = b[12 + 0];\n const b31 = b[12 + 1];\n const b32 = b[12 + 2];\n const b33 = b[12 + 3];\n\n dst[ 0] = a00 * b00 + a10 * b01 + a20 * b02 + a30 * b03;\n dst[ 1] = a01 * b00 + a11 * b01 + a21 * b02 + a31 * b03;\n dst[ 2] = a02 * b00 + a12 * b01 + a22 * b02 + a32 * b03;\n dst[ 3] = a03 * b00 + a13 * b01 + a23 * b02 + a33 * b03;\n dst[ 4] = a00 * b10 + a10 * b11 + a20 * b12 + a30 * b13;\n dst[ 5] = a01 * b10 + a11 * b11 + a21 * b12 + a31 * b13;\n dst[ 6] = a02 * b10 + a12 * b11 + a22 * b12 + a32 * b13;\n dst[ 7] = a03 * b10 + a13 * b11 + a23 * b12 + a33 * b13;\n dst[ 8] = a00 * b20 + a10 * b21 + a20 * b22 + a30 * b23;\n dst[ 9] = a01 * b20 + a11 * b21 + a21 * b22 + a31 * b23;\n dst[10] = a02 * b20 + a12 * b21 + a22 * b22 + a32 * b23;\n dst[11] = a03 * b20 + a13 * b21 + a23 * b22 + a33 * b23;\n dst[12] = a00 * b30 + a10 * b31 + a20 * b32 + a30 * b33;\n dst[13] = a01 * b30 + a11 * b31 + a21 * b32 + a31 * b33;\n dst[14] = a02 * b30 + a12 * b31 + a22 * b32 + a32 * b33;\n dst[15] = a03 * b30 + a13 * b31 + a23 * b32 + a33 * b33;\n\n return dst;\n}\n\n/**\n * Sets the translation component of a 4-by-4 matrix to the given\n * vector.\n * @param {module:twgl/m4.Mat4} a The matrix.\n * @param {module:twgl/v3.Vec3} v The vector.\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The matrix with translation set.\n * @memberOf module:twgl/m4\n */\nfunction setTranslation(a, v, dst) {\n dst = dst || identity();\n if (a !== dst) {\n dst[ 0] = a[ 0];\n dst[ 1] = a[ 1];\n dst[ 2] = a[ 2];\n dst[ 3] = a[ 3];\n dst[ 4] = a[ 4];\n dst[ 5] = a[ 5];\n dst[ 6] = a[ 6];\n dst[ 7] = a[ 7];\n dst[ 8] = a[ 8];\n dst[ 9] = a[ 9];\n dst[10] = a[10];\n dst[11] = a[11];\n }\n dst[12] = v[0];\n dst[13] = v[1];\n dst[14] = v[2];\n dst[15] = 1;\n return dst;\n}\n\n/**\n * Returns the translation component of a 4-by-4 matrix as a vector with 3\n * entries.\n * @param {module:twgl/m4.Mat4} m The matrix.\n * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not passed a new one is created.\n * @return {module:twgl/v3.Vec3} The translation component of m.\n * @memberOf module:twgl/m4\n */\nfunction getTranslation(m, dst) {\n dst = dst || v3.create();\n dst[0] = m[12];\n dst[1] = m[13];\n dst[2] = m[14];\n return dst;\n}\n\n/**\n * Returns an axis of a 4x4 matrix as a vector with 3 entries\n * @param {module:twgl/m4.Mat4} m The matrix.\n * @param {number} axis The axis 0 = x, 1 = y, 2 = z;\n * @return {module:twgl/v3.Vec3} [dst] vector.\n * @return {module:twgl/v3.Vec3} The axis component of m.\n * @memberOf module:twgl/m4\n */\nfunction getAxis(m, axis, dst) {\n dst = dst || v3.create();\n const off = axis * 4;\n dst[0] = m[off + 0];\n dst[1] = m[off + 1];\n dst[2] = m[off + 2];\n return dst;\n}\n\n/**\n * Sets an axis of a 4x4 matrix as a vector with 3 entries\n * @param {module:twgl/m4.Mat4} m The matrix.\n * @param {module:twgl/v3.Vec3} v the axis vector\n * @param {number} axis The axis 0 = x, 1 = y, 2 = z;\n * @param {module:twgl/m4.Mat4} [dst] The matrix to set. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The matrix with axis set.\n * @memberOf module:twgl/m4\n */\nfunction setAxis(a, v, axis, dst) {\n if (dst !== a) {\n dst = copy(a, dst);\n }\n const off = axis * 4;\n dst[off + 0] = v[0];\n dst[off + 1] = v[1];\n dst[off + 2] = v[2];\n return dst;\n}\n\n/**\n * Computes a 4-by-4 perspective transformation matrix given the angular height\n * of the frustum, the aspect ratio, and the near and far clipping planes. The\n * arguments define a frustum extending in the negative z direction. The given\n * angle is the vertical angle of the frustum, and the horizontal angle is\n * determined to produce the given aspect ratio. The arguments near and far are\n * the distances to the near and far clipping planes. Note that near and far\n * are not z coordinates, but rather they are distances along the negative\n * z-axis. The matrix generated sends the viewing frustum to the unit box.\n * We assume a unit box extending from -1 to 1 in the x and y dimensions and\n * from 0 to 1 in the z dimension.\n * @param {number} fieldOfViewYInRadians The camera angle from top to bottom (in radians).\n * @param {number} aspect The aspect ratio width / height.\n * @param {number} zNear The depth (negative z coordinate)\n * of the near clipping plane.\n * @param {number} zFar The depth (negative z coordinate)\n * of the far clipping plane.\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The perspective matrix.\n * @memberOf module:twgl/m4\n */\nfunction perspective(fieldOfViewYInRadians, aspect, zNear, zFar, dst) {\n dst = dst || new MatType(16);\n\n const f = Math.tan(Math.PI * 0.5 - 0.5 * fieldOfViewYInRadians);\n const rangeInv = 1.0 / (zNear - zFar);\n\n dst[0] = f / aspect;\n dst[1] = 0;\n dst[2] = 0;\n dst[3] = 0;\n\n dst[4] = 0;\n dst[5] = f;\n dst[6] = 0;\n dst[7] = 0;\n\n dst[8] = 0;\n dst[9] = 0;\n dst[10] = (zNear + zFar) * rangeInv;\n dst[11] = -1;\n\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = zNear * zFar * rangeInv * 2;\n dst[15] = 0;\n\n return dst;\n}\n\n/**\n * Computes a 4-by-4 orthogonal transformation matrix given the left, right,\n * bottom, and top dimensions of the near clipping plane as well as the\n * near and far clipping plane distances.\n * @param {number} left Left side of the near clipping plane viewport.\n * @param {number} right Right side of the near clipping plane viewport.\n * @param {number} bottom Bottom of the near clipping plane viewport.\n * @param {number} top Top of the near clipping plane viewport.\n * @param {number} near The depth (negative z coordinate)\n * of the near clipping plane.\n * @param {number} far The depth (negative z coordinate)\n * of the far clipping plane.\n * @param {module:twgl/m4.Mat4} [dst] Output matrix. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The perspective matrix.\n * @memberOf module:twgl/m4\n */\nfunction ortho(left, right, bottom, top, near, far, dst) {\n dst = dst || new MatType(16);\n\n dst[0] = 2 / (right - left);\n dst[1] = 0;\n dst[2] = 0;\n dst[3] = 0;\n\n dst[4] = 0;\n dst[5] = 2 / (top - bottom);\n dst[6] = 0;\n dst[7] = 0;\n\n dst[8] = 0;\n dst[9] = 0;\n dst[10] = 2 / (near - far);\n dst[11] = 0;\n\n dst[12] = (right + left) / (left - right);\n dst[13] = (top + bottom) / (bottom - top);\n dst[14] = (far + near) / (near - far);\n dst[15] = 1;\n\n return dst;\n}\n\n/**\n * Computes a 4-by-4 perspective transformation matrix given the left, right,\n * top, bottom, near and far clipping planes. The arguments define a frustum\n * extending in the negative z direction. The arguments near and far are the\n * distances to the near and far clipping planes. Note that near and far are not\n * z coordinates, but rather they are distances along the negative z-axis. The\n * matrix generated sends the viewing frustum to the unit box. We assume a unit\n * box extending from -1 to 1 in the x and y dimensions and from 0 to 1 in the z\n * dimension.\n * @param {number} left The x coordinate of the left plane of the box.\n * @param {number} right The x coordinate of the right plane of the box.\n * @param {number} bottom The y coordinate of the bottom plane of the box.\n * @param {number} top The y coordinate of the right plane of the box.\n * @param {number} near The negative z coordinate of the near plane of the box.\n * @param {number} far The negative z coordinate of the far plane of the box.\n * @param {module:twgl/m4.Mat4} [dst] Output matrix. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The perspective projection matrix.\n * @memberOf module:twgl/m4\n */\nfunction frustum(left, right, bottom, top, near, far, dst) {\n dst = dst || new MatType(16);\n\n const dx = (right - left);\n const dy = (top - bottom);\n const dz = (near - far);\n\n dst[ 0] = 2 * near / dx;\n dst[ 1] = 0;\n dst[ 2] = 0;\n dst[ 3] = 0;\n dst[ 4] = 0;\n dst[ 5] = 2 * near / dy;\n dst[ 6] = 0;\n dst[ 7] = 0;\n dst[ 8] = (left + right) / dx;\n dst[ 9] = (top + bottom) / dy;\n dst[10] = far / dz;\n dst[11] = -1;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = near * far / dz;\n dst[15] = 0;\n\n return dst;\n}\n\nlet xAxis;\nlet yAxis;\nlet zAxis;\n\n/**\n * Computes a 4-by-4 look-at transformation.\n *\n * This is a matrix which positions the camera itself. If you want\n * a view matrix (a matrix which moves things in front of the camera)\n * take the inverse of this.\n *\n * @param {module:twgl/v3.Vec3} eye The position of the eye.\n * @param {module:twgl/v3.Vec3} target The position meant to be viewed.\n * @param {module:twgl/v3.Vec3} up A vector pointing up.\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The look-at matrix.\n * @memberOf module:twgl/m4\n */\nfunction lookAt(eye, target, up, dst) {\n dst = dst || new MatType(16);\n\n xAxis = xAxis || v3.create();\n yAxis = yAxis || v3.create();\n zAxis = zAxis || v3.create();\n\n v3.normalize(\n v3.subtract(eye, target, zAxis), zAxis);\n v3.normalize(v3.cross(up, zAxis, xAxis), xAxis);\n v3.normalize(v3.cross(zAxis, xAxis, yAxis), yAxis);\n\n dst[ 0] = xAxis[0];\n dst[ 1] = xAxis[1];\n dst[ 2] = xAxis[2];\n dst[ 3] = 0;\n dst[ 4] = yAxis[0];\n dst[ 5] = yAxis[1];\n dst[ 6] = yAxis[2];\n dst[ 7] = 0;\n dst[ 8] = zAxis[0];\n dst[ 9] = zAxis[1];\n dst[10] = zAxis[2];\n dst[11] = 0;\n dst[12] = eye[0];\n dst[13] = eye[1];\n dst[14] = eye[2];\n dst[15] = 1;\n\n return dst;\n}\n\n/**\n * Creates a 4-by-4 matrix which translates by the given vector v.\n * @param {module:twgl/v3.Vec3} v The vector by\n * which to translate.\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The translation matrix.\n * @memberOf module:twgl/m4\n */\nfunction translation(v, dst) {\n dst = dst || new MatType(16);\n\n dst[ 0] = 1;\n dst[ 1] = 0;\n dst[ 2] = 0;\n dst[ 3] = 0;\n dst[ 4] = 0;\n dst[ 5] = 1;\n dst[ 6] = 0;\n dst[ 7] = 0;\n dst[ 8] = 0;\n dst[ 9] = 0;\n dst[10] = 1;\n dst[11] = 0;\n dst[12] = v[0];\n dst[13] = v[1];\n dst[14] = v[2];\n dst[15] = 1;\n return dst;\n}\n\n/**\n * Translates the given 4-by-4 matrix by the given vector v.\n * @param {module:twgl/m4.Mat4} m The matrix.\n * @param {module:twgl/v3.Vec3} v The vector by\n * which to translate.\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The translated matrix.\n * @memberOf module:twgl/m4\n */\nfunction translate(m, v, dst) {\n dst = dst || new MatType(16);\n\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n const m00 = m[0];\n const m01 = m[1];\n const m02 = m[2];\n const m03 = m[3];\n const m10 = m[1 * 4 + 0];\n const m11 = m[1 * 4 + 1];\n const m12 = m[1 * 4 + 2];\n const m13 = m[1 * 4 + 3];\n const m20 = m[2 * 4 + 0];\n const m21 = m[2 * 4 + 1];\n const m22 = m[2 * 4 + 2];\n const m23 = m[2 * 4 + 3];\n const m30 = m[3 * 4 + 0];\n const m31 = m[3 * 4 + 1];\n const m32 = m[3 * 4 + 2];\n const m33 = m[3 * 4 + 3];\n\n if (m !== dst) {\n dst[ 0] = m00;\n dst[ 1] = m01;\n dst[ 2] = m02;\n dst[ 3] = m03;\n dst[ 4] = m10;\n dst[ 5] = m11;\n dst[ 6] = m12;\n dst[ 7] = m13;\n dst[ 8] = m20;\n dst[ 9] = m21;\n dst[10] = m22;\n dst[11] = m23;\n }\n\n dst[12] = m00 * v0 + m10 * v1 + m20 * v2 + m30;\n dst[13] = m01 * v0 + m11 * v1 + m21 * v2 + m31;\n dst[14] = m02 * v0 + m12 * v1 + m22 * v2 + m32;\n dst[15] = m03 * v0 + m13 * v1 + m23 * v2 + m33;\n\n return dst;\n}\n\n/**\n * Creates a 4-by-4 matrix which rotates around the x-axis by the given angle.\n * @param {number} angleInRadians The angle by which to rotate (in radians).\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The rotation matrix.\n * @memberOf module:twgl/m4\n */\nfunction rotationX(angleInRadians, dst) {\n dst = dst || new MatType(16);\n\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n\n dst[ 0] = 1;\n dst[ 1] = 0;\n dst[ 2] = 0;\n dst[ 3] = 0;\n dst[ 4] = 0;\n dst[ 5] = c;\n dst[ 6] = s;\n dst[ 7] = 0;\n dst[ 8] = 0;\n dst[ 9] = -s;\n dst[10] = c;\n dst[11] = 0;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = 0;\n dst[15] = 1;\n\n return dst;\n}\n\n/**\n * Rotates the given 4-by-4 matrix around the x-axis by the given\n * angle.\n * @param {module:twgl/m4.Mat4} m The matrix.\n * @param {number} angleInRadians The angle by which to rotate (in radians).\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The rotated matrix.\n * @memberOf module:twgl/m4\n */\nfunction rotateX(m, angleInRadians, dst) {\n dst = dst || new MatType(16);\n\n const m10 = m[4];\n const m11 = m[5];\n const m12 = m[6];\n const m13 = m[7];\n const m20 = m[8];\n const m21 = m[9];\n const m22 = m[10];\n const m23 = m[11];\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n\n dst[4] = c * m10 + s * m20;\n dst[5] = c * m11 + s * m21;\n dst[6] = c * m12 + s * m22;\n dst[7] = c * m13 + s * m23;\n dst[8] = c * m20 - s * m10;\n dst[9] = c * m21 - s * m11;\n dst[10] = c * m22 - s * m12;\n dst[11] = c * m23 - s * m13;\n\n if (m !== dst) {\n dst[ 0] = m[ 0];\n dst[ 1] = m[ 1];\n dst[ 2] = m[ 2];\n dst[ 3] = m[ 3];\n dst[12] = m[12];\n dst[13] = m[13];\n dst[14] = m[14];\n dst[15] = m[15];\n }\n\n return dst;\n}\n\n/**\n * Creates a 4-by-4 matrix which rotates around the y-axis by the given angle.\n * @param {number} angleInRadians The angle by which to rotate (in radians).\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The rotation matrix.\n * @memberOf module:twgl/m4\n */\nfunction rotationY(angleInRadians, dst) {\n dst = dst || new MatType(16);\n\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n\n dst[ 0] = c;\n dst[ 1] = 0;\n dst[ 2] = -s;\n dst[ 3] = 0;\n dst[ 4] = 0;\n dst[ 5] = 1;\n dst[ 6] = 0;\n dst[ 7] = 0;\n dst[ 8] = s;\n dst[ 9] = 0;\n dst[10] = c;\n dst[11] = 0;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = 0;\n dst[15] = 1;\n\n return dst;\n}\n\n/**\n * Rotates the given 4-by-4 matrix around the y-axis by the given\n * angle.\n * @param {module:twgl/m4.Mat4} m The matrix.\n * @param {number} angleInRadians The angle by which to rotate (in radians).\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The rotated matrix.\n * @memberOf module:twgl/m4\n */\nfunction rotateY(m, angleInRadians, dst) {\n dst = dst || new MatType(16);\n\n const m00 = m[0 * 4 + 0];\n const m01 = m[0 * 4 + 1];\n const m02 = m[0 * 4 + 2];\n const m03 = m[0 * 4 + 3];\n const m20 = m[2 * 4 + 0];\n const m21 = m[2 * 4 + 1];\n const m22 = m[2 * 4 + 2];\n const m23 = m[2 * 4 + 3];\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n\n dst[ 0] = c * m00 - s * m20;\n dst[ 1] = c * m01 - s * m21;\n dst[ 2] = c * m02 - s * m22;\n dst[ 3] = c * m03 - s * m23;\n dst[ 8] = c * m20 + s * m00;\n dst[ 9] = c * m21 + s * m01;\n dst[10] = c * m22 + s * m02;\n dst[11] = c * m23 + s * m03;\n\n if (m !== dst) {\n dst[ 4] = m[ 4];\n dst[ 5] = m[ 5];\n dst[ 6] = m[ 6];\n dst[ 7] = m[ 7];\n dst[12] = m[12];\n dst[13] = m[13];\n dst[14] = m[14];\n dst[15] = m[15];\n }\n\n return dst;\n}\n\n/**\n * Creates a 4-by-4 matrix which rotates around the z-axis by the given angle.\n * @param {number} angleInRadians The angle by which to rotate (in radians).\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The rotation matrix.\n * @memberOf module:twgl/m4\n */\nfunction rotationZ(angleInRadians, dst) {\n dst = dst || new MatType(16);\n\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n\n dst[ 0] = c;\n dst[ 1] = s;\n dst[ 2] = 0;\n dst[ 3] = 0;\n dst[ 4] = -s;\n dst[ 5] = c;\n dst[ 6] = 0;\n dst[ 7] = 0;\n dst[ 8] = 0;\n dst[ 9] = 0;\n dst[10] = 1;\n dst[11] = 0;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = 0;\n dst[15] = 1;\n\n return dst;\n}\n\n/**\n * Rotates the given 4-by-4 matrix around the z-axis by the given\n * angle.\n * @param {module:twgl/m4.Mat4} m The matrix.\n * @param {number} angleInRadians The angle by which to rotate (in radians).\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The rotated matrix.\n * @memberOf module:twgl/m4\n */\nfunction rotateZ(m, angleInRadians, dst) {\n dst = dst || new MatType(16);\n\n const m00 = m[0 * 4 + 0];\n const m01 = m[0 * 4 + 1];\n const m02 = m[0 * 4 + 2];\n const m03 = m[0 * 4 + 3];\n const m10 = m[1 * 4 + 0];\n const m11 = m[1 * 4 + 1];\n const m12 = m[1 * 4 + 2];\n const m13 = m[1 * 4 + 3];\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n\n dst[ 0] = c * m00 + s * m10;\n dst[ 1] = c * m01 + s * m11;\n dst[ 2] = c * m02 + s * m12;\n dst[ 3] = c * m03 + s * m13;\n dst[ 4] = c * m10 - s * m00;\n dst[ 5] = c * m11 - s * m01;\n dst[ 6] = c * m12 - s * m02;\n dst[ 7] = c * m13 - s * m03;\n\n if (m !== dst) {\n dst[ 8] = m[ 8];\n dst[ 9] = m[ 9];\n dst[10] = m[10];\n dst[11] = m[11];\n dst[12] = m[12];\n dst[13] = m[13];\n dst[14] = m[14];\n dst[15] = m[15];\n }\n\n return dst;\n}\n\n/**\n * Creates a 4-by-4 matrix which rotates around the given axis by the given\n * angle.\n * @param {module:twgl/v3.Vec3} axis The axis\n * about which to rotate.\n * @param {number} angleInRadians The angle by which to rotate (in radians).\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} A matrix which rotates angle radians\n * around the axis.\n * @memberOf module:twgl/m4\n */\nfunction axisRotation(axis, angleInRadians, dst) {\n dst = dst || new MatType(16);\n\n let x = axis[0];\n let y = axis[1];\n let z = axis[2];\n const n = Math.sqrt(x * x + y * y + z * z);\n x /= n;\n y /= n;\n z /= n;\n const xx = x * x;\n const yy = y * y;\n const zz = z * z;\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n const oneMinusCosine = 1 - c;\n\n dst[ 0] = xx + (1 - xx) * c;\n dst[ 1] = x * y * oneMinusCosine + z * s;\n dst[ 2] = x * z * oneMinusCosine - y * s;\n dst[ 3] = 0;\n dst[ 4] = x * y * oneMinusCosine - z * s;\n dst[ 5] = yy + (1 - yy) * c;\n dst[ 6] = y * z * oneMinusCosine + x * s;\n dst[ 7] = 0;\n dst[ 8] = x * z * oneMinusCosine + y * s;\n dst[ 9] = y * z * oneMinusCosine - x * s;\n dst[10] = zz + (1 - zz) * c;\n dst[11] = 0;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = 0;\n dst[15] = 1;\n\n return dst;\n}\n\n/**\n * Rotates the given 4-by-4 matrix around the given axis by the\n * given angle.\n * @param {module:twgl/m4.Mat4} m The matrix.\n * @param {module:twgl/v3.Vec3} axis The axis\n * about which to rotate.\n * @param {number} angleInRadians The angle by which to rotate (in radians).\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The rotated matrix.\n * @memberOf module:twgl/m4\n */\nfunction axisRotate(m, axis, angleInRadians, dst) {\n dst = dst || new MatType(16);\n\n let x = axis[0];\n let y = axis[1];\n let z = axis[2];\n const n = Math.sqrt(x * x + y * y + z * z);\n x /= n;\n y /= n;\n z /= n;\n const xx = x * x;\n const yy = y * y;\n const zz = z * z;\n const c = Math.cos(angleInRadians);\n const s = Math.sin(angleInRadians);\n const oneMinusCosine = 1 - c;\n\n const r00 = xx + (1 - xx) * c;\n const r01 = x * y * oneMinusCosine + z * s;\n const r02 = x * z * oneMinusCosine - y * s;\n const r10 = x * y * oneMinusCosine - z * s;\n const r11 = yy + (1 - yy) * c;\n const r12 = y * z * oneMinusCosine + x * s;\n const r20 = x * z * oneMinusCosine + y * s;\n const r21 = y * z * oneMinusCosine - x * s;\n const r22 = zz + (1 - zz) * c;\n\n const m00 = m[0];\n const m01 = m[1];\n const m02 = m[2];\n const m03 = m[3];\n const m10 = m[4];\n const m11 = m[5];\n const m12 = m[6];\n const m13 = m[7];\n const m20 = m[8];\n const m21 = m[9];\n const m22 = m[10];\n const m23 = m[11];\n\n dst[ 0] = r00 * m00 + r01 * m10 + r02 * m20;\n dst[ 1] = r00 * m01 + r01 * m11 + r02 * m21;\n dst[ 2] = r00 * m02 + r01 * m12 + r02 * m22;\n dst[ 3] = r00 * m03 + r01 * m13 + r02 * m23;\n dst[ 4] = r10 * m00 + r11 * m10 + r12 * m20;\n dst[ 5] = r10 * m01 + r11 * m11 + r12 * m21;\n dst[ 6] = r10 * m02 + r11 * m12 + r12 * m22;\n dst[ 7] = r10 * m03 + r11 * m13 + r12 * m23;\n dst[ 8] = r20 * m00 + r21 * m10 + r22 * m20;\n dst[ 9] = r20 * m01 + r21 * m11 + r22 * m21;\n dst[10] = r20 * m02 + r21 * m12 + r22 * m22;\n dst[11] = r20 * m03 + r21 * m13 + r22 * m23;\n\n if (m !== dst) {\n dst[12] = m[12];\n dst[13] = m[13];\n dst[14] = m[14];\n dst[15] = m[15];\n }\n\n return dst;\n}\n\n/**\n * Creates a 4-by-4 matrix which scales in each dimension by an amount given by\n * the corresponding entry in the given vector; assumes the vector has three\n * entries.\n * @param {module:twgl/v3.Vec3} v A vector of\n * three entries specifying the factor by which to scale in each dimension.\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The scaling matrix.\n * @memberOf module:twgl/m4\n */\nfunction scaling(v, dst) {\n dst = dst || new MatType(16);\n\n dst[ 0] = v[0];\n dst[ 1] = 0;\n dst[ 2] = 0;\n dst[ 3] = 0;\n dst[ 4] = 0;\n dst[ 5] = v[1];\n dst[ 6] = 0;\n dst[ 7] = 0;\n dst[ 8] = 0;\n dst[ 9] = 0;\n dst[10] = v[2];\n dst[11] = 0;\n dst[12] = 0;\n dst[13] = 0;\n dst[14] = 0;\n dst[15] = 1;\n\n return dst;\n}\n\n/**\n * Scales the given 4-by-4 matrix in each dimension by an amount\n * given by the corresponding entry in the given vector; assumes the vector has\n * three entries.\n * @param {module:twgl/m4.Mat4} m The matrix to be modified.\n * @param {module:twgl/v3.Vec3} v A vector of three entries specifying the\n * factor by which to scale in each dimension.\n * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.\n * @return {module:twgl/m4.Mat4} The scaled matrix.\n * @memberOf module:twgl/m4\n */\nfunction scale(m, v, dst) {\n dst = dst || new MatType(16);\n\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n\n dst[ 0] = v0 * m[0 * 4 + 0];\n dst[ 1] = v0 * m[0 * 4 + 1];\n dst[ 2] = v0 * m[0 * 4 + 2];\n dst[ 3] = v0 * m[0 * 4 + 3];\n dst[ 4] = v1 * m[1 * 4 + 0];\n dst[ 5] = v1 * m[1 * 4 + 1];\n dst[ 6] = v1 * m[1 * 4 + 2];\n dst[ 7] = v1 * m[1 * 4 + 3];\n dst[ 8] = v2 * m[2 * 4 + 0];\n dst[ 9] = v2 * m[2 * 4 + 1];\n dst[10] = v2 * m[2 * 4 + 2];\n dst[11] = v2 * m[2 * 4 + 3];\n\n if (m !== dst) {\n dst[12] = m[12];\n dst[13] = m[13];\n dst[14] = m[14];\n dst[15] = m[15];\n }\n\n return dst;\n}\n\n/**\n * Takes a 4-by-4 matrix and a vector with 3 entries,\n * interprets the vector as a point, transforms that point by the matrix, and\n * returns the result as a vector with 3 entries.\n * @param {module:twgl/m4.Mat4} m The matrix.\n * @param {module:twgl/v3.Vec3} v The point.\n * @param {module:twgl/v3.Vec3} [dst] optional vec3 to store result. If not passed a new one is created.\n * @return {module:twgl/v3.Vec3} The transformed point.\n * @memberOf module:twgl/m4\n */\nfunction transformPoint(m, v, dst) {\n dst = dst || v3.create();\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n const d = v0 * m[0 * 4 + 3] + v1 * m[1 * 4 + 3] + v2 * m[2 * 4 + 3] + m[3 * 4 + 3];\n\n dst[0] = (v0 * m[0 * 4 + 0] + v1 * m[1 * 4 + 0] + v2 * m[2 * 4 + 0] + m[3 * 4 + 0]) / d;\n dst[1] = (v0 * m[0 * 4 + 1] + v1 * m[1 * 4 + 1] + v2 * m[2 * 4 + 1] + m[3 * 4 + 1]) / d;\n dst[2] = (v0 * m[0 * 4 + 2] + v1 * m[1 * 4 + 2] + v2 * m[2 * 4 + 2] + m[3 * 4 + 2]) / d;\n\n return dst;\n}\n\n/**\n * Takes a 4-by-4 matrix and a vector with 3 entries, interprets the vector as a\n * direction, transforms that direction by the matrix, and returns the result;\n * assumes the transformation of 3-dimensional space represented by the matrix\n * is parallel-preserving, i.e. any combination of rotation, scaling and\n * translation, but not a perspective distortion. Returns a vector with 3\n * entries.\n * @param {module:twgl/m4.Mat4} m The matrix.\n * @param {module:twgl/v3.Vec3} v The direction.\n * @param {module:twgl/v3.Vec3} [dst] optional Vec3 to store result. If not passed a new one is created.\n * @return {module:twgl/v3.Vec3} The transformed direction.\n * @memberOf module:twgl/m4\n */\nfunction transformDirection(m, v, dst) {\n dst = dst || v3.create();\n\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n\n dst[0] = v0 * m[0 * 4 + 0] + v1 * m[1 * 4 + 0] + v2 * m[2 * 4 + 0];\n dst[1] = v0 * m[0 * 4 + 1] + v1 * m[1 * 4 + 1] + v2 * m[2 * 4 + 1];\n dst[2] = v0 * m[0 * 4 + 2] + v1 * m[1 * 4 + 2] + v2 * m[2 * 4 + 2];\n\n return dst;\n}\n\n/**\n * Takes a 4-by-4 matrix m and a vector v with 3 entries, interprets the vector\n * as a normal to a surface, and computes a vector which is normal upon\n * transforming that surface by the matrix. The effect of this function is the\n * same as transforming v (as a direction) by the inverse-transpose of m. This\n * function assumes the transformation of 3-dimensional space represented by the\n * matrix is parallel-preserving, i.e. any combination of rotation, scaling and\n * translation, but not a perspective distortion. Returns a vector with 3\n * entries.\n * @param {module:twgl/m4.Mat4} m The matrix.\n * @param {module:twgl/v3.Vec3} v The normal.\n * @param {module:twgl/v3.Vec3} [dst] The direction. If not passed a new one is created.\n * @return {module:twgl/v3.Vec3} The transformed normal.\n * @memberOf module:twgl/m4\n */\nfunction transformNormal(m, v, dst) {\n dst = dst || v3.create();\n const mi = inverse(m);\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n\n dst[0] = v0 * mi[0 * 4 + 0] + v1 * mi[0 * 4 + 1] + v2 * mi[0 * 4 + 2];\n dst[1] = v0 * mi[1 * 4 + 0] + v1 * mi[1 * 4 + 1] + v2 * mi[1 * 4 + 2];\n dst[2] = v0 * mi[2 * 4 + 0] + v1 * mi[2 * 4 + 1] + v2 * mi[2 * 4 + 2];\n\n return dst;\n}\n\nexport {\n axisRotate,\n axisRotation,\n copy,\n frustum,\n getAxis,\n getTranslation,\n identity,\n inverse,\n lookAt,\n multiply,\n negate,\n ortho,\n perspective,\n rotateX,\n rotateY,\n rotateZ,\n rotationX,\n rotationY,\n rotationZ,\n scale,\n scaling,\n setAxis,\n setDefaultType,\n setTranslation,\n transformDirection,\n transformNormal,\n transformPoint,\n translate,\n translation,\n transpose,\n};\n\n","/*\n * Copyright 2019 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n\n/**\n * Various functions to make simple primitives\n *\n * note: Most primitive functions come in 3 styles\n *\n * * `createSomeShapeBufferInfo`\n *\n * These functions are almost always the functions you want to call. They\n * create vertices then make WebGLBuffers and create {@link module:twgl.AttribInfo}s\n * returning a {@link module:twgl.BufferInfo} you can pass to {@link module:twgl.setBuffersAndAttributes}\n * and {@link module:twgl.drawBufferInfo} etc...\n *\n * * `createSomeShapeBuffers`\n *\n * These create WebGLBuffers and put your data in them but nothing else.\n * It's a shortcut to doing it yourself if you don't want to use\n * the higher level functions.\n *\n * * `createSomeShapeVertices`\n *\n * These just create vertices, no buffers. This allows you to manipulate the vertices\n * or add more data before generating a {@link module:twgl.BufferInfo}. Once you're finished\n * manipulating the vertices call {@link module:twgl.createBufferInfoFromArrays}.\n *\n * example:\n *\n * const arrays = twgl.primitives.createPlaneArrays(1);\n * twgl.primitives.reorientVertices(arrays, m4.rotationX(Math.PI * 0.5));\n * const bufferInfo = twgl.createBufferInfoFromArrays(gl, arrays);\n *\n * @module twgl/primitives\n */\nimport * as attributes from './attributes.js';\nimport * as helper from './helper.js';\nimport * as typedArrays from './typedarrays.js';\nimport * as m4 from './m4.js';\nimport * as v3 from './v3.js';\n\nconst getArray = attributes.getArray_; // eslint-disable-line\nconst getNumComponents = attributes.getNumComponents_; // eslint-disable-line\n\n/**\n * @typedef {(Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array)} TypedArray\n */\n\n/**\n * Add `push` to a typed array. It just keeps a 'cursor'\n * and allows use to `push` values into the array so we\n * don't have to manually compute offsets\n * @param {TypedArray} typedArray TypedArray to augment\n * @param {number} numComponents number of components.\n * @private\n */\nfunction augmentTypedArray(typedArray, numComponents) {\n let cursor = 0;\n typedArray.push = function() {\n for (let ii = 0; ii < arguments.length; ++ii) {\n const value = arguments[ii];\n if (value instanceof Array || typedArrays.isArrayBuffer(value)) {\n for (let jj = 0; jj < value.length; ++jj) {\n typedArray[cursor++] = value[jj];\n }\n } else {\n typedArray[cursor++] = value;\n }\n }\n };\n typedArray.reset = function(opt_index) {\n cursor = opt_index || 0;\n };\n typedArray.numComponents = numComponents;\n Object.defineProperty(typedArray, 'numElements', {\n get: function() {\n return this.length / this.numComponents | 0;\n },\n });\n return typedArray;\n}\n\n/**\n * creates a typed array with a `push` function attached\n * so that you can easily *push* values.\n *\n * `push` can take multiple arguments. If an argument is an array each element\n * of the array will be added to the typed array.\n *\n * Example:\n *\n * const array = createAugmentedTypedArray(3, 2); // creates a Float32Array with 6 values\n * array.push(1, 2, 3);\n * array.push([4, 5, 6]);\n * // array now contains [1, 2, 3, 4, 5, 6]\n *\n * Also has `numComponents` and `numElements` properties.\n *\n * @param {number} numComponents number of components\n * @param {number} numElements number of elements. The total size of the array will be `numComponents * numElements`.\n * @param {constructor} opt_type A constructor for the type. Default = `Float32Array`.\n * @return {ArrayBufferView} A typed array.\n * @memberOf module:twgl/primitives\n */\nfunction createAugmentedTypedArray(numComponents, numElements, opt_type) {\n const Type = opt_type || Float32Array;\n return augmentTypedArray(new Type(numComponents * numElements), numComponents);\n}\n\nfunction allButIndices(name) {\n return name !== \"indices\";\n}\n\n/**\n * Given indexed vertices creates a new set of vertices un-indexed by expanding the indexed vertices.\n * @param {Object.} vertices The indexed vertices to deindex\n * @return {Object.} The deindexed vertices\n * @memberOf module:twgl/primitives\n */\nfunction deindexVertices(vertices) {\n const indices = vertices.indices;\n const newVertices = {};\n const numElements = indices.length;\n\n function expandToUnindexed(channel) {\n const srcBuffer = vertices[channel];\n const numComponents = srcBuffer.numComponents;\n const dstBuffer = createAugmentedTypedArray(numComponents, numElements, srcBuffer.constructor);\n for (let ii = 0; ii < numElements; ++ii) {\n const ndx = indices[ii];\n const offset = ndx * numComponents;\n for (let jj = 0; jj < numComponents; ++jj) {\n dstBuffer.push(srcBuffer[offset + jj]);\n }\n }\n newVertices[channel] = dstBuffer;\n }\n\n Object.keys(vertices).filter(allButIndices).forEach(expandToUnindexed);\n\n return newVertices;\n}\n\n/**\n * flattens the normals of deindexed vertices in place.\n * @param {Object.} vertices The deindexed vertices who's normals to flatten\n * @return {Object.} The flattened vertices (same as was passed in)\n * @memberOf module:twgl/primitives\n */\nfunction flattenNormals(vertices) {\n if (vertices.indices) {\n throw new Error('can not flatten normals of indexed vertices. deindex them first');\n }\n\n const normals = vertices.normal;\n const numNormals = normals.length;\n for (let ii = 0; ii < numNormals; ii += 9) {\n // pull out the 3 normals for this triangle\n const nax = normals[ii + 0];\n const nay = normals[ii + 1];\n const naz = normals[ii + 2];\n\n const nbx = normals[ii + 3];\n const nby = normals[ii + 4];\n const nbz = normals[ii + 5];\n\n const ncx = normals[ii + 6];\n const ncy = normals[ii + 7];\n const ncz = normals[ii + 8];\n\n // add them\n let nx = nax + nbx + ncx;\n let ny = nay + nby + ncy;\n let nz = naz + nbz + ncz;\n\n // normalize them\n const length = Math.sqrt(nx * nx + ny * ny + nz * nz);\n\n nx /= length;\n ny /= length;\n nz /= length;\n\n // copy them back in\n normals[ii + 0] = nx;\n normals[ii + 1] = ny;\n normals[ii + 2] = nz;\n\n normals[ii + 3] = nx;\n normals[ii + 4] = ny;\n normals[ii + 5] = nz;\n\n normals[ii + 6] = nx;\n normals[ii + 7] = ny;\n normals[ii + 8] = nz;\n }\n\n return vertices;\n}\n\nfunction applyFuncToV3Array(array, matrix, fn) {\n const len = array.length;\n const tmp = new Float32Array(3);\n for (let ii = 0; ii < len; ii += 3) {\n fn(matrix, [array[ii], array[ii + 1], array[ii + 2]], tmp);\n array[ii ] = tmp[0];\n array[ii + 1] = tmp[1];\n array[ii + 2] = tmp[2];\n }\n}\n\nfunction transformNormal(mi, v, dst) {\n dst = dst || v3.create();\n const v0 = v[0];\n const v1 = v[1];\n const v2 = v[2];\n\n dst[0] = v0 * mi[0 * 4 + 0] + v1 * mi[0 * 4 + 1] + v2 * mi[0 * 4 + 2];\n dst[1] = v0 * mi[1 * 4 + 0] + v1 * mi[1 * 4 + 1] + v2 * mi[1 * 4 + 2];\n dst[2] = v0 * mi[2 * 4 + 0] + v1 * mi[2 * 4 + 1] + v2 * mi[2 * 4 + 2];\n\n return dst;\n}\n\n/**\n * Reorients directions by the given matrix..\n * @param {(number[]|TypedArray)} array The array. Assumes value floats per element.\n * @param {module:twgl/m4.Mat4} matrix A matrix to multiply by.\n * @return {(number[]|TypedArray)} the same array that was passed in\n * @memberOf module:twgl/primitives\n */\nfunction reorientDirections(array, matrix) {\n applyFuncToV3Array(array, matrix, m4.transformDirection);\n return array;\n}\n\n/**\n * Reorients normals by the inverse-transpose of the given\n * matrix..\n * @param {(number[]|TypedArray)} array The array. Assumes value floats per element.\n * @param {module:twgl/m4.Mat4} matrix A matrix to multiply by.\n * @return {(number[]|TypedArray)} the same array that was passed in\n * @memberOf module:twgl/primitives\n */\nfunction reorientNormals(array, matrix) {\n applyFuncToV3Array(array, m4.inverse(matrix), transformNormal);\n return array;\n}\n\n/**\n * Reorients positions by the given matrix. In other words, it\n * multiplies each vertex by the given matrix.\n * @param {(number[]|TypedArray)} array The array. Assumes value floats per element.\n * @param {module:twgl/m4.Mat4} matrix A matrix to multiply by.\n * @return {(number[]|TypedArray)} the same array that was passed in\n * @memberOf module:twgl/primitives\n */\nfunction reorientPositions(array, matrix) {\n applyFuncToV3Array(array, matrix, m4.transformPoint);\n return array;\n}\n\n/**\n * @typedef {(number[]|TypedArray)} NativeArrayOrTypedArray\n */\n\n/**\n * Reorients arrays by the given matrix. Assumes arrays have\n * names that contains 'pos' could be reoriented as positions,\n * 'binorm' or 'tan' as directions, and 'norm' as normals.\n *\n * @param {Object.} arrays The vertices to reorient\n * @param {module:twgl/m4.Mat4} matrix matrix to reorient by.\n * @return {Object.} same arrays that were passed in.\n * @memberOf module:twgl/primitives\n */\nfunction reorientVertices(arrays, matrix) {\n Object.keys(arrays).forEach(function(name) {\n const array = arrays[name];\n if (name.indexOf(\"pos\") >= 0) {\n reorientPositions(array, matrix);\n } else if (name.indexOf(\"tan\") >= 0 || name.indexOf(\"binorm\") >= 0) {\n reorientDirections(array, matrix);\n } else if (name.indexOf(\"norm\") >= 0) {\n reorientNormals(array, matrix);\n }\n });\n return arrays;\n}\n\n/**\n * Creates XY quad BufferInfo\n *\n * The default with no parameters will return a 2x2 quad with values from -1 to +1.\n * If you want a unit quad with that goes from 0 to 1 you'd call it with\n *\n * twgl.primitives.createXYQuadBufferInfo(gl, 1, 0.5, 0.5);\n *\n * If you want a unit quad centered above 0,0 you'd call it with\n *\n * twgl.primitives.createXYQuadBufferInfo(gl, 1, 0, 0.5);\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} [size] the size across the quad. Defaults to 2 which means vertices will go from -1 to +1\n * @param {number} [xOffset] the amount to offset the quad in X\n * @param {number} [yOffset] the amount to offset the quad in Y\n * @return {Object.} the created XY Quad BufferInfo\n * @memberOf module:twgl/primitives\n * @function createXYQuadBuffers\n */\n\n/**\n * Creates XY quad Buffers\n *\n * The default with no parameters will return a 2x2 quad with values from -1 to +1.\n * If you want a unit quad with that goes from 0 to 1 you'd call it with\n *\n * twgl.primitives.createXYQuadBufferInfo(gl, 1, 0.5, 0.5);\n *\n * If you want a unit quad centered above 0,0 you'd call it with\n *\n * twgl.primitives.createXYQuadBufferInfo(gl, 1, 0, 0.5);\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} [size] the size across the quad. Defaults to 2 which means vertices will go from -1 to +1\n * @param {number} [xOffset] the amount to offset the quad in X\n * @param {number} [yOffset] the amount to offset the quad in Y\n * @return {module:twgl.BufferInfo} the created XY Quad buffers\n * @memberOf module:twgl/primitives\n * @function createXYQuadBufferInfo\n */\n\n/**\n * Creates XY quad vertices\n *\n * The default with no parameters will return a 2x2 quad with values from -1 to +1.\n * If you want a unit quad with that goes from 0 to 1 you'd call it with\n *\n * twgl.primitives.createXYQuadVertices(1, 0.5, 0.5);\n *\n * If you want a unit quad centered above 0,0 you'd call it with\n *\n * twgl.primitives.createXYQuadVertices(1, 0, 0.5);\n *\n * @param {number} [size] the size across the quad. Defaults to 2 which means vertices will go from -1 to +1\n * @param {number} [xOffset] the amount to offset the quad in X\n * @param {number} [yOffset] the amount to offset the quad in Y\n * @return {Object.} the created XY Quad vertices\n * @memberOf module:twgl/primitives\n */\nfunction createXYQuadVertices(size, xOffset, yOffset) {\n size = size || 2;\n xOffset = xOffset || 0;\n yOffset = yOffset || 0;\n size *= 0.5;\n return {\n position: {\n numComponents: 2,\n data: [\n xOffset + -1 * size, yOffset + -1 * size,\n xOffset + 1 * size, yOffset + -1 * size,\n xOffset + -1 * size, yOffset + 1 * size,\n xOffset + 1 * size, yOffset + 1 * size,\n ],\n },\n normal: [\n 0, 0, 1,\n 0, 0, 1,\n 0, 0, 1,\n 0, 0, 1,\n ],\n texcoord: [\n 0, 0,\n 1, 0,\n 0, 1,\n 1, 1,\n ],\n indices: [ 0, 1, 2, 2, 1, 3 ],\n };\n}\n\n/**\n * Creates XZ plane BufferInfo.\n *\n * The created plane has position, normal, and texcoord data\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} [width] Width of the plane. Default = 1\n * @param {number} [depth] Depth of the plane. Default = 1\n * @param {number} [subdivisionsWidth] Number of steps across the plane. Default = 1\n * @param {number} [subdivisionsDepth] Number of steps down the plane. Default = 1\n * @param {module:twgl/m4.Mat4} [matrix] A matrix by which to multiply all the vertices.\n * @return {module:twgl.BufferInfo} The created plane BufferInfo.\n * @memberOf module:twgl/primitives\n * @function createPlaneBufferInfo\n */\n\n/**\n * Creates XZ plane buffers.\n *\n * The created plane has position, normal, and texcoord data\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} [width] Width of the plane. Default = 1\n * @param {number} [depth] Depth of the plane. Default = 1\n * @param {number} [subdivisionsWidth] Number of steps across the plane. Default = 1\n * @param {number} [subdivisionsDepth] Number of steps down the plane. Default = 1\n * @param {module:twgl/m4.Mat4} [matrix] A matrix by which to multiply all the vertices.\n * @return {Object.} The created plane buffers.\n * @memberOf module:twgl/primitives\n * @function createPlaneBuffers\n */\n\n/**\n * Creates XZ plane vertices.\n *\n * The created plane has position, normal, and texcoord data\n *\n * @param {number} [width] Width of the plane. Default = 1\n * @param {number} [depth] Depth of the plane. Default = 1\n * @param {number} [subdivisionsWidth] Number of steps across the plane. Default = 1\n * @param {number} [subdivisionsDepth] Number of steps down the plane. Default = 1\n * @param {module:twgl/m4.Mat4} [matrix] A matrix by which to multiply all the vertices.\n * @return {Object.} The created plane vertices.\n * @memberOf module:twgl/primitives\n */\nfunction createPlaneVertices(\n width,\n depth,\n subdivisionsWidth,\n subdivisionsDepth,\n matrix) {\n width = width || 1;\n depth = depth || 1;\n subdivisionsWidth = subdivisionsWidth || 1;\n subdivisionsDepth = subdivisionsDepth || 1;\n matrix = matrix || m4.identity();\n\n const numVertices = (subdivisionsWidth + 1) * (subdivisionsDepth + 1);\n const positions = createAugmentedTypedArray(3, numVertices);\n const normals = createAugmentedTypedArray(3, numVertices);\n const texcoords = createAugmentedTypedArray(2, numVertices);\n\n for (let z = 0; z <= subdivisionsDepth; z++) {\n for (let x = 0; x <= subdivisionsWidth; x++) {\n const u = x / subdivisionsWidth;\n const v = z / subdivisionsDepth;\n positions.push(\n width * u - width * 0.5,\n 0,\n depth * v - depth * 0.5);\n normals.push(0, 1, 0);\n texcoords.push(u, v);\n }\n }\n\n const numVertsAcross = subdivisionsWidth + 1;\n const indices = createAugmentedTypedArray(\n 3, subdivisionsWidth * subdivisionsDepth * 2, Uint16Array);\n\n for (let z = 0; z < subdivisionsDepth; z++) { // eslint-disable-line\n for (let x = 0; x < subdivisionsWidth; x++) { // eslint-disable-line\n // Make triangle 1 of quad.\n indices.push(\n (z + 0) * numVertsAcross + x,\n (z + 1) * numVertsAcross + x,\n (z + 0) * numVertsAcross + x + 1);\n\n // Make triangle 2 of quad.\n indices.push(\n (z + 1) * numVertsAcross + x,\n (z + 1) * numVertsAcross + x + 1,\n (z + 0) * numVertsAcross + x + 1);\n }\n }\n\n const arrays = reorientVertices({\n position: positions,\n normal: normals,\n texcoord: texcoords,\n indices: indices,\n }, matrix);\n return arrays;\n}\n\n/**\n * Creates sphere BufferInfo.\n *\n * The created sphere has position, normal, and texcoord data\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} radius radius of the sphere.\n * @param {number} subdivisionsAxis number of steps around the sphere.\n * @param {number} subdivisionsHeight number of vertically on the sphere.\n * @param {number} [opt_startLatitudeInRadians] where to start the\n * top of the sphere. Default = 0.\n * @param {number} [opt_endLatitudeInRadians] Where to end the\n * bottom of the sphere. Default = Math.PI.\n * @param {number} [opt_startLongitudeInRadians] where to start\n * wrapping the sphere. Default = 0.\n * @param {number} [opt_endLongitudeInRadians] where to end\n * wrapping the sphere. Default = 2 * Math.PI.\n * @return {module:twgl.BufferInfo} The created sphere BufferInfo.\n * @memberOf module:twgl/primitives\n * @function createSphereBufferInfo\n */\n\n/**\n * Creates sphere buffers.\n *\n * The created sphere has position, normal, and texcoord data\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} radius radius of the sphere.\n * @param {number} subdivisionsAxis number of steps around the sphere.\n * @param {number} subdivisionsHeight number of vertically on the sphere.\n * @param {number} [opt_startLatitudeInRadians] where to start the\n * top of the sphere. Default = 0.\n * @param {number} [opt_endLatitudeInRadians] Where to end the\n * bottom of the sphere. Default = Math.PI.\n * @param {number} [opt_startLongitudeInRadians] where to start\n * wrapping the sphere. Default = 0.\n * @param {number} [opt_endLongitudeInRadians] where to end\n * wrapping the sphere. Default = 2 * Math.PI.\n * @return {Object.} The created sphere buffers.\n * @memberOf module:twgl/primitives\n * @function createSphereBuffers\n */\n\n/**\n * Creates sphere vertices.\n *\n * The created sphere has position, normal, and texcoord data\n *\n * @param {number} radius radius of the sphere.\n * @param {number} subdivisionsAxis number of steps around the sphere.\n * @param {number} subdivisionsHeight number of vertically on the sphere.\n * @param {number} [opt_startLatitudeInRadians] where to start the\n * top of the sphere. Default = 0.\n * @param {number} [opt_endLatitudeInRadians] Where to end the\n * bottom of the sphere. Default = Math.PI.\n * @param {number} [opt_startLongitudeInRadians] where to start\n * wrapping the sphere. Default = 0.\n * @param {number} [opt_endLongitudeInRadians] where to end\n * wrapping the sphere. Default = 2 * Math.PI.\n * @return {Object.} The created sphere vertices.\n * @memberOf module:twgl/primitives\n */\nfunction createSphereVertices(\n radius,\n subdivisionsAxis,\n subdivisionsHeight,\n opt_startLatitudeInRadians,\n opt_endLatitudeInRadians,\n opt_startLongitudeInRadians,\n opt_endLongitudeInRadians) {\n if (subdivisionsAxis <= 0 || subdivisionsHeight <= 0) {\n throw new Error('subdivisionAxis and subdivisionHeight must be > 0');\n }\n\n opt_startLatitudeInRadians = opt_startLatitudeInRadians || 0;\n opt_endLatitudeInRadians = opt_endLatitudeInRadians || Math.PI;\n opt_startLongitudeInRadians = opt_startLongitudeInRadians || 0;\n opt_endLongitudeInRadians = opt_endLongitudeInRadians || (Math.PI * 2);\n\n const latRange = opt_endLatitudeInRadians - opt_startLatitudeInRadians;\n const longRange = opt_endLongitudeInRadians - opt_startLongitudeInRadians;\n\n // We are going to generate our sphere by iterating through its\n // spherical coordinates and generating 2 triangles for each quad on a\n // ring of the sphere.\n const numVertices = (subdivisionsAxis + 1) * (subdivisionsHeight + 1);\n const positions = createAugmentedTypedArray(3, numVertices);\n const normals = createAugmentedTypedArray(3, numVertices);\n const texcoords = createAugmentedTypedArray(2 , numVertices);\n\n // Generate the individual vertices in our vertex buffer.\n for (let y = 0; y <= subdivisionsHeight; y++) {\n for (let x = 0; x <= subdivisionsAxis; x++) {\n // Generate a vertex based on its spherical coordinates\n const u = x / subdivisionsAxis;\n const v = y / subdivisionsHeight;\n const theta = longRange * u + opt_startLongitudeInRadians;\n const phi = latRange * v + opt_startLatitudeInRadians;\n const sinTheta = Math.sin(theta);\n const cosTheta = Math.cos(theta);\n const sinPhi = Math.sin(phi);\n const cosPhi = Math.cos(phi);\n const ux = cosTheta * sinPhi;\n const uy = cosPhi;\n const uz = sinTheta * sinPhi;\n positions.push(radius * ux, radius * uy, radius * uz);\n normals.push(ux, uy, uz);\n texcoords.push(1 - u, v);\n }\n }\n\n const numVertsAround = subdivisionsAxis + 1;\n const indices = createAugmentedTypedArray(3, subdivisionsAxis * subdivisionsHeight * 2, Uint16Array);\n for (let x = 0; x < subdivisionsAxis; x++) { // eslint-disable-line\n for (let y = 0; y < subdivisionsHeight; y++) { // eslint-disable-line\n // Make triangle 1 of quad.\n indices.push(\n (y + 0) * numVertsAround + x,\n (y + 0) * numVertsAround + x + 1,\n (y + 1) * numVertsAround + x);\n\n // Make triangle 2 of quad.\n indices.push(\n (y + 1) * numVertsAround + x,\n (y + 0) * numVertsAround + x + 1,\n (y + 1) * numVertsAround + x + 1);\n }\n }\n\n return {\n position: positions,\n normal: normals,\n texcoord: texcoords,\n indices: indices,\n };\n}\n\n/**\n * Array of the indices of corners of each face of a cube.\n * @type {Array.}\n * @private\n */\nconst CUBE_FACE_INDICES = [\n [3, 7, 5, 1], // right\n [6, 2, 0, 4], // left\n [6, 7, 3, 2], // ??\n [0, 1, 5, 4], // ??\n [7, 6, 4, 5], // front\n [2, 3, 1, 0], // back\n];\n\n/**\n * Creates a BufferInfo for a cube.\n *\n * The cube is created around the origin. (-size / 2, size / 2).\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} [size] width, height and depth of the cube.\n * @return {module:twgl.BufferInfo} The created BufferInfo.\n * @memberOf module:twgl/primitives\n * @function createCubeBufferInfo\n */\n\n/**\n * Creates the buffers and indices for a cube.\n *\n * The cube is created around the origin. (-size / 2, size / 2).\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} [size] width, height and depth of the cube.\n * @return {Object.} The created buffers.\n * @memberOf module:twgl/primitives\n * @function createCubeBuffers\n */\n\n/**\n * Creates the vertices and indices for a cube.\n *\n * The cube is created around the origin. (-size / 2, size / 2).\n *\n * @param {number} [size] width, height and depth of the cube.\n * @return {Object.} The created vertices.\n * @memberOf module:twgl/primitives\n */\nfunction createCubeVertices(size) {\n size = size || 1;\n const k = size / 2;\n\n const cornerVertices = [\n [-k, -k, -k],\n [+k, -k, -k],\n [-k, +k, -k],\n [+k, +k, -k],\n [-k, -k, +k],\n [+k, -k, +k],\n [-k, +k, +k],\n [+k, +k, +k],\n ];\n\n const faceNormals = [\n [+1, +0, +0],\n [-1, +0, +0],\n [+0, +1, +0],\n [+0, -1, +0],\n [+0, +0, +1],\n [+0, +0, -1],\n ];\n\n const uvCoords = [\n [1, 0],\n [0, 0],\n [0, 1],\n [1, 1],\n ];\n\n const numVertices = 6 * 4;\n const positions = createAugmentedTypedArray(3, numVertices);\n const normals = createAugmentedTypedArray(3, numVertices);\n const texcoords = createAugmentedTypedArray(2 , numVertices);\n const indices = createAugmentedTypedArray(3, 6 * 2, Uint16Array);\n\n for (let f = 0; f < 6; ++f) {\n const faceIndices = CUBE_FACE_INDICES[f];\n for (let v = 0; v < 4; ++v) {\n const position = cornerVertices[faceIndices[v]];\n const normal = faceNormals[f];\n const uv = uvCoords[v];\n\n // Each face needs all four vertices because the normals and texture\n // coordinates are not all the same.\n positions.push(position);\n normals.push(normal);\n texcoords.push(uv);\n\n }\n // Two triangles make a square face.\n const offset = 4 * f;\n indices.push(offset + 0, offset + 1, offset + 2);\n indices.push(offset + 0, offset + 2, offset + 3);\n }\n\n return {\n position: positions,\n normal: normals,\n texcoord: texcoords,\n indices: indices,\n };\n}\n\n/**\n * Creates a BufferInfo for a truncated cone, which is like a cylinder\n * except that it has different top and bottom radii. A truncated cone\n * can also be used to create cylinders and regular cones. The\n * truncated cone will be created centered about the origin, with the\n * y axis as its vertical axis.\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} bottomRadius Bottom radius of truncated cone.\n * @param {number} topRadius Top radius of truncated cone.\n * @param {number} height Height of truncated cone.\n * @param {number} radialSubdivisions The number of subdivisions around the\n * truncated cone.\n * @param {number} verticalSubdivisions The number of subdivisions down the\n * truncated cone.\n * @param {boolean} [opt_topCap] Create top cap. Default = true.\n * @param {boolean} [opt_bottomCap] Create bottom cap. Default = true.\n * @return {module:twgl.BufferInfo} The created cone BufferInfo.\n * @memberOf module:twgl/primitives\n * @function createTruncatedConeBufferInfo\n */\n\n/**\n * Creates buffers for a truncated cone, which is like a cylinder\n * except that it has different top and bottom radii. A truncated cone\n * can also be used to create cylinders and regular cones. The\n * truncated cone will be created centered about the origin, with the\n * y axis as its vertical axis.\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} bottomRadius Bottom radius of truncated cone.\n * @param {number} topRadius Top radius of truncated cone.\n * @param {number} height Height of truncated cone.\n * @param {number} radialSubdivisions The number of subdivisions around the\n * truncated cone.\n * @param {number} verticalSubdivisions The number of subdivisions down the\n * truncated cone.\n * @param {boolean} [opt_topCap] Create top cap. Default = true.\n * @param {boolean} [opt_bottomCap] Create bottom cap. Default = true.\n * @return {Object.} The created cone buffers.\n * @memberOf module:twgl/primitives\n * @function createTruncatedConeBuffers\n */\n\n/**\n * Creates vertices for a truncated cone, which is like a cylinder\n * except that it has different top and bottom radii. A truncated cone\n * can also be used to create cylinders and regular cones. The\n * truncated cone will be created centered about the origin, with the\n * y axis as its vertical axis. .\n *\n * @param {number} bottomRadius Bottom radius of truncated cone.\n * @param {number} topRadius Top radius of truncated cone.\n * @param {number} height Height of truncated cone.\n * @param {number} radialSubdivisions The number of subdivisions around the\n * truncated cone.\n * @param {number} verticalSubdivisions The number of subdivisions down the\n * truncated cone.\n * @param {boolean} [opt_topCap] Create top cap. Default = true.\n * @param {boolean} [opt_bottomCap] Create bottom cap. Default = true.\n * @return {Object.} The created cone vertices.\n * @memberOf module:twgl/primitives\n */\nfunction createTruncatedConeVertices(\n bottomRadius,\n topRadius,\n height,\n radialSubdivisions,\n verticalSubdivisions,\n opt_topCap,\n opt_bottomCap) {\n if (radialSubdivisions < 3) {\n throw new Error('radialSubdivisions must be 3 or greater');\n }\n\n if (verticalSubdivisions < 1) {\n throw new Error('verticalSubdivisions must be 1 or greater');\n }\n\n const topCap = (opt_topCap === undefined) ? true : opt_topCap;\n const bottomCap = (opt_bottomCap === undefined) ? true : opt_bottomCap;\n\n const extra = (topCap ? 2 : 0) + (bottomCap ? 2 : 0);\n\n const numVertices = (radialSubdivisions + 1) * (verticalSubdivisions + 1 + extra);\n const positions = createAugmentedTypedArray(3, numVertices);\n const normals = createAugmentedTypedArray(3, numVertices);\n const texcoords = createAugmentedTypedArray(2, numVertices);\n const indices = createAugmentedTypedArray(3, radialSubdivisions * (verticalSubdivisions + extra) * 2, Uint16Array);\n\n const vertsAroundEdge = radialSubdivisions + 1;\n\n // The slant of the cone is constant across its surface\n const slant = Math.atan2(bottomRadius - topRadius, height);\n const cosSlant = Math.cos(slant);\n const sinSlant = Math.sin(slant);\n\n const start = topCap ? -2 : 0;\n const end = verticalSubdivisions + (bottomCap ? 2 : 0);\n\n for (let yy = start; yy <= end; ++yy) {\n let v = yy / verticalSubdivisions;\n let y = height * v;\n let ringRadius;\n if (yy < 0) {\n y = 0;\n v = 1;\n ringRadius = bottomRadius;\n } else if (yy > verticalSubdivisions) {\n y = height;\n v = 1;\n ringRadius = topRadius;\n } else {\n ringRadius = bottomRadius +\n (topRadius - bottomRadius) * (yy / verticalSubdivisions);\n }\n if (yy === -2 || yy === verticalSubdivisions + 2) {\n ringRadius = 0;\n v = 0;\n }\n y -= height / 2;\n for (let ii = 0; ii < vertsAroundEdge; ++ii) {\n const sin = Math.sin(ii * Math.PI * 2 / radialSubdivisions);\n const cos = Math.cos(ii * Math.PI * 2 / radialSubdivisions);\n positions.push(sin * ringRadius, y, cos * ringRadius);\n if (yy < 0) {\n normals.push(0, -1, 0);\n } else if (yy > verticalSubdivisions) {\n normals.push(0, 1, 0);\n } else if (ringRadius === 0.0) {\n normals.push(0, 0, 0);\n } else {\n normals.push(sin * cosSlant, sinSlant, cos * cosSlant);\n }\n texcoords.push((ii / radialSubdivisions), 1 - v);\n }\n }\n\n for (let yy = 0; yy < verticalSubdivisions + extra; ++yy) { // eslint-disable-line\n for (let ii = 0; ii < radialSubdivisions; ++ii) { // eslint-disable-line\n indices.push(vertsAroundEdge * (yy + 0) + 0 + ii,\n vertsAroundEdge * (yy + 0) + 1 + ii,\n vertsAroundEdge * (yy + 1) + 1 + ii);\n indices.push(vertsAroundEdge * (yy + 0) + 0 + ii,\n vertsAroundEdge * (yy + 1) + 1 + ii,\n vertsAroundEdge * (yy + 1) + 0 + ii);\n }\n }\n\n return {\n position: positions,\n normal: normals,\n texcoord: texcoords,\n indices: indices,\n };\n}\n\n/**\n * Expands RLE data\n * @param {number[]} rleData data in format of run-length, x, y, z, run-length, x, y, z\n * @param {number[]} [padding] value to add each entry with.\n * @return {number[]} the expanded rleData\n * @private\n */\nfunction expandRLEData(rleData, padding) {\n padding = padding || [];\n const data = [];\n for (let ii = 0; ii < rleData.length; ii += 4) {\n const runLength = rleData[ii];\n const element = rleData.slice(ii + 1, ii + 4);\n element.push.apply(element, padding);\n for (let jj = 0; jj < runLength; ++jj) {\n data.push.apply(data, element);\n }\n }\n return data;\n}\n\n/**\n * Creates 3D 'F' BufferInfo.\n * An 'F' is useful because you can easily tell which way it is oriented.\n * The created 'F' has position, normal, texcoord, and color buffers.\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @return {module:twgl.BufferInfo} The created BufferInfo.\n * @memberOf module:twgl/primitives\n * @function create3DFBufferInfo\n */\n\n/**\n * Creates 3D 'F' buffers.\n * An 'F' is useful because you can easily tell which way it is oriented.\n * The created 'F' has position, normal, texcoord, and color buffers.\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @return {Object.} The created buffers.\n * @memberOf module:twgl/primitives\n * @function create3DFBuffers\n */\n\n/**\n * Creates 3D 'F' vertices.\n * An 'F' is useful because you can easily tell which way it is oriented.\n * The created 'F' has position, normal, texcoord, and color arrays.\n *\n * @return {Object.} The created vertices.\n * @memberOf module:twgl/primitives\n */\nfunction create3DFVertices() {\n\n const positions = [\n // left column front\n 0, 0, 0,\n 0, 150, 0,\n 30, 0, 0,\n 0, 150, 0,\n 30, 150, 0,\n 30, 0, 0,\n\n // top rung front\n 30, 0, 0,\n 30, 30, 0,\n 100, 0, 0,\n 30, 30, 0,\n 100, 30, 0,\n 100, 0, 0,\n\n // middle rung front\n 30, 60, 0,\n 30, 90, 0,\n 67, 60, 0,\n 30, 90, 0,\n 67, 90, 0,\n 67, 60, 0,\n\n // left column back\n 0, 0, 30,\n 30, 0, 30,\n 0, 150, 30,\n 0, 150, 30,\n 30, 0, 30,\n 30, 150, 30,\n\n // top rung back\n 30, 0, 30,\n 100, 0, 30,\n 30, 30, 30,\n 30, 30, 30,\n 100, 0, 30,\n 100, 30, 30,\n\n // middle rung back\n 30, 60, 30,\n 67, 60, 30,\n 30, 90, 30,\n 30, 90, 30,\n 67, 60, 30,\n 67, 90, 30,\n\n // top\n 0, 0, 0,\n 100, 0, 0,\n 100, 0, 30,\n 0, 0, 0,\n 100, 0, 30,\n 0, 0, 30,\n\n // top rung front\n 100, 0, 0,\n 100, 30, 0,\n 100, 30, 30,\n 100, 0, 0,\n 100, 30, 30,\n 100, 0, 30,\n\n // under top rung\n 30, 30, 0,\n 30, 30, 30,\n 100, 30, 30,\n 30, 30, 0,\n 100, 30, 30,\n 100, 30, 0,\n\n // between top rung and middle\n 30, 30, 0,\n 30, 60, 30,\n 30, 30, 30,\n 30, 30, 0,\n 30, 60, 0,\n 30, 60, 30,\n\n // top of middle rung\n 30, 60, 0,\n 67, 60, 30,\n 30, 60, 30,\n 30, 60, 0,\n 67, 60, 0,\n 67, 60, 30,\n\n // front of middle rung\n 67, 60, 0,\n 67, 90, 30,\n 67, 60, 30,\n 67, 60, 0,\n 67, 90, 0,\n 67, 90, 30,\n\n // bottom of middle rung.\n 30, 90, 0,\n 30, 90, 30,\n 67, 90, 30,\n 30, 90, 0,\n 67, 90, 30,\n 67, 90, 0,\n\n // front of bottom\n 30, 90, 0,\n 30, 150, 30,\n 30, 90, 30,\n 30, 90, 0,\n 30, 150, 0,\n 30, 150, 30,\n\n // bottom\n 0, 150, 0,\n 0, 150, 30,\n 30, 150, 30,\n 0, 150, 0,\n 30, 150, 30,\n 30, 150, 0,\n\n // left side\n 0, 0, 0,\n 0, 0, 30,\n 0, 150, 30,\n 0, 0, 0,\n 0, 150, 30,\n 0, 150, 0,\n ];\n\n const texcoords = [\n // left column front\n 0.22, 0.19,\n 0.22, 0.79,\n 0.34, 0.19,\n 0.22, 0.79,\n 0.34, 0.79,\n 0.34, 0.19,\n\n // top rung front\n 0.34, 0.19,\n 0.34, 0.31,\n 0.62, 0.19,\n 0.34, 0.31,\n 0.62, 0.31,\n 0.62, 0.19,\n\n // middle rung front\n 0.34, 0.43,\n 0.34, 0.55,\n 0.49, 0.43,\n 0.34, 0.55,\n 0.49, 0.55,\n 0.49, 0.43,\n\n // left column back\n 0, 0,\n 1, 0,\n 0, 1,\n 0, 1,\n 1, 0,\n 1, 1,\n\n // top rung back\n 0, 0,\n 1, 0,\n 0, 1,\n 0, 1,\n 1, 0,\n 1, 1,\n\n // middle rung back\n 0, 0,\n 1, 0,\n 0, 1,\n 0, 1,\n 1, 0,\n 1, 1,\n\n // top\n 0, 0,\n 1, 0,\n 1, 1,\n 0, 0,\n 1, 1,\n 0, 1,\n\n // top rung front\n 0, 0,\n 1, 0,\n 1, 1,\n 0, 0,\n 1, 1,\n 0, 1,\n\n // under top rung\n 0, 0,\n 0, 1,\n 1, 1,\n 0, 0,\n 1, 1,\n 1, 0,\n\n // between top rung and middle\n 0, 0,\n 1, 1,\n 0, 1,\n 0, 0,\n 1, 0,\n 1, 1,\n\n // top of middle rung\n 0, 0,\n 1, 1,\n 0, 1,\n 0, 0,\n 1, 0,\n 1, 1,\n\n // front of middle rung\n 0, 0,\n 1, 1,\n 0, 1,\n 0, 0,\n 1, 0,\n 1, 1,\n\n // bottom of middle rung.\n 0, 0,\n 0, 1,\n 1, 1,\n 0, 0,\n 1, 1,\n 1, 0,\n\n // front of bottom\n 0, 0,\n 1, 1,\n 0, 1,\n 0, 0,\n 1, 0,\n 1, 1,\n\n // bottom\n 0, 0,\n 0, 1,\n 1, 1,\n 0, 0,\n 1, 1,\n 1, 0,\n\n // left side\n 0, 0,\n 0, 1,\n 1, 1,\n 0, 0,\n 1, 1,\n 1, 0,\n ];\n\n const normals = expandRLEData([\n // left column front\n // top rung front\n // middle rung front\n 18, 0, 0, 1,\n\n // left column back\n // top rung back\n // middle rung back\n 18, 0, 0, -1,\n\n // top\n 6, 0, 1, 0,\n\n // top rung front\n 6, 1, 0, 0,\n\n // under top rung\n 6, 0, -1, 0,\n\n // between top rung and middle\n 6, 1, 0, 0,\n\n // top of middle rung\n 6, 0, 1, 0,\n\n // front of middle rung\n 6, 1, 0, 0,\n\n // bottom of middle rung.\n 6, 0, -1, 0,\n\n // front of bottom\n 6, 1, 0, 0,\n\n // bottom\n 6, 0, -1, 0,\n\n // left side\n 6, -1, 0, 0,\n ]);\n\n const colors = expandRLEData([\n // left column front\n // top rung front\n // middle rung front\n 18, 200, 70, 120,\n\n // left column back\n // top rung back\n // middle rung back\n 18, 80, 70, 200,\n\n // top\n 6, 70, 200, 210,\n\n // top rung front\n 6, 200, 200, 70,\n\n // under top rung\n 6, 210, 100, 70,\n\n // between top rung and middle\n 6, 210, 160, 70,\n\n // top of middle rung\n 6, 70, 180, 210,\n\n // front of middle rung\n 6, 100, 70, 210,\n\n // bottom of middle rung.\n 6, 76, 210, 100,\n\n // front of bottom\n 6, 140, 210, 80,\n\n // bottom\n 6, 90, 130, 110,\n\n // left side\n 6, 160, 160, 220,\n ], [255]);\n\n const numVerts = positions.length / 3;\n\n const arrays = {\n position: createAugmentedTypedArray(3, numVerts),\n texcoord: createAugmentedTypedArray(2, numVerts),\n normal: createAugmentedTypedArray(3, numVerts),\n color: createAugmentedTypedArray(4, numVerts, Uint8Array),\n indices: createAugmentedTypedArray(3, numVerts / 3, Uint16Array),\n };\n\n arrays.position.push(positions);\n arrays.texcoord.push(texcoords);\n arrays.normal.push(normals);\n arrays.color.push(colors);\n\n for (let ii = 0; ii < numVerts; ++ii) {\n arrays.indices.push(ii);\n }\n\n return arrays;\n}\n\n/**\n * Creates crescent BufferInfo.\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} verticalRadius The vertical radius of the crescent.\n * @param {number} outerRadius The outer radius of the crescent.\n * @param {number} innerRadius The inner radius of the crescent.\n * @param {number} thickness The thickness of the crescent.\n * @param {number} subdivisionsDown number of steps around the crescent.\n * @param {number} [startOffset] Where to start arc. Default 0.\n * @param {number} [endOffset] Where to end arg. Default 1.\n * @return {module:twgl.BufferInfo} The created BufferInfo.\n * @memberOf module:twgl/primitives\n * @function createCresentBufferInfo\n */\n\n/**\n * Creates crescent buffers.\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} verticalRadius The vertical radius of the crescent.\n * @param {number} outerRadius The outer radius of the crescent.\n * @param {number} innerRadius The inner radius of the crescent.\n * @param {number} thickness The thickness of the crescent.\n * @param {number} subdivisionsDown number of steps around the crescent.\n * @param {number} [startOffset] Where to start arc. Default 0.\n * @param {number} [endOffset] Where to end arg. Default 1.\n * @return {Object.} The created buffers.\n * @memberOf module:twgl/primitives\n * @function createCresentBuffers\n */\n\n/**\n * Creates crescent vertices.\n *\n * @param {number} verticalRadius The vertical radius of the crescent.\n * @param {number} outerRadius The outer radius of the crescent.\n * @param {number} innerRadius The inner radius of the crescent.\n * @param {number} thickness The thickness of the crescent.\n * @param {number} subdivisionsDown number of steps around the crescent.\n * @param {number} [startOffset] Where to start arc. Default 0.\n * @param {number} [endOffset] Where to end arg. Default 1.\n * @return {Object.} The created vertices.\n * @memberOf module:twgl/primitives\n * @function createCresentBuffers\n */\n\n/**\n * Creates crescent BufferInfo.\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} verticalRadius The vertical radius of the crescent.\n * @param {number} outerRadius The outer radius of the crescent.\n * @param {number} innerRadius The inner radius of the crescent.\n * @param {number} thickness The thickness of the crescent.\n * @param {number} subdivisionsDown number of steps around the crescent.\n * @param {number} [startOffset] Where to start arc. Default 0.\n * @param {number} [endOffset] Where to end arg. Default 1.\n * @return {module:twgl.BufferInfo} The created BufferInfo.\n * @memberOf module:twgl/primitives\n * @function createCrescentBufferInfo\n */\n\n/**\n * Creates crescent buffers.\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} verticalRadius The vertical radius of the crescent.\n * @param {number} outerRadius The outer radius of the crescent.\n * @param {number} innerRadius The inner radius of the crescent.\n * @param {number} thickness The thickness of the crescent.\n * @param {number} subdivisionsDown number of steps around the crescent.\n * @param {number} [startOffset] Where to start arc. Default 0.\n * @param {number} [endOffset] Where to end arg. Default 1.\n * @return {Object.} The created buffers.\n * @memberOf module:twgl/primitives\n * @function createCrescentBuffers\n */\n\n/**\n * Creates crescent vertices.\n *\n * @param {number} verticalRadius The vertical radius of the crescent.\n * @param {number} outerRadius The outer radius of the crescent.\n * @param {number} innerRadius The inner radius of the crescent.\n * @param {number} thickness The thickness of the crescent.\n * @param {number} subdivisionsDown number of steps around the crescent.\n * @param {number} [startOffset] Where to start arc. Default 0.\n * @param {number} [endOffset] Where to end arg. Default 1.\n * @return {Object.} The created vertices.\n * @memberOf module:twgl/primitives\n */\n function createCrescentVertices(\n verticalRadius,\n outerRadius,\n innerRadius,\n thickness,\n subdivisionsDown,\n startOffset,\n endOffset) {\n if (subdivisionsDown <= 0) {\n throw new Error('subdivisionDown must be > 0');\n }\n\n startOffset = startOffset || 0;\n endOffset = endOffset || 1;\n\n const subdivisionsThick = 2;\n\n const offsetRange = endOffset - startOffset;\n const numVertices = (subdivisionsDown + 1) * 2 * (2 + subdivisionsThick);\n const positions = createAugmentedTypedArray(3, numVertices);\n const normals = createAugmentedTypedArray(3, numVertices);\n const texcoords = createAugmentedTypedArray(2, numVertices);\n\n function lerp(a, b, s) {\n return a + (b - a) * s;\n }\n\n function createArc(arcRadius, x, normalMult, normalAdd, uMult, uAdd) {\n for (let z = 0; z <= subdivisionsDown; z++) {\n const uBack = x / (subdivisionsThick - 1);\n const v = z / subdivisionsDown;\n const xBack = (uBack - 0.5) * 2;\n const angle = (startOffset + (v * offsetRange)) * Math.PI;\n const s = Math.sin(angle);\n const c = Math.cos(angle);\n const radius = lerp(verticalRadius, arcRadius, s);\n const px = xBack * thickness;\n const py = c * verticalRadius;\n const pz = s * radius;\n positions.push(px, py, pz);\n const n = v3.add(v3.multiply([0, s, c], normalMult), normalAdd);\n normals.push(n);\n texcoords.push(uBack * uMult + uAdd, v);\n }\n }\n\n // Generate the individual vertices in our vertex buffer.\n for (let x = 0; x < subdivisionsThick; x++) {\n const uBack = (x / (subdivisionsThick - 1) - 0.5) * 2;\n createArc(outerRadius, x, [1, 1, 1], [0, 0, 0], 1, 0);\n createArc(outerRadius, x, [0, 0, 0], [uBack, 0, 0], 0, 0);\n createArc(innerRadius, x, [1, 1, 1], [0, 0, 0], 1, 0);\n createArc(innerRadius, x, [0, 0, 0], [uBack, 0, 0], 0, 1);\n }\n\n // Do outer surface.\n const indices = createAugmentedTypedArray(3, (subdivisionsDown * 2) * (2 + subdivisionsThick), Uint16Array);\n\n function createSurface(leftArcOffset, rightArcOffset) {\n for (let z = 0; z < subdivisionsDown; ++z) {\n // Make triangle 1 of quad.\n indices.push(\n leftArcOffset + z + 0,\n leftArcOffset + z + 1,\n rightArcOffset + z + 0);\n\n // Make triangle 2 of quad.\n indices.push(\n leftArcOffset + z + 1,\n rightArcOffset + z + 1,\n rightArcOffset + z + 0);\n }\n }\n\n const numVerticesDown = subdivisionsDown + 1;\n // front\n createSurface(numVerticesDown * 0, numVerticesDown * 4);\n // right\n createSurface(numVerticesDown * 5, numVerticesDown * 7);\n // back\n createSurface(numVerticesDown * 6, numVerticesDown * 2);\n // left\n createSurface(numVerticesDown * 3, numVerticesDown * 1);\n\n return {\n position: positions,\n normal: normals,\n texcoord: texcoords,\n indices: indices,\n };\n}\n\n/**\n * Creates cylinder BufferInfo. The cylinder will be created around the origin\n * along the y-axis.\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} radius Radius of cylinder.\n * @param {number} height Height of cylinder.\n * @param {number} radialSubdivisions The number of subdivisions around the cylinder.\n * @param {number} verticalSubdivisions The number of subdivisions down the cylinder.\n * @param {boolean} [topCap] Create top cap. Default = true.\n * @param {boolean} [bottomCap] Create bottom cap. Default = true.\n * @return {module:twgl.BufferInfo} The created BufferInfo.\n * @memberOf module:twgl/primitives\n * @function createCylinderBufferInfo\n */\n\n /**\n * Creates cylinder buffers. The cylinder will be created around the origin\n * along the y-axis.\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} radius Radius of cylinder.\n * @param {number} height Height of cylinder.\n * @param {number} radialSubdivisions The number of subdivisions around the cylinder.\n * @param {number} verticalSubdivisions The number of subdivisions down the cylinder.\n * @param {boolean} [topCap] Create top cap. Default = true.\n * @param {boolean} [bottomCap] Create bottom cap. Default = true.\n * @return {Object.} The created buffers.\n * @memberOf module:twgl/primitives\n * @function createCylinderBuffers\n */\n\n /**\n * Creates cylinder vertices. The cylinder will be created around the origin\n * along the y-axis.\n *\n * @param {number} radius Radius of cylinder.\n * @param {number} height Height of cylinder.\n * @param {number} radialSubdivisions The number of subdivisions around the cylinder.\n * @param {number} verticalSubdivisions The number of subdivisions down the cylinder.\n * @param {boolean} [topCap] Create top cap. Default = true.\n * @param {boolean} [bottomCap] Create bottom cap. Default = true.\n * @return {Object.} The created vertices.\n * @memberOf module:twgl/primitives\n */\nfunction createCylinderVertices(\n radius,\n height,\n radialSubdivisions,\n verticalSubdivisions,\n topCap,\n bottomCap) {\n return createTruncatedConeVertices(\n radius,\n radius,\n height,\n radialSubdivisions,\n verticalSubdivisions,\n topCap,\n bottomCap);\n}\n\n/**\n * Creates BufferInfo for a torus\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} radius radius of center of torus circle.\n * @param {number} thickness radius of torus ring.\n * @param {number} radialSubdivisions The number of subdivisions around the torus.\n * @param {number} bodySubdivisions The number of subdivisions around the body torus.\n * @param {boolean} [startAngle] start angle in radians. Default = 0.\n * @param {boolean} [endAngle] end angle in radians. Default = Math.PI * 2.\n * @return {module:twgl.BufferInfo} The created BufferInfo.\n * @memberOf module:twgl/primitives\n * @function createTorusBufferInfo\n */\n\n/**\n * Creates buffers for a torus\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} radius radius of center of torus circle.\n * @param {number} thickness radius of torus ring.\n * @param {number} radialSubdivisions The number of subdivisions around the torus.\n * @param {number} bodySubdivisions The number of subdivisions around the body torus.\n * @param {boolean} [startAngle] start angle in radians. Default = 0.\n * @param {boolean} [endAngle] end angle in radians. Default = Math.PI * 2.\n * @return {Object.} The created buffers.\n * @memberOf module:twgl/primitives\n * @function createTorusBuffers\n */\n\n/**\n * Creates vertices for a torus\n *\n * @param {number} radius radius of center of torus circle.\n * @param {number} thickness radius of torus ring.\n * @param {number} radialSubdivisions The number of subdivisions around the torus.\n * @param {number} bodySubdivisions The number of subdivisions around the body torus.\n * @param {boolean} [startAngle] start angle in radians. Default = 0.\n * @param {boolean} [endAngle] end angle in radians. Default = Math.PI * 2.\n * @return {Object.} The created vertices.\n * @memberOf module:twgl/primitives\n */\nfunction createTorusVertices(\n radius,\n thickness,\n radialSubdivisions,\n bodySubdivisions,\n startAngle,\n endAngle) {\n if (radialSubdivisions < 3) {\n throw new Error('radialSubdivisions must be 3 or greater');\n }\n\n if (bodySubdivisions < 3) {\n throw new Error('verticalSubdivisions must be 3 or greater');\n }\n\n startAngle = startAngle || 0;\n endAngle = endAngle || Math.PI * 2;\n const range = endAngle - startAngle;\n\n const radialParts = radialSubdivisions + 1;\n const bodyParts = bodySubdivisions + 1;\n const numVertices = radialParts * bodyParts;\n const positions = createAugmentedTypedArray(3, numVertices);\n const normals = createAugmentedTypedArray(3, numVertices);\n const texcoords = createAugmentedTypedArray(2, numVertices);\n const indices = createAugmentedTypedArray(3, (radialSubdivisions) * (bodySubdivisions) * 2, Uint16Array);\n\n for (let slice = 0; slice < bodyParts; ++slice) {\n const v = slice / bodySubdivisions;\n const sliceAngle = v * Math.PI * 2;\n const sliceSin = Math.sin(sliceAngle);\n const ringRadius = radius + sliceSin * thickness;\n const ny = Math.cos(sliceAngle);\n const y = ny * thickness;\n for (let ring = 0; ring < radialParts; ++ring) {\n const u = ring / radialSubdivisions;\n const ringAngle = startAngle + u * range;\n const xSin = Math.sin(ringAngle);\n const zCos = Math.cos(ringAngle);\n const x = xSin * ringRadius;\n const z = zCos * ringRadius;\n const nx = xSin * sliceSin;\n const nz = zCos * sliceSin;\n positions.push(x, y, z);\n normals.push(nx, ny, nz);\n texcoords.push(u, 1 - v);\n }\n }\n\n for (let slice = 0; slice < bodySubdivisions; ++slice) { // eslint-disable-line\n for (let ring = 0; ring < radialSubdivisions; ++ring) { // eslint-disable-line\n const nextRingIndex = 1 + ring;\n const nextSliceIndex = 1 + slice;\n indices.push(radialParts * slice + ring,\n radialParts * nextSliceIndex + ring,\n radialParts * slice + nextRingIndex);\n indices.push(radialParts * nextSliceIndex + ring,\n radialParts * nextSliceIndex + nextRingIndex,\n radialParts * slice + nextRingIndex);\n }\n }\n\n return {\n position: positions,\n normal: normals,\n texcoord: texcoords,\n indices: indices,\n };\n}\n\n\n/**\n * Creates a disc BufferInfo. The disc will be in the xz plane, centered at\n * the origin. When creating, at least 3 divisions, or pie\n * pieces, need to be specified, otherwise the triangles making\n * up the disc will be degenerate. You can also specify the\n * number of radial pieces `stacks`. A value of 1 for\n * stacks will give you a simple disc of pie pieces. If you\n * want to create an annulus you can set `innerRadius` to a\n * value > 0. Finally, `stackPower` allows you to have the widths\n * increase or decrease as you move away from the center. This\n * is particularly useful when using the disc as a ground plane\n * with a fixed camera such that you don't need the resolution\n * of small triangles near the perimeter. For example, a value\n * of 2 will produce stacks whose outside radius increases with\n * the square of the stack index. A value of 1 will give uniform\n * stacks.\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} radius Radius of the ground plane.\n * @param {number} divisions Number of triangles in the ground plane (at least 3).\n * @param {number} [stacks] Number of radial divisions (default=1).\n * @param {number} [innerRadius] Default 0.\n * @param {number} [stackPower] Power to raise stack size to for decreasing width.\n * @return {module:twgl.BufferInfo} The created BufferInfo.\n * @memberOf module:twgl/primitives\n * @function createDiscBufferInfo\n */\n\n/**\n * Creates disc buffers. The disc will be in the xz plane, centered at\n * the origin. When creating, at least 3 divisions, or pie\n * pieces, need to be specified, otherwise the triangles making\n * up the disc will be degenerate. You can also specify the\n * number of radial pieces `stacks`. A value of 1 for\n * stacks will give you a simple disc of pie pieces. If you\n * want to create an annulus you can set `innerRadius` to a\n * value > 0. Finally, `stackPower` allows you to have the widths\n * increase or decrease as you move away from the center. This\n * is particularly useful when using the disc as a ground plane\n * with a fixed camera such that you don't need the resolution\n * of small triangles near the perimeter. For example, a value\n * of 2 will produce stacks whose outside radius increases with\n * the square of the stack index. A value of 1 will give uniform\n * stacks.\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext.\n * @param {number} radius Radius of the ground plane.\n * @param {number} divisions Number of triangles in the ground plane (at least 3).\n * @param {number} [stacks] Number of radial divisions (default=1).\n * @param {number} [innerRadius] Default 0.\n * @param {number} [stackPower] Power to raise stack size to for decreasing width.\n * @return {Object.} The created buffers.\n * @memberOf module:twgl/primitives\n * @function createDiscBuffers\n */\n\n/**\n * Creates disc vertices. The disc will be in the xz plane, centered at\n * the origin. When creating, at least 3 divisions, or pie\n * pieces, need to be specified, otherwise the triangles making\n * up the disc will be degenerate. You can also specify the\n * number of radial pieces `stacks`. A value of 1 for\n * stacks will give you a simple disc of pie pieces. If you\n * want to create an annulus you can set `innerRadius` to a\n * value > 0. Finally, `stackPower` allows you to have the widths\n * increase or decrease as you move away from the center. This\n * is particularly useful when using the disc as a ground plane\n * with a fixed camera such that you don't need the resolution\n * of small triangles near the perimeter. For example, a value\n * of 2 will produce stacks whose outside radius increases with\n * the square of the stack index. A value of 1 will give uniform\n * stacks.\n *\n * @param {number} radius Radius of the ground plane.\n * @param {number} divisions Number of triangles in the ground plane (at least 3).\n * @param {number} [stacks] Number of radial divisions (default=1).\n * @param {number} [innerRadius] Default 0.\n * @param {number} [stackPower] Power to raise stack size to for decreasing width.\n * @return {Object.} The created vertices.\n * @memberOf module:twgl/primitives\n */\nfunction createDiscVertices(\n radius,\n divisions,\n stacks,\n innerRadius,\n stackPower) {\n if (divisions < 3) {\n throw new Error('divisions must be at least 3');\n }\n\n stacks = stacks ? stacks : 1;\n stackPower = stackPower ? stackPower : 1;\n innerRadius = innerRadius ? innerRadius : 0;\n\n // Note: We don't share the center vertex because that would\n // mess up texture coordinates.\n const numVertices = (divisions + 1) * (stacks + 1);\n\n const positions = createAugmentedTypedArray(3, numVertices);\n const normals = createAugmentedTypedArray(3, numVertices);\n const texcoords = createAugmentedTypedArray(2, numVertices);\n const indices = createAugmentedTypedArray(3, stacks * divisions * 2, Uint16Array);\n\n let firstIndex = 0;\n const radiusSpan = radius - innerRadius;\n const pointsPerStack = divisions + 1;\n\n // Build the disk one stack at a time.\n for (let stack = 0; stack <= stacks; ++stack) {\n const stackRadius = innerRadius + radiusSpan * Math.pow(stack / stacks, stackPower);\n\n for (let i = 0; i <= divisions; ++i) {\n const theta = 2.0 * Math.PI * i / divisions;\n const x = stackRadius * Math.cos(theta);\n const z = stackRadius * Math.sin(theta);\n\n positions.push(x, 0, z);\n normals.push(0, 1, 0);\n texcoords.push(1 - (i / divisions), stack / stacks);\n if (stack > 0 && i !== divisions) {\n // a, b, c and d are the indices of the vertices of a quad. unless\n // the current stack is the one closest to the center, in which case\n // the vertices a and b connect to the center vertex.\n const a = firstIndex + (i + 1);\n const b = firstIndex + i;\n const c = firstIndex + i - pointsPerStack;\n const d = firstIndex + (i + 1) - pointsPerStack;\n\n // Make a quad of the vertices a, b, c, d.\n indices.push(a, b, c);\n indices.push(a, c, d);\n }\n }\n\n firstIndex += divisions + 1;\n }\n\n return {\n position: positions,\n normal: normals,\n texcoord: texcoords,\n indices: indices,\n };\n}\n\n/**\n * creates a random integer between 0 and range - 1 inclusive.\n * @param {number} range\n * @return {number} random value between 0 and range - 1 inclusive.\n * @private\n */\nfunction randInt(range) {\n return Math.random() * range | 0;\n}\n\n/**\n * Used to supply random colors\n * @callback RandomColorFunc\n * @param {number} ndx index of triangle/quad if unindexed or index of vertex if indexed\n * @param {number} channel 0 = red, 1 = green, 2 = blue, 3 = alpha\n * @return {number} a number from 0 to 255\n * @memberOf module:twgl/primitives\n */\n\n/**\n * @typedef {Object} RandomVerticesOptions\n * @property {number} [vertsPerColor] Defaults to 3 for non-indexed vertices\n * @property {module:twgl/primitives.RandomColorFunc} [rand] A function to generate random numbers\n * @memberOf module:twgl/primitives\n */\n\n/**\n * Creates an augmentedTypedArray of random vertex colors.\n * If the vertices are indexed (have an indices array) then will\n * just make random colors. Otherwise assumes they are triangles\n * and makes one random color for every 3 vertices.\n * @param {Object.} vertices Vertices as returned from one of the createXXXVertices functions.\n * @param {module:twgl/primitives.RandomVerticesOptions} [options] options.\n * @return {Object.} same vertices as passed in with `color` added.\n * @memberOf module:twgl/primitives\n */\nfunction makeRandomVertexColors(vertices, options) {\n options = options || {};\n const numElements = vertices.position.numElements;\n const vColors = createAugmentedTypedArray(4, numElements, Uint8Array);\n const rand = options.rand || function(ndx, channel) {\n return channel < 3 ? randInt(256) : 255;\n };\n vertices.color = vColors;\n if (vertices.indices) {\n // just make random colors if index\n for (let ii = 0; ii < numElements; ++ii) {\n vColors.push(rand(ii, 0), rand(ii, 1), rand(ii, 2), rand(ii, 3));\n }\n } else {\n // make random colors per triangle\n const numVertsPerColor = options.vertsPerColor || 3;\n const numSets = numElements / numVertsPerColor;\n for (let ii = 0; ii < numSets; ++ii) { // eslint-disable-line\n const color = [rand(ii, 0), rand(ii, 1), rand(ii, 2), rand(ii, 3)];\n for (let jj = 0; jj < numVertsPerColor; ++jj) {\n vColors.push(color);\n }\n }\n }\n return vertices;\n}\n\n/**\n * creates a function that calls fn to create vertices and then\n * creates a buffers for them\n * @private\n */\nfunction createBufferFunc(fn) {\n return function(gl) {\n const arrays = fn.apply(this, Array.prototype.slice.call(arguments, 1));\n return attributes.createBuffersFromArrays(gl, arrays);\n };\n}\n\n/**\n * creates a function that calls fn to create vertices and then\n * creates a bufferInfo object for them\n * @private\n */\nfunction createBufferInfoFunc(fn) {\n return function(gl) {\n const arrays = fn.apply(null, Array.prototype.slice.call(arguments, 1));\n return attributes.createBufferInfoFromArrays(gl, arrays);\n };\n}\n\nconst arraySpecPropertyNames = [\n \"numComponents\",\n \"size\",\n \"type\",\n \"normalize\",\n \"stride\",\n \"offset\",\n \"attrib\",\n \"name\",\n \"attribName\",\n];\n\n/**\n * Copy elements from one array to another\n *\n * @param {Array|TypedArray} src source array\n * @param {Array|TypedArray} dst dest array\n * @param {number} dstNdx index in dest to copy src\n * @param {number} [offset] offset to add to copied values\n * @private\n */\nfunction copyElements(src, dst, dstNdx, offset) {\n offset = offset || 0;\n const length = src.length;\n for (let ii = 0; ii < length; ++ii) {\n dst[dstNdx + ii] = src[ii] + offset;\n }\n}\n\n/**\n * Creates an array of the same time\n *\n * @param {(number[]|ArrayBufferView|module:twgl.FullArraySpec)} srcArray array who's type to copy\n * @param {number} length size of new array\n * @return {(number[]|ArrayBufferView|module:twgl.FullArraySpec)} array with same type as srcArray\n * @private\n */\nfunction createArrayOfSameType(srcArray, length) {\n const arraySrc = getArray(srcArray);\n const newArray = new arraySrc.constructor(length);\n let newArraySpec = newArray;\n // If it appears to have been augmented make new one augmented\n if (arraySrc.numComponents && arraySrc.numElements) {\n augmentTypedArray(newArray, arraySrc.numComponents);\n }\n // If it was a full spec make new one a full spec\n if (srcArray.data) {\n newArraySpec = {\n data: newArray,\n };\n helper.copyNamedProperties(arraySpecPropertyNames, srcArray, newArraySpec);\n }\n return newArraySpec;\n}\n\n/**\n * Concatenates sets of vertices\n *\n * Assumes the vertices match in composition. For example\n * if one set of vertices has positions, normals, and indices\n * all sets of vertices must have positions, normals, and indices\n * and of the same type.\n *\n * Example:\n *\n * const cubeVertices = twgl.primitives.createCubeVertices(2);\n * const sphereVertices = twgl.primitives.createSphereVertices(1, 10, 10);\n * // move the sphere 2 units up\n * twgl.primitives.reorientVertices(\n * sphereVertices, twgl.m4.translation([0, 2, 0]));\n * // merge the sphere with the cube\n * const cubeSphereVertices = twgl.primitives.concatVertices(\n * [cubeVertices, sphereVertices]);\n * // turn them into WebGL buffers and attrib data\n * const bufferInfo = twgl.createBufferInfoFromArrays(gl, cubeSphereVertices);\n *\n * @param {module:twgl.Arrays[]} arrays Array of arrays of vertices\n * @return {module:twgl.Arrays} The concatenated vertices.\n * @memberOf module:twgl/primitives\n */\nfunction concatVertices(arrayOfArrays) {\n const names = {};\n let baseName;\n // get names of all arrays.\n // and numElements for each set of vertices\n for (let ii = 0; ii < arrayOfArrays.length; ++ii) {\n const arrays = arrayOfArrays[ii];\n Object.keys(arrays).forEach(function(name) { // eslint-disable-line\n if (!names[name]) {\n names[name] = [];\n }\n if (!baseName && name !== 'indices') {\n baseName = name;\n }\n const arrayInfo = arrays[name];\n const numComponents = getNumComponents(arrayInfo, name);\n const array = getArray(arrayInfo);\n const numElements = array.length / numComponents;\n names[name].push(numElements);\n });\n }\n\n // compute length of combined array\n // and return one for reference\n function getLengthOfCombinedArrays(name) {\n let length = 0;\n let arraySpec;\n for (let ii = 0; ii < arrayOfArrays.length; ++ii) {\n const arrays = arrayOfArrays[ii];\n const arrayInfo = arrays[name];\n const array = getArray(arrayInfo);\n length += array.length;\n if (!arraySpec || arrayInfo.data) {\n arraySpec = arrayInfo;\n }\n }\n return {\n length: length,\n spec: arraySpec,\n };\n }\n\n function copyArraysToNewArray(name, base, newArray) {\n let baseIndex = 0;\n let offset = 0;\n for (let ii = 0; ii < arrayOfArrays.length; ++ii) {\n const arrays = arrayOfArrays[ii];\n const arrayInfo = arrays[name];\n const array = getArray(arrayInfo);\n if (name === 'indices') {\n copyElements(array, newArray, offset, baseIndex);\n baseIndex += base[ii];\n } else {\n copyElements(array, newArray, offset);\n }\n offset += array.length;\n }\n }\n\n const base = names[baseName];\n\n const newArrays = {};\n Object.keys(names).forEach(function(name) {\n const info = getLengthOfCombinedArrays(name);\n const newArraySpec = createArrayOfSameType(info.spec, info.length);\n copyArraysToNewArray(name, base, getArray(newArraySpec));\n newArrays[name] = newArraySpec;\n });\n return newArrays;\n}\n\n/**\n * Creates a duplicate set of vertices\n *\n * This is useful for calling reorientVertices when you\n * also want to keep the original available\n *\n * @param {module:twgl.Arrays} arrays of vertices\n * @return {module:twgl.Arrays} The duplicated vertices.\n * @memberOf module:twgl/primitives\n */\nfunction duplicateVertices(arrays) {\n const newArrays = {};\n Object.keys(arrays).forEach(function(name) {\n const arraySpec = arrays[name];\n const srcArray = getArray(arraySpec);\n const newArraySpec = createArrayOfSameType(arraySpec, srcArray.length);\n copyElements(srcArray, getArray(newArraySpec), 0);\n newArrays[name] = newArraySpec;\n });\n return newArrays;\n}\n\nconst create3DFBufferInfo = createBufferInfoFunc(create3DFVertices);\nconst create3DFBuffers = createBufferFunc(create3DFVertices);\nconst createCubeBufferInfo = createBufferInfoFunc(createCubeVertices);\nconst createCubeBuffers = createBufferFunc(createCubeVertices);\nconst createPlaneBufferInfo = createBufferInfoFunc(createPlaneVertices);\nconst createPlaneBuffers = createBufferFunc(createPlaneVertices);\nconst createSphereBufferInfo = createBufferInfoFunc(createSphereVertices);\nconst createSphereBuffers = createBufferFunc(createSphereVertices);\nconst createTruncatedConeBufferInfo = createBufferInfoFunc(createTruncatedConeVertices);\nconst createTruncatedConeBuffers = createBufferFunc(createTruncatedConeVertices);\nconst createXYQuadBufferInfo = createBufferInfoFunc(createXYQuadVertices);\nconst createXYQuadBuffers = createBufferFunc(createXYQuadVertices);\nconst createCrescentBufferInfo = createBufferInfoFunc(createCrescentVertices);\nconst createCrescentBuffers = createBufferFunc(createCrescentVertices);\nconst createCylinderBufferInfo = createBufferInfoFunc(createCylinderVertices);\nconst createCylinderBuffers = createBufferFunc(createCylinderVertices);\nconst createTorusBufferInfo = createBufferInfoFunc(createTorusVertices);\nconst createTorusBuffers = createBufferFunc(createTorusVertices);\nconst createDiscBufferInfo = createBufferInfoFunc(createDiscVertices);\nconst createDiscBuffers = createBufferFunc(createDiscVertices);\n\n// these were mis-spelled until 4.12\nconst createCresentBufferInfo = createCrescentBufferInfo;\nconst createCresentBuffers = createCrescentBuffers;\nconst createCresentVertices = createCrescentVertices;\n\nexport {\n create3DFBufferInfo,\n create3DFBuffers,\n create3DFVertices,\n createAugmentedTypedArray,\n createCubeBufferInfo,\n createCubeBuffers,\n createCubeVertices,\n createPlaneBufferInfo,\n createPlaneBuffers,\n createPlaneVertices,\n createSphereBufferInfo,\n createSphereBuffers,\n createSphereVertices,\n createTruncatedConeBufferInfo,\n createTruncatedConeBuffers,\n createTruncatedConeVertices,\n createXYQuadBufferInfo,\n createXYQuadBuffers,\n createXYQuadVertices,\n createCresentBufferInfo,\n createCresentBuffers,\n createCresentVertices,\n createCrescentBufferInfo,\n createCrescentBuffers,\n createCrescentVertices,\n createCylinderBufferInfo,\n createCylinderBuffers,\n createCylinderVertices,\n createTorusBufferInfo,\n createTorusBuffers,\n createTorusVertices,\n createDiscBufferInfo,\n createDiscBuffers,\n createDiscVertices,\n deindexVertices,\n flattenNormals,\n makeRandomVertexColors,\n reorientDirections,\n reorientNormals,\n reorientPositions,\n reorientVertices,\n concatVertices,\n duplicateVertices,\n};\n\n","/*\n * Copyright 2019 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n\nimport * as utils from './utils.js';\nimport * as helper from './helper.js';\n\n/**\n * Low level shader program related functions\n *\n * You should generally not need to use these functions. They are provided\n * for those cases where you're doing something out of the ordinary\n * and you need lower level access.\n *\n * For backward compatibility they are available at both `twgl.programs` and `twgl`\n * itself\n *\n * See {@link module:twgl} for core functions\n *\n * @module twgl/programs\n */\n\nconst error = helper.error;\nconst warn = helper.warn;\nfunction getElementById(id) {\n return (typeof document !== 'undefined' && document.getElementById)\n ? document.getElementById(id)\n : null;\n}\n\nconst TEXTURE0 = 0x84c0;\nconst DYNAMIC_DRAW = 0x88e8;\n\nconst ARRAY_BUFFER = 0x8892;\nconst ELEMENT_ARRAY_BUFFER = 0x8893;\nconst UNIFORM_BUFFER = 0x8a11;\nconst TRANSFORM_FEEDBACK_BUFFER = 0x8c8e;\n\nconst TRANSFORM_FEEDBACK = 0x8e22;\n\nconst COMPILE_STATUS = 0x8b81;\nconst LINK_STATUS = 0x8b82;\nconst FRAGMENT_SHADER = 0x8b30;\nconst VERTEX_SHADER = 0x8b31;\nconst SEPARATE_ATTRIBS = 0x8c8d;\n\nconst ACTIVE_UNIFORMS = 0x8b86;\nconst ACTIVE_ATTRIBUTES = 0x8b89;\nconst TRANSFORM_FEEDBACK_VARYINGS = 0x8c83;\nconst ACTIVE_UNIFORM_BLOCKS = 0x8a36;\nconst UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER = 0x8a44;\nconst UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER = 0x8a46;\nconst UNIFORM_BLOCK_DATA_SIZE = 0x8a40;\nconst UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES = 0x8a43;\n\nconst FLOAT = 0x1406;\nconst FLOAT_VEC2 = 0x8B50;\nconst FLOAT_VEC3 = 0x8B51;\nconst FLOAT_VEC4 = 0x8B52;\nconst INT = 0x1404;\nconst INT_VEC2 = 0x8B53;\nconst INT_VEC3 = 0x8B54;\nconst INT_VEC4 = 0x8B55;\nconst BOOL = 0x8B56;\nconst BOOL_VEC2 = 0x8B57;\nconst BOOL_VEC3 = 0x8B58;\nconst BOOL_VEC4 = 0x8B59;\nconst FLOAT_MAT2 = 0x8B5A;\nconst FLOAT_MAT3 = 0x8B5B;\nconst FLOAT_MAT4 = 0x8B5C;\nconst SAMPLER_2D = 0x8B5E;\nconst SAMPLER_CUBE = 0x8B60;\nconst SAMPLER_3D = 0x8B5F;\nconst SAMPLER_2D_SHADOW = 0x8B62;\nconst FLOAT_MAT2x3 = 0x8B65;\nconst FLOAT_MAT2x4 = 0x8B66;\nconst FLOAT_MAT3x2 = 0x8B67;\nconst FLOAT_MAT3x4 = 0x8B68;\nconst FLOAT_MAT4x2 = 0x8B69;\nconst FLOAT_MAT4x3 = 0x8B6A;\nconst SAMPLER_2D_ARRAY = 0x8DC1;\nconst SAMPLER_2D_ARRAY_SHADOW = 0x8DC4;\nconst SAMPLER_CUBE_SHADOW = 0x8DC5;\nconst UNSIGNED_INT = 0x1405;\nconst UNSIGNED_INT_VEC2 = 0x8DC6;\nconst UNSIGNED_INT_VEC3 = 0x8DC7;\nconst UNSIGNED_INT_VEC4 = 0x8DC8;\nconst INT_SAMPLER_2D = 0x8DCA;\nconst INT_SAMPLER_3D = 0x8DCB;\nconst INT_SAMPLER_CUBE = 0x8DCC;\nconst INT_SAMPLER_2D_ARRAY = 0x8DCF;\nconst UNSIGNED_INT_SAMPLER_2D = 0x8DD2;\nconst UNSIGNED_INT_SAMPLER_3D = 0x8DD3;\nconst UNSIGNED_INT_SAMPLER_CUBE = 0x8DD4;\nconst UNSIGNED_INT_SAMPLER_2D_ARRAY = 0x8DD7;\n\nconst TEXTURE_2D = 0x0DE1;\nconst TEXTURE_CUBE_MAP = 0x8513;\nconst TEXTURE_3D = 0x806F;\nconst TEXTURE_2D_ARRAY = 0x8C1A;\n\nconst typeMap = {};\n\n/**\n * Returns the corresponding bind point for a given sampler type\n */\nfunction getBindPointForSamplerType(gl, type) {\n return typeMap[type].bindPoint;\n}\n\n// This kind of sucks! If you could compose functions as in `var fn = gl[name];`\n// this code could be a lot smaller but that is sadly really slow (T_T)\n\nfunction floatSetter(gl, location) {\n return function(v) {\n gl.uniform1f(location, v);\n };\n}\n\nfunction floatArraySetter(gl, location) {\n return function(v) {\n gl.uniform1fv(location, v);\n };\n}\n\nfunction floatVec2Setter(gl, location) {\n return function(v) {\n gl.uniform2fv(location, v);\n };\n}\n\nfunction floatVec3Setter(gl, location) {\n return function(v) {\n gl.uniform3fv(location, v);\n };\n}\n\nfunction floatVec4Setter(gl, location) {\n return function(v) {\n gl.uniform4fv(location, v);\n };\n}\n\nfunction intSetter(gl, location) {\n return function(v) {\n gl.uniform1i(location, v);\n };\n}\n\nfunction intArraySetter(gl, location) {\n return function(v) {\n gl.uniform1iv(location, v);\n };\n}\n\nfunction intVec2Setter(gl, location) {\n return function(v) {\n gl.uniform2iv(location, v);\n };\n}\n\nfunction intVec3Setter(gl, location) {\n return function(v) {\n gl.uniform3iv(location, v);\n };\n}\n\nfunction intVec4Setter(gl, location) {\n return function(v) {\n gl.uniform4iv(location, v);\n };\n}\n\nfunction uintSetter(gl, location) {\n return function(v) {\n gl.uniform1ui(location, v);\n };\n}\n\nfunction uintArraySetter(gl, location) {\n return function(v) {\n gl.uniform1uiv(location, v);\n };\n}\n\nfunction uintVec2Setter(gl, location) {\n return function(v) {\n gl.uniform2uiv(location, v);\n };\n}\n\nfunction uintVec3Setter(gl, location) {\n return function(v) {\n gl.uniform3uiv(location, v);\n };\n}\n\nfunction uintVec4Setter(gl, location) {\n return function(v) {\n gl.uniform4uiv(location, v);\n };\n}\n\nfunction floatMat2Setter(gl, location) {\n return function(v) {\n gl.uniformMatrix2fv(location, false, v);\n };\n}\n\nfunction floatMat3Setter(gl, location) {\n return function(v) {\n gl.uniformMatrix3fv(location, false, v);\n };\n}\n\nfunction floatMat4Setter(gl, location) {\n return function(v) {\n gl.uniformMatrix4fv(location, false, v);\n };\n}\n\nfunction floatMat23Setter(gl, location) {\n return function(v) {\n gl.uniformMatrix2x3fv(location, false, v);\n };\n}\n\nfunction floatMat32Setter(gl, location) {\n return function(v) {\n gl.uniformMatrix3x2fv(location, false, v);\n };\n}\n\nfunction floatMat24Setter(gl, location) {\n return function(v) {\n gl.uniformMatrix2x4fv(location, false, v);\n };\n}\n\nfunction floatMat42Setter(gl, location) {\n return function(v) {\n gl.uniformMatrix4x2fv(location, false, v);\n };\n}\n\nfunction floatMat34Setter(gl, location) {\n return function(v) {\n gl.uniformMatrix3x4fv(location, false, v);\n };\n}\n\nfunction floatMat43Setter(gl, location) {\n return function(v) {\n gl.uniformMatrix4x3fv(location, false, v);\n };\n}\n\nfunction samplerSetter(gl, type, unit, location) {\n const bindPoint = getBindPointForSamplerType(gl, type);\n return utils.isWebGL2(gl) ? function(textureOrPair) {\n let texture;\n let sampler;\n if (helper.isTexture(gl, textureOrPair)) {\n texture = textureOrPair;\n sampler = null;\n } else {\n texture = textureOrPair.texture;\n sampler = textureOrPair.sampler;\n }\n gl.uniform1i(location, unit);\n gl.activeTexture(TEXTURE0 + unit);\n gl.bindTexture(bindPoint, texture);\n gl.bindSampler(unit, sampler);\n } : function(texture) {\n gl.uniform1i(location, unit);\n gl.activeTexture(TEXTURE0 + unit);\n gl.bindTexture(bindPoint, texture);\n };\n}\n\nfunction samplerArraySetter(gl, type, unit, location, size) {\n const bindPoint = getBindPointForSamplerType(gl, type);\n const units = new Int32Array(size);\n for (let ii = 0; ii < size; ++ii) {\n units[ii] = unit + ii;\n }\n\n return utils.isWebGL2(gl) ? function(textures) {\n gl.uniform1iv(location, units);\n textures.forEach(function(textureOrPair, index) {\n gl.activeTexture(TEXTURE0 + units[index]);\n let texture;\n let sampler;\n if (helper.isTexture(gl, textureOrPair)) {\n texture = textureOrPair;\n sampler = null;\n } else {\n texture = textureOrPair.texture;\n sampler = textureOrPair.sampler;\n }\n gl.bindSampler(unit, sampler);\n gl.bindTexture(bindPoint, texture);\n });\n } : function(textures) {\n gl.uniform1iv(location, units);\n textures.forEach(function(texture, index) {\n gl.activeTexture(TEXTURE0 + units[index]);\n gl.bindTexture(bindPoint, texture);\n });\n };\n}\n\ntypeMap[FLOAT] = { Type: Float32Array, size: 4, setter: floatSetter, arraySetter: floatArraySetter, };\ntypeMap[FLOAT_VEC2] = { Type: Float32Array, size: 8, setter: floatVec2Setter, };\ntypeMap[FLOAT_VEC3] = { Type: Float32Array, size: 12, setter: floatVec3Setter, };\ntypeMap[FLOAT_VEC4] = { Type: Float32Array, size: 16, setter: floatVec4Setter, };\ntypeMap[INT] = { Type: Int32Array, size: 4, setter: intSetter, arraySetter: intArraySetter, };\ntypeMap[INT_VEC2] = { Type: Int32Array, size: 8, setter: intVec2Setter, };\ntypeMap[INT_VEC3] = { Type: Int32Array, size: 12, setter: intVec3Setter, };\ntypeMap[INT_VEC4] = { Type: Int32Array, size: 16, setter: intVec4Setter, };\ntypeMap[UNSIGNED_INT] = { Type: Uint32Array, size: 4, setter: uintSetter, arraySetter: uintArraySetter, };\ntypeMap[UNSIGNED_INT_VEC2] = { Type: Uint32Array, size: 8, setter: uintVec2Setter, };\ntypeMap[UNSIGNED_INT_VEC3] = { Type: Uint32Array, size: 12, setter: uintVec3Setter, };\ntypeMap[UNSIGNED_INT_VEC4] = { Type: Uint32Array, size: 16, setter: uintVec4Setter, };\ntypeMap[BOOL] = { Type: Uint32Array, size: 4, setter: intSetter, arraySetter: intArraySetter, };\ntypeMap[BOOL_VEC2] = { Type: Uint32Array, size: 8, setter: intVec2Setter, };\ntypeMap[BOOL_VEC3] = { Type: Uint32Array, size: 12, setter: intVec3Setter, };\ntypeMap[BOOL_VEC4] = { Type: Uint32Array, size: 16, setter: intVec4Setter, };\ntypeMap[FLOAT_MAT2] = { Type: Float32Array, size: 16, setter: floatMat2Setter, };\ntypeMap[FLOAT_MAT3] = { Type: Float32Array, size: 36, setter: floatMat3Setter, };\ntypeMap[FLOAT_MAT4] = { Type: Float32Array, size: 64, setter: floatMat4Setter, };\ntypeMap[FLOAT_MAT2x3] = { Type: Float32Array, size: 24, setter: floatMat23Setter, };\ntypeMap[FLOAT_MAT2x4] = { Type: Float32Array, size: 32, setter: floatMat24Setter, };\ntypeMap[FLOAT_MAT3x2] = { Type: Float32Array, size: 24, setter: floatMat32Setter, };\ntypeMap[FLOAT_MAT3x4] = { Type: Float32Array, size: 48, setter: floatMat34Setter, };\ntypeMap[FLOAT_MAT4x2] = { Type: Float32Array, size: 32, setter: floatMat42Setter, };\ntypeMap[FLOAT_MAT4x3] = { Type: Float32Array, size: 48, setter: floatMat43Setter, };\ntypeMap[SAMPLER_2D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D, };\ntypeMap[SAMPLER_CUBE] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_CUBE_MAP, };\ntypeMap[SAMPLER_3D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_3D, };\ntypeMap[SAMPLER_2D_SHADOW] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D, };\ntypeMap[SAMPLER_2D_ARRAY] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D_ARRAY, };\ntypeMap[SAMPLER_2D_ARRAY_SHADOW] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D_ARRAY, };\ntypeMap[SAMPLER_CUBE_SHADOW] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_CUBE_MAP, };\ntypeMap[INT_SAMPLER_2D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D, };\ntypeMap[INT_SAMPLER_3D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_3D, };\ntypeMap[INT_SAMPLER_CUBE] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_CUBE_MAP, };\ntypeMap[INT_SAMPLER_2D_ARRAY] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D_ARRAY, };\ntypeMap[UNSIGNED_INT_SAMPLER_2D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D, };\ntypeMap[UNSIGNED_INT_SAMPLER_3D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_3D, };\ntypeMap[UNSIGNED_INT_SAMPLER_CUBE] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_CUBE_MAP, };\ntypeMap[UNSIGNED_INT_SAMPLER_2D_ARRAY] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D_ARRAY, };\n\nfunction floatAttribSetter(gl, index) {\n return function(b) {\n if (b.value) {\n gl.disableVertexAttribArray(index);\n switch (b.value.length) {\n case 4:\n gl.vertexAttrib4fv(index, b.value);\n break;\n case 3:\n gl.vertexAttrib3fv(index, b.value);\n break;\n case 2:\n gl.vertexAttrib2fv(index, b.value);\n break;\n case 1:\n gl.vertexAttrib1fv(index, b.value);\n break;\n default:\n throw new Error('the length of a float constant value must be between 1 and 4!');\n }\n } else {\n gl.bindBuffer(ARRAY_BUFFER, b.buffer);\n gl.enableVertexAttribArray(index);\n gl.vertexAttribPointer(\n index, b.numComponents || b.size, b.type || FLOAT, b.normalize || false, b.stride || 0, b.offset || 0);\n if (b.divisor !== undefined) {\n gl.vertexAttribDivisor(index, b.divisor);\n }\n }\n };\n}\n\nfunction intAttribSetter(gl, index) {\n return function(b) {\n if (b.value) {\n gl.disableVertexAttribArray(index);\n if (b.value.length === 4) {\n gl.vertexAttrib4iv(index, b.value);\n } else {\n throw new Error('The length of an integer constant value must be 4!');\n }\n } else {\n gl.bindBuffer(ARRAY_BUFFER, b.buffer);\n gl.enableVertexAttribArray(index);\n gl.vertexAttribIPointer(\n index, b.numComponents || b.size, b.type || INT, b.stride || 0, b.offset || 0);\n if (b.divisor !== undefined) {\n gl.vertexAttribDivisor(index, b.divisor);\n }\n }\n };\n}\n\nfunction uintAttribSetter(gl, index) {\n return function(b) {\n if (b.value) {\n gl.disableVertexAttribArray(index);\n if (b.value.length === 4) {\n gl.vertexAttrib4uiv(index, b.value);\n } else {\n throw new Error('The length of an unsigned integer constant value must be 4!');\n }\n } else {\n gl.bindBuffer(ARRAY_BUFFER, b.buffer);\n gl.enableVertexAttribArray(index);\n gl.vertexAttribIPointer(\n index, b.numComponents || b.size, b.type || UNSIGNED_INT, b.stride || 0, b.offset || 0);\n if (b.divisor !== undefined) {\n gl.vertexAttribDivisor(index, b.divisor);\n }\n }\n };\n}\n\nfunction matAttribSetter(gl, index, typeInfo) {\n const defaultSize = typeInfo.size;\n const count = typeInfo.count;\n\n return function(b) {\n gl.bindBuffer(ARRAY_BUFFER, b.buffer);\n const numComponents = b.size || b.numComponents || defaultSize;\n const size = numComponents / count;\n const type = b.type || FLOAT;\n const typeInfo = typeMap[type];\n const stride = typeInfo.size * numComponents;\n const normalize = b.normalize || false;\n const offset = b.offset || 0;\n const rowOffset = stride / count;\n for (let i = 0; i < count; ++i) {\n gl.enableVertexAttribArray(index + i);\n gl.vertexAttribPointer(\n index + i, size, type, normalize, stride, offset + rowOffset * i);\n if (b.divisor !== undefined) {\n gl.vertexAttribDivisor(index + i, b.divisor);\n }\n }\n };\n}\n\n\n\nconst attrTypeMap = {};\nattrTypeMap[FLOAT] = { size: 4, setter: floatAttribSetter, };\nattrTypeMap[FLOAT_VEC2] = { size: 8, setter: floatAttribSetter, };\nattrTypeMap[FLOAT_VEC3] = { size: 12, setter: floatAttribSetter, };\nattrTypeMap[FLOAT_VEC4] = { size: 16, setter: floatAttribSetter, };\nattrTypeMap[INT] = { size: 4, setter: intAttribSetter, };\nattrTypeMap[INT_VEC2] = { size: 8, setter: intAttribSetter, };\nattrTypeMap[INT_VEC3] = { size: 12, setter: intAttribSetter, };\nattrTypeMap[INT_VEC4] = { size: 16, setter: intAttribSetter, };\nattrTypeMap[UNSIGNED_INT] = { size: 4, setter: uintAttribSetter, };\nattrTypeMap[UNSIGNED_INT_VEC2] = { size: 8, setter: uintAttribSetter, };\nattrTypeMap[UNSIGNED_INT_VEC3] = { size: 12, setter: uintAttribSetter, };\nattrTypeMap[UNSIGNED_INT_VEC4] = { size: 16, setter: uintAttribSetter, };\nattrTypeMap[BOOL] = { size: 4, setter: intAttribSetter, };\nattrTypeMap[BOOL_VEC2] = { size: 8, setter: intAttribSetter, };\nattrTypeMap[BOOL_VEC3] = { size: 12, setter: intAttribSetter, };\nattrTypeMap[BOOL_VEC4] = { size: 16, setter: intAttribSetter, };\nattrTypeMap[FLOAT_MAT2] = { size: 4, setter: matAttribSetter, count: 2, };\nattrTypeMap[FLOAT_MAT3] = { size: 9, setter: matAttribSetter, count: 3, };\nattrTypeMap[FLOAT_MAT4] = { size: 16, setter: matAttribSetter, count: 4, };\n\n// make sure we don't see a global gl\nconst gl = undefined; /* eslint-disable-line */ /* lgtm [js/unused-local-variable] */\n\n/**\n * Error Callback\n * @callback ErrorCallback\n * @param {string} msg error message.\n * @param {number} [lineOffset] amount to add to line number\n * @memberOf module:twgl\n */\n\nfunction addLineNumbers(src, lineOffset) {\n lineOffset = lineOffset || 0;\n ++lineOffset;\n\n return src.split(\"\\n\").map(function(line, ndx) {\n return (ndx + lineOffset) + \": \" + line;\n }).join(\"\\n\");\n}\n\nconst spaceRE = /^[ \\t]*\\n/;\n\n/**\n * Loads a shader.\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.\n * @param {string} shaderSource The shader source.\n * @param {number} shaderType The type of shader.\n * @param {module:twgl.ErrorCallback} opt_errorCallback callback for errors.\n * @return {WebGLShader} The created shader.\n * @private\n */\nfunction loadShader(gl, shaderSource, shaderType, opt_errorCallback) {\n const errFn = opt_errorCallback || error;\n // Create the shader object\n const shader = gl.createShader(shaderType);\n\n // Remove the first end of line because WebGL 2.0 requires\n // #version 300 es\n // as the first line. No whitespace allowed before that line\n // so\n //\n // \n //\n // Has one line before it which is invalid according to GLSL ES 3.00\n //\n let lineOffset = 0;\n if (spaceRE.test(shaderSource)) {\n lineOffset = 1;\n shaderSource = shaderSource.replace(spaceRE, '');\n }\n\n // Load the shader source\n gl.shaderSource(shader, shaderSource);\n\n // Compile the shader\n gl.compileShader(shader);\n\n // Check the compile status\n const compiled = gl.getShaderParameter(shader, COMPILE_STATUS);\n if (!compiled) {\n // Something went wrong during compilation; get the error\n const lastError = gl.getShaderInfoLog(shader);\n errFn(addLineNumbers(shaderSource, lineOffset) + \"\\n*** Error compiling shader: \" + lastError);\n gl.deleteShader(shader);\n return null;\n }\n\n return shader;\n}\n\n/**\n * @typedef {Object} ProgramOptions\n * @property {function(string)} [errorCallback] callback for errors\n * @property {Object.} [attribLocations] a attribute name to location map\n * @property {(module:twgl.BufferInfo|Object.|string[])} [transformFeedbackVaryings] If passed\n * a BufferInfo will use the attribs names inside. If passed an object of AttribInfos will use the names from that object. Otherwise\n * you can pass an array of names.\n * @property {number} [transformFeedbackMode] the mode to pass `gl.transformFeedbackVaryings`. Defaults to `SEPARATE_ATTRIBS`.\n * @memberOf module:twgl\n */\n\n/**\n * Gets the program options based on all these optional arguments\n * @param {module:twgl.ProgramOptions|string[]} [opt_attribs] Options for the program or an array of attribs names. Locations will be assigned by index if not passed in\n * @param {number[]} [opt_locations] The locations for the. A parallel array to opt_attribs letting you assign locations.\n * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console\n * on error. If you want something else pass an callback. It's passed an error message.\n * @return {module:twgl.ProgramOptions} an instance of ProgramOptions based on the arguments passed in\n * @private\n */\nfunction getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {\n let transformFeedbackVaryings;\n let transformFeedbackMode;\n if (typeof opt_locations === 'function') {\n opt_errorCallback = opt_locations;\n opt_locations = undefined;\n }\n if (typeof opt_attribs === 'function') {\n opt_errorCallback = opt_attribs;\n opt_attribs = undefined;\n } else if (opt_attribs && !Array.isArray(opt_attribs)) {\n // If we have an errorCallback we can just return this object\n // Otherwise we need to construct one with default errorCallback\n if (opt_attribs.errorCallback) {\n return opt_attribs;\n }\n const opt = opt_attribs;\n opt_errorCallback = opt.errorCallback;\n opt_attribs = opt.attribLocations;\n transformFeedbackVaryings = opt.transformFeedbackVaryings;\n transformFeedbackMode = opt.transformFeedbackMode;\n }\n\n const options = {\n errorCallback: opt_errorCallback || error,\n transformFeedbackVaryings: transformFeedbackVaryings,\n transformFeedbackMode: transformFeedbackMode,\n };\n\n if (opt_attribs) {\n let attribLocations = {};\n if (Array.isArray(opt_attribs)) {\n opt_attribs.forEach(function(attrib, ndx) {\n attribLocations[attrib] = opt_locations ? opt_locations[ndx] : ndx;\n });\n } else {\n attribLocations = opt_attribs;\n }\n options.attribLocations = attribLocations;\n }\n\n return options;\n}\n\nconst defaultShaderType = [\n \"VERTEX_SHADER\",\n \"FRAGMENT_SHADER\",\n];\n\nfunction getShaderTypeFromScriptType(gl, scriptType) {\n if (scriptType.indexOf(\"frag\") >= 0) {\n return FRAGMENT_SHADER;\n } else if (scriptType.indexOf(\"vert\") >= 0) {\n return VERTEX_SHADER;\n }\n return undefined;\n}\n\nfunction deleteShaders(gl, shaders) {\n shaders.forEach(function(shader) {\n gl.deleteShader(shader);\n });\n}\n\n/**\n * Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the\n * program and calls useProgram.\n *\n * NOTE: There are 4 signatures for this function\n *\n * twgl.createProgram(gl, [vs, fs], options);\n * twgl.createProgram(gl, [vs, fs], opt_errFunc);\n * twgl.createProgram(gl, [vs, fs], opt_attribs, opt_errFunc);\n * twgl.createProgram(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.\n * @param {WebGLShader[]|string[]} shaders The shaders to attach, or element ids for their source, or strings that contain their source\n * @param {module:twgl.ProgramOptions|string[]|module:twgl.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\n * @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.\n * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console\n * on error. If you want something else pass an callback. It's passed an error message.\n * @return {WebGLProgram?} the created program or null if error.\n * @memberOf module:twgl/programs\n */\nfunction createProgram(\n gl, shaders, opt_attribs, opt_locations, opt_errorCallback) {\n const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);\n const realShaders = [];\n const newShaders = [];\n for (let ndx = 0; ndx < shaders.length; ++ndx) {\n let shader = shaders[ndx];\n if (typeof (shader) === 'string') {\n const elem = getElementById(shader);\n const src = elem ? elem.text : shader;\n let type = gl[defaultShaderType[ndx]];\n if (elem && elem.type) {\n type = getShaderTypeFromScriptType(gl, elem.type) || type;\n }\n shader = loadShader(gl, src, type, progOptions.errorCallback);\n newShaders.push(shader);\n }\n if (helper.isShader(gl, shader)) {\n realShaders.push(shader);\n }\n }\n\n if (realShaders.length !== shaders.length) {\n progOptions.errorCallback(\"not enough shaders for program\");\n deleteShaders(gl, newShaders);\n return null;\n }\n\n const program = gl.createProgram();\n realShaders.forEach(function(shader) {\n gl.attachShader(program, shader);\n });\n if (progOptions.attribLocations) {\n Object.keys(progOptions.attribLocations).forEach(function(attrib) {\n gl.bindAttribLocation(program, progOptions.attribLocations[attrib], attrib);\n });\n }\n let varyings = progOptions.transformFeedbackVaryings;\n if (varyings) {\n if (varyings.attribs) {\n varyings = varyings.attribs;\n }\n if (!Array.isArray(varyings)) {\n varyings = Object.keys(varyings);\n }\n gl.transformFeedbackVaryings(program, varyings, progOptions.transformFeedbackMode || SEPARATE_ATTRIBS);\n }\n gl.linkProgram(program);\n\n // Check the link status\n const linked = gl.getProgramParameter(program, LINK_STATUS);\n if (!linked) {\n // something went wrong with the link\n const lastError = gl.getProgramInfoLog(program);\n progOptions.errorCallback(\"Error in program linking:\" + lastError);\n\n gl.deleteProgram(program);\n deleteShaders(gl, newShaders);\n return null;\n }\n return program;\n}\n\n/**\n * Loads a shader from a script tag.\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.\n * @param {string} scriptId The id of the script tag.\n * @param {number} [opt_shaderType] The type of shader. If not passed in it will\n * be derived from the type of the script tag.\n * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors.\n * @return {WebGLShader?} The created shader or null if error.\n * @private\n */\nfunction createShaderFromScript(\n gl, scriptId, opt_shaderType, opt_errorCallback) {\n let shaderSource = \"\";\n const shaderScript = getElementById(scriptId);\n if (!shaderScript) {\n throw new Error(`unknown script element: ${scriptId}`);\n }\n shaderSource = shaderScript.text;\n\n const shaderType = opt_shaderType || getShaderTypeFromScriptType(gl, shaderScript.type);\n if (!shaderType) {\n throw new Error('unknown shader type');\n }\n\n return loadShader(gl, shaderSource, shaderType, opt_errorCallback);\n}\n\n/**\n * Creates a program from 2 script tags.\n *\n * NOTE: There are 4 signatures for this function\n *\n * twgl.createProgramFromScripts(gl, [vs, fs], opt_options);\n * twgl.createProgramFromScripts(gl, [vs, fs], opt_errFunc);\n * twgl.createProgramFromScripts(gl, [vs, fs], opt_attribs, opt_errFunc);\n * twgl.createProgramFromScripts(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext\n * to use.\n * @param {string[]} shaderScriptIds Array of ids of the script\n * tags for the shaders. The first is assumed to be the\n * vertex shader, the second the fragment shader.\n * @param {module:twgl.ProgramOptions|string[]|module:twgl.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\n * @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.\n * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console\n * on error. If you want something else pass an callback. It's passed an error message.\n * @return {WebGLProgram?} the created program or null if error.\n * @memberOf module:twgl/programs\n */\nfunction createProgramFromScripts(\n gl, shaderScriptIds, opt_attribs, opt_locations, opt_errorCallback) {\n const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);\n const shaders = [];\n for (let ii = 0; ii < shaderScriptIds.length; ++ii) {\n const shader = createShaderFromScript(\n gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions.errorCallback);\n if (!shader) {\n return null;\n }\n shaders.push(shader);\n }\n return createProgram(gl, shaders, progOptions);\n}\n\n/**\n * Creates a program from 2 sources.\n *\n * NOTE: There are 4 signatures for this function\n *\n * twgl.createProgramFromSource(gl, [vs, fs], opt_options);\n * twgl.createProgramFromSource(gl, [vs, fs], opt_errFunc);\n * twgl.createProgramFromSource(gl, [vs, fs], opt_attribs, opt_errFunc);\n * twgl.createProgramFromSource(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext\n * to use.\n * @param {string[]} shaderSources Array of sources for the\n * shaders. The first is assumed to be the vertex shader,\n * the second the fragment shader.\n * @param {module:twgl.ProgramOptions|string[]|module:twgl.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\n * @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.\n * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console\n * on error. If you want something else pass an callback. It's passed an error message.\n * @return {WebGLProgram?} the created program or null if error.\n * @memberOf module:twgl/programs\n */\nfunction createProgramFromSources(\n gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {\n const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);\n const shaders = [];\n for (let ii = 0; ii < shaderSources.length; ++ii) {\n const shader = loadShader(\n gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions.errorCallback);\n if (!shader) {\n return null;\n }\n shaders.push(shader);\n }\n return createProgram(gl, shaders, progOptions);\n}\n\n/**\n * Returns true if attribute/uniform is a reserved/built in\n *\n * It makes no sense to me why GL returns these because it's\n * illegal to call `gl.getUniformLocation` and `gl.getAttribLocation`\n * with names that start with `gl_` (and `webgl_` in WebGL)\n *\n * I can only assume they are there because they might count\n * when computing the number of uniforms/attributes used when you want to\n * know if you are near the limit. That doesn't really make sense\n * to me but the fact that these get returned are in the spec.\n *\n * @param {WebGLActiveInfo} info As returned from `gl.getActiveUniform` or\n * `gl.getActiveAttrib`.\n * @return {bool} true if it's reserved\n * @private\n */\nfunction isBuiltIn(info) {\n const name = info.name;\n return name.startsWith(\"gl_\") || name.startsWith(\"webgl_\");\n}\n\n/**\n * Creates setter functions for all uniforms of a shader\n * program.\n *\n * @see {@link module:twgl.setUniforms}\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.\n * @param {WebGLProgram} program the program to create setters for.\n * @returns {Object.} an object with a setter by name for each uniform\n * @memberOf module:twgl/programs\n */\nfunction createUniformSetters(gl, program) {\n let textureUnit = 0;\n\n /**\n * Creates a setter for a uniform of the given program with it's\n * location embedded in the setter.\n * @param {WebGLProgram} program\n * @param {WebGLUniformInfo} uniformInfo\n * @returns {function} the created setter.\n */\n function createUniformSetter(program, uniformInfo) {\n const location = gl.getUniformLocation(program, uniformInfo.name);\n const isArray = (uniformInfo.size > 1 && uniformInfo.name.substr(-3) === \"[0]\");\n const type = uniformInfo.type;\n const typeInfo = typeMap[type];\n if (!typeInfo) {\n throw new Error(`unknown type: 0x${type.toString(16)}`); // we should never get here.\n }\n let setter;\n if (typeInfo.bindPoint) {\n // it's a sampler\n const unit = textureUnit;\n textureUnit += uniformInfo.size;\n if (isArray) {\n setter = typeInfo.arraySetter(gl, type, unit, location, uniformInfo.size);\n } else {\n setter = typeInfo.setter(gl, type, unit, location, uniformInfo.size);\n }\n } else {\n if (typeInfo.arraySetter && isArray) {\n setter = typeInfo.arraySetter(gl, location);\n } else {\n setter = typeInfo.setter(gl, location);\n }\n }\n setter.location = location;\n return setter;\n }\n\n const uniformSetters = { };\n const numUniforms = gl.getProgramParameter(program, ACTIVE_UNIFORMS);\n\n for (let ii = 0; ii < numUniforms; ++ii) {\n const uniformInfo = gl.getActiveUniform(program, ii);\n if (isBuiltIn(uniformInfo)) {\n continue;\n }\n let name = uniformInfo.name;\n // remove the array suffix.\n if (name.substr(-3) === \"[0]\") {\n name = name.substr(0, name.length - 3);\n }\n const setter = createUniformSetter(program, uniformInfo);\n uniformSetters[name] = setter;\n }\n return uniformSetters;\n}\n\n/**\n * @typedef {Object} TransformFeedbackInfo\n * @property {number} index index of transform feedback\n * @property {number} type GL type\n * @property {number} size 1 - 4\n * @memberOf module:twgl\n */\n\n/**\n * Create TransformFeedbackInfo for passing to bindTransformFeedbackInfo.\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.\n * @param {WebGLProgram} program an existing WebGLProgram.\n * @return {Object}\n * @memberOf module:twgl\n */\nfunction createTransformFeedbackInfo(gl, program) {\n const info = {};\n const numVaryings = gl.getProgramParameter(program, TRANSFORM_FEEDBACK_VARYINGS);\n for (let ii = 0; ii < numVaryings; ++ii) {\n const varying = gl.getTransformFeedbackVarying(program, ii);\n info[varying.name] = {\n index: ii,\n type: varying.type,\n size: varying.size,\n };\n }\n return info;\n}\n\n/**\n * Binds buffers for transform feedback.\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.\n * @param {(module:twgl.ProgramInfo|Object)} transformFeedbackInfo A ProgramInfo or TransformFeedbackInfo.\n * @param {(module:twgl.BufferInfo|Object)} [bufferInfo] A BufferInfo or set of AttribInfos.\n * @memberOf module:twgl\n */\nfunction bindTransformFeedbackInfo(gl, transformFeedbackInfo, bufferInfo) {\n if (transformFeedbackInfo.transformFeedbackInfo) {\n transformFeedbackInfo = transformFeedbackInfo.transformFeedbackInfo;\n }\n if (bufferInfo.attribs) {\n bufferInfo = bufferInfo.attribs;\n }\n for (const name in bufferInfo) {\n const varying = transformFeedbackInfo[name];\n if (varying) {\n const buf = bufferInfo[name];\n if (buf.offset) {\n gl.bindBufferRange(TRANSFORM_FEEDBACK_BUFFER, varying.index, buf.buffer, buf.offset, buf.size);\n } else {\n gl.bindBufferBase(TRANSFORM_FEEDBACK_BUFFER, varying.index, buf.buffer);\n }\n }\n }\n}\n\n/**\n * Creates a transform feedback and sets the buffers\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.\n * @param {module:twgl.ProgramInfo} programInfo A ProgramInfo as returned from {@link module:twgl.createProgramInfo}\n * @param {(module:twgl.BufferInfo|Object)} [bufferInfo] A BufferInfo or set of AttribInfos.\n * @return {WebGLTransformFeedback} the created transform feedback\n * @memberOf module:twgl\n */\nfunction createTransformFeedback(gl, programInfo, bufferInfo) {\n const tf = gl.createTransformFeedback();\n gl.bindTransformFeedback(TRANSFORM_FEEDBACK, tf);\n gl.useProgram(programInfo.program);\n bindTransformFeedbackInfo(gl, programInfo, bufferInfo);\n gl.bindTransformFeedback(TRANSFORM_FEEDBACK, null);\n return tf;\n}\n\n/**\n * @typedef {Object} UniformData\n * @property {number} type The WebGL type enum for this uniform\n * @property {number} size The number of elements for this uniform\n * @property {number} blockNdx The block index this uniform appears in\n * @property {number} offset The byte offset in the block for this uniform's value\n * @memberOf module:twgl\n */\n\n/**\n * The specification for one UniformBlockObject\n *\n * @typedef {Object} BlockSpec\n * @property {number} index The index of the block.\n * @property {number} size The size in bytes needed for the block\n * @property {number[]} uniformIndices The indices of the uniforms used by the block. These indices\n * correspond to entries in a UniformData array in the {@link module:twgl.UniformBlockSpec}.\n * @property {bool} usedByVertexShader Self explanatory\n * @property {bool} usedByFragmentShader Self explanatory\n * @property {bool} used Self explanatory\n * @memberOf module:twgl\n */\n\n/**\n * A `UniformBlockSpec` represents the data needed to create and bind\n * UniformBlockObjects for a given program\n *\n * @typedef {Object} UniformBlockSpec\n * @property {Object. blockSpecs The BlockSpec for each block by block name\n * @property {UniformData[]} uniformData An array of data for each uniform by uniform index.\n * @memberOf module:twgl\n */\n\n/**\n * Creates a UniformBlockSpec for the given program.\n *\n * A UniformBlockSpec represents the data needed to create and bind\n * UniformBlockObjects\n *\n * @param {WebGL2RenderingContext} gl A WebGL2 Rendering Context\n * @param {WebGLProgram} program A WebGLProgram for a successfully linked program\n * @return {module:twgl.UniformBlockSpec} The created UniformBlockSpec\n * @memberOf module:twgl/programs\n */\nfunction createUniformBlockSpecFromProgram(gl, program) {\n const numUniforms = gl.getProgramParameter(program, ACTIVE_UNIFORMS);\n const uniformData = [];\n const uniformIndices = [];\n\n for (let ii = 0; ii < numUniforms; ++ii) {\n uniformIndices.push(ii);\n uniformData.push({});\n const uniformInfo = gl.getActiveUniform(program, ii);\n if (isBuiltIn(uniformInfo)) {\n break;\n }\n // REMOVE [0]?\n uniformData[ii].name = uniformInfo.name;\n }\n\n [\n [ \"UNIFORM_TYPE\", \"type\" ],\n [ \"UNIFORM_SIZE\", \"size\" ], // num elements\n [ \"UNIFORM_BLOCK_INDEX\", \"blockNdx\" ],\n [ \"UNIFORM_OFFSET\", \"offset\", ],\n ].forEach(function(pair) {\n const pname = pair[0];\n const key = pair[1];\n gl.getActiveUniforms(program, uniformIndices, gl[pname]).forEach(function(value, ndx) {\n uniformData[ndx][key] = value;\n });\n });\n\n const blockSpecs = {};\n\n const numUniformBlocks = gl.getProgramParameter(program, ACTIVE_UNIFORM_BLOCKS);\n for (let ii = 0; ii < numUniformBlocks; ++ii) {\n const name = gl.getActiveUniformBlockName(program, ii);\n const blockSpec = {\n index: ii,\n usedByVertexShader: gl.getActiveUniformBlockParameter(program, ii, UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),\n usedByFragmentShader: gl.getActiveUniformBlockParameter(program, ii, UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER),\n size: gl.getActiveUniformBlockParameter(program, ii, UNIFORM_BLOCK_DATA_SIZE),\n uniformIndices: gl.getActiveUniformBlockParameter(program, ii, UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES),\n };\n blockSpec.used = blockSpec.usedByVertexShader || blockSpec.usedByFragmentShader;\n blockSpecs[name] = blockSpec;\n }\n\n return {\n blockSpecs: blockSpecs,\n uniformData: uniformData,\n };\n}\n\nconst arraySuffixRE = /\\[\\d+\\]\\.$/; // better way to check?\n\n/**\n * Represents a UniformBlockObject including an ArrayBuffer with all the uniform values\n * and a corresponding WebGLBuffer to hold those values on the GPU\n *\n * @typedef {Object} UniformBlockInfo\n * @property {string} name The name of the block\n * @property {ArrayBuffer} array The array buffer that contains the uniform values\n * @property {Float32Array} asFloat A float view on the array buffer. This is useful\n * inspecting the contents of the buffer in the debugger.\n * @property {WebGLBuffer} buffer A WebGL buffer that will hold a copy of the uniform values for rendering.\n * @property {number} [offset] offset into buffer\n * @property {Object.} uniforms A uniform name to ArrayBufferView map.\n * each Uniform has a correctly typed `ArrayBufferView` into array at the correct offset\n * and length of that uniform. So for example a float uniform would have a 1 float `Float32Array`\n * view. A single mat4 would have a 16 element `Float32Array` view. An ivec2 would have an\n * `Int32Array` view, etc.\n * @memberOf module:twgl\n */\n\n/**\n * Creates a `UniformBlockInfo` for the specified block\n *\n * Note: **If the blockName matches no existing blocks a warning is printed to the console and a dummy\n * `UniformBlockInfo` is returned**. This is because when debugging GLSL\n * it is common to comment out large portions of a shader or for example set\n * the final output to a constant. When that happens blocks get optimized out.\n * If this function did not create dummy blocks your code would crash when debugging.\n *\n * @param {WebGL2RenderingContext} gl A WebGL2RenderingContext\n * @param {WebGLProgram} program A WebGLProgram\n * @param {module:twgl.UniformBlockSpec} uniformBlockSpec. A UniformBlockSpec as returned\n * from {@link module:twgl.createUniformBlockSpecFromProgram}.\n * @param {string} blockName The name of the block.\n * @return {module:twgl.UniformBlockInfo} The created UniformBlockInfo\n * @memberOf module:twgl/programs\n */\nfunction createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockName) {\n const blockSpecs = uniformBlockSpec.blockSpecs;\n const uniformData = uniformBlockSpec.uniformData;\n const blockSpec = blockSpecs[blockName];\n if (!blockSpec) {\n warn(\"no uniform block object named:\", blockName);\n return {\n name: blockName,\n uniforms: {},\n };\n }\n const array = new ArrayBuffer(blockSpec.size);\n const buffer = gl.createBuffer();\n const uniformBufferIndex = blockSpec.index;\n gl.bindBuffer(UNIFORM_BUFFER, buffer);\n gl.uniformBlockBinding(program, blockSpec.index, uniformBufferIndex);\n\n let prefix = blockName + \".\";\n if (arraySuffixRE.test(prefix)) {\n prefix = prefix.replace(arraySuffixRE, \".\");\n }\n const uniforms = {};\n blockSpec.uniformIndices.forEach(function(uniformNdx) {\n const data = uniformData[uniformNdx];\n const typeInfo = typeMap[data.type];\n const Type = typeInfo.Type;\n const length = data.size * typeInfo.size;\n let name = data.name;\n if (name.substr(0, prefix.length) === prefix) {\n name = name.substr(prefix.length);\n }\n uniforms[name] = new Type(array, data.offset, length / Type.BYTES_PER_ELEMENT);\n });\n return {\n name: blockName,\n array: array,\n asFloat: new Float32Array(array), // for debugging\n buffer: buffer,\n uniforms: uniforms,\n };\n}\n\n/**\n * Creates a `UniformBlockInfo` for the specified block\n *\n * Note: **If the blockName matches no existing blocks a warning is printed to the console and a dummy\n * `UniformBlockInfo` is returned**. This is because when debugging GLSL\n * it is common to comment out large portions of a shader or for example set\n * the final output to a constant. When that happens blocks get optimized out.\n * If this function did not create dummy blocks your code would crash when debugging.\n *\n * @param {WebGL2RenderingContext} gl A WebGL2RenderingContext\n * @param {module:twgl.ProgramInfo} programInfo a `ProgramInfo`\n * as returned from {@link module:twgl.createProgramInfo}\n * @param {string} blockName The name of the block.\n * @return {module:twgl.UniformBlockInfo} The created UniformBlockInfo\n * @memberOf module:twgl/programs\n */\nfunction createUniformBlockInfo(gl, programInfo, blockName) {\n return createUniformBlockInfoFromProgram(gl, programInfo.program, programInfo.uniformBlockSpec, blockName);\n}\n\n/**\n * Binds a uniform block to the matching uniform block point.\n * Matches by blocks by name so blocks must have the same name not just the same\n * structure.\n *\n * If you have changed any values and you upload the values into the corresponding WebGLBuffer\n * call {@link module:twgl.setUniformBlock} instead.\n *\n * @param {WebGL2RenderingContext} gl A WebGL 2 rendering context.\n * @param {(module:twgl.ProgramInfo|module:twgl.UniformBlockSpec)} programInfo a `ProgramInfo`\n * as returned from {@link module:twgl.createProgramInfo} or or `UniformBlockSpec` as\n * returned from {@link module:twgl.createUniformBlockSpecFromProgram}.\n * @param {module:twgl.UniformBlockInfo} uniformBlockInfo a `UniformBlockInfo` as returned from\n * {@link module:twgl.createUniformBlockInfo}.\n * @return {bool} true if buffer was bound. If the programInfo has no block with the same block name\n * no buffer is bound.\n * @memberOf module:twgl/programs\n */\nfunction bindUniformBlock(gl, programInfo, uniformBlockInfo) {\n const uniformBlockSpec = programInfo.uniformBlockSpec || programInfo;\n const blockSpec = uniformBlockSpec.blockSpecs[uniformBlockInfo.name];\n if (blockSpec) {\n const bufferBindIndex = blockSpec.index;\n gl.bindBufferRange(UNIFORM_BUFFER, bufferBindIndex, uniformBlockInfo.buffer, uniformBlockInfo.offset || 0, uniformBlockInfo.array.byteLength);\n return true;\n }\n return false;\n}\n\n/**\n * Uploads the current uniform values to the corresponding WebGLBuffer\n * and binds that buffer to the program's corresponding bind point for the uniform block object.\n *\n * If you haven't changed any values and you only need to bind the uniform block object\n * call {@link module:twgl.bindUniformBlock} instead.\n *\n * @param {WebGL2RenderingContext} gl A WebGL 2 rendering context.\n * @param {(module:twgl.ProgramInfo|module:twgl.UniformBlockSpec)} programInfo a `ProgramInfo`\n * as returned from {@link module:twgl.createProgramInfo} or or `UniformBlockSpec` as\n * returned from {@link module:twgl.createUniformBlockSpecFromProgram}.\n * @param {module:twgl.UniformBlockInfo} uniformBlockInfo a `UniformBlockInfo` as returned from\n * {@link module:twgl.createUniformBlockInfo}.\n * @memberOf module:twgl/programs\n */\nfunction setUniformBlock(gl, programInfo, uniformBlockInfo) {\n if (bindUniformBlock(gl, programInfo, uniformBlockInfo)) {\n gl.bufferData(UNIFORM_BUFFER, uniformBlockInfo.array, DYNAMIC_DRAW);\n }\n}\n\n/**\n * Sets values of a uniform block object\n *\n * @param {module:twgl.UniformBlockInfo} uniformBlockInfo A UniformBlockInfo as returned by {@link module:twgl.createUniformBlockInfo}.\n * @param {Object.} values A uniform name to value map where the value is correct for the given\n * type of uniform. So for example given a block like\n *\n * uniform SomeBlock {\n * float someFloat;\n * vec2 someVec2;\n * vec3 someVec3Array[2];\n * int someInt;\n * }\n *\n * You can set the values of the uniform block with\n *\n * twgl.setBlockUniforms(someBlockInfo, {\n * someFloat: 12.3,\n * someVec2: [1, 2],\n * someVec3Array: [1, 2, 3, 4, 5, 6],\n * someInt: 5,\n * }\n *\n * Arrays can be JavaScript arrays or typed arrays\n *\n * Any name that doesn't match will be ignored\n * @memberOf module:twgl/programs\n */\nfunction setBlockUniforms(uniformBlockInfo, values) {\n const uniforms = uniformBlockInfo.uniforms;\n for (const name in values) {\n const array = uniforms[name];\n if (array) {\n const value = values[name];\n if (value.length) {\n array.set(value);\n } else {\n array[0] = value;\n }\n }\n }\n}\n\n/**\n * Set uniforms and binds related textures.\n *\n * example:\n *\n * const programInfo = createProgramInfo(\n * gl, [\"some-vs\", \"some-fs\"]);\n *\n * const tex1 = gl.createTexture();\n * const tex2 = gl.createTexture();\n *\n * ... assume we setup the textures with data ...\n *\n * const uniforms = {\n * u_someSampler: tex1,\n * u_someOtherSampler: tex2,\n * u_someColor: [1,0,0,1],\n * u_somePosition: [0,1,1],\n * u_someMatrix: [\n * 1,0,0,0,\n * 0,1,0,0,\n * 0,0,1,0,\n * 0,0,0,0,\n * ],\n * };\n *\n * gl.useProgram(program);\n *\n * This will automatically bind the textures AND set the\n * uniforms.\n *\n * twgl.setUniforms(programInfo, uniforms);\n *\n * For the example above it is equivalent to\n *\n * var texUnit = 0;\n * gl.activeTexture(gl.TEXTURE0 + texUnit);\n * gl.bindTexture(gl.TEXTURE_2D, tex1);\n * gl.uniform1i(u_someSamplerLocation, texUnit++);\n * gl.activeTexture(gl.TEXTURE0 + texUnit);\n * gl.bindTexture(gl.TEXTURE_2D, tex2);\n * gl.uniform1i(u_someSamplerLocation, texUnit++);\n * gl.uniform4fv(u_someColorLocation, [1, 0, 0, 1]);\n * gl.uniform3fv(u_somePositionLocation, [0, 1, 1]);\n * gl.uniformMatrix4fv(u_someMatrix, false, [\n * 1,0,0,0,\n * 0,1,0,0,\n * 0,0,1,0,\n * 0,0,0,0,\n * ]);\n *\n * Note it is perfectly reasonable to call `setUniforms` multiple times. For example\n *\n * const uniforms = {\n * u_someSampler: tex1,\n * u_someOtherSampler: tex2,\n * };\n *\n * const moreUniforms {\n * u_someColor: [1,0,0,1],\n * u_somePosition: [0,1,1],\n * u_someMatrix: [\n * 1,0,0,0,\n * 0,1,0,0,\n * 0,0,1,0,\n * 0,0,0,0,\n * ],\n * };\n *\n * twgl.setUniforms(programInfo, uniforms);\n * twgl.setUniforms(programInfo, moreUniforms);\n *\n * You can also add WebGLSamplers to uniform samplers as in\n *\n * const uniforms = {\n * u_someSampler: {\n * texture: someWebGLTexture,\n * sampler: someWebGLSampler,\n * },\n * };\n *\n * In which case both the sampler and texture will be bound to the\n * same unit.\n *\n * @param {(module:twgl.ProgramInfo|Object.)} setters a `ProgramInfo` as returned from `createProgramInfo` or the setters returned from\n * `createUniformSetters`.\n * @param {Object.} values an object with values for the\n * uniforms.\n * You can pass multiple objects by putting them in an array or by calling with more arguments.For example\n *\n * const sharedUniforms = {\n * u_fogNear: 10,\n * u_projection: ...\n * ...\n * };\n *\n * const localUniforms = {\n * u_world: ...\n * u_diffuseColor: ...\n * };\n *\n * twgl.setUniforms(programInfo, sharedUniforms, localUniforms);\n *\n * // is the same as\n *\n * twgl.setUniforms(programInfo, [sharedUniforms, localUniforms]);\n *\n * // is the same as\n *\n * twgl.setUniforms(programInfo, sharedUniforms);\n * twgl.setUniforms(programInfo, localUniforms};\n *\n * @memberOf module:twgl/programs\n */\nfunction setUniforms(setters, values) { // eslint-disable-line\n const actualSetters = setters.uniformSetters || setters;\n const numArgs = arguments.length;\n for (let aNdx = 1; aNdx < numArgs; ++aNdx) {\n const values = arguments[aNdx];\n if (Array.isArray(values)) {\n const numValues = values.length;\n for (let ii = 0; ii < numValues; ++ii) {\n setUniforms(actualSetters, values[ii]);\n }\n } else {\n for (const name in values) {\n const setter = actualSetters[name];\n if (setter) {\n setter(values[name]);\n }\n }\n }\n }\n}\n\n/**\n * Alias for `setUniforms`\n * @function\n * @param {(module:twgl.ProgramInfo|Object.)} setters a `ProgramInfo` as returned from `createProgramInfo` or the setters returned from\n * `createUniformSetters`.\n * @param {Object.} values an object with values for the\n * @memberOf module:twgl/programs\n */\nconst setUniformsAndBindTextures = setUniforms;\n\n/**\n * Creates setter functions for all attributes of a shader\n * program. You can pass this to {@link module:twgl.setBuffersAndAttributes} to set all your buffers and attributes.\n *\n * @see {@link module:twgl.setAttributes} for example\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.\n * @param {WebGLProgram} program the program to create setters for.\n * @return {Object.} an object with a setter for each attribute by name.\n * @memberOf module:twgl/programs\n */\nfunction createAttributeSetters(gl, program) {\n const attribSetters = {\n };\n\n const numAttribs = gl.getProgramParameter(program, ACTIVE_ATTRIBUTES);\n for (let ii = 0; ii < numAttribs; ++ii) {\n const attribInfo = gl.getActiveAttrib(program, ii);\n if (isBuiltIn(attribInfo)) {\n continue;\n }\n const index = gl.getAttribLocation(program, attribInfo.name);\n const typeInfo = attrTypeMap[attribInfo.type];\n const setter = typeInfo.setter(gl, index, typeInfo);\n setter.location = index;\n attribSetters[attribInfo.name] = setter;\n }\n\n return attribSetters;\n}\n\n/**\n * Sets attributes and binds buffers (deprecated... use {@link module:twgl.setBuffersAndAttributes})\n *\n * Example:\n *\n * const program = createProgramFromScripts(\n * gl, [\"some-vs\", \"some-fs\");\n *\n * const attribSetters = createAttributeSetters(program);\n *\n * const positionBuffer = gl.createBuffer();\n * const texcoordBuffer = gl.createBuffer();\n *\n * const attribs = {\n * a_position: {buffer: positionBuffer, numComponents: 3},\n * a_texcoord: {buffer: texcoordBuffer, numComponents: 2},\n * };\n *\n * gl.useProgram(program);\n *\n * This will automatically bind the buffers AND set the\n * attributes.\n *\n * setAttributes(attribSetters, attribs);\n *\n * Properties of attribs. For each attrib you can add\n * properties:\n *\n * * type: the type of data in the buffer. Default = gl.FLOAT\n * * normalize: whether or not to normalize the data. Default = false\n * * stride: the stride. Default = 0\n * * offset: offset into the buffer. Default = 0\n * * divisor: the divisor for instances. Default = undefined\n *\n * For example if you had 3 value float positions, 2 value\n * float texcoord and 4 value uint8 colors you'd setup your\n * attribs like this\n *\n * const attribs = {\n * a_position: {buffer: positionBuffer, numComponents: 3},\n * a_texcoord: {buffer: texcoordBuffer, numComponents: 2},\n * a_color: {\n * buffer: colorBuffer,\n * numComponents: 4,\n * type: gl.UNSIGNED_BYTE,\n * normalize: true,\n * },\n * };\n *\n * @param {Object.} setters Attribute setters as returned from createAttributeSetters\n * @param {Object.} buffers AttribInfos mapped by attribute name.\n * @memberOf module:twgl/programs\n * @deprecated use {@link module:twgl.setBuffersAndAttributes}\n */\nfunction setAttributes(setters, buffers) {\n for (const name in buffers) {\n const setter = setters[name];\n if (setter) {\n setter(buffers[name]);\n }\n }\n}\n\n/**\n * Sets attributes and buffers including the `ELEMENT_ARRAY_BUFFER` if appropriate\n *\n * Example:\n *\n * const programInfo = createProgramInfo(\n * gl, [\"some-vs\", \"some-fs\");\n *\n * const arrays = {\n * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },\n * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },\n * };\n *\n * const bufferInfo = createBufferInfoFromArrays(gl, arrays);\n *\n * gl.useProgram(programInfo.program);\n *\n * This will automatically bind the buffers AND set the\n * attributes.\n *\n * setBuffersAndAttributes(gl, programInfo, bufferInfo);\n *\n * For the example above it is equivalent to\n *\n * gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);\n * gl.enableVertexAttribArray(a_positionLocation);\n * gl.vertexAttribPointer(a_positionLocation, 3, gl.FLOAT, false, 0, 0);\n * gl.bindBuffer(gl.ARRAY_BUFFER, texcoordBuffer);\n * gl.enableVertexAttribArray(a_texcoordLocation);\n * gl.vertexAttribPointer(a_texcoordLocation, 4, gl.FLOAT, false, 0, 0);\n *\n * @param {WebGLRenderingContext} gl A WebGLRenderingContext.\n * @param {(module:twgl.ProgramInfo|Object.)} setters A `ProgramInfo` as returned from {@link module:twgl.createProgramInfo} or Attribute setters as returned from {@link module:twgl.createAttributeSetters}\n * @param {(module:twgl.BufferInfo|module:twgl.VertexArrayInfo)} buffers a `BufferInfo` as returned from {@link module:twgl.createBufferInfoFromArrays}.\n * or a `VertexArrayInfo` as returned from {@link module:twgl.createVertexArrayInfo}\n * @memberOf module:twgl/programs\n */\nfunction setBuffersAndAttributes(gl, programInfo, buffers) {\n if (buffers.vertexArrayObject) {\n gl.bindVertexArray(buffers.vertexArrayObject);\n } else {\n setAttributes(programInfo.attribSetters || programInfo, buffers.attribs);\n if (buffers.indices) {\n gl.bindBuffer(ELEMENT_ARRAY_BUFFER, buffers.indices);\n }\n }\n}\n\n/**\n * @typedef {Object} ProgramInfo\n * @property {WebGLProgram} program A shader program\n * @property {Object} uniformSetters object of setters as returned from createUniformSetters,\n * @property {Object} attribSetters object of setters as returned from createAttribSetters,\n * @property {module:twgl.UniformBlockSpec} [uniformBlockSpace] a uniform block spec for making UniformBlockInfos with createUniformBlockInfo etc..\n * @property {Object} [transformFeedbackInfo] info for transform feedbacks\n * @memberOf module:twgl\n */\n\n/**\n * Creates a ProgramInfo from an existing program.\n *\n * A ProgramInfo contains\n *\n * programInfo = {\n * program: WebGLProgram,\n * uniformSetters: object of setters as returned from createUniformSetters,\n * attribSetters: object of setters as returned from createAttribSetters,\n * }\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext\n * to use.\n * @param {WebGLProgram} program an existing WebGLProgram.\n * @return {module:twgl.ProgramInfo} The created ProgramInfo.\n * @memberOf module:twgl/programs\n */\nfunction createProgramInfoFromProgram(gl, program) {\n const uniformSetters = createUniformSetters(gl, program);\n const attribSetters = createAttributeSetters(gl, program);\n const programInfo = {\n program: program,\n uniformSetters: uniformSetters,\n attribSetters: attribSetters,\n };\n\n if (utils.isWebGL2(gl)) {\n programInfo.uniformBlockSpec = createUniformBlockSpecFromProgram(gl, program);\n programInfo.transformFeedbackInfo = createTransformFeedbackInfo(gl, program);\n }\n\n return programInfo;\n}\n\n/**\n * Creates a ProgramInfo from 2 sources.\n *\n * A ProgramInfo contains\n *\n * programInfo = {\n * program: WebGLProgram,\n * uniformSetters: object of setters as returned from createUniformSetters,\n * attribSetters: object of setters as returned from createAttribSetters,\n * }\n *\n * NOTE: There are 4 signatures for this function\n *\n * twgl.createProgramInfo(gl, [vs, fs], options);\n * twgl.createProgramInfo(gl, [vs, fs], opt_errFunc);\n * twgl.createProgramInfo(gl, [vs, fs], opt_attribs, opt_errFunc);\n * twgl.createProgramInfo(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext\n * to use.\n * @param {string[]} shaderSources Array of sources for the\n * shaders or ids. The first is assumed to be the vertex shader,\n * the second the fragment shader.\n * @param {module:twgl.ProgramOptions|string[]|module:twgl.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\n * @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.\n * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console\n * on error. If you want something else pass an callback. It's passed an error message.\n * @return {module:twgl.ProgramInfo?} The created ProgramInfo or null if it failed to link or compile\n * @memberOf module:twgl/programs\n */\nfunction createProgramInfo(\n gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {\n const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);\n let good = true;\n shaderSources = shaderSources.map(function(source) {\n // Lets assume if there is no \\n it's an id\n if (source.indexOf(\"\\n\") < 0) {\n const script = getElementById(source);\n if (!script) {\n progOptions.errorCallback(\"no element with id: \" + source);\n good = false;\n } else {\n source = script.text;\n }\n }\n return source;\n });\n if (!good) {\n return null;\n }\n const program = createProgramFromSources(gl, shaderSources, progOptions);\n if (!program) {\n return null;\n }\n return createProgramInfoFromProgram(gl, program);\n}\n\nexport {\n createAttributeSetters,\n\n createProgram,\n createProgramFromScripts,\n createProgramFromSources,\n createProgramInfo,\n createProgramInfoFromProgram,\n createUniformSetters,\n createUniformBlockSpecFromProgram,\n createUniformBlockInfoFromProgram,\n createUniformBlockInfo,\n\n createTransformFeedback,\n createTransformFeedbackInfo,\n bindTransformFeedbackInfo,\n\n setAttributes,\n setBuffersAndAttributes,\n setUniforms,\n setUniformsAndBindTextures,\n setUniformBlock,\n setBlockUniforms,\n bindUniformBlock,\n};\n\n","/*\n * Copyright 2019 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n\nimport * as utils from './utils.js';\nimport * as typedArrays from './typedarrays.js';\nimport * as helper from './helper.js';\n\n/**\n * Low level texture related functions\n *\n * You should generally not need to use these functions. They are provided\n * for those cases where you're doing something out of the ordinary\n * and you need lower level access.\n *\n * For backward compatibility they are available at both `twgl.textures` and `twgl`\n * itself\n *\n * See {@link module:twgl} for core functions\n *\n * @module twgl/textures\n */\n\n// make sure we don't see a global gl\nconst gl = undefined; /* eslint-disable-line */ /* lgtm [js/unused-local-variable] */\nconst defaults = {\n textureColor: new Uint8Array([128, 192, 255, 255]),\n textureOptions: {},\n crossOrigin: undefined,\n};\nconst isArrayBuffer = typedArrays.isArrayBuffer;\n\n// Should we make this on demand?\nlet s_ctx;\nfunction getShared2DContext() {\n s_ctx = s_ctx ||\n ((typeof document !== 'undefined' && document.createElement)\n ? document.createElement(\"canvas\").getContext(\"2d\")\n : null);\n return s_ctx;\n}\n\n// NOTE: Chrome supports 2D canvas in a Worker (behind flag as of v64 but\n// not only does Firefox NOT support it but Firefox freezes immediately\n// if you try to create one instead of just returning null and continuing.\n// : (global.OffscreenCanvas && (new global.OffscreenCanvas(1, 1)).getContext(\"2d\")); // OffscreenCanvas may not support 2d\n\n// NOTE: We can maybe remove some of the need for the 2d canvas. In WebGL2\n// we can use the various unpack settings. Otherwise we could try using\n// the ability of an ImageBitmap to be cut. Unfortunately cutting an ImageBitmap\n// is async and the current TWGL code expects a non-Async result though that\n// might not be a problem. ImageBitmap though is not available in Edge or Safari\n// as of 2018-01-02\n\n/* PixelFormat */\nconst ALPHA = 0x1906;\nconst RGB = 0x1907;\nconst RGBA = 0x1908;\nconst LUMINANCE = 0x1909;\nconst LUMINANCE_ALPHA = 0x190A;\nconst DEPTH_COMPONENT = 0x1902;\nconst DEPTH_STENCIL = 0x84F9;\n\n/* TextureWrapMode */\n// const REPEAT = 0x2901;\n// const MIRRORED_REPEAT = 0x8370;\nconst CLAMP_TO_EDGE = 0x812f;\n\n/* TextureMagFilter */\nconst NEAREST = 0x2600;\nconst LINEAR = 0x2601;\n\n/* TextureMinFilter */\n// const NEAREST_MIPMAP_NEAREST = 0x2700;\n// const LINEAR_MIPMAP_NEAREST = 0x2701;\n// const NEAREST_MIPMAP_LINEAR = 0x2702;\n// const LINEAR_MIPMAP_LINEAR = 0x2703;\n\n/* Texture Target */\nconst TEXTURE_2D = 0x0de1;\nconst TEXTURE_CUBE_MAP = 0x8513;\nconst TEXTURE_3D = 0x806f;\nconst TEXTURE_2D_ARRAY = 0x8c1a;\n\n/* Cubemap Targets */\nconst TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515;\nconst TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516;\nconst TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517;\nconst TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518;\nconst TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519;\nconst TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851a;\n\n/* Texture Parameters */\nconst TEXTURE_MIN_FILTER = 0x2801;\nconst TEXTURE_MAG_FILTER = 0x2800;\nconst TEXTURE_WRAP_S = 0x2802;\nconst TEXTURE_WRAP_T = 0x2803;\nconst TEXTURE_WRAP_R = 0x8072;\nconst TEXTURE_MIN_LOD = 0x813a;\nconst TEXTURE_MAX_LOD = 0x813b;\nconst TEXTURE_BASE_LEVEL = 0x813c;\nconst TEXTURE_MAX_LEVEL = 0x813d;\n\n\n/* Pixel store */\nconst UNPACK_ALIGNMENT = 0x0cf5;\nconst UNPACK_ROW_LENGTH = 0x0cf2;\nconst UNPACK_IMAGE_HEIGHT = 0x806e;\nconst UNPACK_SKIP_PIXELS = 0x0cf4;\nconst UNPACK_SKIP_ROWS = 0x0cf3;\nconst UNPACK_SKIP_IMAGES = 0x806d;\nconst UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243;\nconst UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241;\nconst UNPACK_FLIP_Y_WEBGL = 0x9240;\n\nconst R8 = 0x8229;\nconst R8_SNORM = 0x8F94;\nconst R16F = 0x822D;\nconst R32F = 0x822E;\nconst R8UI = 0x8232;\nconst R8I = 0x8231;\nconst RG16UI = 0x823A;\nconst RG16I = 0x8239;\nconst RG32UI = 0x823C;\nconst RG32I = 0x823B;\nconst RG8 = 0x822B;\nconst RG8_SNORM = 0x8F95;\nconst RG16F = 0x822F;\nconst RG32F = 0x8230;\nconst RG8UI = 0x8238;\nconst RG8I = 0x8237;\nconst R16UI = 0x8234;\nconst R16I = 0x8233;\nconst R32UI = 0x8236;\nconst R32I = 0x8235;\nconst RGB8 = 0x8051;\nconst SRGB8 = 0x8C41;\nconst RGB565 = 0x8D62;\nconst RGB8_SNORM = 0x8F96;\nconst R11F_G11F_B10F = 0x8C3A;\nconst RGB9_E5 = 0x8C3D;\nconst RGB16F = 0x881B;\nconst RGB32F = 0x8815;\nconst RGB8UI = 0x8D7D;\nconst RGB8I = 0x8D8F;\nconst RGB16UI = 0x8D77;\nconst RGB16I = 0x8D89;\nconst RGB32UI = 0x8D71;\nconst RGB32I = 0x8D83;\nconst RGBA8 = 0x8058;\nconst SRGB8_ALPHA8 = 0x8C43;\nconst RGBA8_SNORM = 0x8F97;\nconst RGB5_A1 = 0x8057;\nconst RGBA4 = 0x8056;\nconst RGB10_A2 = 0x8059;\nconst RGBA16F = 0x881A;\nconst RGBA32F = 0x8814;\nconst RGBA8UI = 0x8D7C;\nconst RGBA8I = 0x8D8E;\nconst RGB10_A2UI = 0x906F;\nconst RGBA16UI = 0x8D76;\nconst RGBA16I = 0x8D88;\nconst RGBA32I = 0x8D82;\nconst RGBA32UI = 0x8D70;\n\nconst DEPTH_COMPONENT16 = 0x81A5;\nconst DEPTH_COMPONENT24 = 0x81A6;\nconst DEPTH_COMPONENT32F = 0x8CAC;\nconst DEPTH32F_STENCIL8 = 0x8CAD;\nconst DEPTH24_STENCIL8 = 0x88F0;\n\n/* DataType */\nconst BYTE = 0x1400;\nconst UNSIGNED_BYTE = 0x1401;\nconst SHORT = 0x1402;\nconst UNSIGNED_SHORT = 0x1403;\nconst INT = 0x1404;\nconst UNSIGNED_INT = 0x1405;\nconst FLOAT = 0x1406;\nconst UNSIGNED_SHORT_4_4_4_4 = 0x8033;\nconst UNSIGNED_SHORT_5_5_5_1 = 0x8034;\nconst UNSIGNED_SHORT_5_6_5 = 0x8363;\nconst HALF_FLOAT = 0x140B;\nconst HALF_FLOAT_OES = 0x8D61; // Thanks Khronos for making this different >:(\nconst UNSIGNED_INT_2_10_10_10_REV = 0x8368;\nconst UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B;\nconst UNSIGNED_INT_5_9_9_9_REV = 0x8C3E;\nconst FLOAT_32_UNSIGNED_INT_24_8_REV = 0x8DAD;\nconst UNSIGNED_INT_24_8 = 0x84FA;\n\nconst RG = 0x8227;\nconst RG_INTEGER = 0x8228;\nconst RED = 0x1903;\nconst RED_INTEGER = 0x8D94;\nconst RGB_INTEGER = 0x8D98;\nconst RGBA_INTEGER = 0x8D99;\n\nconst formatInfo = {};\n{\n // NOTE: this is named `numColorComponents` vs `numComponents` so we can let Uglify mangle\n // the name.\n const f = formatInfo;\n f[ALPHA] = { numColorComponents: 1, };\n f[LUMINANCE] = { numColorComponents: 1, };\n f[LUMINANCE_ALPHA] = { numColorComponents: 2, };\n f[RGB] = { numColorComponents: 3, };\n f[RGBA] = { numColorComponents: 4, };\n f[RED] = { numColorComponents: 1, };\n f[RED_INTEGER] = { numColorComponents: 1, };\n f[RG] = { numColorComponents: 2, };\n f[RG_INTEGER] = { numColorComponents: 2, };\n f[RGB] = { numColorComponents: 3, };\n f[RGB_INTEGER] = { numColorComponents: 3, };\n f[RGBA] = { numColorComponents: 4, };\n f[RGBA_INTEGER] = { numColorComponents: 4, };\n f[DEPTH_COMPONENT] = { numColorComponents: 1, };\n f[DEPTH_STENCIL] = { numColorComponents: 2, };\n}\n\n/**\n * @typedef {Object} TextureFormatDetails\n * @property {number} textureFormat format to pass texImage2D and similar functions.\n * @property {boolean} colorRenderable true if you can render to this format of texture.\n * @property {boolean} textureFilterable true if you can filter the texture, false if you can ony use `NEAREST`.\n * @property {number[]} type Array of possible types you can pass to texImage2D and similar function\n * @property {Object.} bytesPerElementMap A map of types to bytes per element\n * @private\n */\n\nlet s_textureInternalFormatInfo;\nfunction getTextureInternalFormatInfo(internalFormat) {\n if (!s_textureInternalFormatInfo) {\n // NOTE: these properties need unique names so we can let Uglify mangle the name.\n const t = {};\n // unsized formats\n t[ALPHA] = { textureFormat: ALPHA, colorRenderable: true, textureFilterable: true, bytesPerElement: [1, 2, 2, 4], type: [UNSIGNED_BYTE, HALF_FLOAT, HALF_FLOAT_OES, FLOAT], };\n t[LUMINANCE] = { textureFormat: LUMINANCE, colorRenderable: true, textureFilterable: true, bytesPerElement: [1, 2, 2, 4], type: [UNSIGNED_BYTE, HALF_FLOAT, HALF_FLOAT_OES, FLOAT], };\n t[LUMINANCE_ALPHA] = { textureFormat: LUMINANCE_ALPHA, colorRenderable: true, textureFilterable: true, bytesPerElement: [2, 4, 4, 8], type: [UNSIGNED_BYTE, HALF_FLOAT, HALF_FLOAT_OES, FLOAT], };\n t[RGB] = { textureFormat: RGB, colorRenderable: true, textureFilterable: true, bytesPerElement: [3, 6, 6, 12, 2], type: [UNSIGNED_BYTE, HALF_FLOAT, HALF_FLOAT_OES, FLOAT, UNSIGNED_SHORT_5_6_5], };\n t[RGBA] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4, 8, 8, 16, 2, 2], type: [UNSIGNED_BYTE, HALF_FLOAT, HALF_FLOAT_OES, FLOAT, UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_5_5_5_1], };\n\n // sized formats\n t[R8] = { textureFormat: RED, colorRenderable: true, textureFilterable: true, bytesPerElement: [1], type: [UNSIGNED_BYTE], };\n t[R8_SNORM] = { textureFormat: RED, colorRenderable: false, textureFilterable: true, bytesPerElement: [1], type: [BYTE], };\n t[R16F] = { textureFormat: RED, colorRenderable: false, textureFilterable: true, bytesPerElement: [4, 2], type: [FLOAT, HALF_FLOAT], };\n t[R32F] = { textureFormat: RED, colorRenderable: false, textureFilterable: false, bytesPerElement: [4], type: [FLOAT], };\n t[R8UI] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [1], type: [UNSIGNED_BYTE], };\n t[R8I] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [1], type: [BYTE], };\n t[R16UI] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [UNSIGNED_SHORT], };\n t[R16I] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [SHORT], };\n t[R32UI] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT], };\n t[R32I] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [INT], };\n t[RG8] = { textureFormat: RG, colorRenderable: true, textureFilterable: true, bytesPerElement: [2], type: [UNSIGNED_BYTE], };\n t[RG8_SNORM] = { textureFormat: RG, colorRenderable: false, textureFilterable: true, bytesPerElement: [2], type: [BYTE], };\n t[RG16F] = { textureFormat: RG, colorRenderable: false, textureFilterable: true, bytesPerElement: [8, 4], type: [FLOAT, HALF_FLOAT], };\n t[RG32F] = { textureFormat: RG, colorRenderable: false, textureFilterable: false, bytesPerElement: [8], type: [FLOAT], };\n t[RG8UI] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [UNSIGNED_BYTE], };\n t[RG8I] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [BYTE], };\n t[RG16UI] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_SHORT], };\n t[RG16I] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [SHORT], };\n t[RG32UI] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [UNSIGNED_INT], };\n t[RG32I] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [INT], };\n t[RGB8] = { textureFormat: RGB, colorRenderable: true, textureFilterable: true, bytesPerElement: [3], type: [UNSIGNED_BYTE], };\n t[SRGB8] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [3], type: [UNSIGNED_BYTE], };\n t[RGB565] = { textureFormat: RGB, colorRenderable: true, textureFilterable: true, bytesPerElement: [3, 2], type: [UNSIGNED_BYTE, UNSIGNED_SHORT_5_6_5], };\n t[RGB8_SNORM] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [3], type: [BYTE], };\n t[R11F_G11F_B10F] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [12, 6, 4], type: [FLOAT, HALF_FLOAT, UNSIGNED_INT_10F_11F_11F_REV], };\n t[RGB9_E5] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [12, 6, 4], type: [FLOAT, HALF_FLOAT, UNSIGNED_INT_5_9_9_9_REV], };\n t[RGB16F] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [12, 6], type: [FLOAT, HALF_FLOAT], };\n t[RGB32F] = { textureFormat: RGB, colorRenderable: false, textureFilterable: false, bytesPerElement: [12], type: [FLOAT], };\n t[RGB8UI] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [3], type: [UNSIGNED_BYTE], };\n t[RGB8I] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [3], type: [BYTE], };\n t[RGB16UI] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [6], type: [UNSIGNED_SHORT], };\n t[RGB16I] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [6], type: [SHORT], };\n t[RGB32UI] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [12], type: [UNSIGNED_INT], };\n t[RGB32I] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [12], type: [INT], };\n t[RGBA8] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4], type: [UNSIGNED_BYTE], };\n t[SRGB8_ALPHA8] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4], type: [UNSIGNED_BYTE], };\n t[RGBA8_SNORM] = { textureFormat: RGBA, colorRenderable: false, textureFilterable: true, bytesPerElement: [4], type: [BYTE], };\n t[RGB5_A1] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4, 2, 4], type: [UNSIGNED_BYTE, UNSIGNED_SHORT_5_5_5_1, UNSIGNED_INT_2_10_10_10_REV], };\n t[RGBA4] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4, 2], type: [UNSIGNED_BYTE, UNSIGNED_SHORT_4_4_4_4], };\n t[RGB10_A2] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4], type: [UNSIGNED_INT_2_10_10_10_REV], };\n t[RGBA16F] = { textureFormat: RGBA, colorRenderable: false, textureFilterable: true, bytesPerElement: [16, 8], type: [FLOAT, HALF_FLOAT], };\n t[RGBA32F] = { textureFormat: RGBA, colorRenderable: false, textureFilterable: false, bytesPerElement: [16], type: [FLOAT], };\n t[RGBA8UI] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_BYTE], };\n t[RGBA8I] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [BYTE], };\n t[RGB10_A2UI] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT_2_10_10_10_REV], };\n t[RGBA16UI] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [UNSIGNED_SHORT], };\n t[RGBA16I] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [SHORT], };\n t[RGBA32I] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [16], type: [INT], };\n t[RGBA32UI] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [16], type: [UNSIGNED_INT], };\n // Sized Internal\n t[DEPTH_COMPONENT16] = { textureFormat: DEPTH_COMPONENT, colorRenderable: true, textureFilterable: false, bytesPerElement: [2, 4], type: [UNSIGNED_SHORT, UNSIGNED_INT], };\n t[DEPTH_COMPONENT24] = { textureFormat: DEPTH_COMPONENT, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT], };\n t[DEPTH_COMPONENT32F] = { textureFormat: DEPTH_COMPONENT, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [FLOAT], };\n t[DEPTH24_STENCIL8] = { textureFormat: DEPTH_STENCIL, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT_24_8], };\n t[DEPTH32F_STENCIL8] = { textureFormat: DEPTH_STENCIL, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [FLOAT_32_UNSIGNED_INT_24_8_REV], };\n\n Object.keys(t).forEach(function(internalFormat) {\n const info = t[internalFormat];\n info.bytesPerElementMap = {};\n info.bytesPerElement.forEach(function(bytesPerElement, ndx) {\n const type = info.type[ndx];\n info.bytesPerElementMap[type] = bytesPerElement;\n });\n });\n s_textureInternalFormatInfo = t;\n }\n return s_textureInternalFormatInfo[internalFormat];\n}\n\n/**\n * Gets the number of bytes per element for a given internalFormat / type\n * @param {number} internalFormat The internalFormat parameter from texImage2D etc..\n * @param {number} type The type parameter for texImage2D etc..\n * @return {number} the number of bytes per element for the given internalFormat, type combo\n * @memberOf module:twgl/textures\n */\nfunction getBytesPerElementForInternalFormat(internalFormat, type) {\n const info = getTextureInternalFormatInfo(internalFormat);\n if (!info) {\n throw \"unknown internal format\";\n }\n const bytesPerElement = info.bytesPerElementMap[type];\n if (bytesPerElement === undefined) {\n throw \"unknown internal format\";\n }\n return bytesPerElement;\n}\n\n/**\n * Info related to a specific texture internalFormat as returned\n * from {@link module:twgl/textures.getFormatAndTypeForInternalFormat}.\n *\n * @typedef {Object} TextureFormatInfo\n * @property {number} format Format to pass to texImage2D and related functions\n * @property {number} type Type to pass to texImage2D and related functions\n * @memberOf module:twgl/textures\n */\n\n/**\n * Gets the format and type for a given internalFormat\n *\n * @param {number} internalFormat The internal format\n * @return {module:twgl/textures.TextureFormatInfo} the corresponding format and type,\n * @memberOf module:twgl/textures\n */\nfunction getFormatAndTypeForInternalFormat(internalFormat) {\n const info = getTextureInternalFormatInfo(internalFormat);\n if (!info) {\n throw \"unknown internal format\";\n }\n return {\n format: info.textureFormat,\n type: info.type[0],\n };\n}\n\n/**\n * Returns true if value is power of 2\n * @param {number} value number to check.\n * @return true if value is power of 2\n * @private\n */\nfunction isPowerOf2(value) {\n return (value & (value - 1)) === 0;\n}\n\n/**\n * Gets whether or not we can generate mips for the given\n * internal format.\n *\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {number} width The width parameter from texImage2D etc..\n * @param {number} height The height parameter from texImage2D etc..\n * @param {number} internalFormat The internalFormat parameter from texImage2D etc..\n * @return {boolean} true if we can generate mips\n * @memberOf module:twgl/textures\n */\nfunction canGenerateMipmap(gl, width, height, internalFormat) {\n if (!utils.isWebGL2(gl)) {\n return isPowerOf2(width) && isPowerOf2(height);\n }\n const info = getTextureInternalFormatInfo(internalFormat);\n if (!info) {\n throw \"unknown internal format\";\n }\n return info.colorRenderable && info.textureFilterable;\n}\n\n/**\n * Gets whether or not we can generate mips for the given format\n * @param {number} internalFormat The internalFormat parameter from texImage2D etc..\n * @return {boolean} true if we can generate mips\n * @memberOf module:twgl/textures\n */\nfunction canFilter(internalFormat) {\n const info = getTextureInternalFormatInfo(internalFormat);\n if (!info) {\n throw \"unknown internal format\";\n }\n return info.textureFilterable;\n}\n\n/**\n * Gets the number of components for a given image format.\n * @param {number} format the format.\n * @return {number} the number of components for the format.\n * @memberOf module:twgl/textures\n */\nfunction getNumComponentsForFormat(format) {\n const info = formatInfo[format];\n if (!info) {\n throw \"unknown format: \" + format;\n }\n return info.numColorComponents;\n}\n\n/**\n * Gets the texture type for a given array type.\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @return {number} the gl texture type\n * @private\n */\nfunction getTextureTypeForArrayType(gl, src, defaultType) {\n if (isArrayBuffer(src)) {\n return typedArrays.getGLTypeForTypedArray(src);\n }\n return defaultType || UNSIGNED_BYTE;\n}\n\nfunction guessDimensions(gl, target, width, height, numElements) {\n if (numElements % 1 !== 0) {\n throw \"can't guess dimensions\";\n }\n if (!width && !height) {\n const size = Math.sqrt(numElements / (target === TEXTURE_CUBE_MAP ? 6 : 1));\n if (size % 1 === 0) {\n width = size;\n height = size;\n } else {\n width = numElements;\n height = 1;\n }\n } else if (!height) {\n height = numElements / width;\n if (height % 1) {\n throw \"can't guess dimensions\";\n }\n } else if (!width) {\n width = numElements / height;\n if (width % 1) {\n throw \"can't guess dimensions\";\n }\n }\n return {\n width: width,\n height: height,\n };\n}\n\n/**\n * Sets the default texture color.\n *\n * The default texture color is used when loading textures from\n * urls. Because the URL will be loaded async we'd like to be\n * able to use the texture immediately. By putting a 1x1 pixel\n * color in the texture we can start using the texture before\n * the URL has loaded.\n *\n * @param {number[]} color Array of 4 values in the range 0 to 1\n * @deprecated see {@link module:twgl.setDefaults}\n * @memberOf module:twgl/textures\n */\nfunction setDefaultTextureColor(color) {\n defaults.textureColor = new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);\n}\n\nfunction setDefaults(newDefaults) {\n helper.copyExistingProperties(newDefaults, defaults);\n if (newDefaults.textureColor) {\n setDefaultTextureColor(newDefaults.textureColor);\n }\n}\n\n/**\n * A function to generate the source for a texture.\n * @callback TextureFunc\n * @param {WebGLRenderingContext} gl A WebGLRenderingContext\n * @param {module:twgl.TextureOptions} options the texture options\n * @return {*} Returns any of the things documented for `src` for {@link module:twgl.TextureOptions}.\n * @memberOf module:twgl\n */\n\n/**\n * Texture options passed to most texture functions. Each function will use whatever options\n * are appropriate for its needs. This lets you pass the same options to all functions.\n *\n * Note: A `TexImageSource` is defined in the WebGL spec as a `HTMLImageElement`, `HTMLVideoElement`,\n * `HTMLCanvasElement`, `ImageBitmap`, or `ImageData`.\n *\n * @typedef {Object} TextureOptions\n * @property {number} [target] the type of texture `gl.TEXTURE_2D` or `gl.TEXTURE_CUBE_MAP`. Defaults to `gl.TEXTURE_2D`.\n * @property {number} [level] the mip level to affect. Defaults to 0. Note, if set auto will be considered false unless explicitly set to true.\n * @property {number} [width] the width of the texture. Only used if src is an array or typed array or null.\n * @property {number} [height] the height of a texture. Only used if src is an array or typed array or null.\n * @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` .\n * @property {number} [min] the min filter setting (eg. `gl.LINEAR`). Defaults to `gl.NEAREST_MIPMAP_LINEAR`\n * or if texture is not a power of 2 on both dimensions then defaults to `gl.LINEAR`.\n * @property {number} [mag] the mag filter setting (eg. `gl.LINEAR`). Defaults to `gl.LINEAR`\n * @property {number} [minMag] both the min and mag filter settings.\n * @property {number} [internalFormat] internal format for texture. Defaults to `gl.RGBA`\n * @property {number} [format] format for texture. Defaults to `gl.RGBA`.\n * @property {number} [type] type for texture. Defaults to `gl.UNSIGNED_BYTE` unless `src` is ArrayBufferView. If `src`\n * is ArrayBufferView defaults to type that matches ArrayBufferView type.\n * @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\n * @property {number} [wrapS] Texture wrapping for S. Defaults to `gl.REPEAT` and `gl.CLAMP_TO_EDGE` for cube. If set takes precedence over `wrap`.\n * @property {number} [wrapT] Texture wrapping for T. Defaults to `gl.REPEAT` and `gl.CLAMP_TO_EDGE` for cube. If set takes precedence over `wrap`.\n * @property {number} [wrapR] Texture wrapping for R. Defaults to `gl.REPEAT` and `gl.CLAMP_TO_EDGE` for cube. If set takes precedence over `wrap`.\n * @property {number} [minLod] TEXTURE_MIN_LOD setting\n * @property {number} [maxLod] TEXTURE_MAX_LOD setting\n * @property {number} [baseLevel] TEXTURE_BASE_LEVEL setting\n * @property {number} [maxLevel] TEXTURE_MAX_LEVEL setting\n * @property {number} [unpackAlignment] The `gl.UNPACK_ALIGNMENT` used when uploading an array. Defaults to 1.\n * @property {number[]|ArrayBufferView} [color] Color to initialize this texture with if loading an image asynchronously.\n * The default use a blue 1x1 pixel texture. You can set another default by calling `twgl.setDefaults`\n * or you can set an individual texture's initial color by setting this property. Example: `[1, .5, .5, 1]` = pink\n * @property {number} [premultiplyAlpha] Whether or not to premultiply alpha. Defaults to whatever the current setting is.\n * This lets you set it once before calling `twgl.createTexture` or `twgl.createTextures` and only override\n * the current setting for specific textures.\n * @property {number} [flipY] Whether or not to flip the texture vertically on upload. Defaults to whatever the current setting is.\n * This lets you set it once before calling `twgl.createTexture` or `twgl.createTextures` and only override\n * the current setting for specific textures.\n * @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.\n * This lets you set it once before calling `twgl.createTexture` or `twgl.createTextures` and only override\n * the current setting for specific textures.\n * @property {boolean} [auto] If `undefined` or `true`, in WebGL1, texture filtering is set automatically for non-power of 2 images and\n * mips are generated for power of 2 images. In WebGL2 mips are generated if they can be. Note: if `level` is set above\n * then then `auto` is assumed to be `false` unless explicity set to `true`.\n * @property {number[]} [cubeFaceOrder] The order that cube faces are pulled out of an img or set of images. The default is\n *\n * [gl.TEXTURE_CUBE_MAP_POSITIVE_X,\n * gl.TEXTURE_CUBE_MAP_NEGATIVE_X,\n * gl.TEXTURE_CUBE_MAP_POSITIVE_Y,\n * gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,\n * gl.TEXTURE_CUBE_MAP_POSITIVE_Z,\n * gl.TEXTURE_CUBE_MAP_NEGATIVE_Z]\n *\n * @property {(number[]|ArrayBufferView|TexImageSource|TexImageSource[]|string|string[]|module:twgl.TextureFunc)} [src] source for texture\n *\n * If `string` then it's assumed to be a URL to an image. The image will be downloaded async. A usable\n * 1x1 pixel texture will be returned immediately. The texture will be updated once the image has downloaded.\n * If `target` is `gl.TEXTURE_CUBE_MAP` will attempt to divide image into 6 square pieces. 1x6, 6x1, 3x2, 2x3.\n * The pieces will be uploaded in `cubeFaceOrder`\n *\n * 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.\n *\n * If `string[]` or `TexImageSource[]` and target is `gl.TEXTURE_2D_ARRAY` then each entry is a slice of the a 2d array texture\n * and will be scaled to the specified width and height OR to the size of the first image that loads.\n *\n * If `TexImageSource` then it wil be used immediately to create the contents of the texture. Examples `HTMLImageElement`,\n * `HTMLCanvasElement`, `HTMLVideoElement`.\n *\n * If `number[]` or `ArrayBufferView` it's assumed to be data for a texture. If `width` or `height` is\n * not specified it is guessed as follows. First the number of elements is computed by `src.length / numComponents`\n * where `numComponents` is derived from `format`. If `target` is `gl.TEXTURE_CUBE_MAP` then `numElements` is divided\n * by 6. Then\n *\n * * If neither `width` nor `height` are specified and `sqrt(numElements)` is an integer then width and height\n * are set to `sqrt(numElements)`. Otherwise `width = numElements` and `height = 1`.\n *\n * * If only one of `width` or `height` is specified then the other equals `numElements / specifiedDimension`.\n *\n * If `number[]` will be converted to `type`.\n *\n * If `src` is a function it will be called with a `WebGLRenderingContext` and these options.\n * Whatever it returns is subject to these rules. So it can return a string url, an `HTMLElement`\n * an array etc...\n *\n * If `src` is undefined then an empty texture will be created of size `width` by `height`.\n *\n * @property {string} [crossOrigin] What to set the crossOrigin property of images when they are downloaded.\n * default: undefined. Also see {@link module:twgl.setDefaults}.\n *\n * @memberOf module:twgl\n */\n\n// NOTE: While querying GL is considered slow it's not remotely as slow\n// as uploading a texture. On top of that you're unlikely to call this in\n// a perf critical loop. Even if upload a texture every frame that's unlikely\n// to be more than 1 or 2 textures a frame. In other words, the benefits of\n// making the API easy to use outweigh any supposed perf benefits\n//\n// Also note I get that having one global of these is bad practice.\n// As long as it's used correctly it means no garbage which probably\n// doesn't matter when dealing with textures but old habits die hard.\nconst lastPackState = {};\n\n/**\n * Saves any packing state that will be set based on the options.\n * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @private\n */\nfunction savePackState(gl, options) {\n if (options.colorspaceConversion !== undefined) {\n lastPackState.colorspaceConversion = gl.getParameter(UNPACK_COLORSPACE_CONVERSION_WEBGL);\n gl.pixelStorei(UNPACK_COLORSPACE_CONVERSION_WEBGL, options.colorspaceConversion);\n }\n if (options.premultiplyAlpha !== undefined) {\n lastPackState.premultiplyAlpha = gl.getParameter(UNPACK_PREMULTIPLY_ALPHA_WEBGL);\n gl.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL, options.premultiplyAlpha);\n }\n if (options.flipY !== undefined) {\n lastPackState.flipY = gl.getParameter(UNPACK_FLIP_Y_WEBGL);\n gl.pixelStorei(UNPACK_FLIP_Y_WEBGL, options.flipY);\n }\n}\n\n/**\n * Restores any packing state that was set based on the options.\n * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @private\n */\nfunction restorePackState(gl, options) {\n if (options.colorspaceConversion !== undefined) {\n gl.pixelStorei(UNPACK_COLORSPACE_CONVERSION_WEBGL, lastPackState.colorspaceConversion);\n }\n if (options.premultiplyAlpha !== undefined) {\n gl.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL, lastPackState.premultiplyAlpha);\n }\n if (options.flipY !== undefined) {\n gl.pixelStorei(UNPACK_FLIP_Y_WEBGL, lastPackState.flipY);\n }\n}\n\n/**\n * Saves state related to data size\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @private\n */\nfunction saveSkipState(gl) {\n lastPackState.unpackAlignment = gl.getParameter(UNPACK_ALIGNMENT);\n if (utils.isWebGL2(gl)) {\n lastPackState.unpackRowLength = gl.getParameter(UNPACK_ROW_LENGTH);\n lastPackState.unpackImageHeight = gl.getParameter(UNPACK_IMAGE_HEIGHT);\n lastPackState.unpackSkipPixels = gl.getParameter(UNPACK_SKIP_PIXELS);\n lastPackState.unpackSkipRows = gl.getParameter(UNPACK_SKIP_ROWS);\n lastPackState.unpackSkipImages = gl.getParameter(UNPACK_SKIP_IMAGES);\n }\n}\n\n/**\n * Restores state related to data size\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @private\n */\nfunction restoreSkipState(gl) {\n gl.pixelStorei(UNPACK_ALIGNMENT, lastPackState.unpackAlignment);\n if (utils.isWebGL2(gl)) {\n gl.pixelStorei(UNPACK_ROW_LENGTH, lastPackState.unpackRowLength);\n gl.pixelStorei(UNPACK_IMAGE_HEIGHT, lastPackState.unpackImageHeight);\n gl.pixelStorei(UNPACK_SKIP_PIXELS, lastPackState.unpackSkipPixels);\n gl.pixelStorei(UNPACK_SKIP_ROWS, lastPackState.unpackSkipRows);\n gl.pixelStorei(UNPACK_SKIP_IMAGES, lastPackState.unpackSkipImages);\n }\n}\n\n\n/**\n * Sets the parameters of a texture or sampler\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {number|WebGLSampler} target texture target or sampler\n * @param {function()} parameteriFn texParameteri or samplerParameteri fn\n * @param {WebGLTexture} tex the WebGLTexture to set parameters for\n * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.\n * This is often the same options you passed in when you created the texture.\n * @private\n */\nfunction setTextureSamplerParameters(gl, target, parameteriFn, options) {\n if (options.minMag) {\n parameteriFn.call(gl, target, TEXTURE_MIN_FILTER, options.minMag);\n parameteriFn.call(gl, target, TEXTURE_MAG_FILTER, options.minMag);\n }\n if (options.min) {\n parameteriFn.call(gl, target, TEXTURE_MIN_FILTER, options.min);\n }\n if (options.mag) {\n parameteriFn.call(gl, target, TEXTURE_MAG_FILTER, options.mag);\n }\n if (options.wrap) {\n parameteriFn.call(gl, target, TEXTURE_WRAP_S, options.wrap);\n parameteriFn.call(gl, target, TEXTURE_WRAP_T, options.wrap);\n if (target === TEXTURE_3D || helper.isSampler(gl, target)) {\n parameteriFn.call(gl, target, TEXTURE_WRAP_R, options.wrap);\n }\n }\n if (options.wrapR) {\n parameteriFn.call(gl, target, TEXTURE_WRAP_R, options.wrapR);\n }\n if (options.wrapS) {\n parameteriFn.call(gl, target, TEXTURE_WRAP_S, options.wrapS);\n }\n if (options.wrapT) {\n parameteriFn.call(gl, target, TEXTURE_WRAP_T, options.wrapT);\n }\n if (options.minLod) {\n parameteriFn.call(gl, target, TEXTURE_MIN_LOD, options.minLod);\n }\n if (options.maxLod) {\n parameteriFn.call(gl, target, TEXTURE_MAX_LOD, options.maxLod);\n }\n if (options.baseLevel) {\n parameteriFn.call(gl, target, TEXTURE_BASE_LEVEL, options.baseLevel);\n }\n if (options.maxLevel) {\n parameteriFn.call(gl, target, TEXTURE_MAX_LEVEL, options.maxLevel);\n }\n}\n\n/**\n * Sets the texture parameters of a texture.\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {WebGLTexture} tex the WebGLTexture to set parameters for\n * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.\n * This is often the same options you passed in when you created the texture.\n * @memberOf module:twgl/textures\n */\nfunction setTextureParameters(gl, tex, options) {\n const target = options.target || TEXTURE_2D;\n gl.bindTexture(target, tex);\n setTextureSamplerParameters(gl, target, gl.texParameteri, options);\n}\n\n/**\n * Sets the sampler parameters of a sampler.\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {WebGLSampler} sampler the WebGLSampler to set parameters for\n * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.\n * @memberOf module:twgl/textures\n */\nfunction setSamplerParameters(gl, sampler, options) {\n setTextureSamplerParameters(gl, sampler, gl.samplerParameteri, options);\n}\n\n/**\n * Creates a new sampler object and sets parameters.\n *\n * Example:\n *\n * const sampler = twgl.createSampler(gl, {\n * minMag: gl.NEAREST, // sets both TEXTURE_MIN_FILTER and TEXTURE_MAG_FILTER\n * wrap: gl.CLAMP_TO_NEAREST, // sets both TEXTURE_WRAP_S and TEXTURE_WRAP_T and TEXTURE_WRAP_R\n * });\n *\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {Object.} options A object of TextureOptions one per sampler.\n * @return {Object.} the created samplers by name\n * @private\n */\nfunction createSampler(gl, options) {\n const sampler = gl.createSampler();\n setSamplerParameters(gl, sampler, options);\n return sampler;\n}\n\n/**\n * Creates a multiple sampler objects and sets parameters on each.\n *\n * Example:\n *\n * const samplers = twgl.createSamplers(gl, {\n * nearest: {\n * minMag: gl.NEAREST,\n * },\n * nearestClampS: {\n * minMag: gl.NEAREST,\n * wrapS: gl.CLAMP_TO_NEAREST,\n * },\n * linear: {\n * minMag: gl.LINEAR,\n * },\n * nearestClamp: {\n * minMag: gl.NEAREST,\n * wrap: gl.CLAMP_TO_EDGE,\n * },\n * linearClamp: {\n * minMag: gl.LINEAR,\n * wrap: gl.CLAMP_TO_EDGE,\n * },\n * linearClampT: {\n * minMag: gl.LINEAR,\n * wrapT: gl.CLAMP_TO_EDGE,\n * },\n * });\n *\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set on the sampler\n * @private\n */\nfunction createSamplers(gl, samplerOptions) {\n const samplers = {};\n Object.keys(samplerOptions).forEach(function(name) {\n samplers[name] = createSampler(gl, samplerOptions[name]);\n });\n return samplers;\n}\n\n/**\n * Makes a 1x1 pixel\n * If no color is passed in uses the default color which can be set by calling `setDefaultTextureColor`.\n * @param {(number[]|ArrayBufferView)} [color] The color using 0-1 values\n * @return {Uint8Array} Unit8Array with color.\n * @private\n */\nfunction make1Pixel(color) {\n color = color || defaults.textureColor;\n if (isArrayBuffer(color)) {\n return color;\n }\n return new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);\n}\n\n/**\n * Sets filtering or generates mips for texture based on width or height\n * If width or height is not passed in uses `options.width` and//or `options.height`\n *\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {WebGLTexture} tex the WebGLTexture to set parameters for\n * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.\n * This is often the same options you passed in when you created the texture.\n * @param {number} [width] width of texture\n * @param {number} [height] height of texture\n * @param {number} [internalFormat] The internalFormat parameter from texImage2D etc..\n * @memberOf module:twgl/textures\n */\nfunction setTextureFilteringForSize(gl, tex, options, width, height, internalFormat) {\n options = options || defaults.textureOptions;\n internalFormat = internalFormat || RGBA;\n const target = options.target || TEXTURE_2D;\n width = width || options.width;\n height = height || options.height;\n gl.bindTexture(target, tex);\n if (canGenerateMipmap(gl, width, height, internalFormat)) {\n gl.generateMipmap(target);\n } else {\n const filtering = canFilter(internalFormat) ? LINEAR : NEAREST;\n gl.texParameteri(target, TEXTURE_MIN_FILTER, filtering);\n gl.texParameteri(target, TEXTURE_MAG_FILTER, filtering);\n gl.texParameteri(target, TEXTURE_WRAP_S, CLAMP_TO_EDGE);\n gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE);\n }\n}\n\nfunction shouldAutomaticallySetTextureFilteringForSize(options) {\n return options.auto === true || (options.auto === undefined && options.level === undefined);\n}\n\n/**\n * Gets an array of cubemap face enums\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.\n * This is often the same options you passed in when you created the texture.\n * @return {number[]} cubemap face enums\n * @private\n */\nfunction getCubeFaceOrder(gl, options) {\n options = options || {};\n return options.cubeFaceOrder || [\n TEXTURE_CUBE_MAP_POSITIVE_X,\n TEXTURE_CUBE_MAP_NEGATIVE_X,\n TEXTURE_CUBE_MAP_POSITIVE_Y,\n TEXTURE_CUBE_MAP_NEGATIVE_Y,\n TEXTURE_CUBE_MAP_POSITIVE_Z,\n TEXTURE_CUBE_MAP_NEGATIVE_Z,\n ];\n}\n\n/**\n * @typedef {Object} FaceInfo\n * @property {number} face gl enum for texImage2D\n * @property {number} ndx face index (0 - 5) into source data\n * @ignore\n */\n\n/**\n * Gets an array of FaceInfos\n * There's a bug in some NVidia drivers that will crash the driver if\n * `gl.TEXTURE_CUBE_MAP_POSITIVE_X` is not uploaded first. So, we take\n * the user's desired order from his faces to WebGL and make sure we\n * do the faces in WebGL order\n *\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.\n * @return {FaceInfo[]} cubemap face infos. Arguably the `face` property of each element is redundant but\n * it's needed internally to sort the array of `ndx` properties by `face`.\n * @private\n */\nfunction getCubeFacesWithNdx(gl, options) {\n const faces = getCubeFaceOrder(gl, options);\n // work around bug in NVidia drivers. We have to upload the first face first else the driver crashes :(\n const facesWithNdx = faces.map(function(face, ndx) {\n return { face: face, ndx: ndx };\n });\n facesWithNdx.sort(function(a, b) {\n return a.face - b.face;\n });\n return facesWithNdx;\n}\n\n/**\n * Set a texture from the contents of an element. Will also set\n * texture filtering or generate mips based on the dimensions of the element\n * unless `options.auto === false`. If `target === gl.TEXTURE_CUBE_MAP` will\n * attempt to slice image into 1x6, 2x3, 3x2, or 6x1 images, one for each face.\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {WebGLTexture} tex the WebGLTexture to set parameters for\n * @param {HTMLElement} element a canvas, img, or video element.\n * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.\n * This is often the same options you passed in when you created the texture.\n * @memberOf module:twgl/textures\n * @kind function\n */\nfunction setTextureFromElement(gl, tex, element, options) {\n options = options || defaults.textureOptions;\n const target = options.target || TEXTURE_2D;\n const level = options.level || 0;\n let width = element.width;\n let height = element.height;\n const internalFormat = options.internalFormat || options.format || RGBA;\n const formatType = getFormatAndTypeForInternalFormat(internalFormat);\n const format = options.format || formatType.format;\n const type = options.type || formatType.type;\n savePackState(gl, options);\n gl.bindTexture(target, tex);\n if (target === TEXTURE_CUBE_MAP) {\n // guess the parts\n const imgWidth = element.width;\n const imgHeight = element.height;\n let size;\n let slices;\n if (imgWidth / 6 === imgHeight) {\n // It's 6x1\n size = imgHeight;\n slices = [0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0];\n } else if (imgHeight / 6 === imgWidth) {\n // It's 1x6\n size = imgWidth;\n slices = [0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5];\n } else if (imgWidth / 3 === imgHeight / 2) {\n // It's 3x2\n size = imgWidth / 3;\n slices = [0, 0, 1, 0, 2, 0, 0, 1, 1, 1, 2, 1];\n } else if (imgWidth / 2 === imgHeight / 3) {\n // It's 2x3\n size = imgWidth / 2;\n slices = [0, 0, 1, 0, 0, 1, 1, 1, 0, 2, 1, 2];\n } else {\n throw \"can't figure out cube map from element: \" + (element.src ? element.src : element.nodeName);\n }\n const ctx = getShared2DContext();\n if (ctx) {\n ctx.canvas.width = size;\n ctx.canvas.height = size;\n width = size;\n height = size;\n getCubeFacesWithNdx(gl, options).forEach(function(f) {\n const xOffset = slices[f.ndx * 2 + 0] * size;\n const yOffset = slices[f.ndx * 2 + 1] * size;\n ctx.drawImage(element, xOffset, yOffset, size, size, 0, 0, size, size);\n gl.texImage2D(f.face, level, internalFormat, format, type, ctx.canvas);\n });\n // Free up the canvas memory\n ctx.canvas.width = 1;\n ctx.canvas.height = 1;\n } else if (typeof createImageBitmap !== 'undefined') {\n // NOTE: It seems like we should prefer ImageBitmap because unlike canvas it's\n // note lossy? (alpha is not premultiplied? although I'm not sure what\n width = size;\n height = size;\n getCubeFacesWithNdx(gl, options).forEach(function(f) {\n const xOffset = slices[f.ndx * 2 + 0] * size;\n const yOffset = slices[f.ndx * 2 + 1] * size;\n // We can't easily use a default texture color here as it would have to match\n // the type across all faces where as with a 2D one there's only one face\n // so we're replacing everything all at once. It also has to be the correct size.\n // On the other hand we need all faces to be the same size so as one face loads\n // the rest match else the texture will be un-renderable.\n gl.texImage2D(f.face, level, internalFormat, size, size, 0, format, type, null);\n createImageBitmap(element, xOffset, yOffset, size, size, {\n premultiplyAlpha: 'none',\n colorSpaceConversion: 'none',\n })\n .then(function(imageBitmap) {\n savePackState(gl, options);\n gl.bindTexture(target, tex);\n gl.texImage2D(f.face, level, internalFormat, format, type, imageBitmap);\n restorePackState(gl, options);\n if (shouldAutomaticallySetTextureFilteringForSize(options)) {\n setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);\n }\n });\n });\n }\n } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {\n const smallest = Math.min(element.width, element.height);\n const largest = Math.max(element.width, element.height);\n const depth = largest / smallest;\n if (depth % 1 !== 0) {\n throw \"can not compute 3D dimensions of element\";\n }\n const xMult = element.width === largest ? 1 : 0;\n const yMult = element.height === largest ? 1 : 0;\n saveSkipState(gl);\n gl.pixelStorei(UNPACK_ALIGNMENT, 1);\n gl.pixelStorei(UNPACK_ROW_LENGTH, element.width);\n gl.pixelStorei(UNPACK_IMAGE_HEIGHT, 0);\n gl.pixelStorei(UNPACK_SKIP_IMAGES, 0);\n gl.texImage3D(target, level, internalFormat, smallest, smallest, smallest, 0, format, type, null);\n for (let d = 0; d < depth; ++d) {\n const srcX = d * smallest * xMult;\n const srcY = d * smallest * yMult;\n gl.pixelStorei(UNPACK_SKIP_PIXELS, srcX);\n gl.pixelStorei(UNPACK_SKIP_ROWS, srcY);\n gl.texSubImage3D(target, level, 0, 0, d, smallest, smallest, 1, format, type, element);\n }\n restoreSkipState(gl);\n } else {\n gl.texImage2D(target, level, internalFormat, format, type, element);\n }\n restorePackState(gl, options);\n if (shouldAutomaticallySetTextureFilteringForSize(options)) {\n setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);\n }\n setTextureParameters(gl, tex, options);\n}\n\nfunction noop() {\n}\n\n/**\n * Checks whether the url's origin is the same so that we can set the `crossOrigin`\n * @param {string} url url to image\n * @returns {boolean} true if the window's origin is the same as image's url\n * @private\n */\nfunction urlIsSameOrigin(url) {\n if (typeof document !== 'undefined') {\n // for IE really\n const a = document.createElement('a');\n a.href = url;\n return a.hostname === location.hostname &&\n a.port === location.port &&\n a.protocol === location.protocol;\n } else {\n const localOrigin = (new URL(location.href)).origin;\n const urlOrigin = (new URL(url, location.href)).origin;\n return urlOrigin === localOrigin;\n }\n}\n\nfunction setToAnonymousIfUndefinedAndURLIsNotSameOrigin(url, crossOrigin) {\n return crossOrigin === undefined && !urlIsSameOrigin(url)\n ? 'anonymous'\n : crossOrigin;\n}\n\n/**\n * Loads an image\n * @param {string} url url to image\n * @param {string} crossOrigin\n * @param {function(err, img)} [callback] a callback that's passed an error and the image. The error will be non-null\n * if there was an error\n * @return {HTMLImageElement} the image being loaded.\n * @private\n */\nfunction loadImage(url, crossOrigin, callback) {\n callback = callback || noop;\n let img;\n crossOrigin = crossOrigin !== undefined ? crossOrigin : defaults.crossOrigin;\n crossOrigin = setToAnonymousIfUndefinedAndURLIsNotSameOrigin(url, crossOrigin);\n if (typeof Image !== 'undefined') {\n img = new Image();\n if (crossOrigin !== undefined) {\n img.crossOrigin = crossOrigin;\n }\n\n const clearEventHandlers = function clearEventHandlers() {\n img.removeEventListener('error', onError); // eslint-disable-line\n img.removeEventListener('load', onLoad); // eslint-disable-line\n img = null;\n };\n\n const onError = function onError() {\n const msg = \"couldn't load image: \" + url;\n helper.error(msg);\n callback(msg, img);\n clearEventHandlers();\n };\n\n const onLoad = function onLoad() {\n callback(null, img);\n clearEventHandlers();\n };\n\n img.addEventListener('error', onError);\n img.addEventListener('load', onLoad);\n img.src = url;\n return img;\n } else if (typeof ImageBitmap !== 'undefined') {\n let err;\n let bm;\n const cb = function cb() {\n callback(err, bm);\n };\n\n const options = {};\n if (crossOrigin) {\n options.mode = 'cors'; // TODO: not sure how to translate image.crossOrigin\n }\n fetch(url, options).then(function(response) {\n if (!response.ok) {\n throw response;\n }\n return response.blob();\n }).then(function(blob) {\n return createImageBitmap(blob, {\n premultiplyAlpha: 'none',\n colorSpaceConversion: 'none',\n });\n }).then(function(bitmap) {\n // not sure if this works. We don't want\n // to catch the user's error. So, call\n // the callback in a timeout so we're\n // not in this scope inside the promise.\n bm = bitmap;\n setTimeout(cb);\n }).catch(function(e) {\n err = e;\n setTimeout(cb);\n });\n img = null;\n }\n return img;\n}\n\n/**\n * check if object is a TexImageSource\n *\n * @param {Object} obj Object to test\n * @return {boolean} true if object is a TexImageSource\n * @private\n */\nfunction isTexImageSource(obj) {\n return (typeof ImageBitmap !== 'undefined' && obj instanceof ImageBitmap) ||\n (typeof ImageData !== 'undefined' && obj instanceof ImageData) ||\n (typeof HTMLElement !== 'undefined' && obj instanceof HTMLElement);\n}\n\n/**\n * if obj is an TexImageSource then just\n * uses it otherwise if obj is a string\n * then load it first.\n *\n * @param {string|TexImageSource} obj\n * @param {string} crossOrigin\n * @param {function(err, img)} [callback] a callback that's passed an error and the image. The error will be non-null\n * if there was an error\n * @private\n */\nfunction loadAndUseImage(obj, crossOrigin, callback) {\n if (isTexImageSource(obj)) {\n setTimeout(function() {\n callback(null, obj);\n });\n return obj;\n }\n\n return loadImage(obj, crossOrigin, callback);\n}\n\n/**\n * Sets a texture to a 1x1 pixel color. If `options.color === false` is nothing happens. If it's not set\n * the default texture color is used which can be set by calling `setDefaultTextureColor`.\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {WebGLTexture} tex the WebGLTexture to set parameters for\n * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.\n * This is often the same options you passed in when you created the texture.\n * @memberOf module:twgl/textures\n */\nfunction setTextureTo1PixelColor(gl, tex, options) {\n options = options || defaults.textureOptions;\n const target = options.target || TEXTURE_2D;\n gl.bindTexture(target, tex);\n if (options.color === false) {\n return;\n }\n // Assume it's a URL\n // Put 1x1 pixels in texture. That makes it renderable immediately regardless of filtering.\n const color = make1Pixel(options.color);\n if (target === TEXTURE_CUBE_MAP) {\n for (let ii = 0; ii < 6; ++ii) {\n gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, 0, RGBA, 1, 1, 0, RGBA, UNSIGNED_BYTE, color);\n }\n } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {\n gl.texImage3D(target, 0, RGBA, 1, 1, 1, 0, RGBA, UNSIGNED_BYTE, color);\n } else {\n gl.texImage2D(target, 0, RGBA, 1, 1, 0, RGBA, UNSIGNED_BYTE, color);\n }\n}\n\n/**\n * The src image(s) used to create a texture.\n *\n * When you call {@link module:twgl.createTexture} or {@link module:twgl.createTextures}\n * you can pass in urls for images to load into the textures. If it's a single url\n * then this will be a single HTMLImageElement. If it's an array of urls used for a cubemap\n * this will be a corresponding array of images for the cubemap.\n *\n * @typedef {HTMLImageElement|HTMLImageElement[]} TextureSrc\n * @memberOf module:twgl\n */\n\n/**\n * A callback for when an image finished downloading and been uploaded into a texture\n * @callback TextureReadyCallback\n * @param {*} err If truthy there was an error.\n * @param {WebGLTexture} texture the texture.\n * @param {module:twgl.TextureSrc} source image(s) used to as the src for the texture\n * @memberOf module:twgl\n */\n\n/**\n * A callback for when all images have finished downloading and been uploaded into their respective textures\n * @callback TexturesReadyCallback\n * @param {*} err If truthy there was an error.\n * @param {Object.} textures the created textures by name. Same as returned by {@link module:twgl.createTextures}.\n * @param {Object.} sources the image(s) used for the texture by name.\n * @memberOf module:twgl\n */\n\n/**\n * A callback for when an image finished downloading and been uploaded into a texture\n * @callback CubemapReadyCallback\n * @param {*} err If truthy there was an error.\n * @param {WebGLTexture} tex the texture.\n * @param {HTMLImageElement[]} imgs the images for each face.\n * @memberOf module:twgl\n */\n\n/**\n * A callback for when an image finished downloading and been uploaded into a texture\n * @callback ThreeDReadyCallback\n * @param {*} err If truthy there was an error.\n * @param {WebGLTexture} tex the texture.\n * @param {HTMLImageElement[]} imgs the images for each slice.\n * @memberOf module:twgl\n */\n\n/**\n * Loads a texture from an image from a Url as specified in `options.src`\n * If `options.color !== false` will set the texture to a 1x1 pixel color so that the texture is\n * immediately useable. It will be updated with the contents of the image once the image has finished\n * downloading. Filtering options will be set as appropriate for image unless `options.auto === false`.\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {WebGLTexture} tex the WebGLTexture to set parameters for\n * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.\n * @param {module:twgl.TextureReadyCallback} [callback] A function to be called when the image has finished loading. err will\n * be non null if there was an error.\n * @return {HTMLImageElement} the image being downloaded.\n * @memberOf module:twgl/textures\n */\nfunction loadTextureFromUrl(gl, tex, options, callback) {\n callback = callback || noop;\n options = options || defaults.textureOptions;\n setTextureTo1PixelColor(gl, tex, options);\n // Because it's async we need to copy the options.\n options = Object.assign({}, options);\n const img = loadAndUseImage(options.src, options.crossOrigin, function(err, img) {\n if (err) {\n callback(err, tex, img);\n } else {\n setTextureFromElement(gl, tex, img, options);\n callback(null, tex, img);\n }\n });\n return img;\n}\n\n/**\n * Loads a cubemap from 6 urls or TexImageSources as specified in `options.src`. Will set the cubemap to a 1x1 pixel color\n * so that it is usable immediately unless `option.color === false`.\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {WebGLTexture} tex the WebGLTexture to set parameters for\n * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.\n * @param {module:twgl.CubemapReadyCallback} [callback] A function to be called when all the images have finished loading. err will\n * be non null if there was an error.\n * @memberOf module:twgl/textures\n */\nfunction loadCubemapFromUrls(gl, tex, options, callback) {\n callback = callback || noop;\n const urls = options.src;\n if (urls.length !== 6) {\n throw \"there must be 6 urls for a cubemap\";\n }\n const level = options.level || 0;\n const internalFormat = options.internalFormat || options.format || RGBA;\n const formatType = getFormatAndTypeForInternalFormat(internalFormat);\n const format = options.format || formatType.format;\n const type = options.type || UNSIGNED_BYTE;\n const target = options.target || TEXTURE_2D;\n if (target !== TEXTURE_CUBE_MAP) {\n throw \"target must be TEXTURE_CUBE_MAP\";\n }\n setTextureTo1PixelColor(gl, tex, options);\n // Because it's async we need to copy the options.\n options = Object.assign({}, options);\n let numToLoad = 6;\n const errors = [];\n const faces = getCubeFaceOrder(gl, options);\n let imgs; // eslint-disable-line\n\n function uploadImg(faceTarget) {\n return function(err, img) {\n --numToLoad;\n if (err) {\n errors.push(err);\n } else {\n if (img.width !== img.height) {\n errors.push(\"cubemap face img is not a square: \" + img.src);\n } else {\n savePackState(gl, options);\n gl.bindTexture(target, tex);\n\n // So assuming this is the first image we now have one face that's img sized\n // and 5 faces that are 1x1 pixel so size the other faces\n if (numToLoad === 5) {\n // use the default order\n getCubeFaceOrder(gl).forEach(function(otherTarget) {\n // Should we re-use the same face or a color?\n gl.texImage2D(otherTarget, level, internalFormat, format, type, img);\n });\n } else {\n gl.texImage2D(faceTarget, level, internalFormat, format, type, img);\n }\n\n restorePackState(gl, options);\n if (shouldAutomaticallySetTextureFilteringForSize(options)) {\n gl.generateMipmap(target);\n }\n }\n }\n\n if (numToLoad === 0) {\n callback(errors.length ? errors : undefined, tex, imgs);\n }\n };\n }\n\n imgs = urls.map(function(url, ndx) {\n return loadAndUseImage(url, options.crossOrigin, uploadImg(faces[ndx]));\n });\n}\n\n/**\n * Loads a 2d array or 3d texture from urls OR TexImageSources as specified in `options.src`.\n * Will set the texture to a 1x1 pixel color\n * so that it is usable immediately unless `option.color === false`.\n *\n * If the width and height is not specified the width and height of the first\n * image loaded will be used. Note that since images are loaded async\n * which image downloads first is unknown.\n *\n * If an image is not the same size as the width and height it will be scaled\n * to that width and height.\n *\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {WebGLTexture} tex the WebGLTexture to set parameters for\n * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.\n * @param {module:twgl.ThreeDReadyCallback} [callback] A function to be called when all the images have finished loading. err will\n * be non null if there was an error.\n * @memberOf module:twgl/textures\n */\nfunction loadSlicesFromUrls(gl, tex, options, callback) {\n callback = callback || noop;\n const urls = options.src;\n const internalFormat = options.internalFormat || options.format || RGBA;\n const formatType = getFormatAndTypeForInternalFormat(internalFormat);\n const format = options.format || formatType.format;\n const type = options.type || UNSIGNED_BYTE;\n const target = options.target || TEXTURE_2D_ARRAY;\n if (target !== TEXTURE_3D && target !== TEXTURE_2D_ARRAY) {\n throw \"target must be TEXTURE_3D or TEXTURE_2D_ARRAY\";\n }\n setTextureTo1PixelColor(gl, tex, options);\n // Because it's async we need to copy the options.\n options = Object.assign({}, options);\n let numToLoad = urls.length;\n const errors = [];\n let imgs; // eslint-disable-line\n const level = options.level || 0;\n let width = options.width;\n let height = options.height;\n const depth = urls.length;\n let firstImage = true;\n\n function uploadImg(slice) {\n return function(err, img) {\n --numToLoad;\n if (err) {\n errors.push(err);\n } else {\n savePackState(gl, options);\n gl.bindTexture(target, tex);\n\n if (firstImage) {\n firstImage = false;\n width = options.width || img.width;\n height = options.height || img.height;\n gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, null);\n\n // put it in every slice otherwise some slices will be 0,0,0,0\n for (let s = 0; s < depth; ++s) {\n gl.texSubImage3D(target, level, 0, 0, s, width, height, 1, format, type, img);\n }\n } else {\n let src = img;\n let ctx;\n if (img.width !== width || img.height !== height) {\n // Size the image to fix\n ctx = getShared2DContext();\n src = ctx.canvas;\n ctx.canvas.width = width;\n ctx.canvas.height = height;\n ctx.drawImage(img, 0, 0, width, height);\n }\n\n gl.texSubImage3D(target, level, 0, 0, slice, width, height, 1, format, type, src);\n\n // free the canvas memory\n if (ctx && src === ctx.canvas) {\n ctx.canvas.width = 0;\n ctx.canvas.height = 0;\n }\n }\n\n restorePackState(gl, options);\n if (shouldAutomaticallySetTextureFilteringForSize(options)) {\n gl.generateMipmap(target);\n }\n }\n\n if (numToLoad === 0) {\n callback(errors.length ? errors : undefined, tex, imgs);\n }\n };\n }\n\n imgs = urls.map(function(url, ndx) {\n return loadAndUseImage(url, options.crossOrigin, uploadImg(ndx));\n });\n}\n\n/**\n * Sets a texture from an array or typed array. If the width or height is not provided will attempt to\n * guess the size. See {@link module:twgl.TextureOptions}.\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {WebGLTexture} tex the WebGLTexture to set parameters for\n * @param {(number[]|ArrayBufferView)} src An array or typed arry with texture data.\n * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.\n * This is often the same options you passed in when you created the texture.\n * @memberOf module:twgl/textures\n */\nfunction setTextureFromArray(gl, tex, src, options) {\n options = options || defaults.textureOptions;\n const target = options.target || TEXTURE_2D;\n gl.bindTexture(target, tex);\n let width = options.width;\n let height = options.height;\n let depth = options.depth;\n const level = options.level || 0;\n const internalFormat = options.internalFormat || options.format || RGBA;\n const formatType = getFormatAndTypeForInternalFormat(internalFormat);\n const format = options.format || formatType.format;\n const type = options.type || getTextureTypeForArrayType(gl, src, formatType.type);\n if (!isArrayBuffer(src)) {\n const Type = typedArrays.getTypedArrayTypeForGLType(type);\n src = new Type(src);\n } else if (src instanceof Uint8ClampedArray) {\n src = new Uint8Array(src.buffer);\n }\n\n const bytesPerElement = getBytesPerElementForInternalFormat(internalFormat, type);\n const numElements = src.byteLength / bytesPerElement; // TODO: check UNPACK_ALIGNMENT?\n if (numElements % 1) {\n throw \"length wrong size for format: \" + utils.glEnumToString(gl, format);\n }\n let dimensions;\n if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {\n if (!width && !height && !depth) {\n const size = Math.cbrt(numElements);\n if (size % 1 !== 0) {\n throw \"can't guess cube size of array of numElements: \" + numElements;\n }\n width = size;\n height = size;\n depth = size;\n } else if (width && (!height || !depth)) {\n dimensions = guessDimensions(gl, target, height, depth, numElements / width);\n height = dimensions.width;\n depth = dimensions.height;\n } else if (height && (!width || !depth)) {\n dimensions = guessDimensions(gl, target, width, depth, numElements / height);\n width = dimensions.width;\n depth = dimensions.height;\n } else {\n dimensions = guessDimensions(gl, target, width, height, numElements / depth);\n width = dimensions.width;\n height = dimensions.height;\n }\n } else {\n dimensions = guessDimensions(gl, target, width, height, numElements);\n width = dimensions.width;\n height = dimensions.height;\n }\n saveSkipState(gl);\n gl.pixelStorei(UNPACK_ALIGNMENT, options.unpackAlignment || 1);\n savePackState(gl, options);\n if (target === TEXTURE_CUBE_MAP) {\n const elementsPerElement = bytesPerElement / src.BYTES_PER_ELEMENT;\n const faceSize = numElements / 6 * elementsPerElement;\n\n getCubeFacesWithNdx(gl, options).forEach(f => {\n const offset = faceSize * f.ndx;\n const data = src.subarray(offset, offset + faceSize);\n gl.texImage2D(f.face, level, internalFormat, width, height, 0, format, type, data);\n });\n } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {\n gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, src);\n } else {\n gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, src);\n }\n restorePackState(gl, options);\n restoreSkipState(gl);\n return {\n width: width,\n height: height,\n depth: depth,\n type: type,\n };\n}\n\n/**\n * Sets a texture with no contents of a certain size. In other words calls `gl.texImage2D` with `null`.\n * You must set `options.width` and `options.height`.\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {WebGLTexture} tex the WebGLTexture to set parameters for\n * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.\n * @memberOf module:twgl/textures\n */\nfunction setEmptyTexture(gl, tex, options) {\n const target = options.target || TEXTURE_2D;\n gl.bindTexture(target, tex);\n const level = options.level || 0;\n const internalFormat = options.internalFormat || options.format || RGBA;\n const formatType = getFormatAndTypeForInternalFormat(internalFormat);\n const format = options.format || formatType.format;\n const type = options.type || formatType.type;\n savePackState(gl, options);\n if (target === TEXTURE_CUBE_MAP) {\n for (let ii = 0; ii < 6; ++ii) {\n gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, level, internalFormat, options.width, options.height, 0, format, type, null);\n }\n } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {\n gl.texImage3D(target, level, internalFormat, options.width, options.height, options.depth, 0, format, type, null);\n } else {\n gl.texImage2D(target, level, internalFormat, options.width, options.height, 0, format, type, null);\n }\n restorePackState(gl, options);\n}\n\n/**\n * Creates a texture based on the options passed in.\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.\n * @param {module:twgl.TextureReadyCallback} [callback] A callback called when an image has been downloaded and uploaded to the texture.\n * @return {WebGLTexture} the created texture.\n * @memberOf module:twgl/textures\n */\nfunction createTexture(gl, options, callback) {\n callback = callback || noop;\n options = options || defaults.textureOptions;\n const tex = gl.createTexture();\n const target = options.target || TEXTURE_2D;\n let width = options.width || 1;\n let height = options.height || 1;\n const internalFormat = options.internalFormat || RGBA;\n gl.bindTexture(target, tex);\n if (target === TEXTURE_CUBE_MAP) {\n // this should have been the default for cubemaps :(\n gl.texParameteri(target, TEXTURE_WRAP_S, CLAMP_TO_EDGE);\n gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE);\n }\n let src = options.src;\n if (src) {\n if (typeof src === \"function\") {\n src = src(gl, options);\n }\n if (typeof (src) === \"string\") {\n loadTextureFromUrl(gl, tex, options, callback);\n } else if (isArrayBuffer(src) ||\n (Array.isArray(src) && (\n typeof src[0] === 'number' ||\n Array.isArray(src[0]) ||\n isArrayBuffer(src[0]))\n )\n ) {\n const dimensions = setTextureFromArray(gl, tex, src, options);\n width = dimensions.width;\n height = dimensions.height;\n } else if (Array.isArray(src) && (typeof (src[0]) === 'string' || isTexImageSource(src[0]))) {\n if (target === TEXTURE_CUBE_MAP) {\n loadCubemapFromUrls(gl, tex, options, callback);\n } else {\n loadSlicesFromUrls(gl, tex, options, callback);\n }\n } else if (isTexImageSource(src)) {\n setTextureFromElement(gl, tex, src, options);\n width = src.width;\n height = src.height;\n } else {\n throw \"unsupported src type\";\n }\n } else {\n setEmptyTexture(gl, tex, options);\n }\n if (shouldAutomaticallySetTextureFilteringForSize(options)) {\n setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);\n }\n setTextureParameters(gl, tex, options);\n return tex;\n}\n\n/**\n * Resizes a texture based on the options passed in.\n *\n * Note: This is not a generic resize anything function.\n * It's mostly used by {@link module:twgl.resizeFramebufferInfo}\n * It will use `options.src` if it exists to try to determine a `type`\n * otherwise it will assume `gl.UNSIGNED_BYTE`. No data is provided\n * for the texture. Texture parameters will be set accordingly\n *\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {WebGLTexture} tex the texture to resize\n * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.\n * @param {number} [width] the new width. If not passed in will use `options.width`\n * @param {number} [height] the new height. If not passed in will use `options.height`\n * @param {number} [depth] the new depth. If not passed in will use `options.depth`\n * @memberOf module:twgl/textures\n */\nfunction resizeTexture(gl, tex, options, width, height, depth) {\n width = width || options.width;\n height = height || options.height;\n depth = depth || options.depth;\n const target = options.target || TEXTURE_2D;\n gl.bindTexture(target, tex);\n const level = options.level || 0;\n const internalFormat = options.internalFormat || options.format || RGBA;\n const formatType = getFormatAndTypeForInternalFormat(internalFormat);\n const format = options.format || formatType.format;\n let type;\n const src = options.src;\n if (!src) {\n type = options.type || formatType.type;\n } else if (isArrayBuffer(src) || (Array.isArray(src) && typeof (src[0]) === 'number')) {\n type = options.type || getTextureTypeForArrayType(gl, src, formatType.type);\n } else {\n type = options.type || formatType.type;\n }\n if (target === TEXTURE_CUBE_MAP) {\n for (let ii = 0; ii < 6; ++ii) {\n gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, level, internalFormat, width, height, 0, format, type, null);\n }\n } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {\n gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, null);\n } else {\n gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, null);\n }\n}\n\n/**\n * Check if a src is an async request.\n * if src is a string we're going to download an image\n * if src is an array of strings we're going to download cubemap images\n * @param {*} src The src from a TextureOptions\n * @returns {bool} true if src is async.\n * @private\n */\nfunction isAsyncSrc(src) {\n return typeof src === 'string' ||\n (Array.isArray(src) && typeof src[0] === 'string');\n}\n\n/**\n * Creates a bunch of textures based on the passed in options.\n *\n * Example:\n *\n * const textures = twgl.createTextures(gl, {\n * // a power of 2 image\n * hftIcon: { src: \"images/hft-icon-16.png\", mag: gl.NEAREST },\n * // a non-power of 2 image\n * clover: { src: \"images/clover.jpg\" },\n * // From a canvas\n * fromCanvas: { src: ctx.canvas },\n * // A cubemap from 6 images\n * yokohama: {\n * target: gl.TEXTURE_CUBE_MAP,\n * src: [\n * 'images/yokohama/posx.jpg',\n * 'images/yokohama/negx.jpg',\n * 'images/yokohama/posy.jpg',\n * 'images/yokohama/negy.jpg',\n * 'images/yokohama/posz.jpg',\n * 'images/yokohama/negz.jpg',\n * ],\n * },\n * // A cubemap from 1 image (can be 1x6, 2x3, 3x2, 6x1)\n * goldengate: {\n * target: gl.TEXTURE_CUBE_MAP,\n * src: 'images/goldengate.jpg',\n * },\n * // A 2x2 pixel texture from a JavaScript array\n * checker: {\n * mag: gl.NEAREST,\n * min: gl.LINEAR,\n * src: [\n * 255,255,255,255,\n * 192,192,192,255,\n * 192,192,192,255,\n * 255,255,255,255,\n * ],\n * },\n * // a 1x2 pixel texture from a typed array.\n * stripe: {\n * mag: gl.NEAREST,\n * min: gl.LINEAR,\n * format: gl.LUMINANCE,\n * src: new Uint8Array([\n * 255,\n * 128,\n * 255,\n * 128,\n * 255,\n * 128,\n * 255,\n * 128,\n * ]),\n * width: 1,\n * },\n * });\n *\n * Now\n *\n * * `textures.hftIcon` will be a 2d texture\n * * `textures.clover` will be a 2d texture\n * * `textures.fromCanvas` will be a 2d texture\n * * `textures.yohohama` will be a cubemap texture\n * * `textures.goldengate` will be a cubemap texture\n * * `textures.checker` will be a 2d texture\n * * `textures.stripe` will be a 2d texture\n *\n * @param {WebGLRenderingContext} gl the WebGLRenderingContext\n * @param {Object.} options A object of TextureOptions one per texture.\n * @param {module:twgl.TexturesReadyCallback} [callback] A callback called when all textures have been downloaded.\n * @return {Object.} the created textures by name\n * @memberOf module:twgl/textures\n */\nfunction createTextures(gl, textureOptions, callback) {\n callback = callback || noop;\n let numDownloading = 0;\n const errors = [];\n const textures = {};\n const images = {};\n\n function callCallbackIfReady() {\n if (numDownloading === 0) {\n setTimeout(function() {\n callback(errors.length ? errors : undefined, textures, images);\n }, 0);\n }\n }\n\n Object.keys(textureOptions).forEach(function(name) {\n const options = textureOptions[name];\n let onLoadFn;\n if (isAsyncSrc(options.src)) {\n onLoadFn = function(err, tex, img) {\n images[name] = img;\n --numDownloading;\n if (err) {\n errors.push(err);\n }\n callCallbackIfReady();\n };\n ++numDownloading;\n }\n textures[name] = createTexture(gl, options, onLoadFn);\n });\n\n // queue the callback if there are no images to download.\n // We do this because if your code is structured to wait for\n // images to download but then you comment out all the async\n // images your code would break.\n callCallbackIfReady();\n\n return textures;\n}\n\nexport {\n setDefaults as setTextureDefaults_,\n\n createSampler,\n createSamplers,\n setSamplerParameters,\n\n createTexture,\n setEmptyTexture,\n setTextureFromArray,\n loadTextureFromUrl,\n setTextureFromElement,\n setTextureFilteringForSize,\n setTextureParameters,\n setDefaultTextureColor,\n createTextures,\n resizeTexture,\n\n canGenerateMipmap,\n canFilter,\n getNumComponentsForFormat,\n getBytesPerElementForInternalFormat,\n getFormatAndTypeForInternalFormat,\n};\n\n","import * as m4 from './m4.js';\nimport * as v3 from './v3.js';\nimport * as primitives from './primitives.js';\n\nexport * from './twgl.js';\nexport {\n m4,\n v3,\n primitives,\n};\n\n\n\n\n\n","/*\n * Copyright 2019 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n\nimport * as attributes from './attributes.js';\nimport * as textures from './textures.js';\nimport * as helper from './helper.js';\nimport * as utils from './utils.js';\n\nimport * as draw from './draw.js';\nimport * as framebuffers from './framebuffers.js';\nimport * as programs from './programs.js';\nimport * as typedarrays from './typedarrays.js';\nimport * as vertexArrays from './vertex-arrays.js';\n\n/**\n * The main TWGL module.\n *\n * For most use cases you shouldn't need anything outside this module.\n * Exceptions between the stuff added to twgl-full (v3, m4, primitives)\n *\n * @module twgl\n * @borrows module:twgl/attributes.setAttribInfoBufferFromArray as setAttribInfoBufferFromArray\n * @borrows module:twgl/attributes.createBufferInfoFromArrays as createBufferInfoFromArrays\n * @borrows module:twgl/attributes.createVertexArrayInfo as createVertexArrayInfo\n * @borrows module:twgl/draw.drawBufferInfo as drawBufferInfo\n * @borrows module:twgl/draw.drawObjectList as drawObjectList\n * @borrows module:twgl/framebuffers.createFramebufferInfo as createFramebufferInfo\n * @borrows module:twgl/framebuffers.resizeFramebufferInfo as resizeFramebufferInfo\n * @borrows module:twgl/framebuffers.bindFramebufferInfo as bindFramebufferInfo\n * @borrows module:twgl/programs.createProgramInfo as createProgramInfo\n * @borrows module:twgl/programs.createUniformBlockInfo as createUniformBlockInfo\n * @borrows module:twgl/programs.bindUniformBlock as bindUniformBlock\n * @borrows module:twgl/programs.setUniformBlock as setUniformBlock\n * @borrows module:twgl/programs.setBlockUniforms as setBlockUniforms\n * @borrows module:twgl/programs.setUniforms as setUniforms\n * @borrows module:twgl/programs.setBuffersAndAttributes as setBuffersAndAttributes\n * @borrows module:twgl/textures.setTextureFromArray as setTextureFromArray\n * @borrows module:twgl/textures.createTexture as createTexture\n * @borrows module:twgl/textures.resizeTexture as resizeTexture\n * @borrows module:twgl/textures.createTextures as createTextures\n */\n\n// make sure we don't see a global gl\nconst gl = undefined; /* eslint-disable-line */ /* lgtm [js/unused-local-variable] */\nconst defaults = {\n addExtensionsToContext: true,\n};\n\n/**\n * Various default settings for twgl.\n *\n * Note: You can call this any number of times. Example:\n *\n * twgl.setDefaults({ textureColor: [1, 0, 0, 1] });\n * twgl.setDefaults({ attribPrefix: 'a_' });\n *\n * is equivalent to\n *\n * twgl.setDefaults({\n * textureColor: [1, 0, 0, 1],\n * attribPrefix: 'a_',\n * });\n *\n * @typedef {Object} Defaults\n * @property {string} [attribPrefix] The prefix to stick on attributes\n *\n * When writing shaders I prefer to name attributes with `a_`, uniforms with `u_` and varyings with `v_`\n * as it makes it clear where they came from. But, when building geometry I prefer using un-prefixed names.\n *\n * In other words I'll create arrays of geometry like this\n *\n * const arrays = {\n * position: ...\n * normal: ...\n * texcoord: ...\n * };\n *\n * But need those mapped to attributes and my attributes start with `a_`.\n *\n * Default: `\"\"`\n *\n * @property {number[]} [textureColor] Array of 4 values in the range 0 to 1\n *\n * The default texture color is used when loading textures from\n * urls. Because the URL will be loaded async we'd like to be\n * able to use the texture immediately. By putting a 1x1 pixel\n * color in the texture we can start using the texture before\n * the URL has loaded.\n *\n * Default: `[0.5, 0.75, 1, 1]`\n *\n * @property {string} [crossOrigin]\n *\n * If not undefined sets the crossOrigin attribute on images\n * that twgl creates when downloading images for textures.\n *\n * Also see {@link module:twgl.TextureOptions}.\n *\n * @property {bool} [addExtensionsToContext]\n *\n * If true, then, when twgl will try to add any supported WebGL extensions\n * directly to the context under their normal GL names. For example\n * if ANGLE_instances_arrays exists then twgl would enable it,\n * add the functions `vertexAttribDivisor`, `drawArraysInstanced`,\n * `drawElementsInstanced`, and the constant `VERTEX_ATTRIB_ARRAY_DIVISOR`\n * to the `WebGLRenderingContext`.\n *\n * @memberOf module:twgl\n */\n\n/**\n * Sets various defaults for twgl.\n *\n * In the interest of terseness which is kind of the point\n * of twgl I've integrated a few of the older functions here\n *\n * @param {module:twgl.Defaults} newDefaults The default settings.\n * @memberOf module:twgl\n */\nfunction setDefaults(newDefaults) {\n helper.copyExistingProperties(newDefaults, defaults);\n attributes.setAttributeDefaults_(newDefaults); // eslint-disable-line\n textures.setTextureDefaults_(newDefaults); // eslint-disable-line\n}\n\nconst prefixRE = /^(.*?)_/;\nfunction addExtensionToContext(gl, extensionName) {\n utils.glEnumToString(gl, 0);\n const ext = gl.getExtension(extensionName);\n if (ext) {\n const enums = {};\n const fnSuffix = prefixRE.exec(extensionName)[1];\n const enumSuffix = '_' + fnSuffix;\n for (const key in ext) {\n const value = ext[key];\n const isFunc = typeof (value) === 'function';\n const suffix = isFunc ? fnSuffix : enumSuffix;\n let name = key;\n // examples of where this is not true are WEBGL_compressed_texture_s3tc\n // and WEBGL_compressed_texture_pvrtc\n if (key.endsWith(suffix)) {\n name = key.substring(0, key.length - suffix.length);\n }\n if (gl[name] !== undefined) {\n if (!isFunc && gl[name] !== value) {\n helper.warn(name, gl[name], value, key);\n }\n } else {\n if (isFunc) {\n gl[name] = function(origFn) {\n return function() {\n return origFn.apply(ext, arguments);\n };\n }(value);\n } else {\n gl[name] = value;\n enums[name] = value;\n }\n }\n }\n // pass the modified enums to glEnumToString\n enums.constructor = {\n name: ext.constructor.name,\n };\n utils.glEnumToString(enums, 0);\n }\n return ext;\n}\n\n/*\n * If you're wondering why the code doesn't just iterate\n * over all extensions using `gl.getExtensions` is that it's possible\n * some future extension is incompatible with this code. Rather than\n * have thing suddenly break it seems better to manually add to this\n * list.\n *\n */\nconst supportedExtensions = [\n 'ANGLE_instanced_arrays',\n 'EXT_blend_minmax',\n 'EXT_color_buffer_float',\n 'EXT_color_buffer_half_float',\n 'EXT_disjoint_timer_query',\n 'EXT_disjoint_timer_query_webgl2',\n 'EXT_frag_depth',\n 'EXT_sRGB',\n 'EXT_shader_texture_lod',\n 'EXT_texture_filter_anisotropic',\n 'OES_element_index_uint',\n 'OES_standard_derivatives',\n 'OES_texture_float',\n 'OES_texture_float_linear',\n 'OES_texture_half_float',\n 'OES_texture_half_float_linear',\n 'OES_vertex_array_object',\n 'WEBGL_color_buffer_float',\n 'WEBGL_compressed_texture_atc',\n 'WEBGL_compressed_texture_etc1',\n 'WEBGL_compressed_texture_pvrtc',\n 'WEBGL_compressed_texture_s3tc',\n 'WEBGL_compressed_texture_s3tc_srgb',\n 'WEBGL_depth_texture',\n 'WEBGL_draw_buffers',\n];\n\n/**\n * Attempts to enable all of the following extensions\n * and add their functions and constants to the\n * `WebGLRenderingContext` using their normal non-extension like names.\n *\n * ANGLE_instanced_arrays\n * EXT_blend_minmax\n * EXT_color_buffer_float\n * EXT_color_buffer_half_float\n * EXT_disjoint_timer_query\n * EXT_disjoint_timer_query_webgl2\n * EXT_frag_depth\n * EXT_sRGB\n * EXT_shader_texture_lod\n * EXT_texture_filter_anisotropic\n * OES_element_index_uint\n * OES_standard_derivatives\n * OES_texture_float\n * OES_texture_float_linear\n * OES_texture_half_float\n * OES_texture_half_float_linear\n * OES_vertex_array_object\n * WEBGL_color_buffer_float\n * WEBGL_compressed_texture_atc\n * WEBGL_compressed_texture_etc1\n * WEBGL_compressed_texture_pvrtc\n * WEBGL_compressed_texture_s3tc\n * WEBGL_compressed_texture_s3tc_srgb\n * WEBGL_depth_texture\n * WEBGL_draw_buffers\n *\n * For example if `ANGLE_instanced_arrays` exists then the functions\n * `drawArraysInstanced`, `drawElementsInstanced`, `vertexAttribDivisor`\n * and the constant `VERTEX_ATTRIB_ARRAY_DIVISOR` are added to the\n * `WebGLRenderingContext`.\n *\n * Note that if you want to know if the extension exists you should\n * probably call `gl.getExtension` for each extension. Alternatively\n * you can check for the existence of the functions or constants that\n * are expected to be added. For example\n *\n * if (gl.drawBuffers) {\n * // Either WEBGL_draw_buffers was enabled OR you're running in WebGL2\n * ....\n *\n * @param {WebGLRenderingContext} gl A WebGLRenderingContext\n * @memberOf module:twgl\n */\nfunction addExtensionsToContext(gl) {\n for (let ii = 0; ii < supportedExtensions.length; ++ii) {\n addExtensionToContext(gl, supportedExtensions[ii]);\n }\n}\n\n/**\n * Creates a webgl context.\n * @param {HTMLCanvasElement} canvas The canvas tag to get\n * context from. If one is not passed in one will be\n * created.\n * @return {WebGLRenderingContext} The created context.\n * @private\n */\nfunction create3DContext(canvas, opt_attribs) {\n const names = [\"webgl\", \"experimental-webgl\"];\n let context = null;\n for (let ii = 0; ii < names.length; ++ii) {\n context = canvas.getContext(names[ii], opt_attribs);\n if (context) {\n if (defaults.addExtensionsToContext) {\n addExtensionsToContext(context);\n }\n break;\n }\n }\n return context;\n}\n\n/**\n * Gets a WebGL1 context.\n *\n * Note: Will attempt to enable Vertex Array Objects\n * and add WebGL2 entry points. (unless you first set defaults with\n * `twgl.setDefaults({enableVertexArrayObjects: false})`;\n *\n * @param {HTMLCanvasElement} canvas a canvas element.\n * @param {WebGLContextAttributes} [opt_attribs] optional webgl context creation attributes\n * @return {WebGLRenderingContext} The created context.\n * @memberOf module:twgl\n */\nfunction getWebGLContext(canvas, opt_attribs) {\n const gl = create3DContext(canvas, opt_attribs);\n return gl;\n}\n\n/**\n * Creates a webgl context.\n *\n * Will return a WebGL2 context if possible.\n *\n * You can check if it's WebGL2 with\n *\n * twgl.isWebGL2(gl);\n *\n * @param {HTMLCanvasElement} canvas The canvas tag to get\n * context from. If one is not passed in one will be\n * created.\n * @return {WebGLRenderingContext} The created context.\n */\nfunction createContext(canvas, opt_attribs) {\n const names = [\"webgl2\", \"webgl\", \"experimental-webgl\"];\n let context = null;\n for (let ii = 0; ii < names.length; ++ii) {\n context = canvas.getContext(names[ii], opt_attribs);\n if (context) {\n if (defaults.addExtensionsToContext) {\n addExtensionsToContext(context);\n }\n break;\n }\n }\n return context;\n}\n\n/**\n * Gets a WebGL context. Will create a WebGL2 context if possible.\n *\n * You can check if it's WebGL2 with\n *\n * function isWebGL2(gl) {\n * return gl.getParameter(gl.VERSION).indexOf(\"WebGL 2.0 \") == 0;\n * }\n *\n * Note: For a WebGL1 context will attempt to enable Vertex Array Objects\n * and add WebGL2 entry points. (unless you first set defaults with\n * `twgl.setDefaults({enableVertexArrayObjects: false})`;\n *\n * @param {HTMLCanvasElement} canvas a canvas element.\n * @param {WebGLContextAttributes} [opt_attribs] optional webgl context creation attributes\n * @return {WebGLRenderingContext} The created context.\n * @memberOf module:twgl\n */\nfunction getContext(canvas, opt_attribs) {\n const gl = createContext(canvas, opt_attribs);\n return gl;\n}\n\n/**\n * Resize a canvas to match the size it's displayed.\n * @param {HTMLCanvasElement} canvas The canvas to resize.\n * @param {number} [multiplier] So you can pass in `window.devicePixelRatio` or other scale value if you want to.\n * @return {boolean} true if the canvas was resized.\n * @memberOf module:twgl\n */\nfunction resizeCanvasToDisplaySize(canvas, multiplier) {\n multiplier = multiplier || 1;\n multiplier = Math.max(0, multiplier);\n const width = canvas.clientWidth * multiplier | 0;\n const height = canvas.clientHeight * multiplier | 0;\n if (canvas.width !== width || canvas.height !== height) {\n canvas.width = width;\n canvas.height = height;\n return true;\n }\n return false;\n}\n\nexport {\n addExtensionsToContext,\n getContext,\n getWebGLContext,\n resizeCanvasToDisplaySize,\n setDefaults,\n\n attributes,\n draw,\n framebuffers,\n programs,\n textures,\n typedarrays,\n utils,\n vertexArrays,\n};\n\n// function notPrivate(name) {\n// return name[name.length - 1] !== '_';\n// }\n//\n// function copyPublicProperties(src, dst) {\n// Object.keys(src).filter(notPrivate).forEach(function(key) {\n// dst[key] = src[key];\n// });\n// return dst;\n// }\n\nexport * from './attributes.js';\nexport * from './draw.js';\nexport * from './framebuffers.js';\nexport * from './programs.js';\nexport * from './textures.js';\nexport * from './typedarrays.js';\nexport * from './utils.js';\nexport * from './vertex-arrays.js';\n\n\n","/*\n * Copyright 2019 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n\n/**\n * Low level shader typed array related functions\n *\n * You should generally not need to use these functions. They are provided\n * for those cases where you're doing something out of the ordinary\n * and you need lower level access.\n *\n * For backward compatibility they are available at both `twgl.typedArray` and `twgl`\n * itself\n *\n * See {@link module:twgl} for core functions\n *\n * @module twgl/typedArray\n */\n\n// make sure we don't see a global gl\nconst gl = undefined; /* eslint-disable-line */ /* lgtm [js/unused-local-variable] */\n\n/* DataType */\nconst BYTE = 0x1400;\nconst UNSIGNED_BYTE = 0x1401;\nconst SHORT = 0x1402;\nconst UNSIGNED_SHORT = 0x1403;\nconst INT = 0x1404;\nconst UNSIGNED_INT = 0x1405;\nconst FLOAT = 0x1406;\nconst UNSIGNED_SHORT_4_4_4_4 = 0x8033;\nconst UNSIGNED_SHORT_5_5_5_1 = 0x8034;\nconst UNSIGNED_SHORT_5_6_5 = 0x8363;\nconst HALF_FLOAT = 0x140B;\nconst UNSIGNED_INT_2_10_10_10_REV = 0x8368;\nconst UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B;\nconst UNSIGNED_INT_5_9_9_9_REV = 0x8C3E;\nconst FLOAT_32_UNSIGNED_INT_24_8_REV = 0x8DAD;\nconst UNSIGNED_INT_24_8 = 0x84FA;\n\nconst glTypeToTypedArray = {};\n{\n const tt = glTypeToTypedArray;\n tt[BYTE] = Int8Array;\n tt[UNSIGNED_BYTE] = Uint8Array;\n tt[SHORT] = Int16Array;\n tt[UNSIGNED_SHORT] = Uint16Array;\n tt[INT] = Int32Array;\n tt[UNSIGNED_INT] = Uint32Array;\n tt[FLOAT] = Float32Array;\n tt[UNSIGNED_SHORT_4_4_4_4] = Uint16Array;\n tt[UNSIGNED_SHORT_5_5_5_1] = Uint16Array;\n tt[UNSIGNED_SHORT_5_6_5] = Uint16Array;\n tt[HALF_FLOAT] = Uint16Array;\n tt[UNSIGNED_INT_2_10_10_10_REV] = Uint32Array;\n tt[UNSIGNED_INT_10F_11F_11F_REV] = Uint32Array;\n tt[UNSIGNED_INT_5_9_9_9_REV] = Uint32Array;\n tt[FLOAT_32_UNSIGNED_INT_24_8_REV] = Uint32Array;\n tt[UNSIGNED_INT_24_8] = Uint32Array;\n}\n\n/**\n * Get the GL type for a typedArray\n * @param {ArrayBufferView} typedArray a typedArray\n * @return {number} the GL type for array. For example pass in an `Int8Array` and `gl.BYTE` will\n * be returned. Pass in a `Uint32Array` and `gl.UNSIGNED_INT` will be returned\n * @memberOf module:twgl/typedArray\n */\nfunction getGLTypeForTypedArray(typedArray) {\n if (typedArray instanceof Int8Array) { return BYTE; } // eslint-disable-line\n if (typedArray instanceof Uint8Array) { return UNSIGNED_BYTE; } // eslint-disable-line\n if (typedArray instanceof Uint8ClampedArray) { return UNSIGNED_BYTE; } // eslint-disable-line\n if (typedArray instanceof Int16Array) { return SHORT; } // eslint-disable-line\n if (typedArray instanceof Uint16Array) { return UNSIGNED_SHORT; } // eslint-disable-line\n if (typedArray instanceof Int32Array) { return INT; } // eslint-disable-line\n if (typedArray instanceof Uint32Array) { return UNSIGNED_INT; } // eslint-disable-line\n if (typedArray instanceof Float32Array) { return FLOAT; } // eslint-disable-line\n throw new Error('unsupported typed array type');\n}\n\n/**\n * Get the GL type for a typedArray type\n * @param {ArrayBufferView} typedArrayType a typedArray constructor\n * @return {number} the GL type for type. For example pass in `Int8Array` and `gl.BYTE` will\n * be returned. Pass in `Uint32Array` and `gl.UNSIGNED_INT` will be returned\n * @memberOf module:twgl/typedArray\n */\nfunction getGLTypeForTypedArrayType(typedArrayType) {\n if (typedArrayType === Int8Array) { return BYTE; } // eslint-disable-line\n if (typedArrayType === Uint8Array) { return UNSIGNED_BYTE; } // eslint-disable-line\n if (typedArrayType === Uint8ClampedArray) { return UNSIGNED_BYTE; } // eslint-disable-line\n if (typedArrayType === Int16Array) { return SHORT; } // eslint-disable-line\n if (typedArrayType === Uint16Array) { return UNSIGNED_SHORT; } // eslint-disable-line\n if (typedArrayType === Int32Array) { return INT; } // eslint-disable-line\n if (typedArrayType === Uint32Array) { return UNSIGNED_INT; } // eslint-disable-line\n if (typedArrayType === Float32Array) { return FLOAT; } // eslint-disable-line\n throw new Error('unsupported typed array type');\n}\n\n/**\n * Get the typed array constructor for a given GL type\n * @param {number} type the GL type. (eg: `gl.UNSIGNED_INT`)\n * @return {function} the constructor for a the corresponding typed array. (eg. `Uint32Array`).\n * @memberOf module:twgl/typedArray\n */\nfunction getTypedArrayTypeForGLType(type) {\n const CTOR = glTypeToTypedArray[type];\n if (!CTOR) {\n throw new Error('unknown gl type');\n }\n return CTOR;\n}\n\nconst isArrayBuffer = typeof SharedArrayBuffer !== 'undefined'\n ? function isArrayBufferOrSharedArrayBuffer(a) {\n return a && a.buffer && (a.buffer instanceof ArrayBuffer || a.buffer instanceof SharedArrayBuffer);\n }\n : function isArrayBuffer(a) {\n return a && a.buffer && a.buffer instanceof ArrayBuffer;\n };\n\nexport {\n getGLTypeForTypedArray,\n getGLTypeForTypedArrayType,\n getTypedArrayTypeForGLType,\n isArrayBuffer,\n};\n\n","/*\n * Copyright 2019 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n\n/**\n * Gets the gl version as a number\n * @param {WebGLRenderingContext} gl A WebGLRenderingContext\n * @return {number} version of gl\n * @private\n */\n//function getVersionAsNumber(gl) {\n// return parseFloat(gl.getParameter(gl.VERSION).substr(6));\n//}\n\n/**\n * Check if context is WebGL 2.0\n * @param {WebGLRenderingContext} gl A WebGLRenderingContext\n * @return {bool} true if it's WebGL 2.0\n * @memberOf module:twgl\n */\nfunction isWebGL2(gl) {\n // This is the correct check but it's slow\n // return gl.getParameter(gl.VERSION).indexOf(\"WebGL 2.0\") === 0;\n // This might also be the correct check but I'm assuming it's slow-ish\n // return gl instanceof WebGL2RenderingContext;\n return !!gl.texStorage2D;\n}\n\n/**\n * Check if context is WebGL 1.0\n * @param {WebGLRenderingContext} gl A WebGLRenderingContext\n * @return {bool} true if it's WebGL 1.0\n * @memberOf module:twgl\n */\nfunction isWebGL1(gl) {\n // This is the correct check but it's slow\n // const version = getVersionAsNumber(gl);\n // return version <= 1.0 && version > 0.0; // because as of 2016/5 Edge returns 0.96\n // This might also be the correct check but I'm assuming it's slow-ish\n // return gl instanceof WebGLRenderingContext;\n return !gl.texStorage2D;\n}\n\n/**\n * Gets a string for WebGL enum\n *\n * Note: Several enums are the same. Without more\n * context (which function) it's impossible to always\n * give the correct enum. As it is, for matching values\n * it gives all enums. Checking the WebGL2RenderingContext\n * that means\n *\n * 0 = ZERO | POINT | NONE | NO_ERROR\n * 1 = ONE | LINES | SYNC_FLUSH_COMMANDS_BIT\n * 32777 = BLEND_EQUATION_RGB | BLEND_EQUATION_RGB\n * 36662 = COPY_READ_BUFFER | COPY_READ_BUFFER_BINDING\n * 36663 = COPY_WRITE_BUFFER | COPY_WRITE_BUFFER_BINDING\n * 36006 = FRAMEBUFFER_BINDING | DRAW_FRAMEBUFFER_BINDING\n *\n * It's also not useful for bits really unless you pass in individual bits.\n * In other words\n *\n * const bits = gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT;\n * twgl.glEnumToString(gl, bits); // not going to work\n *\n * Note that some enums only exist on extensions. If you\n * want them to show up you need to pass the extension at least\n * once. For example\n *\n * const ext = gl.getExtension('WEBGL_compressed_texture_s3tc');\n * if (ext) {\n * twgl.glEnumToString(ext, 0); // just prime the function\n *\n * ..later..\n *\n * const internalFormat = ext.COMPRESSED_RGB_S3TC_DXT1_EXT;\n * console.log(twgl.glEnumToString(gl, internalFormat));\n *\n * Notice I didn't have to pass the extension the second time. This means\n * you can have place that generically gets an enum for texture formats for example.\n * and as long as you primed the function with the extensions\n *\n * If you're using `twgl.addExtensionsToContext` to enable your extensions\n * then twgl will automatically get the extension's enums.\n *\n * @param {WebGLRenderingContext} gl A WebGLRenderingContext or any extension object\n * @param {number} value the value of the enum you want to look up.\n * @return {string} enum string or hex value\n * @memberOf module:twgl\n * @function glEnumToString\n */\nconst glEnumToString = (function() {\n const haveEnumsForType = {};\n const enums = {};\n\n function addEnums(gl) {\n const type = gl.constructor.name;\n if (!haveEnumsForType[type]) {\n for (const key in gl) {\n if (typeof gl[key] === 'number') {\n const existing = enums[gl[key]];\n enums[gl[key]] = existing ? `${existing} | ${key}` : key;\n }\n }\n haveEnumsForType[type] = true;\n }\n }\n\n return function glEnumToString(gl, value) {\n addEnums(gl);\n return enums[value] || (\"0x\" + value.toString(16));\n };\n}());\n\nexport {\n glEnumToString,\n isWebGL1,\n isWebGL2,\n};\n\n\n","/*\n * Copyright 2019 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n\n/**\n *\n * Vec3 math math functions.\n *\n * Almost all functions take an optional `dst` argument. If it is not passed in the\n * functions will create a new Vec3. In other words you can do this\n *\n * var v = v3.cross(v1, v2); // Creates a new Vec3 with the cross product of v1 x v2.\n *\n * or\n *\n * var v = v3.create();\n * v3.cross(v1, v2, v); // Puts the cross product of v1 x v2 in v\n *\n * The first style is often easier but depending on where it's used it generates garbage where\n * as there is almost never allocation with the second style.\n *\n * It is always save to pass any vector as the destination. So for example\n *\n * v3.cross(v1, v2, v1); // Puts the cross product of v1 x v2 in v1\n *\n * @module twgl/v3\n */\n\nlet VecType = Float32Array;\n\n/**\n * A JavaScript array with 3 values or a Float32Array with 3 values.\n * When created by the library will create the default type which is `Float32Array`\n * but can be set by calling {@link module:twgl/v3.setDefaultType}.\n * @typedef {(number[]|Float32Array)} Vec3\n * @memberOf module:twgl/v3\n */\n\n/**\n * Sets the type this library creates for a Vec3\n * @param {constructor} ctor the constructor for the type. Either `Float32Array` or `Array`\n * @return {constructor} previous constructor for Vec3\n * @memberOf module:twgl/v3\n */\nfunction setDefaultType(ctor) {\n const oldType = VecType;\n VecType = ctor;\n return oldType;\n}\n\n/**\n * Creates a vec3; may be called with x, y, z to set initial values.\n * @param {number} [x] Initial x value.\n * @param {number} [y] Initial y value.\n * @param {number} [z] Initial z value.\n * @return {module:twgl/v3.Vec3} the created vector\n * @memberOf module:twgl/v3\n */\nfunction create(x, y, z) {\n const dst = new VecType(3);\n if (x) {\n dst[0] = x;\n }\n if (y) {\n dst[1] = y;\n }\n if (z) {\n dst[2] = z;\n }\n return dst;\n}\n\n/**\n * Adds two vectors; assumes a and b have the same dimension.\n * @param {module:twgl/v3.Vec3} a Operand vector.\n * @param {module:twgl/v3.Vec3} b Operand vector.\n * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.\n * @return {module:twgl/v3.Vec3} A vector tha tis the sum of a and b.\n * @memberOf module:twgl/v3\n */\nfunction add(a, b, dst) {\n dst = dst || new VecType(3);\n\n dst[0] = a[0] + b[0];\n dst[1] = a[1] + b[1];\n dst[2] = a[2] + b[2];\n\n return dst;\n}\n\n/**\n * Subtracts two vectors.\n * @param {module:twgl/v3.Vec3} a Operand vector.\n * @param {module:twgl/v3.Vec3} b Operand vector.\n * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.\n * @return {module:twgl/v3.Vec3} A vector that is the difference of a and b.\n * @memberOf module:twgl/v3\n */\nfunction subtract(a, b, dst) {\n dst = dst || new VecType(3);\n\n dst[0] = a[0] - b[0];\n dst[1] = a[1] - b[1];\n dst[2] = a[2] - b[2];\n\n return dst;\n}\n\n/**\n * Performs linear interpolation on two vectors.\n * Given vectors a and b and interpolation coefficient t, returns\n * a + t * (b - a).\n * @param {module:twgl/v3.Vec3} a Operand vector.\n * @param {module:twgl/v3.Vec3} b Operand vector.\n * @param {number} t Interpolation coefficient.\n * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.\n * @return {module:twgl/v3.Vec3} The linear interpolated result.\n * @memberOf module:twgl/v3\n */\nfunction lerp(a, b, t, dst) {\n dst = dst || new VecType(3);\n\n dst[0] = a[0] + t * (b[0] - a[0]);\n dst[1] = a[1] + t * (b[1] - a[1]);\n dst[2] = a[2] + t * (b[2] - a[2]);\n\n return dst;\n}\n\n/**\n * Performs linear interpolation on two vectors.\n * Given vectors a and b and interpolation coefficient vector t, returns\n * a + t * (b - a).\n * @param {module:twgl/v3.Vec3} a Operand vector.\n * @param {module:twgl/v3.Vec3} b Operand vector.\n * @param {module:twgl/v3.Vec3} t Interpolation coefficients vector.\n * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.\n * @return {module:twgl/v3.Vec3} the linear interpolated result.\n * @memberOf module:twgl/v3\n */\nfunction lerpV(a, b, t, dst) {\n dst = dst || new VecType(3);\n\n dst[0] = a[0] + t[0] * (b[0] - a[0]);\n dst[1] = a[1] + t[1] * (b[1] - a[1]);\n dst[2] = a[2] + t[2] * (b[2] - a[2]);\n\n return dst;\n}\n\n/**\n * Return max values of two vectors.\n * Given vectors a and b returns\n * [max(a[0], b[0]), max(a[1], b[1]), max(a[2], b[2])].\n * @param {module:twgl/v3.Vec3} a Operand vector.\n * @param {module:twgl/v3.Vec3} b Operand vector.\n * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.\n * @return {module:twgl/v3.Vec3} The max components vector.\n * @memberOf module:twgl/v3\n */\nfunction max(a, b, dst) {\n dst = dst || new VecType(3);\n\n dst[0] = Math.max(a[0], b[0]);\n dst[1] = Math.max(a[1], b[1]);\n dst[2] = Math.max(a[2], b[2]);\n\n return dst;\n}\n\n/**\n * Return min values of two vectors.\n * Given vectors a and b returns\n * [min(a[0], b[0]), min(a[1], b[1]), min(a[2], b[2])].\n * @param {module:twgl/v3.Vec3} a Operand vector.\n * @param {module:twgl/v3.Vec3} b Operand vector.\n * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.\n * @return {module:twgl/v3.Vec3} The min components vector.\n * @memberOf module:twgl/v3\n */\nfunction min(a, b, dst) {\n dst = dst || new VecType(3);\n\n dst[0] = Math.min(a[0], b[0]);\n dst[1] = Math.min(a[1], b[1]);\n dst[2] = Math.min(a[2], b[2]);\n\n return dst;\n}\n\n/**\n * Multiplies a vector by a scalar.\n * @param {module:twgl/v3.Vec3} v The vector.\n * @param {number} k The scalar.\n * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.\n * @return {module:twgl/v3.Vec3} The scaled vector.\n * @memberOf module:twgl/v3\n */\nfunction mulScalar(v, k, dst) {\n dst = dst || new VecType(3);\n\n dst[0] = v[0] * k;\n dst[1] = v[1] * k;\n dst[2] = v[2] * k;\n\n return dst;\n}\n\n/**\n * Divides a vector by a scalar.\n * @param {module:twgl/v3.Vec3} v The vector.\n * @param {number} k The scalar.\n * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.\n * @return {module:twgl/v3.Vec3} The scaled vector.\n * @memberOf module:twgl/v3\n */\nfunction divScalar(v, k, dst) {\n dst = dst || new VecType(3);\n\n dst[0] = v[0] / k;\n dst[1] = v[1] / k;\n dst[2] = v[2] / k;\n\n return dst;\n}\n\n/**\n * Computes the cross product of two vectors; assumes both vectors have\n * three entries.\n * @param {module:twgl/v3.Vec3} a Operand vector.\n * @param {module:twgl/v3.Vec3} b Operand vector.\n * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.\n * @return {module:twgl/v3.Vec3} The vector of a cross b.\n * @memberOf module:twgl/v3\n */\nfunction cross(a, b, dst) {\n dst = dst || new VecType(3);\n\n const t1 = a[2] * b[0] - a[0] * b[2];\n const t2 = a[0] * b[1] - a[1] * b[0];\n dst[0] = a[1] * b[2] - a[2] * b[1];\n dst[1] = t1;\n dst[2] = t2;\n\n return dst;\n}\n\n/**\n * Computes the dot product of two vectors; assumes both vectors have\n * three entries.\n * @param {module:twgl/v3.Vec3} a Operand vector.\n * @param {module:twgl/v3.Vec3} b Operand vector.\n * @return {number} dot product\n * @memberOf module:twgl/v3\n */\nfunction dot(a, b) {\n return (a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]);\n}\n\n/**\n * Computes the length of vector\n * @param {module:twgl/v3.Vec3} v vector.\n * @return {number} length of vector.\n * @memberOf module:twgl/v3\n */\nfunction length(v) {\n return Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);\n}\n\n/**\n * Computes the square of the length of vector\n * @param {module:twgl/v3.Vec3} v vector.\n * @return {number} square of the length of vector.\n * @memberOf module:twgl/v3\n */\nfunction lengthSq(v) {\n return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];\n}\n\n/**\n * Computes the distance between 2 points\n * @param {module:twgl/v3.Vec3} a vector.\n * @param {module:twgl/v3.Vec3} b vector.\n * @return {number} distance between a and b\n * @memberOf module:twgl/v3\n */\nfunction distance(a, b) {\n const dx = a[0] - b[0];\n const dy = a[1] - b[1];\n const dz = a[2] - b[2];\n return Math.sqrt(dx * dx + dy * dy + dz * dz);\n}\n\n/**\n * Computes the square of the distance between 2 points\n * @param {module:twgl/v3.Vec3} a vector.\n * @param {module:twgl/v3.Vec3} b vector.\n * @return {number} square of the distance between a and b\n * @memberOf module:twgl/v3\n */\nfunction distanceSq(a, b) {\n const dx = a[0] - b[0];\n const dy = a[1] - b[1];\n const dz = a[2] - b[2];\n return dx * dx + dy * dy + dz * dz;\n}\n\n/**\n * Divides a vector by its Euclidean length and returns the quotient.\n * @param {module:twgl/v3.Vec3} a The vector.\n * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.\n * @return {module:twgl/v3.Vec3} The normalized vector.\n * @memberOf module:twgl/v3\n */\nfunction normalize(a, dst) {\n dst = dst || new VecType(3);\n\n const lenSq = a[0] * a[0] + a[1] * a[1] + a[2] * a[2];\n const len = Math.sqrt(lenSq);\n if (len > 0.00001) {\n dst[0] = a[0] / len;\n dst[1] = a[1] / len;\n dst[2] = a[2] / len;\n } else {\n dst[0] = 0;\n dst[1] = 0;\n dst[2] = 0;\n }\n\n return dst;\n}\n\n/**\n * Negates a vector.\n * @param {module:twgl/v3.Vec3} v The vector.\n * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.\n * @return {module:twgl/v3.Vec3} -v.\n * @memberOf module:twgl/v3\n */\nfunction negate(v, dst) {\n dst = dst || new VecType(3);\n\n dst[0] = -v[0];\n dst[1] = -v[1];\n dst[2] = -v[2];\n\n return dst;\n}\n\n/**\n * Copies a vector.\n * @param {module:twgl/v3.Vec3} v The vector.\n * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.\n * @return {module:twgl/v3.Vec3} A copy of v.\n * @memberOf module:twgl/v3\n */\nfunction copy(v, dst) {\n dst = dst || new VecType(3);\n\n dst[0] = v[0];\n dst[1] = v[1];\n dst[2] = v[2];\n\n return dst;\n}\n\n/**\n * Multiplies a vector by another vector (component-wise); assumes a and\n * b have the same length.\n * @param {module:twgl/v3.Vec3} a Operand vector.\n * @param {module:twgl/v3.Vec3} b Operand vector.\n * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.\n * @return {module:twgl/v3.Vec3} The vector of products of entries of a and\n * b.\n * @memberOf module:twgl/v3\n */\nfunction multiply(a, b, dst) {\n dst = dst || new VecType(3);\n\n dst[0] = a[0] * b[0];\n dst[1] = a[1] * b[1];\n dst[2] = a[2] * b[2];\n\n return dst;\n}\n\n/**\n * Divides a vector by another vector (component-wise); assumes a and\n * b have the same length.\n * @param {module:twgl/v3.Vec3} a Operand vector.\n * @param {module:twgl/v3.Vec3} b Operand vector.\n * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.\n * @return {module:twgl/v3.Vec3} The vector of quotients of entries of a and\n * b.\n * @memberOf module:twgl/v3\n */\nfunction divide(a, b, dst) {\n dst = dst || new VecType(3);\n\n dst[0] = a[0] / b[0];\n dst[1] = a[1] / b[1];\n dst[2] = a[2] / b[2];\n\n return dst;\n}\n\nexport {\n add,\n copy,\n create,\n cross,\n distance,\n distanceSq,\n divide,\n divScalar,\n dot,\n lerp,\n lerpV,\n length,\n lengthSq,\n max,\n min,\n mulScalar,\n multiply,\n negate,\n normalize,\n setDefaultType,\n subtract,\n};\n\n","/*\n * Copyright 2019 Gregg Tavares\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the \"Software\"),\n * to deal in the Software without restriction, including without limitation\n * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n * and/or sell copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\n\nimport * as programs from './programs.js';\n\n/**\n * vertex array object related functions\n *\n * You should generally not need to use these functions. They are provided\n * for those cases where you're doing something out of the ordinary\n * and you need lower level access.\n *\n * For backward compatibility they are available at both `twgl.attributes` and `twgl`\n * itself\n *\n * See {@link module:twgl} for core functions\n *\n * @module twgl/vertexArrays\n */\n\nconst ELEMENT_ARRAY_BUFFER = 0x8893;\n\n/**\n * @typedef {Object} VertexArrayInfo\n * @property {number} numElements The number of elements to pass to `gl.drawArrays` or `gl.drawElements`.\n * @property {number} [elementType] The type of indices `UNSIGNED_BYTE`, `UNSIGNED_SHORT` etc..\n * @property {WebGLVertexArrayObject} [vertexArrayObject] a vertex array object\n * @memberOf module:twgl\n */\n\n/**\n * Creates a VertexArrayInfo from a BufferInfo and one or more ProgramInfos\n *\n * This can be passed to {@link module:twgl.setBuffersAndAttributes} and to\n * {@link module:twgl:drawBufferInfo}.\n *\n * > **IMPORTANT:** Vertex Array Objects are **not** a direct analog for a BufferInfo. Vertex Array Objects\n * assign buffers to specific attributes at creation time. That means they can only be used with programs\n * who's attributes use the same attribute locations for the same purposes.\n *\n * > Bind your attribute locations by passing an array of attribute names to {@link module:twgl.createProgramInfo}\n * or use WebGL 2's GLSL ES 3's `layout(location = )` to make sure locations match.\n *\n * also\n *\n * > **IMPORTANT:** After calling twgl.setBuffersAndAttribute with a BufferInfo that uses a Vertex Array Object\n * that Vertex Array Object will be bound. That means **ANY MANIPULATION OF ELEMENT_ARRAY_BUFFER or ATTRIBUTES**\n * will affect the Vertex Array Object state.\n *\n * > Call `gl.bindVertexArray(null)` to get back manipulating the global attributes and ELEMENT_ARRAY_BUFFER.\n *\n * @param {WebGLRenderingContext} gl A WebGLRenderingContext\n * @param {module:twgl.ProgramInfo|module:twgl.ProgramInfo[]} programInfo a programInfo or array of programInfos\n * @param {module:twgl.BufferInfo} bufferInfo BufferInfo as returned from createBufferInfoFromArrays etc...\n *\n * You need to make sure every attribute that will be used is bound. So for example assume shader 1\n * uses attributes A, B, C and shader 2 uses attributes A, B, D. If you only pass in the programInfo\n * for shader 1 then only attributes A, B, and C will have their attributes set because TWGL doesn't\n * now attribute D's location.\n *\n * So, you can pass in both shader 1 and shader 2's programInfo\n *\n * @return {module:twgl.VertexArrayInfo} The created VertexArrayInfo\n *\n * @memberOf module:twgl/vertexArrays\n */\nfunction createVertexArrayInfo(gl, programInfos, bufferInfo) {\n const vao = gl.createVertexArray();\n gl.bindVertexArray(vao);\n if (!programInfos.length) {\n programInfos = [programInfos];\n }\n programInfos.forEach(function(programInfo) {\n programs.setBuffersAndAttributes(gl, programInfo, bufferInfo);\n });\n gl.bindVertexArray(null);\n return {\n numElements: bufferInfo.numElements,\n elementType: bufferInfo.elementType,\n vertexArrayObject: vao,\n };\n}\n\n/**\n * Creates a vertex array object and then sets the attributes on it\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.\n * @param {Object.} setters Attribute setters as returned from createAttributeSetters\n * @param {Object.} attribs AttribInfos mapped by attribute name.\n * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices\n * @memberOf module:twgl/vertexArrays\n */\nfunction createVAOAndSetAttributes(gl, setters, attribs, indices) {\n const vao = gl.createVertexArray();\n gl.bindVertexArray(vao);\n programs.setAttributes(setters, attribs);\n if (indices) {\n gl.bindBuffer(ELEMENT_ARRAY_BUFFER, indices);\n }\n // We unbind this because otherwise any change to ELEMENT_ARRAY_BUFFER\n // like when creating buffers for other stuff will mess up this VAO's binding\n gl.bindVertexArray(null);\n return vao;\n}\n\n/**\n * Creates a vertex array object and then sets the attributes\n * on it\n *\n * @param {WebGLRenderingContext} gl The WebGLRenderingContext\n * to use.\n * @param {Object.| module:twgl.ProgramInfo} programInfo as returned from createProgramInfo or Attribute setters as returned from createAttributeSetters\n * @param {module:twgl.BufferInfo} bufferInfo BufferInfo as returned from createBufferInfoFromArrays etc...\n * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices\n * @memberOf module:twgl/vertexArrays\n */\nfunction createVAOFromBufferInfo(gl, programInfo, bufferInfo) {\n return createVAOAndSetAttributes(gl, programInfo.attribSetters || programInfo, bufferInfo.attribs, bufferInfo.indices);\n}\n\nexport {\n createVertexArrayInfo,\n createVAOAndSetAttributes,\n createVAOFromBufferInfo,\n};\n\n"],"sourceRoot":""}
\ No newline at end of file
diff --git a/blocks/waves/twgl/twgl-full.min.js b/blocks/waves/twgl/twgl-full.min.js
new file mode 100755
index 00000000..1d87ae4b
--- /dev/null
+++ b/blocks/waves/twgl/twgl-full.min.js
@@ -0,0 +1,6 @@
+/*!
+ * @license twgl.js 4.14.2 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
+ * Available via the MIT license.
+ * see: http://github.com/greggman/twgl.js for details
+ */
+!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.twgl=r():e.twgl=r()}("undefined"!=typeof self?self:this,(function(){return function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=8)}([function(e,r,t){"use strict";r.__esModule=!0,r.copyExistingProperties=function(e,r){Object.keys(r).forEach((function(t){r.hasOwnProperty(t)&&e.hasOwnProperty(t)&&(r[t]=e[t])}))},r.copyNamedProperties=function(e,r,t){e.forEach((function(e){var n=r[e];void 0!==n&&(t[e]=n)}))},r.error=function(){var e;(e=console).error.apply(e,arguments)},r.warn=function(){var e;(e=console).warn.apply(e,arguments)},r.isBuffer=function(e,r){return"undefined"!=typeof WebGLBuffer&&r instanceof WebGLBuffer},r.isRenderbuffer=function(e,r){return"undefined"!=typeof WebGLRenderbuffer&&r instanceof WebGLRenderbuffer},r.isShader=function(e,r){return"undefined"!=typeof WebGLShader&&r instanceof WebGLShader},r.isTexture=function(e,r){return"undefined"!=typeof WebGLTexture&&r instanceof WebGLTexture},r.isSampler=function(e,r){return"undefined"!=typeof WebGLSampler&&r instanceof WebGLSampler}},function(e,r,t){"use strict";r.__esModule=!0,r.getGLTypeForTypedArray=function(e){if(e instanceof Int8Array)return 5120;if(e instanceof Uint8Array)return 5121;if(e instanceof Uint8ClampedArray)return 5121;if(e instanceof Int16Array)return 5122;if(e instanceof Uint16Array)return 5123;if(e instanceof Int32Array)return 5124;if(e instanceof Uint32Array)return 5125;if(e instanceof Float32Array)return 5126;throw new Error("unsupported typed array type")},r.getGLTypeForTypedArrayType=function(e){if(e===Int8Array)return 5120;if(e===Uint8Array)return 5121;if(e===Uint8ClampedArray)return 5121;if(e===Int16Array)return 5122;if(e===Uint16Array)return 5123;if(e===Int32Array)return 5124;if(e===Uint32Array)return 5125;if(e===Float32Array)return 5126;throw new Error("unsupported typed array type")},r.getTypedArrayTypeForGLType=function(e){var r=n[e];if(!r)throw new Error("unknown gl type");return r},r.isArrayBuffer=void 0;var n={},o=n;o[5120]=Int8Array,o[5121]=Uint8Array,o[5122]=Int16Array,o[5123]=Uint16Array,o[5124]=Int32Array,o[5125]=Uint32Array,o[5126]=Float32Array,o[32819]=Uint16Array,o[32820]=Uint16Array,o[33635]=Uint16Array,o[5131]=Uint16Array,o[33640]=Uint32Array,o[35899]=Uint32Array,o[35902]=Uint32Array,o[36269]=Uint32Array,o[34042]=Uint32Array;var u="undefined"!=typeof SharedArrayBuffer?function(e){return e&&e.buffer&&(e.buffer instanceof ArrayBuffer||e.buffer instanceof SharedArrayBuffer)}:function(e){return e&&e.buffer&&e.buffer instanceof ArrayBuffer};r.isArrayBuffer=u},function(e,r,t){"use strict";r.__esModule=!0,r.add=function(e,r,t){return(t=t||new n(3))[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t},r.copy=function(e,r){return(r=r||new n(3))[0]=e[0],r[1]=e[1],r[2]=e[2],r},r.create=function(e,r,t){var o=new n(3);e&&(o[0]=e);r&&(o[1]=r);t&&(o[2]=t);return o},r.cross=function(e,r,t){t=t||new n(3);var o=e[2]*r[0]-e[0]*r[2],u=e[0]*r[1]-e[1]*r[0];return t[0]=e[1]*r[2]-e[2]*r[1],t[1]=o,t[2]=u,t},r.distance=function(e,r){var t=e[0]-r[0],n=e[1]-r[1],o=e[2]-r[2];return Math.sqrt(t*t+n*n+o*o)},r.distanceSq=function(e,r){var t=e[0]-r[0],n=e[1]-r[1],o=e[2]-r[2];return t*t+n*n+o*o},r.divide=function(e,r,t){return(t=t||new n(3))[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t},r.divScalar=function(e,r,t){return(t=t||new n(3))[0]=e[0]/r,t[1]=e[1]/r,t[2]=e[2]/r,t},r.dot=function(e,r){return e[0]*r[0]+e[1]*r[1]+e[2]*r[2]},r.lerp=function(e,r,t,o){return(o=o||new n(3))[0]=e[0]+t*(r[0]-e[0]),o[1]=e[1]+t*(r[1]-e[1]),o[2]=e[2]+t*(r[2]-e[2]),o},r.lerpV=function(e,r,t,o){return(o=o||new n(3))[0]=e[0]+t[0]*(r[0]-e[0]),o[1]=e[1]+t[1]*(r[1]-e[1]),o[2]=e[2]+t[2]*(r[2]-e[2]),o},r.length=function(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])},r.lengthSq=function(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]},r.max=function(e,r,t){return(t=t||new n(3))[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t},r.min=function(e,r,t){return(t=t||new n(3))[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t},r.mulScalar=function(e,r,t){return(t=t||new n(3))[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t},r.multiply=function(e,r,t){return(t=t||new n(3))[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t},r.negate=function(e,r){return(r=r||new n(3))[0]=-e[0],r[1]=-e[1],r[2]=-e[2],r},r.normalize=function(e,r){r=r||new n(3);var t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],o=Math.sqrt(t);o>1e-5?(r[0]=e[0]/o,r[1]=e[1]/o,r[2]=e[2]/o):(r[0]=0,r[1]=0,r[2]=0);return r},r.setDefaultType=function(e){var r=n;return n=e,r},r.subtract=function(e,r,t){return(t=t||new n(3))[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t};var n=Float32Array},function(e,r,t){"use strict";r.__esModule=!0,r.isWebGL1=function(e){return!e.texStorage2D},r.isWebGL2=function(e){return!!e.texStorage2D},r.glEnumToString=void 0;var n,o,u=(n={},o={},function(e,r){return function(e){var r=e.constructor.name;if(!n[r]){for(var t in e)if("number"==typeof e[t]){var u=o[e[t]];o[e[t]]=u?"".concat(u," | ").concat(t):t}n[r]=!0}}(e),o[r]||"0x"+r.toString(16)});r.glEnumToString=u},function(e,r,t){"use strict";r.__esModule=!0,r.createAttributeSetters=D,r.createProgram=T,r.createProgramFromScripts=function(e,r,t,n,o){for(var u=j(t,n,o),i=[],a=0;a=0?35632:r.indexOf("vert")>=0?35633:void 0}function R(e,r){r.forEach((function(r){e.deleteShader(r)}))}function T(e,r,t,n,u){for(var i=j(t,n,u),a=[],f=[],l=0;l1&&"[0]"===n.name.substr(-3),a=n.type,f=l[a];if(!f)throw new Error("unknown type: 0x".concat(a.toString(16)));if(f.bindPoint){var c=t;t+=n.size,o=i?f.arraySetter(e,a,c,u,n.size):f.setter(e,a,c,u,n.size)}else o=f.arraySetter&&i?f.arraySetter(e,u):f.setter(e,u);return o.location=u,o}for(var o={},u=e.getProgramParameter(r,35718),i=0;i0)throw new Error("numComponents ".concat(u," not correct for length ").concat(o));return i}(r);return t},r.createBufferFromArray=w,r.createBufferFromTypedArray=c,r.createBufferInfoFromArrays=function(e,r,t){var o=p(e,r),u=Object.assign({},t||{});u.attribs=Object.assign({},t?t.attribs:{},o);var i=r.indices;if(i){var f=m(i,"indices");u.indices=c(e,f,34963),u.numElements=f.length,u.elementType=n.getGLTypeForTypedArray(f)}else u.numElements||(u.numElements=function(e,r){var t,n;for(n=0;n0)throw new Error("Can not guess numComponents for attribute '".concat(e,"'. Tried ").concat(t," but ").concat(r," values is not evenly divisible by ").concat(t,". You should specify it."));return t}function d(e,r){return e.numComponents||e.size||y(r,s(e).length)}function m(e,r){if(n.isArrayBuffer(e))return e;if(n.isArrayBuffer(e.data))return e.data;Array.isArray(e)&&(e={data:e});var t=e.type;return t||(t=l(r)?Uint16Array:Float32Array),new t(e.data)}function p(e,r){var t={};return Object.keys(r).forEach((function(o){if(!l(o)){var u=r[o],i=u.attrib||u.name||u.attribName||a.attribPrefix+o;if(u.value){if(!Array.isArray(u.value)&&!n.isArrayBuffer(u.value))throw new Error("array.value is not array or typedarray");t[i]={value:u.value}}else{var f,s,v,b;if(u.buffer&&u.buffer instanceof WebGLBuffer)f=u.buffer,b=u.numComponents||u.size,s=u.type,v=u.normalize;else if("number"==typeof u||"number"==typeof u.data){var p=u.data||u,x=u.type||Float32Array,w=p*x.BYTES_PER_ELEMENT;s=n.getGLTypeForTypedArrayType(x),v=void 0!==u.normalize?u.normalize:(F=x)===Int8Array||F===Uint8Array,b=u.numComponents||u.size||y(o,p),f=e.createBuffer(),e.bindBuffer(34962,f),e.bufferData(34962,w,u.drawType||35044)}else{var h=m(u,o);f=c(e,h,void 0,u.drawType),s=n.getGLTypeForTypedArray(h),v=void 0!==u.normalize?u.normalize:function(e){return e instanceof Int8Array||e instanceof Uint8Array}(h),b=d(u,o)}t[i]={buffer:f,numComponents:b,type:s,normalize:v,stride:u.stride||0,offset:u.offset||0,divisor:void 0===u.divisor?void 0:u.divisor,drawType:u.drawType}}}var F})),e.bindBuffer(34962,null),t}var x=["position","positions","a_position"];function w(e,r,t){var n="indices"===t?34963:34962;return c(e,m(r,t),n)}},function(e,r,t){"use strict";r.__esModule=!0,r.setTextureDefaults_=function(e){u.copyExistingProperties(e,c),e.textureColor&&_(e.textureColor)},r.createSampler=C,r.createSamplers=function(e,r){var t={};return Object.keys(r).forEach((function(n){t[n]=C(e,r[n])})),t},r.setSamplerParameters=U,r.createTexture=Z,r.setEmptyTexture=K,r.setTextureFromArray=Y,r.loadTextureFromUrl=H,r.setTextureFromElement=B,r.setTextureFilteringForSize=S,r.setTextureParameters=z,r.setDefaultTextureColor=_,r.createTextures=function(e,r,t){t=t||L;var n=0,o=[],u={},i={};function a(){0===n&&setTimeout((function(){t(o.length?o:void 0,u,i)}),0)}return Object.keys(r).forEach((function(t){var f,c,l=r[t];("string"==typeof(c=l.src)||Array.isArray(c)&&"string"==typeof c[0])&&(f=function(e,r,u){i[t]=u,--n,e&&o.push(e),a()},++n),u[t]=Z(e,l,f)})),a(),u},r.resizeTexture=function(e,r,t,n,o,u){n=n||t.width,o=o||t.height,u=u||t.depth;var i=t.target||3553;e.bindTexture(i,r);var a,f=t.level||0,c=t.internalFormat||t.format||6408,s=w(c),v=t.format||s.format,b=t.src;a=b&&(l(b)||Array.isArray(b)&&"number"==typeof b[0])?t.type||A(e,b,s.type):t.type||s.type;if(34067===i)for(var y=0;y<6;++y)e.texImage2D(34069+y,f,c,n,o,0,v,a,null);else 32879===i||35866===i?e.texImage3D(i,f,c,n,o,u,0,v,a,null):e.texImage2D(i,f,c,n,o,0,v,a,null)},r.canGenerateMipmap=F,r.canFilter=E,r.getNumComponentsForFormat=function(e){var r=d[e];if(!r)throw"unknown format: "+e;return r.u},r.getBytesPerElementForInternalFormat=x,r.getFormatAndTypeForInternalFormat=w;var n=a(t(3)),o=a(t(1)),u=a(t(0));function i(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return i=function(){return e},e}function a(e){if(e&&e.__esModule)return e;var r=i();if(r&&r.has(e))return r.get(e);var t={};if(null!=e){var n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var u=n?Object.getOwnPropertyDescriptor(e,o):null;u&&(u.get||u.set)?Object.defineProperty(t,o,u):t[o]=e[o]}}return t.default=e,r&&r.set(e,t),t}var f,c={textureColor:new Uint8Array([128,192,255,255]),textureOptions:{},crossOrigin:void 0},l=o.isArrayBuffer;function s(){return f=f||("undefined"!=typeof document&&document.createElement?document.createElement("canvas").getContext("2d"):null)}var v,b=6407,y=33319,d={},m=d;function p(e){if(!v){var r={6406:{v:6406,h:!0,F:!0,A:[1,2,2,4],type:[5121,5131,36193,5126]},6409:{v:6409,h:!0,F:!0,A:[1,2,2,4],type:[5121,5131,36193,5126]},6410:{v:6410,h:!0,F:!0,A:[2,4,4,8],type:[5121,5131,36193,5126]}};r[b]={v:b,h:!0,F:!0,A:[3,6,6,12,2],type:[5121,5131,36193,5126,33635]},r[6408]={v:6408,h:!0,F:!0,A:[4,8,8,16,2,2],type:[5121,5131,36193,5126,32819,32820]},r[33321]={v:6403,h:!0,F:!0,A:[1],type:[5121]},r[36756]={v:6403,h:!1,F:!0,A:[1],type:[5120]},r[33325]={v:6403,h:!1,F:!0,A:[4,2],type:[5126,5131]},r[33326]={v:6403,h:!1,F:!1,A:[4],type:[5126]},r[33330]={v:36244,h:!0,F:!1,A:[1],type:[5121]},r[33329]={v:36244,h:!0,F:!1,A:[1],type:[5120]},r[33332]={v:36244,h:!0,F:!1,A:[2],type:[5123]},r[33331]={v:36244,h:!0,F:!1,A:[2],type:[5122]},r[33334]={v:36244,h:!0,F:!1,A:[4],type:[5125]},r[33333]={v:36244,h:!0,F:!1,A:[4],type:[5124]},r[33323]={v:y,h:!0,F:!0,A:[2],type:[5121]},r[36757]={v:y,h:!1,F:!0,A:[2],type:[5120]},r[33327]={v:y,h:!1,F:!0,A:[8,4],type:[5126,5131]},r[33328]={v:y,h:!1,F:!1,A:[8],type:[5126]},r[33336]={v:33320,h:!0,F:!1,A:[2],type:[5121]},r[33335]={v:33320,h:!0,F:!1,A:[2],type:[5120]},r[33338]={v:33320,h:!0,F:!1,A:[4],type:[5123]},r[33337]={v:33320,h:!0,F:!1,A:[4],type:[5122]},r[33340]={v:33320,h:!0,F:!1,A:[8],type:[5125]},r[33339]={v:33320,h:!0,F:!1,A:[8],type:[5124]},r[32849]={v:b,h:!0,F:!0,A:[3],type:[5121]},r[35905]={v:b,h:!1,F:!0,A:[3],type:[5121]},r[36194]={v:b,h:!0,F:!0,A:[3,2],type:[5121,33635]},r[36758]={v:b,h:!1,F:!0,A:[3],type:[5120]},r[35898]={v:b,h:!1,F:!0,A:[12,6,4],type:[5126,5131,35899]},r[35901]={v:b,h:!1,F:!0,A:[12,6,4],type:[5126,5131,35902]},r[34843]={v:b,h:!1,F:!0,A:[12,6],type:[5126,5131]},r[34837]={v:b,h:!1,F:!1,A:[12],type:[5126]},r[36221]={v:36248,h:!1,F:!1,A:[3],type:[5121]},r[36239]={v:36248,h:!1,F:!1,A:[3],type:[5120]},r[36215]={v:36248,h:!1,F:!1,A:[6],type:[5123]},r[36233]={v:36248,h:!1,F:!1,A:[6],type:[5122]},r[36209]={v:36248,h:!1,F:!1,A:[12],type:[5125]},r[36227]={v:36248,h:!1,F:!1,A:[12],type:[5124]},r[32856]={v:6408,h:!0,F:!0,A:[4],type:[5121]},r[35907]={v:6408,h:!0,F:!0,A:[4],type:[5121]},r[36759]={v:6408,h:!1,F:!0,A:[4],type:[5120]},r[32855]={v:6408,h:!0,F:!0,A:[4,2,4],type:[5121,32820,33640]},r[32854]={v:6408,h:!0,F:!0,A:[4,2],type:[5121,32819]},r[32857]={v:6408,h:!0,F:!0,A:[4],type:[33640]},r[34842]={v:6408,h:!1,F:!0,A:[16,8],type:[5126,5131]},r[34836]={v:6408,h:!1,F:!1,A:[16],type:[5126]},r[36220]={v:36249,h:!0,F:!1,A:[4],type:[5121]},r[36238]={v:36249,h:!0,F:!1,A:[4],type:[5120]},r[36975]={v:36249,h:!0,F:!1,A:[4],type:[33640]},r[36214]={v:36249,h:!0,F:!1,A:[8],type:[5123]},r[36232]={v:36249,h:!0,F:!1,A:[8],type:[5122]},r[36226]={v:36249,h:!0,F:!1,A:[16],type:[5124]},r[36208]={v:36249,h:!0,F:!1,A:[16],type:[5125]},r[33189]={v:6402,h:!0,F:!1,A:[2,4],type:[5123,5125]},r[33190]={v:6402,h:!0,F:!1,A:[4],type:[5125]},r[36012]={v:6402,h:!0,F:!1,A:[4],type:[5126]},r[35056]={v:34041,h:!0,F:!1,A:[4],type:[34042]},r[36013]={v:34041,h:!0,F:!1,A:[4],type:[36269]},Object.keys(r).forEach((function(e){var t=r[e];t.bytesPerElementMap={},t.A.forEach((function(e,r){var n=t.type[r];t.bytesPerElementMap[n]=e}))})),v=r}return v[e]}function x(e,r){var t=p(e);if(!t)throw"unknown internal format";var n=t.bytesPerElementMap[r];if(void 0===n)throw"unknown internal format";return n}function w(e){var r=p(e);if(!r)throw"unknown internal format";return{format:r.v,type:r.type[0]}}function h(e){return 0==(e&e-1)}function F(e,r,t,o){if(!n.isWebGL2(e))return h(r)&&h(t);var u=p(o);if(!u)throw"unknown internal format";return u.h&&u.F}function E(e){var r=p(e);if(!r)throw"unknown internal format";return r.F}function A(e,r,t){return l(r)?o.getGLTypeForTypedArray(r):t||5121}function O(e,r,t,n,o){if(o%1!=0)throw"can't guess dimensions";if(t||n){if(n){if(!t&&(t=o/n)%1)throw"can't guess dimensions"}else if((n=o/t)%1)throw"can't guess dimensions"}else{var u=Math.sqrt(o/(34067===r?6:1));u%1==0?(t=u,n=u):(t=o,n=1)}return{width:t,height:n}}function _(e){c.textureColor=new Uint8Array([255*e[0],255*e[1],255*e[2],255*e[3]])}m[6406]={u:1},m[6409]={u:1},m[6410]={u:2},m[b]={u:3},m[6408]={u:4},m[6403]={u:1},m[36244]={u:1},m[y]={u:2},m[33320]={u:2},m[b]={u:3},m[36248]={u:3},m[6408]={u:4},m[36249]={u:4},m[6402]={u:1},m[34041]={u:2};var j={};function M(e,r){void 0!==r.colorspaceConversion&&(j.colorspaceConversion=e.getParameter(37443),e.pixelStorei(37443,r.colorspaceConversion)),void 0!==r.premultiplyAlpha&&(j.premultiplyAlpha=e.getParameter(37441),e.pixelStorei(37441,r.premultiplyAlpha)),void 0!==r.flipY&&(j.flipY=e.getParameter(37440),e.pixelStorei(37440,r.flipY))}function P(e,r){void 0!==r.colorspaceConversion&&e.pixelStorei(37443,j.colorspaceConversion),void 0!==r.premultiplyAlpha&&e.pixelStorei(37441,j.premultiplyAlpha),void 0!==r.flipY&&e.pixelStorei(37440,j.flipY)}function R(e){j.unpackAlignment=e.getParameter(3317),n.isWebGL2(e)&&(j.unpackRowLength=e.getParameter(3314),j.unpackImageHeight=e.getParameter(32878),j.unpackSkipPixels=e.getParameter(3316),j.unpackSkipRows=e.getParameter(3315),j.unpackSkipImages=e.getParameter(32877))}function T(e){e.pixelStorei(3317,j.unpackAlignment),n.isWebGL2(e)&&(e.pixelStorei(3314,j.unpackRowLength),e.pixelStorei(32878,j.unpackImageHeight),e.pixelStorei(3316,j.unpackSkipPixels),e.pixelStorei(3315,j.unpackSkipRows),e.pixelStorei(32877,j.unpackSkipImages))}function g(e,r,t,n){n.minMag&&(t.call(e,r,10241,n.minMag),t.call(e,r,10240,n.minMag)),n.min&&t.call(e,r,10241,n.min),n.mag&&t.call(e,r,10240,n.mag),n.wrap&&(t.call(e,r,10242,n.wrap),t.call(e,r,10243,n.wrap),(32879===r||u.isSampler(e,r))&&t.call(e,r,32882,n.wrap)),n.wrapR&&t.call(e,r,32882,n.wrapR),n.wrapS&&t.call(e,r,10242,n.wrapS),n.wrapT&&t.call(e,r,10243,n.wrapT),n.minLod&&t.call(e,r,33082,n.minLod),n.maxLod&&t.call(e,r,33083,n.maxLod),n.baseLevel&&t.call(e,r,33084,n.baseLevel),n.maxLevel&&t.call(e,r,33085,n.maxLevel)}function z(e,r,t){var n=t.target||3553;e.bindTexture(n,r),g(e,n,e.texParameteri,t)}function U(e,r,t){g(e,r,e.samplerParameteri,t)}function C(e,r){var t=e.createSampler();return U(e,t,r),t}function S(e,r,t,n,o,u){u=u||6408;var i=(t=t||c.textureOptions).target||3553;if(n=n||t.width,o=o||t.height,e.bindTexture(i,r),F(e,n,o,u))e.generateMipmap(i);else{var a=E(u)?9729:9728;e.texParameteri(i,10241,a),e.texParameteri(i,10240,a),e.texParameteri(i,10242,33071),e.texParameteri(i,10243,33071)}}function k(e){return!0===e.auto||void 0===e.auto&&void 0===e.level}function W(e,r){return(r=r||{}).cubeFaceOrder||[34069,34070,34071,34072,34073,34074]}function I(e,r){var t=W(0,r).map((function(e,r){return{face:e,ndx:r}}));return t.sort((function(e,r){return e.face-r.face})),t}function B(e,r,t,n){var o=(n=n||c.textureOptions).target||3553,u=n.level||0,i=t.width,a=t.height,f=n.internalFormat||n.format||6408,l=w(f),v=n.format||l.format,b=n.type||l.type;if(M(e,n),e.bindTexture(o,r),34067===o){var y,d,m=t.width,p=t.height;if(m/6===p)y=p,d=[0,0,1,0,2,0,3,0,4,0,5,0];else if(p/6===m)y=m,d=[0,0,0,1,0,2,0,3,0,4,0,5];else if(m/3==p/2)y=m/3,d=[0,0,1,0,2,0,0,1,1,1,2,1];else{if(m/2!=p/3)throw"can't figure out cube map from element: "+(t.src?t.src:t.nodeName);y=m/2,d=[0,0,1,0,0,1,1,1,0,2,1,2]}var x=s();x?(x.canvas.width=y,x.canvas.height=y,i=y,a=y,I(0,n).forEach((function(r){var n=d[2*r.ndx+0]*y,o=d[2*r.ndx+1]*y;x.drawImage(t,n,o,y,y,0,0,y,y),e.texImage2D(r.face,u,f,v,b,x.canvas)})),x.canvas.width=1,x.canvas.height=1):"undefined"!=typeof createImageBitmap&&(i=y,a=y,I(0,n).forEach((function(c){var l=d[2*c.ndx+0]*y,s=d[2*c.ndx+1]*y;e.texImage2D(c.face,u,f,y,y,0,v,b,null),createImageBitmap(t,l,s,y,y,{premultiplyAlpha:"none",colorSpaceConversion:"none"}).then((function(t){M(e,n),e.bindTexture(o,r),e.texImage2D(c.face,u,f,v,b,t),P(e,n),k(n)&&S(e,r,n,i,a,f)}))})))}else if(32879===o||35866===o){var h=Math.min(t.width,t.height),F=Math.max(t.width,t.height),E=F/h;if(E%1!=0)throw"can not compute 3D dimensions of element";var A=t.width===F?1:0,O=t.height===F?1:0;R(e),e.pixelStorei(3317,1),e.pixelStorei(3314,t.width),e.pixelStorei(32878,0),e.pixelStorei(32877,0),e.texImage3D(o,u,f,h,h,h,0,v,b,null);for(var _=0;_=0?w(n,r):t.indexOf("tan")>=0||t.indexOf("binorm")>=0?p(n,r):t.indexOf("norm")>=0&&x(n,r)})),e}function F(e,r,t){return e=e||2,{position:{numComponents:2,data:[(r=r||0)+-1*(e*=.5),(t=t||0)+-1*e,r+1*e,t+-1*e,r+-1*e,t+1*e,r+1*e,t+1*e]},normal:[0,0,1,0,0,1,0,0,1,0,0,1],texcoord:[0,0,1,0,0,1,1,1],indices:[0,1,2,2,1,3]}}function E(e,r,t,n,o){e=e||1,r=r||1,t=t||1,n=n||1,o=o||i.identity();for(var u=(t+1)*(n+1),a=b(3,u),f=b(3,u),c=b(2,u),l=0;l<=n;l++)for(var s=0;s<=t;s++){var v=s/t,y=l/n;a.push(e*v-.5*e,0,r*y-.5*r),f.push(0,1,0),c.push(v,y)}for(var d=t+1,m=b(3,t*n*2,Uint16Array),p=0;p 0");n=n||0,u=u||0;for(var a=(o=o||Math.PI)-n,f=(i=i||2*Math.PI)-u,c=(r+1)*(t+1),l=b(3,c),s=b(3,c),v=b(2,c),y=0;y<=t;y++)for(var d=0;d<=r;d++){var m=d/r,p=y/t,x=f*m+u,w=a*p+n,h=Math.sin(x),F=Math.cos(x),E=Math.sin(w),A=F*E,O=Math.cos(w),_=h*E;l.push(e*A,e*O,e*_),s.push(A,O,_),v.push(1-m,p)}for(var j=r+1,M=b(3,r*t*2,Uint16Array),P=0;Po?(A=t,E=1,O=r):O=e+F/o*(r-e),-2!==F&&F!==o+2||(O=0,E=0),A-=t/2;for(var _=0;_o?v.push(0,1,0):0===O?v.push(0,0,0):v.push(j*x,w,M*x),y.push(_/n,1-E)}}for(var P=0;P 0");var f=(i=i||1)-(u=u||0),c=2*(o+1)*4,l=b(3,c),s=b(3,c),v=b(2,c);function y(e,r,t){return e+(r-e)*t}function d(r,t,i,c,b,d){for(var m=0;m<=o;m++){var p=t/1,x=m/o,w=2*(p-.5),h=(u+x*f)*Math.PI,F=Math.sin(h),E=Math.cos(h),A=y(e,r,F),O=w*n,_=E*e,j=F*A;l.push(O,_,j);var M=a.add(a.multiply([0,F,E],i),c);s.push(M),v.push(p*b+d,x)}}for(var m=0;m<2;m++){var p=2*(m/1-.5);d(r,m,[1,1,1],[0,0,0],1,0),d(r,m,[0,0,0],[p,0,0],0,0),d(t,m,[1,1,1],[0,0,0],1,0),d(t,m,[0,0,0],[p,0,0],0,1)}var x=b(3,2*o*4,Uint16Array);function w(e,r){for(var t=0;t0&&m!==r){var h=l+(m+1),F=l+m,E=l+m-v,A=l+(m+1)-v;c.push(h,F,E),c.push(h,E,A)}}l+=r+1}return{position:i,normal:a,texcoord:f,indices:c}}function U(e){return function(r){var t=e.apply(this,Array.prototype.slice.call(arguments,1));return n.createBuffersFromArrays(r,t)}}function C(e){return function(r){var t=e.apply(null,Array.prototype.slice.call(arguments,1));return n.createBufferInfoFromArrays(r,t)}}var S=["numComponents","size","type","normalize","stride","offset","attrib","name","attribName"];function k(e,r,t,n){n=n||0;for(var o=e.length,u=0;u 0.00001) {
+ dst[0] = a[0] / len;
+ dst[1] = a[1] / len;
+ dst[2] = a[2] / len;
+ } else {
+ dst[0] = 0;
+ dst[1] = 0;
+ dst[2] = 0;
+ }
+
+ return dst;
+}
+
+/**
+ * Negates a vector.
+ * @param {module:twgl/v3.Vec3} v The vector.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} -v.
+ * @memberOf module:twgl/v3
+ */
+function negate(v, dst) {
+ dst = dst || new VecType(3);
+
+ dst[0] = -v[0];
+ dst[1] = -v[1];
+ dst[2] = -v[2];
+
+ return dst;
+}
+
+/**
+ * Copies a vector.
+ * @param {module:twgl/v3.Vec3} v The vector.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} A copy of v.
+ * @memberOf module:twgl/v3
+ */
+function copy(v, dst) {
+ dst = dst || new VecType(3);
+
+ dst[0] = v[0];
+ dst[1] = v[1];
+ dst[2] = v[2];
+
+ return dst;
+}
+
+/**
+ * Multiplies a vector by another vector (component-wise); assumes a and
+ * b have the same length.
+ * @param {module:twgl/v3.Vec3} a Operand vector.
+ * @param {module:twgl/v3.Vec3} b Operand vector.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} The vector of products of entries of a and
+ * b.
+ * @memberOf module:twgl/v3
+ */
+function multiply(a, b, dst) {
+ dst = dst || new VecType(3);
+
+ dst[0] = a[0] * b[0];
+ dst[1] = a[1] * b[1];
+ dst[2] = a[2] * b[2];
+
+ return dst;
+}
+
+/**
+ * Divides a vector by another vector (component-wise); assumes a and
+ * b have the same length.
+ * @param {module:twgl/v3.Vec3} a Operand vector.
+ * @param {module:twgl/v3.Vec3} b Operand vector.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not new one is created.
+ * @return {module:twgl/v3.Vec3} The vector of quotients of entries of a and
+ * b.
+ * @memberOf module:twgl/v3
+ */
+function divide(a, b, dst) {
+ dst = dst || new VecType(3);
+
+ dst[0] = a[0] / b[0];
+ dst[1] = a[1] / b[1];
+ dst[2] = a[2] / b[2];
+
+ return dst;
+}
+
+var v3 = /*#__PURE__*/Object.freeze({
+ __proto__: null,
+ add: add,
+ copy: copy,
+ create: create,
+ cross: cross,
+ distance: distance,
+ distanceSq: distanceSq,
+ divide: divide,
+ divScalar: divScalar,
+ dot: dot,
+ lerp: lerp,
+ lerpV: lerpV,
+ length: length$1,
+ lengthSq: lengthSq,
+ max: max,
+ min: min,
+ mulScalar: mulScalar,
+ multiply: multiply,
+ negate: negate,
+ normalize: normalize,
+ setDefaultType: setDefaultType,
+ subtract: subtract
+});
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * 4x4 Matrix math math functions.
+ *
+ * Almost all functions take an optional `dst` argument. If it is not passed in the
+ * functions will create a new matrix. In other words you can do this
+ *
+ * const mat = m4.translation([1, 2, 3]); // Creates a new translation matrix
+ *
+ * or
+ *
+ * const mat = m4.create();
+ * m4.translation([1, 2, 3], mat); // Puts translation matrix in mat.
+ *
+ * The first style is often easier but depending on where it's used it generates garbage where
+ * as there is almost never allocation with the second style.
+ *
+ * It is always save to pass any matrix as the destination. So for example
+ *
+ * const mat = m4.identity();
+ * const trans = m4.translation([1, 2, 3]);
+ * m4.multiply(mat, trans, mat); // Multiplies mat * trans and puts result in mat.
+ *
+ * @module twgl/m4
+ */
+let MatType = Float32Array;
+
+/**
+ * A JavaScript array with 16 values or a Float32Array with 16 values.
+ * When created by the library will create the default type which is `Float32Array`
+ * but can be set by calling {@link module:twgl/m4.setDefaultType}.
+ * @typedef {(number[]|Float32Array)} Mat4
+ * @memberOf module:twgl/m4
+ */
+
+/**
+ * Sets the type this library creates for a Mat4
+ * @param {constructor} ctor the constructor for the type. Either `Float32Array` or `Array`
+ * @return {constructor} previous constructor for Mat4
+ * @memberOf module:twgl/m4
+ */
+function setDefaultType$1(ctor) {
+ const oldType = MatType;
+ MatType = ctor;
+ return oldType;
+}
+
+/**
+ * Negates a matrix.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} -m.
+ * @memberOf module:twgl/m4
+ */
+function negate$1(m, dst) {
+ dst = dst || new MatType(16);
+
+ dst[ 0] = -m[ 0];
+ dst[ 1] = -m[ 1];
+ dst[ 2] = -m[ 2];
+ dst[ 3] = -m[ 3];
+ dst[ 4] = -m[ 4];
+ dst[ 5] = -m[ 5];
+ dst[ 6] = -m[ 6];
+ dst[ 7] = -m[ 7];
+ dst[ 8] = -m[ 8];
+ dst[ 9] = -m[ 9];
+ dst[10] = -m[10];
+ dst[11] = -m[11];
+ dst[12] = -m[12];
+ dst[13] = -m[13];
+ dst[14] = -m[14];
+ dst[15] = -m[15];
+
+ return dst;
+}
+
+/**
+ * Copies a matrix.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/m4.Mat4} [dst] The matrix. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} A copy of m.
+ * @memberOf module:twgl/m4
+ */
+function copy$1(m, dst) {
+ dst = dst || new MatType(16);
+
+ dst[ 0] = m[ 0];
+ dst[ 1] = m[ 1];
+ dst[ 2] = m[ 2];
+ dst[ 3] = m[ 3];
+ dst[ 4] = m[ 4];
+ dst[ 5] = m[ 5];
+ dst[ 6] = m[ 6];
+ dst[ 7] = m[ 7];
+ dst[ 8] = m[ 8];
+ dst[ 9] = m[ 9];
+ dst[10] = m[10];
+ dst[11] = m[11];
+ dst[12] = m[12];
+ dst[13] = m[13];
+ dst[14] = m[14];
+ dst[15] = m[15];
+
+ return dst;
+}
+
+/**
+ * Creates an n-by-n identity matrix.
+ *
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} An n-by-n identity matrix.
+ * @memberOf module:twgl/m4
+ */
+function identity(dst) {
+ dst = dst || new MatType(16);
+
+ dst[ 0] = 1;
+ dst[ 1] = 0;
+ dst[ 2] = 0;
+ dst[ 3] = 0;
+ dst[ 4] = 0;
+ dst[ 5] = 1;
+ dst[ 6] = 0;
+ dst[ 7] = 0;
+ dst[ 8] = 0;
+ dst[ 9] = 0;
+ dst[10] = 1;
+ dst[11] = 0;
+ dst[12] = 0;
+ dst[13] = 0;
+ dst[14] = 0;
+ dst[15] = 1;
+
+ return dst;
+}
+
+/**
+ * Takes the transpose of a matrix.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The transpose of m.
+ * @memberOf module:twgl/m4
+ */
+ function transpose(m, dst) {
+ dst = dst || new MatType(16);
+ if (dst === m) {
+ let t;
+
+ t = m[1];
+ m[1] = m[4];
+ m[4] = t;
+
+ t = m[2];
+ m[2] = m[8];
+ m[8] = t;
+
+ t = m[3];
+ m[3] = m[12];
+ m[12] = t;
+
+ t = m[6];
+ m[6] = m[9];
+ m[9] = t;
+
+ t = m[7];
+ m[7] = m[13];
+ m[13] = t;
+
+ t = m[11];
+ m[11] = m[14];
+ m[14] = t;
+ return dst;
+ }
+
+ const m00 = m[0 * 4 + 0];
+ const m01 = m[0 * 4 + 1];
+ const m02 = m[0 * 4 + 2];
+ const m03 = m[0 * 4 + 3];
+ const m10 = m[1 * 4 + 0];
+ const m11 = m[1 * 4 + 1];
+ const m12 = m[1 * 4 + 2];
+ const m13 = m[1 * 4 + 3];
+ const m20 = m[2 * 4 + 0];
+ const m21 = m[2 * 4 + 1];
+ const m22 = m[2 * 4 + 2];
+ const m23 = m[2 * 4 + 3];
+ const m30 = m[3 * 4 + 0];
+ const m31 = m[3 * 4 + 1];
+ const m32 = m[3 * 4 + 2];
+ const m33 = m[3 * 4 + 3];
+
+ dst[ 0] = m00;
+ dst[ 1] = m10;
+ dst[ 2] = m20;
+ dst[ 3] = m30;
+ dst[ 4] = m01;
+ dst[ 5] = m11;
+ dst[ 6] = m21;
+ dst[ 7] = m31;
+ dst[ 8] = m02;
+ dst[ 9] = m12;
+ dst[10] = m22;
+ dst[11] = m32;
+ dst[12] = m03;
+ dst[13] = m13;
+ dst[14] = m23;
+ dst[15] = m33;
+
+ return dst;
+}
+
+/**
+ * Computes the inverse of a 4-by-4 matrix.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The inverse of m.
+ * @memberOf module:twgl/m4
+ */
+function inverse(m, dst) {
+ dst = dst || new MatType(16);
+
+ const m00 = m[0 * 4 + 0];
+ const m01 = m[0 * 4 + 1];
+ const m02 = m[0 * 4 + 2];
+ const m03 = m[0 * 4 + 3];
+ const m10 = m[1 * 4 + 0];
+ const m11 = m[1 * 4 + 1];
+ const m12 = m[1 * 4 + 2];
+ const m13 = m[1 * 4 + 3];
+ const m20 = m[2 * 4 + 0];
+ const m21 = m[2 * 4 + 1];
+ const m22 = m[2 * 4 + 2];
+ const m23 = m[2 * 4 + 3];
+ const m30 = m[3 * 4 + 0];
+ const m31 = m[3 * 4 + 1];
+ const m32 = m[3 * 4 + 2];
+ const m33 = m[3 * 4 + 3];
+ const tmp_0 = m22 * m33;
+ const tmp_1 = m32 * m23;
+ const tmp_2 = m12 * m33;
+ const tmp_3 = m32 * m13;
+ const tmp_4 = m12 * m23;
+ const tmp_5 = m22 * m13;
+ const tmp_6 = m02 * m33;
+ const tmp_7 = m32 * m03;
+ const tmp_8 = m02 * m23;
+ const tmp_9 = m22 * m03;
+ const tmp_10 = m02 * m13;
+ const tmp_11 = m12 * m03;
+ const tmp_12 = m20 * m31;
+ const tmp_13 = m30 * m21;
+ const tmp_14 = m10 * m31;
+ const tmp_15 = m30 * m11;
+ const tmp_16 = m10 * m21;
+ const tmp_17 = m20 * m11;
+ const tmp_18 = m00 * m31;
+ const tmp_19 = m30 * m01;
+ const tmp_20 = m00 * m21;
+ const tmp_21 = m20 * m01;
+ const tmp_22 = m00 * m11;
+ const tmp_23 = m10 * m01;
+
+ const t0 = (tmp_0 * m11 + tmp_3 * m21 + tmp_4 * m31) -
+ (tmp_1 * m11 + tmp_2 * m21 + tmp_5 * m31);
+ const t1 = (tmp_1 * m01 + tmp_6 * m21 + tmp_9 * m31) -
+ (tmp_0 * m01 + tmp_7 * m21 + tmp_8 * m31);
+ const t2 = (tmp_2 * m01 + tmp_7 * m11 + tmp_10 * m31) -
+ (tmp_3 * m01 + tmp_6 * m11 + tmp_11 * m31);
+ const t3 = (tmp_5 * m01 + tmp_8 * m11 + tmp_11 * m21) -
+ (tmp_4 * m01 + tmp_9 * m11 + tmp_10 * m21);
+
+ const d = 1.0 / (m00 * t0 + m10 * t1 + m20 * t2 + m30 * t3);
+
+ dst[ 0] = d * t0;
+ dst[ 1] = d * t1;
+ dst[ 2] = d * t2;
+ dst[ 3] = d * t3;
+ dst[ 4] = d * ((tmp_1 * m10 + tmp_2 * m20 + tmp_5 * m30) -
+ (tmp_0 * m10 + tmp_3 * m20 + tmp_4 * m30));
+ dst[ 5] = d * ((tmp_0 * m00 + tmp_7 * m20 + tmp_8 * m30) -
+ (tmp_1 * m00 + tmp_6 * m20 + tmp_9 * m30));
+ dst[ 6] = d * ((tmp_3 * m00 + tmp_6 * m10 + tmp_11 * m30) -
+ (tmp_2 * m00 + tmp_7 * m10 + tmp_10 * m30));
+ dst[ 7] = d * ((tmp_4 * m00 + tmp_9 * m10 + tmp_10 * m20) -
+ (tmp_5 * m00 + tmp_8 * m10 + tmp_11 * m20));
+ dst[ 8] = d * ((tmp_12 * m13 + tmp_15 * m23 + tmp_16 * m33) -
+ (tmp_13 * m13 + tmp_14 * m23 + tmp_17 * m33));
+ dst[ 9] = d * ((tmp_13 * m03 + tmp_18 * m23 + tmp_21 * m33) -
+ (tmp_12 * m03 + tmp_19 * m23 + tmp_20 * m33));
+ dst[10] = d * ((tmp_14 * m03 + tmp_19 * m13 + tmp_22 * m33) -
+ (tmp_15 * m03 + tmp_18 * m13 + tmp_23 * m33));
+ dst[11] = d * ((tmp_17 * m03 + tmp_20 * m13 + tmp_23 * m23) -
+ (tmp_16 * m03 + tmp_21 * m13 + tmp_22 * m23));
+ dst[12] = d * ((tmp_14 * m22 + tmp_17 * m32 + tmp_13 * m12) -
+ (tmp_16 * m32 + tmp_12 * m12 + tmp_15 * m22));
+ dst[13] = d * ((tmp_20 * m32 + tmp_12 * m02 + tmp_19 * m22) -
+ (tmp_18 * m22 + tmp_21 * m32 + tmp_13 * m02));
+ dst[14] = d * ((tmp_18 * m12 + tmp_23 * m32 + tmp_15 * m02) -
+ (tmp_22 * m32 + tmp_14 * m02 + tmp_19 * m12));
+ dst[15] = d * ((tmp_22 * m22 + tmp_16 * m02 + tmp_21 * m12) -
+ (tmp_20 * m12 + tmp_23 * m22 + tmp_17 * m02));
+
+ return dst;
+}
+
+/**
+ * Multiplies two 4-by-4 matrices with a on the left and b on the right
+ * @param {module:twgl/m4.Mat4} a The matrix on the left.
+ * @param {module:twgl/m4.Mat4} b The matrix on the right.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The matrix product of a and b.
+ * @memberOf module:twgl/m4
+ */
+function multiply$1(a, b, dst) {
+ dst = dst || new MatType(16);
+
+ const a00 = a[0];
+ const a01 = a[1];
+ const a02 = a[2];
+ const a03 = a[3];
+ const a10 = a[ 4 + 0];
+ const a11 = a[ 4 + 1];
+ const a12 = a[ 4 + 2];
+ const a13 = a[ 4 + 3];
+ const a20 = a[ 8 + 0];
+ const a21 = a[ 8 + 1];
+ const a22 = a[ 8 + 2];
+ const a23 = a[ 8 + 3];
+ const a30 = a[12 + 0];
+ const a31 = a[12 + 1];
+ const a32 = a[12 + 2];
+ const a33 = a[12 + 3];
+ const b00 = b[0];
+ const b01 = b[1];
+ const b02 = b[2];
+ const b03 = b[3];
+ const b10 = b[ 4 + 0];
+ const b11 = b[ 4 + 1];
+ const b12 = b[ 4 + 2];
+ const b13 = b[ 4 + 3];
+ const b20 = b[ 8 + 0];
+ const b21 = b[ 8 + 1];
+ const b22 = b[ 8 + 2];
+ const b23 = b[ 8 + 3];
+ const b30 = b[12 + 0];
+ const b31 = b[12 + 1];
+ const b32 = b[12 + 2];
+ const b33 = b[12 + 3];
+
+ dst[ 0] = a00 * b00 + a10 * b01 + a20 * b02 + a30 * b03;
+ dst[ 1] = a01 * b00 + a11 * b01 + a21 * b02 + a31 * b03;
+ dst[ 2] = a02 * b00 + a12 * b01 + a22 * b02 + a32 * b03;
+ dst[ 3] = a03 * b00 + a13 * b01 + a23 * b02 + a33 * b03;
+ dst[ 4] = a00 * b10 + a10 * b11 + a20 * b12 + a30 * b13;
+ dst[ 5] = a01 * b10 + a11 * b11 + a21 * b12 + a31 * b13;
+ dst[ 6] = a02 * b10 + a12 * b11 + a22 * b12 + a32 * b13;
+ dst[ 7] = a03 * b10 + a13 * b11 + a23 * b12 + a33 * b13;
+ dst[ 8] = a00 * b20 + a10 * b21 + a20 * b22 + a30 * b23;
+ dst[ 9] = a01 * b20 + a11 * b21 + a21 * b22 + a31 * b23;
+ dst[10] = a02 * b20 + a12 * b21 + a22 * b22 + a32 * b23;
+ dst[11] = a03 * b20 + a13 * b21 + a23 * b22 + a33 * b23;
+ dst[12] = a00 * b30 + a10 * b31 + a20 * b32 + a30 * b33;
+ dst[13] = a01 * b30 + a11 * b31 + a21 * b32 + a31 * b33;
+ dst[14] = a02 * b30 + a12 * b31 + a22 * b32 + a32 * b33;
+ dst[15] = a03 * b30 + a13 * b31 + a23 * b32 + a33 * b33;
+
+ return dst;
+}
+
+/**
+ * Sets the translation component of a 4-by-4 matrix to the given
+ * vector.
+ * @param {module:twgl/m4.Mat4} a The matrix.
+ * @param {module:twgl/v3.Vec3} v The vector.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The matrix with translation set.
+ * @memberOf module:twgl/m4
+ */
+function setTranslation(a, v, dst) {
+ dst = dst || identity();
+ if (a !== dst) {
+ dst[ 0] = a[ 0];
+ dst[ 1] = a[ 1];
+ dst[ 2] = a[ 2];
+ dst[ 3] = a[ 3];
+ dst[ 4] = a[ 4];
+ dst[ 5] = a[ 5];
+ dst[ 6] = a[ 6];
+ dst[ 7] = a[ 7];
+ dst[ 8] = a[ 8];
+ dst[ 9] = a[ 9];
+ dst[10] = a[10];
+ dst[11] = a[11];
+ }
+ dst[12] = v[0];
+ dst[13] = v[1];
+ dst[14] = v[2];
+ dst[15] = 1;
+ return dst;
+}
+
+/**
+ * Returns the translation component of a 4-by-4 matrix as a vector with 3
+ * entries.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/v3.Vec3} [dst] vector to hold result. If not passed a new one is created.
+ * @return {module:twgl/v3.Vec3} The translation component of m.
+ * @memberOf module:twgl/m4
+ */
+function getTranslation(m, dst) {
+ dst = dst || create();
+ dst[0] = m[12];
+ dst[1] = m[13];
+ dst[2] = m[14];
+ return dst;
+}
+
+/**
+ * Returns an axis of a 4x4 matrix as a vector with 3 entries
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {number} axis The axis 0 = x, 1 = y, 2 = z;
+ * @return {module:twgl/v3.Vec3} [dst] vector.
+ * @return {module:twgl/v3.Vec3} The axis component of m.
+ * @memberOf module:twgl/m4
+ */
+function getAxis(m, axis, dst) {
+ dst = dst || create();
+ const off = axis * 4;
+ dst[0] = m[off + 0];
+ dst[1] = m[off + 1];
+ dst[2] = m[off + 2];
+ return dst;
+}
+
+/**
+ * Sets an axis of a 4x4 matrix as a vector with 3 entries
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/v3.Vec3} v the axis vector
+ * @param {number} axis The axis 0 = x, 1 = y, 2 = z;
+ * @param {module:twgl/m4.Mat4} [dst] The matrix to set. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The matrix with axis set.
+ * @memberOf module:twgl/m4
+ */
+function setAxis(a, v, axis, dst) {
+ if (dst !== a) {
+ dst = copy$1(a, dst);
+ }
+ const off = axis * 4;
+ dst[off + 0] = v[0];
+ dst[off + 1] = v[1];
+ dst[off + 2] = v[2];
+ return dst;
+}
+
+/**
+ * Computes a 4-by-4 perspective transformation matrix given the angular height
+ * of the frustum, the aspect ratio, and the near and far clipping planes. The
+ * arguments define a frustum extending in the negative z direction. The given
+ * angle is the vertical angle of the frustum, and the horizontal angle is
+ * determined to produce the given aspect ratio. The arguments near and far are
+ * the distances to the near and far clipping planes. Note that near and far
+ * are not z coordinates, but rather they are distances along the negative
+ * z-axis. The matrix generated sends the viewing frustum to the unit box.
+ * We assume a unit box extending from -1 to 1 in the x and y dimensions and
+ * from 0 to 1 in the z dimension.
+ * @param {number} fieldOfViewYInRadians The camera angle from top to bottom (in radians).
+ * @param {number} aspect The aspect ratio width / height.
+ * @param {number} zNear The depth (negative z coordinate)
+ * of the near clipping plane.
+ * @param {number} zFar The depth (negative z coordinate)
+ * of the far clipping plane.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The perspective matrix.
+ * @memberOf module:twgl/m4
+ */
+function perspective(fieldOfViewYInRadians, aspect, zNear, zFar, dst) {
+ dst = dst || new MatType(16);
+
+ const f = Math.tan(Math.PI * 0.5 - 0.5 * fieldOfViewYInRadians);
+ const rangeInv = 1.0 / (zNear - zFar);
+
+ dst[0] = f / aspect;
+ dst[1] = 0;
+ dst[2] = 0;
+ dst[3] = 0;
+
+ dst[4] = 0;
+ dst[5] = f;
+ dst[6] = 0;
+ dst[7] = 0;
+
+ dst[8] = 0;
+ dst[9] = 0;
+ dst[10] = (zNear + zFar) * rangeInv;
+ dst[11] = -1;
+
+ dst[12] = 0;
+ dst[13] = 0;
+ dst[14] = zNear * zFar * rangeInv * 2;
+ dst[15] = 0;
+
+ return dst;
+}
+
+/**
+ * Computes a 4-by-4 orthogonal transformation matrix given the left, right,
+ * bottom, and top dimensions of the near clipping plane as well as the
+ * near and far clipping plane distances.
+ * @param {number} left Left side of the near clipping plane viewport.
+ * @param {number} right Right side of the near clipping plane viewport.
+ * @param {number} bottom Bottom of the near clipping plane viewport.
+ * @param {number} top Top of the near clipping plane viewport.
+ * @param {number} near The depth (negative z coordinate)
+ * of the near clipping plane.
+ * @param {number} far The depth (negative z coordinate)
+ * of the far clipping plane.
+ * @param {module:twgl/m4.Mat4} [dst] Output matrix. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The perspective matrix.
+ * @memberOf module:twgl/m4
+ */
+function ortho(left, right, bottom, top, near, far, dst) {
+ dst = dst || new MatType(16);
+
+ dst[0] = 2 / (right - left);
+ dst[1] = 0;
+ dst[2] = 0;
+ dst[3] = 0;
+
+ dst[4] = 0;
+ dst[5] = 2 / (top - bottom);
+ dst[6] = 0;
+ dst[7] = 0;
+
+ dst[8] = 0;
+ dst[9] = 0;
+ dst[10] = 2 / (near - far);
+ dst[11] = 0;
+
+ dst[12] = (right + left) / (left - right);
+ dst[13] = (top + bottom) / (bottom - top);
+ dst[14] = (far + near) / (near - far);
+ dst[15] = 1;
+
+ return dst;
+}
+
+/**
+ * Computes a 4-by-4 perspective transformation matrix given the left, right,
+ * top, bottom, near and far clipping planes. The arguments define a frustum
+ * extending in the negative z direction. The arguments near and far are the
+ * distances to the near and far clipping planes. Note that near and far are not
+ * z coordinates, but rather they are distances along the negative z-axis. The
+ * matrix generated sends the viewing frustum to the unit box. We assume a unit
+ * box extending from -1 to 1 in the x and y dimensions and from 0 to 1 in the z
+ * dimension.
+ * @param {number} left The x coordinate of the left plane of the box.
+ * @param {number} right The x coordinate of the right plane of the box.
+ * @param {number} bottom The y coordinate of the bottom plane of the box.
+ * @param {number} top The y coordinate of the right plane of the box.
+ * @param {number} near The negative z coordinate of the near plane of the box.
+ * @param {number} far The negative z coordinate of the far plane of the box.
+ * @param {module:twgl/m4.Mat4} [dst] Output matrix. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The perspective projection matrix.
+ * @memberOf module:twgl/m4
+ */
+function frustum(left, right, bottom, top, near, far, dst) {
+ dst = dst || new MatType(16);
+
+ const dx = (right - left);
+ const dy = (top - bottom);
+ const dz = (near - far);
+
+ dst[ 0] = 2 * near / dx;
+ dst[ 1] = 0;
+ dst[ 2] = 0;
+ dst[ 3] = 0;
+ dst[ 4] = 0;
+ dst[ 5] = 2 * near / dy;
+ dst[ 6] = 0;
+ dst[ 7] = 0;
+ dst[ 8] = (left + right) / dx;
+ dst[ 9] = (top + bottom) / dy;
+ dst[10] = far / dz;
+ dst[11] = -1;
+ dst[12] = 0;
+ dst[13] = 0;
+ dst[14] = near * far / dz;
+ dst[15] = 0;
+
+ return dst;
+}
+
+let xAxis;
+let yAxis;
+let zAxis;
+
+/**
+ * Computes a 4-by-4 look-at transformation.
+ *
+ * This is a matrix which positions the camera itself. If you want
+ * a view matrix (a matrix which moves things in front of the camera)
+ * take the inverse of this.
+ *
+ * @param {module:twgl/v3.Vec3} eye The position of the eye.
+ * @param {module:twgl/v3.Vec3} target The position meant to be viewed.
+ * @param {module:twgl/v3.Vec3} up A vector pointing up.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The look-at matrix.
+ * @memberOf module:twgl/m4
+ */
+function lookAt(eye, target, up, dst) {
+ dst = dst || new MatType(16);
+
+ xAxis = xAxis || create();
+ yAxis = yAxis || create();
+ zAxis = zAxis || create();
+
+ normalize(
+ subtract(eye, target, zAxis), zAxis);
+ normalize(cross(up, zAxis, xAxis), xAxis);
+ normalize(cross(zAxis, xAxis, yAxis), yAxis);
+
+ dst[ 0] = xAxis[0];
+ dst[ 1] = xAxis[1];
+ dst[ 2] = xAxis[2];
+ dst[ 3] = 0;
+ dst[ 4] = yAxis[0];
+ dst[ 5] = yAxis[1];
+ dst[ 6] = yAxis[2];
+ dst[ 7] = 0;
+ dst[ 8] = zAxis[0];
+ dst[ 9] = zAxis[1];
+ dst[10] = zAxis[2];
+ dst[11] = 0;
+ dst[12] = eye[0];
+ dst[13] = eye[1];
+ dst[14] = eye[2];
+ dst[15] = 1;
+
+ return dst;
+}
+
+/**
+ * Creates a 4-by-4 matrix which translates by the given vector v.
+ * @param {module:twgl/v3.Vec3} v The vector by
+ * which to translate.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The translation matrix.
+ * @memberOf module:twgl/m4
+ */
+function translation(v, dst) {
+ dst = dst || new MatType(16);
+
+ dst[ 0] = 1;
+ dst[ 1] = 0;
+ dst[ 2] = 0;
+ dst[ 3] = 0;
+ dst[ 4] = 0;
+ dst[ 5] = 1;
+ dst[ 6] = 0;
+ dst[ 7] = 0;
+ dst[ 8] = 0;
+ dst[ 9] = 0;
+ dst[10] = 1;
+ dst[11] = 0;
+ dst[12] = v[0];
+ dst[13] = v[1];
+ dst[14] = v[2];
+ dst[15] = 1;
+ return dst;
+}
+
+/**
+ * Translates the given 4-by-4 matrix by the given vector v.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/v3.Vec3} v The vector by
+ * which to translate.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The translated matrix.
+ * @memberOf module:twgl/m4
+ */
+function translate(m, v, dst) {
+ dst = dst || new MatType(16);
+
+ const v0 = v[0];
+ const v1 = v[1];
+ const v2 = v[2];
+ const m00 = m[0];
+ const m01 = m[1];
+ const m02 = m[2];
+ const m03 = m[3];
+ const m10 = m[1 * 4 + 0];
+ const m11 = m[1 * 4 + 1];
+ const m12 = m[1 * 4 + 2];
+ const m13 = m[1 * 4 + 3];
+ const m20 = m[2 * 4 + 0];
+ const m21 = m[2 * 4 + 1];
+ const m22 = m[2 * 4 + 2];
+ const m23 = m[2 * 4 + 3];
+ const m30 = m[3 * 4 + 0];
+ const m31 = m[3 * 4 + 1];
+ const m32 = m[3 * 4 + 2];
+ const m33 = m[3 * 4 + 3];
+
+ if (m !== dst) {
+ dst[ 0] = m00;
+ dst[ 1] = m01;
+ dst[ 2] = m02;
+ dst[ 3] = m03;
+ dst[ 4] = m10;
+ dst[ 5] = m11;
+ dst[ 6] = m12;
+ dst[ 7] = m13;
+ dst[ 8] = m20;
+ dst[ 9] = m21;
+ dst[10] = m22;
+ dst[11] = m23;
+ }
+
+ dst[12] = m00 * v0 + m10 * v1 + m20 * v2 + m30;
+ dst[13] = m01 * v0 + m11 * v1 + m21 * v2 + m31;
+ dst[14] = m02 * v0 + m12 * v1 + m22 * v2 + m32;
+ dst[15] = m03 * v0 + m13 * v1 + m23 * v2 + m33;
+
+ return dst;
+}
+
+/**
+ * Creates a 4-by-4 matrix which rotates around the x-axis by the given angle.
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The rotation matrix.
+ * @memberOf module:twgl/m4
+ */
+function rotationX(angleInRadians, dst) {
+ dst = dst || new MatType(16);
+
+ const c = Math.cos(angleInRadians);
+ const s = Math.sin(angleInRadians);
+
+ dst[ 0] = 1;
+ dst[ 1] = 0;
+ dst[ 2] = 0;
+ dst[ 3] = 0;
+ dst[ 4] = 0;
+ dst[ 5] = c;
+ dst[ 6] = s;
+ dst[ 7] = 0;
+ dst[ 8] = 0;
+ dst[ 9] = -s;
+ dst[10] = c;
+ dst[11] = 0;
+ dst[12] = 0;
+ dst[13] = 0;
+ dst[14] = 0;
+ dst[15] = 1;
+
+ return dst;
+}
+
+/**
+ * Rotates the given 4-by-4 matrix around the x-axis by the given
+ * angle.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The rotated matrix.
+ * @memberOf module:twgl/m4
+ */
+function rotateX(m, angleInRadians, dst) {
+ dst = dst || new MatType(16);
+
+ const m10 = m[4];
+ const m11 = m[5];
+ const m12 = m[6];
+ const m13 = m[7];
+ const m20 = m[8];
+ const m21 = m[9];
+ const m22 = m[10];
+ const m23 = m[11];
+ const c = Math.cos(angleInRadians);
+ const s = Math.sin(angleInRadians);
+
+ dst[4] = c * m10 + s * m20;
+ dst[5] = c * m11 + s * m21;
+ dst[6] = c * m12 + s * m22;
+ dst[7] = c * m13 + s * m23;
+ dst[8] = c * m20 - s * m10;
+ dst[9] = c * m21 - s * m11;
+ dst[10] = c * m22 - s * m12;
+ dst[11] = c * m23 - s * m13;
+
+ if (m !== dst) {
+ dst[ 0] = m[ 0];
+ dst[ 1] = m[ 1];
+ dst[ 2] = m[ 2];
+ dst[ 3] = m[ 3];
+ dst[12] = m[12];
+ dst[13] = m[13];
+ dst[14] = m[14];
+ dst[15] = m[15];
+ }
+
+ return dst;
+}
+
+/**
+ * Creates a 4-by-4 matrix which rotates around the y-axis by the given angle.
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The rotation matrix.
+ * @memberOf module:twgl/m4
+ */
+function rotationY(angleInRadians, dst) {
+ dst = dst || new MatType(16);
+
+ const c = Math.cos(angleInRadians);
+ const s = Math.sin(angleInRadians);
+
+ dst[ 0] = c;
+ dst[ 1] = 0;
+ dst[ 2] = -s;
+ dst[ 3] = 0;
+ dst[ 4] = 0;
+ dst[ 5] = 1;
+ dst[ 6] = 0;
+ dst[ 7] = 0;
+ dst[ 8] = s;
+ dst[ 9] = 0;
+ dst[10] = c;
+ dst[11] = 0;
+ dst[12] = 0;
+ dst[13] = 0;
+ dst[14] = 0;
+ dst[15] = 1;
+
+ return dst;
+}
+
+/**
+ * Rotates the given 4-by-4 matrix around the y-axis by the given
+ * angle.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The rotated matrix.
+ * @memberOf module:twgl/m4
+ */
+function rotateY(m, angleInRadians, dst) {
+ dst = dst || new MatType(16);
+
+ const m00 = m[0 * 4 + 0];
+ const m01 = m[0 * 4 + 1];
+ const m02 = m[0 * 4 + 2];
+ const m03 = m[0 * 4 + 3];
+ const m20 = m[2 * 4 + 0];
+ const m21 = m[2 * 4 + 1];
+ const m22 = m[2 * 4 + 2];
+ const m23 = m[2 * 4 + 3];
+ const c = Math.cos(angleInRadians);
+ const s = Math.sin(angleInRadians);
+
+ dst[ 0] = c * m00 - s * m20;
+ dst[ 1] = c * m01 - s * m21;
+ dst[ 2] = c * m02 - s * m22;
+ dst[ 3] = c * m03 - s * m23;
+ dst[ 8] = c * m20 + s * m00;
+ dst[ 9] = c * m21 + s * m01;
+ dst[10] = c * m22 + s * m02;
+ dst[11] = c * m23 + s * m03;
+
+ if (m !== dst) {
+ dst[ 4] = m[ 4];
+ dst[ 5] = m[ 5];
+ dst[ 6] = m[ 6];
+ dst[ 7] = m[ 7];
+ dst[12] = m[12];
+ dst[13] = m[13];
+ dst[14] = m[14];
+ dst[15] = m[15];
+ }
+
+ return dst;
+}
+
+/**
+ * Creates a 4-by-4 matrix which rotates around the z-axis by the given angle.
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The rotation matrix.
+ * @memberOf module:twgl/m4
+ */
+function rotationZ(angleInRadians, dst) {
+ dst = dst || new MatType(16);
+
+ const c = Math.cos(angleInRadians);
+ const s = Math.sin(angleInRadians);
+
+ dst[ 0] = c;
+ dst[ 1] = s;
+ dst[ 2] = 0;
+ dst[ 3] = 0;
+ dst[ 4] = -s;
+ dst[ 5] = c;
+ dst[ 6] = 0;
+ dst[ 7] = 0;
+ dst[ 8] = 0;
+ dst[ 9] = 0;
+ dst[10] = 1;
+ dst[11] = 0;
+ dst[12] = 0;
+ dst[13] = 0;
+ dst[14] = 0;
+ dst[15] = 1;
+
+ return dst;
+}
+
+/**
+ * Rotates the given 4-by-4 matrix around the z-axis by the given
+ * angle.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The rotated matrix.
+ * @memberOf module:twgl/m4
+ */
+function rotateZ(m, angleInRadians, dst) {
+ dst = dst || new MatType(16);
+
+ const m00 = m[0 * 4 + 0];
+ const m01 = m[0 * 4 + 1];
+ const m02 = m[0 * 4 + 2];
+ const m03 = m[0 * 4 + 3];
+ const m10 = m[1 * 4 + 0];
+ const m11 = m[1 * 4 + 1];
+ const m12 = m[1 * 4 + 2];
+ const m13 = m[1 * 4 + 3];
+ const c = Math.cos(angleInRadians);
+ const s = Math.sin(angleInRadians);
+
+ dst[ 0] = c * m00 + s * m10;
+ dst[ 1] = c * m01 + s * m11;
+ dst[ 2] = c * m02 + s * m12;
+ dst[ 3] = c * m03 + s * m13;
+ dst[ 4] = c * m10 - s * m00;
+ dst[ 5] = c * m11 - s * m01;
+ dst[ 6] = c * m12 - s * m02;
+ dst[ 7] = c * m13 - s * m03;
+
+ if (m !== dst) {
+ dst[ 8] = m[ 8];
+ dst[ 9] = m[ 9];
+ dst[10] = m[10];
+ dst[11] = m[11];
+ dst[12] = m[12];
+ dst[13] = m[13];
+ dst[14] = m[14];
+ dst[15] = m[15];
+ }
+
+ return dst;
+}
+
+/**
+ * Creates a 4-by-4 matrix which rotates around the given axis by the given
+ * angle.
+ * @param {module:twgl/v3.Vec3} axis The axis
+ * about which to rotate.
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} A matrix which rotates angle radians
+ * around the axis.
+ * @memberOf module:twgl/m4
+ */
+function axisRotation(axis, angleInRadians, dst) {
+ dst = dst || new MatType(16);
+
+ let x = axis[0];
+ let y = axis[1];
+ let z = axis[2];
+ const n = Math.sqrt(x * x + y * y + z * z);
+ x /= n;
+ y /= n;
+ z /= n;
+ const xx = x * x;
+ const yy = y * y;
+ const zz = z * z;
+ const c = Math.cos(angleInRadians);
+ const s = Math.sin(angleInRadians);
+ const oneMinusCosine = 1 - c;
+
+ dst[ 0] = xx + (1 - xx) * c;
+ dst[ 1] = x * y * oneMinusCosine + z * s;
+ dst[ 2] = x * z * oneMinusCosine - y * s;
+ dst[ 3] = 0;
+ dst[ 4] = x * y * oneMinusCosine - z * s;
+ dst[ 5] = yy + (1 - yy) * c;
+ dst[ 6] = y * z * oneMinusCosine + x * s;
+ dst[ 7] = 0;
+ dst[ 8] = x * z * oneMinusCosine + y * s;
+ dst[ 9] = y * z * oneMinusCosine - x * s;
+ dst[10] = zz + (1 - zz) * c;
+ dst[11] = 0;
+ dst[12] = 0;
+ dst[13] = 0;
+ dst[14] = 0;
+ dst[15] = 1;
+
+ return dst;
+}
+
+/**
+ * Rotates the given 4-by-4 matrix around the given axis by the
+ * given angle.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/v3.Vec3} axis The axis
+ * about which to rotate.
+ * @param {number} angleInRadians The angle by which to rotate (in radians).
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The rotated matrix.
+ * @memberOf module:twgl/m4
+ */
+function axisRotate(m, axis, angleInRadians, dst) {
+ dst = dst || new MatType(16);
+
+ let x = axis[0];
+ let y = axis[1];
+ let z = axis[2];
+ const n = Math.sqrt(x * x + y * y + z * z);
+ x /= n;
+ y /= n;
+ z /= n;
+ const xx = x * x;
+ const yy = y * y;
+ const zz = z * z;
+ const c = Math.cos(angleInRadians);
+ const s = Math.sin(angleInRadians);
+ const oneMinusCosine = 1 - c;
+
+ const r00 = xx + (1 - xx) * c;
+ const r01 = x * y * oneMinusCosine + z * s;
+ const r02 = x * z * oneMinusCosine - y * s;
+ const r10 = x * y * oneMinusCosine - z * s;
+ const r11 = yy + (1 - yy) * c;
+ const r12 = y * z * oneMinusCosine + x * s;
+ const r20 = x * z * oneMinusCosine + y * s;
+ const r21 = y * z * oneMinusCosine - x * s;
+ const r22 = zz + (1 - zz) * c;
+
+ const m00 = m[0];
+ const m01 = m[1];
+ const m02 = m[2];
+ const m03 = m[3];
+ const m10 = m[4];
+ const m11 = m[5];
+ const m12 = m[6];
+ const m13 = m[7];
+ const m20 = m[8];
+ const m21 = m[9];
+ const m22 = m[10];
+ const m23 = m[11];
+
+ dst[ 0] = r00 * m00 + r01 * m10 + r02 * m20;
+ dst[ 1] = r00 * m01 + r01 * m11 + r02 * m21;
+ dst[ 2] = r00 * m02 + r01 * m12 + r02 * m22;
+ dst[ 3] = r00 * m03 + r01 * m13 + r02 * m23;
+ dst[ 4] = r10 * m00 + r11 * m10 + r12 * m20;
+ dst[ 5] = r10 * m01 + r11 * m11 + r12 * m21;
+ dst[ 6] = r10 * m02 + r11 * m12 + r12 * m22;
+ dst[ 7] = r10 * m03 + r11 * m13 + r12 * m23;
+ dst[ 8] = r20 * m00 + r21 * m10 + r22 * m20;
+ dst[ 9] = r20 * m01 + r21 * m11 + r22 * m21;
+ dst[10] = r20 * m02 + r21 * m12 + r22 * m22;
+ dst[11] = r20 * m03 + r21 * m13 + r22 * m23;
+
+ if (m !== dst) {
+ dst[12] = m[12];
+ dst[13] = m[13];
+ dst[14] = m[14];
+ dst[15] = m[15];
+ }
+
+ return dst;
+}
+
+/**
+ * Creates a 4-by-4 matrix which scales in each dimension by an amount given by
+ * the corresponding entry in the given vector; assumes the vector has three
+ * entries.
+ * @param {module:twgl/v3.Vec3} v A vector of
+ * three entries specifying the factor by which to scale in each dimension.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The scaling matrix.
+ * @memberOf module:twgl/m4
+ */
+function scaling(v, dst) {
+ dst = dst || new MatType(16);
+
+ dst[ 0] = v[0];
+ dst[ 1] = 0;
+ dst[ 2] = 0;
+ dst[ 3] = 0;
+ dst[ 4] = 0;
+ dst[ 5] = v[1];
+ dst[ 6] = 0;
+ dst[ 7] = 0;
+ dst[ 8] = 0;
+ dst[ 9] = 0;
+ dst[10] = v[2];
+ dst[11] = 0;
+ dst[12] = 0;
+ dst[13] = 0;
+ dst[14] = 0;
+ dst[15] = 1;
+
+ return dst;
+}
+
+/**
+ * Scales the given 4-by-4 matrix in each dimension by an amount
+ * given by the corresponding entry in the given vector; assumes the vector has
+ * three entries.
+ * @param {module:twgl/m4.Mat4} m The matrix to be modified.
+ * @param {module:twgl/v3.Vec3} v A vector of three entries specifying the
+ * factor by which to scale in each dimension.
+ * @param {module:twgl/m4.Mat4} [dst] matrix to hold result. If not passed a new one is created.
+ * @return {module:twgl/m4.Mat4} The scaled matrix.
+ * @memberOf module:twgl/m4
+ */
+function scale(m, v, dst) {
+ dst = dst || new MatType(16);
+
+ const v0 = v[0];
+ const v1 = v[1];
+ const v2 = v[2];
+
+ dst[ 0] = v0 * m[0 * 4 + 0];
+ dst[ 1] = v0 * m[0 * 4 + 1];
+ dst[ 2] = v0 * m[0 * 4 + 2];
+ dst[ 3] = v0 * m[0 * 4 + 3];
+ dst[ 4] = v1 * m[1 * 4 + 0];
+ dst[ 5] = v1 * m[1 * 4 + 1];
+ dst[ 6] = v1 * m[1 * 4 + 2];
+ dst[ 7] = v1 * m[1 * 4 + 3];
+ dst[ 8] = v2 * m[2 * 4 + 0];
+ dst[ 9] = v2 * m[2 * 4 + 1];
+ dst[10] = v2 * m[2 * 4 + 2];
+ dst[11] = v2 * m[2 * 4 + 3];
+
+ if (m !== dst) {
+ dst[12] = m[12];
+ dst[13] = m[13];
+ dst[14] = m[14];
+ dst[15] = m[15];
+ }
+
+ return dst;
+}
+
+/**
+ * Takes a 4-by-4 matrix and a vector with 3 entries,
+ * interprets the vector as a point, transforms that point by the matrix, and
+ * returns the result as a vector with 3 entries.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/v3.Vec3} v The point.
+ * @param {module:twgl/v3.Vec3} [dst] optional vec3 to store result. If not passed a new one is created.
+ * @return {module:twgl/v3.Vec3} The transformed point.
+ * @memberOf module:twgl/m4
+ */
+function transformPoint(m, v, dst) {
+ dst = dst || create();
+ const v0 = v[0];
+ const v1 = v[1];
+ const v2 = v[2];
+ const d = v0 * m[0 * 4 + 3] + v1 * m[1 * 4 + 3] + v2 * m[2 * 4 + 3] + m[3 * 4 + 3];
+
+ dst[0] = (v0 * m[0 * 4 + 0] + v1 * m[1 * 4 + 0] + v2 * m[2 * 4 + 0] + m[3 * 4 + 0]) / d;
+ dst[1] = (v0 * m[0 * 4 + 1] + v1 * m[1 * 4 + 1] + v2 * m[2 * 4 + 1] + m[3 * 4 + 1]) / d;
+ dst[2] = (v0 * m[0 * 4 + 2] + v1 * m[1 * 4 + 2] + v2 * m[2 * 4 + 2] + m[3 * 4 + 2]) / d;
+
+ return dst;
+}
+
+/**
+ * Takes a 4-by-4 matrix and a vector with 3 entries, interprets the vector as a
+ * direction, transforms that direction by the matrix, and returns the result;
+ * assumes the transformation of 3-dimensional space represented by the matrix
+ * is parallel-preserving, i.e. any combination of rotation, scaling and
+ * translation, but not a perspective distortion. Returns a vector with 3
+ * entries.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/v3.Vec3} v The direction.
+ * @param {module:twgl/v3.Vec3} [dst] optional Vec3 to store result. If not passed a new one is created.
+ * @return {module:twgl/v3.Vec3} The transformed direction.
+ * @memberOf module:twgl/m4
+ */
+function transformDirection(m, v, dst) {
+ dst = dst || create();
+
+ const v0 = v[0];
+ const v1 = v[1];
+ const v2 = v[2];
+
+ dst[0] = v0 * m[0 * 4 + 0] + v1 * m[1 * 4 + 0] + v2 * m[2 * 4 + 0];
+ dst[1] = v0 * m[0 * 4 + 1] + v1 * m[1 * 4 + 1] + v2 * m[2 * 4 + 1];
+ dst[2] = v0 * m[0 * 4 + 2] + v1 * m[1 * 4 + 2] + v2 * m[2 * 4 + 2];
+
+ return dst;
+}
+
+/**
+ * Takes a 4-by-4 matrix m and a vector v with 3 entries, interprets the vector
+ * as a normal to a surface, and computes a vector which is normal upon
+ * transforming that surface by the matrix. The effect of this function is the
+ * same as transforming v (as a direction) by the inverse-transpose of m. This
+ * function assumes the transformation of 3-dimensional space represented by the
+ * matrix is parallel-preserving, i.e. any combination of rotation, scaling and
+ * translation, but not a perspective distortion. Returns a vector with 3
+ * entries.
+ * @param {module:twgl/m4.Mat4} m The matrix.
+ * @param {module:twgl/v3.Vec3} v The normal.
+ * @param {module:twgl/v3.Vec3} [dst] The direction. If not passed a new one is created.
+ * @return {module:twgl/v3.Vec3} The transformed normal.
+ * @memberOf module:twgl/m4
+ */
+function transformNormal(m, v, dst) {
+ dst = dst || create();
+ const mi = inverse(m);
+ const v0 = v[0];
+ const v1 = v[1];
+ const v2 = v[2];
+
+ dst[0] = v0 * mi[0 * 4 + 0] + v1 * mi[0 * 4 + 1] + v2 * mi[0 * 4 + 2];
+ dst[1] = v0 * mi[1 * 4 + 0] + v1 * mi[1 * 4 + 1] + v2 * mi[1 * 4 + 2];
+ dst[2] = v0 * mi[2 * 4 + 0] + v1 * mi[2 * 4 + 1] + v2 * mi[2 * 4 + 2];
+
+ return dst;
+}
+
+var m4 = /*#__PURE__*/Object.freeze({
+ __proto__: null,
+ axisRotate: axisRotate,
+ axisRotation: axisRotation,
+ copy: copy$1,
+ frustum: frustum,
+ getAxis: getAxis,
+ getTranslation: getTranslation,
+ identity: identity,
+ inverse: inverse,
+ lookAt: lookAt,
+ multiply: multiply$1,
+ negate: negate$1,
+ ortho: ortho,
+ perspective: perspective,
+ rotateX: rotateX,
+ rotateY: rotateY,
+ rotateZ: rotateZ,
+ rotationX: rotationX,
+ rotationY: rotationY,
+ rotationZ: rotationZ,
+ scale: scale,
+ scaling: scaling,
+ setAxis: setAxis,
+ setDefaultType: setDefaultType$1,
+ setTranslation: setTranslation,
+ transformDirection: transformDirection,
+ transformNormal: transformNormal,
+ transformPoint: transformPoint,
+ translate: translate,
+ translation: translation,
+ transpose: transpose
+});
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/* DataType */
+const BYTE = 0x1400;
+const UNSIGNED_BYTE = 0x1401;
+const SHORT = 0x1402;
+const UNSIGNED_SHORT = 0x1403;
+const INT = 0x1404;
+const UNSIGNED_INT = 0x1405;
+const FLOAT = 0x1406;
+const UNSIGNED_SHORT_4_4_4_4 = 0x8033;
+const UNSIGNED_SHORT_5_5_5_1 = 0x8034;
+const UNSIGNED_SHORT_5_6_5 = 0x8363;
+const HALF_FLOAT = 0x140B;
+const UNSIGNED_INT_2_10_10_10_REV = 0x8368;
+const UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B;
+const UNSIGNED_INT_5_9_9_9_REV = 0x8C3E;
+const FLOAT_32_UNSIGNED_INT_24_8_REV = 0x8DAD;
+const UNSIGNED_INT_24_8 = 0x84FA;
+
+const glTypeToTypedArray = {};
+{
+ const tt = glTypeToTypedArray;
+ tt[BYTE] = Int8Array;
+ tt[UNSIGNED_BYTE] = Uint8Array;
+ tt[SHORT] = Int16Array;
+ tt[UNSIGNED_SHORT] = Uint16Array;
+ tt[INT] = Int32Array;
+ tt[UNSIGNED_INT] = Uint32Array;
+ tt[FLOAT] = Float32Array;
+ tt[UNSIGNED_SHORT_4_4_4_4] = Uint16Array;
+ tt[UNSIGNED_SHORT_5_5_5_1] = Uint16Array;
+ tt[UNSIGNED_SHORT_5_6_5] = Uint16Array;
+ tt[HALF_FLOAT] = Uint16Array;
+ tt[UNSIGNED_INT_2_10_10_10_REV] = Uint32Array;
+ tt[UNSIGNED_INT_10F_11F_11F_REV] = Uint32Array;
+ tt[UNSIGNED_INT_5_9_9_9_REV] = Uint32Array;
+ tt[FLOAT_32_UNSIGNED_INT_24_8_REV] = Uint32Array;
+ tt[UNSIGNED_INT_24_8] = Uint32Array;
+}
+
+/**
+ * Get the GL type for a typedArray
+ * @param {ArrayBufferView} typedArray a typedArray
+ * @return {number} the GL type for array. For example pass in an `Int8Array` and `gl.BYTE` will
+ * be returned. Pass in a `Uint32Array` and `gl.UNSIGNED_INT` will be returned
+ * @memberOf module:twgl/typedArray
+ */
+function getGLTypeForTypedArray(typedArray) {
+ if (typedArray instanceof Int8Array) { return BYTE; } // eslint-disable-line
+ if (typedArray instanceof Uint8Array) { return UNSIGNED_BYTE; } // eslint-disable-line
+ if (typedArray instanceof Uint8ClampedArray) { return UNSIGNED_BYTE; } // eslint-disable-line
+ if (typedArray instanceof Int16Array) { return SHORT; } // eslint-disable-line
+ if (typedArray instanceof Uint16Array) { return UNSIGNED_SHORT; } // eslint-disable-line
+ if (typedArray instanceof Int32Array) { return INT; } // eslint-disable-line
+ if (typedArray instanceof Uint32Array) { return UNSIGNED_INT; } // eslint-disable-line
+ if (typedArray instanceof Float32Array) { return FLOAT; } // eslint-disable-line
+ throw new Error('unsupported typed array type');
+}
+
+/**
+ * Get the GL type for a typedArray type
+ * @param {ArrayBufferView} typedArrayType a typedArray constructor
+ * @return {number} the GL type for type. For example pass in `Int8Array` and `gl.BYTE` will
+ * be returned. Pass in `Uint32Array` and `gl.UNSIGNED_INT` will be returned
+ * @memberOf module:twgl/typedArray
+ */
+function getGLTypeForTypedArrayType(typedArrayType) {
+ if (typedArrayType === Int8Array) { return BYTE; } // eslint-disable-line
+ if (typedArrayType === Uint8Array) { return UNSIGNED_BYTE; } // eslint-disable-line
+ if (typedArrayType === Uint8ClampedArray) { return UNSIGNED_BYTE; } // eslint-disable-line
+ if (typedArrayType === Int16Array) { return SHORT; } // eslint-disable-line
+ if (typedArrayType === Uint16Array) { return UNSIGNED_SHORT; } // eslint-disable-line
+ if (typedArrayType === Int32Array) { return INT; } // eslint-disable-line
+ if (typedArrayType === Uint32Array) { return UNSIGNED_INT; } // eslint-disable-line
+ if (typedArrayType === Float32Array) { return FLOAT; } // eslint-disable-line
+ throw new Error('unsupported typed array type');
+}
+
+/**
+ * Get the typed array constructor for a given GL type
+ * @param {number} type the GL type. (eg: `gl.UNSIGNED_INT`)
+ * @return {function} the constructor for a the corresponding typed array. (eg. `Uint32Array`).
+ * @memberOf module:twgl/typedArray
+ */
+function getTypedArrayTypeForGLType(type) {
+ const CTOR = glTypeToTypedArray[type];
+ if (!CTOR) {
+ throw new Error('unknown gl type');
+ }
+ return CTOR;
+}
+
+const isArrayBuffer = typeof SharedArrayBuffer !== 'undefined'
+ ? function isArrayBufferOrSharedArrayBuffer(a) {
+ return a && a.buffer && (a.buffer instanceof ArrayBuffer || a.buffer instanceof SharedArrayBuffer);
+ }
+ : function isArrayBuffer(a) {
+ return a && a.buffer && a.buffer instanceof ArrayBuffer;
+ };
+
+var typedarrays = /*#__PURE__*/Object.freeze({
+ __proto__: null,
+ getGLTypeForTypedArray: getGLTypeForTypedArray,
+ getGLTypeForTypedArrayType: getGLTypeForTypedArrayType,
+ getTypedArrayTypeForGLType: getTypedArrayTypeForGLType,
+ isArrayBuffer: isArrayBuffer
+});
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/* eslint no-console: "off" */
+
+/**
+ * Copy named properties
+ *
+ * @param {string[]} names names of properties to copy
+ * @param {object} src object to copy properties from
+ * @param {object} dst object to copy properties to
+ * @private
+ */
+function copyNamedProperties(names, src, dst) {
+ names.forEach(function(name) {
+ const value = src[name];
+ if (value !== undefined) {
+ dst[name] = value;
+ }
+ });
+}
+
+/**
+ * Copies properties from source to dest only if a matching key is in dest
+ *
+ * @param {Object.} src the source
+ * @param {Object.} dst the dest
+ * @private
+ */
+function copyExistingProperties(src, dst) {
+ Object.keys(dst).forEach(function(key) {
+ if (dst.hasOwnProperty(key) && src.hasOwnProperty(key)) { /* eslint no-prototype-builtins: 0 */
+ dst[key] = src[key];
+ }
+ });
+}
+
+function error(...args) {
+ console.error(...args);
+}
+
+function warn(...args) {
+ console.warn(...args);
+}
+
+function isBuffer(gl, t) {
+ return typeof WebGLBuffer !== 'undefined' && t instanceof WebGLBuffer;
+}
+
+function isRenderbuffer(gl, t) {
+ return typeof WebGLRenderbuffer !== 'undefined' && t instanceof WebGLRenderbuffer;
+}
+
+function isShader(gl, t) {
+ return typeof WebGLShader !== 'undefined' && t instanceof WebGLShader;
+}
+
+function isTexture(gl, t) {
+ return typeof WebGLTexture !== 'undefined' && t instanceof WebGLTexture;
+}
+
+function isSampler(gl, t) {
+ return typeof WebGLSampler !== 'undefined' && t instanceof WebGLSampler;
+}
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+const STATIC_DRAW = 0x88e4;
+const ARRAY_BUFFER = 0x8892;
+const ELEMENT_ARRAY_BUFFER = 0x8893;
+const BUFFER_SIZE = 0x8764;
+
+const BYTE$1 = 0x1400;
+const UNSIGNED_BYTE$1 = 0x1401;
+const SHORT$1 = 0x1402;
+const UNSIGNED_SHORT$1 = 0x1403;
+const INT$1 = 0x1404;
+const UNSIGNED_INT$1 = 0x1405;
+const FLOAT$1 = 0x1406;
+const defaults = {
+ attribPrefix: "",
+};
+
+/**
+ * Sets the default attrib prefix
+ *
+ * When writing shaders I prefer to name attributes with `a_`, uniforms with `u_` and varyings with `v_`
+ * as it makes it clear where they came from. But, when building geometry I prefer using un-prefixed names.
+ *
+ * In other words I'll create arrays of geometry like this
+ *
+ * var arrays = {
+ * position: ...
+ * normal: ...
+ * texcoord: ...
+ * };
+ *
+ * But need those mapped to attributes and my attributes start with `a_`.
+ *
+ * @deprecated see {@link module:twgl.setDefaults}
+ * @param {string} prefix prefix for attribs
+ * @memberOf module:twgl/attributes
+ */
+function setAttributePrefix(prefix) {
+ defaults.attribPrefix = prefix;
+}
+
+function setDefaults(newDefaults) {
+ copyExistingProperties(newDefaults, defaults);
+}
+
+function setBufferFromTypedArray(gl, type, buffer, array, drawType) {
+ gl.bindBuffer(type, buffer);
+ gl.bufferData(type, array, drawType || STATIC_DRAW);
+}
+
+/**
+ * Given typed array creates a WebGLBuffer and copies the typed array
+ * into it.
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @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
+ * @param {number} [type] the GL bind type for the buffer. Default = `gl.ARRAY_BUFFER`.
+ * @param {number} [drawType] the GL draw type for the buffer. Default = 'gl.STATIC_DRAW`.
+ * @return {WebGLBuffer} the created WebGLBuffer
+ * @memberOf module:twgl/attributes
+ */
+function createBufferFromTypedArray(gl, typedArray, type, drawType) {
+ if (isBuffer(gl, typedArray)) {
+ return typedArray;
+ }
+ type = type || ARRAY_BUFFER;
+ const buffer = gl.createBuffer();
+ setBufferFromTypedArray(gl, type, buffer, typedArray, drawType);
+ return buffer;
+}
+
+function isIndices(name) {
+ return name === "indices";
+}
+
+// This is really just a guess. Though I can't really imagine using
+// anything else? Maybe for some compression?
+function getNormalizationForTypedArray(typedArray) {
+ if (typedArray instanceof Int8Array) { return true; } // eslint-disable-line
+ if (typedArray instanceof Uint8Array) { return true; } // eslint-disable-line
+ return false;
+}
+
+// This is really just a guess. Though I can't really imagine using
+// anything else? Maybe for some compression?
+function getNormalizationForTypedArrayType(typedArrayType) {
+ if (typedArrayType === Int8Array) { return true; } // eslint-disable-line
+ if (typedArrayType === Uint8Array) { return true; } // eslint-disable-line
+ return false;
+}
+
+function getArray(array) {
+ return array.length ? array : array.data;
+}
+
+const texcoordRE = /coord|texture/i;
+const colorRE = /color|colour/i;
+
+function guessNumComponentsFromName(name, length) {
+ let numComponents;
+ if (texcoordRE.test(name)) {
+ numComponents = 2;
+ } else if (colorRE.test(name)) {
+ numComponents = 4;
+ } else {
+ numComponents = 3; // position, normals, indices ...
+ }
+
+ if (length % numComponents > 0) {
+ throw new Error(`Can not guess numComponents for attribute '${name}'. Tried ${numComponents} but ${length} values is not evenly divisible by ${numComponents}. You should specify it.`);
+ }
+
+ return numComponents;
+}
+
+function getNumComponents(array, arrayName) {
+ return array.numComponents || array.size || guessNumComponentsFromName(arrayName, getArray(array).length);
+}
+
+function makeTypedArray(array, name) {
+ if (isArrayBuffer(array)) {
+ return array;
+ }
+
+ if (isArrayBuffer(array.data)) {
+ return array.data;
+ }
+
+ if (Array.isArray(array)) {
+ array = {
+ data: array,
+ };
+ }
+
+ let Type = array.type;
+ if (!Type) {
+ if (isIndices(name)) {
+ Type = Uint16Array;
+ } else {
+ Type = Float32Array;
+ }
+ }
+ return new Type(array.data);
+}
+
+/**
+ * The info for an attribute. This is effectively just the arguments to `gl.vertexAttribPointer` plus the WebGLBuffer
+ * for the attribute.
+ *
+ * @typedef {Object} AttribInfo
+ * @property {number[]|ArrayBufferView} [value] a constant value for the attribute. Note: if this is set the attribute will be
+ * disabled and set to this constant value and all other values will be ignored.
+ * @property {number} [numComponents] the number of components for this attribute.
+ * @property {number} [size] synonym for `numComponents`.
+ * @property {number} [type] the type of the attribute (eg. `gl.FLOAT`, `gl.UNSIGNED_BYTE`, etc...) Default = `gl.FLOAT`
+ * @property {boolean} [normalize] whether or not to normalize the data. Default = false
+ * @property {number} [offset] offset into buffer in bytes. Default = 0
+ * @property {number} [stride] the stride in bytes per element. Default = 0
+ * @property {number} [divisor] the divisor in instances. Default = undefined. Note: undefined = don't call gl.vertexAttribDivisor
+ * where as anything else = do call it with this value
+ * @property {WebGLBuffer} buffer the buffer that contains the data for this attribute
+ * @property {number} [drawType] the draw type passed to gl.bufferData. Default = gl.STATIC_DRAW
+ * @memberOf module:twgl
+ */
+
+/**
+ * Use this type of array spec when TWGL can't guess the type or number of components of an array
+ * @typedef {Object} FullArraySpec
+ * @property {number[]|ArrayBufferView} [value] a constant value for the attribute. Note: if this is set the attribute will be
+ * disabled and set to this constant value and all other values will be ignored.
+ * @property {(number|number[]|ArrayBufferView)} data The data of the array. A number alone becomes the number of elements of type.
+ * @property {number} [numComponents] number of components for `vertexAttribPointer`. Default is based on the name of the array.
+ * If `coord` is in the name assumes `numComponents = 2`.
+ * If `color` is in the name assumes `numComponents = 4`.
+ * otherwise assumes `numComponents = 3`
+ * @property {constructor} [type] type. This is only used if `data` is a JavaScript array. It is the constructor for the typedarray. (eg. `Uint8Array`).
+ * For example if you want colors in a `Uint8Array` you might have a `FullArraySpec` like `{ type: Uint8Array, data: [255,0,255,255, ...], }`.
+ * @property {number} [size] synonym for `numComponents`.
+ * @property {boolean} [normalize] normalize for `vertexAttribPointer`. Default is true if type is `Int8Array` or `Uint8Array` otherwise false.
+ * @property {number} [stride] stride for `vertexAttribPointer`. Default = 0
+ * @property {number} [offset] offset for `vertexAttribPointer`. Default = 0
+ * @property {number} [divisor] divisor for `vertexAttribDivisor`. Default = undefined. Note: undefined = don't call gl.vertexAttribDivisor
+ * where as anything else = do call it with this value
+ * @property {string} [attrib] name of attribute this array maps to. Defaults to same name as array prefixed by the default attribPrefix.
+ * @property {string} [name] synonym for `attrib`.
+ * @property {string} [attribName] synonym for `attrib`.
+ * @property {WebGLBuffer} [buffer] Buffer to use for this attribute. This lets you use your own buffer
+ * but you will need to supply `numComponents` and `type`. You can effectively pass an `AttribInfo`
+ * to provide this. Example:
+ *
+ * const bufferInfo1 = twgl.createBufferInfoFromArrays(gl, {
+ * position: [1, 2, 3, ... ],
+ * });
+ * const bufferInfo2 = twgl.createBufferInfoFromArrays(gl, {
+ * position: bufferInfo1.attribs.position, // use the same buffer from bufferInfo1
+ * });
+ *
+ * @memberOf module:twgl
+ */
+
+/**
+ * An individual array in {@link module:twgl.Arrays}
+ *
+ * When passed to {@link module:twgl.createBufferInfoFromArrays} if an ArraySpec is `number[]` or `ArrayBufferView`
+ * the types will be guessed based on the name. `indices` will be `Uint16Array`, everything else will
+ * be `Float32Array`. If an ArraySpec is a number it's the number of floats for an empty (zeroed) buffer.
+ *
+ * @typedef {(number|number[]|ArrayBufferView|module:twgl.FullArraySpec)} ArraySpec
+ * @memberOf module:twgl
+ */
+
+/**
+ * This is a JavaScript object of arrays by name. The names should match your shader's attributes. If your
+ * attributes have a common prefix you can specify it by calling {@link module:twgl.setAttributePrefix}.
+ *
+ * Bare JavaScript Arrays
+ *
+ * var arrays = {
+ * position: [-1, 1, 0],
+ * normal: [0, 1, 0],
+ * ...
+ * }
+ *
+ * Bare TypedArrays
+ *
+ * var arrays = {
+ * position: new Float32Array([-1, 1, 0]),
+ * color: new Uint8Array([255, 128, 64, 255]),
+ * ...
+ * }
+ *
+ * * Will guess at `numComponents` if not specified based on name.
+ *
+ * If `coord` is in the name assumes `numComponents = 2`
+ *
+ * If `color` is in the name assumes `numComponents = 4`
+ *
+ * otherwise assumes `numComponents = 3`
+ *
+ * Objects with various fields. See {@link module:twgl.FullArraySpec}.
+ *
+ * var arrays = {
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
+ * normal: { numComponents: 3, data: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], },
+ * indices: { numComponents: 3, data: [0, 1, 2, 1, 2, 3], },
+ * };
+ *
+ * @typedef {Object.} Arrays
+ * @memberOf module:twgl
+ */
+
+
+/**
+ * Creates a set of attribute data and WebGLBuffers from set of arrays
+ *
+ * Given
+ *
+ * var arrays = {
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
+ * normal: { numComponents: 3, data: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], },
+ * color: { numComponents: 4, data: [255, 255, 255, 255, 255, 0, 0, 255, 0, 0, 255, 255], type: Uint8Array, },
+ * indices: { numComponents: 3, data: [0, 1, 2, 1, 2, 3], },
+ * };
+ *
+ * returns something like
+ *
+ * var attribs = {
+ * position: { numComponents: 3, type: gl.FLOAT, normalize: false, buffer: WebGLBuffer, },
+ * texcoord: { numComponents: 2, type: gl.FLOAT, normalize: false, buffer: WebGLBuffer, },
+ * normal: { numComponents: 3, type: gl.FLOAT, normalize: false, buffer: WebGLBuffer, },
+ * color: { numComponents: 4, type: gl.UNSIGNED_BYTE, normalize: true, buffer: WebGLBuffer, },
+ * };
+ *
+ * notes:
+ *
+ * * Arrays can take various forms
+ *
+ * Bare JavaScript Arrays
+ *
+ * var arrays = {
+ * position: [-1, 1, 0],
+ * normal: [0, 1, 0],
+ * ...
+ * }
+ *
+ * Bare TypedArrays
+ *
+ * var arrays = {
+ * position: new Float32Array([-1, 1, 0]),
+ * color: new Uint8Array([255, 128, 64, 255]),
+ * ...
+ * }
+ *
+ * * Will guess at `numComponents` if not specified based on name.
+ *
+ * If `coord` is in the name assumes `numComponents = 2`
+ *
+ * If `color` is in the name assumes `numComponents = 4`
+ *
+ * otherwise assumes `numComponents = 3`
+ *
+ * @param {WebGLRenderingContext} gl The webgl rendering context.
+ * @param {module:twgl.Arrays} arrays The arrays
+ * @param {module:twgl.BufferInfo} [srcBufferInfo] a BufferInfo to copy from
+ * This lets you share buffers. Any arrays you supply will override
+ * the buffers from srcBufferInfo.
+ * @return {Object.} the attribs
+ * @memberOf module:twgl/attributes
+ */
+function createAttribsFromArrays(gl, arrays) {
+ const attribs = {};
+ Object.keys(arrays).forEach(function(arrayName) {
+ if (!isIndices(arrayName)) {
+ const array = arrays[arrayName];
+ const attribName = array.attrib || array.name || array.attribName || (defaults.attribPrefix + arrayName);
+ if (array.value) {
+ if (!Array.isArray(array.value) && !isArrayBuffer(array.value)) {
+ throw new Error('array.value is not array or typedarray');
+ }
+ attribs[attribName] = {
+ value: array.value,
+ };
+ } else {
+ let buffer;
+ let type;
+ let normalization;
+ let numComponents;
+ if (array.buffer && array.buffer instanceof WebGLBuffer) {
+ buffer = array.buffer;
+ numComponents = array.numComponents || array.size;
+ type = array.type;
+ normalization = array.normalize;
+ } else if (typeof array === "number" || typeof array.data === "number") {
+ const numValues = array.data || array;
+ const arrayType = array.type || Float32Array;
+ const numBytes = numValues * arrayType.BYTES_PER_ELEMENT;
+ type = getGLTypeForTypedArrayType(arrayType);
+ normalization = array.normalize !== undefined ? array.normalize : getNormalizationForTypedArrayType(arrayType);
+ numComponents = array.numComponents || array.size || guessNumComponentsFromName(arrayName, numValues);
+ buffer = gl.createBuffer();
+ gl.bindBuffer(ARRAY_BUFFER, buffer);
+ gl.bufferData(ARRAY_BUFFER, numBytes, array.drawType || STATIC_DRAW);
+ } else {
+ const typedArray = makeTypedArray(array, arrayName);
+ buffer = createBufferFromTypedArray(gl, typedArray, undefined, array.drawType);
+ type = getGLTypeForTypedArray(typedArray);
+ normalization = array.normalize !== undefined ? array.normalize : getNormalizationForTypedArray(typedArray);
+ numComponents = getNumComponents(array, arrayName);
+ }
+ attribs[attribName] = {
+ buffer: buffer,
+ numComponents: numComponents,
+ type: type,
+ normalize: normalization,
+ stride: array.stride || 0,
+ offset: array.offset || 0,
+ divisor: array.divisor === undefined ? undefined : array.divisor,
+ drawType: array.drawType,
+ };
+ }
+ }
+ });
+ gl.bindBuffer(ARRAY_BUFFER, null);
+ return attribs;
+}
+
+/**
+ * Sets the contents of a buffer attached to an attribInfo
+ *
+ * This is helper function to dynamically update a buffer.
+ *
+ * Let's say you make a bufferInfo
+ *
+ * var arrays = {
+ * position: new Float32Array([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]),
+ * texcoord: new Float32Array([0, 0, 0, 1, 1, 0, 1, 1]),
+ * normal: new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]),
+ * indices: new Uint16Array([0, 1, 2, 1, 2, 3]),
+ * };
+ * var bufferInfo = twgl.createBufferInfoFromArrays(gl, arrays);
+ *
+ * And you want to dynamically update the positions. You could do this
+ *
+ * // assuming arrays.position has already been updated with new data.
+ * twgl.setAttribInfoBufferFromArray(gl, bufferInfo.attribs.position, arrays.position);
+ *
+ * @param {WebGLRenderingContext} gl
+ * @param {AttribInfo} attribInfo The attribInfo who's buffer contents to set. NOTE: If you have an attribute prefix
+ * the name of the attribute will include the prefix.
+ * @param {ArraySpec} array Note: it is arguably inefficient to pass in anything but a typed array because anything
+ * else will have to be converted to a typed array before it can be used by WebGL. During init time that
+ * inefficiency is usually not important but if you're updating data dynamically best to be efficient.
+ * @param {number} [offset] an optional offset into the buffer. This is only an offset into the WebGL buffer
+ * not the array. To pass in an offset into the array itself use a typed array and create an `ArrayBufferView`
+ * for the portion of the array you want to use.
+ *
+ * var someArray = new Float32Array(1000); // an array with 1000 floats
+ * var someSubArray = new Float32Array(someArray.buffer, offsetInBytes, sizeInUnits); // a view into someArray
+ *
+ * Now you can pass `someSubArray` into setAttribInfoBufferFromArray`
+ * @memberOf module:twgl/attributes
+ */
+function setAttribInfoBufferFromArray(gl, attribInfo, array, offset) {
+ array = makeTypedArray(array);
+ if (offset !== undefined) {
+ gl.bindBuffer(ARRAY_BUFFER, attribInfo.buffer);
+ gl.bufferSubData(ARRAY_BUFFER, offset, array);
+ } else {
+ setBufferFromTypedArray(gl, ARRAY_BUFFER, attribInfo.buffer, array, attribInfo.drawType);
+ }
+}
+
+function getBytesPerValueForGLType(gl, type) {
+ if (type === BYTE$1) return 1; // eslint-disable-line
+ if (type === UNSIGNED_BYTE$1) return 1; // eslint-disable-line
+ if (type === SHORT$1) return 2; // eslint-disable-line
+ if (type === UNSIGNED_SHORT$1) return 2; // eslint-disable-line
+ if (type === INT$1) return 4; // eslint-disable-line
+ if (type === UNSIGNED_INT$1) return 4; // eslint-disable-line
+ if (type === FLOAT$1) return 4; // eslint-disable-line
+ return 0;
+}
+
+// Tries to get the number of elements from a set of arrays.
+const positionKeys = ['position', 'positions', 'a_position'];
+function getNumElementsFromNonIndexedArrays(arrays) {
+ let key;
+ let ii;
+ for (ii = 0; ii < positionKeys.length; ++ii) {
+ key = positionKeys[ii];
+ if (key in arrays) {
+ break;
+ }
+ }
+ if (ii === positionKeys.length) {
+ key = Object.keys(arrays)[0];
+ }
+ const array = arrays[key];
+ const length = getArray(array).length;
+ const numComponents = getNumComponents(array, key);
+ const numElements = length / numComponents;
+ if (length % numComponents > 0) {
+ throw new Error(`numComponents ${numComponents} not correct for length ${length}`);
+ }
+ return numElements;
+}
+
+function getNumElementsFromAttributes(gl, attribs) {
+ let key;
+ let ii;
+ for (ii = 0; ii < positionKeys.length; ++ii) {
+ key = positionKeys[ii];
+ if (key in attribs) {
+ break;
+ }
+ key = defaults.attribPrefix + key;
+ if (key in attribs) {
+ break;
+ }
+ }
+ if (ii === positionKeys.length) {
+ key = Object.keys(attribs)[0];
+ }
+ const attrib = attribs[key];
+ gl.bindBuffer(ARRAY_BUFFER, attrib.buffer);
+ const numBytes = gl.getBufferParameter(ARRAY_BUFFER, BUFFER_SIZE);
+ gl.bindBuffer(ARRAY_BUFFER, null);
+
+ const bytesPerValue = getBytesPerValueForGLType(gl, attrib.type);
+ const totalElements = numBytes / bytesPerValue;
+ const numComponents = attrib.numComponents || attrib.size;
+ // TODO: check stride
+ const numElements = totalElements / numComponents;
+ if (numElements % 1 !== 0) {
+ throw new Error(`numComponents ${numComponents} not correct for length ${length}`);
+ }
+ return numElements;
+}
+
+/**
+ * @typedef {Object} BufferInfo
+ * @property {number} numElements The number of elements to pass to `gl.drawArrays` or `gl.drawElements`.
+ * @property {number} [elementType] The type of indices `UNSIGNED_BYTE`, `UNSIGNED_SHORT` etc..
+ * @property {WebGLBuffer} [indices] The indices `ELEMENT_ARRAY_BUFFER` if any indices exist.
+ * @property {Object.} [attribs] The attribs appropriate to call `setAttributes`
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a BufferInfo from an object of arrays.
+ *
+ * This can be passed to {@link module:twgl.setBuffersAndAttributes} and to
+ * {@link module:twgl:drawBufferInfo}.
+ *
+ * Given an object like
+ *
+ * var arrays = {
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
+ * normal: { numComponents: 3, data: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], },
+ * indices: { numComponents: 3, data: [0, 1, 2, 1, 2, 3], },
+ * };
+ *
+ * Creates an BufferInfo like this
+ *
+ * bufferInfo = {
+ * numElements: 4, // or whatever the number of elements is
+ * indices: WebGLBuffer, // this property will not exist if there are no indices
+ * attribs: {
+ * position: { buffer: WebGLBuffer, numComponents: 3, },
+ * normal: { buffer: WebGLBuffer, numComponents: 3, },
+ * texcoord: { buffer: WebGLBuffer, numComponents: 2, },
+ * },
+ * };
+ *
+ * The properties of arrays can be JavaScript arrays in which case the number of components
+ * will be guessed.
+ *
+ * var arrays = {
+ * position: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0],
+ * texcoord: [0, 0, 0, 1, 1, 0, 1, 1],
+ * normal: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],
+ * indices: [0, 1, 2, 1, 2, 3],
+ * };
+ *
+ * They can also be TypedArrays
+ *
+ * var arrays = {
+ * position: new Float32Array([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]),
+ * texcoord: new Float32Array([0, 0, 0, 1, 1, 0, 1, 1]),
+ * normal: new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]),
+ * indices: new Uint16Array([0, 1, 2, 1, 2, 3]),
+ * };
+ *
+ * Or AugmentedTypedArrays
+ *
+ * var positions = createAugmentedTypedArray(3, 4);
+ * var texcoords = createAugmentedTypedArray(2, 4);
+ * var normals = createAugmentedTypedArray(3, 4);
+ * var indices = createAugmentedTypedArray(3, 2, Uint16Array);
+ *
+ * positions.push([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]);
+ * texcoords.push([0, 0, 0, 1, 1, 0, 1, 1]);
+ * normals.push([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]);
+ * indices.push([0, 1, 2, 1, 2, 3]);
+ *
+ * var arrays = {
+ * position: positions,
+ * texcoord: texcoords,
+ * normal: normals,
+ * indices: indices,
+ * };
+ *
+ * For the last example it is equivalent to
+ *
+ * var bufferInfo = {
+ * attribs: {
+ * position: { numComponents: 3, buffer: gl.createBuffer(), },
+ * texcoord: { numComponents: 2, buffer: gl.createBuffer(), },
+ * normal: { numComponents: 3, buffer: gl.createBuffer(), },
+ * },
+ * indices: gl.createBuffer(),
+ * numElements: 6,
+ * };
+ *
+ * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.position.buffer);
+ * gl.bufferData(gl.ARRAY_BUFFER, arrays.position, gl.STATIC_DRAW);
+ * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.texcoord.buffer);
+ * gl.bufferData(gl.ARRAY_BUFFER, arrays.texcoord, gl.STATIC_DRAW);
+ * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.normal.buffer);
+ * gl.bufferData(gl.ARRAY_BUFFER, arrays.normal, gl.STATIC_DRAW);
+ * gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, bufferInfo.indices);
+ * gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, arrays.indices, gl.STATIC_DRAW);
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @param {module:twgl.Arrays} arrays Your data
+ * @param {module:twgl.BufferInfo} [srcBufferInfo] An existing
+ * buffer info to start from. WebGLBuffers etc specified
+ * in the srcBufferInfo will be used in a new BufferInfo
+ * with any arrays specified overriding the ones in
+ * srcBufferInfo.
+ * @return {module:twgl.BufferInfo} A BufferInfo
+ * @memberOf module:twgl/attributes
+ */
+function createBufferInfoFromArrays(gl, arrays, srcBufferInfo) {
+ const newAttribs = createAttribsFromArrays(gl, arrays);
+ const bufferInfo = Object.assign({}, srcBufferInfo ? srcBufferInfo : {});
+ bufferInfo.attribs = Object.assign({}, srcBufferInfo ? srcBufferInfo.attribs : {}, newAttribs);
+ const indices = arrays.indices;
+ if (indices) {
+ const newIndices = makeTypedArray(indices, "indices");
+ bufferInfo.indices = createBufferFromTypedArray(gl, newIndices, ELEMENT_ARRAY_BUFFER);
+ bufferInfo.numElements = newIndices.length;
+ bufferInfo.elementType = getGLTypeForTypedArray(newIndices);
+ } else if (!bufferInfo.numElements) {
+ bufferInfo.numElements = getNumElementsFromAttributes(gl, bufferInfo.attribs);
+ }
+
+ return bufferInfo;
+}
+
+/**
+ * Creates a buffer from an array, typed array, or array spec
+ *
+ * Given something like this
+ *
+ * [1, 2, 3],
+ *
+ * or
+ *
+ * new Uint16Array([1,2,3]);
+ *
+ * or
+ *
+ * {
+ * data: [1, 2, 3],
+ * type: Uint8Array,
+ * }
+ *
+ * returns a WebGLBuffer that contains the given data.
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext.
+ * @param {module:twgl.ArraySpec} array an array, typed array, or array spec.
+ * @param {string} arrayName name of array. Used to guess the type if type can not be derived otherwise.
+ * @return {WebGLBuffer} a WebGLBuffer containing the data in array.
+ * @memberOf module:twgl/attributes
+ */
+function createBufferFromArray(gl, array, arrayName) {
+ const type = arrayName === "indices" ? ELEMENT_ARRAY_BUFFER : ARRAY_BUFFER;
+ const typedArray = makeTypedArray(array, arrayName);
+ return createBufferFromTypedArray(gl, typedArray, type);
+}
+
+/**
+ * Creates buffers from arrays or typed arrays
+ *
+ * Given something like this
+ *
+ * var arrays = {
+ * positions: [1, 2, 3],
+ * normals: [0, 0, 1],
+ * }
+ *
+ * returns something like
+ *
+ * buffers = {
+ * positions: WebGLBuffer,
+ * normals: WebGLBuffer,
+ * }
+ *
+ * If the buffer is named 'indices' it will be made an ELEMENT_ARRAY_BUFFER.
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext.
+ * @param {module:twgl.Arrays} arrays
+ * @return {Object} returns an object with one WebGLBuffer per array
+ * @memberOf module:twgl/attributes
+ */
+function createBuffersFromArrays(gl, arrays) {
+ const buffers = { };
+ Object.keys(arrays).forEach(function(key) {
+ buffers[key] = createBufferFromArray(gl, arrays[key], key);
+ });
+
+ // Ugh!
+ if (arrays.indices) {
+ buffers.numElements = arrays.indices.length;
+ buffers.elementType = getGLTypeForTypedArray(makeTypedArray(arrays.indices));
+ } else {
+ buffers.numElements = getNumElementsFromNonIndexedArrays(arrays);
+ }
+
+ return buffers;
+}
+
+var attributes = /*#__PURE__*/Object.freeze({
+ __proto__: null,
+ createAttribsFromArrays: createAttribsFromArrays,
+ createBuffersFromArrays: createBuffersFromArrays,
+ createBufferFromArray: createBufferFromArray,
+ createBufferFromTypedArray: createBufferFromTypedArray,
+ createBufferInfoFromArrays: createBufferInfoFromArrays,
+ setAttribInfoBufferFromArray: setAttribInfoBufferFromArray,
+ setAttributePrefix: setAttributePrefix,
+ setAttributeDefaults_: setDefaults,
+ getNumComponents_: getNumComponents,
+ getArray_: getArray
+});
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+const getArray$1 = getArray; // eslint-disable-line
+const getNumComponents$1 = getNumComponents; // eslint-disable-line
+
+/**
+ * @typedef {(Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array)} TypedArray
+ */
+
+/**
+ * Add `push` to a typed array. It just keeps a 'cursor'
+ * and allows use to `push` values into the array so we
+ * don't have to manually compute offsets
+ * @param {TypedArray} typedArray TypedArray to augment
+ * @param {number} numComponents number of components.
+ * @private
+ */
+function augmentTypedArray(typedArray, numComponents) {
+ let cursor = 0;
+ typedArray.push = function() {
+ for (let ii = 0; ii < arguments.length; ++ii) {
+ const value = arguments[ii];
+ if (value instanceof Array || isArrayBuffer(value)) {
+ for (let jj = 0; jj < value.length; ++jj) {
+ typedArray[cursor++] = value[jj];
+ }
+ } else {
+ typedArray[cursor++] = value;
+ }
+ }
+ };
+ typedArray.reset = function(opt_index) {
+ cursor = opt_index || 0;
+ };
+ typedArray.numComponents = numComponents;
+ Object.defineProperty(typedArray, 'numElements', {
+ get: function() {
+ return this.length / this.numComponents | 0;
+ },
+ });
+ return typedArray;
+}
+
+/**
+ * creates a typed array with a `push` function attached
+ * so that you can easily *push* values.
+ *
+ * `push` can take multiple arguments. If an argument is an array each element
+ * of the array will be added to the typed array.
+ *
+ * Example:
+ *
+ * const array = createAugmentedTypedArray(3, 2); // creates a Float32Array with 6 values
+ * array.push(1, 2, 3);
+ * array.push([4, 5, 6]);
+ * // array now contains [1, 2, 3, 4, 5, 6]
+ *
+ * Also has `numComponents` and `numElements` properties.
+ *
+ * @param {number} numComponents number of components
+ * @param {number} numElements number of elements. The total size of the array will be `numComponents * numElements`.
+ * @param {constructor} opt_type A constructor for the type. Default = `Float32Array`.
+ * @return {ArrayBufferView} A typed array.
+ * @memberOf module:twgl/primitives
+ */
+function createAugmentedTypedArray(numComponents, numElements, opt_type) {
+ const Type = opt_type || Float32Array;
+ return augmentTypedArray(new Type(numComponents * numElements), numComponents);
+}
+
+function allButIndices(name) {
+ return name !== "indices";
+}
+
+/**
+ * Given indexed vertices creates a new set of vertices un-indexed by expanding the indexed vertices.
+ * @param {Object.} vertices The indexed vertices to deindex
+ * @return {Object.} The deindexed vertices
+ * @memberOf module:twgl/primitives
+ */
+function deindexVertices(vertices) {
+ const indices = vertices.indices;
+ const newVertices = {};
+ const numElements = indices.length;
+
+ function expandToUnindexed(channel) {
+ const srcBuffer = vertices[channel];
+ const numComponents = srcBuffer.numComponents;
+ const dstBuffer = createAugmentedTypedArray(numComponents, numElements, srcBuffer.constructor);
+ for (let ii = 0; ii < numElements; ++ii) {
+ const ndx = indices[ii];
+ const offset = ndx * numComponents;
+ for (let jj = 0; jj < numComponents; ++jj) {
+ dstBuffer.push(srcBuffer[offset + jj]);
+ }
+ }
+ newVertices[channel] = dstBuffer;
+ }
+
+ Object.keys(vertices).filter(allButIndices).forEach(expandToUnindexed);
+
+ return newVertices;
+}
+
+/**
+ * flattens the normals of deindexed vertices in place.
+ * @param {Object.} vertices The deindexed vertices who's normals to flatten
+ * @return {Object.} The flattened vertices (same as was passed in)
+ * @memberOf module:twgl/primitives
+ */
+function flattenNormals(vertices) {
+ if (vertices.indices) {
+ throw new Error('can not flatten normals of indexed vertices. deindex them first');
+ }
+
+ const normals = vertices.normal;
+ const numNormals = normals.length;
+ for (let ii = 0; ii < numNormals; ii += 9) {
+ // pull out the 3 normals for this triangle
+ const nax = normals[ii + 0];
+ const nay = normals[ii + 1];
+ const naz = normals[ii + 2];
+
+ const nbx = normals[ii + 3];
+ const nby = normals[ii + 4];
+ const nbz = normals[ii + 5];
+
+ const ncx = normals[ii + 6];
+ const ncy = normals[ii + 7];
+ const ncz = normals[ii + 8];
+
+ // add them
+ let nx = nax + nbx + ncx;
+ let ny = nay + nby + ncy;
+ let nz = naz + nbz + ncz;
+
+ // normalize them
+ const length = Math.sqrt(nx * nx + ny * ny + nz * nz);
+
+ nx /= length;
+ ny /= length;
+ nz /= length;
+
+ // copy them back in
+ normals[ii + 0] = nx;
+ normals[ii + 1] = ny;
+ normals[ii + 2] = nz;
+
+ normals[ii + 3] = nx;
+ normals[ii + 4] = ny;
+ normals[ii + 5] = nz;
+
+ normals[ii + 6] = nx;
+ normals[ii + 7] = ny;
+ normals[ii + 8] = nz;
+ }
+
+ return vertices;
+}
+
+function applyFuncToV3Array(array, matrix, fn) {
+ const len = array.length;
+ const tmp = new Float32Array(3);
+ for (let ii = 0; ii < len; ii += 3) {
+ fn(matrix, [array[ii], array[ii + 1], array[ii + 2]], tmp);
+ array[ii ] = tmp[0];
+ array[ii + 1] = tmp[1];
+ array[ii + 2] = tmp[2];
+ }
+}
+
+function transformNormal$1(mi, v, dst) {
+ dst = dst || create();
+ const v0 = v[0];
+ const v1 = v[1];
+ const v2 = v[2];
+
+ dst[0] = v0 * mi[0 * 4 + 0] + v1 * mi[0 * 4 + 1] + v2 * mi[0 * 4 + 2];
+ dst[1] = v0 * mi[1 * 4 + 0] + v1 * mi[1 * 4 + 1] + v2 * mi[1 * 4 + 2];
+ dst[2] = v0 * mi[2 * 4 + 0] + v1 * mi[2 * 4 + 1] + v2 * mi[2 * 4 + 2];
+
+ return dst;
+}
+
+/**
+ * Reorients directions by the given matrix..
+ * @param {(number[]|TypedArray)} array The array. Assumes value floats per element.
+ * @param {module:twgl/m4.Mat4} matrix A matrix to multiply by.
+ * @return {(number[]|TypedArray)} the same array that was passed in
+ * @memberOf module:twgl/primitives
+ */
+function reorientDirections(array, matrix) {
+ applyFuncToV3Array(array, matrix, transformDirection);
+ return array;
+}
+
+/**
+ * Reorients normals by the inverse-transpose of the given
+ * matrix..
+ * @param {(number[]|TypedArray)} array The array. Assumes value floats per element.
+ * @param {module:twgl/m4.Mat4} matrix A matrix to multiply by.
+ * @return {(number[]|TypedArray)} the same array that was passed in
+ * @memberOf module:twgl/primitives
+ */
+function reorientNormals(array, matrix) {
+ applyFuncToV3Array(array, inverse(matrix), transformNormal$1);
+ return array;
+}
+
+/**
+ * Reorients positions by the given matrix. In other words, it
+ * multiplies each vertex by the given matrix.
+ * @param {(number[]|TypedArray)} array The array. Assumes value floats per element.
+ * @param {module:twgl/m4.Mat4} matrix A matrix to multiply by.
+ * @return {(number[]|TypedArray)} the same array that was passed in
+ * @memberOf module:twgl/primitives
+ */
+function reorientPositions(array, matrix) {
+ applyFuncToV3Array(array, matrix, transformPoint);
+ return array;
+}
+
+/**
+ * @typedef {(number[]|TypedArray)} NativeArrayOrTypedArray
+ */
+
+/**
+ * Reorients arrays by the given matrix. Assumes arrays have
+ * names that contains 'pos' could be reoriented as positions,
+ * 'binorm' or 'tan' as directions, and 'norm' as normals.
+ *
+ * @param {Object.} arrays The vertices to reorient
+ * @param {module:twgl/m4.Mat4} matrix matrix to reorient by.
+ * @return {Object.} same arrays that were passed in.
+ * @memberOf module:twgl/primitives
+ */
+function reorientVertices(arrays, matrix) {
+ Object.keys(arrays).forEach(function(name) {
+ const array = arrays[name];
+ if (name.indexOf("pos") >= 0) {
+ reorientPositions(array, matrix);
+ } else if (name.indexOf("tan") >= 0 || name.indexOf("binorm") >= 0) {
+ reorientDirections(array, matrix);
+ } else if (name.indexOf("norm") >= 0) {
+ reorientNormals(array, matrix);
+ }
+ });
+ return arrays;
+}
+
+/**
+ * Creates XY quad BufferInfo
+ *
+ * The default with no parameters will return a 2x2 quad with values from -1 to +1.
+ * If you want a unit quad with that goes from 0 to 1 you'd call it with
+ *
+ * twgl.primitives.createXYQuadBufferInfo(gl, 1, 0.5, 0.5);
+ *
+ * If you want a unit quad centered above 0,0 you'd call it with
+ *
+ * twgl.primitives.createXYQuadBufferInfo(gl, 1, 0, 0.5);
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} [size] the size across the quad. Defaults to 2 which means vertices will go from -1 to +1
+ * @param {number} [xOffset] the amount to offset the quad in X
+ * @param {number} [yOffset] the amount to offset the quad in Y
+ * @return {Object.} the created XY Quad BufferInfo
+ * @memberOf module:twgl/primitives
+ * @function createXYQuadBuffers
+ */
+
+/**
+ * Creates XY quad Buffers
+ *
+ * The default with no parameters will return a 2x2 quad with values from -1 to +1.
+ * If you want a unit quad with that goes from 0 to 1 you'd call it with
+ *
+ * twgl.primitives.createXYQuadBufferInfo(gl, 1, 0.5, 0.5);
+ *
+ * If you want a unit quad centered above 0,0 you'd call it with
+ *
+ * twgl.primitives.createXYQuadBufferInfo(gl, 1, 0, 0.5);
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} [size] the size across the quad. Defaults to 2 which means vertices will go from -1 to +1
+ * @param {number} [xOffset] the amount to offset the quad in X
+ * @param {number} [yOffset] the amount to offset the quad in Y
+ * @return {module:twgl.BufferInfo} the created XY Quad buffers
+ * @memberOf module:twgl/primitives
+ * @function createXYQuadBufferInfo
+ */
+
+/**
+ * Creates XY quad vertices
+ *
+ * The default with no parameters will return a 2x2 quad with values from -1 to +1.
+ * If you want a unit quad with that goes from 0 to 1 you'd call it with
+ *
+ * twgl.primitives.createXYQuadVertices(1, 0.5, 0.5);
+ *
+ * If you want a unit quad centered above 0,0 you'd call it with
+ *
+ * twgl.primitives.createXYQuadVertices(1, 0, 0.5);
+ *
+ * @param {number} [size] the size across the quad. Defaults to 2 which means vertices will go from -1 to +1
+ * @param {number} [xOffset] the amount to offset the quad in X
+ * @param {number} [yOffset] the amount to offset the quad in Y
+ * @return {Object.} the created XY Quad vertices
+ * @memberOf module:twgl/primitives
+ */
+function createXYQuadVertices(size, xOffset, yOffset) {
+ size = size || 2;
+ xOffset = xOffset || 0;
+ yOffset = yOffset || 0;
+ size *= 0.5;
+ return {
+ position: {
+ numComponents: 2,
+ data: [
+ xOffset + -1 * size, yOffset + -1 * size,
+ xOffset + 1 * size, yOffset + -1 * size,
+ xOffset + -1 * size, yOffset + 1 * size,
+ xOffset + 1 * size, yOffset + 1 * size,
+ ],
+ },
+ normal: [
+ 0, 0, 1,
+ 0, 0, 1,
+ 0, 0, 1,
+ 0, 0, 1,
+ ],
+ texcoord: [
+ 0, 0,
+ 1, 0,
+ 0, 1,
+ 1, 1,
+ ],
+ indices: [ 0, 1, 2, 2, 1, 3 ],
+ };
+}
+
+/**
+ * Creates XZ plane BufferInfo.
+ *
+ * The created plane has position, normal, and texcoord data
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} [width] Width of the plane. Default = 1
+ * @param {number} [depth] Depth of the plane. Default = 1
+ * @param {number} [subdivisionsWidth] Number of steps across the plane. Default = 1
+ * @param {number} [subdivisionsDepth] Number of steps down the plane. Default = 1
+ * @param {module:twgl/m4.Mat4} [matrix] A matrix by which to multiply all the vertices.
+ * @return {module:twgl.BufferInfo} The created plane BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createPlaneBufferInfo
+ */
+
+/**
+ * Creates XZ plane buffers.
+ *
+ * The created plane has position, normal, and texcoord data
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} [width] Width of the plane. Default = 1
+ * @param {number} [depth] Depth of the plane. Default = 1
+ * @param {number} [subdivisionsWidth] Number of steps across the plane. Default = 1
+ * @param {number} [subdivisionsDepth] Number of steps down the plane. Default = 1
+ * @param {module:twgl/m4.Mat4} [matrix] A matrix by which to multiply all the vertices.
+ * @return {Object.} The created plane buffers.
+ * @memberOf module:twgl/primitives
+ * @function createPlaneBuffers
+ */
+
+/**
+ * Creates XZ plane vertices.
+ *
+ * The created plane has position, normal, and texcoord data
+ *
+ * @param {number} [width] Width of the plane. Default = 1
+ * @param {number} [depth] Depth of the plane. Default = 1
+ * @param {number} [subdivisionsWidth] Number of steps across the plane. Default = 1
+ * @param {number} [subdivisionsDepth] Number of steps down the plane. Default = 1
+ * @param {module:twgl/m4.Mat4} [matrix] A matrix by which to multiply all the vertices.
+ * @return {Object.} The created plane vertices.
+ * @memberOf module:twgl/primitives
+ */
+function createPlaneVertices(
+ width,
+ depth,
+ subdivisionsWidth,
+ subdivisionsDepth,
+ matrix) {
+ width = width || 1;
+ depth = depth || 1;
+ subdivisionsWidth = subdivisionsWidth || 1;
+ subdivisionsDepth = subdivisionsDepth || 1;
+ matrix = matrix || identity();
+
+ const numVertices = (subdivisionsWidth + 1) * (subdivisionsDepth + 1);
+ const positions = createAugmentedTypedArray(3, numVertices);
+ const normals = createAugmentedTypedArray(3, numVertices);
+ const texcoords = createAugmentedTypedArray(2, numVertices);
+
+ for (let z = 0; z <= subdivisionsDepth; z++) {
+ for (let x = 0; x <= subdivisionsWidth; x++) {
+ const u = x / subdivisionsWidth;
+ const v = z / subdivisionsDepth;
+ positions.push(
+ width * u - width * 0.5,
+ 0,
+ depth * v - depth * 0.5);
+ normals.push(0, 1, 0);
+ texcoords.push(u, v);
+ }
+ }
+
+ const numVertsAcross = subdivisionsWidth + 1;
+ const indices = createAugmentedTypedArray(
+ 3, subdivisionsWidth * subdivisionsDepth * 2, Uint16Array);
+
+ for (let z = 0; z < subdivisionsDepth; z++) { // eslint-disable-line
+ for (let x = 0; x < subdivisionsWidth; x++) { // eslint-disable-line
+ // Make triangle 1 of quad.
+ indices.push(
+ (z + 0) * numVertsAcross + x,
+ (z + 1) * numVertsAcross + x,
+ (z + 0) * numVertsAcross + x + 1);
+
+ // Make triangle 2 of quad.
+ indices.push(
+ (z + 1) * numVertsAcross + x,
+ (z + 1) * numVertsAcross + x + 1,
+ (z + 0) * numVertsAcross + x + 1);
+ }
+ }
+
+ const arrays = reorientVertices({
+ position: positions,
+ normal: normals,
+ texcoord: texcoords,
+ indices: indices,
+ }, matrix);
+ return arrays;
+}
+
+/**
+ * Creates sphere BufferInfo.
+ *
+ * The created sphere has position, normal, and texcoord data
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} radius radius of the sphere.
+ * @param {number} subdivisionsAxis number of steps around the sphere.
+ * @param {number} subdivisionsHeight number of vertically on the sphere.
+ * @param {number} [opt_startLatitudeInRadians] where to start the
+ * top of the sphere. Default = 0.
+ * @param {number} [opt_endLatitudeInRadians] Where to end the
+ * bottom of the sphere. Default = Math.PI.
+ * @param {number} [opt_startLongitudeInRadians] where to start
+ * wrapping the sphere. Default = 0.
+ * @param {number} [opt_endLongitudeInRadians] where to end
+ * wrapping the sphere. Default = 2 * Math.PI.
+ * @return {module:twgl.BufferInfo} The created sphere BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createSphereBufferInfo
+ */
+
+/**
+ * Creates sphere buffers.
+ *
+ * The created sphere has position, normal, and texcoord data
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} radius radius of the sphere.
+ * @param {number} subdivisionsAxis number of steps around the sphere.
+ * @param {number} subdivisionsHeight number of vertically on the sphere.
+ * @param {number} [opt_startLatitudeInRadians] where to start the
+ * top of the sphere. Default = 0.
+ * @param {number} [opt_endLatitudeInRadians] Where to end the
+ * bottom of the sphere. Default = Math.PI.
+ * @param {number} [opt_startLongitudeInRadians] where to start
+ * wrapping the sphere. Default = 0.
+ * @param {number} [opt_endLongitudeInRadians] where to end
+ * wrapping the sphere. Default = 2 * Math.PI.
+ * @return {Object.} The created sphere buffers.
+ * @memberOf module:twgl/primitives
+ * @function createSphereBuffers
+ */
+
+/**
+ * Creates sphere vertices.
+ *
+ * The created sphere has position, normal, and texcoord data
+ *
+ * @param {number} radius radius of the sphere.
+ * @param {number} subdivisionsAxis number of steps around the sphere.
+ * @param {number} subdivisionsHeight number of vertically on the sphere.
+ * @param {number} [opt_startLatitudeInRadians] where to start the
+ * top of the sphere. Default = 0.
+ * @param {number} [opt_endLatitudeInRadians] Where to end the
+ * bottom of the sphere. Default = Math.PI.
+ * @param {number} [opt_startLongitudeInRadians] where to start
+ * wrapping the sphere. Default = 0.
+ * @param {number} [opt_endLongitudeInRadians] where to end
+ * wrapping the sphere. Default = 2 * Math.PI.
+ * @return {Object.} The created sphere vertices.
+ * @memberOf module:twgl/primitives
+ */
+function createSphereVertices(
+ radius,
+ subdivisionsAxis,
+ subdivisionsHeight,
+ opt_startLatitudeInRadians,
+ opt_endLatitudeInRadians,
+ opt_startLongitudeInRadians,
+ opt_endLongitudeInRadians) {
+ if (subdivisionsAxis <= 0 || subdivisionsHeight <= 0) {
+ throw new Error('subdivisionAxis and subdivisionHeight must be > 0');
+ }
+
+ opt_startLatitudeInRadians = opt_startLatitudeInRadians || 0;
+ opt_endLatitudeInRadians = opt_endLatitudeInRadians || Math.PI;
+ opt_startLongitudeInRadians = opt_startLongitudeInRadians || 0;
+ opt_endLongitudeInRadians = opt_endLongitudeInRadians || (Math.PI * 2);
+
+ const latRange = opt_endLatitudeInRadians - opt_startLatitudeInRadians;
+ const longRange = opt_endLongitudeInRadians - opt_startLongitudeInRadians;
+
+ // We are going to generate our sphere by iterating through its
+ // spherical coordinates and generating 2 triangles for each quad on a
+ // ring of the sphere.
+ const numVertices = (subdivisionsAxis + 1) * (subdivisionsHeight + 1);
+ const positions = createAugmentedTypedArray(3, numVertices);
+ const normals = createAugmentedTypedArray(3, numVertices);
+ const texcoords = createAugmentedTypedArray(2 , numVertices);
+
+ // Generate the individual vertices in our vertex buffer.
+ for (let y = 0; y <= subdivisionsHeight; y++) {
+ for (let x = 0; x <= subdivisionsAxis; x++) {
+ // Generate a vertex based on its spherical coordinates
+ const u = x / subdivisionsAxis;
+ const v = y / subdivisionsHeight;
+ const theta = longRange * u + opt_startLongitudeInRadians;
+ const phi = latRange * v + opt_startLatitudeInRadians;
+ const sinTheta = Math.sin(theta);
+ const cosTheta = Math.cos(theta);
+ const sinPhi = Math.sin(phi);
+ const cosPhi = Math.cos(phi);
+ const ux = cosTheta * sinPhi;
+ const uy = cosPhi;
+ const uz = sinTheta * sinPhi;
+ positions.push(radius * ux, radius * uy, radius * uz);
+ normals.push(ux, uy, uz);
+ texcoords.push(1 - u, v);
+ }
+ }
+
+ const numVertsAround = subdivisionsAxis + 1;
+ const indices = createAugmentedTypedArray(3, subdivisionsAxis * subdivisionsHeight * 2, Uint16Array);
+ for (let x = 0; x < subdivisionsAxis; x++) { // eslint-disable-line
+ for (let y = 0; y < subdivisionsHeight; y++) { // eslint-disable-line
+ // Make triangle 1 of quad.
+ indices.push(
+ (y + 0) * numVertsAround + x,
+ (y + 0) * numVertsAround + x + 1,
+ (y + 1) * numVertsAround + x);
+
+ // Make triangle 2 of quad.
+ indices.push(
+ (y + 1) * numVertsAround + x,
+ (y + 0) * numVertsAround + x + 1,
+ (y + 1) * numVertsAround + x + 1);
+ }
+ }
+
+ return {
+ position: positions,
+ normal: normals,
+ texcoord: texcoords,
+ indices: indices,
+ };
+}
+
+/**
+ * Array of the indices of corners of each face of a cube.
+ * @type {Array.}
+ * @private
+ */
+const CUBE_FACE_INDICES = [
+ [3, 7, 5, 1], // right
+ [6, 2, 0, 4], // left
+ [6, 7, 3, 2], // ??
+ [0, 1, 5, 4], // ??
+ [7, 6, 4, 5], // front
+ [2, 3, 1, 0], // back
+];
+
+/**
+ * Creates a BufferInfo for a cube.
+ *
+ * The cube is created around the origin. (-size / 2, size / 2).
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} [size] width, height and depth of the cube.
+ * @return {module:twgl.BufferInfo} The created BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createCubeBufferInfo
+ */
+
+/**
+ * Creates the buffers and indices for a cube.
+ *
+ * The cube is created around the origin. (-size / 2, size / 2).
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} [size] width, height and depth of the cube.
+ * @return {Object.} The created buffers.
+ * @memberOf module:twgl/primitives
+ * @function createCubeBuffers
+ */
+
+/**
+ * Creates the vertices and indices for a cube.
+ *
+ * The cube is created around the origin. (-size / 2, size / 2).
+ *
+ * @param {number} [size] width, height and depth of the cube.
+ * @return {Object.} The created vertices.
+ * @memberOf module:twgl/primitives
+ */
+function createCubeVertices(size) {
+ size = size || 1;
+ const k = size / 2;
+
+ const cornerVertices = [
+ [-k, -k, -k],
+ [+k, -k, -k],
+ [-k, +k, -k],
+ [+k, +k, -k],
+ [-k, -k, +k],
+ [+k, -k, +k],
+ [-k, +k, +k],
+ [+k, +k, +k],
+ ];
+
+ const faceNormals = [
+ [+1, +0, +0],
+ [-1, +0, +0],
+ [+0, +1, +0],
+ [+0, -1, +0],
+ [+0, +0, +1],
+ [+0, +0, -1],
+ ];
+
+ const uvCoords = [
+ [1, 0],
+ [0, 0],
+ [0, 1],
+ [1, 1],
+ ];
+
+ const numVertices = 6 * 4;
+ const positions = createAugmentedTypedArray(3, numVertices);
+ const normals = createAugmentedTypedArray(3, numVertices);
+ const texcoords = createAugmentedTypedArray(2 , numVertices);
+ const indices = createAugmentedTypedArray(3, 6 * 2, Uint16Array);
+
+ for (let f = 0; f < 6; ++f) {
+ const faceIndices = CUBE_FACE_INDICES[f];
+ for (let v = 0; v < 4; ++v) {
+ const position = cornerVertices[faceIndices[v]];
+ const normal = faceNormals[f];
+ const uv = uvCoords[v];
+
+ // Each face needs all four vertices because the normals and texture
+ // coordinates are not all the same.
+ positions.push(position);
+ normals.push(normal);
+ texcoords.push(uv);
+
+ }
+ // Two triangles make a square face.
+ const offset = 4 * f;
+ indices.push(offset + 0, offset + 1, offset + 2);
+ indices.push(offset + 0, offset + 2, offset + 3);
+ }
+
+ return {
+ position: positions,
+ normal: normals,
+ texcoord: texcoords,
+ indices: indices,
+ };
+}
+
+/**
+ * Creates a BufferInfo for a truncated cone, which is like a cylinder
+ * except that it has different top and bottom radii. A truncated cone
+ * can also be used to create cylinders and regular cones. The
+ * truncated cone will be created centered about the origin, with the
+ * y axis as its vertical axis.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} bottomRadius Bottom radius of truncated cone.
+ * @param {number} topRadius Top radius of truncated cone.
+ * @param {number} height Height of truncated cone.
+ * @param {number} radialSubdivisions The number of subdivisions around the
+ * truncated cone.
+ * @param {number} verticalSubdivisions The number of subdivisions down the
+ * truncated cone.
+ * @param {boolean} [opt_topCap] Create top cap. Default = true.
+ * @param {boolean} [opt_bottomCap] Create bottom cap. Default = true.
+ * @return {module:twgl.BufferInfo} The created cone BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createTruncatedConeBufferInfo
+ */
+
+/**
+ * Creates buffers for a truncated cone, which is like a cylinder
+ * except that it has different top and bottom radii. A truncated cone
+ * can also be used to create cylinders and regular cones. The
+ * truncated cone will be created centered about the origin, with the
+ * y axis as its vertical axis.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} bottomRadius Bottom radius of truncated cone.
+ * @param {number} topRadius Top radius of truncated cone.
+ * @param {number} height Height of truncated cone.
+ * @param {number} radialSubdivisions The number of subdivisions around the
+ * truncated cone.
+ * @param {number} verticalSubdivisions The number of subdivisions down the
+ * truncated cone.
+ * @param {boolean} [opt_topCap] Create top cap. Default = true.
+ * @param {boolean} [opt_bottomCap] Create bottom cap. Default = true.
+ * @return {Object.} The created cone buffers.
+ * @memberOf module:twgl/primitives
+ * @function createTruncatedConeBuffers
+ */
+
+/**
+ * Creates vertices for a truncated cone, which is like a cylinder
+ * except that it has different top and bottom radii. A truncated cone
+ * can also be used to create cylinders and regular cones. The
+ * truncated cone will be created centered about the origin, with the
+ * y axis as its vertical axis. .
+ *
+ * @param {number} bottomRadius Bottom radius of truncated cone.
+ * @param {number} topRadius Top radius of truncated cone.
+ * @param {number} height Height of truncated cone.
+ * @param {number} radialSubdivisions The number of subdivisions around the
+ * truncated cone.
+ * @param {number} verticalSubdivisions The number of subdivisions down the
+ * truncated cone.
+ * @param {boolean} [opt_topCap] Create top cap. Default = true.
+ * @param {boolean} [opt_bottomCap] Create bottom cap. Default = true.
+ * @return {Object.} The created cone vertices.
+ * @memberOf module:twgl/primitives
+ */
+function createTruncatedConeVertices(
+ bottomRadius,
+ topRadius,
+ height,
+ radialSubdivisions,
+ verticalSubdivisions,
+ opt_topCap,
+ opt_bottomCap) {
+ if (radialSubdivisions < 3) {
+ throw new Error('radialSubdivisions must be 3 or greater');
+ }
+
+ if (verticalSubdivisions < 1) {
+ throw new Error('verticalSubdivisions must be 1 or greater');
+ }
+
+ const topCap = (opt_topCap === undefined) ? true : opt_topCap;
+ const bottomCap = (opt_bottomCap === undefined) ? true : opt_bottomCap;
+
+ const extra = (topCap ? 2 : 0) + (bottomCap ? 2 : 0);
+
+ const numVertices = (radialSubdivisions + 1) * (verticalSubdivisions + 1 + extra);
+ const positions = createAugmentedTypedArray(3, numVertices);
+ const normals = createAugmentedTypedArray(3, numVertices);
+ const texcoords = createAugmentedTypedArray(2, numVertices);
+ const indices = createAugmentedTypedArray(3, radialSubdivisions * (verticalSubdivisions + extra) * 2, Uint16Array);
+
+ const vertsAroundEdge = radialSubdivisions + 1;
+
+ // The slant of the cone is constant across its surface
+ const slant = Math.atan2(bottomRadius - topRadius, height);
+ const cosSlant = Math.cos(slant);
+ const sinSlant = Math.sin(slant);
+
+ const start = topCap ? -2 : 0;
+ const end = verticalSubdivisions + (bottomCap ? 2 : 0);
+
+ for (let yy = start; yy <= end; ++yy) {
+ let v = yy / verticalSubdivisions;
+ let y = height * v;
+ let ringRadius;
+ if (yy < 0) {
+ y = 0;
+ v = 1;
+ ringRadius = bottomRadius;
+ } else if (yy > verticalSubdivisions) {
+ y = height;
+ v = 1;
+ ringRadius = topRadius;
+ } else {
+ ringRadius = bottomRadius +
+ (topRadius - bottomRadius) * (yy / verticalSubdivisions);
+ }
+ if (yy === -2 || yy === verticalSubdivisions + 2) {
+ ringRadius = 0;
+ v = 0;
+ }
+ y -= height / 2;
+ for (let ii = 0; ii < vertsAroundEdge; ++ii) {
+ const sin = Math.sin(ii * Math.PI * 2 / radialSubdivisions);
+ const cos = Math.cos(ii * Math.PI * 2 / radialSubdivisions);
+ positions.push(sin * ringRadius, y, cos * ringRadius);
+ if (yy < 0) {
+ normals.push(0, -1, 0);
+ } else if (yy > verticalSubdivisions) {
+ normals.push(0, 1, 0);
+ } else if (ringRadius === 0.0) {
+ normals.push(0, 0, 0);
+ } else {
+ normals.push(sin * cosSlant, sinSlant, cos * cosSlant);
+ }
+ texcoords.push((ii / radialSubdivisions), 1 - v);
+ }
+ }
+
+ for (let yy = 0; yy < verticalSubdivisions + extra; ++yy) { // eslint-disable-line
+ for (let ii = 0; ii < radialSubdivisions; ++ii) { // eslint-disable-line
+ indices.push(vertsAroundEdge * (yy + 0) + 0 + ii,
+ vertsAroundEdge * (yy + 0) + 1 + ii,
+ vertsAroundEdge * (yy + 1) + 1 + ii);
+ indices.push(vertsAroundEdge * (yy + 0) + 0 + ii,
+ vertsAroundEdge * (yy + 1) + 1 + ii,
+ vertsAroundEdge * (yy + 1) + 0 + ii);
+ }
+ }
+
+ return {
+ position: positions,
+ normal: normals,
+ texcoord: texcoords,
+ indices: indices,
+ };
+}
+
+/**
+ * Expands RLE data
+ * @param {number[]} rleData data in format of run-length, x, y, z, run-length, x, y, z
+ * @param {number[]} [padding] value to add each entry with.
+ * @return {number[]} the expanded rleData
+ * @private
+ */
+function expandRLEData(rleData, padding) {
+ padding = padding || [];
+ const data = [];
+ for (let ii = 0; ii < rleData.length; ii += 4) {
+ const runLength = rleData[ii];
+ const element = rleData.slice(ii + 1, ii + 4);
+ element.push.apply(element, padding);
+ for (let jj = 0; jj < runLength; ++jj) {
+ data.push.apply(data, element);
+ }
+ }
+ return data;
+}
+
+/**
+ * Creates 3D 'F' BufferInfo.
+ * An 'F' is useful because you can easily tell which way it is oriented.
+ * The created 'F' has position, normal, texcoord, and color buffers.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @return {module:twgl.BufferInfo} The created BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function create3DFBufferInfo
+ */
+
+/**
+ * Creates 3D 'F' buffers.
+ * An 'F' is useful because you can easily tell which way it is oriented.
+ * The created 'F' has position, normal, texcoord, and color buffers.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @return {Object.} The created buffers.
+ * @memberOf module:twgl/primitives
+ * @function create3DFBuffers
+ */
+
+/**
+ * Creates 3D 'F' vertices.
+ * An 'F' is useful because you can easily tell which way it is oriented.
+ * The created 'F' has position, normal, texcoord, and color arrays.
+ *
+ * @return {Object.} The created vertices.
+ * @memberOf module:twgl/primitives
+ */
+function create3DFVertices() {
+
+ const positions = [
+ // left column front
+ 0, 0, 0,
+ 0, 150, 0,
+ 30, 0, 0,
+ 0, 150, 0,
+ 30, 150, 0,
+ 30, 0, 0,
+
+ // top rung front
+ 30, 0, 0,
+ 30, 30, 0,
+ 100, 0, 0,
+ 30, 30, 0,
+ 100, 30, 0,
+ 100, 0, 0,
+
+ // middle rung front
+ 30, 60, 0,
+ 30, 90, 0,
+ 67, 60, 0,
+ 30, 90, 0,
+ 67, 90, 0,
+ 67, 60, 0,
+
+ // left column back
+ 0, 0, 30,
+ 30, 0, 30,
+ 0, 150, 30,
+ 0, 150, 30,
+ 30, 0, 30,
+ 30, 150, 30,
+
+ // top rung back
+ 30, 0, 30,
+ 100, 0, 30,
+ 30, 30, 30,
+ 30, 30, 30,
+ 100, 0, 30,
+ 100, 30, 30,
+
+ // middle rung back
+ 30, 60, 30,
+ 67, 60, 30,
+ 30, 90, 30,
+ 30, 90, 30,
+ 67, 60, 30,
+ 67, 90, 30,
+
+ // top
+ 0, 0, 0,
+ 100, 0, 0,
+ 100, 0, 30,
+ 0, 0, 0,
+ 100, 0, 30,
+ 0, 0, 30,
+
+ // top rung front
+ 100, 0, 0,
+ 100, 30, 0,
+ 100, 30, 30,
+ 100, 0, 0,
+ 100, 30, 30,
+ 100, 0, 30,
+
+ // under top rung
+ 30, 30, 0,
+ 30, 30, 30,
+ 100, 30, 30,
+ 30, 30, 0,
+ 100, 30, 30,
+ 100, 30, 0,
+
+ // between top rung and middle
+ 30, 30, 0,
+ 30, 60, 30,
+ 30, 30, 30,
+ 30, 30, 0,
+ 30, 60, 0,
+ 30, 60, 30,
+
+ // top of middle rung
+ 30, 60, 0,
+ 67, 60, 30,
+ 30, 60, 30,
+ 30, 60, 0,
+ 67, 60, 0,
+ 67, 60, 30,
+
+ // front of middle rung
+ 67, 60, 0,
+ 67, 90, 30,
+ 67, 60, 30,
+ 67, 60, 0,
+ 67, 90, 0,
+ 67, 90, 30,
+
+ // bottom of middle rung.
+ 30, 90, 0,
+ 30, 90, 30,
+ 67, 90, 30,
+ 30, 90, 0,
+ 67, 90, 30,
+ 67, 90, 0,
+
+ // front of bottom
+ 30, 90, 0,
+ 30, 150, 30,
+ 30, 90, 30,
+ 30, 90, 0,
+ 30, 150, 0,
+ 30, 150, 30,
+
+ // bottom
+ 0, 150, 0,
+ 0, 150, 30,
+ 30, 150, 30,
+ 0, 150, 0,
+ 30, 150, 30,
+ 30, 150, 0,
+
+ // left side
+ 0, 0, 0,
+ 0, 0, 30,
+ 0, 150, 30,
+ 0, 0, 0,
+ 0, 150, 30,
+ 0, 150, 0,
+ ];
+
+ const texcoords = [
+ // left column front
+ 0.22, 0.19,
+ 0.22, 0.79,
+ 0.34, 0.19,
+ 0.22, 0.79,
+ 0.34, 0.79,
+ 0.34, 0.19,
+
+ // top rung front
+ 0.34, 0.19,
+ 0.34, 0.31,
+ 0.62, 0.19,
+ 0.34, 0.31,
+ 0.62, 0.31,
+ 0.62, 0.19,
+
+ // middle rung front
+ 0.34, 0.43,
+ 0.34, 0.55,
+ 0.49, 0.43,
+ 0.34, 0.55,
+ 0.49, 0.55,
+ 0.49, 0.43,
+
+ // left column back
+ 0, 0,
+ 1, 0,
+ 0, 1,
+ 0, 1,
+ 1, 0,
+ 1, 1,
+
+ // top rung back
+ 0, 0,
+ 1, 0,
+ 0, 1,
+ 0, 1,
+ 1, 0,
+ 1, 1,
+
+ // middle rung back
+ 0, 0,
+ 1, 0,
+ 0, 1,
+ 0, 1,
+ 1, 0,
+ 1, 1,
+
+ // top
+ 0, 0,
+ 1, 0,
+ 1, 1,
+ 0, 0,
+ 1, 1,
+ 0, 1,
+
+ // top rung front
+ 0, 0,
+ 1, 0,
+ 1, 1,
+ 0, 0,
+ 1, 1,
+ 0, 1,
+
+ // under top rung
+ 0, 0,
+ 0, 1,
+ 1, 1,
+ 0, 0,
+ 1, 1,
+ 1, 0,
+
+ // between top rung and middle
+ 0, 0,
+ 1, 1,
+ 0, 1,
+ 0, 0,
+ 1, 0,
+ 1, 1,
+
+ // top of middle rung
+ 0, 0,
+ 1, 1,
+ 0, 1,
+ 0, 0,
+ 1, 0,
+ 1, 1,
+
+ // front of middle rung
+ 0, 0,
+ 1, 1,
+ 0, 1,
+ 0, 0,
+ 1, 0,
+ 1, 1,
+
+ // bottom of middle rung.
+ 0, 0,
+ 0, 1,
+ 1, 1,
+ 0, 0,
+ 1, 1,
+ 1, 0,
+
+ // front of bottom
+ 0, 0,
+ 1, 1,
+ 0, 1,
+ 0, 0,
+ 1, 0,
+ 1, 1,
+
+ // bottom
+ 0, 0,
+ 0, 1,
+ 1, 1,
+ 0, 0,
+ 1, 1,
+ 1, 0,
+
+ // left side
+ 0, 0,
+ 0, 1,
+ 1, 1,
+ 0, 0,
+ 1, 1,
+ 1, 0,
+ ];
+
+ const normals = expandRLEData([
+ // left column front
+ // top rung front
+ // middle rung front
+ 18, 0, 0, 1,
+
+ // left column back
+ // top rung back
+ // middle rung back
+ 18, 0, 0, -1,
+
+ // top
+ 6, 0, 1, 0,
+
+ // top rung front
+ 6, 1, 0, 0,
+
+ // under top rung
+ 6, 0, -1, 0,
+
+ // between top rung and middle
+ 6, 1, 0, 0,
+
+ // top of middle rung
+ 6, 0, 1, 0,
+
+ // front of middle rung
+ 6, 1, 0, 0,
+
+ // bottom of middle rung.
+ 6, 0, -1, 0,
+
+ // front of bottom
+ 6, 1, 0, 0,
+
+ // bottom
+ 6, 0, -1, 0,
+
+ // left side
+ 6, -1, 0, 0,
+ ]);
+
+ const colors = expandRLEData([
+ // left column front
+ // top rung front
+ // middle rung front
+ 18, 200, 70, 120,
+
+ // left column back
+ // top rung back
+ // middle rung back
+ 18, 80, 70, 200,
+
+ // top
+ 6, 70, 200, 210,
+
+ // top rung front
+ 6, 200, 200, 70,
+
+ // under top rung
+ 6, 210, 100, 70,
+
+ // between top rung and middle
+ 6, 210, 160, 70,
+
+ // top of middle rung
+ 6, 70, 180, 210,
+
+ // front of middle rung
+ 6, 100, 70, 210,
+
+ // bottom of middle rung.
+ 6, 76, 210, 100,
+
+ // front of bottom
+ 6, 140, 210, 80,
+
+ // bottom
+ 6, 90, 130, 110,
+
+ // left side
+ 6, 160, 160, 220,
+ ], [255]);
+
+ const numVerts = positions.length / 3;
+
+ const arrays = {
+ position: createAugmentedTypedArray(3, numVerts),
+ texcoord: createAugmentedTypedArray(2, numVerts),
+ normal: createAugmentedTypedArray(3, numVerts),
+ color: createAugmentedTypedArray(4, numVerts, Uint8Array),
+ indices: createAugmentedTypedArray(3, numVerts / 3, Uint16Array),
+ };
+
+ arrays.position.push(positions);
+ arrays.texcoord.push(texcoords);
+ arrays.normal.push(normals);
+ arrays.color.push(colors);
+
+ for (let ii = 0; ii < numVerts; ++ii) {
+ arrays.indices.push(ii);
+ }
+
+ return arrays;
+}
+
+/**
+ * Creates crescent BufferInfo.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} verticalRadius The vertical radius of the crescent.
+ * @param {number} outerRadius The outer radius of the crescent.
+ * @param {number} innerRadius The inner radius of the crescent.
+ * @param {number} thickness The thickness of the crescent.
+ * @param {number} subdivisionsDown number of steps around the crescent.
+ * @param {number} [startOffset] Where to start arc. Default 0.
+ * @param {number} [endOffset] Where to end arg. Default 1.
+ * @return {module:twgl.BufferInfo} The created BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createCresentBufferInfo
+ */
+
+/**
+ * Creates crescent buffers.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} verticalRadius The vertical radius of the crescent.
+ * @param {number} outerRadius The outer radius of the crescent.
+ * @param {number} innerRadius The inner radius of the crescent.
+ * @param {number} thickness The thickness of the crescent.
+ * @param {number} subdivisionsDown number of steps around the crescent.
+ * @param {number} [startOffset] Where to start arc. Default 0.
+ * @param {number} [endOffset] Where to end arg. Default 1.
+ * @return {Object.} The created buffers.
+ * @memberOf module:twgl/primitives
+ * @function createCresentBuffers
+ */
+
+/**
+ * Creates crescent vertices.
+ *
+ * @param {number} verticalRadius The vertical radius of the crescent.
+ * @param {number} outerRadius The outer radius of the crescent.
+ * @param {number} innerRadius The inner radius of the crescent.
+ * @param {number} thickness The thickness of the crescent.
+ * @param {number} subdivisionsDown number of steps around the crescent.
+ * @param {number} [startOffset] Where to start arc. Default 0.
+ * @param {number} [endOffset] Where to end arg. Default 1.
+ * @return {Object.} The created vertices.
+ * @memberOf module:twgl/primitives
+ * @function createCresentBuffers
+ */
+
+/**
+ * Creates crescent BufferInfo.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} verticalRadius The vertical radius of the crescent.
+ * @param {number} outerRadius The outer radius of the crescent.
+ * @param {number} innerRadius The inner radius of the crescent.
+ * @param {number} thickness The thickness of the crescent.
+ * @param {number} subdivisionsDown number of steps around the crescent.
+ * @param {number} [startOffset] Where to start arc. Default 0.
+ * @param {number} [endOffset] Where to end arg. Default 1.
+ * @return {module:twgl.BufferInfo} The created BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createCrescentBufferInfo
+ */
+
+/**
+ * Creates crescent buffers.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} verticalRadius The vertical radius of the crescent.
+ * @param {number} outerRadius The outer radius of the crescent.
+ * @param {number} innerRadius The inner radius of the crescent.
+ * @param {number} thickness The thickness of the crescent.
+ * @param {number} subdivisionsDown number of steps around the crescent.
+ * @param {number} [startOffset] Where to start arc. Default 0.
+ * @param {number} [endOffset] Where to end arg. Default 1.
+ * @return {Object.} The created buffers.
+ * @memberOf module:twgl/primitives
+ * @function createCrescentBuffers
+ */
+
+/**
+ * Creates crescent vertices.
+ *
+ * @param {number} verticalRadius The vertical radius of the crescent.
+ * @param {number} outerRadius The outer radius of the crescent.
+ * @param {number} innerRadius The inner radius of the crescent.
+ * @param {number} thickness The thickness of the crescent.
+ * @param {number} subdivisionsDown number of steps around the crescent.
+ * @param {number} [startOffset] Where to start arc. Default 0.
+ * @param {number} [endOffset] Where to end arg. Default 1.
+ * @return {Object.} The created vertices.
+ * @memberOf module:twgl/primitives
+ */
+ function createCrescentVertices(
+ verticalRadius,
+ outerRadius,
+ innerRadius,
+ thickness,
+ subdivisionsDown,
+ startOffset,
+ endOffset) {
+ if (subdivisionsDown <= 0) {
+ throw new Error('subdivisionDown must be > 0');
+ }
+
+ startOffset = startOffset || 0;
+ endOffset = endOffset || 1;
+
+ const subdivisionsThick = 2;
+
+ const offsetRange = endOffset - startOffset;
+ const numVertices = (subdivisionsDown + 1) * 2 * (2 + subdivisionsThick);
+ const positions = createAugmentedTypedArray(3, numVertices);
+ const normals = createAugmentedTypedArray(3, numVertices);
+ const texcoords = createAugmentedTypedArray(2, numVertices);
+
+ function lerp(a, b, s) {
+ return a + (b - a) * s;
+ }
+
+ function createArc(arcRadius, x, normalMult, normalAdd, uMult, uAdd) {
+ for (let z = 0; z <= subdivisionsDown; z++) {
+ const uBack = x / (subdivisionsThick - 1);
+ const v = z / subdivisionsDown;
+ const xBack = (uBack - 0.5) * 2;
+ const angle = (startOffset + (v * offsetRange)) * Math.PI;
+ const s = Math.sin(angle);
+ const c = Math.cos(angle);
+ const radius = lerp(verticalRadius, arcRadius, s);
+ const px = xBack * thickness;
+ const py = c * verticalRadius;
+ const pz = s * radius;
+ positions.push(px, py, pz);
+ const n = add(multiply([0, s, c], normalMult), normalAdd);
+ normals.push(n);
+ texcoords.push(uBack * uMult + uAdd, v);
+ }
+ }
+
+ // Generate the individual vertices in our vertex buffer.
+ for (let x = 0; x < subdivisionsThick; x++) {
+ const uBack = (x / (subdivisionsThick - 1) - 0.5) * 2;
+ createArc(outerRadius, x, [1, 1, 1], [0, 0, 0], 1, 0);
+ createArc(outerRadius, x, [0, 0, 0], [uBack, 0, 0], 0, 0);
+ createArc(innerRadius, x, [1, 1, 1], [0, 0, 0], 1, 0);
+ createArc(innerRadius, x, [0, 0, 0], [uBack, 0, 0], 0, 1);
+ }
+
+ // Do outer surface.
+ const indices = createAugmentedTypedArray(3, (subdivisionsDown * 2) * (2 + subdivisionsThick), Uint16Array);
+
+ function createSurface(leftArcOffset, rightArcOffset) {
+ for (let z = 0; z < subdivisionsDown; ++z) {
+ // Make triangle 1 of quad.
+ indices.push(
+ leftArcOffset + z + 0,
+ leftArcOffset + z + 1,
+ rightArcOffset + z + 0);
+
+ // Make triangle 2 of quad.
+ indices.push(
+ leftArcOffset + z + 1,
+ rightArcOffset + z + 1,
+ rightArcOffset + z + 0);
+ }
+ }
+
+ const numVerticesDown = subdivisionsDown + 1;
+ // front
+ createSurface(numVerticesDown * 0, numVerticesDown * 4);
+ // right
+ createSurface(numVerticesDown * 5, numVerticesDown * 7);
+ // back
+ createSurface(numVerticesDown * 6, numVerticesDown * 2);
+ // left
+ createSurface(numVerticesDown * 3, numVerticesDown * 1);
+
+ return {
+ position: positions,
+ normal: normals,
+ texcoord: texcoords,
+ indices: indices,
+ };
+}
+
+/**
+ * Creates cylinder BufferInfo. The cylinder will be created around the origin
+ * along the y-axis.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} radius Radius of cylinder.
+ * @param {number} height Height of cylinder.
+ * @param {number} radialSubdivisions The number of subdivisions around the cylinder.
+ * @param {number} verticalSubdivisions The number of subdivisions down the cylinder.
+ * @param {boolean} [topCap] Create top cap. Default = true.
+ * @param {boolean} [bottomCap] Create bottom cap. Default = true.
+ * @return {module:twgl.BufferInfo} The created BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createCylinderBufferInfo
+ */
+
+ /**
+ * Creates cylinder buffers. The cylinder will be created around the origin
+ * along the y-axis.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} radius Radius of cylinder.
+ * @param {number} height Height of cylinder.
+ * @param {number} radialSubdivisions The number of subdivisions around the cylinder.
+ * @param {number} verticalSubdivisions The number of subdivisions down the cylinder.
+ * @param {boolean} [topCap] Create top cap. Default = true.
+ * @param {boolean} [bottomCap] Create bottom cap. Default = true.
+ * @return {Object.} The created buffers.
+ * @memberOf module:twgl/primitives
+ * @function createCylinderBuffers
+ */
+
+ /**
+ * Creates cylinder vertices. The cylinder will be created around the origin
+ * along the y-axis.
+ *
+ * @param {number} radius Radius of cylinder.
+ * @param {number} height Height of cylinder.
+ * @param {number} radialSubdivisions The number of subdivisions around the cylinder.
+ * @param {number} verticalSubdivisions The number of subdivisions down the cylinder.
+ * @param {boolean} [topCap] Create top cap. Default = true.
+ * @param {boolean} [bottomCap] Create bottom cap. Default = true.
+ * @return {Object.} The created vertices.
+ * @memberOf module:twgl/primitives
+ */
+function createCylinderVertices(
+ radius,
+ height,
+ radialSubdivisions,
+ verticalSubdivisions,
+ topCap,
+ bottomCap) {
+ return createTruncatedConeVertices(
+ radius,
+ radius,
+ height,
+ radialSubdivisions,
+ verticalSubdivisions,
+ topCap,
+ bottomCap);
+}
+
+/**
+ * Creates BufferInfo for a torus
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} radius radius of center of torus circle.
+ * @param {number} thickness radius of torus ring.
+ * @param {number} radialSubdivisions The number of subdivisions around the torus.
+ * @param {number} bodySubdivisions The number of subdivisions around the body torus.
+ * @param {boolean} [startAngle] start angle in radians. Default = 0.
+ * @param {boolean} [endAngle] end angle in radians. Default = Math.PI * 2.
+ * @return {module:twgl.BufferInfo} The created BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createTorusBufferInfo
+ */
+
+/**
+ * Creates buffers for a torus
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} radius radius of center of torus circle.
+ * @param {number} thickness radius of torus ring.
+ * @param {number} radialSubdivisions The number of subdivisions around the torus.
+ * @param {number} bodySubdivisions The number of subdivisions around the body torus.
+ * @param {boolean} [startAngle] start angle in radians. Default = 0.
+ * @param {boolean} [endAngle] end angle in radians. Default = Math.PI * 2.
+ * @return {Object.} The created buffers.
+ * @memberOf module:twgl/primitives
+ * @function createTorusBuffers
+ */
+
+/**
+ * Creates vertices for a torus
+ *
+ * @param {number} radius radius of center of torus circle.
+ * @param {number} thickness radius of torus ring.
+ * @param {number} radialSubdivisions The number of subdivisions around the torus.
+ * @param {number} bodySubdivisions The number of subdivisions around the body torus.
+ * @param {boolean} [startAngle] start angle in radians. Default = 0.
+ * @param {boolean} [endAngle] end angle in radians. Default = Math.PI * 2.
+ * @return {Object.} The created vertices.
+ * @memberOf module:twgl/primitives
+ */
+function createTorusVertices(
+ radius,
+ thickness,
+ radialSubdivisions,
+ bodySubdivisions,
+ startAngle,
+ endAngle) {
+ if (radialSubdivisions < 3) {
+ throw new Error('radialSubdivisions must be 3 or greater');
+ }
+
+ if (bodySubdivisions < 3) {
+ throw new Error('verticalSubdivisions must be 3 or greater');
+ }
+
+ startAngle = startAngle || 0;
+ endAngle = endAngle || Math.PI * 2;
+ const range = endAngle - startAngle;
+
+ const radialParts = radialSubdivisions + 1;
+ const bodyParts = bodySubdivisions + 1;
+ const numVertices = radialParts * bodyParts;
+ const positions = createAugmentedTypedArray(3, numVertices);
+ const normals = createAugmentedTypedArray(3, numVertices);
+ const texcoords = createAugmentedTypedArray(2, numVertices);
+ const indices = createAugmentedTypedArray(3, (radialSubdivisions) * (bodySubdivisions) * 2, Uint16Array);
+
+ for (let slice = 0; slice < bodyParts; ++slice) {
+ const v = slice / bodySubdivisions;
+ const sliceAngle = v * Math.PI * 2;
+ const sliceSin = Math.sin(sliceAngle);
+ const ringRadius = radius + sliceSin * thickness;
+ const ny = Math.cos(sliceAngle);
+ const y = ny * thickness;
+ for (let ring = 0; ring < radialParts; ++ring) {
+ const u = ring / radialSubdivisions;
+ const ringAngle = startAngle + u * range;
+ const xSin = Math.sin(ringAngle);
+ const zCos = Math.cos(ringAngle);
+ const x = xSin * ringRadius;
+ const z = zCos * ringRadius;
+ const nx = xSin * sliceSin;
+ const nz = zCos * sliceSin;
+ positions.push(x, y, z);
+ normals.push(nx, ny, nz);
+ texcoords.push(u, 1 - v);
+ }
+ }
+
+ for (let slice = 0; slice < bodySubdivisions; ++slice) { // eslint-disable-line
+ for (let ring = 0; ring < radialSubdivisions; ++ring) { // eslint-disable-line
+ const nextRingIndex = 1 + ring;
+ const nextSliceIndex = 1 + slice;
+ indices.push(radialParts * slice + ring,
+ radialParts * nextSliceIndex + ring,
+ radialParts * slice + nextRingIndex);
+ indices.push(radialParts * nextSliceIndex + ring,
+ radialParts * nextSliceIndex + nextRingIndex,
+ radialParts * slice + nextRingIndex);
+ }
+ }
+
+ return {
+ position: positions,
+ normal: normals,
+ texcoord: texcoords,
+ indices: indices,
+ };
+}
+
+
+/**
+ * Creates a disc BufferInfo. The disc will be in the xz plane, centered at
+ * the origin. When creating, at least 3 divisions, or pie
+ * pieces, need to be specified, otherwise the triangles making
+ * up the disc will be degenerate. You can also specify the
+ * number of radial pieces `stacks`. A value of 1 for
+ * stacks will give you a simple disc of pie pieces. If you
+ * want to create an annulus you can set `innerRadius` to a
+ * value > 0. Finally, `stackPower` allows you to have the widths
+ * increase or decrease as you move away from the center. This
+ * is particularly useful when using the disc as a ground plane
+ * with a fixed camera such that you don't need the resolution
+ * of small triangles near the perimeter. For example, a value
+ * of 2 will produce stacks whose outside radius increases with
+ * the square of the stack index. A value of 1 will give uniform
+ * stacks.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} radius Radius of the ground plane.
+ * @param {number} divisions Number of triangles in the ground plane (at least 3).
+ * @param {number} [stacks] Number of radial divisions (default=1).
+ * @param {number} [innerRadius] Default 0.
+ * @param {number} [stackPower] Power to raise stack size to for decreasing width.
+ * @return {module:twgl.BufferInfo} The created BufferInfo.
+ * @memberOf module:twgl/primitives
+ * @function createDiscBufferInfo
+ */
+
+/**
+ * Creates disc buffers. The disc will be in the xz plane, centered at
+ * the origin. When creating, at least 3 divisions, or pie
+ * pieces, need to be specified, otherwise the triangles making
+ * up the disc will be degenerate. You can also specify the
+ * number of radial pieces `stacks`. A value of 1 for
+ * stacks will give you a simple disc of pie pieces. If you
+ * want to create an annulus you can set `innerRadius` to a
+ * value > 0. Finally, `stackPower` allows you to have the widths
+ * increase or decrease as you move away from the center. This
+ * is particularly useful when using the disc as a ground plane
+ * with a fixed camera such that you don't need the resolution
+ * of small triangles near the perimeter. For example, a value
+ * of 2 will produce stacks whose outside radius increases with
+ * the square of the stack index. A value of 1 will give uniform
+ * stacks.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext.
+ * @param {number} radius Radius of the ground plane.
+ * @param {number} divisions Number of triangles in the ground plane (at least 3).
+ * @param {number} [stacks] Number of radial divisions (default=1).
+ * @param {number} [innerRadius] Default 0.
+ * @param {number} [stackPower] Power to raise stack size to for decreasing width.
+ * @return {Object.} The created buffers.
+ * @memberOf module:twgl/primitives
+ * @function createDiscBuffers
+ */
+
+/**
+ * Creates disc vertices. The disc will be in the xz plane, centered at
+ * the origin. When creating, at least 3 divisions, or pie
+ * pieces, need to be specified, otherwise the triangles making
+ * up the disc will be degenerate. You can also specify the
+ * number of radial pieces `stacks`. A value of 1 for
+ * stacks will give you a simple disc of pie pieces. If you
+ * want to create an annulus you can set `innerRadius` to a
+ * value > 0. Finally, `stackPower` allows you to have the widths
+ * increase or decrease as you move away from the center. This
+ * is particularly useful when using the disc as a ground plane
+ * with a fixed camera such that you don't need the resolution
+ * of small triangles near the perimeter. For example, a value
+ * of 2 will produce stacks whose outside radius increases with
+ * the square of the stack index. A value of 1 will give uniform
+ * stacks.
+ *
+ * @param {number} radius Radius of the ground plane.
+ * @param {number} divisions Number of triangles in the ground plane (at least 3).
+ * @param {number} [stacks] Number of radial divisions (default=1).
+ * @param {number} [innerRadius] Default 0.
+ * @param {number} [stackPower] Power to raise stack size to for decreasing width.
+ * @return {Object.} The created vertices.
+ * @memberOf module:twgl/primitives
+ */
+function createDiscVertices(
+ radius,
+ divisions,
+ stacks,
+ innerRadius,
+ stackPower) {
+ if (divisions < 3) {
+ throw new Error('divisions must be at least 3');
+ }
+
+ stacks = stacks ? stacks : 1;
+ stackPower = stackPower ? stackPower : 1;
+ innerRadius = innerRadius ? innerRadius : 0;
+
+ // Note: We don't share the center vertex because that would
+ // mess up texture coordinates.
+ const numVertices = (divisions + 1) * (stacks + 1);
+
+ const positions = createAugmentedTypedArray(3, numVertices);
+ const normals = createAugmentedTypedArray(3, numVertices);
+ const texcoords = createAugmentedTypedArray(2, numVertices);
+ const indices = createAugmentedTypedArray(3, stacks * divisions * 2, Uint16Array);
+
+ let firstIndex = 0;
+ const radiusSpan = radius - innerRadius;
+ const pointsPerStack = divisions + 1;
+
+ // Build the disk one stack at a time.
+ for (let stack = 0; stack <= stacks; ++stack) {
+ const stackRadius = innerRadius + radiusSpan * Math.pow(stack / stacks, stackPower);
+
+ for (let i = 0; i <= divisions; ++i) {
+ const theta = 2.0 * Math.PI * i / divisions;
+ const x = stackRadius * Math.cos(theta);
+ const z = stackRadius * Math.sin(theta);
+
+ positions.push(x, 0, z);
+ normals.push(0, 1, 0);
+ texcoords.push(1 - (i / divisions), stack / stacks);
+ if (stack > 0 && i !== divisions) {
+ // a, b, c and d are the indices of the vertices of a quad. unless
+ // the current stack is the one closest to the center, in which case
+ // the vertices a and b connect to the center vertex.
+ const a = firstIndex + (i + 1);
+ const b = firstIndex + i;
+ const c = firstIndex + i - pointsPerStack;
+ const d = firstIndex + (i + 1) - pointsPerStack;
+
+ // Make a quad of the vertices a, b, c, d.
+ indices.push(a, b, c);
+ indices.push(a, c, d);
+ }
+ }
+
+ firstIndex += divisions + 1;
+ }
+
+ return {
+ position: positions,
+ normal: normals,
+ texcoord: texcoords,
+ indices: indices,
+ };
+}
+
+/**
+ * creates a random integer between 0 and range - 1 inclusive.
+ * @param {number} range
+ * @return {number} random value between 0 and range - 1 inclusive.
+ * @private
+ */
+function randInt(range) {
+ return Math.random() * range | 0;
+}
+
+/**
+ * Used to supply random colors
+ * @callback RandomColorFunc
+ * @param {number} ndx index of triangle/quad if unindexed or index of vertex if indexed
+ * @param {number} channel 0 = red, 1 = green, 2 = blue, 3 = alpha
+ * @return {number} a number from 0 to 255
+ * @memberOf module:twgl/primitives
+ */
+
+/**
+ * @typedef {Object} RandomVerticesOptions
+ * @property {number} [vertsPerColor] Defaults to 3 for non-indexed vertices
+ * @property {module:twgl/primitives.RandomColorFunc} [rand] A function to generate random numbers
+ * @memberOf module:twgl/primitives
+ */
+
+/**
+ * Creates an augmentedTypedArray of random vertex colors.
+ * If the vertices are indexed (have an indices array) then will
+ * just make random colors. Otherwise assumes they are triangles
+ * and makes one random color for every 3 vertices.
+ * @param {Object.} vertices Vertices as returned from one of the createXXXVertices functions.
+ * @param {module:twgl/primitives.RandomVerticesOptions} [options] options.
+ * @return {Object.} same vertices as passed in with `color` added.
+ * @memberOf module:twgl/primitives
+ */
+function makeRandomVertexColors(vertices, options) {
+ options = options || {};
+ const numElements = vertices.position.numElements;
+ const vColors = createAugmentedTypedArray(4, numElements, Uint8Array);
+ const rand = options.rand || function(ndx, channel) {
+ return channel < 3 ? randInt(256) : 255;
+ };
+ vertices.color = vColors;
+ if (vertices.indices) {
+ // just make random colors if index
+ for (let ii = 0; ii < numElements; ++ii) {
+ vColors.push(rand(ii, 0), rand(ii, 1), rand(ii, 2), rand(ii, 3));
+ }
+ } else {
+ // make random colors per triangle
+ const numVertsPerColor = options.vertsPerColor || 3;
+ const numSets = numElements / numVertsPerColor;
+ for (let ii = 0; ii < numSets; ++ii) { // eslint-disable-line
+ const color = [rand(ii, 0), rand(ii, 1), rand(ii, 2), rand(ii, 3)];
+ for (let jj = 0; jj < numVertsPerColor; ++jj) {
+ vColors.push(color);
+ }
+ }
+ }
+ return vertices;
+}
+
+/**
+ * creates a function that calls fn to create vertices and then
+ * creates a buffers for them
+ * @private
+ */
+function createBufferFunc(fn) {
+ return function(gl) {
+ const arrays = fn.apply(this, Array.prototype.slice.call(arguments, 1));
+ return createBuffersFromArrays(gl, arrays);
+ };
+}
+
+/**
+ * creates a function that calls fn to create vertices and then
+ * creates a bufferInfo object for them
+ * @private
+ */
+function createBufferInfoFunc(fn) {
+ return function(gl) {
+ const arrays = fn.apply(null, Array.prototype.slice.call(arguments, 1));
+ return createBufferInfoFromArrays(gl, arrays);
+ };
+}
+
+const arraySpecPropertyNames = [
+ "numComponents",
+ "size",
+ "type",
+ "normalize",
+ "stride",
+ "offset",
+ "attrib",
+ "name",
+ "attribName",
+];
+
+/**
+ * Copy elements from one array to another
+ *
+ * @param {Array|TypedArray} src source array
+ * @param {Array|TypedArray} dst dest array
+ * @param {number} dstNdx index in dest to copy src
+ * @param {number} [offset] offset to add to copied values
+ * @private
+ */
+function copyElements(src, dst, dstNdx, offset) {
+ offset = offset || 0;
+ const length = src.length;
+ for (let ii = 0; ii < length; ++ii) {
+ dst[dstNdx + ii] = src[ii] + offset;
+ }
+}
+
+/**
+ * Creates an array of the same time
+ *
+ * @param {(number[]|ArrayBufferView|module:twgl.FullArraySpec)} srcArray array who's type to copy
+ * @param {number} length size of new array
+ * @return {(number[]|ArrayBufferView|module:twgl.FullArraySpec)} array with same type as srcArray
+ * @private
+ */
+function createArrayOfSameType(srcArray, length) {
+ const arraySrc = getArray$1(srcArray);
+ const newArray = new arraySrc.constructor(length);
+ let newArraySpec = newArray;
+ // If it appears to have been augmented make new one augmented
+ if (arraySrc.numComponents && arraySrc.numElements) {
+ augmentTypedArray(newArray, arraySrc.numComponents);
+ }
+ // If it was a full spec make new one a full spec
+ if (srcArray.data) {
+ newArraySpec = {
+ data: newArray,
+ };
+ copyNamedProperties(arraySpecPropertyNames, srcArray, newArraySpec);
+ }
+ return newArraySpec;
+}
+
+/**
+ * Concatenates sets of vertices
+ *
+ * Assumes the vertices match in composition. For example
+ * if one set of vertices has positions, normals, and indices
+ * all sets of vertices must have positions, normals, and indices
+ * and of the same type.
+ *
+ * Example:
+ *
+ * const cubeVertices = twgl.primitives.createCubeVertices(2);
+ * const sphereVertices = twgl.primitives.createSphereVertices(1, 10, 10);
+ * // move the sphere 2 units up
+ * twgl.primitives.reorientVertices(
+ * sphereVertices, twgl.m4.translation([0, 2, 0]));
+ * // merge the sphere with the cube
+ * const cubeSphereVertices = twgl.primitives.concatVertices(
+ * [cubeVertices, sphereVertices]);
+ * // turn them into WebGL buffers and attrib data
+ * const bufferInfo = twgl.createBufferInfoFromArrays(gl, cubeSphereVertices);
+ *
+ * @param {module:twgl.Arrays[]} arrays Array of arrays of vertices
+ * @return {module:twgl.Arrays} The concatenated vertices.
+ * @memberOf module:twgl/primitives
+ */
+function concatVertices(arrayOfArrays) {
+ const names = {};
+ let baseName;
+ // get names of all arrays.
+ // and numElements for each set of vertices
+ for (let ii = 0; ii < arrayOfArrays.length; ++ii) {
+ const arrays = arrayOfArrays[ii];
+ Object.keys(arrays).forEach(function(name) { // eslint-disable-line
+ if (!names[name]) {
+ names[name] = [];
+ }
+ if (!baseName && name !== 'indices') {
+ baseName = name;
+ }
+ const arrayInfo = arrays[name];
+ const numComponents = getNumComponents$1(arrayInfo, name);
+ const array = getArray$1(arrayInfo);
+ const numElements = array.length / numComponents;
+ names[name].push(numElements);
+ });
+ }
+
+ // compute length of combined array
+ // and return one for reference
+ function getLengthOfCombinedArrays(name) {
+ let length = 0;
+ let arraySpec;
+ for (let ii = 0; ii < arrayOfArrays.length; ++ii) {
+ const arrays = arrayOfArrays[ii];
+ const arrayInfo = arrays[name];
+ const array = getArray$1(arrayInfo);
+ length += array.length;
+ if (!arraySpec || arrayInfo.data) {
+ arraySpec = arrayInfo;
+ }
+ }
+ return {
+ length: length,
+ spec: arraySpec,
+ };
+ }
+
+ function copyArraysToNewArray(name, base, newArray) {
+ let baseIndex = 0;
+ let offset = 0;
+ for (let ii = 0; ii < arrayOfArrays.length; ++ii) {
+ const arrays = arrayOfArrays[ii];
+ const arrayInfo = arrays[name];
+ const array = getArray$1(arrayInfo);
+ if (name === 'indices') {
+ copyElements(array, newArray, offset, baseIndex);
+ baseIndex += base[ii];
+ } else {
+ copyElements(array, newArray, offset);
+ }
+ offset += array.length;
+ }
+ }
+
+ const base = names[baseName];
+
+ const newArrays = {};
+ Object.keys(names).forEach(function(name) {
+ const info = getLengthOfCombinedArrays(name);
+ const newArraySpec = createArrayOfSameType(info.spec, info.length);
+ copyArraysToNewArray(name, base, getArray$1(newArraySpec));
+ newArrays[name] = newArraySpec;
+ });
+ return newArrays;
+}
+
+/**
+ * Creates a duplicate set of vertices
+ *
+ * This is useful for calling reorientVertices when you
+ * also want to keep the original available
+ *
+ * @param {module:twgl.Arrays} arrays of vertices
+ * @return {module:twgl.Arrays} The duplicated vertices.
+ * @memberOf module:twgl/primitives
+ */
+function duplicateVertices(arrays) {
+ const newArrays = {};
+ Object.keys(arrays).forEach(function(name) {
+ const arraySpec = arrays[name];
+ const srcArray = getArray$1(arraySpec);
+ const newArraySpec = createArrayOfSameType(arraySpec, srcArray.length);
+ copyElements(srcArray, getArray$1(newArraySpec), 0);
+ newArrays[name] = newArraySpec;
+ });
+ return newArrays;
+}
+
+const create3DFBufferInfo = createBufferInfoFunc(create3DFVertices);
+const create3DFBuffers = createBufferFunc(create3DFVertices);
+const createCubeBufferInfo = createBufferInfoFunc(createCubeVertices);
+const createCubeBuffers = createBufferFunc(createCubeVertices);
+const createPlaneBufferInfo = createBufferInfoFunc(createPlaneVertices);
+const createPlaneBuffers = createBufferFunc(createPlaneVertices);
+const createSphereBufferInfo = createBufferInfoFunc(createSphereVertices);
+const createSphereBuffers = createBufferFunc(createSphereVertices);
+const createTruncatedConeBufferInfo = createBufferInfoFunc(createTruncatedConeVertices);
+const createTruncatedConeBuffers = createBufferFunc(createTruncatedConeVertices);
+const createXYQuadBufferInfo = createBufferInfoFunc(createXYQuadVertices);
+const createXYQuadBuffers = createBufferFunc(createXYQuadVertices);
+const createCrescentBufferInfo = createBufferInfoFunc(createCrescentVertices);
+const createCrescentBuffers = createBufferFunc(createCrescentVertices);
+const createCylinderBufferInfo = createBufferInfoFunc(createCylinderVertices);
+const createCylinderBuffers = createBufferFunc(createCylinderVertices);
+const createTorusBufferInfo = createBufferInfoFunc(createTorusVertices);
+const createTorusBuffers = createBufferFunc(createTorusVertices);
+const createDiscBufferInfo = createBufferInfoFunc(createDiscVertices);
+const createDiscBuffers = createBufferFunc(createDiscVertices);
+
+// these were mis-spelled until 4.12
+const createCresentBufferInfo = createCrescentBufferInfo;
+const createCresentBuffers = createCrescentBuffers;
+const createCresentVertices = createCrescentVertices;
+
+var primitives = /*#__PURE__*/Object.freeze({
+ __proto__: null,
+ create3DFBufferInfo: create3DFBufferInfo,
+ create3DFBuffers: create3DFBuffers,
+ create3DFVertices: create3DFVertices,
+ createAugmentedTypedArray: createAugmentedTypedArray,
+ createCubeBufferInfo: createCubeBufferInfo,
+ createCubeBuffers: createCubeBuffers,
+ createCubeVertices: createCubeVertices,
+ createPlaneBufferInfo: createPlaneBufferInfo,
+ createPlaneBuffers: createPlaneBuffers,
+ createPlaneVertices: createPlaneVertices,
+ createSphereBufferInfo: createSphereBufferInfo,
+ createSphereBuffers: createSphereBuffers,
+ createSphereVertices: createSphereVertices,
+ createTruncatedConeBufferInfo: createTruncatedConeBufferInfo,
+ createTruncatedConeBuffers: createTruncatedConeBuffers,
+ createTruncatedConeVertices: createTruncatedConeVertices,
+ createXYQuadBufferInfo: createXYQuadBufferInfo,
+ createXYQuadBuffers: createXYQuadBuffers,
+ createXYQuadVertices: createXYQuadVertices,
+ createCresentBufferInfo: createCresentBufferInfo,
+ createCresentBuffers: createCresentBuffers,
+ createCresentVertices: createCresentVertices,
+ createCrescentBufferInfo: createCrescentBufferInfo,
+ createCrescentBuffers: createCrescentBuffers,
+ createCrescentVertices: createCrescentVertices,
+ createCylinderBufferInfo: createCylinderBufferInfo,
+ createCylinderBuffers: createCylinderBuffers,
+ createCylinderVertices: createCylinderVertices,
+ createTorusBufferInfo: createTorusBufferInfo,
+ createTorusBuffers: createTorusBuffers,
+ createTorusVertices: createTorusVertices,
+ createDiscBufferInfo: createDiscBufferInfo,
+ createDiscBuffers: createDiscBuffers,
+ createDiscVertices: createDiscVertices,
+ deindexVertices: deindexVertices,
+ flattenNormals: flattenNormals,
+ makeRandomVertexColors: makeRandomVertexColors,
+ reorientDirections: reorientDirections,
+ reorientNormals: reorientNormals,
+ reorientPositions: reorientPositions,
+ reorientVertices: reorientVertices,
+ concatVertices: concatVertices,
+ duplicateVertices: duplicateVertices
+});
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * Gets the gl version as a number
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @return {number} version of gl
+ * @private
+ */
+//function getVersionAsNumber(gl) {
+// return parseFloat(gl.getParameter(gl.VERSION).substr(6));
+//}
+
+/**
+ * Check if context is WebGL 2.0
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @return {bool} true if it's WebGL 2.0
+ * @memberOf module:twgl
+ */
+function isWebGL2(gl) {
+ // This is the correct check but it's slow
+ // return gl.getParameter(gl.VERSION).indexOf("WebGL 2.0") === 0;
+ // This might also be the correct check but I'm assuming it's slow-ish
+ // return gl instanceof WebGL2RenderingContext;
+ return !!gl.texStorage2D;
+}
+
+/**
+ * Check if context is WebGL 1.0
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @return {bool} true if it's WebGL 1.0
+ * @memberOf module:twgl
+ */
+function isWebGL1(gl) {
+ // This is the correct check but it's slow
+ // const version = getVersionAsNumber(gl);
+ // return version <= 1.0 && version > 0.0; // because as of 2016/5 Edge returns 0.96
+ // This might also be the correct check but I'm assuming it's slow-ish
+ // return gl instanceof WebGLRenderingContext;
+ return !gl.texStorage2D;
+}
+
+/**
+ * Gets a string for WebGL enum
+ *
+ * Note: Several enums are the same. Without more
+ * context (which function) it's impossible to always
+ * give the correct enum. As it is, for matching values
+ * it gives all enums. Checking the WebGL2RenderingContext
+ * that means
+ *
+ * 0 = ZERO | POINT | NONE | NO_ERROR
+ * 1 = ONE | LINES | SYNC_FLUSH_COMMANDS_BIT
+ * 32777 = BLEND_EQUATION_RGB | BLEND_EQUATION_RGB
+ * 36662 = COPY_READ_BUFFER | COPY_READ_BUFFER_BINDING
+ * 36663 = COPY_WRITE_BUFFER | COPY_WRITE_BUFFER_BINDING
+ * 36006 = FRAMEBUFFER_BINDING | DRAW_FRAMEBUFFER_BINDING
+ *
+ * It's also not useful for bits really unless you pass in individual bits.
+ * In other words
+ *
+ * const bits = gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT;
+ * twgl.glEnumToString(gl, bits); // not going to work
+ *
+ * Note that some enums only exist on extensions. If you
+ * want them to show up you need to pass the extension at least
+ * once. For example
+ *
+ * const ext = gl.getExtension('WEBGL_compressed_texture_s3tc');
+ * if (ext) {
+ * twgl.glEnumToString(ext, 0); // just prime the function
+ *
+ * ..later..
+ *
+ * const internalFormat = ext.COMPRESSED_RGB_S3TC_DXT1_EXT;
+ * console.log(twgl.glEnumToString(gl, internalFormat));
+ *
+ * Notice I didn't have to pass the extension the second time. This means
+ * you can have place that generically gets an enum for texture formats for example.
+ * and as long as you primed the function with the extensions
+ *
+ * If you're using `twgl.addExtensionsToContext` to enable your extensions
+ * then twgl will automatically get the extension's enums.
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext or any extension object
+ * @param {number} value the value of the enum you want to look up.
+ * @return {string} enum string or hex value
+ * @memberOf module:twgl
+ * @function glEnumToString
+ */
+const glEnumToString = (function() {
+ const haveEnumsForType = {};
+ const enums = {};
+
+ function addEnums(gl) {
+ const type = gl.constructor.name;
+ if (!haveEnumsForType[type]) {
+ for (const key in gl) {
+ if (typeof gl[key] === 'number') {
+ const existing = enums[gl[key]];
+ enums[gl[key]] = existing ? `${existing} | ${key}` : key;
+ }
+ }
+ haveEnumsForType[type] = true;
+ }
+ }
+
+ return function glEnumToString(gl, value) {
+ addEnums(gl);
+ return enums[value] || ("0x" + value.toString(16));
+ };
+}());
+
+var utils = /*#__PURE__*/Object.freeze({
+ __proto__: null,
+ glEnumToString: glEnumToString,
+ isWebGL1: isWebGL1,
+ isWebGL2: isWebGL2
+});
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+const defaults$1 = {
+ textureColor: new Uint8Array([128, 192, 255, 255]),
+ textureOptions: {},
+ crossOrigin: undefined,
+};
+const isArrayBuffer$1 = isArrayBuffer;
+
+// Should we make this on demand?
+let s_ctx;
+function getShared2DContext() {
+ s_ctx = s_ctx ||
+ ((typeof document !== 'undefined' && document.createElement)
+ ? document.createElement("canvas").getContext("2d")
+ : null);
+ return s_ctx;
+}
+
+// NOTE: Chrome supports 2D canvas in a Worker (behind flag as of v64 but
+// not only does Firefox NOT support it but Firefox freezes immediately
+// if you try to create one instead of just returning null and continuing.
+// : (global.OffscreenCanvas && (new global.OffscreenCanvas(1, 1)).getContext("2d")); // OffscreenCanvas may not support 2d
+
+// NOTE: We can maybe remove some of the need for the 2d canvas. In WebGL2
+// we can use the various unpack settings. Otherwise we could try using
+// the ability of an ImageBitmap to be cut. Unfortunately cutting an ImageBitmap
+// is async and the current TWGL code expects a non-Async result though that
+// might not be a problem. ImageBitmap though is not available in Edge or Safari
+// as of 2018-01-02
+
+/* PixelFormat */
+const ALPHA = 0x1906;
+const RGB = 0x1907;
+const RGBA = 0x1908;
+const LUMINANCE = 0x1909;
+const LUMINANCE_ALPHA = 0x190A;
+const DEPTH_COMPONENT = 0x1902;
+const DEPTH_STENCIL = 0x84F9;
+
+/* TextureWrapMode */
+// const REPEAT = 0x2901;
+// const MIRRORED_REPEAT = 0x8370;
+const CLAMP_TO_EDGE = 0x812f;
+
+/* TextureMagFilter */
+const NEAREST = 0x2600;
+const LINEAR = 0x2601;
+
+/* TextureMinFilter */
+// const NEAREST_MIPMAP_NEAREST = 0x2700;
+// const LINEAR_MIPMAP_NEAREST = 0x2701;
+// const NEAREST_MIPMAP_LINEAR = 0x2702;
+// const LINEAR_MIPMAP_LINEAR = 0x2703;
+
+/* Texture Target */
+const TEXTURE_2D = 0x0de1;
+const TEXTURE_CUBE_MAP = 0x8513;
+const TEXTURE_3D = 0x806f;
+const TEXTURE_2D_ARRAY = 0x8c1a;
+
+/* Cubemap Targets */
+const TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515;
+const TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516;
+const TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517;
+const TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518;
+const TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519;
+const TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851a;
+
+/* Texture Parameters */
+const TEXTURE_MIN_FILTER = 0x2801;
+const TEXTURE_MAG_FILTER = 0x2800;
+const TEXTURE_WRAP_S = 0x2802;
+const TEXTURE_WRAP_T = 0x2803;
+const TEXTURE_WRAP_R = 0x8072;
+const TEXTURE_MIN_LOD = 0x813a;
+const TEXTURE_MAX_LOD = 0x813b;
+const TEXTURE_BASE_LEVEL = 0x813c;
+const TEXTURE_MAX_LEVEL = 0x813d;
+
+
+/* Pixel store */
+const UNPACK_ALIGNMENT = 0x0cf5;
+const UNPACK_ROW_LENGTH = 0x0cf2;
+const UNPACK_IMAGE_HEIGHT = 0x806e;
+const UNPACK_SKIP_PIXELS = 0x0cf4;
+const UNPACK_SKIP_ROWS = 0x0cf3;
+const UNPACK_SKIP_IMAGES = 0x806d;
+const UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243;
+const UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241;
+const UNPACK_FLIP_Y_WEBGL = 0x9240;
+
+const R8 = 0x8229;
+const R8_SNORM = 0x8F94;
+const R16F = 0x822D;
+const R32F = 0x822E;
+const R8UI = 0x8232;
+const R8I = 0x8231;
+const RG16UI = 0x823A;
+const RG16I = 0x8239;
+const RG32UI = 0x823C;
+const RG32I = 0x823B;
+const RG8 = 0x822B;
+const RG8_SNORM = 0x8F95;
+const RG16F = 0x822F;
+const RG32F = 0x8230;
+const RG8UI = 0x8238;
+const RG8I = 0x8237;
+const R16UI = 0x8234;
+const R16I = 0x8233;
+const R32UI = 0x8236;
+const R32I = 0x8235;
+const RGB8 = 0x8051;
+const SRGB8 = 0x8C41;
+const RGB565 = 0x8D62;
+const RGB8_SNORM = 0x8F96;
+const R11F_G11F_B10F = 0x8C3A;
+const RGB9_E5 = 0x8C3D;
+const RGB16F = 0x881B;
+const RGB32F = 0x8815;
+const RGB8UI = 0x8D7D;
+const RGB8I = 0x8D8F;
+const RGB16UI = 0x8D77;
+const RGB16I = 0x8D89;
+const RGB32UI = 0x8D71;
+const RGB32I = 0x8D83;
+const RGBA8 = 0x8058;
+const SRGB8_ALPHA8 = 0x8C43;
+const RGBA8_SNORM = 0x8F97;
+const RGB5_A1 = 0x8057;
+const RGBA4 = 0x8056;
+const RGB10_A2 = 0x8059;
+const RGBA16F = 0x881A;
+const RGBA32F = 0x8814;
+const RGBA8UI = 0x8D7C;
+const RGBA8I = 0x8D8E;
+const RGB10_A2UI = 0x906F;
+const RGBA16UI = 0x8D76;
+const RGBA16I = 0x8D88;
+const RGBA32I = 0x8D82;
+const RGBA32UI = 0x8D70;
+
+const DEPTH_COMPONENT16 = 0x81A5;
+const DEPTH_COMPONENT24 = 0x81A6;
+const DEPTH_COMPONENT32F = 0x8CAC;
+const DEPTH32F_STENCIL8 = 0x8CAD;
+const DEPTH24_STENCIL8 = 0x88F0;
+
+/* DataType */
+const BYTE$2 = 0x1400;
+const UNSIGNED_BYTE$2 = 0x1401;
+const SHORT$2 = 0x1402;
+const UNSIGNED_SHORT$2 = 0x1403;
+const INT$2 = 0x1404;
+const UNSIGNED_INT$2 = 0x1405;
+const FLOAT$2 = 0x1406;
+const UNSIGNED_SHORT_4_4_4_4$1 = 0x8033;
+const UNSIGNED_SHORT_5_5_5_1$1 = 0x8034;
+const UNSIGNED_SHORT_5_6_5$1 = 0x8363;
+const HALF_FLOAT$1 = 0x140B;
+const HALF_FLOAT_OES = 0x8D61; // Thanks Khronos for making this different >:(
+const UNSIGNED_INT_2_10_10_10_REV$1 = 0x8368;
+const UNSIGNED_INT_10F_11F_11F_REV$1 = 0x8C3B;
+const UNSIGNED_INT_5_9_9_9_REV$1 = 0x8C3E;
+const FLOAT_32_UNSIGNED_INT_24_8_REV$1 = 0x8DAD;
+const UNSIGNED_INT_24_8$1 = 0x84FA;
+
+const RG = 0x8227;
+const RG_INTEGER = 0x8228;
+const RED = 0x1903;
+const RED_INTEGER = 0x8D94;
+const RGB_INTEGER = 0x8D98;
+const RGBA_INTEGER = 0x8D99;
+
+const formatInfo = {};
+{
+ // NOTE: this is named `numColorComponents` vs `numComponents` so we can let Uglify mangle
+ // the name.
+ const f = formatInfo;
+ f[ALPHA] = { numColorComponents: 1, };
+ f[LUMINANCE] = { numColorComponents: 1, };
+ f[LUMINANCE_ALPHA] = { numColorComponents: 2, };
+ f[RGB] = { numColorComponents: 3, };
+ f[RGBA] = { numColorComponents: 4, };
+ f[RED] = { numColorComponents: 1, };
+ f[RED_INTEGER] = { numColorComponents: 1, };
+ f[RG] = { numColorComponents: 2, };
+ f[RG_INTEGER] = { numColorComponents: 2, };
+ f[RGB] = { numColorComponents: 3, };
+ f[RGB_INTEGER] = { numColorComponents: 3, };
+ f[RGBA] = { numColorComponents: 4, };
+ f[RGBA_INTEGER] = { numColorComponents: 4, };
+ f[DEPTH_COMPONENT] = { numColorComponents: 1, };
+ f[DEPTH_STENCIL] = { numColorComponents: 2, };
+}
+
+/**
+ * @typedef {Object} TextureFormatDetails
+ * @property {number} textureFormat format to pass texImage2D and similar functions.
+ * @property {boolean} colorRenderable true if you can render to this format of texture.
+ * @property {boolean} textureFilterable true if you can filter the texture, false if you can ony use `NEAREST`.
+ * @property {number[]} type Array of possible types you can pass to texImage2D and similar function
+ * @property {Object.} bytesPerElementMap A map of types to bytes per element
+ * @private
+ */
+
+let s_textureInternalFormatInfo;
+function getTextureInternalFormatInfo(internalFormat) {
+ if (!s_textureInternalFormatInfo) {
+ // NOTE: these properties need unique names so we can let Uglify mangle the name.
+ const t = {};
+ // unsized formats
+ t[ALPHA] = { textureFormat: ALPHA, colorRenderable: true, textureFilterable: true, bytesPerElement: [1, 2, 2, 4], type: [UNSIGNED_BYTE$2, HALF_FLOAT$1, HALF_FLOAT_OES, FLOAT$2], };
+ t[LUMINANCE] = { textureFormat: LUMINANCE, colorRenderable: true, textureFilterable: true, bytesPerElement: [1, 2, 2, 4], type: [UNSIGNED_BYTE$2, HALF_FLOAT$1, HALF_FLOAT_OES, FLOAT$2], };
+ t[LUMINANCE_ALPHA] = { textureFormat: LUMINANCE_ALPHA, colorRenderable: true, textureFilterable: true, bytesPerElement: [2, 4, 4, 8], type: [UNSIGNED_BYTE$2, HALF_FLOAT$1, HALF_FLOAT_OES, FLOAT$2], };
+ t[RGB] = { textureFormat: RGB, colorRenderable: true, textureFilterable: true, bytesPerElement: [3, 6, 6, 12, 2], type: [UNSIGNED_BYTE$2, HALF_FLOAT$1, HALF_FLOAT_OES, FLOAT$2, UNSIGNED_SHORT_5_6_5$1], };
+ t[RGBA] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4, 8, 8, 16, 2, 2], type: [UNSIGNED_BYTE$2, HALF_FLOAT$1, HALF_FLOAT_OES, FLOAT$2, UNSIGNED_SHORT_4_4_4_4$1, UNSIGNED_SHORT_5_5_5_1$1], };
+
+ // sized formats
+ t[R8] = { textureFormat: RED, colorRenderable: true, textureFilterable: true, bytesPerElement: [1], type: [UNSIGNED_BYTE$2], };
+ t[R8_SNORM] = { textureFormat: RED, colorRenderable: false, textureFilterable: true, bytesPerElement: [1], type: [BYTE$2], };
+ t[R16F] = { textureFormat: RED, colorRenderable: false, textureFilterable: true, bytesPerElement: [4, 2], type: [FLOAT$2, HALF_FLOAT$1], };
+ t[R32F] = { textureFormat: RED, colorRenderable: false, textureFilterable: false, bytesPerElement: [4], type: [FLOAT$2], };
+ t[R8UI] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [1], type: [UNSIGNED_BYTE$2], };
+ t[R8I] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [1], type: [BYTE$2], };
+ t[R16UI] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [UNSIGNED_SHORT$2], };
+ t[R16I] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [SHORT$2], };
+ t[R32UI] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT$2], };
+ t[R32I] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [INT$2], };
+ t[RG8] = { textureFormat: RG, colorRenderable: true, textureFilterable: true, bytesPerElement: [2], type: [UNSIGNED_BYTE$2], };
+ t[RG8_SNORM] = { textureFormat: RG, colorRenderable: false, textureFilterable: true, bytesPerElement: [2], type: [BYTE$2], };
+ t[RG16F] = { textureFormat: RG, colorRenderable: false, textureFilterable: true, bytesPerElement: [8, 4], type: [FLOAT$2, HALF_FLOAT$1], };
+ t[RG32F] = { textureFormat: RG, colorRenderable: false, textureFilterable: false, bytesPerElement: [8], type: [FLOAT$2], };
+ t[RG8UI] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [UNSIGNED_BYTE$2], };
+ t[RG8I] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [BYTE$2], };
+ t[RG16UI] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_SHORT$2], };
+ t[RG16I] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [SHORT$2], };
+ t[RG32UI] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [UNSIGNED_INT$2], };
+ t[RG32I] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [INT$2], };
+ t[RGB8] = { textureFormat: RGB, colorRenderable: true, textureFilterable: true, bytesPerElement: [3], type: [UNSIGNED_BYTE$2], };
+ t[SRGB8] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [3], type: [UNSIGNED_BYTE$2], };
+ t[RGB565] = { textureFormat: RGB, colorRenderable: true, textureFilterable: true, bytesPerElement: [3, 2], type: [UNSIGNED_BYTE$2, UNSIGNED_SHORT_5_6_5$1], };
+ t[RGB8_SNORM] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [3], type: [BYTE$2], };
+ t[R11F_G11F_B10F] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [12, 6, 4], type: [FLOAT$2, HALF_FLOAT$1, UNSIGNED_INT_10F_11F_11F_REV$1], };
+ t[RGB9_E5] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [12, 6, 4], type: [FLOAT$2, HALF_FLOAT$1, UNSIGNED_INT_5_9_9_9_REV$1], };
+ t[RGB16F] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [12, 6], type: [FLOAT$2, HALF_FLOAT$1], };
+ t[RGB32F] = { textureFormat: RGB, colorRenderable: false, textureFilterable: false, bytesPerElement: [12], type: [FLOAT$2], };
+ t[RGB8UI] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [3], type: [UNSIGNED_BYTE$2], };
+ t[RGB8I] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [3], type: [BYTE$2], };
+ t[RGB16UI] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [6], type: [UNSIGNED_SHORT$2], };
+ t[RGB16I] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [6], type: [SHORT$2], };
+ t[RGB32UI] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [12], type: [UNSIGNED_INT$2], };
+ t[RGB32I] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [12], type: [INT$2], };
+ t[RGBA8] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4], type: [UNSIGNED_BYTE$2], };
+ t[SRGB8_ALPHA8] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4], type: [UNSIGNED_BYTE$2], };
+ t[RGBA8_SNORM] = { textureFormat: RGBA, colorRenderable: false, textureFilterable: true, bytesPerElement: [4], type: [BYTE$2], };
+ t[RGB5_A1] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4, 2, 4], type: [UNSIGNED_BYTE$2, UNSIGNED_SHORT_5_5_5_1$1, UNSIGNED_INT_2_10_10_10_REV$1], };
+ t[RGBA4] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4, 2], type: [UNSIGNED_BYTE$2, UNSIGNED_SHORT_4_4_4_4$1], };
+ t[RGB10_A2] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4], type: [UNSIGNED_INT_2_10_10_10_REV$1], };
+ t[RGBA16F] = { textureFormat: RGBA, colorRenderable: false, textureFilterable: true, bytesPerElement: [16, 8], type: [FLOAT$2, HALF_FLOAT$1], };
+ t[RGBA32F] = { textureFormat: RGBA, colorRenderable: false, textureFilterable: false, bytesPerElement: [16], type: [FLOAT$2], };
+ t[RGBA8UI] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_BYTE$2], };
+ t[RGBA8I] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [BYTE$2], };
+ t[RGB10_A2UI] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT_2_10_10_10_REV$1], };
+ t[RGBA16UI] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [UNSIGNED_SHORT$2], };
+ t[RGBA16I] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [SHORT$2], };
+ t[RGBA32I] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [16], type: [INT$2], };
+ t[RGBA32UI] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [16], type: [UNSIGNED_INT$2], };
+ // Sized Internal
+ t[DEPTH_COMPONENT16] = { textureFormat: DEPTH_COMPONENT, colorRenderable: true, textureFilterable: false, bytesPerElement: [2, 4], type: [UNSIGNED_SHORT$2, UNSIGNED_INT$2], };
+ t[DEPTH_COMPONENT24] = { textureFormat: DEPTH_COMPONENT, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT$2], };
+ t[DEPTH_COMPONENT32F] = { textureFormat: DEPTH_COMPONENT, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [FLOAT$2], };
+ t[DEPTH24_STENCIL8] = { textureFormat: DEPTH_STENCIL, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT_24_8$1], };
+ t[DEPTH32F_STENCIL8] = { textureFormat: DEPTH_STENCIL, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [FLOAT_32_UNSIGNED_INT_24_8_REV$1], };
+
+ Object.keys(t).forEach(function(internalFormat) {
+ const info = t[internalFormat];
+ info.bytesPerElementMap = {};
+ info.bytesPerElement.forEach(function(bytesPerElement, ndx) {
+ const type = info.type[ndx];
+ info.bytesPerElementMap[type] = bytesPerElement;
+ });
+ });
+ s_textureInternalFormatInfo = t;
+ }
+ return s_textureInternalFormatInfo[internalFormat];
+}
+
+/**
+ * Gets the number of bytes per element for a given internalFormat / type
+ * @param {number} internalFormat The internalFormat parameter from texImage2D etc..
+ * @param {number} type The type parameter for texImage2D etc..
+ * @return {number} the number of bytes per element for the given internalFormat, type combo
+ * @memberOf module:twgl/textures
+ */
+function getBytesPerElementForInternalFormat(internalFormat, type) {
+ const info = getTextureInternalFormatInfo(internalFormat);
+ if (!info) {
+ throw "unknown internal format";
+ }
+ const bytesPerElement = info.bytesPerElementMap[type];
+ if (bytesPerElement === undefined) {
+ throw "unknown internal format";
+ }
+ return bytesPerElement;
+}
+
+/**
+ * Info related to a specific texture internalFormat as returned
+ * from {@link module:twgl/textures.getFormatAndTypeForInternalFormat}.
+ *
+ * @typedef {Object} TextureFormatInfo
+ * @property {number} format Format to pass to texImage2D and related functions
+ * @property {number} type Type to pass to texImage2D and related functions
+ * @memberOf module:twgl/textures
+ */
+
+/**
+ * Gets the format and type for a given internalFormat
+ *
+ * @param {number} internalFormat The internal format
+ * @return {module:twgl/textures.TextureFormatInfo} the corresponding format and type,
+ * @memberOf module:twgl/textures
+ */
+function getFormatAndTypeForInternalFormat(internalFormat) {
+ const info = getTextureInternalFormatInfo(internalFormat);
+ if (!info) {
+ throw "unknown internal format";
+ }
+ return {
+ format: info.textureFormat,
+ type: info.type[0],
+ };
+}
+
+/**
+ * Returns true if value is power of 2
+ * @param {number} value number to check.
+ * @return true if value is power of 2
+ * @private
+ */
+function isPowerOf2(value) {
+ return (value & (value - 1)) === 0;
+}
+
+/**
+ * Gets whether or not we can generate mips for the given
+ * internal format.
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {number} width The width parameter from texImage2D etc..
+ * @param {number} height The height parameter from texImage2D etc..
+ * @param {number} internalFormat The internalFormat parameter from texImage2D etc..
+ * @return {boolean} true if we can generate mips
+ * @memberOf module:twgl/textures
+ */
+function canGenerateMipmap(gl, width, height, internalFormat) {
+ if (!isWebGL2(gl)) {
+ return isPowerOf2(width) && isPowerOf2(height);
+ }
+ const info = getTextureInternalFormatInfo(internalFormat);
+ if (!info) {
+ throw "unknown internal format";
+ }
+ return info.colorRenderable && info.textureFilterable;
+}
+
+/**
+ * Gets whether or not we can generate mips for the given format
+ * @param {number} internalFormat The internalFormat parameter from texImage2D etc..
+ * @return {boolean} true if we can generate mips
+ * @memberOf module:twgl/textures
+ */
+function canFilter(internalFormat) {
+ const info = getTextureInternalFormatInfo(internalFormat);
+ if (!info) {
+ throw "unknown internal format";
+ }
+ return info.textureFilterable;
+}
+
+/**
+ * Gets the number of components for a given image format.
+ * @param {number} format the format.
+ * @return {number} the number of components for the format.
+ * @memberOf module:twgl/textures
+ */
+function getNumComponentsForFormat(format) {
+ const info = formatInfo[format];
+ if (!info) {
+ throw "unknown format: " + format;
+ }
+ return info.numColorComponents;
+}
+
+/**
+ * Gets the texture type for a given array type.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @return {number} the gl texture type
+ * @private
+ */
+function getTextureTypeForArrayType(gl, src, defaultType) {
+ if (isArrayBuffer$1(src)) {
+ return getGLTypeForTypedArray(src);
+ }
+ return defaultType || UNSIGNED_BYTE$2;
+}
+
+function guessDimensions(gl, target, width, height, numElements) {
+ if (numElements % 1 !== 0) {
+ throw "can't guess dimensions";
+ }
+ if (!width && !height) {
+ const size = Math.sqrt(numElements / (target === TEXTURE_CUBE_MAP ? 6 : 1));
+ if (size % 1 === 0) {
+ width = size;
+ height = size;
+ } else {
+ width = numElements;
+ height = 1;
+ }
+ } else if (!height) {
+ height = numElements / width;
+ if (height % 1) {
+ throw "can't guess dimensions";
+ }
+ } else if (!width) {
+ width = numElements / height;
+ if (width % 1) {
+ throw "can't guess dimensions";
+ }
+ }
+ return {
+ width: width,
+ height: height,
+ };
+}
+
+/**
+ * Sets the default texture color.
+ *
+ * The default texture color is used when loading textures from
+ * urls. Because the URL will be loaded async we'd like to be
+ * able to use the texture immediately. By putting a 1x1 pixel
+ * color in the texture we can start using the texture before
+ * the URL has loaded.
+ *
+ * @param {number[]} color Array of 4 values in the range 0 to 1
+ * @deprecated see {@link module:twgl.setDefaults}
+ * @memberOf module:twgl/textures
+ */
+function setDefaultTextureColor(color) {
+ defaults$1.textureColor = new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);
+}
+
+function setDefaults$1(newDefaults) {
+ copyExistingProperties(newDefaults, defaults$1);
+ if (newDefaults.textureColor) {
+ setDefaultTextureColor(newDefaults.textureColor);
+ }
+}
+
+/**
+ * A function to generate the source for a texture.
+ * @callback TextureFunc
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @param {module:twgl.TextureOptions} options the texture options
+ * @return {*} Returns any of the things documented for `src` for {@link module:twgl.TextureOptions}.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Texture options passed to most texture functions. Each function will use whatever options
+ * are appropriate for its needs. This lets you pass the same options to all functions.
+ *
+ * Note: A `TexImageSource` is defined in the WebGL spec as a `HTMLImageElement`, `HTMLVideoElement`,
+ * `HTMLCanvasElement`, `ImageBitmap`, or `ImageData`.
+ *
+ * @typedef {Object} TextureOptions
+ * @property {number} [target] the type of texture `gl.TEXTURE_2D` or `gl.TEXTURE_CUBE_MAP`. Defaults to `gl.TEXTURE_2D`.
+ * @property {number} [level] the mip level to affect. Defaults to 0. Note, if set auto will be considered false unless explicitly set to true.
+ * @property {number} [width] the width of the texture. Only used if src is an array or typed array or null.
+ * @property {number} [height] the height of a texture. Only used if src is an array or typed array or null.
+ * @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` .
+ * @property {number} [min] the min filter setting (eg. `gl.LINEAR`). Defaults to `gl.NEAREST_MIPMAP_LINEAR`
+ * or if texture is not a power of 2 on both dimensions then defaults to `gl.LINEAR`.
+ * @property {number} [mag] the mag filter setting (eg. `gl.LINEAR`). Defaults to `gl.LINEAR`
+ * @property {number} [minMag] both the min and mag filter settings.
+ * @property {number} [internalFormat] internal format for texture. Defaults to `gl.RGBA`
+ * @property {number} [format] format for texture. Defaults to `gl.RGBA`.
+ * @property {number} [type] type for texture. Defaults to `gl.UNSIGNED_BYTE` unless `src` is ArrayBufferView. If `src`
+ * is ArrayBufferView defaults to type that matches ArrayBufferView type.
+ * @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
+ * @property {number} [wrapS] Texture wrapping for S. Defaults to `gl.REPEAT` and `gl.CLAMP_TO_EDGE` for cube. If set takes precedence over `wrap`.
+ * @property {number} [wrapT] Texture wrapping for T. Defaults to `gl.REPEAT` and `gl.CLAMP_TO_EDGE` for cube. If set takes precedence over `wrap`.
+ * @property {number} [wrapR] Texture wrapping for R. Defaults to `gl.REPEAT` and `gl.CLAMP_TO_EDGE` for cube. If set takes precedence over `wrap`.
+ * @property {number} [minLod] TEXTURE_MIN_LOD setting
+ * @property {number} [maxLod] TEXTURE_MAX_LOD setting
+ * @property {number} [baseLevel] TEXTURE_BASE_LEVEL setting
+ * @property {number} [maxLevel] TEXTURE_MAX_LEVEL setting
+ * @property {number} [unpackAlignment] The `gl.UNPACK_ALIGNMENT` used when uploading an array. Defaults to 1.
+ * @property {number[]|ArrayBufferView} [color] Color to initialize this texture with if loading an image asynchronously.
+ * The default use a blue 1x1 pixel texture. You can set another default by calling `twgl.setDefaults`
+ * or you can set an individual texture's initial color by setting this property. Example: `[1, .5, .5, 1]` = pink
+ * @property {number} [premultiplyAlpha] Whether or not to premultiply alpha. Defaults to whatever the current setting is.
+ * This lets you set it once before calling `twgl.createTexture` or `twgl.createTextures` and only override
+ * the current setting for specific textures.
+ * @property {number} [flipY] Whether or not to flip the texture vertically on upload. Defaults to whatever the current setting is.
+ * This lets you set it once before calling `twgl.createTexture` or `twgl.createTextures` and only override
+ * the current setting for specific textures.
+ * @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.
+ * This lets you set it once before calling `twgl.createTexture` or `twgl.createTextures` and only override
+ * the current setting for specific textures.
+ * @property {boolean} [auto] If `undefined` or `true`, in WebGL1, texture filtering is set automatically for non-power of 2 images and
+ * mips are generated for power of 2 images. In WebGL2 mips are generated if they can be. Note: if `level` is set above
+ * then then `auto` is assumed to be `false` unless explicity set to `true`.
+ * @property {number[]} [cubeFaceOrder] The order that cube faces are pulled out of an img or set of images. The default is
+ *
+ * [gl.TEXTURE_CUBE_MAP_POSITIVE_X,
+ * gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
+ * gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
+ * gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
+ * gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
+ * gl.TEXTURE_CUBE_MAP_NEGATIVE_Z]
+ *
+ * @property {(number[]|ArrayBufferView|TexImageSource|TexImageSource[]|string|string[]|module:twgl.TextureFunc)} [src] source for texture
+ *
+ * If `string` then it's assumed to be a URL to an image. The image will be downloaded async. A usable
+ * 1x1 pixel texture will be returned immediately. The texture will be updated once the image has downloaded.
+ * If `target` is `gl.TEXTURE_CUBE_MAP` will attempt to divide image into 6 square pieces. 1x6, 6x1, 3x2, 2x3.
+ * The pieces will be uploaded in `cubeFaceOrder`
+ *
+ * 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.
+ *
+ * If `string[]` or `TexImageSource[]` and target is `gl.TEXTURE_2D_ARRAY` then each entry is a slice of the a 2d array texture
+ * and will be scaled to the specified width and height OR to the size of the first image that loads.
+ *
+ * If `TexImageSource` then it wil be used immediately to create the contents of the texture. Examples `HTMLImageElement`,
+ * `HTMLCanvasElement`, `HTMLVideoElement`.
+ *
+ * If `number[]` or `ArrayBufferView` it's assumed to be data for a texture. If `width` or `height` is
+ * not specified it is guessed as follows. First the number of elements is computed by `src.length / numComponents`
+ * where `numComponents` is derived from `format`. If `target` is `gl.TEXTURE_CUBE_MAP` then `numElements` is divided
+ * by 6. Then
+ *
+ * * If neither `width` nor `height` are specified and `sqrt(numElements)` is an integer then width and height
+ * are set to `sqrt(numElements)`. Otherwise `width = numElements` and `height = 1`.
+ *
+ * * If only one of `width` or `height` is specified then the other equals `numElements / specifiedDimension`.
+ *
+ * If `number[]` will be converted to `type`.
+ *
+ * If `src` is a function it will be called with a `WebGLRenderingContext` and these options.
+ * Whatever it returns is subject to these rules. So it can return a string url, an `HTMLElement`
+ * an array etc...
+ *
+ * If `src` is undefined then an empty texture will be created of size `width` by `height`.
+ *
+ * @property {string} [crossOrigin] What to set the crossOrigin property of images when they are downloaded.
+ * default: undefined. Also see {@link module:twgl.setDefaults}.
+ *
+ * @memberOf module:twgl
+ */
+
+// NOTE: While querying GL is considered slow it's not remotely as slow
+// as uploading a texture. On top of that you're unlikely to call this in
+// a perf critical loop. Even if upload a texture every frame that's unlikely
+// to be more than 1 or 2 textures a frame. In other words, the benefits of
+// making the API easy to use outweigh any supposed perf benefits
+//
+// Also note I get that having one global of these is bad practice.
+// As long as it's used correctly it means no garbage which probably
+// doesn't matter when dealing with textures but old habits die hard.
+const lastPackState = {};
+
+/**
+ * Saves any packing state that will be set based on the options.
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @private
+ */
+function savePackState(gl, options) {
+ if (options.colorspaceConversion !== undefined) {
+ lastPackState.colorspaceConversion = gl.getParameter(UNPACK_COLORSPACE_CONVERSION_WEBGL);
+ gl.pixelStorei(UNPACK_COLORSPACE_CONVERSION_WEBGL, options.colorspaceConversion);
+ }
+ if (options.premultiplyAlpha !== undefined) {
+ lastPackState.premultiplyAlpha = gl.getParameter(UNPACK_PREMULTIPLY_ALPHA_WEBGL);
+ gl.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL, options.premultiplyAlpha);
+ }
+ if (options.flipY !== undefined) {
+ lastPackState.flipY = gl.getParameter(UNPACK_FLIP_Y_WEBGL);
+ gl.pixelStorei(UNPACK_FLIP_Y_WEBGL, options.flipY);
+ }
+}
+
+/**
+ * Restores any packing state that was set based on the options.
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @private
+ */
+function restorePackState(gl, options) {
+ if (options.colorspaceConversion !== undefined) {
+ gl.pixelStorei(UNPACK_COLORSPACE_CONVERSION_WEBGL, lastPackState.colorspaceConversion);
+ }
+ if (options.premultiplyAlpha !== undefined) {
+ gl.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL, lastPackState.premultiplyAlpha);
+ }
+ if (options.flipY !== undefined) {
+ gl.pixelStorei(UNPACK_FLIP_Y_WEBGL, lastPackState.flipY);
+ }
+}
+
+/**
+ * Saves state related to data size
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @private
+ */
+function saveSkipState(gl) {
+ lastPackState.unpackAlignment = gl.getParameter(UNPACK_ALIGNMENT);
+ if (isWebGL2(gl)) {
+ lastPackState.unpackRowLength = gl.getParameter(UNPACK_ROW_LENGTH);
+ lastPackState.unpackImageHeight = gl.getParameter(UNPACK_IMAGE_HEIGHT);
+ lastPackState.unpackSkipPixels = gl.getParameter(UNPACK_SKIP_PIXELS);
+ lastPackState.unpackSkipRows = gl.getParameter(UNPACK_SKIP_ROWS);
+ lastPackState.unpackSkipImages = gl.getParameter(UNPACK_SKIP_IMAGES);
+ }
+}
+
+/**
+ * Restores state related to data size
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @private
+ */
+function restoreSkipState(gl) {
+ gl.pixelStorei(UNPACK_ALIGNMENT, lastPackState.unpackAlignment);
+ if (isWebGL2(gl)) {
+ gl.pixelStorei(UNPACK_ROW_LENGTH, lastPackState.unpackRowLength);
+ gl.pixelStorei(UNPACK_IMAGE_HEIGHT, lastPackState.unpackImageHeight);
+ gl.pixelStorei(UNPACK_SKIP_PIXELS, lastPackState.unpackSkipPixels);
+ gl.pixelStorei(UNPACK_SKIP_ROWS, lastPackState.unpackSkipRows);
+ gl.pixelStorei(UNPACK_SKIP_IMAGES, lastPackState.unpackSkipImages);
+ }
+}
+
+
+/**
+ * Sets the parameters of a texture or sampler
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {number|WebGLSampler} target texture target or sampler
+ * @param {function()} parameteriFn texParameteri or samplerParameteri fn
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @private
+ */
+function setTextureSamplerParameters(gl, target, parameteriFn, options) {
+ if (options.minMag) {
+ parameteriFn.call(gl, target, TEXTURE_MIN_FILTER, options.minMag);
+ parameteriFn.call(gl, target, TEXTURE_MAG_FILTER, options.minMag);
+ }
+ if (options.min) {
+ parameteriFn.call(gl, target, TEXTURE_MIN_FILTER, options.min);
+ }
+ if (options.mag) {
+ parameteriFn.call(gl, target, TEXTURE_MAG_FILTER, options.mag);
+ }
+ if (options.wrap) {
+ parameteriFn.call(gl, target, TEXTURE_WRAP_S, options.wrap);
+ parameteriFn.call(gl, target, TEXTURE_WRAP_T, options.wrap);
+ if (target === TEXTURE_3D || isSampler(gl, target)) {
+ parameteriFn.call(gl, target, TEXTURE_WRAP_R, options.wrap);
+ }
+ }
+ if (options.wrapR) {
+ parameteriFn.call(gl, target, TEXTURE_WRAP_R, options.wrapR);
+ }
+ if (options.wrapS) {
+ parameteriFn.call(gl, target, TEXTURE_WRAP_S, options.wrapS);
+ }
+ if (options.wrapT) {
+ parameteriFn.call(gl, target, TEXTURE_WRAP_T, options.wrapT);
+ }
+ if (options.minLod) {
+ parameteriFn.call(gl, target, TEXTURE_MIN_LOD, options.minLod);
+ }
+ if (options.maxLod) {
+ parameteriFn.call(gl, target, TEXTURE_MAX_LOD, options.maxLod);
+ }
+ if (options.baseLevel) {
+ parameteriFn.call(gl, target, TEXTURE_BASE_LEVEL, options.baseLevel);
+ }
+ if (options.maxLevel) {
+ parameteriFn.call(gl, target, TEXTURE_MAX_LEVEL, options.maxLevel);
+ }
+}
+
+/**
+ * Sets the texture parameters of a texture.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @memberOf module:twgl/textures
+ */
+function setTextureParameters(gl, tex, options) {
+ const target = options.target || TEXTURE_2D;
+ gl.bindTexture(target, tex);
+ setTextureSamplerParameters(gl, target, gl.texParameteri, options);
+}
+
+/**
+ * Sets the sampler parameters of a sampler.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLSampler} sampler the WebGLSampler to set parameters for
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @memberOf module:twgl/textures
+ */
+function setSamplerParameters(gl, sampler, options) {
+ setTextureSamplerParameters(gl, sampler, gl.samplerParameteri, options);
+}
+
+/**
+ * Creates a new sampler object and sets parameters.
+ *
+ * Example:
+ *
+ * const sampler = twgl.createSampler(gl, {
+ * minMag: gl.NEAREST, // sets both TEXTURE_MIN_FILTER and TEXTURE_MAG_FILTER
+ * wrap: gl.CLAMP_TO_NEAREST, // sets both TEXTURE_WRAP_S and TEXTURE_WRAP_T and TEXTURE_WRAP_R
+ * });
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {Object.} options A object of TextureOptions one per sampler.
+ * @return {Object.} the created samplers by name
+ * @private
+ */
+function createSampler(gl, options) {
+ const sampler = gl.createSampler();
+ setSamplerParameters(gl, sampler, options);
+ return sampler;
+}
+
+/**
+ * Creates a multiple sampler objects and sets parameters on each.
+ *
+ * Example:
+ *
+ * const samplers = twgl.createSamplers(gl, {
+ * nearest: {
+ * minMag: gl.NEAREST,
+ * },
+ * nearestClampS: {
+ * minMag: gl.NEAREST,
+ * wrapS: gl.CLAMP_TO_NEAREST,
+ * },
+ * linear: {
+ * minMag: gl.LINEAR,
+ * },
+ * nearestClamp: {
+ * minMag: gl.NEAREST,
+ * wrap: gl.CLAMP_TO_EDGE,
+ * },
+ * linearClamp: {
+ * minMag: gl.LINEAR,
+ * wrap: gl.CLAMP_TO_EDGE,
+ * },
+ * linearClampT: {
+ * minMag: gl.LINEAR,
+ * wrapT: gl.CLAMP_TO_EDGE,
+ * },
+ * });
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set on the sampler
+ * @private
+ */
+function createSamplers(gl, samplerOptions) {
+ const samplers = {};
+ Object.keys(samplerOptions).forEach(function(name) {
+ samplers[name] = createSampler(gl, samplerOptions[name]);
+ });
+ return samplers;
+}
+
+/**
+ * Makes a 1x1 pixel
+ * If no color is passed in uses the default color which can be set by calling `setDefaultTextureColor`.
+ * @param {(number[]|ArrayBufferView)} [color] The color using 0-1 values
+ * @return {Uint8Array} Unit8Array with color.
+ * @private
+ */
+function make1Pixel(color) {
+ color = color || defaults$1.textureColor;
+ if (isArrayBuffer$1(color)) {
+ return color;
+ }
+ return new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);
+}
+
+/**
+ * Sets filtering or generates mips for texture based on width or height
+ * If width or height is not passed in uses `options.width` and//or `options.height`
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @param {number} [width] width of texture
+ * @param {number} [height] height of texture
+ * @param {number} [internalFormat] The internalFormat parameter from texImage2D etc..
+ * @memberOf module:twgl/textures
+ */
+function setTextureFilteringForSize(gl, tex, options, width, height, internalFormat) {
+ options = options || defaults$1.textureOptions;
+ internalFormat = internalFormat || RGBA;
+ const target = options.target || TEXTURE_2D;
+ width = width || options.width;
+ height = height || options.height;
+ gl.bindTexture(target, tex);
+ if (canGenerateMipmap(gl, width, height, internalFormat)) {
+ gl.generateMipmap(target);
+ } else {
+ const filtering = canFilter(internalFormat) ? LINEAR : NEAREST;
+ gl.texParameteri(target, TEXTURE_MIN_FILTER, filtering);
+ gl.texParameteri(target, TEXTURE_MAG_FILTER, filtering);
+ gl.texParameteri(target, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
+ gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
+ }
+}
+
+function shouldAutomaticallySetTextureFilteringForSize(options) {
+ return options.auto === true || (options.auto === undefined && options.level === undefined);
+}
+
+/**
+ * Gets an array of cubemap face enums
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @return {number[]} cubemap face enums
+ * @private
+ */
+function getCubeFaceOrder(gl, options) {
+ options = options || {};
+ return options.cubeFaceOrder || [
+ TEXTURE_CUBE_MAP_POSITIVE_X,
+ TEXTURE_CUBE_MAP_NEGATIVE_X,
+ TEXTURE_CUBE_MAP_POSITIVE_Y,
+ TEXTURE_CUBE_MAP_NEGATIVE_Y,
+ TEXTURE_CUBE_MAP_POSITIVE_Z,
+ TEXTURE_CUBE_MAP_NEGATIVE_Z,
+ ];
+}
+
+/**
+ * @typedef {Object} FaceInfo
+ * @property {number} face gl enum for texImage2D
+ * @property {number} ndx face index (0 - 5) into source data
+ * @ignore
+ */
+
+/**
+ * Gets an array of FaceInfos
+ * There's a bug in some NVidia drivers that will crash the driver if
+ * `gl.TEXTURE_CUBE_MAP_POSITIVE_X` is not uploaded first. So, we take
+ * the user's desired order from his faces to WebGL and make sure we
+ * do the faces in WebGL order
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @return {FaceInfo[]} cubemap face infos. Arguably the `face` property of each element is redundant but
+ * it's needed internally to sort the array of `ndx` properties by `face`.
+ * @private
+ */
+function getCubeFacesWithNdx(gl, options) {
+ const faces = getCubeFaceOrder(gl, options);
+ // work around bug in NVidia drivers. We have to upload the first face first else the driver crashes :(
+ const facesWithNdx = faces.map(function(face, ndx) {
+ return { face: face, ndx: ndx };
+ });
+ facesWithNdx.sort(function(a, b) {
+ return a.face - b.face;
+ });
+ return facesWithNdx;
+}
+
+/**
+ * Set a texture from the contents of an element. Will also set
+ * texture filtering or generate mips based on the dimensions of the element
+ * unless `options.auto === false`. If `target === gl.TEXTURE_CUBE_MAP` will
+ * attempt to slice image into 1x6, 2x3, 3x2, or 6x1 images, one for each face.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {HTMLElement} element a canvas, img, or video element.
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @memberOf module:twgl/textures
+ * @kind function
+ */
+function setTextureFromElement(gl, tex, element, options) {
+ options = options || defaults$1.textureOptions;
+ const target = options.target || TEXTURE_2D;
+ const level = options.level || 0;
+ let width = element.width;
+ let height = element.height;
+ const internalFormat = options.internalFormat || options.format || RGBA;
+ const formatType = getFormatAndTypeForInternalFormat(internalFormat);
+ const format = options.format || formatType.format;
+ const type = options.type || formatType.type;
+ savePackState(gl, options);
+ gl.bindTexture(target, tex);
+ if (target === TEXTURE_CUBE_MAP) {
+ // guess the parts
+ const imgWidth = element.width;
+ const imgHeight = element.height;
+ let size;
+ let slices;
+ if (imgWidth / 6 === imgHeight) {
+ // It's 6x1
+ size = imgHeight;
+ slices = [0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0];
+ } else if (imgHeight / 6 === imgWidth) {
+ // It's 1x6
+ size = imgWidth;
+ slices = [0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5];
+ } else if (imgWidth / 3 === imgHeight / 2) {
+ // It's 3x2
+ size = imgWidth / 3;
+ slices = [0, 0, 1, 0, 2, 0, 0, 1, 1, 1, 2, 1];
+ } else if (imgWidth / 2 === imgHeight / 3) {
+ // It's 2x3
+ size = imgWidth / 2;
+ slices = [0, 0, 1, 0, 0, 1, 1, 1, 0, 2, 1, 2];
+ } else {
+ throw "can't figure out cube map from element: " + (element.src ? element.src : element.nodeName);
+ }
+ const ctx = getShared2DContext();
+ if (ctx) {
+ ctx.canvas.width = size;
+ ctx.canvas.height = size;
+ width = size;
+ height = size;
+ getCubeFacesWithNdx(gl, options).forEach(function(f) {
+ const xOffset = slices[f.ndx * 2 + 0] * size;
+ const yOffset = slices[f.ndx * 2 + 1] * size;
+ ctx.drawImage(element, xOffset, yOffset, size, size, 0, 0, size, size);
+ gl.texImage2D(f.face, level, internalFormat, format, type, ctx.canvas);
+ });
+ // Free up the canvas memory
+ ctx.canvas.width = 1;
+ ctx.canvas.height = 1;
+ } else if (typeof createImageBitmap !== 'undefined') {
+ // NOTE: It seems like we should prefer ImageBitmap because unlike canvas it's
+ // note lossy? (alpha is not premultiplied? although I'm not sure what
+ width = size;
+ height = size;
+ getCubeFacesWithNdx(gl, options).forEach(function(f) {
+ const xOffset = slices[f.ndx * 2 + 0] * size;
+ const yOffset = slices[f.ndx * 2 + 1] * size;
+ // We can't easily use a default texture color here as it would have to match
+ // the type across all faces where as with a 2D one there's only one face
+ // so we're replacing everything all at once. It also has to be the correct size.
+ // On the other hand we need all faces to be the same size so as one face loads
+ // the rest match else the texture will be un-renderable.
+ gl.texImage2D(f.face, level, internalFormat, size, size, 0, format, type, null);
+ createImageBitmap(element, xOffset, yOffset, size, size, {
+ premultiplyAlpha: 'none',
+ colorSpaceConversion: 'none',
+ })
+ .then(function(imageBitmap) {
+ savePackState(gl, options);
+ gl.bindTexture(target, tex);
+ gl.texImage2D(f.face, level, internalFormat, format, type, imageBitmap);
+ restorePackState(gl, options);
+ if (shouldAutomaticallySetTextureFilteringForSize(options)) {
+ setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
+ }
+ });
+ });
+ }
+ } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
+ const smallest = Math.min(element.width, element.height);
+ const largest = Math.max(element.width, element.height);
+ const depth = largest / smallest;
+ if (depth % 1 !== 0) {
+ throw "can not compute 3D dimensions of element";
+ }
+ const xMult = element.width === largest ? 1 : 0;
+ const yMult = element.height === largest ? 1 : 0;
+ saveSkipState(gl);
+ gl.pixelStorei(UNPACK_ALIGNMENT, 1);
+ gl.pixelStorei(UNPACK_ROW_LENGTH, element.width);
+ gl.pixelStorei(UNPACK_IMAGE_HEIGHT, 0);
+ gl.pixelStorei(UNPACK_SKIP_IMAGES, 0);
+ gl.texImage3D(target, level, internalFormat, smallest, smallest, smallest, 0, format, type, null);
+ for (let d = 0; d < depth; ++d) {
+ const srcX = d * smallest * xMult;
+ const srcY = d * smallest * yMult;
+ gl.pixelStorei(UNPACK_SKIP_PIXELS, srcX);
+ gl.pixelStorei(UNPACK_SKIP_ROWS, srcY);
+ gl.texSubImage3D(target, level, 0, 0, d, smallest, smallest, 1, format, type, element);
+ }
+ restoreSkipState(gl);
+ } else {
+ gl.texImage2D(target, level, internalFormat, format, type, element);
+ }
+ restorePackState(gl, options);
+ if (shouldAutomaticallySetTextureFilteringForSize(options)) {
+ setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
+ }
+ setTextureParameters(gl, tex, options);
+}
+
+function noop() {
+}
+
+/**
+ * Checks whether the url's origin is the same so that we can set the `crossOrigin`
+ * @param {string} url url to image
+ * @returns {boolean} true if the window's origin is the same as image's url
+ * @private
+ */
+function urlIsSameOrigin(url) {
+ if (typeof document !== 'undefined') {
+ // for IE really
+ const a = document.createElement('a');
+ a.href = url;
+ return a.hostname === location.hostname &&
+ a.port === location.port &&
+ a.protocol === location.protocol;
+ } else {
+ const localOrigin = (new URL(location.href)).origin;
+ const urlOrigin = (new URL(url, location.href)).origin;
+ return urlOrigin === localOrigin;
+ }
+}
+
+function setToAnonymousIfUndefinedAndURLIsNotSameOrigin(url, crossOrigin) {
+ return crossOrigin === undefined && !urlIsSameOrigin(url)
+ ? 'anonymous'
+ : crossOrigin;
+}
+
+/**
+ * Loads an image
+ * @param {string} url url to image
+ * @param {string} crossOrigin
+ * @param {function(err, img)} [callback] a callback that's passed an error and the image. The error will be non-null
+ * if there was an error
+ * @return {HTMLImageElement} the image being loaded.
+ * @private
+ */
+function loadImage(url, crossOrigin, callback) {
+ callback = callback || noop;
+ let img;
+ crossOrigin = crossOrigin !== undefined ? crossOrigin : defaults$1.crossOrigin;
+ crossOrigin = setToAnonymousIfUndefinedAndURLIsNotSameOrigin(url, crossOrigin);
+ if (typeof Image !== 'undefined') {
+ img = new Image();
+ if (crossOrigin !== undefined) {
+ img.crossOrigin = crossOrigin;
+ }
+
+ const clearEventHandlers = function clearEventHandlers() {
+ img.removeEventListener('error', onError); // eslint-disable-line
+ img.removeEventListener('load', onLoad); // eslint-disable-line
+ img = null;
+ };
+
+ const onError = function onError() {
+ const msg = "couldn't load image: " + url;
+ error(msg);
+ callback(msg, img);
+ clearEventHandlers();
+ };
+
+ const onLoad = function onLoad() {
+ callback(null, img);
+ clearEventHandlers();
+ };
+
+ img.addEventListener('error', onError);
+ img.addEventListener('load', onLoad);
+ img.src = url;
+ return img;
+ } else if (typeof ImageBitmap !== 'undefined') {
+ let err;
+ let bm;
+ const cb = function cb() {
+ callback(err, bm);
+ };
+
+ const options = {};
+ if (crossOrigin) {
+ options.mode = 'cors'; // TODO: not sure how to translate image.crossOrigin
+ }
+ fetch(url, options).then(function(response) {
+ if (!response.ok) {
+ throw response;
+ }
+ return response.blob();
+ }).then(function(blob) {
+ return createImageBitmap(blob, {
+ premultiplyAlpha: 'none',
+ colorSpaceConversion: 'none',
+ });
+ }).then(function(bitmap) {
+ // not sure if this works. We don't want
+ // to catch the user's error. So, call
+ // the callback in a timeout so we're
+ // not in this scope inside the promise.
+ bm = bitmap;
+ setTimeout(cb);
+ }).catch(function(e) {
+ err = e;
+ setTimeout(cb);
+ });
+ img = null;
+ }
+ return img;
+}
+
+/**
+ * check if object is a TexImageSource
+ *
+ * @param {Object} obj Object to test
+ * @return {boolean} true if object is a TexImageSource
+ * @private
+ */
+function isTexImageSource(obj) {
+ return (typeof ImageBitmap !== 'undefined' && obj instanceof ImageBitmap) ||
+ (typeof ImageData !== 'undefined' && obj instanceof ImageData) ||
+ (typeof HTMLElement !== 'undefined' && obj instanceof HTMLElement);
+}
+
+/**
+ * if obj is an TexImageSource then just
+ * uses it otherwise if obj is a string
+ * then load it first.
+ *
+ * @param {string|TexImageSource} obj
+ * @param {string} crossOrigin
+ * @param {function(err, img)} [callback] a callback that's passed an error and the image. The error will be non-null
+ * if there was an error
+ * @private
+ */
+function loadAndUseImage(obj, crossOrigin, callback) {
+ if (isTexImageSource(obj)) {
+ setTimeout(function() {
+ callback(null, obj);
+ });
+ return obj;
+ }
+
+ return loadImage(obj, crossOrigin, callback);
+}
+
+/**
+ * Sets a texture to a 1x1 pixel color. If `options.color === false` is nothing happens. If it's not set
+ * the default texture color is used which can be set by calling `setDefaultTextureColor`.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @memberOf module:twgl/textures
+ */
+function setTextureTo1PixelColor(gl, tex, options) {
+ options = options || defaults$1.textureOptions;
+ const target = options.target || TEXTURE_2D;
+ gl.bindTexture(target, tex);
+ if (options.color === false) {
+ return;
+ }
+ // Assume it's a URL
+ // Put 1x1 pixels in texture. That makes it renderable immediately regardless of filtering.
+ const color = make1Pixel(options.color);
+ if (target === TEXTURE_CUBE_MAP) {
+ for (let ii = 0; ii < 6; ++ii) {
+ gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, 0, RGBA, 1, 1, 0, RGBA, UNSIGNED_BYTE$2, color);
+ }
+ } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
+ gl.texImage3D(target, 0, RGBA, 1, 1, 1, 0, RGBA, UNSIGNED_BYTE$2, color);
+ } else {
+ gl.texImage2D(target, 0, RGBA, 1, 1, 0, RGBA, UNSIGNED_BYTE$2, color);
+ }
+}
+
+/**
+ * The src image(s) used to create a texture.
+ *
+ * When you call {@link module:twgl.createTexture} or {@link module:twgl.createTextures}
+ * you can pass in urls for images to load into the textures. If it's a single url
+ * then this will be a single HTMLImageElement. If it's an array of urls used for a cubemap
+ * this will be a corresponding array of images for the cubemap.
+ *
+ * @typedef {HTMLImageElement|HTMLImageElement[]} TextureSrc
+ * @memberOf module:twgl
+ */
+
+/**
+ * A callback for when an image finished downloading and been uploaded into a texture
+ * @callback TextureReadyCallback
+ * @param {*} err If truthy there was an error.
+ * @param {WebGLTexture} texture the texture.
+ * @param {module:twgl.TextureSrc} source image(s) used to as the src for the texture
+ * @memberOf module:twgl
+ */
+
+/**
+ * A callback for when all images have finished downloading and been uploaded into their respective textures
+ * @callback TexturesReadyCallback
+ * @param {*} err If truthy there was an error.
+ * @param {Object.} textures the created textures by name. Same as returned by {@link module:twgl.createTextures}.
+ * @param {Object.} sources the image(s) used for the texture by name.
+ * @memberOf module:twgl
+ */
+
+/**
+ * A callback for when an image finished downloading and been uploaded into a texture
+ * @callback CubemapReadyCallback
+ * @param {*} err If truthy there was an error.
+ * @param {WebGLTexture} tex the texture.
+ * @param {HTMLImageElement[]} imgs the images for each face.
+ * @memberOf module:twgl
+ */
+
+/**
+ * A callback for when an image finished downloading and been uploaded into a texture
+ * @callback ThreeDReadyCallback
+ * @param {*} err If truthy there was an error.
+ * @param {WebGLTexture} tex the texture.
+ * @param {HTMLImageElement[]} imgs the images for each slice.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Loads a texture from an image from a Url as specified in `options.src`
+ * If `options.color !== false` will set the texture to a 1x1 pixel color so that the texture is
+ * immediately useable. It will be updated with the contents of the image once the image has finished
+ * downloading. Filtering options will be set as appropriate for image unless `options.auto === false`.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
+ * @param {module:twgl.TextureReadyCallback} [callback] A function to be called when the image has finished loading. err will
+ * be non null if there was an error.
+ * @return {HTMLImageElement} the image being downloaded.
+ * @memberOf module:twgl/textures
+ */
+function loadTextureFromUrl(gl, tex, options, callback) {
+ callback = callback || noop;
+ options = options || defaults$1.textureOptions;
+ setTextureTo1PixelColor(gl, tex, options);
+ // Because it's async we need to copy the options.
+ options = Object.assign({}, options);
+ const img = loadAndUseImage(options.src, options.crossOrigin, function(err, img) {
+ if (err) {
+ callback(err, tex, img);
+ } else {
+ setTextureFromElement(gl, tex, img, options);
+ callback(null, tex, img);
+ }
+ });
+ return img;
+}
+
+/**
+ * Loads a cubemap from 6 urls or TexImageSources as specified in `options.src`. Will set the cubemap to a 1x1 pixel color
+ * so that it is usable immediately unless `option.color === false`.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @param {module:twgl.CubemapReadyCallback} [callback] A function to be called when all the images have finished loading. err will
+ * be non null if there was an error.
+ * @memberOf module:twgl/textures
+ */
+function loadCubemapFromUrls(gl, tex, options, callback) {
+ callback = callback || noop;
+ const urls = options.src;
+ if (urls.length !== 6) {
+ throw "there must be 6 urls for a cubemap";
+ }
+ const level = options.level || 0;
+ const internalFormat = options.internalFormat || options.format || RGBA;
+ const formatType = getFormatAndTypeForInternalFormat(internalFormat);
+ const format = options.format || formatType.format;
+ const type = options.type || UNSIGNED_BYTE$2;
+ const target = options.target || TEXTURE_2D;
+ if (target !== TEXTURE_CUBE_MAP) {
+ throw "target must be TEXTURE_CUBE_MAP";
+ }
+ setTextureTo1PixelColor(gl, tex, options);
+ // Because it's async we need to copy the options.
+ options = Object.assign({}, options);
+ let numToLoad = 6;
+ const errors = [];
+ const faces = getCubeFaceOrder(gl, options);
+ let imgs; // eslint-disable-line
+
+ function uploadImg(faceTarget) {
+ return function(err, img) {
+ --numToLoad;
+ if (err) {
+ errors.push(err);
+ } else {
+ if (img.width !== img.height) {
+ errors.push("cubemap face img is not a square: " + img.src);
+ } else {
+ savePackState(gl, options);
+ gl.bindTexture(target, tex);
+
+ // So assuming this is the first image we now have one face that's img sized
+ // and 5 faces that are 1x1 pixel so size the other faces
+ if (numToLoad === 5) {
+ // use the default order
+ getCubeFaceOrder().forEach(function(otherTarget) {
+ // Should we re-use the same face or a color?
+ gl.texImage2D(otherTarget, level, internalFormat, format, type, img);
+ });
+ } else {
+ gl.texImage2D(faceTarget, level, internalFormat, format, type, img);
+ }
+
+ restorePackState(gl, options);
+ if (shouldAutomaticallySetTextureFilteringForSize(options)) {
+ gl.generateMipmap(target);
+ }
+ }
+ }
+
+ if (numToLoad === 0) {
+ callback(errors.length ? errors : undefined, tex, imgs);
+ }
+ };
+ }
+
+ imgs = urls.map(function(url, ndx) {
+ return loadAndUseImage(url, options.crossOrigin, uploadImg(faces[ndx]));
+ });
+}
+
+/**
+ * Loads a 2d array or 3d texture from urls OR TexImageSources as specified in `options.src`.
+ * Will set the texture to a 1x1 pixel color
+ * so that it is usable immediately unless `option.color === false`.
+ *
+ * If the width and height is not specified the width and height of the first
+ * image loaded will be used. Note that since images are loaded async
+ * which image downloads first is unknown.
+ *
+ * If an image is not the same size as the width and height it will be scaled
+ * to that width and height.
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @param {module:twgl.ThreeDReadyCallback} [callback] A function to be called when all the images have finished loading. err will
+ * be non null if there was an error.
+ * @memberOf module:twgl/textures
+ */
+function loadSlicesFromUrls(gl, tex, options, callback) {
+ callback = callback || noop;
+ const urls = options.src;
+ const internalFormat = options.internalFormat || options.format || RGBA;
+ const formatType = getFormatAndTypeForInternalFormat(internalFormat);
+ const format = options.format || formatType.format;
+ const type = options.type || UNSIGNED_BYTE$2;
+ const target = options.target || TEXTURE_2D_ARRAY;
+ if (target !== TEXTURE_3D && target !== TEXTURE_2D_ARRAY) {
+ throw "target must be TEXTURE_3D or TEXTURE_2D_ARRAY";
+ }
+ setTextureTo1PixelColor(gl, tex, options);
+ // Because it's async we need to copy the options.
+ options = Object.assign({}, options);
+ let numToLoad = urls.length;
+ const errors = [];
+ let imgs; // eslint-disable-line
+ const level = options.level || 0;
+ let width = options.width;
+ let height = options.height;
+ const depth = urls.length;
+ let firstImage = true;
+
+ function uploadImg(slice) {
+ return function(err, img) {
+ --numToLoad;
+ if (err) {
+ errors.push(err);
+ } else {
+ savePackState(gl, options);
+ gl.bindTexture(target, tex);
+
+ if (firstImage) {
+ firstImage = false;
+ width = options.width || img.width;
+ height = options.height || img.height;
+ gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, null);
+
+ // put it in every slice otherwise some slices will be 0,0,0,0
+ for (let s = 0; s < depth; ++s) {
+ gl.texSubImage3D(target, level, 0, 0, s, width, height, 1, format, type, img);
+ }
+ } else {
+ let src = img;
+ let ctx;
+ if (img.width !== width || img.height !== height) {
+ // Size the image to fix
+ ctx = getShared2DContext();
+ src = ctx.canvas;
+ ctx.canvas.width = width;
+ ctx.canvas.height = height;
+ ctx.drawImage(img, 0, 0, width, height);
+ }
+
+ gl.texSubImage3D(target, level, 0, 0, slice, width, height, 1, format, type, src);
+
+ // free the canvas memory
+ if (ctx && src === ctx.canvas) {
+ ctx.canvas.width = 0;
+ ctx.canvas.height = 0;
+ }
+ }
+
+ restorePackState(gl, options);
+ if (shouldAutomaticallySetTextureFilteringForSize(options)) {
+ gl.generateMipmap(target);
+ }
+ }
+
+ if (numToLoad === 0) {
+ callback(errors.length ? errors : undefined, tex, imgs);
+ }
+ };
+ }
+
+ imgs = urls.map(function(url, ndx) {
+ return loadAndUseImage(url, options.crossOrigin, uploadImg(ndx));
+ });
+}
+
+/**
+ * Sets a texture from an array or typed array. If the width or height is not provided will attempt to
+ * guess the size. See {@link module:twgl.TextureOptions}.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {(number[]|ArrayBufferView)} src An array or typed arry with texture data.
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @memberOf module:twgl/textures
+ */
+function setTextureFromArray(gl, tex, src, options) {
+ options = options || defaults$1.textureOptions;
+ const target = options.target || TEXTURE_2D;
+ gl.bindTexture(target, tex);
+ let width = options.width;
+ let height = options.height;
+ let depth = options.depth;
+ const level = options.level || 0;
+ const internalFormat = options.internalFormat || options.format || RGBA;
+ const formatType = getFormatAndTypeForInternalFormat(internalFormat);
+ const format = options.format || formatType.format;
+ const type = options.type || getTextureTypeForArrayType(gl, src, formatType.type);
+ if (!isArrayBuffer$1(src)) {
+ const Type = getTypedArrayTypeForGLType(type);
+ src = new Type(src);
+ } else if (src instanceof Uint8ClampedArray) {
+ src = new Uint8Array(src.buffer);
+ }
+
+ const bytesPerElement = getBytesPerElementForInternalFormat(internalFormat, type);
+ const numElements = src.byteLength / bytesPerElement; // TODO: check UNPACK_ALIGNMENT?
+ if (numElements % 1) {
+ throw "length wrong size for format: " + glEnumToString(gl, format);
+ }
+ let dimensions;
+ if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
+ if (!width && !height && !depth) {
+ const size = Math.cbrt(numElements);
+ if (size % 1 !== 0) {
+ throw "can't guess cube size of array of numElements: " + numElements;
+ }
+ width = size;
+ height = size;
+ depth = size;
+ } else if (width && (!height || !depth)) {
+ dimensions = guessDimensions(gl, target, height, depth, numElements / width);
+ height = dimensions.width;
+ depth = dimensions.height;
+ } else if (height && (!width || !depth)) {
+ dimensions = guessDimensions(gl, target, width, depth, numElements / height);
+ width = dimensions.width;
+ depth = dimensions.height;
+ } else {
+ dimensions = guessDimensions(gl, target, width, height, numElements / depth);
+ width = dimensions.width;
+ height = dimensions.height;
+ }
+ } else {
+ dimensions = guessDimensions(gl, target, width, height, numElements);
+ width = dimensions.width;
+ height = dimensions.height;
+ }
+ saveSkipState(gl);
+ gl.pixelStorei(UNPACK_ALIGNMENT, options.unpackAlignment || 1);
+ savePackState(gl, options);
+ if (target === TEXTURE_CUBE_MAP) {
+ const elementsPerElement = bytesPerElement / src.BYTES_PER_ELEMENT;
+ const faceSize = numElements / 6 * elementsPerElement;
+
+ getCubeFacesWithNdx(gl, options).forEach(f => {
+ const offset = faceSize * f.ndx;
+ const data = src.subarray(offset, offset + faceSize);
+ gl.texImage2D(f.face, level, internalFormat, width, height, 0, format, type, data);
+ });
+ } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
+ gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, src);
+ } else {
+ gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, src);
+ }
+ restorePackState(gl, options);
+ restoreSkipState(gl);
+ return {
+ width: width,
+ height: height,
+ depth: depth,
+ type: type,
+ };
+}
+
+/**
+ * Sets a texture with no contents of a certain size. In other words calls `gl.texImage2D` with `null`.
+ * You must set `options.width` and `options.height`.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @memberOf module:twgl/textures
+ */
+function setEmptyTexture(gl, tex, options) {
+ const target = options.target || TEXTURE_2D;
+ gl.bindTexture(target, tex);
+ const level = options.level || 0;
+ const internalFormat = options.internalFormat || options.format || RGBA;
+ const formatType = getFormatAndTypeForInternalFormat(internalFormat);
+ const format = options.format || formatType.format;
+ const type = options.type || formatType.type;
+ savePackState(gl, options);
+ if (target === TEXTURE_CUBE_MAP) {
+ for (let ii = 0; ii < 6; ++ii) {
+ gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, level, internalFormat, options.width, options.height, 0, format, type, null);
+ }
+ } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
+ gl.texImage3D(target, level, internalFormat, options.width, options.height, options.depth, 0, format, type, null);
+ } else {
+ gl.texImage2D(target, level, internalFormat, options.width, options.height, 0, format, type, null);
+ }
+ restorePackState(gl, options);
+}
+
+/**
+ * Creates a texture based on the options passed in.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
+ * @param {module:twgl.TextureReadyCallback} [callback] A callback called when an image has been downloaded and uploaded to the texture.
+ * @return {WebGLTexture} the created texture.
+ * @memberOf module:twgl/textures
+ */
+function createTexture(gl, options, callback) {
+ callback = callback || noop;
+ options = options || defaults$1.textureOptions;
+ const tex = gl.createTexture();
+ const target = options.target || TEXTURE_2D;
+ let width = options.width || 1;
+ let height = options.height || 1;
+ const internalFormat = options.internalFormat || RGBA;
+ gl.bindTexture(target, tex);
+ if (target === TEXTURE_CUBE_MAP) {
+ // this should have been the default for cubemaps :(
+ gl.texParameteri(target, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
+ gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
+ }
+ let src = options.src;
+ if (src) {
+ if (typeof src === "function") {
+ src = src(gl, options);
+ }
+ if (typeof (src) === "string") {
+ loadTextureFromUrl(gl, tex, options, callback);
+ } else if (isArrayBuffer$1(src) ||
+ (Array.isArray(src) && (
+ typeof src[0] === 'number' ||
+ Array.isArray(src[0]) ||
+ isArrayBuffer$1(src[0]))
+ )
+ ) {
+ const dimensions = setTextureFromArray(gl, tex, src, options);
+ width = dimensions.width;
+ height = dimensions.height;
+ } else if (Array.isArray(src) && (typeof (src[0]) === 'string' || isTexImageSource(src[0]))) {
+ if (target === TEXTURE_CUBE_MAP) {
+ loadCubemapFromUrls(gl, tex, options, callback);
+ } else {
+ loadSlicesFromUrls(gl, tex, options, callback);
+ }
+ } else if (isTexImageSource(src)) {
+ setTextureFromElement(gl, tex, src, options);
+ width = src.width;
+ height = src.height;
+ } else {
+ throw "unsupported src type";
+ }
+ } else {
+ setEmptyTexture(gl, tex, options);
+ }
+ if (shouldAutomaticallySetTextureFilteringForSize(options)) {
+ setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
+ }
+ setTextureParameters(gl, tex, options);
+ return tex;
+}
+
+/**
+ * Resizes a texture based on the options passed in.
+ *
+ * Note: This is not a generic resize anything function.
+ * It's mostly used by {@link module:twgl.resizeFramebufferInfo}
+ * It will use `options.src` if it exists to try to determine a `type`
+ * otherwise it will assume `gl.UNSIGNED_BYTE`. No data is provided
+ * for the texture. Texture parameters will be set accordingly
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the texture to resize
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @param {number} [width] the new width. If not passed in will use `options.width`
+ * @param {number} [height] the new height. If not passed in will use `options.height`
+ * @param {number} [depth] the new depth. If not passed in will use `options.depth`
+ * @memberOf module:twgl/textures
+ */
+function resizeTexture(gl, tex, options, width, height, depth) {
+ width = width || options.width;
+ height = height || options.height;
+ depth = depth || options.depth;
+ const target = options.target || TEXTURE_2D;
+ gl.bindTexture(target, tex);
+ const level = options.level || 0;
+ const internalFormat = options.internalFormat || options.format || RGBA;
+ const formatType = getFormatAndTypeForInternalFormat(internalFormat);
+ const format = options.format || formatType.format;
+ let type;
+ const src = options.src;
+ if (!src) {
+ type = options.type || formatType.type;
+ } else if (isArrayBuffer$1(src) || (Array.isArray(src) && typeof (src[0]) === 'number')) {
+ type = options.type || getTextureTypeForArrayType(gl, src, formatType.type);
+ } else {
+ type = options.type || formatType.type;
+ }
+ if (target === TEXTURE_CUBE_MAP) {
+ for (let ii = 0; ii < 6; ++ii) {
+ gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, level, internalFormat, width, height, 0, format, type, null);
+ }
+ } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
+ gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, null);
+ } else {
+ gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, null);
+ }
+}
+
+/**
+ * Check if a src is an async request.
+ * if src is a string we're going to download an image
+ * if src is an array of strings we're going to download cubemap images
+ * @param {*} src The src from a TextureOptions
+ * @returns {bool} true if src is async.
+ * @private
+ */
+function isAsyncSrc(src) {
+ return typeof src === 'string' ||
+ (Array.isArray(src) && typeof src[0] === 'string');
+}
+
+/**
+ * Creates a bunch of textures based on the passed in options.
+ *
+ * Example:
+ *
+ * const textures = twgl.createTextures(gl, {
+ * // a power of 2 image
+ * hftIcon: { src: "images/hft-icon-16.png", mag: gl.NEAREST },
+ * // a non-power of 2 image
+ * clover: { src: "images/clover.jpg" },
+ * // From a canvas
+ * fromCanvas: { src: ctx.canvas },
+ * // A cubemap from 6 images
+ * yokohama: {
+ * target: gl.TEXTURE_CUBE_MAP,
+ * src: [
+ * 'images/yokohama/posx.jpg',
+ * 'images/yokohama/negx.jpg',
+ * 'images/yokohama/posy.jpg',
+ * 'images/yokohama/negy.jpg',
+ * 'images/yokohama/posz.jpg',
+ * 'images/yokohama/negz.jpg',
+ * ],
+ * },
+ * // A cubemap from 1 image (can be 1x6, 2x3, 3x2, 6x1)
+ * goldengate: {
+ * target: gl.TEXTURE_CUBE_MAP,
+ * src: 'images/goldengate.jpg',
+ * },
+ * // A 2x2 pixel texture from a JavaScript array
+ * checker: {
+ * mag: gl.NEAREST,
+ * min: gl.LINEAR,
+ * src: [
+ * 255,255,255,255,
+ * 192,192,192,255,
+ * 192,192,192,255,
+ * 255,255,255,255,
+ * ],
+ * },
+ * // a 1x2 pixel texture from a typed array.
+ * stripe: {
+ * mag: gl.NEAREST,
+ * min: gl.LINEAR,
+ * format: gl.LUMINANCE,
+ * src: new Uint8Array([
+ * 255,
+ * 128,
+ * 255,
+ * 128,
+ * 255,
+ * 128,
+ * 255,
+ * 128,
+ * ]),
+ * width: 1,
+ * },
+ * });
+ *
+ * Now
+ *
+ * * `textures.hftIcon` will be a 2d texture
+ * * `textures.clover` will be a 2d texture
+ * * `textures.fromCanvas` will be a 2d texture
+ * * `textures.yohohama` will be a cubemap texture
+ * * `textures.goldengate` will be a cubemap texture
+ * * `textures.checker` will be a 2d texture
+ * * `textures.stripe` will be a 2d texture
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {Object.} options A object of TextureOptions one per texture.
+ * @param {module:twgl.TexturesReadyCallback} [callback] A callback called when all textures have been downloaded.
+ * @return {Object.} the created textures by name
+ * @memberOf module:twgl/textures
+ */
+function createTextures(gl, textureOptions, callback) {
+ callback = callback || noop;
+ let numDownloading = 0;
+ const errors = [];
+ const textures = {};
+ const images = {};
+
+ function callCallbackIfReady() {
+ if (numDownloading === 0) {
+ setTimeout(function() {
+ callback(errors.length ? errors : undefined, textures, images);
+ }, 0);
+ }
+ }
+
+ Object.keys(textureOptions).forEach(function(name) {
+ const options = textureOptions[name];
+ let onLoadFn;
+ if (isAsyncSrc(options.src)) {
+ onLoadFn = function(err, tex, img) {
+ images[name] = img;
+ --numDownloading;
+ if (err) {
+ errors.push(err);
+ }
+ callCallbackIfReady();
+ };
+ ++numDownloading;
+ }
+ textures[name] = createTexture(gl, options, onLoadFn);
+ });
+
+ // queue the callback if there are no images to download.
+ // We do this because if your code is structured to wait for
+ // images to download but then you comment out all the async
+ // images your code would break.
+ callCallbackIfReady();
+
+ return textures;
+}
+
+var textures = /*#__PURE__*/Object.freeze({
+ __proto__: null,
+ setTextureDefaults_: setDefaults$1,
+ createSampler: createSampler,
+ createSamplers: createSamplers,
+ setSamplerParameters: setSamplerParameters,
+ createTexture: createTexture,
+ setEmptyTexture: setEmptyTexture,
+ setTextureFromArray: setTextureFromArray,
+ loadTextureFromUrl: loadTextureFromUrl,
+ setTextureFromElement: setTextureFromElement,
+ setTextureFilteringForSize: setTextureFilteringForSize,
+ setTextureParameters: setTextureParameters,
+ setDefaultTextureColor: setDefaultTextureColor,
+ createTextures: createTextures,
+ resizeTexture: resizeTexture,
+ canGenerateMipmap: canGenerateMipmap,
+ canFilter: canFilter,
+ getNumComponentsForFormat: getNumComponentsForFormat,
+ getBytesPerElementForInternalFormat: getBytesPerElementForInternalFormat,
+ getFormatAndTypeForInternalFormat: getFormatAndTypeForInternalFormat
+});
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * Low level shader program related functions
+ *
+ * You should generally not need to use these functions. They are provided
+ * for those cases where you're doing something out of the ordinary
+ * and you need lower level access.
+ *
+ * For backward compatibility they are available at both `twgl.programs` and `twgl`
+ * itself
+ *
+ * See {@link module:twgl} for core functions
+ *
+ * @module twgl/programs
+ */
+
+const error$1 = error;
+const warn$1 = warn;
+function getElementById(id) {
+ return (typeof document !== 'undefined' && document.getElementById)
+ ? document.getElementById(id)
+ : null;
+}
+
+const TEXTURE0 = 0x84c0;
+const DYNAMIC_DRAW = 0x88e8;
+
+const ARRAY_BUFFER$1 = 0x8892;
+const ELEMENT_ARRAY_BUFFER$1 = 0x8893;
+const UNIFORM_BUFFER = 0x8a11;
+const TRANSFORM_FEEDBACK_BUFFER = 0x8c8e;
+
+const TRANSFORM_FEEDBACK = 0x8e22;
+
+const COMPILE_STATUS = 0x8b81;
+const LINK_STATUS = 0x8b82;
+const FRAGMENT_SHADER = 0x8b30;
+const VERTEX_SHADER = 0x8b31;
+const SEPARATE_ATTRIBS = 0x8c8d;
+
+const ACTIVE_UNIFORMS = 0x8b86;
+const ACTIVE_ATTRIBUTES = 0x8b89;
+const TRANSFORM_FEEDBACK_VARYINGS = 0x8c83;
+const ACTIVE_UNIFORM_BLOCKS = 0x8a36;
+const UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER = 0x8a44;
+const UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER = 0x8a46;
+const UNIFORM_BLOCK_DATA_SIZE = 0x8a40;
+const UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES = 0x8a43;
+
+const FLOAT$3 = 0x1406;
+const FLOAT_VEC2 = 0x8B50;
+const FLOAT_VEC3 = 0x8B51;
+const FLOAT_VEC4 = 0x8B52;
+const INT$3 = 0x1404;
+const INT_VEC2 = 0x8B53;
+const INT_VEC3 = 0x8B54;
+const INT_VEC4 = 0x8B55;
+const BOOL = 0x8B56;
+const BOOL_VEC2 = 0x8B57;
+const BOOL_VEC3 = 0x8B58;
+const BOOL_VEC4 = 0x8B59;
+const FLOAT_MAT2 = 0x8B5A;
+const FLOAT_MAT3 = 0x8B5B;
+const FLOAT_MAT4 = 0x8B5C;
+const SAMPLER_2D = 0x8B5E;
+const SAMPLER_CUBE = 0x8B60;
+const SAMPLER_3D = 0x8B5F;
+const SAMPLER_2D_SHADOW = 0x8B62;
+const FLOAT_MAT2x3 = 0x8B65;
+const FLOAT_MAT2x4 = 0x8B66;
+const FLOAT_MAT3x2 = 0x8B67;
+const FLOAT_MAT3x4 = 0x8B68;
+const FLOAT_MAT4x2 = 0x8B69;
+const FLOAT_MAT4x3 = 0x8B6A;
+const SAMPLER_2D_ARRAY = 0x8DC1;
+const SAMPLER_2D_ARRAY_SHADOW = 0x8DC4;
+const SAMPLER_CUBE_SHADOW = 0x8DC5;
+const UNSIGNED_INT$3 = 0x1405;
+const UNSIGNED_INT_VEC2 = 0x8DC6;
+const UNSIGNED_INT_VEC3 = 0x8DC7;
+const UNSIGNED_INT_VEC4 = 0x8DC8;
+const INT_SAMPLER_2D = 0x8DCA;
+const INT_SAMPLER_3D = 0x8DCB;
+const INT_SAMPLER_CUBE = 0x8DCC;
+const INT_SAMPLER_2D_ARRAY = 0x8DCF;
+const UNSIGNED_INT_SAMPLER_2D = 0x8DD2;
+const UNSIGNED_INT_SAMPLER_3D = 0x8DD3;
+const UNSIGNED_INT_SAMPLER_CUBE = 0x8DD4;
+const UNSIGNED_INT_SAMPLER_2D_ARRAY = 0x8DD7;
+
+const TEXTURE_2D$1 = 0x0DE1;
+const TEXTURE_CUBE_MAP$1 = 0x8513;
+const TEXTURE_3D$1 = 0x806F;
+const TEXTURE_2D_ARRAY$1 = 0x8C1A;
+
+const typeMap = {};
+
+/**
+ * Returns the corresponding bind point for a given sampler type
+ */
+function getBindPointForSamplerType(gl, type) {
+ return typeMap[type].bindPoint;
+}
+
+// This kind of sucks! If you could compose functions as in `var fn = gl[name];`
+// this code could be a lot smaller but that is sadly really slow (T_T)
+
+function floatSetter(gl, location) {
+ return function(v) {
+ gl.uniform1f(location, v);
+ };
+}
+
+function floatArraySetter(gl, location) {
+ return function(v) {
+ gl.uniform1fv(location, v);
+ };
+}
+
+function floatVec2Setter(gl, location) {
+ return function(v) {
+ gl.uniform2fv(location, v);
+ };
+}
+
+function floatVec3Setter(gl, location) {
+ return function(v) {
+ gl.uniform3fv(location, v);
+ };
+}
+
+function floatVec4Setter(gl, location) {
+ return function(v) {
+ gl.uniform4fv(location, v);
+ };
+}
+
+function intSetter(gl, location) {
+ return function(v) {
+ gl.uniform1i(location, v);
+ };
+}
+
+function intArraySetter(gl, location) {
+ return function(v) {
+ gl.uniform1iv(location, v);
+ };
+}
+
+function intVec2Setter(gl, location) {
+ return function(v) {
+ gl.uniform2iv(location, v);
+ };
+}
+
+function intVec3Setter(gl, location) {
+ return function(v) {
+ gl.uniform3iv(location, v);
+ };
+}
+
+function intVec4Setter(gl, location) {
+ return function(v) {
+ gl.uniform4iv(location, v);
+ };
+}
+
+function uintSetter(gl, location) {
+ return function(v) {
+ gl.uniform1ui(location, v);
+ };
+}
+
+function uintArraySetter(gl, location) {
+ return function(v) {
+ gl.uniform1uiv(location, v);
+ };
+}
+
+function uintVec2Setter(gl, location) {
+ return function(v) {
+ gl.uniform2uiv(location, v);
+ };
+}
+
+function uintVec3Setter(gl, location) {
+ return function(v) {
+ gl.uniform3uiv(location, v);
+ };
+}
+
+function uintVec4Setter(gl, location) {
+ return function(v) {
+ gl.uniform4uiv(location, v);
+ };
+}
+
+function floatMat2Setter(gl, location) {
+ return function(v) {
+ gl.uniformMatrix2fv(location, false, v);
+ };
+}
+
+function floatMat3Setter(gl, location) {
+ return function(v) {
+ gl.uniformMatrix3fv(location, false, v);
+ };
+}
+
+function floatMat4Setter(gl, location) {
+ return function(v) {
+ gl.uniformMatrix4fv(location, false, v);
+ };
+}
+
+function floatMat23Setter(gl, location) {
+ return function(v) {
+ gl.uniformMatrix2x3fv(location, false, v);
+ };
+}
+
+function floatMat32Setter(gl, location) {
+ return function(v) {
+ gl.uniformMatrix3x2fv(location, false, v);
+ };
+}
+
+function floatMat24Setter(gl, location) {
+ return function(v) {
+ gl.uniformMatrix2x4fv(location, false, v);
+ };
+}
+
+function floatMat42Setter(gl, location) {
+ return function(v) {
+ gl.uniformMatrix4x2fv(location, false, v);
+ };
+}
+
+function floatMat34Setter(gl, location) {
+ return function(v) {
+ gl.uniformMatrix3x4fv(location, false, v);
+ };
+}
+
+function floatMat43Setter(gl, location) {
+ return function(v) {
+ gl.uniformMatrix4x3fv(location, false, v);
+ };
+}
+
+function samplerSetter(gl, type, unit, location) {
+ const bindPoint = getBindPointForSamplerType(gl, type);
+ return isWebGL2(gl) ? function(textureOrPair) {
+ let texture;
+ let sampler;
+ if (isTexture(gl, textureOrPair)) {
+ texture = textureOrPair;
+ sampler = null;
+ } else {
+ texture = textureOrPair.texture;
+ sampler = textureOrPair.sampler;
+ }
+ gl.uniform1i(location, unit);
+ gl.activeTexture(TEXTURE0 + unit);
+ gl.bindTexture(bindPoint, texture);
+ gl.bindSampler(unit, sampler);
+ } : function(texture) {
+ gl.uniform1i(location, unit);
+ gl.activeTexture(TEXTURE0 + unit);
+ gl.bindTexture(bindPoint, texture);
+ };
+}
+
+function samplerArraySetter(gl, type, unit, location, size) {
+ const bindPoint = getBindPointForSamplerType(gl, type);
+ const units = new Int32Array(size);
+ for (let ii = 0; ii < size; ++ii) {
+ units[ii] = unit + ii;
+ }
+
+ return isWebGL2(gl) ? function(textures) {
+ gl.uniform1iv(location, units);
+ textures.forEach(function(textureOrPair, index) {
+ gl.activeTexture(TEXTURE0 + units[index]);
+ let texture;
+ let sampler;
+ if (isTexture(gl, textureOrPair)) {
+ texture = textureOrPair;
+ sampler = null;
+ } else {
+ texture = textureOrPair.texture;
+ sampler = textureOrPair.sampler;
+ }
+ gl.bindSampler(unit, sampler);
+ gl.bindTexture(bindPoint, texture);
+ });
+ } : function(textures) {
+ gl.uniform1iv(location, units);
+ textures.forEach(function(texture, index) {
+ gl.activeTexture(TEXTURE0 + units[index]);
+ gl.bindTexture(bindPoint, texture);
+ });
+ };
+}
+
+typeMap[FLOAT$3] = { Type: Float32Array, size: 4, setter: floatSetter, arraySetter: floatArraySetter, };
+typeMap[FLOAT_VEC2] = { Type: Float32Array, size: 8, setter: floatVec2Setter, };
+typeMap[FLOAT_VEC3] = { Type: Float32Array, size: 12, setter: floatVec3Setter, };
+typeMap[FLOAT_VEC4] = { Type: Float32Array, size: 16, setter: floatVec4Setter, };
+typeMap[INT$3] = { Type: Int32Array, size: 4, setter: intSetter, arraySetter: intArraySetter, };
+typeMap[INT_VEC2] = { Type: Int32Array, size: 8, setter: intVec2Setter, };
+typeMap[INT_VEC3] = { Type: Int32Array, size: 12, setter: intVec3Setter, };
+typeMap[INT_VEC4] = { Type: Int32Array, size: 16, setter: intVec4Setter, };
+typeMap[UNSIGNED_INT$3] = { Type: Uint32Array, size: 4, setter: uintSetter, arraySetter: uintArraySetter, };
+typeMap[UNSIGNED_INT_VEC2] = { Type: Uint32Array, size: 8, setter: uintVec2Setter, };
+typeMap[UNSIGNED_INT_VEC3] = { Type: Uint32Array, size: 12, setter: uintVec3Setter, };
+typeMap[UNSIGNED_INT_VEC4] = { Type: Uint32Array, size: 16, setter: uintVec4Setter, };
+typeMap[BOOL] = { Type: Uint32Array, size: 4, setter: intSetter, arraySetter: intArraySetter, };
+typeMap[BOOL_VEC2] = { Type: Uint32Array, size: 8, setter: intVec2Setter, };
+typeMap[BOOL_VEC3] = { Type: Uint32Array, size: 12, setter: intVec3Setter, };
+typeMap[BOOL_VEC4] = { Type: Uint32Array, size: 16, setter: intVec4Setter, };
+typeMap[FLOAT_MAT2] = { Type: Float32Array, size: 16, setter: floatMat2Setter, };
+typeMap[FLOAT_MAT3] = { Type: Float32Array, size: 36, setter: floatMat3Setter, };
+typeMap[FLOAT_MAT4] = { Type: Float32Array, size: 64, setter: floatMat4Setter, };
+typeMap[FLOAT_MAT2x3] = { Type: Float32Array, size: 24, setter: floatMat23Setter, };
+typeMap[FLOAT_MAT2x4] = { Type: Float32Array, size: 32, setter: floatMat24Setter, };
+typeMap[FLOAT_MAT3x2] = { Type: Float32Array, size: 24, setter: floatMat32Setter, };
+typeMap[FLOAT_MAT3x4] = { Type: Float32Array, size: 48, setter: floatMat34Setter, };
+typeMap[FLOAT_MAT4x2] = { Type: Float32Array, size: 32, setter: floatMat42Setter, };
+typeMap[FLOAT_MAT4x3] = { Type: Float32Array, size: 48, setter: floatMat43Setter, };
+typeMap[SAMPLER_2D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D$1, };
+typeMap[SAMPLER_CUBE] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_CUBE_MAP$1, };
+typeMap[SAMPLER_3D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_3D$1, };
+typeMap[SAMPLER_2D_SHADOW] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D$1, };
+typeMap[SAMPLER_2D_ARRAY] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D_ARRAY$1, };
+typeMap[SAMPLER_2D_ARRAY_SHADOW] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D_ARRAY$1, };
+typeMap[SAMPLER_CUBE_SHADOW] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_CUBE_MAP$1, };
+typeMap[INT_SAMPLER_2D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D$1, };
+typeMap[INT_SAMPLER_3D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_3D$1, };
+typeMap[INT_SAMPLER_CUBE] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_CUBE_MAP$1, };
+typeMap[INT_SAMPLER_2D_ARRAY] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D_ARRAY$1, };
+typeMap[UNSIGNED_INT_SAMPLER_2D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D$1, };
+typeMap[UNSIGNED_INT_SAMPLER_3D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_3D$1, };
+typeMap[UNSIGNED_INT_SAMPLER_CUBE] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_CUBE_MAP$1, };
+typeMap[UNSIGNED_INT_SAMPLER_2D_ARRAY] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D_ARRAY$1, };
+
+function floatAttribSetter(gl, index) {
+ return function(b) {
+ if (b.value) {
+ gl.disableVertexAttribArray(index);
+ switch (b.value.length) {
+ case 4:
+ gl.vertexAttrib4fv(index, b.value);
+ break;
+ case 3:
+ gl.vertexAttrib3fv(index, b.value);
+ break;
+ case 2:
+ gl.vertexAttrib2fv(index, b.value);
+ break;
+ case 1:
+ gl.vertexAttrib1fv(index, b.value);
+ break;
+ default:
+ throw new Error('the length of a float constant value must be between 1 and 4!');
+ }
+ } else {
+ gl.bindBuffer(ARRAY_BUFFER$1, b.buffer);
+ gl.enableVertexAttribArray(index);
+ gl.vertexAttribPointer(
+ index, b.numComponents || b.size, b.type || FLOAT$3, b.normalize || false, b.stride || 0, b.offset || 0);
+ if (b.divisor !== undefined) {
+ gl.vertexAttribDivisor(index, b.divisor);
+ }
+ }
+ };
+}
+
+function intAttribSetter(gl, index) {
+ return function(b) {
+ if (b.value) {
+ gl.disableVertexAttribArray(index);
+ if (b.value.length === 4) {
+ gl.vertexAttrib4iv(index, b.value);
+ } else {
+ throw new Error('The length of an integer constant value must be 4!');
+ }
+ } else {
+ gl.bindBuffer(ARRAY_BUFFER$1, b.buffer);
+ gl.enableVertexAttribArray(index);
+ gl.vertexAttribIPointer(
+ index, b.numComponents || b.size, b.type || INT$3, b.stride || 0, b.offset || 0);
+ if (b.divisor !== undefined) {
+ gl.vertexAttribDivisor(index, b.divisor);
+ }
+ }
+ };
+}
+
+function uintAttribSetter(gl, index) {
+ return function(b) {
+ if (b.value) {
+ gl.disableVertexAttribArray(index);
+ if (b.value.length === 4) {
+ gl.vertexAttrib4uiv(index, b.value);
+ } else {
+ throw new Error('The length of an unsigned integer constant value must be 4!');
+ }
+ } else {
+ gl.bindBuffer(ARRAY_BUFFER$1, b.buffer);
+ gl.enableVertexAttribArray(index);
+ gl.vertexAttribIPointer(
+ index, b.numComponents || b.size, b.type || UNSIGNED_INT$3, b.stride || 0, b.offset || 0);
+ if (b.divisor !== undefined) {
+ gl.vertexAttribDivisor(index, b.divisor);
+ }
+ }
+ };
+}
+
+function matAttribSetter(gl, index, typeInfo) {
+ const defaultSize = typeInfo.size;
+ const count = typeInfo.count;
+
+ return function(b) {
+ gl.bindBuffer(ARRAY_BUFFER$1, b.buffer);
+ const numComponents = b.size || b.numComponents || defaultSize;
+ const size = numComponents / count;
+ const type = b.type || FLOAT$3;
+ const typeInfo = typeMap[type];
+ const stride = typeInfo.size * numComponents;
+ const normalize = b.normalize || false;
+ const offset = b.offset || 0;
+ const rowOffset = stride / count;
+ for (let i = 0; i < count; ++i) {
+ gl.enableVertexAttribArray(index + i);
+ gl.vertexAttribPointer(
+ index + i, size, type, normalize, stride, offset + rowOffset * i);
+ if (b.divisor !== undefined) {
+ gl.vertexAttribDivisor(index + i, b.divisor);
+ }
+ }
+ };
+}
+
+
+
+const attrTypeMap = {};
+attrTypeMap[FLOAT$3] = { size: 4, setter: floatAttribSetter, };
+attrTypeMap[FLOAT_VEC2] = { size: 8, setter: floatAttribSetter, };
+attrTypeMap[FLOAT_VEC3] = { size: 12, setter: floatAttribSetter, };
+attrTypeMap[FLOAT_VEC4] = { size: 16, setter: floatAttribSetter, };
+attrTypeMap[INT$3] = { size: 4, setter: intAttribSetter, };
+attrTypeMap[INT_VEC2] = { size: 8, setter: intAttribSetter, };
+attrTypeMap[INT_VEC3] = { size: 12, setter: intAttribSetter, };
+attrTypeMap[INT_VEC4] = { size: 16, setter: intAttribSetter, };
+attrTypeMap[UNSIGNED_INT$3] = { size: 4, setter: uintAttribSetter, };
+attrTypeMap[UNSIGNED_INT_VEC2] = { size: 8, setter: uintAttribSetter, };
+attrTypeMap[UNSIGNED_INT_VEC3] = { size: 12, setter: uintAttribSetter, };
+attrTypeMap[UNSIGNED_INT_VEC4] = { size: 16, setter: uintAttribSetter, };
+attrTypeMap[BOOL] = { size: 4, setter: intAttribSetter, };
+attrTypeMap[BOOL_VEC2] = { size: 8, setter: intAttribSetter, };
+attrTypeMap[BOOL_VEC3] = { size: 12, setter: intAttribSetter, };
+attrTypeMap[BOOL_VEC4] = { size: 16, setter: intAttribSetter, };
+attrTypeMap[FLOAT_MAT2] = { size: 4, setter: matAttribSetter, count: 2, };
+attrTypeMap[FLOAT_MAT3] = { size: 9, setter: matAttribSetter, count: 3, };
+attrTypeMap[FLOAT_MAT4] = { size: 16, setter: matAttribSetter, count: 4, };
+
+/**
+ * Error Callback
+ * @callback ErrorCallback
+ * @param {string} msg error message.
+ * @param {number} [lineOffset] amount to add to line number
+ * @memberOf module:twgl
+ */
+
+function addLineNumbers(src, lineOffset) {
+ lineOffset = lineOffset || 0;
+ ++lineOffset;
+
+ return src.split("\n").map(function(line, ndx) {
+ return (ndx + lineOffset) + ": " + line;
+ }).join("\n");
+}
+
+const spaceRE = /^[ \t]*\n/;
+
+/**
+ * Loads a shader.
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {string} shaderSource The shader source.
+ * @param {number} shaderType The type of shader.
+ * @param {module:twgl.ErrorCallback} opt_errorCallback callback for errors.
+ * @return {WebGLShader} The created shader.
+ * @private
+ */
+function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
+ const errFn = opt_errorCallback || error$1;
+ // Create the shader object
+ const shader = gl.createShader(shaderType);
+
+ // Remove the first end of line because WebGL 2.0 requires
+ // #version 300 es
+ // as the first line. No whitespace allowed before that line
+ // so
+ //
+ //
+ //
+ // Has one line before it which is invalid according to GLSL ES 3.00
+ //
+ let lineOffset = 0;
+ if (spaceRE.test(shaderSource)) {
+ lineOffset = 1;
+ shaderSource = shaderSource.replace(spaceRE, '');
+ }
+
+ // Load the shader source
+ gl.shaderSource(shader, shaderSource);
+
+ // Compile the shader
+ gl.compileShader(shader);
+
+ // Check the compile status
+ const compiled = gl.getShaderParameter(shader, COMPILE_STATUS);
+ if (!compiled) {
+ // Something went wrong during compilation; get the error
+ const lastError = gl.getShaderInfoLog(shader);
+ errFn(addLineNumbers(shaderSource, lineOffset) + "\n*** Error compiling shader: " + lastError);
+ gl.deleteShader(shader);
+ return null;
+ }
+
+ return shader;
+}
+
+/**
+ * @typedef {Object} ProgramOptions
+ * @property {function(string)} [errorCallback] callback for errors
+ * @property {Object.} [attribLocations] a attribute name to location map
+ * @property {(module:twgl.BufferInfo|Object.|string[])} [transformFeedbackVaryings] If passed
+ * a BufferInfo will use the attribs names inside. If passed an object of AttribInfos will use the names from that object. Otherwise
+ * you can pass an array of names.
+ * @property {number} [transformFeedbackMode] the mode to pass `gl.transformFeedbackVaryings`. Defaults to `SEPARATE_ATTRIBS`.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Gets the program options based on all these optional arguments
+ * @param {module:twgl.ProgramOptions|string[]} [opt_attribs] Options for the program or an array of attribs names. Locations will be assigned by index if not passed in
+ * @param {number[]} [opt_locations] The locations for the. A parallel array to opt_attribs letting you assign locations.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
+ * on error. If you want something else pass an callback. It's passed an error message.
+ * @return {module:twgl.ProgramOptions} an instance of ProgramOptions based on the arguments passed in
+ * @private
+ */
+function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
+ let transformFeedbackVaryings;
+ let transformFeedbackMode;
+ if (typeof opt_locations === 'function') {
+ opt_errorCallback = opt_locations;
+ opt_locations = undefined;
+ }
+ if (typeof opt_attribs === 'function') {
+ opt_errorCallback = opt_attribs;
+ opt_attribs = undefined;
+ } else if (opt_attribs && !Array.isArray(opt_attribs)) {
+ // If we have an errorCallback we can just return this object
+ // Otherwise we need to construct one with default errorCallback
+ if (opt_attribs.errorCallback) {
+ return opt_attribs;
+ }
+ const opt = opt_attribs;
+ opt_errorCallback = opt.errorCallback;
+ opt_attribs = opt.attribLocations;
+ transformFeedbackVaryings = opt.transformFeedbackVaryings;
+ transformFeedbackMode = opt.transformFeedbackMode;
+ }
+
+ const options = {
+ errorCallback: opt_errorCallback || error$1,
+ transformFeedbackVaryings: transformFeedbackVaryings,
+ transformFeedbackMode: transformFeedbackMode,
+ };
+
+ if (opt_attribs) {
+ let attribLocations = {};
+ if (Array.isArray(opt_attribs)) {
+ opt_attribs.forEach(function(attrib, ndx) {
+ attribLocations[attrib] = opt_locations ? opt_locations[ndx] : ndx;
+ });
+ } else {
+ attribLocations = opt_attribs;
+ }
+ options.attribLocations = attribLocations;
+ }
+
+ return options;
+}
+
+const defaultShaderType = [
+ "VERTEX_SHADER",
+ "FRAGMENT_SHADER",
+];
+
+function getShaderTypeFromScriptType(gl, scriptType) {
+ if (scriptType.indexOf("frag") >= 0) {
+ return FRAGMENT_SHADER;
+ } else if (scriptType.indexOf("vert") >= 0) {
+ return VERTEX_SHADER;
+ }
+ return undefined;
+}
+
+function deleteShaders(gl, shaders) {
+ shaders.forEach(function(shader) {
+ gl.deleteShader(shader);
+ });
+}
+
+/**
+ * Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
+ * program and calls useProgram.
+ *
+ * NOTE: There are 4 signatures for this function
+ *
+ * twgl.createProgram(gl, [vs, fs], options);
+ * twgl.createProgram(gl, [vs, fs], opt_errFunc);
+ * twgl.createProgram(gl, [vs, fs], opt_attribs, opt_errFunc);
+ * twgl.createProgram(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {WebGLShader[]|string[]} shaders The shaders to attach, or element ids for their source, or strings that contain their source
+ * @param {module:twgl.ProgramOptions|string[]|module:twgl.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
+ * @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
+ * on error. If you want something else pass an callback. It's passed an error message.
+ * @return {WebGLProgram?} the created program or null if error.
+ * @memberOf module:twgl/programs
+ */
+function createProgram(
+ gl, shaders, opt_attribs, opt_locations, opt_errorCallback) {
+ const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
+ const realShaders = [];
+ const newShaders = [];
+ for (let ndx = 0; ndx < shaders.length; ++ndx) {
+ let shader = shaders[ndx];
+ if (typeof (shader) === 'string') {
+ const elem = getElementById(shader);
+ const src = elem ? elem.text : shader;
+ let type = gl[defaultShaderType[ndx]];
+ if (elem && elem.type) {
+ type = getShaderTypeFromScriptType(gl, elem.type) || type;
+ }
+ shader = loadShader(gl, src, type, progOptions.errorCallback);
+ newShaders.push(shader);
+ }
+ if (isShader(gl, shader)) {
+ realShaders.push(shader);
+ }
+ }
+
+ if (realShaders.length !== shaders.length) {
+ progOptions.errorCallback("not enough shaders for program");
+ deleteShaders(gl, newShaders);
+ return null;
+ }
+
+ const program = gl.createProgram();
+ realShaders.forEach(function(shader) {
+ gl.attachShader(program, shader);
+ });
+ if (progOptions.attribLocations) {
+ Object.keys(progOptions.attribLocations).forEach(function(attrib) {
+ gl.bindAttribLocation(program, progOptions.attribLocations[attrib], attrib);
+ });
+ }
+ let varyings = progOptions.transformFeedbackVaryings;
+ if (varyings) {
+ if (varyings.attribs) {
+ varyings = varyings.attribs;
+ }
+ if (!Array.isArray(varyings)) {
+ varyings = Object.keys(varyings);
+ }
+ gl.transformFeedbackVaryings(program, varyings, progOptions.transformFeedbackMode || SEPARATE_ATTRIBS);
+ }
+ gl.linkProgram(program);
+
+ // Check the link status
+ const linked = gl.getProgramParameter(program, LINK_STATUS);
+ if (!linked) {
+ // something went wrong with the link
+ const lastError = gl.getProgramInfoLog(program);
+ progOptions.errorCallback("Error in program linking:" + lastError);
+
+ gl.deleteProgram(program);
+ deleteShaders(gl, newShaders);
+ return null;
+ }
+ return program;
+}
+
+/**
+ * Loads a shader from a script tag.
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {string} scriptId The id of the script tag.
+ * @param {number} [opt_shaderType] The type of shader. If not passed in it will
+ * be derived from the type of the script tag.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors.
+ * @return {WebGLShader?} The created shader or null if error.
+ * @private
+ */
+function createShaderFromScript(
+ gl, scriptId, opt_shaderType, opt_errorCallback) {
+ let shaderSource = "";
+ const shaderScript = getElementById(scriptId);
+ if (!shaderScript) {
+ throw new Error(`unknown script element: ${scriptId}`);
+ }
+ shaderSource = shaderScript.text;
+
+ const shaderType = opt_shaderType || getShaderTypeFromScriptType(gl, shaderScript.type);
+ if (!shaderType) {
+ throw new Error('unknown shader type');
+ }
+
+ return loadShader(gl, shaderSource, shaderType, opt_errorCallback);
+}
+
+/**
+ * Creates a program from 2 script tags.
+ *
+ * NOTE: There are 4 signatures for this function
+ *
+ * twgl.createProgramFromScripts(gl, [vs, fs], opt_options);
+ * twgl.createProgramFromScripts(gl, [vs, fs], opt_errFunc);
+ * twgl.createProgramFromScripts(gl, [vs, fs], opt_attribs, opt_errFunc);
+ * twgl.createProgramFromScripts(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
+ * to use.
+ * @param {string[]} shaderScriptIds Array of ids of the script
+ * tags for the shaders. The first is assumed to be the
+ * vertex shader, the second the fragment shader.
+ * @param {module:twgl.ProgramOptions|string[]|module:twgl.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
+ * @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
+ * on error. If you want something else pass an callback. It's passed an error message.
+ * @return {WebGLProgram?} the created program or null if error.
+ * @memberOf module:twgl/programs
+ */
+function createProgramFromScripts(
+ gl, shaderScriptIds, opt_attribs, opt_locations, opt_errorCallback) {
+ const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
+ const shaders = [];
+ for (let ii = 0; ii < shaderScriptIds.length; ++ii) {
+ const shader = createShaderFromScript(
+ gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions.errorCallback);
+ if (!shader) {
+ return null;
+ }
+ shaders.push(shader);
+ }
+ return createProgram(gl, shaders, progOptions);
+}
+
+/**
+ * Creates a program from 2 sources.
+ *
+ * NOTE: There are 4 signatures for this function
+ *
+ * twgl.createProgramFromSource(gl, [vs, fs], opt_options);
+ * twgl.createProgramFromSource(gl, [vs, fs], opt_errFunc);
+ * twgl.createProgramFromSource(gl, [vs, fs], opt_attribs, opt_errFunc);
+ * twgl.createProgramFromSource(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
+ * to use.
+ * @param {string[]} shaderSources Array of sources for the
+ * shaders. The first is assumed to be the vertex shader,
+ * the second the fragment shader.
+ * @param {module:twgl.ProgramOptions|string[]|module:twgl.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
+ * @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
+ * on error. If you want something else pass an callback. It's passed an error message.
+ * @return {WebGLProgram?} the created program or null if error.
+ * @memberOf module:twgl/programs
+ */
+function createProgramFromSources(
+ gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
+ const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
+ const shaders = [];
+ for (let ii = 0; ii < shaderSources.length; ++ii) {
+ const shader = loadShader(
+ gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions.errorCallback);
+ if (!shader) {
+ return null;
+ }
+ shaders.push(shader);
+ }
+ return createProgram(gl, shaders, progOptions);
+}
+
+/**
+ * Returns true if attribute/uniform is a reserved/built in
+ *
+ * It makes no sense to me why GL returns these because it's
+ * illegal to call `gl.getUniformLocation` and `gl.getAttribLocation`
+ * with names that start with `gl_` (and `webgl_` in WebGL)
+ *
+ * I can only assume they are there because they might count
+ * when computing the number of uniforms/attributes used when you want to
+ * know if you are near the limit. That doesn't really make sense
+ * to me but the fact that these get returned are in the spec.
+ *
+ * @param {WebGLActiveInfo} info As returned from `gl.getActiveUniform` or
+ * `gl.getActiveAttrib`.
+ * @return {bool} true if it's reserved
+ * @private
+ */
+function isBuiltIn(info) {
+ const name = info.name;
+ return name.startsWith("gl_") || name.startsWith("webgl_");
+}
+
+/**
+ * Creates setter functions for all uniforms of a shader
+ * program.
+ *
+ * @see {@link module:twgl.setUniforms}
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {WebGLProgram} program the program to create setters for.
+ * @returns {Object.} an object with a setter by name for each uniform
+ * @memberOf module:twgl/programs
+ */
+function createUniformSetters(gl, program) {
+ let textureUnit = 0;
+
+ /**
+ * Creates a setter for a uniform of the given program with it's
+ * location embedded in the setter.
+ * @param {WebGLProgram} program
+ * @param {WebGLUniformInfo} uniformInfo
+ * @returns {function} the created setter.
+ */
+ function createUniformSetter(program, uniformInfo) {
+ const location = gl.getUniformLocation(program, uniformInfo.name);
+ const isArray = (uniformInfo.size > 1 && uniformInfo.name.substr(-3) === "[0]");
+ const type = uniformInfo.type;
+ const typeInfo = typeMap[type];
+ if (!typeInfo) {
+ throw new Error(`unknown type: 0x${type.toString(16)}`); // we should never get here.
+ }
+ let setter;
+ if (typeInfo.bindPoint) {
+ // it's a sampler
+ const unit = textureUnit;
+ textureUnit += uniformInfo.size;
+ if (isArray) {
+ setter = typeInfo.arraySetter(gl, type, unit, location, uniformInfo.size);
+ } else {
+ setter = typeInfo.setter(gl, type, unit, location, uniformInfo.size);
+ }
+ } else {
+ if (typeInfo.arraySetter && isArray) {
+ setter = typeInfo.arraySetter(gl, location);
+ } else {
+ setter = typeInfo.setter(gl, location);
+ }
+ }
+ setter.location = location;
+ return setter;
+ }
+
+ const uniformSetters = { };
+ const numUniforms = gl.getProgramParameter(program, ACTIVE_UNIFORMS);
+
+ for (let ii = 0; ii < numUniforms; ++ii) {
+ const uniformInfo = gl.getActiveUniform(program, ii);
+ if (isBuiltIn(uniformInfo)) {
+ continue;
+ }
+ let name = uniformInfo.name;
+ // remove the array suffix.
+ if (name.substr(-3) === "[0]") {
+ name = name.substr(0, name.length - 3);
+ }
+ const setter = createUniformSetter(program, uniformInfo);
+ uniformSetters[name] = setter;
+ }
+ return uniformSetters;
+}
+
+/**
+ * @typedef {Object} TransformFeedbackInfo
+ * @property {number} index index of transform feedback
+ * @property {number} type GL type
+ * @property {number} size 1 - 4
+ * @memberOf module:twgl
+ */
+
+/**
+ * Create TransformFeedbackInfo for passing to bindTransformFeedbackInfo.
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {WebGLProgram} program an existing WebGLProgram.
+ * @return {Object}
+ * @memberOf module:twgl
+ */
+function createTransformFeedbackInfo(gl, program) {
+ const info = {};
+ const numVaryings = gl.getProgramParameter(program, TRANSFORM_FEEDBACK_VARYINGS);
+ for (let ii = 0; ii < numVaryings; ++ii) {
+ const varying = gl.getTransformFeedbackVarying(program, ii);
+ info[varying.name] = {
+ index: ii,
+ type: varying.type,
+ size: varying.size,
+ };
+ }
+ return info;
+}
+
+/**
+ * Binds buffers for transform feedback.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {(module:twgl.ProgramInfo|Object)} transformFeedbackInfo A ProgramInfo or TransformFeedbackInfo.
+ * @param {(module:twgl.BufferInfo|Object)} [bufferInfo] A BufferInfo or set of AttribInfos.
+ * @memberOf module:twgl
+ */
+function bindTransformFeedbackInfo(gl, transformFeedbackInfo, bufferInfo) {
+ if (transformFeedbackInfo.transformFeedbackInfo) {
+ transformFeedbackInfo = transformFeedbackInfo.transformFeedbackInfo;
+ }
+ if (bufferInfo.attribs) {
+ bufferInfo = bufferInfo.attribs;
+ }
+ for (const name in bufferInfo) {
+ const varying = transformFeedbackInfo[name];
+ if (varying) {
+ const buf = bufferInfo[name];
+ if (buf.offset) {
+ gl.bindBufferRange(TRANSFORM_FEEDBACK_BUFFER, varying.index, buf.buffer, buf.offset, buf.size);
+ } else {
+ gl.bindBufferBase(TRANSFORM_FEEDBACK_BUFFER, varying.index, buf.buffer);
+ }
+ }
+ }
+}
+
+/**
+ * Creates a transform feedback and sets the buffers
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {module:twgl.ProgramInfo} programInfo A ProgramInfo as returned from {@link module:twgl.createProgramInfo}
+ * @param {(module:twgl.BufferInfo|Object)} [bufferInfo] A BufferInfo or set of AttribInfos.
+ * @return {WebGLTransformFeedback} the created transform feedback
+ * @memberOf module:twgl
+ */
+function createTransformFeedback(gl, programInfo, bufferInfo) {
+ const tf = gl.createTransformFeedback();
+ gl.bindTransformFeedback(TRANSFORM_FEEDBACK, tf);
+ gl.useProgram(programInfo.program);
+ bindTransformFeedbackInfo(gl, programInfo, bufferInfo);
+ gl.bindTransformFeedback(TRANSFORM_FEEDBACK, null);
+ return tf;
+}
+
+/**
+ * @typedef {Object} UniformData
+ * @property {number} type The WebGL type enum for this uniform
+ * @property {number} size The number of elements for this uniform
+ * @property {number} blockNdx The block index this uniform appears in
+ * @property {number} offset The byte offset in the block for this uniform's value
+ * @memberOf module:twgl
+ */
+
+/**
+ * The specification for one UniformBlockObject
+ *
+ * @typedef {Object} BlockSpec
+ * @property {number} index The index of the block.
+ * @property {number} size The size in bytes needed for the block
+ * @property {number[]} uniformIndices The indices of the uniforms used by the block. These indices
+ * correspond to entries in a UniformData array in the {@link module:twgl.UniformBlockSpec}.
+ * @property {bool} usedByVertexShader Self explanatory
+ * @property {bool} usedByFragmentShader Self explanatory
+ * @property {bool} used Self explanatory
+ * @memberOf module:twgl
+ */
+
+/**
+ * A `UniformBlockSpec` represents the data needed to create and bind
+ * UniformBlockObjects for a given program
+ *
+ * @typedef {Object} UniformBlockSpec
+ * @property {Object. blockSpecs The BlockSpec for each block by block name
+ * @property {UniformData[]} uniformData An array of data for each uniform by uniform index.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a UniformBlockSpec for the given program.
+ *
+ * A UniformBlockSpec represents the data needed to create and bind
+ * UniformBlockObjects
+ *
+ * @param {WebGL2RenderingContext} gl A WebGL2 Rendering Context
+ * @param {WebGLProgram} program A WebGLProgram for a successfully linked program
+ * @return {module:twgl.UniformBlockSpec} The created UniformBlockSpec
+ * @memberOf module:twgl/programs
+ */
+function createUniformBlockSpecFromProgram(gl, program) {
+ const numUniforms = gl.getProgramParameter(program, ACTIVE_UNIFORMS);
+ const uniformData = [];
+ const uniformIndices = [];
+
+ for (let ii = 0; ii < numUniforms; ++ii) {
+ uniformIndices.push(ii);
+ uniformData.push({});
+ const uniformInfo = gl.getActiveUniform(program, ii);
+ if (isBuiltIn(uniformInfo)) {
+ break;
+ }
+ // REMOVE [0]?
+ uniformData[ii].name = uniformInfo.name;
+ }
+
+ [
+ [ "UNIFORM_TYPE", "type" ],
+ [ "UNIFORM_SIZE", "size" ], // num elements
+ [ "UNIFORM_BLOCK_INDEX", "blockNdx" ],
+ [ "UNIFORM_OFFSET", "offset", ],
+ ].forEach(function(pair) {
+ const pname = pair[0];
+ const key = pair[1];
+ gl.getActiveUniforms(program, uniformIndices, gl[pname]).forEach(function(value, ndx) {
+ uniformData[ndx][key] = value;
+ });
+ });
+
+ const blockSpecs = {};
+
+ const numUniformBlocks = gl.getProgramParameter(program, ACTIVE_UNIFORM_BLOCKS);
+ for (let ii = 0; ii < numUniformBlocks; ++ii) {
+ const name = gl.getActiveUniformBlockName(program, ii);
+ const blockSpec = {
+ index: ii,
+ usedByVertexShader: gl.getActiveUniformBlockParameter(program, ii, UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),
+ usedByFragmentShader: gl.getActiveUniformBlockParameter(program, ii, UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER),
+ size: gl.getActiveUniformBlockParameter(program, ii, UNIFORM_BLOCK_DATA_SIZE),
+ uniformIndices: gl.getActiveUniformBlockParameter(program, ii, UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES),
+ };
+ blockSpec.used = blockSpec.usedByVertexShader || blockSpec.usedByFragmentShader;
+ blockSpecs[name] = blockSpec;
+ }
+
+ return {
+ blockSpecs: blockSpecs,
+ uniformData: uniformData,
+ };
+}
+
+const arraySuffixRE = /\[\d+\]\.$/; // better way to check?
+
+/**
+ * Represents a UniformBlockObject including an ArrayBuffer with all the uniform values
+ * and a corresponding WebGLBuffer to hold those values on the GPU
+ *
+ * @typedef {Object} UniformBlockInfo
+ * @property {string} name The name of the block
+ * @property {ArrayBuffer} array The array buffer that contains the uniform values
+ * @property {Float32Array} asFloat A float view on the array buffer. This is useful
+ * inspecting the contents of the buffer in the debugger.
+ * @property {WebGLBuffer} buffer A WebGL buffer that will hold a copy of the uniform values for rendering.
+ * @property {number} [offset] offset into buffer
+ * @property {Object.} uniforms A uniform name to ArrayBufferView map.
+ * each Uniform has a correctly typed `ArrayBufferView` into array at the correct offset
+ * and length of that uniform. So for example a float uniform would have a 1 float `Float32Array`
+ * view. A single mat4 would have a 16 element `Float32Array` view. An ivec2 would have an
+ * `Int32Array` view, etc.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a `UniformBlockInfo` for the specified block
+ *
+ * Note: **If the blockName matches no existing blocks a warning is printed to the console and a dummy
+ * `UniformBlockInfo` is returned**. This is because when debugging GLSL
+ * it is common to comment out large portions of a shader or for example set
+ * the final output to a constant. When that happens blocks get optimized out.
+ * If this function did not create dummy blocks your code would crash when debugging.
+ *
+ * @param {WebGL2RenderingContext} gl A WebGL2RenderingContext
+ * @param {WebGLProgram} program A WebGLProgram
+ * @param {module:twgl.UniformBlockSpec} uniformBlockSpec. A UniformBlockSpec as returned
+ * from {@link module:twgl.createUniformBlockSpecFromProgram}.
+ * @param {string} blockName The name of the block.
+ * @return {module:twgl.UniformBlockInfo} The created UniformBlockInfo
+ * @memberOf module:twgl/programs
+ */
+function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockName) {
+ const blockSpecs = uniformBlockSpec.blockSpecs;
+ const uniformData = uniformBlockSpec.uniformData;
+ const blockSpec = blockSpecs[blockName];
+ if (!blockSpec) {
+ warn$1("no uniform block object named:", blockName);
+ return {
+ name: blockName,
+ uniforms: {},
+ };
+ }
+ const array = new ArrayBuffer(blockSpec.size);
+ const buffer = gl.createBuffer();
+ const uniformBufferIndex = blockSpec.index;
+ gl.bindBuffer(UNIFORM_BUFFER, buffer);
+ gl.uniformBlockBinding(program, blockSpec.index, uniformBufferIndex);
+
+ let prefix = blockName + ".";
+ if (arraySuffixRE.test(prefix)) {
+ prefix = prefix.replace(arraySuffixRE, ".");
+ }
+ const uniforms = {};
+ blockSpec.uniformIndices.forEach(function(uniformNdx) {
+ const data = uniformData[uniformNdx];
+ const typeInfo = typeMap[data.type];
+ const Type = typeInfo.Type;
+ const length = data.size * typeInfo.size;
+ let name = data.name;
+ if (name.substr(0, prefix.length) === prefix) {
+ name = name.substr(prefix.length);
+ }
+ uniforms[name] = new Type(array, data.offset, length / Type.BYTES_PER_ELEMENT);
+ });
+ return {
+ name: blockName,
+ array: array,
+ asFloat: new Float32Array(array), // for debugging
+ buffer: buffer,
+ uniforms: uniforms,
+ };
+}
+
+/**
+ * Creates a `UniformBlockInfo` for the specified block
+ *
+ * Note: **If the blockName matches no existing blocks a warning is printed to the console and a dummy
+ * `UniformBlockInfo` is returned**. This is because when debugging GLSL
+ * it is common to comment out large portions of a shader or for example set
+ * the final output to a constant. When that happens blocks get optimized out.
+ * If this function did not create dummy blocks your code would crash when debugging.
+ *
+ * @param {WebGL2RenderingContext} gl A WebGL2RenderingContext
+ * @param {module:twgl.ProgramInfo} programInfo a `ProgramInfo`
+ * as returned from {@link module:twgl.createProgramInfo}
+ * @param {string} blockName The name of the block.
+ * @return {module:twgl.UniformBlockInfo} The created UniformBlockInfo
+ * @memberOf module:twgl/programs
+ */
+function createUniformBlockInfo(gl, programInfo, blockName) {
+ return createUniformBlockInfoFromProgram(gl, programInfo.program, programInfo.uniformBlockSpec, blockName);
+}
+
+/**
+ * Binds a uniform block to the matching uniform block point.
+ * Matches by blocks by name so blocks must have the same name not just the same
+ * structure.
+ *
+ * If you have changed any values and you upload the values into the corresponding WebGLBuffer
+ * call {@link module:twgl.setUniformBlock} instead.
+ *
+ * @param {WebGL2RenderingContext} gl A WebGL 2 rendering context.
+ * @param {(module:twgl.ProgramInfo|module:twgl.UniformBlockSpec)} programInfo a `ProgramInfo`
+ * as returned from {@link module:twgl.createProgramInfo} or or `UniformBlockSpec` as
+ * returned from {@link module:twgl.createUniformBlockSpecFromProgram}.
+ * @param {module:twgl.UniformBlockInfo} uniformBlockInfo a `UniformBlockInfo` as returned from
+ * {@link module:twgl.createUniformBlockInfo}.
+ * @return {bool} true if buffer was bound. If the programInfo has no block with the same block name
+ * no buffer is bound.
+ * @memberOf module:twgl/programs
+ */
+function bindUniformBlock(gl, programInfo, uniformBlockInfo) {
+ const uniformBlockSpec = programInfo.uniformBlockSpec || programInfo;
+ const blockSpec = uniformBlockSpec.blockSpecs[uniformBlockInfo.name];
+ if (blockSpec) {
+ const bufferBindIndex = blockSpec.index;
+ gl.bindBufferRange(UNIFORM_BUFFER, bufferBindIndex, uniformBlockInfo.buffer, uniformBlockInfo.offset || 0, uniformBlockInfo.array.byteLength);
+ return true;
+ }
+ return false;
+}
+
+/**
+ * Uploads the current uniform values to the corresponding WebGLBuffer
+ * and binds that buffer to the program's corresponding bind point for the uniform block object.
+ *
+ * If you haven't changed any values and you only need to bind the uniform block object
+ * call {@link module:twgl.bindUniformBlock} instead.
+ *
+ * @param {WebGL2RenderingContext} gl A WebGL 2 rendering context.
+ * @param {(module:twgl.ProgramInfo|module:twgl.UniformBlockSpec)} programInfo a `ProgramInfo`
+ * as returned from {@link module:twgl.createProgramInfo} or or `UniformBlockSpec` as
+ * returned from {@link module:twgl.createUniformBlockSpecFromProgram}.
+ * @param {module:twgl.UniformBlockInfo} uniformBlockInfo a `UniformBlockInfo` as returned from
+ * {@link module:twgl.createUniformBlockInfo}.
+ * @memberOf module:twgl/programs
+ */
+function setUniformBlock(gl, programInfo, uniformBlockInfo) {
+ if (bindUniformBlock(gl, programInfo, uniformBlockInfo)) {
+ gl.bufferData(UNIFORM_BUFFER, uniformBlockInfo.array, DYNAMIC_DRAW);
+ }
+}
+
+/**
+ * Sets values of a uniform block object
+ *
+ * @param {module:twgl.UniformBlockInfo} uniformBlockInfo A UniformBlockInfo as returned by {@link module:twgl.createUniformBlockInfo}.
+ * @param {Object.} values A uniform name to value map where the value is correct for the given
+ * type of uniform. So for example given a block like
+ *
+ * uniform SomeBlock {
+ * float someFloat;
+ * vec2 someVec2;
+ * vec3 someVec3Array[2];
+ * int someInt;
+ * }
+ *
+ * You can set the values of the uniform block with
+ *
+ * twgl.setBlockUniforms(someBlockInfo, {
+ * someFloat: 12.3,
+ * someVec2: [1, 2],
+ * someVec3Array: [1, 2, 3, 4, 5, 6],
+ * someInt: 5,
+ * }
+ *
+ * Arrays can be JavaScript arrays or typed arrays
+ *
+ * Any name that doesn't match will be ignored
+ * @memberOf module:twgl/programs
+ */
+function setBlockUniforms(uniformBlockInfo, values) {
+ const uniforms = uniformBlockInfo.uniforms;
+ for (const name in values) {
+ const array = uniforms[name];
+ if (array) {
+ const value = values[name];
+ if (value.length) {
+ array.set(value);
+ } else {
+ array[0] = value;
+ }
+ }
+ }
+}
+
+/**
+ * Set uniforms and binds related textures.
+ *
+ * example:
+ *
+ * const programInfo = createProgramInfo(
+ * gl, ["some-vs", "some-fs"]);
+ *
+ * const tex1 = gl.createTexture();
+ * const tex2 = gl.createTexture();
+ *
+ * ... assume we setup the textures with data ...
+ *
+ * const uniforms = {
+ * u_someSampler: tex1,
+ * u_someOtherSampler: tex2,
+ * u_someColor: [1,0,0,1],
+ * u_somePosition: [0,1,1],
+ * u_someMatrix: [
+ * 1,0,0,0,
+ * 0,1,0,0,
+ * 0,0,1,0,
+ * 0,0,0,0,
+ * ],
+ * };
+ *
+ * gl.useProgram(program);
+ *
+ * This will automatically bind the textures AND set the
+ * uniforms.
+ *
+ * twgl.setUniforms(programInfo, uniforms);
+ *
+ * For the example above it is equivalent to
+ *
+ * var texUnit = 0;
+ * gl.activeTexture(gl.TEXTURE0 + texUnit);
+ * gl.bindTexture(gl.TEXTURE_2D, tex1);
+ * gl.uniform1i(u_someSamplerLocation, texUnit++);
+ * gl.activeTexture(gl.TEXTURE0 + texUnit);
+ * gl.bindTexture(gl.TEXTURE_2D, tex2);
+ * gl.uniform1i(u_someSamplerLocation, texUnit++);
+ * gl.uniform4fv(u_someColorLocation, [1, 0, 0, 1]);
+ * gl.uniform3fv(u_somePositionLocation, [0, 1, 1]);
+ * gl.uniformMatrix4fv(u_someMatrix, false, [
+ * 1,0,0,0,
+ * 0,1,0,0,
+ * 0,0,1,0,
+ * 0,0,0,0,
+ * ]);
+ *
+ * Note it is perfectly reasonable to call `setUniforms` multiple times. For example
+ *
+ * const uniforms = {
+ * u_someSampler: tex1,
+ * u_someOtherSampler: tex2,
+ * };
+ *
+ * const moreUniforms {
+ * u_someColor: [1,0,0,1],
+ * u_somePosition: [0,1,1],
+ * u_someMatrix: [
+ * 1,0,0,0,
+ * 0,1,0,0,
+ * 0,0,1,0,
+ * 0,0,0,0,
+ * ],
+ * };
+ *
+ * twgl.setUniforms(programInfo, uniforms);
+ * twgl.setUniforms(programInfo, moreUniforms);
+ *
+ * You can also add WebGLSamplers to uniform samplers as in
+ *
+ * const uniforms = {
+ * u_someSampler: {
+ * texture: someWebGLTexture,
+ * sampler: someWebGLSampler,
+ * },
+ * };
+ *
+ * In which case both the sampler and texture will be bound to the
+ * same unit.
+ *
+ * @param {(module:twgl.ProgramInfo|Object.)} setters a `ProgramInfo` as returned from `createProgramInfo` or the setters returned from
+ * `createUniformSetters`.
+ * @param {Object.} values an object with values for the
+ * uniforms.
+ * You can pass multiple objects by putting them in an array or by calling with more arguments.For example
+ *
+ * const sharedUniforms = {
+ * u_fogNear: 10,
+ * u_projection: ...
+ * ...
+ * };
+ *
+ * const localUniforms = {
+ * u_world: ...
+ * u_diffuseColor: ...
+ * };
+ *
+ * twgl.setUniforms(programInfo, sharedUniforms, localUniforms);
+ *
+ * // is the same as
+ *
+ * twgl.setUniforms(programInfo, [sharedUniforms, localUniforms]);
+ *
+ * // is the same as
+ *
+ * twgl.setUniforms(programInfo, sharedUniforms);
+ * twgl.setUniforms(programInfo, localUniforms};
+ *
+ * @memberOf module:twgl/programs
+ */
+function setUniforms(setters, values) { // eslint-disable-line
+ const actualSetters = setters.uniformSetters || setters;
+ const numArgs = arguments.length;
+ for (let aNdx = 1; aNdx < numArgs; ++aNdx) {
+ const values = arguments[aNdx];
+ if (Array.isArray(values)) {
+ const numValues = values.length;
+ for (let ii = 0; ii < numValues; ++ii) {
+ setUniforms(actualSetters, values[ii]);
+ }
+ } else {
+ for (const name in values) {
+ const setter = actualSetters[name];
+ if (setter) {
+ setter(values[name]);
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Alias for `setUniforms`
+ * @function
+ * @param {(module:twgl.ProgramInfo|Object.)} setters a `ProgramInfo` as returned from `createProgramInfo` or the setters returned from
+ * `createUniformSetters`.
+ * @param {Object.} values an object with values for the
+ * @memberOf module:twgl/programs
+ */
+const setUniformsAndBindTextures = setUniforms;
+
+/**
+ * Creates setter functions for all attributes of a shader
+ * program. You can pass this to {@link module:twgl.setBuffersAndAttributes} to set all your buffers and attributes.
+ *
+ * @see {@link module:twgl.setAttributes} for example
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {WebGLProgram} program the program to create setters for.
+ * @return {Object.} an object with a setter for each attribute by name.
+ * @memberOf module:twgl/programs
+ */
+function createAttributeSetters(gl, program) {
+ const attribSetters = {
+ };
+
+ const numAttribs = gl.getProgramParameter(program, ACTIVE_ATTRIBUTES);
+ for (let ii = 0; ii < numAttribs; ++ii) {
+ const attribInfo = gl.getActiveAttrib(program, ii);
+ if (isBuiltIn(attribInfo)) {
+ continue;
+ }
+ const index = gl.getAttribLocation(program, attribInfo.name);
+ const typeInfo = attrTypeMap[attribInfo.type];
+ const setter = typeInfo.setter(gl, index, typeInfo);
+ setter.location = index;
+ attribSetters[attribInfo.name] = setter;
+ }
+
+ return attribSetters;
+}
+
+/**
+ * Sets attributes and binds buffers (deprecated... use {@link module:twgl.setBuffersAndAttributes})
+ *
+ * Example:
+ *
+ * const program = createProgramFromScripts(
+ * gl, ["some-vs", "some-fs");
+ *
+ * const attribSetters = createAttributeSetters(program);
+ *
+ * const positionBuffer = gl.createBuffer();
+ * const texcoordBuffer = gl.createBuffer();
+ *
+ * const attribs = {
+ * a_position: {buffer: positionBuffer, numComponents: 3},
+ * a_texcoord: {buffer: texcoordBuffer, numComponents: 2},
+ * };
+ *
+ * gl.useProgram(program);
+ *
+ * This will automatically bind the buffers AND set the
+ * attributes.
+ *
+ * setAttributes(attribSetters, attribs);
+ *
+ * Properties of attribs. For each attrib you can add
+ * properties:
+ *
+ * * type: the type of data in the buffer. Default = gl.FLOAT
+ * * normalize: whether or not to normalize the data. Default = false
+ * * stride: the stride. Default = 0
+ * * offset: offset into the buffer. Default = 0
+ * * divisor: the divisor for instances. Default = undefined
+ *
+ * For example if you had 3 value float positions, 2 value
+ * float texcoord and 4 value uint8 colors you'd setup your
+ * attribs like this
+ *
+ * const attribs = {
+ * a_position: {buffer: positionBuffer, numComponents: 3},
+ * a_texcoord: {buffer: texcoordBuffer, numComponents: 2},
+ * a_color: {
+ * buffer: colorBuffer,
+ * numComponents: 4,
+ * type: gl.UNSIGNED_BYTE,
+ * normalize: true,
+ * },
+ * };
+ *
+ * @param {Object.} setters Attribute setters as returned from createAttributeSetters
+ * @param {Object.} buffers AttribInfos mapped by attribute name.
+ * @memberOf module:twgl/programs
+ * @deprecated use {@link module:twgl.setBuffersAndAttributes}
+ */
+function setAttributes(setters, buffers) {
+ for (const name in buffers) {
+ const setter = setters[name];
+ if (setter) {
+ setter(buffers[name]);
+ }
+ }
+}
+
+/**
+ * Sets attributes and buffers including the `ELEMENT_ARRAY_BUFFER` if appropriate
+ *
+ * Example:
+ *
+ * const programInfo = createProgramInfo(
+ * gl, ["some-vs", "some-fs");
+ *
+ * const arrays = {
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
+ * };
+ *
+ * const bufferInfo = createBufferInfoFromArrays(gl, arrays);
+ *
+ * gl.useProgram(programInfo.program);
+ *
+ * This will automatically bind the buffers AND set the
+ * attributes.
+ *
+ * setBuffersAndAttributes(gl, programInfo, bufferInfo);
+ *
+ * For the example above it is equivalent to
+ *
+ * gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
+ * gl.enableVertexAttribArray(a_positionLocation);
+ * gl.vertexAttribPointer(a_positionLocation, 3, gl.FLOAT, false, 0, 0);
+ * gl.bindBuffer(gl.ARRAY_BUFFER, texcoordBuffer);
+ * gl.enableVertexAttribArray(a_texcoordLocation);
+ * gl.vertexAttribPointer(a_texcoordLocation, 4, gl.FLOAT, false, 0, 0);
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext.
+ * @param {(module:twgl.ProgramInfo|Object.)} setters A `ProgramInfo` as returned from {@link module:twgl.createProgramInfo} or Attribute setters as returned from {@link module:twgl.createAttributeSetters}
+ * @param {(module:twgl.BufferInfo|module:twgl.VertexArrayInfo)} buffers a `BufferInfo` as returned from {@link module:twgl.createBufferInfoFromArrays}.
+ * or a `VertexArrayInfo` as returned from {@link module:twgl.createVertexArrayInfo}
+ * @memberOf module:twgl/programs
+ */
+function setBuffersAndAttributes(gl, programInfo, buffers) {
+ if (buffers.vertexArrayObject) {
+ gl.bindVertexArray(buffers.vertexArrayObject);
+ } else {
+ setAttributes(programInfo.attribSetters || programInfo, buffers.attribs);
+ if (buffers.indices) {
+ gl.bindBuffer(ELEMENT_ARRAY_BUFFER$1, buffers.indices);
+ }
+ }
+}
+
+/**
+ * @typedef {Object} ProgramInfo
+ * @property {WebGLProgram} program A shader program
+ * @property {Object} uniformSetters object of setters as returned from createUniformSetters,
+ * @property {Object} attribSetters object of setters as returned from createAttribSetters,
+ * @property {module:twgl.UniformBlockSpec} [uniformBlockSpace] a uniform block spec for making UniformBlockInfos with createUniformBlockInfo etc..
+ * @property {Object} [transformFeedbackInfo] info for transform feedbacks
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a ProgramInfo from an existing program.
+ *
+ * A ProgramInfo contains
+ *
+ * programInfo = {
+ * program: WebGLProgram,
+ * uniformSetters: object of setters as returned from createUniformSetters,
+ * attribSetters: object of setters as returned from createAttribSetters,
+ * }
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
+ * to use.
+ * @param {WebGLProgram} program an existing WebGLProgram.
+ * @return {module:twgl.ProgramInfo} The created ProgramInfo.
+ * @memberOf module:twgl/programs
+ */
+function createProgramInfoFromProgram(gl, program) {
+ const uniformSetters = createUniformSetters(gl, program);
+ const attribSetters = createAttributeSetters(gl, program);
+ const programInfo = {
+ program: program,
+ uniformSetters: uniformSetters,
+ attribSetters: attribSetters,
+ };
+
+ if (isWebGL2(gl)) {
+ programInfo.uniformBlockSpec = createUniformBlockSpecFromProgram(gl, program);
+ programInfo.transformFeedbackInfo = createTransformFeedbackInfo(gl, program);
+ }
+
+ return programInfo;
+}
+
+/**
+ * Creates a ProgramInfo from 2 sources.
+ *
+ * A ProgramInfo contains
+ *
+ * programInfo = {
+ * program: WebGLProgram,
+ * uniformSetters: object of setters as returned from createUniformSetters,
+ * attribSetters: object of setters as returned from createAttribSetters,
+ * }
+ *
+ * NOTE: There are 4 signatures for this function
+ *
+ * twgl.createProgramInfo(gl, [vs, fs], options);
+ * twgl.createProgramInfo(gl, [vs, fs], opt_errFunc);
+ * twgl.createProgramInfo(gl, [vs, fs], opt_attribs, opt_errFunc);
+ * twgl.createProgramInfo(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
+ * to use.
+ * @param {string[]} shaderSources Array of sources for the
+ * shaders or ids. The first is assumed to be the vertex shader,
+ * the second the fragment shader.
+ * @param {module:twgl.ProgramOptions|string[]|module:twgl.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
+ * @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
+ * on error. If you want something else pass an callback. It's passed an error message.
+ * @return {module:twgl.ProgramInfo?} The created ProgramInfo or null if it failed to link or compile
+ * @memberOf module:twgl/programs
+ */
+function createProgramInfo(
+ gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
+ const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
+ let good = true;
+ shaderSources = shaderSources.map(function(source) {
+ // Lets assume if there is no \n it's an id
+ if (source.indexOf("\n") < 0) {
+ const script = getElementById(source);
+ if (!script) {
+ progOptions.errorCallback("no element with id: " + source);
+ good = false;
+ } else {
+ source = script.text;
+ }
+ }
+ return source;
+ });
+ if (!good) {
+ return null;
+ }
+ const program = createProgramFromSources(gl, shaderSources, progOptions);
+ if (!program) {
+ return null;
+ }
+ return createProgramInfoFromProgram(gl, program);
+}
+
+var programs = /*#__PURE__*/Object.freeze({
+ __proto__: null,
+ createAttributeSetters: createAttributeSetters,
+ createProgram: createProgram,
+ createProgramFromScripts: createProgramFromScripts,
+ createProgramFromSources: createProgramFromSources,
+ createProgramInfo: createProgramInfo,
+ createProgramInfoFromProgram: createProgramInfoFromProgram,
+ createUniformSetters: createUniformSetters,
+ createUniformBlockSpecFromProgram: createUniformBlockSpecFromProgram,
+ createUniformBlockInfoFromProgram: createUniformBlockInfoFromProgram,
+ createUniformBlockInfo: createUniformBlockInfo,
+ createTransformFeedback: createTransformFeedback,
+ createTransformFeedbackInfo: createTransformFeedbackInfo,
+ bindTransformFeedbackInfo: bindTransformFeedbackInfo,
+ setAttributes: setAttributes,
+ setBuffersAndAttributes: setBuffersAndAttributes,
+ setUniforms: setUniforms,
+ setUniformsAndBindTextures: setUniformsAndBindTextures,
+ setUniformBlock: setUniformBlock,
+ setBlockUniforms: setBlockUniforms,
+ bindUniformBlock: bindUniformBlock
+});
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+const TRIANGLES = 0x0004;
+const UNSIGNED_SHORT$3 = 0x1403;
+
+/**
+ * Drawing related functions
+ *
+ * For backward compatibility they are available at both `twgl.draw` and `twgl`
+ * itself
+ *
+ * See {@link module:twgl} for core functions
+ *
+ * @module twgl/draw
+ */
+
+/**
+ * Calls `gl.drawElements` or `gl.drawArrays`, whichever is appropriate
+ *
+ * normally you'd call `gl.drawElements` or `gl.drawArrays` yourself
+ * but calling this means if you switch from indexed data to non-indexed
+ * data you don't have to remember to update your draw call.
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @param {(module:twgl.BufferInfo|module:twgl.VertexArrayInfo)} bufferInfo A BufferInfo as returned from {@link module:twgl.createBufferInfoFromArrays} or
+ * a VertexArrayInfo as returned from {@link module:twgl.createVertexArrayInfo}
+ * @param {number} [type] eg (gl.TRIANGLES, gl.LINES, gl.POINTS, gl.TRIANGLE_STRIP, ...). Defaults to `gl.TRIANGLES`
+ * @param {number} [count] An optional count. Defaults to bufferInfo.numElements
+ * @param {number} [offset] An optional offset. Defaults to 0.
+ * @param {number} [instanceCount] An optional instanceCount. if set then `drawArraysInstanced` or `drawElementsInstanced` will be called
+ * @memberOf module:twgl/draw
+ */
+function drawBufferInfo(gl, bufferInfo, type, count, offset, instanceCount) {
+ type = type === undefined ? TRIANGLES : type;
+ const indices = bufferInfo.indices;
+ const elementType = bufferInfo.elementType;
+ const numElements = count === undefined ? bufferInfo.numElements : count;
+ offset = offset === undefined ? 0 : offset;
+ if (elementType || indices) {
+ if (instanceCount !== undefined) {
+ gl.drawElementsInstanced(type, numElements, elementType === undefined ? UNSIGNED_SHORT$3 : bufferInfo.elementType, offset, instanceCount);
+ } else {
+ gl.drawElements(type, numElements, elementType === undefined ? UNSIGNED_SHORT$3 : bufferInfo.elementType, offset);
+ }
+ } else {
+ if (instanceCount !== undefined) {
+ gl.drawArraysInstanced(type, offset, numElements, instanceCount);
+ } else {
+ gl.drawArrays(type, offset, numElements);
+ }
+ }
+}
+
+/**
+ * A DrawObject is useful for putting objects in to an array and passing them to {@link module:twgl.drawObjectList}.
+ *
+ * You need either a `BufferInfo` or a `VertexArrayInfo`.
+ *
+ * @typedef {Object} DrawObject
+ * @property {boolean} [active] whether or not to draw. Default = `true` (must be `false` to be not true). In other words `undefined` = `true`
+ * @property {number} [type] type to draw eg. `gl.TRIANGLES`, `gl.LINES`, etc...
+ * @property {module:twgl.ProgramInfo} programInfo A ProgramInfo as returned from {@link module:twgl.createProgramInfo}
+ * @property {module:twgl.BufferInfo} [bufferInfo] A BufferInfo as returned from {@link module:twgl.createBufferInfoFromArrays}
+ * @property {module:twgl.VertexArrayInfo} [vertexArrayInfo] A VertexArrayInfo as returned from {@link module:twgl.createVertexArrayInfo}
+ * @property {Object} uniforms The values for the uniforms.
+ * You can pass multiple objects by putting them in an array. For example
+ *
+ * var sharedUniforms = {
+ * u_fogNear: 10,
+ * u_projection: ...
+ * ...
+ * };
+ *
+ * var localUniforms = {
+ * u_world: ...
+ * u_diffuseColor: ...
+ * };
+ *
+ * var drawObj = {
+ * ...
+ * uniforms: [sharedUniforms, localUniforms],
+ * };
+ *
+ * @property {number} [offset] the offset to pass to `gl.drawArrays` or `gl.drawElements`. Defaults to 0.
+ * @property {number} [count] the count to pass to `gl.drawArrays` or `gl.drawElements`. Defaults to bufferInfo.numElements.
+ * @property {number} [instanceCount] the number of instances. Defaults to undefined.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Draws a list of objects
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @param {DrawObject[]} objectsToDraw an array of objects to draw.
+ * @memberOf module:twgl/draw
+ */
+function drawObjectList(gl, objectsToDraw) {
+ let lastUsedProgramInfo = null;
+ let lastUsedBufferInfo = null;
+
+ objectsToDraw.forEach(function(object) {
+ if (object.active === false) {
+ return;
+ }
+
+ const programInfo = object.programInfo;
+ const bufferInfo = object.vertexArrayInfo || object.bufferInfo;
+ let bindBuffers = false;
+ const type = object.type === undefined ? TRIANGLES : object.type;
+
+ if (programInfo !== lastUsedProgramInfo) {
+ lastUsedProgramInfo = programInfo;
+ gl.useProgram(programInfo.program);
+
+ // We have to rebind buffers when changing programs because we
+ // only bind buffers the program uses. So if 2 programs use the same
+ // bufferInfo but the 1st one uses only positions the when the
+ // we switch to the 2nd one some of the attributes will not be on.
+ bindBuffers = true;
+ }
+
+ // Setup all the needed attributes.
+ if (bindBuffers || bufferInfo !== lastUsedBufferInfo) {
+ if (lastUsedBufferInfo && lastUsedBufferInfo.vertexArrayObject && !bufferInfo.vertexArrayObject) {
+ gl.bindVertexArray(null);
+ }
+ lastUsedBufferInfo = bufferInfo;
+ setBuffersAndAttributes(gl, programInfo, bufferInfo);
+ }
+
+ // Set the uniforms.
+ setUniforms(programInfo, object.uniforms);
+
+ // Draw
+ drawBufferInfo(gl, bufferInfo, type, object.count, object.offset, object.instanceCount);
+ });
+
+ if (lastUsedBufferInfo && lastUsedBufferInfo.vertexArrayObject) {
+ gl.bindVertexArray(null);
+ }
+}
+
+var draw = /*#__PURE__*/Object.freeze({
+ __proto__: null,
+ drawBufferInfo: drawBufferInfo,
+ drawObjectList: drawObjectList
+});
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+const FRAMEBUFFER = 0x8d40;
+const RENDERBUFFER = 0x8d41;
+const TEXTURE_2D$2 = 0x0de1;
+
+const UNSIGNED_BYTE$3 = 0x1401;
+
+/* PixelFormat */
+const DEPTH_COMPONENT$1 = 0x1902;
+const RGBA$1 = 0x1908;
+
+/* Framebuffer Object. */
+const RGBA4$1 = 0x8056;
+const RGB5_A1$1 = 0x8057;
+const RGB565$1 = 0x8D62;
+const DEPTH_COMPONENT16$1 = 0x81A5;
+const STENCIL_INDEX = 0x1901;
+const STENCIL_INDEX8 = 0x8D48;
+const DEPTH_STENCIL$1 = 0x84F9;
+const COLOR_ATTACHMENT0 = 0x8CE0;
+const DEPTH_ATTACHMENT = 0x8D00;
+const STENCIL_ATTACHMENT = 0x8D20;
+const DEPTH_STENCIL_ATTACHMENT = 0x821A;
+const CLAMP_TO_EDGE$1 = 0x812F;
+const LINEAR$1 = 0x2601;
+
+/**
+ * The options for a framebuffer attachment.
+ *
+ * Note: For a `format` that is a texture include all the texture
+ * options from {@link module:twgl.TextureOptions} for example
+ * `min`, `mag`, `clamp`, etc... Note that unlike {@link module:twgl.TextureOptions}
+ * `auto` defaults to `false` for attachment textures but `min` and `mag` default
+ * to `gl.LINEAR` and `wrap` defaults to `CLAMP_TO_EDGE`
+ *
+ * @typedef {Object} AttachmentOptions
+ * @property {number} [attach] The attachment point. Defaults
+ * to `gl.COLOR_ATTACHMENT0 + ndx` unless type is a depth or stencil type
+ * then it's gl.DEPTH_ATTACHMENT or `gl.DEPTH_STENCIL_ATTACHMENT` depending
+ * on the format or attachment type.
+ * @property {number} [format] The format. If one of `gl.RGBA4`,
+ * `gl.RGB565`, `gl.RGB5_A1`, `gl.DEPTH_COMPONENT16`,
+ * `gl.STENCIL_INDEX8` or `gl.DEPTH_STENCIL` then will create a
+ * renderbuffer. Otherwise will create a texture. Default = `gl.RGBA`
+ * @property {number} [type] The type. Used for texture. Default = `gl.UNSIGNED_BYTE`.
+ * @property {number} [target] The texture target for `gl.framebufferTexture2D`.
+ * Defaults to `gl.TEXTURE_2D`. Set to appropriate face for cube maps.
+ * @property {number} [level] level for `gl.framebufferTexture2D`. Defaults to 0.
+ * @property {number} [layer] layer for `gl.framebufferTextureLayer`. Defaults to undefined.
+ * If set then `gl.framebufferTextureLayer` is called, if not then `gl.framebufferTexture2D`
+ * @property {WebGLObject} [attachment] An existing renderbuffer or texture.
+ * If provided will attach this Object. This allows you to share
+ * attachments across framebuffers.
+ * @memberOf module:twgl
+ * @mixes module:twgl.TextureOptions
+ */
+
+const defaultAttachments = [
+ { format: RGBA$1, type: UNSIGNED_BYTE$3, min: LINEAR$1, wrap: CLAMP_TO_EDGE$1, },
+ { format: DEPTH_STENCIL$1, },
+];
+
+const attachmentsByFormat = {};
+attachmentsByFormat[DEPTH_STENCIL$1] = DEPTH_STENCIL_ATTACHMENT;
+attachmentsByFormat[STENCIL_INDEX] = STENCIL_ATTACHMENT;
+attachmentsByFormat[STENCIL_INDEX8] = STENCIL_ATTACHMENT;
+attachmentsByFormat[DEPTH_COMPONENT$1] = DEPTH_ATTACHMENT;
+attachmentsByFormat[DEPTH_COMPONENT16$1] = DEPTH_ATTACHMENT;
+
+function getAttachmentPointForFormat(format) {
+ return attachmentsByFormat[format];
+}
+
+const renderbufferFormats = {};
+renderbufferFormats[RGBA4$1] = true;
+renderbufferFormats[RGB5_A1$1] = true;
+renderbufferFormats[RGB565$1] = true;
+renderbufferFormats[DEPTH_STENCIL$1] = true;
+renderbufferFormats[DEPTH_COMPONENT16$1] = true;
+renderbufferFormats[STENCIL_INDEX] = true;
+renderbufferFormats[STENCIL_INDEX8] = true;
+
+function isRenderbufferFormat(format) {
+ return renderbufferFormats[format];
+}
+
+/**
+ * @typedef {Object} FramebufferInfo
+ * @property {WebGLFramebuffer} framebuffer The WebGLFramebuffer for this framebufferInfo
+ * @property {WebGLObject[]} attachments The created attachments in the same order as passed in to {@link module:twgl.createFramebufferInfo}.
+ * @property {number} width The width of the framebuffer and its attachments
+ * @property {number} height The width of the framebuffer and its attachments
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a framebuffer and attachments.
+ *
+ * This returns a {@link module:twgl.FramebufferInfo} because it needs to return the attachments as well as the framebuffer.
+ *
+ * The simplest usage
+ *
+ * // create an RGBA/UNSIGNED_BYTE texture and DEPTH_STENCIL renderbuffer
+ * const fbi = twgl.createFramebufferInfo(gl);
+ *
+ * More complex usage
+ *
+ * // create an RGB565 renderbuffer and a STENCIL_INDEX8 renderbuffer
+ * const attachments = [
+ * { format: RGB565, mag: NEAREST },
+ * { format: STENCIL_INDEX8 },
+ * ]
+ * const fbi = twgl.createFramebufferInfo(gl, attachments);
+ *
+ * Passing in a specific size
+ *
+ * const width = 256;
+ * const height = 256;
+ * const fbi = twgl.createFramebufferInfo(gl, attachments, width, height);
+ *
+ * **Note!!** It is up to you to check if the framebuffer is renderable by calling `gl.checkFramebufferStatus`.
+ * [WebGL1 only guarantees 3 combinations of attachments work](https://www.khronos.org/registry/webgl/specs/latest/1.0/#6.6).
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.AttachmentOptions[]} [attachments] which attachments to create. If not provided the default is a framebuffer with an
+ * `RGBA`, `UNSIGNED_BYTE` texture `COLOR_ATTACHMENT0` and a `DEPTH_STENCIL` renderbuffer `DEPTH_STENCIL_ATTACHMENT`.
+ * @param {number} [width] the width for the attachments. Default = size of drawingBuffer
+ * @param {number} [height] the height for the attachments. Default = size of drawingBuffer
+ * @return {module:twgl.FramebufferInfo} the framebuffer and attachments.
+ * @memberOf module:twgl/framebuffers
+ */
+function createFramebufferInfo(gl, attachments, width, height) {
+ const target = FRAMEBUFFER;
+ const fb = gl.createFramebuffer();
+ gl.bindFramebuffer(target, fb);
+ width = width || gl.drawingBufferWidth;
+ height = height || gl.drawingBufferHeight;
+ attachments = attachments || defaultAttachments;
+ let colorAttachmentCount = 0;
+ const framebufferInfo = {
+ framebuffer: fb,
+ attachments: [],
+ width: width,
+ height: height,
+ };
+ attachments.forEach(function(attachmentOptions) {
+ let attachment = attachmentOptions.attachment;
+ const format = attachmentOptions.format;
+ let attachmentPoint = getAttachmentPointForFormat(format);
+ if (!attachmentPoint) {
+ attachmentPoint = COLOR_ATTACHMENT0 + colorAttachmentCount++;
+ }
+ if (!attachment) {
+ if (isRenderbufferFormat(format)) {
+ attachment = gl.createRenderbuffer();
+ gl.bindRenderbuffer(RENDERBUFFER, attachment);
+ gl.renderbufferStorage(RENDERBUFFER, format, width, height);
+ } else {
+ const textureOptions = Object.assign({}, attachmentOptions);
+ textureOptions.width = width;
+ textureOptions.height = height;
+ if (textureOptions.auto === undefined) {
+ textureOptions.auto = false;
+ textureOptions.min = textureOptions.min || textureOptions.minMag || LINEAR$1;
+ textureOptions.mag = textureOptions.mag || textureOptions.minMag || LINEAR$1;
+ textureOptions.wrapS = textureOptions.wrapS || textureOptions.wrap || CLAMP_TO_EDGE$1;
+ textureOptions.wrapT = textureOptions.wrapT || textureOptions.wrap || CLAMP_TO_EDGE$1;
+ }
+ attachment = createTexture(gl, textureOptions);
+ }
+ }
+ if (isRenderbuffer(gl, attachment)) {
+ gl.framebufferRenderbuffer(target, attachmentPoint, RENDERBUFFER, attachment);
+ } else if (isTexture(gl, attachment)) {
+ if (attachmentOptions.layer !== undefined) {
+ gl.framebufferTextureLayer(
+ target,
+ attachmentPoint,
+ attachment,
+ attachmentOptions.level || 0,
+ attachmentOptions.layer);
+ } else {
+ gl.framebufferTexture2D(
+ target,
+ attachmentPoint,
+ attachmentOptions.texTarget || TEXTURE_2D$2,
+ attachment,
+ attachmentOptions.level || 0);
+ }
+ } else {
+ throw new Error('unknown attachment type');
+ }
+ framebufferInfo.attachments.push(attachment);
+ });
+ return framebufferInfo;
+}
+
+/**
+ * Resizes the attachments of a framebuffer.
+ *
+ * You need to pass in the same `attachments` as you passed in {@link module:twgl.createFramebufferInfo}
+ * because TWGL has no idea the format/type of each attachment.
+ *
+ * The simplest usage
+ *
+ * // create an RGBA/UNSIGNED_BYTE texture and DEPTH_STENCIL renderbuffer
+ * const fbi = twgl.createFramebufferInfo(gl);
+ *
+ * ...
+ *
+ * function render() {
+ * if (twgl.resizeCanvasToDisplaySize(gl.canvas)) {
+ * // resize the attachments
+ * twgl.resizeFramebufferInfo(gl, fbi);
+ * }
+ *
+ * More complex usage
+ *
+ * // create an RGB565 renderbuffer and a STENCIL_INDEX8 renderbuffer
+ * const attachments = [
+ * { format: RGB565, mag: NEAREST },
+ * { format: STENCIL_INDEX8 },
+ * ]
+ * const fbi = twgl.createFramebufferInfo(gl, attachments);
+ *
+ * ...
+ *
+ * function render() {
+ * if (twgl.resizeCanvasToDisplaySize(gl.canvas)) {
+ * // resize the attachments to match
+ * twgl.resizeFramebufferInfo(gl, fbi, attachments);
+ * }
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.FramebufferInfo} framebufferInfo a framebufferInfo as returned from {@link module:twgl.createFramebufferInfo}.
+ * @param {module:twgl.AttachmentOptions[]} [attachments] the same attachments options as passed to {@link module:twgl.createFramebufferInfo}.
+ * @param {number} [width] the width for the attachments. Default = size of drawingBuffer
+ * @param {number} [height] the height for the attachments. Default = size of drawingBuffer
+ * @memberOf module:twgl/framebuffers
+ */
+function resizeFramebufferInfo(gl, framebufferInfo, attachments, width, height) {
+ width = width || gl.drawingBufferWidth;
+ height = height || gl.drawingBufferHeight;
+ framebufferInfo.width = width;
+ framebufferInfo.height = height;
+ attachments = attachments || defaultAttachments;
+ attachments.forEach(function(attachmentOptions, ndx) {
+ const attachment = framebufferInfo.attachments[ndx];
+ const format = attachmentOptions.format;
+ if (isRenderbuffer(gl, attachment)) {
+ gl.bindRenderbuffer(RENDERBUFFER, attachment);
+ gl.renderbufferStorage(RENDERBUFFER, format, width, height);
+ } else if (isTexture(gl, attachment)) {
+ resizeTexture(gl, attachment, attachmentOptions, width, height);
+ } else {
+ throw new Error('unknown attachment type');
+ }
+ });
+}
+
+/**
+ * Binds a framebuffer
+ *
+ * This function pretty much solely exists because I spent hours
+ * trying to figure out why something I wrote wasn't working only
+ * to realize I forget to set the viewport dimensions.
+ * My hope is this function will fix that.
+ *
+ * It is effectively the same as
+ *
+ * gl.bindFramebuffer(gl.FRAMEBUFFER, someFramebufferInfo.framebuffer);
+ * gl.viewport(0, 0, someFramebufferInfo.width, someFramebufferInfo.height);
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.FramebufferInfo|null} [framebufferInfo] a framebufferInfo as returned from {@link module:twgl.createFramebufferInfo}.
+ * If falsy will bind the canvas.
+ * @param {number} [target] The target. If not passed `gl.FRAMEBUFFER` will be used.
+ * @memberOf module:twgl/framebuffers
+ */
+
+function bindFramebufferInfo(gl, framebufferInfo, target) {
+ target = target || FRAMEBUFFER;
+ if (framebufferInfo) {
+ gl.bindFramebuffer(target, framebufferInfo.framebuffer);
+ gl.viewport(0, 0, framebufferInfo.width, framebufferInfo.height);
+ } else {
+ gl.bindFramebuffer(target, null);
+ gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
+ }
+}
+
+var framebuffers = /*#__PURE__*/Object.freeze({
+ __proto__: null,
+ bindFramebufferInfo: bindFramebufferInfo,
+ createFramebufferInfo: createFramebufferInfo,
+ resizeFramebufferInfo: resizeFramebufferInfo
+});
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * vertex array object related functions
+ *
+ * You should generally not need to use these functions. They are provided
+ * for those cases where you're doing something out of the ordinary
+ * and you need lower level access.
+ *
+ * For backward compatibility they are available at both `twgl.attributes` and `twgl`
+ * itself
+ *
+ * See {@link module:twgl} for core functions
+ *
+ * @module twgl/vertexArrays
+ */
+
+const ELEMENT_ARRAY_BUFFER$2 = 0x8893;
+
+/**
+ * @typedef {Object} VertexArrayInfo
+ * @property {number} numElements The number of elements to pass to `gl.drawArrays` or `gl.drawElements`.
+ * @property {number} [elementType] The type of indices `UNSIGNED_BYTE`, `UNSIGNED_SHORT` etc..
+ * @property {WebGLVertexArrayObject} [vertexArrayObject] a vertex array object
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a VertexArrayInfo from a BufferInfo and one or more ProgramInfos
+ *
+ * This can be passed to {@link module:twgl.setBuffersAndAttributes} and to
+ * {@link module:twgl:drawBufferInfo}.
+ *
+ * > **IMPORTANT:** Vertex Array Objects are **not** a direct analog for a BufferInfo. Vertex Array Objects
+ * assign buffers to specific attributes at creation time. That means they can only be used with programs
+ * who's attributes use the same attribute locations for the same purposes.
+ *
+ * > Bind your attribute locations by passing an array of attribute names to {@link module:twgl.createProgramInfo}
+ * or use WebGL 2's GLSL ES 3's `layout(location = )` to make sure locations match.
+ *
+ * also
+ *
+ * > **IMPORTANT:** After calling twgl.setBuffersAndAttribute with a BufferInfo that uses a Vertex Array Object
+ * that Vertex Array Object will be bound. That means **ANY MANIPULATION OF ELEMENT_ARRAY_BUFFER or ATTRIBUTES**
+ * will affect the Vertex Array Object state.
+ *
+ * > Call `gl.bindVertexArray(null)` to get back manipulating the global attributes and ELEMENT_ARRAY_BUFFER.
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @param {module:twgl.ProgramInfo|module:twgl.ProgramInfo[]} programInfo a programInfo or array of programInfos
+ * @param {module:twgl.BufferInfo} bufferInfo BufferInfo as returned from createBufferInfoFromArrays etc...
+ *
+ * You need to make sure every attribute that will be used is bound. So for example assume shader 1
+ * uses attributes A, B, C and shader 2 uses attributes A, B, D. If you only pass in the programInfo
+ * for shader 1 then only attributes A, B, and C will have their attributes set because TWGL doesn't
+ * now attribute D's location.
+ *
+ * So, you can pass in both shader 1 and shader 2's programInfo
+ *
+ * @return {module:twgl.VertexArrayInfo} The created VertexArrayInfo
+ *
+ * @memberOf module:twgl/vertexArrays
+ */
+function createVertexArrayInfo(gl, programInfos, bufferInfo) {
+ const vao = gl.createVertexArray();
+ gl.bindVertexArray(vao);
+ if (!programInfos.length) {
+ programInfos = [programInfos];
+ }
+ programInfos.forEach(function(programInfo) {
+ setBuffersAndAttributes(gl, programInfo, bufferInfo);
+ });
+ gl.bindVertexArray(null);
+ return {
+ numElements: bufferInfo.numElements,
+ elementType: bufferInfo.elementType,
+ vertexArrayObject: vao,
+ };
+}
+
+/**
+ * Creates a vertex array object and then sets the attributes on it
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {Object.} setters Attribute setters as returned from createAttributeSetters
+ * @param {Object.} attribs AttribInfos mapped by attribute name.
+ * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices
+ * @memberOf module:twgl/vertexArrays
+ */
+function createVAOAndSetAttributes(gl, setters, attribs, indices) {
+ const vao = gl.createVertexArray();
+ gl.bindVertexArray(vao);
+ setAttributes(setters, attribs);
+ if (indices) {
+ gl.bindBuffer(ELEMENT_ARRAY_BUFFER$2, indices);
+ }
+ // We unbind this because otherwise any change to ELEMENT_ARRAY_BUFFER
+ // like when creating buffers for other stuff will mess up this VAO's binding
+ gl.bindVertexArray(null);
+ return vao;
+}
+
+/**
+ * Creates a vertex array object and then sets the attributes
+ * on it
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
+ * to use.
+ * @param {Object.| module:twgl.ProgramInfo} programInfo as returned from createProgramInfo or Attribute setters as returned from createAttributeSetters
+ * @param {module:twgl.BufferInfo} bufferInfo BufferInfo as returned from createBufferInfoFromArrays etc...
+ * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices
+ * @memberOf module:twgl/vertexArrays
+ */
+function createVAOFromBufferInfo(gl, programInfo, bufferInfo) {
+ return createVAOAndSetAttributes(gl, programInfo.attribSetters || programInfo, bufferInfo.attribs, bufferInfo.indices);
+}
+
+var vertexArrays = /*#__PURE__*/Object.freeze({
+ __proto__: null,
+ createVertexArrayInfo: createVertexArrayInfo,
+ createVAOAndSetAttributes: createVAOAndSetAttributes,
+ createVAOFromBufferInfo: createVAOFromBufferInfo
+});
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+const defaults$2 = {
+ addExtensionsToContext: true,
+};
+
+/**
+ * Various default settings for twgl.
+ *
+ * Note: You can call this any number of times. Example:
+ *
+ * twgl.setDefaults({ textureColor: [1, 0, 0, 1] });
+ * twgl.setDefaults({ attribPrefix: 'a_' });
+ *
+ * is equivalent to
+ *
+ * twgl.setDefaults({
+ * textureColor: [1, 0, 0, 1],
+ * attribPrefix: 'a_',
+ * });
+ *
+ * @typedef {Object} Defaults
+ * @property {string} [attribPrefix] The prefix to stick on attributes
+ *
+ * When writing shaders I prefer to name attributes with `a_`, uniforms with `u_` and varyings with `v_`
+ * as it makes it clear where they came from. But, when building geometry I prefer using un-prefixed names.
+ *
+ * In other words I'll create arrays of geometry like this
+ *
+ * const arrays = {
+ * position: ...
+ * normal: ...
+ * texcoord: ...
+ * };
+ *
+ * But need those mapped to attributes and my attributes start with `a_`.
+ *
+ * Default: `""`
+ *
+ * @property {number[]} [textureColor] Array of 4 values in the range 0 to 1
+ *
+ * The default texture color is used when loading textures from
+ * urls. Because the URL will be loaded async we'd like to be
+ * able to use the texture immediately. By putting a 1x1 pixel
+ * color in the texture we can start using the texture before
+ * the URL has loaded.
+ *
+ * Default: `[0.5, 0.75, 1, 1]`
+ *
+ * @property {string} [crossOrigin]
+ *
+ * If not undefined sets the crossOrigin attribute on images
+ * that twgl creates when downloading images for textures.
+ *
+ * Also see {@link module:twgl.TextureOptions}.
+ *
+ * @property {bool} [addExtensionsToContext]
+ *
+ * If true, then, when twgl will try to add any supported WebGL extensions
+ * directly to the context under their normal GL names. For example
+ * if ANGLE_instances_arrays exists then twgl would enable it,
+ * add the functions `vertexAttribDivisor`, `drawArraysInstanced`,
+ * `drawElementsInstanced`, and the constant `VERTEX_ATTRIB_ARRAY_DIVISOR`
+ * to the `WebGLRenderingContext`.
+ *
+ * @memberOf module:twgl
+ */
+
+/**
+ * Sets various defaults for twgl.
+ *
+ * In the interest of terseness which is kind of the point
+ * of twgl I've integrated a few of the older functions here
+ *
+ * @param {module:twgl.Defaults} newDefaults The default settings.
+ * @memberOf module:twgl
+ */
+function setDefaults$2(newDefaults) {
+ copyExistingProperties(newDefaults, defaults$2);
+ setDefaults(newDefaults); // eslint-disable-line
+ setDefaults$1(newDefaults); // eslint-disable-line
+}
+
+const prefixRE = /^(.*?)_/;
+function addExtensionToContext(gl, extensionName) {
+ glEnumToString(gl, 0);
+ const ext = gl.getExtension(extensionName);
+ if (ext) {
+ const enums = {};
+ const fnSuffix = prefixRE.exec(extensionName)[1];
+ const enumSuffix = '_' + fnSuffix;
+ for (const key in ext) {
+ const value = ext[key];
+ const isFunc = typeof (value) === 'function';
+ const suffix = isFunc ? fnSuffix : enumSuffix;
+ let name = key;
+ // examples of where this is not true are WEBGL_compressed_texture_s3tc
+ // and WEBGL_compressed_texture_pvrtc
+ if (key.endsWith(suffix)) {
+ name = key.substring(0, key.length - suffix.length);
+ }
+ if (gl[name] !== undefined) {
+ if (!isFunc && gl[name] !== value) {
+ warn(name, gl[name], value, key);
+ }
+ } else {
+ if (isFunc) {
+ gl[name] = function(origFn) {
+ return function() {
+ return origFn.apply(ext, arguments);
+ };
+ }(value);
+ } else {
+ gl[name] = value;
+ enums[name] = value;
+ }
+ }
+ }
+ // pass the modified enums to glEnumToString
+ enums.constructor = {
+ name: ext.constructor.name,
+ };
+ glEnumToString(enums, 0);
+ }
+ return ext;
+}
+
+/*
+ * If you're wondering why the code doesn't just iterate
+ * over all extensions using `gl.getExtensions` is that it's possible
+ * some future extension is incompatible with this code. Rather than
+ * have thing suddenly break it seems better to manually add to this
+ * list.
+ *
+ */
+const supportedExtensions = [
+ 'ANGLE_instanced_arrays',
+ 'EXT_blend_minmax',
+ 'EXT_color_buffer_float',
+ 'EXT_color_buffer_half_float',
+ 'EXT_disjoint_timer_query',
+ 'EXT_disjoint_timer_query_webgl2',
+ 'EXT_frag_depth',
+ 'EXT_sRGB',
+ 'EXT_shader_texture_lod',
+ 'EXT_texture_filter_anisotropic',
+ 'OES_element_index_uint',
+ 'OES_standard_derivatives',
+ 'OES_texture_float',
+ 'OES_texture_float_linear',
+ 'OES_texture_half_float',
+ 'OES_texture_half_float_linear',
+ 'OES_vertex_array_object',
+ 'WEBGL_color_buffer_float',
+ 'WEBGL_compressed_texture_atc',
+ 'WEBGL_compressed_texture_etc1',
+ 'WEBGL_compressed_texture_pvrtc',
+ 'WEBGL_compressed_texture_s3tc',
+ 'WEBGL_compressed_texture_s3tc_srgb',
+ 'WEBGL_depth_texture',
+ 'WEBGL_draw_buffers',
+];
+
+/**
+ * Attempts to enable all of the following extensions
+ * and add their functions and constants to the
+ * `WebGLRenderingContext` using their normal non-extension like names.
+ *
+ * ANGLE_instanced_arrays
+ * EXT_blend_minmax
+ * EXT_color_buffer_float
+ * EXT_color_buffer_half_float
+ * EXT_disjoint_timer_query
+ * EXT_disjoint_timer_query_webgl2
+ * EXT_frag_depth
+ * EXT_sRGB
+ * EXT_shader_texture_lod
+ * EXT_texture_filter_anisotropic
+ * OES_element_index_uint
+ * OES_standard_derivatives
+ * OES_texture_float
+ * OES_texture_float_linear
+ * OES_texture_half_float
+ * OES_texture_half_float_linear
+ * OES_vertex_array_object
+ * WEBGL_color_buffer_float
+ * WEBGL_compressed_texture_atc
+ * WEBGL_compressed_texture_etc1
+ * WEBGL_compressed_texture_pvrtc
+ * WEBGL_compressed_texture_s3tc
+ * WEBGL_compressed_texture_s3tc_srgb
+ * WEBGL_depth_texture
+ * WEBGL_draw_buffers
+ *
+ * For example if `ANGLE_instanced_arrays` exists then the functions
+ * `drawArraysInstanced`, `drawElementsInstanced`, `vertexAttribDivisor`
+ * and the constant `VERTEX_ATTRIB_ARRAY_DIVISOR` are added to the
+ * `WebGLRenderingContext`.
+ *
+ * Note that if you want to know if the extension exists you should
+ * probably call `gl.getExtension` for each extension. Alternatively
+ * you can check for the existence of the functions or constants that
+ * are expected to be added. For example
+ *
+ * if (gl.drawBuffers) {
+ * // Either WEBGL_draw_buffers was enabled OR you're running in WebGL2
+ * ....
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @memberOf module:twgl
+ */
+function addExtensionsToContext(gl) {
+ for (let ii = 0; ii < supportedExtensions.length; ++ii) {
+ addExtensionToContext(gl, supportedExtensions[ii]);
+ }
+}
+
+/**
+ * Creates a webgl context.
+ * @param {HTMLCanvasElement} canvas The canvas tag to get
+ * context from. If one is not passed in one will be
+ * created.
+ * @return {WebGLRenderingContext} The created context.
+ * @private
+ */
+function create3DContext(canvas, opt_attribs) {
+ const names = ["webgl", "experimental-webgl"];
+ let context = null;
+ for (let ii = 0; ii < names.length; ++ii) {
+ context = canvas.getContext(names[ii], opt_attribs);
+ if (context) {
+ if (defaults$2.addExtensionsToContext) {
+ addExtensionsToContext(context);
+ }
+ break;
+ }
+ }
+ return context;
+}
+
+/**
+ * Gets a WebGL1 context.
+ *
+ * Note: Will attempt to enable Vertex Array Objects
+ * and add WebGL2 entry points. (unless you first set defaults with
+ * `twgl.setDefaults({enableVertexArrayObjects: false})`;
+ *
+ * @param {HTMLCanvasElement} canvas a canvas element.
+ * @param {WebGLContextAttributes} [opt_attribs] optional webgl context creation attributes
+ * @return {WebGLRenderingContext} The created context.
+ * @memberOf module:twgl
+ */
+function getWebGLContext(canvas, opt_attribs) {
+ const gl = create3DContext(canvas, opt_attribs);
+ return gl;
+}
+
+/**
+ * Creates a webgl context.
+ *
+ * Will return a WebGL2 context if possible.
+ *
+ * You can check if it's WebGL2 with
+ *
+ * twgl.isWebGL2(gl);
+ *
+ * @param {HTMLCanvasElement} canvas The canvas tag to get
+ * context from. If one is not passed in one will be
+ * created.
+ * @return {WebGLRenderingContext} The created context.
+ */
+function createContext(canvas, opt_attribs) {
+ const names = ["webgl2", "webgl", "experimental-webgl"];
+ let context = null;
+ for (let ii = 0; ii < names.length; ++ii) {
+ context = canvas.getContext(names[ii], opt_attribs);
+ if (context) {
+ if (defaults$2.addExtensionsToContext) {
+ addExtensionsToContext(context);
+ }
+ break;
+ }
+ }
+ return context;
+}
+
+/**
+ * Gets a WebGL context. Will create a WebGL2 context if possible.
+ *
+ * You can check if it's WebGL2 with
+ *
+ * function isWebGL2(gl) {
+ * return gl.getParameter(gl.VERSION).indexOf("WebGL 2.0 ") == 0;
+ * }
+ *
+ * Note: For a WebGL1 context will attempt to enable Vertex Array Objects
+ * and add WebGL2 entry points. (unless you first set defaults with
+ * `twgl.setDefaults({enableVertexArrayObjects: false})`;
+ *
+ * @param {HTMLCanvasElement} canvas a canvas element.
+ * @param {WebGLContextAttributes} [opt_attribs] optional webgl context creation attributes
+ * @return {WebGLRenderingContext} The created context.
+ * @memberOf module:twgl
+ */
+function getContext(canvas, opt_attribs) {
+ const gl = createContext(canvas, opt_attribs);
+ return gl;
+}
+
+/**
+ * Resize a canvas to match the size it's displayed.
+ * @param {HTMLCanvasElement} canvas The canvas to resize.
+ * @param {number} [multiplier] So you can pass in `window.devicePixelRatio` or other scale value if you want to.
+ * @return {boolean} true if the canvas was resized.
+ * @memberOf module:twgl
+ */
+function resizeCanvasToDisplaySize(canvas, multiplier) {
+ multiplier = multiplier || 1;
+ multiplier = Math.max(0, multiplier);
+ const width = canvas.clientWidth * multiplier | 0;
+ const height = canvas.clientHeight * multiplier | 0;
+ if (canvas.width !== width || canvas.height !== height) {
+ canvas.width = width;
+ canvas.height = height;
+ return true;
+ }
+ return false;
+}
+
+export { addExtensionsToContext, attributes, bindFramebufferInfo, bindTransformFeedbackInfo, bindUniformBlock, canFilter, canGenerateMipmap, createAttribsFromArrays, createAttributeSetters, createBufferFromArray, createBufferFromTypedArray, createBufferInfoFromArrays, createBuffersFromArrays, createFramebufferInfo, createProgram, createProgramFromScripts, createProgramFromSources, createProgramInfo, createProgramInfoFromProgram, createSampler, createSamplers, createTexture, createTextures, createTransformFeedback, createTransformFeedbackInfo, createUniformBlockInfo, createUniformBlockInfoFromProgram, createUniformBlockSpecFromProgram, createUniformSetters, createVAOAndSetAttributes, createVAOFromBufferInfo, createVertexArrayInfo, draw, drawBufferInfo, drawObjectList, framebuffers, getArray as getArray_, getBytesPerElementForInternalFormat, getContext, getFormatAndTypeForInternalFormat, getGLTypeForTypedArray, getGLTypeForTypedArrayType, getNumComponentsForFormat, getNumComponents as getNumComponents_, getTypedArrayTypeForGLType, getWebGLContext, glEnumToString, isArrayBuffer, isWebGL1, isWebGL2, loadTextureFromUrl, m4, primitives, programs, resizeCanvasToDisplaySize, resizeFramebufferInfo, resizeTexture, setAttribInfoBufferFromArray, setDefaults as setAttributeDefaults_, setAttributePrefix, setAttributes, setBlockUniforms, setBuffersAndAttributes, setDefaultTextureColor, setDefaults$2 as setDefaults, setEmptyTexture, setSamplerParameters, setDefaults$1 as setTextureDefaults_, setTextureFilteringForSize, setTextureFromArray, setTextureFromElement, setTextureParameters, setUniformBlock, setUniforms, setUniformsAndBindTextures, textures, typedarrays, utils, v3, vertexArrays };
diff --git a/blocks/waves/twgl/twgl.d.ts b/blocks/waves/twgl/twgl.d.ts
new file mode 100755
index 00000000..20fcdf69
--- /dev/null
+++ b/blocks/waves/twgl/twgl.d.ts
@@ -0,0 +1,332 @@
+
+export type Defaults = {
+ attribPrefix?: string;
+ textureColor?: number[];
+ crossOrigin?: string;
+ addExtensionsToContext?: boolean;
+};
+export function setDefaults(newDefaults: Defaults): void;
+export function addExtensionsToContext(gl: WebGLRenderingContext): void;
+export function getWebGLContext(canvas: HTMLCanvasElement, opt_attribs?: WebGLContextAttributes): WebGLRenderingContext;
+export function createContext(canvas: HTMLCanvasElement): WebGLRenderingContext;
+export function getContext(canvas: HTMLCanvasElement, opt_attribs?: WebGLContextAttributes): WebGLRenderingContext;
+export function resizeCanvasToDisplaySize(canvas: HTMLCanvasElement, multiplier?: number): boolean;
+export type AttribInfo = {
+ value?: number[] | ArrayBufferView;
+ numComponents?: number;
+ size?: number;
+ type?: number;
+ normalize?: boolean;
+ offset?: number;
+ stride?: number;
+ divisor?: number;
+ buffer: WebGLBuffer;
+ drawType?: number;
+};
+export type FullArraySpec = {
+ value?: number[] | ArrayBufferView;
+ data: number | number[] | ArrayBufferView;
+ numComponents?: number;
+ type?: Function;
+ size?: number;
+ normalize?: boolean;
+ stride?: number;
+ offset?: number;
+ divisor?: number;
+ attrib?: string;
+ name?: string;
+ attribName?: string;
+ buffer?: WebGLBuffer;
+};
+export type ArraySpec = number | number[] | ArrayBufferView | FullArraySpec;
+export type Arrays = {
+ [key: string]: ArraySpec;
+};
+export type BufferInfo = {
+ numElements: number;
+ elementType?: number;
+ indices?: WebGLBuffer;
+ attribs?: {
+ [key: string]: AttribInfo;
+ };
+};
+export type DrawObject = {
+ active?: boolean;
+ type?: number;
+ programInfo: ProgramInfo;
+ bufferInfo?: BufferInfo;
+ vertexArrayInfo?: VertexArrayInfo;
+ uniforms: {
+ [key: string]: any;
+ };
+ offset?: number;
+ count?: number;
+ instanceCount?: number;
+};
+export type AttachmentOptions = TextureOptions & {
+ attach?: number;
+ format?: number;
+ type?: number;
+ target?: number;
+ level?: number;
+ layer?: number;
+ attachment?: WebGLObject;
+};
+export type FramebufferInfo = {
+ framebuffer: WebGLFramebuffer;
+ attachments: WebGLObject[];
+ width: number;
+ height: number;
+};
+export type ErrorCallback = (msg: string, lineOffset?: number) => void;
+export type ProgramOptions = {
+ errorCallback?: (...params: any[]) => any;
+ attribLocations?: {
+ [key: string]: number;
+ };
+ transformFeedbackVaryings?: BufferInfo | {
+ [key: string]: AttribInfo;
+ } | string[];
+ transformFeedbackMode?: number;
+};
+export type TransformFeedbackInfo = {
+ index: number;
+ type: number;
+ size: number;
+};
+export function createTransformFeedbackInfo(gl: WebGLRenderingContext, program: WebGLProgram): {
+ [key: string]: TransformFeedbackInfo;
+};
+export function bindTransformFeedbackInfo(gl: WebGLRenderingContext, transformFeedbackInfo: ProgramInfo | {
+ [key: string]: TransformFeedbackInfo;
+}, bufferInfo?: BufferInfo | {
+ [key: string]: AttribInfo;
+}): void;
+export function createTransformFeedback(gl: WebGLRenderingContext, programInfo: ProgramInfo, bufferInfo?: BufferInfo | {
+ [key: string]: AttribInfo;
+}): WebGLTransformFeedback;
+export type UniformData = {
+ type: number;
+ size: number;
+ blockNdx: number;
+ offset: number;
+};
+export type BlockSpec = {
+ index: number;
+ size: number;
+ uniformIndices: number[];
+ usedByVertexShader: boolean;
+ usedByFragmentShader: boolean;
+ used: boolean;
+};
+export type UniformBlockSpec = {
+ uniformData: UniformData[];
+};
+export type UniformBlockInfo = {
+ name: string;
+ array: ArrayBuffer;
+ asFloat: Float32Array;
+ buffer: WebGLBuffer;
+ offset?: number;
+ uniforms: {
+ [key: string]: ArrayBufferView;
+ };
+};
+export type ProgramInfo = {
+ program: WebGLProgram;
+ uniformSetters: {
+ [key: string]: (...params: any[]) => any;
+ };
+ attribSetters: {
+ [key: string]: (...params: any[]) => any;
+ };
+ uniformBlockSpace?: UniformBlockSpec;
+ transformFeedbackInfo?: {
+ [key: string]: TransformFeedbackInfo;
+ };
+};
+export type TextureFunc = (gl: WebGLRenderingContext, options: TextureOptions) => any;
+export type TextureOptions = {
+ target?: number;
+ level?: number;
+ width?: number;
+ height?: number;
+ depth?: number;
+ min?: number;
+ mag?: number;
+ minMag?: number;
+ internalFormat?: number;
+ format?: number;
+ type?: number;
+ wrap?: number;
+ wrapS?: number;
+ wrapT?: number;
+ wrapR?: number;
+ minLod?: number;
+ maxLod?: number;
+ baseLevel?: number;
+ maxLevel?: number;
+ unpackAlignment?: number;
+ color?: number[] | ArrayBufferView;
+ premultiplyAlpha?: number;
+ flipY?: number;
+ colorspaceConversion?: number;
+ auto?: boolean;
+ cubeFaceOrder?: number[];
+ src?: number[] | ArrayBufferView | TexImageSource | TexImageSource[] | string | string[] | TextureFunc;
+ crossOrigin?: string;
+};
+export type TextureSrc = HTMLImageElement | HTMLImageElement[];
+export type TextureReadyCallback = (err: any, texture: WebGLTexture, source: TextureSrc) => void;
+export type TexturesReadyCallback = (err: any, textures: {
+ [key: string]: WebGLTexture;
+}, sources: {
+ [key: string]: TextureSrc;
+}) => void;
+export type CubemapReadyCallback = (err: any, tex: WebGLTexture, imgs: HTMLImageElement[]) => void;
+export type ThreeDReadyCallback = (err: any, tex: WebGLTexture, imgs: HTMLImageElement[]) => void;
+export function isWebGL2(gl: WebGLRenderingContext): boolean;
+export function isWebGL1(gl: WebGLRenderingContext): boolean;
+export function glEnumToString(gl: WebGLRenderingContext, value: number): string;
+export type VertexArrayInfo = {
+ numElements: number;
+ elementType?: number;
+ vertexArrayObject?: WebGLVertexArrayObject;
+};
+export function setAttribInfoBufferFromArray(gl: WebGLRenderingContext, attribInfo: AttribInfo, array: ArraySpec, offset?: number): void;
+export function createBufferInfoFromArrays(gl: WebGLRenderingContext, arrays: Arrays, srcBufferInfo?: BufferInfo): BufferInfo;
+export function drawBufferInfo(gl: WebGLRenderingContext, bufferInfo: BufferInfo | VertexArrayInfo, type?: number, count?: number, offset?: number, instanceCount?: number): void;
+export function drawObjectList(gl: WebGLRenderingContext, objectsToDraw: DrawObject[]): void;
+export function createFramebufferInfo(gl: WebGLRenderingContext, attachments?: AttachmentOptions[], width?: number, height?: number): FramebufferInfo;
+export function resizeFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo: FramebufferInfo, attachments?: AttachmentOptions[], width?: number, height?: number): void;
+export function bindFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo?: FramebufferInfo | null, target?: number): void;
+export function createProgramInfo(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): ProgramInfo;
+export function createUniformBlockInfo(gl: WebGL2RenderingContext, programInfo: ProgramInfo, blockName: string): UniformBlockInfo;
+export function bindUniformBlock(gl: WebGL2RenderingContext, programInfo: ProgramInfo | UniformBlockSpec, uniformBlockInfo: UniformBlockInfo): boolean;
+export function setUniformBlock(gl: WebGL2RenderingContext, programInfo: ProgramInfo | UniformBlockSpec, uniformBlockInfo: UniformBlockInfo): void;
+export function setBlockUniforms(uniformBlockInfo: UniformBlockInfo, values: {
+ [key: string]: any;
+}): void;
+export function setUniforms(setters: ProgramInfo | {
+ [key: string]: (...params: any[]) => any;
+}, values: {
+ [key: string]: any;
+}): void;
+export function setBuffersAndAttributes(gl: WebGLRenderingContext, setters: ProgramInfo | {
+ [key: string]: (...params: any[]) => any;
+}, buffers: BufferInfo | VertexArrayInfo): void;
+export function setTextureFromArray(gl: WebGLRenderingContext, tex: WebGLTexture, src: number[] | ArrayBufferView, options?: TextureOptions): void;
+export function createTexture(gl: WebGLRenderingContext, options?: TextureOptions, callback?: TextureReadyCallback): WebGLTexture;
+export function resizeTexture(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, width?: number, height?: number, depth?: number): void;
+export function createTextures(gl: WebGLRenderingContext, options: {
+ [key: string]: TextureOptions;
+}, callback?: TexturesReadyCallback): {
+ [key: string]: WebGLTexture;
+};
+
+
+export function setAttributePrefix(prefix: string): void;
+export function createBufferFromTypedArray(gl: WebGLRenderingContext, typedArray: ArrayBuffer | SharedArrayBuffer | ArrayBufferView | WebGLBuffer, type?: number, drawType?: number): WebGLBuffer;
+export function createAttribsFromArrays(gl: WebGLRenderingContext, arrays: Arrays, srcBufferInfo?: BufferInfo): {
+ [key: string]: AttribInfo;
+};
+export function setAttribInfoBufferFromArray(gl: WebGLRenderingContext, attribInfo: AttribInfo, array: ArraySpec, offset?: number): void;
+export function createBufferInfoFromArrays(gl: WebGLRenderingContext, arrays: Arrays, srcBufferInfo?: BufferInfo): BufferInfo;
+export function createBufferFromArray(gl: WebGLRenderingContext, array: ArraySpec, arrayName: string): WebGLBuffer;
+export function createBuffersFromArrays(gl: WebGLRenderingContext, arrays: Arrays): {
+ [key: string]: WebGLBuffer;
+};
+
+
+export function drawBufferInfo(gl: WebGLRenderingContext, bufferInfo: BufferInfo | VertexArrayInfo, type?: number, count?: number, offset?: number, instanceCount?: number): void;
+export function drawObjectList(gl: WebGLRenderingContext, objectsToDraw: DrawObject[]): void;
+
+
+export function createFramebufferInfo(gl: WebGLRenderingContext, attachments?: AttachmentOptions[], width?: number, height?: number): FramebufferInfo;
+export function resizeFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo: FramebufferInfo, attachments?: AttachmentOptions[], width?: number, height?: number): void;
+export function bindFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo?: FramebufferInfo | null, target?: number): void;
+
+
+export function getBindPointForSamplerType(): void;
+export function createProgram(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
+export function createProgramFromScripts(gl: WebGLRenderingContext, shaderScriptIds: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
+export function createProgramFromSources(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
+export function createUniformSetters(gl: WebGLRenderingContext, program: WebGLProgram): {
+ [key: string]: (...params: any[]) => any;
+};
+export function createUniformBlockSpecFromProgram(gl: WebGL2RenderingContext, program: WebGLProgram): UniformBlockSpec;
+export function createUniformBlockInfoFromProgram(gl: WebGL2RenderingContext, program: WebGLProgram, blockName: string): UniformBlockInfo;
+export function createUniformBlockInfo(gl: WebGL2RenderingContext, programInfo: ProgramInfo, blockName: string): UniformBlockInfo;
+export function bindUniformBlock(gl: WebGL2RenderingContext, programInfo: ProgramInfo | UniformBlockSpec, uniformBlockInfo: UniformBlockInfo): boolean;
+export function setUniformBlock(gl: WebGL2RenderingContext, programInfo: ProgramInfo | UniformBlockSpec, uniformBlockInfo: UniformBlockInfo): void;
+export function setBlockUniforms(uniformBlockInfo: UniformBlockInfo, values: {
+ [key: string]: any;
+}): void;
+export function setUniforms(setters: ProgramInfo | {
+ [key: string]: (...params: any[]) => any;
+}, values: {
+ [key: string]: any;
+}): void;
+export function setUniformsAndBindTextures(setters: ProgramInfo | {
+ [key: string]: (...params: any[]) => any;
+}, values: {
+ [key: string]: any;
+}): void;
+export function createAttributeSetters(gl: WebGLRenderingContext, program: WebGLProgram): {
+ [key: string]: (...params: any[]) => any;
+};
+export function setAttributes(setters: {
+ [key: string]: (...params: any[]) => any;
+}, buffers: {
+ [key: string]: AttribInfo;
+}): void;
+export function setBuffersAndAttributes(gl: WebGLRenderingContext, setters: ProgramInfo | {
+ [key: string]: (...params: any[]) => any;
+}, buffers: BufferInfo | VertexArrayInfo): void;
+export function createProgramInfoFromProgram(gl: WebGLRenderingContext, program: WebGLProgram): ProgramInfo;
+export function createProgramInfo(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): ProgramInfo;
+
+
+export function getBytesPerElementForInternalFormat(internalFormat: number, type: number): number;
+export type TextureFormatInfo = {
+ format: number;
+ type: number;
+};
+export function getFormatAndTypeForInternalFormat(internalFormat: number): TextureFormatInfo;
+export function canGenerateMipmap(gl: WebGLRenderingContext, width: number, height: number, internalFormat: number): boolean;
+export function canFilter(internalFormat: number): boolean;
+export function getNumComponentsForFormat(format: number): number;
+export function setDefaultTextureColor(color: number[]): void;
+export function setTextureParameters(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions): void;
+export function setSamplerParameters(gl: WebGLRenderingContext, sampler: WebGLSampler, options: TextureOptions): void;
+export function setTextureFilteringForSize(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions, width?: number, height?: number, internalFormat?: number): void;
+export function setTextureFromElement(gl: WebGLRenderingContext, tex: WebGLTexture, element: HTMLElement, options?: TextureOptions): void;
+export function setTextureTo1PixelColor(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions): void;
+export function loadTextureFromUrl(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions, callback?: TextureReadyCallback): HTMLImageElement;
+export function loadCubemapFromUrls(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, callback?: CubemapReadyCallback): void;
+export function loadSlicesFromUrls(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, callback?: ThreeDReadyCallback): void;
+export function setTextureFromArray(gl: WebGLRenderingContext, tex: WebGLTexture, src: number[] | ArrayBufferView, options?: TextureOptions): void;
+export function setEmptyTexture(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions): void;
+export function createTexture(gl: WebGLRenderingContext, options?: TextureOptions, callback?: TextureReadyCallback): WebGLTexture;
+export function resizeTexture(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, width?: number, height?: number, depth?: number): void;
+export function createTextures(gl: WebGLRenderingContext, options: {
+ [key: string]: TextureOptions;
+}, callback?: TexturesReadyCallback): {
+ [key: string]: WebGLTexture;
+};
+
+
+export function getGLTypeForTypedArray(typedArray: ArrayBufferView): number;
+export function getGLTypeForTypedArrayType(typedArrayType: ArrayBufferView): number;
+export function getTypedArrayTypeForGLType(type: number): (...params: any[]) => any;
+
+
+export function createVertexArrayInfo(gl: WebGLRenderingContext, programInfo: ProgramInfo | ProgramInfo[], bufferInfo: BufferInfo): VertexArrayInfo;
+export function createVAOAndSetAttributes(gl: WebGLRenderingContext, setters: {
+ [key: string]: (...params: any[]) => any;
+}, attribs: {
+ [key: string]: AttribInfo;
+}, indices?: WebGLBuffer): void;
+export function createVAOFromBufferInfo(gl: WebGLRenderingContext, programInfo: {
+ [key: string]: (...params: any[]) => any;
+} | ProgramInfo, bufferInfo: BufferInfo, indices?: WebGLBuffer): void;
diff --git a/blocks/waves/twgl/twgl.js b/blocks/waves/twgl/twgl.js
new file mode 100755
index 00000000..6f87facf
--- /dev/null
+++ b/blocks/waves/twgl/twgl.js
@@ -0,0 +1,7042 @@
+/*!
+ * @license twgl.js 4.14.2 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
+ * Available via the MIT license.
+ * see: http://github.com/greggman/twgl.js for details
+ */
+(function webpackUniversalModuleDefinition(root, factory) {
+ if(typeof exports === 'object' && typeof module === 'object')
+ module.exports = factory();
+ else if(typeof define === 'function' && define.amd)
+ define([], factory);
+ else if(typeof exports === 'object')
+ exports["twgl"] = factory();
+ else
+ root["twgl"] = factory();
+})(typeof self !== 'undefined' ? self : this, function() {
+return /******/ (function(modules) { // webpackBootstrap
+/******/ // The module cache
+/******/ var installedModules = {};
+/******/
+/******/ // The require function
+/******/ function __webpack_require__(moduleId) {
+/******/
+/******/ // Check if module is in cache
+/******/ if(installedModules[moduleId]) {
+/******/ return installedModules[moduleId].exports;
+/******/ }
+/******/ // Create a new module (and put it into the cache)
+/******/ var module = installedModules[moduleId] = {
+/******/ i: moduleId,
+/******/ l: false,
+/******/ exports: {}
+/******/ };
+/******/
+/******/ // Execute the module function
+/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
+/******/
+/******/ // Flag the module as loaded
+/******/ module.l = true;
+/******/
+/******/ // Return the exports of the module
+/******/ return module.exports;
+/******/ }
+/******/
+/******/
+/******/ // expose the modules object (__webpack_modules__)
+/******/ __webpack_require__.m = modules;
+/******/
+/******/ // expose the module cache
+/******/ __webpack_require__.c = installedModules;
+/******/
+/******/ // define getter function for harmony exports
+/******/ __webpack_require__.d = function(exports, name, getter) {
+/******/ if(!__webpack_require__.o(exports, name)) {
+/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
+/******/ }
+/******/ };
+/******/
+/******/ // define __esModule on exports
+/******/ __webpack_require__.r = function(exports) {
+/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
+/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
+/******/ }
+/******/ Object.defineProperty(exports, '__esModule', { value: true });
+/******/ };
+/******/
+/******/ // create a fake namespace object
+/******/ // mode & 1: value is a module id, require it
+/******/ // mode & 2: merge all properties of value into the ns
+/******/ // mode & 4: return value when already ns object
+/******/ // mode & 8|1: behave like require
+/******/ __webpack_require__.t = function(value, mode) {
+/******/ if(mode & 1) value = __webpack_require__(value);
+/******/ if(mode & 8) return value;
+/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
+/******/ var ns = Object.create(null);
+/******/ __webpack_require__.r(ns);
+/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
+/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
+/******/ return ns;
+/******/ };
+/******/
+/******/ // getDefaultExport function for compatibility with non-harmony modules
+/******/ __webpack_require__.n = function(module) {
+/******/ var getter = module && module.__esModule ?
+/******/ function getDefault() { return module['default']; } :
+/******/ function getModuleExports() { return module; };
+/******/ __webpack_require__.d(getter, 'a', getter);
+/******/ return getter;
+/******/ };
+/******/
+/******/ // Object.prototype.hasOwnProperty.call
+/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
+/******/
+/******/ // __webpack_public_path__
+/******/ __webpack_require__.p = "";
+/******/
+/******/
+/******/ // Load entry module and return exports
+/******/ return __webpack_require__(__webpack_require__.s = "./src/twgl-base.js");
+/******/ })
+/************************************************************************/
+/******/ ({
+
+/***/ "./src/attributes.js":
+/*!***************************!*\
+ !*** ./src/attributes.js ***!
+ \***************************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.createAttribsFromArrays = createAttribsFromArrays;
+exports.createBuffersFromArrays = createBuffersFromArrays;
+exports.createBufferFromArray = createBufferFromArray;
+exports.createBufferFromTypedArray = createBufferFromTypedArray;
+exports.createBufferInfoFromArrays = createBufferInfoFromArrays;
+exports.setAttribInfoBufferFromArray = setAttribInfoBufferFromArray;
+exports.setAttributePrefix = setAttributePrefix;
+exports.setAttributeDefaults_ = setDefaults;
+exports.getNumComponents_ = getNumComponents;
+exports.getArray_ = getArray;
+
+var typedArrays = _interopRequireWildcard(__webpack_require__(/*! ./typedarrays.js */ "./src/typedarrays.js"));
+
+var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
+
+function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+var STATIC_DRAW = 0x88e4;
+var ARRAY_BUFFER = 0x8892;
+var ELEMENT_ARRAY_BUFFER = 0x8893;
+var BUFFER_SIZE = 0x8764;
+var BYTE = 0x1400;
+var UNSIGNED_BYTE = 0x1401;
+var SHORT = 0x1402;
+var UNSIGNED_SHORT = 0x1403;
+var INT = 0x1404;
+var UNSIGNED_INT = 0x1405;
+var FLOAT = 0x1406;
+/**
+ * Low level attribute and buffer related functions
+ *
+ * You should generally not need to use these functions. They are provided
+ * for those cases where you're doing something out of the ordinary
+ * and you need lower level access.
+ *
+ * For backward compatibility they are available at both `twgl.attributes` and `twgl`
+ * itself
+ *
+ * See {@link module:twgl} for core functions
+ *
+ * @module twgl/attributes
+ */
+// make sure we don't see a global gl
+
+var gl = undefined;
+/* eslint-disable-line */
+
+/* lgtm [js/unused-local-variable] */
+
+var defaults = {
+ attribPrefix: ""
+};
+/**
+ * Sets the default attrib prefix
+ *
+ * When writing shaders I prefer to name attributes with `a_`, uniforms with `u_` and varyings with `v_`
+ * as it makes it clear where they came from. But, when building geometry I prefer using un-prefixed names.
+ *
+ * In other words I'll create arrays of geometry like this
+ *
+ * var arrays = {
+ * position: ...
+ * normal: ...
+ * texcoord: ...
+ * };
+ *
+ * But need those mapped to attributes and my attributes start with `a_`.
+ *
+ * @deprecated see {@link module:twgl.setDefaults}
+ * @param {string} prefix prefix for attribs
+ * @memberOf module:twgl/attributes
+ */
+
+function setAttributePrefix(prefix) {
+ defaults.attribPrefix = prefix;
+}
+
+function setDefaults(newDefaults) {
+ helper.copyExistingProperties(newDefaults, defaults);
+}
+
+function setBufferFromTypedArray(gl, type, buffer, array, drawType) {
+ gl.bindBuffer(type, buffer);
+ gl.bufferData(type, array, drawType || STATIC_DRAW);
+}
+/**
+ * Given typed array creates a WebGLBuffer and copies the typed array
+ * into it.
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @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
+ * @param {number} [type] the GL bind type for the buffer. Default = `gl.ARRAY_BUFFER`.
+ * @param {number} [drawType] the GL draw type for the buffer. Default = 'gl.STATIC_DRAW`.
+ * @return {WebGLBuffer} the created WebGLBuffer
+ * @memberOf module:twgl/attributes
+ */
+
+
+function createBufferFromTypedArray(gl, typedArray, type, drawType) {
+ if (helper.isBuffer(gl, typedArray)) {
+ return typedArray;
+ }
+
+ type = type || ARRAY_BUFFER;
+ var buffer = gl.createBuffer();
+ setBufferFromTypedArray(gl, type, buffer, typedArray, drawType);
+ return buffer;
+}
+
+function isIndices(name) {
+ return name === "indices";
+} // This is really just a guess. Though I can't really imagine using
+// anything else? Maybe for some compression?
+
+
+function getNormalizationForTypedArray(typedArray) {
+ if (typedArray instanceof Int8Array) {
+ return true;
+ } // eslint-disable-line
+
+
+ if (typedArray instanceof Uint8Array) {
+ return true;
+ } // eslint-disable-line
+
+
+ return false;
+} // This is really just a guess. Though I can't really imagine using
+// anything else? Maybe for some compression?
+
+
+function getNormalizationForTypedArrayType(typedArrayType) {
+ if (typedArrayType === Int8Array) {
+ return true;
+ } // eslint-disable-line
+
+
+ if (typedArrayType === Uint8Array) {
+ return true;
+ } // eslint-disable-line
+
+
+ return false;
+}
+
+function getArray(array) {
+ return array.length ? array : array.data;
+}
+
+var texcoordRE = /coord|texture/i;
+var colorRE = /color|colour/i;
+
+function guessNumComponentsFromName(name, length) {
+ var numComponents;
+
+ if (texcoordRE.test(name)) {
+ numComponents = 2;
+ } else if (colorRE.test(name)) {
+ numComponents = 4;
+ } else {
+ numComponents = 3; // position, normals, indices ...
+ }
+
+ if (length % numComponents > 0) {
+ throw new Error("Can not guess numComponents for attribute '".concat(name, "'. Tried ").concat(numComponents, " but ").concat(length, " values is not evenly divisible by ").concat(numComponents, ". You should specify it."));
+ }
+
+ return numComponents;
+}
+
+function getNumComponents(array, arrayName) {
+ return array.numComponents || array.size || guessNumComponentsFromName(arrayName, getArray(array).length);
+}
+
+function makeTypedArray(array, name) {
+ if (typedArrays.isArrayBuffer(array)) {
+ return array;
+ }
+
+ if (typedArrays.isArrayBuffer(array.data)) {
+ return array.data;
+ }
+
+ if (Array.isArray(array)) {
+ array = {
+ data: array
+ };
+ }
+
+ var Type = array.type;
+
+ if (!Type) {
+ if (isIndices(name)) {
+ Type = Uint16Array;
+ } else {
+ Type = Float32Array;
+ }
+ }
+
+ return new Type(array.data);
+}
+/**
+ * The info for an attribute. This is effectively just the arguments to `gl.vertexAttribPointer` plus the WebGLBuffer
+ * for the attribute.
+ *
+ * @typedef {Object} AttribInfo
+ * @property {number[]|ArrayBufferView} [value] a constant value for the attribute. Note: if this is set the attribute will be
+ * disabled and set to this constant value and all other values will be ignored.
+ * @property {number} [numComponents] the number of components for this attribute.
+ * @property {number} [size] synonym for `numComponents`.
+ * @property {number} [type] the type of the attribute (eg. `gl.FLOAT`, `gl.UNSIGNED_BYTE`, etc...) Default = `gl.FLOAT`
+ * @property {boolean} [normalize] whether or not to normalize the data. Default = false
+ * @property {number} [offset] offset into buffer in bytes. Default = 0
+ * @property {number} [stride] the stride in bytes per element. Default = 0
+ * @property {number} [divisor] the divisor in instances. Default = undefined. Note: undefined = don't call gl.vertexAttribDivisor
+ * where as anything else = do call it with this value
+ * @property {WebGLBuffer} buffer the buffer that contains the data for this attribute
+ * @property {number} [drawType] the draw type passed to gl.bufferData. Default = gl.STATIC_DRAW
+ * @memberOf module:twgl
+ */
+
+/**
+ * Use this type of array spec when TWGL can't guess the type or number of components of an array
+ * @typedef {Object} FullArraySpec
+ * @property {number[]|ArrayBufferView} [value] a constant value for the attribute. Note: if this is set the attribute will be
+ * disabled and set to this constant value and all other values will be ignored.
+ * @property {(number|number[]|ArrayBufferView)} data The data of the array. A number alone becomes the number of elements of type.
+ * @property {number} [numComponents] number of components for `vertexAttribPointer`. Default is based on the name of the array.
+ * If `coord` is in the name assumes `numComponents = 2`.
+ * If `color` is in the name assumes `numComponents = 4`.
+ * otherwise assumes `numComponents = 3`
+ * @property {constructor} [type] type. This is only used if `data` is a JavaScript array. It is the constructor for the typedarray. (eg. `Uint8Array`).
+ * For example if you want colors in a `Uint8Array` you might have a `FullArraySpec` like `{ type: Uint8Array, data: [255,0,255,255, ...], }`.
+ * @property {number} [size] synonym for `numComponents`.
+ * @property {boolean} [normalize] normalize for `vertexAttribPointer`. Default is true if type is `Int8Array` or `Uint8Array` otherwise false.
+ * @property {number} [stride] stride for `vertexAttribPointer`. Default = 0
+ * @property {number} [offset] offset for `vertexAttribPointer`. Default = 0
+ * @property {number} [divisor] divisor for `vertexAttribDivisor`. Default = undefined. Note: undefined = don't call gl.vertexAttribDivisor
+ * where as anything else = do call it with this value
+ * @property {string} [attrib] name of attribute this array maps to. Defaults to same name as array prefixed by the default attribPrefix.
+ * @property {string} [name] synonym for `attrib`.
+ * @property {string} [attribName] synonym for `attrib`.
+ * @property {WebGLBuffer} [buffer] Buffer to use for this attribute. This lets you use your own buffer
+ * but you will need to supply `numComponents` and `type`. You can effectively pass an `AttribInfo`
+ * to provide this. Example:
+ *
+ * const bufferInfo1 = twgl.createBufferInfoFromArrays(gl, {
+ * position: [1, 2, 3, ... ],
+ * });
+ * const bufferInfo2 = twgl.createBufferInfoFromArrays(gl, {
+ * position: bufferInfo1.attribs.position, // use the same buffer from bufferInfo1
+ * });
+ *
+ * @memberOf module:twgl
+ */
+
+/**
+ * An individual array in {@link module:twgl.Arrays}
+ *
+ * When passed to {@link module:twgl.createBufferInfoFromArrays} if an ArraySpec is `number[]` or `ArrayBufferView`
+ * the types will be guessed based on the name. `indices` will be `Uint16Array`, everything else will
+ * be `Float32Array`. If an ArraySpec is a number it's the number of floats for an empty (zeroed) buffer.
+ *
+ * @typedef {(number|number[]|ArrayBufferView|module:twgl.FullArraySpec)} ArraySpec
+ * @memberOf module:twgl
+ */
+
+/**
+ * This is a JavaScript object of arrays by name. The names should match your shader's attributes. If your
+ * attributes have a common prefix you can specify it by calling {@link module:twgl.setAttributePrefix}.
+ *
+ * Bare JavaScript Arrays
+ *
+ * var arrays = {
+ * position: [-1, 1, 0],
+ * normal: [0, 1, 0],
+ * ...
+ * }
+ *
+ * Bare TypedArrays
+ *
+ * var arrays = {
+ * position: new Float32Array([-1, 1, 0]),
+ * color: new Uint8Array([255, 128, 64, 255]),
+ * ...
+ * }
+ *
+ * * Will guess at `numComponents` if not specified based on name.
+ *
+ * If `coord` is in the name assumes `numComponents = 2`
+ *
+ * If `color` is in the name assumes `numComponents = 4`
+ *
+ * otherwise assumes `numComponents = 3`
+ *
+ * Objects with various fields. See {@link module:twgl.FullArraySpec}.
+ *
+ * var arrays = {
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
+ * normal: { numComponents: 3, data: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], },
+ * indices: { numComponents: 3, data: [0, 1, 2, 1, 2, 3], },
+ * };
+ *
+ * @typedef {Object.} Arrays
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a set of attribute data and WebGLBuffers from set of arrays
+ *
+ * Given
+ *
+ * var arrays = {
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
+ * normal: { numComponents: 3, data: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], },
+ * color: { numComponents: 4, data: [255, 255, 255, 255, 255, 0, 0, 255, 0, 0, 255, 255], type: Uint8Array, },
+ * indices: { numComponents: 3, data: [0, 1, 2, 1, 2, 3], },
+ * };
+ *
+ * returns something like
+ *
+ * var attribs = {
+ * position: { numComponents: 3, type: gl.FLOAT, normalize: false, buffer: WebGLBuffer, },
+ * texcoord: { numComponents: 2, type: gl.FLOAT, normalize: false, buffer: WebGLBuffer, },
+ * normal: { numComponents: 3, type: gl.FLOAT, normalize: false, buffer: WebGLBuffer, },
+ * color: { numComponents: 4, type: gl.UNSIGNED_BYTE, normalize: true, buffer: WebGLBuffer, },
+ * };
+ *
+ * notes:
+ *
+ * * Arrays can take various forms
+ *
+ * Bare JavaScript Arrays
+ *
+ * var arrays = {
+ * position: [-1, 1, 0],
+ * normal: [0, 1, 0],
+ * ...
+ * }
+ *
+ * Bare TypedArrays
+ *
+ * var arrays = {
+ * position: new Float32Array([-1, 1, 0]),
+ * color: new Uint8Array([255, 128, 64, 255]),
+ * ...
+ * }
+ *
+ * * Will guess at `numComponents` if not specified based on name.
+ *
+ * If `coord` is in the name assumes `numComponents = 2`
+ *
+ * If `color` is in the name assumes `numComponents = 4`
+ *
+ * otherwise assumes `numComponents = 3`
+ *
+ * @param {WebGLRenderingContext} gl The webgl rendering context.
+ * @param {module:twgl.Arrays} arrays The arrays
+ * @param {module:twgl.BufferInfo} [srcBufferInfo] a BufferInfo to copy from
+ * This lets you share buffers. Any arrays you supply will override
+ * the buffers from srcBufferInfo.
+ * @return {Object.} the attribs
+ * @memberOf module:twgl/attributes
+ */
+
+
+function createAttribsFromArrays(gl, arrays) {
+ var attribs = {};
+ Object.keys(arrays).forEach(function (arrayName) {
+ if (!isIndices(arrayName)) {
+ var array = arrays[arrayName];
+ var attribName = array.attrib || array.name || array.attribName || defaults.attribPrefix + arrayName;
+
+ if (array.value) {
+ if (!Array.isArray(array.value) && !typedArrays.isArrayBuffer(array.value)) {
+ throw new Error('array.value is not array or typedarray');
+ }
+
+ attribs[attribName] = {
+ value: array.value
+ };
+ } else {
+ var buffer;
+ var type;
+ var normalization;
+ var numComponents;
+
+ if (array.buffer && array.buffer instanceof WebGLBuffer) {
+ buffer = array.buffer;
+ numComponents = array.numComponents || array.size;
+ type = array.type;
+ normalization = array.normalize;
+ } else if (typeof array === "number" || typeof array.data === "number") {
+ var numValues = array.data || array;
+ var arrayType = array.type || Float32Array;
+ var numBytes = numValues * arrayType.BYTES_PER_ELEMENT;
+ type = typedArrays.getGLTypeForTypedArrayType(arrayType);
+ normalization = array.normalize !== undefined ? array.normalize : getNormalizationForTypedArrayType(arrayType);
+ numComponents = array.numComponents || array.size || guessNumComponentsFromName(arrayName, numValues);
+ buffer = gl.createBuffer();
+ gl.bindBuffer(ARRAY_BUFFER, buffer);
+ gl.bufferData(ARRAY_BUFFER, numBytes, array.drawType || STATIC_DRAW);
+ } else {
+ var typedArray = makeTypedArray(array, arrayName);
+ buffer = createBufferFromTypedArray(gl, typedArray, undefined, array.drawType);
+ type = typedArrays.getGLTypeForTypedArray(typedArray);
+ normalization = array.normalize !== undefined ? array.normalize : getNormalizationForTypedArray(typedArray);
+ numComponents = getNumComponents(array, arrayName);
+ }
+
+ attribs[attribName] = {
+ buffer: buffer,
+ numComponents: numComponents,
+ type: type,
+ normalize: normalization,
+ stride: array.stride || 0,
+ offset: array.offset || 0,
+ divisor: array.divisor === undefined ? undefined : array.divisor,
+ drawType: array.drawType
+ };
+ }
+ }
+ });
+ gl.bindBuffer(ARRAY_BUFFER, null);
+ return attribs;
+}
+/**
+ * Sets the contents of a buffer attached to an attribInfo
+ *
+ * This is helper function to dynamically update a buffer.
+ *
+ * Let's say you make a bufferInfo
+ *
+ * var arrays = {
+ * position: new Float32Array([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]),
+ * texcoord: new Float32Array([0, 0, 0, 1, 1, 0, 1, 1]),
+ * normal: new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]),
+ * indices: new Uint16Array([0, 1, 2, 1, 2, 3]),
+ * };
+ * var bufferInfo = twgl.createBufferInfoFromArrays(gl, arrays);
+ *
+ * And you want to dynamically update the positions. You could do this
+ *
+ * // assuming arrays.position has already been updated with new data.
+ * twgl.setAttribInfoBufferFromArray(gl, bufferInfo.attribs.position, arrays.position);
+ *
+ * @param {WebGLRenderingContext} gl
+ * @param {AttribInfo} attribInfo The attribInfo who's buffer contents to set. NOTE: If you have an attribute prefix
+ * the name of the attribute will include the prefix.
+ * @param {ArraySpec} array Note: it is arguably inefficient to pass in anything but a typed array because anything
+ * else will have to be converted to a typed array before it can be used by WebGL. During init time that
+ * inefficiency is usually not important but if you're updating data dynamically best to be efficient.
+ * @param {number} [offset] an optional offset into the buffer. This is only an offset into the WebGL buffer
+ * not the array. To pass in an offset into the array itself use a typed array and create an `ArrayBufferView`
+ * for the portion of the array you want to use.
+ *
+ * var someArray = new Float32Array(1000); // an array with 1000 floats
+ * var someSubArray = new Float32Array(someArray.buffer, offsetInBytes, sizeInUnits); // a view into someArray
+ *
+ * Now you can pass `someSubArray` into setAttribInfoBufferFromArray`
+ * @memberOf module:twgl/attributes
+ */
+
+
+function setAttribInfoBufferFromArray(gl, attribInfo, array, offset) {
+ array = makeTypedArray(array);
+
+ if (offset !== undefined) {
+ gl.bindBuffer(ARRAY_BUFFER, attribInfo.buffer);
+ gl.bufferSubData(ARRAY_BUFFER, offset, array);
+ } else {
+ setBufferFromTypedArray(gl, ARRAY_BUFFER, attribInfo.buffer, array, attribInfo.drawType);
+ }
+}
+
+function getBytesPerValueForGLType(gl, type) {
+ if (type === BYTE) return 1; // eslint-disable-line
+
+ if (type === UNSIGNED_BYTE) return 1; // eslint-disable-line
+
+ if (type === SHORT) return 2; // eslint-disable-line
+
+ if (type === UNSIGNED_SHORT) return 2; // eslint-disable-line
+
+ if (type === INT) return 4; // eslint-disable-line
+
+ if (type === UNSIGNED_INT) return 4; // eslint-disable-line
+
+ if (type === FLOAT) return 4; // eslint-disable-line
+
+ return 0;
+} // Tries to get the number of elements from a set of arrays.
+
+
+var positionKeys = ['position', 'positions', 'a_position'];
+
+function getNumElementsFromNonIndexedArrays(arrays) {
+ var key;
+ var ii;
+
+ for (ii = 0; ii < positionKeys.length; ++ii) {
+ key = positionKeys[ii];
+
+ if (key in arrays) {
+ break;
+ }
+ }
+
+ if (ii === positionKeys.length) {
+ key = Object.keys(arrays)[0];
+ }
+
+ var array = arrays[key];
+ var length = getArray(array).length;
+ var numComponents = getNumComponents(array, key);
+ var numElements = length / numComponents;
+
+ if (length % numComponents > 0) {
+ throw new Error("numComponents ".concat(numComponents, " not correct for length ").concat(length));
+ }
+
+ return numElements;
+}
+
+function getNumElementsFromAttributes(gl, attribs) {
+ var key;
+ var ii;
+
+ for (ii = 0; ii < positionKeys.length; ++ii) {
+ key = positionKeys[ii];
+
+ if (key in attribs) {
+ break;
+ }
+
+ key = defaults.attribPrefix + key;
+
+ if (key in attribs) {
+ break;
+ }
+ }
+
+ if (ii === positionKeys.length) {
+ key = Object.keys(attribs)[0];
+ }
+
+ var attrib = attribs[key];
+ gl.bindBuffer(ARRAY_BUFFER, attrib.buffer);
+ var numBytes = gl.getBufferParameter(ARRAY_BUFFER, BUFFER_SIZE);
+ gl.bindBuffer(ARRAY_BUFFER, null);
+ var bytesPerValue = getBytesPerValueForGLType(gl, attrib.type);
+ var totalElements = numBytes / bytesPerValue;
+ var numComponents = attrib.numComponents || attrib.size; // TODO: check stride
+
+ var numElements = totalElements / numComponents;
+
+ if (numElements % 1 !== 0) {
+ throw new Error("numComponents ".concat(numComponents, " not correct for length ").concat(length));
+ }
+
+ return numElements;
+}
+/**
+ * @typedef {Object} BufferInfo
+ * @property {number} numElements The number of elements to pass to `gl.drawArrays` or `gl.drawElements`.
+ * @property {number} [elementType] The type of indices `UNSIGNED_BYTE`, `UNSIGNED_SHORT` etc..
+ * @property {WebGLBuffer} [indices] The indices `ELEMENT_ARRAY_BUFFER` if any indices exist.
+ * @property {Object.} [attribs] The attribs appropriate to call `setAttributes`
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a BufferInfo from an object of arrays.
+ *
+ * This can be passed to {@link module:twgl.setBuffersAndAttributes} and to
+ * {@link module:twgl:drawBufferInfo}.
+ *
+ * Given an object like
+ *
+ * var arrays = {
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
+ * normal: { numComponents: 3, data: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], },
+ * indices: { numComponents: 3, data: [0, 1, 2, 1, 2, 3], },
+ * };
+ *
+ * Creates an BufferInfo like this
+ *
+ * bufferInfo = {
+ * numElements: 4, // or whatever the number of elements is
+ * indices: WebGLBuffer, // this property will not exist if there are no indices
+ * attribs: {
+ * position: { buffer: WebGLBuffer, numComponents: 3, },
+ * normal: { buffer: WebGLBuffer, numComponents: 3, },
+ * texcoord: { buffer: WebGLBuffer, numComponents: 2, },
+ * },
+ * };
+ *
+ * The properties of arrays can be JavaScript arrays in which case the number of components
+ * will be guessed.
+ *
+ * var arrays = {
+ * position: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0],
+ * texcoord: [0, 0, 0, 1, 1, 0, 1, 1],
+ * normal: [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],
+ * indices: [0, 1, 2, 1, 2, 3],
+ * };
+ *
+ * They can also be TypedArrays
+ *
+ * var arrays = {
+ * position: new Float32Array([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]),
+ * texcoord: new Float32Array([0, 0, 0, 1, 1, 0, 1, 1]),
+ * normal: new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]),
+ * indices: new Uint16Array([0, 1, 2, 1, 2, 3]),
+ * };
+ *
+ * Or AugmentedTypedArrays
+ *
+ * var positions = createAugmentedTypedArray(3, 4);
+ * var texcoords = createAugmentedTypedArray(2, 4);
+ * var normals = createAugmentedTypedArray(3, 4);
+ * var indices = createAugmentedTypedArray(3, 2, Uint16Array);
+ *
+ * positions.push([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]);
+ * texcoords.push([0, 0, 0, 1, 1, 0, 1, 1]);
+ * normals.push([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]);
+ * indices.push([0, 1, 2, 1, 2, 3]);
+ *
+ * var arrays = {
+ * position: positions,
+ * texcoord: texcoords,
+ * normal: normals,
+ * indices: indices,
+ * };
+ *
+ * For the last example it is equivalent to
+ *
+ * var bufferInfo = {
+ * attribs: {
+ * position: { numComponents: 3, buffer: gl.createBuffer(), },
+ * texcoord: { numComponents: 2, buffer: gl.createBuffer(), },
+ * normal: { numComponents: 3, buffer: gl.createBuffer(), },
+ * },
+ * indices: gl.createBuffer(),
+ * numElements: 6,
+ * };
+ *
+ * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.position.buffer);
+ * gl.bufferData(gl.ARRAY_BUFFER, arrays.position, gl.STATIC_DRAW);
+ * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.texcoord.buffer);
+ * gl.bufferData(gl.ARRAY_BUFFER, arrays.texcoord, gl.STATIC_DRAW);
+ * gl.bindBuffer(gl.ARRAY_BUFFER, bufferInfo.attribs.normal.buffer);
+ * gl.bufferData(gl.ARRAY_BUFFER, arrays.normal, gl.STATIC_DRAW);
+ * gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, bufferInfo.indices);
+ * gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, arrays.indices, gl.STATIC_DRAW);
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @param {module:twgl.Arrays} arrays Your data
+ * @param {module:twgl.BufferInfo} [srcBufferInfo] An existing
+ * buffer info to start from. WebGLBuffers etc specified
+ * in the srcBufferInfo will be used in a new BufferInfo
+ * with any arrays specified overriding the ones in
+ * srcBufferInfo.
+ * @return {module:twgl.BufferInfo} A BufferInfo
+ * @memberOf module:twgl/attributes
+ */
+
+
+function createBufferInfoFromArrays(gl, arrays, srcBufferInfo) {
+ var newAttribs = createAttribsFromArrays(gl, arrays);
+ var bufferInfo = Object.assign({}, srcBufferInfo ? srcBufferInfo : {});
+ bufferInfo.attribs = Object.assign({}, srcBufferInfo ? srcBufferInfo.attribs : {}, newAttribs);
+ var indices = arrays.indices;
+
+ if (indices) {
+ var newIndices = makeTypedArray(indices, "indices");
+ bufferInfo.indices = createBufferFromTypedArray(gl, newIndices, ELEMENT_ARRAY_BUFFER);
+ bufferInfo.numElements = newIndices.length;
+ bufferInfo.elementType = typedArrays.getGLTypeForTypedArray(newIndices);
+ } else if (!bufferInfo.numElements) {
+ bufferInfo.numElements = getNumElementsFromAttributes(gl, bufferInfo.attribs);
+ }
+
+ return bufferInfo;
+}
+/**
+ * Creates a buffer from an array, typed array, or array spec
+ *
+ * Given something like this
+ *
+ * [1, 2, 3],
+ *
+ * or
+ *
+ * new Uint16Array([1,2,3]);
+ *
+ * or
+ *
+ * {
+ * data: [1, 2, 3],
+ * type: Uint8Array,
+ * }
+ *
+ * returns a WebGLBuffer that contains the given data.
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext.
+ * @param {module:twgl.ArraySpec} array an array, typed array, or array spec.
+ * @param {string} arrayName name of array. Used to guess the type if type can not be derived otherwise.
+ * @return {WebGLBuffer} a WebGLBuffer containing the data in array.
+ * @memberOf module:twgl/attributes
+ */
+
+
+function createBufferFromArray(gl, array, arrayName) {
+ var type = arrayName === "indices" ? ELEMENT_ARRAY_BUFFER : ARRAY_BUFFER;
+ var typedArray = makeTypedArray(array, arrayName);
+ return createBufferFromTypedArray(gl, typedArray, type);
+}
+/**
+ * Creates buffers from arrays or typed arrays
+ *
+ * Given something like this
+ *
+ * var arrays = {
+ * positions: [1, 2, 3],
+ * normals: [0, 0, 1],
+ * }
+ *
+ * returns something like
+ *
+ * buffers = {
+ * positions: WebGLBuffer,
+ * normals: WebGLBuffer,
+ * }
+ *
+ * If the buffer is named 'indices' it will be made an ELEMENT_ARRAY_BUFFER.
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext.
+ * @param {module:twgl.Arrays} arrays
+ * @return {Object} returns an object with one WebGLBuffer per array
+ * @memberOf module:twgl/attributes
+ */
+
+
+function createBuffersFromArrays(gl, arrays) {
+ var buffers = {};
+ Object.keys(arrays).forEach(function (key) {
+ buffers[key] = createBufferFromArray(gl, arrays[key], key);
+ }); // Ugh!
+
+ if (arrays.indices) {
+ buffers.numElements = arrays.indices.length;
+ buffers.elementType = typedArrays.getGLTypeForTypedArray(makeTypedArray(arrays.indices), 'indices');
+ } else {
+ buffers.numElements = getNumElementsFromNonIndexedArrays(arrays);
+ }
+
+ return buffers;
+}
+
+/***/ }),
+
+/***/ "./src/draw.js":
+/*!*********************!*\
+ !*** ./src/draw.js ***!
+ \*********************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.drawBufferInfo = drawBufferInfo;
+exports.drawObjectList = drawObjectList;
+
+var programs = _interopRequireWildcard(__webpack_require__(/*! ./programs.js */ "./src/programs.js"));
+
+function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+var TRIANGLES = 0x0004;
+var UNSIGNED_SHORT = 0x1403;
+/**
+ * Drawing related functions
+ *
+ * For backward compatibility they are available at both `twgl.draw` and `twgl`
+ * itself
+ *
+ * See {@link module:twgl} for core functions
+ *
+ * @module twgl/draw
+ */
+
+/**
+ * Calls `gl.drawElements` or `gl.drawArrays`, whichever is appropriate
+ *
+ * normally you'd call `gl.drawElements` or `gl.drawArrays` yourself
+ * but calling this means if you switch from indexed data to non-indexed
+ * data you don't have to remember to update your draw call.
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @param {(module:twgl.BufferInfo|module:twgl.VertexArrayInfo)} bufferInfo A BufferInfo as returned from {@link module:twgl.createBufferInfoFromArrays} or
+ * a VertexArrayInfo as returned from {@link module:twgl.createVertexArrayInfo}
+ * @param {number} [type] eg (gl.TRIANGLES, gl.LINES, gl.POINTS, gl.TRIANGLE_STRIP, ...). Defaults to `gl.TRIANGLES`
+ * @param {number} [count] An optional count. Defaults to bufferInfo.numElements
+ * @param {number} [offset] An optional offset. Defaults to 0.
+ * @param {number} [instanceCount] An optional instanceCount. if set then `drawArraysInstanced` or `drawElementsInstanced` will be called
+ * @memberOf module:twgl/draw
+ */
+
+function drawBufferInfo(gl, bufferInfo, type, count, offset, instanceCount) {
+ type = type === undefined ? TRIANGLES : type;
+ var indices = bufferInfo.indices;
+ var elementType = bufferInfo.elementType;
+ var numElements = count === undefined ? bufferInfo.numElements : count;
+ offset = offset === undefined ? 0 : offset;
+
+ if (elementType || indices) {
+ if (instanceCount !== undefined) {
+ gl.drawElementsInstanced(type, numElements, elementType === undefined ? UNSIGNED_SHORT : bufferInfo.elementType, offset, instanceCount);
+ } else {
+ gl.drawElements(type, numElements, elementType === undefined ? UNSIGNED_SHORT : bufferInfo.elementType, offset);
+ }
+ } else {
+ if (instanceCount !== undefined) {
+ gl.drawArraysInstanced(type, offset, numElements, instanceCount);
+ } else {
+ gl.drawArrays(type, offset, numElements);
+ }
+ }
+}
+/**
+ * A DrawObject is useful for putting objects in to an array and passing them to {@link module:twgl.drawObjectList}.
+ *
+ * You need either a `BufferInfo` or a `VertexArrayInfo`.
+ *
+ * @typedef {Object} DrawObject
+ * @property {boolean} [active] whether or not to draw. Default = `true` (must be `false` to be not true). In other words `undefined` = `true`
+ * @property {number} [type] type to draw eg. `gl.TRIANGLES`, `gl.LINES`, etc...
+ * @property {module:twgl.ProgramInfo} programInfo A ProgramInfo as returned from {@link module:twgl.createProgramInfo}
+ * @property {module:twgl.BufferInfo} [bufferInfo] A BufferInfo as returned from {@link module:twgl.createBufferInfoFromArrays}
+ * @property {module:twgl.VertexArrayInfo} [vertexArrayInfo] A VertexArrayInfo as returned from {@link module:twgl.createVertexArrayInfo}
+ * @property {Object} uniforms The values for the uniforms.
+ * You can pass multiple objects by putting them in an array. For example
+ *
+ * var sharedUniforms = {
+ * u_fogNear: 10,
+ * u_projection: ...
+ * ...
+ * };
+ *
+ * var localUniforms = {
+ * u_world: ...
+ * u_diffuseColor: ...
+ * };
+ *
+ * var drawObj = {
+ * ...
+ * uniforms: [sharedUniforms, localUniforms],
+ * };
+ *
+ * @property {number} [offset] the offset to pass to `gl.drawArrays` or `gl.drawElements`. Defaults to 0.
+ * @property {number} [count] the count to pass to `gl.drawArrays` or `gl.drawElements`. Defaults to bufferInfo.numElements.
+ * @property {number} [instanceCount] the number of instances. Defaults to undefined.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Draws a list of objects
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @param {DrawObject[]} objectsToDraw an array of objects to draw.
+ * @memberOf module:twgl/draw
+ */
+
+
+function drawObjectList(gl, objectsToDraw) {
+ var lastUsedProgramInfo = null;
+ var lastUsedBufferInfo = null;
+ objectsToDraw.forEach(function (object) {
+ if (object.active === false) {
+ return;
+ }
+
+ var programInfo = object.programInfo;
+ var bufferInfo = object.vertexArrayInfo || object.bufferInfo;
+ var bindBuffers = false;
+ var type = object.type === undefined ? TRIANGLES : object.type;
+
+ if (programInfo !== lastUsedProgramInfo) {
+ lastUsedProgramInfo = programInfo;
+ gl.useProgram(programInfo.program); // We have to rebind buffers when changing programs because we
+ // only bind buffers the program uses. So if 2 programs use the same
+ // bufferInfo but the 1st one uses only positions the when the
+ // we switch to the 2nd one some of the attributes will not be on.
+
+ bindBuffers = true;
+ } // Setup all the needed attributes.
+
+
+ if (bindBuffers || bufferInfo !== lastUsedBufferInfo) {
+ if (lastUsedBufferInfo && lastUsedBufferInfo.vertexArrayObject && !bufferInfo.vertexArrayObject) {
+ gl.bindVertexArray(null);
+ }
+
+ lastUsedBufferInfo = bufferInfo;
+ programs.setBuffersAndAttributes(gl, programInfo, bufferInfo);
+ } // Set the uniforms.
+
+
+ programs.setUniforms(programInfo, object.uniforms); // Draw
+
+ drawBufferInfo(gl, bufferInfo, type, object.count, object.offset, object.instanceCount);
+ });
+
+ if (lastUsedBufferInfo && lastUsedBufferInfo.vertexArrayObject) {
+ gl.bindVertexArray(null);
+ }
+}
+
+/***/ }),
+
+/***/ "./src/framebuffers.js":
+/*!*****************************!*\
+ !*** ./src/framebuffers.js ***!
+ \*****************************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.bindFramebufferInfo = bindFramebufferInfo;
+exports.createFramebufferInfo = createFramebufferInfo;
+exports.resizeFramebufferInfo = resizeFramebufferInfo;
+
+var textures = _interopRequireWildcard(__webpack_require__(/*! ./textures.js */ "./src/textures.js"));
+
+var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
+
+function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * Framebuffer related functions
+ *
+ * For backward compatibility they are available at both `twgl.framebuffer` and `twgl`
+ * itself
+ *
+ * See {@link module:twgl} for core functions
+ *
+ * @module twgl/framebuffers
+ */
+// make sure we don't see a global gl
+var gl = undefined;
+/* eslint-disable-line */
+
+/* lgtm [js/unused-local-variable] */
+
+var FRAMEBUFFER = 0x8d40;
+var RENDERBUFFER = 0x8d41;
+var TEXTURE_2D = 0x0de1;
+var UNSIGNED_BYTE = 0x1401;
+/* PixelFormat */
+
+var DEPTH_COMPONENT = 0x1902;
+var RGBA = 0x1908;
+/* Framebuffer Object. */
+
+var RGBA4 = 0x8056;
+var RGB5_A1 = 0x8057;
+var RGB565 = 0x8D62;
+var DEPTH_COMPONENT16 = 0x81A5;
+var STENCIL_INDEX = 0x1901;
+var STENCIL_INDEX8 = 0x8D48;
+var DEPTH_STENCIL = 0x84F9;
+var COLOR_ATTACHMENT0 = 0x8CE0;
+var DEPTH_ATTACHMENT = 0x8D00;
+var STENCIL_ATTACHMENT = 0x8D20;
+var DEPTH_STENCIL_ATTACHMENT = 0x821A;
+/* TextureWrapMode */
+
+var REPEAT = 0x2901; // eslint-disable-line
+
+var CLAMP_TO_EDGE = 0x812F;
+var MIRRORED_REPEAT = 0x8370; // eslint-disable-line
+
+/* TextureMagFilter */
+
+var NEAREST = 0x2600; // eslint-disable-line
+
+var LINEAR = 0x2601;
+/* TextureMinFilter */
+
+var NEAREST_MIPMAP_NEAREST = 0x2700; // eslint-disable-line
+
+var LINEAR_MIPMAP_NEAREST = 0x2701; // eslint-disable-line
+
+var NEAREST_MIPMAP_LINEAR = 0x2702; // eslint-disable-line
+
+var LINEAR_MIPMAP_LINEAR = 0x2703; // eslint-disable-line
+
+/**
+ * The options for a framebuffer attachment.
+ *
+ * Note: For a `format` that is a texture include all the texture
+ * options from {@link module:twgl.TextureOptions} for example
+ * `min`, `mag`, `clamp`, etc... Note that unlike {@link module:twgl.TextureOptions}
+ * `auto` defaults to `false` for attachment textures but `min` and `mag` default
+ * to `gl.LINEAR` and `wrap` defaults to `CLAMP_TO_EDGE`
+ *
+ * @typedef {Object} AttachmentOptions
+ * @property {number} [attach] The attachment point. Defaults
+ * to `gl.COLOR_ATTACHMENT0 + ndx` unless type is a depth or stencil type
+ * then it's gl.DEPTH_ATTACHMENT or `gl.DEPTH_STENCIL_ATTACHMENT` depending
+ * on the format or attachment type.
+ * @property {number} [format] The format. If one of `gl.RGBA4`,
+ * `gl.RGB565`, `gl.RGB5_A1`, `gl.DEPTH_COMPONENT16`,
+ * `gl.STENCIL_INDEX8` or `gl.DEPTH_STENCIL` then will create a
+ * renderbuffer. Otherwise will create a texture. Default = `gl.RGBA`
+ * @property {number} [type] The type. Used for texture. Default = `gl.UNSIGNED_BYTE`.
+ * @property {number} [target] The texture target for `gl.framebufferTexture2D`.
+ * Defaults to `gl.TEXTURE_2D`. Set to appropriate face for cube maps.
+ * @property {number} [level] level for `gl.framebufferTexture2D`. Defaults to 0.
+ * @property {number} [layer] layer for `gl.framebufferTextureLayer`. Defaults to undefined.
+ * If set then `gl.framebufferTextureLayer` is called, if not then `gl.framebufferTexture2D`
+ * @property {WebGLObject} [attachment] An existing renderbuffer or texture.
+ * If provided will attach this Object. This allows you to share
+ * attachments across framebuffers.
+ * @memberOf module:twgl
+ * @mixes module:twgl.TextureOptions
+ */
+
+var defaultAttachments = [{
+ format: RGBA,
+ type: UNSIGNED_BYTE,
+ min: LINEAR,
+ wrap: CLAMP_TO_EDGE
+}, {
+ format: DEPTH_STENCIL
+}];
+var attachmentsByFormat = {};
+attachmentsByFormat[DEPTH_STENCIL] = DEPTH_STENCIL_ATTACHMENT;
+attachmentsByFormat[STENCIL_INDEX] = STENCIL_ATTACHMENT;
+attachmentsByFormat[STENCIL_INDEX8] = STENCIL_ATTACHMENT;
+attachmentsByFormat[DEPTH_COMPONENT] = DEPTH_ATTACHMENT;
+attachmentsByFormat[DEPTH_COMPONENT16] = DEPTH_ATTACHMENT;
+
+function getAttachmentPointForFormat(format) {
+ return attachmentsByFormat[format];
+}
+
+var renderbufferFormats = {};
+renderbufferFormats[RGBA4] = true;
+renderbufferFormats[RGB5_A1] = true;
+renderbufferFormats[RGB565] = true;
+renderbufferFormats[DEPTH_STENCIL] = true;
+renderbufferFormats[DEPTH_COMPONENT16] = true;
+renderbufferFormats[STENCIL_INDEX] = true;
+renderbufferFormats[STENCIL_INDEX8] = true;
+
+function isRenderbufferFormat(format) {
+ return renderbufferFormats[format];
+}
+/**
+ * @typedef {Object} FramebufferInfo
+ * @property {WebGLFramebuffer} framebuffer The WebGLFramebuffer for this framebufferInfo
+ * @property {WebGLObject[]} attachments The created attachments in the same order as passed in to {@link module:twgl.createFramebufferInfo}.
+ * @property {number} width The width of the framebuffer and its attachments
+ * @property {number} height The width of the framebuffer and its attachments
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a framebuffer and attachments.
+ *
+ * This returns a {@link module:twgl.FramebufferInfo} because it needs to return the attachments as well as the framebuffer.
+ *
+ * The simplest usage
+ *
+ * // create an RGBA/UNSIGNED_BYTE texture and DEPTH_STENCIL renderbuffer
+ * const fbi = twgl.createFramebufferInfo(gl);
+ *
+ * More complex usage
+ *
+ * // create an RGB565 renderbuffer and a STENCIL_INDEX8 renderbuffer
+ * const attachments = [
+ * { format: RGB565, mag: NEAREST },
+ * { format: STENCIL_INDEX8 },
+ * ]
+ * const fbi = twgl.createFramebufferInfo(gl, attachments);
+ *
+ * Passing in a specific size
+ *
+ * const width = 256;
+ * const height = 256;
+ * const fbi = twgl.createFramebufferInfo(gl, attachments, width, height);
+ *
+ * **Note!!** It is up to you to check if the framebuffer is renderable by calling `gl.checkFramebufferStatus`.
+ * [WebGL1 only guarantees 3 combinations of attachments work](https://www.khronos.org/registry/webgl/specs/latest/1.0/#6.6).
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.AttachmentOptions[]} [attachments] which attachments to create. If not provided the default is a framebuffer with an
+ * `RGBA`, `UNSIGNED_BYTE` texture `COLOR_ATTACHMENT0` and a `DEPTH_STENCIL` renderbuffer `DEPTH_STENCIL_ATTACHMENT`.
+ * @param {number} [width] the width for the attachments. Default = size of drawingBuffer
+ * @param {number} [height] the height for the attachments. Default = size of drawingBuffer
+ * @return {module:twgl.FramebufferInfo} the framebuffer and attachments.
+ * @memberOf module:twgl/framebuffers
+ */
+
+
+function createFramebufferInfo(gl, attachments, width, height) {
+ var target = FRAMEBUFFER;
+ var fb = gl.createFramebuffer();
+ gl.bindFramebuffer(target, fb);
+ width = width || gl.drawingBufferWidth;
+ height = height || gl.drawingBufferHeight;
+ attachments = attachments || defaultAttachments;
+ var colorAttachmentCount = 0;
+ var framebufferInfo = {
+ framebuffer: fb,
+ attachments: [],
+ width: width,
+ height: height
+ };
+ attachments.forEach(function (attachmentOptions) {
+ var attachment = attachmentOptions.attachment;
+ var format = attachmentOptions.format;
+ var attachmentPoint = getAttachmentPointForFormat(format);
+
+ if (!attachmentPoint) {
+ attachmentPoint = COLOR_ATTACHMENT0 + colorAttachmentCount++;
+ }
+
+ if (!attachment) {
+ if (isRenderbufferFormat(format)) {
+ attachment = gl.createRenderbuffer();
+ gl.bindRenderbuffer(RENDERBUFFER, attachment);
+ gl.renderbufferStorage(RENDERBUFFER, format, width, height);
+ } else {
+ var textureOptions = Object.assign({}, attachmentOptions);
+ textureOptions.width = width;
+ textureOptions.height = height;
+
+ if (textureOptions.auto === undefined) {
+ textureOptions.auto = false;
+ textureOptions.min = textureOptions.min || textureOptions.minMag || LINEAR;
+ textureOptions.mag = textureOptions.mag || textureOptions.minMag || LINEAR;
+ textureOptions.wrapS = textureOptions.wrapS || textureOptions.wrap || CLAMP_TO_EDGE;
+ textureOptions.wrapT = textureOptions.wrapT || textureOptions.wrap || CLAMP_TO_EDGE;
+ }
+
+ attachment = textures.createTexture(gl, textureOptions);
+ }
+ }
+
+ if (helper.isRenderbuffer(gl, attachment)) {
+ gl.framebufferRenderbuffer(target, attachmentPoint, RENDERBUFFER, attachment);
+ } else if (helper.isTexture(gl, attachment)) {
+ if (attachmentOptions.layer !== undefined) {
+ gl.framebufferTextureLayer(target, attachmentPoint, attachment, attachmentOptions.level || 0, attachmentOptions.layer);
+ } else {
+ gl.framebufferTexture2D(target, attachmentPoint, attachmentOptions.texTarget || TEXTURE_2D, attachment, attachmentOptions.level || 0);
+ }
+ } else {
+ throw new Error('unknown attachment type');
+ }
+
+ framebufferInfo.attachments.push(attachment);
+ });
+ return framebufferInfo;
+}
+/**
+ * Resizes the attachments of a framebuffer.
+ *
+ * You need to pass in the same `attachments` as you passed in {@link module:twgl.createFramebufferInfo}
+ * because TWGL has no idea the format/type of each attachment.
+ *
+ * The simplest usage
+ *
+ * // create an RGBA/UNSIGNED_BYTE texture and DEPTH_STENCIL renderbuffer
+ * const fbi = twgl.createFramebufferInfo(gl);
+ *
+ * ...
+ *
+ * function render() {
+ * if (twgl.resizeCanvasToDisplaySize(gl.canvas)) {
+ * // resize the attachments
+ * twgl.resizeFramebufferInfo(gl, fbi);
+ * }
+ *
+ * More complex usage
+ *
+ * // create an RGB565 renderbuffer and a STENCIL_INDEX8 renderbuffer
+ * const attachments = [
+ * { format: RGB565, mag: NEAREST },
+ * { format: STENCIL_INDEX8 },
+ * ]
+ * const fbi = twgl.createFramebufferInfo(gl, attachments);
+ *
+ * ...
+ *
+ * function render() {
+ * if (twgl.resizeCanvasToDisplaySize(gl.canvas)) {
+ * // resize the attachments to match
+ * twgl.resizeFramebufferInfo(gl, fbi, attachments);
+ * }
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.FramebufferInfo} framebufferInfo a framebufferInfo as returned from {@link module:twgl.createFramebufferInfo}.
+ * @param {module:twgl.AttachmentOptions[]} [attachments] the same attachments options as passed to {@link module:twgl.createFramebufferInfo}.
+ * @param {number} [width] the width for the attachments. Default = size of drawingBuffer
+ * @param {number} [height] the height for the attachments. Default = size of drawingBuffer
+ * @memberOf module:twgl/framebuffers
+ */
+
+
+function resizeFramebufferInfo(gl, framebufferInfo, attachments, width, height) {
+ width = width || gl.drawingBufferWidth;
+ height = height || gl.drawingBufferHeight;
+ framebufferInfo.width = width;
+ framebufferInfo.height = height;
+ attachments = attachments || defaultAttachments;
+ attachments.forEach(function (attachmentOptions, ndx) {
+ var attachment = framebufferInfo.attachments[ndx];
+ var format = attachmentOptions.format;
+
+ if (helper.isRenderbuffer(gl, attachment)) {
+ gl.bindRenderbuffer(RENDERBUFFER, attachment);
+ gl.renderbufferStorage(RENDERBUFFER, format, width, height);
+ } else if (helper.isTexture(gl, attachment)) {
+ textures.resizeTexture(gl, attachment, attachmentOptions, width, height);
+ } else {
+ throw new Error('unknown attachment type');
+ }
+ });
+}
+/**
+ * Binds a framebuffer
+ *
+ * This function pretty much solely exists because I spent hours
+ * trying to figure out why something I wrote wasn't working only
+ * to realize I forget to set the viewport dimensions.
+ * My hope is this function will fix that.
+ *
+ * It is effectively the same as
+ *
+ * gl.bindFramebuffer(gl.FRAMEBUFFER, someFramebufferInfo.framebuffer);
+ * gl.viewport(0, 0, someFramebufferInfo.width, someFramebufferInfo.height);
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.FramebufferInfo|null} [framebufferInfo] a framebufferInfo as returned from {@link module:twgl.createFramebufferInfo}.
+ * If falsy will bind the canvas.
+ * @param {number} [target] The target. If not passed `gl.FRAMEBUFFER` will be used.
+ * @memberOf module:twgl/framebuffers
+ */
+
+
+function bindFramebufferInfo(gl, framebufferInfo, target) {
+ target = target || FRAMEBUFFER;
+
+ if (framebufferInfo) {
+ gl.bindFramebuffer(target, framebufferInfo.framebuffer);
+ gl.viewport(0, 0, framebufferInfo.width, framebufferInfo.height);
+ } else {
+ gl.bindFramebuffer(target, null);
+ gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
+ }
+}
+
+/***/ }),
+
+/***/ "./src/helper.js":
+/*!***********************!*\
+ !*** ./src/helper.js ***!
+ \***********************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.copyExistingProperties = copyExistingProperties;
+exports.copyNamedProperties = copyNamedProperties;
+exports.error = error;
+exports.warn = warn;
+exports.isBuffer = isBuffer;
+exports.isRenderbuffer = isRenderbuffer;
+exports.isShader = isShader;
+exports.isTexture = isTexture;
+exports.isSampler = isSampler;
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/* eslint no-console: "off" */
+
+/**
+ * Copy named properties
+ *
+ * @param {string[]} names names of properties to copy
+ * @param {object} src object to copy properties from
+ * @param {object} dst object to copy properties to
+ * @private
+ */
+function copyNamedProperties(names, src, dst) {
+ names.forEach(function (name) {
+ var value = src[name];
+
+ if (value !== undefined) {
+ dst[name] = value;
+ }
+ });
+}
+/**
+ * Copies properties from source to dest only if a matching key is in dest
+ *
+ * @param {Object.} src the source
+ * @param {Object.} dst the dest
+ * @private
+ */
+
+
+function copyExistingProperties(src, dst) {
+ Object.keys(dst).forEach(function (key) {
+ if (dst.hasOwnProperty(key) && src.hasOwnProperty(key)) {
+ /* eslint no-prototype-builtins: 0 */
+ dst[key] = src[key];
+ }
+ });
+}
+
+function error() {
+ var _console;
+
+ (_console = console).error.apply(_console, arguments);
+}
+
+function warn() {
+ var _console2;
+
+ (_console2 = console).warn.apply(_console2, arguments);
+}
+
+function isBuffer(gl, t) {
+ return typeof WebGLBuffer !== 'undefined' && t instanceof WebGLBuffer;
+}
+
+function isRenderbuffer(gl, t) {
+ return typeof WebGLRenderbuffer !== 'undefined' && t instanceof WebGLRenderbuffer;
+}
+
+function isShader(gl, t) {
+ return typeof WebGLShader !== 'undefined' && t instanceof WebGLShader;
+}
+
+function isTexture(gl, t) {
+ return typeof WebGLTexture !== 'undefined' && t instanceof WebGLTexture;
+}
+
+function isSampler(gl, t) {
+ return typeof WebGLSampler !== 'undefined' && t instanceof WebGLSampler;
+}
+
+/***/ }),
+
+/***/ "./src/programs.js":
+/*!*************************!*\
+ !*** ./src/programs.js ***!
+ \*************************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.createAttributeSetters = createAttributeSetters;
+exports.createProgram = createProgram;
+exports.createProgramFromScripts = createProgramFromScripts;
+exports.createProgramFromSources = createProgramFromSources;
+exports.createProgramInfo = createProgramInfo;
+exports.createProgramInfoFromProgram = createProgramInfoFromProgram;
+exports.createUniformSetters = createUniformSetters;
+exports.createUniformBlockSpecFromProgram = createUniformBlockSpecFromProgram;
+exports.createUniformBlockInfoFromProgram = createUniformBlockInfoFromProgram;
+exports.createUniformBlockInfo = createUniformBlockInfo;
+exports.createTransformFeedback = createTransformFeedback;
+exports.createTransformFeedbackInfo = createTransformFeedbackInfo;
+exports.bindTransformFeedbackInfo = bindTransformFeedbackInfo;
+exports.setAttributes = setAttributes;
+exports.setBuffersAndAttributes = setBuffersAndAttributes;
+exports.setUniforms = setUniforms;
+exports.setUniformBlock = setUniformBlock;
+exports.setBlockUniforms = setBlockUniforms;
+exports.bindUniformBlock = bindUniformBlock;
+exports.setUniformsAndBindTextures = void 0;
+
+var utils = _interopRequireWildcard(__webpack_require__(/*! ./utils.js */ "./src/utils.js"));
+
+var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
+
+function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * Low level shader program related functions
+ *
+ * You should generally not need to use these functions. They are provided
+ * for those cases where you're doing something out of the ordinary
+ * and you need lower level access.
+ *
+ * For backward compatibility they are available at both `twgl.programs` and `twgl`
+ * itself
+ *
+ * See {@link module:twgl} for core functions
+ *
+ * @module twgl/programs
+ */
+var error = helper.error;
+var warn = helper.warn;
+
+function getElementById(id) {
+ return typeof document !== 'undefined' && document.getElementById ? document.getElementById(id) : null;
+}
+
+var TEXTURE0 = 0x84c0;
+var DYNAMIC_DRAW = 0x88e8;
+var ARRAY_BUFFER = 0x8892;
+var ELEMENT_ARRAY_BUFFER = 0x8893;
+var UNIFORM_BUFFER = 0x8a11;
+var TRANSFORM_FEEDBACK_BUFFER = 0x8c8e;
+var TRANSFORM_FEEDBACK = 0x8e22;
+var COMPILE_STATUS = 0x8b81;
+var LINK_STATUS = 0x8b82;
+var FRAGMENT_SHADER = 0x8b30;
+var VERTEX_SHADER = 0x8b31;
+var SEPARATE_ATTRIBS = 0x8c8d;
+var ACTIVE_UNIFORMS = 0x8b86;
+var ACTIVE_ATTRIBUTES = 0x8b89;
+var TRANSFORM_FEEDBACK_VARYINGS = 0x8c83;
+var ACTIVE_UNIFORM_BLOCKS = 0x8a36;
+var UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER = 0x8a44;
+var UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER = 0x8a46;
+var UNIFORM_BLOCK_DATA_SIZE = 0x8a40;
+var UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES = 0x8a43;
+var FLOAT = 0x1406;
+var FLOAT_VEC2 = 0x8B50;
+var FLOAT_VEC3 = 0x8B51;
+var FLOAT_VEC4 = 0x8B52;
+var INT = 0x1404;
+var INT_VEC2 = 0x8B53;
+var INT_VEC3 = 0x8B54;
+var INT_VEC4 = 0x8B55;
+var BOOL = 0x8B56;
+var BOOL_VEC2 = 0x8B57;
+var BOOL_VEC3 = 0x8B58;
+var BOOL_VEC4 = 0x8B59;
+var FLOAT_MAT2 = 0x8B5A;
+var FLOAT_MAT3 = 0x8B5B;
+var FLOAT_MAT4 = 0x8B5C;
+var SAMPLER_2D = 0x8B5E;
+var SAMPLER_CUBE = 0x8B60;
+var SAMPLER_3D = 0x8B5F;
+var SAMPLER_2D_SHADOW = 0x8B62;
+var FLOAT_MAT2x3 = 0x8B65;
+var FLOAT_MAT2x4 = 0x8B66;
+var FLOAT_MAT3x2 = 0x8B67;
+var FLOAT_MAT3x4 = 0x8B68;
+var FLOAT_MAT4x2 = 0x8B69;
+var FLOAT_MAT4x3 = 0x8B6A;
+var SAMPLER_2D_ARRAY = 0x8DC1;
+var SAMPLER_2D_ARRAY_SHADOW = 0x8DC4;
+var SAMPLER_CUBE_SHADOW = 0x8DC5;
+var UNSIGNED_INT = 0x1405;
+var UNSIGNED_INT_VEC2 = 0x8DC6;
+var UNSIGNED_INT_VEC3 = 0x8DC7;
+var UNSIGNED_INT_VEC4 = 0x8DC8;
+var INT_SAMPLER_2D = 0x8DCA;
+var INT_SAMPLER_3D = 0x8DCB;
+var INT_SAMPLER_CUBE = 0x8DCC;
+var INT_SAMPLER_2D_ARRAY = 0x8DCF;
+var UNSIGNED_INT_SAMPLER_2D = 0x8DD2;
+var UNSIGNED_INT_SAMPLER_3D = 0x8DD3;
+var UNSIGNED_INT_SAMPLER_CUBE = 0x8DD4;
+var UNSIGNED_INT_SAMPLER_2D_ARRAY = 0x8DD7;
+var TEXTURE_2D = 0x0DE1;
+var TEXTURE_CUBE_MAP = 0x8513;
+var TEXTURE_3D = 0x806F;
+var TEXTURE_2D_ARRAY = 0x8C1A;
+var typeMap = {};
+/**
+ * Returns the corresponding bind point for a given sampler type
+ */
+
+function getBindPointForSamplerType(gl, type) {
+ return typeMap[type].bindPoint;
+} // This kind of sucks! If you could compose functions as in `var fn = gl[name];`
+// this code could be a lot smaller but that is sadly really slow (T_T)
+
+
+function floatSetter(gl, location) {
+ return function (v) {
+ gl.uniform1f(location, v);
+ };
+}
+
+function floatArraySetter(gl, location) {
+ return function (v) {
+ gl.uniform1fv(location, v);
+ };
+}
+
+function floatVec2Setter(gl, location) {
+ return function (v) {
+ gl.uniform2fv(location, v);
+ };
+}
+
+function floatVec3Setter(gl, location) {
+ return function (v) {
+ gl.uniform3fv(location, v);
+ };
+}
+
+function floatVec4Setter(gl, location) {
+ return function (v) {
+ gl.uniform4fv(location, v);
+ };
+}
+
+function intSetter(gl, location) {
+ return function (v) {
+ gl.uniform1i(location, v);
+ };
+}
+
+function intArraySetter(gl, location) {
+ return function (v) {
+ gl.uniform1iv(location, v);
+ };
+}
+
+function intVec2Setter(gl, location) {
+ return function (v) {
+ gl.uniform2iv(location, v);
+ };
+}
+
+function intVec3Setter(gl, location) {
+ return function (v) {
+ gl.uniform3iv(location, v);
+ };
+}
+
+function intVec4Setter(gl, location) {
+ return function (v) {
+ gl.uniform4iv(location, v);
+ };
+}
+
+function uintSetter(gl, location) {
+ return function (v) {
+ gl.uniform1ui(location, v);
+ };
+}
+
+function uintArraySetter(gl, location) {
+ return function (v) {
+ gl.uniform1uiv(location, v);
+ };
+}
+
+function uintVec2Setter(gl, location) {
+ return function (v) {
+ gl.uniform2uiv(location, v);
+ };
+}
+
+function uintVec3Setter(gl, location) {
+ return function (v) {
+ gl.uniform3uiv(location, v);
+ };
+}
+
+function uintVec4Setter(gl, location) {
+ return function (v) {
+ gl.uniform4uiv(location, v);
+ };
+}
+
+function floatMat2Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix2fv(location, false, v);
+ };
+}
+
+function floatMat3Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix3fv(location, false, v);
+ };
+}
+
+function floatMat4Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix4fv(location, false, v);
+ };
+}
+
+function floatMat23Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix2x3fv(location, false, v);
+ };
+}
+
+function floatMat32Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix3x2fv(location, false, v);
+ };
+}
+
+function floatMat24Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix2x4fv(location, false, v);
+ };
+}
+
+function floatMat42Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix4x2fv(location, false, v);
+ };
+}
+
+function floatMat34Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix3x4fv(location, false, v);
+ };
+}
+
+function floatMat43Setter(gl, location) {
+ return function (v) {
+ gl.uniformMatrix4x3fv(location, false, v);
+ };
+}
+
+function samplerSetter(gl, type, unit, location) {
+ var bindPoint = getBindPointForSamplerType(gl, type);
+ return utils.isWebGL2(gl) ? function (textureOrPair) {
+ var texture;
+ var sampler;
+
+ if (helper.isTexture(gl, textureOrPair)) {
+ texture = textureOrPair;
+ sampler = null;
+ } else {
+ texture = textureOrPair.texture;
+ sampler = textureOrPair.sampler;
+ }
+
+ gl.uniform1i(location, unit);
+ gl.activeTexture(TEXTURE0 + unit);
+ gl.bindTexture(bindPoint, texture);
+ gl.bindSampler(unit, sampler);
+ } : function (texture) {
+ gl.uniform1i(location, unit);
+ gl.activeTexture(TEXTURE0 + unit);
+ gl.bindTexture(bindPoint, texture);
+ };
+}
+
+function samplerArraySetter(gl, type, unit, location, size) {
+ var bindPoint = getBindPointForSamplerType(gl, type);
+ var units = new Int32Array(size);
+
+ for (var ii = 0; ii < size; ++ii) {
+ units[ii] = unit + ii;
+ }
+
+ return utils.isWebGL2(gl) ? function (textures) {
+ gl.uniform1iv(location, units);
+ textures.forEach(function (textureOrPair, index) {
+ gl.activeTexture(TEXTURE0 + units[index]);
+ var texture;
+ var sampler;
+
+ if (helper.isTexture(gl, textureOrPair)) {
+ texture = textureOrPair;
+ sampler = null;
+ } else {
+ texture = textureOrPair.texture;
+ sampler = textureOrPair.sampler;
+ }
+
+ gl.bindSampler(unit, sampler);
+ gl.bindTexture(bindPoint, texture);
+ });
+ } : function (textures) {
+ gl.uniform1iv(location, units);
+ textures.forEach(function (texture, index) {
+ gl.activeTexture(TEXTURE0 + units[index]);
+ gl.bindTexture(bindPoint, texture);
+ });
+ };
+}
+
+typeMap[FLOAT] = {
+ Type: Float32Array,
+ size: 4,
+ setter: floatSetter,
+ arraySetter: floatArraySetter
+};
+typeMap[FLOAT_VEC2] = {
+ Type: Float32Array,
+ size: 8,
+ setter: floatVec2Setter
+};
+typeMap[FLOAT_VEC3] = {
+ Type: Float32Array,
+ size: 12,
+ setter: floatVec3Setter
+};
+typeMap[FLOAT_VEC4] = {
+ Type: Float32Array,
+ size: 16,
+ setter: floatVec4Setter
+};
+typeMap[INT] = {
+ Type: Int32Array,
+ size: 4,
+ setter: intSetter,
+ arraySetter: intArraySetter
+};
+typeMap[INT_VEC2] = {
+ Type: Int32Array,
+ size: 8,
+ setter: intVec2Setter
+};
+typeMap[INT_VEC3] = {
+ Type: Int32Array,
+ size: 12,
+ setter: intVec3Setter
+};
+typeMap[INT_VEC4] = {
+ Type: Int32Array,
+ size: 16,
+ setter: intVec4Setter
+};
+typeMap[UNSIGNED_INT] = {
+ Type: Uint32Array,
+ size: 4,
+ setter: uintSetter,
+ arraySetter: uintArraySetter
+};
+typeMap[UNSIGNED_INT_VEC2] = {
+ Type: Uint32Array,
+ size: 8,
+ setter: uintVec2Setter
+};
+typeMap[UNSIGNED_INT_VEC3] = {
+ Type: Uint32Array,
+ size: 12,
+ setter: uintVec3Setter
+};
+typeMap[UNSIGNED_INT_VEC4] = {
+ Type: Uint32Array,
+ size: 16,
+ setter: uintVec4Setter
+};
+typeMap[BOOL] = {
+ Type: Uint32Array,
+ size: 4,
+ setter: intSetter,
+ arraySetter: intArraySetter
+};
+typeMap[BOOL_VEC2] = {
+ Type: Uint32Array,
+ size: 8,
+ setter: intVec2Setter
+};
+typeMap[BOOL_VEC3] = {
+ Type: Uint32Array,
+ size: 12,
+ setter: intVec3Setter
+};
+typeMap[BOOL_VEC4] = {
+ Type: Uint32Array,
+ size: 16,
+ setter: intVec4Setter
+};
+typeMap[FLOAT_MAT2] = {
+ Type: Float32Array,
+ size: 16,
+ setter: floatMat2Setter
+};
+typeMap[FLOAT_MAT3] = {
+ Type: Float32Array,
+ size: 36,
+ setter: floatMat3Setter
+};
+typeMap[FLOAT_MAT4] = {
+ Type: Float32Array,
+ size: 64,
+ setter: floatMat4Setter
+};
+typeMap[FLOAT_MAT2x3] = {
+ Type: Float32Array,
+ size: 24,
+ setter: floatMat23Setter
+};
+typeMap[FLOAT_MAT2x4] = {
+ Type: Float32Array,
+ size: 32,
+ setter: floatMat24Setter
+};
+typeMap[FLOAT_MAT3x2] = {
+ Type: Float32Array,
+ size: 24,
+ setter: floatMat32Setter
+};
+typeMap[FLOAT_MAT3x4] = {
+ Type: Float32Array,
+ size: 48,
+ setter: floatMat34Setter
+};
+typeMap[FLOAT_MAT4x2] = {
+ Type: Float32Array,
+ size: 32,
+ setter: floatMat42Setter
+};
+typeMap[FLOAT_MAT4x3] = {
+ Type: Float32Array,
+ size: 48,
+ setter: floatMat43Setter
+};
+typeMap[SAMPLER_2D] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_2D
+};
+typeMap[SAMPLER_CUBE] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_CUBE_MAP
+};
+typeMap[SAMPLER_3D] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_3D
+};
+typeMap[SAMPLER_2D_SHADOW] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_2D
+};
+typeMap[SAMPLER_2D_ARRAY] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_2D_ARRAY
+};
+typeMap[SAMPLER_2D_ARRAY_SHADOW] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_2D_ARRAY
+};
+typeMap[SAMPLER_CUBE_SHADOW] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_CUBE_MAP
+};
+typeMap[INT_SAMPLER_2D] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_2D
+};
+typeMap[INT_SAMPLER_3D] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_3D
+};
+typeMap[INT_SAMPLER_CUBE] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_CUBE_MAP
+};
+typeMap[INT_SAMPLER_2D_ARRAY] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_2D_ARRAY
+};
+typeMap[UNSIGNED_INT_SAMPLER_2D] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_2D
+};
+typeMap[UNSIGNED_INT_SAMPLER_3D] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_3D
+};
+typeMap[UNSIGNED_INT_SAMPLER_CUBE] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_CUBE_MAP
+};
+typeMap[UNSIGNED_INT_SAMPLER_2D_ARRAY] = {
+ Type: null,
+ size: 0,
+ setter: samplerSetter,
+ arraySetter: samplerArraySetter,
+ bindPoint: TEXTURE_2D_ARRAY
+};
+
+function floatAttribSetter(gl, index) {
+ return function (b) {
+ if (b.value) {
+ gl.disableVertexAttribArray(index);
+
+ switch (b.value.length) {
+ case 4:
+ gl.vertexAttrib4fv(index, b.value);
+ break;
+
+ case 3:
+ gl.vertexAttrib3fv(index, b.value);
+ break;
+
+ case 2:
+ gl.vertexAttrib2fv(index, b.value);
+ break;
+
+ case 1:
+ gl.vertexAttrib1fv(index, b.value);
+ break;
+
+ default:
+ throw new Error('the length of a float constant value must be between 1 and 4!');
+ }
+ } else {
+ gl.bindBuffer(ARRAY_BUFFER, b.buffer);
+ gl.enableVertexAttribArray(index);
+ gl.vertexAttribPointer(index, b.numComponents || b.size, b.type || FLOAT, b.normalize || false, b.stride || 0, b.offset || 0);
+
+ if (b.divisor !== undefined) {
+ gl.vertexAttribDivisor(index, b.divisor);
+ }
+ }
+ };
+}
+
+function intAttribSetter(gl, index) {
+ return function (b) {
+ if (b.value) {
+ gl.disableVertexAttribArray(index);
+
+ if (b.value.length === 4) {
+ gl.vertexAttrib4iv(index, b.value);
+ } else {
+ throw new Error('The length of an integer constant value must be 4!');
+ }
+ } else {
+ gl.bindBuffer(ARRAY_BUFFER, b.buffer);
+ gl.enableVertexAttribArray(index);
+ gl.vertexAttribIPointer(index, b.numComponents || b.size, b.type || INT, b.stride || 0, b.offset || 0);
+
+ if (b.divisor !== undefined) {
+ gl.vertexAttribDivisor(index, b.divisor);
+ }
+ }
+ };
+}
+
+function uintAttribSetter(gl, index) {
+ return function (b) {
+ if (b.value) {
+ gl.disableVertexAttribArray(index);
+
+ if (b.value.length === 4) {
+ gl.vertexAttrib4uiv(index, b.value);
+ } else {
+ throw new Error('The length of an unsigned integer constant value must be 4!');
+ }
+ } else {
+ gl.bindBuffer(ARRAY_BUFFER, b.buffer);
+ gl.enableVertexAttribArray(index);
+ gl.vertexAttribIPointer(index, b.numComponents || b.size, b.type || UNSIGNED_INT, b.stride || 0, b.offset || 0);
+
+ if (b.divisor !== undefined) {
+ gl.vertexAttribDivisor(index, b.divisor);
+ }
+ }
+ };
+}
+
+function matAttribSetter(gl, index, typeInfo) {
+ var defaultSize = typeInfo.size;
+ var count = typeInfo.count;
+ return function (b) {
+ gl.bindBuffer(ARRAY_BUFFER, b.buffer);
+ var numComponents = b.size || b.numComponents || defaultSize;
+ var size = numComponents / count;
+ var type = b.type || FLOAT;
+ var typeInfo = typeMap[type];
+ var stride = typeInfo.size * numComponents;
+ var normalize = b.normalize || false;
+ var offset = b.offset || 0;
+ var rowOffset = stride / count;
+
+ for (var i = 0; i < count; ++i) {
+ gl.enableVertexAttribArray(index + i);
+ gl.vertexAttribPointer(index + i, size, type, normalize, stride, offset + rowOffset * i);
+
+ if (b.divisor !== undefined) {
+ gl.vertexAttribDivisor(index + i, b.divisor);
+ }
+ }
+ };
+}
+
+var attrTypeMap = {};
+attrTypeMap[FLOAT] = {
+ size: 4,
+ setter: floatAttribSetter
+};
+attrTypeMap[FLOAT_VEC2] = {
+ size: 8,
+ setter: floatAttribSetter
+};
+attrTypeMap[FLOAT_VEC3] = {
+ size: 12,
+ setter: floatAttribSetter
+};
+attrTypeMap[FLOAT_VEC4] = {
+ size: 16,
+ setter: floatAttribSetter
+};
+attrTypeMap[INT] = {
+ size: 4,
+ setter: intAttribSetter
+};
+attrTypeMap[INT_VEC2] = {
+ size: 8,
+ setter: intAttribSetter
+};
+attrTypeMap[INT_VEC3] = {
+ size: 12,
+ setter: intAttribSetter
+};
+attrTypeMap[INT_VEC4] = {
+ size: 16,
+ setter: intAttribSetter
+};
+attrTypeMap[UNSIGNED_INT] = {
+ size: 4,
+ setter: uintAttribSetter
+};
+attrTypeMap[UNSIGNED_INT_VEC2] = {
+ size: 8,
+ setter: uintAttribSetter
+};
+attrTypeMap[UNSIGNED_INT_VEC3] = {
+ size: 12,
+ setter: uintAttribSetter
+};
+attrTypeMap[UNSIGNED_INT_VEC4] = {
+ size: 16,
+ setter: uintAttribSetter
+};
+attrTypeMap[BOOL] = {
+ size: 4,
+ setter: intAttribSetter
+};
+attrTypeMap[BOOL_VEC2] = {
+ size: 8,
+ setter: intAttribSetter
+};
+attrTypeMap[BOOL_VEC3] = {
+ size: 12,
+ setter: intAttribSetter
+};
+attrTypeMap[BOOL_VEC4] = {
+ size: 16,
+ setter: intAttribSetter
+};
+attrTypeMap[FLOAT_MAT2] = {
+ size: 4,
+ setter: matAttribSetter,
+ count: 2
+};
+attrTypeMap[FLOAT_MAT3] = {
+ size: 9,
+ setter: matAttribSetter,
+ count: 3
+};
+attrTypeMap[FLOAT_MAT4] = {
+ size: 16,
+ setter: matAttribSetter,
+ count: 4
+}; // make sure we don't see a global gl
+
+var gl = undefined;
+/* eslint-disable-line */
+
+/* lgtm [js/unused-local-variable] */
+
+/**
+ * Error Callback
+ * @callback ErrorCallback
+ * @param {string} msg error message.
+ * @param {number} [lineOffset] amount to add to line number
+ * @memberOf module:twgl
+ */
+
+function addLineNumbers(src, lineOffset) {
+ lineOffset = lineOffset || 0;
+ ++lineOffset;
+ return src.split("\n").map(function (line, ndx) {
+ return ndx + lineOffset + ": " + line;
+ }).join("\n");
+}
+
+var spaceRE = /^[ \t]*\n/;
+/**
+ * Loads a shader.
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {string} shaderSource The shader source.
+ * @param {number} shaderType The type of shader.
+ * @param {module:twgl.ErrorCallback} opt_errorCallback callback for errors.
+ * @return {WebGLShader} The created shader.
+ * @private
+ */
+
+function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
+ var errFn = opt_errorCallback || error; // Create the shader object
+
+ var shader = gl.createShader(shaderType); // Remove the first end of line because WebGL 2.0 requires
+ // #version 300 es
+ // as the first line. No whitespace allowed before that line
+ // so
+ //
+ //
+ //
+ // Has one line before it which is invalid according to GLSL ES 3.00
+ //
+
+ var lineOffset = 0;
+
+ if (spaceRE.test(shaderSource)) {
+ lineOffset = 1;
+ shaderSource = shaderSource.replace(spaceRE, '');
+ } // Load the shader source
+
+
+ gl.shaderSource(shader, shaderSource); // Compile the shader
+
+ gl.compileShader(shader); // Check the compile status
+
+ var compiled = gl.getShaderParameter(shader, COMPILE_STATUS);
+
+ if (!compiled) {
+ // Something went wrong during compilation; get the error
+ var lastError = gl.getShaderInfoLog(shader);
+ errFn(addLineNumbers(shaderSource, lineOffset) + "\n*** Error compiling shader: " + lastError);
+ gl.deleteShader(shader);
+ return null;
+ }
+
+ return shader;
+}
+/**
+ * @typedef {Object} ProgramOptions
+ * @property {function(string)} [errorCallback] callback for errors
+ * @property {Object.} [attribLocations] a attribute name to location map
+ * @property {(module:twgl.BufferInfo|Object.|string[])} [transformFeedbackVaryings] If passed
+ * a BufferInfo will use the attribs names inside. If passed an object of AttribInfos will use the names from that object. Otherwise
+ * you can pass an array of names.
+ * @property {number} [transformFeedbackMode] the mode to pass `gl.transformFeedbackVaryings`. Defaults to `SEPARATE_ATTRIBS`.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Gets the program options based on all these optional arguments
+ * @param {module:twgl.ProgramOptions|string[]} [opt_attribs] Options for the program or an array of attribs names. Locations will be assigned by index if not passed in
+ * @param {number[]} [opt_locations] The locations for the. A parallel array to opt_attribs letting you assign locations.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
+ * on error. If you want something else pass an callback. It's passed an error message.
+ * @return {module:twgl.ProgramOptions} an instance of ProgramOptions based on the arguments passed in
+ * @private
+ */
+
+
+function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
+ var transformFeedbackVaryings;
+ var transformFeedbackMode;
+
+ if (typeof opt_locations === 'function') {
+ opt_errorCallback = opt_locations;
+ opt_locations = undefined;
+ }
+
+ if (typeof opt_attribs === 'function') {
+ opt_errorCallback = opt_attribs;
+ opt_attribs = undefined;
+ } else if (opt_attribs && !Array.isArray(opt_attribs)) {
+ // If we have an errorCallback we can just return this object
+ // Otherwise we need to construct one with default errorCallback
+ if (opt_attribs.errorCallback) {
+ return opt_attribs;
+ }
+
+ var opt = opt_attribs;
+ opt_errorCallback = opt.errorCallback;
+ opt_attribs = opt.attribLocations;
+ transformFeedbackVaryings = opt.transformFeedbackVaryings;
+ transformFeedbackMode = opt.transformFeedbackMode;
+ }
+
+ var options = {
+ errorCallback: opt_errorCallback || error,
+ transformFeedbackVaryings: transformFeedbackVaryings,
+ transformFeedbackMode: transformFeedbackMode
+ };
+
+ if (opt_attribs) {
+ var attribLocations = {};
+
+ if (Array.isArray(opt_attribs)) {
+ opt_attribs.forEach(function (attrib, ndx) {
+ attribLocations[attrib] = opt_locations ? opt_locations[ndx] : ndx;
+ });
+ } else {
+ attribLocations = opt_attribs;
+ }
+
+ options.attribLocations = attribLocations;
+ }
+
+ return options;
+}
+
+var defaultShaderType = ["VERTEX_SHADER", "FRAGMENT_SHADER"];
+
+function getShaderTypeFromScriptType(gl, scriptType) {
+ if (scriptType.indexOf("frag") >= 0) {
+ return FRAGMENT_SHADER;
+ } else if (scriptType.indexOf("vert") >= 0) {
+ return VERTEX_SHADER;
+ }
+
+ return undefined;
+}
+
+function deleteShaders(gl, shaders) {
+ shaders.forEach(function (shader) {
+ gl.deleteShader(shader);
+ });
+}
+/**
+ * Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
+ * program and calls useProgram.
+ *
+ * NOTE: There are 4 signatures for this function
+ *
+ * twgl.createProgram(gl, [vs, fs], options);
+ * twgl.createProgram(gl, [vs, fs], opt_errFunc);
+ * twgl.createProgram(gl, [vs, fs], opt_attribs, opt_errFunc);
+ * twgl.createProgram(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {WebGLShader[]|string[]} shaders The shaders to attach, or element ids for their source, or strings that contain their source
+ * @param {module:twgl.ProgramOptions|string[]|module:twgl.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
+ * @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
+ * on error. If you want something else pass an callback. It's passed an error message.
+ * @return {WebGLProgram?} the created program or null if error.
+ * @memberOf module:twgl/programs
+ */
+
+
+function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallback) {
+ var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
+ var realShaders = [];
+ var newShaders = [];
+
+ for (var ndx = 0; ndx < shaders.length; ++ndx) {
+ var shader = shaders[ndx];
+
+ if (typeof shader === 'string') {
+ var elem = getElementById(shader);
+ var src = elem ? elem.text : shader;
+ var type = gl[defaultShaderType[ndx]];
+
+ if (elem && elem.type) {
+ type = getShaderTypeFromScriptType(gl, elem.type) || type;
+ }
+
+ shader = loadShader(gl, src, type, progOptions.errorCallback);
+ newShaders.push(shader);
+ }
+
+ if (helper.isShader(gl, shader)) {
+ realShaders.push(shader);
+ }
+ }
+
+ if (realShaders.length !== shaders.length) {
+ progOptions.errorCallback("not enough shaders for program");
+ deleteShaders(gl, newShaders);
+ return null;
+ }
+
+ var program = gl.createProgram();
+ realShaders.forEach(function (shader) {
+ gl.attachShader(program, shader);
+ });
+
+ if (progOptions.attribLocations) {
+ Object.keys(progOptions.attribLocations).forEach(function (attrib) {
+ gl.bindAttribLocation(program, progOptions.attribLocations[attrib], attrib);
+ });
+ }
+
+ var varyings = progOptions.transformFeedbackVaryings;
+
+ if (varyings) {
+ if (varyings.attribs) {
+ varyings = varyings.attribs;
+ }
+
+ if (!Array.isArray(varyings)) {
+ varyings = Object.keys(varyings);
+ }
+
+ gl.transformFeedbackVaryings(program, varyings, progOptions.transformFeedbackMode || SEPARATE_ATTRIBS);
+ }
+
+ gl.linkProgram(program); // Check the link status
+
+ var linked = gl.getProgramParameter(program, LINK_STATUS);
+
+ if (!linked) {
+ // something went wrong with the link
+ var lastError = gl.getProgramInfoLog(program);
+ progOptions.errorCallback("Error in program linking:" + lastError);
+ gl.deleteProgram(program);
+ deleteShaders(gl, newShaders);
+ return null;
+ }
+
+ return program;
+}
+/**
+ * Loads a shader from a script tag.
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {string} scriptId The id of the script tag.
+ * @param {number} [opt_shaderType] The type of shader. If not passed in it will
+ * be derived from the type of the script tag.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors.
+ * @return {WebGLShader?} The created shader or null if error.
+ * @private
+ */
+
+
+function createShaderFromScript(gl, scriptId, opt_shaderType, opt_errorCallback) {
+ var shaderSource = "";
+ var shaderScript = getElementById(scriptId);
+
+ if (!shaderScript) {
+ throw new Error("unknown script element: ".concat(scriptId));
+ }
+
+ shaderSource = shaderScript.text;
+ var shaderType = opt_shaderType || getShaderTypeFromScriptType(gl, shaderScript.type);
+
+ if (!shaderType) {
+ throw new Error('unknown shader type');
+ }
+
+ return loadShader(gl, shaderSource, shaderType, opt_errorCallback);
+}
+/**
+ * Creates a program from 2 script tags.
+ *
+ * NOTE: There are 4 signatures for this function
+ *
+ * twgl.createProgramFromScripts(gl, [vs, fs], opt_options);
+ * twgl.createProgramFromScripts(gl, [vs, fs], opt_errFunc);
+ * twgl.createProgramFromScripts(gl, [vs, fs], opt_attribs, opt_errFunc);
+ * twgl.createProgramFromScripts(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
+ * to use.
+ * @param {string[]} shaderScriptIds Array of ids of the script
+ * tags for the shaders. The first is assumed to be the
+ * vertex shader, the second the fragment shader.
+ * @param {module:twgl.ProgramOptions|string[]|module:twgl.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
+ * @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
+ * on error. If you want something else pass an callback. It's passed an error message.
+ * @return {WebGLProgram?} the created program or null if error.
+ * @memberOf module:twgl/programs
+ */
+
+
+function createProgramFromScripts(gl, shaderScriptIds, opt_attribs, opt_locations, opt_errorCallback) {
+ var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
+ var shaders = [];
+
+ for (var ii = 0; ii < shaderScriptIds.length; ++ii) {
+ var shader = createShaderFromScript(gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions.errorCallback);
+
+ if (!shader) {
+ return null;
+ }
+
+ shaders.push(shader);
+ }
+
+ return createProgram(gl, shaders, progOptions);
+}
+/**
+ * Creates a program from 2 sources.
+ *
+ * NOTE: There are 4 signatures for this function
+ *
+ * twgl.createProgramFromSource(gl, [vs, fs], opt_options);
+ * twgl.createProgramFromSource(gl, [vs, fs], opt_errFunc);
+ * twgl.createProgramFromSource(gl, [vs, fs], opt_attribs, opt_errFunc);
+ * twgl.createProgramFromSource(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
+ * to use.
+ * @param {string[]} shaderSources Array of sources for the
+ * shaders. The first is assumed to be the vertex shader,
+ * the second the fragment shader.
+ * @param {module:twgl.ProgramOptions|string[]|module:twgl.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
+ * @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
+ * on error. If you want something else pass an callback. It's passed an error message.
+ * @return {WebGLProgram?} the created program or null if error.
+ * @memberOf module:twgl/programs
+ */
+
+
+function createProgramFromSources(gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
+ var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
+ var shaders = [];
+
+ for (var ii = 0; ii < shaderSources.length; ++ii) {
+ var shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions.errorCallback);
+
+ if (!shader) {
+ return null;
+ }
+
+ shaders.push(shader);
+ }
+
+ return createProgram(gl, shaders, progOptions);
+}
+/**
+ * Returns true if attribute/uniform is a reserved/built in
+ *
+ * It makes no sense to me why GL returns these because it's
+ * illegal to call `gl.getUniformLocation` and `gl.getAttribLocation`
+ * with names that start with `gl_` (and `webgl_` in WebGL)
+ *
+ * I can only assume they are there because they might count
+ * when computing the number of uniforms/attributes used when you want to
+ * know if you are near the limit. That doesn't really make sense
+ * to me but the fact that these get returned are in the spec.
+ *
+ * @param {WebGLActiveInfo} info As returned from `gl.getActiveUniform` or
+ * `gl.getActiveAttrib`.
+ * @return {bool} true if it's reserved
+ * @private
+ */
+
+
+function isBuiltIn(info) {
+ var name = info.name;
+ return name.startsWith("gl_") || name.startsWith("webgl_");
+}
+/**
+ * Creates setter functions for all uniforms of a shader
+ * program.
+ *
+ * @see {@link module:twgl.setUniforms}
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {WebGLProgram} program the program to create setters for.
+ * @returns {Object.} an object with a setter by name for each uniform
+ * @memberOf module:twgl/programs
+ */
+
+
+function createUniformSetters(gl, program) {
+ var textureUnit = 0;
+ /**
+ * Creates a setter for a uniform of the given program with it's
+ * location embedded in the setter.
+ * @param {WebGLProgram} program
+ * @param {WebGLUniformInfo} uniformInfo
+ * @returns {function} the created setter.
+ */
+
+ function createUniformSetter(program, uniformInfo) {
+ var location = gl.getUniformLocation(program, uniformInfo.name);
+ var isArray = uniformInfo.size > 1 && uniformInfo.name.substr(-3) === "[0]";
+ var type = uniformInfo.type;
+ var typeInfo = typeMap[type];
+
+ if (!typeInfo) {
+ throw new Error("unknown type: 0x".concat(type.toString(16))); // we should never get here.
+ }
+
+ var setter;
+
+ if (typeInfo.bindPoint) {
+ // it's a sampler
+ var unit = textureUnit;
+ textureUnit += uniformInfo.size;
+
+ if (isArray) {
+ setter = typeInfo.arraySetter(gl, type, unit, location, uniformInfo.size);
+ } else {
+ setter = typeInfo.setter(gl, type, unit, location, uniformInfo.size);
+ }
+ } else {
+ if (typeInfo.arraySetter && isArray) {
+ setter = typeInfo.arraySetter(gl, location);
+ } else {
+ setter = typeInfo.setter(gl, location);
+ }
+ }
+
+ setter.location = location;
+ return setter;
+ }
+
+ var uniformSetters = {};
+ var numUniforms = gl.getProgramParameter(program, ACTIVE_UNIFORMS);
+
+ for (var ii = 0; ii < numUniforms; ++ii) {
+ var uniformInfo = gl.getActiveUniform(program, ii);
+
+ if (isBuiltIn(uniformInfo)) {
+ continue;
+ }
+
+ var name = uniformInfo.name; // remove the array suffix.
+
+ if (name.substr(-3) === "[0]") {
+ name = name.substr(0, name.length - 3);
+ }
+
+ var setter = createUniformSetter(program, uniformInfo);
+ uniformSetters[name] = setter;
+ }
+
+ return uniformSetters;
+}
+/**
+ * @typedef {Object} TransformFeedbackInfo
+ * @property {number} index index of transform feedback
+ * @property {number} type GL type
+ * @property {number} size 1 - 4
+ * @memberOf module:twgl
+ */
+
+/**
+ * Create TransformFeedbackInfo for passing to bindTransformFeedbackInfo.
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {WebGLProgram} program an existing WebGLProgram.
+ * @return {Object}
+ * @memberOf module:twgl
+ */
+
+
+function createTransformFeedbackInfo(gl, program) {
+ var info = {};
+ var numVaryings = gl.getProgramParameter(program, TRANSFORM_FEEDBACK_VARYINGS);
+
+ for (var ii = 0; ii < numVaryings; ++ii) {
+ var varying = gl.getTransformFeedbackVarying(program, ii);
+ info[varying.name] = {
+ index: ii,
+ type: varying.type,
+ size: varying.size
+ };
+ }
+
+ return info;
+}
+/**
+ * Binds buffers for transform feedback.
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {(module:twgl.ProgramInfo|Object)} transformFeedbackInfo A ProgramInfo or TransformFeedbackInfo.
+ * @param {(module:twgl.BufferInfo|Object)} [bufferInfo] A BufferInfo or set of AttribInfos.
+ * @memberOf module:twgl
+ */
+
+
+function bindTransformFeedbackInfo(gl, transformFeedbackInfo, bufferInfo) {
+ if (transformFeedbackInfo.transformFeedbackInfo) {
+ transformFeedbackInfo = transformFeedbackInfo.transformFeedbackInfo;
+ }
+
+ if (bufferInfo.attribs) {
+ bufferInfo = bufferInfo.attribs;
+ }
+
+ for (var name in bufferInfo) {
+ var varying = transformFeedbackInfo[name];
+
+ if (varying) {
+ var buf = bufferInfo[name];
+
+ if (buf.offset) {
+ gl.bindBufferRange(TRANSFORM_FEEDBACK_BUFFER, varying.index, buf.buffer, buf.offset, buf.size);
+ } else {
+ gl.bindBufferBase(TRANSFORM_FEEDBACK_BUFFER, varying.index, buf.buffer);
+ }
+ }
+ }
+}
+/**
+ * Creates a transform feedback and sets the buffers
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {module:twgl.ProgramInfo} programInfo A ProgramInfo as returned from {@link module:twgl.createProgramInfo}
+ * @param {(module:twgl.BufferInfo|Object)} [bufferInfo] A BufferInfo or set of AttribInfos.
+ * @return {WebGLTransformFeedback} the created transform feedback
+ * @memberOf module:twgl
+ */
+
+
+function createTransformFeedback(gl, programInfo, bufferInfo) {
+ var tf = gl.createTransformFeedback();
+ gl.bindTransformFeedback(TRANSFORM_FEEDBACK, tf);
+ gl.useProgram(programInfo.program);
+ bindTransformFeedbackInfo(gl, programInfo, bufferInfo);
+ gl.bindTransformFeedback(TRANSFORM_FEEDBACK, null);
+ return tf;
+}
+/**
+ * @typedef {Object} UniformData
+ * @property {number} type The WebGL type enum for this uniform
+ * @property {number} size The number of elements for this uniform
+ * @property {number} blockNdx The block index this uniform appears in
+ * @property {number} offset The byte offset in the block for this uniform's value
+ * @memberOf module:twgl
+ */
+
+/**
+ * The specification for one UniformBlockObject
+ *
+ * @typedef {Object} BlockSpec
+ * @property {number} index The index of the block.
+ * @property {number} size The size in bytes needed for the block
+ * @property {number[]} uniformIndices The indices of the uniforms used by the block. These indices
+ * correspond to entries in a UniformData array in the {@link module:twgl.UniformBlockSpec}.
+ * @property {bool} usedByVertexShader Self explanatory
+ * @property {bool} usedByFragmentShader Self explanatory
+ * @property {bool} used Self explanatory
+ * @memberOf module:twgl
+ */
+
+/**
+ * A `UniformBlockSpec` represents the data needed to create and bind
+ * UniformBlockObjects for a given program
+ *
+ * @typedef {Object} UniformBlockSpec
+ * @property {Object. blockSpecs The BlockSpec for each block by block name
+ * @property {UniformData[]} uniformData An array of data for each uniform by uniform index.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a UniformBlockSpec for the given program.
+ *
+ * A UniformBlockSpec represents the data needed to create and bind
+ * UniformBlockObjects
+ *
+ * @param {WebGL2RenderingContext} gl A WebGL2 Rendering Context
+ * @param {WebGLProgram} program A WebGLProgram for a successfully linked program
+ * @return {module:twgl.UniformBlockSpec} The created UniformBlockSpec
+ * @memberOf module:twgl/programs
+ */
+
+
+function createUniformBlockSpecFromProgram(gl, program) {
+ var numUniforms = gl.getProgramParameter(program, ACTIVE_UNIFORMS);
+ var uniformData = [];
+ var uniformIndices = [];
+
+ for (var ii = 0; ii < numUniforms; ++ii) {
+ uniformIndices.push(ii);
+ uniformData.push({});
+ var uniformInfo = gl.getActiveUniform(program, ii);
+
+ if (isBuiltIn(uniformInfo)) {
+ break;
+ } // REMOVE [0]?
+
+
+ uniformData[ii].name = uniformInfo.name;
+ }
+
+ [["UNIFORM_TYPE", "type"], ["UNIFORM_SIZE", "size"], // num elements
+ ["UNIFORM_BLOCK_INDEX", "blockNdx"], ["UNIFORM_OFFSET", "offset"]].forEach(function (pair) {
+ var pname = pair[0];
+ var key = pair[1];
+ gl.getActiveUniforms(program, uniformIndices, gl[pname]).forEach(function (value, ndx) {
+ uniformData[ndx][key] = value;
+ });
+ });
+ var blockSpecs = {};
+ var numUniformBlocks = gl.getProgramParameter(program, ACTIVE_UNIFORM_BLOCKS);
+
+ for (var _ii = 0; _ii < numUniformBlocks; ++_ii) {
+ var name = gl.getActiveUniformBlockName(program, _ii);
+ var blockSpec = {
+ index: _ii,
+ usedByVertexShader: gl.getActiveUniformBlockParameter(program, _ii, UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),
+ usedByFragmentShader: gl.getActiveUniformBlockParameter(program, _ii, UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER),
+ size: gl.getActiveUniformBlockParameter(program, _ii, UNIFORM_BLOCK_DATA_SIZE),
+ uniformIndices: gl.getActiveUniformBlockParameter(program, _ii, UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES)
+ };
+ blockSpec.used = blockSpec.usedByVertexShader || blockSpec.usedByFragmentShader;
+ blockSpecs[name] = blockSpec;
+ }
+
+ return {
+ blockSpecs: blockSpecs,
+ uniformData: uniformData
+ };
+}
+
+var arraySuffixRE = /\[\d+\]\.$/; // better way to check?
+
+/**
+ * Represents a UniformBlockObject including an ArrayBuffer with all the uniform values
+ * and a corresponding WebGLBuffer to hold those values on the GPU
+ *
+ * @typedef {Object} UniformBlockInfo
+ * @property {string} name The name of the block
+ * @property {ArrayBuffer} array The array buffer that contains the uniform values
+ * @property {Float32Array} asFloat A float view on the array buffer. This is useful
+ * inspecting the contents of the buffer in the debugger.
+ * @property {WebGLBuffer} buffer A WebGL buffer that will hold a copy of the uniform values for rendering.
+ * @property {number} [offset] offset into buffer
+ * @property {Object.} uniforms A uniform name to ArrayBufferView map.
+ * each Uniform has a correctly typed `ArrayBufferView` into array at the correct offset
+ * and length of that uniform. So for example a float uniform would have a 1 float `Float32Array`
+ * view. A single mat4 would have a 16 element `Float32Array` view. An ivec2 would have an
+ * `Int32Array` view, etc.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a `UniformBlockInfo` for the specified block
+ *
+ * Note: **If the blockName matches no existing blocks a warning is printed to the console and a dummy
+ * `UniformBlockInfo` is returned**. This is because when debugging GLSL
+ * it is common to comment out large portions of a shader or for example set
+ * the final output to a constant. When that happens blocks get optimized out.
+ * If this function did not create dummy blocks your code would crash when debugging.
+ *
+ * @param {WebGL2RenderingContext} gl A WebGL2RenderingContext
+ * @param {WebGLProgram} program A WebGLProgram
+ * @param {module:twgl.UniformBlockSpec} uniformBlockSpec. A UniformBlockSpec as returned
+ * from {@link module:twgl.createUniformBlockSpecFromProgram}.
+ * @param {string} blockName The name of the block.
+ * @return {module:twgl.UniformBlockInfo} The created UniformBlockInfo
+ * @memberOf module:twgl/programs
+ */
+
+function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockName) {
+ var blockSpecs = uniformBlockSpec.blockSpecs;
+ var uniformData = uniformBlockSpec.uniformData;
+ var blockSpec = blockSpecs[blockName];
+
+ if (!blockSpec) {
+ warn("no uniform block object named:", blockName);
+ return {
+ name: blockName,
+ uniforms: {}
+ };
+ }
+
+ var array = new ArrayBuffer(blockSpec.size);
+ var buffer = gl.createBuffer();
+ var uniformBufferIndex = blockSpec.index;
+ gl.bindBuffer(UNIFORM_BUFFER, buffer);
+ gl.uniformBlockBinding(program, blockSpec.index, uniformBufferIndex);
+ var prefix = blockName + ".";
+
+ if (arraySuffixRE.test(prefix)) {
+ prefix = prefix.replace(arraySuffixRE, ".");
+ }
+
+ var uniforms = {};
+ blockSpec.uniformIndices.forEach(function (uniformNdx) {
+ var data = uniformData[uniformNdx];
+ var typeInfo = typeMap[data.type];
+ var Type = typeInfo.Type;
+ var length = data.size * typeInfo.size;
+ var name = data.name;
+
+ if (name.substr(0, prefix.length) === prefix) {
+ name = name.substr(prefix.length);
+ }
+
+ uniforms[name] = new Type(array, data.offset, length / Type.BYTES_PER_ELEMENT);
+ });
+ return {
+ name: blockName,
+ array: array,
+ asFloat: new Float32Array(array),
+ // for debugging
+ buffer: buffer,
+ uniforms: uniforms
+ };
+}
+/**
+ * Creates a `UniformBlockInfo` for the specified block
+ *
+ * Note: **If the blockName matches no existing blocks a warning is printed to the console and a dummy
+ * `UniformBlockInfo` is returned**. This is because when debugging GLSL
+ * it is common to comment out large portions of a shader or for example set
+ * the final output to a constant. When that happens blocks get optimized out.
+ * If this function did not create dummy blocks your code would crash when debugging.
+ *
+ * @param {WebGL2RenderingContext} gl A WebGL2RenderingContext
+ * @param {module:twgl.ProgramInfo} programInfo a `ProgramInfo`
+ * as returned from {@link module:twgl.createProgramInfo}
+ * @param {string} blockName The name of the block.
+ * @return {module:twgl.UniformBlockInfo} The created UniformBlockInfo
+ * @memberOf module:twgl/programs
+ */
+
+
+function createUniformBlockInfo(gl, programInfo, blockName) {
+ return createUniformBlockInfoFromProgram(gl, programInfo.program, programInfo.uniformBlockSpec, blockName);
+}
+/**
+ * Binds a uniform block to the matching uniform block point.
+ * Matches by blocks by name so blocks must have the same name not just the same
+ * structure.
+ *
+ * If you have changed any values and you upload the values into the corresponding WebGLBuffer
+ * call {@link module:twgl.setUniformBlock} instead.
+ *
+ * @param {WebGL2RenderingContext} gl A WebGL 2 rendering context.
+ * @param {(module:twgl.ProgramInfo|module:twgl.UniformBlockSpec)} programInfo a `ProgramInfo`
+ * as returned from {@link module:twgl.createProgramInfo} or or `UniformBlockSpec` as
+ * returned from {@link module:twgl.createUniformBlockSpecFromProgram}.
+ * @param {module:twgl.UniformBlockInfo} uniformBlockInfo a `UniformBlockInfo` as returned from
+ * {@link module:twgl.createUniformBlockInfo}.
+ * @return {bool} true if buffer was bound. If the programInfo has no block with the same block name
+ * no buffer is bound.
+ * @memberOf module:twgl/programs
+ */
+
+
+function bindUniformBlock(gl, programInfo, uniformBlockInfo) {
+ var uniformBlockSpec = programInfo.uniformBlockSpec || programInfo;
+ var blockSpec = uniformBlockSpec.blockSpecs[uniformBlockInfo.name];
+
+ if (blockSpec) {
+ var bufferBindIndex = blockSpec.index;
+ gl.bindBufferRange(UNIFORM_BUFFER, bufferBindIndex, uniformBlockInfo.buffer, uniformBlockInfo.offset || 0, uniformBlockInfo.array.byteLength);
+ return true;
+ }
+
+ return false;
+}
+/**
+ * Uploads the current uniform values to the corresponding WebGLBuffer
+ * and binds that buffer to the program's corresponding bind point for the uniform block object.
+ *
+ * If you haven't changed any values and you only need to bind the uniform block object
+ * call {@link module:twgl.bindUniformBlock} instead.
+ *
+ * @param {WebGL2RenderingContext} gl A WebGL 2 rendering context.
+ * @param {(module:twgl.ProgramInfo|module:twgl.UniformBlockSpec)} programInfo a `ProgramInfo`
+ * as returned from {@link module:twgl.createProgramInfo} or or `UniformBlockSpec` as
+ * returned from {@link module:twgl.createUniformBlockSpecFromProgram}.
+ * @param {module:twgl.UniformBlockInfo} uniformBlockInfo a `UniformBlockInfo` as returned from
+ * {@link module:twgl.createUniformBlockInfo}.
+ * @memberOf module:twgl/programs
+ */
+
+
+function setUniformBlock(gl, programInfo, uniformBlockInfo) {
+ if (bindUniformBlock(gl, programInfo, uniformBlockInfo)) {
+ gl.bufferData(UNIFORM_BUFFER, uniformBlockInfo.array, DYNAMIC_DRAW);
+ }
+}
+/**
+ * Sets values of a uniform block object
+ *
+ * @param {module:twgl.UniformBlockInfo} uniformBlockInfo A UniformBlockInfo as returned by {@link module:twgl.createUniformBlockInfo}.
+ * @param {Object.} values A uniform name to value map where the value is correct for the given
+ * type of uniform. So for example given a block like
+ *
+ * uniform SomeBlock {
+ * float someFloat;
+ * vec2 someVec2;
+ * vec3 someVec3Array[2];
+ * int someInt;
+ * }
+ *
+ * You can set the values of the uniform block with
+ *
+ * twgl.setBlockUniforms(someBlockInfo, {
+ * someFloat: 12.3,
+ * someVec2: [1, 2],
+ * someVec3Array: [1, 2, 3, 4, 5, 6],
+ * someInt: 5,
+ * }
+ *
+ * Arrays can be JavaScript arrays or typed arrays
+ *
+ * Any name that doesn't match will be ignored
+ * @memberOf module:twgl/programs
+ */
+
+
+function setBlockUniforms(uniformBlockInfo, values) {
+ var uniforms = uniformBlockInfo.uniforms;
+
+ for (var name in values) {
+ var array = uniforms[name];
+
+ if (array) {
+ var value = values[name];
+
+ if (value.length) {
+ array.set(value);
+ } else {
+ array[0] = value;
+ }
+ }
+ }
+}
+/**
+ * Set uniforms and binds related textures.
+ *
+ * example:
+ *
+ * const programInfo = createProgramInfo(
+ * gl, ["some-vs", "some-fs"]);
+ *
+ * const tex1 = gl.createTexture();
+ * const tex2 = gl.createTexture();
+ *
+ * ... assume we setup the textures with data ...
+ *
+ * const uniforms = {
+ * u_someSampler: tex1,
+ * u_someOtherSampler: tex2,
+ * u_someColor: [1,0,0,1],
+ * u_somePosition: [0,1,1],
+ * u_someMatrix: [
+ * 1,0,0,0,
+ * 0,1,0,0,
+ * 0,0,1,0,
+ * 0,0,0,0,
+ * ],
+ * };
+ *
+ * gl.useProgram(program);
+ *
+ * This will automatically bind the textures AND set the
+ * uniforms.
+ *
+ * twgl.setUniforms(programInfo, uniforms);
+ *
+ * For the example above it is equivalent to
+ *
+ * var texUnit = 0;
+ * gl.activeTexture(gl.TEXTURE0 + texUnit);
+ * gl.bindTexture(gl.TEXTURE_2D, tex1);
+ * gl.uniform1i(u_someSamplerLocation, texUnit++);
+ * gl.activeTexture(gl.TEXTURE0 + texUnit);
+ * gl.bindTexture(gl.TEXTURE_2D, tex2);
+ * gl.uniform1i(u_someSamplerLocation, texUnit++);
+ * gl.uniform4fv(u_someColorLocation, [1, 0, 0, 1]);
+ * gl.uniform3fv(u_somePositionLocation, [0, 1, 1]);
+ * gl.uniformMatrix4fv(u_someMatrix, false, [
+ * 1,0,0,0,
+ * 0,1,0,0,
+ * 0,0,1,0,
+ * 0,0,0,0,
+ * ]);
+ *
+ * Note it is perfectly reasonable to call `setUniforms` multiple times. For example
+ *
+ * const uniforms = {
+ * u_someSampler: tex1,
+ * u_someOtherSampler: tex2,
+ * };
+ *
+ * const moreUniforms {
+ * u_someColor: [1,0,0,1],
+ * u_somePosition: [0,1,1],
+ * u_someMatrix: [
+ * 1,0,0,0,
+ * 0,1,0,0,
+ * 0,0,1,0,
+ * 0,0,0,0,
+ * ],
+ * };
+ *
+ * twgl.setUniforms(programInfo, uniforms);
+ * twgl.setUniforms(programInfo, moreUniforms);
+ *
+ * You can also add WebGLSamplers to uniform samplers as in
+ *
+ * const uniforms = {
+ * u_someSampler: {
+ * texture: someWebGLTexture,
+ * sampler: someWebGLSampler,
+ * },
+ * };
+ *
+ * In which case both the sampler and texture will be bound to the
+ * same unit.
+ *
+ * @param {(module:twgl.ProgramInfo|Object.)} setters a `ProgramInfo` as returned from `createProgramInfo` or the setters returned from
+ * `createUniformSetters`.
+ * @param {Object.} values an object with values for the
+ * uniforms.
+ * You can pass multiple objects by putting them in an array or by calling with more arguments.For example
+ *
+ * const sharedUniforms = {
+ * u_fogNear: 10,
+ * u_projection: ...
+ * ...
+ * };
+ *
+ * const localUniforms = {
+ * u_world: ...
+ * u_diffuseColor: ...
+ * };
+ *
+ * twgl.setUniforms(programInfo, sharedUniforms, localUniforms);
+ *
+ * // is the same as
+ *
+ * twgl.setUniforms(programInfo, [sharedUniforms, localUniforms]);
+ *
+ * // is the same as
+ *
+ * twgl.setUniforms(programInfo, sharedUniforms);
+ * twgl.setUniforms(programInfo, localUniforms};
+ *
+ * @memberOf module:twgl/programs
+ */
+
+
+function setUniforms(setters, values) {
+ // eslint-disable-line
+ var actualSetters = setters.uniformSetters || setters;
+ var numArgs = arguments.length;
+
+ for (var aNdx = 1; aNdx < numArgs; ++aNdx) {
+ var _values = arguments[aNdx];
+
+ if (Array.isArray(_values)) {
+ var numValues = _values.length;
+
+ for (var ii = 0; ii < numValues; ++ii) {
+ setUniforms(actualSetters, _values[ii]);
+ }
+ } else {
+ for (var name in _values) {
+ var setter = actualSetters[name];
+
+ if (setter) {
+ setter(_values[name]);
+ }
+ }
+ }
+ }
+}
+/**
+ * Alias for `setUniforms`
+ * @function
+ * @param {(module:twgl.ProgramInfo|Object.)} setters a `ProgramInfo` as returned from `createProgramInfo` or the setters returned from
+ * `createUniformSetters`.
+ * @param {Object.} values an object with values for the
+ * @memberOf module:twgl/programs
+ */
+
+
+var setUniformsAndBindTextures = setUniforms;
+/**
+ * Creates setter functions for all attributes of a shader
+ * program. You can pass this to {@link module:twgl.setBuffersAndAttributes} to set all your buffers and attributes.
+ *
+ * @see {@link module:twgl.setAttributes} for example
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
+ * @param {WebGLProgram} program the program to create setters for.
+ * @return {Object.} an object with a setter for each attribute by name.
+ * @memberOf module:twgl/programs
+ */
+
+exports.setUniformsAndBindTextures = setUniformsAndBindTextures;
+
+function createAttributeSetters(gl, program) {
+ var attribSetters = {};
+ var numAttribs = gl.getProgramParameter(program, ACTIVE_ATTRIBUTES);
+
+ for (var ii = 0; ii < numAttribs; ++ii) {
+ var attribInfo = gl.getActiveAttrib(program, ii);
+
+ if (isBuiltIn(attribInfo)) {
+ continue;
+ }
+
+ var index = gl.getAttribLocation(program, attribInfo.name);
+ var typeInfo = attrTypeMap[attribInfo.type];
+ var setter = typeInfo.setter(gl, index, typeInfo);
+ setter.location = index;
+ attribSetters[attribInfo.name] = setter;
+ }
+
+ return attribSetters;
+}
+/**
+ * Sets attributes and binds buffers (deprecated... use {@link module:twgl.setBuffersAndAttributes})
+ *
+ * Example:
+ *
+ * const program = createProgramFromScripts(
+ * gl, ["some-vs", "some-fs");
+ *
+ * const attribSetters = createAttributeSetters(program);
+ *
+ * const positionBuffer = gl.createBuffer();
+ * const texcoordBuffer = gl.createBuffer();
+ *
+ * const attribs = {
+ * a_position: {buffer: positionBuffer, numComponents: 3},
+ * a_texcoord: {buffer: texcoordBuffer, numComponents: 2},
+ * };
+ *
+ * gl.useProgram(program);
+ *
+ * This will automatically bind the buffers AND set the
+ * attributes.
+ *
+ * setAttributes(attribSetters, attribs);
+ *
+ * Properties of attribs. For each attrib you can add
+ * properties:
+ *
+ * * type: the type of data in the buffer. Default = gl.FLOAT
+ * * normalize: whether or not to normalize the data. Default = false
+ * * stride: the stride. Default = 0
+ * * offset: offset into the buffer. Default = 0
+ * * divisor: the divisor for instances. Default = undefined
+ *
+ * For example if you had 3 value float positions, 2 value
+ * float texcoord and 4 value uint8 colors you'd setup your
+ * attribs like this
+ *
+ * const attribs = {
+ * a_position: {buffer: positionBuffer, numComponents: 3},
+ * a_texcoord: {buffer: texcoordBuffer, numComponents: 2},
+ * a_color: {
+ * buffer: colorBuffer,
+ * numComponents: 4,
+ * type: gl.UNSIGNED_BYTE,
+ * normalize: true,
+ * },
+ * };
+ *
+ * @param {Object.} setters Attribute setters as returned from createAttributeSetters
+ * @param {Object.} buffers AttribInfos mapped by attribute name.
+ * @memberOf module:twgl/programs
+ * @deprecated use {@link module:twgl.setBuffersAndAttributes}
+ */
+
+
+function setAttributes(setters, buffers) {
+ for (var name in buffers) {
+ var setter = setters[name];
+
+ if (setter) {
+ setter(buffers[name]);
+ }
+ }
+}
+/**
+ * Sets attributes and buffers including the `ELEMENT_ARRAY_BUFFER` if appropriate
+ *
+ * Example:
+ *
+ * const programInfo = createProgramInfo(
+ * gl, ["some-vs", "some-fs");
+ *
+ * const arrays = {
+ * position: { numComponents: 3, data: [0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0], },
+ * texcoord: { numComponents: 2, data: [0, 0, 0, 1, 1, 0, 1, 1], },
+ * };
+ *
+ * const bufferInfo = createBufferInfoFromArrays(gl, arrays);
+ *
+ * gl.useProgram(programInfo.program);
+ *
+ * This will automatically bind the buffers AND set the
+ * attributes.
+ *
+ * setBuffersAndAttributes(gl, programInfo, bufferInfo);
+ *
+ * For the example above it is equivalent to
+ *
+ * gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
+ * gl.enableVertexAttribArray(a_positionLocation);
+ * gl.vertexAttribPointer(a_positionLocation, 3, gl.FLOAT, false, 0, 0);
+ * gl.bindBuffer(gl.ARRAY_BUFFER, texcoordBuffer);
+ * gl.enableVertexAttribArray(a_texcoordLocation);
+ * gl.vertexAttribPointer(a_texcoordLocation, 4, gl.FLOAT, false, 0, 0);
+ *
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext.
+ * @param {(module:twgl.ProgramInfo|Object.)} setters A `ProgramInfo` as returned from {@link module:twgl.createProgramInfo} or Attribute setters as returned from {@link module:twgl.createAttributeSetters}
+ * @param {(module:twgl.BufferInfo|module:twgl.VertexArrayInfo)} buffers a `BufferInfo` as returned from {@link module:twgl.createBufferInfoFromArrays}.
+ * or a `VertexArrayInfo` as returned from {@link module:twgl.createVertexArrayInfo}
+ * @memberOf module:twgl/programs
+ */
+
+
+function setBuffersAndAttributes(gl, programInfo, buffers) {
+ if (buffers.vertexArrayObject) {
+ gl.bindVertexArray(buffers.vertexArrayObject);
+ } else {
+ setAttributes(programInfo.attribSetters || programInfo, buffers.attribs);
+
+ if (buffers.indices) {
+ gl.bindBuffer(ELEMENT_ARRAY_BUFFER, buffers.indices);
+ }
+ }
+}
+/**
+ * @typedef {Object} ProgramInfo
+ * @property {WebGLProgram} program A shader program
+ * @property {Object} uniformSetters object of setters as returned from createUniformSetters,
+ * @property {Object} attribSetters object of setters as returned from createAttribSetters,
+ * @property {module:twgl.UniformBlockSpec} [uniformBlockSpace] a uniform block spec for making UniformBlockInfos with createUniformBlockInfo etc..
+ * @property {Object} [transformFeedbackInfo] info for transform feedbacks
+ * @memberOf module:twgl
+ */
+
+/**
+ * Creates a ProgramInfo from an existing program.
+ *
+ * A ProgramInfo contains
+ *
+ * programInfo = {
+ * program: WebGLProgram,
+ * uniformSetters: object of setters as returned from createUniformSetters,
+ * attribSetters: object of setters as returned from createAttribSetters,
+ * }
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
+ * to use.
+ * @param {WebGLProgram} program an existing WebGLProgram.
+ * @return {module:twgl.ProgramInfo} The created ProgramInfo.
+ * @memberOf module:twgl/programs
+ */
+
+
+function createProgramInfoFromProgram(gl, program) {
+ var uniformSetters = createUniformSetters(gl, program);
+ var attribSetters = createAttributeSetters(gl, program);
+ var programInfo = {
+ program: program,
+ uniformSetters: uniformSetters,
+ attribSetters: attribSetters
+ };
+
+ if (utils.isWebGL2(gl)) {
+ programInfo.uniformBlockSpec = createUniformBlockSpecFromProgram(gl, program);
+ programInfo.transformFeedbackInfo = createTransformFeedbackInfo(gl, program);
+ }
+
+ return programInfo;
+}
+/**
+ * Creates a ProgramInfo from 2 sources.
+ *
+ * A ProgramInfo contains
+ *
+ * programInfo = {
+ * program: WebGLProgram,
+ * uniformSetters: object of setters as returned from createUniformSetters,
+ * attribSetters: object of setters as returned from createAttribSetters,
+ * }
+ *
+ * NOTE: There are 4 signatures for this function
+ *
+ * twgl.createProgramInfo(gl, [vs, fs], options);
+ * twgl.createProgramInfo(gl, [vs, fs], opt_errFunc);
+ * twgl.createProgramInfo(gl, [vs, fs], opt_attribs, opt_errFunc);
+ * twgl.createProgramInfo(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
+ *
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
+ * to use.
+ * @param {string[]} shaderSources Array of sources for the
+ * shaders or ids. The first is assumed to be the vertex shader,
+ * the second the fragment shader.
+ * @param {module:twgl.ProgramOptions|string[]|module:twgl.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
+ * @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
+ * on error. If you want something else pass an callback. It's passed an error message.
+ * @return {module:twgl.ProgramInfo?} The created ProgramInfo or null if it failed to link or compile
+ * @memberOf module:twgl/programs
+ */
+
+
+function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
+ var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
+ var good = true;
+ shaderSources = shaderSources.map(function (source) {
+ // Lets assume if there is no \n it's an id
+ if (source.indexOf("\n") < 0) {
+ var script = getElementById(source);
+
+ if (!script) {
+ progOptions.errorCallback("no element with id: " + source);
+ good = false;
+ } else {
+ source = script.text;
+ }
+ }
+
+ return source;
+ });
+
+ if (!good) {
+ return null;
+ }
+
+ var program = createProgramFromSources(gl, shaderSources, progOptions);
+
+ if (!program) {
+ return null;
+ }
+
+ return createProgramInfoFromProgram(gl, program);
+}
+
+/***/ }),
+
+/***/ "./src/textures.js":
+/*!*************************!*\
+ !*** ./src/textures.js ***!
+ \*************************/
+/*! no static exports found */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+exports.__esModule = true;
+exports.setTextureDefaults_ = setDefaults;
+exports.createSampler = createSampler;
+exports.createSamplers = createSamplers;
+exports.setSamplerParameters = setSamplerParameters;
+exports.createTexture = createTexture;
+exports.setEmptyTexture = setEmptyTexture;
+exports.setTextureFromArray = setTextureFromArray;
+exports.loadTextureFromUrl = loadTextureFromUrl;
+exports.setTextureFromElement = setTextureFromElement;
+exports.setTextureFilteringForSize = setTextureFilteringForSize;
+exports.setTextureParameters = setTextureParameters;
+exports.setDefaultTextureColor = setDefaultTextureColor;
+exports.createTextures = createTextures;
+exports.resizeTexture = resizeTexture;
+exports.canGenerateMipmap = canGenerateMipmap;
+exports.canFilter = canFilter;
+exports.getNumComponentsForFormat = getNumComponentsForFormat;
+exports.getBytesPerElementForInternalFormat = getBytesPerElementForInternalFormat;
+exports.getFormatAndTypeForInternalFormat = getFormatAndTypeForInternalFormat;
+
+var utils = _interopRequireWildcard(__webpack_require__(/*! ./utils.js */ "./src/utils.js"));
+
+var typedArrays = _interopRequireWildcard(__webpack_require__(/*! ./typedarrays.js */ "./src/typedarrays.js"));
+
+var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
+
+function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
+
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+
+/*
+ * Copyright 2019 Gregg Tavares
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * Low level texture related functions
+ *
+ * You should generally not need to use these functions. They are provided
+ * for those cases where you're doing something out of the ordinary
+ * and you need lower level access.
+ *
+ * For backward compatibility they are available at both `twgl.textures` and `twgl`
+ * itself
+ *
+ * See {@link module:twgl} for core functions
+ *
+ * @module twgl/textures
+ */
+// make sure we don't see a global gl
+var gl = undefined;
+/* eslint-disable-line */
+
+/* lgtm [js/unused-local-variable] */
+
+var defaults = {
+ textureColor: new Uint8Array([128, 192, 255, 255]),
+ textureOptions: {},
+ crossOrigin: undefined
+};
+var isArrayBuffer = typedArrays.isArrayBuffer; // Should we make this on demand?
+
+var s_ctx;
+
+function getShared2DContext() {
+ s_ctx = s_ctx || (typeof document !== 'undefined' && document.createElement ? document.createElement("canvas").getContext("2d") : null);
+ return s_ctx;
+} // NOTE: Chrome supports 2D canvas in a Worker (behind flag as of v64 but
+// not only does Firefox NOT support it but Firefox freezes immediately
+// if you try to create one instead of just returning null and continuing.
+// : (global.OffscreenCanvas && (new global.OffscreenCanvas(1, 1)).getContext("2d")); // OffscreenCanvas may not support 2d
+// NOTE: We can maybe remove some of the need for the 2d canvas. In WebGL2
+// we can use the various unpack settings. Otherwise we could try using
+// the ability of an ImageBitmap to be cut. Unfortunately cutting an ImageBitmap
+// is async and the current TWGL code expects a non-Async result though that
+// might not be a problem. ImageBitmap though is not available in Edge or Safari
+// as of 2018-01-02
+
+/* PixelFormat */
+
+
+var ALPHA = 0x1906;
+var RGB = 0x1907;
+var RGBA = 0x1908;
+var LUMINANCE = 0x1909;
+var LUMINANCE_ALPHA = 0x190A;
+var DEPTH_COMPONENT = 0x1902;
+var DEPTH_STENCIL = 0x84F9;
+/* TextureWrapMode */
+// const REPEAT = 0x2901;
+// const MIRRORED_REPEAT = 0x8370;
+
+var CLAMP_TO_EDGE = 0x812f;
+/* TextureMagFilter */
+
+var NEAREST = 0x2600;
+var LINEAR = 0x2601;
+/* TextureMinFilter */
+// const NEAREST_MIPMAP_NEAREST = 0x2700;
+// const LINEAR_MIPMAP_NEAREST = 0x2701;
+// const NEAREST_MIPMAP_LINEAR = 0x2702;
+// const LINEAR_MIPMAP_LINEAR = 0x2703;
+
+/* Texture Target */
+
+var TEXTURE_2D = 0x0de1;
+var TEXTURE_CUBE_MAP = 0x8513;
+var TEXTURE_3D = 0x806f;
+var TEXTURE_2D_ARRAY = 0x8c1a;
+/* Cubemap Targets */
+
+var TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515;
+var TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516;
+var TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517;
+var TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518;
+var TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519;
+var TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851a;
+/* Texture Parameters */
+
+var TEXTURE_MIN_FILTER = 0x2801;
+var TEXTURE_MAG_FILTER = 0x2800;
+var TEXTURE_WRAP_S = 0x2802;
+var TEXTURE_WRAP_T = 0x2803;
+var TEXTURE_WRAP_R = 0x8072;
+var TEXTURE_MIN_LOD = 0x813a;
+var TEXTURE_MAX_LOD = 0x813b;
+var TEXTURE_BASE_LEVEL = 0x813c;
+var TEXTURE_MAX_LEVEL = 0x813d;
+/* Pixel store */
+
+var UNPACK_ALIGNMENT = 0x0cf5;
+var UNPACK_ROW_LENGTH = 0x0cf2;
+var UNPACK_IMAGE_HEIGHT = 0x806e;
+var UNPACK_SKIP_PIXELS = 0x0cf4;
+var UNPACK_SKIP_ROWS = 0x0cf3;
+var UNPACK_SKIP_IMAGES = 0x806d;
+var UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243;
+var UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241;
+var UNPACK_FLIP_Y_WEBGL = 0x9240;
+var R8 = 0x8229;
+var R8_SNORM = 0x8F94;
+var R16F = 0x822D;
+var R32F = 0x822E;
+var R8UI = 0x8232;
+var R8I = 0x8231;
+var RG16UI = 0x823A;
+var RG16I = 0x8239;
+var RG32UI = 0x823C;
+var RG32I = 0x823B;
+var RG8 = 0x822B;
+var RG8_SNORM = 0x8F95;
+var RG16F = 0x822F;
+var RG32F = 0x8230;
+var RG8UI = 0x8238;
+var RG8I = 0x8237;
+var R16UI = 0x8234;
+var R16I = 0x8233;
+var R32UI = 0x8236;
+var R32I = 0x8235;
+var RGB8 = 0x8051;
+var SRGB8 = 0x8C41;
+var RGB565 = 0x8D62;
+var RGB8_SNORM = 0x8F96;
+var R11F_G11F_B10F = 0x8C3A;
+var RGB9_E5 = 0x8C3D;
+var RGB16F = 0x881B;
+var RGB32F = 0x8815;
+var RGB8UI = 0x8D7D;
+var RGB8I = 0x8D8F;
+var RGB16UI = 0x8D77;
+var RGB16I = 0x8D89;
+var RGB32UI = 0x8D71;
+var RGB32I = 0x8D83;
+var RGBA8 = 0x8058;
+var SRGB8_ALPHA8 = 0x8C43;
+var RGBA8_SNORM = 0x8F97;
+var RGB5_A1 = 0x8057;
+var RGBA4 = 0x8056;
+var RGB10_A2 = 0x8059;
+var RGBA16F = 0x881A;
+var RGBA32F = 0x8814;
+var RGBA8UI = 0x8D7C;
+var RGBA8I = 0x8D8E;
+var RGB10_A2UI = 0x906F;
+var RGBA16UI = 0x8D76;
+var RGBA16I = 0x8D88;
+var RGBA32I = 0x8D82;
+var RGBA32UI = 0x8D70;
+var DEPTH_COMPONENT16 = 0x81A5;
+var DEPTH_COMPONENT24 = 0x81A6;
+var DEPTH_COMPONENT32F = 0x8CAC;
+var DEPTH32F_STENCIL8 = 0x8CAD;
+var DEPTH24_STENCIL8 = 0x88F0;
+/* DataType */
+
+var BYTE = 0x1400;
+var UNSIGNED_BYTE = 0x1401;
+var SHORT = 0x1402;
+var UNSIGNED_SHORT = 0x1403;
+var INT = 0x1404;
+var UNSIGNED_INT = 0x1405;
+var FLOAT = 0x1406;
+var UNSIGNED_SHORT_4_4_4_4 = 0x8033;
+var UNSIGNED_SHORT_5_5_5_1 = 0x8034;
+var UNSIGNED_SHORT_5_6_5 = 0x8363;
+var HALF_FLOAT = 0x140B;
+var HALF_FLOAT_OES = 0x8D61; // Thanks Khronos for making this different >:(
+
+var UNSIGNED_INT_2_10_10_10_REV = 0x8368;
+var UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B;
+var UNSIGNED_INT_5_9_9_9_REV = 0x8C3E;
+var FLOAT_32_UNSIGNED_INT_24_8_REV = 0x8DAD;
+var UNSIGNED_INT_24_8 = 0x84FA;
+var RG = 0x8227;
+var RG_INTEGER = 0x8228;
+var RED = 0x1903;
+var RED_INTEGER = 0x8D94;
+var RGB_INTEGER = 0x8D98;
+var RGBA_INTEGER = 0x8D99;
+var formatInfo = {};
+{
+ // NOTE: this is named `numColorComponents` vs `numComponents` so we can let Uglify mangle
+ // the name.
+ var f = formatInfo;
+ f[ALPHA] = {
+ numColorComponents: 1
+ };
+ f[LUMINANCE] = {
+ numColorComponents: 1
+ };
+ f[LUMINANCE_ALPHA] = {
+ numColorComponents: 2
+ };
+ f[RGB] = {
+ numColorComponents: 3
+ };
+ f[RGBA] = {
+ numColorComponents: 4
+ };
+ f[RED] = {
+ numColorComponents: 1
+ };
+ f[RED_INTEGER] = {
+ numColorComponents: 1
+ };
+ f[RG] = {
+ numColorComponents: 2
+ };
+ f[RG_INTEGER] = {
+ numColorComponents: 2
+ };
+ f[RGB] = {
+ numColorComponents: 3
+ };
+ f[RGB_INTEGER] = {
+ numColorComponents: 3
+ };
+ f[RGBA] = {
+ numColorComponents: 4
+ };
+ f[RGBA_INTEGER] = {
+ numColorComponents: 4
+ };
+ f[DEPTH_COMPONENT] = {
+ numColorComponents: 1
+ };
+ f[DEPTH_STENCIL] = {
+ numColorComponents: 2
+ };
+}
+/**
+ * @typedef {Object} TextureFormatDetails
+ * @property {number} textureFormat format to pass texImage2D and similar functions.
+ * @property {boolean} colorRenderable true if you can render to this format of texture.
+ * @property {boolean} textureFilterable true if you can filter the texture, false if you can ony use `NEAREST`.
+ * @property {number[]} type Array of possible types you can pass to texImage2D and similar function
+ * @property {Object.} bytesPerElementMap A map of types to bytes per element
+ * @private
+ */
+
+var s_textureInternalFormatInfo;
+
+function getTextureInternalFormatInfo(internalFormat) {
+ if (!s_textureInternalFormatInfo) {
+ // NOTE: these properties need unique names so we can let Uglify mangle the name.
+ var t = {}; // unsized formats
+
+ t[ALPHA] = {
+ textureFormat: ALPHA,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [1, 2, 2, 4],
+ type: [UNSIGNED_BYTE, HALF_FLOAT, HALF_FLOAT_OES, FLOAT]
+ };
+ t[LUMINANCE] = {
+ textureFormat: LUMINANCE,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [1, 2, 2, 4],
+ type: [UNSIGNED_BYTE, HALF_FLOAT, HALF_FLOAT_OES, FLOAT]
+ };
+ t[LUMINANCE_ALPHA] = {
+ textureFormat: LUMINANCE_ALPHA,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [2, 4, 4, 8],
+ type: [UNSIGNED_BYTE, HALF_FLOAT, HALF_FLOAT_OES, FLOAT]
+ };
+ t[RGB] = {
+ textureFormat: RGB,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [3, 6, 6, 12, 2],
+ type: [UNSIGNED_BYTE, HALF_FLOAT, HALF_FLOAT_OES, FLOAT, UNSIGNED_SHORT_5_6_5]
+ };
+ t[RGBA] = {
+ textureFormat: RGBA,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [4, 8, 8, 16, 2, 2],
+ type: [UNSIGNED_BYTE, HALF_FLOAT, HALF_FLOAT_OES, FLOAT, UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_5_5_5_1]
+ }; // sized formats
+
+ t[R8] = {
+ textureFormat: RED,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [1],
+ type: [UNSIGNED_BYTE]
+ };
+ t[R8_SNORM] = {
+ textureFormat: RED,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [1],
+ type: [BYTE]
+ };
+ t[R16F] = {
+ textureFormat: RED,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [4, 2],
+ type: [FLOAT, HALF_FLOAT]
+ };
+ t[R32F] = {
+ textureFormat: RED,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [FLOAT]
+ };
+ t[R8UI] = {
+ textureFormat: RED_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [1],
+ type: [UNSIGNED_BYTE]
+ };
+ t[R8I] = {
+ textureFormat: RED_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [1],
+ type: [BYTE]
+ };
+ t[R16UI] = {
+ textureFormat: RED_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [2],
+ type: [UNSIGNED_SHORT]
+ };
+ t[R16I] = {
+ textureFormat: RED_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [2],
+ type: [SHORT]
+ };
+ t[R32UI] = {
+ textureFormat: RED_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [UNSIGNED_INT]
+ };
+ t[R32I] = {
+ textureFormat: RED_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [INT]
+ };
+ t[RG8] = {
+ textureFormat: RG,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [2],
+ type: [UNSIGNED_BYTE]
+ };
+ t[RG8_SNORM] = {
+ textureFormat: RG,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [2],
+ type: [BYTE]
+ };
+ t[RG16F] = {
+ textureFormat: RG,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [8, 4],
+ type: [FLOAT, HALF_FLOAT]
+ };
+ t[RG32F] = {
+ textureFormat: RG,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [8],
+ type: [FLOAT]
+ };
+ t[RG8UI] = {
+ textureFormat: RG_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [2],
+ type: [UNSIGNED_BYTE]
+ };
+ t[RG8I] = {
+ textureFormat: RG_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [2],
+ type: [BYTE]
+ };
+ t[RG16UI] = {
+ textureFormat: RG_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [UNSIGNED_SHORT]
+ };
+ t[RG16I] = {
+ textureFormat: RG_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [SHORT]
+ };
+ t[RG32UI] = {
+ textureFormat: RG_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [8],
+ type: [UNSIGNED_INT]
+ };
+ t[RG32I] = {
+ textureFormat: RG_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [8],
+ type: [INT]
+ };
+ t[RGB8] = {
+ textureFormat: RGB,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [3],
+ type: [UNSIGNED_BYTE]
+ };
+ t[SRGB8] = {
+ textureFormat: RGB,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [3],
+ type: [UNSIGNED_BYTE]
+ };
+ t[RGB565] = {
+ textureFormat: RGB,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [3, 2],
+ type: [UNSIGNED_BYTE, UNSIGNED_SHORT_5_6_5]
+ };
+ t[RGB8_SNORM] = {
+ textureFormat: RGB,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [3],
+ type: [BYTE]
+ };
+ t[R11F_G11F_B10F] = {
+ textureFormat: RGB,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [12, 6, 4],
+ type: [FLOAT, HALF_FLOAT, UNSIGNED_INT_10F_11F_11F_REV]
+ };
+ t[RGB9_E5] = {
+ textureFormat: RGB,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [12, 6, 4],
+ type: [FLOAT, HALF_FLOAT, UNSIGNED_INT_5_9_9_9_REV]
+ };
+ t[RGB16F] = {
+ textureFormat: RGB,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [12, 6],
+ type: [FLOAT, HALF_FLOAT]
+ };
+ t[RGB32F] = {
+ textureFormat: RGB,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [12],
+ type: [FLOAT]
+ };
+ t[RGB8UI] = {
+ textureFormat: RGB_INTEGER,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [3],
+ type: [UNSIGNED_BYTE]
+ };
+ t[RGB8I] = {
+ textureFormat: RGB_INTEGER,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [3],
+ type: [BYTE]
+ };
+ t[RGB16UI] = {
+ textureFormat: RGB_INTEGER,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [6],
+ type: [UNSIGNED_SHORT]
+ };
+ t[RGB16I] = {
+ textureFormat: RGB_INTEGER,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [6],
+ type: [SHORT]
+ };
+ t[RGB32UI] = {
+ textureFormat: RGB_INTEGER,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [12],
+ type: [UNSIGNED_INT]
+ };
+ t[RGB32I] = {
+ textureFormat: RGB_INTEGER,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [12],
+ type: [INT]
+ };
+ t[RGBA8] = {
+ textureFormat: RGBA,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [4],
+ type: [UNSIGNED_BYTE]
+ };
+ t[SRGB8_ALPHA8] = {
+ textureFormat: RGBA,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [4],
+ type: [UNSIGNED_BYTE]
+ };
+ t[RGBA8_SNORM] = {
+ textureFormat: RGBA,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [4],
+ type: [BYTE]
+ };
+ t[RGB5_A1] = {
+ textureFormat: RGBA,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [4, 2, 4],
+ type: [UNSIGNED_BYTE, UNSIGNED_SHORT_5_5_5_1, UNSIGNED_INT_2_10_10_10_REV]
+ };
+ t[RGBA4] = {
+ textureFormat: RGBA,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [4, 2],
+ type: [UNSIGNED_BYTE, UNSIGNED_SHORT_4_4_4_4]
+ };
+ t[RGB10_A2] = {
+ textureFormat: RGBA,
+ colorRenderable: true,
+ textureFilterable: true,
+ bytesPerElement: [4],
+ type: [UNSIGNED_INT_2_10_10_10_REV]
+ };
+ t[RGBA16F] = {
+ textureFormat: RGBA,
+ colorRenderable: false,
+ textureFilterable: true,
+ bytesPerElement: [16, 8],
+ type: [FLOAT, HALF_FLOAT]
+ };
+ t[RGBA32F] = {
+ textureFormat: RGBA,
+ colorRenderable: false,
+ textureFilterable: false,
+ bytesPerElement: [16],
+ type: [FLOAT]
+ };
+ t[RGBA8UI] = {
+ textureFormat: RGBA_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [UNSIGNED_BYTE]
+ };
+ t[RGBA8I] = {
+ textureFormat: RGBA_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [BYTE]
+ };
+ t[RGB10_A2UI] = {
+ textureFormat: RGBA_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [UNSIGNED_INT_2_10_10_10_REV]
+ };
+ t[RGBA16UI] = {
+ textureFormat: RGBA_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [8],
+ type: [UNSIGNED_SHORT]
+ };
+ t[RGBA16I] = {
+ textureFormat: RGBA_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [8],
+ type: [SHORT]
+ };
+ t[RGBA32I] = {
+ textureFormat: RGBA_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [16],
+ type: [INT]
+ };
+ t[RGBA32UI] = {
+ textureFormat: RGBA_INTEGER,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [16],
+ type: [UNSIGNED_INT]
+ }; // Sized Internal
+
+ t[DEPTH_COMPONENT16] = {
+ textureFormat: DEPTH_COMPONENT,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [2, 4],
+ type: [UNSIGNED_SHORT, UNSIGNED_INT]
+ };
+ t[DEPTH_COMPONENT24] = {
+ textureFormat: DEPTH_COMPONENT,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [UNSIGNED_INT]
+ };
+ t[DEPTH_COMPONENT32F] = {
+ textureFormat: DEPTH_COMPONENT,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [FLOAT]
+ };
+ t[DEPTH24_STENCIL8] = {
+ textureFormat: DEPTH_STENCIL,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [UNSIGNED_INT_24_8]
+ };
+ t[DEPTH32F_STENCIL8] = {
+ textureFormat: DEPTH_STENCIL,
+ colorRenderable: true,
+ textureFilterable: false,
+ bytesPerElement: [4],
+ type: [FLOAT_32_UNSIGNED_INT_24_8_REV]
+ };
+ Object.keys(t).forEach(function (internalFormat) {
+ var info = t[internalFormat];
+ info.bytesPerElementMap = {};
+ info.bytesPerElement.forEach(function (bytesPerElement, ndx) {
+ var type = info.type[ndx];
+ info.bytesPerElementMap[type] = bytesPerElement;
+ });
+ });
+ s_textureInternalFormatInfo = t;
+ }
+
+ return s_textureInternalFormatInfo[internalFormat];
+}
+/**
+ * Gets the number of bytes per element for a given internalFormat / type
+ * @param {number} internalFormat The internalFormat parameter from texImage2D etc..
+ * @param {number} type The type parameter for texImage2D etc..
+ * @return {number} the number of bytes per element for the given internalFormat, type combo
+ * @memberOf module:twgl/textures
+ */
+
+
+function getBytesPerElementForInternalFormat(internalFormat, type) {
+ var info = getTextureInternalFormatInfo(internalFormat);
+
+ if (!info) {
+ throw "unknown internal format";
+ }
+
+ var bytesPerElement = info.bytesPerElementMap[type];
+
+ if (bytesPerElement === undefined) {
+ throw "unknown internal format";
+ }
+
+ return bytesPerElement;
+}
+/**
+ * Info related to a specific texture internalFormat as returned
+ * from {@link module:twgl/textures.getFormatAndTypeForInternalFormat}.
+ *
+ * @typedef {Object} TextureFormatInfo
+ * @property {number} format Format to pass to texImage2D and related functions
+ * @property {number} type Type to pass to texImage2D and related functions
+ * @memberOf module:twgl/textures
+ */
+
+/**
+ * Gets the format and type for a given internalFormat
+ *
+ * @param {number} internalFormat The internal format
+ * @return {module:twgl/textures.TextureFormatInfo} the corresponding format and type,
+ * @memberOf module:twgl/textures
+ */
+
+
+function getFormatAndTypeForInternalFormat(internalFormat) {
+ var info = getTextureInternalFormatInfo(internalFormat);
+
+ if (!info) {
+ throw "unknown internal format";
+ }
+
+ return {
+ format: info.textureFormat,
+ type: info.type[0]
+ };
+}
+/**
+ * Returns true if value is power of 2
+ * @param {number} value number to check.
+ * @return true if value is power of 2
+ * @private
+ */
+
+
+function isPowerOf2(value) {
+ return (value & value - 1) === 0;
+}
+/**
+ * Gets whether or not we can generate mips for the given
+ * internal format.
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {number} width The width parameter from texImage2D etc..
+ * @param {number} height The height parameter from texImage2D etc..
+ * @param {number} internalFormat The internalFormat parameter from texImage2D etc..
+ * @return {boolean} true if we can generate mips
+ * @memberOf module:twgl/textures
+ */
+
+
+function canGenerateMipmap(gl, width, height, internalFormat) {
+ if (!utils.isWebGL2(gl)) {
+ return isPowerOf2(width) && isPowerOf2(height);
+ }
+
+ var info = getTextureInternalFormatInfo(internalFormat);
+
+ if (!info) {
+ throw "unknown internal format";
+ }
+
+ return info.colorRenderable && info.textureFilterable;
+}
+/**
+ * Gets whether or not we can generate mips for the given format
+ * @param {number} internalFormat The internalFormat parameter from texImage2D etc..
+ * @return {boolean} true if we can generate mips
+ * @memberOf module:twgl/textures
+ */
+
+
+function canFilter(internalFormat) {
+ var info = getTextureInternalFormatInfo(internalFormat);
+
+ if (!info) {
+ throw "unknown internal format";
+ }
+
+ return info.textureFilterable;
+}
+/**
+ * Gets the number of components for a given image format.
+ * @param {number} format the format.
+ * @return {number} the number of components for the format.
+ * @memberOf module:twgl/textures
+ */
+
+
+function getNumComponentsForFormat(format) {
+ var info = formatInfo[format];
+
+ if (!info) {
+ throw "unknown format: " + format;
+ }
+
+ return info.numColorComponents;
+}
+/**
+ * Gets the texture type for a given array type.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @return {number} the gl texture type
+ * @private
+ */
+
+
+function getTextureTypeForArrayType(gl, src, defaultType) {
+ if (isArrayBuffer(src)) {
+ return typedArrays.getGLTypeForTypedArray(src);
+ }
+
+ return defaultType || UNSIGNED_BYTE;
+}
+
+function guessDimensions(gl, target, width, height, numElements) {
+ if (numElements % 1 !== 0) {
+ throw "can't guess dimensions";
+ }
+
+ if (!width && !height) {
+ var size = Math.sqrt(numElements / (target === TEXTURE_CUBE_MAP ? 6 : 1));
+
+ if (size % 1 === 0) {
+ width = size;
+ height = size;
+ } else {
+ width = numElements;
+ height = 1;
+ }
+ } else if (!height) {
+ height = numElements / width;
+
+ if (height % 1) {
+ throw "can't guess dimensions";
+ }
+ } else if (!width) {
+ width = numElements / height;
+
+ if (width % 1) {
+ throw "can't guess dimensions";
+ }
+ }
+
+ return {
+ width: width,
+ height: height
+ };
+}
+/**
+ * Sets the default texture color.
+ *
+ * The default texture color is used when loading textures from
+ * urls. Because the URL will be loaded async we'd like to be
+ * able to use the texture immediately. By putting a 1x1 pixel
+ * color in the texture we can start using the texture before
+ * the URL has loaded.
+ *
+ * @param {number[]} color Array of 4 values in the range 0 to 1
+ * @deprecated see {@link module:twgl.setDefaults}
+ * @memberOf module:twgl/textures
+ */
+
+
+function setDefaultTextureColor(color) {
+ defaults.textureColor = new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);
+}
+
+function setDefaults(newDefaults) {
+ helper.copyExistingProperties(newDefaults, defaults);
+
+ if (newDefaults.textureColor) {
+ setDefaultTextureColor(newDefaults.textureColor);
+ }
+}
+/**
+ * A function to generate the source for a texture.
+ * @callback TextureFunc
+ * @param {WebGLRenderingContext} gl A WebGLRenderingContext
+ * @param {module:twgl.TextureOptions} options the texture options
+ * @return {*} Returns any of the things documented for `src` for {@link module:twgl.TextureOptions}.
+ * @memberOf module:twgl
+ */
+
+/**
+ * Texture options passed to most texture functions. Each function will use whatever options
+ * are appropriate for its needs. This lets you pass the same options to all functions.
+ *
+ * Note: A `TexImageSource` is defined in the WebGL spec as a `HTMLImageElement`, `HTMLVideoElement`,
+ * `HTMLCanvasElement`, `ImageBitmap`, or `ImageData`.
+ *
+ * @typedef {Object} TextureOptions
+ * @property {number} [target] the type of texture `gl.TEXTURE_2D` or `gl.TEXTURE_CUBE_MAP`. Defaults to `gl.TEXTURE_2D`.
+ * @property {number} [level] the mip level to affect. Defaults to 0. Note, if set auto will be considered false unless explicitly set to true.
+ * @property {number} [width] the width of the texture. Only used if src is an array or typed array or null.
+ * @property {number} [height] the height of a texture. Only used if src is an array or typed array or null.
+ * @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` .
+ * @property {number} [min] the min filter setting (eg. `gl.LINEAR`). Defaults to `gl.NEAREST_MIPMAP_LINEAR`
+ * or if texture is not a power of 2 on both dimensions then defaults to `gl.LINEAR`.
+ * @property {number} [mag] the mag filter setting (eg. `gl.LINEAR`). Defaults to `gl.LINEAR`
+ * @property {number} [minMag] both the min and mag filter settings.
+ * @property {number} [internalFormat] internal format for texture. Defaults to `gl.RGBA`
+ * @property {number} [format] format for texture. Defaults to `gl.RGBA`.
+ * @property {number} [type] type for texture. Defaults to `gl.UNSIGNED_BYTE` unless `src` is ArrayBufferView. If `src`
+ * is ArrayBufferView defaults to type that matches ArrayBufferView type.
+ * @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
+ * @property {number} [wrapS] Texture wrapping for S. Defaults to `gl.REPEAT` and `gl.CLAMP_TO_EDGE` for cube. If set takes precedence over `wrap`.
+ * @property {number} [wrapT] Texture wrapping for T. Defaults to `gl.REPEAT` and `gl.CLAMP_TO_EDGE` for cube. If set takes precedence over `wrap`.
+ * @property {number} [wrapR] Texture wrapping for R. Defaults to `gl.REPEAT` and `gl.CLAMP_TO_EDGE` for cube. If set takes precedence over `wrap`.
+ * @property {number} [minLod] TEXTURE_MIN_LOD setting
+ * @property {number} [maxLod] TEXTURE_MAX_LOD setting
+ * @property {number} [baseLevel] TEXTURE_BASE_LEVEL setting
+ * @property {number} [maxLevel] TEXTURE_MAX_LEVEL setting
+ * @property {number} [unpackAlignment] The `gl.UNPACK_ALIGNMENT` used when uploading an array. Defaults to 1.
+ * @property {number[]|ArrayBufferView} [color] Color to initialize this texture with if loading an image asynchronously.
+ * The default use a blue 1x1 pixel texture. You can set another default by calling `twgl.setDefaults`
+ * or you can set an individual texture's initial color by setting this property. Example: `[1, .5, .5, 1]` = pink
+ * @property {number} [premultiplyAlpha] Whether or not to premultiply alpha. Defaults to whatever the current setting is.
+ * This lets you set it once before calling `twgl.createTexture` or `twgl.createTextures` and only override
+ * the current setting for specific textures.
+ * @property {number} [flipY] Whether or not to flip the texture vertically on upload. Defaults to whatever the current setting is.
+ * This lets you set it once before calling `twgl.createTexture` or `twgl.createTextures` and only override
+ * the current setting for specific textures.
+ * @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.
+ * This lets you set it once before calling `twgl.createTexture` or `twgl.createTextures` and only override
+ * the current setting for specific textures.
+ * @property {boolean} [auto] If `undefined` or `true`, in WebGL1, texture filtering is set automatically for non-power of 2 images and
+ * mips are generated for power of 2 images. In WebGL2 mips are generated if they can be. Note: if `level` is set above
+ * then then `auto` is assumed to be `false` unless explicity set to `true`.
+ * @property {number[]} [cubeFaceOrder] The order that cube faces are pulled out of an img or set of images. The default is
+ *
+ * [gl.TEXTURE_CUBE_MAP_POSITIVE_X,
+ * gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
+ * gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
+ * gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
+ * gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
+ * gl.TEXTURE_CUBE_MAP_NEGATIVE_Z]
+ *
+ * @property {(number[]|ArrayBufferView|TexImageSource|TexImageSource[]|string|string[]|module:twgl.TextureFunc)} [src] source for texture
+ *
+ * If `string` then it's assumed to be a URL to an image. The image will be downloaded async. A usable
+ * 1x1 pixel texture will be returned immediately. The texture will be updated once the image has downloaded.
+ * If `target` is `gl.TEXTURE_CUBE_MAP` will attempt to divide image into 6 square pieces. 1x6, 6x1, 3x2, 2x3.
+ * The pieces will be uploaded in `cubeFaceOrder`
+ *
+ * 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.
+ *
+ * If `string[]` or `TexImageSource[]` and target is `gl.TEXTURE_2D_ARRAY` then each entry is a slice of the a 2d array texture
+ * and will be scaled to the specified width and height OR to the size of the first image that loads.
+ *
+ * If `TexImageSource` then it wil be used immediately to create the contents of the texture. Examples `HTMLImageElement`,
+ * `HTMLCanvasElement`, `HTMLVideoElement`.
+ *
+ * If `number[]` or `ArrayBufferView` it's assumed to be data for a texture. If `width` or `height` is
+ * not specified it is guessed as follows. First the number of elements is computed by `src.length / numComponents`
+ * where `numComponents` is derived from `format`. If `target` is `gl.TEXTURE_CUBE_MAP` then `numElements` is divided
+ * by 6. Then
+ *
+ * * If neither `width` nor `height` are specified and `sqrt(numElements)` is an integer then width and height
+ * are set to `sqrt(numElements)`. Otherwise `width = numElements` and `height = 1`.
+ *
+ * * If only one of `width` or `height` is specified then the other equals `numElements / specifiedDimension`.
+ *
+ * If `number[]` will be converted to `type`.
+ *
+ * If `src` is a function it will be called with a `WebGLRenderingContext` and these options.
+ * Whatever it returns is subject to these rules. So it can return a string url, an `HTMLElement`
+ * an array etc...
+ *
+ * If `src` is undefined then an empty texture will be created of size `width` by `height`.
+ *
+ * @property {string} [crossOrigin] What to set the crossOrigin property of images when they are downloaded.
+ * default: undefined. Also see {@link module:twgl.setDefaults}.
+ *
+ * @memberOf module:twgl
+ */
+// NOTE: While querying GL is considered slow it's not remotely as slow
+// as uploading a texture. On top of that you're unlikely to call this in
+// a perf critical loop. Even if upload a texture every frame that's unlikely
+// to be more than 1 or 2 textures a frame. In other words, the benefits of
+// making the API easy to use outweigh any supposed perf benefits
+//
+// Also note I get that having one global of these is bad practice.
+// As long as it's used correctly it means no garbage which probably
+// doesn't matter when dealing with textures but old habits die hard.
+
+
+var lastPackState = {};
+/**
+ * Saves any packing state that will be set based on the options.
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @private
+ */
+
+function savePackState(gl, options) {
+ if (options.colorspaceConversion !== undefined) {
+ lastPackState.colorspaceConversion = gl.getParameter(UNPACK_COLORSPACE_CONVERSION_WEBGL);
+ gl.pixelStorei(UNPACK_COLORSPACE_CONVERSION_WEBGL, options.colorspaceConversion);
+ }
+
+ if (options.premultiplyAlpha !== undefined) {
+ lastPackState.premultiplyAlpha = gl.getParameter(UNPACK_PREMULTIPLY_ALPHA_WEBGL);
+ gl.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL, options.premultiplyAlpha);
+ }
+
+ if (options.flipY !== undefined) {
+ lastPackState.flipY = gl.getParameter(UNPACK_FLIP_Y_WEBGL);
+ gl.pixelStorei(UNPACK_FLIP_Y_WEBGL, options.flipY);
+ }
+}
+/**
+ * Restores any packing state that was set based on the options.
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @private
+ */
+
+
+function restorePackState(gl, options) {
+ if (options.colorspaceConversion !== undefined) {
+ gl.pixelStorei(UNPACK_COLORSPACE_CONVERSION_WEBGL, lastPackState.colorspaceConversion);
+ }
+
+ if (options.premultiplyAlpha !== undefined) {
+ gl.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL, lastPackState.premultiplyAlpha);
+ }
+
+ if (options.flipY !== undefined) {
+ gl.pixelStorei(UNPACK_FLIP_Y_WEBGL, lastPackState.flipY);
+ }
+}
+/**
+ * Saves state related to data size
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @private
+ */
+
+
+function saveSkipState(gl) {
+ lastPackState.unpackAlignment = gl.getParameter(UNPACK_ALIGNMENT);
+
+ if (utils.isWebGL2(gl)) {
+ lastPackState.unpackRowLength = gl.getParameter(UNPACK_ROW_LENGTH);
+ lastPackState.unpackImageHeight = gl.getParameter(UNPACK_IMAGE_HEIGHT);
+ lastPackState.unpackSkipPixels = gl.getParameter(UNPACK_SKIP_PIXELS);
+ lastPackState.unpackSkipRows = gl.getParameter(UNPACK_SKIP_ROWS);
+ lastPackState.unpackSkipImages = gl.getParameter(UNPACK_SKIP_IMAGES);
+ }
+}
+/**
+ * Restores state related to data size
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @private
+ */
+
+
+function restoreSkipState(gl) {
+ gl.pixelStorei(UNPACK_ALIGNMENT, lastPackState.unpackAlignment);
+
+ if (utils.isWebGL2(gl)) {
+ gl.pixelStorei(UNPACK_ROW_LENGTH, lastPackState.unpackRowLength);
+ gl.pixelStorei(UNPACK_IMAGE_HEIGHT, lastPackState.unpackImageHeight);
+ gl.pixelStorei(UNPACK_SKIP_PIXELS, lastPackState.unpackSkipPixels);
+ gl.pixelStorei(UNPACK_SKIP_ROWS, lastPackState.unpackSkipRows);
+ gl.pixelStorei(UNPACK_SKIP_IMAGES, lastPackState.unpackSkipImages);
+ }
+}
+/**
+ * Sets the parameters of a texture or sampler
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {number|WebGLSampler} target texture target or sampler
+ * @param {function()} parameteriFn texParameteri or samplerParameteri fn
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @private
+ */
+
+
+function setTextureSamplerParameters(gl, target, parameteriFn, options) {
+ if (options.minMag) {
+ parameteriFn.call(gl, target, TEXTURE_MIN_FILTER, options.minMag);
+ parameteriFn.call(gl, target, TEXTURE_MAG_FILTER, options.minMag);
+ }
+
+ if (options.min) {
+ parameteriFn.call(gl, target, TEXTURE_MIN_FILTER, options.min);
+ }
+
+ if (options.mag) {
+ parameteriFn.call(gl, target, TEXTURE_MAG_FILTER, options.mag);
+ }
+
+ if (options.wrap) {
+ parameteriFn.call(gl, target, TEXTURE_WRAP_S, options.wrap);
+ parameteriFn.call(gl, target, TEXTURE_WRAP_T, options.wrap);
+
+ if (target === TEXTURE_3D || helper.isSampler(gl, target)) {
+ parameteriFn.call(gl, target, TEXTURE_WRAP_R, options.wrap);
+ }
+ }
+
+ if (options.wrapR) {
+ parameteriFn.call(gl, target, TEXTURE_WRAP_R, options.wrapR);
+ }
+
+ if (options.wrapS) {
+ parameteriFn.call(gl, target, TEXTURE_WRAP_S, options.wrapS);
+ }
+
+ if (options.wrapT) {
+ parameteriFn.call(gl, target, TEXTURE_WRAP_T, options.wrapT);
+ }
+
+ if (options.minLod) {
+ parameteriFn.call(gl, target, TEXTURE_MIN_LOD, options.minLod);
+ }
+
+ if (options.maxLod) {
+ parameteriFn.call(gl, target, TEXTURE_MAX_LOD, options.maxLod);
+ }
+
+ if (options.baseLevel) {
+ parameteriFn.call(gl, target, TEXTURE_BASE_LEVEL, options.baseLevel);
+ }
+
+ if (options.maxLevel) {
+ parameteriFn.call(gl, target, TEXTURE_MAX_LEVEL, options.maxLevel);
+ }
+}
+/**
+ * Sets the texture parameters of a texture.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @memberOf module:twgl/textures
+ */
+
+
+function setTextureParameters(gl, tex, options) {
+ var target = options.target || TEXTURE_2D;
+ gl.bindTexture(target, tex);
+ setTextureSamplerParameters(gl, target, gl.texParameteri, options);
+}
+/**
+ * Sets the sampler parameters of a sampler.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLSampler} sampler the WebGLSampler to set parameters for
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @memberOf module:twgl/textures
+ */
+
+
+function setSamplerParameters(gl, sampler, options) {
+ setTextureSamplerParameters(gl, sampler, gl.samplerParameteri, options);
+}
+/**
+ * Creates a new sampler object and sets parameters.
+ *
+ * Example:
+ *
+ * const sampler = twgl.createSampler(gl, {
+ * minMag: gl.NEAREST, // sets both TEXTURE_MIN_FILTER and TEXTURE_MAG_FILTER
+ * wrap: gl.CLAMP_TO_NEAREST, // sets both TEXTURE_WRAP_S and TEXTURE_WRAP_T and TEXTURE_WRAP_R
+ * });
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {Object.} options A object of TextureOptions one per sampler.
+ * @return {Object.} the created samplers by name
+ * @private
+ */
+
+
+function createSampler(gl, options) {
+ var sampler = gl.createSampler();
+ setSamplerParameters(gl, sampler, options);
+ return sampler;
+}
+/**
+ * Creates a multiple sampler objects and sets parameters on each.
+ *
+ * Example:
+ *
+ * const samplers = twgl.createSamplers(gl, {
+ * nearest: {
+ * minMag: gl.NEAREST,
+ * },
+ * nearestClampS: {
+ * minMag: gl.NEAREST,
+ * wrapS: gl.CLAMP_TO_NEAREST,
+ * },
+ * linear: {
+ * minMag: gl.LINEAR,
+ * },
+ * nearestClamp: {
+ * minMag: gl.NEAREST,
+ * wrap: gl.CLAMP_TO_EDGE,
+ * },
+ * linearClamp: {
+ * minMag: gl.LINEAR,
+ * wrap: gl.CLAMP_TO_EDGE,
+ * },
+ * linearClampT: {
+ * minMag: gl.LINEAR,
+ * wrapT: gl.CLAMP_TO_EDGE,
+ * },
+ * });
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set on the sampler
+ * @private
+ */
+
+
+function createSamplers(gl, samplerOptions) {
+ var samplers = {};
+ Object.keys(samplerOptions).forEach(function (name) {
+ samplers[name] = createSampler(gl, samplerOptions[name]);
+ });
+ return samplers;
+}
+/**
+ * Makes a 1x1 pixel
+ * If no color is passed in uses the default color which can be set by calling `setDefaultTextureColor`.
+ * @param {(number[]|ArrayBufferView)} [color] The color using 0-1 values
+ * @return {Uint8Array} Unit8Array with color.
+ * @private
+ */
+
+
+function make1Pixel(color) {
+ color = color || defaults.textureColor;
+
+ if (isArrayBuffer(color)) {
+ return color;
+ }
+
+ return new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);
+}
+/**
+ * Sets filtering or generates mips for texture based on width or height
+ * If width or height is not passed in uses `options.width` and//or `options.height`
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @param {number} [width] width of texture
+ * @param {number} [height] height of texture
+ * @param {number} [internalFormat] The internalFormat parameter from texImage2D etc..
+ * @memberOf module:twgl/textures
+ */
+
+
+function setTextureFilteringForSize(gl, tex, options, width, height, internalFormat) {
+ options = options || defaults.textureOptions;
+ internalFormat = internalFormat || RGBA;
+ var target = options.target || TEXTURE_2D;
+ width = width || options.width;
+ height = height || options.height;
+ gl.bindTexture(target, tex);
+
+ if (canGenerateMipmap(gl, width, height, internalFormat)) {
+ gl.generateMipmap(target);
+ } else {
+ var filtering = canFilter(internalFormat) ? LINEAR : NEAREST;
+ gl.texParameteri(target, TEXTURE_MIN_FILTER, filtering);
+ gl.texParameteri(target, TEXTURE_MAG_FILTER, filtering);
+ gl.texParameteri(target, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
+ gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
+ }
+}
+
+function shouldAutomaticallySetTextureFilteringForSize(options) {
+ return options.auto === true || options.auto === undefined && options.level === undefined;
+}
+/**
+ * Gets an array of cubemap face enums
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @return {number[]} cubemap face enums
+ * @private
+ */
+
+
+function getCubeFaceOrder(gl, options) {
+ options = options || {};
+ return options.cubeFaceOrder || [TEXTURE_CUBE_MAP_POSITIVE_X, TEXTURE_CUBE_MAP_NEGATIVE_X, TEXTURE_CUBE_MAP_POSITIVE_Y, TEXTURE_CUBE_MAP_NEGATIVE_Y, TEXTURE_CUBE_MAP_POSITIVE_Z, TEXTURE_CUBE_MAP_NEGATIVE_Z];
+}
+/**
+ * @typedef {Object} FaceInfo
+ * @property {number} face gl enum for texImage2D
+ * @property {number} ndx face index (0 - 5) into source data
+ * @ignore
+ */
+
+/**
+ * Gets an array of FaceInfos
+ * There's a bug in some NVidia drivers that will crash the driver if
+ * `gl.TEXTURE_CUBE_MAP_POSITIVE_X` is not uploaded first. So, we take
+ * the user's desired order from his faces to WebGL and make sure we
+ * do the faces in WebGL order
+ *
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
+ * @return {FaceInfo[]} cubemap face infos. Arguably the `face` property of each element is redundant but
+ * it's needed internally to sort the array of `ndx` properties by `face`.
+ * @private
+ */
+
+
+function getCubeFacesWithNdx(gl, options) {
+ var faces = getCubeFaceOrder(gl, options); // work around bug in NVidia drivers. We have to upload the first face first else the driver crashes :(
+
+ var facesWithNdx = faces.map(function (face, ndx) {
+ return {
+ face: face,
+ ndx: ndx
+ };
+ });
+ facesWithNdx.sort(function (a, b) {
+ return a.face - b.face;
+ });
+ return facesWithNdx;
+}
+/**
+ * Set a texture from the contents of an element. Will also set
+ * texture filtering or generate mips based on the dimensions of the element
+ * unless `options.auto === false`. If `target === gl.TEXTURE_CUBE_MAP` will
+ * attempt to slice image into 1x6, 2x3, 3x2, or 6x1 images, one for each face.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {HTMLElement} element a canvas, img, or video element.
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @memberOf module:twgl/textures
+ * @kind function
+ */
+
+
+function setTextureFromElement(gl, tex, element, options) {
+ options = options || defaults.textureOptions;
+ var target = options.target || TEXTURE_2D;
+ var level = options.level || 0;
+ var width = element.width;
+ var height = element.height;
+ var internalFormat = options.internalFormat || options.format || RGBA;
+ var formatType = getFormatAndTypeForInternalFormat(internalFormat);
+ var format = options.format || formatType.format;
+ var type = options.type || formatType.type;
+ savePackState(gl, options);
+ gl.bindTexture(target, tex);
+
+ if (target === TEXTURE_CUBE_MAP) {
+ // guess the parts
+ var imgWidth = element.width;
+ var imgHeight = element.height;
+ var size;
+ var slices;
+
+ if (imgWidth / 6 === imgHeight) {
+ // It's 6x1
+ size = imgHeight;
+ slices = [0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0];
+ } else if (imgHeight / 6 === imgWidth) {
+ // It's 1x6
+ size = imgWidth;
+ slices = [0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5];
+ } else if (imgWidth / 3 === imgHeight / 2) {
+ // It's 3x2
+ size = imgWidth / 3;
+ slices = [0, 0, 1, 0, 2, 0, 0, 1, 1, 1, 2, 1];
+ } else if (imgWidth / 2 === imgHeight / 3) {
+ // It's 2x3
+ size = imgWidth / 2;
+ slices = [0, 0, 1, 0, 0, 1, 1, 1, 0, 2, 1, 2];
+ } else {
+ throw "can't figure out cube map from element: " + (element.src ? element.src : element.nodeName);
+ }
+
+ var ctx = getShared2DContext();
+
+ if (ctx) {
+ ctx.canvas.width = size;
+ ctx.canvas.height = size;
+ width = size;
+ height = size;
+ getCubeFacesWithNdx(gl, options).forEach(function (f) {
+ var xOffset = slices[f.ndx * 2 + 0] * size;
+ var yOffset = slices[f.ndx * 2 + 1] * size;
+ ctx.drawImage(element, xOffset, yOffset, size, size, 0, 0, size, size);
+ gl.texImage2D(f.face, level, internalFormat, format, type, ctx.canvas);
+ }); // Free up the canvas memory
+
+ ctx.canvas.width = 1;
+ ctx.canvas.height = 1;
+ } else if (typeof createImageBitmap !== 'undefined') {
+ // NOTE: It seems like we should prefer ImageBitmap because unlike canvas it's
+ // note lossy? (alpha is not premultiplied? although I'm not sure what
+ width = size;
+ height = size;
+ getCubeFacesWithNdx(gl, options).forEach(function (f) {
+ var xOffset = slices[f.ndx * 2 + 0] * size;
+ var yOffset = slices[f.ndx * 2 + 1] * size; // We can't easily use a default texture color here as it would have to match
+ // the type across all faces where as with a 2D one there's only one face
+ // so we're replacing everything all at once. It also has to be the correct size.
+ // On the other hand we need all faces to be the same size so as one face loads
+ // the rest match else the texture will be un-renderable.
+
+ gl.texImage2D(f.face, level, internalFormat, size, size, 0, format, type, null);
+ createImageBitmap(element, xOffset, yOffset, size, size, {
+ premultiplyAlpha: 'none',
+ colorSpaceConversion: 'none'
+ }).then(function (imageBitmap) {
+ savePackState(gl, options);
+ gl.bindTexture(target, tex);
+ gl.texImage2D(f.face, level, internalFormat, format, type, imageBitmap);
+ restorePackState(gl, options);
+
+ if (shouldAutomaticallySetTextureFilteringForSize(options)) {
+ setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
+ }
+ });
+ });
+ }
+ } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
+ var smallest = Math.min(element.width, element.height);
+ var largest = Math.max(element.width, element.height);
+ var depth = largest / smallest;
+
+ if (depth % 1 !== 0) {
+ throw "can not compute 3D dimensions of element";
+ }
+
+ var xMult = element.width === largest ? 1 : 0;
+ var yMult = element.height === largest ? 1 : 0;
+ saveSkipState(gl);
+ gl.pixelStorei(UNPACK_ALIGNMENT, 1);
+ gl.pixelStorei(UNPACK_ROW_LENGTH, element.width);
+ gl.pixelStorei(UNPACK_IMAGE_HEIGHT, 0);
+ gl.pixelStorei(UNPACK_SKIP_IMAGES, 0);
+ gl.texImage3D(target, level, internalFormat, smallest, smallest, smallest, 0, format, type, null);
+
+ for (var d = 0; d < depth; ++d) {
+ var srcX = d * smallest * xMult;
+ var srcY = d * smallest * yMult;
+ gl.pixelStorei(UNPACK_SKIP_PIXELS, srcX);
+ gl.pixelStorei(UNPACK_SKIP_ROWS, srcY);
+ gl.texSubImage3D(target, level, 0, 0, d, smallest, smallest, 1, format, type, element);
+ }
+
+ restoreSkipState(gl);
+ } else {
+ gl.texImage2D(target, level, internalFormat, format, type, element);
+ }
+
+ restorePackState(gl, options);
+
+ if (shouldAutomaticallySetTextureFilteringForSize(options)) {
+ setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
+ }
+
+ setTextureParameters(gl, tex, options);
+}
+
+function noop() {}
+/**
+ * Checks whether the url's origin is the same so that we can set the `crossOrigin`
+ * @param {string} url url to image
+ * @returns {boolean} true if the window's origin is the same as image's url
+ * @private
+ */
+
+
+function urlIsSameOrigin(url) {
+ if (typeof document !== 'undefined') {
+ // for IE really
+ var a = document.createElement('a');
+ a.href = url;
+ return a.hostname === location.hostname && a.port === location.port && a.protocol === location.protocol;
+ } else {
+ var localOrigin = new URL(location.href).origin;
+ var urlOrigin = new URL(url, location.href).origin;
+ return urlOrigin === localOrigin;
+ }
+}
+
+function setToAnonymousIfUndefinedAndURLIsNotSameOrigin(url, crossOrigin) {
+ return crossOrigin === undefined && !urlIsSameOrigin(url) ? 'anonymous' : crossOrigin;
+}
+/**
+ * Loads an image
+ * @param {string} url url to image
+ * @param {string} crossOrigin
+ * @param {function(err, img)} [callback] a callback that's passed an error and the image. The error will be non-null
+ * if there was an error
+ * @return {HTMLImageElement} the image being loaded.
+ * @private
+ */
+
+
+function loadImage(url, crossOrigin, callback) {
+ callback = callback || noop;
+ var img;
+ crossOrigin = crossOrigin !== undefined ? crossOrigin : defaults.crossOrigin;
+ crossOrigin = setToAnonymousIfUndefinedAndURLIsNotSameOrigin(url, crossOrigin);
+
+ if (typeof Image !== 'undefined') {
+ img = new Image();
+
+ if (crossOrigin !== undefined) {
+ img.crossOrigin = crossOrigin;
+ }
+
+ var clearEventHandlers = function clearEventHandlers() {
+ img.removeEventListener('error', onError); // eslint-disable-line
+
+ img.removeEventListener('load', onLoad); // eslint-disable-line
+
+ img = null;
+ };
+
+ var onError = function onError() {
+ var msg = "couldn't load image: " + url;
+ helper.error(msg);
+ callback(msg, img);
+ clearEventHandlers();
+ };
+
+ var onLoad = function onLoad() {
+ callback(null, img);
+ clearEventHandlers();
+ };
+
+ img.addEventListener('error', onError);
+ img.addEventListener('load', onLoad);
+ img.src = url;
+ return img;
+ } else if (typeof ImageBitmap !== 'undefined') {
+ var err;
+ var bm;
+
+ var cb = function cb() {
+ callback(err, bm);
+ };
+
+ var options = {};
+
+ if (crossOrigin) {
+ options.mode = 'cors'; // TODO: not sure how to translate image.crossOrigin
+ }
+
+ fetch(url, options).then(function (response) {
+ if (!response.ok) {
+ throw response;
+ }
+
+ return response.blob();
+ }).then(function (blob) {
+ return createImageBitmap(blob, {
+ premultiplyAlpha: 'none',
+ colorSpaceConversion: 'none'
+ });
+ }).then(function (bitmap) {
+ // not sure if this works. We don't want
+ // to catch the user's error. So, call
+ // the callback in a timeout so we're
+ // not in this scope inside the promise.
+ bm = bitmap;
+ setTimeout(cb);
+ })["catch"](function (e) {
+ err = e;
+ setTimeout(cb);
+ });
+ img = null;
+ }
+
+ return img;
+}
+/**
+ * check if object is a TexImageSource
+ *
+ * @param {Object} obj Object to test
+ * @return {boolean} true if object is a TexImageSource
+ * @private
+ */
+
+
+function isTexImageSource(obj) {
+ return typeof ImageBitmap !== 'undefined' && obj instanceof ImageBitmap || typeof ImageData !== 'undefined' && obj instanceof ImageData || typeof HTMLElement !== 'undefined' && obj instanceof HTMLElement;
+}
+/**
+ * if obj is an TexImageSource then just
+ * uses it otherwise if obj is a string
+ * then load it first.
+ *
+ * @param {string|TexImageSource} obj
+ * @param {string} crossOrigin
+ * @param {function(err, img)} [callback] a callback that's passed an error and the image. The error will be non-null
+ * if there was an error
+ * @private
+ */
+
+
+function loadAndUseImage(obj, crossOrigin, callback) {
+ if (isTexImageSource(obj)) {
+ setTimeout(function () {
+ callback(null, obj);
+ });
+ return obj;
+ }
+
+ return loadImage(obj, crossOrigin, callback);
+}
+/**
+ * Sets a texture to a 1x1 pixel color. If `options.color === false` is nothing happens. If it's not set
+ * the default texture color is used which can be set by calling `setDefaultTextureColor`.
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
+ * This is often the same options you passed in when you created the texture.
+ * @memberOf module:twgl/textures
+ */
+
+
+function setTextureTo1PixelColor(gl, tex, options) {
+ options = options || defaults.textureOptions;
+ var target = options.target || TEXTURE_2D;
+ gl.bindTexture(target, tex);
+
+ if (options.color === false) {
+ return;
+ } // Assume it's a URL
+ // Put 1x1 pixels in texture. That makes it renderable immediately regardless of filtering.
+
+
+ var color = make1Pixel(options.color);
+
+ if (target === TEXTURE_CUBE_MAP) {
+ for (var ii = 0; ii < 6; ++ii) {
+ gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, 0, RGBA, 1, 1, 0, RGBA, UNSIGNED_BYTE, color);
+ }
+ } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
+ gl.texImage3D(target, 0, RGBA, 1, 1, 1, 0, RGBA, UNSIGNED_BYTE, color);
+ } else {
+ gl.texImage2D(target, 0, RGBA, 1, 1, 0, RGBA, UNSIGNED_BYTE, color);
+ }
+}
+/**
+ * The src image(s) used to create a texture.
+ *
+ * When you call {@link module:twgl.createTexture} or {@link module:twgl.createTextures}
+ * you can pass in urls for images to load into the textures. If it's a single url
+ * then this will be a single HTMLImageElement. If it's an array of urls used for a cubemap
+ * this will be a corresponding array of images for the cubemap.
+ *
+ * @typedef {HTMLImageElement|HTMLImageElement[]} TextureSrc
+ * @memberOf module:twgl
+ */
+
+/**
+ * A callback for when an image finished downloading and been uploaded into a texture
+ * @callback TextureReadyCallback
+ * @param {*} err If truthy there was an error.
+ * @param {WebGLTexture} texture the texture.
+ * @param {module:twgl.TextureSrc} source image(s) used to as the src for the texture
+ * @memberOf module:twgl
+ */
+
+/**
+ * A callback for when all images have finished downloading and been uploaded into their respective textures
+ * @callback TexturesReadyCallback
+ * @param {*} err If truthy there was an error.
+ * @param {Object.} textures the created textures by name. Same as returned by {@link module:twgl.createTextures}.
+ * @param {Object.