*reserved RayObject align offset 0 for private usage inside each structure
authorAndre Susano Pinto <andresusanopinto@gmail.com>
Tue, 30 Jun 2009 14:05:33 +0000 (14:05 +0000)
committerAndre Susano Pinto <andresusanopinto@gmail.com>
Tue, 30 Jun 2009 14:05:33 +0000 (14:05 +0000)
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))

source/blender/render/intern/include/rayobject.h
source/blender/render/intern/source/rayobject.c
source/blender/render/intern/source/rayobject_bvh.c
source/blender/render/intern/source/rayobject_instance.c
source/blender/render/intern/source/rayobject_mesh.c
source/blender/render/intern/source/rayobject_octree.c
source/blender/render/intern/source/rayshade.c

index 53d96d6331fce36caf51797a59d8cda0df8eef17..d516c122bccc2f4c30c798468dfc9b71238fdea7 100644 (file)
        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
index ef224dc7d21b1e95153d77a7acd5bae076800a4f..3af2969b67e924544f87bdba5cec81571c8392ee 100644 (file)
@@ -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
index c5e0cca808c998384a429441230ccf2d37f7f5fd..54fbc5ba0bebbaebc31ebf7b82af47161ce9d74d 100644 (file)
@@ -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)
index a5024e97450ea976d2129aa2ad24d77146bb0cb7..4a67e8108cb4577054a4eb33426910d4dcf513c1 100644 (file)
@@ -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)
index eee7231aef42c0f7a2293e81f4b6bd9b04489d7b..538c245988d5cd14b6e916ed08c74c8aaebb3805 100644 (file)
@@ -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);
 }
index b715695dc109eafe5487c00942288defecfaa28b..b7850c05104ae170dc2c12f6d9053eeda22567d4 100644 (file)
@@ -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]);
        }
 
index 3fe3ac8690b2383d00328a11664599c33445c036..975de3a5da3c27bba7300a5b1f735990ce6f2c50 100644 (file)
@@ -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 );