Changeset 3597 for trunk/src/opengl/mesa/macros.h
- Timestamp:
- May 23, 2000, 10:35:01 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/opengl/mesa/macros.h
r2938 r3597 1 /* $Id: macros.h,v 1. 1 2000-02-29 00:48:33 sandervlExp $ */1 /* $Id: macros.h,v 1.2 2000-05-23 20:34:52 jeroen Exp $ */ 2 2 3 3 /* 4 4 * Mesa 3-D graphics library 5 * Version: 3. 15 * Version: 3.3 6 6 * 7 7 * Copyright (C) 1999 Brian Paul All Rights Reserved. … … 25 25 */ 26 26 27 28 29 30 31 27 /* 32 28 * A collection of useful macros. … … 37 33 #define MACROS_H 38 34 39 #ifndef XFree86Server 40 #include <assert.h> 41 #include <math.h> 42 #include <string.h> 43 #else 44 #include <GL/glx_ansic.h> 45 #endif 46 47 48 #ifdef DEBUG 35 #if defined(DEBUG) 49 36 # define ASSERT(X) assert(X) 37 #define ABORT() abort() 38 #define EXIT(rc) exit(rc) 50 39 #else 51 40 # define ASSERT(X) 41 #define ABORT() abort() 42 #define EXIT(rc) exit(rc) 43 #endif 44 45 #if defined(__WIN32OS2__) 46 #ifdef DEBUG 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); } 57 #else 58 #define ASSERT(X) 59 #define ABORT() abort() 60 #define EXIT(rc) exit(rc) 61 #endif 52 62 #endif 53 63 … … 62 72 63 73 74 /* Limits: */ 75 #define MAX_GLUSHORT 0xffff 76 #define MAX_GLUINT 0xffffffff 77 78 79 /* Some compilers don't like some of Mesa's const usage */ 80 #ifdef NO_CONST 81 # define CONST 82 #else 83 # define CONST const 84 #endif 85 86 87 /* Pi */ 88 #ifndef M_PI 89 #define M_PI (3.1415926) 90 #endif 91 92 93 /* Degrees to radians conversion: */ 94 #define DEG2RAD (M_PI/180.0) 95 96 97 #ifndef NULL 98 #define NULL 0 99 #endif 100 101 102 103 /* 104 * Bitmask helpers 105 */ 106 #define SET_BITS(WORD, BITS) (WORD) |= (BITS) 107 #define CLEAR_BITS(WORD, BITS) (WORD) &= ~(BITS) 108 #define TEST_BITS(WORD, BITS) ((WORD) & (BITS)) 109 110 64 111 /* Stepping a GLfloat pointer by a byte stride 65 112 */ … … 69 116 70 117 71 /* Limits: */72 #define MAX_GLUSHORT 0xffff73 #define MAX_GLUINT 0xffffffff74 75 76 118 #define ZERO_2V( DST ) (DST)[0] = (DST)[1] = 0 77 119 #define ZERO_3V( DST ) (DST)[0] = (DST)[1] = (DST)[2] = 0 … … 81 123 /* Copy short vectors: */ 82 124 #define COPY_2V( DST, SRC ) \ 83 /*do*/{ \125 do { \ 84 126 (DST)[0] = (SRC)[0]; \ 85 127 (DST)[1] = (SRC)[1]; \ 86 } /* while (0)*/128 } while (0) 87 129 88 130 89 131 #define COPY_3V( DST, SRC ) \ 90 /*do */{ \132 do { \ 91 133 (DST)[0] = (SRC)[0]; \ 92 134 (DST)[1] = (SRC)[1]; \ 93 135 (DST)[2] = (SRC)[2]; \ 94 } /* while (0)*/136 } while (0) 95 137 96 138 #define COPY_4V( DST, SRC ) \ 97 /*do */{ \139 do { \ 98 140 (DST)[0] = (SRC)[0]; \ 99 141 (DST)[1] = (SRC)[1]; \ 100 142 (DST)[2] = (SRC)[2]; \ 101 143 (DST)[3] = (SRC)[3]; \ 102 } /* while (0)*/144 } while (0) 103 145 104 146 105 147 #define COPY_2FV( DST, SRC ) \ 106 /*do*/{ \148 do { \ 107 149 const GLfloat *_tmp = (SRC); \ 108 150 (DST)[0] = _tmp[0]; \ 109 151 (DST)[1] = _tmp[1]; \ 110 } /* while (0)*/152 } while (0) 111 153 112 154 113 155 #define COPY_3FV( DST, SRC ) \ 114 /*do*/{ \156 do { \ 115 157 const GLfloat *_tmp = (SRC); \ 116 158 (DST)[0] = _tmp[0]; \ 117 159 (DST)[1] = _tmp[1]; \ 118 160 (DST)[2] = _tmp[2]; \ 119 } /* while (0)*/161 } while (0) 120 162 121 163 #define COPY_4FV( DST, SRC ) \ 122 /*do*/{ \164 do { \ 123 165 const GLfloat *_tmp = (SRC); \ 124 166 (DST)[0] = _tmp[0]; \ … … 126 168 (DST)[2] = _tmp[2]; \ 127 169 (DST)[3] = _tmp[3]; \ 128 } /* while (0)*/170 } while (0) 129 171 130 172 131 173 132 174 #define COPY_SZ_4V(DST, SZ, SRC) \ 133 /*do */{ \175 do { \ 134 176 switch (SZ) { \ 135 177 case 4: (DST)[3] = (SRC)[3]; \ … … 138 180 case 1: (DST)[0] = (SRC)[0]; \ 139 181 } \ 140 } /* while(0)*/182 } while(0) 141 183 142 184 #define SUB_4V( DST, SRCA, SRCB ) \ 143 /*do */{ \185 do { \ 144 186 (DST)[0] = (SRCA)[0] - (SRCB)[0]; \ 145 187 (DST)[1] = (SRCA)[1] - (SRCB)[1]; \ 146 188 (DST)[2] = (SRCA)[2] - (SRCB)[2]; \ 147 189 (DST)[3] = (SRCA)[3] - (SRCB)[3]; \ 148 } /* while (0)*/190 } while (0) 149 191 150 192 #define ADD_4V( DST, SRCA, SRCB ) \ 151 /*do*/{ \193 do { \ 152 194 (DST)[0] = (SRCA)[0] + (SRCB)[0]; \ 153 195 (DST)[1] = (SRCA)[1] + (SRCB)[1]; \ 154 196 (DST)[2] = (SRCA)[2] + (SRCB)[2]; \ 155 197 (DST)[3] = (SRCA)[3] + (SRCB)[3]; \ 156 } /* while (0)*/198 } while (0) 157 199 158 200 #define SCALE_4V( DST, SRCA, SRCB ) \ 159 /*do*/{ \201 do { \ 160 202 (DST)[0] = (SRCA)[0] * (SRCB)[0]; \ 161 203 (DST)[1] = (SRCA)[1] * (SRCB)[1]; \ 162 204 (DST)[2] = (SRCA)[2] * (SRCB)[2]; \ 163 205 (DST)[3] = (SRCA)[3] * (SRCB)[3]; \ 164 } /* while (0)*/206 } while (0) 165 207 166 208 #define ACC_4V( DST, SRC ) \ 167 /*do*/{ \168 (DST)[0] += (SRC)[0]; 169 (DST)[1] += (SRC)[1]; 170 (DST)[2] += (SRC)[2]; 171 (DST)[3] += (SRC)[3]; 172 } /* while (0)*/209 do { \ 210 (DST)[0] += (SRC)[0]; \ 211 (DST)[1] += (SRC)[1]; \ 212 (DST)[2] += (SRC)[2]; \ 213 (DST)[3] += (SRC)[3]; \ 214 } while (0) 173 215 174 216 #define ACC_SCALE_4V( DST, SRCA, SRCB ) \ 175 /*do*/{ \176 (DST)[0] += (SRCA)[0] * (SRCB)[0]; 177 (DST)[1] += (SRCA)[1] * (SRCB)[1]; 178 (DST)[2] += (SRCA)[2] * (SRCB)[2]; 179 (DST)[3] += (SRCA)[3] * (SRCB)[3]; 180 } /* while (0)*/217 do { \ 218 (DST)[0] += (SRCA)[0] * (SRCB)[0]; \ 219 (DST)[1] += (SRCA)[1] * (SRCB)[1]; \ 220 (DST)[2] += (SRCA)[2] * (SRCB)[2]; \ 221 (DST)[3] += (SRCA)[3] * (SRCB)[3]; \ 222 } while (0) 181 223 182 224 #define ACC_SCALE_SCALAR_4V( DST, S, SRCB ) \ 183 /*do*/{ \184 (DST)[0] += S * (SRCB)[0]; 185 (DST)[1] += S * (SRCB)[1]; 186 (DST)[2] += S * (SRCB)[2]; 187 (DST)[3] += S * (SRCB)[3]; 188 } /* while (0)*/225 do { \ 226 (DST)[0] += S * (SRCB)[0]; \ 227 (DST)[1] += S * (SRCB)[1]; \ 228 (DST)[2] += S * (SRCB)[2]; \ 229 (DST)[3] += S * (SRCB)[3]; \ 230 } while (0) 189 231 190 232 #define SCALE_SCALAR_4V( DST, S, SRCB ) \ 191 /*do*/{ \233 do { \ 192 234 (DST)[0] = S * (SRCB)[0]; \ 193 235 (DST)[1] = S * (SRCB)[1]; \ 194 236 (DST)[2] = S * (SRCB)[2]; \ 195 237 (DST)[3] = S * (SRCB)[3]; \ 196 } /* while (0)*/238 } while (0) 197 239 198 240 199 241 #define SELF_SCALE_SCALAR_4V( DST, S ) \ 200 /*do*/{ \242 do { \ 201 243 (DST)[0] *= S; \ 202 244 (DST)[1] *= S; \ 203 245 (DST)[2] *= S; \ 204 246 (DST)[3] *= S; \ 205 } /* while (0)*/247 } while (0) 206 248 207 249 … … 210 252 */ 211 253 #define SUB_3V( DST, SRCA, SRCB ) \ 212 /*do*/{ \254 do { \ 213 255 (DST)[0] = (SRCA)[0] - (SRCB)[0]; \ 214 256 (DST)[1] = (SRCA)[1] - (SRCB)[1]; \ 215 257 (DST)[2] = (SRCA)[2] - (SRCB)[2]; \ 216 } /* while (0)*/258 } while (0) 217 259 218 260 #define ADD_3V( DST, SRCA, SRCB ) \ 219 /*do*/{ \261 do { \ 220 262 (DST)[0] = (SRCA)[0] + (SRCB)[0]; \ 221 263 (DST)[1] = (SRCA)[1] + (SRCB)[1]; \ 222 264 (DST)[2] = (SRCA)[2] + (SRCB)[2]; \ 223 } /* while (0)*/265 } while (0) 224 266 225 267 #define SCALE_3V( DST, SRCA, SRCB ) \ 226 /*do*/{ \268 do { \ 227 269 (DST)[0] = (SRCA)[0] * (SRCB)[0]; \ 228 270 (DST)[1] = (SRCA)[1] * (SRCB)[1]; \ 229 271 (DST)[2] = (SRCA)[2] * (SRCB)[2]; \ 230 } /* while (0)*/272 } while (0) 231 273 232 274 #define ACC_3V( DST, SRC ) \ 233 /*do*/{ \275 do { \ 234 276 (DST)[0] += (SRC)[0]; \ 235 277 (DST)[1] += (SRC)[1]; \ 236 278 (DST)[2] += (SRC)[2]; \ 237 } /* while (0)*/279 } while (0) 238 280 239 281 #define ACC_SCALE_3V( DST, SRCA, SRCB ) \ 240 /*do*/{ \282 do { \ 241 283 (DST)[0] += (SRCA)[0] * (SRCB)[0]; \ 242 284 (DST)[1] += (SRCA)[1] * (SRCB)[1]; \ 243 285 (DST)[2] += (SRCA)[2] * (SRCB)[2]; \ 244 } /* while (0)*/286 } while (0) 245 287 246 288 #define SCALE_SCALAR_3V( DST, S, SRCB ) \ 247 /*do*/{ \289 do { \ 248 290 (DST)[0] = S * (SRCB)[0]; \ 249 291 (DST)[1] = S * (SRCB)[1]; \ 250 292 (DST)[2] = S * (SRCB)[2]; \ 251 } /* while (0)*/293 } while (0) 252 294 253 295 #define ACC_SCALE_SCALAR_3V( DST, S, SRCB ) \ 254 /*do*/{ \296 do { \ 255 297 (DST)[0] += S * (SRCB)[0]; \ 256 298 (DST)[1] += S * (SRCB)[1]; \ 257 299 (DST)[2] += S * (SRCB)[2]; \ 258 } /* while (0)*/300 } while (0) 259 301 260 302 #define SELF_SCALE_SCALAR_3V( DST, S ) \ 261 /*do*/{ \303 do { \ 262 304 (DST)[0] *= S; \ 263 305 (DST)[1] *= S; \ 264 306 (DST)[2] *= S; \ 265 } /* while (0)*/307 } while (0) 266 308 267 309 #define ACC_SCALAR_3V( DST, S ) \ 268 /*do*/{ \310 do { \ 269 311 (DST)[0] += S; \ 270 312 (DST)[1] += S; \ 271 313 (DST)[2] += S; \ 272 } /* while (0)*/314 } while (0) 273 315 274 316 /* And also for 2-vectors 275 317 */ 276 318 #define SUB_2V( DST, SRCA, SRCB ) \ 277 /*do*/{ \319 do { \ 278 320 (DST)[0] = (SRCA)[0] - (SRCB)[0]; \ 279 321 (DST)[1] = (SRCA)[1] - (SRCB)[1]; \ 280 } /* while (0)*/322 } while (0) 281 323 282 324 #define ADD_2V( DST, SRCA, SRCB ) \ 283 /*do*/{ \325 do { \ 284 326 (DST)[0] = (SRCA)[0] + (SRCB)[0]; \ 285 327 (DST)[1] = (SRCA)[1] + (SRCB)[1]; \ 286 } /* while (0)*/328 } while (0) 287 329 288 330 #define SCALE_2V( DST, SRCA, SRCB ) \ 289 /*do*/{ \331 do { \ 290 332 (DST)[0] = (SRCA)[0] * (SRCB)[0]; \ 291 333 (DST)[1] = (SRCA)[1] * (SRCB)[1]; \ 292 } /* while (0)*/334 } while (0) 293 335 294 336 #define ACC_2V( DST, SRC ) \ 295 /*do*/{ \337 do { \ 296 338 (DST)[0] += (SRC)[0]; \ 297 339 (DST)[1] += (SRC)[1]; \ 298 } /* while (0)*/340 } while (0) 299 341 300 342 #define ACC_SCALE_2V( DST, SRCA, SRCB ) \ 301 /*do*/{ \343 do { \ 302 344 (DST)[0] += (SRCA)[0] * (SRCB)[0]; \ 303 345 (DST)[1] += (SRCA)[1] * (SRCB)[1]; \ 304 } /* while (0)*/346 } while (0) 305 347 306 348 #define SCALE_SCALAR_2V( DST, S, SRCB ) \ 307 /*do*/{ \349 do { \ 308 350 (DST)[0] = S * (SRCB)[0]; \ 309 351 (DST)[1] = S * (SRCB)[1]; \ 310 } /* while (0)*/352 } while (0) 311 353 312 354 #define ACC_SCALE_SCALAR_2V( DST, S, SRCB ) \ 313 /*do*/{ \355 do { \ 314 356 (DST)[0] += S * (SRCB)[0]; \ 315 357 (DST)[1] += S * (SRCB)[1]; \ 316 } /* while (0)*/358 } while (0) 317 359 318 360 #define SELF_SCALE_SCALAR_2V( DST, S ) \ 319 /*do*/{ \361 do { \ 320 362 (DST)[0] *= S; \ 321 363 (DST)[1] *= S; \ 322 } /* while (0)*/364 } while (0) 323 365 324 366 #define ACC_SCALAR_2V( DST, S ) \ 325 /*do*/{ \367 do { \ 326 368 (DST)[0] += S; \ 327 369 (DST)[1] += S; \ 328 } /* while (0)*/370 } while (0) 329 371 330 372 … … 334 376 */ 335 377 #define COPY_4UBV(DST, SRC) \ 336 /*do*/ {\378 do { \ 337 379 if (sizeof(GLuint)==4*sizeof(GLubyte)) { \ 338 380 *((GLuint*)(DST)) = *((GLuint*)(SRC)); \ … … 344 386 (DST)[3] = (SRC)[3]; \ 345 387 } \ 346 } /* while (0)*/388 } while (0) 347 389 348 390 349 391 /* Assign scalers to short vectors: */ 350 392 #define ASSIGN_2V( V, V0, V1 ) \ 351 /*do*/ { V[0] = V0; V[1] = V1; } //while(0)393 do { V[0] = V0; V[1] = V1; } while(0) 352 394 353 395 #define ASSIGN_3V( V, V0, V1, V2 ) \ 354 /*do*/ { V[0] = V0; V[1] = V1; V[2] = V2; } //while(0)396 do { V[0] = V0; V[1] = V1; V[2] = V2; } while(0) 355 397 356 398 #define ASSIGN_4V( V, V0, V1, V2, V3 ) \ 357 /*do*/{ \399 do { \ 358 400 V[0] = V0; \ 359 401 V[1] = V1; \ 360 402 V[2] = V2; \ 361 403 V[3] = V3; \ 362 } /* while(0)*/404 } while(0) 363 405 364 406 … … 421 463 * Integer / float conversion for colors, normals, etc. 422 464 */ 423 424 425 426 465 427 466 #define BYTE_TO_UBYTE(b) (b < 0 ? 0 : (GLubyte) b) … … 430 469 #define INT_TO_UBYTE(i) (i < 0 ? 0 : (GLubyte) (i >> 23)) 431 470 #define UINT_TO_UBYTE(i) (GLubyte) (i >> 24) 432 433 434 435 471 436 472 /* Convert GLubyte in [0,255] to GLfloat in [0.0,1.0] */ … … 480 516 481 517 482 483 /*484 * Memory allocation485 * XXX these should probably go into a new glmemory.h file.486 */487 #ifdef DEBUG488 extern void *gl_malloc(size_t bytes);489 extern void *gl_calloc(size_t bytes);490 extern void gl_free(void *ptr);491 #define MALLOC(BYTES) gl_malloc(BYTES)492 #define CALLOC(BYTES) gl_calloc(BYTES)493 #define MALLOC_STRUCT(T) (struct T *) gl_malloc(sizeof(struct T))494 #define CALLOC_STRUCT(T) (struct T *) gl_calloc(sizeof(struct T))495 #define FREE(PTR) gl_free(PTR)496 #else497 #define MALLOC(BYTES) (void *) malloc(BYTES)498 #define CALLOC(BYTES) (void *) calloc(1, BYTES)499 #define MALLOC_STRUCT(T) (struct T *) malloc(sizeof(struct T))500 #define CALLOC_STRUCT(T) (struct T *) calloc(1,sizeof(struct T))501 #define FREE(PTR) free(PTR)502 #endif503 504 505 /* Memory copy: */506 #ifdef SUNOS4507 #define MEMCPY( DST, SRC, BYTES) \508 memcpy( (char *) (DST), (char *) (SRC), (int) (BYTES) )509 #else510 #define MEMCPY( DST, SRC, BYTES) \511 memcpy( (void *) (DST), (void *) (SRC), (size_t) (BYTES) )512 #endif513 514 515 /* Memory set: */516 #ifdef SUNOS4517 #define MEMSET( DST, VAL, N ) \518 memset( (char *) (DST), (int) (VAL), (int) (N) )519 #else520 #define MEMSET( DST, VAL, N ) \521 memset( (void *) (DST), (int) (VAL), (size_t) (N) )522 #endif523 524 525 /* MACs and BeOS don't support static larger than 32kb, so... */526 #if defined(macintosh) && !defined(__MRC__)527 extern char *AGLAlloc(int size);528 extern void AGLFree(char* ptr);529 # define DEFARRAY(TYPE,NAME,SIZE) TYPE *NAME = (TYPE*)AGLAlloc(sizeof(TYPE)*(SIZE))530 # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE (*NAME)[SIZE2] = (TYPE(*)[SIZE2])AGLAlloc(sizeof(TYPE)*(SIZE1)*(SIZE2))531 # define CHECKARRAY(NAME,CMD) do {if (!(NAME)) {CMD;}} while (0)532 # define UNDEFARRAY(NAME) do {if ((NAME)) {AGLFree((char*)NAME);} }while (0)533 #elif defined(__BEOS__)534 # define DEFARRAY(TYPE,NAME,SIZE) TYPE *NAME = (TYPE*)malloc(sizeof(TYPE)*(SIZE))535 # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE (*NAME)[SIZE2] = (TYPE(*)[SIZE2])malloc(sizeof(TYPE)*(SIZE1)*(SIZE2))536 # define CHECKARRAY(NAME,CMD) do {if (!(NAME)) {CMD;}} while (0)537 # define UNDEFARRAY(NAME) do {if ((NAME)) {free((char*)NAME);} }while (0)538 #else539 # define DEFARRAY(TYPE,NAME,SIZE) TYPE NAME[SIZE]540 # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE NAME[SIZE1][SIZE2]541 # define CHECKARRAY(NAME,CMD) do {} while(0)542 # define UNDEFARRAY(NAME)543 #endif544 545 546 /* Some compilers don't like some of Mesa's const usage */547 #ifdef NO_CONST548 # define CONST549 #else550 # define CONST const551 #endif552 553 554 555 /* Pi */556 #ifndef M_PI557 #define M_PI (3.1415926)558 #endif559 560 561 /* Degrees to radians conversion: */562 #define DEG2RAD (M_PI/180.0)563 564 565 #ifndef NULL566 #define NULL 0567 #endif568 569 570 571 518 #endif /*MACROS_H*/
Note:
See TracChangeset
for help on using the changeset viewer.