Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CC_OUTPUT_BSP_TREE_H_ | |
| 6 #define CC_OUTPUT_BSP_TREE_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "cc/base/scoped_ptr_deque.h" | |
| 13 #include "cc/base/scoped_ptr_vector.h" | |
| 14 #include "cc/output/bsp_compare_result.h" | |
| 15 #include "cc/output/bsp_controller.h" | |
| 16 #include "cc/quads/draw_polygon.h" | |
| 17 | |
| 18 namespace cc { | |
| 19 | |
| 20 struct BspNode { | |
| 21 // This represents the splitting plane. | |
| 22 scoped_ptr<DrawPolygon> node_data; | |
| 23 // This represents any coplanar geometry we found while building the BSP. | |
| 24 ScopedPtrVector<DrawPolygon> coplanars_front; | |
| 25 ScopedPtrVector<DrawPolygon> coplanars_back; | |
| 26 | |
| 27 scoped_ptr<BspNode> back_child; | |
| 28 scoped_ptr<BspNode> front_child; | |
| 29 | |
| 30 explicit BspNode(scoped_ptr<DrawPolygon> data); | |
| 31 ~BspNode(); | |
| 32 }; | |
| 33 | |
| 34 class BspTree { | |
| 35 private: | |
| 36 scoped_ptr<BspNode> root_; | |
| 37 BspController* controller_; | |
| 38 | |
| 39 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.
| |
| 40 void BuildTree(const scoped_ptr<BspNode>& node, | |
| 41 ScopedPtrDeque<DrawPolygon>* data); | |
| 42 | |
| 43 template <typename ActionHandlerType> | |
| 44 void WalkInOrderAction(ActionHandlerType* action_handler, | |
| 45 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
| |
| 46 (*action_handler)(item); | |
| 47 } | |
| 48 | |
| 49 template <typename ActionHandlerType> | |
| 50 void WalkInOrderRecursion(ActionHandlerType* action_handler, | |
| 51 const scoped_ptr<BspNode>& node) const { | |
| 52 // If our view is in front of the the polygon | |
| 53 // 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.
| |
| 54 if (controller_->GetCameraPositionRelative(*(node->node_data)) == | |
| 55 IN_FRONT) { | |
| 56 if (node->back_child) | |
| 57 WalkInOrderRecursion(action_handler, node->back_child); | |
| 58 // Add all items from this node level to the list in their current order. | |
| 59 for (unsigned int i = 0; i < node->coplanars_front.size(); i++) { | |
| 60 WalkInOrderAction(action_handler, node->coplanars_front[i]); | |
| 61 } | |
| 62 WalkInOrderAction(action_handler, node->node_data.get()); | |
| 63 for (unsigned int i = 0; i < node->coplanars_back.size(); i++) { | |
| 64 WalkInOrderAction(action_handler, node->coplanars_back[i]); | |
| 65 } | |
| 66 if (node->front_child) | |
| 67 WalkInOrderRecursion(action_handler, node->front_child); | |
| 68 } else { | |
| 69 if (node->front_child) | |
| 70 WalkInOrderRecursion(action_handler, node->front_child); | |
| 71 // Add all items from this node level to the list in their current order. | |
| 72 for (unsigned int i = 0; i < node->coplanars_back.size(); i++) { | |
| 73 WalkInOrderAction(action_handler, node->coplanars_back[i]); | |
| 74 } | |
| 75 WalkInOrderAction(action_handler, node->node_data.get()); | |
| 76 for (unsigned int i = 0; i < node->coplanars_front.size(); i++) { | |
| 77 WalkInOrderAction(action_handler, node->coplanars_front[i]); | |
| 78 } | |
| 79 if (node->back_child) | |
| 80 WalkInOrderRecursion(action_handler, node->back_child); | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 public: | |
| 85 BspTree(BspController* bsp_controller, ScopedPtrVector<DrawPolygon>* list); | |
| 86 scoped_ptr<BspNode>& root() { return root_; } | |
| 87 | |
| 88 template <typename ActionHandlerType> | |
| 89 void TraverseWithActionHandler(ActionHandlerType* action_handler) const { | |
| 90 if (root_) { | |
| 91 WalkInOrderRecursion<ActionHandlerType>(action_handler, root_); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 void Clear(); | |
| 96 ~BspTree(); | |
| 97 }; | |
| 98 | |
| 99 } // namespace cc | |
| 100 | |
| 101 #endif // CC_OUTPUT_BSP_TREE_H_ | |
| OLD | NEW |