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

Fixed texture arrays issue

David Catuhe пре 9 година
родитељ
комит
11629cc1e8

Разлика између датотеке није приказан због своје велике величине
+ 18 - 18
dist/preview release/babylon.core.js


Разлика између датотеке није приказан због своје велике величине
+ 3647 - 3645
dist/preview release/babylon.d.ts


Разлика између датотеке није приказан због своје велике величине
+ 37 - 36
dist/preview release/babylon.js


+ 25 - 6
dist/preview release/babylon.max.js

@@ -7768,10 +7768,14 @@ var BABYLON;
                 this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);
                 this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);
             }
             }
         };
         };
-        Engine.prototype.setTexture = function (channel, texture) {
+        Engine.prototype.setTexture = function (channel, uniform, texture) {
             if (channel < 0) {
             if (channel < 0) {
                 return;
                 return;
             }
             }
+            this._gl.uniform1i(uniform, channel);
+            this._setTexture(channel, texture);
+        };
+        Engine.prototype._setTexture = function (channel, texture) {
             // Not ready?
             // Not ready?
             if (!texture || !texture.isReady()) {
             if (!texture || !texture.isReady()) {
                 if (this._activeTexturesCache[channel] != null) {
                 if (this._activeTexturesCache[channel] != null) {
@@ -7843,12 +7847,19 @@ var BABYLON;
                 this._setAnisotropicLevel(this._gl.TEXTURE_2D, texture);
                 this._setAnisotropicLevel(this._gl.TEXTURE_2D, texture);
             }
             }
         };
         };
-        Engine.prototype.setTextureArray = function (channel, textures) {
+        Engine.prototype.setTextureArray = function (channel, uniform, textures) {
             if (channel < 0) {
             if (channel < 0) {
                 return;
                 return;
             }
             }
+            if (!this._textureUnits || this._textureUnits.length !== textures.length) {
+                this._textureUnits = new Int32Array(textures.length);
+            }
+            for (var i = 0; i < textures.length; i++) {
+                this._textureUnits[i] = channel + i;
+            }
+            this._gl.uniform1iv(uniform, this._textureUnits);
             for (var index = 0; index < textures.length; index++) {
             for (var index = 0; index < textures.length; index++) {
-                this.setTexture(channel, textures[index]);
+                this._setTexture(channel + index, textures[index]);
             }
             }
         };
         };
         Engine.prototype._setAnisotropicLevel = function (key, texture) {
         Engine.prototype._setAnisotropicLevel = function (key, texture) {
@@ -23255,7 +23266,8 @@ var BABYLON;
                 this._program = engine.createShaderProgram(vertexSourceCode, fragmentSourceCode, defines);
                 this._program = engine.createShaderProgram(vertexSourceCode, fragmentSourceCode, defines);
                 this._uniforms = engine.getUniforms(this._program, this._uniformsNames);
                 this._uniforms = engine.getUniforms(this._program, this._uniformsNames);
                 this._attributes = engine.getAttributes(this._program, attributesNames);
                 this._attributes = engine.getAttributes(this._program, attributesNames);
-                for (var index = 0; index < this._samplers.length; index++) {
+                var index;
+                for (index = 0; index < this._samplers.length; index++) {
                     var sampler = this.getUniform(this._samplers[index]);
                     var sampler = this.getUniform(this._samplers[index]);
                     if (sampler == null) {
                     if (sampler == null) {
                         this._samplers.splice(index, 1);
                         this._samplers.splice(index, 1);
@@ -23299,10 +23311,16 @@ var BABYLON;
             this._engine._bindTexture(this._samplers.indexOf(channel), texture);
             this._engine._bindTexture(this._samplers.indexOf(channel), texture);
         };
         };
         Effect.prototype.setTexture = function (channel, texture) {
         Effect.prototype.setTexture = function (channel, texture) {
-            this._engine.setTexture(this._samplers.indexOf(channel), texture);
+            this._engine.setTexture(this._samplers.indexOf(channel), this.getUniform(channel), texture);
         };
         };
         Effect.prototype.setTextureArray = function (channel, textures) {
         Effect.prototype.setTextureArray = function (channel, textures) {
-            this._engine.setTextureArray(this._samplers.indexOf(channel), textures);
+            if (this._samplers.indexOf(channel + "Ex") === -1) {
+                var initialPos = this._samplers.indexOf(channel);
+                for (var index = 1; index < textures.length; index++) {
+                    this._samplers.splice(initialPos + index, 0, channel + "Ex");
+                }
+            }
+            this._engine.setTextureArray(this._samplers.indexOf(channel), this.getUniform(channel), textures);
         };
         };
         Effect.prototype.setTextureFromPostProcess = function (channel, postProcess) {
         Effect.prototype.setTextureFromPostProcess = function (channel, postProcess) {
             this._engine.setTextureFromPostProcess(this._samplers.indexOf(channel), postProcess);
             this._engine.setTextureFromPostProcess(this._samplers.indexOf(channel), postProcess);
@@ -46427,6 +46445,7 @@ var BABYLON;
             if (this._options.samplers.indexOf(name) === -1) {
             if (this._options.samplers.indexOf(name) === -1) {
                 this._options.samplers.push(name);
                 this._options.samplers.push(name);
             }
             }
+            this._checkUniform(name);
             this._textureArrays[name] = textures;
             this._textureArrays[name] = textures;
             return this;
             return this;
         };
         };

Разлика између датотеке није приказан због своје велике величине
+ 37 - 36
dist/preview release/babylon.noworker.js


+ 10 - 3
src/Materials/babylon.effect.js

@@ -265,7 +265,8 @@ var BABYLON;
                 this._program = engine.createShaderProgram(vertexSourceCode, fragmentSourceCode, defines);
                 this._program = engine.createShaderProgram(vertexSourceCode, fragmentSourceCode, defines);
                 this._uniforms = engine.getUniforms(this._program, this._uniformsNames);
                 this._uniforms = engine.getUniforms(this._program, this._uniformsNames);
                 this._attributes = engine.getAttributes(this._program, attributesNames);
                 this._attributes = engine.getAttributes(this._program, attributesNames);
-                for (var index = 0; index < this._samplers.length; index++) {
+                var index;
+                for (index = 0; index < this._samplers.length; index++) {
                     var sampler = this.getUniform(this._samplers[index]);
                     var sampler = this.getUniform(this._samplers[index]);
                     if (sampler == null) {
                     if (sampler == null) {
                         this._samplers.splice(index, 1);
                         this._samplers.splice(index, 1);
@@ -309,10 +310,16 @@ var BABYLON;
             this._engine._bindTexture(this._samplers.indexOf(channel), texture);
             this._engine._bindTexture(this._samplers.indexOf(channel), texture);
         };
         };
         Effect.prototype.setTexture = function (channel, texture) {
         Effect.prototype.setTexture = function (channel, texture) {
-            this._engine.setTexture(this._samplers.indexOf(channel), texture);
+            this._engine.setTexture(this._samplers.indexOf(channel), this.getUniform(channel), texture);
         };
         };
         Effect.prototype.setTextureArray = function (channel, textures) {
         Effect.prototype.setTextureArray = function (channel, textures) {
-            this._engine.setTextureArray(this._samplers.indexOf(channel), textures);
+            if (this._samplers.indexOf(channel + "Ex") === -1) {
+                var initialPos = this._samplers.indexOf(channel);
+                for (var index = 1; index < textures.length; index++) {
+                    this._samplers.splice(initialPos + index, 0, channel + "Ex");
+                }
+            }
+            this._engine.setTextureArray(this._samplers.indexOf(channel), this.getUniform(channel), textures);
         };
         };
         Effect.prototype.setTextureFromPostProcess = function (channel, postProcess) {
         Effect.prototype.setTextureFromPostProcess = function (channel, postProcess) {
             this._engine.setTextureFromPostProcess(this._samplers.indexOf(channel), postProcess);
             this._engine.setTextureFromPostProcess(this._samplers.indexOf(channel), postProcess);

+ 13 - 4
src/Materials/babylon.effect.ts

@@ -291,7 +291,7 @@
 
 
                     Tools.LoadFile(includeShaderUrl, (fileContent) => {
                     Tools.LoadFile(includeShaderUrl, (fileContent) => {
                         Effect.IncludesShadersStore[includeFile] = fileContent;
                         Effect.IncludesShadersStore[includeFile] = fileContent;
-                        this._processIncludes(<string>returnValue, callback)
+                        this._processIncludes(<string>returnValue, callback);
                     });
                     });
                     return;
                     return;
                 }
                 }
@@ -331,7 +331,8 @@
                 this._uniforms = engine.getUniforms(this._program, this._uniformsNames);
                 this._uniforms = engine.getUniforms(this._program, this._uniformsNames);
                 this._attributes = engine.getAttributes(this._program, attributesNames);
                 this._attributes = engine.getAttributes(this._program, attributesNames);
 
 
-                for (var index = 0; index < this._samplers.length; index++) {
+                var index: number;
+                for (index = 0; index < this._samplers.length; index++) {
                     var sampler = this.getUniform(this._samplers[index]);
                     var sampler = this.getUniform(this._samplers[index]);
 
 
                     if (sampler == null) {
                     if (sampler == null) {
@@ -339,6 +340,7 @@
                         index--;
                         index--;
                     }
                     }
                 }
                 }
+
                 engine.bindSamplers(this);
                 engine.bindSamplers(this);
 
 
                 this._isReady = true;
                 this._isReady = true;
@@ -375,11 +377,18 @@
         }
         }
 
 
         public setTexture(channel: string, texture: BaseTexture): void {
         public setTexture(channel: string, texture: BaseTexture): void {
-            this._engine.setTexture(this._samplers.indexOf(channel), texture);
+            this._engine.setTexture(this._samplers.indexOf(channel), this.getUniform(channel), texture);
         }
         }
 
 
         public setTextureArray(channel: string, textures: BaseTexture[]): void {
         public setTextureArray(channel: string, textures: BaseTexture[]): void {
-            this._engine.setTextureArray(this._samplers.indexOf(channel), textures);
+            if (this._samplers.indexOf(channel + "Ex") === -1) {
+                var initialPos = this._samplers.indexOf(channel);
+                for (var index = 1; index < textures.length; index++) {
+                    this._samplers.splice(initialPos + index, 0, channel + "Ex");
+                }
+            }
+
+            this._engine.setTextureArray(this._samplers.indexOf(channel), this.getUniform(channel), textures);
         }
         }
 
 
         public setTextureFromPostProcess(channel: string, postProcess: PostProcess): void {
         public setTextureFromPostProcess(channel: string, postProcess: PostProcess): void {

+ 1 - 0
src/Materials/babylon.shaderMaterial.js

@@ -53,6 +53,7 @@ var BABYLON;
             if (this._options.samplers.indexOf(name) === -1) {
             if (this._options.samplers.indexOf(name) === -1) {
                 this._options.samplers.push(name);
                 this._options.samplers.push(name);
             }
             }
+            this._checkUniform(name);
             this._textureArrays[name] = textures;
             this._textureArrays[name] = textures;
             return this;
             return this;
         };
         };

+ 3 - 0
src/Materials/babylon.shaderMaterial.ts

@@ -58,6 +58,9 @@
             if (this._options.samplers.indexOf(name) === -1) {
             if (this._options.samplers.indexOf(name) === -1) {
                 this._options.samplers.push(name);
                 this._options.samplers.push(name);
             }
             }
+
+            this._checkUniform(name);
+
             this._textureArrays[name] = textures;
             this._textureArrays[name] = textures;
 
 
             return this;
             return this;

+ 14 - 3
src/babylon.engine.js

@@ -1923,10 +1923,14 @@ var BABYLON;
                 this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);
                 this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);
             }
             }
         };
         };
