diff options
author | Andre Susano Pinto <andresusanopinto@gmail.com> | 2009-08-29 21:24:45 +0400 |
---|---|---|
committer | Andre Susano Pinto <andresusanopinto@gmail.com> | 2009-08-29 21:24:45 +0400 |
commit | ea18c6ef0abcdd5841d77175a67e2611dce446b5 (patch) | |
tree | eef7a43d6618e0a7b3a89499776ab41b3fb50e41 /source/blender/render/intern/raytrace/bvh.h | |
parent | aec7f2f2c47d02b08383a4f30c0dd0067830b8c8 (diff) |
Code reorganization
-separated vbvh, svbvh, qbvh in diferent files (before the only way to switch between them was at compile time)
Diffstat (limited to 'source/blender/render/intern/raytrace/bvh.h')
-rw-r--r-- | source/blender/render/intern/raytrace/bvh.h | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/source/blender/render/intern/raytrace/bvh.h b/source/blender/render/intern/raytrace/bvh.h index 55bed6f0662..21234a40673 100644 --- a/source/blender/render/intern/raytrace/bvh.h +++ b/source/blender/render/intern/raytrace/bvh.h @@ -26,6 +26,12 @@ * * ***** END GPL LICENSE BLOCK ***** */ +#include "rayobject.h" +#include "MEM_guardedalloc.h" +#include "rayobject_rtbuild.h" +#include "rayobject_hint.h" + +#include <assert.h> #include <xmmintrin.h> #ifndef RE_RAYTRACE_BVH_H @@ -285,7 +291,6 @@ static int bvh_node_stack_raycast_simd(Node *root, Isect *isec) return hit; } - /* * recursively transverse a BVH looking for a rayhit using system stack */ @@ -336,4 +341,56 @@ static int bvh_node_raycast(Node *node, Isect *isec) } */ +template<class Node,class HintObject> +void bvh_dfs_make_hint(Node *node, LCTSHint *hint, int reserve_space, HintObject *hintObject) +{ + assert( hint->size + reserve_space + 1 <= RE_RAY_LCTS_MAX_SIZE ); + + if(is_leaf(node)) + { + hint->stack[hint->size++] = (RayObject*)node; + } + else + { + int childs = count_childs(node); + if(hint->size + reserve_space + childs <= RE_RAY_LCTS_MAX_SIZE) + { + int result = hint_test_bb(hintObject, node->bb, node->bb+3); + if(result == HINT_RECURSE) + { + /* We are 100% sure the ray will be pass inside this node */ + bvh_dfs_make_hint_push_siblings(node->child, hint, reserve_space, hintObject); + } + else if(result == HINT_ACCEPT) + { + hint->stack[hint->size++] = (RayObject*)node; + } + } + else + { + hint->stack[hint->size++] = (RayObject*)node; + } + } +} + + +template<class Tree> +static RayObjectAPI* bvh_get_api(int maxstacksize); + + +template<class Tree, int DFS_STACK_SIZE> +static inline RayObject *bvh_create_tree(int size) +{ + Tree *obj= (Tree*)MEM_callocN(sizeof(Tree), "BVHTree" ); + assert( RE_rayobject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */ + + obj->rayobj.api = bvh_get_api<Tree>(DFS_STACK_SIZE); + obj->root = NULL; + + obj->node_arena = NULL; + obj->builder = rtbuild_create( size ); + + return RE_rayobject_unalignRayAPI((RayObject*) obj); +} + #endif |