diff options
Diffstat (limited to 'src/mesa/main/macros.h')
-rw-r--r-- | src/mesa/main/macros.h | 277 |
1 files changed, 172 insertions, 105 deletions
diff --git a/src/mesa/main/macros.h b/src/mesa/main/macros.h index 9f326a0093b..fcb63f53f20 100644 --- a/src/mesa/main/macros.h +++ b/src/mesa/main/macros.h @@ -1,3 +1,7 @@ +/** + * \file macros.h + * A collection of useful macros. + */ /* * Mesa 3-D graphics library @@ -24,60 +28,56 @@ */ -/* - * A collection of useful macros. - */ - #ifndef MACROS_H #define MACROS_H #include "imports.h" -/* - * Integer / float conversion for colors, normals, etc. +/** + * \name Integer / float conversion for colors, normals, etc. */ +/*@{*/ -/* Convert GLubyte in [0,255] to GLfloat in [0.0,1.0] */ +/** Convert GLubyte in [0,255] to GLfloat in [0.0,1.0] */ extern GLfloat _mesa_ubyte_to_float_color_tab[256]; #define UBYTE_TO_FLOAT(u) _mesa_ubyte_to_float_color_tab[(unsigned int)(u)] -/* Convert GLfloat in [0.0,1.0] to GLubyte in [0,255] */ +/** Convert GLfloat in [0.0,1.0] to GLubyte in [0,255] */ #define FLOAT_TO_UBYTE(X) ((GLubyte) (GLint) ((X) * 255.0F)) -/* Convert GLbyte in [-128,127] to GLfloat in [-1.0,1.0] */ +/** Convert GLbyte in [-128,127] to GLfloat in [-1.0,1.0] */ #define BYTE_TO_FLOAT(B) ((2.0F * (B) + 1.0F) * (1.0F/255.0F)) -/* Convert GLfloat in [-1.0,1.0] to GLbyte in [-128,127] */ +/** Convert GLfloat in [-1.0,1.0] to GLbyte in [-128,127] */ #define FLOAT_TO_BYTE(X) ( (((GLint) (255.0F * (X))) - 1) / 2 ) -/* Convert GLushort in [0,65536] to GLfloat in [0.0,1.0] */ +/** Convert GLushort in [0,65536] to GLfloat in [0.0,1.0] */ #define USHORT_TO_FLOAT(S) ((GLfloat) (S) * (1.0F / 65535.0F)) -/* Convert GLfloat in [0.0,1.0] to GLushort in [0,65536] */ +/** Convert GLfloat in [0.0,1.0] to GLushort in [0,65536] */ #define FLOAT_TO_USHORT(X) ((GLushort) (GLint) ((X) * 65535.0F)) - -/* Convert GLshort in [-32768,32767] to GLfloat in [-1.0,1.0] */ +/** Convert GLshort in [-32768,32767] to GLfloat in [-1.0,1.0] */ #define SHORT_TO_FLOAT(S) ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)) -/* Convert GLfloat in [0.0,1.0] to GLshort in [-32768,32767] */ +/** Convert GLfloat in [0.0,1.0] to GLshort in [-32768,32767] */ #define FLOAT_TO_SHORT(X) ( (((GLint) (65535.0F * (X))) - 1) / 2 ) -/* Convert GLuint in [0,4294967295] to GLfloat in [0.0,1.0] */ +/** Convert GLuint in [0,4294967295] to GLfloat in [0.0,1.0] */ #define UINT_TO_FLOAT(U) ((GLfloat) (U) * (1.0F / 4294967295.0F)) -/* Convert GLfloat in [0.0,1.0] to GLuint in [0,4294967295] */ +/** Convert GLfloat in [0.0,1.0] to GLuint in [0,4294967295] */ #define FLOAT_TO_UINT(X) ((GLuint) ((X) * 4294967295.0)) -/* Convert GLint in [-2147483648,2147483647] to GLfloat in [-1.0,1.0] */ +/** Convert GLint in [-2147483648,2147483647] to GLfloat in [-1.0,1.0] */ #define INT_TO_FLOAT(I) ((2.0F * (I) + 1.0F) * (1.0F/4294967294.0F)) -/* Convert GLfloat in [-1.0,1.0] to GLint in [-2147483648,2147483647] */ +/** Convert GLfloat in [-1.0,1.0] to GLint in [-2147483648,2147483647] */ /* causes overflow: #define FLOAT_TO_INT(X) ( (((GLint) (4294967294.0F * (X))) - 1) / 2 ) */ @@ -103,52 +103,41 @@ extern GLfloat _mesa_ubyte_to_float_color_tab[256]; us = ( (GLushort) IROUND( (f) * 65535.0F) ) -/* Stepping a GLfloat pointer by a byte stride - */ +/** Stepping a GLfloat pointer by a byte stride */ #define STRIDE_F(p, i) (p = (GLfloat *)((GLubyte *)p + i)) +/** Stepping a GLuint pointer by a byte stride */ #define STRIDE_UI(p, i) (p = (GLuint *)((GLubyte *)p + i)) +/** Stepping a GLubyte[4] pointer by a byte stride */ #define STRIDE_4UB(p, i) (p = (GLubyte (*)[4])((GLubyte *)p + i)) +/** Stepping a GLchan[4] pointer by a byte stride */ #define STRIDE_4CHAN(p, i) (p = (GLchan (*)[4])((GLubyte *)p + i)) +/** Stepping a GLchan pointer by a byte stride */ #define STRIDE_CHAN(p, i) (p = (GLchan *)((GLubyte *)p + i)) +/** Stepping a \p t pointer by a byte stride */ #define STRIDE_T(p, t, i) (p = (t)((GLubyte *)p + i)) -#define ZERO_2V( DST ) (DST)[0] = (DST)[1] = 0 -#define ZERO_3V( DST ) (DST)[0] = (DST)[1] = (DST)[2] = 0 -#define ZERO_4V( DST ) (DST)[0] = (DST)[1] = (DST)[2] = (DST)[3] = 0 +/**********************************************************************/ +/** \name 4-element vector operations */ +/*@{*/ +/** Zero */ +#define ZERO_4V( DST ) (DST)[0] = (DST)[1] = (DST)[2] = (DST)[3] = 0 +/** Test for equality */ #define TEST_EQ_4V(a,b) ((a)[0] == (b)[0] && \ (a)[1] == (b)[1] && \ (a)[2] == (b)[2] && \ (a)[3] == (b)[3]) -#define TEST_EQ_3V(a,b) ((a)[0] == (b)[0] && \ - (a)[1] == (b)[1] && \ - (a)[2] == (b)[2]) - +/** Test for equality (unsigned bytes) */ #if defined(__i386__) #define TEST_EQ_4UBV(DST, SRC) *((GLuint*)(DST)) == *((GLuint*)(SRC)) #else #define TEST_EQ_4UBV(DST, SRC) TEST_EQ_4V(DST, SRC) #endif - - -/* Copy short vectors: */ -#define COPY_2V( DST, SRC ) \ -do { \ - (DST)[0] = (SRC)[0]; \ - (DST)[1] = (SRC)[1]; \ -} while (0) - -#define COPY_3V( DST, SRC ) \ -do { \ - (DST)[0] = (SRC)[0]; \ - (DST)[1] = (SRC)[1]; \ - (DST)[2] = (SRC)[2]; \ -} while (0) - +/** Copy a 4-element vector */ #define COPY_4V( DST, SRC ) \ do { \ (DST)[0] = (SRC)[0]; \ @@ -157,19 +146,7 @@ do { \ (DST)[3] = (SRC)[3]; \ } while (0) -#define COPY_2V_CAST( DST, SRC, CAST ) \ -do { \ - (DST)[0] = (CAST)(SRC)[0]; \ - (DST)[1] = (CAST)(SRC)[1]; \ -} while (0) - -#define COPY_3V_CAST( DST, SRC, CAST ) \ -do { \ - (DST)[0] = (CAST)(SRC)[0]; \ - (DST)[1] = (CAST)(SRC)[1]; \ - (DST)[2] = (CAST)(SRC)[2]; \ -} while (0) - +/** Copy a 4-element vector with cast */ #define COPY_4V_CAST( DST, SRC, CAST ) \ do { \ (DST)[0] = (CAST)(SRC)[0]; \ @@ -178,6 +155,7 @@ do { \ (DST)[3] = (CAST)(SRC)[3]; \ } while (0) +/** Copy a 4-element unsigned byte vector */ #if defined(__i386__) #define COPY_4UBV(DST, SRC) \ do { \ @@ -194,21 +172,7 @@ do { \ } while (0) #endif -#define COPY_2FV( DST, SRC ) \ -do { \ - const GLfloat *_tmp = (SRC); \ - (DST)[0] = _tmp[0]; \ - (DST)[1] = _tmp[1]; \ -} while (0) - -#define COPY_3FV( DST, SRC ) \ -do { \ - const GLfloat *_tmp = (SRC); \ - (DST)[0] = _tmp[0]; \ - (DST)[1] = _tmp[1]; \ - (DST)[2] = _tmp[2]; \ -} while (0) - +/** Copy a 4-element float vector */ #define COPY_4FV( DST, SRC ) \ do { \ const GLfloat *_tmp = (SRC); \ @@ -219,7 +183,7 @@ do { \ } while (0) - +/** Copy \p SZ elements into a 4-element vector */ #define COPY_SZ_4V(DST, SZ, SRC) \ do { \ switch (SZ) { \ @@ -230,12 +194,15 @@ do { \ } \ } while(0) +/** Copy \p SZ elements into a homegeneous (4-element) vector, giving + * default values to the remaining */ #define COPY_CLEAN_4V(DST, SZ, SRC) \ do { \ ASSIGN_4V( DST, 0, 0, 0, 1 ); \ COPY_SZ_4V( DST, SZ, SRC ); \ } while (0) +/** Subtraction */ #define SUB_4V( DST, SRCA, SRCB ) \ do { \ (DST)[0] = (SRCA)[0] - (SRCB)[0]; \ @@ -244,6 +211,7 @@ do { \ (DST)[3] = (SRCA)[3] - (SRCB)[3]; \ } while (0) +/** Addition */ #define ADD_4V( DST, SRCA, SRCB ) \ do { \ (DST)[0] = (SRCA)[0] + (SRCB)[0]; \ @@ -252,6 +220,7 @@ do { \ (DST)[3] = (SRCA)[3] + (SRCB)[3]; \ } while (0) +/** Element-wise multiplication */ #define SCALE_4V( DST, SRCA, SRCB ) \ do { \ (DST)[0] = (SRCA)[0] * (SRCB)[0]; \ @@ -260,6 +229,7 @@ do { \ (DST)[3] = (SRCA)[3] * (SRCB)[3]; \ } while (0) +/** In-place addition */ #define ACC_4V( DST, SRC ) \ do { \ (DST)[0] += (SRC)[0]; \ @@ -268,6 +238,7 @@ do { \ (DST)[3] += (SRC)[3]; \ } while (0) +/** Element-wise multiplication and addition */ #define ACC_SCALE_4V( DST, SRCA, SRCB ) \ do { \ (DST)[0] += (SRCA)[0] * (SRCB)[0]; \ @@ -276,6 +247,7 @@ do { \ (DST)[3] += (SRCA)[3] * (SRCB)[3]; \ } while (0) +/** In-place scalar multiplication and addition */ #define ACC_SCALE_SCALAR_4V( DST, S, SRCB ) \ do { \ (DST)[0] += S * (SRCB)[0]; \ @@ -284,6 +256,7 @@ do { \ (DST)[3] += S * (SRCB)[3]; \ } while (0) +/** Scalar multiplication */ #define SCALE_SCALAR_4V( DST, S, SRCB ) \ do { \ (DST)[0] = S * (SRCB)[0]; \ @@ -292,7 +265,7 @@ do { \ (DST)[3] = S * (SRCB)[3]; \ } while (0) - +/** In-place scalar multiplication */ #define SELF_SCALE_SCALAR_4V( DST, S ) \ do { \ (DST)[0] *= S; \ @@ -301,10 +274,56 @@ do { \ (DST)[3] *= S; \ } while (0) +/** Assignment */ +#define ASSIGN_4V( V, V0, V1, V2, V3 ) \ +do { \ + V[0] = V0; \ + V[1] = V1; \ + V[2] = V2; \ + V[3] = V3; \ +} while(0) -/* - * Similarly for 3-vectors. - */ +/*@}*/ + + +/**********************************************************************/ +/** \name 3-element vector operations*/ +/*@{*/ + +/** Zero */ +#define ZERO_3V( DST ) (DST)[0] = (DST)[1] = (DST)[2] = 0 + +/** Test for equality */ +#define TEST_EQ_3V(a,b) ((a)[0] == (b)[0] && \ + (a)[1] == (b)[1] && \ + (a)[2] == (b)[2]) + +/** Copy a 3-element vector */ +#define COPY_3V( DST, SRC ) \ +do { \ + (DST)[0] = (SRC)[0]; \ + (DST)[1] = (SRC)[1]; \ + (DST)[2] = (SRC)[2]; \ +} while (0) + +/** Copy a 3-element vector with cast */ +#define COPY_3V_CAST( DST, SRC, CAST ) \ +do { \ + (DST)[0] = (CAST)(SRC)[0]; \ + (DST)[1] = (CAST)(SRC)[1]; \ + (DST)[2] = (CAST)(SRC)[2]; \ +} while (0) + +/** Copy a 3-element float vector */ +#define COPY_3FV( DST, SRC ) \ +do { \ + const GLfloat *_tmp = (SRC); \ + (DST)[0] = _tmp[0]; \ + (DST)[1] = _tmp[1]; \ + (DST)[2] = _tmp[2]; \ +} while (0) + +/** Subtraction */ #define SUB_3V( DST, SRCA, SRCB ) \ do { \ (DST)[0] = (SRCA)[0] - (SRCB)[0]; \ @@ -312,6 +331,7 @@ do { \ (DST)[2] = (SRCA)[2] - (SRCB)[2]; \ } while (0) +/** Addition */ #define ADD_3V( DST, SRCA, SRCB ) \ do { \ (DST)[0] = (SRCA)[0] + (SRCB)[0]; \ @@ -319,6 +339,7 @@ do { \ (DST)[2] = (SRCA)[2] + (SRCB)[2]; \ } while (0) +/** In-place scalar multiplication */ #define SCALE_3V( DST, SRCA, SRCB ) \ do { \ (DST)[0] = (SRCA)[0] * (SRCB)[0]; \ @@ -326,6 +347,7 @@ do { \ (DST)[2] = (SRCA)[2] * (SRCB)[2]; \ } while (0) +/** In-place element-wise multiplication */ #define SELF_SCALE_3V( DST, SRC ) \ do { \ (DST)[0] *= (SRC)[0]; \ @@ -333,6 +355,7 @@ do { \ (DST)[2] *= (SRC)[2]; \ } while (0) +/** In-place addition */ #define ACC_3V( DST, SRC ) \ do { \ (DST)[0] += (SRC)[0]; \ @@ -340,6 +363,7 @@ do { \ (DST)[2] += (SRC)[2]; \ } while (0) +/** Element-wise multiplication and addition */ #define ACC_SCALE_3V( DST, SRCA, SRCB ) \ do { \ (DST)[0] += (SRCA)[0] * (SRCB)[0]; \ @@ -347,6 +371,7 @@ do { \ (DST)[2] += (SRCA)[2] * (SRCB)[2]; \ } while (0) +/** Scalar multiplication */ #define SCALE_SCALAR_3V( DST, S, SRCB ) \ do { \ (DST)[0] = S * (SRCB)[0]; \ @@ -354,6 +379,7 @@ do { \ (DST)[2] = S * (SRCB)[2]; \ } while (0) +/** In-place scalar multiplication and addition */ #define ACC_SCALE_SCALAR_3V( DST, S, SRCB ) \ do { \ (DST)[0] += S * (SRCB)[0]; \ @@ -361,6 +387,7 @@ do { \ (DST)[2] += S * (SRCB)[2]; \ } while (0) +/** In-place scalar multiplication */ #define SELF_SCALE_SCALAR_3V( DST, S ) \ do { \ (DST)[0] *= S; \ @@ -368,6 +395,7 @@ do { \ (DST)[2] *= S; \ } while (0) +/** In-place scalar addition */ #define ACC_SCALAR_3V( DST, S ) \ do { \ (DST)[0] += S; \ @@ -375,56 +403,103 @@ do { \ (DST)[2] += S; \ } while (0) -/* And also for 2-vectors - */ +/** Assignment */ +#define ASSIGN_3V( V, V0, V1, V2 ) \ +do { \ + V[0] = V0; \ + V[1] = V1; \ + V[2] = V2; \ +} while(0) + +/*@}*/ + + +/**********************************************************************/ +/** \name 2-element vector operations*/ +/*@{*/ + +/** Zero */ +#define ZERO_2V( DST ) (DST)[0] = (DST)[1] = 0 + +/** Copy a 2-element vector */ +#define COPY_2V( DST, SRC ) \ +do { \ + (DST)[0] = (SRC)[0]; \ + (DST)[1] = (SRC)[1]; \ +} while (0) + +/** Copy a 2-element vector with cast */ +#define COPY_2V_CAST( DST, SRC, CAST ) \ +do { \ + (DST)[0] = (CAST)(SRC)[0]; \ + (DST)[1] = (CAST)(SRC)[1]; \ +} while (0) + +/** Copy a 2-element float vector */ +#define COPY_2FV( DST, SRC ) \ +do { \ + const GLfloat *_tmp = (SRC); \ + (DST)[0] = _tmp[0]; \ + (DST)[1] = _tmp[1]; \ +} while (0) + +/** Subtraction */ #define SUB_2V( DST, SRCA, SRCB ) \ do { \ (DST)[0] = (SRCA)[0] - (SRCB)[0]; \ (DST)[1] = (SRCA)[1] - (SRCB)[1]; \ } while (0) +/** Addition */ #define ADD_2V( DST, SRCA, SRCB ) \ do { \ (DST)[0] = (SRCA)[0] + (SRCB)[0]; \ (DST)[1] = (SRCA)[1] + (SRCB)[1]; \ } while (0) +/** In-place scalar multiplication */ #define SCALE_2V( DST, SRCA, SRCB ) \ do { \ (DST)[0] = (SRCA)[0] * (SRCB)[0]; \ (DST)[1] = (SRCA)[1] * (SRCB)[1]; \ } while (0) +/** In-place addition */ #define ACC_2V( DST, SRC ) \ do { \ (DST)[0] += (SRC)[0]; \ (DST)[1] += (SRC)[1]; \ } while (0) +/** Element-wise multiplication and addition */ #define ACC_SCALE_2V( DST, SRCA, SRCB ) \ do { \ (DST)[0] += (SRCA)[0] * (SRCB)[0]; \ (DST)[1] += (SRCA)[1] * (SRCB)[1]; \ } while (0) +/** Scalar multiplication */ #define SCALE_SCALAR_2V( DST, S, SRCB ) \ do { \ (DST)[0] = S * (SRCB)[0]; \ (DST)[1] = S * (SRCB)[1]; \ } while (0) +/** In-place scalar multiplication and addition */ #define ACC_SCALE_SCALAR_2V( DST, S, SRCB ) \ do { \ (DST)[0] += S * (SRCB)[0]; \ (DST)[1] += S * (SRCB)[1]; \ } while (0) +/** In-place scalar multiplication */ #define SELF_SCALE_SCALAR_2V( DST, S ) \ do { \ (DST)[0] *= S; \ (DST)[1] *= S; \ } while (0) +/** In-place scalar addition */ #define ACC_SCALAR_2V( DST, S ) \ do { \ (DST)[0] += S; \ @@ -433,14 +508,15 @@ do { \ -/* +/** * Linear interpolation - * NOTE: OUT argument is evaluated twice! - * NOTE: Be wary of using *coord++ as an argument to any of these macros! + * + * \note \p OUT argument is evaluated twice! + * \note Be wary of using *coord++ as an argument to any of these macros! */ #define LINTERP(T, OUT, IN) ((OUT) + (T) * ((IN) - (OUT))) -/* Can do better with integer math: +/* Can do better with integer math */ #define INTERP_UB( t, dstub, outub, inub ) \ do { \ @@ -506,58 +582,47 @@ do { \ -/* Assign scalers to short vectors: */ +/** Assign scalers to short vectors */ #define ASSIGN_2V( V, V0, V1 ) \ do { \ V[0] = V0; \ V[1] = V1; \ } while(0) -#define ASSIGN_3V( V, V0, V1, V2 ) \ -do { \ - V[0] = V0; \ - V[1] = V1; \ - V[2] = V2; \ -} while(0) - -#define ASSIGN_4V( V, V0, V1, V2, V3 ) \ -do { \ - V[0] = V0; \ - V[1] = V1; \ - V[2] = V2; \ - V[3] = V3; \ -} while(0) +/*@}*/ -/* Clamp X to [MIN,MAX]: */ +/** Clamp X to [MIN,MAX] */ #define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) ) -/* Assign X to CLAMP(X, MIN, MAX) */ +/** Assign X to CLAMP(X, MIN, MAX) */ #define CLAMP_SELF(x, mn, mx) \ ( (x)<(mn) ? ((x) = (mn)) : ((x)>(mx) ? ((x)=(mx)) : (x)) ) -/* Min of two values: */ +/** Minimum of two values: */ #define MIN2( A, B ) ( (A)<(B) ? (A) : (B) ) -/* MAX of two values: */ +/** Maximum of two values: */ #define MAX2( A, B ) ( (A)>(B) ? (A) : (B) ) -/* Dot product of two 2-element vectors */ +/** Dot product of two 2-element vectors */ #define DOT2( a, b ) ( (a)[0]*(b)[0] + (a)[1]*(b)[1] ) -/* Dot product of two 3-element vectors */ +/** Dot product of two 3-element vectors */ #define DOT3( a, b ) ( (a)[0]*(b)[0] + (a)[1]*(b)[1] + (a)[2]*(b)[2] ) -/* Dot product of two 4-element vectors */ +/** Dot product of two 4-element vectors */ #define DOT4( a, b ) ( (a)[0]*(b)[0] + (a)[1]*(b)[1] + \ (a)[2]*(b)[2] + (a)[3]*(b)[3] ) +/** Dot product of two 4-element vectors */ #define DOT4V(v,a,b,c,d) (v[0]*(a) + v[1]*(b) + v[2]*(c) + v[3]*(d)) +/** Cross product of two 3-element vectors */ #define CROSS3(n, u, v) \ do { \ (n)[0] = (u)[1]*(v)[2] - (u)[2]*(v)[1]; \ @@ -585,5 +650,7 @@ do { \ #define LEN_SQUARED_2FV( V ) ((V)[0]*(V)[0]+(V)[1]*(V)[1]) +/*@}*/ + #endif |