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