Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write to gl_FragData instead of gl_FragColor for debug commands if MRT is used #4864

Merged
merged 4 commits into from
Jan 16, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -1433,22 +1433,38 @@ define([
var sp = defaultValue(shaderProgram, command.shaderProgram);
var fs = sp.fragmentShaderSource.clone();

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 (targets.indexOf(match[1]) === -1) {
targets.push(match[1]);
}
}
return source;
});
var length = targets.length;

var newMain =
'void main() \n' +
'{ \n' +
' czm_Debug_main(); \n';

var i;
if (scene.debugShowCommands) {
if (!defined(command._debugColor)) {
command._debugColor = Color.fromRandom();
}
var c = command._debugColor;
newMain += ' gl_FragColor.rgb *= vec3(' + c.red + ', ' + c.green + ', ' + c.blue + '); \n';
if (length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below, we are usually more explicit, e.g., length > 0

for (i = 0; i < length; ++i) {
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';
}
}

if (scene.debugShowFrustums) {
Expand All @@ -1457,7 +1473,13 @@ define([
var r = (command.debugOverlappingFrustums & (1 << 0)) ? '1.0' : '0.0';
var g = (command.debugOverlappingFrustums & (1 << 1)) ? '1.0' : '0.0';
var b = (command.debugOverlappingFrustums & (1 << 2)) ? '1.0' : '0.0';
newMain += ' gl_FragColor.rgb *= vec3(' + r + ', ' + g + ', ' + b + '); \n';
if (length) {
for (i = 0; i < length; ++i) {
newMain += ' gl_FragData[' + targets[i] + '].rgb *= vec3(' + r + ', ' + g + ', ' + b + '); \n';
}
} else {
newMain += ' ' + 'gl_FragColor' + '.rgb *= vec3(' + r + ', ' + g + ', ' + b + '); \n';
}
}

newMain += '}';
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');