浏览代码

Factoring getInternalFormat for RawTexture functions

David Catuhe 9 年之前
父节点
当前提交
bb9032b5ef

文件差异内容过多而无法显示
+ 17 - 17
dist/preview release/babylon.core.js


文件差异内容过多而无法显示
+ 739 - 736
dist/preview release/babylon.d.ts


文件差异内容过多而无法显示
+ 23 - 23
dist/preview release/babylon.js


+ 67 - 2
dist/preview release/babylon.max.js

@@ -5287,6 +5287,7 @@ var BABYLON;
             this._caps.fragmentDepthSupported = this._gl.getExtension('EXT_frag_depth') !== null;
             this._caps.fragmentDepthSupported = this._gl.getExtension('EXT_frag_depth') !== null;
             this._caps.highPrecisionShaderSupported = true;
             this._caps.highPrecisionShaderSupported = true;
             this._caps.drawBuffersExtension = this._gl.getExtension('WEBGL_draw_buffers');
             this._caps.drawBuffersExtension = this._gl.getExtension('WEBGL_draw_buffers');
+            this._caps.textureFloatLinearFiltering = this._gl.getExtension('OES_texture_float_linear');
             if (this._gl.getShaderPrecisionFormat) {
             if (this._gl.getShaderPrecisionFormat) {
                 var highp = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.HIGH_FLOAT);
                 var highp = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.HIGH_FLOAT);
                 this._caps.highPrecisionShaderSupported = highp.precision !== 0;
                 this._caps.highPrecisionShaderSupported = highp.precision !== 0;
@@ -6314,8 +6315,7 @@ var BABYLON;
             }
             }
             return texture;
             return texture;
         };
         };
-        Engine.prototype.updateRawTexture = function (texture, data, format, invertY, compression) {
-            if (compression === void 0) { compression = null; }
+        Engine.prototype._getInternalFormat = function (format) {
             var internalFormat = this._gl.RGBA;
             var internalFormat = this._gl.RGBA;
             switch (format) {
             switch (format) {
                 case Engine.TEXTUREFORMAT_ALPHA:
                 case Engine.TEXTUREFORMAT_ALPHA:
@@ -6334,6 +6334,11 @@ var BABYLON;
                     internalFormat = this._gl.RGBA;
                     internalFormat = this._gl.RGBA;
                     break;
                     break;
             }
             }
+            return internalFormat;
+        };
+        Engine.prototype.updateRawTexture = function (texture, data, format, invertY, compression) {
+            if (compression === void 0) { compression = null; }
+            var internalFormat = this._getInternalFormat(format);
             this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
             this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
             this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
             this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
             if (compression) {
             if (compression) {
@@ -6640,6 +6645,66 @@ var BABYLON;
             }
             }
             return texture;
             return texture;
         };
         };
