2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Texture state handling.
36 #include "extensions.h"
38 #include "nvfragprog.h"
43 #include "math/m_xform.h"
44 #include "math/m_matrix.h"
49 /* Needed for an Amiga compiler */
50 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
51 #define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
53 /* all other compilers */
54 #define ENUM_TO_FLOAT(X) ((GLfloat)(X))
55 #define ENUM_TO_DOUBLE(X) ((GLdouble)(X))
59 * Default texture combine environment state. This is used to initialize
60 * a context's texture units and as the basis for converting "classic"
61 * texture environmnets to ARB_texture_env_combine style values.
63 static const struct gl_tex_env_combine_state default_combine_state
= {
64 GL_MODULATE
, GL_MODULATE
,
65 { GL_TEXTURE
, GL_PREVIOUS
, GL_CONSTANT
},
66 { GL_TEXTURE
, GL_PREVIOUS
, GL_CONSTANT
},
67 { GL_SRC_COLOR
, GL_SRC_COLOR
, GL_SRC_ALPHA
},
68 { GL_SRC_ALPHA
, GL_SRC_ALPHA
, GL_SRC_ALPHA
},
75 _mesa_copy_texture_state( const GLcontext
*src
, GLcontext
*dst
)
82 dst
->Texture
.CurrentUnit
= src
->Texture
.CurrentUnit
;
83 dst
->Texture
._GenFlags
= src
->Texture
._GenFlags
;
84 dst
->Texture
._TexGenEnabled
= src
->Texture
._TexGenEnabled
;
85 dst
->Texture
._TexMatEnabled
= src
->Texture
._TexMatEnabled
;
86 dst
->Texture
.SharedPalette
= src
->Texture
.SharedPalette
;
89 for (i
= 0; i
< src
->Const
.MaxTextureUnits
; i
++) {
90 dst
->Texture
.Unit
[i
].Enabled
= src
->Texture
.Unit
[i
].Enabled
;
91 dst
->Texture
.Unit
[i
].EnvMode
= src
->Texture
.Unit
[i
].EnvMode
;
92 COPY_4V(dst
->Texture
.Unit
[i
].EnvColor
, src
->Texture
.Unit
[i
].EnvColor
);
93 dst
->Texture
.Unit
[i
].TexGenEnabled
= src
->Texture
.Unit
[i
].TexGenEnabled
;
94 dst
->Texture
.Unit
[i
].GenModeS
= src
->Texture
.Unit
[i
].GenModeS
;
95 dst
->Texture
.Unit
[i
].GenModeT
= src
->Texture
.Unit
[i
].GenModeT
;
96 dst
->Texture
.Unit
[i
].GenModeR
= src
->Texture
.Unit
[i
].GenModeR
;
97 dst
->Texture
.Unit
[i
].GenModeQ
= src
->Texture
.Unit
[i
].GenModeQ
;
98 dst
->Texture
.Unit
[i
]._GenBitS
= src
->Texture
.Unit
[i
]._GenBitS
;
99 dst
->Texture
.Unit
[i
]._GenBitT
= src
->Texture
.Unit
[i
]._GenBitT
;
100 dst
->Texture
.Unit
[i
]._GenBitR
= src
->Texture
.Unit
[i
]._GenBitR
;
101 dst
->Texture
.Unit
[i
]._GenBitQ
= src
->Texture
.Unit
[i
]._GenBitQ
;
102 dst
->Texture
.Unit
[i
]._GenFlags
= src
->Texture
.Unit
[i
]._GenFlags
;
103 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneS
, src
->Texture
.Unit
[i
].ObjectPlaneS
);
104 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneT
, src
->Texture
.Unit
[i
].ObjectPlaneT
);
105 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneR
, src
->Texture
.Unit
[i
].ObjectPlaneR
);
106 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneQ
, src
->Texture
.Unit
[i
].ObjectPlaneQ
);
107 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneS
, src
->Texture
.Unit
[i
].EyePlaneS
);
108 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneT
, src
->Texture
.Unit
[i
].EyePlaneT
);
109 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneR
, src
->Texture
.Unit
[i
].EyePlaneR
);
110 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneQ
, src
->Texture
.Unit
[i
].EyePlaneQ
);
111 dst
->Texture
.Unit
[i
].LodBias
= src
->Texture
.Unit
[i
].LodBias
;
113 /* GL_EXT_texture_env_combine */
114 dst
->Texture
.Unit
[i
].Combine
.ModeRGB
= src
->Texture
.Unit
[i
].Combine
.ModeRGB
;
115 dst
->Texture
.Unit
[i
].Combine
.ModeA
= src
->Texture
.Unit
[i
].Combine
.ModeA
;
116 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.SourceRGB
, src
->Texture
.Unit
[i
].Combine
.SourceRGB
);
117 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.SourceA
, src
->Texture
.Unit
[i
].Combine
.SourceA
);
118 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.OperandRGB
, src
->Texture
.Unit
[i
].Combine
.OperandRGB
);
119 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.OperandA
, src
->Texture
.Unit
[i
].Combine
.OperandA
);
120 dst
->Texture
.Unit
[i
].Combine
.ScaleShiftRGB
= src
->Texture
.Unit
[i
].Combine
.ScaleShiftRGB
;
121 dst
->Texture
.Unit
[i
].Combine
.ScaleShiftA
= src
->Texture
.Unit
[i
].Combine
.ScaleShiftA
;
123 /* texture object state */
124 _mesa_copy_texture_object(dst
->Texture
.Unit
[i
].Current1D
,
125 src
->Texture
.Unit
[i
].Current1D
);
126 _mesa_copy_texture_object(dst
->Texture
.Unit
[i
].Current2D
,
127 src
->Texture
.Unit
[i
].Current2D
);
128 _mesa_copy_texture_object(dst
->Texture
.Unit
[i
].Current3D
,
129 src
->Texture
.Unit
[i
].Current3D
);
130 _mesa_copy_texture_object(dst
->Texture
.Unit
[i
].CurrentCubeMap
,
131 src
->Texture
.Unit
[i
].CurrentCubeMap
);
132 _mesa_copy_texture_object(dst
->Texture
.Unit
[i
].CurrentRect
,
133 src
->Texture
.Unit
[i
].CurrentRect
);
142 _mesa_print_texunit_state( GLcontext
*ctx
, GLuint unit
)
144 const struct gl_texture_unit
*texUnit
= ctx
->Texture
.Unit
+ unit
;
145 _mesa_printf("Texture Unit %d\n", unit
);
146 _mesa_printf(" GL_TEXTURE_ENV_MODE = %s\n", _mesa_lookup_enum_by_nr(texUnit
->EnvMode
));
147 _mesa_printf(" GL_COMBINE_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.ModeRGB
));
148 _mesa_printf(" GL_COMBINE_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.ModeA
));
149 _mesa_printf(" GL_SOURCE0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceRGB
[0]));
150 _mesa_printf(" GL_SOURCE1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceRGB
[1]));
151 _mesa_printf(" GL_SOURCE2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceRGB
[2]));
152 _mesa_printf(" GL_SOURCE0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceA
[0]));
153 _mesa_printf(" GL_SOURCE1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceA
[1]));
154 _mesa_printf(" GL_SOURCE2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceA
[2]));
155 _mesa_printf(" GL_OPERAND0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandRGB
[0]));
156 _mesa_printf(" GL_OPERAND1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandRGB
[1]));
157 _mesa_printf(" GL_OPERAND2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandRGB
[2]));
158 _mesa_printf(" GL_OPERAND0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandA
[0]));
159 _mesa_printf(" GL_OPERAND1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandA
[1]));
160 _mesa_printf(" GL_OPERAND2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandA
[2]));
161 _mesa_printf(" GL_RGB_SCALE = %d\n", 1 << texUnit
->Combine
.ScaleShiftRGB
);
162 _mesa_printf(" GL_ALPHA_SCALE = %d\n", 1 << texUnit
->Combine
.ScaleShiftA
);
163 _mesa_printf(" GL_TEXTURE_ENV_COLOR = (%f, %f, %f, %f)\n", texUnit
->EnvColor
[0], texUnit
->EnvColor
[1], texUnit
->EnvColor
[2], texUnit
->EnvColor
[3]);
168 /**********************************************************************/
169 /* Texture Environment */
170 /**********************************************************************/
173 * Convert "classic" texture environment to ARB_texture_env_combine style
176 * \param state texture_env_combine state vector to be filled-in.
177 * \param mode Classic texture environment mode (i.e., \c GL_REPLACE,
178 * \c GL_BLEND, \c GL_DECAL, etc.).
179 * \param tex_base_format Base format of the texture associated with the
183 calculate_derived_texenv( struct gl_tex_env_combine_state
* state
,
184 GLenum mode
, GLenum tex_base_format
)
189 *state
= default_combine_state
;
191 switch( tex_base_format
) {
193 state
->SourceRGB
[0] = GL_PREVIOUS
;
196 case GL_LUMINANCE_ALPHA
:
204 state
->SourceA
[0] = GL_PREVIOUS
;
208 state
->SourceRGB
[0] = GL_PREVIOUS
;
209 state
->SourceA
[0] = GL_PREVIOUS
;
210 state
->ModeRGB
= GL_REPLACE
;
211 state
->ModeA
= GL_REPLACE
;
219 mode_rgb
= (tex_base_format
== GL_ALPHA
) ? GL_REPLACE
: mode
;
224 mode_rgb
= GL_INTERPOLATE
;
227 state
->SourceA
[0] = GL_PREVIOUS
;
229 /* Having alpha / luminance / intensity textures replace using the
230 * incoming fragment color matches the definition in NV_texture_shader.
231 * The 1.5 spec simply marks these as "undefined".
233 switch( tex_base_format
) {
236 case GL_LUMINANCE_ALPHA
:
238 state
->SourceRGB
[0] = GL_PREVIOUS
;
242 mode_rgb
= GL_REPLACE
;
245 state
->SourceRGB
[2] = GL_TEXTURE
;
251 mode_rgb
= GL_INTERPOLATE
;
252 mode_a
= GL_MODULATE
;
254 switch( tex_base_format
) {
256 mode_rgb
= GL_REPLACE
;
259 mode_a
= GL_INTERPOLATE
;
263 case GL_LUMINANCE_ALPHA
:
266 state
->SourceRGB
[2] = GL_TEXTURE
;
267 state
->SourceA
[2] = GL_TEXTURE
;
268 state
->SourceRGB
[0] = GL_CONSTANT
;
269 state
->OperandRGB
[2] = GL_SRC_COLOR
;
275 mode_rgb
= (tex_base_format
== GL_ALPHA
) ? GL_REPLACE
: GL_ADD
;
276 mode_a
= (tex_base_format
== GL_INTENSITY
) ? GL_ADD
: GL_MODULATE
;
280 mode_rgb
= GL_REPLACE
;
286 state
->ModeRGB
= (state
->SourceRGB
[0] != GL_PREVIOUS
)
287 ? mode_rgb
: GL_REPLACE
;
288 state
->ModeA
= (state
->SourceA
[0] != GL_PREVIOUS
)
289 ? mode_a
: GL_REPLACE
;
293 _mesa_TexEnvfv( GLenum target
, GLenum pname
, const GLfloat
*param
)
295 GET_CURRENT_CONTEXT(ctx
);
296 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
297 ASSERT_OUTSIDE_BEGIN_END(ctx
);
299 #define TE_ERROR(errCode, msg, value) \
300 _mesa_error(ctx, errCode, msg, _mesa_lookup_enum_by_nr(value));
302 if (target
== GL_TEXTURE_ENV
) {
304 case GL_TEXTURE_ENV_MODE
:
306 const GLenum mode
= (GLenum
) (GLint
) *param
;
307 if (mode
== GL_MODULATE
||
310 mode
== GL_REPLACE
||
311 (mode
== GL_ADD
&& ctx
->Extensions
.EXT_texture_env_add
) ||
312 (mode
== GL_COMBINE
&&
313 (ctx
->Extensions
.EXT_texture_env_combine
||
314 ctx
->Extensions
.ARB_texture_env_combine
))) {
316 if (texUnit
->EnvMode
== mode
)
318 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
319 texUnit
->EnvMode
= mode
;
321 /* FIXME: Is this needed here or is having it in
322 * FIXME: update_texture_state enough?
324 if ( mode
== GL_COMBINE
) {
325 texUnit
->_CurrentCombine
= & texUnit
->Combine
;
327 else if ( texUnit
->_Current
!= NULL
) {
328 calculate_derived_texenv( & texUnit
->_EnvMode
, mode
,
329 texUnit
->_Current
->Image
[0][0]->Format
);
330 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
334 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
339 case GL_TEXTURE_ENV_COLOR
:
342 tmp
[0] = CLAMP( param
[0], 0.0F
, 1.0F
);
343 tmp
[1] = CLAMP( param
[1], 0.0F
, 1.0F
);
344 tmp
[2] = CLAMP( param
[2], 0.0F
, 1.0F
);
345 tmp
[3] = CLAMP( param
[3], 0.0F
, 1.0F
);
346 if (TEST_EQ_4V(tmp
, texUnit
->EnvColor
))
348 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
349 COPY_4FV(texUnit
->EnvColor
, tmp
);
353 if (ctx
->Extensions
.EXT_texture_env_combine
||
354 ctx
->Extensions
.ARB_texture_env_combine
) {
355 const GLenum mode
= (GLenum
) (GLint
) *param
;
365 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
366 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
370 case GL_DOT3_RGB_EXT
:
371 case GL_DOT3_RGBA_EXT
:
372 if (!ctx
->Extensions
.EXT_texture_env_dot3
) {
373 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
379 if (!ctx
->Extensions
.ARB_texture_env_dot3
) {
380 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
384 case GL_MODULATE_ADD_ATI
:
385 case GL_MODULATE_SIGNED_ADD_ATI
:
386 case GL_MODULATE_SUBTRACT_ATI
:
387 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
388 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
393 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
396 if (texUnit
->Combine
.ModeRGB
== mode
)
398 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
399 texUnit
->Combine
.ModeRGB
= mode
;
402 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
406 case GL_COMBINE_ALPHA
:
407 if (ctx
->Extensions
.EXT_texture_env_combine
||
408 ctx
->Extensions
.ARB_texture_env_combine
) {
409 const GLenum mode
= (GLenum
) (GLint
) *param
;
419 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
420 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
424 case GL_MODULATE_ADD_ATI
:
425 case GL_MODULATE_SIGNED_ADD_ATI
:
426 case GL_MODULATE_SUBTRACT_ATI
:
427 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
428 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
433 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
437 if (texUnit
->Combine
.ModeA
== mode
)
439 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
440 texUnit
->Combine
.ModeA
= mode
;
443 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
450 if (ctx
->Extensions
.EXT_texture_env_combine
||
451 ctx
->Extensions
.ARB_texture_env_combine
) {
452 const GLenum source
= (GLenum
) (GLint
) *param
;
453 const GLuint s
= pname
- GL_SOURCE0_RGB
;
454 if (source
== GL_TEXTURE
||
455 source
== GL_CONSTANT
||
456 source
== GL_PRIMARY_COLOR
||
457 source
== GL_PREVIOUS
||
458 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
459 source
>= GL_TEXTURE0
&&
460 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
461 (ctx
->Extensions
.ATI_texture_env_combine3
&&
462 (source
== GL_ZERO
|| source
== GL_ONE
))) {
464 if (texUnit
->Combine
.SourceRGB
[s
] == source
)
466 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
467 texUnit
->Combine
.SourceRGB
[s
] = source
;
470 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
475 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
479 case GL_SOURCE0_ALPHA
:
480 case GL_SOURCE1_ALPHA
:
481 case GL_SOURCE2_ALPHA
:
482 if (ctx
->Extensions
.EXT_texture_env_combine
||
483 ctx
->Extensions
.ARB_texture_env_combine
) {
484 const GLenum source
= (GLenum
) (GLint
) *param
;
485 const GLuint s
= pname
- GL_SOURCE0_ALPHA
;
486 if (source
== GL_TEXTURE
||
487 source
== GL_CONSTANT
||
488 source
== GL_PRIMARY_COLOR
||
489 source
== GL_PREVIOUS
||
490 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
491 source
>= GL_TEXTURE0
&&
492 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
493 (ctx
->Extensions
.ATI_texture_env_combine3
&&
494 (source
== GL_ZERO
|| source
== GL_ONE
))) {
496 if (texUnit
->Combine
.SourceA
[s
] == source
)
498 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
499 texUnit
->Combine
.SourceA
[s
] = source
;
502 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
507 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
511 case GL_OPERAND0_RGB
:
512 case GL_OPERAND1_RGB
:
513 if (ctx
->Extensions
.EXT_texture_env_combine
||
514 ctx
->Extensions
.ARB_texture_env_combine
) {
515 const GLenum operand
= (GLenum
) (GLint
) *param
;
516 const GLuint s
= pname
- GL_OPERAND0_RGB
;
519 case GL_ONE_MINUS_SRC_COLOR
:
521 case GL_ONE_MINUS_SRC_ALPHA
:
522 if (texUnit
->Combine
.OperandRGB
[s
] == operand
)
524 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
525 texUnit
->Combine
.OperandRGB
[s
] = operand
;
528 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
533 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
537 case GL_OPERAND0_ALPHA
:
538 case GL_OPERAND1_ALPHA
:
539 if (ctx
->Extensions
.EXT_texture_env_combine
||
540 ctx
->Extensions
.ARB_texture_env_combine
) {
541 const GLenum operand
= (GLenum
) (GLint
) *param
;
544 case GL_ONE_MINUS_SRC_ALPHA
:
545 if (texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] ==
548 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
549 texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] = operand
;
552 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
557 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
561 case GL_OPERAND2_RGB
:
562 if (ctx
->Extensions
.EXT_texture_env_combine
||
563 ctx
->Extensions
.ARB_texture_env_combine
) {
564 const GLenum operand
= (GLenum
) (GLint
) *param
;
566 case GL_SRC_COLOR
: /* ARB combine only */
567 case GL_ONE_MINUS_SRC_COLOR
: /* ARB combine only */
569 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
570 if (texUnit
->Combine
.OperandRGB
[2] == operand
)
572 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
573 texUnit
->Combine
.OperandRGB
[2] = operand
;
576 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
581 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
585 case GL_OPERAND2_ALPHA
:
586 if (ctx
->Extensions
.EXT_texture_env_combine
||
587 ctx
->Extensions
.ARB_texture_env_combine
) {
588 const GLenum operand
= (GLenum
) (GLint
) *param
;
591 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
592 if (texUnit
->Combine
.OperandA
[2] == operand
)
594 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
595 texUnit
->Combine
.OperandA
[2] = operand
;
598 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
603 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
608 if (ctx
->Extensions
.EXT_texture_env_combine
||
609 ctx
->Extensions
.ARB_texture_env_combine
) {
614 else if (*param
== 2.0) {
617 else if (*param
== 4.0) {
621 _mesa_error( ctx
, GL_INVALID_VALUE
,
622 "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" );
625 if (texUnit
->Combine
.ScaleShiftRGB
== newshift
)
627 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
628 texUnit
->Combine
.ScaleShiftRGB
= newshift
;
631 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
636 if (ctx
->Extensions
.EXT_texture_env_combine
||
637 ctx
->Extensions
.ARB_texture_env_combine
) {
642 else if (*param
== 2.0) {
645 else if (*param
== 4.0) {
649 _mesa_error( ctx
, GL_INVALID_VALUE
,
650 "glTexEnv(GL_ALPHA_SCALE not 1, 2 or 4)" );
653 if (texUnit
->Combine
.ScaleShiftA
== newshift
)
655 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
656 texUnit
->Combine
.ScaleShiftA
= newshift
;
659 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
664 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
668 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
669 /* GL_EXT_texture_lod_bias */
670 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
671 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
674 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
675 if (texUnit
->LodBias
== param
[0])
677 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
678 texUnit
->LodBias
= param
[0];
681 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
685 else if (target
== GL_POINT_SPRITE_NV
) {
686 /* GL_ARB_point_sprite / GL_NV_point_sprite */
687 if (!ctx
->Extensions
.NV_point_sprite
688 && !ctx
->Extensions
.ARB_point_sprite
) {
689 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
692 if (pname
== GL_COORD_REPLACE_NV
) {
693 const GLenum value
= (GLenum
) param
[0];
694 if (value
== GL_TRUE
|| value
== GL_FALSE
) {
695 /* It's kind of weird to set point state via glTexEnv,
696 * but that's what the spec calls for.
698 const GLboolean state
= (GLboolean
) value
;
699 if (ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] == state
)
701 FLUSH_VERTICES(ctx
, _NEW_POINT
);
702 ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] = state
;
705 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param=0x%x)", value
);
710 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname=0x%x)", pname
);
715 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)",target
);
719 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
720 _mesa_debug(ctx
, "glTexEnv %s %s %.1f(%s) ...\n",
721 _mesa_lookup_enum_by_nr(target
),
722 _mesa_lookup_enum_by_nr(pname
),
724 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
726 /* Tell device driver about the new texture environment */
727 if (ctx
->Driver
.TexEnv
) {
728 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
734 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
736 _mesa_TexEnvfv( target
, pname
, ¶m
);
742 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
745 p
[0] = (GLfloat
) param
;
746 p
[1] = p
[2] = p
[3] = 0.0;
747 _mesa_TexEnvfv( target
, pname
, p
);
752 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
755 if (pname
== GL_TEXTURE_ENV_COLOR
) {
756 p
[0] = INT_TO_FLOAT( param
[0] );
757 p
[1] = INT_TO_FLOAT( param
[1] );
758 p
[2] = INT_TO_FLOAT( param
[2] );
759 p
[3] = INT_TO_FLOAT( param
[3] );
762 p
[0] = (GLfloat
) param
[0];
763 p
[1] = p
[2] = p
[3] = 0; /* init to zero, just to be safe */
765 _mesa_TexEnvfv( target
, pname
, p
);
770 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
772 GET_CURRENT_CONTEXT(ctx
);
773 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
774 ASSERT_OUTSIDE_BEGIN_END(ctx
);
776 if (target
== GL_TEXTURE_ENV
) {
778 case GL_TEXTURE_ENV_MODE
:
779 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
781 case GL_TEXTURE_ENV_COLOR
:
782 COPY_4FV( params
, texUnit
->EnvColor
);
785 if (ctx
->Extensions
.EXT_texture_env_combine
||
786 ctx
->Extensions
.ARB_texture_env_combine
) {
787 *params
= (GLfloat
) texUnit
->Combine
.ModeRGB
;
790 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
793 case GL_COMBINE_ALPHA
:
794 if (ctx
->Extensions
.EXT_texture_env_combine
||
795 ctx
->Extensions
.ARB_texture_env_combine
) {
796 *params
= (GLfloat
) texUnit
->Combine
.ModeA
;
799 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
803 if (ctx
->Extensions
.EXT_texture_env_combine
||
804 ctx
->Extensions
.ARB_texture_env_combine
) {
805 *params
= (GLfloat
) texUnit
->Combine
.SourceRGB
[0];
808 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
812 if (ctx
->Extensions
.EXT_texture_env_combine
||
813 ctx
->Extensions
.ARB_texture_env_combine
) {
814 *params
= (GLfloat
) texUnit
->Combine
.SourceRGB
[1];
817 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
821 if (ctx
->Extensions
.EXT_texture_env_combine
||
822 ctx
->Extensions
.ARB_texture_env_combine
) {
823 *params
= (GLfloat
) texUnit
->Combine
.SourceRGB
[2];
826 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
829 case GL_SOURCE0_ALPHA
:
830 if (ctx
->Extensions
.EXT_texture_env_combine
||
831 ctx
->Extensions
.ARB_texture_env_combine
) {
832 *params
= (GLfloat
) texUnit
->Combine
.SourceA
[0];
835 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
838 case GL_SOURCE1_ALPHA
:
839 if (ctx
->Extensions
.EXT_texture_env_combine
||
840 ctx
->Extensions
.ARB_texture_env_combine
) {
841 *params
= (GLfloat
) texUnit
->Combine
.SourceA
[1];
844 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
847 case GL_SOURCE2_ALPHA
:
848 if (ctx
->Extensions
.EXT_texture_env_combine
||
849 ctx
->Extensions
.ARB_texture_env_combine
) {
850 *params
= (GLfloat
) texUnit
->Combine
.SourceA
[2];
853 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
856 case GL_OPERAND0_RGB
:
857 if (ctx
->Extensions
.EXT_texture_env_combine
||
858 ctx
->Extensions
.ARB_texture_env_combine
) {
859 *params
= (GLfloat
) texUnit
->Combine
.OperandRGB
[0];
862 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
865 case GL_OPERAND1_RGB
:
866 if (ctx
->Extensions
.EXT_texture_env_combine
||
867 ctx
->Extensions
.ARB_texture_env_combine
) {
868 *params
= (GLfloat
) texUnit
->Combine
.OperandRGB
[1];
871 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
874 case GL_OPERAND2_RGB
:
875 if (ctx
->Extensions
.EXT_texture_env_combine
||
876 ctx
->Extensions
.ARB_texture_env_combine
) {
877 *params
= (GLfloat
) texUnit
->Combine
.OperandRGB
[2];
880 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
883 case GL_OPERAND0_ALPHA
:
884 if (ctx
->Extensions
.EXT_texture_env_combine
||
885 ctx
->Extensions
.ARB_texture_env_combine
) {
886 *params
= (GLfloat
) texUnit
->Combine
.OperandA
[0];
889 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
892 case GL_OPERAND1_ALPHA
:
893 if (ctx
->Extensions
.EXT_texture_env_combine
||
894 ctx
->Extensions
.ARB_texture_env_combine
) {
895 *params
= (GLfloat
) texUnit
->Combine
.OperandA
[1];
898 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
901 case GL_OPERAND2_ALPHA
:
902 if (ctx
->Extensions
.EXT_texture_env_combine
||
903 ctx
->Extensions
.ARB_texture_env_combine
) {
904 *params
= (GLfloat
) texUnit
->Combine
.OperandA
[2];
907 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
911 if (ctx
->Extensions
.EXT_texture_env_combine
||
912 ctx
->Extensions
.ARB_texture_env_combine
) {
913 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
915 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
921 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
926 if (ctx
->Extensions
.EXT_texture_env_combine
||
927 ctx
->Extensions
.ARB_texture_env_combine
) {
928 if (texUnit
->Combine
.ScaleShiftA
== 0)
930 else if (texUnit
->Combine
.ScaleShiftA
== 1)
936 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
941 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname=0x%x)", pname
);
944 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
945 /* GL_EXT_texture_lod_bias */
946 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
947 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
950 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
951 *params
= texUnit
->LodBias
;
954 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
958 else if (target
== GL_POINT_SPRITE_NV
) {
959 /* GL_ARB_point_sprite / GL_NV_point_sprite */
960 if (!ctx
->Extensions
.NV_point_sprite
961 && !ctx
->Extensions
.ARB_point_sprite
) {
962 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
965 if (pname
== GL_COORD_REPLACE_NV
) {
966 *params
= (GLfloat
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
969 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
974 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
981 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
983 GET_CURRENT_CONTEXT(ctx
);
984 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
985 ASSERT_OUTSIDE_BEGIN_END(ctx
);
987 if (target
== GL_TEXTURE_ENV
) {
989 case GL_TEXTURE_ENV_MODE
:
990 *params
= (GLint
) texUnit
->EnvMode
;
992 case GL_TEXTURE_ENV_COLOR
:
993 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
994 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
995 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
996 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
999 if (ctx
->Extensions
.EXT_texture_env_combine
||
1000 ctx
->Extensions
.ARB_texture_env_combine
) {
1001 *params
= (GLint
) texUnit
->Combine
.ModeRGB
;
1004 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1007 case GL_COMBINE_ALPHA
:
1008 if (ctx
->Extensions
.EXT_texture_env_combine
||
1009 ctx
->Extensions
.ARB_texture_env_combine
) {
1010 *params
= (GLint
) texUnit
->Combine
.ModeA
;
1013 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1016 case GL_SOURCE0_RGB
:
1017 if (ctx
->Extensions
.EXT_texture_env_combine
||
1018 ctx
->Extensions
.ARB_texture_env_combine
) {
1019 *params
= (GLint
) texUnit
->Combine
.SourceRGB
[0];
1022 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1025 case GL_SOURCE1_RGB
:
1026 if (ctx
->Extensions
.EXT_texture_env_combine
||
1027 ctx
->Extensions
.ARB_texture_env_combine
) {
1028 *params
= (GLint
) texUnit
->Combine
.SourceRGB
[1];
1031 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1034 case GL_SOURCE2_RGB
:
1035 if (ctx
->Extensions
.EXT_texture_env_combine
||
1036 ctx
->Extensions
.ARB_texture_env_combine
) {
1037 *params
= (GLint
) texUnit
->Combine
.SourceRGB
[2];
1040 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1043 case GL_SOURCE0_ALPHA
:
1044 if (ctx
->Extensions
.EXT_texture_env_combine
||
1045 ctx
->Extensions
.ARB_texture_env_combine
) {
1046 *params
= (GLint
) texUnit
->Combine
.SourceA
[0];
1049 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1052 case GL_SOURCE1_ALPHA
:
1053 if (ctx
->Extensions
.EXT_texture_env_combine
||
1054 ctx
->Extensions
.ARB_texture_env_combine
) {
1055 *params
= (GLint
) texUnit
->Combine
.SourceA
[1];
1058 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1061 case GL_SOURCE2_ALPHA
:
1062 if (ctx
->Extensions
.EXT_texture_env_combine
||
1063 ctx
->Extensions
.ARB_texture_env_combine
) {
1064 *params
= (GLint
) texUnit
->Combine
.SourceA
[2];
1067 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1070 case GL_OPERAND0_RGB
:
1071 if (ctx
->Extensions
.EXT_texture_env_combine
||
1072 ctx
->Extensions
.ARB_texture_env_combine
) {
1073 *params
= (GLint
) texUnit
->Combine
.OperandRGB
[0];
1076 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1079 case GL_OPERAND1_RGB
:
1080 if (ctx
->Extensions
.EXT_texture_env_combine
||
1081 ctx
->Extensions
.ARB_texture_env_combine
) {
1082 *params
= (GLint
) texUnit
->Combine
.OperandRGB
[1];
1085 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1088 case GL_OPERAND2_RGB
:
1089 if (ctx
->Extensions
.EXT_texture_env_combine
||
1090 ctx
->Extensions
.ARB_texture_env_combine
) {
1091 *params
= (GLint
) texUnit
->Combine
.OperandRGB
[2];
1094 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1097 case GL_OPERAND0_ALPHA
:
1098 if (ctx
->Extensions
.EXT_texture_env_combine
||
1099 ctx
->Extensions
.ARB_texture_env_combine
) {
1100 *params
= (GLint
) texUnit
->Combine
.OperandA
[0];
1103 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1106 case GL_OPERAND1_ALPHA
:
1107 if (ctx
->Extensions
.EXT_texture_env_combine
||
1108 ctx
->Extensions
.ARB_texture_env_combine
) {
1109 *params
= (GLint
) texUnit
->Combine
.OperandA
[1];
1112 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1115 case GL_OPERAND2_ALPHA
:
1116 if (ctx
->Extensions
.EXT_texture_env_combine
||
1117 ctx
->Extensions
.ARB_texture_env_combine
) {
1118 *params
= (GLint
) texUnit
->Combine
.OperandA
[2];
1121 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1125 if (ctx
->Extensions
.EXT_texture_env_combine
||
1126 ctx
->Extensions
.ARB_texture_env_combine
) {
1127 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
1129 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
1135 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1139 case GL_ALPHA_SCALE
:
1140 if (ctx
->Extensions
.EXT_texture_env_combine
||
1141 ctx
->Extensions
.ARB_texture_env_combine
) {
1142 if (texUnit
->Combine
.ScaleShiftA
== 0)
1144 else if (texUnit
->Combine
.ScaleShiftA
== 1)
1150 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1155 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname=0x%x)",
1159 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
1160 /* GL_EXT_texture_lod_bias */
1161 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
1162 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1165 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
1166 *params
= (GLint
) texUnit
->LodBias
;
1169 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
1173 else if (target
== GL_POINT_SPRITE_NV
) {
1174 /* GL_ARB_point_sprite / GL_NV_point_sprite */
1175 if (!ctx
->Extensions
.NV_point_sprite
1176 && !ctx
->Extensions
.ARB_point_sprite
) {
1177 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1180 if (pname
== GL_COORD_REPLACE_NV
) {
1181 *params
= (GLint
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
1184 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
1189 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1197 /**********************************************************************/
1198 /* Texture Parameters */
1199 /**********************************************************************/
1202 _mesa_validate_texture_wrap_mode(GLcontext
* ctx
,
1203 GLenum target
, GLenum eparam
)
1205 const struct gl_extensions
* const e
= & ctx
->Extensions
;
1207 if (eparam
== GL_CLAMP
|| eparam
== GL_CLAMP_TO_EDGE
||
1208 (eparam
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
1209 /* any texture target */
1212 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
1213 (eparam
== GL_REPEAT
||
1214 (eparam
== GL_MIRRORED_REPEAT
&&
1215 e
->ARB_texture_mirrored_repeat
) ||
1216 (eparam
== GL_MIRROR_CLAMP_EXT
&&
1217 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
1218 (eparam
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
1219 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
1220 (eparam
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
1221 (e
->EXT_texture_mirror_clamp
)))) {
1222 /* non-rectangle texture */
1226 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1232 _mesa_TexParameterf( GLenum target
, GLenum pname
, GLfloat param
)
1234 _mesa_TexParameterfv(target
, pname
, ¶m
);
1239 _mesa_TexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
1241 GET_CURRENT_CONTEXT(ctx
);
1242 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1243 GLenum eparam
= (GLenum
) (GLint
) params
[0];
1244 struct gl_texture_object
*texObj
;
1245 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1247 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
1248 _mesa_debug(ctx
, "glTexParameter %s %s %.1f(%s)...\n",
1249 _mesa_lookup_enum_by_nr(target
),
1250 _mesa_lookup_enum_by_nr(pname
),
1252 _mesa_lookup_enum_by_nr(eparam
));
1257 texObj
= texUnit
->Current1D
;
1260 texObj
= texUnit
->Current2D
;
1263 texObj
= texUnit
->Current3D
;
1265 case GL_TEXTURE_CUBE_MAP
:
1266 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1267 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1270 texObj
= texUnit
->CurrentCubeMap
;
1272 case GL_TEXTURE_RECTANGLE_NV
:
1273 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1274 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1277 texObj
= texUnit
->CurrentRect
;
1280 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1285 case GL_TEXTURE_MIN_FILTER
:
1286 /* A small optimization */
1287 if (texObj
->MinFilter
== eparam
)
1289 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
1290 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1291 texObj
->MinFilter
= eparam
;
1293 else if ((eparam
==GL_NEAREST_MIPMAP_NEAREST
||
1294 eparam
==GL_LINEAR_MIPMAP_NEAREST
||
1295 eparam
==GL_NEAREST_MIPMAP_LINEAR
||
1296 eparam
==GL_LINEAR_MIPMAP_LINEAR
) &&
1297 texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
1298 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1299 texObj
->MinFilter
= eparam
;
1302 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1306 case GL_TEXTURE_MAG_FILTER
:
1307 /* A small optimization */
1308 if (texObj
->MagFilter
== eparam
)
1311 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
1312 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1313 texObj
->MagFilter
= eparam
;
1316 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1320 case GL_TEXTURE_WRAP_S
:
1321 if (texObj
->WrapS
== eparam
)
1323 if (_mesa_validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1324 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1325 texObj
->WrapS
= eparam
;
1331 case GL_TEXTURE_WRAP_T
:
1332 if (texObj
->WrapT
== eparam
)
1334 if (_mesa_validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1335 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1336 texObj
->WrapT
= eparam
;
1342 case GL_TEXTURE_WRAP_R
:
1343 if (texObj
->WrapR
== eparam
)
1345 if (_mesa_validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1346 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1347 texObj
->WrapR
= eparam
;
1353 case GL_TEXTURE_BORDER_COLOR
:
1354 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1355 texObj
->BorderColor
[RCOMP
] = params
[0];
1356 texObj
->BorderColor
[GCOMP
] = params
[1];
1357 texObj
->BorderColor
[BCOMP
] = params
[2];
1358 texObj
->BorderColor
[ACOMP
] = params
[3];
1359 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[RCOMP
], params
[0]);
1360 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[GCOMP
], params
[1]);
1361 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[BCOMP
], params
[2]);
1362 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[ACOMP
], params
[3]);
1364 case GL_TEXTURE_MIN_LOD
:
1365 if (texObj
->MinLod
== params
[0])
1367 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1368 texObj
->MinLod
= params
[0];
1370 case GL_TEXTURE_MAX_LOD
:
1371 if (texObj
->MaxLod
== params
[0])
1373 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1374 texObj
->MaxLod
= params
[0];
1376 case GL_TEXTURE_BASE_LEVEL
:
1377 if (params
[0] < 0.0) {
1378 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1381 if (target
== GL_TEXTURE_RECTANGLE_NV
&& params
[0] != 0.0) {
1382 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1385 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1386 texObj
->BaseLevel
= (GLint
) params
[0];
1388 case GL_TEXTURE_MAX_LEVEL
:
1389 if (params
[0] < 0.0) {
1390 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1393 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1394 texObj
->MaxLevel
= (GLint
) params
[0];
1396 case GL_TEXTURE_PRIORITY
:
1397 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1398 texObj
->Priority
= CLAMP( params
[0], 0.0F
, 1.0F
);
1400 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1401 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1402 if (params
[0] < 1.0) {
1403 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1406 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1407 texObj
->MaxAnisotropy
= params
[0];
1410 _mesa_error(ctx
, GL_INVALID_ENUM
,
1411 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
1415 case GL_TEXTURE_COMPARE_SGIX
:
1416 if (ctx
->Extensions
.SGIX_shadow
) {
1417 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1418 texObj
->CompareFlag
= params
[0] ? GL_TRUE
: GL_FALSE
;
1421 _mesa_error(ctx
, GL_INVALID_ENUM
,
1422 "glTexParameter(pname=GL_TEXTURE_COMPARE_SGIX)");
1426 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1427 if (ctx
->Extensions
.SGIX_shadow
) {
1428 GLenum op
= (GLenum
) params
[0];
1429 if (op
== GL_TEXTURE_LEQUAL_R_SGIX
||
1430 op
== GL_TEXTURE_GEQUAL_R_SGIX
) {
1431 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1432 texObj
->CompareOperator
= op
;
1435 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param)");
1439 _mesa_error(ctx
, GL_INVALID_ENUM
,
1440 "glTexParameter(pname=GL_TEXTURE_COMPARE_OPERATOR_SGIX)");
1444 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1445 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1446 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1447 texObj
->ShadowAmbient
= CLAMP(params
[0], 0.0F
, 1.0F
);
1450 _mesa_error(ctx
, GL_INVALID_ENUM
,
1451 "glTexParameter(pname=GL_SHADOW_AMBIENT_SGIX)");
1455 case GL_GENERATE_MIPMAP_SGIS
:
1456 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1457 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
1460 _mesa_error(ctx
, GL_INVALID_ENUM
,
1461 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
1465 case GL_TEXTURE_COMPARE_MODE_ARB
:
1466 if (ctx
->Extensions
.ARB_shadow
) {
1467 const GLenum mode
= (GLenum
) params
[0];
1468 if (mode
== GL_NONE
|| mode
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
1469 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1470 texObj
->CompareMode
= mode
;
1473 _mesa_error(ctx
, GL_INVALID_ENUM
,
1474 "glTexParameter(bad GL_TEXTURE_COMPARE_MODE_ARB: 0x%x)", mode
);
1479 _mesa_error(ctx
, GL_INVALID_ENUM
,
1480 "glTexParameter(pname=GL_TEXTURE_COMPARE_MODE_ARB)");
1484 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1485 if (ctx
->Extensions
.ARB_shadow
) {
1486 const GLenum func
= (GLenum
) params
[0];
1487 if (func
== GL_LEQUAL
|| func
== GL_GEQUAL
) {
1488 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1489 texObj
->CompareFunc
= func
;
1491 else if (ctx
->Extensions
.EXT_shadow_funcs
&&
1492 (func
== GL_EQUAL
||
1493 func
== GL_NOTEQUAL
||
1495 func
== GL_GREATER
||
1496 func
== GL_ALWAYS
||
1497 func
== GL_NEVER
)) {
1498 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1499 texObj
->CompareFunc
= func
;
1502 _mesa_error(ctx
, GL_INVALID_ENUM
,
1503 "glTexParameter(bad GL_TEXTURE_COMPARE_FUNC_ARB)");
1508 _mesa_error(ctx
, GL_INVALID_ENUM
,
1509 "glTexParameter(pname=GL_TEXTURE_COMPARE_FUNC_ARB)");
1513 case GL_DEPTH_TEXTURE_MODE_ARB
:
1514 if (ctx
->Extensions
.ARB_depth_texture
) {
1515 const GLenum result
= (GLenum
) params
[0];
1516 if (result
== GL_LUMINANCE
|| result
== GL_INTENSITY
1517 || result
== GL_ALPHA
) {
1518 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1519 texObj
->DepthMode
= result
;
1522 _mesa_error(ctx
, GL_INVALID_ENUM
,
1523 "glTexParameter(bad GL_DEPTH_TEXTURE_MODE_ARB)");
1528 _mesa_error(ctx
, GL_INVALID_ENUM
,
1529 "glTexParameter(pname=GL_DEPTH_TEXTURE_MODE_ARB)");
1533 case GL_TEXTURE_LOD_BIAS
:
1534 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias*/
1535 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1536 if (texObj
->LodBias
!= params
[0]) {
1537 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1538 texObj
->LodBias
= params
[0];
1544 _mesa_error(ctx
, GL_INVALID_ENUM
,
1545 "glTexParameter(pname=0x%x)", pname
);
1549 texObj
->Complete
= GL_FALSE
;
1551 if (ctx
->Driver
.TexParameter
) {
1552 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
1558 _mesa_TexParameteri( GLenum target
, GLenum pname
, GLint param
)
1561 if (pname
== GL_TEXTURE_PRIORITY
)
1562 fparam
[0] = INT_TO_FLOAT(param
);
1564 fparam
[0] = (GLfloat
) param
;
1565 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
1566 _mesa_TexParameterfv(target
, pname
, fparam
);
1571 _mesa_TexParameteriv( GLenum target
, GLenum pname
, const GLint
*params
)
1574 if (pname
== GL_TEXTURE_BORDER_COLOR
) {
1575 fparam
[0] = INT_TO_FLOAT(params
[0]);
1576 fparam
[1] = INT_TO_FLOAT(params
[1]);
1577 fparam
[2] = INT_TO_FLOAT(params
[2]);
1578 fparam
[3] = INT_TO_FLOAT(params
[3]);
1581 if (pname
== GL_TEXTURE_PRIORITY
)
1582 fparam
[0] = INT_TO_FLOAT(params
[0]);
1584 fparam
[0] = (GLfloat
) params
[0];
1585 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
1587 _mesa_TexParameterfv(target
, pname
, fparam
);
1592 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1593 GLenum pname
, GLfloat
*params
)
1596 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1597 *params
= (GLfloat
) iparam
;
1602 tex_image_dimensions(GLcontext
*ctx
, GLenum target
)
1606 case GL_PROXY_TEXTURE_1D
:
1609 case GL_PROXY_TEXTURE_2D
:
1612 case GL_PROXY_TEXTURE_3D
:
1614 case GL_TEXTURE_CUBE_MAP
:
1615 case GL_PROXY_TEXTURE_CUBE_MAP
:
1616 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1617 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1618 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1619 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1620 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1621 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1622 return ctx
->Extensions
.ARB_texture_cube_map
? 2 : 0;
1623 case GL_TEXTURE_RECTANGLE_NV
:
1624 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1625 return ctx
->Extensions
.NV_texture_rectangle
? 2 : 0;
1627 _mesa_problem(ctx
, "bad target in _mesa_tex_target_dimensions()");
1634 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1635 GLenum pname
, GLint
*params
)
1637 GET_CURRENT_CONTEXT(ctx
);
1638 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1639 const struct gl_texture_image
*img
= NULL
;
1643 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1645 /* this will catch bad target values */
1646 dimensions
= tex_image_dimensions(ctx
, target
); /* 1, 2 or 3 */
1647 if (dimensions
== 0) {
1648 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
1654 case GL_PROXY_TEXTURE_1D
:
1656 case GL_PROXY_TEXTURE_2D
:
1657 maxLevels
= ctx
->Const
.MaxTextureLevels
;
1660 case GL_PROXY_TEXTURE_3D
:
1661 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
1663 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1664 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1665 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1666 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1667 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1668 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1669 case GL_PROXY_TEXTURE_CUBE_MAP
:
1670 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
1672 case GL_TEXTURE_RECTANGLE_NV
:
1673 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1677 _mesa_problem(ctx
, "switch in _mesa_GetTexLevelParameter");
1681 if (level
< 0 || level
>= maxLevels
) {
1682 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1686 img
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1687 if (!img
|| !img
->TexFormat
) {
1688 /* undefined texture image */
1689 if (pname
== GL_TEXTURE_COMPONENTS
)
1696 isProxy
= (target
== GL_PROXY_TEXTURE_1D
) ||
1697 (target
== GL_PROXY_TEXTURE_2D
) ||
1698 (target
== GL_PROXY_TEXTURE_3D
) ||
1699 (target
== GL_PROXY_TEXTURE_CUBE_MAP
) ||
1700 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
);
1703 case GL_TEXTURE_WIDTH
:
1704 *params
= img
->Width
;
1706 case GL_TEXTURE_HEIGHT
:
1707 *params
= img
->Height
;
1709 case GL_TEXTURE_DEPTH
:
1710 *params
= img
->Depth
;
1712 case GL_TEXTURE_INTERNAL_FORMAT
:
1713 *params
= img
->IntFormat
;
1715 case GL_TEXTURE_BORDER
:
1716 *params
= img
->Border
;
1718 case GL_TEXTURE_RED_SIZE
:
1719 if (img
->Format
== GL_RGB
|| img
->Format
== GL_RGBA
)
1720 *params
= img
->TexFormat
->RedBits
;
1724 case GL_TEXTURE_GREEN_SIZE
:
1725 if (img
->Format
== GL_RGB
|| img
->Format
== GL_RGBA
)
1726 *params
= img
->TexFormat
->GreenBits
;
1730 case GL_TEXTURE_BLUE_SIZE
:
1731 if (img
->Format
== GL_RGB
|| img
->Format
== GL_RGBA
)
1732 *params
= img
->TexFormat
->BlueBits
;
1736 case GL_TEXTURE_ALPHA_SIZE
:
1737 if (img
->Format
== GL_ALPHA
|| img
->Format
== GL_LUMINANCE_ALPHA
||
1738 img
->Format
== GL_RGBA
)
1739 *params
= img
->TexFormat
->AlphaBits
;
1743 case GL_TEXTURE_INTENSITY_SIZE
:
1744 if (img
->Format
!= GL_INTENSITY
)
1746 else if (img
->TexFormat
->IntensityBits
> 0)
1747 *params
= img
->TexFormat
->IntensityBits
;
1748 else /* intensity probably stored as rgb texture */
1749 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
1751 case GL_TEXTURE_LUMINANCE_SIZE
:
1752 if (img
->Format
!= GL_LUMINANCE
&&
1753 img
->Format
!= GL_LUMINANCE_ALPHA
)
1755 else if (img
->TexFormat
->LuminanceBits
> 0)
1756 *params
= img
->TexFormat
->LuminanceBits
;
1757 else /* luminance probably stored as rgb texture */
1758 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
1760 case GL_TEXTURE_INDEX_SIZE_EXT
:
1761 if (img
->Format
== GL_COLOR_INDEX
)
1762 *params
= img
->TexFormat
->IndexBits
;
1767 /* XXX this isn't in the GL_SGIX_depth_texture spec
1768 * but seems appropriate.
1770 if (ctx
->Extensions
.SGIX_depth_texture
)
1771 *params
= img
->TexFormat
->DepthBits
;
1773 _mesa_error(ctx
, GL_INVALID_ENUM
,
1774 "glGetTexLevelParameter[if]v(pname)");
1777 /* GL_ARB_texture_compression */
1778 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1779 if (ctx
->Extensions
.ARB_texture_compression
) {
1780 if (img
->IsCompressed
&& !isProxy
)
1781 *params
= img
->CompressedSize
;
1783 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1784 "glGetTexLevelParameter[if]v(pname)");
1787 _mesa_error(ctx
, GL_INVALID_ENUM
,
1788 "glGetTexLevelParameter[if]v(pname)");
1791 case GL_TEXTURE_COMPRESSED
:
1792 if (ctx
->Extensions
.ARB_texture_compression
) {
1793 *params
= (GLint
) img
->IsCompressed
;
1796 _mesa_error(ctx
, GL_INVALID_ENUM
,
1797 "glGetTexLevelParameter[if]v(pname)");
1802 _mesa_error(ctx
, GL_INVALID_ENUM
,
1803 "glGetTexLevelParameter[if]v(pname)");
1810 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1812 GET_CURRENT_CONTEXT(ctx
);
1813 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1814 struct gl_texture_object
*obj
;
1815 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1817 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1819 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
1824 case GL_TEXTURE_MAG_FILTER
:
1825 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1827 case GL_TEXTURE_MIN_FILTER
:
1828 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1830 case GL_TEXTURE_WRAP_S
:
1831 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1833 case GL_TEXTURE_WRAP_T
:
1834 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1836 case GL_TEXTURE_WRAP_R
:
1837 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1839 case GL_TEXTURE_BORDER_COLOR
:
1840 params
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1841 params
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1842 params
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1843 params
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1845 case GL_TEXTURE_RESIDENT
:
1848 if (ctx
->Driver
.IsTextureResident
)
1849 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1852 *params
= ENUM_TO_FLOAT(resident
);
1855 case GL_TEXTURE_PRIORITY
:
1856 *params
= obj
->Priority
;
1858 case GL_TEXTURE_MIN_LOD
:
1859 *params
= obj
->MinLod
;
1861 case GL_TEXTURE_MAX_LOD
:
1862 *params
= obj
->MaxLod
;
1864 case GL_TEXTURE_BASE_LEVEL
:
1865 *params
= (GLfloat
) obj
->BaseLevel
;
1867 case GL_TEXTURE_MAX_LEVEL
:
1868 *params
= (GLfloat
) obj
->MaxLevel
;
1870 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1871 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1872 *params
= obj
->MaxAnisotropy
;
1876 case GL_TEXTURE_COMPARE_SGIX
:
1877 if (ctx
->Extensions
.SGIX_shadow
) {
1878 *params
= (GLfloat
) obj
->CompareFlag
;
1882 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1883 if (ctx
->Extensions
.SGIX_shadow
) {
1884 *params
= (GLfloat
) obj
->CompareOperator
;
1888 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1889 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1890 *params
= obj
->ShadowAmbient
;
1894 case GL_GENERATE_MIPMAP_SGIS
:
1895 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1896 *params
= (GLfloat
) obj
->GenerateMipmap
;
1900 case GL_TEXTURE_COMPARE_MODE_ARB
:
1901 if (ctx
->Extensions
.ARB_shadow
) {
1902 *params
= (GLfloat
) obj
->CompareMode
;
1906 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1907 if (ctx
->Extensions
.ARB_shadow
) {
1908 *params
= (GLfloat
) obj
->CompareFunc
;
1912 case GL_DEPTH_TEXTURE_MODE_ARB
:
1913 if (ctx
->Extensions
.ARB_depth_texture
) {
1914 *params
= (GLfloat
) obj
->DepthMode
;
1918 case GL_TEXTURE_LOD_BIAS
:
1919 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1920 *params
= obj
->LodBias
;
1925 ; /* silence warnings */
1927 /* If we get here, pname was an unrecognized enum */
1928 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1934 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1936 GET_CURRENT_CONTEXT(ctx
);
1937 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1938 struct gl_texture_object
*obj
;
1939 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1941 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1943 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
1948 case GL_TEXTURE_MAG_FILTER
:
1949 *params
= (GLint
) obj
->MagFilter
;
1950 case GL_TEXTURE_LOD_BIAS
:
1951 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1952 *params
= (GLint
) obj
->LodBias
;
1957 case GL_TEXTURE_MIN_FILTER
:
1958 *params
= (GLint
) obj
->MinFilter
;
1960 case GL_TEXTURE_WRAP_S
:
1961 *params
= (GLint
) obj
->WrapS
;
1963 case GL_TEXTURE_WRAP_T
:
1964 *params
= (GLint
) obj
->WrapT
;
1966 case GL_TEXTURE_WRAP_R
:
1967 *params
= (GLint
) obj
->WrapR
;
1969 case GL_TEXTURE_BORDER_COLOR
:
1972 b
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1973 b
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1974 b
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1975 b
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1976 params
[0] = FLOAT_TO_INT(b
[0]);
1977 params
[1] = FLOAT_TO_INT(b
[1]);
1978 params
[2] = FLOAT_TO_INT(b
[2]);
1979 params
[3] = FLOAT_TO_INT(b
[3]);
1982 case GL_TEXTURE_RESIDENT
:
1985 if (ctx
->Driver
.IsTextureResident
)
1986 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1989 *params
= (GLint
) resident
;
1992 case GL_TEXTURE_PRIORITY
:
1993 *params
= FLOAT_TO_INT(obj
->Priority
);
1995 case GL_TEXTURE_MIN_LOD
:
1996 *params
= (GLint
) obj
->MinLod
;
1998 case GL_TEXTURE_MAX_LOD
:
1999 *params
= (GLint
) obj
->MaxLod
;
2001 case GL_TEXTURE_BASE_LEVEL
:
2002 *params
= obj
->BaseLevel
;
2004 case GL_TEXTURE_MAX_LEVEL
:
2005 *params
= obj
->MaxLevel
;
2007 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
2008 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
2009 *params
= (GLint
) obj
->MaxAnisotropy
;
2013 case GL_TEXTURE_COMPARE_SGIX
:
2014 if (ctx
->Extensions
.SGIX_shadow
) {
2015 *params
= (GLint
) obj
->CompareFlag
;
2019 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
2020 if (ctx
->Extensions
.SGIX_shadow
) {
2021 *params
= (GLint
) obj
->CompareOperator
;
2025 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
2026 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
2027 *params
= (GLint
) FLOAT_TO_INT(obj
->ShadowAmbient
);
2031 case GL_GENERATE_MIPMAP_SGIS
:
2032 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
2033 *params
= (GLint
) obj
->GenerateMipmap
;
2037 case GL_TEXTURE_COMPARE_MODE_ARB
:
2038 if (ctx
->Extensions
.ARB_shadow
) {
2039 *params
= (GLint
) obj
->CompareMode
;
2043 case GL_TEXTURE_COMPARE_FUNC_ARB
:
2044 if (ctx
->Extensions
.ARB_shadow
) {
2045 *params
= (GLint
) obj
->CompareFunc
;
2049 case GL_DEPTH_TEXTURE_MODE_ARB
:
2050 if (ctx
->Extensions
.ARB_depth_texture
) {
2051 *params
= (GLint
) obj
->DepthMode
;
2056 ; /* silence warnings */
2058 /* If we get here, pname was an unrecognized enum */
2059 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
2065 /**********************************************************************/
2066 /* Texture Coord Generation */
2067 /**********************************************************************/
2071 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
2073 GET_CURRENT_CONTEXT(ctx
);
2074 GLuint tUnit
= ctx
->Texture
.CurrentUnit
;
2075 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
2076 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2078 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
2079 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
2080 _mesa_lookup_enum_by_nr(coord
),
2081 _mesa_lookup_enum_by_nr(pname
),
2083 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *params
));
2087 if (pname
==GL_TEXTURE_GEN_MODE
) {
2088 GLenum mode
= (GLenum
) (GLint
) *params
;
2091 case GL_OBJECT_LINEAR
:
2092 bits
= TEXGEN_OBJ_LINEAR
;
2095 bits
= TEXGEN_EYE_LINEAR
;
2097 case GL_REFLECTION_MAP_NV
:
2098 bits
= TEXGEN_REFLECTION_MAP_NV
;
2100 case GL_NORMAL_MAP_NV
:
2101 bits
= TEXGEN_NORMAL_MAP_NV
;
2104 bits
= TEXGEN_SPHERE_MAP
;
2107 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2110 if (texUnit
->GenModeS
== mode
)
2112 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2113 texUnit
->GenModeS
= mode
;
2114 texUnit
->_GenBitS
= bits
;
2116 else if (pname
==GL_OBJECT_PLANE
) {
2117 if (TEST_EQ_4V(texUnit
->ObjectPlaneS
, params
))
2119 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2120 texUnit
->ObjectPlaneS
[0] = params
[0];
2121 texUnit
->ObjectPlaneS
[1] = params
[1];
2122 texUnit
->ObjectPlaneS
[2] = params
[2];
2123 texUnit
->ObjectPlaneS
[3] = params
[3];
2125 else if (pname
==GL_EYE_PLANE
) {
2128 /* Transform plane equation by the inverse modelview matrix */
2129 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
) {
2130 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2132 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2133 if (TEST_EQ_4V(texUnit
->EyePlaneS
, tmp
))
2135 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2136 COPY_4FV(texUnit
->EyePlaneS
, tmp
);
2139 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2144 if (pname
==GL_TEXTURE_GEN_MODE
) {
2145 GLenum mode
= (GLenum
) (GLint
) *params
;
2148 case GL_OBJECT_LINEAR
:
2149 bitt
= TEXGEN_OBJ_LINEAR
;
2152 bitt
= TEXGEN_EYE_LINEAR
;
2154 case GL_REFLECTION_MAP_NV
:
2155 bitt
= TEXGEN_REFLECTION_MAP_NV
;
2157 case GL_NORMAL_MAP_NV
:
2158 bitt
= TEXGEN_NORMAL_MAP_NV
;
2161 bitt
= TEXGEN_SPHERE_MAP
;
2164 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2167 if (texUnit
->GenModeT
== mode
)
2169 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2170 texUnit
->GenModeT
= mode
;
2171 texUnit
->_GenBitT
= bitt
;
2173 else if (pname
==GL_OBJECT_PLANE
) {
2174 if (TEST_EQ_4V(texUnit
->ObjectPlaneT
, params
))
2176 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2177 texUnit
->ObjectPlaneT
[0] = params
[0];
2178 texUnit
->ObjectPlaneT
[1] = params
[1];
2179 texUnit
->ObjectPlaneT
[2] = params
[2];
2180 texUnit
->ObjectPlaneT
[3] = params
[3];
2182 else if (pname
==GL_EYE_PLANE
) {
2184 /* Transform plane equation by the inverse modelview matrix */
2185 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
) {
2186 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2188 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2189 if (TEST_EQ_4V(texUnit
->EyePlaneT
, tmp
))
2191 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2192 COPY_4FV(texUnit
->EyePlaneT
, tmp
);
2195 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2200 if (pname
==GL_TEXTURE_GEN_MODE
) {
2201 GLenum mode
= (GLenum
) (GLint
) *params
;
2204 case GL_OBJECT_LINEAR
:
2205 bitr
= TEXGEN_OBJ_LINEAR
;
2207 case GL_REFLECTION_MAP_NV
:
2208 bitr
= TEXGEN_REFLECTION_MAP_NV
;
2210 case GL_NORMAL_MAP_NV
:
2211 bitr
= TEXGEN_NORMAL_MAP_NV
;
2214 bitr
= TEXGEN_EYE_LINEAR
;
2217 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2220 if (texUnit
->GenModeR
== mode
)
2222 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2223 texUnit
->GenModeR
= mode
;
2224 texUnit
->_GenBitR
= bitr
;
2226 else if (pname
==GL_OBJECT_PLANE
) {
2227 if (TEST_EQ_4V(texUnit
->ObjectPlaneR
, params
))
2229 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2230 texUnit
->ObjectPlaneR
[0] = params
[0];
2231 texUnit
->ObjectPlaneR
[1] = params
[1];
2232 texUnit
->ObjectPlaneR
[2] = params
[2];
2233 texUnit
->ObjectPlaneR
[3] = params
[3];
2235 else if (pname
==GL_EYE_PLANE
) {
2237 /* Transform plane equation by the inverse modelview matrix */
2238 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
) {
2239 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2241 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2242 if (TEST_EQ_4V(texUnit
->EyePlaneR
, tmp
))
2244 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2245 COPY_4FV(texUnit
->EyePlaneR
, tmp
);
2248 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2253 if (pname
==GL_TEXTURE_GEN_MODE
) {
2254 GLenum mode
= (GLenum
) (GLint
) *params
;
2257 case GL_OBJECT_LINEAR
:
2258 bitq
= TEXGEN_OBJ_LINEAR
;
2261 bitq
= TEXGEN_EYE_LINEAR
;
2264 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2267 if (texUnit
->GenModeQ
== mode
)
2269 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2270 texUnit
->GenModeQ
= mode
;
2271 texUnit
->_GenBitQ
= bitq
;
2273 else if (pname
==GL_OBJECT_PLANE
) {
2274 if (TEST_EQ_4V(texUnit
->ObjectPlaneQ
, params
))
2276 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2277 texUnit
->ObjectPlaneQ
[0] = params
[0];
2278 texUnit
->ObjectPlaneQ
[1] = params
[1];
2279 texUnit
->ObjectPlaneQ
[2] = params
[2];
2280 texUnit
->ObjectPlaneQ
[3] = params
[3];
2282 else if (pname
==GL_EYE_PLANE
) {
2284 /* Transform plane equation by the inverse modelview matrix */
2285 if (ctx
->ModelviewMatrixStack
.Top
->flags
& MAT_DIRTY_INVERSE
) {
2286 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2288 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2289 if (TEST_EQ_4V(texUnit
->EyePlaneQ
, tmp
))
2291 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2292 COPY_4FV(texUnit
->EyePlaneQ
, tmp
);
2295 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2300 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
2304 if (ctx
->Driver
.TexGen
)
2305 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
2310 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
2313 p
[0] = (GLfloat
) params
[0];
2314 if (pname
== GL_TEXTURE_GEN_MODE
) {
2315 p
[1] = p
[2] = p
[3] = 0.0F
;
2318 p
[1] = (GLfloat
) params
[1];
2319 p
[2] = (GLfloat
) params
[2];
2320 p
[3] = (GLfloat
) params
[3];
2322 _mesa_TexGenfv(coord
, pname
, p
);
2327 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
2329 GLfloat p
= (GLfloat
) param
;
2330 _mesa_TexGenfv( coord
, pname
, &p
);
2335 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
2338 p
[0] = (GLfloat
) params
[0];
2339 if (pname
== GL_TEXTURE_GEN_MODE
) {
2340 p
[1] = p
[2] = p
[3] = 0.0F
;
2343 p
[1] = (GLfloat
) params
[1];
2344 p
[2] = (GLfloat
) params
[2];
2345 p
[3] = (GLfloat
) params
[3];
2347 _mesa_TexGenfv( coord
, pname
, p
);
2352 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
2354 _mesa_TexGenfv(coord
, pname
, ¶m
);
2359 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
2361 _mesa_TexGeniv( coord
, pname
, ¶m
);
2367 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
2369 GET_CURRENT_CONTEXT(ctx
);
2370 GLuint tUnit
= ctx
->Texture
.CurrentUnit
;
2371 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
2372 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2376 if (pname
==GL_TEXTURE_GEN_MODE
) {
2377 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
2379 else if (pname
==GL_OBJECT_PLANE
) {
2380 COPY_4V( params
, texUnit
->ObjectPlaneS
);
2382 else if (pname
==GL_EYE_PLANE
) {
2383 COPY_4V( params
, texUnit
->EyePlaneS
);
2386 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2391 if (pname
==GL_TEXTURE_GEN_MODE
) {
2392 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
2394 else if (pname
==GL_OBJECT_PLANE
) {
2395 COPY_4V( params
, texUnit
->ObjectPlaneT
);
2397 else if (pname
==GL_EYE_PLANE
) {
2398 COPY_4V( params
, texUnit
->EyePlaneT
);
2401 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2406 if (pname
==GL_TEXTURE_GEN_MODE
) {
2407 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
2409 else if (pname
==GL_OBJECT_PLANE
) {
2410 COPY_4V( params
, texUnit
->ObjectPlaneR
);
2412 else if (pname
==GL_EYE_PLANE
) {
2413 COPY_4V( params
, texUnit
->EyePlaneR
);
2416 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2421 if (pname
==GL_TEXTURE_GEN_MODE
) {
2422 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
2424 else if (pname
==GL_OBJECT_PLANE
) {
2425 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
2427 else if (pname
==GL_EYE_PLANE
) {
2428 COPY_4V( params
, texUnit
->EyePlaneQ
);
2431 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2436 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
2444 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
2446 GET_CURRENT_CONTEXT(ctx
);
2447 GLuint tUnit
= ctx
->Texture
.CurrentUnit
;
2448 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
2449 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2453 if (pname
==GL_TEXTURE_GEN_MODE
) {
2454 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
2456 else if (pname
==GL_OBJECT_PLANE
) {
2457 COPY_4V( params
, texUnit
->ObjectPlaneS
);
2459 else if (pname
==GL_EYE_PLANE
) {
2460 COPY_4V( params
, texUnit
->EyePlaneS
);
2463 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2468 if (pname
==GL_TEXTURE_GEN_MODE
) {
2469 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
2471 else if (pname
==GL_OBJECT_PLANE
) {
2472 COPY_4V( params
, texUnit
->ObjectPlaneT
);
2474 else if (pname
==GL_EYE_PLANE
) {
2475 COPY_4V( params
, texUnit
->EyePlaneT
);
2478 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2483 if (pname
==GL_TEXTURE_GEN_MODE
) {
2484 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
2486 else if (pname
==GL_OBJECT_PLANE
) {
2487 COPY_4V( params
, texUnit
->ObjectPlaneR
);
2489 else if (pname
==GL_EYE_PLANE
) {
2490 COPY_4V( params
, texUnit
->EyePlaneR
);
2493 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2498 if (pname
==GL_TEXTURE_GEN_MODE
) {
2499 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
2501 else if (pname
==GL_OBJECT_PLANE
) {
2502 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
2504 else if (pname
==GL_EYE_PLANE
) {
2505 COPY_4V( params
, texUnit
->EyePlaneQ
);
2508 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2513 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
2521 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
2523 GET_CURRENT_CONTEXT(ctx
);
2524 GLuint tUnit
= ctx
->Texture
.CurrentUnit
;
2525 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[tUnit
];
2526 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2530 if (pname
==GL_TEXTURE_GEN_MODE
) {
2531 params
[0] = texUnit
->GenModeS
;
2533 else if (pname
==GL_OBJECT_PLANE
) {
2534 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
2535 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
2536 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
2537 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
2539 else if (pname
==GL_EYE_PLANE
) {
2540 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
2541 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
2542 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
2543 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
2546 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2551 if (pname
==GL_TEXTURE_GEN_MODE
) {
2552 params
[0] = texUnit
->GenModeT
;
2554 else if (pname
==GL_OBJECT_PLANE
) {
2555 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
2556 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
2557 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
2558 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
2560 else if (pname
==GL_EYE_PLANE
) {
2561 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
2562 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
2563 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
2564 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
2567 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2572 if (pname
==GL_TEXTURE_GEN_MODE
) {
2573 params
[0] = texUnit
->GenModeR
;
2575 else if (pname
==GL_OBJECT_PLANE
) {
2576 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
2577 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
2578 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
2579 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
2581 else if (pname
==GL_EYE_PLANE
) {
2582 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
2583 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
2584 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
2585 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
2588 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2593 if (pname
==GL_TEXTURE_GEN_MODE
) {
2594 params
[0] = texUnit
->GenModeQ
;
2596 else if (pname
==GL_OBJECT_PLANE
) {
2597 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
2598 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
2599 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
2600 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
2602 else if (pname
==GL_EYE_PLANE
) {
2603 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
2604 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
2605 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
2606 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
2609 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2614 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
2620 /* GL_ARB_multitexture */
2622 _mesa_ActiveTextureARB( GLenum target
)
2624 GET_CURRENT_CONTEXT(ctx
);
2625 const GLuint texUnit
= target
- GL_TEXTURE0
;
2626 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2628 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2629 _mesa_debug(ctx
, "glActiveTexture %s\n",
2630 _mesa_lookup_enum_by_nr(target
));
2632 /* Cater for texture unit 0 is first, therefore use >= */
2633 if (texUnit
>= ctx
->Const
.MaxTextureUnits
) {
2634 _mesa_error(ctx
, GL_INVALID_ENUM
, "glActiveTexture(target)");
2638 if (ctx
->Texture
.CurrentUnit
== texUnit
)
2641 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2643 ctx
->Texture
.CurrentUnit
= texUnit
;
2644 if (ctx
->Transform
.MatrixMode
== GL_TEXTURE
) {
2645 /* update current stack pointer */
2646 ctx
->CurrentStack
= &ctx
->TextureMatrixStack
[texUnit
];
2649 if (ctx
->Driver
.ActiveTexture
) {
2650 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
2655 /* GL_ARB_multitexture */
2657 _mesa_ClientActiveTextureARB( GLenum target
)
2659 GET_CURRENT_CONTEXT(ctx
);
2660 GLuint texUnit
= target
- GL_TEXTURE0
;
2661 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2663 if (texUnit
> ctx
->Const
.MaxTextureUnits
) {
2664 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClientActiveTexture(target)");
2668 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
2669 ctx
->Array
.ActiveTexture
= texUnit
;
2674 /**********************************************************************/
2675 /* Pixel Texgen Extensions */
2676 /**********************************************************************/
2679 _mesa_PixelTexGenSGIX(GLenum mode
)
2681 GLenum newRgbSource
, newAlphaSource
;
2682 GET_CURRENT_CONTEXT(ctx
);
2683 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2687 newRgbSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2688 newAlphaSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2691 newRgbSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2692 newAlphaSource
= GL_CURRENT_RASTER_COLOR
;
2695 newRgbSource
= GL_CURRENT_RASTER_COLOR
;
2696 newAlphaSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2699 newRgbSource
= GL_CURRENT_RASTER_COLOR
;
2700 newAlphaSource
= GL_CURRENT_RASTER_COLOR
;
2703 _mesa_error(ctx
, GL_INVALID_ENUM
, "glPixelTexGenSGIX(mode)");
2707 if (newRgbSource
== ctx
->Pixel
.FragmentRgbSource
&&
2708 newAlphaSource
== ctx
->Pixel
.FragmentAlphaSource
)
2711 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
2712 ctx
->Pixel
.FragmentRgbSource
= newRgbSource
;
2713 ctx
->Pixel
.FragmentAlphaSource
= newAlphaSource
;
2718 _mesa_PixelTexGenParameterfSGIS(GLenum target
, GLfloat value
)
2720 _mesa_PixelTexGenParameteriSGIS(target
, (GLint
) value
);
2725 _mesa_PixelTexGenParameterfvSGIS(GLenum target
, const GLfloat
*value
)
2727 _mesa_PixelTexGenParameteriSGIS(target
, (GLint
) *value
);
2732 _mesa_PixelTexGenParameteriSGIS(GLenum target
, GLint value
)
2734 GET_CURRENT_CONTEXT(ctx
);
2735 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2737 if (value
!= GL_CURRENT_RASTER_COLOR
&& value
!= GL_PIXEL_GROUP_COLOR_SGIS
) {
2738 _mesa_error(ctx
, GL_INVALID_ENUM
, "glPixelTexGenParameterSGIS(value)");
2743 case GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS
:
2744 if (ctx
->Pixel
.FragmentRgbSource
== (GLenum
) value
)
2746 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
2747 ctx
->Pixel
.FragmentRgbSource
= (GLenum
) value
;
2749 case GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS
:
2750 if (ctx
->Pixel
.FragmentAlphaSource
== (GLenum
) value
)
2752 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
2753 ctx
->Pixel
.FragmentAlphaSource
= (GLenum
) value
;
2756 _mesa_error(ctx
, GL_INVALID_ENUM
, "glPixelTexGenParameterSGIS(target)");
2763 _mesa_PixelTexGenParameterivSGIS(GLenum target
, const GLint
*value
)
2765 _mesa_PixelTexGenParameteriSGIS(target
, *value
);
2770 _mesa_GetPixelTexGenParameterfvSGIS(GLenum target
, GLfloat
*value
)
2772 GET_CURRENT_CONTEXT(ctx
);
2773 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2775 if (target
== GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS
) {
2776 *value
= (GLfloat
) ctx
->Pixel
.FragmentRgbSource
;
2778 else if (target
== GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS
) {
2779 *value
= (GLfloat
) ctx
->Pixel
.FragmentAlphaSource
;
2782 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetPixelTexGenParameterfvSGIS(target)");
2788 _mesa_GetPixelTexGenParameterivSGIS(GLenum target
, GLint
*value
)
2790 GET_CURRENT_CONTEXT(ctx
);
2791 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2793 if (target
== GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS
) {
2794 *value
= (GLint
) ctx
->Pixel
.FragmentRgbSource
;
2796 else if (target
== GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS
) {
2797 *value
= (GLint
) ctx
->Pixel
.FragmentAlphaSource
;
2800 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetPixelTexGenParameterivSGIS(target)");
2806 /**********************************************************************/
2807 /***** State management *****/
2808 /**********************************************************************/
2812 * \note This routine refers to derived texture attribute values to
2813 * compute the ENABLE_TEXMAT flags, but is only called on
2814 * _NEW_TEXTURE_MATRIX. On changes to _NEW_TEXTURE, the ENABLE_TEXMAT
2815 * flags are updated by _mesa_update_textures(), below.
2817 * \param ctx GL context.
2820 update_texture_matrices( GLcontext
*ctx
)
2824 ctx
->Texture
._TexMatEnabled
= 0;
2826 for (i
=0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
2827 if (ctx
->TextureMatrixStack
[i
].Top
->flags
& MAT_DIRTY
) {
2828 _math_matrix_analyse( ctx
->TextureMatrixStack
[i
].Top
);
2830 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
&&
2831 ctx
->TextureMatrixStack
[i
].Top
->type
!= MATRIX_IDENTITY
)
2832 ctx
->Texture
._TexMatEnabled
|= ENABLE_TEXMAT(i
);
2834 if (ctx
->Driver
.TextureMatrix
)
2835 ctx
->Driver
.TextureMatrix( ctx
, i
, ctx
->TextureMatrixStack
[i
].Top
);
2844 * \note This routine refers to derived texture matrix values to
2845 * compute the ENABLE_TEXMAT flags, but is only called on
2846 * _NEW_TEXTURE. On changes to _NEW_TEXTURE_MATRIX, the ENABLE_TEXMAT
2847 * flags are updated by _mesa_update_texture_matrices, above.
2849 * \param ctx GL context.
2852 update_texture_state( GLcontext
*ctx
)
2856 ctx
->NewState
|= _NEW_TEXTURE
; /* TODO: only set this if there are
2860 ctx
->Texture
._EnabledUnits
= 0;
2861 ctx
->Texture
._GenFlags
= 0;
2862 ctx
->Texture
._TexMatEnabled
= 0;
2863 ctx
->Texture
._TexGenEnabled
= 0;
2865 /* Update texture unit state.
2866 * XXX this loop should probably be broken into separate loops for
2867 * texture coord units and texture image units.
2869 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
2870 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
2873 texUnit
->_Current
= NULL
;
2874 texUnit
->_ReallyEnabled
= 0;
2875 texUnit
->_GenFlags
= 0;
2877 /* Get the bitmask of texture enables */
2878 if (ctx
->FragmentProgram
.Enabled
&& ctx
->FragmentProgram
.Current
) {
2879 enableBits
= ctx
->FragmentProgram
.Current
->TexturesUsed
[unit
];
2882 if (!texUnit
->Enabled
)
2884 enableBits
= texUnit
->Enabled
;
2887 /* Look for the highest-priority texture target that's enabled and
2888 * complete. That's the one we'll use for texturing. If we're using
2889 * a fragment program we're guaranteed that bitcount(enabledBits) <= 1.
2891 if (enableBits
& TEXTURE_CUBE_BIT
) {
2892 struct gl_texture_object
*texObj
= texUnit
->CurrentCubeMap
;
2893 if (!texObj
->Complete
) {
2894 _mesa_test_texobj_completeness(ctx
, texObj
);
2896 if (texObj
->Complete
) {
2897 texUnit
->_ReallyEnabled
= TEXTURE_CUBE_BIT
;
2898 texUnit
->_Current
= texObj
;
2902 if (!texUnit
->_ReallyEnabled
&& (enableBits
& TEXTURE_3D_BIT
)) {
2903 struct gl_texture_object
*texObj
= texUnit
->Current3D
;
2904 if (!texObj
->Complete
) {
2905 _mesa_test_texobj_completeness(ctx
, texObj
);
2907 if (texObj
->Complete
) {
2908 texUnit
->_ReallyEnabled
= TEXTURE_3D_BIT
;
2909 texUnit
->_Current
= texObj
;
2913 if (!texUnit
->_ReallyEnabled
&& (enableBits
& TEXTURE_RECT_BIT
)) {
2914 struct gl_texture_object
*texObj
= texUnit
->CurrentRect
;
2915 if (!texObj
->Complete
) {
2916 _mesa_test_texobj_completeness(ctx
, texObj
);
2918 if (texObj
->Complete
) {
2919 texUnit
->_ReallyEnabled
= TEXTURE_RECT_BIT
;
2920 texUnit
->_Current
= texObj
;
2924 if (!texUnit
->_ReallyEnabled
&& (enableBits
& TEXTURE_2D_BIT
)) {
2925 struct gl_texture_object
*texObj
= texUnit
->Current2D
;
2926 if (!texObj
->Complete
) {
2927 _mesa_test_texobj_completeness(ctx
, texObj
);
2929 if (texObj
->Complete
) {
2930 texUnit
->_ReallyEnabled
= TEXTURE_2D_BIT
;
2931 texUnit
->_Current
= texObj
;
2935 if (!texUnit
->_ReallyEnabled
&& (enableBits
& TEXTURE_1D_BIT
)) {
2936 struct gl_texture_object
*texObj
= texUnit
->Current1D
;
2937 if (!texObj
->Complete
) {
2938 _mesa_test_texobj_completeness(ctx
, texObj
);
2940 if (texObj
->Complete
) {
2941 texUnit
->_ReallyEnabled
= TEXTURE_1D_BIT
;
2942 texUnit
->_Current
= texObj
;
2946 if (!texUnit
->_ReallyEnabled
) {
2950 if (texUnit
->_ReallyEnabled
)
2951 ctx
->Texture
._EnabledUnits
|= (1 << unit
);
2953 if ( texUnit
->EnvMode
== GL_COMBINE
) {
2954 texUnit
->_CurrentCombine
= & texUnit
->Combine
;
2957 calculate_derived_texenv( & texUnit
->_EnvMode
,
2959 texUnit
->_Current
->Image
[0][0]->Format
);
2960 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
2963 switch (texUnit
->_CurrentCombine
->ModeRGB
) {
2965 texUnit
->_CurrentCombine
->_NumArgsRGB
= 1;
2973 case GL_DOT3_RGB_EXT
:
2974 case GL_DOT3_RGBA_EXT
:
2975 texUnit
->_CurrentCombine
->_NumArgsRGB
= 2;
2977 case GL_INTERPOLATE
:
2978 case GL_MODULATE_ADD_ATI
:
2979 case GL_MODULATE_SIGNED_ADD_ATI
:
2980 case GL_MODULATE_SUBTRACT_ATI
:
2981 texUnit
->_CurrentCombine
->_NumArgsRGB
= 3;
2984 texUnit
->_CurrentCombine
->_NumArgsRGB
= 0;
2989 switch (texUnit
->_CurrentCombine
->ModeA
) {
2991 texUnit
->_CurrentCombine
->_NumArgsA
= 1;
2997 texUnit
->_CurrentCombine
->_NumArgsA
= 2;
2999 case GL_INTERPOLATE
:
3000 case GL_MODULATE_ADD_ATI
:
3001 case GL_MODULATE_SIGNED_ADD_ATI
:
3002 case GL_MODULATE_SUBTRACT_ATI
:
3003 texUnit
->_CurrentCombine
->_NumArgsA
= 3;
3006 texUnit
->_CurrentCombine
->_NumArgsA
= 0;
3011 if (texUnit
->TexGenEnabled
) {
3012 if (texUnit
->TexGenEnabled
& S_BIT
) {
3013 texUnit
->_GenFlags
|= texUnit
->_GenBitS
;
3015 if (texUnit
->TexGenEnabled
& T_BIT
) {
3016 texUnit
->_GenFlags
|= texUnit
->_GenBitT
;
3018 if (texUnit
->TexGenEnabled
& Q_BIT
) {
3019 texUnit
->_GenFlags
|= texUnit
->_GenBitQ
;
3021 if (texUnit
->TexGenEnabled
& R_BIT
) {
3022 texUnit
->_GenFlags
|= texUnit
->_GenBitR
;
3025 ctx
->Texture
._TexGenEnabled
|= ENABLE_TEXGEN(unit
);
3026 ctx
->Texture
._GenFlags
|= texUnit
->_GenFlags
;
3029 if (ctx
->TextureMatrixStack
[unit
].Top
->type
!= MATRIX_IDENTITY
)
3030 ctx
->Texture
._TexMatEnabled
|= ENABLE_TEXMAT(unit
);
3033 ctx
->Texture
._EnabledCoordUnits
= ctx
->Texture
._EnabledUnits
;
3034 /* Fragment programs may need texture coordinates but not the
3035 * corresponding texture images.
3037 if (ctx
->FragmentProgram
.Enabled
&& ctx
->FragmentProgram
.Current
) {
3038 ctx
->Texture
._EnabledCoordUnits
|=
3039 (ctx
->FragmentProgram
.Current
->InputsRead
>> FRAG_ATTRIB_TEX0
);
3044 void _mesa_update_texture( GLcontext
*ctx
, GLuint new_state
)
3046 if (new_state
& _NEW_TEXTURE_MATRIX
)
3047 update_texture_matrices( ctx
);
3049 if (new_state
& (_NEW_TEXTURE
| _NEW_PROGRAM
))
3050 update_texture_state( ctx
);
3053 /**********************************************************************/
3054 /***** Initialization *****/
3055 /**********************************************************************/
3058 * Allocate the proxy textures for the given context.
3060 * \param ctx the context to allocate proxies for.
3062 * \return GL_TRUE on success, or GL_FALSE on failure
3064 * If run out of memory part way through the allocations, clean up and return
3068 alloc_proxy_textures( GLcontext
*ctx
)
3070 ctx
->Texture
.Proxy1D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_1D
);
3071 if (!ctx
->Texture
.Proxy1D
)
3074 ctx
->Texture
.Proxy2D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_2D
);
3075 if (!ctx
->Texture
.Proxy2D
)
3078 ctx
->Texture
.Proxy3D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_3D
);
3079 if (!ctx
->Texture
.Proxy3D
)
3082 ctx
->Texture
.ProxyCubeMap
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_CUBE_MAP_ARB
);
3083 if (!ctx
->Texture
.ProxyCubeMap
)
3086 ctx
->Texture
.ProxyRect
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_RECTANGLE_NV
);
3087 if (!ctx
->Texture
.ProxyRect
)
3093 if (ctx
->Texture
.Proxy1D
)
3094 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1D
);
3095 if (ctx
->Texture
.Proxy2D
)
3096 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2D
);
3097 if (ctx
->Texture
.Proxy3D
)
3098 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy3D
);
3099 if (ctx
->Texture
.ProxyCubeMap
)
3100 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyCubeMap
);
3101 if (ctx
->Texture
.ProxyRect
)
3102 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyRect
);
3108 * Initialize a texture unit.
3110 * \param ctx GL context.
3111 * \param unit texture unit number to be initialized.
3114 init_texture_unit( GLcontext
*ctx
, GLuint unit
)
3116 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
3118 texUnit
->EnvMode
= GL_MODULATE
;
3119 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
3121 texUnit
->Combine
= default_combine_state
;
3122 texUnit
->_EnvMode
= default_combine_state
;
3123 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
3125 texUnit
->TexGenEnabled
= 0;
3126 texUnit
->GenModeS
= GL_EYE_LINEAR
;
3127 texUnit
->GenModeT
= GL_EYE_LINEAR
;
3128 texUnit
->GenModeR
= GL_EYE_LINEAR
;
3129 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
3130 texUnit
->_GenBitS
= TEXGEN_EYE_LINEAR
;
3131 texUnit
->_GenBitT
= TEXGEN_EYE_LINEAR
;
3132 texUnit
->_GenBitR
= TEXGEN_EYE_LINEAR
;
3133 texUnit
->_GenBitQ
= TEXGEN_EYE_LINEAR
;
3135 /* Yes, these plane coefficients are correct! */
3136 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
3137 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
3138 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
3139 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
3140 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
3141 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
3142 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
3143 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
3145 texUnit
->Current1D
= ctx
->Shared
->Default1D
;
3146 texUnit
->Current2D
= ctx
->Shared
->Default2D
;
3147 texUnit
->Current3D
= ctx
->Shared
->Default3D
;
3148 texUnit
->CurrentCubeMap
= ctx
->Shared
->DefaultCubeMap
;
3149 texUnit
->CurrentRect
= ctx
->Shared
->DefaultRect
;
3153 GLboolean
_mesa_init_texture( GLcontext
* ctx
)
3157 assert(MAX_TEXTURE_LEVELS
>= MAX_3D_TEXTURE_LEVELS
);
3158 assert(MAX_TEXTURE_LEVELS
>= MAX_CUBE_TEXTURE_LEVELS
);
3160 /* Effectively bind the default textures to all texture units */
3161 ctx
->Shared
->Default1D
->RefCount
+= MAX_TEXTURE_UNITS
;
3162 ctx
->Shared
->Default2D
->RefCount
+= MAX_TEXTURE_UNITS
;
3163 ctx
->Shared
->Default3D
->RefCount
+= MAX_TEXTURE_UNITS
;
3164 ctx
->Shared
->DefaultCubeMap
->RefCount
+= MAX_TEXTURE_UNITS
;
3165 ctx
->Shared
->DefaultRect
->RefCount
+= MAX_TEXTURE_UNITS
;
3168 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
3169 ctx
->Texture
._EnabledUnits
= 0;
3170 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
3171 init_texture_unit( ctx
, i
);
3172 ctx
->Texture
.SharedPalette
= GL_FALSE
;
3173 _mesa_init_colortable(&ctx
->Texture
.Palette
);
3175 /* Allocate proxy textures */
3176 if (!alloc_proxy_textures( ctx
))
3182 void _mesa_free_texture_data( GLcontext
*ctx
)
3186 /* Free proxy texture objects */
3187 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1D
);
3188 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2D
);
3189 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy3D
);
3190 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyCubeMap
);
3191 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyRect
);
3193 for (i
= 0; i
< MAX_TEXTURE_IMAGE_UNITS
; i
++)
3194 _mesa_free_colortable_data( &ctx
->Texture
.Unit
[i
].ColorTable
);