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