Ignore:
Timestamp:
May 23, 2000, 10:35:01 PM (25 years ago)
Author:
jeroen
Message:

* empty log message *

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 sandervl Exp $ */
     1/* $Id: macros.h,v 1.2 2000-05-23 20:34:52 jeroen Exp $ */
    22
    33/*
    44 * Mesa 3-D graphics library
    5  * Version:  3.1
     5 * Version:  3.3
    66 *
    77 * Copyright (C) 1999  Brian Paul   All Rights Reserved.
     
    2525 */
    2626
    27 
    28 
    29 
    30 
    3127/*
    3228 * A collection of useful macros.
     
    3733#define MACROS_H
    3834
    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)
    4936#  define ASSERT(X)   assert(X)
     37#define ABORT()       abort()
     38#define EXIT(rc)      exit(rc)
    5039#else
    5140#  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__); \
     51MessageBox(0,msg,"Error",MB_OK); \
     52}
     53#define ABORT() {char msg[200]; sprintf(msg,"ABORT at line %d in %s",__FILE__,__LINE__); \
     54abort(); }
     55#define EXIT(rc) {char msg[200]; sprintf(msg,"EXIT at line %d in %s - rc %d",__FILE__,__LINE__,rc); \
     56exit(rc); }
     57#else
     58#define ASSERT(X)
     59#define ABORT()       abort()
     60#define EXIT(rc)      exit(rc)
     61#endif
    5262#endif
    5363
     
    6272
    6373
     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
    64111/* Stepping a GLfloat pointer by a byte stride
    65112 */
     
    69116
    70117
    71 /* Limits: */
    72 #define MAX_GLUSHORT    0xffff
    73 #define MAX_GLUINT      0xffffffff
    74 
    75 
    76118#define ZERO_2V( DST )  (DST)[0] = (DST)[1] = 0
    77119#define ZERO_3V( DST )  (DST)[0] = (DST)[1] = (DST)[2] = 0
     
    81123/* Copy short vectors: */
    82124#define COPY_2V( DST, SRC )                     \
    83 /*do*/ {                                            \
     125do {                                            \
    84126   (DST)[0] = (SRC)[0];                         \
    85127   (DST)[1] = (SRC)[1];                         \
    86 }                                                              /* while (0)*/
     128} while (0)
    87129
    88130
    89131#define COPY_3V( DST, SRC )                     \
    90 /*do */{                                            \
     132do {                                            \
    91133   (DST)[0] = (SRC)[0];                         \
    92134   (DST)[1] = (SRC)[1];                         \
    93135   (DST)[2] = (SRC)[2];                         \
    94 }                                                              /* while (0)*/
     136} while (0)
    95137
    96138#define COPY_4V( DST, SRC )                     \
    97 /*do */{                                            \
     139do {                                            \
    98140   (DST)[0] = (SRC)[0];                         \
    99141   (DST)[1] = (SRC)[1];                         \
    100142   (DST)[2] = (SRC)[2];                         \
    101143   (DST)[3] = (SRC)[3];                         \
    102 }                                                              /* while (0)*/
     144} while (0)
    103145
    104146
    105147#define COPY_2FV( DST, SRC )                    \
    106 /*do*/ {                                            \
     148do {                                            \
    107149   const GLfloat *_tmp = (SRC);                 \
    108150   (DST)[0] = _tmp[0];                          \
    109151   (DST)[1] = _tmp[1];                          \
    110 }                                                              /* while (0)*/
     152} while (0)
    111153
    112154
    113155#define COPY_3FV( DST, SRC )                    \
    114 /*do*/ {                                            \
     156do {                                            \
    115157   const GLfloat *_tmp = (SRC);                 \
    116158   (DST)[0] = _tmp[0];                          \
    117159   (DST)[1] = _tmp[1];                          \
    118160   (DST)[2] = _tmp[2];                          \
    119 }                                                              /* while (0)*/
     161} while (0)
    120162
    121163#define COPY_4FV( DST, SRC )                    \
    122 /*do*/ {                                            \
     164do {                                            \
    123165   const GLfloat *_tmp = (SRC);                 \
    124166   (DST)[0] = _tmp[0];                          \
     
    126168   (DST)[2] = _tmp[2];                          \
    127169   (DST)[3] = _tmp[3];                          \
    128 }                                                              /* while (0)*/
     170} while (0)
    129171
    130172
    131173
    132174#define COPY_SZ_4V(DST, SZ, SRC)                \
    133 /*do */{                                            \
     175do {                                            \
    134176   switch (SZ) {                                \
    135177   case 4: (DST)[3] = (SRC)[3];                 \
     
    138180   case 1: (DST)[0] = (SRC)[0];                 \
    139181   }                                            \
    140 }                                                               /* while(0)*/
     182} while(0)
    141183
    142184#define SUB_4V( DST, SRCA, SRCB )               \
    143 /*do */{                                            \
     185do {                                            \
    144186      (DST)[0] = (SRCA)[0] - (SRCB)[0];         \
    145187      (DST)[1] = (SRCA)[1] - (SRCB)[1];         \
    146188      (DST)[2] = (SRCA)[2] - (SRCB)[2];         \
    147189      (DST)[3] = (SRCA)[3] - (SRCB)[3];         \
    148 }                                                              /* while (0)*/
     190} while (0)
    149191
    150192#define ADD_4V( DST, SRCA, SRCB )               \
    151 /*do*/ {                                            \
     193do {                                            \
    152194      (DST)[0] = (SRCA)[0] + (SRCB)[0];         \
    153195      (DST)[1] = (SRCA)[1] + (SRCB)[1];         \
    154196      (DST)[2] = (SRCA)[2] + (SRCB)[2];         \
    155197      (DST)[3] = (SRCA)[3] + (SRCB)[3];         \
    156 }                                                              /* while (0)*/
     198} while (0)
    157199
    158200#define SCALE_4V( DST, SRCA, SRCB )             \
    159 /*do*/ {                                            \
     201do {                                            \
    160202      (DST)[0] = (SRCA)[0] * (SRCB)[0];         \
    161203      (DST)[1] = (SRCA)[1] * (SRCB)[1];         \
    162204      (DST)[2] = (SRCA)[2] * (SRCB)[2];         \
    163205      (DST)[3] = (SRCA)[3] * (SRCB)[3];         \
    164 }                                                              /* while (0)*/
     206} while (0)
    165207
    166208#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)*/
     209do {                                            \
     210      (DST)[0] += (SRC)[0];                     \
     211      (DST)[1] += (SRC)[1];                     \
     212      (DST)[2] += (SRC)[2];                     \
     213      (DST)[3] += (SRC)[3];                     \
     214} while (0)
    173215
    174216#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)*/
     217do {                                            \
     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)
    181223
    182224#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)*/
     225do {                                            \
     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)
    189231
    190232#define SCALE_SCALAR_4V( DST, S, SRCB )         \
    191 /*do*/ {                                            \
     233do {                                            \
    192234      (DST)[0] = S * (SRCB)[0];                 \
    193235      (DST)[1] = S * (SRCB)[1];                 \
    194236      (DST)[2] = S * (SRCB)[2];                 \
    195237      (DST)[3] = S * (SRCB)[3];                 \
    196 }                                                              /* while (0)*/
     238} while (0)
    197239
    198240
    199241#define SELF_SCALE_SCALAR_4V( DST, S )          \
    200 /*do*/ {                                            \
     242do {                                            \
    201243      (DST)[0] *= S;                            \
    202244      (DST)[1] *= S;                            \
    203245      (DST)[2] *= S;                            \
    204246      (DST)[3] *= S;                            \
    205 }                                                              /* while (0)*/
     247} while (0)
    206248
    207249
     
    210252 */
    211253#define SUB_3V( DST, SRCA, SRCB )               \
    212 /*do*/ {                                            \
     254do {                                            \
    213255      (DST)[0] = (SRCA)[0] - (SRCB)[0];         \
    214256      (DST)[1] = (SRCA)[1] - (SRCB)[1];         \
    215257      (DST)[2] = (SRCA)[2] - (SRCB)[2];         \
    216 }                                                              /* while (0)*/
     258} while (0)
    217259
    218260#define ADD_3V( DST, SRCA, SRCB )               \
    219 /*do*/ {                                            \
     261do {                                            \
    220262      (DST)[0] = (SRCA)[0] + (SRCB)[0];         \
    221263      (DST)[1] = (SRCA)[1] + (SRCB)[1];         \
    222264      (DST)[2] = (SRCA)[2] + (SRCB)[2];         \
    223 }                                                              /* while (0)*/
     265} while (0)
    224266
    225267#define SCALE_3V( DST, SRCA, SRCB )             \
    226 /*do*/ {                                            \
     268do {                                            \
    227269      (DST)[0] = (SRCA)[0] * (SRCB)[0];         \
    228270      (DST)[1] = (SRCA)[1] * (SRCB)[1];         \
    229271      (DST)[2] = (SRCA)[2] * (SRCB)[2];         \
    230 }                                                              /* while (0)*/
     272} while (0)
    231273
    232274#define ACC_3V( DST, SRC )                      \
    233 /*do*/ {                                            \
     275do {                                            \
    234276      (DST)[0] += (SRC)[0];                     \
    235277      (DST)[1] += (SRC)[1];                     \
    236278      (DST)[2] += (SRC)[2];                     \
    237 }                                                              /* while (0)*/
     279} while (0)
    238280
    239281#define ACC_SCALE_3V( DST, SRCA, SRCB )         \
    240 /*do*/ {                                            \
     282do {                                            \
    241283      (DST)[0] += (SRCA)[0] * (SRCB)[0];        \
    242284      (DST)[1] += (SRCA)[1] * (SRCB)[1];        \
    243285      (DST)[2] += (SRCA)[2] * (SRCB)[2];        \
    244 }                                                              /* while (0)*/
     286} while (0)
    245287
    246288#define SCALE_SCALAR_3V( DST, S, SRCB )         \
    247 /*do*/ {                                            \
     289do {                                            \
    248290      (DST)[0] = S * (SRCB)[0];                 \
    249291      (DST)[1] = S * (SRCB)[1];                 \
    250292      (DST)[2] = S * (SRCB)[2];                 \
    251 }                                                              /* while (0)*/
     293} while (0)
    252294
    253295#define ACC_SCALE_SCALAR_3V( DST, S, SRCB )     \
    254 /*do*/ {                                            \
     296do {                                            \
    255297      (DST)[0] += S * (SRCB)[0];                \
    256298      (DST)[1] += S * (SRCB)[1];                \
    257299      (DST)[2] += S * (SRCB)[2];                \
    258 }                                                              /* while (0)*/
     300} while (0)
    259301
    260302#define SELF_SCALE_SCALAR_3V( DST, S )          \
    261 /*do*/ {                                            \
     303do {                                            \
    262304      (DST)[0] *= S;                            \
    263305      (DST)[1] *= S;                            \
    264306      (DST)[2] *= S;                            \
    265 }                                                              /* while (0)*/
     307} while (0)
    266308
    267309#define ACC_SCALAR_3V( DST, S )                 \
    268 /*do*/ {                                            \
     310do {                                            \
    269311      (DST)[0] += S;                            \
    270312      (DST)[1] += S;                            \
    271313      (DST)[2] += S;                            \
    272 }                                                              /* while (0)*/
     314} while (0)
    273315
    274316/* And also for 2-vectors
    275317 */
    276318#define SUB_2V( DST, SRCA, SRCB )               \
    277 /*do*/ {                                            \
     319do {                                            \
    278320      (DST)[0] = (SRCA)[0] - (SRCB)[0];         \
    279321      (DST)[1] = (SRCA)[1] - (SRCB)[1];         \
    280 }                                                              /* while (0)*/
     322} while (0)
    281323
    282324#define ADD_2V( DST, SRCA, SRCB )               \
    283 /*do*/ {                                            \
     325do {                                            \
    284326      (DST)[0] = (SRCA)[0] + (SRCB)[0];         \
    285327      (DST)[1] = (SRCA)[1] + (SRCB)[1];         \
    286 }                                                              /* while (0)*/
     328} while (0)
    287329
    288330#define SCALE_2V( DST, SRCA, SRCB )             \
    289 /*do*/ {                                            \
     331do {                                            \
    290332      (DST)[0] = (SRCA)[0] * (SRCB)[0];         \
    291333      (DST)[1] = (SRCA)[1] * (SRCB)[1];         \
    292 }                                                              /* while (0)*/
     334} while (0)
    293335
    294336#define ACC_2V( DST, SRC )                      \
    295 /*do*/ {                                            \
     337do {                                            \
    296338      (DST)[0] += (SRC)[0];                     \
    297339      (DST)[1] += (SRC)[1];                     \
    298 }                                                              /* while (0)*/
     340} while (0)
    299341
    300342#define ACC_SCALE_2V( DST, SRCA, SRCB )         \
    301 /*do*/ {                                            \
     343do {                                            \
    302344      (DST)[0] += (SRCA)[0] * (SRCB)[0];        \
    303345      (DST)[1] += (SRCA)[1] * (SRCB)[1];        \
    304 }                                                              /* while (0)*/
     346} while (0)
    305347
    306348#define SCALE_SCALAR_2V( DST, S, SRCB )         \
    307 /*do*/ {                                            \
     349do {                                            \
    308350      (DST)[0] = S * (SRCB)[0];                 \
    309351      (DST)[1] = S * (SRCB)[1];                 \
    310 }                                                              /* while (0)*/
     352} while (0)
    311353
    312354#define ACC_SCALE_SCALAR_2V( DST, S, SRCB )     \
    313 /*do*/ {                                            \
     355do {                                            \
    314356      (DST)[0] += S * (SRCB)[0];                \
    315357      (DST)[1] += S * (SRCB)[1];                \
    316 }                                                              /* while (0)*/
     358} while (0)
    317359
    318360#define SELF_SCALE_SCALAR_2V( DST, S )          \
    319 /*do*/ {                                            \
     361do {                                            \
    320362      (DST)[0] *= S;                            \
    321363      (DST)[1] *= S;                            \
    322 }                                                              /* while (0)*/
     364} while (0)
    323365
    324366#define ACC_SCALAR_2V( DST, S )                 \
    325 /*do*/ {                                            \
     367do {                                            \
    326368      (DST)[0] += S;                            \
    327369      (DST)[1] += S;                            \
    328 }                                                              /* while (0)*/
     370} while (0)
    329371
    330372
     
    334376 */
    335377#define COPY_4UBV(DST, SRC)                     \
    336 /*do*/ {                                        \
     378do {                                            \
    337379   if (sizeof(GLuint)==4*sizeof(GLubyte)) {     \
    338380      *((GLuint*)(DST)) = *((GLuint*)(SRC));    \
     
    344386      (DST)[3] = (SRC)[3];                      \
    345387   }                                            \
    346 }                                                              /* while (0)*/
     388} while (0)
    347389
    348390
    349391/* Assign scalers to short vectors: */
    350392#define ASSIGN_2V( V, V0, V1 )  \
    351 /*do*/ { V[0] = V0;  V[1] = V1; } //while(0)
     393do { V[0] = V0;  V[1] = V1; } while(0)
    352394
    353395#define ASSIGN_3V( V, V0, V1, V2 )  \
    354 /*do*/ { V[0] = V0;  V[1] = V1;  V[2] = V2; } //while(0)
     396do { V[0] = V0;  V[1] = V1;  V[2] = V2; } while(0)
    355397
    356398#define ASSIGN_4V( V, V0, V1, V2, V3 )          \
    357 /*do*/ {                                            \
     399do {                                            \
    358400    V[0] = V0;                                  \
    359401    V[1] = V1;                                  \
    360402    V[2] = V2;                                  \
    361403    V[3] = V3;                                  \
    362 }                                                               /* while(0)*/
     404} while(0)
    363405
    364406
     
    421463 * Integer / float conversion for colors, normals, etc.
    422464 */
    423 
    424 
    425 
    426465
    427466#define BYTE_TO_UBYTE(b)   (b < 0 ? 0 : (GLubyte) b)
     
    430469#define INT_TO_UBYTE(i)    (i < 0 ? 0 : (GLubyte) (i >> 23))
    431470#define UINT_TO_UBYTE(i)                (GLubyte) (i >> 24)
    432 
    433 
    434 
    435471
    436472/* Convert GLubyte in [0,255] to GLfloat in [0.0,1.0] */
     
    480516
    481517
    482 
    483 /*
    484  * Memory allocation
    485  * XXX these should probably go into a new glmemory.h file.
    486  */
    487 #ifdef DEBUG
    488 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 #else
    497 #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 #endif
    503 
    504 
    505 /* Memory copy: */
    506 #ifdef SUNOS4
    507 #define MEMCPY( DST, SRC, BYTES) \
    508         memcpy( (char *) (DST), (char *) (SRC), (int) (BYTES) )
    509 #else
    510 #define MEMCPY( DST, SRC, BYTES) \
    511         memcpy( (void *) (DST), (void *) (SRC), (size_t) (BYTES) )
    512 #endif
    513 
    514 
    515 /* Memory set: */
    516 #ifdef SUNOS4
    517 #define MEMSET( DST, VAL, N ) \
    518         memset( (char *) (DST), (int) (VAL), (int) (N) )
    519 #else
    520 #define MEMSET( DST, VAL, N ) \
    521         memset( (void *) (DST), (int) (VAL), (size_t) (N) )
    522 #endif
    523 
    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 #else
    539 #  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 #endif
    544 
    545 
    546 /* Some compilers don't like some of Mesa's const usage */
    547 #ifdef NO_CONST
    548 #  define CONST
    549 #else
    550 #  define CONST const
    551 #endif
    552 
    553 
    554 
    555 /* Pi */
    556 #ifndef M_PI
    557 #define M_PI (3.1415926)
    558 #endif
    559 
    560 
    561 /* Degrees to radians conversion: */
    562 #define DEG2RAD (M_PI/180.0)
    563 
    564 
    565 #ifndef NULL
    566 #define NULL 0
    567 #endif
    568 
    569 
    570 
    571518#endif /*MACROS_H*/
Note: See TracChangeset for help on using the changeset viewer.