+        Engine.prototype.createRawCubeTexture = function (url, scene, size, format, type, noMipmap, callback) {
+            var _this = this;
+            var gl = this._gl;
+            var texture = gl.createTexture();
+            scene._addPendingData(texture);
+            texture.isCube = true;
+            texture.references = 1;
+            texture.url = url;
+            var internalFormat = this._getInternalFormat(format);
+            var textureType = gl.UNSIGNED_BYTE;
+            if (type === Engine.TEXTURETYPE_FLOAT) {
+                textureType = gl.FLOAT;
+            }
+            var width = size;
+            var height = width;
+            var isPot = (BABYLON.Tools.IsExponentOfTwo(width) && BABYLON.Tools.IsExponentOfTwo(height));
+            texture._width = width;
+            texture._height = height;
+            var onerror = function () {
+                scene._removePendingData(texture);
+            };
+            var internalCallback = function (data) {
+                var rgbeDataArrays = callback(data);
+                var facesIndex = [
+                    gl.TEXTURE_CUBE_MAP_POSITIVE_X, gl.TEXTURE_CUBE_MAP_POSITIVE_Y, gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
+                    gl.TEXTURE_CUBE_MAP_NEGATIVE_X, gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, gl.TEXTURE_CUBE_MAP_NEGATIVE_Z
+                ];
+                gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
+                gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
+                for (var index = 0; index < facesIndex.length; index++) {
+                    var faceData = rgbeDataArrays[index];
+                    gl.texImage2D(facesIndex[index], 0, internalFormat, width, height, 0, internalFormat, textureType, faceData);
+                }
+                if (!noMipmap && isPot) {
+                    gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
+                }
+                else {
+                    noMipmap = true;
+                }
+                if (textureType == gl.FLOAT && !_this._caps.textureFloatLinearFiltering) {
+                    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
+                    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
+                }
+                else {
+                    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+                    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, noMipmap ? gl.LINEAR : gl.LINEAR_MIPMAP_LINEAR);
+                }
+                gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+                gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+                gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
+                texture.isReady = true;
+                _this.resetTextureCache();
+                scene._removePendingData(texture);
+            };
+            BABYLON.Tools.LoadFile(url, function (data) {
+                internalCallback(data);
+            }, onerror, scene.database, true);
+            return texture;
+        };
+        ;
         Engine.prototype._releaseTexture = function (texture) {
         Engine.prototype._releaseTexture = function (texture) {
             var gl = this._gl;
             var gl = this._gl;
             if (texture._framebuffer) {
             if (texture._framebuffer) {

文件差异内容过多而无法显示
+ 23 - 23
dist/preview release/babylon.noworker.js


+ 67 - 2
src/babylon.engine.js

@@ -454,6 +454,7 @@ var BABYLON;
             this._caps.fragmentDepthSupported = this._gl.getExtension('EXT_frag_depth') !== null;
             this._caps.fragmentDepthSupported = this._gl.getExtension('EXT_frag_depth') !== null;
             this._caps.highPrecisionShaderSupported = true;
             this._caps.highPrecisionShaderSupported = true;
             this._caps.drawBuffersExtension = this._gl.getExtension('WEBGL_draw_buffers');
             this._caps.drawBuffersExtension = this._gl.getExtension('WEBGL_draw_buffers');
+            this._caps.textureFloatLinearFiltering = this._gl.getExtension('OES_texture_float_linear');
             if (this._gl.getShaderPrecisionFormat) {
             if (this._gl.getShaderPrecisionFormat) {
                 var highp = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.HIGH_FLOAT);
                 var highp = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.HIGH_FLOAT);
                 this._caps.highPrecisionShaderSupported = highp.precision !== 0;
                 this._caps.highPrecisionShaderSupported = highp.precision !== 0;
@@ -1481,8 +1482,7 @@ var BABYLON;
             }
             }
             return texture;
             return texture;
         };
         };
-        Engine.prototype.updateRawTexture = function (texture, data, format, invertY, compression) {
-            if (compression === void 0) { compression = null; }
+        Engine.prototype._getInternalFormat = function (format) {
             var internalFormat = this._gl.RGBA;
             var internalFormat = this._gl.RGBA;
             switch (format) {
             switch (format) {
                 case Engine.TEXTUREFORMAT_ALPHA:
                 case Engine.TEXTUREFORMAT_ALPHA:
@@ -1501,6 +1501,11 @@ var BABYLON;
                     internalFormat = this._gl.RGBA;
                     internalFormat = this._gl.RGBA;
                     break;
                     break;
             }
             }
+            return internalFormat;
+        };
+        Engine.prototype.updateRawTexture = function (texture, data, format, invertY, compression) {
+            if (compression === void 0) { compression = null; }
+            var internalFormat = this._getInternalFormat(format);
             this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
             this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
             this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
             this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
             if (compression) {
             if (compression) {
@@ -1807,6 +1812,66 @@ var BABYLON;
             }
             }
             return texture;
             return texture;
         };
         };
