~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/render/intern/raytrace/rayobject_vbvh.cpp

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
#include "MEM_guardedalloc.h"
40
40
 
41
 
#include "BKE_global.h"
42
 
 
43
41
#include "BLI_math.h"
44
42
#include "BLI_memarena.h"
45
43
#include "BLI_utildefines.h"
46
44
 
 
45
#include "BKE_global.h"
 
46
 
47
47
#include "rayintersection.h"
48
48
#include "rayobject.h"
49
49
#include "rayobject_rtbuild.h"
55
55
#include <queue>
56
56
#include <algorithm>
57
57
 
58
 
#define DFS_STACK_SIZE  256
 
58
#define DFS_STACK_SIZE  256
59
59
 
60
 
struct VBVHTree
61
 
{
 
60
struct VBVHTree {
62
61
        RayObject rayobj;
63
62
        VBVHNode *root;
64
63
        MemArena *node_arena;
69
68
/*
70
69
 * Cost to test N childs
71
70
 */
72
 
struct PackCost
73
 
{
 
71
struct PackCost {
74
72
        float operator()(int n)
75
73
        {
76
74
                return n;
84
82
        
85
83
        //TODO find a away to exactly calculate the needed memory
86
84
        MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "vbvh arena");
87
 
                                           BLI_memarena_use_malloc(arena1);
 
85
        BLI_memarena_use_malloc(arena1);
88
86
        
89
87
        //Build and optimize the tree
90
 
        if (1)
91
 
        {
92
 
                VBVHNode *root = BuildBinaryVBVH<VBVHNode>(arena1,&obj->rayobj.control).transform(obj->builder);
93
 
                if (RE_rayobjectcontrol_test_break(&obj->rayobj.control))
94
 
                {
 
88
        if (1) {
 
89
                VBVHNode *root = BuildBinaryVBVH<VBVHNode>(arena1, &obj->rayobj.control).transform(obj->builder);
 
90
                if (RE_rayobjectcontrol_test_break(&obj->rayobj.control)) {
95
91
                        BLI_memarena_free(arena1);
96
92
                        return;
97
93
                }
108
104
                else
109
105
                        obj->root = NULL;
110
106
        }
111
 
        else
112
 
        {
113
 
/*
114
 
        TODO
 
107
        else {
 
108
                /* TODO */
 
109
#if 0
115
110
                MemArena *arena2 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "vbvh arena2");
116
 
                                                   BLI_memarena_use_malloc(arena2);
 
111
                BLI_memarena_use_malloc(arena2);
117
112
                                                   
118
113
                //Finds the optimal packing of this tree using a given cost model
119
114
                //TODO this uses quite a lot of memory, find ways to reduce memory usage during building
120
 
                OVBVHNode *root = BuildBinaryVBVH<OVBVHNode>(arena2).transform(obj->builder);                   
121
 
                VBVH_optimalPackSIMD<OVBVHNode,PackCost>(PackCost()).transform(root);
 
115
                OVBVHNode *root = BuildBinaryVBVH<OVBVHNode>(arena2).transform(obj->builder);
 
116
                VBVH_optimalPackSIMD<OVBVHNode, PackCost>(PackCost()).transform(root);
122
117
                obj->root = Reorganize_VBVH<OVBVHNode>(arena1).transform(root);
123
118
                
124
119
                BLI_memarena_free(arena2);
125
 
 */
 
120
#endif
126
121
        }
127
122
 
128
123
        //Cleanup
129
 
        rtbuild_free( obj->builder );
 
124
        rtbuild_free(obj->builder);
130
125
        obj->builder = NULL;
131
126
 
132
127
        obj->node_arena = arena1;
133
 
        obj->cost = 1.0;        
 
128
        obj->cost = 1.0;
134
129
}
135
130
 
136
131
template<int StackSize>
137
 
int intersect(VBVHTree *obj, Isect* isec)
 
132
int intersect(VBVHTree *obj, Isect *isec)
138
133
{
139
134
        //TODO renable hint support
140
135
        if (RE_rayobject_isAligned(obj->root)) {
141
136
                if (isec->mode == RE_RAY_SHADOW)
142
 
                        return bvh_node_stack_raycast<VBVHNode,StackSize,false,true>( obj->root, isec);
 
137
                        return bvh_node_stack_raycast<VBVHNode, StackSize, false, true>(obj->root, isec);
143
138
                else
144
 
                        return bvh_node_stack_raycast<VBVHNode,StackSize,false,false>( obj->root, isec);
 
139
                        return bvh_node_stack_raycast<VBVHNode, StackSize, false, false>(obj->root, isec);
145
140
        }
146
141
        else
147
 
                return RE_rayobject_intersect( (RayObject*) obj->root, isec );
 
142
                return RE_rayobject_intersect( (RayObject *) obj->root, isec);
148
143
}
149
144
 
150
145
template<class Tree>
153
148
        //TODO renable hint support
154
149
        {
155
150
                hint->size = 0;
156
 
                hint->stack[hint->size++] = (RayObject*)tree->root;
 
151
                hint->stack[hint->size++] = (RayObject *)tree->root;
157
152
        }
158
153
}
159
154
 
160
 
void bfree(VBVHTree *tree)
 
155
#if 0  /* UNUSED */
 
156
static void bfree(VBVHTree *tree)
161
157
{
162
 
        if (tot_pushup + tot_pushdown + tot_hints + tot_moves)
163
 
        {
 
158
        if (tot_pushup + tot_pushdown + tot_hints + tot_moves) {
164
159
                if (G.debug & G_DEBUG) {
165
160
                        printf("tot pushups: %d\n", tot_pushup);
166
161
                        printf("tot pushdowns: %d\n", tot_pushdown);
175
170
        }
176
171
        bvh_free(tree);
177
172
}
 
173
#endif
178
174
 
179
175
/* the cast to pointer function is needed to workarround gcc bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11407 */
180
176
template<class Tree, int STACK_SIZE>
182
178
{
183
179
        static RayObjectAPI api = 
184
180
        {
185
 
                (RE_rayobject_raycast_callback) ((int(*)(Tree*,Isect*)) &intersect<STACK_SIZE>),
186
 
                (RE_rayobject_add_callback)     ((void(*)(Tree*,RayObject*)) &bvh_add<Tree>),
187
 
                (RE_rayobject_done_callback)    ((void(*)(Tree*))       &bvh_done<Tree>),
188
 
                (RE_rayobject_free_callback)    ((void(*)(Tree*))       &bvh_free<Tree>),
189
 
                (RE_rayobject_merge_bb_callback)((void(*)(Tree*,float*,float*)) &bvh_bb<Tree>),
190
 
                (RE_rayobject_cost_callback)    ((float(*)(Tree*))      &bvh_cost<Tree>),
191
 
                (RE_rayobject_hint_bb_callback) ((void(*)(Tree*,LCTSHint*,float*,float*)) &bvh_hint_bb<Tree>)
 
181
                (RE_rayobject_raycast_callback) ((int   (*)(Tree *, Isect *)) & intersect<STACK_SIZE>),
 
182
                (RE_rayobject_add_callback)     ((void  (*)(Tree *, RayObject *)) & bvh_add<Tree>),
 
183
                (RE_rayobject_done_callback)    ((void  (*)(Tree *))       & bvh_done<Tree>),
 
184
                (RE_rayobject_free_callback)    ((void  (*)(Tree *))       & bvh_free<Tree>),
 
185
                (RE_rayobject_merge_bb_callback)((void  (*)(Tree *, float *, float *)) & bvh_bb<Tree>),
 
186
                (RE_rayobject_cost_callback)    ((float (*)(Tree *))      & bvh_cost<Tree>),
 
187
                (RE_rayobject_hint_bb_callback) ((void  (*)(Tree *, LCTSHint *, float *, float *)) & bvh_hint_bb<Tree>)
192
188
        };
193
189
        
194
190
        return api;
195
191
}
196
192
 
197
193
template<class Tree>
198
 
RayObjectAPI* bvh_get_api(int maxstacksize)
 
194
RayObjectAPI *bvh_get_api(int maxstacksize)
199
195
{
200
 
        static RayObjectAPI bvh_api256 = make_api<Tree,1024>();
 
196
        static RayObjectAPI bvh_api256 = make_api<Tree, 1024>();
201
197
        
202
198
        if (maxstacksize <= 1024) return &bvh_api256;
203
199
        assert(maxstacksize <= 256);
206
202
 
207
203
RayObject *RE_rayobject_vbvh_create(int size)
208
204
{
209
 
        return bvh_create_tree<VBVHTree,DFS_STACK_SIZE>(size);
 
205
        return bvh_create_tree<VBVHTree, DFS_STACK_SIZE>(size);
210
206
}