summaryrefslogtreecommitdiffstats
path: root/o3d/samples/o3d-webgl/draw_list.js
diff options
context:
space:
mode:
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;