瀏覽代碼

CreateAlphaTexture with gl.ALPHA as internalTexture format

Trevor Baron 7 年之前
父節點
當前提交
a36c00a4f8
共有 2 個文件被更改,包括 13 次插入7 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 12 7
      src/Engine/babylon.engine.ts

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

@@ -41,6 +41,7 @@
 
 ## Bug fixes
 - VR experience helper will now fire pointer events even when no mesh is currently hit ([TrevorDev](https://github.com/TrevorDev))
+- RawTexture.CreateAlphaTexture no longer fails to create a usable texture ([TrevorDev](https://github.com/TrevorDev))
 
 ### Core Engine
 

+ 12 - 7
src/Engine/babylon.engine.ts

@@ -4363,8 +4363,9 @@
         public updateRawTexture(texture: Nullable<InternalTexture>, data: Nullable<ArrayBufferView>, format: number, invertY: boolean, compression: Nullable<string> = null, type = Engine.TEXTURETYPE_UNSIGNED_INT): void {            if (!texture) {
                 return;
             }
-
+            // babylon's internalSizedFomat but gl's texImage2D internalFormat
             var internalSizedFomat = this._getRGBABufferInternalSizedFormat(type, format);
+            // babylon's internalFormat but gl's texImage2D format
             var internalFormat = this._getInternalFormat(format);
             var textureType = this._getWebGLTextureType(type);
             this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);
@@ -4381,7 +4382,7 @@
             if (texture.width % 4 !== 0) {
                 this._gl.pixelStorei(this._gl.UNPACK_ALIGNMENT, 1);
             }
-
+            
             if (compression && data) {
                 this._gl.compressedTexImage2D(this._gl.TEXTURE_2D, 0, (<any>this.getCaps().s3tc)[compression], texture.width, texture.height, 0, <DataView>data);
             } else {
@@ -4576,7 +4577,7 @@
                     }
 
                     texture._workingContext.drawImage(video, 0, 0, video.videoWidth, video.videoHeight, 0, 0, texture.width, texture.height);
-
+                    
                     this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, texture._workingCanvas);
                 } else {
                     this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, video);
@@ -7099,17 +7100,19 @@
         /** @hidden */
         public _getRGBABufferInternalSizedFormat(type: number, format?: number): number {
             if (this._webGLVersion === 1) {
-                if (format) {
+                if (format !== undefined) {
                     switch(format) {
                         case Engine.TEXTUREFORMAT_LUMINANCE:
                             return this._gl.LUMINANCE;
+                        case Engine.TEXTUREFORMAT_ALPHA:
+                            return this._gl.ALPHA;     
                     }                    
                 }
                 return this._gl.RGBA;
             }
 
             if (type === Engine.TEXTURETYPE_FLOAT) {
-                if (format) {
+                if (format !== undefined) {
                     switch(format) {
                         case Engine.TEXTUREFORMAT_R32F:
                             return this._gl.R32F;
@@ -7125,12 +7128,14 @@
                 return this._gl.RGBA16F;
             }
 
-            if (format) {
+            if (format !== undefined) {
                 switch(format) {
                     case Engine.TEXTUREFORMAT_LUMINANCE:
                         return this._gl.LUMINANCE;
                     case Engine.TEXTUREFORMAT_RGB:
-                        return this._gl.RGB;                        
+                        return this._gl.RGB;     
+                    case Engine.TEXTUREFORMAT_ALPHA:
+                        return this._gl.ALPHA;                        
                 }                    
             }
             return this._gl.RGBA;