mesa: add new helper _mesa_get_texobj_by_target_and_texunit
[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_TextureParameterfEXT(GLuint texture, GLenum target, GLenum pname, GLfloat param)
1200 {
1201 struct gl_texture_object *texObj;
1202 GET_CURRENT_CONTEXT(ctx);
1203
1204 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1205 "glTextureParameterfEXT");
1206 if (!texObj)
1207 return;
1208
1209 if (!is_texparameteri_target_valid(texObj->Target)) {
1210 _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterfEXT");
1211 return;
1212 }
1213
1214 _mesa_texture_parameterf(ctx, texObj, pname, param, true);
1215 }
1216
1217 void GLAPIENTRY
1218 _mesa_TextureParameterf(GLuint texture, GLenum pname, GLfloat param)
1219 {
1220 struct gl_texture_object *texObj;
1221 GET_CURRENT_CONTEXT(ctx);
1222
1223 texObj = get_texobj_by_name(ctx, texture, "glTextureParameterf");
1224 if (!texObj)
1225 return;
1226
1227 _mesa_texture_parameterf(ctx, texObj, pname, param, true);
1228 }
1229
1230 void GLAPIENTRY
1231 _mesa_TextureParameteriEXT(GLuint texture, GLenum target, GLenum pname, GLint param)
1232 {
1233 struct gl_texture_object *texObj;
1234 GET_CURRENT_CONTEXT(ctx);
1235
1236 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1237 "glTextureParameteriEXT");
1238 if (!texObj)
1239 return;
1240
1241 if (!is_texparameteri_target_valid(texObj->Target)) {
1242 _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameteriEXT(target)");
1243 return;
1244 }
1245
1246 _mesa_texture_parameteri(ctx, texObj, pname, param, true);
1247 }
1248
1249 void GLAPIENTRY
1250 _mesa_TextureParameteri(GLuint texture, GLenum pname, GLint param)
1251 {
1252 struct gl_texture_object *texObj;
1253 GET_CURRENT_CONTEXT(ctx);
1254
1255 texObj = get_texobj_by_name(ctx, texture, "glTextureParameteri");
1256 if (!texObj)
1257 return;
1258
1259 _mesa_texture_parameteri(ctx, texObj, pname, param, true);
1260 }
1261
1262 void GLAPIENTRY
1263 _mesa_TextureParameterivEXT(GLuint texture, GLenum target, GLenum pname,
1264 const GLint *params)
1265 {
1266 struct gl_texture_object *texObj;
1267 GET_CURRENT_CONTEXT(ctx);
1268
1269 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1270 "glTextureParameterivEXT");
1271 if (!texObj)
1272 return;
1273
1274 if (!is_texparameteri_target_valid(texObj->Target)) {
1275 _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterivEXT(target)");
1276 return;
1277 }
1278
1279 _mesa_texture_parameteriv(ctx, texObj, pname, params, true);
1280 }
1281
1282 void GLAPIENTRY
1283 _mesa_TextureParameteriv(GLuint texture, GLenum pname,
1284 const GLint *params)
1285 {
1286 struct gl_texture_object *texObj;
1287 GET_CURRENT_CONTEXT(ctx);
1288
1289 texObj = get_texobj_by_name(ctx, texture, "glTextureParameteriv");
1290 if (!texObj)
1291 return;
1292
1293 _mesa_texture_parameteriv(ctx, texObj, pname, params, true);
1294 }
1295
1296
1297 void GLAPIENTRY
1298 _mesa_TextureParameterIiv(GLuint texture, GLenum pname, const GLint *params)
1299 {
1300 struct gl_texture_object *texObj;
1301 GET_CURRENT_CONTEXT(ctx);
1302
1303 texObj = get_texobj_by_name(ctx, texture, "glTextureParameterIiv");
1304 if (!texObj)
1305 return;
1306
1307 _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
1308 }
1309
1310 void GLAPIENTRY
1311 _mesa_TextureParameterIuiv(GLuint texture, GLenum pname, const GLuint *params)
1312 {
1313 struct gl_texture_object *texObj;
1314 GET_CURRENT_CONTEXT(ctx);
1315
1316 texObj = get_texobj_by_name(ctx, texture, "glTextureParameterIuiv");
1317 if (!texObj)
1318 return;
1319
1320 _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
1321 }
1322
1323 GLboolean
1324 _mesa_legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target,
1325 bool dsa)
1326 {
1327 /* Common targets for desktop GL and GLES 3.1. */
1328 switch (target) {
1329 case GL_TEXTURE_2D:
1330 case GL_TEXTURE_3D:
1331 return GL_TRUE;
1332 case GL_TEXTURE_2D_ARRAY_EXT:
1333 return ctx->Extensions.EXT_texture_array;
1334 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1335 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1336 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1337 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1338 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1339 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1340 return ctx->Extensions.ARB_texture_cube_map;
1341 case GL_TEXTURE_2D_MULTISAMPLE:
1342 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
1343 return ctx->Extensions.ARB_texture_multisample;
1344 case GL_TEXTURE_BUFFER:
1345 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1346 * but not in earlier versions that expose ARB_texture_buffer_object.
1347 *
1348 * From the ARB_texture_buffer_object spec:
1349 * "(7) Do buffer textures support texture parameters (TexParameter) or
1350 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1351 *
1352 * RESOLVED: No. [...] Note that the spec edits above don't add
1353 * explicit error language for any of these cases. That is because
1354 * each of the functions enumerate the set of valid <target>
1355 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1356 * these cases means that target is not legal, and an INVALID_ENUM
1357 * error should be generated."
1358 *
1359 * From the OpenGL 3.1 spec:
1360 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1361 */
1362 return (_mesa_is_desktop_gl(ctx) && ctx->Version >= 31) ||
1363 _mesa_has_OES_texture_buffer(ctx);
1364 case GL_TEXTURE_CUBE_MAP_ARRAY:
1365 return _mesa_has_texture_cube_map_array(ctx);
1366 }
1367
1368 if (!_mesa_is_desktop_gl(ctx))
1369 return GL_FALSE;
1370
1371 /* Rest of the desktop GL targets. */
1372 switch (target) {
1373 case GL_TEXTURE_1D:
1374 case GL_PROXY_TEXTURE_1D:
1375 case GL_PROXY_TEXTURE_2D:
1376 case GL_PROXY_TEXTURE_3D:
1377 return GL_TRUE;
1378 case GL_PROXY_TEXTURE_CUBE_MAP:
1379 return ctx->Extensions.ARB_texture_cube_map;
1380 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY:
1381 return ctx->Extensions.ARB_texture_cube_map_array;
1382 case GL_TEXTURE_RECTANGLE_NV:
1383 case GL_PROXY_TEXTURE_RECTANGLE_NV:
1384 return ctx->Extensions.NV_texture_rectangle;
1385 case GL_TEXTURE_1D_ARRAY_EXT:
1386 case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
1387 case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
1388 return ctx->Extensions.EXT_texture_array;
1389 case GL_PROXY_TEXTURE_2D_MULTISAMPLE:
1390 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY:
1391 return ctx->Extensions.ARB_texture_multisample;
1392
1393 /* This is a valid target for dsa, but the OpenGL 4.5 core spec
1394 * (30.10.2014) Section 8.11 Texture Queries says:
1395 * "For GetTextureLevelParameter* only, texture may also be a cube
1396 * map texture object. In this case the query is always performed
1397 * for face zero (the TEXTURE_CUBE_MAP_POSITIVE_X face), since there
1398 * is no way to specify another face."
1399 */
1400 case GL_TEXTURE_CUBE_MAP:
1401 return dsa;
1402 default:
1403 return GL_FALSE;
1404 }
1405 }
1406
1407
1408 static void
1409 get_tex_level_parameter_image(struct gl_context *ctx,
1410 const struct gl_texture_object *texObj,
1411 GLenum target, GLint level,
1412 GLenum pname, GLint *params,
1413 bool dsa)
1414 {
1415 const struct gl_texture_image *img = NULL;
1416 struct gl_texture_image dummy_image;
1417 mesa_format texFormat;
1418 const char *suffix = dsa ? "ture" : "";
1419
1420 img = _mesa_select_tex_image(texObj, target, level);
1421 if (!img || img->TexFormat == MESA_FORMAT_NONE) {
1422 /* In case of undefined texture image return the default values.
1423 *
1424 * From OpenGL 4.0 spec, page 398:
1425 * "The initial internal format of a texel array is RGBA
1426 * instead of 1. TEXTURE_COMPONENTS is deprecated; always
1427 * use TEXTURE_INTERNAL_FORMAT."
1428 */
1429 memset(&dummy_image, 0, sizeof(dummy_image));
1430 dummy_image.TexFormat = MESA_FORMAT_NONE;
1431 dummy_image.InternalFormat = GL_RGBA;
1432 dummy_image._BaseFormat = GL_NONE;
1433 dummy_image.FixedSampleLocations = GL_TRUE;
1434
1435 img = &dummy_image;
1436 }
1437
1438 texFormat = img->TexFormat;
1439
1440 switch (pname) {
1441 case GL_TEXTURE_WIDTH:
1442 *params = img->Width;
1443 break;
1444 case GL_TEXTURE_HEIGHT:
1445 *params = img->Height;
1446 break;
1447 case GL_TEXTURE_DEPTH:
1448 *params = img->Depth;
1449 break;
1450 case GL_TEXTURE_INTERNAL_FORMAT:
1451 if (_mesa_is_format_compressed(texFormat)) {
1452 /* need to return the actual compressed format */
1453 *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
1454 }
1455 else {
1456 /* If the true internal format is not compressed but the user
1457 * requested a generic compressed format, we have to return the
1458 * generic base format that matches.
1459 *
1460 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1461 *
1462 * "If no specific compressed format is available,
1463 * internalformat is instead replaced by the corresponding base
1464 * internal format."
1465 *
1466 * Otherwise just return the user's requested internal format
1467 */
1468 const GLenum f =
1469 _mesa_gl_compressed_format_base_format(img->InternalFormat);
1470
1471 *params = (f != 0) ? f : img->InternalFormat;
1472 }
1473 break;
1474 case GL_TEXTURE_BORDER:
1475 if (ctx->API != API_OPENGL_COMPAT)
1476 goto invalid_pname;
1477 *params = img->Border;
1478 break;
1479 case GL_TEXTURE_RED_SIZE:
1480 case GL_TEXTURE_GREEN_SIZE:
1481 case GL_TEXTURE_BLUE_SIZE:
1482 case GL_TEXTURE_ALPHA_SIZE:
1483 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1484 *params = _mesa_get_format_bits(texFormat, pname);
1485 else
1486 *params = 0;
1487 break;
1488 case GL_TEXTURE_INTENSITY_SIZE:
1489 case GL_TEXTURE_LUMINANCE_SIZE:
1490 if (ctx->API != API_OPENGL_COMPAT)
1491 goto invalid_pname;
1492 if (_mesa_base_format_has_channel(img->_BaseFormat, pname)) {
1493 *params = _mesa_get_format_bits(texFormat, pname);
1494 if (*params == 0) {
1495 /* intensity or luminance is probably stored as RGB[A] */
1496 *params = MIN2(_mesa_get_format_bits(texFormat,
1497 GL_TEXTURE_RED_SIZE),
1498 _mesa_get_format_bits(texFormat,
1499 GL_TEXTURE_GREEN_SIZE));
1500 }
1501 if (*params == 0 && pname == GL_TEXTURE_INTENSITY_SIZE) {
1502 /* Gallium may store intensity as LA */
1503 *params = _mesa_get_format_bits(texFormat,
1504 GL_TEXTURE_ALPHA_SIZE);
1505 }
1506 }
1507 else {
1508 *params = 0;
1509 }
1510 break;
1511 case GL_TEXTURE_DEPTH_SIZE_ARB:
1512 if (!ctx->Extensions.ARB_depth_texture)
1513 goto invalid_pname;
1514 *params = _mesa_get_format_bits(texFormat, pname);
1515 break;
1516 case GL_TEXTURE_STENCIL_SIZE:
1517 *params = _mesa_get_format_bits(texFormat, pname);
1518 break;
1519 case GL_TEXTURE_SHARED_SIZE:
1520 if (ctx->Version < 30 &&
1521 !ctx->Extensions.EXT_texture_shared_exponent)
1522 goto invalid_pname;
1523 *params = texFormat == MESA_FORMAT_R9G9B9E5_FLOAT ? 5 : 0;
1524 break;
1525
1526 /* GL_ARB_texture_compression */
1527 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1528 if (_mesa_is_format_compressed(texFormat) &&
1529 !_mesa_is_proxy_texture(target)) {
1530 *params = _mesa_format_image_size(texFormat, img->Width,
1531 img->Height, img->Depth);
1532 } else {
1533 _mesa_error(ctx, GL_INVALID_OPERATION,
1534 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1535 _mesa_enum_to_string(pname));
1536 }
1537 break;
1538 case GL_TEXTURE_COMPRESSED:
1539 *params = (GLint) _mesa_is_format_compressed(texFormat);
1540 break;
1541
1542 /* GL_ARB_texture_float */
1543 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1544 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1545 if (ctx->API != API_OPENGL_COMPAT)
1546 goto invalid_pname;
1547 /* FALLTHROUGH */
1548 case GL_TEXTURE_RED_TYPE_ARB:
1549 case GL_TEXTURE_GREEN_TYPE_ARB:
1550 case GL_TEXTURE_BLUE_TYPE_ARB:
1551 case GL_TEXTURE_ALPHA_TYPE_ARB:
1552 case GL_TEXTURE_DEPTH_TYPE_ARB:
1553 if (!ctx->Extensions.ARB_texture_float)
1554 goto invalid_pname;
1555 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1556 *params = _mesa_get_format_datatype(texFormat);
1557 else
1558 *params = GL_NONE;
1559 break;
1560
1561 /* GL_ARB_texture_multisample */
1562 case GL_TEXTURE_SAMPLES:
1563 if (!ctx->Extensions.ARB_texture_multisample)
1564 goto invalid_pname;
1565 *params = img->NumSamples;
1566 break;
1567
1568 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1569 if (!ctx->Extensions.ARB_texture_multisample)
1570 goto invalid_pname;
1571 *params = img->FixedSampleLocations;
1572 break;
1573
1574 /* There is never a buffer data store here, but these pnames still have
1575 * to work.
1576 */
1577
1578 /* GL_ARB_texture_buffer_object */
1579 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
1580 if (!ctx->Extensions.ARB_texture_buffer_object)
1581 goto invalid_pname;
1582 *params = 0;
1583 break;
1584
1585 /* GL_ARB_texture_buffer_range */
1586 case GL_TEXTURE_BUFFER_OFFSET:
1587 if (!ctx->Extensions.ARB_texture_buffer_range)
1588 goto invalid_pname;
1589 *params = 0;
1590 break;
1591 case GL_TEXTURE_BUFFER_SIZE:
1592 if (!ctx->Extensions.ARB_texture_buffer_range)
1593 goto invalid_pname;
1594 *params = 0;
1595 break;
1596
1597 default:
1598 goto invalid_pname;
1599 }
1600
1601 /* no error if we get here */
1602 return;
1603
1604 invalid_pname:
1605 _mesa_error(ctx, GL_INVALID_ENUM,
1606 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1607 _mesa_enum_to_string(pname));
1608 }
1609
1610
1611 /**
1612 * Handle a glGetTexLevelParamteriv() call for a texture buffer.
1613 */
1614 static void
1615 get_tex_level_parameter_buffer(struct gl_context *ctx,
1616 const struct gl_texture_object *texObj,
1617 GLenum pname, GLint *params, bool dsa)
1618 {
1619 const struct gl_buffer_object *bo = texObj->BufferObject;
1620 mesa_format texFormat = texObj->_BufferObjectFormat;
1621 int bytes = MAX2(1, _mesa_get_format_bytes(texFormat));
1622 GLenum internalFormat = texObj->BufferObjectFormat;
1623 GLenum baseFormat = _mesa_get_format_base_format(texFormat);
1624 const char *suffix = dsa ? "ture" : "";
1625
1626 assert(texObj->Target == GL_TEXTURE_BUFFER);
1627
1628 if (!bo) {
1629 /* undefined texture buffer object */
1630 switch (pname) {
1631 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1632 *params = GL_TRUE;
1633 break;
1634 case GL_TEXTURE_INTERNAL_FORMAT:
1635 *params = internalFormat;
1636 break;
1637 default:
1638 *params = 0;
1639 break;
1640 }
1641 return;
1642 }
1643
1644 switch (pname) {
1645 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
1646 *params = bo->Name;
1647 break;
1648 case GL_TEXTURE_WIDTH:
1649 *params = ((texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize)
1650 / bytes;
1651 break;
1652 case GL_TEXTURE_HEIGHT:
1653 case GL_TEXTURE_DEPTH:
1654 *params = 1;
1655 break;
1656 case GL_TEXTURE_BORDER:
1657 case GL_TEXTURE_SHARED_SIZE:
1658 case GL_TEXTURE_COMPRESSED:
1659 *params = 0;
1660 break;
1661 case GL_TEXTURE_INTERNAL_FORMAT:
1662 *params = internalFormat;
1663 break;
1664 case GL_TEXTURE_RED_SIZE:
1665 case GL_TEXTURE_GREEN_SIZE:
1666 case GL_TEXTURE_BLUE_SIZE:
1667 case GL_TEXTURE_ALPHA_SIZE:
1668 if (_mesa_base_format_has_channel(baseFormat, pname))
1669 *params = _mesa_get_format_bits(texFormat, pname);
1670 else
1671 *params = 0;
1672 break;
1673 case GL_TEXTURE_INTENSITY_SIZE:
1674 case GL_TEXTURE_LUMINANCE_SIZE:
1675 if (_mesa_base_format_has_channel(baseFormat, pname)) {
1676 *params = _mesa_get_format_bits(texFormat, pname);
1677 if (*params == 0) {
1678 /* intensity or luminance is probably stored as RGB[A] */
1679 *params = MIN2(_mesa_get_format_bits(texFormat,
1680 GL_TEXTURE_RED_SIZE),
1681 _mesa_get_format_bits(texFormat,
1682 GL_TEXTURE_GREEN_SIZE));
1683 }
1684 } else {
1685 *params = 0;
1686 }
1687 break;
1688 case GL_TEXTURE_DEPTH_SIZE_ARB:
1689 case GL_TEXTURE_STENCIL_SIZE_EXT:
1690 *params = _mesa_get_format_bits(texFormat, pname);
1691 break;
1692
1693 /* GL_ARB_texture_buffer_range */
1694 case GL_TEXTURE_BUFFER_OFFSET:
1695 if (!ctx->Extensions.ARB_texture_buffer_range)
1696 goto invalid_pname;
1697 *params = texObj->BufferOffset;
1698 break;
1699 case GL_TEXTURE_BUFFER_SIZE:
1700 if (!ctx->Extensions.ARB_texture_buffer_range)
1701 goto invalid_pname;
1702 *params = (texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize;
1703 break;
1704
1705 /* GL_ARB_texture_multisample */
1706 case GL_TEXTURE_SAMPLES:
1707 if (!ctx->Extensions.ARB_texture_multisample)
1708 goto invalid_pname;
1709 *params = 0;
1710 break;
1711
1712 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1713 if (!ctx->Extensions.ARB_texture_multisample)
1714 goto invalid_pname;
1715 *params = GL_TRUE;
1716 break;
1717
1718 /* GL_ARB_texture_compression */
1719 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1720 /* Always illegal for GL_TEXTURE_BUFFER */
1721 _mesa_error(ctx, GL_INVALID_OPERATION,
1722 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1723 _mesa_enum_to_string(pname));
1724 break;
1725
1726 /* GL_ARB_texture_float */
1727 case GL_TEXTURE_RED_TYPE_ARB:
1728 case GL_TEXTURE_GREEN_TYPE_ARB:
1729 case GL_TEXTURE_BLUE_TYPE_ARB:
1730 case GL_TEXTURE_ALPHA_TYPE_ARB:
1731 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1732 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1733 case GL_TEXTURE_DEPTH_TYPE_ARB:
1734 if (!ctx->Extensions.ARB_texture_float)
1735 goto invalid_pname;
1736 if (_mesa_base_format_has_channel(baseFormat, pname))
1737 *params = _mesa_get_format_datatype(texFormat);
1738 else
1739 *params = GL_NONE;
1740 break;
1741
1742 default:
1743 goto invalid_pname;
1744 }
1745
1746 /* no error if we get here */
1747 return;
1748
1749 invalid_pname:
1750 _mesa_error(ctx, GL_INVALID_ENUM,
1751 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1752 _mesa_enum_to_string(pname));
1753 }
1754
1755 static bool
1756 valid_tex_level_parameteriv_target(struct gl_context *ctx, GLenum target,
1757 bool dsa)
1758 {
1759 const char *suffix = dsa ? "ture" : "";
1760 if (!_mesa_legal_get_tex_level_parameter_target(ctx, target, dsa)) {
1761 _mesa_error(ctx, GL_INVALID_ENUM,
1762 "glGetTex%sLevelParameter[if]v(target=%s)", suffix,
1763 _mesa_enum_to_string(target));
1764 return false;
1765 }
1766 return true;
1767 }
1768
1769 /**
1770 * This isn't exposed to the rest of the driver because it is a part of the
1771 * OpenGL API that is rarely used.
1772 */
1773 static void
1774 get_tex_level_parameteriv(struct gl_context *ctx,
1775 struct gl_texture_object *texObj,
1776 GLenum target, GLint level,
1777 GLenum pname, GLint *params,
1778 bool dsa)
1779 {
1780 GLint maxLevels;
1781 const char *suffix = dsa ? "ture" : "";
1782
1783 /* Check for errors */
1784 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
1785 _mesa_error(ctx, GL_INVALID_OPERATION,
1786 "glGetTex%sLevelParameter[if]v("
1787 "current unit >= max combined texture units)", suffix);
1788 return;
1789 }
1790
1791 maxLevels = _mesa_max_texture_levels(ctx, target);
1792 assert(maxLevels != 0);
1793
1794 if (level < 0 || level >= maxLevels) {
1795 _mesa_error(ctx, GL_INVALID_VALUE,
1796 "glGetTex%sLevelParameter[if]v(level out of range)", suffix);
1797 return;
1798 }
1799
1800 /* Get the level parameter */
1801 if (target == GL_TEXTURE_BUFFER) {
1802 get_tex_level_parameter_buffer(ctx, texObj, pname, params, dsa);
1803 }
1804 else {
1805 get_tex_level_parameter_image(ctx, texObj, target,
1806 level, pname, params, dsa);
1807 }
1808 }
1809
1810 void GLAPIENTRY
1811 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
1812 GLenum pname, GLfloat *params )
1813 {
1814 struct gl_texture_object *texObj;
1815 GLint iparam;
1816 GET_CURRENT_CONTEXT(ctx);
1817
1818 if (!valid_tex_level_parameteriv_target(ctx, target, false))
1819 return;
1820
1821 texObj = _mesa_get_current_tex_object(ctx, target);
1822 if (!texObj)
1823 return;
1824
1825 get_tex_level_parameteriv(ctx, texObj, target, level,
1826 pname, &iparam, false);
1827
1828 *params = (GLfloat) iparam;
1829 }
1830
1831 void GLAPIENTRY
1832 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
1833 GLenum pname, GLint *params )
1834 {
1835 struct gl_texture_object *texObj;
1836 GET_CURRENT_CONTEXT(ctx);
1837
1838 if (!valid_tex_level_parameteriv_target(ctx, target, false))
1839 return;
1840
1841 texObj = _mesa_get_current_tex_object(ctx, target);
1842 if (!texObj)
1843 return;
1844
1845 get_tex_level_parameteriv(ctx, texObj, target, level,
1846 pname, params, false);
1847 }
1848
1849 void GLAPIENTRY
1850 _mesa_GetTextureLevelParameterfv(GLuint texture, GLint level,
1851 GLenum pname, GLfloat *params)
1852 {
1853 struct gl_texture_object *texObj;
1854 GLint iparam;
1855 GET_CURRENT_CONTEXT(ctx);
1856
1857 texObj = _mesa_lookup_texture_err(ctx, texture,
1858 "glGetTextureLevelParameterfv");
1859 if (!texObj)
1860 return;
1861
1862 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
1863 return;
1864
1865 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
1866 pname, &iparam, true);
1867
1868 *params = (GLfloat) iparam;
1869 }
1870
1871 void GLAPIENTRY
1872 _mesa_GetTextureLevelParameterfvEXT(GLuint texture, GLenum target, GLint level,
1873 GLenum pname, GLfloat *params)
1874 {
1875 struct gl_texture_object *texObj;
1876 GLint iparam;
1877 GET_CURRENT_CONTEXT(ctx);
1878
1879 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1880 "glGetTextureLevelParameterfvEXT");
1881 if (!texObj)
1882 return;
1883
1884 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
1885 return;
1886
1887 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
1888 pname, &iparam, true);
1889
1890 *params = (GLfloat) iparam;
1891 }
1892
1893 void GLAPIENTRY
1894 _mesa_GetTextureLevelParameteriv(GLuint texture, GLint level,
1895 GLenum pname, GLint *params)
1896 {
1897 struct gl_texture_object *texObj;
1898 GET_CURRENT_CONTEXT(ctx);
1899
1900 texObj = _mesa_lookup_texture_err(ctx, texture,
1901 "glGetTextureLevelParameteriv");
1902 if (!texObj)
1903 return;
1904
1905 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
1906 return;
1907
1908 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
1909 pname, params, true);
1910 }
1911
1912 void GLAPIENTRY
1913 _mesa_GetTextureLevelParameterivEXT(GLuint texture, GLenum target, GLint level,
1914 GLenum pname, GLint *params)
1915 {
1916 struct gl_texture_object *texObj;
1917 GET_CURRENT_CONTEXT(ctx);
1918
1919 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1920 "glGetTextureLevelParameterivEXT");
1921 if (!texObj)
1922 return;
1923
1924 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
1925 return;
1926
1927 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
1928 pname, params, true);
1929 }
1930
1931
1932 /**
1933 * This isn't exposed to the rest of the driver because it is a part of the
1934 * OpenGL API that is rarely used.
1935 */
1936 static void
1937 get_tex_parameterfv(struct gl_context *ctx,
1938 struct gl_texture_object *obj,
1939 GLenum pname, GLfloat *params, bool dsa)
1940 {
1941 _mesa_lock_context_textures(ctx);
1942 switch (pname) {
1943 case GL_TEXTURE_MAG_FILTER:
1944 *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
1945 break;
1946 case GL_TEXTURE_MIN_FILTER:
1947 *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
1948 break;
1949 case GL_TEXTURE_WRAP_S:
1950 *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
1951 break;
1952 case GL_TEXTURE_WRAP_T:
1953 *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
1954 break;
1955 case GL_TEXTURE_WRAP_R:
1956 *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
1957 break;
1958 case GL_TEXTURE_BORDER_COLOR:
1959 if (ctx->API == API_OPENGLES ||
1960 !ctx->Extensions.ARB_texture_border_clamp)
1961 goto invalid_pname;
1962
1963 if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
1964 _mesa_update_state_locked(ctx);
1965 if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer)) {
1966 params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1967 params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1968 params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1969 params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
1970 }
1971 else {
1972 params[0] = obj->Sampler.BorderColor.f[0];
1973 params[1] = obj->Sampler.BorderColor.f[1];
1974 params[2] = obj->Sampler.BorderColor.f[2];
1975 params[3] = obj->Sampler.BorderColor.f[3];
1976 }
1977 break;
1978 case GL_TEXTURE_RESIDENT:
1979 if (ctx->API != API_OPENGL_COMPAT)
1980 goto invalid_pname;
1981
1982 *params = 1.0F;
1983 break;
1984 case GL_TEXTURE_PRIORITY:
1985 if (ctx->API != API_OPENGL_COMPAT)
1986 goto invalid_pname;
1987
1988 *params = obj->Priority;
1989 break;
1990 case GL_TEXTURE_MIN_LOD:
1991 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1992 goto invalid_pname;
1993
1994 *params = obj->Sampler.MinLod;
1995 break;
1996 case GL_TEXTURE_MAX_LOD:
1997 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1998 goto invalid_pname;
1999
2000 *params = obj->Sampler.MaxLod;
2001 break;
2002 case GL_TEXTURE_BASE_LEVEL:
2003 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2004 goto invalid_pname;
2005
2006 *params = (GLfloat) obj->BaseLevel;
2007 break;
2008 case GL_TEXTURE_MAX_LEVEL:
2009 *params = (GLfloat) obj->MaxLevel;
2010 break;
2011 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2012 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
2013 goto invalid_pname;
2014 *params = obj->Sampler.MaxAnisotropy;
2015 break;
2016 case GL_GENERATE_MIPMAP_SGIS:
2017 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
2018 goto invalid_pname;
2019
2020 *params = (GLfloat) obj->GenerateMipmap;
2021 break;
2022 case GL_TEXTURE_COMPARE_MODE_ARB:
2023 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2024 && !_mesa_is_gles3(ctx))
2025 goto invalid_pname;
2026 *params = (GLfloat) obj->Sampler.CompareMode;
2027 break;
2028 case GL_TEXTURE_COMPARE_FUNC_ARB:
2029 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2030 && !_mesa_is_gles3(ctx))
2031 goto invalid_pname;
2032 *params = (GLfloat) obj->Sampler.CompareFunc;
2033 break;
2034 case GL_DEPTH_TEXTURE_MODE_ARB:
2035 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
2036 * never existed in OpenGL ES.
2037 */
2038 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
2039 goto invalid_pname;
2040 *params = (GLfloat) obj->DepthMode;
2041 break;
2042 case GL_DEPTH_STENCIL_TEXTURE_MODE:
2043 if (!_mesa_has_ARB_stencil_texturing(ctx) && !_mesa_is_gles31(ctx))
2044 goto invalid_pname;
2045 *params = (GLfloat)
2046 (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
2047 break;
2048 case GL_TEXTURE_LOD_BIAS:
2049 if (_mesa_is_gles(ctx))
2050 goto invalid_pname;
2051
2052 *params = obj->Sampler.LodBias;
2053 break;
2054 case GL_TEXTURE_CROP_RECT_OES:
2055 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
2056 goto invalid_pname;
2057
2058 params[0] = (GLfloat) obj->CropRect[0];
2059 params[1] = (GLfloat) obj->CropRect[1];
2060 params[2] = (GLfloat) obj->CropRect[2];
2061 params[3] = (GLfloat) obj->CropRect[3];
2062 break;
2063
2064 case GL_TEXTURE_SWIZZLE_R_EXT:
2065 case GL_TEXTURE_SWIZZLE_G_EXT:
2066 case GL_TEXTURE_SWIZZLE_B_EXT:
2067 case GL_TEXTURE_SWIZZLE_A_EXT:
2068 if ((!_mesa_is_desktop_gl(ctx)
2069 || !ctx->Extensions.EXT_texture_swizzle)
2070 && !_mesa_is_gles3(ctx))
2071 goto invalid_pname;
2072 *params = (GLfloat) obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
2073 break;
2074
2075 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
2076 if ((!_mesa_is_desktop_gl(ctx)
2077 || !ctx->Extensions.EXT_texture_swizzle)
2078 && !_mesa_is_gles3(ctx)) {
2079 goto invalid_pname;
2080 }
2081 else {
2082 GLuint comp;
2083 for (comp = 0; comp < 4; comp++) {
2084 params[comp] = (GLfloat) obj->Swizzle[comp];
2085 }
2086 }
2087 break;
2088
2089 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
2090 if (!_mesa_is_desktop_gl(ctx)
2091 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
2092 goto invalid_pname;
2093 *params = (GLfloat) obj->Sampler.CubeMapSeamless;
2094 break;
2095
2096 case GL_TEXTURE_IMMUTABLE_FORMAT:
2097 *params = (GLfloat) obj->Immutable;
2098 break;
2099
2100 case GL_TEXTURE_IMMUTABLE_LEVELS:
2101 if (_mesa_is_gles3(ctx) || _mesa_has_texture_view(ctx))
2102 *params = (GLfloat) obj->ImmutableLevels;
2103 else
2104 goto invalid_pname;
2105 break;
2106
2107 case GL_TEXTURE_VIEW_MIN_LEVEL:
2108 if (!_mesa_has_texture_view(ctx))
2109 goto invalid_pname;
2110 *params = (GLfloat) obj->MinLevel;
2111 break;
2112
2113 case GL_TEXTURE_VIEW_NUM_LEVELS:
2114 if (!_mesa_has_texture_view(ctx))
2115 goto invalid_pname;
2116 *params = (GLfloat) obj->NumLevels;
2117 break;
2118
2119 case GL_TEXTURE_VIEW_MIN_LAYER:
2120 if (!_mesa_has_texture_view(ctx))
2121 goto invalid_pname;
2122 *params = (GLfloat) obj->MinLayer;
2123 break;
2124
2125 case GL_TEXTURE_VIEW_NUM_LAYERS:
2126 if (!_mesa_has_texture_view(ctx))
2127 goto invalid_pname;
2128 *params = (GLfloat) obj->NumLayers;
2129 break;
2130
2131 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
2132 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
2133 goto invalid_pname;
2134 *params = (GLfloat) obj->RequiredTextureImageUnits;
2135 break;
2136
2137 case GL_TEXTURE_SRGB_DECODE_EXT:
2138 if (!ctx->Extensions.EXT_texture_sRGB_decode)
2139 goto invalid_pname;
2140 *params = (GLfloat) obj->Sampler.sRGBDecode;
2141 break;
2142
2143 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
2144 if (!ctx->Extensions.ARB_shader_image_load_store)
2145 goto invalid_pname;
2146 *params = (GLfloat) obj->ImageFormatCompatibilityType;
2147 break;
2148
2149 case GL_TEXTURE_TARGET:
2150 if (ctx->API != API_OPENGL_CORE)
2151 goto invalid_pname;
2152 *params = ENUM_TO_FLOAT(obj->Target);
2153 break;
2154
2155 case GL_TEXTURE_TILING_EXT:
2156 if (!ctx->Extensions.EXT_memory_object)
2157 goto invalid_pname;
2158 *params = ENUM_TO_FLOAT(obj->TextureTiling);
2159 break;
2160
2161 default:
2162 goto invalid_pname;
2163 }
2164
2165 /* no error if we get here */
2166 _mesa_unlock_context_textures(ctx);
2167 return;
2168
2169 invalid_pname:
2170 _mesa_unlock_context_textures(ctx);
2171 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameterfv(pname=0x%x)",
2172 dsa ? "ture" : "", pname);
2173 }
2174
2175
2176 static void
2177 get_tex_parameteriv(struct gl_context *ctx,
2178 struct gl_texture_object *obj,
2179 GLenum pname, GLint *params, bool dsa)
2180 {
2181 _mesa_lock_texture(ctx, obj);
2182 switch (pname) {
2183 case GL_TEXTURE_MAG_FILTER:
2184 *params = (GLint) obj->Sampler.MagFilter;
2185 break;
2186 case GL_TEXTURE_MIN_FILTER:
2187 *params = (GLint) obj->Sampler.MinFilter;
2188 break;
2189 case GL_TEXTURE_WRAP_S:
2190 *params = (GLint) obj->Sampler.WrapS;
2191 break;
2192 case GL_TEXTURE_WRAP_T:
2193 *params = (GLint) obj->Sampler.WrapT;
2194 break;
2195 case GL_TEXTURE_WRAP_R:
2196 *params = (GLint) obj->Sampler.WrapR;
2197 break;
2198 case GL_TEXTURE_BORDER_COLOR:
2199 if (ctx->API == API_OPENGLES ||
2200 !ctx->Extensions.ARB_texture_border_clamp)
2201 goto invalid_pname;
2202
2203 {
2204 GLfloat b[4];
2205 b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
2206 b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
2207 b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
2208 b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
2209 params[0] = FLOAT_TO_INT(b[0]);
2210 params[1] = FLOAT_TO_INT(b[1]);
2211 params[2] = FLOAT_TO_INT(b[2]);
2212 params[3] = FLOAT_TO_INT(b[3]);
2213 }
2214 break;
2215 case GL_TEXTURE_RESIDENT:
2216 if (ctx->API != API_OPENGL_COMPAT)
2217 goto invalid_pname;
2218
2219 *params = 1;
2220 break;
2221 case GL_TEXTURE_PRIORITY:
2222 if (ctx->API != API_OPENGL_COMPAT)
2223 goto invalid_pname;
2224
2225 *params = FLOAT_TO_INT(obj->Priority);
2226 break;
2227 case GL_TEXTURE_MIN_LOD:
2228 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2229 goto invalid_pname;
2230 /* GL spec 'Data Conversions' section specifies that floating-point
2231 * value in integer Get function is rounded to nearest integer
2232 */
2233 *params = IROUND(obj->Sampler.MinLod);
2234 break;
2235 case GL_TEXTURE_MAX_LOD:
2236 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2237 goto invalid_pname;
2238 /* GL spec 'Data Conversions' section specifies that floating-point
2239 * value in integer Get function is rounded to nearest integer
2240 */
2241 *params = IROUND(obj->Sampler.MaxLod);
2242 break;
2243 case GL_TEXTURE_BASE_LEVEL:
2244 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2245 goto invalid_pname;
2246
2247 *params = obj->BaseLevel;
2248 break;
2249 case GL_TEXTURE_MAX_LEVEL:
2250 *params = obj->MaxLevel;
2251 break;
2252 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2253 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
2254 goto invalid_pname;
2255 /* GL spec 'Data Conversions' section specifies that floating-point
2256 * value in integer Get function is rounded to nearest integer
2257 */
2258 *params = IROUND(obj->Sampler.MaxAnisotropy);
2259 break;
2260 case GL_GENERATE_MIPMAP_SGIS:
2261 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
2262 goto invalid_pname;
2263
2264 *params = (GLint) obj->GenerateMipmap;
2265 break;
2266 case GL_TEXTURE_COMPARE_MODE_ARB:
2267 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2268 && !_mesa_is_gles3(ctx))
2269 goto invalid_pname;
2270 *params = (GLint) obj->Sampler.CompareMode;
2271 break;
2272 case GL_TEXTURE_COMPARE_FUNC_ARB:
2273 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2274 && !_mesa_is_gles3(ctx))
2275 goto invalid_pname;
2276 *params = (GLint) obj->Sampler.CompareFunc;
2277 break;
2278 case GL_DEPTH_TEXTURE_MODE_ARB:
2279 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
2280 goto invalid_pname;
2281 *params = (GLint) obj->DepthMode;
2282 break;
2283 case GL_DEPTH_STENCIL_TEXTURE_MODE:
2284 if (!_mesa_has_ARB_stencil_texturing(ctx) && !_mesa_is_gles31(ctx))
2285 goto invalid_pname;
2286 *params = (GLint)
2287 (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
2288 break;
2289 case GL_TEXTURE_LOD_BIAS:
2290 if (_mesa_is_gles(ctx))
2291 goto invalid_pname;
2292
2293 /* GL spec 'Data Conversions' section specifies that floating-point
2294 * value in integer Get function is rounded to nearest integer
2295 */
2296 *params = IROUND(obj->Sampler.LodBias);
2297 break;
2298 case GL_TEXTURE_CROP_RECT_OES:
2299 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
2300 goto invalid_pname;
2301
2302 params[0] = obj->CropRect[0];
2303 params[1] = obj->CropRect[1];
2304 params[2] = obj->CropRect[2];
2305 params[3] = obj->CropRect[3];
2306 break;
2307 case GL_TEXTURE_SWIZZLE_R_EXT:
2308 case GL_TEXTURE_SWIZZLE_G_EXT:
2309 case GL_TEXTURE_SWIZZLE_B_EXT:
2310 case GL_TEXTURE_SWIZZLE_A_EXT:
2311 if ((!_mesa_is_desktop_gl(ctx)
2312 || !ctx->Extensions.EXT_texture_swizzle)
2313 && !_mesa_is_gles3(ctx))
2314 goto invalid_pname;
2315 *params = obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
2316 break;
2317
2318 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
2319 if ((!_mesa_is_desktop_gl(ctx)
2320 || !ctx->Extensions.EXT_texture_swizzle)
2321 && !_mesa_is_gles3(ctx))
2322 goto invalid_pname;
2323 COPY_4V(params, obj->Swizzle);
2324 break;
2325
2326 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
2327 if (!_mesa_is_desktop_gl(ctx)
2328 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
2329 goto invalid_pname;
2330 *params = (GLint) obj->Sampler.CubeMapSeamless;
2331 break;
2332
2333 case GL_TEXTURE_IMMUTABLE_FORMAT:
2334 *params = (GLint) obj->Immutable;
2335 break;
2336
2337 case GL_TEXTURE_IMMUTABLE_LEVELS:
2338 if (_mesa_is_gles3(ctx) ||
2339 (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_view))
2340 *params = obj->ImmutableLevels;
2341 else
2342 goto invalid_pname;
2343 break;
2344
2345 case GL_TEXTURE_VIEW_MIN_LEVEL:
2346 if (!ctx->Extensions.ARB_texture_view)
2347 goto invalid_pname;
2348 *params = (GLint) obj->MinLevel;
2349 break;
2350
2351 case GL_TEXTURE_VIEW_NUM_LEVELS:
2352 if (!ctx->Extensions.ARB_texture_view)
2353 goto invalid_pname;
2354 *params = (GLint) obj->NumLevels;
2355 break;
2356
2357 case GL_TEXTURE_VIEW_MIN_LAYER:
2358 if (!ctx->Extensions.ARB_texture_view)
2359 goto invalid_pname;
2360 *params = (GLint) obj->MinLayer;
2361 break;
2362
2363 case GL_TEXTURE_VIEW_NUM_LAYERS:
2364 if (!ctx->Extensions.ARB_texture_view)
2365 goto invalid_pname;
2366 *params = (GLint) obj->NumLayers;
2367 break;
2368
2369 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
2370 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
2371 goto invalid_pname;
2372 *params = obj->RequiredTextureImageUnits;
2373 break;
2374
2375 case GL_TEXTURE_SRGB_DECODE_EXT:
2376 if (!ctx->Extensions.EXT_texture_sRGB_decode)
2377 goto invalid_pname;
2378 *params = obj->Sampler.sRGBDecode;
2379 break;
2380
2381 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
2382 if (!ctx->Extensions.ARB_shader_image_load_store)
2383 goto invalid_pname;
2384 *params = obj->ImageFormatCompatibilityType;
2385 break;
2386
2387 case GL_TEXTURE_TARGET:
2388 if (ctx->API != API_OPENGL_CORE)
2389 goto invalid_pname;
2390 *params = (GLint) obj->Target;
2391 break;
2392
2393 case GL_TEXTURE_TILING_EXT:
2394 if (!ctx->Extensions.EXT_memory_object)
2395 goto invalid_pname;
2396 *params = (GLint) obj->TextureTiling;
2397 break;
2398
2399 default:
2400 goto invalid_pname;
2401 }
2402
2403 /* no error if we get here */
2404 _mesa_unlock_texture(ctx, obj);
2405 return;
2406
2407 invalid_pname:
2408 _mesa_unlock_texture(ctx, obj);
2409 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameteriv(pname=0x%x)",
2410 dsa ? "ture" : "", pname);
2411 }
2412
2413 static void
2414 get_tex_parameterIiv(struct gl_context *ctx,
2415 struct gl_texture_object *obj,
2416 GLenum pname, GLint *params, bool dsa)
2417 {
2418 switch (pname) {
2419 case GL_TEXTURE_BORDER_COLOR:
2420 COPY_4V(params, obj->Sampler.BorderColor.i);
2421 break;
2422 default:
2423 get_tex_parameteriv(ctx, obj, pname, params, dsa);
2424 }
2425 }
2426
2427 void GLAPIENTRY
2428 _mesa_GetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
2429 {
2430 struct gl_texture_object *obj;
2431 GET_CURRENT_CONTEXT(ctx);
2432
2433 obj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2434 ctx->Texture.CurrentUnit,
2435 false,
2436 "glGetTexParameterfv");
2437 if (!obj)
2438 return;
2439
2440 get_tex_parameterfv(ctx, obj, pname, params, false);
2441 }
2442
2443 void GLAPIENTRY
2444 _mesa_GetTexParameteriv(GLenum target, GLenum pname, GLint *params)
2445 {
2446 struct gl_texture_object *obj;
2447 GET_CURRENT_CONTEXT(ctx);
2448
2449 obj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2450 ctx->Texture.CurrentUnit,
2451 false,
2452 "glGetTexParameteriv");
2453 if (!obj)
2454 return;
2455
2456 get_tex_parameteriv(ctx, obj, pname, params, false);
2457 }
2458
2459 /** New in GL 3.0 */
2460 void GLAPIENTRY
2461 _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
2462 {
2463 struct gl_texture_object *texObj;
2464 GET_CURRENT_CONTEXT(ctx);
2465
2466 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2467 ctx->Texture.CurrentUnit,
2468 false,
2469 "glGetTexParameterIiv");
2470 if (!texObj)
2471 return;
2472
2473 get_tex_parameterIiv(ctx, texObj, pname, params, false);
2474 }
2475
2476
2477 /** New in GL 3.0 */
2478 void GLAPIENTRY
2479 _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
2480 {
2481 struct gl_texture_object *texObj;
2482 GET_CURRENT_CONTEXT(ctx);
2483
2484 texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2485 ctx->Texture.CurrentUnit,
2486 false,
2487 "glGetTexParameterIuiv");
2488 if (!texObj)
2489 return;
2490
2491 get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, false);
2492 }
2493
2494 void GLAPIENTRY
2495 _mesa_GetTextureParameterfvEXT(GLuint texture, GLenum target, GLenum pname, GLfloat *params)
2496 {
2497 struct gl_texture_object *texObj;
2498 GET_CURRENT_CONTEXT(ctx);
2499
2500 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2501 "glGetTextureParameterfvEXT");
2502 if (!texObj)
2503 return;
2504
2505 if (!is_texparameteri_target_valid(texObj->Target)) {
2506 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTextureParameterfvEXT");
2507 return;
2508 }
2509
2510 get_tex_parameterfv(ctx, texObj, pname, params, true);
2511 }
2512
2513 void GLAPIENTRY
2514 _mesa_GetTextureParameterfv(GLuint texture, GLenum pname, GLfloat *params)
2515 {
2516 struct gl_texture_object *obj;
2517 GET_CURRENT_CONTEXT(ctx);
2518
2519 obj = get_texobj_by_name(ctx, texture, "glGetTextureParameterfv");
2520 if (!obj)
2521 return;
2522
2523 get_tex_parameterfv(ctx, obj, pname, params, true);
2524 }
2525
2526 void GLAPIENTRY
2527 _mesa_GetTextureParameterivEXT(GLuint texture, GLenum target, GLenum pname, GLint *params)
2528 {
2529 struct gl_texture_object *texObj;
2530 GET_CURRENT_CONTEXT(ctx);
2531
2532 texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2533 "glGetTextureParameterivEXT");
2534 if (!texObj)
2535 return;
2536
2537 if (!is_texparameteri_target_valid(texObj->Target)) {
2538 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTextureParameterivEXT");
2539 return;
2540 }
2541 get_tex_parameteriv(ctx, texObj, pname, params, true);
2542 }
2543
2544 void GLAPIENTRY
2545 _mesa_GetTextureParameteriv(GLuint texture, GLenum pname, GLint *params)
2546 {
2547 struct gl_texture_object *obj;
2548 GET_CURRENT_CONTEXT(ctx);
2549
2550 obj = get_texobj_by_name(ctx, texture, "glGetTextureParameteriv");
2551 if (!obj)
2552 return;
2553
2554 get_tex_parameteriv(ctx, obj, pname, params, true);
2555 }
2556
2557 void GLAPIENTRY
2558 _mesa_GetTextureParameterIiv(GLuint texture, GLenum pname, GLint *params)
2559 {
2560 struct gl_texture_object *texObj;
2561 GET_CURRENT_CONTEXT(ctx);
2562
2563 texObj = get_texobj_by_name(ctx, texture, "glGetTextureParameterIiv");
2564 if (!texObj)
2565 return;
2566
2567 get_tex_parameterIiv(ctx, texObj, pname, params, true);
2568 }
2569
2570
2571 void GLAPIENTRY
2572 _mesa_GetTextureParameterIuiv(GLuint texture, GLenum pname, GLuint *params)
2573 {
2574 struct gl_texture_object *texObj;
2575 GET_CURRENT_CONTEXT(ctx);
2576
2577 texObj = get_texobj_by_name(ctx, texture, "glGetTextureParameterIuiv");
2578 if (!texObj)
2579 return;
2580
2581 get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, true);
2582 }