Cycles: Split BVH implementations into separate files
[blender.git] / intern / cycles / bvh / bvh2.h
1 /*
2  * Adapted from code copyright 2009-2010 NVIDIA Corporation
3  * Modifications Copyright 2011, Blender Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #ifndef __BVH2_H__
19 #define __BVH2_H__
20
21 #include "bvh/bvh.h"
22 #include "bvh/bvh_params.h"
23
24 #include "util/util_types.h"
25 #include "util/util_vector.h"
26
27 CCL_NAMESPACE_BEGIN
28
29 class BVHNode;
30 struct BVHStackEntry;
31 class BVHParams;
32 class BoundBox;
33 class LeafNode;
34 class Object;
35 class Progress;
36
37 #define BVH_NODE_SIZE           4
38 #define BVH_NODE_LEAF_SIZE      1
39 #define BVH_UNALIGNED_NODE_SIZE 7
40
41 /* BVH2
42  *
43  * Typical BVH with each node having two children.
44  */
45 class BVH2 : public BVH {
46 protected:
47         /* constructor */
48         friend class BVH;
49         BVH2(const BVHParams& params, const vector<Object*>& objects);
50
51         /* pack */
52         void pack_nodes(const BVHNode *root);
53
54         void pack_leaf(const BVHStackEntry& e,
55                        const LeafNode *leaf);
56         void pack_inner(const BVHStackEntry& e,
57                         const BVHStackEntry& e0,
58                         const BVHStackEntry& e1);
59
60         void pack_aligned_inner(const BVHStackEntry& e,
61                                 const BVHStackEntry& e0,
62                                 const BVHStackEntry& e1);
63         void pack_aligned_node(int idx,
64                                const BoundBox& b0,
65                                const BoundBox& b1,
66                                int c0, int c1,
67                                uint visibility0, uint visibility1);
68
69         void pack_unaligned_inner(const BVHStackEntry& e,
70                                   const BVHStackEntry& e0,
71                                   const BVHStackEntry& e1);
72         void pack_unaligned_node(int idx,
73                                  const Transform& aligned_space0,
74                                  const Transform& aligned_space1,
75                                  const BoundBox& b0,
76                                  const BoundBox& b1,
77                                  int c0, int c1,
78                                  uint visibility0, uint visibility1);
79
80         /* refit */
81         void refit_nodes();
82         void refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility);
83 };
84
85 CCL_NAMESPACE_END
86
87 #endif /* __BVH2_H__ */