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