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
},
67 * Copy a texture binding. Helper used by _mesa_copy_texture_state().
70 copy_texture_binding(const GLcontext
*ctx
,
71 struct gl_texture_object
**dst
,
72 struct gl_texture_object
*src
)
74 /* only copy if names differ (per OpenGL SI) */
75 if ((*dst
)->Name
!= src
->Name
) {
76 /* unbind/delete dest binding which we're changing */
78 if ((*dst
)->RefCount
== 0) {
79 /* time to delete this texture object */
80 ASSERT((*dst
)->Name
!= 0);
81 ASSERT(ctx
->Driver
.DeleteTexture
);
82 /* XXX cast-away const, unfortunately */
83 (*ctx
->Driver
.DeleteTexture
)((GLcontext
*) ctx
, *dst
);
85 /* make new binding, incrementing ref count */
93 * Used by glXCopyContext to copy texture state from one context to another.
96 _mesa_copy_texture_state( const GLcontext
*src
, GLcontext
*dst
)
103 dst
->Texture
.CurrentUnit
= src
->Texture
.CurrentUnit
;
104 dst
->Texture
._GenFlags
= src
->Texture
._GenFlags
;
105 dst
->Texture
._TexGenEnabled
= src
->Texture
._TexGenEnabled
;
106 dst
->Texture
._TexMatEnabled
= src
->Texture
._TexMatEnabled
;
107 dst
->Texture
.SharedPalette
= src
->Texture
.SharedPalette
;
110 for (i
= 0; i
< src
->Const
.MaxTextureUnits
; i
++) {
111 dst
->Texture
.Unit
[i
].Enabled
= src
->Texture
.Unit
[i
].Enabled
;
112 dst
->Texture
.Unit
[i
].EnvMode
= src
->Texture
.Unit
[i
].EnvMode
;
113 COPY_4V(dst
->Texture
.Unit
[i
].EnvColor
, src
->Texture
.Unit
[i
].EnvColor
);
114 dst
->Texture
.Unit
[i
].TexGenEnabled
= src
->Texture
.Unit
[i
].TexGenEnabled
;
115 dst
->Texture
.Unit
[i
].GenModeS
= src
->Texture
.Unit
[i
].GenModeS
;
116 dst
->Texture
.Unit
[i
].GenModeT
= src
->Texture
.Unit
[i
].GenModeT
;
117 dst
->Texture
.Unit
[i
].GenModeR
= src
->Texture
.Unit
[i
].GenModeR
;
118 dst
->Texture
.Unit
[i
].GenModeQ
= src
->Texture
.Unit
[i
].GenModeQ
;
119 dst
->Texture
.Unit
[i
]._GenBitS
= src
->Texture
.Unit
[i
]._GenBitS
;
120 dst
->Texture
.Unit
[i
]._GenBitT
= src
->Texture
.Unit
[i
]._GenBitT
;
121 dst
->Texture
.Unit
[i
]._GenBitR
= src
->Texture
.Unit
[i
]._GenBitR
;
122 dst
->Texture
.Unit
[i
]._GenBitQ
= src
->Texture
.Unit
[i
]._GenBitQ
;
123 dst
->Texture
.Unit
[i
]._GenFlags
= src
->Texture
.Unit
[i
]._GenFlags
;
124 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneS
, src
->Texture
.Unit
[i
].ObjectPlaneS
);
125 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneT
, src
->Texture
.Unit
[i
].ObjectPlaneT
);
126 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneR
, src
->Texture
.Unit
[i
].ObjectPlaneR
);
127 COPY_4V(dst
->Texture
.Unit
[i
].ObjectPlaneQ
, src
->Texture
.Unit
[i
].ObjectPlaneQ
);
128 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneS
, src
->Texture
.Unit
[i
].EyePlaneS
);
129 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneT
, src
->Texture
.Unit
[i
].EyePlaneT
);
130 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneR
, src
->Texture
.Unit
[i
].EyePlaneR
);
131 COPY_4V(dst
->Texture
.Unit
[i
].EyePlaneQ
, src
->Texture
.Unit
[i
].EyePlaneQ
);
132 dst
->Texture
.Unit
[i
].LodBias
= src
->Texture
.Unit
[i
].LodBias
;
134 /* GL_EXT_texture_env_combine */
135 dst
->Texture
.Unit
[i
].Combine
.ModeRGB
= src
->Texture
.Unit
[i
].Combine
.ModeRGB
;
136 dst
->Texture
.Unit
[i
].Combine
.ModeA
= src
->Texture
.Unit
[i
].Combine
.ModeA
;
137 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.SourceRGB
, src
->Texture
.Unit
[i
].Combine
.SourceRGB
);
138 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.SourceA
, src
->Texture
.Unit
[i
].Combine
.SourceA
);
139 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.OperandRGB
, src
->Texture
.Unit
[i
].Combine
.OperandRGB
);
140 COPY_3V(dst
->Texture
.Unit
[i
].Combine
.OperandA
, src
->Texture
.Unit
[i
].Combine
.OperandA
);
141 dst
->Texture
.Unit
[i
].Combine
.ScaleShiftRGB
= src
->Texture
.Unit
[i
].Combine
.ScaleShiftRGB
;
142 dst
->Texture
.Unit
[i
].Combine
.ScaleShiftA
= src
->Texture
.Unit
[i
].Combine
.ScaleShiftA
;
144 /* copy texture object bindings, not contents of texture objects */
145 _mesa_lock_context_textures(dst
);
147 copy_texture_binding(src
, &dst
->Texture
.Unit
[i
].Current1D
,
148 src
->Texture
.Unit
[i
].Current1D
);
149 copy_texture_binding(src
, &dst
->Texture
.Unit
[i
].Current2D
,
150 src
->Texture
.Unit
[i
].Current2D
);
151 copy_texture_binding(src
, &dst
->Texture
.Unit
[i
].Current3D
,
152 src
->Texture
.Unit
[i
].Current3D
);
153 copy_texture_binding(src
, &dst
->Texture
.Unit
[i
].CurrentCubeMap
,
154 src
->Texture
.Unit
[i
].CurrentCubeMap
);
155 copy_texture_binding(src
, &dst
->Texture
.Unit
[i
].CurrentRect
,
156 src
->Texture
.Unit
[i
].CurrentRect
);
157 copy_texture_binding(src
, &dst
->Texture
.Unit
[i
].Current1DArray
,
158 src
->Texture
.Unit
[i
].Current1DArray
);
159 copy_texture_binding(src
, &dst
->Texture
.Unit
[i
].Current2DArray
,
160 src
->Texture
.Unit
[i
].Current2DArray
);
162 _mesa_unlock_context_textures(dst
);
171 _mesa_print_texunit_state( GLcontext
*ctx
, GLuint unit
)
173 const struct gl_texture_unit
*texUnit
= ctx
->Texture
.Unit
+ unit
;
174 _mesa_printf("Texture Unit %d\n", unit
);
175 _mesa_printf(" GL_TEXTURE_ENV_MODE = %s\n", _mesa_lookup_enum_by_nr(texUnit
->EnvMode
));
176 _mesa_printf(" GL_COMBINE_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.ModeRGB
));
177 _mesa_printf(" GL_COMBINE_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.ModeA
));
178 _mesa_printf(" GL_SOURCE0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceRGB
[0]));
179 _mesa_printf(" GL_SOURCE1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceRGB
[1]));
180 _mesa_printf(" GL_SOURCE2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceRGB
[2]));
181 _mesa_printf(" GL_SOURCE0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceA
[0]));
182 _mesa_printf(" GL_SOURCE1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceA
[1]));
183 _mesa_printf(" GL_SOURCE2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.SourceA
[2]));
184 _mesa_printf(" GL_OPERAND0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandRGB
[0]));
185 _mesa_printf(" GL_OPERAND1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandRGB
[1]));
186 _mesa_printf(" GL_OPERAND2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandRGB
[2]));
187 _mesa_printf(" GL_OPERAND0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandA
[0]));
188 _mesa_printf(" GL_OPERAND1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandA
[1]));
189 _mesa_printf(" GL_OPERAND2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit
->Combine
.OperandA
[2]));
190 _mesa_printf(" GL_RGB_SCALE = %d\n", 1 << texUnit
->Combine
.ScaleShiftRGB
);
191 _mesa_printf(" GL_ALPHA_SCALE = %d\n", 1 << texUnit
->Combine
.ScaleShiftA
);
192 _mesa_printf(" GL_TEXTURE_ENV_COLOR = (%f, %f, %f, %f)\n", texUnit
->EnvColor
[0], texUnit
->EnvColor
[1], texUnit
->EnvColor
[2], texUnit
->EnvColor
[3]);
197 /**********************************************************************/
198 /* Texture Environment */
199 /**********************************************************************/
202 * Convert "classic" texture environment to ARB_texture_env_combine style
205 * \param state texture_env_combine state vector to be filled-in.
206 * \param mode Classic texture environment mode (i.e., \c GL_REPLACE,
207 * \c GL_BLEND, \c GL_DECAL, etc.).
208 * \param texBaseFormat Base format of the texture associated with the
212 calculate_derived_texenv( struct gl_tex_env_combine_state
*state
,
213 GLenum mode
, GLenum texBaseFormat
)
218 *state
= default_combine_state
;
220 switch (texBaseFormat
) {
222 state
->SourceRGB
[0] = GL_PREVIOUS
;
225 case GL_LUMINANCE_ALPHA
:
233 state
->SourceA
[0] = GL_PREVIOUS
;
237 _mesa_problem(NULL
, "Invalid texBaseFormat in calculate_derived_texenv");
241 if (mode
== GL_REPLACE_EXT
)
247 mode_rgb
= (texBaseFormat
== GL_ALPHA
) ? GL_REPLACE
: mode
;
252 mode_rgb
= GL_INTERPOLATE
;
255 state
->SourceA
[0] = GL_PREVIOUS
;
257 /* Having alpha / luminance / intensity textures replace using the
258 * incoming fragment color matches the definition in NV_texture_shader.
259 * The 1.5 spec simply marks these as "undefined".
261 switch (texBaseFormat
) {
264 case GL_LUMINANCE_ALPHA
:
266 state
->SourceRGB
[0] = GL_PREVIOUS
;
270 mode_rgb
= GL_REPLACE
;
273 state
->SourceRGB
[2] = GL_TEXTURE
;
279 mode_rgb
= GL_INTERPOLATE
;
280 mode_a
= GL_MODULATE
;
282 switch (texBaseFormat
) {
284 mode_rgb
= GL_REPLACE
;
287 mode_a
= GL_INTERPOLATE
;
288 state
->SourceA
[0] = GL_CONSTANT
;
289 state
->OperandA
[2] = GL_SRC_ALPHA
;
293 case GL_LUMINANCE_ALPHA
:
296 state
->SourceRGB
[2] = GL_TEXTURE
;
297 state
->SourceA
[2] = GL_TEXTURE
;
298 state
->SourceRGB
[0] = GL_CONSTANT
;
299 state
->OperandRGB
[2] = GL_SRC_COLOR
;
305 mode_rgb
= (texBaseFormat
== GL_ALPHA
) ? GL_REPLACE
: GL_ADD
;
306 mode_a
= (texBaseFormat
== GL_INTENSITY
) ? GL_ADD
: GL_MODULATE
;
311 "Invalid texture env mode in calculate_derived_texenv");
315 state
->ModeRGB
= (state
->SourceRGB
[0] != GL_PREVIOUS
)
316 ? mode_rgb
: GL_REPLACE
;
317 state
->ModeA
= (state
->SourceA
[0] != GL_PREVIOUS
)
318 ? mode_a
: GL_REPLACE
;
323 _mesa_TexEnvfv( GLenum target
, GLenum pname
, const GLfloat
*param
)
326 GET_CURRENT_CONTEXT(ctx
);
327 struct gl_texture_unit
*texUnit
;
328 ASSERT_OUTSIDE_BEGIN_END(ctx
);
330 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
331 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
332 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
333 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexEnvfv(current unit)");
337 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
339 #define TE_ERROR(errCode, msg, value) \
340 _mesa_error(ctx, errCode, msg, _mesa_lookup_enum_by_nr(value));
342 if (target
== GL_TEXTURE_ENV
) {
344 case GL_TEXTURE_ENV_MODE
:
346 GLenum mode
= (GLenum
) (GLint
) *param
;
347 if (mode
== GL_REPLACE_EXT
)
349 if (texUnit
->EnvMode
== mode
)
351 if (mode
== GL_MODULATE
||
354 mode
== GL_REPLACE
||
355 (mode
== GL_ADD
&& ctx
->Extensions
.EXT_texture_env_add
) ||
356 (mode
== GL_COMBINE
&&
357 (ctx
->Extensions
.EXT_texture_env_combine
||
358 ctx
->Extensions
.ARB_texture_env_combine
))) {
360 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
361 texUnit
->EnvMode
= mode
;
364 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
369 case GL_TEXTURE_ENV_COLOR
:
372 tmp
[0] = CLAMP( param
[0], 0.0F
, 1.0F
);
373 tmp
[1] = CLAMP( param
[1], 0.0F
, 1.0F
);
374 tmp
[2] = CLAMP( param
[2], 0.0F
, 1.0F
);
375 tmp
[3] = CLAMP( param
[3], 0.0F
, 1.0F
);
376 if (TEST_EQ_4V(tmp
, texUnit
->EnvColor
))
378 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
379 COPY_4FV(texUnit
->EnvColor
, tmp
);
383 if (ctx
->Extensions
.EXT_texture_env_combine
||
384 ctx
->Extensions
.ARB_texture_env_combine
) {
385 const GLenum mode
= (GLenum
) (GLint
) *param
;
386 if (texUnit
->Combine
.ModeRGB
== mode
)
397 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
398 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
402 case GL_DOT3_RGB_EXT
:
403 case GL_DOT3_RGBA_EXT
:
404 if (!ctx
->Extensions
.EXT_texture_env_dot3
) {
405 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
411 if (!ctx
->Extensions
.ARB_texture_env_dot3
) {
412 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
416 case GL_MODULATE_ADD_ATI
:
417 case GL_MODULATE_SIGNED_ADD_ATI
:
418 case GL_MODULATE_SUBTRACT_ATI
:
419 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
420 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
425 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
428 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
429 texUnit
->Combine
.ModeRGB
= mode
;
432 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
436 case GL_COMBINE_ALPHA
:
437 if (ctx
->Extensions
.EXT_texture_env_combine
||
438 ctx
->Extensions
.ARB_texture_env_combine
) {
439 const GLenum mode
= (GLenum
) (GLint
) *param
;
440 if (texUnit
->Combine
.ModeA
== mode
)
451 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
452 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
456 case GL_MODULATE_ADD_ATI
:
457 case GL_MODULATE_SIGNED_ADD_ATI
:
458 case GL_MODULATE_SUBTRACT_ATI
:
459 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
460 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
465 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
468 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
469 texUnit
->Combine
.ModeA
= mode
;
472 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
479 if (ctx
->Extensions
.EXT_texture_env_combine
||
480 ctx
->Extensions
.ARB_texture_env_combine
) {
481 const GLenum source
= (GLenum
) (GLint
) *param
;
482 const GLuint s
= pname
- GL_SOURCE0_RGB
;
483 if (texUnit
->Combine
.SourceRGB
[s
] == source
)
485 if (source
== GL_TEXTURE
||
486 source
== GL_CONSTANT
||
487 source
== GL_PRIMARY_COLOR
||
488 source
== GL_PREVIOUS
||
489 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
490 source
>= GL_TEXTURE0
&&
491 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
492 (ctx
->Extensions
.ATI_texture_env_combine3
&&
493 (source
== GL_ZERO
|| source
== GL_ONE
))) {
495 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
496 texUnit
->Combine
.SourceRGB
[s
] = source
;
499 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
504 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
508 case GL_SOURCE0_ALPHA
:
509 case GL_SOURCE1_ALPHA
:
510 case GL_SOURCE2_ALPHA
:
511 if (ctx
->Extensions
.EXT_texture_env_combine
||
512 ctx
->Extensions
.ARB_texture_env_combine
) {
513 const GLenum source
= (GLenum
) (GLint
) *param
;
514 const GLuint s
= pname
- GL_SOURCE0_ALPHA
;
515 if (texUnit
->Combine
.SourceA
[s
] == source
)
517 if (source
== GL_TEXTURE
||
518 source
== GL_CONSTANT
||
519 source
== GL_PRIMARY_COLOR
||
520 source
== GL_PREVIOUS
||
521 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
522 source
>= GL_TEXTURE0
&&
523 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
524 (ctx
->Extensions
.ATI_texture_env_combine3
&&
525 (source
== GL_ZERO
|| source
== GL_ONE
))) {
527 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
528 texUnit
->Combine
.SourceA
[s
] = source
;
531 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
536 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
540 case GL_OPERAND0_RGB
:
541 case GL_OPERAND1_RGB
:
542 if (ctx
->Extensions
.EXT_texture_env_combine
||
543 ctx
->Extensions
.ARB_texture_env_combine
) {
544 const GLenum operand
= (GLenum
) (GLint
) *param
;
545 const GLuint s
= pname
- GL_OPERAND0_RGB
;
546 if (texUnit
->Combine
.OperandRGB
[s
] == operand
)
550 case GL_ONE_MINUS_SRC_COLOR
:
552 case GL_ONE_MINUS_SRC_ALPHA
:
553 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
554 texUnit
->Combine
.OperandRGB
[s
] = operand
;
557 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
562 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
566 case GL_OPERAND0_ALPHA
:
567 case GL_OPERAND1_ALPHA
:
568 if (ctx
->Extensions
.EXT_texture_env_combine
||
569 ctx
->Extensions
.ARB_texture_env_combine
) {
570 const GLenum operand
= (GLenum
) (GLint
) *param
;
571 if (texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] == operand
)
575 case GL_ONE_MINUS_SRC_ALPHA
:
576 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
577 texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] = operand
;
580 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
585 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
589 case GL_OPERAND2_RGB
:
590 if (ctx
->Extensions
.ARB_texture_env_combine
) {
591 const GLenum operand
= (GLenum
) (GLint
) *param
;
592 if (texUnit
->Combine
.OperandRGB
[2] == operand
)
595 case GL_SRC_COLOR
: /* ARB combine only */
596 case GL_ONE_MINUS_SRC_COLOR
: /* ARB combine only */
598 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
599 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
600 texUnit
->Combine
.OperandRGB
[2] = operand
;
603 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
607 else if (ctx
->Extensions
.EXT_texture_env_combine
) {
608 const GLenum operand
= (GLenum
) (GLint
) *param
;
609 if (texUnit
->Combine
.OperandRGB
[2] == operand
)
611 /* operand must be GL_SRC_ALPHA which is the initial value - thus
612 don't need to actually compare the operand to the possible value */
614 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
619 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
623 case GL_OPERAND2_ALPHA
:
624 if (ctx
->Extensions
.ARB_texture_env_combine
) {
625 const GLenum operand
= (GLenum
) (GLint
) *param
;
626 if (texUnit
->Combine
.OperandA
[2] == operand
)
630 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
631 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
632 texUnit
->Combine
.OperandA
[2] = operand
;
635 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
639 else if (ctx
->Extensions
.EXT_texture_env_combine
) {
640 const GLenum operand
= (GLenum
) (GLint
) *param
;
641 if (texUnit
->Combine
.OperandA
[2] == operand
)
643 /* operand must be GL_SRC_ALPHA which is the initial value - thus
644 don't need to actually compare the operand to the possible value */
646 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
651 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
656 if (ctx
->Extensions
.EXT_texture_env_combine
||
657 ctx
->Extensions
.ARB_texture_env_combine
) {
662 else if (*param
== 2.0) {
665 else if (*param
== 4.0) {
669 _mesa_error( ctx
, GL_INVALID_VALUE
,
670 "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" );
673 if (texUnit
->Combine
.ScaleShiftRGB
== newshift
)
675 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
676 texUnit
->Combine
.ScaleShiftRGB
= newshift
;
679 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
684 if (ctx
->Extensions
.EXT_texture_env_combine
||
685 ctx
->Extensions
.ARB_texture_env_combine
) {
690 else if (*param
== 2.0) {
693 else if (*param
== 4.0) {
697 _mesa_error( ctx
, GL_INVALID_VALUE
,
698 "glTexEnv(GL_ALPHA_SCALE not 1, 2 or 4)" );
701 if (texUnit
->Combine
.ScaleShiftA
== newshift
)
703 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
704 texUnit
->Combine
.ScaleShiftA
= newshift
;
707 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
712 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
716 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
717 /* GL_EXT_texture_lod_bias */
718 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
719 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
722 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
723 if (texUnit
->LodBias
== param
[0])
725 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
726 texUnit
->LodBias
= param
[0];
729 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
733 else if (target
== GL_POINT_SPRITE_NV
) {
734 /* GL_ARB_point_sprite / GL_NV_point_sprite */
735 if (!ctx
->Extensions
.NV_point_sprite
736 && !ctx
->Extensions
.ARB_point_sprite
) {
737 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
740 if (pname
== GL_COORD_REPLACE_NV
) {
741 const GLenum value
= (GLenum
) param
[0];
742 if (value
== GL_TRUE
|| value
== GL_FALSE
) {
743 /* It's kind of weird to set point state via glTexEnv,
744 * but that's what the spec calls for.
746 const GLboolean state
= (GLboolean
) value
;
747 if (ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] == state
)
749 FLUSH_VERTICES(ctx
, _NEW_POINT
);
750 ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] = state
;
753 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param=0x%x)", value
);
758 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname=0x%x)", pname
);
763 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)",target
);
767 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
768 _mesa_debug(ctx
, "glTexEnv %s %s %.1f(%s) ...\n",
769 _mesa_lookup_enum_by_nr(target
),
770 _mesa_lookup_enum_by_nr(pname
),
772 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
774 /* Tell device driver about the new texture environment */
775 if (ctx
->Driver
.TexEnv
) {
776 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
782 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
784 _mesa_TexEnvfv( target
, pname
, ¶m
);
790 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
793 p
[0] = (GLfloat
) param
;
794 p
[1] = p
[2] = p
[3] = 0.0;
795 _mesa_TexEnvfv( target
, pname
, p
);
800 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
803 if (pname
== GL_TEXTURE_ENV_COLOR
) {
804 p
[0] = INT_TO_FLOAT( param
[0] );
805 p
[1] = INT_TO_FLOAT( param
[1] );
806 p
[2] = INT_TO_FLOAT( param
[2] );
807 p
[3] = INT_TO_FLOAT( param
[3] );
810 p
[0] = (GLfloat
) param
[0];
811 p
[1] = p
[2] = p
[3] = 0; /* init to zero, just to be safe */
813 _mesa_TexEnvfv( target
, pname
, p
);
818 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
821 const struct gl_texture_unit
*texUnit
;
822 GET_CURRENT_CONTEXT(ctx
);
823 ASSERT_OUTSIDE_BEGIN_END(ctx
);
825 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
826 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
827 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
828 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnvfv(current unit)");
832 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
834 if (target
== GL_TEXTURE_ENV
) {
836 case GL_TEXTURE_ENV_MODE
:
837 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
839 case GL_TEXTURE_ENV_COLOR
:
840 COPY_4FV( params
, texUnit
->EnvColor
);
843 if (ctx
->Extensions
.EXT_texture_env_combine
||
844 ctx
->Extensions
.ARB_texture_env_combine
) {
845 *params
= (GLfloat
) texUnit
->Combine
.ModeRGB
;
848 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
851 case GL_COMBINE_ALPHA
:
852 if (ctx
->Extensions
.EXT_texture_env_combine
||
853 ctx
->Extensions
.ARB_texture_env_combine
) {
854 *params
= (GLfloat
) texUnit
->Combine
.ModeA
;
857 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
863 if (ctx
->Extensions
.EXT_texture_env_combine
||
864 ctx
->Extensions
.ARB_texture_env_combine
) {
865 const unsigned rgb_idx
= pname
- GL_SOURCE0_RGB
;
866 *params
= (GLfloat
) texUnit
->Combine
.SourceRGB
[rgb_idx
];
869 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
872 case GL_SOURCE0_ALPHA
:
873 case GL_SOURCE1_ALPHA
:
874 case GL_SOURCE2_ALPHA
:
875 if (ctx
->Extensions
.EXT_texture_env_combine
||
876 ctx
->Extensions
.ARB_texture_env_combine
) {
877 const unsigned alpha_idx
= pname
- GL_SOURCE0_ALPHA
;
878 *params
= (GLfloat
) texUnit
->Combine
.SourceA
[alpha_idx
];
881 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
884 case GL_OPERAND0_RGB
:
885 case GL_OPERAND1_RGB
:
886 case GL_OPERAND2_RGB
:
887 if (ctx
->Extensions
.EXT_texture_env_combine
||
888 ctx
->Extensions
.ARB_texture_env_combine
) {
889 const unsigned op_rgb
= pname
- GL_OPERAND0_RGB
;
890 *params
= (GLfloat
) texUnit
->Combine
.OperandRGB
[op_rgb
];
893 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
896 case GL_OPERAND0_ALPHA
:
897 case GL_OPERAND1_ALPHA
:
898 case GL_OPERAND2_ALPHA
:
899 if (ctx
->Extensions
.EXT_texture_env_combine
||
900 ctx
->Extensions
.ARB_texture_env_combine
) {
901 const unsigned op_alpha
= pname
- GL_OPERAND0_ALPHA
;
902 *params
= (GLfloat
) texUnit
->Combine
.OperandA
[op_alpha
];
905 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
909 if (ctx
->Extensions
.EXT_texture_env_combine
||
910 ctx
->Extensions
.ARB_texture_env_combine
) {
911 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
913 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
919 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
924 if (ctx
->Extensions
.EXT_texture_env_combine
||
925 ctx
->Extensions
.ARB_texture_env_combine
) {
926 if (texUnit
->Combine
.ScaleShiftA
== 0)
928 else if (texUnit
->Combine
.ScaleShiftA
== 1)
934 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
939 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname=0x%x)", pname
);
942 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
943 /* GL_EXT_texture_lod_bias */
944 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
945 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
948 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
949 *params
= texUnit
->LodBias
;
952 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
956 else if (target
== GL_POINT_SPRITE_NV
) {
957 /* GL_ARB_point_sprite / GL_NV_point_sprite */
958 if (!ctx
->Extensions
.NV_point_sprite
959 && !ctx
->Extensions
.ARB_point_sprite
) {
960 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
963 if (pname
== GL_COORD_REPLACE_NV
) {
964 *params
= (GLfloat
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
967 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
972 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
979 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
982 const struct gl_texture_unit
*texUnit
;
983 GET_CURRENT_CONTEXT(ctx
);
984 ASSERT_OUTSIDE_BEGIN_END(ctx
);
986 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
987 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
988 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
989 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnviv(current unit)");
993 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
995 if (target
== GL_TEXTURE_ENV
) {
997 case GL_TEXTURE_ENV_MODE
:
998 *params
= (GLint
) texUnit
->EnvMode
;
1000 case GL_TEXTURE_ENV_COLOR
:
1001 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
1002 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
1003 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
1004 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
1006 case GL_COMBINE_RGB
:
1007 if (ctx
->Extensions
.EXT_texture_env_combine
||
1008 ctx
->Extensions
.ARB_texture_env_combine
) {
1009 *params
= (GLint
) texUnit
->Combine
.ModeRGB
;
1012 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1015 case GL_COMBINE_ALPHA
:
1016 if (ctx
->Extensions
.EXT_texture_env_combine
||
1017 ctx
->Extensions
.ARB_texture_env_combine
) {
1018 *params
= (GLint
) texUnit
->Combine
.ModeA
;
1021 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1024 case GL_SOURCE0_RGB
:
1025 case GL_SOURCE1_RGB
:
1026 case GL_SOURCE2_RGB
:
1027 if (ctx
->Extensions
.EXT_texture_env_combine
||
1028 ctx
->Extensions
.ARB_texture_env_combine
) {
1029 const unsigned rgb_idx
= pname
- GL_SOURCE0_RGB
;
1030 *params
= (GLint
) texUnit
->Combine
.SourceRGB
[rgb_idx
];
1033 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1036 case GL_SOURCE0_ALPHA
:
1037 case GL_SOURCE1_ALPHA
:
1038 case GL_SOURCE2_ALPHA
:
1039 if (ctx
->Extensions
.EXT_texture_env_combine
||
1040 ctx
->Extensions
.ARB_texture_env_combine
) {
1041 const unsigned alpha_idx
= pname
- GL_SOURCE0_ALPHA
;
1042 *params
= (GLint
) texUnit
->Combine
.SourceA
[alpha_idx
];
1045 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1048 case GL_OPERAND0_RGB
:
1049 case GL_OPERAND1_RGB
:
1050 case GL_OPERAND2_RGB
:
1051 if (ctx
->Extensions
.EXT_texture_env_combine
||
1052 ctx
->Extensions
.ARB_texture_env_combine
) {
1053 const unsigned op_rgb
= pname
- GL_OPERAND0_RGB
;
1054 *params
= (GLint
) texUnit
->Combine
.OperandRGB
[op_rgb
];
1057 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1060 case GL_OPERAND0_ALPHA
:
1061 case GL_OPERAND1_ALPHA
:
1062 case GL_OPERAND2_ALPHA
:
1063 if (ctx
->Extensions
.EXT_texture_env_combine
||
1064 ctx
->Extensions
.ARB_texture_env_combine
) {
1065 const unsigned op_alpha
= pname
- GL_OPERAND0_ALPHA
;
1066 *params
= (GLint
) texUnit
->Combine
.OperandA
[op_alpha
];
1069 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1073 if (ctx
->Extensions
.EXT_texture_env_combine
||
1074 ctx
->Extensions
.ARB_texture_env_combine
) {
1075 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
1077 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
1083 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1087 case GL_ALPHA_SCALE
:
1088 if (ctx
->Extensions
.EXT_texture_env_combine
||
1089 ctx
->Extensions
.ARB_texture_env_combine
) {
1090 if (texUnit
->Combine
.ScaleShiftA
== 0)
1092 else if (texUnit
->Combine
.ScaleShiftA
== 1)
1098 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1103 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname=0x%x)",
1107 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
1108 /* GL_EXT_texture_lod_bias */
1109 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
1110 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1113 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
1114 *params
= (GLint
) texUnit
->LodBias
;
1117 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
1121 else if (target
== GL_POINT_SPRITE_NV
) {
1122 /* GL_ARB_point_sprite / GL_NV_point_sprite */
1123 if (!ctx
->Extensions
.NV_point_sprite
1124 && !ctx
->Extensions
.ARB_point_sprite
) {
1125 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1128 if (pname
== GL_COORD_REPLACE_NV
) {
1129 *params
= (GLint
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
1132 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
1137 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1145 /**********************************************************************/
1146 /* Texture Parameters */
1147 /**********************************************************************/
1150 * Check if a coordinate wrap mode is supported for the texture target.
1151 * \return GL_TRUE if legal, GL_FALSE otherwise
1154 validate_texture_wrap_mode(GLcontext
* ctx
, GLenum target
, GLenum wrap
)
1156 const struct gl_extensions
* const e
= & ctx
->Extensions
;
1158 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
1159 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
1160 /* any texture target */
1163 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
1164 (wrap
== GL_REPEAT
||
1165 (wrap
== GL_MIRRORED_REPEAT
&&
1166 e
->ARB_texture_mirrored_repeat
) ||
1167 (wrap
== GL_MIRROR_CLAMP_EXT
&&
1168 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
1169 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
1170 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
1171 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
1172 (e
->EXT_texture_mirror_clamp
)))) {
1173 /* non-rectangle texture */
1177 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1183 _mesa_TexParameterf( GLenum target
, GLenum pname
, GLfloat param
)
1185 _mesa_TexParameterfv(target
, pname
, ¶m
);
1190 _mesa_TexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
1192 const GLenum eparam
= (GLenum
) (GLint
) params
[0];
1193 struct gl_texture_unit
*texUnit
;
1194 struct gl_texture_object
*texObj
;
1195 GET_CURRENT_CONTEXT(ctx
);
1196 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1198 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
1199 _mesa_debug(ctx
, "glTexParameter %s %s %.1f(%s)...\n",
1200 _mesa_lookup_enum_by_nr(target
),
1201 _mesa_lookup_enum_by_nr(pname
),
1203 _mesa_lookup_enum_by_nr(eparam
));
1205 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1206 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameterfv(current unit)");
1210 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1214 texObj
= texUnit
->Current1D
;
1217 texObj
= texUnit
->Current2D
;
1220 texObj
= texUnit
->Current3D
;
1222 case GL_TEXTURE_CUBE_MAP
:
1223 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1224 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1227 texObj
= texUnit
->CurrentCubeMap
;
1229 case GL_TEXTURE_RECTANGLE_NV
:
1230 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1231 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1234 texObj
= texUnit
->CurrentRect
;
1236 case GL_TEXTURE_1D_ARRAY_EXT
:
1237 if (!ctx
->Extensions
.MESA_texture_array
) {
1238 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1241 texObj
= texUnit
->Current1DArray
;
1243 case GL_TEXTURE_2D_ARRAY_EXT
:
1244 if (!ctx
->Extensions
.MESA_texture_array
) {
1245 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1248 texObj
= texUnit
->Current2DArray
;
1251 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1256 case GL_TEXTURE_MIN_FILTER
:
1257 /* A small optimization */
1258 if (texObj
->MinFilter
== eparam
)
1260 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
1261 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1262 texObj
->MinFilter
= eparam
;
1264 else if ((eparam
==GL_NEAREST_MIPMAP_NEAREST
||
1265 eparam
==GL_LINEAR_MIPMAP_NEAREST
||
1266 eparam
==GL_NEAREST_MIPMAP_LINEAR
||
1267 eparam
==GL_LINEAR_MIPMAP_LINEAR
) &&
1268 texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
1269 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1270 texObj
->MinFilter
= eparam
;
1273 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1277 case GL_TEXTURE_MAG_FILTER
:
1278 /* A small optimization */
1279 if (texObj
->MagFilter
== eparam
)
1282 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
1283 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1284 texObj
->MagFilter
= eparam
;
1287 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1291 case GL_TEXTURE_WRAP_S
:
1292 if (texObj
->WrapS
== eparam
)
1294 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1295 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1296 texObj
->WrapS
= eparam
;
1302 case GL_TEXTURE_WRAP_T
:
1303 if (texObj
->WrapT
== eparam
)
1305 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1306 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1307 texObj
->WrapT
= eparam
;
1313 case GL_TEXTURE_WRAP_R
:
1314 if (texObj
->WrapR
== eparam
)
1316 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1317 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1318 texObj
->WrapR
= eparam
;
1324 case GL_TEXTURE_BORDER_COLOR
:
1325 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1326 texObj
->BorderColor
[RCOMP
] = params
[0];
1327 texObj
->BorderColor
[GCOMP
] = params
[1];
1328 texObj
->BorderColor
[BCOMP
] = params
[2];
1329 texObj
->BorderColor
[ACOMP
] = params
[3];
1330 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[RCOMP
], params
[0]);
1331 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[GCOMP
], params
[1]);
1332 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[BCOMP
], params
[2]);
1333 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[ACOMP
], params
[3]);
1335 case GL_TEXTURE_MIN_LOD
:
1336 if (texObj
->MinLod
== params
[0])
1338 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1339 texObj
->MinLod
= params
[0];
1341 case GL_TEXTURE_MAX_LOD
:
1342 if (texObj
->MaxLod
== params
[0])
1344 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1345 texObj
->MaxLod
= params
[0];
1347 case GL_TEXTURE_BASE_LEVEL
:
1348 if (params
[0] < 0.0) {
1349 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
1352 if (target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0.0) {
1353 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
1356 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1357 texObj
->BaseLevel
= (GLint
) params
[0];
1359 case GL_TEXTURE_MAX_LEVEL
:
1360 if (params
[0] < 0.0) {
1361 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
1364 if (target
== GL_TEXTURE_RECTANGLE_ARB
) {
1365 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(param)");
1368 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1369 texObj
->MaxLevel
= (GLint
) params
[0];
1371 case GL_TEXTURE_PRIORITY
:
1372 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1373 texObj
->Priority
= CLAMP( params
[0], 0.0F
, 1.0F
);
1375 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1376 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1377 if (params
[0] < 1.0) {
1378 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1381 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1382 /* clamp to max, that's what NVIDIA does */
1383 texObj
->MaxAnisotropy
= MIN2(params
[0],
1384 ctx
->Const
.MaxTextureMaxAnisotropy
);
1387 _mesa_error(ctx
, GL_INVALID_ENUM
,
1388 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
1392 case GL_TEXTURE_COMPARE_SGIX
:
1393 if (ctx
->Extensions
.SGIX_shadow
) {
1394 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1395 texObj
->CompareFlag
= params
[0] ? GL_TRUE
: GL_FALSE
;
1398 _mesa_error(ctx
, GL_INVALID_ENUM
,
1399 "glTexParameter(pname=GL_TEXTURE_COMPARE_SGIX)");
1403 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1404 if (ctx
->Extensions
.SGIX_shadow
) {
1405 GLenum op
= (GLenum
) params
[0];
1406 if (op
== GL_TEXTURE_LEQUAL_R_SGIX
||
1407 op
== GL_TEXTURE_GEQUAL_R_SGIX
) {
1408 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1409 texObj
->CompareOperator
= op
;
1412 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param)");
1416 _mesa_error(ctx
, GL_INVALID_ENUM
,
1417 "glTexParameter(pname=GL_TEXTURE_COMPARE_OPERATOR_SGIX)");
1421 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1422 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1423 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1424 texObj
->ShadowAmbient
= CLAMP(params
[0], 0.0F
, 1.0F
);
1427 _mesa_error(ctx
, GL_INVALID_ENUM
,
1428 "glTexParameter(pname=GL_SHADOW_AMBIENT_SGIX)");
1432 case GL_GENERATE_MIPMAP_SGIS
:
1433 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1434 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
1437 _mesa_error(ctx
, GL_INVALID_ENUM
,
1438 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
1442 case GL_TEXTURE_COMPARE_MODE_ARB
:
1443 if (ctx
->Extensions
.ARB_shadow
) {
1444 const GLenum mode
= (GLenum
) params
[0];
1445 if (mode
== GL_NONE
|| mode
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
1446 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1447 texObj
->CompareMode
= mode
;
1450 _mesa_error(ctx
, GL_INVALID_ENUM
,
1451 "glTexParameter(bad GL_TEXTURE_COMPARE_MODE_ARB: 0x%x)", mode
);
1456 _mesa_error(ctx
, GL_INVALID_ENUM
,
1457 "glTexParameter(pname=GL_TEXTURE_COMPARE_MODE_ARB)");
1461 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1462 if (ctx
->Extensions
.ARB_shadow
) {
1463 const GLenum func
= (GLenum
) params
[0];
1464 if (func
== GL_LEQUAL
|| func
== GL_GEQUAL
) {
1465 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1466 texObj
->CompareFunc
= func
;
1468 else if (ctx
->Extensions
.EXT_shadow_funcs
&&
1469 (func
== GL_EQUAL
||
1470 func
== GL_NOTEQUAL
||
1472 func
== GL_GREATER
||
1473 func
== GL_ALWAYS
||
1474 func
== GL_NEVER
)) {
1475 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1476 texObj
->CompareFunc
= func
;
1479 _mesa_error(ctx
, GL_INVALID_ENUM
,
1480 "glTexParameter(bad GL_TEXTURE_COMPARE_FUNC_ARB)");
1485 _mesa_error(ctx
, GL_INVALID_ENUM
,
1486 "glTexParameter(pname=GL_TEXTURE_COMPARE_FUNC_ARB)");
1490 case GL_DEPTH_TEXTURE_MODE_ARB
:
1491 if (ctx
->Extensions
.ARB_depth_texture
) {
1492 const GLenum result
= (GLenum
) params
[0];
1493 if (result
== GL_LUMINANCE
|| result
== GL_INTENSITY
1494 || result
== GL_ALPHA
) {
1495 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1496 texObj
->DepthMode
= result
;
1499 _mesa_error(ctx
, GL_INVALID_ENUM
,
1500 "glTexParameter(bad GL_DEPTH_TEXTURE_MODE_ARB)");
1505 _mesa_error(ctx
, GL_INVALID_ENUM
,
1506 "glTexParameter(pname=GL_DEPTH_TEXTURE_MODE_ARB)");
1510 case GL_TEXTURE_LOD_BIAS
:
1511 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias*/
1512 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1513 if (texObj
->LodBias
!= params
[0]) {
1514 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1515 texObj
->LodBias
= params
[0];
1521 _mesa_error(ctx
, GL_INVALID_ENUM
,
1522 "glTexParameter(pname=0x%x)", pname
);
1526 texObj
->_Complete
= GL_FALSE
;
1528 if (ctx
->Driver
.TexParameter
) {
1529 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
1535 _mesa_TexParameteri( GLenum target
, GLenum pname
, GLint param
)
1538 if (pname
== GL_TEXTURE_PRIORITY
)
1539 fparam
[0] = INT_TO_FLOAT(param
);
1541 fparam
[0] = (GLfloat
) param
;
1542 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
1543 _mesa_TexParameterfv(target
, pname
, fparam
);
1548 _mesa_TexParameteriv( GLenum target
, GLenum pname
, const GLint
*params
)
1551 if (pname
== GL_TEXTURE_BORDER_COLOR
) {
1552 fparam
[0] = INT_TO_FLOAT(params
[0]);
1553 fparam
[1] = INT_TO_FLOAT(params
[1]);
1554 fparam
[2] = INT_TO_FLOAT(params
[2]);
1555 fparam
[3] = INT_TO_FLOAT(params
[3]);
1558 if (pname
== GL_TEXTURE_PRIORITY
)
1559 fparam
[0] = INT_TO_FLOAT(params
[0]);
1561 fparam
[0] = (GLfloat
) params
[0];
1562 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
1564 _mesa_TexParameterfv(target
, pname
, fparam
);
1569 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1570 GLenum pname
, GLfloat
*params
)
1573 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1574 *params
= (GLfloat
) iparam
;
1579 tex_image_dimensions(GLcontext
*ctx
, GLenum target
)
1583 case GL_PROXY_TEXTURE_1D
:
1586 case GL_PROXY_TEXTURE_2D
:
1589 case GL_PROXY_TEXTURE_3D
:
1591 case GL_TEXTURE_CUBE_MAP
:
1592 case GL_PROXY_TEXTURE_CUBE_MAP
:
1593 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1594 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1595 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1596 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1597 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1598 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1599 return ctx
->Extensions
.ARB_texture_cube_map
? 2 : 0;
1600 case GL_TEXTURE_RECTANGLE_NV
:
1601 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1602 return ctx
->Extensions
.NV_texture_rectangle
? 2 : 0;
1603 case GL_TEXTURE_1D_ARRAY_EXT
:
1604 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1605 return ctx
->Extensions
.MESA_texture_array
? 2 : 0;
1606 case GL_TEXTURE_2D_ARRAY_EXT
:
1607 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1608 return ctx
->Extensions
.MESA_texture_array
? 3 : 0;
1610 _mesa_problem(ctx
, "bad target in _mesa_tex_target_dimensions()");
1617 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1618 GLenum pname
, GLint
*params
)
1620 const struct gl_texture_unit
*texUnit
;
1621 struct gl_texture_object
*texObj
;
1622 const struct gl_texture_image
*img
= NULL
;
1626 GET_CURRENT_CONTEXT(ctx
);
1627 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1629 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1630 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1631 "glGetTexLevelParameteriv(current unit)");
1635 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1637 /* this will catch bad target values */
1638 dimensions
= tex_image_dimensions(ctx
, target
); /* 1, 2 or 3 */
1639 if (dimensions
== 0) {
1640 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
1644 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1645 if (maxLevels
== 0) {
1646 /* should not happen since <target> was just checked above */
1647 _mesa_problem(ctx
, "maxLevels=0 in _mesa_GetTexLevelParameter");
1651 if (level
< 0 || level
>= maxLevels
) {
1652 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1656 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1657 _mesa_lock_texture(ctx
, texObj
);
1659 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1660 if (!img
|| !img
->TexFormat
) {
1661 /* undefined texture image */
1662 if (pname
== GL_TEXTURE_COMPONENTS
)
1669 isProxy
= _mesa_is_proxy_texture(target
);
1672 case GL_TEXTURE_WIDTH
:
1673 *params
= img
->Width
;
1675 case GL_TEXTURE_HEIGHT
:
1676 *params
= img
->Height
;
1678 case GL_TEXTURE_DEPTH
:
1679 *params
= img
->Depth
;
1681 case GL_TEXTURE_INTERNAL_FORMAT
:
1682 *params
= img
->InternalFormat
;
1684 case GL_TEXTURE_BORDER
:
1685 *params
= img
->Border
;
1687 case GL_TEXTURE_RED_SIZE
:
1688 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
1689 *params
= img
->TexFormat
->RedBits
;
1693 case GL_TEXTURE_GREEN_SIZE
:
1694 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
1695 *params
= img
->TexFormat
->GreenBits
;
1699 case GL_TEXTURE_BLUE_SIZE
:
1700 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
1701 *params
= img
->TexFormat
->BlueBits
;
1705 case GL_TEXTURE_ALPHA_SIZE
:
1706 if (img
->_BaseFormat
== GL_ALPHA
||
1707 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
1708 img
->_BaseFormat
== GL_RGBA
)
1709 *params
= img
->TexFormat
->AlphaBits
;
1713 case GL_TEXTURE_INTENSITY_SIZE
:
1714 if (img
->_BaseFormat
!= GL_INTENSITY
)
1716 else if (img
->TexFormat
->IntensityBits
> 0)
1717 *params
= img
->TexFormat
->IntensityBits
;
1718 else /* intensity probably stored as rgb texture */
1719 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
1721 case GL_TEXTURE_LUMINANCE_SIZE
:
1722 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
1723 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
1725 else if (img
->TexFormat
->LuminanceBits
> 0)
1726 *params
= img
->TexFormat
->LuminanceBits
;
1727 else /* luminance probably stored as rgb texture */
1728 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
1730 case GL_TEXTURE_INDEX_SIZE_EXT
:
1731 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
1732 *params
= img
->TexFormat
->IndexBits
;
1736 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1737 if (ctx
->Extensions
.SGIX_depth_texture
||
1738 ctx
->Extensions
.ARB_depth_texture
)
1739 *params
= img
->TexFormat
->DepthBits
;
1741 _mesa_error(ctx
, GL_INVALID_ENUM
,
1742 "glGetTexLevelParameter[if]v(pname)");
1744 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1745 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
1746 *params
= img
->TexFormat
->StencilBits
;
1749 _mesa_error(ctx
, GL_INVALID_ENUM
,
1750 "glGetTexLevelParameter[if]v(pname)");
1754 /* GL_ARB_texture_compression */
1755 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1756 if (ctx
->Extensions
.ARB_texture_compression
) {
1757 if (img
->IsCompressed
&& !isProxy
) {
1758 /* Don't use ctx->Driver.CompressedTextureSize() since that
1759 * may returned a padded hardware size.
1761 *params
= _mesa_compressed_texture_size(ctx
, img
->Width
,
1762 img
->Height
, img
->Depth
,
1763 img
->TexFormat
->MesaFormat
);
1766 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1767 "glGetTexLevelParameter[if]v(pname)");
1771 _mesa_error(ctx
, GL_INVALID_ENUM
,
1772 "glGetTexLevelParameter[if]v(pname)");
1775 case GL_TEXTURE_COMPRESSED
:
1776 if (ctx
->Extensions
.ARB_texture_compression
) {
1777 *params
= (GLint
) img
->IsCompressed
;
1780 _mesa_error(ctx
, GL_INVALID_ENUM
,
1781 "glGetTexLevelParameter[if]v(pname)");
1785 /* GL_ARB_texture_float */
1786 case GL_TEXTURE_RED_TYPE_ARB
:
1787 if (ctx
->Extensions
.ARB_texture_float
) {
1788 *params
= img
->TexFormat
->RedBits
? img
->TexFormat
->DataType
: GL_NONE
;
1791 _mesa_error(ctx
, GL_INVALID_ENUM
,
1792 "glGetTexLevelParameter[if]v(pname)");
1795 case GL_TEXTURE_GREEN_TYPE_ARB
:
1796 if (ctx
->Extensions
.ARB_texture_float
) {
1797 *params
= img
->TexFormat
->GreenBits
? img
->TexFormat
->DataType
: GL_NONE
;
1800 _mesa_error(ctx
, GL_INVALID_ENUM
,
1801 "glGetTexLevelParameter[if]v(pname)");
1804 case GL_TEXTURE_BLUE_TYPE_ARB
:
1805 if (ctx
->Extensions
.ARB_texture_float
) {
1806 *params
= img
->TexFormat
->BlueBits
? img
->TexFormat
->DataType
: GL_NONE
;
1809 _mesa_error(ctx
, GL_INVALID_ENUM
,
1810 "glGetTexLevelParameter[if]v(pname)");
1813 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1814 if (ctx
->Extensions
.ARB_texture_float
) {
1815 *params
= img
->TexFormat
->AlphaBits
? img
->TexFormat
->DataType
: GL_NONE
;
1818 _mesa_error(ctx
, GL_INVALID_ENUM
,
1819 "glGetTexLevelParameter[if]v(pname)");
1822 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1823 if (ctx
->Extensions
.ARB_texture_float
) {
1824 *params
= img
->TexFormat
->LuminanceBits
? img
->TexFormat
->DataType
: GL_NONE
;
1827 _mesa_error(ctx
, GL_INVALID_ENUM
,
1828 "glGetTexLevelParameter[if]v(pname)");
1831 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1832 if (ctx
->Extensions
.ARB_texture_float
) {
1833 *params
= img
->TexFormat
->IntensityBits
? img
->TexFormat
->DataType
: GL_NONE
;
1836 _mesa_error(ctx
, GL_INVALID_ENUM
,
1837 "glGetTexLevelParameter[if]v(pname)");
1840 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1841 if (ctx
->Extensions
.ARB_texture_float
) {
1842 *params
= img
->TexFormat
->DepthBits
? img
->TexFormat
->DataType
: GL_NONE
;
1845 _mesa_error(ctx
, GL_INVALID_ENUM
,
1846 "glGetTexLevelParameter[if]v(pname)");
1851 _mesa_error(ctx
, GL_INVALID_ENUM
,
1852 "glGetTexLevelParameter[if]v(pname)");
1856 _mesa_unlock_texture(ctx
, texObj
);
1862 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1864 struct gl_texture_unit
*texUnit
;
1865 struct gl_texture_object
*obj
;
1866 GLboolean error
= GL_FALSE
;
1867 GET_CURRENT_CONTEXT(ctx
);
1868 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1870 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1871 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1872 "glGetTexParameterfv(current unit)");
1876 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1878 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1880 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
1884 _mesa_lock_texture(ctx
, obj
);
1886 case GL_TEXTURE_MAG_FILTER
:
1887 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1889 case GL_TEXTURE_MIN_FILTER
:
1890 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1892 case GL_TEXTURE_WRAP_S
:
1893 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1895 case GL_TEXTURE_WRAP_T
:
1896 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1898 case GL_TEXTURE_WRAP_R
:
1899 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1901 case GL_TEXTURE_BORDER_COLOR
:
1902 params
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1903 params
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1904 params
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1905 params
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1907 case GL_TEXTURE_RESIDENT
:
1910 if (ctx
->Driver
.IsTextureResident
)
1911 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1914 *params
= ENUM_TO_FLOAT(resident
);
1917 case GL_TEXTURE_PRIORITY
:
1918 *params
= obj
->Priority
;
1920 case GL_TEXTURE_MIN_LOD
:
1921 *params
= obj
->MinLod
;
1923 case GL_TEXTURE_MAX_LOD
:
1924 *params
= obj
->MaxLod
;
1926 case GL_TEXTURE_BASE_LEVEL
:
1927 *params
= (GLfloat
) obj
->BaseLevel
;
1929 case GL_TEXTURE_MAX_LEVEL
:
1930 *params
= (GLfloat
) obj
->MaxLevel
;
1932 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1933 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1934 *params
= obj
->MaxAnisotropy
;
1939 case GL_TEXTURE_COMPARE_SGIX
:
1940 if (ctx
->Extensions
.SGIX_shadow
) {
1941 *params
= (GLfloat
) obj
->CompareFlag
;
1946 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1947 if (ctx
->Extensions
.SGIX_shadow
) {
1948 *params
= (GLfloat
) obj
->CompareOperator
;
1953 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1954 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1955 *params
= obj
->ShadowAmbient
;
1960 case GL_GENERATE_MIPMAP_SGIS
:
1961 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1962 *params
= (GLfloat
) obj
->GenerateMipmap
;
1967 case GL_TEXTURE_COMPARE_MODE_ARB
:
1968 if (ctx
->Extensions
.ARB_shadow
) {
1969 *params
= (GLfloat
) obj
->CompareMode
;
1974 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1975 if (ctx
->Extensions
.ARB_shadow
) {
1976 *params
= (GLfloat
) obj
->CompareFunc
;
1981 case GL_DEPTH_TEXTURE_MODE_ARB
:
1982 if (ctx
->Extensions
.ARB_depth_texture
) {
1983 *params
= (GLfloat
) obj
->DepthMode
;
1988 case GL_TEXTURE_LOD_BIAS
:
1989 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1990 *params
= obj
->LodBias
;
2000 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
2003 _mesa_unlock_texture(ctx
, obj
);
2008 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
2010 struct gl_texture_unit
*texUnit
;
2011 struct gl_texture_object
*obj
;
2012 GET_CURRENT_CONTEXT(ctx
);
2013 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2015 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
2016 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2017 "glGetTexParameteriv(current unit)");
2021 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2023 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2025 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
2030 case GL_TEXTURE_MAG_FILTER
:
2031 *params
= (GLint
) obj
->MagFilter
;
2033 case GL_TEXTURE_MIN_FILTER
:
2034 *params
= (GLint
) obj
->MinFilter
;
2036 case GL_TEXTURE_WRAP_S
:
2037 *params
= (GLint
) obj
->WrapS
;
2039 case GL_TEXTURE_WRAP_T
:
2040 *params
= (GLint
) obj
->WrapT
;
2042 case GL_TEXTURE_WRAP_R
:
2043 *params
= (GLint
) obj
->WrapR
;
2045 case GL_TEXTURE_BORDER_COLOR
:
2048 b
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
2049 b
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
2050 b
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
2051 b
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
2052 params
[0] = FLOAT_TO_INT(b
[0]);
2053 params
[1] = FLOAT_TO_INT(b
[1]);
2054 params
[2] = FLOAT_TO_INT(b
[2]);
2055 params
[3] = FLOAT_TO_INT(b
[3]);
2058 case GL_TEXTURE_RESIDENT
:
2061 if (ctx
->Driver
.IsTextureResident
)
2062 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
2065 *params
= (GLint
) resident
;
2068 case GL_TEXTURE_PRIORITY
:
2069 *params
= FLOAT_TO_INT(obj
->Priority
);
2071 case GL_TEXTURE_MIN_LOD
:
2072 *params
= (GLint
) obj
->MinLod
;
2074 case GL_TEXTURE_MAX_LOD
:
2075 *params
= (GLint
) obj
->MaxLod
;
2077 case GL_TEXTURE_BASE_LEVEL
:
2078 *params
= obj
->BaseLevel
;
2080 case GL_TEXTURE_MAX_LEVEL
:
2081 *params
= obj
->MaxLevel
;
2083 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
2084 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
2085 *params
= (GLint
) obj
->MaxAnisotropy
;
2089 case GL_TEXTURE_COMPARE_SGIX
:
2090 if (ctx
->Extensions
.SGIX_shadow
) {
2091 *params
= (GLint
) obj
->CompareFlag
;
2095 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
2096 if (ctx
->Extensions
.SGIX_shadow
) {
2097 *params
= (GLint
) obj
->CompareOperator
;
2101 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
2102 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
2103 *params
= (GLint
) FLOAT_TO_INT(obj
->ShadowAmbient
);
2107 case GL_GENERATE_MIPMAP_SGIS
:
2108 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
2109 *params
= (GLint
) obj
->GenerateMipmap
;
2113 case GL_TEXTURE_COMPARE_MODE_ARB
:
2114 if (ctx
->Extensions
.ARB_shadow
) {
2115 *params
= (GLint
) obj
->CompareMode
;
2119 case GL_TEXTURE_COMPARE_FUNC_ARB
:
2120 if (ctx
->Extensions
.ARB_shadow
) {
2121 *params
= (GLint
) obj
->CompareFunc
;
2125 case GL_DEPTH_TEXTURE_MODE_ARB
:
2126 if (ctx
->Extensions
.ARB_depth_texture
) {
2127 *params
= (GLint
) obj
->DepthMode
;
2131 case GL_TEXTURE_LOD_BIAS
:
2132 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
2133 *params
= (GLint
) obj
->LodBias
;
2138 ; /* silence warnings */
2140 /* If we get here, pname was an unrecognized enum */
2141 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
2147 /**********************************************************************/
2148 /* Texture Coord Generation */
2149 /**********************************************************************/
2153 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
2155 GET_CURRENT_CONTEXT(ctx
);
2156 struct gl_texture_unit
*texUnit
;
2157 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2159 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
2160 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
2161 _mesa_lookup_enum_by_nr(coord
),
2162 _mesa_lookup_enum_by_nr(pname
),
2164 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *params
));
2166 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2167 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexGen(current unit)");
2171 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2175 if (pname
==GL_TEXTURE_GEN_MODE
) {
2176 GLenum mode
= (GLenum
) (GLint
) *params
;
2179 case GL_OBJECT_LINEAR
:
2180 bits
= TEXGEN_OBJ_LINEAR
;
2183 bits
= TEXGEN_EYE_LINEAR
;
2185 case GL_REFLECTION_MAP_NV
:
2186 bits
= TEXGEN_REFLECTION_MAP_NV
;
2188 case GL_NORMAL_MAP_NV
:
2189 bits
= TEXGEN_NORMAL_MAP_NV
;
2192 bits
= TEXGEN_SPHERE_MAP
;
2195 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2198 if (texUnit
->GenModeS
== mode
)
2200 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2201 texUnit
->GenModeS
= mode
;
2202 texUnit
->_GenBitS
= bits
;
2204 else if (pname
==GL_OBJECT_PLANE
) {
2205 if (TEST_EQ_4V(texUnit
->ObjectPlaneS
, params
))
2207 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2208 COPY_4FV(texUnit
->ObjectPlaneS
, params
);
2210 else if (pname
==GL_EYE_PLANE
) {
2212 /* Transform plane equation by the inverse modelview matrix */
2213 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
2214 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2216 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2217 if (TEST_EQ_4V(texUnit
->EyePlaneS
, tmp
))
2219 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2220 COPY_4FV(texUnit
->EyePlaneS
, tmp
);
2223 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2228 if (pname
==GL_TEXTURE_GEN_MODE
) {
2229 GLenum mode
= (GLenum
) (GLint
) *params
;
2232 case GL_OBJECT_LINEAR
:
2233 bitt
= TEXGEN_OBJ_LINEAR
;
2236 bitt
= TEXGEN_EYE_LINEAR
;
2238 case GL_REFLECTION_MAP_NV
:
2239 bitt
= TEXGEN_REFLECTION_MAP_NV
;
2241 case GL_NORMAL_MAP_NV
:
2242 bitt
= TEXGEN_NORMAL_MAP_NV
;
2245 bitt
= TEXGEN_SPHERE_MAP
;
2248 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2251 if (texUnit
->GenModeT
== mode
)
2253 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2254 texUnit
->GenModeT
= mode
;
2255 texUnit
->_GenBitT
= bitt
;
2257 else if (pname
==GL_OBJECT_PLANE
) {
2258 if (TEST_EQ_4V(texUnit
->ObjectPlaneT
, params
))
2260 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2261 COPY_4FV(texUnit
->ObjectPlaneT
, params
);
2263 else if (pname
==GL_EYE_PLANE
) {
2265 /* Transform plane equation by the inverse modelview matrix */
2266 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
2267 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2269 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2270 if (TEST_EQ_4V(texUnit
->EyePlaneT
, tmp
))
2272 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2273 COPY_4FV(texUnit
->EyePlaneT
, tmp
);
2276 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2281 if (pname
==GL_TEXTURE_GEN_MODE
) {
2282 GLenum mode
= (GLenum
) (GLint
) *params
;
2285 case GL_OBJECT_LINEAR
:
2286 bitr
= TEXGEN_OBJ_LINEAR
;
2288 case GL_REFLECTION_MAP_NV
:
2289 bitr
= TEXGEN_REFLECTION_MAP_NV
;
2291 case GL_NORMAL_MAP_NV
:
2292 bitr
= TEXGEN_NORMAL_MAP_NV
;
2295 bitr
= TEXGEN_EYE_LINEAR
;
2298 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2301 if (texUnit
->GenModeR
== mode
)
2303 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2304 texUnit
->GenModeR
= mode
;
2305 texUnit
->_GenBitR
= bitr
;
2307 else if (pname
==GL_OBJECT_PLANE
) {
2308 if (TEST_EQ_4V(texUnit
->ObjectPlaneR
, params
))
2310 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2311 COPY_4FV(texUnit
->ObjectPlaneR
, params
);
2313 else if (pname
==GL_EYE_PLANE
) {
2315 /* Transform plane equation by the inverse modelview matrix */
2316 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
2317 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2319 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2320 if (TEST_EQ_4V(texUnit
->EyePlaneR
, tmp
))
2322 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2323 COPY_4FV(texUnit
->EyePlaneR
, tmp
);
2326 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2331 if (pname
==GL_TEXTURE_GEN_MODE
) {
2332 GLenum mode
= (GLenum
) (GLint
) *params
;
2335 case GL_OBJECT_LINEAR
:
2336 bitq
= TEXGEN_OBJ_LINEAR
;
2339 bitq
= TEXGEN_EYE_LINEAR
;
2342 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2345 if (texUnit
->GenModeQ
== mode
)
2347 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2348 texUnit
->GenModeQ
= mode
;
2349 texUnit
->_GenBitQ
= bitq
;
2351 else if (pname
==GL_OBJECT_PLANE
) {
2352 if (TEST_EQ_4V(texUnit
->ObjectPlaneQ
, params
))
2354 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2355 COPY_4FV(texUnit
->ObjectPlaneQ
, params
);
2357 else if (pname
==GL_EYE_PLANE
) {
2359 /* Transform plane equation by the inverse modelview matrix */
2360 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
2361 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2363 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2364 if (TEST_EQ_4V(texUnit
->EyePlaneQ
, tmp
))
2366 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2367 COPY_4FV(texUnit
->EyePlaneQ
, tmp
);
2370 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2375 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
2379 if (ctx
->Driver
.TexGen
)
2380 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
2385 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*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_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
2404 GLfloat p
= (GLfloat
) param
;
2405 _mesa_TexGenfv( coord
, pname
, &p
);
2410 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
2413 p
[0] = (GLfloat
) params
[0];
2414 if (pname
== GL_TEXTURE_GEN_MODE
) {
2415 p
[1] = p
[2] = p
[3] = 0.0F
;
2418 p
[1] = (GLfloat
) params
[1];
2419 p
[2] = (GLfloat
) params
[2];
2420 p
[3] = (GLfloat
) params
[3];
2422 _mesa_TexGenfv( coord
, pname
, p
);
2427 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
2429 _mesa_TexGenfv(coord
, pname
, ¶m
);
2434 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
2436 _mesa_TexGeniv( coord
, pname
, ¶m
);
2442 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
2444 const struct gl_texture_unit
*texUnit
;
2445 GET_CURRENT_CONTEXT(ctx
);
2446 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2448 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2449 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGendv(current unit)");
2453 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2457 if (pname
==GL_TEXTURE_GEN_MODE
) {
2458 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
2460 else if (pname
==GL_OBJECT_PLANE
) {
2461 COPY_4V( params
, texUnit
->ObjectPlaneS
);
2463 else if (pname
==GL_EYE_PLANE
) {
2464 COPY_4V( params
, texUnit
->EyePlaneS
);
2467 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2472 if (pname
==GL_TEXTURE_GEN_MODE
) {
2473 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
2475 else if (pname
==GL_OBJECT_PLANE
) {
2476 COPY_4V( params
, texUnit
->ObjectPlaneT
);
2478 else if (pname
==GL_EYE_PLANE
) {
2479 COPY_4V( params
, texUnit
->EyePlaneT
);
2482 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2487 if (pname
==GL_TEXTURE_GEN_MODE
) {
2488 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
2490 else if (pname
==GL_OBJECT_PLANE
) {
2491 COPY_4V( params
, texUnit
->ObjectPlaneR
);
2493 else if (pname
==GL_EYE_PLANE
) {
2494 COPY_4V( params
, texUnit
->EyePlaneR
);
2497 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2502 if (pname
==GL_TEXTURE_GEN_MODE
) {
2503 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
2505 else if (pname
==GL_OBJECT_PLANE
) {
2506 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
2508 else if (pname
==GL_EYE_PLANE
) {
2509 COPY_4V( params
, texUnit
->EyePlaneQ
);
2512 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2517 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
2525 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
2527 const struct gl_texture_unit
*texUnit
;
2528 GET_CURRENT_CONTEXT(ctx
);
2529 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2531 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2532 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGenfv(current unit)");
2536 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2540 if (pname
==GL_TEXTURE_GEN_MODE
) {
2541 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
2543 else if (pname
==GL_OBJECT_PLANE
) {
2544 COPY_4V( params
, texUnit
->ObjectPlaneS
);
2546 else if (pname
==GL_EYE_PLANE
) {
2547 COPY_4V( params
, texUnit
->EyePlaneS
);
2550 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2555 if (pname
==GL_TEXTURE_GEN_MODE
) {
2556 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
2558 else if (pname
==GL_OBJECT_PLANE
) {
2559 COPY_4V( params
, texUnit
->ObjectPlaneT
);
2561 else if (pname
==GL_EYE_PLANE
) {
2562 COPY_4V( params
, texUnit
->EyePlaneT
);
2565 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2570 if (pname
==GL_TEXTURE_GEN_MODE
) {
2571 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
2573 else if (pname
==GL_OBJECT_PLANE
) {
2574 COPY_4V( params
, texUnit
->ObjectPlaneR
);
2576 else if (pname
==GL_EYE_PLANE
) {
2577 COPY_4V( params
, texUnit
->EyePlaneR
);
2580 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2585 if (pname
==GL_TEXTURE_GEN_MODE
) {
2586 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
2588 else if (pname
==GL_OBJECT_PLANE
) {
2589 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
2591 else if (pname
==GL_EYE_PLANE
) {
2592 COPY_4V( params
, texUnit
->EyePlaneQ
);
2595 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2600 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
2608 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
2610 const struct gl_texture_unit
*texUnit
;
2611 GET_CURRENT_CONTEXT(ctx
);
2612 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2614 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2615 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGeniv(current unit)");
2619 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2623 if (pname
==GL_TEXTURE_GEN_MODE
) {
2624 params
[0] = texUnit
->GenModeS
;
2626 else if (pname
==GL_OBJECT_PLANE
) {
2627 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
2628 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
2629 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
2630 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
2632 else if (pname
==GL_EYE_PLANE
) {
2633 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
2634 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
2635 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
2636 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
2639 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2644 if (pname
==GL_TEXTURE_GEN_MODE
) {
2645 params
[0] = texUnit
->GenModeT
;
2647 else if (pname
==GL_OBJECT_PLANE
) {
2648 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
2649 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
2650 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
2651 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
2653 else if (pname
==GL_EYE_PLANE
) {
2654 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
2655 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
2656 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
2657 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
2660 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2665 if (pname
==GL_TEXTURE_GEN_MODE
) {
2666 params
[0] = texUnit
->GenModeR
;
2668 else if (pname
==GL_OBJECT_PLANE
) {
2669 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
2670 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
2671 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
2672 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
2674 else if (pname
==GL_EYE_PLANE
) {
2675 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
2676 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
2677 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
2678 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
2681 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2686 if (pname
==GL_TEXTURE_GEN_MODE
) {
2687 params
[0] = texUnit
->GenModeQ
;
2689 else if (pname
==GL_OBJECT_PLANE
) {
2690 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
2691 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
2692 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
2693 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
2695 else if (pname
==GL_EYE_PLANE
) {
2696 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
2697 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
2698 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
2699 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
2702 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2707 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
2714 /* GL_ARB_multitexture */
2716 _mesa_ActiveTextureARB(GLenum texture
)
2718 GET_CURRENT_CONTEXT(ctx
);
2719 const GLuint texUnit
= texture
- GL_TEXTURE0
;
2720 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2722 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2723 _mesa_debug(ctx
, "glActiveTexture %s\n",
2724 _mesa_lookup_enum_by_nr(texture
));
2726 /* XXX error-check against max(coordunits, imageunits) */
2727 if (texUnit
>= ctx
->Const
.MaxTextureUnits
) {
2728 _mesa_error(ctx
, GL_INVALID_ENUM
, "glActiveTexture(texture)");
2732 if (ctx
->Texture
.CurrentUnit
== texUnit
)
2735 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2737 ctx
->Texture
.CurrentUnit
= texUnit
;
2738 if (ctx
->Transform
.MatrixMode
== GL_TEXTURE
) {
2739 /* update current stack pointer */
2740 ctx
->CurrentStack
= &ctx
->TextureMatrixStack
[texUnit
];
2743 if (ctx
->Driver
.ActiveTexture
) {
2744 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
2749 /* GL_ARB_multitexture */
2751 _mesa_ClientActiveTextureARB(GLenum texture
)
2753 GET_CURRENT_CONTEXT(ctx
);
2754 GLuint texUnit
= texture
- GL_TEXTURE0
;
2755 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2757 if (texUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2758 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClientActiveTexture(texture)");
2762 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
2763 ctx
->Array
.ActiveTexture
= texUnit
;
2768 /**********************************************************************/
2769 /***** State management *****/
2770 /**********************************************************************/
2774 * \note This routine refers to derived texture attribute values to
2775 * compute the ENABLE_TEXMAT flags, but is only called on
2776 * _NEW_TEXTURE_MATRIX. On changes to _NEW_TEXTURE, the ENABLE_TEXMAT
2777 * flags are updated by _mesa_update_textures(), below.
2779 * \param ctx GL context.
2782 update_texture_matrices( GLcontext
*ctx
)
2786 ctx
->Texture
._TexMatEnabled
= 0;
2788 for (i
=0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
2789 if (_math_matrix_is_dirty(ctx
->TextureMatrixStack
[i
].Top
)) {
2790 _math_matrix_analyse( ctx
->TextureMatrixStack
[i
].Top
);
2792 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
&&
2793 ctx
->TextureMatrixStack
[i
].Top
->type
!= MATRIX_IDENTITY
)
2794 ctx
->Texture
._TexMatEnabled
|= ENABLE_TEXMAT(i
);
2796 if (ctx
->Driver
.TextureMatrix
)
2797 ctx
->Driver
.TextureMatrix( ctx
, i
, ctx
->TextureMatrixStack
[i
].Top
);
2804 * Update texture object's _Function field. We need to do this
2805 * whenever any of the texture object's shadow-related fields change
2806 * or when we start/stop using a fragment program.
2808 * This function could be expanded someday to update additional per-object
2809 * fields that depend on assorted state changes.
2812 update_texture_compare_function(GLcontext
*ctx
,
2813 struct gl_texture_object
*tObj
)
2815 /* XXX temporarily disable this test since it breaks the GLSL
2816 * shadow2D(), etc. functions.
2818 if (0 /*ctx->FragmentProgram._Current*/) {
2819 /* Texel/coordinate comparison is ignored for programs.
2820 * See GL_ARB_fragment_program/shader spec for details.
2822 tObj
->_Function
= GL_NONE
;
2824 else if (tObj
->CompareFlag
) {
2825 /* GL_SGIX_shadow */
2826 if (tObj
->CompareOperator
== GL_TEXTURE_LEQUAL_R_SGIX
) {
2827 tObj
->_Function
= GL_LEQUAL
;
2830 ASSERT(tObj
->CompareOperator
== GL_TEXTURE_GEQUAL_R_SGIX
);
2831 tObj
->_Function
= GL_GEQUAL
;
2834 else if (tObj
->CompareMode
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
2836 tObj
->_Function
= tObj
->CompareFunc
;
2839 tObj
->_Function
= GL_NONE
; /* pass depth through as grayscale */
2845 * Helper function for determining which texture object (1D, 2D, cube, etc)
2846 * should actually be used.
2849 texture_override(GLcontext
*ctx
,
2850 struct gl_texture_unit
*texUnit
, GLbitfield enableBits
,
2851 struct gl_texture_object
*texObj
, GLuint textureBit
)
2853 if (!texUnit
->_ReallyEnabled
&& (enableBits
& textureBit
)) {
2854 if (!texObj
->_Complete
) {
2855 _mesa_test_texobj_completeness(ctx
, texObj
);
2857 if (texObj
->_Complete
) {
2858 texUnit
->_ReallyEnabled
= textureBit
;
2859 texUnit
->_Current
= texObj
;
2860 update_texture_compare_function(ctx
, texObj
);
2867 * \note This routine refers to derived texture matrix values to
2868 * compute the ENABLE_TEXMAT flags, but is only called on
2869 * _NEW_TEXTURE. On changes to _NEW_TEXTURE_MATRIX, the ENABLE_TEXMAT
2870 * flags are updated by _mesa_update_texture_matrices, above.
2872 * \param ctx GL context.
2875 update_texture_state( GLcontext
*ctx
)
2878 struct gl_fragment_program
*fprog
= NULL
;
2879 struct gl_vertex_program
*vprog
= NULL
;
2881 if (ctx
->Shader
.CurrentProgram
&&
2882 ctx
->Shader
.CurrentProgram
->LinkStatus
) {
2883 fprog
= ctx
->Shader
.CurrentProgram
->FragmentProgram
;
2884 vprog
= ctx
->Shader
.CurrentProgram
->VertexProgram
;
2887 if (ctx
->FragmentProgram
._Enabled
) {
2888 fprog
= ctx
->FragmentProgram
.Current
;
2890 if (ctx
->VertexProgram
._Enabled
) {
2891 /* XXX enable this if/when non-shader vertex programs get
2893 vprog = ctx->VertexProgram.Current;
2898 ctx
->NewState
|= _NEW_TEXTURE
; /* TODO: only set this if there are
2902 ctx
->Texture
._EnabledUnits
= 0;
2903 ctx
->Texture
._GenFlags
= 0;
2904 ctx
->Texture
._TexMatEnabled
= 0;
2905 ctx
->Texture
._TexGenEnabled
= 0;
2908 * Update texture unit state.
2910 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
2911 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
2912 GLbitfield enableBits
;
2914 texUnit
->_Current
= NULL
;
2915 texUnit
->_ReallyEnabled
= 0;
2916 texUnit
->_GenFlags
= 0;
2918 /* Get the bitmask of texture enables.
2919 * enableBits will be a mask of the TEXTURE_*_BIT flags indicating
2920 * which texture targets are enabled (fixed function) or referenced
2921 * by a fragment shader/program. When multiple flags are set, we'll
2922 * settle on the one with highest priority (see texture_override below).
2924 if (fprog
|| vprog
) {
2927 enableBits
|= fprog
->Base
.TexturesUsed
[unit
];
2929 enableBits
|= vprog
->Base
.TexturesUsed
[unit
];
2932 if (!texUnit
->Enabled
)
2934 enableBits
= texUnit
->Enabled
;
2937 /* Look for the highest-priority texture target that's enabled and
2938 * complete. That's the one we'll use for texturing. If we're using
2939 * a fragment program we're guaranteed that bitcount(enabledBits) <= 1.
2941 texture_override(ctx
, texUnit
, enableBits
,
2942 texUnit
->Current2DArray
, TEXTURE_2D_ARRAY_BIT
);
2943 texture_override(ctx
, texUnit
, enableBits
,
2944 texUnit
->Current1DArray
, TEXTURE_1D_ARRAY_BIT
);
2945 texture_override(ctx
, texUnit
, enableBits
,
2946 texUnit
->CurrentCubeMap
, TEXTURE_CUBE_BIT
);
2947 texture_override(ctx
, texUnit
, enableBits
,
2948 texUnit
->Current3D
, TEXTURE_3D_BIT
);
2949 texture_override(ctx
, texUnit
, enableBits
,
2950 texUnit
->CurrentRect
, TEXTURE_RECT_BIT
);
2951 texture_override(ctx
, texUnit
, enableBits
,
2952 texUnit
->Current2D
, TEXTURE_2D_BIT
);
2953 texture_override(ctx
, texUnit
, enableBits
,
2954 texUnit
->Current1D
, TEXTURE_1D_BIT
);
2956 if (!texUnit
->_ReallyEnabled
) {
2960 if (texUnit
->_ReallyEnabled
)
2961 ctx
->Texture
._EnabledUnits
|= (1 << unit
);
2963 if (texUnit
->EnvMode
== GL_COMBINE
) {
2964 texUnit
->_CurrentCombine
= & texUnit
->Combine
;
2967 const struct gl_texture_object
*texObj
= texUnit
->_Current
;
2968 GLenum format
= texObj
->Image
[0][texObj
->BaseLevel
]->_BaseFormat
;
2969 if (format
== GL_COLOR_INDEX
) {
2970 format
= GL_RGBA
; /* a bit of a hack */
2972 else if (format
== GL_DEPTH_COMPONENT
2973 || format
== GL_DEPTH_STENCIL_EXT
) {
2974 format
= texObj
->DepthMode
;
2976 calculate_derived_texenv(&texUnit
->_EnvMode
, texUnit
->EnvMode
, format
);
2977 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
2980 switch (texUnit
->_CurrentCombine
->ModeRGB
) {
2982 texUnit
->_CurrentCombine
->_NumArgsRGB
= 1;
2990 case GL_DOT3_RGB_EXT
:
2991 case GL_DOT3_RGBA_EXT
:
2992 texUnit
->_CurrentCombine
->_NumArgsRGB
= 2;
2994 case GL_INTERPOLATE
:
2995 case GL_MODULATE_ADD_ATI
:
2996 case GL_MODULATE_SIGNED_ADD_ATI
:
2997 case GL_MODULATE_SUBTRACT_ATI
:
2998 texUnit
->_CurrentCombine
->_NumArgsRGB
= 3;
3001 texUnit
->_CurrentCombine
->_NumArgsRGB
= 0;
3002 _mesa_problem(ctx
, "invalid RGB combine mode in update_texture_state");
3006 switch (texUnit
->_CurrentCombine
->ModeA
) {
3008 texUnit
->_CurrentCombine
->_NumArgsA
= 1;
3014 texUnit
->_CurrentCombine
->_NumArgsA
= 2;
3016 case GL_INTERPOLATE
:
3017 case GL_MODULATE_ADD_ATI
:
3018 case GL_MODULATE_SIGNED_ADD_ATI
:
3019 case GL_MODULATE_SUBTRACT_ATI
:
3020 texUnit
->_CurrentCombine
->_NumArgsA
= 3;
3023 texUnit
->_CurrentCombine
->_NumArgsA
= 0;
3024 _mesa_problem(ctx
, "invalid Alpha combine mode in update_texture_state");
3028 if (texUnit
->TexGenEnabled
) {
3029 if (texUnit
->TexGenEnabled
& S_BIT
) {
3030 texUnit
->_GenFlags
|= texUnit
->_GenBitS
;
3032 if (texUnit
->TexGenEnabled
& T_BIT
) {
3033 texUnit
->_GenFlags
|= texUnit
->_GenBitT
;
3035 if (texUnit
->TexGenEnabled
& Q_BIT
) {
3036 texUnit
->_GenFlags
|= texUnit
->_GenBitQ
;
3038 if (texUnit
->TexGenEnabled
& R_BIT
) {
3039 texUnit
->_GenFlags
|= texUnit
->_GenBitR
;
3042 ctx
->Texture
._TexGenEnabled
|= ENABLE_TEXGEN(unit
);
3043 ctx
->Texture
._GenFlags
|= texUnit
->_GenFlags
;
3046 if (ctx
->TextureMatrixStack
[unit
].Top
->type
!= MATRIX_IDENTITY
)
3047 ctx
->Texture
._TexMatEnabled
|= ENABLE_TEXMAT(unit
);
3050 /* Determine which texture coordinate sets are actually needed */
3052 const GLuint coordMask
= (1 << MAX_TEXTURE_COORD_UNITS
) - 1;
3053 ctx
->Texture
._EnabledCoordUnits
3054 = (fprog
->Base
.InputsRead
>> FRAG_ATTRIB_TEX0
) & coordMask
;
3057 ctx
->Texture
._EnabledCoordUnits
= ctx
->Texture
._EnabledUnits
;
3063 * Update texture-related derived state.
3066 _mesa_update_texture( GLcontext
*ctx
, GLuint new_state
)
3068 if (new_state
& _NEW_TEXTURE_MATRIX
)
3069 update_texture_matrices( ctx
);
3071 if (new_state
& (_NEW_TEXTURE
| _NEW_PROGRAM
))
3072 update_texture_state( ctx
);
3076 /**********************************************************************/
3077 /***** Initialization *****/
3078 /**********************************************************************/
3081 * Allocate the proxy textures for the given context.
3083 * \param ctx the context to allocate proxies for.
3085 * \return GL_TRUE on success, or GL_FALSE on failure
3087 * If run out of memory part way through the allocations, clean up and return
3091 alloc_proxy_textures( GLcontext
*ctx
)
3093 ctx
->Texture
.Proxy1D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_1D
);
3094 if (!ctx
->Texture
.Proxy1D
)
3097 ctx
->Texture
.Proxy2D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_2D
);
3098 if (!ctx
->Texture
.Proxy2D
)
3101 ctx
->Texture
.Proxy3D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_3D
);
3102 if (!ctx
->Texture
.Proxy3D
)
3105 ctx
->Texture
.ProxyCubeMap
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_CUBE_MAP_ARB
);
3106 if (!ctx
->Texture
.ProxyCubeMap
)
3109 ctx
->Texture
.ProxyRect
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_RECTANGLE_NV
);
3110 if (!ctx
->Texture
.ProxyRect
)
3113 ctx
->Texture
.Proxy1DArray
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_1D_ARRAY_EXT
);
3114 if (!ctx
->Texture
.Proxy1DArray
)
3117 ctx
->Texture
.Proxy2DArray
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_2D_ARRAY_EXT
);
3118 if (!ctx
->Texture
.Proxy2DArray
)
3124 if (ctx
->Texture
.Proxy1D
)
3125 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1D
);
3126 if (ctx
->Texture
.Proxy2D
)
3127 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2D
);
3128 if (ctx
->Texture
.Proxy3D
)
3129 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy3D
);
3130 if (ctx
->Texture
.ProxyCubeMap
)
3131 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyCubeMap
);
3132 if (ctx
->Texture
.ProxyRect
)
3133 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyRect
);
3134 if (ctx
->Texture
.Proxy1DArray
)
3135 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1DArray
);
3136 if (ctx
->Texture
.Proxy2DArray
)
3137 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2DArray
);
3143 * Initialize a texture unit.
3145 * \param ctx GL context.
3146 * \param unit texture unit number to be initialized.
3149 init_texture_unit( GLcontext
*ctx
, GLuint unit
)
3151 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
3153 texUnit
->EnvMode
= GL_MODULATE
;
3154 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
3156 texUnit
->Combine
= default_combine_state
;
3157 texUnit
->_EnvMode
= default_combine_state
;
3158 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
3160 texUnit
->TexGenEnabled
= 0;
3161 texUnit
->GenModeS
= GL_EYE_LINEAR
;
3162 texUnit
->GenModeT
= GL_EYE_LINEAR
;
3163 texUnit
->GenModeR
= GL_EYE_LINEAR
;
3164 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
3165 texUnit
->_GenBitS
= TEXGEN_EYE_LINEAR
;
3166 texUnit
->_GenBitT
= TEXGEN_EYE_LINEAR
;
3167 texUnit
->_GenBitR
= TEXGEN_EYE_LINEAR
;
3168 texUnit
->_GenBitQ
= TEXGEN_EYE_LINEAR
;
3170 /* Yes, these plane coefficients are correct! */
3171 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
3172 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
3173 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
3174 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
3175 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
3176 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
3177 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
3178 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
3180 texUnit
->Current1D
= ctx
->Shared
->Default1D
;
3181 texUnit
->Current2D
= ctx
->Shared
->Default2D
;
3182 texUnit
->Current3D
= ctx
->Shared
->Default3D
;
3183 texUnit
->CurrentCubeMap
= ctx
->Shared
->DefaultCubeMap
;
3184 texUnit
->CurrentRect
= ctx
->Shared
->DefaultRect
;
3185 texUnit
->Current1DArray
= ctx
->Shared
->Default1DArray
;
3186 texUnit
->Current2DArray
= ctx
->Shared
->Default2DArray
;
3191 * Initialize texture state for the given context.
3194 _mesa_init_texture(GLcontext
*ctx
)
3198 assert(MAX_TEXTURE_LEVELS
>= MAX_3D_TEXTURE_LEVELS
);
3199 assert(MAX_TEXTURE_LEVELS
>= MAX_CUBE_TEXTURE_LEVELS
);
3201 /* Effectively bind the default textures to all texture units */
3202 ctx
->Shared
->Default1D
->RefCount
+= MAX_TEXTURE_UNITS
;
3203 ctx
->Shared
->Default2D
->RefCount
+= MAX_TEXTURE_UNITS
;
3204 ctx
->Shared
->Default3D
->RefCount
+= MAX_TEXTURE_UNITS
;
3205 ctx
->Shared
->DefaultCubeMap
->RefCount
+= MAX_TEXTURE_UNITS
;
3206 ctx
->Shared
->DefaultRect
->RefCount
+= MAX_TEXTURE_UNITS
;
3207 ctx
->Shared
->Default1DArray
->RefCount
+= MAX_TEXTURE_UNITS
;
3208 ctx
->Shared
->Default2DArray
->RefCount
+= MAX_TEXTURE_UNITS
;
3211 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
3212 ctx
->Texture
._EnabledUnits
= 0;
3213 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
3214 init_texture_unit( ctx
, i
);
3215 ctx
->Texture
.SharedPalette
= GL_FALSE
;
3216 _mesa_init_colortable(&ctx
->Texture
.Palette
);
3218 /* Allocate proxy textures */
3219 if (!alloc_proxy_textures( ctx
))
3227 * Free dynamically-allocted texture data attached to the given context.
3230 _mesa_free_texture_data(GLcontext
*ctx
)
3234 /* Free proxy texture objects */
3235 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1D
);
3236 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2D
);
3237 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy3D
);
3238 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyCubeMap
);
3239 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyRect
);
3240 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1DArray
);
3241 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2DArray
);
3243 for (i
= 0; i
< MAX_TEXTURE_IMAGE_UNITS
; i
++)
3244 _mesa_free_colortable_data( &ctx
->Texture
.Unit
[i
].ColorTable
);