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 all 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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Change Log
* Fixed KML for when color is an empty string [#4826](https://github.com/AnalyticalGraphicsInc/cesium/pull/4826)
* Added support for WMS version 1.3 by using CRS vice SRS query string parameter to request projection. SRS is still used for older versions.
* The attribute `perInstanceAttribute` of `DebugAppearance` has been made optional and defaults to `false`.
* Fixed a bug that would cause a crash when `debugShowFrustums` is enabled with OIT [#4864](https://github.com/AnalyticalGraphicsInc/cesium/pull/4864)

### 1.29 - 2017-01-02
* Improved 3D Models
Expand Down
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 > 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 > 0) {
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');