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