Correct clamping of TEXTURE_{MAX, BASE}_LEVEL
[mesa.git] / src / mesa / main / texparam.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 /**
27 * \file texparam.c
28 *
29 * glTexParameter-related functions
30 */
31
32 #include <stdbool.h>
33 #include "main/glheader.h"
34 #include "main/blend.h"
35 #include "main/colormac.h"
36 #include "main/context.h"
37 #include "main/enums.h"
38 #include "main/formats.h"
39 #include "main/glformats.h"
40 #include "main/macros.h"
41 #include "main/mtypes.h"
42 #include "main/state.h"
43 #include "main/texcompress.h"
44 #include "main/texobj.h"
45 #include "main/texparam.h"
46 #include "main/teximage.h"
47 #include "main/texstate.h"
48 #include "program/prog_instruction.h"
49
50
51 /**
52 * Check if a coordinate wrap mode is supported for the texture target.
53 * \return GL_TRUE if legal, GL_FALSE otherwise
54 */
55 static GLboolean
56 validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
57 {
58 const struct gl_extensions * const e = & ctx->Extensions;
59 const bool is_desktop_gl = _mesa_is_desktop_gl(ctx);
60 bool supported;
61
62 switch (wrap) {
63 case GL_CLAMP:
64 /* GL_CLAMP was removed in the core profile, and it has never existed in
65 * OpenGL ES.
66 */
67 supported = (ctx->API == API_OPENGL_COMPAT)
68 && (target != GL_TEXTURE_EXTERNAL_OES);
69 break;
70
71 case GL_CLAMP_TO_EDGE:
72 supported = true;
73 break;
74
75 case GL_CLAMP_TO_BORDER:
76 supported = is_desktop_gl && e->ARB_texture_border_clamp
77 && (target != GL_TEXTURE_EXTERNAL_OES);
78 break;
79
80 case GL_REPEAT:
81 case GL_MIRRORED_REPEAT:
82 supported = (target != GL_TEXTURE_RECTANGLE_NV)
83 && (target != GL_TEXTURE_EXTERNAL_OES);
84 break;
85
86 case GL_MIRROR_CLAMP_EXT:
87 case GL_MIRROR_CLAMP_TO_EDGE_EXT:
88 supported = is_desktop_gl
89 && (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)
90 && (target != GL_TEXTURE_RECTANGLE_NV)
91 && (target != GL_TEXTURE_EXTERNAL_OES);
92 break;
93
94 case GL_MIRROR_CLAMP_TO_BORDER_EXT:
95 supported = is_desktop_gl && e->EXT_texture_mirror_clamp
96 && (target != GL_TEXTURE_RECTANGLE_NV)
97 && (target != GL_TEXTURE_EXTERNAL_OES);
98 break;
99
100 default:
101 supported = false;
102 break;
103 }
104
105 if (!supported)
106 _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(param=0x%x)", wrap );
107
108 return supported;
109 }
110
111
112 /**
113 * Get current texture object for given target.
114 * Return NULL if any error (and record the error).
115 * Note that this is different from _mesa_select_tex_object() in that proxy
116 * targets are not accepted.
117 * Only the glGetTexLevelParameter() functions accept proxy targets.
118 */
119 static struct gl_texture_object *
120 get_texobj(struct gl_context *ctx, GLenum target, GLboolean get)
121 {
122 struct gl_texture_unit *texUnit;
123
124 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
125 _mesa_error(ctx, GL_INVALID_OPERATION,
126 "gl%sTexParameter(current unit)", get ? "Get" : "");
127 return NULL;
128 }
129
130 texUnit = _mesa_get_current_tex_unit(ctx);
131
132 switch (target) {
133 case GL_TEXTURE_1D:
134 if (_mesa_is_desktop_gl(ctx))
135 return texUnit->CurrentTex[TEXTURE_1D_INDEX];
136 break;
137 case GL_TEXTURE_2D:
138 return texUnit->CurrentTex[TEXTURE_2D_INDEX];
139 case GL_TEXTURE_3D:
140 if (ctx->API != API_OPENGLES)
141 return texUnit->CurrentTex[TEXTURE_3D_INDEX];
142 break;
143 case GL_TEXTURE_CUBE_MAP:
144 if (ctx->Extensions.ARB_texture_cube_map) {
145 return texUnit->CurrentTex[TEXTURE_CUBE_INDEX];
146 }
147 break;
148 case GL_TEXTURE_RECTANGLE_NV:
149 if (_mesa_is_desktop_gl(ctx)
150 && ctx->Extensions.NV_texture_rectangle) {
151 return texUnit->CurrentTex[TEXTURE_RECT_INDEX];
152 }
153 break;
154 case GL_TEXTURE_1D_ARRAY_EXT:
155 if (_mesa_is_desktop_gl(ctx)
156 && (ctx->Extensions.MESA_texture_array ||
157 ctx->Extensions.EXT_texture_array)) {
158 return texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX];
159 }
160 break;
161 case GL_TEXTURE_2D_ARRAY_EXT:
162 if ((_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx))
163 && (ctx->Extensions.MESA_texture_array ||
164 ctx->Extensions.EXT_texture_array)) {
165 return texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX];
166 }
167 break;
168 case GL_TEXTURE_EXTERNAL_OES:
169 if (_mesa_is_gles(ctx) && ctx->Extensions.OES_EGL_image_external) {
170 return texUnit->CurrentTex[TEXTURE_EXTERNAL_INDEX];
171 }
172 break;
173 case GL_TEXTURE_CUBE_MAP_ARRAY:
174 if (ctx->Extensions.ARB_texture_cube_map_array) {
175 return texUnit->CurrentTex[TEXTURE_CUBE_ARRAY_INDEX];
176 }
177 break;
178 case GL_TEXTURE_2D_MULTISAMPLE:
179 if (ctx->Extensions.ARB_texture_multisample) {
180 return texUnit->CurrentTex[TEXTURE_2D_MULTISAMPLE_INDEX];
181 }
182 break;
183 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
184 if (ctx->Extensions.ARB_texture_multisample) {
185 return texUnit->CurrentTex[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX];
186 }
187 break;
188 default:
189 ;
190 }
191
192 _mesa_error(ctx, GL_INVALID_ENUM,
193 "gl%sTexParameter(target)", get ? "Get" : "");
194 return NULL;
195 }
196
197
198 /**
199 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
200 * \return -1 if error.
201 */
202 static GLint
203 comp_to_swizzle(GLenum comp)
204 {
205 switch (comp) {
206 case GL_RED:
207 return SWIZZLE_X;
208 case GL_GREEN:
209 return SWIZZLE_Y;
210 case GL_BLUE:
211 return SWIZZLE_Z;
212 case GL_ALPHA:
213 return SWIZZLE_W;
214 case GL_ZERO:
215 return SWIZZLE_ZERO;
216 case GL_ONE:
217 return SWIZZLE_ONE;
218 default:
219 return -1;
220 }
221 }
222
223
224 static void
225 set_swizzle_component(GLuint *swizzle, GLuint comp, GLuint swz)
226 {
227 ASSERT(comp < 4);
228 ASSERT(swz <= SWIZZLE_NIL);
229 {
230 GLuint mask = 0x7 << (3 * comp);
231 GLuint s = (*swizzle & ~mask) | (swz << (3 * comp));
232 *swizzle = s;
233 }
234 }
235
236
237 /**
238 * This is called just prior to changing any texture object state which
239 * will not effect texture completeness.
240 */
241 static inline void
242 flush(struct gl_context *ctx)
243 {
244 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
245 }
246
247
248 /**
249 * This is called just prior to changing any texture object state which
250 * can effect texture completeness (texture base level, max level).
251 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
252 * state flag and then mark the texture object as 'incomplete' so that any
253 * per-texture derived state gets recomputed.
254 */
255 static inline void
256 incomplete(struct gl_context *ctx, struct gl_texture_object *texObj)
257 {
258 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
259 _mesa_dirty_texobj(ctx, texObj, GL_TRUE);
260 }
261
262
263 static GLboolean
264 target_allows_setting_sampler_parameters(GLenum target)
265 {
266 switch (target) {
267 case GL_TEXTURE_2D_MULTISAMPLE:
268 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
269 return GL_FALSE;
270
271 default:
272 return GL_TRUE;
273 }
274 }
275
276
277 /**
278 * Set an integer-valued texture parameter
279 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
280 */
281 static GLboolean
282 set_tex_parameteri(struct gl_context *ctx,
283 struct gl_texture_object *texObj,
284 GLenum pname, const GLint *params)
285 {
286 switch (pname) {
287 case GL_TEXTURE_MIN_FILTER:
288 if (!target_allows_setting_sampler_parameters(texObj->Target))
289 goto invalid_operation;
290
291 if (texObj->Sampler.MinFilter == params[0])
292 return GL_FALSE;
293 switch (params[0]) {
294 case GL_NEAREST:
295 case GL_LINEAR:
296 flush(ctx);
297 texObj->Sampler.MinFilter = params[0];
298 return GL_TRUE;
299 case GL_NEAREST_MIPMAP_NEAREST:
300 case GL_LINEAR_MIPMAP_NEAREST:
301 case GL_NEAREST_MIPMAP_LINEAR:
302 case GL_LINEAR_MIPMAP_LINEAR:
303 if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
304 texObj->Target != GL_TEXTURE_EXTERNAL_OES) {
305 flush(ctx);
306 texObj->Sampler.MinFilter = params[0];
307 return GL_TRUE;
308 }
309 /* fall-through */
310 default:
311 goto invalid_param;
312 }
313 return GL_FALSE;
314
315 case GL_TEXTURE_MAG_FILTER:
316 if (!target_allows_setting_sampler_parameters(texObj->Target))
317 goto invalid_operation;
318
319 if (texObj->Sampler.MagFilter == params[0])
320 return GL_FALSE;
321 switch (params[0]) {
322 case GL_NEAREST:
323 case GL_LINEAR:
324 flush(ctx); /* does not effect completeness */
325 texObj->Sampler.MagFilter = params[0];
326 return GL_TRUE;
327 default:
328 goto invalid_param;
329 }
330 return GL_FALSE;
331
332 case GL_TEXTURE_WRAP_S:
333 if (!target_allows_setting_sampler_parameters(texObj->Target))
334 goto invalid_operation;
335
336 if (texObj->Sampler.WrapS == params[0])
337 return GL_FALSE;
338 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
339 flush(ctx);
340 texObj->Sampler.WrapS = params[0];
341 return GL_TRUE;
342 }
343 return GL_FALSE;
344
345 case GL_TEXTURE_WRAP_T:
346 if (!target_allows_setting_sampler_parameters(texObj->Target))
347 goto invalid_operation;
348
349 if (texObj->Sampler.WrapT == params[0])
350 return GL_FALSE;
351 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
352 flush(ctx);
353 texObj->Sampler.WrapT = params[0];
354 return GL_TRUE;
355 }
356 return GL_FALSE;
357
358 case GL_TEXTURE_WRAP_R:
359 if (!target_allows_setting_sampler_parameters(texObj->Target))
360 goto invalid_operation;
361
362 if (texObj->Sampler.WrapR == params[0])
363 return GL_FALSE;
364 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
365 flush(ctx);
366 texObj->Sampler.WrapR = params[0];
367 return GL_TRUE;
368 }
369 return GL_FALSE;
370
371 case GL_TEXTURE_BASE_LEVEL:
372 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
373 goto invalid_pname;
374
375 if (texObj->BaseLevel == params[0])
376 return GL_FALSE;
377
378 if ((texObj->Target == GL_TEXTURE_2D_MULTISAMPLE ||
379 texObj->Target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) && params[0] != 0)
380 goto invalid_operation;
381
382 if (params[0] < 0 ||
383 (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] != 0)) {
384 _mesa_error(ctx, GL_INVALID_VALUE,
385 "glTexParameter(param=%d)", params[0]);
386 return GL_FALSE;
387 }
388 incomplete(ctx, texObj);
389
390 /** See note about ARB_texture_storage below */
391 if (texObj->Immutable)
392 texObj->BaseLevel = MIN2(texObj->ImmutableLevels - 1, params[0]);
393 else
394 texObj->BaseLevel = params[0];
395
396 return GL_TRUE;
397
398 case GL_TEXTURE_MAX_LEVEL:
399 if (texObj->MaxLevel == params[0])
400 return GL_FALSE;
401
402 if (params[0] < 0 || texObj->Target == GL_TEXTURE_RECTANGLE_ARB) {
403 _mesa_error(ctx, GL_INVALID_VALUE,
404 "glTexParameter(param=%d)", params[0]);
405 return GL_FALSE;
406 }
407 incomplete(ctx, texObj);
408
409 /** From ARB_texture_storage:
410 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
411 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
412 * the range [level_base, <levels> - 1], where <levels> is the parameter
413 * passed the call to TexStorage* for the texture object.
414 */
415 if (texObj->Immutable)
416 texObj->MaxLevel = CLAMP(params[0], texObj->BaseLevel,
417 texObj->ImmutableLevels - 1);
418 else
419 texObj->MaxLevel = params[0];
420
421 return GL_TRUE;
422
423 case GL_GENERATE_MIPMAP_SGIS:
424 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
425 goto invalid_pname;
426
427 if (params[0] && texObj->Target == GL_TEXTURE_EXTERNAL_OES)
428 goto invalid_param;
429 if (texObj->GenerateMipmap != params[0]) {
430 /* no flush() */
431 texObj->GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
432 return GL_TRUE;
433 }
434 return GL_FALSE;
435
436 case GL_TEXTURE_COMPARE_MODE_ARB:
437 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow)
438 || _mesa_is_gles3(ctx)) {
439
440 if (!target_allows_setting_sampler_parameters(texObj->Target))
441 goto invalid_operation;
442
443 if (texObj->Sampler.CompareMode == params[0])
444 return GL_FALSE;
445 if (params[0] == GL_NONE ||
446 params[0] == GL_COMPARE_R_TO_TEXTURE_ARB) {
447 flush(ctx);
448 texObj->Sampler.CompareMode = params[0];
449 return GL_TRUE;
450 }
451 goto invalid_param;
452 }
453 goto invalid_pname;
454
455 case GL_TEXTURE_COMPARE_FUNC_ARB:
456 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow)
457 || _mesa_is_gles3(ctx)) {
458
459 if (!target_allows_setting_sampler_parameters(texObj->Target))
460 goto invalid_operation;
461
462 if (texObj->Sampler.CompareFunc == params[0])
463 return GL_FALSE;
464 switch (params[0]) {
465 case GL_LEQUAL:
466 case GL_GEQUAL:
467 case GL_EQUAL:
468 case GL_NOTEQUAL:
469 case GL_LESS:
470 case GL_GREATER:
471 case GL_ALWAYS:
472 case GL_NEVER:
473 flush(ctx);
474 texObj->Sampler.CompareFunc = params[0];
475 return GL_TRUE;
476 default:
477 goto invalid_param;
478 }
479 }
480 goto invalid_pname;
481
482 case GL_DEPTH_TEXTURE_MODE_ARB:
483 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
484 * existed in OpenGL ES.
485 */
486 if (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_depth_texture) {
487 if (texObj->DepthMode == params[0])
488 return GL_FALSE;
489 if (params[0] == GL_LUMINANCE ||
490 params[0] == GL_INTENSITY ||
491 params[0] == GL_ALPHA ||
492 (ctx->Extensions.ARB_texture_rg && params[0] == GL_RED)) {
493 flush(ctx);
494 texObj->DepthMode = params[0];
495 return GL_TRUE;
496 }
497 goto invalid_param;
498 }
499 goto invalid_pname;
500
501 case GL_TEXTURE_CROP_RECT_OES:
502 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
503 goto invalid_pname;
504
505 texObj->CropRect[0] = params[0];
506 texObj->CropRect[1] = params[1];
507 texObj->CropRect[2] = params[2];
508 texObj->CropRect[3] = params[3];
509 return GL_TRUE;
510
511 case GL_TEXTURE_SWIZZLE_R_EXT:
512 case GL_TEXTURE_SWIZZLE_G_EXT:
513 case GL_TEXTURE_SWIZZLE_B_EXT:
514 case GL_TEXTURE_SWIZZLE_A_EXT:
515 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_swizzle)
516 || _mesa_is_gles3(ctx)) {
517 const GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
518 const GLint swz = comp_to_swizzle(params[0]);
519 if (swz < 0) {
520 _mesa_error(ctx, GL_INVALID_OPERATION,
521 "glTexParameter(swizzle 0x%x)", params[0]);
522 return GL_FALSE;
523 }
524 ASSERT(comp < 4);
525
526 flush(ctx);
527 texObj->Swizzle[comp] = params[0];
528 set_swizzle_component(&texObj->_Swizzle, comp, swz);
529 return GL_TRUE;
530 }
531 goto invalid_pname;
532
533 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
534 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_swizzle)
535 || _mesa_is_gles3(ctx)) {
536 GLuint comp;
537 flush(ctx);
538 for (comp = 0; comp < 4; comp++) {
539 const GLint swz = comp_to_swizzle(params[comp]);
540 if (swz >= 0) {
541 texObj->Swizzle[comp] = params[comp];
542 set_swizzle_component(&texObj->_Swizzle, comp, swz);
543 }
544 else {
545 _mesa_error(ctx, GL_INVALID_OPERATION,
546 "glTexParameter(swizzle 0x%x)", params[comp]);
547 return GL_FALSE;
548 }
549 }
550 return GL_TRUE;
551 }
552 goto invalid_pname;
553
554 case GL_TEXTURE_SRGB_DECODE_EXT:
555 if (_mesa_is_desktop_gl(ctx)
556 && ctx->Extensions.EXT_texture_sRGB_decode) {
557 GLenum decode = params[0];
558
559 if (!target_allows_setting_sampler_parameters(texObj->Target))
560 goto invalid_operation;
561
562 if (decode == GL_DECODE_EXT || decode == GL_SKIP_DECODE_EXT) {
563 if (texObj->Sampler.sRGBDecode != decode) {
564 flush(ctx);
565 texObj->Sampler.sRGBDecode = decode;
566 }
567 return GL_TRUE;
568 }
569 }
570 goto invalid_pname;
571
572 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
573 if (_mesa_is_desktop_gl(ctx)
574 && ctx->Extensions.AMD_seamless_cubemap_per_texture) {
575 GLenum param = params[0];
576
577 if (!target_allows_setting_sampler_parameters(texObj->Target))
578 goto invalid_operation;
579
580 if (param != GL_TRUE && param != GL_FALSE) {
581 goto invalid_param;
582 }
583 if (param != texObj->Sampler.CubeMapSeamless) {
584 flush(ctx);
585 texObj->Sampler.CubeMapSeamless = param;
586 }
587 return GL_TRUE;
588 }
589 goto invalid_pname;
590
591 default:
592 goto invalid_pname;
593 }
594
595 invalid_pname:
596 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=%s)",
597 _mesa_lookup_enum_by_nr(pname));
598 return GL_FALSE;
599
600 invalid_param:
601 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(param=%s)",
602 _mesa_lookup_enum_by_nr(params[0]));
603 return GL_FALSE;
604
605 invalid_operation:
606 _mesa_error(ctx, GL_INVALID_OPERATION, "glTexParameter(pname=%s)",
607 _mesa_lookup_enum_by_nr(pname));
608 return GL_FALSE;
609 }
610
611
612 /**
613 * Set a float-valued texture parameter
614 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
615 */
616 static GLboolean
617 set_tex_parameterf(struct gl_context *ctx,
618 struct gl_texture_object *texObj,
619 GLenum pname, const GLfloat *params)
620 {
621 switch (pname) {
622 case GL_TEXTURE_MIN_LOD:
623 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
624 goto invalid_pname;
625
626 if (!target_allows_setting_sampler_parameters(texObj->Target))
627 goto invalid_operation;
628
629 if (texObj->Sampler.MinLod == params[0])
630 return GL_FALSE;
631 flush(ctx);
632 texObj->Sampler.MinLod = params[0];
633 return GL_TRUE;
634
635 case GL_TEXTURE_MAX_LOD:
636 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
637 goto invalid_pname;
638
639 if (!target_allows_setting_sampler_parameters(texObj->Target))
640 goto invalid_operation;
641
642 if (texObj->Sampler.MaxLod == params[0])
643 return GL_FALSE;
644 flush(ctx);
645 texObj->Sampler.MaxLod = params[0];
646 return GL_TRUE;
647
648 case GL_TEXTURE_PRIORITY:
649 if (ctx->API != API_OPENGL_COMPAT)
650 goto invalid_pname;
651
652 flush(ctx);
653 texObj->Priority = CLAMP(params[0], 0.0F, 1.0F);
654 return GL_TRUE;
655
656 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
657 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
658 if (!target_allows_setting_sampler_parameters(texObj->Target))
659 goto invalid_operation;
660
661 if (texObj->Sampler.MaxAnisotropy == params[0])
662 return GL_FALSE;
663 if (params[0] < 1.0) {
664 _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
665 return GL_FALSE;
666 }
667 flush(ctx);
668 /* clamp to max, that's what NVIDIA does */
669 texObj->Sampler.MaxAnisotropy = MIN2(params[0],
670 ctx->Const.MaxTextureMaxAnisotropy);
671 return GL_TRUE;
672 }
673 else {
674 static GLuint count = 0;
675 if (count++ < 10)
676 goto invalid_pname;
677 }
678 return GL_FALSE;
679
680 case GL_TEXTURE_LOD_BIAS:
681 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias.
682 * It was removed in core-profile, and it has never existed in OpenGL
683 * ES.
684 */
685 if (ctx->API != API_OPENGL_COMPAT)
686 goto invalid_pname;
687
688 if (!target_allows_setting_sampler_parameters(texObj->Target))
689 goto invalid_operation;
690
691 if (texObj->Sampler.LodBias != params[0]) {
692 flush(ctx);
693 texObj->Sampler.LodBias = params[0];
694 return GL_TRUE;
695 }
696 break;
697
698 case GL_TEXTURE_BORDER_COLOR:
699 if (!_mesa_is_desktop_gl(ctx))
700 goto invalid_pname;
701
702 if (!target_allows_setting_sampler_parameters(texObj->Target))
703 goto invalid_operation;
704
705 flush(ctx);
706 /* ARB_texture_float disables clamping */
707 if (ctx->Extensions.ARB_texture_float) {
708 texObj->Sampler.BorderColor.f[RCOMP] = params[0];
709 texObj->Sampler.BorderColor.f[GCOMP] = params[1];
710 texObj->Sampler.BorderColor.f[BCOMP] = params[2];
711 texObj->Sampler.BorderColor.f[ACOMP] = params[3];
712 } else {
713 texObj->Sampler.BorderColor.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F);
714 texObj->Sampler.BorderColor.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F);
715 texObj->Sampler.BorderColor.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F);
716 texObj->Sampler.BorderColor.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F);
717 }
718 return GL_TRUE;
719
720 default:
721 goto invalid_pname;
722 }
723 return GL_FALSE;
724
725 invalid_pname:
726 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=%s)",
727 _mesa_lookup_enum_by_nr(pname));
728 return GL_FALSE;
729
730 invalid_operation:
731 _mesa_error(ctx, GL_INVALID_OPERATION, "glTexParameter(pname=%s)",
732 _mesa_lookup_enum_by_nr(pname));
733 return GL_FALSE;
734 }
735
736
737 void GLAPIENTRY
738 _mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
739 {
740 GLboolean need_update;
741 struct gl_texture_object *texObj;
742 GET_CURRENT_CONTEXT(ctx);
743
744 texObj = get_texobj(ctx, target, GL_FALSE);
745 if (!texObj)
746 return;
747
748 switch (pname) {
749 case GL_TEXTURE_MIN_FILTER:
750 case GL_TEXTURE_MAG_FILTER:
751 case GL_TEXTURE_WRAP_S:
752 case GL_TEXTURE_WRAP_T:
753 case GL_TEXTURE_WRAP_R:
754 case GL_TEXTURE_BASE_LEVEL:
755 case GL_TEXTURE_MAX_LEVEL:
756 case GL_GENERATE_MIPMAP_SGIS:
757 case GL_TEXTURE_COMPARE_MODE_ARB:
758 case GL_TEXTURE_COMPARE_FUNC_ARB:
759 case GL_DEPTH_TEXTURE_MODE_ARB:
760 case GL_TEXTURE_SRGB_DECODE_EXT:
761 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
762 case GL_TEXTURE_SWIZZLE_R_EXT:
763 case GL_TEXTURE_SWIZZLE_G_EXT:
764 case GL_TEXTURE_SWIZZLE_B_EXT:
765 case GL_TEXTURE_SWIZZLE_A_EXT:
766 {
767 GLint p[4];
768 p[0] = (param > 0) ?
769 ((param > INT_MAX) ? INT_MAX : (GLint) (param + 0.5)) :
770 ((param < INT_MIN) ? INT_MIN : (GLint) (param - 0.5));
771
772 p[1] = p[2] = p[3] = 0;
773 need_update = set_tex_parameteri(ctx, texObj, pname, p);
774 }
775 break;
776 default:
777 {
778 /* this will generate an error if pname is illegal */
779 GLfloat p[4];
780 p[0] = param;
781 p[1] = p[2] = p[3] = 0.0F;
782 need_update = set_tex_parameterf(ctx, texObj, pname, p);
783 }
784 }
785
786 if (ctx->Driver.TexParameter && need_update) {
787 ctx->Driver.TexParameter(ctx, target, texObj, pname, &param);
788 }
789 }
790
791
792 void GLAPIENTRY
793 _mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
794 {
795 GLboolean need_update;
796 struct gl_texture_object *texObj;
797 GET_CURRENT_CONTEXT(ctx);
798
799 texObj = get_texobj(ctx, target, GL_FALSE);
800 if (!texObj)
801 return;
802
803 switch (pname) {
804 case GL_TEXTURE_MIN_FILTER:
805 case GL_TEXTURE_MAG_FILTER:
806 case GL_TEXTURE_WRAP_S:
807 case GL_TEXTURE_WRAP_T:
808 case GL_TEXTURE_WRAP_R:
809 case GL_TEXTURE_BASE_LEVEL:
810 case GL_TEXTURE_MAX_LEVEL:
811 case GL_GENERATE_MIPMAP_SGIS:
812 case GL_TEXTURE_COMPARE_MODE_ARB:
813 case GL_TEXTURE_COMPARE_FUNC_ARB:
814 case GL_DEPTH_TEXTURE_MODE_ARB:
815 case GL_TEXTURE_SRGB_DECODE_EXT:
816 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
817 {
818 /* convert float param to int */
819 GLint p[4];
820 p[0] = (GLint) params[0];
821 p[1] = p[2] = p[3] = 0;
822 need_update = set_tex_parameteri(ctx, texObj, pname, p);
823 }
824 break;
825 case GL_TEXTURE_CROP_RECT_OES:
826 {
827 /* convert float params to int */
828 GLint iparams[4];
829 iparams[0] = (GLint) params[0];
830 iparams[1] = (GLint) params[1];
831 iparams[2] = (GLint) params[2];
832 iparams[3] = (GLint) params[3];
833 need_update = set_tex_parameteri(ctx, texObj, pname, iparams);
834 }
835 break;
836 case GL_TEXTURE_SWIZZLE_R_EXT:
837 case GL_TEXTURE_SWIZZLE_G_EXT:
838 case GL_TEXTURE_SWIZZLE_B_EXT:
839 case GL_TEXTURE_SWIZZLE_A_EXT:
840 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
841 {
842 GLint p[4] = {0, 0, 0, 0};
843 p[0] = (GLint) params[0];
844 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT) {
845 p[1] = (GLint) params[1];
846 p[2] = (GLint) params[2];
847 p[3] = (GLint) params[3];
848 }
849 need_update = set_tex_parameteri(ctx, texObj, pname, p);
850 }
851 break;
852 default:
853 /* this will generate an error if pname is illegal */
854 need_update = set_tex_parameterf(ctx, texObj, pname, params);
855 }
856
857 if (ctx->Driver.TexParameter && need_update) {
858 ctx->Driver.TexParameter(ctx, target, texObj, pname, params);
859 }
860 }
861
862
863 void GLAPIENTRY
864 _mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
865 {
866 GLboolean need_update;
867 struct gl_texture_object *texObj;
868 GET_CURRENT_CONTEXT(ctx);
869
870 texObj = get_texobj(ctx, target, GL_FALSE);
871 if (!texObj)
872 return;
873
874 switch (pname) {
875 case GL_TEXTURE_MIN_LOD:
876 case GL_TEXTURE_MAX_LOD:
877 case GL_TEXTURE_PRIORITY:
878 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
879 case GL_TEXTURE_LOD_BIAS:
880 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
881 {
882 GLfloat fparam[4];
883 fparam[0] = (GLfloat) param;
884 fparam[1] = fparam[2] = fparam[3] = 0.0F;
885 /* convert int param to float */
886 need_update = set_tex_parameterf(ctx, texObj, pname, fparam);
887 }
888 break;
889 default:
890 /* this will generate an error if pname is illegal */
891 {
892 GLint iparam[4];
893 iparam[0] = param;
894 iparam[1] = iparam[2] = iparam[3] = 0;
895 need_update = set_tex_parameteri(ctx, texObj, pname, iparam);
896 }
897 }
898
899 if (ctx->Driver.TexParameter && need_update) {
900 GLfloat fparam = (GLfloat) param;
901 ctx->Driver.TexParameter(ctx, target, texObj, pname, &fparam);
902 }
903 }
904
905
906 void GLAPIENTRY
907 _mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
908 {
909 GLboolean need_update;
910 struct gl_texture_object *texObj;
911 GET_CURRENT_CONTEXT(ctx);
912
913 texObj = get_texobj(ctx, target, GL_FALSE);
914 if (!texObj)
915 return;
916
917 switch (pname) {
918 case GL_TEXTURE_BORDER_COLOR:
919 {
920 /* convert int params to float */
921 GLfloat fparams[4];
922 fparams[0] = INT_TO_FLOAT(params[0]);
923 fparams[1] = INT_TO_FLOAT(params[1]);
924 fparams[2] = INT_TO_FLOAT(params[2]);
925 fparams[3] = INT_TO_FLOAT(params[3]);
926 need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
927 }
928 break;
929 case GL_TEXTURE_MIN_LOD:
930 case GL_TEXTURE_MAX_LOD:
931 case GL_TEXTURE_PRIORITY:
932 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
933 case GL_TEXTURE_LOD_BIAS:
934 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
935 {
936 /* convert int param to float */
937 GLfloat fparams[4];
938 fparams[0] = (GLfloat) params[0];
939 fparams[1] = fparams[2] = fparams[3] = 0.0F;
940 need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
941 }
942 break;
943 default:
944 /* this will generate an error if pname is illegal */
945 need_update = set_tex_parameteri(ctx, texObj, pname, params);
946 }
947
948 if (ctx->Driver.TexParameter && need_update) {
949 GLfloat fparams[4];
950 fparams[0] = INT_TO_FLOAT(params[0]);
951 if (pname == GL_TEXTURE_BORDER_COLOR ||
952 pname == GL_TEXTURE_CROP_RECT_OES) {
953 fparams[1] = INT_TO_FLOAT(params[1]);
954 fparams[2] = INT_TO_FLOAT(params[2]);
955 fparams[3] = INT_TO_FLOAT(params[3]);
956 }
957 ctx->Driver.TexParameter(ctx, target, texObj, pname, fparams);
958 }
959 }
960
961
962 /**
963 * Set tex parameter to integer value(s). Primarily intended to set
964 * integer-valued texture border color (for integer-valued textures).
965 * New in GL 3.0.
966 */
967 void GLAPIENTRY
968 _mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
969 {
970 struct gl_texture_object *texObj;
971 GET_CURRENT_CONTEXT(ctx);
972
973 texObj = get_texobj(ctx, target, GL_FALSE);
974 if (!texObj)
975 return;
976
977 switch (pname) {
978 case GL_TEXTURE_BORDER_COLOR:
979 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
980 /* set the integer-valued border color */
981 COPY_4V(texObj->Sampler.BorderColor.i, params);
982 break;
983 default:
984 _mesa_TexParameteriv(target, pname, params);
985 break;
986 }
987 /* XXX no driver hook for TexParameterIiv() yet */
988 }
989
990
991 /**
992 * Set tex parameter to unsigned integer value(s). Primarily intended to set
993 * uint-valued texture border color (for integer-valued textures).
994 * New in GL 3.0
995 */
996 void GLAPIENTRY
997 _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
998 {
999 struct gl_texture_object *texObj;
1000 GET_CURRENT_CONTEXT(ctx);
1001
1002 texObj = get_texobj(ctx, target, GL_FALSE);
1003 if (!texObj)
1004 return;
1005
1006 switch (pname) {
1007 case GL_TEXTURE_BORDER_COLOR:
1008 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1009 /* set the unsigned integer-valued border color */
1010 COPY_4V(texObj->Sampler.BorderColor.ui, params);
1011 break;
1012 default:
1013 _mesa_TexParameteriv(target, pname, (const GLint *) params);
1014 break;
1015 }
1016 /* XXX no driver hook for TexParameterIuiv() yet */
1017 }
1018
1019
1020 static GLboolean
1021 legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target)
1022 {
1023 switch (target) {
1024 case GL_TEXTURE_1D:
1025 case GL_PROXY_TEXTURE_1D:
1026 case GL_TEXTURE_2D:
1027 case GL_PROXY_TEXTURE_2D:
1028 case GL_TEXTURE_3D:
1029 case GL_PROXY_TEXTURE_3D:
1030 return GL_TRUE;
1031 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
1032 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
1033 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
1034 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
1035 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
1036 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
1037 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
1038 return ctx->Extensions.ARB_texture_cube_map;
1039 case GL_TEXTURE_RECTANGLE_NV:
1040 case GL_PROXY_TEXTURE_RECTANGLE_NV:
1041 return ctx->Extensions.NV_texture_rectangle;
1042 case GL_TEXTURE_1D_ARRAY_EXT:
1043 case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
1044 case GL_TEXTURE_2D_ARRAY_EXT:
1045 case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
1046 return (ctx->Extensions.MESA_texture_array ||
1047 ctx->Extensions.EXT_texture_array);
1048 case GL_TEXTURE_BUFFER:
1049 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1050 * but not in earlier versions that expose ARB_texture_buffer_object.
1051 *
1052 * From the ARB_texture_buffer_object spec:
1053 * "(7) Do buffer textures support texture parameters (TexParameter) or
1054 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1055 *
1056 * RESOLVED: No. [...] Note that the spec edits above don't add
1057 * explicit error language for any of these cases. That is because
1058 * each of the functions enumerate the set of valid <target>
1059 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1060 * these cases means that target is not legal, and an INVALID_ENUM
1061 * error should be generated."
1062 *
1063 * From the OpenGL 3.1 spec:
1064 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1065 */
1066 return ctx->API == API_OPENGL_CORE && ctx->Version >= 31;
1067 case GL_TEXTURE_2D_MULTISAMPLE:
1068 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
1069 case GL_PROXY_TEXTURE_2D_MULTISAMPLE:
1070 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY:
1071 return ctx->Extensions.ARB_texture_multisample;
1072 default:
1073 return GL_FALSE;
1074 }
1075 }
1076
1077
1078 static void
1079 get_tex_level_parameter_image(struct gl_context *ctx,
1080 const struct gl_texture_object *texObj,
1081 GLenum target, GLint level,
1082 GLenum pname, GLint *params)
1083 {
1084 const struct gl_texture_image *img = NULL;
1085 gl_format texFormat;
1086
1087 img = _mesa_select_tex_image(ctx, texObj, target, level);
1088 if (!img || img->TexFormat == MESA_FORMAT_NONE) {
1089 /* undefined texture image */
1090 if (pname == GL_TEXTURE_COMPONENTS)
1091 *params = 1;
1092 else
1093 *params = 0;
1094 return;
1095 }
1096
1097 texFormat = img->TexFormat;
1098
1099 switch (pname) {
1100 case GL_TEXTURE_WIDTH:
1101 *params = img->Width;
1102 break;
1103 case GL_TEXTURE_HEIGHT:
1104 *params = img->Height;
1105 break;
1106 case GL_TEXTURE_DEPTH:
1107 *params = img->Depth;
1108 break;
1109 case GL_TEXTURE_INTERNAL_FORMAT:
1110 if (_mesa_is_format_compressed(texFormat)) {
1111 /* need to return the actual compressed format */
1112 *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
1113 }
1114 else {
1115 /* If the true internal format is not compressed but the user
1116 * requested a generic compressed format, we have to return the
1117 * generic base format that matches.
1118 *
1119 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1120 *
1121 * "If no specific compressed format is available,
1122 * internalformat is instead replaced by the corresponding base
1123 * internal format."
1124 *
1125 * Otherwise just return the user's requested internal format
1126 */
1127 const GLenum f =
1128 _mesa_gl_compressed_format_base_format(img->InternalFormat);
1129
1130 *params = (f != 0) ? f : img->InternalFormat;
1131 }
1132 break;
1133 case GL_TEXTURE_BORDER:
1134 *params = img->Border;
1135 break;
1136 case GL_TEXTURE_RED_SIZE:
1137 case GL_TEXTURE_GREEN_SIZE:
1138 case GL_TEXTURE_BLUE_SIZE:
1139 case GL_TEXTURE_ALPHA_SIZE:
1140 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1141 *params = _mesa_get_format_bits(texFormat, pname);
1142 else
1143 *params = 0;
1144 break;
1145 case GL_TEXTURE_INTENSITY_SIZE:
1146 case GL_TEXTURE_LUMINANCE_SIZE:
1147 if (_mesa_base_format_has_channel(img->_BaseFormat, pname)) {
1148 *params = _mesa_get_format_bits(texFormat, pname);
1149 if (*params == 0) {
1150 /* intensity or luminance is probably stored as RGB[A] */
1151 *params = MIN2(_mesa_get_format_bits(texFormat,
1152 GL_TEXTURE_RED_SIZE),
1153 _mesa_get_format_bits(texFormat,
1154 GL_TEXTURE_GREEN_SIZE));
1155 }
1156 }
1157 else {
1158 *params = 0;
1159 }
1160 break;
1161 case GL_TEXTURE_DEPTH_SIZE_ARB:
1162 if (!ctx->Extensions.ARB_depth_texture)
1163 goto invalid_pname;
1164 *params = _mesa_get_format_bits(texFormat, pname);
1165 break;
1166 case GL_TEXTURE_STENCIL_SIZE_EXT:
1167 if (!ctx->Extensions.EXT_packed_depth_stencil &&
1168 !ctx->Extensions.ARB_framebuffer_object)
1169 goto invalid_pname;
1170 *params = _mesa_get_format_bits(texFormat, pname);
1171 break;
1172 case GL_TEXTURE_SHARED_SIZE:
1173 if (ctx->Version < 30 &&
1174 !ctx->Extensions.EXT_texture_shared_exponent)
1175 goto invalid_pname;
1176 *params = texFormat == MESA_FORMAT_RGB9_E5_FLOAT ? 5 : 0;
1177 break;
1178
1179 /* GL_ARB_texture_compression */
1180 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1181 if (_mesa_is_format_compressed(texFormat) &&
1182 !_mesa_is_proxy_texture(target)) {
1183 *params = _mesa_format_image_size(texFormat, img->Width,
1184 img->Height, img->Depth);
1185 }
1186 else {
1187 _mesa_error(ctx, GL_INVALID_OPERATION,
1188 "glGetTexLevelParameter[if]v(pname)");
1189 }
1190 break;
1191 case GL_TEXTURE_COMPRESSED:
1192 *params = (GLint) _mesa_is_format_compressed(texFormat);
1193 break;
1194
1195 /* GL_ARB_texture_float */
1196 case GL_TEXTURE_RED_TYPE_ARB:
1197 case GL_TEXTURE_GREEN_TYPE_ARB:
1198 case GL_TEXTURE_BLUE_TYPE_ARB:
1199 case GL_TEXTURE_ALPHA_TYPE_ARB:
1200 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1201 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1202 case GL_TEXTURE_DEPTH_TYPE_ARB:
1203 if (!ctx->Extensions.ARB_texture_float)
1204 goto invalid_pname;
1205 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1206 *params = _mesa_get_format_datatype(texFormat);
1207 else
1208 *params = GL_NONE;
1209 break;
1210
1211 /* GL_ARB_texture_multisample */
1212 case GL_TEXTURE_SAMPLES:
1213 if (!ctx->Extensions.ARB_texture_multisample)
1214 goto invalid_pname;
1215 *params = img->NumSamples;
1216 break;
1217
1218 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1219 if (!ctx->Extensions.ARB_texture_multisample)
1220 goto invalid_pname;
1221 *params = img->FixedSampleLocations;
1222 break;
1223
1224 default:
1225 goto invalid_pname;
1226 }
1227
1228 /* no error if we get here */
1229 return;
1230
1231 invalid_pname:
1232 _mesa_error(ctx, GL_INVALID_ENUM,
1233 "glGetTexLevelParameter[if]v(pname=%s)",
1234 _mesa_lookup_enum_by_nr(pname));
1235 }
1236
1237
1238 static void
1239 get_tex_level_parameter_buffer(struct gl_context *ctx,
1240 const struct gl_texture_object *texObj,
1241 GLenum pname, GLint *params)
1242 {
1243 const struct gl_buffer_object *bo = texObj->BufferObject;
1244 gl_format texFormat = texObj->_BufferObjectFormat;
1245 GLenum internalFormat = texObj->BufferObjectFormat;
1246 GLenum baseFormat = _mesa_get_format_base_format(texFormat);
1247
1248 if (!bo) {
1249 /* undefined texture buffer object */
1250 *params = pname == GL_TEXTURE_COMPONENTS ? 1 : 0;
1251 return;
1252 }
1253
1254 switch (pname) {
1255 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
1256 *params = bo->Name;
1257 break;
1258 case GL_TEXTURE_WIDTH:
1259 *params = bo->Size;
1260 break;
1261 case GL_TEXTURE_HEIGHT:
1262 case GL_TEXTURE_DEPTH:
1263 case GL_TEXTURE_BORDER:
1264 case GL_TEXTURE_SHARED_SIZE:
1265 case GL_TEXTURE_COMPRESSED:
1266 *params = 0;
1267 break;
1268 case GL_TEXTURE_INTERNAL_FORMAT:
1269 *params = internalFormat;
1270 break;
1271 case GL_TEXTURE_RED_SIZE:
1272 case GL_TEXTURE_GREEN_SIZE:
1273 case GL_TEXTURE_BLUE_SIZE:
1274 case GL_TEXTURE_ALPHA_SIZE:
1275 if (_mesa_base_format_has_channel(baseFormat, pname))
1276 *params = _mesa_get_format_bits(texFormat, pname);
1277 else
1278 *params = 0;
1279 break;
1280 case GL_TEXTURE_INTENSITY_SIZE:
1281 case GL_TEXTURE_LUMINANCE_SIZE:
1282 if (_mesa_base_format_has_channel(baseFormat, pname)) {
1283 *params = _mesa_get_format_bits(texFormat, pname);
1284 if (*params == 0) {
1285 /* intensity or luminance is probably stored as RGB[A] */
1286 *params = MIN2(_mesa_get_format_bits(texFormat,
1287 GL_TEXTURE_RED_SIZE),
1288 _mesa_get_format_bits(texFormat,
1289 GL_TEXTURE_GREEN_SIZE));
1290 }
1291 } else {
1292 *params = 0;
1293 }
1294 break;
1295 case GL_TEXTURE_DEPTH_SIZE_ARB:
1296 case GL_TEXTURE_STENCIL_SIZE_EXT:
1297 *params = _mesa_get_format_bits(texFormat, pname);
1298 break;
1299
1300 /* GL_ARB_texture_buffer_range */
1301 case GL_TEXTURE_BUFFER_OFFSET:
1302 if (!ctx->Extensions.ARB_texture_buffer_range)
1303 goto invalid_pname;
1304 *params = texObj->BufferOffset;
1305 break;
1306 case GL_TEXTURE_BUFFER_SIZE:
1307 if (!ctx->Extensions.ARB_texture_buffer_range)
1308 goto invalid_pname;
1309 *params = (texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize;
1310 break;
1311
1312 /* GL_ARB_texture_compression */
1313 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1314 /* Always illegal for GL_TEXTURE_BUFFER */
1315 _mesa_error(ctx, GL_INVALID_OPERATION,
1316 "glGetTexLevelParameter[if]v(pname)");
1317 break;
1318
1319 /* GL_ARB_texture_float */
1320 case GL_TEXTURE_RED_TYPE_ARB:
1321 case GL_TEXTURE_GREEN_TYPE_ARB:
1322 case GL_TEXTURE_BLUE_TYPE_ARB:
1323 case GL_TEXTURE_ALPHA_TYPE_ARB:
1324 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1325 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1326 case GL_TEXTURE_DEPTH_TYPE_ARB:
1327 if (!ctx->Extensions.ARB_texture_float)
1328 goto invalid_pname;
1329 if (_mesa_base_format_has_channel(baseFormat, pname))
1330 *params = _mesa_get_format_datatype(texFormat);
1331 else
1332 *params = GL_NONE;
1333 break;
1334
1335 default:
1336 goto invalid_pname;
1337 }
1338
1339 /* no error if we get here */
1340 return;
1341
1342 invalid_pname:
1343 _mesa_error(ctx, GL_INVALID_ENUM,
1344 "glGetTexLevelParameter[if]v(pname=%s)",
1345 _mesa_lookup_enum_by_nr(pname));
1346 }
1347
1348
1349 void GLAPIENTRY
1350 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
1351 GLenum pname, GLfloat *params )
1352 {
1353 GLint iparam;
1354 _mesa_GetTexLevelParameteriv( target, level, pname, &iparam );
1355 *params = (GLfloat) iparam;
1356 }
1357
1358
1359 void GLAPIENTRY
1360 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
1361 GLenum pname, GLint *params )
1362 {
1363 const struct gl_texture_unit *texUnit;
1364 struct gl_texture_object *texObj;
1365 GLint maxLevels;
1366 GET_CURRENT_CONTEXT(ctx);
1367
1368 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
1369 _mesa_error(ctx, GL_INVALID_OPERATION,
1370 "glGetTexLevelParameteriv(current unit)");
1371 return;
1372 }
1373
1374 texUnit = _mesa_get_current_tex_unit(ctx);
1375
1376 if (!legal_get_tex_level_parameter_target(ctx, target)) {
1377 _mesa_error(ctx, GL_INVALID_ENUM,
1378 "glGetTexLevelParameter[if]v(target=0x%x)", target);
1379 return;
1380 }
1381
1382 maxLevels = _mesa_max_texture_levels(ctx, target);
1383 assert(maxLevels != 0);
1384
1385 if (level < 0 || level >= maxLevels) {
1386 _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
1387 return;
1388 }
1389
1390 texObj = _mesa_select_tex_object(ctx, texUnit, target);
1391
1392 if (target == GL_TEXTURE_BUFFER)
1393 get_tex_level_parameter_buffer(ctx, texObj, pname, params);
1394 else
1395 get_tex_level_parameter_image(ctx, texObj, target, level, pname, params);
1396 }
1397
1398
1399 void GLAPIENTRY
1400 _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
1401 {
1402 struct gl_texture_object *obj;
1403 GET_CURRENT_CONTEXT(ctx);
1404
1405 obj = get_texobj(ctx, target, GL_TRUE);
1406 if (!obj)
1407 return;
1408
1409 _mesa_lock_texture(ctx, obj);
1410 switch (pname) {
1411 case GL_TEXTURE_MAG_FILTER:
1412 *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
1413 break;
1414 case GL_TEXTURE_MIN_FILTER:
1415 *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
1416 break;
1417 case GL_TEXTURE_WRAP_S:
1418 *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
1419 break;
1420 case GL_TEXTURE_WRAP_T:
1421 *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
1422 break;
1423 case GL_TEXTURE_WRAP_R:
1424 *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
1425 break;
1426 case GL_TEXTURE_BORDER_COLOR:
1427 if (!_mesa_is_desktop_gl(ctx))
1428 goto invalid_pname;
1429
1430 if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
1431 _mesa_update_state_locked(ctx);
1432 if (_mesa_get_clamp_fragment_color(ctx)) {
1433 params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1434 params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1435 params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1436 params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
1437 }
1438 else {
1439 params[0] = obj->Sampler.BorderColor.f[0];
1440 params[1] = obj->Sampler.BorderColor.f[1];
1441 params[2] = obj->Sampler.BorderColor.f[2];
1442 params[3] = obj->Sampler.BorderColor.f[3];
1443 }
1444 break;
1445 case GL_TEXTURE_RESIDENT:
1446 if (ctx->API != API_OPENGL_COMPAT)
1447 goto invalid_pname;
1448
1449 *params = 1.0F;
1450 break;
1451 case GL_TEXTURE_PRIORITY:
1452 if (ctx->API != API_OPENGL_COMPAT)
1453 goto invalid_pname;
1454
1455 *params = obj->Priority;
1456 break;
1457 case GL_TEXTURE_MIN_LOD:
1458 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1459 goto invalid_pname;
1460
1461 *params = obj->Sampler.MinLod;
1462 break;
1463 case GL_TEXTURE_MAX_LOD:
1464 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1465 goto invalid_pname;
1466
1467 *params = obj->Sampler.MaxLod;
1468 break;
1469 case GL_TEXTURE_BASE_LEVEL:
1470 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1471 goto invalid_pname;
1472
1473 *params = (GLfloat) obj->BaseLevel;
1474 break;
1475 case GL_TEXTURE_MAX_LEVEL:
1476 *params = (GLfloat) obj->MaxLevel;
1477 break;
1478 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1479 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
1480 goto invalid_pname;
1481 *params = obj->Sampler.MaxAnisotropy;
1482 break;
1483 case GL_GENERATE_MIPMAP_SGIS:
1484 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1485 goto invalid_pname;
1486
1487 *params = (GLfloat) obj->GenerateMipmap;
1488 break;
1489 case GL_TEXTURE_COMPARE_MODE_ARB:
1490 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
1491 && !_mesa_is_gles3(ctx))
1492 goto invalid_pname;
1493 *params = (GLfloat) obj->Sampler.CompareMode;
1494 break;
1495 case GL_TEXTURE_COMPARE_FUNC_ARB:
1496 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
1497 && !_mesa_is_gles3(ctx))
1498 goto invalid_pname;
1499 *params = (GLfloat) obj->Sampler.CompareFunc;
1500 break;
1501 case GL_DEPTH_TEXTURE_MODE_ARB:
1502 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1503 * never existed in OpenGL ES.
1504 */
1505 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
1506 goto invalid_pname;
1507 *params = (GLfloat) obj->DepthMode;
1508 break;
1509 case GL_TEXTURE_LOD_BIAS:
1510 if (ctx->API != API_OPENGL_COMPAT)
1511 goto invalid_pname;
1512
1513 *params = obj->Sampler.LodBias;
1514 break;
1515 case GL_TEXTURE_CROP_RECT_OES:
1516 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
1517 goto invalid_pname;
1518
1519 params[0] = (GLfloat) obj->CropRect[0];
1520 params[1] = (GLfloat) obj->CropRect[1];
1521 params[2] = (GLfloat) obj->CropRect[2];
1522 params[3] = (GLfloat) obj->CropRect[3];
1523 break;
1524
1525 case GL_TEXTURE_SWIZZLE_R_EXT:
1526 case GL_TEXTURE_SWIZZLE_G_EXT:
1527 case GL_TEXTURE_SWIZZLE_B_EXT:
1528 case GL_TEXTURE_SWIZZLE_A_EXT:
1529 if ((!_mesa_is_desktop_gl(ctx)
1530 || !ctx->Extensions.EXT_texture_swizzle)
1531 && !_mesa_is_gles3(ctx))
1532 goto invalid_pname;
1533 *params = (GLfloat) obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
1534 break;
1535
1536 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
1537 if ((!_mesa_is_desktop_gl(ctx)
1538 || !ctx->Extensions.EXT_texture_swizzle)
1539 && !_mesa_is_gles3(ctx)) {
1540 goto invalid_pname;
1541 }
1542 else {
1543 GLuint comp;
1544 for (comp = 0; comp < 4; comp++) {
1545 params[comp] = (GLfloat) obj->Swizzle[comp];
1546 }
1547 }
1548 break;
1549
1550 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1551 if (!_mesa_is_desktop_gl(ctx)
1552 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
1553 goto invalid_pname;
1554 *params = (GLfloat) obj->Sampler.CubeMapSeamless;
1555 break;
1556
1557 case GL_TEXTURE_IMMUTABLE_FORMAT:
1558 *params = (GLfloat) obj->Immutable;
1559 break;
1560
1561 case GL_TEXTURE_IMMUTABLE_LEVELS:
1562 if (!_mesa_is_gles3(ctx))
1563 goto invalid_pname;
1564 *params = (GLfloat) obj->ImmutableLevels;
1565 break;
1566
1567 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
1568 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
1569 goto invalid_pname;
1570 *params = (GLfloat) obj->RequiredTextureImageUnits;
1571 break;
1572
1573 case GL_TEXTURE_SRGB_DECODE_EXT:
1574 if (!ctx->Extensions.EXT_texture_sRGB_decode)
1575 goto invalid_pname;
1576 *params = (GLfloat) obj->Sampler.sRGBDecode;
1577 break;
1578
1579 default:
1580 goto invalid_pname;
1581 }
1582
1583 /* no error if we get here */
1584 _mesa_unlock_texture(ctx, obj);
1585 return;
1586
1587 invalid_pname:
1588 _mesa_unlock_texture(ctx, obj);
1589 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname=0x%x)", pname);
1590 }
1591
1592
1593 void GLAPIENTRY
1594 _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
1595 {
1596 struct gl_texture_object *obj;
1597 GET_CURRENT_CONTEXT(ctx);
1598
1599 obj = get_texobj(ctx, target, GL_TRUE);
1600 if (!obj)
1601 return;
1602
1603 _mesa_lock_texture(ctx, obj);
1604 switch (pname) {
1605 case GL_TEXTURE_MAG_FILTER:
1606 *params = (GLint) obj->Sampler.MagFilter;
1607 break;
1608 case GL_TEXTURE_MIN_FILTER:
1609 *params = (GLint) obj->Sampler.MinFilter;
1610 break;
1611 case GL_TEXTURE_WRAP_S:
1612 *params = (GLint) obj->Sampler.WrapS;
1613 break;
1614 case GL_TEXTURE_WRAP_T:
1615 *params = (GLint) obj->Sampler.WrapT;
1616 break;
1617 case GL_TEXTURE_WRAP_R:
1618 *params = (GLint) obj->Sampler.WrapR;
1619 break;
1620 case GL_TEXTURE_BORDER_COLOR:
1621 if (!_mesa_is_desktop_gl(ctx))
1622 goto invalid_pname;
1623
1624 {
1625 GLfloat b[4];
1626 b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1627 b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1628 b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1629 b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
1630 params[0] = FLOAT_TO_INT(b[0]);
1631 params[1] = FLOAT_TO_INT(b[1]);
1632 params[2] = FLOAT_TO_INT(b[2]);
1633 params[3] = FLOAT_TO_INT(b[3]);
1634 }
1635 break;
1636 case GL_TEXTURE_RESIDENT:
1637 if (ctx->API != API_OPENGL_COMPAT)
1638 goto invalid_pname;
1639
1640 *params = 1;
1641 break;
1642 case GL_TEXTURE_PRIORITY:
1643 if (ctx->API != API_OPENGL_COMPAT)
1644 goto invalid_pname;
1645
1646 *params = FLOAT_TO_INT(obj->Priority);
1647 break;
1648 case GL_TEXTURE_MIN_LOD:
1649 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1650 goto invalid_pname;
1651
1652 *params = (GLint) obj->Sampler.MinLod;
1653 break;
1654 case GL_TEXTURE_MAX_LOD:
1655 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1656 goto invalid_pname;
1657
1658 *params = (GLint) obj->Sampler.MaxLod;
1659 break;
1660 case GL_TEXTURE_BASE_LEVEL:
1661 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1662 goto invalid_pname;
1663
1664 *params = obj->BaseLevel;
1665 break;
1666 case GL_TEXTURE_MAX_LEVEL:
1667 *params = obj->MaxLevel;
1668 break;
1669 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1670 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
1671 goto invalid_pname;
1672 *params = (GLint) obj->Sampler.MaxAnisotropy;
1673 break;
1674 case GL_GENERATE_MIPMAP_SGIS:
1675 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1676 goto invalid_pname;
1677
1678 *params = (GLint) obj->GenerateMipmap;
1679 break;
1680 case GL_TEXTURE_COMPARE_MODE_ARB:
1681 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
1682 && !_mesa_is_gles3(ctx))
1683 goto invalid_pname;
1684 *params = (GLint) obj->Sampler.CompareMode;
1685 break;
1686 case GL_TEXTURE_COMPARE_FUNC_ARB:
1687 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
1688 && !_mesa_is_gles3(ctx))
1689 goto invalid_pname;
1690 *params = (GLint) obj->Sampler.CompareFunc;
1691 break;
1692 case GL_DEPTH_TEXTURE_MODE_ARB:
1693 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
1694 goto invalid_pname;
1695 *params = (GLint) obj->DepthMode;
1696 break;
1697 case GL_TEXTURE_LOD_BIAS:
1698 if (ctx->API != API_OPENGL_COMPAT)
1699 goto invalid_pname;
1700
1701 *params = (GLint) obj->Sampler.LodBias;
1702 break;
1703 case GL_TEXTURE_CROP_RECT_OES:
1704 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
1705 goto invalid_pname;
1706
1707 params[0] = obj->CropRect[0];
1708 params[1] = obj->CropRect[1];
1709 params[2] = obj->CropRect[2];
1710 params[3] = obj->CropRect[3];
1711 break;
1712 case GL_TEXTURE_SWIZZLE_R_EXT:
1713 case GL_TEXTURE_SWIZZLE_G_EXT:
1714 case GL_TEXTURE_SWIZZLE_B_EXT:
1715 case GL_TEXTURE_SWIZZLE_A_EXT:
1716 if ((!_mesa_is_desktop_gl(ctx)
1717 || !ctx->Extensions.EXT_texture_swizzle)
1718 && !_mesa_is_gles3(ctx))
1719 goto invalid_pname;
1720 *params = obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
1721 break;
1722
1723 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
1724 if ((!_mesa_is_desktop_gl(ctx)
1725 || !ctx->Extensions.EXT_texture_swizzle)
1726 && !_mesa_is_gles3(ctx))
1727 goto invalid_pname;
1728 COPY_4V(params, obj->Swizzle);
1729 break;
1730
1731 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1732 if (!_mesa_is_desktop_gl(ctx)
1733 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
1734 goto invalid_pname;
1735 *params = (GLint) obj->Sampler.CubeMapSeamless;
1736 break;
1737
1738 case GL_TEXTURE_IMMUTABLE_FORMAT:
1739 *params = (GLint) obj->Immutable;
1740 break;
1741
1742 case GL_TEXTURE_IMMUTABLE_LEVELS:
1743 if (!_mesa_is_gles3(ctx))
1744 goto invalid_pname;
1745 *params = obj->ImmutableLevels;
1746 break;
1747
1748 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
1749 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
1750 goto invalid_pname;
1751 *params = obj->RequiredTextureImageUnits;
1752 break;
1753
1754 case GL_TEXTURE_SRGB_DECODE_EXT:
1755 if (!ctx->Extensions.EXT_texture_sRGB_decode)
1756 goto invalid_pname;
1757 *params = obj->Sampler.sRGBDecode;
1758 break;
1759
1760 default:
1761 goto invalid_pname;
1762 }
1763
1764 /* no error if we get here */
1765 _mesa_unlock_texture(ctx, obj);
1766 return;
1767
1768 invalid_pname:
1769 _mesa_unlock_texture(ctx, obj);
1770 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname=0x%x)", pname);
1771 }
1772
1773
1774 /** New in GL 3.0 */
1775 void GLAPIENTRY
1776 _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
1777 {
1778 struct gl_texture_object *texObj;
1779 GET_CURRENT_CONTEXT(ctx);
1780
1781 texObj = get_texobj(ctx, target, GL_TRUE);
1782 if (!texObj)
1783 return;
1784
1785 switch (pname) {
1786 case GL_TEXTURE_BORDER_COLOR:
1787 COPY_4V(params, texObj->Sampler.BorderColor.i);
1788 break;
1789 default:
1790 _mesa_GetTexParameteriv(target, pname, params);
1791 }
1792 }
1793
1794
1795 /** New in GL 3.0 */
1796 void GLAPIENTRY
1797 _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
1798 {
1799 struct gl_texture_object *texObj;
1800 GET_CURRENT_CONTEXT(ctx);
1801
1802 texObj = get_texobj(ctx, target, GL_TRUE);
1803 if (!texObj)
1804 return;
1805
1806 switch (pname) {
1807 case GL_TEXTURE_BORDER_COLOR:
1808 COPY_4V(params, texObj->Sampler.BorderColor.i);
1809 break;
1810 default:
1811 {
1812 GLint ip[4];
1813 _mesa_GetTexParameteriv(target, pname, ip);
1814 params[0] = ip[0];
1815 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT ||
1816 pname == GL_TEXTURE_CROP_RECT_OES) {
1817 params[1] = ip[1];
1818 params[2] = ip[2];
1819 params[3] = ip[3];
1820 }
1821 }
1822 }
1823 }