[MESA]
[reactos.git] / reactos / dll / opengl / mesa / 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
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/texcompress.h"
44 #include "main/texparam.h"
45 #include "main/teximage.h"
46 #include "main/texstate.h"
47 #include "program/prog_instruction.h"
48
49
50 /**
51 * Check if a coordinate wrap mode is supported for the texture target.
52 * \return GL_TRUE if legal, GL_FALSE otherwise
53 */
54 static GLboolean
55 validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
56 {
57 const struct gl_extensions * const e = & ctx->Extensions;
58
59 if (target == GL_TEXTURE_RECTANGLE_NV) {
60 if (wrap == GL_CLAMP || wrap == GL_CLAMP_TO_EDGE ||
61 (wrap == GL_CLAMP_TO_BORDER && e->ARB_texture_border_clamp))
62 return GL_TRUE;
63 }
64 else if (target == GL_TEXTURE_EXTERNAL_OES) {
65 if (wrap == GL_CLAMP_TO_EDGE)
66 return GL_TRUE;
67 }
68 else {
69 switch (wrap) {
70 case GL_CLAMP:
71 case GL_REPEAT:
72 case GL_CLAMP_TO_EDGE:
73 case GL_MIRRORED_REPEAT:
74 return GL_TRUE;
75 case GL_CLAMP_TO_BORDER:
76 if (e->ARB_texture_border_clamp)
77 return GL_TRUE;
78 break;
79 case GL_MIRROR_CLAMP_EXT:
80 case GL_MIRROR_CLAMP_TO_EDGE_EXT:
81 if (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)
82 return GL_TRUE;
83 break;
84 case GL_MIRROR_CLAMP_TO_BORDER_EXT:
85 if (e->EXT_texture_mirror_clamp)
86 return GL_TRUE;
87 break;
88 default:
89 break;
90 }
91 }
92
93 _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(param=0x%x)", wrap );
94 return GL_FALSE;
95 }
96
97
98 /**
99 * Get current texture object for given target.
100 * Return NULL if any error (and record the error).
101 * Note that this is different from _mesa_select_tex_object() in that proxy
102 * targets are not accepted.
103 * Only the glGetTexLevelParameter() functions accept proxy targets.
104 */
105 static struct gl_texture_object *
106 get_texobj(struct gl_context *ctx, GLenum target, GLboolean get)
107 {
108 struct gl_texture_unit *texUnit;
109
110 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
111 _mesa_error(ctx, GL_INVALID_OPERATION,
112 "gl%sTexParameter(current unit)", get ? "Get" : "");
113 return NULL;
114 }
115
116 texUnit = _mesa_get_current_tex_unit(ctx);
117
118 switch (target) {
119 case GL_TEXTURE_1D:
120 return texUnit->CurrentTex[TEXTURE_1D_INDEX];
121 case GL_TEXTURE_2D:
122 return texUnit->CurrentTex[TEXTURE_2D_INDEX];
123 case GL_TEXTURE_3D:
124 return texUnit->CurrentTex[TEXTURE_3D_INDEX];
125 case GL_TEXTURE_CUBE_MAP:
126 if (ctx->Extensions.ARB_texture_cube_map) {
127 return texUnit->CurrentTex[TEXTURE_CUBE_INDEX];
128 }
129 break;
130 case GL_TEXTURE_RECTANGLE_NV:
131 if (ctx->Extensions.NV_texture_rectangle) {
132 return texUnit->CurrentTex[TEXTURE_RECT_INDEX];
133 }
134 break;
135 case GL_TEXTURE_1D_ARRAY_EXT:
136 if (ctx->Extensions.MESA_texture_array ||
137 ctx->Extensions.EXT_texture_array) {
138 return texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX];
139 }
140 break;
141 case GL_TEXTURE_2D_ARRAY_EXT:
142 if (ctx->Extensions.MESA_texture_array ||
143 ctx->Extensions.EXT_texture_array) {
144 return texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX];
145 }
146 break;
147 case GL_TEXTURE_EXTERNAL_OES:
148 if (ctx->Extensions.OES_EGL_image_external) {
149 return texUnit->CurrentTex[TEXTURE_EXTERNAL_INDEX];
150 }
151 break;
152 default:
153 ;
154 }
155
156 _mesa_error(ctx, GL_INVALID_ENUM,
157 "gl%sTexParameter(target)", get ? "Get" : "");
158 return NULL;
159 }
160
161
162 /**
163 * This is called just prior to changing any texture object state which
164 * will not effect texture completeness.
165 */
166 static inline void
167 flush(struct gl_context *ctx)
168 {
169 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
170 }
171
172
173 /**
174 * This is called just prior to changing any texture object state which
175 * can effect texture completeness (texture base level, max level,
176 * minification filter).
177 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
178 * state flag and then mark the texture object as 'incomplete' so that any
179 * per-texture derived state gets recomputed.
180 */
181 static inline void
182 incomplete(struct gl_context *ctx, struct gl_texture_object *texObj)
183 {
184 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
185 texObj->_Complete = GL_FALSE;
186 }
187
188
189 /**
190 * Set an integer-valued texture parameter
191 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
192 */
193 static GLboolean
194 set_tex_parameteri(struct gl_context *ctx,
195 struct gl_texture_object *texObj,
196 GLenum pname, const GLint *params)
197 {
198 switch (pname) {
199 case GL_TEXTURE_MIN_FILTER:
200 if (texObj->Sampler.MinFilter == params[0])
201 return GL_FALSE;
202 switch (params[0]) {
203 case GL_NEAREST:
204 case GL_LINEAR:
205 incomplete(ctx, texObj);
206 texObj->Sampler.MinFilter = params[0];
207 return GL_TRUE;
208 case GL_NEAREST_MIPMAP_NEAREST:
209 case GL_LINEAR_MIPMAP_NEAREST:
210 case GL_NEAREST_MIPMAP_LINEAR:
211 case GL_LINEAR_MIPMAP_LINEAR:
212 if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
213 texObj->Target != GL_TEXTURE_EXTERNAL_OES) {
214 incomplete(ctx, texObj);
215 texObj->Sampler.MinFilter = params[0];
216 return GL_TRUE;
217 }
218 /* fall-through */
219 default:
220 goto invalid_param;
221 }
222 return GL_FALSE;
223
224 case GL_TEXTURE_MAG_FILTER:
225 if (texObj->Sampler.MagFilter == params[0])
226 return GL_FALSE;
227 switch (params[0]) {
228 case GL_NEAREST:
229 case GL_LINEAR:
230 flush(ctx); /* does not effect completeness */
231 texObj->Sampler.MagFilter = params[0];
232 return GL_TRUE;
233 default:
234 goto invalid_param;
235 }
236 return GL_FALSE;
237
238 case GL_TEXTURE_WRAP_S:
239 if (texObj->Sampler.WrapS == params[0])
240 return GL_FALSE;
241 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
242 flush(ctx);
243 texObj->Sampler.WrapS = params[0];
244 return GL_TRUE;
245 }
246 return GL_FALSE;
247
248 case GL_TEXTURE_WRAP_T:
249 if (texObj->Sampler.WrapT == params[0])
250 return GL_FALSE;
251 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
252 flush(ctx);
253 texObj->Sampler.WrapT = params[0];
254 return GL_TRUE;
255 }
256 return GL_FALSE;
257
258 case GL_TEXTURE_WRAP_R:
259 if (texObj->Sampler.WrapR == params[0])
260 return GL_FALSE;
261 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
262 flush(ctx);
263 texObj->Sampler.WrapR = params[0];
264 return GL_TRUE;
265 }
266 return GL_FALSE;
267
268 case GL_TEXTURE_BASE_LEVEL:
269 if (texObj->BaseLevel == params[0])
270 return GL_FALSE;
271 if (params[0] < 0 ||
272 (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] != 0)) {
273 _mesa_error(ctx, GL_INVALID_VALUE,
274 "glTexParameter(param=%d)", params[0]);
275 return GL_FALSE;
276 }
277 incomplete(ctx, texObj);
278 texObj->BaseLevel = params[0];
279 return GL_TRUE;
280
281 case GL_TEXTURE_MAX_LEVEL:
282 if (texObj->MaxLevel == params[0])
283 return GL_FALSE;
284 if (params[0] < 0 || texObj->Target == GL_TEXTURE_RECTANGLE_ARB) {
285 _mesa_error(ctx, GL_INVALID_OPERATION,
286 "glTexParameter(param=%d)", params[0]);
287 return GL_FALSE;
288 }
289 incomplete(ctx, texObj);
290 texObj->MaxLevel = params[0];
291 return GL_TRUE;
292
293 case GL_GENERATE_MIPMAP_SGIS:
294 if (params[0] && texObj->Target == GL_TEXTURE_EXTERNAL_OES)
295 goto invalid_param;
296 if (texObj->GenerateMipmap != params[0]) {
297 /* no flush() */
298 texObj->GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
299 return GL_TRUE;
300 }
301 return GL_FALSE;
302
303 #if FEATURE_OES_draw_texture
304 case GL_TEXTURE_CROP_RECT_OES:
305 texObj->CropRect[0] = params[0];
306 texObj->CropRect[1] = params[1];
307 texObj->CropRect[2] = params[2];
308 texObj->CropRect[3] = params[3];
309 return GL_TRUE;
310 #endif
311
312 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
313 if (ctx->Extensions.AMD_seamless_cubemap_per_texture) {
314 GLenum param = params[0];
315 if (param != GL_TRUE && param != GL_FALSE) {
316 goto invalid_param;
317 }
318 if (param != texObj->Sampler.CubeMapSeamless) {
319 flush(ctx);
320 texObj->Sampler.CubeMapSeamless = param;
321 }
322 return GL_TRUE;
323 }
324 goto invalid_pname;
325
326 default:
327 goto invalid_pname;
328 }
329
330 invalid_pname:
331 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=%s)",
332 _mesa_lookup_enum_by_nr(pname));
333 return GL_FALSE;
334
335 invalid_param:
336 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(param=%s)",
337 _mesa_lookup_enum_by_nr(params[0]));
338 return GL_FALSE;
339 }
340
341
342 /**
343 * Set a float-valued texture parameter
344 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
345 */
346 static GLboolean
347 set_tex_parameterf(struct gl_context *ctx,
348 struct gl_texture_object *texObj,
349 GLenum pname, const GLfloat *params)
350 {
351 switch (pname) {
352 case GL_TEXTURE_MIN_LOD:
353 if (texObj->Sampler.MinLod == params[0])
354 return GL_FALSE;
355 flush(ctx);
356 texObj->Sampler.MinLod = params[0];
357 return GL_TRUE;
358
359 case GL_TEXTURE_MAX_LOD:
360 if (texObj->Sampler.MaxLod == params[0])
361 return GL_FALSE;
362 flush(ctx);
363 texObj->Sampler.MaxLod = params[0];
364 return GL_TRUE;
365
366 case GL_TEXTURE_PRIORITY:
367 flush(ctx);
368 texObj->Priority = CLAMP(params[0], 0.0F, 1.0F);
369 return GL_TRUE;
370
371 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
372 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
373 if (texObj->Sampler.MaxAnisotropy == params[0])
374 return GL_FALSE;
375 if (params[0] < 1.0) {
376 _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
377 return GL_FALSE;
378 }
379 flush(ctx);
380 /* clamp to max, that's what NVIDIA does */
381 texObj->Sampler.MaxAnisotropy = MIN2(params[0],
382 ctx->Const.MaxTextureMaxAnisotropy);
383 return GL_TRUE;
384 }
385 else {
386 static GLuint count = 0;
387 if (count++ < 10)
388 _mesa_error(ctx, GL_INVALID_ENUM,
389 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
390 }
391 return GL_FALSE;
392
393 case GL_TEXTURE_LOD_BIAS:
394 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
395 if (texObj->Sampler.LodBias != params[0]) {
396 flush(ctx);
397 texObj->Sampler.LodBias = params[0];
398 return GL_TRUE;
399 }
400 break;
401
402 case GL_TEXTURE_BORDER_COLOR:
403 flush(ctx);
404 /* ARB_texture_float disables clamping */
405 if (ctx->Extensions.ARB_texture_float) {
406 texObj->Sampler.BorderColor.f[RCOMP] = params[0];
407 texObj->Sampler.BorderColor.f[GCOMP] = params[1];
408 texObj->Sampler.BorderColor.f[BCOMP] = params[2];
409 texObj->Sampler.BorderColor.f[ACOMP] = params[3];
410 } else {
411 texObj->Sampler.BorderColor.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F);
412 texObj->Sampler.BorderColor.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F);
413 texObj->Sampler.BorderColor.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F);
414 texObj->Sampler.BorderColor.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F);
415 }
416 return GL_TRUE;
417
418 default:
419 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=0x%x)", pname);
420 }
421 return GL_FALSE;
422 }
423
424
425 void GLAPIENTRY
426 _mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
427 {
428 GLboolean need_update;
429 struct gl_texture_object *texObj;
430 GET_CURRENT_CONTEXT(ctx);
431 ASSERT_OUTSIDE_BEGIN_END(ctx);
432
433 texObj = get_texobj(ctx, target, GL_FALSE);
434 if (!texObj)
435 return;
436
437 switch (pname) {
438 case GL_TEXTURE_MIN_FILTER:
439 case GL_TEXTURE_MAG_FILTER:
440 case GL_TEXTURE_WRAP_S:
441 case GL_TEXTURE_WRAP_T:
442 case GL_TEXTURE_WRAP_R:
443 case GL_TEXTURE_BASE_LEVEL:
444 case GL_TEXTURE_MAX_LEVEL:
445 case GL_GENERATE_MIPMAP_SGIS:
446 case GL_TEXTURE_COMPARE_MODE_ARB:
447 case GL_TEXTURE_COMPARE_FUNC_ARB:
448 case GL_DEPTH_TEXTURE_MODE_ARB:
449 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
450 {
451 /* convert float param to int */
452 GLint p[4];
453 p[0] = (GLint) param;
454 p[1] = p[2] = p[3] = 0;
455 need_update = set_tex_parameteri(ctx, texObj, pname, p);
456 }
457 break;
458 case GL_TEXTURE_SWIZZLE_R_EXT:
459 case GL_TEXTURE_SWIZZLE_G_EXT:
460 case GL_TEXTURE_SWIZZLE_B_EXT:
461 case GL_TEXTURE_SWIZZLE_A_EXT:
462 {
463 GLint p[4];
464 p[0] = (GLint) param;
465 p[1] = p[2] = p[3] = 0;
466 need_update = set_tex_parameteri(ctx, texObj, pname, p);
467 }
468 break;
469 default:
470 {
471 /* this will generate an error if pname is illegal */
472 GLfloat p[4];
473 p[0] = param;
474 p[1] = p[2] = p[3] = 0.0F;
475 need_update = set_tex_parameterf(ctx, texObj, pname, p);
476 }
477 }
478
479 if (ctx->Driver.TexParameter && need_update) {
480 ctx->Driver.TexParameter(ctx, target, texObj, pname, &param);
481 }
482 }
483
484
485 void GLAPIENTRY
486 _mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
487 {
488 GLboolean need_update;
489 struct gl_texture_object *texObj;
490 GET_CURRENT_CONTEXT(ctx);
491 ASSERT_OUTSIDE_BEGIN_END(ctx);
492
493 texObj = get_texobj(ctx, target, GL_FALSE);
494 if (!texObj)
495 return;
496
497 switch (pname) {
498 case GL_TEXTURE_MIN_FILTER:
499 case GL_TEXTURE_MAG_FILTER:
500 case GL_TEXTURE_WRAP_S:
501 case GL_TEXTURE_WRAP_T:
502 case GL_TEXTURE_WRAP_R:
503 case GL_TEXTURE_BASE_LEVEL:
504 case GL_TEXTURE_MAX_LEVEL:
505 case GL_GENERATE_MIPMAP_SGIS:
506 case GL_TEXTURE_COMPARE_MODE_ARB:
507 case GL_TEXTURE_COMPARE_FUNC_ARB:
508 case GL_DEPTH_TEXTURE_MODE_ARB:
509 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
510 {
511 /* convert float param to int */
512 GLint p[4];
513 p[0] = (GLint) params[0];
514 p[1] = p[2] = p[3] = 0;
515 need_update = set_tex_parameteri(ctx, texObj, pname, p);
516 }
517 break;
518
519 #if FEATURE_OES_draw_texture
520 case GL_TEXTURE_CROP_RECT_OES:
521 {
522 /* convert float params to int */
523 GLint iparams[4];
524 iparams[0] = (GLint) params[0];
525 iparams[1] = (GLint) params[1];
526 iparams[2] = (GLint) params[2];
527 iparams[3] = (GLint) params[3];
528 need_update = set_tex_parameteri(ctx, texObj, pname, iparams);
529 }
530 break;
531 #endif
532
533 case GL_TEXTURE_SWIZZLE_R_EXT:
534 case GL_TEXTURE_SWIZZLE_G_EXT:
535 case GL_TEXTURE_SWIZZLE_B_EXT:
536 case GL_TEXTURE_SWIZZLE_A_EXT:
537 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
538 {
539 GLint p[4] = {0, 0, 0, 0};
540 p[0] = (GLint) params[0];
541 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT) {
542 p[1] = (GLint) params[1];
543 p[2] = (GLint) params[2];
544 p[3] = (GLint) params[3];
545 }
546 need_update = set_tex_parameteri(ctx, texObj, pname, p);
547 }
548 break;
549 default:
550 /* this will generate an error if pname is illegal */
551 need_update = set_tex_parameterf(ctx, texObj, pname, params);
552 }
553
554 if (ctx->Driver.TexParameter && need_update) {
555 ctx->Driver.TexParameter(ctx, target, texObj, pname, params);
556 }
557 }
558
559
560 void GLAPIENTRY
561 _mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
562 {
563 GLboolean need_update;
564 struct gl_texture_object *texObj;
565 GET_CURRENT_CONTEXT(ctx);
566 ASSERT_OUTSIDE_BEGIN_END(ctx);
567
568 texObj = get_texobj(ctx, target, GL_FALSE);
569 if (!texObj)
570 return;
571
572 switch (pname) {
573 case GL_TEXTURE_MIN_LOD:
574 case GL_TEXTURE_MAX_LOD:
575 case GL_TEXTURE_PRIORITY:
576 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
577 case GL_TEXTURE_LOD_BIAS:
578 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
579 {
580 GLfloat fparam[4];
581 fparam[0] = (GLfloat) param;
582 fparam[1] = fparam[2] = fparam[3] = 0.0F;
583 /* convert int param to float */
584 need_update = set_tex_parameterf(ctx, texObj, pname, fparam);
585 }
586 break;
587 default:
588 /* this will generate an error if pname is illegal */
589 {
590 GLint iparam[4];
591 iparam[0] = param;
592 iparam[1] = iparam[2] = iparam[3] = 0;
593 need_update = set_tex_parameteri(ctx, texObj, pname, iparam);
594 }
595 }
596
597 if (ctx->Driver.TexParameter && need_update) {
598 GLfloat fparam = (GLfloat) param;
599 ctx->Driver.TexParameter(ctx, target, texObj, pname, &fparam);
600 }
601 }
602
603
604 void GLAPIENTRY
605 _mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
606 {
607 GLboolean need_update;
608 struct gl_texture_object *texObj;
609 GET_CURRENT_CONTEXT(ctx);
610 ASSERT_OUTSIDE_BEGIN_END(ctx);
611
612 texObj = get_texobj(ctx, target, GL_FALSE);
613 if (!texObj)
614 return;
615
616 switch (pname) {
617 case GL_TEXTURE_BORDER_COLOR:
618 {
619 /* convert int params to float */
620 GLfloat fparams[4];
621 fparams[0] = INT_TO_FLOAT(params[0]);
622 fparams[1] = INT_TO_FLOAT(params[1]);
623 fparams[2] = INT_TO_FLOAT(params[2]);
624 fparams[3] = INT_TO_FLOAT(params[3]);
625 need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
626 }
627 break;
628 case GL_TEXTURE_MIN_LOD:
629 case GL_TEXTURE_MAX_LOD:
630 case GL_TEXTURE_PRIORITY:
631 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
632 case GL_TEXTURE_LOD_BIAS:
633 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
634 {
635 /* convert int param to float */
636 GLfloat fparams[4];
637 fparams[0] = (GLfloat) params[0];
638 fparams[1] = fparams[2] = fparams[3] = 0.0F;
639 need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
640 }
641 break;
642 default:
643 /* this will generate an error if pname is illegal */
644 need_update = set_tex_parameteri(ctx, texObj, pname, params);
645 }
646
647 if (ctx->Driver.TexParameter && need_update) {
648 GLfloat fparams[4];
649 fparams[0] = INT_TO_FLOAT(params[0]);
650 if (pname == GL_TEXTURE_BORDER_COLOR ||
651 pname == GL_TEXTURE_CROP_RECT_OES) {
652 fparams[1] = INT_TO_FLOAT(params[1]);
653 fparams[2] = INT_TO_FLOAT(params[2]);
654 fparams[3] = INT_TO_FLOAT(params[3]);
655 }
656 ctx->Driver.TexParameter(ctx, target, texObj, pname, fparams);
657 }
658 }
659
660
661 /**
662 * Set tex parameter to integer value(s). Primarily intended to set
663 * integer-valued texture border color (for integer-valued textures).
664 * New in GL 3.0.
665 */
666 void GLAPIENTRY
667 _mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
668 {
669 struct gl_texture_object *texObj;
670 GET_CURRENT_CONTEXT(ctx);
671 ASSERT_OUTSIDE_BEGIN_END(ctx);
672
673 texObj = get_texobj(ctx, target, GL_FALSE);
674 if (!texObj)
675 return;
676
677 switch (pname) {
678 case GL_TEXTURE_BORDER_COLOR:
679 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
680 /* set the integer-valued border color */
681 COPY_4V(texObj->Sampler.BorderColor.i, params);
682 break;
683 default:
684 _mesa_TexParameteriv(target, pname, params);
685 break;
686 }
687 /* XXX no driver hook for TexParameterIiv() yet */
688 }
689
690
691 /**
692 * Set tex parameter to unsigned integer value(s). Primarily intended to set
693 * uint-valued texture border color (for integer-valued textures).
694 * New in GL 3.0
695 */
696 void GLAPIENTRY
697 _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
698 {
699 struct gl_texture_object *texObj;
700 GET_CURRENT_CONTEXT(ctx);
701 ASSERT_OUTSIDE_BEGIN_END(ctx);
702
703 texObj = get_texobj(ctx, target, GL_FALSE);
704 if (!texObj)
705 return;
706
707 switch (pname) {
708 case GL_TEXTURE_BORDER_COLOR:
709 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
710 /* set the unsigned integer-valued border color */
711 COPY_4V(texObj->Sampler.BorderColor.ui, params);
712 break;
713 default:
714 _mesa_TexParameteriv(target, pname, (const GLint *) params);
715 break;
716 }
717 /* XXX no driver hook for TexParameterIuiv() yet */
718 }
719
720
721 void GLAPIENTRY
722 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
723 GLenum pname, GLfloat *params )
724 {
725 GLint iparam;
726 _mesa_GetTexLevelParameteriv( target, level, pname, &iparam );
727 *params = (GLfloat) iparam;
728 }
729
730
731 void GLAPIENTRY
732 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
733 GLenum pname, GLint *params )
734 {
735 const struct gl_texture_unit *texUnit;
736 struct gl_texture_object *texObj;
737 const struct gl_texture_image *img = NULL;
738 GLint maxLevels;
739 gl_format texFormat;
740 GET_CURRENT_CONTEXT(ctx);
741 ASSERT_OUTSIDE_BEGIN_END(ctx);
742
743 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
744 _mesa_error(ctx, GL_INVALID_OPERATION,
745 "glGetTexLevelParameteriv(current unit)");
746 return;
747 }
748
749 texUnit = _mesa_get_current_tex_unit(ctx);
750
751 /* this will catch bad target values */
752 maxLevels = _mesa_max_texture_levels(ctx, target);
753 if (maxLevels == 0) {
754 _mesa_error(ctx, GL_INVALID_ENUM,
755 "glGetTexLevelParameter[if]v(target=0x%x)", target);
756 return;
757 }
758
759 if (level < 0 || level >= maxLevels) {
760 _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
761 return;
762 }
763
764 texObj = _mesa_select_tex_object(ctx, texUnit, target);
765
766 img = _mesa_select_tex_image(ctx, texObj, target, level);
767 if (!img || img->TexFormat == MESA_FORMAT_NONE) {
768 /* undefined texture image */
769 if (pname == GL_TEXTURE_COMPONENTS)
770 *params = 1;
771 else
772 *params = 0;
773 return;
774 }
775
776 texFormat = img->TexFormat;
777
778 switch (pname) {
779 case GL_TEXTURE_WIDTH:
780 *params = img->Width;
781 break;
782 case GL_TEXTURE_HEIGHT:
783 *params = img->Height;
784 break;
785 case GL_TEXTURE_DEPTH:
786 *params = img->Depth;
787 break;
788 case GL_TEXTURE_INTERNAL_FORMAT:
789 if (_mesa_is_format_compressed(texFormat)) {
790 /* need to return the actual compressed format */
791 *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
792 }
793 else {
794 /* If the true internal format is not compressed but the user
795 * requested a generic compressed format, we have to return the
796 * generic base format that matches.
797 *
798 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
799 *
800 * "If no specific compressed format is available,
801 * internalformat is instead replaced by the corresponding base
802 * internal format."
803 *
804 * Otherwise just return the user's requested internal format
805 */
806 const GLenum f =
807 _mesa_gl_compressed_format_base_format(img->InternalFormat);
808
809 *params = (f != 0) ? f : img->InternalFormat;
810 }
811 break;
812 case GL_TEXTURE_BORDER:
813 *params = img->Border;
814 break;
815 case GL_TEXTURE_RED_SIZE:
816 case GL_TEXTURE_GREEN_SIZE:
817 case GL_TEXTURE_BLUE_SIZE:
818 case GL_TEXTURE_ALPHA_SIZE:
819 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
820 *params = _mesa_get_format_bits(texFormat, pname);
821 else
822 *params = 0;
823 break;
824 case GL_TEXTURE_INTENSITY_SIZE:
825 case GL_TEXTURE_LUMINANCE_SIZE:
826 if (_mesa_base_format_has_channel(img->_BaseFormat, pname)) {
827 *params = _mesa_get_format_bits(texFormat, pname);
828 if (*params == 0) {
829 /* intensity or luminance is probably stored as RGB[A] */
830 *params = MIN2(_mesa_get_format_bits(texFormat,
831 GL_TEXTURE_RED_SIZE),
832 _mesa_get_format_bits(texFormat,
833 GL_TEXTURE_GREEN_SIZE));
834 }
835 }
836 else {
837 *params = 0;
838 }
839 break;
840 case GL_TEXTURE_STENCIL_SIZE_EXT:
841 if (!ctx->Extensions.EXT_packed_depth_stencil &&
842 !ctx->Extensions.ARB_framebuffer_object)
843 goto invalid_pname;
844 *params = _mesa_get_format_bits(texFormat, pname);
845 break;
846
847 /* GL_ARB_texture_compression */
848 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
849 if (_mesa_is_format_compressed(texFormat) &&
850 !_mesa_is_proxy_texture(target)) {
851 *params = _mesa_format_image_size(texFormat, img->Width,
852 img->Height, img->Depth);
853 }
854 else {
855 _mesa_error(ctx, GL_INVALID_OPERATION,
856 "glGetTexLevelParameter[if]v(pname)");
857 }
858 break;
859 case GL_TEXTURE_COMPRESSED:
860 *params = (GLint) _mesa_is_format_compressed(texFormat);
861 break;
862
863 /* GL_ARB_texture_float */
864 case GL_TEXTURE_RED_TYPE_ARB:
865 case GL_TEXTURE_GREEN_TYPE_ARB:
866 case GL_TEXTURE_BLUE_TYPE_ARB:
867 case GL_TEXTURE_ALPHA_TYPE_ARB:
868 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
869 case GL_TEXTURE_INTENSITY_TYPE_ARB:
870 case GL_TEXTURE_DEPTH_TYPE_ARB:
871 if (!ctx->Extensions.ARB_texture_float)
872 goto invalid_pname;
873 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
874 *params = _mesa_get_format_datatype(texFormat);
875 else
876 *params = GL_NONE;
877 break;
878
879 default:
880 goto invalid_pname;
881 }
882
883 /* no error if we get here */
884 return;
885
886 invalid_pname:
887 _mesa_error(ctx, GL_INVALID_ENUM,
888 "glGetTexLevelParameter[if]v(pname=%s)",
889 _mesa_lookup_enum_by_nr(pname));
890 }
891
892
893
894 void GLAPIENTRY
895 _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
896 {
897 struct gl_texture_object *obj;
898 GET_CURRENT_CONTEXT(ctx);
899 ASSERT_OUTSIDE_BEGIN_END(ctx);
900
901 obj = get_texobj(ctx, target, GL_TRUE);
902 if (!obj)
903 return;
904
905 _mesa_lock_texture(ctx, obj);
906 switch (pname) {
907 case GL_TEXTURE_MAG_FILTER:
908 *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
909 break;
910 case GL_TEXTURE_MIN_FILTER:
911 *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
912 break;
913 case GL_TEXTURE_WRAP_S:
914 *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
915 break;
916 case GL_TEXTURE_WRAP_T:
917 *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
918 break;
919 case GL_TEXTURE_WRAP_R:
920 *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
921 break;
922 case GL_TEXTURE_BORDER_COLOR:
923 if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
924 _mesa_update_state_locked(ctx);
925 if (ctx->Color._ClampFragmentColor) {
926 params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
927 params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
928 params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
929 params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
930 }
931 else {
932 params[0] = obj->Sampler.BorderColor.f[0];
933 params[1] = obj->Sampler.BorderColor.f[1];
934 params[2] = obj->Sampler.BorderColor.f[2];
935 params[3] = obj->Sampler.BorderColor.f[3];
936 }
937 break;
938 case GL_TEXTURE_RESIDENT:
939 *params = 1.0F;
940 break;
941 case GL_TEXTURE_PRIORITY:
942 *params = obj->Priority;
943 break;
944 case GL_TEXTURE_MIN_LOD:
945 *params = obj->Sampler.MinLod;
946 break;
947 case GL_TEXTURE_MAX_LOD:
948 *params = obj->Sampler.MaxLod;
949 break;
950 case GL_TEXTURE_BASE_LEVEL:
951 *params = (GLfloat) obj->BaseLevel;
952 break;
953 case GL_TEXTURE_MAX_LEVEL:
954 *params = (GLfloat) obj->MaxLevel;
955 break;
956 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
957 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
958 goto invalid_pname;
959 *params = obj->Sampler.MaxAnisotropy;
960 break;
961 case GL_GENERATE_MIPMAP_SGIS:
962 *params = (GLfloat) obj->GenerateMipmap;
963 break;
964 case GL_TEXTURE_LOD_BIAS:
965 *params = obj->Sampler.LodBias;
966 break;
967 #if FEATURE_OES_draw_texture
968 case GL_TEXTURE_CROP_RECT_OES:
969 params[0] = obj->CropRect[0];
970 params[1] = obj->CropRect[1];
971 params[2] = obj->CropRect[2];
972 params[3] = obj->CropRect[3];
973 break;
974 #endif
975
976 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
977 if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
978 goto invalid_pname;
979 *params = (GLfloat) obj->Sampler.CubeMapSeamless;
980 break;
981
982 case GL_TEXTURE_IMMUTABLE_FORMAT:
983 if (!ctx->Extensions.ARB_texture_storage)
984 goto invalid_pname;
985 *params = (GLfloat) obj->Immutable;
986 break;
987
988 default:
989 goto invalid_pname;
990 }
991
992 /* no error if we get here */
993 _mesa_unlock_texture(ctx, obj);
994 return;
995
996 invalid_pname:
997 _mesa_unlock_texture(ctx, obj);
998 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname=0x%x)", pname);
999 }
1000
1001
1002 void GLAPIENTRY
1003 _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
1004 {
1005 struct gl_texture_object *obj;
1006 GET_CURRENT_CONTEXT(ctx);
1007 ASSERT_OUTSIDE_BEGIN_END(ctx);
1008
1009 obj = get_texobj(ctx, target, GL_TRUE);
1010 if (!obj)
1011 return;
1012
1013 _mesa_lock_texture(ctx, obj);
1014 switch (pname) {
1015 case GL_TEXTURE_MAG_FILTER:
1016 *params = (GLint) obj->Sampler.MagFilter;
1017 break;;
1018 case GL_TEXTURE_MIN_FILTER:
1019 *params = (GLint) obj->Sampler.MinFilter;
1020 break;;
1021 case GL_TEXTURE_WRAP_S:
1022 *params = (GLint) obj->Sampler.WrapS;
1023 break;;
1024 case GL_TEXTURE_WRAP_T:
1025 *params = (GLint) obj->Sampler.WrapT;
1026 break;;
1027 case GL_TEXTURE_WRAP_R:
1028 *params = (GLint) obj->Sampler.WrapR;
1029 break;;
1030 case GL_TEXTURE_BORDER_COLOR:
1031 {
1032 GLfloat b[4];
1033 b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1034 b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1035 b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1036 b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
1037 params[0] = FLOAT_TO_INT(b[0]);
1038 params[1] = FLOAT_TO_INT(b[1]);
1039 params[2] = FLOAT_TO_INT(b[2]);
1040 params[3] = FLOAT_TO_INT(b[3]);
1041 }
1042 break;;
1043 case GL_TEXTURE_RESIDENT:
1044 *params = 1;
1045 break;;
1046 case GL_TEXTURE_PRIORITY:
1047 *params = FLOAT_TO_INT(obj->Priority);
1048 break;;
1049 case GL_TEXTURE_MIN_LOD:
1050 *params = (GLint) obj->Sampler.MinLod;
1051 break;;
1052 case GL_TEXTURE_MAX_LOD:
1053 *params = (GLint) obj->Sampler.MaxLod;
1054 break;;
1055 case GL_TEXTURE_BASE_LEVEL:
1056 *params = obj->BaseLevel;
1057 break;;
1058 case GL_TEXTURE_MAX_LEVEL:
1059 *params = obj->MaxLevel;
1060 break;;
1061 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1062 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
1063 goto invalid_pname;
1064 *params = (GLint) obj->Sampler.MaxAnisotropy;
1065 break;
1066 case GL_GENERATE_MIPMAP_SGIS:
1067 *params = (GLint) obj->GenerateMipmap;
1068 break;
1069 case GL_TEXTURE_LOD_BIAS:
1070 *params = (GLint) obj->Sampler.LodBias;
1071 break;
1072 #if FEATURE_OES_draw_texture
1073 case GL_TEXTURE_CROP_RECT_OES:
1074 params[0] = obj->CropRect[0];
1075 params[1] = obj->CropRect[1];
1076 params[2] = obj->CropRect[2];
1077 params[3] = obj->CropRect[3];
1078 break;
1079 #endif
1080
1081 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1082 if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
1083 goto invalid_pname;
1084 *params = (GLint) obj->Sampler.CubeMapSeamless;
1085 break;
1086
1087 case GL_TEXTURE_IMMUTABLE_FORMAT:
1088 if (!ctx->Extensions.ARB_texture_storage)
1089 goto invalid_pname;
1090 *params = (GLint) obj->Immutable;
1091 break;
1092
1093 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
1094 if (!ctx->Extensions.OES_EGL_image_external)
1095 goto invalid_pname;
1096 *params = obj->RequiredTextureImageUnits;
1097 break;
1098
1099 default:
1100 goto invalid_pname;
1101 }
1102
1103 /* no error if we get here */
1104 _mesa_unlock_texture(ctx, obj);
1105 return;
1106
1107 invalid_pname:
1108 _mesa_unlock_texture(ctx, obj);
1109 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname=0x%x)", pname);
1110 }
1111
1112
1113 /** New in GL 3.0 */
1114 void GLAPIENTRY
1115 _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
1116 {
1117 struct gl_texture_object *texObj;
1118 GET_CURRENT_CONTEXT(ctx);
1119 ASSERT_OUTSIDE_BEGIN_END(ctx);
1120
1121 texObj = get_texobj(ctx, target, GL_TRUE);
1122 if (!texObj)
1123 return;
1124
1125 switch (pname) {
1126 case GL_TEXTURE_BORDER_COLOR:
1127 COPY_4V(params, texObj->Sampler.BorderColor.i);
1128 break;
1129 default:
1130 _mesa_GetTexParameteriv(target, pname, params);
1131 }
1132 }
1133
1134
1135 /** New in GL 3.0 */
1136 void GLAPIENTRY
1137 _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
1138 {
1139 struct gl_texture_object *texObj;
1140 GET_CURRENT_CONTEXT(ctx);
1141 ASSERT_OUTSIDE_BEGIN_END(ctx);
1142
1143 texObj = get_texobj(ctx, target, GL_TRUE);
1144 if (!texObj)
1145 return;
1146
1147 switch (pname) {
1148 case GL_TEXTURE_BORDER_COLOR:
1149 COPY_4V(params, texObj->Sampler.BorderColor.i);
1150 break;
1151 default:
1152 {
1153 GLint ip[4];
1154 _mesa_GetTexParameteriv(target, pname, ip);
1155 params[0] = ip[0];
1156 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT ||
1157 pname == GL_TEXTURE_CROP_RECT_OES) {
1158 params[1] = ip[1];
1159 params[2] = ip[2];
1160 params[3] = ip[3];
1161 }
1162 }
1163 }
1164 }