Index: cc/output/bsp_tree.h |
diff --git a/cc/output/bsp_tree.h b/cc/output/bsp_tree.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cd1ec7195da8440cfa276552598ec5e497a3f82e |
--- /dev/null |
+++ b/cc/output/bsp_tree.h |
@@ -0,0 +1,101 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CC_OUTPUT_BSP_TREE_H_ |
+#define CC_OUTPUT_BSP_TREE_H_ |
+ |
+#include <list> |
+#include <vector> |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "cc/base/scoped_ptr_deque.h" |
+#include "cc/base/scoped_ptr_vector.h" |
+#include "cc/output/bsp_compare_result.h" |
+#include "cc/output/bsp_controller.h" |
+#include "cc/quads/draw_polygon.h" |
+ |
+namespace cc { |
+ |
+struct BspNode { |
+ // This represents the splitting plane. |
+ scoped_ptr<DrawPolygon> node_data; |
+ // This represents any coplanar geometry we found while building the BSP. |
+ ScopedPtrVector<DrawPolygon> coplanars_front; |
+ ScopedPtrVector<DrawPolygon> coplanars_back; |
+ |
+ scoped_ptr<BspNode> back_child; |
+ scoped_ptr<BspNode> front_child; |
+ |
+ explicit BspNode(scoped_ptr<DrawPolygon> data); |
+ ~BspNode(); |
+}; |
+ |
+class BspTree { |
+ private: |
+ scoped_ptr<BspNode> root_; |
+ BspController* controller_; |
+ |
+ void FromList(ScopedPtrVector<DrawPolygon>* list); |
Ian Vollick
2014/07/16 20:54:33
Would be nice to add comment explaining the differ
troyhildebrandt
2014/07/18 21:48:26
Done.
|
+ void BuildTree(const scoped_ptr<BspNode>& node, |
+ ScopedPtrDeque<DrawPolygon>* data); |
+ |
+ template <typename ActionHandlerType> |
+ void WalkInOrderAction(ActionHandlerType* action_handler, |
+ DrawPolygon* item) const { |
Ian Vollick
2014/07/16 20:54:33
If you define these templatized member functions o
troyhildebrandt
2014/07/18 21:48:26
Simply changed the ordering, no complaints from th
|
+ (*action_handler)(item); |
+ } |
+ |
+ template <typename ActionHandlerType> |
+ void WalkInOrderRecursion(ActionHandlerType* action_handler, |
+ const scoped_ptr<BspNode>& node) const { |
+ // If our view is in front of the the polygon |
+ // in this node then walk back then front. |
Ian Vollick
2014/07/16 20:54:33
Could this be made more concise by storing node pt
troyhildebrandt
2014/07/18 21:48:26
Done.
|
+ if (controller_->GetCameraPositionRelative(*(node->node_data)) == |
+ IN_FRONT) { |
+ if (node->back_child) |
+ WalkInOrderRecursion(action_handler, node->back_child); |
+ // Add all items from this node level to the list in their current order. |
+ for (unsigned int i = 0; i < node->coplanars_front.size(); i++) { |
+ WalkInOrderAction(action_handler, node->coplanars_front[i]); |
+ } |
+ WalkInOrderAction(action_handler, node->node_data.get()); |
+ for (unsigned int i = 0; i < node->coplanars_back.size(); i++) { |
+ WalkInOrderAction(action_handler, node->coplanars_back[i]); |
+ } |
+ if (node->front_child) |
+ WalkInOrderRecursion(action_handler, node->front_child); |
+ } else { |
+ if (node->front_child) |
+ WalkInOrderRecursion(action_handler, node->front_child); |
+ // Add all items from this node level to the list in their current order. |
+ for (unsigned int i = 0; i < node->coplanars_back.size(); i++) { |
+ WalkInOrderAction(action_handler, node->coplanars_back[i]); |
+ } |
+ WalkInOrderAction(action_handler, node->node_data.get()); |
+ for (unsigned int i = 0; i < node->coplanars_front.size(); i++) { |
+ WalkInOrderAction(action_handler, node->coplanars_front[i]); |
+ } |
+ if (node->back_child) |
+ WalkInOrderRecursion(action_handler, node->back_child); |
+ } |
+ } |
+ |
+ public: |
+ BspTree(BspController* bsp_controller, ScopedPtrVector<DrawPolygon>* list); |
+ scoped_ptr<BspNode>& root() { return root_; } |
+ |
+ template <typename ActionHandlerType> |
+ void TraverseWithActionHandler(ActionHandlerType* action_handler) const { |
+ if (root_) { |
+ WalkInOrderRecursion<ActionHandlerType>(action_handler, root_); |
+ } |
+ } |
+ |
+ void Clear(); |
+ ~BspTree(); |
+}; |
+ |
+} // namespace cc |
+ |
+#endif // CC_OUTPUT_BSP_TREE_H_ |