glthread: rename marshal.h/c to glthread_marshal.h and glthread_shaderobj.c
[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 {
928 GLfloat fparam[4];
929 fparam[0] = (GLfloat) param;
930 fparam[1] = fparam[2] = fparam[3] = 0.0F;
931 /* convert int param to float */
932 need_update = set_tex_parameterf(ctx, texObj, pname, fparam, dsa);
933 }
934 break;
935 case GL_TEXTURE_BORDER_COLOR:
936 case GL_TEXTURE_SWIZZLE_RGBA:
937 {
938 _mesa_error(ctx, GL_INVALID_ENUM,
939 "glTex%sParameteri(non-scalar pname)",
940 dsa ? "ture" : "");
941 return;
942 }
943 default:
944 /* this will generate an error if pname is illegal */
945 {
946 GLint iparam[4];
947 iparam[0] = param;
948 iparam[1] = iparam[2] = iparam[3] = 0;
949 need_update = set_tex_parameteri(ctx, texObj, pname, iparam, dsa);
950 }
951 }
952
953 if (ctx->Driver.TexParameter && need_update) {
954 ctx->Driver.TexParameter(ctx, texObj, pname);
955 }
956 }
957
958
959 void
960 _mesa_texture_parameteriv(struct gl_context *ctx,
961 struct gl_texture_object *texObj,
962 GLenum pname, const GLint *params, bool dsa)
963 {
964 GLboolean need_update;
965
966 switch (pname) {
967 case GL_TEXTURE_BORDER_COLOR:
968 {
969 /* convert int params to float */
970 GLfloat fparams[4];
971 fparams[0] = INT_TO_FLOAT(params[0]);
972 fparams[1] = INT_TO_FLOAT(params[1]);
973 fparams[2] = INT_TO_FLOAT(params[2]);
974 fparams[3] = INT_TO_FLOAT(params[3]);
975 need_update = set_tex_parameterf(ctx, texObj, pname, fparams, dsa);
976 }
977 break;
978 case GL_TEXTURE_MIN_LOD:
979 case GL_TEXTURE_MAX_LOD:
980 case GL_TEXTURE_PRIORITY:
981 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
982 case GL_TEXTURE_LOD_BIAS:
983 {
984 /* convert int param to float */
985 GLfloat fparams[4];
986 fparams[0] = (GLfloat) params[0];
987 fparams[1] = fparams[2] = fparams[3] = 0.0F;
988 need_update = set_tex_parameterf(ctx, texObj, pname, fparams, dsa);
989 }
990 break;
991 default:
992 /* this will generate an error if pname is illegal */
993 need_update = set_tex_parameteri(ctx, texObj, pname, params, dsa);
994 }
995
996 if (ctx->Driver.TexParameter && need_update) {
997 ctx->Driver.TexParameter(ctx, texObj, pname);
998 }
999 }
1000
1001 void
1002 _mesa_texture_parameterIiv(struct gl_context *ctx,
1003 struct gl_texture_object *texObj,
1004 GLenum pname, const GLint *params, bool dsa)
1005 {
1006 switch (pname) {
1007 case GL_TEXTURE_BORDER_COLOR:
1008 if (texObj->HandleAllocated) {
1009 _mesa_error(ctx, GL_INVALID_OPERATION,
1010 "glTextureParameterIiv(immutable texture)");
1011 return;
1012 }
1013
1014 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target)) {
1015 _mesa_error(ctx, GL_INVALID_ENUM, "glTextureParameterIiv(texture)");
1016 return;
1017 }
1018 FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT);
1019 /* set the integer-valued border color */
1020 COPY_4V(texObj->Sampler.BorderColor.i, params);
1021 break;
1022 default:
1023 _mesa_texture_parameteriv(ctx, texObj, pname, params, dsa);
1024 break;
1025 }
1026 /* XXX no driver hook for TexParameterIiv() yet */
1027 }
1028
1029 void
1030 _mesa_texture_parameterIuiv(struct gl_context *ctx,
1031 struct gl_texture_object *texObj,
1032 GLenum pname, const GLuint *params, bool dsa)
1033 {
1034 switch (pname) {
1035 case GL_TEXTURE_BORDER_COLOR:
1036 if (texObj->HandleAllocated) {
1037 _mesa_error(ctx, GL_INVALID_OPERATION,
1038 "glTextureParameterIuiv(immutable texture)");
1039 return;
1040 }
1041
1042 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target)) {
1043 _mesa_error(ctx, GL_INVALID_ENUM, "glTextureParameterIuiv(texture)");
1044 return;
1045 }
1046 FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT);
1047 /* set the unsigned integer-valued border color */
1048 COPY_4V(texObj->Sampler.BorderColor.ui, params);
1049 break;
1050 default:
1051 _mesa_texture_parameteriv(ctx, texObj, pname, (const GLint *) params,
1052 dsa);
1053 break;
1054 }
1055 /* XXX no driver hook for TexParameterIuiv() yet */
1056 }
1057
1058 void GLAPIENTRY
1059 _mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
1060 {
1061 struct gl_texture_object *texObj;
1062 GET_CURRENT_CONTEXT(ctx);
1063
1064 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1065 ctx->Texture.CurrentUnit,
1066 false,
1067 "glTexParameterf");
1068 if (!texObj)
1069 return;
1070
1071 _mesa_texture_parameterf(ctx, texObj, pname, param, false);
1072 }
1073
1074 void GLAPIENTRY
1075 _mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1076 {
1077 struct gl_texture_object *texObj;
1078 GET_CURRENT_CONTEXT(ctx);
1079
1080 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1081 ctx->Texture.CurrentUnit,
1082 false,
1083 "glTexParameterfv");
1084 if (!texObj)
1085 return;
1086
1087 _mesa_texture_parameterfv(ctx, texObj, pname, params, false);
1088 }
1089
1090 void GLAPIENTRY
1091 _mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
1092 {
1093 struct gl_texture_object *texObj;
1094 GET_CURRENT_CONTEXT(ctx);
1095
1096 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1097 ctx->Texture.CurrentUnit,
1098 false,
1099 "glTexParameteri");
1100 if (!texObj)
1101 return;
1102
1103 _mesa_texture_parameteri(ctx, texObj, pname, param, false);
1104 }
1105
1106 void GLAPIENTRY
1107 _mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
1108 {
1109 struct gl_texture_object *texObj;
1110 GET_CURRENT_CONTEXT(ctx);
1111
1112 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1113 ctx->Texture.CurrentUnit,
1114 false,
1115 "glTexParameteriv");
1116 if (!texObj)
1117 return;
1118
1119 _mesa_texture_parameteriv(ctx, texObj, pname, params, false);
1120 }
1121
1122 /**
1123 * Set tex parameter to integer value(s). Primarily intended to set
1124 * integer-valued texture border color (for integer-valued textures).
1125 * New in GL 3.0.
1126 */
1127 void GLAPIENTRY
1128 _mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
1129 {
1130 struct gl_texture_object *texObj;
1131 GET_CURRENT_CONTEXT(ctx);
1132
1133 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1134 ctx->Texture.CurrentUnit,
1135 false,
1136 "glTexParameterIiv");
1137 if (!texObj)
1138 return;
1139
1140 _mesa_texture_parameterIiv(ctx, texObj, pname, params, false);
1141 }
1142
1143 /**
1144 * Set tex parameter to unsigned integer value(s). Primarily intended to set
1145 * uint-valued texture border color (for integer-valued textures).
1146 * New in GL 3.0
1147 */
1148 void GLAPIENTRY
1149 _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
1150 {
1151 struct gl_texture_object *texObj;
1152 GET_CURRENT_CONTEXT(ctx);
1153
1154 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1155 ctx->Texture.CurrentUnit,
1156 false,
1157 "glTexParameterIuiv");
1158 if (!texObj)
1159 return;
1160
1161 _mesa_texture_parameterIuiv(ctx, texObj, pname, params, false);
1162 }
1163
1164 void GLAPIENTRY
1165 _mesa_TextureParameterfvEXT(GLuint texture, GLenum target, GLenum pname, const GLfloat *params)
1166 {
1167 struct gl_texture_object *texObj;
1168 GET_CURRENT_CONTEXT(ctx);
1169
1170 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1171 "glTextureParameterfvEXT");
1172 if (!texObj)
1173 return;
1174
1175 if (!is_texparameteri_target_valid(texObj->Target)) {
1176 _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterfvEXT");
1177 return;
1178 }
1179
1180 _mesa_texture_parameterfv(ctx, texObj, pname, params, true);
1181 }
1182
1183 void GLAPIENTRY
1184 _mesa_TextureParameterfv(GLuint texture, GLenum pname, const GLfloat *params)
1185 {
1186 struct gl_texture_object *texObj;
1187 GET_CURRENT_CONTEXT(ctx);
1188
1189 texObj = get_texobj_by_name(ctx, texture, "glTextureParameterfv");
1190 if (!texObj)
1191 return;
1192
1193 _mesa_texture_parameterfv(ctx, texObj, pname, params, true);
1194 }
1195
1196 void GLAPIENTRY
1197 _mesa_MultiTexParameterfvEXT(GLenum texunit, GLenum target, GLenum pname, const GLfloat *params)
1198 {
1199 struct gl_texture_object *texObj;
1200 GET_CURRENT_CONTEXT(ctx);
1201
1202 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1203 texunit - GL_TEXTURE0,
1204 false,
1205 "glMultiTexParameterfvEXT");
1206 if (!texObj)
1207 return;
1208
1209 if (!is_texparameteri_target_valid(texObj->Target)) {
1210 _mesa_error(ctx, GL_INVALID_OPERATION, "glMultiTexParameterifvEXT(target)");
1211 return;
1212 }
1213
1214 _mesa_texture_parameterfv(ctx, texObj, pname, params, true);
1215 }
1216
1217 void GLAPIENTRY
1218 _mesa_TextureParameterfEXT(GLuint texture, GLenum target, GLenum pname, GLfloat param)
1219 {
1220 struct gl_texture_object *texObj;
1221 GET_CURRENT_CONTEXT(ctx);
1222
1223 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1224 "glTextureParameterfEXT");
1225 if (!texObj)
1226 return;
1227
1228 if (!is_texparameteri_target_valid(texObj->Target)) {
1229 _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterfEXT");
1230 return;
1231 }
1232
1233 _mesa_texture_parameterf(ctx, texObj, pname, param, true);
1234 }
1235
1236 void GLAPIENTRY
1237 _mesa_MultiTexParameterfEXT(GLenum texunit, GLenum target, GLenum pname,
1238 GLfloat param)
1239 {
1240 struct gl_texture_object *texObj;
1241 GET_CURRENT_CONTEXT(ctx);
1242
1243 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1244 texunit - GL_TEXTURE0,
1245 false,
1246 "glMultiTexParameterfEXT");
1247 if (!texObj)
1248 return;
1249
1250 if (!is_texparameteri_target_valid(texObj->Target)) {
1251 _mesa_error(ctx, GL_INVALID_OPERATION, "glMultiTexParameterfEXT");
1252 return;
1253 }
1254
1255 _mesa_texture_parameterf(ctx, texObj, pname, param, true);
1256 }
1257
1258 void GLAPIENTRY
1259 _mesa_TextureParameterf(GLuint texture, GLenum pname, GLfloat param)
1260 {
1261 struct gl_texture_object *texObj;
1262 GET_CURRENT_CONTEXT(ctx);
1263
1264 texObj = get_texobj_by_name(ctx, texture, "glTextureParameterf");
1265 if (!texObj)
1266 return;
1267
1268 _mesa_texture_parameterf(ctx, texObj, pname, param, true);
1269 }
1270
1271 void GLAPIENTRY
1272 _mesa_TextureParameteriEXT(GLuint texture, GLenum target, GLenum pname, GLint param)
1273 {
1274 struct gl_texture_object *texObj;
1275 GET_CURRENT_CONTEXT(ctx);
1276
1277 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1278 "glTextureParameteriEXT");
1279 if (!texObj)
1280 return;
1281
1282 if (!is_texparameteri_target_valid(texObj->Target)) {
1283 _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameteriEXT(target)");
1284 return;
1285 }
1286
1287 _mesa_texture_parameteri(ctx, texObj, pname, param, true);
1288 }
1289
1290 void GLAPIENTRY
1291 _mesa_MultiTexParameteriEXT(GLenum texunit, GLenum target, GLenum pname,
1292 GLint param)
1293 {
1294 struct gl_texture_object *texObj;
1295 GET_CURRENT_CONTEXT(ctx);
1296
1297 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1298 texunit - GL_TEXTURE0,
1299 false,
1300 "glMultiTexParameteriEXT");
1301 if (!texObj)
1302 return;
1303
1304 if (!is_texparameteri_target_valid(texObj->Target)) {
1305 _mesa_error(ctx, GL_INVALID_OPERATION, "glMultiTexParameteriEXT(target)");
1306 return;
1307 }
1308
1309 _mesa_texture_parameteri(ctx, texObj, pname, param, true);
1310 }
1311
1312 void GLAPIENTRY
1313 _mesa_TextureParameteri(GLuint texture, GLenum pname, GLint param)
1314 {
1315 struct gl_texture_object *texObj;
1316 GET_CURRENT_CONTEXT(ctx);
1317
1318 texObj = get_texobj_by_name(ctx, texture, "glTextureParameteri");
1319 if (!texObj)
1320 return;
1321
1322 _mesa_texture_parameteri(ctx, texObj, pname, param, true);
1323 }
1324
1325 void GLAPIENTRY
1326 _mesa_TextureParameterivEXT(GLuint texture, GLenum target, GLenum pname,
1327 const GLint *params)
1328 {
1329 struct gl_texture_object *texObj;
1330 GET_CURRENT_CONTEXT(ctx);
1331
1332 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1333 "glTextureParameterivEXT");
1334 if (!texObj)
1335 return;
1336
1337 if (!is_texparameteri_target_valid(texObj->Target)) {
1338 _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterivEXT(target)");
1339 return;
1340 }
1341
1342 _mesa_texture_parameteriv(ctx, texObj, pname, params, true);
1343 }
1344
1345 void GLAPIENTRY
1346 _mesa_MultiTexParameterivEXT(GLenum texunit, GLenum target, GLenum pname,
1347 const GLint *params)
1348 {
1349 struct gl_texture_object *texObj;
1350 GET_CURRENT_CONTEXT(ctx);
1351
1352 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1353 texunit - GL_TEXTURE0,
1354 false,
1355 "glMultiTexParameterivEXT");
1356 if (!texObj)
1357 return;
1358
1359 if (!is_texparameteri_target_valid(texObj->Target)) {
1360 _mesa_error(ctx, GL_INVALID_OPERATION, "glMultiTexParameterivEXT(target)");
1361 return;
1362 }
1363
1364 _mesa_texture_parameteriv(ctx, texObj, pname, params, true);
1365 }
1366
1367 void GLAPIENTRY
1368 _mesa_TextureParameteriv(GLuint texture, GLenum pname,
1369 const GLint *params)
1370 {
1371 struct gl_texture_object *texObj;
1372 GET_CURRENT_CONTEXT(ctx);
1373
1374 texObj = get_texobj_by_name(ctx, texture, "glTextureParameteriv");
1375 if (!texObj)
1376 return;
1377
1378 _mesa_texture_parameteriv(ctx, texObj, pname, params, true);
1379 }
1380
1381
1382 void GLAPIENTRY
1383 _mesa_TextureParameterIiv(GLuint texture, GLenum pname, const GLint *params)
1384 {
1385 struct gl_texture_object *texObj;
1386 GET_CURRENT_CONTEXT(ctx);
1387
1388 texObj = get_texobj_by_name(ctx, texture, "glTextureParameterIiv");
1389 if (!texObj)
1390 return;
1391
1392 _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
1393 }
1394
1395 void GLAPIENTRY
1396 _mesa_TextureParameterIivEXT(GLuint texture, GLenum target, GLenum pname,
1397 const GLint *params)
1398 {
1399 struct gl_texture_object *texObj;
1400 GET_CURRENT_CONTEXT(ctx);
1401
1402 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1403 "glTextureParameterIivEXT");
1404 if (!texObj)
1405 return;
1406
1407 _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
1408 }
1409
1410 void GLAPIENTRY
1411 _mesa_MultiTexParameterIivEXT(GLenum texunit, GLenum target, GLenum pname,
1412 const GLint *params)
1413 {
1414 struct gl_texture_object *texObj;
1415 GET_CURRENT_CONTEXT(ctx);
1416
1417 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1418 texunit - GL_TEXTURE0,
1419 true,
1420 "glMultiTexParameterIivEXT");
1421 if (!texObj)
1422 return;
1423
1424 _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
1425 }
1426
1427 void GLAPIENTRY
1428 _mesa_TextureParameterIuiv(GLuint texture, GLenum pname, const GLuint *params)
1429 {
1430 struct gl_texture_object *texObj;
1431 GET_CURRENT_CONTEXT(ctx);
1432
1433 texObj = get_texobj_by_name(ctx, texture, "glTextureParameterIuiv");
1434 if (!texObj)
1435 return;
1436
1437 _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
1438 }
1439
1440 void GLAPIENTRY
1441 _mesa_TextureParameterIuivEXT(GLuint texture, GLenum target, GLenum pname,
1442 const GLuint *params)
1443 {
1444 struct gl_texture_object *texObj;
1445 GET_CURRENT_CONTEXT(ctx);
1446
1447 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1448 "glTextureParameterIuivEXT");
1449 if (!texObj)
1450 return;
1451
1452 _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
1453 }
1454
1455 void GLAPIENTRY
1456 _mesa_MultiTexParameterIuivEXT(GLenum texunit, GLenum target, GLenum pname,
1457 const GLuint *params)
1458 {
1459 struct gl_texture_object *texObj;
1460 GET_CURRENT_CONTEXT(ctx);
1461
1462 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1463 texunit - GL_TEXTURE0,
1464 true,
1465 "glMultiTexParameterIuivEXT");
1466 if (!texObj)
1467 return;
1468
1469 _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
1470 }
1471
1472 GLboolean
1473 _mesa_legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target,
1474 bool dsa)
1475 {
1476 /* Common targets for desktop GL and GLES 3.1. */
1477 switch (target) {
1478 case GL_TEXTURE_2D:
1479 case GL_TEXTURE_3D:
1480 return GL_TRUE;
1481 case GL_TEXTURE_2D_ARRAY_EXT:
1482 return ctx->Extensions.EXT_texture_array;
1483 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1484 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1485 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1486 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1487 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1488 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1489 return ctx->Extensions.ARB_texture_cube_map;
1490 case GL_TEXTURE_2D_MULTISAMPLE:
1491 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
1492 return ctx->Extensions.ARB_texture_multisample;
1493 case GL_TEXTURE_BUFFER:
1494 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1495 * but not in earlier versions that expose ARB_texture_buffer_object.
1496 *
1497 * From the ARB_texture_buffer_object spec:
1498 * "(7) Do buffer textures support texture parameters (TexParameter) or
1499 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1500 *
1501 * RESOLVED: No. [...] Note that the spec edits above don't add
1502 * explicit error language for any of these cases. That is because
1503 * each of the functions enumerate the set of valid <target>
1504 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1505 * these cases means that target is not legal, and an INVALID_ENUM
1506 * error should be generated."
1507 *
1508 * From the OpenGL 3.1 spec:
1509 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1510 */
1511 return (_mesa_is_desktop_gl(ctx) && ctx->Version >= 31) ||
1512 _mesa_has_OES_texture_buffer(ctx);
1513 case GL_TEXTURE_CUBE_MAP_ARRAY:
1514 return _mesa_has_texture_cube_map_array(ctx);
1515 }
1516
1517 if (!_mesa_is_desktop_gl(ctx))
1518 return GL_FALSE;
1519
1520 /* Rest of the desktop GL targets. */
1521 switch (target) {
1522 case GL_TEXTURE_1D:
1523 case GL_PROXY_TEXTURE_1D:
1524 case GL_PROXY_TEXTURE_2D:
1525 case GL_PROXY_TEXTURE_3D:
1526 return GL_TRUE;
1527 case GL_PROXY_TEXTURE_CUBE_MAP:
1528 return ctx->Extensions.ARB_texture_cube_map;
1529 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY:
1530 return ctx->Extensions.ARB_texture_cube_map_array;
1531 case GL_TEXTURE_RECTANGLE_NV:
1532 case GL_PROXY_TEXTURE_RECTANGLE_NV:
1533 return ctx->Extensions.NV_texture_rectangle;
1534 case GL_TEXTURE_1D_ARRAY_EXT:
1535 case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
1536 case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
1537 return ctx->Extensions.EXT_texture_array;
1538 case GL_PROXY_TEXTURE_2D_MULTISAMPLE:
1539 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY:
1540 return ctx->Extensions.ARB_texture_multisample;
1541
1542 /* This is a valid target for dsa, but the OpenGL 4.5 core spec
1543 * (30.10.2014) Section 8.11 Texture Queries says:
1544 * "For GetTextureLevelParameter* only, texture may also be a cube
1545 * map texture object. In this case the query is always performed
1546 * for face zero (the TEXTURE_CUBE_MAP_POSITIVE_X face), since there
1547 * is no way to specify another face."
1548 */
1549 case GL_TEXTURE_CUBE_MAP:
1550 return dsa;
1551 default:
1552 return GL_FALSE;
1553 }
1554 }
1555
1556
1557 static void
1558 get_tex_level_parameter_image(struct gl_context *ctx,
1559 const struct gl_texture_object *texObj,
1560 GLenum target, GLint level,
1561 GLenum pname, GLint *params,
1562 bool dsa)
1563 {
1564 const struct gl_texture_image *img = NULL;
1565 struct gl_texture_image dummy_image;
1566 mesa_format texFormat;
1567 const char *suffix = dsa ? "ture" : "";
1568
1569 img = _mesa_select_tex_image(texObj, target, level);
1570 if (!img || img->TexFormat == MESA_FORMAT_NONE) {
1571 /* In case of undefined texture image return the default values.
1572 *
1573 * From OpenGL 4.0 spec, page 398:
1574 * "The initial internal format of a texel array is RGBA
1575 * instead of 1. TEXTURE_COMPONENTS is deprecated; always
1576 * use TEXTURE_INTERNAL_FORMAT."
1577 */
1578 memset(&dummy_image, 0, sizeof(dummy_image));
1579 dummy_image.TexFormat = MESA_FORMAT_NONE;
1580 dummy_image.InternalFormat = GL_RGBA;
1581 dummy_image._BaseFormat = GL_NONE;
1582 dummy_image.FixedSampleLocations = GL_TRUE;
1583
1584 img = &dummy_image;
1585 }
1586
1587 texFormat = img->TexFormat;
1588
1589 switch (pname) {
1590 case GL_TEXTURE_WIDTH:
1591 *params = img->Width;
1592 break;
1593 case GL_TEXTURE_HEIGHT:
1594 *params = img->Height;
1595 break;
1596 case GL_TEXTURE_DEPTH:
1597 *params = img->Depth;
1598 break;
1599 case GL_TEXTURE_INTERNAL_FORMAT:
1600 if (_mesa_is_format_compressed(texFormat)) {
1601 /* need to return the actual compressed format */
1602 *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
1603 }
1604 else {
1605 /* If the true internal format is not compressed but the user
1606 * requested a generic compressed format, we have to return the
1607 * generic base format that matches.
1608 *
1609 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1610 *
1611 * "If no specific compressed format is available,
1612 * internalformat is instead replaced by the corresponding base
1613 * internal format."
1614 *
1615 * Otherwise just return the user's requested internal format
1616 */
1617 const GLenum f =
1618 _mesa_gl_compressed_format_base_format(img->InternalFormat);
1619
1620 *params = (f != 0) ? f : img->InternalFormat;
1621 }
1622 break;
1623 case GL_TEXTURE_BORDER:
1624 if (ctx->API != API_OPENGL_COMPAT)
1625 goto invalid_pname;
1626 *params = img->Border;
1627 break;
1628 case GL_TEXTURE_RED_SIZE:
1629 case GL_TEXTURE_GREEN_SIZE:
1630 case GL_TEXTURE_BLUE_SIZE:
1631 case GL_TEXTURE_ALPHA_SIZE:
1632 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1633 *params = _mesa_get_format_bits(texFormat, pname);
1634 else
1635 *params = 0;
1636 break;
1637 case GL_TEXTURE_INTENSITY_SIZE:
1638 case GL_TEXTURE_LUMINANCE_SIZE:
1639 if (ctx->API != API_OPENGL_COMPAT)
1640 goto invalid_pname;
1641 if (_mesa_base_format_has_channel(img->_BaseFormat, pname)) {
1642 *params = _mesa_get_format_bits(texFormat, pname);
1643 if (*params == 0) {
1644 /* intensity or luminance is probably stored as RGB[A] */
1645 *params = MIN2(_mesa_get_format_bits(texFormat,
1646 GL_TEXTURE_RED_SIZE),
1647 _mesa_get_format_bits(texFormat,
1648 GL_TEXTURE_GREEN_SIZE));
1649 }
1650 if (*params == 0 && pname == GL_TEXTURE_INTENSITY_SIZE) {
1651 /* Gallium may store intensity as LA */
1652 *params = _mesa_get_format_bits(texFormat,
1653 GL_TEXTURE_ALPHA_SIZE);
1654 }
1655 }
1656 else {
1657 *params = 0;
1658 }
1659 break;
1660 case GL_TEXTURE_DEPTH_SIZE_ARB:
1661 if (!ctx->Extensions.ARB_depth_texture)
1662 goto invalid_pname;
1663 *params = _mesa_get_format_bits(texFormat, pname);
1664 break;
1665 case GL_TEXTURE_STENCIL_SIZE:
1666 *params = _mesa_get_format_bits(texFormat, pname);
1667 break;
1668 case GL_TEXTURE_SHARED_SIZE:
1669 if (ctx->Version < 30 &&
1670 !ctx->Extensions.EXT_texture_shared_exponent)
1671 goto invalid_pname;
1672 *params = texFormat == MESA_FORMAT_R9G9B9E5_FLOAT ? 5 : 0;
1673 break;
1674
1675 /* GL_ARB_texture_compression */
1676 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1677 if (_mesa_is_format_compressed(texFormat) &&
1678 !_mesa_is_proxy_texture(target)) {
1679 *params = _mesa_format_image_size(texFormat, img->Width,
1680 img->Height, img->Depth);
1681 } else {
1682 _mesa_error(ctx, GL_INVALID_OPERATION,
1683 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1684 _mesa_enum_to_string(pname));
1685 }
1686 break;
1687 case GL_TEXTURE_COMPRESSED:
1688 *params = (GLint) _mesa_is_format_compressed(texFormat);
1689 break;
1690
1691 /* GL_ARB_texture_float */
1692 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1693 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1694 if (ctx->API != API_OPENGL_COMPAT)
1695 goto invalid_pname;
1696 /* FALLTHROUGH */
1697 case GL_TEXTURE_RED_TYPE_ARB:
1698 case GL_TEXTURE_GREEN_TYPE_ARB:
1699 case GL_TEXTURE_BLUE_TYPE_ARB:
1700 case GL_TEXTURE_ALPHA_TYPE_ARB:
1701 case GL_TEXTURE_DEPTH_TYPE_ARB:
1702 if (!ctx->Extensions.ARB_texture_float)
1703 goto invalid_pname;
1704 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1705 *params = _mesa_get_format_datatype(texFormat);
1706 else
1707 *params = GL_NONE;
1708 break;
1709
1710 /* GL_ARB_texture_multisample */
1711 case GL_TEXTURE_SAMPLES:
1712 if (!ctx->Extensions.ARB_texture_multisample)
1713 goto invalid_pname;
1714 *params = img->NumSamples;
1715 break;
1716
1717 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1718 if (!ctx->Extensions.ARB_texture_multisample)
1719 goto invalid_pname;
1720 *params = img->FixedSampleLocations;
1721 break;
1722
1723 /* There is never a buffer data store here, but these pnames still have
1724 * to work.
1725 */
1726
1727 /* GL_ARB_texture_buffer_object */
1728 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
1729 if (!ctx->Extensions.ARB_texture_buffer_object)
1730 goto invalid_pname;
1731 *params = 0;
1732 break;
1733
1734 /* GL_ARB_texture_buffer_range */
1735 case GL_TEXTURE_BUFFER_OFFSET:
1736 if (!ctx->Extensions.ARB_texture_buffer_range)
1737 goto invalid_pname;
1738 *params = 0;
1739 break;
1740 case GL_TEXTURE_BUFFER_SIZE:
1741 if (!ctx->Extensions.ARB_texture_buffer_range)
1742 goto invalid_pname;
1743 *params = 0;
1744 break;
1745
1746 default:
1747 goto invalid_pname;
1748 }
1749
1750 /* no error if we get here */
1751 return;
1752
1753 invalid_pname:
1754 _mesa_error(ctx, GL_INVALID_ENUM,
1755 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1756 _mesa_enum_to_string(pname));
1757 }
1758
1759
1760 /**
1761 * Handle a glGetTexLevelParamteriv() call for a texture buffer.
1762 */
1763 static void
1764 get_tex_level_parameter_buffer(struct gl_context *ctx,
1765 const struct gl_texture_object *texObj,
1766 GLenum pname, GLint *params, bool dsa)
1767 {
1768 const struct gl_buffer_object *bo = texObj->BufferObject;
1769 mesa_format texFormat = texObj->_BufferObjectFormat;
1770 int bytes = MAX2(1, _mesa_get_format_bytes(texFormat));
1771 GLenum internalFormat = texObj->BufferObjectFormat;
1772 GLenum baseFormat = _mesa_get_format_base_format(texFormat);
1773 const char *suffix = dsa ? "ture" : "";
1774
1775 assert(texObj->Target == GL_TEXTURE_BUFFER);
1776
1777 if (!bo) {
1778 /* undefined texture buffer object */
1779 switch (pname) {
1780 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1781 *params = GL_TRUE;
1782 break;
1783 case GL_TEXTURE_INTERNAL_FORMAT:
1784 *params = internalFormat;
1785 break;
1786 default:
1787 *params = 0;
1788 break;
1789 }
1790 return;
1791 }
1792
1793 switch (pname) {
1794 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
1795 *params = bo->Name;
1796 break;
1797 case GL_TEXTURE_WIDTH:
1798 *params = ((texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize)
1799 / bytes;
1800 break;
1801 case GL_TEXTURE_HEIGHT:
1802 case GL_TEXTURE_DEPTH:
1803 *params = 1;
1804 break;
1805 case GL_TEXTURE_BORDER:
1806 case GL_TEXTURE_SHARED_SIZE:
1807 case GL_TEXTURE_COMPRESSED:
1808 *params = 0;
1809 break;
1810 case GL_TEXTURE_INTERNAL_FORMAT:
1811 *params = internalFormat;
1812 break;
1813 case GL_TEXTURE_RED_SIZE:
1814 case GL_TEXTURE_GREEN_SIZE:
1815 case GL_TEXTURE_BLUE_SIZE:
1816 case GL_TEXTURE_ALPHA_SIZE:
1817 if (_mesa_base_format_has_channel(baseFormat, pname))
1818 *params = _mesa_get_format_bits(texFormat, pname);
1819 else
1820 *params = 0;
1821 break;
1822 case GL_TEXTURE_INTENSITY_SIZE:
1823 case GL_TEXTURE_LUMINANCE_SIZE:
1824 if (_mesa_base_format_has_channel(baseFormat, pname)) {
1825 *params = _mesa_get_format_bits(texFormat, pname);
1826 if (*params == 0) {
1827 /* intensity or luminance is probably stored as RGB[A] */
1828 *params = MIN2(_mesa_get_format_bits(texFormat,
1829 GL_TEXTURE_RED_SIZE),
1830 _mesa_get_format_bits(texFormat,
1831 GL_TEXTURE_GREEN_SIZE));
1832 }
1833 } else {
1834 *params = 0;
1835 }
1836 break;
1837 case GL_TEXTURE_DEPTH_SIZE_ARB:
1838 case GL_TEXTURE_STENCIL_SIZE_EXT:
1839 *params = _mesa_get_format_bits(texFormat, pname);
1840 break;
1841
1842 /* GL_ARB_texture_buffer_range */
1843 case GL_TEXTURE_BUFFER_OFFSET:
1844 if (!ctx->Extensions.ARB_texture_buffer_range)
1845 goto invalid_pname;
1846 *params = texObj->BufferOffset;
1847 break;
1848 case GL_TEXTURE_BUFFER_SIZE:
1849 if (!ctx->Extensions.ARB_texture_buffer_range)
1850 goto invalid_pname;
1851 *params = (texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize;
1852 break;
1853
1854 /* GL_ARB_texture_multisample */
1855 case GL_TEXTURE_SAMPLES:
1856 if (!ctx->Extensions.ARB_texture_multisample)
1857 goto invalid_pname;
1858 *params = 0;
1859 break;
1860
1861 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1862 if (!ctx->Extensions.ARB_texture_multisample)
1863 goto invalid_pname;
1864 *params = GL_TRUE;
1865 break;
1866
1867 /* GL_ARB_texture_compression */
1868 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1869 /* Always illegal for GL_TEXTURE_BUFFER */
1870 _mesa_error(ctx, GL_INVALID_OPERATION,
1871 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1872 _mesa_enum_to_string(pname));
1873 break;
1874
1875 /* GL_ARB_texture_float */
1876 case GL_TEXTURE_RED_TYPE_ARB:
1877 case GL_TEXTURE_GREEN_TYPE_ARB:
1878 case GL_TEXTURE_BLUE_TYPE_ARB:
1879 case GL_TEXTURE_ALPHA_TYPE_ARB:
1880 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1881 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1882 case GL_TEXTURE_DEPTH_TYPE_ARB:
1883 if (!ctx->Extensions.ARB_texture_float)
1884 goto invalid_pname;
1885 if (_mesa_base_format_has_channel(baseFormat, pname))
1886 *params = _mesa_get_format_datatype(texFormat);
1887 else
1888 *params = GL_NONE;
1889 break;
1890
1891 default:
1892 goto invalid_pname;
1893 }
1894
1895 /* no error if we get here */
1896 return;
1897
1898 invalid_pname:
1899 _mesa_error(ctx, GL_INVALID_ENUM,
1900 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1901 _mesa_enum_to_string(pname));
1902 }
1903
1904 static bool
1905 valid_tex_level_parameteriv_target(struct gl_context *ctx, GLenum target,
1906 bool dsa)
1907 {
1908 const char *suffix = dsa ? "ture" : "";
1909 if (!_mesa_legal_get_tex_level_parameter_target(ctx, target, dsa)) {
1910 _mesa_error(ctx, GL_INVALID_ENUM,
1911 "glGetTex%sLevelParameter[if]v(target=%s)", suffix,
1912 _mesa_enum_to_string(target));
1913 return false;
1914 }
1915 return true;
1916 }
1917
1918 /**
1919 * This isn't exposed to the rest of the driver because it is a part of the
1920 * OpenGL API that is rarely used.
1921 */
1922 static void
1923 get_tex_level_parameteriv(struct gl_context *ctx,
1924 struct gl_texture_object *texObj,
1925 GLenum target, GLint level,
1926 GLenum pname, GLint *params,
1927 bool dsa)
1928 {
1929 GLint maxLevels;
1930 const char *suffix = dsa ? "ture" : "";
1931
1932 /* Check for errors */
1933 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
1934 _mesa_error(ctx, GL_INVALID_OPERATION,
1935 "glGetTex%sLevelParameter[if]v("
1936 "current unit >= max combined texture units)", suffix);
1937 return;
1938 }
1939
1940 maxLevels = _mesa_max_texture_levels(ctx, target);
1941 assert(maxLevels != 0);
1942
1943 if (level < 0 || level >= maxLevels) {
1944 _mesa_error(ctx, GL_INVALID_VALUE,
1945 "glGetTex%sLevelParameter[if]v(level out of range)", suffix);
1946 return;
1947 }
1948
1949 /* Get the level parameter */
1950 if (target == GL_TEXTURE_BUFFER) {
1951 get_tex_level_parameter_buffer(ctx, texObj, pname, params, dsa);
1952 }
1953 else {
1954 get_tex_level_parameter_image(ctx, texObj, target,
1955 level, pname, params, dsa);
1956 }
1957 }
1958
1959 void GLAPIENTRY
1960 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
1961 GLenum pname, GLfloat *params )
1962 {
1963 struct gl_texture_object *texObj;
1964 GLint iparam;
1965 GET_CURRENT_CONTEXT(ctx);
1966
1967 if (!valid_tex_level_parameteriv_target(ctx, target, false))
1968 return;
1969
1970 texObj = _mesa_get_current_tex_object(ctx, target);
1971 if (!texObj)
1972 return;
1973
1974 get_tex_level_parameteriv(ctx, texObj, target, level,
1975 pname, &iparam, false);
1976
1977 *params = (GLfloat) iparam;
1978 }
1979
1980 void GLAPIENTRY
1981 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
1982 GLenum pname, GLint *params )
1983 {
1984 struct gl_texture_object *texObj;
1985 GET_CURRENT_CONTEXT(ctx);
1986
1987 if (!valid_tex_level_parameteriv_target(ctx, target, false))
1988 return;
1989
1990 texObj = _mesa_get_current_tex_object(ctx, target);
1991 if (!texObj)
1992 return;
1993
1994 get_tex_level_parameteriv(ctx, texObj, target, level,
1995 pname, params, false);
1996 }
1997
1998 void GLAPIENTRY
1999 _mesa_GetTextureLevelParameterfv(GLuint texture, GLint level,
2000 GLenum pname, GLfloat *params)
2001 {
2002 struct gl_texture_object *texObj;
2003 GLint iparam;
2004 GET_CURRENT_CONTEXT(ctx);
2005
2006 texObj = _mesa_lookup_texture_err(ctx, texture,
2007 "glGetTextureLevelParameterfv");
2008 if (!texObj)
2009 return;
2010
2011 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2012 return;
2013
2014 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2015 pname, &iparam, true);
2016
2017 *params = (GLfloat) iparam;
2018 }
2019
2020 void GLAPIENTRY
2021 _mesa_GetTextureLevelParameterfvEXT(GLuint texture, GLenum target, GLint level,
2022 GLenum pname, GLfloat *params)
2023 {
2024 struct gl_texture_object *texObj;
2025 GLint iparam;
2026 GET_CURRENT_CONTEXT(ctx);
2027
2028 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2029 "glGetTextureLevelParameterfvEXT");
2030 if (!texObj)
2031 return;
2032
2033 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2034 return;
2035
2036 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2037 pname, &iparam, true);
2038
2039 *params = (GLfloat) iparam;
2040 }
2041
2042 void GLAPIENTRY
2043 _mesa_GetMultiTexLevelParameterfvEXT(GLenum texunit, GLenum target, GLint level,
2044 GLenum pname, GLfloat *params)
2045 {
2046 struct gl_texture_object *texObj;
2047 GLint iparam;
2048 GET_CURRENT_CONTEXT(ctx);
2049
2050 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2051 texunit - GL_TEXTURE0,
2052 true,
2053 "glGetMultiTexLevelParameterfvEXT");
2054 if (!texObj)
2055 return;
2056
2057 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2058 return;
2059
2060 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2061 pname, &iparam, true);
2062
2063 *params = (GLfloat) iparam;
2064 }
2065
2066 void GLAPIENTRY
2067 _mesa_GetTextureLevelParameteriv(GLuint texture, GLint level,
2068 GLenum pname, GLint *params)
2069 {
2070 struct gl_texture_object *texObj;
2071 GET_CURRENT_CONTEXT(ctx);
2072
2073 texObj = _mesa_lookup_texture_err(ctx, texture,
2074 "glGetTextureLevelParameteriv");
2075 if (!texObj)
2076 return;
2077
2078 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2079 return;
2080
2081 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2082 pname, params, true);
2083 }
2084
2085 void GLAPIENTRY
2086 _mesa_GetTextureLevelParameterivEXT(GLuint texture, GLenum target, GLint level,
2087 GLenum pname, GLint *params)
2088 {
2089 struct gl_texture_object *texObj;
2090 GET_CURRENT_CONTEXT(ctx);
2091
2092 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2093 "glGetTextureLevelParameterivEXT");
2094 if (!texObj)
2095 return;
2096
2097 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2098 return;
2099
2100 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2101 pname, params, true);
2102 }
2103
2104 void GLAPIENTRY
2105 _mesa_GetMultiTexLevelParameterivEXT(GLenum texunit, GLenum target, GLint level,
2106 GLenum pname, GLint *params)
2107 {
2108 struct gl_texture_object *texObj;
2109 GET_CURRENT_CONTEXT(ctx);
2110
2111 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2112 texunit - GL_TEXTURE0,
2113 true,
2114 "glGetMultiTexLevelParameterivEXT");
2115 if (!texObj)
2116 return;
2117
2118 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2119 return;
2120
2121 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2122 pname, params, true);
2123 }
2124
2125
2126 /**
2127 * This isn't exposed to the rest of the driver because it is a part of the
2128 * OpenGL API that is rarely used.
2129 */
2130 static void
2131 get_tex_parameterfv(struct gl_context *ctx,
2132 struct gl_texture_object *obj,
2133 GLenum pname, GLfloat *params, bool dsa)
2134 {
2135 _mesa_lock_context_textures(ctx);
2136 switch (pname) {
2137 case GL_TEXTURE_MAG_FILTER:
2138 *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
2139 break;
2140 case GL_TEXTURE_MIN_FILTER:
2141 *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
2142 break;
2143 case GL_TEXTURE_WRAP_S:
2144 *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
2145 break;
2146 case GL_TEXTURE_WRAP_T:
2147 *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
2148 break;
2149 case GL_TEXTURE_WRAP_R:
2150 *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
2151 break;
2152 case GL_TEXTURE_BORDER_COLOR:
2153 if (ctx->API == API_OPENGLES ||
2154 !ctx->Extensions.ARB_texture_border_clamp)
2155 goto invalid_pname;
2156
2157 if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
2158 _mesa_update_state_locked(ctx);
2159 if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer)) {
2160 params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
2161 params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
2162 params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
2163 params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
2164 }
2165 else {
2166 params[0] = obj->Sampler.BorderColor.f[0];
2167 params[1] = obj->Sampler.BorderColor.f[1];
2168 params[2] = obj->Sampler.BorderColor.f[2];
2169 params[3] = obj->Sampler.BorderColor.f[3];
2170 }
2171 break;
2172 case GL_TEXTURE_RESIDENT:
2173 if (ctx->API != API_OPENGL_COMPAT)
2174 goto invalid_pname;
2175
2176 *params = 1.0F;
2177 break;
2178 case GL_TEXTURE_PRIORITY:
2179 if (ctx->API != API_OPENGL_COMPAT)
2180 goto invalid_pname;
2181
2182 *params = obj->Priority;
2183 break;
2184 case GL_TEXTURE_MIN_LOD:
2185 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2186 goto invalid_pname;
2187
2188 *params = obj->Sampler.MinLod;
2189 break;
2190 case GL_TEXTURE_MAX_LOD:
2191 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2192 goto invalid_pname;
2193
2194 *params = obj->Sampler.MaxLod;
2195 break;
2196 case GL_TEXTURE_BASE_LEVEL:
2197 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2198 goto invalid_pname;
2199
2200 *params = (GLfloat) obj->BaseLevel;
2201 break;
2202 case GL_TEXTURE_MAX_LEVEL:
2203 *params = (GLfloat) obj->MaxLevel;
2204 break;
2205 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2206 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
2207 goto invalid_pname;
2208 *params = obj->Sampler.MaxAnisotropy;
2209 break;
2210 case GL_GENERATE_MIPMAP_SGIS:
2211 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
2212 goto invalid_pname;
2213
2214 *params = (GLfloat) obj->GenerateMipmap;
2215 break;
2216 case GL_TEXTURE_COMPARE_MODE_ARB:
2217 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2218 && !_mesa_is_gles3(ctx))
2219 goto invalid_pname;
2220 *params = (GLfloat) obj->Sampler.CompareMode;
2221 break;
2222 case GL_TEXTURE_COMPARE_FUNC_ARB:
2223 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2224 && !_mesa_is_gles3(ctx))
2225 goto invalid_pname;
2226 *params = (GLfloat) obj->Sampler.CompareFunc;
2227 break;
2228 case GL_DEPTH_TEXTURE_MODE_ARB:
2229 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
2230 * never existed in OpenGL ES.
2231 */
2232 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
2233 goto invalid_pname;
2234 *params = (GLfloat) obj->DepthMode;
2235 break;
2236 case GL_DEPTH_STENCIL_TEXTURE_MODE:
2237 if (!_mesa_has_ARB_stencil_texturing(ctx) && !_mesa_is_gles31(ctx))
2238 goto invalid_pname;
2239 *params = (GLfloat)
2240 (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
2241 break;
2242 case GL_TEXTURE_LOD_BIAS:
2243 if (_mesa_is_gles(ctx))
2244 goto invalid_pname;
2245
2246 *params = obj->Sampler.LodBias;
2247 break;
2248 case GL_TEXTURE_CROP_RECT_OES:
2249 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
2250 goto invalid_pname;
2251
2252 params[0] = (GLfloat) obj->CropRect[0];
2253 params[1] = (GLfloat) obj->CropRect[1];
2254 params[2] = (GLfloat) obj->CropRect[2];
2255 params[3] = (GLfloat) obj->CropRect[3];
2256 break;
2257
2258 case GL_TEXTURE_SWIZZLE_R_EXT:
2259 case GL_TEXTURE_SWIZZLE_G_EXT:
2260 case GL_TEXTURE_SWIZZLE_B_EXT:
2261 case GL_TEXTURE_SWIZZLE_A_EXT:
2262 if ((!_mesa_is_desktop_gl(ctx)
2263 || !ctx->Extensions.EXT_texture_swizzle)
2264 && !_mesa_is_gles3(ctx))
2265 goto invalid_pname;
2266 *params = (GLfloat) obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
2267 break;
2268
2269 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
2270 if ((!_mesa_is_desktop_gl(ctx)
2271 || !ctx->Extensions.EXT_texture_swizzle)
2272 && !_mesa_is_gles3(ctx)) {
2273 goto invalid_pname;
2274 }
2275 else {
2276 GLuint comp;
2277 for (comp = 0; comp < 4; comp++) {
2278 params[comp] = (GLfloat) obj->Swizzle[comp];
2279 }
2280 }
2281 break;
2282
2283 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
2284 if (!_mesa_is_desktop_gl(ctx)
2285 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
2286 goto invalid_pname;
2287 *params = (GLfloat) obj->Sampler.CubeMapSeamless;
2288 break;
2289
2290 case GL_TEXTURE_IMMUTABLE_FORMAT:
2291 *params = (GLfloat) obj->Immutable;
2292 break;
2293
2294 case GL_TEXTURE_IMMUTABLE_LEVELS:
2295 if (_mesa_is_gles3(ctx) || _mesa_has_texture_view(ctx))
2296 *params = (GLfloat) obj->ImmutableLevels;
2297 else
2298 goto invalid_pname;
2299 break;
2300
2301 case GL_TEXTURE_VIEW_MIN_LEVEL:
2302 if (!_mesa_has_texture_view(ctx))
2303 goto invalid_pname;
2304 *params = (GLfloat) obj->MinLevel;
2305 break;
2306
2307 case GL_TEXTURE_VIEW_NUM_LEVELS:
2308 if (!_mesa_has_texture_view(ctx))
2309 goto invalid_pname;
2310 *params = (GLfloat) obj->NumLevels;
2311 break;
2312
2313 case GL_TEXTURE_VIEW_MIN_LAYER:
2314 if (!_mesa_has_texture_view(ctx))
2315 goto invalid_pname;
2316 *params = (GLfloat) obj->MinLayer;
2317 break;
2318
2319 case GL_TEXTURE_VIEW_NUM_LAYERS:
2320 if (!_mesa_has_texture_view(ctx))
2321 goto invalid_pname;
2322 *params = (GLfloat) obj->NumLayers;
2323 break;
2324
2325 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
2326 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
2327 goto invalid_pname;
2328 *params = (GLfloat) obj->RequiredTextureImageUnits;
2329 break;
2330
2331 case GL_TEXTURE_SRGB_DECODE_EXT:
2332 if (!ctx->Extensions.EXT_texture_sRGB_decode)
2333 goto invalid_pname;
2334 *params = (GLfloat) obj->Sampler.sRGBDecode;
2335 break;
2336
2337 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
2338 if (!ctx->Extensions.ARB_shader_image_load_store)
2339 goto invalid_pname;
2340 *params = (GLfloat) obj->ImageFormatCompatibilityType;
2341 break;
2342
2343 case GL_TEXTURE_TARGET:
2344 if (ctx->API != API_OPENGL_CORE)
2345 goto invalid_pname;
2346 *params = ENUM_TO_FLOAT(obj->Target);
2347 break;
2348
2349 case GL_TEXTURE_TILING_EXT:
2350 if (!ctx->Extensions.EXT_memory_object)
2351 goto invalid_pname;
2352 *params = ENUM_TO_FLOAT(obj->TextureTiling);
2353 break;
2354
2355 default:
2356 goto invalid_pname;
2357 }
2358
2359 /* no error if we get here */
2360 _mesa_unlock_context_textures(ctx);
2361 return;
2362
2363 invalid_pname:
2364 _mesa_unlock_context_textures(ctx);
2365 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameterfv(pname=0x%x)",
2366 dsa ? "ture" : "", pname);
2367 }
2368
2369
2370 static void
2371 get_tex_parameteriv(struct gl_context *ctx,
2372 struct gl_texture_object *obj,
2373 GLenum pname, GLint *params, bool dsa)
2374 {
2375 _mesa_lock_texture(ctx, obj);
2376 switch (pname) {
2377 case GL_TEXTURE_MAG_FILTER:
2378 *params = (GLint) obj->Sampler.MagFilter;
2379 break;
2380 case GL_TEXTURE_MIN_FILTER:
2381 *params = (GLint) obj->Sampler.MinFilter;
2382 break;
2383 case GL_TEXTURE_WRAP_S:
2384 *params = (GLint) obj->Sampler.WrapS;
2385 break;
2386 case GL_TEXTURE_WRAP_T:
2387 *params = (GLint) obj->Sampler.WrapT;
2388 break;
2389 case GL_TEXTURE_WRAP_R:
2390 *params = (GLint) obj->Sampler.WrapR;
2391 break;
2392 case GL_TEXTURE_BORDER_COLOR:
2393 if (ctx->API == API_OPENGLES ||
2394 !ctx->Extensions.ARB_texture_border_clamp)
2395 goto invalid_pname;
2396
2397 {
2398 GLfloat b[4];
2399 b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
2400 b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
2401 b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
2402 b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
2403 params[0] = FLOAT_TO_INT(b[0]);
2404 params[1] = FLOAT_TO_INT(b[1]);
2405 params[2] = FLOAT_TO_INT(b[2]);
2406 params[3] = FLOAT_TO_INT(b[3]);
2407 }
2408 break;
2409 case GL_TEXTURE_RESIDENT:
2410 if (ctx->API != API_OPENGL_COMPAT)
2411 goto invalid_pname;
2412
2413 *params = 1;
2414 break;
2415 case GL_TEXTURE_PRIORITY:
2416 if (ctx->API != API_OPENGL_COMPAT)
2417 goto invalid_pname;
2418
2419 *params = FLOAT_TO_INT(obj->Priority);
2420 break;
2421 case GL_TEXTURE_MIN_LOD:
2422 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2423 goto invalid_pname;
2424 /* GL spec 'Data Conversions' section specifies that floating-point
2425 * value in integer Get function is rounded to nearest integer
2426 */
2427 *params = IROUND(obj->Sampler.MinLod);
2428 break;
2429 case GL_TEXTURE_MAX_LOD:
2430 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2431 goto invalid_pname;
2432 /* GL spec 'Data Conversions' section specifies that floating-point
2433 * value in integer Get function is rounded to nearest integer
2434 */
2435 *params = IROUND(obj->Sampler.MaxLod);
2436 break;
2437 case GL_TEXTURE_BASE_LEVEL:
2438 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2439 goto invalid_pname;
2440
2441 *params = obj->BaseLevel;
2442 break;
2443 case GL_TEXTURE_MAX_LEVEL:
2444 *params = obj->MaxLevel;
2445 break;
2446 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2447 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
2448 goto invalid_pname;
2449 /* GL spec 'Data Conversions' section specifies that floating-point
2450 * value in integer Get function is rounded to nearest integer
2451 */
2452 *params = IROUND(obj->Sampler.MaxAnisotropy);
2453 break;
2454 case GL_GENERATE_MIPMAP_SGIS:
2455 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
2456 goto invalid_pname;
2457
2458 *params = (GLint) obj->GenerateMipmap;
2459 break;
2460 case GL_TEXTURE_COMPARE_MODE_ARB:
2461 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2462 && !_mesa_is_gles3(ctx))
2463 goto invalid_pname;
2464 *params = (GLint) obj->Sampler.CompareMode;
2465 break;
2466 case GL_TEXTURE_COMPARE_FUNC_ARB:
2467 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2468 && !_mesa_is_gles3(ctx))
2469 goto invalid_pname;
2470 *params = (GLint) obj->Sampler.CompareFunc;
2471 break;
2472 case GL_DEPTH_TEXTURE_MODE_ARB:
2473 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
2474 goto invalid_pname;
2475 *params = (GLint) obj->DepthMode;
2476 break;
2477 case GL_DEPTH_STENCIL_TEXTURE_MODE:
2478 if (!_mesa_has_ARB_stencil_texturing(ctx) && !_mesa_is_gles31(ctx))
2479 goto invalid_pname;
2480 *params = (GLint)
2481 (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
2482 break;
2483 case GL_TEXTURE_LOD_BIAS:
2484 if (_mesa_is_gles(ctx))
2485 goto invalid_pname;
2486
2487 /* GL spec 'Data Conversions' section specifies that floating-point
2488 * value in integer Get function is rounded to nearest integer
2489 */
2490 *params = IROUND(obj->Sampler.LodBias);
2491 break;
2492 case GL_TEXTURE_CROP_RECT_OES:
2493 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
2494 goto invalid_pname;
2495
2496 params[0] = obj->CropRect[0];
2497 params[1] = obj->CropRect[1];
2498 params[2] = obj->CropRect[2];
2499 params[3] = obj->CropRect[3];
2500 break;
2501 case GL_TEXTURE_SWIZZLE_R_EXT:
2502 case GL_TEXTURE_SWIZZLE_G_EXT:
2503 case GL_TEXTURE_SWIZZLE_B_EXT:
2504 case GL_TEXTURE_SWIZZLE_A_EXT:
2505 if ((!_mesa_is_desktop_gl(ctx)
2506 || !ctx->Extensions.EXT_texture_swizzle)
2507 && !_mesa_is_gles3(ctx))
2508 goto invalid_pname;
2509 *params = obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
2510 break;
2511
2512 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
2513 if ((!_mesa_is_desktop_gl(ctx)
2514 || !ctx->Extensions.EXT_texture_swizzle)
2515 && !_mesa_is_gles3(ctx))
2516 goto invalid_pname;
2517 COPY_4V(params, obj->Swizzle);
2518 break;
2519
2520 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
2521 if (!_mesa_is_desktop_gl(ctx)
2522 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
2523 goto invalid_pname;
2524 *params = (GLint) obj->Sampler.CubeMapSeamless;
2525 break;
2526
2527 case GL_TEXTURE_IMMUTABLE_FORMAT:
2528 *params = (GLint) obj->Immutable;
2529 break;
2530
2531 case GL_TEXTURE_IMMUTABLE_LEVELS:
2532 if (_mesa_is_gles3(ctx) ||
2533 (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_view))
2534 *params = obj->ImmutableLevels;
2535 else
2536 goto invalid_pname;
2537 break;
2538
2539 case GL_TEXTURE_VIEW_MIN_LEVEL:
2540 if (!ctx->Extensions.ARB_texture_view)
2541 goto invalid_pname;
2542 *params = (GLint) obj->MinLevel;
2543 break;
2544
2545 case GL_TEXTURE_VIEW_NUM_LEVELS:
2546 if (!ctx->Extensions.ARB_texture_view)
2547 goto invalid_pname;
2548 *params = (GLint) obj->NumLevels;
2549 break;
2550
2551 case GL_TEXTURE_VIEW_MIN_LAYER:
2552 if (!ctx->Extensions.ARB_texture_view)
2553 goto invalid_pname;
2554 *params = (GLint) obj->MinLayer;
2555 break;
2556
2557 case GL_TEXTURE_VIEW_NUM_LAYERS:
2558 if (!ctx->Extensions.ARB_texture_view)
2559 goto invalid_pname;
2560 *params = (GLint) obj->NumLayers;
2561 break;
2562
2563 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
2564 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
2565 goto invalid_pname;
2566 *params = obj->RequiredTextureImageUnits;
2567 break;
2568
2569 case GL_TEXTURE_SRGB_DECODE_EXT:
2570 if (!ctx->Extensions.EXT_texture_sRGB_decode)
2571 goto invalid_pname;
2572 *params = obj->Sampler.sRGBDecode;
2573 break;
2574
2575 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
2576 if (!ctx->Extensions.ARB_shader_image_load_store)
2577 goto invalid_pname;
2578 *params = obj->ImageFormatCompatibilityType;
2579 break;
2580
2581 case GL_TEXTURE_TARGET:
2582 if (ctx->API != API_OPENGL_CORE)
2583 goto invalid_pname;
2584 *params = (GLint) obj->Target;
2585 break;
2586
2587 case GL_TEXTURE_TILING_EXT:
2588 if (!ctx->Extensions.EXT_memory_object)
2589 goto invalid_pname;
2590 *params = (GLint) obj->TextureTiling;
2591 break;
2592
2593 default:
2594 goto invalid_pname;
2595 }
2596
2597 /* no error if we get here */
2598 _mesa_unlock_texture(ctx, obj);
2599 return;
2600
2601 invalid_pname:
2602 _mesa_unlock_texture(ctx, obj);
2603 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameteriv(pname=0x%x)",
2604 dsa ? "ture" : "", pname);
2605 }
2606
2607 static void
2608 get_tex_parameterIiv(struct gl_context *ctx,
2609 struct gl_texture_object *obj,
2610 GLenum pname, GLint *params, bool dsa)
2611 {
2612 switch (pname) {
2613 case GL_TEXTURE_BORDER_COLOR:
2614 COPY_4V(params, obj->Sampler.BorderColor.i);
2615 break;
2616 default:
2617 get_tex_parameteriv(ctx, obj, pname, params, dsa);
2618 }
2619 }
2620
2621 void GLAPIENTRY
2622 _mesa_GetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
2623 {
2624 struct gl_texture_object *obj;
2625 GET_CURRENT_CONTEXT(ctx);
2626
2627 obj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2628 ctx->Texture.CurrentUnit,
2629 false,
2630 "glGetTexParameterfv");
2631 if (!obj)
2632 return;
2633
2634 get_tex_parameterfv(ctx, obj, pname, params, false);
2635 }
2636
2637 void GLAPIENTRY
2638 _mesa_GetTexParameteriv(GLenum target, GLenum pname, GLint *params)
2639 {
2640 struct gl_texture_object *obj;
2641 GET_CURRENT_CONTEXT(ctx);
2642
2643 obj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2644 ctx->Texture.CurrentUnit,
2645 false,
2646 "glGetTexParameteriv");
2647 if (!obj)
2648 return;
2649
2650 get_tex_parameteriv(ctx, obj, pname, params, false);
2651 }
2652
2653 /** New in GL 3.0 */
2654 void GLAPIENTRY
2655 _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
2656 {
2657 struct gl_texture_object *texObj;
2658 GET_CURRENT_CONTEXT(ctx);
2659
2660 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2661 ctx->Texture.CurrentUnit,
2662 false,
2663 "glGetTexParameterIiv");
2664 if (!texObj)
2665 return;
2666
2667 get_tex_parameterIiv(ctx, texObj, pname, params, false);
2668 }
2669
2670
2671 /** New in GL 3.0 */
2672 void GLAPIENTRY
2673 _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
2674 {
2675 struct gl_texture_object *texObj;
2676 GET_CURRENT_CONTEXT(ctx);
2677
2678 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2679 ctx->Texture.CurrentUnit,
2680 false,
2681 "glGetTexParameterIuiv");
2682 if (!texObj)
2683 return;
2684
2685 get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, false);
2686 }
2687
2688 void GLAPIENTRY
2689 _mesa_GetTextureParameterfvEXT(GLuint texture, GLenum target, GLenum pname, GLfloat *params)
2690 {
2691 struct gl_texture_object *texObj;
2692 GET_CURRENT_CONTEXT(ctx);
2693
2694 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2695 "glGetTextureParameterfvEXT");
2696 if (!texObj)
2697 return;
2698
2699 if (!is_texparameteri_target_valid(texObj->Target)) {
2700 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTextureParameterfvEXT");
2701 return;
2702 }
2703
2704 get_tex_parameterfv(ctx, texObj, pname, params, true);
2705 }
2706
2707 void GLAPIENTRY
2708 _mesa_GetMultiTexParameterfvEXT(GLenum texunit, GLenum target, GLenum pname, GLfloat *params)
2709 {
2710 struct gl_texture_object *texObj;
2711 GET_CURRENT_CONTEXT(ctx);
2712
2713 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2714 texunit - GL_TEXTURE0,
2715 false,
2716 "glGetMultiTexParameterfvEXT");
2717 if (!texObj)
2718 return;
2719
2720 if (!is_texparameteri_target_valid(texObj->Target)) {
2721 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetMultiTexParameterfvEXT");
2722 return;
2723 }
2724 get_tex_parameterfv(ctx, texObj, pname, params, true);
2725 }
2726
2727 void GLAPIENTRY
2728 _mesa_GetTextureParameterfv(GLuint texture, GLenum pname, GLfloat *params)
2729 {
2730 struct gl_texture_object *obj;
2731 GET_CURRENT_CONTEXT(ctx);
2732
2733 obj = get_texobj_by_name(ctx, texture, "glGetTextureParameterfv");
2734 if (!obj)
2735 return;
2736
2737 get_tex_parameterfv(ctx, obj, pname, params, true);
2738 }
2739
2740 void GLAPIENTRY
2741 _mesa_GetTextureParameterivEXT(GLuint texture, GLenum target, GLenum pname, GLint *params)
2742 {
2743 struct gl_texture_object *texObj;
2744 GET_CURRENT_CONTEXT(ctx);
2745
2746 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2747 "glGetTextureParameterivEXT");
2748 if (!texObj)
2749 return;
2750
2751 if (!is_texparameteri_target_valid(texObj->Target)) {
2752 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTextureParameterivEXT");
2753 return;
2754 }
2755 get_tex_parameteriv(ctx, texObj, pname, params, true);
2756 }
2757
2758 void GLAPIENTRY
2759 _mesa_GetMultiTexParameterivEXT(GLenum texunit, GLenum target, GLenum pname, GLint *params)
2760 {
2761 struct gl_texture_object *texObj;
2762 GET_CURRENT_CONTEXT(ctx);
2763
2764 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2765 texunit - GL_TEXTURE0,
2766 false,
2767 "glGetMultiTexParameterivEXT");
2768 if (!texObj)
2769 return;
2770
2771 if (!is_texparameteri_target_valid(texObj->Target)) {
2772 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetMultiTexParameterivEXT");
2773 return;
2774 }
2775 get_tex_parameteriv(ctx, texObj, pname, params, true);
2776 }
2777
2778 void GLAPIENTRY
2779 _mesa_GetTextureParameteriv(GLuint texture, GLenum pname, GLint *params)
2780 {
2781 struct gl_texture_object *obj;
2782 GET_CURRENT_CONTEXT(ctx);
2783
2784 obj = get_texobj_by_name(ctx, texture, "glGetTextureParameteriv");
2785 if (!obj)
2786 return;
2787
2788 get_tex_parameteriv(ctx, obj, pname, params, true);
2789 }
2790
2791 void GLAPIENTRY
2792 _mesa_GetTextureParameterIiv(GLuint texture, GLenum pname, GLint *params)
2793 {
2794 struct gl_texture_object *texObj;
2795 GET_CURRENT_CONTEXT(ctx);
2796
2797 texObj = get_texobj_by_name(ctx, texture, "glGetTextureParameterIiv");
2798 if (!texObj)
2799 return;
2800
2801 get_tex_parameterIiv(ctx, texObj, pname, params, true);
2802 }
2803
2804 void GLAPIENTRY
2805 _mesa_GetTextureParameterIivEXT(GLuint texture, GLenum target, GLenum pname, GLint *params)
2806 {
2807 struct gl_texture_object *texObj;
2808 GET_CURRENT_CONTEXT(ctx);
2809
2810 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2811 "glGetTextureParameterIivEXT");
2812 if (!texObj)
2813 return;
2814
2815
2816 get_tex_parameterIiv(ctx, texObj, pname, params, true);
2817 }
2818
2819 void GLAPIENTRY
2820 _mesa_GetMultiTexParameterIivEXT(GLenum texunit, GLenum target, GLenum pname,
2821 GLint *params)
2822 {
2823 struct gl_texture_object *texObj;
2824 GET_CURRENT_CONTEXT(ctx);
2825
2826 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2827 texunit - GL_TEXTURE0,
2828 true,
2829 "glGetMultiTexParameterIiv");
2830 if (!texObj)
2831 return;
2832
2833 get_tex_parameterIiv(ctx, texObj, pname, params, true);
2834 }
2835
2836 void GLAPIENTRY
2837 _mesa_GetTextureParameterIuiv(GLuint texture, GLenum pname, GLuint *params)
2838 {
2839 struct gl_texture_object *texObj;
2840 GET_CURRENT_CONTEXT(ctx);
2841
2842 texObj = get_texobj_by_name(ctx, texture, "glGetTextureParameterIuiv");
2843 if (!texObj)
2844 return;
2845
2846 get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, true);
2847 }
2848
2849 void GLAPIENTRY
2850 _mesa_GetTextureParameterIuivEXT(GLuint texture, GLenum target, GLenum pname,
2851 GLuint *params)
2852 {
2853 struct gl_texture_object *texObj;
2854 GET_CURRENT_CONTEXT(ctx);
2855
2856 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2857 "glGetTextureParameterIuvEXT");
2858 if (!texObj)
2859 return;
2860
2861 get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, true);
2862 }
2863
2864 void GLAPIENTRY
2865 _mesa_GetMultiTexParameterIuivEXT(GLenum texunit, GLenum target, GLenum pname,
2866 GLuint *params)
2867 {
2868 struct gl_texture_object *texObj;
2869 GET_CURRENT_CONTEXT(ctx);
2870
2871 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2872 texunit - GL_TEXTURE0,
2873 true,
2874 "glGetMultiTexParameterIuiv");
2875 if (!texObj)
2876 return;
2877
2878 get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, true);
2879 }