mesa: remove the redundant check
[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
398 flush(ctx);
399 texObj->Swizzle[comp] = params[0];
400 set_swizzle_component(&texObj->_Swizzle, comp, swz);
401 return GL_TRUE;
402 }
403 goto invalid_pname;
404
405 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
406 if (ctx->Extensions.EXT_texture_swizzle) {
407 GLuint comp;
408 flush(ctx);
409 for (comp = 0; comp < 4; comp++) {
410 const GLint swz = comp_to_swizzle(params[comp]);
411 if (swz >= 0) {
412 texObj->Swizzle[comp] = params[comp];
413 set_swizzle_component(&texObj->_Swizzle, comp, swz);
414 }
415 else {
416 _mesa_error(ctx, GL_INVALID_OPERATION,
417 "glTexParameter(swizzle 0x%x)", params[comp]);
418 return GL_FALSE;
419 }
420 }
421 return GL_TRUE;
422 }
423 goto invalid_pname;
424
425 case GL_TEXTURE_SRGB_DECODE_EXT:
426 if (ctx->Extensions.EXT_texture_sRGB_decode) {
427 GLenum decode = params[0];
428 if (decode == GL_DECODE_EXT || decode == GL_SKIP_DECODE_EXT) {
429 if (texObj->Sampler.sRGBDecode != decode) {
430 flush(ctx);
431 texObj->Sampler.sRGBDecode = decode;
432 }
433 return GL_TRUE;
434 }
435 }
436 goto invalid_pname;
437
438 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
439 if (ctx->Extensions.AMD_seamless_cubemap_per_texture) {
440 GLenum param = params[0];
441 if (param != GL_TRUE && param != GL_FALSE) {
442 goto invalid_param;
443 }
444 if (param != texObj->Sampler.CubeMapSeamless) {
445 flush(ctx);
446 texObj->Sampler.CubeMapSeamless = param;
447 }
448 return GL_TRUE;
449 }
450 goto invalid_pname;
451
452 default:
453 goto invalid_pname;
454 }
455
456 invalid_pname:
457 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=%s)",
458 _mesa_lookup_enum_by_nr(pname));
459 return GL_FALSE;
460
461 invalid_param:
462 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(param=%s)",
463 _mesa_lookup_enum_by_nr(params[0]));
464 return GL_FALSE;
465 }
466
467
468 /**
469 * Set a float-valued texture parameter
470 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
471 */
472 static GLboolean
473 set_tex_parameterf(struct gl_context *ctx,
474 struct gl_texture_object *texObj,
475 GLenum pname, const GLfloat *params)
476 {
477 switch (pname) {
478 case GL_TEXTURE_MIN_LOD:
479 if (texObj->Sampler.MinLod == params[0])
480 return GL_FALSE;
481 flush(ctx);
482 texObj->Sampler.MinLod = params[0];
483 return GL_TRUE;
484
485 case GL_TEXTURE_MAX_LOD:
486 if (texObj->Sampler.MaxLod == params[0])
487 return GL_FALSE;
488 flush(ctx);
489 texObj->Sampler.MaxLod = params[0];
490 return GL_TRUE;
491
492 case GL_TEXTURE_PRIORITY:
493 flush(ctx);
494 texObj->Priority = CLAMP(params[0], 0.0F, 1.0F);
495 return GL_TRUE;
496
497 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
498 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
499 if (texObj->Sampler.MaxAnisotropy == params[0])
500 return GL_FALSE;
501 if (params[0] < 1.0) {
502 _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
503 return GL_FALSE;
504 }
505 flush(ctx);
506 /* clamp to max, that's what NVIDIA does */
507 texObj->Sampler.MaxAnisotropy = MIN2(params[0],
508 ctx->Const.MaxTextureMaxAnisotropy);
509 return GL_TRUE;
510 }
511 else {
512 static GLuint count = 0;
513 if (count++ < 10)
514 _mesa_error(ctx, GL_INVALID_ENUM,
515 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
516 }
517 return GL_FALSE;
518
519 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
520 if (ctx->Extensions.ARB_shadow_ambient) {
521 if (texObj->Sampler.CompareFailValue != params[0]) {
522 flush(ctx);
523 texObj->Sampler.CompareFailValue = CLAMP(params[0], 0.0F, 1.0F);
524 return GL_TRUE;
525 }
526 }
527 else {
528 _mesa_error(ctx, GL_INVALID_ENUM,
529 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
530 }
531 return GL_FALSE;
532
533 case GL_TEXTURE_LOD_BIAS:
534 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
535 if (texObj->Sampler.LodBias != params[0]) {
536 flush(ctx);
537 texObj->Sampler.LodBias = params[0];
538 return GL_TRUE;
539 }
540 break;
541
542 case GL_TEXTURE_BORDER_COLOR:
543 flush(ctx);
544 /* ARB_texture_float disables clamping */
545 if (ctx->Extensions.ARB_texture_float) {
546 texObj->Sampler.BorderColor.f[RCOMP] = params[0];
547 texObj->Sampler.BorderColor.f[GCOMP] = params[1];
548 texObj->Sampler.BorderColor.f[BCOMP] = params[2];
549 texObj->Sampler.BorderColor.f[ACOMP] = params[3];
550 } else {
551 texObj->Sampler.BorderColor.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F);
552 texObj->Sampler.BorderColor.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F);
553 texObj->Sampler.BorderColor.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F);
554 texObj->Sampler.BorderColor.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F);
555 }
556 return GL_TRUE;
557
558 default:
559 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=0x%x)", pname);
560 }
561 return GL_FALSE;
562 }
563
564
565 void GLAPIENTRY
566 _mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
567 {
568 GLboolean need_update;
569 struct gl_texture_object *texObj;
570 GET_CURRENT_CONTEXT(ctx);
571 ASSERT_OUTSIDE_BEGIN_END(ctx);
572
573 texObj = get_texobj(ctx, target, GL_FALSE);
574 if (!texObj)
575 return;
576
577 switch (pname) {
578 case GL_TEXTURE_MIN_FILTER:
579 case GL_TEXTURE_MAG_FILTER:
580 case GL_TEXTURE_WRAP_S:
581 case GL_TEXTURE_WRAP_T:
582 case GL_TEXTURE_WRAP_R:
583 case GL_TEXTURE_BASE_LEVEL:
584 case GL_TEXTURE_MAX_LEVEL:
585 case GL_GENERATE_MIPMAP_SGIS:
586 case GL_TEXTURE_COMPARE_MODE_ARB:
587 case GL_TEXTURE_COMPARE_FUNC_ARB:
588 case GL_DEPTH_TEXTURE_MODE_ARB:
589 case GL_TEXTURE_SRGB_DECODE_EXT:
590 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
591 {
592 /* convert float param to int */
593 GLint p[4];
594 p[0] = (GLint) param;
595 p[1] = p[2] = p[3] = 0;
596 need_update = set_tex_parameteri(ctx, texObj, pname, p);
597 }
598 break;
599 default:
600 {
601 /* this will generate an error if pname is illegal */
602 GLfloat p[4];
603 p[0] = param;
604 p[1] = p[2] = p[3] = 0.0F;
605 need_update = set_tex_parameterf(ctx, texObj, pname, p);
606 }
607 }
608
609 if (ctx->Driver.TexParameter && need_update) {
610 ctx->Driver.TexParameter(ctx, target, texObj, pname, &param);
611 }
612 }
613
614
615 void GLAPIENTRY
616 _mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
617 {
618 GLboolean need_update;
619 struct gl_texture_object *texObj;
620 GET_CURRENT_CONTEXT(ctx);
621 ASSERT_OUTSIDE_BEGIN_END(ctx);
622
623 texObj = get_texobj(ctx, target, GL_FALSE);
624 if (!texObj)
625 return;
626
627 switch (pname) {
628 case GL_TEXTURE_MIN_FILTER:
629 case GL_TEXTURE_MAG_FILTER:
630 case GL_TEXTURE_WRAP_S:
631 case GL_TEXTURE_WRAP_T:
632 case GL_TEXTURE_WRAP_R:
633 case GL_TEXTURE_BASE_LEVEL:
634 case GL_TEXTURE_MAX_LEVEL:
635 case GL_GENERATE_MIPMAP_SGIS:
636 case GL_TEXTURE_COMPARE_MODE_ARB:
637 case GL_TEXTURE_COMPARE_FUNC_ARB:
638 case GL_DEPTH_TEXTURE_MODE_ARB:
639 case GL_TEXTURE_SRGB_DECODE_EXT:
640 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
641 {
642 /* convert float param to int */
643 GLint p[4];
644 p[0] = (GLint) params[0];
645 p[1] = p[2] = p[3] = 0;
646 need_update = set_tex_parameteri(ctx, texObj, pname, p);
647 }
648 break;
649
650 #if FEATURE_OES_draw_texture
651 case GL_TEXTURE_CROP_RECT_OES:
652 {
653 /* convert float params to int */
654 GLint iparams[4];
655 iparams[0] = (GLint) params[0];
656 iparams[1] = (GLint) params[1];
657 iparams[2] = (GLint) params[2];
658 iparams[3] = (GLint) params[3];
659 need_update = set_tex_parameteri(ctx, texObj, pname, iparams);
660 }
661 break;
662 #endif
663
664 default:
665 /* this will generate an error if pname is illegal */
666 need_update = set_tex_parameterf(ctx, texObj, pname, params);
667 }
668
669 if (ctx->Driver.TexParameter && need_update) {
670 ctx->Driver.TexParameter(ctx, target, texObj, pname, params);
671 }
672 }
673
674
675 void GLAPIENTRY
676 _mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
677 {
678 GLboolean need_update;
679 struct gl_texture_object *texObj;
680 GET_CURRENT_CONTEXT(ctx);
681 ASSERT_OUTSIDE_BEGIN_END(ctx);
682
683 texObj = get_texobj(ctx, target, GL_FALSE);
684 if (!texObj)
685 return;
686
687 switch (pname) {
688 case GL_TEXTURE_MIN_LOD:
689 case GL_TEXTURE_MAX_LOD:
690 case GL_TEXTURE_PRIORITY:
691 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
692 case GL_TEXTURE_LOD_BIAS:
693 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
694 {
695 GLfloat fparam[4];
696 fparam[0] = (GLfloat) param;
697 fparam[1] = fparam[2] = fparam[3] = 0.0F;
698 /* convert int param to float */
699 need_update = set_tex_parameterf(ctx, texObj, pname, fparam);
700 }
701 break;
702 default:
703 /* this will generate an error if pname is illegal */
704 {
705 GLint iparam[4];
706 iparam[0] = param;
707 iparam[1] = iparam[2] = iparam[3] = 0;
708 need_update = set_tex_parameteri(ctx, texObj, pname, iparam);
709 }
710 }
711
712 if (ctx->Driver.TexParameter && need_update) {
713 GLfloat fparam = (GLfloat) param;
714 ctx->Driver.TexParameter(ctx, target, texObj, pname, &fparam);
715 }
716 }
717
718
719 void GLAPIENTRY
720 _mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
721 {
722 GLboolean need_update;
723 struct gl_texture_object *texObj;
724 GET_CURRENT_CONTEXT(ctx);
725 ASSERT_OUTSIDE_BEGIN_END(ctx);
726
727 texObj = get_texobj(ctx, target, GL_FALSE);
728 if (!texObj)
729 return;
730
731 switch (pname) {
732 case GL_TEXTURE_BORDER_COLOR:
733 {
734 /* convert int params to float */
735 GLfloat fparams[4];
736 fparams[0] = INT_TO_FLOAT(params[0]);
737 fparams[1] = INT_TO_FLOAT(params[1]);
738 fparams[2] = INT_TO_FLOAT(params[2]);
739 fparams[3] = INT_TO_FLOAT(params[3]);
740 need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
741 }
742 break;
743 case GL_TEXTURE_MIN_LOD:
744 case GL_TEXTURE_MAX_LOD:
745 case GL_TEXTURE_PRIORITY:
746 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
747 case GL_TEXTURE_LOD_BIAS:
748 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
749 {
750 /* convert int param to float */
751 GLfloat fparams[4];
752 fparams[0] = (GLfloat) params[0];
753 fparams[1] = fparams[2] = fparams[3] = 0.0F;
754 need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
755 }
756 break;
757 default:
758 /* this will generate an error if pname is illegal */
759 need_update = set_tex_parameteri(ctx, texObj, pname, params);
760 }
761
762 if (ctx->Driver.TexParameter && need_update) {
763 GLfloat fparams[4];
764 fparams[0] = INT_TO_FLOAT(params[0]);
765 if (pname == GL_TEXTURE_BORDER_COLOR ||
766 pname == GL_TEXTURE_CROP_RECT_OES) {
767 fparams[1] = INT_TO_FLOAT(params[1]);
768 fparams[2] = INT_TO_FLOAT(params[2]);
769 fparams[3] = INT_TO_FLOAT(params[3]);
770 }
771 ctx->Driver.TexParameter(ctx, target, texObj, pname, fparams);
772 }
773 }
774
775
776 /**
777 * Set tex parameter to integer value(s). Primarily intended to set
778 * integer-valued texture border color (for integer-valued textures).
779 * New in GL 3.0.
780 */
781 void GLAPIENTRY
782 _mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
783 {
784 struct gl_texture_object *texObj;
785 GET_CURRENT_CONTEXT(ctx);
786 ASSERT_OUTSIDE_BEGIN_END(ctx);
787
788 texObj = get_texobj(ctx, target, GL_FALSE);
789 if (!texObj)
790 return;
791
792 switch (pname) {
793 case GL_TEXTURE_BORDER_COLOR:
794 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
795 /* set the integer-valued border color */
796 COPY_4V(texObj->Sampler.BorderColor.i, params);
797 break;
798 default:
799 _mesa_TexParameteriv(target, pname, params);
800 break;
801 }
802 /* XXX no driver hook for TexParameterIiv() yet */
803 }
804
805
806 /**
807 * Set tex parameter to unsigned integer value(s). Primarily intended to set
808 * uint-valued texture border color (for integer-valued textures).
809 * New in GL 3.0
810 */
811 void GLAPIENTRY
812 _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
813 {
814 struct gl_texture_object *texObj;
815 GET_CURRENT_CONTEXT(ctx);
816 ASSERT_OUTSIDE_BEGIN_END(ctx);
817
818 texObj = get_texobj(ctx, target, GL_FALSE);
819 if (!texObj)
820 return;
821
822 switch (pname) {
823 case GL_TEXTURE_BORDER_COLOR:
824 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
825 /* set the unsigned integer-valued border color */
826 COPY_4V(texObj->Sampler.BorderColor.ui, params);
827 break;
828 default:
829 _mesa_TexParameteriv(target, pname, (const GLint *) params);
830 break;
831 }
832 /* XXX no driver hook for TexParameterIuiv() yet */
833 }
834
835
836
837
838 void GLAPIENTRY
839 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
840 GLenum pname, GLfloat *params )
841 {
842 GLint iparam;
843 _mesa_GetTexLevelParameteriv( target, level, pname, &iparam );
844 *params = (GLfloat) iparam;
845 }
846
847
848 void GLAPIENTRY
849 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
850 GLenum pname, GLint *params )
851 {
852 const struct gl_texture_unit *texUnit;
853 struct gl_texture_object *texObj;
854 const struct gl_texture_image *img = NULL;
855 GLint maxLevels;
856 gl_format texFormat;
857 GET_CURRENT_CONTEXT(ctx);
858 ASSERT_OUTSIDE_BEGIN_END(ctx);
859
860 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
861 _mesa_error(ctx, GL_INVALID_OPERATION,
862 "glGetTexLevelParameteriv(current unit)");
863 return;
864 }
865
866 texUnit = _mesa_get_current_tex_unit(ctx);
867
868 /* this will catch bad target values */
869 maxLevels = _mesa_max_texture_levels(ctx, target);
870 if (maxLevels == 0) {
871 _mesa_error(ctx, GL_INVALID_ENUM,
872 "glGetTexLevelParameter[if]v(target=0x%x)", target);
873 return;
874 }
875
876 if (level < 0 || level >= maxLevels) {
877 _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
878 return;
879 }
880
881 texObj = _mesa_select_tex_object(ctx, texUnit, target);
882
883 img = _mesa_select_tex_image(ctx, texObj, target, level);
884 if (!img || img->TexFormat == MESA_FORMAT_NONE) {
885 /* undefined texture image */
886 if (pname == GL_TEXTURE_COMPONENTS)
887 *params = 1;
888 else
889 *params = 0;
890 return;
891 }
892
893 texFormat = img->TexFormat;
894
895 switch (pname) {
896 case GL_TEXTURE_WIDTH:
897 *params = img->Width;
898 break;
899 case GL_TEXTURE_HEIGHT:
900 *params = img->Height;
901 break;
902 case GL_TEXTURE_DEPTH:
903 *params = img->Depth;
904 break;
905 case GL_TEXTURE_INTERNAL_FORMAT:
906 if (_mesa_is_format_compressed(texFormat)) {
907 /* need to return the actual compressed format */
908 *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
909 }
910 else {
911 /* If the true internal format is not compressed but the user
912 * requested a generic compressed format, we have to return the
913 * generic base format that matches.
914 *
915 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
916 *
917 * "If no specific compressed format is available,
918 * internalformat is instead replaced by the corresponding base
919 * internal format."
920 *
921 * Otherwise just return the user's requested internal format
922 */
923 const GLenum f =
924 _mesa_gl_compressed_format_base_format(img->InternalFormat);
925
926 *params = (f != 0) ? f : img->InternalFormat;
927 }
928 break;
929 case GL_TEXTURE_BORDER:
930 *params = img->Border;
931 break;
932 case GL_TEXTURE_RED_SIZE:
933 if (img->_BaseFormat == GL_RED) {
934 *params = _mesa_get_format_bits(texFormat, pname);
935 break;
936 }
937 /* FALLTHROUGH */
938 case GL_TEXTURE_GREEN_SIZE:
939 if (img->_BaseFormat == GL_RG) {
940 *params = _mesa_get_format_bits(texFormat, pname);
941 break;
942 }
943 /* FALLTHROUGH */
944 case GL_TEXTURE_BLUE_SIZE:
945 if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
946 *params = _mesa_get_format_bits(texFormat, pname);
947 else
948 *params = 0;
949 break;
950 case GL_TEXTURE_ALPHA_SIZE:
951 if (img->_BaseFormat == GL_ALPHA ||
952 img->_BaseFormat == GL_LUMINANCE_ALPHA ||
953 img->_BaseFormat == GL_RGBA)
954 *params = _mesa_get_format_bits(texFormat, pname);
955 else
956 *params = 0;
957 break;
958 case GL_TEXTURE_INTENSITY_SIZE:
959 if (img->_BaseFormat != GL_INTENSITY)
960 *params = 0;
961 else {
962 *params = _mesa_get_format_bits(texFormat, pname);
963 if (*params == 0) {
964 /* intensity probably stored as rgb texture */
965 *params = MIN2(_mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE),
966 _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE));
967 }
968 }
969 break;
970 case GL_TEXTURE_LUMINANCE_SIZE:
971 if (img->_BaseFormat != GL_LUMINANCE &&
972 img->_BaseFormat != GL_LUMINANCE_ALPHA)
973 *params = 0;
974 else {
975 *params = _mesa_get_format_bits(texFormat, pname);
976 if (*params == 0) {
977 /* luminance probably stored as rgb texture */
978 *params = MIN2(_mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE),
979 _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE));
980 }
981 }
982 break;
983 case GL_TEXTURE_DEPTH_SIZE_ARB:
984 if (!ctx->Extensions.ARB_depth_texture)
985 goto invalid_pname;
986 *params = _mesa_get_format_bits(texFormat, pname);
987 break;
988 case GL_TEXTURE_STENCIL_SIZE_EXT:
989 if (!ctx->Extensions.EXT_packed_depth_stencil &&
990 !ctx->Extensions.ARB_framebuffer_object)
991 goto invalid_pname;
992 *params = _mesa_get_format_bits(texFormat, pname);
993 break;
994 case GL_TEXTURE_SHARED_SIZE:
995 if (ctx->VersionMajor < 3 &&
996 !ctx->Extensions.EXT_texture_shared_exponent)
997 goto invalid_pname;
998 *params = texFormat == MESA_FORMAT_RGB9_E5_FLOAT ? 5 : 0;
999 break;
1000
1001 /* GL_ARB_texture_compression */
1002 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1003 if (_mesa_is_format_compressed(texFormat) &&
1004 !_mesa_is_proxy_texture(target)) {
1005 *params = _mesa_format_image_size(texFormat, img->Width,
1006 img->Height, img->Depth);
1007 }
1008 else {
1009 _mesa_error(ctx, GL_INVALID_OPERATION,
1010 "glGetTexLevelParameter[if]v(pname)");
1011 }
1012 break;
1013 case GL_TEXTURE_COMPRESSED:
1014 *params = (GLint) _mesa_is_format_compressed(texFormat);
1015 break;
1016
1017 /* GL_ARB_texture_float */
1018 case GL_TEXTURE_RED_TYPE_ARB:
1019 if (!ctx->Extensions.ARB_texture_float)
1020 goto invalid_pname;
1021 *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE) ?
1022 _mesa_get_format_datatype(texFormat) : GL_NONE;
1023 break;
1024 case GL_TEXTURE_GREEN_TYPE_ARB:
1025 if (!ctx->Extensions.ARB_texture_float)
1026 goto invalid_pname;
1027 *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE) ?
1028 _mesa_get_format_datatype(texFormat) : GL_NONE;
1029 break;
1030 case GL_TEXTURE_BLUE_TYPE_ARB:
1031 if (!ctx->Extensions.ARB_texture_float)
1032 goto invalid_pname;
1033 *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_BLUE_SIZE) ?
1034 _mesa_get_format_datatype(texFormat) : GL_NONE;
1035 break;
1036 case GL_TEXTURE_ALPHA_TYPE_ARB:
1037 if (!ctx->Extensions.ARB_texture_float)
1038 goto invalid_pname;
1039 *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_ALPHA_SIZE) ?
1040 _mesa_get_format_datatype(texFormat) : GL_NONE;
1041 break;
1042 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1043 if (!ctx->Extensions.ARB_texture_float)
1044 goto invalid_pname;
1045 *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_LUMINANCE_SIZE) ?
1046 _mesa_get_format_datatype(texFormat) : GL_NONE;
1047 break;
1048 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1049 if (!ctx->Extensions.ARB_texture_float)
1050 goto invalid_pname;
1051 *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_INTENSITY_SIZE) ?
1052 _mesa_get_format_datatype(texFormat) : GL_NONE;
1053 break;
1054 case GL_TEXTURE_DEPTH_TYPE_ARB:
1055 if (!ctx->Extensions.ARB_texture_float)
1056 goto invalid_pname;
1057 *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_DEPTH_SIZE) ?
1058 _mesa_get_format_datatype(texFormat) : GL_NONE;
1059 break;
1060
1061 default:
1062 goto invalid_pname;
1063 }
1064
1065 /* no error if we get here */
1066 return;
1067
1068 invalid_pname:
1069 _mesa_error(ctx, GL_INVALID_ENUM,
1070 "glGetTexLevelParameter[if]v(pname=%s)",
1071 _mesa_lookup_enum_by_nr(pname));
1072 }
1073
1074
1075
1076 void GLAPIENTRY
1077 _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
1078 {
1079 struct gl_texture_object *obj;
1080 GET_CURRENT_CONTEXT(ctx);
1081 ASSERT_OUTSIDE_BEGIN_END(ctx);
1082
1083 obj = get_texobj(ctx, target, GL_TRUE);
1084 if (!obj)
1085 return;
1086
1087 _mesa_lock_texture(ctx, obj);
1088 switch (pname) {
1089 case GL_TEXTURE_MAG_FILTER:
1090 *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
1091 break;
1092 case GL_TEXTURE_MIN_FILTER:
1093 *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
1094 break;
1095 case GL_TEXTURE_WRAP_S:
1096 *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
1097 break;
1098 case GL_TEXTURE_WRAP_T:
1099 *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
1100 break;
1101 case GL_TEXTURE_WRAP_R:
1102 *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
1103 break;
1104 case GL_TEXTURE_BORDER_COLOR:
1105 if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
1106 _mesa_update_state_locked(ctx);
1107 if (ctx->Color._ClampFragmentColor) {
1108 params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1109 params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1110 params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1111 params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
1112 }
1113 else {
1114 params[0] = obj->Sampler.BorderColor.f[0];
1115 params[1] = obj->Sampler.BorderColor.f[1];
1116 params[2] = obj->Sampler.BorderColor.f[2];
1117 params[3] = obj->Sampler.BorderColor.f[3];
1118 }
1119 break;
1120 case GL_TEXTURE_RESIDENT:
1121 *params = ctx->Driver.IsTextureResident ?
1122 ctx->Driver.IsTextureResident(ctx, obj) : 1.0F;
1123 break;
1124 case GL_TEXTURE_PRIORITY:
1125 *params = obj->Priority;
1126 break;
1127 case GL_TEXTURE_MIN_LOD:
1128 *params = obj->Sampler.MinLod;
1129 break;
1130 case GL_TEXTURE_MAX_LOD:
1131 *params = obj->Sampler.MaxLod;
1132 break;
1133 case GL_TEXTURE_BASE_LEVEL:
1134 *params = (GLfloat) obj->BaseLevel;
1135 break;
1136 case GL_TEXTURE_MAX_LEVEL:
1137 *params = (GLfloat) obj->MaxLevel;
1138 break;
1139 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1140 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
1141 goto invalid_pname;
1142 *params = obj->Sampler.MaxAnisotropy;
1143 break;
1144 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
1145 if (!ctx->Extensions.ARB_shadow_ambient)
1146 goto invalid_pname;
1147 *params = obj->Sampler.CompareFailValue;
1148 break;
1149 case GL_GENERATE_MIPMAP_SGIS:
1150 *params = (GLfloat) obj->GenerateMipmap;
1151 break;
1152 case GL_TEXTURE_COMPARE_MODE_ARB:
1153 if (!ctx->Extensions.ARB_shadow)
1154 goto invalid_pname;
1155 *params = (GLfloat) obj->Sampler.CompareMode;
1156 break;
1157 case GL_TEXTURE_COMPARE_FUNC_ARB:
1158 if (!ctx->Extensions.ARB_shadow)
1159 goto invalid_pname;
1160 *params = (GLfloat) obj->Sampler.CompareFunc;
1161 break;
1162 case GL_DEPTH_TEXTURE_MODE_ARB:
1163 if (!ctx->Extensions.ARB_depth_texture)
1164 goto invalid_pname;
1165 *params = (GLfloat) obj->Sampler.DepthMode;
1166 break;
1167 case GL_TEXTURE_LOD_BIAS:
1168 *params = obj->Sampler.LodBias;
1169 break;
1170 #if FEATURE_OES_draw_texture
1171 case GL_TEXTURE_CROP_RECT_OES:
1172 params[0] = obj->CropRect[0];
1173 params[1] = obj->CropRect[1];
1174 params[2] = obj->CropRect[2];
1175 params[3] = obj->CropRect[3];
1176 break;
1177 #endif
1178
1179 case GL_TEXTURE_SWIZZLE_R_EXT:
1180 case GL_TEXTURE_SWIZZLE_G_EXT:
1181 case GL_TEXTURE_SWIZZLE_B_EXT:
1182 case GL_TEXTURE_SWIZZLE_A_EXT:
1183 if (!ctx->Extensions.EXT_texture_swizzle)
1184 goto invalid_pname;
1185 *params = (GLfloat) obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
1186 break;
1187
1188 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
1189 if (!ctx->Extensions.EXT_texture_swizzle) {
1190 goto invalid_pname;
1191 }
1192 else {
1193 GLuint comp;
1194 for (comp = 0; comp < 4; comp++) {
1195 params[comp] = (GLfloat) obj->Swizzle[comp];
1196 }
1197 }
1198 break;
1199
1200 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1201 if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
1202 goto invalid_pname;
1203 *params = (GLfloat) obj->Sampler.CubeMapSeamless;
1204 break;
1205
1206 case GL_TEXTURE_IMMUTABLE_FORMAT:
1207 if (!ctx->Extensions.ARB_texture_storage)
1208 goto invalid_pname;
1209 *params = (GLfloat) obj->Immutable;
1210 break;
1211
1212 default:
1213 goto invalid_pname;
1214 }
1215
1216 /* no error if we get here */
1217 _mesa_unlock_texture(ctx, obj);
1218 return;
1219
1220 invalid_pname:
1221 _mesa_unlock_texture(ctx, obj);
1222 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname=0x%x)", pname);
1223 }
1224
1225
1226 void GLAPIENTRY
1227 _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
1228 {
1229 struct gl_texture_object *obj;
1230 GET_CURRENT_CONTEXT(ctx);
1231 ASSERT_OUTSIDE_BEGIN_END(ctx);
1232
1233 obj = get_texobj(ctx, target, GL_TRUE);
1234 if (!obj)
1235 return;
1236
1237 _mesa_lock_texture(ctx, obj);
1238 switch (pname) {
1239 case GL_TEXTURE_MAG_FILTER:
1240 *params = (GLint) obj->Sampler.MagFilter;
1241 break;;
1242 case GL_TEXTURE_MIN_FILTER:
1243 *params = (GLint) obj->Sampler.MinFilter;
1244 break;;
1245 case GL_TEXTURE_WRAP_S:
1246 *params = (GLint) obj->Sampler.WrapS;
1247 break;;
1248 case GL_TEXTURE_WRAP_T:
1249 *params = (GLint) obj->Sampler.WrapT;
1250 break;;
1251 case GL_TEXTURE_WRAP_R:
1252 *params = (GLint) obj->Sampler.WrapR;
1253 break;;
1254 case GL_TEXTURE_BORDER_COLOR:
1255 {
1256 GLfloat b[4];
1257 b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1258 b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1259 b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1260 b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
1261 params[0] = FLOAT_TO_INT(b[0]);
1262 params[1] = FLOAT_TO_INT(b[1]);
1263 params[2] = FLOAT_TO_INT(b[2]);
1264 params[3] = FLOAT_TO_INT(b[3]);
1265 }
1266 break;;
1267 case GL_TEXTURE_RESIDENT:
1268 *params = ctx->Driver.IsTextureResident ?
1269 ctx->Driver.IsTextureResident(ctx, obj) : 1;
1270 break;;
1271 case GL_TEXTURE_PRIORITY:
1272 *params = FLOAT_TO_INT(obj->Priority);
1273 break;;
1274 case GL_TEXTURE_MIN_LOD:
1275 *params = (GLint) obj->Sampler.MinLod;
1276 break;;
1277 case GL_TEXTURE_MAX_LOD:
1278 *params = (GLint) obj->Sampler.MaxLod;
1279 break;;
1280 case GL_TEXTURE_BASE_LEVEL:
1281 *params = obj->BaseLevel;
1282 break;;
1283 case GL_TEXTURE_MAX_LEVEL:
1284 *params = obj->MaxLevel;
1285 break;;
1286 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1287 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
1288 goto invalid_pname;
1289 *params = (GLint) obj->Sampler.MaxAnisotropy;
1290 break;
1291 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
1292 if (!ctx->Extensions.ARB_shadow_ambient)
1293 goto invalid_pname;
1294 *params = (GLint) FLOAT_TO_INT(obj->Sampler.CompareFailValue);
1295 break;
1296 case GL_GENERATE_MIPMAP_SGIS:
1297 *params = (GLint) obj->GenerateMipmap;
1298 break;
1299 case GL_TEXTURE_COMPARE_MODE_ARB:
1300 if (!ctx->Extensions.ARB_shadow)
1301 goto invalid_pname;
1302 *params = (GLint) obj->Sampler.CompareMode;
1303 break;
1304 case GL_TEXTURE_COMPARE_FUNC_ARB:
1305 if (!ctx->Extensions.ARB_shadow)
1306 goto invalid_pname;
1307 *params = (GLint) obj->Sampler.CompareFunc;
1308 break;
1309 case GL_DEPTH_TEXTURE_MODE_ARB:
1310 if (!ctx->Extensions.ARB_depth_texture)
1311 goto invalid_pname;
1312 *params = (GLint) obj->Sampler.DepthMode;
1313 break;
1314 case GL_TEXTURE_LOD_BIAS:
1315 *params = (GLint) obj->Sampler.LodBias;
1316 break;
1317 #if FEATURE_OES_draw_texture
1318 case GL_TEXTURE_CROP_RECT_OES:
1319 params[0] = obj->CropRect[0];
1320 params[1] = obj->CropRect[1];
1321 params[2] = obj->CropRect[2];
1322 params[3] = obj->CropRect[3];
1323 break;
1324 #endif
1325 case GL_TEXTURE_SWIZZLE_R_EXT:
1326 case GL_TEXTURE_SWIZZLE_G_EXT:
1327 case GL_TEXTURE_SWIZZLE_B_EXT:
1328 case GL_TEXTURE_SWIZZLE_A_EXT:
1329 if (!ctx->Extensions.EXT_texture_swizzle)
1330 goto invalid_pname;
1331 *params = obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
1332 break;
1333
1334 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
1335 if (!ctx->Extensions.EXT_texture_swizzle)
1336 goto invalid_pname;
1337 COPY_4V(params, obj->Swizzle);
1338 break;
1339
1340 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1341 if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
1342 goto invalid_pname;
1343 *params = (GLint) obj->Sampler.CubeMapSeamless;
1344 break;
1345
1346 case GL_TEXTURE_IMMUTABLE_FORMAT:
1347 if (!ctx->Extensions.ARB_texture_storage)
1348 goto invalid_pname;
1349 *params = (GLint) obj->Immutable;
1350 break;
1351
1352 default:
1353 goto invalid_pname;
1354 }
1355
1356 /* no error if we get here */
1357 _mesa_unlock_texture(ctx, obj);
1358 return;
1359
1360 invalid_pname:
1361 _mesa_unlock_texture(ctx, obj);
1362 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname=0x%x)", pname);
1363 }
1364
1365
1366 /** New in GL 3.0 */
1367 void GLAPIENTRY
1368 _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
1369 {
1370 struct gl_texture_object *texObj;
1371 GET_CURRENT_CONTEXT(ctx);
1372 ASSERT_OUTSIDE_BEGIN_END(ctx);
1373
1374 texObj = get_texobj(ctx, target, GL_TRUE);
1375 if (!texObj)
1376 return;
1377
1378 switch (pname) {
1379 case GL_TEXTURE_BORDER_COLOR:
1380 COPY_4V(params, texObj->Sampler.BorderColor.i);
1381 break;
1382 default:
1383 _mesa_GetTexParameteriv(target, pname, params);
1384 }
1385 }
1386
1387
1388 /** New in GL 3.0 */
1389 void GLAPIENTRY
1390 _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
1391 {
1392 struct gl_texture_object *texObj;
1393 GET_CURRENT_CONTEXT(ctx);
1394 ASSERT_OUTSIDE_BEGIN_END(ctx);
1395
1396 texObj = get_texobj(ctx, target, GL_TRUE);
1397 if (!texObj)
1398 return;
1399
1400 switch (pname) {
1401 case GL_TEXTURE_BORDER_COLOR:
1402 COPY_4V(params, texObj->Sampler.BorderColor.i);
1403 break;
1404 default:
1405 {
1406 GLint ip[4];
1407 _mesa_GetTexParameteriv(target, pname, ip);
1408 params[0] = ip[0];
1409 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT ||
1410 pname == GL_TEXTURE_CROP_RECT_OES) {
1411 params[1] = ip[1];
1412 params[2] = ip[2];
1413 params[3] = ip[3];
1414 }
1415 }
1416 }
1417 }