[6098] | 1 | /* $Id: macros.h,v 1.3 2001-06-25 18:51:32 bird Exp $ */
|
---|
[2938] | 2 |
|
---|
| 3 | /*
|
---|
| 4 | * Mesa 3-D graphics library
|
---|
[3597] | 5 | * Version: 3.3
|
---|
[2938] | 6 | *
|
---|
| 7 | * Copyright (C) 1999 Brian Paul All Rights Reserved.
|
---|
| 8 | *
|
---|
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
| 10 | * copy of this software and associated documentation files (the "Software"),
|
---|
| 11 | * to deal in the Software without restriction, including without limitation
|
---|
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
| 13 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
| 14 | * Software is furnished to do so, subject to the following conditions:
|
---|
| 15 | *
|
---|
| 16 | * The above copyright notice and this permission notice shall be included
|
---|
| 17 | * in all copies or substantial portions of the Software.
|
---|
| 18 | *
|
---|
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
---|
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
| 22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
---|
| 23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
---|
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
---|
| 25 | */
|
---|
| 26 |
|
---|
| 27 | /*
|
---|
| 28 | * A collection of useful macros.
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | #ifndef MACROS_H
|
---|
| 33 | #define MACROS_H
|
---|
| 34 |
|
---|
[3597] | 35 | #if defined(DEBUG)
|
---|
| 36 | # define ASSERT(X) assert(X)
|
---|
| 37 | #define ABORT() abort()
|
---|
| 38 | #define EXIT(rc) exit(rc)
|
---|
[2938] | 39 | #else
|
---|
[3597] | 40 | # define ASSERT(X)
|
---|
| 41 | #define ABORT() abort()
|
---|
| 42 | #define EXIT(rc) exit(rc)
|
---|
[2938] | 43 | #endif
|
---|
| 44 |
|
---|
[3597] | 45 | #if defined(__WIN32OS2__)
|
---|
[2938] | 46 | #ifdef DEBUG
|
---|
[3597] | 47 | #undef ASSERT
|
---|
| 48 | #undef ABORT
|
---|
| 49 | #undef EXIT
|
---|
| 50 | #define ASSERT(X) if(!(X)) { char msg[200]; sprintf(msg,"Assertion failed at line %d in %s",__LINE__,__FILE__); \
|
---|
| 51 | MessageBox(0,msg,"Error",MB_OK); \
|
---|
| 52 | }
|
---|
| 53 | #define ABORT() {char msg[200]; sprintf(msg,"ABORT at line %d in %s",__FILE__,__LINE__); \
|
---|
| 54 | abort(); }
|
---|
| 55 | #define EXIT(rc) {char msg[200]; sprintf(msg,"EXIT at line %d in %s - rc %d",__FILE__,__LINE__,rc); \
|
---|
| 56 | exit(rc); }
|
---|
[2938] | 57 | #else
|
---|
[3597] | 58 | #define ASSERT(X)
|
---|
| 59 | #define ABORT() abort()
|
---|
| 60 | #define EXIT(rc) exit(rc)
|
---|
[2938] | 61 | #endif
|
---|
[3597] | 62 | #endif
|
---|
[2938] | 63 |
|
---|
| 64 |
|
---|
| 65 | #if defined(__GNUC__)
|
---|
| 66 | #define INLINE __inline__
|
---|
| 67 | #elif defined(__MSC__)
|
---|
| 68 | #define INLINE __inline
|
---|
| 69 | #else
|
---|
[6098] | 70 | #ifndef INLINE
|
---|
[2938] | 71 | #define INLINE
|
---|
| 72 | #endif
|
---|
[6098] | 73 | #endif
|
---|
[2938] | 74 |
|
---|
| 75 |
|
---|
[3597] | 76 | /* Limits: */
|
---|
| 77 | #define MAX_GLUSHORT 0xffff
|
---|
| 78 | #define MAX_GLUINT 0xffffffff
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 | /* Some compilers don't like some of Mesa's const usage */
|
---|
| 82 | #ifdef NO_CONST
|
---|
| 83 | # define CONST
|
---|
| 84 | #else
|
---|
| 85 | # define CONST const
|
---|
| 86 | #endif
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | /* Pi */
|
---|
| 90 | #ifndef M_PI
|
---|
| 91 | #define M_PI (3.1415926)
|
---|
| 92 | #endif
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | /* Degrees to radians conversion: */
|
---|
| 96 | #define DEG2RAD (M_PI/180.0)
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 | #ifndef NULL
|
---|
| 100 | #define NULL 0
|
---|
| 101 | #endif
|
---|
| 102 |
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 | /*
|
---|
| 106 | * Bitmask helpers
|
---|
| 107 | */
|
---|
| 108 | #define SET_BITS(WORD, BITS) (WORD) |= (BITS)
|
---|
| 109 | #define CLEAR_BITS(WORD, BITS) (WORD) &= ~(BITS)
|
---|
| 110 | #define TEST_BITS(WORD, BITS) ((WORD) & (BITS))
|
---|
| 111 |
|
---|
| 112 |
|
---|
[2938] | 113 | /* Stepping a GLfloat pointer by a byte stride
|
---|
| 114 | */
|
---|
| 115 | #define STRIDE_F(p, i) (p = (GLfloat *)((GLubyte *)p + i))
|
---|
| 116 | #define STRIDE_UI(p, i) (p = (GLuint *)((GLubyte *)p + i))
|
---|
| 117 | #define STRIDE_T(p, t, i) (p = (t *)((GLubyte *)p + i))
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 | #define ZERO_2V( DST ) (DST)[0] = (DST)[1] = 0
|
---|
| 121 | #define ZERO_3V( DST ) (DST)[0] = (DST)[1] = (DST)[2] = 0
|
---|
| 122 | #define ZERO_4V( DST ) (DST)[0] = (DST)[1] = (DST)[2] = (DST)[3] = 0
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | /* Copy short vectors: */
|
---|
| 126 | #define COPY_2V( DST, SRC ) \
|
---|
[3597] | 127 | do { \
|
---|
[2938] | 128 | (DST)[0] = (SRC)[0]; \
|
---|
| 129 | (DST)[1] = (SRC)[1]; \
|
---|
[3597] | 130 | } while (0)
|
---|
[2938] | 131 |
|
---|
| 132 |
|
---|
| 133 | #define COPY_3V( DST, SRC ) \
|
---|
[3597] | 134 | do { \
|
---|
[2938] | 135 | (DST)[0] = (SRC)[0]; \
|
---|
| 136 | (DST)[1] = (SRC)[1]; \
|
---|
| 137 | (DST)[2] = (SRC)[2]; \
|
---|
[3597] | 138 | } while (0)
|
---|
[2938] | 139 |
|
---|
| 140 | #define COPY_4V( DST, SRC ) \
|
---|
[3597] | 141 | do { \
|
---|
[2938] | 142 | (DST)[0] = (SRC)[0]; \
|
---|
| 143 | (DST)[1] = (SRC)[1]; \
|
---|
| 144 | (DST)[2] = (SRC)[2]; \
|
---|
| 145 | (DST)[3] = (SRC)[3]; \
|
---|
[3597] | 146 | } while (0)
|
---|
[2938] | 147 |
|
---|
| 148 |
|
---|
| 149 | #define COPY_2FV( DST, SRC ) \
|
---|
[3597] | 150 | do { \
|
---|
[2938] | 151 | const GLfloat *_tmp = (SRC); \
|
---|
| 152 | (DST)[0] = _tmp[0]; \
|
---|
| 153 | (DST)[1] = _tmp[1]; \
|
---|
[3597] | 154 | } while (0)
|
---|
[2938] | 155 |
|
---|
| 156 |
|
---|
| 157 | #define COPY_3FV( DST, SRC ) \
|
---|
[3597] | 158 | do { \
|
---|
[2938] | 159 | const GLfloat *_tmp = (SRC); \
|
---|
| 160 | (DST)[0] = _tmp[0]; \
|
---|
| 161 | (DST)[1] = _tmp[1]; \
|
---|
| 162 | (DST)[2] = _tmp[2]; \
|
---|
[3597] | 163 | } while (0)
|
---|
[2938] | 164 |
|
---|
| 165 | #define COPY_4FV( DST, SRC ) \
|
---|
[3597] | 166 | do { \
|
---|
[2938] | 167 | const GLfloat *_tmp = (SRC); \
|
---|
| 168 | (DST)[0] = _tmp[0]; \
|
---|
| 169 | (DST)[1] = _tmp[1]; \
|
---|
| 170 | (DST)[2] = _tmp[2]; \
|
---|
| 171 | (DST)[3] = _tmp[3]; \
|
---|
[3597] | 172 | } while (0)
|
---|
[2938] | 173 |
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 | #define COPY_SZ_4V(DST, SZ, SRC) \
|
---|
[3597] | 177 | do { \
|
---|
[2938] | 178 | switch (SZ) { \
|
---|
| 179 | case 4: (DST)[3] = (SRC)[3]; \
|
---|
| 180 | case 3: (DST)[2] = (SRC)[2]; \
|
---|
| 181 | case 2: (DST)[1] = (SRC)[1]; \
|
---|
| 182 | case 1: (DST)[0] = (SRC)[0]; \
|
---|
| 183 | } \
|
---|
[3597] | 184 | } while(0)
|
---|
[2938] | 185 |
|
---|
| 186 | #define SUB_4V( DST, SRCA, SRCB ) \
|
---|
[3597] | 187 | do { \
|
---|
[2938] | 188 | (DST)[0] = (SRCA)[0] - (SRCB)[0]; \
|
---|
| 189 | (DST)[1] = (SRCA)[1] - (SRCB)[1]; \
|
---|
| 190 | (DST)[2] = (SRCA)[2] - (SRCB)[2]; \
|
---|
| 191 | (DST)[3] = (SRCA)[3] - (SRCB)[3]; \
|
---|
[3597] | 192 | } while (0)
|
---|
[2938] | 193 |
|
---|
| 194 | #define ADD_4V( DST, SRCA, SRCB ) \
|
---|
[3597] | 195 | do { \
|
---|
[2938] | 196 | (DST)[0] = (SRCA)[0] + (SRCB)[0]; \
|
---|
| 197 | (DST)[1] = (SRCA)[1] + (SRCB)[1]; \
|
---|
| 198 | (DST)[2] = (SRCA)[2] + (SRCB)[2]; \
|
---|
| 199 | (DST)[3] = (SRCA)[3] + (SRCB)[3]; \
|
---|
[3597] | 200 | } while (0)
|
---|
[2938] | 201 |
|
---|
| 202 | #define SCALE_4V( DST, SRCA, SRCB ) \
|
---|
[3597] | 203 | do { \
|
---|
[2938] | 204 | (DST)[0] = (SRCA)[0] * (SRCB)[0]; \
|
---|
| 205 | (DST)[1] = (SRCA)[1] * (SRCB)[1]; \
|
---|
| 206 | (DST)[2] = (SRCA)[2] * (SRCB)[2]; \
|
---|
| 207 | (DST)[3] = (SRCA)[3] * (SRCB)[3]; \
|
---|
[3597] | 208 | } while (0)
|
---|
[2938] | 209 |
|
---|
| 210 | #define ACC_4V( DST, SRC ) \
|
---|
[3597] | 211 | do { \
|
---|
| 212 | (DST)[0] += (SRC)[0]; \
|
---|
| 213 | (DST)[1] += (SRC)[1]; \
|
---|
| 214 | (DST)[2] += (SRC)[2]; \
|
---|
| 215 | (DST)[3] += (SRC)[3]; \
|
---|
| 216 | } while (0)
|
---|
[2938] | 217 |
|
---|
| 218 | #define ACC_SCALE_4V( DST, SRCA, SRCB ) \
|
---|
[3597] | 219 | do { \
|
---|
| 220 | (DST)[0] += (SRCA)[0] * (SRCB)[0]; \
|
---|
| 221 | (DST)[1] += (SRCA)[1] * (SRCB)[1]; \
|
---|
| 222 | (DST)[2] += (SRCA)[2] * (SRCB)[2]; \
|
---|
| 223 | (DST)[3] += (SRCA)[3] * (SRCB)[3]; \
|
---|
| 224 | } while (0)
|
---|
[2938] | 225 |
|
---|
| 226 | #define ACC_SCALE_SCALAR_4V( DST, S, SRCB ) \
|
---|
[3597] | 227 | do { \
|
---|
| 228 | (DST)[0] += S * (SRCB)[0]; \
|
---|
| 229 | (DST)[1] += S * (SRCB)[1]; \
|
---|
| 230 | (DST)[2] += S * (SRCB)[2]; \
|
---|
| 231 | (DST)[3] += S * (SRCB)[3]; \
|
---|
| 232 | } while (0)
|
---|
[2938] | 233 |
|
---|
| 234 | #define SCALE_SCALAR_4V( DST, S, SRCB ) \
|
---|
[3597] | 235 | do { \
|
---|
[2938] | 236 | (DST)[0] = S * (SRCB)[0]; \
|
---|
| 237 | (DST)[1] = S * (SRCB)[1]; \
|
---|
| 238 | (DST)[2] = S * (SRCB)[2]; \
|
---|
| 239 | (DST)[3] = S * (SRCB)[3]; \
|
---|
[3597] | 240 | } while (0)
|
---|
[2938] | 241 |
|
---|
| 242 |
|
---|
| 243 | #define SELF_SCALE_SCALAR_4V( DST, S ) \
|
---|
[3597] | 244 | do { \
|
---|
[2938] | 245 | (DST)[0] *= S; \
|
---|
| 246 | (DST)[1] *= S; \
|
---|
| 247 | (DST)[2] *= S; \
|
---|
| 248 | (DST)[3] *= S; \
|
---|
[3597] | 249 | } while (0)
|
---|
[2938] | 250 |
|
---|
| 251 |
|
---|
| 252 | /*
|
---|
| 253 | * Similarly for 3-vectors.
|
---|
| 254 | */
|
---|
| 255 | #define SUB_3V( DST, SRCA, SRCB ) \
|
---|
[3597] | 256 | do { \
|
---|
[2938] | 257 | (DST)[0] = (SRCA)[0] - (SRCB)[0]; \
|
---|
| 258 | (DST)[1] = (SRCA)[1] - (SRCB)[1]; \
|
---|
| 259 | (DST)[2] = (SRCA)[2] - (SRCB)[2]; \
|
---|
[3597] | 260 | } while (0)
|
---|
[2938] | 261 |
|
---|
| 262 | #define ADD_3V( DST, SRCA, SRCB ) \
|
---|
[3597] | 263 | do { \
|
---|
[2938] | 264 | (DST)[0] = (SRCA)[0] + (SRCB)[0]; \
|
---|
| 265 | (DST)[1] = (SRCA)[1] + (SRCB)[1]; \
|
---|
| 266 | (DST)[2] = (SRCA)[2] + (SRCB)[2]; \
|
---|
[3597] | 267 | } while (0)
|
---|
[2938] | 268 |
|
---|
| 269 | #define SCALE_3V( DST, SRCA, SRCB ) \
|
---|
[3597] | 270 | do { \
|
---|
[2938] | 271 | (DST)[0] = (SRCA)[0] * (SRCB)[0]; \
|
---|
| 272 | (DST)[1] = (SRCA)[1] * (SRCB)[1]; \
|
---|
| 273 | (DST)[2] = (SRCA)[2] * (SRCB)[2]; \
|
---|
[3597] | 274 | } while (0)
|
---|
[2938] | 275 |
|
---|
| 276 | #define ACC_3V( DST, SRC ) \
|
---|
[3597] | 277 | do { \
|
---|
[2938] | 278 | (DST)[0] += (SRC)[0]; \
|
---|
| 279 | (DST)[1] += (SRC)[1]; \
|
---|
| 280 | (DST)[2] += (SRC)[2]; \
|
---|
[3597] | 281 | } while (0)
|
---|
[2938] | 282 |
|
---|
| 283 | #define ACC_SCALE_3V( DST, SRCA, SRCB ) \
|
---|
[3597] | 284 | do { \
|
---|
[2938] | 285 | (DST)[0] += (SRCA)[0] * (SRCB)[0]; \
|
---|
| 286 | (DST)[1] += (SRCA)[1] * (SRCB)[1]; \
|
---|
| 287 | (DST)[2] += (SRCA)[2] * (SRCB)[2]; \
|
---|
[3597] | 288 | } while (0)
|
---|
[2938] | 289 |
|
---|
| 290 | #define SCALE_SCALAR_3V( DST, S, SRCB ) \
|
---|
[3597] | 291 | do { \
|
---|
[2938] | 292 | (DST)[0] = S * (SRCB)[0]; \
|
---|
| 293 | (DST)[1] = S * (SRCB)[1]; \
|
---|
| 294 | (DST)[2] = S * (SRCB)[2]; \
|
---|
[3597] | 295 | } while (0)
|
---|
[2938] | 296 |
|
---|
| 297 | #define ACC_SCALE_SCALAR_3V( DST, S, SRCB ) \
|
---|
[3597] | 298 | do { \
|
---|
[2938] | 299 | (DST)[0] += S * (SRCB)[0]; \
|
---|
| 300 | (DST)[1] += S * (SRCB)[1]; \
|
---|
| 301 | (DST)[2] += S * (SRCB)[2]; \
|
---|
[3597] | 302 | } while (0)
|
---|
[2938] | 303 |
|
---|
| 304 | #define SELF_SCALE_SCALAR_3V( DST, S ) \
|
---|
[3597] | 305 | do { \
|
---|
[2938] | 306 | (DST)[0] *= S; \
|
---|
| 307 | (DST)[1] *= S; \
|
---|
| 308 | (DST)[2] *= S; \
|
---|
[3597] | 309 | } while (0)
|
---|
[2938] | 310 |
|
---|
| 311 | #define ACC_SCALAR_3V( DST, S ) \
|
---|
[3597] | 312 | do { \
|
---|
[2938] | 313 | (DST)[0] += S; \
|
---|
| 314 | (DST)[1] += S; \
|
---|
| 315 | (DST)[2] += S; \
|
---|
[3597] | 316 | } while (0)
|
---|
[2938] | 317 |
|
---|
| 318 | /* And also for 2-vectors
|
---|
| 319 | */
|
---|
| 320 | #define SUB_2V( DST, SRCA, SRCB ) \
|
---|
[3597] | 321 | do { \
|
---|
[2938] | 322 | (DST)[0] = (SRCA)[0] - (SRCB)[0]; \
|
---|
| 323 | (DST)[1] = (SRCA)[1] - (SRCB)[1]; \
|
---|
[3597] | 324 | } while (0)
|
---|
[2938] | 325 |
|
---|
| 326 | #define ADD_2V( DST, SRCA, SRCB ) \
|
---|
[3597] | 327 | do { \
|
---|
[2938] | 328 | (DST)[0] = (SRCA)[0] + (SRCB)[0]; \
|
---|
| 329 | (DST)[1] = (SRCA)[1] + (SRCB)[1]; \
|
---|
[3597] | 330 | } while (0)
|
---|
[2938] | 331 |
|
---|
| 332 | #define SCALE_2V( DST, SRCA, SRCB ) \
|
---|
[3597] | 333 | do { \
|
---|
[2938] | 334 | (DST)[0] = (SRCA)[0] * (SRCB)[0]; \
|
---|
| 335 | (DST)[1] = (SRCA)[1] * (SRCB)[1]; \
|
---|
[3597] | 336 | } while (0)
|
---|
[2938] | 337 |
|
---|
| 338 | #define ACC_2V( DST, SRC ) \
|
---|
[3597] | 339 | do { \
|
---|
[2938] | 340 | (DST)[0] += (SRC)[0]; \
|
---|
| 341 | (DST)[1] += (SRC)[1]; \
|
---|
[3597] | 342 | } while (0)
|
---|
[2938] | 343 |
|
---|
| 344 | #define ACC_SCALE_2V( DST, SRCA, SRCB ) \
|
---|
[3597] | 345 | do { \
|
---|
[2938] | 346 | (DST)[0] += (SRCA)[0] * (SRCB)[0]; \
|
---|
| 347 | (DST)[1] += (SRCA)[1] * (SRCB)[1]; \
|
---|
[3597] | 348 | } while (0)
|
---|
[2938] | 349 |
|
---|
| 350 | #define SCALE_SCALAR_2V( DST, S, SRCB ) \
|
---|
[3597] | 351 | do { \
|
---|
[2938] | 352 | (DST)[0] = S * (SRCB)[0]; \
|
---|
| 353 | (DST)[1] = S * (SRCB)[1]; \
|
---|
[3597] | 354 | } while (0)
|
---|
[2938] | 355 |
|
---|
| 356 | #define ACC_SCALE_SCALAR_2V( DST, S, SRCB ) \
|
---|
[3597] | 357 | do { \
|
---|
[2938] | 358 | (DST)[0] += S * (SRCB)[0]; \
|
---|
| 359 | (DST)[1] += S * (SRCB)[1]; \
|
---|
[3597] | 360 | } while (0)
|
---|
[2938] | 361 |
|
---|
| 362 | #define SELF_SCALE_SCALAR_2V( DST, S ) \
|
---|
[3597] | 363 | do { \
|
---|
[2938] | 364 | (DST)[0] *= S; \
|
---|
| 365 | (DST)[1] *= S; \
|
---|
[3597] | 366 | } while (0)
|
---|
[2938] | 367 |
|
---|
| 368 | #define ACC_SCALAR_2V( DST, S ) \
|
---|
[3597] | 369 | do { \
|
---|
[2938] | 370 | (DST)[0] += S; \
|
---|
| 371 | (DST)[1] += S; \
|
---|
[3597] | 372 | } while (0)
|
---|
[2938] | 373 |
|
---|
| 374 |
|
---|
| 375 |
|
---|
| 376 | /*
|
---|
| 377 | * Copy a vector of 4 GLubytes from SRC to DST.
|
---|
| 378 | */
|
---|
| 379 | #define COPY_4UBV(DST, SRC) \
|
---|
[3597] | 380 | do { \
|
---|
[2938] | 381 | if (sizeof(GLuint)==4*sizeof(GLubyte)) { \
|
---|
| 382 | *((GLuint*)(DST)) = *((GLuint*)(SRC)); \
|
---|
| 383 | } \
|
---|
| 384 | else { \
|
---|
| 385 | (DST)[0] = (SRC)[0]; \
|
---|
| 386 | (DST)[1] = (SRC)[1]; \
|
---|
| 387 | (DST)[2] = (SRC)[2]; \
|
---|
| 388 | (DST)[3] = (SRC)[3]; \
|
---|
| 389 | } \
|
---|
[3597] | 390 | } while (0)
|
---|
[2938] | 391 |
|
---|
| 392 |
|
---|
| 393 | /* Assign scalers to short vectors: */
|
---|
| 394 | #define ASSIGN_2V( V, V0, V1 ) \
|
---|
[3597] | 395 | do { V[0] = V0; V[1] = V1; } while(0)
|
---|
[2938] | 396 |
|
---|
| 397 | #define ASSIGN_3V( V, V0, V1, V2 ) \
|
---|
[3597] | 398 | do { V[0] = V0; V[1] = V1; V[2] = V2; } while(0)
|
---|
[2938] | 399 |
|
---|
| 400 | #define ASSIGN_4V( V, V0, V1, V2, V3 ) \
|
---|
[3597] | 401 | do { \
|
---|
[2938] | 402 | V[0] = V0; \
|
---|
| 403 | V[1] = V1; \
|
---|
| 404 | V[2] = V2; \
|
---|
| 405 | V[3] = V3; \
|
---|
[3597] | 406 | } while(0)
|
---|
[2938] | 407 |
|
---|
| 408 |
|
---|
| 409 |
|
---|
| 410 |
|
---|
| 411 | /* Absolute value (for Int, Float, Double): */
|
---|
| 412 | #define ABSI(X) ((X) < 0 ? -(X) : (X))
|
---|
| 413 | #define ABSF(X) ((X) < 0.0F ? -(X) : (X))
|
---|
| 414 | #define ABSD(X) ((X) < 0.0 ? -(X) : (X))
|
---|
| 415 |
|
---|
| 416 |
|
---|
| 417 |
|
---|
| 418 | /* Round a floating-point value to the nearest integer: */
|
---|
| 419 | #define ROUNDF(X) ( (X)<0.0F ? ((GLint) ((X)-0.5F)) : ((GLint) ((X)+0.5F)) )
|
---|
| 420 |
|
---|
| 421 |
|
---|
| 422 | /* Compute ceiling of integer quotient of A divided by B: */
|
---|
| 423 | #define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
|
---|
| 424 |
|
---|
| 425 |
|
---|
| 426 | /* Clamp X to [MIN,MAX]: */
|
---|
| 427 | #define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) )
|
---|
| 428 |
|
---|
| 429 | /* Assign X to CLAMP(X, MIN, MAX) */
|
---|
| 430 | #define CLAMP_SELF(x, mn, mx) \
|
---|
| 431 | ( (x)<(mn) ? ((x) = (mn)) : ((x)>(mx) ? ((x)=(mx)) : (x)) )
|
---|
| 432 |
|
---|
| 433 |
|
---|
| 434 |
|
---|
| 435 | /* Min of two values: */
|
---|
| 436 | #define MIN2( A, B ) ( (A)<(B) ? (A) : (B) )
|
---|
| 437 |
|
---|
| 438 |
|
---|
| 439 | /* MAX of two values: */
|
---|
| 440 | #define MAX2( A, B ) ( (A)>(B) ? (A) : (B) )
|
---|
| 441 |
|
---|
| 442 | /* Dot product of two 2-element vectors */
|
---|
| 443 | #define DOT2( a, b ) ( (a)[0]*(b)[0] + (a)[1]*(b)[1] )
|
---|
| 444 |
|
---|
| 445 | /* Dot product of two 3-element vectors */
|
---|
| 446 | #define DOT3( a, b ) ( (a)[0]*(b)[0] + (a)[1]*(b)[1] + (a)[2]*(b)[2] )
|
---|
| 447 |
|
---|
| 448 |
|
---|
| 449 | /* Dot product of two 4-element vectors */
|
---|
| 450 | #define DOT4( a, b ) ( (a)[0]*(b)[0] + (a)[1]*(b)[1] + \
|
---|
| 451 | (a)[2]*(b)[2] + (a)[3]*(b)[3] )
|
---|
| 452 |
|
---|
| 453 | #define DOT4V(v,a,b,c,d) (v[0]*a + v[1]*b + v[2]*c + v[3]*d)
|
---|
| 454 |
|
---|
| 455 |
|
---|
| 456 | #define CROSS3(n, u, v) \
|
---|
| 457 | do { \
|
---|
| 458 | (n)[0] = (u)[1]*(v)[2] - (u)[2]*(v)[1]; \
|
---|
| 459 | (n)[1] = (u)[2]*(v)[0] - (u)[0]*(v)[2]; \
|
---|
| 460 | (n)[2] = (u)[0]*(v)[1] - (u)[1]*(v)[0]; \
|
---|
| 461 | } while (0)
|
---|
| 462 |
|
---|
| 463 |
|
---|
| 464 | /*
|
---|
| 465 | * Integer / float conversion for colors, normals, etc.
|
---|
| 466 | */
|
---|
| 467 |
|
---|
| 468 | #define BYTE_TO_UBYTE(b) (b < 0 ? 0 : (GLubyte) b)
|
---|
| 469 | #define SHORT_TO_UBYTE(s) (s < 0 ? 0 : (GLubyte) (s >> 7))
|
---|
| 470 | #define USHORT_TO_UBYTE(s) (GLubyte) (s >> 8)
|
---|
| 471 | #define INT_TO_UBYTE(i) (i < 0 ? 0 : (GLubyte) (i >> 23))
|
---|
| 472 | #define UINT_TO_UBYTE(i) (GLubyte) (i >> 24)
|
---|
| 473 |
|
---|
| 474 | /* Convert GLubyte in [0,255] to GLfloat in [0.0,1.0] */
|
---|
| 475 | #define UBYTE_TO_FLOAT(B) ((GLfloat) (B) * (1.0F / 255.0F))
|
---|
| 476 |
|
---|
| 477 | /* Convert GLfloat in [0.0,1.0] to GLubyte in [0,255] */
|
---|
| 478 | #define FLOAT_TO_UBYTE(X) ((GLubyte) (GLint) (((X)) * 255.0F))
|
---|
| 479 |
|
---|
| 480 |
|
---|
| 481 | /* Convert GLbyte in [-128,127] to GLfloat in [-1.0,1.0] */
|
---|
| 482 | #define BYTE_TO_FLOAT(B) ((2.0F * (B) + 1.0F) * (1.0F/255.0F))
|
---|
| 483 |
|
---|
| 484 | /* Convert GLfloat in [-1.0,1.0] to GLbyte in [-128,127] */
|
---|
| 485 | #define FLOAT_TO_BYTE(X) ( (((GLint) (255.0F * (X))) - 1) / 2 )
|
---|
| 486 |
|
---|
| 487 |
|
---|
| 488 | /* Convert GLushort in [0,65536] to GLfloat in [0.0,1.0] */
|
---|
| 489 | #define USHORT_TO_FLOAT(S) ((GLfloat) (S) * (1.0F / 65535.0F))
|
---|
| 490 |
|
---|
| 491 | /* Convert GLfloat in [0.0,1.0] to GLushort in [0,65536] */
|
---|
| 492 | #define FLOAT_TO_USHORT(X) ((GLushort) (GLint) ((X) * 65535.0F))
|
---|
| 493 |
|
---|
| 494 |
|
---|
| 495 | /* Convert GLshort in [-32768,32767] to GLfloat in [-1.0,1.0] */
|
---|
| 496 | #define SHORT_TO_FLOAT(S) ((2.0F * (S) + 1.0F) * (1.0F/65535.0F))
|
---|
| 497 |
|
---|
| 498 | /* Convert GLfloat in [0.0,1.0] to GLshort in [-32768,32767] */
|
---|
| 499 | #define FLOAT_TO_SHORT(X) ( (((GLint) (65535.0F * (X))) - 1) / 2 )
|
---|
| 500 |
|
---|
| 501 |
|
---|
| 502 | /* Convert GLuint in [0,4294967295] to GLfloat in [0.0,1.0] */
|
---|
| 503 | #define UINT_TO_FLOAT(U) ((GLfloat) (U) * (1.0F / 4294967295.0F))
|
---|
| 504 |
|
---|
| 505 | /* Convert GLfloat in [0.0,1.0] to GLuint in [0,4294967295] */
|
---|
| 506 | #define FLOAT_TO_UINT(X) ((GLuint) ((X) * 4294967295.0))
|
---|
| 507 |
|
---|
| 508 |
|
---|
| 509 | /* Convert GLint in [-2147483648,2147483647] to GLfloat in [-1.0,1.0] */
|
---|
| 510 | #define INT_TO_FLOAT(I) ((2.0F * (I) + 1.0F) * (1.0F/4294967294.0F))
|
---|
| 511 |
|
---|
| 512 | /* Convert GLfloat in [-1.0,1.0] to GLint in [-2147483648,2147483647] */
|
---|
| 513 | /* causes overflow:
|
---|
| 514 | #define FLOAT_TO_INT(X) ( (((GLint) (4294967294.0F * (X))) - 1) / 2 )
|
---|
| 515 | */
|
---|
| 516 | /* a close approximation: */
|
---|
| 517 | #define FLOAT_TO_INT(X) ( (GLint) (2147483647.0 * (X)) )
|
---|
| 518 |
|
---|
| 519 |
|
---|
| 520 | #endif /*MACROS_H*/
|
---|