Skip to content

Commit

Permalink
Merge pull request #2120 from AnalyticalGraphicsInc/oit-flag
Browse files Browse the repository at this point in the history
Fix #1749 by adding an OIT flag.
  • Loading branch information
pjcozzi committed Sep 9, 2014
2 parents 91f3aaf + b72081d commit 11cd61e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -3,6 +3,7 @@ Change Log

### 1.2 - 2014-10-01

* Added a constructor option to `Scene`, `CesiumWidget`, and `Viewer` to disable order independent translucency.
* Eliminated imagery artifacts at some zoom levels due to Mercator reprojection.
* Fixed a bug in `Model` where the wrong animations could be used when the model was created from glTF JSON instead of
a url to a glTF file. [#2078](https://github.com/AnalyticalGraphicsInc/cesium/issues/2078)
Expand Down
22 changes: 19 additions & 3 deletions Source/Scene/Scene.js
Expand Up @@ -154,6 +154,7 @@ define([
* @param {Object} [options.contextOptions] Context and WebGL creation properties. See details above.
* @param {Element} [options.creditContainer] The HTML element in which the credits will be displayed.
* @param {MapProjection} [options.mapProjection=new GeographicProjection()] The map projection to use in 2D and Columbus View modes.
* @param {Boolean} [options.orderIndependentTranslucency=true] If true and the configuration supports it, use order independent translucency.
* @param {Boolean} [options.scene3DOnly=false] If true, optimizes memory use and performance for 3D mode but disables the ability to use 2D or Columbus View. *
* @see CesiumWidget
* @see {@link http://www.khronos.org/registry/webgl/specs/latest/#5.2|WebGLContextAttributes}
Expand Down Expand Up @@ -214,7 +215,7 @@ define([
this._frustumCommandsList = [];
this._overlayCommandList = [];

this._oit = new OIT(context);
this._oit = defaultValue(options.orderIndependentTranslucency, true) ? new OIT(context) : undefined;
this._executeOITFunction = undefined;

this._fxaa = new FXAA();
Expand Down Expand Up @@ -731,6 +732,19 @@ define([
}
},

/**
* Gets whether or not the scene has order independent translucency enabled.
* Note that this only reflects the original construction option, and there are
* other factors that could prevent OIT from functioning on a given system configuration.
* @memberof Scene.prototype
* @type {Boolean}
*/
orderIndependentTranslucency : {
get : function() {
return defined(this._oit);
}
},

/**
* Gets the unique identifier for this scene.
* @memberof Scene.prototype
Expand Down Expand Up @@ -1175,7 +1189,7 @@ define([
}
}

var useOIT = !picking && renderTranslucentCommands && scene._oit.isSupported();
var useOIT = !picking && renderTranslucentCommands && defined(scene._oit) && scene._oit.isSupported();
if (useOIT) {
scene._oit.update(context);
scene._oit.clear(context, passState, clearColor);
Expand Down Expand Up @@ -1700,7 +1714,9 @@ define([

this._transitioner.destroy();

this._oit.destroy();
if (defined(this._oit)) {
this._oit.destroy();
}
this._fxaa.destroy();

this._context = this._context && this._context.destroy();
Expand Down
2 changes: 2 additions & 0 deletions Source/Widgets/CesiumWidget/CesiumWidget.js
Expand Up @@ -138,6 +138,7 @@ define([
* @param {SkyBox} [options.skyBox] The skybox used to render the stars. When <code>undefined</code>, the default stars are used.
* @param {SceneMode} [options.sceneMode=SceneMode.SCENE3D] The initial scene mode.
* @param {Boolean} [options.scene3DOnly=false] When <code>true</code>, each geometry instance will only be rendered in 3D to save GPU memory.
* @param {Boolean} [options.orderIndependentTranslucency=true] If true and the configuration supports it, use order independent translucency.
* @param {MapProjection} [options.mapProjection=new GeographicProjection()] The map projection to use in 2D and Columbus View modes.
* @param {Boolean} [options.useDefaultRenderLoop=true] True if this widget should control the render loop, false otherwise.
* @param {Number} [options.targetFrameRate] The target frame rate when using the default render loop.
Expand Down Expand Up @@ -233,6 +234,7 @@ define([
contextOptions : options.contextOptions,
creditContainer : creditContainer,
mapProjection : options.mapProjection,
orderIndependentTranslucency : options.orderIndependentTranslucency,
scene3DOnly : defaultValue(options.scene3DOnly, false)
});
this._scene = scene;
Expand Down
2 changes: 2 additions & 0 deletions Source/Widgets/Viewer/Viewer.js
Expand Up @@ -97,6 +97,7 @@ define([
* @param {Object} [options.contextOptions] Context and WebGL creation properties corresponding to <code>options</code> passed to {@link Scene}.
* @param {SceneMode} [options.sceneMode=SceneMode.SCENE3D] The initial scene mode.
* @param {MapProjection} [options.mapProjection=new GeographicProjection()] The map projection to use in 2D and Columbus View modes.
* @param {Boolean} [options.orderIndependentTranslucency=true] If true and the configuration supports it, use order independent translucency.
* @param {Element|String} [options.creditContainer] The DOM element or ID that will contain the {@link CreditDisplay}. If not specified, the credits are added to the bottom of the widget itself.
* @param {DataSourceCollection} [options.dataSources=new DataSourceCollection()] The collection of data sources visualized by the widget. If this parameter is provided,
the instance is assumed to be owned by the caller and will not be destroyed when the viewer is destroyed.
Expand Down Expand Up @@ -224,6 +225,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
skyBox : options.skyBox,
sceneMode : options.sceneMode,
mapProjection : options.mapProjection,
orderIndependentTranslucency : options.orderIndependentTranslucency,
contextOptions : options.contextOptions,
useDefaultRenderLoop : options.useDefaultRenderLoop,
targetFrameRate : options.targetFrameRate,
Expand Down
14 changes: 14 additions & 0 deletions Specs/Widgets/CesiumWidget/CesiumWidgetSpec.js
Expand Up @@ -181,6 +181,20 @@ defineSuite([
expect(contextAttributes.preserveDrawingBuffer).toEqual(webglOptions.preserveDrawingBuffer);
});

it('can enable Order Independent Translucency', function() {
widget = new CesiumWidget(container, {
orderIndependentTranslucency : true
});
expect(widget.scene.orderIndependentTranslucency).toBe(true);
});

it('can disable Order Independent Translucency', function() {
widget = new CesiumWidget(container, {
orderIndependentTranslucency : false
});
expect(widget.scene.orderIndependentTranslucency).toBe(false);
});

it('throws if no container provided', function() {
expect(function() {
return new CesiumWidget(undefined);
Expand Down
14 changes: 14 additions & 0 deletions Specs/Widgets/Viewer/ViewerSpec.js
Expand Up @@ -312,6 +312,20 @@ defineSuite([
expect(contextAttributes.preserveDrawingBuffer).toEqual(webglOptions.preserveDrawingBuffer);
});

it('can enable Order Independent Translucency', function() {
viewer = new Viewer(container, {
orderIndependentTranslucency : true
});
expect(viewer.scene.orderIndependentTranslucency).toBe(true);
});

it('can disable Order Independent Translucency', function() {
viewer = new Viewer(container, {
orderIndependentTranslucency : false
});
expect(viewer.scene.orderIndependentTranslucency).toBe(false);
});

it('can set scene mode', function() {
viewer = new Viewer(container, {
sceneMode : SceneMode.SCENE2D
Expand Down

0 comments on commit 11cd61e

Please sign in to comment.