-        Engine.prototype.setTexture = function (channel, texture) {
+        Engine.prototype.setTexture = function (channel, uniform, texture) {
             if (channel < 0) {
             if (channel < 0) {
                 return;
                 return;
             }
             }
+            this._gl.uniform1i(uniform, channel);
+            this._setTexture(channel, texture);
+        };
+        Engine.prototype._setTexture = function (channel, texture) {
             // Not ready?
             // Not ready?
             if (!texture || !texture.isReady()) {
             if (!texture || !texture.isReady()) {
                 if (this._activeTexturesCache[channel] != null) {
                 if (this._activeTexturesCache[channel] != null) {
@@ -1998,12 +2002,19 @@ var BABYLON;
                 this._setAnisotropicLevel(this._gl.TEXTURE_2D, texture);
                 this._setAnisotropicLevel(this._gl.TEXTURE_2D, texture);
             }
             }
         };
         };
-        Engine.prototype.setTextureArray = function (channel, textures) {
+        Engine.prototype.setTextureArray = function (channel, uniform, textures) {
             if (channel < 0) {
             if (channel < 0) {
                 return;
                 return;
             }
             }
+            if (!this._textureUnits || this._textureUnits.length !== textures.length) {
+                this._textureUnits = new Int32Array(textures.length);
+            }
+            for (var i = 0; i < textures.length; i++) {
+                this._textureUnits[i] = channel + i;
+            }
+            this._gl.uniform1iv(uniform, this._textureUnits);
             for (var index = 0; index < textures.length; index++) {
             for (var index = 0; index < textures.length; index++) {
-                this.setTexture(channel, textures[index]);
+                this._setTexture(channel + index, textures[index]);
             }
             }
         };
         };
         Engine.prototype._setAnisotropicLevel = function (key, texture) {
         Engine.prototype._setAnisotropicLevel = function (key, texture) {

+ 18 - 3
src/babylon.engine.ts

@@ -355,6 +355,7 @@
         private _currentBufferPointers: Array<{ indx: number, size: number, type: number, normalized: boolean, stride: number, offset: number, buffer: WebGLBuffer }> = [];
         private _currentBufferPointers: Array<{ indx: number, size: number, type: number, normalized: boolean, stride: number, offset: number, buffer: WebGLBuffer }> = [];
         private _currentInstanceLocations = new Array<number>();
         private _currentInstanceLocations = new Array<number>();
         private _currentInstanceBuffers = new Array<WebGLBuffer>();
         private _currentInstanceBuffers = new Array<WebGLBuffer>();
+        private _textureUnits: Int32Array;
 
 
         private _workingCanvas: HTMLCanvasElement;
         private _workingCanvas: HTMLCanvasElement;
         private _workingContext: CanvasRenderingContext2D;
         private _workingContext: CanvasRenderingContext2D;
@@ -2329,10 +2330,16 @@
             }
             }
         }
         }
 
 
