2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 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.
37 #include "texcompress.h"
41 #include "texenvprogram.h"
43 #include "math/m_xform.h"
46 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
47 #define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
51 * Default texture combine environment state. This is used to initialize
52 * a context's texture units and as the basis for converting "classic"
53 * texture environmnets to ARB_texture_env_combine style values.
55 static const struct gl_tex_env_combine_state default_combine_state
= {
56 GL_MODULATE
, GL_MODULATE
,
57 { GL_TEXTURE
, GL_PREVIOUS
, GL_CONSTANT
},
58 { GL_TEXTURE
, GL_PREVIOUS
, GL_CONSTANT
},
59 { GL_SRC_COLOR
, GL_SRC_COLOR
, GL_SRC_ALPHA
},
60 { GL_SRC_ALPHA
, GL_SRC_ALPHA
, GL_SRC_ALPHA
},
68 * Used by glXCopyContext to copy texture state from one context to another.
71 _mesa_copy_texture_state( const GLcontext
*src
, GLcontext
*dst
)
78 dst
->Texture
.CurrentUnit
= src
->Texture
.CurrentUnit
;
79 dst
->Texture
._GenFlags
= src
->Texture
._GenFlags
;
80 dst
->Texture
._TexGenEnabled
= src
->Texture
._TexGenEnabled
;
81 dst
->Texture
._TexMatEnabled
= src
->Texture
._TexMatEnabled
;
82 dst
->Texture
.SharedPalette
= src
->Texture
.SharedPalette
;
85 for (i
= 0; i
< src
->Const
.MaxTextureUnits
; i
++) {
86 dst
->Texture
.Unit
[i
].Enabled
= src
->Texture
.Unit
[i
].Enabled
;
87 dst
->Texture
.Unit
[i
].EnvMode
= src
->Texture
.Unit
[i
].EnvMode
;
88 COPY_4V(dst
->Texture
.Unit
[i
].EnvColor
, src
->Texture
.Unit
[i
].EnvColor
);
89 dst
->Texture
.Unit
[i
].TexGenEnabled
= src
->Texture
.Unit
[i
].TexGenEnabled
;
90 dst
->Texture
.Unit
[i
].GenModeS
= src
->Texture
.Unit
[i
].GenModeS
;
91 dst
->Texture
.Unit
[i
].GenModeT
= src
->Texture
.Unit
[i
].GenModeT
;
92 dst
->Texture
.Unit
[i
].GenModeR
= src
->Texture
.Unit
[i
].GenModeR
;
93 dst
->Texture
.Unit
[i
].GenModeQ
= src
->Texture
.Unit
[i
].GenModeQ
;
94 dst
->Texture
.Unit
[i
]._GenBitS
= src
->Texture
.Unit
[i
]._GenBitS
;
95 dst
->Texture
.Unit
[i
]._GenBitT
= src
->Texture
.Unit
[i
]._GenBitT
;
96 dst
->Texture
.Unit
[i
]._GenBitR
= src
->Texture
.Unit
[i
]._GenBitR
;
97 dst
->Texture
.Unit
[i
]._GenBitQ
= src
->Texture
.Unit
[i
]._GenBitQ
;
98 dst
->Texture
.Unit
[i
]._GenFlags
= src
->Texture
.Unit
[i
]._GenFlags
;
99 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneS
, src
->Texture
.Unit
[i
].ObjectPlaneS
);
100 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneT
, src
->Texture
.Unit
[i
].ObjectPlaneT
);
101 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneR
, src
->Texture
.Unit
[i
].ObjectPlaneR
);
102 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneQ
, src
->Texture
.Unit
[i
].ObjectPlaneQ
);
103 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneS
, src
->Texture
.Unit
[i
].EyePlaneS
);
104 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneT
, src
->Texture
.Unit
[i
].EyePlaneT
);
105 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneR
, src
->Texture
.Unit
[i
].EyePlaneR
);
106 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneQ
, src
->Texture
.Unit
[i
].EyePlaneQ
);
107 dst
->Texture
.Unit
[i
].LodBias
= src
->Texture
.Unit
[i
].LodBias
;
109 /* GL_EXT_texture_env_combine */
110 dst
->Texture
.Unit
[i
].Combine
.ModeRGB
= src
->Texture
.Unit
[i
].Combine
.ModeRGB
;
111 dst
->Texture
.Unit
[i
].Combine
.ModeA
= src
->Texture
.Unit
[i
].Combine
.ModeA
;
112 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.SourceRGB
, src
->Texture
.Unit
[i
].Combine
.SourceRGB
);
113 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.SourceA
, src
->Texture
.Unit
[i
].Combine
.SourceA
);
114 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.OperandRGB
, src
->Texture
.Unit
[i
].Combine
.OperandRGB
);
115 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.OperandA
, src
->Texture
.Unit
[i
].Combine
.OperandA
);
116 dst
->Texture
.Unit
[i
].Combine
.ScaleShiftRGB
= src
->Texture
.Unit
[i
].Combine
.ScaleShiftRGB
;
117 dst
->Texture
.Unit
[i
].Combine
.ScaleShiftA
= src
->Texture
.Unit
[i
].Combine
.ScaleShiftA
;
119 /* copy texture object bindings, not contents of texture objects */
120 _mesa_lock_context_textures(dst
);
122 _mesa_reference_texobj(&dst
->Texture
.Unit
[i
].Current1D
,
123 src
->Texture
.Unit
[i
].Current1D
);
124 _mesa_reference_texobj(&dst
->Texture
.Unit
[i
].Current2D
,
125 src
->Texture
.Unit
[i
].Current2D
);
126 _mesa_reference_texobj(&dst
->Texture
.Unit
[i
].Current3D
,
127 src
->Texture
.Unit
[i
].Current3D
);
128 _mesa_reference_texobj(&dst
->Texture
.Unit
[i
].CurrentCubeMap
,
129 src
->Texture
.Unit
[i
].CurrentCubeMap
);
130 _mesa_reference_texobj(&dst
->Texture
.Unit
[i
].CurrentRect
,
131 src
->Texture
.Unit
[i
].CurrentRect
);
132 _mesa_reference_texobj(&dst
->Texture
.Unit
[i
].Current1DArray
,
133 src
->Texture
.Unit
[i
].Current1DArray
);
134 _mesa_reference_texobj(&dst
->Texture
.Unit
[i
].Current2DArray
,
135 src
->Texture
.Unit
[i
].Current2DArray
);
137 _mesa_unlock_context_textures(dst
);
146 _mesa_print_texunit_state( GLcontext
*ctx
, GLuint unit
)
148 const struct gl_texture_unit
*texUnit
= ctx
->Texture
.Unit
+ unit
;
149 _mesa_printf("Texture Unit %d\n", unit
);
150 _mesa_printf(" GL_TEXTURE_ENV_MODE = %s\n", _mesa_lookup_enum_by_nr(texUnit
->EnvMode
));
151 _mesa_printf(" GL_COMBINE_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.ModeRGB
));
152 _mesa_printf(" GL_COMBINE_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.ModeA
));
153 _mesa_printf(" GL_SOURCE0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceRGB
[0]));
154 _mesa_printf(" GL_SOURCE1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceRGB
[1]));
155 _mesa_printf(" GL_SOURCE2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceRGB
[2]));
156 _mesa_printf(" GL_SOURCE0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceA
[0]));
157 _mesa_printf(" GL_SOURCE1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceA
[1]));
158 _mesa_printf(" GL_SOURCE2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceA
[2]));
159 _mesa_printf(" GL_OPERAND0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandRGB
[0]));
160 _mesa_printf(" GL_OPERAND1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandRGB
[1]));
161 _mesa_printf(" GL_OPERAND2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandRGB
[2]));
162 _mesa_printf(" GL_OPERAND0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandA
[0]));
163 _mesa_printf(" GL_OPERAND1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandA
[1]));
164 _mesa_printf(" GL_OPERAND2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandA
[2]));
165 _mesa_printf(" GL_RGB_SCALE = %d\n", 1 << texUnit
->Combine
.ScaleShiftRGB
);
166 _mesa_printf(" GL_ALPHA_SCALE = %d\n", 1 << texUnit
->Combine
.ScaleShiftA
);
167 _mesa_printf(" GL_TEXTURE_ENV_COLOR = (%f, %f, %f, %f)\n", texUnit
->EnvColor
[0], texUnit
->EnvColor
[1], texUnit
->EnvColor
[2], texUnit
->EnvColor
[3]);
172 /**********************************************************************/
173 /* Texture Environment */
174 /**********************************************************************/
177 * Convert "classic" texture environment to ARB_texture_env_combine style
180 * \param state texture_env_combine state vector to be filled-in.
181 * \param mode Classic texture environment mode (i.e., \c GL_REPLACE,
182 * \c GL_BLEND, \c GL_DECAL, etc.).
183 * \param texBaseFormat Base format of the texture associated with the
187 calculate_derived_texenv( struct gl_tex_env_combine_state
*state
,
188 GLenum mode
, GLenum texBaseFormat
)
193 *state
= default_combine_state
;
195 switch (texBaseFormat
) {
197 state
->SourceRGB
[0] = GL_PREVIOUS
;
200 case GL_LUMINANCE_ALPHA
:
208 state
->SourceA
[0] = GL_PREVIOUS
;
212 _mesa_problem(NULL
, "Invalid texBaseFormat in calculate_derived_texenv");
219 mode_rgb
= (texBaseFormat
== 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 (texBaseFormat
) {
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 (texBaseFormat
) {
256 mode_rgb
= GL_REPLACE
;
259 mode_a
= GL_INTERPOLATE
;
260 state
->SourceA
[0] = GL_CONSTANT
;
261 state
->OperandA
[2] = GL_SRC_ALPHA
;
265 case GL_LUMINANCE_ALPHA
:
268 state
->SourceRGB
[2] = GL_TEXTURE
;
269 state
->SourceA
[2] = GL_TEXTURE
;
270 state
->SourceRGB
[0] = GL_CONSTANT
;
271 state
->OperandRGB
[2] = GL_SRC_COLOR
;
277 mode_rgb
= (texBaseFormat
== GL_ALPHA
) ? GL_REPLACE
: GL_ADD
;
278 mode_a
= (texBaseFormat
== GL_INTENSITY
) ? GL_ADD
: GL_MODULATE
;
283 "Invalid texture env mode in calculate_derived_texenv");
287 state
->ModeRGB
= (state
->SourceRGB
[0] != GL_PREVIOUS
)
288 ? mode_rgb
: GL_REPLACE
;
289 state
->ModeA
= (state
->SourceA
[0] != GL_PREVIOUS
)
290 ? mode_a
: GL_REPLACE
;
295 _mesa_TexEnvfv( GLenum target
, GLenum pname
, const GLfloat
*param
)
298 GET_CURRENT_CONTEXT(ctx
);
299 struct gl_texture_unit
*texUnit
;
300 ASSERT_OUTSIDE_BEGIN_END(ctx
);
302 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
303 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
304 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
305 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexEnvfv(current unit)");
309 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
311 #define TE_ERROR(errCode, msg, value) \
312 _mesa_error(ctx, errCode, msg, _mesa_lookup_enum_by_nr(value));
314 if (target
== GL_TEXTURE_ENV
) {
316 case GL_TEXTURE_ENV_MODE
:
318 const GLenum mode
= (GLenum
) (GLint
) *param
;
319 if (texUnit
->EnvMode
== mode
)
321 if (mode
== GL_MODULATE
||
324 mode
== GL_REPLACE
||
325 (mode
== GL_ADD
&& ctx
->Extensions
.EXT_texture_env_add
) ||
326 (mode
== GL_COMBINE
&&
327 (ctx
->Extensions
.EXT_texture_env_combine
||
328 ctx
->Extensions
.ARB_texture_env_combine
))) {
330 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
331 texUnit
->EnvMode
= mode
;
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
;
356 if (texUnit
->Combine
.ModeRGB
== mode
)
367 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
368 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
372 case GL_DOT3_RGB_EXT
:
373 case GL_DOT3_RGBA_EXT
:
374 if (!ctx
->Extensions
.EXT_texture_env_dot3
) {
375 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
381 if (!ctx
->Extensions
.ARB_texture_env_dot3
) {
382 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
386 case GL_MODULATE_ADD_ATI
:
387 case GL_MODULATE_SIGNED_ADD_ATI
:
388 case GL_MODULATE_SUBTRACT_ATI
:
389 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
390 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
395 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", 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
;
410 if (texUnit
->Combine
.ModeA
== mode
)
421 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
422 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
426 case GL_MODULATE_ADD_ATI
:
427 case GL_MODULATE_SIGNED_ADD_ATI
:
428 case GL_MODULATE_SUBTRACT_ATI
:
429 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
430 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
435 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
438 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
439 texUnit
->Combine
.ModeA
= mode
;
442 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
449 if (ctx
->Extensions
.EXT_texture_env_combine
||
450 ctx
->Extensions
.ARB_texture_env_combine
) {
451 const GLenum source
= (GLenum
) (GLint
) *param
;
452 const GLuint s
= pname
- GL_SOURCE0_RGB
;
453 if (texUnit
->Combine
.SourceRGB
[s
] == source
)
455 if (source
== GL_TEXTURE
||
456 source
== GL_CONSTANT
||
457 source
== GL_PRIMARY_COLOR
||
458 source
== GL_PREVIOUS
||
459 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
460 source
>= GL_TEXTURE0
&&
461 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
462 (ctx
->Extensions
.ATI_texture_env_combine3
&&
463 (source
== GL_ZERO
|| source
== GL_ONE
))) {
465 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
466 texUnit
->Combine
.SourceRGB
[s
] = source
;
469 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
474 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
478 case GL_SOURCE0_ALPHA
:
479 case GL_SOURCE1_ALPHA
:
480 case GL_SOURCE2_ALPHA
:
481 if (ctx
->Extensions
.EXT_texture_env_combine
||
482 ctx
->Extensions
.ARB_texture_env_combine
) {
483 const GLenum source
= (GLenum
) (GLint
) *param
;
484 const GLuint s
= pname
- GL_SOURCE0_ALPHA
;
485 if (texUnit
->Combine
.SourceA
[s
] == source
)
487 if (source
== GL_TEXTURE
||
488 source
== GL_CONSTANT
||
489 source
== GL_PRIMARY_COLOR
||
490 source
== GL_PREVIOUS
||
491 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
492 source
>= GL_TEXTURE0
&&
493 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
494 (ctx
->Extensions
.ATI_texture_env_combine3
&&
495 (source
== GL_ZERO
|| source
== GL_ONE
))) {
497 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
498 texUnit
->Combine
.SourceA
[s
] = source
;
501 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
506 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
510 case GL_OPERAND0_RGB
:
511 case GL_OPERAND1_RGB
:
512 if (ctx
->Extensions
.EXT_texture_env_combine
||
513 ctx
->Extensions
.ARB_texture_env_combine
) {
514 const GLenum operand
= (GLenum
) (GLint
) *param
;
515 const GLuint s
= pname
- GL_OPERAND0_RGB
;
516 if (texUnit
->Combine
.OperandRGB
[s
] == operand
)
520 case GL_ONE_MINUS_SRC_COLOR
:
522 case GL_ONE_MINUS_SRC_ALPHA
:
523 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
524 texUnit
->Combine
.OperandRGB
[s
] = operand
;
527 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
532 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
536 case GL_OPERAND0_ALPHA
:
537 case GL_OPERAND1_ALPHA
:
538 if (ctx
->Extensions
.EXT_texture_env_combine
||
539 ctx
->Extensions
.ARB_texture_env_combine
) {
540 const GLenum operand
= (GLenum
) (GLint
) *param
;
541 if (texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] == operand
)
545 case GL_ONE_MINUS_SRC_ALPHA
:
546 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
547 texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] = operand
;
550 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
555 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
559 case GL_OPERAND2_RGB
:
560 if (ctx
->Extensions
.ARB_texture_env_combine
) {
561 const GLenum operand
= (GLenum
) (GLint
) *param
;
562 if (texUnit
->Combine
.OperandRGB
[2] == operand
)
565 case GL_SRC_COLOR
: /* ARB combine only */
566 case GL_ONE_MINUS_SRC_COLOR
: /* ARB combine only */
568 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
569 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
570 texUnit
->Combine
.OperandRGB
[2] = operand
;
573 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
577 else if (ctx
->Extensions
.EXT_texture_env_combine
) {
578 const GLenum operand
= (GLenum
) (GLint
) *param
;
579 if (texUnit
->Combine
.OperandRGB
[2] == operand
)
581 /* operand must be GL_SRC_ALPHA which is the initial value - thus
582 don't need to actually compare the operand to the possible value */
584 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
589 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
593 case GL_OPERAND2_ALPHA
:
594 if (ctx
->Extensions
.ARB_texture_env_combine
) {
595 const GLenum operand
= (GLenum
) (GLint
) *param
;
596 if (texUnit
->Combine
.OperandA
[2] == operand
)
600 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
601 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
602 texUnit
->Combine
.OperandA
[2] = operand
;
605 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
609 else if (ctx
->Extensions
.EXT_texture_env_combine
) {
610 const GLenum operand
= (GLenum
) (GLint
) *param
;
611 if (texUnit
->Combine
.OperandA
[2] == operand
)
613 /* operand must be GL_SRC_ALPHA which is the initial value - thus
614 don't need to actually compare the operand to the possible value */
616 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
621 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
626 if (ctx
->Extensions
.EXT_texture_env_combine
||
627 ctx
->Extensions
.ARB_texture_env_combine
) {
632 else if (*param
== 2.0) {
635 else if (*param
== 4.0) {
639 _mesa_error( ctx
, GL_INVALID_VALUE
,
640 "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" );
643 if (texUnit
->Combine
.ScaleShiftRGB
== newshift
)
645 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
646 texUnit
->Combine
.ScaleShiftRGB
= newshift
;
649 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
654 if (ctx
->Extensions
.EXT_texture_env_combine
||
655 ctx
->Extensions
.ARB_texture_env_combine
) {
660 else if (*param
== 2.0) {
663 else if (*param
== 4.0) {
667 _mesa_error( ctx
, GL_INVALID_VALUE
,
668 "glTexEnv(GL_ALPHA_SCALE not 1, 2 or 4)" );
671 if (texUnit
->Combine
.ScaleShiftA
== newshift
)
673 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
674 texUnit
->Combine
.ScaleShiftA
= newshift
;
677 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
682 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
686 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
687 /* GL_EXT_texture_lod_bias */
688 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
689 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
692 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
693 if (texUnit
->LodBias
== param
[0])
695 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
696 texUnit
->LodBias
= param
[0];
699 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
703 else if (target
== GL_POINT_SPRITE_NV
) {
704 /* GL_ARB_point_sprite / GL_NV_point_sprite */
705 if (!ctx
->Extensions
.NV_point_sprite
706 && !ctx
->Extensions
.ARB_point_sprite
) {
707 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
710 if (pname
== GL_COORD_REPLACE_NV
) {
711 const GLenum value
= (GLenum
) param
[0];
712 if (value
== GL_TRUE
|| value
== GL_FALSE
) {
713 /* It's kind of weird to set point state via glTexEnv,
714 * but that's what the spec calls for.
716 const GLboolean state
= (GLboolean
) value
;
717 if (ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] == state
)
719 FLUSH_VERTICES(ctx
, _NEW_POINT
);
720 ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] = state
;
723 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param=0x%x)", value
);
728 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname=0x%x)", pname
);
733 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)",target
);
737 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
738 _mesa_debug(ctx
, "glTexEnv %s %s %.1f(%s) ...\n",
739 _mesa_lookup_enum_by_nr(target
),
740 _mesa_lookup_enum_by_nr(pname
),
742 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
744 /* Tell device driver about the new texture environment */
745 if (ctx
->Driver
.TexEnv
) {
746 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
752 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
754 _mesa_TexEnvfv( target
, pname
, ¶m
);
760 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
763 p
[0] = (GLfloat
) param
;
764 p
[1] = p
[2] = p
[3] = 0.0;
765 _mesa_TexEnvfv( target
, pname
, p
);
770 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
773 if (pname
== GL_TEXTURE_ENV_COLOR
) {
774 p
[0] = INT_TO_FLOAT( param
[0] );
775 p
[1] = INT_TO_FLOAT( param
[1] );
776 p
[2] = INT_TO_FLOAT( param
[2] );
777 p
[3] = INT_TO_FLOAT( param
[3] );
780 p
[0] = (GLfloat
) param
[0];
781 p
[1] = p
[2] = p
[3] = 0; /* init to zero, just to be safe */
783 _mesa_TexEnvfv( target
, pname
, p
);
788 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
791 const struct gl_texture_unit
*texUnit
;
792 GET_CURRENT_CONTEXT(ctx
);
793 ASSERT_OUTSIDE_BEGIN_END(ctx
);
795 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
796 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
797 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
798 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnvfv(current unit)");
802 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
804 if (target
== GL_TEXTURE_ENV
) {
806 case GL_TEXTURE_ENV_MODE
:
807 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
809 case GL_TEXTURE_ENV_COLOR
:
810 COPY_4FV( params
, texUnit
->EnvColor
);
813 if (ctx
->Extensions
.EXT_texture_env_combine
||
814 ctx
->Extensions
.ARB_texture_env_combine
) {
815 *params
= (GLfloat
) texUnit
->Combine
.ModeRGB
;
818 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
821 case GL_COMBINE_ALPHA
:
822 if (ctx
->Extensions
.EXT_texture_env_combine
||
823 ctx
->Extensions
.ARB_texture_env_combine
) {
824 *params
= (GLfloat
) texUnit
->Combine
.ModeA
;
827 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
833 if (ctx
->Extensions
.EXT_texture_env_combine
||
834 ctx
->Extensions
.ARB_texture_env_combine
) {
835 const unsigned rgb_idx
= pname
- GL_SOURCE0_RGB
;
836 *params
= (GLfloat
) texUnit
->Combine
.SourceRGB
[rgb_idx
];
839 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
842 case GL_SOURCE0_ALPHA
:
843 case GL_SOURCE1_ALPHA
:
844 case GL_SOURCE2_ALPHA
:
845 if (ctx
->Extensions
.EXT_texture_env_combine
||
846 ctx
->Extensions
.ARB_texture_env_combine
) {
847 const unsigned alpha_idx
= pname
- GL_SOURCE0_ALPHA
;
848 *params
= (GLfloat
) texUnit
->Combine
.SourceA
[alpha_idx
];
851 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
854 case GL_OPERAND0_RGB
:
855 case GL_OPERAND1_RGB
:
856 case GL_OPERAND2_RGB
:
857 if (ctx
->Extensions
.EXT_texture_env_combine
||
858 ctx
->Extensions
.ARB_texture_env_combine
) {
859 const unsigned op_rgb
= pname
- GL_OPERAND0_RGB
;
860 *params
= (GLfloat
) texUnit
->Combine
.OperandRGB
[op_rgb
];
863 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
866 case GL_OPERAND0_ALPHA
:
867 case GL_OPERAND1_ALPHA
:
868 case GL_OPERAND2_ALPHA
:
869 if (ctx
->Extensions
.EXT_texture_env_combine
||
870 ctx
->Extensions
.ARB_texture_env_combine
) {
871 const unsigned op_alpha
= pname
- GL_OPERAND0_ALPHA
;
872 *params
= (GLfloat
) texUnit
->Combine
.OperandA
[op_alpha
];
875 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
879 if (ctx
->Extensions
.EXT_texture_env_combine
||
880 ctx
->Extensions
.ARB_texture_env_combine
) {
881 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
883 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
889 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
894 if (ctx
->Extensions
.EXT_texture_env_combine
||
895 ctx
->Extensions
.ARB_texture_env_combine
) {
896 if (texUnit
->Combine
.ScaleShiftA
== 0)
898 else if (texUnit
->Combine
.ScaleShiftA
== 1)
904 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
909 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname=0x%x)", pname
);
912 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
913 /* GL_EXT_texture_lod_bias */
914 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
915 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
918 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
919 *params
= texUnit
->LodBias
;
922 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
926 else if (target
== GL_POINT_SPRITE_NV
) {
927 /* GL_ARB_point_sprite / GL_NV_point_sprite */
928 if (!ctx
->Extensions
.NV_point_sprite
929 && !ctx
->Extensions
.ARB_point_sprite
) {
930 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
933 if (pname
== GL_COORD_REPLACE_NV
) {
934 *params
= (GLfloat
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
937 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
942 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
949 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
952 const struct gl_texture_unit
*texUnit
;
953 GET_CURRENT_CONTEXT(ctx
);
954 ASSERT_OUTSIDE_BEGIN_END(ctx
);
956 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
957 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
958 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
959 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnviv(current unit)");
963 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
965 if (target
== GL_TEXTURE_ENV
) {
967 case GL_TEXTURE_ENV_MODE
:
968 *params
= (GLint
) texUnit
->EnvMode
;
970 case GL_TEXTURE_ENV_COLOR
:
971 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
972 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
973 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
974 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
977 if (ctx
->Extensions
.EXT_texture_env_combine
||
978 ctx
->Extensions
.ARB_texture_env_combine
) {
979 *params
= (GLint
) texUnit
->Combine
.ModeRGB
;
982 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
985 case GL_COMBINE_ALPHA
:
986 if (ctx
->Extensions
.EXT_texture_env_combine
||
987 ctx
->Extensions
.ARB_texture_env_combine
) {
988 *params
= (GLint
) texUnit
->Combine
.ModeA
;
991 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
997 if (ctx
->Extensions
.EXT_texture_env_combine
||
998 ctx
->Extensions
.ARB_texture_env_combine
) {
999 const unsigned rgb_idx
= pname
- GL_SOURCE0_RGB
;
1000 *params
= (GLint
) texUnit
->Combine
.SourceRGB
[rgb_idx
];
1003 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1006 case GL_SOURCE0_ALPHA
:
1007 case GL_SOURCE1_ALPHA
:
1008 case GL_SOURCE2_ALPHA
:
1009 if (ctx
->Extensions
.EXT_texture_env_combine
||
1010 ctx
->Extensions
.ARB_texture_env_combine
) {
1011 const unsigned alpha_idx
= pname
- GL_SOURCE0_ALPHA
;
1012 *params
= (GLint
) texUnit
->Combine
.SourceA
[alpha_idx
];
1015 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1018 case GL_OPERAND0_RGB
:
1019 case GL_OPERAND1_RGB
:
1020 case GL_OPERAND2_RGB
:
1021 if (ctx
->Extensions
.EXT_texture_env_combine
||
1022 ctx
->Extensions
.ARB_texture_env_combine
) {
1023 const unsigned op_rgb
= pname
- GL_OPERAND0_RGB
;
1024 *params
= (GLint
) texUnit
->Combine
.OperandRGB
[op_rgb
];
1027 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1030 case GL_OPERAND0_ALPHA
:
1031 case GL_OPERAND1_ALPHA
:
1032 case GL_OPERAND2_ALPHA
:
1033 if (ctx
->Extensions
.EXT_texture_env_combine
||
1034 ctx
->Extensions
.ARB_texture_env_combine
) {
1035 const unsigned op_alpha
= pname
- GL_OPERAND0_ALPHA
;
1036 *params
= (GLint
) texUnit
->Combine
.OperandA
[op_alpha
];
1039 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1043 if (ctx
->Extensions
.EXT_texture_env_combine
||
1044 ctx
->Extensions
.ARB_texture_env_combine
) {
1045 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
1047 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
1053 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1057 case GL_ALPHA_SCALE
:
1058 if (ctx
->Extensions
.EXT_texture_env_combine
||
1059 ctx
->Extensions
.ARB_texture_env_combine
) {
1060 if (texUnit
->Combine
.ScaleShiftA
== 0)
1062 else if (texUnit
->Combine
.ScaleShiftA
== 1)
1068 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1073 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname=0x%x)",
1077 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
1078 /* GL_EXT_texture_lod_bias */
1079 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
1080 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1083 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
1084 *params
= (GLint
) texUnit
->LodBias
;
1087 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
1091 else if (target
== GL_POINT_SPRITE_NV
) {
1092 /* GL_ARB_point_sprite / GL_NV_point_sprite */
1093 if (!ctx
->Extensions
.NV_point_sprite
1094 && !ctx
->Extensions
.ARB_point_sprite
) {
1095 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1098 if (pname
== GL_COORD_REPLACE_NV
) {
1099 *params
= (GLint
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
1102 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
1107 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1115 /**********************************************************************/
1116 /* Texture Parameters */
1117 /**********************************************************************/
1120 * Check if a coordinate wrap mode is supported for the texture target.
1121 * \return GL_TRUE if legal, GL_FALSE otherwise
1124 validate_texture_wrap_mode(GLcontext
* ctx
, GLenum target
, GLenum wrap
)
1126 const struct gl_extensions
* const e
= & ctx
->Extensions
;
1128 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
1129 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
1130 /* any texture target */
1133 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
1134 (wrap
== GL_REPEAT
||
1135 (wrap
== GL_MIRRORED_REPEAT
&&
1136 e
->ARB_texture_mirrored_repeat
) ||
1137 (wrap
== GL_MIRROR_CLAMP_EXT
&&
1138 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
1139 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
1140 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
1141 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
1142 (e
->EXT_texture_mirror_clamp
)))) {
1143 /* non-rectangle texture */
1147 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1153 _mesa_TexParameterf( GLenum target
, GLenum pname
, GLfloat param
)
1155 _mesa_TexParameterfv(target
, pname
, ¶m
);
1160 _mesa_TexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
1162 const GLenum eparam
= (GLenum
) (GLint
) params
[0];
1163 struct gl_texture_unit
*texUnit
;
1164 struct gl_texture_object
*texObj
;
1165 GET_CURRENT_CONTEXT(ctx
);
1166 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1168 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
1169 _mesa_debug(ctx
, "glTexParameter %s %s %.1f(%s)...\n",
1170 _mesa_lookup_enum_by_nr(target
),
1171 _mesa_lookup_enum_by_nr(pname
),
1173 _mesa_lookup_enum_by_nr(eparam
));
1175 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1176 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameterfv(current unit)");
1180 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1184 texObj
= texUnit
->Current1D
;
1187 texObj
= texUnit
->Current2D
;
1190 texObj
= texUnit
->Current3D
;
1192 case GL_TEXTURE_CUBE_MAP
:
1193 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1194 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1197 texObj
= texUnit
->CurrentCubeMap
;
1199 case GL_TEXTURE_RECTANGLE_NV
:
1200 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1201 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1204 texObj
= texUnit
->CurrentRect
;
1206 case GL_TEXTURE_1D_ARRAY_EXT
:
1207 if (!ctx
->Extensions
.MESA_texture_array
) {
1208 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1211 texObj
= texUnit
->Current1DArray
;
1213 case GL_TEXTURE_2D_ARRAY_EXT
:
1214 if (!ctx
->Extensions
.MESA_texture_array
) {
1215 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1218 texObj
= texUnit
->Current2DArray
;
1221 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1226 case GL_TEXTURE_MIN_FILTER
:
1227 /* A small optimization */
1228 if (texObj
->MinFilter
== eparam
)
1230 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
1231 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1232 texObj
->MinFilter
= eparam
;
1234 else if ((eparam
==GL_NEAREST_MIPMAP_NEAREST
||
1235 eparam
==GL_LINEAR_MIPMAP_NEAREST
||
1236 eparam
==GL_NEAREST_MIPMAP_LINEAR
||
1237 eparam
==GL_LINEAR_MIPMAP_LINEAR
) &&
1238 texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
1239 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1240 texObj
->MinFilter
= eparam
;
1243 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1247 case GL_TEXTURE_MAG_FILTER
:
1248 /* A small optimization */
1249 if (texObj
->MagFilter
== eparam
)
1252 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
1253 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1254 texObj
->MagFilter
= eparam
;
1257 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1261 case GL_TEXTURE_WRAP_S
:
1262 if (texObj
->WrapS
== eparam
)
1264 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1265 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1266 texObj
->WrapS
= eparam
;
1272 case GL_TEXTURE_WRAP_T
:
1273 if (texObj
->WrapT
== eparam
)
1275 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1276 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1277 texObj
->WrapT
= eparam
;
1283 case GL_TEXTURE_WRAP_R
:
1284 if (texObj
->WrapR
== eparam
)
1286 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1287 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1288 texObj
->WrapR
= eparam
;
1294 case GL_TEXTURE_BORDER_COLOR
:
1295 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1296 texObj
->BorderColor
[RCOMP
] = params
[0];
1297 texObj
->BorderColor
[GCOMP
] = params
[1];
1298 texObj
->BorderColor
[BCOMP
] = params
[2];
1299 texObj
->BorderColor
[ACOMP
] = params
[3];
1300 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[RCOMP
], params
[0]);
1301 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[GCOMP
], params
[1]);
1302 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[BCOMP
], params
[2]);
1303 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[ACOMP
], params
[3]);
1305 case GL_TEXTURE_MIN_LOD
:
1306 if (texObj
->MinLod
== params
[0])
1308 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1309 texObj
->MinLod
= params
[0];
1311 case GL_TEXTURE_MAX_LOD
:
1312 if (texObj
->MaxLod
== params
[0])
1314 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1315 texObj
->MaxLod
= params
[0];
1317 case GL_TEXTURE_BASE_LEVEL
:
1318 if (params
[0] < 0.0) {
1319 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
1322 if (target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0.0) {
1323 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
1326 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1327 texObj
->BaseLevel
= (GLint
) params
[0];
1329 case GL_TEXTURE_MAX_LEVEL
:
1330 if (params
[0] < 0.0) {
1331 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
1334 if (target
== GL_TEXTURE_RECTANGLE_ARB
) {
1335 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(param)");
1338 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1339 texObj
->MaxLevel
= (GLint
) params
[0];
1341 case GL_TEXTURE_PRIORITY
:
1342 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1343 texObj
->Priority
= CLAMP( params
[0], 0.0F
, 1.0F
);
1345 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1346 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1347 if (params
[0] < 1.0) {
1348 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1351 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1352 /* clamp to max, that's what NVIDIA does */
1353 texObj
->MaxAnisotropy
= MIN2(params
[0],
1354 ctx
->Const
.MaxTextureMaxAnisotropy
);
1357 _mesa_error(ctx
, GL_INVALID_ENUM
,
1358 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
1362 case GL_TEXTURE_COMPARE_SGIX
:
1363 if (ctx
->Extensions
.SGIX_shadow
) {
1364 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1365 texObj
->CompareFlag
= params
[0] ? GL_TRUE
: GL_FALSE
;
1368 _mesa_error(ctx
, GL_INVALID_ENUM
,
1369 "glTexParameter(pname=GL_TEXTURE_COMPARE_SGIX)");
1373 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1374 if (ctx
->Extensions
.SGIX_shadow
) {
1375 GLenum op
= (GLenum
) params
[0];
1376 if (op
== GL_TEXTURE_LEQUAL_R_SGIX
||
1377 op
== GL_TEXTURE_GEQUAL_R_SGIX
) {
1378 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1379 texObj
->CompareOperator
= op
;
1382 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param)");
1386 _mesa_error(ctx
, GL_INVALID_ENUM
,
1387 "glTexParameter(pname=GL_TEXTURE_COMPARE_OPERATOR_SGIX)");
1391 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1392 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1393 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1394 texObj
->ShadowAmbient
= CLAMP(params
[0], 0.0F
, 1.0F
);
1397 _mesa_error(ctx
, GL_INVALID_ENUM
,
1398 "glTexParameter(pname=GL_SHADOW_AMBIENT_SGIX)");
1402 case GL_GENERATE_MIPMAP_SGIS
:
1403 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1404 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
1407 _mesa_error(ctx
, GL_INVALID_ENUM
,
1408 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
1412 case GL_TEXTURE_COMPARE_MODE_ARB
:
1413 if (ctx
->Extensions
.ARB_shadow
) {
1414 const GLenum mode
= (GLenum
) params
[0];
1415 if (mode
== GL_NONE
|| mode
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
1416 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1417 texObj
->CompareMode
= mode
;
1420 _mesa_error(ctx
, GL_INVALID_ENUM
,
1421 "glTexParameter(bad GL_TEXTURE_COMPARE_MODE_ARB: 0x%x)", mode
);
1426 _mesa_error(ctx
, GL_INVALID_ENUM
,
1427 "glTexParameter(pname=GL_TEXTURE_COMPARE_MODE_ARB)");
1431 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1432 if (ctx
->Extensions
.ARB_shadow
) {
1433 const GLenum func
= (GLenum
) params
[0];
1434 if (func
== GL_LEQUAL
|| func
== GL_GEQUAL
) {
1435 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1436 texObj
->CompareFunc
= func
;
1438 else if (ctx
->Extensions
.EXT_shadow_funcs
&&
1439 (func
== GL_EQUAL
||
1440 func
== GL_NOTEQUAL
||
1442 func
== GL_GREATER
||
1443 func
== GL_ALWAYS
||
1444 func
== GL_NEVER
)) {
1445 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1446 texObj
->CompareFunc
= func
;
1449 _mesa_error(ctx
, GL_INVALID_ENUM
,
1450 "glTexParameter(bad GL_TEXTURE_COMPARE_FUNC_ARB)");
1455 _mesa_error(ctx
, GL_INVALID_ENUM
,
1456 "glTexParameter(pname=GL_TEXTURE_COMPARE_FUNC_ARB)");
1460 case GL_DEPTH_TEXTURE_MODE_ARB
:
1461 if (ctx
->Extensions
.ARB_depth_texture
) {
1462 const GLenum result
= (GLenum
) params
[0];
1463 if (result
== GL_LUMINANCE
|| result
== GL_INTENSITY
1464 || result
== GL_ALPHA
) {
1465 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1466 texObj
->DepthMode
= result
;
1469 _mesa_error(ctx
, GL_INVALID_ENUM
,
1470 "glTexParameter(bad GL_DEPTH_TEXTURE_MODE_ARB)");
1475 _mesa_error(ctx
, GL_INVALID_ENUM
,
1476 "glTexParameter(pname=GL_DEPTH_TEXTURE_MODE_ARB)");
1480 case GL_TEXTURE_LOD_BIAS
:
1481 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias*/
1482 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1483 if (texObj
->LodBias
!= params
[0]) {
1484 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1485 texObj
->LodBias
= params
[0];
1491 _mesa_error(ctx
, GL_INVALID_ENUM
,
1492 "glTexParameter(pname=0x%x)", pname
);
1496 texObj
->_Complete
= GL_FALSE
;
1498 if (ctx
->Driver
.TexParameter
) {
1499 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
1505 _mesa_TexParameteri( GLenum target
, GLenum pname
, GLint param
)
1508 if (pname
== GL_TEXTURE_PRIORITY
)
1509 fparam
[0] = INT_TO_FLOAT(param
);
1511 fparam
[0] = (GLfloat
) param
;
1512 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
1513 _mesa_TexParameterfv(target
, pname
, fparam
);
1518 _mesa_TexParameteriv( GLenum target
, GLenum pname
, const GLint
*params
)
1521 if (pname
== GL_TEXTURE_BORDER_COLOR
) {
1522 fparam
[0] = INT_TO_FLOAT(params
[0]);
1523 fparam
[1] = INT_TO_FLOAT(params
[1]);
1524 fparam
[2] = INT_TO_FLOAT(params
[2]);
1525 fparam
[3] = INT_TO_FLOAT(params
[3]);
1528 if (pname
== GL_TEXTURE_PRIORITY
)
1529 fparam
[0] = INT_TO_FLOAT(params
[0]);
1531 fparam
[0] = (GLfloat
) params
[0];
1532 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
1534 _mesa_TexParameterfv(target
, pname
, fparam
);
1539 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1540 GLenum pname
, GLfloat
*params
)
1543 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1544 *params
= (GLfloat
) iparam
;
1549 tex_image_dimensions(GLcontext
*ctx
, GLenum target
)
1553 case GL_PROXY_TEXTURE_1D
:
1556 case GL_PROXY_TEXTURE_2D
:
1559 case GL_PROXY_TEXTURE_3D
:
1561 case GL_TEXTURE_CUBE_MAP
:
1562 case GL_PROXY_TEXTURE_CUBE_MAP
:
1563 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1564 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1565 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1566 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1567 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1568 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1569 return ctx
->Extensions
.ARB_texture_cube_map
? 2 : 0;
1570 case GL_TEXTURE_RECTANGLE_NV
:
1571 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1572 return ctx
->Extensions
.NV_texture_rectangle
? 2 : 0;
1573 case GL_TEXTURE_1D_ARRAY_EXT
:
1574 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1575 return ctx
->Extensions
.MESA_texture_array
? 2 : 0;
1576 case GL_TEXTURE_2D_ARRAY_EXT
:
1577 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1578 return ctx
->Extensions
.MESA_texture_array
? 3 : 0;
1580 _mesa_problem(ctx
, "bad target in _mesa_tex_target_dimensions()");
1587 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1588 GLenum pname
, GLint
*params
)
1590 const struct gl_texture_unit
*texUnit
;
1591 struct gl_texture_object
*texObj
;
1592 const struct gl_texture_image
*img
= NULL
;
1596 GET_CURRENT_CONTEXT(ctx
);
1597 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1599 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1600 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1601 "glGetTexLevelParameteriv(current unit)");
1605 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1607 /* this will catch bad target values */
1608 dimensions
= tex_image_dimensions(ctx
, target
); /* 1, 2 or 3 */
1609 if (dimensions
== 0) {
1610 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
1614 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1615 if (maxLevels
== 0) {
1616 /* should not happen since <target> was just checked above */
1617 _mesa_problem(ctx
, "maxLevels=0 in _mesa_GetTexLevelParameter");
1621 if (level
< 0 || level
>= maxLevels
) {
1622 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1626 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1627 _mesa_lock_texture(ctx
, texObj
);
1629 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1630 if (!img
|| !img
->TexFormat
) {
1631 /* undefined texture image */
1632 if (pname
== GL_TEXTURE_COMPONENTS
)
1639 isProxy
= _mesa_is_proxy_texture(target
);
1642 case GL_TEXTURE_WIDTH
:
1643 *params
= img
->Width
;
1645 case GL_TEXTURE_HEIGHT
:
1646 *params
= img
->Height
;
1648 case GL_TEXTURE_DEPTH
:
1649 *params
= img
->Depth
;
1651 case GL_TEXTURE_INTERNAL_FORMAT
:
1652 *params
= img
->InternalFormat
;
1654 case GL_TEXTURE_BORDER
:
1655 *params
= img
->Border
;
1657 case GL_TEXTURE_RED_SIZE
:
1658 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
1659 *params
= img
->TexFormat
->RedBits
;
1663 case GL_TEXTURE_GREEN_SIZE
:
1664 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
1665 *params
= img
->TexFormat
->GreenBits
;
1669 case GL_TEXTURE_BLUE_SIZE
:
1670 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
1671 *params
= img
->TexFormat
->BlueBits
;
1675 case GL_TEXTURE_ALPHA_SIZE
:
1676 if (img
->_BaseFormat
== GL_ALPHA
||
1677 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
1678 img
->_BaseFormat
== GL_RGBA
)
1679 *params
= img
->TexFormat
->AlphaBits
;
1683 case GL_TEXTURE_INTENSITY_SIZE
:
1684 if (img
->_BaseFormat
!= GL_INTENSITY
)
1686 else if (img
->TexFormat
->IntensityBits
> 0)
1687 *params
= img
->TexFormat
->IntensityBits
;
1688 else /* intensity probably stored as rgb texture */
1689 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
1691 case GL_TEXTURE_LUMINANCE_SIZE
:
1692 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
1693 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
1695 else if (img
->TexFormat
->LuminanceBits
> 0)
1696 *params
= img
->TexFormat
->LuminanceBits
;
1697 else /* luminance probably stored as rgb texture */
1698 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
1700 case GL_TEXTURE_INDEX_SIZE_EXT
:
1701 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
1702 *params
= img
->TexFormat
->IndexBits
;
1706 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1707 if (ctx
->Extensions
.SGIX_depth_texture
||
1708 ctx
->Extensions
.ARB_depth_texture
)
1709 *params
= img
->TexFormat
->DepthBits
;
1711 _mesa_error(ctx
, GL_INVALID_ENUM
,
1712 "glGetTexLevelParameter[if]v(pname)");
1714 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1715 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
1716 *params
= img
->TexFormat
->StencilBits
;
1719 _mesa_error(ctx
, GL_INVALID_ENUM
,
1720 "glGetTexLevelParameter[if]v(pname)");
1724 /* GL_ARB_texture_compression */
1725 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1726 if (ctx
->Extensions
.ARB_texture_compression
) {
1727 if (img
->IsCompressed
&& !isProxy
) {
1728 /* Don't use ctx->Driver.CompressedTextureSize() since that
1729 * may returned a padded hardware size.
1731 *params
= _mesa_compressed_texture_size(ctx
, img
->Width
,
1732 img
->Height
, img
->Depth
,
1733 img
->TexFormat
->MesaFormat
);
1736 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1737 "glGetTexLevelParameter[if]v(pname)");
1741 _mesa_error(ctx
, GL_INVALID_ENUM
,
1742 "glGetTexLevelParameter[if]v(pname)");
1745 case GL_TEXTURE_COMPRESSED
:
1746 if (ctx
->Extensions
.ARB_texture_compression
) {
1747 *params
= (GLint
) img
->IsCompressed
;
1750 _mesa_error(ctx
, GL_INVALID_ENUM
,
1751 "glGetTexLevelParameter[if]v(pname)");
1755 /* GL_ARB_texture_float */
1756 case GL_TEXTURE_RED_TYPE_ARB
:
1757 if (ctx
->Extensions
.ARB_texture_float
) {
1758 *params
= img
->TexFormat
->RedBits
? img
->TexFormat
->DataType
: GL_NONE
;
1761 _mesa_error(ctx
, GL_INVALID_ENUM
,
1762 "glGetTexLevelParameter[if]v(pname)");
1765 case GL_TEXTURE_GREEN_TYPE_ARB
:
1766 if (ctx
->Extensions
.ARB_texture_float
) {
1767 *params
= img
->TexFormat
->GreenBits
? img
->TexFormat
->DataType
: GL_NONE
;
1770 _mesa_error(ctx
, GL_INVALID_ENUM
,
1771 "glGetTexLevelParameter[if]v(pname)");
1774 case GL_TEXTURE_BLUE_TYPE_ARB
:
1775 if (ctx
->Extensions
.ARB_texture_float
) {
1776 *params
= img
->TexFormat
->BlueBits
? img
->TexFormat
->DataType
: GL_NONE
;
1779 _mesa_error(ctx
, GL_INVALID_ENUM
,
1780 "glGetTexLevelParameter[if]v(pname)");
1783 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1784 if (ctx
->Extensions
.ARB_texture_float
) {
1785 *params
= img
->TexFormat
->AlphaBits
? img
->TexFormat
->DataType
: GL_NONE
;
1788 _mesa_error(ctx
, GL_INVALID_ENUM
,
1789 "glGetTexLevelParameter[if]v(pname)");
1792 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1793 if (ctx
->Extensions
.ARB_texture_float
) {
1794 *params
= img
->TexFormat
->LuminanceBits
? img
->TexFormat
->DataType
: GL_NONE
;
1797 _mesa_error(ctx
, GL_INVALID_ENUM
,
1798 "glGetTexLevelParameter[if]v(pname)");
1801 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1802 if (ctx
->Extensions
.ARB_texture_float
) {
1803 *params
= img
->TexFormat
->IntensityBits
? img
->TexFormat
->DataType
: GL_NONE
;
1806 _mesa_error(ctx
, GL_INVALID_ENUM
,
1807 "glGetTexLevelParameter[if]v(pname)");
1810 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1811 if (ctx
->Extensions
.ARB_texture_float
) {
1812 *params
= img
->TexFormat
->DepthBits
? img
->TexFormat
->DataType
: GL_NONE
;
1815 _mesa_error(ctx
, GL_INVALID_ENUM
,
1816 "glGetTexLevelParameter[if]v(pname)");
1821 _mesa_error(ctx
, GL_INVALID_ENUM
,
1822 "glGetTexLevelParameter[if]v(pname)");
1826 _mesa_unlock_texture(ctx
, texObj
);
1832 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1834 struct gl_texture_unit
*texUnit
;
1835 struct gl_texture_object
*obj
;
1836 GLboolean error
= GL_FALSE
;
1837 GET_CURRENT_CONTEXT(ctx
);
1838 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1840 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1841 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1842 "glGetTexParameterfv(current unit)");
1846 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1848 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1850 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
1854 _mesa_lock_texture(ctx
, obj
);
1856 case GL_TEXTURE_MAG_FILTER
:
1857 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1859 case GL_TEXTURE_MIN_FILTER
:
1860 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1862 case GL_TEXTURE_WRAP_S
:
1863 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1865 case GL_TEXTURE_WRAP_T
:
1866 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1868 case GL_TEXTURE_WRAP_R
:
1869 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1871 case GL_TEXTURE_BORDER_COLOR
:
1872 params
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1873 params
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1874 params
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1875 params
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1877 case GL_TEXTURE_RESIDENT
:
1880 if (ctx
->Driver
.IsTextureResident
)
1881 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1884 *params
= ENUM_TO_FLOAT(resident
);
1887 case GL_TEXTURE_PRIORITY
:
1888 *params
= obj
->Priority
;
1890 case GL_TEXTURE_MIN_LOD
:
1891 *params
= obj
->MinLod
;
1893 case GL_TEXTURE_MAX_LOD
:
1894 *params
= obj
->MaxLod
;
1896 case GL_TEXTURE_BASE_LEVEL
:
1897 *params
= (GLfloat
) obj
->BaseLevel
;
1899 case GL_TEXTURE_MAX_LEVEL
:
1900 *params
= (GLfloat
) obj
->MaxLevel
;
1902 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1903 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1904 *params
= obj
->MaxAnisotropy
;
1909 case GL_TEXTURE_COMPARE_SGIX
:
1910 if (ctx
->Extensions
.SGIX_shadow
) {
1911 *params
= (GLfloat
) obj
->CompareFlag
;
1916 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1917 if (ctx
->Extensions
.SGIX_shadow
) {
1918 *params
= (GLfloat
) obj
->CompareOperator
;
1923 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1924 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1925 *params
= obj
->ShadowAmbient
;
1930 case GL_GENERATE_MIPMAP_SGIS
:
1931 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1932 *params
= (GLfloat
) obj
->GenerateMipmap
;
1937 case GL_TEXTURE_COMPARE_MODE_ARB
:
1938 if (ctx
->Extensions
.ARB_shadow
) {
1939 *params
= (GLfloat
) obj
->CompareMode
;
1944 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1945 if (ctx
->Extensions
.ARB_shadow
) {
1946 *params
= (GLfloat
) obj
->CompareFunc
;
1951 case GL_DEPTH_TEXTURE_MODE_ARB
:
1952 if (ctx
->Extensions
.ARB_depth_texture
) {
1953 *params
= (GLfloat
) obj
->DepthMode
;
1958 case GL_TEXTURE_LOD_BIAS
:
1959 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1960 *params
= obj
->LodBias
;
1970 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1973 _mesa_unlock_texture(ctx
, obj
);
1978 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1980 struct gl_texture_unit
*texUnit
;
1981 struct gl_texture_object
*obj
;
1982 GET_CURRENT_CONTEXT(ctx
);
1983 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1985 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1986 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1987 "glGetTexParameteriv(current unit)");
1991 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1993 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1995 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
2000 case GL_TEXTURE_MAG_FILTER
:
2001 *params
= (GLint
) obj
->MagFilter
;
2003 case GL_TEXTURE_MIN_FILTER
:
2004 *params
= (GLint
) obj
->MinFilter
;
2006 case GL_TEXTURE_WRAP_S
:
2007 *params
= (GLint
) obj
->WrapS
;
2009 case GL_TEXTURE_WRAP_T
:
2010 *params
= (GLint
) obj
->WrapT
;
2012 case GL_TEXTURE_WRAP_R
:
2013 *params
= (GLint
) obj
->WrapR
;
2015 case GL_TEXTURE_BORDER_COLOR
:
2018 b
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
2019 b
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
2020 b
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
2021 b
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
2022 params
[0] = FLOAT_TO_INT(b
[0]);
2023 params
[1] = FLOAT_TO_INT(b
[1]);
2024 params
[2] = FLOAT_TO_INT(b
[2]);
2025 params
[3] = FLOAT_TO_INT(b
[3]);
2028 case GL_TEXTURE_RESIDENT
:
2031 if (ctx
->Driver
.IsTextureResident
)
2032 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
2035 *params
= (GLint
) resident
;
2038 case GL_TEXTURE_PRIORITY
:
2039 *params
= FLOAT_TO_INT(obj
->Priority
);
2041 case GL_TEXTURE_MIN_LOD
:
2042 *params
= (GLint
) obj
->MinLod
;
2044 case GL_TEXTURE_MAX_LOD
:
2045 *params
= (GLint
) obj
->MaxLod
;
2047 case GL_TEXTURE_BASE_LEVEL
:
2048 *params
= obj
->BaseLevel
;
2050 case GL_TEXTURE_MAX_LEVEL
:
2051 *params
= obj
->MaxLevel
;
2053 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
2054 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
2055 *params
= (GLint
) obj
->MaxAnisotropy
;
2059 case GL_TEXTURE_COMPARE_SGIX
:
2060 if (ctx
->Extensions
.SGIX_shadow
) {
2061 *params
= (GLint
) obj
->CompareFlag
;
2065 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
2066 if (ctx
->Extensions
.SGIX_shadow
) {
2067 *params
= (GLint
) obj
->CompareOperator
;
2071 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
2072 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
2073 *params
= (GLint
) FLOAT_TO_INT(obj
->ShadowAmbient
);
2077 case GL_GENERATE_MIPMAP_SGIS
:
2078 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
2079 *params
= (GLint
) obj
->GenerateMipmap
;
2083 case GL_TEXTURE_COMPARE_MODE_ARB
:
2084 if (ctx
->Extensions
.ARB_shadow
) {
2085 *params
= (GLint
) obj
->CompareMode
;
2089 case GL_TEXTURE_COMPARE_FUNC_ARB
:
2090 if (ctx
->Extensions
.ARB_shadow
) {
2091 *params
= (GLint
) obj
->CompareFunc
;
2095 case GL_DEPTH_TEXTURE_MODE_ARB
:
2096 if (ctx
->Extensions
.ARB_depth_texture
) {
2097 *params
= (GLint
) obj
->DepthMode
;
2101 case GL_TEXTURE_LOD_BIAS
:
2102 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
2103 *params
= (GLint
) obj
->LodBias
;
2108 ; /* silence warnings */
2110 /* If we get here, pname was an unrecognized enum */
2111 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
2117 /**********************************************************************/
2118 /* Texture Coord Generation */
2119 /**********************************************************************/
2123 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
2125 GET_CURRENT_CONTEXT(ctx
);
2126 struct gl_texture_unit
*texUnit
;
2127 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2129 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
2130 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
2131 _mesa_lookup_enum_by_nr(coord
),
2132 _mesa_lookup_enum_by_nr(pname
),
2134 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *params
));
2136 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2137 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexGen(current unit)");
2141 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2145 if (pname
==GL_TEXTURE_GEN_MODE
) {
2146 GLenum mode
= (GLenum
) (GLint
) *params
;
2149 case GL_OBJECT_LINEAR
:
2150 bits
= TEXGEN_OBJ_LINEAR
;
2153 bits
= TEXGEN_EYE_LINEAR
;
2155 case GL_REFLECTION_MAP_NV
:
2156 bits
= TEXGEN_REFLECTION_MAP_NV
;
2158 case GL_NORMAL_MAP_NV
:
2159 bits
= TEXGEN_NORMAL_MAP_NV
;
2162 bits
= TEXGEN_SPHERE_MAP
;
2165 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2168 if (texUnit
->GenModeS
== mode
)
2170 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2171 texUnit
->GenModeS
= mode
;
2172 texUnit
->_GenBitS
= bits
;
2174 else if (pname
==GL_OBJECT_PLANE
) {
2175 if (TEST_EQ_4V(texUnit
->ObjectPlaneS
, params
))
2177 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2178 COPY_4FV(texUnit
->ObjectPlaneS
, params
);
2180 else if (pname
==GL_EYE_PLANE
) {
2182 /* Transform plane equation by the inverse modelview matrix */
2183 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
2184 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2186 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2187 if (TEST_EQ_4V(texUnit
->EyePlaneS
, tmp
))
2189 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2190 COPY_4FV(texUnit
->EyePlaneS
, tmp
);
2193 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2198 if (pname
==GL_TEXTURE_GEN_MODE
) {
2199 GLenum mode
= (GLenum
) (GLint
) *params
;
2202 case GL_OBJECT_LINEAR
:
2203 bitt
= TEXGEN_OBJ_LINEAR
;
2206 bitt
= TEXGEN_EYE_LINEAR
;
2208 case GL_REFLECTION_MAP_NV
:
2209 bitt
= TEXGEN_REFLECTION_MAP_NV
;
2211 case GL_NORMAL_MAP_NV
:
2212 bitt
= TEXGEN_NORMAL_MAP_NV
;
2215 bitt
= TEXGEN_SPHERE_MAP
;
2218 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2221 if (texUnit
->GenModeT
== mode
)
2223 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2224 texUnit
->GenModeT
= mode
;
2225 texUnit
->_GenBitT
= bitt
;
2227 else if (pname
==GL_OBJECT_PLANE
) {
2228 if (TEST_EQ_4V(texUnit
->ObjectPlaneT
, params
))
2230 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2231 COPY_4FV(texUnit
->ObjectPlaneT
, params
);
2233 else if (pname
==GL_EYE_PLANE
) {
2235 /* Transform plane equation by the inverse modelview matrix */
2236 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
2237 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2239 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2240 if (TEST_EQ_4V(texUnit
->EyePlaneT
, tmp
))
2242 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2243 COPY_4FV(texUnit
->EyePlaneT
, tmp
);
2246 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2251 if (pname
==GL_TEXTURE_GEN_MODE
) {
2252 GLenum mode
= (GLenum
) (GLint
) *params
;
2255 case GL_OBJECT_LINEAR
:
2256 bitr
= TEXGEN_OBJ_LINEAR
;
2258 case GL_REFLECTION_MAP_NV
:
2259 bitr
= TEXGEN_REFLECTION_MAP_NV
;
2261 case GL_NORMAL_MAP_NV
:
2262 bitr
= TEXGEN_NORMAL_MAP_NV
;
2265 bitr
= TEXGEN_EYE_LINEAR
;
2268 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2271 if (texUnit
->GenModeR
== mode
)
2273 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2274 texUnit
->GenModeR
= mode
;
2275 texUnit
->_GenBitR
= bitr
;
2277 else if (pname
==GL_OBJECT_PLANE
) {
2278 if (TEST_EQ_4V(texUnit
->ObjectPlaneR
, params
))
2280 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2281 COPY_4FV(texUnit
->ObjectPlaneR
, params
);
2283 else if (pname
==GL_EYE_PLANE
) {
2285 /* Transform plane equation by the inverse modelview matrix */
2286 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
2287 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2289 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2290 if (TEST_EQ_4V(texUnit
->EyePlaneR
, tmp
))
2292 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2293 COPY_4FV(texUnit
->EyePlaneR
, tmp
);
2296 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2301 if (pname
==GL_TEXTURE_GEN_MODE
) {
2302 GLenum mode
= (GLenum
) (GLint
) *params
;
2305 case GL_OBJECT_LINEAR
:
2306 bitq
= TEXGEN_OBJ_LINEAR
;
2309 bitq
= TEXGEN_EYE_LINEAR
;
2312 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2315 if (texUnit
->GenModeQ
== mode
)
2317 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2318 texUnit
->GenModeQ
= mode
;
2319 texUnit
->_GenBitQ
= bitq
;
2321 else if (pname
==GL_OBJECT_PLANE
) {
2322 if (TEST_EQ_4V(texUnit
->ObjectPlaneQ
, params
))
2324 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2325 COPY_4FV(texUnit
->ObjectPlaneQ
, params
);
2327 else if (pname
==GL_EYE_PLANE
) {
2329 /* Transform plane equation by the inverse modelview matrix */
2330 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
2331 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2333 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2334 if (TEST_EQ_4V(texUnit
->EyePlaneQ
, tmp
))
2336 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2337 COPY_4FV(texUnit
->EyePlaneQ
, tmp
);
2340 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2345 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
2349 if (ctx
->Driver
.TexGen
)
2350 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
2355 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
2358 p
[0] = (GLfloat
) params
[0];
2359 if (pname
== GL_TEXTURE_GEN_MODE
) {
2360 p
[1] = p
[2] = p
[3] = 0.0F
;
2363 p
[1] = (GLfloat
) params
[1];
2364 p
[2] = (GLfloat
) params
[2];
2365 p
[3] = (GLfloat
) params
[3];
2367 _mesa_TexGenfv(coord
, pname
, p
);
2372 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
2374 GLfloat p
= (GLfloat
) param
;
2375 _mesa_TexGenfv( coord
, pname
, &p
);
2380 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
2383 p
[0] = (GLfloat
) params
[0];
2384 if (pname
== GL_TEXTURE_GEN_MODE
) {
2385 p
[1] = p
[2] = p
[3] = 0.0F
;
2388 p
[1] = (GLfloat
) params
[1];
2389 p
[2] = (GLfloat
) params
[2];
2390 p
[3] = (GLfloat
) params
[3];
2392 _mesa_TexGenfv( coord
, pname
, p
);
2397 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
2399 _mesa_TexGenfv(coord
, pname
, ¶m
);
2404 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
2406 _mesa_TexGeniv( coord
, pname
, ¶m
);
2412 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
2414 const struct gl_texture_unit
*texUnit
;
2415 GET_CURRENT_CONTEXT(ctx
);
2416 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2418 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2419 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGendv(current unit)");
2423 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2427 if (pname
==GL_TEXTURE_GEN_MODE
) {
2428 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
2430 else if (pname
==GL_OBJECT_PLANE
) {
2431 COPY_4V( params
, texUnit
->ObjectPlaneS
);
2433 else if (pname
==GL_EYE_PLANE
) {
2434 COPY_4V( params
, texUnit
->EyePlaneS
);
2437 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2442 if (pname
==GL_TEXTURE_GEN_MODE
) {
2443 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
2445 else if (pname
==GL_OBJECT_PLANE
) {
2446 COPY_4V( params
, texUnit
->ObjectPlaneT
);
2448 else if (pname
==GL_EYE_PLANE
) {
2449 COPY_4V( params
, texUnit
->EyePlaneT
);
2452 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2457 if (pname
==GL_TEXTURE_GEN_MODE
) {
2458 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
2460 else if (pname
==GL_OBJECT_PLANE
) {
2461 COPY_4V( params
, texUnit
->ObjectPlaneR
);
2463 else if (pname
==GL_EYE_PLANE
) {
2464 COPY_4V( params
, texUnit
->EyePlaneR
);
2467 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2472 if (pname
==GL_TEXTURE_GEN_MODE
) {
2473 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
2475 else if (pname
==GL_OBJECT_PLANE
) {
2476 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
2478 else if (pname
==GL_EYE_PLANE
) {
2479 COPY_4V( params
, texUnit
->EyePlaneQ
);
2482 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2487 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
2495 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
2497 const struct gl_texture_unit
*texUnit
;
2498 GET_CURRENT_CONTEXT(ctx
);
2499 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2501 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2502 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGenfv(current unit)");
2506 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2510 if (pname
==GL_TEXTURE_GEN_MODE
) {
2511 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
2513 else if (pname
==GL_OBJECT_PLANE
) {
2514 COPY_4V( params
, texUnit
->ObjectPlaneS
);
2516 else if (pname
==GL_EYE_PLANE
) {
2517 COPY_4V( params
, texUnit
->EyePlaneS
);
2520 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2525 if (pname
==GL_TEXTURE_GEN_MODE
) {
2526 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
2528 else if (pname
==GL_OBJECT_PLANE
) {
2529 COPY_4V( params
, texUnit
->ObjectPlaneT
);
2531 else if (pname
==GL_EYE_PLANE
) {
2532 COPY_4V( params
, texUnit
->EyePlaneT
);
2535 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2540 if (pname
==GL_TEXTURE_GEN_MODE
) {
2541 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
2543 else if (pname
==GL_OBJECT_PLANE
) {
2544 COPY_4V( params
, texUnit
->ObjectPlaneR
);
2546 else if (pname
==GL_EYE_PLANE
) {
2547 COPY_4V( params
, texUnit
->EyePlaneR
);
2550 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2555 if (pname
==GL_TEXTURE_GEN_MODE
) {
2556 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
2558 else if (pname
==GL_OBJECT_PLANE
) {
2559 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
2561 else if (pname
==GL_EYE_PLANE
) {
2562 COPY_4V( params
, texUnit
->EyePlaneQ
);
2565 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2570 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
2578 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
2580 const struct gl_texture_unit
*texUnit
;
2581 GET_CURRENT_CONTEXT(ctx
);
2582 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2584 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2585 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGeniv(current unit)");
2589 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2593 if (pname
==GL_TEXTURE_GEN_MODE
) {
2594 params
[0] = texUnit
->GenModeS
;
2596 else if (pname
==GL_OBJECT_PLANE
) {
2597 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
2598 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
2599 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
2600 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
2602 else if (pname
==GL_EYE_PLANE
) {
2603 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
2604 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
2605 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
2606 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
2609 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2614 if (pname
==GL_TEXTURE_GEN_MODE
) {
2615 params
[0] = texUnit
->GenModeT
;
2617 else if (pname
==GL_OBJECT_PLANE
) {
2618 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
2619 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
2620 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
2621 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
2623 else if (pname
==GL_EYE_PLANE
) {
2624 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
2625 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
2626 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
2627 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
2630 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2635 if (pname
==GL_TEXTURE_GEN_MODE
) {
2636 params
[0] = texUnit
->GenModeR
;
2638 else if (pname
==GL_OBJECT_PLANE
) {
2639 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
2640 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
2641 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
2642 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
2644 else if (pname
==GL_EYE_PLANE
) {
2645 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
2646 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
2647 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
2648 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
2651 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2656 if (pname
==GL_TEXTURE_GEN_MODE
) {
2657 params
[0] = texUnit
->GenModeQ
;
2659 else if (pname
==GL_OBJECT_PLANE
) {
2660 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
2661 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
2662 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
2663 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
2665 else if (pname
==GL_EYE_PLANE
) {
2666 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
2667 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
2668 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
2669 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
2672 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2677 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
2684 /* GL_ARB_multitexture */
2686 _mesa_ActiveTextureARB(GLenum texture
)
2688 GET_CURRENT_CONTEXT(ctx
);
2689 const GLuint texUnit
= texture
- GL_TEXTURE0
;
2690 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2692 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2693 _mesa_debug(ctx
, "glActiveTexture %s\n",
2694 _mesa_lookup_enum_by_nr(texture
));
2696 /* XXX error-check against max(coordunits, imageunits) */
2697 if (texUnit
>= ctx
->Const
.MaxTextureUnits
) {
2698 _mesa_error(ctx
, GL_INVALID_ENUM
, "glActiveTexture(texture)");
2702 if (ctx
->Texture
.CurrentUnit
== texUnit
)
2705 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2707 ctx
->Texture
.CurrentUnit
= texUnit
;
2708 if (ctx
->Transform
.MatrixMode
== GL_TEXTURE
) {
2709 /* update current stack pointer */
2710 ctx
->CurrentStack
= &ctx
->TextureMatrixStack
[texUnit
];
2713 if (ctx
->Driver
.ActiveTexture
) {
2714 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
2719 /* GL_ARB_multitexture */
2721 _mesa_ClientActiveTextureARB(GLenum texture
)
2723 GET_CURRENT_CONTEXT(ctx
);
2724 GLuint texUnit
= texture
- GL_TEXTURE0
;
2725 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2727 if (texUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2728 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClientActiveTexture(texture)");
2732 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
2733 ctx
->Array
.ActiveTexture
= texUnit
;
2738 /**********************************************************************/
2739 /***** State management *****/
2740 /**********************************************************************/
2744 * \note This routine refers to derived texture attribute values to
2745 * compute the ENABLE_TEXMAT flags, but is only called on
2746 * _NEW_TEXTURE_MATRIX. On changes to _NEW_TEXTURE, the ENABLE_TEXMAT
2747 * flags are updated by _mesa_update_textures(), below.
2749 * \param ctx GL context.
2752 update_texture_matrices( GLcontext
*ctx
)
2756 ctx
->Texture
._TexMatEnabled
= 0;
2758 for (i
=0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
2759 if (_math_matrix_is_dirty(ctx
->TextureMatrixStack
[i
].Top
)) {
2760 _math_matrix_analyse( ctx
->TextureMatrixStack
[i
].Top
);
2762 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
&&
2763 ctx
->TextureMatrixStack
[i
].Top
->type
!= MATRIX_IDENTITY
)
2764 ctx
->Texture
._TexMatEnabled
|= ENABLE_TEXMAT(i
);
2766 if (ctx
->Driver
.TextureMatrix
)
2767 ctx
->Driver
.TextureMatrix( ctx
, i
, ctx
->TextureMatrixStack
[i
].Top
);
2774 * Update texture object's _Function field. We need to do this
2775 * whenever any of the texture object's shadow-related fields change
2776 * or when we start/stop using a fragment program.
2778 * This function could be expanded someday to update additional per-object
2779 * fields that depend on assorted state changes.
2782 update_texture_compare_function(GLcontext
*ctx
,
2783 struct gl_texture_object
*tObj
)
2785 /* XXX temporarily disable this test since it breaks the GLSL
2786 * shadow2D(), etc. functions.
2788 if (0 /*ctx->FragmentProgram._Current*/) {
2789 /* Texel/coordinate comparison is ignored for programs.
2790 * See GL_ARB_fragment_program/shader spec for details.
2792 tObj
->_Function
= GL_NONE
;
2794 else if (tObj
->CompareFlag
) {
2795 /* GL_SGIX_shadow */
2796 if (tObj
->CompareOperator
== GL_TEXTURE_LEQUAL_R_SGIX
) {
2797 tObj
->_Function
= GL_LEQUAL
;
2800 ASSERT(tObj
->CompareOperator
== GL_TEXTURE_GEQUAL_R_SGIX
);
2801 tObj
->_Function
= GL_GEQUAL
;
2804 else if (tObj
->CompareMode
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
2806 tObj
->_Function
= tObj
->CompareFunc
;
2809 tObj
->_Function
= GL_NONE
; /* pass depth through as grayscale */
2815 * Helper function for determining which texture object (1D, 2D, cube, etc)
2816 * should actually be used.
2819 texture_override(GLcontext
*ctx
,
2820 struct gl_texture_unit
*texUnit
, GLbitfield enableBits
,
2821 struct gl_texture_object
*texObj
, GLuint textureBit
)
2823 if (!texUnit
->_ReallyEnabled
&& (enableBits
& textureBit
)) {
2824 if (!texObj
->_Complete
) {
2825 _mesa_test_texobj_completeness(ctx
, texObj
);
2827 if (texObj
->_Complete
) {
2828 texUnit
->_ReallyEnabled
= textureBit
;
2829 texUnit
->_Current
= texObj
;
2830 update_texture_compare_function(ctx
, texObj
);
2837 * \note This routine refers to derived texture matrix values to
2838 * compute the ENABLE_TEXMAT flags, but is only called on
2839 * _NEW_TEXTURE. On changes to _NEW_TEXTURE_MATRIX, the ENABLE_TEXMAT
2840 * flags are updated by _mesa_update_texture_matrices, above.
2842 * \param ctx GL context.
2845 update_texture_state( GLcontext
*ctx
)
2848 struct gl_fragment_program
*fprog
= NULL
;
2849 struct gl_vertex_program
*vprog
= NULL
;
2851 if (ctx
->Shader
.CurrentProgram
&&
2852 ctx
->Shader
.CurrentProgram
->LinkStatus
) {
2853 fprog
= ctx
->Shader
.CurrentProgram
->FragmentProgram
;
2854 vprog
= ctx
->Shader
.CurrentProgram
->VertexProgram
;
2857 if (ctx
->FragmentProgram
._Enabled
) {
2858 fprog
= ctx
->FragmentProgram
.Current
;
2860 if (ctx
->VertexProgram
._Enabled
) {
2861 /* XXX enable this if/when non-shader vertex programs get
2863 vprog = ctx->VertexProgram.Current;
2868 ctx
->NewState
|= _NEW_TEXTURE
; /* TODO: only set this if there are
2872 ctx
->Texture
._EnabledUnits
= 0;
2873 ctx
->Texture
._GenFlags
= 0;
2874 ctx
->Texture
._TexMatEnabled
= 0;
2875 ctx
->Texture
._TexGenEnabled
= 0;
2878 * Update texture unit state.
2880 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
2881 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
2882 GLbitfield enableBits
;
2884 texUnit
->_Current
= NULL
;
2885 texUnit
->_ReallyEnabled
= 0;
2886 texUnit
->_GenFlags
= 0;
2888 /* Get the bitmask of texture enables.
2889 * enableBits will be a mask of the TEXTURE_*_BIT flags indicating
2890 * which texture targets are enabled (fixed function) or referenced
2891 * by a fragment shader/program. When multiple flags are set, we'll
2892 * settle on the one with highest priority (see texture_override below).
2894 if (fprog
|| vprog
) {
2897 enableBits
|= fprog
->Base
.TexturesUsed
[unit
];
2899 enableBits
|= vprog
->Base
.TexturesUsed
[unit
];
2902 if (!texUnit
->Enabled
)
2904 enableBits
= texUnit
->Enabled
;
2907 /* Look for the highest-priority texture target that's enabled and
2908 * complete. That's the one we'll use for texturing. If we're using
2909 * a fragment program we're guaranteed that bitcount(enabledBits) <= 1.
2911 texture_override(ctx
, texUnit
, enableBits
,
2912 texUnit
->Current2DArray
, TEXTURE_2D_ARRAY_BIT
);
2913 texture_override(ctx
, texUnit
, enableBits
,
2914 texUnit
->Current1DArray
, TEXTURE_1D_ARRAY_BIT
);
2915 texture_override(ctx
, texUnit
, enableBits
,
2916 texUnit
->CurrentCubeMap
, TEXTURE_CUBE_BIT
);
2917 texture_override(ctx
, texUnit
, enableBits
,
2918 texUnit
->Current3D
, TEXTURE_3D_BIT
);
2919 texture_override(ctx
, texUnit
, enableBits
,
2920 texUnit
->CurrentRect
, TEXTURE_RECT_BIT
);
2921 texture_override(ctx
, texUnit
, enableBits
,
2922 texUnit
->Current2D
, TEXTURE_2D_BIT
);
2923 texture_override(ctx
, texUnit
, enableBits
,
2924 texUnit
->Current1D
, TEXTURE_1D_BIT
);
2926 if (!texUnit
->_ReallyEnabled
) {
2930 if (texUnit
->_ReallyEnabled
)
2931 ctx
->Texture
._EnabledUnits
|= (1 << unit
);
2933 if (texUnit
->EnvMode
== GL_COMBINE
) {
2934 texUnit
->_CurrentCombine
= & texUnit
->Combine
;
2937 const struct gl_texture_object
*texObj
= texUnit
->_Current
;
2938 GLenum format
= texObj
->Image
[0][texObj
->BaseLevel
]->_BaseFormat
;
2939 if (format
== GL_COLOR_INDEX
) {
2940 format
= GL_RGBA
; /* a bit of a hack */
2942 else if (format
== GL_DEPTH_COMPONENT
2943 || format
== GL_DEPTH_STENCIL_EXT
) {
2944 format
= texObj
->DepthMode
;
2946 calculate_derived_texenv(&texUnit
->_EnvMode
, texUnit
->EnvMode
, format
);
2947 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
2950 switch (texUnit
->_CurrentCombine
->ModeRGB
) {
2952 texUnit
->_CurrentCombine
->_NumArgsRGB
= 1;
2960 case GL_DOT3_RGB_EXT
:
2961 case GL_DOT3_RGBA_EXT
:
2962 texUnit
->_CurrentCombine
->_NumArgsRGB
= 2;
2964 case GL_INTERPOLATE
:
2965 case GL_MODULATE_ADD_ATI
:
2966 case GL_MODULATE_SIGNED_ADD_ATI
:
2967 case GL_MODULATE_SUBTRACT_ATI
:
2968 texUnit
->_CurrentCombine
->_NumArgsRGB
= 3;
2971 texUnit
->_CurrentCombine
->_NumArgsRGB
= 0;
2972 _mesa_problem(ctx
, "invalid RGB combine mode in update_texture_state");
2976 switch (texUnit
->_CurrentCombine
->ModeA
) {
2978 texUnit
->_CurrentCombine
->_NumArgsA
= 1;
2984 texUnit
->_CurrentCombine
->_NumArgsA
= 2;
2986 case GL_INTERPOLATE
:
2987 case GL_MODULATE_ADD_ATI
:
2988 case GL_MODULATE_SIGNED_ADD_ATI
:
2989 case GL_MODULATE_SUBTRACT_ATI
:
2990 texUnit
->_CurrentCombine
->_NumArgsA
= 3;
2993 texUnit
->_CurrentCombine
->_NumArgsA
= 0;
2994 _mesa_problem(ctx
, "invalid Alpha combine mode in update_texture_state");
2998 if (texUnit
->TexGenEnabled
) {
2999 if (texUnit
->TexGenEnabled
& S_BIT
) {
3000 texUnit
->_GenFlags
|= texUnit
->_GenBitS
;
3002 if (texUnit
->TexGenEnabled
& T_BIT
) {
3003 texUnit
->_GenFlags
|= texUnit
->_GenBitT
;
3005 if (texUnit
->TexGenEnabled
& Q_BIT
) {
3006 texUnit
->_GenFlags
|= texUnit
->_GenBitQ
;
3008 if (texUnit
->TexGenEnabled
& R_BIT
) {
3009 texUnit
->_GenFlags
|= texUnit
->_GenBitR
;
3012 ctx
->Texture
._TexGenEnabled
|= ENABLE_TEXGEN(unit
);
3013 ctx
->Texture
._GenFlags
|= texUnit
->_GenFlags
;
3016 if (ctx
->TextureMatrixStack
[unit
].Top
->type
!= MATRIX_IDENTITY
)
3017 ctx
->Texture
._TexMatEnabled
|= ENABLE_TEXMAT(unit
);
3020 /* Determine which texture coordinate sets are actually needed */
3022 const GLuint coordMask
= (1 << MAX_TEXTURE_COORD_UNITS
) - 1;
3023 ctx
->Texture
._EnabledCoordUnits
3024 = (fprog
->Base
.InputsRead
>> FRAG_ATTRIB_TEX0
) & coordMask
;
3027 ctx
->Texture
._EnabledCoordUnits
= ctx
->Texture
._EnabledUnits
;
3033 * Update texture-related derived state.
3036 _mesa_update_texture( GLcontext
*ctx
, GLuint new_state
)
3038 if (new_state
& _NEW_TEXTURE_MATRIX
)
3039 update_texture_matrices( ctx
);
3041 if (new_state
& (_NEW_TEXTURE
| _NEW_PROGRAM
))
3042 update_texture_state( ctx
);
3046 /**********************************************************************/
3047 /***** Initialization *****/
3048 /**********************************************************************/
3051 * Allocate the proxy textures for the given context.
3053 * \param ctx the context to allocate proxies for.
3055 * \return GL_TRUE on success, or GL_FALSE on failure
3057 * If run out of memory part way through the allocations, clean up and return
3061 alloc_proxy_textures( GLcontext
*ctx
)
3063 ctx
->Texture
.Proxy1D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_1D
);
3064 if (!ctx
->Texture
.Proxy1D
)
3067 ctx
->Texture
.Proxy2D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_2D
);
3068 if (!ctx
->Texture
.Proxy2D
)
3071 ctx
->Texture
.Proxy3D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_3D
);
3072 if (!ctx
->Texture
.Proxy3D
)
3075 ctx
->Texture
.ProxyCubeMap
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_CUBE_MAP_ARB
);
3076 if (!ctx
->Texture
.ProxyCubeMap
)
3079 ctx
->Texture
.ProxyRect
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_RECTANGLE_NV
);
3080 if (!ctx
->Texture
.ProxyRect
)
3083 ctx
->Texture
.Proxy1DArray
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_1D_ARRAY_EXT
);
3084 if (!ctx
->Texture
.Proxy1DArray
)
3087 ctx
->Texture
.Proxy2DArray
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_2D_ARRAY_EXT
);
3088 if (!ctx
->Texture
.Proxy2DArray
)
3091 assert(ctx
->Texture
.Proxy1D
->RefCount
== 1);
3096 if (ctx
->Texture
.Proxy1D
)
3097 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1D
);
3098 if (ctx
->Texture
.Proxy2D
)
3099 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2D
);
3100 if (ctx
->Texture
.Proxy3D
)
3101 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy3D
);
3102 if (ctx
->Texture
.ProxyCubeMap
)
3103 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyCubeMap
);
3104 if (ctx
->Texture
.ProxyRect
)
3105 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyRect
);
3106 if (ctx
->Texture
.Proxy1DArray
)
3107 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1DArray
);
3108 if (ctx
->Texture
.Proxy2DArray
)
3109 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2DArray
);
3115 * Initialize a texture unit.
3117 * \param ctx GL context.
3118 * \param unit texture unit number to be initialized.
3121 init_texture_unit( GLcontext
*ctx
, GLuint unit
)
3123 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
3125 texUnit
->EnvMode
= GL_MODULATE
;
3126 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
3128 texUnit
->Combine
= default_combine_state
;
3129 texUnit
->_EnvMode
= default_combine_state
;
3130 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
3132 texUnit
->TexGenEnabled
= 0;
3133 texUnit
->GenModeS
= GL_EYE_LINEAR
;
3134 texUnit
->GenModeT
= GL_EYE_LINEAR
;
3135 texUnit
->GenModeR
= GL_EYE_LINEAR
;
3136 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
3137 texUnit
->_GenBitS
= TEXGEN_EYE_LINEAR
;
3138 texUnit
->_GenBitT
= TEXGEN_EYE_LINEAR
;
3139 texUnit
->_GenBitR
= TEXGEN_EYE_LINEAR
;
3140 texUnit
->_GenBitQ
= TEXGEN_EYE_LINEAR
;
3142 /* Yes, these plane coefficients are correct! */
3143 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
3144 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
3145 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
3146 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
3147 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
3148 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
3149 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
3150 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
3152 /* initialize current texture object ptrs to the shared default objects */
3153 _mesa_reference_texobj(&texUnit
->Current1D
, ctx
->Shared
->Default1D
);
3154 _mesa_reference_texobj(&texUnit
->Current2D
, ctx
->Shared
->Default2D
);
3155 _mesa_reference_texobj(&texUnit
->Current3D
, ctx
->Shared
->Default3D
);
3156 _mesa_reference_texobj(&texUnit
->CurrentCubeMap
, ctx
->Shared
->DefaultCubeMap
);
3157 _mesa_reference_texobj(&texUnit
->CurrentRect
, ctx
->Shared
->DefaultRect
);
3158 _mesa_reference_texobj(&texUnit
->Current1DArray
, ctx
->Shared
->Default1DArray
);
3159 _mesa_reference_texobj(&texUnit
->Current2DArray
, ctx
->Shared
->Default2DArray
);
3164 * Initialize texture state for the given context.
3167 _mesa_init_texture(GLcontext
*ctx
)
3171 assert(MAX_TEXTURE_LEVELS
>= MAX_3D_TEXTURE_LEVELS
);
3172 assert(MAX_TEXTURE_LEVELS
>= MAX_CUBE_TEXTURE_LEVELS
);
3175 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
3176 ctx
->Texture
._EnabledUnits
= 0;
3177 ctx
->Texture
.SharedPalette
= GL_FALSE
;
3178 _mesa_init_colortable(&ctx
->Texture
.Palette
);
3180 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++)
3181 init_texture_unit( ctx
, i
);
3183 /* After we're done initializing the context's texture state the default
3184 * texture objects' refcounts should be at least MAX_TEXTURE_UNITS + 1.
3186 assert(ctx
->Shared
->Default1D
->RefCount
>= MAX_TEXTURE_UNITS
+ 1);
3188 _mesa_TexEnvProgramCacheInit( ctx
);
3190 /* Allocate proxy textures */
3191 if (!alloc_proxy_textures( ctx
))
3199 * Free dynamically-allocted texture data attached to the given context.
3202 _mesa_free_texture_data(GLcontext
*ctx
)
3206 /* Free proxy texture objects */
3207 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1D
);
3208 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2D
);
3209 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy3D
);
3210 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyCubeMap
);
3211 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyRect
);
3212 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1DArray
);
3213 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2DArray
);
3215 for (i
= 0; i
< MAX_TEXTURE_IMAGE_UNITS
; i
++)
3216 _mesa_free_colortable_data( &ctx
->Texture
.Unit
[i
].ColorTable
);
3218 _mesa_TexEnvProgramCacheDestroy( ctx
);