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