Prechádzať zdrojové kódy

Support non-power-of-2 DynamicTexture height/width

To avoid forcing height and width to powers of two:

- generateMips = false
- samplingMode = NEAREST_SAMPLINGMODE
Keith Dahlby 9 rokov pred
rodič
commit
d444697bce

+ 1 - 0
dist/preview release/what's new.md

@@ -83,3 +83,4 @@
     - `Engine.bindMultiBuffers` is now `Engine.bindBuffers` and strongly typed `{ [key: string]: VertexBuffer; }` of buffers ([benaadams](https://github.com/benaadams))
     - `Engine.createDynamicVertexBuffer` takes vertices rather than capacity, creating and initalizing in one gpu instruction ([benaadams](https://github.com/benaadams)) 
     - Internally new `Engine.bindBuffer` is used rather than `gl.bindBuffer` which only binds when the bound buffer is changing ([benaadams](https://github.com/benaadams)) 
+    - `DynamicTexture` no longer forces height/width to exponents of 2 if MIP maps are disabled and sampling mode is nearest  ([dahlbyk](https://github.com/dahlbyk))

+ 4 - 3
src/Materials/Textures/babylon.dynamicTexture.js

@@ -14,17 +14,18 @@ var BABYLON;
             this.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
             this._generateMipMaps = generateMipMaps;
+            var forceExponentOfTwo = generateMipMaps || samplingMode !== BABYLON.Texture.NEAREST_SAMPLINGMODE;
             if (options.getContext) {
                 this._canvas = options;
-                this._texture = scene.getEngine().createDynamicTexture(options.width, options.height, generateMipMaps, samplingMode);
+                this._texture = scene.getEngine().createDynamicTexture(options.width, options.height, generateMipMaps, samplingMode, forceExponentOfTwo);
             }
             else {
                 this._canvas = document.createElement("canvas");
                 if (options.width) {
-                    this._texture = scene.getEngine().createDynamicTexture(options.width, options.height, generateMipMaps, samplingMode);
+                    this._texture = scene.getEngine().createDynamicTexture(options.width, options.height, generateMipMaps, samplingMode, forceExponentOfTwo);
                 }
                 else {
-                    this._texture = scene.getEngine().createDynamicTexture(options, options, generateMipMaps, samplingMode);
+                    this._texture = scene.getEngine().createDynamicTexture(options, options, generateMipMaps, samplingMode, forceExponentOfTwo);
                 }
             }
             var textureSize = this.getSize();

+ 5 - 3
src/Materials/Textures/babylon.dynamicTexture.ts

@@ -14,16 +14,18 @@
 
             this._generateMipMaps = generateMipMaps;
 
+            var forceExponentOfTwo = generateMipMaps || samplingMode !== Texture.NEAREST_SAMPLINGMODE;
+
             if (options.getContext) {
                 this._canvas = options;
-                this._texture = scene.getEngine().createDynamicTexture(options.width, options.height, generateMipMaps, samplingMode);
+                this._texture = scene.getEngine().createDynamicTexture(options.width, options.height, generateMipMaps, samplingMode, forceExponentOfTwo);
             } else {
                 this._canvas = document.createElement("canvas");
 
                 if (options.width) {
-                    this._texture = scene.getEngine().createDynamicTexture(options.width, options.height, generateMipMaps, samplingMode);
+                    this._texture = scene.getEngine().createDynamicTexture(options.width, options.height, generateMipMaps, samplingMode, forceExponentOfTwo);
                 } else {
-                    this._texture = scene.getEngine().createDynamicTexture(options, options, generateMipMaps, samplingMode);
+                    this._texture = scene.getEngine().createDynamicTexture(options, options, generateMipMaps, samplingMode, forceExponentOfTwo);
                 }
             }