Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: cc/output/bsp_tree.h

Issue 384083002: WIP BSP Tree for 3D Layer Sorting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 public:
36 BspTree(BspController* bsp_controller, ScopedPtrVector<DrawPolygon>* list);
37 scoped_ptr<BspNode>& root() { return root_; }
38
39 template <typename ActionHandlerType>
40 void TraverseWithActionHandler(ActionHandlerType* action_handler) const {
41 if (root_) {
42 WalkInOrderRecursion<ActionHandlerType>(action_handler, root_);
43 }
44 }
45
46 void Clear();
47 ~BspTree();
48
49 private:
50 scoped_ptr<BspNode> root_;
51 BspController* controller_;
52
53 void FromList(ScopedPtrVector<DrawPolygon>* list);
54 void BuildTree(const scoped_ptr<BspNode>& node,
55 ScopedPtrDeque<DrawPolygon>* data);
56
57 template <typename ActionHandlerType>
58 void WalkInOrderAction(ActionHandlerType* action_handler,
59 DrawPolygon* item) const {
60 (*action_handler)(item);
61 }
62
63 template <typename ActionHandlerType>
64 void WalkInOrderVisitNodes(
65 ActionHandlerType* action_handler,
66 const scoped_ptr<BspNode>& node,
67 const scoped_ptr<BspNode>& first_child,
68 const scoped_ptr<BspNode>& second_child,
69 const ScopedPtrVector<DrawPolygon>& first_coplanars,
70 const ScopedPtrVector<DrawPolygon>& second_coplanars) const {
71 if (first_child) {
72 WalkInOrderRecursion(action_handler, first_child);
73 }
74 for (unsigned int i = 0; i < first_coplanars.size(); i++) {
75 WalkInOrderAction(action_handler, first_coplanars[i]);
76 }
77 WalkInOrderAction(action_handler, node->node_data.get());
78 for (unsigned int i = 0; i < second_coplanars.size(); i++) {
79 WalkInOrderAction(action_handler, second_coplanars[i]);
80 }
81 if (second_child) {
82 WalkInOrderRecursion(action_handler, second_child);
83 }
84 }
85
86 template <typename ActionHandlerType>
87 void WalkInOrderRecursion(ActionHandlerType* action_handler,
88 const scoped_ptr<BspNode>& node) const {
89 // If our view is in front of the the polygon
90 // in this node then walk back then front.
91 if (controller_->GetCameraPositionRelative(*(node->node_data)) ==
92 BSP_FRONT) {
93 WalkInOrderVisitNodes<ActionHandlerType>(action_handler,
94 node,
95 node->back_child,
96 node->front_child,
97 node->coplanars_front,
98 node->coplanars_back);
99 } else {
100 WalkInOrderVisitNodes<ActionHandlerType>(action_handler,
101 node,
102 node->front_child,
103 node->back_child,
104 node->coplanars_back,
105 node->coplanars_front);
106 }
107 }
108 };
109
110 } // namespace cc
111
112 #endif // CC_OUTPUT_BSP_TREE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698