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