[MESA]
[reactos.git] / reactos / dll / opengl / 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
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/image.h"
39 #include "main/macros.h"
40 #include "main/mfeatures.h"
41 #include "main/mtypes.h"
42 #include "main/state.h"
43 #include "main/texparam.h"
44 #include "main/teximage.h"
45 #include "main/texstate.h"
46
47
48 /**
49 * Check if a coordinate wrap mode is supported for the texture target.
50 * \return GL_TRUE if legal, GL_FALSE otherwise
51 */
52 static GLboolean
53 validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
54 {
55 switch (wrap) {
56 case GL_CLAMP:
57 case GL_REPEAT:
58 case GL_MIRRORED_REPEAT:
59 return GL_TRUE;
60 default:
61 break;
62 }
63
64 _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(param=0x%x)", wrap );
65 return GL_FALSE;
66 }
67
68
69 /**
70 * Get current texture object for given target.
71 * Return NULL if any error (and record the error).
72 * Note that this is different from _mesa_select_tex_object() in that proxy
73 * targets are not accepted.
74 * Only the glGetTexLevelParameter() functions accept proxy targets.
75 */
76 static struct gl_texture_object *
77 get_texobj(struct gl_context *ctx, GLenum target, GLboolean get)
78 {
79 struct gl_texture_unit *texUnit;
80
81 texUnit = &ctx->Texture.Unit;
82
83 switch (target) {
84 case GL_TEXTURE_1D:
85 return texUnit->CurrentTex[TEXTURE_1D_INDEX];
86 case GL_TEXTURE_2D:
87 return texUnit->CurrentTex[TEXTURE_2D_INDEX];
88 case GL_TEXTURE_3D:
89 return texUnit->CurrentTex[TEXTURE_3D_INDEX];
90 case GL_TEXTURE_CUBE_MAP:
91 if (ctx->Extensions.ARB_texture_cube_map) {
92 return texUnit->CurrentTex[TEXTURE_CUBE_INDEX];
93 }
94 break;
95 default:
96 ;
97 }
98
99 _mesa_error(ctx, GL_INVALID_ENUM,
100 "gl%sTexParameter(target)", get ? "Get" : "");
101 return NULL;
102 }
103
104
105 /**
106 * This is called just prior to changing any texture object state which
107 * will not effect texture completeness.
108 */
109 static inline void
110 flush(struct gl_context *ctx)
111 {
112 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
113 }
114
115
116 /**
117 * This is called just prior to changing any texture object state which
118 * can effect texture completeness (texture base level, max level,
119 * minification filter).
120 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
121 * state flag and then mark the texture object as 'incomplete' so that any
122 * per-texture derived state gets recomputed.
123 */
124 static inline void
125 incomplete(struct gl_context *ctx, struct gl_texture_object *texObj)
126 {
127 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
128 texObj->_Complete = GL_FALSE;
129 }
130
131
132 /**
133 * Set an integer-valued texture parameter
134 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
135 */
136 static GLboolean
137 set_tex_parameteri(struct gl_context *ctx,
138 struct gl_texture_object *texObj,
139 GLenum pname, const GLint *params)
140 {
141 switch (pname) {
142 case GL_TEXTURE_MIN_FILTER:
143 if (texObj->Sampler.MinFilter == params[0])
144 return GL_FALSE;
145 switch (params[0]) {
146 case GL_NEAREST:
147 case GL_LINEAR:
148 incomplete(ctx, texObj);
149 texObj->Sampler.MinFilter = params[0];
150 return GL_TRUE;
151 case GL_NEAREST_MIPMAP_NEAREST:
152 case GL_LINEAR_MIPMAP_NEAREST:
153 case GL_NEAREST_MIPMAP_LINEAR:
154 case GL_LINEAR_MIPMAP_LINEAR:
155 incomplete(ctx, texObj);
156 texObj->Sampler.MinFilter = params[0];
157 return GL_TRUE;
158 /* fall-through */
159 default:
160 goto invalid_param;
161 }
162 return GL_FALSE;
163
164 case GL_TEXTURE_MAG_FILTER:
165 if (texObj->Sampler.MagFilter == params[0])
166 return GL_FALSE;
167 switch (params[0]) {
168 case GL_NEAREST:
169 case GL_LINEAR:
170 flush(ctx); /* does not effect completeness */
171 texObj->Sampler.MagFilter = params[0];
172 return GL_TRUE;
173 default:
174 goto invalid_param;
175 }
176 return GL_FALSE;
177
178 case GL_TEXTURE_WRAP_S:
179 if (texObj->Sampler.WrapS == params[0])
180 return GL_FALSE;
181 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
182 flush(ctx);
183 texObj->Sampler.WrapS = params[0];
184 return GL_TRUE;
185 }
186 return GL_FALSE;
187
188 case GL_TEXTURE_WRAP_T:
189 if (texObj->Sampler.WrapT == params[0])
190 return GL_FALSE;
191 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
192 flush(ctx);
193 texObj->Sampler.WrapT = params[0];
194 return GL_TRUE;
195 }
196 return GL_FALSE;
197
198 case GL_TEXTURE_WRAP_R:
199 if (texObj->Sampler.WrapR == params[0])
200 return GL_FALSE;
201 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
202 flush(ctx);
203 texObj->Sampler.WrapR = params[0];
204 return GL_TRUE;
205 }
206 return GL_FALSE;
207
208 default:
209 goto invalid_pname;
210 }
211
212 invalid_pname:
213 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=%s)",
214 _mesa_lookup_enum_by_nr(pname));
215 return GL_FALSE;
216
217 invalid_param:
218 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(param=%s)",
219 _mesa_lookup_enum_by_nr(params[0]));
220 return GL_FALSE;
221 }
222
223
224 /**
225 * Set a float-valued texture parameter
226 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
227 */
228 static GLboolean
229 set_tex_parameterf(struct gl_context *ctx,
230 struct gl_texture_object *texObj,
231 GLenum pname, const GLfloat *params)
232 {
233 switch (pname) {
234
235 case GL_TEXTURE_PRIORITY:
236 flush(ctx);
237 texObj->Priority = CLAMP(params[0], 0.0F, 1.0F);
238 return GL_TRUE;
239
240 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
241 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
242 if (texObj->Sampler.MaxAnisotropy == params[0])
243 return GL_FALSE;
244 if (params[0] < 1.0) {
245 _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
246 return GL_FALSE;
247 }
248 flush(ctx);
249 /* clamp to max, that's what NVIDIA does */
250 texObj->Sampler.MaxAnisotropy = MIN2(params[0],
251 ctx->Const.MaxTextureMaxAnisotropy);
252 return GL_TRUE;
253 }
254 else {
255 static GLuint count = 0;
256 if (count++ < 10)
257 _mesa_error(ctx, GL_INVALID_ENUM,
258 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
259 }
260 return GL_FALSE;
261
262 case GL_TEXTURE_BORDER_COLOR:
263 flush(ctx);
264 /* ARB_texture_float disables clamping */
265 if (ctx->Extensions.ARB_texture_float) {
266 texObj->Sampler.BorderColor.f[RCOMP] = params[0];
267 texObj->Sampler.BorderColor.f[GCOMP] = params[1];
268 texObj->Sampler.BorderColor.f[BCOMP] = params[2];
269 texObj->Sampler.BorderColor.f[ACOMP] = params[3];
270 } else {
271 texObj->Sampler.BorderColor.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F);
272 texObj->Sampler.BorderColor.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F);
273 texObj->Sampler.BorderColor.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F);
274 texObj->Sampler.BorderColor.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F);
275 }
276 return GL_TRUE;
277
278 default:
279 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=0x%x)", pname);
280 }
281 return GL_FALSE;
282 }
283
284
285 void GLAPIENTRY
286 _mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
287 {
288 GLboolean need_update;
289 struct gl_texture_object *texObj;
290 GET_CURRENT_CONTEXT(ctx);
291 ASSERT_OUTSIDE_BEGIN_END(ctx);
292
293 texObj = get_texobj(ctx, target, GL_FALSE);
294 if (!texObj)
295 return;
296
297 switch (pname) {
298 case GL_TEXTURE_MIN_FILTER:
299 case GL_TEXTURE_MAG_FILTER:
300 case GL_TEXTURE_WRAP_S:
301 case GL_TEXTURE_WRAP_T:
302 case GL_TEXTURE_WRAP_R:
303 case GL_TEXTURE_COMPARE_MODE_ARB:
304 case GL_TEXTURE_COMPARE_FUNC_ARB:
305 case GL_DEPTH_TEXTURE_MODE_ARB:
306 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
307 {
308 /* convert float param to int */
309 GLint p[4];
310 p[0] = (GLint) param;
311 p[1] = p[2] = p[3] = 0;
312 need_update = set_tex_parameteri(ctx, texObj, pname, p);
313 }
314 break;
315 case GL_TEXTURE_SWIZZLE_R_EXT:
316 case GL_TEXTURE_SWIZZLE_G_EXT:
317 case GL_TEXTURE_SWIZZLE_B_EXT:
318 case GL_TEXTURE_SWIZZLE_A_EXT:
319 {
320 GLint p[4];
321 p[0] = (GLint) param;
322 p[1] = p[2] = p[3] = 0;
323 need_update = set_tex_parameteri(ctx, texObj, pname, p);
324 }
325 break;
326 default:
327 {
328 /* this will generate an error if pname is illegal */
329 GLfloat p[4];
330 p[0] = param;
331 p[1] = p[2] = p[3] = 0.0F;
332 need_update = set_tex_parameterf(ctx, texObj, pname, p);
333 }
334 }
335
336 if (ctx->Driver.TexParameter && need_update) {
337 ctx->Driver.TexParameter(ctx, target, texObj, pname, &param);
338 }
339 }
340
341
342 void GLAPIENTRY
343 _mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
344 {
345 GLboolean need_update;
346 struct gl_texture_object *texObj;
347 GET_CURRENT_CONTEXT(ctx);
348 ASSERT_OUTSIDE_BEGIN_END(ctx);
349
350 texObj = get_texobj(ctx, target, GL_FALSE);
351 if (!texObj)
352 return;
353
354 switch (pname) {
355 case GL_TEXTURE_MIN_FILTER:
356 case GL_TEXTURE_MAG_FILTER:
357 case GL_TEXTURE_WRAP_S:
358 case GL_TEXTURE_WRAP_T:
359 case GL_TEXTURE_WRAP_R:
360 case GL_TEXTURE_COMPARE_MODE_ARB:
361 case GL_TEXTURE_COMPARE_FUNC_ARB:
362 case GL_DEPTH_TEXTURE_MODE_ARB:
363 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
364 {
365 /* convert float param to int */
366 GLint p[4];
367 p[0] = (GLint) params[0];
368 p[1] = p[2] = p[3] = 0;
369 need_update = set_tex_parameteri(ctx, texObj, pname, p);
370 }
371 break;
372
373 case GL_TEXTURE_SWIZZLE_R_EXT:
374 case GL_TEXTURE_SWIZZLE_G_EXT:
375 case GL_TEXTURE_SWIZZLE_B_EXT:
376 case GL_TEXTURE_SWIZZLE_A_EXT:
377 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
378 {
379 GLint p[4] = {0, 0, 0, 0};
380 p[0] = (GLint) params[0];
381 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT) {
382 p[1] = (GLint) params[1];
383 p[2] = (GLint) params[2];
384 p[3] = (GLint) params[3];
385 }
386 need_update = set_tex_parameteri(ctx, texObj, pname, p);
387 }
388 break;
389 default:
390 /* this will generate an error if pname is illegal */
391 need_update = set_tex_parameterf(ctx, texObj, pname, params);
392 }
393
394 if (ctx->Driver.TexParameter && need_update) {
395 ctx->Driver.TexParameter(ctx, target, texObj, pname, params);
396 }
397 }
398
399
400 void GLAPIENTRY
401 _mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
402 {
403 GLboolean need_update;
404 struct gl_texture_object *texObj;
405 GET_CURRENT_CONTEXT(ctx);
406 ASSERT_OUTSIDE_BEGIN_END(ctx);
407
408 texObj = get_texobj(ctx, target, GL_FALSE);
409 if (!texObj)
410 return;
411
412 switch (pname) {
413 case GL_TEXTURE_MIN_LOD:
414 case GL_TEXTURE_MAX_LOD:
415 case GL_TEXTURE_PRIORITY:
416 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
417 case GL_TEXTURE_LOD_BIAS:
418 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
419 {
420 GLfloat fparam[4];
421 fparam[0] = (GLfloat) param;
422 fparam[1] = fparam[2] = fparam[3] = 0.0F;
423 /* convert int param to float */
424 need_update = set_tex_parameterf(ctx, texObj, pname, fparam);
425 }
426 break;
427 default:
428 /* this will generate an error if pname is illegal */
429 {
430 GLint iparam[4];
431 iparam[0] = param;
432 iparam[1] = iparam[2] = iparam[3] = 0;
433 need_update = set_tex_parameteri(ctx, texObj, pname, iparam);
434 }
435 }
436
437 if (ctx->Driver.TexParameter && need_update) {
438 GLfloat fparam = (GLfloat) param;
439 ctx->Driver.TexParameter(ctx, target, texObj, pname, &fparam);
440 }
441 }
442
443
444 void GLAPIENTRY
445 _mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
446 {
447 GLboolean need_update;
448 struct gl_texture_object *texObj;
449 GET_CURRENT_CONTEXT(ctx);
450 ASSERT_OUTSIDE_BEGIN_END(ctx);
451
452 texObj = get_texobj(ctx, target, GL_FALSE);
453 if (!texObj)
454 return;
455
456 switch (pname) {
457 case GL_TEXTURE_BORDER_COLOR:
458 {
459 /* convert int params to float */
460 GLfloat fparams[4];
461 fparams[0] = INT_TO_FLOAT(params[0]);
462 fparams[1] = INT_TO_FLOAT(params[1]);
463 fparams[2] = INT_TO_FLOAT(params[2]);
464 fparams[3] = INT_TO_FLOAT(params[3]);
465 need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
466 }
467 break;
468 case GL_TEXTURE_MIN_LOD:
469 case GL_TEXTURE_MAX_LOD:
470 case GL_TEXTURE_PRIORITY:
471 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
472 case GL_TEXTURE_LOD_BIAS:
473 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
474 {
475 /* convert int param to float */
476 GLfloat fparams[4];
477 fparams[0] = (GLfloat) params[0];
478 fparams[1] = fparams[2] = fparams[3] = 0.0F;
479 need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
480 }
481 break;
482 default:
483 /* this will generate an error if pname is illegal */
484 need_update = set_tex_parameteri(ctx, texObj, pname, params);
485 }
486
487 if (ctx->Driver.TexParameter && need_update) {
488 GLfloat fparams[4];
489 fparams[0] = INT_TO_FLOAT(params[0]);
490 if (pname == GL_TEXTURE_BORDER_COLOR ||
491 pname == GL_TEXTURE_CROP_RECT_OES) {
492 fparams[1] = INT_TO_FLOAT(params[1]);
493 fparams[2] = INT_TO_FLOAT(params[2]);
494 fparams[3] = INT_TO_FLOAT(params[3]);
495 }
496 ctx->Driver.TexParameter(ctx, target, texObj, pname, fparams);
497 }
498 }
499
500
501 /**
502 * Set tex parameter to integer value(s). Primarily intended to set
503 * integer-valued texture border color (for integer-valued textures).
504 * New in GL 3.0.
505 */
506 void GLAPIENTRY
507 _mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
508 {
509 struct gl_texture_object *texObj;
510 GET_CURRENT_CONTEXT(ctx);
511 ASSERT_OUTSIDE_BEGIN_END(ctx);
512
513 texObj = get_texobj(ctx, target, GL_FALSE);
514 if (!texObj)
515 return;
516
517 switch (pname) {
518 case GL_TEXTURE_BORDER_COLOR:
519 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
520 /* set the integer-valued border color */
521 COPY_4V(texObj->Sampler.BorderColor.i, params);
522 break;
523 default:
524 _mesa_TexParameteriv(target, pname, params);
525 break;
526 }
527 /* XXX no driver hook for TexParameterIiv() yet */
528 }
529
530
531 /**
532 * Set tex parameter to unsigned integer value(s). Primarily intended to set
533 * uint-valued texture border color (for integer-valued textures).
534 * New in GL 3.0
535 */
536 void GLAPIENTRY
537 _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
538 {
539 struct gl_texture_object *texObj;
540 GET_CURRENT_CONTEXT(ctx);
541 ASSERT_OUTSIDE_BEGIN_END(ctx);
542
543 texObj = get_texobj(ctx, target, GL_FALSE);
544 if (!texObj)
545 return;
546
547 switch (pname) {
548 case GL_TEXTURE_BORDER_COLOR:
549 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
550 /* set the unsigned integer-valued border color */
551 COPY_4V(texObj->Sampler.BorderColor.ui, params);
552 break;
553 default:
554 _mesa_TexParameteriv(target, pname, (const GLint *) params);
555 break;
556 }
557 /* XXX no driver hook for TexParameterIuiv() yet */
558 }
559
560
561 void GLAPIENTRY
562 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
563 GLenum pname, GLfloat *params )
564 {
565 GLint iparam;
566 _mesa_GetTexLevelParameteriv( target, level, pname, &iparam );
567 *params = (GLfloat) iparam;
568 }
569
570
571 void GLAPIENTRY
572 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
573 GLenum pname, GLint *params )
574 {
575 struct gl_texture_object *texObj;
576 const struct gl_texture_image *img = NULL;
577 GLint maxLevels;
578 gl_format texFormat;
579 GET_CURRENT_CONTEXT(ctx);
580 ASSERT_OUTSIDE_BEGIN_END(ctx);
581
582 /* this will catch bad target values */
583 maxLevels = _mesa_max_texture_levels(ctx, target);
584 if (maxLevels == 0) {
585 _mesa_error(ctx, GL_INVALID_ENUM,
586 "glGetTexLevelParameter[if]v(target=0x%x)", target);
587 return;
588 }
589
590 if (level < 0 || level >= maxLevels) {
591 _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
592 return;
593 }
594
595 texObj = _mesa_select_tex_object(ctx, target);
596
597 img = _mesa_select_tex_image(ctx, texObj, target, level);
598 if (!img || img->TexFormat == MESA_FORMAT_NONE) {
599 /* undefined texture image */
600 if (pname == GL_TEXTURE_COMPONENTS)
601 *params = 1;
602 else
603 *params = 0;
604 return;
605 }
606
607 texFormat = img->TexFormat;
608
609 switch (pname) {
610 case GL_TEXTURE_WIDTH:
611 *params = img->Width;
612 break;
613 case GL_TEXTURE_HEIGHT:
614 *params = img->Height;
615 break;
616 case GL_TEXTURE_DEPTH:
617 *params = img->Depth;
618 break;
619 case GL_TEXTURE_INTERNAL_FORMAT:
620 *params = img->InternalFormat;
621 break;
622 case GL_TEXTURE_BORDER:
623 *params = img->Border;
624 break;
625 case GL_TEXTURE_RED_SIZE:
626 case GL_TEXTURE_GREEN_SIZE:
627 case GL_TEXTURE_BLUE_SIZE:
628 case GL_TEXTURE_ALPHA_SIZE:
629 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
630 *params = _mesa_get_format_bits(texFormat, pname);
631 else
632 *params = 0;
633 break;
634 case GL_TEXTURE_INTENSITY_SIZE:
635 case GL_TEXTURE_LUMINANCE_SIZE:
636 if (_mesa_base_format_has_channel(img->_BaseFormat, pname)) {
637 *params = _mesa_get_format_bits(texFormat, pname);
638 if (*params == 0) {
639 /* intensity or luminance is probably stored as RGB[A] */
640 *params = MIN2(_mesa_get_format_bits(texFormat,
641 GL_TEXTURE_RED_SIZE),
642 _mesa_get_format_bits(texFormat,
643 GL_TEXTURE_GREEN_SIZE));
644 }
645 }
646 else {
647 *params = 0;
648 }
649 break;
650
651 /* GL_ARB_texture_float */
652 case GL_TEXTURE_RED_TYPE_ARB:
653 case GL_TEXTURE_GREEN_TYPE_ARB:
654 case GL_TEXTURE_BLUE_TYPE_ARB:
655 case GL_TEXTURE_ALPHA_TYPE_ARB:
656 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
657 case GL_TEXTURE_INTENSITY_TYPE_ARB:
658 case GL_TEXTURE_DEPTH_TYPE_ARB:
659 if (!ctx->Extensions.ARB_texture_float)
660 goto invalid_pname;
661 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
662 *params = _mesa_get_format_datatype(texFormat);
663 else
664 *params = GL_NONE;
665 break;
666
667 default:
668 goto invalid_pname;
669 }
670
671 /* no error if we get here */
672 return;
673
674 invalid_pname:
675 _mesa_error(ctx, GL_INVALID_ENUM,
676 "glGetTexLevelParameter[if]v(pname=%s)",
677 _mesa_lookup_enum_by_nr(pname));
678 }
679
680
681
682 void GLAPIENTRY
683 _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
684 {
685 struct gl_texture_object *obj;
686 GET_CURRENT_CONTEXT(ctx);
687 ASSERT_OUTSIDE_BEGIN_END(ctx);
688
689 obj = get_texobj(ctx, target, GL_TRUE);
690 if (!obj)
691 return;
692
693 _mesa_lock_texture(ctx, obj);
694 switch (pname) {
695 case GL_TEXTURE_MAG_FILTER:
696 *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
697 break;
698 case GL_TEXTURE_MIN_FILTER:
699 *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
700 break;
701 case GL_TEXTURE_WRAP_S:
702 *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
703 break;
704 case GL_TEXTURE_WRAP_T:
705 *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
706 break;
707 case GL_TEXTURE_WRAP_R:
708 *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
709 break;
710 case GL_TEXTURE_BORDER_COLOR:
711 if (ctx->NewState & _NEW_BUFFERS)
712 _mesa_update_state_locked(ctx);
713 params[0] = obj->Sampler.BorderColor.f[0];
714 params[1] = obj->Sampler.BorderColor.f[1];
715 params[2] = obj->Sampler.BorderColor.f[2];
716 params[3] = obj->Sampler.BorderColor.f[3];
717 break;
718 case GL_TEXTURE_RESIDENT:
719 *params = 1.0F;
720 break;
721 case GL_TEXTURE_PRIORITY:
722 *params = obj->Priority;
723 break;
724 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
725 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
726 goto invalid_pname;
727 *params = obj->Sampler.MaxAnisotropy;
728 break;
729
730 case GL_TEXTURE_IMMUTABLE_FORMAT:
731 if (!ctx->Extensions.ARB_texture_storage)
732 goto invalid_pname;
733 *params = (GLfloat) obj->Immutable;
734 break;
735
736 default:
737 goto invalid_pname;
738 }
739
740 /* no error if we get here */
741 _mesa_unlock_texture(ctx, obj);
742 return;
743
744 invalid_pname:
745 _mesa_unlock_texture(ctx, obj);
746 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname=0x%x)", pname);
747 }
748
749
750 void GLAPIENTRY
751 _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
752 {
753 struct gl_texture_object *obj;
754 GET_CURRENT_CONTEXT(ctx);
755 ASSERT_OUTSIDE_BEGIN_END(ctx);
756
757 obj = get_texobj(ctx, target, GL_TRUE);
758 if (!obj)
759 return;
760
761 _mesa_lock_texture(ctx, obj);
762 switch (pname) {
763 case GL_TEXTURE_MAG_FILTER:
764 *params = (GLint) obj->Sampler.MagFilter;
765 break;;
766 case GL_TEXTURE_MIN_FILTER:
767 *params = (GLint) obj->Sampler.MinFilter;
768 break;;
769 case GL_TEXTURE_WRAP_S:
770 *params = (GLint) obj->Sampler.WrapS;
771 break;;
772 case GL_TEXTURE_WRAP_T:
773 *params = (GLint) obj->Sampler.WrapT;
774 break;;
775 case GL_TEXTURE_WRAP_R:
776 *params = (GLint) obj->Sampler.WrapR;
777 break;;
778 case GL_TEXTURE_BORDER_COLOR:
779 {
780 GLfloat b[4];
781 b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
782 b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
783 b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
784 b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
785 params[0] = FLOAT_TO_INT(b[0]);
786 params[1] = FLOAT_TO_INT(b[1]);
787 params[2] = FLOAT_TO_INT(b[2]);
788 params[3] = FLOAT_TO_INT(b[3]);
789 }
790 break;;
791 case GL_TEXTURE_RESIDENT:
792 *params = 1;
793 break;;
794 case GL_TEXTURE_PRIORITY:
795 *params = FLOAT_TO_INT(obj->Priority);
796 break;
797 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
798 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
799 goto invalid_pname;
800 *params = (GLint) obj->Sampler.MaxAnisotropy;
801 break;
802
803 case GL_TEXTURE_IMMUTABLE_FORMAT:
804 if (!ctx->Extensions.ARB_texture_storage)
805 goto invalid_pname;
806 *params = (GLint) obj->Immutable;
807 break;
808
809 default:
810 goto invalid_pname;
811 }
812
813 /* no error if we get here */
814 _mesa_unlock_texture(ctx, obj);
815 return;
816
817 invalid_pname:
818 _mesa_unlock_texture(ctx, obj);
819 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname=0x%x)", pname);
820 }
821
822
823 /** New in GL 3.0 */
824 void GLAPIENTRY
825 _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
826 {
827 struct gl_texture_object *texObj;
828 GET_CURRENT_CONTEXT(ctx);
829 ASSERT_OUTSIDE_BEGIN_END(ctx);
830
831 texObj = get_texobj(ctx, target, GL_TRUE);
832 if (!texObj)
833 return;
834
835 switch (pname) {
836 case GL_TEXTURE_BORDER_COLOR:
837 COPY_4V(params, texObj->Sampler.BorderColor.i);
838 break;
839 default:
840 _mesa_GetTexParameteriv(target, pname, params);
841 }
842 }
843
844
845 /** New in GL 3.0 */
846 void GLAPIENTRY
847 _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
848 {
849 struct gl_texture_object *texObj;
850 GET_CURRENT_CONTEXT(ctx);
851 ASSERT_OUTSIDE_BEGIN_END(ctx);
852
853 texObj = get_texobj(ctx, target, GL_TRUE);
854 if (!texObj)
855 return;
856
857 switch (pname) {
858 case GL_TEXTURE_BORDER_COLOR:
859 COPY_4V(params, texObj->Sampler.BorderColor.i);
860 break;
861 default:
862 {
863 GLint ip[4];
864 _mesa_GetTexParameteriv(target, pname, ip);
865 params[0] = ip[0];
866 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT ||
867 pname == GL_TEXTURE_CROP_RECT_OES) {
868 params[1] = ip[1];
869 params[2] = ip[2];
870 params[3] = ip[3];
871 }
872 }
873 }
874 }