Forráskód Böngészése

removing gl from abstractMesh

DESKTOP-QJU4N0L\mityh 8 éve
szülő
commit
5133777596

+ 2 - 5
Tools/Gulp/config.json

@@ -80,8 +80,7 @@
                 "../../src/Mesh/babylon.mesh.vertexData.js",
                 "../../src/Mesh/babylon.geometry.js",
                 "../../src/PostProcess/babylon.postProcessManager.js",
-                "../../src/Tools/babylon.performanceMonitor.js",
-                "../../src/Rendering/babylon.occlusionBoundingBoxRenderer.js"
+                "../../src/Tools/babylon.performanceMonitor.js"
             ]
         },         
         "particles" : 
@@ -95,9 +94,7 @@
             ],
             "shaders" : [
                 "particles.vertex",
-                "particles.fragment",
-                "color.vertex",
-                "color.fragment"
+                "particles.fragment"
             ]
         },       
         "cameraBehaviors" : 

+ 12 - 23
src/Mesh/babylon.abstractMesh.ts

@@ -128,8 +128,6 @@
         public definedFacingForward = true; // orientation for POV movement & rotation
         public position = Vector3.Zero();
 
-        private _occlusionBoundingBoxRenderer: OcclusionBoundingBoxRenderer;
-        private _gl = this.getEngine()._gl;
         private _webGLVersion = this.getEngine().webGLVersion;
         private _occlusionInternalRetryCounter = 0;
         public occlusionType = AbstractMesh.OCCLUSION_TYPE_NO_VALUE;
@@ -142,16 +140,10 @@
             this._isOccluded = value;
         }
 
-        public occlusionQuery = this._gl.createQuery();
+        public occlusionQuery = this.getEngine().createQuery();
         public isOcclusionQueryInProgress = false;
 
-        private _occlusionQueryAlgorithmType: number = this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE;
-        get occlusionQueryAlgorithmType(): number {
-            return this._occlusionQueryAlgorithmType === this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE ? AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE : AbstractMesh.OCCLUSION_ALGORITHM_TYPE_ACCURATE;
-        }
-        set occlusionQueryAlgorithmType(alogrithmType: number) {
-            this._occlusionQueryAlgorithmType = alogrithmType === AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE ? this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE : this._gl.ANY_SAMPLES_PASSED;
-        }
+        public occlusionQueryAlgorithmType = AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE;
 
         private _rotation = Vector3.Zero();
         private _rotationQuaternion: Quaternion;
@@ -1834,10 +1826,6 @@
             this.onCollideObservable.clear();
             this.onCollisionPositionChangeObservable.clear();
 
-            if (this._occlusionBoundingBoxRenderer) {
-                this._occlusionBoundingBoxRenderer.dispose();
-            }
-
             this._isDisposed = true;
 
             super.dispose();
@@ -2288,15 +2276,13 @@
                 return;
             }
 
-            if (!this._occlusionBoundingBoxRenderer) {
-                var scene = this.getScene();
-                this._occlusionBoundingBoxRenderer = new OcclusionBoundingBoxRenderer(scene);
-            }
+            var engine = this.getEngine();
 
             if (this.isOcclusionQueryInProgress) {
-                var isOcclusionQueryAvailable = this._gl.getQueryParameter(this.occlusionQuery, this._gl.QUERY_RESULT_AVAILABLE) as boolean;
+                
+                var isOcclusionQueryAvailable = engine.isQueryResultAvailable(this.occlusionQuery);
                 if (isOcclusionQueryAvailable) {
-                    var occlusionQueryResult = this._gl.getQueryParameter(this.occlusionQuery, this._gl.QUERY_RESULT) as number;
+                    var occlusionQueryResult = engine.getQueryResult(this.occlusionQuery);
 
                     this.isOcclusionQueryInProgress = false;
                     this._occlusionInternalRetryCounter = 0;
@@ -2322,9 +2308,12 @@
                 }
             }
 
-            this._gl.beginQuery(this._occlusionQueryAlgorithmType, this.occlusionQuery);
-            this._occlusionBoundingBoxRenderer.render(this);
-            this._gl.endQuery(this._occlusionQueryAlgorithmType);
+
+            var scene = this.getScene();
+            var occlusionBoundingBoxRenderer = scene.getBoundingBoxRenderer();
+            engine.beginQuery(this.occlusionQueryAlgorithmType, this.occlusionQuery);
+            occlusionBoundingBoxRenderer.renderOcclusionBoundingBox(this);
+            engine.endQuery(this.occlusionQueryAlgorithmType);
             this.isOcclusionQueryInProgress = true;
         }
 

