GL_INTENSITY case was incorrect in extract_float_rgba()
[mesa.git] / src / mesa / main / api_noop.c
1 /* $Id: api_noop.c,v 1.7 2001/03/20 18:35:23 gareth Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 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 #include "glheader.h"
29 #include "api_noop.h"
30 #include "api_validate.h"
31 #include "context.h"
32 #include "colormac.h"
33 #include "light.h"
34 #include "macros.h"
35 #include "mmath.h"
36 #include "mtypes.h"
37
38
39 /* In states where certain vertex components are required for t&l or
40 * rasterization, we still need to keep track of the current values.
41 * These functions provide this service by keeping uptodate the
42 * 'ctx->Current' struct for all data elements not included in the
43 * currently enabled hardware vertex.
44 *
45 */
46 void _mesa_noop_EdgeFlag( GLboolean b )
47 {
48 GET_CURRENT_CONTEXT(ctx);
49 ctx->Current.EdgeFlag = b;
50 }
51
52 void _mesa_noop_EdgeFlagv( const GLboolean *b )
53 {
54 GET_CURRENT_CONTEXT(ctx);
55 ctx->Current.EdgeFlag = *b;
56 }
57
58 void _mesa_noop_FogCoordfEXT( GLfloat a )
59 {
60 GET_CURRENT_CONTEXT(ctx);
61 ctx->Current.FogCoord = a;
62 }
63
64 void _mesa_noop_FogCoordfvEXT( const GLfloat *v )
65 {
66 GET_CURRENT_CONTEXT(ctx);
67 ctx->Current.FogCoord = *v;
68 }
69
70 void _mesa_noop_Indexi( GLint i )
71 {
72 GET_CURRENT_CONTEXT(ctx);
73 ctx->Current.Index = i;
74 }
75
76 void _mesa_noop_Indexiv( const GLint *v )
77 {
78 GET_CURRENT_CONTEXT(ctx);
79 ctx->Current.Index = *v;
80 }
81
82 void _mesa_noop_Normal3f( GLfloat a, GLfloat b, GLfloat c )
83 {
84 GET_CURRENT_CONTEXT(ctx);
85 GLfloat *dest = ctx->Current.Normal;
86 COPY_FLOAT(dest[0], a);
87 COPY_FLOAT(dest[1], b);
88 COPY_FLOAT(dest[2], c);
89 }
90
91 void _mesa_noop_Normal3fv( const GLfloat *v )
92 {
93 GET_CURRENT_CONTEXT(ctx);
94 GLfloat *dest = ctx->Current.Normal;
95 COPY_FLOAT(dest[0], v[0]);
96 COPY_FLOAT(dest[1], v[1]);
97 COPY_FLOAT(dest[2], v[2]);
98 }
99
100 void _mesa_noop_Materialfv( GLenum face, GLenum pname, const GLfloat *params )
101 {
102 GET_CURRENT_CONTEXT(ctx);
103 struct gl_material mat[2];
104 GLuint bitmask = _mesa_material_bitmask( ctx, face, pname, ~0,
105 "_mesa_noop_Materialfv" );
106 if (bitmask == 0)
107 return;
108
109 if (bitmask & FRONT_AMBIENT_BIT) {
110 COPY_4FV( mat[0].Ambient, params );
111 }
112 if (bitmask & BACK_AMBIENT_BIT) {
113 COPY_4FV( mat[1].Ambient, params );
114 }
115 if (bitmask & FRONT_DIFFUSE_BIT) {
116 COPY_4FV( mat[0].Diffuse, params );
117 }
118 if (bitmask & BACK_DIFFUSE_BIT) {
119 COPY_4FV( mat[1].Diffuse, params );
120 }
121 if (bitmask & FRONT_SPECULAR_BIT) {
122 COPY_4FV( mat[0].Specular, params );
123 }
124 if (bitmask & BACK_SPECULAR_BIT) {
125 COPY_4FV( mat[1].Specular, params );
126 }
127 if (bitmask & FRONT_EMISSION_BIT) {
128 COPY_4FV( mat[0].Emission, params );
129 }
130 if (bitmask & BACK_EMISSION_BIT) {
131 COPY_4FV( mat[1].Emission, params );
132 }
133 if (bitmask & FRONT_SHININESS_BIT) {
134 GLfloat shininess = CLAMP( params[0], 0.0F, 128.0F );
135 mat[0].Shininess = shininess;
136 }
137 if (bitmask & BACK_SHININESS_BIT) {
138 GLfloat shininess = CLAMP( params[0], 0.0F, 128.0F );
139 mat[1].Shininess = shininess;
140 }
141 if (bitmask & FRONT_INDEXES_BIT) {
142 mat[0].AmbientIndex = params[0];
143 mat[0].DiffuseIndex = params[1];
144 mat[0].SpecularIndex = params[2];
145 }
146 if (bitmask & BACK_INDEXES_BIT) {
147 mat[1].AmbientIndex = params[0];
148 mat[1].DiffuseIndex = params[1];
149 mat[1].SpecularIndex = params[2];
150 }
151
152 _mesa_update_material( ctx, mat, bitmask );
153 }
154
155 void _mesa_noop_Color4ub( GLubyte a, GLubyte b, GLubyte c, GLubyte d )
156 {
157 GET_CURRENT_CONTEXT(ctx);
158 GLchan *color = ctx->Current.Color;
159 color[0] = UBYTE_TO_CHAN(a);
160 color[1] = UBYTE_TO_CHAN(b);
161 color[2] = UBYTE_TO_CHAN(c);
162 color[3] = UBYTE_TO_CHAN(d);
163 }
164
165 void _mesa_noop_Color4ubv( const GLubyte *v )
166 {
167 GET_CURRENT_CONTEXT(ctx);
168 GLchan *color = ctx->Current.Color;
169 #if CHAN_TYPE == GL_UNSIGNED_BYTE
170 COPY_4UBV( color, v );
171 #else
172 color[0] = UBYTE_TO_CHAN(v[0]);
173 color[1] = UBYTE_TO_CHAN(v[1]);
174 color[2] = UBYTE_TO_CHAN(v[2]);
175 color[3] = UBYTE_TO_CHAN(v[3]);
176 #endif
177 }
178
179 void _mesa_noop_Color4f( GLfloat a, GLfloat b, GLfloat c, GLfloat d )
180 {
181 GET_CURRENT_CONTEXT(ctx);
182 GLchan *color = ctx->Current.Color;
183 UNCLAMPED_FLOAT_TO_CHAN(color[0], a);
184 UNCLAMPED_FLOAT_TO_CHAN(color[1], b);
185 UNCLAMPED_FLOAT_TO_CHAN(color[2], c);
186 UNCLAMPED_FLOAT_TO_CHAN(color[3], d);
187 }
188
189 void _mesa_noop_Color4fv( const GLfloat *v )
190 {
191 GET_CURRENT_CONTEXT(ctx);
192 GLchan *color = ctx->Current.Color;
193 UNCLAMPED_FLOAT_TO_CHAN(color[0], v[0]);
194 UNCLAMPED_FLOAT_TO_CHAN(color[1], v[1]);
195 UNCLAMPED_FLOAT_TO_CHAN(color[2], v[2]);
196 UNCLAMPED_FLOAT_TO_CHAN(color[3], v[3]);
197 }
198
199 void _mesa_noop_Color3ub( GLubyte a, GLubyte b, GLubyte c )
200 {
201 GET_CURRENT_CONTEXT(ctx);
202 GLchan *color = ctx->Current.Color;
203 color[0] = UBYTE_TO_CHAN(a);
204 color[1] = UBYTE_TO_CHAN(b);
205 color[2] = UBYTE_TO_CHAN(c);
206 color[3] = CHAN_MAX;
207 }
208
209 void _mesa_noop_Color3ubv( const GLubyte *v )
210 {
211 GET_CURRENT_CONTEXT(ctx);
212 GLchan *color = ctx->Current.Color;
213 color[0] = UBYTE_TO_CHAN(v[0]);
214 color[1] = UBYTE_TO_CHAN(v[1]);
215 color[2] = UBYTE_TO_CHAN(v[2]);
216 color[3] = CHAN_MAX;
217 }
218
219 void _mesa_noop_Color3f( GLfloat a, GLfloat b, GLfloat c )
220 {
221 GET_CURRENT_CONTEXT(ctx);
222 GLchan *color = ctx->Current.Color;
223 UNCLAMPED_FLOAT_TO_CHAN(color[0], a);
224 UNCLAMPED_FLOAT_TO_CHAN(color[1], b);
225 UNCLAMPED_FLOAT_TO_CHAN(color[2], c);
226 color[3] = CHAN_MAX;
227 }
228
229 void _mesa_noop_Color3fv( const GLfloat *v )
230 {
231 GET_CURRENT_CONTEXT(ctx);
232 GLchan *color = ctx->Current.Color;
233 UNCLAMPED_FLOAT_TO_CHAN(color[0], v[0]);
234 UNCLAMPED_FLOAT_TO_CHAN(color[1], v[1]);
235 UNCLAMPED_FLOAT_TO_CHAN(color[2], v[2]);
236 color[3] = CHAN_MAX;
237 }
238
239 void _mesa_noop_MultiTexCoord1fARB( GLenum target, GLfloat a )
240 {
241 GET_CURRENT_CONTEXT(ctx);
242 GLuint unit = target - GL_TEXTURE0_ARB;
243
244 /* unit is unsigned -- cannot be less than zero.
245 */
246 if (unit < MAX_TEXTURE_UNITS)
247 {
248 GLfloat *dest = ctx->Current.Texcoord[unit];
249 COPY_FLOAT(dest[0], a);
250 dest[1] = 0;
251 dest[2] = 0;
252 dest[3] = 1;
253 }
254 }
255
256 void _mesa_noop_MultiTexCoord1fvARB( GLenum target, GLfloat *v )
257 {
258 GET_CURRENT_CONTEXT(ctx);
259 GLuint unit = target - GL_TEXTURE0_ARB;
260
261 /* unit is unsigned -- cannot be less than zero.
262 */
263 if (unit < MAX_TEXTURE_UNITS)
264 {
265 GLfloat *dest = ctx->Current.Texcoord[unit];
266 COPY_FLOAT(dest[0], v[0]);
267 dest[1] = 0;
268 dest[2] = 0;
269 dest[3] = 1;
270 }
271 }
272
273 void _mesa_noop_MultiTexCoord2fARB( GLenum target, GLfloat a, GLfloat b )
274 {
275 GET_CURRENT_CONTEXT(ctx);
276 GLuint unit = target - GL_TEXTURE0_ARB;
277
278 /* unit is unsigned -- cannot be less than zero.
279 */
280 if (unit < MAX_TEXTURE_UNITS)
281 {
282 GLfloat *dest = ctx->Current.Texcoord[unit];
283 COPY_FLOAT(dest[0], a);
284 COPY_FLOAT(dest[1], b);
285 dest[2] = 0;
286 dest[3] = 1;
287 }
288 }
289
290 void _mesa_noop_MultiTexCoord2fvARB( GLenum target, GLfloat *v )
291 {
292 GET_CURRENT_CONTEXT(ctx);
293 GLuint unit = target - GL_TEXTURE0_ARB;
294
295 /* unit is unsigned -- cannot be less than zero.
296 */
297 if (unit < MAX_TEXTURE_UNITS)
298 {
299 GLfloat *dest = ctx->Current.Texcoord[unit];
300 COPY_FLOAT(dest[0], v[0]);
301 COPY_FLOAT(dest[1], v[1]);
302 dest[2] = 0;
303 dest[3] = 1;
304 }
305 }
306
307 void _mesa_noop_MultiTexCoord3fARB( GLenum target, GLfloat a, GLfloat b, GLfloat c)
308 {
309 GET_CURRENT_CONTEXT(ctx);
310 GLuint unit = target - GL_TEXTURE0_ARB;
311
312 /* unit is unsigned -- cannot be less than zero.
313 */
314 if (unit < MAX_TEXTURE_UNITS)
315 {
316 GLfloat *dest = ctx->Current.Texcoord[unit];
317 COPY_FLOAT(dest[0], a);
318 COPY_FLOAT(dest[1], b);
319 COPY_FLOAT(dest[2], c);
320 dest[3] = 1;
321 }
322 }
323
324 void _mesa_noop_MultiTexCoord3fvARB( GLenum target, GLfloat *v )
325 {
326 GET_CURRENT_CONTEXT(ctx);
327 GLuint unit = target - GL_TEXTURE0_ARB;
328
329 /* unit is unsigned -- cannot be less than zero.
330 */
331 if (unit < MAX_TEXTURE_UNITS)
332 {
333 GLfloat *dest = ctx->Current.Texcoord[unit];
334 COPY_FLOAT(dest[0], v[0]);
335 COPY_FLOAT(dest[1], v[1]);
336 COPY_FLOAT(dest[2], v[2]);
337 dest[3] = 1;
338 }
339 }
340
341 void _mesa_noop_MultiTexCoord4fARB( GLenum target, GLfloat a, GLfloat b,
342 GLfloat c, GLfloat d )
343 {
344 GET_CURRENT_CONTEXT(ctx);
345 GLuint unit = target - GL_TEXTURE0_ARB;
346
347 /* unit is unsigned -- cannot be less than zero.
348 */
349 if (unit < MAX_TEXTURE_UNITS)
350 {
351 GLfloat *dest = ctx->Current.Texcoord[unit];
352 COPY_FLOAT(dest[0], a);
353 COPY_FLOAT(dest[1], b);
354 COPY_FLOAT(dest[2], c);
355 dest[3] = d;
356 }
357 }
358
359 void _mesa_noop_MultiTexCoord4fvARB( GLenum target, GLfloat *v )
360 {
361 GET_CURRENT_CONTEXT(ctx);
362 GLuint unit = target - GL_TEXTURE0_ARB;
363
364 /* unit is unsigned -- cannot be less than zero.
365 */
366 if (unit < MAX_TEXTURE_UNITS)
367 {
368 GLfloat *dest = ctx->Current.Texcoord[unit];
369 COPY_FLOAT(dest[0], v[0]);
370 COPY_FLOAT(dest[1], v[1]);
371 COPY_FLOAT(dest[2], v[2]);
372 COPY_FLOAT(dest[3], v[3]);
373 }
374 }
375
376 void _mesa_noop_SecondaryColor3ubEXT( GLubyte a, GLubyte b, GLubyte c )
377 {
378 GET_CURRENT_CONTEXT(ctx);
379 GLchan *color = ctx->Current.SecondaryColor;
380 color[0] = UBYTE_TO_CHAN(a);
381 color[1] = UBYTE_TO_CHAN(b);
382 color[2] = UBYTE_TO_CHAN(c);
383 color[3] = CHAN_MAX;
384 }
385
386 void _mesa_noop_SecondaryColor3ubvEXT( const GLubyte *v )
387 {
388 GET_CURRENT_CONTEXT(ctx);
389 GLchan *color = ctx->Current.SecondaryColor;
390 color[0] = UBYTE_TO_CHAN(v[0]);
391 color[1] = UBYTE_TO_CHAN(v[1]);
392 color[2] = UBYTE_TO_CHAN(v[2]);
393 color[3] = CHAN_MAX;
394 }
395
396 void _mesa_noop_SecondaryColor3fEXT( GLfloat a, GLfloat b, GLfloat c )
397 {
398 GET_CURRENT_CONTEXT(ctx);
399 GLchan *color = ctx->Current.SecondaryColor;
400 UNCLAMPED_FLOAT_TO_CHAN(color[0], a);
401 UNCLAMPED_FLOAT_TO_CHAN(color[1], b);
402 UNCLAMPED_FLOAT_TO_CHAN(color[2], c);
403 color[3] = CHAN_MAX;
404 }
405
406 void _mesa_noop_SecondaryColor3fvEXT( const GLfloat *v )
407 {
408 GET_CURRENT_CONTEXT(ctx);
409 GLchan *color = ctx->Current.SecondaryColor;
410 UNCLAMPED_FLOAT_TO_CHAN(color[0], v[0]);
411 UNCLAMPED_FLOAT_TO_CHAN(color[1], v[1]);
412 UNCLAMPED_FLOAT_TO_CHAN(color[2], v[2]);
413 color[3] = CHAN_MAX;
414 }
415
416 void _mesa_noop_TexCoord1f( GLfloat a )
417 {
418 GET_CURRENT_CONTEXT(ctx);
419 GLfloat *dest = ctx->Current.Texcoord[0];
420 COPY_FLOAT(dest[0], a);
421 dest[1] = 0;
422 dest[2] = 0;
423 dest[3] = 1;
424 }
425
426 void _mesa_noop_TexCoord1fv( GLfloat *v )
427 {
428 GET_CURRENT_CONTEXT(ctx);
429 GLfloat *dest = ctx->Current.Texcoord[0];
430 COPY_FLOAT(dest[0], v[0]);
431 dest[1] = 0;
432 dest[2] = 0;
433 dest[3] = 1;
434 }
435
436 void _mesa_noop_TexCoord2f( GLfloat a, GLfloat b )
437 {
438 GET_CURRENT_CONTEXT(ctx);
439 GLfloat *dest = ctx->Current.Texcoord[0];
440 COPY_FLOAT(dest[0], a);
441 COPY_FLOAT(dest[1], b);
442 dest[2] = 0;
443 dest[3] = 1;
444 }
445
446 void _mesa_noop_TexCoord2fv( GLfloat *v )
447 {
448 GET_CURRENT_CONTEXT(ctx);
449 GLfloat *dest = ctx->Current.Texcoord[0];
450 COPY_FLOAT(dest[0], v[0]);
451 COPY_FLOAT(dest[1], v[1]);
452 dest[2] = 0;
453 dest[3] = 1;
454 }
455
456 void _mesa_noop_TexCoord3f( GLfloat a, GLfloat b, GLfloat c )
457 {
458 GET_CURRENT_CONTEXT(ctx);
459 GLfloat *dest = ctx->Current.Texcoord[0];
460 COPY_FLOAT(dest[0], a);
461 COPY_FLOAT(dest[1], b);
462 COPY_FLOAT(dest[2], c);
463 dest[3] = 1;
464 }
465
466 void _mesa_noop_TexCoord3fv( GLfloat *v )
467 {
468 GET_CURRENT_CONTEXT(ctx);
469 GLfloat *dest = ctx->Current.Texcoord[0];
470 COPY_FLOAT(dest[0], v[0]);
471 COPY_FLOAT(dest[1], v[1]);
472 COPY_FLOAT(dest[2], v[2]);
473 dest[3] = 1;
474 }
475
476 void _mesa_noop_TexCoord4f( GLfloat a, GLfloat b, GLfloat c, GLfloat d )
477 {
478 GET_CURRENT_CONTEXT(ctx);
479 GLfloat *dest = ctx->Current.Texcoord[0];
480 COPY_FLOAT(dest[0], a);
481 COPY_FLOAT(dest[1], b);
482 COPY_FLOAT(dest[2], c);
483 COPY_FLOAT(dest[3], d);
484 }
485
486 void _mesa_noop_TexCoord4fv( GLfloat *v )
487 {
488 GET_CURRENT_CONTEXT(ctx);
489 GLfloat *dest = ctx->Current.Texcoord[0];
490 COPY_FLOAT(dest[0], v[0]);
491 COPY_FLOAT(dest[1], v[1]);
492 COPY_FLOAT(dest[2], v[2]);
493 COPY_FLOAT(dest[3], v[3]);
494 }
495
496 /* Execute a glRectf() function. This is not suitable for GL_COMPILE
497 * modes (as the test for outside begin/end is not compiled),
498 * but may be useful for drivers in circumstances which exclude
499 * display list interactions.
500 *
501 * (None of the functions in this file are suitable for GL_COMPILE
502 * modes).
503 */
504 void _mesa_noop_Rectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 )
505 {
506 {
507 GET_CURRENT_CONTEXT(ctx);
508 ASSERT_OUTSIDE_BEGIN_END(ctx);
509 }
510
511 glBegin( GL_QUADS );
512 glVertex2f( x1, y1 );
513 glVertex2f( x2, y1 );
514 glVertex2f( x2, y2 );
515 glVertex2f( x1, y2 );
516 glEnd();
517 }
518
519
520 /* Some very basic support for arrays. Drivers without explicit array
521 * support can hook these in, but still need to supply an array-elt
522 * implementation.
523 */
524 void _mesa_noop_DrawArrays(GLenum mode, GLint start, GLsizei count)
525 {
526 GET_CURRENT_CONTEXT(ctx);
527 GLint i;
528
529 if (!_mesa_validate_DrawArrays( ctx, mode, start, count ))
530 return;
531
532 glBegin(mode);
533 for (i = start ; i <= count ; i++)
534 glArrayElement( i );
535 glEnd();
536 }
537
538
539 void _mesa_noop_DrawElements(GLenum mode, GLsizei count, GLenum type,
540 const GLvoid *indices)
541 {
542 GET_CURRENT_CONTEXT(ctx);
543 GLint i;
544
545 if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices ))
546 return;
547
548 glBegin(mode);
549
550 switch (type) {
551 case GL_UNSIGNED_BYTE:
552 for (i = 0 ; i < count ; i++)
553 glArrayElement( ((GLubyte *)indices)[i] );
554 break;
555 case GL_UNSIGNED_SHORT:
556 for (i = 0 ; i < count ; i++)
557 glArrayElement( ((GLushort *)indices)[i] );
558 break;
559 case GL_UNSIGNED_INT:
560 for (i = 0 ; i < count ; i++)
561 glArrayElement( ((GLuint *)indices)[i] );
562 break;
563 default:
564 _mesa_error( ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
565 break;
566 }
567
568 glEnd();
569 }
570
571 void _mesa_noop_DrawRangeElements(GLenum mode,
572 GLuint start, GLuint end,
573 GLsizei count, GLenum type,
574 const GLvoid *indices)
575 {
576 GET_CURRENT_CONTEXT(ctx);
577
578 if (_mesa_validate_DrawRangeElements( ctx, mode,
579 start, end,
580 count, type, indices ))
581 glDrawElements( mode, count, type, indices );
582 }