-        public setTexture(channel: number, texture: BaseTexture): void {
+        public setTexture(channel: number, uniform: WebGLUniformLocation, texture: BaseTexture): void {
             if (channel < 0) {
             if (channel < 0) {
                 return;
                 return;
             }
             }
+
+            this._gl.uniform1i(uniform, channel);
+            this._setTexture(channel, texture);
+        }
+
+        private _setTexture(channel: number, texture: BaseTexture): void {
             // Not ready?
             // Not ready?
             if (!texture || !texture.isReady()) {
             if (!texture || !texture.isReady()) {
                 if (this._activeTexturesCache[channel] != null) {
                 if (this._activeTexturesCache[channel] != null) {
@@ -2414,13 +2421,21 @@
             }
             }
         }
         }
 
 
-        public setTextureArray(channel: number, textures: BaseTexture[]): void {
+        public setTextureArray(channel: number, uniform: WebGLUniformLocation, textures: BaseTexture[]): void {
             if (channel < 0) {
             if (channel < 0) {
                 return;
                 return;
             }
             }
 
 
+            if (!this._textureUnits || this._textureUnits.length !== textures.length) {
+                this._textureUnits = new Int32Array(textures.length);
+            }
+            for (let i = 0; i < textures.length; i++) {
+                this._textureUnits[i] = channel + i;
+            }
+            this._gl.uniform1iv(uniform, this._textureUnits);
+
             for (var index = 0; index < textures.length; index++) {
             for (var index = 0; index < textures.length; index++) {
-                this.setTexture(channel, textures[index]);
+                this._setTexture(channel + index, textures[index]);
             }
             }
         }
         }