Advertisement
shubhamgoyal

Untitled

Mar 21st, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.      * Necessary to upload the actual image data to the GPU. Without this the texture will be blank. Called automatically
  3.      * in most cases due to loading and caching APIs. Flagging an image source with `_invalid = true` will trigger this
  4.      * next time the image is rendered.
  5.      * @param {WebGLRenderingContext} gl
  6.      * @param {Image | Canvas} image The image data to be uploaded
  7.      * @protected
  8.      */
  9.     p._updateTextureImageData = function (gl, image) {
  10.         // the bitwise & is intentional, cheap exponent 2 check
  11.         var isNPOT = (image.width & image.width-1) || (image.height & image.height-1);
  12.         var texture = this._textureDictionary[image._storeID];
  13.  
  14.         gl.activeTexture(gl.TEXTURE0 + texture._activeIndex);
  15.         gl.bindTexture(gl.TEXTURE_2D, texture);
  16.  
  17.         texture.isPOT = !isNPOT;
  18.         this.setTextureParams(gl, texture.isPOT);
  19.  
  20.         try {
  21.             gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  22.         } catch(e) {
  23.             var errString = "\nAn error has occurred. This is most likely due to security restrictions on WebGL images with local or cross-domain origins";
  24.             if(console.error) {
  25.                 //TODO: LM: I recommend putting this into a log function internally, since you do it so often, and each is implemented differently.
  26.                 console.error(errString);
  27.                 console.error(e);
  28.             } else if (console) {
  29.                 console.log(errString);
  30.                 console.log(e);
  31.             }
  32.         }
  33.  
  34.         image._invalid = false;
  35.  
  36.         texture._w = image.width;
  37.         texture._h = image.height;
  38.  
  39.         if (this.vocalDebug) {
  40.             if (isNPOT) {
  41.                 console.warn("NPOT(Non Power of Two) Texture: "+ image.src);
  42.             }
  43.             if (image.width > gl.MAX_TEXTURE_SIZE || image.height > gl.MAX_TEXTURE_SIZE){
  44.                 console && console.error("Oversized Texture: "+ image.width+"x"+image.height +" vs "+ gl.MAX_TEXTURE_SIZE +"max");
  45.             }
  46.         }
  47.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement