3284af1dcddb14d309571f85233097fb15cbc63d
[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 case GL_TEXTURE_COMPARE_MODE_ARB:
304 if (ctx->Extensions.ARB_shadow) {
305 if (texObj->Sampler.CompareMode == params[0])
306 return GL_FALSE;
307 if (params[0] == GL_NONE ||
308 params[0] == GL_COMPARE_R_TO_TEXTURE_ARB) {
309 flush(ctx);
310 texObj->Sampler.CompareMode = params[0];
311 return GL_TRUE;
312 }
313 goto invalid_param;
314 }
315 goto invalid_pname;
316
317 case GL_TEXTURE_COMPARE_FUNC_ARB:
318 if (ctx->Extensions.ARB_shadow) {
319 if (texObj->Sampler.CompareFunc == params[0])
320 return GL_FALSE;
321 switch (params[0]) {
322 case GL_LEQUAL:
323 case GL_GEQUAL:
324 flush(ctx);
325 texObj->Sampler.CompareFunc = params[0];
326 return GL_TRUE;
327 case GL_EQUAL:
328 case GL_NOTEQUAL:
329 case GL_LESS:
330 case GL_GREATER:
331 case GL_ALWAYS:
332 case GL_NEVER:
333 if (ctx->Extensions.EXT_shadow_funcs) {
334 flush(ctx);
335 texObj->Sampler.CompareFunc = params[0];
336 return GL_TRUE;
337 }
338 /* fall-through */
339 default:
340 goto invalid_param;
341 }
342 }
343 goto invalid_pname;
344
345 case GL_DEPTH_TEXTURE_MODE_ARB:
346 if (ctx->Extensions.ARB_depth_texture) {
347 if (texObj->Sampler.DepthMode == params[0])
348 return GL_FALSE;
349 if (params[0] == GL_LUMINANCE ||
350 params[0] == GL_INTENSITY ||
351 params[0] == GL_ALPHA ||
352 (ctx->Extensions.ARB_texture_rg && params[0] == GL_RED)) {
353 flush(ctx);
354 texObj->Sampler.DepthMode = params[0];
355 return GL_TRUE;
356 }
357 goto invalid_param;
358 }
359 goto invalid_pname;
360
361 #if FEATURE_OES_draw_texture
362 case GL_TEXTURE_CROP_RECT_OES:
363 texObj->CropRect[0] = params[0];
364 texObj->CropRect[1] = params[1];
365 texObj->CropRect[2] = params[2];
366 texObj->CropRect[3] = params[3];
367 return GL_TRUE;
368 #endif
369
370 case GL_TEXTURE_SRGB_DECODE_EXT:
371 if (ctx->Extensions.EXT_texture_sRGB_decode) {
372 GLenum decode = params[0];
373 if (decode == GL_DECODE_EXT || decode == GL_SKIP_DECODE_EXT) {
374 if (texObj->Sampler.sRGBDecode != decode) {
375 flush(ctx);
376 texObj->Sampler.sRGBDecode = decode;
377 }
378 return GL_TRUE;
379 }
380 }
381 goto invalid_pname;
382
383 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
384 if (ctx->Extensions.AMD_seamless_cubemap_per_texture) {
385 GLenum param = params[0];
386 if (param != GL_TRUE && param != GL_FALSE) {
387 goto invalid_param;
388 }
389 if (param != texObj->Sampler.CubeMapSeamless) {
390 flush(ctx);
391 texObj->Sampler.CubeMapSeamless = param;
392 }
393 return GL_TRUE;
394 }
395 goto invalid_pname;
396
397 default:
398 goto invalid_pname;
399 }
400
401 invalid_pname:
402 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=%s)",
403 _mesa_lookup_enum_by_nr(pname));
404 return GL_FALSE;
405
406 invalid_param:
407 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(param=%s)",
408 _mesa_lookup_enum_by_nr(params[0]));
409 return GL_FALSE;
410 }
411
412
413 /**
414 * Set a float-valued texture parameter
415 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
416 */
417 static GLboolean
418 set_tex_parameterf(struct gl_context *ctx,
419 struct gl_texture_object *texObj,
420 GLenum pname, const GLfloat *params)
421 {
422 switch (pname) {
423 case GL_TEXTURE_MIN_LOD:
424 if (texObj->Sampler.MinLod == params[0])
425 return GL_FALSE;
426 flush(ctx);
427 texObj->Sampler.MinLod = params[0];
428 return GL_TRUE;
429
430 case GL_TEXTURE_MAX_LOD:
431 if (texObj->Sampler.MaxLod == params[0])
432 return GL_FALSE;
433 flush(ctx);
434 texObj->Sampler.MaxLod = params[0];
435 return GL_TRUE;
436
437 case GL_TEXTURE_PRIORITY:
438 flush(ctx);
439 texObj->Priority = CLAMP(params[0], 0.0F, 1.0F);
440 return GL_TRUE;
441
442 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
443 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
444 if (texObj->Sampler.MaxAnisotropy == params[0])
445 return GL_FALSE;
446 if (params[0] < 1.0) {
447 _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
448 return GL_FALSE;
449 }
450 flush(ctx);
451 /* clamp to max, that's what NVIDIA does */
452 texObj->Sampler.MaxAnisotropy = MIN2(params[0],
453 ctx->Const.MaxTextureMaxAnisotropy);
454 return GL_TRUE;
455 }
456 else {
457 static GLuint count = 0;
458 if (count++ < 10)
459 _mesa_error(ctx, GL_INVALID_ENUM,
460 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
461 }
462 return GL_FALSE;
463
464 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
465 if (ctx->Extensions.ARB_shadow_ambient) {
466 if (texObj->Sampler.CompareFailValue != params[0]) {
467 flush(ctx);
468 texObj->Sampler.CompareFailValue = CLAMP(params[0], 0.0F, 1.0F);
469 return GL_TRUE;
470 }
471 }
472 else {
473 _mesa_error(ctx, GL_INVALID_ENUM,
474 "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
475 }
476 return GL_FALSE;
477
478 case GL_TEXTURE_LOD_BIAS:
479 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
480 if (texObj->Sampler.LodBias != params[0]) {
481 flush(ctx);
482 texObj->Sampler.LodBias = params[0];
483 return GL_TRUE;
484 }
485 break;
486
487 case GL_TEXTURE_BORDER_COLOR:
488 flush(ctx);
489 /* ARB_texture_float disables clamping */
490 if (ctx->Extensions.ARB_texture_float) {
491 texObj->Sampler.BorderColor.f[RCOMP] = params[0];
492 texObj->Sampler.BorderColor.f[GCOMP] = params[1];
493 texObj->Sampler.BorderColor.f[BCOMP] = params[2];
494 texObj->Sampler.BorderColor.f[ACOMP] = params[3];
495 } else {
496 texObj->Sampler.BorderColor.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F);
497 texObj->Sampler.BorderColor.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F);
498 texObj->Sampler.BorderColor.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F);
499 texObj->Sampler.BorderColor.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F);
500 }
501 return GL_TRUE;
502
503 default:
504 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=0x%x)", pname);
505 }
506 return GL_FALSE;
507 }
508
509
510 void GLAPIENTRY
511 _mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
512 {
513 GLboolean need_update;
514 struct gl_texture_object *texObj;
515 GET_CURRENT_CONTEXT(ctx);
516 ASSERT_OUTSIDE_BEGIN_END(ctx);
517
518 texObj = get_texobj(ctx, target, GL_FALSE);
519 if (!texObj)
520 return;
521
522 switch (pname) {
523 case GL_TEXTURE_MIN_FILTER:
524 case GL_TEXTURE_MAG_FILTER:
525 case GL_TEXTURE_WRAP_S:
526 case GL_TEXTURE_WRAP_T:
527 case GL_TEXTURE_WRAP_R:
528 case GL_TEXTURE_BASE_LEVEL:
529 case GL_TEXTURE_MAX_LEVEL:
530 case GL_GENERATE_MIPMAP_SGIS:
531 case GL_TEXTURE_COMPARE_MODE_ARB:
532 case GL_TEXTURE_COMPARE_FUNC_ARB:
533 case GL_DEPTH_TEXTURE_MODE_ARB:
534 case GL_TEXTURE_SRGB_DECODE_EXT:
535 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
536 {
537 /* convert float param to int */
538 GLint p[4];
539 p[0] = (GLint) param;
540 p[1] = p[2] = p[3] = 0;
541 need_update = set_tex_parameteri(ctx, texObj, pname, p);
542 }
543 break;
544 case GL_TEXTURE_SWIZZLE_R_EXT:
545 case GL_TEXTURE_SWIZZLE_G_EXT:
546 case GL_TEXTURE_SWIZZLE_B_EXT:
547 case GL_TEXTURE_SWIZZLE_A_EXT:
548 {
549 GLint p[4];
550 p[0] = (GLint) param;
551 p[1] = p[2] = p[3] = 0;
552 need_update = set_tex_parameteri(ctx, texObj, pname, p);
553 }
554 break;
555 default:
556 {
557 /* this will generate an error if pname is illegal */
558 GLfloat p[4];
559 p[0] = param;
560 p[1] = p[2] = p[3] = 0.0F;
561 need_update = set_tex_parameterf(ctx, texObj, pname, p);
562 }
563 }
564
565 if (ctx->Driver.TexParameter && need_update) {
566 ctx->Driver.TexParameter(ctx, target, texObj, pname, &param);
567 }
568 }
569
570
571 void GLAPIENTRY
572 _mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
573 {
574 GLboolean need_update;
575 struct gl_texture_object *texObj;
576 GET_CURRENT_CONTEXT(ctx);
577 ASSERT_OUTSIDE_BEGIN_END(ctx);
578
579 texObj = get_texobj(ctx, target, GL_FALSE);
580 if (!texObj)
581 return;
582
583 switch (pname) {
584 case GL_TEXTURE_MIN_FILTER:
585 case GL_TEXTURE_MAG_FILTER:
586 case GL_TEXTURE_WRAP_S:
587 case GL_TEXTURE_WRAP_T:
588 case GL_TEXTURE_WRAP_R:
589 case GL_TEXTURE_BASE_LEVEL:
590 case GL_TEXTURE_MAX_LEVEL:
591 case GL_GENERATE_MIPMAP_SGIS:
592 case GL_TEXTURE_COMPARE_MODE_ARB:
593 case GL_TEXTURE_COMPARE_FUNC_ARB:
594 case GL_DEPTH_TEXTURE_MODE_ARB:
595 case GL_TEXTURE_SRGB_DECODE_EXT:
596 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
597 {
598 /* convert float param to int */
599 GLint p[4];
600 p[0] = (GLint) params[0];
601 p[1] = p[2] = p[3] = 0;
602 need_update = set_tex_parameteri(ctx, texObj, pname, p);
603 }
604 break;
605
606 #if FEATURE_OES_draw_texture
607 case GL_TEXTURE_CROP_RECT_OES:
608 {
609 /* convert float params to int */
610 GLint iparams[4];
611 iparams[0] = (GLint) params[0];
612 iparams[1] = (GLint) params[1];
613 iparams[2] = (GLint) params[2];
614 iparams[3] = (GLint) params[3];
615 need_update = set_tex_parameteri(ctx, texObj, pname, iparams);
616 }
617 break;
618 #endif
619
620 case GL_TEXTURE_SWIZZLE_R_EXT:
621 case GL_TEXTURE_SWIZZLE_G_EXT:
622 case GL_TEXTURE_SWIZZLE_B_EXT:
623 case GL_TEXTURE_SWIZZLE_A_EXT:
624 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
625 {
626 GLint p[4] = {0, 0, 0, 0};
627 p[0] = (GLint) params[0];
628 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT) {
629 p[1] = (GLint) params[1];
630 p[2] = (GLint) params[2];
631 p[3] = (GLint) params[3];
632 }
633 need_update = set_tex_parameteri(ctx, texObj, pname, p);
634 }
635 break;
636 default:
637 /* this will generate an error if pname is illegal */
638 need_update = set_tex_parameterf(ctx, texObj, pname, params);
639 }
640
641 if (ctx->Driver.TexParameter && need_update) {
642 ctx->Driver.TexParameter(ctx, target, texObj, pname, params);
643 }
644 }
645
646
647 void GLAPIENTRY
648 _mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
649 {
650 GLboolean need_update;
651 struct gl_texture_object *texObj;
652 GET_CURRENT_CONTEXT(ctx);
653 ASSERT_OUTSIDE_BEGIN_END(ctx);
654
655 texObj = get_texobj(ctx, target, GL_FALSE);
656 if (!texObj)
657 return;
658
659 switch (pname) {
660 case GL_TEXTURE_MIN_LOD:
661 case GL_TEXTURE_MAX_LOD:
662 case GL_TEXTURE_PRIORITY:
663 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
664 case GL_TEXTURE_LOD_BIAS:
665 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
666 {
667 GLfloat fparam[4];
668 fparam[0] = (GLfloat) param;
669 fparam[1] = fparam[2] = fparam[3] = 0.0F;
670 /* convert int param to float */
671 need_update = set_tex_parameterf(ctx, texObj, pname, fparam);
672 }
673 break;
674 default:
675 /* this will generate an error if pname is illegal */
676 {
677 GLint iparam[4];
678 iparam[0] = param;
679 iparam[1] = iparam[2] = iparam[3] = 0;
680 need_update = set_tex_parameteri(ctx, texObj, pname, iparam);
681 }
682 }
683
684 if (ctx->Driver.TexParameter && need_update) {
685 GLfloat fparam = (GLfloat) param;
686 ctx->Driver.TexParameter(ctx, target, texObj, pname, &fparam);
687 }
688 }
689
690
691 void GLAPIENTRY
692 _mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
693 {
694 GLboolean need_update;
695 struct gl_texture_object *texObj;
696 GET_CURRENT_CONTEXT(ctx);
697 ASSERT_OUTSIDE_BEGIN_END(ctx);
698
699 texObj = get_texobj(ctx, target, GL_FALSE);
700 if (!texObj)
701 return;
702
703 switch (pname) {
704 case GL_TEXTURE_BORDER_COLOR:
705 {
706 /* convert int params to float */
707 GLfloat fparams[4];
708 fparams[0] = INT_TO_FLOAT(params[0]);
709 fparams[1] = INT_TO_FLOAT(params[1]);
710 fparams[2] = INT_TO_FLOAT(params[2]);
711 fparams[3] = INT_TO_FLOAT(params[3]);
712 need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
713 }
714 break;
715 case GL_TEXTURE_MIN_LOD:
716 case GL_TEXTURE_MAX_LOD:
717 case GL_TEXTURE_PRIORITY:
718 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
719 case GL_TEXTURE_LOD_BIAS:
720 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
721 {
722 /* convert int param to float */
723 GLfloat fparams[4];
724 fparams[0] = (GLfloat) params[0];
725 fparams[1] = fparams[2] = fparams[3] = 0.0F;
726 need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
727 }
728 break;
729 default:
730 /* this will generate an error if pname is illegal */
731 need_update = set_tex_parameteri(ctx, texObj, pname, params);
732 }
733
734 if (ctx->Driver.TexParameter && need_update) {
735 GLfloat fparams[4];
736 fparams[0] = INT_TO_FLOAT(params[0]);
737 if (pname == GL_TEXTURE_BORDER_COLOR ||
738 pname == GL_TEXTURE_CROP_RECT_OES) {
739 fparams[1] = INT_TO_FLOAT(params[1]);
740 fparams[2] = INT_TO_FLOAT(params[2]);
741 fparams[3] = INT_TO_FLOAT(params[3]);
742 }
743 ctx->Driver.TexParameter(ctx, target, texObj, pname, fparams);
744 }
745 }
746
747
748 /**
749 * Set tex parameter to integer value(s). Primarily intended to set
750 * integer-valued texture border color (for integer-valued textures).
751 * New in GL 3.0.
752 */
753 void GLAPIENTRY
754 _mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
755 {
756 struct gl_texture_object *texObj;
757 GET_CURRENT_CONTEXT(ctx);
758 ASSERT_OUTSIDE_BEGIN_END(ctx);
759
760 texObj = get_texobj(ctx, target, GL_FALSE);
761 if (!texObj)
762 return;
763
764 switch (pname) {
765 case GL_TEXTURE_BORDER_COLOR:
766 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
767 /* set the integer-valued border color */
768 COPY_4V(texObj->Sampler.BorderColor.i, params);
769 break;
770 default:
771 _mesa_TexParameteriv(target, pname, params);
772 break;
773 }
774 /* XXX no driver hook for TexParameterIiv() yet */
775 }
776
777
778 /**
779 * Set tex parameter to unsigned integer value(s). Primarily intended to set
780 * uint-valued texture border color (for integer-valued textures).
781 * New in GL 3.0
782 */
783 void GLAPIENTRY
784 _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
785 {
786 struct gl_texture_object *texObj;
787 GET_CURRENT_CONTEXT(ctx);
788 ASSERT_OUTSIDE_BEGIN_END(ctx);
789
790 texObj = get_texobj(ctx, target, GL_FALSE);
791 if (!texObj)
792 return;
793
794 switch (pname) {
795 case GL_TEXTURE_BORDER_COLOR:
796 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
797 /* set the unsigned integer-valued border color */
798 COPY_4V(texObj->Sampler.BorderColor.ui, params);
799 break;
800 default:
801 _mesa_TexParameteriv(target, pname, (const GLint *) params);
802 break;
803 }
804 /* XXX no driver hook for TexParameterIuiv() yet */
805 }
806
807
808 void GLAPIENTRY
809 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
810 GLenum pname, GLfloat *params )
811 {
812 GLint iparam;
813 _mesa_GetTexLevelParameteriv( target, level, pname, &iparam );
814 *params = (GLfloat) iparam;
815 }
816
817
818 void GLAPIENTRY
819 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
820 GLenum pname, GLint *params )
821 {
822 const struct gl_texture_unit *texUnit;
823 struct gl_texture_object *texObj;
824 const struct gl_texture_image *img = NULL;
825 GLint maxLevels;
826 gl_format texFormat;
827 GET_CURRENT_CONTEXT(ctx);
828 ASSERT_OUTSIDE_BEGIN_END(ctx);
829
830 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
831 _mesa_error(ctx, GL_INVALID_OPERATION,
832 "glGetTexLevelParameteriv(current unit)");
833 return;
834 }
835
836 texUnit = _mesa_get_current_tex_unit(ctx);
837
838 /* this will catch bad target values */
839 maxLevels = _mesa_max_texture_levels(ctx, target);
840 if (maxLevels == 0) {
841 _mesa_error(ctx, GL_INVALID_ENUM,
842 "glGetTexLevelParameter[if]v(target=0x%x)", target);
843 return;
844 }
845
846 if (level < 0 || level >= maxLevels) {
847 _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
848 return;
849 }
850
851 texObj = _mesa_select_tex_object(ctx, texUnit, target);
852
853 img = _mesa_select_tex_image(ctx, texObj, target, level);
854 if (!img || img->TexFormat == MESA_FORMAT_NONE) {
855 /* undefined texture image */
856 if (pname == GL_TEXTURE_COMPONENTS)
857 *params = 1;
858 else
859 *params = 0;
860 return;
861 }
862
863 texFormat = img->TexFormat;
864
865 switch (pname) {
866 case GL_TEXTURE_WIDTH:
867 *params = img->Width;
868 break;
869 case GL_TEXTURE_HEIGHT:
870 *params = img->Height;
871 break;
872 case GL_TEXTURE_DEPTH:
873 *params = img->Depth;
874 break;
875 case GL_TEXTURE_INTERNAL_FORMAT:
876 if (_mesa_is_format_compressed(texFormat)) {
877 /* need to return the actual compressed format */
878 *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
879 }
880 else {
881 /* If the true internal format is not compressed but the user
882 * requested a generic compressed format, we have to return the
883 * generic base format that matches.
884 *
885 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
886 *
887 * "If no specific compressed format is available,
888 * internalformat is instead replaced by the corresponding base
889 * internal format."
890 *
891 * Otherwise just return the user's requested internal format
892 */
893 const GLenum f =
894 _mesa_gl_compressed_format_base_format(img->InternalFormat);
895
896 *params = (f != 0) ? f : img->InternalFormat;
897 }
898 break;
899 case GL_TEXTURE_BORDER:
900 *params = img->Border;
901 break;
902 case GL_TEXTURE_RED_SIZE:
903 case GL_TEXTURE_GREEN_SIZE:
904 case GL_TEXTURE_BLUE_SIZE:
905 case GL_TEXTURE_ALPHA_SIZE:
906 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
907 *params = _mesa_get_format_bits(texFormat, pname);
908 else
909 *params = 0;
910 break;
911 case GL_TEXTURE_INTENSITY_SIZE:
912 case GL_TEXTURE_LUMINANCE_SIZE:
913 if (_mesa_base_format_has_channel(img->_BaseFormat, pname)) {
914 *params = _mesa_get_format_bits(texFormat, pname);
915 if (*params == 0) {
916 /* intensity or luminance is probably stored as RGB[A] */
917 *params = MIN2(_mesa_get_format_bits(texFormat,
918 GL_TEXTURE_RED_SIZE),
919 _mesa_get_format_bits(texFormat,
920 GL_TEXTURE_GREEN_SIZE));
921 }
922 }
923 else {
924 *params = 0;
925 }
926 break;
927 case GL_TEXTURE_DEPTH_SIZE_ARB:
928 if (!ctx->Extensions.ARB_depth_texture)
929 goto invalid_pname;
930 *params = _mesa_get_format_bits(texFormat, pname);
931 break;
932 case GL_TEXTURE_STENCIL_SIZE_EXT:
933 if (!ctx->Extensions.EXT_packed_depth_stencil &&
934 !ctx->Extensions.ARB_framebuffer_object)
935 goto invalid_pname;
936 *params = _mesa_get_format_bits(texFormat, pname);
937 break;
938
939 /* GL_ARB_texture_compression */
940 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
941 if (_mesa_is_format_compressed(texFormat) &&
942 !_mesa_is_proxy_texture(target)) {
943 *params = _mesa_format_image_size(texFormat, img->Width,
944 img->Height, img->Depth);
945 }
946 else {
947 _mesa_error(ctx, GL_INVALID_OPERATION,
948 "glGetTexLevelParameter[if]v(pname)");
949 }
950 break;
951 case GL_TEXTURE_COMPRESSED:
952 *params = (GLint) _mesa_is_format_compressed(texFormat);
953 break;
954
955 /* GL_ARB_texture_float */
956 case GL_TEXTURE_RED_TYPE_ARB:
957 case GL_TEXTURE_GREEN_TYPE_ARB:
958 case GL_TEXTURE_BLUE_TYPE_ARB:
959 case GL_TEXTURE_ALPHA_TYPE_ARB:
960 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
961 case GL_TEXTURE_INTENSITY_TYPE_ARB:
962 case GL_TEXTURE_DEPTH_TYPE_ARB:
963 if (!ctx->Extensions.ARB_texture_float)
964 goto invalid_pname;
965 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
966 *params = _mesa_get_format_datatype(texFormat);
967 else
968 *params = GL_NONE;
969 break;
970
971 default:
972 goto invalid_pname;
973 }
974
975 /* no error if we get here */
976 return;
977
978 invalid_pname:
979 _mesa_error(ctx, GL_INVALID_ENUM,
980 "glGetTexLevelParameter[if]v(pname=%s)",
981 _mesa_lookup_enum_by_nr(pname));
982 }
983
984
985
986 void GLAPIENTRY
987 _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
988 {
989 struct gl_texture_object *obj;
990 GET_CURRENT_CONTEXT(ctx);
991 ASSERT_OUTSIDE_BEGIN_END(ctx);
992
993 obj = get_texobj(ctx, target, GL_TRUE);
994 if (!obj)
995 return;
996
997 _mesa_lock_texture(ctx, obj);
998 switch (pname) {
999 case GL_TEXTURE_MAG_FILTER:
1000 *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
1001 break;
1002 case GL_TEXTURE_MIN_FILTER:
1003 *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
1004 break;
1005 case GL_TEXTURE_WRAP_S:
1006 *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
1007 break;
1008 case GL_TEXTURE_WRAP_T:
1009 *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
1010 break;
1011 case GL_TEXTURE_WRAP_R:
1012 *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
1013 break;
1014 case GL_TEXTURE_BORDER_COLOR:
1015 if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
1016 _mesa_update_state_locked(ctx);
1017 if (ctx->Color._ClampFragmentColor) {
1018 params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1019 params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1020 params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1021 params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
1022 }
1023 else {
1024 params[0] = obj->Sampler.BorderColor.f[0];
1025 params[1] = obj->Sampler.BorderColor.f[1];
1026 params[2] = obj->Sampler.BorderColor.f[2];
1027 params[3] = obj->Sampler.BorderColor.f[3];
1028 }
1029 break;
1030 case GL_TEXTURE_RESIDENT:
1031 *params = 1.0F;
1032 break;
1033 case GL_TEXTURE_PRIORITY:
1034 *params = obj->Priority;
1035 break;
1036 case GL_TEXTURE_MIN_LOD:
1037 *params = obj->Sampler.MinLod;
1038 break;
1039 case GL_TEXTURE_MAX_LOD:
1040 *params = obj->Sampler.MaxLod;
1041 break;
1042 case GL_TEXTURE_BASE_LEVEL:
1043 *params = (GLfloat) obj->BaseLevel;
1044 break;
1045 case GL_TEXTURE_MAX_LEVEL:
1046 *params = (GLfloat) obj->MaxLevel;
1047 break;
1048 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1049 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
1050 goto invalid_pname;
1051 *params = obj->Sampler.MaxAnisotropy;
1052 break;
1053 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
1054 if (!ctx->Extensions.ARB_shadow_ambient)
1055 goto invalid_pname;
1056 *params = obj->Sampler.CompareFailValue;
1057 break;
1058 case GL_GENERATE_MIPMAP_SGIS:
1059 *params = (GLfloat) obj->GenerateMipmap;
1060 break;
1061 case GL_TEXTURE_COMPARE_MODE_ARB:
1062 if (!ctx->Extensions.ARB_shadow)
1063 goto invalid_pname;
1064 *params = (GLfloat) obj->Sampler.CompareMode;
1065 break;
1066 case GL_TEXTURE_COMPARE_FUNC_ARB:
1067 if (!ctx->Extensions.ARB_shadow)
1068 goto invalid_pname;
1069 *params = (GLfloat) obj->Sampler.CompareFunc;
1070 break;
1071 case GL_DEPTH_TEXTURE_MODE_ARB:
1072 if (!ctx->Extensions.ARB_depth_texture)
1073 goto invalid_pname;
1074 *params = (GLfloat) obj->Sampler.DepthMode;
1075 break;
1076 case GL_TEXTURE_LOD_BIAS:
1077 *params = obj->Sampler.LodBias;
1078 break;
1079 #if FEATURE_OES_draw_texture
1080 case GL_TEXTURE_CROP_RECT_OES:
1081 params[0] = obj->CropRect[0];
1082 params[1] = obj->CropRect[1];
1083 params[2] = obj->CropRect[2];
1084 params[3] = obj->CropRect[3];
1085 break;
1086 #endif
1087
1088 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1089 if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
1090 goto invalid_pname;
1091 *params = (GLfloat) obj->Sampler.CubeMapSeamless;
1092 break;
1093
1094 case GL_TEXTURE_IMMUTABLE_FORMAT:
1095 if (!ctx->Extensions.ARB_texture_storage)
1096 goto invalid_pname;
1097 *params = (GLfloat) obj->Immutable;
1098 break;
1099
1100 default:
1101 goto invalid_pname;
1102 }
1103
1104 /* no error if we get here */
1105 _mesa_unlock_texture(ctx, obj);
1106 return;
1107
1108 invalid_pname:
1109 _mesa_unlock_texture(ctx, obj);
1110 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname=0x%x)", pname);
1111 }
1112
1113
1114 void GLAPIENTRY
1115 _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
1116 {
1117 struct gl_texture_object *obj;
1118 GET_CURRENT_CONTEXT(ctx);
1119 ASSERT_OUTSIDE_BEGIN_END(ctx);
1120
1121 obj = get_texobj(ctx, target, GL_TRUE);
1122 if (!obj)
1123 return;
1124
1125 _mesa_lock_texture(ctx, obj);
1126 switch (pname) {
1127 case GL_TEXTURE_MAG_FILTER:
1128 *params = (GLint) obj->Sampler.MagFilter;
1129 break;;
1130 case GL_TEXTURE_MIN_FILTER:
1131 *params = (GLint) obj->Sampler.MinFilter;
1132 break;;
1133 case GL_TEXTURE_WRAP_S:
1134 *params = (GLint) obj->Sampler.WrapS;
1135 break;;
1136 case GL_TEXTURE_WRAP_T:
1137 *params = (GLint) obj->Sampler.WrapT;
1138 break;;
1139 case GL_TEXTURE_WRAP_R:
1140 *params = (GLint) obj->Sampler.WrapR;
1141 break;;
1142 case GL_TEXTURE_BORDER_COLOR:
1143 {
1144 GLfloat b[4];
1145 b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1146 b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1147 b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1148 b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
1149 params[0] = FLOAT_TO_INT(b[0]);
1150 params[1] = FLOAT_TO_INT(b[1]);
1151 params[2] = FLOAT_TO_INT(b[2]);
1152 params[3] = FLOAT_TO_INT(b[3]);
1153 }
1154 break;;
1155 case GL_TEXTURE_RESIDENT:
1156 *params = 1;
1157 break;;
1158 case GL_TEXTURE_PRIORITY:
1159 *params = FLOAT_TO_INT(obj->Priority);
1160 break;;
1161 case GL_TEXTURE_MIN_LOD:
1162 *params = (GLint) obj->Sampler.MinLod;
1163 break;;
1164 case GL_TEXTURE_MAX_LOD:
1165 *params = (GLint) obj->Sampler.MaxLod;
1166 break;;
1167 case GL_TEXTURE_BASE_LEVEL:
1168 *params = obj->BaseLevel;
1169 break;;
1170 case GL_TEXTURE_MAX_LEVEL:
1171 *params = obj->MaxLevel;
1172 break;;
1173 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1174 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
1175 goto invalid_pname;
1176 *params = (GLint) obj->Sampler.MaxAnisotropy;
1177 break;
1178 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
1179 if (!ctx->Extensions.ARB_shadow_ambient)
1180 goto invalid_pname;
1181 *params = (GLint) FLOAT_TO_INT(obj->Sampler.CompareFailValue);
1182 break;
1183 case GL_GENERATE_MIPMAP_SGIS:
1184 *params = (GLint) obj->GenerateMipmap;
1185 break;
1186 case GL_TEXTURE_COMPARE_MODE_ARB:
1187 if (!ctx->Extensions.ARB_shadow)
1188 goto invalid_pname;
1189 *params = (GLint) obj->Sampler.CompareMode;
1190 break;
1191 case GL_TEXTURE_COMPARE_FUNC_ARB:
1192 if (!ctx->Extensions.ARB_shadow)
1193 goto invalid_pname;
1194 *params = (GLint) obj->Sampler.CompareFunc;
1195 break;
1196 case GL_DEPTH_TEXTURE_MODE_ARB:
1197 if (!ctx->Extensions.ARB_depth_texture)
1198 goto invalid_pname;
1199 *params = (GLint) obj->Sampler.DepthMode;
1200 break;
1201 case GL_TEXTURE_LOD_BIAS:
1202 *params = (GLint) obj->Sampler.LodBias;
1203 break;
1204 #if FEATURE_OES_draw_texture
1205 case GL_TEXTURE_CROP_RECT_OES:
1206 params[0] = obj->CropRect[0];
1207 params[1] = obj->CropRect[1];
1208 params[2] = obj->CropRect[2];
1209 params[3] = obj->CropRect[3];
1210 break;
1211 #endif
1212
1213 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1214 if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
1215 goto invalid_pname;
1216 *params = (GLint) obj->Sampler.CubeMapSeamless;
1217 break;
1218
1219 case GL_TEXTURE_IMMUTABLE_FORMAT:
1220 if (!ctx->Extensions.ARB_texture_storage)
1221 goto invalid_pname;
1222 *params = (GLint) obj->Immutable;
1223 break;
1224
1225 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
1226 if (!ctx->Extensions.OES_EGL_image_external)
1227 goto invalid_pname;
1228 *params = obj->RequiredTextureImageUnits;
1229 break;
1230
1231 default:
1232 goto invalid_pname;
1233 }
1234
1235 /* no error if we get here */
1236 _mesa_unlock_texture(ctx, obj);
1237 return;
1238
1239 invalid_pname:
1240 _mesa_unlock_texture(ctx, obj);
1241 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname=0x%x)", pname);
1242 }
1243
1244
1245 /** New in GL 3.0 */
1246 void GLAPIENTRY
1247 _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
1248 {
1249 struct gl_texture_object *texObj;
1250 GET_CURRENT_CONTEXT(ctx);
1251 ASSERT_OUTSIDE_BEGIN_END(ctx);
1252
1253 texObj = get_texobj(ctx, target, GL_TRUE);
1254 if (!texObj)
1255 return;
1256
1257 switch (pname) {
1258 case GL_TEXTURE_BORDER_COLOR:
1259 COPY_4V(params, texObj->Sampler.BorderColor.i);
1260 break;
1261 default:
1262 _mesa_GetTexParameteriv(target, pname, params);
1263 }
1264 }
1265
1266
1267 /** New in GL 3.0 */
1268 void GLAPIENTRY
1269 _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
1270 {
1271 struct gl_texture_object *texObj;
1272 GET_CURRENT_CONTEXT(ctx);
1273 ASSERT_OUTSIDE_BEGIN_END(ctx);
1274
1275 texObj = get_texobj(ctx, target, GL_TRUE);
1276 if (!texObj)
1277 return;
1278
1279 switch (pname) {
1280 case GL_TEXTURE_BORDER_COLOR:
1281 COPY_4V(params, texObj->Sampler.BorderColor.i);
1282 break;
1283 default:
1284 {
1285 GLint ip[4];
1286 _mesa_GetTexParameteriv(target, pname, ip);
1287 params[0] = ip[0];
1288 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT ||
1289 pname == GL_TEXTURE_CROP_RECT_OES) {
1290 params[1] = ip[1];
1291 params[2] = ip[2];
1292 params[3] = ip[3];
1293 }
1294 }
1295 }
1296 }