+ 38 - 1
src/Rendering/babylon.boundingBoxRenderer.ts

@@ -27,7 +27,7 @@
 
 
             var engine = this._scene.getEngine();
-            var boxdata = VertexData.CreateBox({size: 1.0});
+            var boxdata = VertexData.CreateBox({ size: 1.0 });
             this._vertexBuffers[VertexBuffer.PositionKind] = new VertexBuffer(engine, boxdata.positions, VertexBuffer.PositionKind, false);
             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]);
         }
@@ -89,6 +89,43 @@
             engine.setDepthWrite(true);
         }
 
+        public renderOcclusionBoundingBox(mesh: AbstractMesh): void {
+
+            this._prepareRessources();
+
+            if (!this._colorShader.isReady()) {
+                return;
+            }
+
+            var engine = this._scene.getEngine();
+            engine.setDepthWrite(false);
+            engine.setColorWrite(false);
+            this._colorShader._preBind();
+
+            var boundingBox = mesh._boundingInfo.boundingBox;
+            var min = boundingBox.minimum;
+            var max = boundingBox.maximum;
+            var diff = max.subtract(min);
+            var median = min.add(diff.scale(0.5));
+
+            var worldMatrix = Matrix.Scaling(diff.x, diff.y, diff.z)
+                .multiply(Matrix.Translation(median.x, median.y, median.z))
+                .multiply(boundingBox.getWorldMatrix());
+
+            engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());
+
+            engine.setDepthFunctionToLess();
+            this._scene.resetCachedMaterial();
+            this._colorShader.bind(worldMatrix);
+
+            engine.draw(false, 0, 24);
+
+            this._colorShader.unbind();
+            engine.setDepthFunctionToLessOrEqual();
+            engine.setDepthWrite(true);
+            engine.setColorWrite(true);
+        }
+
         public dispose(): void {
             if (!this._colorShader) {
                 return;

+ 0 - 82
src/Rendering/babylon.occlusionBoundingBoxRenderer.ts

@@ -1,82 +0,0 @@
-module BABYLON {
-    
-    export class OcclusionBoundingBoxRenderer {
-        private _scene: Scene;
-        private _colorShader: ShaderMaterial;
-        private _vertexBuffers: { [key: string]: VertexBuffer } = {};
-        private _indexBuffer: WebGLBuffer;
-
-        constructor(scene: Scene) {
-            this._scene = scene;
-        }
-
-        private _prepareRessources(): void {
-            if (this._colorShader) {
-                return;
-            }
-
-            this._colorShader = new ShaderMaterial("colorShader", this._scene, "color",
-                {
-                    attributes: [VertexBuffer.PositionKind],
-                    uniforms: ["world", "viewProjection", "color"]
-                });
-
-            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._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 render(mesh: AbstractMesh): void {
-
-            this._prepareRessources();
-
-            if (!this._colorShader.isReady()) {
-                return;
-            }
-
-            var engine = this._scene.getEngine();
-            engine.setDepthWrite(false);
-            engine.setColorWrite(false);
-            this._colorShader._preBind();
-
-            var boundingBox = mesh._boundingInfo.boundingBox;
-            var min = boundingBox.minimum;
-            var max = boundingBox.maximum;
-            var diff = max.subtract(min);
-            var median = min.add(diff.scale(0.5));
-
-            var worldMatrix = Matrix.Scaling(diff.x, diff.y, diff.z)
-                .multiply(Matrix.Translation(median.x, median.y, median.z))
-                .multiply(boundingBox.getWorldMatrix());
-
-            engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());
-
-            engine.setDepthFunctionToLess();
-            this._scene.resetCachedMaterial();
-            this._colorShader.bind(worldMatrix);
-
-            engine.draw(false, 0, 24);
-
-            this._colorShader.unbind();
-            engine.setDepthFunctionToLessOrEqual();
-            engine.setDepthWrite(true);
-            engine.setColorWrite(true);
-        }
-
-        public dispose(): void {
-            if (!this._colorShader) {
-                return;
-            }
-
-            this._colorShader.dispose();
-
-            var buffer = this._vertexBuffers[VertexBuffer.PositionKind];
-            if (buffer) {
-                buffer.dispose();
-                this._vertexBuffers[VertexBuffer.PositionKind] = null;
-            }
-            this._scene.getEngine()._releaseBuffer(this._indexBuffer);
-        }
-    }
-}

+ 33 - 11
src/babylon.engine.ts

@@ -103,7 +103,7 @@
             mag: magFilter
         }
     }
