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

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

Issue 2151893002: Perform BSP polygon splitting and orientation selection in a single step. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 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
« no previous file with comments | « cc/output/bsp_tree.h ('k') | cc/output/bsp_tree_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "cc/output/bsp_tree.h" 5 #include "cc/output/bsp_tree.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 26 matching lines...) Expand all
37 void BspTree::BuildTree( 37 void BspTree::BuildTree(
38 BspNode* node, 38 BspNode* node,
39 std::deque<std::unique_ptr<DrawPolygon>>* polygon_list) { 39 std::deque<std::unique_ptr<DrawPolygon>>* polygon_list) {
40 std::deque<std::unique_ptr<DrawPolygon>> front_list; 40 std::deque<std::unique_ptr<DrawPolygon>> front_list;
41 std::deque<std::unique_ptr<DrawPolygon>> back_list; 41 std::deque<std::unique_ptr<DrawPolygon>> back_list;
42 42
43 // We take in a list of polygons at this level of the tree, and have to 43 // We take in a list of polygons at this level of the tree, and have to
44 // find a splitting plane, then classify polygons as either in front of 44 // find a splitting plane, then classify polygons as either in front of
45 // or behind that splitting plane. 45 // or behind that splitting plane.
46 while (!polygon_list->empty()) { 46 while (!polygon_list->empty()) {
47 // Is this particular polygon in front of or behind our splitting polygon. 47 std::unique_ptr<DrawPolygon> polygon;
48 BspCompareResult comparer_result = 48 std::unique_ptr<DrawPolygon> new_front;
49 GetNodePositionRelative(*polygon_list->front(), *(node->node_data)); 49 std::unique_ptr<DrawPolygon> new_back;
50 50 // Time to split this geometry, *it needs to be split by node_data.
51 // If it's clearly behind or in front of the splitting plane, we use the 51 polygon = PopFront(polygon_list);
52 // heuristic to decide whether or not we should put it at the back 52 bool is_coplanar;
53 // or front of the list. 53 node->node_data->SplitPolygon(std::move(polygon), &new_front, &new_back,
54 switch (comparer_result) { 54 &is_coplanar);
55 case BSP_FRONT: 55 if (is_coplanar) {
56 front_list.push_back(PopFront(polygon_list)); 56 if (new_front)
57 break; 57 node->coplanars_front.push_back(std::move(new_front));
58 case BSP_BACK: 58 if (new_back)
59 back_list.push_back(PopFront(polygon_list)); 59 node->coplanars_back.push_back(std::move(new_back));
60 break; 60 } else {
61 case BSP_SPLIT: 61 if (new_front)
62 {
63 std::unique_ptr<DrawPolygon> polygon;
64 std::unique_ptr<DrawPolygon> new_front;
65 std::unique_ptr<DrawPolygon> new_back;
66 // Time to split this geometry, *it needs to be split by node_data.
67 polygon = PopFront(polygon_list);
68 bool split_result =
69 polygon->Split(*(node->node_data), &new_front, &new_back);
70 DCHECK(split_result);
71 if (!split_result) {
72 break;
73 }
74 front_list.push_back(std::move(new_front)); 62 front_list.push_back(std::move(new_front));
63 if (new_back)
75 back_list.push_back(std::move(new_back)); 64 back_list.push_back(std::move(new_back));
76 break;
77 }
78 case BSP_COPLANAR_FRONT:
79 node->coplanars_front.push_back(PopFront(polygon_list));
80 break;
81 case BSP_COPLANAR_BACK:
82 node->coplanars_back.push_back(PopFront(polygon_list));
83 break;
84 default:
85 NOTREACHED();
86 break;
87 } 65 }
88 } 66 }
89 67
90 // Build the back subtree using the front of the back_list as our splitter. 68 // Build the back subtree using the front of the back_list as our splitter.
91 if (back_list.size() > 0) { 69 if (back_list.size() > 0) {
92 node->back_child = base::WrapUnique(new BspNode(PopFront(&back_list))); 70 node->back_child = base::WrapUnique(new BspNode(PopFront(&back_list)));
93 BuildTree(node->back_child.get(), &back_list); 71 BuildTree(node->back_child.get(), &back_list);
94 } 72 }
95 73
96 // Build the front subtree using the front of the front_list as our splitter. 74 // Build the front subtree using the front of the front_list as our splitter.
97 if (front_list.size() > 0) { 75 if (front_list.size() > 0) {
98 node->front_child = base::WrapUnique(new BspNode(PopFront(&front_list))); 76 node->front_child = base::WrapUnique(new BspNode(PopFront(&front_list)));
99 BuildTree(node->front_child.get(), &front_list); 77 BuildTree(node->front_child.get(), &front_list);
100 } 78 }
101 } 79 }
102 80
103 BspCompareResult BspTree::GetNodePositionRelative(const DrawPolygon& node_a,
104 const DrawPolygon& node_b) {
105 return DrawPolygon::SideCompare(node_a, node_b);
106 }
107
108 // The base comparer with 0,0,0 as camera position facing forward 81 // The base comparer with 0,0,0 as camera position facing forward
109 BspCompareResult BspTree::GetCameraPositionRelative(const DrawPolygon& node) { 82 BspCompareResult BspTree::GetCameraPositionRelative(const DrawPolygon& node) {
110 if (node.normal().z() > 0.0f) { 83 if (node.normal().z() > 0.0f) {
111 return BSP_FRONT; 84 return BSP_FRONT;
112 } 85 }
113 return BSP_BACK; 86 return BSP_BACK;
114 } 87 }
115 88
116 BspTree::~BspTree() { 89 BspTree::~BspTree() {
117 } 90 }
118 91
119 } // namespace cc 92 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/bsp_tree.h ('k') | cc/output/bsp_tree_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698