Bläddra i källkod

removing count property on multirenderTarget

Benjamin Guignabert 5 år sedan
förälder
incheckning
3acb9bc436

+ 14 - 11
src/Engines/Extensions/engine.multiRender.ts

@@ -16,7 +16,7 @@ declare module "../../Engines/thinEngine" {
          * @param disableGenerateMipMaps defines a boolean indicating that mipmaps must not be generated
          * @param onBeforeUnbind defines a function which will be called before the effective unbind
          */
-        unBindMultiColorAttachmentFramebuffer(count: number, textures: InternalTexture[], disableGenerateMipMaps: boolean, onBeforeUnbind?: () => void): void;
+        unBindMultiColorAttachmentFramebuffer(textures: InternalTexture[], disableGenerateMipMaps: boolean, onBeforeUnbind?: () => void): void;
 
         /**
          * Create a multi render target texture
@@ -35,7 +35,7 @@ declare module "../../Engines/thinEngine" {
          * @param samples defines the sample count to set
          * @returns the effective sample count (could be 0 if multisample render targets are not supported)
          */
-        updateMultipleRenderTargetTextureSampleCount(count: number, textures: Nullable<InternalTexture[]>, samples: number): number;
+        updateMultipleRenderTargetTextureSampleCount(textures: Nullable<InternalTexture[]>, samples: number): number;
 
         /**
          * Clears attachments
@@ -77,7 +77,7 @@ ThinEngine.prototype.clearColorAttachments = function(texture: InternalTexture,
     gl.drawBuffers(texture._attachments!);
 };
 
-ThinEngine.prototype.unBindMultiColorAttachmentFramebuffer = function(count: number, textures: InternalTexture[], disableGenerateMipMaps: boolean = false, onBeforeUnbind?: () => void): void {
+ThinEngine.prototype.unBindMultiColorAttachmentFramebuffer = function(textures: InternalTexture[], disableGenerateMipMaps: boolean = false, onBeforeUnbind?: () => void): void {
     this._currentRenderTarget = null;
 
     // If MSAA, we need to bitblt back to main texture
@@ -87,11 +87,8 @@ ThinEngine.prototype.unBindMultiColorAttachmentFramebuffer = function(count: num
         gl.bindFramebuffer(gl.READ_FRAMEBUFFER, textures[0]._MSAAFramebuffer);
         gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, textures[0]._framebuffer);
 
-        var attachments = textures[0]._attachments;
-        if (!attachments) {
-            attachments = new Array(count);
-            textures[0]._attachments = attachments;
-        }
+        var attachments = textures[0]._attachments!;
+        var count = attachments.length;
 
         for (var i = 0; i < count; i++) {
             var texture = textures[i];
@@ -114,7 +111,7 @@ ThinEngine.prototype.unBindMultiColorAttachmentFramebuffer = function(count: num
         gl.drawBuffers(attachments);
     }
 
-    for (var i = 0; i < count; i++) {
+    for (var i = 0; i < textures[0]._attachments!.length; i++) {
         var texture = textures[i];
         if (texture.generateMipMaps && !disableGenerateMipMaps && !texture.isCube) {
             this._bindTextureDirectly(gl.TEXTURE_2D, texture, true);
@@ -293,8 +290,8 @@ ThinEngine.prototype.createMultipleRenderTarget = function(size: any, options: I
     return textures;
 };
 
-ThinEngine.prototype.updateMultipleRenderTargetTextureSampleCount = function(count: number, textures: Nullable<InternalTexture[]>, samples: number): number {
-    if (this.webGLVersion < 2 || !textures || count == 0) {
+ThinEngine.prototype.updateMultipleRenderTargetTextureSampleCount = function(textures: Nullable<InternalTexture[]>, samples: number): number {
+    if (this.webGLVersion < 2 || !textures) {
         return 1;
     }
 
@@ -302,6 +299,12 @@ ThinEngine.prototype.updateMultipleRenderTargetTextureSampleCount = function(cou
         return samples;
     }
 
+    var count = textures[0]._attachments!.length;
+
+    if (count === 0) {
+        return 1;
+    }
+
     var gl = this._gl;
 
     samples = Math.min(samples, this.getCaps().maxMSAASamples);

+ 1 - 1
src/Engines/thinEngine.ts

@@ -1345,7 +1345,7 @@ export class ThinEngine {
         if (texture._MSAAFramebuffer) {
             if (texture._textureArray) {
                 // This texture is part of a MRT texture, we need to treat all attachments
-                this.unBindMultiColorAttachmentFramebuffer(texture._textureCount!, texture._textureArray!, disableGenerateMipMaps, onBeforeUnbind);
+                this.unBindMultiColorAttachmentFramebuffer(texture._textureArray!, disableGenerateMipMaps, onBeforeUnbind);
                 return;
             }
             gl.bindFramebuffer(gl.READ_FRAMEBUFFER, texture._MSAAFramebuffer);

+ 3 - 3
src/Materials/Textures/multiRenderTarget.ts

@@ -189,7 +189,7 @@ export class MultiRenderTarget extends RenderTargetTexture {
         this._texture = this._internalTextures[0];
 
         if (this.samples !== 1) {
-            this._getEngine()!.updateMultipleRenderTargetTextureSampleCount(this.count, this._internalTextures, this.samples);
+            this._getEngine()!.updateMultipleRenderTargetTextureSampleCount(this._internalTextures, this.samples);
         }
     }
 
@@ -221,7 +221,7 @@ export class MultiRenderTarget extends RenderTargetTexture {
             return;
         }
 
-        this._samples = this._getEngine()!.updateMultipleRenderTargetTextureSampleCount(this.count, this._internalTextures, value);
+        this._samples = this._getEngine()!.updateMultipleRenderTargetTextureSampleCount(this._internalTextures, value);
     }
 
     /**
@@ -235,7 +235,7 @@ export class MultiRenderTarget extends RenderTargetTexture {
     }
 
     protected unbindFrameBuffer(engine: Engine, faceIndex: number): void {
-        engine.unBindMultiColorAttachmentFramebuffer(this.count, this._internalTextures, this.isCube, () => {
+        engine.unBindMultiColorAttachmentFramebuffer(this._internalTextures, this.isCube, () => {
             this.onAfterRenderObservable.notifyObservers(faceIndex);
         });
     }