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