mesa: add missing case in _mesa_GetTexParameterfv()
[mesa.git] / src / mesa / main / texparam.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.5
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR 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/colormac.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/mfeatures.h"
41 #include "main/mtypes.h"
42 #include "main/state.h"
43 #include "main/texcompress.h"
44 #include "main/texobj.h"
45 #include "main/texparam.h"
46 #include "main/teximage.h"
47 #include "main/texstate.h"
48 #include "program/prog_instruction.h"
49
50
51 /**
52 * Check if a coordinate wrap mode is supported for the texture target.
53 * \return GL_TRUE if legal, GL_FALSE otherwise
54 */
55 static GLboolean
56 validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
57 {
58 const struct gl_extensions * const e = & ctx->Extensions;
59 const bool is_desktop_gl = _mesa_is_desktop_gl(ctx);
60 bool supported;
61
62 switch (wrap) {
63 case GL_CLAMP:
64 /* GL_CLAMP was removed in the core profile, and it has never existed in
65 * OpenGL ES.
66 */
67 supported = (ctx->API == API_OPENGL_COMPAT)
68 && (target != GL_TEXTURE_EXTERNAL_OES);
69 break;
70
71 case GL_CLAMP_TO_EDGE:
72 supported = true;
73 break;
74
75 case GL_CLAMP_TO_BORDER:
76 supported = is_desktop_gl && e->ARB_texture_border_clamp
77 && (target != GL_TEXTURE_EXTERNAL_OES);
78 break;
79
80 case GL_REPEAT:
81 case GL_MIRRORED_REPEAT:
82 supported = (target != GL_TEXTURE_RECTANGLE_NV)
83 && (target != GL_TEXTURE_EXTERNAL_OES);
84 break;
85
86 case GL_MIRROR_CLAMP_EXT:
87 case GL_MIRROR_CLAMP_TO_EDGE_EXT:
88 supported = is_desktop_gl
89 && (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)
90 && (target != GL_TEXTURE_RECTANGLE_NV)
91 && (target != GL_TEXTURE_EXTERNAL_OES);
92 break;
93
94 case GL_MIRROR_CLAMP_TO_BORDER_EXT:
95 supported = is_desktop_gl && e->EXT_texture_mirror_clamp
96 && (target != GL_TEXTURE_RECTANGLE_NV)
97 && (target != GL_TEXTURE_EXTERNAL_OES);
98 break;
99
100 default:
101 supported = false;
102 break;
103 }
104
105 if (!supported)
106 _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(param=0x%x)", wrap );
107
108 return supported;
109 }
110
111
112 /**
113 * Get current texture object for given target.
114 * Return NULL if any error (and record the error).
115 * Note that this is different from _mesa_select_tex_object() in that proxy
116 * targets are not accepted.
117 * Only the glGetTexLevelParameter() functions accept proxy targets.
118 */
119 static struct gl_texture_object *
120 get_texobj(struct gl_context *ctx, GLenum target, GLboolean get)
121 {
122 struct gl_texture_unit *texUnit;
123
124 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
125 _mesa_error(ctx, GL_INVALID_OPERATION,
126 "gl%sTexParameter(current unit)", get ? "Get" : "");
127 return NULL;
128 }
129
130 texUnit = _mesa_get_current_tex_unit(ctx);
131
132 switch (target) {
133 case GL_TEXTURE_1D:
134 if (_mesa_is_desktop_gl(ctx))
135 return texUnit->CurrentTex[TEXTURE_1D_INDEX];
136 break;
137 case GL_TEXTURE_2D:
138 return texUnit->CurrentTex[TEXTURE_2D_INDEX];
139 case GL_TEXTURE_3D:
140 if (ctx->API != API_OPENGLES)
141 return texUnit->CurrentTex[TEXTURE_3D_INDEX];
142 break;
143 case GL_TEXTURE_CUBE_MAP:
144 if (ctx->Extensions.ARB_texture_cube_map) {
145 return texUnit->CurrentTex[TEXTURE_CUBE_INDEX];
146 }
147 break;
148 case GL_TEXTURE_RECTANGLE_NV:
149 if (_mesa_is_desktop_gl(ctx)
150 && ctx->Extensions.NV_texture_rectangle) {
151 return texUnit->CurrentTex[TEXTURE_RECT_INDEX];
152 }
153 break;
154 case GL_TEXTURE_1D_ARRAY_EXT:
155 if (_mesa_is_desktop_gl(ctx)
156 && (ctx->Extensions.MESA_texture_array ||
157 ctx->Extensions.EXT_texture_array)) {
158 return texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX];
159 }
160 break;
161 case GL_TEXTURE_2D_ARRAY_EXT:
162 if ((_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx))
163 && (ctx->Extensions.MESA_texture_array ||
164 ctx->Extensions.EXT_texture_array)) {
165 return texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX];
166 }
167 break;
168 case GL_TEXTURE_EXTERNAL_OES:
169 if (_mesa_is_gles(ctx) && ctx->Extensions.OES_EGL_image_external) {
170 return texUnit->CurrentTex[TEXTURE_EXTERNAL_INDEX];
171 }
172 break;
173 case GL_TEXTURE_CUBE_MAP_ARRAY:
174 if (ctx->Extensions.ARB_texture_cube_map_array) {
175 return texUnit->CurrentTex[TEXTURE_CUBE_ARRAY_INDEX];
176 }
177 break;
178 default:
179 ;
180 }
181
182 _mesa_error(ctx, GL_INVALID_ENUM,
183 "gl%sTexParameter(target)", get ? "Get" : "");
184 return NULL;
185 }
186
187
188 /**
189 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
190 * \return -1 if error.
191 */
192 static GLint
193 comp_to_swizzle(GLenum comp)
194 {
195 switch (comp) {
196 case GL_RED:
197 return SWIZZLE_X;
198 case GL_GREEN:
199 return SWIZZLE_Y;
200 case GL_BLUE:
201 return SWIZZLE_Z;
202 case GL_ALPHA:
203 return SWIZZLE_W;
204 case GL_ZERO:
205 return SWIZZLE_ZERO;
206 case GL_ONE:
207 return SWIZZLE_ONE;
208 default:
209 return -1;
210 }
211 }
212
213
214 static void
215 set_swizzle_component(GLuint *swizzle, GLuint comp, GLuint swz)
216 {
217 ASSERT(comp < 4);
218 ASSERT(swz <= SWIZZLE_NIL);
219 {
220 GLuint mask = 0x7 << (3 * comp);
221 GLuint s = (*swizzle & ~mask) | (swz << (3 * comp));
222 *swizzle = s;
223 }
224 }
225
226
227 /**
228 * This is called just prior to changing any texture object state which
229 * will not effect texture completeness.
230 */
231 static inline void
232 flush(struct gl_context *ctx)
233 {
234 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
235 }
236
237
238 /**
239 * This is called just prior to changing any texture object state which
240 * can effect texture completeness (texture base level, max level).
241 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
242 * state flag and then mark the texture object as 'incomplete' so that any
243 * per-texture derived state gets recomputed.
244 */
245 static inline void
246 incomplete(struct gl_context *ctx, struct gl_texture_object *texObj)
247 {
248 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
249 _mesa_dirty_texobj(ctx, texObj, GL_TRUE);
250 }
251
252
253 /**
254 * Set an integer-valued texture parameter
255 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
256 */
257 static GLboolean
258 set_tex_parameteri(struct gl_context *ctx,
259 struct gl_texture_object *texObj,
260 GLenum pname, const GLint *params)
261 {
262 switch (pname) {
263 case GL_TEXTURE_MIN_FILTER:
264 if (texObj->Sampler.MinFilter == params[0])
265 return GL_FALSE;
266 switch (params[0]) {
267 case GL_NEAREST:
268 case GL_LINEAR:
269 flush(ctx);
270 texObj->Sampler.MinFilter = params[0];
271 return GL_TRUE;
272 case GL_NEAREST_MIPMAP_NEAREST:
273 case GL_LINEAR_MIPMAP_NEAREST:
274 case GL_NEAREST_MIPMAP_LINEAR:
275 case GL_LINEAR_MIPMAP_LINEAR:
276 if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
277 texObj->Target != GL_TEXTURE_EXTERNAL_OES) {
278 flush(ctx);
279 texObj->Sampler.MinFilter = params[0];
280 return GL_TRUE;
281 }
282 /* fall-through */
283 default:
284 goto invalid_param;
285 }
286 return GL_FALSE;
287
288 case GL_TEXTURE_MAG_FILTER:
289 if (texObj->Sampler.MagFilter == params[0])
290 return GL_FALSE;
291 switch (params[0]) {
292 case GL_NEAREST:
293 case GL_LINEAR:
294 flush(ctx); /* does not effect completeness */
295 texObj->Sampler.MagFilter = params[0];
296 return GL_TRUE;
297 default:
298 goto invalid_param;
299 }
300 return GL_FALSE;
301
302 case GL_TEXTURE_WRAP_S:
303 if (texObj->Sampler.WrapS == params[0])
304 return GL_FALSE;
305 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
306 flush(ctx);
307 texObj->Sampler.WrapS = params[0];
308 return GL_TRUE;
309 }
310 return GL_FALSE;
311
312 case GL_TEXTURE_WRAP_T:
313 if (texObj->Sampler.WrapT == params[0])
314 return GL_FALSE;
315 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
316 flush(ctx);
317 texObj->Sampler.WrapT = params[0];
318 return GL_TRUE;
319 }
320 return GL_FALSE;
321
322 case GL_TEXTURE_WRAP_R:
323 if (texObj->Sampler.WrapR == params[0])
324 return GL_FALSE;
325 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
326 flush(ctx);
327 texObj->Sampler.WrapR = params[0];
328 return GL_TRUE;
329 }
330 return GL_FALSE;
331
332 case GL_TEXTURE_BASE_LEVEL:
333 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
334 goto invalid_pname;
335
336 if (texObj->BaseLevel == params[0])
337 return GL_FALSE;
338 if (params[0] < 0 ||
339 (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] != 0)) {
340 _mesa_error(ctx, GL_INVALID_VALUE,
341 "glTexParameter(param=%d)", params[0]);
342 return GL_FALSE;
343 }
344 incomplete(ctx, texObj);
345 texObj->BaseLevel = params[0];
346 return GL_TRUE;
347
348 case GL_TEXTURE_MAX_LEVEL:
349 if (texObj->MaxLevel == params[0])
350 return GL_FALSE;
351 if (params[0] < 0 || texObj->Target == GL_TEXTURE_RECTANGLE_ARB) {
352 _mesa_error(ctx, GL_INVALID_VALUE,
353 "glTexParameter(param=%d)", params[0]);
354 return GL_FALSE;
355 }
356 incomplete(ctx, texObj);
357 texObj->MaxLevel = params[0];
358 return GL_TRUE;
359
360 case GL_GENERATE_MIPMAP_SGIS:
361 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
362 goto invalid_pname;
363
364 if (params[0] && texObj->Target == GL_TEXTURE_EXTERNAL_OES)
365 goto invalid_param;
366 if (texObj->GenerateMipmap != params[0]) {
367 /* no flush() */
368 texObj->GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
369 return GL_TRUE;
370 }
371 return GL_FALSE;
372
373 case GL_TEXTURE_COMPARE_MODE_ARB:
374 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow)
375 || _mesa_is_gles3(ctx)) {
376 if (texObj->Sampler.CompareMode == params[0])
377 return GL_FALSE;
378 if (params[0] == GL_NONE ||
379 params[0] == GL_COMPARE_R_TO_TEXTURE_ARB) {
380 flush(ctx);
381 texObj->Sampler.CompareMode = params[0];
382 return GL_TRUE;
383 }
384 goto invalid_param;
385 }
386 goto invalid_pname;
387
388 case GL_TEXTURE_COMPARE_FUNC_ARB:
389 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow)
390 || _mesa_is_gles3(ctx)) {
391 if (texObj->Sampler.CompareFunc == params[0])
392 return GL_FALSE;
393 switch (params[0]) {
394 case GL_LEQUAL:
395 case GL_GEQUAL:
396 flush(ctx);
397 texObj->Sampler.CompareFunc = params[0];
398 return GL_TRUE;
399 case GL_EQUAL:
400 case GL_NOTEQUAL:
401 case GL_LESS:
402 case GL_GREATER:
403 case GL_ALWAYS:
404 case GL_NEVER:
405 if (ctx->Extensions.EXT_shadow_funcs) {
406 flush(ctx);
407 texObj->Sampler.CompareFunc = params[0];
408 return GL_TRUE;
409 }
410 /* fall-through */
411 default:
412 goto invalid_param;
413 }
414 }
415 goto invalid_pname;
416
417 case GL_DEPTH_TEXTURE_MODE_ARB:
418 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
419 * existed in OpenGL ES.
420 */
421 if (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_depth_texture) {
422 if (texObj->DepthMode == params[0])
423 return GL_FALSE;
424 if (params[0] == GL_LUMINANCE ||
425 params[0] == GL_INTENSITY ||
426 params[0] == GL_ALPHA ||
427 (ctx->Extensions.ARB_texture_rg && params[0] == GL_RED)) {
428 flush(ctx);
429 texObj->DepthMode = params[0];
430 return GL_TRUE;
431 }
432 goto invalid_param;
433 }
434 goto invalid_pname;
435
436 case GL_TEXTURE_CROP_RECT_OES:
437 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
438 goto invalid_pname;
439
440 texObj->CropRect[0] = params[0];
441 texObj->CropRect[1] = params[1];
442 texObj->CropRect[2] = params[2];
443 texObj->CropRect[3] = params[3];
444 return GL_TRUE;
445
446 case GL_TEXTURE_SWIZZLE_R_EXT:
447 case GL_TEXTURE_SWIZZLE_G_EXT:
448 case GL_TEXTURE_SWIZZLE_B_EXT:
449 case GL_TEXTURE_SWIZZLE_A_EXT:
450 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_swizzle)
451 || _mesa_is_gles3(ctx)) {
452 const GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
453 const GLint swz = comp_to_swizzle(params[0]);
454 if (swz < 0) {
455 _mesa_error(ctx, GL_INVALID_OPERATION,
456 "glTexParameter(swizzle 0x%x)", params[0]);
457 return GL_FALSE;
458 }
459 ASSERT(comp < 4);
460
461 flush(ctx);
462 texObj->Swizzle[comp] = params[0];
463 set_swizzle_component(&texObj->_Swizzle, comp, swz);
464 return GL_TRUE;
465 }
466 goto invalid_pname;
467
468 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
469 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_swizzle)
470 || _mesa_is_gles3(ctx)) {
471 GLuint comp;
472 flush(ctx);
473 for (comp = 0; comp < 4; comp++) {
474 const GLint swz = comp_to_swizzle(params[comp]);
475 if (swz >= 0) {
476 texObj->Swizzle[comp] = params[comp];
477 set_swizzle_component(&texObj->_Swizzle, comp, swz);
478 }
479 else {
480 _mesa_error(ctx, GL_INVALID_OPERATION,
481 "glTexParameter(swizzle 0x%x)", params[comp]);
482 return GL_FALSE;
483 }
484 }
485 return GL_TRUE;
486 }
487 goto invalid_pname;
488
489 case GL_TEXTURE_SRGB_DECODE_EXT:
490 if (_mesa_is_desktop_gl(ctx)
491 && ctx->Extensions.EXT_texture_sRGB_decode) {
492 GLenum decode = params[0];
493 if (decode == GL_DECODE_EXT || decode == GL_SKIP_DECODE_EXT) {
494 if (texObj->Sampler.sRGBDecode != decode) {
495 flush(ctx);
496 texObj->Sampler.sRGBDecode = decode;
497 }
498 return GL_TRUE;
499 }
500 }
501 goto invalid_pname;
502
503 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
504 if (_mesa_is_desktop_gl(ctx)
505 && ctx->Extensions.AMD_seamless_cubemap_per_texture) {
506 GLenum param = params[0];
507 if (param != GL_TRUE && param != GL_FALSE) {
508 goto invalid_param;
509 }
510 if (param != texObj->Sampler.CubeMapSeamless) {
511 flush(ctx);
512 texObj->Sampler.CubeMapSeamless = param;
513 }
514 return GL_TRUE;
515 }
516 goto invalid_pname;
517
518 default:
519 goto invalid_pname;
520 }
521
522 invalid_pname:
523 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=%s)",
524 _mesa_lookup_enum_by_nr(pname));
525 return GL_FALSE;
526
527 invalid_param:
528 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(param=%s)",
529 _mesa_lookup_enum_by_nr(params[0]));
530 return GL_FALSE;
531 }
532
533
534 /**
535 * Set a float-valued texture parameter
536 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
537 */
538 static GLboolean
539 set_tex_parameterf(struct gl_context *ctx,
540 struct gl_texture_object *texObj,
541 GLenum pname, const GLfloat *params)
542 {
543 switch (pname) {
544 case GL_TEXTURE_MIN_LOD:
545 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
546 goto invalid_pname;
547
548 if (texObj->Sampler.MinLod == params[0])
549 return GL_FALSE;
550 flush(ctx);
551 texObj->Sampler.MinLod = params[0];
552 return GL_TRUE;
553
554 case GL_TEXTURE_MAX_LOD:
555 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
556 goto invalid_pname;
557
558 if (texObj->Sampler.MaxLod == params[0])
559 return GL_FALSE;
560 flush(ctx);
561 texObj->Sampler.MaxLod = params[0];
562 return GL_TRUE;
563
564 case GL_TEXTURE_PRIORITY:
565 if (ctx->API != API_OPENGL_COMPAT)
566 goto invalid_pname;
567
568 flush(ctx);
569 texObj->Priority = CLAMP(params[0], 0.0F, 1.0F);
570 return GL_TRUE;
571
572 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
573 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
574 if (texObj->Sampler.MaxAnisotropy == params[0])
575 return GL_FALSE;
576 if (params[0] < 1.0) {
577 _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
578 return GL_FALSE;
579 }
580 flush(ctx);
581 /* clamp to max, that's what NVIDIA does */
582 texObj->Sampler.MaxAnisotropy = MIN2(params[0],
583 ctx->Const.MaxTextureMaxAnisotropy);
584 return GL_TRUE;
585 }
586 else {
587 static GLuint count = 0;
588 if (count++ < 10)
589 goto invalid_pname;
590 }
591 return GL_FALSE;
592
593 case GL_TEXTURE_LOD_BIAS:
594 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias.
595 * It was removed in core-profile, and it has never existed in OpenGL
596 * ES.
597 */
598 if (ctx->API != API_OPENGL_COMPAT)
599 goto invalid_pname;
600
601 if (texObj->Sampler.LodBias != params[0]) {
602 flush(ctx);
603 texObj->Sampler.LodBias = params[0];
604 return GL_TRUE;
605 }
606 break;
607
608 case GL_TEXTURE_BORDER_COLOR:
609 if (!_mesa_is_desktop_gl(ctx))
610 goto invalid_pname;
611
612 flush(ctx);
613 /* ARB_texture_float disables clamping */
614 if (ctx->Extensions.ARB_texture_float) {
615 texObj->Sampler.BorderColor.f[RCOMP] = params[0];
616 texObj->Sampler.BorderColor.f[GCOMP] = params[1];
617 texObj->Sampler.BorderColor.f[BCOMP] = params[2];
618 texObj->Sampler.BorderColor.f[ACOMP] = params[3];
619 } else {
620 texObj->Sampler.BorderColor.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F);
621 texObj->Sampler.BorderColor.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F);
622 texObj->Sampler.BorderColor.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F);
623 texObj->Sampler.BorderColor.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F);
624 }
625 return GL_TRUE;
626
627 default:
628 goto invalid_pname;
629 }
630 return GL_FALSE;
631
632 invalid_pname:
633 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=%s)",
634 _mesa_lookup_enum_by_nr(pname));
635 return GL_FALSE;
636 }
637
638
639 void GLAPIENTRY
640 _mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
641 {
642 GLboolean need_update;
643 struct gl_texture_object *texObj;
644 GET_CURRENT_CONTEXT(ctx);
645
646 texObj = get_texobj(ctx, target, GL_FALSE);
647 if (!texObj)
648 return;
649
650 switch (pname) {
651 case GL_TEXTURE_MIN_FILTER:
652 case GL_TEXTURE_MAG_FILTER:
653 case GL_TEXTURE_WRAP_S:
654 case GL_TEXTURE_WRAP_T:
655 case GL_TEXTURE_WRAP_R:
656 case GL_TEXTURE_BASE_LEVEL:
657 case GL_TEXTURE_MAX_LEVEL:
658 case GL_GENERATE_MIPMAP_SGIS:
659 case GL_TEXTURE_COMPARE_MODE_ARB:
660 case GL_TEXTURE_COMPARE_FUNC_ARB:
661 case GL_DEPTH_TEXTURE_MODE_ARB:
662 case GL_TEXTURE_SRGB_DECODE_EXT:
663 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
664 case GL_TEXTURE_SWIZZLE_R_EXT:
665 case GL_TEXTURE_SWIZZLE_G_EXT:
666 case GL_TEXTURE_SWIZZLE_B_EXT:
667 case GL_TEXTURE_SWIZZLE_A_EXT:
668 {
669 GLint p[4];
670 p[0] = (param > 0) ?
671 ((param > INT_MAX) ? INT_MAX : (GLint) (param + 0.5)) :
672 ((param < INT_MIN) ? INT_MIN : (GLint) (param - 0.5));
673
674 p[1] = p[2] = p[3] = 0;
675 need_update = set_tex_parameteri(ctx, texObj, pname, p);
676 }
677 break;
678 default:
679 {
680 /* this will generate an error if pname is illegal */
681 GLfloat p[4];
682 p[0] = param;
683 p[1] = p[2] = p[3] = 0.0F;
684 need_update = set_tex_parameterf(ctx, texObj, pname, p);
685 }
686 }
687
688 if (ctx->Driver.TexParameter && need_update) {
689 ctx->Driver.TexParameter(ctx, target, texObj, pname, &param);
690 }
691 }
692
693
694 void GLAPIENTRY
695 _mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
696 {
697 GLboolean need_update;
698 struct gl_texture_object *texObj;
699 GET_CURRENT_CONTEXT(ctx);
700
701 texObj = get_texobj(ctx, target, GL_FALSE);
702 if (!texObj)
703 return;
704
705 switch (pname) {
706 case GL_TEXTURE_MIN_FILTER:
707 case GL_TEXTURE_MAG_FILTER:
708 case GL_TEXTURE_WRAP_S:
709 case GL_TEXTURE_WRAP_T:
710 case GL_TEXTURE_WRAP_R:
711 case GL_TEXTURE_BASE_LEVEL:
712 case GL_TEXTURE_MAX_LEVEL:
713 case GL_GENERATE_MIPMAP_SGIS:
714 case GL_TEXTURE_COMPARE_MODE_ARB:
715 case GL_TEXTURE_COMPARE_FUNC_ARB:
716 case GL_DEPTH_TEXTURE_MODE_ARB:
717 case GL_TEXTURE_SRGB_DECODE_EXT:
718 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
719 {
720 /* convert float param to int */
721 GLint p[4];
722 p[0] = (GLint) params[0];
723 p[1] = p[2] = p[3] = 0;
724 need_update = set_tex_parameteri(ctx, texObj, pname, p);
725 }
726 break;
727 case GL_TEXTURE_CROP_RECT_OES:
728 {
729 /* convert float params to int */
730 GLint iparams[4];
731 iparams[0] = (GLint) params[0];
732 iparams[1] = (GLint) params[1];
733 iparams[2] = (GLint) params[2];
734 iparams[3] = (GLint) params[3];
735 need_update = set_tex_parameteri(ctx, texObj, pname, iparams);
736 }
737 break;
738 case GL_TEXTURE_SWIZZLE_R_EXT:
739 case GL_TEXTURE_SWIZZLE_G_EXT:
740 case GL_TEXTURE_SWIZZLE_B_EXT:
741 case GL_TEXTURE_SWIZZLE_A_EXT:
742 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
743 {
744 GLint p[4] = {0, 0, 0, 0};
745 p[0] = (GLint) params[0];
746 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT) {
747 p[1] = (GLint) params[1];
748 p[2] = (GLint) params[2];
749 p[3] = (GLint) params[3];
750 }
751 need_update = set_tex_parameteri(ctx, texObj, pname, p);
752 }
753 break;
754 default:
755 /* this will generate an error if pname is illegal */
756 need_update = set_tex_parameterf(ctx, texObj, pname, params);
757 }
758
759 if (ctx->Driver.TexParameter && need_update) {
760 ctx->Driver.TexParameter(ctx, target, texObj, pname, params);
761 }
762 }
763
764
765 void GLAPIENTRY
766 _mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
767 {
768 GLboolean need_update;
769 struct gl_texture_object *texObj;
770 GET_CURRENT_CONTEXT(ctx);
771
772 texObj = get_texobj(ctx, target, GL_FALSE);
773 if (!texObj)
774 return;
775
776 switch (pname) {
777 case GL_TEXTURE_MIN_LOD:
778 case GL_TEXTURE_MAX_LOD:
779 case GL_TEXTURE_PRIORITY:
780 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
781 case GL_TEXTURE_LOD_BIAS:
782 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
783 {
784 GLfloat fparam[4];
785 fparam[0] = (GLfloat) param;
786 fparam[1] = fparam[2] = fparam[3] = 0.0F;
787 /* convert int param to float */
788 need_update = set_tex_parameterf(ctx, texObj, pname, fparam);
789 }
790 break;
791 default:
792 /* this will generate an error if pname is illegal */
793 {
794 GLint iparam[4];
795 iparam[0] = param;
796 iparam[1] = iparam[2] = iparam[3] = 0;
797 need_update = set_tex_parameteri(ctx, texObj, pname, iparam);
798 }
799 }
800
801 if (ctx->Driver.TexParameter && need_update) {
802 GLfloat fparam = (GLfloat) param;
803 ctx->Driver.TexParameter(ctx, target, texObj, pname, &fparam);
804 }
805 }
806
807
808 void GLAPIENTRY
809 _mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
810 {
811 GLboolean need_update;
812 struct gl_texture_object *texObj;
813 GET_CURRENT_CONTEXT(ctx);
814
815 texObj = get_texobj(ctx, target, GL_FALSE);
816 if (!texObj)
817 return;
818
819 switch (pname) {
820 case GL_TEXTURE_BORDER_COLOR:
821 {
822 /* convert int params to float */
823 GLfloat fparams[4];
824 fparams[0] = INT_TO_FLOAT(params[0]);
825 fparams[1] = INT_TO_FLOAT(params[1]);
826 fparams[2] = INT_TO_FLOAT(params[2]);
827 fparams[3] = INT_TO_FLOAT(params[3]);
828 need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
829 }
830 break;
831 case GL_TEXTURE_MIN_LOD:
832 case GL_TEXTURE_MAX_LOD:
833 case GL_TEXTURE_PRIORITY:
834 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
835 case GL_TEXTURE_LOD_BIAS:
836 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
837 {
838 /* convert int param to float */
839 GLfloat fparams[4];
840 fparams[0] = (GLfloat) params[0];
841 fparams[1] = fparams[2] = fparams[3] = 0.0F;
842 need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
843 }
844 break;
845 default:
846 /* this will generate an error if pname is illegal */
847 need_update = set_tex_parameteri(ctx, texObj, pname, params);
848 }
849
850 if (ctx->Driver.TexParameter && need_update) {
851 GLfloat fparams[4];
852 fparams[0] = INT_TO_FLOAT(params[0]);
853 if (pname == GL_TEXTURE_BORDER_COLOR ||
854 pname == GL_TEXTURE_CROP_RECT_OES) {
855 fparams[1] = INT_TO_FLOAT(params[1]);
856 fparams[2] = INT_TO_FLOAT(params[2]);
857 fparams[3] = INT_TO_FLOAT(params[3]);
858 }
859 ctx->Driver.TexParameter(ctx, target, texObj, pname, fparams);
860 }
861 }
862
863
864 /**
865 * Set tex parameter to integer value(s). Primarily intended to set
866 * integer-valued texture border color (for integer-valued textures).
867 * New in GL 3.0.
868 */
869 void GLAPIENTRY
870 _mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
871 {
872 struct gl_texture_object *texObj;
873 GET_CURRENT_CONTEXT(ctx);
874
875 texObj = get_texobj(ctx, target, GL_FALSE);
876 if (!texObj)
877 return;
878
879 switch (pname) {
880 case GL_TEXTURE_BORDER_COLOR:
881 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
882 /* set the integer-valued border color */
883 COPY_4V(texObj->Sampler.BorderColor.i, params);
884 break;
885 default:
886 _mesa_TexParameteriv(target, pname, params);
887 break;
888 }
889 /* XXX no driver hook for TexParameterIiv() yet */
890 }
891
892
893 /**
894 * Set tex parameter to unsigned integer value(s). Primarily intended to set
895 * uint-valued texture border color (for integer-valued textures).
896 * New in GL 3.0
897 */
898 void GLAPIENTRY
899 _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
900 {
901 struct gl_texture_object *texObj;
902 GET_CURRENT_CONTEXT(ctx);
903
904 texObj = get_texobj(ctx, target, GL_FALSE);
905 if (!texObj)
906 return;
907
908 switch (pname) {
909 case GL_TEXTURE_BORDER_COLOR:
910 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
911 /* set the unsigned integer-valued border color */
912 COPY_4V(texObj->Sampler.BorderColor.ui, params);
913 break;
914 default:
915 _mesa_TexParameteriv(target, pname, (const GLint *) params);
916 break;
917 }
918 /* XXX no driver hook for TexParameterIuiv() yet */
919 }
920
921
922 static GLboolean
923 legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target)
924 {
925 switch (target) {
926 case GL_TEXTURE_1D:
927 case GL_PROXY_TEXTURE_1D:
928 case GL_TEXTURE_2D:
929 case GL_PROXY_TEXTURE_2D:
930 case GL_TEXTURE_3D:
931 case GL_PROXY_TEXTURE_3D:
932 return GL_TRUE;
933 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
934 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
935 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
936 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
937 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
938 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
939 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
940 return ctx->Extensions.ARB_texture_cube_map;
941 case GL_TEXTURE_RECTANGLE_NV:
942 case GL_PROXY_TEXTURE_RECTANGLE_NV:
943 return ctx->Extensions.NV_texture_rectangle;
944 case GL_TEXTURE_1D_ARRAY_EXT:
945 case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
946 case GL_TEXTURE_2D_ARRAY_EXT:
947 case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
948 return (ctx->Extensions.MESA_texture_array ||
949 ctx->Extensions.EXT_texture_array);
950 case GL_TEXTURE_BUFFER:
951 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
952 * but not in earlier versions that expose ARB_texture_buffer_object.
953 *
954 * From the ARB_texture_buffer_object spec:
955 * "(7) Do buffer textures support texture parameters (TexParameter) or
956 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
957 *
958 * RESOLVED: No. [...] Note that the spec edits above don't add
959 * explicit error language for any of these cases. That is because
960 * each of the functions enumerate the set of valid <target>
961 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
962 * these cases means that target is not legal, and an INVALID_ENUM
963 * error should be generated."
964 *
965 * From the OpenGL 3.1 spec:
966 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
967 */
968 return ctx->API == API_OPENGL_CORE && ctx->Version >= 31;
969 default:
970 return GL_FALSE;
971 }
972 }
973
974
975 static void
976 get_tex_level_parameter_image(struct gl_context *ctx,
977 const struct gl_texture_object *texObj,
978 GLenum target, GLint level,
979 GLenum pname, GLint *params)
980 {
981 const struct gl_texture_image *img = NULL;
982 gl_format texFormat;
983
984 img = _mesa_select_tex_image(ctx, texObj, target, level);
985 if (!img || img->TexFormat == MESA_FORMAT_NONE) {
986 /* undefined texture image */
987 if (pname == GL_TEXTURE_COMPONENTS)
988 *params = 1;
989 else
990 *params = 0;
991 return;
992 }
993
994 texFormat = img->TexFormat;
995
996 switch (pname) {
997 case GL_TEXTURE_WIDTH:
998 *params = img->Width;
999 break;
1000 case GL_TEXTURE_HEIGHT:
1001 *params = img->Height;
1002 break;
1003 case GL_TEXTURE_DEPTH:
1004 *params = img->Depth;
1005 break;
1006 case GL_TEXTURE_INTERNAL_FORMAT:
1007 if (_mesa_is_format_compressed(texFormat)) {
1008 /* need to return the actual compressed format */
1009 *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
1010 }
1011 else {
1012 /* If the true internal format is not compressed but the user
1013 * requested a generic compressed format, we have to return the
1014 * generic base format that matches.
1015 *
1016 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1017 *
1018 * "If no specific compressed format is available,
1019 * internalformat is instead replaced by the corresponding base
1020 * internal format."
1021 *
1022 * Otherwise just return the user's requested internal format
1023 */
1024 const GLenum f =
1025 _mesa_gl_compressed_format_base_format(img->InternalFormat);
1026
1027 *params = (f != 0) ? f : img->InternalFormat;
1028 }
1029 break;
1030 case GL_TEXTURE_BORDER:
1031 *params = img->Border;
1032 break;
1033 case GL_TEXTURE_RED_SIZE:
1034 case GL_TEXTURE_GREEN_SIZE:
1035 case GL_TEXTURE_BLUE_SIZE:
1036 case GL_TEXTURE_ALPHA_SIZE:
1037 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1038 *params = _mesa_get_format_bits(texFormat, pname);
1039 else
1040 *params = 0;
1041 break;
1042 case GL_TEXTURE_INTENSITY_SIZE:
1043 case GL_TEXTURE_LUMINANCE_SIZE:
1044 if (_mesa_base_format_has_channel(img->_BaseFormat, pname)) {
1045 *params = _mesa_get_format_bits(texFormat, pname);
1046 if (*params == 0) {
1047 /* intensity or luminance is probably stored as RGB[A] */
1048 *params = MIN2(_mesa_get_format_bits(texFormat,
1049 GL_TEXTURE_RED_SIZE),
1050 _mesa_get_format_bits(texFormat,
1051 GL_TEXTURE_GREEN_SIZE));
1052 }
1053 }
1054 else {
1055 *params = 0;
1056 }
1057 break;
1058 case GL_TEXTURE_DEPTH_SIZE_ARB:
1059 if (!ctx->Extensions.ARB_depth_texture)
1060 goto invalid_pname;
1061 *params = _mesa_get_format_bits(texFormat, pname);
1062 break;
1063 case GL_TEXTURE_STENCIL_SIZE_EXT:
1064 if (!ctx->Extensions.EXT_packed_depth_stencil &&
1065 !ctx->Extensions.ARB_framebuffer_object)
1066 goto invalid_pname;
1067 *params = _mesa_get_format_bits(texFormat, pname);
1068 break;
1069 case GL_TEXTURE_SHARED_SIZE:
1070 if (ctx->Version < 30 &&
1071 !ctx->Extensions.EXT_texture_shared_exponent)
1072 goto invalid_pname;
1073 *params = texFormat == MESA_FORMAT_RGB9_E5_FLOAT ? 5 : 0;
1074 break;
1075
1076 /* GL_ARB_texture_compression */
1077 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1078 if (_mesa_is_format_compressed(texFormat) &&
1079 !_mesa_is_proxy_texture(target)) {
1080 *params = _mesa_format_image_size(texFormat, img->Width,
1081 img->Height, img->Depth);
1082 }
1083 else {
1084 _mesa_error(ctx, GL_INVALID_OPERATION,
1085 "glGetTexLevelParameter[if]v(pname)");
1086 }
1087 break;
1088 case GL_TEXTURE_COMPRESSED:
1089 *params = (GLint) _mesa_is_format_compressed(texFormat);
1090 break;
1091
1092 /* GL_ARB_texture_float */
1093 case GL_TEXTURE_RED_TYPE_ARB:
1094 case GL_TEXTURE_GREEN_TYPE_ARB:
1095 case GL_TEXTURE_BLUE_TYPE_ARB:
1096 case GL_TEXTURE_ALPHA_TYPE_ARB:
1097 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1098 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1099 case GL_TEXTURE_DEPTH_TYPE_ARB:
1100 if (!ctx->Extensions.ARB_texture_float)
1101 goto invalid_pname;
1102 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1103 *params = _mesa_get_format_datatype(texFormat);
1104 else
1105 *params = GL_NONE;
1106 break;
1107
1108 default:
1109 goto invalid_pname;
1110 }
1111
1112 /* no error if we get here */
1113 return;
1114
1115 invalid_pname:
1116 _mesa_error(ctx, GL_INVALID_ENUM,
1117 "glGetTexLevelParameter[if]v(pname=%s)",
1118 _mesa_lookup_enum_by_nr(pname));
1119 }
1120
1121
1122 static void
1123 get_tex_level_parameter_buffer(struct gl_context *ctx,
1124 const struct gl_texture_object *texObj,
1125 GLenum pname, GLint *params)
1126 {
1127 const struct gl_buffer_object *bo = texObj->BufferObject;
1128 gl_format texFormat = texObj->_BufferObjectFormat;
1129 GLenum internalFormat = texObj->BufferObjectFormat;
1130 GLenum baseFormat = _mesa_get_format_base_format(texFormat);
1131
1132 if (!bo) {
1133 /* undefined texture buffer object */
1134 *params = pname == GL_TEXTURE_COMPONENTS ? 1 : 0;
1135 return;
1136 }
1137
1138 switch (pname) {
1139 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
1140 *params = bo->Name;
1141 break;
1142 case GL_TEXTURE_WIDTH:
1143 *params = bo->Size;
1144 break;
1145 case GL_TEXTURE_HEIGHT:
1146 case GL_TEXTURE_DEPTH:
1147 case GL_TEXTURE_BORDER:
1148 case GL_TEXTURE_SHARED_SIZE:
1149 case GL_TEXTURE_COMPRESSED:
1150 *params = 0;
1151 break;
1152 case GL_TEXTURE_INTERNAL_FORMAT:
1153 *params = internalFormat;
1154 break;
1155 case GL_TEXTURE_RED_SIZE:
1156 case GL_TEXTURE_GREEN_SIZE:
1157 case GL_TEXTURE_BLUE_SIZE:
1158 case GL_TEXTURE_ALPHA_SIZE:
1159 if (_mesa_base_format_has_channel(baseFormat, pname))
1160 *params = _mesa_get_format_bits(texFormat, pname);
1161 else
1162 *params = 0;
1163 break;
1164 case GL_TEXTURE_INTENSITY_SIZE:
1165 case GL_TEXTURE_LUMINANCE_SIZE:
1166 if (_mesa_base_format_has_channel(baseFormat, pname)) {
1167 *params = _mesa_get_format_bits(texFormat, pname);
1168 if (*params == 0) {
1169 /* intensity or luminance is probably stored as RGB[A] */
1170 *params = MIN2(_mesa_get_format_bits(texFormat,
1171 GL_TEXTURE_RED_SIZE),
1172 _mesa_get_format_bits(texFormat,
1173 GL_TEXTURE_GREEN_SIZE));
1174 }
1175 } else {
1176 *params = 0;
1177 }
1178 break;
1179 case GL_TEXTURE_DEPTH_SIZE_ARB:
1180 case GL_TEXTURE_STENCIL_SIZE_EXT:
1181 *params = _mesa_get_format_bits(texFormat, pname);
1182 break;
1183
1184 /* GL_ARB_texture_buffer_range */
1185 case GL_TEXTURE_BUFFER_OFFSET:
1186 if (!ctx->Extensions.ARB_texture_buffer_range)
1187 goto invalid_pname;
1188 *params = texObj->BufferOffset;
1189 break;
1190 case GL_TEXTURE_BUFFER_SIZE:
1191 if (!ctx->Extensions.ARB_texture_buffer_range)
1192 goto invalid_pname;
1193 *params = (texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize;
1194 break;
1195
1196 /* GL_ARB_texture_compression */
1197 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1198 /* Always illegal for GL_TEXTURE_BUFFER */
1199 _mesa_error(ctx, GL_INVALID_OPERATION,
1200 "glGetTexLevelParameter[if]v(pname)");
1201 break;
1202
1203 /* GL_ARB_texture_float */
1204 case GL_TEXTURE_RED_TYPE_ARB:
1205 case GL_TEXTURE_GREEN_TYPE_ARB:
1206 case GL_TEXTURE_BLUE_TYPE_ARB:
1207 case GL_TEXTURE_ALPHA_TYPE_ARB:
1208 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1209 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1210 case GL_TEXTURE_DEPTH_TYPE_ARB:
1211 if (!ctx->Extensions.ARB_texture_float)
1212 goto invalid_pname;
1213 if (_mesa_base_format_has_channel(baseFormat, pname))
1214 *params = _mesa_get_format_datatype(texFormat);
1215 else
1216 *params = GL_NONE;
1217 break;
1218
1219 default:
1220 goto invalid_pname;
1221 }
1222
1223 /* no error if we get here */
1224 return;
1225
1226 invalid_pname:
1227 _mesa_error(ctx, GL_INVALID_ENUM,
1228 "glGetTexLevelParameter[if]v(pname=%s)",
1229 _mesa_lookup_enum_by_nr(pname));
1230 }
1231
1232
1233 void GLAPIENTRY
1234 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
1235 GLenum pname, GLfloat *params )
1236 {
1237 GLint iparam;
1238 _mesa_GetTexLevelParameteriv( target, level, pname, &iparam );
1239 *params = (GLfloat) iparam;
1240 }
1241
1242
1243 void GLAPIENTRY
1244 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
1245 GLenum pname, GLint *params )
1246 {
1247 const struct gl_texture_unit *texUnit;
1248 struct gl_texture_object *texObj;
1249 GLint maxLevels;
1250 GET_CURRENT_CONTEXT(ctx);
1251
1252 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
1253 _mesa_error(ctx, GL_INVALID_OPERATION,
1254 "glGetTexLevelParameteriv(current unit)");
1255 return;
1256 }
1257
1258 texUnit = _mesa_get_current_tex_unit(ctx);
1259
1260 if (!legal_get_tex_level_parameter_target(ctx, target)) {
1261 _mesa_error(ctx, GL_INVALID_ENUM,
1262 "glGetTexLevelParameter[if]v(target=0x%x)", target);
1263 return;
1264 }
1265
1266 maxLevels = _mesa_max_texture_levels(ctx, target);
1267 assert(maxLevels != 0);
1268
1269 if (level < 0 || level >= maxLevels) {
1270 _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
1271 return;
1272 }
1273
1274 texObj = _mesa_select_tex_object(ctx, texUnit, target);
1275
1276 if (target == GL_TEXTURE_BUFFER)
1277 get_tex_level_parameter_buffer(ctx, texObj, pname, params);
1278 else
1279 get_tex_level_parameter_image(ctx, texObj, target, level, pname, params);
1280 }
1281
1282
1283 void GLAPIENTRY
1284 _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
1285 {
1286 struct gl_texture_object *obj;
1287 GET_CURRENT_CONTEXT(ctx);
1288
1289 obj = get_texobj(ctx, target, GL_TRUE);
1290 if (!obj)
1291 return;
1292
1293 _mesa_lock_texture(ctx, obj);
1294 switch (pname) {
1295 case GL_TEXTURE_MAG_FILTER:
1296 *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
1297 break;
1298 case GL_TEXTURE_MIN_FILTER:
1299 *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
1300 break;
1301 case GL_TEXTURE_WRAP_S:
1302 *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
1303 break;
1304 case GL_TEXTURE_WRAP_T:
1305 *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
1306 break;
1307 case GL_TEXTURE_WRAP_R:
1308 *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
1309 break;
1310 case GL_TEXTURE_BORDER_COLOR:
1311 if (!_mesa_is_desktop_gl(ctx))
1312 goto invalid_pname;
1313
1314 if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
1315 _mesa_update_state_locked(ctx);
1316 if (ctx->Color._ClampFragmentColor) {
1317 params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1318 params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1319 params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1320 params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
1321 }
1322 else {
1323 params[0] = obj->Sampler.BorderColor.f[0];
1324 params[1] = obj->Sampler.BorderColor.f[1];
1325 params[2] = obj->Sampler.BorderColor.f[2];
1326 params[3] = obj->Sampler.BorderColor.f[3];
1327 }
1328 break;
1329 case GL_TEXTURE_RESIDENT:
1330 if (ctx->API != API_OPENGL_COMPAT)
1331 goto invalid_pname;
1332
1333 *params = 1.0F;
1334 break;
1335 case GL_TEXTURE_PRIORITY:
1336 if (ctx->API != API_OPENGL_COMPAT)
1337 goto invalid_pname;
1338
1339 *params = obj->Priority;
1340 break;
1341 case GL_TEXTURE_MIN_LOD:
1342 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1343 goto invalid_pname;
1344
1345 *params = obj->Sampler.MinLod;
1346 break;
1347 case GL_TEXTURE_MAX_LOD:
1348 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1349 goto invalid_pname;
1350
1351 *params = obj->Sampler.MaxLod;
1352 break;
1353 case GL_TEXTURE_BASE_LEVEL:
1354 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1355 goto invalid_pname;
1356
1357 *params = (GLfloat) obj->BaseLevel;
1358 break;
1359 case GL_TEXTURE_MAX_LEVEL:
1360 *params = (GLfloat) obj->MaxLevel;
1361 break;
1362 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1363 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
1364 goto invalid_pname;
1365 *params = obj->Sampler.MaxAnisotropy;
1366 break;
1367 case GL_GENERATE_MIPMAP_SGIS:
1368 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1369 goto invalid_pname;
1370
1371 *params = (GLfloat) obj->GenerateMipmap;
1372 break;
1373 case GL_TEXTURE_COMPARE_MODE_ARB:
1374 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
1375 && !_mesa_is_gles3(ctx))
1376 goto invalid_pname;
1377 *params = (GLfloat) obj->Sampler.CompareMode;
1378 break;
1379 case GL_TEXTURE_COMPARE_FUNC_ARB:
1380 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
1381 && !_mesa_is_gles3(ctx))
1382 goto invalid_pname;
1383 *params = (GLfloat) obj->Sampler.CompareFunc;
1384 break;
1385 case GL_DEPTH_TEXTURE_MODE_ARB:
1386 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1387 * never existed in OpenGL ES.
1388 */
1389 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
1390 goto invalid_pname;
1391 *params = (GLfloat) obj->DepthMode;
1392 break;
1393 case GL_TEXTURE_LOD_BIAS:
1394 if (ctx->API != API_OPENGL_COMPAT)
1395 goto invalid_pname;
1396
1397 *params = obj->Sampler.LodBias;
1398 break;
1399 case GL_TEXTURE_CROP_RECT_OES:
1400 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
1401 goto invalid_pname;
1402
1403 params[0] = (GLfloat) obj->CropRect[0];
1404 params[1] = (GLfloat) obj->CropRect[1];
1405 params[2] = (GLfloat) obj->CropRect[2];
1406 params[3] = (GLfloat) obj->CropRect[3];
1407 break;
1408
1409 case GL_TEXTURE_SWIZZLE_R_EXT:
1410 case GL_TEXTURE_SWIZZLE_G_EXT:
1411 case GL_TEXTURE_SWIZZLE_B_EXT:
1412 case GL_TEXTURE_SWIZZLE_A_EXT:
1413 if ((!_mesa_is_desktop_gl(ctx)
1414 || !ctx->Extensions.EXT_texture_swizzle)
1415 && !_mesa_is_gles3(ctx))
1416 goto invalid_pname;
1417 *params = (GLfloat) obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
1418 break;
1419
1420 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
1421 if ((!_mesa_is_desktop_gl(ctx)
1422 || !ctx->Extensions.EXT_texture_swizzle)
1423 && !_mesa_is_gles3(ctx)) {
1424 goto invalid_pname;
1425 }
1426 else {
1427 GLuint comp;
1428 for (comp = 0; comp < 4; comp++) {
1429 params[comp] = (GLfloat) obj->Swizzle[comp];
1430 }
1431 }
1432 break;
1433
1434 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1435 if (!_mesa_is_desktop_gl(ctx)
1436 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
1437 goto invalid_pname;
1438 *params = (GLfloat) obj->Sampler.CubeMapSeamless;
1439 break;
1440
1441 case GL_TEXTURE_IMMUTABLE_FORMAT:
1442 if (!ctx->Extensions.ARB_texture_storage)
1443 goto invalid_pname;
1444 *params = (GLfloat) obj->Immutable;
1445 break;
1446
1447 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
1448 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
1449 goto invalid_pname;
1450 *params = obj->RequiredTextureImageUnits;
1451 break;
1452
1453 case GL_TEXTURE_SRGB_DECODE_EXT:
1454 if (!ctx->Extensions.EXT_texture_sRGB_decode)
1455 goto invalid_pname;
1456 *params = (GLfloat) obj->Sampler.sRGBDecode;
1457 break;
1458
1459 default:
1460 goto invalid_pname;
1461 }
1462
1463 /* no error if we get here */
1464 _mesa_unlock_texture(ctx, obj);
1465 return;
1466
1467 invalid_pname:
1468 _mesa_unlock_texture(ctx, obj);
1469 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname=0x%x)", pname);
1470 }
1471
1472
1473 void GLAPIENTRY
1474 _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
1475 {
1476 struct gl_texture_object *obj;
1477 GET_CURRENT_CONTEXT(ctx);
1478
1479 obj = get_texobj(ctx, target, GL_TRUE);
1480 if (!obj)
1481 return;
1482
1483 _mesa_lock_texture(ctx, obj);
1484 switch (pname) {
1485 case GL_TEXTURE_MAG_FILTER:
1486 *params = (GLint) obj->Sampler.MagFilter;
1487 break;
1488 case GL_TEXTURE_MIN_FILTER:
1489 *params = (GLint) obj->Sampler.MinFilter;
1490 break;
1491 case GL_TEXTURE_WRAP_S:
1492 *params = (GLint) obj->Sampler.WrapS;
1493 break;
1494 case GL_TEXTURE_WRAP_T:
1495 *params = (GLint) obj->Sampler.WrapT;
1496 break;
1497 case GL_TEXTURE_WRAP_R:
1498 *params = (GLint) obj->Sampler.WrapR;
1499 break;
1500 case GL_TEXTURE_BORDER_COLOR:
1501 if (!_mesa_is_desktop_gl(ctx))
1502 goto invalid_pname;
1503
1504 {
1505 GLfloat b[4];
1506 b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1507 b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1508 b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1509 b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
1510 params[0] = FLOAT_TO_INT(b[0]);
1511 params[1] = FLOAT_TO_INT(b[1]);
1512 params[2] = FLOAT_TO_INT(b[2]);
1513 params[3] = FLOAT_TO_INT(b[3]);
1514 }
1515 break;
1516 case GL_TEXTURE_RESIDENT:
1517 if (ctx->API != API_OPENGL_COMPAT)
1518 goto invalid_pname;
1519
1520 *params = 1;
1521 break;
1522 case GL_TEXTURE_PRIORITY:
1523 if (ctx->API != API_OPENGL_COMPAT)
1524 goto invalid_pname;
1525
1526 *params = FLOAT_TO_INT(obj->Priority);
1527 break;
1528 case GL_TEXTURE_MIN_LOD:
1529 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1530 goto invalid_pname;
1531
1532 *params = (GLint) obj->Sampler.MinLod;
1533 break;
1534 case GL_TEXTURE_MAX_LOD:
1535 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1536 goto invalid_pname;
1537
1538 *params = (GLint) obj->Sampler.MaxLod;
1539 break;
1540 case GL_TEXTURE_BASE_LEVEL:
1541 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1542 goto invalid_pname;
1543
1544 *params = obj->BaseLevel;
1545 break;
1546 case GL_TEXTURE_MAX_LEVEL:
1547 *params = obj->MaxLevel;
1548 break;
1549 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1550 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
1551 goto invalid_pname;
1552 *params = (GLint) obj->Sampler.MaxAnisotropy;
1553 break;
1554 case GL_GENERATE_MIPMAP_SGIS:
1555 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1556 goto invalid_pname;
1557
1558 *params = (GLint) obj->GenerateMipmap;
1559 break;
1560 case GL_TEXTURE_COMPARE_MODE_ARB:
1561 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
1562 && !_mesa_is_gles3(ctx))
1563 goto invalid_pname;
1564 *params = (GLint) obj->Sampler.CompareMode;
1565 break;
1566 case GL_TEXTURE_COMPARE_FUNC_ARB:
1567 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
1568 && !_mesa_is_gles3(ctx))
1569 goto invalid_pname;
1570 *params = (GLint) obj->Sampler.CompareFunc;
1571 break;
1572 case GL_DEPTH_TEXTURE_MODE_ARB:
1573 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
1574 goto invalid_pname;
1575 *params = (GLint) obj->DepthMode;
1576 break;
1577 case GL_TEXTURE_LOD_BIAS:
1578 if (ctx->API != API_OPENGL_COMPAT)
1579 goto invalid_pname;
1580
1581 *params = (GLint) obj->Sampler.LodBias;
1582 break;
1583 case GL_TEXTURE_CROP_RECT_OES:
1584 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
1585 goto invalid_pname;
1586
1587 params[0] = obj->CropRect[0];
1588 params[1] = obj->CropRect[1];
1589 params[2] = obj->CropRect[2];
1590 params[3] = obj->CropRect[3];
1591 break;
1592 case GL_TEXTURE_SWIZZLE_R_EXT:
1593 case GL_TEXTURE_SWIZZLE_G_EXT:
1594 case GL_TEXTURE_SWIZZLE_B_EXT:
1595 case GL_TEXTURE_SWIZZLE_A_EXT:
1596 if ((!_mesa_is_desktop_gl(ctx)
1597 || !ctx->Extensions.EXT_texture_swizzle)
1598 && !_mesa_is_gles3(ctx))
1599 goto invalid_pname;
1600 *params = obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
1601 break;
1602
1603 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
1604 if ((!_mesa_is_desktop_gl(ctx)
1605 || !ctx->Extensions.EXT_texture_swizzle)
1606 && !_mesa_is_gles3(ctx))
1607 goto invalid_pname;
1608 COPY_4V(params, obj->Swizzle);
1609 break;
1610
1611 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1612 if (!_mesa_is_desktop_gl(ctx)
1613 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
1614 goto invalid_pname;
1615 *params = (GLint) obj->Sampler.CubeMapSeamless;
1616 break;
1617
1618 case GL_TEXTURE_IMMUTABLE_FORMAT:
1619 if (!ctx->Extensions.ARB_texture_storage)
1620 goto invalid_pname;
1621 *params = (GLint) obj->Immutable;
1622 break;
1623
1624 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
1625 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
1626 goto invalid_pname;
1627 *params = obj->RequiredTextureImageUnits;
1628 break;
1629
1630 case GL_TEXTURE_SRGB_DECODE_EXT:
1631 if (!ctx->Extensions.EXT_texture_sRGB_decode)
1632 goto invalid_pname;
1633 *params = obj->Sampler.sRGBDecode;
1634 break;
1635
1636 default:
1637 goto invalid_pname;
1638 }
1639
1640 /* no error if we get here */
1641 _mesa_unlock_texture(ctx, obj);
1642 return;
1643
1644 invalid_pname:
1645 _mesa_unlock_texture(ctx, obj);
1646 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname=0x%x)", pname);
1647 }
1648
1649
1650 /** New in GL 3.0 */
1651 void GLAPIENTRY
1652 _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
1653 {
1654 struct gl_texture_object *texObj;
1655 GET_CURRENT_CONTEXT(ctx);
1656
1657 texObj = get_texobj(ctx, target, GL_TRUE);
1658 if (!texObj)
1659 return;
1660
1661 switch (pname) {
1662 case GL_TEXTURE_BORDER_COLOR:
1663 COPY_4V(params, texObj->Sampler.BorderColor.i);
1664 break;
1665 default:
1666 _mesa_GetTexParameteriv(target, pname, params);
1667 }
1668 }
1669
1670
1671 /** New in GL 3.0 */
1672 void GLAPIENTRY
1673 _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
1674 {
1675 struct gl_texture_object *texObj;
1676 GET_CURRENT_CONTEXT(ctx);
1677
1678 texObj = get_texobj(ctx, target, GL_TRUE);
1679 if (!texObj)
1680 return;
1681
1682 switch (pname) {
1683 case GL_TEXTURE_BORDER_COLOR:
1684 COPY_4V(params, texObj->Sampler.BorderColor.i);
1685 break;
1686 default:
1687 {
1688 GLint ip[4];
1689 _mesa_GetTexParameteriv(target, pname, ip);
1690 params[0] = ip[0];
1691 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT ||
1692 pname == GL_TEXTURE_CROP_RECT_OES) {
1693 params[1] = ip[1];
1694 params[2] = ip[2];
1695 params[3] = ip[3];
1696 }
1697 }
1698 }
1699 }