mesa: enable GL_TEXTURE_LOD_BIAS set/get
[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 if (_mesa_is_gles(ctx))
689 goto invalid_pname;
690
691 if (!target_allows_setting_sampler_parameters(texObj->Target))
692 goto invalid_operation;
693
694 if (texObj->Sampler.LodBias != params[0]) {
695 flush(ctx);
696 texObj->Sampler.LodBias = params[0];
697 return GL_TRUE;
698 }
699 break;
700
701 case GL_TEXTURE_BORDER_COLOR:
702 if (!_mesa_is_desktop_gl(ctx))
703 goto invalid_pname;
704
705 if (!target_allows_setting_sampler_parameters(texObj->Target))
706 goto invalid_operation;
707
708 flush(ctx);
709 /* ARB_texture_float disables clamping */
710 if (ctx->Extensions.ARB_texture_float) {
711 texObj->Sampler.BorderColor.f[RCOMP] = params[0];
712 texObj->Sampler.BorderColor.f[GCOMP] = params[1];
713 texObj->Sampler.BorderColor.f[BCOMP] = params[2];
714 texObj->Sampler.BorderColor.f[ACOMP] = params[3];
715 } else {
716 texObj->Sampler.BorderColor.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F);
717 texObj->Sampler.BorderColor.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F);
718 texObj->Sampler.BorderColor.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F);
719 texObj->Sampler.BorderColor.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F);
720 }
721 return GL_TRUE;
722
723 default:
724 goto invalid_pname;
725 }
726 return GL_FALSE;
727
728 invalid_pname:
729 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=%s)",
730 _mesa_lookup_enum_by_nr(pname));
731 return GL_FALSE;
732
733 invalid_operation:
734 _mesa_error(ctx, GL_INVALID_OPERATION, "glTexParameter(pname=%s)",
735 _mesa_lookup_enum_by_nr(pname));
736 return GL_FALSE;
737 }
738
739
740 void GLAPIENTRY
741 _mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
742 {
743 GLboolean need_update;
744 struct gl_texture_object *texObj;
745 GET_CURRENT_CONTEXT(ctx);
746
747 texObj = get_texobj(ctx, target, GL_FALSE);
748 if (!texObj)
749 return;
750
751 switch (pname) {
752 case GL_TEXTURE_MIN_FILTER:
753 case GL_TEXTURE_MAG_FILTER:
754 case GL_TEXTURE_WRAP_S:
755 case GL_TEXTURE_WRAP_T:
756 case GL_TEXTURE_WRAP_R:
757 case GL_TEXTURE_BASE_LEVEL:
758 case GL_TEXTURE_MAX_LEVEL:
759 case GL_GENERATE_MIPMAP_SGIS:
760 case GL_TEXTURE_COMPARE_MODE_ARB:
761 case GL_TEXTURE_COMPARE_FUNC_ARB:
762 case GL_DEPTH_TEXTURE_MODE_ARB:
763 case GL_TEXTURE_SRGB_DECODE_EXT:
764 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
765 case GL_TEXTURE_SWIZZLE_R_EXT:
766 case GL_TEXTURE_SWIZZLE_G_EXT:
767 case GL_TEXTURE_SWIZZLE_B_EXT:
768 case GL_TEXTURE_SWIZZLE_A_EXT:
769 {
770 GLint p[4];
771 p[0] = (param > 0) ?
772 ((param > INT_MAX) ? INT_MAX : (GLint) (param + 0.5)) :
773 ((param < INT_MIN) ? INT_MIN : (GLint) (param - 0.5));
774
775 p[1] = p[2] = p[3] = 0;
776 need_update = set_tex_parameteri(ctx, texObj, pname, p);
777 }
778 break;
779 default:
780 {
781 /* this will generate an error if pname is illegal */
782 GLfloat p[4];
783 p[0] = param;
784 p[1] = p[2] = p[3] = 0.0F;
785 need_update = set_tex_parameterf(ctx, texObj, pname, p);
786 }
787 }
788
789 if (ctx->Driver.TexParameter && need_update) {
790 ctx->Driver.TexParameter(ctx, target, texObj, pname, &param);
791 }
792 }
793
794
795 void GLAPIENTRY
796 _mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
797 {
798 GLboolean need_update;
799 struct gl_texture_object *texObj;
800 GET_CURRENT_CONTEXT(ctx);
801
802 texObj = get_texobj(ctx, target, GL_FALSE);
803 if (!texObj)
804 return;
805
806 switch (pname) {
807 case GL_TEXTURE_MIN_FILTER:
808 case GL_TEXTURE_MAG_FILTER:
809 case GL_TEXTURE_WRAP_S:
810 case GL_TEXTURE_WRAP_T:
811 case GL_TEXTURE_WRAP_R:
812 case GL_TEXTURE_BASE_LEVEL:
813 case GL_TEXTURE_MAX_LEVEL:
814 case GL_GENERATE_MIPMAP_SGIS:
815 case GL_TEXTURE_COMPARE_MODE_ARB:
816 case GL_TEXTURE_COMPARE_FUNC_ARB:
817 case GL_DEPTH_TEXTURE_MODE_ARB:
818 case GL_TEXTURE_SRGB_DECODE_EXT:
819 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
820 {
821 /* convert float param to int */
822 GLint p[4];
823 p[0] = (GLint) params[0];
824 p[1] = p[2] = p[3] = 0;
825 need_update = set_tex_parameteri(ctx, texObj, pname, p);
826 }
827 break;
828 case GL_TEXTURE_CROP_RECT_OES:
829 {
830 /* convert float params to int */
831 GLint iparams[4];
832 iparams[0] = (GLint) params[0];
833 iparams[1] = (GLint) params[1];
834 iparams[2] = (GLint) params[2];
835 iparams[3] = (GLint) params[3];
836 need_update = set_tex_parameteri(ctx, texObj, pname, iparams);
837 }
838 break;
839 case GL_TEXTURE_SWIZZLE_R_EXT:
840 case GL_TEXTURE_SWIZZLE_G_EXT:
841 case GL_TEXTURE_SWIZZLE_B_EXT:
842 case GL_TEXTURE_SWIZZLE_A_EXT:
843 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
844 {
845 GLint p[4] = {0, 0, 0, 0};
846 p[0] = (GLint) params[0];
847 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT) {
848 p[1] = (GLint) params[1];
849 p[2] = (GLint) params[2];
850 p[3] = (GLint) params[3];
851 }
852 need_update = set_tex_parameteri(ctx, texObj, pname, p);
853 }
854 break;
855 default:
856 /* this will generate an error if pname is illegal */
857 need_update = set_tex_parameterf(ctx, texObj, pname, params);
858 }
859
860 if (ctx->Driver.TexParameter && need_update) {
861 ctx->Driver.TexParameter(ctx, target, texObj, pname, params);
862 }
863 }
864
865
866 void GLAPIENTRY
867 _mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
868 {
869 GLboolean need_update;
870 struct gl_texture_object *texObj;
871 GET_CURRENT_CONTEXT(ctx);
872
873 texObj = get_texobj(ctx, target, GL_FALSE);
874 if (!texObj)
875 return;
876
877 switch (pname) {
878 case GL_TEXTURE_MIN_LOD:
879 case GL_TEXTURE_MAX_LOD:
880 case GL_TEXTURE_PRIORITY:
881 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
882 case GL_TEXTURE_LOD_BIAS:
883 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
884 {
885 GLfloat fparam[4];
886 fparam[0] = (GLfloat) param;
887 fparam[1] = fparam[2] = fparam[3] = 0.0F;
888 /* convert int param to float */
889 need_update = set_tex_parameterf(ctx, texObj, pname, fparam);
890 }
891 break;
892 default:
893 /* this will generate an error if pname is illegal */
894 {
895 GLint iparam[4];
896 iparam[0] = param;
897 iparam[1] = iparam[2] = iparam[3] = 0;
898 need_update = set_tex_parameteri(ctx, texObj, pname, iparam);
899 }
900 }
901
902 if (ctx->Driver.TexParameter && need_update) {
903 GLfloat fparam = (GLfloat) param;
904 ctx->Driver.TexParameter(ctx, target, texObj, pname, &fparam);
905 }
906 }
907
908
909 void GLAPIENTRY
910 _mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
911 {
912 GLboolean need_update;
913 struct gl_texture_object *texObj;
914 GET_CURRENT_CONTEXT(ctx);
915
916 texObj = get_texobj(ctx, target, GL_FALSE);
917 if (!texObj)
918 return;
919
920 switch (pname) {
921 case GL_TEXTURE_BORDER_COLOR:
922 {
923 /* convert int params to float */
924 GLfloat fparams[4];
925 fparams[0] = INT_TO_FLOAT(params[0]);
926 fparams[1] = INT_TO_FLOAT(params[1]);
927 fparams[2] = INT_TO_FLOAT(params[2]);
928 fparams[3] = INT_TO_FLOAT(params[3]);
929 need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
930 }
931 break;
932 case GL_TEXTURE_MIN_LOD:
933 case GL_TEXTURE_MAX_LOD:
934 case GL_TEXTURE_PRIORITY:
935 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
936 case GL_TEXTURE_LOD_BIAS:
937 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
938 {
939 /* convert int param to float */
940 GLfloat fparams[4];
941 fparams[0] = (GLfloat) params[0];
942 fparams[1] = fparams[2] = fparams[3] = 0.0F;
943 need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
944 }
945 break;
946 default:
947 /* this will generate an error if pname is illegal */
948 need_update = set_tex_parameteri(ctx, texObj, pname, params);
949 }
950
951 if (ctx->Driver.TexParameter && need_update) {
952 GLfloat fparams[4];
953 fparams[0] = INT_TO_FLOAT(params[0]);
954 if (pname == GL_TEXTURE_BORDER_COLOR ||
955 pname == GL_TEXTURE_CROP_RECT_OES) {
956 fparams[1] = INT_TO_FLOAT(params[1]);
957 fparams[2] = INT_TO_FLOAT(params[2]);
958 fparams[3] = INT_TO_FLOAT(params[3]);
959 }
960 ctx->Driver.TexParameter(ctx, target, texObj, pname, fparams);
961 }
962 }
963
964
965 /**
966 * Set tex parameter to integer value(s). Primarily intended to set
967 * integer-valued texture border color (for integer-valued textures).
968 * New in GL 3.0.
969 */
970 void GLAPIENTRY
971 _mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
972 {
973 struct gl_texture_object *texObj;
974 GET_CURRENT_CONTEXT(ctx);
975
976 texObj = get_texobj(ctx, target, GL_FALSE);
977 if (!texObj)
978 return;
979
980 switch (pname) {
981 case GL_TEXTURE_BORDER_COLOR:
982 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
983 /* set the integer-valued border color */
984 COPY_4V(texObj->Sampler.BorderColor.i, params);
985 break;
986 default:
987 _mesa_TexParameteriv(target, pname, params);
988 break;
989 }
990 /* XXX no driver hook for TexParameterIiv() yet */
991 }
992
993
994 /**
995 * Set tex parameter to unsigned integer value(s). Primarily intended to set
996 * uint-valued texture border color (for integer-valued textures).
997 * New in GL 3.0
998 */
999 void GLAPIENTRY
1000 _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
1001 {
1002 struct gl_texture_object *texObj;
1003 GET_CURRENT_CONTEXT(ctx);
1004
1005 texObj = get_texobj(ctx, target, GL_FALSE);
1006 if (!texObj)
1007 return;
1008
1009 switch (pname) {
1010 case GL_TEXTURE_BORDER_COLOR:
1011 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1012 /* set the unsigned integer-valued border color */
1013 COPY_4V(texObj->Sampler.BorderColor.ui, params);
1014 break;
1015 default:
1016 _mesa_TexParameteriv(target, pname, (const GLint *) params);
1017 break;
1018 }
1019 /* XXX no driver hook for TexParameterIuiv() yet */
1020 }
1021
1022
1023 static GLboolean
1024 legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target)
1025 {
1026 switch (target) {
1027 case GL_TEXTURE_1D:
1028 case GL_PROXY_TEXTURE_1D:
1029 case GL_TEXTURE_2D:
1030 case GL_PROXY_TEXTURE_2D:
1031 case GL_TEXTURE_3D:
1032 case GL_PROXY_TEXTURE_3D:
1033 return GL_TRUE;
1034 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
1035 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
1036 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
1037 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
1038 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
1039 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
1040 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
1041 return ctx->Extensions.ARB_texture_cube_map;
1042 case GL_TEXTURE_RECTANGLE_NV:
1043 case GL_PROXY_TEXTURE_RECTANGLE_NV:
1044 return ctx->Extensions.NV_texture_rectangle;
1045 case GL_TEXTURE_1D_ARRAY_EXT:
1046 case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
1047 case GL_TEXTURE_2D_ARRAY_EXT:
1048 case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
1049 return (ctx->Extensions.MESA_texture_array ||
1050 ctx->Extensions.EXT_texture_array);
1051 case GL_TEXTURE_BUFFER:
1052 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1053 * but not in earlier versions that expose ARB_texture_buffer_object.
1054 *
1055 * From the ARB_texture_buffer_object spec:
1056 * "(7) Do buffer textures support texture parameters (TexParameter) or
1057 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1058 *
1059 * RESOLVED: No. [...] Note that the spec edits above don't add
1060 * explicit error language for any of these cases. That is because
1061 * each of the functions enumerate the set of valid <target>
1062 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1063 * these cases means that target is not legal, and an INVALID_ENUM
1064 * error should be generated."
1065 *
1066 * From the OpenGL 3.1 spec:
1067 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1068 */
1069 return ctx->API == API_OPENGL_CORE && ctx->Version >= 31;
1070 case GL_TEXTURE_2D_MULTISAMPLE:
1071 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
1072 case GL_PROXY_TEXTURE_2D_MULTISAMPLE:
1073 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY:
1074 return ctx->Extensions.ARB_texture_multisample;
1075 default:
1076 return GL_FALSE;
1077 }
1078 }
1079
1080
1081 static void
1082 get_tex_level_parameter_image(struct gl_context *ctx,
1083 const struct gl_texture_object *texObj,
1084 GLenum target, GLint level,
1085 GLenum pname, GLint *params)
1086 {
1087 const struct gl_texture_image *img = NULL;
1088 gl_format texFormat;
1089
1090 img = _mesa_select_tex_image(ctx, texObj, target, level);
1091 if (!img || img->TexFormat == MESA_FORMAT_NONE) {
1092 /* undefined texture image */
1093 if (pname == GL_TEXTURE_COMPONENTS)
1094 *params = 1;
1095 else
1096 *params = 0;
1097 return;
1098 }
1099
1100 texFormat = img->TexFormat;
1101
1102 switch (pname) {
1103 case GL_TEXTURE_WIDTH:
1104 *params = img->Width;
1105 break;
1106 case GL_TEXTURE_HEIGHT:
1107 *params = img->Height;
1108 break;
1109 case GL_TEXTURE_DEPTH:
1110 *params = img->Depth;
1111 break;
1112 case GL_TEXTURE_INTERNAL_FORMAT:
1113 if (_mesa_is_format_compressed(texFormat)) {
1114 /* need to return the actual compressed format */
1115 *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
1116 }
1117 else {
1118 /* If the true internal format is not compressed but the user
1119 * requested a generic compressed format, we have to return the
1120 * generic base format that matches.
1121 *
1122 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1123 *
1124 * "If no specific compressed format is available,
1125 * internalformat is instead replaced by the corresponding base
1126 * internal format."
1127 *
1128 * Otherwise just return the user's requested internal format
1129 */
1130 const GLenum f =
1131 _mesa_gl_compressed_format_base_format(img->InternalFormat);
1132
1133 *params = (f != 0) ? f : img->InternalFormat;
1134 }
1135 break;
1136 case GL_TEXTURE_BORDER:
1137 *params = img->Border;
1138 break;
1139 case GL_TEXTURE_RED_SIZE:
1140 case GL_TEXTURE_GREEN_SIZE:
1141 case GL_TEXTURE_BLUE_SIZE:
1142 case GL_TEXTURE_ALPHA_SIZE:
1143 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1144 *params = _mesa_get_format_bits(texFormat, pname);
1145 else
1146 *params = 0;
1147 break;
1148 case GL_TEXTURE_INTENSITY_SIZE:
1149 case GL_TEXTURE_LUMINANCE_SIZE:
1150 if (_mesa_base_format_has_channel(img->_BaseFormat, pname)) {
1151 *params = _mesa_get_format_bits(texFormat, pname);
1152 if (*params == 0) {
1153 /* intensity or luminance is probably stored as RGB[A] */
1154 *params = MIN2(_mesa_get_format_bits(texFormat,
1155 GL_TEXTURE_RED_SIZE),
1156 _mesa_get_format_bits(texFormat,
1157 GL_TEXTURE_GREEN_SIZE));
1158 }
1159 }
1160 else {
1161 *params = 0;
1162 }
1163 break;
1164 case GL_TEXTURE_DEPTH_SIZE_ARB:
1165 if (!ctx->Extensions.ARB_depth_texture)
1166 goto invalid_pname;
1167 *params = _mesa_get_format_bits(texFormat, pname);
1168 break;
1169 case GL_TEXTURE_STENCIL_SIZE_EXT:
1170 if (!ctx->Extensions.EXT_packed_depth_stencil &&
1171 !ctx->Extensions.ARB_framebuffer_object)
1172 goto invalid_pname;
1173 *params = _mesa_get_format_bits(texFormat, pname);
1174 break;
1175 case GL_TEXTURE_SHARED_SIZE:
1176 if (ctx->Version < 30 &&
1177 !ctx->Extensions.EXT_texture_shared_exponent)
1178 goto invalid_pname;
1179 *params = texFormat == MESA_FORMAT_RGB9_E5_FLOAT ? 5 : 0;
1180 break;
1181
1182 /* GL_ARB_texture_compression */
1183 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1184 if (_mesa_is_format_compressed(texFormat) &&
1185 !_mesa_is_proxy_texture(target)) {
1186 *params = _mesa_format_image_size(texFormat, img->Width,
1187 img->Height, img->Depth);
1188 }
1189 else {
1190 _mesa_error(ctx, GL_INVALID_OPERATION,
1191 "glGetTexLevelParameter[if]v(pname)");
1192 }
1193 break;
1194 case GL_TEXTURE_COMPRESSED:
1195 *params = (GLint) _mesa_is_format_compressed(texFormat);
1196 break;
1197
1198 /* GL_ARB_texture_float */
1199 case GL_TEXTURE_RED_TYPE_ARB:
1200 case GL_TEXTURE_GREEN_TYPE_ARB:
1201 case GL_TEXTURE_BLUE_TYPE_ARB:
1202 case GL_TEXTURE_ALPHA_TYPE_ARB:
1203 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1204 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1205 case GL_TEXTURE_DEPTH_TYPE_ARB:
1206 if (!ctx->Extensions.ARB_texture_float)
1207 goto invalid_pname;
1208 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1209 *params = _mesa_get_format_datatype(texFormat);
1210 else
1211 *params = GL_NONE;
1212 break;
1213
1214 /* GL_ARB_texture_multisample */
1215 case GL_TEXTURE_SAMPLES:
1216 if (!ctx->Extensions.ARB_texture_multisample)
1217 goto invalid_pname;
1218 *params = img->NumSamples;
1219 break;
1220
1221 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1222 if (!ctx->Extensions.ARB_texture_multisample)
1223 goto invalid_pname;
1224 *params = img->FixedSampleLocations;
1225 break;
1226
1227 default:
1228 goto invalid_pname;
1229 }
1230
1231 /* no error if we get here */
1232 return;
1233
1234 invalid_pname:
1235 _mesa_error(ctx, GL_INVALID_ENUM,
1236 "glGetTexLevelParameter[if]v(pname=%s)",
1237 _mesa_lookup_enum_by_nr(pname));
1238 }
1239
1240
1241 static void
1242 get_tex_level_parameter_buffer(struct gl_context *ctx,
1243 const struct gl_texture_object *texObj,
1244 GLenum pname, GLint *params)
1245 {
1246 const struct gl_buffer_object *bo = texObj->BufferObject;
1247 gl_format texFormat = texObj->_BufferObjectFormat;
1248 GLenum internalFormat = texObj->BufferObjectFormat;
1249 GLenum baseFormat = _mesa_get_format_base_format(texFormat);
1250
1251 if (!bo) {
1252 /* undefined texture buffer object */
1253 *params = pname == GL_TEXTURE_COMPONENTS ? 1 : 0;
1254 return;
1255 }
1256
1257 switch (pname) {
1258 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
1259 *params = bo->Name;
1260 break;
1261 case GL_TEXTURE_WIDTH:
1262 *params = bo->Size;
1263 break;
1264 case GL_TEXTURE_HEIGHT:
1265 case GL_TEXTURE_DEPTH:
1266 case GL_TEXTURE_BORDER:
1267 case GL_TEXTURE_SHARED_SIZE:
1268 case GL_TEXTURE_COMPRESSED:
1269 *params = 0;
1270 break;
1271 case GL_TEXTURE_INTERNAL_FORMAT:
1272 *params = internalFormat;
1273 break;
1274 case GL_TEXTURE_RED_SIZE:
1275 case GL_TEXTURE_GREEN_SIZE:
1276 case GL_TEXTURE_BLUE_SIZE:
1277 case GL_TEXTURE_ALPHA_SIZE:
1278 if (_mesa_base_format_has_channel(baseFormat, pname))
1279 *params = _mesa_get_format_bits(texFormat, pname);
1280 else
1281 *params = 0;
1282 break;
1283 case GL_TEXTURE_INTENSITY_SIZE:
1284 case GL_TEXTURE_LUMINANCE_SIZE:
1285 if (_mesa_base_format_has_channel(baseFormat, pname)) {
1286 *params = _mesa_get_format_bits(texFormat, pname);
1287 if (*params == 0) {
1288 /* intensity or luminance is probably stored as RGB[A] */
1289 *params = MIN2(_mesa_get_format_bits(texFormat,
1290 GL_TEXTURE_RED_SIZE),
1291 _mesa_get_format_bits(texFormat,
1292 GL_TEXTURE_GREEN_SIZE));
1293 }
1294 } else {
1295 *params = 0;
1296 }
1297 break;
1298 case GL_TEXTURE_DEPTH_SIZE_ARB:
1299 case GL_TEXTURE_STENCIL_SIZE_EXT:
1300 *params = _mesa_get_format_bits(texFormat, pname);
1301 break;
1302
1303 /* GL_ARB_texture_buffer_range */
1304 case GL_TEXTURE_BUFFER_OFFSET:
1305 if (!ctx->Extensions.ARB_texture_buffer_range)
1306 goto invalid_pname;
1307 *params = texObj->BufferOffset;
1308 break;
1309 case GL_TEXTURE_BUFFER_SIZE:
1310 if (!ctx->Extensions.ARB_texture_buffer_range)
1311 goto invalid_pname;
1312 *params = (texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize;
1313 break;
1314
1315 /* GL_ARB_texture_compression */
1316 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1317 /* Always illegal for GL_TEXTURE_BUFFER */
1318 _mesa_error(ctx, GL_INVALID_OPERATION,
1319 "glGetTexLevelParameter[if]v(pname)");
1320 break;
1321
1322 /* GL_ARB_texture_float */
1323 case GL_TEXTURE_RED_TYPE_ARB:
1324 case GL_TEXTURE_GREEN_TYPE_ARB:
1325 case GL_TEXTURE_BLUE_TYPE_ARB:
1326 case GL_TEXTURE_ALPHA_TYPE_ARB:
1327 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1328 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1329 case GL_TEXTURE_DEPTH_TYPE_ARB:
1330 if (!ctx->Extensions.ARB_texture_float)
1331 goto invalid_pname;
1332 if (_mesa_base_format_has_channel(baseFormat, pname))
1333 *params = _mesa_get_format_datatype(texFormat);
1334 else
1335 *params = GL_NONE;
1336 break;
1337
1338 default:
1339 goto invalid_pname;
1340 }
1341
1342 /* no error if we get here */
1343 return;
1344
1345 invalid_pname:
1346 _mesa_error(ctx, GL_INVALID_ENUM,
1347 "glGetTexLevelParameter[if]v(pname=%s)",
1348 _mesa_lookup_enum_by_nr(pname));
1349 }
1350
1351
1352 void GLAPIENTRY
1353 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
1354 GLenum pname, GLfloat *params )
1355 {
1356 GLint iparam;
1357 _mesa_GetTexLevelParameteriv( target, level, pname, &iparam );
1358 *params = (GLfloat) iparam;
1359 }
1360
1361
1362 void GLAPIENTRY
1363 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
1364 GLenum pname, GLint *params )
1365 {
1366 const struct gl_texture_unit *texUnit;
1367 struct gl_texture_object *texObj;
1368 GLint maxLevels;
1369 GET_CURRENT_CONTEXT(ctx);
1370
1371 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
1372 _mesa_error(ctx, GL_INVALID_OPERATION,
1373 "glGetTexLevelParameteriv(current unit)");
1374 return;
1375 }
1376
1377 texUnit = _mesa_get_current_tex_unit(ctx);
1378
1379 if (!legal_get_tex_level_parameter_target(ctx, target)) {
1380 _mesa_error(ctx, GL_INVALID_ENUM,
1381 "glGetTexLevelParameter[if]v(target=0x%x)", target);
1382 return;
1383 }
1384
1385 maxLevels = _mesa_max_texture_levels(ctx, target);
1386 assert(maxLevels != 0);
1387
1388 if (level < 0 || level >= maxLevels) {
1389 _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
1390 return;
1391 }
1392
1393 texObj = _mesa_select_tex_object(ctx, texUnit, target);
1394
1395 if (target == GL_TEXTURE_BUFFER)
1396 get_tex_level_parameter_buffer(ctx, texObj, pname, params);
1397 else
1398 get_tex_level_parameter_image(ctx, texObj, target, level, pname, params);
1399 }
1400
1401
1402 void GLAPIENTRY
1403 _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
1404 {
1405 struct gl_texture_object *obj;
1406 GET_CURRENT_CONTEXT(ctx);
1407
1408 obj = get_texobj(ctx, target, GL_TRUE);
1409 if (!obj)
1410 return;
1411
1412 _mesa_lock_texture(ctx, obj);
1413 switch (pname) {
1414 case GL_TEXTURE_MAG_FILTER:
1415 *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
1416 break;
1417 case GL_TEXTURE_MIN_FILTER:
1418 *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
1419 break;
1420 case GL_TEXTURE_WRAP_S:
1421 *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
1422 break;
1423 case GL_TEXTURE_WRAP_T:
1424 *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
1425 break;
1426 case GL_TEXTURE_WRAP_R:
1427 *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
1428 break;
1429 case GL_TEXTURE_BORDER_COLOR:
1430 if (!_mesa_is_desktop_gl(ctx))
1431 goto invalid_pname;
1432
1433 if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
1434 _mesa_update_state_locked(ctx);
1435 if (_mesa_get_clamp_fragment_color(ctx)) {
1436 params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1437 params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1438 params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1439 params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
1440 }
1441 else {
1442 params[0] = obj->Sampler.BorderColor.f[0];
1443 params[1] = obj->Sampler.BorderColor.f[1];
1444 params[2] = obj->Sampler.BorderColor.f[2];
1445 params[3] = obj->Sampler.BorderColor.f[3];
1446 }
1447 break;
1448 case GL_TEXTURE_RESIDENT:
1449 if (ctx->API != API_OPENGL_COMPAT)
1450 goto invalid_pname;
1451
1452 *params = 1.0F;
1453 break;
1454 case GL_TEXTURE_PRIORITY:
1455 if (ctx->API != API_OPENGL_COMPAT)
1456 goto invalid_pname;
1457
1458 *params = obj->Priority;
1459 break;
1460 case GL_TEXTURE_MIN_LOD:
1461 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1462 goto invalid_pname;
1463
1464 *params = obj->Sampler.MinLod;
1465 break;
1466 case GL_TEXTURE_MAX_LOD:
1467 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1468 goto invalid_pname;
1469
1470 *params = obj->Sampler.MaxLod;
1471 break;
1472 case GL_TEXTURE_BASE_LEVEL:
1473 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1474 goto invalid_pname;
1475
1476 *params = (GLfloat) obj->BaseLevel;
1477 break;
1478 case GL_TEXTURE_MAX_LEVEL:
1479 *params = (GLfloat) obj->MaxLevel;
1480 break;
1481 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1482 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
1483 goto invalid_pname;
1484 *params = obj->Sampler.MaxAnisotropy;
1485 break;
1486 case GL_GENERATE_MIPMAP_SGIS:
1487 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1488 goto invalid_pname;
1489
1490 *params = (GLfloat) obj->GenerateMipmap;
1491 break;
1492 case GL_TEXTURE_COMPARE_MODE_ARB:
1493 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
1494 && !_mesa_is_gles3(ctx))
1495 goto invalid_pname;
1496 *params = (GLfloat) obj->Sampler.CompareMode;
1497 break;
1498 case GL_TEXTURE_COMPARE_FUNC_ARB:
1499 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
1500 && !_mesa_is_gles3(ctx))
1501 goto invalid_pname;
1502 *params = (GLfloat) obj->Sampler.CompareFunc;
1503 break;
1504 case GL_DEPTH_TEXTURE_MODE_ARB:
1505 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1506 * never existed in OpenGL ES.
1507 */
1508 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
1509 goto invalid_pname;
1510 *params = (GLfloat) obj->DepthMode;
1511 break;
1512 case GL_TEXTURE_LOD_BIAS:
1513 if (_mesa_is_gles(ctx))
1514 goto invalid_pname;
1515
1516 *params = obj->Sampler.LodBias;
1517 break;
1518 case GL_TEXTURE_CROP_RECT_OES:
1519 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
1520 goto invalid_pname;
1521
1522 params[0] = (GLfloat) obj->CropRect[0];
1523 params[1] = (GLfloat) obj->CropRect[1];
1524 params[2] = (GLfloat) obj->CropRect[2];
1525 params[3] = (GLfloat) obj->CropRect[3];
1526 break;
1527
1528 case GL_TEXTURE_SWIZZLE_R_EXT:
1529 case GL_TEXTURE_SWIZZLE_G_EXT:
1530 case GL_TEXTURE_SWIZZLE_B_EXT:
1531 case GL_TEXTURE_SWIZZLE_A_EXT:
1532 if ((!_mesa_is_desktop_gl(ctx)
1533 || !ctx->Extensions.EXT_texture_swizzle)
1534 && !_mesa_is_gles3(ctx))
1535 goto invalid_pname;
1536 *params = (GLfloat) obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
1537 break;
1538
1539 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
1540 if ((!_mesa_is_desktop_gl(ctx)
1541 || !ctx->Extensions.EXT_texture_swizzle)
1542 && !_mesa_is_gles3(ctx)) {
1543 goto invalid_pname;
1544 }
1545 else {
1546 GLuint comp;
1547 for (comp = 0; comp < 4; comp++) {
1548 params[comp] = (GLfloat) obj->Swizzle[comp];
1549 }
1550 }
1551 break;
1552
1553 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1554 if (!_mesa_is_desktop_gl(ctx)
1555 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
1556 goto invalid_pname;
1557 *params = (GLfloat) obj->Sampler.CubeMapSeamless;
1558 break;
1559
1560 case GL_TEXTURE_IMMUTABLE_FORMAT:
1561 *params = (GLfloat) obj->Immutable;
1562 break;
1563
1564 case GL_TEXTURE_IMMUTABLE_LEVELS:
1565 if (!_mesa_is_gles3(ctx))
1566 goto invalid_pname;
1567 *params = (GLfloat) obj->ImmutableLevels;
1568 break;
1569
1570 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
1571 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
1572 goto invalid_pname;
1573 *params = (GLfloat) obj->RequiredTextureImageUnits;
1574 break;
1575
1576 case GL_TEXTURE_SRGB_DECODE_EXT:
1577 if (!ctx->Extensions.EXT_texture_sRGB_decode)
1578 goto invalid_pname;
1579 *params = (GLfloat) obj->Sampler.sRGBDecode;
1580 break;
1581
1582 default:
1583 goto invalid_pname;
1584 }
1585
1586 /* no error if we get here */
1587 _mesa_unlock_texture(ctx, obj);
1588 return;
1589
1590 invalid_pname:
1591 _mesa_unlock_texture(ctx, obj);
1592 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname=0x%x)", pname);
1593 }
1594
1595
1596 void GLAPIENTRY
1597 _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
1598 {
1599 struct gl_texture_object *obj;
1600 GET_CURRENT_CONTEXT(ctx);
1601
1602 obj = get_texobj(ctx, target, GL_TRUE);
1603 if (!obj)
1604 return;
1605
1606 _mesa_lock_texture(ctx, obj);
1607 switch (pname) {
1608 case GL_TEXTURE_MAG_FILTER:
1609 *params = (GLint) obj->Sampler.MagFilter;
1610 break;
1611 case GL_TEXTURE_MIN_FILTER:
1612 *params = (GLint) obj->Sampler.MinFilter;
1613 break;
1614 case GL_TEXTURE_WRAP_S:
1615 *params = (GLint) obj->Sampler.WrapS;
1616 break;
1617 case GL_TEXTURE_WRAP_T:
1618 *params = (GLint) obj->Sampler.WrapT;
1619 break;
1620 case GL_TEXTURE_WRAP_R:
1621 *params = (GLint) obj->Sampler.WrapR;
1622 break;
1623 case GL_TEXTURE_BORDER_COLOR:
1624 if (!_mesa_is_desktop_gl(ctx))
1625 goto invalid_pname;
1626
1627 {
1628 GLfloat b[4];
1629 b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1630 b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1631 b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1632 b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
1633 params[0] = FLOAT_TO_INT(b[0]);
1634 params[1] = FLOAT_TO_INT(b[1]);
1635 params[2] = FLOAT_TO_INT(b[2]);
1636 params[3] = FLOAT_TO_INT(b[3]);
1637 }
1638 break;
1639 case GL_TEXTURE_RESIDENT:
1640 if (ctx->API != API_OPENGL_COMPAT)
1641 goto invalid_pname;
1642
1643 *params = 1;
1644 break;
1645 case GL_TEXTURE_PRIORITY:
1646 if (ctx->API != API_OPENGL_COMPAT)
1647 goto invalid_pname;
1648
1649 *params = FLOAT_TO_INT(obj->Priority);
1650 break;
1651 case GL_TEXTURE_MIN_LOD:
1652 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1653 goto invalid_pname;
1654
1655 *params = (GLint) obj->Sampler.MinLod;
1656 break;
1657 case GL_TEXTURE_MAX_LOD:
1658 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1659 goto invalid_pname;
1660
1661 *params = (GLint) obj->Sampler.MaxLod;
1662 break;
1663 case GL_TEXTURE_BASE_LEVEL:
1664 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1665 goto invalid_pname;
1666
1667 *params = obj->BaseLevel;
1668 break;
1669 case GL_TEXTURE_MAX_LEVEL:
1670 *params = obj->MaxLevel;
1671 break;
1672 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1673 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
1674 goto invalid_pname;
1675 *params = (GLint) obj->Sampler.MaxAnisotropy;
1676 break;
1677 case GL_GENERATE_MIPMAP_SGIS:
1678 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1679 goto invalid_pname;
1680
1681 *params = (GLint) obj->GenerateMipmap;
1682 break;
1683 case GL_TEXTURE_COMPARE_MODE_ARB:
1684 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
1685 && !_mesa_is_gles3(ctx))
1686 goto invalid_pname;
1687 *params = (GLint) obj->Sampler.CompareMode;
1688 break;
1689 case GL_TEXTURE_COMPARE_FUNC_ARB:
1690 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
1691 && !_mesa_is_gles3(ctx))
1692 goto invalid_pname;
1693 *params = (GLint) obj->Sampler.CompareFunc;
1694 break;
1695 case GL_DEPTH_TEXTURE_MODE_ARB:
1696 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
1697 goto invalid_pname;
1698 *params = (GLint) obj->DepthMode;
1699 break;
1700 case GL_TEXTURE_LOD_BIAS:
1701 if (_mesa_is_gles(ctx))
1702 goto invalid_pname;
1703
1704 /* GL spec 'Data Conversions' section specifies that floating-point
1705 * value in integer Get function is rounded to nearest integer
1706 */
1707 *params = (GLint) roundf(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 }