use BCOPY macro on FreeBSD
[mesa.git] / src / mesa / main / texstate.c
1 /* $Id: texstate.c,v 1.9 2000/03/07 17:54:58 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.3
6 *
7 * Copyright (C) 1999-2000 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 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "context.h"
33 #include "enums.h"
34 #include "extensions.h"
35 #include "macros.h"
36 #include "matrix.h"
37 #include "texobj.h"
38 #include "texstate.h"
39 #include "texture.h"
40 #include "types.h"
41 #include "xform.h"
42 #endif
43
44
45
46 #ifdef SPECIALCAST
47 /* Needed for an Amiga compiler */
48 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
49 #define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
50 #else
51 /* all other compilers */
52 #define ENUM_TO_FLOAT(X) ((GLfloat)(X))
53 #define ENUM_TO_DOUBLE(X) ((GLdouble)(X))
54 #endif
55
56
57
58
59 /**********************************************************************/
60 /* Texture Environment */
61 /**********************************************************************/
62
63
64 void
65 _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
66 {
67 GET_CURRENT_CONTEXT(ctx);
68 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
69
70 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexEnv");
71
72 if (target==GL_TEXTURE_ENV) {
73
74 if (pname==GL_TEXTURE_ENV_MODE) {
75 GLenum mode = (GLenum) (GLint) *param;
76 switch (mode) {
77 case GL_ADD:
78 if (!ctx->Extensions.HaveTextureEnvAdd) {
79 gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(param)");
80 return;
81 }
82 /* FALL-THROUGH */
83 case GL_MODULATE:
84 case GL_BLEND:
85 case GL_DECAL:
86 case GL_REPLACE:
87 /* A small optimization for drivers */
88 if (texUnit->EnvMode == mode)
89 return;
90
91 if (MESA_VERBOSE & (VERBOSE_STATE|VERBOSE_TEXTURE))
92 fprintf(stderr, "glTexEnv: old mode %s, new mode %s\n",
93 gl_lookup_enum_by_nr(texUnit->EnvMode),
94 gl_lookup_enum_by_nr(mode));
95
96 texUnit->EnvMode = mode;
97 ctx->NewState |= NEW_TEXTURE_ENV;
98 break;
99 default:
100 gl_error( ctx, GL_INVALID_VALUE, "glTexEnv(param)" );
101 return;
102 }
103 }
104 else if (pname==GL_TEXTURE_ENV_COLOR) {
105 texUnit->EnvColor[0] = CLAMP( param[0], 0.0F, 1.0F );
106 texUnit->EnvColor[1] = CLAMP( param[1], 0.0F, 1.0F );
107 texUnit->EnvColor[2] = CLAMP( param[2], 0.0F, 1.0F );
108 texUnit->EnvColor[3] = CLAMP( param[3], 0.0F, 1.0F );
109 }
110 else {
111 gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
112 return;
113 }
114
115 }
116 else if (target==GL_TEXTURE_FILTER_CONTROL_EXT) {
117
118 if (!ctx->Extensions.HaveTextureLodBias) {
119 gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
120 return;
121 }
122
123 if (pname==GL_TEXTURE_LOD_BIAS_EXT) {
124 texUnit->LodBias = param[0];
125 }
126 else {
127 gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
128 return;
129 }
130
131 }
132 else {
133 gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(target)" );
134 return;
135 }
136
137 if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
138 fprintf(stderr, "glTexEnv %s %s %.1f(%s) ...\n",
139 gl_lookup_enum_by_nr(target),
140 gl_lookup_enum_by_nr(pname),
141 *param,
142 gl_lookup_enum_by_nr((GLenum) (GLint) *param));
143
144 /* Tell device driver about the new texture environment */
145 if (ctx->Driver.TexEnv) {
146 (*ctx->Driver.TexEnv)( ctx, target, pname, param );
147 }
148
149 }
150
151
152 void
153 _mesa_TexEnvf( GLenum target, GLenum pname, GLfloat param )
154 {
155 _mesa_TexEnvfv( target, pname, &param );
156 }
157
158
159
160 void
161 _mesa_TexEnvi( GLenum target, GLenum pname, GLint param )
162 {
163 GLfloat p[4];
164 p[0] = (GLfloat) param;
165 p[1] = p[2] = p[3] = 0.0;
166 _mesa_TexEnvfv( target, pname, p );
167 }
168
169
170 void
171 _mesa_TexEnviv( GLenum target, GLenum pname, const GLint *param )
172 {
173 GLfloat p[4];
174 p[0] = INT_TO_FLOAT( param[0] );
175 p[1] = INT_TO_FLOAT( param[1] );
176 p[2] = INT_TO_FLOAT( param[2] );
177 p[3] = INT_TO_FLOAT( param[3] );
178 _mesa_TexEnvfv( target, pname, p );
179 }
180
181
182 void
183 _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
184 {
185 GET_CURRENT_CONTEXT(ctx);
186 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
187
188 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexEnvfv");
189
190 if (target!=GL_TEXTURE_ENV) {
191 gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
192 return;
193 }
194 switch (pname) {
195 case GL_TEXTURE_ENV_MODE:
196 *params = ENUM_TO_FLOAT(texUnit->EnvMode);
197 break;
198 case GL_TEXTURE_ENV_COLOR:
199 COPY_4FV( params, texUnit->EnvColor );
200 break;
201 default:
202 gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" );
203 }
204 }
205
206
207 void
208 _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
209 {
210 GET_CURRENT_CONTEXT(ctx);
211 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
212
213 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexEnviv");
214
215 if (target!=GL_TEXTURE_ENV) {
216 gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" );
217 return;
218 }
219 switch (pname) {
220 case GL_TEXTURE_ENV_MODE:
221 *params = (GLint) texUnit->EnvMode;
222 break;
223 case GL_TEXTURE_ENV_COLOR:
224 params[0] = FLOAT_TO_INT( texUnit->EnvColor[0] );
225 params[1] = FLOAT_TO_INT( texUnit->EnvColor[1] );
226 params[2] = FLOAT_TO_INT( texUnit->EnvColor[2] );
227 params[3] = FLOAT_TO_INT( texUnit->EnvColor[3] );
228 break;
229 default:
230 gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)" );
231 }
232 }
233
234
235
236
237 /**********************************************************************/
238 /* Texture Parameters */
239 /**********************************************************************/
240
241
242 void
243 _mesa_TexParameterf( GLenum target, GLenum pname, GLfloat param )
244 {
245 _mesa_TexParameterfv(target, pname, &param);
246 }
247
248
249 void
250 _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
251 {
252 GET_CURRENT_CONTEXT(ctx);
253 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
254 GLenum eparam = (GLenum) (GLint) params[0];
255 struct gl_texture_object *texObj;
256
257 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexParameterfv");
258
259 if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
260 fprintf(stderr, "texPARAM %s %s %d...\n",
261 gl_lookup_enum_by_nr(target),
262 gl_lookup_enum_by_nr(pname),
263 eparam);
264
265
266 switch (target) {
267 case GL_TEXTURE_1D:
268 texObj = texUnit->CurrentD[1];
269 break;
270 case GL_TEXTURE_2D:
271 texObj = texUnit->CurrentD[2];
272 break;
273 case GL_TEXTURE_3D_EXT:
274 texObj = texUnit->CurrentD[3];
275 break;
276 default:
277 gl_error( ctx, GL_INVALID_ENUM, "glTexParameter(target)" );
278 return;
279 }
280
281 switch (pname) {
282 case GL_TEXTURE_MIN_FILTER:
283 /* A small optimization */
284 if (texObj->MinFilter == eparam)
285 return;
286
287 if (eparam==GL_NEAREST || eparam==GL_LINEAR
288 || eparam==GL_NEAREST_MIPMAP_NEAREST
289 || eparam==GL_LINEAR_MIPMAP_NEAREST
290 || eparam==GL_NEAREST_MIPMAP_LINEAR
291 || eparam==GL_LINEAR_MIPMAP_LINEAR) {
292 texObj->MinFilter = eparam;
293 ctx->NewState |= NEW_TEXTURING;
294 }
295 else {
296 gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
297 return;
298 }
299 break;
300 case GL_TEXTURE_MAG_FILTER:
301 /* A small optimization */
302 if (texObj->MagFilter == eparam)
303 return;
304
305 if (eparam==GL_NEAREST || eparam==GL_LINEAR) {
306 texObj->MagFilter = eparam;
307 ctx->NewState |= NEW_TEXTURING;
308 }
309 else {
310 gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
311 return;
312 }
313 break;
314 case GL_TEXTURE_WRAP_S:
315 if (texObj->WrapS == eparam)
316 return;
317
318 if (eparam==GL_CLAMP || eparam==GL_REPEAT || eparam==GL_CLAMP_TO_EDGE) {
319 texObj->WrapS = eparam;
320 ctx->NewState |= NEW_TEXTURING;
321 }
322 else {
323 gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
324 return;
325 }
326 break;
327 case GL_TEXTURE_WRAP_T:
328 if (texObj->WrapT == eparam)
329 return;
330
331 if (eparam==GL_CLAMP || eparam==GL_REPEAT || eparam==GL_CLAMP_TO_EDGE) {
332 texObj->WrapT = eparam;
333 ctx->NewState |= NEW_TEXTURING;
334 }
335 else {
336 gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
337 return;
338 }
339 break;
340 case GL_TEXTURE_WRAP_R_EXT:
341 if (texObj->WrapR == eparam)
342 return;
343
344 if (eparam==GL_CLAMP || eparam==GL_REPEAT || eparam==GL_CLAMP_TO_EDGE) {
345 texObj->WrapR = eparam;
346 ctx->NewState |= NEW_TEXTURING;
347 }
348 else {
349 gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
350 }
351 break;
352 case GL_TEXTURE_BORDER_COLOR:
353 texObj->BorderColor[0] = (GLubyte) CLAMP((GLint)(params[0]*255.0), 0, 255);
354 texObj->BorderColor[1] = (GLubyte) CLAMP((GLint)(params[1]*255.0), 0, 255);
355 texObj->BorderColor[2] = (GLubyte) CLAMP((GLint)(params[2]*255.0), 0, 255);
356 texObj->BorderColor[3] = (GLubyte) CLAMP((GLint)(params[3]*255.0), 0, 255);
357 break;
358 case GL_TEXTURE_MIN_LOD:
359 texObj->MinLod = params[0];
360 ctx->NewState |= NEW_TEXTURING;
361 break;
362 case GL_TEXTURE_MAX_LOD:
363 texObj->MaxLod = params[0];
364 ctx->NewState |= NEW_TEXTURING;
365 break;
366 case GL_TEXTURE_BASE_LEVEL:
367 if (params[0] < 0.0) {
368 gl_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
369 return;
370 }
371 texObj->BaseLevel = (GLint) params[0];
372 ctx->NewState |= NEW_TEXTURING;
373 break;
374 case GL_TEXTURE_MAX_LEVEL:
375 if (params[0] < 0.0) {
376 gl_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
377 return;
378 }
379 texObj->MaxLevel = (GLint) params[0];
380 ctx->NewState |= NEW_TEXTURING;
381 break;
382 case GL_TEXTURE_PRIORITY:
383 /* (keithh@netcomuk.co.uk) */
384 texObj->Priority = CLAMP( params[0], 0.0F, 1.0F );
385 break;
386 default:
387 gl_error( ctx, GL_INVALID_ENUM, "glTexParameter(pname)" );
388 return;
389 }
390
391 gl_put_texobj_on_dirty_list( ctx, texObj );
392
393 if (ctx->Driver.TexParameter) {
394 (*ctx->Driver.TexParameter)( ctx, target, texObj, pname, params );
395 }
396 }
397
398
399 void
400 _mesa_TexParameteri( GLenum target, GLenum pname, const GLint param )
401 {
402 GLfloat fparam[4];
403 fparam[0] = (GLfloat) param;
404 fparam[1] = fparam[2] = fparam[3] = 0.0;
405 _mesa_TexParameterfv(target, pname, fparam);
406 }
407
408 void
409 _mesa_TexParameteriv( GLenum target, GLenum pname, const GLint *params )
410 {
411 GLfloat fparam[4];
412 fparam[0] = (GLfloat) params[0];
413 fparam[1] = fparam[2] = fparam[3] = 0.0;
414 _mesa_TexParameterfv(target, pname, fparam);
415 }
416
417
418 void
419 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
420 GLenum pname, GLfloat *params )
421 {
422 GLint iparam;
423 _mesa_GetTexLevelParameteriv( target, level, pname, &iparam );
424 *params = (GLfloat) iparam;
425 }
426
427
428
429 void
430 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
431 GLenum pname, GLint *params )
432 {
433 GET_CURRENT_CONTEXT(ctx);
434 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
435 const struct gl_texture_image *img = NULL;
436 GLuint dimensions;
437
438 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexLevelParameter");
439
440 if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
441 gl_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
442 return;
443 }
444
445 switch (target) {
446 case GL_TEXTURE_1D:
447 img = texUnit->CurrentD[1]->Image[level];
448 dimensions = 1;
449 break;
450 case GL_TEXTURE_2D:
451 img = texUnit->CurrentD[2]->Image[level];
452 dimensions = 2;
453 break;
454 case GL_TEXTURE_3D:
455 img = texUnit->CurrentD[3]->Image[level];
456 dimensions = 3;
457 break;
458 case GL_PROXY_TEXTURE_1D:
459 img = ctx->Texture.Proxy1D->Image[level];
460 dimensions = 1;
461 break;
462 case GL_PROXY_TEXTURE_2D:
463 img = ctx->Texture.Proxy2D->Image[level];
464 dimensions = 2;
465 break;
466 case GL_PROXY_TEXTURE_3D:
467 img = ctx->Texture.Proxy3D->Image[level];
468 dimensions = 3;
469 break;
470 default:
471 gl_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(target)");
472 return;
473 }
474
475 if (!img) {
476 if (pname == GL_TEXTURE_COMPONENTS)
477 *params = 1;
478 else
479 *params = 0;
480 return;
481 }
482
483 switch (pname) {
484 case GL_TEXTURE_WIDTH:
485 *params = img->Width;
486 return;
487 case GL_TEXTURE_HEIGHT:
488 if (dimensions > 1) {
489 *params = img->Height;
490 }
491 else {
492 gl_error( ctx, GL_INVALID_ENUM,
493 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_HEIGHT)" );
494 }
495 return;
496 case GL_TEXTURE_DEPTH:
497 if (dimensions > 2) {
498 *params = img->Depth;
499 }
500 else {
501 gl_error( ctx, GL_INVALID_ENUM,
502 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_DEPTH)" );
503 }
504 return;
505 case GL_TEXTURE_COMPONENTS:
506 *params = img->IntFormat;
507 return;
508 case GL_TEXTURE_BORDER:
509 *params = img->Border;
510 return;
511 case GL_TEXTURE_RED_SIZE:
512 *params = img->RedBits;
513 return;
514 case GL_TEXTURE_GREEN_SIZE:
515 *params = img->GreenBits;
516 return;
517 case GL_TEXTURE_BLUE_SIZE:
518 *params = img->BlueBits;
519 return;
520 case GL_TEXTURE_ALPHA_SIZE:
521 *params = img->AlphaBits;
522 return;
523 case GL_TEXTURE_INTENSITY_SIZE:
524 *params = img->IntensityBits;
525 return;
526 case GL_TEXTURE_LUMINANCE_SIZE:
527 *params = img->LuminanceBits;
528 return;
529 case GL_TEXTURE_INDEX_SIZE_EXT:
530 *params = img->IndexBits;
531 return;
532 default:
533 gl_error( ctx, GL_INVALID_ENUM,
534 "glGetTexLevelParameter[if]v(pname)" );
535 }
536 }
537
538
539
540 void
541 _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
542 {
543 GET_CURRENT_CONTEXT(ctx);
544 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
545 struct gl_texture_object *obj;
546
547 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexParameterfv");
548
549 switch (target) {
550 case GL_TEXTURE_1D:
551 obj = texUnit->CurrentD[1];
552 break;
553 case GL_TEXTURE_2D:
554 obj = texUnit->CurrentD[2];
555 break;
556 case GL_TEXTURE_3D_EXT:
557 obj = texUnit->CurrentD[3];
558 break;
559 default:
560 gl_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(target)");
561 return;
562 }
563
564 switch (pname) {
565 case GL_TEXTURE_MAG_FILTER:
566 *params = ENUM_TO_FLOAT(obj->MagFilter);
567 break;
568 case GL_TEXTURE_MIN_FILTER:
569 *params = ENUM_TO_FLOAT(obj->MinFilter);
570 break;
571 case GL_TEXTURE_WRAP_S:
572 *params = ENUM_TO_FLOAT(obj->WrapS);
573 break;
574 case GL_TEXTURE_WRAP_T:
575 *params = ENUM_TO_FLOAT(obj->WrapT);
576 break;
577 case GL_TEXTURE_WRAP_R_EXT:
578 *params = ENUM_TO_FLOAT(obj->WrapR);
579 break;
580 case GL_TEXTURE_BORDER_COLOR:
581 params[0] = obj->BorderColor[0] / 255.0F;
582 params[1] = obj->BorderColor[1] / 255.0F;
583 params[2] = obj->BorderColor[2] / 255.0F;
584 params[3] = obj->BorderColor[3] / 255.0F;
585 break;
586 case GL_TEXTURE_RESIDENT:
587 *params = ENUM_TO_FLOAT(GL_TRUE);
588 break;
589 case GL_TEXTURE_PRIORITY:
590 *params = obj->Priority;
591 break;
592 case GL_TEXTURE_MIN_LOD:
593 *params = obj->MinLod;
594 break;
595 case GL_TEXTURE_MAX_LOD:
596 *params = obj->MaxLod;
597 break;
598 case GL_TEXTURE_BASE_LEVEL:
599 *params = (GLfloat) obj->BaseLevel;
600 break;
601 case GL_TEXTURE_MAX_LEVEL:
602 *params = (GLfloat) obj->MaxLevel;
603 break;
604 default:
605 gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname)" );
606 }
607 }
608
609
610 void
611 _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
612 {
613 GET_CURRENT_CONTEXT(ctx);
614 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
615 struct gl_texture_object *obj;
616
617 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexParameteriv");
618
619 switch (target) {
620 case GL_TEXTURE_1D:
621 obj = texUnit->CurrentD[1];
622 break;
623 case GL_TEXTURE_2D:
624 obj = texUnit->CurrentD[2];
625 break;
626 case GL_TEXTURE_3D_EXT:
627 obj = texUnit->CurrentD[3];
628 break;
629 default:
630 gl_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(target)");
631 return;
632 }
633
634 switch (pname) {
635 case GL_TEXTURE_MAG_FILTER:
636 *params = (GLint) obj->MagFilter;
637 break;
638 case GL_TEXTURE_MIN_FILTER:
639 *params = (GLint) obj->MinFilter;
640 break;
641 case GL_TEXTURE_WRAP_S:
642 *params = (GLint) obj->WrapS;
643 break;
644 case GL_TEXTURE_WRAP_T:
645 *params = (GLint) obj->WrapT;
646 break;
647 case GL_TEXTURE_WRAP_R_EXT:
648 *params = (GLint) obj->WrapR;
649 break;
650 case GL_TEXTURE_BORDER_COLOR:
651 {
652 GLfloat color[4];
653 color[0] = obj->BorderColor[0] / 255.0F;
654 color[1] = obj->BorderColor[1] / 255.0F;
655 color[2] = obj->BorderColor[2] / 255.0F;
656 color[3] = obj->BorderColor[3] / 255.0F;
657 params[0] = FLOAT_TO_INT( color[0] );
658 params[1] = FLOAT_TO_INT( color[1] );
659 params[2] = FLOAT_TO_INT( color[2] );
660 params[3] = FLOAT_TO_INT( color[3] );
661 }
662 break;
663 case GL_TEXTURE_RESIDENT:
664 *params = (GLint) GL_TRUE;
665 break;
666 case GL_TEXTURE_PRIORITY:
667 *params = (GLint) obj->Priority;
668 break;
669 case GL_TEXTURE_MIN_LOD:
670 *params = (GLint) obj->MinLod;
671 break;
672 case GL_TEXTURE_MAX_LOD:
673 *params = (GLint) obj->MaxLod;
674 break;
675 case GL_TEXTURE_BASE_LEVEL:
676 *params = obj->BaseLevel;
677 break;
678 case GL_TEXTURE_MAX_LEVEL:
679 *params = obj->MaxLevel;
680 break;
681 default:
682 gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname)" );
683 }
684 }
685
686
687
688
689 /**********************************************************************/
690 /* Texture Coord Generation */
691 /**********************************************************************/
692
693
694 void
695 _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
696 {
697 GET_CURRENT_CONTEXT(ctx);
698 GLuint tUnit = ctx->Texture.CurrentTransformUnit;
699 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
700 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexGenfv");
701
702 if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
703 fprintf(stderr, "texGEN %s %s %x...\n",
704 gl_lookup_enum_by_nr(coord),
705 gl_lookup_enum_by_nr(pname),
706 *(int *)params);
707
708 switch (coord) {
709 case GL_S:
710 if (pname==GL_TEXTURE_GEN_MODE) {
711 GLenum mode = (GLenum) (GLint) *params;
712 switch (mode) {
713 case GL_OBJECT_LINEAR:
714 texUnit->GenModeS = mode;
715 texUnit->GenBitS = TEXGEN_OBJ_LINEAR;
716 break;
717 case GL_EYE_LINEAR:
718 texUnit->GenModeS = mode;
719 texUnit->GenBitS = TEXGEN_EYE_LINEAR;
720 break;
721 case GL_REFLECTION_MAP_NV:
722 texUnit->GenModeS = mode;
723 texUnit->GenBitS = TEXGEN_REFLECTION_MAP_NV;
724 break;
725 case GL_NORMAL_MAP_NV:
726 texUnit->GenModeS = mode;
727 texUnit->GenBitS = TEXGEN_NORMAL_MAP_NV;
728 break;
729 case GL_SPHERE_MAP:
730 texUnit->GenModeS = mode;
731 texUnit->GenBitS = TEXGEN_SPHERE_MAP;
732 break;
733 default:
734 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
735 return;
736 }
737 }
738 else if (pname==GL_OBJECT_PLANE) {
739 texUnit->ObjectPlaneS[0] = params[0];
740 texUnit->ObjectPlaneS[1] = params[1];
741 texUnit->ObjectPlaneS[2] = params[2];
742 texUnit->ObjectPlaneS[3] = params[3];
743 }
744 else if (pname==GL_EYE_PLANE) {
745 /* Transform plane equation by the inverse modelview matrix */
746 if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) {
747 gl_matrix_analyze( &ctx->ModelView );
748 }
749 gl_transform_vector( texUnit->EyePlaneS, params,
750 ctx->ModelView.inv );
751 }
752 else {
753 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
754 return;
755 }
756 break;
757 case GL_T:
758 if (pname==GL_TEXTURE_GEN_MODE) {
759 GLenum mode = (GLenum) (GLint) *params;
760 switch(mode) {
761 case GL_OBJECT_LINEAR:
762 texUnit->GenModeT = GL_OBJECT_LINEAR;
763 texUnit->GenBitT = TEXGEN_OBJ_LINEAR;
764 break;
765 case GL_EYE_LINEAR:
766 texUnit->GenModeT = GL_EYE_LINEAR;
767 texUnit->GenBitT = TEXGEN_EYE_LINEAR;
768 break;
769 case GL_REFLECTION_MAP_NV:
770 texUnit->GenModeT = GL_REFLECTION_MAP_NV;
771 texUnit->GenBitT = TEXGEN_REFLECTION_MAP_NV;
772 break;
773 case GL_NORMAL_MAP_NV:
774 texUnit->GenModeT = GL_NORMAL_MAP_NV;
775 texUnit->GenBitT = TEXGEN_NORMAL_MAP_NV;
776 break;
777 case GL_SPHERE_MAP:
778 texUnit->GenModeT = GL_SPHERE_MAP;
779 texUnit->GenBitT = TEXGEN_SPHERE_MAP;
780 break;
781 default:
782 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
783 return;
784 }
785 }
786 else if (pname==GL_OBJECT_PLANE) {
787 texUnit->ObjectPlaneT[0] = params[0];
788 texUnit->ObjectPlaneT[1] = params[1];
789 texUnit->ObjectPlaneT[2] = params[2];
790 texUnit->ObjectPlaneT[3] = params[3];
791 }
792 else if (pname==GL_EYE_PLANE) {
793 /* Transform plane equation by the inverse modelview matrix */
794 if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) {
795 gl_matrix_analyze( &ctx->ModelView );
796 }
797 gl_transform_vector( texUnit->EyePlaneT, params,
798 ctx->ModelView.inv );
799 }
800 else {
801 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
802 return;
803 }
804 break;
805 case GL_R:
806 if (pname==GL_TEXTURE_GEN_MODE) {
807 GLenum mode = (GLenum) (GLint) *params;
808 switch (mode) {
809 case GL_OBJECT_LINEAR:
810 texUnit->GenModeR = GL_OBJECT_LINEAR;
811 texUnit->GenBitR = TEXGEN_OBJ_LINEAR;
812 break;
813 case GL_REFLECTION_MAP_NV:
814 texUnit->GenModeR = GL_REFLECTION_MAP_NV;
815 texUnit->GenBitR = TEXGEN_REFLECTION_MAP_NV;
816 break;
817 case GL_NORMAL_MAP_NV:
818 texUnit->GenModeR = GL_NORMAL_MAP_NV;
819 texUnit->GenBitR = TEXGEN_NORMAL_MAP_NV;
820 break;
821 case GL_EYE_LINEAR:
822 texUnit->GenModeR = GL_EYE_LINEAR;
823 texUnit->GenBitR = TEXGEN_EYE_LINEAR;
824 break;
825 default:
826 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
827 return;
828 }
829 }
830 else if (pname==GL_OBJECT_PLANE) {
831 texUnit->ObjectPlaneR[0] = params[0];
832 texUnit->ObjectPlaneR[1] = params[1];
833 texUnit->ObjectPlaneR[2] = params[2];
834 texUnit->ObjectPlaneR[3] = params[3];
835 }
836 else if (pname==GL_EYE_PLANE) {
837 /* Transform plane equation by the inverse modelview matrix */
838 if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) {
839 gl_matrix_analyze( &ctx->ModelView );
840 }
841 gl_transform_vector( texUnit->EyePlaneR, params,
842 ctx->ModelView.inv );
843 }
844 else {
845 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
846 return;
847 }
848 break;
849 case GL_Q:
850 if (pname==GL_TEXTURE_GEN_MODE) {
851 GLenum mode = (GLenum) (GLint) *params;
852 switch (mode) {
853 case GL_OBJECT_LINEAR:
854 texUnit->GenModeQ = GL_OBJECT_LINEAR;
855 texUnit->GenBitQ = TEXGEN_OBJ_LINEAR;
856 break;
857 case GL_EYE_LINEAR:
858 texUnit->GenModeQ = GL_EYE_LINEAR;
859 texUnit->GenBitQ = TEXGEN_EYE_LINEAR;
860 break;
861 default:
862 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
863 return;
864 }
865 }
866 else if (pname==GL_OBJECT_PLANE) {
867 texUnit->ObjectPlaneQ[0] = params[0];
868 texUnit->ObjectPlaneQ[1] = params[1];
869 texUnit->ObjectPlaneQ[2] = params[2];
870 texUnit->ObjectPlaneQ[3] = params[3];
871 }
872 else if (pname==GL_EYE_PLANE) {
873 /* Transform plane equation by the inverse modelview matrix */
874 if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) {
875 gl_matrix_analyze( &ctx->ModelView );
876 }
877 gl_transform_vector( texUnit->EyePlaneQ, params,
878 ctx->ModelView.inv );
879 }
880 else {
881 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
882 return;
883 }
884 break;
885 default:
886 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(coord)" );
887 return;
888 }
889
890 ctx->NewState |= NEW_TEXTURING;
891 }
892
893
894 void
895 _mesa_TexGeniv(GLenum coord, GLenum pname, const GLint *params )
896 {
897 GLfloat p[4];
898 p[0] = params[0];
899 p[1] = params[1];
900 p[2] = params[2];
901 p[3] = params[3];
902 _mesa_TexGenfv(coord, pname, p);
903 }
904
905
906 void
907 _mesa_TexGend(GLenum coord, GLenum pname, GLdouble param )
908 {
909 GLfloat p = (GLfloat) param;
910 _mesa_TexGenfv( coord, pname, &p );
911 }
912
913
914 void
915 _mesa_TexGendv(GLenum coord, GLenum pname, const GLdouble *params )
916 {
917 GLfloat p[4];
918 p[0] = params[0];
919 p[1] = params[1];
920 p[2] = params[2];
921 p[3] = params[3];
922 _mesa_TexGenfv( coord, pname, p );
923 }
924
925
926 void
927 _mesa_TexGenf( GLenum coord, GLenum pname, GLfloat param )
928 {
929 _mesa_TexGenfv(coord, pname, &param);
930 }
931
932
933 void
934 _mesa_TexGeni( GLenum coord, GLenum pname, GLint param )
935 {
936 _mesa_TexGeniv( coord, pname, &param );
937 }
938
939
940
941 void
942 _mesa_GetTexGendv( GLenum coord, GLenum pname, GLdouble *params )
943 {
944 GET_CURRENT_CONTEXT(ctx);
945 GLuint tUnit = ctx->Texture.CurrentTransformUnit;
946 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
947
948 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexGendv");
949
950 switch( coord ) {
951 case GL_S:
952 if (pname==GL_TEXTURE_GEN_MODE) {
953 params[0] = ENUM_TO_DOUBLE(texUnit->GenModeS);
954 }
955 else if (pname==GL_OBJECT_PLANE) {
956 COPY_4V( params, texUnit->ObjectPlaneS );
957 }
958 else if (pname==GL_EYE_PLANE) {
959 COPY_4V( params, texUnit->EyePlaneS );
960 }
961 else {
962 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
963 return;
964 }
965 break;
966 case GL_T:
967 if (pname==GL_TEXTURE_GEN_MODE) {
968 params[0] = ENUM_TO_DOUBLE(texUnit->GenModeT);
969 }
970 else if (pname==GL_OBJECT_PLANE) {
971 COPY_4V( params, texUnit->ObjectPlaneT );
972 }
973 else if (pname==GL_EYE_PLANE) {
974 COPY_4V( params, texUnit->EyePlaneT );
975 }
976 else {
977 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
978 return;
979 }
980 break;
981 case GL_R:
982 if (pname==GL_TEXTURE_GEN_MODE) {
983 params[0] = ENUM_TO_DOUBLE(texUnit->GenModeR);
984 }
985 else if (pname==GL_OBJECT_PLANE) {
986 COPY_4V( params, texUnit->ObjectPlaneR );
987 }
988 else if (pname==GL_EYE_PLANE) {
989 COPY_4V( params, texUnit->EyePlaneR );
990 }
991 else {
992 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
993 return;
994 }
995 break;
996 case GL_Q:
997 if (pname==GL_TEXTURE_GEN_MODE) {
998 params[0] = ENUM_TO_DOUBLE(texUnit->GenModeQ);
999 }
1000 else if (pname==GL_OBJECT_PLANE) {
1001 COPY_4V( params, texUnit->ObjectPlaneQ );
1002 }
1003 else if (pname==GL_EYE_PLANE) {
1004 COPY_4V( params, texUnit->EyePlaneQ );
1005 }
1006 else {
1007 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
1008 return;
1009 }
1010 break;
1011 default:
1012 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(coord)" );
1013 return;
1014 }
1015 }
1016
1017
1018
1019 void
1020 _mesa_GetTexGenfv( GLenum coord, GLenum pname, GLfloat *params )
1021 {
1022 GET_CURRENT_CONTEXT(ctx);
1023 GLuint tUnit = ctx->Texture.CurrentTransformUnit;
1024 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
1025
1026 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexGenfv");
1027
1028 switch( coord ) {
1029 case GL_S:
1030 if (pname==GL_TEXTURE_GEN_MODE) {
1031 params[0] = ENUM_TO_FLOAT(texUnit->GenModeS);
1032 }
1033 else if (pname==GL_OBJECT_PLANE) {
1034 COPY_4V( params, texUnit->ObjectPlaneS );
1035 }
1036 else if (pname==GL_EYE_PLANE) {
1037 COPY_4V( params, texUnit->EyePlaneS );
1038 }
1039 else {
1040 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
1041 return;
1042 }
1043 break;
1044 case GL_T:
1045 if (pname==GL_TEXTURE_GEN_MODE) {
1046 params[0] = ENUM_TO_FLOAT(texUnit->GenModeT);
1047 }
1048 else if (pname==GL_OBJECT_PLANE) {
1049 COPY_4V( params, texUnit->ObjectPlaneT );
1050 }
1051 else if (pname==GL_EYE_PLANE) {
1052 COPY_4V( params, texUnit->EyePlaneT );
1053 }
1054 else {
1055 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
1056 return;
1057 }
1058 break;
1059 case GL_R:
1060 if (pname==GL_TEXTURE_GEN_MODE) {
1061 params[0] = ENUM_TO_FLOAT(texUnit->GenModeR);
1062 }
1063 else if (pname==GL_OBJECT_PLANE) {
1064 COPY_4V( params, texUnit->ObjectPlaneR );
1065 }
1066 else if (pname==GL_EYE_PLANE) {
1067 COPY_4V( params, texUnit->EyePlaneR );
1068 }
1069 else {
1070 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
1071 return;
1072 }
1073 break;
1074 case GL_Q:
1075 if (pname==GL_TEXTURE_GEN_MODE) {
1076 params[0] = ENUM_TO_FLOAT(texUnit->GenModeQ);
1077 }
1078 else if (pname==GL_OBJECT_PLANE) {
1079 COPY_4V( params, texUnit->ObjectPlaneQ );
1080 }
1081 else if (pname==GL_EYE_PLANE) {
1082 COPY_4V( params, texUnit->EyePlaneQ );
1083 }
1084 else {
1085 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
1086 return;
1087 }
1088 break;
1089 default:
1090 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(coord)" );
1091 return;
1092 }
1093 }
1094
1095
1096
1097 void
1098 _mesa_GetTexGeniv( GLenum coord, GLenum pname, GLint *params )
1099 {
1100 GET_CURRENT_CONTEXT(ctx);
1101 GLuint tUnit = ctx->Texture.CurrentTransformUnit;
1102 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
1103
1104 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexGeniv");
1105
1106 switch( coord ) {
1107 case GL_S:
1108 if (pname==GL_TEXTURE_GEN_MODE) {
1109 params[0] = texUnit->GenModeS;
1110 }
1111 else if (pname==GL_OBJECT_PLANE) {
1112 params[0] = (GLint) texUnit->ObjectPlaneS[0];
1113 params[1] = (GLint) texUnit->ObjectPlaneS[1];
1114 params[2] = (GLint) texUnit->ObjectPlaneS[2];
1115 params[3] = (GLint) texUnit->ObjectPlaneS[3];
1116 }
1117 else if (pname==GL_EYE_PLANE) {
1118 params[0] = (GLint) texUnit->EyePlaneS[0];
1119 params[1] = (GLint) texUnit->EyePlaneS[1];
1120 params[2] = (GLint) texUnit->EyePlaneS[2];
1121 params[3] = (GLint) texUnit->EyePlaneS[3];
1122 }
1123 else {
1124 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
1125 return;
1126 }
1127 break;
1128 case GL_T:
1129 if (pname==GL_TEXTURE_GEN_MODE) {
1130 params[0] = texUnit->GenModeT;
1131 }
1132 else if (pname==GL_OBJECT_PLANE) {
1133 params[0] = (GLint) texUnit->ObjectPlaneT[0];
1134 params[1] = (GLint) texUnit->ObjectPlaneT[1];
1135 params[2] = (GLint) texUnit->ObjectPlaneT[2];
1136 params[3] = (GLint) texUnit->ObjectPlaneT[3];
1137 }
1138 else if (pname==GL_EYE_PLANE) {
1139 params[0] = (GLint) texUnit->EyePlaneT[0];
1140 params[1] = (GLint) texUnit->EyePlaneT[1];
1141 params[2] = (GLint) texUnit->EyePlaneT[2];
1142 params[3] = (GLint) texUnit->EyePlaneT[3];
1143 }
1144 else {
1145 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
1146 return;
1147 }
1148 break;
1149 case GL_R:
1150 if (pname==GL_TEXTURE_GEN_MODE) {
1151 params[0] = texUnit->GenModeR;
1152 }
1153 else if (pname==GL_OBJECT_PLANE) {
1154 params[0] = (GLint) texUnit->ObjectPlaneR[0];
1155 params[1] = (GLint) texUnit->ObjectPlaneR[1];
1156 params[2] = (GLint) texUnit->ObjectPlaneR[2];
1157 params[3] = (GLint) texUnit->ObjectPlaneR[3];
1158 }
1159 else if (pname==GL_EYE_PLANE) {
1160 params[0] = (GLint) texUnit->EyePlaneR[0];
1161 params[1] = (GLint) texUnit->EyePlaneR[1];
1162 params[2] = (GLint) texUnit->EyePlaneR[2];
1163 params[3] = (GLint) texUnit->EyePlaneR[3];
1164 }
1165 else {
1166 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
1167 return;
1168 }
1169 break;
1170 case GL_Q:
1171 if (pname==GL_TEXTURE_GEN_MODE) {
1172 params[0] = texUnit->GenModeQ;
1173 }
1174 else if (pname==GL_OBJECT_PLANE) {
1175 params[0] = (GLint) texUnit->ObjectPlaneQ[0];
1176 params[1] = (GLint) texUnit->ObjectPlaneQ[1];
1177 params[2] = (GLint) texUnit->ObjectPlaneQ[2];
1178 params[3] = (GLint) texUnit->ObjectPlaneQ[3];
1179 }
1180 else if (pname==GL_EYE_PLANE) {
1181 params[0] = (GLint) texUnit->EyePlaneQ[0];
1182 params[1] = (GLint) texUnit->EyePlaneQ[1];
1183 params[2] = (GLint) texUnit->EyePlaneQ[2];
1184 params[3] = (GLint) texUnit->EyePlaneQ[3];
1185 }
1186 else {
1187 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
1188 return;
1189 }
1190 break;
1191 default:
1192 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(coord)" );
1193 return;
1194 }
1195 }
1196
1197
1198 /* GL_ARB_multitexture */
1199 void
1200 _mesa_ActiveTextureARB( GLenum target )
1201 {
1202 GET_CURRENT_CONTEXT(ctx);
1203 GLint maxUnits = ctx->Const.MaxTextureUnits;
1204
1205 ASSERT_OUTSIDE_BEGIN_END( ctx, "glActiveTextureARB" );
1206
1207 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
1208 fprintf(stderr, "glActiveTexture %s\n",
1209 gl_lookup_enum_by_nr(target));
1210
1211 if (target >= GL_TEXTURE0_ARB && target < GL_TEXTURE0_ARB + maxUnits) {
1212 GLint texUnit = target - GL_TEXTURE0_ARB;
1213 ctx->Texture.CurrentUnit = texUnit;
1214 ctx->Texture.CurrentTransformUnit = texUnit;
1215 if (ctx->Driver.ActiveTexture) {
1216 (*ctx->Driver.ActiveTexture)( ctx, (GLuint) texUnit );
1217 }
1218 }
1219 else {
1220 gl_error(ctx, GL_INVALID_OPERATION, "glActiveTextureARB(target)");
1221 }
1222 }
1223
1224
1225 /* GL_ARB_multitexture */
1226 void
1227 _mesa_ClientActiveTextureARB( GLenum target )
1228 {
1229 GET_CURRENT_CONTEXT(ctx);
1230 GLint maxUnits = ctx->Const.MaxTextureUnits;
1231
1232 ASSERT_OUTSIDE_BEGIN_END( ctx, "glClientActiveTextureARB" );
1233
1234 if (target >= GL_TEXTURE0_ARB && target < GL_TEXTURE0_ARB + maxUnits) {
1235 GLint texUnit = target - GL_TEXTURE0_ARB;
1236 ctx->Array.ActiveTexture = texUnit;
1237 }
1238 else {
1239 gl_error(ctx, GL_INVALID_OPERATION, "glActiveTextureARB(target)");
1240 }
1241 }
1242
1243
1244
1245 /*
1246 * Put the given texture object into the list of dirty texture objects.
1247 * When a texture object is dirty we have to reexamine it for completeness
1248 * and perhaps choose a different texture sampling function.
1249 */
1250 void gl_put_texobj_on_dirty_list( GLcontext *ctx, struct gl_texture_object *t )
1251 {
1252 ASSERT(ctx);
1253 ASSERT(t);
1254 /* Only insert if not already in the dirty list.
1255 * The Dirty flag is only set iff the texture object is in the dirty list.
1256 */
1257 if (!t->Dirty) {
1258 ASSERT(t->NextDirty == NULL);
1259 t->Dirty = GL_TRUE;
1260 t->NextDirty = ctx->Shared->DirtyTexObjList;
1261 ctx->Shared->DirtyTexObjList = t;
1262 }
1263 #ifdef DEBUG
1264 else {
1265 /* make sure t is in the list */
1266 struct gl_texture_object *obj = ctx->Shared->DirtyTexObjList;
1267 while (obj) {
1268 if (obj == t) {
1269 return;
1270 }
1271 obj = obj->NextDirty;
1272 }
1273 gl_problem(ctx, "Error in gl_put_texobj_on_dirty_list");
1274 }
1275 #endif
1276 }
1277
1278
1279 /*
1280 * Remove a texture object from the dirty texture list.
1281 */
1282 void gl_remove_texobj_from_dirty_list( struct gl_shared_state *shared,
1283 struct gl_texture_object *tObj )
1284 {
1285 struct gl_texture_object *t, *prev = NULL;
1286 ASSERT(shared);
1287 ASSERT(tObj);
1288 for (t = shared->DirtyTexObjList; t; t = t->NextDirty) {
1289 if (t == tObj) {
1290 if (prev) {
1291 prev->NextDirty = t->NextDirty;
1292 }
1293 else {
1294 shared->DirtyTexObjList = t->NextDirty;
1295 }
1296 return;
1297 }
1298 prev = t;
1299 }
1300 }
1301
1302
1303 /*
1304 * This is called by gl_update_state() if the NEW_TEXTURING bit in
1305 * ctx->NewState is set.
1306 */
1307 void gl_update_dirty_texobjs( GLcontext *ctx )
1308 {
1309 struct gl_texture_object *t, *next;
1310 for (t = ctx->Shared->DirtyTexObjList; t; t = next) {
1311 next = t->NextDirty;
1312 gl_test_texture_object_completeness(ctx, t);
1313 gl_set_texture_sampler(t);
1314 t->NextDirty = NULL;
1315 t->Dirty = GL_FALSE;
1316 }
1317 ctx->Shared->DirtyTexObjList = NULL;
1318 }