summaryrefslogtreecommitdiffstats
path: root/o3d/samples/o3d-webgl/draw_list.js
diff options
context:
space:
mode:
authorpetersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-17 21:36:08 +0000
committerpetersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-17 21:36:08 +0000
commit422e69530732e4f54acb649ea8130ed22e3ccb53 (patch)
treecd556e693f9448a83d63a764e13561c67c883d6e /o3d/samples/o3d-webgl/draw_list.js
parenta81e44e1ccd4c19de283dcd1e90da04bf8ae0208 (diff)
downloadchromium_src-422e69530732e4f54acb649ea8130ed22e3ccb53.zip
chromium_src-422e69530732e4f54acb649ea8130ed22e3ccb53.tar.gz
chromium_src-422e69530732e4f54acb649ea8130ed22e3ccb53.tar.bz2
Sorts drawlists by priority or by depth as indicated by the flag in the DrawPass.
Review URL: http://codereview.chromium.org/2075003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47459 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/samples/o3d-webgl/draw_list.js')
-rw-r--r--o3d/samples/o3d-webgl/draw_list.js47
1 files changed, 46 insertions, 1 deletions
diff --git a/o3d/samples/o3d-webgl/draw_list.js b/o3d/samples/o3d-webgl/draw_list.js
index 875f237..6132a8b 100644
--- a/o3d/samples/o3d-webgl/draw_list.js
+++ b/o3d/samples/o3d-webgl/draw_list.js
@@ -69,10 +69,55 @@ o3d.DrawList.BY_PRIORITY = 2;
/**
+ * Compare function for by-priority sort.
+ */
+o3d.DrawList.comparePriority_ = function(drawElementInfoA, drawElementInfoB) {
+ return drawElementInfoA.drawElement.owner.priority -
+ drawElementInfoB.drawElement.owner.priority;
+};
+
+
+/**
+ * Compare function for by-z-coordinate sort.
+ * @param {!o3d.DrawElement} drawElementInfoA
+ * @param {!o3d.DrawElement} drawElementInfoB
+ */
+o3d.DrawList.compareZ_ = function(drawElementInfoA, drawElementInfoB) {
+ return o3d.Transform.transformPointZOnly(
+ drawElementInfoA.worldViewProjection,
+ drawElementInfoA.drawElement.owner.zSortPoint) -
+ o3d.Transform.transformPointZOnly(
+ drawElementInfoB.worldViewProjection,
+ drawElementInfoB.drawElement.owner.zSortPoint);
+};
+
+
+/**
+ * Sorts this list according to the given sort method.
+ * @param {o3d.DrawList.SortMethod} sort_method Which method to use.
+ * @private
+ */
+o3d.DrawList.prototype.sort_ = function(sort_method) {
+ switch (sort_method) {
+ case o3d.DrawList.BY_PRIORITY:
+ this.list_.sort(o3d.DrawList.comparePriority_);
+ break;
+
+ case o3d.DrawList.BY_Z_ORDER:
+ this.list_.sort(o3d.DrawList.compareZ_);
+ break;
+
+ case o3d.DrawList.BY_PERFORMANCE:
+ default:
+ break;
+ }
+};
+
+
+/**
* Renders the draw list.
*/
o3d.DrawList.prototype.render = function() {
- // TODO(petersont): Add sort.
for (var i = 0; i < this.list_.length; ++i) {
var drawElementInfo = this.list_[i];
var world = drawElementInfo.world;