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