From 5f89b26e86b5e1d30d2b33fb5ec10f34656a69c1 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Tue, 18 Dec 2018 16:50:34 -0500 Subject: [PATCH] Temp --- Specs/Scene/ClassificationPrimitiveSpec.js | 49 +++-- Specs/Scene/GroundPrimitiveSpec.js | 221 ++++++++++++--------- 2 files changed, 159 insertions(+), 111 deletions(-) diff --git a/Specs/Scene/ClassificationPrimitiveSpec.js b/Specs/Scene/ClassificationPrimitiveSpec.js index eafb815b1cb1..c98769d3cb9a 100644 --- a/Specs/Scene/ClassificationPrimitiveSpec.js +++ b/Specs/Scene/ClassificationPrimitiveSpec.js @@ -64,17 +64,8 @@ defineSuite([ var primitive; var globePrimitive; var tilesetPrimitive; - - beforeAll(function() { - scene = createScene(); - scene.postProcessStages.fxaa.enabled = false; - - ellipsoid = Ellipsoid.WGS84; - }); - - afterAll(function() { - scene.destroyForSpecs(); - }); + var reusableGlobePrimitive; + var reusableTilesetPrimitive; function viewCenter() { scene.camera.setView({ destination : rectangle }); @@ -88,7 +79,7 @@ defineSuite([ scene.camera.setView({ destination : tilesetRectangle }); } - function MockPrimitive(rectangle, pass) { + function createPrimitive(rectangle, pass) { var renderState; if (pass === Pass.CESIUM_3D_TILE) { renderState = RenderState.fromCache({ @@ -101,7 +92,7 @@ defineSuite([ } var depthColorAttribute = ColorGeometryInstanceAttribute.fromColor(new Color(0.0, 0.0, 1.0, 1.0)); depthColor = depthColorAttribute.value; - this._primitive = new Primitive({ + return new Primitive({ geometryInstances : new GeometryInstance({ geometry : new RectangleGeometry({ ellipsoid : Ellipsoid.WGS84, @@ -119,7 +110,10 @@ defineSuite([ }), asynchronous : false }); + } + function MockPrimitive(primitive, pass) { + this._primitive = primitive; this._pass = pass; } @@ -139,21 +133,36 @@ defineSuite([ }; MockPrimitive.prototype.destroy = function() { - this._primitive.destroy(); return destroyObject(this); }; - beforeEach(function() { - scene.morphTo3D(0); - scene.render(); // clear any afterRender commands + beforeAll(function() { + scene = createScene(); + scene.postProcessStages.fxaa.enabled = false; + + ellipsoid = Ellipsoid.WGS84; rectangle = Rectangle.fromDegrees(-75.0, 25.0, -70.0, 30.0); globeRectangle = Rectangle.fromDegrees(-75.0, 27.5, -70.0, 30.0); tilesetRectangle = Rectangle.fromDegrees(-75.0, 25.0, -70.0, 27.5); + reusableGlobePrimitive = createPrimitive(globeRectangle, Pass.GLOBE); + reusableTilesetPrimitive = createPrimitive(tilesetRectangle, Pass.CESIUM_3D_TILE); + }); + + afterAll(function() { + reusableGlobePrimitive.destroy(); + reusableTilesetPrimitive.destroy(); + scene.destroyForSpecs(); + }); + + beforeEach(function() { + scene.morphTo3D(0); + scene.render(); // clear any afterRender commands + // wrap rectangle primitive so it gets executed during the globe pass or 3D Tiles pass to lay down depth - globePrimitive = new MockPrimitive(globeRectangle, Pass.GLOBE); - tilesetPrimitive = new MockPrimitive(tilesetRectangle, Pass.CESIUM_3D_TILE); + globePrimitive = new MockPrimitive(reusableGlobePrimitive, Pass.GLOBE); + tilesetPrimitive = new MockPrimitive(reusableTilesetPrimitive, Pass.CESIUM_3D_TILE); var center = Rectangle.center(rectangle); var origin = ellipsoid.cartographicToCartesian(center); @@ -1046,7 +1055,7 @@ defineSuite([ primitive.appearance = new MaterialAppearance(); expect(function() { - expectRender(boxColor); + expect(scene).toRender(boxColor); }).toThrowDeveloperError(); }); diff --git a/Specs/Scene/GroundPrimitiveSpec.js b/Specs/Scene/GroundPrimitiveSpec.js index 9b6b81543666..6c977b26cdbd 100644 --- a/Specs/Scene/GroundPrimitiveSpec.js +++ b/Specs/Scene/GroundPrimitiveSpec.js @@ -15,12 +15,14 @@ defineSuite([ 'Core/RectangleGeometry', 'Core/ShowGeometryInstanceAttribute', 'Renderer/Pass', + 'Renderer/RenderState', 'Scene/ClassificationType', 'Scene/EllipsoidSurfaceAppearance', 'Scene/InvertClassification', 'Scene/Material', 'Scene/PerInstanceColorAppearance', 'Scene/Primitive', + 'Scene/StencilConstants', 'Specs/createCanvas', 'Specs/createScene', 'Specs/pollToPromise' @@ -41,12 +43,14 @@ defineSuite([ RectangleGeometry, ShowGeometryInstanceAttribute, Pass, + RenderState, ClassificationType, EllipsoidSurfaceAppearance, InvertClassification, Material, PerInstanceColorAppearance, Primitive, + StencilConstants, createCanvas, createScene, pollToPromise) { @@ -57,88 +61,123 @@ defineSuite([ var ellipsoid; var rectangle; + var globeRectangle; + var tilesetRectangle; var depthColor; var rectColor; var rectangleInstance; var primitive; - var depthPrimitive; - var reusablePrimitive; + var globePrimitive; + var tilesetPrimitive; + var reusableGlobePrimitive; + var reusableTilesetPrimitive; - beforeAll(function() { - scene = createScene(); - - scene.postProcessStages.fxaa.enabled = false; + function viewCenter() { + scene.camera.setView({ destination : rectangle }); + } - context = scene.context; + function viewGlobePrimitive() { + scene.camera.setView({ destination : globeRectangle }); + } - ellipsoid = Ellipsoid.WGS84; - return GroundPrimitive.initializeTerrainHeights().then(function(){ - var depthColorAttribute = ColorGeometryInstanceAttribute.fromColor(new Color(0.0, 0.0, 1.0, 1.0)); - depthColor = depthColorAttribute.value; - var bigRectangle = Rectangle.fromDegrees(-180 + CesiumMath.EPSILON4, -90 + CesiumMath.EPSILON4, 180 - CesiumMath.EPSILON4, 90 - CesiumMath.EPSILON4); + function view3DTilesPrimitive() { + scene.camera.setView({ destination : tilesetRectangle }); + } - reusablePrimitive = new Primitive({ - geometryInstances : new GeometryInstance({ - geometry : new RectangleGeometry({ - ellipsoid : ellipsoid, - rectangle : bigRectangle - }), - id : 'depth rectangle', - attributes : { - color : depthColorAttribute - } - }), - appearance : new PerInstanceColorAppearance({ - translucent : false, - flat : true - }), - asynchronous : false + function createPrimitive(rectangle, pass) { + var renderState; + if (pass === Pass.CESIUM_3D_TILE) { + renderState = RenderState.fromCache({ + stencilTest : StencilConstants.setCesium3DTileBit(), + stencilMask : StencilConstants.CESIUM_3D_TILE_MASK, + depthTest : { + enabled : true + } }); + } + var depthColorAttribute = ColorGeometryInstanceAttribute.fromColor(new Color(0.0, 0.0, 1.0, 1.0)); + depthColor = depthColorAttribute.value; + return new Primitive({ + geometryInstances : new GeometryInstance({ + geometry : new RectangleGeometry({ + ellipsoid : Ellipsoid.WGS84, + rectangle : rectangle + }), + id : 'depth rectangle', + attributes : { + color : depthColorAttribute + } + }), + appearance : new PerInstanceColorAppearance({ + translucent : false, + flat : true, + renderState : renderState + }), + asynchronous : false }); - }); - - afterAll(function() { - reusablePrimitive.destroy(); - scene.destroyForSpecs(); - // Leave ground primitive uninitialized - ApproximateTerrainHeights._initPromise = undefined; - ApproximateTerrainHeights._terrainHeights = undefined; - }); + } - function MockGlobePrimitive(primitive) { + function MockPrimitive(primitive, pass) { this._primitive = primitive; - this.pass = Pass.GLOBE; + this._pass = pass; } - MockGlobePrimitive.prototype.update = function(frameState) { + MockPrimitive.prototype.update = function(frameState) { var commandList = frameState.commandList; var startLength = commandList.length; this._primitive.update(frameState); for (var i = startLength; i < commandList.length; ++i) { var command = commandList[i]; - command.pass = this.pass; + command.pass = this._pass; } }; - MockGlobePrimitive.prototype.isDestroyed = function() { + MockPrimitive.prototype.isDestroyed = function() { return false; }; - MockGlobePrimitive.prototype.destroy = function() { + MockPrimitive.prototype.destroy = function() { return destroyObject(this); }; + beforeAll(function() { + scene = createScene(); + + scene.postProcessStages.fxaa.enabled = false; + + context = scene.context; + + ellipsoid = Ellipsoid.WGS84; + + rectangle = Rectangle.fromDegrees(-80.0, 20.0, -70.0, 30.0); + globeRectangle = Rectangle.fromDegrees(-80.0, 25.0, -70.0, 30.0); + tilesetRectangle = Rectangle.fromDegrees(-80.0, 20.0, -70.0, 25.0); + + reusableGlobePrimitive = createPrimitive(globeRectangle, Pass.GLOBE); + reusableTilesetPrimitive = createPrimitive(tilesetRectangle, Pass.CESIUM_3D_TILE); + + return GroundPrimitive.initializeTerrainHeights(); + }); + + afterAll(function() { + reusableGlobePrimitive.destroy(); + reusableTilesetPrimitive.destroy(); + scene.destroyForSpecs(); + // Leave ground primitive uninitialized + ApproximateTerrainHeights._initPromise = undefined; + ApproximateTerrainHeights._terrainHeights = undefined; + }); + beforeEach(function() { scene.morphTo3D(0); scene.render(); // clear any afterRender commands - rectangle = Rectangle.fromDegrees(-80.0, 20.0, -70.0, 30.0); - - // wrap rectangle primitive so it gets executed during the globe pass to lay down depth - depthPrimitive = new MockGlobePrimitive(reusablePrimitive); + // wrap rectangle primitive so it gets executed during the globe pass or 3D Tiles pass to lay down depth + globePrimitive = new MockPrimitive(reusableGlobePrimitive, Pass.GLOBE); + tilesetPrimitive = new MockPrimitive(reusableTilesetPrimitive, Pass.CESIUM_3D_TILE); var rectColorAttribute = ColorGeometryInstanceAttribute.fromColor(new Color(1.0, 1.0, 0.0, 1.0)); rectColor = rectColorAttribute.value; @@ -155,9 +194,11 @@ defineSuite([ }); afterEach(function() { + scene.primitives.removeAll(); scene.groundPrimitives.removeAll(); primitive = primitive && !primitive.isDestroyed() && primitive.destroy(); - depthPrimitive = depthPrimitive && !depthPrimitive.isDestroyed() && depthPrimitive.destroy(); + globePrimitive = globePrimitive && !globePrimitive.isDestroyed() && globePrimitive.destroy(); + tilesetPrimitive = tilesetPrimitive && !tilesetPrimitive.isDestroyed() && tilesetPrimitive.destroy(); }); it('default constructs', function() { @@ -342,17 +383,43 @@ defineSuite([ expect(frameState.commandList.length).toEqual(0); }); - function verifyGroundPrimitiveRender(primitive, color) { - scene.camera.setView({ destination : rectangle }); + function expectRender(color) { + expect(scene).toRender(color); + } - scene.groundPrimitives.add(depthPrimitive); + function expectRenderBlank() { expect(scene).toRenderAndCall(function(rgba) { expect(rgba).not.toEqual([0, 0, 0, 255]); expect(rgba[0]).toEqual(0); }); + } + + function verifyGroundPrimitiveRender(primitive, color) { + scene.primitives.add(globePrimitive); + scene.primitives.add(tilesetPrimitive); + + view3DTilesPrimitive(); + expectRenderBlank(); scene.groundPrimitives.add(primitive); - expect(scene).toRender(color); + + primitive.classificationType = ClassificationType.BOTH; + view3DTilesPrimitive(); + expectRender(color); + viewGlobePrimitive(); + expectRender(color); + + primitive.classificationType = ClassificationType.CESIUM_3D_TILE; + view3DTilesPrimitive(); + expectRender(color); + viewGlobePrimitive(); + expectRenderBlank(); + + primitive.classificationType = ClassificationType.TERRAIN; + view3DTilesPrimitive(); + expectRenderBlank(); + viewGlobePrimitive(); + expectRender(color); } it('renders in 3D', function() { @@ -393,11 +460,8 @@ defineSuite([ scene.camera.setView({ destination : bigIdlRectangle }); - scene.groundPrimitives.add(depthPrimitive); - expect(scene).toRenderAndCall(function(rgba) { - expect(rgba).not.toEqual([0, 0, 0, 255]); - expect(rgba[0]).toEqual(0); - }); + scene.primitives.add(globePrimitive); + expectRenderBlank(); scene.groundPrimitives.add(primitive); expect(scene).toRender(rectColor); @@ -428,11 +492,8 @@ defineSuite([ scene.camera.setView({ destination : smallIdlRectangle }); - scene.groundPrimitives.add(depthPrimitive); - expect(scene).toRenderAndCall(function(rgba) { - expect(rgba).not.toEqual([0, 0, 0, 255]); - expect(rgba[0]).toEqual(0); - }); + scene.primitives.add(globePrimitive); + expectRenderBlank(); scene.groundPrimitives.add(primitive); expect(scene).toRender(rectColor); @@ -467,41 +528,22 @@ defineSuite([ }); describe('larger scene', function() { - // Screen space techniques may produce unexpected results with 1x1 canvasses + // Screen space techniques may produce unexpected results with 1x1 canvases var largeScene; var largeSceneReusablePrimitive; beforeAll(function() { largeScene = createScene({ canvas : createCanvas(2, 2) }); - - var depthColorAttribute = ColorGeometryInstanceAttribute.fromColor(new Color(0.0, 0.0, 1.0, 1.0)); - depthColor = depthColorAttribute.value; var bigRectangle = Rectangle.fromDegrees(-180 + CesiumMath.EPSILON4, -90 + CesiumMath.EPSILON4, 180 - CesiumMath.EPSILON4, 90 - CesiumMath.EPSILON4); - - largeSceneReusablePrimitive = new Primitive({ - geometryInstances : new GeometryInstance({ - geometry : new RectangleGeometry({ - ellipsoid : ellipsoid, - rectangle : bigRectangle - }), - id : 'depth rectangle', - attributes : { - color : depthColorAttribute - } - }), - appearance : new PerInstanceColorAppearance({ - translucent : false, - flat : true - }), - asynchronous : false - }); + largeSceneReusablePrimitive = createPrimitive(bigRectangle, Pass.GLOBE); }); afterAll(function() { largeSceneReusablePrimitive.destroy(); largeScene.destroyForSpecs(); }); afterEach(function(){ + largeScene.primitives.removeAll(); largeScene.groundPrimitives.removeAll(); }); @@ -511,15 +553,12 @@ defineSuite([ largeScene.postProcessStages.fxaa.enabled = false; largeScene.camera.setView({destination : destination}); - var largeSceneDepthPrimitive = new MockGlobePrimitive(largeSceneReusablePrimitive); + var largeSceneDepthPrimitive = new MockPrimitive(largeSceneReusablePrimitive); - largeScene.groundPrimitives.add(largeSceneDepthPrimitive); - expect(largeScene).toRenderAndCall(function(rgba) { - expect(arraySlice(rgba, 0, 4)).not.toEqual([0, 0, 0, 255]); - expect(rgba[0]).toEqual(0); - }); + largeScene.primitives.add(largeSceneDepthPrimitive); + expectRenderBlank(); - largeScene.groundPrimitives.add(groundPrimitive); + largeScene.primitives.add(groundPrimitive); expect(largeScene).toRenderAndCall(function(rgba) { expect(arraySlice(rgba, 0, 4)).toEqual(expectedColor); });