Skip to content

Commit

Permalink
Merge branch 'master' into preprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
bagnell committed Dec 17, 2013
2 parents 9a844ac + 28a048a commit 0083faf
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 72 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Beta Releases
* Added `Billboard.setPixelOffsetScaleByDistance`, `Label.setPixelOffsetScaleByDistance`, `DynamicBillboard.pixelOffsetScaleByDistance`, and `DynamicLabel.pixelOffsetScaleByDistance` to control minimum/maximum pixelOffset scaling based on camera distance.
* The `Viewer` widget now clears `Geocoder` input when the user clicks the home button.
* The `Geocoder` input type has been changed to `search`, which improves usability (particularly on mobile devices). There were also some other minor styling improvements.
* Fix disabling `CentralBody.enableLighting`.

### b23 - 2013-12-02

Expand Down
11 changes: 5 additions & 6 deletions Source/Renderer/ShaderCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ define([

if (this._shaders[keyword]) {
cachedShader = this._shaders[keyword];

// No longer want to release this if it was previously released.
delete this._shadersToRelease[keyword];
} else {
var sp = this._context.createShaderProgram(vertexShaderSource, fragmentShaderSource, attributeLocations);

Expand Down Expand Up @@ -96,13 +99,9 @@ define([

for ( var keyword in shadersToRelease) {
if (shadersToRelease.hasOwnProperty(keyword)) {
// Check the count again here because the shader may have been requested
// after it was released, in which case, we are avoiding thrashing the cache.
var cachedShader = shadersToRelease[keyword];
if (cachedShader.count === 0) {
delete this._shaders[cachedShader.keyword];
cachedShader.shaderProgram.destroy();
}
delete this._shaders[cachedShader.keyword];
cachedShader.shaderProgram.destroy();
}
}

Expand Down
1 change: 1 addition & 0 deletions Source/Scene/CentralBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ define([

this._showingPrettyOcean = defined(this._oceanNormalMap);
this._hasWaterMask = hasWaterMask;
this._enableLighting = this.enableLighting;
}

var cameraPosition = frameState.camera.positionWC;
Expand Down
34 changes: 23 additions & 11 deletions Source/Scene/OrthographicFrustum.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,20 +316,32 @@ define([

/**
* Returns a duplicate of a OrthographicFrustum instance.
*
* @memberof OrthographicFrustum
*
* @returns {OrthographicFrustum} A new copy of the OrthographicFrustum instance.
* @param {OrthographicFrustum} [result] The object onto which to store the result.
* @returns {OrthographicFrustum} The modified result parameter or a new PerspectiveFrustum instance if one was not provided.
*/
OrthographicFrustum.prototype.clone = function() {
var frustum = new OrthographicFrustum();
frustum.left = this.left;
frustum.right = this.right;
frustum.top = this.top;
frustum.bottom = this.bottom;
frustum.near = this.near;
frustum.far = this.far;
return frustum;
OrthographicFrustum.prototype.clone = function(result) {
if (!defined(result)) {
result = new OrthographicFrustum();
}

result.left = this.left;
result.right = this.right;
result.top = this.top;
result.bottom = this.bottom;
result.near = this.near;
result.far = this.far;

// force update of clone to compute matrices
result._left = undefined;
result._right = undefined;
result._top = undefined;
result._bottom = undefined;
result._near = undefined;
result._far = undefined;

return result;
};

/**
Expand Down
31 changes: 21 additions & 10 deletions Source/Scene/PerspectiveFrustum.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,30 @@ define([

/**
* Returns a duplicate of a PerspectiveFrustum instance.
*
* @memberof PerspectiveFrustum
*
* @returns {PerspectiveFrustum} A new copy of the PerspectiveFrustum instance.
* @param {PerspectiveFrustum} [result] The object onto which to store the result.
* @returns {PerspectiveFrustum} The modified result parameter or a new PerspectiveFrustum instance if one was not provided.
*/
PerspectiveFrustum.prototype.clone = function() {
var frustum = new PerspectiveFrustum();
frustum.fovy = this.fovy;
frustum.aspectRatio = this.aspectRatio;
frustum.near = this.near;
frustum.far = this.far;
frustum._offCenterFrustum = this._offCenterFrustum.clone();
return frustum;
PerspectiveFrustum.prototype.clone = function(result) {
if (!defined(result)) {
result = new PerspectiveFrustum();
}

result.fovy = this.fovy;
result.aspectRatio = this.aspectRatio;
result.near = this.near;
result.far = this.far;

// force update of clone to compute matrices
result._fovy = undefined;
result._aspectRatio = undefined;
result._near = undefined;
result._far = undefined;

this._offCenterFrustum.clone(result._offCenterFrustum);

return result;
};

/**
Expand Down
34 changes: 23 additions & 11 deletions Source/Scene/PerspectiveOffCenterFrustum.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,20 +375,32 @@ define([

/**
* Returns a duplicate of a PerspectiveOffCenterFrustum instance.
*
* @memberof PerspectiveOffCenterFrustum
*
* @returns {PerspectiveOffCenterFrustum} A new copy of the PerspectiveOffCenterFrustum instance.
* @param {PerspectiveOffCenterFrustum} [result] The object onto which to store the result.
* @returns {PerspectiveOffCenterFrustum} The modified result parameter or a new PerspectiveFrustum instance if one was not provided.
*/
PerspectiveOffCenterFrustum.prototype.clone = function() {
var frustum = new PerspectiveOffCenterFrustum();
frustum.right = this.right;
frustum.left = this.left;
frustum.top = this.top;
frustum.bottom = this.bottom;
frustum.near = this.near;
frustum.far = this.far;
return frustum;
PerspectiveOffCenterFrustum.prototype.clone = function(result) {
if (!defined(result)) {
result = new PerspectiveOffCenterFrustum();
}

result.right = this.right;
result.left = this.left;
result.top = this.top;
result.bottom = this.bottom;
result.near = this.near;
result.far = this.far;

// force update of clone to compute matrices
result._left = undefined;
result._right = undefined;
result._top = undefined;
result._bottom = undefined;
result._near = undefined;
result._far = undefined;

return result;
};

/**
Expand Down
100 changes: 71 additions & 29 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ define([
'./SceneTransforms',
'./FrameState',
'./OrthographicFrustum',
'./PerspectiveFrustum',
'./PerspectiveOffCenterFrustum',
'./FrustumCommands',
'./Primitive',
Expand Down Expand Up @@ -75,6 +76,7 @@ define([
SceneTransforms,
FrameState,
OrthographicFrustum,
PerspectiveFrustum,
PerspectiveOffCenterFrustum,
FrustumCommands,
Primitive,
Expand Down Expand Up @@ -260,6 +262,20 @@ define([
*/
this.debugCommandFilter = undefined;

/**
* This property is for debugging only; it is not for production use.
* <p>
* When <code>true</code>, commands are randomly shaded. This is useful
* for performance analysis to see what parts of a scene or model are
* command-dense and could benefit from batching.
* </p>
*
* @type Boolean
*
* @default false
*/
this.debugShowCommands = false;

/**
* This property is for debugging only; it is not for production use.
* <p>
Expand Down Expand Up @@ -571,43 +587,58 @@ define([
}
}

function createFrustumDebugFragmentShaderSource(command) {
var fragmentShaderSource = command.shaderProgram.fragmentShaderSource;
var renamedFS = fragmentShaderSource.replace(/void\s+main\s*\(\s*(?:void)?\s*\)/g, 'void czm_frustumDebug_main()');
function getAttributeLocations(shaderProgram) {
var attributeLocations = {};
var attributes = shaderProgram.getVertexAttributes();
for (var a in attributes) {
if (attributes.hasOwnProperty(a)) {
attributeLocations[a] = attributes[a].index;
}
}

// Support up to three frustums. If a command overlaps all
// three, it's code is not changed.
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';
return attributeLocations;
}

function createDebugFragmentShaderSource(command, scene) {
var fragmentShaderSource = command.shaderProgram.fragmentShaderSource;
var renamedFS = fragmentShaderSource.replace(/void\s+main\s*\(\s*(?:void)?\s*\)/g, 'void czm_Debug_main()');

var pickMain =
var newMain =
'void main() \n' +
'{ \n' +
' czm_frustumDebug_main(); \n' +
' gl_FragColor.rgb *= vec3(' + r + ', ' + g + ', ' + b + '); \n' +
'}';
' czm_Debug_main(); \n';

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 (scene.debugShowFrustums) {
// Support up to three frustums. If a command overlaps all
// three, it's code is not changed.
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';
}

return renamedFS + '\n' + pickMain;
newMain += '}';

return renamedFS + '\n' + newMain;
}

function executeFrustumDebugCommand(command, context, passState) {
function executeDebugCommand(command, scene, context, passState) {
if (defined(command.shaderProgram)) {
// Replace shader for frustum visualization
var sp = command.shaderProgram;
var attributeLocations = {};
var attributes = sp.getVertexAttributes();
for (var a in attributes) {
if (attributes.hasOwnProperty(a)) {
attributeLocations[a] = attributes[a].index;
}
}
var attributeLocations = getAttributeLocations(sp);

command.shaderProgram = context.getShaderCache().getShaderProgram(
sp.vertexShaderSource, createFrustumDebugFragmentShaderSource(command), attributeLocations);

sp.vertexShaderSource, createDebugFragmentShaderSource(command, scene), attributeLocations);
command.execute(context, passState);

command.shaderProgram.release();
command.shaderProgram = sp;
}
Expand All @@ -618,10 +649,10 @@ define([
return;
}

if (!scene.debugShowFrustums) {
command.execute(context, passState);
if (scene.debugShowCommands || scene.debugShowFrustums) {
executeDebugCommand(command, scene, context, passState);
} else {
executeFrustumDebugCommand(command, context, passState);
command.execute(context, passState);
}

if (command.debugShowBoundingVolume && (defined(command.boundingVolume))) {
Expand Down Expand Up @@ -681,13 +712,25 @@ define([
(!defined(occluder) || occluder.isBoundingSphereVisible(boundingVolume)))));
}

var scratchPerspectiveFrustum = new PerspectiveFrustum();
var scratchPerspectiveOffCenterFrustum = new PerspectiveOffCenterFrustum();
var scratchOrthographicFrustum = new OrthographicFrustum();

function executeCommands(scene, passState, clearColor) {
var frameState = scene._frameState;
var camera = scene._camera;
var frustum = camera.frustum.clone();
var context = scene._context;
var us = context.getUniformState();

var frustum;
if (defined(camera.frustum.fovy)) {
frustum = camera.frustum.clone(scratchPerspectiveFrustum);
} else if (defined(camera.frustum.infiniteProjectionMatrix)){
frustum = camera.frustum.clone(scratchPerspectiveOffCenterFrustum);
} else {
frustum = camera.frustum.clone(scratchOrthographicFrustum);
}

if (defined(scene.sun) && scene.sunBloom !== scene._sunBloom) {
if (scene.sunBloom) {
scene._sunPostProcess = new SunPostProcess();
Expand All @@ -706,7 +749,6 @@ define([
var sunCommand = (frameState.passes.color && defined(scene.sun)) ? scene.sun.update(context, frameState) : undefined;
var sunVisible = isVisible(sunCommand, frameState);


if (sunVisible && scene.sunBloom) {
passState.framebuffer = scene._sunPostProcess.update(context);
}
Expand Down
17 changes: 12 additions & 5 deletions Specs/Scene/OrthographicFrustumSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,22 @@ defineSuite([
expect(pixelSize.y).toEqual(2.0);
});

it('clone', function() {
var clone = frustum.clone();
expect(clone).toEqual(frustum);
});

it('throws with undefined frustum parameters', function() {
var frustum = new OrthographicFrustum();
expect(function() {
return frustum.projectionMatrix;
}).toThrow();
});

it('clone', function() {
var frustum2 = frustum.clone();
expect(frustum).toEqual(frustum2);
});

it('clone with result parameter', function() {
var result = new OrthographicFrustum();
var frustum2 = frustum.clone(result);
expect(frustum2).toBe(result);
expect(frustum).toEqual(frustum2);
});
});
12 changes: 12 additions & 0 deletions Specs/Scene/PerspectiveFrustumSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,16 @@ defineSuite([
return frustum.infiniteProjectionMatrix;
}).toThrowDeveloperError();
});

it('clone', function() {
var frustum2 = frustum.clone();
expect(frustum).toEqual(frustum2);
});

it('clone with result parameter', function() {
var result = new PerspectiveFrustum();
var frustum2 = frustum.clone(result);
expect(frustum2).toBe(result);
expect(frustum).toEqual(frustum2);
});
});
Loading

0 comments on commit 0083faf

Please sign in to comment.