Blender V2.61 - r43446

rayobject_internal.h

Go to the documentation of this file.
00001 
00005 #ifndef RE_RAYOBJECT_INTERNAL_H
00006 #define RE_RAYOBJECT_INTERNAL_H
00007 
00008 #ifdef __cplusplus
00009 extern "C" {
00010 #endif
00011 
00012 /* RayObjectControl
00013  *
00014  * This class is intended as a place holder for control, configuration of the
00015  * rayobject like:
00016  *  - stop building (TODO maybe when porting build to threads this could be
00017  *    implemented with some thread_cancel function)
00018  *  - max number of threads and threads callback to use during build
00019  *  ...
00020  */ 
00021 
00022 typedef int  (*RE_rayobjectcontrol_test_break_callback)(void *data);
00023 
00024 typedef struct RayObjectControl {
00025     void *data;
00026     RE_rayobjectcontrol_test_break_callback test_break; 
00027 } RayObjectControl;
00028 
00029 /* Returns true if for some reason a heavy processing function should stop
00030  * (eg.: user asked to stop during a tree a build)
00031  */
00032 
00033 int RE_rayobjectcontrol_test_break(RayObjectControl *c);
00034 
00035 /* RayObject
00036     
00037     A ray object is everything where we can cast rays like:
00038         * a face/triangle
00039         * an octree
00040         * a bvh tree
00041         * an octree of bvh's
00042         * a bvh of bvh's
00043     
00044         
00045     All types of RayObjects can be created by implementing the
00046     callbacks of the RayObject.
00047 
00048     Due to high computing time evolved with casting on faces
00049     there is a special type of RayObject (named RayFace)
00050     which won't use callbacks like other generic nodes.
00051     
00052     In order to allow a mixture of RayFace+RayObjects,
00053     all RayObjects must be 4byte aligned, allowing us to use the
00054     2 least significant bits (with the mask 0x03) to define the
00055     type of RayObject.
00056     
00057     This leads to 4 possible types of RayObject:
00058 
00059      addr&3  - type of object
00060         0       Self (reserved for each structure)
00061         1       RayFace (tri/quad primitive)
00062         2       RayObject (generic with API callbacks)
00063         3       VlakPrimitive
00064                 (vlak primitive - to be used when we have a vlak describing the data
00065                  eg.: on render code)
00066 
00067     0 means it's reserved and has it own meaning inside each ray acceleration structure
00068     (this way each structure can use the allign offset to determine if a node represents a
00069      RayObject primitive, which can be used to save memory)
00070  */
00071 
00072 /* used to test the type of ray object */
00073 #define RE_rayobject_isAligned(o)       ((((intptr_t)o)&3) == 0)
00074 #define RE_rayobject_isRayFace(o)       ((((intptr_t)o)&3) == 1)
00075 #define RE_rayobject_isRayAPI(o)        ((((intptr_t)o)&3) == 2)
00076 #define RE_rayobject_isVlakPrimitive(o) ((((intptr_t)o)&3) == 3)
00077 
00078 /* used to align a given ray object */
00079 #define RE_rayobject_align(o)                   ((RayObject*)(((intptr_t)o)&(~3)))
00080 
00081 /* used to unalign a given ray object */
00082 #define RE_rayobject_unalignRayFace(o)          ((RayObject*)(((intptr_t)o)|1))
00083 #define RE_rayobject_unalignRayAPI(o)           ((RayObject*)(((intptr_t)o)|2))
00084 #define RE_rayobject_unalignVlakPrimitive(o)    ((RayObject*)(((intptr_t)o)|3))
00085 
00086 /*
00087  * This rayobject represents a generic object. With it's own callbacks for raytrace operations.
00088  * It's suitable to implement things like LOD.
00089  */
00090 
00091 struct RayObject {
00092     struct RayObjectAPI *api;
00093     struct RayObjectControl control;
00094 };
00095 
00096 typedef int  (*RE_rayobject_raycast_callback)(RayObject *, struct Isect *);
00097 typedef void (*RE_rayobject_add_callback)(RayObject *raytree, RayObject *rayobject);
00098 typedef void (*RE_rayobject_done_callback)(RayObject *);
00099 typedef void (*RE_rayobject_free_callback)(RayObject *);
00100 typedef void (*RE_rayobject_merge_bb_callback)(RayObject *, float *min, float *max);
00101 typedef float (*RE_rayobject_cost_callback)(RayObject *);
00102 typedef void (*RE_rayobject_hint_bb_callback)(RayObject *, struct RayHint *, float *, float *);
00103 
00104 typedef struct RayObjectAPI {
00105     RE_rayobject_raycast_callback   raycast;
00106     RE_rayobject_add_callback       add;
00107     RE_rayobject_done_callback      done;
00108     RE_rayobject_free_callback      free;
00109     RE_rayobject_merge_bb_callback  bb;
00110     RE_rayobject_cost_callback      cost;
00111     RE_rayobject_hint_bb_callback   hint_bb;
00112 } RayObjectAPI;
00113 
00114 /*
00115  * Returns the expected cost of raycast on this node, primitives have a cost of 1
00116  */
00117 float RE_rayobject_cost(RayObject *r);
00118 
00119 /*
00120  * This function differs from RE_rayobject_raycast
00121  * RE_rayobject_intersect does NOT perform last-hit optimization
00122  * So this is probably a function to call inside raytrace structures
00123  */
00124 int RE_rayobject_intersect(RayObject *r, struct Isect *i);
00125 
00126 #ifdef __cplusplus
00127 }
00128 #endif
00129 
00130 #endif
00131