Browse Source

fallback for non pot textures for webGL 1

Trevor Baron 6 years ago
parent
commit
8685be7bee

+ 9 - 0
src/Materials/Textures/Loaders/basisTextureLoader.ts

@@ -5,6 +5,9 @@ import { IInternalTextureLoader } from "../../../Materials/Textures/internalText
 import { _TimeToken } from "../../../Instrumentation/timeToken";
 import { _DepthCullingState, _StencilState, _AlphaState } from "../../../States/index";
 import { BasisTools } from "../../../Misc/basis";
+import { Texture } from '../texture';
+import { Tools } from '../../../Misc/tools';
+import { Scalar } from '../../../Maths/math.scalar';
 
 /**
  * Loader for .basis file format
@@ -100,7 +103,13 @@ export class _BasisTextureLoader implements IInternalTextureLoader {
                         source.getEngine()._bindTextureDirectly(source.getEngine()._gl.TEXTURE_2D, texture, true);
                     });
                 }else {
+                    texture.width = fileInfo.width;
+                    texture.height = fileInfo.height;
                     texture.getEngine()._uploadCompressedDataToTextureDirectly(texture, BasisTools.GetInternalFormatFromBasisFormat(format!), fileInfo.width, fileInfo.height, transcodeResult.pixels, 0, 0);
+                    if(texture.getEngine().webGLVersion < 2 && (Scalar.Log2(texture.width) % 1 !== 0 || Scalar.Log2(texture.height) % 1 !== 0)){
+                        Tools.Warn("Loaded .basis texture width and height are not a power of two. Texture wrapping will be set to Texture.CLAMP_ADDRESSMODE as other modes are not supported with non power of two dimensions in webGL 1.");
+                        texture._cachedWrapU = Texture.CLAMP_ADDRESSMODE;
+                    }
                 }
             });
         });

+ 19 - 2
src/Materials/Textures/texture.ts

@@ -289,9 +289,26 @@ export class Texture extends BaseTexture {
         scene.getEngine().onBeforeTextureInitObservable.notifyObservers(this);
 
         let load = () => {
-            if (this._texture && this._texture._invertVScale) {
-                this.vScale = -1;
+            if(this._texture){
+                if (this._texture._invertVScale) {
+                    this.vScale = -1;
+                }
+                
+                // Update texutre to match internal texture's wrapping
+                if(this._texture._cachedWrapU !== null){
+                    this.wrapU = this._texture._cachedWrapU;
+                    this._texture._cachedWrapU = null;
+                }
+                if(this._texture._cachedWrapV !== null){
+                    this.wrapV = this._texture._cachedWrapV;
+                    this._texture._cachedWrapV = null;
+                }
+                if(this._texture._cachedWrapR !== null){
+                    this.wrapR = this._texture._cachedWrapR;
+                    this._texture._cachedWrapR = null;
+                }
             }
+            
             if (this.onLoadObservable.hasObservers()) {
                 this.onLoadObservable.notifyObservers(this);
             }