lots of gl_*() to _mesa_*() namespace clean-up
[mesa.git] / src / mesa / main / api_noop.c
1 /* $Id: api_noop.c,v 1.5 2001/03/03 20:33:27 brianp 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 }
202
203 void _mesa_noop_Color3ub( GLubyte a, GLubyte b, GLubyte c )
204 {
205 GET_CURRENT_CONTEXT(ctx);
206 GLchan *color = ctx->Current.Color;
207 color[0] = UBYTE_TO_CHAN(a);
208 color[1] = UBYTE_TO_CHAN(b);
209 color[2] = UBYTE_TO_CHAN(c);
210 color[3] = CHAN_MAX;
211 }
212
213 void _mesa_noop_Color3ubv( const GLubyte *v )
214 {
215 GET_CURRENT_CONTEXT(ctx);
216 GLchan *color = ctx->Current.Color;
217 color[0] = UBYTE_TO_CHAN(v[0]);
218 color[1] = UBYTE_TO_CHAN(v[1]);
219 color[2] = UBYTE_TO_CHAN(v[2]);
220 color[3] = CHAN_MAX;
221 }
222
223 void _mesa_noop_Color3f( GLfloat a, GLfloat b, GLfloat c )
224 {
225 GET_CURRENT_CONTEXT(ctx);
226 GLchan *color = ctx->Current.Color;
227 UNCLAMPED_FLOAT_TO_CHAN(color[0], a);
228 UNCLAMPED_FLOAT_TO_CHAN(color[1], b);
229 UNCLAMPED_FLOAT_TO_CHAN(color[2], c);
230 color[3] = CHAN_MAX;
231 }
232
233 void _mesa_noop_Color3fv( const GLfloat *v )
234 {
235 GET_CURRENT_CONTEXT(ctx);
236 GLchan *color = ctx->Current.Color;
237 UNCLAMPED_FLOAT_TO_CHAN(color[0], v[0]);
238 UNCLAMPED_FLOAT_TO_CHAN(color[1], v[1]);
239 UNCLAMPED_FLOAT_TO_CHAN(color[2], v[2]);
240 color[3] = CHAN_MAX;
241 }
242
243 void _mesa_noop_MultiTexCoord1fARB( GLenum target, GLfloat a )
244 {
245 GET_CURRENT_CONTEXT(ctx);
246 GLuint unit = target - GL_TEXTURE0_ARB;
247
248 /* unit is unsigned -- cannot be less than zero.
249 */
250 if (unit < MAX_TEXTURE_UNITS)
251 {
252 GLfloat *dest = ctx->Current.Texcoord[unit];
253 COPY_FLOAT(dest[0], a);
254 dest[1] = 0;
255 dest[2] = 0;
256 dest[3] = 1;
257 }
258 }
259
260 void _mesa_noop_MultiTexCoord1fvARB( GLenum target, GLfloat *v )
261 {
262 GET_CURRENT_CONTEXT(ctx);
263 GLuint unit = target - GL_TEXTURE0_ARB;
264
265 /* unit is unsigned -- cannot be less than zero.
266 */
267 if (unit < MAX_TEXTURE_UNITS)
268 {
269 GLfloat *dest = ctx->Current.Texcoord[unit];
270 COPY_FLOAT(dest[0], v[0]);
271 dest[1] = 0;
272 dest[2] = 0;
273 dest[3] = 1;
274 }
275 }
276
277 void _mesa_noop_MultiTexCoord2fARB( GLenum target, GLfloat a, GLfloat b )
278 {
279 GET_CURRENT_CONTEXT(ctx);
280 GLuint unit = target - GL_TEXTURE0_ARB;
281
282 /* unit is unsigned -- cannot be less than zero.
283 */
284 if (unit < MAX_TEXTURE_UNITS)
285 {
286 GLfloat *dest = ctx->Current.Texcoord[unit];
287 COPY_FLOAT(dest[0], a);
288 COPY_FLOAT(dest[1], b);
289 dest[2] = 0;
290 dest[3] = 1;
291 }
292 }
293
294 void _mesa_noop_MultiTexCoord2fvARB( GLenum target, GLfloat *v )
295 {
296 GET_CURRENT_CONTEXT(ctx);
297 GLuint unit = target - GL_TEXTURE0_ARB;
298
299 /* unit is unsigned -- cannot be less than zero.
300 */
301 if (unit < MAX_TEXTURE_UNITS)
302 {
303 GLfloat *dest = ctx->Current.Texcoord[unit];
304 COPY_FLOAT(dest[0], v[0]);
305 COPY_FLOAT(dest[1], v[1]);
306 dest[2] = 0;
307 dest[3] = 1;
308 }
309 }
310
311 void _mesa_noop_MultiTexCoord3fARB( GLenum target, GLfloat a, GLfloat b, GLfloat c)
312 {
313 GET_CURRENT_CONTEXT(ctx);
314 GLuint unit = target - GL_TEXTURE0_ARB;
315
316 /* unit is unsigned -- cannot be less than zero.
317 */
318 if (unit < MAX_TEXTURE_UNITS)
319 {
320 GLfloat *dest = ctx->Current.Texcoord[unit];
321 COPY_FLOAT(dest[0], a);
322 COPY_FLOAT(dest[1], b);
323 COPY_FLOAT(dest[2], c);
324 dest[3] = 1;
325 }
326 }
327
328 void _mesa_noop_MultiTexCoord3fvARB( GLenum target, GLfloat *v )
329 {
330 GET_CURRENT_CONTEXT(ctx);
331 GLuint unit = target - GL_TEXTURE0_ARB;
332
333 /* unit is unsigned -- cannot be less than zero.
334 */
335 if (unit < MAX_TEXTURE_UNITS)
336 {
337 GLfloat *dest = ctx->Current.Texcoord[unit];
338 COPY_FLOAT(dest[0], v[0]);
339 COPY_FLOAT(dest[1], v[1]);
340 COPY_FLOAT(dest[2], v[2]);
341 dest[3] = 1;
342 }
343 }
344
345 void _mesa_noop_MultiTexCoord4fARB( GLenum target, GLfloat a, GLfloat b,
346 GLfloat c, GLfloat d )
347 {
348 GET_CURRENT_CONTEXT(ctx);
349 GLuint unit = target - GL_TEXTURE0_ARB;
350
351 /* unit is unsigned -- cannot be less than zero.
352 */
353 if (unit < MAX_TEXTURE_UNITS)
354 {
355 GLfloat *dest = ctx->Current.Texcoord[unit];
356 COPY_FLOAT(dest[0], a);
357 COPY_FLOAT(dest[1], b);
358 COPY_FLOAT(dest[2], c);
359 dest[3] = d;
360 }
361 }
362
363 void _mesa_noop_MultiTexCoord4fvARB( GLenum target, GLfloat *v )
364 {
365 GET_CURRENT_CONTEXT(ctx);
366 GLuint unit = target - GL_TEXTURE0_ARB;
367
368 /* unit is unsigned -- cannot be less than zero.
369 */
370 if (unit < MAX_TEXTURE_UNITS)
371 {
372 GLfloat *dest = ctx->Current.Texcoord[unit];
373 COPY_FLOAT(dest[0], v[0]);
374 COPY_FLOAT(dest[1], v[1]);
375 COPY_FLOAT(dest[2], v[2]);
376 COPY_FLOAT(dest[3], v[3]);
377 }
378 }
379
380 void _mesa_noop_SecondaryColor3ubEXT( GLubyte a, GLubyte b, GLubyte c )
381 {
382 GET_CURRENT_CONTEXT(ctx);
383 GLchan *color = ctx->Current.SecondaryColor;
384 color[0] = UBYTE_TO_CHAN(a);
385 color[1] = UBYTE_TO_CHAN(b);
386 color[2] = UBYTE_TO_CHAN(c);
387 color[3] = CHAN_MAX;
388 }
389
390 void _mesa_noop_SecondaryColor3ubvEXT( const GLubyte *v )
391 {
392 GET_CURRENT_CONTEXT(ctx);
393 GLchan *color = ctx->Current.SecondaryColor;
394 color[0] = UBYTE_TO_CHAN(v[0]);
395 color[1] = UBYTE_TO_CHAN(v[1]);
396 color[2] = UBYTE_TO_CHAN(v[2]);
397 color[3] = CHAN_MAX;
398 }
399
400 void _mesa_noop_SecondaryColor3fEXT( GLfloat a, GLfloat b, GLfloat c )
401 {
402 GET_CURRENT_CONTEXT(ctx);
403 GLchan *color = ctx->Current.SecondaryColor;
404 UNCLAMPED_FLOAT_TO_CHAN(color[0], a);
405 UNCLAMPED_FLOAT_TO_CHAN(color[1], b);
406 UNCLAMPED_FLOAT_TO_CHAN(color[2], c);
407 color[3] = CHAN_MAX;
408 }
409
410 void _mesa_noop_SecondaryColor3fvEXT( const GLfloat *v )
411 {
412 GET_CURRENT_CONTEXT(ctx);
413 GLchan *color = ctx->Current.SecondaryColor;
414 UNCLAMPED_FLOAT_TO_CHAN(color[0], v[0]);
415 UNCLAMPED_FLOAT_TO_CHAN(color[1], v[1]);
416 UNCLAMPED_FLOAT_TO_CHAN(color[2], v[2]);
417 color[3] = CHAN_MAX;
418 }
419
420 void _mesa_noop_TexCoord1f( GLfloat a )
421 {
422 GET_CURRENT_CONTEXT(ctx);
423 GLfloat *dest = ctx->Current.Texcoord[0];
424 COPY_FLOAT(dest[0], a);
425 dest[1] = 0;
426 dest[2] = 0;
427 dest[3] = 1;
428 }
429
430 void _mesa_noop_TexCoord1fv( GLfloat *v )
431 {
432 GET_CURRENT_CONTEXT(ctx);
433 GLfloat *dest = ctx->Current.Texcoord[0];
434 COPY_FLOAT(dest[0], v[0]);
435 dest[1] = 0;
436 dest[2] = 0;
437 dest[3] = 1;
438 }
439
440 void _mesa_noop_TexCoord2f( GLfloat a, GLfloat b )
441 {
442 GET_CURRENT_CONTEXT(ctx);
443 GLfloat *dest = ctx->Current.Texcoord[0];
444 COPY_FLOAT(dest[0], a);
445 COPY_FLOAT(dest[1], b);
446 dest[2] = 0;
447 dest[3] = 1;
448 }
449
450 void _mesa_noop_TexCoord2fv( GLfloat *v )
451 {
452 GET_CURRENT_CONTEXT(ctx);
453 GLfloat *dest = ctx->Current.Texcoord[0];
454 COPY_FLOAT(dest[0], v[0]);
455 COPY_FLOAT(dest[1], v[1]);
456 dest[2] = 0;
457 dest[3] = 1;
458 }
459
460 void _mesa_noop_TexCoord3f( GLfloat a, GLfloat b, GLfloat c )
461 {
462 GET_CURRENT_CONTEXT(ctx);
463 GLfloat *dest = ctx->Current.Texcoord[0];
464 COPY_FLOAT(dest[0], a);
465 COPY_FLOAT(dest[1], b);
466 COPY_FLOAT(dest[2], c);
467 dest[3] = 1;
468 }
469
470 void _mesa_noop_TexCoord3fv( GLfloat *v )
471 {
472 GET_CURRENT_CONTEXT(ctx);
473 GLfloat *dest = ctx->Current.Texcoord[0];
474 COPY_FLOAT(dest[0], v[0]);
475 COPY_FLOAT(dest[1], v[1]);
476 COPY_FLOAT(dest[2], v[2]);
477 dest[3] = 1;
478 }
479
480 void _mesa_noop_TexCoord4f( GLfloat a, GLfloat b, GLfloat c, GLfloat d )
481 {
482 GET_CURRENT_CONTEXT(ctx);
483 GLfloat *dest = ctx->Current.Texcoord[0];
484 COPY_FLOAT(dest[0], a);
485 COPY_FLOAT(dest[1], b);
486 COPY_FLOAT(dest[2], c);
487 COPY_FLOAT(dest[3], d);
488 }
489
490 void _mesa_noop_TexCoord4fv( GLfloat *v )
491 {
492 GET_CURRENT_CONTEXT(ctx);
493 GLfloat *dest = ctx->Current.Texcoord[0];
494 COPY_FLOAT(dest[0], v[0]);
495 COPY_FLOAT(dest[1], v[1]);
496 COPY_FLOAT(dest[2], v[2]);
497 COPY_FLOAT(dest[3], v[3]);
498 }
499
500 /* Execute a glRectf() function. This is not suitable for GL_COMPILE
501 * modes (as the test for outside begin/end is not compiled),
502 * but may be useful for drivers in circumstances which exclude
503 * display list interactions.
504 *
505 * (None of the functions in this file are suitable for GL_COMPILE
506 * modes).
507 */
508 void _mesa_noop_Rectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 )
509 {
510 {
511 GET_CURRENT_CONTEXT(ctx);
512 ASSERT_OUTSIDE_BEGIN_END(ctx);
513 }
514
515 glBegin( GL_QUADS );
516 glVertex2f( x1, y1 );
517 glVertex2f( x2, y1 );
518 glVertex2f( x2, y2 );
519 glVertex2f( x1, y2 );
520 glEnd();
521 }
522
523
524 /* Some very basic support for arrays. Drivers without explicit array
525 * support can hook these in, but still need to supply an array-elt
526 * implementation.
527 */
528 void _mesa_noop_DrawArrays(GLenum mode, GLint start, GLsizei count)
529 {
530 GET_CURRENT_CONTEXT(ctx);
531 GLint i;
532
533 if (!_mesa_validate_DrawArrays( ctx, mode, start, count ))
534 return;
535
536 glBegin(mode);
537 for (i = start ; i <= count ; i++)
538 glArrayElement( i );
539 glEnd();
540 }
541
542
543 void _mesa_noop_DrawElements(GLenum mode, GLsizei count, GLenum type,
544 const GLvoid *indices)
545 {
546 GET_CURRENT_CONTEXT(ctx);
547 GLint i;
548
549 if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices ))
550 return;
551
552 glBegin(mode);
553
554 switch (type) {
555 case GL_UNSIGNED_BYTE:
556 for (i = 0 ; i < count ; i++)
557 glArrayElement( ((GLubyte *)indices)[i] );
558 break;
559 case GL_UNSIGNED_SHORT:
560 for (i = 0 ; i < count ; i++)
561 glArrayElement( ((GLushort *)indices)[i] );
562 break;
563 case GL_UNSIGNED_INT:
564 for (i = 0 ; i < count ; i++)
565 glArrayElement( ((GLuint *)indices)[i] );
566 break;
567 default:
568 _mesa_error( ctx, GL_INVALID_ENUM, "glDrawElements(type)" );
569 break;
570 }
571
572 glEnd();
573 }
574
575 void _mesa_noop_DrawRangeElements(GLenum mode,
576 GLuint start, GLuint end,
577 GLsizei count, GLenum type,
578 const GLvoid *indices)
579 {
580 GET_CURRENT_CONTEXT(ctx);
581
582 if (_mesa_validate_DrawRangeElements( ctx, mode,
583 start, end,
584 count, type, indices ))
585 glDrawElements( mode, count, type, indices );
586 }
587