blob: 4db406fa9f645422859761bc31b615c4eaf82757 [file] [log] [blame]
Brian Paulae1fdc12008-06-11 20:05:53 -06001/*
2 * Mesa 3-D graphics library
Brian Paulae1fdc12008-06-11 20:05:53 -06003 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
Brian Paulaad3f542009-02-09 13:58:32 -07005 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
Brian Paulae1fdc12008-06-11 20:05:53 -06006 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
Kenneth Graunke3d8d5b22013-04-21 13:46:48 -070020 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
Brian Paulae1fdc12008-06-11 20:05:53 -060024 */
25
Rico Schüller14f02cd2013-10-27 08:02:00 -060026/**
Brian Paulae1fdc12008-06-11 20:05:53 -060027 * \file texparam.c
28 *
29 * glTexParameter-related functions
30 */
31
Ian Romanickd53101a2011-10-03 12:46:23 -070032#include <stdbool.h>
Brian Paulae1fdc12008-06-11 20:05:53 -060033#include "main/glheader.h"
Marek Olšák755648c2013-03-28 01:56:01 +010034#include "main/blend.h"
Brian Paulae1fdc12008-06-11 20:05:53 -060035#include "main/context.h"
Brian Paul0f6b8e22011-01-25 18:27:44 -070036#include "main/enums.h"
Brian Paulb64d4782009-09-27 19:38:21 -060037#include "main/formats.h"
Brian Paula1287f52012-07-22 11:20:00 -060038#include "main/glformats.h"
Brian Paulae1fdc12008-06-11 20:05:53 -060039#include "main/macros.h"
Vinson Lee0117da42011-01-05 23:11:54 -080040#include "main/mtypes.h"
Marek Olšáke5c6a922011-02-15 23:30:23 +010041#include "main/state.h"
Brian Paulae1fdc12008-06-11 20:05:53 -060042#include "main/texcompress.h"
Brian Paulff005bd2012-03-17 16:30:03 -060043#include "main/texobj.h"
Brian Paulae1fdc12008-06-11 20:05:53 -060044#include "main/texparam.h"
45#include "main/teximage.h"
Brian Paul6aa7a032009-08-13 09:55:34 -060046#include "main/texstate.h"
Brian Paulec2b92f2010-06-10 23:02:41 -060047#include "program/prog_instruction.h"
Brian Paulae1fdc12008-06-11 20:05:53 -060048
49
Brian Paulae1fdc12008-06-11 20:05:53 -060050/**
51 * Check if a coordinate wrap mode is supported for the texture target.
52 * \return GL_TRUE if legal, GL_FALSE otherwise
53 */
Rico Schüller14f02cd2013-10-27 08:02:00 -060054static GLboolean
Kristian Høgsbergf9995b32010-10-12 12:26:10 -040055validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap)
Brian Paulae1fdc12008-06-11 20:05:53 -060056{
57 const struct gl_extensions * const e = & ctx->Extensions;
Ian Romanick842efb92011-10-03 13:03:47 -070058 const bool is_desktop_gl = _mesa_is_desktop_gl(ctx);
Ian Romanickd53101a2011-10-03 12:46:23 -070059 bool supported;
Brian Paulae1fdc12008-06-11 20:05:53 -060060
Ian Romanickd53101a2011-10-03 12:46:23 -070061 switch (wrap) {
62 case GL_CLAMP:
Ian Romanick842efb92011-10-03 13:03:47 -070063 /* GL_CLAMP was removed in the core profile, and it has never existed in
64 * OpenGL ES.
65 */
Paul Berrydbd61352012-11-27 12:26:51 -080066 supported = (ctx->API == API_OPENGL_COMPAT)
Ian Romanick842efb92011-10-03 13:03:47 -070067 && (target != GL_TEXTURE_EXTERNAL_OES);
Ian Romanickd53101a2011-10-03 12:46:23 -070068 break;
69
70 case GL_CLAMP_TO_EDGE:
71 supported = true;
72 break;
73
74 case GL_CLAMP_TO_BORDER:
Ilia Mirkinb6654832016-02-15 19:09:15 -050075 supported = ctx->API != API_OPENGLES && e->ARB_texture_border_clamp
Ian Romanickd53101a2011-10-03 12:46:23 -070076 && (target != GL_TEXTURE_EXTERNAL_OES);
77 break;
78
79 case GL_REPEAT:
80 case GL_MIRRORED_REPEAT:
81 supported = (target != GL_TEXTURE_RECTANGLE_NV)
82 && (target != GL_TEXTURE_EXTERNAL_OES);
83 break;
84
85 case GL_MIRROR_CLAMP_EXT:
Rico Schüller1bbd3bb2013-10-20 12:39:55 +020086 supported = is_desktop_gl
87 && (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)
88 && (target != GL_TEXTURE_RECTANGLE_NV)
89 && (target != GL_TEXTURE_EXTERNAL_OES);
90 break;
91
Ian Romanickd53101a2011-10-03 12:46:23 -070092 case GL_MIRROR_CLAMP_TO_EDGE_EXT:
Rico Schüller14f02cd2013-10-27 08:02:00 -060093 supported = is_desktop_gl
Rico Schüller1bbd3bb2013-10-20 12:39:55 +020094 && (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp || e->ARB_texture_mirror_clamp_to_edge)
95 && (target != GL_TEXTURE_RECTANGLE_NV)
Ian Romanickd53101a2011-10-03 12:46:23 -070096 && (target != GL_TEXTURE_EXTERNAL_OES);
97 break;
98
99 case GL_MIRROR_CLAMP_TO_BORDER_EXT:
Ian Romanick842efb92011-10-03 13:03:47 -0700100 supported = is_desktop_gl && e->EXT_texture_mirror_clamp
Rico Schüller1bbd3bb2013-10-20 12:39:55 +0200101 && (target != GL_TEXTURE_RECTANGLE_NV)
Ian Romanickd53101a2011-10-03 12:46:23 -0700102 && (target != GL_TEXTURE_EXTERNAL_OES);
103 break;
104
105 default:
106 supported = false;
107 break;
Brian Paulae1fdc12008-06-11 20:05:53 -0600108 }
109
Ian Romanickd53101a2011-10-03 12:46:23 -0700110 if (!supported)
111 _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(param=0x%x)", wrap );
112
113 return supported;
Brian Paulae1fdc12008-06-11 20:05:53 -0600114}
115
116
Brian Paul318e53a2009-01-27 11:07:21 -0700117/**
118 * Get current texture object for given target.
Brian Paul32b99832010-01-04 19:20:33 -0700119 * Return NULL if any error (and record the error).
Brian Paulf09a1262014-01-27 12:05:53 -0700120 * Note that this is different from _mesa_get_current_tex_object() in that
121 * proxy targets are not accepted.
Brian Paul32b99832010-01-04 19:20:33 -0700122 * Only the glGetTexLevelParameter() functions accept proxy targets.
Brian Paul318e53a2009-01-27 11:07:21 -0700123 */
124static struct gl_texture_object *
Laura Ekstrand5ad53932014-12-10 16:13:31 -0800125get_texobj_by_target(struct gl_context *ctx, GLenum target, GLboolean get)
Brian Paulae1fdc12008-06-11 20:05:53 -0600126{
Brian Paulae1fdc12008-06-11 20:05:53 -0600127 struct gl_texture_unit *texUnit;
Ian Romanicka7224542013-11-23 12:16:57 -0800128 int targetIndex;
Brian Paulae1fdc12008-06-11 20:05:53 -0600129
Brian Paulb2a30492010-02-03 15:47:44 -0700130 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
Brian Paul32b99832010-01-04 19:20:33 -0700131 _mesa_error(ctx, GL_INVALID_OPERATION,
132 "gl%sTexParameter(current unit)", get ? "Get" : "");
Brian Paul318e53a2009-01-27 11:07:21 -0700133 return NULL;
Brian Paulae1fdc12008-06-11 20:05:53 -0600134 }
135
Brian Paul6aa7a032009-08-13 09:55:34 -0600136 texUnit = _mesa_get_current_tex_unit(ctx);
Brian Paulae1fdc12008-06-11 20:05:53 -0600137
Ian Romanicka7224542013-11-23 12:16:57 -0800138 targetIndex = _mesa_tex_target_to_index(ctx, target);
139 if (targetIndex < 0 || targetIndex == TEXTURE_BUFFER_INDEX) {
140 _mesa_error(ctx, GL_INVALID_ENUM,
Brian Paul32b99832010-01-04 19:20:33 -0700141 "gl%sTexParameter(target)", get ? "Get" : "");
Ian Romanicka7224542013-11-23 12:16:57 -0800142 return NULL;
143 }
144 assert(targetIndex < NUM_TEXTURE_TARGETS);
145
146 return texUnit->CurrentTex[targetIndex];
Brian Paul318e53a2009-01-27 11:07:21 -0700147}
Brian Paulae1fdc12008-06-11 20:05:53 -0600148
Laura Ekstrand5ad53932014-12-10 16:13:31 -0800149/**
150 * Get current texture object for given name.
151 * Return NULL if any error (and record the error).
152 * Note that proxy targets are not accepted.
153 * Only the glGetTexLevelParameter() functions accept proxy targets.
154 */
155static struct gl_texture_object *
156get_texobj_by_name(struct gl_context *ctx, GLuint texture, GLboolean get)
157{
158 struct gl_texture_object *texObj;
159
160 texObj = _mesa_lookup_texture(ctx, texture);
161 if (!texObj) {
162 /*
163 * User passed a non-generated name.
164 * Throw the error in the caller.
165 */
166 return NULL;
167 }
168
169 switch (texObj->Target) {
170 case GL_TEXTURE_1D:
171 case GL_TEXTURE_1D_ARRAY:
172 case GL_TEXTURE_2D:
173 case GL_TEXTURE_2D_ARRAY:
174 case GL_TEXTURE_2D_MULTISAMPLE:
175 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
176 case GL_TEXTURE_3D:
177 case GL_TEXTURE_CUBE_MAP:
178 case GL_TEXTURE_CUBE_MAP_ARRAY:
179 case GL_TEXTURE_RECTANGLE:
180 return texObj;
181 default:
182 _mesa_error(ctx, GL_INVALID_ENUM,
183 "gl%sTextureParameter(target)", get ? "Get" : "");
184 return NULL;
185 }
186
187}
188
Brian Paul318e53a2009-01-27 11:07:21 -0700189
Brian Paul4a89e512009-01-28 10:27:33 -0700190/**
191 * Convert GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE to SWIZZLE_X/Y/Z/W/ZERO/ONE.
192 * \return -1 if error.
193 */
194static GLint
195comp_to_swizzle(GLenum comp)
196{
197 switch (comp) {
198 case GL_RED:
199 return SWIZZLE_X;
200 case GL_GREEN:
201 return SWIZZLE_Y;
202 case GL_BLUE:
203 return SWIZZLE_Z;
204 case GL_ALPHA:
205 return SWIZZLE_W;
206 case GL_ZERO:
207 return SWIZZLE_ZERO;
208 case GL_ONE:
209 return SWIZZLE_ONE;
210 default:
211 return -1;
212 }
213}
214
215
216static void
217set_swizzle_component(GLuint *swizzle, GLuint comp, GLuint swz)
218{
Matt Turnerbfcdb842015-02-20 20:18:47 -0800219 assert(comp < 4);
220 assert(swz <= SWIZZLE_NIL);
Brian Paul4a89e512009-01-28 10:27:33 -0700221 {
222 GLuint mask = 0x7 << (3 * comp);
223 GLuint s = (*swizzle & ~mask) | (swz << (3 * comp));
224 *swizzle = s;
225 }
226}
227
228
Brian Paulaad3f542009-02-09 13:58:32 -0700229/**
Brian Paulf4dc24a2011-01-23 09:10:35 -0700230 * This is called just prior to changing any texture object state which
Laura Ekstrandbad39f62015-01-06 10:04:31 -0800231 * will not affect texture completeness.
Brian Paulf4dc24a2011-01-23 09:10:35 -0700232 */
Brian Paul9520f482011-09-30 21:03:42 -0600233static inline void
Brian Paulf4dc24a2011-01-23 09:10:35 -0700234flush(struct gl_context *ctx)
235{
236 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
237}
238
239
240/**
241 * This is called just prior to changing any texture object state which
Laura Ekstrandbad39f62015-01-06 10:04:31 -0800242 * could affect texture completeness (texture base level, max level).
Brian Paulaad3f542009-02-09 13:58:32 -0700243 * Any pending rendering will be flushed out, we'll set the _NEW_TEXTURE
244 * state flag and then mark the texture object as 'incomplete' so that any
245 * per-texture derived state gets recomputed.
246 */
Brian Paul9520f482011-09-30 21:03:42 -0600247static inline void
Brian Paulf4dc24a2011-01-23 09:10:35 -0700248incomplete(struct gl_context *ctx, struct gl_texture_object *texObj)
Brian Paulaad3f542009-02-09 13:58:32 -0700249{
250 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
Kenneth Graunkee9b410b2013-09-17 21:50:26 -0700251 _mesa_dirty_texobj(ctx, texObj);
Brian Paulaad3f542009-02-09 13:58:32 -0700252}
253
254
Alejandro Piñeiroa8736a22015-12-22 20:04:38 +0100255GLboolean
256_mesa_target_allows_setting_sampler_parameters(GLenum target)
Chris Forbese0015c82013-03-15 22:52:12 +1300257{
258 switch (target) {
259 case GL_TEXTURE_2D_MULTISAMPLE:
260 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
261 return GL_FALSE;
262
263 default:
264 return GL_TRUE;
265 }
266}
267
268
Roland Scheideggerebc14782009-04-02 23:38:34 +0200269/**
270 * Set an integer-valued texture parameter
271 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
272 */
273static GLboolean
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400274set_tex_parameteri(struct gl_context *ctx,
Brian Paul318e53a2009-01-27 11:07:21 -0700275 struct gl_texture_object *texObj,
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800276 GLenum pname, const GLint *params, bool dsa)
Brian Paul318e53a2009-01-27 11:07:21 -0700277{
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800278 const char *suffix = dsa ? "ture" : "";
279
Brian Paul318e53a2009-01-27 11:07:21 -0700280 switch (pname) {
281 case GL_TEXTURE_MIN_FILTER:
Alejandro Piñeiroa8736a22015-12-22 20:04:38 +0100282 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800283 goto invalid_enum;
Chris Forbese0015c82013-03-15 22:52:12 +1300284
Brian Paulecfaab82011-04-10 12:44:46 -0600285 if (texObj->Sampler.MinFilter == params[0])
Roland Scheideggerebc14782009-04-02 23:38:34 +0200286 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700287 switch (params[0]) {
288 case GL_NEAREST:
289 case GL_LINEAR:
Brian Paulf4a93e02012-03-17 16:30:03 -0600290 flush(ctx);
Brian Paulecfaab82011-04-10 12:44:46 -0600291 texObj->Sampler.MinFilter = params[0];
Roland Scheideggerebc14782009-04-02 23:38:34 +0200292 return GL_TRUE;
Brian Paul318e53a2009-01-27 11:07:21 -0700293 case GL_NEAREST_MIPMAP_NEAREST:
294 case GL_LINEAR_MIPMAP_NEAREST:
295 case GL_NEAREST_MIPMAP_LINEAR:
296 case GL_LINEAR_MIPMAP_LINEAR:
Chia-I Wu0c87f162011-10-23 18:52:38 +0800297 if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
298 texObj->Target != GL_TEXTURE_EXTERNAL_OES) {
Brian Paulf4a93e02012-03-17 16:30:03 -0600299 flush(ctx);
Brian Paulecfaab82011-04-10 12:44:46 -0600300 texObj->Sampler.MinFilter = params[0];
Roland Scheideggerebc14782009-04-02 23:38:34 +0200301 return GL_TRUE;
Brian Paulae1fdc12008-06-11 20:05:53 -0600302 }
Brian Paul318e53a2009-01-27 11:07:21 -0700303 /* fall-through */
304 default:
Brian Paul0f6b8e22011-01-25 18:27:44 -0700305 goto invalid_param;
Brian Paul318e53a2009-01-27 11:07:21 -0700306 }
Roland Scheideggerebc14782009-04-02 23:38:34 +0200307 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700308
309 case GL_TEXTURE_MAG_FILTER:
Alejandro Piñeiroa8736a22015-12-22 20:04:38 +0100310 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800311 goto invalid_enum;
Chris Forbese0015c82013-03-15 22:52:12 +1300312
Brian Paulecfaab82011-04-10 12:44:46 -0600313 if (texObj->Sampler.MagFilter == params[0])
Roland Scheideggerebc14782009-04-02 23:38:34 +0200314 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700315 switch (params[0]) {
316 case GL_NEAREST:
317 case GL_LINEAR:
Brian Paulf4dc24a2011-01-23 09:10:35 -0700318 flush(ctx); /* does not effect completeness */
Brian Paulecfaab82011-04-10 12:44:46 -0600319 texObj->Sampler.MagFilter = params[0];
Roland Scheideggerebc14782009-04-02 23:38:34 +0200320 return GL_TRUE;
Brian Paul318e53a2009-01-27 11:07:21 -0700321 default:
Brian Paul0f6b8e22011-01-25 18:27:44 -0700322 goto invalid_param;
Brian Paul318e53a2009-01-27 11:07:21 -0700323 }
Roland Scheideggerebc14782009-04-02 23:38:34 +0200324 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700325
326 case GL_TEXTURE_WRAP_S:
Alejandro Piñeiroa8736a22015-12-22 20:04:38 +0100327 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800328 goto invalid_enum;
Chris Forbese0015c82013-03-15 22:52:12 +1300329
Brian Paulecfaab82011-04-10 12:44:46 -0600330 if (texObj->Sampler.WrapS == params[0])
Roland Scheideggerebc14782009-04-02 23:38:34 +0200331 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700332 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
Brian Paulf4dc24a2011-01-23 09:10:35 -0700333 flush(ctx);
Brian Paulecfaab82011-04-10 12:44:46 -0600334 texObj->Sampler.WrapS = params[0];
Roland Scheideggerebc14782009-04-02 23:38:34 +0200335 return GL_TRUE;
Brian Paul318e53a2009-01-27 11:07:21 -0700336 }
Roland Scheideggerebc14782009-04-02 23:38:34 +0200337 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700338
339 case GL_TEXTURE_WRAP_T:
Alejandro Piñeiroa8736a22015-12-22 20:04:38 +0100340 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800341 goto invalid_enum;
Chris Forbese0015c82013-03-15 22:52:12 +1300342
Brian Paulecfaab82011-04-10 12:44:46 -0600343 if (texObj->Sampler.WrapT == params[0])
Roland Scheideggerebc14782009-04-02 23:38:34 +0200344 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700345 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
Brian Paulf4dc24a2011-01-23 09:10:35 -0700346 flush(ctx);
Brian Paulecfaab82011-04-10 12:44:46 -0600347 texObj->Sampler.WrapT = params[0];
Roland Scheideggerebc14782009-04-02 23:38:34 +0200348 return GL_TRUE;
Brian Paul318e53a2009-01-27 11:07:21 -0700349 }
Roland Scheideggerebc14782009-04-02 23:38:34 +0200350 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700351
352 case GL_TEXTURE_WRAP_R:
Alejandro Piñeiroa8736a22015-12-22 20:04:38 +0100353 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800354 goto invalid_enum;
Chris Forbese0015c82013-03-15 22:52:12 +1300355
Brian Paulecfaab82011-04-10 12:44:46 -0600356 if (texObj->Sampler.WrapR == params[0])
Roland Scheideggerebc14782009-04-02 23:38:34 +0200357 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700358 if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) {
Brian Paulf4dc24a2011-01-23 09:10:35 -0700359 flush(ctx);
Brian Paulecfaab82011-04-10 12:44:46 -0600360 texObj->Sampler.WrapR = params[0];
Roland Scheideggerebc14782009-04-02 23:38:34 +0200361 return GL_TRUE;
Brian Paul318e53a2009-01-27 11:07:21 -0700362 }
Roland Scheideggerebc14782009-04-02 23:38:34 +0200363 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700364
365 case GL_TEXTURE_BASE_LEVEL:
Ian Romanickb3dd5242012-07-26 18:04:50 -0700366 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
367 goto invalid_pname;
368
Brian Paul318e53a2009-01-27 11:07:21 -0700369 if (texObj->BaseLevel == params[0])
Roland Scheideggerebc14782009-04-02 23:38:34 +0200370 return GL_FALSE;
Chris Forbese0015c82013-03-15 22:52:12 +1300371
372 if ((texObj->Target == GL_TEXTURE_2D_MULTISAMPLE ||
373 texObj->Target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) && params[0] != 0)
374 goto invalid_operation;
375
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800376 if (params[0] < 0) {
Brian Paul1d003992009-04-23 17:54:34 -0600377 _mesa_error(ctx, GL_INVALID_VALUE,
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800378 "glTex%sParameter(param=%d)", suffix, params[0]);
379 return GL_FALSE;
380 }
381 if (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] != 0) {
382 _mesa_error(ctx, GL_INVALID_OPERATION,
383 "glTex%sParameter(target=%s, param=%d)", suffix,
Kenneth Graunke2f11e922015-07-18 01:22:00 -0700384 _mesa_enum_to_string(texObj->Target), params[0]);
Roland Scheideggerebc14782009-04-02 23:38:34 +0200385 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700386 }
Brian Paulf4dc24a2011-01-23 09:10:35 -0700387 incomplete(ctx, texObj);
Corey Richardsonabdbd022013-07-31 10:46:12 -0400388
389 /** See note about ARB_texture_storage below */
390 if (texObj->Immutable)
391 texObj->BaseLevel = MIN2(texObj->ImmutableLevels - 1, params[0]);
392 else
393 texObj->BaseLevel = params[0];
394
Roland Scheideggerebc14782009-04-02 23:38:34 +0200395 return GL_TRUE;
Brian Paul318e53a2009-01-27 11:07:21 -0700396
397 case GL_TEXTURE_MAX_LEVEL:
398 if (texObj->MaxLevel == params[0])
Roland Scheideggerebc14782009-04-02 23:38:34 +0200399 return GL_FALSE;
Chris Forbese0015c82013-03-15 22:52:12 +1300400
Iago Toral Quirogaf5904b72014-03-31 02:04:00 -0600401 if (params[0] < 0 ||
402 (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] > 0)) {
Kenneth Graunkef399a702012-11-08 02:24:08 -0800403 _mesa_error(ctx, GL_INVALID_VALUE,
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800404 "glTex%sParameter(param=%d)", suffix,
405 params[0]);
Roland Scheideggerebc14782009-04-02 23:38:34 +0200406 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700407 }
Brian Paulf4dc24a2011-01-23 09:10:35 -0700408 incomplete(ctx, texObj);
Corey Richardsonabdbd022013-07-31 10:46:12 -0400409
410 /** From ARB_texture_storage:
411 * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
412 * clamped to the range [0, <levels> - 1] and level_max is then clamped to
413 * the range [level_base, <levels> - 1], where <levels> is the parameter
414 * passed the call to TexStorage* for the texture object.
415 */
416 if (texObj->Immutable)
417 texObj->MaxLevel = CLAMP(params[0], texObj->BaseLevel,
418 texObj->ImmutableLevels - 1);
419 else
420 texObj->MaxLevel = params[0];
421
Roland Scheideggerebc14782009-04-02 23:38:34 +0200422 return GL_TRUE;
Brian Paul318e53a2009-01-27 11:07:21 -0700423
Brian Paul318e53a2009-01-27 11:07:21 -0700424 case GL_GENERATE_MIPMAP_SGIS:
Paul Berrydbd61352012-11-27 12:26:51 -0800425 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
Ian Romanickb3dd5242012-07-26 18:04:50 -0700426 goto invalid_pname;
427
Chia-I Wu0c87f162011-10-23 18:52:38 +0800428 if (params[0] && texObj->Target == GL_TEXTURE_EXTERNAL_OES)
429 goto invalid_param;
Ian Romanick7f11d472010-09-27 14:55:52 -0700430 if (texObj->GenerateMipmap != params[0]) {
Brian Paulf4dc24a2011-01-23 09:10:35 -0700431 /* no flush() */
Ian Romanick7f11d472010-09-27 14:55:52 -0700432 texObj->GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
433 return GL_TRUE;
Brian Paul318e53a2009-01-27 11:07:21 -0700434 }
Roland Scheideggerebc14782009-04-02 23:38:34 +0200435 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700436
437 case GL_TEXTURE_COMPARE_MODE_ARB:
Ian Romanickb3dd5242012-07-26 18:04:50 -0700438 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow)
439 || _mesa_is_gles3(ctx)) {
Chris Forbese0015c82013-03-15 22:52:12 +1300440
Alejandro Piñeiroa8736a22015-12-22 20:04:38 +0100441 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800442 goto invalid_enum;
Chris Forbese0015c82013-03-15 22:52:12 +1300443
Brian Paulecfaab82011-04-10 12:44:46 -0600444 if (texObj->Sampler.CompareMode == params[0])
Brian Paul0f6b8e22011-01-25 18:27:44 -0700445 return GL_FALSE;
446 if (params[0] == GL_NONE ||
447 params[0] == GL_COMPARE_R_TO_TEXTURE_ARB) {
Brian Paulf4dc24a2011-01-23 09:10:35 -0700448 flush(ctx);
Brian Paulecfaab82011-04-10 12:44:46 -0600449 texObj->Sampler.CompareMode = params[0];
Roland Scheideggerebc14782009-04-02 23:38:34 +0200450 return GL_TRUE;
Brian Paul37c768b2009-02-09 13:50:36 -0700451 }
Brian Paul0f6b8e22011-01-25 18:27:44 -0700452 goto invalid_param;
Brian Paul318e53a2009-01-27 11:07:21 -0700453 }
Brian Paul0f6b8e22011-01-25 18:27:44 -0700454 goto invalid_pname;
Brian Paul318e53a2009-01-27 11:07:21 -0700455
456 case GL_TEXTURE_COMPARE_FUNC_ARB:
Ian Romanickb3dd5242012-07-26 18:04:50 -0700457 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_shadow)
458 || _mesa_is_gles3(ctx)) {
Chris Forbese0015c82013-03-15 22:52:12 +1300459
Alejandro Piñeiroa8736a22015-12-22 20:04:38 +0100460 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800461 goto invalid_enum;
Chris Forbese0015c82013-03-15 22:52:12 +1300462
Brian Paulecfaab82011-04-10 12:44:46 -0600463 if (texObj->Sampler.CompareFunc == params[0])
Roland Scheideggerebc14782009-04-02 23:38:34 +0200464 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700465 switch (params[0]) {
466 case GL_LEQUAL:
467 case GL_GEQUAL:
Brian Paul318e53a2009-01-27 11:07:21 -0700468 case GL_EQUAL:
469 case GL_NOTEQUAL:
470 case GL_LESS:
471 case GL_GREATER:
472 case GL_ALWAYS:
473 case GL_NEVER:
Ian Romanick927f5722013-06-27 18:20:34 -0700474 flush(ctx);
475 texObj->Sampler.CompareFunc = params[0];
476 return GL_TRUE;
Brian Paul318e53a2009-01-27 11:07:21 -0700477 default:
Brian Paul0f6b8e22011-01-25 18:27:44 -0700478 goto invalid_param;
Brian Paulae1fdc12008-06-11 20:05:53 -0600479 }
Brian Paul318e53a2009-01-27 11:07:21 -0700480 }
Brian Paul0f6b8e22011-01-25 18:27:44 -0700481 goto invalid_pname;
Brian Paul318e53a2009-01-27 11:07:21 -0700482
483 case GL_DEPTH_TEXTURE_MODE_ARB:
Ian Romanickb3dd5242012-07-26 18:04:50 -0700484 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has never
485 * existed in OpenGL ES.
486 */
Paul Berrydbd61352012-11-27 12:26:51 -0800487 if (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_depth_texture) {
Pauli Nieminenc37efbf2012-06-12 21:38:46 +0300488 if (texObj->DepthMode == params[0])
Brian Paul0f6b8e22011-01-25 18:27:44 -0700489 return GL_FALSE;
490 if (params[0] == GL_LUMINANCE ||
491 params[0] == GL_INTENSITY ||
492 params[0] == GL_ALPHA ||
493 (ctx->Extensions.ARB_texture_rg && params[0] == GL_RED)) {
Brian Paulf4dc24a2011-01-23 09:10:35 -0700494 flush(ctx);
Pauli Nieminenc37efbf2012-06-12 21:38:46 +0300495 texObj->DepthMode = params[0];
Roland Scheideggerebc14782009-04-02 23:38:34 +0200496 return GL_TRUE;
Brian Paul37c768b2009-02-09 13:50:36 -0700497 }
Brian Paul0f6b8e22011-01-25 18:27:44 -0700498 goto invalid_param;
Brian Paul318e53a2009-01-27 11:07:21 -0700499 }
Brian Paul0f6b8e22011-01-25 18:27:44 -0700500 goto invalid_pname;
Brian Paul318e53a2009-01-27 11:07:21 -0700501
Kenneth Graunke23e81b92014-02-23 21:59:24 -0800502 case GL_DEPTH_STENCIL_TEXTURE_MODE:
Ilia Mirkind33ef192016-02-11 15:21:02 -0500503 if (_mesa_has_ARB_stencil_texturing(ctx) || _mesa_is_gles31(ctx)) {
Kenneth Graunke23e81b92014-02-23 21:59:24 -0800504 bool stencil = params[0] == GL_STENCIL_INDEX;
505 if (!stencil && params[0] != GL_DEPTH_COMPONENT)
506 goto invalid_param;
507
508 if (texObj->StencilSampling == stencil)
509 return GL_FALSE;
510
511 texObj->StencilSampling = stencil;
512 return GL_TRUE;
513 }
514 goto invalid_pname;
515
Brian Paul318e53a2009-01-27 11:07:21 -0700516 case GL_TEXTURE_CROP_RECT_OES:
Ian Romanickb3dd5242012-07-26 18:04:50 -0700517 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
518 goto invalid_pname;
519
Brian Paul318e53a2009-01-27 11:07:21 -0700520 texObj->CropRect[0] = params[0];
521 texObj->CropRect[1] = params[1];
522 texObj->CropRect[2] = params[2];
523 texObj->CropRect[3] = params[3];
Roland Scheideggerebc14782009-04-02 23:38:34 +0200524 return GL_TRUE;
Brian Paulae1fdc12008-06-11 20:05:53 -0600525
Brian Paul4a89e512009-01-28 10:27:33 -0700526 case GL_TEXTURE_SWIZZLE_R_EXT:
527 case GL_TEXTURE_SWIZZLE_G_EXT:
528 case GL_TEXTURE_SWIZZLE_B_EXT:
529 case GL_TEXTURE_SWIZZLE_A_EXT:
Ian Romanickb3dd5242012-07-26 18:04:50 -0700530 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_swizzle)
531 || _mesa_is_gles3(ctx)) {
Brian Paul4a89e512009-01-28 10:27:33 -0700532 const GLuint comp = pname - GL_TEXTURE_SWIZZLE_R_EXT;
533 const GLint swz = comp_to_swizzle(params[0]);
Brian Paul72f0b4a2009-01-28 10:44:04 -0700534 if (swz < 0) {
Brian Paul475f5ff2014-04-24 14:44:03 -0600535 _mesa_error(ctx, GL_INVALID_ENUM,
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800536 "glTex%sParameter(swizzle 0x%x)", suffix, params[0]);
Roland Scheideggerebc14782009-04-02 23:38:34 +0200537 return GL_FALSE;
Brian Paul72f0b4a2009-01-28 10:44:04 -0700538 }
Matt Turnerbfcdb842015-02-20 20:18:47 -0800539 assert(comp < 4);
Yuanhan Liud9f05ac2011-10-21 11:24:18 +0800540
541 flush(ctx);
542 texObj->Swizzle[comp] = params[0];
543 set_swizzle_component(&texObj->_Swizzle, comp, swz);
544 return GL_TRUE;
Brian Paul4a89e512009-01-28 10:27:33 -0700545 }
Brian Paul0f6b8e22011-01-25 18:27:44 -0700546 goto invalid_pname;
Brian Paul4a89e512009-01-28 10:27:33 -0700547
548 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
Ian Romanickb3dd5242012-07-26 18:04:50 -0700549 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_swizzle)
550 || _mesa_is_gles3(ctx)) {
Brian Paul4a89e512009-01-28 10:27:33 -0700551 GLuint comp;
Brian Paulf4dc24a2011-01-23 09:10:35 -0700552 flush(ctx);
Brian Paul4a89e512009-01-28 10:27:33 -0700553 for (comp = 0; comp < 4; comp++) {
554 const GLint swz = comp_to_swizzle(params[comp]);
555 if (swz >= 0) {
556 texObj->Swizzle[comp] = params[comp];
557 set_swizzle_component(&texObj->_Swizzle, comp, swz);
558 }
559 else {
Brian Paul475f5ff2014-04-24 14:44:03 -0600560 _mesa_error(ctx, GL_INVALID_ENUM,
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800561 "glTex%sParameter(swizzle 0x%x)",
562 suffix, params[comp]);
Roland Scheideggerebc14782009-04-02 23:38:34 +0200563 return GL_FALSE;
Brian Paul4a89e512009-01-28 10:27:33 -0700564 }
565 }
Roland Scheideggerebc14782009-04-02 23:38:34 +0200566 return GL_TRUE;
Brian Paul4a89e512009-01-28 10:27:33 -0700567 }
Brian Paul0f6b8e22011-01-25 18:27:44 -0700568 goto invalid_pname;
569
Dave Airlieedc2dd82011-01-13 12:12:21 +1000570 case GL_TEXTURE_SRGB_DECODE_EXT:
Ilia Mirkin28751832016-02-20 15:58:19 -0500571 if (ctx->Extensions.EXT_texture_sRGB_decode) {
Chris Forbese0015c82013-03-15 22:52:12 +1300572 GLenum decode = params[0];
573
Alejandro Piñeiroa8736a22015-12-22 20:04:38 +0100574 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800575 goto invalid_enum;
Chris Forbese0015c82013-03-15 22:52:12 +1300576
Dave Airlieedc2dd82011-01-13 12:12:21 +1000577 if (decode == GL_DECODE_EXT || decode == GL_SKIP_DECODE_EXT) {
Brian Paulecfaab82011-04-10 12:44:46 -0600578 if (texObj->Sampler.sRGBDecode != decode) {
Brian Paulf4dc24a2011-01-23 09:10:35 -0700579 flush(ctx);
Brian Paulecfaab82011-04-10 12:44:46 -0600580 texObj->Sampler.sRGBDecode = decode;
Dave Airlieedc2dd82011-01-13 12:12:21 +1000581 }
582 return GL_TRUE;
583 }
584 }
Brian Paul0f6b8e22011-01-25 18:27:44 -0700585 goto invalid_pname;
586
Marek Olšáka19c42f2011-05-03 11:37:25 +0200587 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
Ian Romanickb3dd5242012-07-26 18:04:50 -0700588 if (_mesa_is_desktop_gl(ctx)
589 && ctx->Extensions.AMD_seamless_cubemap_per_texture) {
Marek Olšáka19c42f2011-05-03 11:37:25 +0200590 GLenum param = params[0];
Chris Forbese0015c82013-03-15 22:52:12 +1300591
Alejandro Piñeiroa8736a22015-12-22 20:04:38 +0100592 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800593 goto invalid_enum;
Chris Forbese0015c82013-03-15 22:52:12 +1300594
Marek Olšáka19c42f2011-05-03 11:37:25 +0200595 if (param != GL_TRUE && param != GL_FALSE) {
596 goto invalid_param;
597 }
598 if (param != texObj->Sampler.CubeMapSeamless) {
599 flush(ctx);
600 texObj->Sampler.CubeMapSeamless = param;
601 }
602 return GL_TRUE;
603 }
604 goto invalid_pname;
605
Brian Paul318e53a2009-01-27 11:07:21 -0700606 default:
Brian Paul0f6b8e22011-01-25 18:27:44 -0700607 goto invalid_pname;
Brian Paul318e53a2009-01-27 11:07:21 -0700608 }
Brian Paul0f6b8e22011-01-25 18:27:44 -0700609
610invalid_pname:
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800611 _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
Kenneth Graunke2f11e922015-07-18 01:22:00 -0700612 suffix, _mesa_enum_to_string(pname));
Brian Paul0f6b8e22011-01-25 18:27:44 -0700613 return GL_FALSE;
614
615invalid_param:
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800616 _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(param=%s)",
Kenneth Graunke2f11e922015-07-18 01:22:00 -0700617 suffix, _mesa_enum_to_string(params[0]));
Roland Scheideggerebc14782009-04-02 23:38:34 +0200618 return GL_FALSE;
Chris Forbese0015c82013-03-15 22:52:12 +1300619
620invalid_operation:
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800621 _mesa_error(ctx, GL_INVALID_OPERATION, "glTex%sParameter(pname=%s)",
Kenneth Graunke2f11e922015-07-18 01:22:00 -0700622 suffix, _mesa_enum_to_string(pname));
Laura Ekstrandf4dce7a2014-12-10 16:30:46 -0800623 return GL_FALSE;
624
625invalid_enum:
626 _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
Kenneth Graunke2f11e922015-07-18 01:22:00 -0700627 suffix, _mesa_enum_to_string(pname));
Chris Forbese0015c82013-03-15 22:52:12 +1300628 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700629}
630
631
Roland Scheideggerebc14782009-04-02 23:38:34 +0200632/**
633 * Set a float-valued texture parameter
634 * \return GL_TRUE if legal AND the value changed, GL_FALSE otherwise
635 */
636static GLboolean
Kristian Høgsbergf9995b32010-10-12 12:26:10 -0400637set_tex_parameterf(struct gl_context *ctx,
Brian Paul318e53a2009-01-27 11:07:21 -0700638 struct gl_texture_object *texObj,
Laura Ekstrand795ba442014-12-10 16:32:16 -0800639 GLenum pname, const GLfloat *params, bool dsa)
Brian Paul318e53a2009-01-27 11:07:21 -0700640{
Laura Ekstrand795ba442014-12-10 16:32:16 -0800641 const char *suffix = dsa ? "ture" : "";
642
Brian Paul318e53a2009-01-27 11:07:21 -0700643 switch (pname) {
644 case GL_TEXTURE_MIN_LOD:
Ian Romanickb3dd5242012-07-26 18:04:50 -0700645 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
646 goto invalid_pname;
647
Alejandro Piñeiroa8736a22015-12-22 20:04:38 +0100648 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
Laura Ekstrand795ba442014-12-10 16:32:16 -0800649 goto invalid_enum;
Chris Forbese0015c82013-03-15 22:52:12 +1300650
Brian Paulecfaab82011-04-10 12:44:46 -0600651 if (texObj->Sampler.MinLod == params[0])
Roland Scheideggerebc14782009-04-02 23:38:34 +0200652 return GL_FALSE;
Brian Paulf4dc24a2011-01-23 09:10:35 -0700653 flush(ctx);
Brian Paulecfaab82011-04-10 12:44:46 -0600654 texObj->Sampler.MinLod = params[0];
Roland Scheideggerebc14782009-04-02 23:38:34 +0200655 return GL_TRUE;
Brian Paul318e53a2009-01-27 11:07:21 -0700656
657 case GL_TEXTURE_MAX_LOD:
Ian Romanickb3dd5242012-07-26 18:04:50 -0700658 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
659 goto invalid_pname;
660
Alejandro Piñeiroa8736a22015-12-22 20:04:38 +0100661 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
Laura Ekstrand795ba442014-12-10 16:32:16 -0800662 goto invalid_enum;
Chris Forbese0015c82013-03-15 22:52:12 +1300663
Brian Paulecfaab82011-04-10 12:44:46 -0600664 if (texObj->Sampler.MaxLod == params[0])
Roland Scheideggerebc14782009-04-02 23:38:34 +0200665 return GL_FALSE;
Brian Paulf4dc24a2011-01-23 09:10:35 -0700666 flush(ctx);
Brian Paulecfaab82011-04-10 12:44:46 -0600667 texObj->Sampler.MaxLod = params[0];
Roland Scheideggerebc14782009-04-02 23:38:34 +0200668 return GL_TRUE;
Brian Paul318e53a2009-01-27 11:07:21 -0700669
670 case GL_TEXTURE_PRIORITY:
Paul Berrydbd61352012-11-27 12:26:51 -0800671 if (ctx->API != API_OPENGL_COMPAT)
Ian Romanickb3dd5242012-07-26 18:04:50 -0700672 goto invalid_pname;
673
Brian Paulf4dc24a2011-01-23 09:10:35 -0700674 flush(ctx);
Brian Paul318e53a2009-01-27 11:07:21 -0700675 texObj->Priority = CLAMP(params[0], 0.0F, 1.0F);
Roland Scheideggerebc14782009-04-02 23:38:34 +0200676 return GL_TRUE;
Brian Paul318e53a2009-01-27 11:07:21 -0700677
678 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
679 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
Alejandro Piñeiroa8736a22015-12-22 20:04:38 +0100680 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
Laura Ekstrand795ba442014-12-10 16:32:16 -0800681 goto invalid_enum;
Chris Forbese0015c82013-03-15 22:52:12 +1300682
Brian Paulecfaab82011-04-10 12:44:46 -0600683 if (texObj->Sampler.MaxAnisotropy == params[0])
Roland Scheideggerebc14782009-04-02 23:38:34 +0200684 return GL_FALSE;
Matt Turnera5623132015-07-12 23:15:42 -0700685 if (params[0] < 1.0F) {
Laura Ekstrand795ba442014-12-10 16:32:16 -0800686 _mesa_error(ctx, GL_INVALID_VALUE, "glTex%sParameter(param)",
687 suffix);
Roland Scheideggerebc14782009-04-02 23:38:34 +0200688 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700689 }
Brian Paulf4dc24a2011-01-23 09:10:35 -0700690 flush(ctx);
Brian Paul318e53a2009-01-27 11:07:21 -0700691 /* clamp to max, that's what NVIDIA does */
Brian Paulecfaab82011-04-10 12:44:46 -0600692 texObj->Sampler.MaxAnisotropy = MIN2(params[0],
Brian Paul318e53a2009-01-27 11:07:21 -0700693 ctx->Const.MaxTextureMaxAnisotropy);
Roland Scheideggerebc14782009-04-02 23:38:34 +0200694 return GL_TRUE;
Brian Paul318e53a2009-01-27 11:07:21 -0700695 }
696 else {
Brian Paul74bec422009-05-06 09:01:47 -0600697 static GLuint count = 0;
698 if (count++ < 10)
Ian Romanickb3dd5242012-07-26 18:04:50 -0700699 goto invalid_pname;
Brian Paul318e53a2009-01-27 11:07:21 -0700700 }
Roland Scheideggerebc14782009-04-02 23:38:34 +0200701 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700702
Brian Paul318e53a2009-01-27 11:07:21 -0700703 case GL_TEXTURE_LOD_BIAS:
Tapani Pälli7e61b442013-11-20 13:27:10 +0200704 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias. */
705 if (_mesa_is_gles(ctx))
Ian Romanickb3dd5242012-07-26 18:04:50 -0700706 goto invalid_pname;
707
Alejandro Piñeiroa8736a22015-12-22 20:04:38 +0100708 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
Laura Ekstrand795ba442014-12-10 16:32:16 -0800709 goto invalid_enum;
Chris Forbese0015c82013-03-15 22:52:12 +1300710
Ian Romanickf9a23522011-08-30 17:33:51 -0700711 if (texObj->Sampler.LodBias != params[0]) {
712 flush(ctx);
713 texObj->Sampler.LodBias = params[0];
714 return GL_TRUE;
Brian Paul318e53a2009-01-27 11:07:21 -0700715 }
716 break;
717
718 case GL_TEXTURE_BORDER_COLOR:
Ilia Mirkinb6654832016-02-15 19:09:15 -0500719 if (ctx->API == API_OPENGLES ||
720 !ctx->Extensions.ARB_texture_border_clamp)
Ian Romanickb3dd5242012-07-26 18:04:50 -0700721 goto invalid_pname;
722
Alejandro Piñeiroa8736a22015-12-22 20:04:38 +0100723 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target))
Laura Ekstrand795ba442014-12-10 16:32:16 -0800724 goto invalid_enum;
Chris Forbese0015c82013-03-15 22:52:12 +1300725
Brian Paulf4dc24a2011-01-23 09:10:35 -0700726 flush(ctx);
Marek Olšáke28fe8f2011-03-26 13:06:22 +0100727 /* ARB_texture_float disables clamping */
728 if (ctx->Extensions.ARB_texture_float) {
Brian Paulecfaab82011-04-10 12:44:46 -0600729 texObj->Sampler.BorderColor.f[RCOMP] = params[0];
730 texObj->Sampler.BorderColor.f[GCOMP] = params[1];
731 texObj->Sampler.BorderColor.f[BCOMP] = params[2];
732 texObj->Sampler.BorderColor.f[ACOMP] = params[3];
Marek Olšáke28fe8f2011-03-26 13:06:22 +0100733 } else {
Brian Paulecfaab82011-04-10 12:44:46 -0600734 texObj->Sampler.BorderColor.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F);
735 texObj->Sampler.BorderColor.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F);
736 texObj->Sampler.BorderColor.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F);
737 texObj->Sampler.BorderColor.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F);
Marek Olšáke28fe8f2011-03-26 13:06:22 +0100738 }
Roland Scheideggerebc14782009-04-02 23:38:34 +0200739 return GL_TRUE;
Brian Paul318e53a2009-01-27 11:07:21 -0700740
741 default:
Ian Romanickb3dd5242012-07-26 18:04:50 -0700742 goto invalid_pname;
Brian Paul318e53a2009-01-27 11:07:21 -0700743 }
Roland Scheideggerebc14782009-04-02 23:38:34 +0200744 return GL_FALSE;
Ian Romanickb3dd5242012-07-26 18:04:50 -0700745
746invalid_pname:
Laura Ekstrand795ba442014-12-10 16:32:16 -0800747 _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
Kenneth Graunke2f11e922015-07-18 01:22:00 -0700748 suffix, _mesa_enum_to_string(pname));
Ian Romanickb3dd5242012-07-26 18:04:50 -0700749 return GL_FALSE;
Chris Forbese0015c82013-03-15 22:52:12 +1300750
Laura Ekstrand795ba442014-12-10 16:32:16 -0800751invalid_enum:
752 _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameter(pname=%s)",
Kenneth Graunke2f11e922015-07-18 01:22:00 -0700753 suffix, _mesa_enum_to_string(pname));
Chris Forbese0015c82013-03-15 22:52:12 +1300754 return GL_FALSE;
Brian Paul318e53a2009-01-27 11:07:21 -0700755}
756
757
Laura Ekstrandabc688e2014-12-10 16:33:18 -0800758void
759_mesa_texture_parameterf(struct gl_context *ctx,
760 struct gl_texture_object *texObj,
761 GLenum pname, GLfloat param, bool dsa)
Brian Paul318e53a2009-01-27 11:07:21 -0700762{
Roland Scheideggerebc14782009-04-02 23:38:34 +0200763 GLboolean need_update;
Brian Paul318e53a2009-01-27 11:07:21 -0700764
765 switch (pname) {
766 case GL_TEXTURE_MIN_FILTER:
767 case GL_TEXTURE_MAG_FILTER:
768 case GL_TEXTURE_WRAP_S:
769 case GL_TEXTURE_WRAP_T:
770 case GL_TEXTURE_WRAP_R:
771 case GL_TEXTURE_BASE_LEVEL:
772 case GL_TEXTURE_MAX_LEVEL:
Brian Paul318e53a2009-01-27 11:07:21 -0700773 case GL_GENERATE_MIPMAP_SGIS:
774 case GL_TEXTURE_COMPARE_MODE_ARB:
775 case GL_TEXTURE_COMPARE_FUNC_ARB:
776 case GL_DEPTH_TEXTURE_MODE_ARB:
Kenneth Graunke23e81b92014-02-23 21:59:24 -0800777 case GL_DEPTH_STENCIL_TEXTURE_MODE:
Dave Airlieedc2dd82011-01-13 12:12:21 +1000778 case GL_TEXTURE_SRGB_DECODE_EXT:
Marek Olšáka19c42f2011-05-03 11:37:25 +0200779 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
Yuanhan Liu77cd3bf2011-10-21 11:27:25 +0800780 case GL_TEXTURE_SWIZZLE_R_EXT:
781 case GL_TEXTURE_SWIZZLE_G_EXT:
782 case GL_TEXTURE_SWIZZLE_B_EXT:
783 case GL_TEXTURE_SWIZZLE_A_EXT:
784 {
785 GLint p[4];
Anuj Phogatd0ce8d62013-01-07 10:30:11 +0530786 p[0] = (param > 0) ?
787 ((param > INT_MAX) ? INT_MAX : (GLint) (param + 0.5)) :
788 ((param < INT_MIN) ? INT_MIN : (GLint) (param - 0.5));
789
Yuanhan Liu77cd3bf2011-10-21 11:27:25 +0800790 p[1] = p[2] = p[3] = 0;
Laura Ekstrandabc688e2014-12-10 16:33:18 -0800791 need_update = set_tex_parameteri(ctx, texObj, pname, p, dsa);
Yuanhan Liu77cd3bf2011-10-21 11:27:25 +0800792 }
793 break;
Laura Ekstrandabc688e2014-12-10 16:33:18 -0800794 case GL_TEXTURE_BORDER_COLOR:
795 case GL_TEXTURE_SWIZZLE_RGBA:
796 _mesa_error(ctx, GL_INVALID_ENUM, "glTex%sParameterf(non-scalar pname)",
797 dsa ? "ture" : "");
798 return;
Brian Paul318e53a2009-01-27 11:07:21 -0700799 default:
Vinson Lee270d36d2009-11-29 21:17:44 -0500800 {
801 /* this will generate an error if pname is illegal */
802 GLfloat p[4];
803 p[0] = param;
804 p[1] = p[2] = p[3] = 0.0F;
Laura Ekstrandabc688e2014-12-10 16:33:18 -0800805 need_update = set_tex_parameterf(ctx, texObj, pname, p, dsa);
Vinson Lee270d36d2009-11-29 21:17:44 -0500806 }
Brian Paulae1fdc12008-06-11 20:05:53 -0600807 }
808
Roland Scheideggerebc14782009-04-02 23:38:34 +0200809 if (ctx->Driver.TexParameter && need_update) {
Brian Paula710c212016-10-07 14:28:21 -0600810 ctx->Driver.TexParameter(ctx, texObj, pname);
Brian Paulae1fdc12008-06-11 20:05:53 -0600811 }
812}
813
814
Laura Ekstrand2ce5db32014-12-10 16:19:21 -0800815void
816_mesa_texture_parameterfv(struct gl_context *ctx,
817 struct gl_texture_object *texObj,
818 GLenum pname, const GLfloat *params, bool dsa)
Brian Paulae1fdc12008-06-11 20:05:53 -0600819{
Roland Scheideggerebc14782009-04-02 23:38:34 +0200820 GLboolean need_update;
Brian Paul318e53a2009-01-27 11:07:21 -0700821 switch (pname) {
822 case GL_TEXTURE_MIN_FILTER:
823 case GL_TEXTURE_MAG_FILTER:
824 case GL_TEXTURE_WRAP_S:
825 case GL_TEXTURE_WRAP_T:
826 case GL_TEXTURE_WRAP_R:
827 case GL_TEXTURE_BASE_LEVEL:
828 case GL_TEXTURE_MAX_LEVEL:
Brian Paul318e53a2009-01-27 11:07:21 -0700829 case GL_GENERATE_MIPMAP_SGIS:
830 case GL_TEXTURE_COMPARE_MODE_ARB:
831 case GL_TEXTURE_COMPARE_FUNC_ARB:
832 case GL_DEPTH_TEXTURE_MODE_ARB:
Kenneth Graunke23e81b92014-02-23 21:59:24 -0800833 case GL_DEPTH_STENCIL_TEXTURE_MODE:
Dave Airlieedc2dd82011-01-13 12:12:21 +1000834 case GL_TEXTURE_SRGB_DECODE_EXT:
Marek Olšáka19c42f2011-05-03 11:37:25 +0200835 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
Brian Paul318e53a2009-01-27 11:07:21 -0700836 {
837 /* convert float param to int */
Vinson Leed88f3b92009-12-08 14:31:38 -0800838 GLint p[4];
839 p[0] = (GLint) params[0];
840 p[1] = p[2] = p[3] = 0;
Laura Ekstrand2ce5db32014-12-10 16:19:21 -0800841 need_update = set_tex_parameteri(ctx, texObj, pname, p, dsa);
Brian Paul318e53a2009-01-27 11:07:21 -0700842 }
843 break;
Brian Paul318e53a2009-01-27 11:07:21 -0700844 case GL_TEXTURE_CROP_RECT_OES:
845 {
846 /* convert float params to int */
847 GLint iparams[4];
848 iparams[0] = (GLint) params[0];
849 iparams[1] = (GLint) params[1];
850 iparams[2] = (GLint) params[2];
851 iparams[3] = (GLint) params[3];
Laura Ekstrand2ce5db32014-12-10 16:19:21 -0800852 need_update = set_tex_parameteri(ctx, texObj, pname, iparams, dsa);
Brian Paul318e53a2009-01-27 11:07:21 -0700853 }
854 break;
Yuanhan Liu77cd3bf2011-10-21 11:27:25 +0800855 case GL_TEXTURE_SWIZZLE_R_EXT:
856 case GL_TEXTURE_SWIZZLE_G_EXT:
857 case GL_TEXTURE_SWIZZLE_B_EXT:
858 case GL_TEXTURE_SWIZZLE_A_EXT:
859 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
860 {
861 GLint p[4] = {0, 0, 0, 0};
862 p[0] = (GLint) params[0];
863 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT) {
864 p[1] = (GLint) params[1];
865 p[2] = (GLint) params[2];
866 p[3] = (GLint) params[3];
867 }
Laura Ekstrand2ce5db32014-12-10 16:19:21 -0800868 need_update = set_tex_parameteri(ctx, texObj, pname, p, dsa);
Yuanhan Liu77cd3bf2011-10-21 11:27:25 +0800869 }
870 break;
Brian Paul318e53a2009-01-27 11:07:21 -0700871 default:
872 /* this will generate an error if pname is illegal */
Laura Ekstrand2ce5db32014-12-10 16:19:21 -0800873 need_update = set_tex_parameterf(ctx, texObj, pname, params, dsa);
Brian Paul318e53a2009-01-27 11:07:21 -0700874 }
875
Roland Scheideggerebc14782009-04-02 23:38:34 +0200876 if (ctx->Driver.TexParameter && need_update) {
Brian Paula710c212016-10-07 14:28:21 -0600877 ctx->Driver.TexParameter(ctx, texObj, pname);
Brian Paul318e53a2009-01-27 11:07:21 -0700878 }
Brian Paulae1fdc12008-06-11 20:05:53 -0600879}
880
881
Laura Ekstrand354d7892015-01-05 16:48:34 -0800882void
883_mesa_texture_parameteri(struct gl_context *ctx,
884 struct gl_texture_object *texObj,
885 GLenum pname, GLint param, bool dsa)
Brian Paulae1fdc12008-06-11 20:05:53 -0600886{
Roland Scheideggerebc14782009-04-02 23:38:34 +0200887 GLboolean need_update;
Brian Paul318e53a2009-01-27 11:07:21 -0700888 switch (pname) {
889 case GL_TEXTURE_MIN_LOD:
890 case GL_TEXTURE_MAX_LOD:
891 case GL_TEXTURE_PRIORITY:
892 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
893 case GL_TEXTURE_LOD_BIAS:
Brian Paul26da28c2009-01-28 16:49:28 -0700894 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
Brian Paul318e53a2009-01-27 11:07:21 -0700895 {
Vinson Leea1d46fb2009-12-08 15:42:13 -0800896 GLfloat fparam[4];
897 fparam[0] = (GLfloat) param;
898 fparam[1] = fparam[2] = fparam[3] = 0.0F;
Brian Paul318e53a2009-01-27 11:07:21 -0700899 /* convert int param to float */
Laura Ekstrand354d7892015-01-05 16:48:34 -0800900 need_update = set_tex_parameterf(ctx, texObj, pname, fparam, dsa);
Brian Paul318e53a2009-01-27 11:07:21 -0700901 }
902 break;
Laura Ekstrand354d7892015-01-05 16:48:34 -0800903 case GL_TEXTURE_BORDER_COLOR:
904 case GL_TEXTURE_SWIZZLE_RGBA:
905 {
906 _mesa_error(ctx, GL_INVALID_ENUM,
907 "glTex%sParameteri(non-scalar pname)",
908 dsa ? "ture" : "");
909 return;
910 }
Brian Paul318e53a2009-01-27 11:07:21 -0700911 default:
912 /* this will generate an error if pname is illegal */
Vinson Lee3f7c2ac2009-12-08 17:25:05 -0800913 {
914 GLint iparam[4];
915 iparam[0] = param;
916 iparam[1] = iparam[2] = iparam[3] = 0;
Laura Ekstrand354d7892015-01-05 16:48:34 -0800917 need_update = set_tex_parameteri(ctx, texObj, pname, iparam, dsa);
Vinson Lee3f7c2ac2009-12-08 17:25:05 -0800918 }
Brian Paulae1fdc12008-06-11 20:05:53 -0600919 }
Brian Paul318e53a2009-01-27 11:07:21 -0700920
Roland Scheideggerebc14782009-04-02 23:38:34 +0200921 if (ctx->Driver.TexParameter && need_update) {
Brian Paula710c212016-10-07 14:28:21 -0600922 ctx->Driver.TexParameter(ctx, texObj, pname);
Brian Paul1b7e9092008-08-12 17:41:57 -0600923 }
Brian Paul318e53a2009-01-27 11:07:21 -0700924}
925
926
Laura Ekstrandd954f602014-12-10 16:57:50 -0800927void
928_mesa_texture_parameteriv(struct gl_context *ctx,
929 struct gl_texture_object *texObj,
930 GLenum pname, const GLint *params, bool dsa)
Brian Paul318e53a2009-01-27 11:07:21 -0700931{
Roland Scheideggerebc14782009-04-02 23:38:34 +0200932 GLboolean need_update;
Brian Paul318e53a2009-01-27 11:07:21 -0700933
934 switch (pname) {
935 case GL_TEXTURE_BORDER_COLOR:
936 {
Samuel Iglesias Gonsálvez308b06d2016-11-07 11:49:13 +0100937 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target)) {
938 _mesa_error(ctx, GL_INVALID_ENUM, "glTextureParameteriv(texture)");
939 return;
940 }
Brian Paul318e53a2009-01-27 11:07:21 -0700941 /* convert int params to float */
942 GLfloat fparams[4];
943 fparams[0] = INT_TO_FLOAT(params[0]);
944 fparams[1] = INT_TO_FLOAT(params[1]);
945 fparams[2] = INT_TO_FLOAT(params[2]);
946 fparams[3] = INT_TO_FLOAT(params[3]);
Laura Ekstrandd954f602014-12-10 16:57:50 -0800947 need_update = set_tex_parameterf(ctx, texObj, pname, fparams, dsa);
Brian Paul318e53a2009-01-27 11:07:21 -0700948 }
949 break;
950 case GL_TEXTURE_MIN_LOD:
951 case GL_TEXTURE_MAX_LOD:
952 case GL_TEXTURE_PRIORITY:
953 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
954 case GL_TEXTURE_LOD_BIAS:
Brian Paul26da28c2009-01-28 16:49:28 -0700955 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
Brian Paul318e53a2009-01-27 11:07:21 -0700956 {
957 /* convert int param to float */
Vinson Leedcb4a372009-12-10 12:11:09 -0800958 GLfloat fparams[4];
959 fparams[0] = (GLfloat) params[0];
960 fparams[1] = fparams[2] = fparams[3] = 0.0F;
Laura Ekstrandd954f602014-12-10 16:57:50 -0800961 need_update = set_tex_parameterf(ctx, texObj, pname, fparams, dsa);
Brian Paul318e53a2009-01-27 11:07:21 -0700962 }
963 break;
964 default:
965 /* this will generate an error if pname is illegal */
Laura Ekstrandd954f602014-12-10 16:57:50 -0800966 need_update = set_tex_parameteri(ctx, texObj, pname, params, dsa);
Brian Paulae1fdc12008-06-11 20:05:53 -0600967 }
Brian Paul318e53a2009-01-27 11:07:21 -0700968
Roland Scheideggerebc14782009-04-02 23:38:34 +0200969 if (ctx->Driver.TexParameter && need_update) {
Brian Paula710c212016-10-07 14:28:21 -0600970 ctx->Driver.TexParameter(ctx, texObj, pname);
Brian Paul318e53a2009-01-27 11:07:21 -0700971 }
Brian Paulae1fdc12008-06-11 20:05:53 -0600972}
973
Laura Ekstrandd954f602014-12-10 16:57:50 -0800974void
975_mesa_texture_parameterIiv(struct gl_context *ctx,
976 struct gl_texture_object *texObj,
977 GLenum pname, const GLint *params, bool dsa)
978{
979 switch (pname) {
980 case GL_TEXTURE_BORDER_COLOR:
Samuel Iglesias Gonsálvez308b06d2016-11-07 11:49:13 +0100981 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target)) {
982 _mesa_error(ctx, GL_INVALID_ENUM, "glTextureParameterIiv(texture)");
983 return;
984 }
Laura Ekstrandd954f602014-12-10 16:57:50 -0800985 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
986 /* set the integer-valued border color */
987 COPY_4V(texObj->Sampler.BorderColor.i, params);
988 break;
989 default:
990 _mesa_texture_parameteriv(ctx, texObj, pname, params, dsa);
991 break;
992 }
993 /* XXX no driver hook for TexParameterIiv() yet */
994}
995
996void
997_mesa_texture_parameterIuiv(struct gl_context *ctx,
998 struct gl_texture_object *texObj,
999 GLenum pname, const GLuint *params, bool dsa)
1000{
1001 switch (pname) {
1002 case GL_TEXTURE_BORDER_COLOR:
Samuel Iglesias Gonsálvez308b06d2016-11-07 11:49:13 +01001003 if (!_mesa_target_allows_setting_sampler_parameters(texObj->Target)) {
1004 _mesa_error(ctx, GL_INVALID_ENUM, "glTextureParameterIuiv(texture)");
1005 return;
1006 }
Laura Ekstrandd954f602014-12-10 16:57:50 -08001007 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1008 /* set the unsigned integer-valued border color */
1009 COPY_4V(texObj->Sampler.BorderColor.ui, params);
1010 break;
1011 default:
1012 _mesa_texture_parameteriv(ctx, texObj, pname, (const GLint *) params,
1013 dsa);
1014 break;
1015 }
1016 /* XXX no driver hook for TexParameterIuiv() yet */
1017}
1018
Laura Ekstrandabc688e2014-12-10 16:33:18 -08001019void GLAPIENTRY
1020_mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param)
1021{
1022 struct gl_texture_object *texObj;
1023 GET_CURRENT_CONTEXT(ctx);
1024
1025 texObj = get_texobj_by_target(ctx, target, GL_FALSE);
1026 if (!texObj)
1027 return;
1028
1029 _mesa_texture_parameterf(ctx, texObj, pname, param, false);
1030}
1031
Laura Ekstrand2ce5db32014-12-10 16:19:21 -08001032void GLAPIENTRY
1033_mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1034{
1035 struct gl_texture_object *texObj;
1036 GET_CURRENT_CONTEXT(ctx);
1037
1038 texObj = get_texobj_by_target(ctx, target, GL_FALSE);
1039 if (!texObj)
1040 return;
1041
1042 _mesa_texture_parameterfv(ctx, texObj, pname, params, false);
1043}
1044
Laura Ekstrand354d7892015-01-05 16:48:34 -08001045void GLAPIENTRY
1046_mesa_TexParameteri(GLenum target, GLenum pname, GLint param)
1047{
1048 struct gl_texture_object *texObj;
1049 GET_CURRENT_CONTEXT(ctx);
1050
1051 texObj = get_texobj_by_target(ctx, target, GL_FALSE);
1052 if (!texObj)
1053 return;
1054
1055 _mesa_texture_parameteri(ctx, texObj, pname, param, false);
1056}
1057
Laura Ekstrandd954f602014-12-10 16:57:50 -08001058void GLAPIENTRY
1059_mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params)
1060{
1061 struct gl_texture_object *texObj;
1062 GET_CURRENT_CONTEXT(ctx);
1063
1064 texObj = get_texobj_by_target(ctx, target, GL_FALSE);
1065 if (!texObj)
1066 return;
1067
1068 _mesa_texture_parameteriv(ctx, texObj, pname, params, false);
1069}
1070
Brian Paul7836a962010-01-04 20:00:00 -07001071/**
1072 * Set tex parameter to integer value(s). Primarily intended to set
1073 * integer-valued texture border color (for integer-valued textures).
1074 * New in GL 3.0.
1075 */
1076void GLAPIENTRY
1077_mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params)
1078{
1079 struct gl_texture_object *texObj;
1080 GET_CURRENT_CONTEXT(ctx);
Brian Paul7836a962010-01-04 20:00:00 -07001081
Laura Ekstrand5ad53932014-12-10 16:13:31 -08001082 texObj = get_texobj_by_target(ctx, target, GL_FALSE);
Brian Paul7836a962010-01-04 20:00:00 -07001083 if (!texObj)
1084 return;
1085
Laura Ekstrandd954f602014-12-10 16:57:50 -08001086 _mesa_texture_parameterIiv(ctx, texObj, pname, params, false);
Brian Paul7836a962010-01-04 20:00:00 -07001087}
1088
Brian Paul7836a962010-01-04 20:00:00 -07001089/**
1090 * Set tex parameter to unsigned integer value(s). Primarily intended to set
1091 * uint-valued texture border color (for integer-valued textures).
1092 * New in GL 3.0
1093 */
1094void GLAPIENTRY
1095_mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
1096{
1097 struct gl_texture_object *texObj;
1098 GET_CURRENT_CONTEXT(ctx);
Brian Paul7836a962010-01-04 20:00:00 -07001099
Laura Ekstrand5ad53932014-12-10 16:13:31 -08001100 texObj = get_texobj_by_target(ctx, target, GL_FALSE);
Brian Paul7836a962010-01-04 20:00:00 -07001101 if (!texObj)
1102 return;
1103
Laura Ekstrandd954f602014-12-10 16:57:50 -08001104 _mesa_texture_parameterIuiv(ctx, texObj, pname, params, false);
Brian Paul7836a962010-01-04 20:00:00 -07001105}
1106
Laura Ekstrand2ce5db32014-12-10 16:19:21 -08001107
1108void GLAPIENTRY
1109_mesa_TextureParameterfv(GLuint texture, GLenum pname, const GLfloat *params)
1110{
1111 struct gl_texture_object *texObj;
1112 GET_CURRENT_CONTEXT(ctx);
1113
1114 texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
1115 if (!texObj) {
1116 /* User passed a non-generated name. */
1117 _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterfv(texture)");
1118 return;
1119 }
1120
1121 _mesa_texture_parameterfv(ctx, texObj, pname, params, true);
1122}
1123
Laura Ekstrandabc688e2014-12-10 16:33:18 -08001124void GLAPIENTRY
1125_mesa_TextureParameterf(GLuint texture, GLenum pname, GLfloat param)
1126{
1127 struct gl_texture_object *texObj;
1128 GET_CURRENT_CONTEXT(ctx);
1129
1130 texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
1131 if (!texObj) {
1132 /* User passed a non-generated name. */
1133 _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameterf(texture)");
1134 return;
1135 }
1136
1137 _mesa_texture_parameterf(ctx, texObj, pname, param, true);
1138}
Brian Paul7836a962010-01-04 20:00:00 -07001139
Laura Ekstrand354d7892015-01-05 16:48:34 -08001140void GLAPIENTRY
1141_mesa_TextureParameteri(GLuint texture, GLenum pname, GLint param)
1142{
1143 struct gl_texture_object *texObj;
1144 GET_CURRENT_CONTEXT(ctx);
1145
1146 texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
1147 if (!texObj) {
1148 /* User passed a non-generated name. */
1149 _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameteri(texture)");
1150 return;
1151 }
1152
1153 _mesa_texture_parameteri(ctx, texObj, pname, param, true);
1154}
1155
Laura Ekstrandd954f602014-12-10 16:57:50 -08001156void GLAPIENTRY
1157_mesa_TextureParameteriv(GLuint texture, GLenum pname,
1158 const GLint *params)
1159{
1160 struct gl_texture_object *texObj;
1161 GET_CURRENT_CONTEXT(ctx);
1162
1163 texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
1164 if (!texObj) {
1165 /* User passed a non-generated name. */
1166 _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureParameteriv(texture)");
1167 return;
1168 }
1169
1170 _mesa_texture_parameteriv(ctx, texObj, pname, params, true);
1171}
1172
1173
1174void GLAPIENTRY
1175_mesa_TextureParameterIiv(GLuint texture, GLenum pname, const GLint *params)
1176{
1177 struct gl_texture_object *texObj;
1178 GET_CURRENT_CONTEXT(ctx);
1179
1180 texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
1181 if (!texObj) {
1182 /* User passed a non-generated name. */
1183 _mesa_error(ctx, GL_INVALID_OPERATION,
1184 "glTextureParameterIiv(texture)");
1185 return;
1186 }
1187
1188 _mesa_texture_parameterIiv(ctx, texObj, pname, params, true);
1189}
1190
1191void GLAPIENTRY
1192_mesa_TextureParameterIuiv(GLuint texture, GLenum pname, const GLuint *params)
1193{
1194 struct gl_texture_object *texObj;
1195 GET_CURRENT_CONTEXT(ctx);
1196
1197 texObj = get_texobj_by_name(ctx, texture, GL_FALSE);
1198 if (!texObj) {
1199 /* User passed a non-generated name. */
1200 _mesa_error(ctx, GL_INVALID_OPERATION,
1201 "glTextureParameterIuiv(texture)");
1202 return;
1203 }
1204
1205 _mesa_texture_parameterIuiv(ctx, texObj, pname, params, true);
1206}
1207
Antia Puentesf1c789f2015-11-30 20:37:24 +01001208GLboolean
1209_mesa_legal_get_tex_level_parameter_target(struct gl_context *ctx, GLenum target,
1210 bool dsa)
Kenneth Graunke9e4fde82012-06-10 18:41:58 -07001211{
Tapani Pällie0c2ea02015-07-28 11:25:35 +03001212 /* Common targets for desktop GL and GLES 3.1. */
Kenneth Graunke9e4fde82012-06-10 18:41:58 -07001213 switch (target) {
Kenneth Graunke9e4fde82012-06-10 18:41:58 -07001214 case GL_TEXTURE_2D:
Kenneth Graunke9e4fde82012-06-10 18:41:58 -07001215 case GL_TEXTURE_3D:
Kenneth Graunke9e4fde82012-06-10 18:41:58 -07001216 return GL_TRUE;
Tapani Pällie0c2ea02015-07-28 11:25:35 +03001217 case GL_TEXTURE_2D_ARRAY_EXT:
1218 return ctx->Extensions.EXT_texture_array;
Brian Paul6a086732016-02-11 07:45:50 -07001219 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1220 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1221 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1222 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1223 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1224 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
Tapani Pällie0c2ea02015-07-28 11:25:35 +03001225 return ctx->Extensions.ARB_texture_cube_map;
1226 case GL_TEXTURE_2D_MULTISAMPLE:
Tapani Pälli16ad1d22015-08-24 10:09:52 +03001227 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
Tapani Pällie0c2ea02015-07-28 11:25:35 +03001228 return ctx->Extensions.ARB_texture_multisample;
Ilia Mirkinb4c0c512016-02-27 16:16:28 -05001229 case GL_TEXTURE_BUFFER:
1230 /* GetTexLevelParameter accepts GL_TEXTURE_BUFFER in GL 3.1+ contexts,
1231 * but not in earlier versions that expose ARB_texture_buffer_object.
1232 *
1233 * From the ARB_texture_buffer_object spec:
1234 * "(7) Do buffer textures support texture parameters (TexParameter) or
1235 * queries (GetTexParameter, GetTexLevelParameter, GetTexImage)?
1236 *
1237 * RESOLVED: No. [...] Note that the spec edits above don't add
1238 * explicit error language for any of these cases. That is because
1239 * each of the functions enumerate the set of valid <target>
1240 * parameters. Not editing the spec to allow TEXTURE_BUFFER_ARB in
1241 * these cases means that target is not legal, and an INVALID_ENUM
1242 * error should be generated."
1243 *
1244 * From the OpenGL 3.1 spec:
1245 * "target may also be TEXTURE_BUFFER, indicating the texture buffer."
1246 */
1247 return (ctx->API == API_OPENGL_CORE && ctx->Version >= 31) ||
1248 _mesa_has_OES_texture_buffer(ctx);
Ian Romanickdc4f53b2016-08-17 10:20:34 +01001249 case GL_TEXTURE_CUBE_MAP_ARRAY:
1250 return _mesa_has_texture_cube_map_array(ctx);
Tapani Pällie0c2ea02015-07-28 11:25:35 +03001251 }
1252
1253 if (!_mesa_is_desktop_gl(ctx))
1254 return GL_FALSE;
1255
1256 /* Rest of the desktop GL targets. */
1257 switch (target) {
1258 case GL_TEXTURE_1D:
1259 case GL_PROXY_TEXTURE_1D:
1260 case GL_PROXY_TEXTURE_2D:
1261 case GL_PROXY_TEXTURE_3D:
1262 return GL_TRUE;
Brian Paul6a086732016-02-11 07:45:50 -07001263 case GL_PROXY_TEXTURE_CUBE_MAP:
Kenneth Graunke9e4fde82012-06-10 18:41:58 -07001264 return ctx->Extensions.ARB_texture_cube_map;
Ian Romanickdc4f53b2016-08-17 10:20:34 +01001265 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY:
Anuj Phogat6bd24722014-02-14 17:27:29 -08001266 return ctx->Extensions.ARB_texture_cube_map_array;
Kenneth Graunke9e4fde82012-06-10 18:41:58 -07001267 case GL_TEXTURE_RECTANGLE_NV:
1268 case GL_PROXY_TEXTURE_RECTANGLE_NV:
1269 return ctx->Extensions.NV_texture_rectangle;
1270 case GL_TEXTURE_1D_ARRAY_EXT:
1271 case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
Kenneth Graunke9e4fde82012-06-10 18:41:58 -07001272 case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
Ian Romanick538a7f22013-11-20 13:41:23 -08001273 return ctx->Extensions.EXT_texture_array;
Mikko Juola8624a512013-07-30 20:39:00 +03001274 case GL_PROXY_TEXTURE_2D_MULTISAMPLE:
1275 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY:
Chris Forbesd04a4dd2012-11-24 21:46:56 +13001276 return ctx->Extensions.ARB_texture_multisample;
Laura Ekstrandbf5c5882014-12-10 16:55:52 -08001277
1278 /* This is a valid target for dsa, but the OpenGL 4.5 core spec
1279 * (30.10.2014) Section 8.11 Texture Queries says:
1280 * "For GetTextureLevelParameter* only, texture may also be a cube
1281 * map texture object. In this case the query is always performed
1282 * for face zero (the TEXTURE_CUBE_MAP_POSITIVE_X face), since there
1283 * is no way to specify another face."
1284 */
1285 case GL_TEXTURE_CUBE_MAP:
1286 return dsa;
Kenneth Graunke9e4fde82012-06-10 18:41:58 -07001287 default:
1288 return GL_FALSE;
1289 }
1290}
1291
1292
Kenneth Graunke8c37fc12012-06-11 01:27:38 -07001293static void
1294get_tex_level_parameter_image(struct gl_context *ctx,
Brian Paul1a9e4d52012-08-17 10:52:16 -06001295 const struct gl_texture_object *texObj,
Kenneth Graunke8c37fc12012-06-11 01:27:38 -07001296 GLenum target, GLint level,
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001297 GLenum pname, GLint *params,
1298 bool dsa)
Brian Paulae1fdc12008-06-11 20:05:53 -06001299{
Brian Paulae1fdc12008-06-11 20:05:53 -06001300 const struct gl_texture_image *img = NULL;
Ian Romanickee58c712014-06-17 14:58:14 -07001301 struct gl_texture_image dummy_image;
Mark Mueller71fe9432014-01-04 14:11:43 -08001302 mesa_format texFormat;
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001303 const char *suffix = dsa ? "ture" : "";
Brian Paulae1fdc12008-06-11 20:05:53 -06001304
Brian Paulf262ed62015-01-02 16:56:12 -07001305 img = _mesa_select_tex_image(texObj, target, level);
Brian Paul26684e02011-07-28 09:43:09 -06001306 if (!img || img->TexFormat == MESA_FORMAT_NONE) {
Anuj Phogat06398012014-02-21 16:58:07 -08001307 /* In case of undefined texture image return the default values.
1308 *
1309 * From OpenGL 4.0 spec, page 398:
1310 * "The initial internal format of a texel array is RGBA
1311 * instead of 1. TEXTURE_COMPONENTS is deprecated; always
1312 * use TEXTURE_INTERNAL_FORMAT."
1313 */
Ian Romanickee58c712014-06-17 14:58:14 -07001314 memset(&dummy_image, 0, sizeof(dummy_image));
1315 dummy_image.TexFormat = MESA_FORMAT_NONE;
1316 dummy_image.InternalFormat = GL_RGBA;
1317 dummy_image._BaseFormat = GL_NONE;
Ilia Mirkin64114442016-02-11 15:30:35 -05001318 dummy_image.FixedSampleLocations = GL_TRUE;
Anuj Phogat06398012014-02-21 16:58:07 -08001319
Ian Romanickee58c712014-06-17 14:58:14 -07001320 img = &dummy_image;
Brian Paulae1fdc12008-06-11 20:05:53 -06001321 }
1322
Brian Paul1f7c9142009-09-30 20:28:45 -06001323 texFormat = img->TexFormat;
Brian Paulaf0adb52009-09-27 20:56:04 -06001324
Brian Paulae1fdc12008-06-11 20:05:53 -06001325 switch (pname) {
1326 case GL_TEXTURE_WIDTH:
1327 *params = img->Width;
1328 break;
1329 case GL_TEXTURE_HEIGHT:
1330 *params = img->Height;
1331 break;
1332 case GL_TEXTURE_DEPTH:
1333 *params = img->Depth;
1334 break;
1335 case GL_TEXTURE_INTERNAL_FORMAT:
Brian Paul365f6582011-01-25 18:44:11 -07001336 if (_mesa_is_format_compressed(texFormat)) {
Brian Paulcd62b4f2009-10-23 14:40:40 -06001337 /* need to return the actual compressed format */
Brian Paul365f6582011-01-25 18:44:11 -07001338 *params = _mesa_compressed_format_to_glenum(ctx, texFormat);
Brian Paulcd62b4f2009-10-23 14:40:40 -06001339 }
1340 else {
Ian Romanick143b65f2011-07-22 15:26:24 -07001341 /* If the true internal format is not compressed but the user
1342 * requested a generic compressed format, we have to return the
1343 * generic base format that matches.
1344 *
1345 * From page 119 (page 129 of the PDF) of the OpenGL 1.3 spec:
1346 *
1347 * "If no specific compressed format is available,
1348 * internalformat is instead replaced by the corresponding base
1349 * internal format."
1350 *
1351 * Otherwise just return the user's requested internal format
1352 */
1353 const GLenum f =
1354 _mesa_gl_compressed_format_base_format(img->InternalFormat);
1355
1356 *params = (f != 0) ? f : img->InternalFormat;
1357 }
Brian Paulae1fdc12008-06-11 20:05:53 -06001358 break;
1359 case GL_TEXTURE_BORDER:
Ian Romanick75028662014-06-16 17:17:43 -07001360 if (ctx->API != API_OPENGL_COMPAT)
1361 goto invalid_pname;
Brian Paulae1fdc12008-06-11 20:05:53 -06001362 *params = img->Border;
1363 break;
1364 case GL_TEXTURE_RED_SIZE:
Brian Paulae1fdc12008-06-11 20:05:53 -06001365 case GL_TEXTURE_GREEN_SIZE:
Brian Paulae1fdc12008-06-11 20:05:53 -06001366 case GL_TEXTURE_BLUE_SIZE:
Brian Paulae1fdc12008-06-11 20:05:53 -06001367 case GL_TEXTURE_ALPHA_SIZE:
Brian Paulf0b6e9a2011-11-23 15:33:45 -07001368 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
Brian Paulaf0adb52009-09-27 20:56:04 -06001369 *params = _mesa_get_format_bits(texFormat, pname);
Brian Paulae1fdc12008-06-11 20:05:53 -06001370 else
1371 *params = 0;
1372 break;
1373 case GL_TEXTURE_INTENSITY_SIZE:
Brian Pauld45c9b22011-11-23 15:33:46 -07001374 case GL_TEXTURE_LUMINANCE_SIZE:
Ian Romanick9a723b92014-06-16 17:57:30 -07001375 if (ctx->API != API_OPENGL_COMPAT)
1376 goto invalid_pname;
Brian Pauld45c9b22011-11-23 15:33:46 -07001377 if (_mesa_base_format_has_channel(img->_BaseFormat, pname)) {
Brian Paulaf0adb52009-09-27 20:56:04 -06001378 *params = _mesa_get_format_bits(texFormat, pname);
Brian Paulb64d4782009-09-27 19:38:21 -06001379 if (*params == 0) {
Brian Pauld45c9b22011-11-23 15:33:46 -07001380 /* intensity or luminance is probably stored as RGB[A] */
1381 *params = MIN2(_mesa_get_format_bits(texFormat,
1382 GL_TEXTURE_RED_SIZE),
1383 _mesa_get_format_bits(texFormat,
1384 GL_TEXTURE_GREEN_SIZE));
Brian Paulb64d4782009-09-27 19:38:21 -06001385 }
1386 }
Brian Paulb64d4782009-09-27 19:38:21 -06001387 else {
Brian Pauld45c9b22011-11-23 15:33:46 -07001388 *params = 0;
Brian Paulb64d4782009-09-27 19:38:21 -06001389 }
Brian Paulae1fdc12008-06-11 20:05:53 -06001390 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06001391 case GL_TEXTURE_DEPTH_SIZE_ARB:
Brian Paul88a4f2f2011-08-04 08:22:30 -06001392 if (!ctx->Extensions.ARB_depth_texture)
Brian Paulf3224002011-01-25 18:42:53 -07001393 goto invalid_pname;
Brian Paul88a4f2f2011-08-04 08:22:30 -06001394 *params = _mesa_get_format_bits(texFormat, pname);
Brian Paulae1fdc12008-06-11 20:05:53 -06001395 break;
Ian Romanick49493222013-11-13 14:15:11 -08001396 case GL_TEXTURE_STENCIL_SIZE:
Brian Paul88a4f2f2011-08-04 08:22:30 -06001397 *params = _mesa_get_format_bits(texFormat, pname);
Brian Paulae1fdc12008-06-11 20:05:53 -06001398 break;
Brian Paul61753c42010-03-20 12:04:52 -06001399 case GL_TEXTURE_SHARED_SIZE:
Eric Anholt9c1b4182012-07-26 14:43:56 -07001400 if (ctx->Version < 30 &&
Brian Paul88a4f2f2011-08-04 08:22:30 -06001401 !ctx->Extensions.EXT_texture_shared_exponent)
Brian Paulf3224002011-01-25 18:42:53 -07001402 goto invalid_pname;
Mark Muellereeed49f2014-01-26 15:12:56 -08001403 *params = texFormat == MESA_FORMAT_R9G9B9E5_FLOAT ? 5 : 0;
Brian Paul61753c42010-03-20 12:04:52 -06001404 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06001405
1406 /* GL_ARB_texture_compression */
1407 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
Brian Paul0bfd1742011-01-25 18:45:44 -07001408 if (_mesa_is_format_compressed(texFormat) &&
1409 !_mesa_is_proxy_texture(target)) {
Brian Pauld6ee86c2009-10-24 16:49:57 -06001410 *params = _mesa_format_image_size(texFormat, img->Width,
1411 img->Height, img->Depth);
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001412 }
1413 else {
1414 _mesa_error(ctx, GL_INVALID_OPERATION,
1415 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
Kenneth Graunke2f11e922015-07-18 01:22:00 -07001416 _mesa_enum_to_string(pname));
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001417 }
Brian Paulae1fdc12008-06-11 20:05:53 -06001418 break;
1419 case GL_TEXTURE_COMPRESSED:
Brian Paul365f6582011-01-25 18:44:11 -07001420 *params = (GLint) _mesa_is_format_compressed(texFormat);
Brian Paulae1fdc12008-06-11 20:05:53 -06001421 break;
1422
1423 /* GL_ARB_texture_float */
Ian Romanick9a723b92014-06-16 17:57:30 -07001424 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1425 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1426 if (ctx->API != API_OPENGL_COMPAT)
1427 goto invalid_pname;
1428 /* FALLTHROUGH */
Brian Paulae1fdc12008-06-11 20:05:53 -06001429 case GL_TEXTURE_RED_TYPE_ARB:
Brian Paulae1fdc12008-06-11 20:05:53 -06001430 case GL_TEXTURE_GREEN_TYPE_ARB:
Brian Paulae1fdc12008-06-11 20:05:53 -06001431 case GL_TEXTURE_BLUE_TYPE_ARB:
Brian Paulae1fdc12008-06-11 20:05:53 -06001432 case GL_TEXTURE_ALPHA_TYPE_ARB:
Brian Paulae1fdc12008-06-11 20:05:53 -06001433 case GL_TEXTURE_DEPTH_TYPE_ARB:
Brian Paul88a4f2f2011-08-04 08:22:30 -06001434 if (!ctx->Extensions.ARB_texture_float)
Brian Paulf3224002011-01-25 18:42:53 -07001435 goto invalid_pname;
Brian Paulf0b6e9a2011-11-23 15:33:45 -07001436 if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
Eric Anholt250a9c82011-11-04 15:28:58 -07001437 *params = _mesa_get_format_datatype(texFormat);
1438 else
1439 *params = GL_NONE;
Brian Paulae1fdc12008-06-11 20:05:53 -06001440 break;
1441
Chris Forbesd04a4dd2012-11-24 21:46:56 +13001442 /* GL_ARB_texture_multisample */
1443 case GL_TEXTURE_SAMPLES:
1444 if (!ctx->Extensions.ARB_texture_multisample)
1445 goto invalid_pname;
1446 *params = img->NumSamples;
1447 break;
1448
1449 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1450 if (!ctx->Extensions.ARB_texture_multisample)
1451 goto invalid_pname;
1452 *params = img->FixedSampleLocations;
1453 break;
1454
Ilia Mirkin659beca2016-02-27 16:04:51 -05001455 /* There is never a buffer data store here, but these pnames still have
1456 * to work.
1457 */
1458
1459 /* GL_ARB_texture_buffer_object */
1460 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
1461 if (!ctx->Extensions.ARB_texture_buffer_object)
1462 goto invalid_pname;
1463 *params = 0;
1464 break;
1465
1466 /* GL_ARB_texture_buffer_range */
1467 case GL_TEXTURE_BUFFER_OFFSET:
1468 if (!ctx->Extensions.ARB_texture_buffer_range)
1469 goto invalid_pname;
1470 *params = 0;
1471 break;
1472 case GL_TEXTURE_BUFFER_SIZE:
1473 if (!ctx->Extensions.ARB_texture_buffer_range)
1474 goto invalid_pname;
1475 *params = 0;
1476 break;
1477
Brian Paulae1fdc12008-06-11 20:05:53 -06001478 default:
Brian Paulf3224002011-01-25 18:42:53 -07001479 goto invalid_pname;
Brian Paulae1fdc12008-06-11 20:05:53 -06001480 }
1481
Brian Paulf3224002011-01-25 18:42:53 -07001482 /* no error if we get here */
1483 return;
1484
1485invalid_pname:
1486 _mesa_error(ctx, GL_INVALID_ENUM,
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001487 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
Kenneth Graunke2f11e922015-07-18 01:22:00 -07001488 _mesa_enum_to_string(pname));
Brian Paulae1fdc12008-06-11 20:05:53 -06001489}
1490
1491
Brian Paul57279c52016-09-23 12:59:29 -06001492/**
1493 * Handle a glGetTexLevelParamteriv() call for a texture buffer.
1494 */
Kenneth Graunke3df13b32012-06-10 19:33:01 -07001495static void
1496get_tex_level_parameter_buffer(struct gl_context *ctx,
Brian Paul1a9e4d52012-08-17 10:52:16 -06001497 const struct gl_texture_object *texObj,
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001498 GLenum pname, GLint *params, bool dsa)
Kenneth Graunke3df13b32012-06-10 19:33:01 -07001499{
Brian Paul1a9e4d52012-08-17 10:52:16 -06001500 const struct gl_buffer_object *bo = texObj->BufferObject;
Mark Mueller71fe9432014-01-04 14:11:43 -08001501 mesa_format texFormat = texObj->_BufferObjectFormat;
Ilia Mirkin659beca2016-02-27 16:04:51 -05001502 int bytes = MAX2(1, _mesa_get_format_bytes(texFormat));
Kenneth Graunke3df13b32012-06-10 19:33:01 -07001503 GLenum internalFormat = texObj->BufferObjectFormat;
1504 GLenum baseFormat = _mesa_get_format_base_format(texFormat);
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001505 const char *suffix = dsa ? "ture" : "";
Kenneth Graunke3df13b32012-06-10 19:33:01 -07001506
Brian Paul57279c52016-09-23 12:59:29 -06001507 assert(texObj->Target == GL_TEXTURE_BUFFER);
1508
Kenneth Graunke3df13b32012-06-10 19:33:01 -07001509 if (!bo) {
1510 /* undefined texture buffer object */
Ilia Mirkin659beca2016-02-27 16:04:51 -05001511 switch (pname) {
1512 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1513 *params = GL_TRUE;
1514 break;
1515 case GL_TEXTURE_INTERNAL_FORMAT:
1516 *params = internalFormat;
1517 break;
1518 default:
1519 *params = 0;
1520 break;
1521 }
Kenneth Graunke3df13b32012-06-10 19:33:01 -07001522 return;
1523 }
1524
1525 switch (pname) {
1526 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING:
1527 *params = bo->Name;
1528 break;
1529 case GL_TEXTURE_WIDTH:
Ilia Mirkin659beca2016-02-27 16:04:51 -05001530 *params = ((texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize)
1531 / bytes;
Kenneth Graunke3df13b32012-06-10 19:33:01 -07001532 break;
1533 case GL_TEXTURE_HEIGHT:
1534 case GL_TEXTURE_DEPTH:
Ilia Mirkin659beca2016-02-27 16:04:51 -05001535 *params = 1;
1536 break;
Kenneth Graunke3df13b32012-06-10 19:33:01 -07001537 case GL_TEXTURE_BORDER:
1538 case GL_TEXTURE_SHARED_SIZE:
1539 case GL_TEXTURE_COMPRESSED:
1540 *params = 0;
1541 break;
1542 case GL_TEXTURE_INTERNAL_FORMAT:
1543 *params = internalFormat;
1544 break;
1545 case GL_TEXTURE_RED_SIZE:
1546 case GL_TEXTURE_GREEN_SIZE:
1547 case GL_TEXTURE_BLUE_SIZE:
1548 case GL_TEXTURE_ALPHA_SIZE:
1549 if (_mesa_base_format_has_channel(baseFormat, pname))
1550 *params = _mesa_get_format_bits(texFormat, pname);
1551 else
1552 *params = 0;
1553 break;
1554 case GL_TEXTURE_INTENSITY_SIZE:
1555 case GL_TEXTURE_LUMINANCE_SIZE:
1556 if (_mesa_base_format_has_channel(baseFormat, pname)) {
1557 *params = _mesa_get_format_bits(texFormat, pname);
1558 if (*params == 0) {
1559 /* intensity or luminance is probably stored as RGB[A] */
1560 *params = MIN2(_mesa_get_format_bits(texFormat,
1561 GL_TEXTURE_RED_SIZE),
1562 _mesa_get_format_bits(texFormat,
1563 GL_TEXTURE_GREEN_SIZE));
1564 }
1565 } else {
1566 *params = 0;
1567 }
1568 break;
1569 case GL_TEXTURE_DEPTH_SIZE_ARB:
1570 case GL_TEXTURE_STENCIL_SIZE_EXT:
1571 *params = _mesa_get_format_bits(texFormat, pname);
1572 break;
1573
Christoph Bumiller785a8c32013-01-25 14:54:05 +01001574 /* GL_ARB_texture_buffer_range */
1575 case GL_TEXTURE_BUFFER_OFFSET:
1576 if (!ctx->Extensions.ARB_texture_buffer_range)
1577 goto invalid_pname;
1578 *params = texObj->BufferOffset;
1579 break;
1580 case GL_TEXTURE_BUFFER_SIZE:
1581 if (!ctx->Extensions.ARB_texture_buffer_range)
1582 goto invalid_pname;
1583 *params = (texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize;
1584 break;
1585
Ilia Mirkin659beca2016-02-27 16:04:51 -05001586 /* GL_ARB_texture_multisample */
1587 case GL_TEXTURE_SAMPLES:
1588 if (!ctx->Extensions.ARB_texture_multisample)
1589 goto invalid_pname;
1590 *params = 0;
1591 break;
1592
1593 case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
1594 if (!ctx->Extensions.ARB_texture_multisample)
1595 goto invalid_pname;
1596 *params = GL_TRUE;
1597 break;
1598
Kenneth Graunke3df13b32012-06-10 19:33:01 -07001599 /* GL_ARB_texture_compression */
1600 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
Brian Paula6af24e2012-08-17 10:50:39 -06001601 /* Always illegal for GL_TEXTURE_BUFFER */
1602 _mesa_error(ctx, GL_INVALID_OPERATION,
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001603 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
Kenneth Graunke2f11e922015-07-18 01:22:00 -07001604 _mesa_enum_to_string(pname));
Kenneth Graunke3df13b32012-06-10 19:33:01 -07001605 break;
1606
1607 /* GL_ARB_texture_float */
1608 case GL_TEXTURE_RED_TYPE_ARB:
1609 case GL_TEXTURE_GREEN_TYPE_ARB:
1610 case GL_TEXTURE_BLUE_TYPE_ARB:
1611 case GL_TEXTURE_ALPHA_TYPE_ARB:
1612 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1613 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1614 case GL_TEXTURE_DEPTH_TYPE_ARB:
1615 if (!ctx->Extensions.ARB_texture_float)
1616 goto invalid_pname;
1617 if (_mesa_base_format_has_channel(baseFormat, pname))
1618 *params = _mesa_get_format_datatype(texFormat);
1619 else
1620 *params = GL_NONE;
1621 break;
1622
1623 default:
1624 goto invalid_pname;
1625 }
1626
1627 /* no error if we get here */
1628 return;
1629
1630invalid_pname:
1631 _mesa_error(ctx, GL_INVALID_ENUM,
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001632 "glGetTex%sLevelParameter[if]v(pname=%s)", suffix,
Kenneth Graunke2f11e922015-07-18 01:22:00 -07001633 _mesa_enum_to_string(pname));
Kenneth Graunke3df13b32012-06-10 19:33:01 -07001634}
1635
Tapani Pällia7e6f8c2015-08-13 17:03:44 +03001636static bool
1637valid_tex_level_parameteriv_target(struct gl_context *ctx, GLenum target,
1638 bool dsa)
1639{
1640 const char *suffix = dsa ? "ture" : "";
Antia Puentesf1c789f2015-11-30 20:37:24 +01001641 if (!_mesa_legal_get_tex_level_parameter_target(ctx, target, dsa)) {
Tapani Pällia7e6f8c2015-08-13 17:03:44 +03001642 _mesa_error(ctx, GL_INVALID_ENUM,
1643 "glGetTex%sLevelParameter[if]v(target=%s)", suffix,
1644 _mesa_enum_to_string(target));
1645 return false;
1646 }
1647 return true;
1648}
Kenneth Graunke3df13b32012-06-10 19:33:01 -07001649
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001650/**
1651 * This isn't exposed to the rest of the driver because it is a part of the
1652 * OpenGL API that is rarely used.
1653 */
1654static void
1655get_tex_level_parameteriv(struct gl_context *ctx,
1656 struct gl_texture_object *texObj,
1657 GLenum target, GLint level,
1658 GLenum pname, GLint *params,
1659 bool dsa)
Kenneth Graunke8c37fc12012-06-11 01:27:38 -07001660{
Kenneth Graunke8c37fc12012-06-11 01:27:38 -07001661 GLint maxLevels;
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001662 const char *suffix = dsa ? "ture" : "";
Kenneth Graunke8c37fc12012-06-11 01:27:38 -07001663
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001664 /* Check for errors */
Kenneth Graunke8c37fc12012-06-11 01:27:38 -07001665 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
1666 _mesa_error(ctx, GL_INVALID_OPERATION,
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001667 "glGetTex%sLevelParameter[if]v("
1668 "current unit >= max combined texture units)", suffix);
Kenneth Graunke8c37fc12012-06-11 01:27:38 -07001669 return;
1670 }
1671
Kenneth Graunke8c37fc12012-06-11 01:27:38 -07001672 maxLevels = _mesa_max_texture_levels(ctx, target);
1673 assert(maxLevels != 0);
1674
1675 if (level < 0 || level >= maxLevels) {
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001676 _mesa_error(ctx, GL_INVALID_VALUE,
1677 "glGetTex%sLevelParameter[if]v(level out of range)", suffix);
Kenneth Graunke8c37fc12012-06-11 01:27:38 -07001678 return;
1679 }
1680
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001681 /* Get the level parameter */
1682 if (target == GL_TEXTURE_BUFFER) {
1683 get_tex_level_parameter_buffer(ctx, texObj, pname, params, dsa);
1684 }
1685 else {
1686 get_tex_level_parameter_image(ctx, texObj, target,
1687 level, pname, params, dsa);
1688 }
Kenneth Graunke8c37fc12012-06-11 01:27:38 -07001689}
1690
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001691void GLAPIENTRY
1692_mesa_GetTexLevelParameterfv( GLenum target, GLint level,
1693 GLenum pname, GLfloat *params )
1694{
1695 struct gl_texture_object *texObj;
1696 GLint iparam;
1697 GET_CURRENT_CONTEXT(ctx);
1698
Tapani Pällia7e6f8c2015-08-13 17:03:44 +03001699 if (!valid_tex_level_parameteriv_target(ctx, target, false))
1700 return;
1701
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001702 texObj = _mesa_get_current_tex_object(ctx, target);
1703 if (!texObj)
1704 return;
1705
1706 get_tex_level_parameteriv(ctx, texObj, target, level,
1707 pname, &iparam, false);
1708
1709 *params = (GLfloat) iparam;
1710}
1711
1712void GLAPIENTRY
1713_mesa_GetTexLevelParameteriv( GLenum target, GLint level,
1714 GLenum pname, GLint *params )
1715{
1716 struct gl_texture_object *texObj;
1717 GET_CURRENT_CONTEXT(ctx);
1718
Tapani Pällia7e6f8c2015-08-13 17:03:44 +03001719 if (!valid_tex_level_parameteriv_target(ctx, target, false))
1720 return;
1721
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001722 texObj = _mesa_get_current_tex_object(ctx, target);
1723 if (!texObj)
1724 return;
1725
1726 get_tex_level_parameteriv(ctx, texObj, target, level,
1727 pname, params, false);
1728}
1729
1730void GLAPIENTRY
1731_mesa_GetTextureLevelParameterfv(GLuint texture, GLint level,
1732 GLenum pname, GLfloat *params)
1733{
1734 struct gl_texture_object *texObj;
1735 GLint iparam;
1736 GET_CURRENT_CONTEXT(ctx);
1737
1738 texObj = _mesa_lookup_texture_err(ctx, texture,
1739 "glGetTextureLevelParameterfv");
1740 if (!texObj)
1741 return;
1742
Tapani Pällia7e6f8c2015-08-13 17:03:44 +03001743 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
1744 return;
1745
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001746 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
1747 pname, &iparam, true);
1748
1749 *params = (GLfloat) iparam;
1750}
1751
1752void GLAPIENTRY
1753_mesa_GetTextureLevelParameteriv(GLuint texture, GLint level,
1754 GLenum pname, GLint *params)
1755{
1756 struct gl_texture_object *texObj;
1757 GET_CURRENT_CONTEXT(ctx);
1758
1759 texObj = _mesa_lookup_texture_err(ctx, texture,
1760 "glGetTextureLevelParameteriv");
1761 if (!texObj)
1762 return;
1763
Tapani Pällia7e6f8c2015-08-13 17:03:44 +03001764 if (!valid_tex_level_parameteriv_target(ctx, texObj->Target, true))
1765 return;
1766
Laura Ekstrand86bb3be2014-12-10 15:19:59 -08001767 get_tex_level_parameteriv(ctx, texObj, texObj->Target, level,
1768 pname, params, true);
1769}
Brian Paulae1fdc12008-06-11 20:05:53 -06001770
Laura Ekstrand89912d02014-12-10 15:32:20 -08001771/**
1772 * This isn't exposed to the rest of the driver because it is a part of the
1773 * OpenGL API that is rarely used.
1774 */
1775static void
1776get_tex_parameterfv(struct gl_context *ctx,
1777 struct gl_texture_object *obj,
1778 GLenum pname, GLfloat *params, bool dsa)
Brian Paulae1fdc12008-06-11 20:05:53 -06001779{
Kristian Høgsberg5fad83b2014-08-08 16:53:53 -07001780 _mesa_lock_context_textures(ctx);
Brian Paulae1fdc12008-06-11 20:05:53 -06001781 switch (pname) {
1782 case GL_TEXTURE_MAG_FILTER:
Brian Paulecfaab82011-04-10 12:44:46 -06001783 *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter);
Brian Paulae1fdc12008-06-11 20:05:53 -06001784 break;
1785 case GL_TEXTURE_MIN_FILTER:
Brian Paulecfaab82011-04-10 12:44:46 -06001786 *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter);
Brian Paulae1fdc12008-06-11 20:05:53 -06001787 break;
1788 case GL_TEXTURE_WRAP_S:
Brian Paulecfaab82011-04-10 12:44:46 -06001789 *params = ENUM_TO_FLOAT(obj->Sampler.WrapS);
Brian Paulae1fdc12008-06-11 20:05:53 -06001790 break;
1791 case GL_TEXTURE_WRAP_T:
Brian Paulecfaab82011-04-10 12:44:46 -06001792 *params = ENUM_TO_FLOAT(obj->Sampler.WrapT);
Brian Paulae1fdc12008-06-11 20:05:53 -06001793 break;
1794 case GL_TEXTURE_WRAP_R:
Brian Paulecfaab82011-04-10 12:44:46 -06001795 *params = ENUM_TO_FLOAT(obj->Sampler.WrapR);
Brian Paulae1fdc12008-06-11 20:05:53 -06001796 break;
1797 case GL_TEXTURE_BORDER_COLOR:
Ilia Mirkinb6654832016-02-15 19:09:15 -05001798 if (ctx->API == API_OPENGLES ||
1799 !ctx->Extensions.ARB_texture_border_clamp)
Ian Romanickc9689e32012-07-26 18:15:40 -07001800 goto invalid_pname;
1801
Brian Paul1e89a522011-08-04 08:22:31 -06001802 if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
Marek Olšáke5c6a922011-02-15 23:30:23 +01001803 _mesa_update_state_locked(ctx);
Laura Ekstrand2cabfd92015-03-03 14:03:33 -08001804 if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer)) {
Brian Paulecfaab82011-04-10 12:44:46 -06001805 params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
1806 params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
1807 params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
1808 params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
Marek Olšáke5c6a922011-02-15 23:30:23 +01001809 }
Brian Paul1e89a522011-08-04 08:22:31 -06001810 else {
Brian Paulecfaab82011-04-10 12:44:46 -06001811 params[0] = obj->Sampler.BorderColor.f[0];
1812 params[1] = obj->Sampler.BorderColor.f[1];
1813 params[2] = obj->Sampler.BorderColor.f[2];
1814 params[3] = obj->Sampler.BorderColor.f[3];
Marek Olšáke5c6a922011-02-15 23:30:23 +01001815 }
Brian Paulae1fdc12008-06-11 20:05:53 -06001816 break;
1817 case GL_TEXTURE_RESIDENT:
Paul Berrydbd61352012-11-27 12:26:51 -08001818 if (ctx->API != API_OPENGL_COMPAT)
Ian Romanickc9689e32012-07-26 18:15:40 -07001819 goto invalid_pname;
1820
Brian Paul2f881392011-12-03 10:04:18 -07001821 *params = 1.0F;
Brian Paulae1fdc12008-06-11 20:05:53 -06001822 break;
1823 case GL_TEXTURE_PRIORITY:
Paul Berrydbd61352012-11-27 12:26:51 -08001824 if (ctx->API != API_OPENGL_COMPAT)
Ian Romanickc9689e32012-07-26 18:15:40 -07001825 goto invalid_pname;
1826
Brian Paulae1fdc12008-06-11 20:05:53 -06001827 *params = obj->Priority;
1828 break;
1829 case GL_TEXTURE_MIN_LOD:
Ian Romanickc9689e32012-07-26 18:15:40 -07001830 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1831 goto invalid_pname;
1832
Brian Paulecfaab82011-04-10 12:44:46 -06001833 *params = obj->Sampler.MinLod;
Brian Paulae1fdc12008-06-11 20:05:53 -06001834 break;
1835 case GL_TEXTURE_MAX_LOD:
Ian Romanickc9689e32012-07-26 18:15:40 -07001836 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1837 goto invalid_pname;
1838
Brian Paulecfaab82011-04-10 12:44:46 -06001839 *params = obj->Sampler.MaxLod;
Brian Paulae1fdc12008-06-11 20:05:53 -06001840 break;
1841 case GL_TEXTURE_BASE_LEVEL:
Ian Romanickc9689e32012-07-26 18:15:40 -07001842 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1843 goto invalid_pname;
1844
Brian Paulae1fdc12008-06-11 20:05:53 -06001845 *params = (GLfloat) obj->BaseLevel;
1846 break;
1847 case GL_TEXTURE_MAX_LEVEL:
1848 *params = (GLfloat) obj->MaxLevel;
1849 break;
1850 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
Brian Paul88a4f2f2011-08-04 08:22:30 -06001851 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
1852 goto invalid_pname;
1853 *params = obj->Sampler.MaxAnisotropy;
Brian Paulae1fdc12008-06-11 20:05:53 -06001854 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06001855 case GL_GENERATE_MIPMAP_SGIS:
Paul Berrydbd61352012-11-27 12:26:51 -08001856 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
Ian Romanickc9689e32012-07-26 18:15:40 -07001857 goto invalid_pname;
1858
Ian Romanick7f11d472010-09-27 14:55:52 -07001859 *params = (GLfloat) obj->GenerateMipmap;
Brian Paulae1fdc12008-06-11 20:05:53 -06001860 break;
1861 case GL_TEXTURE_COMPARE_MODE_ARB:
Ian Romanickc9689e32012-07-26 18:15:40 -07001862 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
1863 && !_mesa_is_gles3(ctx))
Brian Paul88a4f2f2011-08-04 08:22:30 -06001864 goto invalid_pname;
1865 *params = (GLfloat) obj->Sampler.CompareMode;
Brian Paulae1fdc12008-06-11 20:05:53 -06001866 break;
1867 case GL_TEXTURE_COMPARE_FUNC_ARB:
Ian Romanickc9689e32012-07-26 18:15:40 -07001868 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
1869 && !_mesa_is_gles3(ctx))
Brian Paul88a4f2f2011-08-04 08:22:30 -06001870 goto invalid_pname;
1871 *params = (GLfloat) obj->Sampler.CompareFunc;
Brian Paulae1fdc12008-06-11 20:05:53 -06001872 break;
1873 case GL_DEPTH_TEXTURE_MODE_ARB:
Ian Romanickc9689e32012-07-26 18:15:40 -07001874 /* GL_DEPTH_TEXTURE_MODE_ARB is removed in core-profile and it has
1875 * never existed in OpenGL ES.
1876 */
Paul Berrydbd61352012-11-27 12:26:51 -08001877 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
Brian Paul88a4f2f2011-08-04 08:22:30 -06001878 goto invalid_pname;
Pauli Nieminenc37efbf2012-06-12 21:38:46 +03001879 *params = (GLfloat) obj->DepthMode;
Brian Paulae1fdc12008-06-11 20:05:53 -06001880 break;
Kenneth Graunke23e81b92014-02-23 21:59:24 -08001881 case GL_DEPTH_STENCIL_TEXTURE_MODE:
Ilia Mirkind33ef192016-02-11 15:21:02 -05001882 if (!_mesa_has_ARB_stencil_texturing(ctx) && !_mesa_is_gles31(ctx))
Kenneth Graunke23e81b92014-02-23 21:59:24 -08001883 goto invalid_pname;
1884 *params = (GLfloat)
1885 (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
1886 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06001887 case GL_TEXTURE_LOD_BIAS:
Tapani Pälli7e61b442013-11-20 13:27:10 +02001888 if (_mesa_is_gles(ctx))
Ian Romanickc9689e32012-07-26 18:15:40 -07001889 goto invalid_pname;
1890
Brian Paul88a4f2f2011-08-04 08:22:30 -06001891 *params = obj->Sampler.LodBias;
Brian Paulae1fdc12008-06-11 20:05:53 -06001892 break;
Brian Paul1b7e9092008-08-12 17:41:57 -06001893 case GL_TEXTURE_CROP_RECT_OES:
Ian Romanickc9689e32012-07-26 18:15:40 -07001894 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
1895 goto invalid_pname;
1896
Brian Paulddb774d2013-01-22 17:17:24 -07001897 params[0] = (GLfloat) obj->CropRect[0];
1898 params[1] = (GLfloat) obj->CropRect[1];
1899 params[2] = (GLfloat) obj->CropRect[2];
1900 params[3] = (GLfloat) obj->CropRect[3];
Brian Paul1b7e9092008-08-12 17:41:57 -06001901 break;
Brian Paul4a89e512009-01-28 10:27:33 -07001902
1903 case GL_TEXTURE_SWIZZLE_R_EXT:
1904 case GL_TEXTURE_SWIZZLE_G_EXT:
1905 case GL_TEXTURE_SWIZZLE_B_EXT:
1906 case GL_TEXTURE_SWIZZLE_A_EXT:
Ian Romanickc9689e32012-07-26 18:15:40 -07001907 if ((!_mesa_is_desktop_gl(ctx)
1908 || !ctx->Extensions.EXT_texture_swizzle)
1909 && !_mesa_is_gles3(ctx))
Brian Paul88a4f2f2011-08-04 08:22:30 -06001910 goto invalid_pname;
1911 *params = (GLfloat) obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
Brian Paul4a89e512009-01-28 10:27:33 -07001912 break;
1913
1914 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
Ian Romanickc9689e32012-07-26 18:15:40 -07001915 if ((!_mesa_is_desktop_gl(ctx)
1916 || !ctx->Extensions.EXT_texture_swizzle)
1917 && !_mesa_is_gles3(ctx)) {
Brian Paul88a4f2f2011-08-04 08:22:30 -06001918 goto invalid_pname;
1919 }
1920 else {
Brian Paul4a89e512009-01-28 10:27:33 -07001921 GLuint comp;
1922 for (comp = 0; comp < 4; comp++) {
1923 params[comp] = (GLfloat) obj->Swizzle[comp];
1924 }
1925 }
Brian Paul4a89e512009-01-28 10:27:33 -07001926 break;
1927
Marek Olšáka19c42f2011-05-03 11:37:25 +02001928 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
Ian Romanickc9689e32012-07-26 18:15:40 -07001929 if (!_mesa_is_desktop_gl(ctx)
1930 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
Brian Paul88a4f2f2011-08-04 08:22:30 -06001931 goto invalid_pname;
1932 *params = (GLfloat) obj->Sampler.CubeMapSeamless;
Brian Pauldc1f32d2011-07-29 16:49:55 -06001933 break;
Marek Olšáka19c42f2011-05-03 11:37:25 +02001934
Brian Paulfbc41932011-10-31 10:52:56 -06001935 case GL_TEXTURE_IMMUTABLE_FORMAT:
Brian Paulfbc41932011-10-31 10:52:56 -06001936 *params = (GLfloat) obj->Immutable;
1937 break;
1938
Matt Turner12dc4be2013-03-04 11:03:58 -08001939 case GL_TEXTURE_IMMUTABLE_LEVELS:
Courtney Goeltzenleuchterf1563e62013-11-04 13:29:48 -07001940 if (_mesa_is_gles3(ctx) ||
1941 (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_view))
1942 *params = (GLfloat) obj->ImmutableLevels;
1943 else
Matt Turner12dc4be2013-03-04 11:03:58 -08001944 goto invalid_pname;
Courtney Goeltzenleuchterf1563e62013-11-04 13:29:48 -07001945 break;
1946
1947 case GL_TEXTURE_VIEW_MIN_LEVEL:
1948 if (!ctx->Extensions.ARB_texture_view)
1949 goto invalid_pname;
1950 *params = (GLfloat) obj->MinLevel;
1951 break;
1952
1953 case GL_TEXTURE_VIEW_NUM_LEVELS:
1954 if (!ctx->Extensions.ARB_texture_view)
1955 goto invalid_pname;
1956 *params = (GLfloat) obj->NumLevels;
1957 break;
1958
1959 case GL_TEXTURE_VIEW_MIN_LAYER:
1960 if (!ctx->Extensions.ARB_texture_view)
1961 goto invalid_pname;
1962 *params = (GLfloat) obj->MinLayer;
1963 break;
1964
1965 case GL_TEXTURE_VIEW_NUM_LAYERS:
1966 if (!ctx->Extensions.ARB_texture_view)
1967 goto invalid_pname;
1968 *params = (GLfloat) obj->NumLayers;
Matt Turner12dc4be2013-03-04 11:03:58 -08001969 break;
1970
Tapani Pälli331967c2013-02-20 13:00:07 +02001971 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
1972 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
1973 goto invalid_pname;
Brian Paul8ba5c792013-07-08 09:55:38 -06001974 *params = (GLfloat) obj->RequiredTextureImageUnits;
Tapani Pälli331967c2013-02-20 13:00:07 +02001975 break;
1976
Ian Romanickae3023e2012-09-18 15:19:18 +02001977 case GL_TEXTURE_SRGB_DECODE_EXT:
1978 if (!ctx->Extensions.EXT_texture_sRGB_decode)
1979 goto invalid_pname;
1980 *params = (GLfloat) obj->Sampler.sRGBDecode;
1981 break;
1982
Marta Lofstedt3df78562015-08-12 11:57:39 +02001983 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
1984 if (!ctx->Extensions.ARB_shader_image_load_store)
1985 goto invalid_pname;
1986 *params = (GLfloat) obj->ImageFormatCompatibilityType;
1987 break;
1988
Daniel Scharrer5aaaaeb2015-08-28 11:45:35 +02001989 case GL_TEXTURE_TARGET:
1990 if (ctx->API != API_OPENGL_CORE)
1991 goto invalid_pname;
1992 *params = ENUM_TO_FLOAT(obj->Target);
1993 break;
1994
Brian Paulae1fdc12008-06-11 20:05:53 -06001995 default:
Brian Paul88a4f2f2011-08-04 08:22:30 -06001996 goto invalid_pname;
Brian Paulae1fdc12008-06-11 20:05:53 -06001997 }
Brian Paul4a89e512009-01-28 10:27:33 -07001998
Brian Paul88a4f2f2011-08-04 08:22:30 -06001999 /* no error if we get here */
Kristian Høgsberg5fad83b2014-08-08 16:53:53 -07002000 _mesa_unlock_context_textures(ctx);
Brian Paul88a4f2f2011-08-04 08:22:30 -06002001 return;
2002
2003invalid_pname:
Kristian Høgsberg5fad83b2014-08-08 16:53:53 -07002004 _mesa_unlock_context_textures(ctx);
Laura Ekstrand89912d02014-12-10 15:32:20 -08002005 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameterfv(pname=0x%x)",
2006 dsa ? "ture" : "", pname);
Brian Paulae1fdc12008-06-11 20:05:53 -06002007}
2008
2009
Laura Ekstrandc2c50772014-12-10 15:35:38 -08002010static void
2011get_tex_parameteriv(struct gl_context *ctx,
2012 struct gl_texture_object *obj,
2013 GLenum pname, GLint *params, bool dsa)
Brian Paulae1fdc12008-06-11 20:05:53 -06002014{
Brian Paul6d845802010-01-04 19:05:31 -07002015 _mesa_lock_texture(ctx, obj);
Brian Paulae1fdc12008-06-11 20:05:53 -06002016 switch (pname) {
2017 case GL_TEXTURE_MAG_FILTER:
Brian Paulecfaab82011-04-10 12:44:46 -06002018 *params = (GLint) obj->Sampler.MagFilter;
Dave Airlie449cae12012-02-12 16:05:08 +00002019 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06002020 case GL_TEXTURE_MIN_FILTER:
Brian Paulecfaab82011-04-10 12:44:46 -06002021 *params = (GLint) obj->Sampler.MinFilter;
Dave Airlie449cae12012-02-12 16:05:08 +00002022 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06002023 case GL_TEXTURE_WRAP_S:
Brian Paulecfaab82011-04-10 12:44:46 -06002024 *params = (GLint) obj->Sampler.WrapS;
Dave Airlie449cae12012-02-12 16:05:08 +00002025 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06002026 case GL_TEXTURE_WRAP_T:
Brian Paulecfaab82011-04-10 12:44:46 -06002027 *params = (GLint) obj->Sampler.WrapT;
Dave Airlie449cae12012-02-12 16:05:08 +00002028 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06002029 case GL_TEXTURE_WRAP_R:
Brian Paulecfaab82011-04-10 12:44:46 -06002030 *params = (GLint) obj->Sampler.WrapR;
Dave Airlie449cae12012-02-12 16:05:08 +00002031 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06002032 case GL_TEXTURE_BORDER_COLOR:
Ilia Mirkinb6654832016-02-15 19:09:15 -05002033 if (ctx->API == API_OPENGLES ||
2034 !ctx->Extensions.ARB_texture_border_clamp)
Ian Romanickc9689e32012-07-26 18:15:40 -07002035 goto invalid_pname;
2036
Brian Paulae1fdc12008-06-11 20:05:53 -06002037 {
2038 GLfloat b[4];
Brian Paulecfaab82011-04-10 12:44:46 -06002039 b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F);
2040 b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F);
2041 b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F);
2042 b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F);
Brian Paulae1fdc12008-06-11 20:05:53 -06002043 params[0] = FLOAT_TO_INT(b[0]);
2044 params[1] = FLOAT_TO_INT(b[1]);
2045 params[2] = FLOAT_TO_INT(b[2]);
2046 params[3] = FLOAT_TO_INT(b[3]);
2047 }
Dave Airlie449cae12012-02-12 16:05:08 +00002048 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06002049 case GL_TEXTURE_RESIDENT:
Paul Berrydbd61352012-11-27 12:26:51 -08002050 if (ctx->API != API_OPENGL_COMPAT)
Ian Romanickc9689e32012-07-26 18:15:40 -07002051 goto invalid_pname;
2052
Brian Paul2f881392011-12-03 10:04:18 -07002053 *params = 1;
Dave Airlie449cae12012-02-12 16:05:08 +00002054 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06002055 case GL_TEXTURE_PRIORITY:
Paul Berrydbd61352012-11-27 12:26:51 -08002056 if (ctx->API != API_OPENGL_COMPAT)
Ian Romanickc9689e32012-07-26 18:15:40 -07002057 goto invalid_pname;
2058
Brian Paulae1fdc12008-06-11 20:05:53 -06002059 *params = FLOAT_TO_INT(obj->Priority);
Dave Airlie449cae12012-02-12 16:05:08 +00002060 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06002061 case GL_TEXTURE_MIN_LOD:
Ian Romanickc9689e32012-07-26 18:15:40 -07002062 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2063 goto invalid_pname;
Samuel Iglesias Gonsalvezd8d59202014-12-11 23:34:14 +01002064 /* GL spec 'Data Conversions' section specifies that floating-point
2065 * value in integer Get function is rounded to nearest integer
2066 */
2067 *params = IROUND(obj->Sampler.MinLod);
Dave Airlie449cae12012-02-12 16:05:08 +00002068 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06002069 case GL_TEXTURE_MAX_LOD:
Ian Romanickc9689e32012-07-26 18:15:40 -07002070 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2071 goto invalid_pname;
Samuel Iglesias Gonsalvezd8d59202014-12-11 23:34:14 +01002072 /* GL spec 'Data Conversions' section specifies that floating-point
2073 * value in integer Get function is rounded to nearest integer
2074 */
2075 *params = IROUND(obj->Sampler.MaxLod);
Dave Airlie449cae12012-02-12 16:05:08 +00002076 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06002077 case GL_TEXTURE_BASE_LEVEL:
Ian Romanickc9689e32012-07-26 18:15:40 -07002078 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
2079 goto invalid_pname;
2080
Brian Paulae1fdc12008-06-11 20:05:53 -06002081 *params = obj->BaseLevel;
Dave Airlie449cae12012-02-12 16:05:08 +00002082 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06002083 case GL_TEXTURE_MAX_LEVEL:
2084 *params = obj->MaxLevel;
Dave Airlie449cae12012-02-12 16:05:08 +00002085 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06002086 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
Brian Paul88a4f2f2011-08-04 08:22:30 -06002087 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
2088 goto invalid_pname;
Samuel Iglesias Gonsalvezd8d59202014-12-11 23:34:14 +01002089 /* GL spec 'Data Conversions' section specifies that floating-point
2090 * value in integer Get function is rounded to nearest integer
2091 */
2092 *params = IROUND(obj->Sampler.MaxAnisotropy);
Brian Paulae1fdc12008-06-11 20:05:53 -06002093 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06002094 case GL_GENERATE_MIPMAP_SGIS:
Paul Berrydbd61352012-11-27 12:26:51 -08002095 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
Ian Romanickc9689e32012-07-26 18:15:40 -07002096 goto invalid_pname;
2097
Ian Romanick7f11d472010-09-27 14:55:52 -07002098 *params = (GLint) obj->GenerateMipmap;
Brian Paulae1fdc12008-06-11 20:05:53 -06002099 break;
2100 case GL_TEXTURE_COMPARE_MODE_ARB:
Ian Romanickc9689e32012-07-26 18:15:40 -07002101 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2102 && !_mesa_is_gles3(ctx))
Brian Paul88a4f2f2011-08-04 08:22:30 -06002103 goto invalid_pname;
2104 *params = (GLint) obj->Sampler.CompareMode;
Brian Paulae1fdc12008-06-11 20:05:53 -06002105 break;
2106 case GL_TEXTURE_COMPARE_FUNC_ARB:
Ian Romanickc9689e32012-07-26 18:15:40 -07002107 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_shadow)
2108 && !_mesa_is_gles3(ctx))
Brian Paul88a4f2f2011-08-04 08:22:30 -06002109 goto invalid_pname;
2110 *params = (GLint) obj->Sampler.CompareFunc;
Brian Paulae1fdc12008-06-11 20:05:53 -06002111 break;
2112 case GL_DEPTH_TEXTURE_MODE_ARB:
Paul Berrydbd61352012-11-27 12:26:51 -08002113 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.ARB_depth_texture)
Brian Paul88a4f2f2011-08-04 08:22:30 -06002114 goto invalid_pname;
Pauli Nieminenc37efbf2012-06-12 21:38:46 +03002115 *params = (GLint) obj->DepthMode;
Brian Paulae1fdc12008-06-11 20:05:53 -06002116 break;
Kenneth Graunke23e81b92014-02-23 21:59:24 -08002117 case GL_DEPTH_STENCIL_TEXTURE_MODE:
Ilia Mirkind33ef192016-02-11 15:21:02 -05002118 if (!_mesa_has_ARB_stencil_texturing(ctx) && !_mesa_is_gles31(ctx))
Kenneth Graunke23e81b92014-02-23 21:59:24 -08002119 goto invalid_pname;
2120 *params = (GLint)
2121 (obj->StencilSampling ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT);
2122 break;
Brian Paulae1fdc12008-06-11 20:05:53 -06002123 case GL_TEXTURE_LOD_BIAS:
Tapani Pälli7e61b442013-11-20 13:27:10 +02002124 if (_mesa_is_gles(ctx))
Ian Romanickc9689e32012-07-26 18:15:40 -07002125 goto invalid_pname;
2126
Tapani Pälli7e61b442013-11-20 13:27:10 +02002127 /* GL spec 'Data Conversions' section specifies that floating-point
2128 * value in integer Get function is rounded to nearest integer
2129 */
José Fonsecabba8f1052013-11-21 13:56:00 +00002130 *params = IROUND(obj->Sampler.LodBias);
Brian Paulae1fdc12008-06-11 20:05:53 -06002131 break;
Brian Paul1b7e9092008-08-12 17:41:57 -06002132 case GL_TEXTURE_CROP_RECT_OES:
Ian Romanickc9689e32012-07-26 18:15:40 -07002133 if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
2134 goto invalid_pname;
2135
Brian Paul1b7e9092008-08-12 17:41:57 -06002136 params[0] = obj->CropRect[0];
Brad Kingee80c642008-09-26 07:40:05 -06002137 params[1] = obj->CropRect[1];
2138 params[2] = obj->CropRect[2];
2139 params[3] = obj->CropRect[3];
Brian Paul1b7e9092008-08-12 17:41:57 -06002140 break;
Brian Paul4a89e512009-01-28 10:27:33 -07002141 case GL_TEXTURE_SWIZZLE_R_EXT:
2142 case GL_TEXTURE_SWIZZLE_G_EXT:
2143 case GL_TEXTURE_SWIZZLE_B_EXT:
2144 case GL_TEXTURE_SWIZZLE_A_EXT:
Ian Romanickc9689e32012-07-26 18:15:40 -07002145 if ((!_mesa_is_desktop_gl(ctx)
2146 || !ctx->Extensions.EXT_texture_swizzle)
2147 && !_mesa_is_gles3(ctx))
Brian Paul88a4f2f2011-08-04 08:22:30 -06002148 goto invalid_pname;
2149 *params = obj->Swizzle[pname - GL_TEXTURE_SWIZZLE_R_EXT];
Brian Paul4a89e512009-01-28 10:27:33 -07002150 break;
2151
2152 case GL_TEXTURE_SWIZZLE_RGBA_EXT:
Ian Romanickc9689e32012-07-26 18:15:40 -07002153 if ((!_mesa_is_desktop_gl(ctx)
2154 || !ctx->Extensions.EXT_texture_swizzle)
2155 && !_mesa_is_gles3(ctx))
Brian Paul88a4f2f2011-08-04 08:22:30 -06002156 goto invalid_pname;
2157 COPY_4V(params, obj->Swizzle);
Brian Paul4a89e512009-01-28 10:27:33 -07002158 break;
2159
Marek Olšáka19c42f2011-05-03 11:37:25 +02002160 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
Ian Romanickc9689e32012-07-26 18:15:40 -07002161 if (!_mesa_is_desktop_gl(ctx)
2162 || !ctx->Extensions.AMD_seamless_cubemap_per_texture)
Brian Paul88a4f2f2011-08-04 08:22:30 -06002163 goto invalid_pname;
2164 *params = (GLint) obj->Sampler.CubeMapSeamless;
Brian Pauldc1f32d2011-07-29 16:49:55 -06002165 break;
Marek Olšáka19c42f2011-05-03 11:37:25 +02002166
Brian Paulfbc41932011-10-31 10:52:56 -06002167 case GL_TEXTURE_IMMUTABLE_FORMAT:
Brian Paulfbc41932011-10-31 10:52:56 -06002168 *params = (GLint) obj->Immutable;
2169 break;
2170
Matt Turner12dc4be2013-03-04 11:03:58 -08002171 case GL_TEXTURE_IMMUTABLE_LEVELS:
Courtney Goeltzenleuchterf1563e62013-11-04 13:29:48 -07002172 if (_mesa_is_gles3(ctx) ||
2173 (_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_view))
2174 *params = obj->ImmutableLevels;
2175 else
Matt Turner12dc4be2013-03-04 11:03:58 -08002176 goto invalid_pname;
Courtney Goeltzenleuchterf1563e62013-11-04 13:29:48 -07002177 break;
2178
2179 case GL_TEXTURE_VIEW_MIN_LEVEL:
2180 if (!ctx->Extensions.ARB_texture_view)
2181 goto invalid_pname;
2182 *params = (GLint) obj->MinLevel;
2183 break;
2184
2185 case GL_TEXTURE_VIEW_NUM_LEVELS:
2186 if (!ctx->Extensions.ARB_texture_view)
2187 goto invalid_pname;
2188 *params = (GLint) obj->NumLevels;
2189 break;
2190
2191 case GL_TEXTURE_VIEW_MIN_LAYER:
2192 if (!ctx->Extensions.ARB_texture_view)
2193 goto invalid_pname;
2194 *params = (GLint) obj->MinLayer;
2195 break;
2196
2197 case GL_TEXTURE_VIEW_NUM_LAYERS:
2198 if (!ctx->Extensions.ARB_texture_view)
2199 goto invalid_pname;
2200 *params = (GLint) obj->NumLayers;
Matt Turner12dc4be2013-03-04 11:03:58 -08002201 break;
2202
Chia-I Wu0c87f162011-10-23 18:52:38 +08002203 case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES:
Ian Romanickc9689e32012-07-26 18:15:40 -07002204 if (!_mesa_is_gles(ctx) || !ctx->Extensions.OES_EGL_image_external)
Chia-I Wu0c87f162011-10-23 18:52:38 +08002205 goto invalid_pname;
2206 *params = obj->RequiredTextureImageUnits;
2207 break;
2208
Ian Romanickae3023e2012-09-18 15:19:18 +02002209 case GL_TEXTURE_SRGB_DECODE_EXT:
2210 if (!ctx->Extensions.EXT_texture_sRGB_decode)
2211 goto invalid_pname;
2212 *params = obj->Sampler.sRGBDecode;
2213 break;
2214
Francisco Jerez902f9df2013-11-25 10:11:59 -08002215 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
2216 if (!ctx->Extensions.ARB_shader_image_load_store)
2217 goto invalid_pname;
2218 *params = obj->ImageFormatCompatibilityType;
2219 break;
2220
Daniel Scharrer5aaaaeb2015-08-28 11:45:35 +02002221 case GL_TEXTURE_TARGET:
2222 if (ctx->API != API_OPENGL_CORE)
2223 goto invalid_pname;
2224 *params = (GLint) obj->Target;
2225 break;
2226
Brian Paulae1fdc12008-06-11 20:05:53 -06002227 default:
Brian Paul88a4f2f2011-08-04 08:22:30 -06002228 goto invalid_pname;
Brian Paulae1fdc12008-06-11 20:05:53 -06002229 }
Brian Paul4a89e512009-01-28 10:27:33 -07002230
Brian Paul88a4f2f2011-08-04 08:22:30 -06002231 /* no error if we get here */
Brian Paul4a89e512009-01-28 10:27:33 -07002232 _mesa_unlock_texture(ctx, obj);
Brian Paul88a4f2f2011-08-04 08:22:30 -06002233 return;
2234
2235invalid_pname:
2236 _mesa_unlock_texture(ctx, obj);
Laura Ekstrandc2c50772014-12-10 15:35:38 -08002237 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTex%sParameteriv(pname=0x%x)",
2238 dsa ? "ture" : "", pname);
2239}
2240
2241static void
2242get_tex_parameterIiv(struct gl_context *ctx,
2243 struct gl_texture_object *obj,
2244 GLenum pname, GLint *params, bool dsa)
2245{
2246 switch (pname) {
2247 case GL_TEXTURE_BORDER_COLOR:
2248 COPY_4V(params, obj->Sampler.BorderColor.i);
2249 break;
2250 default:
2251 get_tex_parameteriv(ctx, obj, pname, params, dsa);
2252 }
2253}
2254
2255static void
2256get_tex_parameterIuiv(struct gl_context *ctx,
2257 struct gl_texture_object *obj,
2258 GLenum pname, GLuint *params, bool dsa)
2259{
2260 switch (pname) {
2261 case GL_TEXTURE_BORDER_COLOR:
2262 COPY_4V(params, obj->Sampler.BorderColor.i);
2263 break;
2264 default:
2265 {
2266 GLint ip[4];
2267 get_tex_parameteriv(ctx, obj, pname, ip, dsa);
2268 params[0] = ip[0];
2269 if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT ||
2270 pname == GL_TEXTURE_CROP_RECT_OES) {
2271 params[1] = ip[1];
2272 params[2] = ip[2];
2273 params[3] = ip[3];
2274 }
2275 }
2276 }
Brian Paulae1fdc12008-06-11 20:05:53 -06002277}
Brian Paul7836a962010-01-04 20:00:00 -07002278
Laura Ekstrand89912d02014-12-10 15:32:20 -08002279void GLAPIENTRY
2280_mesa_GetTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
2281{
2282 struct gl_texture_object *obj;
2283 GET_CURRENT_CONTEXT(ctx);
2284
2285 obj = get_texobj_by_target(ctx, target, GL_TRUE);
2286 if (!obj)
2287 return;
2288
2289 get_tex_parameterfv(ctx, obj, pname, params, false);
2290}
2291
Laura Ekstrandc2c50772014-12-10 15:35:38 -08002292void GLAPIENTRY
2293_mesa_GetTexParameteriv(GLenum target, GLenum pname, GLint *params)
2294{
2295 struct gl_texture_object *obj;
2296 GET_CURRENT_CONTEXT(ctx);
2297
2298 obj = get_texobj_by_target(ctx, target, GL_TRUE);
2299 if (!obj)
2300 return;
2301
2302 get_tex_parameteriv(ctx, obj, pname, params, false);
2303}
Laura Ekstrand89912d02014-12-10 15:32:20 -08002304
Brian Paul7836a962010-01-04 20:00:00 -07002305/** New in GL 3.0 */
2306void GLAPIENTRY
2307_mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params)
2308{
2309 struct gl_texture_object *texObj;
2310 GET_CURRENT_CONTEXT(ctx);
Brian Paul7836a962010-01-04 20:00:00 -07002311
Laura Ekstrand5ad53932014-12-10 16:13:31 -08002312 texObj = get_texobj_by_target(ctx, target, GL_TRUE);
Brian Paul02d81df2011-08-04 08:22:31 -06002313 if (!texObj)
2314 return;
Rico Schüller14f02cd2013-10-27 08:02:00 -06002315
Laura Ekstrandc2c50772014-12-10 15:35:38 -08002316 get_tex_parameterIiv(ctx, texObj, pname, params, false);
Brian Paul7836a962010-01-04 20:00:00 -07002317}
2318
2319
2320/** New in GL 3.0 */
2321void GLAPIENTRY
2322_mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params)
2323{
2324 struct gl_texture_object *texObj;
2325 GET_CURRENT_CONTEXT(ctx);
Brian Paul7836a962010-01-04 20:00:00 -07002326
Laura Ekstrand5ad53932014-12-10 16:13:31 -08002327 texObj = get_texobj_by_target(ctx, target, GL_TRUE);
Brian Paul02d81df2011-08-04 08:22:31 -06002328 if (!texObj)
2329 return;
Rico Schüller14f02cd2013-10-27 08:02:00 -06002330
Laura Ekstrandc2c50772014-12-10 15:35:38 -08002331 get_tex_parameterIuiv(ctx, texObj, pname, params, false);
Brian Paul7836a962010-01-04 20:00:00 -07002332}
Laura Ekstrand89912d02014-12-10 15:32:20 -08002333
2334
2335void GLAPIENTRY
2336_mesa_GetTextureParameterfv(GLuint texture, GLenum pname, GLfloat *params)
2337{
2338 struct gl_texture_object *obj;
2339 GET_CURRENT_CONTEXT(ctx);
2340
2341 obj = get_texobj_by_name(ctx, texture, GL_TRUE);
2342 if (!obj) {
2343 /* User passed a non-generated name. */
2344 _mesa_error(ctx, GL_INVALID_OPERATION,
2345 "glGetTextureParameterfv(texture)");
2346 return;
2347 }
2348
2349 get_tex_parameterfv(ctx, obj, pname, params, true);
2350}
Laura Ekstrandc2c50772014-12-10 15:35:38 -08002351
2352void GLAPIENTRY
2353_mesa_GetTextureParameteriv(GLuint texture, GLenum pname, GLint *params)
2354{
2355 struct gl_texture_object *obj;
2356 GET_CURRENT_CONTEXT(ctx);
2357
2358 obj = get_texobj_by_name(ctx, texture, GL_TRUE);
2359 if (!obj) {
2360 /* User passed a non-generated name. */
2361 _mesa_error(ctx, GL_INVALID_OPERATION,
2362 "glGetTextureParameteriv(texture)");
2363 return;
2364 }
2365
2366 get_tex_parameteriv(ctx, obj, pname, params, true);
2367}
2368
2369void GLAPIENTRY
2370_mesa_GetTextureParameterIiv(GLuint texture, GLenum pname, GLint *params)
2371{
2372 struct gl_texture_object *texObj;
2373 GET_CURRENT_CONTEXT(ctx);
2374
2375 texObj = get_texobj_by_name(ctx, texture, GL_TRUE);
2376 if (!texObj) {
2377 /* User passed a non-generated name. */
2378 _mesa_error(ctx, GL_INVALID_OPERATION,
2379 "glGetTextureParameterIiv(texture)");
2380 return;
2381 }
2382
2383 get_tex_parameterIiv(ctx, texObj, pname, params, true);
2384}
2385
2386
2387void GLAPIENTRY
2388_mesa_GetTextureParameterIuiv(GLuint texture, GLenum pname, GLuint *params)
2389{
2390 struct gl_texture_object *texObj;
2391 GET_CURRENT_CONTEXT(ctx);
2392
2393 texObj = get_texobj_by_name(ctx, texture, GL_TRUE);
2394 if (!texObj) {
2395 /* User passed a non-generated name. */
2396 _mesa_error(ctx, GL_INVALID_OPERATION,
2397 "glGetTextureParameterIuiv(texture)");
2398 return;
2399 }
2400
2401 get_tex_parameterIuiv(ctx, texObj, pname, params, true);
2402}