f3a01ae65e56daac50514f8a1c1d7cd4235e9006
[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_GetTextureLevelParameterfvEXT(GLuint texture, GLenum target, GLint level,
1888 GLenum pname, GLfloat *params)
1889 {
1890 struct gl_texture_object *texObj;
1891 GLint iparam;
1892 GET_CURRENT_CONTEXT(ctx);
1893
1894 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1895 "glGetTextureLevelParameterfvEXT");
1896 if (!texObj)
1897 return;
1898
1899 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
1900 return;
1901
1902 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
1903 pname, &iparam, true);
1904
1905 *params = (GLfloat) iparam;
1906 }
1907
1908 void GLAPIENTRY
1909 _mesa_GetTextureLevelParameteriv(GLuint texture, GLint level,
1910 GLenum pname, GLint *params)
1911 {
1912 struct gl_texture_object *texObj;
1913 GET_CURRENT_CONTEXT(ctx);
1914
1915 texObj = _mesa_lookup_texture_err(ctx, texture,
1916 "glGetTextureLevelParameteriv");
1917 if (!texObj)
1918 return;
1919
1920 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
1921 return;
1922
1923 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
1924 pname, params, true);
1925 }
1926
1927 void GLAPIENTRY
1928 _mesa_GetTextureLevelParameterivEXT(GLuint texture, GLenum target, GLint level,
1929 GLenum pname, GLint *params)
1930 {
1931 struct gl_texture_object *texObj;
1932 GET_CURRENT_CONTEXT(ctx);
1933
1934 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1935 "glGetTextureLevelParameterivEXT");
1936 if (!texObj)
1937 return;
1938
1939 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
1940 return;
1941
1942 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
1943 pname, params, true);
1944 }
1945
1946
1947 /**
1948 * This isn't exposed to the rest of the driver because it is a part of the
1949 * OpenGL API that is rarely used.
1950 */
1951 static void
1952 get_tex_parameterfv(struct gl_context *ctx,
1953 struct gl_texture_object *obj,
1954 GLenum pname, GLfloat *params, bool dsa)
1955 {
1956 _mesa_lock_context_textures(ctx);
1957 switch (pname) {
1958 case GL_TEXTURE_MAG_FILTER:
1959 *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
1960 break;
1961 case GL_TEXTURE_MIN_FILTER:
1962 *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
1963 break;
1964 case GL_TEXTURE_WRAP_S:
1965 *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
1966 break;
1967 case GL_TEXTURE_WRAP_T:
1968 *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
1969 break;
1970 case GL_TEXTURE_WRAP_R:
1971 *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
1972 break;
1973 case GL_TEXTURE_BORDER_COLOR:
1974 if (ctx->API == API_OPENGLES ||
1975 !ctx->Extensions.ARB_texture_border_clamp)
1976 goto invalid_pname;
1977
1978 if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
1979 _mesa_update_state_locked(ctx);
1980 if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer)) {
1981 params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1982 params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1983 params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1984 params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
1985 }
1986 else {
1987 params[0] = obj->Sampler.BorderColor.f[0];
1988 params[1] = obj->Sampler.BorderColor.f[1];
1989 params[2] = obj->Sampler.BorderColor.f[2];
1990 params[3] = obj->Sampler.BorderColor.f[3];
1991 }
1992 break;
1993 case GL_TEXTURE_RESIDENT:
1994 if (ctx->API != API_OPENGL_COMPAT)
1995 goto invalid_pname;
1996
1997 *params = 1.0F;
1998 break;
1999 case GL_TEXTURE_PRIORITY:
2000 if (ctx->API != API_OPENGL_COMPAT)
2001 goto invalid_pname;
2002
2003 *params = obj->Priority;
2004 break;
2005 case GL_TEXTURE_MIN_LOD:
2006 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2007 goto invalid_pname;
2008
2009 *params = obj->Sampler.MinLod;
2010 break;
2011 case GL_TEXTURE_MAX_LOD:
2012 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2013 goto invalid_pname;
2014
2015 *params = obj->Sampler.MaxLod;
2016 break;
2017 case GL_TEXTURE_BASE_LEVEL:
2018 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2019 goto invalid_pname;
2020
2021 *params = (GLfloat) obj->BaseLevel;
2022 break;
2023 case GL_TEXTURE_MAX_LEVEL:
2024 *params = (GLfloat) obj->MaxLevel;
2025 break;
2026 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2027 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
2028 goto invalid_pname;
2029 *params = obj->Sampler.MaxAnisotropy;
2030 break;
2031 case GL_GENERATE_MIPMAP_SGIS:
2032 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
2033 goto invalid_pname;
2034
2035 *params = (GLfloat) obj->GenerateMipmap;
2036 break;
2037 case GL_TEXTURE_COMPARE_MODE_ARB:
2038 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2039 && !_mesa_is_gles3(ctx))
2040 goto invalid_pname;
2041 *params = (GLfloat) obj->Sampler.CompareMode;
2042 break;
2043 case GL_TEXTURE_COMPARE_FUNC_ARB:
2044 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2045 && !_mesa_is_gles3(ctx))
2046 goto invalid_pname;
2047 *params = (GLfloat) obj->Sampler.CompareFunc;
2048 break;
2049 case GL_DEPTH_TEXTURE_MODE_ARB:
2050 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
2051 * never existed in OpenGL ES.
2052 */
2053 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
2054 goto invalid_pname;
2055 *params = (GLfloat) obj->DepthMode;
2056 break;
2057 case GL_DEPTH_STENCIL_TEXTURE_MODE:
2058 if (!_mesa_has_ARB_stencil_texturing(ctx) && !_mesa_is_gles31(ctx))
2059 goto invalid_pname;
2060 *params = (GLfloat)
2061 (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
2062 break;
2063 case GL_TEXTURE_LOD_BIAS:
2064 if (_mesa_is_gles(ctx))
2065 goto invalid_pname;
2066
2067 *params = obj->Sampler.LodBias;
2068 break;
2069 case GL_TEXTURE_CROP_RECT_OES:
2070 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
2071 goto invalid_pname;
2072
2073 params[0] = (GLfloat) obj->CropRect[0];
2074 params[1] = (GLfloat) obj->CropRect[1];
2075 params[2] = (GLfloat) obj->CropRect[2];
2076 params[3] = (GLfloat) obj->CropRect[3];
2077 break;
2078
2079 case GL_TEXTURE_SWIZZLE_R_EXT:
2080 case GL_TEXTURE_SWIZZLE_G_EXT:
2081 case GL_TEXTURE_SWIZZLE_B_EXT:
2082 case GL_TEXTURE_SWIZZLE_A_EXT:
2083 if ((!_mesa_is_desktop_gl(ctx)
2084 || !ctx->Extensions.EXT_texture_swizzle)
2085 && !_mesa_is_gles3(ctx))
2086 goto invalid_pname;
2087 *params = (GLfloat) obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
2088 break;
2089
2090 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
2091 if ((!_mesa_is_desktop_gl(ctx)
2092 || !ctx->Extensions.EXT_texture_swizzle)
2093 && !_mesa_is_gles3(ctx)) {
2094 goto invalid_pname;
2095 }
2096 else {
2097 GLuint comp;
2098 for (comp = 0; comp < 4; comp++) {
2099 params[comp] = (GLfloat) obj->Swizzle[comp];
2100 }
2101 }
2102 break;
2103
2104 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
2105 if (!_mesa_is_desktop_gl(ctx)
2106 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
2107 goto invalid_pname;
2108 *params = (GLfloat) obj->Sampler.CubeMapSeamless;
2109 break;
2110
2111 case GL_TEXTURE_IMMUTABLE_FORMAT:
2112 *params = (GLfloat) obj->Immutable;
2113 break;
2114
2115 case GL_TEXTURE_IMMUTABLE_LEVELS:
2116 if (_mesa_is_gles3(ctx) || _mesa_has_texture_view(ctx))
2117 *params = (GLfloat) obj->ImmutableLevels;
2118 else
2119 goto invalid_pname;
2120 break;
2121
2122 case GL_TEXTURE_VIEW_MIN_LEVEL:
2123 if (!_mesa_has_texture_view(ctx))
2124 goto invalid_pname;
2125 *params = (GLfloat) obj->MinLevel;
2126 break;
2127
2128 case GL_TEXTURE_VIEW_NUM_LEVELS:
2129 if (!_mesa_has_texture_view(ctx))
2130 goto invalid_pname;
2131 *params = (GLfloat) obj->NumLevels;
2132 break;
2133
2134 case GL_TEXTURE_VIEW_MIN_LAYER:
2135 if (!_mesa_has_texture_view(ctx))
2136 goto invalid_pname;
2137 *params = (GLfloat) obj->MinLayer;
2138 break;
2139
2140 case GL_TEXTURE_VIEW_NUM_LAYERS:
2141 if (!_mesa_has_texture_view(ctx))
2142 goto invalid_pname;
2143 *params = (GLfloat) obj->NumLayers;
2144 break;
2145
2146 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
2147 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
2148 goto invalid_pname;
2149 *params = (GLfloat) obj->RequiredTextureImageUnits;
2150 break;
2151
2152 case GL_TEXTURE_SRGB_DECODE_EXT:
2153 if (!ctx->Extensions.EXT_texture_sRGB_decode)
2154 goto invalid_pname;
2155 *params = (GLfloat) obj->Sampler.sRGBDecode;
2156 break;
2157
2158 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
2159 if (!ctx->Extensions.ARB_shader_image_load_store)
2160 goto invalid_pname;
2161 *params = (GLfloat) obj->ImageFormatCompatibilityType;
2162 break;
2163
2164 case GL_TEXTURE_TARGET:
2165 if (ctx->API != API_OPENGL_CORE)
2166 goto invalid_pname;
2167 *params = ENUM_TO_FLOAT(obj->Target);
2168 break;
2169
2170 case GL_TEXTURE_TILING_EXT:
2171 if (!ctx->Extensions.EXT_memory_object)
2172 goto invalid_pname;
2173 *params = ENUM_TO_FLOAT(obj->TextureTiling);
2174 break;
2175
2176 default:
2177 goto invalid_pname;
2178 }
2179
2180 /* no error if we get here */
2181 _mesa_unlock_context_textures(ctx);
2182 return;
2183
2184 invalid_pname:
2185 _mesa_unlock_context_textures(ctx);
2186 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameterfv(pname=0x%x)",
2187 dsa ? "ture" : "", pname);
2188 }
2189
2190
2191 static void
2192 get_tex_parameteriv(struct gl_context *ctx,
2193 struct gl_texture_object *obj,
2194 GLenum pname, GLint *params, bool dsa)
2195 {
2196 _mesa_lock_texture(ctx, obj);
2197 switch (pname) {
2198 case GL_TEXTURE_MAG_FILTER:
2199 *params = (GLint) obj->Sampler.MagFilter;
2200 break;
2201 case GL_TEXTURE_MIN_FILTER:
2202 *params = (GLint) obj->Sampler.MinFilter;
2203 break;
2204 case GL_TEXTURE_WRAP_S:
2205 *params = (GLint) obj->Sampler.WrapS;
2206 break;
2207 case GL_TEXTURE_WRAP_T:
2208 *params = (GLint) obj->Sampler.WrapT;
2209 break;
2210 case GL_TEXTURE_WRAP_R:
2211 *params = (GLint) obj->Sampler.WrapR;
2212 break;
2213 case GL_TEXTURE_BORDER_COLOR:
2214 if (ctx->API == API_OPENGLES ||
2215 !ctx->Extensions.ARB_texture_border_clamp)
2216 goto invalid_pname;
2217
2218 {
2219 GLfloat b[4];
2220 b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
2221 b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
2222 b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
2223 b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
2224 params[0] = FLOAT_TO_INT(b[0]);
2225 params[1] = FLOAT_TO_INT(b[1]);
2226 params[2] = FLOAT_TO_INT(b[2]);
2227 params[3] = FLOAT_TO_INT(b[3]);
2228 }
2229 break;
2230 case GL_TEXTURE_RESIDENT:
2231 if (ctx->API != API_OPENGL_COMPAT)
2232 goto invalid_pname;
2233
2234 *params = 1;
2235 break;
2236 case GL_TEXTURE_PRIORITY:
2237 if (ctx->API != API_OPENGL_COMPAT)
2238 goto invalid_pname;
2239
2240 *params = FLOAT_TO_INT(obj->Priority);
2241 break;
2242 case GL_TEXTURE_MIN_LOD:
2243 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2244 goto invalid_pname;
2245 /* GL spec 'Data Conversions' section specifies that floating-point
2246 * value in integer Get function is rounded to nearest integer
2247 */
2248 *params = IROUND(obj->Sampler.MinLod);
2249 break;
2250 case GL_TEXTURE_MAX_LOD:
2251 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2252 goto invalid_pname;
2253 /* GL spec 'Data Conversions' section specifies that floating-point
2254 * value in integer Get function is rounded to nearest integer
2255 */
2256 *params = IROUND(obj->Sampler.MaxLod);
2257 break;
2258 case GL_TEXTURE_BASE_LEVEL:
2259 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2260 goto invalid_pname;
2261
2262 *params = obj->BaseLevel;
2263 break;
2264 case GL_TEXTURE_MAX_LEVEL:
2265 *params = obj->MaxLevel;
2266 break;
2267 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2268 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
2269 goto invalid_pname;
2270 /* GL spec 'Data Conversions' section specifies that floating-point
2271 * value in integer Get function is rounded to nearest integer
2272 */
2273 *params = IROUND(obj->Sampler.MaxAnisotropy);
2274 break;
2275 case GL_GENERATE_MIPMAP_SGIS:
2276 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
2277 goto invalid_pname;
2278
2279 *params = (GLint) obj->GenerateMipmap;
2280 break;
2281 case GL_TEXTURE_COMPARE_MODE_ARB:
2282 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2283 && !_mesa_is_gles3(ctx))
2284 goto invalid_pname;
2285 *params = (GLint) obj->Sampler.CompareMode;
2286 break;
2287 case GL_TEXTURE_COMPARE_FUNC_ARB:
2288 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2289 && !_mesa_is_gles3(ctx))
2290 goto invalid_pname;
2291 *params = (GLint) obj->Sampler.CompareFunc;
2292 break;
2293 case GL_DEPTH_TEXTURE_MODE_ARB:
2294 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
2295 goto invalid_pname;
2296 *params = (GLint) obj->DepthMode;
2297 break;
2298 case GL_DEPTH_STENCIL_TEXTURE_MODE:
2299 if (!_mesa_has_ARB_stencil_texturing(ctx) && !_mesa_is_gles31(ctx))
2300 goto invalid_pname;
2301 *params = (GLint)
2302 (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
2303 break;
2304 case GL_TEXTURE_LOD_BIAS:
2305 if (_mesa_is_gles(ctx))
2306 goto invalid_pname;
2307
2308 /* GL spec 'Data Conversions' section specifies that floating-point
2309 * value in integer Get function is rounded to nearest integer
2310 */
2311 *params = IROUND(obj->Sampler.LodBias);
2312 break;
2313 case GL_TEXTURE_CROP_RECT_OES:
2314 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
2315 goto invalid_pname;
2316
2317 params[0] = obj->CropRect[0];
2318 params[1] = obj->CropRect[1];
2319 params[2] = obj->CropRect[2];
2320 params[3] = obj->CropRect[3];
2321 break;
2322 case GL_TEXTURE_SWIZZLE_R_EXT:
2323 case GL_TEXTURE_SWIZZLE_G_EXT:
2324 case GL_TEXTURE_SWIZZLE_B_EXT:
2325 case GL_TEXTURE_SWIZZLE_A_EXT:
2326 if ((!_mesa_is_desktop_gl(ctx)
2327 || !ctx->Extensions.EXT_texture_swizzle)
2328 && !_mesa_is_gles3(ctx))
2329 goto invalid_pname;
2330 *params = obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
2331 break;
2332
2333 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
2334 if ((!_mesa_is_desktop_gl(ctx)
2335 || !ctx->Extensions.EXT_texture_swizzle)
2336 && !_mesa_is_gles3(ctx))
2337 goto invalid_pname;
2338 COPY_4V(params, obj->Swizzle);
2339 break;
2340
2341 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
2342 if (!_mesa_is_desktop_gl(ctx)
2343 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
2344 goto invalid_pname;
2345 *params = (GLint) obj->Sampler.CubeMapSeamless;
2346 break;
2347
2348 case GL_TEXTURE_IMMUTABLE_FORMAT:
2349 *params = (GLint) obj->Immutable;
2350 break;
2351
2352 case GL_TEXTURE_IMMUTABLE_LEVELS:
2353 if (_mesa_is_gles3(ctx) ||
2354 (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_view))
2355 *params = obj->ImmutableLevels;
2356 else
2357 goto invalid_pname;
2358 break;
2359
2360 case GL_TEXTURE_VIEW_MIN_LEVEL:
2361 if (!ctx->Extensions.ARB_texture_view)
2362 goto invalid_pname;
2363 *params = (GLint) obj->MinLevel;
2364 break;
2365
2366 case GL_TEXTURE_VIEW_NUM_LEVELS:
2367 if (!ctx->Extensions.ARB_texture_view)
2368 goto invalid_pname;
2369 *params = (GLint) obj->NumLevels;
2370 break;
2371
2372 case GL_TEXTURE_VIEW_MIN_LAYER:
2373 if (!ctx->Extensions.ARB_texture_view)
2374 goto invalid_pname;
2375 *params = (GLint) obj->MinLayer;
2376 break;
2377
2378 case GL_TEXTURE_VIEW_NUM_LAYERS:
2379 if (!ctx->Extensions.ARB_texture_view)
2380 goto invalid_pname;
2381 *params = (GLint) obj->NumLayers;
2382 break;
2383
2384 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
2385 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
2386 goto invalid_pname;
2387 *params = obj->RequiredTextureImageUnits;
2388 break;
2389
2390 case GL_TEXTURE_SRGB_DECODE_EXT:
2391 if (!ctx->Extensions.EXT_texture_sRGB_decode)
2392 goto invalid_pname;
2393 *params = obj->Sampler.sRGBDecode;
2394 break;
2395
2396 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
2397 if (!ctx->Extensions.ARB_shader_image_load_store)
2398 goto invalid_pname;
2399 *params = obj->ImageFormatCompatibilityType;
2400 break;
2401
2402 case GL_TEXTURE_TARGET:
2403 if (ctx->API != API_OPENGL_CORE)
2404 goto invalid_pname;
2405 *params = (GLint) obj->Target;
2406 break;
2407
2408 case GL_TEXTURE_TILING_EXT:
2409 if (!ctx->Extensions.EXT_memory_object)
2410 goto invalid_pname;
2411 *params = (GLint) obj->TextureTiling;
2412 break;
2413
2414 default:
2415 goto invalid_pname;
2416 }
2417
2418 /* no error if we get here */
2419 _mesa_unlock_texture(ctx, obj);
2420 return;
2421
2422 invalid_pname:
2423 _mesa_unlock_texture(ctx, obj);
2424 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameteriv(pname=0x%x)",
2425 dsa ? "ture" : "", pname);
2426 }
2427
2428 static void
2429 get_tex_parameterIiv(struct gl_context *ctx,
2430 struct gl_texture_object *obj,
2431 GLenum pname, GLint *params, bool dsa)
2432 {
2433 switch (pname) {
2434 case GL_TEXTURE_BORDER_COLOR:
2435 COPY_4V(params, obj->Sampler.BorderColor.i);
2436 break;
2437 default:
2438 get_tex_parameteriv(ctx, obj, pname, params, dsa);
2439 }
2440 }
2441
2442 void GLAPIENTRY
2443 _mesa_GetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
2444 {
2445 struct gl_texture_object *obj;
2446 GET_CURRENT_CONTEXT(ctx);
2447
2448 obj = get_texobj_by_target(ctx, target, GL_TRUE);
2449 if (!obj)
2450 return;
2451
2452 get_tex_parameterfv(ctx, obj, pname, params, false);
2453 }
2454
2455 void GLAPIENTRY
2456 _mesa_GetTexParameteriv(GLenum target, GLenum pname, GLint *params)
2457 {
2458 struct gl_texture_object *obj;
2459 GET_CURRENT_CONTEXT(ctx);
2460
2461 obj = get_texobj_by_target(ctx, target, GL_TRUE);
2462 if (!obj)
2463 return;
2464
2465 get_tex_parameteriv(ctx, obj, pname, params, false);
2466 }
2467
2468 /** New in GL 3.0 */
2469 void GLAPIENTRY
2470 _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
2471 {
2472 struct gl_texture_object *texObj;
2473 GET_CURRENT_CONTEXT(ctx);
2474
2475 texObj = get_texobj_by_target(ctx, target, GL_TRUE);
2476 if (!texObj)
2477 return;
2478
2479 get_tex_parameterIiv(ctx, texObj, pname, params, false);
2480 }
2481
2482
2483 /** New in GL 3.0 */
2484 void GLAPIENTRY
2485 _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
2486 {
2487 struct gl_texture_object *texObj;
2488 GET_CURRENT_CONTEXT(ctx);
2489
2490 texObj = get_texobj_by_target(ctx, target, GL_TRUE);
2491 if (!texObj)
2492 return;
2493
2494 get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, false);
2495 }
2496
2497 void GLAPIENTRY
2498 _mesa_GetTextureParameterfvEXT(GLuint texture, GLenum target, GLenum pname, GLfloat *params)
2499 {
2500 struct gl_texture_object *texObj;
2501 GET_CURRENT_CONTEXT(ctx);
2502
2503 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2504 "glGetTextureParameterfvEXT");
2505 if (!texObj)
2506 return;
2507
2508 if (!is_texparameteri_target_valid(texObj->Target)) {
2509 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTextureParameterfvEXT");
2510 return;
2511 }
2512
2513 get_tex_parameterfv(ctx, texObj, pname, params, true);
2514 }
2515
2516 void GLAPIENTRY
2517 _mesa_GetTextureParameterfv(GLuint texture, GLenum pname, GLfloat *params)
2518 {
2519 struct gl_texture_object *obj;
2520 GET_CURRENT_CONTEXT(ctx);
2521
2522 obj = get_texobj_by_name(ctx, texture, "glGetTextureParameterfv");
2523 if (!obj)
2524 return;
2525
2526 get_tex_parameterfv(ctx, obj, pname, params, true);
2527 }
2528
2529 void GLAPIENTRY
2530 _mesa_GetTextureParameterivEXT(GLuint texture, GLenum target, GLenum pname, GLint *params)
2531 {
2532 struct gl_texture_object *texObj;
2533 GET_CURRENT_CONTEXT(ctx);
2534
2535 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2536 "glGetTextureParameterivEXT");
2537 if (!texObj)
2538 return;
2539
2540 if (!is_texparameteri_target_valid(texObj->Target)) {
2541 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTextureParameterivEXT");
2542 return;
2543 }
2544 get_tex_parameteriv(ctx, texObj, pname, params, true);
2545 }
2546
2547 void GLAPIENTRY
2548 _mesa_GetTextureParameteriv(GLuint texture, GLenum pname, GLint *params)
2549 {
2550 struct gl_texture_object *obj;
2551 GET_CURRENT_CONTEXT(ctx);
2552
2553 obj = get_texobj_by_name(ctx, texture, "glGetTextureParameteriv");
2554 if (!obj)
2555 return;
2556
2557 get_tex_parameteriv(ctx, obj, pname, params, true);
2558 }
2559
2560 void GLAPIENTRY
2561 _mesa_GetTextureParameterIiv(GLuint texture, GLenum pname, GLint *params)
2562 {
2563 struct gl_texture_object *texObj;
2564 GET_CURRENT_CONTEXT(ctx);
2565
2566 texObj = get_texobj_by_name(ctx, texture, "glGetTextureParameterIiv");
2567 if (!texObj)
2568 return;
2569
2570 get_tex_parameterIiv(ctx, texObj, pname, params, true);
2571 }
2572
2573
2574 void GLAPIENTRY
2575 _mesa_GetTextureParameterIuiv(GLuint texture, GLenum pname, GLuint *params)
2576 {
2577 struct gl_texture_object *texObj;
2578 GET_CURRENT_CONTEXT(ctx);
2579
2580 texObj = get_texobj_by_name(ctx, texture, "glGetTextureParameterIuiv");
2581 if (!texObj)
2582 return;
2583
2584 get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, true);
2585 }