1c1f859d4Smrg/*
2c1f859d4Smrg * Mesa 3-D graphics library
3c1f859d4Smrg *
4c1f859d4Smrg * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
5c1f859d4Smrg * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
6c1f859d4Smrg *
7c1f859d4Smrg * Permission is hereby granted, free of charge, to any person obtaining a
8c1f859d4Smrg * copy of this software and associated documentation files (the "Software"),
9c1f859d4Smrg * to deal in the Software without restriction, including without limitation
10c1f859d4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11c1f859d4Smrg * and/or sell copies of the Software, and to permit persons to whom the
12c1f859d4Smrg * Software is furnished to do so, subject to the following conditions:
13c1f859d4Smrg *
14c1f859d4Smrg * The above copyright notice and this permission notice shall be included
15c1f859d4Smrg * in all copies or substantial portions of the Software.
16c1f859d4Smrg *
17c1f859d4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18c1f859d4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19c1f859d4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE.
24c1f859d4Smrg */
25c1f859d4Smrg
26af69d88dSmrg/**
27c1f859d4Smrg * \file texparam.c
28c1f859d4Smrg *
29c1f859d4Smrg * glTexParameter-related functions
30c1f859d4Smrg */
31c1f859d4Smrg
32af69d88dSmrg#include <stdbool.h>
33c1f859d4Smrg#include "main/glheader.h"
34af69d88dSmrg#include "main/blend.h"
354a49301eSmrg#include "main/context.h"
363464ebd5Sriastradh#include "main/enums.h"
374a49301eSmrg#include "main/formats.h"
38af69d88dSmrg#include "main/glformats.h"
39c1f859d4Smrg#include "main/macros.h"
403464ebd5Sriastradh#include "main/mtypes.h"
413464ebd5Sriastradh#include "main/state.h"
42c1f859d4Smrg#include "main/texcompress.h"
43af69d88dSmrg#include "main/texobj.h"
44c1f859d4Smrg#include "main/texparam.h"
45c1f859d4Smrg#include "main/teximage.h"
464a49301eSmrg#include "main/texstate.h"
473464ebd5Sriastradh#include "program/prog_instruction.h"
487ec681f3Smrg#include "util/u_math.h"
49c1f859d4Smrg
507ec681f3Smrg/**
517ec681f3Smrg * Use macro to resolve undefined clamping behaviour when using lroundf
527ec681f3Smrg */
537ec681f3Smrg#define LCLAMPF(a, lmin, lmax) ((a) > (lmin) ? ( (a) >= (lmax) ? (lmax) : (lroundf(a)) ) : (lmin))
54c1f859d4Smrg
55c1f859d4Smrg/**
56c1f859d4Smrg * Check if a coordinate wrap mode is supported for the texture target.
57c1f859d4Smrg * \return GL_TRUE if legal, GL_FALSE otherwise
58c1f859d4Smrg */
59af69d88dSmrgstatic GLboolean
603464ebd5Sriastradhvalidate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
61c1f859d4Smrg{
62c1f859d4Smrg   const struct gl_extensions * const e = & ctx->Extensions;
63af69d88dSmrg   const bool is_desktop_gl = _mesa_is_desktop_gl(ctx);
64af69d88dSmrg   bool supported;
65af69d88dSmrg
66af69d88dSmrg   switch (wrap) {
67af69d88dSmrg   case GL_CLAMP:
68af69d88dSmrg      /* GL_CLAMP was removed in the core profile, and it has never existed in
69af69d88dSmrg       * OpenGL ES.
70af69d88dSmrg       */
71af69d88dSmrg      supported = (ctx->API == API_OPENGL_COMPAT)
72af69d88dSmrg         && (target != GL_TEXTURE_EXTERNAL_OES);
73af69d88dSmrg      break;
74c1f859d4Smrg
75af69d88dSmrg   case GL_CLAMP_TO_EDGE:
76af69d88dSmrg      supported = true;
77af69d88dSmrg      break;
78af69d88dSmrg
79af69d88dSmrg   case GL_CLAMP_TO_BORDER:
8001e04c3fSmrg      supported = ctx->API != API_OPENGLES && e->ARB_texture_border_clamp
81af69d88dSmrg         && (target != GL_TEXTURE_EXTERNAL_OES);
82af69d88dSmrg      break;
83af69d88dSmrg
84af69d88dSmrg   case GL_REPEAT:
85af69d88dSmrg   case GL_MIRRORED_REPEAT:
86af69d88dSmrg      supported = (target != GL_TEXTURE_RECTANGLE_NV)
87af69d88dSmrg         && (target != GL_TEXTURE_EXTERNAL_OES);
88af69d88dSmrg      break;
89af69d88dSmrg
90af69d88dSmrg   case GL_MIRROR_CLAMP_EXT:
91af69d88dSmrg      supported = is_desktop_gl
92af69d88dSmrg         && (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)
93af69d88dSmrg         && (target != GL_TEXTURE_RECTANGLE_NV)
94af69d88dSmrg         && (target != GL_TEXTURE_EXTERNAL_OES);
95af69d88dSmrg      break;
96af69d88dSmrg
97af69d88dSmrg   case GL_MIRROR_CLAMP_TO_EDGE_EXT:
987ec681f3Smrg      supported = (target != GL_TEXTURE_RECTANGLE_NV)
997ec681f3Smrg         && (target != GL_TEXTURE_EXTERNAL_OES)
1007ec681f3Smrg         && (_mesa_has_ARB_texture_mirror_clamp_to_edge(ctx) ||
1017ec681f3Smrg            _mesa_has_ATI_texture_mirror_once(ctx) ||
1027ec681f3Smrg            _mesa_has_EXT_texture_mirror_clamp(ctx));
103af69d88dSmrg      break;
104af69d88dSmrg
105af69d88dSmrg   case GL_MIRROR_CLAMP_TO_BORDER_EXT:
106af69d88dSmrg      supported = is_desktop_gl && e->EXT_texture_mirror_clamp
107af69d88dSmrg         && (target != GL_TEXTURE_RECTANGLE_NV)
108af69d88dSmrg         && (target != GL_TEXTURE_EXTERNAL_OES);
109af69d88dSmrg      break;
110af69d88dSmrg
111af69d88dSmrg   default:
112af69d88dSmrg      supported = false;
113af69d88dSmrg      break;
114c1f859d4Smrg   }
115c1f859d4Smrg
116af69d88dSmrg   if (!supported)
117af69d88dSmrg      _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(param=0x%x)", wrap );
118af69d88dSmrg
119af69d88dSmrg   return supported;
120c1f859d4Smrg}
121c1f859d4Smrg
122c1f859d4Smrg
1237ec681f3Smrgstatic bool
1247ec681f3Smrgis_texparameteri_target_valid(GLenum target)
125c1f859d4Smrg{
1267ec681f3Smrg   switch (target) {
1277ec681f3Smrg   case GL_TEXTURE_1D:
1287ec681f3Smrg   case GL_TEXTURE_1D_ARRAY:
1297ec681f3Smrg   case GL_TEXTURE_2D:
1307ec681f3Smrg   case GL_TEXTURE_2D_ARRAY:
1317ec681f3Smrg   case GL_TEXTURE_2D_MULTISAMPLE:
1327ec681f3Smrg   case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
1337ec681f3Smrg   case GL_TEXTURE_3D:
1347ec681f3Smrg   case GL_TEXTURE_CUBE_MAP:
1357ec681f3Smrg   case GL_TEXTURE_CUBE_MAP_ARRAY:
1367ec681f3Smrg   case GL_TEXTURE_RECTANGLE:
1377ec681f3Smrg      return true;
1387ec681f3Smrg   default:
1397ec681f3Smrg      return false;
140c1f859d4Smrg   }
141c1f859d4Smrg}
142c1f859d4Smrg
1437ec681f3Smrg
14401e04c3fSmrg/**
14501e04c3fSmrg * Get current texture object for given name.
14601e04c3fSmrg * Return NULL if any error (and record the error).
14701e04c3fSmrg * Note that proxy targets are not accepted.
14801e04c3fSmrg * Only the glGetTexLevelParameter() functions accept proxy targets.
14901e04c3fSmrg */
15001e04c3fSmrgstatic struct gl_texture_object *
15101e04c3fSmrgget_texobj_by_name(struct gl_context *ctx, GLuint texture, const char *name)
15201e04c3fSmrg{
15301e04c3fSmrg   struct gl_texture_object *texObj;
15401e04c3fSmrg
15501e04c3fSmrg   texObj = _mesa_lookup_texture_err(ctx, texture, name);
15601e04c3fSmrg   if (!texObj)
15701e04c3fSmrg      return NULL;
15801e04c3fSmrg
1597ec681f3Smrg   if (!is_texparameteri_target_valid(texObj->Target)) {
16001e04c3fSmrg      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(target)", name);
16101e04c3fSmrg      return NULL;
16201e04c3fSmrg   }
16301e04c3fSmrg
1647ec681f3Smrg   return texObj;
16501e04c3fSmrg}
16601e04c3fSmrg
167c1f859d4Smrg
1684a49301eSmrg/**
1694a49301eSmrg * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
1704a49301eSmrg * \return -1 if error.
1714a49301eSmrg */
1724a49301eSmrgstatic GLint
1734a49301eSmrgcomp_to_swizzle(GLenum comp)
1744a49301eSmrg{
1754a49301eSmrg   switch (comp) {
1764a49301eSmrg   case GL_RED:
1774a49301eSmrg      return SWIZZLE_X;
1784a49301eSmrg   case GL_GREEN:
1794a49301eSmrg      return SWIZZLE_Y;
1804a49301eSmrg   case GL_BLUE:
1814a49301eSmrg      return SWIZZLE_Z;
1824a49301eSmrg   case GL_ALPHA:
1834a49301eSmrg      return SWIZZLE_W;
1844a49301eSmrg   case GL_ZERO:
1854a49301eSmrg      return SWIZZLE_ZERO;
1864a49301eSmrg   case GL_ONE:
1874a49301eSmrg      return SWIZZLE_ONE;
1884a49301eSmrg   default:
1894a49301eSmrg      return -1;
1904a49301eSmrg   }
1914a49301eSmrg}
1924a49301eSmrg
1934a49301eSmrg
1944a49301eSmrgstatic void
19501e04c3fSmrgset_swizzle_component(GLushort *swizzle, GLuint comp, GLuint swz)
1964a49301eSmrg{
19701e04c3fSmrg   assert(comp < 4);
19801e04c3fSmrg   assert(swz <= SWIZZLE_NIL);
1994a49301eSmrg   {
2004a49301eSmrg      GLuint mask = 0x7 << (3 * comp);
2014a49301eSmrg      GLuint s = (*swizzle & ~mask) | (swz << (3 * comp));
2024a49301eSmrg      *swizzle = s;
2034a49301eSmrg   }
2044a49301eSmrg}
2054a49301eSmrg
2064a49301eSmrg
207c1f859d4Smrg/**
2083464ebd5Sriastradh * This is called just prior to changing any texture object state which
20901e04c3fSmrg * will not affect texture completeness.
2103464ebd5Sriastradh */
211af69d88dSmrgstatic inline void
2123464ebd5Sriastradhflush(struct gl_context *ctx)
2133464ebd5Sriastradh{
2147ec681f3Smrg   FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT, GL_TEXTURE_BIT);
2153464ebd5Sriastradh}
2163464ebd5Sriastradh
2173464ebd5Sriastradh
2183464ebd5Sriastradh/**
2193464ebd5Sriastradh * This is called just prior to changing any texture object state which
22001e04c3fSmrg * could affect texture completeness (texture base level, max level).
22101e04c3fSmrg * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE_OBJECT
222c1f859d4Smrg * state flag and then mark the texture object as 'incomplete' so that any
223c1f859d4Smrg * per-texture derived state gets recomputed.
224c1f859d4Smrg */
225af69d88dSmrgstatic inline void
2263464ebd5Sriastradhincomplete(struct gl_context *ctx, struct gl_texture_object *texObj)
227c1f859d4Smrg{
2287ec681f3Smrg   FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT, GL_TEXTURE_BIT);
229af69d88dSmrg   _mesa_dirty_texobj(ctx, texObj);
230af69d88dSmrg}
231af69d88dSmrg
232af69d88dSmrg
23301e04c3fSmrgGLboolean
23401e04c3fSmrg_mesa_target_allows_setting_sampler_parameters(GLenum target)
235af69d88dSmrg{
236af69d88dSmrg   switch (target) {
237af69d88dSmrg   case GL_TEXTURE_2D_MULTISAMPLE:
238af69d88dSmrg   case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
239af69d88dSmrg      return GL_FALSE;
240af69d88dSmrg
241af69d88dSmrg   default:
242af69d88dSmrg      return GL_TRUE;
243af69d88dSmrg   }
244c1f859d4Smrg}
245c1f859d4Smrg
246c1f859d4Smrg
2477ec681f3Smrgstatic inline GLboolean
2487ec681f3Smrgis_wrap_gl_clamp(GLint param)
2497ec681f3Smrg{
2507ec681f3Smrg   return param == GL_CLAMP || param == GL_MIRROR_CLAMP_EXT;
2517ec681f3Smrg}
2527ec681f3Smrg
253c1f859d4Smrg/**
254c1f859d4Smrg * Set an integer-valued texture parameter
255c1f859d4Smrg * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
256c1f859d4Smrg */
257c1f859d4Smrgstatic GLboolean
2583464ebd5Sriastradhset_tex_parameteri(struct gl_context *ctx,
259c1f859d4Smrg                   struct gl_texture_object *texObj,
26001e04c3fSmrg                   GLenum pname, const GLint *params, bool dsa)
261c1f859d4Smrg{
26201e04c3fSmrg   const char *suffix = dsa ? "ture" : "";
26301e04c3fSmrg
26401e04c3fSmrg   if (texObj->HandleAllocated) {
26501e04c3fSmrg      /* The ARB_bindless_texture spec says:
26601e04c3fSmrg       *
26701e04c3fSmrg       * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
26801e04c3fSmrg       * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
26901e04c3fSmrg       * functions defined in terms of these, if the texture object to be
27001e04c3fSmrg       * modified is referenced by one or more texture or image handles."
27101e04c3fSmrg       */
27201e04c3fSmrg      _mesa_error(ctx, GL_INVALID_OPERATION,
27301e04c3fSmrg                  "glTex%sParameter(immutable texture)", suffix);
27401e04c3fSmrg      return GL_FALSE;
27501e04c3fSmrg   }
27601e04c3fSmrg
277c1f859d4Smrg   switch (pname) {
278c1f859d4Smrg   case GL_TEXTURE_MIN_FILTER:
27901e04c3fSmrg      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
2807ec681f3Smrg         goto invalid_dsa;
281af69d88dSmrg
2827ec681f3Smrg      if (texObj->Sampler.Attrib.MinFilter == params[0])
283c1f859d4Smrg         return GL_FALSE;
284c1f859d4Smrg      switch (params[0]) {
285c1f859d4Smrg      case GL_NEAREST:
286c1f859d4Smrg      case GL_LINEAR:
287af69d88dSmrg         flush(ctx);
2887ec681f3Smrg         texObj->Sampler.Attrib.MinFilter = params[0];
2897ec681f3Smrg         texObj->Sampler.Attrib.state.min_img_filter = filter_to_gallium(params[0]);
2907ec681f3Smrg         texObj->Sampler.Attrib.state.min_mip_filter = mipfilter_to_gallium(params[0]);
2917ec681f3Smrg         _mesa_lower_gl_clamp(ctx, &texObj->Sampler);
292c1f859d4Smrg         return GL_TRUE;
293c1f859d4Smrg      case GL_NEAREST_MIPMAP_NEAREST:
294c1f859d4Smrg      case GL_LINEAR_MIPMAP_NEAREST:
295c1f859d4Smrg      case GL_NEAREST_MIPMAP_LINEAR:
296c1f859d4Smrg      case GL_LINEAR_MIPMAP_LINEAR:
297af69d88dSmrg         if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
298af69d88dSmrg             texObj->Target != GL_TEXTURE_EXTERNAL_OES) {
299af69d88dSmrg            flush(ctx);
3007ec681f3Smrg            texObj->Sampler.Attrib.MinFilter = params[0];
3017ec681f3Smrg            texObj->Sampler.Attrib.state.min_img_filter = filter_to_gallium(params[0]);
3027ec681f3Smrg            texObj->Sampler.Attrib.state.min_mip_filter = mipfilter_to_gallium(params[0]);
3037ec681f3Smrg            _mesa_lower_gl_clamp(ctx, &texObj->Sampler);
304c1f859d4Smrg            return GL_TRUE;
305c1f859d4Smrg         }
3067ec681f3Smrg         FALLTHROUGH;
307c1f859d4Smrg      default:
3083464ebd5Sriastradh         goto invalid_param;
309c1f859d4Smrg      }
310c1f859d4Smrg      return GL_FALSE;
311c1f859d4Smrg
312c1f859d4Smrg   case GL_TEXTURE_MAG_FILTER:
31301e04c3fSmrg      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
3147ec681f3Smrg         goto invalid_dsa;
315af69d88dSmrg
3167ec681f3Smrg      if (texObj->Sampler.Attrib.MagFilter == params[0])
317c1f859d4Smrg         return GL_FALSE;
318c1f859d4Smrg      switch (params[0]) {
319c1f859d4Smrg      case GL_NEAREST:
320c1f859d4Smrg      case GL_LINEAR:
3213464ebd5Sriastradh         flush(ctx); /* does not effect completeness */
3227ec681f3Smrg         texObj->Sampler.Attrib.MagFilter = params[0];
3237ec681f3Smrg         texObj->Sampler.Attrib.state.mag_img_filter = filter_to_gallium(params[0]);
3247ec681f3Smrg         _mesa_lower_gl_clamp(ctx, &texObj->Sampler);
325c1f859d4Smrg         return GL_TRUE;
326c1f859d4Smrg      default:
3273464ebd5Sriastradh         goto invalid_param;
328c1f859d4Smrg      }
329c1f859d4Smrg      return GL_FALSE;
330c1f859d4Smrg
331c1f859d4Smrg   case GL_TEXTURE_WRAP_S:
33201e04c3fSmrg      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
3337ec681f3Smrg         goto invalid_dsa;
334af69d88dSmrg
3357ec681f3Smrg      if (texObj->Sampler.Attrib.WrapS == params[0])
336c1f859d4Smrg         return GL_FALSE;
337c1f859d4Smrg      if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
3383464ebd5Sriastradh         flush(ctx);
3397ec681f3Smrg         if (is_wrap_gl_clamp(texObj->Sampler.Attrib.WrapS) != is_wrap_gl_clamp(params[0]))
3407ec681f3Smrg            ctx->NewDriverState |= ctx->DriverFlags.NewSamplersWithClamp;
3417ec681f3Smrg         texObj->Sampler.Attrib.WrapS = params[0];
3427ec681f3Smrg         texObj->Sampler.Attrib.state.wrap_s = wrap_to_gallium(params[0]);
3437ec681f3Smrg         _mesa_lower_gl_clamp(ctx, &texObj->Sampler);
344c1f859d4Smrg         return GL_TRUE;
345c1f859d4Smrg      }
346c1f859d4Smrg      return GL_FALSE;
347c1f859d4Smrg
348c1f859d4Smrg   case GL_TEXTURE_WRAP_T:
34901e04c3fSmrg      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
3507ec681f3Smrg         goto invalid_dsa;
351af69d88dSmrg
3527ec681f3Smrg      if (texObj->Sampler.Attrib.WrapT == params[0])
353c1f859d4Smrg         return GL_FALSE;
354c1f859d4Smrg      if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
3553464ebd5Sriastradh         flush(ctx);
3567ec681f3Smrg         if (is_wrap_gl_clamp(texObj->Sampler.Attrib.WrapT) != is_wrap_gl_clamp(params[0]))
3577ec681f3Smrg            ctx->NewDriverState |= ctx->DriverFlags.NewSamplersWithClamp;
3587ec681f3Smrg         texObj->Sampler.Attrib.WrapT = params[0];
3597ec681f3Smrg         texObj->Sampler.Attrib.state.wrap_t = wrap_to_gallium(params[0]);
3607ec681f3Smrg         _mesa_lower_gl_clamp(ctx, &texObj->Sampler);
361c1f859d4Smrg         return GL_TRUE;
362c1f859d4Smrg      }
363c1f859d4Smrg      return GL_FALSE;
364c1f859d4Smrg
365c1f859d4Smrg   case GL_TEXTURE_WRAP_R:
36601e04c3fSmrg      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
3677ec681f3Smrg         goto invalid_dsa;
368af69d88dSmrg
3697ec681f3Smrg      if (texObj->Sampler.Attrib.WrapR == params[0])
370c1f859d4Smrg         return GL_FALSE;
371c1f859d4Smrg      if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
3723464ebd5Sriastradh         flush(ctx);
3737ec681f3Smrg         if (is_wrap_gl_clamp(texObj->Sampler.Attrib.WrapR) != is_wrap_gl_clamp(params[0]))
3747ec681f3Smrg            ctx->NewDriverState |= ctx->DriverFlags.NewSamplersWithClamp;
3757ec681f3Smrg         texObj->Sampler.Attrib.WrapR = params[0];
3767ec681f3Smrg         texObj->Sampler.Attrib.state.wrap_r = wrap_to_gallium(params[0]);
3777ec681f3Smrg         _mesa_lower_gl_clamp(ctx, &texObj->Sampler);
378c1f859d4Smrg         return GL_TRUE;
379c1f859d4Smrg      }
380c1f859d4Smrg      return GL_FALSE;
381c1f859d4Smrg
382c1f859d4Smrg   case GL_TEXTURE_BASE_LEVEL:
383af69d88dSmrg      if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
384af69d88dSmrg         goto invalid_pname;
385af69d88dSmrg
3867ec681f3Smrg      if (texObj->Attrib.BaseLevel == params[0])
387c1f859d4Smrg         return GL_FALSE;
388af69d88dSmrg
38901e04c3fSmrg      /* Section 8.10 (Texture Parameters) of the OpenGL 4.5 Core Profile spec
39001e04c3fSmrg       * says:
39101e04c3fSmrg       *
39201e04c3fSmrg       *    An INVALID_OPERATION error is generated if the effective target is
39301e04c3fSmrg       *    TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY, or
39401e04c3fSmrg       *    TEXTURE_RECTANGLE, and pname TEXTURE_BASE_LEVEL is set to a value
39501e04c3fSmrg       *    other than zero.
39601e04c3fSmrg       *
39701e04c3fSmrg       * Note that section 3.8.8 (Texture Parameters) of the OpenGL 3.3 Core
39801e04c3fSmrg       * Profile spec said:
39901e04c3fSmrg       *
40001e04c3fSmrg       *    The error INVALID_VALUE is generated if TEXTURE_BASE_LEVEL is set
40101e04c3fSmrg       *    to any value other than zero.
40201e04c3fSmrg       *
40301e04c3fSmrg       * We take the 4.5 language as a correction to 3.3, and we implement
40401e04c3fSmrg       * that on all GL versions.
40501e04c3fSmrg       */
406af69d88dSmrg      if ((texObj->Target == GL_TEXTURE_2D_MULTISAMPLE ||
40701e04c3fSmrg           texObj->Target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY ||
40801e04c3fSmrg           texObj->Target == GL_TEXTURE_RECTANGLE) && params[0] != 0)
409af69d88dSmrg         goto invalid_operation;
410af69d88dSmrg
41101e04c3fSmrg      if (params[0] < 0) {
4124a49301eSmrg         _mesa_error(ctx, GL_INVALID_VALUE,
41301e04c3fSmrg                     "glTex%sParameter(param=%d)", suffix, params[0]);
414c1f859d4Smrg         return GL_FALSE;
415c1f859d4Smrg      }
4163464ebd5Sriastradh      incomplete(ctx, texObj);
417af69d88dSmrg
418af69d88dSmrg      /** See note about ARB_texture_storage below */
419af69d88dSmrg      if (texObj->Immutable)
4207ec681f3Smrg         texObj->Attrib.BaseLevel = MIN2(texObj->Attrib.ImmutableLevels - 1, params[0]);
421af69d88dSmrg      else
4227ec681f3Smrg         texObj->Attrib.BaseLevel = params[0];
423af69d88dSmrg
424c1f859d4Smrg      return GL_TRUE;
425c1f859d4Smrg
426c1f859d4Smrg   case GL_TEXTURE_MAX_LEVEL:
4277ec681f3Smrg      if (texObj->Attrib.MaxLevel == params[0])
428c1f859d4Smrg         return GL_FALSE;
429af69d88dSmrg
430af69d88dSmrg      if (params[0] < 0 ||
431af69d88dSmrg          (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] > 0)) {
432af69d88dSmrg         _mesa_error(ctx, GL_INVALID_VALUE,
43301e04c3fSmrg                     "glTex%sParameter(param=%d)", suffix,
43401e04c3fSmrg                     params[0]);
435c1f859d4Smrg         return GL_FALSE;
436c1f859d4Smrg      }
4373464ebd5Sriastradh      incomplete(ctx, texObj);
438af69d88dSmrg
439af69d88dSmrg      /** From ARB_texture_storage:
440af69d88dSmrg       * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
441af69d88dSmrg       * clamped to the range [0, <levels> - 1] and level_max is then clamped to
442af69d88dSmrg       * the range [level_base, <levels> - 1], where <levels> is the parameter
443af69d88dSmrg       * passed the call to TexStorage* for the texture object.
444af69d88dSmrg       */
445af69d88dSmrg      if (texObj->Immutable)
4467ec681f3Smrg          texObj->Attrib.MaxLevel = CLAMP(params[0], texObj->Attrib.BaseLevel,
4477ec681f3Smrg                                   texObj->Attrib.ImmutableLevels - 1);
448af69d88dSmrg      else
4497ec681f3Smrg         texObj->Attrib.MaxLevel = params[0];
450af69d88dSmrg
451c1f859d4Smrg      return GL_TRUE;
452c1f859d4Smrg
453c1f859d4Smrg   case GL_GENERATE_MIPMAP_SGIS:
454af69d88dSmrg      if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
455af69d88dSmrg         goto invalid_pname;
456af69d88dSmrg
457af69d88dSmrg      if (params[0] && texObj->Target == GL_TEXTURE_EXTERNAL_OES)
458af69d88dSmrg         goto invalid_param;
4597ec681f3Smrg      if (texObj->Attrib.GenerateMipmap != params[0]) {
4603464ebd5Sriastradh         /* no flush() */
4617ec681f3Smrg	 texObj->Attrib.GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
4623464ebd5Sriastradh	 return GL_TRUE;
463c1f859d4Smrg      }
464c1f859d4Smrg      return GL_FALSE;
465c1f859d4Smrg
466c1f859d4Smrg   case GL_TEXTURE_COMPARE_MODE_ARB:
467af69d88dSmrg      if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow)
468af69d88dSmrg          || _mesa_is_gles3(ctx)) {
469af69d88dSmrg
47001e04c3fSmrg         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
4717ec681f3Smrg            goto invalid_dsa;
472af69d88dSmrg
4737ec681f3Smrg         if (texObj->Sampler.Attrib.CompareMode == params[0])
4743464ebd5Sriastradh            return GL_FALSE;
4753464ebd5Sriastradh         if (params[0] == GL_NONE ||
4763464ebd5Sriastradh             params[0] == GL_COMPARE_R_TO_TEXTURE_ARB) {
4773464ebd5Sriastradh            flush(ctx);
4787ec681f3Smrg            texObj->Sampler.Attrib.CompareMode = params[0];
479c1f859d4Smrg            return GL_TRUE;
480c1f859d4Smrg         }
4813464ebd5Sriastradh         goto invalid_param;
482c1f859d4Smrg      }
4833464ebd5Sriastradh      goto invalid_pname;
484c1f859d4Smrg
485c1f859d4Smrg   case GL_TEXTURE_COMPARE_FUNC_ARB:
486af69d88dSmrg      if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow)
487af69d88dSmrg          || _mesa_is_gles3(ctx)) {
488af69d88dSmrg
48901e04c3fSmrg         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
4907ec681f3Smrg            goto invalid_dsa;
491af69d88dSmrg
4927ec681f3Smrg         if (texObj->Sampler.Attrib.CompareFunc == params[0])
493c1f859d4Smrg            return GL_FALSE;
494c1f859d4Smrg         switch (params[0]) {
495c1f859d4Smrg         case GL_LEQUAL:
496c1f859d4Smrg         case GL_GEQUAL:
497c1f859d4Smrg         case GL_EQUAL:
498c1f859d4Smrg         case GL_NOTEQUAL:
499c1f859d4Smrg         case GL_LESS:
500c1f859d4Smrg         case GL_GREATER:
501c1f859d4Smrg         case GL_ALWAYS:
502c1f859d4Smrg         case GL_NEVER:
503af69d88dSmrg            flush(ctx);
5047ec681f3Smrg            texObj->Sampler.Attrib.CompareFunc = params[0];
5057ec681f3Smrg            texObj->Sampler.Attrib.state.compare_func = func_to_gallium(params[0]);
506af69d88dSmrg            return GL_TRUE;
507c1f859d4Smrg         default:
5083464ebd5Sriastradh            goto invalid_param;
509c1f859d4Smrg         }
510c1f859d4Smrg      }
5113464ebd5Sriastradh      goto invalid_pname;
512c1f859d4Smrg
513c1f859d4Smrg   case GL_DEPTH_TEXTURE_MODE_ARB:
514af69d88dSmrg      /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
515af69d88dSmrg       * existed in OpenGL ES.
516af69d88dSmrg       */
517af69d88dSmrg      if (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_depth_texture) {
5187ec681f3Smrg         if (texObj->Attrib.DepthMode == params[0])
5193464ebd5Sriastradh            return GL_FALSE;
5203464ebd5Sriastradh         if (params[0] == GL_LUMINANCE ||
5213464ebd5Sriastradh             params[0] == GL_INTENSITY ||
5223464ebd5Sriastradh             params[0] == GL_ALPHA ||
5233464ebd5Sriastradh             (ctx->Extensions.ARB_texture_rg && params[0] == GL_RED)) {
5243464ebd5Sriastradh            flush(ctx);
5257ec681f3Smrg            texObj->Attrib.DepthMode = params[0];
526c1f859d4Smrg            return GL_TRUE;
527c1f859d4Smrg         }
5283464ebd5Sriastradh         goto invalid_param;
529c1f859d4Smrg      }
5303464ebd5Sriastradh      goto invalid_pname;
531c1f859d4Smrg
532af69d88dSmrg   case GL_DEPTH_STENCIL_TEXTURE_MODE:
53301e04c3fSmrg      if (_mesa_has_ARB_stencil_texturing(ctx) || _mesa_is_gles31(ctx)) {
534af69d88dSmrg         bool stencil = params[0] == GL_STENCIL_INDEX;
535af69d88dSmrg         if (!stencil && params[0] != GL_DEPTH_COMPONENT)
536af69d88dSmrg            goto invalid_param;
537af69d88dSmrg
538af69d88dSmrg         if (texObj->StencilSampling == stencil)
539af69d88dSmrg            return GL_FALSE;
540af69d88dSmrg
5417ec681f3Smrg         /* This should not be restored by glPopAttrib. */
5427ec681f3Smrg         FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT, 0);
543af69d88dSmrg         texObj->StencilSampling = stencil;
544af69d88dSmrg         return GL_TRUE;
545af69d88dSmrg      }
546af69d88dSmrg      goto invalid_pname;
547af69d88dSmrg
548c1f859d4Smrg   case GL_TEXTURE_CROP_RECT_OES:
549af69d88dSmrg      if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
550af69d88dSmrg         goto invalid_pname;
551af69d88dSmrg
552c1f859d4Smrg      texObj->CropRect[0] = params[0];
553c1f859d4Smrg      texObj->CropRect[1] = params[1];
554c1f859d4Smrg      texObj->CropRect[2] = params[2];
555c1f859d4Smrg      texObj->CropRect[3] = params[3];
556c1f859d4Smrg      return GL_TRUE;
557c1f859d4Smrg
5584a49301eSmrg   case GL_TEXTURE_SWIZZLE_R_EXT:
5594a49301eSmrg   case GL_TEXTURE_SWIZZLE_G_EXT:
5604a49301eSmrg   case GL_TEXTURE_SWIZZLE_B_EXT:
5614a49301eSmrg   case GL_TEXTURE_SWIZZLE_A_EXT:
562af69d88dSmrg      if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_swizzle)
563af69d88dSmrg          || _mesa_is_gles3(ctx)) {
5644a49301eSmrg         const GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
5654a49301eSmrg         const GLint swz = comp_to_swizzle(params[0]);
5664a49301eSmrg         if (swz < 0) {
567af69d88dSmrg            _mesa_error(ctx, GL_INVALID_ENUM,
56801e04c3fSmrg                        "glTex%sParameter(swizzle 0x%x)", suffix, params[0]);
5694a49301eSmrg            return GL_FALSE;
5704a49301eSmrg         }
57101e04c3fSmrg         assert(comp < 4);
572af69d88dSmrg
573af69d88dSmrg         flush(ctx);
5747ec681f3Smrg         texObj->Attrib.Swizzle[comp] = params[0];
5757ec681f3Smrg         set_swizzle_component(&texObj->Attrib._Swizzle, comp, swz);
576af69d88dSmrg         return GL_TRUE;
5774a49301eSmrg      }
5783464ebd5Sriastradh      goto invalid_pname;
5794a49301eSmrg
5804a49301eSmrg   case GL_TEXTURE_SWIZZLE_RGBA_EXT:
581af69d88dSmrg      if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_swizzle)
582af69d88dSmrg          || _mesa_is_gles3(ctx)) {
5834a49301eSmrg         GLuint comp;
5843464ebd5Sriastradh         flush(ctx);
5854a49301eSmrg         for (comp = 0; comp < 4; comp++) {
5864a49301eSmrg            const GLint swz = comp_to_swizzle(params[comp]);
5874a49301eSmrg            if (swz >= 0) {
5887ec681f3Smrg               texObj->Attrib.Swizzle[comp] = params[comp];
5897ec681f3Smrg               set_swizzle_component(&texObj->Attrib._Swizzle, comp, swz);
5904a49301eSmrg            }
5914a49301eSmrg            else {
592af69d88dSmrg               _mesa_error(ctx, GL_INVALID_ENUM,
59301e04c3fSmrg                           "glTex%sParameter(swizzle 0x%x)",
59401e04c3fSmrg                           suffix, params[comp]);
5954a49301eSmrg               return GL_FALSE;
5964a49301eSmrg            }
5974a49301eSmrg         }
5984a49301eSmrg         return GL_TRUE;
5994a49301eSmrg      }
6003464ebd5Sriastradh      goto invalid_pname;
6013464ebd5Sriastradh
6023464ebd5Sriastradh   case GL_TEXTURE_SRGB_DECODE_EXT:
60301e04c3fSmrg      if (ctx->Extensions.EXT_texture_sRGB_decode) {
604af69d88dSmrg         GLenum decode = params[0];
605af69d88dSmrg
60601e04c3fSmrg         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
6077ec681f3Smrg            goto invalid_dsa;
608af69d88dSmrg
6093464ebd5Sriastradh	 if (decode == GL_DECODE_EXT || decode == GL_SKIP_DECODE_EXT) {
6107ec681f3Smrg	    if (texObj->Sampler.Attrib.sRGBDecode != decode) {
6113464ebd5Sriastradh	       flush(ctx);
6127ec681f3Smrg	       texObj->Sampler.Attrib.sRGBDecode = decode;
6133464ebd5Sriastradh	    }
6143464ebd5Sriastradh	    return GL_TRUE;
6153464ebd5Sriastradh	 }
6163464ebd5Sriastradh      }
6173464ebd5Sriastradh      goto invalid_pname;
6183464ebd5Sriastradh
6197ec681f3Smrg   case GL_TEXTURE_REDUCTION_MODE_EXT:
6207ec681f3Smrg      if (ctx->Extensions.EXT_texture_filter_minmax ||
6217ec681f3Smrg          _mesa_has_ARB_texture_filter_minmax(ctx)) {
6227ec681f3Smrg         GLenum mode = params[0];
6237ec681f3Smrg
6247ec681f3Smrg         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
6257ec681f3Smrg            goto invalid_dsa;
6267ec681f3Smrg
6277ec681f3Smrg         if (mode == GL_WEIGHTED_AVERAGE_EXT || mode == GL_MIN || mode == GL_MAX) {
6287ec681f3Smrg            if (texObj->Sampler.Attrib.ReductionMode != mode) {
6297ec681f3Smrg               flush(ctx);
6307ec681f3Smrg               texObj->Sampler.Attrib.ReductionMode = mode;
6317ec681f3Smrg               texObj->Sampler.Attrib.state.reduction_mode = reduction_to_gallium(mode);
6327ec681f3Smrg            }
6337ec681f3Smrg            return GL_TRUE;
6347ec681f3Smrg         }
6357ec681f3Smrg      }
6367ec681f3Smrg      goto invalid_pname;
6377ec681f3Smrg
6383464ebd5Sriastradh   case GL_TEXTURE_CUBE_MAP_SEAMLESS:
639af69d88dSmrg      if (_mesa_is_desktop_gl(ctx)
640af69d88dSmrg          && ctx->Extensions.AMD_seamless_cubemap_per_texture) {
6413464ebd5Sriastradh         GLenum param = params[0];
642af69d88dSmrg
64301e04c3fSmrg         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
6447ec681f3Smrg            goto invalid_dsa;
645af69d88dSmrg
6463464ebd5Sriastradh         if (param != GL_TRUE && param != GL_FALSE) {
6473464ebd5Sriastradh            goto invalid_param;
6483464ebd5Sriastradh         }
6497ec681f3Smrg         if (param != texObj->Sampler.Attrib.CubeMapSeamless) {
6503464ebd5Sriastradh            flush(ctx);
6517ec681f3Smrg            texObj->Sampler.Attrib.CubeMapSeamless = param;
6527ec681f3Smrg            texObj->Sampler.Attrib.state.seamless_cube_map = param;
6533464ebd5Sriastradh         }
6543464ebd5Sriastradh         return GL_TRUE;
6553464ebd5Sriastradh      }
6563464ebd5Sriastradh      goto invalid_pname;
6574a49301eSmrg
65801e04c3fSmrg   case GL_TEXTURE_TILING_EXT:
6597ec681f3Smrg      if (ctx->Extensions.EXT_memory_object && !texObj->Immutable) {
6607ec681f3Smrg            texObj->TextureTiling = params[0];
66101e04c3fSmrg
66201e04c3fSmrg         return GL_TRUE;
66301e04c3fSmrg      }
66401e04c3fSmrg      goto invalid_pname;
66501e04c3fSmrg
666c1f859d4Smrg   default:
6673464ebd5Sriastradh      goto invalid_pname;
668c1f859d4Smrg   }
6693464ebd5Sriastradh
6703464ebd5Sriastradhinvalid_pname:
67101e04c3fSmrg   _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
67201e04c3fSmrg               suffix, _mesa_enum_to_string(pname));
6733464ebd5Sriastradh   return GL_FALSE;
6743464ebd5Sriastradh
6753464ebd5Sriastradhinvalid_param:
67601e04c3fSmrg   _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(param=%s)",
67701e04c3fSmrg               suffix, _mesa_enum_to_string(params[0]));
678c1f859d4Smrg   return GL_FALSE;
679af69d88dSmrg
6807ec681f3Smrginvalid_dsa:
6817ec681f3Smrg   if (!dsa)
6827ec681f3Smrg      goto invalid_enum;
6837ec681f3Smrg
684af69d88dSmrginvalid_operation:
68501e04c3fSmrg   _mesa_error(ctx, GL_INVALID_OPERATION, "glTex%sParameter(pname=%s)",
68601e04c3fSmrg               suffix, _mesa_enum_to_string(pname));
68701e04c3fSmrg   return GL_FALSE;
68801e04c3fSmrg
68901e04c3fSmrginvalid_enum:
69001e04c3fSmrg   _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
69101e04c3fSmrg               suffix, _mesa_enum_to_string(pname));
692af69d88dSmrg   return GL_FALSE;
693c1f859d4Smrg}
694c1f859d4Smrg
695c1f859d4Smrg
696c1f859d4Smrg/**
697c1f859d4Smrg * Set a float-valued texture parameter
698c1f859d4Smrg * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
699c1f859d4Smrg */
700c1f859d4Smrgstatic GLboolean
7013464ebd5Sriastradhset_tex_parameterf(struct gl_context *ctx,
702c1f859d4Smrg                   struct gl_texture_object *texObj,
70301e04c3fSmrg                   GLenum pname, const GLfloat *params, bool dsa)
704c1f859d4Smrg{
70501e04c3fSmrg   const char *suffix = dsa ? "ture" : "";
70601e04c3fSmrg
70701e04c3fSmrg   if (texObj->HandleAllocated) {
70801e04c3fSmrg      /* The ARB_bindless_texture spec says:
70901e04c3fSmrg       *
71001e04c3fSmrg       * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
71101e04c3fSmrg       * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
71201e04c3fSmrg       * functions defined in terms of these, if the texture object to be
71301e04c3fSmrg       * modified is referenced by one or more texture or image handles."
71401e04c3fSmrg       */
71501e04c3fSmrg      _mesa_error(ctx, GL_INVALID_OPERATION,
71601e04c3fSmrg                  "glTex%sParameter(immutable texture)", suffix);
71701e04c3fSmrg      return GL_FALSE;
71801e04c3fSmrg   }
71901e04c3fSmrg
720c1f859d4Smrg   switch (pname) {
721c1f859d4Smrg   case GL_TEXTURE_MIN_LOD:
722af69d88dSmrg      if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
723af69d88dSmrg         goto invalid_pname;
724af69d88dSmrg
72501e04c3fSmrg      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
7267ec681f3Smrg         goto invalid_dsa;
727af69d88dSmrg
7287ec681f3Smrg      if (texObj->Sampler.Attrib.MinLod == params[0])
729c1f859d4Smrg         return GL_FALSE;
7303464ebd5Sriastradh      flush(ctx);
7317ec681f3Smrg      texObj->Sampler.Attrib.MinLod = params[0];
7327ec681f3Smrg      texObj->Sampler.Attrib.state.min_lod = MAX2(params[0], 0.0f); /* only positive vals */
733c1f859d4Smrg      return GL_TRUE;
734c1f859d4Smrg
735c1f859d4Smrg   case GL_TEXTURE_MAX_LOD:
736af69d88dSmrg      if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
737af69d88dSmrg         goto invalid_pname;
738af69d88dSmrg
73901e04c3fSmrg      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
7407ec681f3Smrg         goto invalid_dsa;
741af69d88dSmrg
7427ec681f3Smrg      if (texObj->Sampler.Attrib.MaxLod == params[0])
743c1f859d4Smrg         return GL_FALSE;
7443464ebd5Sriastradh      flush(ctx);
7457ec681f3Smrg      texObj->Sampler.Attrib.MaxLod = params[0];
7467ec681f3Smrg      texObj->Sampler.Attrib.state.max_lod = params[0];
747c1f859d4Smrg      return GL_TRUE;
748c1f859d4Smrg
749c1f859d4Smrg   case GL_TEXTURE_PRIORITY:
750af69d88dSmrg      if (ctx->API != API_OPENGL_COMPAT)
751af69d88dSmrg         goto invalid_pname;
752af69d88dSmrg
7533464ebd5Sriastradh      flush(ctx);
7547ec681f3Smrg      texObj->Attrib.Priority = CLAMP(params[0], 0.0F, 1.0F);
755c1f859d4Smrg      return GL_TRUE;
756c1f859d4Smrg
757c1f859d4Smrg   case GL_TEXTURE_MAX_ANISOTROPY_EXT:
758c1f859d4Smrg      if (ctx->Extensions.EXT_texture_filter_anisotropic) {
75901e04c3fSmrg         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
7607ec681f3Smrg            goto invalid_dsa;
761af69d88dSmrg
7627ec681f3Smrg         if (texObj->Sampler.Attrib.MaxAnisotropy == params[0])
763c1f859d4Smrg            return GL_FALSE;
76401e04c3fSmrg         if (params[0] < 1.0F) {
76501e04c3fSmrg            _mesa_error(ctx, GL_INVALID_VALUE, "glTex%sParameter(param)",
76601e04c3fSmrg                        suffix);
767c1f859d4Smrg            return GL_FALSE;
768c1f859d4Smrg         }
7693464ebd5Sriastradh         flush(ctx);
770c1f859d4Smrg         /* clamp to max, that's what NVIDIA does */
7717ec681f3Smrg         texObj->Sampler.Attrib.MaxAnisotropy = MIN2(params[0],
772c1f859d4Smrg                                      ctx->Const.MaxTextureMaxAnisotropy);
7737ec681f3Smrg         texObj->Sampler.Attrib.state.max_anisotropy =
7747ec681f3Smrg            texObj->Sampler.Attrib.MaxAnisotropy == 1 ?
7757ec681f3Smrg                  0 : texObj->Sampler.Attrib.MaxAnisotropy; /* gallium sets 0 for 1 */
776c1f859d4Smrg         return GL_TRUE;
777c1f859d4Smrg      }
778c1f859d4Smrg      else {
7794a49301eSmrg         static GLuint count = 0;
7804a49301eSmrg         if (count++ < 10)
781af69d88dSmrg            goto invalid_pname;
782c1f859d4Smrg      }
783c1f859d4Smrg      return GL_FALSE;
784c1f859d4Smrg
785c1f859d4Smrg   case GL_TEXTURE_LOD_BIAS:
786af69d88dSmrg      /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
787af69d88dSmrg      if (_mesa_is_gles(ctx))
788af69d88dSmrg         goto invalid_pname;
789af69d88dSmrg
79001e04c3fSmrg      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
7917ec681f3Smrg         goto invalid_dsa;
792af69d88dSmrg
7937ec681f3Smrg      if (texObj->Sampler.Attrib.LodBias != params[0]) {
794af69d88dSmrg	 flush(ctx);
7957ec681f3Smrg	 texObj->Sampler.Attrib.LodBias = params[0];
7967ec681f3Smrg         texObj->Sampler.Attrib.state.lod_bias = util_quantize_lod_bias(params[0]);
797af69d88dSmrg	 return GL_TRUE;
798c1f859d4Smrg      }
799c1f859d4Smrg      break;
800c1f859d4Smrg
801c1f859d4Smrg   case GL_TEXTURE_BORDER_COLOR:
80201e04c3fSmrg      /* Border color exists in desktop OpenGL since 1.0 for GL_CLAMP.  In
80301e04c3fSmrg       * OpenGL ES 2.0+, it only exists in when GL_OES_texture_border_clamp is
80401e04c3fSmrg       * enabled.  It is never available in OpenGL ES 1.x.
80501e04c3fSmrg       *
80601e04c3fSmrg       * FIXME: Every driver that supports GLES2 has this extension.  Elide
80701e04c3fSmrg       * the check?
80801e04c3fSmrg       */
80901e04c3fSmrg      if (ctx->API == API_OPENGLES ||
81001e04c3fSmrg          (ctx->API == API_OPENGLES2 &&
81101e04c3fSmrg           !ctx->Extensions.ARB_texture_border_clamp))
812af69d88dSmrg         goto invalid_pname;
813af69d88dSmrg
81401e04c3fSmrg      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
81501e04c3fSmrg         goto invalid_enum;
816af69d88dSmrg
8173464ebd5Sriastradh      flush(ctx);
8183464ebd5Sriastradh      /* ARB_texture_float disables clamping */
8193464ebd5Sriastradh      if (ctx->Extensions.ARB_texture_float) {
8207ec681f3Smrg         memcpy(texObj->Sampler.Attrib.state.border_color.f, params, 4 * sizeof(float));
8213464ebd5Sriastradh      } else {
8227ec681f3Smrg         texObj->Sampler.Attrib.state.border_color.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F);
8237ec681f3Smrg         texObj->Sampler.Attrib.state.border_color.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F);
8247ec681f3Smrg         texObj->Sampler.Attrib.state.border_color.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F);
8257ec681f3Smrg         texObj->Sampler.Attrib.state.border_color.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F);
8263464ebd5Sriastradh      }
8277ec681f3Smrg      _mesa_update_is_border_color_nonzero(&texObj->Sampler);
828c1f859d4Smrg      return GL_TRUE;
829c1f859d4Smrg
83001e04c3fSmrg   case GL_TEXTURE_TILING_EXT:
83101e04c3fSmrg      if (ctx->Extensions.EXT_memory_object) {
83201e04c3fSmrg         texObj->TextureTiling = params[0];
83301e04c3fSmrg         return GL_TRUE;
83401e04c3fSmrg      }
83501e04c3fSmrg      goto invalid_pname;
83601e04c3fSmrg
837c1f859d4Smrg   default:
838af69d88dSmrg      goto invalid_pname;
839c1f859d4Smrg   }
840c1f859d4Smrg   return GL_FALSE;
841af69d88dSmrg
842af69d88dSmrginvalid_pname:
84301e04c3fSmrg   _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
84401e04c3fSmrg               suffix, _mesa_enum_to_string(pname));
845af69d88dSmrg   return GL_FALSE;
846af69d88dSmrg
8477ec681f3Smrginvalid_dsa:
8487ec681f3Smrg   if (!dsa)
8497ec681f3Smrg      goto invalid_enum;
8507ec681f3Smrg   _mesa_error(ctx, GL_INVALID_OPERATION, "glTex%sParameter(pname=%s)",
8517ec681f3Smrg               suffix, _mesa_enum_to_string(pname));
8527ec681f3Smrg   return GL_FALSE;
85301e04c3fSmrginvalid_enum:
85401e04c3fSmrg   _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
85501e04c3fSmrg               suffix, _mesa_enum_to_string(pname));
856af69d88dSmrg   return GL_FALSE;
857c1f859d4Smrg}
858c1f859d4Smrg
859c1f859d4Smrg
86001e04c3fSmrgvoid
86101e04c3fSmrg_mesa_texture_parameterf(struct gl_context *ctx,
86201e04c3fSmrg                         struct gl_texture_object *texObj,
86301e04c3fSmrg                         GLenum pname, GLfloat param, bool dsa)
864c1f859d4Smrg{
865c1f859d4Smrg   GLboolean need_update;
866c1f859d4Smrg
867c1f859d4Smrg   switch (pname) {
868c1f859d4Smrg   case GL_TEXTURE_MIN_FILTER:
869c1f859d4Smrg   case GL_TEXTURE_MAG_FILTER:
870c1f859d4Smrg   case GL_TEXTURE_WRAP_S:
871c1f859d4Smrg   case GL_TEXTURE_WRAP_T:
872c1f859d4Smrg   case GL_TEXTURE_WRAP_R:
873c1f859d4Smrg   case GL_TEXTURE_BASE_LEVEL:
874c1f859d4Smrg   case GL_TEXTURE_MAX_LEVEL:
875c1f859d4Smrg   case GL_GENERATE_MIPMAP_SGIS:
876c1f859d4Smrg   case GL_TEXTURE_COMPARE_MODE_ARB:
877c1f859d4Smrg   case GL_TEXTURE_COMPARE_FUNC_ARB:
878c1f859d4Smrg   case GL_DEPTH_TEXTURE_MODE_ARB:
879af69d88dSmrg   case GL_DEPTH_STENCIL_TEXTURE_MODE:
8803464ebd5Sriastradh   case GL_TEXTURE_SRGB_DECODE_EXT:
8817ec681f3Smrg   case GL_TEXTURE_REDUCTION_MODE_EXT:
8823464ebd5Sriastradh   case GL_TEXTURE_CUBE_MAP_SEAMLESS:
883af69d88dSmrg   case GL_TEXTURE_SWIZZLE_R_EXT:
884af69d88dSmrg   case GL_TEXTURE_SWIZZLE_G_EXT:
885af69d88dSmrg   case GL_TEXTURE_SWIZZLE_B_EXT:
886af69d88dSmrg   case GL_TEXTURE_SWIZZLE_A_EXT:
887c1f859d4Smrg      {
8884a49301eSmrg         GLint p[4];
889af69d88dSmrg         p[0] = (param > 0) ?
890af69d88dSmrg                ((param > INT_MAX) ? INT_MAX : (GLint) (param + 0.5)) :
891af69d88dSmrg                ((param < INT_MIN) ? INT_MIN : (GLint) (param - 0.5));
892af69d88dSmrg
8934a49301eSmrg         p[1] = p[2] = p[3] = 0;
89401e04c3fSmrg         need_update = set_tex_parameteri(ctx, texObj, pname, p, dsa);
895c1f859d4Smrg      }
896c1f859d4Smrg      break;
89701e04c3fSmrg   case GL_TEXTURE_BORDER_COLOR:
89801e04c3fSmrg   case GL_TEXTURE_SWIZZLE_RGBA:
89901e04c3fSmrg      _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameterf(non-scalar pname)",
90001e04c3fSmrg                  dsa ? "ture" : "");
90101e04c3fSmrg      return;
902c1f859d4Smrg   default:
9034a49301eSmrg      {
9044a49301eSmrg         /* this will generate an error if pname is illegal */
9054a49301eSmrg         GLfloat p[4];
9064a49301eSmrg         p[0] = param;
9074a49301eSmrg         p[1] = p[2] = p[3] = 0.0F;
90801e04c3fSmrg         need_update = set_tex_parameterf(ctx, texObj, pname, p, dsa);
9094a49301eSmrg      }
910c1f859d4Smrg   }
911c1f859d4Smrg
912c1f859d4Smrg   if (ctx->Driver.TexParameter && need_update) {
91301e04c3fSmrg      ctx->Driver.TexParameter(ctx, texObj, pname);
914c1f859d4Smrg   }
915c1f859d4Smrg}
916c1f859d4Smrg
917c1f859d4Smrg
91801e04c3fSmrgvoid
91901e04c3fSmrg_mesa_texture_parameterfv(struct gl_context *ctx,
92001e04c3fSmrg                          struct gl_texture_object *texObj,
92101e04c3fSmrg                          GLenum pname, const GLfloat *params, bool dsa)
922c1f859d4Smrg{
923c1f859d4Smrg   GLboolean need_update;
924c1f859d4Smrg   switch (pname) {
925c1f859d4Smrg   case GL_TEXTURE_MIN_FILTER:
926c1f859d4Smrg   case GL_TEXTURE_MAG_FILTER:
927c1f859d4Smrg   case GL_TEXTURE_WRAP_S:
928c1f859d4Smrg   case GL_TEXTURE_WRAP_T:
929c1f859d4Smrg   case GL_TEXTURE_WRAP_R:
930c1f859d4Smrg   case GL_TEXTURE_BASE_LEVEL:
931c1f859d4Smrg   case GL_TEXTURE_MAX_LEVEL:
932c1f859d4Smrg   case GL_GENERATE_MIPMAP_SGIS:
933c1f859d4Smrg   case GL_TEXTURE_COMPARE_MODE_ARB:
934c1f859d4Smrg   case GL_TEXTURE_COMPARE_FUNC_ARB:
935c1f859d4Smrg   case GL_DEPTH_TEXTURE_MODE_ARB:
936af69d88dSmrg   case GL_DEPTH_STENCIL_TEXTURE_MODE:
9373464ebd5Sriastradh   case GL_TEXTURE_SRGB_DECODE_EXT:
9387ec681f3Smrg   case GL_TEXTURE_REDUCTION_MODE_EXT:
9393464ebd5Sriastradh   case GL_TEXTURE_CUBE_MAP_SEAMLESS:
940c1f859d4Smrg      {
941c1f859d4Smrg         /* convert float param to int */
9424a49301eSmrg         GLint p[4];
9434a49301eSmrg         p[0] = (GLint) params[0];
9444a49301eSmrg         p[1] = p[2] = p[3] = 0;
94501e04c3fSmrg         need_update = set_tex_parameteri(ctx, texObj, pname, p, dsa);
946c1f859d4Smrg      }
947c1f859d4Smrg      break;
948c1f859d4Smrg   case GL_TEXTURE_CROP_RECT_OES:
949c1f859d4Smrg      {
950c1f859d4Smrg         /* convert float params to int */
951c1f859d4Smrg         GLint iparams[4];
952c1f859d4Smrg         iparams[0] = (GLint) params[0];
953c1f859d4Smrg         iparams[1] = (GLint) params[1];
954c1f859d4Smrg         iparams[2] = (GLint) params[2];
955c1f859d4Smrg         iparams[3] = (GLint) params[3];
95601e04c3fSmrg         need_update = set_tex_parameteri(ctx, texObj, pname, iparams, dsa);
957c1f859d4Smrg      }
958c1f859d4Smrg      break;
959af69d88dSmrg   case GL_TEXTURE_SWIZZLE_R_EXT:
960af69d88dSmrg   case GL_TEXTURE_SWIZZLE_G_EXT:
961af69d88dSmrg   case GL_TEXTURE_SWIZZLE_B_EXT:
962af69d88dSmrg   case GL_TEXTURE_SWIZZLE_A_EXT:
963af69d88dSmrg   case GL_TEXTURE_SWIZZLE_RGBA_EXT:
964af69d88dSmrg      {
965af69d88dSmrg         GLint p[4] = {0, 0, 0, 0};
966af69d88dSmrg         p[0] = (GLint) params[0];
967af69d88dSmrg         if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT) {
968af69d88dSmrg            p[1] = (GLint) params[1];
969af69d88dSmrg            p[2] = (GLint) params[2];
970af69d88dSmrg            p[3] = (GLint) params[3];
971af69d88dSmrg         }
97201e04c3fSmrg         need_update = set_tex_parameteri(ctx, texObj, pname, p, dsa);
973af69d88dSmrg      }
974af69d88dSmrg      break;
975c1f859d4Smrg   default:
976c1f859d4Smrg      /* this will generate an error if pname is illegal */
97701e04c3fSmrg      need_update = set_tex_parameterf(ctx, texObj, pname, params, dsa);
978c1f859d4Smrg   }
979c1f859d4Smrg
980c1f859d4Smrg   if (ctx->Driver.TexParameter && need_update) {
98101e04c3fSmrg      ctx->Driver.TexParameter(ctx, texObj, pname);
982c1f859d4Smrg   }
983c1f859d4Smrg}
984c1f859d4Smrg
985c1f859d4Smrg
98601e04c3fSmrgvoid
98701e04c3fSmrg_mesa_texture_parameteri(struct gl_context *ctx,
98801e04c3fSmrg                         struct gl_texture_object *texObj,
98901e04c3fSmrg                         GLenum pname, GLint param, bool dsa)
990c1f859d4Smrg{
991c1f859d4Smrg   GLboolean need_update;
992c1f859d4Smrg   switch (pname) {
993c1f859d4Smrg   case GL_TEXTURE_MIN_LOD:
994c1f859d4Smrg   case GL_TEXTURE_MAX_LOD:
995c1f859d4Smrg   case GL_TEXTURE_PRIORITY:
996c1f859d4Smrg   case GL_TEXTURE_MAX_ANISOTROPY_EXT:
997c1f859d4Smrg   case GL_TEXTURE_LOD_BIAS:
998c1f859d4Smrg      {
9994a49301eSmrg         GLfloat fparam[4];
10004a49301eSmrg         fparam[0] = (GLfloat) param;
10014a49301eSmrg         fparam[1] = fparam[2] = fparam[3] = 0.0F;
1002c1f859d4Smrg         /* convert int param to float */
100301e04c3fSmrg         need_update = set_tex_parameterf(ctx, texObj, pname, fparam, dsa);
1004c1f859d4Smrg      }
1005c1f859d4Smrg      break;
100601e04c3fSmrg   case GL_TEXTURE_BORDER_COLOR:
100701e04c3fSmrg   case GL_TEXTURE_SWIZZLE_RGBA:
100801e04c3fSmrg      {
100901e04c3fSmrg         _mesa_error(ctx, GL_INVALID_ENUM,
101001e04c3fSmrg                     "glTex%sParameteri(non-scalar pname)",
101101e04c3fSmrg                     dsa ? "ture" : "");
101201e04c3fSmrg         return;
101301e04c3fSmrg      }
1014c1f859d4Smrg   default:
1015c1f859d4Smrg      /* this will generate an error if pname is illegal */
10164a49301eSmrg      {
10174a49301eSmrg         GLint iparam[4];
10184a49301eSmrg         iparam[0] = param;
10194a49301eSmrg         iparam[1] = iparam[2] = iparam[3] = 0;
102001e04c3fSmrg         need_update = set_tex_parameteri(ctx, texObj, pname, iparam, dsa);
10214a49301eSmrg      }
1022c1f859d4Smrg   }
1023c1f859d4Smrg
1024c1f859d4Smrg   if (ctx->Driver.TexParameter && need_update) {
102501e04c3fSmrg      ctx->Driver.TexParameter(ctx, texObj, pname);
1026c1f859d4Smrg   }
1027c1f859d4Smrg}
1028c1f859d4Smrg
1029c1f859d4Smrg
103001e04c3fSmrgvoid
103101e04c3fSmrg_mesa_texture_parameteriv(struct gl_context *ctx,
103201e04c3fSmrg                          struct gl_texture_object *texObj,
103301e04c3fSmrg                          GLenum pname, const GLint *params, bool dsa)
1034c1f859d4Smrg{
1035c1f859d4Smrg   GLboolean need_update;
1036c1f859d4Smrg
1037c1f859d4Smrg   switch (pname) {
1038c1f859d4Smrg   case GL_TEXTURE_BORDER_COLOR:
1039c1f859d4Smrg      {
1040c1f859d4Smrg         /* convert int params to float */
1041c1f859d4Smrg         GLfloat fparams[4];
1042c1f859d4Smrg         fparams[0] = INT_TO_FLOAT(params[0]);
1043c1f859d4Smrg         fparams[1] = INT_TO_FLOAT(params[1]);
1044c1f859d4Smrg         fparams[2] = INT_TO_FLOAT(params[2]);
1045c1f859d4Smrg         fparams[3] = INT_TO_FLOAT(params[3]);
104601e04c3fSmrg         need_update = set_tex_parameterf(ctx, texObj, pname, fparams, dsa);
1047c1f859d4Smrg      }
1048c1f859d4Smrg      break;
1049c1f859d4Smrg   case GL_TEXTURE_MIN_LOD:
1050c1f859d4Smrg   case GL_TEXTURE_MAX_LOD:
1051c1f859d4Smrg   case GL_TEXTURE_PRIORITY:
1052c1f859d4Smrg   case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1053c1f859d4Smrg   case GL_TEXTURE_LOD_BIAS:
1054c1f859d4Smrg      {
1055c1f859d4Smrg         /* convert int param to float */
10564a49301eSmrg         GLfloat fparams[4];
10574a49301eSmrg         fparams[0] = (GLfloat) params[0];
10584a49301eSmrg         fparams[1] = fparams[2] = fparams[3] = 0.0F;
105901e04c3fSmrg         need_update = set_tex_parameterf(ctx, texObj, pname, fparams, dsa);
1060c1f859d4Smrg      }
1061c1f859d4Smrg      break;
1062c1f859d4Smrg   default:
1063c1f859d4Smrg      /* this will generate an error if pname is illegal */
106401e04c3fSmrg      need_update = set_tex_parameteri(ctx, texObj, pname, params, dsa);
1065c1f859d4Smrg   }
1066c1f859d4Smrg
1067c1f859d4Smrg   if (ctx->Driver.TexParameter && need_update) {
106801e04c3fSmrg      ctx->Driver.TexParameter(ctx, texObj, pname);
106901e04c3fSmrg   }
107001e04c3fSmrg}
107101e04c3fSmrg
107201e04c3fSmrgvoid
107301e04c3fSmrg_mesa_texture_parameterIiv(struct gl_context *ctx,
107401e04c3fSmrg                           struct gl_texture_object *texObj,
107501e04c3fSmrg                           GLenum pname, const GLint *params, bool dsa)
107601e04c3fSmrg{
107701e04c3fSmrg   switch (pname) {
107801e04c3fSmrg   case GL_TEXTURE_BORDER_COLOR:
107901e04c3fSmrg      if (texObj->HandleAllocated) {
108001e04c3fSmrg         _mesa_error(ctx, GL_INVALID_OPERATION,
108101e04c3fSmrg                     "glTextureParameterIiv(immutable texture)");
108201e04c3fSmrg         return;
108301e04c3fSmrg      }
108401e04c3fSmrg
108501e04c3fSmrg      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target)) {
10867ec681f3Smrg         _mesa_error(ctx, dsa ? GL_INVALID_OPERATION : GL_INVALID_ENUM, "glTextureParameterIiv(texture)");
108701e04c3fSmrg         return;
108801e04c3fSmrg      }
10897ec681f3Smrg      FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT, GL_TEXTURE_BIT);
109001e04c3fSmrg      /* set the integer-valued border color */
10917ec681f3Smrg      COPY_4V(texObj->Sampler.Attrib.state.border_color.i, params);
10927ec681f3Smrg      _mesa_update_is_border_color_nonzero(&texObj->Sampler);
109301e04c3fSmrg      break;
109401e04c3fSmrg   default:
109501e04c3fSmrg      _mesa_texture_parameteriv(ctx, texObj, pname, params, dsa);
109601e04c3fSmrg      break;
109701e04c3fSmrg   }
109801e04c3fSmrg   /* XXX no driver hook for TexParameterIiv() yet */
109901e04c3fSmrg}
110001e04c3fSmrg
110101e04c3fSmrgvoid
110201e04c3fSmrg_mesa_texture_parameterIuiv(struct gl_context *ctx,
110301e04c3fSmrg                            struct gl_texture_object *texObj,
110401e04c3fSmrg                            GLenum pname, const GLuint *params, bool dsa)
110501e04c3fSmrg{
110601e04c3fSmrg   switch (pname) {
110701e04c3fSmrg   case GL_TEXTURE_BORDER_COLOR:
110801e04c3fSmrg      if (texObj->HandleAllocated) {
110901e04c3fSmrg         _mesa_error(ctx, GL_INVALID_OPERATION,
111001e04c3fSmrg                     "glTextureParameterIuiv(immutable texture)");
111101e04c3fSmrg         return;
1112c1f859d4Smrg      }
111301e04c3fSmrg
111401e04c3fSmrg      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target)) {
11157ec681f3Smrg         _mesa_error(ctx, dsa ? GL_INVALID_OPERATION : GL_INVALID_ENUM, "glTextureParameterIuiv(texture)");
111601e04c3fSmrg         return;
111701e04c3fSmrg      }
11187ec681f3Smrg      FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT, GL_TEXTURE_BIT);
111901e04c3fSmrg      /* set the unsigned integer-valued border color */
11207ec681f3Smrg      COPY_4V(texObj->Sampler.Attrib.state.border_color.ui, params);
11217ec681f3Smrg      _mesa_update_is_border_color_nonzero(&texObj->Sampler);
112201e04c3fSmrg      break;
112301e04c3fSmrg   default:
112401e04c3fSmrg      _mesa_texture_parameteriv(ctx, texObj, pname, (const GLint *) params,
112501e04c3fSmrg                                dsa);
112601e04c3fSmrg      break;
1127c1f859d4Smrg   }
112801e04c3fSmrg   /* XXX no driver hook for TexParameterIuiv() yet */
1129c1f859d4Smrg}
1130c1f859d4Smrg
113101e04c3fSmrgvoid GLAPIENTRY
113201e04c3fSmrg_mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
113301e04c3fSmrg{
113401e04c3fSmrg   struct gl_texture_object *texObj;
113501e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
113601e04c3fSmrg
11377ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
11387ec681f3Smrg                                                   ctx->Texture.CurrentUnit,
11397ec681f3Smrg                                                   false,
11407ec681f3Smrg                                                   "glTexParameterf");
114101e04c3fSmrg   if (!texObj)
114201e04c3fSmrg      return;
114301e04c3fSmrg
114401e04c3fSmrg   _mesa_texture_parameterf(ctx, texObj, pname, param, false);
114501e04c3fSmrg}
114601e04c3fSmrg
114701e04c3fSmrgvoid GLAPIENTRY
114801e04c3fSmrg_mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
114901e04c3fSmrg{
115001e04c3fSmrg   struct gl_texture_object *texObj;
115101e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
115201e04c3fSmrg
11537ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
11547ec681f3Smrg                                                   ctx->Texture.CurrentUnit,
11557ec681f3Smrg                                                   false,
11567ec681f3Smrg                                                   "glTexParameterfv");
115701e04c3fSmrg   if (!texObj)
115801e04c3fSmrg      return;
115901e04c3fSmrg
116001e04c3fSmrg   _mesa_texture_parameterfv(ctx, texObj, pname, params, false);
116101e04c3fSmrg}
116201e04c3fSmrg
116301e04c3fSmrgvoid GLAPIENTRY
116401e04c3fSmrg_mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
116501e04c3fSmrg{
116601e04c3fSmrg   struct gl_texture_object *texObj;
116701e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
116801e04c3fSmrg
11697ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
11707ec681f3Smrg                                                   ctx->Texture.CurrentUnit,
11717ec681f3Smrg                                                   false,
11727ec681f3Smrg                                                   "glTexParameteri");
117301e04c3fSmrg   if (!texObj)
117401e04c3fSmrg      return;
117501e04c3fSmrg
117601e04c3fSmrg   _mesa_texture_parameteri(ctx, texObj, pname, param, false);
117701e04c3fSmrg}
117801e04c3fSmrg
117901e04c3fSmrgvoid GLAPIENTRY
118001e04c3fSmrg_mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
118101e04c3fSmrg{
118201e04c3fSmrg   struct gl_texture_object *texObj;
118301e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
118401e04c3fSmrg
11857ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
11867ec681f3Smrg                                                   ctx->Texture.CurrentUnit,
11877ec681f3Smrg                                                   false,
11887ec681f3Smrg                                                   "glTexParameteriv");
118901e04c3fSmrg   if (!texObj)
119001e04c3fSmrg      return;
119101e04c3fSmrg
119201e04c3fSmrg   _mesa_texture_parameteriv(ctx, texObj, pname, params, false);
119301e04c3fSmrg}
1194c1f859d4Smrg
1195cdc920a0Smrg/**
1196cdc920a0Smrg * Set tex parameter to integer value(s).  Primarily intended to set
1197cdc920a0Smrg * integer-valued texture border color (for integer-valued textures).
1198cdc920a0Smrg * New in GL 3.0.
1199cdc920a0Smrg */
1200cdc920a0Smrgvoid GLAPIENTRY
1201cdc920a0Smrg_mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
1202cdc920a0Smrg{
1203cdc920a0Smrg   struct gl_texture_object *texObj;
1204cdc920a0Smrg   GET_CURRENT_CONTEXT(ctx);
1205cdc920a0Smrg
12067ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
12077ec681f3Smrg                                                   ctx->Texture.CurrentUnit,
12087ec681f3Smrg                                                   false,
12097ec681f3Smrg                                                   "glTexParameterIiv");
1210cdc920a0Smrg   if (!texObj)
1211cdc920a0Smrg      return;
1212cdc920a0Smrg
121301e04c3fSmrg   _mesa_texture_parameterIiv(ctx, texObj, pname, params, false);
1214cdc920a0Smrg}
1215cdc920a0Smrg
1216cdc920a0Smrg/**
1217cdc920a0Smrg * Set tex parameter to unsigned integer value(s).  Primarily intended to set
1218cdc920a0Smrg * uint-valued texture border color (for integer-valued textures).
1219cdc920a0Smrg * New in GL 3.0
1220cdc920a0Smrg */
1221cdc920a0Smrgvoid GLAPIENTRY
1222cdc920a0Smrg_mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
1223cdc920a0Smrg{
1224cdc920a0Smrg   struct gl_texture_object *texObj;
1225cdc920a0Smrg   GET_CURRENT_CONTEXT(ctx);
1226cdc920a0Smrg
12277ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
12287ec681f3Smrg                                                   ctx->Texture.CurrentUnit,
12297ec681f3Smrg                                                   false,
12307ec681f3Smrg                                                   "glTexParameterIuiv");
1231cdc920a0Smrg   if (!texObj)
1232cdc920a0Smrg      return;
1233cdc920a0Smrg
123401e04c3fSmrg   _mesa_texture_parameterIuiv(ctx, texObj, pname, params, false);
1235cdc920a0Smrg}
1236cdc920a0Smrg
12377ec681f3Smrgvoid GLAPIENTRY
12387ec681f3Smrg_mesa_TextureParameterfvEXT(GLuint texture, GLenum target, GLenum pname, const GLfloat *params)
12397ec681f3Smrg{
12407ec681f3Smrg   struct gl_texture_object *texObj;
12417ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
12427ec681f3Smrg
12437ec681f3Smrg   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
12447ec681f3Smrg                                           "glTextureParameterfvEXT");
12457ec681f3Smrg   if (!texObj)
12467ec681f3Smrg      return;
12477ec681f3Smrg
12487ec681f3Smrg   if (!is_texparameteri_target_valid(texObj->Target)) {
12497ec681f3Smrg      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterfvEXT");
12507ec681f3Smrg      return;
12517ec681f3Smrg   }
12527ec681f3Smrg
12537ec681f3Smrg   _mesa_texture_parameterfv(ctx, texObj, pname, params, true);
12547ec681f3Smrg}
1255cdc920a0Smrg
125601e04c3fSmrgvoid GLAPIENTRY
125701e04c3fSmrg_mesa_TextureParameterfv(GLuint texture, GLenum pname, const GLfloat *params)
125801e04c3fSmrg{
125901e04c3fSmrg   struct gl_texture_object *texObj;
126001e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
126101e04c3fSmrg
126201e04c3fSmrg   texObj = get_texobj_by_name(ctx, texture, "glTextureParameterfv");
126301e04c3fSmrg   if (!texObj)
126401e04c3fSmrg      return;
126501e04c3fSmrg
126601e04c3fSmrg   _mesa_texture_parameterfv(ctx, texObj, pname, params, true);
126701e04c3fSmrg}
126801e04c3fSmrg
12697ec681f3Smrgvoid GLAPIENTRY
12707ec681f3Smrg_mesa_MultiTexParameterfvEXT(GLenum texunit, GLenum target, GLenum pname, const GLfloat *params)
12717ec681f3Smrg{
12727ec681f3Smrg   struct gl_texture_object *texObj;
12737ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
12747ec681f3Smrg
12757ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
12767ec681f3Smrg                                                   texunit - GL_TEXTURE0,
12777ec681f3Smrg                                                   false,
12787ec681f3Smrg                                                   "glMultiTexParameterfvEXT");
12797ec681f3Smrg   if (!texObj)
12807ec681f3Smrg      return;
12817ec681f3Smrg
12827ec681f3Smrg   if (!is_texparameteri_target_valid(texObj->Target)) {
12837ec681f3Smrg      _mesa_error(ctx, GL_INVALID_OPERATION, "glMultiTexParameterifvEXT(target)");
12847ec681f3Smrg      return;
12857ec681f3Smrg   }
12867ec681f3Smrg
12877ec681f3Smrg   _mesa_texture_parameterfv(ctx, texObj, pname, params, true);
12887ec681f3Smrg}
12897ec681f3Smrg
12907ec681f3Smrgvoid GLAPIENTRY
12917ec681f3Smrg_mesa_TextureParameterfEXT(GLuint texture, GLenum target, GLenum pname, GLfloat param)
12927ec681f3Smrg{
12937ec681f3Smrg   struct gl_texture_object *texObj;
12947ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
12957ec681f3Smrg
12967ec681f3Smrg   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
12977ec681f3Smrg                                           "glTextureParameterfEXT");
12987ec681f3Smrg   if (!texObj)
12997ec681f3Smrg      return;
13007ec681f3Smrg
13017ec681f3Smrg   if (!is_texparameteri_target_valid(texObj->Target)) {
13027ec681f3Smrg      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterfEXT");
13037ec681f3Smrg      return;
13047ec681f3Smrg   }
13057ec681f3Smrg
13067ec681f3Smrg   _mesa_texture_parameterf(ctx, texObj, pname, param, true);
13077ec681f3Smrg}
13087ec681f3Smrg
13097ec681f3Smrgvoid GLAPIENTRY
13107ec681f3Smrg_mesa_MultiTexParameterfEXT(GLenum texunit, GLenum target, GLenum pname,
13117ec681f3Smrg                            GLfloat param)
13127ec681f3Smrg{
13137ec681f3Smrg   struct gl_texture_object *texObj;
13147ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
13157ec681f3Smrg
13167ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
13177ec681f3Smrg                                                   texunit - GL_TEXTURE0,
13187ec681f3Smrg                                                   false,
13197ec681f3Smrg                                                   "glMultiTexParameterfEXT");
13207ec681f3Smrg   if (!texObj)
13217ec681f3Smrg      return;
13227ec681f3Smrg
13237ec681f3Smrg   if (!is_texparameteri_target_valid(texObj->Target)) {
13247ec681f3Smrg      _mesa_error(ctx, GL_INVALID_OPERATION, "glMultiTexParameterfEXT");
13257ec681f3Smrg      return;
13267ec681f3Smrg   }
13277ec681f3Smrg
13287ec681f3Smrg   _mesa_texture_parameterf(ctx, texObj, pname, param, true);
13297ec681f3Smrg}
13307ec681f3Smrg
133101e04c3fSmrgvoid GLAPIENTRY
133201e04c3fSmrg_mesa_TextureParameterf(GLuint texture, GLenum pname, GLfloat param)
1333c1f859d4Smrg{
133401e04c3fSmrg   struct gl_texture_object *texObj;
133501e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
133601e04c3fSmrg
133701e04c3fSmrg   texObj = get_texobj_by_name(ctx, texture, "glTextureParameterf");
133801e04c3fSmrg   if (!texObj)
133901e04c3fSmrg      return;
134001e04c3fSmrg
134101e04c3fSmrg   _mesa_texture_parameterf(ctx, texObj, pname, param, true);
134201e04c3fSmrg}
134301e04c3fSmrg
13447ec681f3Smrgvoid GLAPIENTRY
13457ec681f3Smrg_mesa_TextureParameteriEXT(GLuint texture, GLenum target, GLenum pname, GLint param)
13467ec681f3Smrg{
13477ec681f3Smrg   struct gl_texture_object *texObj;
13487ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
13497ec681f3Smrg
13507ec681f3Smrg   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
13517ec681f3Smrg                                           "glTextureParameteriEXT");
13527ec681f3Smrg   if (!texObj)
13537ec681f3Smrg      return;
13547ec681f3Smrg
13557ec681f3Smrg   if (!is_texparameteri_target_valid(texObj->Target)) {
13567ec681f3Smrg      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameteriEXT(target)");
13577ec681f3Smrg      return;
13587ec681f3Smrg   }
13597ec681f3Smrg
13607ec681f3Smrg   _mesa_texture_parameteri(ctx, texObj, pname, param, true);
13617ec681f3Smrg}
13627ec681f3Smrg
13637ec681f3Smrgvoid GLAPIENTRY
13647ec681f3Smrg_mesa_MultiTexParameteriEXT(GLenum texunit, GLenum target, GLenum pname,
13657ec681f3Smrg                            GLint param)
13667ec681f3Smrg{
13677ec681f3Smrg   struct gl_texture_object *texObj;
13687ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
13697ec681f3Smrg
13707ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
13717ec681f3Smrg                                                   texunit - GL_TEXTURE0,
13727ec681f3Smrg                                                   false,
13737ec681f3Smrg                                                   "glMultiTexParameteriEXT");
13747ec681f3Smrg   if (!texObj)
13757ec681f3Smrg      return;
13767ec681f3Smrg
13777ec681f3Smrg   if (!is_texparameteri_target_valid(texObj->Target)) {
13787ec681f3Smrg      _mesa_error(ctx, GL_INVALID_OPERATION, "glMultiTexParameteriEXT(target)");
13797ec681f3Smrg      return;
13807ec681f3Smrg   }
13817ec681f3Smrg
13827ec681f3Smrg   _mesa_texture_parameteri(ctx, texObj, pname, param, true);
13837ec681f3Smrg}
13847ec681f3Smrg
138501e04c3fSmrgvoid GLAPIENTRY
138601e04c3fSmrg_mesa_TextureParameteri(GLuint texture, GLenum pname, GLint param)
138701e04c3fSmrg{
138801e04c3fSmrg   struct gl_texture_object *texObj;
138901e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
139001e04c3fSmrg
139101e04c3fSmrg   texObj = get_texobj_by_name(ctx, texture, "glTextureParameteri");
139201e04c3fSmrg   if (!texObj)
139301e04c3fSmrg      return;
139401e04c3fSmrg
139501e04c3fSmrg   _mesa_texture_parameteri(ctx, texObj, pname, param, true);
139601e04c3fSmrg}
139701e04c3fSmrg
13987ec681f3Smrgvoid GLAPIENTRY
13997ec681f3Smrg_mesa_TextureParameterivEXT(GLuint texture, GLenum target, GLenum pname,
14007ec681f3Smrg                         const GLint *params)
14017ec681f3Smrg{
14027ec681f3Smrg   struct gl_texture_object *texObj;
14037ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
14047ec681f3Smrg
14057ec681f3Smrg   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
14067ec681f3Smrg                                           "glTextureParameterivEXT");
14077ec681f3Smrg   if (!texObj)
14087ec681f3Smrg      return;
14097ec681f3Smrg
14107ec681f3Smrg   if (!is_texparameteri_target_valid(texObj->Target)) {
14117ec681f3Smrg      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterivEXT(target)");
14127ec681f3Smrg      return;
14137ec681f3Smrg   }
14147ec681f3Smrg
14157ec681f3Smrg   _mesa_texture_parameteriv(ctx, texObj, pname, params, true);
14167ec681f3Smrg}
14177ec681f3Smrg
14187ec681f3Smrgvoid GLAPIENTRY
14197ec681f3Smrg_mesa_MultiTexParameterivEXT(GLenum texunit, GLenum target, GLenum pname,
14207ec681f3Smrg                             const GLint *params)
14217ec681f3Smrg{
14227ec681f3Smrg   struct gl_texture_object *texObj;
14237ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
14247ec681f3Smrg
14257ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
14267ec681f3Smrg                                                   texunit - GL_TEXTURE0,
14277ec681f3Smrg                                                   false,
14287ec681f3Smrg                                                   "glMultiTexParameterivEXT");
14297ec681f3Smrg   if (!texObj)
14307ec681f3Smrg      return;
14317ec681f3Smrg
14327ec681f3Smrg   if (!is_texparameteri_target_valid(texObj->Target)) {
14337ec681f3Smrg      _mesa_error(ctx, GL_INVALID_OPERATION, "glMultiTexParameterivEXT(target)");
14347ec681f3Smrg      return;
14357ec681f3Smrg   }
14367ec681f3Smrg
14377ec681f3Smrg   _mesa_texture_parameteriv(ctx, texObj, pname, params, true);
14387ec681f3Smrg}
14397ec681f3Smrg
144001e04c3fSmrgvoid GLAPIENTRY
144101e04c3fSmrg_mesa_TextureParameteriv(GLuint texture, GLenum pname,
144201e04c3fSmrg                         const GLint *params)
144301e04c3fSmrg{
144401e04c3fSmrg   struct gl_texture_object *texObj;
144501e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
144601e04c3fSmrg
144701e04c3fSmrg   texObj = get_texobj_by_name(ctx, texture, "glTextureParameteriv");
144801e04c3fSmrg   if (!texObj)
144901e04c3fSmrg      return;
145001e04c3fSmrg
145101e04c3fSmrg   _mesa_texture_parameteriv(ctx, texObj, pname, params, true);
145201e04c3fSmrg}
145301e04c3fSmrg
145401e04c3fSmrg
145501e04c3fSmrgvoid GLAPIENTRY
145601e04c3fSmrg_mesa_TextureParameterIiv(GLuint texture, GLenum pname, const GLint *params)
145701e04c3fSmrg{
145801e04c3fSmrg   struct gl_texture_object *texObj;
145901e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
146001e04c3fSmrg
146101e04c3fSmrg   texObj = get_texobj_by_name(ctx, texture, "glTextureParameterIiv");
146201e04c3fSmrg   if (!texObj)
146301e04c3fSmrg      return;
146401e04c3fSmrg
146501e04c3fSmrg   _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
146601e04c3fSmrg}
146701e04c3fSmrg
14687ec681f3Smrgvoid GLAPIENTRY
14697ec681f3Smrg_mesa_TextureParameterIivEXT(GLuint texture, GLenum target, GLenum pname,
14707ec681f3Smrg                             const GLint *params)
14717ec681f3Smrg{
14727ec681f3Smrg   struct gl_texture_object *texObj;
14737ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
14747ec681f3Smrg
14757ec681f3Smrg   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
14767ec681f3Smrg                                           "glTextureParameterIivEXT");
14777ec681f3Smrg   if (!texObj)
14787ec681f3Smrg      return;
14797ec681f3Smrg
14807ec681f3Smrg   _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
14817ec681f3Smrg}
14827ec681f3Smrg
14837ec681f3Smrgvoid GLAPIENTRY
14847ec681f3Smrg_mesa_MultiTexParameterIivEXT(GLenum texunit, GLenum target, GLenum pname,
14857ec681f3Smrg                              const GLint *params)
14867ec681f3Smrg{
14877ec681f3Smrg   struct gl_texture_object *texObj;
14887ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
14897ec681f3Smrg
14907ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
14917ec681f3Smrg                                                   texunit - GL_TEXTURE0,
14927ec681f3Smrg                                                   true,
14937ec681f3Smrg                                                   "glMultiTexParameterIivEXT");
14947ec681f3Smrg   if (!texObj)
14957ec681f3Smrg      return;
14967ec681f3Smrg
14977ec681f3Smrg   _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
14987ec681f3Smrg}
14997ec681f3Smrg
150001e04c3fSmrgvoid GLAPIENTRY
150101e04c3fSmrg_mesa_TextureParameterIuiv(GLuint texture, GLenum pname, const GLuint *params)
150201e04c3fSmrg{
150301e04c3fSmrg   struct gl_texture_object *texObj;
150401e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
150501e04c3fSmrg
150601e04c3fSmrg   texObj = get_texobj_by_name(ctx, texture, "glTextureParameterIuiv");
150701e04c3fSmrg   if (!texObj)
150801e04c3fSmrg      return;
150901e04c3fSmrg
151001e04c3fSmrg   _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
151101e04c3fSmrg}
151201e04c3fSmrg
15137ec681f3Smrgvoid GLAPIENTRY
15147ec681f3Smrg_mesa_TextureParameterIuivEXT(GLuint texture, GLenum target, GLenum pname,
15157ec681f3Smrg                              const GLuint *params)
15167ec681f3Smrg{
15177ec681f3Smrg   struct gl_texture_object *texObj;
15187ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
15197ec681f3Smrg
15207ec681f3Smrg   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
15217ec681f3Smrg                                           "glTextureParameterIuivEXT");
15227ec681f3Smrg   if (!texObj)
15237ec681f3Smrg      return;
15247ec681f3Smrg
15257ec681f3Smrg   _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
15267ec681f3Smrg}
15277ec681f3Smrg
15287ec681f3Smrgvoid GLAPIENTRY
15297ec681f3Smrg_mesa_MultiTexParameterIuivEXT(GLenum texunit, GLenum target, GLenum pname,
15307ec681f3Smrg                               const GLuint *params)
15317ec681f3Smrg{
15327ec681f3Smrg   struct gl_texture_object *texObj;
15337ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
15347ec681f3Smrg
15357ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
15367ec681f3Smrg                                                   texunit - GL_TEXTURE0,
15377ec681f3Smrg                                                   true,
15387ec681f3Smrg                                                   "glMultiTexParameterIuivEXT");
15397ec681f3Smrg   if (!texObj)
15407ec681f3Smrg      return;
15417ec681f3Smrg
15427ec681f3Smrg   _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
15437ec681f3Smrg}
15447ec681f3Smrg
154501e04c3fSmrgGLboolean
154601e04c3fSmrg_mesa_legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target,
154701e04c3fSmrg                                           bool dsa)
154801e04c3fSmrg{
154901e04c3fSmrg   /* Common targets for desktop GL and GLES 3.1. */
1550af69d88dSmrg   switch (target) {
1551af69d88dSmrg   case GL_TEXTURE_2D:
1552af69d88dSmrg   case GL_TEXTURE_3D:
1553af69d88dSmrg      return GL_TRUE;
1554af69d88dSmrg   case GL_TEXTURE_2D_ARRAY_EXT:
1555af69d88dSmrg      return ctx->Extensions.EXT_texture_array;
155601e04c3fSmrg   case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
155701e04c3fSmrg   case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
155801e04c3fSmrg   case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
155901e04c3fSmrg   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
156001e04c3fSmrg   case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
156101e04c3fSmrg   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
156201e04c3fSmrg      return ctx->Extensions.ARB_texture_cube_map;
156301e04c3fSmrg   case GL_TEXTURE_2D_MULTISAMPLE:
156401e04c3fSmrg   case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
156501e04c3fSmrg      return ctx->Extensions.ARB_texture_multisample;
1566af69d88dSmrg   case GL_TEXTURE_BUFFER:
1567af69d88dSmrg      /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1568af69d88dSmrg       * but not in earlier versions that expose ARB_texture_buffer_object.
1569af69d88dSmrg       *
1570af69d88dSmrg       * From the ARB_texture_buffer_object spec:
1571af69d88dSmrg       * "(7) Do buffer textures support texture parameters (TexParameter) or
1572af69d88dSmrg       *      queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1573af69d88dSmrg       *
1574af69d88dSmrg       *    RESOLVED:  No. [...] Note that the spec edits above don't add
1575af69d88dSmrg       *    explicit error language for any of these cases.  That is because
1576af69d88dSmrg       *    each of the functions enumerate the set of valid <target>
1577af69d88dSmrg       *    parameters.  Not editing the spec to allow TEXTURE_BUFFER_ARB in
1578af69d88dSmrg       *    these cases means that target is not legal, and an INVALID_ENUM
1579af69d88dSmrg       *    error should be generated."
1580af69d88dSmrg       *
1581af69d88dSmrg       * From the OpenGL 3.1 spec:
1582af69d88dSmrg       * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1583af69d88dSmrg       */
158401e04c3fSmrg      return (_mesa_is_desktop_gl(ctx) && ctx->Version >= 31) ||
158501e04c3fSmrg             _mesa_has_OES_texture_buffer(ctx);
158601e04c3fSmrg   case GL_TEXTURE_CUBE_MAP_ARRAY:
158701e04c3fSmrg      return _mesa_has_texture_cube_map_array(ctx);
158801e04c3fSmrg   }
158901e04c3fSmrg
159001e04c3fSmrg   if (!_mesa_is_desktop_gl(ctx))
159101e04c3fSmrg      return GL_FALSE;
159201e04c3fSmrg
159301e04c3fSmrg   /* Rest of the desktop GL targets. */
159401e04c3fSmrg   switch (target) {
159501e04c3fSmrg   case GL_TEXTURE_1D:
159601e04c3fSmrg   case GL_PROXY_TEXTURE_1D:
159701e04c3fSmrg   case GL_PROXY_TEXTURE_2D:
159801e04c3fSmrg   case GL_PROXY_TEXTURE_3D:
159901e04c3fSmrg      return GL_TRUE;
160001e04c3fSmrg   case GL_PROXY_TEXTURE_CUBE_MAP:
160101e04c3fSmrg      return ctx->Extensions.ARB_texture_cube_map;
160201e04c3fSmrg   case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY:
160301e04c3fSmrg      return ctx->Extensions.ARB_texture_cube_map_array;
160401e04c3fSmrg   case GL_TEXTURE_RECTANGLE_NV:
160501e04c3fSmrg   case GL_PROXY_TEXTURE_RECTANGLE_NV:
160601e04c3fSmrg      return ctx->Extensions.NV_texture_rectangle;
160701e04c3fSmrg   case GL_TEXTURE_1D_ARRAY_EXT:
160801e04c3fSmrg   case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
160901e04c3fSmrg   case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
161001e04c3fSmrg      return ctx->Extensions.EXT_texture_array;
1611af69d88dSmrg   case GL_PROXY_TEXTURE_2D_MULTISAMPLE:
1612af69d88dSmrg   case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY:
1613af69d88dSmrg      return ctx->Extensions.ARB_texture_multisample;
161401e04c3fSmrg
161501e04c3fSmrg   /*  This is a valid target for dsa, but the OpenGL 4.5 core spec
161601e04c3fSmrg    *  (30.10.2014) Section 8.11 Texture Queries says:
161701e04c3fSmrg    *       "For GetTextureLevelParameter* only, texture may also be a cube
161801e04c3fSmrg    *       map texture object.  In this case the query is always performed
161901e04c3fSmrg    *       for face zero (the TEXTURE_CUBE_MAP_POSITIVE_X face), since there
162001e04c3fSmrg    *       is no way to specify another face."
162101e04c3fSmrg    */
162201e04c3fSmrg   case GL_TEXTURE_CUBE_MAP:
162301e04c3fSmrg      return dsa;
1624af69d88dSmrg   default:
1625af69d88dSmrg      return GL_FALSE;
1626af69d88dSmrg   }
1627c1f859d4Smrg}
1628c1f859d4Smrg
1629c1f859d4Smrg
1630af69d88dSmrgstatic void
1631af69d88dSmrgget_tex_level_parameter_image(struct gl_context *ctx,
1632af69d88dSmrg                              const struct gl_texture_object *texObj,
1633af69d88dSmrg                              GLenum target, GLint level,
163401e04c3fSmrg                              GLenum pname, GLint *params,
163501e04c3fSmrg                              bool dsa)
1636c1f859d4Smrg{
1637c1f859d4Smrg   const struct gl_texture_image *img = NULL;
1638af69d88dSmrg   struct gl_texture_image dummy_image;
1639af69d88dSmrg   mesa_format texFormat;
164001e04c3fSmrg   const char *suffix = dsa ? "ture" : "";
1641c1f859d4Smrg
164201e04c3fSmrg   img = _mesa_select_tex_image(texObj, target, level);
1643af69d88dSmrg   if (!img || img->TexFormat == MESA_FORMAT_NONE) {
1644af69d88dSmrg      /* In case of undefined texture image return the default values.
1645af69d88dSmrg       *
1646af69d88dSmrg       * From OpenGL 4.0 spec, page 398:
1647af69d88dSmrg       *    "The initial internal format of a texel array is RGBA
1648af69d88dSmrg       *     instead of 1. TEXTURE_COMPONENTS is deprecated; always
1649af69d88dSmrg       *     use TEXTURE_INTERNAL_FORMAT."
1650af69d88dSmrg       */
1651af69d88dSmrg      memset(&dummy_image, 0, sizeof(dummy_image));
1652af69d88dSmrg      dummy_image.TexFormat = MESA_FORMAT_NONE;
1653af69d88dSmrg      dummy_image.InternalFormat = GL_RGBA;
1654af69d88dSmrg      dummy_image._BaseFormat = GL_NONE;
165501e04c3fSmrg      dummy_image.FixedSampleLocations = GL_TRUE;
1656af69d88dSmrg
1657af69d88dSmrg      img = &dummy_image;
1658c1f859d4Smrg   }
1659c1f859d4Smrg
16604a49301eSmrg   texFormat = img->TexFormat;
16614a49301eSmrg
1662c1f859d4Smrg   switch (pname) {
1663c1f859d4Smrg      case GL_TEXTURE_WIDTH:
1664c1f859d4Smrg         *params = img->Width;
1665c1f859d4Smrg         break;
1666c1f859d4Smrg      case GL_TEXTURE_HEIGHT:
1667c1f859d4Smrg         *params = img->Height;
1668c1f859d4Smrg         break;
1669c1f859d4Smrg      case GL_TEXTURE_DEPTH:
1670c1f859d4Smrg         *params = img->Depth;
1671c1f859d4Smrg         break;
1672c1f859d4Smrg      case GL_TEXTURE_INTERNAL_FORMAT:
16733464ebd5Sriastradh         if (_mesa_is_format_compressed(texFormat)) {
16744a49301eSmrg            /* need to return the actual compressed format */
16753464ebd5Sriastradh            *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
16764a49301eSmrg         }
16774a49301eSmrg         else {
16783464ebd5Sriastradh	    /* If the true internal format is not compressed but the user
16793464ebd5Sriastradh	     * requested a generic compressed format, we have to return the
16803464ebd5Sriastradh	     * generic base format that matches.
16813464ebd5Sriastradh	     *
16823464ebd5Sriastradh	     * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
16833464ebd5Sriastradh	     *
16843464ebd5Sriastradh	     *     "If no specific compressed format is available,
16853464ebd5Sriastradh	     *     internalformat is instead replaced by the corresponding base
16863464ebd5Sriastradh	     *     internal format."
16873464ebd5Sriastradh	     *
16883464ebd5Sriastradh	     * Otherwise just return the user's requested internal format
16893464ebd5Sriastradh	     */
16903464ebd5Sriastradh	    const GLenum f =
16913464ebd5Sriastradh	       _mesa_gl_compressed_format_base_format(img->InternalFormat);
16923464ebd5Sriastradh
16933464ebd5Sriastradh	    *params = (f != 0) ? f : img->InternalFormat;
16943464ebd5Sriastradh	 }
1695c1f859d4Smrg         break;
1696c1f859d4Smrg      case GL_TEXTURE_BORDER:
1697af69d88dSmrg         if (ctx->API != API_OPENGL_COMPAT)
1698af69d88dSmrg            goto invalid_pname;
1699c1f859d4Smrg         *params = img->Border;
1700c1f859d4Smrg         break;
1701c1f859d4Smrg      case GL_TEXTURE_RED_SIZE:
1702c1f859d4Smrg      case GL_TEXTURE_GREEN_SIZE:
1703c1f859d4Smrg      case GL_TEXTURE_BLUE_SIZE:
1704c1f859d4Smrg      case GL_TEXTURE_ALPHA_SIZE:
1705af69d88dSmrg         if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
17064a49301eSmrg            *params = _mesa_get_format_bits(texFormat, pname);
1707c1f859d4Smrg         else
1708c1f859d4Smrg            *params = 0;
1709c1f859d4Smrg         break;
1710c1f859d4Smrg      case GL_TEXTURE_INTENSITY_SIZE:
1711c1f859d4Smrg      case GL_TEXTURE_LUMINANCE_SIZE:
1712af69d88dSmrg         if (ctx->API != API_OPENGL_COMPAT)
1713af69d88dSmrg            goto invalid_pname;
1714af69d88dSmrg         if (_mesa_base_format_has_channel(img->_BaseFormat, pname)) {
17154a49301eSmrg            *params = _mesa_get_format_bits(texFormat, pname);
17164a49301eSmrg            if (*params == 0) {
1717af69d88dSmrg               /* intensity or luminance is probably stored as RGB[A] */
1718af69d88dSmrg               *params = MIN2(_mesa_get_format_bits(texFormat,
1719af69d88dSmrg                                                    GL_TEXTURE_RED_SIZE),
1720af69d88dSmrg                              _mesa_get_format_bits(texFormat,
1721af69d88dSmrg                                                    GL_TEXTURE_GREEN_SIZE));
17224a49301eSmrg            }
172301e04c3fSmrg            if (*params == 0 && pname == GL_TEXTURE_INTENSITY_SIZE) {
172401e04c3fSmrg               /* Gallium may store intensity as LA */
17257ec681f3Smrg               *params = _mesa_get_format_bits(texFormat,
172601e04c3fSmrg                                               GL_TEXTURE_ALPHA_SIZE);
172701e04c3fSmrg            }
17284a49301eSmrg         }
1729af69d88dSmrg         else {
1730c1f859d4Smrg            *params = 0;
1731af69d88dSmrg         }
1732c1f859d4Smrg         break;
1733c1f859d4Smrg      case GL_TEXTURE_DEPTH_SIZE_ARB:
1734af69d88dSmrg         if (!ctx->Extensions.ARB_depth_texture)
17353464ebd5Sriastradh            goto invalid_pname;
1736af69d88dSmrg         *params = _mesa_get_format_bits(texFormat, pname);
1737c1f859d4Smrg         break;
1738af69d88dSmrg      case GL_TEXTURE_STENCIL_SIZE:
1739af69d88dSmrg         *params = _mesa_get_format_bits(texFormat, pname);
17403464ebd5Sriastradh         break;
17413464ebd5Sriastradh      case GL_TEXTURE_SHARED_SIZE:
1742af69d88dSmrg         if (ctx->Version < 30 &&
1743af69d88dSmrg             !ctx->Extensions.EXT_texture_shared_exponent)
17443464ebd5Sriastradh            goto invalid_pname;
1745af69d88dSmrg         *params = texFormat == MESA_FORMAT_R9G9B9E5_FLOAT ? 5 : 0;
1746c1f859d4Smrg         break;
1747c1f859d4Smrg
1748c1f859d4Smrg      /* GL_ARB_texture_compression */
1749c1f859d4Smrg      case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
175001e04c3fSmrg         if (_mesa_is_format_compressed(texFormat) &&
17513464ebd5Sriastradh             !_mesa_is_proxy_texture(target)) {
17524a49301eSmrg            *params = _mesa_format_image_size(texFormat, img->Width,
17534a49301eSmrg                                              img->Height, img->Depth);
175401e04c3fSmrg         } else {
175501e04c3fSmrg            _mesa_error(ctx, GL_INVALID_OPERATION,
175601e04c3fSmrg                        "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
175701e04c3fSmrg                        _mesa_enum_to_string(pname));
175801e04c3fSmrg         }
1759c1f859d4Smrg         break;
1760c1f859d4Smrg      case GL_TEXTURE_COMPRESSED:
17613464ebd5Sriastradh         *params = (GLint) _mesa_is_format_compressed(texFormat);
1762c1f859d4Smrg         break;
1763c1f859d4Smrg
1764c1f859d4Smrg      /* GL_ARB_texture_float */
1765af69d88dSmrg      case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1766af69d88dSmrg      case GL_TEXTURE_INTENSITY_TYPE_ARB:
1767af69d88dSmrg         if (ctx->API != API_OPENGL_COMPAT)
17683464ebd5Sriastradh            goto invalid_pname;
17697ec681f3Smrg         FALLTHROUGH;
1770af69d88dSmrg      case GL_TEXTURE_RED_TYPE_ARB:
1771c1f859d4Smrg      case GL_TEXTURE_GREEN_TYPE_ARB:
1772af69d88dSmrg      case GL_TEXTURE_BLUE_TYPE_ARB:
1773af69d88dSmrg      case GL_TEXTURE_ALPHA_TYPE_ARB:
1774af69d88dSmrg      case GL_TEXTURE_DEPTH_TYPE_ARB:
1775af69d88dSmrg         if (!ctx->Extensions.ARB_texture_float)
17763464ebd5Sriastradh            goto invalid_pname;
1777af69d88dSmrg	 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1778af69d88dSmrg	    *params = _mesa_get_format_datatype(texFormat);
1779af69d88dSmrg	 else
1780af69d88dSmrg	    *params = GL_NONE;
1781c1f859d4Smrg         break;
1782af69d88dSmrg
1783af69d88dSmrg      /* GL_ARB_texture_multisample */
1784af69d88dSmrg      case GL_TEXTURE_SAMPLES:
1785af69d88dSmrg         if (!ctx->Extensions.ARB_texture_multisample)
17863464ebd5Sriastradh            goto invalid_pname;
1787af69d88dSmrg         *params = img->NumSamples;
1788c1f859d4Smrg         break;
1789af69d88dSmrg
1790af69d88dSmrg      case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1791af69d88dSmrg         if (!ctx->Extensions.ARB_texture_multisample)
17923464ebd5Sriastradh            goto invalid_pname;
1793af69d88dSmrg         *params = img->FixedSampleLocations;
1794c1f859d4Smrg         break;
1795af69d88dSmrg
179601e04c3fSmrg      /* There is never a buffer data store here, but these pnames still have
179701e04c3fSmrg       * to work.
179801e04c3fSmrg       */
179901e04c3fSmrg
180001e04c3fSmrg      /* GL_ARB_texture_buffer_object */
180101e04c3fSmrg      case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
180201e04c3fSmrg         if (!ctx->Extensions.ARB_texture_buffer_object)
180301e04c3fSmrg            goto invalid_pname;
180401e04c3fSmrg         *params = 0;
180501e04c3fSmrg         break;
180601e04c3fSmrg
180701e04c3fSmrg      /* GL_ARB_texture_buffer_range */
180801e04c3fSmrg      case GL_TEXTURE_BUFFER_OFFSET:
180901e04c3fSmrg         if (!ctx->Extensions.ARB_texture_buffer_range)
181001e04c3fSmrg            goto invalid_pname;
181101e04c3fSmrg         *params = 0;
181201e04c3fSmrg         break;
181301e04c3fSmrg      case GL_TEXTURE_BUFFER_SIZE:
181401e04c3fSmrg         if (!ctx->Extensions.ARB_texture_buffer_range)
181501e04c3fSmrg            goto invalid_pname;
181601e04c3fSmrg         *params = 0;
181701e04c3fSmrg         break;
181801e04c3fSmrg
1819af69d88dSmrg      default:
1820af69d88dSmrg         goto invalid_pname;
1821af69d88dSmrg   }
1822af69d88dSmrg
1823af69d88dSmrg   /* no error if we get here */
1824af69d88dSmrg   return;
1825af69d88dSmrg
1826af69d88dSmrginvalid_pname:
1827af69d88dSmrg   _mesa_error(ctx, GL_INVALID_ENUM,
182801e04c3fSmrg               "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
182901e04c3fSmrg               _mesa_enum_to_string(pname));
1830af69d88dSmrg}
1831af69d88dSmrg
1832af69d88dSmrg
183301e04c3fSmrg/**
183401e04c3fSmrg * Handle a glGetTexLevelParamteriv() call for a texture buffer.
183501e04c3fSmrg */
1836af69d88dSmrgstatic void
1837af69d88dSmrgget_tex_level_parameter_buffer(struct gl_context *ctx,
1838af69d88dSmrg                               const struct gl_texture_object *texObj,
183901e04c3fSmrg                               GLenum pname, GLint *params, bool dsa)
1840af69d88dSmrg{
1841af69d88dSmrg   const struct gl_buffer_object *bo = texObj->BufferObject;
1842af69d88dSmrg   mesa_format texFormat = texObj->_BufferObjectFormat;
184301e04c3fSmrg   int bytes = MAX2(1, _mesa_get_format_bytes(texFormat));
1844af69d88dSmrg   GLenum internalFormat = texObj->BufferObjectFormat;
1845af69d88dSmrg   GLenum baseFormat = _mesa_get_format_base_format(texFormat);
184601e04c3fSmrg   const char *suffix = dsa ? "ture" : "";
184701e04c3fSmrg
184801e04c3fSmrg   assert(texObj->Target == GL_TEXTURE_BUFFER);
1849af69d88dSmrg
1850af69d88dSmrg   if (!bo) {
1851af69d88dSmrg      /* undefined texture buffer object */
185201e04c3fSmrg      switch (pname) {
185301e04c3fSmrg      case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
185401e04c3fSmrg         *params = GL_TRUE;
185501e04c3fSmrg         break;
185601e04c3fSmrg      case GL_TEXTURE_INTERNAL_FORMAT:
185701e04c3fSmrg         *params = internalFormat;
185801e04c3fSmrg         break;
185901e04c3fSmrg      default:
186001e04c3fSmrg         *params = 0;
186101e04c3fSmrg         break;
186201e04c3fSmrg      }
1863af69d88dSmrg      return;
1864af69d88dSmrg   }
1865af69d88dSmrg
1866af69d88dSmrg   switch (pname) {
1867af69d88dSmrg      case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
1868af69d88dSmrg         *params = bo->Name;
1869af69d88dSmrg         break;
1870af69d88dSmrg      case GL_TEXTURE_WIDTH:
187101e04c3fSmrg         *params = ((texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize)
187201e04c3fSmrg            / bytes;
1873af69d88dSmrg         break;
1874af69d88dSmrg      case GL_TEXTURE_HEIGHT:
1875af69d88dSmrg      case GL_TEXTURE_DEPTH:
187601e04c3fSmrg         *params = 1;
187701e04c3fSmrg         break;
1878af69d88dSmrg      case GL_TEXTURE_BORDER:
1879af69d88dSmrg      case GL_TEXTURE_SHARED_SIZE:
1880af69d88dSmrg      case GL_TEXTURE_COMPRESSED:
1881af69d88dSmrg         *params = 0;
1882af69d88dSmrg         break;
1883af69d88dSmrg      case GL_TEXTURE_INTERNAL_FORMAT:
1884af69d88dSmrg         *params = internalFormat;
1885af69d88dSmrg         break;
1886af69d88dSmrg      case GL_TEXTURE_RED_SIZE:
1887af69d88dSmrg      case GL_TEXTURE_GREEN_SIZE:
1888af69d88dSmrg      case GL_TEXTURE_BLUE_SIZE:
1889af69d88dSmrg      case GL_TEXTURE_ALPHA_SIZE:
1890af69d88dSmrg         if (_mesa_base_format_has_channel(baseFormat, pname))
1891af69d88dSmrg            *params = _mesa_get_format_bits(texFormat, pname);
1892af69d88dSmrg         else
1893af69d88dSmrg            *params = 0;
1894af69d88dSmrg         break;
1895af69d88dSmrg      case GL_TEXTURE_INTENSITY_SIZE:
1896af69d88dSmrg      case GL_TEXTURE_LUMINANCE_SIZE:
1897af69d88dSmrg         if (_mesa_base_format_has_channel(baseFormat, pname)) {
1898af69d88dSmrg            *params = _mesa_get_format_bits(texFormat, pname);
1899af69d88dSmrg            if (*params == 0) {
1900af69d88dSmrg               /* intensity or luminance is probably stored as RGB[A] */
1901af69d88dSmrg               *params = MIN2(_mesa_get_format_bits(texFormat,
1902af69d88dSmrg                                                    GL_TEXTURE_RED_SIZE),
1903af69d88dSmrg                              _mesa_get_format_bits(texFormat,
1904af69d88dSmrg                                                    GL_TEXTURE_GREEN_SIZE));
1905af69d88dSmrg            }
1906af69d88dSmrg         } else {
1907af69d88dSmrg            *params = 0;
1908c1f859d4Smrg         }
1909af69d88dSmrg         break;
1910af69d88dSmrg      case GL_TEXTURE_DEPTH_SIZE_ARB:
1911af69d88dSmrg      case GL_TEXTURE_STENCIL_SIZE_EXT:
1912af69d88dSmrg         *params = _mesa_get_format_bits(texFormat, pname);
1913af69d88dSmrg         break;
1914af69d88dSmrg
1915af69d88dSmrg      /* GL_ARB_texture_buffer_range */
1916af69d88dSmrg      case GL_TEXTURE_BUFFER_OFFSET:
1917af69d88dSmrg         if (!ctx->Extensions.ARB_texture_buffer_range)
19183464ebd5Sriastradh            goto invalid_pname;
1919af69d88dSmrg         *params = texObj->BufferOffset;
1920c1f859d4Smrg         break;
1921af69d88dSmrg      case GL_TEXTURE_BUFFER_SIZE:
1922af69d88dSmrg         if (!ctx->Extensions.ARB_texture_buffer_range)
19233464ebd5Sriastradh            goto invalid_pname;
1924af69d88dSmrg         *params = (texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize;
1925c1f859d4Smrg         break;
1926af69d88dSmrg
192701e04c3fSmrg      /* GL_ARB_texture_multisample */
192801e04c3fSmrg      case GL_TEXTURE_SAMPLES:
192901e04c3fSmrg         if (!ctx->Extensions.ARB_texture_multisample)
193001e04c3fSmrg            goto invalid_pname;
193101e04c3fSmrg         *params = 0;
193201e04c3fSmrg         break;
193301e04c3fSmrg
193401e04c3fSmrg      case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
193501e04c3fSmrg         if (!ctx->Extensions.ARB_texture_multisample)
193601e04c3fSmrg            goto invalid_pname;
193701e04c3fSmrg         *params = GL_TRUE;
193801e04c3fSmrg         break;
193901e04c3fSmrg
1940af69d88dSmrg      /* GL_ARB_texture_compression */
1941af69d88dSmrg      case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1942af69d88dSmrg         /* Always illegal for GL_TEXTURE_BUFFER */
1943af69d88dSmrg         _mesa_error(ctx, GL_INVALID_OPERATION,
194401e04c3fSmrg                     "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
194501e04c3fSmrg                     _mesa_enum_to_string(pname));
1946af69d88dSmrg         break;
1947af69d88dSmrg
1948af69d88dSmrg      /* GL_ARB_texture_float */
1949af69d88dSmrg      case GL_TEXTURE_RED_TYPE_ARB:
1950af69d88dSmrg      case GL_TEXTURE_GREEN_TYPE_ARB:
1951af69d88dSmrg      case GL_TEXTURE_BLUE_TYPE_ARB:
1952af69d88dSmrg      case GL_TEXTURE_ALPHA_TYPE_ARB:
1953af69d88dSmrg      case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1954af69d88dSmrg      case GL_TEXTURE_INTENSITY_TYPE_ARB:
1955c1f859d4Smrg      case GL_TEXTURE_DEPTH_TYPE_ARB:
1956af69d88dSmrg         if (!ctx->Extensions.ARB_texture_float)
19573464ebd5Sriastradh            goto invalid_pname;
1958af69d88dSmrg         if (_mesa_base_format_has_channel(baseFormat, pname))
1959af69d88dSmrg            *params = _mesa_get_format_datatype(texFormat);
1960af69d88dSmrg         else
1961af69d88dSmrg            *params = GL_NONE;
1962c1f859d4Smrg         break;
1963c1f859d4Smrg
1964c1f859d4Smrg      default:
19653464ebd5Sriastradh         goto invalid_pname;
1966c1f859d4Smrg   }
1967c1f859d4Smrg
19683464ebd5Sriastradh   /* no error if we get here */
19693464ebd5Sriastradh   return;
19703464ebd5Sriastradh
19713464ebd5Sriastradhinvalid_pname:
19723464ebd5Sriastradh   _mesa_error(ctx, GL_INVALID_ENUM,
197301e04c3fSmrg               "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
197401e04c3fSmrg               _mesa_enum_to_string(pname));
197501e04c3fSmrg}
197601e04c3fSmrg
197701e04c3fSmrgstatic bool
197801e04c3fSmrgvalid_tex_level_parameteriv_target(struct gl_context *ctx, GLenum target,
197901e04c3fSmrg                                   bool dsa)
198001e04c3fSmrg{
198101e04c3fSmrg   const char *suffix = dsa ? "ture" : "";
198201e04c3fSmrg   if (!_mesa_legal_get_tex_level_parameter_target(ctx, target, dsa)) {
198301e04c3fSmrg      _mesa_error(ctx, GL_INVALID_ENUM,
198401e04c3fSmrg                  "glGetTex%sLevelParameter[if]v(target=%s)", suffix,
198501e04c3fSmrg                  _mesa_enum_to_string(target));
198601e04c3fSmrg      return false;
198701e04c3fSmrg   }
198801e04c3fSmrg   return true;
1989c1f859d4Smrg}
1990c1f859d4Smrg
199101e04c3fSmrg/**
199201e04c3fSmrg * This isn't exposed to the rest of the driver because it is a part of the
199301e04c3fSmrg * OpenGL API that is rarely used.
199401e04c3fSmrg */
199501e04c3fSmrgstatic void
199601e04c3fSmrgget_tex_level_parameteriv(struct gl_context *ctx,
199701e04c3fSmrg                          struct gl_texture_object *texObj,
199801e04c3fSmrg                          GLenum target, GLint level,
199901e04c3fSmrg                          GLenum pname, GLint *params,
200001e04c3fSmrg                          bool dsa)
200101e04c3fSmrg{
200201e04c3fSmrg   GLint maxLevels;
200301e04c3fSmrg   const char *suffix = dsa ? "ture" : "";
200401e04c3fSmrg
200501e04c3fSmrg   /* Check for errors */
200601e04c3fSmrg   if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
200701e04c3fSmrg      _mesa_error(ctx, GL_INVALID_OPERATION,
200801e04c3fSmrg                  "glGetTex%sLevelParameter[if]v("
200901e04c3fSmrg                  "current unit >= max combined texture units)", suffix);
201001e04c3fSmrg      return;
201101e04c3fSmrg   }
201201e04c3fSmrg
201301e04c3fSmrg   maxLevels = _mesa_max_texture_levels(ctx, target);
201401e04c3fSmrg   assert(maxLevels != 0);
201501e04c3fSmrg
201601e04c3fSmrg   if (level < 0 || level >= maxLevels) {
201701e04c3fSmrg      _mesa_error(ctx, GL_INVALID_VALUE,
201801e04c3fSmrg                  "glGetTex%sLevelParameter[if]v(level out of range)", suffix);
201901e04c3fSmrg      return;
202001e04c3fSmrg   }
202101e04c3fSmrg
202201e04c3fSmrg   /* Get the level parameter */
202301e04c3fSmrg   if (target == GL_TEXTURE_BUFFER) {
202401e04c3fSmrg      get_tex_level_parameter_buffer(ctx, texObj, pname, params, dsa);
202501e04c3fSmrg   }
202601e04c3fSmrg   else {
202701e04c3fSmrg      get_tex_level_parameter_image(ctx, texObj, target,
202801e04c3fSmrg                                    level, pname, params, dsa);
202901e04c3fSmrg   }
203001e04c3fSmrg}
2031c1f859d4Smrg
2032af69d88dSmrgvoid GLAPIENTRY
2033af69d88dSmrg_mesa_GetTexLevelParameterfv( GLenum target, GLint level,
2034af69d88dSmrg                              GLenum pname, GLfloat *params )
2035af69d88dSmrg{
203601e04c3fSmrg   struct gl_texture_object *texObj;
2037af69d88dSmrg   GLint iparam;
203801e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
203901e04c3fSmrg
204001e04c3fSmrg   if (!valid_tex_level_parameteriv_target(ctx, target, false))
204101e04c3fSmrg      return;
204201e04c3fSmrg
204301e04c3fSmrg   texObj = _mesa_get_current_tex_object(ctx, target);
204401e04c3fSmrg   if (!texObj)
204501e04c3fSmrg      return;
204601e04c3fSmrg
204701e04c3fSmrg   get_tex_level_parameteriv(ctx, texObj, target, level,
204801e04c3fSmrg                             pname, &iparam, false);
204901e04c3fSmrg
2050af69d88dSmrg   *params = (GLfloat) iparam;
2051af69d88dSmrg}
2052af69d88dSmrg
2053af69d88dSmrgvoid GLAPIENTRY
2054af69d88dSmrg_mesa_GetTexLevelParameteriv( GLenum target, GLint level,
2055af69d88dSmrg                              GLenum pname, GLint *params )
2056af69d88dSmrg{
2057af69d88dSmrg   struct gl_texture_object *texObj;
2058af69d88dSmrg   GET_CURRENT_CONTEXT(ctx);
2059af69d88dSmrg
206001e04c3fSmrg   if (!valid_tex_level_parameteriv_target(ctx, target, false))
2061af69d88dSmrg      return;
2062af69d88dSmrg
206301e04c3fSmrg   texObj = _mesa_get_current_tex_object(ctx, target);
206401e04c3fSmrg   if (!texObj)
2065af69d88dSmrg      return;
2066af69d88dSmrg
206701e04c3fSmrg   get_tex_level_parameteriv(ctx, texObj, target, level,
206801e04c3fSmrg                             pname, params, false);
206901e04c3fSmrg}
2070af69d88dSmrg
207101e04c3fSmrgvoid GLAPIENTRY
207201e04c3fSmrg_mesa_GetTextureLevelParameterfv(GLuint texture, GLint level,
207301e04c3fSmrg                                 GLenum pname, GLfloat *params)
207401e04c3fSmrg{
207501e04c3fSmrg   struct gl_texture_object *texObj;
207601e04c3fSmrg   GLint iparam;
207701e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
207801e04c3fSmrg
207901e04c3fSmrg   texObj = _mesa_lookup_texture_err(ctx, texture,
208001e04c3fSmrg                                     "glGetTextureLevelParameterfv");
208101e04c3fSmrg   if (!texObj)
2082af69d88dSmrg      return;
2083af69d88dSmrg
208401e04c3fSmrg   if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
208501e04c3fSmrg      return;
2086af69d88dSmrg
208701e04c3fSmrg   get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
208801e04c3fSmrg                             pname, &iparam, true);
2089af69d88dSmrg
209001e04c3fSmrg   *params = (GLfloat) iparam;
209101e04c3fSmrg}
2092c1f859d4Smrg
20937ec681f3Smrgvoid GLAPIENTRY
20947ec681f3Smrg_mesa_GetTextureLevelParameterfvEXT(GLuint texture, GLenum target, GLint level,
20957ec681f3Smrg                                    GLenum pname, GLfloat *params)
20967ec681f3Smrg{
20977ec681f3Smrg   struct gl_texture_object *texObj;
20987ec681f3Smrg   GLint iparam;
20997ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
21007ec681f3Smrg
21017ec681f3Smrg   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
21027ec681f3Smrg                                           "glGetTextureLevelParameterfvEXT");
21037ec681f3Smrg   if (!texObj)
21047ec681f3Smrg      return;
21057ec681f3Smrg
21067ec681f3Smrg   if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
21077ec681f3Smrg      return;
21087ec681f3Smrg
21097ec681f3Smrg   get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
21107ec681f3Smrg                             pname, &iparam, true);
21117ec681f3Smrg
21127ec681f3Smrg   *params = (GLfloat) iparam;
21137ec681f3Smrg}
21147ec681f3Smrg
21157ec681f3Smrgvoid GLAPIENTRY
21167ec681f3Smrg_mesa_GetMultiTexLevelParameterfvEXT(GLenum texunit, GLenum target, GLint level,
21177ec681f3Smrg                                     GLenum pname, GLfloat *params)
21187ec681f3Smrg{
21197ec681f3Smrg   struct gl_texture_object *texObj;
21207ec681f3Smrg   GLint iparam;
21217ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
21227ec681f3Smrg
21237ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
21247ec681f3Smrg                                                   texunit - GL_TEXTURE0,
21257ec681f3Smrg                                                   true,
21267ec681f3Smrg                                                   "glGetMultiTexLevelParameterfvEXT");
21277ec681f3Smrg   if (!texObj)
21287ec681f3Smrg      return;
21297ec681f3Smrg
21307ec681f3Smrg   if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
21317ec681f3Smrg      return;
21327ec681f3Smrg
21337ec681f3Smrg   get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
21347ec681f3Smrg                             pname, &iparam, true);
21357ec681f3Smrg
21367ec681f3Smrg   *params = (GLfloat) iparam;
21377ec681f3Smrg}
21387ec681f3Smrg
2139c1f859d4Smrgvoid GLAPIENTRY
214001e04c3fSmrg_mesa_GetTextureLevelParameteriv(GLuint texture, GLint level,
214101e04c3fSmrg                                 GLenum pname, GLint *params)
2142c1f859d4Smrg{
214301e04c3fSmrg   struct gl_texture_object *texObj;
2144c1f859d4Smrg   GET_CURRENT_CONTEXT(ctx);
2145c1f859d4Smrg
214601e04c3fSmrg   texObj = _mesa_lookup_texture_err(ctx, texture,
214701e04c3fSmrg                                     "glGetTextureLevelParameteriv");
214801e04c3fSmrg   if (!texObj)
214901e04c3fSmrg      return;
215001e04c3fSmrg
215101e04c3fSmrg   if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2152c1f859d4Smrg      return;
2153c1f859d4Smrg
215401e04c3fSmrg   get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
215501e04c3fSmrg                             pname, params, true);
215601e04c3fSmrg}
215701e04c3fSmrg
21587ec681f3Smrgvoid GLAPIENTRY
21597ec681f3Smrg_mesa_GetTextureLevelParameterivEXT(GLuint texture, GLenum target, GLint level,
21607ec681f3Smrg                                    GLenum pname, GLint *params)
21617ec681f3Smrg{
21627ec681f3Smrg   struct gl_texture_object *texObj;
21637ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
21647ec681f3Smrg
21657ec681f3Smrg   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
21667ec681f3Smrg                                           "glGetTextureLevelParameterivEXT");
21677ec681f3Smrg   if (!texObj)
21687ec681f3Smrg      return;
21697ec681f3Smrg
21707ec681f3Smrg   if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
21717ec681f3Smrg      return;
21727ec681f3Smrg
21737ec681f3Smrg   get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
21747ec681f3Smrg                             pname, params, true);
21757ec681f3Smrg}
21767ec681f3Smrg
21777ec681f3Smrgvoid GLAPIENTRY
21787ec681f3Smrg_mesa_GetMultiTexLevelParameterivEXT(GLenum texunit, GLenum target, GLint level,
21797ec681f3Smrg                                     GLenum pname, GLint *params)
21807ec681f3Smrg{
21817ec681f3Smrg   struct gl_texture_object *texObj;
21827ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
21837ec681f3Smrg
21847ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
21857ec681f3Smrg                                                   texunit - GL_TEXTURE0,
21867ec681f3Smrg                                                   true,
21877ec681f3Smrg                                                   "glGetMultiTexLevelParameterivEXT");
21887ec681f3Smrg   if (!texObj)
21897ec681f3Smrg      return;
21907ec681f3Smrg
21917ec681f3Smrg   if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
21927ec681f3Smrg      return;
21937ec681f3Smrg
21947ec681f3Smrg   get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
21957ec681f3Smrg                             pname, params, true);
21967ec681f3Smrg}
21977ec681f3Smrg
21987ec681f3Smrg
219901e04c3fSmrg/**
220001e04c3fSmrg * This isn't exposed to the rest of the driver because it is a part of the
220101e04c3fSmrg * OpenGL API that is rarely used.
220201e04c3fSmrg */
220301e04c3fSmrgstatic void
220401e04c3fSmrgget_tex_parameterfv(struct gl_context *ctx,
220501e04c3fSmrg                    struct gl_texture_object *obj,
220601e04c3fSmrg                    GLenum pname, GLfloat *params, bool dsa)
220701e04c3fSmrg{
2208af69d88dSmrg   _mesa_lock_context_textures(ctx);
2209c1f859d4Smrg   switch (pname) {
2210c1f859d4Smrg      case GL_TEXTURE_MAG_FILTER:
22117ec681f3Smrg	 *params = ENUM_TO_FLOAT(obj->Sampler.Attrib.MagFilter);
2212c1f859d4Smrg	 break;
2213c1f859d4Smrg      case GL_TEXTURE_MIN_FILTER:
22147ec681f3Smrg         *params = ENUM_TO_FLOAT(obj->Sampler.Attrib.MinFilter);
2215c1f859d4Smrg         break;
2216c1f859d4Smrg      case GL_TEXTURE_WRAP_S:
22177ec681f3Smrg         *params = ENUM_TO_FLOAT(obj->Sampler.Attrib.WrapS);
2218c1f859d4Smrg         break;
2219c1f859d4Smrg      case GL_TEXTURE_WRAP_T:
22207ec681f3Smrg         *params = ENUM_TO_FLOAT(obj->Sampler.Attrib.WrapT);
2221c1f859d4Smrg         break;
2222c1f859d4Smrg      case GL_TEXTURE_WRAP_R:
22237ec681f3Smrg         *params = ENUM_TO_FLOAT(obj->Sampler.Attrib.WrapR);
2224c1f859d4Smrg         break;
2225c1f859d4Smrg      case GL_TEXTURE_BORDER_COLOR:
222601e04c3fSmrg         if (ctx->API == API_OPENGLES ||
222701e04c3fSmrg             !ctx->Extensions.ARB_texture_border_clamp)
2228af69d88dSmrg            goto invalid_pname;
2229af69d88dSmrg
223001e04c3fSmrg         if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer)) {
22317ec681f3Smrg            params[0] = CLAMP(obj->Sampler.Attrib.state.border_color.f[0], 0.0F, 1.0F);
22327ec681f3Smrg            params[1] = CLAMP(obj->Sampler.Attrib.state.border_color.f[1], 0.0F, 1.0F);
22337ec681f3Smrg            params[2] = CLAMP(obj->Sampler.Attrib.state.border_color.f[2], 0.0F, 1.0F);
22347ec681f3Smrg            params[3] = CLAMP(obj->Sampler.Attrib.state.border_color.f[3], 0.0F, 1.0F);
22353464ebd5Sriastradh         }
2236af69d88dSmrg         else {
22377ec681f3Smrg            params[0] = obj->Sampler.Attrib.state.border_color.f[0];
22387ec681f3Smrg            params[1] = obj->Sampler.Attrib.state.border_color.f[1];
22397ec681f3Smrg            params[2] = obj->Sampler.Attrib.state.border_color.f[2];
22407ec681f3Smrg            params[3] = obj->Sampler.Attrib.state.border_color.f[3];
22413464ebd5Sriastradh         }
2242c1f859d4Smrg         break;
2243c1f859d4Smrg      case GL_TEXTURE_RESIDENT:
2244af69d88dSmrg         if (ctx->API != API_OPENGL_COMPAT)
2245af69d88dSmrg            goto invalid_pname;
2246af69d88dSmrg
2247af69d88dSmrg         *params = 1.0F;
2248c1f859d4Smrg         break;
2249c1f859d4Smrg      case GL_TEXTURE_PRIORITY:
2250af69d88dSmrg         if (ctx->API != API_OPENGL_COMPAT)
2251af69d88dSmrg            goto invalid_pname;
2252af69d88dSmrg
22537ec681f3Smrg         *params = obj->Attrib.Priority;
2254c1f859d4Smrg         break;
2255c1f859d4Smrg      case GL_TEXTURE_MIN_LOD:
2256af69d88dSmrg         if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2257af69d88dSmrg            goto invalid_pname;
2258af69d88dSmrg
22597ec681f3Smrg         *params = obj->Sampler.Attrib.MinLod;
2260c1f859d4Smrg         break;
2261c1f859d4Smrg      case GL_TEXTURE_MAX_LOD:
2262af69d88dSmrg         if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2263af69d88dSmrg            goto invalid_pname;
2264af69d88dSmrg
22657ec681f3Smrg         *params = obj->Sampler.Attrib.MaxLod;
2266c1f859d4Smrg         break;
2267c1f859d4Smrg      case GL_TEXTURE_BASE_LEVEL:
2268af69d88dSmrg         if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2269af69d88dSmrg            goto invalid_pname;
2270af69d88dSmrg
22717ec681f3Smrg         *params = (GLfloat) obj->Attrib.BaseLevel;
2272c1f859d4Smrg         break;
2273c1f859d4Smrg      case GL_TEXTURE_MAX_LEVEL:
22747ec681f3Smrg         *params = (GLfloat) obj->Attrib.MaxLevel;
2275c1f859d4Smrg         break;
2276c1f859d4Smrg      case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2277af69d88dSmrg         if (!ctx->Extensions.EXT_texture_filter_anisotropic)
2278af69d88dSmrg            goto invalid_pname;
22797ec681f3Smrg         *params = obj->Sampler.Attrib.MaxAnisotropy;
2280c1f859d4Smrg         break;
2281c1f859d4Smrg      case GL_GENERATE_MIPMAP_SGIS:
2282af69d88dSmrg         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
2283af69d88dSmrg            goto invalid_pname;
2284af69d88dSmrg
22857ec681f3Smrg	 *params = (GLfloat) obj->Attrib.GenerateMipmap;
2286c1f859d4Smrg         break;
2287c1f859d4Smrg      case GL_TEXTURE_COMPARE_MODE_ARB:
2288af69d88dSmrg         if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2289af69d88dSmrg             && !_mesa_is_gles3(ctx))
2290af69d88dSmrg            goto invalid_pname;
22917ec681f3Smrg         *params = (GLfloat) obj->Sampler.Attrib.CompareMode;
2292c1f859d4Smrg         break;
2293c1f859d4Smrg      case GL_TEXTURE_COMPARE_FUNC_ARB:
2294af69d88dSmrg         if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2295af69d88dSmrg             && !_mesa_is_gles3(ctx))
2296af69d88dSmrg            goto invalid_pname;
22977ec681f3Smrg         *params = (GLfloat) obj->Sampler.Attrib.CompareFunc;
2298c1f859d4Smrg         break;
2299c1f859d4Smrg      case GL_DEPTH_TEXTURE_MODE_ARB:
2300af69d88dSmrg         /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
2301af69d88dSmrg          * never existed in OpenGL ES.
2302af69d88dSmrg          */
2303af69d88dSmrg         if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
2304af69d88dSmrg            goto invalid_pname;
23057ec681f3Smrg         *params = (GLfloat) obj->Attrib.DepthMode;
2306af69d88dSmrg         break;
2307af69d88dSmrg      case GL_DEPTH_STENCIL_TEXTURE_MODE:
230801e04c3fSmrg         if (!_mesa_has_ARB_stencil_texturing(ctx) && !_mesa_is_gles31(ctx))
2309af69d88dSmrg            goto invalid_pname;
2310af69d88dSmrg         *params = (GLfloat)
2311af69d88dSmrg            (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
2312c1f859d4Smrg         break;
2313c1f859d4Smrg      case GL_TEXTURE_LOD_BIAS:
2314af69d88dSmrg         if (_mesa_is_gles(ctx))
2315af69d88dSmrg            goto invalid_pname;
2316af69d88dSmrg
23177ec681f3Smrg         *params = obj->Sampler.Attrib.LodBias;
2318c1f859d4Smrg         break;
2319c1f859d4Smrg      case GL_TEXTURE_CROP_RECT_OES:
2320af69d88dSmrg         if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
2321af69d88dSmrg            goto invalid_pname;
2322af69d88dSmrg
2323af69d88dSmrg         params[0] = (GLfloat) obj->CropRect[0];
2324af69d88dSmrg         params[1] = (GLfloat) obj->CropRect[1];
2325af69d88dSmrg         params[2] = (GLfloat) obj->CropRect[2];
2326af69d88dSmrg         params[3] = (GLfloat) obj->CropRect[3];
2327c1f859d4Smrg         break;
23284a49301eSmrg
23294a49301eSmrg      case GL_TEXTURE_SWIZZLE_R_EXT:
23304a49301eSmrg      case GL_TEXTURE_SWIZZLE_G_EXT:
23314a49301eSmrg      case GL_TEXTURE_SWIZZLE_B_EXT:
23324a49301eSmrg      case GL_TEXTURE_SWIZZLE_A_EXT:
2333af69d88dSmrg         if ((!_mesa_is_desktop_gl(ctx)
2334af69d88dSmrg              || !ctx->Extensions.EXT_texture_swizzle)
2335af69d88dSmrg             && !_mesa_is_gles3(ctx))
2336af69d88dSmrg            goto invalid_pname;
23377ec681f3Smrg         *params = (GLfloat) obj->Attrib.Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
23384a49301eSmrg         break;
23394a49301eSmrg
23404a49301eSmrg      case GL_TEXTURE_SWIZZLE_RGBA_EXT:
2341af69d88dSmrg         if ((!_mesa_is_desktop_gl(ctx)
2342af69d88dSmrg              || !ctx->Extensions.EXT_texture_swizzle)
2343af69d88dSmrg             && !_mesa_is_gles3(ctx)) {
2344af69d88dSmrg            goto invalid_pname;
2345af69d88dSmrg         }
2346af69d88dSmrg         else {
23474a49301eSmrg            GLuint comp;
23484a49301eSmrg            for (comp = 0; comp < 4; comp++) {
23497ec681f3Smrg               params[comp] = (GLfloat) obj->Attrib.Swizzle[comp];
23504a49301eSmrg            }
23514a49301eSmrg         }
23524a49301eSmrg         break;
23534a49301eSmrg
23543464ebd5Sriastradh      case GL_TEXTURE_CUBE_MAP_SEAMLESS:
2355af69d88dSmrg         if (!_mesa_is_desktop_gl(ctx)
2356af69d88dSmrg             || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
2357af69d88dSmrg            goto invalid_pname;
23587ec681f3Smrg         *params = (GLfloat) obj->Sampler.Attrib.CubeMapSeamless;
2359af69d88dSmrg         break;
2360af69d88dSmrg
2361af69d88dSmrg      case GL_TEXTURE_IMMUTABLE_FORMAT:
2362af69d88dSmrg         *params = (GLfloat) obj->Immutable;
2363af69d88dSmrg         break;
2364af69d88dSmrg
2365af69d88dSmrg      case GL_TEXTURE_IMMUTABLE_LEVELS:
236601e04c3fSmrg         if (_mesa_is_gles3(ctx) || _mesa_has_texture_view(ctx))
23677ec681f3Smrg            *params = (GLfloat) obj->Attrib.ImmutableLevels;
2368af69d88dSmrg         else
2369af69d88dSmrg            goto invalid_pname;
2370af69d88dSmrg         break;
2371af69d88dSmrg
2372af69d88dSmrg      case GL_TEXTURE_VIEW_MIN_LEVEL:
237301e04c3fSmrg         if (!_mesa_has_texture_view(ctx))
2374af69d88dSmrg            goto invalid_pname;
23757ec681f3Smrg         *params = (GLfloat) obj->Attrib.MinLevel;
2376af69d88dSmrg         break;
2377af69d88dSmrg
2378af69d88dSmrg      case GL_TEXTURE_VIEW_NUM_LEVELS:
237901e04c3fSmrg         if (!_mesa_has_texture_view(ctx))
2380af69d88dSmrg            goto invalid_pname;
23817ec681f3Smrg         *params = (GLfloat) obj->Attrib.NumLevels;
2382af69d88dSmrg         break;
2383af69d88dSmrg
2384af69d88dSmrg      case GL_TEXTURE_VIEW_MIN_LAYER:
238501e04c3fSmrg         if (!_mesa_has_texture_view(ctx))
2386af69d88dSmrg            goto invalid_pname;
23877ec681f3Smrg         *params = (GLfloat) obj->Attrib.MinLayer;
2388af69d88dSmrg         break;
2389af69d88dSmrg
2390af69d88dSmrg      case GL_TEXTURE_VIEW_NUM_LAYERS:
239101e04c3fSmrg         if (!_mesa_has_texture_view(ctx))
2392af69d88dSmrg            goto invalid_pname;
23937ec681f3Smrg         *params = (GLfloat) obj->Attrib.NumLayers;
2394af69d88dSmrg         break;
2395af69d88dSmrg
2396af69d88dSmrg      case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
2397af69d88dSmrg         if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
2398af69d88dSmrg            goto invalid_pname;
2399af69d88dSmrg         *params = (GLfloat) obj->RequiredTextureImageUnits;
2400af69d88dSmrg         break;
2401af69d88dSmrg
2402af69d88dSmrg      case GL_TEXTURE_SRGB_DECODE_EXT:
2403af69d88dSmrg         if (!ctx->Extensions.EXT_texture_sRGB_decode)
2404af69d88dSmrg            goto invalid_pname;
24057ec681f3Smrg         *params = (GLfloat) obj->Sampler.Attrib.sRGBDecode;
24067ec681f3Smrg         break;
24077ec681f3Smrg
24087ec681f3Smrg      case GL_TEXTURE_REDUCTION_MODE_EXT:
24097ec681f3Smrg         if (!ctx->Extensions.EXT_texture_filter_minmax &&
24107ec681f3Smrg             !_mesa_has_ARB_texture_filter_minmax(ctx))
24117ec681f3Smrg            goto invalid_pname;
24127ec681f3Smrg         *params = (GLfloat) obj->Sampler.Attrib.ReductionMode;
24133464ebd5Sriastradh         break;
24143464ebd5Sriastradh
241501e04c3fSmrg      case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
241601e04c3fSmrg         if (!ctx->Extensions.ARB_shader_image_load_store)
241701e04c3fSmrg            goto invalid_pname;
24187ec681f3Smrg         *params = (GLfloat) obj->Attrib.ImageFormatCompatibilityType;
241901e04c3fSmrg         break;
242001e04c3fSmrg
242101e04c3fSmrg      case GL_TEXTURE_TARGET:
242201e04c3fSmrg         if (ctx->API != API_OPENGL_CORE)
242301e04c3fSmrg            goto invalid_pname;
242401e04c3fSmrg         *params = ENUM_TO_FLOAT(obj->Target);
242501e04c3fSmrg         break;
242601e04c3fSmrg
242701e04c3fSmrg      case GL_TEXTURE_TILING_EXT:
242801e04c3fSmrg         if (!ctx->Extensions.EXT_memory_object)
242901e04c3fSmrg            goto invalid_pname;
243001e04c3fSmrg         *params = ENUM_TO_FLOAT(obj->TextureTiling);
243101e04c3fSmrg         break;
243201e04c3fSmrg
2433c1f859d4Smrg      default:
2434af69d88dSmrg         goto invalid_pname;
2435c1f859d4Smrg   }
24364a49301eSmrg
2437af69d88dSmrg   /* no error if we get here */
2438af69d88dSmrg   _mesa_unlock_context_textures(ctx);
2439af69d88dSmrg   return;
2440c1f859d4Smrg
2441af69d88dSmrginvalid_pname:
2442af69d88dSmrg   _mesa_unlock_context_textures(ctx);
244301e04c3fSmrg   _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameterfv(pname=0x%x)",
244401e04c3fSmrg               dsa ? "ture" : "", pname);
2445c1f859d4Smrg}
2446c1f859d4Smrg
2447c1f859d4Smrg
244801e04c3fSmrgstatic void
244901e04c3fSmrgget_tex_parameteriv(struct gl_context *ctx,
245001e04c3fSmrg                    struct gl_texture_object *obj,
245101e04c3fSmrg                    GLenum pname, GLint *params, bool dsa)
2452c1f859d4Smrg{
24534a49301eSmrg   _mesa_lock_texture(ctx, obj);
2454c1f859d4Smrg   switch (pname) {
2455c1f859d4Smrg      case GL_TEXTURE_MAG_FILTER:
24567ec681f3Smrg         *params = (GLint) obj->Sampler.Attrib.MagFilter;
2457af69d88dSmrg         break;
2458c1f859d4Smrg      case GL_TEXTURE_MIN_FILTER:
24597ec681f3Smrg         *params = (GLint) obj->Sampler.Attrib.MinFilter;
2460af69d88dSmrg         break;
2461c1f859d4Smrg      case GL_TEXTURE_WRAP_S:
24627ec681f3Smrg         *params = (GLint) obj->Sampler.Attrib.WrapS;
2463af69d88dSmrg         break;
2464c1f859d4Smrg      case GL_TEXTURE_WRAP_T:
24657ec681f3Smrg         *params = (GLint) obj->Sampler.Attrib.WrapT;
2466af69d88dSmrg         break;
2467c1f859d4Smrg      case GL_TEXTURE_WRAP_R:
24687ec681f3Smrg         *params = (GLint) obj->Sampler.Attrib.WrapR;
2469af69d88dSmrg         break;
2470c1f859d4Smrg      case GL_TEXTURE_BORDER_COLOR:
247101e04c3fSmrg         if (ctx->API == API_OPENGLES ||
247201e04c3fSmrg             !ctx->Extensions.ARB_texture_border_clamp)
2473af69d88dSmrg            goto invalid_pname;
2474af69d88dSmrg
2475c1f859d4Smrg         {
2476c1f859d4Smrg            GLfloat b[4];
24777ec681f3Smrg            b[0] = CLAMP(obj->Sampler.Attrib.state.border_color.f[0], 0.0F, 1.0F);
24787ec681f3Smrg            b[1] = CLAMP(obj->Sampler.Attrib.state.border_color.f[1], 0.0F, 1.0F);
24797ec681f3Smrg            b[2] = CLAMP(obj->Sampler.Attrib.state.border_color.f[2], 0.0F, 1.0F);
24807ec681f3Smrg            b[3] = CLAMP(obj->Sampler.Attrib.state.border_color.f[3], 0.0F, 1.0F);
2481c1f859d4Smrg            params[0] = FLOAT_TO_INT(b[0]);
2482c1f859d4Smrg            params[1] = FLOAT_TO_INT(b[1]);
2483c1f859d4Smrg            params[2] = FLOAT_TO_INT(b[2]);
2484c1f859d4Smrg            params[3] = FLOAT_TO_INT(b[3]);
2485c1f859d4Smrg         }
2486af69d88dSmrg         break;
2487c1f859d4Smrg      case GL_TEXTURE_RESIDENT:
2488af69d88dSmrg         if (ctx->API != API_OPENGL_COMPAT)
2489af69d88dSmrg            goto invalid_pname;
2490af69d88dSmrg
2491af69d88dSmrg         *params = 1;
2492af69d88dSmrg         break;
2493c1f859d4Smrg      case GL_TEXTURE_PRIORITY:
2494af69d88dSmrg         if (ctx->API != API_OPENGL_COMPAT)
2495af69d88dSmrg            goto invalid_pname;
2496af69d88dSmrg
24977ec681f3Smrg         *params = FLOAT_TO_INT(obj->Attrib.Priority);
2498af69d88dSmrg         break;
2499c1f859d4Smrg      case GL_TEXTURE_MIN_LOD:
2500af69d88dSmrg         if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2501af69d88dSmrg            goto invalid_pname;
250201e04c3fSmrg         /* GL spec 'Data Conversions' section specifies that floating-point
250301e04c3fSmrg          * value in integer Get function is rounded to nearest integer
25047ec681f3Smrg          *
25057ec681f3Smrg          * Section 2.2.2 (Data Conversions For State Query Commands) of the
25067ec681f3Smrg          * OpenGL 4.5 spec says:
25077ec681f3Smrg          *
25087ec681f3Smrg          *   Following these steps, if a value is so large in magnitude that
25097ec681f3Smrg          *   it cannot be represented by the returned data type, then the
25107ec681f3Smrg          *   nearest value representable using that type is returned.
251101e04c3fSmrg          */
25127ec681f3Smrg         *params = LCLAMPF(obj->Sampler.Attrib.MinLod, INT_MIN, INT_MAX);
2513af69d88dSmrg         break;
2514c1f859d4Smrg      case GL_TEXTURE_MAX_LOD:
2515af69d88dSmrg         if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2516af69d88dSmrg            goto invalid_pname;
251701e04c3fSmrg         /* GL spec 'Data Conversions' section specifies that floating-point
251801e04c3fSmrg          * value in integer Get function is rounded to nearest integer
25197ec681f3Smrg          *
25207ec681f3Smrg          * Section 2.2.2 (Data Conversions For State Query Commands) of the
25217ec681f3Smrg          * OpenGL 4.5 spec says:
25227ec681f3Smrg          *
25237ec681f3Smrg          *   Following these steps, if a value is so large in magnitude that
25247ec681f3Smrg          *   it cannot be represented by the returned data type, then the
25257ec681f3Smrg          *   nearest value representable using that type is returned.
252601e04c3fSmrg          */
25277ec681f3Smrg         *params = LCLAMPF(obj->Sampler.Attrib.MaxLod, INT_MIN, INT_MAX);
2528af69d88dSmrg         break;
2529c1f859d4Smrg      case GL_TEXTURE_BASE_LEVEL:
2530af69d88dSmrg         if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2531af69d88dSmrg            goto invalid_pname;
2532af69d88dSmrg
25337ec681f3Smrg         *params = obj->Attrib.BaseLevel;
2534af69d88dSmrg         break;
2535c1f859d4Smrg      case GL_TEXTURE_MAX_LEVEL:
25367ec681f3Smrg         *params = obj->Attrib.MaxLevel;
2537c1f859d4Smrg         break;
2538af69d88dSmrg      case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2539af69d88dSmrg         if (!ctx->Extensions.EXT_texture_filter_anisotropic)
2540af69d88dSmrg            goto invalid_pname;
254101e04c3fSmrg         /* GL spec 'Data Conversions' section specifies that floating-point
254201e04c3fSmrg          * value in integer Get function is rounded to nearest integer
25437ec681f3Smrg          *
25447ec681f3Smrg          * Section 2.2.2 (Data Conversions For State Query Commands) of the
25457ec681f3Smrg          * OpenGL 4.5 spec says:
25467ec681f3Smrg          *
25477ec681f3Smrg          *   Following these steps, if a value is so large in magnitude that
25487ec681f3Smrg          *   it cannot be represented by the returned data type, then the
25497ec681f3Smrg          *   nearest value representable using that type is returned.
255001e04c3fSmrg          */
25517ec681f3Smrg         *params = LCLAMPF(obj->Sampler.Attrib.MaxAnisotropy, INT_MIN, INT_MAX);
2552c1f859d4Smrg         break;
2553c1f859d4Smrg      case GL_GENERATE_MIPMAP_SGIS:
2554af69d88dSmrg         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
2555af69d88dSmrg            goto invalid_pname;
2556af69d88dSmrg
25577ec681f3Smrg	 *params = (GLint) obj->Attrib.GenerateMipmap;
2558c1f859d4Smrg         break;
2559c1f859d4Smrg      case GL_TEXTURE_COMPARE_MODE_ARB:
2560af69d88dSmrg         if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2561af69d88dSmrg             && !_mesa_is_gles3(ctx))
2562af69d88dSmrg            goto invalid_pname;
25637ec681f3Smrg         *params = (GLint) obj->Sampler.Attrib.CompareMode;
2564c1f859d4Smrg         break;
2565c1f859d4Smrg      case GL_TEXTURE_COMPARE_FUNC_ARB:
2566af69d88dSmrg         if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2567af69d88dSmrg             && !_mesa_is_gles3(ctx))
2568af69d88dSmrg            goto invalid_pname;
25697ec681f3Smrg         *params = (GLint) obj->Sampler.Attrib.CompareFunc;
2570c1f859d4Smrg         break;
2571c1f859d4Smrg      case GL_DEPTH_TEXTURE_MODE_ARB:
2572af69d88dSmrg         if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
2573af69d88dSmrg            goto invalid_pname;
25747ec681f3Smrg         *params = (GLint) obj->Attrib.DepthMode;
2575af69d88dSmrg         break;
2576af69d88dSmrg      case GL_DEPTH_STENCIL_TEXTURE_MODE:
257701e04c3fSmrg         if (!_mesa_has_ARB_stencil_texturing(ctx) && !_mesa_is_gles31(ctx))
2578af69d88dSmrg            goto invalid_pname;
2579af69d88dSmrg         *params = (GLint)
2580af69d88dSmrg            (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
2581c1f859d4Smrg         break;
2582c1f859d4Smrg      case GL_TEXTURE_LOD_BIAS:
2583af69d88dSmrg         if (_mesa_is_gles(ctx))
2584af69d88dSmrg            goto invalid_pname;
2585af69d88dSmrg
2586af69d88dSmrg         /* GL spec 'Data Conversions' section specifies that floating-point
2587af69d88dSmrg          * value in integer Get function is rounded to nearest integer
25887ec681f3Smrg          *
25897ec681f3Smrg          * Section 2.2.2 (Data Conversions For State Query Commands) of the
25907ec681f3Smrg          * OpenGL 4.5 spec says:
25917ec681f3Smrg          *
25927ec681f3Smrg          *   Following these steps, if a value is so large in magnitude that
25937ec681f3Smrg          *   it cannot be represented by the returned data type, then the
25947ec681f3Smrg          *   nearest value representable using that type is returned.
2595af69d88dSmrg          */
25967ec681f3Smrg         *params = LCLAMPF(obj->Sampler.Attrib.LodBias, INT_MIN, INT_MAX);
2597c1f859d4Smrg         break;
2598c1f859d4Smrg      case GL_TEXTURE_CROP_RECT_OES:
2599af69d88dSmrg         if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
2600af69d88dSmrg            goto invalid_pname;
2601af69d88dSmrg
2602c1f859d4Smrg         params[0] = obj->CropRect[0];
2603c1f859d4Smrg         params[1] = obj->CropRect[1];
2604c1f859d4Smrg         params[2] = obj->CropRect[2];
2605c1f859d4Smrg         params[3] = obj->CropRect[3];
2606c1f859d4Smrg         break;
26074a49301eSmrg      case GL_TEXTURE_SWIZZLE_R_EXT:
26084a49301eSmrg      case GL_TEXTURE_SWIZZLE_G_EXT:
26094a49301eSmrg      case GL_TEXTURE_SWIZZLE_B_EXT:
26104a49301eSmrg      case GL_TEXTURE_SWIZZLE_A_EXT:
2611af69d88dSmrg         if ((!_mesa_is_desktop_gl(ctx)
2612af69d88dSmrg              || !ctx->Extensions.EXT_texture_swizzle)
2613af69d88dSmrg             && !_mesa_is_gles3(ctx))
2614af69d88dSmrg            goto invalid_pname;
26157ec681f3Smrg         *params = obj->Attrib.Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
26164a49301eSmrg         break;
26174a49301eSmrg
26184a49301eSmrg      case GL_TEXTURE_SWIZZLE_RGBA_EXT:
2619af69d88dSmrg         if ((!_mesa_is_desktop_gl(ctx)
2620af69d88dSmrg              || !ctx->Extensions.EXT_texture_swizzle)
2621af69d88dSmrg             && !_mesa_is_gles3(ctx))
2622af69d88dSmrg            goto invalid_pname;
26237ec681f3Smrg         COPY_4V(params, obj->Attrib.Swizzle);
26244a49301eSmrg         break;
26254a49301eSmrg
26263464ebd5Sriastradh      case GL_TEXTURE_CUBE_MAP_SEAMLESS:
2627af69d88dSmrg         if (!_mesa_is_desktop_gl(ctx)
2628af69d88dSmrg             || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
2629af69d88dSmrg            goto invalid_pname;
26307ec681f3Smrg         *params = (GLint) obj->Sampler.Attrib.CubeMapSeamless;
2631af69d88dSmrg         break;
2632af69d88dSmrg
2633af69d88dSmrg      case GL_TEXTURE_IMMUTABLE_FORMAT:
2634af69d88dSmrg         *params = (GLint) obj->Immutable;
2635af69d88dSmrg         break;
2636af69d88dSmrg
2637af69d88dSmrg      case GL_TEXTURE_IMMUTABLE_LEVELS:
2638af69d88dSmrg         if (_mesa_is_gles3(ctx) ||
2639af69d88dSmrg             (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_view))
26407ec681f3Smrg            *params = obj->Attrib.ImmutableLevels;
2641af69d88dSmrg         else
2642af69d88dSmrg            goto invalid_pname;
2643af69d88dSmrg         break;
2644af69d88dSmrg
2645af69d88dSmrg      case GL_TEXTURE_VIEW_MIN_LEVEL:
2646af69d88dSmrg         if (!ctx->Extensions.ARB_texture_view)
2647af69d88dSmrg            goto invalid_pname;
26487ec681f3Smrg         *params = (GLint) obj->Attrib.MinLevel;
2649af69d88dSmrg         break;
2650af69d88dSmrg
2651af69d88dSmrg      case GL_TEXTURE_VIEW_NUM_LEVELS:
2652af69d88dSmrg         if (!ctx->Extensions.ARB_texture_view)
2653af69d88dSmrg            goto invalid_pname;
26547ec681f3Smrg         *params = (GLint) obj->Attrib.NumLevels;
2655af69d88dSmrg         break;
2656af69d88dSmrg
2657af69d88dSmrg      case GL_TEXTURE_VIEW_MIN_LAYER:
2658af69d88dSmrg         if (!ctx->Extensions.ARB_texture_view)
2659af69d88dSmrg            goto invalid_pname;
26607ec681f3Smrg         *params = (GLint) obj->Attrib.MinLayer;
2661af69d88dSmrg         break;
2662af69d88dSmrg
2663af69d88dSmrg      case GL_TEXTURE_VIEW_NUM_LAYERS:
2664af69d88dSmrg         if (!ctx->Extensions.ARB_texture_view)
2665af69d88dSmrg            goto invalid_pname;
26667ec681f3Smrg         *params = (GLint) obj->Attrib.NumLayers;
2667af69d88dSmrg         break;
2668af69d88dSmrg
2669af69d88dSmrg      case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
2670af69d88dSmrg         if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
2671af69d88dSmrg            goto invalid_pname;
2672af69d88dSmrg         *params = obj->RequiredTextureImageUnits;
2673af69d88dSmrg         break;
2674af69d88dSmrg
2675af69d88dSmrg      case GL_TEXTURE_SRGB_DECODE_EXT:
2676af69d88dSmrg         if (!ctx->Extensions.EXT_texture_sRGB_decode)
2677af69d88dSmrg            goto invalid_pname;
26787ec681f3Smrg         *params = obj->Sampler.Attrib.sRGBDecode;
26797ec681f3Smrg         break;
26807ec681f3Smrg
26817ec681f3Smrg      case GL_TEXTURE_REDUCTION_MODE_EXT:
26827ec681f3Smrg         if (!ctx->Extensions.EXT_texture_filter_minmax &&
26837ec681f3Smrg             !_mesa_has_ARB_texture_filter_minmax(ctx))
26847ec681f3Smrg            goto invalid_pname;
26857ec681f3Smrg         *params = obj->Sampler.Attrib.ReductionMode;
2686af69d88dSmrg         break;
2687af69d88dSmrg
2688af69d88dSmrg      case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
2689af69d88dSmrg         if (!ctx->Extensions.ARB_shader_image_load_store)
2690af69d88dSmrg            goto invalid_pname;
26917ec681f3Smrg         *params = obj->Attrib.ImageFormatCompatibilityType;
26923464ebd5Sriastradh         break;
26933464ebd5Sriastradh
269401e04c3fSmrg      case GL_TEXTURE_TARGET:
269501e04c3fSmrg         if (ctx->API != API_OPENGL_CORE)
269601e04c3fSmrg            goto invalid_pname;
269701e04c3fSmrg         *params = (GLint) obj->Target;
269801e04c3fSmrg         break;
269901e04c3fSmrg
270001e04c3fSmrg      case GL_TEXTURE_TILING_EXT:
270101e04c3fSmrg         if (!ctx->Extensions.EXT_memory_object)
270201e04c3fSmrg            goto invalid_pname;
270301e04c3fSmrg         *params = (GLint) obj->TextureTiling;
270401e04c3fSmrg         break;
270501e04c3fSmrg
2706c1f859d4Smrg      default:
2707af69d88dSmrg         goto invalid_pname;
2708c1f859d4Smrg   }
27094a49301eSmrg
2710af69d88dSmrg   /* no error if we get here */
2711af69d88dSmrg   _mesa_unlock_texture(ctx, obj);
2712af69d88dSmrg   return;
27134a49301eSmrg
2714af69d88dSmrginvalid_pname:
27154a49301eSmrg   _mesa_unlock_texture(ctx, obj);
271601e04c3fSmrg   _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameteriv(pname=0x%x)",
271701e04c3fSmrg               dsa ? "ture" : "", pname);
271801e04c3fSmrg}
271901e04c3fSmrg
272001e04c3fSmrgstatic void
272101e04c3fSmrgget_tex_parameterIiv(struct gl_context *ctx,
272201e04c3fSmrg                     struct gl_texture_object *obj,
272301e04c3fSmrg                     GLenum pname, GLint *params, bool dsa)
272401e04c3fSmrg{
272501e04c3fSmrg   switch (pname) {
272601e04c3fSmrg   case GL_TEXTURE_BORDER_COLOR:
27277ec681f3Smrg      COPY_4V(params, obj->Sampler.Attrib.state.border_color.i);
272801e04c3fSmrg      break;
272901e04c3fSmrg   default:
273001e04c3fSmrg      get_tex_parameteriv(ctx, obj, pname, params, dsa);
273101e04c3fSmrg   }
273201e04c3fSmrg}
273301e04c3fSmrg
273401e04c3fSmrgvoid GLAPIENTRY
273501e04c3fSmrg_mesa_GetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
273601e04c3fSmrg{
273701e04c3fSmrg   struct gl_texture_object *obj;
273801e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
273901e04c3fSmrg
27407ec681f3Smrg   obj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
27417ec681f3Smrg                                                ctx->Texture.CurrentUnit,
27427ec681f3Smrg                                                false,
27437ec681f3Smrg                                                "glGetTexParameterfv");
274401e04c3fSmrg   if (!obj)
274501e04c3fSmrg      return;
274601e04c3fSmrg
274701e04c3fSmrg   get_tex_parameterfv(ctx, obj, pname, params, false);
2748c1f859d4Smrg}
2749cdc920a0Smrg
275001e04c3fSmrgvoid GLAPIENTRY
275101e04c3fSmrg_mesa_GetTexParameteriv(GLenum target, GLenum pname, GLint *params)
275201e04c3fSmrg{
275301e04c3fSmrg   struct gl_texture_object *obj;
275401e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
275501e04c3fSmrg
27567ec681f3Smrg   obj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
27577ec681f3Smrg                                                ctx->Texture.CurrentUnit,
27587ec681f3Smrg                                                false,
27597ec681f3Smrg                                                "glGetTexParameteriv");
276001e04c3fSmrg   if (!obj)
276101e04c3fSmrg      return;
276201e04c3fSmrg
276301e04c3fSmrg   get_tex_parameteriv(ctx, obj, pname, params, false);
276401e04c3fSmrg}
2765cdc920a0Smrg
2766cdc920a0Smrg/** New in GL 3.0 */
2767cdc920a0Smrgvoid GLAPIENTRY
2768cdc920a0Smrg_mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
2769cdc920a0Smrg{
2770cdc920a0Smrg   struct gl_texture_object *texObj;
2771cdc920a0Smrg   GET_CURRENT_CONTEXT(ctx);
2772cdc920a0Smrg
27737ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
27747ec681f3Smrg                                                ctx->Texture.CurrentUnit,
27757ec681f3Smrg                                                false,
27767ec681f3Smrg                                                "glGetTexParameterIiv");
2777af69d88dSmrg   if (!texObj)
2778af69d88dSmrg      return;
2779af69d88dSmrg
278001e04c3fSmrg   get_tex_parameterIiv(ctx, texObj, pname, params, false);
2781cdc920a0Smrg}
2782cdc920a0Smrg
2783cdc920a0Smrg
2784cdc920a0Smrg/** New in GL 3.0 */
2785cdc920a0Smrgvoid GLAPIENTRY
2786cdc920a0Smrg_mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
2787cdc920a0Smrg{
2788cdc920a0Smrg   struct gl_texture_object *texObj;
2789cdc920a0Smrg   GET_CURRENT_CONTEXT(ctx);
2790cdc920a0Smrg
27917ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
27927ec681f3Smrg                                                ctx->Texture.CurrentUnit,
27937ec681f3Smrg                                                false,
27947ec681f3Smrg                                                "glGetTexParameterIuiv");
2795af69d88dSmrg   if (!texObj)
2796af69d88dSmrg      return;
2797af69d88dSmrg
279801e04c3fSmrg   get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, false);
279901e04c3fSmrg}
280001e04c3fSmrg
28017ec681f3Smrgvoid GLAPIENTRY
28027ec681f3Smrg_mesa_GetTextureParameterfvEXT(GLuint texture, GLenum target, GLenum pname, GLfloat *params)
28037ec681f3Smrg{
28047ec681f3Smrg   struct gl_texture_object *texObj;
28057ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
28067ec681f3Smrg
28077ec681f3Smrg   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
28087ec681f3Smrg                                           "glGetTextureParameterfvEXT");
28097ec681f3Smrg   if (!texObj)
28107ec681f3Smrg      return;
28117ec681f3Smrg
28127ec681f3Smrg   if (!is_texparameteri_target_valid(texObj->Target)) {
28137ec681f3Smrg      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTextureParameterfvEXT");
28147ec681f3Smrg      return;
28157ec681f3Smrg   }
28167ec681f3Smrg
28177ec681f3Smrg   get_tex_parameterfv(ctx, texObj, pname, params, true);
28187ec681f3Smrg}
28197ec681f3Smrg
28207ec681f3Smrgvoid GLAPIENTRY
28217ec681f3Smrg_mesa_GetMultiTexParameterfvEXT(GLenum texunit, GLenum target, GLenum pname, GLfloat *params)
28227ec681f3Smrg{
28237ec681f3Smrg   struct gl_texture_object *texObj;
28247ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
28257ec681f3Smrg
28267ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
28277ec681f3Smrg                                                   texunit - GL_TEXTURE0,
28287ec681f3Smrg                                                   false,
28297ec681f3Smrg                                                   "glGetMultiTexParameterfvEXT");
28307ec681f3Smrg   if (!texObj)
28317ec681f3Smrg      return;
28327ec681f3Smrg
28337ec681f3Smrg   if (!is_texparameteri_target_valid(texObj->Target)) {
28347ec681f3Smrg      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetMultiTexParameterfvEXT");
28357ec681f3Smrg      return;
28367ec681f3Smrg   }
28377ec681f3Smrg   get_tex_parameterfv(ctx, texObj, pname, params, true);
28387ec681f3Smrg}
283901e04c3fSmrg
284001e04c3fSmrgvoid GLAPIENTRY
284101e04c3fSmrg_mesa_GetTextureParameterfv(GLuint texture, GLenum pname, GLfloat *params)
284201e04c3fSmrg{
284301e04c3fSmrg   struct gl_texture_object *obj;
284401e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
284501e04c3fSmrg
284601e04c3fSmrg   obj = get_texobj_by_name(ctx, texture, "glGetTextureParameterfv");
284701e04c3fSmrg   if (!obj)
284801e04c3fSmrg      return;
284901e04c3fSmrg
285001e04c3fSmrg   get_tex_parameterfv(ctx, obj, pname, params, true);
285101e04c3fSmrg}
285201e04c3fSmrg
28537ec681f3Smrgvoid GLAPIENTRY
28547ec681f3Smrg_mesa_GetTextureParameterivEXT(GLuint texture, GLenum target, GLenum pname, GLint *params)
28557ec681f3Smrg{
28567ec681f3Smrg   struct gl_texture_object *texObj;
28577ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
28587ec681f3Smrg
28597ec681f3Smrg   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
28607ec681f3Smrg                                           "glGetTextureParameterivEXT");
28617ec681f3Smrg   if (!texObj)
28627ec681f3Smrg      return;
28637ec681f3Smrg
28647ec681f3Smrg   if (!is_texparameteri_target_valid(texObj->Target)) {
28657ec681f3Smrg      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTextureParameterivEXT");
28667ec681f3Smrg      return;
28677ec681f3Smrg   }
28687ec681f3Smrg   get_tex_parameteriv(ctx, texObj, pname, params, true);
28697ec681f3Smrg}
28707ec681f3Smrg
28717ec681f3Smrgvoid GLAPIENTRY
28727ec681f3Smrg_mesa_GetMultiTexParameterivEXT(GLenum texunit, GLenum target, GLenum pname, GLint *params)
28737ec681f3Smrg{
28747ec681f3Smrg   struct gl_texture_object *texObj;
28757ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
28767ec681f3Smrg
28777ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
28787ec681f3Smrg                                                   texunit - GL_TEXTURE0,
28797ec681f3Smrg                                                   false,
28807ec681f3Smrg                                                   "glGetMultiTexParameterivEXT");
28817ec681f3Smrg   if (!texObj)
28827ec681f3Smrg      return;
28837ec681f3Smrg
28847ec681f3Smrg   if (!is_texparameteri_target_valid(texObj->Target)) {
28857ec681f3Smrg      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetMultiTexParameterivEXT");
28867ec681f3Smrg      return;
28877ec681f3Smrg   }
28887ec681f3Smrg   get_tex_parameteriv(ctx, texObj, pname, params, true);
28897ec681f3Smrg}
28907ec681f3Smrg
289101e04c3fSmrgvoid GLAPIENTRY
289201e04c3fSmrg_mesa_GetTextureParameteriv(GLuint texture, GLenum pname, GLint *params)
289301e04c3fSmrg{
289401e04c3fSmrg   struct gl_texture_object *obj;
289501e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
289601e04c3fSmrg
289701e04c3fSmrg   obj = get_texobj_by_name(ctx, texture, "glGetTextureParameteriv");
289801e04c3fSmrg   if (!obj)
289901e04c3fSmrg      return;
290001e04c3fSmrg
290101e04c3fSmrg   get_tex_parameteriv(ctx, obj, pname, params, true);
290201e04c3fSmrg}
290301e04c3fSmrg
290401e04c3fSmrgvoid GLAPIENTRY
290501e04c3fSmrg_mesa_GetTextureParameterIiv(GLuint texture, GLenum pname, GLint *params)
290601e04c3fSmrg{
290701e04c3fSmrg   struct gl_texture_object *texObj;
290801e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
290901e04c3fSmrg
291001e04c3fSmrg   texObj = get_texobj_by_name(ctx, texture, "glGetTextureParameterIiv");
291101e04c3fSmrg   if (!texObj)
291201e04c3fSmrg      return;
291301e04c3fSmrg
291401e04c3fSmrg   get_tex_parameterIiv(ctx, texObj, pname, params, true);
291501e04c3fSmrg}
291601e04c3fSmrg
29177ec681f3Smrgvoid GLAPIENTRY
29187ec681f3Smrg_mesa_GetTextureParameterIivEXT(GLuint texture, GLenum target, GLenum pname, GLint *params)
29197ec681f3Smrg{
29207ec681f3Smrg   struct gl_texture_object *texObj;
29217ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
29227ec681f3Smrg
29237ec681f3Smrg   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
29247ec681f3Smrg                                           "glGetTextureParameterIivEXT");
29257ec681f3Smrg   if (!texObj)
29267ec681f3Smrg      return;
29277ec681f3Smrg
29287ec681f3Smrg
29297ec681f3Smrg   get_tex_parameterIiv(ctx, texObj, pname, params, true);
29307ec681f3Smrg}
29317ec681f3Smrg
29327ec681f3Smrgvoid GLAPIENTRY
29337ec681f3Smrg_mesa_GetMultiTexParameterIivEXT(GLenum texunit, GLenum target, GLenum pname,
29347ec681f3Smrg                                 GLint *params)
29357ec681f3Smrg{
29367ec681f3Smrg   struct gl_texture_object *texObj;
29377ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
29387ec681f3Smrg
29397ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
29407ec681f3Smrg                                                   texunit - GL_TEXTURE0,
29417ec681f3Smrg                                                   true,
29427ec681f3Smrg                                                   "glGetMultiTexParameterIiv");
29437ec681f3Smrg   if (!texObj)
29447ec681f3Smrg      return;
29457ec681f3Smrg
29467ec681f3Smrg   get_tex_parameterIiv(ctx, texObj, pname, params, true);
29477ec681f3Smrg}
294801e04c3fSmrg
294901e04c3fSmrgvoid GLAPIENTRY
295001e04c3fSmrg_mesa_GetTextureParameterIuiv(GLuint texture, GLenum pname, GLuint *params)
295101e04c3fSmrg{
295201e04c3fSmrg   struct gl_texture_object *texObj;
295301e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
295401e04c3fSmrg
295501e04c3fSmrg   texObj = get_texobj_by_name(ctx, texture, "glGetTextureParameterIuiv");
295601e04c3fSmrg   if (!texObj)
295701e04c3fSmrg      return;
295801e04c3fSmrg
295901e04c3fSmrg   get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, true);
2960cdc920a0Smrg}
29617ec681f3Smrg
29627ec681f3Smrgvoid GLAPIENTRY
29637ec681f3Smrg_mesa_GetTextureParameterIuivEXT(GLuint texture, GLenum target, GLenum pname,
29647ec681f3Smrg                                 GLuint *params)
29657ec681f3Smrg{
29667ec681f3Smrg   struct gl_texture_object *texObj;
29677ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
29687ec681f3Smrg
29697ec681f3Smrg   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
29707ec681f3Smrg                                           "glGetTextureParameterIuvEXT");
29717ec681f3Smrg   if (!texObj)
29727ec681f3Smrg      return;
29737ec681f3Smrg
29747ec681f3Smrg   get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, true);
29757ec681f3Smrg}
29767ec681f3Smrg
29777ec681f3Smrgvoid GLAPIENTRY
29787ec681f3Smrg_mesa_GetMultiTexParameterIuivEXT(GLenum texunit, GLenum target, GLenum pname,
29797ec681f3Smrg                               GLuint *params)
29807ec681f3Smrg{
29817ec681f3Smrg   struct gl_texture_object *texObj;
29827ec681f3Smrg   GET_CURRENT_CONTEXT(ctx);
29837ec681f3Smrg
29847ec681f3Smrg   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
29857ec681f3Smrg                                                   texunit - GL_TEXTURE0,
29867ec681f3Smrg                                                   true,
29877ec681f3Smrg                                                   "glGetMultiTexParameterIuiv");
29887ec681f3Smrg   if (!texObj)
29897ec681f3Smrg      return;
29907ec681f3Smrg
29917ec681f3Smrg   get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, true);
29927ec681f3Smrg}
2993