src/render/Texture.js
function (gl, image, wrapMode) {

            if (!gl) {
                throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "Texture", "constructor",
                    "missingGlContext"));
            }

            if (!image) {
                throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "Texture", "constructor",
                    "missingImage"));
            }

            if (!wrapMode) {
                wrapMode = gl.CLAMP_TO_EDGE;
            }

            var textureId = gl.createTexture(),
                isPowerOfTwo = (WWMath.isPowerOfTwo(image.width) && WWMath.isPowerOfTwo(image.height));

            this.originalImageWidth = image.width;
            this.originalImageHeight = image.height;

            if (wrapMode === gl.REPEAT && !isPowerOfTwo) {
                image = this.resizeImage(image);
                isPowerOfTwo = true;
            }

            this.imageWidth = image.width;
            this.imageHeight = image.height;
            this.size = image.width * image.height * 4;

            gl.bindTexture(gl.TEXTURE_2D, textureId);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER,
                isPowerOfTwo ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);

            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapMode);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapMode);

            gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);
            gl.texImage2D(gl.TEXTURE_2D, 0,
                gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
            gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);

            if (isPowerOfTwo) {
                gl.generateMipmap(gl.TEXTURE_2D);
            }

            this.textureId = textureId;

            /**
             * The time at which this texture was created.
             * @type {Date}
             */
            this.creationTime = new Date();

            // Internal use only. Intentionally not documented.
            this.texParameters = {};

            // Internal use only. Intentionally not documented.
            // https://www.khronos.org/registry/webgl/extensions/EXT_texture_filter_anisotrop
            this.anisotropicFilterExt = (gl.getExtension("EXT_texture_filter_anisotropic") ||
                                         gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic"));
        }
function (gl, image, wrapMode) {

            if (!gl) {
                throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "Texture", "constructor",
                    "missingGlContext"));
            }

            if (!image) {
                throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "Texture", "constructor",
                    "missingImage"));
            }

            if (!wrapMode) {
                wrapMode = gl.CLAMP_TO_EDGE;
            }

            var textureId = gl.createTexture(),
                isPowerOfTwo = (WWMath.isPowerOfTwo(image.width) && WWMath.isPowerOfTwo(image.height));

            this.originalImageWidth = image.width;
            this.originalImageHeight = image.height;

            if (wrapMode === gl.REPEAT && !isPowerOfTwo) {
                image = this.resizeImage(image);
                isPowerOfTwo = true;
            }

            this.imageWidth = image.width;
            this.imageHeight = image.height;
            this.size = image.width * image.height * 4;

            gl.bindTexture(gl.TEXTURE_2D, textureId);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER,
                isPowerOfTwo ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);

            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapMode);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapMode);

            gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);
            gl.texImage2D(gl.TEXTURE_2D, 0,
                gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
            gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);

            if (isPowerOfTwo) {
                gl.generateMipmap(gl.TEXTURE_2D);
            }

            this.textureId = textureId;

            /**
             * The time at which this texture was created.
             * @type {Date}
             */
            this.creationTime = new Date();

            // Internal use only. Intentionally not documented.
            this.texParameters = {};

            // Internal use only. Intentionally not documented.
            // https://www.khronos.org/registry/webgl/extensions/EXT_texture_filter_anisotrop
            this.anisotropicFilterExt = (gl.getExtension("EXT_texture_filter_anisotropic") ||
                                         gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic"));
        }
function ( gl , image , wrapMode ) { if ( ! gl ) { throw new ArgumentError ( Logger . logMessage ( Logger . LEVEL_SEVERE , "Texture" , "constructor" , "missingGlContext" ) ) ; } if ( ! image ) { throw new ArgumentError ( Logger . logMessage ( Logger . LEVEL_SEVERE , "Texture" , "constructor" , "missingImage" ) ) ; } if ( ! wrapMode ) { wrapMode = gl . CLAMP_TO_EDGE ; } var textureId = gl . createTexture ( ) , isPowerOfTwo = ( WWMath . isPowerOfTwo ( image . width ) && WWMath . isPowerOfTwo ( image . height ) ) ; this . originalImageWidth = image . width ; this . originalImageHeight = image . height ; if ( wrapMode === gl . REPEAT && ! isPowerOfTwo ) { image = this . resizeImage ( image ) ; isPowerOfTwo = true ; } this . imageWidth = image . width ; this . imageHeight = image . height ; this . size = image . width * image . height * 4 ; gl . bindTexture ( gl . TEXTURE_2D , textureId ) ; gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , isPowerOfTwo ? gl . LINEAR_MIPMAP_LINEAR : gl . LINEAR ) ; gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , wrapMode ) ; gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_T , wrapMode ) ; gl . pixelStorei ( gl . UNPACK_PREMULTIPLY_ALPHA_WEBGL , 1 ) ; gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , gl . RGBA , gl . UNSIGNED_BYTE , image ) ; gl . pixelStorei ( gl . UNPACK_PREMULTIPLY_ALPHA_WEBGL , 0 ) ; if ( isPowerOfTwo ) { gl . generateMipmap ( gl . TEXTURE_2D ) ; } this . textureId = textureId ; /**
             * The time at which this texture was created.
             * @type {Date}
             */ this . creationTime = new Date ( ) ; // Internal use only. Intentionally not documented. this . texParameters = { } ; // Internal use only. Intentionally not documented. // https://www.khronos.org/registry/webgl/extensions/EXT_texture_filter_anisotrop this . anisotropicFilterExt = ( gl . getExtension ( "EXT_texture_filter_anisotropic" ) || gl . getExtension ( "WEBKIT_EXT_texture_filter_anisotropic" ) ) ; }
Constructs a texture for a specified image.
@alias Texture
@constructor
@classdesc Represents a WebGL texture. Applications typically do not interact with this class.
@param {WebGLRenderingContext} gl The current WebGL rendering context.
@param {Image} image The texture's image.
@param {GLenum} wrapMode Optional. Specifies the wrap mode of the texture. Defaults to gl.CLAMP_TO_EDGE
@throws {ArgumentError} If the specified WebGL context or image is null or undefined.
Constructs a texture for a specified image .