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