From effcecdc4b6aeb2ae672b0c64c8190402aecd168 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Mon, 17 Dec 2018 19:00:39 -0500 Subject: [PATCH] ClassificationPrimitive and GlobePrimitive tests --- Source/Scene/InvertClassification.js | 7 +- Source/Scene/Scene.js | 13 +- ...d3DModel3DTileContentClassificationSpec.js | 4 +- Specs/Scene/ClassificationPrimitiveSpec.js | 186 +++++++++----- Specs/Scene/GroundPrimitiveSpec.js | 229 +++++++++++------- 5 files changed, 294 insertions(+), 145 deletions(-) diff --git a/Source/Scene/InvertClassification.js b/Source/Scene/InvertClassification.js index c468b7c93660..25b4dff62510 100644 --- a/Source/Scene/InvertClassification.js +++ b/Source/Scene/InvertClassification.js @@ -112,7 +112,6 @@ define([ reference : 0, mask : StencilConstants.CLASSIFICATION_MASK }, - stencilMask : StencilConstants.CLASSIFICATION_MASK, blending : BlendingState.ALPHA_BLEND }; @@ -130,15 +129,19 @@ define([ reference : 0, mask : StencilConstants.CLASSIFICATION_MASK }, - stencilMask : StencilConstants.CLASSIFICATION_MASK, blending : BlendingState.ALPHA_BLEND }; + // Set the 3D Tiles bit when rendering back into the scene's framebuffer. This is only needed if + // invert classification does not use the scene's depth-stencil texture, which is the case if the invert + // classification color is translucent. var rsDefault = { depthMask : true, depthTest : { enabled : true }, + stencilTest : StencilConstants.setCesium3DTileBit(), + stencilMask : StencilConstants.CESIUM_3D_TILE_MASK, blending : BlendingState.ALPHA_BLEND }; diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index c144bbbd9c08..92823beab81b 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -46,6 +46,7 @@ define([ '../Renderer/Framebuffer', '../Renderer/Pass', '../Renderer/PixelDatatype', + '../Renderer/RenderState', '../Renderer/ShaderProgram', '../Renderer/ShaderSource', '../Renderer/Texture', @@ -76,6 +77,7 @@ define([ './SceneTransitioner', './ScreenSpaceCameraController', './ShadowMap', + './StencilConstants', './SunPostProcess', './TweenCollection', './View' @@ -127,6 +129,7 @@ define([ Framebuffer, Pass, PixelDatatype, + RenderState, ShaderProgram, ShaderSource, Texture, @@ -157,6 +160,7 @@ define([ SceneTransitioner, ScreenSpaceCameraController, ShadowMap, + StencilConstants, SunPostProcess, TweenCollection, View) { @@ -322,6 +326,12 @@ define([ this._stencilClearCommand = new ClearCommand({ stencil : 0 }); + this._classificationStencilClearCommand = new ClearCommand({ + stencil : 0, + renderState : RenderState.fromCache({ + stencilMask : StencilConstants.CLASSIFICATION_MASK + }) + }); this._depthOnlyRenderStateCache = {}; this._pickRenderStateCache = {}; @@ -2146,6 +2156,7 @@ define([ var useDepthPlane = environmentState.useDepthPlane; var clearDepth = scene._depthClearCommand; var clearStencil = scene._stencilClearCommand; + var clearClassificationStencil = scene._classificationStencilClearCommand; var depthPlane = scene._depthPlane; var usePostProcessSelected = environmentState.usePostProcessSelected; @@ -2304,7 +2315,7 @@ define([ // Clear stencil set by the classification for the next classification pass if (length > 0 && context.stencilBuffer) { - clearStencil.execute(context, passState); + clearClassificationStencil.execute(context, passState); } // Draw style over classification. diff --git a/Specs/Scene/Batched3DModel3DTileContentClassificationSpec.js b/Specs/Scene/Batched3DModel3DTileContentClassificationSpec.js index 4323cda58d68..5242838719b5 100644 --- a/Specs/Scene/Batched3DModel3DTileContentClassificationSpec.js +++ b/Specs/Scene/Batched3DModel3DTileContentClassificationSpec.js @@ -104,7 +104,7 @@ defineSuite([ asynchronous : false }); - this.pass = pass; + this._pass = pass; } MockPrimitive.prototype.update = function(frameState) { @@ -114,7 +114,7 @@ defineSuite([ for (var i = startLength; i < commandList.length; ++i) { var command = commandList[i]; - command.pass = this.pass; + command.pass = this._pass; } }; diff --git a/Specs/Scene/ClassificationPrimitiveSpec.js b/Specs/Scene/ClassificationPrimitiveSpec.js index e3c278aa3470..d1afb517bcea 100644 --- a/Specs/Scene/ClassificationPrimitiveSpec.js +++ b/Specs/Scene/ClassificationPrimitiveSpec.js @@ -13,11 +13,14 @@ defineSuite([ 'Core/ShowGeometryInstanceAttribute', 'Core/Transforms', 'Renderer/Pass', + 'Renderer/RenderState', + 'Scene/ClassificationType', 'Scene/InvertClassification', 'Scene/MaterialAppearance', 'Scene/PerInstanceColorAppearance', 'Scene/Primitive', 'Scene/ShadowVolumeAppearance', + 'Scene/StencilConstants', 'Specs/createScene', 'Specs/pollToPromise' ], function( @@ -35,11 +38,14 @@ defineSuite([ ShowGeometryInstanceAttribute, Transforms, Pass, + RenderState, + ClassificationType, InvertClassification, MaterialAppearance, PerInstanceColorAppearance, Primitive, ShadowVolumeAppearance, + StencilConstants, createScene, pollToPromise) { 'use strict'; @@ -54,72 +60,97 @@ defineSuite([ var boxInstance; var primitive; - var depthPrimitive; - - beforeAll(function() { - scene = createScene(); - scene.postProcessStages.fxaa.enabled = false; - - ellipsoid = Ellipsoid.WGS84; - }); - - afterAll(function() { - scene.destroyForSpecs(); - }); + var globePrimitive; + var tilesetPrimitive; + var reusableGlobePrimitive; + var reusableTilesetPrimitive; + + 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 + }); + } - function MockGlobePrimitive(primitive) { + function MockPrimitive(primitive, pass) { this._primitive = primitive; - this.pass = Pass.GLOBE; + this._pass = pass; + this.show = true; } - MockGlobePrimitive.prototype.update = function(frameState) { + MockPrimitive.prototype.update = function(frameState) { + if (!this.show) { + return; + } + 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() { - this._primitive.destroy(); + MockPrimitive.prototype.destroy = function() { 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); + reusableGlobePrimitive = createPrimitive(rectangle, Pass.GLOBE); + reusableTilesetPrimitive = createPrimitive(rectangle, Pass.CESIUM_3D_TILE); + }); - var depthColorAttribute = ColorGeometryInstanceAttribute.fromColor(new Color(0.0, 0.0, 1.0, 1.0)); - depthColor = depthColorAttribute.value; - var primitive = new Primitive({ - geometryInstances : new GeometryInstance({ - geometry : new RectangleGeometry({ - ellipsoid : ellipsoid, - rectangle : rectangle - }), - id : 'depth rectangle', - attributes : { - color : depthColorAttribute - } - }), - appearance : new PerInstanceColorAppearance({ - translucent : false, - flat : true - }), - asynchronous : false - }); + 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 to lay down depth - depthPrimitive = new MockGlobePrimitive(primitive); + // wrap rectangle primitive so it gets executed during the globe pass and 3D Tiles pass to lay down depth + globePrimitive = new MockPrimitive(reusableGlobePrimitive, Pass.GLOBE); + tilesetPrimitive = new MockPrimitive(reusableTilesetPrimitive, Pass.CESIUM_3D_TILE); var center = Rectangle.center(rectangle); var origin = ellipsoid.cartographicToCartesian(center); @@ -142,9 +173,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() { @@ -328,17 +361,53 @@ defineSuite([ expect(frameState.commandList.length).toEqual(0); }); - function verifyClassificationPrimitiveRender(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 verifyClassificationPrimitiveRender(primitive, color) { + scene.camera.setView({ destination : rectangle }); + + scene.primitives.add(globePrimitive); + scene.primitives.add(tilesetPrimitive); + + expectRenderBlank(); scene.groundPrimitives.add(primitive); - expect(scene).toRender(color); + + primitive.classificationType = ClassificationType.BOTH; + globePrimitive.show = false; + tilesetPrimitive.show = true; + expectRender(color); + globePrimitive.show = true; + tilesetPrimitive.show = false; + expectRender(color); + + primitive.classificationType = ClassificationType.CESIUM_3D_TILE; + globePrimitive.show = false; + tilesetPrimitive.show = true; + expectRender(color); + globePrimitive.show = true; + tilesetPrimitive.show = false; + expectRenderBlank(); + + primitive.classificationType = ClassificationType.TERRAIN; + globePrimitive.show = false; + tilesetPrimitive.show = true; + expectRenderBlank(); + globePrimitive.show = true; + tilesetPrimitive.show = false; + expectRender(color); + + globePrimitive.show = true; + tilesetPrimitive.show = true; } it('renders in 3D', function() { @@ -450,7 +519,6 @@ defineSuite([ scene.invertClassification = true; scene.invertClassificationColor = new Color(0.25, 0.25, 0.25, 1.0); - depthPrimitive.pass = Pass.CESIUM_3D_TILE; boxInstance.attributes.show = new ShowGeometryInstanceAttribute(true); primitive = new ClassificationPrimitive({ @@ -466,7 +534,7 @@ defineSuite([ invertedColor[2] = Color.floatToByte(Color.byteToFloat(depthColor[2]) * scene.invertClassificationColor.blue); invertedColor[3] = 255; - scene.groundPrimitives.add(depthPrimitive); + scene.primitives.add(tilesetPrimitive); expect(scene).toRender(invertedColor); scene.groundPrimitives.add(primitive); @@ -490,7 +558,6 @@ defineSuite([ scene.invertClassification = true; scene.invertClassificationColor = new Color(0.25, 0.25, 0.25, 0.25); - depthPrimitive.pass = Pass.CESIUM_3D_TILE; boxInstance.attributes.show = new ShowGeometryInstanceAttribute(true); primitive = new ClassificationPrimitive({ @@ -506,7 +573,7 @@ defineSuite([ invertedColor[2] = Color.floatToByte(Color.byteToFloat(depthColor[2]) * scene.invertClassificationColor.blue * scene.invertClassificationColor.alpha); invertedColor[3] = 255; - scene.groundPrimitives.add(depthPrimitive); + scene.primitives.add(tilesetPrimitive); expect(scene).toRender(invertedColor); scene.groundPrimitives.add(primitive); @@ -588,6 +655,10 @@ defineSuite([ verifyClassificationPrimitiveRender(primitive, boxColor); + scene.primitives.destroyPrimitives = false; + scene.primitives.removeAll(); + scene.primitives.destroyPrimitives = true; + scene.groundPrimitives.destroyPrimitives = false; scene.groundPrimitives.removeAll(); scene.groundPrimitives.destroyPrimitives = true; @@ -614,6 +685,10 @@ defineSuite([ verifyClassificationPrimitiveRender(primitive, boxColor); + scene.primitives.destroyPrimitives = false; + scene.primitives.removeAll(); + scene.primitives.destroyPrimitives = true; + scene.groundPrimitives.destroyPrimitives = false; scene.groundPrimitives.removeAll(); scene.groundPrimitives.destroyPrimitives = true; @@ -688,9 +763,10 @@ defineSuite([ verifyClassificationPrimitiveRender(primitive, boxColor); expect(scene).toDrillPickAndCall(function(pickedObjects) { - expect(pickedObjects.length).toEqual(2); + expect(pickedObjects.length).toEqual(3); expect(pickedObjects[0].primitive).toEqual(primitive); - expect(pickedObjects[1].primitive).toEqual(depthPrimitive._primitive); + expect(pickedObjects[1].primitive).toEqual(globePrimitive._primitive); + expect(pickedObjects[2].primitive).toEqual(tilesetPrimitive._primitive); }); }); @@ -970,7 +1046,7 @@ defineSuite([ }); scene.camera.setView({ destination : rectangle }); - scene.groundPrimitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); expect(scene).toRenderAndCall(function(rgba) { expect(rgba).not.toEqual([0, 0, 0, 255]); expect(rgba[0]).toEqual(0); diff --git a/Specs/Scene/GroundPrimitiveSpec.js b/Specs/Scene/GroundPrimitiveSpec.js index 9b6b81543666..65e592793db1 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) { @@ -63,82 +67,108 @@ defineSuite([ var rectangleInstance; var primitive; - var depthPrimitive; - var reusablePrimitive; - - beforeAll(function() { - scene = createScene(); - - scene.postProcessStages.fxaa.enabled = false; - - context = scene.context; - - 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); - - 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 + var globePrimitive; + var tilesetPrimitive; + var reusableGlobePrimitive; + var reusableTilesetPrimitive; + + 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; + this.show = true; } - MockGlobePrimitive.prototype.update = function(frameState) { + MockPrimitive.prototype.update = function(frameState) { + if (!this.show) { + return; + } + 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; + + var bigRectangle = Rectangle.fromDegrees(-180 + CesiumMath.EPSILON4, -90 + CesiumMath.EPSILON4, 180 - CesiumMath.EPSILON4, 90 - CesiumMath.EPSILON4); + reusableGlobePrimitive = createPrimitive(bigRectangle, Pass.GLOBE); + reusableTilesetPrimitive = createPrimitive(bigRectangle, 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 and 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 +185,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 +374,53 @@ 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.camera.setView({ destination : rectangle }); + + scene.primitives.add(globePrimitive); + scene.primitives.add(tilesetPrimitive); + + expectRenderBlank(); scene.groundPrimitives.add(primitive); - expect(scene).toRender(color); + + primitive.classificationType = ClassificationType.BOTH; + globePrimitive.show = false; + tilesetPrimitive.show = true; + expectRender(color); + globePrimitive.show = true; + tilesetPrimitive.show = false; + expectRender(color); + + primitive.classificationType = ClassificationType.CESIUM_3D_TILE; + globePrimitive.show = false; + tilesetPrimitive.show = true; + expectRender(color); + globePrimitive.show = true; + tilesetPrimitive.show = false; + expectRenderBlank(); + + primitive.classificationType = ClassificationType.TERRAIN; + globePrimitive.show = false; + tilesetPrimitive.show = true; + expectRenderBlank(); + globePrimitive.show = true; + tilesetPrimitive.show = false; + expectRender(color); + + globePrimitive.show = true; + tilesetPrimitive.show = true; } it('renders in 3D', function() { @@ -393,7 +461,7 @@ defineSuite([ scene.camera.setView({ destination : bigIdlRectangle }); - scene.groundPrimitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); expect(scene).toRenderAndCall(function(rgba) { expect(rgba).not.toEqual([0, 0, 0, 255]); expect(rgba[0]).toEqual(0); @@ -428,7 +496,7 @@ defineSuite([ scene.camera.setView({ destination : smallIdlRectangle }); - scene.groundPrimitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); expect(scene).toRenderAndCall(function(rgba) { expect(rgba).not.toEqual([0, 0, 0, 255]); expect(rgba[0]).toEqual(0); @@ -469,39 +537,24 @@ defineSuite([ describe('larger scene', function() { // Screen space techniques may produce unexpected results with 1x1 canvasses var largeScene; - var largeSceneReusablePrimitive; + var largeSceneReusableGlobePrimitive; + var largeSceneReusableTilesetPrimitive; 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 - }); + largeSceneReusableGlobePrimitive = createPrimitive(bigRectangle, Pass.GLOBE); + largeSceneReusableTilesetPrimitive = createPrimitive(bigRectangle, Pass.CESIUM_3D_TILE); }); afterAll(function() { - largeSceneReusablePrimitive.destroy(); + largeSceneReusableGlobePrimitive.destroy(); + largeSceneReusableTilesetPrimitive.destroy(); largeScene.destroyForSpecs(); }); afterEach(function(){ + largeScene.primitives.removeAll(); largeScene.groundPrimitives.removeAll(); }); @@ -511,9 +564,9 @@ defineSuite([ largeScene.postProcessStages.fxaa.enabled = false; largeScene.camera.setView({destination : destination}); - var largeSceneDepthPrimitive = new MockGlobePrimitive(largeSceneReusablePrimitive); + var largeSceneGlobePrimitive = new MockPrimitive(largeSceneReusableGlobePrimitive, Pass.GLOBE); - largeScene.groundPrimitives.add(largeSceneDepthPrimitive); + largeScene.primitives.add(largeSceneGlobePrimitive); expect(largeScene).toRenderAndCall(function(rgba) { expect(arraySlice(rgba, 0, 4)).not.toEqual([0, 0, 0, 255]); expect(rgba[0]).toEqual(0); @@ -696,7 +749,6 @@ defineSuite([ scene.invertClassification = true; scene.invertClassificationColor = new Color(0.25, 0.25, 0.25, 1.0); - depthPrimitive.pass = Pass.CESIUM_3D_TILE; rectangleInstance.attributes.show = new ShowGeometryInstanceAttribute(true); primitive = new GroundPrimitive({ @@ -713,7 +765,7 @@ defineSuite([ invertedColor[2] = Color.floatToByte(Color.byteToFloat(depthColor[2]) * scene.invertClassificationColor.blue); invertedColor[3] = 255; - scene.groundPrimitives.add(depthPrimitive); + scene.primitives.add(tilesetPrimitive); expect(scene).toRender(invertedColor); scene.groundPrimitives.add(primitive); @@ -737,7 +789,6 @@ defineSuite([ scene.invertClassification = true; scene.invertClassificationColor = new Color(0.25, 0.25, 0.25, 0.25); - depthPrimitive.pass = Pass.CESIUM_3D_TILE; rectangleInstance.attributes.show = new ShowGeometryInstanceAttribute(true); primitive = new GroundPrimitive({ @@ -754,7 +805,7 @@ defineSuite([ invertedColor[2] = Color.floatToByte(Color.byteToFloat(depthColor[2]) * scene.invertClassificationColor.blue * scene.invertClassificationColor.alpha); invertedColor[3] = 255; - scene.groundPrimitives.add(depthPrimitive); + scene.primitives.add(tilesetPrimitive); expect(scene).toRender(invertedColor); scene.groundPrimitives.add(primitive); @@ -836,6 +887,10 @@ defineSuite([ verifyGroundPrimitiveRender(primitive, rectColor); + scene.primitives.destroyPrimitives = false; + scene.primitives.removeAll(); + scene.primitives.destroyPrimitives = true; + scene.groundPrimitives.destroyPrimitives = false; scene.groundPrimitives.removeAll(); scene.groundPrimitives.destroyPrimitives = true; @@ -862,6 +917,10 @@ defineSuite([ verifyGroundPrimitiveRender(primitive, rectColor); + scene.primitives.destroyPrimitives = false; + scene.primitives.removeAll(); + scene.primitives.destroyPrimitives = true; + scene.groundPrimitives.destroyPrimitives = false; scene.groundPrimitives.removeAll(); scene.groundPrimitives.destroyPrimitives = true; @@ -904,7 +963,7 @@ defineSuite([ asynchronous : false }); - scene.groundPrimitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); scene.groundPrimitives.add(primitive); scene.camera.setView({ destination : rect }); scene.renderForSpecs();