diff options
author | Andre Susano Pinto <andresusanopinto@gmail.com> | 2009-09-15 19:15:43 +0400 |
---|---|---|
committer | Andre Susano Pinto <andresusanopinto@gmail.com> | 2009-09-15 19:15:43 +0400 |
commit | f7c686d0ae68842feddd4f37deadab12e1fa4991 (patch) | |
tree | 52773e6d6236aec9a3a80bf6c5c1ea5f7e943224 /source/blender/blenkernel/BKE_utildefines.h | |
parent | f8657be654f89c6a4826ef8dd3e2275dfe2d4a5a (diff) | |
parent | 0338b05a64184ce1a439a418ebc4e315185c1eec (diff) |
svn merge -r 22571:22800 https://svn.blender.org/svnroot/bf-blender/trunk/blender
svn merge -r 22800:23207 https://svn.blender.org/svnroot/bf-blender/trunk/blender
Merged volumetric with new raytrace code (it compiles and rendered volume-cube.blend withouth problems)
Part1:
source/blender
Diffstat (limited to 'source/blender/blenkernel/BKE_utildefines.h')
-rw-r--r-- | source/blender/blenkernel/BKE_utildefines.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_utildefines.h b/source/blender/blenkernel/BKE_utildefines.h index eba5032997d..c0ed8430177 100644 --- a/source/blender/blenkernel/BKE_utildefines.h +++ b/source/blender/blenkernel/BKE_utildefines.h @@ -115,6 +115,7 @@ #define VECSUB(v1,v2,v3) {*(v1)= *(v2) - *(v3); *(v1+1)= *(v2+1) - *(v3+1); *(v1+2)= *(v2+2) - *(v3+2);} #define VECSUB2D(v1,v2,v3) {*(v1)= *(v2) - *(v3); *(v1+1)= *(v2+1) - *(v3+1);} #define VECADDFAC(v1,v2,v3,fac) {*(v1)= *(v2) + *(v3)*(fac); *(v1+1)= *(v2+1) + *(v3+1)*(fac); *(v1+2)= *(v2+2) + *(v3+2)*(fac);} +#define VECSUBFAC(v1,v2,v3,fac) {*(v1)= *(v2) - *(v3)*(fac); *(v1+1)= *(v2+1) - *(v3+1)*(fac); *(v1+2)= *(v2+2) - *(v3+2)*(fac);} #define QUATADDFAC(v1,v2,v3,fac) {*(v1)= *(v2) + *(v3)*(fac); *(v1+1)= *(v2+1) + *(v3+1)*(fac); *(v1+2)= *(v2+2) + *(v3+2)*(fac); *(v1+3)= *(v2+3) + *(v3+3)*(fac);} #define INPR(v1, v2) ( (v1)[0]*(v2)[0] + (v1)[1]*(v2)[1] + (v1)[2]*(v2)[2] ) @@ -200,5 +201,54 @@ #define SET_INT_IN_POINTER(i) ((void*)(intptr_t)(i)) #define GET_INT_FROM_POINTER(i) ((int)(intptr_t)(i)) +/*little array macro library. example of usage: + +int *arr = NULL; +V_DECLARE(arr); +int i; + +for (i=0; i<10; i++) { + V_GROW(arr); + arr[i] = something; +} +V_FREE(arr); + +arrays are buffered, using double-buffering (so on each reallocation, +the array size is doubled). supposedly this should give good Big Oh +behaviour, though it may not be the best in practice. +*/ + +#define V_DECLARE(vec) int _##vec##_count=0; void *_##vec##_tmp + +/*in the future, I plan on having V_DECLARE allocate stack memory it'll + use at first, and switch over to heap when it needs more. that'll mess + up cases where you'd want to use this API to build a dynamic list for + non-local use, so all such cases should use this macro.*/ +#define V_DYNDECLARE(vec) V_DECLARE(vec) + +/*this returns the entire size of the array, including any buffering.*/ +#define V_SIZE(vec) ((signed int)((vec)==NULL ? 0 : MEM_allocN_len(vec) / sizeof(*vec))) + +/*this returns the logical size of the array, not including buffering.*/ +#define V_COUNT(vec) _##vec##_count + +/*grow the array by one. zeroes the new elements.*/ +#define V_GROW(vec) \ + V_SIZE(vec) > _##vec##_count ? _##vec##_count++ : \ + ((_##vec##_tmp = MEM_callocN(sizeof(*vec)*(_##vec##_count*2+2), #vec " " __FILE__ " ")),\ + (vec && memcpy(_##vec##_tmp, vec, sizeof(*vec) * _##vec##_count)),\ + (vec && (MEM_freeN(vec),1)),\ + (vec = _##vec##_tmp),\ + _##vec##_count++) + +#define V_FREE(vec) if (vec) MEM_freeN(vec); + +/*resets the logical size of an array to zero, but doesn't + free the memory.*/ +#define V_RESET(vec) _##vec##_count=0 + +/*set the count of the array*/ +#define V_SETCOUNT(vec, count) _##vec##_count = (count) + #endif |