Skip to content

Commit

Permalink
Merge pull request #3787 from lasalvavida/specs-refactor
Browse files Browse the repository at this point in the history
Specs refactor
  • Loading branch information
lilleyse committed Mar 29, 2016
2 parents 5a0fd8e + d81c05b commit 26e081f
Show file tree
Hide file tree
Showing 5 changed files with 397 additions and 471 deletions.
2 changes: 1 addition & 1 deletion Source/Scene/DebugAppearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ define([
var getColor;

// Well-known normalized vector attributes in VertexFormat
if ((attributeName === 'normal') || (attributeName === 'binormal') | (attributeName === 'tangent')) {
if ((attributeName === 'normal') || (attributeName === 'binormal') || (attributeName === 'tangent')) {
getColor = 'vec4 getColor() { return vec4((' + varyingName + ' + vec3(1.0)) * 0.5, 1.0); }\n';
} else {
// All other attributes, both well-known and custom
Expand Down
120 changes: 47 additions & 73 deletions Specs/Scene/DebugAppearanceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ defineSuite([
'Renderer/ClearCommand',
'Scene/Appearance',
'Scene/Primitive',
'Specs/createContext',
'Specs/createFrameState',
'Specs/render'
'Specs/createScene'
], function(
DebugAppearance,
ComponentDatatype,
Expand All @@ -26,29 +24,30 @@ defineSuite([
ClearCommand,
Appearance,
Primitive,
createContext,
createFrameState,
render) {
createScene) {
'use strict';

var context;
var frameState;
var scene;
var primitive;
var rectangle = Rectangle.fromDegrees(-10.0, -10.0, 10.0, 10.0);

beforeAll(function() {
context = createContext();
scene = createScene();
scene.primitives.destroyPrimitives = false;
scene.frameState.scene3DOnly = false;
});

beforeEach(function() {
frameState = createFrameState(context);

frameState.camera.setView({ destination : rectangle });
var us = context.uniformState;
us.update(frameState);
scene.camera.setView({ destination : rectangle });
});

afterAll(function() {
context.destroyForSpecs();
scene.destroyForSpecs();
});

afterEach(function() {
scene.primitives.removeAll();
primitive = primitive && !primitive.isDestroyed() && primitive.destroy();
});

function createInstance(vertexFormat) {
Expand Down Expand Up @@ -183,7 +182,7 @@ defineSuite([
position : true,
normal : true
});
var primitive = new Primitive({
primitive = new Primitive({
geometryInstances : createInstance(vertexFormat),
appearance : new DebugAppearance({
attributeName : 'normal'
Expand All @@ -192,13 +191,10 @@ defineSuite([
compressVertices : false
});

ClearCommand.ALL.execute(context);
expect(context.readPixels()).toEqual([0, 0, 0, 0]);

render(frameState, primitive);
expect(context.readPixels()).not.toEqual([0, 0, 0, 0]);
expect(scene.renderForSpecs()).toEqual([0, 0, 0, 255]);

primitive = primitive && primitive.destroy();
scene.primitives.add(primitive);
expect(scene.renderForSpecs()).not.toEqual([0, 0, 0, 255]);
});

it('renders binormal', function() {
Expand All @@ -207,7 +203,7 @@ defineSuite([
normal : true,
binormal : true
});
var primitive = new Primitive({
primitive = new Primitive({
geometryInstances : createInstance(vertexFormat),
appearance : new DebugAppearance({
attributeName : 'binormal'
Expand All @@ -216,13 +212,10 @@ defineSuite([
compressVertices : false
});

ClearCommand.ALL.execute(context);
expect(context.readPixels()).toEqual([0, 0, 0, 0]);
expect(scene.renderForSpecs()).toEqual([0, 0, 0, 255]);

render(frameState, primitive);
expect(context.readPixels()).not.toEqual([0, 0, 0, 0]);

primitive = primitive && primitive.destroy();
scene.primitives.add(primitive);
expect(scene.renderForSpecs()).not.toEqual([0, 0, 0, 255]);
});

it('renders tangent', function() {
Expand All @@ -231,7 +224,7 @@ defineSuite([
normal : true,
tangent : true
});
var primitive = new Primitive({
primitive = new Primitive({
geometryInstances : createInstance(vertexFormat),
appearance : new DebugAppearance({
attributeName : 'tangent'
Expand All @@ -240,21 +233,18 @@ defineSuite([
compressVertices : false
});

ClearCommand.ALL.execute(context);
expect(context.readPixels()).toEqual([0, 0, 0, 0]);

render(frameState, primitive);
expect(context.readPixels()).not.toEqual([0, 0, 0, 0]);
expect(scene.renderForSpecs()).toEqual([0, 0, 0, 255]);

primitive = primitive && primitive.destroy();
scene.primitives.add(primitive);
expect(scene.renderForSpecs()).not.toEqual([0, 0, 0, 255]);
});

it('renders st', function() {
var vertexFormat = new VertexFormat({
position : true,
st : true
});
var primitive = new Primitive({
primitive = new Primitive({
geometryInstances : createInstance(vertexFormat),
appearance : new DebugAppearance({
attributeName : 'st'
Expand All @@ -263,13 +253,10 @@ defineSuite([
compressVertices : false
});

ClearCommand.ALL.execute(context);
expect(context.readPixels()).toEqual([0, 0, 0, 0]);

render(frameState, primitive);
expect(context.readPixels()).not.toEqual([0, 0, 0, 0]);
expect(scene.renderForSpecs()).toEqual([0, 0, 0, 255]);

primitive = primitive && primitive.destroy();
scene.primitives.add(primitive);
expect(scene.renderForSpecs()).not.toEqual([0, 0, 0, 255]);
});

it('renders float', function() {
Expand All @@ -281,7 +268,7 @@ defineSuite([
value : [1.0]
})
};
var primitive = new Primitive({
primitive = new Primitive({
geometryInstances : rectangleInstance,
appearance : new DebugAppearance({
attributeName : 'debug',
Expand All @@ -290,13 +277,10 @@ defineSuite([
asynchronous : false
});

ClearCommand.ALL.execute(context);
expect(context.readPixels()).toEqual([0, 0, 0, 0]);
expect(scene.renderForSpecs()).toEqual([0, 0, 0, 255]);

render(frameState, primitive);
expect(context.readPixels()).not.toEqual([0, 0, 0, 0]);

primitive = primitive && primitive.destroy();
scene.primitives.add(primitive);
expect(scene.renderForSpecs()).not.toEqual([0, 0, 0, 255]);
});

it('renders vec2', function() {
Expand All @@ -308,7 +292,7 @@ defineSuite([
value : [1.0, 2.0]
})
};
var primitive = new Primitive({
primitive = new Primitive({
geometryInstances : rectangleInstance,
appearance : new DebugAppearance({
attributeName : 'debug',
Expand All @@ -317,13 +301,10 @@ defineSuite([
asynchronous : false
});

ClearCommand.ALL.execute(context);
expect(context.readPixels()).toEqual([0, 0, 0, 0]);

render(frameState, primitive);
expect(context.readPixels()).not.toEqual([0, 0, 0, 0]);
expect(scene.renderForSpecs()).toEqual([0, 0, 0, 255]);

primitive = primitive && primitive.destroy();
scene.primitives.add(primitive);
expect(scene.renderForSpecs()).not.toEqual([0, 0, 0, 255]);
});

it('renders vec3', function() {
Expand All @@ -335,7 +316,7 @@ defineSuite([
value : [1.0, 2.0, 3.0]
})
};
var primitive = new Primitive({
primitive = new Primitive({
geometryInstances : rectangleInstance,
appearance : new DebugAppearance({
attributeName : 'debug',
Expand All @@ -344,40 +325,33 @@ defineSuite([
asynchronous : false
});

ClearCommand.ALL.execute(context);
expect(context.readPixels()).toEqual([0, 0, 0, 0]);

render(frameState, primitive);
expect(context.readPixels()).not.toEqual([0, 0, 0, 0]);
expect(scene.renderForSpecs()).toEqual([0, 0, 0, 255]);

primitive = primitive && primitive.destroy();
scene.primitives.add(primitive);
expect(scene.renderForSpecs()).not.toEqual([0, 0, 0, 255]);
});

it('renders vec4', function() {
var rectangleInstance = createInstance();
rectangleInstance.attributes = {
debug : new GeometryInstanceAttribute({
componentDatatype : ComponentDatatype.FLOAT,
componentsPerAttribute : 3,
componentsPerAttribute : 4,
value : [1.0, 2.0, 3.0, 4.0]
})
};
var primitive = new Primitive({
primitive = new Primitive({
geometryInstances : rectangleInstance,
appearance : new DebugAppearance({
attributeName : 'debug',
glslDatatype : 'vec4'
}),
asynchronous : false
});
expect(scene.renderForSpecs()).toEqual([0, 0, 0, 255]);

ClearCommand.ALL.execute(context);
expect(context.readPixels()).toEqual([0, 0, 0, 0]);

render(frameState, primitive);
expect(context.readPixels()).not.toEqual([0, 0, 0, 0]);

primitive = primitive && primitive.destroy();
scene.primitives.add(primitive);
expect(scene.renderForSpecs()).not.toEqual([0, 0, 0, 255]);
});

}, 'WebGL');
Loading

0 comments on commit 26e081f

Please sign in to comment.