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

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

Issue 2060183003: Revert of Perform BSP polygon splitting and orientation selection in a single step. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 std::unique_ptr<DrawPolygon> polygon; 47 // Is this particular polygon in front of or behind our splitting polygon.
48 std::unique_ptr<DrawPolygon> new_front; 48 BspCompareResult comparer_result =
49 std::unique_ptr<DrawPolygon> new_back; 49 GetNodePositionRelative(*polygon_list->front(), *(node->node_data));
50 // Time to split this geometry, *it needs to be split by node_data. 50
51 polygon = PopFront(polygon_list); 51 // If it's clearly behind or in front of the splitting plane, we use the
52 bool is_coplanar; 52 // heuristic to decide whether or not we should put it at the back
53 node->node_data->SplitPolygon(std::move(polygon), &new_front, &new_back, 53 // or front of the list.
54 &is_coplanar); 54 switch (comparer_result) {
55 if (is_coplanar) { 55 case BSP_FRONT:
56 if (new_front) 56 front_list.push_back(PopFront(polygon_list));
57 node->coplanars_front.push_back(std::move(new_front)); 57 break;
58 if (new_back) 58 case BSP_BACK:
59 node->coplanars_back.push_back(std::move(new_back)); 59 back_list.push_back(PopFront(polygon_list));
60 } else { 60 break;
61 if (new_front) 61 case BSP_SPLIT:
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 }
62 front_list.push_back(std::move(new_front)); 74 front_list.push_back(std::move(new_front));
63 if (new_back)
64 back_list.push_back(std::move(new_back)); 75 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;
65 } 87 }
66 } 88 }
67 89
68 // Build the back subtree using the front of the back_list as our splitter. 90 // Build the back subtree using the front of the back_list as our splitter.
69 if (back_list.size() > 0) { 91 if (back_list.size() > 0) {
70 node->back_child = base::WrapUnique(new BspNode(PopFront(&back_list))); 92 node->back_child = base::WrapUnique(new BspNode(PopFront(&back_list)));
71 BuildTree(node->back_child.get(), &back_list); 93 BuildTree(node->back_child.get(), &back_list);
72 } 94 }
73 95
74 // Build the front subtree using the front of the front_list as our splitter. 96 // Build the front subtree using the front of the front_list as our splitter.
75 if (front_list.size() > 0) { 97 if (front_list.size() > 0) {
76 node->front_child = base::WrapUnique(new BspNode(PopFront(&front_list))); 98 node->front_child = base::WrapUnique(new BspNode(PopFront(&front_list)));
77 BuildTree(node->front_child.get(), &front_list); 99 BuildTree(node->front_child.get(), &front_list);
78 } 100 }
79 } 101 }
80 102
103 BspCompareResult BspTree::GetNodePositionRelative(const DrawPolygon& node_a,
104 const DrawPolygon& node_b) {
105 return DrawPolygon::SideCompare(node_a, node_b);
106 }
107
81 // The base comparer with 0,0,0 as camera position facing forward 108 // The base comparer with 0,0,0 as camera position facing forward
82 BspCompareResult BspTree::GetCameraPositionRelative(const DrawPolygon& node) { 109 BspCompareResult BspTree::GetCameraPositionRelative(const DrawPolygon& node) {
83 if (node.normal().z() > 0.0f) { 110 if (node.normal().z() > 0.0f) {
84 return BSP_FRONT; 111 return BSP_FRONT;
85 } 112 }
86 return BSP_BACK; 113 return BSP_BACK;
87 } 114 }
88 115
89 BspTree::~BspTree() { 116 BspTree::~BspTree() {
90 } 117 }
91 118
92 } // namespace cc 119 } // 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