3
* Mesa 3-D graphics library
6
* Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
15
* The above copyright notice and this permission notice shall be included
16
* in all copies or substantial portions of the Software.
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.
26
* Gareth Hughes <gareth@valinux.com>
29
/* Template for immediate mode color functions.
31
* FIXME: Floating-point color versions of these...
35
static void TAG(Color3f)( GLfloat r, GLfloat g, GLfloat b )
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;
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;
51
static void TAG(Color3fv)( const GLfloat *v )
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;
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;
67
static void TAG(Color3ub)( GLubyte r, GLubyte g, GLubyte b )
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;
76
CURRENT_COLOR( RCOMP ) = r;
77
CURRENT_COLOR( GCOMP ) = g;
78
CURRENT_COLOR( BCOMP ) = b;
79
CURRENT_COLOR( ACOMP ) = 255;
83
static void TAG(Color3ubv)( const GLubyte *v )
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;
92
CURRENT_COLOR( RCOMP ) = v[0];
93
CURRENT_COLOR( GCOMP ) = v[1];
94
CURRENT_COLOR( BCOMP ) = v[2];
95
CURRENT_COLOR( ACOMP ) = 255;
99
static void TAG(Color4f)( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
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);
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 );
115
static void TAG(Color4fv)( const GLfloat *v )
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);
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] );
131
static void TAG(Color4ub)( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
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 );
140
CURRENT_COLOR( RCOMP ) = r;
141
CURRENT_COLOR( GCOMP ) = g;
142
CURRENT_COLOR( BCOMP ) = b;
143
CURRENT_COLOR( ACOMP ) = a;
147
static void TAG(Color4ubv)( const GLubyte *v )
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] );
156
CURRENT_COLOR( RCOMP ) = v[0];
157
CURRENT_COLOR( GCOMP ) = v[1];
158
CURRENT_COLOR( BCOMP ) = v[2];
159
CURRENT_COLOR( ACOMP ) = v[3];
164
static void TAG(ColorMaterial3f)( GLfloat r, GLfloat g, GLfloat b )
166
GET_CURRENT_CONTEXT(ctx);
167
GLfloat *color = ctx->Current.Color;
174
_mesa_update_color_material( ctx, color );
175
RECALC_BASE_COLOR( ctx );
178
static void TAG(ColorMaterial3fv)( const GLfloat *v )
180
GET_CURRENT_CONTEXT(ctx);
181
GLfloat *color = ctx->Current.Color;
188
_mesa_update_color_material( ctx, color );
189
RECALC_BASE_COLOR( ctx );
192
static void TAG(ColorMaterial3ub)( GLubyte r, GLubyte g, GLubyte b )
194
GET_CURRENT_CONTEXT(ctx);
195
GLfloat *color = ctx->Current.Color;
197
color[0] = UBYTE_TO_FLOAT( r );
198
color[1] = UBYTE_TO_FLOAT( g );
199
color[2] = UBYTE_TO_FLOAT( b );
202
_mesa_update_color_material( ctx, color );
203
RECALC_BASE_COLOR( ctx );
206
static void TAG(ColorMaterial3ubv)( const GLubyte *v )
208
GET_CURRENT_CONTEXT(ctx);
209
GLfloat *color = ctx->Current.Color;
211
color[0] = UBYTE_TO_FLOAT( v[0] );
212
color[1] = UBYTE_TO_FLOAT( v[1] );
213
color[2] = UBYTE_TO_FLOAT( v[2] );
216
_mesa_update_color_material( ctx, color );
217
RECALC_BASE_COLOR( ctx );
220
static void TAG(ColorMaterial4f)( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
222
GET_CURRENT_CONTEXT(ctx);
223
GLfloat *color = ctx->Current.Color;
230
_mesa_update_color_material( ctx, color );
231
RECALC_BASE_COLOR( ctx );
234
static void TAG(ColorMaterial4fv)( const GLfloat *v )
236
GET_CURRENT_CONTEXT(ctx);
237
GLfloat *color = ctx->Current.Color;
244
_mesa_update_color_material( ctx, color );
245
RECALC_BASE_COLOR( ctx );
248
static void TAG(ColorMaterial4ub)( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
250
GET_CURRENT_CONTEXT(ctx);
251
GLfloat *color = ctx->Current.Color;
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 );
258
_mesa_update_color_material( ctx, color );
259
RECALC_BASE_COLOR( ctx );
262
static void TAG(ColorMaterial4ubv)( const GLubyte *v )
264
GET_CURRENT_CONTEXT(ctx);
265
GLfloat *color = ctx->Current.Color;
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] );
272
_mesa_update_color_material( ctx, color );
273
RECALC_BASE_COLOR( ctx );
280
/* =============================================================
281
* Color chooser functions:
284
static void TAG(choose_Color3f)( GLfloat r, GLfloat g, GLfloat b )
286
GET_CURRENT_CONTEXT(ctx);
288
if ( ctx->Light.Enabled ) {
289
if ( ctx->Light.ColorMaterialEnabled ) {
290
SET_Color3f(ctx->Exec, TAG(ColorMaterial3f));
292
SET_Color3f(ctx->Exec, _mesa_noop_Color3f);
295
SET_Color3f(ctx->Exec, TAG(Color3f));
297
glColor3f( r, g, b );
300
static void TAG(choose_Color3fv)( const GLfloat *v )
302
GET_CURRENT_CONTEXT(ctx);
304
if ( ctx->Light.Enabled ) {
305
if ( ctx->Light.ColorMaterialEnabled ) {
306
SET_Color3fv(ctx->Exec, TAG(ColorMaterial3fv));
308
SET_Color3fv(ctx->Exec, _mesa_noop_Color3fv);
311
SET_Color3fv(ctx->Exec, TAG(Color3fv));
316
static void TAG(choose_Color3ub)( GLubyte r, GLubyte g, GLubyte b )
318
GET_CURRENT_CONTEXT(ctx);
320
if ( ctx->Light.Enabled ) {
321
if ( ctx->Light.ColorMaterialEnabled ) {
322
SET_Color3ub(ctx->Exec, TAG(ColorMaterial3ub));
324
SET_Color3ub(ctx->Exec, _mesa_noop_Color3ub);
327
SET_Color3ub(ctx->Exec, TAG(Color3ub));
329
glColor3ub( r, g, b );
332
static void TAG(choose_Color3ubv)( const GLubyte *v )
334
GET_CURRENT_CONTEXT(ctx);
336
if ( ctx->Light.Enabled ) {
337
if ( ctx->Light.ColorMaterialEnabled ) {
338
SET_Color3ubv(ctx->Exec, TAG(ColorMaterial3ubv));
340
SET_Color3ubv(ctx->Exec, _mesa_noop_Color3ubv);
343
SET_Color3ubv(ctx->Exec, TAG(Color3ubv));
348
static void TAG(choose_Color4f)( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
350
GET_CURRENT_CONTEXT(ctx);
352
if ( ctx->Light.Enabled ) {
353
if ( ctx->Light.ColorMaterialEnabled ) {
354
SET_Color4f(ctx->Exec, TAG(ColorMaterial4f));
356
SET_Color4f(ctx->Exec, _mesa_noop_Color4f);
359
SET_Color4f(ctx->Exec, TAG(Color4f));
361
glColor4f( r, g, b, a );
364
static void TAG(choose_Color4fv)( const GLfloat *v )
366
GET_CURRENT_CONTEXT(ctx);
368
if ( ctx->Light.Enabled ) {
369
if ( ctx->Light.ColorMaterialEnabled ) {
370
SET_Color4fv(ctx->Exec, TAG(ColorMaterial4fv));
372
SET_Color4fv(ctx->Exec, _mesa_noop_Color4fv);
375
SET_Color4fv(ctx->Exec, TAG(Color4fv));
380
static void TAG(choose_Color4ub)( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
382
GET_CURRENT_CONTEXT(ctx);
384
if ( ctx->Light.Enabled ) {
385
if ( ctx->Light.ColorMaterialEnabled ) {
386
SET_Color4ub(ctx->Exec, TAG(ColorMaterial4ub));
388
SET_Color4ub(ctx->Exec, _mesa_noop_Color4ub);
391
SET_Color4ub(ctx->Exec, TAG(Color4ub));
393
glColor4ub( r, g, b, a );
396
static void TAG(choose_Color4ubv)( const GLubyte *v )
398
GET_CURRENT_CONTEXT(ctx);
400
if ( ctx->Light.Enabled ) {
401
if ( ctx->Light.ColorMaterialEnabled ) {
402
SET_Color4ubv(ctx->Exec, TAG(ColorMaterial4ubv));
404
SET_Color4ubv(ctx->Exec, _mesa_noop_Color4ubv);
407
SET_Color4ubv(ctx->Exec, TAG(Color4ubv));
416
#undef CURRENT_SPECULAR
417
#undef COLOR_IS_FLOAT
418
#undef RECALC_BASE_COLOR