+        Engine.prototype.createRawCubeTexture = function (url, scene, size, format, type, noMipmap, callback) {
+            var _this = this;
+            var gl = this._gl;
+            var texture = gl.createTexture();
+            scene._addPendingData(texture);
+            texture.isCube = true;
+            texture.references = 1;
+            texture.url = url;
+            var internalFormat = this._getInternalFormat(format);
+            var textureType = gl.UNSIGNED_BYTE;
+            if (type === Engine.TEXTURETYPE_FLOAT) {
+                textureType = gl.FLOAT;
+            }
+            var width = size;
+            var height = width;
+            var isPot = (BABYLON.Tools.IsExponentOfTwo(width) && BABYLON.Tools.IsExponentOfTwo(height));
+            texture._width = width;
+            texture._height = height;
+            var onerror = function () {
+                scene._removePendingData(texture);
+            };
+            var internalCallback = function (data) {
+                var rgbeDataArrays = callback(data);
+                var facesIndex = [
+                    gl.TEXTURE_CUBE_MAP_POSITIVE_X, gl.TEXTURE_CUBE_MAP_POSITIVE_Y, gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
+                    gl.TEXTURE_CUBE_MAP_NEGATIVE_X, gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, gl.TEXTURE_CUBE_MAP_NEGATIVE_Z
+                ];
+                gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
+                gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
+                for (var index = 0; index < facesIndex.length; index++) {
+                    var faceData = rgbeDataArrays[index];
+                    gl.texImage2D(facesIndex[index], 0, internalFormat, width, height, 0, internalFormat, textureType, faceData);
+                }
+                if (!noMipmap && isPot) {
+                    gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
+                }
+                else {
+                    noMipmap = true;
+                }
+                if (textureType == gl.FLOAT && !_this._caps.textureFloatLinearFiltering) {
+                    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
+                    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
+                }
+                else {
+                    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+                    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, noMipmap ? gl.LINEAR : gl.LINEAR_MIPMAP_LINEAR);
+                }
+                gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+                gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+                gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
+                texture.isReady = true;
+                _this.resetTextureCache();
+                scene._removePendingData(texture);
+            };
+            BABYLON.Tools.LoadFile(url, function (data) {
+                internalCallback(data);
+            }, onerror, scene.database, true);
+            return texture;
+        };
+        ;
         Engine.prototype._releaseTexture = function (texture) {
         Engine.prototype._releaseTexture = function (texture) {
             var gl = this._gl;
             var gl = this._gl;
             if (texture._framebuffer) {
             if (texture._framebuffer) {

+ 88 - 4
src/babylon.engine.ts

@@ -386,6 +386,7 @@
         public uintIndices: boolean;
         public uintIndices: boolean;
         public highPrecisionShaderSupported: boolean;
         public highPrecisionShaderSupported: boolean;
         public fragmentDepthSupported: boolean;
         public fragmentDepthSupported: boolean;
+        public textureFloatLinearFiltering: boolean;
         public drawBuffersExtension;
         public drawBuffersExtension;
     }
     }
 
 
@@ -657,6 +658,7 @@
             this._caps.fragmentDepthSupported = this._gl.getExtension('EXT_frag_depth') !== null;
             this._caps.fragmentDepthSupported = this._gl.getExtension('EXT_frag_depth') !== null;
             this._caps.highPrecisionShaderSupported = true;
             this._caps.highPrecisionShaderSupported = true;
             this._caps.drawBuffersExtension = this._gl.getExtension('WEBGL_draw_buffers');
             this._caps.drawBuffersExtension = this._gl.getExtension('WEBGL_draw_buffers');
+            this._caps.textureFloatLinearFiltering = this._gl.getExtension('OES_texture_float_linear');
 
 
             if (this._gl.getShaderPrecisionFormat) {
             if (this._gl.getShaderPrecisionFormat) {
                 var highp = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.HIGH_FLOAT);
                 var highp = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.HIGH_FLOAT);
@@ -683,9 +685,9 @@
                 // Pointer lock
                 // Pointer lock
                 if (this.isFullscreen && this._pointerLockRequested) {
                 if (this.isFullscreen && this._pointerLockRequested) {
                     canvas.requestPointerLock = canvas.requestPointerLock ||
                     canvas.requestPointerLock = canvas.requestPointerLock ||
-                    canvas.msRequestPointerLock ||
-                    canvas.mozRequestPointerLock ||
-                    canvas.webkitRequestPointerLock;
+                        canvas.msRequestPointerLock ||
+                        canvas.mozRequestPointerLock ||
+                        canvas.webkitRequestPointerLock;
 
 
                     if (canvas.requestPointerLock) {
                     if (canvas.requestPointerLock) {
                         canvas.requestPointerLock();
                         canvas.requestPointerLock();
@@ -1751,7 +1753,7 @@
             return texture;
             return texture;
         }
         }
 
 
-        public updateRawTexture(texture: WebGLTexture, data: ArrayBufferView, format: number, invertY: boolean, compression: string = null): void {
+        private _getInternalFormat(format: number): number {
             var internalFormat = this._gl.RGBA;
             var internalFormat = this._gl.RGBA;
             switch (format) {
             switch (format) {
                 case Engine.TEXTUREFORMAT_ALPHA:
                 case Engine.TEXTUREFORMAT_ALPHA:
@@ -1770,6 +1772,12 @@
                     internalFormat = this._gl.RGBA;
                     internalFormat = this._gl.RGBA;
                     break;
                     break;
             }
             }
+
+            return internalFormat;
+        }
+
+        public updateRawTexture(texture: WebGLTexture, data: ArrayBufferView, format: number, invertY: boolean, compression: string = null): void {
+            var internalFormat = this._getInternalFormat(format);
             this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
             this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
             this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
             this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
 
 
@@ -2149,6 +2157,81 @@
             return texture;
             return texture;
         }
         }
 
 
+        public createRawCubeTexture(url: string, scene: Scene, size: number, format: number, type: number, noMipmap: boolean, callback: (ArrayBuffer) => ArrayBufferView[]): WebGLTexture {
+            var gl = this._gl;
+            var texture = gl.createTexture();
+            scene._addPendingData(texture);
+            texture.isCube = true;
+            texture.references = 1;
+            texture.url = url;
+
+            var internalFormat = this._getInternalFormat(format);
+
+            var textureType = gl.UNSIGNED_BYTE;
+            if (type === Engine.TEXTURETYPE_FLOAT) {
+                textureType = gl.FLOAT;
+            }
+
+            var width = size;
+            var height = width;
+            var isPot = (Tools.IsExponentOfTwo(width) && Tools.IsExponentOfTwo(height));
+
+            texture._width = width;
+            texture._height = height;
+
+            var onerror = () => {
+                scene._removePendingData(texture);
+            };
+
+            var internalCallback = (data) => {
+                var rgbeDataArrays = callback(data);
+
+                var facesIndex = [
+                    gl.TEXTURE_CUBE_MAP_POSITIVE_X, gl.TEXTURE_CUBE_MAP_POSITIVE_Y, gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
+                    gl.TEXTURE_CUBE_MAP_NEGATIVE_X, gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, gl.TEXTURE_CUBE_MAP_NEGATIVE_Z
+                ];
+
+                gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
+                gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
+
+                for (var index = 0; index < facesIndex.length; index++) {
+                    var faceData = rgbeDataArrays[index];
+                    gl.texImage2D(facesIndex[index], 0, internalFormat, width, height, 0, internalFormat, textureType, faceData);
+                }
+
+                if (!noMipmap && isPot) {
+                    gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
+                }
+                else {
+                    noMipmap = true;
+                }
+
+                if (textureType == gl.FLOAT && !this._caps.textureFloatLinearFiltering) {
+                    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
+                    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
+                }
+                else {
+                    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+                    gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, noMipmap ? gl.LINEAR : gl.LINEAR_MIPMAP_LINEAR);
+                }
+
+                gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+                gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+                gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
+
+                texture.isReady = true;
+
+                this.resetTextureCache();
+                scene._removePendingData(texture);
+            };
+
+            Tools.LoadFile(url, data => {
+                internalCallback(data);
+            }, onerror, scene.database, true);
+
+            return texture;
+        };
+
         public _releaseTexture(texture: WebGLTexture): void {
         public _releaseTexture(texture: WebGLTexture): void {
             var gl = this._gl;
             var gl = this._gl;
 
 
@@ -2448,3 +2531,4 @@
     }
     }
 }
 }
 
 
+