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