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