r600g: pad the DMA CS to a multiple of 8 dwords
[mesa.git] / src / mesa / main / samplerobj.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2011 VMware, Inc. All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24
25 /**
26 * \file samplerobj.c
27 * \brief Functions for the GL_ARB_sampler_objects extension.
28 * \author Brian Paul
29 */
30
31
32 #include "main/glheader.h"
33 #include "main/context.h"
34 #include "main/dispatch.h"
35 #include "main/enums.h"
36 #include "main/hash.h"
37 #include "main/macros.h"
38 #include "main/mfeatures.h"
39 #include "main/mtypes.h"
40 #include "main/samplerobj.h"
41
42
43 static struct gl_sampler_object *
44 _mesa_lookup_samplerobj(struct gl_context *ctx, GLuint name)
45 {
46 if (name == 0)
47 return NULL;
48 else
49 return (struct gl_sampler_object *)
50 _mesa_HashLookup(ctx->Shared->SamplerObjects, name);
51 }
52
53
54 /**
55 * Handle reference counting.
56 */
57 void
58 _mesa_reference_sampler_object_(struct gl_context *ctx,
59 struct gl_sampler_object **ptr,
60 struct gl_sampler_object *samp)
61 {
62 assert(*ptr != samp); /* The inline wrapper should prevent no-op calls */
63
64 if (*ptr) {
65 /* Unreference the old sampler */
66 GLboolean deleteFlag = GL_FALSE;
67 struct gl_sampler_object *oldSamp = *ptr;
68
69 /*_glthread_LOCK_MUTEX(oldSamp->Mutex);*/
70 ASSERT(oldSamp->RefCount > 0);
71 oldSamp->RefCount--;
72 #if 0
73 printf("SamplerObj %p %d DECR to %d\n",
74 (void *) oldSamp, oldSamp->Name, oldSamp->RefCount);
75 #endif
76 deleteFlag = (oldSamp->RefCount == 0);
77 /*_glthread_UNLOCK_MUTEX(oldSamp->Mutex);*/
78
79 if (deleteFlag) {
80 ASSERT(ctx->Driver.DeleteSamplerObject);
81 ctx->Driver.DeleteSamplerObject(ctx, oldSamp);
82 }
83
84 *ptr = NULL;
85 }
86 ASSERT(!*ptr);
87
88 if (samp) {
89 /* reference new sampler */
90 /*_glthread_LOCK_MUTEX(samp->Mutex);*/
91 if (samp->RefCount == 0) {
92 /* this sampler's being deleted (look just above) */
93 /* Not sure this can every really happen. Warn if it does. */
94 _mesa_problem(NULL, "referencing deleted sampler object");
95 *ptr = NULL;
96 }
97 else {
98 samp->RefCount++;
99 #if 0
100 printf("SamplerObj %p %d INCR to %d\n",
101 (void *) samp, samp->Name, samp->RefCount);
102 #endif
103 *ptr = samp;
104 }
105 /*_glthread_UNLOCK_MUTEX(samp->Mutex);*/
106 }
107 }
108
109
110 /**
111 * Initialize the fields of the given sampler object.
112 */
113 static void
114 _mesa_init_sampler_object(struct gl_sampler_object *sampObj, GLuint name)
115 {
116 sampObj->Name = name;
117 sampObj->RefCount = 1;
118 sampObj->WrapS = GL_REPEAT;
119 sampObj->WrapT = GL_REPEAT;
120 sampObj->WrapR = GL_REPEAT;
121 sampObj->MinFilter = GL_NEAREST_MIPMAP_LINEAR;
122 sampObj->MagFilter = GL_LINEAR;
123 sampObj->BorderColor.f[0] = 0.0;
124 sampObj->BorderColor.f[1] = 0.0;
125 sampObj->BorderColor.f[2] = 0.0;
126 sampObj->BorderColor.f[3] = 0.0;
127 sampObj->MinLod = -1000.0F;
128 sampObj->MaxLod = 1000.0F;
129 sampObj->LodBias = 0.0F;
130 sampObj->MaxAnisotropy = 1.0F;
131 sampObj->CompareMode = GL_NONE;
132 sampObj->CompareFunc = GL_LEQUAL;
133 sampObj->sRGBDecode = GL_DECODE_EXT;
134 sampObj->CubeMapSeamless = GL_FALSE;
135 }
136
137 /**
138 * Fallback for ctx->Driver.NewSamplerObject();
139 */
140 struct gl_sampler_object *
141 _mesa_new_sampler_object(struct gl_context *ctx, GLuint name)
142 {
143 struct gl_sampler_object *sampObj = CALLOC_STRUCT(gl_sampler_object);
144 if (sampObj) {
145 _mesa_init_sampler_object(sampObj, name);
146 }
147 return sampObj;
148 }
149
150
151 /**
152 * Fallback for ctx->Driver.DeleteSamplerObject();
153 */
154 static void
155 _mesa_delete_sampler_object(struct gl_context *ctx,
156 struct gl_sampler_object *sampObj)
157 {
158 free(sampObj);
159 }
160
161
162 void GLAPIENTRY
163 _mesa_GenSamplers(GLsizei count, GLuint *samplers)
164 {
165 GET_CURRENT_CONTEXT(ctx);
166 GLuint first;
167 GLint i;
168
169 if (MESA_VERBOSE & VERBOSE_API)
170 _mesa_debug(ctx, "glGenSamplers(%d)\n", count);
171
172 if (count < 0) {
173 _mesa_error(ctx, GL_INVALID_VALUE, "glGenSamplers");
174 return;
175 }
176
177 if (!samplers)
178 return;
179
180 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->SamplerObjects, count);
181
182 /* Insert the ID and pointer to new sampler object into hash table */
183 for (i = 0; i < count; i++) {
184 struct gl_sampler_object *sampObj =
185 ctx->Driver.NewSamplerObject(ctx, first + i);
186 _mesa_HashInsert(ctx->Shared->SamplerObjects, first + i, sampObj);
187 samplers[i] = first + i;
188 }
189 }
190
191
192 void GLAPIENTRY
193 _mesa_DeleteSamplers(GLsizei count, const GLuint *samplers)
194 {
195 GET_CURRENT_CONTEXT(ctx);
196 GLsizei i;
197
198 FLUSH_VERTICES(ctx, 0);
199
200 if (count < 0) {
201 _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteSamplers(count)");
202 return;
203 }
204
205 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
206
207 for (i = 0; i < count; i++) {
208 if (samplers[i]) {
209 struct gl_sampler_object *sampObj =
210 _mesa_lookup_samplerobj(ctx, samplers[i]);
211 if (sampObj) {
212 /* The ID is immediately freed for re-use */
213 _mesa_HashRemove(ctx->Shared->SamplerObjects, samplers[i]);
214 /* But the object exists until its reference count goes to zero */
215 _mesa_reference_sampler_object(ctx, &sampObj, NULL);
216 }
217 }
218 }
219
220 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
221 }
222
223
224 GLboolean GLAPIENTRY
225 _mesa_IsSampler(GLuint sampler)
226 {
227 struct gl_sampler_object *sampObj;
228 GET_CURRENT_CONTEXT(ctx);
229
230 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
231
232 if (sampler == 0)
233 return GL_FALSE;
234
235 sampObj = _mesa_lookup_samplerobj(ctx, sampler);
236
237 return sampObj != NULL;
238 }
239
240
241 void GLAPIENTRY
242 _mesa_BindSampler(GLuint unit, GLuint sampler)
243 {
244 struct gl_sampler_object *sampObj;
245 GET_CURRENT_CONTEXT(ctx);
246
247 if (unit >= ctx->Const.MaxCombinedTextureImageUnits) {
248 _mesa_error(ctx, GL_INVALID_VALUE, "glBindSampler(unit %u)", unit);
249 return;
250 }
251
252 if (sampler == 0) {
253 /* Use the default sampler object, the one contained in the texture
254 * object.
255 */
256 sampObj = NULL;
257 }
258 else {
259 /* user-defined sampler object */
260 sampObj = _mesa_lookup_samplerobj(ctx, sampler);
261 if (!sampObj) {
262 _mesa_error(ctx, GL_INVALID_OPERATION, "glBindSampler(sampler)");
263 return;
264 }
265 }
266
267 if (ctx->Texture.Unit[unit].Sampler != sampObj) {
268 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
269 }
270
271 /* bind new sampler */
272 _mesa_reference_sampler_object(ctx, &ctx->Texture.Unit[unit].Sampler,
273 sampObj);
274 }
275
276
277 /**
278 * Check if a coordinate wrap mode is legal.
279 * \return GL_TRUE if legal, GL_FALSE otherwise
280 */
281 static GLboolean
282 validate_texture_wrap_mode(struct gl_context *ctx, GLenum wrap)
283 {
284 const struct gl_extensions * const e = &ctx->Extensions;
285
286 switch (wrap) {
287 case GL_CLAMP:
288 case GL_CLAMP_TO_EDGE:
289 case GL_REPEAT:
290 case GL_MIRRORED_REPEAT:
291 return GL_TRUE;
292 case GL_CLAMP_TO_BORDER:
293 return e->ARB_texture_border_clamp;
294 case GL_MIRROR_CLAMP_EXT:
295 return e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp;
296 case GL_MIRROR_CLAMP_TO_EDGE_EXT:
297 return e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp;
298 case GL_MIRROR_CLAMP_TO_BORDER_EXT:
299 return e->EXT_texture_mirror_clamp;
300 default:
301 return GL_FALSE;
302 }
303 }
304
305
306 /**
307 * This is called just prior to changing any sampler object state.
308 */
309 static inline void
310 flush(struct gl_context *ctx)
311 {
312 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
313 }
314
315
316 #define INVALID_PARAM 0x100
317 #define INVALID_PNAME 0x101
318 #define INVALID_VALUE 0x102
319
320 static GLuint
321 set_sampler_wrap_s(struct gl_context *ctx, struct gl_sampler_object *samp,
322 GLint param)
323 {
324 if (samp->WrapS == param)
325 return GL_FALSE;
326 if (validate_texture_wrap_mode(ctx, param)) {
327 flush(ctx);
328 samp->WrapS = param;
329 return GL_TRUE;
330 }
331 return INVALID_PARAM;
332 }
333
334
335 static GLuint
336 set_sampler_wrap_t(struct gl_context *ctx, struct gl_sampler_object *samp,
337 GLint param)
338 {
339 if (samp->WrapT == param)
340 return GL_FALSE;
341 if (validate_texture_wrap_mode(ctx, param)) {
342 flush(ctx);
343 samp->WrapT = param;
344 return GL_TRUE;
345 }
346 return INVALID_PARAM;
347 }
348
349
350 static GLuint
351 set_sampler_wrap_r(struct gl_context *ctx, struct gl_sampler_object *samp,
352 GLint param)
353 {
354 if (samp->WrapR == param)
355 return GL_FALSE;
356 if (validate_texture_wrap_mode(ctx, param)) {
357 flush(ctx);
358 samp->WrapR = param;
359 return GL_TRUE;
360 }
361 return INVALID_PARAM;
362 }
363
364
365 static GLuint
366 set_sampler_min_filter(struct gl_context *ctx, struct gl_sampler_object *samp,
367 GLint param)
368 {
369 if (samp->MinFilter == param)
370 return GL_FALSE;
371
372 switch (param) {
373 case GL_NEAREST:
374 case GL_LINEAR:
375 case GL_NEAREST_MIPMAP_NEAREST:
376 case GL_LINEAR_MIPMAP_NEAREST:
377 case GL_NEAREST_MIPMAP_LINEAR:
378 case GL_LINEAR_MIPMAP_LINEAR:
379 flush(ctx);
380 samp->MinFilter = param;
381 return GL_TRUE;
382 default:
383 return INVALID_PARAM;
384 }
385 }
386
387
388 static GLuint
389 set_sampler_mag_filter(struct gl_context *ctx, struct gl_sampler_object *samp,
390 GLint param)
391 {
392 if (samp->MagFilter == param)
393 return GL_FALSE;
394
395 switch (param) {
396 case GL_NEAREST:
397 case GL_LINEAR:
398 flush(ctx);
399 samp->MagFilter = param;
400 return GL_TRUE;
401 default:
402 return INVALID_PARAM;
403 }
404 }
405
406
407 static GLuint
408 set_sampler_lod_bias(struct gl_context *ctx, struct gl_sampler_object *samp,
409 GLfloat param)
410 {
411 if (samp->LodBias == param)
412 return GL_FALSE;
413
414 flush(ctx);
415 samp->LodBias = param;
416 return GL_TRUE;
417 }
418
419
420 static GLuint
421 set_sampler_border_colorf(struct gl_context *ctx,
422 struct gl_sampler_object *samp,
423 const GLfloat params[4])
424 {
425 flush(ctx);
426 samp->BorderColor.f[RCOMP] = params[0];
427 samp->BorderColor.f[GCOMP] = params[1];
428 samp->BorderColor.f[BCOMP] = params[2];
429 samp->BorderColor.f[ACOMP] = params[3];
430 return GL_TRUE;
431 }
432
433
434 static GLuint
435 set_sampler_border_colori(struct gl_context *ctx,
436 struct gl_sampler_object *samp,
437 const GLint params[4])
438 {
439 flush(ctx);
440 samp->BorderColor.i[RCOMP] = params[0];
441 samp->BorderColor.i[GCOMP] = params[1];
442 samp->BorderColor.i[BCOMP] = params[2];
443 samp->BorderColor.i[ACOMP] = params[3];
444 return GL_TRUE;
445 }
446
447
448 static GLuint
449 set_sampler_border_colorui(struct gl_context *ctx,
450 struct gl_sampler_object *samp,
451 const GLuint params[4])
452 {
453 flush(ctx);
454 samp->BorderColor.ui[RCOMP] = params[0];
455 samp->BorderColor.ui[GCOMP] = params[1];
456 samp->BorderColor.ui[BCOMP] = params[2];
457 samp->BorderColor.ui[ACOMP] = params[3];
458 return GL_TRUE;
459 }
460
461
462 static GLuint
463 set_sampler_min_lod(struct gl_context *ctx, struct gl_sampler_object *samp,
464 GLfloat param)
465 {
466 if (samp->MinLod == param)
467 return GL_FALSE;
468
469 flush(ctx);
470 samp->MinLod = param;
471 return GL_TRUE;
472 }
473
474
475 static GLuint
476 set_sampler_max_lod(struct gl_context *ctx, struct gl_sampler_object *samp,
477 GLfloat param)
478 {
479 if (samp->MaxLod == param)
480 return GL_FALSE;
481
482 flush(ctx);
483 samp->MaxLod = param;
484 return GL_TRUE;
485 }
486
487
488 static GLuint
489 set_sampler_compare_mode(struct gl_context *ctx,
490 struct gl_sampler_object *samp, GLint param)
491 {
492 if (!ctx->Extensions.ARB_shadow)
493 return INVALID_PNAME;
494
495 if (samp->CompareMode == param)
496 return GL_FALSE;
497
498 if (param == GL_NONE ||
499 param == GL_COMPARE_R_TO_TEXTURE_ARB) {
500 flush(ctx);
501 samp->CompareMode = param;
502 return GL_TRUE;
503 }
504
505 return INVALID_PARAM;
506 }
507
508
509 static GLuint
510 set_sampler_compare_func(struct gl_context *ctx,
511 struct gl_sampler_object *samp, GLint param)
512 {
513 if (!ctx->Extensions.ARB_shadow)
514 return INVALID_PNAME;
515
516 if (samp->CompareFunc == param)
517 return GL_FALSE;
518
519 switch (param) {
520 case GL_LEQUAL:
521 case GL_GEQUAL:
522 flush(ctx);
523 samp->CompareFunc = param;
524 return GL_TRUE;
525 case GL_EQUAL:
526 case GL_NOTEQUAL:
527 case GL_LESS:
528 case GL_GREATER:
529 case GL_ALWAYS:
530 case GL_NEVER:
531 if (ctx->Extensions.EXT_shadow_funcs) {
532 flush(ctx);
533 samp->CompareFunc = param;
534 return GL_TRUE;
535 }
536 /* fall-through */
537 default:
538 return INVALID_PARAM;
539 }
540 }
541
542
543 static GLuint
544 set_sampler_max_anisotropy(struct gl_context *ctx,
545 struct gl_sampler_object *samp, GLfloat param)
546 {
547 if (!ctx->Extensions.EXT_texture_filter_anisotropic)
548 return INVALID_PNAME;
549
550 if (samp->MaxAnisotropy == param)
551 return GL_FALSE;
552
553 if (param < 1.0)
554 return INVALID_VALUE;
555
556 flush(ctx);
557 /* clamp to max, that's what NVIDIA does */
558 samp->MaxAnisotropy = MIN2(param, ctx->Const.MaxTextureMaxAnisotropy);
559 return GL_TRUE;
560 }
561
562
563 static GLuint
564 set_sampler_cube_map_seamless(struct gl_context *ctx,
565 struct gl_sampler_object *samp, GLboolean param)
566 {
567 if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
568 return INVALID_PNAME;
569
570 if (samp->CubeMapSeamless == param)
571 return GL_FALSE;
572
573 if (param != GL_TRUE && param != GL_FALSE)
574 return INVALID_VALUE;
575
576 flush(ctx);
577 samp->CubeMapSeamless = param;
578 return GL_TRUE;
579 }
580
581 static GLuint
582 set_sampler_srgb_decode(struct gl_context *ctx,
583 struct gl_sampler_object *samp, GLenum param)
584 {
585 if (!ctx->Extensions.EXT_texture_sRGB_decode)
586 return INVALID_PNAME;
587
588 if (samp->sRGBDecode == param)
589 return GL_FALSE;
590
591 if (param != GL_DECODE_EXT && param != GL_SKIP_DECODE_EXT)
592 return INVALID_VALUE;
593
594 flush(ctx);
595 samp->sRGBDecode = param;
596 return GL_TRUE;
597 }
598
599 void GLAPIENTRY
600 _mesa_SamplerParameteri(GLuint sampler, GLenum pname, GLint param)
601 {
602 struct gl_sampler_object *sampObj;
603 GLuint res;
604 GET_CURRENT_CONTEXT(ctx);
605
606 sampObj = _mesa_lookup_samplerobj(ctx, sampler);
607 if (!sampObj) {
608 _mesa_error(ctx, GL_INVALID_VALUE, "glSamplerParameteri(sampler %u)",
609 sampler);
610 return;
611 }
612
613 switch (pname) {
614 case GL_TEXTURE_WRAP_S:
615 res = set_sampler_wrap_s(ctx, sampObj, param);
616 break;
617 case GL_TEXTURE_WRAP_T:
618 res = set_sampler_wrap_t(ctx, sampObj, param);
619 break;
620 case GL_TEXTURE_WRAP_R:
621 res = set_sampler_wrap_r(ctx, sampObj, param);
622 break;
623 case GL_TEXTURE_MIN_FILTER:
624 res = set_sampler_min_filter(ctx, sampObj, param);
625 break;
626 case GL_TEXTURE_MAG_FILTER:
627 res = set_sampler_mag_filter(ctx, sampObj, param);
628 break;
629 case GL_TEXTURE_MIN_LOD:
630 res = set_sampler_min_lod(ctx, sampObj, (GLfloat) param);
631 break;
632 case GL_TEXTURE_MAX_LOD:
633 res = set_sampler_max_lod(ctx, sampObj, (GLfloat) param);
634 break;
635 case GL_TEXTURE_LOD_BIAS:
636 res = set_sampler_lod_bias(ctx, sampObj, (GLfloat) param);
637 break;
638 case GL_TEXTURE_COMPARE_MODE:
639 res = set_sampler_compare_mode(ctx, sampObj, param);
640 break;
641 case GL_TEXTURE_COMPARE_FUNC:
642 res = set_sampler_compare_func(ctx, sampObj, param);
643 break;
644 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
645 res = set_sampler_max_anisotropy(ctx, sampObj, (GLfloat) param);
646 break;
647 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
648 res = set_sampler_cube_map_seamless(ctx, sampObj, param);
649 break;
650 case GL_TEXTURE_SRGB_DECODE_EXT:
651 res = set_sampler_srgb_decode(ctx, sampObj, param);
652 break;
653 case GL_TEXTURE_BORDER_COLOR:
654 /* fall-through */
655 default:
656 res = INVALID_PNAME;
657 }
658
659 switch (res) {
660 case GL_FALSE:
661 /* no change */
662 break;
663 case GL_TRUE:
664 /* state change - we do nothing special at this time */
665 break;
666 case INVALID_PNAME:
667 _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameteri(pname=%s)\n",
668 _mesa_lookup_enum_by_nr(pname));
669 break;
670 case INVALID_PARAM:
671 _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameteri(param=%d)\n",
672 param);
673 break;
674 case INVALID_VALUE:
675 _mesa_error(ctx, GL_INVALID_VALUE, "glSamplerParameteri(param=%d)\n",
676 param);
677 break;
678 default:
679 ;
680 }
681 }
682
683
684 void GLAPIENTRY
685 _mesa_SamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
686 {
687 struct gl_sampler_object *sampObj;
688 GLuint res;
689 GET_CURRENT_CONTEXT(ctx);
690
691 sampObj = _mesa_lookup_samplerobj(ctx, sampler);
692 if (!sampObj) {
693 _mesa_error(ctx, GL_INVALID_VALUE, "glSamplerParameterf(sampler %u)",
694 sampler);
695 return;
696 }
697
698 switch (pname) {
699 case GL_TEXTURE_WRAP_S:
700 res = set_sampler_wrap_s(ctx, sampObj, (GLint) param);
701 break;
702 case GL_TEXTURE_WRAP_T:
703 res = set_sampler_wrap_t(ctx, sampObj, (GLint) param);
704 break;
705 case GL_TEXTURE_WRAP_R:
706 res = set_sampler_wrap_r(ctx, sampObj, (GLint) param);
707 break;
708 case GL_TEXTURE_MIN_FILTER:
709 res = set_sampler_min_filter(ctx, sampObj, (GLint) param);
710 break;
711 case GL_TEXTURE_MAG_FILTER:
712 res = set_sampler_mag_filter(ctx, sampObj, (GLint) param);
713 break;
714 case GL_TEXTURE_MIN_LOD:
715 res = set_sampler_min_lod(ctx, sampObj, param);
716 break;
717 case GL_TEXTURE_MAX_LOD:
718 res = set_sampler_max_lod(ctx, sampObj, param);
719 break;
720 case GL_TEXTURE_LOD_BIAS:
721 res = set_sampler_lod_bias(ctx, sampObj, param);
722 break;
723 case GL_TEXTURE_COMPARE_MODE:
724 res = set_sampler_compare_mode(ctx, sampObj, (GLint) param);
725 break;
726 case GL_TEXTURE_COMPARE_FUNC:
727 res = set_sampler_compare_func(ctx, sampObj, (GLint) param);
728 break;
729 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
730 res = set_sampler_max_anisotropy(ctx, sampObj, param);
731 break;
732 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
733 res = set_sampler_cube_map_seamless(ctx, sampObj, (GLboolean) param);
734 break;
735 case GL_TEXTURE_SRGB_DECODE_EXT:
736 res = set_sampler_srgb_decode(ctx, sampObj, (GLenum) param);
737 break;
738 case GL_TEXTURE_BORDER_COLOR:
739 /* fall-through */
740 default:
741 res = INVALID_PNAME;
742 }
743
744 switch (res) {
745 case GL_FALSE:
746 /* no change */
747 break;
748 case GL_TRUE:
749 /* state change - we do nothing special at this time */
750 break;
751 case INVALID_PNAME:
752 _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameterf(pname=%s)\n",
753 _mesa_lookup_enum_by_nr(pname));
754 break;
755 case INVALID_PARAM:
756 _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameterf(param=%f)\n",
757 param);
758 break;
759 case INVALID_VALUE:
760 _mesa_error(ctx, GL_INVALID_VALUE, "glSamplerParameterf(param=%f)\n",
761 param);
762 break;
763 default:
764 ;
765 }
766 }
767
768 void GLAPIENTRY
769 _mesa_SamplerParameteriv(GLuint sampler, GLenum pname, const GLint *params)
770 {
771 struct gl_sampler_object *sampObj;
772 GLuint res;
773 GET_CURRENT_CONTEXT(ctx);
774
775 sampObj = _mesa_lookup_samplerobj(ctx, sampler);
776 if (!sampObj) {
777 _mesa_error(ctx, GL_INVALID_VALUE, "glSamplerParameteriv(sampler %u)",
778 sampler);
779 return;
780 }
781
782 switch (pname) {
783 case GL_TEXTURE_WRAP_S:
784 res = set_sampler_wrap_s(ctx, sampObj, params[0]);
785 break;
786 case GL_TEXTURE_WRAP_T:
787 res = set_sampler_wrap_t(ctx, sampObj, params[0]);
788 break;
789 case GL_TEXTURE_WRAP_R:
790 res = set_sampler_wrap_r(ctx, sampObj, params[0]);
791 break;
792 case GL_TEXTURE_MIN_FILTER:
793 res = set_sampler_min_filter(ctx, sampObj, params[0]);
794 break;
795 case GL_TEXTURE_MAG_FILTER:
796 res = set_sampler_mag_filter(ctx, sampObj, params[0]);
797 break;
798 case GL_TEXTURE_MIN_LOD:
799 res = set_sampler_min_lod(ctx, sampObj, (GLfloat) params[0]);
800 break;
801 case GL_TEXTURE_MAX_LOD:
802 res = set_sampler_max_lod(ctx, sampObj, (GLfloat) params[0]);
803 break;
804 case GL_TEXTURE_LOD_BIAS:
805 res = set_sampler_lod_bias(ctx, sampObj, (GLfloat) params[0]);
806 break;
807 case GL_TEXTURE_COMPARE_MODE:
808 res = set_sampler_compare_mode(ctx, sampObj, params[0]);
809 break;
810 case GL_TEXTURE_COMPARE_FUNC:
811 res = set_sampler_compare_func(ctx, sampObj, params[0]);
812 break;
813 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
814 res = set_sampler_max_anisotropy(ctx, sampObj, (GLfloat) params[0]);
815 break;
816 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
817 res = set_sampler_cube_map_seamless(ctx, sampObj, params[0]);
818 break;
819 case GL_TEXTURE_SRGB_DECODE_EXT:
820 res = set_sampler_srgb_decode(ctx, sampObj, params[0]);
821 break;
822 case GL_TEXTURE_BORDER_COLOR:
823 {
824 GLfloat c[4];
825 c[0] = INT_TO_FLOAT(params[0]);
826 c[1] = INT_TO_FLOAT(params[1]);
827 c[2] = INT_TO_FLOAT(params[2]);
828 c[3] = INT_TO_FLOAT(params[3]);
829 res = set_sampler_border_colorf(ctx, sampObj, c);
830 }
831 break;
832 default:
833 res = INVALID_PNAME;
834 }
835
836 switch (res) {
837 case GL_FALSE:
838 /* no change */
839 break;
840 case GL_TRUE:
841 /* state change - we do nothing special at this time */
842 break;
843 case INVALID_PNAME:
844 _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameteriv(pname=%s)\n",
845 _mesa_lookup_enum_by_nr(pname));
846 break;
847 case INVALID_PARAM:
848 _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameteriv(param=%d)\n",
849 params[0]);
850 break;
851 case INVALID_VALUE:
852 _mesa_error(ctx, GL_INVALID_VALUE, "glSamplerParameteriv(param=%d)\n",
853 params[0]);
854 break;
855 default:
856 ;
857 }
858 }
859
860 void GLAPIENTRY
861 _mesa_SamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *params)
862 {
863 struct gl_sampler_object *sampObj;
864 GLuint res;
865 GET_CURRENT_CONTEXT(ctx);
866
867 sampObj = _mesa_lookup_samplerobj(ctx, sampler);
868 if (!sampObj) {
869 _mesa_error(ctx, GL_INVALID_VALUE, "glSamplerParameterfv(sampler %u)",
870 sampler);
871 return;
872 }
873
874 switch (pname) {
875 case GL_TEXTURE_WRAP_S:
876 res = set_sampler_wrap_s(ctx, sampObj, (GLint) params[0]);
877 break;
878 case GL_TEXTURE_WRAP_T:
879 res = set_sampler_wrap_t(ctx, sampObj, (GLint) params[0]);
880 break;
881 case GL_TEXTURE_WRAP_R:
882 res = set_sampler_wrap_r(ctx, sampObj, (GLint) params[0]);
883 break;
884 case GL_TEXTURE_MIN_FILTER:
885 res = set_sampler_min_filter(ctx, sampObj, (GLint) params[0]);
886 break;
887 case GL_TEXTURE_MAG_FILTER:
888 res = set_sampler_mag_filter(ctx, sampObj, (GLint) params[0]);
889 break;
890 case GL_TEXTURE_MIN_LOD:
891 res = set_sampler_min_lod(ctx, sampObj, params[0]);
892 break;
893 case GL_TEXTURE_MAX_LOD:
894 res = set_sampler_max_lod(ctx, sampObj, params[0]);
895 break;
896 case GL_TEXTURE_LOD_BIAS:
897 res = set_sampler_lod_bias(ctx, sampObj, params[0]);
898 break;
899 case GL_TEXTURE_COMPARE_MODE:
900 res = set_sampler_compare_mode(ctx, sampObj, (GLint) params[0]);
901 break;
902 case GL_TEXTURE_COMPARE_FUNC:
903 res = set_sampler_compare_func(ctx, sampObj, (GLint) params[0]);
904 break;
905 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
906 res = set_sampler_max_anisotropy(ctx, sampObj, params[0]);
907 break;
908 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
909 res = set_sampler_cube_map_seamless(ctx, sampObj, (GLboolean) params[0]);
910 break;
911 case GL_TEXTURE_SRGB_DECODE_EXT:
912 res = set_sampler_srgb_decode(ctx, sampObj, (GLenum) params[0]);
913 break;
914 case GL_TEXTURE_BORDER_COLOR:
915 res = set_sampler_border_colorf(ctx, sampObj, params);
916 break;
917 default:
918 res = INVALID_PNAME;
919 }
920
921 switch (res) {
922 case GL_FALSE:
923 /* no change */
924 break;
925 case GL_TRUE:
926 /* state change - we do nothing special at this time */
927 break;
928 case INVALID_PNAME:
929 _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameterfv(pname=%s)\n",
930 _mesa_lookup_enum_by_nr(pname));
931 break;
932 case INVALID_PARAM:
933 _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameterfv(param=%f)\n",
934 params[0]);
935 break;
936 case INVALID_VALUE:
937 _mesa_error(ctx, GL_INVALID_VALUE, "glSamplerParameterfv(param=%f)\n",
938 params[0]);
939 break;
940 default:
941 ;
942 }
943 }
944
945 void GLAPIENTRY
946 _mesa_SamplerParameterIiv(GLuint sampler, GLenum pname, const GLint *params)
947 {
948 struct gl_sampler_object *sampObj;
949 GLuint res;
950 GET_CURRENT_CONTEXT(ctx);
951
952 sampObj = _mesa_lookup_samplerobj(ctx, sampler);
953 if (!sampObj) {
954 _mesa_error(ctx, GL_INVALID_VALUE, "glSamplerParameterIiv(sampler %u)",
955 sampler);
956 return;
957 }
958
959 switch (pname) {
960 case GL_TEXTURE_WRAP_S:
961 res = set_sampler_wrap_s(ctx, sampObj, params[0]);
962 break;
963 case GL_TEXTURE_WRAP_T:
964 res = set_sampler_wrap_t(ctx, sampObj, params[0]);
965 break;
966 case GL_TEXTURE_WRAP_R:
967 res = set_sampler_wrap_r(ctx, sampObj, params[0]);
968 break;
969 case GL_TEXTURE_MIN_FILTER:
970 res = set_sampler_min_filter(ctx, sampObj, params[0]);
971 break;
972 case GL_TEXTURE_MAG_FILTER:
973 res = set_sampler_mag_filter(ctx, sampObj, params[0]);
974 break;
975 case GL_TEXTURE_MIN_LOD:
976 res = set_sampler_min_lod(ctx, sampObj, (GLfloat) params[0]);
977 break;
978 case GL_TEXTURE_MAX_LOD:
979 res = set_sampler_max_lod(ctx, sampObj, (GLfloat) params[0]);
980 break;
981 case GL_TEXTURE_LOD_BIAS:
982 res = set_sampler_lod_bias(ctx, sampObj, (GLfloat) params[0]);
983 break;
984 case GL_TEXTURE_COMPARE_MODE:
985 res = set_sampler_compare_mode(ctx, sampObj, params[0]);
986 break;
987 case GL_TEXTURE_COMPARE_FUNC:
988 res = set_sampler_compare_func(ctx, sampObj, params[0]);
989 break;
990 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
991 res = set_sampler_max_anisotropy(ctx, sampObj, (GLfloat) params[0]);
992 break;
993 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
994 res = set_sampler_cube_map_seamless(ctx, sampObj, params[0]);
995 break;
996 case GL_TEXTURE_SRGB_DECODE_EXT:
997 res = set_sampler_srgb_decode(ctx, sampObj, (GLenum) params[0]);
998 break;
999 case GL_TEXTURE_BORDER_COLOR:
1000 res = set_sampler_border_colori(ctx, sampObj, params);
1001 break;
1002 default:
1003 res = INVALID_PNAME;
1004 }
1005
1006 switch (res) {
1007 case GL_FALSE:
1008 /* no change */
1009 break;
1010 case GL_TRUE:
1011 /* state change - we do nothing special at this time */
1012 break;
1013 case INVALID_PNAME:
1014 _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameterIiv(pname=%s)\n",
1015 _mesa_lookup_enum_by_nr(pname));
1016 break;
1017 case INVALID_PARAM:
1018 _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameterIiv(param=%d)\n",
1019 params[0]);
1020 break;
1021 case INVALID_VALUE:
1022 _mesa_error(ctx, GL_INVALID_VALUE, "glSamplerParameterIiv(param=%d)\n",
1023 params[0]);
1024 break;
1025 default:
1026 ;
1027 }
1028 }
1029
1030
1031 void GLAPIENTRY
1032 _mesa_SamplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *params)
1033 {
1034 struct gl_sampler_object *sampObj;
1035 GLuint res;
1036 GET_CURRENT_CONTEXT(ctx);
1037
1038 sampObj = _mesa_lookup_samplerobj(ctx, sampler);
1039 if (!sampObj) {
1040 _mesa_error(ctx, GL_INVALID_VALUE, "glSamplerParameterIuiv(sampler %u)",
1041 sampler);
1042 return;
1043 }
1044
1045 switch (pname) {
1046 case GL_TEXTURE_WRAP_S:
1047 res = set_sampler_wrap_s(ctx, sampObj, params[0]);
1048 break;
1049 case GL_TEXTURE_WRAP_T:
1050 res = set_sampler_wrap_t(ctx, sampObj, params[0]);
1051 break;
1052 case GL_TEXTURE_WRAP_R:
1053 res = set_sampler_wrap_r(ctx, sampObj, params[0]);
1054 break;
1055 case GL_TEXTURE_MIN_FILTER:
1056 res = set_sampler_min_filter(ctx, sampObj, params[0]);
1057 break;
1058 case GL_TEXTURE_MAG_FILTER:
1059 res = set_sampler_mag_filter(ctx, sampObj, params[0]);
1060 break;
1061 case GL_TEXTURE_MIN_LOD:
1062 res = set_sampler_min_lod(ctx, sampObj, (GLfloat) params[0]);
1063 break;
1064 case GL_TEXTURE_MAX_LOD:
1065 res = set_sampler_max_lod(ctx, sampObj, (GLfloat) params[0]);
1066 break;
1067 case GL_TEXTURE_LOD_BIAS:
1068 res = set_sampler_lod_bias(ctx, sampObj, (GLfloat) params[0]);
1069 break;
1070 case GL_TEXTURE_COMPARE_MODE:
1071 res = set_sampler_compare_mode(ctx, sampObj, params[0]);
1072 break;
1073 case GL_TEXTURE_COMPARE_FUNC:
1074 res = set_sampler_compare_func(ctx, sampObj, params[0]);
1075 break;
1076 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1077 res = set_sampler_max_anisotropy(ctx, sampObj, (GLfloat) params[0]);
1078 break;
1079 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1080 res = set_sampler_cube_map_seamless(ctx, sampObj, params[0]);
1081 break;
1082 case GL_TEXTURE_SRGB_DECODE_EXT:
1083 res = set_sampler_srgb_decode(ctx, sampObj, (GLenum) params[0]);
1084 break;
1085 case GL_TEXTURE_BORDER_COLOR:
1086 res = set_sampler_border_colorui(ctx, sampObj, params);
1087 break;
1088 default:
1089 res = INVALID_PNAME;
1090 }
1091
1092 switch (res) {
1093 case GL_FALSE:
1094 /* no change */
1095 break;
1096 case GL_TRUE:
1097 /* state change - we do nothing special at this time */
1098 break;
1099 case INVALID_PNAME:
1100 _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameterIuiv(pname=%s)\n",
1101 _mesa_lookup_enum_by_nr(pname));
1102 break;
1103 case INVALID_PARAM:
1104 _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameterIuiv(param=%u)\n",
1105 params[0]);
1106 break;
1107 case INVALID_VALUE:
1108 _mesa_error(ctx, GL_INVALID_VALUE, "glSamplerParameterIuiv(param=%u)\n",
1109 params[0]);
1110 break;
1111 default:
1112 ;
1113 }
1114 }
1115
1116
1117 void GLAPIENTRY
1118 _mesa_GetSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
1119 {
1120 struct gl_sampler_object *sampObj;
1121 GET_CURRENT_CONTEXT(ctx);
1122
1123 sampObj = _mesa_lookup_samplerobj(ctx, sampler);
1124 if (!sampObj) {
1125 _mesa_error(ctx, GL_INVALID_VALUE, "glGetSamplerParameteriv(sampler %u)",
1126 sampler);
1127 return;
1128 }
1129
1130 switch (pname) {
1131 case GL_TEXTURE_WRAP_S:
1132 *params = sampObj->WrapS;
1133 break;
1134 case GL_TEXTURE_WRAP_T:
1135 *params = sampObj->WrapT;
1136 break;
1137 case GL_TEXTURE_WRAP_R:
1138 *params = sampObj->WrapR;
1139 break;
1140 case GL_TEXTURE_MIN_FILTER:
1141 *params = sampObj->MinFilter;
1142 break;
1143 case GL_TEXTURE_MAG_FILTER:
1144 *params = sampObj->MagFilter;
1145 break;
1146 case GL_TEXTURE_MIN_LOD:
1147 *params = (GLint) sampObj->MinLod;
1148 break;
1149 case GL_TEXTURE_MAX_LOD:
1150 *params = (GLint) sampObj->MaxLod;
1151 break;
1152 case GL_TEXTURE_LOD_BIAS:
1153 *params = (GLint) sampObj->LodBias;
1154 break;
1155 case GL_TEXTURE_COMPARE_MODE:
1156 if (!ctx->Extensions.ARB_shadow)
1157 goto invalid_pname;
1158 *params = sampObj->CompareMode;
1159 break;
1160 case GL_TEXTURE_COMPARE_FUNC:
1161 if (!ctx->Extensions.ARB_shadow)
1162 goto invalid_pname;
1163 *params = sampObj->CompareFunc;
1164 break;
1165 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1166 *params = (GLint) sampObj->MaxAnisotropy;
1167 break;
1168 case GL_TEXTURE_BORDER_COLOR:
1169 params[0] = FLOAT_TO_INT(sampObj->BorderColor.f[0]);
1170 params[1] = FLOAT_TO_INT(sampObj->BorderColor.f[1]);
1171 params[2] = FLOAT_TO_INT(sampObj->BorderColor.f[2]);
1172 params[3] = FLOAT_TO_INT(sampObj->BorderColor.f[3]);
1173 break;
1174 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1175 if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
1176 goto invalid_pname;
1177 *params = sampObj->CubeMapSeamless;
1178 break;
1179 case GL_TEXTURE_SRGB_DECODE_EXT:
1180 if (!ctx->Extensions.EXT_texture_sRGB_decode)
1181 goto invalid_pname;
1182 *params = (GLenum) sampObj->sRGBDecode;
1183 break;
1184 default:
1185 goto invalid_pname;
1186 }
1187 return;
1188
1189 invalid_pname:
1190 _mesa_error(ctx, GL_INVALID_ENUM, "glGetSamplerParameteriv(pname=%s)",
1191 _mesa_lookup_enum_by_nr(pname));
1192 }
1193
1194
1195 void GLAPIENTRY
1196 _mesa_GetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
1197 {
1198 struct gl_sampler_object *sampObj;
1199 GET_CURRENT_CONTEXT(ctx);
1200
1201 sampObj = _mesa_lookup_samplerobj(ctx, sampler);
1202 if (!sampObj) {
1203 _mesa_error(ctx, GL_INVALID_VALUE, "glGetSamplerParameterfv(sampler %u)",
1204 sampler);
1205 return;
1206 }
1207
1208 switch (pname) {
1209 case GL_TEXTURE_WRAP_S:
1210 *params = (GLfloat) sampObj->WrapS;
1211 break;
1212 case GL_TEXTURE_WRAP_T:
1213 *params = (GLfloat) sampObj->WrapT;
1214 break;
1215 case GL_TEXTURE_WRAP_R:
1216 *params = (GLfloat) sampObj->WrapR;
1217 break;
1218 case GL_TEXTURE_MIN_FILTER:
1219 *params = (GLfloat) sampObj->MinFilter;
1220 break;
1221 case GL_TEXTURE_MAG_FILTER:
1222 *params = (GLfloat) sampObj->MagFilter;
1223 break;
1224 case GL_TEXTURE_MIN_LOD:
1225 *params = sampObj->MinLod;
1226 break;
1227 case GL_TEXTURE_MAX_LOD:
1228 *params = sampObj->MaxLod;
1229 break;
1230 case GL_TEXTURE_LOD_BIAS:
1231 *params = sampObj->LodBias;
1232 break;
1233 case GL_TEXTURE_COMPARE_MODE:
1234 if (!ctx->Extensions.ARB_shadow)
1235 goto invalid_pname;
1236 *params = (GLfloat) sampObj->CompareMode;
1237 break;
1238 case GL_TEXTURE_COMPARE_FUNC:
1239 if (!ctx->Extensions.ARB_shadow)
1240 goto invalid_pname;
1241 *params = (GLfloat) sampObj->CompareFunc;
1242 break;
1243 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1244 *params = sampObj->MaxAnisotropy;
1245 break;
1246 case GL_TEXTURE_BORDER_COLOR:
1247 params[0] = sampObj->BorderColor.f[0];
1248 params[1] = sampObj->BorderColor.f[1];
1249 params[2] = sampObj->BorderColor.f[2];
1250 params[3] = sampObj->BorderColor.f[3];
1251 break;
1252 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1253 if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
1254 goto invalid_pname;
1255 *params = (GLfloat) sampObj->CubeMapSeamless;
1256 break;
1257 case GL_TEXTURE_SRGB_DECODE_EXT:
1258 if (!ctx->Extensions.EXT_texture_sRGB_decode)
1259 goto invalid_pname;
1260 *params = (GLfloat) sampObj->sRGBDecode;
1261 break;
1262 default:
1263 goto invalid_pname;
1264 }
1265 return;
1266
1267 invalid_pname:
1268 _mesa_error(ctx, GL_INVALID_ENUM, "glGetSamplerParameterfv(pname=%s)",
1269 _mesa_lookup_enum_by_nr(pname));
1270 }
1271
1272
1273 void GLAPIENTRY
1274 _mesa_GetSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params)
1275 {
1276 struct gl_sampler_object *sampObj;
1277 GET_CURRENT_CONTEXT(ctx);
1278
1279 sampObj = _mesa_lookup_samplerobj(ctx, sampler);
1280 if (!sampObj) {
1281 _mesa_error(ctx, GL_INVALID_VALUE,
1282 "glGetSamplerParameterIiv(sampler %u)",
1283 sampler);
1284 return;
1285 }
1286
1287 switch (pname) {
1288 case GL_TEXTURE_WRAP_S:
1289 *params = sampObj->WrapS;
1290 break;
1291 case GL_TEXTURE_WRAP_T:
1292 *params = sampObj->WrapT;
1293 break;
1294 case GL_TEXTURE_WRAP_R:
1295 *params = sampObj->WrapR;
1296 break;
1297 case GL_TEXTURE_MIN_FILTER:
1298 *params = sampObj->MinFilter;
1299 break;
1300 case GL_TEXTURE_MAG_FILTER:
1301 *params = sampObj->MagFilter;
1302 break;
1303 case GL_TEXTURE_MIN_LOD:
1304 *params = (GLint) sampObj->MinLod;
1305 break;
1306 case GL_TEXTURE_MAX_LOD:
1307 *params = (GLint) sampObj->MaxLod;
1308 break;
1309 case GL_TEXTURE_LOD_BIAS:
1310 *params = (GLint) sampObj->LodBias;
1311 break;
1312 case GL_TEXTURE_COMPARE_MODE:
1313 if (!ctx->Extensions.ARB_shadow)
1314 goto invalid_pname;
1315 *params = sampObj->CompareMode;
1316 break;
1317 case GL_TEXTURE_COMPARE_FUNC:
1318 if (!ctx->Extensions.ARB_shadow)
1319 goto invalid_pname;
1320 *params = sampObj->CompareFunc;
1321 break;
1322 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1323 *params = (GLint) sampObj->MaxAnisotropy;
1324 break;
1325 case GL_TEXTURE_BORDER_COLOR:
1326 params[0] = sampObj->BorderColor.i[0];
1327 params[1] = sampObj->BorderColor.i[1];
1328 params[2] = sampObj->BorderColor.i[2];
1329 params[3] = sampObj->BorderColor.i[3];
1330 break;
1331 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1332 if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
1333 goto invalid_pname;
1334 *params = sampObj->CubeMapSeamless;
1335 break;
1336 case GL_TEXTURE_SRGB_DECODE_EXT:
1337 if (!ctx->Extensions.EXT_texture_sRGB_decode)
1338 goto invalid_pname;
1339 *params = (GLenum) sampObj->sRGBDecode;
1340 break;
1341 default:
1342 goto invalid_pname;
1343 }
1344 return;
1345
1346 invalid_pname:
1347 _mesa_error(ctx, GL_INVALID_ENUM, "glGetSamplerParameterIiv(pname=%s)",
1348 _mesa_lookup_enum_by_nr(pname));
1349 }
1350
1351
1352 void GLAPIENTRY
1353 _mesa_GetSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params)
1354 {
1355 struct gl_sampler_object *sampObj;
1356 GET_CURRENT_CONTEXT(ctx);
1357
1358 sampObj = _mesa_lookup_samplerobj(ctx, sampler);
1359 if (!sampObj) {
1360 _mesa_error(ctx, GL_INVALID_VALUE,
1361 "glGetSamplerParameterIuiv(sampler %u)",
1362 sampler);
1363 return;
1364 }
1365
1366 switch (pname) {
1367 case GL_TEXTURE_WRAP_S:
1368 *params = sampObj->WrapS;
1369 break;
1370 case GL_TEXTURE_WRAP_T:
1371 *params = sampObj->WrapT;
1372 break;
1373 case GL_TEXTURE_WRAP_R:
1374 *params = sampObj->WrapR;
1375 break;
1376 case GL_TEXTURE_MIN_FILTER:
1377 *params = sampObj->MinFilter;
1378 break;
1379 case GL_TEXTURE_MAG_FILTER:
1380 *params = sampObj->MagFilter;
1381 break;
1382 case GL_TEXTURE_MIN_LOD:
1383 *params = (GLuint) sampObj->MinLod;
1384 break;
1385 case GL_TEXTURE_MAX_LOD:
1386 *params = (GLuint) sampObj->MaxLod;
1387 break;
1388 case GL_TEXTURE_LOD_BIAS:
1389 *params = (GLuint) sampObj->LodBias;
1390 break;
1391 case GL_TEXTURE_COMPARE_MODE:
1392 if (!ctx->Extensions.ARB_shadow)
1393 goto invalid_pname;
1394 *params = sampObj->CompareMode;
1395 break;
1396 case GL_TEXTURE_COMPARE_FUNC:
1397 if (!ctx->Extensions.ARB_shadow)
1398 goto invalid_pname;
1399 *params = sampObj->CompareFunc;
1400 break;
1401 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1402 *params = (GLuint) sampObj->MaxAnisotropy;
1403 break;
1404 case GL_TEXTURE_BORDER_COLOR:
1405 params[0] = sampObj->BorderColor.ui[0];
1406 params[1] = sampObj->BorderColor.ui[1];
1407 params[2] = sampObj->BorderColor.ui[2];
1408 params[3] = sampObj->BorderColor.ui[3];
1409 break;
1410 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1411 if (!ctx->Extensions.AMD_seamless_cubemap_per_texture)
1412 goto invalid_pname;
1413 *params = sampObj->CubeMapSeamless;
1414 break;
1415 case GL_TEXTURE_SRGB_DECODE_EXT:
1416 if (!ctx->Extensions.EXT_texture_sRGB_decode)
1417 goto invalid_pname;
1418 *params = (GLenum) sampObj->sRGBDecode;
1419 break;
1420 default:
1421 goto invalid_pname;
1422 }
1423 return;
1424
1425 invalid_pname:
1426 _mesa_error(ctx, GL_INVALID_ENUM, "glGetSamplerParameterIuiv(pname=%s)",
1427 _mesa_lookup_enum_by_nr(pname));
1428 }
1429
1430
1431 void
1432 _mesa_init_sampler_object_functions(struct dd_function_table *driver)
1433 {
1434 driver->NewSamplerObject = _mesa_new_sampler_object;
1435 driver->DeleteSamplerObject = _mesa_delete_sampler_object;
1436 }