Преглед изворни кода

New ```Mesh.forceSamplingMode``` function

David Catuhe пре 11 година
родитељ
комит
a89bf35e14

+ 4 - 0
Babylon/Materials/textures/babylon.texture.js

@@ -65,6 +65,10 @@ var BABYLON;
             t.z += 0.5;
         };
 
+        Texture.prototype.forceSamplingMode = function (mode) {
+            this.getScene().getEngine().setSamplingMode(this._texture, mode);
+        };
+
         Texture.prototype.getTextureMatrix = function () {
             if (this.uOffset === this._cachedUOffset && this.vOffset === this._cachedVOffset && this.uScale === this._cachedUScale && this.vScale === this._cachedVScale && this.uAng === this._cachedUAng && this.vAng === this._cachedVAng && this.wAng === this._cachedWAng) {
                 return this._cachedTextureMatrix;

+ 4 - 0
Babylon/Materials/textures/babylon.texture.ts

@@ -95,6 +95,10 @@
             t.z += 0.5;
         }
 
+        public forceSamplingMode(mode: number): void {
+            this.getScene().getEngine().setSamplingMode(this._texture, mode);
+        }
+
         public getTextureMatrix(): Matrix {
             if (
                 this.uOffset === this._cachedUOffset &&

+ 22 - 0
Babylon/babylon.engine.js

@@ -843,6 +843,28 @@
             this._cachedEffectForVertexBuffers = null;
         };
 
+        Engine.prototype.setSamplingMode = function (texture, samplingMode) {
+            var gl = this._gl;
+
+            gl.bindTexture(gl.TEXTURE_2D, texture);
+
+            var magFilter = gl.NEAREST;
+            var minFilter = gl.NEAREST;
+
+            if (samplingMode === BABYLON.Texture.BILINEAR_SAMPLINGMODE) {
+                magFilter = gl.LINEAR;
+                minFilter = gl.LINEAR;
+            } else if (samplingMode === BABYLON.Texture.TRILINEAR_SAMPLINGMODE) {
+                magFilter = gl.LINEAR;
+                minFilter = gl.LINEAR_MIPMAP_LINEAR;
+            }
+
+            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);
+            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
+
+            gl.bindTexture(gl.TEXTURE_2D, null);
+        };
+
         Engine.prototype.createTexture = function (url, noMipmap, invertY, scene) {
             var _this = this;
             var texture = this._gl.createTexture();

+ 23 - 1
Babylon/babylon.engine.ts

@@ -606,7 +606,7 @@
             for (var index = 0; index < 4; index++) {
                 var offsetLocation = offsetLocations[index];
                 this._gl.enableVertexAttribArray(offsetLocation);
-                this._gl.vertexAttribPointer(offsetLocation, 4, this._gl.FLOAT, false, 64, index * 16);                
+                this._gl.vertexAttribPointer(offsetLocation, 4, this._gl.FLOAT, false, 64, index * 16);
                 this._caps.instancedArrays.vertexAttribDivisorANGLE(offsetLocation, 1);
             }
         }
@@ -877,6 +877,28 @@
             this._cachedEffectForVertexBuffers = null;
         }
 
+        public setSamplingMode(texture: WebGLTexture, samplingMode: number): void {
+            var gl = this._gl;
+
+            gl.bindTexture(gl.TEXTURE_2D, texture);
+
+            var magFilter = gl.NEAREST;
+            var minFilter = gl.NEAREST;
+
+            if (samplingMode === BABYLON.Texture.BILINEAR_SAMPLINGMODE) {
+                magFilter = gl.LINEAR;
+                minFilter = gl.LINEAR;
+            } else if (samplingMode === BABYLON.Texture.TRILINEAR_SAMPLINGMODE) {
+                magFilter = gl.LINEAR;
+                minFilter = gl.LINEAR_MIPMAP_LINEAR;
+            }
+
+            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);
+            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
+
+            gl.bindTexture(gl.TEXTURE_2D, null);
+        }
+
         public createTexture(url: string, noMipmap: boolean, invertY: boolean, scene: Scene): WebGLTexture {
             var texture = this._gl.createTexture();
 

Разлика између датотеке није приказан због своје велике величине
+ 5 - 5
babylon.1.12-beta.js