patch to import Jon Smirl's work from Bitkeeper
[mesa.git] / src / mesa / tnl_dd / imm / t_dd_imm_capi.h
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 3.5
5 *
6 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Gareth Hughes <gareth@valinux.com>
27 */
28
29 /* Template for immediate mode color functions.
30 *
31 * FIXME: Floating-point color versions of these...
32 */
33
34
35 static void TAG(Color3f)( GLfloat r, GLfloat g, GLfloat b )
36 {
37 GET_CURRENT;
38 #ifdef COLOR_IS_FLOAT
39 CURRENT_COLOR( RCOMP ) = CLAMP(r, 0.0f, 1.0f);
40 CURRENT_COLOR( GCOMP ) = CLAMP(g, 0.0f, 1.0f);
41 CURRENT_COLOR( BCOMP ) = CLAMP(b, 0.0f, 1.0f);
42 CURRENT_COLOR( ACOMP ) = 1.0f;
43 #else
44 UNCLAMPED_FLOAT_TO_UBYTE( CURRENT_COLOR( RCOMP ), r );
45 UNCLAMPED_FLOAT_TO_UBYTE( CURRENT_COLOR( GCOMP ), g );
46 UNCLAMPED_FLOAT_TO_UBYTE( CURRENT_COLOR( BCOMP ), b );
47 CURRENT_COLOR( ACOMP ) = 255;
48 #endif
49 }
50
51 static void TAG(Color3fv)( const GLfloat *v )
52 {
53 GET_CURRENT;
54 #ifdef COLOR_IS_FLOAT
55 CURRENT_COLOR( RCOMP ) = CLAMP(v[0], 0.0f, 1.0f);
56 CURRENT_COLOR( GCOMP ) = CLAMP(v[1], 0.0f, 1.0f);
57 CURRENT_COLOR( BCOMP ) = CLAMP(v[2], 0.0f, 1.0f);
58 CURRENT_COLOR( ACOMP ) = 1.0f;
59 #else
60 UNCLAMPED_FLOAT_TO_UBYTE( CURRENT_COLOR( RCOMP ), v[0] );
61 UNCLAMPED_FLOAT_TO_UBYTE( CURRENT_COLOR( GCOMP ), v[1] );
62 UNCLAMPED_FLOAT_TO_UBYTE( CURRENT_COLOR( BCOMP ), v[2] );
63 CURRENT_COLOR( ACOMP ) = 255;
64 #endif
65 }
66
67 static void TAG(Color3ub)( GLubyte r, GLubyte g, GLubyte b )
68 {
69 GET_CURRENT;
70 #ifdef COLOR_IS_FLOAT
71 CURRENT_COLOR( RCOMP ) = UBYTE_TO_FLOAT( r );
72 CURRENT_COLOR( GCOMP ) = UBYTE_TO_FLOAT( g );
73 CURRENT_COLOR( BCOMP ) = UBYTE_TO_FLOAT( b );
74 CURRENT_COLOR( ACOMP ) = 1.0f;
75 #else
76 CURRENT_COLOR( RCOMP ) = r;
77 CURRENT_COLOR( GCOMP ) = g;
78 CURRENT_COLOR( BCOMP ) = b;
79 CURRENT_COLOR( ACOMP ) = 255;
80 #endif
81 }
82
83 static void TAG(Color3ubv)( const GLubyte *v )
84 {
85 GET_CURRENT;
86 #ifdef COLOR_IS_FLOAT
87 CURRENT_COLOR( RCOMP ) = UBYTE_TO_FLOAT( v[0] );
88 CURRENT_COLOR( GCOMP ) = UBYTE_TO_FLOAT( v[1] );
89 CURRENT_COLOR( BCOMP ) = UBYTE_TO_FLOAT( v[2] );
90 CURRENT_COLOR( ACOMP ) = 1.0f;
91 #else
92 CURRENT_COLOR( RCOMP ) = v[0];
93 CURRENT_COLOR( GCOMP ) = v[1];
94 CURRENT_COLOR( BCOMP ) = v[2];
95 CURRENT_COLOR( ACOMP ) = 255;
96 #endif
97 }
98
99 static void TAG(Color4f)( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
100 {
101 GET_CURRENT;
102 #ifdef COLOR_IS_FLOAT
103 CURRENT_COLOR( RCOMP ) = CLAMP(r, 0.0f, 1.0f);
104 CURRENT_COLOR( GCOMP ) = CLAMP(g, 0.0f, 1.0f);
105 CURRENT_COLOR( BCOMP ) = CLAMP(b, 0.0f, 1.0f);
106 CURRENT_COLOR( ACOMP ) = CLAMP(a, 0.0f, 1.0f);
107 #else
108 UNCLAMPED_FLOAT_TO_UBYTE( CURRENT_COLOR( RCOMP ), r );
109 UNCLAMPED_FLOAT_TO_UBYTE( CURRENT_COLOR( GCOMP ), g );
110 UNCLAMPED_FLOAT_TO_UBYTE( CURRENT_COLOR( BCOMP ), b );
111 UNCLAMPED_FLOAT_TO_UBYTE( CURRENT_COLOR( ACOMP ), a );
112 #endif
113 }
114
115 static void TAG(Color4fv)( const GLfloat *v )
116 {
117 GET_CURRENT;
118 #ifdef COLOR_IS_FLOAT
119 CURRENT_COLOR( RCOMP ) = CLAMP(v[0], 0.0f, 1.0f);
120 CURRENT_COLOR( GCOMP ) = CLAMP(v[1], 0.0f, 1.0f);
121 CURRENT_COLOR( BCOMP ) = CLAMP(v[2], 0.0f, 1.0f);
122 CURRENT_COLOR( ACOMP ) = CLAMP(v[3], 0.0f, 1.0f);
123 #else
124 UNCLAMPED_FLOAT_TO_UBYTE( CURRENT_COLOR( RCOMP ), v[0] );
125 UNCLAMPED_FLOAT_TO_UBYTE( CURRENT_COLOR( GCOMP ), v[1] );
126 UNCLAMPED_FLOAT_TO_UBYTE( CURRENT_COLOR( BCOMP ), v[2] );
127 UNCLAMPED_FLOAT_TO_UBYTE( CURRENT_COLOR( ACOMP ), v[3] );
128 #endif
129 }
130
131 static void TAG(Color4ub)( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
132 {
133 GET_CURRENT;
134 #ifdef COLOR_IS_FLOAT
135 CURRENT_COLOR( RCOMP ) = UBYTE_TO_FLOAT( r );
136 CURRENT_COLOR( GCOMP ) = UBYTE_TO_FLOAT( g );
137 CURRENT_COLOR( BCOMP ) = UBYTE_TO_FLOAT( b );
138 CURRENT_COLOR( ACOMP ) = UBYTE_TO_FLOAT( a );
139 #else
140 CURRENT_COLOR( RCOMP ) = r;
141 CURRENT_COLOR( GCOMP ) = g;
142 CURRENT_COLOR( BCOMP ) = b;
143 CURRENT_COLOR( ACOMP ) = a;
144 #endif
145 }
146
147 static void TAG(Color4ubv)( const GLubyte *v )
148 {
149 GET_CURRENT;
150 #ifdef COLOR_IS_FLOAT
151 CURRENT_COLOR( RCOMP ) = UBYTE_TO_FLOAT( v[0] );
152 CURRENT_COLOR( GCOMP ) = UBYTE_TO_FLOAT( v[1] );
153 CURRENT_COLOR( BCOMP ) = UBYTE_TO_FLOAT( v[2] );
154 CURRENT_COLOR( ACOMP ) = UBYTE_TO_FLOAT( v[3] );
155 #else
156 CURRENT_COLOR( RCOMP ) = v[0];
157 CURRENT_COLOR( GCOMP ) = v[1];
158 CURRENT_COLOR( BCOMP ) = v[2];
159 CURRENT_COLOR( ACOMP ) = v[3];
160 #endif
161 }
162
163
164 static void TAG(ColorMaterial3f)( GLfloat r, GLfloat g, GLfloat b )
165 {
166 GET_CURRENT_CONTEXT(ctx);
167 GLfloat *color = ctx->Current.Color;
168
169 color[0] = r;
170 color[1] = g;
171 color[2] = b;
172 color[3] = 1.0;
173
174 _mesa_update_color_material( ctx, color );
175 RECALC_BASE_COLOR( ctx );
176 }
177
178 static void TAG(ColorMaterial3fv)( const GLfloat *v )
179 {
180 GET_CURRENT_CONTEXT(ctx);
181 GLfloat *color = ctx->Current.Color;
182
183 color[0] = v[0];
184 color[1] = v[1];
185 color[2] = v[2];
186 color[3] = 1.0;
187
188 _mesa_update_color_material( ctx, color );
189 RECALC_BASE_COLOR( ctx );
190 }
191
192 static void TAG(ColorMaterial3ub)( GLubyte r, GLubyte g, GLubyte b )
193 {
194 GET_CURRENT_CONTEXT(ctx);
195 GLfloat *color = ctx->Current.Color;
196
197 color[0] = UBYTE_TO_FLOAT( r );
198 color[1] = UBYTE_TO_FLOAT( g );
199 color[2] = UBYTE_TO_FLOAT( b );
200 color[3] = 1.0;
201
202 _mesa_update_color_material( ctx, color );
203 RECALC_BASE_COLOR( ctx );
204 }
205
206 static void TAG(ColorMaterial3ubv)( const GLubyte *v )
207 {
208 GET_CURRENT_CONTEXT(ctx);
209 GLfloat *color = ctx->Current.Color;
210
211 color[0] = UBYTE_TO_FLOAT( v[0] );
212 color[1] = UBYTE_TO_FLOAT( v[1] );
213 color[2] = UBYTE_TO_FLOAT( v[2] );
214 color[3] = 1.0;
215
216 _mesa_update_color_material( ctx, color );
217 RECALC_BASE_COLOR( ctx );
218 }
219
220 static void TAG(ColorMaterial4f)( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
221 {
222 GET_CURRENT_CONTEXT(ctx);
223 GLfloat *color = ctx->Current.Color;
224
225 color[0] = r;
226 color[1] = g;
227 color[2] = b;
228 color[3] = a;
229
230 _mesa_update_color_material( ctx, color );
231 RECALC_BASE_COLOR( ctx );
232 }
233
234 static void TAG(ColorMaterial4fv)( const GLfloat *v )
235 {
236 GET_CURRENT_CONTEXT(ctx);
237 GLfloat *color = ctx->Current.Color;
238
239 color[0] = v[0];
240 color[1] = v[1];
241 color[2] = v[2];
242 color[3] = v[3];
243
244 _mesa_update_color_material( ctx, color );
245 RECALC_BASE_COLOR( ctx );
246 }
247
248 static void TAG(ColorMaterial4ub)( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
249 {
250 GET_CURRENT_CONTEXT(ctx);
251 GLfloat *color = ctx->Current.Color;
252
253 color[0] = UBYTE_TO_FLOAT( r );
254 color[1] = UBYTE_TO_FLOAT( g );
255 color[2] = UBYTE_TO_FLOAT( b );
256 color[3] = UBYTE_TO_FLOAT( a );
257
258 _mesa_update_color_material( ctx, color );
259 RECALC_BASE_COLOR( ctx );
260 }
261
262 static void TAG(ColorMaterial4ubv)( const GLubyte *v )
263 {
264 GET_CURRENT_CONTEXT(ctx);
265 GLfloat *color = ctx->Current.Color;
266
267 color[0] = UBYTE_TO_FLOAT( v[0] );
268 color[1] = UBYTE_TO_FLOAT( v[1] );
269 color[2] = UBYTE_TO_FLOAT( v[2] );
270 color[3] = UBYTE_TO_FLOAT( v[3] );
271
272 _mesa_update_color_material( ctx, color );
273 RECALC_BASE_COLOR( ctx );
274 }
275
276
277
278
279
280 /* =============================================================
281 * Color chooser functions:
282 */
283
284 static void TAG(choose_Color3f)( GLfloat r, GLfloat g, GLfloat b )
285 {
286 GET_CURRENT_CONTEXT(ctx);
287
288 if ( ctx->Light.Enabled ) {
289 if ( ctx->Light.ColorMaterialEnabled ) {
290 ctx->Exec->Color3f = TAG(ColorMaterial3f);
291 } else {
292 ctx->Exec->Color3f = _mesa_noop_Color3f;
293 }
294 } else {
295 ctx->Exec->Color3f = TAG(Color3f);
296 }
297 glColor3f( r, g, b );
298 }
299
300 static void TAG(choose_Color3fv)( const GLfloat *v )
301 {
302 GET_CURRENT_CONTEXT(ctx);
303
304 if ( ctx->Light.Enabled ) {
305 if ( ctx->Light.ColorMaterialEnabled ) {
306 ctx->Exec->Color3fv = TAG(ColorMaterial3fv);
307 } else {
308 ctx->Exec->Color3fv = _mesa_noop_Color3fv;
309 }
310 } else {
311 ctx->Exec->Color3fv = TAG(Color3fv);
312 }
313 glColor3fv( v );
314 }
315
316 static void TAG(choose_Color3ub)( GLubyte r, GLubyte g, GLubyte b )
317 {
318 GET_CURRENT_CONTEXT(ctx);
319
320 if ( ctx->Light.Enabled ) {
321 if ( ctx->Light.ColorMaterialEnabled ) {
322 ctx->Exec->Color3ub = TAG(ColorMaterial3ub);
323 } else {
324 ctx->Exec->Color3ub = _mesa_noop_Color3ub;
325 }
326 } else {
327 ctx->Exec->Color3ub = TAG(Color3ub);
328 }
329 glColor3ub( r, g, b );
330 }
331
332 static void TAG(choose_Color3ubv)( const GLubyte *v )
333 {
334 GET_CURRENT_CONTEXT(ctx);
335
336 if ( ctx->Light.Enabled ) {
337 if ( ctx->Light.ColorMaterialEnabled ) {
338 ctx->Exec->Color3ubv = TAG(ColorMaterial3ubv);
339 } else {
340 ctx->Exec->Color3ubv = _mesa_noop_Color3ubv;
341 }
342 } else {
343 ctx->Exec->Color3ubv = TAG(Color3ubv);
344 }
345 glColor3ubv( v );
346 }
347
348 static void TAG(choose_Color4f)( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
349 {
350 GET_CURRENT_CONTEXT(ctx);
351
352 if ( ctx->Light.Enabled ) {
353 if ( ctx->Light.ColorMaterialEnabled ) {
354 ctx->Exec->Color4f = TAG(ColorMaterial4f);
355 } else {
356 ctx->Exec->Color4f = _mesa_noop_Color4f;
357 }
358 } else {
359 ctx->Exec->Color4f = TAG(Color4f);
360 }
361 glColor4f( r, g, b, a );
362 }
363
364 static void TAG(choose_Color4fv)( const GLfloat *v )
365 {
366 GET_CURRENT_CONTEXT(ctx);
367
368 if ( ctx->Light.Enabled ) {
369 if ( ctx->Light.ColorMaterialEnabled ) {
370 ctx->Exec->Color4fv = TAG(ColorMaterial4fv);
371 } else {
372 ctx->Exec->Color4fv = _mesa_noop_Color4fv;
373 }
374 } else {
375 ctx->Exec->Color4fv = TAG(Color4fv);
376 }
377 glColor4fv( v );
378 }
379
380 static void TAG(choose_Color4ub)( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
381 {
382 GET_CURRENT_CONTEXT(ctx);
383
384 if ( ctx->Light.Enabled ) {
385 if ( ctx->Light.ColorMaterialEnabled ) {
386 ctx->Exec->Color4ub = TAG(ColorMaterial4ub);
387 } else {
388 ctx->Exec->Color4ub = _mesa_noop_Color4ub;
389 }
390 } else {
391 ctx->Exec->Color4ub = TAG(Color4ub);
392 }
393 glColor4ub( r, g, b, a );
394 }
395
396 static void TAG(choose_Color4ubv)( const GLubyte *v )
397 {
398 GET_CURRENT_CONTEXT(ctx);
399
400 if ( ctx->Light.Enabled ) {
401 if ( ctx->Light.ColorMaterialEnabled ) {
402 ctx->Exec->Color4ubv = TAG(ColorMaterial4ubv);
403 } else {
404 ctx->Exec->Color4ubv = _mesa_noop_Color4ubv;
405 }
406 } else {
407 ctx->Exec->Color4ubv = TAG(Color4ubv);
408 }
409 glColor4ubv( v );
410 }
411
412
413
414 #undef GET_CURRENT
415 #undef CURRENT_COLOR
416 #undef CURRENT_SPECULAR
417 #undef COLOR_IS_FLOAT
418 #undef RECALC_BASE_COLOR
419 #undef TAG