3 * Standard C library function wrappers.
5 * Imports are services which the device driver or window system or
6 * operating system provides to the core renderer. The core renderer (Mesa)
7 * will call these functions in order to do memory allocation, simple I/O,
10 * Some drivers will want to override/replace this file with something
11 * specialized, but that'll be rare.
13 * Eventually, I want to move roll the glheader.h file into this.
15 * The OpenGL SI's __GLimports structure allows per-context specification of
16 * replacements for the standard C lib functions. In practice that's probably
17 * never needed; compile-time replacements are far more likely.
19 * The _mesa_*() functions defined here don't in general take a context
20 * parameter. I guess we can change that someday, if need be.
21 * So for now, the __GLimports stuff really isn't used.
23 * \todo Functions still needed:
30 * Mesa 3-D graphics library
33 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
35 * Permission is hereby granted, free of charge, to any person obtaining a
36 * copy of this software and associated documentation files (the "Software"),
37 * to deal in the Software without restriction, including without limitation
38 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
39 * and/or sell copies of the Software, and to permit persons to whom the
40 * Software is furnished to do so, subject to the following conditions:
42 * The above copyright notice and this permission notice shall be included
43 * in all copies or substantial portions of the Software.
45 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
46 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
49 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
50 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
60 #define MAXSTRING 4000 /* for vsnprintf() */
63 #define vsnprintf _vsnprintf
64 #elif defined(__IBMC__) || defined(__IBMCPP__) || ( defined(__VMS) && __CRTL_VER < 70312000 )
65 extern int vsnprintf(char *str
, size_t count
, const char *fmt
, va_list arg
);
67 #include "vsnprintf.c"
71 /**********************************************************************/
75 /** Wrapper around malloc() */
77 _mesa_malloc(size_t bytes
)
82 /** Wrapper around calloc() */
84 _mesa_calloc(size_t bytes
)
86 return calloc(1, bytes
);
89 /** Wrapper around free() */
97 * Allocate aligned memory.
99 * \param bytes number of bytes to allocate.
100 * \param alignment alignment (must be greater than zero).
102 * Allocates extra memory to accommodate rounding up the address for
103 * alignment and to record the real malloc address.
105 * \sa _mesa_align_free().
108 _mesa_align_malloc(size_t bytes
, unsigned long alignment
)
110 #if defined(HAVE_POSIX_MEMALIGN)
113 (void) posix_memalign(& mem
, alignment
, bytes
);
118 ASSERT( alignment
> 0 );
120 ptr
= (uintptr_t) _mesa_malloc(bytes
+ alignment
+ sizeof(void *));
124 buf
= (ptr
+ alignment
+ sizeof(void *)) & ~(uintptr_t)(alignment
- 1);
125 *(uintptr_t *)(buf
- sizeof(void *)) = ptr
;
128 /* mark the non-aligned area */
129 while ( ptr
< buf
- sizeof(void *) ) {
130 *(unsigned long *)ptr
= 0xcdcdcdcd;
131 ptr
+= sizeof(unsigned long);
136 #endif /* defined(HAVE_POSIX_MEMALIGN) */
140 * Same as _mesa_align_malloc(), but using _mesa_calloc() instead of
144 _mesa_align_calloc(size_t bytes
, unsigned long alignment
)
146 #if defined(HAVE_POSIX_MEMALIGN)
149 mem
= _mesa_align_malloc(bytes
, alignment
);
151 (void) memset(mem
, 0, bytes
);
158 ASSERT( alignment
> 0 );
160 ptr
= (uintptr_t) _mesa_calloc(bytes
+ alignment
+ sizeof(void *));
164 buf
= (ptr
+ alignment
+ sizeof(void *)) & ~(uintptr_t)(alignment
- 1);
165 *(uintptr_t *)(buf
- sizeof(void *)) = ptr
;
168 /* mark the non-aligned area */
169 while ( ptr
< buf
- sizeof(void *) ) {
170 *(unsigned long *)ptr
= 0xcdcdcdcd;
171 ptr
+= sizeof(unsigned long);
176 #endif /* defined(HAVE_POSIX_MEMALIGN) */
180 * Free memory which was allocated with either _mesa_align_malloc()
181 * or _mesa_align_calloc().
182 * \param ptr pointer to the memory to be freed.
183 * The actual address to free is stored in the word immediately before the
184 * address the client sees.
187 _mesa_align_free(void *ptr
)
189 #if defined(HAVE_POSIX_MEMALIGN)
192 void **cubbyHole
= (void **) ((char *) ptr
- sizeof(void *));
193 void *realAddr
= *cubbyHole
;
194 _mesa_free(realAddr
);
195 #endif /* defined(HAVE_POSIX_MEMALIGN) */
199 * Reallocate memory, with alignment.
202 _mesa_align_realloc(void *oldBuffer
, size_t oldSize
, size_t newSize
,
203 unsigned long alignment
)
205 const size_t copySize
= (oldSize
< newSize
) ? oldSize
: newSize
;
206 void *newBuf
= _mesa_align_malloc(newSize
, alignment
);
207 if (newBuf
&& oldBuffer
&& copySize
> 0) {
208 _mesa_memcpy(newBuf
, oldBuffer
, copySize
);
211 _mesa_align_free(oldBuffer
);
217 /** Reallocate memory */
219 _mesa_realloc(void *oldBuffer
, size_t oldSize
, size_t newSize
)
221 const size_t copySize
= (oldSize
< newSize
) ? oldSize
: newSize
;
222 void *newBuffer
= _mesa_malloc(newSize
);
223 if (newBuffer
&& oldBuffer
&& copySize
> 0)
224 _mesa_memcpy(newBuffer
, oldBuffer
, copySize
);
226 _mesa_free(oldBuffer
);
230 /** memcpy wrapper */
232 _mesa_memcpy(void *dest
, const void *src
, size_t n
)
235 return memcpy((char *) dest
, (char *) src
, (int) n
);
237 return memcpy(dest
, src
, n
);
241 /** Wrapper around memset() */
243 _mesa_memset( void *dst
, int val
, size_t n
)
246 memset( (char *) dst
, (int) val
, (int) n
);
253 * Fill memory with a constant 16bit word.
254 * \param dst destination pointer.
256 * \param n number of words.
259 _mesa_memset16( unsigned short *dst
, unsigned short val
, size_t n
)
265 /** Wrapper around either memcpy() or bzero() */
267 _mesa_bzero( void *dst
, size_t n
)
269 #if defined(__FreeBSD__)
276 /** Wrapper around memcmp() */
278 _mesa_memcmp( const void *s1
, const void *s2
, size_t n
)
281 return memcmp( (char *) s1
, (char *) s2
, (int) n
);
283 return memcmp(s1
, s2
, n
);
290 /**********************************************************************/
294 /** Wrapper around sin() */
301 /** Single precision wrapper around sin() */
305 return (float) sin((double) a
);
308 /** Wrapper around cos() */
315 /** Single precision wrapper around asin() */
319 return (float) asin((double) x
);
322 /** Single precision wrapper around atan() */
326 return (float) atan((double) x
);
329 /** Wrapper around sqrt() */
331 _mesa_sqrtd(double x
)
338 * A High Speed, Low Precision Square Root
339 * by Paul Lalonde and Robert Dawson
340 * from "Graphics Gems", Academic Press, 1990
342 * SPARC implementation of a fast square root by table
344 * SPARC floating point format is as follows:
347 * sign exponent mantissa
349 static short sqrttab
[0x100]; /* declare table of square roots */
351 static void init_sqrt_table(void)
353 #if defined(USE_IEEE) && !defined(DEBUG)
355 fi_type fi
; /* to access the bits of a float in C quickly */
356 /* we use a union defined in glheader.h */
358 for(i
=0; i
<= 0x7f; i
++) {
362 * Build a float with the bit pattern i as mantissa
363 * and an exponent of 0, stored as 127
366 fi
.i
= (i
<< 16) | (127 << 23);
367 fi
.f
= _mesa_sqrtd(fi
.f
);
370 * Take the square root then strip the first 7 bits of
371 * the mantissa into the table
374 sqrttab
[i
] = (fi
.i
& 0x7fffff) >> 16;
377 * Repeat the process, this time with an exponent of
382 fi
.i
= (i
<< 16) | (128 << 23);
384 sqrttab
[i
+0x80] = (fi
.i
& 0x7fffff) >> 16;
387 (void) sqrttab
; /* silence compiler warnings */
388 #endif /*HAVE_FAST_MATH*/
393 * Single precision square root.
396 _mesa_sqrtf( float x
)
398 #if defined(USE_IEEE) && !defined(DEBUG)
400 /* to access the bits of a float in C
401 * we use a union from glheader.h */
403 short e
; /* the exponent */
404 if (x
== 0.0F
) return 0.0F
; /* check for square root of 0 */
406 e
= (num
.i
>> 23) - 127; /* get the exponent - on a SPARC the */
407 /* exponent is stored with 127 added */
408 num
.i
&= 0x7fffff; /* leave only the mantissa */
409 if (e
& 0x01) num
.i
|= 0x800000;
410 /* the exponent is odd so we have to */
411 /* look it up in the second half of */
412 /* the lookup table, so we set the */
414 e
>>= 1; /* divide the exponent by two */
415 /* note that in C the shift */
416 /* operators are sign preserving */
417 /* for signed operands */
418 /* Do the table lookup, based on the quaternary mantissa,
419 * then reconstruct the result back into a float
421 num
.i
= ((sqrttab
[num
.i
>> 16]) << 16) | ((e
+ 127) << 23);
425 return (float) _mesa_sqrtd((double) x
);
431 inv_sqrt - A single precision 1/sqrt routine for IEEE format floats.
432 written by Josh Vanderhoof, based on newsgroup posts by James Van Buskirk
436 _mesa_inv_sqrtf(float n
)
438 #if defined(USE_IEEE) && !defined(DEBUG)
442 #if 0 /* not used, see below -BP */
445 union { float f
; unsigned int i
; } u
;
449 Exponent part of the magic number -
452 1. subtract the bias from the exponent,
454 3. divide by two (rounding towards -inf)
457 Which is the same as subtracting the exponent from 381 and dividing
460 floor(-(x - 127) / 2) + 127 = floor((381 - x) / 2)
466 Significand part of magic number -
468 With the current magic number, "(magic - u.i) >> 1" will give you:
470 for 1 <= u.f <= 2: 1.25 - u.f / 4
471 for 2 <= u.f <= 4: 1.00 - u.f / 8
473 This isn't a bad approximation of 1/sqrt. The maximum difference from
474 1/sqrt will be around .06. After three Newton-Raphson iterations, the
475 maximum difference is less than 4.5e-8. (Which is actually close
476 enough to make the following bias academic...)
478 To get a better approximation you can add a bias to the magic
479 number. For example, if you subtract 1/2 of the maximum difference in
480 the first approximation (.03), you will get the following function:
482 for 1 <= u.f <= 2: 1.22 - u.f / 4
483 for 2 <= u.f <= 3.76: 0.97 - u.f / 8
484 for 3.76 <= u.f <= 4: 0.72 - u.f / 16
485 (The 3.76 to 4 range is where the result is < .5.)
487 This is the closest possible initial approximation, but with a maximum
488 error of 8e-11 after three NR iterations, it is still not perfect. If
489 you subtract 0.0332281 instead of .03, the maximum error will be
490 2.5e-11 after three NR iterations, which should be about as close as
493 for 1 <= u.f <= 2: 1.2167719 - u.f / 4
494 for 2 <= u.f <= 3.73: 0.9667719 - u.f / 8
495 for 3.73 <= u.f <= 4: 0.7167719 - u.f / 16
499 magic
-= (int)(0.0332281 * (1 << 25));
502 u
.i
= (magic
- u
.i
) >> 1;
505 Instead of Newton-Raphson, we use Goldschmidt's algorithm, which
506 allows more parallelism. From what I understand, the parallelism
507 comes at the cost of less precision, because it lets error
508 accumulate across iterations.
523 return x2
* r2
; /* we can stop here, and be conformant -BP */
532 return (float) (1.0 / sqrt(n
));
537 /** Wrapper around pow() */
539 _mesa_pow(double x
, double y
)
546 * Find the first bit set in a word.
551 #if (defined(_WIN32) && !defined(__MINGW32__) ) || defined(__IBMC__) || defined(__IBMCPP__)
552 register int bit
= 0;
554 if ((i
& 0xffff) == 0) {
558 if ((i
& 0xff) == 0) {
562 if ((i
& 0xf) == 0) {
566 while ((i
& 1) == 0) {
579 * Return number of bits set in given GLuint.
582 _mesa_bitcount(unsigned int n
)
585 for (bits
= 0; n
> 0; n
= n
>> 1) {
593 * Convert a 4-byte float to a 2-byte half float.
594 * Based on code from:
595 * http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/008786.html
598 _mesa_float_to_half(float val
)
600 const int flt
= *((int *) (void *) &val
);
601 const int flt_m
= flt
& 0x7fffff;
602 const int flt_e
= (flt
>> 23) & 0xff;
603 const int flt_s
= (flt
>> 31) & 0x1;
610 /* handle special cases */
611 if ((flt_e
== 0) && (flt_m
== 0)) {
613 /* m = 0; - already set */
616 else if ((flt_e
== 0) && (flt_m
!= 0)) {
617 /* denorm -- denorm float maps to 0 half */
618 /* m = 0; - already set */
621 else if ((flt_e
== 0xff) && (flt_m
== 0)) {
623 /* m = 0; - already set */
626 else if ((flt_e
== 0xff) && (flt_m
!= 0)) {
633 const int new_exp
= flt_e
- 127;
636 /* m = 0; - already set */
639 else if (new_exp
< -14) {
640 /* this maps to a denorm */
641 unsigned int exp_val
= (unsigned int) (-14 - new_exp
); /* 2^-exp_val*/
646 "float_to_half: logical error in denorm creation!\n");
647 /* m = 0; - already set */
649 case 1: m
= 512 + (flt_m
>> 14); break;
650 case 2: m
= 256 + (flt_m
>> 15); break;
651 case 3: m
= 128 + (flt_m
>> 16); break;
652 case 4: m
= 64 + (flt_m
>> 17); break;
653 case 5: m
= 32 + (flt_m
>> 18); break;
654 case 6: m
= 16 + (flt_m
>> 19); break;
655 case 7: m
= 8 + (flt_m
>> 20); break;
656 case 8: m
= 4 + (flt_m
>> 21); break;
657 case 9: m
= 2 + (flt_m
>> 22); break;
658 case 10: m
= 1; break;
661 else if (new_exp
> 15) {
662 /* map this value to infinity */
663 /* m = 0; - already set */
673 result
= (s
<< 15) | (e
<< 10) | m
;
679 * Convert a 2-byte half float to a 4-byte float.
680 * Based on code from:
681 * http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/008786.html
684 _mesa_half_to_float(GLhalfARB val
)
686 /* XXX could also use a 64K-entry lookup table */
687 const int m
= val
& 0x3ff;
688 const int e
= (val
>> 10) & 0x1f;
689 const int s
= (val
>> 15) & 0x1;
690 int flt_m
, flt_e
, flt_s
, flt
;
696 /* handle special cases */
697 if ((e
== 0) && (m
== 0)) {
702 else if ((e
== 0) && (m
!= 0)) {
703 /* denorm -- denorm half will fit in non-denorm single */
704 const float half_denorm
= 1.0f
/ 16384.0f
; /* 2^-14 */
705 float mantissa
= ((float) (m
)) / 1024.0f
;
706 float sign
= s
? -1.0f
: 1.0f
;
707 return sign
* mantissa
* half_denorm
;
709 else if ((e
== 31) && (m
== 0)) {
714 else if ((e
== 31) && (m
!= 0)) {
725 flt
= (flt_s
<< 31) | (flt_e
<< 23) | flt_m
;
726 result
= *((float *) (void *) &flt
);
733 /**********************************************************************/
734 /** \name Sort & Search */
738 * Wrapper for bsearch().
741 _mesa_bsearch( const void *key
, const void *base
, size_t nmemb
, size_t size
,
742 int (*compar
)(const void *, const void *) )
744 return bsearch(key
, base
, nmemb
, size
, compar
);
750 /**********************************************************************/
751 /** \name Environment vars */
755 * Wrapper for getenv().
758 _mesa_getenv( const char *var
)
770 /**********************************************************************/
774 /** Wrapper around strstr() */
776 _mesa_strstr( const char *haystack
, const char *needle
)
778 return strstr(haystack
, needle
);
781 /** Wrapper around strncat() */
783 _mesa_strncat( char *dest
, const char *src
, size_t n
)
785 return strncat(dest
, src
, n
);
788 /** Wrapper around strcpy() */
790 _mesa_strcpy( char *dest
, const char *src
)
792 return strcpy(dest
, src
);
795 /** Wrapper around strncpy() */
797 _mesa_strncpy( char *dest
, const char *src
, size_t n
)
799 return strncpy(dest
, src
, n
);
802 /** Wrapper around strlen() */
804 _mesa_strlen( const char *s
)
809 /** Wrapper around strcmp() */
811 _mesa_strcmp( const char *s1
, const char *s2
)
813 return strcmp(s1
, s2
);
816 /** Wrapper around strncmp() */
818 _mesa_strncmp( const char *s1
, const char *s2
, size_t n
)
820 return strncmp(s1
, s2
, n
);
823 /** Implemented using _mesa_malloc() and _mesa_strcpy */
825 _mesa_strdup( const char *s
)
827 size_t l
= _mesa_strlen(s
);
828 char *s2
= (char *) _mesa_malloc(l
+ 1);
834 /** Wrapper around atoi() */
836 _mesa_atoi(const char *s
)
841 /** Wrapper around strtod() */
843 _mesa_strtod( const char *s
, char **end
)
845 return strtod(s
, end
);
851 /**********************************************************************/
855 /** Wrapper around vsprintf() */
857 _mesa_sprintf( char *str
, const char *fmt
, ... )
861 va_start( args
, fmt
);
862 r
= vsprintf( str
, fmt
, args
);
867 /** Wrapper around printf(), using vsprintf() for the formatting. */
869 _mesa_printf( const char *fmtString
, ... )
873 va_start( args
, fmtString
);
874 vsnprintf(s
, MAXSTRING
, fmtString
, args
);
876 fprintf(stderr
,"%s", s
);
879 /** Wrapper around vsprintf() */
881 _mesa_vsprintf( char *str
, const char *fmt
, va_list args
)
883 return vsprintf( str
, fmt
, args
);
889 /**********************************************************************/
890 /** \name Diagnostics */
896 * \param ctx GL context.
897 * \param fmtString printf() alike format string.
899 * If debugging is enabled (either at compile-time via the DEBUG macro, or
900 * run-time via the MESA_DEBUG environment variable), prints the warning to
901 * stderr via fprintf().
904 _mesa_warning( GLcontext
*ctx
, const char *fmtString
, ... )
910 va_start( args
, fmtString
);
911 (void) vsnprintf( str
, MAXSTRING
, fmtString
, args
);
914 debug
= GL_TRUE
; /* always print warning */
916 debug
= _mesa_getenv("MESA_DEBUG") ? GL_TRUE
: GL_FALSE
;
919 fprintf(stderr
, "Mesa warning: %s\n", str
);
924 * This function is called when the Mesa user has stumbled into a code
925 * path which may not be implemented fully or correctly.
927 * \param ctx GL context.
928 * \param s problem description string.
930 * Prints the message to stderr via fprintf().
933 _mesa_problem( const GLcontext
*ctx
, const char *fmtString
, ... )
939 va_start( args
, fmtString
);
940 vsnprintf( str
, MAXSTRING
, fmtString
, args
);
943 fprintf(stderr
, "Mesa %s implementation error: %s\n", MESA_VERSION_STRING
, str
);
944 fprintf(stderr
, "Please report at bugzilla.freedesktop.org\n");
948 * Display an error message.
950 * If in debug mode, print error message.
951 * Also, record the error code by calling _mesa_record_error().
953 * \param ctx the GL context.
954 * \param error the error value.
955 * \param fmtString printf() style format string, followed by optional args
957 * If debugging is enabled (either at compile-time via the DEBUG macro, or
958 * run-time via the MESA_DEBUG environment variable), interperts the error code and
959 * prints the error message via _mesa_debug().
962 _mesa_error( GLcontext
*ctx
, GLenum error
, const char *fmtString
, ... )
964 const char *debugEnv
;
967 debugEnv
= _mesa_getenv("MESA_DEBUG");
970 if (debugEnv
&& _mesa_strstr(debugEnv
, "silent"))
983 char where
[MAXSTRING
];
986 va_start( args
, fmtString
);
987 vsnprintf( where
, MAXSTRING
, fmtString
, args
);
992 errstr
= "GL_NO_ERROR";
994 case GL_INVALID_VALUE
:
995 errstr
= "GL_INVALID_VALUE";
997 case GL_INVALID_ENUM
:
998 errstr
= "GL_INVALID_ENUM";
1000 case GL_INVALID_OPERATION
:
1001 errstr
= "GL_INVALID_OPERATION";
1003 case GL_STACK_OVERFLOW
:
1004 errstr
= "GL_STACK_OVERFLOW";
1006 case GL_STACK_UNDERFLOW
:
1007 errstr
= "GL_STACK_UNDERFLOW";
1009 case GL_OUT_OF_MEMORY
:
1010 errstr
= "GL_OUT_OF_MEMORY";
1012 case GL_TABLE_TOO_LARGE
:
1013 errstr
= "GL_TABLE_TOO_LARGE";
1015 case GL_INVALID_FRAMEBUFFER_OPERATION_EXT
:
1016 errstr
= "GL_INVALID_FRAMEBUFFER_OPERATION";
1022 _mesa_debug(ctx
, "User error: %s in %s\n", errstr
, where
);
1025 _mesa_record_error(ctx
, error
);
1029 * Report debug information.
1031 * \param ctx GL context.
1032 * \param fmtString printf() alike format string.
1034 * Prints the message to stderr via fprintf().
1037 _mesa_debug( const GLcontext
*ctx
, const char *fmtString
, ... )
1042 va_start(args
, fmtString
);
1043 vsnprintf(s
, MAXSTRING
, fmtString
, args
);
1045 fprintf(stderr
, "Mesa: %s", s
);
1054 /**********************************************************************/
1059 * Wrapper for exit().
1062 _mesa_exit( int status
)
1070 /**********************************************************************/
1071 /** \name Default Imports Wrapper */
1074 /** Wrapper around _mesa_malloc() */
1076 default_malloc(__GLcontext
*gc
, size_t size
)
1079 return _mesa_malloc(size
);
1082 /** Wrapper around _mesa_malloc() */
1084 default_calloc(__GLcontext
*gc
, size_t numElem
, size_t elemSize
)
1087 return _mesa_calloc(numElem
* elemSize
);
1090 /** Wrapper around realloc() */
1092 default_realloc(__GLcontext
*gc
, void *oldAddr
, size_t newSize
)
1095 return realloc(oldAddr
, newSize
);
1098 /** Wrapper around _mesa_free() */
1100 default_free(__GLcontext
*gc
, void *addr
)
1106 /** Wrapper around _mesa_getenv() */
1108 default_getenv( __GLcontext
*gc
, const char *var
)
1111 return _mesa_getenv(var
);
1114 /** Wrapper around _mesa_warning() */
1116 default_warning(__GLcontext
*gc
, char *str
)
1118 _mesa_warning(gc
, str
);
1121 /** Wrapper around _mesa_problem() */
1123 default_fatal(__GLcontext
*gc
, char *str
)
1125 _mesa_problem(gc
, str
);
1129 /** Wrapper around atoi() */
1131 default_atoi(__GLcontext
*gc
, const char *str
)
1137 /** Wrapper around vsprintf() */
1139 default_sprintf(__GLcontext
*gc
, char *str
, const char *fmt
, ...)
1144 va_start( args
, fmt
);
1145 r
= vsprintf( str
, fmt
, args
);
1150 /** Wrapper around fopen() */
1152 default_fopen(__GLcontext
*gc
, const char *path
, const char *mode
)
1155 return fopen(path
, mode
);
1158 /** Wrapper around fclose() */
1160 default_fclose(__GLcontext
*gc
, void *stream
)
1163 return fclose((FILE *) stream
);
1166 /** Wrapper around vfprintf() */
1168 default_fprintf(__GLcontext
*gc
, void *stream
, const char *fmt
, ...)
1173 va_start( args
, fmt
);
1174 r
= vfprintf( (FILE *) stream
, fmt
, args
);
1180 * \todo this really is driver-specific and can't be here
1182 static __GLdrawablePrivate
*
1183 default_GetDrawablePrivate(__GLcontext
*gc
)
1193 * Initialize a __GLimports object to point to the functions in this
1196 * This is to be called from device drivers.
1198 * Also, do some one-time initializations.
1200 * \param imports the object to initialize.
1201 * \param driverCtx pointer to device driver-specific data.
1204 _mesa_init_default_imports(__GLimports
*imports
, void *driverCtx
)
1206 /* XXX maybe move this one-time init stuff into context.c */
1207 static GLboolean initialized
= GL_FALSE
;
1210 initialized
= GL_TRUE
;
1213 imports
->malloc
= default_malloc
;
1214 imports
->calloc
= default_calloc
;
1215 imports
->realloc
= default_realloc
;
1216 imports
->free
= default_free
;
1217 imports
->warning
= default_warning
;
1218 imports
->fatal
= default_fatal
;
1219 imports
->getenv
= default_getenv
; /* not used for now */
1220 imports
->atoi
= default_atoi
;
1221 imports
->sprintf
= default_sprintf
;
1222 imports
->fopen
= default_fopen
;
1223 imports
->fclose
= default_fclose
;
1224 imports
->fprintf
= default_fprintf
;
1225 imports
->getDrawablePrivate
= default_GetDrawablePrivate
;
1226 imports
->other
= driverCtx
;