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

Move hasAlpha property from BaseTexture to InternalTexture

Popov72 пре 4 година
родитељ
комит
2d910cb5f9
2 измењених фајлова са 27 додато и 7 уклоњено
  1. 25 7
      src/Materials/Textures/baseTexture.ts
  2. 2 0
      src/Materials/Textures/internalTexture.ts

+ 25 - 7
src/Materials/Textures/baseTexture.ts

@@ -50,23 +50,41 @@ export class BaseTexture extends ThinTexture implements IAnimatable {
      */
     public reservedDataStore: any = null;
 
-    @serialize("hasAlpha")
     private _hasAlpha = false;
     /**
      * Define if the texture is having a usable alpha value (can be use for transparency or glossiness for instance).
      */
+    @serialize()
+    public get hasAlpha(): boolean {
+        if (!this._texture) {
+            return this._hasAlpha;
+        } else {
+            if (this._texture._hasAlpha === null) {
+                this._texture._hasAlpha = this._hasAlpha;
+            }
+        }
+
+        return this._texture._hasAlpha;
+    }
+
     public set hasAlpha(value: boolean) {
-        if (this._hasAlpha === value) {
-            return;
+        if (!this._texture) {
+            if (this._hasAlpha === value) {
+                return;
+            }
+
+            this._hasAlpha = value;
+        } else {
+            if (this._texture._hasAlpha === value) {
+                return;
+            }
+            this._texture._hasAlpha = value;
         }
-        this._hasAlpha = value;
+
         if (this._scene) {
             this._scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag | Constants.MATERIAL_MiscDirtyFlag);
         }
     }
-    public get hasAlpha(): boolean {
-        return this._hasAlpha;
-    }
 
     /**
      * Defines if the alpha value should be determined via the rgb values.

+ 2 - 0
src/Materials/Textures/internalTexture.ts

@@ -257,6 +257,8 @@ export class InternalTexture {
 
     /** @hidden */
     public _gammaSpace: Nullable<boolean> = null;
+    /** @hidden */
+    public _hasAlpha: Nullable<boolean> = null;
 
     private _engine: ThinEngine;