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