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