浏览代码

Webgl context lost step 7

David Catuhe 8 年之前
父节点
当前提交
50806f2efd

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


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


+ 1 - 1
src/Materials/Textures/babylon.internalTexture.ts

@@ -141,7 +141,7 @@ module BABYLON {
                     proxy._swapAndDie(this);
 
                     this.isReady = true;
-                return;                
+                return;                                      
 
                 case InternalTexture.DATASOURCE_CUBE:
                     proxy = this._engine.createCubeTexture(this.url, null, this._files, !this.generateMipMaps, () => {

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

@@ -73,14 +73,30 @@ module BABYLON {
                 generateDepthTexture: generateDepthTexture,
                 types: types,
                 textureCount: count
-            };
-
-            this._internalTextures = scene.getEngine().createMultipleRenderTarget(size, this._multiRenderTargetOptions);
+            };            
+            
+            this._createInternalTextures();
+            this._createTextures();
+        }
 
+        public _rebuild(): void {
+            this.releaseInternalTextures();
             this._createInternalTextures();
+
+            for (var i = 0; i < this._internalTextures.length; i++) {
+                var texture = this._textures[i];
+                texture._texture = this._internalTextures[i];
+            }
+
+            // Keeps references to frame buffer and stencil/depth buffer
+            this._texture = this._internalTextures[0];
         }
 
         private _createInternalTextures(): void {
+            this._internalTextures = this.getScene().getEngine().createMultipleRenderTarget(this._size , this._multiRenderTargetOptions);
+        }
+
+        private _createTextures(): void {
             this._textures = [];
             for (var i = 0; i < this._internalTextures.length; i++) {
                 var texture = new BABYLON.Texture(null, this.getScene());

+ 4 - 0
src/Particles/babylon.gpuParticleSystem.ts

@@ -34,6 +34,10 @@
 
         }
 
+        public rebuild(): void {
+            
+        }
+
         public dispose(): void {
             var index = this._scene.particleSystems.indexOf(this);
             if (index > -1) {

+ 25 - 13
src/Particles/babylon.particleSystem.ts

@@ -21,6 +21,8 @@
         dispose(): void; 
         clone(name: string, newEmitter: any): IParticleSystem;
         serialize(): any;
+
+        rebuild(): void
     }
 
     export class ParticleSystem implements IDisposable, IAnimatable, IParticleSystem {
@@ -127,19 +129,7 @@
 
             scene.particleSystems.push(this);
 
-            var indices = [];
-            var index = 0;
-            for (var count = 0; count < capacity; count++) {
-                indices.push(index);
-                indices.push(index + 1);
-                indices.push(index + 2);
-                indices.push(index);
-                indices.push(index + 2);
-                indices.push(index + 3);
-                index += 4;
-            }
-
-            this._indexBuffer = scene.getEngine().createIndexBuffer(indices);
+            this._createIndexBuffer();
 
             // 11 floats per particle (x, y, z, r, g, b, a, angle, size, offsetX, offsetY) + 1 filler
             this._vertexData = new Float32Array(capacity * 11 * 4);
@@ -199,6 +189,22 @@
             }
         }
 
+        private _createIndexBuffer() {
+            var indices = [];
+            var index = 0;
+            for (var count = 0; count < this._capacity ; count++) {
+                indices.push(index);
+                indices.push(index + 1);
+                indices.push(index + 2);
+                indices.push(index);
+                indices.push(index + 2);
+                indices.push(index + 3);
+                index += 4;
+            }
+
+            this._indexBuffer = this._scene.getEngine().createIndexBuffer(indices);
+        }
+
         public recycleParticle(particle: Particle): void {
             var lastParticle = this.particles.pop();
 
@@ -396,6 +402,12 @@
             this._vertexBuffer.update(this._vertexData);
         }
 
+        public rebuild(): void {
+            this._createIndexBuffer();
+
+            this._vertexBuffer._rebuild();
+        }
+
         public render(): number {
             var effect = this._getEffect();
 

+ 6 - 0
src/PostProcess/RenderPipeline/Pipelines/babylon.ssao2RenderingPipeline.ts

@@ -250,6 +250,12 @@
                 }
             };
         }
+        
+        public _rebuild() {
+            this._firstUpdate = true;
+
+            super._rebuild();
+        }
 
         private _generateHemisphere(): number[] {
             var numSamples = this.samples;

+ 5 - 0
src/PostProcess/RenderPipeline/Pipelines/babylon.ssaoRenderingPipeline.ts

@@ -189,6 +189,11 @@
             };
         }
 
