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