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