Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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