+        public _rebuild() {
+            this._firstUpdate = true;
+            super._rebuild();            
+        }
+
         private _createSSAOPostProcess(ratio: number): void {
             var numSamples = 16;
             var sampleSphere = [

+ 4 - 0
src/PostProcess/RenderPipeline/babylon.postProcessRenderPipeline.ts

@@ -46,6 +46,10 @@ module BABYLON {
 
         // private
 
+        public _rebuild() {
+            
+        }
+
         public _enableEffect(renderEffectName: string, cameras: Camera);
         public _enableEffect(renderEffectName: string, cameras: Camera[]);
         public _enableEffect(renderEffectName: string, cameras: any): void {

+ 25 - 5
src/PostProcess/RenderPipeline/babylon.postProcessRenderPipelineManager.ts

@@ -84,12 +84,32 @@ module BABYLON {
 
         public update(): void {
             for (var renderPipelineName in this._renderPipelines) {
-                var pipeline = this._renderPipelines[renderPipelineName];
-                if (!pipeline.isSupported) {
+                if (this._renderPipelines.hasOwnProperty(renderPipelineName)) {
+                    var pipeline = this._renderPipelines[renderPipelineName];
+                    if (!pipeline.isSupported) {
+                        pipeline.dispose();
+                        delete this._renderPipelines[renderPipelineName];
+                    } else {
+                        pipeline._update();
+                    }
+                }
+            }
+        }
+
+        public _rebuild(): void {
+            for (var renderPipelineName in this._renderPipelines) {
+                if (this._renderPipelines.hasOwnProperty(renderPipelineName)) {
+                    var pipeline = this._renderPipelines[renderPipelineName];
+                    pipeline._rebuild();
+                }
+            }
+        }
+
+        public dispose(): void {
+            for (var renderPipelineName in this._renderPipelines) {
+                if (this._renderPipelines.hasOwnProperty(renderPipelineName)) {
+                    var pipeline = this._renderPipelines[renderPipelineName];
                     pipeline.dispose();
-                    delete this._renderPipelines[renderPipelineName];
-                } else {
-                    pipeline._update();
                 }
             }
         }

+ 10 - 0
src/Rendering/babylon.boundingBoxRenderer.ts

@@ -29,9 +29,19 @@
             var engine = this._scene.getEngine();
             var boxdata = VertexData.CreateBox({ size: 1.0 });
             this._vertexBuffers[VertexBuffer.PositionKind] = new VertexBuffer(engine, boxdata.positions, VertexBuffer.PositionKind, false);
+            this._createIndexBuffer();
+        }
+
+        private _createIndexBuffer(): void {
+            var engine = this._scene.getEngine();
             this._indexBuffer = engine.createIndexBuffer([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 7, 1, 6, 2, 5, 3, 4]);
         }
 
+        public _rebuild(): void {
+            this._vertexBuffers[VertexBuffer.PositionKind]._rebuild();
+            this._createIndexBuffer();
+        }
+
         public reset(): void {
             this.renderList.reset();
         }

+ 6 - 0
src/babylon.engine.ts

@@ -3650,6 +3650,12 @@
         }
 
         public updateRawCubeTexture(texture: InternalTexture, data: ArrayBufferView[], format: number, type: number, invertY: boolean, compression: string = null, level = 0): void {
+            texture._bufferViewArray = data;
+            texture.format = format;
+            texture.type = type;
+            texture.invertY = invertY;
+            texture._compression = compression;
+
             var gl = this._gl;
             var textureType = this._getWebGLTextureType(type);
             var internalFormat = this._getInternalFormat(format);

+ 16 - 0
src/babylon.scene.ts

@@ -3474,6 +3474,10 @@
             // Post-processes
             this.postProcessManager.dispose();
 
+            if (this._postProcessRenderPipelineManager) {
+                this._postProcessRenderPipelineManager.dispose();
+            }
+
             // Physics
             if (this._physicsEngine) {
                 this.disablePhysicsEngine();
@@ -3857,6 +3861,18 @@
             for (var highlightLayer of this.highlightLayers) {
                 highlightLayer._rebuild();
             }
+
+            if (this._boundingBoxRenderer) {
+                this._boundingBoxRenderer._rebuild();
+            }
+
+            for (var system of this.particleSystems) {
+                system.rebuild();
+            }
+
+            if (this._postProcessRenderPipelineManager) {
+                this._postProcessRenderPipelineManager._rebuild();
+            }            
         }
 
         public _rebuildTextures(): void {

二进制
tests/validation/ReferenceImages/DefaultRenderingPipeline.png


+ 1 - 1
tests/validation/config.json

@@ -217,7 +217,7 @@
     },      
     {
       "title": "Default rendering pipeline",
-      "renderCount": 10,
+      "renderCount": 20,
       "playgroundId": "#5XB8YT#2",
       "referenceImage": "DefaultRenderingPipeline.png"
     },             

+ 1 - 1
tests/validation/validation.js

@@ -189,7 +189,7 @@ runTest(index) {
                     var code = JSON.parse(snippet.jsonPayload).code.toString();
                     code = code.replace(/\/textures\//g, pgRoot + "/textures/");
                     code = code.replace(/"textures\//g, "\"" + pgRoot + "/textures/");
-                    code = code.replace(/\/scenes\//g, "\"" + pgRoot + "/scenes/");
+                    code = code.replace(/\/scenes\//g, pgRoot + "/scenes/");
                     code = code.replace(/"scenes\//g, "\"" + pgRoot + "/scenes/");
 
                     currentScene = eval(code + "\r\ncreateScene(engine)");