Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
austinEng committed Jan 13, 2017
1 parent 76c33a2 commit 9578b57
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -1433,19 +1433,19 @@ define([
var sp = defaultValue(shaderProgram, command.shaderProgram);
var fs = sp.fragmentShaderSource.clone();

var colorTargets = [];
var targets = [];
fs.sources = fs.sources.map(function(source) {
source = ShaderSource.replaceMain(source, 'czm_Debug_main');
var re = /gl_FragData\[(\d+)\]/g;
var match;
while ((match = re.exec(source)) !== null) {
if (colorTargets.indexOf(match[1]) === -1) {
colorTargets.push(match[1]);
if (targets.indexOf(match[1]) === -1) {
targets.push(match[1]);
}
}
return source;
});
var length = colorTargets.length;
var length = targets.length;

var newMain =
'void main() \n' +
Expand All @@ -1459,7 +1459,7 @@ define([
var c = command._debugColor;
if (length) {
for (var i = 0; i < length; ++i) {
newMain += ' gl_FragData[' + colorTargets[i] + '].rgb *= vec3(' + c.red + ', ' + c.green + ', ' + c.blue + '); \n';
newMain += ' gl_FragData[' + targets[i] + '].rgb *= vec3(' + c.red + ', ' + c.green + ', ' + c.blue + '); \n';
}
} else {
newMain += ' ' + 'gl_FragColor' + '.rgb *= vec3(' + c.red + ', ' + c.green + ', ' + c.blue + '); \n';
Expand All @@ -1474,7 +1474,7 @@ define([
var b = (command.debugOverlappingFrustums & (1 << 2)) ? '1.0' : '0.0';
if (length) {
for (var i = 0; i < length; ++i) {
newMain += ' gl_FragData[' + colorTargets[i] + '].rgb *= vec3(' + r + ', ' + g + ', ' + b + '); \n';
newMain += ' gl_FragData[' + targets[i] + '].rgb *= vec3(' + r + ', ' + g + ', ' + b + '); \n';
}
} else {
newMain += ' ' + 'gl_FragColor' + '.rgb *= vec3(' + r + ', ' + g + ', ' + b + '); \n';
Expand Down
44 changes: 44 additions & 0 deletions Specs/Scene/SceneSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -873,4 +873,48 @@ defineSuite([
expect(s.maximumCubeMapSize).toBeGreaterThanOrEqualTo(16);
s.destroyForSpecs();
});

it('does not throw with debugShowCommands', function() {
var s = createScene();
if (s.context.drawBuffers) {
s.debugShowCommands = true;

var rectangle = Rectangle.fromDegrees(-100.0, 30.0, -90.0, 40.0);

var rectanglePrimitive = createRectangle(rectangle, 1000.0);
rectanglePrimitive.appearance.material.uniforms.color = new Color(1.0, 0.0, 0.0, 0.5);

var primitives = s.primitives;
primitives.add(rectanglePrimitive);

s.camera.setView({ destination : rectangle });

expect(function() {
s.renderForSpecs();
}).not.toThrowRuntimeError();
}
s.destroyForSpecs();
});

it('does not throw with debugShowFrustums', function() {
var s = createScene();
if (s.context.drawBuffers) {
s.debugShowFrustums = true;

var rectangle = Rectangle.fromDegrees(-100.0, 30.0, -90.0, 40.0);

var rectanglePrimitive = createRectangle(rectangle, 1000.0);
rectanglePrimitive.appearance.material.uniforms.color = new Color(1.0, 0.0, 0.0, 0.5);

var primitives = s.primitives;
primitives.add(rectanglePrimitive);

s.camera.setView({ destination : rectangle });

expect(function() {
s.renderForSpecs();
}).not.toThrowRuntimeError();
}
s.destroyForSpecs();
});
}, 'WebGL');

0 comments on commit 9578b57

Please sign in to comment.