1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Mesa 3-D graphics library
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
5bf215546Sopenharmony_ci * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
6bf215546Sopenharmony_ci *
7bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
8bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
9bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
10bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
12bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included
15bf215546Sopenharmony_ci * in all copies or substantial portions of the Software.
16bf215546Sopenharmony_ci *
17bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
24bf215546Sopenharmony_ci */
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci/**
27bf215546Sopenharmony_ci * \file texparam.c
28bf215546Sopenharmony_ci *
29bf215546Sopenharmony_ci * glTexParameter-related functions
30bf215546Sopenharmony_ci */
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci#include <stdbool.h>
33bf215546Sopenharmony_ci#include "main/glheader.h"
34bf215546Sopenharmony_ci#include "main/blend.h"
35bf215546Sopenharmony_ci#include "main/context.h"
36bf215546Sopenharmony_ci#include "main/enums.h"
37bf215546Sopenharmony_ci#include "main/formats.h"
38bf215546Sopenharmony_ci#include "main/glformats.h"
39bf215546Sopenharmony_ci#include "main/macros.h"
40bf215546Sopenharmony_ci#include "main/mtypes.h"
41bf215546Sopenharmony_ci#include "main/state.h"
42bf215546Sopenharmony_ci#include "main/texcompress.h"
43bf215546Sopenharmony_ci#include "main/texobj.h"
44bf215546Sopenharmony_ci#include "main/texparam.h"
45bf215546Sopenharmony_ci#include "main/teximage.h"
46bf215546Sopenharmony_ci#include "main/texstate.h"
47bf215546Sopenharmony_ci#include "program/prog_instruction.h"
48bf215546Sopenharmony_ci#include "util/u_math.h"
49bf215546Sopenharmony_ci#include "api_exec_decl.h"
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci#include "state_tracker/st_cb_texture.h"
52bf215546Sopenharmony_ci#include "state_tracker/st_sampler_view.h"
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_ci/**
55bf215546Sopenharmony_ci * Use macro to resolve undefined clamping behaviour when using lroundf
56bf215546Sopenharmony_ci */
57bf215546Sopenharmony_ci#define LCLAMPF(a, lmin, lmax) ((a) > (lmin) ? ( (a) >= (lmax) ? (lmax) : (lroundf(a)) ) : (lmin))
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci/**
60bf215546Sopenharmony_ci * Check if a coordinate wrap mode is supported for the texture target.
61bf215546Sopenharmony_ci * \return GL_TRUE if legal, GL_FALSE otherwise
62bf215546Sopenharmony_ci */
63bf215546Sopenharmony_cistatic GLboolean
64bf215546Sopenharmony_civalidate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
65bf215546Sopenharmony_ci{
66bf215546Sopenharmony_ci   const struct gl_extensions * const e = & ctx->Extensions;
67bf215546Sopenharmony_ci   const bool is_desktop_gl = _mesa_is_desktop_gl(ctx);
68bf215546Sopenharmony_ci   bool supported;
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ci   switch (wrap) {
71bf215546Sopenharmony_ci   case GL_CLAMP:
72bf215546Sopenharmony_ci      /* GL_CLAMP was removed in the core profile, and it has never existed in
73bf215546Sopenharmony_ci       * OpenGL ES.
74bf215546Sopenharmony_ci       */
75bf215546Sopenharmony_ci      supported = (ctx->API == API_OPENGL_COMPAT)
76bf215546Sopenharmony_ci         && (target != GL_TEXTURE_EXTERNAL_OES);
77bf215546Sopenharmony_ci      break;
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci   case GL_CLAMP_TO_EDGE:
80bf215546Sopenharmony_ci      supported = true;
81bf215546Sopenharmony_ci      break;
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_ci   case GL_CLAMP_TO_BORDER:
84bf215546Sopenharmony_ci      supported = ctx->API != API_OPENGLES
85bf215546Sopenharmony_ci         && (target != GL_TEXTURE_EXTERNAL_OES);
86bf215546Sopenharmony_ci      break;
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ci   case GL_REPEAT:
89bf215546Sopenharmony_ci   case GL_MIRRORED_REPEAT:
90bf215546Sopenharmony_ci      supported = (target != GL_TEXTURE_RECTANGLE_NV)
91bf215546Sopenharmony_ci         && (target != GL_TEXTURE_EXTERNAL_OES);
92bf215546Sopenharmony_ci      break;
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci   case GL_MIRROR_CLAMP_EXT:
95bf215546Sopenharmony_ci      supported = is_desktop_gl
96bf215546Sopenharmony_ci         && (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)
97bf215546Sopenharmony_ci         && (target != GL_TEXTURE_RECTANGLE_NV)
98bf215546Sopenharmony_ci         && (target != GL_TEXTURE_EXTERNAL_OES);
99bf215546Sopenharmony_ci      break;
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci   case GL_MIRROR_CLAMP_TO_EDGE_EXT:
102bf215546Sopenharmony_ci      supported = (target != GL_TEXTURE_RECTANGLE_NV)
103bf215546Sopenharmony_ci         && (target != GL_TEXTURE_EXTERNAL_OES)
104bf215546Sopenharmony_ci         && (_mesa_has_ARB_texture_mirror_clamp_to_edge(ctx) ||
105bf215546Sopenharmony_ci            _mesa_has_ATI_texture_mirror_once(ctx) ||
106bf215546Sopenharmony_ci            _mesa_has_EXT_texture_mirror_clamp(ctx));
107bf215546Sopenharmony_ci      break;
108bf215546Sopenharmony_ci
109bf215546Sopenharmony_ci   case GL_MIRROR_CLAMP_TO_BORDER_EXT:
110bf215546Sopenharmony_ci      supported = is_desktop_gl && e->EXT_texture_mirror_clamp
111bf215546Sopenharmony_ci         && (target != GL_TEXTURE_RECTANGLE_NV)
112bf215546Sopenharmony_ci         && (target != GL_TEXTURE_EXTERNAL_OES);
113bf215546Sopenharmony_ci      break;
114bf215546Sopenharmony_ci
115bf215546Sopenharmony_ci   default:
116bf215546Sopenharmony_ci      supported = false;
117bf215546Sopenharmony_ci      break;
118bf215546Sopenharmony_ci   }
119bf215546Sopenharmony_ci
120bf215546Sopenharmony_ci   if (!supported)
121bf215546Sopenharmony_ci      _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(param=0x%x)", wrap );
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_ci   return supported;
124bf215546Sopenharmony_ci}
125bf215546Sopenharmony_ci
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_cistatic bool
128bf215546Sopenharmony_ciis_texparameteri_target_valid(GLenum target)
129bf215546Sopenharmony_ci{
130bf215546Sopenharmony_ci   switch (target) {
131bf215546Sopenharmony_ci   case GL_TEXTURE_1D:
132bf215546Sopenharmony_ci   case GL_TEXTURE_1D_ARRAY:
133bf215546Sopenharmony_ci   case GL_TEXTURE_2D:
134bf215546Sopenharmony_ci   case GL_TEXTURE_2D_ARRAY:
135bf215546Sopenharmony_ci   case GL_TEXTURE_2D_MULTISAMPLE:
136bf215546Sopenharmony_ci   case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
137bf215546Sopenharmony_ci   case GL_TEXTURE_3D:
138bf215546Sopenharmony_ci   case GL_TEXTURE_CUBE_MAP:
139bf215546Sopenharmony_ci   case GL_TEXTURE_CUBE_MAP_ARRAY:
140bf215546Sopenharmony_ci   case GL_TEXTURE_RECTANGLE:
141bf215546Sopenharmony_ci      return true;
142bf215546Sopenharmony_ci   default:
143bf215546Sopenharmony_ci      return false;
144bf215546Sopenharmony_ci   }
145bf215546Sopenharmony_ci}
146bf215546Sopenharmony_ci
147bf215546Sopenharmony_ci
148bf215546Sopenharmony_ci/**
149bf215546Sopenharmony_ci * Get current texture object for given name.
150bf215546Sopenharmony_ci * Return NULL if any error (and record the error).
151bf215546Sopenharmony_ci * Note that proxy targets are not accepted.
152bf215546Sopenharmony_ci * Only the glGetTexLevelParameter() functions accept proxy targets.
153bf215546Sopenharmony_ci */
154bf215546Sopenharmony_cistatic struct gl_texture_object *
155bf215546Sopenharmony_ciget_texobj_by_name(struct gl_context *ctx, GLuint texture, const char *name)
156bf215546Sopenharmony_ci{
157bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
158bf215546Sopenharmony_ci
159bf215546Sopenharmony_ci   texObj = _mesa_lookup_texture_err(ctx, texture, name);
160bf215546Sopenharmony_ci   if (!texObj)
161bf215546Sopenharmony_ci      return NULL;
162bf215546Sopenharmony_ci
163bf215546Sopenharmony_ci   if (!is_texparameteri_target_valid(texObj->Target)) {
164bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(target)", name);
165bf215546Sopenharmony_ci      return NULL;
166bf215546Sopenharmony_ci   }
167bf215546Sopenharmony_ci
168bf215546Sopenharmony_ci   return texObj;
169bf215546Sopenharmony_ci}
170bf215546Sopenharmony_ci
171bf215546Sopenharmony_ci
172bf215546Sopenharmony_ci/**
173bf215546Sopenharmony_ci * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
174bf215546Sopenharmony_ci * \return -1 if error.
175bf215546Sopenharmony_ci */
176bf215546Sopenharmony_cistatic GLint
177bf215546Sopenharmony_cicomp_to_swizzle(GLenum comp)
178bf215546Sopenharmony_ci{
179bf215546Sopenharmony_ci   switch (comp) {
180bf215546Sopenharmony_ci   case GL_RED:
181bf215546Sopenharmony_ci      return SWIZZLE_X;
182bf215546Sopenharmony_ci   case GL_GREEN:
183bf215546Sopenharmony_ci      return SWIZZLE_Y;
184bf215546Sopenharmony_ci   case GL_BLUE:
185bf215546Sopenharmony_ci      return SWIZZLE_Z;
186bf215546Sopenharmony_ci   case GL_ALPHA:
187bf215546Sopenharmony_ci      return SWIZZLE_W;
188bf215546Sopenharmony_ci   case GL_ZERO:
189bf215546Sopenharmony_ci      return SWIZZLE_ZERO;
190bf215546Sopenharmony_ci   case GL_ONE:
191bf215546Sopenharmony_ci      return SWIZZLE_ONE;
192bf215546Sopenharmony_ci   default:
193bf215546Sopenharmony_ci      return -1;
194bf215546Sopenharmony_ci   }
195bf215546Sopenharmony_ci}
196bf215546Sopenharmony_ci
197bf215546Sopenharmony_ci
198bf215546Sopenharmony_cistatic void
199bf215546Sopenharmony_ciset_swizzle_component(GLushort *swizzle, GLuint comp, GLuint swz)
200bf215546Sopenharmony_ci{
201bf215546Sopenharmony_ci   assert(comp < 4);
202bf215546Sopenharmony_ci   assert(swz <= SWIZZLE_NIL);
203bf215546Sopenharmony_ci   {
204bf215546Sopenharmony_ci      GLuint mask = 0x7 << (3 * comp);
205bf215546Sopenharmony_ci      GLuint s = (*swizzle & ~mask) | (swz << (3 * comp));
206bf215546Sopenharmony_ci      *swizzle = s;
207bf215546Sopenharmony_ci   }
208bf215546Sopenharmony_ci}
209bf215546Sopenharmony_ci
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_ci/**
212bf215546Sopenharmony_ci * This is called just prior to changing any texture object state which
213bf215546Sopenharmony_ci * will not affect texture completeness.
214bf215546Sopenharmony_ci */
215bf215546Sopenharmony_cistatic inline void
216bf215546Sopenharmony_ciflush(struct gl_context *ctx)
217bf215546Sopenharmony_ci{
218bf215546Sopenharmony_ci   FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT, GL_TEXTURE_BIT);
219bf215546Sopenharmony_ci}
220bf215546Sopenharmony_ci
221bf215546Sopenharmony_ci
222bf215546Sopenharmony_ci/**
223bf215546Sopenharmony_ci * This is called just prior to changing any texture object state which
224bf215546Sopenharmony_ci * could affect texture completeness (texture base level, max level).
225bf215546Sopenharmony_ci * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE_OBJECT
226bf215546Sopenharmony_ci * state flag and then mark the texture object as 'incomplete' so that any
227bf215546Sopenharmony_ci * per-texture derived state gets recomputed.
228bf215546Sopenharmony_ci */
229bf215546Sopenharmony_cistatic inline void
230bf215546Sopenharmony_ciincomplete(struct gl_context *ctx, struct gl_texture_object *texObj)
231bf215546Sopenharmony_ci{
232bf215546Sopenharmony_ci   FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT, GL_TEXTURE_BIT);
233bf215546Sopenharmony_ci   _mesa_dirty_texobj(ctx, texObj);
234bf215546Sopenharmony_ci}
235bf215546Sopenharmony_ci
236bf215546Sopenharmony_ci
237bf215546Sopenharmony_ciGLboolean
238bf215546Sopenharmony_ci_mesa_target_allows_setting_sampler_parameters(GLenum target)
239bf215546Sopenharmony_ci{
240bf215546Sopenharmony_ci   switch (target) {
241bf215546Sopenharmony_ci   case GL_TEXTURE_2D_MULTISAMPLE:
242bf215546Sopenharmony_ci   case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
243bf215546Sopenharmony_ci      return GL_FALSE;
244bf215546Sopenharmony_ci
245bf215546Sopenharmony_ci   default:
246bf215546Sopenharmony_ci      return GL_TRUE;
247bf215546Sopenharmony_ci   }
248bf215546Sopenharmony_ci}
249bf215546Sopenharmony_ci
250bf215546Sopenharmony_ci
251bf215546Sopenharmony_ci/**
252bf215546Sopenharmony_ci * Set an integer-valued texture parameter
253bf215546Sopenharmony_ci * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
254bf215546Sopenharmony_ci */
255bf215546Sopenharmony_cistatic GLboolean
256bf215546Sopenharmony_ciset_tex_parameteri(struct gl_context *ctx,
257bf215546Sopenharmony_ci                   struct gl_texture_object *texObj,
258bf215546Sopenharmony_ci                   GLenum pname, const GLint *params, bool dsa)
259bf215546Sopenharmony_ci{
260bf215546Sopenharmony_ci   const char *suffix = dsa ? "ture" : "";
261bf215546Sopenharmony_ci
262bf215546Sopenharmony_ci   if (texObj->HandleAllocated) {
263bf215546Sopenharmony_ci      /* The ARB_bindless_texture spec says:
264bf215546Sopenharmony_ci       *
265bf215546Sopenharmony_ci       * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
266bf215546Sopenharmony_ci       * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
267bf215546Sopenharmony_ci       * functions defined in terms of these, if the texture object to be
268bf215546Sopenharmony_ci       * modified is referenced by one or more texture or image handles."
269bf215546Sopenharmony_ci       */
270bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION,
271bf215546Sopenharmony_ci                  "glTex%sParameter(immutable texture)", suffix);
272bf215546Sopenharmony_ci      return GL_FALSE;
273bf215546Sopenharmony_ci   }
274bf215546Sopenharmony_ci
275bf215546Sopenharmony_ci   switch (pname) {
276bf215546Sopenharmony_ci   case GL_TEXTURE_MIN_FILTER:
277bf215546Sopenharmony_ci      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
278bf215546Sopenharmony_ci         goto invalid_dsa;
279bf215546Sopenharmony_ci
280bf215546Sopenharmony_ci      if (texObj->Sampler.Attrib.MinFilter == params[0])
281bf215546Sopenharmony_ci         return GL_FALSE;
282bf215546Sopenharmony_ci      switch (params[0]) {
283bf215546Sopenharmony_ci      case GL_NEAREST:
284bf215546Sopenharmony_ci      case GL_LINEAR:
285bf215546Sopenharmony_ci         flush(ctx);
286bf215546Sopenharmony_ci         texObj->Sampler.Attrib.MinFilter = params[0];
287bf215546Sopenharmony_ci         texObj->Sampler.Attrib.state.min_img_filter = filter_to_gallium(params[0]);
288bf215546Sopenharmony_ci         texObj->Sampler.Attrib.state.min_mip_filter = mipfilter_to_gallium(params[0]);
289bf215546Sopenharmony_ci         _mesa_lower_gl_clamp(ctx, &texObj->Sampler);
290bf215546Sopenharmony_ci         return GL_TRUE;
291bf215546Sopenharmony_ci      case GL_NEAREST_MIPMAP_NEAREST:
292bf215546Sopenharmony_ci      case GL_LINEAR_MIPMAP_NEAREST:
293bf215546Sopenharmony_ci      case GL_NEAREST_MIPMAP_LINEAR:
294bf215546Sopenharmony_ci      case GL_LINEAR_MIPMAP_LINEAR:
295bf215546Sopenharmony_ci         if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
296bf215546Sopenharmony_ci             texObj->Target != GL_TEXTURE_EXTERNAL_OES) {
297bf215546Sopenharmony_ci            flush(ctx);
298bf215546Sopenharmony_ci            texObj->Sampler.Attrib.MinFilter = params[0];
299bf215546Sopenharmony_ci            texObj->Sampler.Attrib.state.min_img_filter = filter_to_gallium(params[0]);
300bf215546Sopenharmony_ci            texObj->Sampler.Attrib.state.min_mip_filter = mipfilter_to_gallium(params[0]);
301bf215546Sopenharmony_ci            _mesa_lower_gl_clamp(ctx, &texObj->Sampler);
302bf215546Sopenharmony_ci            return GL_TRUE;
303bf215546Sopenharmony_ci         }
304bf215546Sopenharmony_ci         FALLTHROUGH;
305bf215546Sopenharmony_ci      default:
306bf215546Sopenharmony_ci         goto invalid_param;
307bf215546Sopenharmony_ci      }
308bf215546Sopenharmony_ci      return GL_FALSE;
309bf215546Sopenharmony_ci
310bf215546Sopenharmony_ci   case GL_TEXTURE_MAG_FILTER:
311bf215546Sopenharmony_ci      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
312bf215546Sopenharmony_ci         goto invalid_dsa;
313bf215546Sopenharmony_ci
314bf215546Sopenharmony_ci      if (texObj->Sampler.Attrib.MagFilter == params[0])
315bf215546Sopenharmony_ci         return GL_FALSE;
316bf215546Sopenharmony_ci      switch (params[0]) {
317bf215546Sopenharmony_ci      case GL_NEAREST:
318bf215546Sopenharmony_ci      case GL_LINEAR:
319bf215546Sopenharmony_ci         flush(ctx); /* does not effect completeness */
320bf215546Sopenharmony_ci         texObj->Sampler.Attrib.MagFilter = params[0];
321bf215546Sopenharmony_ci         texObj->Sampler.Attrib.state.mag_img_filter = filter_to_gallium(params[0]);
322bf215546Sopenharmony_ci         _mesa_lower_gl_clamp(ctx, &texObj->Sampler);
323bf215546Sopenharmony_ci         return GL_TRUE;
324bf215546Sopenharmony_ci      default:
325bf215546Sopenharmony_ci         goto invalid_param;
326bf215546Sopenharmony_ci      }
327bf215546Sopenharmony_ci      return GL_FALSE;
328bf215546Sopenharmony_ci
329bf215546Sopenharmony_ci   case GL_TEXTURE_WRAP_S:
330bf215546Sopenharmony_ci      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
331bf215546Sopenharmony_ci         goto invalid_dsa;
332bf215546Sopenharmony_ci
333bf215546Sopenharmony_ci      if (texObj->Sampler.Attrib.WrapS == params[0])
334bf215546Sopenharmony_ci         return GL_FALSE;
335bf215546Sopenharmony_ci      if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
336bf215546Sopenharmony_ci         flush(ctx);
337bf215546Sopenharmony_ci         update_sampler_gl_clamp(ctx, &texObj->Sampler, is_wrap_gl_clamp(texObj->Sampler.Attrib.WrapS), is_wrap_gl_clamp(params[0]), WRAP_S);
338bf215546Sopenharmony_ci         texObj->Sampler.Attrib.WrapS = params[0];
339bf215546Sopenharmony_ci         texObj->Sampler.Attrib.state.wrap_s = wrap_to_gallium(params[0]);
340bf215546Sopenharmony_ci         _mesa_lower_gl_clamp(ctx, &texObj->Sampler);
341bf215546Sopenharmony_ci         return GL_TRUE;
342bf215546Sopenharmony_ci      }
343bf215546Sopenharmony_ci      return GL_FALSE;
344bf215546Sopenharmony_ci
345bf215546Sopenharmony_ci   case GL_TEXTURE_WRAP_T:
346bf215546Sopenharmony_ci      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
347bf215546Sopenharmony_ci         goto invalid_dsa;
348bf215546Sopenharmony_ci
349bf215546Sopenharmony_ci      if (texObj->Sampler.Attrib.WrapT == params[0])
350bf215546Sopenharmony_ci         return GL_FALSE;
351bf215546Sopenharmony_ci      if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
352bf215546Sopenharmony_ci         flush(ctx);
353bf215546Sopenharmony_ci         update_sampler_gl_clamp(ctx, &texObj->Sampler, is_wrap_gl_clamp(texObj->Sampler.Attrib.WrapT), is_wrap_gl_clamp(params[0]), WRAP_T);
354bf215546Sopenharmony_ci         texObj->Sampler.Attrib.WrapT = params[0];
355bf215546Sopenharmony_ci         texObj->Sampler.Attrib.state.wrap_t = wrap_to_gallium(params[0]);
356bf215546Sopenharmony_ci         _mesa_lower_gl_clamp(ctx, &texObj->Sampler);
357bf215546Sopenharmony_ci         return GL_TRUE;
358bf215546Sopenharmony_ci      }
359bf215546Sopenharmony_ci      return GL_FALSE;
360bf215546Sopenharmony_ci
361bf215546Sopenharmony_ci   case GL_TEXTURE_WRAP_R:
362bf215546Sopenharmony_ci      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
363bf215546Sopenharmony_ci         goto invalid_dsa;
364bf215546Sopenharmony_ci
365bf215546Sopenharmony_ci      if (texObj->Sampler.Attrib.WrapR == params[0])
366bf215546Sopenharmony_ci         return GL_FALSE;
367bf215546Sopenharmony_ci      if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
368bf215546Sopenharmony_ci         flush(ctx);
369bf215546Sopenharmony_ci         update_sampler_gl_clamp(ctx, &texObj->Sampler, is_wrap_gl_clamp(texObj->Sampler.Attrib.WrapR), is_wrap_gl_clamp(params[0]), WRAP_R);
370bf215546Sopenharmony_ci         texObj->Sampler.Attrib.WrapR = params[0];
371bf215546Sopenharmony_ci         texObj->Sampler.Attrib.state.wrap_r = wrap_to_gallium(params[0]);
372bf215546Sopenharmony_ci         _mesa_lower_gl_clamp(ctx, &texObj->Sampler);
373bf215546Sopenharmony_ci         return GL_TRUE;
374bf215546Sopenharmony_ci      }
375bf215546Sopenharmony_ci      return GL_FALSE;
376bf215546Sopenharmony_ci
377bf215546Sopenharmony_ci   case GL_TEXTURE_BASE_LEVEL:
378bf215546Sopenharmony_ci      if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
379bf215546Sopenharmony_ci         goto invalid_pname;
380bf215546Sopenharmony_ci
381bf215546Sopenharmony_ci      if (texObj->Attrib.BaseLevel == params[0])
382bf215546Sopenharmony_ci         return GL_FALSE;
383bf215546Sopenharmony_ci
384bf215546Sopenharmony_ci      /* Section 8.10 (Texture Parameters) of the OpenGL 4.5 Core Profile spec
385bf215546Sopenharmony_ci       * says:
386bf215546Sopenharmony_ci       *
387bf215546Sopenharmony_ci       *    An INVALID_OPERATION error is generated if the effective target is
388bf215546Sopenharmony_ci       *    TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY, or
389bf215546Sopenharmony_ci       *    TEXTURE_RECTANGLE, and pname TEXTURE_BASE_LEVEL is set to a value
390bf215546Sopenharmony_ci       *    other than zero.
391bf215546Sopenharmony_ci       *
392bf215546Sopenharmony_ci       * Note that section 3.8.8 (Texture Parameters) of the OpenGL 3.3 Core
393bf215546Sopenharmony_ci       * Profile spec said:
394bf215546Sopenharmony_ci       *
395bf215546Sopenharmony_ci       *    The error INVALID_VALUE is generated if TEXTURE_BASE_LEVEL is set
396bf215546Sopenharmony_ci       *    to any value other than zero.
397bf215546Sopenharmony_ci       *
398bf215546Sopenharmony_ci       * We take the 4.5 language as a correction to 3.3, and we implement
399bf215546Sopenharmony_ci       * that on all GL versions.
400bf215546Sopenharmony_ci       */
401bf215546Sopenharmony_ci      if ((texObj->Target == GL_TEXTURE_2D_MULTISAMPLE ||
402bf215546Sopenharmony_ci           texObj->Target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY ||
403bf215546Sopenharmony_ci           texObj->Target == GL_TEXTURE_RECTANGLE) && params[0] != 0)
404bf215546Sopenharmony_ci         goto invalid_operation;
405bf215546Sopenharmony_ci
406bf215546Sopenharmony_ci      if (params[0] < 0) {
407bf215546Sopenharmony_ci         _mesa_error(ctx, GL_INVALID_VALUE,
408bf215546Sopenharmony_ci                     "glTex%sParameter(param=%d)", suffix, params[0]);
409bf215546Sopenharmony_ci         return GL_FALSE;
410bf215546Sopenharmony_ci      }
411bf215546Sopenharmony_ci      incomplete(ctx, texObj);
412bf215546Sopenharmony_ci
413bf215546Sopenharmony_ci      /** See note about ARB_texture_storage below */
414bf215546Sopenharmony_ci      if (texObj->Immutable)
415bf215546Sopenharmony_ci         texObj->Attrib.BaseLevel = MIN2(texObj->Attrib.ImmutableLevels - 1, params[0]);
416bf215546Sopenharmony_ci      else
417bf215546Sopenharmony_ci         texObj->Attrib.BaseLevel = params[0];
418bf215546Sopenharmony_ci
419bf215546Sopenharmony_ci      return GL_TRUE;
420bf215546Sopenharmony_ci
421bf215546Sopenharmony_ci   case GL_TEXTURE_MAX_LEVEL:
422bf215546Sopenharmony_ci      if (texObj->Attrib.MaxLevel == params[0])
423bf215546Sopenharmony_ci         return GL_FALSE;
424bf215546Sopenharmony_ci
425bf215546Sopenharmony_ci      if (params[0] < 0 ||
426bf215546Sopenharmony_ci          (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] > 0)) {
427bf215546Sopenharmony_ci         _mesa_error(ctx, GL_INVALID_VALUE,
428bf215546Sopenharmony_ci                     "glTex%sParameter(param=%d)", suffix,
429bf215546Sopenharmony_ci                     params[0]);
430bf215546Sopenharmony_ci         return GL_FALSE;
431bf215546Sopenharmony_ci      }
432bf215546Sopenharmony_ci      incomplete(ctx, texObj);
433bf215546Sopenharmony_ci
434bf215546Sopenharmony_ci      /** From ARB_texture_storage:
435bf215546Sopenharmony_ci       * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
436bf215546Sopenharmony_ci       * clamped to the range [0, <levels> - 1] and level_max is then clamped to
437bf215546Sopenharmony_ci       * the range [level_base, <levels> - 1], where <levels> is the parameter
438bf215546Sopenharmony_ci       * passed the call to TexStorage* for the texture object.
439bf215546Sopenharmony_ci       */
440bf215546Sopenharmony_ci      if (texObj->Immutable)
441bf215546Sopenharmony_ci          texObj->Attrib.MaxLevel = CLAMP(params[0], texObj->Attrib.BaseLevel,
442bf215546Sopenharmony_ci                                   texObj->Attrib.ImmutableLevels - 1);
443bf215546Sopenharmony_ci      else
444bf215546Sopenharmony_ci         texObj->Attrib.MaxLevel = params[0];
445bf215546Sopenharmony_ci
446bf215546Sopenharmony_ci      return GL_TRUE;
447bf215546Sopenharmony_ci
448bf215546Sopenharmony_ci   case GL_GENERATE_MIPMAP_SGIS:
449bf215546Sopenharmony_ci      if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
450bf215546Sopenharmony_ci         goto invalid_pname;
451bf215546Sopenharmony_ci
452bf215546Sopenharmony_ci      if (params[0] && texObj->Target == GL_TEXTURE_EXTERNAL_OES)
453bf215546Sopenharmony_ci         goto invalid_param;
454bf215546Sopenharmony_ci      if (texObj->Attrib.GenerateMipmap != params[0]) {
455bf215546Sopenharmony_ci         /* no flush() */
456bf215546Sopenharmony_ci	 texObj->Attrib.GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
457bf215546Sopenharmony_ci	 return GL_TRUE;
458bf215546Sopenharmony_ci      }
459bf215546Sopenharmony_ci      return GL_FALSE;
460bf215546Sopenharmony_ci
461bf215546Sopenharmony_ci   case GL_TEXTURE_COMPARE_MODE_ARB:
462bf215546Sopenharmony_ci      if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow)
463bf215546Sopenharmony_ci          || _mesa_is_gles3(ctx)) {
464bf215546Sopenharmony_ci
465bf215546Sopenharmony_ci         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
466bf215546Sopenharmony_ci            goto invalid_dsa;
467bf215546Sopenharmony_ci
468bf215546Sopenharmony_ci         if (texObj->Sampler.Attrib.CompareMode == params[0])
469bf215546Sopenharmony_ci            return GL_FALSE;
470bf215546Sopenharmony_ci         if (params[0] == GL_NONE ||
471bf215546Sopenharmony_ci             params[0] == GL_COMPARE_R_TO_TEXTURE_ARB) {
472bf215546Sopenharmony_ci            flush(ctx);
473bf215546Sopenharmony_ci            texObj->Sampler.Attrib.CompareMode = params[0];
474bf215546Sopenharmony_ci            return GL_TRUE;
475bf215546Sopenharmony_ci         }
476bf215546Sopenharmony_ci         goto invalid_param;
477bf215546Sopenharmony_ci      }
478bf215546Sopenharmony_ci      goto invalid_pname;
479bf215546Sopenharmony_ci
480bf215546Sopenharmony_ci   case GL_TEXTURE_COMPARE_FUNC_ARB:
481bf215546Sopenharmony_ci      if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow)
482bf215546Sopenharmony_ci          || _mesa_is_gles3(ctx)) {
483bf215546Sopenharmony_ci
484bf215546Sopenharmony_ci         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
485bf215546Sopenharmony_ci            goto invalid_dsa;
486bf215546Sopenharmony_ci
487bf215546Sopenharmony_ci         if (texObj->Sampler.Attrib.CompareFunc == params[0])
488bf215546Sopenharmony_ci            return GL_FALSE;
489bf215546Sopenharmony_ci         switch (params[0]) {
490bf215546Sopenharmony_ci         case GL_LEQUAL:
491bf215546Sopenharmony_ci         case GL_GEQUAL:
492bf215546Sopenharmony_ci         case GL_EQUAL:
493bf215546Sopenharmony_ci         case GL_NOTEQUAL:
494bf215546Sopenharmony_ci         case GL_LESS:
495bf215546Sopenharmony_ci         case GL_GREATER:
496bf215546Sopenharmony_ci         case GL_ALWAYS:
497bf215546Sopenharmony_ci         case GL_NEVER:
498bf215546Sopenharmony_ci            flush(ctx);
499bf215546Sopenharmony_ci            texObj->Sampler.Attrib.CompareFunc = params[0];
500bf215546Sopenharmony_ci            texObj->Sampler.Attrib.state.compare_func = func_to_gallium(params[0]);
501bf215546Sopenharmony_ci            return GL_TRUE;
502bf215546Sopenharmony_ci         default:
503bf215546Sopenharmony_ci            goto invalid_param;
504bf215546Sopenharmony_ci         }
505bf215546Sopenharmony_ci      }
506bf215546Sopenharmony_ci      goto invalid_pname;
507bf215546Sopenharmony_ci
508bf215546Sopenharmony_ci   case GL_DEPTH_TEXTURE_MODE_ARB:
509bf215546Sopenharmony_ci      /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
510bf215546Sopenharmony_ci       * existed in OpenGL ES.
511bf215546Sopenharmony_ci       */
512bf215546Sopenharmony_ci      if (ctx->API == API_OPENGL_COMPAT) {
513bf215546Sopenharmony_ci         if (texObj->Attrib.DepthMode == params[0])
514bf215546Sopenharmony_ci            return GL_FALSE;
515bf215546Sopenharmony_ci         if (params[0] == GL_LUMINANCE ||
516bf215546Sopenharmony_ci             params[0] == GL_INTENSITY ||
517bf215546Sopenharmony_ci             params[0] == GL_ALPHA ||
518bf215546Sopenharmony_ci             (ctx->Extensions.ARB_texture_rg && params[0] == GL_RED)) {
519bf215546Sopenharmony_ci            flush(ctx);
520bf215546Sopenharmony_ci            texObj->Attrib.DepthMode = params[0];
521bf215546Sopenharmony_ci            return GL_TRUE;
522bf215546Sopenharmony_ci         }
523bf215546Sopenharmony_ci         goto invalid_param;
524bf215546Sopenharmony_ci      }
525bf215546Sopenharmony_ci      goto invalid_pname;
526bf215546Sopenharmony_ci
527bf215546Sopenharmony_ci   case GL_DEPTH_STENCIL_TEXTURE_MODE:
528bf215546Sopenharmony_ci      if (_mesa_has_ARB_stencil_texturing(ctx) || _mesa_is_gles31(ctx)) {
529bf215546Sopenharmony_ci         bool stencil = params[0] == GL_STENCIL_INDEX;
530bf215546Sopenharmony_ci         if (!stencil && params[0] != GL_DEPTH_COMPONENT)
531bf215546Sopenharmony_ci            goto invalid_param;
532bf215546Sopenharmony_ci
533bf215546Sopenharmony_ci         if (texObj->StencilSampling == stencil)
534bf215546Sopenharmony_ci            return GL_FALSE;
535bf215546Sopenharmony_ci
536bf215546Sopenharmony_ci         /* This should not be restored by glPopAttrib. */
537bf215546Sopenharmony_ci         FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT, 0);
538bf215546Sopenharmony_ci         texObj->StencilSampling = stencil;
539bf215546Sopenharmony_ci         return GL_TRUE;
540bf215546Sopenharmony_ci      }
541bf215546Sopenharmony_ci      goto invalid_pname;
542bf215546Sopenharmony_ci
543bf215546Sopenharmony_ci   case GL_TEXTURE_CROP_RECT_OES:
544bf215546Sopenharmony_ci      if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
545bf215546Sopenharmony_ci         goto invalid_pname;
546bf215546Sopenharmony_ci
547bf215546Sopenharmony_ci      texObj->CropRect[0] = params[0];
548bf215546Sopenharmony_ci      texObj->CropRect[1] = params[1];
549bf215546Sopenharmony_ci      texObj->CropRect[2] = params[2];
550bf215546Sopenharmony_ci      texObj->CropRect[3] = params[3];
551bf215546Sopenharmony_ci      return GL_TRUE;
552bf215546Sopenharmony_ci
553bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_R_EXT:
554bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_G_EXT:
555bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_B_EXT:
556bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_A_EXT:
557bf215546Sopenharmony_ci      if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_swizzle)
558bf215546Sopenharmony_ci          || _mesa_is_gles3(ctx)) {
559bf215546Sopenharmony_ci         const GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
560bf215546Sopenharmony_ci         const GLint swz = comp_to_swizzle(params[0]);
561bf215546Sopenharmony_ci         if (swz < 0) {
562bf215546Sopenharmony_ci            _mesa_error(ctx, GL_INVALID_ENUM,
563bf215546Sopenharmony_ci                        "glTex%sParameter(swizzle 0x%x)", suffix, params[0]);
564bf215546Sopenharmony_ci            return GL_FALSE;
565bf215546Sopenharmony_ci         }
566bf215546Sopenharmony_ci         assert(comp < 4);
567bf215546Sopenharmony_ci
568bf215546Sopenharmony_ci         flush(ctx);
569bf215546Sopenharmony_ci         texObj->Attrib.Swizzle[comp] = params[0];
570bf215546Sopenharmony_ci         set_swizzle_component(&texObj->Attrib._Swizzle, comp, swz);
571bf215546Sopenharmony_ci         return GL_TRUE;
572bf215546Sopenharmony_ci      }
573bf215546Sopenharmony_ci      goto invalid_pname;
574bf215546Sopenharmony_ci
575bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_RGBA_EXT:
576bf215546Sopenharmony_ci      if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_swizzle)
577bf215546Sopenharmony_ci          || _mesa_is_gles3(ctx)) {
578bf215546Sopenharmony_ci         GLuint comp;
579bf215546Sopenharmony_ci         flush(ctx);
580bf215546Sopenharmony_ci         for (comp = 0; comp < 4; comp++) {
581bf215546Sopenharmony_ci            const GLint swz = comp_to_swizzle(params[comp]);
582bf215546Sopenharmony_ci            if (swz >= 0) {
583bf215546Sopenharmony_ci               texObj->Attrib.Swizzle[comp] = params[comp];
584bf215546Sopenharmony_ci               set_swizzle_component(&texObj->Attrib._Swizzle, comp, swz);
585bf215546Sopenharmony_ci            }
586bf215546Sopenharmony_ci            else {
587bf215546Sopenharmony_ci               _mesa_error(ctx, GL_INVALID_ENUM,
588bf215546Sopenharmony_ci                           "glTex%sParameter(swizzle 0x%x)",
589bf215546Sopenharmony_ci                           suffix, params[comp]);
590bf215546Sopenharmony_ci               return GL_FALSE;
591bf215546Sopenharmony_ci            }
592bf215546Sopenharmony_ci         }
593bf215546Sopenharmony_ci         return GL_TRUE;
594bf215546Sopenharmony_ci      }
595bf215546Sopenharmony_ci      goto invalid_pname;
596bf215546Sopenharmony_ci
597bf215546Sopenharmony_ci   case GL_TEXTURE_SRGB_DECODE_EXT:
598bf215546Sopenharmony_ci      if (ctx->Extensions.EXT_texture_sRGB_decode) {
599bf215546Sopenharmony_ci         GLenum decode = params[0];
600bf215546Sopenharmony_ci
601bf215546Sopenharmony_ci         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
602bf215546Sopenharmony_ci            goto invalid_dsa;
603bf215546Sopenharmony_ci
604bf215546Sopenharmony_ci	 if (decode == GL_DECODE_EXT || decode == GL_SKIP_DECODE_EXT) {
605bf215546Sopenharmony_ci	    if (texObj->Sampler.Attrib.sRGBDecode != decode) {
606bf215546Sopenharmony_ci	       flush(ctx);
607bf215546Sopenharmony_ci	       texObj->Sampler.Attrib.sRGBDecode = decode;
608bf215546Sopenharmony_ci	    }
609bf215546Sopenharmony_ci	    return GL_TRUE;
610bf215546Sopenharmony_ci	 }
611bf215546Sopenharmony_ci      }
612bf215546Sopenharmony_ci      goto invalid_pname;
613bf215546Sopenharmony_ci
614bf215546Sopenharmony_ci   case GL_TEXTURE_REDUCTION_MODE_EXT:
615bf215546Sopenharmony_ci      if (ctx->Extensions.EXT_texture_filter_minmax ||
616bf215546Sopenharmony_ci          _mesa_has_ARB_texture_filter_minmax(ctx)) {
617bf215546Sopenharmony_ci         GLenum mode = params[0];
618bf215546Sopenharmony_ci
619bf215546Sopenharmony_ci         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
620bf215546Sopenharmony_ci            goto invalid_dsa;
621bf215546Sopenharmony_ci
622bf215546Sopenharmony_ci         if (mode == GL_WEIGHTED_AVERAGE_EXT || mode == GL_MIN || mode == GL_MAX) {
623bf215546Sopenharmony_ci            if (texObj->Sampler.Attrib.ReductionMode != mode) {
624bf215546Sopenharmony_ci               flush(ctx);
625bf215546Sopenharmony_ci               texObj->Sampler.Attrib.ReductionMode = mode;
626bf215546Sopenharmony_ci               texObj->Sampler.Attrib.state.reduction_mode = reduction_to_gallium(mode);
627bf215546Sopenharmony_ci            }
628bf215546Sopenharmony_ci            return GL_TRUE;
629bf215546Sopenharmony_ci         }
630bf215546Sopenharmony_ci      }
631bf215546Sopenharmony_ci      goto invalid_pname;
632bf215546Sopenharmony_ci
633bf215546Sopenharmony_ci   case GL_TEXTURE_CUBE_MAP_SEAMLESS:
634bf215546Sopenharmony_ci      if (_mesa_is_desktop_gl(ctx)
635bf215546Sopenharmony_ci          && ctx->Extensions.AMD_seamless_cubemap_per_texture) {
636bf215546Sopenharmony_ci         GLenum param = params[0];
637bf215546Sopenharmony_ci
638bf215546Sopenharmony_ci         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
639bf215546Sopenharmony_ci            goto invalid_dsa;
640bf215546Sopenharmony_ci
641bf215546Sopenharmony_ci         if (param != GL_TRUE && param != GL_FALSE) {
642bf215546Sopenharmony_ci            goto invalid_param;
643bf215546Sopenharmony_ci         }
644bf215546Sopenharmony_ci         if (param != texObj->Sampler.Attrib.CubeMapSeamless) {
645bf215546Sopenharmony_ci            flush(ctx);
646bf215546Sopenharmony_ci            texObj->Sampler.Attrib.CubeMapSeamless = param;
647bf215546Sopenharmony_ci            texObj->Sampler.Attrib.state.seamless_cube_map = param;
648bf215546Sopenharmony_ci         }
649bf215546Sopenharmony_ci         return GL_TRUE;
650bf215546Sopenharmony_ci      }
651bf215546Sopenharmony_ci      goto invalid_pname;
652bf215546Sopenharmony_ci
653bf215546Sopenharmony_ci   case GL_TEXTURE_TILING_EXT:
654bf215546Sopenharmony_ci      if (ctx->Extensions.EXT_memory_object && !texObj->Immutable) {
655bf215546Sopenharmony_ci            texObj->TextureTiling = params[0];
656bf215546Sopenharmony_ci
657bf215546Sopenharmony_ci         return GL_TRUE;
658bf215546Sopenharmony_ci      }
659bf215546Sopenharmony_ci      goto invalid_pname;
660bf215546Sopenharmony_ci
661bf215546Sopenharmony_ci   case GL_TEXTURE_SPARSE_ARB:
662bf215546Sopenharmony_ci   case GL_VIRTUAL_PAGE_SIZE_INDEX_ARB:
663bf215546Sopenharmony_ci      if (!_mesa_has_ARB_sparse_texture(ctx))
664bf215546Sopenharmony_ci         goto invalid_pname;
665bf215546Sopenharmony_ci
666bf215546Sopenharmony_ci      if (texObj->Immutable)
667bf215546Sopenharmony_ci         goto invalid_operation;
668bf215546Sopenharmony_ci
669bf215546Sopenharmony_ci      if (pname == GL_TEXTURE_SPARSE_ARB) {
670bf215546Sopenharmony_ci         /* ARB_sparse_texture spec:
671bf215546Sopenharmony_ci          *
672bf215546Sopenharmony_ci          *   INVALID_VALUE is generated if <pname> is TEXTURE_SPARSE_ARB, <param>
673bf215546Sopenharmony_ci          *   is TRUE and <target> is not one of TEXTURE_2D, TEXTURE_2D_ARRAY,
674bf215546Sopenharmony_ci          *   TEXTURE_CUBE_MAP, TEXTURE_CUBE_MAP_ARRAY, TEXTURE_3D, or
675bf215546Sopenharmony_ci          *   TEXTURE_RECTANGLE.
676bf215546Sopenharmony_ci          *
677bf215546Sopenharmony_ci          * ARB_sparse_texture2 also allow TEXTURE_2D_MULTISAMPLE and
678bf215546Sopenharmony_ci          * TEXTURE_2D_MULTISAMPLE_ARRAY.
679bf215546Sopenharmony_ci          */
680bf215546Sopenharmony_ci         if (params[0] &&
681bf215546Sopenharmony_ci             texObj->Target != GL_TEXTURE_2D &&
682bf215546Sopenharmony_ci             texObj->Target != GL_TEXTURE_2D_ARRAY &&
683bf215546Sopenharmony_ci             texObj->Target != GL_TEXTURE_CUBE_MAP &&
684bf215546Sopenharmony_ci             texObj->Target != GL_TEXTURE_CUBE_MAP_ARRAY &&
685bf215546Sopenharmony_ci             texObj->Target != GL_TEXTURE_3D &&
686bf215546Sopenharmony_ci             texObj->Target != GL_TEXTURE_RECTANGLE &&
687bf215546Sopenharmony_ci             (!_mesa_has_ARB_sparse_texture2(ctx) ||
688bf215546Sopenharmony_ci              (texObj->Target != GL_TEXTURE_2D_MULTISAMPLE &&
689bf215546Sopenharmony_ci               texObj->Target != GL_TEXTURE_2D_MULTISAMPLE_ARRAY))) {
690bf215546Sopenharmony_ci            _mesa_error(ctx, GL_INVALID_VALUE,
691bf215546Sopenharmony_ci                        "glTex%sParameter(target=%d)", suffix, texObj->Target);
692bf215546Sopenharmony_ci            return GL_FALSE;
693bf215546Sopenharmony_ci         }
694bf215546Sopenharmony_ci
695bf215546Sopenharmony_ci         texObj->IsSparse = !!params[0];
696bf215546Sopenharmony_ci      } else
697bf215546Sopenharmony_ci         texObj->VirtualPageSizeIndex = params[0];
698bf215546Sopenharmony_ci
699bf215546Sopenharmony_ci      return GL_TRUE;
700bf215546Sopenharmony_ci
701bf215546Sopenharmony_ci   default:
702bf215546Sopenharmony_ci      goto invalid_pname;
703bf215546Sopenharmony_ci   }
704bf215546Sopenharmony_ci
705bf215546Sopenharmony_ciinvalid_pname:
706bf215546Sopenharmony_ci   _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
707bf215546Sopenharmony_ci               suffix, _mesa_enum_to_string(pname));
708bf215546Sopenharmony_ci   return GL_FALSE;
709bf215546Sopenharmony_ci
710bf215546Sopenharmony_ciinvalid_param:
711bf215546Sopenharmony_ci   _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(param=%s)",
712bf215546Sopenharmony_ci               suffix, _mesa_enum_to_string(params[0]));
713bf215546Sopenharmony_ci   return GL_FALSE;
714bf215546Sopenharmony_ci
715bf215546Sopenharmony_ciinvalid_dsa:
716bf215546Sopenharmony_ci   if (!dsa)
717bf215546Sopenharmony_ci      goto invalid_enum;
718bf215546Sopenharmony_ci
719bf215546Sopenharmony_ciinvalid_operation:
720bf215546Sopenharmony_ci   _mesa_error(ctx, GL_INVALID_OPERATION, "glTex%sParameter(pname=%s)",
721bf215546Sopenharmony_ci               suffix, _mesa_enum_to_string(pname));
722bf215546Sopenharmony_ci   return GL_FALSE;
723bf215546Sopenharmony_ci
724bf215546Sopenharmony_ciinvalid_enum:
725bf215546Sopenharmony_ci   _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
726bf215546Sopenharmony_ci               suffix, _mesa_enum_to_string(pname));
727bf215546Sopenharmony_ci   return GL_FALSE;
728bf215546Sopenharmony_ci}
729bf215546Sopenharmony_ci
730bf215546Sopenharmony_ci
731bf215546Sopenharmony_ci/**
732bf215546Sopenharmony_ci * Set a float-valued texture parameter
733bf215546Sopenharmony_ci * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
734bf215546Sopenharmony_ci */
735bf215546Sopenharmony_cistatic GLboolean
736bf215546Sopenharmony_ciset_tex_parameterf(struct gl_context *ctx,
737bf215546Sopenharmony_ci                   struct gl_texture_object *texObj,
738bf215546Sopenharmony_ci                   GLenum pname, const GLfloat *params, bool dsa)
739bf215546Sopenharmony_ci{
740bf215546Sopenharmony_ci   const char *suffix = dsa ? "ture" : "";
741bf215546Sopenharmony_ci
742bf215546Sopenharmony_ci   if (texObj->HandleAllocated) {
743bf215546Sopenharmony_ci      /* The ARB_bindless_texture spec says:
744bf215546Sopenharmony_ci       *
745bf215546Sopenharmony_ci       * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
746bf215546Sopenharmony_ci       * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
747bf215546Sopenharmony_ci       * functions defined in terms of these, if the texture object to be
748bf215546Sopenharmony_ci       * modified is referenced by one or more texture or image handles."
749bf215546Sopenharmony_ci       */
750bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION,
751bf215546Sopenharmony_ci                  "glTex%sParameter(immutable texture)", suffix);
752bf215546Sopenharmony_ci      return GL_FALSE;
753bf215546Sopenharmony_ci   }
754bf215546Sopenharmony_ci
755bf215546Sopenharmony_ci   switch (pname) {
756bf215546Sopenharmony_ci   case GL_TEXTURE_MIN_LOD:
757bf215546Sopenharmony_ci      if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
758bf215546Sopenharmony_ci         goto invalid_pname;
759bf215546Sopenharmony_ci
760bf215546Sopenharmony_ci      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
761bf215546Sopenharmony_ci         goto invalid_dsa;
762bf215546Sopenharmony_ci
763bf215546Sopenharmony_ci      if (texObj->Sampler.Attrib.MinLod == params[0])
764bf215546Sopenharmony_ci         return GL_FALSE;
765bf215546Sopenharmony_ci      flush(ctx);
766bf215546Sopenharmony_ci      texObj->Sampler.Attrib.MinLod = params[0];
767bf215546Sopenharmony_ci      texObj->Sampler.Attrib.state.min_lod = MAX2(params[0], 0.0f); /* only positive vals */
768bf215546Sopenharmony_ci      return GL_TRUE;
769bf215546Sopenharmony_ci
770bf215546Sopenharmony_ci   case GL_TEXTURE_MAX_LOD:
771bf215546Sopenharmony_ci      if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
772bf215546Sopenharmony_ci         goto invalid_pname;
773bf215546Sopenharmony_ci
774bf215546Sopenharmony_ci      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
775bf215546Sopenharmony_ci         goto invalid_dsa;
776bf215546Sopenharmony_ci
777bf215546Sopenharmony_ci      if (texObj->Sampler.Attrib.MaxLod == params[0])
778bf215546Sopenharmony_ci         return GL_FALSE;
779bf215546Sopenharmony_ci      flush(ctx);
780bf215546Sopenharmony_ci      texObj->Sampler.Attrib.MaxLod = params[0];
781bf215546Sopenharmony_ci      texObj->Sampler.Attrib.state.max_lod = params[0];
782bf215546Sopenharmony_ci      return GL_TRUE;
783bf215546Sopenharmony_ci
784bf215546Sopenharmony_ci   case GL_TEXTURE_PRIORITY:
785bf215546Sopenharmony_ci      if (ctx->API != API_OPENGL_COMPAT)
786bf215546Sopenharmony_ci         goto invalid_pname;
787bf215546Sopenharmony_ci
788bf215546Sopenharmony_ci      flush(ctx);
789bf215546Sopenharmony_ci      texObj->Attrib.Priority = CLAMP(params[0], 0.0F, 1.0F);
790bf215546Sopenharmony_ci      return GL_TRUE;
791bf215546Sopenharmony_ci
792bf215546Sopenharmony_ci   case GL_TEXTURE_MAX_ANISOTROPY_EXT:
793bf215546Sopenharmony_ci      if (ctx->Extensions.EXT_texture_filter_anisotropic) {
794bf215546Sopenharmony_ci         if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
795bf215546Sopenharmony_ci            goto invalid_dsa;
796bf215546Sopenharmony_ci
797bf215546Sopenharmony_ci         if (texObj->Sampler.Attrib.MaxAnisotropy == params[0])
798bf215546Sopenharmony_ci            return GL_FALSE;
799bf215546Sopenharmony_ci         if (params[0] < 1.0F) {
800bf215546Sopenharmony_ci            _mesa_error(ctx, GL_INVALID_VALUE, "glTex%sParameter(param)",
801bf215546Sopenharmony_ci                        suffix);
802bf215546Sopenharmony_ci            return GL_FALSE;
803bf215546Sopenharmony_ci         }
804bf215546Sopenharmony_ci         flush(ctx);
805bf215546Sopenharmony_ci         /* clamp to max, that's what NVIDIA does */
806bf215546Sopenharmony_ci         texObj->Sampler.Attrib.MaxAnisotropy = MIN2(params[0],
807bf215546Sopenharmony_ci                                      ctx->Const.MaxTextureMaxAnisotropy);
808bf215546Sopenharmony_ci         texObj->Sampler.Attrib.state.max_anisotropy =
809bf215546Sopenharmony_ci            texObj->Sampler.Attrib.MaxAnisotropy == 1 ?
810bf215546Sopenharmony_ci                  0 : texObj->Sampler.Attrib.MaxAnisotropy; /* gallium sets 0 for 1 */
811bf215546Sopenharmony_ci         return GL_TRUE;
812bf215546Sopenharmony_ci      }
813bf215546Sopenharmony_ci      else {
814bf215546Sopenharmony_ci         static GLuint count = 0;
815bf215546Sopenharmony_ci         if (count++ < 10)
816bf215546Sopenharmony_ci            goto invalid_pname;
817bf215546Sopenharmony_ci      }
818bf215546Sopenharmony_ci      return GL_FALSE;
819bf215546Sopenharmony_ci
820bf215546Sopenharmony_ci   case GL_TEXTURE_LOD_BIAS:
821bf215546Sopenharmony_ci      /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
822bf215546Sopenharmony_ci      if (_mesa_is_gles(ctx))
823bf215546Sopenharmony_ci         goto invalid_pname;
824bf215546Sopenharmony_ci
825bf215546Sopenharmony_ci      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
826bf215546Sopenharmony_ci         goto invalid_dsa;
827bf215546Sopenharmony_ci
828bf215546Sopenharmony_ci      if (texObj->Sampler.Attrib.LodBias != params[0]) {
829bf215546Sopenharmony_ci	 flush(ctx);
830bf215546Sopenharmony_ci	 texObj->Sampler.Attrib.LodBias = params[0];
831bf215546Sopenharmony_ci         texObj->Sampler.Attrib.state.lod_bias = util_quantize_lod_bias(params[0]);
832bf215546Sopenharmony_ci	 return GL_TRUE;
833bf215546Sopenharmony_ci      }
834bf215546Sopenharmony_ci      break;
835bf215546Sopenharmony_ci
836bf215546Sopenharmony_ci   case GL_TEXTURE_BORDER_COLOR:
837bf215546Sopenharmony_ci      /* Border color exists in desktop OpenGL since 1.0 for GL_CLAMP.  In
838bf215546Sopenharmony_ci       * OpenGL ES 2.0+, it only exists in when GL_OES_texture_border_clamp is
839bf215546Sopenharmony_ci       * enabled.  It is never available in OpenGL ES 1.x.
840bf215546Sopenharmony_ci       */
841bf215546Sopenharmony_ci      if (ctx->API == API_OPENGLES)
842bf215546Sopenharmony_ci         goto invalid_pname;
843bf215546Sopenharmony_ci
844bf215546Sopenharmony_ci      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
845bf215546Sopenharmony_ci         goto invalid_enum;
846bf215546Sopenharmony_ci
847bf215546Sopenharmony_ci      flush(ctx);
848bf215546Sopenharmony_ci      /* ARB_texture_float disables clamping */
849bf215546Sopenharmony_ci      if (ctx->Extensions.ARB_texture_float) {
850bf215546Sopenharmony_ci         memcpy(texObj->Sampler.Attrib.state.border_color.f, params, 4 * sizeof(float));
851bf215546Sopenharmony_ci      } else {
852bf215546Sopenharmony_ci         texObj->Sampler.Attrib.state.border_color.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F);
853bf215546Sopenharmony_ci         texObj->Sampler.Attrib.state.border_color.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F);
854bf215546Sopenharmony_ci         texObj->Sampler.Attrib.state.border_color.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F);
855bf215546Sopenharmony_ci         texObj->Sampler.Attrib.state.border_color.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F);
856bf215546Sopenharmony_ci      }
857bf215546Sopenharmony_ci      _mesa_update_is_border_color_nonzero(&texObj->Sampler);
858bf215546Sopenharmony_ci      return GL_TRUE;
859bf215546Sopenharmony_ci
860bf215546Sopenharmony_ci   case GL_TEXTURE_TILING_EXT:
861bf215546Sopenharmony_ci      if (ctx->Extensions.EXT_memory_object) {
862bf215546Sopenharmony_ci         texObj->TextureTiling = params[0];
863bf215546Sopenharmony_ci         return GL_TRUE;
864bf215546Sopenharmony_ci      }
865bf215546Sopenharmony_ci      goto invalid_pname;
866bf215546Sopenharmony_ci
867bf215546Sopenharmony_ci   default:
868bf215546Sopenharmony_ci      goto invalid_pname;
869bf215546Sopenharmony_ci   }
870bf215546Sopenharmony_ci   return GL_FALSE;
871bf215546Sopenharmony_ci
872bf215546Sopenharmony_ciinvalid_pname:
873bf215546Sopenharmony_ci   _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
874bf215546Sopenharmony_ci               suffix, _mesa_enum_to_string(pname));
875bf215546Sopenharmony_ci   return GL_FALSE;
876bf215546Sopenharmony_ci
877bf215546Sopenharmony_ciinvalid_dsa:
878bf215546Sopenharmony_ci   if (!dsa)
879bf215546Sopenharmony_ci      goto invalid_enum;
880bf215546Sopenharmony_ci   _mesa_error(ctx, GL_INVALID_OPERATION, "glTex%sParameter(pname=%s)",
881bf215546Sopenharmony_ci               suffix, _mesa_enum_to_string(pname));
882bf215546Sopenharmony_ci   return GL_FALSE;
883bf215546Sopenharmony_ciinvalid_enum:
884bf215546Sopenharmony_ci   _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
885bf215546Sopenharmony_ci               suffix, _mesa_enum_to_string(pname));
886bf215546Sopenharmony_ci   return GL_FALSE;
887bf215546Sopenharmony_ci}
888bf215546Sopenharmony_ci
889bf215546Sopenharmony_cistatic bool
890bf215546Sopenharmony_citexparam_invalidates_sampler_views(GLenum pname)
891bf215546Sopenharmony_ci{
892bf215546Sopenharmony_ci   switch (pname) {
893bf215546Sopenharmony_ci      /*
894bf215546Sopenharmony_ci       * Changing any of these texture parameters means we must create
895bf215546Sopenharmony_ci       * new sampler views.
896bf215546Sopenharmony_ci       */
897bf215546Sopenharmony_ci   case GL_ALL_ATTRIB_BITS: /* meaning is all pnames, internal */
898bf215546Sopenharmony_ci   case GL_TEXTURE_BASE_LEVEL:
899bf215546Sopenharmony_ci   case GL_TEXTURE_MAX_LEVEL:
900bf215546Sopenharmony_ci   case GL_DEPTH_TEXTURE_MODE:
901bf215546Sopenharmony_ci   case GL_DEPTH_STENCIL_TEXTURE_MODE:
902bf215546Sopenharmony_ci   case GL_TEXTURE_SRGB_DECODE_EXT:
903bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_R:
904bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_G:
905bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_B:
906bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_A:
907bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_RGBA:
908bf215546Sopenharmony_ci   case GL_TEXTURE_BUFFER_SIZE:
909bf215546Sopenharmony_ci   case GL_TEXTURE_BUFFER_OFFSET:
910bf215546Sopenharmony_ci      return true;
911bf215546Sopenharmony_ci   default:
912bf215546Sopenharmony_ci      return false;
913bf215546Sopenharmony_ci   }
914bf215546Sopenharmony_ci}
915bf215546Sopenharmony_ci
916bf215546Sopenharmony_cistatic void
917bf215546Sopenharmony_ci_mesa_texture_parameter_invalidate(struct gl_context *ctx,
918bf215546Sopenharmony_ci                                   struct gl_texture_object *texObj,
919bf215546Sopenharmony_ci                                   GLenum pname)
920bf215546Sopenharmony_ci{
921bf215546Sopenharmony_ci   if (texparam_invalidates_sampler_views(pname))
922bf215546Sopenharmony_ci      st_texture_release_all_sampler_views(st_context(ctx), texObj);
923bf215546Sopenharmony_ci}
924bf215546Sopenharmony_ci
925bf215546Sopenharmony_civoid
926bf215546Sopenharmony_ci_mesa_texture_parameterf(struct gl_context *ctx,
927bf215546Sopenharmony_ci                         struct gl_texture_object *texObj,
928bf215546Sopenharmony_ci                         GLenum pname, GLfloat param, bool dsa)
929bf215546Sopenharmony_ci{
930bf215546Sopenharmony_ci   GLboolean need_update;
931bf215546Sopenharmony_ci
932bf215546Sopenharmony_ci   switch (pname) {
933bf215546Sopenharmony_ci   case GL_TEXTURE_MIN_FILTER:
934bf215546Sopenharmony_ci   case GL_TEXTURE_MAG_FILTER:
935bf215546Sopenharmony_ci   case GL_TEXTURE_WRAP_S:
936bf215546Sopenharmony_ci   case GL_TEXTURE_WRAP_T:
937bf215546Sopenharmony_ci   case GL_TEXTURE_WRAP_R:
938bf215546Sopenharmony_ci   case GL_TEXTURE_BASE_LEVEL:
939bf215546Sopenharmony_ci   case GL_TEXTURE_MAX_LEVEL:
940bf215546Sopenharmony_ci   case GL_GENERATE_MIPMAP_SGIS:
941bf215546Sopenharmony_ci   case GL_TEXTURE_COMPARE_MODE_ARB:
942bf215546Sopenharmony_ci   case GL_TEXTURE_COMPARE_FUNC_ARB:
943bf215546Sopenharmony_ci   case GL_DEPTH_TEXTURE_MODE_ARB:
944bf215546Sopenharmony_ci   case GL_DEPTH_STENCIL_TEXTURE_MODE:
945bf215546Sopenharmony_ci   case GL_TEXTURE_SRGB_DECODE_EXT:
946bf215546Sopenharmony_ci   case GL_TEXTURE_REDUCTION_MODE_EXT:
947bf215546Sopenharmony_ci   case GL_TEXTURE_CUBE_MAP_SEAMLESS:
948bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_R_EXT:
949bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_G_EXT:
950bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_B_EXT:
951bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_A_EXT:
952bf215546Sopenharmony_ci   case GL_TEXTURE_SPARSE_ARB:
953bf215546Sopenharmony_ci   case GL_VIRTUAL_PAGE_SIZE_INDEX_ARB:
954bf215546Sopenharmony_ci      {
955bf215546Sopenharmony_ci         GLint p[4];
956bf215546Sopenharmony_ci         p[0] = (param > 0) ?
957bf215546Sopenharmony_ci                ((param > INT_MAX) ? INT_MAX : (GLint) (param + 0.5)) :
958bf215546Sopenharmony_ci                ((param < INT_MIN) ? INT_MIN : (GLint) (param - 0.5));
959bf215546Sopenharmony_ci
960bf215546Sopenharmony_ci         p[1] = p[2] = p[3] = 0;
961bf215546Sopenharmony_ci         need_update = set_tex_parameteri(ctx, texObj, pname, p, dsa);
962bf215546Sopenharmony_ci      }
963bf215546Sopenharmony_ci      break;
964bf215546Sopenharmony_ci   case GL_TEXTURE_BORDER_COLOR:
965bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_RGBA:
966bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameterf(non-scalar pname)",
967bf215546Sopenharmony_ci                  dsa ? "ture" : "");
968bf215546Sopenharmony_ci      return;
969bf215546Sopenharmony_ci   default:
970bf215546Sopenharmony_ci      {
971bf215546Sopenharmony_ci         /* this will generate an error if pname is illegal */
972bf215546Sopenharmony_ci         GLfloat p[4];
973bf215546Sopenharmony_ci         p[0] = param;
974bf215546Sopenharmony_ci         p[1] = p[2] = p[3] = 0.0F;
975bf215546Sopenharmony_ci         need_update = set_tex_parameterf(ctx, texObj, pname, p, dsa);
976bf215546Sopenharmony_ci      }
977bf215546Sopenharmony_ci   }
978bf215546Sopenharmony_ci
979bf215546Sopenharmony_ci   if (need_update) {
980bf215546Sopenharmony_ci      _mesa_texture_parameter_invalidate(ctx, texObj, pname);
981bf215546Sopenharmony_ci   }
982bf215546Sopenharmony_ci}
983bf215546Sopenharmony_ci
984bf215546Sopenharmony_ci
985bf215546Sopenharmony_civoid
986bf215546Sopenharmony_ci_mesa_texture_parameterfv(struct gl_context *ctx,
987bf215546Sopenharmony_ci                          struct gl_texture_object *texObj,
988bf215546Sopenharmony_ci                          GLenum pname, const GLfloat *params, bool dsa)
989bf215546Sopenharmony_ci{
990bf215546Sopenharmony_ci   GLboolean need_update;
991bf215546Sopenharmony_ci   switch (pname) {
992bf215546Sopenharmony_ci   case GL_TEXTURE_MIN_FILTER:
993bf215546Sopenharmony_ci   case GL_TEXTURE_MAG_FILTER:
994bf215546Sopenharmony_ci   case GL_TEXTURE_WRAP_S:
995bf215546Sopenharmony_ci   case GL_TEXTURE_WRAP_T:
996bf215546Sopenharmony_ci   case GL_TEXTURE_WRAP_R:
997bf215546Sopenharmony_ci   case GL_TEXTURE_BASE_LEVEL:
998bf215546Sopenharmony_ci   case GL_TEXTURE_MAX_LEVEL:
999bf215546Sopenharmony_ci   case GL_GENERATE_MIPMAP_SGIS:
1000bf215546Sopenharmony_ci   case GL_TEXTURE_COMPARE_MODE_ARB:
1001bf215546Sopenharmony_ci   case GL_TEXTURE_COMPARE_FUNC_ARB:
1002bf215546Sopenharmony_ci   case GL_DEPTH_TEXTURE_MODE_ARB:
1003bf215546Sopenharmony_ci   case GL_DEPTH_STENCIL_TEXTURE_MODE:
1004bf215546Sopenharmony_ci   case GL_TEXTURE_SRGB_DECODE_EXT:
1005bf215546Sopenharmony_ci   case GL_TEXTURE_REDUCTION_MODE_EXT:
1006bf215546Sopenharmony_ci   case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1007bf215546Sopenharmony_ci   case GL_TEXTURE_SPARSE_ARB:
1008bf215546Sopenharmony_ci   case GL_VIRTUAL_PAGE_SIZE_INDEX_ARB:
1009bf215546Sopenharmony_ci      {
1010bf215546Sopenharmony_ci         /* convert float param to int */
1011bf215546Sopenharmony_ci         GLint p[4];
1012bf215546Sopenharmony_ci         p[0] = (GLint) params[0];
1013bf215546Sopenharmony_ci         p[1] = p[2] = p[3] = 0;
1014bf215546Sopenharmony_ci         need_update = set_tex_parameteri(ctx, texObj, pname, p, dsa);
1015bf215546Sopenharmony_ci      }
1016bf215546Sopenharmony_ci      break;
1017bf215546Sopenharmony_ci   case GL_TEXTURE_CROP_RECT_OES:
1018bf215546Sopenharmony_ci      {
1019bf215546Sopenharmony_ci         /* convert float params to int */
1020bf215546Sopenharmony_ci         GLint iparams[4];
1021bf215546Sopenharmony_ci         iparams[0] = (GLint) params[0];
1022bf215546Sopenharmony_ci         iparams[1] = (GLint) params[1];
1023bf215546Sopenharmony_ci         iparams[2] = (GLint) params[2];
1024bf215546Sopenharmony_ci         iparams[3] = (GLint) params[3];
1025bf215546Sopenharmony_ci         need_update = set_tex_parameteri(ctx, texObj, pname, iparams, dsa);
1026bf215546Sopenharmony_ci      }
1027bf215546Sopenharmony_ci      break;
1028bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_R_EXT:
1029bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_G_EXT:
1030bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_B_EXT:
1031bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_A_EXT:
1032bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_RGBA_EXT:
1033bf215546Sopenharmony_ci      {
1034bf215546Sopenharmony_ci         GLint p[4] = {0, 0, 0, 0};
1035bf215546Sopenharmony_ci         p[0] = (GLint) params[0];
1036bf215546Sopenharmony_ci         if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT) {
1037bf215546Sopenharmony_ci            p[1] = (GLint) params[1];
1038bf215546Sopenharmony_ci            p[2] = (GLint) params[2];
1039bf215546Sopenharmony_ci            p[3] = (GLint) params[3];
1040bf215546Sopenharmony_ci         }
1041bf215546Sopenharmony_ci         need_update = set_tex_parameteri(ctx, texObj, pname, p, dsa);
1042bf215546Sopenharmony_ci      }
1043bf215546Sopenharmony_ci      break;
1044bf215546Sopenharmony_ci   default:
1045bf215546Sopenharmony_ci      /* this will generate an error if pname is illegal */
1046bf215546Sopenharmony_ci      need_update = set_tex_parameterf(ctx, texObj, pname, params, dsa);
1047bf215546Sopenharmony_ci   }
1048bf215546Sopenharmony_ci
1049bf215546Sopenharmony_ci   if (need_update) {
1050bf215546Sopenharmony_ci      _mesa_texture_parameter_invalidate(ctx, texObj, pname);
1051bf215546Sopenharmony_ci   }
1052bf215546Sopenharmony_ci}
1053bf215546Sopenharmony_ci
1054bf215546Sopenharmony_ci
1055bf215546Sopenharmony_civoid
1056bf215546Sopenharmony_ci_mesa_texture_parameteri(struct gl_context *ctx,
1057bf215546Sopenharmony_ci                         struct gl_texture_object *texObj,
1058bf215546Sopenharmony_ci                         GLenum pname, GLint param, bool dsa)
1059bf215546Sopenharmony_ci{
1060bf215546Sopenharmony_ci   GLboolean need_update;
1061bf215546Sopenharmony_ci   switch (pname) {
1062bf215546Sopenharmony_ci   case GL_TEXTURE_MIN_LOD:
1063bf215546Sopenharmony_ci   case GL_TEXTURE_MAX_LOD:
1064bf215546Sopenharmony_ci   case GL_TEXTURE_PRIORITY:
1065bf215546Sopenharmony_ci   case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1066bf215546Sopenharmony_ci   case GL_TEXTURE_LOD_BIAS:
1067bf215546Sopenharmony_ci      {
1068bf215546Sopenharmony_ci         GLfloat fparam[4];
1069bf215546Sopenharmony_ci         fparam[0] = (GLfloat) param;
1070bf215546Sopenharmony_ci         fparam[1] = fparam[2] = fparam[3] = 0.0F;
1071bf215546Sopenharmony_ci         /* convert int param to float */
1072bf215546Sopenharmony_ci         need_update = set_tex_parameterf(ctx, texObj, pname, fparam, dsa);
1073bf215546Sopenharmony_ci      }
1074bf215546Sopenharmony_ci      break;
1075bf215546Sopenharmony_ci   case GL_TEXTURE_BORDER_COLOR:
1076bf215546Sopenharmony_ci   case GL_TEXTURE_SWIZZLE_RGBA:
1077bf215546Sopenharmony_ci      {
1078bf215546Sopenharmony_ci         _mesa_error(ctx, GL_INVALID_ENUM,
1079bf215546Sopenharmony_ci                     "glTex%sParameteri(non-scalar pname)",
1080bf215546Sopenharmony_ci                     dsa ? "ture" : "");
1081bf215546Sopenharmony_ci         return;
1082bf215546Sopenharmony_ci      }
1083bf215546Sopenharmony_ci   default:
1084bf215546Sopenharmony_ci      /* this will generate an error if pname is illegal */
1085bf215546Sopenharmony_ci      {
1086bf215546Sopenharmony_ci         GLint iparam[4];
1087bf215546Sopenharmony_ci         iparam[0] = param;
1088bf215546Sopenharmony_ci         iparam[1] = iparam[2] = iparam[3] = 0;
1089bf215546Sopenharmony_ci         need_update = set_tex_parameteri(ctx, texObj, pname, iparam, dsa);
1090bf215546Sopenharmony_ci      }
1091bf215546Sopenharmony_ci   }
1092bf215546Sopenharmony_ci
1093bf215546Sopenharmony_ci   if (need_update) {
1094bf215546Sopenharmony_ci      _mesa_texture_parameter_invalidate(ctx, texObj, pname);
1095bf215546Sopenharmony_ci   }
1096bf215546Sopenharmony_ci}
1097bf215546Sopenharmony_ci
1098bf215546Sopenharmony_ci
1099bf215546Sopenharmony_civoid
1100bf215546Sopenharmony_ci_mesa_texture_parameteriv(struct gl_context *ctx,
1101bf215546Sopenharmony_ci                          struct gl_texture_object *texObj,
1102bf215546Sopenharmony_ci                          GLenum pname, const GLint *params, bool dsa)
1103bf215546Sopenharmony_ci{
1104bf215546Sopenharmony_ci   GLboolean need_update;
1105bf215546Sopenharmony_ci
1106bf215546Sopenharmony_ci   switch (pname) {
1107bf215546Sopenharmony_ci   case GL_TEXTURE_BORDER_COLOR:
1108bf215546Sopenharmony_ci      {
1109bf215546Sopenharmony_ci         /* convert int params to float */
1110bf215546Sopenharmony_ci         GLfloat fparams[4];
1111bf215546Sopenharmony_ci         fparams[0] = INT_TO_FLOAT(params[0]);
1112bf215546Sopenharmony_ci         fparams[1] = INT_TO_FLOAT(params[1]);
1113bf215546Sopenharmony_ci         fparams[2] = INT_TO_FLOAT(params[2]);
1114bf215546Sopenharmony_ci         fparams[3] = INT_TO_FLOAT(params[3]);
1115bf215546Sopenharmony_ci         need_update = set_tex_parameterf(ctx, texObj, pname, fparams, dsa);
1116bf215546Sopenharmony_ci      }
1117bf215546Sopenharmony_ci      break;
1118bf215546Sopenharmony_ci   case GL_TEXTURE_MIN_LOD:
1119bf215546Sopenharmony_ci   case GL_TEXTURE_MAX_LOD:
1120bf215546Sopenharmony_ci   case GL_TEXTURE_PRIORITY:
1121bf215546Sopenharmony_ci   case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1122bf215546Sopenharmony_ci   case GL_TEXTURE_LOD_BIAS:
1123bf215546Sopenharmony_ci      {
1124bf215546Sopenharmony_ci         /* convert int param to float */
1125bf215546Sopenharmony_ci         GLfloat fparams[4];
1126bf215546Sopenharmony_ci         fparams[0] = (GLfloat) params[0];
1127bf215546Sopenharmony_ci         fparams[1] = fparams[2] = fparams[3] = 0.0F;
1128bf215546Sopenharmony_ci         need_update = set_tex_parameterf(ctx, texObj, pname, fparams, dsa);
1129bf215546Sopenharmony_ci      }
1130bf215546Sopenharmony_ci      break;
1131bf215546Sopenharmony_ci   default:
1132bf215546Sopenharmony_ci      /* this will generate an error if pname is illegal */
1133bf215546Sopenharmony_ci      need_update = set_tex_parameteri(ctx, texObj, pname, params, dsa);
1134bf215546Sopenharmony_ci   }
1135bf215546Sopenharmony_ci
1136bf215546Sopenharmony_ci   if (need_update) {
1137bf215546Sopenharmony_ci      _mesa_texture_parameter_invalidate(ctx, texObj, pname);
1138bf215546Sopenharmony_ci   }
1139bf215546Sopenharmony_ci}
1140bf215546Sopenharmony_ci
1141bf215546Sopenharmony_civoid
1142bf215546Sopenharmony_ci_mesa_texture_parameterIiv(struct gl_context *ctx,
1143bf215546Sopenharmony_ci                           struct gl_texture_object *texObj,
1144bf215546Sopenharmony_ci                           GLenum pname, const GLint *params, bool dsa)
1145bf215546Sopenharmony_ci{
1146bf215546Sopenharmony_ci   switch (pname) {
1147bf215546Sopenharmony_ci   case GL_TEXTURE_BORDER_COLOR:
1148bf215546Sopenharmony_ci      if (texObj->HandleAllocated) {
1149bf215546Sopenharmony_ci         _mesa_error(ctx, GL_INVALID_OPERATION,
1150bf215546Sopenharmony_ci                     "glTextureParameterIiv(immutable texture)");
1151bf215546Sopenharmony_ci         return;
1152bf215546Sopenharmony_ci      }
1153bf215546Sopenharmony_ci
1154bf215546Sopenharmony_ci      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target)) {
1155bf215546Sopenharmony_ci         _mesa_error(ctx, dsa ? GL_INVALID_OPERATION : GL_INVALID_ENUM, "glTextureParameterIiv(texture)");
1156bf215546Sopenharmony_ci         return;
1157bf215546Sopenharmony_ci      }
1158bf215546Sopenharmony_ci      FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT, GL_TEXTURE_BIT);
1159bf215546Sopenharmony_ci      /* set the integer-valued border color */
1160bf215546Sopenharmony_ci      COPY_4V(texObj->Sampler.Attrib.state.border_color.i, params);
1161bf215546Sopenharmony_ci      _mesa_update_is_border_color_nonzero(&texObj->Sampler);
1162bf215546Sopenharmony_ci      break;
1163bf215546Sopenharmony_ci   default:
1164bf215546Sopenharmony_ci      _mesa_texture_parameteriv(ctx, texObj, pname, params, dsa);
1165bf215546Sopenharmony_ci      break;
1166bf215546Sopenharmony_ci   }
1167bf215546Sopenharmony_ci   /* XXX no driver hook for TexParameterIiv() yet */
1168bf215546Sopenharmony_ci}
1169bf215546Sopenharmony_ci
1170bf215546Sopenharmony_civoid
1171bf215546Sopenharmony_ci_mesa_texture_parameterIuiv(struct gl_context *ctx,
1172bf215546Sopenharmony_ci                            struct gl_texture_object *texObj,
1173bf215546Sopenharmony_ci                            GLenum pname, const GLuint *params, bool dsa)
1174bf215546Sopenharmony_ci{
1175bf215546Sopenharmony_ci   switch (pname) {
1176bf215546Sopenharmony_ci   case GL_TEXTURE_BORDER_COLOR:
1177bf215546Sopenharmony_ci      if (texObj->HandleAllocated) {
1178bf215546Sopenharmony_ci         _mesa_error(ctx, GL_INVALID_OPERATION,
1179bf215546Sopenharmony_ci                     "glTextureParameterIuiv(immutable texture)");
1180bf215546Sopenharmony_ci         return;
1181bf215546Sopenharmony_ci      }
1182bf215546Sopenharmony_ci
1183bf215546Sopenharmony_ci      if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target)) {
1184bf215546Sopenharmony_ci         _mesa_error(ctx, dsa ? GL_INVALID_OPERATION : GL_INVALID_ENUM, "glTextureParameterIuiv(texture)");
1185bf215546Sopenharmony_ci         return;
1186bf215546Sopenharmony_ci      }
1187bf215546Sopenharmony_ci      FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT, GL_TEXTURE_BIT);
1188bf215546Sopenharmony_ci      /* set the unsigned integer-valued border color */
1189bf215546Sopenharmony_ci      COPY_4V(texObj->Sampler.Attrib.state.border_color.ui, params);
1190bf215546Sopenharmony_ci      _mesa_update_is_border_color_nonzero(&texObj->Sampler);
1191bf215546Sopenharmony_ci      break;
1192bf215546Sopenharmony_ci   default:
1193bf215546Sopenharmony_ci      _mesa_texture_parameteriv(ctx, texObj, pname, (const GLint *) params,
1194bf215546Sopenharmony_ci                                dsa);
1195bf215546Sopenharmony_ci      break;
1196bf215546Sopenharmony_ci   }
1197bf215546Sopenharmony_ci   /* XXX no driver hook for TexParameterIuiv() yet */
1198bf215546Sopenharmony_ci}
1199bf215546Sopenharmony_ci
1200bf215546Sopenharmony_civoid GLAPIENTRY
1201bf215546Sopenharmony_ci_mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
1202bf215546Sopenharmony_ci{
1203bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1204bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1205bf215546Sopenharmony_ci
1206bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1207bf215546Sopenharmony_ci                                                   ctx->Texture.CurrentUnit,
1208bf215546Sopenharmony_ci                                                   false,
1209bf215546Sopenharmony_ci                                                   "glTexParameterf");
1210bf215546Sopenharmony_ci   if (!texObj)
1211bf215546Sopenharmony_ci      return;
1212bf215546Sopenharmony_ci
1213bf215546Sopenharmony_ci   _mesa_texture_parameterf(ctx, texObj, pname, param, false);
1214bf215546Sopenharmony_ci}
1215bf215546Sopenharmony_ci
1216bf215546Sopenharmony_civoid GLAPIENTRY
1217bf215546Sopenharmony_ci_mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1218bf215546Sopenharmony_ci{
1219bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1220bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1221bf215546Sopenharmony_ci
1222bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1223bf215546Sopenharmony_ci                                                   ctx->Texture.CurrentUnit,
1224bf215546Sopenharmony_ci                                                   false,
1225bf215546Sopenharmony_ci                                                   "glTexParameterfv");
1226bf215546Sopenharmony_ci   if (!texObj)
1227bf215546Sopenharmony_ci      return;
1228bf215546Sopenharmony_ci
1229bf215546Sopenharmony_ci   _mesa_texture_parameterfv(ctx, texObj, pname, params, false);
1230bf215546Sopenharmony_ci}
1231bf215546Sopenharmony_ci
1232bf215546Sopenharmony_civoid GLAPIENTRY
1233bf215546Sopenharmony_ci_mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
1234bf215546Sopenharmony_ci{
1235bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1236bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1237bf215546Sopenharmony_ci
1238bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1239bf215546Sopenharmony_ci                                                   ctx->Texture.CurrentUnit,
1240bf215546Sopenharmony_ci                                                   false,
1241bf215546Sopenharmony_ci                                                   "glTexParameteri");
1242bf215546Sopenharmony_ci   if (!texObj)
1243bf215546Sopenharmony_ci      return;
1244bf215546Sopenharmony_ci
1245bf215546Sopenharmony_ci   _mesa_texture_parameteri(ctx, texObj, pname, param, false);
1246bf215546Sopenharmony_ci}
1247bf215546Sopenharmony_ci
1248bf215546Sopenharmony_civoid GLAPIENTRY
1249bf215546Sopenharmony_ci_mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
1250bf215546Sopenharmony_ci{
1251bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1252bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1253bf215546Sopenharmony_ci
1254bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1255bf215546Sopenharmony_ci                                                   ctx->Texture.CurrentUnit,
1256bf215546Sopenharmony_ci                                                   false,
1257bf215546Sopenharmony_ci                                                   "glTexParameteriv");
1258bf215546Sopenharmony_ci   if (!texObj)
1259bf215546Sopenharmony_ci      return;
1260bf215546Sopenharmony_ci
1261bf215546Sopenharmony_ci   _mesa_texture_parameteriv(ctx, texObj, pname, params, false);
1262bf215546Sopenharmony_ci}
1263bf215546Sopenharmony_ci
1264bf215546Sopenharmony_ci/**
1265bf215546Sopenharmony_ci * Set tex parameter to integer value(s).  Primarily intended to set
1266bf215546Sopenharmony_ci * integer-valued texture border color (for integer-valued textures).
1267bf215546Sopenharmony_ci * New in GL 3.0.
1268bf215546Sopenharmony_ci */
1269bf215546Sopenharmony_civoid GLAPIENTRY
1270bf215546Sopenharmony_ci_mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
1271bf215546Sopenharmony_ci{
1272bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1273bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1274bf215546Sopenharmony_ci
1275bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1276bf215546Sopenharmony_ci                                                   ctx->Texture.CurrentUnit,
1277bf215546Sopenharmony_ci                                                   false,
1278bf215546Sopenharmony_ci                                                   "glTexParameterIiv");
1279bf215546Sopenharmony_ci   if (!texObj)
1280bf215546Sopenharmony_ci      return;
1281bf215546Sopenharmony_ci
1282bf215546Sopenharmony_ci   _mesa_texture_parameterIiv(ctx, texObj, pname, params, false);
1283bf215546Sopenharmony_ci}
1284bf215546Sopenharmony_ci
1285bf215546Sopenharmony_ci/**
1286bf215546Sopenharmony_ci * Set tex parameter to unsigned integer value(s).  Primarily intended to set
1287bf215546Sopenharmony_ci * uint-valued texture border color (for integer-valued textures).
1288bf215546Sopenharmony_ci * New in GL 3.0
1289bf215546Sopenharmony_ci */
1290bf215546Sopenharmony_civoid GLAPIENTRY
1291bf215546Sopenharmony_ci_mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
1292bf215546Sopenharmony_ci{
1293bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1294bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1295bf215546Sopenharmony_ci
1296bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1297bf215546Sopenharmony_ci                                                   ctx->Texture.CurrentUnit,
1298bf215546Sopenharmony_ci                                                   false,
1299bf215546Sopenharmony_ci                                                   "glTexParameterIuiv");
1300bf215546Sopenharmony_ci   if (!texObj)
1301bf215546Sopenharmony_ci      return;
1302bf215546Sopenharmony_ci
1303bf215546Sopenharmony_ci   _mesa_texture_parameterIuiv(ctx, texObj, pname, params, false);
1304bf215546Sopenharmony_ci}
1305bf215546Sopenharmony_ci
1306bf215546Sopenharmony_civoid GLAPIENTRY
1307bf215546Sopenharmony_ci_mesa_TextureParameterfvEXT(GLuint texture, GLenum target, GLenum pname, const GLfloat *params)
1308bf215546Sopenharmony_ci{
1309bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1310bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1311bf215546Sopenharmony_ci
1312bf215546Sopenharmony_ci   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1313bf215546Sopenharmony_ci                                           "glTextureParameterfvEXT");
1314bf215546Sopenharmony_ci   if (!texObj)
1315bf215546Sopenharmony_ci      return;
1316bf215546Sopenharmony_ci
1317bf215546Sopenharmony_ci   if (!is_texparameteri_target_valid(texObj->Target)) {
1318bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterfvEXT");
1319bf215546Sopenharmony_ci      return;
1320bf215546Sopenharmony_ci   }
1321bf215546Sopenharmony_ci
1322bf215546Sopenharmony_ci   _mesa_texture_parameterfv(ctx, texObj, pname, params, true);
1323bf215546Sopenharmony_ci}
1324bf215546Sopenharmony_ci
1325bf215546Sopenharmony_civoid GLAPIENTRY
1326bf215546Sopenharmony_ci_mesa_TextureParameterfv(GLuint texture, GLenum pname, const GLfloat *params)
1327bf215546Sopenharmony_ci{
1328bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1329bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1330bf215546Sopenharmony_ci
1331bf215546Sopenharmony_ci   texObj = get_texobj_by_name(ctx, texture, "glTextureParameterfv");
1332bf215546Sopenharmony_ci   if (!texObj)
1333bf215546Sopenharmony_ci      return;
1334bf215546Sopenharmony_ci
1335bf215546Sopenharmony_ci   _mesa_texture_parameterfv(ctx, texObj, pname, params, true);
1336bf215546Sopenharmony_ci}
1337bf215546Sopenharmony_ci
1338bf215546Sopenharmony_civoid GLAPIENTRY
1339bf215546Sopenharmony_ci_mesa_MultiTexParameterfvEXT(GLenum texunit, GLenum target, GLenum pname, const GLfloat *params)
1340bf215546Sopenharmony_ci{
1341bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1342bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1343bf215546Sopenharmony_ci
1344bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1345bf215546Sopenharmony_ci                                                   texunit - GL_TEXTURE0,
1346bf215546Sopenharmony_ci                                                   false,
1347bf215546Sopenharmony_ci                                                   "glMultiTexParameterfvEXT");
1348bf215546Sopenharmony_ci   if (!texObj)
1349bf215546Sopenharmony_ci      return;
1350bf215546Sopenharmony_ci
1351bf215546Sopenharmony_ci   if (!is_texparameteri_target_valid(texObj->Target)) {
1352bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION, "glMultiTexParameterifvEXT(target)");
1353bf215546Sopenharmony_ci      return;
1354bf215546Sopenharmony_ci   }
1355bf215546Sopenharmony_ci
1356bf215546Sopenharmony_ci   _mesa_texture_parameterfv(ctx, texObj, pname, params, true);
1357bf215546Sopenharmony_ci}
1358bf215546Sopenharmony_ci
1359bf215546Sopenharmony_civoid GLAPIENTRY
1360bf215546Sopenharmony_ci_mesa_TextureParameterfEXT(GLuint texture, GLenum target, GLenum pname, GLfloat param)
1361bf215546Sopenharmony_ci{
1362bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1363bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1364bf215546Sopenharmony_ci
1365bf215546Sopenharmony_ci   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1366bf215546Sopenharmony_ci                                           "glTextureParameterfEXT");
1367bf215546Sopenharmony_ci   if (!texObj)
1368bf215546Sopenharmony_ci      return;
1369bf215546Sopenharmony_ci
1370bf215546Sopenharmony_ci   if (!is_texparameteri_target_valid(texObj->Target)) {
1371bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterfEXT");
1372bf215546Sopenharmony_ci      return;
1373bf215546Sopenharmony_ci   }
1374bf215546Sopenharmony_ci
1375bf215546Sopenharmony_ci   _mesa_texture_parameterf(ctx, texObj, pname, param, true);
1376bf215546Sopenharmony_ci}
1377bf215546Sopenharmony_ci
1378bf215546Sopenharmony_civoid GLAPIENTRY
1379bf215546Sopenharmony_ci_mesa_MultiTexParameterfEXT(GLenum texunit, GLenum target, GLenum pname,
1380bf215546Sopenharmony_ci                            GLfloat param)
1381bf215546Sopenharmony_ci{
1382bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1383bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1384bf215546Sopenharmony_ci
1385bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1386bf215546Sopenharmony_ci                                                   texunit - GL_TEXTURE0,
1387bf215546Sopenharmony_ci                                                   false,
1388bf215546Sopenharmony_ci                                                   "glMultiTexParameterfEXT");
1389bf215546Sopenharmony_ci   if (!texObj)
1390bf215546Sopenharmony_ci      return;
1391bf215546Sopenharmony_ci
1392bf215546Sopenharmony_ci   if (!is_texparameteri_target_valid(texObj->Target)) {
1393bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION, "glMultiTexParameterfEXT");
1394bf215546Sopenharmony_ci      return;
1395bf215546Sopenharmony_ci   }
1396bf215546Sopenharmony_ci
1397bf215546Sopenharmony_ci   _mesa_texture_parameterf(ctx, texObj, pname, param, true);
1398bf215546Sopenharmony_ci}
1399bf215546Sopenharmony_ci
1400bf215546Sopenharmony_civoid GLAPIENTRY
1401bf215546Sopenharmony_ci_mesa_TextureParameterf(GLuint texture, GLenum pname, GLfloat param)
1402bf215546Sopenharmony_ci{
1403bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1404bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1405bf215546Sopenharmony_ci
1406bf215546Sopenharmony_ci   texObj = get_texobj_by_name(ctx, texture, "glTextureParameterf");
1407bf215546Sopenharmony_ci   if (!texObj)
1408bf215546Sopenharmony_ci      return;
1409bf215546Sopenharmony_ci
1410bf215546Sopenharmony_ci   _mesa_texture_parameterf(ctx, texObj, pname, param, true);
1411bf215546Sopenharmony_ci}
1412bf215546Sopenharmony_ci
1413bf215546Sopenharmony_civoid GLAPIENTRY
1414bf215546Sopenharmony_ci_mesa_TextureParameteriEXT(GLuint texture, GLenum target, GLenum pname, GLint param)
1415bf215546Sopenharmony_ci{
1416bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1417bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1418bf215546Sopenharmony_ci
1419bf215546Sopenharmony_ci   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1420bf215546Sopenharmony_ci                                           "glTextureParameteriEXT");
1421bf215546Sopenharmony_ci   if (!texObj)
1422bf215546Sopenharmony_ci      return;
1423bf215546Sopenharmony_ci
1424bf215546Sopenharmony_ci   if (!is_texparameteri_target_valid(texObj->Target)) {
1425bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameteriEXT(target)");
1426bf215546Sopenharmony_ci      return;
1427bf215546Sopenharmony_ci   }
1428bf215546Sopenharmony_ci
1429bf215546Sopenharmony_ci   _mesa_texture_parameteri(ctx, texObj, pname, param, true);
1430bf215546Sopenharmony_ci}
1431bf215546Sopenharmony_ci
1432bf215546Sopenharmony_civoid GLAPIENTRY
1433bf215546Sopenharmony_ci_mesa_MultiTexParameteriEXT(GLenum texunit, GLenum target, GLenum pname,
1434bf215546Sopenharmony_ci                            GLint param)
1435bf215546Sopenharmony_ci{
1436bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1437bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1438bf215546Sopenharmony_ci
1439bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1440bf215546Sopenharmony_ci                                                   texunit - GL_TEXTURE0,
1441bf215546Sopenharmony_ci                                                   false,
1442bf215546Sopenharmony_ci                                                   "glMultiTexParameteriEXT");
1443bf215546Sopenharmony_ci   if (!texObj)
1444bf215546Sopenharmony_ci      return;
1445bf215546Sopenharmony_ci
1446bf215546Sopenharmony_ci   if (!is_texparameteri_target_valid(texObj->Target)) {
1447bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION, "glMultiTexParameteriEXT(target)");
1448bf215546Sopenharmony_ci      return;
1449bf215546Sopenharmony_ci   }
1450bf215546Sopenharmony_ci
1451bf215546Sopenharmony_ci   _mesa_texture_parameteri(ctx, texObj, pname, param, true);
1452bf215546Sopenharmony_ci}
1453bf215546Sopenharmony_ci
1454bf215546Sopenharmony_civoid GLAPIENTRY
1455bf215546Sopenharmony_ci_mesa_TextureParameteri(GLuint texture, GLenum pname, GLint param)
1456bf215546Sopenharmony_ci{
1457bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1458bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1459bf215546Sopenharmony_ci
1460bf215546Sopenharmony_ci   texObj = get_texobj_by_name(ctx, texture, "glTextureParameteri");
1461bf215546Sopenharmony_ci   if (!texObj)
1462bf215546Sopenharmony_ci      return;
1463bf215546Sopenharmony_ci
1464bf215546Sopenharmony_ci   _mesa_texture_parameteri(ctx, texObj, pname, param, true);
1465bf215546Sopenharmony_ci}
1466bf215546Sopenharmony_ci
1467bf215546Sopenharmony_civoid GLAPIENTRY
1468bf215546Sopenharmony_ci_mesa_TextureParameterivEXT(GLuint texture, GLenum target, GLenum pname,
1469bf215546Sopenharmony_ci                         const GLint *params)
1470bf215546Sopenharmony_ci{
1471bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1472bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1473bf215546Sopenharmony_ci
1474bf215546Sopenharmony_ci   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1475bf215546Sopenharmony_ci                                           "glTextureParameterivEXT");
1476bf215546Sopenharmony_ci   if (!texObj)
1477bf215546Sopenharmony_ci      return;
1478bf215546Sopenharmony_ci
1479bf215546Sopenharmony_ci   if (!is_texparameteri_target_valid(texObj->Target)) {
1480bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterivEXT(target)");
1481bf215546Sopenharmony_ci      return;
1482bf215546Sopenharmony_ci   }
1483bf215546Sopenharmony_ci
1484bf215546Sopenharmony_ci   _mesa_texture_parameteriv(ctx, texObj, pname, params, true);
1485bf215546Sopenharmony_ci}
1486bf215546Sopenharmony_ci
1487bf215546Sopenharmony_civoid GLAPIENTRY
1488bf215546Sopenharmony_ci_mesa_MultiTexParameterivEXT(GLenum texunit, GLenum target, GLenum pname,
1489bf215546Sopenharmony_ci                             const GLint *params)
1490bf215546Sopenharmony_ci{
1491bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1492bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1493bf215546Sopenharmony_ci
1494bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1495bf215546Sopenharmony_ci                                                   texunit - GL_TEXTURE0,
1496bf215546Sopenharmony_ci                                                   false,
1497bf215546Sopenharmony_ci                                                   "glMultiTexParameterivEXT");
1498bf215546Sopenharmony_ci   if (!texObj)
1499bf215546Sopenharmony_ci      return;
1500bf215546Sopenharmony_ci
1501bf215546Sopenharmony_ci   if (!is_texparameteri_target_valid(texObj->Target)) {
1502bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION, "glMultiTexParameterivEXT(target)");
1503bf215546Sopenharmony_ci      return;
1504bf215546Sopenharmony_ci   }
1505bf215546Sopenharmony_ci
1506bf215546Sopenharmony_ci   _mesa_texture_parameteriv(ctx, texObj, pname, params, true);
1507bf215546Sopenharmony_ci}
1508bf215546Sopenharmony_ci
1509bf215546Sopenharmony_civoid GLAPIENTRY
1510bf215546Sopenharmony_ci_mesa_TextureParameteriv(GLuint texture, GLenum pname,
1511bf215546Sopenharmony_ci                         const GLint *params)
1512bf215546Sopenharmony_ci{
1513bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1514bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1515bf215546Sopenharmony_ci
1516bf215546Sopenharmony_ci   texObj = get_texobj_by_name(ctx, texture, "glTextureParameteriv");
1517bf215546Sopenharmony_ci   if (!texObj)
1518bf215546Sopenharmony_ci      return;
1519bf215546Sopenharmony_ci
1520bf215546Sopenharmony_ci   _mesa_texture_parameteriv(ctx, texObj, pname, params, true);
1521bf215546Sopenharmony_ci}
1522bf215546Sopenharmony_ci
1523bf215546Sopenharmony_ci
1524bf215546Sopenharmony_civoid GLAPIENTRY
1525bf215546Sopenharmony_ci_mesa_TextureParameterIiv(GLuint texture, GLenum pname, const GLint *params)
1526bf215546Sopenharmony_ci{
1527bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1528bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1529bf215546Sopenharmony_ci
1530bf215546Sopenharmony_ci   texObj = get_texobj_by_name(ctx, texture, "glTextureParameterIiv");
1531bf215546Sopenharmony_ci   if (!texObj)
1532bf215546Sopenharmony_ci      return;
1533bf215546Sopenharmony_ci
1534bf215546Sopenharmony_ci   _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
1535bf215546Sopenharmony_ci}
1536bf215546Sopenharmony_ci
1537bf215546Sopenharmony_civoid GLAPIENTRY
1538bf215546Sopenharmony_ci_mesa_TextureParameterIivEXT(GLuint texture, GLenum target, GLenum pname,
1539bf215546Sopenharmony_ci                             const GLint *params)
1540bf215546Sopenharmony_ci{
1541bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1542bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1543bf215546Sopenharmony_ci
1544bf215546Sopenharmony_ci   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1545bf215546Sopenharmony_ci                                           "glTextureParameterIivEXT");
1546bf215546Sopenharmony_ci   if (!texObj)
1547bf215546Sopenharmony_ci      return;
1548bf215546Sopenharmony_ci
1549bf215546Sopenharmony_ci   _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
1550bf215546Sopenharmony_ci}
1551bf215546Sopenharmony_ci
1552bf215546Sopenharmony_civoid GLAPIENTRY
1553bf215546Sopenharmony_ci_mesa_MultiTexParameterIivEXT(GLenum texunit, GLenum target, GLenum pname,
1554bf215546Sopenharmony_ci                              const GLint *params)
1555bf215546Sopenharmony_ci{
1556bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1557bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1558bf215546Sopenharmony_ci
1559bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1560bf215546Sopenharmony_ci                                                   texunit - GL_TEXTURE0,
1561bf215546Sopenharmony_ci                                                   true,
1562bf215546Sopenharmony_ci                                                   "glMultiTexParameterIivEXT");
1563bf215546Sopenharmony_ci   if (!texObj)
1564bf215546Sopenharmony_ci      return;
1565bf215546Sopenharmony_ci
1566bf215546Sopenharmony_ci   _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
1567bf215546Sopenharmony_ci}
1568bf215546Sopenharmony_ci
1569bf215546Sopenharmony_civoid GLAPIENTRY
1570bf215546Sopenharmony_ci_mesa_TextureParameterIuiv(GLuint texture, GLenum pname, const GLuint *params)
1571bf215546Sopenharmony_ci{
1572bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1573bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1574bf215546Sopenharmony_ci
1575bf215546Sopenharmony_ci   texObj = get_texobj_by_name(ctx, texture, "glTextureParameterIuiv");
1576bf215546Sopenharmony_ci   if (!texObj)
1577bf215546Sopenharmony_ci      return;
1578bf215546Sopenharmony_ci
1579bf215546Sopenharmony_ci   _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
1580bf215546Sopenharmony_ci}
1581bf215546Sopenharmony_ci
1582bf215546Sopenharmony_civoid GLAPIENTRY
1583bf215546Sopenharmony_ci_mesa_TextureParameterIuivEXT(GLuint texture, GLenum target, GLenum pname,
1584bf215546Sopenharmony_ci                              const GLuint *params)
1585bf215546Sopenharmony_ci{
1586bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1587bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1588bf215546Sopenharmony_ci
1589bf215546Sopenharmony_ci   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
1590bf215546Sopenharmony_ci                                           "glTextureParameterIuivEXT");
1591bf215546Sopenharmony_ci   if (!texObj)
1592bf215546Sopenharmony_ci      return;
1593bf215546Sopenharmony_ci
1594bf215546Sopenharmony_ci   _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
1595bf215546Sopenharmony_ci}
1596bf215546Sopenharmony_ci
1597bf215546Sopenharmony_civoid GLAPIENTRY
1598bf215546Sopenharmony_ci_mesa_MultiTexParameterIuivEXT(GLenum texunit, GLenum target, GLenum pname,
1599bf215546Sopenharmony_ci                               const GLuint *params)
1600bf215546Sopenharmony_ci{
1601bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
1602bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
1603bf215546Sopenharmony_ci
1604bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
1605bf215546Sopenharmony_ci                                                   texunit - GL_TEXTURE0,
1606bf215546Sopenharmony_ci                                                   true,
1607bf215546Sopenharmony_ci                                                   "glMultiTexParameterIuivEXT");
1608bf215546Sopenharmony_ci   if (!texObj)
1609bf215546Sopenharmony_ci      return;
1610bf215546Sopenharmony_ci
1611bf215546Sopenharmony_ci   _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
1612bf215546Sopenharmony_ci}
1613bf215546Sopenharmony_ci
1614bf215546Sopenharmony_ciGLboolean
1615bf215546Sopenharmony_ci_mesa_legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target,
1616bf215546Sopenharmony_ci                                           bool dsa)
1617bf215546Sopenharmony_ci{
1618bf215546Sopenharmony_ci   /* Common targets for desktop GL and GLES 3.1. */
1619bf215546Sopenharmony_ci   switch (target) {
1620bf215546Sopenharmony_ci   case GL_TEXTURE_2D:
1621bf215546Sopenharmony_ci   case GL_TEXTURE_3D:
1622bf215546Sopenharmony_ci      return GL_TRUE;
1623bf215546Sopenharmony_ci   case GL_TEXTURE_2D_ARRAY_EXT:
1624bf215546Sopenharmony_ci      return ctx->Extensions.EXT_texture_array;
1625bf215546Sopenharmony_ci   case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1626bf215546Sopenharmony_ci   case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1627bf215546Sopenharmony_ci   case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1628bf215546Sopenharmony_ci   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1629bf215546Sopenharmony_ci   case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1630bf215546Sopenharmony_ci   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1631bf215546Sopenharmony_ci      return GL_TRUE;
1632bf215546Sopenharmony_ci   case GL_TEXTURE_2D_MULTISAMPLE:
1633bf215546Sopenharmony_ci   case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
1634bf215546Sopenharmony_ci      return ctx->Extensions.ARB_texture_multisample;
1635bf215546Sopenharmony_ci   case GL_TEXTURE_BUFFER:
1636bf215546Sopenharmony_ci      /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1637bf215546Sopenharmony_ci       * but not in earlier versions that expose ARB_texture_buffer_object.
1638bf215546Sopenharmony_ci       *
1639bf215546Sopenharmony_ci       * From the ARB_texture_buffer_object spec:
1640bf215546Sopenharmony_ci       * "(7) Do buffer textures support texture parameters (TexParameter) or
1641bf215546Sopenharmony_ci       *      queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1642bf215546Sopenharmony_ci       *
1643bf215546Sopenharmony_ci       *    RESOLVED:  No. [...] Note that the spec edits above don't add
1644bf215546Sopenharmony_ci       *    explicit error language for any of these cases.  That is because
1645bf215546Sopenharmony_ci       *    each of the functions enumerate the set of valid <target>
1646bf215546Sopenharmony_ci       *    parameters.  Not editing the spec to allow TEXTURE_BUFFER_ARB in
1647bf215546Sopenharmony_ci       *    these cases means that target is not legal, and an INVALID_ENUM
1648bf215546Sopenharmony_ci       *    error should be generated."
1649bf215546Sopenharmony_ci       *
1650bf215546Sopenharmony_ci       * From the OpenGL 3.1 spec:
1651bf215546Sopenharmony_ci       * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1652bf215546Sopenharmony_ci       *
1653bf215546Sopenharmony_ci       * From ARB_texture_buffer_range, GL_TEXTURE is a valid target in
1654bf215546Sopenharmony_ci       * GetTexLevelParameter.
1655bf215546Sopenharmony_ci       */
1656bf215546Sopenharmony_ci      return (_mesa_is_desktop_gl(ctx) && ctx->Version >= 31) ||
1657bf215546Sopenharmony_ci             _mesa_has_OES_texture_buffer(ctx) ||
1658bf215546Sopenharmony_ci             _mesa_has_ARB_texture_buffer_range(ctx);
1659bf215546Sopenharmony_ci   case GL_TEXTURE_CUBE_MAP_ARRAY:
1660bf215546Sopenharmony_ci      return _mesa_has_texture_cube_map_array(ctx);
1661bf215546Sopenharmony_ci   }
1662bf215546Sopenharmony_ci
1663bf215546Sopenharmony_ci   if (!_mesa_is_desktop_gl(ctx))
1664bf215546Sopenharmony_ci      return GL_FALSE;
1665bf215546Sopenharmony_ci
1666bf215546Sopenharmony_ci   /* Rest of the desktop GL targets. */
1667bf215546Sopenharmony_ci   switch (target) {
1668bf215546Sopenharmony_ci   case GL_TEXTURE_1D:
1669bf215546Sopenharmony_ci   case GL_PROXY_TEXTURE_1D:
1670bf215546Sopenharmony_ci   case GL_PROXY_TEXTURE_2D:
1671bf215546Sopenharmony_ci   case GL_PROXY_TEXTURE_3D:
1672bf215546Sopenharmony_ci   case GL_PROXY_TEXTURE_CUBE_MAP:
1673bf215546Sopenharmony_ci      return GL_TRUE;
1674bf215546Sopenharmony_ci   case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY:
1675bf215546Sopenharmony_ci      return ctx->Extensions.ARB_texture_cube_map_array;
1676bf215546Sopenharmony_ci   case GL_TEXTURE_RECTANGLE_NV:
1677bf215546Sopenharmony_ci   case GL_PROXY_TEXTURE_RECTANGLE_NV:
1678bf215546Sopenharmony_ci      return ctx->Extensions.NV_texture_rectangle;
1679bf215546Sopenharmony_ci   case GL_TEXTURE_1D_ARRAY_EXT:
1680bf215546Sopenharmony_ci   case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
1681bf215546Sopenharmony_ci   case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
1682bf215546Sopenharmony_ci      return ctx->Extensions.EXT_texture_array;
1683bf215546Sopenharmony_ci   case GL_PROXY_TEXTURE_2D_MULTISAMPLE:
1684bf215546Sopenharmony_ci   case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY:
1685bf215546Sopenharmony_ci      return ctx->Extensions.ARB_texture_multisample;
1686bf215546Sopenharmony_ci
1687bf215546Sopenharmony_ci   /*  This is a valid target for dsa, but the OpenGL 4.5 core spec
1688bf215546Sopenharmony_ci    *  (30.10.2014) Section 8.11 Texture Queries says:
1689bf215546Sopenharmony_ci    *       "For GetTextureLevelParameter* only, texture may also be a cube
1690bf215546Sopenharmony_ci    *       map texture object.  In this case the query is always performed
1691bf215546Sopenharmony_ci    *       for face zero (the TEXTURE_CUBE_MAP_POSITIVE_X face), since there
1692bf215546Sopenharmony_ci    *       is no way to specify another face."
1693bf215546Sopenharmony_ci    */
1694bf215546Sopenharmony_ci   case GL_TEXTURE_CUBE_MAP:
1695bf215546Sopenharmony_ci      return dsa;
1696bf215546Sopenharmony_ci   default:
1697bf215546Sopenharmony_ci      return GL_FALSE;
1698bf215546Sopenharmony_ci   }
1699bf215546Sopenharmony_ci}
1700bf215546Sopenharmony_ci
1701bf215546Sopenharmony_ci
1702bf215546Sopenharmony_cistatic void
1703bf215546Sopenharmony_ciget_tex_level_parameter_image(struct gl_context *ctx,
1704bf215546Sopenharmony_ci                              const struct gl_texture_object *texObj,
1705bf215546Sopenharmony_ci                              GLenum target, GLint level,
1706bf215546Sopenharmony_ci                              GLenum pname, GLint *params,
1707bf215546Sopenharmony_ci                              bool dsa)
1708bf215546Sopenharmony_ci{
1709bf215546Sopenharmony_ci   const struct gl_texture_image *img = NULL;
1710bf215546Sopenharmony_ci   struct gl_texture_image dummy_image;
1711bf215546Sopenharmony_ci   mesa_format texFormat;
1712bf215546Sopenharmony_ci   const char *suffix = dsa ? "ture" : "";
1713bf215546Sopenharmony_ci
1714bf215546Sopenharmony_ci   img = _mesa_select_tex_image(texObj, target, level);
1715bf215546Sopenharmony_ci   if (!img || img->TexFormat == MESA_FORMAT_NONE) {
1716bf215546Sopenharmony_ci      /* In case of undefined texture image return the default values.
1717bf215546Sopenharmony_ci       *
1718bf215546Sopenharmony_ci       * From OpenGL 4.0 spec, page 398:
1719bf215546Sopenharmony_ci       *    "The initial internal format of a texel array is RGBA
1720bf215546Sopenharmony_ci       *     instead of 1. TEXTURE_COMPONENTS is deprecated; always
1721bf215546Sopenharmony_ci       *     use TEXTURE_INTERNAL_FORMAT."
1722bf215546Sopenharmony_ci       */
1723bf215546Sopenharmony_ci      memset(&dummy_image, 0, sizeof(dummy_image));
1724bf215546Sopenharmony_ci      dummy_image.TexFormat = MESA_FORMAT_NONE;
1725bf215546Sopenharmony_ci      dummy_image.InternalFormat = GL_RGBA;
1726bf215546Sopenharmony_ci      dummy_image._BaseFormat = GL_NONE;
1727bf215546Sopenharmony_ci      dummy_image.FixedSampleLocations = GL_TRUE;
1728bf215546Sopenharmony_ci
1729bf215546Sopenharmony_ci      img = &dummy_image;
1730bf215546Sopenharmony_ci   }
1731bf215546Sopenharmony_ci
1732bf215546Sopenharmony_ci   texFormat = img->TexFormat;
1733bf215546Sopenharmony_ci
1734bf215546Sopenharmony_ci   switch (pname) {
1735bf215546Sopenharmony_ci      case GL_TEXTURE_WIDTH:
1736bf215546Sopenharmony_ci         *params = img->Width;
1737bf215546Sopenharmony_ci         break;
1738bf215546Sopenharmony_ci      case GL_TEXTURE_HEIGHT:
1739bf215546Sopenharmony_ci         *params = img->Height;
1740bf215546Sopenharmony_ci         break;
1741bf215546Sopenharmony_ci      case GL_TEXTURE_DEPTH:
1742bf215546Sopenharmony_ci         *params = img->Depth;
1743bf215546Sopenharmony_ci         break;
1744bf215546Sopenharmony_ci      case GL_TEXTURE_INTERNAL_FORMAT:
1745bf215546Sopenharmony_ci         if (_mesa_is_format_compressed(texFormat)) {
1746bf215546Sopenharmony_ci            /* need to return the actual compressed format */
1747bf215546Sopenharmony_ci            *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
1748bf215546Sopenharmony_ci         }
1749bf215546Sopenharmony_ci         else {
1750bf215546Sopenharmony_ci	    /* If the true internal format is not compressed but the user
1751bf215546Sopenharmony_ci	     * requested a generic compressed format, we have to return the
1752bf215546Sopenharmony_ci	     * generic base format that matches.
1753bf215546Sopenharmony_ci	     *
1754bf215546Sopenharmony_ci	     * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1755bf215546Sopenharmony_ci	     *
1756bf215546Sopenharmony_ci	     *     "If no specific compressed format is available,
1757bf215546Sopenharmony_ci	     *     internalformat is instead replaced by the corresponding base
1758bf215546Sopenharmony_ci	     *     internal format."
1759bf215546Sopenharmony_ci	     *
1760bf215546Sopenharmony_ci	     * Otherwise just return the user's requested internal format
1761bf215546Sopenharmony_ci	     */
1762bf215546Sopenharmony_ci	    const GLenum f =
1763bf215546Sopenharmony_ci	       _mesa_gl_compressed_format_base_format(img->InternalFormat);
1764bf215546Sopenharmony_ci
1765bf215546Sopenharmony_ci	    *params = (f != 0) ? f : img->InternalFormat;
1766bf215546Sopenharmony_ci	 }
1767bf215546Sopenharmony_ci         break;
1768bf215546Sopenharmony_ci      case GL_TEXTURE_BORDER:
1769bf215546Sopenharmony_ci         if (ctx->API != API_OPENGL_COMPAT)
1770bf215546Sopenharmony_ci            goto invalid_pname;
1771bf215546Sopenharmony_ci         *params = img->Border;
1772bf215546Sopenharmony_ci         break;
1773bf215546Sopenharmony_ci      case GL_TEXTURE_RED_SIZE:
1774bf215546Sopenharmony_ci      case GL_TEXTURE_GREEN_SIZE:
1775bf215546Sopenharmony_ci      case GL_TEXTURE_BLUE_SIZE:
1776bf215546Sopenharmony_ci      case GL_TEXTURE_ALPHA_SIZE:
1777bf215546Sopenharmony_ci         if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1778bf215546Sopenharmony_ci            *params = _mesa_get_format_bits(texFormat, pname);
1779bf215546Sopenharmony_ci         else
1780bf215546Sopenharmony_ci            *params = 0;
1781bf215546Sopenharmony_ci         break;
1782bf215546Sopenharmony_ci      case GL_TEXTURE_INTENSITY_SIZE:
1783bf215546Sopenharmony_ci      case GL_TEXTURE_LUMINANCE_SIZE:
1784bf215546Sopenharmony_ci         if (ctx->API != API_OPENGL_COMPAT)
1785bf215546Sopenharmony_ci            goto invalid_pname;
1786bf215546Sopenharmony_ci         if (_mesa_base_format_has_channel(img->_BaseFormat, pname)) {
1787bf215546Sopenharmony_ci            *params = _mesa_get_format_bits(texFormat, pname);
1788bf215546Sopenharmony_ci            if (*params == 0) {
1789bf215546Sopenharmony_ci               /* intensity or luminance is probably stored as RGB[A] */
1790bf215546Sopenharmony_ci               *params = MIN2(_mesa_get_format_bits(texFormat,
1791bf215546Sopenharmony_ci                                                    GL_TEXTURE_RED_SIZE),
1792bf215546Sopenharmony_ci                              _mesa_get_format_bits(texFormat,
1793bf215546Sopenharmony_ci                                                    GL_TEXTURE_GREEN_SIZE));
1794bf215546Sopenharmony_ci            }
1795bf215546Sopenharmony_ci            if (*params == 0 && pname == GL_TEXTURE_INTENSITY_SIZE) {
1796bf215546Sopenharmony_ci               /* Gallium may store intensity as LA */
1797bf215546Sopenharmony_ci               *params = _mesa_get_format_bits(texFormat,
1798bf215546Sopenharmony_ci                                               GL_TEXTURE_ALPHA_SIZE);
1799bf215546Sopenharmony_ci            }
1800bf215546Sopenharmony_ci         }
1801bf215546Sopenharmony_ci         else {
1802bf215546Sopenharmony_ci            *params = 0;
1803bf215546Sopenharmony_ci         }
1804bf215546Sopenharmony_ci         break;
1805bf215546Sopenharmony_ci      case GL_TEXTURE_DEPTH_SIZE_ARB:
1806bf215546Sopenharmony_ci         *params = _mesa_get_format_bits(texFormat, pname);
1807bf215546Sopenharmony_ci         break;
1808bf215546Sopenharmony_ci      case GL_TEXTURE_STENCIL_SIZE:
1809bf215546Sopenharmony_ci         *params = _mesa_get_format_bits(texFormat, pname);
1810bf215546Sopenharmony_ci         break;
1811bf215546Sopenharmony_ci      case GL_TEXTURE_SHARED_SIZE:
1812bf215546Sopenharmony_ci         if (ctx->Version < 30 &&
1813bf215546Sopenharmony_ci             !ctx->Extensions.EXT_texture_shared_exponent)
1814bf215546Sopenharmony_ci            goto invalid_pname;
1815bf215546Sopenharmony_ci         *params = texFormat == MESA_FORMAT_R9G9B9E5_FLOAT ? 5 : 0;
1816bf215546Sopenharmony_ci         break;
1817bf215546Sopenharmony_ci
1818bf215546Sopenharmony_ci      /* GL_ARB_texture_compression */
1819bf215546Sopenharmony_ci      case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1820bf215546Sopenharmony_ci         if (_mesa_is_format_compressed(texFormat) &&
1821bf215546Sopenharmony_ci             !_mesa_is_proxy_texture(target)) {
1822bf215546Sopenharmony_ci            *params = _mesa_format_image_size(texFormat, img->Width,
1823bf215546Sopenharmony_ci                                              img->Height, img->Depth);
1824bf215546Sopenharmony_ci         } else {
1825bf215546Sopenharmony_ci            _mesa_error(ctx, GL_INVALID_OPERATION,
1826bf215546Sopenharmony_ci                        "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1827bf215546Sopenharmony_ci                        _mesa_enum_to_string(pname));
1828bf215546Sopenharmony_ci         }
1829bf215546Sopenharmony_ci         break;
1830bf215546Sopenharmony_ci      case GL_TEXTURE_COMPRESSED:
1831bf215546Sopenharmony_ci         *params = (GLint) _mesa_is_format_compressed(texFormat);
1832bf215546Sopenharmony_ci         break;
1833bf215546Sopenharmony_ci
1834bf215546Sopenharmony_ci      /* GL_ARB_texture_float */
1835bf215546Sopenharmony_ci      case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1836bf215546Sopenharmony_ci      case GL_TEXTURE_INTENSITY_TYPE_ARB:
1837bf215546Sopenharmony_ci         if (ctx->API != API_OPENGL_COMPAT)
1838bf215546Sopenharmony_ci            goto invalid_pname;
1839bf215546Sopenharmony_ci         FALLTHROUGH;
1840bf215546Sopenharmony_ci      case GL_TEXTURE_RED_TYPE_ARB:
1841bf215546Sopenharmony_ci      case GL_TEXTURE_GREEN_TYPE_ARB:
1842bf215546Sopenharmony_ci      case GL_TEXTURE_BLUE_TYPE_ARB:
1843bf215546Sopenharmony_ci      case GL_TEXTURE_ALPHA_TYPE_ARB:
1844bf215546Sopenharmony_ci      case GL_TEXTURE_DEPTH_TYPE_ARB:
1845bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_texture_float)
1846bf215546Sopenharmony_ci            goto invalid_pname;
1847bf215546Sopenharmony_ci	 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
1848bf215546Sopenharmony_ci	    *params = _mesa_get_format_datatype(texFormat);
1849bf215546Sopenharmony_ci	 else
1850bf215546Sopenharmony_ci	    *params = GL_NONE;
1851bf215546Sopenharmony_ci         break;
1852bf215546Sopenharmony_ci
1853bf215546Sopenharmony_ci      /* GL_ARB_texture_multisample */
1854bf215546Sopenharmony_ci      case GL_TEXTURE_SAMPLES:
1855bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_texture_multisample)
1856bf215546Sopenharmony_ci            goto invalid_pname;
1857bf215546Sopenharmony_ci         *params = img->NumSamples;
1858bf215546Sopenharmony_ci         break;
1859bf215546Sopenharmony_ci
1860bf215546Sopenharmony_ci      case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1861bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_texture_multisample)
1862bf215546Sopenharmony_ci            goto invalid_pname;
1863bf215546Sopenharmony_ci         *params = img->FixedSampleLocations;
1864bf215546Sopenharmony_ci         break;
1865bf215546Sopenharmony_ci
1866bf215546Sopenharmony_ci      /* There is never a buffer data store here, but these pnames still have
1867bf215546Sopenharmony_ci       * to work.
1868bf215546Sopenharmony_ci       */
1869bf215546Sopenharmony_ci
1870bf215546Sopenharmony_ci      /* GL_ARB_texture_buffer_object */
1871bf215546Sopenharmony_ci      case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
1872bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_texture_buffer_object)
1873bf215546Sopenharmony_ci            goto invalid_pname;
1874bf215546Sopenharmony_ci         *params = 0;
1875bf215546Sopenharmony_ci         break;
1876bf215546Sopenharmony_ci
1877bf215546Sopenharmony_ci      /* GL_ARB_texture_buffer_range */
1878bf215546Sopenharmony_ci      case GL_TEXTURE_BUFFER_OFFSET:
1879bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_texture_buffer_range)
1880bf215546Sopenharmony_ci            goto invalid_pname;
1881bf215546Sopenharmony_ci         *params = 0;
1882bf215546Sopenharmony_ci         break;
1883bf215546Sopenharmony_ci      case GL_TEXTURE_BUFFER_SIZE:
1884bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_texture_buffer_range)
1885bf215546Sopenharmony_ci            goto invalid_pname;
1886bf215546Sopenharmony_ci         *params = 0;
1887bf215546Sopenharmony_ci         break;
1888bf215546Sopenharmony_ci
1889bf215546Sopenharmony_ci      default:
1890bf215546Sopenharmony_ci         goto invalid_pname;
1891bf215546Sopenharmony_ci   }
1892bf215546Sopenharmony_ci
1893bf215546Sopenharmony_ci   /* no error if we get here */
1894bf215546Sopenharmony_ci   return;
1895bf215546Sopenharmony_ci
1896bf215546Sopenharmony_ciinvalid_pname:
1897bf215546Sopenharmony_ci   _mesa_error(ctx, GL_INVALID_ENUM,
1898bf215546Sopenharmony_ci               "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
1899bf215546Sopenharmony_ci               _mesa_enum_to_string(pname));
1900bf215546Sopenharmony_ci}
1901bf215546Sopenharmony_ci
1902bf215546Sopenharmony_ci
1903bf215546Sopenharmony_ci/**
1904bf215546Sopenharmony_ci * Handle a glGetTexLevelParamteriv() call for a texture buffer.
1905bf215546Sopenharmony_ci */
1906bf215546Sopenharmony_cistatic void
1907bf215546Sopenharmony_ciget_tex_level_parameter_buffer(struct gl_context *ctx,
1908bf215546Sopenharmony_ci                               const struct gl_texture_object *texObj,
1909bf215546Sopenharmony_ci                               GLenum pname, GLint *params, bool dsa)
1910bf215546Sopenharmony_ci{
1911bf215546Sopenharmony_ci   const struct gl_buffer_object *bo = texObj->BufferObject;
1912bf215546Sopenharmony_ci   mesa_format texFormat = texObj->_BufferObjectFormat;
1913bf215546Sopenharmony_ci   int bytes = MAX2(1, _mesa_get_format_bytes(texFormat));
1914bf215546Sopenharmony_ci   GLenum internalFormat = texObj->BufferObjectFormat;
1915bf215546Sopenharmony_ci   GLenum baseFormat = _mesa_get_format_base_format(texFormat);
1916bf215546Sopenharmony_ci   const char *suffix = dsa ? "ture" : "";
1917bf215546Sopenharmony_ci
1918bf215546Sopenharmony_ci   assert(texObj->Target == GL_TEXTURE_BUFFER);
1919bf215546Sopenharmony_ci
1920bf215546Sopenharmony_ci   if (!bo) {
1921bf215546Sopenharmony_ci      /* undefined texture buffer object */
1922bf215546Sopenharmony_ci      switch (pname) {
1923bf215546Sopenharmony_ci      case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1924bf215546Sopenharmony_ci         *params = GL_TRUE;
1925bf215546Sopenharmony_ci         break;
1926bf215546Sopenharmony_ci      case GL_TEXTURE_INTERNAL_FORMAT:
1927bf215546Sopenharmony_ci         *params = internalFormat;
1928bf215546Sopenharmony_ci         break;
1929bf215546Sopenharmony_ci      default:
1930bf215546Sopenharmony_ci         *params = 0;
1931bf215546Sopenharmony_ci         break;
1932bf215546Sopenharmony_ci      }
1933bf215546Sopenharmony_ci      return;
1934bf215546Sopenharmony_ci   }
1935bf215546Sopenharmony_ci
1936bf215546Sopenharmony_ci   switch (pname) {
1937bf215546Sopenharmony_ci      case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
1938bf215546Sopenharmony_ci         *params = bo->Name;
1939bf215546Sopenharmony_ci         break;
1940bf215546Sopenharmony_ci      case GL_TEXTURE_WIDTH:
1941bf215546Sopenharmony_ci         *params = ((texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize)
1942bf215546Sopenharmony_ci            / bytes;
1943bf215546Sopenharmony_ci         break;
1944bf215546Sopenharmony_ci      case GL_TEXTURE_HEIGHT:
1945bf215546Sopenharmony_ci      case GL_TEXTURE_DEPTH:
1946bf215546Sopenharmony_ci         *params = 1;
1947bf215546Sopenharmony_ci         break;
1948bf215546Sopenharmony_ci      case GL_TEXTURE_BORDER:
1949bf215546Sopenharmony_ci      case GL_TEXTURE_SHARED_SIZE:
1950bf215546Sopenharmony_ci      case GL_TEXTURE_COMPRESSED:
1951bf215546Sopenharmony_ci         *params = 0;
1952bf215546Sopenharmony_ci         break;
1953bf215546Sopenharmony_ci      case GL_TEXTURE_INTERNAL_FORMAT:
1954bf215546Sopenharmony_ci         *params = internalFormat;
1955bf215546Sopenharmony_ci         break;
1956bf215546Sopenharmony_ci      case GL_TEXTURE_RED_SIZE:
1957bf215546Sopenharmony_ci      case GL_TEXTURE_GREEN_SIZE:
1958bf215546Sopenharmony_ci      case GL_TEXTURE_BLUE_SIZE:
1959bf215546Sopenharmony_ci      case GL_TEXTURE_ALPHA_SIZE:
1960bf215546Sopenharmony_ci         if (_mesa_base_format_has_channel(baseFormat, pname))
1961bf215546Sopenharmony_ci            *params = _mesa_get_format_bits(texFormat, pname);
1962bf215546Sopenharmony_ci         else
1963bf215546Sopenharmony_ci            *params = 0;
1964bf215546Sopenharmony_ci         break;
1965bf215546Sopenharmony_ci      case GL_TEXTURE_INTENSITY_SIZE:
1966bf215546Sopenharmony_ci      case GL_TEXTURE_LUMINANCE_SIZE:
1967bf215546Sopenharmony_ci         if (_mesa_base_format_has_channel(baseFormat, pname)) {
1968bf215546Sopenharmony_ci            *params = _mesa_get_format_bits(texFormat, pname);
1969bf215546Sopenharmony_ci            if (*params == 0) {
1970bf215546Sopenharmony_ci               /* intensity or luminance is probably stored as RGB[A] */
1971bf215546Sopenharmony_ci               *params = MIN2(_mesa_get_format_bits(texFormat,
1972bf215546Sopenharmony_ci                                                    GL_TEXTURE_RED_SIZE),
1973bf215546Sopenharmony_ci                              _mesa_get_format_bits(texFormat,
1974bf215546Sopenharmony_ci                                                    GL_TEXTURE_GREEN_SIZE));
1975bf215546Sopenharmony_ci            }
1976bf215546Sopenharmony_ci         } else {
1977bf215546Sopenharmony_ci            *params = 0;
1978bf215546Sopenharmony_ci         }
1979bf215546Sopenharmony_ci         break;
1980bf215546Sopenharmony_ci      case GL_TEXTURE_DEPTH_SIZE_ARB:
1981bf215546Sopenharmony_ci      case GL_TEXTURE_STENCIL_SIZE_EXT:
1982bf215546Sopenharmony_ci         *params = _mesa_get_format_bits(texFormat, pname);
1983bf215546Sopenharmony_ci         break;
1984bf215546Sopenharmony_ci
1985bf215546Sopenharmony_ci      /* GL_ARB_texture_buffer_range */
1986bf215546Sopenharmony_ci      case GL_TEXTURE_BUFFER_OFFSET:
1987bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_texture_buffer_range)
1988bf215546Sopenharmony_ci            goto invalid_pname;
1989bf215546Sopenharmony_ci         *params = texObj->BufferOffset;
1990bf215546Sopenharmony_ci         break;
1991bf215546Sopenharmony_ci      case GL_TEXTURE_BUFFER_SIZE:
1992bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_texture_buffer_range)
1993bf215546Sopenharmony_ci            goto invalid_pname;
1994bf215546Sopenharmony_ci         *params = (texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize;
1995bf215546Sopenharmony_ci         break;
1996bf215546Sopenharmony_ci
1997bf215546Sopenharmony_ci      /* GL_ARB_texture_multisample */
1998bf215546Sopenharmony_ci      case GL_TEXTURE_SAMPLES:
1999bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_texture_multisample)
2000bf215546Sopenharmony_ci            goto invalid_pname;
2001bf215546Sopenharmony_ci         *params = 0;
2002bf215546Sopenharmony_ci         break;
2003bf215546Sopenharmony_ci
2004bf215546Sopenharmony_ci      case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
2005bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_texture_multisample)
2006bf215546Sopenharmony_ci            goto invalid_pname;
2007bf215546Sopenharmony_ci         *params = GL_TRUE;
2008bf215546Sopenharmony_ci         break;
2009bf215546Sopenharmony_ci
2010bf215546Sopenharmony_ci      /* GL_ARB_texture_compression */
2011bf215546Sopenharmony_ci      case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
2012bf215546Sopenharmony_ci         /* Always illegal for GL_TEXTURE_BUFFER */
2013bf215546Sopenharmony_ci         _mesa_error(ctx, GL_INVALID_OPERATION,
2014bf215546Sopenharmony_ci                     "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
2015bf215546Sopenharmony_ci                     _mesa_enum_to_string(pname));
2016bf215546Sopenharmony_ci         break;
2017bf215546Sopenharmony_ci
2018bf215546Sopenharmony_ci      /* GL_ARB_texture_float */
2019bf215546Sopenharmony_ci      case GL_TEXTURE_RED_TYPE_ARB:
2020bf215546Sopenharmony_ci      case GL_TEXTURE_GREEN_TYPE_ARB:
2021bf215546Sopenharmony_ci      case GL_TEXTURE_BLUE_TYPE_ARB:
2022bf215546Sopenharmony_ci      case GL_TEXTURE_ALPHA_TYPE_ARB:
2023bf215546Sopenharmony_ci      case GL_TEXTURE_LUMINANCE_TYPE_ARB:
2024bf215546Sopenharmony_ci      case GL_TEXTURE_INTENSITY_TYPE_ARB:
2025bf215546Sopenharmony_ci      case GL_TEXTURE_DEPTH_TYPE_ARB:
2026bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_texture_float)
2027bf215546Sopenharmony_ci            goto invalid_pname;
2028bf215546Sopenharmony_ci         if (_mesa_base_format_has_channel(baseFormat, pname))
2029bf215546Sopenharmony_ci            *params = _mesa_get_format_datatype(texFormat);
2030bf215546Sopenharmony_ci         else
2031bf215546Sopenharmony_ci            *params = GL_NONE;
2032bf215546Sopenharmony_ci         break;
2033bf215546Sopenharmony_ci
2034bf215546Sopenharmony_ci      default:
2035bf215546Sopenharmony_ci         goto invalid_pname;
2036bf215546Sopenharmony_ci   }
2037bf215546Sopenharmony_ci
2038bf215546Sopenharmony_ci   /* no error if we get here */
2039bf215546Sopenharmony_ci   return;
2040bf215546Sopenharmony_ci
2041bf215546Sopenharmony_ciinvalid_pname:
2042bf215546Sopenharmony_ci   _mesa_error(ctx, GL_INVALID_ENUM,
2043bf215546Sopenharmony_ci               "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
2044bf215546Sopenharmony_ci               _mesa_enum_to_string(pname));
2045bf215546Sopenharmony_ci}
2046bf215546Sopenharmony_ci
2047bf215546Sopenharmony_cistatic bool
2048bf215546Sopenharmony_civalid_tex_level_parameteriv_target(struct gl_context *ctx, GLenum target,
2049bf215546Sopenharmony_ci                                   bool dsa)
2050bf215546Sopenharmony_ci{
2051bf215546Sopenharmony_ci   const char *suffix = dsa ? "ture" : "";
2052bf215546Sopenharmony_ci   if (!_mesa_legal_get_tex_level_parameter_target(ctx, target, dsa)) {
2053bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_ENUM,
2054bf215546Sopenharmony_ci                  "glGetTex%sLevelParameter[if]v(target=%s)", suffix,
2055bf215546Sopenharmony_ci                  _mesa_enum_to_string(target));
2056bf215546Sopenharmony_ci      return false;
2057bf215546Sopenharmony_ci   }
2058bf215546Sopenharmony_ci   return true;
2059bf215546Sopenharmony_ci}
2060bf215546Sopenharmony_ci
2061bf215546Sopenharmony_ci/**
2062bf215546Sopenharmony_ci * This isn't exposed to the rest of the driver because it is a part of the
2063bf215546Sopenharmony_ci * OpenGL API that is rarely used.
2064bf215546Sopenharmony_ci */
2065bf215546Sopenharmony_cistatic void
2066bf215546Sopenharmony_ciget_tex_level_parameteriv(struct gl_context *ctx,
2067bf215546Sopenharmony_ci                          struct gl_texture_object *texObj,
2068bf215546Sopenharmony_ci                          GLenum target, GLint level,
2069bf215546Sopenharmony_ci                          GLenum pname, GLint *params,
2070bf215546Sopenharmony_ci                          bool dsa)
2071bf215546Sopenharmony_ci{
2072bf215546Sopenharmony_ci   GLint maxLevels;
2073bf215546Sopenharmony_ci   const char *suffix = dsa ? "ture" : "";
2074bf215546Sopenharmony_ci
2075bf215546Sopenharmony_ci   /* Check for errors */
2076bf215546Sopenharmony_ci   if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
2077bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION,
2078bf215546Sopenharmony_ci                  "glGetTex%sLevelParameter[if]v("
2079bf215546Sopenharmony_ci                  "current unit >= max combined texture units)", suffix);
2080bf215546Sopenharmony_ci      return;
2081bf215546Sopenharmony_ci   }
2082bf215546Sopenharmony_ci
2083bf215546Sopenharmony_ci   maxLevels = _mesa_max_texture_levels(ctx, target);
2084bf215546Sopenharmony_ci   assert(maxLevels != 0);
2085bf215546Sopenharmony_ci
2086bf215546Sopenharmony_ci   if (level < 0 || level >= maxLevels) {
2087bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_VALUE,
2088bf215546Sopenharmony_ci                  "glGetTex%sLevelParameter[if]v(level out of range)", suffix);
2089bf215546Sopenharmony_ci      return;
2090bf215546Sopenharmony_ci   }
2091bf215546Sopenharmony_ci
2092bf215546Sopenharmony_ci   /* Get the level parameter */
2093bf215546Sopenharmony_ci   if (target == GL_TEXTURE_BUFFER) {
2094bf215546Sopenharmony_ci      get_tex_level_parameter_buffer(ctx, texObj, pname, params, dsa);
2095bf215546Sopenharmony_ci   }
2096bf215546Sopenharmony_ci   else {
2097bf215546Sopenharmony_ci      get_tex_level_parameter_image(ctx, texObj, target,
2098bf215546Sopenharmony_ci                                    level, pname, params, dsa);
2099bf215546Sopenharmony_ci   }
2100bf215546Sopenharmony_ci}
2101bf215546Sopenharmony_ci
2102bf215546Sopenharmony_civoid GLAPIENTRY
2103bf215546Sopenharmony_ci_mesa_GetTexLevelParameterfv( GLenum target, GLint level,
2104bf215546Sopenharmony_ci                              GLenum pname, GLfloat *params )
2105bf215546Sopenharmony_ci{
2106bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
2107bf215546Sopenharmony_ci   GLint iparam;
2108bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2109bf215546Sopenharmony_ci
2110bf215546Sopenharmony_ci   if (!valid_tex_level_parameteriv_target(ctx, target, false))
2111bf215546Sopenharmony_ci      return;
2112bf215546Sopenharmony_ci
2113bf215546Sopenharmony_ci   texObj = _mesa_get_current_tex_object(ctx, target);
2114bf215546Sopenharmony_ci   if (!texObj)
2115bf215546Sopenharmony_ci      return;
2116bf215546Sopenharmony_ci
2117bf215546Sopenharmony_ci   get_tex_level_parameteriv(ctx, texObj, target, level,
2118bf215546Sopenharmony_ci                             pname, &iparam, false);
2119bf215546Sopenharmony_ci
2120bf215546Sopenharmony_ci   *params = (GLfloat) iparam;
2121bf215546Sopenharmony_ci}
2122bf215546Sopenharmony_ci
2123bf215546Sopenharmony_civoid GLAPIENTRY
2124bf215546Sopenharmony_ci_mesa_GetTexLevelParameteriv( GLenum target, GLint level,
2125bf215546Sopenharmony_ci                              GLenum pname, GLint *params )
2126bf215546Sopenharmony_ci{
2127bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
2128bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2129bf215546Sopenharmony_ci
2130bf215546Sopenharmony_ci   if (!valid_tex_level_parameteriv_target(ctx, target, false))
2131bf215546Sopenharmony_ci      return;
2132bf215546Sopenharmony_ci
2133bf215546Sopenharmony_ci   texObj = _mesa_get_current_tex_object(ctx, target);
2134bf215546Sopenharmony_ci   if (!texObj)
2135bf215546Sopenharmony_ci      return;
2136bf215546Sopenharmony_ci
2137bf215546Sopenharmony_ci   get_tex_level_parameteriv(ctx, texObj, target, level,
2138bf215546Sopenharmony_ci                             pname, params, false);
2139bf215546Sopenharmony_ci}
2140bf215546Sopenharmony_ci
2141bf215546Sopenharmony_civoid GLAPIENTRY
2142bf215546Sopenharmony_ci_mesa_GetTextureLevelParameterfv(GLuint texture, GLint level,
2143bf215546Sopenharmony_ci                                 GLenum pname, GLfloat *params)
2144bf215546Sopenharmony_ci{
2145bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
2146bf215546Sopenharmony_ci   GLint iparam;
2147bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2148bf215546Sopenharmony_ci
2149bf215546Sopenharmony_ci   texObj = _mesa_lookup_texture_err(ctx, texture,
2150bf215546Sopenharmony_ci                                     "glGetTextureLevelParameterfv");
2151bf215546Sopenharmony_ci   if (!texObj)
2152bf215546Sopenharmony_ci      return;
2153bf215546Sopenharmony_ci
2154bf215546Sopenharmony_ci   if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2155bf215546Sopenharmony_ci      return;
2156bf215546Sopenharmony_ci
2157bf215546Sopenharmony_ci   get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2158bf215546Sopenharmony_ci                             pname, &iparam, true);
2159bf215546Sopenharmony_ci
2160bf215546Sopenharmony_ci   *params = (GLfloat) iparam;
2161bf215546Sopenharmony_ci}
2162bf215546Sopenharmony_ci
2163bf215546Sopenharmony_civoid GLAPIENTRY
2164bf215546Sopenharmony_ci_mesa_GetTextureLevelParameterfvEXT(GLuint texture, GLenum target, GLint level,
2165bf215546Sopenharmony_ci                                    GLenum pname, GLfloat *params)
2166bf215546Sopenharmony_ci{
2167bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
2168bf215546Sopenharmony_ci   GLint iparam;
2169bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2170bf215546Sopenharmony_ci
2171bf215546Sopenharmony_ci   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2172bf215546Sopenharmony_ci                                           "glGetTextureLevelParameterfvEXT");
2173bf215546Sopenharmony_ci   if (!texObj)
2174bf215546Sopenharmony_ci      return;
2175bf215546Sopenharmony_ci
2176bf215546Sopenharmony_ci   if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2177bf215546Sopenharmony_ci      return;
2178bf215546Sopenharmony_ci
2179bf215546Sopenharmony_ci   get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2180bf215546Sopenharmony_ci                             pname, &iparam, true);
2181bf215546Sopenharmony_ci
2182bf215546Sopenharmony_ci   *params = (GLfloat) iparam;
2183bf215546Sopenharmony_ci}
2184bf215546Sopenharmony_ci
2185bf215546Sopenharmony_civoid GLAPIENTRY
2186bf215546Sopenharmony_ci_mesa_GetMultiTexLevelParameterfvEXT(GLenum texunit, GLenum target, GLint level,
2187bf215546Sopenharmony_ci                                     GLenum pname, GLfloat *params)
2188bf215546Sopenharmony_ci{
2189bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
2190bf215546Sopenharmony_ci   GLint iparam;
2191bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2192bf215546Sopenharmony_ci
2193bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2194bf215546Sopenharmony_ci                                                   texunit - GL_TEXTURE0,
2195bf215546Sopenharmony_ci                                                   true,
2196bf215546Sopenharmony_ci                                                   "glGetMultiTexLevelParameterfvEXT");
2197bf215546Sopenharmony_ci   if (!texObj)
2198bf215546Sopenharmony_ci      return;
2199bf215546Sopenharmony_ci
2200bf215546Sopenharmony_ci   if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2201bf215546Sopenharmony_ci      return;
2202bf215546Sopenharmony_ci
2203bf215546Sopenharmony_ci   get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2204bf215546Sopenharmony_ci                             pname, &iparam, true);
2205bf215546Sopenharmony_ci
2206bf215546Sopenharmony_ci   *params = (GLfloat) iparam;
2207bf215546Sopenharmony_ci}
2208bf215546Sopenharmony_ci
2209bf215546Sopenharmony_civoid GLAPIENTRY
2210bf215546Sopenharmony_ci_mesa_GetTextureLevelParameteriv(GLuint texture, GLint level,
2211bf215546Sopenharmony_ci                                 GLenum pname, GLint *params)
2212bf215546Sopenharmony_ci{
2213bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
2214bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2215bf215546Sopenharmony_ci
2216bf215546Sopenharmony_ci   texObj = _mesa_lookup_texture_err(ctx, texture,
2217bf215546Sopenharmony_ci                                     "glGetTextureLevelParameteriv");
2218bf215546Sopenharmony_ci   if (!texObj)
2219bf215546Sopenharmony_ci      return;
2220bf215546Sopenharmony_ci
2221bf215546Sopenharmony_ci   if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2222bf215546Sopenharmony_ci      return;
2223bf215546Sopenharmony_ci
2224bf215546Sopenharmony_ci   get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2225bf215546Sopenharmony_ci                             pname, params, true);
2226bf215546Sopenharmony_ci}
2227bf215546Sopenharmony_ci
2228bf215546Sopenharmony_civoid GLAPIENTRY
2229bf215546Sopenharmony_ci_mesa_GetTextureLevelParameterivEXT(GLuint texture, GLenum target, GLint level,
2230bf215546Sopenharmony_ci                                    GLenum pname, GLint *params)
2231bf215546Sopenharmony_ci{
2232bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
2233bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2234bf215546Sopenharmony_ci
2235bf215546Sopenharmony_ci   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2236bf215546Sopenharmony_ci                                           "glGetTextureLevelParameterivEXT");
2237bf215546Sopenharmony_ci   if (!texObj)
2238bf215546Sopenharmony_ci      return;
2239bf215546Sopenharmony_ci
2240bf215546Sopenharmony_ci   if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2241bf215546Sopenharmony_ci      return;
2242bf215546Sopenharmony_ci
2243bf215546Sopenharmony_ci   get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2244bf215546Sopenharmony_ci                             pname, params, true);
2245bf215546Sopenharmony_ci}
2246bf215546Sopenharmony_ci
2247bf215546Sopenharmony_civoid GLAPIENTRY
2248bf215546Sopenharmony_ci_mesa_GetMultiTexLevelParameterivEXT(GLenum texunit, GLenum target, GLint level,
2249bf215546Sopenharmony_ci                                     GLenum pname, GLint *params)
2250bf215546Sopenharmony_ci{
2251bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
2252bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2253bf215546Sopenharmony_ci
2254bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2255bf215546Sopenharmony_ci                                                   texunit - GL_TEXTURE0,
2256bf215546Sopenharmony_ci                                                   true,
2257bf215546Sopenharmony_ci                                                   "glGetMultiTexLevelParameterivEXT");
2258bf215546Sopenharmony_ci   if (!texObj)
2259bf215546Sopenharmony_ci      return;
2260bf215546Sopenharmony_ci
2261bf215546Sopenharmony_ci   if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
2262bf215546Sopenharmony_ci      return;
2263bf215546Sopenharmony_ci
2264bf215546Sopenharmony_ci   get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
2265bf215546Sopenharmony_ci                             pname, params, true);
2266bf215546Sopenharmony_ci}
2267bf215546Sopenharmony_ci
2268bf215546Sopenharmony_ci
2269bf215546Sopenharmony_ci/**
2270bf215546Sopenharmony_ci * This isn't exposed to the rest of the driver because it is a part of the
2271bf215546Sopenharmony_ci * OpenGL API that is rarely used.
2272bf215546Sopenharmony_ci */
2273bf215546Sopenharmony_cistatic void
2274bf215546Sopenharmony_ciget_tex_parameterfv(struct gl_context *ctx,
2275bf215546Sopenharmony_ci                    struct gl_texture_object *obj,
2276bf215546Sopenharmony_ci                    GLenum pname, GLfloat *params, bool dsa)
2277bf215546Sopenharmony_ci{
2278bf215546Sopenharmony_ci   _mesa_lock_context_textures(ctx);
2279bf215546Sopenharmony_ci   switch (pname) {
2280bf215546Sopenharmony_ci      case GL_TEXTURE_MAG_FILTER:
2281bf215546Sopenharmony_ci	 *params = ENUM_TO_FLOAT(obj->Sampler.Attrib.MagFilter);
2282bf215546Sopenharmony_ci	 break;
2283bf215546Sopenharmony_ci      case GL_TEXTURE_MIN_FILTER:
2284bf215546Sopenharmony_ci         *params = ENUM_TO_FLOAT(obj->Sampler.Attrib.MinFilter);
2285bf215546Sopenharmony_ci         break;
2286bf215546Sopenharmony_ci      case GL_TEXTURE_WRAP_S:
2287bf215546Sopenharmony_ci         *params = ENUM_TO_FLOAT(obj->Sampler.Attrib.WrapS);
2288bf215546Sopenharmony_ci         break;
2289bf215546Sopenharmony_ci      case GL_TEXTURE_WRAP_T:
2290bf215546Sopenharmony_ci         *params = ENUM_TO_FLOAT(obj->Sampler.Attrib.WrapT);
2291bf215546Sopenharmony_ci         break;
2292bf215546Sopenharmony_ci      case GL_TEXTURE_WRAP_R:
2293bf215546Sopenharmony_ci         *params = ENUM_TO_FLOAT(obj->Sampler.Attrib.WrapR);
2294bf215546Sopenharmony_ci         break;
2295bf215546Sopenharmony_ci      case GL_TEXTURE_BORDER_COLOR:
2296bf215546Sopenharmony_ci         if (ctx->API == API_OPENGLES)
2297bf215546Sopenharmony_ci            goto invalid_pname;
2298bf215546Sopenharmony_ci
2299bf215546Sopenharmony_ci         if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer)) {
2300bf215546Sopenharmony_ci            params[0] = CLAMP(obj->Sampler.Attrib.state.border_color.f[0], 0.0F, 1.0F);
2301bf215546Sopenharmony_ci            params[1] = CLAMP(obj->Sampler.Attrib.state.border_color.f[1], 0.0F, 1.0F);
2302bf215546Sopenharmony_ci            params[2] = CLAMP(obj->Sampler.Attrib.state.border_color.f[2], 0.0F, 1.0F);
2303bf215546Sopenharmony_ci            params[3] = CLAMP(obj->Sampler.Attrib.state.border_color.f[3], 0.0F, 1.0F);
2304bf215546Sopenharmony_ci         }
2305bf215546Sopenharmony_ci         else {
2306bf215546Sopenharmony_ci            params[0] = obj->Sampler.Attrib.state.border_color.f[0];
2307bf215546Sopenharmony_ci            params[1] = obj->Sampler.Attrib.state.border_color.f[1];
2308bf215546Sopenharmony_ci            params[2] = obj->Sampler.Attrib.state.border_color.f[2];
2309bf215546Sopenharmony_ci            params[3] = obj->Sampler.Attrib.state.border_color.f[3];
2310bf215546Sopenharmony_ci         }
2311bf215546Sopenharmony_ci         break;
2312bf215546Sopenharmony_ci      case GL_TEXTURE_RESIDENT:
2313bf215546Sopenharmony_ci         if (ctx->API != API_OPENGL_COMPAT)
2314bf215546Sopenharmony_ci            goto invalid_pname;
2315bf215546Sopenharmony_ci
2316bf215546Sopenharmony_ci         *params = 1.0F;
2317bf215546Sopenharmony_ci         break;
2318bf215546Sopenharmony_ci      case GL_TEXTURE_PRIORITY:
2319bf215546Sopenharmony_ci         if (ctx->API != API_OPENGL_COMPAT)
2320bf215546Sopenharmony_ci            goto invalid_pname;
2321bf215546Sopenharmony_ci
2322bf215546Sopenharmony_ci         *params = obj->Attrib.Priority;
2323bf215546Sopenharmony_ci         break;
2324bf215546Sopenharmony_ci      case GL_TEXTURE_MIN_LOD:
2325bf215546Sopenharmony_ci         if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2326bf215546Sopenharmony_ci            goto invalid_pname;
2327bf215546Sopenharmony_ci
2328bf215546Sopenharmony_ci         *params = obj->Sampler.Attrib.MinLod;
2329bf215546Sopenharmony_ci         break;
2330bf215546Sopenharmony_ci      case GL_TEXTURE_MAX_LOD:
2331bf215546Sopenharmony_ci         if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2332bf215546Sopenharmony_ci            goto invalid_pname;
2333bf215546Sopenharmony_ci
2334bf215546Sopenharmony_ci         *params = obj->Sampler.Attrib.MaxLod;
2335bf215546Sopenharmony_ci         break;
2336bf215546Sopenharmony_ci      case GL_TEXTURE_BASE_LEVEL:
2337bf215546Sopenharmony_ci         if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2338bf215546Sopenharmony_ci            goto invalid_pname;
2339bf215546Sopenharmony_ci
2340bf215546Sopenharmony_ci         *params = (GLfloat) obj->Attrib.BaseLevel;
2341bf215546Sopenharmony_ci         break;
2342bf215546Sopenharmony_ci      case GL_TEXTURE_MAX_LEVEL:
2343bf215546Sopenharmony_ci         *params = (GLfloat) obj->Attrib.MaxLevel;
2344bf215546Sopenharmony_ci         break;
2345bf215546Sopenharmony_ci      case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2346bf215546Sopenharmony_ci         if (!ctx->Extensions.EXT_texture_filter_anisotropic)
2347bf215546Sopenharmony_ci            goto invalid_pname;
2348bf215546Sopenharmony_ci         *params = obj->Sampler.Attrib.MaxAnisotropy;
2349bf215546Sopenharmony_ci         break;
2350bf215546Sopenharmony_ci      case GL_GENERATE_MIPMAP_SGIS:
2351bf215546Sopenharmony_ci         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
2352bf215546Sopenharmony_ci            goto invalid_pname;
2353bf215546Sopenharmony_ci
2354bf215546Sopenharmony_ci	 *params = (GLfloat) obj->Attrib.GenerateMipmap;
2355bf215546Sopenharmony_ci         break;
2356bf215546Sopenharmony_ci      case GL_TEXTURE_COMPARE_MODE_ARB:
2357bf215546Sopenharmony_ci         if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2358bf215546Sopenharmony_ci             && !_mesa_is_gles3(ctx))
2359bf215546Sopenharmony_ci            goto invalid_pname;
2360bf215546Sopenharmony_ci         *params = (GLfloat) obj->Sampler.Attrib.CompareMode;
2361bf215546Sopenharmony_ci         break;
2362bf215546Sopenharmony_ci      case GL_TEXTURE_COMPARE_FUNC_ARB:
2363bf215546Sopenharmony_ci         if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2364bf215546Sopenharmony_ci             && !_mesa_is_gles3(ctx))
2365bf215546Sopenharmony_ci            goto invalid_pname;
2366bf215546Sopenharmony_ci         *params = (GLfloat) obj->Sampler.Attrib.CompareFunc;
2367bf215546Sopenharmony_ci         break;
2368bf215546Sopenharmony_ci      case GL_DEPTH_TEXTURE_MODE_ARB:
2369bf215546Sopenharmony_ci         /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
2370bf215546Sopenharmony_ci          * never existed in OpenGL ES.
2371bf215546Sopenharmony_ci          */
2372bf215546Sopenharmony_ci         if (ctx->API != API_OPENGL_COMPAT)
2373bf215546Sopenharmony_ci            goto invalid_pname;
2374bf215546Sopenharmony_ci         *params = (GLfloat) obj->Attrib.DepthMode;
2375bf215546Sopenharmony_ci         break;
2376bf215546Sopenharmony_ci      case GL_DEPTH_STENCIL_TEXTURE_MODE:
2377bf215546Sopenharmony_ci         if (!_mesa_has_ARB_stencil_texturing(ctx) && !_mesa_is_gles31(ctx))
2378bf215546Sopenharmony_ci            goto invalid_pname;
2379bf215546Sopenharmony_ci         *params = (GLfloat)
2380bf215546Sopenharmony_ci            (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
2381bf215546Sopenharmony_ci         break;
2382bf215546Sopenharmony_ci      case GL_TEXTURE_LOD_BIAS:
2383bf215546Sopenharmony_ci         if (_mesa_is_gles(ctx))
2384bf215546Sopenharmony_ci            goto invalid_pname;
2385bf215546Sopenharmony_ci
2386bf215546Sopenharmony_ci         *params = obj->Sampler.Attrib.LodBias;
2387bf215546Sopenharmony_ci         break;
2388bf215546Sopenharmony_ci      case GL_TEXTURE_CROP_RECT_OES:
2389bf215546Sopenharmony_ci         if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
2390bf215546Sopenharmony_ci            goto invalid_pname;
2391bf215546Sopenharmony_ci
2392bf215546Sopenharmony_ci         params[0] = (GLfloat) obj->CropRect[0];
2393bf215546Sopenharmony_ci         params[1] = (GLfloat) obj->CropRect[1];
2394bf215546Sopenharmony_ci         params[2] = (GLfloat) obj->CropRect[2];
2395bf215546Sopenharmony_ci         params[3] = (GLfloat) obj->CropRect[3];
2396bf215546Sopenharmony_ci         break;
2397bf215546Sopenharmony_ci
2398bf215546Sopenharmony_ci      case GL_TEXTURE_SWIZZLE_R_EXT:
2399bf215546Sopenharmony_ci      case GL_TEXTURE_SWIZZLE_G_EXT:
2400bf215546Sopenharmony_ci      case GL_TEXTURE_SWIZZLE_B_EXT:
2401bf215546Sopenharmony_ci      case GL_TEXTURE_SWIZZLE_A_EXT:
2402bf215546Sopenharmony_ci         if ((!_mesa_is_desktop_gl(ctx)
2403bf215546Sopenharmony_ci              || !ctx->Extensions.EXT_texture_swizzle)
2404bf215546Sopenharmony_ci             && !_mesa_is_gles3(ctx))
2405bf215546Sopenharmony_ci            goto invalid_pname;
2406bf215546Sopenharmony_ci         *params = (GLfloat) obj->Attrib.Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
2407bf215546Sopenharmony_ci         break;
2408bf215546Sopenharmony_ci
2409bf215546Sopenharmony_ci      case GL_TEXTURE_SWIZZLE_RGBA_EXT:
2410bf215546Sopenharmony_ci         if ((!_mesa_is_desktop_gl(ctx)
2411bf215546Sopenharmony_ci              || !ctx->Extensions.EXT_texture_swizzle)
2412bf215546Sopenharmony_ci             && !_mesa_is_gles3(ctx)) {
2413bf215546Sopenharmony_ci            goto invalid_pname;
2414bf215546Sopenharmony_ci         }
2415bf215546Sopenharmony_ci         else {
2416bf215546Sopenharmony_ci            GLuint comp;
2417bf215546Sopenharmony_ci            for (comp = 0; comp < 4; comp++) {
2418bf215546Sopenharmony_ci               params[comp] = (GLfloat) obj->Attrib.Swizzle[comp];
2419bf215546Sopenharmony_ci            }
2420bf215546Sopenharmony_ci         }
2421bf215546Sopenharmony_ci         break;
2422bf215546Sopenharmony_ci
2423bf215546Sopenharmony_ci      case GL_TEXTURE_CUBE_MAP_SEAMLESS:
2424bf215546Sopenharmony_ci         if (!_mesa_is_desktop_gl(ctx)
2425bf215546Sopenharmony_ci             || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
2426bf215546Sopenharmony_ci            goto invalid_pname;
2427bf215546Sopenharmony_ci         *params = (GLfloat) obj->Sampler.Attrib.CubeMapSeamless;
2428bf215546Sopenharmony_ci         break;
2429bf215546Sopenharmony_ci
2430bf215546Sopenharmony_ci      case GL_TEXTURE_IMMUTABLE_FORMAT:
2431bf215546Sopenharmony_ci         *params = (GLfloat) obj->Immutable;
2432bf215546Sopenharmony_ci         break;
2433bf215546Sopenharmony_ci
2434bf215546Sopenharmony_ci      case GL_TEXTURE_IMMUTABLE_LEVELS:
2435bf215546Sopenharmony_ci         if (_mesa_is_gles3(ctx) || _mesa_has_texture_view(ctx))
2436bf215546Sopenharmony_ci            *params = (GLfloat) obj->Attrib.ImmutableLevels;
2437bf215546Sopenharmony_ci         else
2438bf215546Sopenharmony_ci            goto invalid_pname;
2439bf215546Sopenharmony_ci         break;
2440bf215546Sopenharmony_ci
2441bf215546Sopenharmony_ci      case GL_TEXTURE_VIEW_MIN_LEVEL:
2442bf215546Sopenharmony_ci         if (!_mesa_has_texture_view(ctx))
2443bf215546Sopenharmony_ci            goto invalid_pname;
2444bf215546Sopenharmony_ci         *params = (GLfloat) obj->Attrib.MinLevel;
2445bf215546Sopenharmony_ci         break;
2446bf215546Sopenharmony_ci
2447bf215546Sopenharmony_ci      case GL_TEXTURE_VIEW_NUM_LEVELS:
2448bf215546Sopenharmony_ci         if (!_mesa_has_texture_view(ctx))
2449bf215546Sopenharmony_ci            goto invalid_pname;
2450bf215546Sopenharmony_ci         *params = (GLfloat) obj->Attrib.NumLevels;
2451bf215546Sopenharmony_ci         break;
2452bf215546Sopenharmony_ci
2453bf215546Sopenharmony_ci      case GL_TEXTURE_VIEW_MIN_LAYER:
2454bf215546Sopenharmony_ci         if (!_mesa_has_texture_view(ctx))
2455bf215546Sopenharmony_ci            goto invalid_pname;
2456bf215546Sopenharmony_ci         *params = (GLfloat) obj->Attrib.MinLayer;
2457bf215546Sopenharmony_ci         break;
2458bf215546Sopenharmony_ci
2459bf215546Sopenharmony_ci      case GL_TEXTURE_VIEW_NUM_LAYERS:
2460bf215546Sopenharmony_ci         if (!_mesa_has_texture_view(ctx))
2461bf215546Sopenharmony_ci            goto invalid_pname;
2462bf215546Sopenharmony_ci         *params = (GLfloat) obj->Attrib.NumLayers;
2463bf215546Sopenharmony_ci         break;
2464bf215546Sopenharmony_ci
2465bf215546Sopenharmony_ci      case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
2466bf215546Sopenharmony_ci         if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
2467bf215546Sopenharmony_ci            goto invalid_pname;
2468bf215546Sopenharmony_ci         *params = (GLfloat) obj->RequiredTextureImageUnits;
2469bf215546Sopenharmony_ci         break;
2470bf215546Sopenharmony_ci
2471bf215546Sopenharmony_ci      case GL_TEXTURE_SRGB_DECODE_EXT:
2472bf215546Sopenharmony_ci         if (!ctx->Extensions.EXT_texture_sRGB_decode)
2473bf215546Sopenharmony_ci            goto invalid_pname;
2474bf215546Sopenharmony_ci         *params = (GLfloat) obj->Sampler.Attrib.sRGBDecode;
2475bf215546Sopenharmony_ci         break;
2476bf215546Sopenharmony_ci
2477bf215546Sopenharmony_ci      case GL_TEXTURE_REDUCTION_MODE_EXT:
2478bf215546Sopenharmony_ci         if (!ctx->Extensions.EXT_texture_filter_minmax &&
2479bf215546Sopenharmony_ci             !_mesa_has_ARB_texture_filter_minmax(ctx))
2480bf215546Sopenharmony_ci            goto invalid_pname;
2481bf215546Sopenharmony_ci         *params = (GLfloat) obj->Sampler.Attrib.ReductionMode;
2482bf215546Sopenharmony_ci         break;
2483bf215546Sopenharmony_ci
2484bf215546Sopenharmony_ci      case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
2485bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_shader_image_load_store &&
2486bf215546Sopenharmony_ci             !_mesa_is_gles31(ctx))
2487bf215546Sopenharmony_ci            goto invalid_pname;
2488bf215546Sopenharmony_ci         *params = (GLfloat) obj->Attrib.ImageFormatCompatibilityType;
2489bf215546Sopenharmony_ci         break;
2490bf215546Sopenharmony_ci
2491bf215546Sopenharmony_ci      case GL_TEXTURE_TARGET:
2492bf215546Sopenharmony_ci         if (ctx->API != API_OPENGL_CORE)
2493bf215546Sopenharmony_ci            goto invalid_pname;
2494bf215546Sopenharmony_ci         *params = ENUM_TO_FLOAT(obj->Target);
2495bf215546Sopenharmony_ci         break;
2496bf215546Sopenharmony_ci
2497bf215546Sopenharmony_ci      case GL_TEXTURE_TILING_EXT:
2498bf215546Sopenharmony_ci         if (!ctx->Extensions.EXT_memory_object)
2499bf215546Sopenharmony_ci            goto invalid_pname;
2500bf215546Sopenharmony_ci         *params = ENUM_TO_FLOAT(obj->TextureTiling);
2501bf215546Sopenharmony_ci         break;
2502bf215546Sopenharmony_ci
2503bf215546Sopenharmony_ci      case GL_TEXTURE_SPARSE_ARB:
2504bf215546Sopenharmony_ci         if (!_mesa_has_ARB_sparse_texture(ctx))
2505bf215546Sopenharmony_ci            goto invalid_pname;
2506bf215546Sopenharmony_ci         *params = (GLfloat) obj->IsSparse;
2507bf215546Sopenharmony_ci         break;
2508bf215546Sopenharmony_ci
2509bf215546Sopenharmony_ci      case GL_VIRTUAL_PAGE_SIZE_INDEX_ARB:
2510bf215546Sopenharmony_ci         if (!_mesa_has_ARB_sparse_texture(ctx))
2511bf215546Sopenharmony_ci            goto invalid_pname;
2512bf215546Sopenharmony_ci         *params = (GLfloat) obj->VirtualPageSizeIndex;
2513bf215546Sopenharmony_ci         break;
2514bf215546Sopenharmony_ci
2515bf215546Sopenharmony_ci      case GL_NUM_SPARSE_LEVELS_ARB:
2516bf215546Sopenharmony_ci         if (!_mesa_has_ARB_sparse_texture(ctx))
2517bf215546Sopenharmony_ci            goto invalid_pname;
2518bf215546Sopenharmony_ci         *params = (GLfloat) obj->NumSparseLevels;
2519bf215546Sopenharmony_ci         break;
2520bf215546Sopenharmony_ci
2521bf215546Sopenharmony_ci      default:
2522bf215546Sopenharmony_ci         goto invalid_pname;
2523bf215546Sopenharmony_ci   }
2524bf215546Sopenharmony_ci
2525bf215546Sopenharmony_ci   /* no error if we get here */
2526bf215546Sopenharmony_ci   _mesa_unlock_context_textures(ctx);
2527bf215546Sopenharmony_ci   return;
2528bf215546Sopenharmony_ci
2529bf215546Sopenharmony_ciinvalid_pname:
2530bf215546Sopenharmony_ci   _mesa_unlock_context_textures(ctx);
2531bf215546Sopenharmony_ci   _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameterfv(pname=0x%x)",
2532bf215546Sopenharmony_ci               dsa ? "ture" : "", pname);
2533bf215546Sopenharmony_ci}
2534bf215546Sopenharmony_ci
2535bf215546Sopenharmony_ci
2536bf215546Sopenharmony_cistatic void
2537bf215546Sopenharmony_ciget_tex_parameteriv(struct gl_context *ctx,
2538bf215546Sopenharmony_ci                    struct gl_texture_object *obj,
2539bf215546Sopenharmony_ci                    GLenum pname, GLint *params, bool dsa)
2540bf215546Sopenharmony_ci{
2541bf215546Sopenharmony_ci   _mesa_lock_texture(ctx, obj);
2542bf215546Sopenharmony_ci   switch (pname) {
2543bf215546Sopenharmony_ci      case GL_TEXTURE_MAG_FILTER:
2544bf215546Sopenharmony_ci         *params = (GLint) obj->Sampler.Attrib.MagFilter;
2545bf215546Sopenharmony_ci         break;
2546bf215546Sopenharmony_ci      case GL_TEXTURE_MIN_FILTER:
2547bf215546Sopenharmony_ci         *params = (GLint) obj->Sampler.Attrib.MinFilter;
2548bf215546Sopenharmony_ci         break;
2549bf215546Sopenharmony_ci      case GL_TEXTURE_WRAP_S:
2550bf215546Sopenharmony_ci         *params = (GLint) obj->Sampler.Attrib.WrapS;
2551bf215546Sopenharmony_ci         break;
2552bf215546Sopenharmony_ci      case GL_TEXTURE_WRAP_T:
2553bf215546Sopenharmony_ci         *params = (GLint) obj->Sampler.Attrib.WrapT;
2554bf215546Sopenharmony_ci         break;
2555bf215546Sopenharmony_ci      case GL_TEXTURE_WRAP_R:
2556bf215546Sopenharmony_ci         *params = (GLint) obj->Sampler.Attrib.WrapR;
2557bf215546Sopenharmony_ci         break;
2558bf215546Sopenharmony_ci      case GL_TEXTURE_BORDER_COLOR:
2559bf215546Sopenharmony_ci         if (ctx->API == API_OPENGLES)
2560bf215546Sopenharmony_ci            goto invalid_pname;
2561bf215546Sopenharmony_ci
2562bf215546Sopenharmony_ci         {
2563bf215546Sopenharmony_ci            GLfloat b[4];
2564bf215546Sopenharmony_ci            b[0] = CLAMP(obj->Sampler.Attrib.state.border_color.f[0], 0.0F, 1.0F);
2565bf215546Sopenharmony_ci            b[1] = CLAMP(obj->Sampler.Attrib.state.border_color.f[1], 0.0F, 1.0F);
2566bf215546Sopenharmony_ci            b[2] = CLAMP(obj->Sampler.Attrib.state.border_color.f[2], 0.0F, 1.0F);
2567bf215546Sopenharmony_ci            b[3] = CLAMP(obj->Sampler.Attrib.state.border_color.f[3], 0.0F, 1.0F);
2568bf215546Sopenharmony_ci            params[0] = FLOAT_TO_INT(b[0]);
2569bf215546Sopenharmony_ci            params[1] = FLOAT_TO_INT(b[1]);
2570bf215546Sopenharmony_ci            params[2] = FLOAT_TO_INT(b[2]);
2571bf215546Sopenharmony_ci            params[3] = FLOAT_TO_INT(b[3]);
2572bf215546Sopenharmony_ci         }
2573bf215546Sopenharmony_ci         break;
2574bf215546Sopenharmony_ci      case GL_TEXTURE_RESIDENT:
2575bf215546Sopenharmony_ci         if (ctx->API != API_OPENGL_COMPAT)
2576bf215546Sopenharmony_ci            goto invalid_pname;
2577bf215546Sopenharmony_ci
2578bf215546Sopenharmony_ci         *params = 1;
2579bf215546Sopenharmony_ci         break;
2580bf215546Sopenharmony_ci      case GL_TEXTURE_PRIORITY:
2581bf215546Sopenharmony_ci         if (ctx->API != API_OPENGL_COMPAT)
2582bf215546Sopenharmony_ci            goto invalid_pname;
2583bf215546Sopenharmony_ci
2584bf215546Sopenharmony_ci         *params = FLOAT_TO_INT(obj->Attrib.Priority);
2585bf215546Sopenharmony_ci         break;
2586bf215546Sopenharmony_ci      case GL_TEXTURE_MIN_LOD:
2587bf215546Sopenharmony_ci         if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2588bf215546Sopenharmony_ci            goto invalid_pname;
2589bf215546Sopenharmony_ci         /* GL spec 'Data Conversions' section specifies that floating-point
2590bf215546Sopenharmony_ci          * value in integer Get function is rounded to nearest integer
2591bf215546Sopenharmony_ci          *
2592bf215546Sopenharmony_ci          * Section 2.2.2 (Data Conversions For State Query Commands) of the
2593bf215546Sopenharmony_ci          * OpenGL 4.5 spec says:
2594bf215546Sopenharmony_ci          *
2595bf215546Sopenharmony_ci          *   Following these steps, if a value is so large in magnitude that
2596bf215546Sopenharmony_ci          *   it cannot be represented by the returned data type, then the
2597bf215546Sopenharmony_ci          *   nearest value representable using that type is returned.
2598bf215546Sopenharmony_ci          */
2599bf215546Sopenharmony_ci         *params = LCLAMPF(obj->Sampler.Attrib.MinLod, INT_MIN, INT_MAX);
2600bf215546Sopenharmony_ci         break;
2601bf215546Sopenharmony_ci      case GL_TEXTURE_MAX_LOD:
2602bf215546Sopenharmony_ci         if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2603bf215546Sopenharmony_ci            goto invalid_pname;
2604bf215546Sopenharmony_ci         /* GL spec 'Data Conversions' section specifies that floating-point
2605bf215546Sopenharmony_ci          * value in integer Get function is rounded to nearest integer
2606bf215546Sopenharmony_ci          *
2607bf215546Sopenharmony_ci          * Section 2.2.2 (Data Conversions For State Query Commands) of the
2608bf215546Sopenharmony_ci          * OpenGL 4.5 spec says:
2609bf215546Sopenharmony_ci          *
2610bf215546Sopenharmony_ci          *   Following these steps, if a value is so large in magnitude that
2611bf215546Sopenharmony_ci          *   it cannot be represented by the returned data type, then the
2612bf215546Sopenharmony_ci          *   nearest value representable using that type is returned.
2613bf215546Sopenharmony_ci          */
2614bf215546Sopenharmony_ci         *params = LCLAMPF(obj->Sampler.Attrib.MaxLod, INT_MIN, INT_MAX);
2615bf215546Sopenharmony_ci         break;
2616bf215546Sopenharmony_ci      case GL_TEXTURE_BASE_LEVEL:
2617bf215546Sopenharmony_ci         if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2618bf215546Sopenharmony_ci            goto invalid_pname;
2619bf215546Sopenharmony_ci
2620bf215546Sopenharmony_ci         *params = obj->Attrib.BaseLevel;
2621bf215546Sopenharmony_ci         break;
2622bf215546Sopenharmony_ci      case GL_TEXTURE_MAX_LEVEL:
2623bf215546Sopenharmony_ci         *params = obj->Attrib.MaxLevel;
2624bf215546Sopenharmony_ci         break;
2625bf215546Sopenharmony_ci      case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2626bf215546Sopenharmony_ci         if (!ctx->Extensions.EXT_texture_filter_anisotropic)
2627bf215546Sopenharmony_ci            goto invalid_pname;
2628bf215546Sopenharmony_ci         /* GL spec 'Data Conversions' section specifies that floating-point
2629bf215546Sopenharmony_ci          * value in integer Get function is rounded to nearest integer
2630bf215546Sopenharmony_ci          *
2631bf215546Sopenharmony_ci          * Section 2.2.2 (Data Conversions For State Query Commands) of the
2632bf215546Sopenharmony_ci          * OpenGL 4.5 spec says:
2633bf215546Sopenharmony_ci          *
2634bf215546Sopenharmony_ci          *   Following these steps, if a value is so large in magnitude that
2635bf215546Sopenharmony_ci          *   it cannot be represented by the returned data type, then the
2636bf215546Sopenharmony_ci          *   nearest value representable using that type is returned.
2637bf215546Sopenharmony_ci          */
2638bf215546Sopenharmony_ci         *params = LCLAMPF(obj->Sampler.Attrib.MaxAnisotropy, INT_MIN, INT_MAX);
2639bf215546Sopenharmony_ci         break;
2640bf215546Sopenharmony_ci      case GL_GENERATE_MIPMAP_SGIS:
2641bf215546Sopenharmony_ci         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
2642bf215546Sopenharmony_ci            goto invalid_pname;
2643bf215546Sopenharmony_ci
2644bf215546Sopenharmony_ci	 *params = (GLint) obj->Attrib.GenerateMipmap;
2645bf215546Sopenharmony_ci         break;
2646bf215546Sopenharmony_ci      case GL_TEXTURE_COMPARE_MODE_ARB:
2647bf215546Sopenharmony_ci         if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2648bf215546Sopenharmony_ci             && !_mesa_is_gles3(ctx))
2649bf215546Sopenharmony_ci            goto invalid_pname;
2650bf215546Sopenharmony_ci         *params = (GLint) obj->Sampler.Attrib.CompareMode;
2651bf215546Sopenharmony_ci         break;
2652bf215546Sopenharmony_ci      case GL_TEXTURE_COMPARE_FUNC_ARB:
2653bf215546Sopenharmony_ci         if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2654bf215546Sopenharmony_ci             && !_mesa_is_gles3(ctx))
2655bf215546Sopenharmony_ci            goto invalid_pname;
2656bf215546Sopenharmony_ci         *params = (GLint) obj->Sampler.Attrib.CompareFunc;
2657bf215546Sopenharmony_ci         break;
2658bf215546Sopenharmony_ci      case GL_DEPTH_TEXTURE_MODE_ARB:
2659bf215546Sopenharmony_ci         if (ctx->API != API_OPENGL_COMPAT)
2660bf215546Sopenharmony_ci            goto invalid_pname;
2661bf215546Sopenharmony_ci         *params = (GLint) obj->Attrib.DepthMode;
2662bf215546Sopenharmony_ci         break;
2663bf215546Sopenharmony_ci      case GL_DEPTH_STENCIL_TEXTURE_MODE:
2664bf215546Sopenharmony_ci         if (!_mesa_has_ARB_stencil_texturing(ctx) && !_mesa_is_gles31(ctx))
2665bf215546Sopenharmony_ci            goto invalid_pname;
2666bf215546Sopenharmony_ci         *params = (GLint)
2667bf215546Sopenharmony_ci            (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
2668bf215546Sopenharmony_ci         break;
2669bf215546Sopenharmony_ci      case GL_TEXTURE_LOD_BIAS:
2670bf215546Sopenharmony_ci         if (_mesa_is_gles(ctx))
2671bf215546Sopenharmony_ci            goto invalid_pname;
2672bf215546Sopenharmony_ci
2673bf215546Sopenharmony_ci         /* GL spec 'Data Conversions' section specifies that floating-point
2674bf215546Sopenharmony_ci          * value in integer Get function is rounded to nearest integer
2675bf215546Sopenharmony_ci          *
2676bf215546Sopenharmony_ci          * Section 2.2.2 (Data Conversions For State Query Commands) of the
2677bf215546Sopenharmony_ci          * OpenGL 4.5 spec says:
2678bf215546Sopenharmony_ci          *
2679bf215546Sopenharmony_ci          *   Following these steps, if a value is so large in magnitude that
2680bf215546Sopenharmony_ci          *   it cannot be represented by the returned data type, then the
2681bf215546Sopenharmony_ci          *   nearest value representable using that type is returned.
2682bf215546Sopenharmony_ci          */
2683bf215546Sopenharmony_ci         *params = LCLAMPF(obj->Sampler.Attrib.LodBias, INT_MIN, INT_MAX);
2684bf215546Sopenharmony_ci         break;
2685bf215546Sopenharmony_ci      case GL_TEXTURE_CROP_RECT_OES:
2686bf215546Sopenharmony_ci         if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
2687bf215546Sopenharmony_ci            goto invalid_pname;
2688bf215546Sopenharmony_ci
2689bf215546Sopenharmony_ci         params[0] = obj->CropRect[0];
2690bf215546Sopenharmony_ci         params[1] = obj->CropRect[1];
2691bf215546Sopenharmony_ci         params[2] = obj->CropRect[2];
2692bf215546Sopenharmony_ci         params[3] = obj->CropRect[3];
2693bf215546Sopenharmony_ci         break;
2694bf215546Sopenharmony_ci      case GL_TEXTURE_SWIZZLE_R_EXT:
2695bf215546Sopenharmony_ci      case GL_TEXTURE_SWIZZLE_G_EXT:
2696bf215546Sopenharmony_ci      case GL_TEXTURE_SWIZZLE_B_EXT:
2697bf215546Sopenharmony_ci      case GL_TEXTURE_SWIZZLE_A_EXT:
2698bf215546Sopenharmony_ci         if ((!_mesa_is_desktop_gl(ctx)
2699bf215546Sopenharmony_ci              || !ctx->Extensions.EXT_texture_swizzle)
2700bf215546Sopenharmony_ci             && !_mesa_is_gles3(ctx))
2701bf215546Sopenharmony_ci            goto invalid_pname;
2702bf215546Sopenharmony_ci         *params = obj->Attrib.Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
2703bf215546Sopenharmony_ci         break;
2704bf215546Sopenharmony_ci
2705bf215546Sopenharmony_ci      case GL_TEXTURE_SWIZZLE_RGBA_EXT:
2706bf215546Sopenharmony_ci         if ((!_mesa_is_desktop_gl(ctx)
2707bf215546Sopenharmony_ci              || !ctx->Extensions.EXT_texture_swizzle)
2708bf215546Sopenharmony_ci             && !_mesa_is_gles3(ctx))
2709bf215546Sopenharmony_ci            goto invalid_pname;
2710bf215546Sopenharmony_ci         COPY_4V(params, obj->Attrib.Swizzle);
2711bf215546Sopenharmony_ci         break;
2712bf215546Sopenharmony_ci
2713bf215546Sopenharmony_ci      case GL_TEXTURE_CUBE_MAP_SEAMLESS:
2714bf215546Sopenharmony_ci         if (!_mesa_is_desktop_gl(ctx)
2715bf215546Sopenharmony_ci             || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
2716bf215546Sopenharmony_ci            goto invalid_pname;
2717bf215546Sopenharmony_ci         *params = (GLint) obj->Sampler.Attrib.CubeMapSeamless;
2718bf215546Sopenharmony_ci         break;
2719bf215546Sopenharmony_ci
2720bf215546Sopenharmony_ci      case GL_TEXTURE_IMMUTABLE_FORMAT:
2721bf215546Sopenharmony_ci         *params = (GLint) obj->Immutable;
2722bf215546Sopenharmony_ci         break;
2723bf215546Sopenharmony_ci
2724bf215546Sopenharmony_ci      case GL_TEXTURE_IMMUTABLE_LEVELS:
2725bf215546Sopenharmony_ci         if (_mesa_is_gles3(ctx) ||
2726bf215546Sopenharmony_ci             (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_view))
2727bf215546Sopenharmony_ci            *params = obj->Attrib.ImmutableLevels;
2728bf215546Sopenharmony_ci         else
2729bf215546Sopenharmony_ci            goto invalid_pname;
2730bf215546Sopenharmony_ci         break;
2731bf215546Sopenharmony_ci
2732bf215546Sopenharmony_ci      case GL_TEXTURE_VIEW_MIN_LEVEL:
2733bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_texture_view)
2734bf215546Sopenharmony_ci            goto invalid_pname;
2735bf215546Sopenharmony_ci         *params = (GLint) obj->Attrib.MinLevel;
2736bf215546Sopenharmony_ci         break;
2737bf215546Sopenharmony_ci
2738bf215546Sopenharmony_ci      case GL_TEXTURE_VIEW_NUM_LEVELS:
2739bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_texture_view)
2740bf215546Sopenharmony_ci            goto invalid_pname;
2741bf215546Sopenharmony_ci         *params = (GLint) obj->Attrib.NumLevels;
2742bf215546Sopenharmony_ci         break;
2743bf215546Sopenharmony_ci
2744bf215546Sopenharmony_ci      case GL_TEXTURE_VIEW_MIN_LAYER:
2745bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_texture_view)
2746bf215546Sopenharmony_ci            goto invalid_pname;
2747bf215546Sopenharmony_ci         *params = (GLint) obj->Attrib.MinLayer;
2748bf215546Sopenharmony_ci         break;
2749bf215546Sopenharmony_ci
2750bf215546Sopenharmony_ci      case GL_TEXTURE_VIEW_NUM_LAYERS:
2751bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_texture_view)
2752bf215546Sopenharmony_ci            goto invalid_pname;
2753bf215546Sopenharmony_ci         *params = (GLint) obj->Attrib.NumLayers;
2754bf215546Sopenharmony_ci         break;
2755bf215546Sopenharmony_ci
2756bf215546Sopenharmony_ci      case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
2757bf215546Sopenharmony_ci         if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
2758bf215546Sopenharmony_ci            goto invalid_pname;
2759bf215546Sopenharmony_ci         *params = obj->RequiredTextureImageUnits;
2760bf215546Sopenharmony_ci         break;
2761bf215546Sopenharmony_ci
2762bf215546Sopenharmony_ci      case GL_TEXTURE_SRGB_DECODE_EXT:
2763bf215546Sopenharmony_ci         if (!ctx->Extensions.EXT_texture_sRGB_decode)
2764bf215546Sopenharmony_ci            goto invalid_pname;
2765bf215546Sopenharmony_ci         *params = obj->Sampler.Attrib.sRGBDecode;
2766bf215546Sopenharmony_ci         break;
2767bf215546Sopenharmony_ci
2768bf215546Sopenharmony_ci      case GL_TEXTURE_REDUCTION_MODE_EXT:
2769bf215546Sopenharmony_ci         if (!ctx->Extensions.EXT_texture_filter_minmax &&
2770bf215546Sopenharmony_ci             !_mesa_has_ARB_texture_filter_minmax(ctx))
2771bf215546Sopenharmony_ci            goto invalid_pname;
2772bf215546Sopenharmony_ci         *params = obj->Sampler.Attrib.ReductionMode;
2773bf215546Sopenharmony_ci         break;
2774bf215546Sopenharmony_ci
2775bf215546Sopenharmony_ci      case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
2776bf215546Sopenharmony_ci         if (!ctx->Extensions.ARB_shader_image_load_store &&
2777bf215546Sopenharmony_ci             !_mesa_is_gles31(ctx))
2778bf215546Sopenharmony_ci            goto invalid_pname;
2779bf215546Sopenharmony_ci         *params = obj->Attrib.ImageFormatCompatibilityType;
2780bf215546Sopenharmony_ci         break;
2781bf215546Sopenharmony_ci
2782bf215546Sopenharmony_ci      case GL_TEXTURE_TARGET:
2783bf215546Sopenharmony_ci         if (ctx->API != API_OPENGL_CORE)
2784bf215546Sopenharmony_ci            goto invalid_pname;
2785bf215546Sopenharmony_ci         *params = (GLint) obj->Target;
2786bf215546Sopenharmony_ci         break;
2787bf215546Sopenharmony_ci
2788bf215546Sopenharmony_ci      case GL_TEXTURE_TILING_EXT:
2789bf215546Sopenharmony_ci         if (!ctx->Extensions.EXT_memory_object)
2790bf215546Sopenharmony_ci            goto invalid_pname;
2791bf215546Sopenharmony_ci         *params = (GLint) obj->TextureTiling;
2792bf215546Sopenharmony_ci         break;
2793bf215546Sopenharmony_ci
2794bf215546Sopenharmony_ci      case GL_TEXTURE_SPARSE_ARB:
2795bf215546Sopenharmony_ci         if (!_mesa_has_ARB_sparse_texture(ctx))
2796bf215546Sopenharmony_ci            goto invalid_pname;
2797bf215546Sopenharmony_ci         *params = obj->IsSparse;
2798bf215546Sopenharmony_ci         break;
2799bf215546Sopenharmony_ci
2800bf215546Sopenharmony_ci      case GL_VIRTUAL_PAGE_SIZE_INDEX_ARB:
2801bf215546Sopenharmony_ci         if (!_mesa_has_ARB_sparse_texture(ctx))
2802bf215546Sopenharmony_ci            goto invalid_pname;
2803bf215546Sopenharmony_ci         *params = obj->VirtualPageSizeIndex;
2804bf215546Sopenharmony_ci         break;
2805bf215546Sopenharmony_ci
2806bf215546Sopenharmony_ci      case GL_NUM_SPARSE_LEVELS_ARB:
2807bf215546Sopenharmony_ci         if (!_mesa_has_ARB_sparse_texture(ctx))
2808bf215546Sopenharmony_ci            goto invalid_pname;
2809bf215546Sopenharmony_ci         *params = obj->NumSparseLevels;
2810bf215546Sopenharmony_ci         break;
2811bf215546Sopenharmony_ci
2812bf215546Sopenharmony_ci      default:
2813bf215546Sopenharmony_ci         goto invalid_pname;
2814bf215546Sopenharmony_ci   }
2815bf215546Sopenharmony_ci
2816bf215546Sopenharmony_ci   /* no error if we get here */
2817bf215546Sopenharmony_ci   _mesa_unlock_texture(ctx, obj);
2818bf215546Sopenharmony_ci   return;
2819bf215546Sopenharmony_ci
2820bf215546Sopenharmony_ciinvalid_pname:
2821bf215546Sopenharmony_ci   _mesa_unlock_texture(ctx, obj);
2822bf215546Sopenharmony_ci   _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameteriv(pname=0x%x)",
2823bf215546Sopenharmony_ci               dsa ? "ture" : "", pname);
2824bf215546Sopenharmony_ci}
2825bf215546Sopenharmony_ci
2826bf215546Sopenharmony_cistatic void
2827bf215546Sopenharmony_ciget_tex_parameterIiv(struct gl_context *ctx,
2828bf215546Sopenharmony_ci                     struct gl_texture_object *obj,
2829bf215546Sopenharmony_ci                     GLenum pname, GLint *params, bool dsa)
2830bf215546Sopenharmony_ci{
2831bf215546Sopenharmony_ci   switch (pname) {
2832bf215546Sopenharmony_ci   case GL_TEXTURE_BORDER_COLOR:
2833bf215546Sopenharmony_ci      COPY_4V(params, obj->Sampler.Attrib.state.border_color.i);
2834bf215546Sopenharmony_ci      break;
2835bf215546Sopenharmony_ci   default:
2836bf215546Sopenharmony_ci      get_tex_parameteriv(ctx, obj, pname, params, dsa);
2837bf215546Sopenharmony_ci   }
2838bf215546Sopenharmony_ci}
2839bf215546Sopenharmony_ci
2840bf215546Sopenharmony_civoid GLAPIENTRY
2841bf215546Sopenharmony_ci_mesa_GetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
2842bf215546Sopenharmony_ci{
2843bf215546Sopenharmony_ci   struct gl_texture_object *obj;
2844bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2845bf215546Sopenharmony_ci
2846bf215546Sopenharmony_ci   obj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2847bf215546Sopenharmony_ci                                                ctx->Texture.CurrentUnit,
2848bf215546Sopenharmony_ci                                                false,
2849bf215546Sopenharmony_ci                                                "glGetTexParameterfv");
2850bf215546Sopenharmony_ci   if (!obj)
2851bf215546Sopenharmony_ci      return;
2852bf215546Sopenharmony_ci
2853bf215546Sopenharmony_ci   get_tex_parameterfv(ctx, obj, pname, params, false);
2854bf215546Sopenharmony_ci}
2855bf215546Sopenharmony_ci
2856bf215546Sopenharmony_civoid GLAPIENTRY
2857bf215546Sopenharmony_ci_mesa_GetTexParameteriv(GLenum target, GLenum pname, GLint *params)
2858bf215546Sopenharmony_ci{
2859bf215546Sopenharmony_ci   struct gl_texture_object *obj;
2860bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2861bf215546Sopenharmony_ci
2862bf215546Sopenharmony_ci   obj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2863bf215546Sopenharmony_ci                                                ctx->Texture.CurrentUnit,
2864bf215546Sopenharmony_ci                                                false,
2865bf215546Sopenharmony_ci                                                "glGetTexParameteriv");
2866bf215546Sopenharmony_ci   if (!obj)
2867bf215546Sopenharmony_ci      return;
2868bf215546Sopenharmony_ci
2869bf215546Sopenharmony_ci   get_tex_parameteriv(ctx, obj, pname, params, false);
2870bf215546Sopenharmony_ci}
2871bf215546Sopenharmony_ci
2872bf215546Sopenharmony_ci/** New in GL 3.0 */
2873bf215546Sopenharmony_civoid GLAPIENTRY
2874bf215546Sopenharmony_ci_mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
2875bf215546Sopenharmony_ci{
2876bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
2877bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2878bf215546Sopenharmony_ci
2879bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2880bf215546Sopenharmony_ci                                                ctx->Texture.CurrentUnit,
2881bf215546Sopenharmony_ci                                                false,
2882bf215546Sopenharmony_ci                                                "glGetTexParameterIiv");
2883bf215546Sopenharmony_ci   if (!texObj)
2884bf215546Sopenharmony_ci      return;
2885bf215546Sopenharmony_ci
2886bf215546Sopenharmony_ci   get_tex_parameterIiv(ctx, texObj, pname, params, false);
2887bf215546Sopenharmony_ci}
2888bf215546Sopenharmony_ci
2889bf215546Sopenharmony_ci
2890bf215546Sopenharmony_ci/** New in GL 3.0 */
2891bf215546Sopenharmony_civoid GLAPIENTRY
2892bf215546Sopenharmony_ci_mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
2893bf215546Sopenharmony_ci{
2894bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
2895bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2896bf215546Sopenharmony_ci
2897bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2898bf215546Sopenharmony_ci                                                ctx->Texture.CurrentUnit,
2899bf215546Sopenharmony_ci                                                false,
2900bf215546Sopenharmony_ci                                                "glGetTexParameterIuiv");
2901bf215546Sopenharmony_ci   if (!texObj)
2902bf215546Sopenharmony_ci      return;
2903bf215546Sopenharmony_ci
2904bf215546Sopenharmony_ci   get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, false);
2905bf215546Sopenharmony_ci}
2906bf215546Sopenharmony_ci
2907bf215546Sopenharmony_civoid GLAPIENTRY
2908bf215546Sopenharmony_ci_mesa_GetTextureParameterfvEXT(GLuint texture, GLenum target, GLenum pname, GLfloat *params)
2909bf215546Sopenharmony_ci{
2910bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
2911bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2912bf215546Sopenharmony_ci
2913bf215546Sopenharmony_ci   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2914bf215546Sopenharmony_ci                                           "glGetTextureParameterfvEXT");
2915bf215546Sopenharmony_ci   if (!texObj)
2916bf215546Sopenharmony_ci      return;
2917bf215546Sopenharmony_ci
2918bf215546Sopenharmony_ci   if (!is_texparameteri_target_valid(texObj->Target)) {
2919bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTextureParameterfvEXT");
2920bf215546Sopenharmony_ci      return;
2921bf215546Sopenharmony_ci   }
2922bf215546Sopenharmony_ci
2923bf215546Sopenharmony_ci   get_tex_parameterfv(ctx, texObj, pname, params, true);
2924bf215546Sopenharmony_ci}
2925bf215546Sopenharmony_ci
2926bf215546Sopenharmony_civoid GLAPIENTRY
2927bf215546Sopenharmony_ci_mesa_GetMultiTexParameterfvEXT(GLenum texunit, GLenum target, GLenum pname, GLfloat *params)
2928bf215546Sopenharmony_ci{
2929bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
2930bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2931bf215546Sopenharmony_ci
2932bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2933bf215546Sopenharmony_ci                                                   texunit - GL_TEXTURE0,
2934bf215546Sopenharmony_ci                                                   false,
2935bf215546Sopenharmony_ci                                                   "glGetMultiTexParameterfvEXT");
2936bf215546Sopenharmony_ci   if (!texObj)
2937bf215546Sopenharmony_ci      return;
2938bf215546Sopenharmony_ci
2939bf215546Sopenharmony_ci   if (!is_texparameteri_target_valid(texObj->Target)) {
2940bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetMultiTexParameterfvEXT");
2941bf215546Sopenharmony_ci      return;
2942bf215546Sopenharmony_ci   }
2943bf215546Sopenharmony_ci   get_tex_parameterfv(ctx, texObj, pname, params, true);
2944bf215546Sopenharmony_ci}
2945bf215546Sopenharmony_ci
2946bf215546Sopenharmony_civoid GLAPIENTRY
2947bf215546Sopenharmony_ci_mesa_GetTextureParameterfv(GLuint texture, GLenum pname, GLfloat *params)
2948bf215546Sopenharmony_ci{
2949bf215546Sopenharmony_ci   struct gl_texture_object *obj;
2950bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2951bf215546Sopenharmony_ci
2952bf215546Sopenharmony_ci   obj = get_texobj_by_name(ctx, texture, "glGetTextureParameterfv");
2953bf215546Sopenharmony_ci   if (!obj)
2954bf215546Sopenharmony_ci      return;
2955bf215546Sopenharmony_ci
2956bf215546Sopenharmony_ci   get_tex_parameterfv(ctx, obj, pname, params, true);
2957bf215546Sopenharmony_ci}
2958bf215546Sopenharmony_ci
2959bf215546Sopenharmony_civoid GLAPIENTRY
2960bf215546Sopenharmony_ci_mesa_GetTextureParameterivEXT(GLuint texture, GLenum target, GLenum pname, GLint *params)
2961bf215546Sopenharmony_ci{
2962bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
2963bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2964bf215546Sopenharmony_ci
2965bf215546Sopenharmony_ci   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
2966bf215546Sopenharmony_ci                                           "glGetTextureParameterivEXT");
2967bf215546Sopenharmony_ci   if (!texObj)
2968bf215546Sopenharmony_ci      return;
2969bf215546Sopenharmony_ci
2970bf215546Sopenharmony_ci   if (!is_texparameteri_target_valid(texObj->Target)) {
2971bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTextureParameterivEXT");
2972bf215546Sopenharmony_ci      return;
2973bf215546Sopenharmony_ci   }
2974bf215546Sopenharmony_ci   get_tex_parameteriv(ctx, texObj, pname, params, true);
2975bf215546Sopenharmony_ci}
2976bf215546Sopenharmony_ci
2977bf215546Sopenharmony_civoid GLAPIENTRY
2978bf215546Sopenharmony_ci_mesa_GetMultiTexParameterivEXT(GLenum texunit, GLenum target, GLenum pname, GLint *params)
2979bf215546Sopenharmony_ci{
2980bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
2981bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
2982bf215546Sopenharmony_ci
2983bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
2984bf215546Sopenharmony_ci                                                   texunit - GL_TEXTURE0,
2985bf215546Sopenharmony_ci                                                   false,
2986bf215546Sopenharmony_ci                                                   "glGetMultiTexParameterivEXT");
2987bf215546Sopenharmony_ci   if (!texObj)
2988bf215546Sopenharmony_ci      return;
2989bf215546Sopenharmony_ci
2990bf215546Sopenharmony_ci   if (!is_texparameteri_target_valid(texObj->Target)) {
2991bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetMultiTexParameterivEXT");
2992bf215546Sopenharmony_ci      return;
2993bf215546Sopenharmony_ci   }
2994bf215546Sopenharmony_ci   get_tex_parameteriv(ctx, texObj, pname, params, true);
2995bf215546Sopenharmony_ci}
2996bf215546Sopenharmony_ci
2997bf215546Sopenharmony_civoid GLAPIENTRY
2998bf215546Sopenharmony_ci_mesa_GetTextureParameteriv(GLuint texture, GLenum pname, GLint *params)
2999bf215546Sopenharmony_ci{
3000bf215546Sopenharmony_ci   struct gl_texture_object *obj;
3001bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
3002bf215546Sopenharmony_ci
3003bf215546Sopenharmony_ci   obj = get_texobj_by_name(ctx, texture, "glGetTextureParameteriv");
3004bf215546Sopenharmony_ci   if (!obj)
3005bf215546Sopenharmony_ci      return;
3006bf215546Sopenharmony_ci
3007bf215546Sopenharmony_ci   get_tex_parameteriv(ctx, obj, pname, params, true);
3008bf215546Sopenharmony_ci}
3009bf215546Sopenharmony_ci
3010bf215546Sopenharmony_civoid GLAPIENTRY
3011bf215546Sopenharmony_ci_mesa_GetTextureParameterIiv(GLuint texture, GLenum pname, GLint *params)
3012bf215546Sopenharmony_ci{
3013bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
3014bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
3015bf215546Sopenharmony_ci
3016bf215546Sopenharmony_ci   texObj = get_texobj_by_name(ctx, texture, "glGetTextureParameterIiv");
3017bf215546Sopenharmony_ci   if (!texObj)
3018bf215546Sopenharmony_ci      return;
3019bf215546Sopenharmony_ci
3020bf215546Sopenharmony_ci   get_tex_parameterIiv(ctx, texObj, pname, params, true);
3021bf215546Sopenharmony_ci}
3022bf215546Sopenharmony_ci
3023bf215546Sopenharmony_civoid GLAPIENTRY
3024bf215546Sopenharmony_ci_mesa_GetTextureParameterIivEXT(GLuint texture, GLenum target, GLenum pname, GLint *params)
3025bf215546Sopenharmony_ci{
3026bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
3027bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
3028bf215546Sopenharmony_ci
3029bf215546Sopenharmony_ci   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
3030bf215546Sopenharmony_ci                                           "glGetTextureParameterIivEXT");
3031bf215546Sopenharmony_ci   if (!texObj)
3032bf215546Sopenharmony_ci      return;
3033bf215546Sopenharmony_ci
3034bf215546Sopenharmony_ci
3035bf215546Sopenharmony_ci   get_tex_parameterIiv(ctx, texObj, pname, params, true);
3036bf215546Sopenharmony_ci}
3037bf215546Sopenharmony_ci
3038bf215546Sopenharmony_civoid GLAPIENTRY
3039bf215546Sopenharmony_ci_mesa_GetMultiTexParameterIivEXT(GLenum texunit, GLenum target, GLenum pname,
3040bf215546Sopenharmony_ci                                 GLint *params)
3041bf215546Sopenharmony_ci{
3042bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
3043bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
3044bf215546Sopenharmony_ci
3045bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
3046bf215546Sopenharmony_ci                                                   texunit - GL_TEXTURE0,
3047bf215546Sopenharmony_ci                                                   true,
3048bf215546Sopenharmony_ci                                                   "glGetMultiTexParameterIiv");
3049bf215546Sopenharmony_ci   if (!texObj)
3050bf215546Sopenharmony_ci      return;
3051bf215546Sopenharmony_ci
3052bf215546Sopenharmony_ci   get_tex_parameterIiv(ctx, texObj, pname, params, true);
3053bf215546Sopenharmony_ci}
3054bf215546Sopenharmony_ci
3055bf215546Sopenharmony_civoid GLAPIENTRY
3056bf215546Sopenharmony_ci_mesa_GetTextureParameterIuiv(GLuint texture, GLenum pname, GLuint *params)
3057bf215546Sopenharmony_ci{
3058bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
3059bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
3060bf215546Sopenharmony_ci
3061bf215546Sopenharmony_ci   texObj = get_texobj_by_name(ctx, texture, "glGetTextureParameterIuiv");
3062bf215546Sopenharmony_ci   if (!texObj)
3063bf215546Sopenharmony_ci      return;
3064bf215546Sopenharmony_ci
3065bf215546Sopenharmony_ci   get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, true);
3066bf215546Sopenharmony_ci}
3067bf215546Sopenharmony_ci
3068bf215546Sopenharmony_civoid GLAPIENTRY
3069bf215546Sopenharmony_ci_mesa_GetTextureParameterIuivEXT(GLuint texture, GLenum target, GLenum pname,
3070bf215546Sopenharmony_ci                                 GLuint *params)
3071bf215546Sopenharmony_ci{
3072bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
3073bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
3074bf215546Sopenharmony_ci
3075bf215546Sopenharmony_ci   texObj = _mesa_lookup_or_create_texture(ctx, target, texture, false, true,
3076bf215546Sopenharmony_ci                                           "glGetTextureParameterIuvEXT");
3077bf215546Sopenharmony_ci   if (!texObj)
3078bf215546Sopenharmony_ci      return;
3079bf215546Sopenharmony_ci
3080bf215546Sopenharmony_ci   get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, true);
3081bf215546Sopenharmony_ci}
3082bf215546Sopenharmony_ci
3083bf215546Sopenharmony_civoid GLAPIENTRY
3084bf215546Sopenharmony_ci_mesa_GetMultiTexParameterIuivEXT(GLenum texunit, GLenum target, GLenum pname,
3085bf215546Sopenharmony_ci                               GLuint *params)
3086bf215546Sopenharmony_ci{
3087bf215546Sopenharmony_ci   struct gl_texture_object *texObj;
3088bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
3089bf215546Sopenharmony_ci
3090bf215546Sopenharmony_ci   texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target,
3091bf215546Sopenharmony_ci                                                   texunit - GL_TEXTURE0,
3092bf215546Sopenharmony_ci                                                   true,
3093bf215546Sopenharmony_ci                                                   "glGetMultiTexParameterIuiv");
3094bf215546Sopenharmony_ci   if (!texObj)
3095bf215546Sopenharmony_ci      return;
3096bf215546Sopenharmony_ci
3097bf215546Sopenharmony_ci   get_tex_parameterIiv(ctx, texObj, pname, (GLint *) params, true);
3098bf215546Sopenharmony_ci}
3099