texparam.c revision 4a49301e
1c1f859d4Smrg/*
2c1f859d4Smrg * Mesa 3-D graphics library
3c1f859d4Smrg * Version:  7.5
4c1f859d4Smrg *
5c1f859d4Smrg * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
6c1f859d4Smrg * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
7c1f859d4Smrg *
8c1f859d4Smrg * Permission is hereby granted, free of charge, to any person obtaining a
9c1f859d4Smrg * copy of this software and associated documentation files (the "Software"),
10c1f859d4Smrg * to deal in the Software without restriction, including without limitation
11c1f859d4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12c1f859d4Smrg * and/or sell copies of the Software, and to permit persons to whom the
13c1f859d4Smrg * Software is furnished to do so, subject to the following conditions:
14c1f859d4Smrg *
15c1f859d4Smrg * The above copyright notice and this permission notice shall be included
16c1f859d4Smrg * in all copies or substantial portions of the Software.
17c1f859d4Smrg *
18c1f859d4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19c1f859d4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20c1f859d4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21c1f859d4Smrg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22c1f859d4Smrg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23c1f859d4Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24c1f859d4Smrg */
25c1f859d4Smrg
26c1f859d4Smrg/**
27c1f859d4Smrg * \file texparam.c
28c1f859d4Smrg *
29c1f859d4Smrg * glTexParameter-related functions
30c1f859d4Smrg */
31c1f859d4Smrg
32c1f859d4Smrg
33c1f859d4Smrg#include "main/glheader.h"
34c1f859d4Smrg#include "main/colormac.h"
354a49301eSmrg#include "main/context.h"
364a49301eSmrg#include "main/formats.h"
37c1f859d4Smrg#include "main/macros.h"
38c1f859d4Smrg#include "main/texcompress.h"
39c1f859d4Smrg#include "main/texparam.h"
40c1f859d4Smrg#include "main/teximage.h"
414a49301eSmrg#include "main/texstate.h"
424a49301eSmrg#include "shader/prog_instruction.h"
43c1f859d4Smrg
44c1f859d4Smrg
45c1f859d4Smrg/**
46c1f859d4Smrg * Check if a coordinate wrap mode is supported for the texture target.
47c1f859d4Smrg * \return GL_TRUE if legal, GL_FALSE otherwise
48c1f859d4Smrg */
49c1f859d4Smrgstatic GLboolean
50c1f859d4Smrgvalidate_texture_wrap_mode(GLcontext * ctx, GLenum target, GLenum wrap)
51c1f859d4Smrg{
52c1f859d4Smrg   const struct gl_extensions * const e = & ctx->Extensions;
53c1f859d4Smrg
54c1f859d4Smrg   if (wrap == GL_CLAMP || wrap == GL_CLAMP_TO_EDGE ||
55c1f859d4Smrg       (wrap == GL_CLAMP_TO_BORDER && e->ARB_texture_border_clamp)) {
56c1f859d4Smrg      /* any texture target */
57c1f859d4Smrg      return GL_TRUE;
58c1f859d4Smrg   }
59c1f859d4Smrg   else if (target != GL_TEXTURE_RECTANGLE_NV &&
60c1f859d4Smrg	    (wrap == GL_REPEAT ||
61c1f859d4Smrg	     (wrap == GL_MIRRORED_REPEAT &&
62c1f859d4Smrg	      e->ARB_texture_mirrored_repeat) ||
63c1f859d4Smrg	     (wrap == GL_MIRROR_CLAMP_EXT &&
64c1f859d4Smrg	      (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
65c1f859d4Smrg	     (wrap == GL_MIRROR_CLAMP_TO_EDGE_EXT &&
66c1f859d4Smrg	      (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
67c1f859d4Smrg	     (wrap == GL_MIRROR_CLAMP_TO_BORDER_EXT &&
68c1f859d4Smrg	      (e->EXT_texture_mirror_clamp)))) {
69c1f859d4Smrg      /* non-rectangle texture */
70c1f859d4Smrg      return GL_TRUE;
71c1f859d4Smrg   }
72c1f859d4Smrg
734a49301eSmrg   _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(param=0x%x)", wrap );
74c1f859d4Smrg   return GL_FALSE;
75c1f859d4Smrg}
76c1f859d4Smrg
77c1f859d4Smrg
78c1f859d4Smrg/**
79c1f859d4Smrg * Get current texture object for given target.
80c1f859d4Smrg * Return NULL if any error.
814a49301eSmrg * Note that this is different from _mesa_select_tex_object() in that proxy
824a49301eSmrg * targets are not accepted.
83c1f859d4Smrg */
84c1f859d4Smrgstatic struct gl_texture_object *
85c1f859d4Smrgget_texobj(GLcontext *ctx, GLenum target)
86c1f859d4Smrg{
87c1f859d4Smrg   struct gl_texture_unit *texUnit;
88c1f859d4Smrg
89c1f859d4Smrg   if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureImageUnits) {
90c1f859d4Smrg      _mesa_error(ctx, GL_INVALID_OPERATION, "glTexParameter(current unit)");
91c1f859d4Smrg      return NULL;
92c1f859d4Smrg   }
93c1f859d4Smrg
944a49301eSmrg   texUnit = _mesa_get_current_tex_unit(ctx);
95c1f859d4Smrg
96c1f859d4Smrg   switch (target) {
97c1f859d4Smrg   case GL_TEXTURE_1D:
98c1f859d4Smrg      return texUnit->CurrentTex[TEXTURE_1D_INDEX];
99c1f859d4Smrg   case GL_TEXTURE_2D:
100c1f859d4Smrg      return texUnit->CurrentTex[TEXTURE_2D_INDEX];
101c1f859d4Smrg   case GL_TEXTURE_3D:
102c1f859d4Smrg      return texUnit->CurrentTex[TEXTURE_3D_INDEX];
103c1f859d4Smrg   case GL_TEXTURE_CUBE_MAP:
104c1f859d4Smrg      if (ctx->Extensions.ARB_texture_cube_map) {
105c1f859d4Smrg         return texUnit->CurrentTex[TEXTURE_CUBE_INDEX];
106c1f859d4Smrg      }
107c1f859d4Smrg      break;
108c1f859d4Smrg   case GL_TEXTURE_RECTANGLE_NV:
109c1f859d4Smrg      if (ctx->Extensions.NV_texture_rectangle) {
110c1f859d4Smrg         return texUnit->CurrentTex[TEXTURE_RECT_INDEX];
111c1f859d4Smrg      }
112c1f859d4Smrg      break;
113c1f859d4Smrg   case GL_TEXTURE_1D_ARRAY_EXT:
114c1f859d4Smrg      if (ctx->Extensions.MESA_texture_array) {
115c1f859d4Smrg         return texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX];
116c1f859d4Smrg      }
117c1f859d4Smrg      break;
118c1f859d4Smrg   case GL_TEXTURE_2D_ARRAY_EXT:
119c1f859d4Smrg      if (ctx->Extensions.MESA_texture_array) {
120c1f859d4Smrg         return texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX];
121c1f859d4Smrg      }
122c1f859d4Smrg      break;
123c1f859d4Smrg   default:
124c1f859d4Smrg      ;
125c1f859d4Smrg   }
126c1f859d4Smrg
127c1f859d4Smrg   _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(target)");
128c1f859d4Smrg   return NULL;
129c1f859d4Smrg}
130c1f859d4Smrg
131c1f859d4Smrg
1324a49301eSmrg/**
1334a49301eSmrg * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
1344a49301eSmrg * \return -1 if error.
1354a49301eSmrg */
1364a49301eSmrgstatic GLint
1374a49301eSmrgcomp_to_swizzle(GLenum comp)
1384a49301eSmrg{
1394a49301eSmrg   switch (comp) {
1404a49301eSmrg   case GL_RED:
1414a49301eSmrg      return SWIZZLE_X;
1424a49301eSmrg   case GL_GREEN:
1434a49301eSmrg      return SWIZZLE_Y;
1444a49301eSmrg   case GL_BLUE:
1454a49301eSmrg      return SWIZZLE_Z;
1464a49301eSmrg   case GL_ALPHA:
1474a49301eSmrg      return SWIZZLE_W;
1484a49301eSmrg   case GL_ZERO:
1494a49301eSmrg      return SWIZZLE_ZERO;
1504a49301eSmrg   case GL_ONE:
1514a49301eSmrg      return SWIZZLE_ONE;
1524a49301eSmrg   default:
1534a49301eSmrg      return -1;
1544a49301eSmrg   }
1554a49301eSmrg}
1564a49301eSmrg
1574a49301eSmrg
1584a49301eSmrgstatic void
1594a49301eSmrgset_swizzle_component(GLuint *swizzle, GLuint comp, GLuint swz)
1604a49301eSmrg{
1614a49301eSmrg   ASSERT(comp < 4);
1624a49301eSmrg   ASSERT(swz <= SWIZZLE_NIL);
1634a49301eSmrg   {
1644a49301eSmrg      GLuint mask = 0x7 << (3 * comp);
1654a49301eSmrg      GLuint s = (*swizzle & ~mask) | (swz << (3 * comp));
1664a49301eSmrg      *swizzle = s;
1674a49301eSmrg   }
1684a49301eSmrg}
1694a49301eSmrg
1704a49301eSmrg
171c1f859d4Smrg/**
172c1f859d4Smrg * This is called just prior to changing any texture object state.
173c1f859d4Smrg * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
174c1f859d4Smrg * state flag and then mark the texture object as 'incomplete' so that any
175c1f859d4Smrg * per-texture derived state gets recomputed.
176c1f859d4Smrg */
177c1f859d4Smrgstatic INLINE void
178c1f859d4Smrgflush(GLcontext *ctx, struct gl_texture_object *texObj)
179c1f859d4Smrg{
180c1f859d4Smrg   FLUSH_VERTICES(ctx, _NEW_TEXTURE);
181c1f859d4Smrg   texObj->_Complete = GL_FALSE;
182c1f859d4Smrg}
183c1f859d4Smrg
184c1f859d4Smrg
185c1f859d4Smrg/**
186c1f859d4Smrg * Set an integer-valued texture parameter
187c1f859d4Smrg * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
188c1f859d4Smrg */
189c1f859d4Smrgstatic GLboolean
190c1f859d4Smrgset_tex_parameteri(GLcontext *ctx,
191c1f859d4Smrg                   struct gl_texture_object *texObj,
192c1f859d4Smrg                   GLenum pname, const GLint *params)
193c1f859d4Smrg{
194c1f859d4Smrg   switch (pname) {
195c1f859d4Smrg   case GL_TEXTURE_MIN_FILTER:
196c1f859d4Smrg      if (texObj->MinFilter == params[0])
197c1f859d4Smrg         return GL_FALSE;
198c1f859d4Smrg      switch (params[0]) {
199c1f859d4Smrg      case GL_NEAREST:
200c1f859d4Smrg      case GL_LINEAR:
201c1f859d4Smrg         flush(ctx, texObj);
202c1f859d4Smrg         texObj->MinFilter = params[0];
203c1f859d4Smrg         return GL_TRUE;
204c1f859d4Smrg      case GL_NEAREST_MIPMAP_NEAREST:
205c1f859d4Smrg      case GL_LINEAR_MIPMAP_NEAREST:
206c1f859d4Smrg      case GL_NEAREST_MIPMAP_LINEAR:
207c1f859d4Smrg      case GL_LINEAR_MIPMAP_LINEAR:
208c1f859d4Smrg         if (texObj->Target != GL_TEXTURE_RECTANGLE_NV) {
209c1f859d4Smrg            flush(ctx, texObj);
210c1f859d4Smrg            texObj->MinFilter = params[0];
211c1f859d4Smrg            return GL_TRUE;
212c1f859d4Smrg         }
213c1f859d4Smrg         /* fall-through */
214c1f859d4Smrg      default:
2154a49301eSmrg         _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(param=0x%x)",
2164a49301eSmrg                      params[0] );
217c1f859d4Smrg      }
218c1f859d4Smrg      return GL_FALSE;
219c1f859d4Smrg
220c1f859d4Smrg   case GL_TEXTURE_MAG_FILTER:
221c1f859d4Smrg      if (texObj->MagFilter == params[0])
222c1f859d4Smrg         return GL_FALSE;
223c1f859d4Smrg      switch (params[0]) {
224c1f859d4Smrg      case GL_NEAREST:
225c1f859d4Smrg      case GL_LINEAR:
226c1f859d4Smrg         flush(ctx, texObj);
227c1f859d4Smrg         texObj->MagFilter = params[0];
228c1f859d4Smrg         return GL_TRUE;
229c1f859d4Smrg      default:
2304a49301eSmrg         _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(param=0x%x)",
2314a49301eSmrg                      params[0]);
232c1f859d4Smrg      }
233c1f859d4Smrg      return GL_FALSE;
234c1f859d4Smrg
235c1f859d4Smrg   case GL_TEXTURE_WRAP_S:
236c1f859d4Smrg      if (texObj->WrapS == params[0])
237c1f859d4Smrg         return GL_FALSE;
238c1f859d4Smrg      if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
239c1f859d4Smrg         flush(ctx, texObj);
240c1f859d4Smrg         texObj->WrapS = params[0];
241c1f859d4Smrg         return GL_TRUE;
242c1f859d4Smrg      }
243c1f859d4Smrg      return GL_FALSE;
244c1f859d4Smrg
245c1f859d4Smrg   case GL_TEXTURE_WRAP_T:
246c1f859d4Smrg      if (texObj->WrapT == params[0])
247c1f859d4Smrg         return GL_FALSE;
248c1f859d4Smrg      if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
249c1f859d4Smrg         flush(ctx, texObj);
250c1f859d4Smrg         texObj->WrapT = params[0];
251c1f859d4Smrg         return GL_TRUE;
252c1f859d4Smrg      }
253c1f859d4Smrg      return GL_FALSE;
254c1f859d4Smrg
255c1f859d4Smrg   case GL_TEXTURE_WRAP_R:
256c1f859d4Smrg      if (texObj->WrapR == params[0])
257c1f859d4Smrg         return GL_FALSE;
258c1f859d4Smrg      if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
259c1f859d4Smrg         flush(ctx, texObj);
260c1f859d4Smrg         texObj->WrapR = params[0];
261c1f859d4Smrg         return GL_TRUE;
262c1f859d4Smrg      }
263c1f859d4Smrg      return GL_FALSE;
264c1f859d4Smrg
265c1f859d4Smrg   case GL_TEXTURE_BASE_LEVEL:
266c1f859d4Smrg      if (texObj->BaseLevel == params[0])
267c1f859d4Smrg         return GL_FALSE;
268c1f859d4Smrg      if (params[0] < 0 ||
269c1f859d4Smrg          (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] != 0)) {
2704a49301eSmrg         _mesa_error(ctx, GL_INVALID_VALUE,
2714a49301eSmrg                     "glTexParameter(param=%d)", params[0]);
272c1f859d4Smrg         return GL_FALSE;
273c1f859d4Smrg      }
274c1f859d4Smrg      flush(ctx, texObj);
275c1f859d4Smrg      texObj->BaseLevel = params[0];
276c1f859d4Smrg      return GL_TRUE;
277c1f859d4Smrg
278c1f859d4Smrg   case GL_TEXTURE_MAX_LEVEL:
279c1f859d4Smrg      if (texObj->MaxLevel == params[0])
280c1f859d4Smrg         return GL_FALSE;
281c1f859d4Smrg      if (params[0] < 0 || texObj->Target == GL_TEXTURE_RECTANGLE_ARB) {
2824a49301eSmrg         _mesa_error(ctx, GL_INVALID_OPERATION,
2834a49301eSmrg                     "glTexParameter(param=%d)", params[0]);
284c1f859d4Smrg         return GL_FALSE;
285c1f859d4Smrg      }
286c1f859d4Smrg      flush(ctx, texObj);
287c1f859d4Smrg      texObj->MaxLevel = params[0];
288c1f859d4Smrg      return GL_TRUE;
289c1f859d4Smrg
290c1f859d4Smrg   case GL_GENERATE_MIPMAP_SGIS:
291c1f859d4Smrg      if (ctx->Extensions.SGIS_generate_mipmap) {
292c1f859d4Smrg         if (texObj->GenerateMipmap != params[0]) {
293c1f859d4Smrg            flush(ctx, texObj);
294c1f859d4Smrg            texObj->GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
295c1f859d4Smrg            return GL_TRUE;
296c1f859d4Smrg         }
297c1f859d4Smrg         return GL_FALSE;
298c1f859d4Smrg      }
299c1f859d4Smrg      else {
300c1f859d4Smrg         _mesa_error(ctx, GL_INVALID_ENUM,
301c1f859d4Smrg                     "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
302c1f859d4Smrg      }
303c1f859d4Smrg      return GL_FALSE;
304c1f859d4Smrg
305c1f859d4Smrg   case GL_TEXTURE_COMPARE_MODE_ARB:
306c1f859d4Smrg      if (ctx->Extensions.ARB_shadow &&
307c1f859d4Smrg          (params[0] == GL_NONE ||
308c1f859d4Smrg           params[0] == GL_COMPARE_R_TO_TEXTURE_ARB)) {
309c1f859d4Smrg         if (texObj->CompareMode != params[0]) {
310c1f859d4Smrg            flush(ctx, texObj);
311c1f859d4Smrg            texObj->CompareMode = params[0];
312c1f859d4Smrg            return GL_TRUE;
313c1f859d4Smrg         }
314c1f859d4Smrg         return GL_FALSE;
315c1f859d4Smrg      }
316c1f859d4Smrg      else {
317c1f859d4Smrg         _mesa_error(ctx, GL_INVALID_ENUM,
318c1f859d4Smrg                     "glTexParameter(GL_TEXTURE_COMPARE_MODE_ARB)");
319c1f859d4Smrg      }
320c1f859d4Smrg      return GL_FALSE;
321c1f859d4Smrg
322c1f859d4Smrg   case GL_TEXTURE_COMPARE_FUNC_ARB:
323c1f859d4Smrg      if (ctx->Extensions.ARB_shadow) {
324c1f859d4Smrg         if (texObj->CompareFunc == params[0])
325c1f859d4Smrg            return GL_FALSE;
326c1f859d4Smrg         switch (params[0]) {
327c1f859d4Smrg         case GL_LEQUAL:
328c1f859d4Smrg         case GL_GEQUAL:
329c1f859d4Smrg            flush(ctx, texObj);
330c1f859d4Smrg            texObj->CompareFunc = params[0];
331c1f859d4Smrg            return GL_TRUE;
332c1f859d4Smrg         case GL_EQUAL:
333c1f859d4Smrg         case GL_NOTEQUAL:
334c1f859d4Smrg         case GL_LESS:
335c1f859d4Smrg         case GL_GREATER:
336c1f859d4Smrg         case GL_ALWAYS:
337c1f859d4Smrg         case GL_NEVER:
338c1f859d4Smrg            if (ctx->Extensions.EXT_shadow_funcs) {
339c1f859d4Smrg               flush(ctx, texObj);
340c1f859d4Smrg               texObj->CompareFunc = params[0];
341c1f859d4Smrg               return GL_TRUE;
342c1f859d4Smrg            }
343c1f859d4Smrg            /* fall-through */
344c1f859d4Smrg         default:
345c1f859d4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
346c1f859d4Smrg                        "glTexParameter(GL_TEXTURE_COMPARE_FUNC_ARB)");
347c1f859d4Smrg         }
348c1f859d4Smrg      }
349c1f859d4Smrg      else {
3504a49301eSmrg         _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=0x%x)", pname);
351c1f859d4Smrg      }
352c1f859d4Smrg      return GL_FALSE;
353c1f859d4Smrg
354c1f859d4Smrg   case GL_DEPTH_TEXTURE_MODE_ARB:
355c1f859d4Smrg      if (ctx->Extensions.ARB_depth_texture &&
356c1f859d4Smrg          (params[0] == GL_LUMINANCE ||
357c1f859d4Smrg           params[0] == GL_INTENSITY ||
358c1f859d4Smrg           params[0] == GL_ALPHA)) {
359c1f859d4Smrg         if (texObj->DepthMode != params[0]) {
360c1f859d4Smrg            flush(ctx, texObj);
361c1f859d4Smrg            texObj->DepthMode = params[0];
362c1f859d4Smrg            return GL_TRUE;
363c1f859d4Smrg         }
364c1f859d4Smrg      }
365c1f859d4Smrg      else {
366c1f859d4Smrg         _mesa_error(ctx, GL_INVALID_ENUM,
367c1f859d4Smrg                     "glTexParameter(GL_DEPTH_TEXTURE_MODE_ARB)");
368c1f859d4Smrg      }
369c1f859d4Smrg      return GL_FALSE;
370c1f859d4Smrg
371c1f859d4Smrg#ifdef FEATURE_OES_draw_texture
372c1f859d4Smrg   case GL_TEXTURE_CROP_RECT_OES:
373c1f859d4Smrg      texObj->CropRect[0] = params[0];
374c1f859d4Smrg      texObj->CropRect[1] = params[1];
375c1f859d4Smrg      texObj->CropRect[2] = params[2];
376c1f859d4Smrg      texObj->CropRect[3] = params[3];
377c1f859d4Smrg      return GL_TRUE;
378c1f859d4Smrg#endif
379c1f859d4Smrg
3804a49301eSmrg   case GL_TEXTURE_SWIZZLE_R_EXT:
3814a49301eSmrg   case GL_TEXTURE_SWIZZLE_G_EXT:
3824a49301eSmrg   case GL_TEXTURE_SWIZZLE_B_EXT:
3834a49301eSmrg   case GL_TEXTURE_SWIZZLE_A_EXT:
3844a49301eSmrg      if (ctx->Extensions.EXT_texture_swizzle) {
3854a49301eSmrg         const GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
3864a49301eSmrg         const GLint swz = comp_to_swizzle(params[0]);
3874a49301eSmrg         if (swz < 0) {
3884a49301eSmrg            _mesa_error(ctx, GL_INVALID_OPERATION,
3894a49301eSmrg                        "glTexParameter(swizzle 0x%x)", params[0]);
3904a49301eSmrg            return GL_FALSE;
3914a49301eSmrg         }
3924a49301eSmrg         ASSERT(comp < 4);
3934a49301eSmrg         if (swz >= 0) {
3944a49301eSmrg            flush(ctx, texObj);
3954a49301eSmrg            texObj->Swizzle[comp] = params[0];
3964a49301eSmrg            set_swizzle_component(&texObj->_Swizzle, comp, swz);
3974a49301eSmrg            return GL_TRUE;
3984a49301eSmrg         }
3994a49301eSmrg      }
4004a49301eSmrg      _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=0x%x)", pname);
4014a49301eSmrg      return GL_FALSE;
4024a49301eSmrg
4034a49301eSmrg   case GL_TEXTURE_SWIZZLE_RGBA_EXT:
4044a49301eSmrg      if (ctx->Extensions.EXT_texture_swizzle) {
4054a49301eSmrg         GLuint comp;
4064a49301eSmrg         flush(ctx, texObj);
4074a49301eSmrg         for (comp = 0; comp < 4; comp++) {
4084a49301eSmrg            const GLint swz = comp_to_swizzle(params[comp]);
4094a49301eSmrg            if (swz >= 0) {
4104a49301eSmrg               texObj->Swizzle[comp] = params[comp];
4114a49301eSmrg               set_swizzle_component(&texObj->_Swizzle, comp, swz);
4124a49301eSmrg            }
4134a49301eSmrg            else {
4144a49301eSmrg               _mesa_error(ctx, GL_INVALID_OPERATION,
4154a49301eSmrg                           "glTexParameter(swizzle 0x%x)", params[comp]);
4164a49301eSmrg               return GL_FALSE;
4174a49301eSmrg            }
4184a49301eSmrg         }
4194a49301eSmrg         return GL_TRUE;
4204a49301eSmrg      }
4214a49301eSmrg      _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=0x%x)", pname);
4224a49301eSmrg      return GL_FALSE;
4234a49301eSmrg
424c1f859d4Smrg   default:
425c1f859d4Smrg      _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=0x%x)", pname);
426c1f859d4Smrg   }
427c1f859d4Smrg   return GL_FALSE;
428c1f859d4Smrg}
429c1f859d4Smrg
430c1f859d4Smrg
431c1f859d4Smrg/**
432c1f859d4Smrg * Set a float-valued texture parameter
433c1f859d4Smrg * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
434c1f859d4Smrg */
435c1f859d4Smrgstatic GLboolean
436c1f859d4Smrgset_tex_parameterf(GLcontext *ctx,
437c1f859d4Smrg                   struct gl_texture_object *texObj,
438c1f859d4Smrg                   GLenum pname, const GLfloat *params)
439c1f859d4Smrg{
440c1f859d4Smrg   switch (pname) {
441c1f859d4Smrg   case GL_TEXTURE_MIN_LOD:
442c1f859d4Smrg      if (texObj->MinLod == params[0])
443c1f859d4Smrg         return GL_FALSE;
444c1f859d4Smrg      flush(ctx, texObj);
445c1f859d4Smrg      texObj->MinLod = params[0];
446c1f859d4Smrg      return GL_TRUE;
447c1f859d4Smrg
448c1f859d4Smrg   case GL_TEXTURE_MAX_LOD:
449c1f859d4Smrg      if (texObj->MaxLod == params[0])
450c1f859d4Smrg         return GL_FALSE;
451c1f859d4Smrg      flush(ctx, texObj);
452c1f859d4Smrg      texObj->MaxLod = params[0];
453c1f859d4Smrg      return GL_TRUE;
454c1f859d4Smrg
455c1f859d4Smrg   case GL_TEXTURE_PRIORITY:
456c1f859d4Smrg      flush(ctx, texObj);
457c1f859d4Smrg      texObj->Priority = CLAMP(params[0], 0.0F, 1.0F);
458c1f859d4Smrg      return GL_TRUE;
459c1f859d4Smrg
460c1f859d4Smrg   case GL_TEXTURE_MAX_ANISOTROPY_EXT:
461c1f859d4Smrg      if (ctx->Extensions.EXT_texture_filter_anisotropic) {
462c1f859d4Smrg         if (texObj->MaxAnisotropy == params[0])
463c1f859d4Smrg            return GL_FALSE;
464c1f859d4Smrg         if (params[0] < 1.0) {
465c1f859d4Smrg            _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
466c1f859d4Smrg            return GL_FALSE;
467c1f859d4Smrg         }
468c1f859d4Smrg         flush(ctx, texObj);
469c1f859d4Smrg         /* clamp to max, that's what NVIDIA does */
470c1f859d4Smrg         texObj->MaxAnisotropy = MIN2(params[0],
471c1f859d4Smrg                                      ctx->Const.MaxTextureMaxAnisotropy);
472c1f859d4Smrg         return GL_TRUE;
473c1f859d4Smrg      }
474c1f859d4Smrg      else {
4754a49301eSmrg         static GLuint count = 0;
4764a49301eSmrg         if (count++ < 10)
4774a49301eSmrg            _mesa_error(ctx, GL_INVALID_ENUM,
4784a49301eSmrg                        "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
479c1f859d4Smrg      }
480c1f859d4Smrg      return GL_FALSE;
481c1f859d4Smrg
482c1f859d4Smrg   case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
4834a49301eSmrg      if (ctx->Extensions.ARB_shadow_ambient) {
4844a49301eSmrg         if (texObj->CompareFailValue != params[0]) {
485c1f859d4Smrg            flush(ctx, texObj);
4864a49301eSmrg            texObj->CompareFailValue = CLAMP(params[0], 0.0F, 1.0F);
487c1f859d4Smrg            return GL_TRUE;
488c1f859d4Smrg         }
489c1f859d4Smrg      }
490c1f859d4Smrg      else {
491c1f859d4Smrg         _mesa_error(ctx, GL_INVALID_ENUM,
4924a49301eSmrg                    "glTexParameter(pname=GL_TEXTURE_COMPARE_FAIL_VALUE_ARB)");
493c1f859d4Smrg      }
494c1f859d4Smrg      return GL_FALSE;
495c1f859d4Smrg
496c1f859d4Smrg   case GL_TEXTURE_LOD_BIAS:
497c1f859d4Smrg      /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */
498c1f859d4Smrg      if (ctx->Extensions.EXT_texture_lod_bias) {
499c1f859d4Smrg         if (texObj->LodBias != params[0]) {
500c1f859d4Smrg            flush(ctx, texObj);
501c1f859d4Smrg            texObj->LodBias = params[0];
502c1f859d4Smrg            return GL_TRUE;
503c1f859d4Smrg         }
504c1f859d4Smrg         return GL_FALSE;
505c1f859d4Smrg      }
506c1f859d4Smrg      break;
507c1f859d4Smrg
508c1f859d4Smrg   case GL_TEXTURE_BORDER_COLOR:
509c1f859d4Smrg      flush(ctx, texObj);
510c1f859d4Smrg      texObj->BorderColor[RCOMP] = params[0];
511c1f859d4Smrg      texObj->BorderColor[GCOMP] = params[1];
512c1f859d4Smrg      texObj->BorderColor[BCOMP] = params[2];
513c1f859d4Smrg      texObj->BorderColor[ACOMP] = params[3];
514c1f859d4Smrg      return GL_TRUE;
515c1f859d4Smrg
516c1f859d4Smrg   default:
517c1f859d4Smrg      _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(pname=0x%x)", pname);
518c1f859d4Smrg   }
519c1f859d4Smrg   return GL_FALSE;
520c1f859d4Smrg}
521c1f859d4Smrg
522c1f859d4Smrg
523c1f859d4Smrgvoid GLAPIENTRY
524c1f859d4Smrg_mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
525c1f859d4Smrg{
526c1f859d4Smrg   GLboolean need_update;
527c1f859d4Smrg   struct gl_texture_object *texObj;
528c1f859d4Smrg   GET_CURRENT_CONTEXT(ctx);
529c1f859d4Smrg   ASSERT_OUTSIDE_BEGIN_END(ctx);
530c1f859d4Smrg
531c1f859d4Smrg   texObj = get_texobj(ctx, target);
532c1f859d4Smrg   if (!texObj)
533c1f859d4Smrg      return;
534c1f859d4Smrg
535c1f859d4Smrg   switch (pname) {
536c1f859d4Smrg   case GL_TEXTURE_MIN_FILTER:
537c1f859d4Smrg   case GL_TEXTURE_MAG_FILTER:
538c1f859d4Smrg   case GL_TEXTURE_WRAP_S:
539c1f859d4Smrg   case GL_TEXTURE_WRAP_T:
540c1f859d4Smrg   case GL_TEXTURE_WRAP_R:
541c1f859d4Smrg   case GL_TEXTURE_BASE_LEVEL:
542c1f859d4Smrg   case GL_TEXTURE_MAX_LEVEL:
543c1f859d4Smrg   case GL_GENERATE_MIPMAP_SGIS:
544c1f859d4Smrg   case GL_TEXTURE_COMPARE_MODE_ARB:
545c1f859d4Smrg   case GL_TEXTURE_COMPARE_FUNC_ARB:
546c1f859d4Smrg   case GL_DEPTH_TEXTURE_MODE_ARB:
547c1f859d4Smrg      {
548c1f859d4Smrg         /* convert float param to int */
5494a49301eSmrg         GLint p[4];
5504a49301eSmrg         p[0] = (GLint) param;
5514a49301eSmrg         p[1] = p[2] = p[3] = 0;
5524a49301eSmrg         need_update = set_tex_parameteri(ctx, texObj, pname, p);
553c1f859d4Smrg      }
554c1f859d4Smrg      break;
555c1f859d4Smrg   default:
5564a49301eSmrg      {
5574a49301eSmrg         /* this will generate an error if pname is illegal */
5584a49301eSmrg         GLfloat p[4];
5594a49301eSmrg         p[0] = param;
5604a49301eSmrg         p[1] = p[2] = p[3] = 0.0F;
5614a49301eSmrg         need_update = set_tex_parameterf(ctx, texObj, pname, p);
5624a49301eSmrg      }
563c1f859d4Smrg   }
564c1f859d4Smrg
565c1f859d4Smrg   if (ctx->Driver.TexParameter && need_update) {
566c1f859d4Smrg      ctx->Driver.TexParameter(ctx, target, texObj, pname, &param);
567c1f859d4Smrg   }
568c1f859d4Smrg}
569c1f859d4Smrg
570c1f859d4Smrg
571c1f859d4Smrgvoid GLAPIENTRY
572c1f859d4Smrg_mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
573c1f859d4Smrg{
574c1f859d4Smrg   GLboolean need_update;
575c1f859d4Smrg   struct gl_texture_object *texObj;
576c1f859d4Smrg   GET_CURRENT_CONTEXT(ctx);
577c1f859d4Smrg   ASSERT_OUTSIDE_BEGIN_END(ctx);
578c1f859d4Smrg
579c1f859d4Smrg   texObj = get_texobj(ctx, target);
580c1f859d4Smrg   if (!texObj)
581c1f859d4Smrg      return;
582c1f859d4Smrg
583c1f859d4Smrg   switch (pname) {
584c1f859d4Smrg   case GL_TEXTURE_MIN_FILTER:
585c1f859d4Smrg   case GL_TEXTURE_MAG_FILTER:
586c1f859d4Smrg   case GL_TEXTURE_WRAP_S:
587c1f859d4Smrg   case GL_TEXTURE_WRAP_T:
588c1f859d4Smrg   case GL_TEXTURE_WRAP_R:
589c1f859d4Smrg   case GL_TEXTURE_BASE_LEVEL:
590c1f859d4Smrg   case GL_TEXTURE_MAX_LEVEL:
591c1f859d4Smrg   case GL_GENERATE_MIPMAP_SGIS:
592c1f859d4Smrg   case GL_TEXTURE_COMPARE_MODE_ARB:
593c1f859d4Smrg   case GL_TEXTURE_COMPARE_FUNC_ARB:
594c1f859d4Smrg   case GL_DEPTH_TEXTURE_MODE_ARB:
595c1f859d4Smrg      {
596c1f859d4Smrg         /* convert float param to int */
5974a49301eSmrg         GLint p[4];
5984a49301eSmrg         p[0] = (GLint) params[0];
5994a49301eSmrg         p[1] = p[2] = p[3] = 0;
6004a49301eSmrg         need_update = set_tex_parameteri(ctx, texObj, pname, p);
601c1f859d4Smrg      }
602c1f859d4Smrg      break;
603c1f859d4Smrg
604c1f859d4Smrg#ifdef FEATURE_OES_draw_texture
605c1f859d4Smrg   case GL_TEXTURE_CROP_RECT_OES:
606c1f859d4Smrg      {
607c1f859d4Smrg         /* convert float params to int */
608c1f859d4Smrg         GLint iparams[4];
609c1f859d4Smrg         iparams[0] = (GLint) params[0];
610c1f859d4Smrg         iparams[1] = (GLint) params[1];
611c1f859d4Smrg         iparams[2] = (GLint) params[2];
612c1f859d4Smrg         iparams[3] = (GLint) params[3];
6134a49301eSmrg         need_update = set_tex_parameteri(ctx, texObj, pname, iparams);
614c1f859d4Smrg      }
615c1f859d4Smrg      break;
616c1f859d4Smrg#endif
617c1f859d4Smrg
618c1f859d4Smrg   default:
619c1f859d4Smrg      /* this will generate an error if pname is illegal */
620c1f859d4Smrg      need_update = set_tex_parameterf(ctx, texObj, pname, params);
621c1f859d4Smrg   }
622c1f859d4Smrg
623c1f859d4Smrg   if (ctx->Driver.TexParameter && need_update) {
624c1f859d4Smrg      ctx->Driver.TexParameter(ctx, target, texObj, pname, params);
625c1f859d4Smrg   }
626c1f859d4Smrg}
627c1f859d4Smrg
628c1f859d4Smrg
629c1f859d4Smrgvoid GLAPIENTRY
630c1f859d4Smrg_mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
631c1f859d4Smrg{
632c1f859d4Smrg   GLboolean need_update;
633c1f859d4Smrg   struct gl_texture_object *texObj;
634c1f859d4Smrg   GET_CURRENT_CONTEXT(ctx);
635c1f859d4Smrg   ASSERT_OUTSIDE_BEGIN_END(ctx);
636c1f859d4Smrg
637c1f859d4Smrg   texObj = get_texobj(ctx, target);
638c1f859d4Smrg   if (!texObj)
639c1f859d4Smrg      return;
640c1f859d4Smrg
641c1f859d4Smrg   switch (pname) {
642c1f859d4Smrg   case GL_TEXTURE_MIN_LOD:
643c1f859d4Smrg   case GL_TEXTURE_MAX_LOD:
644c1f859d4Smrg   case GL_TEXTURE_PRIORITY:
645c1f859d4Smrg   case GL_TEXTURE_MAX_ANISOTROPY_EXT:
646c1f859d4Smrg   case GL_TEXTURE_LOD_BIAS:
6474a49301eSmrg   case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
648c1f859d4Smrg      {
6494a49301eSmrg         GLfloat fparam[4];
6504a49301eSmrg         fparam[0] = (GLfloat) param;
6514a49301eSmrg         fparam[1] = fparam[2] = fparam[3] = 0.0F;
652c1f859d4Smrg         /* convert int param to float */
6534a49301eSmrg         need_update = set_tex_parameterf(ctx, texObj, pname, fparam);
654c1f859d4Smrg      }
655c1f859d4Smrg      break;
656c1f859d4Smrg   default:
657c1f859d4Smrg      /* this will generate an error if pname is illegal */
6584a49301eSmrg      {
6594a49301eSmrg         GLint iparam[4];
6604a49301eSmrg         iparam[0] = param;
6614a49301eSmrg         iparam[1] = iparam[2] = iparam[3] = 0;
6624a49301eSmrg         need_update = set_tex_parameteri(ctx, texObj, pname, iparam);
6634a49301eSmrg      }
664c1f859d4Smrg   }
665c1f859d4Smrg
666c1f859d4Smrg   if (ctx->Driver.TexParameter && need_update) {
667c1f859d4Smrg      GLfloat fparam = (GLfloat) param;
668c1f859d4Smrg      ctx->Driver.TexParameter(ctx, target, texObj, pname, &fparam);
669c1f859d4Smrg   }
670c1f859d4Smrg}
671c1f859d4Smrg
672c1f859d4Smrg
673c1f859d4Smrgvoid GLAPIENTRY
674c1f859d4Smrg_mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
675c1f859d4Smrg{
676c1f859d4Smrg   GLboolean need_update;
677c1f859d4Smrg   struct gl_texture_object *texObj;
678c1f859d4Smrg   GET_CURRENT_CONTEXT(ctx);
679c1f859d4Smrg   ASSERT_OUTSIDE_BEGIN_END(ctx);
680c1f859d4Smrg
681c1f859d4Smrg   texObj = get_texobj(ctx, target);
682c1f859d4Smrg   if (!texObj)
683c1f859d4Smrg      return;
684c1f859d4Smrg
685c1f859d4Smrg   switch (pname) {
686c1f859d4Smrg   case GL_TEXTURE_BORDER_COLOR:
687c1f859d4Smrg      {
688c1f859d4Smrg         /* convert int params to float */
689c1f859d4Smrg         GLfloat fparams[4];
690c1f859d4Smrg         fparams[0] = INT_TO_FLOAT(params[0]);
691c1f859d4Smrg         fparams[1] = INT_TO_FLOAT(params[1]);
692c1f859d4Smrg         fparams[2] = INT_TO_FLOAT(params[2]);
693c1f859d4Smrg         fparams[3] = INT_TO_FLOAT(params[3]);
694c1f859d4Smrg         need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
695c1f859d4Smrg      }
696c1f859d4Smrg      break;
697c1f859d4Smrg   case GL_TEXTURE_MIN_LOD:
698c1f859d4Smrg   case GL_TEXTURE_MAX_LOD:
699c1f859d4Smrg   case GL_TEXTURE_PRIORITY:
700c1f859d4Smrg   case GL_TEXTURE_MAX_ANISOTROPY_EXT:
701c1f859d4Smrg   case GL_TEXTURE_LOD_BIAS:
7024a49301eSmrg   case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
703c1f859d4Smrg      {
704c1f859d4Smrg         /* convert int param to float */
7054a49301eSmrg         GLfloat fparams[4];
7064a49301eSmrg         fparams[0] = (GLfloat) params[0];
7074a49301eSmrg         fparams[1] = fparams[2] = fparams[3] = 0.0F;
7084a49301eSmrg         need_update = set_tex_parameterf(ctx, texObj, pname, fparams);
709c1f859d4Smrg      }
710c1f859d4Smrg      break;
711c1f859d4Smrg   default:
712c1f859d4Smrg      /* this will generate an error if pname is illegal */
713c1f859d4Smrg      need_update = set_tex_parameteri(ctx, texObj, pname, params);
714c1f859d4Smrg   }
715c1f859d4Smrg
716c1f859d4Smrg   if (ctx->Driver.TexParameter && need_update) {
717c1f859d4Smrg      GLfloat fparams[4];
718c1f859d4Smrg      fparams[0] = INT_TO_FLOAT(params[0]);
719c1f859d4Smrg      if (pname == GL_TEXTURE_BORDER_COLOR ||
720c1f859d4Smrg          pname == GL_TEXTURE_CROP_RECT_OES) {
721c1f859d4Smrg         fparams[1] = INT_TO_FLOAT(params[1]);
722c1f859d4Smrg         fparams[2] = INT_TO_FLOAT(params[2]);
723c1f859d4Smrg         fparams[3] = INT_TO_FLOAT(params[3]);
724c1f859d4Smrg      }
725c1f859d4Smrg      ctx->Driver.TexParameter(ctx, target, texObj, pname, fparams);
726c1f859d4Smrg   }
727c1f859d4Smrg}
728c1f859d4Smrg
729c1f859d4Smrg
730c1f859d4Smrgvoid GLAPIENTRY
731c1f859d4Smrg_mesa_GetTexLevelParameterfv( GLenum target, GLint level,
732c1f859d4Smrg                              GLenum pname, GLfloat *params )
733c1f859d4Smrg{
734c1f859d4Smrg   GLint iparam;
735c1f859d4Smrg   _mesa_GetTexLevelParameteriv( target, level, pname, &iparam );
736c1f859d4Smrg   *params = (GLfloat) iparam;
737c1f859d4Smrg}
738c1f859d4Smrg
739c1f859d4Smrg
740c1f859d4Smrgvoid GLAPIENTRY
741c1f859d4Smrg_mesa_GetTexLevelParameteriv( GLenum target, GLint level,
742c1f859d4Smrg                              GLenum pname, GLint *params )
743c1f859d4Smrg{
744c1f859d4Smrg   const struct gl_texture_unit *texUnit;
745c1f859d4Smrg   struct gl_texture_object *texObj;
746c1f859d4Smrg   const struct gl_texture_image *img = NULL;
747c1f859d4Smrg   GLboolean isProxy;
748c1f859d4Smrg   GLint maxLevels;
7494a49301eSmrg   gl_format texFormat;
750c1f859d4Smrg   GET_CURRENT_CONTEXT(ctx);
751c1f859d4Smrg   ASSERT_OUTSIDE_BEGIN_END(ctx);
752c1f859d4Smrg
753c1f859d4Smrg   if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureImageUnits) {
754c1f859d4Smrg      _mesa_error(ctx, GL_INVALID_OPERATION,
755c1f859d4Smrg                  "glGetTexLevelParameteriv(current unit)");
756c1f859d4Smrg      return;
757c1f859d4Smrg   }
758c1f859d4Smrg
7594a49301eSmrg   texUnit = _mesa_get_current_tex_unit(ctx);
760c1f859d4Smrg
761c1f859d4Smrg   /* this will catch bad target values */
762c1f859d4Smrg   maxLevels = _mesa_max_texture_levels(ctx, target);
763c1f859d4Smrg   if (maxLevels == 0) {
7644a49301eSmrg      _mesa_error(ctx, GL_INVALID_ENUM,
7654a49301eSmrg                  "glGetTexLevelParameter[if]v(target=0x%x)", target);
766c1f859d4Smrg      return;
767c1f859d4Smrg   }
768c1f859d4Smrg
769c1f859d4Smrg   if (level < 0 || level >= maxLevels) {
770c1f859d4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
771c1f859d4Smrg      return;
772c1f859d4Smrg   }
773c1f859d4Smrg
774c1f859d4Smrg   texObj = _mesa_select_tex_object(ctx, texUnit, target);
775c1f859d4Smrg   _mesa_lock_texture(ctx, texObj);
776c1f859d4Smrg
777c1f859d4Smrg   img = _mesa_select_tex_image(ctx, texObj, target, level);
778c1f859d4Smrg   if (!img || !img->TexFormat) {
779c1f859d4Smrg      /* undefined texture image */
780c1f859d4Smrg      if (pname == GL_TEXTURE_COMPONENTS)
781c1f859d4Smrg         *params = 1;
782c1f859d4Smrg      else
783c1f859d4Smrg         *params = 0;
784c1f859d4Smrg      goto out;
785c1f859d4Smrg   }
786c1f859d4Smrg
7874a49301eSmrg   texFormat = img->TexFormat;
7884a49301eSmrg
789c1f859d4Smrg   isProxy = _mesa_is_proxy_texture(target);
790c1f859d4Smrg
791c1f859d4Smrg   switch (pname) {
792c1f859d4Smrg      case GL_TEXTURE_WIDTH:
793c1f859d4Smrg         *params = img->Width;
794c1f859d4Smrg         break;
795c1f859d4Smrg      case GL_TEXTURE_HEIGHT:
796c1f859d4Smrg         *params = img->Height;
797c1f859d4Smrg         break;
798c1f859d4Smrg      case GL_TEXTURE_DEPTH:
799c1f859d4Smrg         *params = img->Depth;
800c1f859d4Smrg         break;
801c1f859d4Smrg      case GL_TEXTURE_INTERNAL_FORMAT:
8024a49301eSmrg         if (_mesa_is_format_compressed(img->TexFormat)) {
8034a49301eSmrg            /* need to return the actual compressed format */
8044a49301eSmrg            *params = _mesa_compressed_format_to_glenum(ctx, img->TexFormat);
8054a49301eSmrg         }
8064a49301eSmrg         else {
8074a49301eSmrg            /* return the user's requested internal format */
8084a49301eSmrg            *params = img->InternalFormat;
8094a49301eSmrg         }
810c1f859d4Smrg         break;
811c1f859d4Smrg      case GL_TEXTURE_BORDER:
812c1f859d4Smrg         *params = img->Border;
813c1f859d4Smrg         break;
814c1f859d4Smrg      case GL_TEXTURE_RED_SIZE:
815c1f859d4Smrg      case GL_TEXTURE_GREEN_SIZE:
816c1f859d4Smrg      case GL_TEXTURE_BLUE_SIZE:
817c1f859d4Smrg         if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
8184a49301eSmrg            *params = _mesa_get_format_bits(texFormat, pname);
819c1f859d4Smrg         else
820c1f859d4Smrg            *params = 0;
821c1f859d4Smrg         break;
822c1f859d4Smrg      case GL_TEXTURE_ALPHA_SIZE:
823c1f859d4Smrg         if (img->_BaseFormat == GL_ALPHA ||
824c1f859d4Smrg             img->_BaseFormat == GL_LUMINANCE_ALPHA ||
825c1f859d4Smrg             img->_BaseFormat == GL_RGBA)
8264a49301eSmrg            *params = _mesa_get_format_bits(texFormat, pname);
827c1f859d4Smrg         else
828c1f859d4Smrg            *params = 0;
829c1f859d4Smrg         break;
830c1f859d4Smrg      case GL_TEXTURE_INTENSITY_SIZE:
831c1f859d4Smrg         if (img->_BaseFormat != GL_INTENSITY)
832c1f859d4Smrg            *params = 0;
8334a49301eSmrg         else {
8344a49301eSmrg            *params = _mesa_get_format_bits(texFormat, pname);
8354a49301eSmrg            if (*params == 0) {
8364a49301eSmrg               /* intensity probably stored as rgb texture */
8374a49301eSmrg               *params = MIN2(_mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE),
8384a49301eSmrg                              _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE));
8394a49301eSmrg            }
8404a49301eSmrg         }
841c1f859d4Smrg         break;
842c1f859d4Smrg      case GL_TEXTURE_LUMINANCE_SIZE:
843c1f859d4Smrg         if (img->_BaseFormat != GL_LUMINANCE &&
844c1f859d4Smrg             img->_BaseFormat != GL_LUMINANCE_ALPHA)
845c1f859d4Smrg            *params = 0;
8464a49301eSmrg         else {
8474a49301eSmrg            *params = _mesa_get_format_bits(texFormat, pname);
8484a49301eSmrg            if (*params == 0) {
8494a49301eSmrg               /* luminance probably stored as rgb texture */
8504a49301eSmrg               *params = MIN2(_mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE),
8514a49301eSmrg                              _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE));
8524a49301eSmrg            }
8534a49301eSmrg         }
854c1f859d4Smrg         break;
855c1f859d4Smrg      case GL_TEXTURE_INDEX_SIZE_EXT:
856c1f859d4Smrg         if (img->_BaseFormat == GL_COLOR_INDEX)
8574a49301eSmrg            *params = _mesa_get_format_bits(texFormat, pname);
858c1f859d4Smrg         else
859c1f859d4Smrg            *params = 0;
860c1f859d4Smrg         break;
861c1f859d4Smrg      case GL_TEXTURE_DEPTH_SIZE_ARB:
862c1f859d4Smrg         if (ctx->Extensions.ARB_depth_texture)
8634a49301eSmrg            *params = _mesa_get_format_bits(texFormat, pname);
864c1f859d4Smrg         else
865c1f859d4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
866c1f859d4Smrg                        "glGetTexLevelParameter[if]v(pname)");
867c1f859d4Smrg         break;
868c1f859d4Smrg      case GL_TEXTURE_STENCIL_SIZE_EXT:
8694a49301eSmrg         if (ctx->Extensions.EXT_packed_depth_stencil ||
8704a49301eSmrg             ctx->Extensions.ARB_framebuffer_object) {
8714a49301eSmrg            *params = _mesa_get_format_bits(texFormat, pname);
872c1f859d4Smrg         }
873c1f859d4Smrg         else {
874c1f859d4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
875c1f859d4Smrg                        "glGetTexLevelParameter[if]v(pname)");
876c1f859d4Smrg         }
877c1f859d4Smrg         break;
878c1f859d4Smrg
879c1f859d4Smrg      /* GL_ARB_texture_compression */
880c1f859d4Smrg      case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
8814a49301eSmrg	 if (_mesa_is_format_compressed(img->TexFormat) && !isProxy) {
8824a49301eSmrg            *params = _mesa_format_image_size(texFormat, img->Width,
8834a49301eSmrg                                              img->Height, img->Depth);
8844a49301eSmrg	 }
8854a49301eSmrg	 else {
8864a49301eSmrg	    _mesa_error(ctx, GL_INVALID_OPERATION,
8874a49301eSmrg			"glGetTexLevelParameter[if]v(pname)");
8884a49301eSmrg	 }
889c1f859d4Smrg         break;
890c1f859d4Smrg      case GL_TEXTURE_COMPRESSED:
8914a49301eSmrg         *params = (GLint) _mesa_is_format_compressed(img->TexFormat);
892c1f859d4Smrg         break;
893c1f859d4Smrg
894c1f859d4Smrg      /* GL_ARB_texture_float */
895c1f859d4Smrg      case GL_TEXTURE_RED_TYPE_ARB:
896c1f859d4Smrg         if (ctx->Extensions.ARB_texture_float) {
8974a49301eSmrg            *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE) ?
8984a49301eSmrg               _mesa_get_format_datatype(texFormat) : GL_NONE;
899c1f859d4Smrg         }
900c1f859d4Smrg         else {
901c1f859d4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
902c1f859d4Smrg                        "glGetTexLevelParameter[if]v(pname)");
903c1f859d4Smrg         }
904c1f859d4Smrg         break;
905c1f859d4Smrg      case GL_TEXTURE_GREEN_TYPE_ARB:
906c1f859d4Smrg         if (ctx->Extensions.ARB_texture_float) {
9074a49301eSmrg            *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE) ?
9084a49301eSmrg               _mesa_get_format_datatype(texFormat) : GL_NONE;
909c1f859d4Smrg         }
910c1f859d4Smrg         else {
911c1f859d4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
912c1f859d4Smrg                        "glGetTexLevelParameter[if]v(pname)");
913c1f859d4Smrg         }
914c1f859d4Smrg         break;
915c1f859d4Smrg      case GL_TEXTURE_BLUE_TYPE_ARB:
916c1f859d4Smrg         if (ctx->Extensions.ARB_texture_float) {
9174a49301eSmrg            *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_BLUE_SIZE) ?
9184a49301eSmrg               _mesa_get_format_datatype(texFormat) : GL_NONE;
919c1f859d4Smrg         }
920c1f859d4Smrg         else {
921c1f859d4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
922c1f859d4Smrg                        "glGetTexLevelParameter[if]v(pname)");
923c1f859d4Smrg         }
924c1f859d4Smrg         break;
925c1f859d4Smrg      case GL_TEXTURE_ALPHA_TYPE_ARB:
926c1f859d4Smrg         if (ctx->Extensions.ARB_texture_float) {
9274a49301eSmrg            *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_ALPHA_SIZE) ?
9284a49301eSmrg               _mesa_get_format_datatype(texFormat) : GL_NONE;
929c1f859d4Smrg         }
930c1f859d4Smrg         else {
931c1f859d4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
932c1f859d4Smrg                        "glGetTexLevelParameter[if]v(pname)");
933c1f859d4Smrg         }
934c1f859d4Smrg         break;
935c1f859d4Smrg      case GL_TEXTURE_LUMINANCE_TYPE_ARB:
936c1f859d4Smrg         if (ctx->Extensions.ARB_texture_float) {
9374a49301eSmrg            *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_LUMINANCE_SIZE) ?
9384a49301eSmrg               _mesa_get_format_datatype(texFormat) : GL_NONE;
939c1f859d4Smrg         }
940c1f859d4Smrg         else {
941c1f859d4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
942c1f859d4Smrg                        "glGetTexLevelParameter[if]v(pname)");
943c1f859d4Smrg         }
944c1f859d4Smrg         break;
945c1f859d4Smrg      case GL_TEXTURE_INTENSITY_TYPE_ARB:
946c1f859d4Smrg         if (ctx->Extensions.ARB_texture_float) {
9474a49301eSmrg            *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_INTENSITY_SIZE) ?
9484a49301eSmrg               _mesa_get_format_datatype(texFormat) : GL_NONE;
949c1f859d4Smrg         }
950c1f859d4Smrg         else {
951c1f859d4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
952c1f859d4Smrg                        "glGetTexLevelParameter[if]v(pname)");
953c1f859d4Smrg         }
954c1f859d4Smrg         break;
955c1f859d4Smrg      case GL_TEXTURE_DEPTH_TYPE_ARB:
956c1f859d4Smrg         if (ctx->Extensions.ARB_texture_float) {
9574a49301eSmrg            *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_DEPTH_SIZE) ?
9584a49301eSmrg               _mesa_get_format_datatype(texFormat) : GL_NONE;
959c1f859d4Smrg         }
960c1f859d4Smrg         else {
961c1f859d4Smrg            _mesa_error(ctx, GL_INVALID_ENUM,
962c1f859d4Smrg                        "glGetTexLevelParameter[if]v(pname)");
963c1f859d4Smrg         }
964c1f859d4Smrg         break;
965c1f859d4Smrg
966c1f859d4Smrg      default:
967c1f859d4Smrg         _mesa_error(ctx, GL_INVALID_ENUM,
968c1f859d4Smrg                     "glGetTexLevelParameter[if]v(pname)");
969c1f859d4Smrg   }
970c1f859d4Smrg
971c1f859d4Smrg out:
972c1f859d4Smrg   _mesa_unlock_texture(ctx, texObj);
973c1f859d4Smrg}
974c1f859d4Smrg
975c1f859d4Smrg
976c1f859d4Smrg
977c1f859d4Smrgvoid GLAPIENTRY
978c1f859d4Smrg_mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
979c1f859d4Smrg{
980c1f859d4Smrg   struct gl_texture_unit *texUnit;
981c1f859d4Smrg   struct gl_texture_object *obj;
982c1f859d4Smrg   GLboolean error = GL_FALSE;
983c1f859d4Smrg   GET_CURRENT_CONTEXT(ctx);
984c1f859d4Smrg   ASSERT_OUTSIDE_BEGIN_END(ctx);
985c1f859d4Smrg
986c1f859d4Smrg   if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureImageUnits) {
987c1f859d4Smrg      _mesa_error(ctx, GL_INVALID_OPERATION,
988c1f859d4Smrg                  "glGetTexParameterfv(current unit)");
989c1f859d4Smrg      return;
990c1f859d4Smrg   }
991c1f859d4Smrg
9924a49301eSmrg   texUnit = _mesa_get_current_tex_unit(ctx);
993c1f859d4Smrg
994c1f859d4Smrg   obj = _mesa_select_tex_object(ctx, texUnit, target);
995c1f859d4Smrg   if (!obj) {
996c1f859d4Smrg      _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(target)");
997c1f859d4Smrg      return;
998c1f859d4Smrg   }
999c1f859d4Smrg
1000c1f859d4Smrg   _mesa_lock_texture(ctx, obj);
1001c1f859d4Smrg   switch (pname) {
1002c1f859d4Smrg      case GL_TEXTURE_MAG_FILTER:
1003c1f859d4Smrg	 *params = ENUM_TO_FLOAT(obj->MagFilter);
1004c1f859d4Smrg	 break;
1005c1f859d4Smrg      case GL_TEXTURE_MIN_FILTER:
1006c1f859d4Smrg         *params = ENUM_TO_FLOAT(obj->MinFilter);
1007c1f859d4Smrg         break;
1008c1f859d4Smrg      case GL_TEXTURE_WRAP_S:
1009c1f859d4Smrg         *params = ENUM_TO_FLOAT(obj->WrapS);
1010c1f859d4Smrg         break;
1011c1f859d4Smrg      case GL_TEXTURE_WRAP_T:
1012c1f859d4Smrg         *params = ENUM_TO_FLOAT(obj->WrapT);
1013c1f859d4Smrg         break;
1014c1f859d4Smrg      case GL_TEXTURE_WRAP_R:
1015c1f859d4Smrg         *params = ENUM_TO_FLOAT(obj->WrapR);
1016c1f859d4Smrg         break;
1017c1f859d4Smrg      case GL_TEXTURE_BORDER_COLOR:
1018c1f859d4Smrg         params[0] = CLAMP(obj->BorderColor[0], 0.0F, 1.0F);
1019c1f859d4Smrg         params[1] = CLAMP(obj->BorderColor[1], 0.0F, 1.0F);
1020c1f859d4Smrg         params[2] = CLAMP(obj->BorderColor[2], 0.0F, 1.0F);
1021c1f859d4Smrg         params[3] = CLAMP(obj->BorderColor[3], 0.0F, 1.0F);
1022c1f859d4Smrg         break;
1023c1f859d4Smrg      case GL_TEXTURE_RESIDENT:
1024c1f859d4Smrg         {
1025c1f859d4Smrg            GLboolean resident;
1026c1f859d4Smrg            if (ctx->Driver.IsTextureResident)
1027c1f859d4Smrg               resident = ctx->Driver.IsTextureResident(ctx, obj);
1028c1f859d4Smrg            else
1029c1f859d4Smrg               resident = GL_TRUE;
1030c1f859d4Smrg            *params = ENUM_TO_FLOAT(resident);
1031c1f859d4Smrg         }
1032c1f859d4Smrg         break;
1033c1f859d4Smrg      case GL_TEXTURE_PRIORITY:
1034c1f859d4Smrg         *params = obj->Priority;
1035c1f859d4Smrg         break;
1036c1f859d4Smrg      case GL_TEXTURE_MIN_LOD:
1037c1f859d4Smrg         *params = obj->MinLod;
1038c1f859d4Smrg         break;
1039c1f859d4Smrg      case GL_TEXTURE_MAX_LOD:
1040c1f859d4Smrg         *params = obj->MaxLod;
1041c1f859d4Smrg         break;
1042c1f859d4Smrg      case GL_TEXTURE_BASE_LEVEL:
1043c1f859d4Smrg         *params = (GLfloat) obj->BaseLevel;
1044c1f859d4Smrg         break;
1045c1f859d4Smrg      case GL_TEXTURE_MAX_LEVEL:
1046c1f859d4Smrg         *params = (GLfloat) obj->MaxLevel;
1047c1f859d4Smrg         break;
1048c1f859d4Smrg      case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1049c1f859d4Smrg         if (ctx->Extensions.EXT_texture_filter_anisotropic) {
1050c1f859d4Smrg            *params = obj->MaxAnisotropy;
1051c1f859d4Smrg         }
1052c1f859d4Smrg	 else
10534a49301eSmrg	    error = GL_TRUE;
1054c1f859d4Smrg         break;
10554a49301eSmrg      case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
10564a49301eSmrg         if (ctx->Extensions.ARB_shadow_ambient) {
10574a49301eSmrg            *params = obj->CompareFailValue;
1058c1f859d4Smrg         }
1059c1f859d4Smrg	 else
10604a49301eSmrg	    error = GL_TRUE;
1061c1f859d4Smrg         break;
1062c1f859d4Smrg      case GL_GENERATE_MIPMAP_SGIS:
1063c1f859d4Smrg         if (ctx->Extensions.SGIS_generate_mipmap) {
1064c1f859d4Smrg            *params = (GLfloat) obj->GenerateMipmap;
1065c1f859d4Smrg         }
1066c1f859d4Smrg	 else
10674a49301eSmrg	    error = GL_TRUE;
1068c1f859d4Smrg         break;
1069c1f859d4Smrg      case GL_TEXTURE_COMPARE_MODE_ARB:
1070c1f859d4Smrg         if (ctx->Extensions.ARB_shadow) {
1071c1f859d4Smrg            *params = (GLfloat) obj->CompareMode;
1072c1f859d4Smrg         }
1073c1f859d4Smrg	 else
10744a49301eSmrg	    error = GL_TRUE;
1075c1f859d4Smrg         break;
1076c1f859d4Smrg      case GL_TEXTURE_COMPARE_FUNC_ARB:
1077c1f859d4Smrg         if (ctx->Extensions.ARB_shadow) {
1078c1f859d4Smrg            *params = (GLfloat) obj->CompareFunc;
1079c1f859d4Smrg         }
1080c1f859d4Smrg	 else
10814a49301eSmrg	    error = GL_TRUE;
1082c1f859d4Smrg         break;
1083c1f859d4Smrg      case GL_DEPTH_TEXTURE_MODE_ARB:
1084c1f859d4Smrg         if (ctx->Extensions.ARB_depth_texture) {
1085c1f859d4Smrg            *params = (GLfloat) obj->DepthMode;
1086c1f859d4Smrg         }
1087c1f859d4Smrg	 else
10884a49301eSmrg	    error = GL_TRUE;
1089c1f859d4Smrg         break;
1090c1f859d4Smrg      case GL_TEXTURE_LOD_BIAS:
1091c1f859d4Smrg         if (ctx->Extensions.EXT_texture_lod_bias) {
1092c1f859d4Smrg            *params = obj->LodBias;
1093c1f859d4Smrg         }
1094c1f859d4Smrg	 else
10954a49301eSmrg	    error = GL_TRUE;
1096c1f859d4Smrg         break;
1097c1f859d4Smrg#ifdef FEATURE_OES_draw_texture
1098c1f859d4Smrg      case GL_TEXTURE_CROP_RECT_OES:
1099c1f859d4Smrg         params[0] = obj->CropRect[0];
1100c1f859d4Smrg         params[1] = obj->CropRect[1];
1101c1f859d4Smrg         params[2] = obj->CropRect[2];
1102c1f859d4Smrg         params[3] = obj->CropRect[3];
1103c1f859d4Smrg         break;
1104c1f859d4Smrg#endif
11054a49301eSmrg
11064a49301eSmrg      case GL_TEXTURE_SWIZZLE_R_EXT:
11074a49301eSmrg      case GL_TEXTURE_SWIZZLE_G_EXT:
11084a49301eSmrg      case GL_TEXTURE_SWIZZLE_B_EXT:
11094a49301eSmrg      case GL_TEXTURE_SWIZZLE_A_EXT:
11104a49301eSmrg         if (ctx->Extensions.EXT_texture_swizzle) {
11114a49301eSmrg            GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
11124a49301eSmrg            *params = (GLfloat) obj->Swizzle[comp];
11134a49301eSmrg         }
11144a49301eSmrg         else {
11154a49301eSmrg            error = GL_TRUE;
11164a49301eSmrg         }
11174a49301eSmrg         break;
11184a49301eSmrg
11194a49301eSmrg      case GL_TEXTURE_SWIZZLE_RGBA_EXT:
11204a49301eSmrg         if (ctx->Extensions.EXT_texture_swizzle) {
11214a49301eSmrg            GLuint comp;
11224a49301eSmrg            for (comp = 0; comp < 4; comp++) {
11234a49301eSmrg               params[comp] = (GLfloat) obj->Swizzle[comp];
11244a49301eSmrg            }
11254a49301eSmrg         }
11264a49301eSmrg         else {
11274a49301eSmrg            error = GL_TRUE;
11284a49301eSmrg         }
11294a49301eSmrg         break;
11304a49301eSmrg
1131c1f859d4Smrg      default:
11324a49301eSmrg	 error = GL_TRUE;
1133c1f859d4Smrg	 break;
1134c1f859d4Smrg   }
11354a49301eSmrg
1136c1f859d4Smrg   if (error)
1137c1f859d4Smrg      _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname=0x%x)",
1138c1f859d4Smrg		  pname);
1139c1f859d4Smrg
1140c1f859d4Smrg   _mesa_unlock_texture(ctx, obj);
1141c1f859d4Smrg}
1142c1f859d4Smrg
1143c1f859d4Smrg
1144c1f859d4Smrgvoid GLAPIENTRY
1145c1f859d4Smrg_mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
1146c1f859d4Smrg{
1147c1f859d4Smrg   struct gl_texture_unit *texUnit;
1148c1f859d4Smrg   struct gl_texture_object *obj;
11494a49301eSmrg   GLboolean error = GL_FALSE;
1150c1f859d4Smrg   GET_CURRENT_CONTEXT(ctx);
1151c1f859d4Smrg   ASSERT_OUTSIDE_BEGIN_END(ctx);
1152c1f859d4Smrg
1153c1f859d4Smrg   if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureImageUnits) {
1154c1f859d4Smrg      _mesa_error(ctx, GL_INVALID_OPERATION,
1155c1f859d4Smrg                  "glGetTexParameteriv(current unit)");
1156c1f859d4Smrg      return;
1157c1f859d4Smrg   }
1158c1f859d4Smrg
11594a49301eSmrg   texUnit = _mesa_get_current_tex_unit(ctx);
1160c1f859d4Smrg
1161c1f859d4Smrg   obj = _mesa_select_tex_object(ctx, texUnit, target);
1162c1f859d4Smrg   if (!obj) {
1163c1f859d4Smrg      _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(target)");
1164c1f859d4Smrg      return;
1165c1f859d4Smrg   }
1166c1f859d4Smrg
11674a49301eSmrg   _mesa_lock_texture(ctx, obj);
1168c1f859d4Smrg   switch (pname) {
1169c1f859d4Smrg      case GL_TEXTURE_MAG_FILTER:
1170c1f859d4Smrg         *params = (GLint) obj->MagFilter;
11714a49301eSmrg         break;;
1172c1f859d4Smrg      case GL_TEXTURE_MIN_FILTER:
1173c1f859d4Smrg         *params = (GLint) obj->MinFilter;
11744a49301eSmrg         break;;
1175c1f859d4Smrg      case GL_TEXTURE_WRAP_S:
1176c1f859d4Smrg         *params = (GLint) obj->WrapS;
11774a49301eSmrg         break;;
1178c1f859d4Smrg      case GL_TEXTURE_WRAP_T:
1179c1f859d4Smrg         *params = (GLint) obj->WrapT;
11804a49301eSmrg         break;;
1181c1f859d4Smrg      case GL_TEXTURE_WRAP_R:
1182c1f859d4Smrg         *params = (GLint) obj->WrapR;
11834a49301eSmrg         break;;
1184c1f859d4Smrg      case GL_TEXTURE_BORDER_COLOR:
1185c1f859d4Smrg         {
1186c1f859d4Smrg            GLfloat b[4];
1187c1f859d4Smrg            b[0] = CLAMP(obj->BorderColor[0], 0.0F, 1.0F);
1188c1f859d4Smrg            b[1] = CLAMP(obj->BorderColor[1], 0.0F, 1.0F);
1189c1f859d4Smrg            b[2] = CLAMP(obj->BorderColor[2], 0.0F, 1.0F);
1190c1f859d4Smrg            b[3] = CLAMP(obj->BorderColor[3], 0.0F, 1.0F);
1191c1f859d4Smrg            params[0] = FLOAT_TO_INT(b[0]);
1192c1f859d4Smrg            params[1] = FLOAT_TO_INT(b[1]);
1193c1f859d4Smrg            params[2] = FLOAT_TO_INT(b[2]);
1194c1f859d4Smrg            params[3] = FLOAT_TO_INT(b[3]);
1195c1f859d4Smrg         }
11964a49301eSmrg         break;;
1197c1f859d4Smrg      case GL_TEXTURE_RESIDENT:
1198c1f859d4Smrg         {
1199c1f859d4Smrg            GLboolean resident;
1200c1f859d4Smrg            if (ctx->Driver.IsTextureResident)
1201c1f859d4Smrg               resident = ctx->Driver.IsTextureResident(ctx, obj);
1202c1f859d4Smrg            else
1203c1f859d4Smrg               resident = GL_TRUE;
1204c1f859d4Smrg            *params = (GLint) resident;
1205c1f859d4Smrg         }
12064a49301eSmrg         break;;
1207c1f859d4Smrg      case GL_TEXTURE_PRIORITY:
1208c1f859d4Smrg         *params = FLOAT_TO_INT(obj->Priority);
12094a49301eSmrg         break;;
1210c1f859d4Smrg      case GL_TEXTURE_MIN_LOD:
1211c1f859d4Smrg         *params = (GLint) obj->MinLod;
12124a49301eSmrg         break;;
1213c1f859d4Smrg      case GL_TEXTURE_MAX_LOD:
1214c1f859d4Smrg         *params = (GLint) obj->MaxLod;
12154a49301eSmrg         break;;
1216c1f859d4Smrg      case GL_TEXTURE_BASE_LEVEL:
1217c1f859d4Smrg         *params = obj->BaseLevel;
12184a49301eSmrg         break;;
1219c1f859d4Smrg      case GL_TEXTURE_MAX_LEVEL:
1220c1f859d4Smrg         *params = obj->MaxLevel;
12214a49301eSmrg         break;;
1222c1f859d4Smrg      case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1223c1f859d4Smrg         if (ctx->Extensions.EXT_texture_filter_anisotropic) {
1224c1f859d4Smrg            *params = (GLint) obj->MaxAnisotropy;
1225c1f859d4Smrg         }
12264a49301eSmrg         else {
12274a49301eSmrg            error = GL_TRUE;
1228c1f859d4Smrg         }
1229c1f859d4Smrg         break;
12304a49301eSmrg      case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
12314a49301eSmrg         if (ctx->Extensions.ARB_shadow_ambient) {
12324a49301eSmrg            *params = (GLint) FLOAT_TO_INT(obj->CompareFailValue);
1233c1f859d4Smrg         }
12344a49301eSmrg         else {
12354a49301eSmrg            error = GL_TRUE;
1236c1f859d4Smrg         }
1237c1f859d4Smrg         break;
1238c1f859d4Smrg      case GL_GENERATE_MIPMAP_SGIS:
1239c1f859d4Smrg         if (ctx->Extensions.SGIS_generate_mipmap) {
1240c1f859d4Smrg            *params = (GLint) obj->GenerateMipmap;
12414a49301eSmrg         }
12424a49301eSmrg         else {
12434a49301eSmrg            error = GL_TRUE;
1244c1f859d4Smrg         }
1245c1f859d4Smrg         break;
1246c1f859d4Smrg      case GL_TEXTURE_COMPARE_MODE_ARB:
1247c1f859d4Smrg         if (ctx->Extensions.ARB_shadow) {
1248c1f859d4Smrg            *params = (GLint) obj->CompareMode;
12494a49301eSmrg         }
12504a49301eSmrg         else {
12514a49301eSmrg            error = GL_TRUE;
1252c1f859d4Smrg         }
1253c1f859d4Smrg         break;
1254c1f859d4Smrg      case GL_TEXTURE_COMPARE_FUNC_ARB:
1255c1f859d4Smrg         if (ctx->Extensions.ARB_shadow) {
1256c1f859d4Smrg            *params = (GLint) obj->CompareFunc;
12574a49301eSmrg         }
12584a49301eSmrg         else {
12594a49301eSmrg            error = GL_TRUE;
1260c1f859d4Smrg         }
1261c1f859d4Smrg         break;
1262c1f859d4Smrg      case GL_DEPTH_TEXTURE_MODE_ARB:
1263c1f859d4Smrg         if (ctx->Extensions.ARB_depth_texture) {
1264c1f859d4Smrg            *params = (GLint) obj->DepthMode;
12654a49301eSmrg         }
12664a49301eSmrg         else {
12674a49301eSmrg            error = GL_TRUE;
1268c1f859d4Smrg         }
1269c1f859d4Smrg         break;
1270c1f859d4Smrg      case GL_TEXTURE_LOD_BIAS:
1271c1f859d4Smrg         if (ctx->Extensions.EXT_texture_lod_bias) {
1272c1f859d4Smrg            *params = (GLint) obj->LodBias;
12734a49301eSmrg         }
12744a49301eSmrg         else {
12754a49301eSmrg            error = GL_TRUE;
1276c1f859d4Smrg         }
1277c1f859d4Smrg         break;
1278c1f859d4Smrg#ifdef FEATURE_OES_draw_texture
1279c1f859d4Smrg      case GL_TEXTURE_CROP_RECT_OES:
1280c1f859d4Smrg         params[0] = obj->CropRect[0];
1281c1f859d4Smrg         params[1] = obj->CropRect[1];
1282c1f859d4Smrg         params[2] = obj->CropRect[2];
1283c1f859d4Smrg         params[3] = obj->CropRect[3];
1284c1f859d4Smrg         break;
1285c1f859d4Smrg#endif
12864a49301eSmrg      case GL_TEXTURE_SWIZZLE_R_EXT:
12874a49301eSmrg      case GL_TEXTURE_SWIZZLE_G_EXT:
12884a49301eSmrg      case GL_TEXTURE_SWIZZLE_B_EXT:
12894a49301eSmrg      case GL_TEXTURE_SWIZZLE_A_EXT:
12904a49301eSmrg         if (ctx->Extensions.EXT_texture_swizzle) {
12914a49301eSmrg            GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
12924a49301eSmrg            *params = obj->Swizzle[comp];
12934a49301eSmrg         }
12944a49301eSmrg         else {
12954a49301eSmrg            error = GL_TRUE;
12964a49301eSmrg         }
12974a49301eSmrg         break;
12984a49301eSmrg
12994a49301eSmrg      case GL_TEXTURE_SWIZZLE_RGBA_EXT:
13004a49301eSmrg         if (ctx->Extensions.EXT_texture_swizzle) {
13014a49301eSmrg            COPY_4V(params, obj->Swizzle);
13024a49301eSmrg         }
13034a49301eSmrg         else {
13044a49301eSmrg            error = GL_TRUE;
13054a49301eSmrg         }
13064a49301eSmrg         break;
13074a49301eSmrg
1308c1f859d4Smrg      default:
1309c1f859d4Smrg         ; /* silence warnings */
1310c1f859d4Smrg   }
13114a49301eSmrg
13124a49301eSmrg   if (error)
13134a49301eSmrg      _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname=0x%x)",
13144a49301eSmrg		  pname);
13154a49301eSmrg
13164a49301eSmrg   _mesa_unlock_texture(ctx, obj);
1317c1f859d4Smrg}
1318