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