Skip to content

Commit

Permalink
Merge pull request #7251 from OmarShehata/speed-up-tests
Browse files Browse the repository at this point in the history
Speed up GroundPrimitive tests
  • Loading branch information
likangning93 authored Nov 16, 2018
2 parents 0193a52 + 020ea64 commit 9c60b85
Showing 1 changed file with 56 additions and 64 deletions.
120 changes: 56 additions & 64 deletions Specs/Scene/GroundPrimitiveSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,44 @@ 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();
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
});
});
});

afterAll(function() {
reusablePrimitive.destroy();
scene.destroyForSpecs();

// Leave ground primitive uninitialized
ApproximateTerrainHeights._initPromise = undefined;
ApproximateTerrainHeights._terrainHeights = undefined;
Expand All @@ -104,7 +128,6 @@ defineSuite([
};

MockGlobePrimitive.prototype.destroy = function() {
this._primitive.destroy();
return destroyObject(this);
};

Expand All @@ -114,28 +137,8 @@ defineSuite([

rectangle = Rectangle.fromDegrees(-80.0, 20.0, -70.0, 30.0);

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.fromDegrees(-180 + CesiumMath.EPSILON4, -90 + CesiumMath.EPSILON4, 180 - CesiumMath.EPSILON4, 90 - CesiumMath.EPSILON4)
}),
id : 'depth rectangle',
attributes : {
color : depthColorAttribute
}
}),
appearance : new PerInstanceColorAppearance({
translucent : false,
flat : true
}),
asynchronous : false
});

// wrap rectangle primitive so it gets executed during the globe pass to lay down depth
depthPrimitive = new MockGlobePrimitive(primitive);
depthPrimitive = new MockGlobePrimitive(reusablePrimitive);

var rectColorAttribute = ColorGeometryInstanceAttribute.fromColor(new Color(1.0, 1.0, 0.0, 1.0));
rectColor = rectColorAttribute.value;
Expand Down Expand Up @@ -303,9 +306,10 @@ defineSuite([
}

primitive = scene.groundPrimitives.add(new GroundPrimitive({
geometryInstances : rectangleInstance
geometryInstances : rectangleInstance,
asynchronous : false,
show : false
}));
primitive.show = false;

var ready = false;
primitive.readyPromise.then(function() {
Expand Down Expand Up @@ -463,41 +467,51 @@ defineSuite([
});

describe('larger scene', function() {
// Screen space techniques may produce unexpected results with 1x1 canvasses
var largeScene;
beforeEach(function() {
var largeSceneReusablePrimitive;
beforeAll(function() {
largeScene = createScene({
canvas : createCanvas(2, 2)
});
});

afterEach(function() {
largeScene.destroyForSpecs();
});
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);

// Screen space techniques may produce unexpected results with 1x1 canvasses
function verifyLargerScene(groundPrimitive, expectedColor, destination) {
largeScene.render();

largeScene.postProcessStages.fxaa.enabled = false;
largeScene.camera.setView({destination : destination});

var largeSceneDepthPrimitive = new MockGlobePrimitive(new Primitive({
largeSceneReusablePrimitive = new Primitive({
geometryInstances : new GeometryInstance({
geometry : new RectangleGeometry({
ellipsoid : ellipsoid,
rectangle : Rectangle.fromDegrees(-180 + CesiumMath.EPSILON4, -90 + CesiumMath.EPSILON4, 180 - CesiumMath.EPSILON4, 90 - CesiumMath.EPSILON4)
rectangle : bigRectangle
}),
id : 'depth rectangle',
attributes : {
color : ColorGeometryInstanceAttribute.fromColor(new Color(0.0, 0.0, 1.0, 1.0))
color : depthColorAttribute
}
}),
appearance : new PerInstanceColorAppearance({
translucent : false,
flat : true
}),
asynchronous : false
}));
});
});
afterAll(function() {
largeSceneReusablePrimitive.destroy();
largeScene.destroyForSpecs();
});
afterEach(function(){
largeScene.groundPrimitives.removeAll();
});

function verifyLargerScene(groundPrimitive, expectedColor, destination) {
largeScene.render();

largeScene.postProcessStages.fxaa.enabled = false;
largeScene.camera.setView({destination : destination});

var largeSceneDepthPrimitive = new MockGlobePrimitive(largeSceneReusablePrimitive);

largeScene.groundPrimitives.add(largeSceneDepthPrimitive);
expect(largeScene).toRenderAndCall(function(rgba) {
Expand Down Expand Up @@ -871,28 +885,6 @@ defineSuite([
var near = 10000.0;
var far = 1000000.0;
var rect = Rectangle.fromDegrees(-1.0, -1.0, 1.0, 1.0);
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
});

// wrap rectangle primitive so it gets executed during the globe pass to lay down depth
depthPrimitive = new MockGlobePrimitive(primitive);

var rectColorAttribute = ColorGeometryInstanceAttribute.fromColor(new Color(1.0, 1.0, 0.0, 1.0));
var rectInstance = new GeometryInstance({
Expand Down

0 comments on commit 9c60b85

Please sign in to comment.