diff options
author | Andre Susano Pinto <andresusanopinto@gmail.com> | 2009-06-30 18:05:33 +0400 |
---|---|---|
committer | Andre Susano Pinto <andresusanopinto@gmail.com> | 2009-06-30 18:05:33 +0400 |
commit | 021e0cc53f5169a92e06eafa321bc53b305f002f (patch) | |
tree | ba43f07710d879a413c0011c002e1ca4b4e49804 /source | |
parent | e0cfafa6292cbcec5d49817583204a418308aac7 (diff) |
*reserved RayObject align offset 0 for private usage inside each structure
point is that other structures like trees can then distiguish between other nodes or rayobject primitives
withouth needing any other variable.
(Note yet used but will reduce memory by a nice factor (linear to the number of primitives))
Diffstat (limited to 'source')
7 files changed, 32 insertions, 22 deletions
diff --git a/source/blender/render/intern/include/rayobject.h b/source/blender/render/intern/include/rayobject.h index 53d96d6331f..d516c122bcc 100644 --- a/source/blender/render/intern/include/rayobject.h +++ b/source/blender/render/intern/include/rayobject.h @@ -58,13 +58,15 @@ only 2 are used: addr&2 - type of object - 0 RayFace - 1 RayObject (generic with API callbacks) - 2 unused + 0 Self (reserved for each structure) + 1 RayFace + 2 RayObject (generic with API callbacks) 3 unused - 0 was choosed to RayFace because thats the one where speed will be needed. - + 0 means it's reserved and has it own meaning inside each ray acceleration structure + (this way each structure can use the allign offset to determine if a node represents a + RayObject primitive, which can be used to save memory) + You actually don't need to care about this if you are only using the API described on RE_raytrace.h */ @@ -101,10 +103,13 @@ typedef struct RayObjectAPI } RayObjectAPI; //TODO use intptr_t -#define RayObject_align(o) ((RayObject*)(((int)o)&(~3))) -#define RayObject_unalign(o) ((RayObject*)(((int)o)|1)) -#define RayObject_isFace(o) ((((int)o)&3) == 0) +#define RayObject_align(o) ((RayObject*)(((int)o)&(~3))) +#define RayObject_unalignRayFace(o) ((RayObject*)(((int)o)|1)) +#define RayObject_unalignRayAPI(o) ((RayObject*)(((int)o)|2)) + #define RayObject_isAligned(o) ((((int)o)&3) == 0) +#define RayObject_isRayFace(o) ((((int)o)&3) == 1) +#define RayObject_isRayAPI(o) ((((int)o)&3) == 2) /* * Extend min/max coords so that the rayobject is inside them diff --git a/source/blender/render/intern/source/rayobject.c b/source/blender/render/intern/source/rayobject.c index ef224dc7d21..3af2969b67e 100644 --- a/source/blender/render/intern/source/rayobject.c +++ b/source/blender/render/intern/source/rayobject.c @@ -255,7 +255,7 @@ static int intersect_rayface(RayFace *face, Isect *is) is->hit.ob = face->ob; is->hit.face = face->face; - is->last_hit = (RayObject*)face; + is->last_hit = (RayObject*) RayObject_unalignRayFace(face); return 1; } @@ -289,15 +289,16 @@ int RE_rayobject_raycast(RayObject *r, Isect *i) int RE_rayobject_intersect(RayObject *r, Isect *i) { - if(RayObject_isFace(r)) + if(RayObject_isRayFace(r)) { - return intersect_rayface( (RayFace*) r, i); + return intersect_rayface( (RayFace*) RayObject_align(r), i); } - else + else if(RayObject_isRayAPI(r)) { r = RayObject_align( r ); return r->api->raycast( r, i ); } + else assert(0); } void RE_rayobject_add(RayObject *r, RayObject *o) @@ -320,19 +321,20 @@ void RE_rayobject_free(RayObject *r) void RE_rayobject_merge_bb(RayObject *r, float *min, float *max) { - if(RayObject_isFace(r)) + if(RayObject_isRayFace(r)) { - RayFace *face = (RayFace*)r; + RayFace *face = (RayFace*) RayObject_align(r); DO_MINMAX( face->v1, min, max ); DO_MINMAX( face->v2, min, max ); DO_MINMAX( face->v3, min, max ); if(face->v4) DO_MINMAX( face->v4, min, max ); } - else + else if(RayObject_isRayAPI(r)) { r = RayObject_align( r ); r->api->bb( r, min, max ); } + else assert(0); } #ifdef RE_RAYCOUNTER diff --git a/source/blender/render/intern/source/rayobject_bvh.c b/source/blender/render/intern/source/rayobject_bvh.c index c5e0cca808c..54fbc5ba0be 100644 --- a/source/blender/render/intern/source/rayobject_bvh.c +++ b/source/blender/render/intern/source/rayobject_bvh.c @@ -69,7 +69,7 @@ RayObject *RE_rayobject_bvh_create(int size) obj->bvh = BLI_bvhtree_new(size, FLT_EPSILON, 4, 6); INIT_MINMAX(obj->bb[0], obj->bb[1]); - return RayObject_unalign((RayObject*) obj); + return RayObject_unalignRayAPI((RayObject*) obj); } static void bvh_callback(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit) diff --git a/source/blender/render/intern/source/rayobject_instance.c b/source/blender/render/intern/source/rayobject_instance.c index a5024e97450..4a67e8108cb 100644 --- a/source/blender/render/intern/source/rayobject_instance.c +++ b/source/blender/render/intern/source/rayobject_instance.c @@ -74,7 +74,7 @@ RayObject *RE_rayobject_instance_create(RayObject *target, float transform[][4], Mat4CpyMat4(obj->target2global, transform); Mat4Invert(obj->global2target, obj->target2global); - return RayObject_unalign((RayObject*) obj); + return RayObject_unalignRayAPI((RayObject*) obj); } static int RayObject_instance_intersect(RayObject *o, Isect *isec) diff --git a/source/blender/render/intern/source/rayobject_mesh.c b/source/blender/render/intern/source/rayobject_mesh.c index eee7231aef4..538c245988d 100644 --- a/source/blender/render/intern/source/rayobject_mesh.c +++ b/source/blender/render/intern/source/rayobject_mesh.c @@ -128,5 +128,5 @@ RayObject* RE_rayobject_mesh_create(Mesh *mesh, void *ob) face->face = (void*)i; } - return RayObject_unalign((RayObject*) rm); + return RayObject_unalignRayAPI((RayObject*) rm); } diff --git a/source/blender/render/intern/source/rayobject_octree.c b/source/blender/render/intern/source/rayobject_octree.c index b715695dc10..b7850c05104 100644 --- a/source/blender/render/intern/source/rayobject_octree.c +++ b/source/blender/render/intern/source/rayobject_octree.c @@ -461,7 +461,7 @@ RayObject *RE_rayobject_octree_create(int ocres, int size) oc->ro_nodes_used = 0; - return RayObject_unalign((RayObject*) oc); + return RayObject_unalignRayAPI((RayObject*) oc); } @@ -631,7 +631,7 @@ static void RayObject_octree_done(RayObject *tree) for(c=0; c<oc->ro_nodes_used; c++) { - assert( RayObject_isFace(oc->ro_nodes[c]) ); + assert( RayObject_isRayFace(oc->ro_nodes[c]) ); octree_fill_rayface(oc, (RayFace*)oc->ro_nodes[c]); } diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c index 3fe3ac8690b..975de3a5da3 100644 --- a/source/blender/render/intern/source/rayshade.c +++ b/source/blender/render/intern/source/rayshade.c @@ -198,7 +198,9 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi) face->ob = obi; face->face = vlr; - RE_rayobject_add( raytree, (RayObject*)face++ ); + RE_rayobject_add( raytree, RayObject_unalignRayFace(face) ); + + face++; } } RE_rayobject_done( raytree ); @@ -311,7 +313,8 @@ static void makeraytree_single(Render *re) face->ob = obi; face->face = vlr; - RE_rayobject_add( raytree, (RayObject*)face++ ); + RE_rayobject_add( raytree, RayObject_unalignRayFace(face) ); + face++; } } RE_rayobject_done( raytree ); |