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