Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into meshTerrain
Browse files Browse the repository at this point in the history
Conflicts:
	CHANGES.md
  • Loading branch information
kring committed Feb 3, 2014
2 parents ff3b059 + 27222fc commit b5167e1
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 141 deletions.
2 changes: 1 addition & 1 deletion Apps/CesiumViewer/CesiumViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ define([
}

if (endUserOptions.stats) {
scene.getPrimitives().add(new PerformanceDisplay());
scene.debugShowFramesPerSecond = true;
}

var theme = endUserOptions.theme;
Expand Down
6 changes: 4 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ Beta Releases
### b25 - 2014-02-03
* Breaking changes:
* The `Viewer` constructor argument `options.fullscreenElement` now matches the `FullscreenButton` default of `document.body`, it was previously the `Viewer` container itself.
* `Asphalt`, `Blob`, `Brick`, `Cement`, `Erosion`, `Facet`, `Grass`, `TieDye`, and `Wood` materials were moved to the [Materials Pack Plugin](https://github.com/AnalyticalGraphicsInc/cesium-materials-pack).
* Removed `Viewer.objectTracked` event; `Viewer.trackedObject` is now an ES5 Knockout observable that can be subscribed to directly.
* Replaced `PerformanceDisplay` with `Scene.debugShowFramesPerSecond`.
* `Asphalt`, `Blob`, `Brick`, `Cement`, `Erosion`, `Facet`, `Grass`, `TieDye`, and `Wood` materials were moved to the [Materials Pack Plugin](https://github.com/AnalyticalGraphicsInc/cesium-materials-pack).
* Renamed `GeometryPipeline.createAttributeIndices` to `GeometryPipeline.createAttributeLocations`.
* Renamed `attributeIndices` property to `attributeLocations` when calling `Context.createVertexArrayFromGeometry`.
* `PerformanceDisplay` requires a DOM element as a parameter
* Fixed globe rendering in the current Canary version of Google Chrome.
* `Viewer` now monitors the clock settings of the first added `DataSource` for changes, and also now has a constructor option `automaticallyTrackFirstDataSourceClock` which will turn off this behavior.
* The `DynamicObjectCollection` created by `CzmlDataSource` now sends a single `collectionChanged` event after CZML is loaded; previously it was sending an event every time an object was created or removed during the load process.
* Added `ScreenSpaceCameraController.enableInputs` to fix issue with inputs not being restored after overlapping camera flights.
* Fixed picking in 2D with rotated map. [#1337](https://github.com/AnalyticalGraphicsInc/cesium/issues/1337)
* `TileMapServiceImageryProvider` can now handle casing differences in tilemapresource.xml.
* `OpenStreetMapImageryProvider` now supports imagery with a minimum level.
* Added `Quaternion.fastSlerp` and `Quaternion.fastSquad`.
* Upgraded Tween.js to version r12.
* `OpenStreetMapImageryProvider` now supports imagery with a minimum level.
* Improved the quality of imagery near the poles when the imagery source uses a `GeographicTilingScheme`.
* `CesiumTerrainProvider` now supports mesh-based terrain like the tiles created by STK Terrain Server.
* Added `makeRelativeUrlAbsolute` function to build an absolute URL from a base URL and a relative URL.
* Added `Intersections2D` class containing operations on 2D triangles.

### b24 - 2014-01-06
Expand Down
16 changes: 13 additions & 3 deletions Source/Scene/CameraController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1023,9 +1023,19 @@ define([
result = new Cartesian3();
}

var scalar = Cartesian3.magnitude(center) + d;
Cartesian3.negate(direction, result);
return Cartesian3.multiplyByScalar(result, scalar, result);
var mag = Cartesian3.magnitude(center);
var scalar = mag + d;

if (mag < CesiumMath.EPSILON6) {
cart.longitude = (east + west) * 0.5;
cart.latitude = (north + south) * 0.5;
ellipsoid.cartographicToCartesian(cart, center);
Cartesian3.normalize(center, center);
} else {
Cartesian3.normalize(center, center);
}

return Cartesian3.multiplyByScalar(center, scalar, result);
}

var viewExtentCVCartographic = new Cartographic();
Expand Down
180 changes: 46 additions & 134 deletions Source/Scene/PerformanceDisplay.js
Original file line number Diff line number Diff line change
@@ -1,199 +1,111 @@
/*global define*/
define([
'../Core/BoundingRectangle',
'../Core/Color',
'../Core/defaultValue',
'../Core/defined',
'../Core/destroyObject',
'../Renderer/PixelFormat',
'./Material',
'./ViewportQuad'
'../Core/DeveloperError',
'../Widgets/getElement'
], function(
BoundingRectangle,
Color,
defaultValue,
defined,
destroyObject,
PixelFormat,
Material,
ViewportQuad) {
DeveloperError,
getElement) {
"use strict";

var defaultFpsColor = Color.fromCssColorString('#e52');
var defaultFrameTimeColor = Color.fromCssColorString('#de3');
var defaultBackgroundColor = Color.fromCssColorString('rgba(0, 0, 30, 0.9)');
var defaultRectangle = new BoundingRectangle(0, 0, 80, 40);
var defaultBackgroundColor = Color.fromCssColorString('rgba(40, 40, 40, 0.7)');

/**
* Draws a display in the top left corner of the scene displaying FPS (frames per second),
* averaged over 1 second intervals, as well as unaveraged frame time.
*
* @alias PerformanceDisplay
* @constructor
*
* @param {Color} [description.fpsColor] The color of the FPS graph.
* @param {Color} [description.frameTimeColor] The color of the frame time graph.
* @param {Color} [description.backgroundColor] The color of the background of the display.
* @param {String} [description.font] The CSS font of the text in the display.
* @param {BoundingRectangle} [description.rectangle] The position and size of the display, relative to the top left corner.
*
* @example
* scene.getPrimitives().add(new Cesium.PerformanceDisplay());
* @private
*/
var PerformanceDisplay = function(description) {
description = defaultValue(description, defaultValue.EMPTY_OBJECT);

var container = getElement(description.container);
if (!defined(container)) {
throw new DeveloperError('container is required');
}

this._container = container;
this._fpsColor = defaultValue(description.fpsColor, defaultFpsColor).toCssColorString();
this._frameTimeColor = defaultValue(description.frameTimeColor, defaultFrameTimeColor).toCssColorString();
this._backgroundColor = defaultValue(description.backgroundColor, defaultBackgroundColor).toCssColorString();
this._font = defaultValue(description.font, 'bold 10px Helvetica,Arial,sans-serif');
this._rectangle = defaultValue(description.rectangle, defaultRectangle);

this._canvas = document.createElement('canvas');
this._canvas.width = this._rectangle.width;
this._canvas.height = this._rectangle.height;

this._canvasContext = this._canvas.getContext('2d');
this._canvasContext.font = this._font;
this._canvasContext.lineWidth = 1;

this._bufferLength = this._rectangle.width;
this._frameTimeSamples = new Array(this._bufferLength);
this._fpsSamples = new Array(this._bufferLength);

for ( var i = 0; i < this._bufferLength; i++) {
this._frameTimeSamples[i] = this._fpsSamples[i] = 0;
}
this._font = defaultValue(description.font, 'bold 12px Helvetica,Arial,sans-serif');

var display = document.createElement('div');
var fpsElement = document.createElement('div');
this._fpsText = document.createTextNode("");
fpsElement.appendChild(this._fpsText);
fpsElement.style.color = this._fpsColor;
var msElement = document.createElement('div');
this._msText = document.createTextNode("");
msElement.style.color = this._frameTimeColor;
msElement.appendChild(this._msText);
display.appendChild(fpsElement);
display.appendChild(msElement);
display.style['z-index'] = 1;
display.style['background-color'] = this._backgroundColor;
display.style.font = this._font;
display.style.padding = '7px';
display.style['border-radius']= '5px';
display.style.border = '1px solid #444';
this._container.appendChild(display);

this._frameTimeIndex = 0;
this._fpsIndex = 0;
this._lastFpsSampleTime = undefined;
this._frameCount = 0;

this._quad = undefined;

this._time = undefined;
this._texture = undefined;
this._viewportHeight = 0;
this._fps = 0;
this._frameTime = 0;
};

/**
* Update the display. This function should only be called once per frame, because
* each call records a frame in the internal buffer and redraws the display.
*/
PerformanceDisplay.prototype.update = function(context, frameState, commandList) {
PerformanceDisplay.prototype.update = function() {
if (!defined(this._time)) {
//first update
this._lastFpsSampleTime = this._time = Date.now();
this._lastFpsSampleTime = Date.now();
this._time = Date.now();
return;
}

var previousTime = this._time;
var time = this._time = Date.now();
var time = Date.now();
this._time = time;

var frameTime = time - previousTime;
this._frameTimeSamples[this._frameTimeIndex++] = frameTime;

if (this._frameTimeIndex >= this._bufferLength) {
this._frameTimeIndex = 0;
}

this._frameCount++;
var fps = this._fps;
var fpsElapsedTime = time - this._lastFpsSampleTime;
if (fpsElapsedTime > 1000) {
fps = this._fps = this._frameCount * 1000 / fpsElapsedTime | 0;
this._fpsSamples[this._fpsIndex++] = fps;

if (this._fpsIndex >= this._bufferLength) {
this._fpsIndex = 0;
}
fps = this._frameCount * 1000 / fpsElapsedTime | 0;

this._lastFpsSampleTime = time;
this._frameCount = 0;
}

var ctx = this._canvasContext;
var canvasWidth = this._rectangle.width;
var canvasHeight = this._rectangle.height;
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.fillStyle = this._backgroundColor;
ctx.fillRect(0, 0, canvasWidth, canvasHeight);

if (defined(fps)) {
ctx.fillStyle = this._fpsColor;
ctx.textAlign = 'left';
ctx.fillText(fps + ' FPS', 1, 10);
}

ctx.fillStyle = this._frameTimeColor;
ctx.textAlign = 'right';
ctx.fillText(frameTime + ' MS', canvasWidth - 1, 10);

for ( var i = 0; i < this._bufferLength; i++) {
fps = this._fpsSamples[(i + this._fpsIndex) % this._bufferLength];
if (fps > 0) {
this._drawLine(this._fpsColor, i, fps / 100);
}

frameTime = this._frameTimeSamples[(i + this._frameTimeIndex) % this._bufferLength];
if (frameTime > 0) {
this._drawLine(this._frameTimeColor, i, frameTime / 200);
}
}

if (!defined(this._quad)) {
this._quad = new ViewportQuad(undefined, Material.fromType(Material.ImageType));
}

if (!defined(this._texture)) {
this._texture = context.createTexture2D({
source : this._canvas,
pixelFormat : PixelFormat.RGBA
});
this._quad.material.uniforms.image = this._texture;
} else {
this._texture.copyFrom(this._canvas);
if (fps !== this._fps) {
this._fpsText.nodeValue = fps + ' FPS';
this._fps = fps;
}

var viewportHeight = context.getDrawingBufferHeight();
if (viewportHeight !== this._viewportHeight) {
this._viewportHeight = viewportHeight;
var rect = this._quad.rectangle;
rect.x = this._rectangle.x;
rect.y = viewportHeight - canvasHeight - this._rectangle.y;
rect.width = canvasWidth;
rect.height = canvasHeight;
}

this._quad.update(context, frameState, commandList);
};

PerformanceDisplay.prototype._drawLine = function(style, x, valuePercent) {
var ctx = this._canvasContext;
var canvasHeight = this._rectangle.height;
var maxGraphHeight = canvasHeight - 10;

x = 0.5 + x;
ctx.beginPath();
ctx.strokeStyle = style;
ctx.moveTo(x, canvasHeight);

var lineHeight = valuePercent * maxGraphHeight;
if (lineHeight > maxGraphHeight) {
lineHeight = maxGraphHeight;
if (frameTime !== this._frameTime) {
this._msText.nodeValue = frameTime + ' MS';
this._frameTime = frameTime;
}

var y = canvasHeight - lineHeight;
ctx.lineTo(x, y);
ctx.stroke();
};

/**
* Destroys the WebGL resources held by this object.
*/
PerformanceDisplay.prototype.destroy = function() {
this._quad = this._quad.destroy();
return destroyObject(this);
};

Expand Down
41 changes: 41 additions & 0 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ define([
'./PerspectiveFrustum',
'./PerspectiveOffCenterFrustum',
'./FrustumCommands',
'./PerformanceDisplay',
'./Primitive',
'./PerInstanceColorAppearance',
'./SunPostProcess',
Expand Down Expand Up @@ -81,6 +82,7 @@ define([
PerspectiveFrustum,
PerspectiveOffCenterFrustum,
FrustumCommands,
PerformanceDisplay,
Primitive,
PerInstanceColorAppearance,
SunPostProcess,
Expand Down Expand Up @@ -315,6 +317,20 @@ define([
*/
this.debugFrustumStatistics = undefined;

/**
* This property is for debugging only; it is not for production use.
* <p>
* Displays frames per second and time between frames.
* </p>
*
* @type Boolean
*
* @default false
*/
this.debugShowFramesPerSecond = false;

this._performanceDisplay = undefined;

this._debugSphere = undefined;

// initial guess at frustums.
Expand Down Expand Up @@ -900,6 +916,26 @@ define([
executeOverlayCommands(this, passState);

frameState.creditDisplay.endFrame();

if (this.debugShowFramesPerSecond) {
if (!defined(this._performanceDisplay)) {
var performanceContainer = document.createElement('div');
performanceContainer.style.position = 'absolute';
performanceContainer.style.top = '10px';
performanceContainer.style.left = '10px';
var container = this._canvas.parentNode;
container.appendChild(performanceContainer);
var performanceDisplay = new PerformanceDisplay({container: performanceContainer});
this._performanceDisplay = performanceDisplay;
this._performanceContainer = performanceContainer;
}

this._performanceDisplay.update();
} else if (defined(this._performanceDisplay)) {
this._performanceDisplay = this._performanceDisplay && this._performanceDisplay.destroy();
this._performanceContainer.parentNode.removeChild(this._performanceContainer);
}

context.endFrame();
executeEvents(frameState);
};
Expand Down Expand Up @@ -1144,6 +1180,11 @@ define([
this._sunPostProcess = this._sunPostProcess && this._sunPostProcess.destroy();
this._context = this._context && this._context.destroy();
this._frameState.creditDisplay.destroy();
if (defined(this._performanceDisplay)){
this._performanceDisplay = this._performanceDisplay && this._performanceDisplay.destroy();
this._performanceContainer.parentNode.removeChild(this._performanceContainer);
}

return destroyObject(this);
};

Expand Down
6 changes: 6 additions & 0 deletions Specs/Scene/SceneSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ defineSuite([
scene.debugShowCommands = false;
});

it('debugShowFramesPerSecond', function() {
scene.debugShowFramesPerSecond = true;
scene.render();
expect(scene._performanceDisplay).toBeDefined();
});

it('opaque/translucent render order (1)', function() {
var extent = Extent.fromDegrees(-100.0, 30.0, -90.0, 40.0);

Expand Down
Loading

0 comments on commit b5167e1

Please sign in to comment.