OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_OUTPUT_BSP_TREE_H_ | 5 #ifndef CC_OUTPUT_BSP_TREE_H_ |
6 #define CC_OUTPUT_BSP_TREE_H_ | 6 #define CC_OUTPUT_BSP_TREE_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "cc/base/scoped_ptr_vector.h" | |
13 #include "cc/output/bsp_compare_result.h" | 12 #include "cc/output/bsp_compare_result.h" |
14 #include "cc/quads/draw_polygon.h" | 13 #include "cc/quads/draw_polygon.h" |
15 | 14 |
16 namespace cc { | 15 namespace cc { |
17 | 16 |
18 struct BspNode { | 17 struct BspNode { |
19 // This represents the splitting plane. | 18 // This represents the splitting plane. |
20 scoped_ptr<DrawPolygon> node_data; | 19 scoped_ptr<DrawPolygon> node_data; |
21 // This represents any coplanar geometry we found while building the BSP. | 20 // This represents any coplanar geometry we found while building the BSP. |
22 ScopedPtrVector<DrawPolygon> coplanars_front; | 21 std::vector<scoped_ptr<DrawPolygon>> coplanars_front; |
23 ScopedPtrVector<DrawPolygon> coplanars_back; | 22 std::vector<scoped_ptr<DrawPolygon>> coplanars_back; |
24 | 23 |
25 scoped_ptr<BspNode> back_child; | 24 scoped_ptr<BspNode> back_child; |
26 scoped_ptr<BspNode> front_child; | 25 scoped_ptr<BspNode> front_child; |
27 | 26 |
28 explicit BspNode(scoped_ptr<DrawPolygon> data); | 27 explicit BspNode(scoped_ptr<DrawPolygon> data); |
29 ~BspNode(); | 28 ~BspNode(); |
30 }; | 29 }; |
31 | 30 |
32 class CC_EXPORT BspTree { | 31 class CC_EXPORT BspTree { |
33 public: | 32 public: |
34 explicit BspTree(std::deque<scoped_ptr<DrawPolygon>>* list); | 33 explicit BspTree(std::deque<scoped_ptr<DrawPolygon>>* list); |
35 scoped_ptr<BspNode>& root() { return root_; } | 34 scoped_ptr<BspNode>& root() { return root_; } |
36 | 35 |
37 template <typename ActionHandlerType> | 36 template <typename ActionHandlerType> |
38 void TraverseWithActionHandler(ActionHandlerType* action_handler) const { | 37 void TraverseWithActionHandler(ActionHandlerType* action_handler) const { |
39 if (root_) { | 38 if (root_) { |
40 WalkInOrderRecursion<ActionHandlerType>(action_handler, root_.get()); | 39 WalkInOrderRecursion<ActionHandlerType>(action_handler, root_.get()); |
41 } | 40 } |
42 } | 41 } |
43 | 42 |
44 ~BspTree(); | 43 ~BspTree(); |
45 | 44 |
46 private: | 45 private: |
47 scoped_ptr<BspNode> root_; | 46 scoped_ptr<BspNode> root_; |
48 | 47 |
49 void FromList(ScopedPtrVector<DrawPolygon>* list); | 48 void FromList(std::vector<scoped_ptr<DrawPolygon>>* list); |
50 void BuildTree(BspNode* node, std::deque<scoped_ptr<DrawPolygon>>* data); | 49 void BuildTree(BspNode* node, std::deque<scoped_ptr<DrawPolygon>>* data); |
51 | 50 |
52 template <typename ActionHandlerType> | 51 template <typename ActionHandlerType> |
53 void WalkInOrderAction(ActionHandlerType* action_handler, | 52 void WalkInOrderAction(ActionHandlerType* action_handler, |
54 DrawPolygon* item) const { | 53 DrawPolygon* item) const { |
55 (*action_handler)(item); | 54 (*action_handler)(item); |
56 } | 55 } |
57 | 56 |
58 template <typename ActionHandlerType> | 57 template <typename ActionHandlerType> |
59 void WalkInOrderVisitNodes( | 58 void WalkInOrderVisitNodes( |
60 ActionHandlerType* action_handler, | 59 ActionHandlerType* action_handler, |
61 const BspNode* node, | 60 const BspNode* node, |
62 const BspNode* first_child, | 61 const BspNode* first_child, |
63 const BspNode* second_child, | 62 const BspNode* second_child, |
64 const ScopedPtrVector<DrawPolygon>& first_coplanars, | 63 const std::vector<scoped_ptr<DrawPolygon>>& first_coplanars, |
65 const ScopedPtrVector<DrawPolygon>& second_coplanars) const { | 64 const std::vector<scoped_ptr<DrawPolygon>>& second_coplanars) const { |
66 if (first_child) { | 65 if (first_child) { |
67 WalkInOrderRecursion(action_handler, first_child); | 66 WalkInOrderRecursion(action_handler, first_child); |
68 } | 67 } |
69 for (size_t i = 0; i < first_coplanars.size(); i++) { | 68 for (size_t i = 0; i < first_coplanars.size(); i++) { |
70 WalkInOrderAction(action_handler, first_coplanars[i]); | 69 WalkInOrderAction(action_handler, first_coplanars[i].get()); |
71 } | 70 } |
72 WalkInOrderAction(action_handler, node->node_data.get()); | 71 WalkInOrderAction(action_handler, node->node_data.get()); |
73 for (size_t i = 0; i < second_coplanars.size(); i++) { | 72 for (size_t i = 0; i < second_coplanars.size(); i++) { |
74 WalkInOrderAction(action_handler, second_coplanars[i]); | 73 WalkInOrderAction(action_handler, second_coplanars[i].get()); |
75 } | 74 } |
76 if (second_child) { | 75 if (second_child) { |
77 WalkInOrderRecursion(action_handler, second_child); | 76 WalkInOrderRecursion(action_handler, second_child); |
78 } | 77 } |
79 } | 78 } |
80 | 79 |
81 template <typename ActionHandlerType> | 80 template <typename ActionHandlerType> |
82 void WalkInOrderRecursion(ActionHandlerType* action_handler, | 81 void WalkInOrderRecursion(ActionHandlerType* action_handler, |
83 const BspNode* node) const { | 82 const BspNode* node) const { |
84 // If our view is in front of the the polygon | 83 // If our view is in front of the the polygon |
(...skipping 20 matching lines...) Expand all Loading... |
105 static BspCompareResult GetNodePositionRelative(const DrawPolygon& node_a, | 104 static BspCompareResult GetNodePositionRelative(const DrawPolygon& node_a, |
106 const DrawPolygon& node_b); | 105 const DrawPolygon& node_b); |
107 // Returns whether or not our viewer is in front of or behind the plane | 106 // Returns whether or not our viewer is in front of or behind the plane |
108 // defined by this polygon/node | 107 // defined by this polygon/node |
109 static BspCompareResult GetCameraPositionRelative(const DrawPolygon& node); | 108 static BspCompareResult GetCameraPositionRelative(const DrawPolygon& node); |
110 }; | 109 }; |
111 | 110 |
112 } // namespace cc | 111 } // namespace cc |
113 | 112 |
114 #endif // CC_OUTPUT_BSP_TREE_H_ | 113 #endif // CC_OUTPUT_BSP_TREE_H_ |
OLD | NEW |