-  
+
     var partialLoad = (url: string, index: number, loadedImages: any, scene,
         onfinish: (images: HTMLImageElement[]) => void, onErrorCallBack: () => void = null) => {
 
@@ -992,11 +992,11 @@
         }
 
         public isDeterministicLockStep(): boolean {
-          return this._deterministicLockstep;
+            return this._deterministicLockstep;
         }
 
         public getLockstepMaxSteps(): number {
-          return this._lockstepMaxSteps;
+            return this._lockstepMaxSteps;
         }
 
         public getGlInfo() {
@@ -2627,7 +2627,7 @@
                         gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
                         gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
                         gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
-                        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);                        
+                        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
 
                         this._rescaleTexture(source, texture, scene, internalFormat, () => {
                             this._releaseTexture(source);
@@ -2653,9 +2653,9 @@
 
         private _rescaleTexture(source: WebGLTexture, destination: WebGLTexture, scene: Scene, internalFormat: number, onComplete: () => void): void {
             let rtt = this.createRenderTargetTexture({
-                    width: destination._width,
-                    height: destination._height,
-                }, {
+                width: destination._width,
+                height: destination._height,
+            }, {
                     generateMipMaps: false,
                     type: Engine.TEXTURETYPE_UNSIGNED_INT,
                     samplingMode: Texture.BILINEAR_SAMPLINGMODE,
@@ -2667,7 +2667,7 @@
             if (!this._rescalePostProcess) {
                 this._rescalePostProcess = new BABYLON.PassPostProcess("rescale", 1, null, Texture.BILINEAR_SAMPLINGMODE, this, false, Engine.TEXTURETYPE_UNSIGNED_INT);
             }
-			this._rescalePostProcess.getEffect().executeWhenCompiled(() => {
+            this._rescalePostProcess.getEffect().executeWhenCompiled(() => {
                 this._rescalePostProcess.onApply = function (effect) {
                     effect._bindTexture("textureSampler", source);
                 }
@@ -2679,7 +2679,7 @@
 
                 this.unBindFramebuffer(rtt);
                 this._releaseTexture(rtt);
-                
+
                 if (onComplete) {
                     onComplete();
                 }
@@ -3706,7 +3706,7 @@
         }
 
         private _prepareWebGLTexture(texture: WebGLTexture, scene: Scene, width: number, height: number, invertY: boolean, noMipmap: boolean, isCompressed: boolean,
-                                        processFunction: (width: number, height: number, continuationCallback: () => void) => boolean, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE): void {
+            processFunction: (width: number, height: number, continuationCallback: () => void) => boolean, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE): void {
             var potWidth = this.needPOTTextures ? Tools.GetExponentOfTwo(width, this.getCaps().maxTextureSize) : width;
             var potHeight = this.needPOTTextures ? Tools.GetExponentOfTwo(height, this.getCaps().maxTextureSize) : height;
 
@@ -3729,7 +3729,7 @@
             })) {
                 // Returning as texture needs extra async steps
                 return;
-            }         
+            }
 
             this._prepareWebGLTextureContinuation(texture, scene, noMipmap, isCompressed, samplingMode);
         }
@@ -4383,6 +4383,28 @@
             return this._gl.RGBA;
         };
 
+        public createQuery(): WebGLQuery {
+            return this._gl.createQuery();
+        }
+
+        public isQueryResultAvailable(query: WebGLQuery) {
+            return this._gl.getQueryParameter(query, this._gl.QUERY_RESULT_AVAILABLE) as boolean;
+        }
+
+        public getQueryResult(query: WebGLQuery) {
+            return this._gl.getQueryParameter(query, this._gl.QUERY_RESULT) as number;
+        }
+
+        public beginQuery(algorithmType: number, query: WebGLQuery) {
+            var glAlgorithm = algorithmType === AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE ? this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE : this._gl.ANY_SAMPLES_PASSED;
+            this._gl.beginQuery(glAlgorithm, query);
+        }
+
+        public endQuery(algorithmType: number) {
+            var glAlgorithm = algorithmType === AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE ? this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE : this._gl.ANY_SAMPLES_PASSED;
+            this._gl.endQuery(glAlgorithm);
+        }
+
         // Statics
         public static isSupported(): boolean {
             try {