Cleanup of derived state calculation prior to seperating software T&L
[mesa.git] / src / mesa / main / imports.c
1 /* $Id: imports.c,v 1.2 2000/09/27 03:30:49 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2000 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 /*
29 * Imports are functions which the device driver or window system or
30 * operating system provides to the core renderer. The core renderer (Mesa)
31 * will call these functions in order to do memory allocation, simple I/O,
32 * etc.
33 *
34 * Some drivers will need to implement these functions themselves but
35 * many (most?) Mesa drivers will be fine using these.
36 *
37 * A server-side GL renderer will likely not use these functions since
38 * the renderer should use the XFree86-wrapped system calls.
39 */
40
41
42 #include "glheader.h"
43 #include "imports.h"
44 #include "mem.h"
45 #include "types.h"
46
47
48 static void *
49 _mesa_Malloc(__GLcontext *gc, size_t size)
50 {
51 return MALLOC(size);
52 }
53
54 static void *
55 _mesa_Calloc(__GLcontext *gc, size_t numElem, size_t elemSize)
56 {
57 return CALLOC(numElem * elemSize);
58 }
59
60 static void *
61 _mesa_Realloc(__GLcontext *gc, void *oldAddr, size_t newSize)
62 {
63 return realloc(oldAddr, newSize);
64 }
65
66 static void
67 _mesa_Free(__GLcontext *gc, void *addr)
68 {
69 FREE(addr);
70 }
71
72 static void
73 _mesa_warning(__GLcontext *gc, char *str)
74 {
75 GLboolean debug;
76 #ifdef DEBUG
77 debug = GL_TRUE;
78 #else
79 if (gc->imports.getenv(gc, "MESA_DEBUG")) {
80 debug = GL_TRUE;
81 }
82 else {
83 debug = GL_FALSE;
84 }
85 #endif
86 if (debug) {
87 fprintf(stderr, "Mesa warning: %s\n", str);
88 }
89 }
90
91 static void
92 _mesa_fatal(__GLcontext *gc, char *str)
93 {
94 fprintf(stderr, "%s\n", str);
95 abort();
96 }
97
98 static char *
99 _mesa_getenv(__GLcontext *gc, const char *var)
100 {
101 (void) gc;
102 return getenv(var);
103 }
104
105 static int
106 _mesa_atoi(__GLcontext *gc, const char *str)
107 {
108 (void) gc;
109 return atoi(str);
110 }
111
112 static int
113 _mesa_sprintf(__GLcontext *gc, char *str, const char *fmt, ...)
114 {
115 /* XXX fix this */
116 return sprintf(str, fmt);
117 }
118
119 static void *
120 _mesa_fopen(__GLcontext *gc, const char *path, const char *mode)
121 {
122 return fopen(path, mode);
123 }
124
125 static int
126 _mesa_fclose(__GLcontext *gc, void *stream)
127 {
128 return fclose(stream);
129 }
130
131 static int
132 _mesa_fprintf(__GLcontext *gc, void *stream, const char *fmt, ...)
133 {
134 /* XXX fix this */
135 return fprintf(stream, fmt);
136 }
137
138 /* XXX this really is driver-specific and can't be here */
139 static __GLdrawablePrivate *
140 _mesa_GetDrawablePrivate(__GLcontext *gc)
141 {
142 return NULL;
143 }
144
145
146 void
147 _mesa_InitDefaultImports(__GLimports *imports, void *driverCtx, void *other)
148 {
149 imports->malloc = _mesa_Malloc;
150 imports->calloc = _mesa_Calloc;
151 imports->realloc = _mesa_Realloc;
152 imports->free = _mesa_Free;
153 imports->warning = _mesa_warning;
154 imports->fatal = _mesa_fatal;
155 imports->getenv = _mesa_getenv;
156 imports->atoi = _mesa_atoi;
157 imports->sprintf = _mesa_sprintf;
158 imports->fopen = _mesa_fopen;
159 imports->fclose = _mesa_fclose;
160 imports->fprintf = _mesa_fprintf;
161 imports->getDrawablePrivate = _mesa_GetDrawablePrivate;
162 imports->wscx = driverCtx;
163 imports->other = other;
164 }