mesa: Remove ARB_texture_mirrored_repeat extension enable flag
[mesa.git] / src / mesa / main / texparam.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.5
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 /**
27 * \file texparam.c
28 *
29 * glTexParameter-related functions
30 */
31
32
33 #include "main/glheader.h"
34 #include "main/colormac.h"
35 #include "main/context.h"
36 #include "main/enums.h"
37 #include "main/formats.h"
38 #include "main/macros.h"
39 #include "main/mfeatures.h"
40 #include "main/mtypes.h"
41 #include "main/state.h"
42 #include "main/texcompress.h"
43 #include "main/texparam.h"
44 #include "main/teximage.h"
45 #include "main/texstate.h"
46 #include "program/prog_instruction.h"
47
48
49 /**
50 * Check if a coordinate wrap mode is supported for the texture target.
51 * \return GL_TRUE if legal, GL_FALSE otherwise
52 */
53 static GLboolean
54 validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
55 {
56 const struct gl_extensions * const e = & ctx->Extensions;
57
58 if (wrap == GL_CLAMP || wrap == GL_CLAMP_TO_EDGE ||
59 (wrap == GL_CLAMP_TO_BORDER && e->ARB_texture_border_clamp)) {
60 /* any texture target */
61 return GL_TRUE;
62 }
63 else if (target != GL_TEXTURE_RECTANGLE_NV &&
64 (wrap == GL_REPEAT ||
65 wrap == GL_MIRRORED_REPEAT ||
66 (wrap == GL_MIRROR_CLAMP_EXT &&
67 (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
68 (wrap == GL_MIRROR_CLAMP_TO_EDGE_EXT &&
69 (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
70 (wrap == GL_MIRROR_CLAMP_TO_BORDER_EXT &&
71 (e->EXT_texture_mirror_clamp)))) {
72 /* non-rectangle texture */
73 return GL_TRUE;
74 }
75
76 _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(param=0x%x)", wrap );
77 return GL_FALSE;
78 }
79
80
81 /**
82 * Get current texture object for given target.
83 * Return NULL if any error (and record the error).
84 * Note that this is different from _mesa_select_tex_object() in that proxy
85 * targets are not accepted.
86 * Only the glGetTexLevelParameter() functions accept proxy targets.
87 */
88 static struct gl_texture_object *
89 get_texobj(struct gl_context *ctx, GLenum target, GLboolean get)
90 {
91 struct gl_texture_unit *texUnit;
92
93 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
94 _mesa_error(ctx, GL_INVALID_OPERATION,
95 "gl%sTexParameter(current unit)", get ? "Get" : "");
96 return NULL;
97 }
98
99 texUnit = _mesa_get_current_tex_unit(ctx);
100
101 switch (target) {
102 case GL_TEXTURE_1D:
103 return texUnit->CurrentTex[TEXTURE_1D_INDEX];
104 case GL_TEXTURE_2D:
105 return texUnit->CurrentTex[TEXTURE_2D_INDEX];
106 case GL_TEXTURE_3D:
107 return texUnit->CurrentTex[TEXTURE_3D_INDEX];
108 case GL_TEXTURE_CUBE_MAP:
109 if (ctx->Extensions.ARB_texture_cube_map) {
110 return texUnit->CurrentTex[TEXTURE_CUBE_INDEX];
111 }
112 break;
113 case GL_TEXTURE_RECTANGLE_NV:
114 if (ctx->Extensions.NV_texture_rectangle) {
115 return texUnit->CurrentTex[TEXTURE_RECT_INDEX];
116 }
117 break;
118 case GL_TEXTURE_1D_ARRAY_EXT:
119 if (ctx->Extensions.MESA_texture_array ||
120 ctx->Extensions.EXT_texture_array) {
121 return texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX];
122 }
123 break;
124 case GL_TEXTURE_2D_ARRAY_EXT:
125 if (ctx->Extensions.MESA_texture_array ||
126 ctx->Extensions.EXT_texture_array) {
127 return texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX];
128 }
129 break;
130 default:
131 ;
132 }
133
134 _mesa_error(ctx, GL_INVALID_ENUM,
135 "gl%sTexParameter(target)", get ? "Get" : "");
136 return NULL;
137 }
138
139
140 /**
141 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
142 * \return -1 if error.
143 */
144 static GLint
145 comp_to_swizzle(GLenum comp)
146 {
147 switch (comp) {
148 case GL_RED:
149 return SWIZZLE_X;
150 case GL_GREEN:
151 return SWIZZLE_Y;
152 case GL_BLUE:
153 return SWIZZLE_Z;
154 case GL_ALPHA:
155 return SWIZZLE_W;
156 case GL_ZERO:
157 return SWIZZLE_ZERO;
158 case GL_ONE:
159 return SWIZZLE_ONE;
160 default:
161 return -1;
162 }
163 }
164
165
166 static void
167 set_swizzle_component(GLuint *swizzle, GLuint comp, GLuint swz)
168 {
169 ASSERT(comp < 4);
170 ASSERT(swz <= SWIZZLE_NIL);
171 {
172 GLuint mask = 0x7 << (3 * comp);
173 GLuint s = (*swizzle & ~mask) | (swz << (3 * comp));
174 *swizzle = s;
175 }
176 }
177
178
179 /**
180 * This is called just prior to changing any texture object state which
181 * will not effect texture completeness.
182 */
183 static INLINE void
184 flush(struct gl_context *ctx)
185 {
186 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
187 }
188
189
190 /**
191 * This is called just prior to changing any texture object state which
192 * can effect texture completeness (texture base level, max level,
193 * minification filter).
194 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
195 * state flag and then mark the texture object as 'incomplete' so that any
196 * per-texture derived state gets recomputed.
197 */
198 static INLINE void
199 incomplete(struct gl_context *ctx, struct gl_texture_object *texObj)
200 {
201 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
202 texObj->_Complete = GL_FALSE;
203 }
204
205
206 /**
207 * Set an integer-valued texture parameter
208 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
209 */
210 static GLboolean
211 set_tex_parameteri(struct gl_context *ctx,
212 struct gl_texture_object *texObj,
213 GLenum pname, const GLint *params)
214 {
215 switch (pname) {
216 case GL_TEXTURE_MIN_FILTER:
217 if (texObj->Sampler.MinFilter == params[0])
218 return GL_FALSE;
219 switch (params[0]) {
220 case GL_NEAREST:
221 case GL_LINEAR:
222 incomplete(ctx, texObj);
223 texObj->Sampler.MinFilter = params[0];
224 return GL_TRUE;
225 case GL_NEAREST_MIPMAP_NEAREST:
226 case GL_LINEAR_MIPMAP_NEAREST:
227 case GL_NEAREST_MIPMAP_LINEAR:
228 case GL_LINEAR_MIPMAP_LINEAR:
229 if (texObj->Target != GL_TEXTURE_RECTANGLE_NV) {
230 incomplete(ctx, texObj);
231 texObj->Sampler.MinFilter = params[0];
232 return GL_TRUE;
233 }
234 /* fall-through */
235 default:
236 goto invalid_param;
237 }
238 return GL_FALSE;
239
240 case GL_TEXTURE_MAG_FILTER:
241 if (texObj->Sampler.MagFilter == params[0])
242 return GL_FALSE;
243 switch (params[0]) {
244 case GL_NEAREST:
245 case GL_LINEAR:
246 flush(ctx); /* does not effect completeness */
247 texObj->Sampler.MagFilter = params[0];
248 return GL_TRUE;
249 default:
250 goto invalid_param;
251 }
252 return GL_FALSE;
253
254 case GL_TEXTURE_WRAP_S:
255 if (texObj->Sampler.WrapS == params[0])
256 return GL_FALSE;
257 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
258 flush(ctx);
259 texObj->Sampler.WrapS = params[0];
260 return GL_TRUE;
261 }
262 return GL_FALSE;
263
264 case GL_TEXTURE_WRAP_T:
265 if (texObj->Sampler.WrapT == params[0])
266 return GL_FALSE;
267 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
268 flush(ctx);
269 texObj->Sampler.WrapT = params[0];
270 return GL_TRUE;
271 }
272 return GL_FALSE;
273
274 case GL_TEXTURE_WRAP_R:
275 if (texObj->Sampler.WrapR == params[0])
276 return GL_FALSE;
277 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
278 flush(ctx);
279 texObj->Sampler.WrapR = params[0];
280 return GL_TRUE;
281 }
282 return GL_FALSE;
283
284 case GL_TEXTURE_BASE_LEVEL:
285 if (texObj->BaseLevel == params[0])
286 return GL_FALSE;
287 if (params[0] < 0 ||
288 (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] != 0)) {
289 _mesa_error(ctx, GL_INVALID_VALUE,
290 "glTexParameter(param=%d)", params[0]);
291 return GL_FALSE;
292 }
293 incomplete(ctx, texObj);
294 texObj->BaseLevel = params[0];
295 return GL_TRUE;
296
297 case GL_TEXTURE_MAX_LEVEL:
298 if (texObj->MaxLevel == params[0])
299 return GL_FALSE;
300 if (params[0] < 0 || texObj->Target == GL_TEXTURE_RECTANGLE_ARB) {
301 _mesa_error(ctx, GL_INVALID_OPERATION,
302 "glTexParameter(param=%d)", params[0]);
303 return GL_FALSE;
304 }
305 incomplete(ctx, texObj);
306 texObj->MaxLevel = params[0];
307 return GL_TRUE;
308
309 case GL_GENERATE_MIPMAP_SGIS:
310 if (texObj->GenerateMipmap != params[0]) {
311 /* no flush() */
312 texObj->GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
313 return GL_TRUE;
314 }
315 return GL_FALSE;
316
317 case GL_TEXTURE_COMPARE_MODE_ARB:
318 if (ctx->Extensions.ARB_shadow) {
319 if (texObj->Sampler.CompareMode == params[0])
320 return GL_FALSE;
321 if (params[0] == GL_NONE ||
322 params[0] == GL_COMPARE_R_TO_TEXTURE_ARB) {
323 flush(ctx);
324 texObj->Sampler.CompareMode = params[0];
325 return GL_TRUE;
326 }
327 goto invalid_param;
328 }
329 goto invalid_pname;
330
331 case GL_TEXTURE_COMPARE_FUNC_ARB:
332 if (ctx->Extensions.ARB_shadow) {
333 if (texObj->Sampler.CompareFunc == params[0])
334 return GL_FALSE;
335 switch (params[0]) {
336 case GL_LEQUAL:
337 case GL_GEQUAL:
338 flush(ctx);
339 texObj->Sampler.CompareFunc = params[0];
340 return GL_TRUE;
341 case GL_EQUAL:
342 case GL_NOTEQUAL:
343 case GL_LESS:
344 case GL_GREATER:
345 case GL_ALWAYS:
346 case GL_NEVER:
347 if (ctx->Extensions.EXT_shadow_funcs) {
348 flush(ctx);
349 texObj->Sampler.CompareFunc = params[0];
350 return GL_TRUE;
351 }
352 /* fall-through */
353 default:
354 goto invalid_param;
355 }
356 }
357 goto invalid_pname;
358
359 case GL_DEPTH_TEXTURE_MODE_ARB:
360 if (ctx->Extensions.ARB_depth_texture) {
361 if (texObj->Sampler.DepthMode == params[0])
362 return GL_FALSE;
363 if (params[0] == GL_LUMINANCE ||
364 params[0] == GL_INTENSITY ||
365 params[0] == GL_ALPHA ||
366 (ctx->Extensions.ARB_texture_rg && params[0] == GL_RED)) {
367 flush(ctx);
368 texObj->Sampler.DepthMode = params[0];
369 return GL_TRUE;
370 }
371 goto invalid_param;
372 }
373 goto invalid_pname;
374
375 #if FEATURE_OES_draw_texture
376 case GL_TEXTURE_CROP_RECT_OES:
377 texObj->CropRect[0] = params[0];
378 texObj->CropRect[1] = params[1];
379 texObj->CropRect[2] = params[2];
380 texObj->CropRect[3] = params[3];
381 return GL_TRUE;
382 #endif
383
384 case GL_TEXTURE_SWIZZLE_R_EXT:
385 case GL_TEXTURE_SWIZZLE_G_EXT:
386 case GL_TEXTURE_SWIZZLE_B_EXT:
387 case GL_TEXTURE_SWIZZLE_A_EXT:
388 if (ctx->Extensions.EXT_texture_swizzle) {
389 const GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
390 const GLint swz = comp_to_swizzle(params[0]);
391 if (swz < 0) {
392 _mesa_error(ctx, GL_INVALID_OPERATION,
393 "glTexParameter(swizzle 0x%x)", params[0]);
394 return GL_FALSE;
395 }
396 ASSERT(comp < 4);
397 if (swz >= 0) {
398 flush(ctx);
399 texObj->Swizzle[comp] = params[0];
400 set_swizzle_component(&texObj->_Swizzle, comp, swz);
401 return GL_TRUE;
402 }
403 }
404 goto invalid_pname;
405
406 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
407 if (ctx->Extensions.EXT_texture_swizzle) {
408 GLuint comp;
409 flush(ctx);
410 for (comp = 0; comp < 4; comp++) {
411 const GLint swz = comp_to_swizzle(params[comp]);
412 if (swz >= 0) {
413 texObj->Swizzle[comp] = params[comp];
414 set_swizzle_component(&texObj->_Swizzle, comp, swz);
415 }
416 else {
417 _mesa_error(ctx, GL_INVALID_OPERATION,
418 "glTexParameter(swizzle 0x%x)", params[comp]);
419 return GL_FALSE;
420 }
421 }
422 return GL_TRUE;
423 }
424 goto invalid_pname;
425
426 case GL_TEXTURE_SRGB_DECODE_EXT:
427 if (ctx->Extensions.EXT_texture_sRGB_decode) {
428 GLenum decode = params[0];
429 if (decode == GL_DECODE_EXT || decode == GL_SKIP_DECODE_EXT) {
430 if (texObj->Sampler.sRGBDecode != decode) {
431 flush(ctx);
432 texObj->Sampler.sRGBDecode = decode;
433 }
434 return GL_TRUE;
435 }
436 }
437 goto invalid_pname;
438
439 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
440 if (ctx->Extensions.AMD_seamless_cubemap_per_texture) {
441 GLenum param = params[0];
442 if (param != GL_TRUE && param != GL_FALSE) {
443 goto invalid_param;
444 }
445 if (param != texObj->Sampler.CubeMapSeamless) {
446 flush(ctx);
447 texObj->Sampler.CubeMapSeamless = param;
448 }
449 return GL_TRUE;
450 }
451 goto invalid_pname;
452
453 default:
454 goto invalid_pname;
455 }
456
457 invalid_pname:
458 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=%s)",
459 _mesa_lookup_enum_by_nr(pname));
460 return GL_FALSE;
461
462 invalid_param:
463 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(param=%s)",
464 _mesa_lookup_enum_by_nr(params[0]));
465 return GL_FALSE;
466 }
467
468
469 /**
470 * Set a float-valued texture parameter
471 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
472 */
473 static GLboolean
474 set_tex_parameterf(struct gl_context *ctx,
475 struct gl_texture_object *texObj,
476 GLenum pname, const GLfloat *params)
477 {
478 switch (pname) {
479 case GL_TEXTURE_MIN_LOD:
480 if (texObj->Sampler.MinLod == params[0])
481 return GL_FALSE;
482 flush(ctx);
483 texObj->Sampler.MinLod = params[0];
484 return GL_TRUE;
485
486 case GL_TEXTURE_MAX_LOD:
487 if (texObj->Sampler.MaxLod == params[0])
488 return GL_FALSE;
489 flush(ctx);
490 texObj->Sampler.MaxLod = params[0];
491 return GL_TRUE;
492
493 case GL_TEXTURE_PRIORITY:
494 flush(ctx);
495 texObj->Priority = CLAMP(params[0], 0.0F, 1.0F);
496 return GL_TRUE;
497
498 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
499 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
500 if (texObj->Sampler.MaxAnisotropy == params[0])
501 return GL_FALSE;
502 if (params[0] < 1.0) {
503 _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
504 return GL_FALSE;
505 }
506 flush(ctx);
507 /* clamp to max, that's what NVIDIA does */
508 texObj->Sampler.MaxAnisotropy = MIN2(params[0],
509 ctx->Const.MaxTextureMaxAnisotropy);
510 return GL_TRUE;
511 }
512 else {
513 static GLuint count = 0;
514 if (count++ < 10)
515 _mesa_error(ctx, GL_INVALID_ENUM,
516 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
517 }
518 return GL_FALSE;
519
520 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
521 if (ctx->Extensions.ARB_shadow_ambient) {
522 if (texObj->Sampler.CompareFailValue != params[0]) {
523 flush(ctx);
524 texObj->Sampler.CompareFailValue = CLAMP(params[0], 0.0F, 1.0F);
525 return GL_TRUE;
526 }
527 }
528 else {
529 _mesa_error(ctx, GL_INVALID_ENUM,
530 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
531 }
532 return GL_FALSE;
533
534 case GL_TEXTURE_LOD_BIAS:
535 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
536 if (texObj->Sampler.LodBias != params[0]) {
537 flush(ctx);
538 texObj->Sampler.LodBias = params[0];
539 return GL_TRUE;
540 }
541 break;
542
543 case GL_TEXTURE_BORDER_COLOR:
544 flush(ctx);
545 /* ARB_texture_float disables clamping */
546 if (ctx->Extensions.ARB_texture_float) {
547 texObj->Sampler.BorderColor.f[RCOMP] = params[0];
548 texObj->Sampler.BorderColor.f[GCOMP] = params[1];
549 texObj->Sampler.BorderColor.f[BCOMP] = params[2];
550 texObj->Sampler.BorderColor.f[ACOMP] = params[3];
551 } else {
552 texObj->Sampler.BorderColor.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F);
553 texObj->Sampler.BorderColor.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F);
554 texObj->Sampler.BorderColor.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F);
555 texObj->Sampler.BorderColor.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F);
556 }
557 return GL_TRUE;
558
559 default:
560 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=0x%x)", pname);
561 }
562 return GL_FALSE;
563 }
564
565
566 void GLAPIENTRY
567 _mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
568 {
569 GLboolean need_update;
570 struct gl_texture_object *texObj;
571 GET_CURRENT_CONTEXT(ctx);
572 ASSERT_OUTSIDE_BEGIN_END(ctx);
573
574 texObj = get_texobj(ctx, target, GL_FALSE);
575 if (!texObj)
576 return;
577
578 switch (pname) {
579 case GL_TEXTURE_MIN_FILTER:
580 case GL_TEXTURE_MAG_FILTER:
581 case GL_TEXTURE_WRAP_S:
582 case GL_TEXTURE_WRAP_T:
583 case GL_TEXTURE_WRAP_R:
584 case GL_TEXTURE_BASE_LEVEL:
585 case GL_TEXTURE_MAX_LEVEL:
586 case GL_GENERATE_MIPMAP_SGIS:
587 case GL_TEXTURE_COMPARE_MODE_ARB:
588 case GL_TEXTURE_COMPARE_FUNC_ARB:
589 case GL_DEPTH_TEXTURE_MODE_ARB:
590 case GL_TEXTURE_SRGB_DECODE_EXT:
591 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
592 {
593 /* convert float param to int */
594 GLint p[4];
595 p[0] = (GLint) param;
596 p[1] = p[2] = p[3] = 0;
597 need_update = set_tex_parameteri(ctx, texObj, pname, p);
598 }
599 break;
600 default:
601 {
602 /* this will generate an error if pname is illegal */
603 GLfloat p[4];
604 p[0] = param;
605 p[1] = p[2] = p[3] = 0.0F;
606 need_update = set_tex_parameterf(ctx, texObj, pname, p);
607 }
608 }
609
610 if (ctx->Driver.TexParameter && need_update) {
611 ctx->Driver.TexParameter(ctx, target, texObj, pname, &param);
612 }
613 }
614
615
616 void GLAPIENTRY
617 _mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
618 {
619 GLboolean need_update;
620 struct gl_texture_object *texObj;
621 GET_CURRENT_CONTEXT(ctx);
622 ASSERT_OUTSIDE_BEGIN_END(ctx);
623
624 texObj = get_texobj(ctx, target, GL_FALSE);
625 if (!texObj)
626 return;
627
628 switch (pname) {
629 case GL_TEXTURE_MIN_FILTER:
630 case GL_TEXTURE_MAG_FILTER:
631 case GL_TEXTURE_WRAP_S:
632 case GL_TEXTURE_WRAP_T:
633 case GL_TEXTURE_WRAP_R:
634 case GL_TEXTURE_BASE_LEVEL:
635 case GL_TEXTURE_MAX_LEVEL:
636 case GL_GENERATE_MIPMAP_SGIS:
637 case GL_TEXTURE_COMPARE_MODE_ARB:
638 case GL_TEXTURE_COMPARE_FUNC_ARB:
639 case GL_DEPTH_TEXTURE_MODE_ARB:
640 case GL_TEXTURE_SRGB_DECODE_EXT:
641 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
642 {
643 /* convert float param to int */
644 GLint p[4];
645 p[0] = (GLint) params[0];
646 p[1] = p[2] = p[3] = 0;
647 need_update = set_tex_parameteri(ctx, texObj, pname, p);
648 }
649 break;
650
651 #if FEATURE_OES_draw_texture
652 case GL_TEXTURE_CROP_RECT_OES:
653 {
654 /* convert float params to int */
655 GLint iparams[4];
656 iparams[0] = (GLint) params[0];
657 iparams[1] = (GLint) params[1];
658 iparams[2] = (GLint) params[2];
659 iparams[3] = (GLint) params[3];
660 need_update = set_tex_parameteri(ctx, texObj, pname, iparams);
661 }
662 break;
663 #endif
664
665 default:
666 /* this will generate an error if pname is illegal */
667 need_update = set_tex_parameterf(ctx, texObj, pname, params);
668 }
669
670 if (ctx->Driver.TexParameter && need_update) {
671 ctx->Driver.TexParameter(ctx, target, texObj, pname, params);
672 }
673 }
674
675
676 void GLAPIENTRY
677 _mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
678 {
679 GLboolean need_update;
680 struct gl_texture_object *texObj;
681 GET_CURRENT_CONTEXT(ctx);
682 ASSERT_OUTSIDE_BEGIN_END(ctx);
683
684 texObj = get_texobj(ctx, target, GL_FALSE);
685 if (!texObj)
686 return;
687
688 switch (pname) {
689 case GL_TEXTURE_MIN_LOD:
690 case GL_TEXTURE_MAX_LOD:
691 case GL_TEXTURE_PRIORITY:
692 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
693 case GL_TEXTURE_LOD_BIAS:
694 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
695 {
696 GLfloat fparam[4];
697 fparam[0] = (GLfloat) param;
698 fparam[1] = fparam[2] = fparam[3] = 0.0F;
699 /* convert int param to float */
700 need_update = set_tex_parameterf(ctx, texObj, pname, fparam);
701 }
702 break;
703 default:
704 /* this will generate an error if pname is illegal */
705 {
706 GLint iparam[4];
707 iparam[0] = param;
708 iparam[1] = iparam[2] = iparam[3] = 0;
709 need_update = set_tex_parameteri(ctx, texObj, pname, iparam);
710 }
711 }
712
713 if (ctx->Driver.TexParameter && need_update) {
714 GLfloat fparam = (GLfloat) param;
715 ctx->Driver.TexParameter(ctx, target, texObj, pname, &fparam);
716 }
717 }
718
719
720 void GLAPIENTRY
721 _mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
722 {
723 GLboolean need_update;
724 struct gl_texture_object *texObj;
725 GET_CURRENT_CONTEXT(ctx);
726 ASSERT_OUTSIDE_BEGIN_END(ctx);
727
728 texObj = get_texobj(ctx, target, GL_FALSE);
729 if (!texObj)
730 return;
731
732 switch (pname) {
733 case GL_TEXTURE_BORDER_COLOR:
734 {
735 /* convert int params to float */
736 GLfloat fparams[4];
737 fparams[0] = INT_TO_FLOAT(params[0]);
738 fparams[1] = INT_TO_FLOAT(params[1]);
739 fparams[2] = INT_TO_FLOAT(params[2]);
740 fparams[3] = INT_TO_FLOAT(params[3]);
741 need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
742 }
743 break;
744 case GL_TEXTURE_MIN_LOD:
745 case GL_TEXTURE_MAX_LOD:
746 case GL_TEXTURE_PRIORITY:
747 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
748 case GL_TEXTURE_LOD_BIAS:
749 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
750 {
751 /* convert int param to float */
752 GLfloat fparams[4];
753 fparams[0] = (GLfloat) params[0];
754 fparams[1] = fparams[2] = fparams[3] = 0.0F;
755 need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
756 }
757 break;
758 default:
759 /* this will generate an error if pname is illegal */
760 need_update = set_tex_parameteri(ctx, texObj, pname, params);
761 }
762
763 if (ctx->Driver.TexParameter && need_update) {
764 GLfloat fparams[4];
765 fparams[0] = INT_TO_FLOAT(params[0]);
766 if (pname == GL_TEXTURE_BORDER_COLOR ||
767 pname == GL_TEXTURE_CROP_RECT_OES) {
768 fparams[1] = INT_TO_FLOAT(params[1]);
769 fparams[2] = INT_TO_FLOAT(params[2]);
770 fparams[3] = INT_TO_FLOAT(params[3]);
771 }
772 ctx->Driver.TexParameter(ctx, target, texObj, pname, fparams);
773 }
774 }
775
776
777 /**
778 * Set tex parameter to integer value(s). Primarily intended to set
779 * integer-valued texture border color (for integer-valued textures).
780 * New in GL 3.0.
781 */
782 void GLAPIENTRY
783 _mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
784 {
785 struct gl_texture_object *texObj;
786 GET_CURRENT_CONTEXT(ctx);
787 ASSERT_OUTSIDE_BEGIN_END(ctx);
788
789 texObj = get_texobj(ctx, target, GL_FALSE);
790 if (!texObj)
791 return;
792
793 switch (pname) {
794 case GL_TEXTURE_BORDER_COLOR:
795 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
796 /* set the integer-valued border color */
797 COPY_4V(texObj->Sampler.BorderColor.i, params);
798 break;
799 default:
800 _mesa_TexParameteriv(target, pname, params);
801 break;
802 }
803 /* XXX no driver hook for TexParameterIiv() yet */
804 }
805
806
807 /**
808 * Set tex parameter to unsigned integer value(s). Primarily intended to set
809 * uint-valued texture border color (for integer-valued textures).
810 * New in GL 3.0
811 */
812 void GLAPIENTRY
813 _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
814 {
815 struct gl_texture_object *texObj;
816 GET_CURRENT_CONTEXT(ctx);
817 ASSERT_OUTSIDE_BEGIN_END(ctx);
818
819 texObj = get_texobj(ctx, target, GL_FALSE);
820 if (!texObj)
821 return;
822
823 switch (pname) {
824 case GL_TEXTURE_BORDER_COLOR:
825 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
826 /* set the unsigned integer-valued border color */
827 COPY_4V(texObj->Sampler.BorderColor.ui, params);
828 break;
829 default:
830 _mesa_TexParameteriv(target, pname, (const GLint *) params);
831 break;
832 }
833 /* XXX no driver hook for TexParameterIuiv() yet */
834 }
835
836
837
838
839 void GLAPIENTRY
840 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
841 GLenum pname, GLfloat *params )
842 {
843 GLint iparam;
844 _mesa_GetTexLevelParameteriv( target, level, pname, &iparam );
845 *params = (GLfloat) iparam;
846 }
847
848
849 void GLAPIENTRY
850 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
851 GLenum pname, GLint *params )
852 {
853 const struct gl_texture_unit *texUnit;
854 struct gl_texture_object *texObj;
855 const struct gl_texture_image *img = NULL;
856 GLint maxLevels;
857 gl_format texFormat;
858 GET_CURRENT_CONTEXT(ctx);
859 ASSERT_OUTSIDE_BEGIN_END(ctx);
860
861 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
862 _mesa_error(ctx, GL_INVALID_OPERATION,
863 "glGetTexLevelParameteriv(current unit)");
864 return;
865 }
866
867 texUnit = _mesa_get_current_tex_unit(ctx);
868
869 /* this will catch bad target values */
870 maxLevels = _mesa_max_texture_levels(ctx, target);
871 if (maxLevels == 0) {
872 _mesa_error(ctx, GL_INVALID_ENUM,
873 "glGetTexLevelParameter[if]v(target=0x%x)", target);
874 return;
875 }
876
877 if (level < 0 || level >= maxLevels) {
878 _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
879 return;
880 }
881
882 texObj = _mesa_select_tex_object(ctx, texUnit, target);
883
884 img = _mesa_select_tex_image(ctx, texObj, target, level);
885 if (!img || img->TexFormat == MESA_FORMAT_NONE) {
886 /* undefined texture image */
887 if (pname == GL_TEXTURE_COMPONENTS)
888 *params = 1;
889 else
890 *params = 0;
891 return;
892 }
893
894 texFormat = img->TexFormat;
895
896 switch (pname) {
897 case GL_TEXTURE_WIDTH:
898 *params = img->Width;
899 break;
900 case GL_TEXTURE_HEIGHT:
901 *params = img->Height;
902 break;
903 case GL_TEXTURE_DEPTH:
904 *params = img->Depth;
905 break;
906 case GL_TEXTURE_INTERNAL_FORMAT:
907 if (_mesa_is_format_compressed(texFormat)) {
908 /* need to return the actual compressed format */
909 *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
910 }
911 else {
912 /* If the true internal format is not compressed but the user
913 * requested a generic compressed format, we have to return the
914 * generic base format that matches.
915 *
916 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
917 *
918 * "If no specific compressed format is available,
919 * internalformat is instead replaced by the corresponding base
920 * internal format."
921 *
922 * Otherwise just return the user's requested internal format
923 */
924 const GLenum f =
925 _mesa_gl_compressed_format_base_format(img->InternalFormat);
926
927 *params = (f != 0) ? f : img->InternalFormat;
928 }
929 break;
930 case GL_TEXTURE_BORDER:
931 *params = img->Border;
932 break;
933 case GL_TEXTURE_RED_SIZE:
934 if (img->_BaseFormat == GL_RED) {
935 *params = _mesa_get_format_bits(texFormat, pname);
936 break;
937 }
938 /* FALLTHROUGH */
939 case GL_TEXTURE_GREEN_SIZE:
940 if (img->_BaseFormat == GL_RG) {
941 *params = _mesa_get_format_bits(texFormat, pname);
942 break;
943 }
944 /* FALLTHROUGH */
945 case GL_TEXTURE_BLUE_SIZE:
946 if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
947 *params = _mesa_get_format_bits(texFormat, pname);
948 else
949 *params = 0;
950 break;
951 case GL_TEXTURE_ALPHA_SIZE:
952 if (img->_BaseFormat == GL_ALPHA ||
953 img->_BaseFormat == GL_LUMINANCE_ALPHA ||
954 img->_BaseFormat == GL_RGBA)
955 *params = _mesa_get_format_bits(texFormat, pname);
956 else
957 *params = 0;
958 break;
959 case GL_TEXTURE_INTENSITY_SIZE:
960 if (img->_BaseFormat != GL_INTENSITY)
961 *params = 0;
962 else {
963 *params = _mesa_get_format_bits(texFormat, pname);
964 if (*params == 0) {
965 /* intensity probably stored as rgb texture */
966 *params = MIN2(_mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE),
967 _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE));
968 }
969 }
970 break;
971 case GL_TEXTURE_LUMINANCE_SIZE:
972 if (img->_BaseFormat != GL_LUMINANCE &&
973 img->_BaseFormat != GL_LUMINANCE_ALPHA)
974 *params = 0;
975 else {
976 *params = _mesa_get_format_bits(texFormat, pname);
977 if (*params == 0) {
978 /* luminance probably stored as rgb texture */
979 *params = MIN2(_mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE),
980 _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE));
981 }
982 }
983 break;
984 case GL_TEXTURE_DEPTH_SIZE_ARB:
985 if (!ctx->Extensions.ARB_depth_texture)
986 goto invalid_pname;
987 *params = _mesa_get_format_bits(texFormat, pname);
988 break;
989 case GL_TEXTURE_STENCIL_SIZE_EXT:
990 if (!ctx->Extensions.EXT_packed_depth_stencil &&
991 !ctx->Extensions.ARB_framebuffer_object)
992 goto invalid_pname;
993 *params = _mesa_get_format_bits(texFormat, pname);
994 break;
995 case GL_TEXTURE_SHARED_SIZE:
996 if (ctx->VersionMajor < 3 &&
997 !ctx->Extensions.EXT_texture_shared_exponent)
998 goto invalid_pname;
999 *params = texFormat == MESA_FORMAT_RGB9_E5_FLOAT ? 5 : 0;
1000 break;
1001
1002 /* GL_ARB_texture_compression */
1003 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1004 if (_mesa_is_format_compressed(texFormat) &&
1005 !_mesa_is_proxy_texture(target)) {
1006 *params = _mesa_format_image_size(texFormat, img->Width,
1007 img->Height, img->Depth);
1008 }
1009 else {
1010 _mesa_error(ctx, GL_INVALID_OPERATION,
1011 "glGetTexLevelParameter[if]v(pname)");
1012 }
1013 break;
1014 case GL_TEXTURE_COMPRESSED:
1015 *params = (GLint) _mesa_is_format_compressed(texFormat);
1016 break;
1017
1018 /* GL_ARB_texture_float */
1019 case GL_TEXTURE_RED_TYPE_ARB:
1020 if (!ctx->Extensions.ARB_texture_float)
1021 goto invalid_pname;
1022 *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE) ?
1023 _mesa_get_format_datatype(texFormat) : GL_NONE;
1024 break;
1025 case GL_TEXTURE_GREEN_TYPE_ARB:
1026 if (!ctx->Extensions.ARB_texture_float)
1027 goto invalid_pname;
1028 *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE) ?
1029 _mesa_get_format_datatype(texFormat) : GL_NONE;
1030 break;
1031 case GL_TEXTURE_BLUE_TYPE_ARB:
1032 if (!ctx->Extensions.ARB_texture_float)
1033 goto invalid_pname;
1034 *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_BLUE_SIZE) ?
1035 _mesa_get_format_datatype(texFormat) : GL_NONE;
1036 break;
1037 case GL_TEXTURE_ALPHA_TYPE_ARB:
1038 if (!ctx->Extensions.ARB_texture_float)
1039 goto invalid_pname;
1040 *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_ALPHA_SIZE) ?
1041 _mesa_get_format_datatype(texFormat) : GL_NONE;
1042 break;
1043 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1044 if (!ctx->Extensions.ARB_texture_float)
1045 goto invalid_pname;
1046 *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_LUMINANCE_SIZE) ?
1047 _mesa_get_format_datatype(texFormat) : GL_NONE;
1048 break;
1049 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1050 if (!ctx->Extensions.ARB_texture_float)
1051 goto invalid_pname;
1052 *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_INTENSITY_SIZE) ?
1053 _mesa_get_format_datatype(texFormat) : GL_NONE;
1054 break;
1055 case GL_TEXTURE_DEPTH_TYPE_ARB:
1056 if (!ctx->Extensions.ARB_texture_float)
1057 goto invalid_pname;
1058 *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_DEPTH_SIZE) ?
1059 _mesa_get_format_datatype(texFormat) : GL_NONE;
1060 break;
1061
1062 default:
1063 goto invalid_pname;
1064 }
1065
1066 /* no error if we get here */
1067 return;
1068
1069 invalid_pname:
1070 _mesa_error(ctx, GL_INVALID_ENUM,
1071 "glGetTexLevelParameter[if]v(pname=%s)",
1072 _mesa_lookup_enum_by_nr(pname));
1073 }
1074
1075
1076
1077 void GLAPIENTRY
1078 _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
1079 {
1080 struct gl_texture_object *obj;
1081 GET_CURRENT_CONTEXT(ctx);
1082 ASSERT_OUTSIDE_BEGIN_END(ctx);
1083
1084 obj = get_texobj(ctx, target, GL_TRUE);
1085 if (!obj)
1086 return;
1087
1088 _mesa_lock_texture(ctx, obj);
1089 switch (pname) {
1090 case GL_TEXTURE_MAG_FILTER:
1091 *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
1092 break;
1093 case GL_TEXTURE_MIN_FILTER:
1094 *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
1095 break;
1096 case GL_TEXTURE_WRAP_S:
1097 *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
1098 break;
1099 case GL_TEXTURE_WRAP_T:
1100 *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
1101 break;
1102 case GL_TEXTURE_WRAP_R:
1103 *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
1104 break;
1105 case GL_TEXTURE_BORDER_COLOR:
1106 if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
1107 _mesa_update_state_locked(ctx);
1108 if (ctx->Color._ClampFragmentColor) {
1109 params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1110 params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1111 params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1112 params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
1113 }
1114 else {
1115 params[0] = obj->Sampler.BorderColor.f[0];
1116 params[1] = obj->Sampler.BorderColor.f[1];
1117 params[2] = obj->Sampler.BorderColor.f[2];
1118 params[3] = obj->Sampler.BorderColor.f[3];
1119 }
1120 break;
1121 case GL_TEXTURE_RESIDENT:
1122 *params = ctx->Driver.IsTextureResident ?
1123 ctx->Driver.IsTextureResident(ctx, obj) : 1.0F;
1124 break;
1125 case GL_TEXTURE_PRIORITY:
1126 *params = obj->Priority;
1127 break;
1128 case GL_TEXTURE_MIN_LOD:
1129 *params = obj->Sampler.MinLod;
1130 break;
1131 case GL_TEXTURE_MAX_LOD:
1132 *params = obj->Sampler.MaxLod;
1133 break;
1134 case GL_TEXTURE_BASE_LEVEL:
1135 *params = (GLfloat) obj->BaseLevel;
1136 break;
1137 case GL_TEXTURE_MAX_LEVEL:
1138 *params = (GLfloat) obj->MaxLevel;
1139 break;
1140 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1141 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
1142 goto invalid_pname;
1143 *params = obj->Sampler.MaxAnisotropy;
1144 break;
1145 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
1146 if (!ctx->Extensions.ARB_shadow_ambient)
1147 goto invalid_pname;
1148 *params = obj->Sampler.CompareFailValue;
1149 break;
1150 case GL_GENERATE_MIPMAP_SGIS:
1151 *params = (GLfloat) obj->GenerateMipmap;
1152 break;
1153 case GL_TEXTURE_COMPARE_MODE_ARB:
1154 if (!ctx->Extensions.ARB_shadow)
1155 goto invalid_pname;
1156 *params = (GLfloat) obj->Sampler.CompareMode;
1157 break;
1158 case GL_TEXTURE_COMPARE_FUNC_ARB:
1159 if (!ctx->Extensions.ARB_shadow)
1160 goto invalid_pname;
1161 *params = (GLfloat) obj->Sampler.CompareFunc;
1162 break;
1163 case GL_DEPTH_TEXTURE_MODE_ARB:
1164 if (!ctx->Extensions.ARB_depth_texture)
1165 goto invalid_pname;
1166 *params = (GLfloat) obj->Sampler.DepthMode;
1167 break;
1168 case GL_TEXTURE_LOD_BIAS:
1169 *params = obj->Sampler.LodBias;
1170 break;
1171 #if FEATURE_OES_draw_texture
1172 case GL_TEXTURE_CROP_RECT_OES:
1173 params[0] = obj->CropRect[0];
1174 params[1] = obj->CropRect[1];
1175 params[2] = obj->CropRect[2];
1176 params[3] = obj->CropRect[3];
1177 break;
1178 #endif
1179
1180 case GL_TEXTURE_SWIZZLE_R_EXT:
1181 case GL_TEXTURE_SWIZZLE_G_EXT:
1182 case GL_TEXTURE_SWIZZLE_B_EXT:
1183 case GL_TEXTURE_SWIZZLE_A_EXT:
1184 if (!ctx->Extensions.EXT_texture_swizzle)
1185 goto invalid_pname;
1186 *params = (GLfloat) obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
1187 break;
1188
1189 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
1190 if (!ctx->Extensions.EXT_texture_swizzle) {
1191 goto invalid_pname;
1192 }
1193 else {
1194 GLuint comp;
1195 for (comp = 0; comp < 4; comp++) {
1196 params[comp] = (GLfloat) obj->Swizzle[comp];
1197 }
1198 }
1199 break;
1200
1201 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1202 if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
1203 goto invalid_pname;
1204 *params = (GLfloat) obj->Sampler.CubeMapSeamless;
1205 break;
1206
1207 default:
1208 goto invalid_pname;
1209 }
1210
1211 /* no error if we get here */
1212 _mesa_unlock_texture(ctx, obj);
1213 return;
1214
1215 invalid_pname:
1216 _mesa_unlock_texture(ctx, obj);
1217 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname=0x%x)", pname);
1218 }
1219
1220
1221 void GLAPIENTRY
1222 _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
1223 {
1224 struct gl_texture_object *obj;
1225 GET_CURRENT_CONTEXT(ctx);
1226 ASSERT_OUTSIDE_BEGIN_END(ctx);
1227
1228 obj = get_texobj(ctx, target, GL_TRUE);
1229 if (!obj)
1230 return;
1231
1232 _mesa_lock_texture(ctx, obj);
1233 switch (pname) {
1234 case GL_TEXTURE_MAG_FILTER:
1235 *params = (GLint) obj->Sampler.MagFilter;
1236 break;;
1237 case GL_TEXTURE_MIN_FILTER:
1238 *params = (GLint) obj->Sampler.MinFilter;
1239 break;;
1240 case GL_TEXTURE_WRAP_S:
1241 *params = (GLint) obj->Sampler.WrapS;
1242 break;;
1243 case GL_TEXTURE_WRAP_T:
1244 *params = (GLint) obj->Sampler.WrapT;
1245 break;;
1246 case GL_TEXTURE_WRAP_R:
1247 *params = (GLint) obj->Sampler.WrapR;
1248 break;;
1249 case GL_TEXTURE_BORDER_COLOR:
1250 {
1251 GLfloat b[4];
1252 b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1253 b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1254 b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1255 b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
1256 params[0] = FLOAT_TO_INT(b[0]);
1257 params[1] = FLOAT_TO_INT(b[1]);
1258 params[2] = FLOAT_TO_INT(b[2]);
1259 params[3] = FLOAT_TO_INT(b[3]);
1260 }
1261 break;;
1262 case GL_TEXTURE_RESIDENT:
1263 *params = ctx->Driver.IsTextureResident ?
1264 ctx->Driver.IsTextureResident(ctx, obj) : 1;
1265 break;;
1266 case GL_TEXTURE_PRIORITY:
1267 *params = FLOAT_TO_INT(obj->Priority);
1268 break;;
1269 case GL_TEXTURE_MIN_LOD:
1270 *params = (GLint) obj->Sampler.MinLod;
1271 break;;
1272 case GL_TEXTURE_MAX_LOD:
1273 *params = (GLint) obj->Sampler.MaxLod;
1274 break;;
1275 case GL_TEXTURE_BASE_LEVEL:
1276 *params = obj->BaseLevel;
1277 break;;
1278 case GL_TEXTURE_MAX_LEVEL:
1279 *params = obj->MaxLevel;
1280 break;;
1281 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1282 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
1283 goto invalid_pname;
1284 *params = (GLint) obj->Sampler.MaxAnisotropy;
1285 break;
1286 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
1287 if (!ctx->Extensions.ARB_shadow_ambient)
1288 goto invalid_pname;
1289 *params = (GLint) FLOAT_TO_INT(obj->Sampler.CompareFailValue);
1290 break;
1291 case GL_GENERATE_MIPMAP_SGIS:
1292 *params = (GLint) obj->GenerateMipmap;
1293 break;
1294 case GL_TEXTURE_COMPARE_MODE_ARB:
1295 if (!ctx->Extensions.ARB_shadow)
1296 goto invalid_pname;
1297 *params = (GLint) obj->Sampler.CompareMode;
1298 break;
1299 case GL_TEXTURE_COMPARE_FUNC_ARB:
1300 if (!ctx->Extensions.ARB_shadow)
1301 goto invalid_pname;
1302 *params = (GLint) obj->Sampler.CompareFunc;
1303 break;
1304 case GL_DEPTH_TEXTURE_MODE_ARB:
1305 if (!ctx->Extensions.ARB_depth_texture)
1306 goto invalid_pname;
1307 *params = (GLint) obj->Sampler.DepthMode;
1308 break;
1309 case GL_TEXTURE_LOD_BIAS:
1310 *params = (GLint) obj->Sampler.LodBias;
1311 break;
1312 #if FEATURE_OES_draw_texture
1313 case GL_TEXTURE_CROP_RECT_OES:
1314 params[0] = obj->CropRect[0];
1315 params[1] = obj->CropRect[1];
1316 params[2] = obj->CropRect[2];
1317 params[3] = obj->CropRect[3];
1318 break;
1319 #endif
1320 case GL_TEXTURE_SWIZZLE_R_EXT:
1321 case GL_TEXTURE_SWIZZLE_G_EXT:
1322 case GL_TEXTURE_SWIZZLE_B_EXT:
1323 case GL_TEXTURE_SWIZZLE_A_EXT:
1324 if (!ctx->Extensions.EXT_texture_swizzle)
1325 goto invalid_pname;
1326 *params = obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
1327 break;
1328
1329 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
1330 if (!ctx->Extensions.EXT_texture_swizzle)
1331 goto invalid_pname;
1332 COPY_4V(params, obj->Swizzle);
1333 break;
1334
1335 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1336 if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
1337 goto invalid_pname;
1338 *params = (GLint) obj->Sampler.CubeMapSeamless;
1339 break;
1340
1341 default:
1342 goto invalid_pname;
1343 }
1344
1345 /* no error if we get here */
1346 _mesa_unlock_texture(ctx, obj);
1347 return;
1348
1349 invalid_pname:
1350 _mesa_unlock_texture(ctx, obj);
1351 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname=0x%x)", pname);
1352 }
1353
1354
1355 /** New in GL 3.0 */
1356 void GLAPIENTRY
1357 _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
1358 {
1359 struct gl_texture_object *texObj;
1360 GET_CURRENT_CONTEXT(ctx);
1361 ASSERT_OUTSIDE_BEGIN_END(ctx);
1362
1363 texObj = get_texobj(ctx, target, GL_TRUE);
1364 if (!texObj)
1365 return;
1366
1367 switch (pname) {
1368 case GL_TEXTURE_BORDER_COLOR:
1369 COPY_4V(params, texObj->Sampler.BorderColor.i);
1370 break;
1371 default:
1372 _mesa_GetTexParameteriv(target, pname, params);
1373 }
1374 }
1375
1376
1377 /** New in GL 3.0 */
1378 void GLAPIENTRY
1379 _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
1380 {
1381 struct gl_texture_object *texObj;
1382 GET_CURRENT_CONTEXT(ctx);
1383 ASSERT_OUTSIDE_BEGIN_END(ctx);
1384
1385 texObj = get_texobj(ctx, target, GL_TRUE);
1386 if (!texObj)
1387 return;
1388
1389 switch (pname) {
1390 case GL_TEXTURE_BORDER_COLOR:
1391 COPY_4V(params, texObj->Sampler.BorderColor.i);
1392 break;
1393 default:
1394 {
1395 GLint ip[4];
1396 _mesa_GetTexParameteriv(target, pname, ip);
1397 params[0] = ip[0];
1398 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT ||
1399 pname == GL_TEXTURE_CROP_RECT_OES) {
1400 params[1] = ip[1];
1401 params[2] = ip[2];
1402 params[3] = ip[3];
1403 }
1404 }
1405 }
1406 }