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");
244 mode_rgb
= (texBaseFormat
== GL_ALPHA
) ? GL_REPLACE
: mode
;
249 mode_rgb
= GL_INTERPOLATE
;
252 state
->SourceA
[0] = GL_PREVIOUS
;
254 /* Having alpha / luminance / intensity textures replace using the
255 * incoming fragment color matches the definition in NV_texture_shader.
256 * The 1.5 spec simply marks these as "undefined".
258 switch (texBaseFormat
) {
261 case GL_LUMINANCE_ALPHA
:
263 state
->SourceRGB
[0] = GL_PREVIOUS
;
267 mode_rgb
= GL_REPLACE
;
270 state
->SourceRGB
[2] = GL_TEXTURE
;
276 mode_rgb
= GL_INTERPOLATE
;
277 mode_a
= GL_MODULATE
;
279 switch (texBaseFormat
) {
281 mode_rgb
= GL_REPLACE
;
284 mode_a
= GL_INTERPOLATE
;
285 state
->SourceA
[0] = GL_CONSTANT
;
286 state
->OperandA
[2] = GL_SRC_ALPHA
;
290 case GL_LUMINANCE_ALPHA
:
293 state
->SourceRGB
[2] = GL_TEXTURE
;
294 state
->SourceA
[2] = GL_TEXTURE
;
295 state
->SourceRGB
[0] = GL_CONSTANT
;
296 state
->OperandRGB
[2] = GL_SRC_COLOR
;
302 mode_rgb
= (texBaseFormat
== GL_ALPHA
) ? GL_REPLACE
: GL_ADD
;
303 mode_a
= (texBaseFormat
== GL_INTENSITY
) ? GL_ADD
: GL_MODULATE
;
308 "Invalid texture env mode in calculate_derived_texenv");
312 state
->ModeRGB
= (state
->SourceRGB
[0] != GL_PREVIOUS
)
313 ? mode_rgb
: GL_REPLACE
;
314 state
->ModeA
= (state
->SourceA
[0] != GL_PREVIOUS
)
315 ? mode_a
: GL_REPLACE
;
320 _mesa_TexEnvfv( GLenum target
, GLenum pname
, const GLfloat
*param
)
323 GET_CURRENT_CONTEXT(ctx
);
324 struct gl_texture_unit
*texUnit
;
325 ASSERT_OUTSIDE_BEGIN_END(ctx
);
327 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
328 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
329 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
330 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexEnvfv(current unit)");
334 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
336 #define TE_ERROR(errCode, msg, value) \
337 _mesa_error(ctx, errCode, msg, _mesa_lookup_enum_by_nr(value));
339 if (target
== GL_TEXTURE_ENV
) {
341 case GL_TEXTURE_ENV_MODE
:
343 const GLenum mode
= (GLenum
) (GLint
) *param
;
344 if (texUnit
->EnvMode
== mode
)
346 if (mode
== GL_MODULATE
||
349 mode
== GL_REPLACE
||
350 (mode
== GL_ADD
&& ctx
->Extensions
.EXT_texture_env_add
) ||
351 (mode
== GL_COMBINE
&&
352 (ctx
->Extensions
.EXT_texture_env_combine
||
353 ctx
->Extensions
.ARB_texture_env_combine
))) {
355 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
356 texUnit
->EnvMode
= mode
;
359 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
364 case GL_TEXTURE_ENV_COLOR
:
367 tmp
[0] = CLAMP( param
[0], 0.0F
, 1.0F
);
368 tmp
[1] = CLAMP( param
[1], 0.0F
, 1.0F
);
369 tmp
[2] = CLAMP( param
[2], 0.0F
, 1.0F
);
370 tmp
[3] = CLAMP( param
[3], 0.0F
, 1.0F
);
371 if (TEST_EQ_4V(tmp
, texUnit
->EnvColor
))
373 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
374 COPY_4FV(texUnit
->EnvColor
, tmp
);
378 if (ctx
->Extensions
.EXT_texture_env_combine
||
379 ctx
->Extensions
.ARB_texture_env_combine
) {
380 const GLenum mode
= (GLenum
) (GLint
) *param
;
381 if (texUnit
->Combine
.ModeRGB
== mode
)
392 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
393 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
397 case GL_DOT3_RGB_EXT
:
398 case GL_DOT3_RGBA_EXT
:
399 if (!ctx
->Extensions
.EXT_texture_env_dot3
) {
400 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
406 if (!ctx
->Extensions
.ARB_texture_env_dot3
) {
407 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
411 case GL_MODULATE_ADD_ATI
:
412 case GL_MODULATE_SIGNED_ADD_ATI
:
413 case GL_MODULATE_SUBTRACT_ATI
:
414 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
415 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
420 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
423 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
424 texUnit
->Combine
.ModeRGB
= mode
;
427 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
431 case GL_COMBINE_ALPHA
:
432 if (ctx
->Extensions
.EXT_texture_env_combine
||
433 ctx
->Extensions
.ARB_texture_env_combine
) {
434 const GLenum mode
= (GLenum
) (GLint
) *param
;
435 if (texUnit
->Combine
.ModeA
== mode
)
446 if (!ctx
->Extensions
.ARB_texture_env_combine
) {
447 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
451 case GL_MODULATE_ADD_ATI
:
452 case GL_MODULATE_SIGNED_ADD_ATI
:
453 case GL_MODULATE_SUBTRACT_ATI
:
454 if (!ctx
->Extensions
.ATI_texture_env_combine3
) {
455 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
460 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", mode
);
463 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
464 texUnit
->Combine
.ModeA
= mode
;
467 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
474 if (ctx
->Extensions
.EXT_texture_env_combine
||
475 ctx
->Extensions
.ARB_texture_env_combine
) {
476 const GLenum source
= (GLenum
) (GLint
) *param
;
477 const GLuint s
= pname
- GL_SOURCE0_RGB
;
478 if (texUnit
->Combine
.SourceRGB
[s
] == source
)
480 if (source
== GL_TEXTURE
||
481 source
== GL_CONSTANT
||
482 source
== GL_PRIMARY_COLOR
||
483 source
== GL_PREVIOUS
||
484 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
485 source
>= GL_TEXTURE0
&&
486 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
487 (ctx
->Extensions
.ATI_texture_env_combine3
&&
488 (source
== GL_ZERO
|| source
== GL_ONE
))) {
490 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
491 texUnit
->Combine
.SourceRGB
[s
] = source
;
494 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
499 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
503 case GL_SOURCE0_ALPHA
:
504 case GL_SOURCE1_ALPHA
:
505 case GL_SOURCE2_ALPHA
:
506 if (ctx
->Extensions
.EXT_texture_env_combine
||
507 ctx
->Extensions
.ARB_texture_env_combine
) {
508 const GLenum source
= (GLenum
) (GLint
) *param
;
509 const GLuint s
= pname
- GL_SOURCE0_ALPHA
;
510 if (texUnit
->Combine
.SourceA
[s
] == source
)
512 if (source
== GL_TEXTURE
||
513 source
== GL_CONSTANT
||
514 source
== GL_PRIMARY_COLOR
||
515 source
== GL_PREVIOUS
||
516 (ctx
->Extensions
.ARB_texture_env_crossbar
&&
517 source
>= GL_TEXTURE0
&&
518 source
< GL_TEXTURE0
+ ctx
->Const
.MaxTextureUnits
) ||
519 (ctx
->Extensions
.ATI_texture_env_combine3
&&
520 (source
== GL_ZERO
|| source
== GL_ONE
))) {
522 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
523 texUnit
->Combine
.SourceA
[s
] = source
;
526 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", source
);
531 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
535 case GL_OPERAND0_RGB
:
536 case GL_OPERAND1_RGB
:
537 if (ctx
->Extensions
.EXT_texture_env_combine
||
538 ctx
->Extensions
.ARB_texture_env_combine
) {
539 const GLenum operand
= (GLenum
) (GLint
) *param
;
540 const GLuint s
= pname
- GL_OPERAND0_RGB
;
541 if (texUnit
->Combine
.OperandRGB
[s
] == operand
)
545 case GL_ONE_MINUS_SRC_COLOR
:
547 case GL_ONE_MINUS_SRC_ALPHA
:
548 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
549 texUnit
->Combine
.OperandRGB
[s
] = operand
;
552 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
557 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
561 case GL_OPERAND0_ALPHA
:
562 case GL_OPERAND1_ALPHA
:
563 if (ctx
->Extensions
.EXT_texture_env_combine
||
564 ctx
->Extensions
.ARB_texture_env_combine
) {
565 const GLenum operand
= (GLenum
) (GLint
) *param
;
566 if (texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] == operand
)
570 case GL_ONE_MINUS_SRC_ALPHA
:
571 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
572 texUnit
->Combine
.OperandA
[pname
-GL_OPERAND0_ALPHA
] = operand
;
575 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
580 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
584 case GL_OPERAND2_RGB
:
585 if (ctx
->Extensions
.ARB_texture_env_combine
) {
586 const GLenum operand
= (GLenum
) (GLint
) *param
;
587 if (texUnit
->Combine
.OperandRGB
[2] == operand
)
590 case GL_SRC_COLOR
: /* ARB combine only */
591 case GL_ONE_MINUS_SRC_COLOR
: /* ARB combine only */
593 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
594 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
595 texUnit
->Combine
.OperandRGB
[2] = operand
;
598 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
602 else if (ctx
->Extensions
.EXT_texture_env_combine
) {
603 const GLenum operand
= (GLenum
) (GLint
) *param
;
604 if (texUnit
->Combine
.OperandRGB
[2] == operand
)
606 /* operand must be GL_SRC_ALPHA which is the initial value - thus
607 don't need to actually compare the operand to the possible value */
609 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
614 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
618 case GL_OPERAND2_ALPHA
:
619 if (ctx
->Extensions
.ARB_texture_env_combine
) {
620 const GLenum operand
= (GLenum
) (GLint
) *param
;
621 if (texUnit
->Combine
.OperandA
[2] == operand
)
625 case GL_ONE_MINUS_SRC_ALPHA
: /* ARB combine only */
626 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
627 texUnit
->Combine
.OperandA
[2] = operand
;
630 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
634 else if (ctx
->Extensions
.EXT_texture_env_combine
) {
635 const GLenum operand
= (GLenum
) (GLint
) *param
;
636 if (texUnit
->Combine
.OperandA
[2] == operand
)
638 /* operand must be GL_SRC_ALPHA which is the initial value - thus
639 don't need to actually compare the operand to the possible value */
641 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(param=%s)", operand
);
646 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
651 if (ctx
->Extensions
.EXT_texture_env_combine
||
652 ctx
->Extensions
.ARB_texture_env_combine
) {
657 else if (*param
== 2.0) {
660 else if (*param
== 4.0) {
664 _mesa_error( ctx
, GL_INVALID_VALUE
,
665 "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" );
668 if (texUnit
->Combine
.ScaleShiftRGB
== newshift
)
670 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
671 texUnit
->Combine
.ScaleShiftRGB
= newshift
;
674 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
679 if (ctx
->Extensions
.EXT_texture_env_combine
||
680 ctx
->Extensions
.ARB_texture_env_combine
) {
685 else if (*param
== 2.0) {
688 else if (*param
== 4.0) {
692 _mesa_error( ctx
, GL_INVALID_VALUE
,
693 "glTexEnv(GL_ALPHA_SCALE not 1, 2 or 4)" );
696 if (texUnit
->Combine
.ScaleShiftA
== newshift
)
698 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
699 texUnit
->Combine
.ScaleShiftA
= newshift
;
702 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
707 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname)" );
711 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
712 /* GL_EXT_texture_lod_bias */
713 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
714 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
717 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
718 if (texUnit
->LodBias
== param
[0])
720 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
721 texUnit
->LodBias
= param
[0];
724 TE_ERROR(GL_INVALID_ENUM
, "glTexEnv(pname=%s)", pname
);
728 else if (target
== GL_POINT_SPRITE_NV
) {
729 /* GL_ARB_point_sprite / GL_NV_point_sprite */
730 if (!ctx
->Extensions
.NV_point_sprite
731 && !ctx
->Extensions
.ARB_point_sprite
) {
732 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)", target
);
735 if (pname
== GL_COORD_REPLACE_NV
) {
736 const GLenum value
= (GLenum
) param
[0];
737 if (value
== GL_TRUE
|| value
== GL_FALSE
) {
738 /* It's kind of weird to set point state via glTexEnv,
739 * but that's what the spec calls for.
741 const GLboolean state
= (GLboolean
) value
;
742 if (ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] == state
)
744 FLUSH_VERTICES(ctx
, _NEW_POINT
);
745 ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
] = state
;
748 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexEnv(param=0x%x)", value
);
753 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(pname=0x%x)", pname
);
758 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexEnv(target=0x%x)",target
);
762 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
763 _mesa_debug(ctx
, "glTexEnv %s %s %.1f(%s) ...\n",
764 _mesa_lookup_enum_by_nr(target
),
765 _mesa_lookup_enum_by_nr(pname
),
767 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *param
));
769 /* Tell device driver about the new texture environment */
770 if (ctx
->Driver
.TexEnv
) {
771 (*ctx
->Driver
.TexEnv
)( ctx
, target
, pname
, param
);
777 _mesa_TexEnvf( GLenum target
, GLenum pname
, GLfloat param
)
779 _mesa_TexEnvfv( target
, pname
, ¶m
);
785 _mesa_TexEnvi( GLenum target
, GLenum pname
, GLint param
)
788 p
[0] = (GLfloat
) param
;
789 p
[1] = p
[2] = p
[3] = 0.0;
790 _mesa_TexEnvfv( target
, pname
, p
);
795 _mesa_TexEnviv( GLenum target
, GLenum pname
, const GLint
*param
)
798 if (pname
== GL_TEXTURE_ENV_COLOR
) {
799 p
[0] = INT_TO_FLOAT( param
[0] );
800 p
[1] = INT_TO_FLOAT( param
[1] );
801 p
[2] = INT_TO_FLOAT( param
[2] );
802 p
[3] = INT_TO_FLOAT( param
[3] );
805 p
[0] = (GLfloat
) param
[0];
806 p
[1] = p
[2] = p
[3] = 0; /* init to zero, just to be safe */
808 _mesa_TexEnvfv( target
, pname
, p
);
813 _mesa_GetTexEnvfv( GLenum target
, GLenum pname
, GLfloat
*params
)
816 const struct gl_texture_unit
*texUnit
;
817 GET_CURRENT_CONTEXT(ctx
);
818 ASSERT_OUTSIDE_BEGIN_END(ctx
);
820 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
821 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
822 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
823 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnvfv(current unit)");
827 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
829 if (target
== GL_TEXTURE_ENV
) {
831 case GL_TEXTURE_ENV_MODE
:
832 *params
= ENUM_TO_FLOAT(texUnit
->EnvMode
);
834 case GL_TEXTURE_ENV_COLOR
:
835 COPY_4FV( params
, texUnit
->EnvColor
);
838 if (ctx
->Extensions
.EXT_texture_env_combine
||
839 ctx
->Extensions
.ARB_texture_env_combine
) {
840 *params
= (GLfloat
) texUnit
->Combine
.ModeRGB
;
843 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
846 case GL_COMBINE_ALPHA
:
847 if (ctx
->Extensions
.EXT_texture_env_combine
||
848 ctx
->Extensions
.ARB_texture_env_combine
) {
849 *params
= (GLfloat
) texUnit
->Combine
.ModeA
;
852 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
858 if (ctx
->Extensions
.EXT_texture_env_combine
||
859 ctx
->Extensions
.ARB_texture_env_combine
) {
860 const unsigned rgb_idx
= pname
- GL_SOURCE0_RGB
;
861 *params
= (GLfloat
) texUnit
->Combine
.SourceRGB
[rgb_idx
];
864 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
867 case GL_SOURCE0_ALPHA
:
868 case GL_SOURCE1_ALPHA
:
869 case GL_SOURCE2_ALPHA
:
870 if (ctx
->Extensions
.EXT_texture_env_combine
||
871 ctx
->Extensions
.ARB_texture_env_combine
) {
872 const unsigned alpha_idx
= pname
- GL_SOURCE0_ALPHA
;
873 *params
= (GLfloat
) texUnit
->Combine
.SourceA
[alpha_idx
];
876 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
879 case GL_OPERAND0_RGB
:
880 case GL_OPERAND1_RGB
:
881 case GL_OPERAND2_RGB
:
882 if (ctx
->Extensions
.EXT_texture_env_combine
||
883 ctx
->Extensions
.ARB_texture_env_combine
) {
884 const unsigned op_rgb
= pname
- GL_OPERAND0_RGB
;
885 *params
= (GLfloat
) texUnit
->Combine
.OperandRGB
[op_rgb
];
888 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
891 case GL_OPERAND0_ALPHA
:
892 case GL_OPERAND1_ALPHA
:
893 case GL_OPERAND2_ALPHA
:
894 if (ctx
->Extensions
.EXT_texture_env_combine
||
895 ctx
->Extensions
.ARB_texture_env_combine
) {
896 const unsigned op_alpha
= pname
- GL_OPERAND0_ALPHA
;
897 *params
= (GLfloat
) texUnit
->Combine
.OperandA
[op_alpha
];
900 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
904 if (ctx
->Extensions
.EXT_texture_env_combine
||
905 ctx
->Extensions
.ARB_texture_env_combine
) {
906 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
908 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
914 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
919 if (ctx
->Extensions
.EXT_texture_env_combine
||
920 ctx
->Extensions
.ARB_texture_env_combine
) {
921 if (texUnit
->Combine
.ScaleShiftA
== 0)
923 else if (texUnit
->Combine
.ScaleShiftA
== 1)
929 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)");
934 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname=0x%x)", pname
);
937 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
938 /* GL_EXT_texture_lod_bias */
939 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
940 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
943 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
944 *params
= texUnit
->LodBias
;
947 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
951 else if (target
== GL_POINT_SPRITE_NV
) {
952 /* GL_ARB_point_sprite / GL_NV_point_sprite */
953 if (!ctx
->Extensions
.NV_point_sprite
954 && !ctx
->Extensions
.ARB_point_sprite
) {
955 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
958 if (pname
== GL_COORD_REPLACE_NV
) {
959 *params
= (GLfloat
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
962 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(pname)" );
967 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnvfv(target)" );
974 _mesa_GetTexEnviv( GLenum target
, GLenum pname
, GLint
*params
)
977 const struct gl_texture_unit
*texUnit
;
978 GET_CURRENT_CONTEXT(ctx
);
979 ASSERT_OUTSIDE_BEGIN_END(ctx
);
981 maxUnit
= (target
== GL_POINT_SPRITE_NV
&& pname
== GL_COORD_REPLACE_NV
)
982 ? ctx
->Const
.MaxTextureCoordUnits
: ctx
->Const
.MaxTextureImageUnits
;
983 if (ctx
->Texture
.CurrentUnit
>= maxUnit
) {
984 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexEnviv(current unit)");
988 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
990 if (target
== GL_TEXTURE_ENV
) {
992 case GL_TEXTURE_ENV_MODE
:
993 *params
= (GLint
) texUnit
->EnvMode
;
995 case GL_TEXTURE_ENV_COLOR
:
996 params
[0] = FLOAT_TO_INT( texUnit
->EnvColor
[0] );
997 params
[1] = FLOAT_TO_INT( texUnit
->EnvColor
[1] );
998 params
[2] = FLOAT_TO_INT( texUnit
->EnvColor
[2] );
999 params
[3] = FLOAT_TO_INT( texUnit
->EnvColor
[3] );
1001 case GL_COMBINE_RGB
:
1002 if (ctx
->Extensions
.EXT_texture_env_combine
||
1003 ctx
->Extensions
.ARB_texture_env_combine
) {
1004 *params
= (GLint
) texUnit
->Combine
.ModeRGB
;
1007 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1010 case GL_COMBINE_ALPHA
:
1011 if (ctx
->Extensions
.EXT_texture_env_combine
||
1012 ctx
->Extensions
.ARB_texture_env_combine
) {
1013 *params
= (GLint
) texUnit
->Combine
.ModeA
;
1016 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1019 case GL_SOURCE0_RGB
:
1020 case GL_SOURCE1_RGB
:
1021 case GL_SOURCE2_RGB
:
1022 if (ctx
->Extensions
.EXT_texture_env_combine
||
1023 ctx
->Extensions
.ARB_texture_env_combine
) {
1024 const unsigned rgb_idx
= pname
- GL_SOURCE0_RGB
;
1025 *params
= (GLint
) texUnit
->Combine
.SourceRGB
[rgb_idx
];
1028 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1031 case GL_SOURCE0_ALPHA
:
1032 case GL_SOURCE1_ALPHA
:
1033 case GL_SOURCE2_ALPHA
:
1034 if (ctx
->Extensions
.EXT_texture_env_combine
||
1035 ctx
->Extensions
.ARB_texture_env_combine
) {
1036 const unsigned alpha_idx
= pname
- GL_SOURCE0_ALPHA
;
1037 *params
= (GLint
) texUnit
->Combine
.SourceA
[alpha_idx
];
1040 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1043 case GL_OPERAND0_RGB
:
1044 case GL_OPERAND1_RGB
:
1045 case GL_OPERAND2_RGB
:
1046 if (ctx
->Extensions
.EXT_texture_env_combine
||
1047 ctx
->Extensions
.ARB_texture_env_combine
) {
1048 const unsigned op_rgb
= pname
- GL_OPERAND0_RGB
;
1049 *params
= (GLint
) texUnit
->Combine
.OperandRGB
[op_rgb
];
1052 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1055 case GL_OPERAND0_ALPHA
:
1056 case GL_OPERAND1_ALPHA
:
1057 case GL_OPERAND2_ALPHA
:
1058 if (ctx
->Extensions
.EXT_texture_env_combine
||
1059 ctx
->Extensions
.ARB_texture_env_combine
) {
1060 const unsigned op_alpha
= pname
- GL_OPERAND0_ALPHA
;
1061 *params
= (GLint
) texUnit
->Combine
.OperandA
[op_alpha
];
1064 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1068 if (ctx
->Extensions
.EXT_texture_env_combine
||
1069 ctx
->Extensions
.ARB_texture_env_combine
) {
1070 if (texUnit
->Combine
.ScaleShiftRGB
== 0)
1072 else if (texUnit
->Combine
.ScaleShiftRGB
== 1)
1078 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1082 case GL_ALPHA_SCALE
:
1083 if (ctx
->Extensions
.EXT_texture_env_combine
||
1084 ctx
->Extensions
.ARB_texture_env_combine
) {
1085 if (texUnit
->Combine
.ScaleShiftA
== 0)
1087 else if (texUnit
->Combine
.ScaleShiftA
== 1)
1093 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)");
1098 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname=0x%x)",
1102 else if (target
== GL_TEXTURE_FILTER_CONTROL_EXT
) {
1103 /* GL_EXT_texture_lod_bias */
1104 if (!ctx
->Extensions
.EXT_texture_lod_bias
) {
1105 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1108 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
1109 *params
= (GLint
) texUnit
->LodBias
;
1112 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
1116 else if (target
== GL_POINT_SPRITE_NV
) {
1117 /* GL_ARB_point_sprite / GL_NV_point_sprite */
1118 if (!ctx
->Extensions
.NV_point_sprite
1119 && !ctx
->Extensions
.ARB_point_sprite
) {
1120 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1123 if (pname
== GL_COORD_REPLACE_NV
) {
1124 *params
= (GLint
) ctx
->Point
.CoordReplace
[ctx
->Texture
.CurrentUnit
];
1127 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(pname)" );
1132 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexEnviv(target)" );
1140 /**********************************************************************/
1141 /* Texture Parameters */
1142 /**********************************************************************/
1145 * Check if a coordinate wrap mode is supported for the texture target.
1146 * \return GL_TRUE if legal, GL_FALSE otherwise
1149 validate_texture_wrap_mode(GLcontext
* ctx
, GLenum target
, GLenum wrap
)
1151 const struct gl_extensions
* const e
= & ctx
->Extensions
;
1153 if (wrap
== GL_CLAMP
|| wrap
== GL_CLAMP_TO_EDGE
||
1154 (wrap
== GL_CLAMP_TO_BORDER
&& e
->ARB_texture_border_clamp
)) {
1155 /* any texture target */
1158 else if (target
!= GL_TEXTURE_RECTANGLE_NV
&&
1159 (wrap
== GL_REPEAT
||
1160 (wrap
== GL_MIRRORED_REPEAT
&&
1161 e
->ARB_texture_mirrored_repeat
) ||
1162 (wrap
== GL_MIRROR_CLAMP_EXT
&&
1163 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
1164 (wrap
== GL_MIRROR_CLAMP_TO_EDGE_EXT
&&
1165 (e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
)) ||
1166 (wrap
== GL_MIRROR_CLAMP_TO_BORDER_EXT
&&
1167 (e
->EXT_texture_mirror_clamp
)))) {
1168 /* non-rectangle texture */
1172 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1178 _mesa_TexParameterf( GLenum target
, GLenum pname
, GLfloat param
)
1180 _mesa_TexParameterfv(target
, pname
, ¶m
);
1185 _mesa_TexParameterfv( GLenum target
, GLenum pname
, const GLfloat
*params
)
1187 const GLenum eparam
= (GLenum
) (GLint
) params
[0];
1188 struct gl_texture_unit
*texUnit
;
1189 struct gl_texture_object
*texObj
;
1190 GET_CURRENT_CONTEXT(ctx
);
1191 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1193 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
1194 _mesa_debug(ctx
, "glTexParameter %s %s %.1f(%s)...\n",
1195 _mesa_lookup_enum_by_nr(target
),
1196 _mesa_lookup_enum_by_nr(pname
),
1198 _mesa_lookup_enum_by_nr(eparam
));
1200 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1201 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameterfv(current unit)");
1205 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1209 texObj
= texUnit
->Current1D
;
1212 texObj
= texUnit
->Current2D
;
1215 texObj
= texUnit
->Current3D
;
1217 case GL_TEXTURE_CUBE_MAP
:
1218 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1219 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1222 texObj
= texUnit
->CurrentCubeMap
;
1224 case GL_TEXTURE_RECTANGLE_NV
:
1225 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1226 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1229 texObj
= texUnit
->CurrentRect
;
1231 case GL_TEXTURE_1D_ARRAY_EXT
:
1232 if (!ctx
->Extensions
.MESA_texture_array
) {
1233 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1236 texObj
= texUnit
->Current1DArray
;
1238 case GL_TEXTURE_2D_ARRAY_EXT
:
1239 if (!ctx
->Extensions
.MESA_texture_array
) {
1240 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1243 texObj
= texUnit
->Current2DArray
;
1246 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexParameter(target)" );
1251 case GL_TEXTURE_MIN_FILTER
:
1252 /* A small optimization */
1253 if (texObj
->MinFilter
== eparam
)
1255 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
1256 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1257 texObj
->MinFilter
= eparam
;
1259 else if ((eparam
==GL_NEAREST_MIPMAP_NEAREST
||
1260 eparam
==GL_LINEAR_MIPMAP_NEAREST
||
1261 eparam
==GL_NEAREST_MIPMAP_LINEAR
||
1262 eparam
==GL_LINEAR_MIPMAP_LINEAR
) &&
1263 texObj
->Target
!= GL_TEXTURE_RECTANGLE_NV
) {
1264 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1265 texObj
->MinFilter
= eparam
;
1268 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1272 case GL_TEXTURE_MAG_FILTER
:
1273 /* A small optimization */
1274 if (texObj
->MagFilter
== eparam
)
1277 if (eparam
==GL_NEAREST
|| eparam
==GL_LINEAR
) {
1278 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1279 texObj
->MagFilter
= eparam
;
1282 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1286 case GL_TEXTURE_WRAP_S
:
1287 if (texObj
->WrapS
== eparam
)
1289 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1290 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1291 texObj
->WrapS
= eparam
;
1297 case GL_TEXTURE_WRAP_T
:
1298 if (texObj
->WrapT
== eparam
)
1300 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1301 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1302 texObj
->WrapT
= eparam
;
1308 case GL_TEXTURE_WRAP_R
:
1309 if (texObj
->WrapR
== eparam
)
1311 if (validate_texture_wrap_mode(ctx
, texObj
->Target
, eparam
)) {
1312 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1313 texObj
->WrapR
= eparam
;
1319 case GL_TEXTURE_BORDER_COLOR
:
1320 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1321 texObj
->BorderColor
[RCOMP
] = params
[0];
1322 texObj
->BorderColor
[GCOMP
] = params
[1];
1323 texObj
->BorderColor
[BCOMP
] = params
[2];
1324 texObj
->BorderColor
[ACOMP
] = params
[3];
1325 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[RCOMP
], params
[0]);
1326 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[GCOMP
], params
[1]);
1327 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[BCOMP
], params
[2]);
1328 UNCLAMPED_FLOAT_TO_CHAN(texObj
->_BorderChan
[ACOMP
], params
[3]);
1330 case GL_TEXTURE_MIN_LOD
:
1331 if (texObj
->MinLod
== params
[0])
1333 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1334 texObj
->MinLod
= params
[0];
1336 case GL_TEXTURE_MAX_LOD
:
1337 if (texObj
->MaxLod
== params
[0])
1339 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1340 texObj
->MaxLod
= params
[0];
1342 case GL_TEXTURE_BASE_LEVEL
:
1343 if (params
[0] < 0.0) {
1344 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
1347 if (target
== GL_TEXTURE_RECTANGLE_ARB
&& params
[0] != 0.0) {
1348 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
1351 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1352 texObj
->BaseLevel
= (GLint
) params
[0];
1354 case GL_TEXTURE_MAX_LEVEL
:
1355 if (params
[0] < 0.0) {
1356 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)");
1359 if (target
== GL_TEXTURE_RECTANGLE_ARB
) {
1360 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexParameter(param)");
1363 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1364 texObj
->MaxLevel
= (GLint
) params
[0];
1366 case GL_TEXTURE_PRIORITY
:
1367 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1368 texObj
->Priority
= CLAMP( params
[0], 0.0F
, 1.0F
);
1370 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1371 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1372 if (params
[0] < 1.0) {
1373 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexParameter(param)" );
1376 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1377 /* clamp to max, that's what NVIDIA does */
1378 texObj
->MaxAnisotropy
= MIN2(params
[0],
1379 ctx
->Const
.MaxTextureMaxAnisotropy
);
1382 _mesa_error(ctx
, GL_INVALID_ENUM
,
1383 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
1387 case GL_TEXTURE_COMPARE_SGIX
:
1388 if (ctx
->Extensions
.SGIX_shadow
) {
1389 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1390 texObj
->CompareFlag
= params
[0] ? GL_TRUE
: GL_FALSE
;
1393 _mesa_error(ctx
, GL_INVALID_ENUM
,
1394 "glTexParameter(pname=GL_TEXTURE_COMPARE_SGIX)");
1398 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1399 if (ctx
->Extensions
.SGIX_shadow
) {
1400 GLenum op
= (GLenum
) params
[0];
1401 if (op
== GL_TEXTURE_LEQUAL_R_SGIX
||
1402 op
== GL_TEXTURE_GEQUAL_R_SGIX
) {
1403 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1404 texObj
->CompareOperator
= op
;
1407 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexParameter(param)");
1411 _mesa_error(ctx
, GL_INVALID_ENUM
,
1412 "glTexParameter(pname=GL_TEXTURE_COMPARE_OPERATOR_SGIX)");
1416 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1417 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1418 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1419 texObj
->ShadowAmbient
= CLAMP(params
[0], 0.0F
, 1.0F
);
1422 _mesa_error(ctx
, GL_INVALID_ENUM
,
1423 "glTexParameter(pname=GL_SHADOW_AMBIENT_SGIX)");
1427 case GL_GENERATE_MIPMAP_SGIS
:
1428 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1429 texObj
->GenerateMipmap
= params
[0] ? GL_TRUE
: GL_FALSE
;
1432 _mesa_error(ctx
, GL_INVALID_ENUM
,
1433 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
1437 case GL_TEXTURE_COMPARE_MODE_ARB
:
1438 if (ctx
->Extensions
.ARB_shadow
) {
1439 const GLenum mode
= (GLenum
) params
[0];
1440 if (mode
== GL_NONE
|| mode
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
1441 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1442 texObj
->CompareMode
= mode
;
1445 _mesa_error(ctx
, GL_INVALID_ENUM
,
1446 "glTexParameter(bad GL_TEXTURE_COMPARE_MODE_ARB: 0x%x)", mode
);
1451 _mesa_error(ctx
, GL_INVALID_ENUM
,
1452 "glTexParameter(pname=GL_TEXTURE_COMPARE_MODE_ARB)");
1456 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1457 if (ctx
->Extensions
.ARB_shadow
) {
1458 const GLenum func
= (GLenum
) params
[0];
1459 if (func
== GL_LEQUAL
|| func
== GL_GEQUAL
) {
1460 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1461 texObj
->CompareFunc
= func
;
1463 else if (ctx
->Extensions
.EXT_shadow_funcs
&&
1464 (func
== GL_EQUAL
||
1465 func
== GL_NOTEQUAL
||
1467 func
== GL_GREATER
||
1468 func
== GL_ALWAYS
||
1469 func
== GL_NEVER
)) {
1470 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1471 texObj
->CompareFunc
= func
;
1474 _mesa_error(ctx
, GL_INVALID_ENUM
,
1475 "glTexParameter(bad GL_TEXTURE_COMPARE_FUNC_ARB)");
1480 _mesa_error(ctx
, GL_INVALID_ENUM
,
1481 "glTexParameter(pname=GL_TEXTURE_COMPARE_FUNC_ARB)");
1485 case GL_DEPTH_TEXTURE_MODE_ARB
:
1486 if (ctx
->Extensions
.ARB_depth_texture
) {
1487 const GLenum result
= (GLenum
) params
[0];
1488 if (result
== GL_LUMINANCE
|| result
== GL_INTENSITY
1489 || result
== GL_ALPHA
) {
1490 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1491 texObj
->DepthMode
= result
;
1494 _mesa_error(ctx
, GL_INVALID_ENUM
,
1495 "glTexParameter(bad GL_DEPTH_TEXTURE_MODE_ARB)");
1500 _mesa_error(ctx
, GL_INVALID_ENUM
,
1501 "glTexParameter(pname=GL_DEPTH_TEXTURE_MODE_ARB)");
1505 case GL_TEXTURE_LOD_BIAS
:
1506 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias*/
1507 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1508 if (texObj
->LodBias
!= params
[0]) {
1509 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1510 texObj
->LodBias
= params
[0];
1516 _mesa_error(ctx
, GL_INVALID_ENUM
,
1517 "glTexParameter(pname=0x%x)", pname
);
1521 texObj
->_Complete
= GL_FALSE
;
1523 if (ctx
->Driver
.TexParameter
) {
1524 (*ctx
->Driver
.TexParameter
)( ctx
, target
, texObj
, pname
, params
);
1530 _mesa_TexParameteri( GLenum target
, GLenum pname
, GLint param
)
1533 if (pname
== GL_TEXTURE_PRIORITY
)
1534 fparam
[0] = INT_TO_FLOAT(param
);
1536 fparam
[0] = (GLfloat
) param
;
1537 fparam
[1] = fparam
[2] = fparam
[3] = 0.0;
1538 _mesa_TexParameterfv(target
, pname
, fparam
);
1543 _mesa_TexParameteriv( GLenum target
, GLenum pname
, const GLint
*params
)
1546 if (pname
== GL_TEXTURE_BORDER_COLOR
) {
1547 fparam
[0] = INT_TO_FLOAT(params
[0]);
1548 fparam
[1] = INT_TO_FLOAT(params
[1]);
1549 fparam
[2] = INT_TO_FLOAT(params
[2]);
1550 fparam
[3] = INT_TO_FLOAT(params
[3]);
1553 if (pname
== GL_TEXTURE_PRIORITY
)
1554 fparam
[0] = INT_TO_FLOAT(params
[0]);
1556 fparam
[0] = (GLfloat
) params
[0];
1557 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
1559 _mesa_TexParameterfv(target
, pname
, fparam
);
1564 _mesa_GetTexLevelParameterfv( GLenum target
, GLint level
,
1565 GLenum pname
, GLfloat
*params
)
1568 _mesa_GetTexLevelParameteriv( target
, level
, pname
, &iparam
);
1569 *params
= (GLfloat
) iparam
;
1574 tex_image_dimensions(GLcontext
*ctx
, GLenum target
)
1578 case GL_PROXY_TEXTURE_1D
:
1581 case GL_PROXY_TEXTURE_2D
:
1584 case GL_PROXY_TEXTURE_3D
:
1586 case GL_TEXTURE_CUBE_MAP
:
1587 case GL_PROXY_TEXTURE_CUBE_MAP
:
1588 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1589 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1590 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1591 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1592 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1593 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1594 return ctx
->Extensions
.ARB_texture_cube_map
? 2 : 0;
1595 case GL_TEXTURE_RECTANGLE_NV
:
1596 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1597 return ctx
->Extensions
.NV_texture_rectangle
? 2 : 0;
1598 case GL_TEXTURE_1D_ARRAY_EXT
:
1599 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1600 return ctx
->Extensions
.MESA_texture_array
? 2 : 0;
1601 case GL_TEXTURE_2D_ARRAY_EXT
:
1602 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1603 return ctx
->Extensions
.MESA_texture_array
? 3 : 0;
1605 _mesa_problem(ctx
, "bad target in _mesa_tex_target_dimensions()");
1612 _mesa_GetTexLevelParameteriv( GLenum target
, GLint level
,
1613 GLenum pname
, GLint
*params
)
1615 const struct gl_texture_unit
*texUnit
;
1616 struct gl_texture_object
*texObj
;
1617 const struct gl_texture_image
*img
= NULL
;
1621 GET_CURRENT_CONTEXT(ctx
);
1622 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1624 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1625 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1626 "glGetTexLevelParameteriv(current unit)");
1630 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1632 /* this will catch bad target values */
1633 dimensions
= tex_image_dimensions(ctx
, target
); /* 1, 2 or 3 */
1634 if (dimensions
== 0) {
1635 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexLevelParameter[if]v(target)");
1639 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1640 if (maxLevels
== 0) {
1641 /* should not happen since <target> was just checked above */
1642 _mesa_problem(ctx
, "maxLevels=0 in _mesa_GetTexLevelParameter");
1646 if (level
< 0 || level
>= maxLevels
) {
1647 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexLevelParameter[if]v" );
1651 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1652 _mesa_lock_texture(ctx
, texObj
);
1654 img
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1655 if (!img
|| !img
->TexFormat
) {
1656 /* undefined texture image */
1657 if (pname
== GL_TEXTURE_COMPONENTS
)
1664 isProxy
= _mesa_is_proxy_texture(target
);
1667 case GL_TEXTURE_WIDTH
:
1668 *params
= img
->Width
;
1670 case GL_TEXTURE_HEIGHT
:
1671 *params
= img
->Height
;
1673 case GL_TEXTURE_DEPTH
:
1674 *params
= img
->Depth
;
1676 case GL_TEXTURE_INTERNAL_FORMAT
:
1677 *params
= img
->InternalFormat
;
1679 case GL_TEXTURE_BORDER
:
1680 *params
= img
->Border
;
1682 case GL_TEXTURE_RED_SIZE
:
1683 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
1684 *params
= img
->TexFormat
->RedBits
;
1688 case GL_TEXTURE_GREEN_SIZE
:
1689 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
1690 *params
= img
->TexFormat
->GreenBits
;
1694 case GL_TEXTURE_BLUE_SIZE
:
1695 if (img
->_BaseFormat
== GL_RGB
|| img
->_BaseFormat
== GL_RGBA
)
1696 *params
= img
->TexFormat
->BlueBits
;
1700 case GL_TEXTURE_ALPHA_SIZE
:
1701 if (img
->_BaseFormat
== GL_ALPHA
||
1702 img
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
1703 img
->_BaseFormat
== GL_RGBA
)
1704 *params
= img
->TexFormat
->AlphaBits
;
1708 case GL_TEXTURE_INTENSITY_SIZE
:
1709 if (img
->_BaseFormat
!= GL_INTENSITY
)
1711 else if (img
->TexFormat
->IntensityBits
> 0)
1712 *params
= img
->TexFormat
->IntensityBits
;
1713 else /* intensity probably stored as rgb texture */
1714 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
1716 case GL_TEXTURE_LUMINANCE_SIZE
:
1717 if (img
->_BaseFormat
!= GL_LUMINANCE
&&
1718 img
->_BaseFormat
!= GL_LUMINANCE_ALPHA
)
1720 else if (img
->TexFormat
->LuminanceBits
> 0)
1721 *params
= img
->TexFormat
->LuminanceBits
;
1722 else /* luminance probably stored as rgb texture */
1723 *params
= MIN2(img
->TexFormat
->RedBits
, img
->TexFormat
->GreenBits
);
1725 case GL_TEXTURE_INDEX_SIZE_EXT
:
1726 if (img
->_BaseFormat
== GL_COLOR_INDEX
)
1727 *params
= img
->TexFormat
->IndexBits
;
1731 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1732 if (ctx
->Extensions
.SGIX_depth_texture
||
1733 ctx
->Extensions
.ARB_depth_texture
)
1734 *params
= img
->TexFormat
->DepthBits
;
1736 _mesa_error(ctx
, GL_INVALID_ENUM
,
1737 "glGetTexLevelParameter[if]v(pname)");
1739 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1740 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
1741 *params
= img
->TexFormat
->StencilBits
;
1744 _mesa_error(ctx
, GL_INVALID_ENUM
,
1745 "glGetTexLevelParameter[if]v(pname)");
1749 /* GL_ARB_texture_compression */
1750 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE
:
1751 if (ctx
->Extensions
.ARB_texture_compression
) {
1752 if (img
->IsCompressed
&& !isProxy
) {
1753 /* Don't use ctx->Driver.CompressedTextureSize() since that
1754 * may returned a padded hardware size.
1756 *params
= _mesa_compressed_texture_size(ctx
, img
->Width
,
1757 img
->Height
, img
->Depth
,
1758 img
->TexFormat
->MesaFormat
);
1761 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1762 "glGetTexLevelParameter[if]v(pname)");
1766 _mesa_error(ctx
, GL_INVALID_ENUM
,
1767 "glGetTexLevelParameter[if]v(pname)");
1770 case GL_TEXTURE_COMPRESSED
:
1771 if (ctx
->Extensions
.ARB_texture_compression
) {
1772 *params
= (GLint
) img
->IsCompressed
;
1775 _mesa_error(ctx
, GL_INVALID_ENUM
,
1776 "glGetTexLevelParameter[if]v(pname)");
1780 /* GL_ARB_texture_float */
1781 case GL_TEXTURE_RED_TYPE_ARB
:
1782 if (ctx
->Extensions
.ARB_texture_float
) {
1783 *params
= img
->TexFormat
->RedBits
? img
->TexFormat
->DataType
: GL_NONE
;
1786 _mesa_error(ctx
, GL_INVALID_ENUM
,
1787 "glGetTexLevelParameter[if]v(pname)");
1790 case GL_TEXTURE_GREEN_TYPE_ARB
:
1791 if (ctx
->Extensions
.ARB_texture_float
) {
1792 *params
= img
->TexFormat
->GreenBits
? img
->TexFormat
->DataType
: GL_NONE
;
1795 _mesa_error(ctx
, GL_INVALID_ENUM
,
1796 "glGetTexLevelParameter[if]v(pname)");
1799 case GL_TEXTURE_BLUE_TYPE_ARB
:
1800 if (ctx
->Extensions
.ARB_texture_float
) {
1801 *params
= img
->TexFormat
->BlueBits
? img
->TexFormat
->DataType
: GL_NONE
;
1804 _mesa_error(ctx
, GL_INVALID_ENUM
,
1805 "glGetTexLevelParameter[if]v(pname)");
1808 case GL_TEXTURE_ALPHA_TYPE_ARB
:
1809 if (ctx
->Extensions
.ARB_texture_float
) {
1810 *params
= img
->TexFormat
->AlphaBits
? img
->TexFormat
->DataType
: GL_NONE
;
1813 _mesa_error(ctx
, GL_INVALID_ENUM
,
1814 "glGetTexLevelParameter[if]v(pname)");
1817 case GL_TEXTURE_LUMINANCE_TYPE_ARB
:
1818 if (ctx
->Extensions
.ARB_texture_float
) {
1819 *params
= img
->TexFormat
->LuminanceBits
? img
->TexFormat
->DataType
: GL_NONE
;
1822 _mesa_error(ctx
, GL_INVALID_ENUM
,
1823 "glGetTexLevelParameter[if]v(pname)");
1826 case GL_TEXTURE_INTENSITY_TYPE_ARB
:
1827 if (ctx
->Extensions
.ARB_texture_float
) {
1828 *params
= img
->TexFormat
->IntensityBits
? img
->TexFormat
->DataType
: GL_NONE
;
1831 _mesa_error(ctx
, GL_INVALID_ENUM
,
1832 "glGetTexLevelParameter[if]v(pname)");
1835 case GL_TEXTURE_DEPTH_TYPE_ARB
:
1836 if (ctx
->Extensions
.ARB_texture_float
) {
1837 *params
= img
->TexFormat
->DepthBits
? img
->TexFormat
->DataType
: GL_NONE
;
1840 _mesa_error(ctx
, GL_INVALID_ENUM
,
1841 "glGetTexLevelParameter[if]v(pname)");
1846 _mesa_error(ctx
, GL_INVALID_ENUM
,
1847 "glGetTexLevelParameter[if]v(pname)");
1851 _mesa_unlock_texture(ctx
, texObj
);
1857 _mesa_GetTexParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
1859 struct gl_texture_unit
*texUnit
;
1860 struct gl_texture_object
*obj
;
1861 GLboolean error
= GL_FALSE
;
1862 GET_CURRENT_CONTEXT(ctx
);
1863 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1865 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1866 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1867 "glGetTexParameterfv(current unit)");
1871 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1873 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1875 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(target)");
1879 _mesa_lock_texture(ctx
, obj
);
1881 case GL_TEXTURE_MAG_FILTER
:
1882 *params
= ENUM_TO_FLOAT(obj
->MagFilter
);
1884 case GL_TEXTURE_MIN_FILTER
:
1885 *params
= ENUM_TO_FLOAT(obj
->MinFilter
);
1887 case GL_TEXTURE_WRAP_S
:
1888 *params
= ENUM_TO_FLOAT(obj
->WrapS
);
1890 case GL_TEXTURE_WRAP_T
:
1891 *params
= ENUM_TO_FLOAT(obj
->WrapT
);
1893 case GL_TEXTURE_WRAP_R
:
1894 *params
= ENUM_TO_FLOAT(obj
->WrapR
);
1896 case GL_TEXTURE_BORDER_COLOR
:
1897 params
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
1898 params
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
1899 params
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
1900 params
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
1902 case GL_TEXTURE_RESIDENT
:
1905 if (ctx
->Driver
.IsTextureResident
)
1906 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
1909 *params
= ENUM_TO_FLOAT(resident
);
1912 case GL_TEXTURE_PRIORITY
:
1913 *params
= obj
->Priority
;
1915 case GL_TEXTURE_MIN_LOD
:
1916 *params
= obj
->MinLod
;
1918 case GL_TEXTURE_MAX_LOD
:
1919 *params
= obj
->MaxLod
;
1921 case GL_TEXTURE_BASE_LEVEL
:
1922 *params
= (GLfloat
) obj
->BaseLevel
;
1924 case GL_TEXTURE_MAX_LEVEL
:
1925 *params
= (GLfloat
) obj
->MaxLevel
;
1927 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1928 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
1929 *params
= obj
->MaxAnisotropy
;
1934 case GL_TEXTURE_COMPARE_SGIX
:
1935 if (ctx
->Extensions
.SGIX_shadow
) {
1936 *params
= (GLfloat
) obj
->CompareFlag
;
1941 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
1942 if (ctx
->Extensions
.SGIX_shadow
) {
1943 *params
= (GLfloat
) obj
->CompareOperator
;
1948 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1949 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
1950 *params
= obj
->ShadowAmbient
;
1955 case GL_GENERATE_MIPMAP_SGIS
:
1956 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
1957 *params
= (GLfloat
) obj
->GenerateMipmap
;
1962 case GL_TEXTURE_COMPARE_MODE_ARB
:
1963 if (ctx
->Extensions
.ARB_shadow
) {
1964 *params
= (GLfloat
) obj
->CompareMode
;
1969 case GL_TEXTURE_COMPARE_FUNC_ARB
:
1970 if (ctx
->Extensions
.ARB_shadow
) {
1971 *params
= (GLfloat
) obj
->CompareFunc
;
1976 case GL_DEPTH_TEXTURE_MODE_ARB
:
1977 if (ctx
->Extensions
.ARB_depth_texture
) {
1978 *params
= (GLfloat
) obj
->DepthMode
;
1983 case GL_TEXTURE_LOD_BIAS
:
1984 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
1985 *params
= obj
->LodBias
;
1995 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameterfv(pname=0x%x)",
1998 _mesa_unlock_texture(ctx
, obj
);
2003 _mesa_GetTexParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
2005 struct gl_texture_unit
*texUnit
;
2006 struct gl_texture_object
*obj
;
2007 GET_CURRENT_CONTEXT(ctx
);
2008 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2010 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
2011 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2012 "glGetTexParameteriv(current unit)");
2016 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2018 obj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2020 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(target)");
2025 case GL_TEXTURE_MAG_FILTER
:
2026 *params
= (GLint
) obj
->MagFilter
;
2028 case GL_TEXTURE_MIN_FILTER
:
2029 *params
= (GLint
) obj
->MinFilter
;
2031 case GL_TEXTURE_WRAP_S
:
2032 *params
= (GLint
) obj
->WrapS
;
2034 case GL_TEXTURE_WRAP_T
:
2035 *params
= (GLint
) obj
->WrapT
;
2037 case GL_TEXTURE_WRAP_R
:
2038 *params
= (GLint
) obj
->WrapR
;
2040 case GL_TEXTURE_BORDER_COLOR
:
2043 b
[0] = CLAMP(obj
->BorderColor
[0], 0.0F
, 1.0F
);
2044 b
[1] = CLAMP(obj
->BorderColor
[1], 0.0F
, 1.0F
);
2045 b
[2] = CLAMP(obj
->BorderColor
[2], 0.0F
, 1.0F
);
2046 b
[3] = CLAMP(obj
->BorderColor
[3], 0.0F
, 1.0F
);
2047 params
[0] = FLOAT_TO_INT(b
[0]);
2048 params
[1] = FLOAT_TO_INT(b
[1]);
2049 params
[2] = FLOAT_TO_INT(b
[2]);
2050 params
[3] = FLOAT_TO_INT(b
[3]);
2053 case GL_TEXTURE_RESIDENT
:
2056 if (ctx
->Driver
.IsTextureResident
)
2057 resident
= ctx
->Driver
.IsTextureResident(ctx
, obj
);
2060 *params
= (GLint
) resident
;
2063 case GL_TEXTURE_PRIORITY
:
2064 *params
= FLOAT_TO_INT(obj
->Priority
);
2066 case GL_TEXTURE_MIN_LOD
:
2067 *params
= (GLint
) obj
->MinLod
;
2069 case GL_TEXTURE_MAX_LOD
:
2070 *params
= (GLint
) obj
->MaxLod
;
2072 case GL_TEXTURE_BASE_LEVEL
:
2073 *params
= obj
->BaseLevel
;
2075 case GL_TEXTURE_MAX_LEVEL
:
2076 *params
= obj
->MaxLevel
;
2078 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
2079 if (ctx
->Extensions
.EXT_texture_filter_anisotropic
) {
2080 *params
= (GLint
) obj
->MaxAnisotropy
;
2084 case GL_TEXTURE_COMPARE_SGIX
:
2085 if (ctx
->Extensions
.SGIX_shadow
) {
2086 *params
= (GLint
) obj
->CompareFlag
;
2090 case GL_TEXTURE_COMPARE_OPERATOR_SGIX
:
2091 if (ctx
->Extensions
.SGIX_shadow
) {
2092 *params
= (GLint
) obj
->CompareOperator
;
2096 case GL_SHADOW_AMBIENT_SGIX
: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
2097 if (ctx
->Extensions
.SGIX_shadow_ambient
) {
2098 *params
= (GLint
) FLOAT_TO_INT(obj
->ShadowAmbient
);
2102 case GL_GENERATE_MIPMAP_SGIS
:
2103 if (ctx
->Extensions
.SGIS_generate_mipmap
) {
2104 *params
= (GLint
) obj
->GenerateMipmap
;
2108 case GL_TEXTURE_COMPARE_MODE_ARB
:
2109 if (ctx
->Extensions
.ARB_shadow
) {
2110 *params
= (GLint
) obj
->CompareMode
;
2114 case GL_TEXTURE_COMPARE_FUNC_ARB
:
2115 if (ctx
->Extensions
.ARB_shadow
) {
2116 *params
= (GLint
) obj
->CompareFunc
;
2120 case GL_DEPTH_TEXTURE_MODE_ARB
:
2121 if (ctx
->Extensions
.ARB_depth_texture
) {
2122 *params
= (GLint
) obj
->DepthMode
;
2126 case GL_TEXTURE_LOD_BIAS
:
2127 if (ctx
->Extensions
.EXT_texture_lod_bias
) {
2128 *params
= (GLint
) obj
->LodBias
;
2133 ; /* silence warnings */
2135 /* If we get here, pname was an unrecognized enum */
2136 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexParameteriv(pname=0x%x)", pname
);
2142 /**********************************************************************/
2143 /* Texture Coord Generation */
2144 /**********************************************************************/
2148 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
2150 GET_CURRENT_CONTEXT(ctx
);
2151 struct gl_texture_unit
*texUnit
;
2152 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2154 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
2155 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
2156 _mesa_lookup_enum_by_nr(coord
),
2157 _mesa_lookup_enum_by_nr(pname
),
2159 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *params
));
2161 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2162 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexGen(current unit)");
2166 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2170 if (pname
==GL_TEXTURE_GEN_MODE
) {
2171 GLenum mode
= (GLenum
) (GLint
) *params
;
2174 case GL_OBJECT_LINEAR
:
2175 bits
= TEXGEN_OBJ_LINEAR
;
2178 bits
= TEXGEN_EYE_LINEAR
;
2180 case GL_REFLECTION_MAP_NV
:
2181 bits
= TEXGEN_REFLECTION_MAP_NV
;
2183 case GL_NORMAL_MAP_NV
:
2184 bits
= TEXGEN_NORMAL_MAP_NV
;
2187 bits
= TEXGEN_SPHERE_MAP
;
2190 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2193 if (texUnit
->GenModeS
== mode
)
2195 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2196 texUnit
->GenModeS
= mode
;
2197 texUnit
->_GenBitS
= bits
;
2199 else if (pname
==GL_OBJECT_PLANE
) {
2200 if (TEST_EQ_4V(texUnit
->ObjectPlaneS
, params
))
2202 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2203 COPY_4FV(texUnit
->ObjectPlaneS
, params
);
2205 else if (pname
==GL_EYE_PLANE
) {
2207 /* Transform plane equation by the inverse modelview matrix */
2208 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
2209 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2211 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2212 if (TEST_EQ_4V(texUnit
->EyePlaneS
, tmp
))
2214 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2215 COPY_4FV(texUnit
->EyePlaneS
, tmp
);
2218 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2223 if (pname
==GL_TEXTURE_GEN_MODE
) {
2224 GLenum mode
= (GLenum
) (GLint
) *params
;
2227 case GL_OBJECT_LINEAR
:
2228 bitt
= TEXGEN_OBJ_LINEAR
;
2231 bitt
= TEXGEN_EYE_LINEAR
;
2233 case GL_REFLECTION_MAP_NV
:
2234 bitt
= TEXGEN_REFLECTION_MAP_NV
;
2236 case GL_NORMAL_MAP_NV
:
2237 bitt
= TEXGEN_NORMAL_MAP_NV
;
2240 bitt
= TEXGEN_SPHERE_MAP
;
2243 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2246 if (texUnit
->GenModeT
== mode
)
2248 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2249 texUnit
->GenModeT
= mode
;
2250 texUnit
->_GenBitT
= bitt
;
2252 else if (pname
==GL_OBJECT_PLANE
) {
2253 if (TEST_EQ_4V(texUnit
->ObjectPlaneT
, params
))
2255 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2256 COPY_4FV(texUnit
->ObjectPlaneT
, params
);
2258 else if (pname
==GL_EYE_PLANE
) {
2260 /* Transform plane equation by the inverse modelview matrix */
2261 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
2262 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2264 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2265 if (TEST_EQ_4V(texUnit
->EyePlaneT
, tmp
))
2267 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2268 COPY_4FV(texUnit
->EyePlaneT
, tmp
);
2271 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2276 if (pname
==GL_TEXTURE_GEN_MODE
) {
2277 GLenum mode
= (GLenum
) (GLint
) *params
;
2280 case GL_OBJECT_LINEAR
:
2281 bitr
= TEXGEN_OBJ_LINEAR
;
2283 case GL_REFLECTION_MAP_NV
:
2284 bitr
= TEXGEN_REFLECTION_MAP_NV
;
2286 case GL_NORMAL_MAP_NV
:
2287 bitr
= TEXGEN_NORMAL_MAP_NV
;
2290 bitr
= TEXGEN_EYE_LINEAR
;
2293 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2296 if (texUnit
->GenModeR
== mode
)
2298 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2299 texUnit
->GenModeR
= mode
;
2300 texUnit
->_GenBitR
= bitr
;
2302 else if (pname
==GL_OBJECT_PLANE
) {
2303 if (TEST_EQ_4V(texUnit
->ObjectPlaneR
, params
))
2305 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2306 COPY_4FV(texUnit
->ObjectPlaneR
, params
);
2308 else if (pname
==GL_EYE_PLANE
) {
2310 /* Transform plane equation by the inverse modelview matrix */
2311 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
2312 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2314 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2315 if (TEST_EQ_4V(texUnit
->EyePlaneR
, tmp
))
2317 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2318 COPY_4FV(texUnit
->EyePlaneR
, tmp
);
2321 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2326 if (pname
==GL_TEXTURE_GEN_MODE
) {
2327 GLenum mode
= (GLenum
) (GLint
) *params
;
2330 case GL_OBJECT_LINEAR
:
2331 bitq
= TEXGEN_OBJ_LINEAR
;
2334 bitq
= TEXGEN_EYE_LINEAR
;
2337 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
2340 if (texUnit
->GenModeQ
== mode
)
2342 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2343 texUnit
->GenModeQ
= mode
;
2344 texUnit
->_GenBitQ
= bitq
;
2346 else if (pname
==GL_OBJECT_PLANE
) {
2347 if (TEST_EQ_4V(texUnit
->ObjectPlaneQ
, params
))
2349 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2350 COPY_4FV(texUnit
->ObjectPlaneQ
, params
);
2352 else if (pname
==GL_EYE_PLANE
) {
2354 /* Transform plane equation by the inverse modelview matrix */
2355 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
2356 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
2358 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
2359 if (TEST_EQ_4V(texUnit
->EyePlaneQ
, tmp
))
2361 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2362 COPY_4FV(texUnit
->EyePlaneQ
, tmp
);
2365 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
2370 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
2374 if (ctx
->Driver
.TexGen
)
2375 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
2380 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
2383 p
[0] = (GLfloat
) params
[0];
2384 if (pname
== GL_TEXTURE_GEN_MODE
) {
2385 p
[1] = p
[2] = p
[3] = 0.0F
;
2388 p
[1] = (GLfloat
) params
[1];
2389 p
[2] = (GLfloat
) params
[2];
2390 p
[3] = (GLfloat
) params
[3];
2392 _mesa_TexGenfv(coord
, pname
, p
);
2397 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
2399 GLfloat p
= (GLfloat
) param
;
2400 _mesa_TexGenfv( coord
, pname
, &p
);
2405 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
2408 p
[0] = (GLfloat
) params
[0];
2409 if (pname
== GL_TEXTURE_GEN_MODE
) {
2410 p
[1] = p
[2] = p
[3] = 0.0F
;
2413 p
[1] = (GLfloat
) params
[1];
2414 p
[2] = (GLfloat
) params
[2];
2415 p
[3] = (GLfloat
) params
[3];
2417 _mesa_TexGenfv( coord
, pname
, p
);
2422 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
2424 _mesa_TexGenfv(coord
, pname
, ¶m
);
2429 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
2431 _mesa_TexGeniv( coord
, pname
, ¶m
);
2437 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
2439 const struct gl_texture_unit
*texUnit
;
2440 GET_CURRENT_CONTEXT(ctx
);
2441 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2443 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2444 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGendv(current unit)");
2448 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2452 if (pname
==GL_TEXTURE_GEN_MODE
) {
2453 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
2455 else if (pname
==GL_OBJECT_PLANE
) {
2456 COPY_4V( params
, texUnit
->ObjectPlaneS
);
2458 else if (pname
==GL_EYE_PLANE
) {
2459 COPY_4V( params
, texUnit
->EyePlaneS
);
2462 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2467 if (pname
==GL_TEXTURE_GEN_MODE
) {
2468 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
2470 else if (pname
==GL_OBJECT_PLANE
) {
2471 COPY_4V( params
, texUnit
->ObjectPlaneT
);
2473 else if (pname
==GL_EYE_PLANE
) {
2474 COPY_4V( params
, texUnit
->EyePlaneT
);
2477 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2482 if (pname
==GL_TEXTURE_GEN_MODE
) {
2483 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
2485 else if (pname
==GL_OBJECT_PLANE
) {
2486 COPY_4V( params
, texUnit
->ObjectPlaneR
);
2488 else if (pname
==GL_EYE_PLANE
) {
2489 COPY_4V( params
, texUnit
->EyePlaneR
);
2492 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2497 if (pname
==GL_TEXTURE_GEN_MODE
) {
2498 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
2500 else if (pname
==GL_OBJECT_PLANE
) {
2501 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
2503 else if (pname
==GL_EYE_PLANE
) {
2504 COPY_4V( params
, texUnit
->EyePlaneQ
);
2507 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
2512 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
2520 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
2522 const struct gl_texture_unit
*texUnit
;
2523 GET_CURRENT_CONTEXT(ctx
);
2524 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2526 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2527 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGenfv(current unit)");
2531 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2535 if (pname
==GL_TEXTURE_GEN_MODE
) {
2536 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
2538 else if (pname
==GL_OBJECT_PLANE
) {
2539 COPY_4V( params
, texUnit
->ObjectPlaneS
);
2541 else if (pname
==GL_EYE_PLANE
) {
2542 COPY_4V( params
, texUnit
->EyePlaneS
);
2545 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2550 if (pname
==GL_TEXTURE_GEN_MODE
) {
2551 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
2553 else if (pname
==GL_OBJECT_PLANE
) {
2554 COPY_4V( params
, texUnit
->ObjectPlaneT
);
2556 else if (pname
==GL_EYE_PLANE
) {
2557 COPY_4V( params
, texUnit
->EyePlaneT
);
2560 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2565 if (pname
==GL_TEXTURE_GEN_MODE
) {
2566 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
2568 else if (pname
==GL_OBJECT_PLANE
) {
2569 COPY_4V( params
, texUnit
->ObjectPlaneR
);
2571 else if (pname
==GL_EYE_PLANE
) {
2572 COPY_4V( params
, texUnit
->EyePlaneR
);
2575 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2580 if (pname
==GL_TEXTURE_GEN_MODE
) {
2581 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
2583 else if (pname
==GL_OBJECT_PLANE
) {
2584 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
2586 else if (pname
==GL_EYE_PLANE
) {
2587 COPY_4V( params
, texUnit
->EyePlaneQ
);
2590 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
2595 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
2603 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
2605 const struct gl_texture_unit
*texUnit
;
2606 GET_CURRENT_CONTEXT(ctx
);
2607 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2609 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2610 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGeniv(current unit)");
2614 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2618 if (pname
==GL_TEXTURE_GEN_MODE
) {
2619 params
[0] = texUnit
->GenModeS
;
2621 else if (pname
==GL_OBJECT_PLANE
) {
2622 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
2623 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
2624 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
2625 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
2627 else if (pname
==GL_EYE_PLANE
) {
2628 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
2629 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
2630 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
2631 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
2634 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2639 if (pname
==GL_TEXTURE_GEN_MODE
) {
2640 params
[0] = texUnit
->GenModeT
;
2642 else if (pname
==GL_OBJECT_PLANE
) {
2643 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
2644 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
2645 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
2646 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
2648 else if (pname
==GL_EYE_PLANE
) {
2649 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
2650 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
2651 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
2652 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
2655 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2660 if (pname
==GL_TEXTURE_GEN_MODE
) {
2661 params
[0] = texUnit
->GenModeR
;
2663 else if (pname
==GL_OBJECT_PLANE
) {
2664 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
2665 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
2666 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
2667 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
2669 else if (pname
==GL_EYE_PLANE
) {
2670 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
2671 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
2672 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
2673 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
2676 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2681 if (pname
==GL_TEXTURE_GEN_MODE
) {
2682 params
[0] = texUnit
->GenModeQ
;
2684 else if (pname
==GL_OBJECT_PLANE
) {
2685 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
2686 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
2687 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
2688 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
2690 else if (pname
==GL_EYE_PLANE
) {
2691 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
2692 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
2693 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
2694 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
2697 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
2702 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );
2709 /* GL_ARB_multitexture */
2711 _mesa_ActiveTextureARB(GLenum texture
)
2713 GET_CURRENT_CONTEXT(ctx
);
2714 const GLuint texUnit
= texture
- GL_TEXTURE0
;
2715 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2717 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2718 _mesa_debug(ctx
, "glActiveTexture %s\n",
2719 _mesa_lookup_enum_by_nr(texture
));
2721 /* XXX error-check against max(coordunits, imageunits) */
2722 if (texUnit
>= ctx
->Const
.MaxTextureUnits
) {
2723 _mesa_error(ctx
, GL_INVALID_ENUM
, "glActiveTexture(texture)");
2727 if (ctx
->Texture
.CurrentUnit
== texUnit
)
2730 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
2732 ctx
->Texture
.CurrentUnit
= texUnit
;
2733 if (ctx
->Transform
.MatrixMode
== GL_TEXTURE
) {
2734 /* update current stack pointer */
2735 ctx
->CurrentStack
= &ctx
->TextureMatrixStack
[texUnit
];
2738 if (ctx
->Driver
.ActiveTexture
) {
2739 (*ctx
->Driver
.ActiveTexture
)( ctx
, (GLuint
) texUnit
);
2744 /* GL_ARB_multitexture */
2746 _mesa_ClientActiveTextureARB(GLenum texture
)
2748 GET_CURRENT_CONTEXT(ctx
);
2749 GLuint texUnit
= texture
- GL_TEXTURE0
;
2750 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2752 if (texUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
2753 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClientActiveTexture(texture)");
2757 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
2758 ctx
->Array
.ActiveTexture
= texUnit
;
2763 /**********************************************************************/
2764 /***** State management *****/
2765 /**********************************************************************/
2769 * \note This routine refers to derived texture attribute values to
2770 * compute the ENABLE_TEXMAT flags, but is only called on
2771 * _NEW_TEXTURE_MATRIX. On changes to _NEW_TEXTURE, the ENABLE_TEXMAT
2772 * flags are updated by _mesa_update_textures(), below.
2774 * \param ctx GL context.
2777 update_texture_matrices( GLcontext
*ctx
)
2781 ctx
->Texture
._TexMatEnabled
= 0;
2783 for (i
=0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
2784 if (_math_matrix_is_dirty(ctx
->TextureMatrixStack
[i
].Top
)) {
2785 _math_matrix_analyse( ctx
->TextureMatrixStack
[i
].Top
);
2787 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
&&
2788 ctx
->TextureMatrixStack
[i
].Top
->type
!= MATRIX_IDENTITY
)
2789 ctx
->Texture
._TexMatEnabled
|= ENABLE_TEXMAT(i
);
2791 if (ctx
->Driver
.TextureMatrix
)
2792 ctx
->Driver
.TextureMatrix( ctx
, i
, ctx
->TextureMatrixStack
[i
].Top
);
2799 * Update texture object's _Function field. We need to do this
2800 * whenever any of the texture object's shadow-related fields change
2801 * or when we start/stop using a fragment program.
2803 * This function could be expanded someday to update additional per-object
2804 * fields that depend on assorted state changes.
2807 update_texture_compare_function(GLcontext
*ctx
,
2808 struct gl_texture_object
*tObj
)
2810 /* XXX temporarily disable this test since it breaks the GLSL
2811 * shadow2D(), etc. functions.
2813 if (0 /*ctx->FragmentProgram._Current*/) {
2814 /* Texel/coordinate comparison is ignored for programs.
2815 * See GL_ARB_fragment_program/shader spec for details.
2817 tObj
->_Function
= GL_NONE
;
2819 else if (tObj
->CompareFlag
) {
2820 /* GL_SGIX_shadow */
2821 if (tObj
->CompareOperator
== GL_TEXTURE_LEQUAL_R_SGIX
) {
2822 tObj
->_Function
= GL_LEQUAL
;
2825 ASSERT(tObj
->CompareOperator
== GL_TEXTURE_GEQUAL_R_SGIX
);
2826 tObj
->_Function
= GL_GEQUAL
;
2829 else if (tObj
->CompareMode
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
2831 tObj
->_Function
= tObj
->CompareFunc
;
2834 tObj
->_Function
= GL_NONE
; /* pass depth through as grayscale */
2840 * Helper function for determining which texture object (1D, 2D, cube, etc)
2841 * should actually be used.
2844 texture_override(GLcontext
*ctx
,
2845 struct gl_texture_unit
*texUnit
, GLbitfield enableBits
,
2846 struct gl_texture_object
*texObj
, GLuint textureBit
)
2848 if (!texUnit
->_ReallyEnabled
&& (enableBits
& textureBit
)) {
2849 if (!texObj
->_Complete
) {
2850 _mesa_test_texobj_completeness(ctx
, texObj
);
2852 if (texObj
->_Complete
) {
2853 texUnit
->_ReallyEnabled
= textureBit
;
2854 texUnit
->_Current
= texObj
;
2855 update_texture_compare_function(ctx
, texObj
);
2862 * \note This routine refers to derived texture matrix values to
2863 * compute the ENABLE_TEXMAT flags, but is only called on
2864 * _NEW_TEXTURE. On changes to _NEW_TEXTURE_MATRIX, the ENABLE_TEXMAT
2865 * flags are updated by _mesa_update_texture_matrices, above.
2867 * \param ctx GL context.
2870 update_texture_state( GLcontext
*ctx
)
2873 struct gl_fragment_program
*fprog
= NULL
;
2874 struct gl_vertex_program
*vprog
= NULL
;
2876 if (ctx
->Shader
.CurrentProgram
&&
2877 ctx
->Shader
.CurrentProgram
->LinkStatus
) {
2878 fprog
= ctx
->Shader
.CurrentProgram
->FragmentProgram
;
2879 vprog
= ctx
->Shader
.CurrentProgram
->VertexProgram
;
2882 if (ctx
->FragmentProgram
._Enabled
) {
2883 fprog
= ctx
->FragmentProgram
.Current
;
2885 if (ctx
->VertexProgram
._Enabled
) {
2886 /* XXX enable this if/when non-shader vertex programs get
2888 vprog = ctx->VertexProgram.Current;
2893 ctx
->NewState
|= _NEW_TEXTURE
; /* TODO: only set this if there are
2897 ctx
->Texture
._EnabledUnits
= 0;
2898 ctx
->Texture
._GenFlags
= 0;
2899 ctx
->Texture
._TexMatEnabled
= 0;
2900 ctx
->Texture
._TexGenEnabled
= 0;
2903 * Update texture unit state.
2905 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
2906 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
2907 GLbitfield enableBits
;
2909 texUnit
->_Current
= NULL
;
2910 texUnit
->_ReallyEnabled
= 0;
2911 texUnit
->_GenFlags
= 0;
2913 /* Get the bitmask of texture enables.
2914 * enableBits will be a mask of the TEXTURE_*_BIT flags indicating
2915 * which texture targets are enabled (fixed function) or referenced
2916 * by a fragment shader/program. When multiple flags are set, we'll
2917 * settle on the one with highest priority (see texture_override below).
2919 if (fprog
|| vprog
) {
2922 enableBits
|= fprog
->Base
.TexturesUsed
[unit
];
2924 enableBits
|= vprog
->Base
.TexturesUsed
[unit
];
2927 if (!texUnit
->Enabled
)
2929 enableBits
= texUnit
->Enabled
;
2932 /* Look for the highest-priority texture target that's enabled and
2933 * complete. That's the one we'll use for texturing. If we're using
2934 * a fragment program we're guaranteed that bitcount(enabledBits) <= 1.
2936 texture_override(ctx
, texUnit
, enableBits
,
2937 texUnit
->Current2DArray
, TEXTURE_2D_ARRAY_BIT
);
2938 texture_override(ctx
, texUnit
, enableBits
,
2939 texUnit
->Current1DArray
, TEXTURE_1D_ARRAY_BIT
);
2940 texture_override(ctx
, texUnit
, enableBits
,
2941 texUnit
->CurrentCubeMap
, TEXTURE_CUBE_BIT
);
2942 texture_override(ctx
, texUnit
, enableBits
,
2943 texUnit
->Current3D
, TEXTURE_3D_BIT
);
2944 texture_override(ctx
, texUnit
, enableBits
,
2945 texUnit
->CurrentRect
, TEXTURE_RECT_BIT
);
2946 texture_override(ctx
, texUnit
, enableBits
,
2947 texUnit
->Current2D
, TEXTURE_2D_BIT
);
2948 texture_override(ctx
, texUnit
, enableBits
,
2949 texUnit
->Current1D
, TEXTURE_1D_BIT
);
2951 if (!texUnit
->_ReallyEnabled
) {
2955 if (texUnit
->_ReallyEnabled
)
2956 ctx
->Texture
._EnabledUnits
|= (1 << unit
);
2958 if (texUnit
->EnvMode
== GL_COMBINE
) {
2959 texUnit
->_CurrentCombine
= & texUnit
->Combine
;
2962 const struct gl_texture_object
*texObj
= texUnit
->_Current
;
2963 GLenum format
= texObj
->Image
[0][texObj
->BaseLevel
]->_BaseFormat
;
2964 if (format
== GL_COLOR_INDEX
) {
2965 format
= GL_RGBA
; /* a bit of a hack */
2967 else if (format
== GL_DEPTH_COMPONENT
2968 || format
== GL_DEPTH_STENCIL_EXT
) {
2969 format
= texObj
->DepthMode
;
2971 calculate_derived_texenv(&texUnit
->_EnvMode
, texUnit
->EnvMode
, format
);
2972 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
2975 switch (texUnit
->_CurrentCombine
->ModeRGB
) {
2977 texUnit
->_CurrentCombine
->_NumArgsRGB
= 1;
2985 case GL_DOT3_RGB_EXT
:
2986 case GL_DOT3_RGBA_EXT
:
2987 texUnit
->_CurrentCombine
->_NumArgsRGB
= 2;
2989 case GL_INTERPOLATE
:
2990 case GL_MODULATE_ADD_ATI
:
2991 case GL_MODULATE_SIGNED_ADD_ATI
:
2992 case GL_MODULATE_SUBTRACT_ATI
:
2993 texUnit
->_CurrentCombine
->_NumArgsRGB
= 3;
2996 texUnit
->_CurrentCombine
->_NumArgsRGB
= 0;
2997 _mesa_problem(ctx
, "invalid RGB combine mode in update_texture_state");
3001 switch (texUnit
->_CurrentCombine
->ModeA
) {
3003 texUnit
->_CurrentCombine
->_NumArgsA
= 1;
3009 texUnit
->_CurrentCombine
->_NumArgsA
= 2;
3011 case GL_INTERPOLATE
:
3012 case GL_MODULATE_ADD_ATI
:
3013 case GL_MODULATE_SIGNED_ADD_ATI
:
3014 case GL_MODULATE_SUBTRACT_ATI
:
3015 texUnit
->_CurrentCombine
->_NumArgsA
= 3;
3018 texUnit
->_CurrentCombine
->_NumArgsA
= 0;
3019 _mesa_problem(ctx
, "invalid Alpha combine mode in update_texture_state");
3023 if (texUnit
->TexGenEnabled
) {
3024 if (texUnit
->TexGenEnabled
& S_BIT
) {
3025 texUnit
->_GenFlags
|= texUnit
->_GenBitS
;
3027 if (texUnit
->TexGenEnabled
& T_BIT
) {
3028 texUnit
->_GenFlags
|= texUnit
->_GenBitT
;
3030 if (texUnit
->TexGenEnabled
& Q_BIT
) {
3031 texUnit
->_GenFlags
|= texUnit
->_GenBitQ
;
3033 if (texUnit
->TexGenEnabled
& R_BIT
) {
3034 texUnit
->_GenFlags
|= texUnit
->_GenBitR
;
3037 ctx
->Texture
._TexGenEnabled
|= ENABLE_TEXGEN(unit
);
3038 ctx
->Texture
._GenFlags
|= texUnit
->_GenFlags
;
3041 if (ctx
->TextureMatrixStack
[unit
].Top
->type
!= MATRIX_IDENTITY
)
3042 ctx
->Texture
._TexMatEnabled
|= ENABLE_TEXMAT(unit
);
3045 /* Determine which texture coordinate sets are actually needed */
3047 const GLuint coordMask
= (1 << MAX_TEXTURE_COORD_UNITS
) - 1;
3048 ctx
->Texture
._EnabledCoordUnits
3049 = (fprog
->Base
.InputsRead
>> FRAG_ATTRIB_TEX0
) & coordMask
;
3052 ctx
->Texture
._EnabledCoordUnits
= ctx
->Texture
._EnabledUnits
;
3058 * Update texture-related derived state.
3061 _mesa_update_texture( GLcontext
*ctx
, GLuint new_state
)
3063 if (new_state
& _NEW_TEXTURE_MATRIX
)
3064 update_texture_matrices( ctx
);
3066 if (new_state
& (_NEW_TEXTURE
| _NEW_PROGRAM
))
3067 update_texture_state( ctx
);
3071 /**********************************************************************/
3072 /***** Initialization *****/
3073 /**********************************************************************/
3076 * Allocate the proxy textures for the given context.
3078 * \param ctx the context to allocate proxies for.
3080 * \return GL_TRUE on success, or GL_FALSE on failure
3082 * If run out of memory part way through the allocations, clean up and return
3086 alloc_proxy_textures( GLcontext
*ctx
)
3088 ctx
->Texture
.Proxy1D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_1D
);
3089 if (!ctx
->Texture
.Proxy1D
)
3092 ctx
->Texture
.Proxy2D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_2D
);
3093 if (!ctx
->Texture
.Proxy2D
)
3096 ctx
->Texture
.Proxy3D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_3D
);
3097 if (!ctx
->Texture
.Proxy3D
)
3100 ctx
->Texture
.ProxyCubeMap
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_CUBE_MAP_ARB
);
3101 if (!ctx
->Texture
.ProxyCubeMap
)
3104 ctx
->Texture
.ProxyRect
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_RECTANGLE_NV
);
3105 if (!ctx
->Texture
.ProxyRect
)
3108 ctx
->Texture
.Proxy1DArray
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_1D_ARRAY_EXT
);
3109 if (!ctx
->Texture
.Proxy1DArray
)
3112 ctx
->Texture
.Proxy2DArray
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_2D_ARRAY_EXT
);
3113 if (!ctx
->Texture
.Proxy2DArray
)
3119 if (ctx
->Texture
.Proxy1D
)
3120 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1D
);
3121 if (ctx
->Texture
.Proxy2D
)
3122 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2D
);
3123 if (ctx
->Texture
.Proxy3D
)
3124 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy3D
);
3125 if (ctx
->Texture
.ProxyCubeMap
)
3126 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyCubeMap
);
3127 if (ctx
->Texture
.ProxyRect
)
3128 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyRect
);
3129 if (ctx
->Texture
.Proxy1DArray
)
3130 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1DArray
);
3131 if (ctx
->Texture
.Proxy2DArray
)
3132 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2DArray
);
3138 * Initialize a texture unit.
3140 * \param ctx GL context.
3141 * \param unit texture unit number to be initialized.
3144 init_texture_unit( GLcontext
*ctx
, GLuint unit
)
3146 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
3148 texUnit
->EnvMode
= GL_MODULATE
;
3149 ASSIGN_4V( texUnit
->EnvColor
, 0.0, 0.0, 0.0, 0.0 );
3151 texUnit
->Combine
= default_combine_state
;
3152 texUnit
->_EnvMode
= default_combine_state
;
3153 texUnit
->_CurrentCombine
= & texUnit
->_EnvMode
;
3155 texUnit
->TexGenEnabled
= 0;
3156 texUnit
->GenModeS
= GL_EYE_LINEAR
;
3157 texUnit
->GenModeT
= GL_EYE_LINEAR
;
3158 texUnit
->GenModeR
= GL_EYE_LINEAR
;
3159 texUnit
->GenModeQ
= GL_EYE_LINEAR
;
3160 texUnit
->_GenBitS
= TEXGEN_EYE_LINEAR
;
3161 texUnit
->_GenBitT
= TEXGEN_EYE_LINEAR
;
3162 texUnit
->_GenBitR
= TEXGEN_EYE_LINEAR
;
3163 texUnit
->_GenBitQ
= TEXGEN_EYE_LINEAR
;
3165 /* Yes, these plane coefficients are correct! */
3166 ASSIGN_4V( texUnit
->ObjectPlaneS
, 1.0, 0.0, 0.0, 0.0 );
3167 ASSIGN_4V( texUnit
->ObjectPlaneT
, 0.0, 1.0, 0.0, 0.0 );
3168 ASSIGN_4V( texUnit
->ObjectPlaneR
, 0.0, 0.0, 0.0, 0.0 );
3169 ASSIGN_4V( texUnit
->ObjectPlaneQ
, 0.0, 0.0, 0.0, 0.0 );
3170 ASSIGN_4V( texUnit
->EyePlaneS
, 1.0, 0.0, 0.0, 0.0 );
3171 ASSIGN_4V( texUnit
->EyePlaneT
, 0.0, 1.0, 0.0, 0.0 );
3172 ASSIGN_4V( texUnit
->EyePlaneR
, 0.0, 0.0, 0.0, 0.0 );
3173 ASSIGN_4V( texUnit
->EyePlaneQ
, 0.0, 0.0, 0.0, 0.0 );
3175 texUnit
->Current1D
= ctx
->Shared
->Default1D
;
3176 texUnit
->Current2D
= ctx
->Shared
->Default2D
;
3177 texUnit
->Current3D
= ctx
->Shared
->Default3D
;
3178 texUnit
->CurrentCubeMap
= ctx
->Shared
->DefaultCubeMap
;
3179 texUnit
->CurrentRect
= ctx
->Shared
->DefaultRect
;
3180 texUnit
->Current1DArray
= ctx
->Shared
->Default1DArray
;
3181 texUnit
->Current2DArray
= ctx
->Shared
->Default2DArray
;
3186 * Initialize texture state for the given context.
3189 _mesa_init_texture(GLcontext
*ctx
)
3193 assert(MAX_TEXTURE_LEVELS
>= MAX_3D_TEXTURE_LEVELS
);
3194 assert(MAX_TEXTURE_LEVELS
>= MAX_CUBE_TEXTURE_LEVELS
);
3196 /* Effectively bind the default textures to all texture units */
3197 ctx
->Shared
->Default1D
->RefCount
+= MAX_TEXTURE_UNITS
;
3198 ctx
->Shared
->Default2D
->RefCount
+= MAX_TEXTURE_UNITS
;
3199 ctx
->Shared
->Default3D
->RefCount
+= MAX_TEXTURE_UNITS
;
3200 ctx
->Shared
->DefaultCubeMap
->RefCount
+= MAX_TEXTURE_UNITS
;
3201 ctx
->Shared
->DefaultRect
->RefCount
+= MAX_TEXTURE_UNITS
;
3202 ctx
->Shared
->Default1DArray
->RefCount
+= MAX_TEXTURE_UNITS
;
3203 ctx
->Shared
->Default2DArray
->RefCount
+= MAX_TEXTURE_UNITS
;
3206 ctx
->Texture
.CurrentUnit
= 0; /* multitexture */
3207 ctx
->Texture
._EnabledUnits
= 0;
3208 for (i
=0; i
<MAX_TEXTURE_UNITS
; i
++)
3209 init_texture_unit( ctx
, i
);
3210 ctx
->Texture
.SharedPalette
= GL_FALSE
;
3211 _mesa_init_colortable(&ctx
->Texture
.Palette
);
3213 /* Allocate proxy textures */
3214 if (!alloc_proxy_textures( ctx
))
3222 * Free dynamically-allocted texture data attached to the given context.
3225 _mesa_free_texture_data(GLcontext
*ctx
)
3229 /* Free proxy texture objects */
3230 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1D
);
3231 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2D
);
3232 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy3D
);
3233 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyCubeMap
);
3234 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.ProxyRect
);
3235 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy1DArray
);
3236 (ctx
->Driver
.DeleteTexture
)(ctx
, ctx
->Texture
.Proxy2DArray
);
3238 for (i
= 0; i
< MAX_TEXTURE_IMAGE_UNITS
; i
++)
3239 _mesa_free_colortable_data( &ctx
->Texture
.Unit
[i
].ColorTable
);