mesa: Add support for OES_texture_cube_map_array
[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/context.h"
36 #include "main/enums.h"
37 #include "main/formats.h"
38 #include "main/glformats.h"
39 #include "main/macros.h"
40 #include "main/mtypes.h"
41 #include "main/state.h"
42 #include "main/texcompress.h"
43 #include "main/texobj.h"
44 #include "main/texparam.h"
45 #include "main/teximage.h"
46 #include "main/texstate.h"
47 #include "program/prog_instruction.h"
48
49
50 /**
51 * Check if a coordinate wrap mode is supported for the texture target.
52 * \return GL_TRUE if legal, GL_FALSE otherwise
53 */
54 static GLboolean
55 validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
56 {
57 const struct gl_extensions * const e = & ctx->Extensions;
58 const bool is_desktop_gl = _mesa_is_desktop_gl(ctx);
59 bool supported;
60
61 switch (wrap) {
62 case GL_CLAMP:
63 /* GL_CLAMP was removed in the core profile, and it has never existed in
64 * OpenGL ES.
65 */
66 supported = (ctx->API == API_OPENGL_COMPAT)
67 && (target != GL_TEXTURE_EXTERNAL_OES);
68 break;
69
70 case GL_CLAMP_TO_EDGE:
71 supported = true;
72 break;
73
74 case GL_CLAMP_TO_BORDER:
75 supported = ctx->API != API_OPENGLES && e->ARB_texture_border_clamp
76 && (target != GL_TEXTURE_EXTERNAL_OES);
77 break;
78
79 case GL_REPEAT:
80 case GL_MIRRORED_REPEAT:
81 supported = (target != GL_TEXTURE_RECTANGLE_NV)
82 && (target != GL_TEXTURE_EXTERNAL_OES);
83 break;
84
85 case GL_MIRROR_CLAMP_EXT:
86 supported = is_desktop_gl
87 && (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)
88 && (target != GL_TEXTURE_RECTANGLE_NV)
89 && (target != GL_TEXTURE_EXTERNAL_OES);
90 break;
91
92 case GL_MIRROR_CLAMP_TO_EDGE_EXT:
93 supported = is_desktop_gl
94 && (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp || e->ARB_texture_mirror_clamp_to_edge)
95 && (target != GL_TEXTURE_RECTANGLE_NV)
96 && (target != GL_TEXTURE_EXTERNAL_OES);
97 break;
98
99 case GL_MIRROR_CLAMP_TO_BORDER_EXT:
100 supported = is_desktop_gl && e->EXT_texture_mirror_clamp
101 && (target != GL_TEXTURE_RECTANGLE_NV)
102 && (target != GL_TEXTURE_EXTERNAL_OES);
103 break;
104
105 default:
106 supported = false;
107 break;
108 }
109
110 if (!supported)
111 _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(param=0x%x)", wrap );
112
113 return supported;
114 }
115
116
117 /**
118 * Get current texture object for given target.
119 * Return NULL if any error (and record the error).
120 * Note that this is different from _mesa_get_current_tex_object() in that
121 * proxy targets are not accepted.
122 * Only the glGetTexLevelParameter() functions accept proxy targets.
123 */
124 static struct gl_texture_object *
125 get_texobj_by_target(struct gl_context *ctx, GLenum target, GLboolean get)
126 {
127 struct gl_texture_unit *texUnit;
128 int targetIndex;
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 targetIndex = _mesa_tex_target_to_index(ctx, target);
139 if (targetIndex < 0 || targetIndex == TEXTURE_BUFFER_INDEX) {
140 _mesa_error(ctx, GL_INVALID_ENUM,
141 "gl%sTexParameter(target)", get ? "Get" : "");
142 return NULL;
143 }
144 assert(targetIndex < NUM_TEXTURE_TARGETS);
145
146 return texUnit->CurrentTex[targetIndex];
147 }
148
149 /**
150 * Get current texture object for given name.
151 * Return NULL if any error (and record the error).
152 * Note that proxy targets are not accepted.
153 * Only the glGetTexLevelParameter() functions accept proxy targets.
154 */
155 static struct gl_texture_object *
156 get_texobj_by_name(struct gl_context *ctx, GLuint texture, GLboolean get)
157 {
158 struct gl_texture_object *texObj;
159
160 texObj = _mesa_lookup_texture(ctx, texture);
161 if (!texObj) {
162 /*
163 * User passed a non-generated name.
164 * Throw the error in the caller.
165 */
166 return NULL;
167 }
168
169 switch (texObj->Target) {
170 case GL_TEXTURE_1D:
171 case GL_TEXTURE_1D_ARRAY:
172 case GL_TEXTURE_2D:
173 case GL_TEXTURE_2D_ARRAY:
174 case GL_TEXTURE_2D_MULTISAMPLE:
175 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
176 case GL_TEXTURE_3D:
177 case GL_TEXTURE_CUBE_MAP:
178 case GL_TEXTURE_CUBE_MAP_ARRAY:
179 case GL_TEXTURE_RECTANGLE:
180 return texObj;
181 default:
182 _mesa_error(ctx, GL_INVALID_ENUM,
183 "gl%sTextureParameter(target)", get ? "Get" : "");
184 return NULL;
185 }
186
187 }
188
189
190 /**
191 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
192 * \return -1 if error.
193 */
194 static GLint
195 comp_to_swizzle(GLenum comp)
196 {
197 switch (comp) {
198 case GL_RED:
199 return SWIZZLE_X;
200 case GL_GREEN:
201 return SWIZZLE_Y;
202 case GL_BLUE:
203 return SWIZZLE_Z;
204 case GL_ALPHA:
205 return SWIZZLE_W;
206 case GL_ZERO:
207 return SWIZZLE_ZERO;
208 case GL_ONE:
209 return SWIZZLE_ONE;
210 default:
211 return -1;
212 }
213 }
214
215
216 static void
217 set_swizzle_component(GLuint *swizzle, GLuint comp, GLuint swz)
218 {
219 assert(comp < 4);
220 assert(swz <= SWIZZLE_NIL);
221 {
222 GLuint mask = 0x7 << (3 * comp);
223 GLuint s = (*swizzle & ~mask) | (swz << (3 * comp));
224 *swizzle = s;
225 }
226 }
227
228
229 /**
230 * This is called just prior to changing any texture object state which
231 * will not affect texture completeness.
232 */
233 static inline void
234 flush(struct gl_context *ctx)
235 {
236 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
237 }
238
239
240 /**
241 * This is called just prior to changing any texture object state which
242 * could affect texture completeness (texture base level, max level).
243 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
244 * state flag and then mark the texture object as 'incomplete' so that any
245 * per-texture derived state gets recomputed.
246 */
247 static inline void
248 incomplete(struct gl_context *ctx, struct gl_texture_object *texObj)
249 {
250 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
251 _mesa_dirty_texobj(ctx, texObj);
252 }
253
254
255 GLboolean
256 _mesa_target_allows_setting_sampler_parameters(GLenum target)
257 {
258 switch (target) {
259 case GL_TEXTURE_2D_MULTISAMPLE:
260 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
261 return GL_FALSE;
262
263 default:
264 return GL_TRUE;
265 }
266 }
267
268
269 /**
270 * Set an integer-valued texture parameter
271 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
272 */
273 static GLboolean
274 set_tex_parameteri(struct gl_context *ctx,
275 struct gl_texture_object *texObj,
276 GLenum pname, const GLint *params, bool dsa)
277 {
278 const char *suffix = dsa ? "ture" : "";
279
280 switch (pname) {
281 case GL_TEXTURE_MIN_FILTER:
282 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
283 goto invalid_enum;
284
285 if (texObj->Sampler.MinFilter == params[0])
286 return GL_FALSE;
287 switch (params[0]) {
288 case GL_NEAREST:
289 case GL_LINEAR:
290 flush(ctx);
291 texObj->Sampler.MinFilter = params[0];
292 return GL_TRUE;
293 case GL_NEAREST_MIPMAP_NEAREST:
294 case GL_LINEAR_MIPMAP_NEAREST:
295 case GL_NEAREST_MIPMAP_LINEAR:
296 case GL_LINEAR_MIPMAP_LINEAR:
297 if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
298 texObj->Target != GL_TEXTURE_EXTERNAL_OES) {
299 flush(ctx);
300 texObj->Sampler.MinFilter = params[0];
301 return GL_TRUE;
302 }
303 /* fall-through */
304 default:
305 goto invalid_param;
306 }
307 return GL_FALSE;
308
309 case GL_TEXTURE_MAG_FILTER:
310 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
311 goto invalid_enum;
312
313 if (texObj->Sampler.MagFilter == params[0])
314 return GL_FALSE;
315 switch (params[0]) {
316 case GL_NEAREST:
317 case GL_LINEAR:
318 flush(ctx); /* does not effect completeness */
319 texObj->Sampler.MagFilter = params[0];
320 return GL_TRUE;
321 default:
322 goto invalid_param;
323 }
324 return GL_FALSE;
325
326 case GL_TEXTURE_WRAP_S:
327 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
328 goto invalid_enum;
329
330 if (texObj->Sampler.WrapS == params[0])
331 return GL_FALSE;
332 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
333 flush(ctx);
334 texObj->Sampler.WrapS = params[0];
335 return GL_TRUE;
336 }
337 return GL_FALSE;
338
339 case GL_TEXTURE_WRAP_T:
340 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
341 goto invalid_enum;
342
343 if (texObj->Sampler.WrapT == params[0])
344 return GL_FALSE;
345 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
346 flush(ctx);
347 texObj->Sampler.WrapT = params[0];
348 return GL_TRUE;
349 }
350 return GL_FALSE;
351
352 case GL_TEXTURE_WRAP_R:
353 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
354 goto invalid_enum;
355
356 if (texObj->Sampler.WrapR == params[0])
357 return GL_FALSE;
358 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
359 flush(ctx);
360 texObj->Sampler.WrapR = params[0];
361 return GL_TRUE;
362 }
363 return GL_FALSE;
364
365 case GL_TEXTURE_BASE_LEVEL:
366 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
367 goto invalid_pname;
368
369 if (texObj->BaseLevel == params[0])
370 return GL_FALSE;
371
372 if ((texObj->Target == GL_TEXTURE_2D_MULTISAMPLE ||
373 texObj->Target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) && params[0] != 0)
374 goto invalid_operation;
375
376 if (params[0] < 0) {
377 _mesa_error(ctx, GL_INVALID_VALUE,
378 "glTex%sParameter(param=%d)", suffix, params[0]);
379 return GL_FALSE;
380 }
381 if (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] != 0) {
382 _mesa_error(ctx, GL_INVALID_OPERATION,
383 "glTex%sParameter(target=%s, param=%d)", suffix,
384 _mesa_enum_to_string(texObj->Target), params[0]);
385 return GL_FALSE;
386 }
387 incomplete(ctx, texObj);
388
389 /** See note about ARB_texture_storage below */
390 if (texObj->Immutable)
391 texObj->BaseLevel = MIN2(texObj->ImmutableLevels - 1, params[0]);
392 else
393 texObj->BaseLevel = params[0];
394
395 return GL_TRUE;
396
397 case GL_TEXTURE_MAX_LEVEL:
398 if (texObj->MaxLevel == params[0])
399 return GL_FALSE;
400
401 if (params[0] < 0 ||
402 (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] > 0)) {
403 _mesa_error(ctx, GL_INVALID_VALUE,
404 "glTex%sParameter(param=%d)", suffix,
405 params[0]);
406 return GL_FALSE;
407 }
408 incomplete(ctx, texObj);
409
410 /** From ARB_texture_storage:
411 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
412 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
413 * the range [level_base, <levels> - 1], where <levels> is the parameter
414 * passed the call to TexStorage* for the texture object.
415 */
416 if (texObj->Immutable)
417 texObj->MaxLevel = CLAMP(params[0], texObj->BaseLevel,
418 texObj->ImmutableLevels - 1);
419 else
420 texObj->MaxLevel = params[0];
421
422 return GL_TRUE;
423
424 case GL_GENERATE_MIPMAP_SGIS:
425 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
426 goto invalid_pname;
427
428 if (params[0] && texObj->Target == GL_TEXTURE_EXTERNAL_OES)
429 goto invalid_param;
430 if (texObj->GenerateMipmap != params[0]) {
431 /* no flush() */
432 texObj->GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
433 return GL_TRUE;
434 }
435 return GL_FALSE;
436
437 case GL_TEXTURE_COMPARE_MODE_ARB:
438 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow)
439 || _mesa_is_gles3(ctx)) {
440
441 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
442 goto invalid_enum;
443
444 if (texObj->Sampler.CompareMode == params[0])
445 return GL_FALSE;
446 if (params[0] == GL_NONE ||
447 params[0] == GL_COMPARE_R_TO_TEXTURE_ARB) {
448 flush(ctx);
449 texObj->Sampler.CompareMode = params[0];
450 return GL_TRUE;
451 }
452 goto invalid_param;
453 }
454 goto invalid_pname;
455
456 case GL_TEXTURE_COMPARE_FUNC_ARB:
457 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow)
458 || _mesa_is_gles3(ctx)) {
459
460 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
461 goto invalid_enum;
462
463 if (texObj->Sampler.CompareFunc == params[0])
464 return GL_FALSE;
465 switch (params[0]) {
466 case GL_LEQUAL:
467 case GL_GEQUAL:
468 case GL_EQUAL:
469 case GL_NOTEQUAL:
470 case GL_LESS:
471 case GL_GREATER:
472 case GL_ALWAYS:
473 case GL_NEVER:
474 flush(ctx);
475 texObj->Sampler.CompareFunc = params[0];
476 return GL_TRUE;
477 default:
478 goto invalid_param;
479 }
480 }
481 goto invalid_pname;
482
483 case GL_DEPTH_TEXTURE_MODE_ARB:
484 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
485 * existed in OpenGL ES.
486 */
487 if (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_depth_texture) {
488 if (texObj->DepthMode == params[0])
489 return GL_FALSE;
490 if (params[0] == GL_LUMINANCE ||
491 params[0] == GL_INTENSITY ||
492 params[0] == GL_ALPHA ||
493 (ctx->Extensions.ARB_texture_rg && params[0] == GL_RED)) {
494 flush(ctx);
495 texObj->DepthMode = params[0];
496 return GL_TRUE;
497 }
498 goto invalid_param;
499 }
500 goto invalid_pname;
501
502 case GL_DEPTH_STENCIL_TEXTURE_MODE:
503 if (_mesa_has_ARB_stencil_texturing(ctx) || _mesa_is_gles31(ctx)) {
504 bool stencil = params[0] == GL_STENCIL_INDEX;
505 if (!stencil && params[0] != GL_DEPTH_COMPONENT)
506 goto invalid_param;
507
508 if (texObj->StencilSampling == stencil)
509 return GL_FALSE;
510
511 texObj->StencilSampling = stencil;
512 return GL_TRUE;
513 }
514 goto invalid_pname;
515
516 case GL_TEXTURE_CROP_RECT_OES:
517 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
518 goto invalid_pname;
519
520 texObj->CropRect[0] = params[0];
521 texObj->CropRect[1] = params[1];
522 texObj->CropRect[2] = params[2];
523 texObj->CropRect[3] = params[3];
524 return GL_TRUE;
525
526 case GL_TEXTURE_SWIZZLE_R_EXT:
527 case GL_TEXTURE_SWIZZLE_G_EXT:
528 case GL_TEXTURE_SWIZZLE_B_EXT:
529 case GL_TEXTURE_SWIZZLE_A_EXT:
530 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_swizzle)
531 || _mesa_is_gles3(ctx)) {
532 const GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
533 const GLint swz = comp_to_swizzle(params[0]);
534 if (swz < 0) {
535 _mesa_error(ctx, GL_INVALID_ENUM,
536 "glTex%sParameter(swizzle 0x%x)", suffix, params[0]);
537 return GL_FALSE;
538 }
539 assert(comp < 4);
540
541 flush(ctx);
542 texObj->Swizzle[comp] = params[0];
543 set_swizzle_component(&texObj->_Swizzle, comp, swz);
544 return GL_TRUE;
545 }
546 goto invalid_pname;
547
548 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
549 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_swizzle)
550 || _mesa_is_gles3(ctx)) {
551 GLuint comp;
552 flush(ctx);
553 for (comp = 0; comp < 4; comp++) {
554 const GLint swz = comp_to_swizzle(params[comp]);
555 if (swz >= 0) {
556 texObj->Swizzle[comp] = params[comp];
557 set_swizzle_component(&texObj->_Swizzle, comp, swz);
558 }
559 else {
560 _mesa_error(ctx, GL_INVALID_ENUM,
561 "glTex%sParameter(swizzle 0x%x)",
562 suffix, params[comp]);
563 return GL_FALSE;
564 }
565 }
566 return GL_TRUE;
567 }
568 goto invalid_pname;
569
570 case GL_TEXTURE_SRGB_DECODE_EXT:
571 if (ctx->Extensions.EXT_texture_sRGB_decode) {
572 GLenum decode = params[0];
573
574 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
575 goto invalid_enum;
576
577 if (decode == GL_DECODE_EXT || decode == GL_SKIP_DECODE_EXT) {
578 if (texObj->Sampler.sRGBDecode != decode) {
579 flush(ctx);
580 texObj->Sampler.sRGBDecode = decode;
581 }
582 return GL_TRUE;
583 }
584 }
585 goto invalid_pname;
586
587 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
588 if (_mesa_is_desktop_gl(ctx)
589 && ctx->Extensions.AMD_seamless_cubemap_per_texture) {
590 GLenum param = params[0];
591
592 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
593 goto invalid_enum;
594
595 if (param != GL_TRUE && param != GL_FALSE) {
596 goto invalid_param;
597 }
598 if (param != texObj->Sampler.CubeMapSeamless) {
599 flush(ctx);
600 texObj->Sampler.CubeMapSeamless = param;
601 }
602 return GL_TRUE;
603 }
604 goto invalid_pname;
605
606 default:
607 goto invalid_pname;
608 }
609
610 invalid_pname:
611 _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
612 suffix, _mesa_enum_to_string(pname));
613 return GL_FALSE;
614
615 invalid_param:
616 _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(param=%s)",
617 suffix, _mesa_enum_to_string(params[0]));
618 return GL_FALSE;
619
620 invalid_operation:
621 _mesa_error(ctx, GL_INVALID_OPERATION, "glTex%sParameter(pname=%s)",
622 suffix, _mesa_enum_to_string(pname));
623 return GL_FALSE;
624
625 invalid_enum:
626 _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
627 suffix, _mesa_enum_to_string(pname));
628 return GL_FALSE;
629 }
630
631
632 /**
633 * Set a float-valued texture parameter
634 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
635 */
636 static GLboolean
637 set_tex_parameterf(struct gl_context *ctx,
638 struct gl_texture_object *texObj,
639 GLenum pname, const GLfloat *params, bool dsa)
640 {
641 const char *suffix = dsa ? "ture" : "";
642
643 switch (pname) {
644 case GL_TEXTURE_MIN_LOD:
645 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
646 goto invalid_pname;
647
648 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
649 goto invalid_enum;
650
651 if (texObj->Sampler.MinLod == params[0])
652 return GL_FALSE;
653 flush(ctx);
654 texObj->Sampler.MinLod = params[0];
655 return GL_TRUE;
656
657 case GL_TEXTURE_MAX_LOD:
658 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
659 goto invalid_pname;
660
661 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
662 goto invalid_enum;
663
664 if (texObj->Sampler.MaxLod == params[0])
665 return GL_FALSE;
666 flush(ctx);
667 texObj->Sampler.MaxLod = params[0];
668 return GL_TRUE;
669
670 case GL_TEXTURE_PRIORITY:
671 if (ctx->API != API_OPENGL_COMPAT)
672 goto invalid_pname;
673
674 flush(ctx);
675 texObj->Priority = CLAMP(params[0], 0.0F, 1.0F);
676 return GL_TRUE;
677
678 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
679 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
680 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
681 goto invalid_enum;
682
683 if (texObj->Sampler.MaxAnisotropy == params[0])
684 return GL_FALSE;
685 if (params[0] < 1.0F) {
686 _mesa_error(ctx, GL_INVALID_VALUE, "glTex%sParameter(param)",
687 suffix);
688 return GL_FALSE;
689 }
690 flush(ctx);
691 /* clamp to max, that's what NVIDIA does */
692 texObj->Sampler.MaxAnisotropy = MIN2(params[0],
693 ctx->Const.MaxTextureMaxAnisotropy);
694 return GL_TRUE;
695 }
696 else {
697 static GLuint count = 0;
698 if (count++ < 10)
699 goto invalid_pname;
700 }
701 return GL_FALSE;
702
703 case GL_TEXTURE_LOD_BIAS:
704 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
705 if (_mesa_is_gles(ctx))
706 goto invalid_pname;
707
708 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
709 goto invalid_enum;
710
711 if (texObj->Sampler.LodBias != params[0]) {
712 flush(ctx);
713 texObj->Sampler.LodBias = params[0];
714 return GL_TRUE;
715 }
716 break;
717
718 case GL_TEXTURE_BORDER_COLOR:
719 if (ctx->API == API_OPENGLES ||
720 !ctx->Extensions.ARB_texture_border_clamp)
721 goto invalid_pname;
722
723 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
724 goto invalid_enum;
725
726 flush(ctx);
727 /* ARB_texture_float disables clamping */
728 if (ctx->Extensions.ARB_texture_float) {
729 texObj->Sampler.BorderColor.f[RCOMP] = params[0];
730 texObj->Sampler.BorderColor.f[GCOMP] = params[1];
731 texObj->Sampler.BorderColor.f[BCOMP] = params[2];
732 texObj->Sampler.BorderColor.f[ACOMP] = params[3];
733 } else {
734 texObj->Sampler.BorderColor.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F);
735 texObj->Sampler.BorderColor.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F);
736 texObj->Sampler.BorderColor.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F);
737 texObj->Sampler.BorderColor.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F);
738 }
739 return GL_TRUE;
740
741 default:
742 goto invalid_pname;
743 }
744 return GL_FALSE;
745
746 invalid_pname:
747 _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
748 suffix, _mesa_enum_to_string(pname));
749 return GL_FALSE;
750
751 invalid_enum:
752 _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
753 suffix, _mesa_enum_to_string(pname));
754 return GL_FALSE;
755 }
756
757
758 void
759 _mesa_texture_parameterf(struct gl_context *ctx,
760 struct gl_texture_object *texObj,
761 GLenum pname, GLfloat param, bool dsa)
762 {
763 GLboolean need_update;
764
765 switch (pname) {
766 case GL_TEXTURE_MIN_FILTER:
767 case GL_TEXTURE_MAG_FILTER:
768 case GL_TEXTURE_WRAP_S:
769 case GL_TEXTURE_WRAP_T:
770 case GL_TEXTURE_WRAP_R:
771 case GL_TEXTURE_BASE_LEVEL:
772 case GL_TEXTURE_MAX_LEVEL:
773 case GL_GENERATE_MIPMAP_SGIS:
774 case GL_TEXTURE_COMPARE_MODE_ARB:
775 case GL_TEXTURE_COMPARE_FUNC_ARB:
776 case GL_DEPTH_TEXTURE_MODE_ARB:
777 case GL_DEPTH_STENCIL_TEXTURE_MODE:
778 case GL_TEXTURE_SRGB_DECODE_EXT:
779 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
780 case GL_TEXTURE_SWIZZLE_R_EXT:
781 case GL_TEXTURE_SWIZZLE_G_EXT:
782 case GL_TEXTURE_SWIZZLE_B_EXT:
783 case GL_TEXTURE_SWIZZLE_A_EXT:
784 {
785 GLint p[4];
786 p[0] = (param > 0) ?
787 ((param > INT_MAX) ? INT_MAX : (GLint) (param + 0.5)) :
788 ((param < INT_MIN) ? INT_MIN : (GLint) (param - 0.5));
789
790 p[1] = p[2] = p[3] = 0;
791 need_update = set_tex_parameteri(ctx, texObj, pname, p, dsa);
792 }
793 break;
794 case GL_TEXTURE_BORDER_COLOR:
795 case GL_TEXTURE_SWIZZLE_RGBA:
796 _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameterf(non-scalar pname)",
797 dsa ? "ture" : "");
798 return;
799 default:
800 {
801 /* this will generate an error if pname is illegal */
802 GLfloat p[4];
803 p[0] = param;
804 p[1] = p[2] = p[3] = 0.0F;
805 need_update = set_tex_parameterf(ctx, texObj, pname, p, dsa);
806 }
807 }
808
809 if (ctx->Driver.TexParameter && need_update) {
810 ctx->Driver.TexParameter(ctx, texObj, pname, &param);
811 }
812 }
813
814
815 void
816 _mesa_texture_parameterfv(struct gl_context *ctx,
817 struct gl_texture_object *texObj,
818 GLenum pname, const GLfloat *params, bool dsa)
819 {
820 GLboolean need_update;
821 switch (pname) {
822 case GL_TEXTURE_MIN_FILTER:
823 case GL_TEXTURE_MAG_FILTER:
824 case GL_TEXTURE_WRAP_S:
825 case GL_TEXTURE_WRAP_T:
826 case GL_TEXTURE_WRAP_R:
827 case GL_TEXTURE_BASE_LEVEL:
828 case GL_TEXTURE_MAX_LEVEL:
829 case GL_GENERATE_MIPMAP_SGIS:
830 case GL_TEXTURE_COMPARE_MODE_ARB:
831 case GL_TEXTURE_COMPARE_FUNC_ARB:
832 case GL_DEPTH_TEXTURE_MODE_ARB:
833 case GL_DEPTH_STENCIL_TEXTURE_MODE:
834 case GL_TEXTURE_SRGB_DECODE_EXT:
835 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
836 {
837 /* convert float param to int */
838 GLint p[4];
839 p[0] = (GLint) params[0];
840 p[1] = p[2] = p[3] = 0;
841 need_update = set_tex_parameteri(ctx, texObj, pname, p, dsa);
842 }
843 break;
844 case GL_TEXTURE_CROP_RECT_OES:
845 {
846 /* convert float params to int */
847 GLint iparams[4];
848 iparams[0] = (GLint) params[0];
849 iparams[1] = (GLint) params[1];
850 iparams[2] = (GLint) params[2];
851 iparams[3] = (GLint) params[3];
852 need_update = set_tex_parameteri(ctx, texObj, pname, iparams, dsa);
853 }
854 break;
855 case GL_TEXTURE_SWIZZLE_R_EXT:
856 case GL_TEXTURE_SWIZZLE_G_EXT:
857 case GL_TEXTURE_SWIZZLE_B_EXT:
858 case GL_TEXTURE_SWIZZLE_A_EXT:
859 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
860 {
861 GLint p[4] = {0, 0, 0, 0};
862 p[0] = (GLint) params[0];
863 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT) {
864 p[1] = (GLint) params[1];
865 p[2] = (GLint) params[2];
866 p[3] = (GLint) params[3];
867 }
868 need_update = set_tex_parameteri(ctx, texObj, pname, p, dsa);
869 }
870 break;
871 default:
872 /* this will generate an error if pname is illegal */
873 need_update = set_tex_parameterf(ctx, texObj, pname, params, dsa);
874 }
875
876 if (ctx->Driver.TexParameter && need_update) {
877 ctx->Driver.TexParameter(ctx, texObj, pname, params);
878 }
879 }
880
881
882 void
883 _mesa_texture_parameteri(struct gl_context *ctx,
884 struct gl_texture_object *texObj,
885 GLenum pname, GLint param, bool dsa)
886 {
887 GLboolean need_update;
888 switch (pname) {
889 case GL_TEXTURE_MIN_LOD:
890 case GL_TEXTURE_MAX_LOD:
891 case GL_TEXTURE_PRIORITY:
892 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
893 case GL_TEXTURE_LOD_BIAS:
894 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
895 {
896 GLfloat fparam[4];
897 fparam[0] = (GLfloat) param;
898 fparam[1] = fparam[2] = fparam[3] = 0.0F;
899 /* convert int param to float */
900 need_update = set_tex_parameterf(ctx, texObj, pname, fparam, dsa);
901 }
902 break;
903 case GL_TEXTURE_BORDER_COLOR:
904 case GL_TEXTURE_SWIZZLE_RGBA:
905 {
906 _mesa_error(ctx, GL_INVALID_ENUM,
907 "glTex%sParameteri(non-scalar pname)",
908 dsa ? "ture" : "");
909 return;
910 }
911 default:
912 /* this will generate an error if pname is illegal */
913 {
914 GLint iparam[4];
915 iparam[0] = param;
916 iparam[1] = iparam[2] = iparam[3] = 0;
917 need_update = set_tex_parameteri(ctx, texObj, pname, iparam, dsa);
918 }
919 }
920
921 if (ctx->Driver.TexParameter && need_update) {
922 GLfloat fparam = (GLfloat) param;
923 ctx->Driver.TexParameter(ctx, texObj, pname, &fparam);
924 }
925 }
926
927
928 void
929 _mesa_texture_parameteriv(struct gl_context *ctx,
930 struct gl_texture_object *texObj,
931 GLenum pname, const GLint *params, bool dsa)
932 {
933 GLboolean need_update;
934
935 switch (pname) {
936 case GL_TEXTURE_BORDER_COLOR:
937 {
938 /* convert int params to float */
939 GLfloat fparams[4];
940 fparams[0] = INT_TO_FLOAT(params[0]);
941 fparams[1] = INT_TO_FLOAT(params[1]);
942 fparams[2] = INT_TO_FLOAT(params[2]);
943 fparams[3] = INT_TO_FLOAT(params[3]);
944 need_update = set_tex_parameterf(ctx, texObj, pname, fparams, dsa);
945 }
946 break;
947 case GL_TEXTURE_MIN_LOD:
948 case GL_TEXTURE_MAX_LOD:
949 case GL_TEXTURE_PRIORITY:
950 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
951 case GL_TEXTURE_LOD_BIAS:
952 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
953 {
954 /* convert int param to float */
955 GLfloat fparams[4];
956 fparams[0] = (GLfloat) params[0];
957 fparams[1] = fparams[2] = fparams[3] = 0.0F;
958 need_update = set_tex_parameterf(ctx, texObj, pname, fparams, dsa);
959 }
960 break;
961 default:
962 /* this will generate an error if pname is illegal */
963 need_update = set_tex_parameteri(ctx, texObj, pname, params, dsa);
964 }
965
966 if (ctx->Driver.TexParameter && need_update) {
967 GLfloat fparams[4];
968 fparams[0] = INT_TO_FLOAT(params[0]);
969 if (pname == GL_TEXTURE_BORDER_COLOR ||
970 pname == GL_TEXTURE_CROP_RECT_OES) {
971 fparams[1] = INT_TO_FLOAT(params[1]);
972 fparams[2] = INT_TO_FLOAT(params[2]);
973 fparams[3] = INT_TO_FLOAT(params[3]);
974 }
975 ctx->Driver.TexParameter(ctx, texObj, pname, fparams);
976 }
977 }
978
979 void
980 _mesa_texture_parameterIiv(struct gl_context *ctx,
981 struct gl_texture_object *texObj,
982 GLenum pname, const GLint *params, bool dsa)
983 {
984 switch (pname) {
985 case GL_TEXTURE_BORDER_COLOR:
986 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
987 /* set the integer-valued border color */
988 COPY_4V(texObj->Sampler.BorderColor.i, params);
989 break;
990 default:
991 _mesa_texture_parameteriv(ctx, texObj, pname, params, dsa);
992 break;
993 }
994 /* XXX no driver hook for TexParameterIiv() yet */
995 }
996
997 void
998 _mesa_texture_parameterIuiv(struct gl_context *ctx,
999 struct gl_texture_object *texObj,
1000 GLenum pname, const GLuint *params, bool dsa)
1001 {
1002 switch (pname) {
1003 case GL_TEXTURE_BORDER_COLOR:
1004 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1005 /* set the unsigned integer-valued border color */
1006 COPY_4V(texObj->Sampler.BorderColor.ui, params);
1007 break;
1008 default:
1009 _mesa_texture_parameteriv(ctx, texObj, pname, (const GLint *) params,
1010 dsa);
1011 break;
1012 }
1013 /* XXX no driver hook for TexParameterIuiv() yet */
1014 }
1015
1016 void GLAPIENTRY
1017 _mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
1018 {
1019 struct gl_texture_object *texObj;
1020 GET_CURRENT_CONTEXT(ctx);
1021
1022 texObj = get_texobj_by_target(ctx, target, GL_FALSE);
1023 if (!texObj)
1024 return;
1025
1026 _mesa_texture_parameterf(ctx, texObj, pname, param, false);
1027 }
1028
1029 void GLAPIENTRY
1030 _mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1031 {
1032 struct gl_texture_object *texObj;
1033 GET_CURRENT_CONTEXT(ctx);
1034
1035 texObj = get_texobj_by_target(ctx, target, GL_FALSE);
1036 if (!texObj)
1037 return;
1038
1039 _mesa_texture_parameterfv(ctx, texObj, pname, params, false);
1040 }
1041
1042 void GLAPIENTRY
1043 _mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
1044 {
1045 struct gl_texture_object *texObj;
1046 GET_CURRENT_CONTEXT(ctx);
1047
1048 texObj = get_texobj_by_target(ctx, target, GL_FALSE);
1049 if (!texObj)
1050 return;
1051
1052 _mesa_texture_parameteri(ctx, texObj, pname, param, false);
1053 }
1054
1055 void GLAPIENTRY
1056 _mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
1057 {
1058 struct gl_texture_object *texObj;
1059 GET_CURRENT_CONTEXT(ctx);
1060
1061 texObj = get_texobj_by_target(ctx, target, GL_FALSE);
1062 if (!texObj)
1063 return;
1064
1065 _mesa_texture_parameteriv(ctx, texObj, pname, params, false);
1066 }
1067
1068 /**
1069 * Set tex parameter to integer value(s). Primarily intended to set
1070 * integer-valued texture border color (for integer-valued textures).
1071 * New in GL 3.0.
1072 */
1073 void GLAPIENTRY
1074 _mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
1075 {
1076 struct gl_texture_object *texObj;
1077 GET_CURRENT_CONTEXT(ctx);
1078
1079 texObj = get_texobj_by_target(ctx, target, GL_FALSE);
1080 if (!texObj)
1081 return;
1082
1083 _mesa_texture_parameterIiv(ctx, texObj, pname, params, false);
1084 }
1085
1086 /**
1087 * Set tex parameter to unsigned integer value(s). Primarily intended to set
1088 * uint-valued texture border color (for integer-valued textures).
1089 * New in GL 3.0
1090 */
1091 void GLAPIENTRY
1092 _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
1093 {
1094 struct gl_texture_object *texObj;
1095 GET_CURRENT_CONTEXT(ctx);
1096
1097 texObj = get_texobj_by_target(ctx, target, GL_FALSE);
1098 if (!texObj)
1099 return;
1100
1101 _mesa_texture_parameterIuiv(ctx, texObj, pname, params, false);
1102 }
1103
1104
1105 void GLAPIENTRY
1106 _mesa_TextureParameterfv(GLuint texture, GLenum pname, const GLfloat *params)
1107 {
1108 struct gl_texture_object *texObj;
1109 GET_CURRENT_CONTEXT(ctx);
1110
1111 texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
1112 if (!texObj) {
1113 /* User passed a non-generated name. */
1114 _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterfv(texture)");
1115 return;
1116 }
1117
1118 _mesa_texture_parameterfv(ctx, texObj, pname, params, true);
1119 }
1120
1121 void GLAPIENTRY
1122 _mesa_TextureParameterf(GLuint texture, GLenum pname, GLfloat param)
1123 {
1124 struct gl_texture_object *texObj;
1125 GET_CURRENT_CONTEXT(ctx);
1126
1127 texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
1128 if (!texObj) {
1129 /* User passed a non-generated name. */
1130 _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterf(texture)");
1131 return;
1132 }
1133
1134 _mesa_texture_parameterf(ctx, texObj, pname, param, true);
1135 }
1136
1137 void GLAPIENTRY
1138 _mesa_TextureParameteri(GLuint texture, GLenum pname, GLint param)
1139 {
1140 struct gl_texture_object *texObj;
1141 GET_CURRENT_CONTEXT(ctx);
1142
1143 texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
1144 if (!texObj) {
1145 /* User passed a non-generated name. */
1146 _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameteri(texture)");
1147 return;
1148 }
1149
1150 _mesa_texture_parameteri(ctx, texObj, pname, param, true);
1151 }
1152
1153 void GLAPIENTRY
1154 _mesa_TextureParameteriv(GLuint texture, GLenum pname,
1155 const GLint *params)
1156 {
1157 struct gl_texture_object *texObj;
1158 GET_CURRENT_CONTEXT(ctx);
1159
1160 texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
1161 if (!texObj) {
1162 /* User passed a non-generated name. */
1163 _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameteriv(texture)");
1164 return;
1165 }
1166
1167 _mesa_texture_parameteriv(ctx, texObj, pname, params, true);
1168 }
1169
1170
1171 void GLAPIENTRY
1172 _mesa_TextureParameterIiv(GLuint texture, GLenum pname, const GLint *params)
1173 {
1174 struct gl_texture_object *texObj;
1175 GET_CURRENT_CONTEXT(ctx);
1176
1177 texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
1178 if (!texObj) {
1179 /* User passed a non-generated name. */
1180 _mesa_error(ctx, GL_INVALID_OPERATION,
1181 "glTextureParameterIiv(texture)");
1182 return;
1183 }
1184
1185 _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
1186 }
1187
1188 void GLAPIENTRY
1189 _mesa_TextureParameterIuiv(GLuint texture, GLenum pname, const GLuint *params)
1190 {
1191 struct gl_texture_object *texObj;
1192 GET_CURRENT_CONTEXT(ctx);
1193
1194 texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
1195 if (!texObj) {
1196 /* User passed a non-generated name. */
1197 _mesa_error(ctx, GL_INVALID_OPERATION,
1198 "glTextureParameterIuiv(texture)");
1199 return;
1200 }
1201
1202 _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
1203 }
1204
1205 GLboolean
1206 _mesa_legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target,
1207 bool dsa)
1208 {
1209 /* Common targets for desktop GL and GLES 3.1. */
1210 switch (target) {
1211 case GL_TEXTURE_2D:
1212 case GL_TEXTURE_3D:
1213 return GL_TRUE;
1214 case GL_TEXTURE_2D_ARRAY_EXT:
1215 return ctx->Extensions.EXT_texture_array;
1216 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1217 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1218 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1219 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1220 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1221 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1222 return ctx->Extensions.ARB_texture_cube_map;
1223 case GL_TEXTURE_2D_MULTISAMPLE:
1224 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
1225 return ctx->Extensions.ARB_texture_multisample;
1226 case GL_TEXTURE_BUFFER:
1227 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1228 * but not in earlier versions that expose ARB_texture_buffer_object.
1229 *
1230 * From the ARB_texture_buffer_object spec:
1231 * "(7) Do buffer textures support texture parameters (TexParameter) or
1232 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1233 *
1234 * RESOLVED: No. [...] Note that the spec edits above don't add
1235 * explicit error language for any of these cases. That is because
1236 * each of the functions enumerate the set of valid <target>
1237 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1238 * these cases means that target is not legal, and an INVALID_ENUM
1239 * error should be generated."
1240 *
1241 * From the OpenGL 3.1 spec:
1242 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1243 */
1244 return (ctx->API == API_OPENGL_CORE && ctx->Version >= 31) ||
1245 _mesa_has_OES_texture_buffer(ctx);
1246 case GL_TEXTURE_CUBE_MAP_ARRAY:
1247 return _mesa_has_texture_cube_map_array(ctx);
1248 }
1249
1250 if (!_mesa_is_desktop_gl(ctx))
1251 return GL_FALSE;
1252
1253 /* Rest of the desktop GL targets. */
1254 switch (target) {
1255 case GL_TEXTURE_1D:
1256 case GL_PROXY_TEXTURE_1D:
1257 case GL_PROXY_TEXTURE_2D:
1258 case GL_PROXY_TEXTURE_3D:
1259 return GL_TRUE;
1260 case GL_PROXY_TEXTURE_CUBE_MAP:
1261 return ctx->Extensions.ARB_texture_cube_map;
1262 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY:
1263 return ctx->Extensions.ARB_texture_cube_map_array;
1264 case GL_TEXTURE_RECTANGLE_NV:
1265 case GL_PROXY_TEXTURE_RECTANGLE_NV:
1266 return ctx->Extensions.NV_texture_rectangle;
1267 case GL_TEXTURE_1D_ARRAY_EXT:
1268 case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
1269 case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
1270 return ctx->Extensions.EXT_texture_array;
1271 case GL_PROXY_TEXTURE_2D_MULTISAMPLE:
1272 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY:
1273 return ctx->Extensions.ARB_texture_multisample;
1274
1275 /* This is a valid target for dsa, but the OpenGL 4.5 core spec
1276 * (30.10.2014) Section 8.11 Texture Queries says:
1277 * "For GetTextureLevelParameter* only, texture may also be a cube
1278 * map texture object. In this case the query is always performed
1279 * for face zero (the TEXTURE_CUBE_MAP_POSITIVE_X face), since there
1280 * is no way to specify another face."
1281 */
1282 case GL_TEXTURE_CUBE_MAP:
1283 return dsa;
1284 default:
1285 return GL_FALSE;
1286 }
1287 }
1288
1289
1290 static void
1291 get_tex_level_parameter_image(struct gl_context *ctx,
1292 const struct gl_texture_object *texObj,
1293 GLenum target, GLint level,
1294 GLenum pname, GLint *params,
1295 bool dsa)
1296 {
1297 const struct gl_texture_image *img = NULL;
1298 struct gl_texture_image dummy_image;
1299 mesa_format texFormat;
1300 const char *suffix = dsa ? "ture" : "";
1301
1302 img = _mesa_select_tex_image(texObj, target, level);
1303 if (!img || img->TexFormat == MESA_FORMAT_NONE) {
1304 /* In case of undefined texture image return the default values.
1305 *
1306 * From OpenGL 4.0 spec, page 398:
1307 * "The initial internal format of a texel array is RGBA
1308 * instead of 1. TEXTURE_COMPONENTS is deprecated; always
1309 * use TEXTURE_INTERNAL_FORMAT."
1310 */
1311 memset(&dummy_image, 0, sizeof(dummy_image));
1312 dummy_image.TexFormat = MESA_FORMAT_NONE;
1313 dummy_image.InternalFormat = GL_RGBA;
1314 dummy_image._BaseFormat = GL_NONE;
1315 dummy_image.FixedSampleLocations = GL_TRUE;
1316
1317 img = &dummy_image;
1318 }
1319
1320 texFormat = img->TexFormat;
1321
1322 switch (pname) {
1323 case GL_TEXTURE_WIDTH:
1324 *params = img->Width;
1325 break;
1326 case GL_TEXTURE_HEIGHT:
1327 *params = img->Height;
1328 break;
1329 case GL_TEXTURE_DEPTH:
1330 *params = img->Depth;
1331 break;
1332 case GL_TEXTURE_INTERNAL_FORMAT:
1333 if (_mesa_is_format_compressed(texFormat)) {
1334 /* need to return the actual compressed format */
1335 *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
1336 }
1337 else {
1338 /* If the true internal format is not compressed but the user
1339 * requested a generic compressed format, we have to return the
1340 * generic base format that matches.
1341 *
1342 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1343 *
1344 * "If no specific compressed format is available,
1345 * internalformat is instead replaced by the corresponding base
1346 * internal format."
1347 *
1348 * Otherwise just return the user's requested internal format
1349 */
1350 const GLenum f =
1351 _mesa_gl_compressed_format_base_format(img->InternalFormat);
1352
1353 *params = (f != 0) ? f : img->InternalFormat;
1354 }
1355 break;
1356 case GL_TEXTURE_BORDER:
1357 if (ctx->API != API_OPENGL_COMPAT)
1358 goto invalid_pname;
1359 *params = img->Border;
1360 break;
1361 case GL_TEXTURE_RED_SIZE:
1362 case GL_TEXTURE_GREEN_SIZE:
1363 case GL_TEXTURE_BLUE_SIZE:
1364 case GL_TEXTURE_ALPHA_SIZE:
1365 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1366 *params = _mesa_get_format_bits(texFormat, pname);
1367 else
1368 *params = 0;
1369 break;
1370 case GL_TEXTURE_INTENSITY_SIZE:
1371 case GL_TEXTURE_LUMINANCE_SIZE:
1372 if (ctx->API != API_OPENGL_COMPAT)
1373 goto invalid_pname;
1374 if (_mesa_base_format_has_channel(img->_BaseFormat, pname)) {
1375 *params = _mesa_get_format_bits(texFormat, pname);
1376 if (*params == 0) {
1377 /* intensity or luminance is probably stored as RGB[A] */
1378 *params = MIN2(_mesa_get_format_bits(texFormat,
1379 GL_TEXTURE_RED_SIZE),
1380 _mesa_get_format_bits(texFormat,
1381 GL_TEXTURE_GREEN_SIZE));
1382 }
1383 }
1384 else {
1385 *params = 0;
1386 }
1387 break;
1388 case GL_TEXTURE_DEPTH_SIZE_ARB:
1389 if (!ctx->Extensions.ARB_depth_texture)
1390 goto invalid_pname;
1391 *params = _mesa_get_format_bits(texFormat, pname);
1392 break;
1393 case GL_TEXTURE_STENCIL_SIZE:
1394 *params = _mesa_get_format_bits(texFormat, pname);
1395 break;
1396 case GL_TEXTURE_SHARED_SIZE:
1397 if (ctx->Version < 30 &&
1398 !ctx->Extensions.EXT_texture_shared_exponent)
1399 goto invalid_pname;
1400 *params = texFormat == MESA_FORMAT_R9G9B9E5_FLOAT ? 5 : 0;
1401 break;
1402
1403 /* GL_ARB_texture_compression */
1404 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1405 if (_mesa_is_format_compressed(texFormat) &&
1406 !_mesa_is_proxy_texture(target)) {
1407 *params = _mesa_format_image_size(texFormat, img->Width,
1408 img->Height, img->Depth);
1409 }
1410 else {
1411 _mesa_error(ctx, GL_INVALID_OPERATION,
1412 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1413 _mesa_enum_to_string(pname));
1414 }
1415 break;
1416 case GL_TEXTURE_COMPRESSED:
1417 *params = (GLint) _mesa_is_format_compressed(texFormat);
1418 break;
1419
1420 /* GL_ARB_texture_float */
1421 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1422 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1423 if (ctx->API != API_OPENGL_COMPAT)
1424 goto invalid_pname;
1425 /* FALLTHROUGH */
1426 case GL_TEXTURE_RED_TYPE_ARB:
1427 case GL_TEXTURE_GREEN_TYPE_ARB:
1428 case GL_TEXTURE_BLUE_TYPE_ARB:
1429 case GL_TEXTURE_ALPHA_TYPE_ARB:
1430 case GL_TEXTURE_DEPTH_TYPE_ARB:
1431 if (!ctx->Extensions.ARB_texture_float)
1432 goto invalid_pname;
1433 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1434 *params = _mesa_get_format_datatype(texFormat);
1435 else
1436 *params = GL_NONE;
1437 break;
1438
1439 /* GL_ARB_texture_multisample */
1440 case GL_TEXTURE_SAMPLES:
1441 if (!ctx->Extensions.ARB_texture_multisample)
1442 goto invalid_pname;
1443 *params = img->NumSamples;
1444 break;
1445
1446 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1447 if (!ctx->Extensions.ARB_texture_multisample)
1448 goto invalid_pname;
1449 *params = img->FixedSampleLocations;
1450 break;
1451
1452 /* There is never a buffer data store here, but these pnames still have
1453 * to work.
1454 */
1455
1456 /* GL_ARB_texture_buffer_object */
1457 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
1458 if (!ctx->Extensions.ARB_texture_buffer_object)
1459 goto invalid_pname;
1460 *params = 0;
1461 break;
1462
1463 /* GL_ARB_texture_buffer_range */
1464 case GL_TEXTURE_BUFFER_OFFSET:
1465 if (!ctx->Extensions.ARB_texture_buffer_range)
1466 goto invalid_pname;
1467 *params = 0;
1468 break;
1469 case GL_TEXTURE_BUFFER_SIZE:
1470 if (!ctx->Extensions.ARB_texture_buffer_range)
1471 goto invalid_pname;
1472 *params = 0;
1473 break;
1474
1475 default:
1476 goto invalid_pname;
1477 }
1478
1479 /* no error if we get here */
1480 return;
1481
1482 invalid_pname:
1483 _mesa_error(ctx, GL_INVALID_ENUM,
1484 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1485 _mesa_enum_to_string(pname));
1486 }
1487
1488
1489 static void
1490 get_tex_level_parameter_buffer(struct gl_context *ctx,
1491 const struct gl_texture_object *texObj,
1492 GLenum pname, GLint *params, bool dsa)
1493 {
1494 const struct gl_buffer_object *bo = texObj->BufferObject;
1495 mesa_format texFormat = texObj->_BufferObjectFormat;
1496 int bytes = MAX2(1, _mesa_get_format_bytes(texFormat));
1497 GLenum internalFormat = texObj->BufferObjectFormat;
1498 GLenum baseFormat = _mesa_get_format_base_format(texFormat);
1499 const char *suffix = dsa ? "ture" : "";
1500
1501 if (!bo) {
1502 /* undefined texture buffer object */
1503 switch (pname) {
1504 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1505 *params = GL_TRUE;
1506 break;
1507 case GL_TEXTURE_INTERNAL_FORMAT:
1508 *params = internalFormat;
1509 break;
1510 default:
1511 *params = 0;
1512 break;
1513 }
1514 return;
1515 }
1516
1517 switch (pname) {
1518 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
1519 *params = bo->Name;
1520 break;
1521 case GL_TEXTURE_WIDTH:
1522 *params = ((texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize)
1523 / bytes;
1524 break;
1525 case GL_TEXTURE_HEIGHT:
1526 case GL_TEXTURE_DEPTH:
1527 *params = 1;
1528 break;
1529 case GL_TEXTURE_BORDER:
1530 case GL_TEXTURE_SHARED_SIZE:
1531 case GL_TEXTURE_COMPRESSED:
1532 *params = 0;
1533 break;
1534 case GL_TEXTURE_INTERNAL_FORMAT:
1535 *params = internalFormat;
1536 break;
1537 case GL_TEXTURE_RED_SIZE:
1538 case GL_TEXTURE_GREEN_SIZE:
1539 case GL_TEXTURE_BLUE_SIZE:
1540 case GL_TEXTURE_ALPHA_SIZE:
1541 if (_mesa_base_format_has_channel(baseFormat, pname))
1542 *params = _mesa_get_format_bits(texFormat, pname);
1543 else
1544 *params = 0;
1545 break;
1546 case GL_TEXTURE_INTENSITY_SIZE:
1547 case GL_TEXTURE_LUMINANCE_SIZE:
1548 if (_mesa_base_format_has_channel(baseFormat, pname)) {
1549 *params = _mesa_get_format_bits(texFormat, pname);
1550 if (*params == 0) {
1551 /* intensity or luminance is probably stored as RGB[A] */
1552 *params = MIN2(_mesa_get_format_bits(texFormat,
1553 GL_TEXTURE_RED_SIZE),
1554 _mesa_get_format_bits(texFormat,
1555 GL_TEXTURE_GREEN_SIZE));
1556 }
1557 } else {
1558 *params = 0;
1559 }
1560 break;
1561 case GL_TEXTURE_DEPTH_SIZE_ARB:
1562 case GL_TEXTURE_STENCIL_SIZE_EXT:
1563 *params = _mesa_get_format_bits(texFormat, pname);
1564 break;
1565
1566 /* GL_ARB_texture_buffer_range */
1567 case GL_TEXTURE_BUFFER_OFFSET:
1568 if (!ctx->Extensions.ARB_texture_buffer_range)
1569 goto invalid_pname;
1570 *params = texObj->BufferOffset;
1571 break;
1572 case GL_TEXTURE_BUFFER_SIZE:
1573 if (!ctx->Extensions.ARB_texture_buffer_range)
1574 goto invalid_pname;
1575 *params = (texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize;
1576 break;
1577
1578 /* GL_ARB_texture_multisample */
1579 case GL_TEXTURE_SAMPLES:
1580 if (!ctx->Extensions.ARB_texture_multisample)
1581 goto invalid_pname;
1582 *params = 0;
1583 break;
1584
1585 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1586 if (!ctx->Extensions.ARB_texture_multisample)
1587 goto invalid_pname;
1588 *params = GL_TRUE;
1589 break;
1590
1591 /* GL_ARB_texture_compression */
1592 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1593 /* Always illegal for GL_TEXTURE_BUFFER */
1594 _mesa_error(ctx, GL_INVALID_OPERATION,
1595 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1596 _mesa_enum_to_string(pname));
1597 break;
1598
1599 /* GL_ARB_texture_float */
1600 case GL_TEXTURE_RED_TYPE_ARB:
1601 case GL_TEXTURE_GREEN_TYPE_ARB:
1602 case GL_TEXTURE_BLUE_TYPE_ARB:
1603 case GL_TEXTURE_ALPHA_TYPE_ARB:
1604 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1605 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1606 case GL_TEXTURE_DEPTH_TYPE_ARB:
1607 if (!ctx->Extensions.ARB_texture_float)
1608 goto invalid_pname;
1609 if (_mesa_base_format_has_channel(baseFormat, pname))
1610 *params = _mesa_get_format_datatype(texFormat);
1611 else
1612 *params = GL_NONE;
1613 break;
1614
1615 default:
1616 goto invalid_pname;
1617 }
1618
1619 /* no error if we get here */
1620 return;
1621
1622 invalid_pname:
1623 _mesa_error(ctx, GL_INVALID_ENUM,
1624 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1625 _mesa_enum_to_string(pname));
1626 }
1627
1628 static bool
1629 valid_tex_level_parameteriv_target(struct gl_context *ctx, GLenum target,
1630 bool dsa)
1631 {
1632 const char *suffix = dsa ? "ture" : "";
1633 if (!_mesa_legal_get_tex_level_parameter_target(ctx, target, dsa)) {
1634 _mesa_error(ctx, GL_INVALID_ENUM,
1635 "glGetTex%sLevelParameter[if]v(target=%s)", suffix,
1636 _mesa_enum_to_string(target));
1637 return false;
1638 }
1639 return true;
1640 }
1641
1642 /**
1643 * This isn't exposed to the rest of the driver because it is a part of the
1644 * OpenGL API that is rarely used.
1645 */
1646 static void
1647 get_tex_level_parameteriv(struct gl_context *ctx,
1648 struct gl_texture_object *texObj,
1649 GLenum target, GLint level,
1650 GLenum pname, GLint *params,
1651 bool dsa)
1652 {
1653 GLint maxLevels;
1654 const char *suffix = dsa ? "ture" : "";
1655
1656 /* Check for errors */
1657 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
1658 _mesa_error(ctx, GL_INVALID_OPERATION,
1659 "glGetTex%sLevelParameter[if]v("
1660 "current unit >= max combined texture units)", suffix);
1661 return;
1662 }
1663
1664 maxLevels = _mesa_max_texture_levels(ctx, target);
1665 assert(maxLevels != 0);
1666
1667 if (level < 0 || level >= maxLevels) {
1668 _mesa_error(ctx, GL_INVALID_VALUE,
1669 "glGetTex%sLevelParameter[if]v(level out of range)", suffix);
1670 return;
1671 }
1672
1673 /* Get the level parameter */
1674 if (target == GL_TEXTURE_BUFFER) {
1675 get_tex_level_parameter_buffer(ctx, texObj, pname, params, dsa);
1676 }
1677 else {
1678 get_tex_level_parameter_image(ctx, texObj, target,
1679 level, pname, params, dsa);
1680 }
1681 }
1682
1683 void GLAPIENTRY
1684 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
1685 GLenum pname, GLfloat *params )
1686 {
1687 struct gl_texture_object *texObj;
1688 GLint iparam;
1689 GET_CURRENT_CONTEXT(ctx);
1690
1691 if (!valid_tex_level_parameteriv_target(ctx, target, false))
1692 return;
1693
1694 texObj = _mesa_get_current_tex_object(ctx, target);
1695 if (!texObj)
1696 return;
1697
1698 get_tex_level_parameteriv(ctx, texObj, target, level,
1699 pname, &iparam, false);
1700
1701 *params = (GLfloat) iparam;
1702 }
1703
1704 void GLAPIENTRY
1705 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
1706 GLenum pname, GLint *params )
1707 {
1708 struct gl_texture_object *texObj;
1709 GET_CURRENT_CONTEXT(ctx);
1710
1711 if (!valid_tex_level_parameteriv_target(ctx, target, false))
1712 return;
1713
1714 texObj = _mesa_get_current_tex_object(ctx, target);
1715 if (!texObj)
1716 return;
1717
1718 get_tex_level_parameteriv(ctx, texObj, target, level,
1719 pname, params, false);
1720 }
1721
1722 void GLAPIENTRY
1723 _mesa_GetTextureLevelParameterfv(GLuint texture, GLint level,
1724 GLenum pname, GLfloat *params)
1725 {
1726 struct gl_texture_object *texObj;
1727 GLint iparam;
1728 GET_CURRENT_CONTEXT(ctx);
1729
1730 texObj = _mesa_lookup_texture_err(ctx, texture,
1731 "glGetTextureLevelParameterfv");
1732 if (!texObj)
1733 return;
1734
1735 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
1736 return;
1737
1738 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
1739 pname, &iparam, true);
1740
1741 *params = (GLfloat) iparam;
1742 }
1743
1744 void GLAPIENTRY
1745 _mesa_GetTextureLevelParameteriv(GLuint texture, GLint level,
1746 GLenum pname, GLint *params)
1747 {
1748 struct gl_texture_object *texObj;
1749 GET_CURRENT_CONTEXT(ctx);
1750
1751 texObj = _mesa_lookup_texture_err(ctx, texture,
1752 "glGetTextureLevelParameteriv");
1753 if (!texObj)
1754 return;
1755
1756 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
1757 return;
1758
1759 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
1760 pname, params, true);
1761 }
1762
1763 /**
1764 * This isn't exposed to the rest of the driver because it is a part of the
1765 * OpenGL API that is rarely used.
1766 */
1767 static void
1768 get_tex_parameterfv(struct gl_context *ctx,
1769 struct gl_texture_object *obj,
1770 GLenum pname, GLfloat *params, bool dsa)
1771 {
1772 _mesa_lock_context_textures(ctx);
1773 switch (pname) {
1774 case GL_TEXTURE_MAG_FILTER:
1775 *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
1776 break;
1777 case GL_TEXTURE_MIN_FILTER:
1778 *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
1779 break;
1780 case GL_TEXTURE_WRAP_S:
1781 *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
1782 break;
1783 case GL_TEXTURE_WRAP_T:
1784 *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
1785 break;
1786 case GL_TEXTURE_WRAP_R:
1787 *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
1788 break;
1789 case GL_TEXTURE_BORDER_COLOR:
1790 if (ctx->API == API_OPENGLES ||
1791 !ctx->Extensions.ARB_texture_border_clamp)
1792 goto invalid_pname;
1793
1794 if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
1795 _mesa_update_state_locked(ctx);
1796 if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer)) {
1797 params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1798 params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1799 params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1800 params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
1801 }
1802 else {
1803 params[0] = obj->Sampler.BorderColor.f[0];
1804 params[1] = obj->Sampler.BorderColor.f[1];
1805 params[2] = obj->Sampler.BorderColor.f[2];
1806 params[3] = obj->Sampler.BorderColor.f[3];
1807 }
1808 break;
1809 case GL_TEXTURE_RESIDENT:
1810 if (ctx->API != API_OPENGL_COMPAT)
1811 goto invalid_pname;
1812
1813 *params = 1.0F;
1814 break;
1815 case GL_TEXTURE_PRIORITY:
1816 if (ctx->API != API_OPENGL_COMPAT)
1817 goto invalid_pname;
1818
1819 *params = obj->Priority;
1820 break;
1821 case GL_TEXTURE_MIN_LOD:
1822 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1823 goto invalid_pname;
1824
1825 *params = obj->Sampler.MinLod;
1826 break;
1827 case GL_TEXTURE_MAX_LOD:
1828 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1829 goto invalid_pname;
1830
1831 *params = obj->Sampler.MaxLod;
1832 break;
1833 case GL_TEXTURE_BASE_LEVEL:
1834 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1835 goto invalid_pname;
1836
1837 *params = (GLfloat) obj->BaseLevel;
1838 break;
1839 case GL_TEXTURE_MAX_LEVEL:
1840 *params = (GLfloat) obj->MaxLevel;
1841 break;
1842 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1843 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
1844 goto invalid_pname;
1845 *params = obj->Sampler.MaxAnisotropy;
1846 break;
1847 case GL_GENERATE_MIPMAP_SGIS:
1848 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1849 goto invalid_pname;
1850
1851 *params = (GLfloat) obj->GenerateMipmap;
1852 break;
1853 case GL_TEXTURE_COMPARE_MODE_ARB:
1854 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
1855 && !_mesa_is_gles3(ctx))
1856 goto invalid_pname;
1857 *params = (GLfloat) obj->Sampler.CompareMode;
1858 break;
1859 case GL_TEXTURE_COMPARE_FUNC_ARB:
1860 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
1861 && !_mesa_is_gles3(ctx))
1862 goto invalid_pname;
1863 *params = (GLfloat) obj->Sampler.CompareFunc;
1864 break;
1865 case GL_DEPTH_TEXTURE_MODE_ARB:
1866 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1867 * never existed in OpenGL ES.
1868 */
1869 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
1870 goto invalid_pname;
1871 *params = (GLfloat) obj->DepthMode;
1872 break;
1873 case GL_DEPTH_STENCIL_TEXTURE_MODE:
1874 if (!_mesa_has_ARB_stencil_texturing(ctx) && !_mesa_is_gles31(ctx))
1875 goto invalid_pname;
1876 *params = (GLfloat)
1877 (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
1878 break;
1879 case GL_TEXTURE_LOD_BIAS:
1880 if (_mesa_is_gles(ctx))
1881 goto invalid_pname;
1882
1883 *params = obj->Sampler.LodBias;
1884 break;
1885 case GL_TEXTURE_CROP_RECT_OES:
1886 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
1887 goto invalid_pname;
1888
1889 params[0] = (GLfloat) obj->CropRect[0];
1890 params[1] = (GLfloat) obj->CropRect[1];
1891 params[2] = (GLfloat) obj->CropRect[2];
1892 params[3] = (GLfloat) obj->CropRect[3];
1893 break;
1894
1895 case GL_TEXTURE_SWIZZLE_R_EXT:
1896 case GL_TEXTURE_SWIZZLE_G_EXT:
1897 case GL_TEXTURE_SWIZZLE_B_EXT:
1898 case GL_TEXTURE_SWIZZLE_A_EXT:
1899 if ((!_mesa_is_desktop_gl(ctx)
1900 || !ctx->Extensions.EXT_texture_swizzle)
1901 && !_mesa_is_gles3(ctx))
1902 goto invalid_pname;
1903 *params = (GLfloat) obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
1904 break;
1905
1906 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
1907 if ((!_mesa_is_desktop_gl(ctx)
1908 || !ctx->Extensions.EXT_texture_swizzle)
1909 && !_mesa_is_gles3(ctx)) {
1910 goto invalid_pname;
1911 }
1912 else {
1913 GLuint comp;
1914 for (comp = 0; comp < 4; comp++) {
1915 params[comp] = (GLfloat) obj->Swizzle[comp];
1916 }
1917 }
1918 break;
1919
1920 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1921 if (!_mesa_is_desktop_gl(ctx)
1922 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
1923 goto invalid_pname;
1924 *params = (GLfloat) obj->Sampler.CubeMapSeamless;
1925 break;
1926
1927 case GL_TEXTURE_IMMUTABLE_FORMAT:
1928 *params = (GLfloat) obj->Immutable;
1929 break;
1930
1931 case GL_TEXTURE_IMMUTABLE_LEVELS:
1932 if (_mesa_is_gles3(ctx) ||
1933 (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_view))
1934 *params = (GLfloat) obj->ImmutableLevels;
1935 else
1936 goto invalid_pname;
1937 break;
1938
1939 case GL_TEXTURE_VIEW_MIN_LEVEL:
1940 if (!ctx->Extensions.ARB_texture_view)
1941 goto invalid_pname;
1942 *params = (GLfloat) obj->MinLevel;
1943 break;
1944
1945 case GL_TEXTURE_VIEW_NUM_LEVELS:
1946 if (!ctx->Extensions.ARB_texture_view)
1947 goto invalid_pname;
1948 *params = (GLfloat) obj->NumLevels;
1949 break;
1950
1951 case GL_TEXTURE_VIEW_MIN_LAYER:
1952 if (!ctx->Extensions.ARB_texture_view)
1953 goto invalid_pname;
1954 *params = (GLfloat) obj->MinLayer;
1955 break;
1956
1957 case GL_TEXTURE_VIEW_NUM_LAYERS:
1958 if (!ctx->Extensions.ARB_texture_view)
1959 goto invalid_pname;
1960 *params = (GLfloat) obj->NumLayers;
1961 break;
1962
1963 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
1964 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
1965 goto invalid_pname;
1966 *params = (GLfloat) obj->RequiredTextureImageUnits;
1967 break;
1968
1969 case GL_TEXTURE_SRGB_DECODE_EXT:
1970 if (!ctx->Extensions.EXT_texture_sRGB_decode)
1971 goto invalid_pname;
1972 *params = (GLfloat) obj->Sampler.sRGBDecode;
1973 break;
1974
1975 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
1976 if (!ctx->Extensions.ARB_shader_image_load_store)
1977 goto invalid_pname;
1978 *params = (GLfloat) obj->ImageFormatCompatibilityType;
1979 break;
1980
1981 case GL_TEXTURE_TARGET:
1982 if (ctx->API != API_OPENGL_CORE)
1983 goto invalid_pname;
1984 *params = ENUM_TO_FLOAT(obj->Target);
1985 break;
1986
1987 default:
1988 goto invalid_pname;
1989 }
1990
1991 /* no error if we get here */
1992 _mesa_unlock_context_textures(ctx);
1993 return;
1994
1995 invalid_pname:
1996 _mesa_unlock_context_textures(ctx);
1997 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameterfv(pname=0x%x)",
1998 dsa ? "ture" : "", pname);
1999 }
2000
2001
2002 static void
2003 get_tex_parameteriv(struct gl_context *ctx,
2004 struct gl_texture_object *obj,
2005 GLenum pname, GLint *params, bool dsa)
2006 {
2007 _mesa_lock_texture(ctx, obj);
2008 switch (pname) {
2009 case GL_TEXTURE_MAG_FILTER:
2010 *params = (GLint) obj->Sampler.MagFilter;
2011 break;
2012 case GL_TEXTURE_MIN_FILTER:
2013 *params = (GLint) obj->Sampler.MinFilter;
2014 break;
2015 case GL_TEXTURE_WRAP_S:
2016 *params = (GLint) obj->Sampler.WrapS;
2017 break;
2018 case GL_TEXTURE_WRAP_T:
2019 *params = (GLint) obj->Sampler.WrapT;
2020 break;
2021 case GL_TEXTURE_WRAP_R:
2022 *params = (GLint) obj->Sampler.WrapR;
2023 break;
2024 case GL_TEXTURE_BORDER_COLOR:
2025 if (ctx->API == API_OPENGLES ||
2026 !ctx->Extensions.ARB_texture_border_clamp)
2027 goto invalid_pname;
2028
2029 {
2030 GLfloat b[4];
2031 b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
2032 b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
2033 b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
2034 b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
2035 params[0] = FLOAT_TO_INT(b[0]);
2036 params[1] = FLOAT_TO_INT(b[1]);
2037 params[2] = FLOAT_TO_INT(b[2]);
2038 params[3] = FLOAT_TO_INT(b[3]);
2039 }
2040 break;
2041 case GL_TEXTURE_RESIDENT:
2042 if (ctx->API != API_OPENGL_COMPAT)
2043 goto invalid_pname;
2044
2045 *params = 1;
2046 break;
2047 case GL_TEXTURE_PRIORITY:
2048 if (ctx->API != API_OPENGL_COMPAT)
2049 goto invalid_pname;
2050
2051 *params = FLOAT_TO_INT(obj->Priority);
2052 break;
2053 case GL_TEXTURE_MIN_LOD:
2054 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2055 goto invalid_pname;
2056 /* GL spec 'Data Conversions' section specifies that floating-point
2057 * value in integer Get function is rounded to nearest integer
2058 */
2059 *params = IROUND(obj->Sampler.MinLod);
2060 break;
2061 case GL_TEXTURE_MAX_LOD:
2062 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2063 goto invalid_pname;
2064 /* GL spec 'Data Conversions' section specifies that floating-point
2065 * value in integer Get function is rounded to nearest integer
2066 */
2067 *params = IROUND(obj->Sampler.MaxLod);
2068 break;
2069 case GL_TEXTURE_BASE_LEVEL:
2070 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2071 goto invalid_pname;
2072
2073 *params = obj->BaseLevel;
2074 break;
2075 case GL_TEXTURE_MAX_LEVEL:
2076 *params = obj->MaxLevel;
2077 break;
2078 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2079 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
2080 goto invalid_pname;
2081 /* GL spec 'Data Conversions' section specifies that floating-point
2082 * value in integer Get function is rounded to nearest integer
2083 */
2084 *params = IROUND(obj->Sampler.MaxAnisotropy);
2085 break;
2086 case GL_GENERATE_MIPMAP_SGIS:
2087 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
2088 goto invalid_pname;
2089
2090 *params = (GLint) obj->GenerateMipmap;
2091 break;
2092 case GL_TEXTURE_COMPARE_MODE_ARB:
2093 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2094 && !_mesa_is_gles3(ctx))
2095 goto invalid_pname;
2096 *params = (GLint) obj->Sampler.CompareMode;
2097 break;
2098 case GL_TEXTURE_COMPARE_FUNC_ARB:
2099 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2100 && !_mesa_is_gles3(ctx))
2101 goto invalid_pname;
2102 *params = (GLint) obj->Sampler.CompareFunc;
2103 break;
2104 case GL_DEPTH_TEXTURE_MODE_ARB:
2105 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
2106 goto invalid_pname;
2107 *params = (GLint) obj->DepthMode;
2108 break;
2109 case GL_DEPTH_STENCIL_TEXTURE_MODE:
2110 if (!_mesa_has_ARB_stencil_texturing(ctx) && !_mesa_is_gles31(ctx))
2111 goto invalid_pname;
2112 *params = (GLint)
2113 (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
2114 break;
2115 case GL_TEXTURE_LOD_BIAS:
2116 if (_mesa_is_gles(ctx))
2117 goto invalid_pname;
2118
2119 /* GL spec 'Data Conversions' section specifies that floating-point
2120 * value in integer Get function is rounded to nearest integer
2121 */
2122 *params = IROUND(obj->Sampler.LodBias);
2123 break;
2124 case GL_TEXTURE_CROP_RECT_OES:
2125 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
2126 goto invalid_pname;
2127
2128 params[0] = obj->CropRect[0];
2129 params[1] = obj->CropRect[1];
2130 params[2] = obj->CropRect[2];
2131 params[3] = obj->CropRect[3];
2132 break;
2133 case GL_TEXTURE_SWIZZLE_R_EXT:
2134 case GL_TEXTURE_SWIZZLE_G_EXT:
2135 case GL_TEXTURE_SWIZZLE_B_EXT:
2136 case GL_TEXTURE_SWIZZLE_A_EXT:
2137 if ((!_mesa_is_desktop_gl(ctx)
2138 || !ctx->Extensions.EXT_texture_swizzle)
2139 && !_mesa_is_gles3(ctx))
2140 goto invalid_pname;
2141 *params = obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
2142 break;
2143
2144 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
2145 if ((!_mesa_is_desktop_gl(ctx)
2146 || !ctx->Extensions.EXT_texture_swizzle)
2147 && !_mesa_is_gles3(ctx))
2148 goto invalid_pname;
2149 COPY_4V(params, obj->Swizzle);
2150 break;
2151
2152 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
2153 if (!_mesa_is_desktop_gl(ctx)
2154 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
2155 goto invalid_pname;
2156 *params = (GLint) obj->Sampler.CubeMapSeamless;
2157 break;
2158
2159 case GL_TEXTURE_IMMUTABLE_FORMAT:
2160 *params = (GLint) obj->Immutable;
2161 break;
2162
2163 case GL_TEXTURE_IMMUTABLE_LEVELS:
2164 if (_mesa_is_gles3(ctx) ||
2165 (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_view))
2166 *params = obj->ImmutableLevels;
2167 else
2168 goto invalid_pname;
2169 break;
2170
2171 case GL_TEXTURE_VIEW_MIN_LEVEL:
2172 if (!ctx->Extensions.ARB_texture_view)
2173 goto invalid_pname;
2174 *params = (GLint) obj->MinLevel;
2175 break;
2176
2177 case GL_TEXTURE_VIEW_NUM_LEVELS:
2178 if (!ctx->Extensions.ARB_texture_view)
2179 goto invalid_pname;
2180 *params = (GLint) obj->NumLevels;
2181 break;
2182
2183 case GL_TEXTURE_VIEW_MIN_LAYER:
2184 if (!ctx->Extensions.ARB_texture_view)
2185 goto invalid_pname;
2186 *params = (GLint) obj->MinLayer;
2187 break;
2188
2189 case GL_TEXTURE_VIEW_NUM_LAYERS:
2190 if (!ctx->Extensions.ARB_texture_view)
2191 goto invalid_pname;
2192 *params = (GLint) obj->NumLayers;
2193 break;
2194
2195 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
2196 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
2197 goto invalid_pname;
2198 *params = obj->RequiredTextureImageUnits;
2199 break;
2200
2201 case GL_TEXTURE_SRGB_DECODE_EXT:
2202 if (!ctx->Extensions.EXT_texture_sRGB_decode)
2203 goto invalid_pname;
2204 *params = obj->Sampler.sRGBDecode;
2205 break;
2206
2207 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
2208 if (!ctx->Extensions.ARB_shader_image_load_store)
2209 goto invalid_pname;
2210 *params = obj->ImageFormatCompatibilityType;
2211 break;
2212
2213 case GL_TEXTURE_TARGET:
2214 if (ctx->API != API_OPENGL_CORE)
2215 goto invalid_pname;
2216 *params = (GLint) obj->Target;
2217 break;
2218
2219 default:
2220 goto invalid_pname;
2221 }
2222
2223 /* no error if we get here */
2224 _mesa_unlock_texture(ctx, obj);
2225 return;
2226
2227 invalid_pname:
2228 _mesa_unlock_texture(ctx, obj);
2229 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameteriv(pname=0x%x)",
2230 dsa ? "ture" : "", pname);
2231 }
2232
2233 static void
2234 get_tex_parameterIiv(struct gl_context *ctx,
2235 struct gl_texture_object *obj,
2236 GLenum pname, GLint *params, bool dsa)
2237 {
2238 switch (pname) {
2239 case GL_TEXTURE_BORDER_COLOR:
2240 COPY_4V(params, obj->Sampler.BorderColor.i);
2241 break;
2242 default:
2243 get_tex_parameteriv(ctx, obj, pname, params, dsa);
2244 }
2245 }
2246
2247 static void
2248 get_tex_parameterIuiv(struct gl_context *ctx,
2249 struct gl_texture_object *obj,
2250 GLenum pname, GLuint *params, bool dsa)
2251 {
2252 switch (pname) {
2253 case GL_TEXTURE_BORDER_COLOR:
2254 COPY_4V(params, obj->Sampler.BorderColor.i);
2255 break;
2256 default:
2257 {
2258 GLint ip[4];
2259 get_tex_parameteriv(ctx, obj, pname, ip, dsa);
2260 params[0] = ip[0];
2261 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT ||
2262 pname == GL_TEXTURE_CROP_RECT_OES) {
2263 params[1] = ip[1];
2264 params[2] = ip[2];
2265 params[3] = ip[3];
2266 }
2267 }
2268 }
2269 }
2270
2271 void GLAPIENTRY
2272 _mesa_GetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
2273 {
2274 struct gl_texture_object *obj;
2275 GET_CURRENT_CONTEXT(ctx);
2276
2277 obj = get_texobj_by_target(ctx, target, GL_TRUE);
2278 if (!obj)
2279 return;
2280
2281 get_tex_parameterfv(ctx, obj, pname, params, false);
2282 }
2283
2284 void GLAPIENTRY
2285 _mesa_GetTexParameteriv(GLenum target, GLenum pname, GLint *params)
2286 {
2287 struct gl_texture_object *obj;
2288 GET_CURRENT_CONTEXT(ctx);
2289
2290 obj = get_texobj_by_target(ctx, target, GL_TRUE);
2291 if (!obj)
2292 return;
2293
2294 get_tex_parameteriv(ctx, obj, pname, params, false);
2295 }
2296
2297 /** New in GL 3.0 */
2298 void GLAPIENTRY
2299 _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
2300 {
2301 struct gl_texture_object *texObj;
2302 GET_CURRENT_CONTEXT(ctx);
2303
2304 texObj = get_texobj_by_target(ctx, target, GL_TRUE);
2305 if (!texObj)
2306 return;
2307
2308 get_tex_parameterIiv(ctx, texObj, pname, params, false);
2309 }
2310
2311
2312 /** New in GL 3.0 */
2313 void GLAPIENTRY
2314 _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
2315 {
2316 struct gl_texture_object *texObj;
2317 GET_CURRENT_CONTEXT(ctx);
2318
2319 texObj = get_texobj_by_target(ctx, target, GL_TRUE);
2320 if (!texObj)
2321 return;
2322
2323 get_tex_parameterIuiv(ctx, texObj, pname, params, false);
2324 }
2325
2326
2327 void GLAPIENTRY
2328 _mesa_GetTextureParameterfv(GLuint texture, GLenum pname, GLfloat *params)
2329 {
2330 struct gl_texture_object *obj;
2331 GET_CURRENT_CONTEXT(ctx);
2332
2333 obj = get_texobj_by_name(ctx, texture, GL_TRUE);
2334 if (!obj) {
2335 /* User passed a non-generated name. */
2336 _mesa_error(ctx, GL_INVALID_OPERATION,
2337 "glGetTextureParameterfv(texture)");
2338 return;
2339 }
2340
2341 get_tex_parameterfv(ctx, obj, pname, params, true);
2342 }
2343
2344 void GLAPIENTRY
2345 _mesa_GetTextureParameteriv(GLuint texture, GLenum pname, GLint *params)
2346 {
2347 struct gl_texture_object *obj;
2348 GET_CURRENT_CONTEXT(ctx);
2349
2350 obj = get_texobj_by_name(ctx, texture, GL_TRUE);
2351 if (!obj) {
2352 /* User passed a non-generated name. */
2353 _mesa_error(ctx, GL_INVALID_OPERATION,
2354 "glGetTextureParameteriv(texture)");
2355 return;
2356 }
2357
2358 get_tex_parameteriv(ctx, obj, pname, params, true);
2359 }
2360
2361 void GLAPIENTRY
2362 _mesa_GetTextureParameterIiv(GLuint texture, GLenum pname, GLint *params)
2363 {
2364 struct gl_texture_object *texObj;
2365 GET_CURRENT_CONTEXT(ctx);
2366
2367 texObj = get_texobj_by_name(ctx, texture, GL_TRUE);
2368 if (!texObj) {
2369 /* User passed a non-generated name. */
2370 _mesa_error(ctx, GL_INVALID_OPERATION,
2371 "glGetTextureParameterIiv(texture)");
2372 return;
2373 }
2374
2375 get_tex_parameterIiv(ctx, texObj, pname, params, true);
2376 }
2377
2378
2379 void GLAPIENTRY
2380 _mesa_GetTextureParameterIuiv(GLuint texture, GLenum pname, GLuint *params)
2381 {
2382 struct gl_texture_object *texObj;
2383 GET_CURRENT_CONTEXT(ctx);
2384
2385 texObj = get_texobj_by_name(ctx, texture, GL_TRUE);
2386 if (!texObj) {
2387 /* User passed a non-generated name. */
2388 _mesa_error(ctx, GL_INVALID_OPERATION,
2389 "glGetTextureParameterIuiv(texture)");
2390 return;
2391 }
2392
2393 get_tex_parameterIuiv(ctx, texObj, pname, params, true);
2394 }