glapi / teximage: implement EGLImageTargetTexStorageEXT
[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_TextureParameterIivEXT(GLuint texture, GLenum target, GLenum pname,
1399 const GLint *params)
1400 {
1401 struct gl_texture_object *texObj;
1402 GET_CURRENT_CONTEXT(ctx);
1403
1404 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1405 "glTextureParameterIivEXT");
1406 if (!texObj)
1407 return;
1408
1409 _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
1410 }
1411
1412 void GLAPIENTRY
1413 _mesa_MultiTexParameterIivEXT(GLenum texunit, GLenum target, GLenum pname,
1414 const GLint *params)
1415 {
1416 struct gl_texture_object *texObj;
1417 GET_CURRENT_CONTEXT(ctx);
1418
1419 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1420 texunit - GL_TEXTURE0,
1421 true,
1422 "glMultiTexParameterIivEXT");
1423 if (!texObj)
1424 return;
1425
1426 _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
1427 }
1428
1429 void GLAPIENTRY
1430 _mesa_TextureParameterIuiv(GLuint texture, GLenum pname, const GLuint *params)
1431 {
1432 struct gl_texture_object *texObj;
1433 GET_CURRENT_CONTEXT(ctx);
1434
1435 texObj = get_texobj_by_name(ctx, texture, "glTextureParameterIuiv");
1436 if (!texObj)
1437 return;
1438
1439 _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
1440 }
1441
1442 void GLAPIENTRY
1443 _mesa_TextureParameterIuivEXT(GLuint texture, GLenum target, GLenum pname,
1444 const GLuint *params)
1445 {
1446 struct gl_texture_object *texObj;
1447 GET_CURRENT_CONTEXT(ctx);
1448
1449 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1450 "glTextureParameterIuivEXT");
1451 if (!texObj)
1452 return;
1453
1454 _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
1455 }
1456
1457 void GLAPIENTRY
1458 _mesa_MultiTexParameterIuivEXT(GLenum texunit, GLenum target, GLenum pname,
1459 const GLuint *params)
1460 {
1461 struct gl_texture_object *texObj;
1462 GET_CURRENT_CONTEXT(ctx);
1463
1464 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1465 texunit - GL_TEXTURE0,
1466 true,
1467 "glMultiTexParameterIuivEXT");
1468 if (!texObj)
1469 return;
1470
1471 _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
1472 }
1473
1474 GLboolean
1475 _mesa_legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target,
1476 bool dsa)
1477 {
1478 /* Common targets for desktop GL and GLES 3.1. */
1479 switch (target) {
1480 case GL_TEXTURE_2D:
1481 case GL_TEXTURE_3D:
1482 return GL_TRUE;
1483 case GL_TEXTURE_2D_ARRAY_EXT:
1484 return ctx->Extensions.EXT_texture_array;
1485 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1486 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1487 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1488 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1489 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1490 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1491 return ctx->Extensions.ARB_texture_cube_map;
1492 case GL_TEXTURE_2D_MULTISAMPLE:
1493 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
1494 return ctx->Extensions.ARB_texture_multisample;
1495 case GL_TEXTURE_BUFFER:
1496 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1497 * but not in earlier versions that expose ARB_texture_buffer_object.
1498 *
1499 * From the ARB_texture_buffer_object spec:
1500 * "(7) Do buffer textures support texture parameters (TexParameter) or
1501 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1502 *
1503 * RESOLVED: No. [...] Note that the spec edits above don't add
1504 * explicit error language for any of these cases. That is because
1505 * each of the functions enumerate the set of valid <target>
1506 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1507 * these cases means that target is not legal, and an INVALID_ENUM
1508 * error should be generated."
1509 *
1510 * From the OpenGL 3.1 spec:
1511 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1512 */
1513 return (_mesa_is_desktop_gl(ctx) && ctx->Version >= 31) ||
1514 _mesa_has_OES_texture_buffer(ctx);
1515 case GL_TEXTURE_CUBE_MAP_ARRAY:
1516 return _mesa_has_texture_cube_map_array(ctx);
1517 }
1518
1519 if (!_mesa_is_desktop_gl(ctx))
1520 return GL_FALSE;
1521
1522 /* Rest of the desktop GL targets. */
1523 switch (target) {
1524 case GL_TEXTURE_1D:
1525 case GL_PROXY_TEXTURE_1D:
1526 case GL_PROXY_TEXTURE_2D:
1527 case GL_PROXY_TEXTURE_3D:
1528 return GL_TRUE;
1529 case GL_PROXY_TEXTURE_CUBE_MAP:
1530 return ctx->Extensions.ARB_texture_cube_map;
1531 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY:
1532 return ctx->Extensions.ARB_texture_cube_map_array;
1533 case GL_TEXTURE_RECTANGLE_NV:
1534 case GL_PROXY_TEXTURE_RECTANGLE_NV:
1535 return ctx->Extensions.NV_texture_rectangle;
1536 case GL_TEXTURE_1D_ARRAY_EXT:
1537 case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
1538 case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
1539 return ctx->Extensions.EXT_texture_array;
1540 case GL_PROXY_TEXTURE_2D_MULTISAMPLE:
1541 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY:
1542 return ctx->Extensions.ARB_texture_multisample;
1543
1544 /* This is a valid target for dsa, but the OpenGL 4.5 core spec
1545 * (30.10.2014) Section 8.11 Texture Queries says:
1546 * "For GetTextureLevelParameter* only, texture may also be a cube
1547 * map texture object. In this case the query is always performed
1548 * for face zero (the TEXTURE_CUBE_MAP_POSITIVE_X face), since there
1549 * is no way to specify another face."
1550 */
1551 case GL_TEXTURE_CUBE_MAP:
1552 return dsa;
1553 default:
1554 return GL_FALSE;
1555 }
1556 }
1557
1558
1559 static void
1560 get_tex_level_parameter_image(struct gl_context *ctx,
1561 const struct gl_texture_object *texObj,
1562 GLenum target, GLint level,
1563 GLenum pname, GLint *params,
1564 bool dsa)
1565 {
1566 const struct gl_texture_image *img = NULL;
1567 struct gl_texture_image dummy_image;
1568 mesa_format texFormat;
1569 const char *suffix = dsa ? "ture" : "";
1570
1571 img = _mesa_select_tex_image(texObj, target, level);
1572 if (!img || img->TexFormat == MESA_FORMAT_NONE) {
1573 /* In case of undefined texture image return the default values.
1574 *
1575 * From OpenGL 4.0 spec, page 398:
1576 * "The initial internal format of a texel array is RGBA
1577 * instead of 1. TEXTURE_COMPONENTS is deprecated; always
1578 * use TEXTURE_INTERNAL_FORMAT."
1579 */
1580 memset(&dummy_image, 0, sizeof(dummy_image));
1581 dummy_image.TexFormat = MESA_FORMAT_NONE;
1582 dummy_image.InternalFormat = GL_RGBA;
1583 dummy_image._BaseFormat = GL_NONE;
1584 dummy_image.FixedSampleLocations = GL_TRUE;
1585
1586 img = &dummy_image;
1587 }
1588
1589 texFormat = img->TexFormat;
1590
1591 switch (pname) {
1592 case GL_TEXTURE_WIDTH:
1593 *params = img->Width;
1594 break;
1595 case GL_TEXTURE_HEIGHT:
1596 *params = img->Height;
1597 break;
1598 case GL_TEXTURE_DEPTH:
1599 *params = img->Depth;
1600 break;
1601 case GL_TEXTURE_INTERNAL_FORMAT:
1602 if (_mesa_is_format_compressed(texFormat)) {
1603 /* need to return the actual compressed format */
1604 *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
1605 }
1606 else {
1607 /* If the true internal format is not compressed but the user
1608 * requested a generic compressed format, we have to return the
1609 * generic base format that matches.
1610 *
1611 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1612 *
1613 * "If no specific compressed format is available,
1614 * internalformat is instead replaced by the corresponding base
1615 * internal format."
1616 *
1617 * Otherwise just return the user's requested internal format
1618 */
1619 const GLenum f =
1620 _mesa_gl_compressed_format_base_format(img->InternalFormat);
1621
1622 *params = (f != 0) ? f : img->InternalFormat;
1623 }
1624 break;
1625 case GL_TEXTURE_BORDER:
1626 if (ctx->API != API_OPENGL_COMPAT)
1627 goto invalid_pname;
1628 *params = img->Border;
1629 break;
1630 case GL_TEXTURE_RED_SIZE:
1631 case GL_TEXTURE_GREEN_SIZE:
1632 case GL_TEXTURE_BLUE_SIZE:
1633 case GL_TEXTURE_ALPHA_SIZE:
1634 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1635 *params = _mesa_get_format_bits(texFormat, pname);
1636 else
1637 *params = 0;
1638 break;
1639 case GL_TEXTURE_INTENSITY_SIZE:
1640 case GL_TEXTURE_LUMINANCE_SIZE:
1641 if (ctx->API != API_OPENGL_COMPAT)
1642 goto invalid_pname;
1643 if (_mesa_base_format_has_channel(img->_BaseFormat, pname)) {
1644 *params = _mesa_get_format_bits(texFormat, pname);
1645 if (*params == 0) {
1646 /* intensity or luminance is probably stored as RGB[A] */
1647 *params = MIN2(_mesa_get_format_bits(texFormat,
1648 GL_TEXTURE_RED_SIZE),
1649 _mesa_get_format_bits(texFormat,
1650 GL_TEXTURE_GREEN_SIZE));
1651 }
1652 if (*params == 0 && pname == GL_TEXTURE_INTENSITY_SIZE) {
1653 /* Gallium may store intensity as LA */
1654 *params = _mesa_get_format_bits(texFormat,
1655 GL_TEXTURE_ALPHA_SIZE);
1656 }
1657 }
1658 else {
1659 *params = 0;
1660 }
1661 break;
1662 case GL_TEXTURE_DEPTH_SIZE_ARB:
1663 if (!ctx->Extensions.ARB_depth_texture)
1664 goto invalid_pname;
1665 *params = _mesa_get_format_bits(texFormat, pname);
1666 break;
1667 case GL_TEXTURE_STENCIL_SIZE:
1668 *params = _mesa_get_format_bits(texFormat, pname);
1669 break;
1670 case GL_TEXTURE_SHARED_SIZE:
1671 if (ctx->Version < 30 &&
1672 !ctx->Extensions.EXT_texture_shared_exponent)
1673 goto invalid_pname;
1674 *params = texFormat == MESA_FORMAT_R9G9B9E5_FLOAT ? 5 : 0;
1675 break;
1676
1677 /* GL_ARB_texture_compression */
1678 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1679 if (_mesa_is_format_compressed(texFormat) &&
1680 !_mesa_is_proxy_texture(target)) {
1681 *params = _mesa_format_image_size(texFormat, img->Width,
1682 img->Height, img->Depth);
1683 } else {
1684 _mesa_error(ctx, GL_INVALID_OPERATION,
1685 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1686 _mesa_enum_to_string(pname));
1687 }
1688 break;
1689 case GL_TEXTURE_COMPRESSED:
1690 *params = (GLint) _mesa_is_format_compressed(texFormat);
1691 break;
1692
1693 /* GL_ARB_texture_float */
1694 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1695 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1696 if (ctx->API != API_OPENGL_COMPAT)
1697 goto invalid_pname;
1698 /* FALLTHROUGH */
1699 case GL_TEXTURE_RED_TYPE_ARB:
1700 case GL_TEXTURE_GREEN_TYPE_ARB:
1701 case GL_TEXTURE_BLUE_TYPE_ARB:
1702 case GL_TEXTURE_ALPHA_TYPE_ARB:
1703 case GL_TEXTURE_DEPTH_TYPE_ARB:
1704 if (!ctx->Extensions.ARB_texture_float)
1705 goto invalid_pname;
1706 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1707 *params = _mesa_get_format_datatype(texFormat);
1708 else
1709 *params = GL_NONE;
1710 break;
1711
1712 /* GL_ARB_texture_multisample */
1713 case GL_TEXTURE_SAMPLES:
1714 if (!ctx->Extensions.ARB_texture_multisample)
1715 goto invalid_pname;
1716 *params = img->NumSamples;
1717 break;
1718
1719 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1720 if (!ctx->Extensions.ARB_texture_multisample)
1721 goto invalid_pname;
1722 *params = img->FixedSampleLocations;
1723 break;
1724
1725 /* There is never a buffer data store here, but these pnames still have
1726 * to work.
1727 */
1728
1729 /* GL_ARB_texture_buffer_object */
1730 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
1731 if (!ctx->Extensions.ARB_texture_buffer_object)
1732 goto invalid_pname;
1733 *params = 0;
1734 break;
1735
1736 /* GL_ARB_texture_buffer_range */
1737 case GL_TEXTURE_BUFFER_OFFSET:
1738 if (!ctx->Extensions.ARB_texture_buffer_range)
1739 goto invalid_pname;
1740 *params = 0;
1741 break;
1742 case GL_TEXTURE_BUFFER_SIZE:
1743 if (!ctx->Extensions.ARB_texture_buffer_range)
1744 goto invalid_pname;
1745 *params = 0;
1746 break;
1747
1748 default:
1749 goto invalid_pname;
1750 }
1751
1752 /* no error if we get here */
1753 return;
1754
1755 invalid_pname:
1756 _mesa_error(ctx, GL_INVALID_ENUM,
1757 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1758 _mesa_enum_to_string(pname));
1759 }
1760
1761
1762 /**
1763 * Handle a glGetTexLevelParamteriv() call for a texture buffer.
1764 */
1765 static void
1766 get_tex_level_parameter_buffer(struct gl_context *ctx,
1767 const struct gl_texture_object *texObj,
1768 GLenum pname, GLint *params, bool dsa)
1769 {
1770 const struct gl_buffer_object *bo = texObj->BufferObject;
1771 mesa_format texFormat = texObj->_BufferObjectFormat;
1772 int bytes = MAX2(1, _mesa_get_format_bytes(texFormat));
1773 GLenum internalFormat = texObj->BufferObjectFormat;
1774 GLenum baseFormat = _mesa_get_format_base_format(texFormat);
1775 const char *suffix = dsa ? "ture" : "";
1776
1777 assert(texObj->Target == GL_TEXTURE_BUFFER);
1778
1779 if (!bo) {
1780 /* undefined texture buffer object */
1781 switch (pname) {
1782 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1783 *params = GL_TRUE;
1784 break;
1785 case GL_TEXTURE_INTERNAL_FORMAT:
1786 *params = internalFormat;
1787 break;
1788 default:
1789 *params = 0;
1790 break;
1791 }
1792 return;
1793 }
1794
1795 switch (pname) {
1796 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
1797 *params = bo->Name;
1798 break;
1799 case GL_TEXTURE_WIDTH:
1800 *params = ((texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize)
1801 / bytes;
1802 break;
1803 case GL_TEXTURE_HEIGHT:
1804 case GL_TEXTURE_DEPTH:
1805 *params = 1;
1806 break;
1807 case GL_TEXTURE_BORDER:
1808 case GL_TEXTURE_SHARED_SIZE:
1809 case GL_TEXTURE_COMPRESSED:
1810 *params = 0;
1811 break;
1812 case GL_TEXTURE_INTERNAL_FORMAT:
1813 *params = internalFormat;
1814 break;
1815 case GL_TEXTURE_RED_SIZE:
1816 case GL_TEXTURE_GREEN_SIZE:
1817 case GL_TEXTURE_BLUE_SIZE:
1818 case GL_TEXTURE_ALPHA_SIZE:
1819 if (_mesa_base_format_has_channel(baseFormat, pname))
1820 *params = _mesa_get_format_bits(texFormat, pname);
1821 else
1822 *params = 0;
1823 break;
1824 case GL_TEXTURE_INTENSITY_SIZE:
1825 case GL_TEXTURE_LUMINANCE_SIZE:
1826 if (_mesa_base_format_has_channel(baseFormat, pname)) {
1827 *params = _mesa_get_format_bits(texFormat, pname);
1828 if (*params == 0) {
1829 /* intensity or luminance is probably stored as RGB[A] */
1830 *params = MIN2(_mesa_get_format_bits(texFormat,
1831 GL_TEXTURE_RED_SIZE),
1832 _mesa_get_format_bits(texFormat,
1833 GL_TEXTURE_GREEN_SIZE));
1834 }
1835 } else {
1836 *params = 0;
1837 }
1838 break;
1839 case GL_TEXTURE_DEPTH_SIZE_ARB:
1840 case GL_TEXTURE_STENCIL_SIZE_EXT:
1841 *params = _mesa_get_format_bits(texFormat, pname);
1842 break;
1843
1844 /* GL_ARB_texture_buffer_range */
1845 case GL_TEXTURE_BUFFER_OFFSET:
1846 if (!ctx->Extensions.ARB_texture_buffer_range)
1847 goto invalid_pname;
1848 *params = texObj->BufferOffset;
1849 break;
1850 case GL_TEXTURE_BUFFER_SIZE:
1851 if (!ctx->Extensions.ARB_texture_buffer_range)
1852 goto invalid_pname;
1853 *params = (texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize;
1854 break;
1855
1856 /* GL_ARB_texture_multisample */
1857 case GL_TEXTURE_SAMPLES:
1858 if (!ctx->Extensions.ARB_texture_multisample)
1859 goto invalid_pname;
1860 *params = 0;
1861 break;
1862
1863 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1864 if (!ctx->Extensions.ARB_texture_multisample)
1865 goto invalid_pname;
1866 *params = GL_TRUE;
1867 break;
1868
1869 /* GL_ARB_texture_compression */
1870 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1871 /* Always illegal for GL_TEXTURE_BUFFER */
1872 _mesa_error(ctx, GL_INVALID_OPERATION,
1873 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1874 _mesa_enum_to_string(pname));
1875 break;
1876
1877 /* GL_ARB_texture_float */
1878 case GL_TEXTURE_RED_TYPE_ARB:
1879 case GL_TEXTURE_GREEN_TYPE_ARB:
1880 case GL_TEXTURE_BLUE_TYPE_ARB:
1881 case GL_TEXTURE_ALPHA_TYPE_ARB:
1882 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1883 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1884 case GL_TEXTURE_DEPTH_TYPE_ARB:
1885 if (!ctx->Extensions.ARB_texture_float)
1886 goto invalid_pname;
1887 if (_mesa_base_format_has_channel(baseFormat, pname))
1888 *params = _mesa_get_format_datatype(texFormat);
1889 else
1890 *params = GL_NONE;
1891 break;
1892
1893 default:
1894 goto invalid_pname;
1895 }
1896
1897 /* no error if we get here */
1898 return;
1899
1900 invalid_pname:
1901 _mesa_error(ctx, GL_INVALID_ENUM,
1902 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1903 _mesa_enum_to_string(pname));
1904 }
1905
1906 static bool
1907 valid_tex_level_parameteriv_target(struct gl_context *ctx, GLenum target,
1908 bool dsa)
1909 {
1910 const char *suffix = dsa ? "ture" : "";
1911 if (!_mesa_legal_get_tex_level_parameter_target(ctx, target, dsa)) {
1912 _mesa_error(ctx, GL_INVALID_ENUM,
1913 "glGetTex%sLevelParameter[if]v(target=%s)", suffix,
1914 _mesa_enum_to_string(target));
1915 return false;
1916 }
1917 return true;
1918 }
1919
1920 /**
1921 * This isn't exposed to the rest of the driver because it is a part of the
1922 * OpenGL API that is rarely used.
1923 */
1924 static void
1925 get_tex_level_parameteriv(struct gl_context *ctx,
1926 struct gl_texture_object *texObj,
1927 GLenum target, GLint level,
1928 GLenum pname, GLint *params,
1929 bool dsa)
1930 {
1931 GLint maxLevels;
1932 const char *suffix = dsa ? "ture" : "";
1933
1934 /* Check for errors */
1935 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
1936 _mesa_error(ctx, GL_INVALID_OPERATION,
1937 "glGetTex%sLevelParameter[if]v("
1938 "current unit >= max combined texture units)", suffix);
1939 return;
1940 }
1941
1942 maxLevels = _mesa_max_texture_levels(ctx, target);
1943 assert(maxLevels != 0);
1944
1945 if (level < 0 || level >= maxLevels) {
1946 _mesa_error(ctx, GL_INVALID_VALUE,
1947 "glGetTex%sLevelParameter[if]v(level out of range)", suffix);
1948 return;
1949 }
1950
1951 /* Get the level parameter */
1952 if (target == GL_TEXTURE_BUFFER) {
1953 get_tex_level_parameter_buffer(ctx, texObj, pname, params, dsa);
1954 }
1955 else {
1956 get_tex_level_parameter_image(ctx, texObj, target,
1957 level, pname, params, dsa);
1958 }
1959 }
1960
1961 void GLAPIENTRY
1962 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
1963 GLenum pname, GLfloat *params )
1964 {
1965 struct gl_texture_object *texObj;
1966 GLint iparam;
1967 GET_CURRENT_CONTEXT(ctx);
1968
1969 if (!valid_tex_level_parameteriv_target(ctx, target, false))
1970 return;
1971
1972 texObj = _mesa_get_current_tex_object(ctx, target);
1973 if (!texObj)
1974 return;
1975
1976 get_tex_level_parameteriv(ctx, texObj, target, level,
1977 pname, &iparam, false);
1978
1979 *params = (GLfloat) iparam;
1980 }
1981
1982 void GLAPIENTRY
1983 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
1984 GLenum pname, GLint *params )
1985 {
1986 struct gl_texture_object *texObj;
1987 GET_CURRENT_CONTEXT(ctx);
1988
1989 if (!valid_tex_level_parameteriv_target(ctx, target, false))
1990 return;
1991
1992 texObj = _mesa_get_current_tex_object(ctx, target);
1993 if (!texObj)
1994 return;
1995
1996 get_tex_level_parameteriv(ctx, texObj, target, level,
1997 pname, params, false);
1998 }
1999
2000 void GLAPIENTRY
2001 _mesa_GetTextureLevelParameterfv(GLuint texture, GLint level,
2002 GLenum pname, GLfloat *params)
2003 {
2004 struct gl_texture_object *texObj;
2005 GLint iparam;
2006 GET_CURRENT_CONTEXT(ctx);
2007
2008 texObj = _mesa_lookup_texture_err(ctx, texture,
2009 "glGetTextureLevelParameterfv");
2010 if (!texObj)
2011 return;
2012
2013 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2014 return;
2015
2016 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2017 pname, &iparam, true);
2018
2019 *params = (GLfloat) iparam;
2020 }
2021
2022 void GLAPIENTRY
2023 _mesa_GetTextureLevelParameterfvEXT(GLuint texture, GLenum target, GLint level,
2024 GLenum pname, GLfloat *params)
2025 {
2026 struct gl_texture_object *texObj;
2027 GLint iparam;
2028 GET_CURRENT_CONTEXT(ctx);
2029
2030 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2031 "glGetTextureLevelParameterfvEXT");
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, &iparam, true);
2040
2041 *params = (GLfloat) iparam;
2042 }
2043
2044 void GLAPIENTRY
2045 _mesa_GetMultiTexLevelParameterfvEXT(GLenum texunit, GLenum target, GLint level,
2046 GLenum pname, GLfloat *params)
2047 {
2048 struct gl_texture_object *texObj;
2049 GLint iparam;
2050 GET_CURRENT_CONTEXT(ctx);
2051
2052 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2053 texunit - GL_TEXTURE0,
2054 true,
2055 "glGetMultiTexLevelParameterfvEXT");
2056 if (!texObj)
2057 return;
2058
2059 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2060 return;
2061
2062 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2063 pname, &iparam, true);
2064
2065 *params = (GLfloat) iparam;
2066 }
2067
2068 void GLAPIENTRY
2069 _mesa_GetTextureLevelParameteriv(GLuint texture, GLint level,
2070 GLenum pname, GLint *params)
2071 {
2072 struct gl_texture_object *texObj;
2073 GET_CURRENT_CONTEXT(ctx);
2074
2075 texObj = _mesa_lookup_texture_err(ctx, texture,
2076 "glGetTextureLevelParameteriv");
2077 if (!texObj)
2078 return;
2079
2080 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2081 return;
2082
2083 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2084 pname, params, true);
2085 }
2086
2087 void GLAPIENTRY
2088 _mesa_GetTextureLevelParameterivEXT(GLuint texture, GLenum target, GLint level,
2089 GLenum pname, GLint *params)
2090 {
2091 struct gl_texture_object *texObj;
2092 GET_CURRENT_CONTEXT(ctx);
2093
2094 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2095 "glGetTextureLevelParameterivEXT");
2096 if (!texObj)
2097 return;
2098
2099 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2100 return;
2101
2102 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2103 pname, params, true);
2104 }
2105
2106 void GLAPIENTRY
2107 _mesa_GetMultiTexLevelParameterivEXT(GLenum texunit, GLenum target, GLint level,
2108 GLenum pname, GLint *params)
2109 {
2110 struct gl_texture_object *texObj;
2111 GET_CURRENT_CONTEXT(ctx);
2112
2113 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2114 texunit - GL_TEXTURE0,
2115 true,
2116 "glGetMultiTexLevelParameterivEXT");
2117 if (!texObj)
2118 return;
2119
2120 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2121 return;
2122
2123 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2124 pname, params, true);
2125 }
2126
2127
2128 /**
2129 * This isn't exposed to the rest of the driver because it is a part of the
2130 * OpenGL API that is rarely used.
2131 */
2132 static void
2133 get_tex_parameterfv(struct gl_context *ctx,
2134 struct gl_texture_object *obj,
2135 GLenum pname, GLfloat *params, bool dsa)
2136 {
2137 _mesa_lock_context_textures(ctx);
2138 switch (pname) {
2139 case GL_TEXTURE_MAG_FILTER:
2140 *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
2141 break;
2142 case GL_TEXTURE_MIN_FILTER:
2143 *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
2144 break;
2145 case GL_TEXTURE_WRAP_S:
2146 *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
2147 break;
2148 case GL_TEXTURE_WRAP_T:
2149 *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
2150 break;
2151 case GL_TEXTURE_WRAP_R:
2152 *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
2153 break;
2154 case GL_TEXTURE_BORDER_COLOR:
2155 if (ctx->API == API_OPENGLES ||
2156 !ctx->Extensions.ARB_texture_border_clamp)
2157 goto invalid_pname;
2158
2159 if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
2160 _mesa_update_state_locked(ctx);
2161 if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer)) {
2162 params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
2163 params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
2164 params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
2165 params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
2166 }
2167 else {
2168 params[0] = obj->Sampler.BorderColor.f[0];
2169 params[1] = obj->Sampler.BorderColor.f[1];
2170 params[2] = obj->Sampler.BorderColor.f[2];
2171 params[3] = obj->Sampler.BorderColor.f[3];
2172 }
2173 break;
2174 case GL_TEXTURE_RESIDENT:
2175 if (ctx->API != API_OPENGL_COMPAT)
2176 goto invalid_pname;
2177
2178 *params = 1.0F;
2179 break;
2180 case GL_TEXTURE_PRIORITY:
2181 if (ctx->API != API_OPENGL_COMPAT)
2182 goto invalid_pname;
2183
2184 *params = obj->Priority;
2185 break;
2186 case GL_TEXTURE_MIN_LOD:
2187 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2188 goto invalid_pname;
2189
2190 *params = obj->Sampler.MinLod;
2191 break;
2192 case GL_TEXTURE_MAX_LOD:
2193 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2194 goto invalid_pname;
2195
2196 *params = obj->Sampler.MaxLod;
2197 break;
2198 case GL_TEXTURE_BASE_LEVEL:
2199 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2200 goto invalid_pname;
2201
2202 *params = (GLfloat) obj->BaseLevel;
2203 break;
2204 case GL_TEXTURE_MAX_LEVEL:
2205 *params = (GLfloat) obj->MaxLevel;
2206 break;
2207 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2208 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
2209 goto invalid_pname;
2210 *params = obj->Sampler.MaxAnisotropy;
2211 break;
2212 case GL_GENERATE_MIPMAP_SGIS:
2213 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
2214 goto invalid_pname;
2215
2216 *params = (GLfloat) obj->GenerateMipmap;
2217 break;
2218 case GL_TEXTURE_COMPARE_MODE_ARB:
2219 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2220 && !_mesa_is_gles3(ctx))
2221 goto invalid_pname;
2222 *params = (GLfloat) obj->Sampler.CompareMode;
2223 break;
2224 case GL_TEXTURE_COMPARE_FUNC_ARB:
2225 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2226 && !_mesa_is_gles3(ctx))
2227 goto invalid_pname;
2228 *params = (GLfloat) obj->Sampler.CompareFunc;
2229 break;
2230 case GL_DEPTH_TEXTURE_MODE_ARB:
2231 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
2232 * never existed in OpenGL ES.
2233 */
2234 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
2235 goto invalid_pname;
2236 *params = (GLfloat) obj->DepthMode;
2237 break;
2238 case GL_DEPTH_STENCIL_TEXTURE_MODE:
2239 if (!_mesa_has_ARB_stencil_texturing(ctx) && !_mesa_is_gles31(ctx))
2240 goto invalid_pname;
2241 *params = (GLfloat)
2242 (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
2243 break;
2244 case GL_TEXTURE_LOD_BIAS:
2245 if (_mesa_is_gles(ctx))
2246 goto invalid_pname;
2247
2248 *params = obj->Sampler.LodBias;
2249 break;
2250 case GL_TEXTURE_CROP_RECT_OES:
2251 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
2252 goto invalid_pname;
2253
2254 params[0] = (GLfloat) obj->CropRect[0];
2255 params[1] = (GLfloat) obj->CropRect[1];
2256 params[2] = (GLfloat) obj->CropRect[2];
2257 params[3] = (GLfloat) obj->CropRect[3];
2258 break;
2259
2260 case GL_TEXTURE_SWIZZLE_R_EXT:
2261 case GL_TEXTURE_SWIZZLE_G_EXT:
2262 case GL_TEXTURE_SWIZZLE_B_EXT:
2263 case GL_TEXTURE_SWIZZLE_A_EXT:
2264 if ((!_mesa_is_desktop_gl(ctx)
2265 || !ctx->Extensions.EXT_texture_swizzle)
2266 && !_mesa_is_gles3(ctx))
2267 goto invalid_pname;
2268 *params = (GLfloat) obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
2269 break;
2270
2271 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
2272 if ((!_mesa_is_desktop_gl(ctx)
2273 || !ctx->Extensions.EXT_texture_swizzle)
2274 && !_mesa_is_gles3(ctx)) {
2275 goto invalid_pname;
2276 }
2277 else {
2278 GLuint comp;
2279 for (comp = 0; comp < 4; comp++) {
2280 params[comp] = (GLfloat) obj->Swizzle[comp];
2281 }
2282 }
2283 break;
2284
2285 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
2286 if (!_mesa_is_desktop_gl(ctx)
2287 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
2288 goto invalid_pname;
2289 *params = (GLfloat) obj->Sampler.CubeMapSeamless;
2290 break;
2291
2292 case GL_TEXTURE_IMMUTABLE_FORMAT:
2293 *params = (GLfloat) obj->Immutable;
2294 break;
2295
2296 case GL_TEXTURE_IMMUTABLE_LEVELS:
2297 if (_mesa_is_gles3(ctx) || _mesa_has_texture_view(ctx))
2298 *params = (GLfloat) obj->ImmutableLevels;
2299 else
2300 goto invalid_pname;
2301 break;
2302
2303 case GL_TEXTURE_VIEW_MIN_LEVEL:
2304 if (!_mesa_has_texture_view(ctx))
2305 goto invalid_pname;
2306 *params = (GLfloat) obj->MinLevel;
2307 break;
2308
2309 case GL_TEXTURE_VIEW_NUM_LEVELS:
2310 if (!_mesa_has_texture_view(ctx))
2311 goto invalid_pname;
2312 *params = (GLfloat) obj->NumLevels;
2313 break;
2314
2315 case GL_TEXTURE_VIEW_MIN_LAYER:
2316 if (!_mesa_has_texture_view(ctx))
2317 goto invalid_pname;
2318 *params = (GLfloat) obj->MinLayer;
2319 break;
2320
2321 case GL_TEXTURE_VIEW_NUM_LAYERS:
2322 if (!_mesa_has_texture_view(ctx))
2323 goto invalid_pname;
2324 *params = (GLfloat) obj->NumLayers;
2325 break;
2326
2327 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
2328 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
2329 goto invalid_pname;
2330 *params = (GLfloat) obj->RequiredTextureImageUnits;
2331 break;
2332
2333 case GL_TEXTURE_SRGB_DECODE_EXT:
2334 if (!ctx->Extensions.EXT_texture_sRGB_decode)
2335 goto invalid_pname;
2336 *params = (GLfloat) obj->Sampler.sRGBDecode;
2337 break;
2338
2339 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
2340 if (!ctx->Extensions.ARB_shader_image_load_store)
2341 goto invalid_pname;
2342 *params = (GLfloat) obj->ImageFormatCompatibilityType;
2343 break;
2344
2345 case GL_TEXTURE_TARGET:
2346 if (ctx->API != API_OPENGL_CORE)
2347 goto invalid_pname;
2348 *params = ENUM_TO_FLOAT(obj->Target);
2349 break;
2350
2351 case GL_TEXTURE_TILING_EXT:
2352 if (!ctx->Extensions.EXT_memory_object)
2353 goto invalid_pname;
2354 *params = ENUM_TO_FLOAT(obj->TextureTiling);
2355 break;
2356
2357 default:
2358 goto invalid_pname;
2359 }
2360
2361 /* no error if we get here */
2362 _mesa_unlock_context_textures(ctx);
2363 return;
2364
2365 invalid_pname:
2366 _mesa_unlock_context_textures(ctx);
2367 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameterfv(pname=0x%x)",
2368 dsa ? "ture" : "", pname);
2369 }
2370
2371
2372 static void
2373 get_tex_parameteriv(struct gl_context *ctx,
2374 struct gl_texture_object *obj,
2375 GLenum pname, GLint *params, bool dsa)
2376 {
2377 _mesa_lock_texture(ctx, obj);
2378 switch (pname) {
2379 case GL_TEXTURE_MAG_FILTER:
2380 *params = (GLint) obj->Sampler.MagFilter;
2381 break;
2382 case GL_TEXTURE_MIN_FILTER:
2383 *params = (GLint) obj->Sampler.MinFilter;
2384 break;
2385 case GL_TEXTURE_WRAP_S:
2386 *params = (GLint) obj->Sampler.WrapS;
2387 break;
2388 case GL_TEXTURE_WRAP_T:
2389 *params = (GLint) obj->Sampler.WrapT;
2390 break;
2391 case GL_TEXTURE_WRAP_R:
2392 *params = (GLint) obj->Sampler.WrapR;
2393 break;
2394 case GL_TEXTURE_BORDER_COLOR:
2395 if (ctx->API == API_OPENGLES ||
2396 !ctx->Extensions.ARB_texture_border_clamp)
2397 goto invalid_pname;
2398
2399 {
2400 GLfloat b[4];
2401 b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
2402 b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
2403 b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
2404 b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
2405 params[0] = FLOAT_TO_INT(b[0]);
2406 params[1] = FLOAT_TO_INT(b[1]);
2407 params[2] = FLOAT_TO_INT(b[2]);
2408 params[3] = FLOAT_TO_INT(b[3]);
2409 }
2410 break;
2411 case GL_TEXTURE_RESIDENT:
2412 if (ctx->API != API_OPENGL_COMPAT)
2413 goto invalid_pname;
2414
2415 *params = 1;
2416 break;
2417 case GL_TEXTURE_PRIORITY:
2418 if (ctx->API != API_OPENGL_COMPAT)
2419 goto invalid_pname;
2420
2421 *params = FLOAT_TO_INT(obj->Priority);
2422 break;
2423 case GL_TEXTURE_MIN_LOD:
2424 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2425 goto invalid_pname;
2426 /* GL spec 'Data Conversions' section specifies that floating-point
2427 * value in integer Get function is rounded to nearest integer
2428 */
2429 *params = IROUND(obj->Sampler.MinLod);
2430 break;
2431 case GL_TEXTURE_MAX_LOD:
2432 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2433 goto invalid_pname;
2434 /* GL spec 'Data Conversions' section specifies that floating-point
2435 * value in integer Get function is rounded to nearest integer
2436 */
2437 *params = IROUND(obj->Sampler.MaxLod);
2438 break;
2439 case GL_TEXTURE_BASE_LEVEL:
2440 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2441 goto invalid_pname;
2442
2443 *params = obj->BaseLevel;
2444 break;
2445 case GL_TEXTURE_MAX_LEVEL:
2446 *params = obj->MaxLevel;
2447 break;
2448 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2449 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
2450 goto invalid_pname;
2451 /* GL spec 'Data Conversions' section specifies that floating-point
2452 * value in integer Get function is rounded to nearest integer
2453 */
2454 *params = IROUND(obj->Sampler.MaxAnisotropy);
2455 break;
2456 case GL_GENERATE_MIPMAP_SGIS:
2457 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
2458 goto invalid_pname;
2459
2460 *params = (GLint) obj->GenerateMipmap;
2461 break;
2462 case GL_TEXTURE_COMPARE_MODE_ARB:
2463 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2464 && !_mesa_is_gles3(ctx))
2465 goto invalid_pname;
2466 *params = (GLint) obj->Sampler.CompareMode;
2467 break;
2468 case GL_TEXTURE_COMPARE_FUNC_ARB:
2469 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2470 && !_mesa_is_gles3(ctx))
2471 goto invalid_pname;
2472 *params = (GLint) obj->Sampler.CompareFunc;
2473 break;
2474 case GL_DEPTH_TEXTURE_MODE_ARB:
2475 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
2476 goto invalid_pname;
2477 *params = (GLint) obj->DepthMode;
2478 break;
2479 case GL_DEPTH_STENCIL_TEXTURE_MODE:
2480 if (!_mesa_has_ARB_stencil_texturing(ctx) && !_mesa_is_gles31(ctx))
2481 goto invalid_pname;
2482 *params = (GLint)
2483 (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
2484 break;
2485 case GL_TEXTURE_LOD_BIAS:
2486 if (_mesa_is_gles(ctx))
2487 goto invalid_pname;
2488
2489 /* GL spec 'Data Conversions' section specifies that floating-point
2490 * value in integer Get function is rounded to nearest integer
2491 */
2492 *params = IROUND(obj->Sampler.LodBias);
2493 break;
2494 case GL_TEXTURE_CROP_RECT_OES:
2495 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
2496 goto invalid_pname;
2497
2498 params[0] = obj->CropRect[0];
2499 params[1] = obj->CropRect[1];
2500 params[2] = obj->CropRect[2];
2501 params[3] = obj->CropRect[3];
2502 break;
2503 case GL_TEXTURE_SWIZZLE_R_EXT:
2504 case GL_TEXTURE_SWIZZLE_G_EXT:
2505 case GL_TEXTURE_SWIZZLE_B_EXT:
2506 case GL_TEXTURE_SWIZZLE_A_EXT:
2507 if ((!_mesa_is_desktop_gl(ctx)
2508 || !ctx->Extensions.EXT_texture_swizzle)
2509 && !_mesa_is_gles3(ctx))
2510 goto invalid_pname;
2511 *params = obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
2512 break;
2513
2514 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
2515 if ((!_mesa_is_desktop_gl(ctx)
2516 || !ctx->Extensions.EXT_texture_swizzle)
2517 && !_mesa_is_gles3(ctx))
2518 goto invalid_pname;
2519 COPY_4V(params, obj->Swizzle);
2520 break;
2521
2522 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
2523 if (!_mesa_is_desktop_gl(ctx)
2524 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
2525 goto invalid_pname;
2526 *params = (GLint) obj->Sampler.CubeMapSeamless;
2527 break;
2528
2529 case GL_TEXTURE_IMMUTABLE_FORMAT:
2530 *params = (GLint) obj->Immutable;
2531 break;
2532
2533 case GL_TEXTURE_IMMUTABLE_LEVELS:
2534 if (_mesa_is_gles3(ctx) ||
2535 (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_view))
2536 *params = obj->ImmutableLevels;
2537 else
2538 goto invalid_pname;
2539 break;
2540
2541 case GL_TEXTURE_VIEW_MIN_LEVEL:
2542 if (!ctx->Extensions.ARB_texture_view)
2543 goto invalid_pname;
2544 *params = (GLint) obj->MinLevel;
2545 break;
2546
2547 case GL_TEXTURE_VIEW_NUM_LEVELS:
2548 if (!ctx->Extensions.ARB_texture_view)
2549 goto invalid_pname;
2550 *params = (GLint) obj->NumLevels;
2551 break;
2552
2553 case GL_TEXTURE_VIEW_MIN_LAYER:
2554 if (!ctx->Extensions.ARB_texture_view)
2555 goto invalid_pname;
2556 *params = (GLint) obj->MinLayer;
2557 break;
2558
2559 case GL_TEXTURE_VIEW_NUM_LAYERS:
2560 if (!ctx->Extensions.ARB_texture_view)
2561 goto invalid_pname;
2562 *params = (GLint) obj->NumLayers;
2563 break;
2564
2565 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
2566 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
2567 goto invalid_pname;
2568 *params = obj->RequiredTextureImageUnits;
2569 break;
2570
2571 case GL_TEXTURE_SRGB_DECODE_EXT:
2572 if (!ctx->Extensions.EXT_texture_sRGB_decode)
2573 goto invalid_pname;
2574 *params = obj->Sampler.sRGBDecode;
2575 break;
2576
2577 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
2578 if (!ctx->Extensions.ARB_shader_image_load_store)
2579 goto invalid_pname;
2580 *params = obj->ImageFormatCompatibilityType;
2581 break;
2582
2583 case GL_TEXTURE_TARGET:
2584 if (ctx->API != API_OPENGL_CORE)
2585 goto invalid_pname;
2586 *params = (GLint) obj->Target;
2587 break;
2588
2589 case GL_TEXTURE_TILING_EXT:
2590 if (!ctx->Extensions.EXT_memory_object)
2591 goto invalid_pname;
2592 *params = (GLint) obj->TextureTiling;
2593 break;
2594
2595 default:
2596 goto invalid_pname;
2597 }
2598
2599 /* no error if we get here */
2600 _mesa_unlock_texture(ctx, obj);
2601 return;
2602
2603 invalid_pname:
2604 _mesa_unlock_texture(ctx, obj);
2605 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameteriv(pname=0x%x)",
2606 dsa ? "ture" : "", pname);
2607 }
2608
2609 static void
2610 get_tex_parameterIiv(struct gl_context *ctx,
2611 struct gl_texture_object *obj,
2612 GLenum pname, GLint *params, bool dsa)
2613 {
2614 switch (pname) {
2615 case GL_TEXTURE_BORDER_COLOR:
2616 COPY_4V(params, obj->Sampler.BorderColor.i);
2617 break;
2618 default:
2619 get_tex_parameteriv(ctx, obj, pname, params, dsa);
2620 }
2621 }
2622
2623 void GLAPIENTRY
2624 _mesa_GetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
2625 {
2626 struct gl_texture_object *obj;
2627 GET_CURRENT_CONTEXT(ctx);
2628
2629 obj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2630 ctx->Texture.CurrentUnit,
2631 false,
2632 "glGetTexParameterfv");
2633 if (!obj)
2634 return;
2635
2636 get_tex_parameterfv(ctx, obj, pname, params, false);
2637 }
2638
2639 void GLAPIENTRY
2640 _mesa_GetTexParameteriv(GLenum target, GLenum pname, GLint *params)
2641 {
2642 struct gl_texture_object *obj;
2643 GET_CURRENT_CONTEXT(ctx);
2644
2645 obj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2646 ctx->Texture.CurrentUnit,
2647 false,
2648 "glGetTexParameteriv");
2649 if (!obj)
2650 return;
2651
2652 get_tex_parameteriv(ctx, obj, pname, params, false);
2653 }
2654
2655 /** New in GL 3.0 */
2656 void GLAPIENTRY
2657 _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
2658 {
2659 struct gl_texture_object *texObj;
2660 GET_CURRENT_CONTEXT(ctx);
2661
2662 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2663 ctx->Texture.CurrentUnit,
2664 false,
2665 "glGetTexParameterIiv");
2666 if (!texObj)
2667 return;
2668
2669 get_tex_parameterIiv(ctx, texObj, pname, params, false);
2670 }
2671
2672
2673 /** New in GL 3.0 */
2674 void GLAPIENTRY
2675 _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
2676 {
2677 struct gl_texture_object *texObj;
2678 GET_CURRENT_CONTEXT(ctx);
2679
2680 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2681 ctx->Texture.CurrentUnit,
2682 false,
2683 "glGetTexParameterIuiv");
2684 if (!texObj)
2685 return;
2686
2687 get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, false);
2688 }
2689
2690 void GLAPIENTRY
2691 _mesa_GetTextureParameterfvEXT(GLuint texture, GLenum target, GLenum pname, GLfloat *params)
2692 {
2693 struct gl_texture_object *texObj;
2694 GET_CURRENT_CONTEXT(ctx);
2695
2696 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2697 "glGetTextureParameterfvEXT");
2698 if (!texObj)
2699 return;
2700
2701 if (!is_texparameteri_target_valid(texObj->Target)) {
2702 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTextureParameterfvEXT");
2703 return;
2704 }
2705
2706 get_tex_parameterfv(ctx, texObj, pname, params, true);
2707 }
2708
2709 void GLAPIENTRY
2710 _mesa_GetMultiTexParameterfvEXT(GLenum texunit, GLenum target, GLenum pname, GLfloat *params)
2711 {
2712 struct gl_texture_object *texObj;
2713 GET_CURRENT_CONTEXT(ctx);
2714
2715 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2716 texunit - GL_TEXTURE0,
2717 false,
2718 "glGetMultiTexParameterfvEXT");
2719 if (!texObj)
2720 return;
2721
2722 if (!is_texparameteri_target_valid(texObj->Target)) {
2723 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetMultiTexParameterfvEXT");
2724 return;
2725 }
2726 get_tex_parameterfv(ctx, texObj, pname, params, true);
2727 }
2728
2729 void GLAPIENTRY
2730 _mesa_GetTextureParameterfv(GLuint texture, GLenum pname, GLfloat *params)
2731 {
2732 struct gl_texture_object *obj;
2733 GET_CURRENT_CONTEXT(ctx);
2734
2735 obj = get_texobj_by_name(ctx, texture, "glGetTextureParameterfv");
2736 if (!obj)
2737 return;
2738
2739 get_tex_parameterfv(ctx, obj, pname, params, true);
2740 }
2741
2742 void GLAPIENTRY
2743 _mesa_GetTextureParameterivEXT(GLuint texture, GLenum target, GLenum pname, GLint *params)
2744 {
2745 struct gl_texture_object *texObj;
2746 GET_CURRENT_CONTEXT(ctx);
2747
2748 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2749 "glGetTextureParameterivEXT");
2750 if (!texObj)
2751 return;
2752
2753 if (!is_texparameteri_target_valid(texObj->Target)) {
2754 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTextureParameterivEXT");
2755 return;
2756 }
2757 get_tex_parameteriv(ctx, texObj, pname, params, true);
2758 }
2759
2760 void GLAPIENTRY
2761 _mesa_GetMultiTexParameterivEXT(GLenum texunit, GLenum target, GLenum pname, GLint *params)
2762 {
2763 struct gl_texture_object *texObj;
2764 GET_CURRENT_CONTEXT(ctx);
2765
2766 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2767 texunit - GL_TEXTURE0,
2768 false,
2769 "glGetMultiTexParameterivEXT");
2770 if (!texObj)
2771 return;
2772
2773 if (!is_texparameteri_target_valid(texObj->Target)) {
2774 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetMultiTexParameterivEXT");
2775 return;
2776 }
2777 get_tex_parameteriv(ctx, texObj, pname, params, true);
2778 }
2779
2780 void GLAPIENTRY
2781 _mesa_GetTextureParameteriv(GLuint texture, GLenum pname, GLint *params)
2782 {
2783 struct gl_texture_object *obj;
2784 GET_CURRENT_CONTEXT(ctx);
2785
2786 obj = get_texobj_by_name(ctx, texture, "glGetTextureParameteriv");
2787 if (!obj)
2788 return;
2789
2790 get_tex_parameteriv(ctx, obj, pname, params, true);
2791 }
2792
2793 void GLAPIENTRY
2794 _mesa_GetTextureParameterIiv(GLuint texture, GLenum pname, GLint *params)
2795 {
2796 struct gl_texture_object *texObj;
2797 GET_CURRENT_CONTEXT(ctx);
2798
2799 texObj = get_texobj_by_name(ctx, texture, "glGetTextureParameterIiv");
2800 if (!texObj)
2801 return;
2802
2803 get_tex_parameterIiv(ctx, texObj, pname, params, true);
2804 }
2805
2806 void GLAPIENTRY
2807 _mesa_GetTextureParameterIivEXT(GLuint texture, GLenum target, GLenum pname, GLint *params)
2808 {
2809 struct gl_texture_object *texObj;
2810 GET_CURRENT_CONTEXT(ctx);
2811
2812 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2813 "glGetTextureParameterIivEXT");
2814 if (!texObj)
2815 return;
2816
2817
2818 get_tex_parameterIiv(ctx, texObj, pname, params, true);
2819 }
2820
2821 void GLAPIENTRY
2822 _mesa_GetMultiTexParameterIivEXT(GLenum texunit, GLenum target, GLenum pname,
2823 GLint *params)
2824 {
2825 struct gl_texture_object *texObj;
2826 GET_CURRENT_CONTEXT(ctx);
2827
2828 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2829 texunit - GL_TEXTURE0,
2830 true,
2831 "glGetMultiTexParameterIiv");
2832 if (!texObj)
2833 return;
2834
2835 get_tex_parameterIiv(ctx, texObj, pname, params, true);
2836 }
2837
2838 void GLAPIENTRY
2839 _mesa_GetTextureParameterIuiv(GLuint texture, GLenum pname, GLuint *params)
2840 {
2841 struct gl_texture_object *texObj;
2842 GET_CURRENT_CONTEXT(ctx);
2843
2844 texObj = get_texobj_by_name(ctx, texture, "glGetTextureParameterIuiv");
2845 if (!texObj)
2846 return;
2847
2848 get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, true);
2849 }
2850
2851 void GLAPIENTRY
2852 _mesa_GetTextureParameterIuivEXT(GLuint texture, GLenum target, GLenum pname,
2853 GLuint *params)
2854 {
2855 struct gl_texture_object *texObj;
2856 GET_CURRENT_CONTEXT(ctx);
2857
2858 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2859 "glGetTextureParameterIuvEXT");
2860 if (!texObj)
2861 return;
2862
2863 get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, true);
2864 }
2865
2866 void GLAPIENTRY
2867 _mesa_GetMultiTexParameterIuivEXT(GLenum texunit, GLenum target, GLenum pname,
2868 GLuint *params)
2869 {
2870 struct gl_texture_object *texObj;
2871 GET_CURRENT_CONTEXT(ctx);
2872
2873 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2874 texunit - GL_TEXTURE0,
2875 true,
2876 "glGetMultiTexParameterIuiv");
2877 if (!texObj)
2878 return;
2879
2880 get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, true);
2881 }