Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenimports.c
Go to the documentation of this file.
00001 00021 /* 00022 * Mesa 3-D graphics library 00023 * Version: 7.1 00024 * 00025 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 00026 * 00027 * Permission is hereby granted, free of charge, to any person obtaining a 00028 * copy of this software and associated documentation files (the "Software"), 00029 * to deal in the Software without restriction, including without limitation 00030 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00031 * and/or sell copies of the Software, and to permit persons to whom the 00032 * Software is furnished to do so, subject to the following conditions: 00033 * 00034 * The above copyright notice and this permission notice shall be included 00035 * in all copies or substantial portions of the Software. 00036 * 00037 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00038 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00039 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00040 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 00041 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00042 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00043 */ 00044 00045 00046 00047 #include "imports.h" 00048 #include "context.h" 00049 #include "version.h" 00050 00051 00052 #define MAXSTRING 4000 /* for vsnprintf() */ 00053 00054 #ifdef WIN32 00055 #define vsnprintf _vsnprintf 00056 #elif defined(__IBMC__) || defined(__IBMCPP__) || ( defined(__VMS) && __CRTL_VER < 70312000 ) 00057 extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg); 00058 #ifdef __VMS 00059 #include "vsnprintf.c" 00060 #endif 00061 #endif 00062 00063 /**********************************************************************/ 00066 00068 void * 00069 _mesa_malloc(size_t bytes) 00070 { 00071 return malloc(bytes); 00072 } 00073 00075 void * 00076 _mesa_calloc(size_t bytes) 00077 { 00078 return calloc(1, bytes); 00079 } 00080 00082 void 00083 _mesa_free(void *ptr) 00084 { 00085 free(ptr); 00086 } 00087 00099 void * 00100 _mesa_align_malloc(size_t bytes, unsigned long alignment) 00101 { 00102 #if defined(HAVE_POSIX_MEMALIGN) 00103 void *mem; 00104 00105 (void) posix_memalign(& mem, alignment, bytes); 00106 return mem; 00107 #elif 0/*defined(_WIN32) && defined(_MSC_VER)*/ 00108 return _aligned_malloc(bytes, alignment); 00109 #else 00110 uintptr_t ptr, buf; 00111 00112 ASSERT( alignment > 0 ); 00113 00114 ptr = (uintptr_t) _mesa_malloc(bytes + alignment + sizeof(void *)); 00115 if (!ptr) 00116 return NULL; 00117 00118 buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1); 00119 *(uintptr_t *)(buf - sizeof(void *)) = ptr; 00120 00121 #ifdef DEBUG 00122 /* mark the non-aligned area */ 00123 while ( ptr < buf - sizeof(void *) ) { 00124 *(unsigned long *)ptr = 0xcdcdcdcd; 00125 ptr += sizeof(unsigned long); 00126 } 00127 #endif 00128 00129 return (void *) buf; 00130 #endif /* defined(HAVE_POSIX_MEMALIGN) */ 00131 } 00132 00137 void * 00138 _mesa_align_calloc(size_t bytes, unsigned long alignment) 00139 { 00140 #if defined(HAVE_POSIX_MEMALIGN) 00141 void *mem; 00142 00143 mem = _mesa_align_malloc(bytes, alignment); 00144 if (mem != NULL) { 00145 (void) memset(mem, 0, bytes); 00146 } 00147 00148 return mem; 00149 #elif 0/*defined(_WIN32) && defined(_MSC_VER)*/ 00150 void *mem; 00151 00152 mem = _aligned_malloc(bytes, alignment); 00153 if (mem != NULL) { 00154 (void) memset(mem, 0, bytes); 00155 } 00156 00157 return mem; 00158 #else 00159 uintptr_t ptr, buf; 00160 00161 ASSERT( alignment > 0 ); 00162 00163 ptr = (uintptr_t) _mesa_calloc(bytes + alignment + sizeof(void *)); 00164 if (!ptr) 00165 return NULL; 00166 00167 buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1); 00168 *(uintptr_t *)(buf - sizeof(void *)) = ptr; 00169 00170 #ifdef DEBUG 00171 /* mark the non-aligned area */ 00172 while ( ptr < buf - sizeof(void *) ) { 00173 *(unsigned long *)ptr = 0xcdcdcdcd; 00174 ptr += sizeof(unsigned long); 00175 } 00176 #endif 00177 00178 return (void *)buf; 00179 #endif /* defined(HAVE_POSIX_MEMALIGN) */ 00180 } 00181 00189 void 00190 _mesa_align_free(void *ptr) 00191 { 00192 #if defined(HAVE_POSIX_MEMALIGN) 00193 free(ptr); 00194 #elif defined(_WIN32) && defined(_MSC_VER) 00195 _aligned_free(ptr); 00196 #else 00197 void **cubbyHole = (void **) ((char *) ptr - sizeof(void *)); 00198 void *realAddr = *cubbyHole; 00199 _mesa_free(realAddr); 00200 #endif /* defined(HAVE_POSIX_MEMALIGN) */ 00201 } 00202 00206 void * 00207 _mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize, 00208 unsigned long alignment) 00209 { 00210 #if defined(_WIN32) && defined(_MSC_VER) 00211 (void) oldSize; 00212 return _aligned_realloc(oldBuffer, newSize, alignment); 00213 #else 00214 const size_t copySize = (oldSize < newSize) ? oldSize : newSize; 00215 void *newBuf = _mesa_align_malloc(newSize, alignment); 00216 if (newBuf && oldBuffer && copySize > 0) { 00217 _mesa_memcpy(newBuf, oldBuffer, copySize); 00218 } 00219 if (oldBuffer) 00220 _mesa_align_free(oldBuffer); 00221 return newBuf; 00222 #endif 00223 } 00224 00225 00226 00228 void * 00229 _mesa_realloc(void *oldBuffer, size_t oldSize, size_t newSize) 00230 { 00231 const size_t copySize = (oldSize < newSize) ? oldSize : newSize; 00232 void *newBuffer = _mesa_malloc(newSize); 00233 if (newBuffer && oldBuffer && copySize > 0) 00234 _mesa_memcpy(newBuffer, oldBuffer, copySize); 00235 if (oldBuffer) 00236 _mesa_free(oldBuffer); 00237 return newBuffer; 00238 } 00239 00241 void * 00242 _mesa_memcpy(void *dest, const void *src, size_t n) 00243 { 00244 #if defined(SUNOS4) 00245 return memcpy((char *) dest, (char *) src, (int) n); 00246 #else 00247 return memcpy(dest, src, n); 00248 #endif 00249 } 00250 00252 void 00253 _mesa_memset( void *dst, int val, size_t n ) 00254 { 00255 #if defined(SUNOS4) 00256 memset( (char *) dst, (int) val, (int) n ); 00257 #else 00258 memset(dst, val, n); 00259 #endif 00260 } 00261 00268 void 00269 _mesa_memset16( unsigned short *dst, unsigned short val, size_t n ) 00270 { 00271 while (n-- > 0) 00272 *dst++ = val; 00273 } 00274 00276 void 00277 _mesa_bzero( void *dst, size_t n ) 00278 { 00279 #if defined(__FreeBSD__) 00280 bzero( dst, n ); 00281 #else 00282 memset( dst, 0, n ); 00283 #endif 00284 } 00285 00287 int 00288 _mesa_memcmp( const void *s1, const void *s2, size_t n ) 00289 { 00290 #if defined(SUNOS4) 00291 return memcmp( (char *) s1, (char *) s2, (int) n ); 00292 #else 00293 return memcmp(s1, s2, n); 00294 #endif 00295 } 00296 00300 /**********************************************************************/ 00303 00305 double 00306 _mesa_sin(double a) 00307 { 00308 return sin(a); 00309 } 00310 00312 float 00313 _mesa_sinf(float a) 00314 { 00315 return (float) sin((double) a); 00316 } 00317 00319 double 00320 _mesa_cos(double a) 00321 { 00322 return cos(a); 00323 } 00324 00326 float 00327 _mesa_asinf(float x) 00328 { 00329 return (float) asin((double) x); 00330 } 00331 00333 float 00334 _mesa_atanf(float x) 00335 { 00336 return (float) atan((double) x); 00337 } 00338 00340 double 00341 _mesa_sqrtd(double x) 00342 { 00343 return sqrt(x); 00344 } 00345 00346 00347 /* 00348 * A High Speed, Low Precision Square Root 00349 * by Paul Lalonde and Robert Dawson 00350 * from "Graphics Gems", Academic Press, 1990 00351 * 00352 * SPARC implementation of a fast square root by table 00353 * lookup. 00354 * SPARC floating point format is as follows: 00355 * 00356 * BIT 31 30 23 22 0 00357 * sign exponent mantissa 00358 */ 00359 static short sqrttab[0x100]; /* declare table of square roots */ 00360 00361 void 00362 _mesa_init_sqrt_table(void) 00363 { 00364 #if defined(USE_IEEE) && !defined(DEBUG) 00365 unsigned short i; 00366 fi_type fi; /* to access the bits of a float in C quickly */ 00367 /* we use a union defined in glheader.h */ 00368 00369 for(i=0; i<= 0x7f; i++) { 00370 fi.i = 0; 00371 00372 /* 00373 * Build a float with the bit pattern i as mantissa 00374 * and an exponent of 0, stored as 127 00375 */ 00376 00377 fi.i = (i << 16) | (127 << 23); 00378 fi.f = _mesa_sqrtd(fi.f); 00379 00380 /* 00381 * Take the square root then strip the first 7 bits of 00382 * the mantissa into the table 00383 */ 00384 00385 sqrttab[i] = (fi.i & 0x7fffff) >> 16; 00386 00387 /* 00388 * Repeat the process, this time with an exponent of 00389 * 1, stored as 128 00390 */ 00391 00392 fi.i = 0; 00393 fi.i = (i << 16) | (128 << 23); 00394 fi.f = sqrt(fi.f); 00395 sqrttab[i+0x80] = (fi.i & 0x7fffff) >> 16; 00396 } 00397 #else 00398 (void) sqrttab; /* silence compiler warnings */ 00399 #endif /*HAVE_FAST_MATH*/ 00400 } 00401 00402 00406 float 00407 _mesa_sqrtf( float x ) 00408 { 00409 #if defined(USE_IEEE) && !defined(DEBUG) 00410 fi_type num; 00411 /* to access the bits of a float in C 00412 * we use a union from glheader.h */ 00413 00414 short e; /* the exponent */ 00415 if (x == 0.0F) return 0.0F; /* check for square root of 0 */ 00416 num.f = x; 00417 e = (num.i >> 23) - 127; /* get the exponent - on a SPARC the */ 00418 /* exponent is stored with 127 added */ 00419 num.i &= 0x7fffff; /* leave only the mantissa */ 00420 if (e & 0x01) num.i |= 0x800000; 00421 /* the exponent is odd so we have to */ 00422 /* look it up in the second half of */ 00423 /* the lookup table, so we set the */ 00424 /* high bit */ 00425 e >>= 1; /* divide the exponent by two */ 00426 /* note that in C the shift */ 00427 /* operators are sign preserving */ 00428 /* for signed operands */ 00429 /* Do the table lookup, based on the quaternary mantissa, 00430 * then reconstruct the result back into a float 00431 */ 00432 num.i = ((sqrttab[num.i >> 16]) << 16) | ((e + 127) << 23); 00433 00434 return num.f; 00435 #else 00436 return (float) _mesa_sqrtd((double) x); 00437 #endif 00438 } 00439 00440 00446 float 00447 _mesa_inv_sqrtf(float n) 00448 { 00449 #if defined(USE_IEEE) && !defined(DEBUG) 00450 float r0, x0, y0; 00451 float r1, x1, y1; 00452 float r2, x2, y2; 00453 #if 0 /* not used, see below -BP */ 00454 float r3, x3, y3; 00455 #endif 00456 union { float f; unsigned int i; } u; 00457 unsigned int magic; 00458 00459 /* 00460 Exponent part of the magic number - 00461 00462 We want to: 00463 1. subtract the bias from the exponent, 00464 2. negate it 00465 3. divide by two (rounding towards -inf) 00466 4. add the bias back 00467 00468 Which is the same as subtracting the exponent from 381 and dividing 00469 by 2. 00470 00471 floor(-(x - 127) / 2) + 127 = floor((381 - x) / 2) 00472 */ 00473 00474 magic = 381 << 23; 00475 00476 /* 00477 Significand part of magic number - 00478 00479 With the current magic number, "(magic - u.i) >> 1" will give you: 00480 00481 for 1 <= u.f <= 2: 1.25 - u.f / 4 00482 for 2 <= u.f <= 4: 1.00 - u.f / 8 00483 00484 This isn't a bad approximation of 1/sqrt. The maximum difference from 00485 1/sqrt will be around .06. After three Newton-Raphson iterations, the 00486 maximum difference is less than 4.5e-8. (Which is actually close 00487 enough to make the following bias academic...) 00488 00489 To get a better approximation you can add a bias to the magic 00490 number. For example, if you subtract 1/2 of the maximum difference in 00491 the first approximation (.03), you will get the following function: 00492 00493 for 1 <= u.f <= 2: 1.22 - u.f / 4 00494 for 2 <= u.f <= 3.76: 0.97 - u.f / 8 00495 for 3.76 <= u.f <= 4: 0.72 - u.f / 16 00496 (The 3.76 to 4 range is where the result is < .5.) 00497 00498 This is the closest possible initial approximation, but with a maximum 00499 error of 8e-11 after three NR iterations, it is still not perfect. If 00500 you subtract 0.0332281 instead of .03, the maximum error will be 00501 2.5e-11 after three NR iterations, which should be about as close as 00502 is possible. 00503 00504 for 1 <= u.f <= 2: 1.2167719 - u.f / 4 00505 for 2 <= u.f <= 3.73: 0.9667719 - u.f / 8 00506 for 3.73 <= u.f <= 4: 0.7167719 - u.f / 16 00507 00508 */ 00509 00510 magic -= (int)(0.0332281 * (1 << 25)); 00511 00512 u.f = n; 00513 u.i = (magic - u.i) >> 1; 00514 00515 /* 00516 Instead of Newton-Raphson, we use Goldschmidt's algorithm, which 00517 allows more parallelism. From what I understand, the parallelism 00518 comes at the cost of less precision, because it lets error 00519 accumulate across iterations. 00520 */ 00521 x0 = 1.0f; 00522 y0 = 0.5f * n; 00523 r0 = u.f; 00524 00525 x1 = x0 * r0; 00526 y1 = y0 * r0 * r0; 00527 r1 = 1.5f - y1; 00528 00529 x2 = x1 * r1; 00530 y2 = y1 * r1 * r1; 00531 r2 = 1.5f - y2; 00532 00533 #if 1 00534 return x2 * r2; /* we can stop here, and be conformant -BP */ 00535 #else 00536 x3 = x2 * r2; 00537 y3 = y2 * r2 * r2; 00538 r3 = 1.5f - y3; 00539 00540 return x3 * r3; 00541 #endif 00542 #else 00543 return (float) (1.0 / sqrt(n)); 00544 #endif 00545 } 00546 00547 00549 double 00550 _mesa_pow(double x, double y) 00551 { 00552 return pow(x, y); 00553 } 00554 00555 00559 int 00560 _mesa_ffs(int i) 00561 { 00562 #if (defined(_WIN32) ) || defined(__IBMC__) || defined(__IBMCPP__) 00563 register int bit = 0; 00564 if (i != 0) { 00565 if ((i & 0xffff) == 0) { 00566 bit += 16; 00567 i >>= 16; 00568 } 00569 if ((i & 0xff) == 0) { 00570 bit += 8; 00571 i >>= 8; 00572 } 00573 if ((i & 0xf) == 0) { 00574 bit += 4; 00575 i >>= 4; 00576 } 00577 while ((i & 1) == 0) { 00578 bit++; 00579 i >>= 1; 00580 } 00581 bit++; 00582 } 00583 return bit; 00584 #else 00585 return ffs(i); 00586 #endif 00587 } 00588 00589 00596 int 00597 #ifdef __MINGW32__ 00598 _mesa_ffsll(long val) 00599 #else 00600 _mesa_ffsll(long long val) 00601 #endif 00602 { 00603 #ifdef ffsll 00604 return ffsll(val); 00605 #else 00606 int bit; 00607 00608 assert(sizeof(val) == 8); 00609 00610 bit = _mesa_ffs(val); 00611 if (bit != 0) 00612 return bit; 00613 00614 bit = _mesa_ffs(val >> 32); 00615 if (bit != 0) 00616 return 32 + bit; 00617 00618 return 0; 00619 #endif 00620 } 00621 00622 00626 unsigned int 00627 _mesa_bitcount(unsigned int n) 00628 { 00629 unsigned int bits; 00630 for (bits = 0; n > 0; n = n >> 1) { 00631 bits += (n & 1); 00632 } 00633 return bits; 00634 } 00635 00636 00642 GLhalfARB 00643 _mesa_float_to_half(float val) 00644 { 00645 const int flt = *((int *) (void *) &val); 00646 const int flt_m = flt & 0x7fffff; 00647 const int flt_e = (flt >> 23) & 0xff; 00648 const int flt_s = (flt >> 31) & 0x1; 00649 int s, e, m = 0; 00650 GLhalfARB result; 00651 00652 /* sign bit */ 00653 s = flt_s; 00654 00655 /* handle special cases */ 00656 if ((flt_e == 0) && (flt_m == 0)) { 00657 /* zero */ 00658 /* m = 0; - already set */ 00659 e = 0; 00660 } 00661 else if ((flt_e == 0) && (flt_m != 0)) { 00662 /* denorm -- denorm float maps to 0 half */ 00663 /* m = 0; - already set */ 00664 e = 0; 00665 } 00666 else if ((flt_e == 0xff) && (flt_m == 0)) { 00667 /* infinity */ 00668 /* m = 0; - already set */ 00669 e = 31; 00670 } 00671 else if ((flt_e == 0xff) && (flt_m != 0)) { 00672 /* NaN */ 00673 m = 1; 00674 e = 31; 00675 } 00676 else { 00677 /* regular number */ 00678 const int new_exp = flt_e - 127; 00679 if (new_exp < -24) { 00680 /* this maps to 0 */ 00681 /* m = 0; - already set */ 00682 e = 0; 00683 } 00684 else if (new_exp < -14) { 00685 /* this maps to a denorm */ 00686 unsigned int exp_val = (unsigned int) (-14 - new_exp); /* 2^-exp_val*/ 00687 e = 0; 00688 switch (exp_val) { 00689 case 0: 00690 _mesa_warning(NULL, 00691 "float_to_half: logical error in denorm creation!\n"); 00692 /* m = 0; - already set */ 00693 break; 00694 case 1: m = 512 + (flt_m >> 14); break; 00695 case 2: m = 256 + (flt_m >> 15); break; 00696 case 3: m = 128 + (flt_m >> 16); break; 00697 case 4: m = 64 + (flt_m >> 17); break; 00698 case 5: m = 32 + (flt_m >> 18); break; 00699 case 6: m = 16 + (flt_m >> 19); break; 00700 case 7: m = 8 + (flt_m >> 20); break; 00701 case 8: m = 4 + (flt_m >> 21); break; 00702 case 9: m = 2 + (flt_m >> 22); break; 00703 case 10: m = 1; break; 00704 } 00705 } 00706 else if (new_exp > 15) { 00707 /* map this value to infinity */ 00708 /* m = 0; - already set */ 00709 e = 31; 00710 } 00711 else { 00712 /* regular */ 00713 e = new_exp + 15; 00714 m = flt_m >> 13; 00715 } 00716 } 00717 00718 result = (s << 15) | (e << 10) | m; 00719 return result; 00720 } 00721 00722 00728 float 00729 _mesa_half_to_float(GLhalfARB val) 00730 { 00731 /* XXX could also use a 64K-entry lookup table */ 00732 const int m = val & 0x3ff; 00733 const int e = (val >> 10) & 0x1f; 00734 const int s = (val >> 15) & 0x1; 00735 int flt_m, flt_e, flt_s, flt; 00736 float result; 00737 00738 /* sign bit */ 00739 flt_s = s; 00740 00741 /* handle special cases */ 00742 if ((e == 0) && (m == 0)) { 00743 /* zero */ 00744 flt_m = 0; 00745 flt_e = 0; 00746 } 00747 else if ((e == 0) && (m != 0)) { 00748 /* denorm -- denorm half will fit in non-denorm single */ 00749 const float half_denorm = 1.0f / 16384.0f; /* 2^-14 */ 00750 float mantissa = ((float) (m)) / 1024.0f; 00751 float sign = s ? -1.0f : 1.0f; 00752 return sign * mantissa * half_denorm; 00753 } 00754 else if ((e == 31) && (m == 0)) { 00755 /* infinity */ 00756 flt_e = 0xff; 00757 flt_m = 0; 00758 } 00759 else if ((e == 31) && (m != 0)) { 00760 /* NaN */ 00761 flt_e = 0xff; 00762 flt_m = 1; 00763 } 00764 else { 00765 /* regular */ 00766 flt_e = e + 112; 00767 flt_m = m << 13; 00768 } 00769 00770 flt = (flt_s << 31) | (flt_e << 23) | flt_m; 00771 result = *((float *) (void *) &flt); 00772 return result; 00773 } 00774 00778 /**********************************************************************/ 00781 00785 void * 00786 _mesa_bsearch( const void *key, const void *base, size_t nmemb, size_t size, 00787 int (*compar)(const void *, const void *) ) 00788 { 00789 #if defined(_WIN32_WCE) 00790 void *mid; 00791 int cmp; 00792 while (nmemb) { 00793 nmemb >>= 1; 00794 mid = (char *)base + nmemb * size; 00795 cmp = (*compar)(key, mid); 00796 if (cmp == 0) 00797 return mid; 00798 if (cmp > 0) { 00799 base = (char *)mid + size; 00800 --nmemb; 00801 } 00802 } 00803 return NULL; 00804 #else 00805 return bsearch(key, base, nmemb, size, compar); 00806 #endif 00807 } 00808 00812 /**********************************************************************/ 00815 00819 char * 00820 _mesa_getenv( const char *var ) 00821 { 00822 #if defined(_XBOX) || defined(_WIN32_WCE) 00823 return NULL; 00824 #else 00825 return getenv(var); 00826 #endif 00827 } 00828 00832 /**********************************************************************/ 00835 00837 char * 00838 _mesa_strstr( const char *haystack, const char *needle ) 00839 { 00840 return strstr(haystack, needle); 00841 } 00842 00844 char * 00845 _mesa_strncat( char *dest, const char *src, size_t n ) 00846 { 00847 return strncat(dest, src, n); 00848 } 00849 00851 char * 00852 _mesa_strcpy( char *dest, const char *src ) 00853 { 00854 return strcpy(dest, src); 00855 } 00856 00858 char * 00859 _mesa_strncpy( char *dest, const char *src, size_t n ) 00860 { 00861 return strncpy(dest, src, n); 00862 } 00863 00865 size_t 00866 _mesa_strlen( const char *s ) 00867 { 00868 return strlen(s); 00869 } 00870 00872 int 00873 _mesa_strcmp( const char *s1, const char *s2 ) 00874 { 00875 return strcmp(s1, s2); 00876 } 00877 00879 int 00880 _mesa_strncmp( const char *s1, const char *s2, size_t n ) 00881 { 00882 return strncmp(s1, s2, n); 00883 } 00884 00889 char * 00890 _mesa_strdup( const char *s ) 00891 { 00892 if (s) { 00893 size_t l = _mesa_strlen(s); 00894 char *s2 = (char *) _mesa_malloc(l + 1); 00895 if (s2) 00896 _mesa_strcpy(s2, s); 00897 return s2; 00898 } 00899 else { 00900 return NULL; 00901 } 00902 } 00903 00905 int 00906 _mesa_atoi(const char *s) 00907 { 00908 return atoi(s); 00909 } 00910 00912 double 00913 _mesa_strtod( const char *s, char **end ) 00914 { 00915 return strtod(s, end); 00916 } 00917 00921 /**********************************************************************/ 00924 00926 int 00927 _mesa_sprintf( char *str, const char *fmt, ... ) 00928 { 00929 int r; 00930 va_list args; 00931 va_start( args, fmt ); 00932 r = vsprintf( str, fmt, args ); 00933 va_end( args ); 00934 return r; 00935 } 00936 00938 int 00939 _mesa_snprintf( char *str, size_t size, const char *fmt, ... ) 00940 { 00941 int r; 00942 va_list args; 00943 va_start( args, fmt ); 00944 r = vsnprintf( str, size, fmt, args ); 00945 va_end( args ); 00946 return r; 00947 } 00948 00950 void 00951 _mesa_printf( const char *fmtString, ... ) 00952 { 00953 char s[MAXSTRING]; 00954 va_list args; 00955 va_start( args, fmtString ); 00956 vsnprintf(s, MAXSTRING, fmtString, args); 00957 va_end( args ); 00958 fprintf(stderr, "%s", s); 00959 } 00960 00962 void 00963 _mesa_fprintf( FILE *f, const char *fmtString, ... ) 00964 { 00965 char s[MAXSTRING]; 00966 va_list args; 00967 va_start( args, fmtString ); 00968 vsnprintf(s, MAXSTRING, fmtString, args); 00969 va_end( args ); 00970 fprintf(f, "%s", s); 00971 } 00972 00973 00975 int 00976 _mesa_vsprintf( char *str, const char *fmt, va_list args ) 00977 { 00978 return vsprintf( str, fmt, args ); 00979 } 00980 00984 /**********************************************************************/ 00987 00995 void 00996 _mesa_warning( GLcontext *ctx, const char *fmtString, ... ) 00997 { 00998 GLboolean debug; 00999 char str[MAXSTRING]; 01000 va_list args; 01001 (void) ctx; 01002 va_start( args, fmtString ); 01003 (void) vsnprintf( str, MAXSTRING, fmtString, args ); 01004 va_end( args ); 01005 #ifdef DEBUG 01006 debug = GL_TRUE; /* always print warning */ 01007 #else 01008 debug = _mesa_getenv("MESA_DEBUG") ? GL_TRUE : GL_FALSE; 01009 #endif 01010 if (debug) { 01011 fprintf(stderr, "Mesa warning: %s\n", str); 01012 } 01013 } 01014 01022 void 01023 _mesa_problem( const GLcontext *ctx, const char *fmtString, ... ) 01024 { 01025 va_list args; 01026 char str[MAXSTRING]; 01027 (void) ctx; 01028 01029 va_start( args, fmtString ); 01030 vsnprintf( str, MAXSTRING, fmtString, args ); 01031 va_end( args ); 01032 01033 fprintf(stderr, "Mesa %s implementation error: %s\n", MESA_VERSION_STRING, str); 01034 fprintf(stderr, "Please report at bugzilla.freedesktop.org\n"); 01035 } 01036 01049 void 01050 _mesa_error( GLcontext *ctx, GLenum error, const char *fmtString, ... ) 01051 { 01052 const char *debugEnv; 01053 GLboolean debug; 01054 01055 debugEnv = _mesa_getenv("MESA_DEBUG"); 01056 01057 #ifdef DEBUG 01058 if (debugEnv && _mesa_strstr(debugEnv, "silent")) 01059 debug = GL_FALSE; 01060 else 01061 debug = GL_TRUE; 01062 #else 01063 if (debugEnv) 01064 debug = GL_TRUE; 01065 else 01066 debug = GL_FALSE; 01067 #endif 01068 01069 if (debug) { 01070 va_list args; 01071 char where[MAXSTRING]; 01072 const char *errstr; 01073 01074 va_start( args, fmtString ); 01075 vsnprintf( where, MAXSTRING, fmtString, args ); 01076 va_end( args ); 01077 01078 switch (error) { 01079 case GL_NO_ERROR: 01080 errstr = "GL_NO_ERROR"; 01081 break; 01082 case GL_INVALID_VALUE: 01083 errstr = "GL_INVALID_VALUE"; 01084 break; 01085 case GL_INVALID_ENUM: 01086 errstr = "GL_INVALID_ENUM"; 01087 break; 01088 case GL_INVALID_OPERATION: 01089 errstr = "GL_INVALID_OPERATION"; 01090 break; 01091 case GL_STACK_OVERFLOW: 01092 errstr = "GL_STACK_OVERFLOW"; 01093 break; 01094 case GL_STACK_UNDERFLOW: 01095 errstr = "GL_STACK_UNDERFLOW"; 01096 break; 01097 case GL_OUT_OF_MEMORY: 01098 errstr = "GL_OUT_OF_MEMORY"; 01099 break; 01100 case GL_TABLE_TOO_LARGE: 01101 errstr = "GL_TABLE_TOO_LARGE"; 01102 break; 01103 case GL_INVALID_FRAMEBUFFER_OPERATION_EXT: 01104 errstr = "GL_INVALID_FRAMEBUFFER_OPERATION"; 01105 break; 01106 default: 01107 errstr = "unknown"; 01108 break; 01109 } 01110 _mesa_debug(ctx, "User error: %s in %s\n", errstr, where); 01111 } 01112 01113 _mesa_record_error(ctx, error); 01114 } 01115 01123 void 01124 _mesa_debug( const GLcontext *ctx, const char *fmtString, ... ) 01125 { 01126 #ifdef DEBUG 01127 char s[MAXSTRING]; 01128 va_list args; 01129 va_start(args, fmtString); 01130 vsnprintf(s, MAXSTRING, fmtString, args); 01131 va_end(args); 01132 fprintf(stderr, "Mesa: %s", s); 01133 #endif /* DEBUG */ 01134 (void) ctx; 01135 (void) fmtString; 01136 } 01137 01144 void 01145 _mesa_exit( int status ) 01146 { 01147 exit(status); 01148 } Generated on Thu May 24 2012 04:19:49 for ReactOS by
1.7.6.1
|