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");
216 if (mode
== GL_REPLACE_EXT
)
222 mode_rgb
= (texBaseFormat
== GL_ALPHA
) ? GL_REPLACE
: mode
;
227 mode_rgb
= GL_INTERPOLATE
;
230 state
->SourceA
[0] = GL_PREVIOUS
;
232 /* Having alpha / luminance / intensity textures replace using the
233 * incoming fragment color matches the definition in NV_texture_shader.
234 * The 1.5 spec simply marks these as "undefined".
236 switch (texBaseFormat
) {
239 case GL_LUMINANCE_ALPHA
:
241 state
->SourceRGB
[0] = GL_PREVIOUS
;
245 mode_rgb
= GL_REPLACE
;
248 state
->SourceRGB
[2] = GL_TEXTURE
;
254 mode_rgb
= GL_INTERPOLATE
;
255 mode_a
= GL_MODULATE
;
257 switch (texBaseFormat
) {
259 mode_rgb
= GL_REPLACE
;
262 mode_a
= GL_INTERPOLATE
;
263 state
->SourceA
[0] = GL_CONSTANT
;
264 state
->OperandA
[2] = GL_SRC_ALPHA
;
268 case GL_LUMINANCE_ALPHA
:
271 state
->SourceRGB
[2] = GL_TEXTURE
;
272 state
->SourceA
[2] = GL_TEXTURE
;
273 state
->SourceRGB
[0] = GL_CONSTANT
;
274 state
->OperandRGB
[2] = GL_SRC_COLOR
;
280 mode_rgb
= (texBaseFormat
== GL_ALPHA
) ? GL_REPLACE
: GL_ADD
;
281 mode_a
= (texBaseFormat
== GL_INTENSITY
) ? GL_ADD
: GL_MODULATE
;
286 "Invalid texture env mode in calculate_derived_texenv");
290 state
->ModeRGB
= (state
->SourceRGB
[0] != GL_PREVIOUS
)
291 ? mode_rgb
: GL_REPLACE
;
292 state
->ModeA
= (state
->SourceA
[0] != GL_PREVIOUS
)
293 ? mode_a
: GL_REPLACE
;
298 _mesa_TexEnvfv( GLenum target
, GLenum pname
, const GLfloat
*param
)
301 GET_CURRENT_CONTEXT(ctx
);
302 struct gl_texture_unit
*texUnit
;
303 ASSERT_OUTSIDE_BEGIN_END(ctx
);
305 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
306 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
307 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
308 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexEnvfv(current unit)");
312 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
314 #define TE_ERROR(errCode, msg, value) \
315 _mesa_error(ctx, errCode, msg, _mesa_lookup_enum_by_nr(value));
317 if (target
== GL_TEXTURE_ENV
) {
319 case GL_TEXTURE_ENV_MODE
:
321 GLenum mode
= (GLenum
) (GLint
) *param
;
322 if (mode
== GL_REPLACE_EXT
)
324 if (texUnit
->EnvMode
== mode
)
326 if (mode
== GL_MODULATE
||
329 mode
== GL_REPLACE
||
330 (mode
== GL_ADD
&& ctx
->Extensions
.EXT_texture_env_add
) ||
331 (mode
== GL_COMBINE
&&
332 (ctx
->Extensions
.EXT_texture_env_combine
||
333 ctx
->Extensions
.ARB_texture_env_combine
))) {
335 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
336 texUnit
->EnvMode
= mode
;
339 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
344 case GL_TEXTURE_ENV_COLOR
:
347 tmp
[0] = CLAMP( param
[0], 0.0F
, 1.0F
);
348 tmp
[1] = CLAMP( param
[1], 0.0F
, 1.0F
);
349 tmp
[2] = CLAMP( param
[2], 0.0F
, 1.0F
);
350 tmp
[3] = CLAMP( param
[3], 0.0F
, 1.0F
);
351 if (TEST_EQ_4V(tmp
, texUnit
->EnvColor
))
353 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
354 COPY_4FV(texUnit
->EnvColor
, tmp
);
358 if (ctx
->Extensions
.EXT_texture_env_combine
||
359 ctx
->Extensions
.ARB_texture_env_combine
) {
360 const GLenum mode
= (GLenum
) (GLint
) *param
;
361 if (texUnit
->Combine
.ModeRGB
== mode
)
372 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
373 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
377 case GL_DOT3_RGB_EXT
:
378 case GL_DOT3_RGBA_EXT
:
379 if (!ctx
->Extensions
.EXT_texture_env_dot3
) {
380 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
386 if (!ctx
->Extensions
.ARB_texture_env_dot3
) {
387 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
391 case GL_MODULATE_ADD_ATI
:
392 case GL_MODULATE_SIGNED_ADD_ATI
:
393 case GL_MODULATE_SUBTRACT_ATI
:
394 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
395 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
400 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
403 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
404 texUnit
->Combine
.ModeRGB
= mode
;
407 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
411 case GL_COMBINE_ALPHA
:
412 if (ctx
->Extensions
.EXT_texture_env_combine
||
413 ctx
->Extensions
.ARB_texture_env_combine
) {
414 const GLenum mode
= (GLenum
) (GLint
) *param
;
415 if (texUnit
->Combine
.ModeA
== mode
)
426 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
427 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
431 case GL_MODULATE_ADD_ATI
:
432 case GL_MODULATE_SIGNED_ADD_ATI
:
433 case GL_MODULATE_SUBTRACT_ATI
:
434 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
435 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
440 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
443 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
444 texUnit
->Combine
.ModeA
= mode
;
447 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
454 if (ctx
->Extensions
.EXT_texture_env_combine
||
455 ctx
->Extensions
.ARB_texture_env_combine
) {
456 const GLenum source
= (GLenum
) (GLint
) *param
;
457 const GLuint s
= pname
- GL_SOURCE0_RGB
;
458 if (texUnit
->Combine
.SourceRGB
[s
] == source
)
460 if (source
== GL_TEXTURE
||
461 source
== GL_CONSTANT
||
462 source
== GL_PRIMARY_COLOR
||
463 source
== GL_PREVIOUS
||
464 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
465 source
>= GL_TEXTURE0
&&
466 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
467 (ctx
->Extensions
.ATI_texture_env_combine3
&&
468 (source
== GL_ZERO
|| source
== GL_ONE
))) {
470 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
471 texUnit
->Combine
.SourceRGB
[s
] = source
;
474 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
479 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
483 case GL_SOURCE0_ALPHA
:
484 case GL_SOURCE1_ALPHA
:
485 case GL_SOURCE2_ALPHA
:
486 if (ctx
->Extensions
.EXT_texture_env_combine
||
487 ctx
->Extensions
.ARB_texture_env_combine
) {
488 const GLenum source
= (GLenum
) (GLint
) *param
;
489 const GLuint s
= pname
- GL_SOURCE0_ALPHA
;
490 if (texUnit
->Combine
.SourceA
[s
] == source
)
492 if (source
== GL_TEXTURE
||
493 source
== GL_CONSTANT
||
494 source
== GL_PRIMARY_COLOR
||
495 source
== GL_PREVIOUS
||
496 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
497 source
>= GL_TEXTURE0
&&
498 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
499 (ctx
->Extensions
.ATI_texture_env_combine3
&&
500 (source
== GL_ZERO
|| source
== GL_ONE
))) {
502 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
503 texUnit
->Combine
.SourceA
[s
] = source
;
506 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
511 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
515 case GL_OPERAND0_RGB
:
516 case GL_OPERAND1_RGB
:
517 if (ctx
->Extensions
.EXT_texture_env_combine
||
518 ctx
->Extensions
.ARB_texture_env_combine
) {
519 const GLenum operand
= (GLenum
) (GLint
) *param
;
520 const GLuint s
= pname
- GL_OPERAND0_RGB
;
521 if (texUnit
->Combine
.OperandRGB
[s
] == operand
)
525 case GL_ONE_MINUS_SRC_COLOR
:
527 case GL_ONE_MINUS_SRC_ALPHA
:
528 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
529 texUnit
->Combine
.OperandRGB
[s
] = operand
;
532 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
537 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
541 case GL_OPERAND0_ALPHA
:
542 case GL_OPERAND1_ALPHA
:
543 if (ctx
->Extensions
.EXT_texture_env_combine
||
544 ctx
->Extensions
.ARB_texture_env_combine
) {
545 const GLenum operand
= (GLenum
) (GLint
) *param
;
546 if (texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] == operand
)
550 case GL_ONE_MINUS_SRC_ALPHA
:
551 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
552 texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] = operand
;
555 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
560 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
564 case GL_OPERAND2_RGB
:
565 if (ctx
->Extensions
.ARB_texture_env_combine
) {
566 const GLenum operand
= (GLenum
) (GLint
) *param
;
567 if (texUnit
->Combine
.OperandRGB
[2] == operand
)
570 case GL_SRC_COLOR
: /* ARB combine only */
571 case GL_ONE_MINUS_SRC_COLOR
: /* ARB combine only */
573 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
574 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
575 texUnit
->Combine
.OperandRGB
[2] = operand
;
578 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
582 else if (ctx
->Extensions
.EXT_texture_env_combine
) {
583 const GLenum operand
= (GLenum
) (GLint
) *param
;
584 if (texUnit
->Combine
.OperandRGB
[2] == operand
)
586 /* operand must be GL_SRC_ALPHA which is the initial value - thus
587 don't need to actually compare the operand to the possible value */
589 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
594 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
598 case GL_OPERAND2_ALPHA
:
599 if (ctx
->Extensions
.ARB_texture_env_combine
) {
600 const GLenum operand
= (GLenum
) (GLint
) *param
;
601 if (texUnit
->Combine
.OperandA
[2] == operand
)
605 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
606 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
607 texUnit
->Combine
.OperandA
[2] = operand
;
610 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
614 else if (ctx
->Extensions
.EXT_texture_env_combine
) {
615 const GLenum operand
= (GLenum
) (GLint
) *param
;
616 if (texUnit
->Combine
.OperandA
[2] == operand
)
618 /* operand must be GL_SRC_ALPHA which is the initial value - thus
619 don't need to actually compare the operand to the possible value */
621 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
626 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
631 if (ctx
->Extensions
.EXT_texture_env_combine
||
632 ctx
->Extensions
.ARB_texture_env_combine
) {
637 else if (*param
== 2.0) {
640 else if (*param
== 4.0) {
644 _mesa_error( ctx
, GL_INVALID_VALUE
,
645 "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" );
648 if (texUnit
->Combine
.ScaleShiftRGB
== newshift
)
650 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
651 texUnit
->Combine
.ScaleShiftRGB
= newshift
;
654 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
659 if (ctx
->Extensions
.EXT_texture_env_combine
||
660 ctx
->Extensions
.ARB_texture_env_combine
) {
665 else if (*param
== 2.0) {
668 else if (*param
== 4.0) {
672 _mesa_error( ctx
, GL_INVALID_VALUE
,
673 "glTexEnv(GL_ALPHA_SCALE not 1, 2 or 4)" );
676 if (texUnit
->Combine
.ScaleShiftA
== newshift
)
678 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
679 texUnit
->Combine
.ScaleShiftA
= newshift
;
682 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
687 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
691 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
692 /* GL_EXT_texture_lod_bias */
693 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
694 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
697 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
698 if (texUnit
->LodBias
== param
[0])
700 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
701 texUnit
->LodBias
= param
[0];
704 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
708 else if (target
== GL_POINT_SPRITE_NV
) {
709 /* GL_ARB_point_sprite / GL_NV_point_sprite */
710 if (!ctx
->Extensions
.NV_point_sprite
711 && !ctx
->Extensions
.ARB_point_sprite
) {
712 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
715 if (pname
== GL_COORD_REPLACE_NV
) {
716 const GLenum value
= (GLenum
) param
[0];
717 if (value
== GL_TRUE
|| value
== GL_FALSE
) {
718 /* It's kind of weird to set point state via glTexEnv,
719 * but that's what the spec calls for.
721 const GLboolean state
= (GLboolean
) value
;
722 if (ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] == state
)
724 FLUSH_VERTICES(ctx
, _NEW_POINT
);
725 ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] = state
;
728 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param=0x%x)", value
);
733 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname=0x%x)", pname
);
738 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)",target
);
742 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
743 _mesa_debug(ctx
, "glTexEnv %s %s %.1f(%s) ...\n",
744 _mesa_lookup_enum_by_nr(target
),
745 _mesa_lookup_enum_by_nr(pname
),
747 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
749 /* Tell device driver about the new texture environment */
750 if (ctx
->Driver
.TexEnv
) {
751 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
757 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
759 _mesa_TexEnvfv( target
, pname
, ¶m
);
765 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
768 p
[0] = (GLfloat
) param
;
769 p
[1] = p
[2] = p
[3] = 0.0;
770 _mesa_TexEnvfv( target
, pname
, p
);
775 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
778 if (pname
== GL_TEXTURE_ENV_COLOR
) {
779 p
[0] = INT_TO_FLOAT( param
[0] );
780 p
[1] = INT_TO_FLOAT( param
[1] );
781 p
[2] = INT_TO_FLOAT( param
[2] );
782 p
[3] = INT_TO_FLOAT( param
[3] );
785 p
[0] = (GLfloat
) param
[0];
786 p
[1] = p
[2] = p
[3] = 0; /* init to zero, just to be safe */
788 _mesa_TexEnvfv( target
, pname
, p
);
793 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
796 const struct gl_texture_unit
*texUnit
;
797 GET_CURRENT_CONTEXT(ctx
);
798 ASSERT_OUTSIDE_BEGIN_END(ctx
);
800 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
801 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
802 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
803 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnvfv(current unit)");
807 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
809 if (target
== GL_TEXTURE_ENV
) {
811 case GL_TEXTURE_ENV_MODE
:
812 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
814 case GL_TEXTURE_ENV_COLOR
:
815 COPY_4FV( params
, texUnit
->EnvColor
);
818 if (ctx
->Extensions
.EXT_texture_env_combine
||
819 ctx
->Extensions
.ARB_texture_env_combine
) {
820 *params
= (GLfloat
) texUnit
->Combine
.ModeRGB
;
823 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
826 case GL_COMBINE_ALPHA
:
827 if (ctx
->Extensions
.EXT_texture_env_combine
||
828 ctx
->Extensions
.ARB_texture_env_combine
) {
829 *params
= (GLfloat
) texUnit
->Combine
.ModeA
;
832 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
838 if (ctx
->Extensions
.EXT_texture_env_combine
||
839 ctx
->Extensions
.ARB_texture_env_combine
) {
840 const unsigned rgb_idx
= pname
- GL_SOURCE0_RGB
;
841 *params
= (GLfloat
) texUnit
->Combine
.SourceRGB
[rgb_idx
];
844 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
847 case GL_SOURCE0_ALPHA
:
848 case GL_SOURCE1_ALPHA
:
849 case GL_SOURCE2_ALPHA
:
850 if (ctx
->Extensions
.EXT_texture_env_combine
||
851 ctx
->Extensions
.ARB_texture_env_combine
) {
852 const unsigned alpha_idx
= pname
- GL_SOURCE0_ALPHA
;
853 *params
= (GLfloat
) texUnit
->Combine
.SourceA
[alpha_idx
];
856 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
859 case GL_OPERAND0_RGB
:
860 case GL_OPERAND1_RGB
:
861 case GL_OPERAND2_RGB
:
862 if (ctx
->Extensions
.EXT_texture_env_combine
||
863 ctx
->Extensions
.ARB_texture_env_combine
) {
864 const unsigned op_rgb
= pname
- GL_OPERAND0_RGB
;
865 *params
= (GLfloat
) texUnit
->Combine
.OperandRGB
[op_rgb
];
868 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
871 case GL_OPERAND0_ALPHA
:
872 case GL_OPERAND1_ALPHA
:
873 case GL_OPERAND2_ALPHA
:
874 if (ctx
->Extensions
.EXT_texture_env_combine
||
875 ctx
->Extensions
.ARB_texture_env_combine
) {
876 const unsigned op_alpha
= pname
- GL_OPERAND0_ALPHA
;
877 *params
= (GLfloat
) texUnit
->Combine
.OperandA
[op_alpha
];
880 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
884 if (ctx
->Extensions
.EXT_texture_env_combine
||
885 ctx
->Extensions
.ARB_texture_env_combine
) {
886 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
888 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
894 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
899 if (ctx
->Extensions
.EXT_texture_env_combine
||
900 ctx
->Extensions
.ARB_texture_env_combine
) {
901 if (texUnit
->Combine
.ScaleShiftA
== 0)
903 else if (texUnit
->Combine
.ScaleShiftA
== 1)
909 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
914 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname=0x%x)", pname
);
917 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
918 /* GL_EXT_texture_lod_bias */
919 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
920 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
923 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
924 *params
= texUnit
->LodBias
;
927 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
931 else if (target
== GL_POINT_SPRITE_NV
) {
932 /* GL_ARB_point_sprite / GL_NV_point_sprite */
933 if (!ctx
->Extensions
.NV_point_sprite
934 && !ctx
->Extensions
.ARB_point_sprite
) {
935 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
938 if (pname
== GL_COORD_REPLACE_NV
) {
939 *params
= (GLfloat
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
942 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
947 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
954 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
957 const struct gl_texture_unit
*texUnit
;
958 GET_CURRENT_CONTEXT(ctx
);
959 ASSERT_OUTSIDE_BEGIN_END(ctx
);
961 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
962 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
963 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
964 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnviv(current unit)");
968 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
970 if (target
== GL_TEXTURE_ENV
) {
972 case GL_TEXTURE_ENV_MODE
:
973 *params
= (GLint
) texUnit
->EnvMode
;
975 case GL_TEXTURE_ENV_COLOR
:
976 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
977 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
978 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
979 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
982 if (ctx
->Extensions
.EXT_texture_env_combine
||
983 ctx
->Extensions
.ARB_texture_env_combine
) {
984 *params
= (GLint
) texUnit
->Combine
.ModeRGB
;
987 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
990 case GL_COMBINE_ALPHA
:
991 if (ctx
->Extensions
.EXT_texture_env_combine
||
992 ctx
->Extensions
.ARB_texture_env_combine
) {
993 *params
= (GLint
) texUnit
->Combine
.ModeA
;
996 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1000 case GL_SOURCE1_RGB
:
1001 case GL_SOURCE2_RGB
:
1002 if (ctx
->Extensions
.EXT_texture_env_combine
||
1003 ctx
->Extensions
.ARB_texture_env_combine
) {
1004 const unsigned rgb_idx
= pname
- GL_SOURCE0_RGB
;
1005 *params
= (GLint
) texUnit
->Combine
.SourceRGB
[rgb_idx
];
1008 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1011 case GL_SOURCE0_ALPHA
:
1012 case GL_SOURCE1_ALPHA
:
1013 case GL_SOURCE2_ALPHA
:
1014 if (ctx
->Extensions
.EXT_texture_env_combine
||
1015 ctx
->Extensions
.ARB_texture_env_combine
) {
1016 const unsigned alpha_idx
= pname
- GL_SOURCE0_ALPHA
;
1017 *params
= (GLint
) texUnit
->Combine
.SourceA
[alpha_idx
];
1020 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1023 case GL_OPERAND0_RGB
:
1024 case GL_OPERAND1_RGB
:
1025 case GL_OPERAND2_RGB
:
1026 if (ctx
->Extensions
.EXT_texture_env_combine
||
1027 ctx
->Extensions
.ARB_texture_env_combine
) {
1028 const unsigned op_rgb
= pname
- GL_OPERAND0_RGB
;
1029 *params
= (GLint
) texUnit
->Combine
.OperandRGB
[op_rgb
];
1032 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1035 case GL_OPERAND0_ALPHA
:
1036 case GL_OPERAND1_ALPHA
:
1037 case GL_OPERAND2_ALPHA
:
1038 if (ctx
->Extensions
.EXT_texture_env_combine
||
1039 ctx
->Extensions
.ARB_texture_env_combine
) {
1040 const unsigned op_alpha
= pname
- GL_OPERAND0_ALPHA
;
1041 *params
= (GLint
) texUnit
->Combine
.OperandA
[op_alpha
];
1044 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1048 if (ctx
->Extensions
.EXT_texture_env_combine
||
1049 ctx
->Extensions
.ARB_texture_env_combine
) {
1050 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
1052 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
1058 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1062 case GL_ALPHA_SCALE
:
1063 if (ctx
->Extensions
.EXT_texture_env_combine
||
1064 ctx
->Extensions
.ARB_texture_env_combine
) {
1065 if (texUnit
->Combine
.ScaleShiftA
== 0)
1067 else if (texUnit
->Combine
.ScaleShiftA
== 1)
1073 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1078 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname=0x%x)",
1082 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
1083 /* GL_EXT_texture_lod_bias */
1084 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
1085 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1088 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
1089 *params
= (GLint
) texUnit
->LodBias
;
1092 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
1096 else if (target
== GL_POINT_SPRITE_NV
) {
1097 /* GL_ARB_point_sprite / GL_NV_point_sprite */
1098 if (!ctx
->Extensions
.NV_point_sprite
1099 && !ctx
->Extensions
.ARB_point_sprite
) {
1100 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1103 if (pname
== GL_COORD_REPLACE_NV
) {
1104 *params
= (GLint
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
1107 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
1112 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1120 /**********************************************************************/
1121 /* Texture Parameters */
1122 /**********************************************************************/
1125 * Check if a coordinate wrap mode is supported for the texture target.
1126 * \return GL_TRUE if legal, GL_FALSE otherwise
1129 validate_texture_wrap_mode(GLcontext
* ctx
, GLenum target
, GLenum wrap
)
1131 const struct gl_extensions
* const e
= & ctx
->Extensions
;
1133 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
1134 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
1135 /* any texture target */
1138 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
1139 (wrap
== GL_REPEAT
||
1140 (wrap
== GL_MIRRORED_REPEAT
&&
1141 e
->ARB_texture_mirrored_repeat
) ||
1142 (wrap
== GL_MIRROR_CLAMP_EXT
&&
1143 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
1144 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
1145 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
1146 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
1147 (e
->EXT_texture_mirror_clamp
)))) {
1148 /* non-rectangle texture */
1152 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1158 _mesa_TexParameterf( GLenum target
, GLenum pname
, GLfloat param
)
1160 _mesa_TexParameterfv(target
, pname
, ¶m
);
1165 _mesa_TexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
1167 const GLenum eparam
= (GLenum
) (GLint
) params
[0];
1168 struct gl_texture_unit
*texUnit
;
1169 struct gl_texture_object
*texObj
;
1170 GET_CURRENT_CONTEXT(ctx
);
1171 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1173 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
1174 _mesa_debug(ctx
, "glTexParameter %s %s %.1f(%s)...\n",
1175 _mesa_lookup_enum_by_nr(target
),
1176 _mesa_lookup_enum_by_nr(pname
),
1178 _mesa_lookup_enum_by_nr(eparam
));
1180 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1181 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameterfv(current unit)");
1185 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1189 texObj
= texUnit
->Current1D
;
1192 texObj
= texUnit
->Current2D
;
1195 texObj
= texUnit
->Current3D
;
1197 case GL_TEXTURE_CUBE_MAP
:
1198 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1199 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1202 texObj
= texUnit
->CurrentCubeMap
;
1204 case GL_TEXTURE_RECTANGLE_NV
:
1205 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1206 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1209 texObj
= texUnit
->CurrentRect
;
1211 case GL_TEXTURE_1D_ARRAY_EXT
:
1212 if (!ctx
->Extensions
.MESA_texture_array
) {
1213 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1216 texObj
= texUnit
->Current1DArray
;
1218 case GL_TEXTURE_2D_ARRAY_EXT
:
1219 if (!ctx
->Extensions
.MESA_texture_array
) {
1220 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1223 texObj
= texUnit
->Current2DArray
;
1226 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1231 case GL_TEXTURE_MIN_FILTER
:
1232 /* A small optimization */
1233 if (texObj
->MinFilter
== eparam
)
1235 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
1236 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1237 texObj
->MinFilter
= eparam
;
1239 else if ((eparam
==GL_NEAREST_MIPMAP_NEAREST
||
1240 eparam
==GL_LINEAR_MIPMAP_NEAREST
||
1241 eparam
==GL_NEAREST_MIPMAP_LINEAR
||
1242 eparam
==GL_LINEAR_MIPMAP_LINEAR
) &&
1243 texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
1244 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1245 texObj
->MinFilter
= eparam
;
1248 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1252 case GL_TEXTURE_MAG_FILTER
:
1253 /* A small optimization */
1254 if (texObj
->MagFilter
== eparam
)
1257 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
1258 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1259 texObj
->MagFilter
= eparam
;
1262 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1266 case GL_TEXTURE_WRAP_S
:
1267 if (texObj
->WrapS
== eparam
)
1269 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1270 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1271 texObj
->WrapS
= eparam
;
1277 case GL_TEXTURE_WRAP_T
:
1278 if (texObj
->WrapT
== eparam
)
1280 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1281 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1282 texObj
->WrapT
= eparam
;
1288 case GL_TEXTURE_WRAP_R
:
1289 if (texObj
->WrapR
== eparam
)
1291 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1292 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1293 texObj
->WrapR
= eparam
;
1299 case GL_TEXTURE_BORDER_COLOR
:
1300 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1301 texObj
->BorderColor
[RCOMP
] = params
[0];
1302 texObj
->BorderColor
[GCOMP
] = params
[1];
1303 texObj
->BorderColor
[BCOMP
] = params
[2];
1304 texObj
->BorderColor
[ACOMP
] = params
[3];
1305 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[RCOMP
], params
[0]);
1306 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[GCOMP
], params
[1]);
1307 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[BCOMP
], params
[2]);
1308 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[ACOMP
], params
[3]);
1310 case GL_TEXTURE_MIN_LOD
:
1311 if (texObj
->MinLod
== params
[0])
1313 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1314 texObj
->MinLod
= params
[0];
1316 case GL_TEXTURE_MAX_LOD
:
1317 if (texObj
->MaxLod
== params
[0])
1319 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1320 texObj
->MaxLod
= params
[0];
1322 case GL_TEXTURE_BASE_LEVEL
:
1323 if (params
[0] < 0.0) {
1324 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
1327 if (target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0.0) {
1328 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
1331 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1332 texObj
->BaseLevel
= (GLint
) params
[0];
1334 case GL_TEXTURE_MAX_LEVEL
:
1335 if (params
[0] < 0.0) {
1336 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
1339 if (target
== GL_TEXTURE_RECTANGLE_ARB
) {
1340 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(param)");
1343 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1344 texObj
->MaxLevel
= (GLint
) params
[0];
1346 case GL_TEXTURE_PRIORITY
:
1347 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1348 texObj
->Priority
= CLAMP( params
[0], 0.0F
, 1.0F
);
1350 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1351 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1352 if (params
[0] < 1.0) {
1353 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1356 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1357 /* clamp to max, that's what NVIDIA does */
1358 texObj
->MaxAnisotropy
= MIN2(params
[0],
1359 ctx
->Const
.MaxTextureMaxAnisotropy
);
1362 _mesa_error(ctx
, GL_INVALID_ENUM
,
1363 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
1367 case GL_TEXTURE_COMPARE_SGIX
:
1368 if (ctx
->Extensions
.SGIX_shadow
) {
1369 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1370 texObj
->CompareFlag
= params
[0] ? GL_TRUE
: GL_FALSE
;
1373 _mesa_error(ctx
, GL_INVALID_ENUM
,
1374 "glTexParameter(pname=GL_TEXTURE_COMPARE_SGIX)");
1378 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1379 if (ctx
->Extensions
.SGIX_shadow
) {
1380 GLenum op
= (GLenum
) params
[0];
1381 if (op
== GL_TEXTURE_LEQUAL_R_SGIX
||
1382 op
== GL_TEXTURE_GEQUAL_R_SGIX
) {
1383 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1384 texObj
->CompareOperator
= op
;
1387 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param)");
1391 _mesa_error(ctx
, GL_INVALID_ENUM
,
1392 "glTexParameter(pname=GL_TEXTURE_COMPARE_OPERATOR_SGIX)");
1396 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1397 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1398 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1399 texObj
->ShadowAmbient
= CLAMP(params
[0], 0.0F
, 1.0F
);
1402 _mesa_error(ctx
, GL_INVALID_ENUM
,
1403 "glTexParameter(pname=GL_SHADOW_AMBIENT_SGIX)");
1407 case GL_GENERATE_MIPMAP_SGIS
:
1408 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1409 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
1412 _mesa_error(ctx
, GL_INVALID_ENUM
,
1413 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
1417 case GL_TEXTURE_COMPARE_MODE_ARB
:
1418 if (ctx
->Extensions
.ARB_shadow
) {
1419 const GLenum mode
= (GLenum
) params
[0];
1420 if (mode
== GL_NONE
|| mode
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
1421 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1422 texObj
->CompareMode
= mode
;
1425 _mesa_error(ctx
, GL_INVALID_ENUM
,
1426 "glTexParameter(bad GL_TEXTURE_COMPARE_MODE_ARB: 0x%x)", mode
);
1431 _mesa_error(ctx
, GL_INVALID_ENUM
,
1432 "glTexParameter(pname=GL_TEXTURE_COMPARE_MODE_ARB)");
1436 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1437 if (ctx
->Extensions
.ARB_shadow
) {
1438 const GLenum func
= (GLenum
) params
[0];
1439 if (func
== GL_LEQUAL
|| func
== GL_GEQUAL
) {
1440 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1441 texObj
->CompareFunc
= func
;
1443 else if (ctx
->Extensions
.EXT_shadow_funcs
&&
1444 (func
== GL_EQUAL
||
1445 func
== GL_NOTEQUAL
||
1447 func
== GL_GREATER
||
1448 func
== GL_ALWAYS
||
1449 func
== GL_NEVER
)) {
1450 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1451 texObj
->CompareFunc
= func
;
1454 _mesa_error(ctx
, GL_INVALID_ENUM
,
1455 "glTexParameter(bad GL_TEXTURE_COMPARE_FUNC_ARB)");
1460 _mesa_error(ctx
, GL_INVALID_ENUM
,
1461 "glTexParameter(pname=GL_TEXTURE_COMPARE_FUNC_ARB)");
1465 case GL_DEPTH_TEXTURE_MODE_ARB
:
1466 if (ctx
->Extensions
.ARB_depth_texture
) {
1467 const GLenum result
= (GLenum
) params
[0];
1468 if (result
== GL_LUMINANCE
|| result
== GL_INTENSITY
1469 || result
== GL_ALPHA
) {
1470 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1471 texObj
->DepthMode
= result
;
1474 _mesa_error(ctx
, GL_INVALID_ENUM
,
1475 "glTexParameter(bad GL_DEPTH_TEXTURE_MODE_ARB)");
1480 _mesa_error(ctx
, GL_INVALID_ENUM
,
1481 "glTexParameter(pname=GL_DEPTH_TEXTURE_MODE_ARB)");
1485 case GL_TEXTURE_LOD_BIAS
:
1486 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias*/
1487 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1488 if (texObj
->LodBias
!= params
[0]) {
1489 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1490 texObj
->LodBias
= params
[0];
1496 _mesa_error(ctx
, GL_INVALID_ENUM
,
1497 "glTexParameter(pname=0x%x)", pname
);
1501 texObj
->_Complete
= GL_FALSE
;
1503 if (ctx
->Driver
.TexParameter
) {
1504 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
1510 _mesa_TexParameteri( GLenum target
, GLenum pname
, GLint param
)
1513 if (pname
== GL_TEXTURE_PRIORITY
)
1514 fparam
[0] = INT_TO_FLOAT(param
);
1516 fparam
[0] = (GLfloat
) param
;
1517 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
1518 _mesa_TexParameterfv(target
, pname
, fparam
);
1523 _mesa_TexParameteriv( GLenum target
, GLenum pname
, const GLint
*params
)
1526 if (pname
== GL_TEXTURE_BORDER_COLOR
) {
1527 fparam
[0] = INT_TO_FLOAT(params
[0]);
1528 fparam
[1] = INT_TO_FLOAT(params
[1]);
1529 fparam
[2] = INT_TO_FLOAT(params
[2]);
1530 fparam
[3] = INT_TO_FLOAT(params
[3]);
1533 if (pname
== GL_TEXTURE_PRIORITY
)
1534 fparam
[0] = INT_TO_FLOAT(params
[0]);
1536 fparam
[0] = (GLfloat
) params
[0];
1537 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
1539 _mesa_TexParameterfv(target
, pname
, fparam
);
1544 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1545 GLenum pname
, GLfloat
*params
)
1548 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1549 *params
= (GLfloat
) iparam
;
1554 tex_image_dimensions(GLcontext
*ctx
, GLenum target
)
1558 case GL_PROXY_TEXTURE_1D
:
1561 case GL_PROXY_TEXTURE_2D
:
1564 case GL_PROXY_TEXTURE_3D
:
1566 case GL_TEXTURE_CUBE_MAP
:
1567 case GL_PROXY_TEXTURE_CUBE_MAP
:
1568 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1569 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1570 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1571 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1572 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1573 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1574 return ctx
->Extensions
.ARB_texture_cube_map
? 2 : 0;
1575 case GL_TEXTURE_RECTANGLE_NV
:
1576 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1577 return ctx
->Extensions
.NV_texture_rectangle
? 2 : 0;
1578 case GL_TEXTURE_1D_ARRAY_EXT
:
1579 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1580 return ctx
->Extensions
.MESA_texture_array
? 2 : 0;
1581 case GL_TEXTURE_2D_ARRAY_EXT
:
1582 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1583 return ctx
->Extensions
.MESA_texture_array
? 3 : 0;
1585 _mesa_problem(ctx
, "bad target in _mesa_tex_target_dimensions()");
1592 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1593 GLenum pname
, GLint
*params
)
1595 const struct gl_texture_unit
*texUnit
;
1596 struct gl_texture_object
*texObj
;
1597 const struct gl_texture_image
*img
= NULL
;
1601 GET_CURRENT_CONTEXT(ctx
);
1602 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1604 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1605 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1606 "glGetTexLevelParameteriv(current unit)");
1610 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1612 /* this will catch bad target values */
1613 dimensions
= tex_image_dimensions(ctx
, target
); /* 1, 2 or 3 */
1614 if (dimensions
== 0) {
1615 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
1619 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1620 if (maxLevels
== 0) {
1621 /* should not happen since <target> was just checked above */
1622 _mesa_problem(ctx
, "maxLevels=0 in _mesa_GetTexLevelParameter");
1626 if (level
< 0 || level
>= maxLevels
) {
1627 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1631 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1632 _mesa_lock_texture(ctx
, texObj
);
1634 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1635 if (!img
|| !img
->TexFormat
) {
1636 /* undefined texture image */
1637 if (pname
== GL_TEXTURE_COMPONENTS
)
1644 isProxy
= _mesa_is_proxy_texture(target
);
1647 case GL_TEXTURE_WIDTH
:
1648 *params
= img
->Width
;
1650 case GL_TEXTURE_HEIGHT
:
1651 *params
= img
->Height
;
1653 case GL_TEXTURE_DEPTH
:
1654 *params
= img
->Depth
;
1656 case GL_TEXTURE_INTERNAL_FORMAT
:
1657 *params
= img
->InternalFormat
;
1659 case GL_TEXTURE_BORDER
:
1660 *params
= img
->Border
;
1662 case GL_TEXTURE_RED_SIZE
:
1663 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
1664 *params
= img
->TexFormat
->RedBits
;
1668 case GL_TEXTURE_GREEN_SIZE
:
1669 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
1670 *params
= img
->TexFormat
->GreenBits
;
1674 case GL_TEXTURE_BLUE_SIZE
:
1675 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
1676 *params
= img
->TexFormat
->BlueBits
;
1680 case GL_TEXTURE_ALPHA_SIZE
:
1681 if (img
->_BaseFormat
== GL_ALPHA
||
1682 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
1683 img
->_BaseFormat
== GL_RGBA
)
1684 *params
= img
->TexFormat
->AlphaBits
;
1688 case GL_TEXTURE_INTENSITY_SIZE
:
1689 if (img
->_BaseFormat
!= GL_INTENSITY
)
1691 else if (img
->TexFormat
->IntensityBits
> 0)
1692 *params
= img
->TexFormat
->IntensityBits
;
1693 else /* intensity probably stored as rgb texture */
1694 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
1696 case GL_TEXTURE_LUMINANCE_SIZE
:
1697 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
1698 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
1700 else if (img
->TexFormat
->LuminanceBits
> 0)
1701 *params
= img
->TexFormat
->LuminanceBits
;
1702 else /* luminance probably stored as rgb texture */
1703 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
1705 case GL_TEXTURE_INDEX_SIZE_EXT
:
1706 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
1707 *params
= img
->TexFormat
->IndexBits
;
1711 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1712 if (ctx
->Extensions
.SGIX_depth_texture
||
1713 ctx
->Extensions
.ARB_depth_texture
)
1714 *params
= img
->TexFormat
->DepthBits
;
1716 _mesa_error(ctx
, GL_INVALID_ENUM
,
1717 "glGetTexLevelParameter[if]v(pname)");
1719 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1720 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
1721 *params
= img
->TexFormat
->StencilBits
;
1724 _mesa_error(ctx
, GL_INVALID_ENUM
,
1725 "glGetTexLevelParameter[if]v(pname)");
1729 /* GL_ARB_texture_compression */
1730 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1731 if (ctx
->Extensions
.ARB_texture_compression
) {
1732 if (img
->IsCompressed
&& !isProxy
) {
1733 /* Don't use ctx->Driver.CompressedTextureSize() since that
1734 * may returned a padded hardware size.
1736 *params
= _mesa_compressed_texture_size(ctx
, img
->Width
,
1737 img
->Height
, img
->Depth
,
1738 img
->TexFormat
->MesaFormat
);
1741 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1742 "glGetTexLevelParameter[if]v(pname)");
1746 _mesa_error(ctx
, GL_INVALID_ENUM
,
1747 "glGetTexLevelParameter[if]v(pname)");
1750 case GL_TEXTURE_COMPRESSED
:
1751 if (ctx
->Extensions
.ARB_texture_compression
) {
1752 *params
= (GLint
) img
->IsCompressed
;
1755 _mesa_error(ctx
, GL_INVALID_ENUM
,
1756 "glGetTexLevelParameter[if]v(pname)");
1760 /* GL_ARB_texture_float */
1761 case GL_TEXTURE_RED_TYPE_ARB
:
1762 if (ctx
->Extensions
.ARB_texture_float
) {
1763 *params
= img
->TexFormat
->RedBits
? img
->TexFormat
->DataType
: GL_NONE
;
1766 _mesa_error(ctx
, GL_INVALID_ENUM
,
1767 "glGetTexLevelParameter[if]v(pname)");
1770 case GL_TEXTURE_GREEN_TYPE_ARB
:
1771 if (ctx
->Extensions
.ARB_texture_float
) {
1772 *params
= img
->TexFormat
->GreenBits
? img
->TexFormat
->DataType
: GL_NONE
;
1775 _mesa_error(ctx
, GL_INVALID_ENUM
,
1776 "glGetTexLevelParameter[if]v(pname)");
1779 case GL_TEXTURE_BLUE_TYPE_ARB
:
1780 if (ctx
->Extensions
.ARB_texture_float
) {
1781 *params
= img
->TexFormat
->BlueBits
? img
->TexFormat
->DataType
: GL_NONE
;
1784 _mesa_error(ctx
, GL_INVALID_ENUM
,
1785 "glGetTexLevelParameter[if]v(pname)");
1788 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1789 if (ctx
->Extensions
.ARB_texture_float
) {
1790 *params
= img
->TexFormat
->AlphaBits
? img
->TexFormat
->DataType
: GL_NONE
;
1793 _mesa_error(ctx
, GL_INVALID_ENUM
,
1794 "glGetTexLevelParameter[if]v(pname)");
1797 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1798 if (ctx
->Extensions
.ARB_texture_float
) {
1799 *params
= img
->TexFormat
->LuminanceBits
? img
->TexFormat
->DataType
: GL_NONE
;
1802 _mesa_error(ctx
, GL_INVALID_ENUM
,
1803 "glGetTexLevelParameter[if]v(pname)");
1806 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1807 if (ctx
->Extensions
.ARB_texture_float
) {
1808 *params
= img
->TexFormat
->IntensityBits
? img
->TexFormat
->DataType
: GL_NONE
;
1811 _mesa_error(ctx
, GL_INVALID_ENUM
,
1812 "glGetTexLevelParameter[if]v(pname)");
1815 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1816 if (ctx
->Extensions
.ARB_texture_float
) {
1817 *params
= img
->TexFormat
->DepthBits
? img
->TexFormat
->DataType
: GL_NONE
;
1820 _mesa_error(ctx
, GL_INVALID_ENUM
,
1821 "glGetTexLevelParameter[if]v(pname)");
1826 _mesa_error(ctx
, GL_INVALID_ENUM
,
1827 "glGetTexLevelParameter[if]v(pname)");
1831 _mesa_unlock_texture(ctx
, texObj
);
1837 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1839 struct gl_texture_unit
*texUnit
;
1840 struct gl_texture_object
*obj
;
1841 GLboolean error
= GL_FALSE
;
1842 GET_CURRENT_CONTEXT(ctx
);
1843 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1845 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1846 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1847 "glGetTexParameterfv(current unit)");
1851 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1853 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1855 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
1859 _mesa_lock_texture(ctx
, obj
);
1861 case GL_TEXTURE_MAG_FILTER
:
1862 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1864 case GL_TEXTURE_MIN_FILTER
:
1865 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1867 case GL_TEXTURE_WRAP_S
:
1868 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1870 case GL_TEXTURE_WRAP_T
:
1871 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1873 case GL_TEXTURE_WRAP_R
:
1874 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1876 case GL_TEXTURE_BORDER_COLOR
:
1877 params
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1878 params
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1879 params
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1880 params
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1882 case GL_TEXTURE_RESIDENT
:
1885 if (ctx
->Driver
.IsTextureResident
)
1886 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1889 *params
= ENUM_TO_FLOAT(resident
);
1892 case GL_TEXTURE_PRIORITY
:
1893 *params
= obj
->Priority
;
1895 case GL_TEXTURE_MIN_LOD
:
1896 *params
= obj
->MinLod
;
1898 case GL_TEXTURE_MAX_LOD
:
1899 *params
= obj
->MaxLod
;
1901 case GL_TEXTURE_BASE_LEVEL
:
1902 *params
= (GLfloat
) obj
->BaseLevel
;
1904 case GL_TEXTURE_MAX_LEVEL
:
1905 *params
= (GLfloat
) obj
->MaxLevel
;
1907 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1908 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1909 *params
= obj
->MaxAnisotropy
;
1914 case GL_TEXTURE_COMPARE_SGIX
:
1915 if (ctx
->Extensions
.SGIX_shadow
) {
1916 *params
= (GLfloat
) obj
->CompareFlag
;
1921 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1922 if (ctx
->Extensions
.SGIX_shadow
) {
1923 *params
= (GLfloat
) obj
->CompareOperator
;
1928 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1929 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1930 *params
= obj
->ShadowAmbient
;
1935 case GL_GENERATE_MIPMAP_SGIS
:
1936 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1937 *params
= (GLfloat
) obj
->GenerateMipmap
;
1942 case GL_TEXTURE_COMPARE_MODE_ARB
:
1943 if (ctx
->Extensions
.ARB_shadow
) {
1944 *params
= (GLfloat
) obj
->CompareMode
;
1949 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1950 if (ctx
->Extensions
.ARB_shadow
) {
1951 *params
= (GLfloat
) obj
->CompareFunc
;
1956 case GL_DEPTH_TEXTURE_MODE_ARB
:
1957 if (ctx
->Extensions
.ARB_depth_texture
) {
1958 *params
= (GLfloat
) obj
->DepthMode
;
1963 case GL_TEXTURE_LOD_BIAS
:
1964 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1965 *params
= obj
->LodBias
;
1975 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1978 _mesa_unlock_texture(ctx
, obj
);
1983 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1985 struct gl_texture_unit
*texUnit
;
1986 struct gl_texture_object
*obj
;
1987 GET_CURRENT_CONTEXT(ctx
);
1988 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1990 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1991 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1992 "glGetTexParameteriv(current unit)");
1996 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1998 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2000 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
2005 case GL_TEXTURE_MAG_FILTER
:
2006 *params
= (GLint
) obj
->MagFilter
;
2008 case GL_TEXTURE_MIN_FILTER
:
2009 *params
= (GLint
) obj
->MinFilter
;
2011 case GL_TEXTURE_WRAP_S
:
2012 *params
= (GLint
) obj
->WrapS
;
2014 case GL_TEXTURE_WRAP_T
:
2015 *params
= (GLint
) obj
->WrapT
;
2017 case GL_TEXTURE_WRAP_R
:
2018 *params
= (GLint
) obj
->WrapR
;
2020 case GL_TEXTURE_BORDER_COLOR
:
2023 b
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
2024 b
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
2025 b
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
2026 b
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
2027 params
[0] = FLOAT_TO_INT(b
[0]);
2028 params
[1] = FLOAT_TO_INT(b
[1]);
2029 params
[2] = FLOAT_TO_INT(b
[2]);
2030 params
[3] = FLOAT_TO_INT(b
[3]);
2033 case GL_TEXTURE_RESIDENT
:
2036 if (ctx
->Driver
.IsTextureResident
)
2037 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
2040 *params
= (GLint
) resident
;
2043 case GL_TEXTURE_PRIORITY
:
2044 *params
= FLOAT_TO_INT(obj
->Priority
);
2046 case GL_TEXTURE_MIN_LOD
:
2047 *params
= (GLint
) obj
->MinLod
;
2049 case GL_TEXTURE_MAX_LOD
:
2050 *params
= (GLint
) obj
->MaxLod
;
2052 case GL_TEXTURE_BASE_LEVEL
:
2053 *params
= obj
->BaseLevel
;
2055 case GL_TEXTURE_MAX_LEVEL
:
2056 *params
= obj
->MaxLevel
;
2058 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
2059 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
2060 *params
= (GLint
) obj
->MaxAnisotropy
;
2064 case GL_TEXTURE_COMPARE_SGIX
:
2065 if (ctx
->Extensions
.SGIX_shadow
) {
2066 *params
= (GLint
) obj
->CompareFlag
;
2070 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
2071 if (ctx
->Extensions
.SGIX_shadow
) {
2072 *params
= (GLint
) obj
->CompareOperator
;
2076 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
2077 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
2078 *params
= (GLint
) FLOAT_TO_INT(obj
->ShadowAmbient
);
2082 case GL_GENERATE_MIPMAP_SGIS
:
2083 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
2084 *params
= (GLint
) obj
->GenerateMipmap
;
2088 case GL_TEXTURE_COMPARE_MODE_ARB
:
2089 if (ctx
->Extensions
.ARB_shadow
) {
2090 *params
= (GLint
) obj
->CompareMode
;
2094 case GL_TEXTURE_COMPARE_FUNC_ARB
:
2095 if (ctx
->Extensions
.ARB_shadow
) {
2096 *params
= (GLint
) obj
->CompareFunc
;
2100 case GL_DEPTH_TEXTURE_MODE_ARB
:
2101 if (ctx
->Extensions
.ARB_depth_texture
) {
2102 *params
= (GLint
) obj
->DepthMode
;
2106 case GL_TEXTURE_LOD_BIAS
:
2107 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
2108 *params
= (GLint
) obj
->LodBias
;
2113 ; /* silence warnings */
2115 /* If we get here, pname was an unrecognized enum */
2116 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
2122 /**********************************************************************/
2123 /* Texture Coord Generation */
2124 /**********************************************************************/
2128 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
2130 GET_CURRENT_CONTEXT(ctx
);
2131 struct gl_texture_unit
*texUnit
;
2132 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2134 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
2135 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
2136 _mesa_lookup_enum_by_nr(coord
),
2137 _mesa_lookup_enum_by_nr(pname
),
2139 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *params
));
2141 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2142 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexGen(current unit)");
2146 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2150 if (pname
==GL_TEXTURE_GEN_MODE
) {
2151 GLenum mode
= (GLenum
) (GLint
) *params
;
2154 case GL_OBJECT_LINEAR
:
2155 bits
= TEXGEN_OBJ_LINEAR
;
2158 bits
= TEXGEN_EYE_LINEAR
;
2160 case GL_REFLECTION_MAP_NV
:
2161 bits
= TEXGEN_REFLECTION_MAP_NV
;
2163 case GL_NORMAL_MAP_NV
:
2164 bits
= TEXGEN_NORMAL_MAP_NV
;
2167 bits
= TEXGEN_SPHERE_MAP
;
2170 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2173 if (texUnit
->GenModeS
== mode
)
2175 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2176 texUnit
->GenModeS
= mode
;
2177 texUnit
->_GenBitS
= bits
;
2179 else if (pname
==GL_OBJECT_PLANE
) {
2180 if (TEST_EQ_4V(texUnit
->ObjectPlaneS
, params
))
2182 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2183 COPY_4FV(texUnit
->ObjectPlaneS
, params
);
2185 else if (pname
==GL_EYE_PLANE
) {
2187 /* Transform plane equation by the inverse modelview matrix */
2188 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
2189 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2191 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2192 if (TEST_EQ_4V(texUnit
->EyePlaneS
, tmp
))
2194 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2195 COPY_4FV(texUnit
->EyePlaneS
, tmp
);
2198 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2203 if (pname
==GL_TEXTURE_GEN_MODE
) {
2204 GLenum mode
= (GLenum
) (GLint
) *params
;
2207 case GL_OBJECT_LINEAR
:
2208 bitt
= TEXGEN_OBJ_LINEAR
;
2211 bitt
= TEXGEN_EYE_LINEAR
;
2213 case GL_REFLECTION_MAP_NV
:
2214 bitt
= TEXGEN_REFLECTION_MAP_NV
;
2216 case GL_NORMAL_MAP_NV
:
2217 bitt
= TEXGEN_NORMAL_MAP_NV
;
2220 bitt
= TEXGEN_SPHERE_MAP
;
2223 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2226 if (texUnit
->GenModeT
== mode
)
2228 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2229 texUnit
->GenModeT
= mode
;
2230 texUnit
->_GenBitT
= bitt
;
2232 else if (pname
==GL_OBJECT_PLANE
) {
2233 if (TEST_EQ_4V(texUnit
->ObjectPlaneT
, params
))
2235 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2236 COPY_4FV(texUnit
->ObjectPlaneT
, params
);
2238 else if (pname
==GL_EYE_PLANE
) {
2240 /* Transform plane equation by the inverse modelview matrix */
2241 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
2242 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2244 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2245 if (TEST_EQ_4V(texUnit
->EyePlaneT
, tmp
))
2247 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2248 COPY_4FV(texUnit
->EyePlaneT
, tmp
);
2251 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2256 if (pname
==GL_TEXTURE_GEN_MODE
) {
2257 GLenum mode
= (GLenum
) (GLint
) *params
;
2260 case GL_OBJECT_LINEAR
:
2261 bitr
= TEXGEN_OBJ_LINEAR
;
2263 case GL_REFLECTION_MAP_NV
:
2264 bitr
= TEXGEN_REFLECTION_MAP_NV
;
2266 case GL_NORMAL_MAP_NV
:
2267 bitr
= TEXGEN_NORMAL_MAP_NV
;
2270 bitr
= TEXGEN_EYE_LINEAR
;
2273 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2276 if (texUnit
->GenModeR
== mode
)
2278 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2279 texUnit
->GenModeR
= mode
;
2280 texUnit
->_GenBitR
= bitr
;
2282 else if (pname
==GL_OBJECT_PLANE
) {
2283 if (TEST_EQ_4V(texUnit
->ObjectPlaneR
, params
))
2285 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2286 COPY_4FV(texUnit
->ObjectPlaneR
, params
);
2288 else if (pname
==GL_EYE_PLANE
) {
2290 /* Transform plane equation by the inverse modelview matrix */
2291 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
2292 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2294 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2295 if (TEST_EQ_4V(texUnit
->EyePlaneR
, tmp
))
2297 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2298 COPY_4FV(texUnit
->EyePlaneR
, tmp
);
2301 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2306 if (pname
==GL_TEXTURE_GEN_MODE
) {
2307 GLenum mode
= (GLenum
) (GLint
) *params
;
2310 case GL_OBJECT_LINEAR
:
2311 bitq
= TEXGEN_OBJ_LINEAR
;
2314 bitq
= TEXGEN_EYE_LINEAR
;
2317 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2320 if (texUnit
->GenModeQ
== mode
)
2322 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2323 texUnit
->GenModeQ
= mode
;
2324 texUnit
->_GenBitQ
= bitq
;
2326 else if (pname
==GL_OBJECT_PLANE
) {
2327 if (TEST_EQ_4V(texUnit
->ObjectPlaneQ
, params
))
2329 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2330 COPY_4FV(texUnit
->ObjectPlaneQ
, params
);
2332 else if (pname
==GL_EYE_PLANE
) {
2334 /* Transform plane equation by the inverse modelview matrix */
2335 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
2336 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2338 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2339 if (TEST_EQ_4V(texUnit
->EyePlaneQ
, tmp
))
2341 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2342 COPY_4FV(texUnit
->EyePlaneQ
, tmp
);
2345 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2350 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
2354 if (ctx
->Driver
.TexGen
)
2355 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
2360 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
2363 p
[0] = (GLfloat
) params
[0];
2364 if (pname
== GL_TEXTURE_GEN_MODE
) {
2365 p
[1] = p
[2] = p
[3] = 0.0F
;
2368 p
[1] = (GLfloat
) params
[1];
2369 p
[2] = (GLfloat
) params
[2];
2370 p
[3] = (GLfloat
) params
[3];
2372 _mesa_TexGenfv(coord
, pname
, p
);
2377 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
2379 GLfloat p
= (GLfloat
) param
;
2380 _mesa_TexGenfv( coord
, pname
, &p
);
2385 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
2388 p
[0] = (GLfloat
) params
[0];
2389 if (pname
== GL_TEXTURE_GEN_MODE
) {
2390 p
[1] = p
[2] = p
[3] = 0.0F
;
2393 p
[1] = (GLfloat
) params
[1];
2394 p
[2] = (GLfloat
) params
[2];
2395 p
[3] = (GLfloat
) params
[3];
2397 _mesa_TexGenfv( coord
, pname
, p
);
2402 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
2404 _mesa_TexGenfv(coord
, pname
, ¶m
);
2409 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
2411 _mesa_TexGeniv( coord
, pname
, ¶m
);
2417 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
2419 const struct gl_texture_unit
*texUnit
;
2420 GET_CURRENT_CONTEXT(ctx
);
2421 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2423 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2424 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGendv(current unit)");
2428 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2432 if (pname
==GL_TEXTURE_GEN_MODE
) {
2433 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
2435 else if (pname
==GL_OBJECT_PLANE
) {
2436 COPY_4V( params
, texUnit
->ObjectPlaneS
);
2438 else if (pname
==GL_EYE_PLANE
) {
2439 COPY_4V( params
, texUnit
->EyePlaneS
);
2442 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2447 if (pname
==GL_TEXTURE_GEN_MODE
) {
2448 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
2450 else if (pname
==GL_OBJECT_PLANE
) {
2451 COPY_4V( params
, texUnit
->ObjectPlaneT
);
2453 else if (pname
==GL_EYE_PLANE
) {
2454 COPY_4V( params
, texUnit
->EyePlaneT
);
2457 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2462 if (pname
==GL_TEXTURE_GEN_MODE
) {
2463 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
2465 else if (pname
==GL_OBJECT_PLANE
) {
2466 COPY_4V( params
, texUnit
->ObjectPlaneR
);
2468 else if (pname
==GL_EYE_PLANE
) {
2469 COPY_4V( params
, texUnit
->EyePlaneR
);
2472 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2477 if (pname
==GL_TEXTURE_GEN_MODE
) {
2478 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
2480 else if (pname
==GL_OBJECT_PLANE
) {
2481 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
2483 else if (pname
==GL_EYE_PLANE
) {
2484 COPY_4V( params
, texUnit
->EyePlaneQ
);
2487 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2492 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
2500 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
2502 const struct gl_texture_unit
*texUnit
;
2503 GET_CURRENT_CONTEXT(ctx
);
2504 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2506 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2507 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGenfv(current unit)");
2511 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2515 if (pname
==GL_TEXTURE_GEN_MODE
) {
2516 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
2518 else if (pname
==GL_OBJECT_PLANE
) {
2519 COPY_4V( params
, texUnit
->ObjectPlaneS
);
2521 else if (pname
==GL_EYE_PLANE
) {
2522 COPY_4V( params
, texUnit
->EyePlaneS
);
2525 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2530 if (pname
==GL_TEXTURE_GEN_MODE
) {
2531 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
2533 else if (pname
==GL_OBJECT_PLANE
) {
2534 COPY_4V( params
, texUnit
->ObjectPlaneT
);
2536 else if (pname
==GL_EYE_PLANE
) {
2537 COPY_4V( params
, texUnit
->EyePlaneT
);
2540 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2545 if (pname
==GL_TEXTURE_GEN_MODE
) {
2546 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
2548 else if (pname
==GL_OBJECT_PLANE
) {
2549 COPY_4V( params
, texUnit
->ObjectPlaneR
);
2551 else if (pname
==GL_EYE_PLANE
) {
2552 COPY_4V( params
, texUnit
->EyePlaneR
);
2555 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2560 if (pname
==GL_TEXTURE_GEN_MODE
) {
2561 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
2563 else if (pname
==GL_OBJECT_PLANE
) {
2564 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
2566 else if (pname
==GL_EYE_PLANE
) {
2567 COPY_4V( params
, texUnit
->EyePlaneQ
);
2570 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2575 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
2583 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
2585 const struct gl_texture_unit
*texUnit
;
2586 GET_CURRENT_CONTEXT(ctx
);
2587 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2589 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2590 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGeniv(current unit)");
2594 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2598 if (pname
==GL_TEXTURE_GEN_MODE
) {
2599 params
[0] = texUnit
->GenModeS
;
2601 else if (pname
==GL_OBJECT_PLANE
) {
2602 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
2603 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
2604 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
2605 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
2607 else if (pname
==GL_EYE_PLANE
) {
2608 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
2609 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
2610 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
2611 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
2614 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2619 if (pname
==GL_TEXTURE_GEN_MODE
) {
2620 params
[0] = texUnit
->GenModeT
;
2622 else if (pname
==GL_OBJECT_PLANE
) {
2623 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
2624 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
2625 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
2626 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
2628 else if (pname
==GL_EYE_PLANE
) {
2629 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
2630 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
2631 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
2632 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
2635 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2640 if (pname
==GL_TEXTURE_GEN_MODE
) {
2641 params
[0] = texUnit
->GenModeR
;
2643 else if (pname
==GL_OBJECT_PLANE
) {
2644 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
2645 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
2646 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
2647 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
2649 else if (pname
==GL_EYE_PLANE
) {
2650 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
2651 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
2652 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
2653 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
2656 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2661 if (pname
==GL_TEXTURE_GEN_MODE
) {
2662 params
[0] = texUnit
->GenModeQ
;
2664 else if (pname
==GL_OBJECT_PLANE
) {
2665 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
2666 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
2667 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
2668 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
2670 else if (pname
==GL_EYE_PLANE
) {
2671 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
2672 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
2673 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
2674 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
2677 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2682 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
2689 /* GL_ARB_multitexture */
2691 _mesa_ActiveTextureARB(GLenum texture
)
2693 GET_CURRENT_CONTEXT(ctx
);
2694 const GLuint texUnit
= texture
- GL_TEXTURE0
;
2695 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2697 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2698 _mesa_debug(ctx
, "glActiveTexture %s\n",
2699 _mesa_lookup_enum_by_nr(texture
));
2701 /* XXX error-check against max(coordunits, imageunits) */
2702 if (texUnit
>= ctx
->Const
.MaxTextureUnits
) {
2703 _mesa_error(ctx
, GL_INVALID_ENUM
, "glActiveTexture(texture)");
2707 if (ctx
->Texture
.CurrentUnit
== texUnit
)
2710 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2712 ctx
->Texture
.CurrentUnit
= texUnit
;
2713 if (ctx
->Transform
.MatrixMode
== GL_TEXTURE
) {
2714 /* update current stack pointer */
2715 ctx
->CurrentStack
= &ctx
->TextureMatrixStack
[texUnit
];
2718 if (ctx
->Driver
.ActiveTexture
) {
2719 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
2724 /* GL_ARB_multitexture */
2726 _mesa_ClientActiveTextureARB(GLenum texture
)
2728 GET_CURRENT_CONTEXT(ctx
);
2729 GLuint texUnit
= texture
- GL_TEXTURE0
;
2730 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2732 if (texUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2733 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClientActiveTexture(texture)");
2737 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
2738 ctx
->Array
.ActiveTexture
= texUnit
;
2743 /**********************************************************************/
2744 /***** State management *****/
2745 /**********************************************************************/
2749 * \note This routine refers to derived texture attribute values to
2750 * compute the ENABLE_TEXMAT flags, but is only called on
2751 * _NEW_TEXTURE_MATRIX. On changes to _NEW_TEXTURE, the ENABLE_TEXMAT
2752 * flags are updated by _mesa_update_textures(), below.
2754 * \param ctx GL context.
2757 update_texture_matrices( GLcontext
*ctx
)
2761 ctx
->Texture
._TexMatEnabled
= 0;
2763 for (i
=0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
2764 if (_math_matrix_is_dirty(ctx
->TextureMatrixStack
[i
].Top
)) {
2765 _math_matrix_analyse( ctx
->TextureMatrixStack
[i
].Top
);
2767 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
&&
2768 ctx
->TextureMatrixStack
[i
].Top
->type
!= MATRIX_IDENTITY
)
2769 ctx
->Texture
._TexMatEnabled
|= ENABLE_TEXMAT(i
);
2771 if (ctx
->Driver
.TextureMatrix
)
2772 ctx
->Driver
.TextureMatrix( ctx
, i
, ctx
->TextureMatrixStack
[i
].Top
);
2779 * Update texture object's _Function field. We need to do this
2780 * whenever any of the texture object's shadow-related fields change
2781 * or when we start/stop using a fragment program.
2783 * This function could be expanded someday to update additional per-object
2784 * fields that depend on assorted state changes.
2787 update_texture_compare_function(GLcontext
*ctx
,
2788 struct gl_texture_object
*tObj
)
2790 /* XXX temporarily disable this test since it breaks the GLSL
2791 * shadow2D(), etc. functions.
2793 if (0 /*ctx->FragmentProgram._Current*/) {
2794 /* Texel/coordinate comparison is ignored for programs.
2795 * See GL_ARB_fragment_program/shader spec for details.
2797 tObj
->_Function
= GL_NONE
;
2799 else if (tObj
->CompareFlag
) {
2800 /* GL_SGIX_shadow */
2801 if (tObj
->CompareOperator
== GL_TEXTURE_LEQUAL_R_SGIX
) {
2802 tObj
->_Function
= GL_LEQUAL
;
2805 ASSERT(tObj
->CompareOperator
== GL_TEXTURE_GEQUAL_R_SGIX
);
2806 tObj
->_Function
= GL_GEQUAL
;
2809 else if (tObj
->CompareMode
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
2811 tObj
->_Function
= tObj
->CompareFunc
;
2814 tObj
->_Function
= GL_NONE
; /* pass depth through as grayscale */
2820 * Helper function for determining which texture object (1D, 2D, cube, etc)
2821 * should actually be used.
2824 texture_override(GLcontext
*ctx
,
2825 struct gl_texture_unit
*texUnit
, GLbitfield enableBits
,
2826 struct gl_texture_object
*texObj
, GLuint textureBit
)
2828 if (!texUnit
->_ReallyEnabled
&& (enableBits
& textureBit
)) {
2829 if (!texObj
->_Complete
) {
2830 _mesa_test_texobj_completeness(ctx
, texObj
);
2832 if (texObj
->_Complete
) {
2833 texUnit
->_ReallyEnabled
= textureBit
;
2834 texUnit
->_Current
= texObj
;
2835 update_texture_compare_function(ctx
, texObj
);
2842 * \note This routine refers to derived texture matrix values to
2843 * compute the ENABLE_TEXMAT flags, but is only called on
2844 * _NEW_TEXTURE. On changes to _NEW_TEXTURE_MATRIX, the ENABLE_TEXMAT
2845 * flags are updated by _mesa_update_texture_matrices, above.
2847 * \param ctx GL context.
2850 update_texture_state( GLcontext
*ctx
)
2853 struct gl_fragment_program
*fprog
= NULL
;
2854 struct gl_vertex_program
*vprog
= NULL
;
2856 if (ctx
->Shader
.CurrentProgram
&&
2857 ctx
->Shader
.CurrentProgram
->LinkStatus
) {
2858 fprog
= ctx
->Shader
.CurrentProgram
->FragmentProgram
;
2859 vprog
= ctx
->Shader
.CurrentProgram
->VertexProgram
;
2862 if (ctx
->FragmentProgram
._Enabled
) {
2863 fprog
= ctx
->FragmentProgram
.Current
;
2865 if (ctx
->VertexProgram
._Enabled
) {
2866 /* XXX enable this if/when non-shader vertex programs get
2868 vprog = ctx->VertexProgram.Current;
2873 ctx
->NewState
|= _NEW_TEXTURE
; /* TODO: only set this if there are
2877 ctx
->Texture
._EnabledUnits
= 0;
2878 ctx
->Texture
._GenFlags
= 0;
2879 ctx
->Texture
._TexMatEnabled
= 0;
2880 ctx
->Texture
._TexGenEnabled
= 0;
2883 * Update texture unit state.
2885 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
2886 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
2887 GLbitfield enableBits
;
2889 texUnit
->_Current
= NULL
;
2890 texUnit
->_ReallyEnabled
= 0;
2891 texUnit
->_GenFlags
= 0;
2893 /* Get the bitmask of texture enables.
2894 * enableBits will be a mask of the TEXTURE_*_BIT flags indicating
2895 * which texture targets are enabled (fixed function) or referenced
2896 * by a fragment shader/program. When multiple flags are set, we'll
2897 * settle on the one with highest priority (see texture_override below).
2899 if (fprog
|| vprog
) {
2902 enableBits
|= fprog
->Base
.TexturesUsed
[unit
];
2904 enableBits
|= vprog
->Base
.TexturesUsed
[unit
];
2907 if (!texUnit
->Enabled
)
2909 enableBits
= texUnit
->Enabled
;
2912 /* Look for the highest-priority texture target that's enabled and
2913 * complete. That's the one we'll use for texturing. If we're using
2914 * a fragment program we're guaranteed that bitcount(enabledBits) <= 1.
2916 texture_override(ctx
, texUnit
, enableBits
,
2917 texUnit
->Current2DArray
, TEXTURE_2D_ARRAY_BIT
);
2918 texture_override(ctx
, texUnit
, enableBits
,
2919 texUnit
->Current1DArray
, TEXTURE_1D_ARRAY_BIT
);
2920 texture_override(ctx
, texUnit
, enableBits
,
2921 texUnit
->CurrentCubeMap
, TEXTURE_CUBE_BIT
);
2922 texture_override(ctx
, texUnit
, enableBits
,
2923 texUnit
->Current3D
, TEXTURE_3D_BIT
);
2924 texture_override(ctx
, texUnit
, enableBits
,
2925 texUnit
->CurrentRect
, TEXTURE_RECT_BIT
);
2926 texture_override(ctx
, texUnit
, enableBits
,
2927 texUnit
->Current2D
, TEXTURE_2D_BIT
);
2928 texture_override(ctx
, texUnit
, enableBits
,
2929 texUnit
->Current1D
, TEXTURE_1D_BIT
);
2931 if (!texUnit
->_ReallyEnabled
) {
2935 if (texUnit
->_ReallyEnabled
)
2936 ctx
->Texture
._EnabledUnits
|= (1 << unit
);
2938 if (texUnit
->EnvMode
== GL_COMBINE
) {
2939 texUnit
->_CurrentCombine
= & texUnit
->Combine
;
2942 const struct gl_texture_object
*texObj
= texUnit
->_Current
;
2943 GLenum format
= texObj
->Image
[0][texObj
->BaseLevel
]->_BaseFormat
;
2944 if (format
== GL_COLOR_INDEX
) {
2945 format
= GL_RGBA
; /* a bit of a hack */
2947 else if (format
== GL_DEPTH_COMPONENT
2948 || format
== GL_DEPTH_STENCIL_EXT
) {
2949 format
= texObj
->DepthMode
;
2951 calculate_derived_texenv(&texUnit
->_EnvMode
, texUnit
->EnvMode
, format
);
2952 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
2955 switch (texUnit
->_CurrentCombine
->ModeRGB
) {
2957 texUnit
->_CurrentCombine
->_NumArgsRGB
= 1;
2965 case GL_DOT3_RGB_EXT
:
2966 case GL_DOT3_RGBA_EXT
:
2967 texUnit
->_CurrentCombine
->_NumArgsRGB
= 2;
2969 case GL_INTERPOLATE
:
2970 case GL_MODULATE_ADD_ATI
:
2971 case GL_MODULATE_SIGNED_ADD_ATI
:
2972 case GL_MODULATE_SUBTRACT_ATI
:
2973 texUnit
->_CurrentCombine
->_NumArgsRGB
= 3;
2976 texUnit
->_CurrentCombine
->_NumArgsRGB
= 0;
2977 _mesa_problem(ctx
, "invalid RGB combine mode in update_texture_state");
2981 switch (texUnit
->_CurrentCombine
->ModeA
) {
2983 texUnit
->_CurrentCombine
->_NumArgsA
= 1;
2989 texUnit
->_CurrentCombine
->_NumArgsA
= 2;
2991 case GL_INTERPOLATE
:
2992 case GL_MODULATE_ADD_ATI
:
2993 case GL_MODULATE_SIGNED_ADD_ATI
:
2994 case GL_MODULATE_SUBTRACT_ATI
:
2995 texUnit
->_CurrentCombine
->_NumArgsA
= 3;
2998 texUnit
->_CurrentCombine
->_NumArgsA
= 0;
2999 _mesa_problem(ctx
, "invalid Alpha combine mode in update_texture_state");
3003 if (texUnit
->TexGenEnabled
) {
3004 if (texUnit
->TexGenEnabled
& S_BIT
) {
3005 texUnit
->_GenFlags
|= texUnit
->_GenBitS
;
3007 if (texUnit
->TexGenEnabled
& T_BIT
) {
3008 texUnit
->_GenFlags
|= texUnit
->_GenBitT
;
3010 if (texUnit
->TexGenEnabled
& Q_BIT
) {
3011 texUnit
->_GenFlags
|= texUnit
->_GenBitQ
;
3013 if (texUnit
->TexGenEnabled
& R_BIT
) {
3014 texUnit
->_GenFlags
|= texUnit
->_GenBitR
;
3017 ctx
->Texture
._TexGenEnabled
|= ENABLE_TEXGEN(unit
);
3018 ctx
->Texture
._GenFlags
|= texUnit
->_GenFlags
;
3021 if (ctx
->TextureMatrixStack
[unit
].Top
->type
!= MATRIX_IDENTITY
)
3022 ctx
->Texture
._TexMatEnabled
|= ENABLE_TEXMAT(unit
);
3025 /* Determine which texture coordinate sets are actually needed */
3027 const GLuint coordMask
= (1 << MAX_TEXTURE_COORD_UNITS
) - 1;
3028 ctx
->Texture
._EnabledCoordUnits
3029 = (fprog
->Base
.InputsRead
>> FRAG_ATTRIB_TEX0
) & coordMask
;
3032 ctx
->Texture
._EnabledCoordUnits
= ctx
->Texture
._EnabledUnits
;
3038 * Update texture-related derived state.
3041 _mesa_update_texture( GLcontext
*ctx
, GLuint new_state
)
3043 if (new_state
& _NEW_TEXTURE_MATRIX
)
3044 update_texture_matrices( ctx
);
3046 if (new_state
& (_NEW_TEXTURE
| _NEW_PROGRAM
))
3047 update_texture_state( ctx
);
3051 /**********************************************************************/
3052 /***** Initialization *****/
3053 /**********************************************************************/
3056 * Allocate the proxy textures for the given context.
3058 * \param ctx the context to allocate proxies for.
3060 * \return GL_TRUE on success, or GL_FALSE on failure
3062 * If run out of memory part way through the allocations, clean up and return
3066 alloc_proxy_textures( GLcontext
*ctx
)
3068 static const GLenum targets
[] = {
3072 GL_TEXTURE_CUBE_MAP_ARB
,
3073 GL_TEXTURE_RECTANGLE_NV
,
3074 GL_TEXTURE_1D_ARRAY_EXT
,
3075 GL_TEXTURE_2D_ARRAY_EXT
3079 ASSERT(Elements(targets
) == NUM_TEXTURE_TARGETS
);
3081 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
3082 if (!(ctx
->Texture
.ProxyTex
[tgt
]
3083 = ctx
->Driver
.NewTextureObject(ctx
, 0, targets
[tgt
]))) {
3084 /* out of memory, free what we did allocate */
3085 while (--tgt
>= 0) {
3086 ctx
->Driver
.DeleteTexture(ctx
, ctx
->Texture
.ProxyTex
[tgt
]);
3092 assert(ctx
->Texture
.ProxyTex
[0]->RefCount
== 1); /* sanity check */
3098 * Initialize a texture unit.
3100 * \param ctx GL context.
3101 * \param unit texture unit number to be initialized.
3104 init_texture_unit( GLcontext
*ctx
, GLuint unit
)
3106 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
3108 texUnit
->EnvMode
= GL_MODULATE
;
3109 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
3111 texUnit
->Combine
= default_combine_state
;
3112 texUnit
->_EnvMode
= default_combine_state
;
3113 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
3115 texUnit
->TexGenEnabled
= 0;
3116 texUnit
->GenModeS
= GL_EYE_LINEAR
;
3117 texUnit
->GenModeT
= GL_EYE_LINEAR
;
3118 texUnit
->GenModeR
= GL_EYE_LINEAR
;
3119 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
3120 texUnit
->_GenBitS
= TEXGEN_EYE_LINEAR
;
3121 texUnit
->_GenBitT
= TEXGEN_EYE_LINEAR
;
3122 texUnit
->_GenBitR
= TEXGEN_EYE_LINEAR
;
3123 texUnit
->_GenBitQ
= TEXGEN_EYE_LINEAR
;
3125 /* Yes, these plane coefficients are correct! */
3126 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
3127 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
3128 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
3129 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
3130 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
3131 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
3132 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
3133 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
3135 /* initialize current texture object ptrs to the shared default objects */
3136 _mesa_reference_texobj(&texUnit
->Current1D
, ctx
->Shared
->Default1D
);
3137 _mesa_reference_texobj(&texUnit
->Current2D
, ctx
->Shared
->Default2D
);
3138 _mesa_reference_texobj(&texUnit
->Current3D
, ctx
->Shared
->Default3D
);
3139 _mesa_reference_texobj(&texUnit
->CurrentCubeMap
, ctx
->Shared
->DefaultCubeMap
);
3140 _mesa_reference_texobj(&texUnit
->CurrentRect
, ctx
->Shared
->DefaultRect
);
3141 _mesa_reference_texobj(&texUnit
->Current1DArray
, ctx
->Shared
->Default1DArray
);
3142 _mesa_reference_texobj(&texUnit
->Current2DArray
, ctx
->Shared
->Default2DArray
);
3147 * Initialize texture state for the given context.
3150 _mesa_init_texture(GLcontext
*ctx
)
3154 assert(MAX_TEXTURE_LEVELS
>= MAX_3D_TEXTURE_LEVELS
);
3155 assert(MAX_TEXTURE_LEVELS
>= MAX_CUBE_TEXTURE_LEVELS
);
3158 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
3159 ctx
->Texture
._EnabledUnits
= 0;
3160 ctx
->Texture
.SharedPalette
= GL_FALSE
;
3161 _mesa_init_colortable(&ctx
->Texture
.Palette
);
3163 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++)
3164 init_texture_unit( ctx
, i
);
3166 /* After we're done initializing the context's texture state the default
3167 * texture objects' refcounts should be at least MAX_TEXTURE_UNITS + 1.
3169 assert(ctx
->Shared
->Default1D
->RefCount
>= MAX_TEXTURE_UNITS
+ 1);
3171 _mesa_TexEnvProgramCacheInit( ctx
);
3173 /* Allocate proxy textures */
3174 if (!alloc_proxy_textures( ctx
))
3182 * Free dynamically-allocted texture data attached to the given context.
3185 _mesa_free_texture_data(GLcontext
*ctx
)
3189 /* unreference current textures */
3190 for (u
= 0; u
< MAX_TEXTURE_IMAGE_UNITS
; u
++) {
3191 struct gl_texture_unit
*unit
= ctx
->Texture
.Unit
+ u
;
3192 _mesa_reference_texobj(&unit
->Current1D
, NULL
);
3193 _mesa_reference_texobj(&unit
->Current2D
, NULL
);
3194 _mesa_reference_texobj(&unit
->Current3D
, NULL
);
3195 _mesa_reference_texobj(&unit
->CurrentCubeMap
, NULL
);
3196 _mesa_reference_texobj(&unit
->CurrentRect
, NULL
);
3197 _mesa_reference_texobj(&unit
->Current1DArray
, NULL
);
3198 _mesa_reference_texobj(&unit
->Current2DArray
, NULL
);
3201 /* Free proxy texture objects */
3202 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++)
3203 ctx
->Driver
.DeleteTexture(ctx
, ctx
->Texture
.ProxyTex
[tgt
]);
3205 for (u
= 0; u
< MAX_TEXTURE_IMAGE_UNITS
; u
++)
3206 _mesa_free_colortable_data( &ctx
->Texture
.Unit
[u
].ColorTable
);
3208 _mesa_TexEnvProgramCacheDestroy( ctx
);
3213 * Update the default texture objects in the given context to reference those
3214 * specified in the shared state and release those referencing the old
3218 _mesa_update_default_objects_texture(GLcontext
*ctx
)
3222 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
3223 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[i
];
3225 _mesa_reference_texobj(&texUnit
->Current1D
, ctx
->Shared
->Default1D
);
3226 _mesa_reference_texobj(&texUnit
->Current2D
, ctx
->Shared
->Default2D
);
3227 _mesa_reference_texobj(&texUnit
->Current3D
, ctx
->Shared
->Default3D
);
3228 _mesa_reference_texobj(&texUnit
->CurrentCubeMap
, ctx
->Shared
->DefaultCubeMap
);
3229 _mesa_reference_texobj(&texUnit
->CurrentRect
, ctx
->Shared
->DefaultRect
);
3230 _mesa_reference_texobj(&texUnit
->Current1DArray
, ctx
->Shared
->Default1DArray
);
3231 _mesa_reference_texobj(&texUnit
->Current2DArray
, ctx
->Shared
->Default2DArray
);