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