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