2 * Mesa 3-D graphics library
4 * Copyright (C) 2011 VMware, Inc. All Rights Reserved.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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 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.
27 * \brief Functions for the GL_ARB_sampler_objects extension.
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/mtypes.h"
39 #include "main/samplerobj.h"
42 struct gl_sampler_object
*
43 _mesa_lookup_samplerobj(struct gl_context
*ctx
, GLuint name
)
48 return (struct gl_sampler_object
*)
49 _mesa_HashLookup(ctx
->Shared
->SamplerObjects
, name
);
54 * Handle reference counting.
57 _mesa_reference_sampler_object_(struct gl_context
*ctx
,
58 struct gl_sampler_object
**ptr
,
59 struct gl_sampler_object
*samp
)
61 assert(*ptr
!= samp
); /* The inline wrapper should prevent no-op calls */
64 /* Unreference the old sampler */
65 GLboolean deleteFlag
= GL_FALSE
;
66 struct gl_sampler_object
*oldSamp
= *ptr
;
68 /*_glthread_LOCK_MUTEX(oldSamp->Mutex);*/
69 ASSERT(oldSamp
->RefCount
> 0);
72 printf("SamplerObj %p %d DECR to %d\n",
73 (void *) oldSamp
, oldSamp
->Name
, oldSamp
->RefCount
);
75 deleteFlag
= (oldSamp
->RefCount
== 0);
76 /*_glthread_UNLOCK_MUTEX(oldSamp->Mutex);*/
79 ASSERT(ctx
->Driver
.DeleteSamplerObject
);
80 ctx
->Driver
.DeleteSamplerObject(ctx
, oldSamp
);
88 /* reference new sampler */
89 /*_glthread_LOCK_MUTEX(samp->Mutex);*/
90 if (samp
->RefCount
== 0) {
91 /* this sampler's being deleted (look just above) */
92 /* Not sure this can every really happen. Warn if it does. */
93 _mesa_problem(NULL
, "referencing deleted sampler object");
99 printf("SamplerObj %p %d INCR to %d\n",
100 (void *) samp
, samp
->Name
, samp
->RefCount
);
104 /*_glthread_UNLOCK_MUTEX(samp->Mutex);*/
110 * Initialize the fields of the given sampler object.
113 _mesa_init_sampler_object(struct gl_sampler_object
*sampObj
, GLuint name
)
115 sampObj
->Name
= name
;
116 sampObj
->RefCount
= 1;
117 sampObj
->WrapS
= GL_REPEAT
;
118 sampObj
->WrapT
= GL_REPEAT
;
119 sampObj
->WrapR
= GL_REPEAT
;
120 sampObj
->MinFilter
= GL_NEAREST_MIPMAP_LINEAR
;
121 sampObj
->MagFilter
= GL_LINEAR
;
122 sampObj
->BorderColor
.f
[0] = 0.0;
123 sampObj
->BorderColor
.f
[1] = 0.0;
124 sampObj
->BorderColor
.f
[2] = 0.0;
125 sampObj
->BorderColor
.f
[3] = 0.0;
126 sampObj
->MinLod
= -1000.0F
;
127 sampObj
->MaxLod
= 1000.0F
;
128 sampObj
->LodBias
= 0.0F
;
129 sampObj
->MaxAnisotropy
= 1.0F
;
130 sampObj
->CompareMode
= GL_NONE
;
131 sampObj
->CompareFunc
= GL_LEQUAL
;
132 sampObj
->sRGBDecode
= GL_DECODE_EXT
;
133 sampObj
->CubeMapSeamless
= GL_FALSE
;
137 * Fallback for ctx->Driver.NewSamplerObject();
139 struct gl_sampler_object
*
140 _mesa_new_sampler_object(struct gl_context
*ctx
, GLuint name
)
142 struct gl_sampler_object
*sampObj
= CALLOC_STRUCT(gl_sampler_object
);
144 _mesa_init_sampler_object(sampObj
, name
);
151 * Fallback for ctx->Driver.DeleteSamplerObject();
154 _mesa_delete_sampler_object(struct gl_context
*ctx
,
155 struct gl_sampler_object
*sampObj
)
162 _mesa_GenSamplers(GLsizei count
, GLuint
*samplers
)
164 GET_CURRENT_CONTEXT(ctx
);
168 if (MESA_VERBOSE
& VERBOSE_API
)
169 _mesa_debug(ctx
, "glGenSamplers(%d)\n", count
);
172 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenSamplers");
179 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->SamplerObjects
, count
);
181 /* Insert the ID and pointer to new sampler object into hash table */
182 for (i
= 0; i
< count
; i
++) {
183 struct gl_sampler_object
*sampObj
=
184 ctx
->Driver
.NewSamplerObject(ctx
, first
+ i
);
185 _mesa_HashInsert(ctx
->Shared
->SamplerObjects
, first
+ i
, sampObj
);
186 samplers
[i
] = first
+ i
;
192 _mesa_DeleteSamplers(GLsizei count
, const GLuint
*samplers
)
194 GET_CURRENT_CONTEXT(ctx
);
197 FLUSH_VERTICES(ctx
, 0);
200 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteSamplers(count)");
204 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
206 for (i
= 0; i
< count
; i
++) {
209 struct gl_sampler_object
*sampObj
=
210 _mesa_lookup_samplerobj(ctx
, samplers
[i
]);
213 /* If the sampler is currently bound, unbind it. */
214 for (j
= 0; j
< ctx
->Const
.MaxCombinedTextureImageUnits
; j
++) {
215 if (ctx
->Texture
.Unit
[j
].Sampler
== sampObj
) {
216 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
217 _mesa_reference_sampler_object(ctx
, &ctx
->Texture
.Unit
[j
].Sampler
, NULL
);
221 /* The ID is immediately freed for re-use */
222 _mesa_HashRemove(ctx
->Shared
->SamplerObjects
, samplers
[i
]);
223 /* But the object exists until its reference count goes to zero */
224 _mesa_reference_sampler_object(ctx
, &sampObj
, NULL
);
229 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
234 _mesa_IsSampler(GLuint sampler
)
236 struct gl_sampler_object
*sampObj
;
237 GET_CURRENT_CONTEXT(ctx
);
239 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
244 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
246 return sampObj
!= NULL
;
251 _mesa_BindSampler(GLuint unit
, GLuint sampler
)
253 struct gl_sampler_object
*sampObj
;
254 GET_CURRENT_CONTEXT(ctx
);
256 if (unit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
257 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindSampler(unit %u)", unit
);
262 /* Use the default sampler object, the one contained in the texture
268 /* user-defined sampler object */
269 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
271 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindSampler(sampler)");
276 if (ctx
->Texture
.Unit
[unit
].Sampler
!= sampObj
) {
277 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
280 /* bind new sampler */
281 _mesa_reference_sampler_object(ctx
, &ctx
->Texture
.Unit
[unit
].Sampler
,
287 * Check if a coordinate wrap mode is legal.
288 * \return GL_TRUE if legal, GL_FALSE otherwise
291 validate_texture_wrap_mode(struct gl_context
*ctx
, GLenum wrap
)
293 const struct gl_extensions
* const e
= &ctx
->Extensions
;
297 case GL_CLAMP_TO_EDGE
:
299 case GL_MIRRORED_REPEAT
:
301 case GL_CLAMP_TO_BORDER
:
302 return e
->ARB_texture_border_clamp
;
303 case GL_MIRROR_CLAMP_EXT
:
304 return e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
;
305 case GL_MIRROR_CLAMP_TO_EDGE_EXT
:
306 return e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
;
307 case GL_MIRROR_CLAMP_TO_BORDER_EXT
:
308 return e
->EXT_texture_mirror_clamp
;
316 * This is called just prior to changing any sampler object state.
319 flush(struct gl_context
*ctx
)
321 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
325 #define INVALID_PARAM 0x100
326 #define INVALID_PNAME 0x101
327 #define INVALID_VALUE 0x102
330 set_sampler_wrap_s(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
333 if (samp
->WrapS
== param
)
335 if (validate_texture_wrap_mode(ctx
, param
)) {
340 return INVALID_PARAM
;
345 set_sampler_wrap_t(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
348 if (samp
->WrapT
== param
)
350 if (validate_texture_wrap_mode(ctx
, param
)) {
355 return INVALID_PARAM
;
360 set_sampler_wrap_r(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
363 if (samp
->WrapR
== param
)
365 if (validate_texture_wrap_mode(ctx
, param
)) {
370 return INVALID_PARAM
;
375 set_sampler_min_filter(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
378 if (samp
->MinFilter
== param
)
384 case GL_NEAREST_MIPMAP_NEAREST
:
385 case GL_LINEAR_MIPMAP_NEAREST
:
386 case GL_NEAREST_MIPMAP_LINEAR
:
387 case GL_LINEAR_MIPMAP_LINEAR
:
389 samp
->MinFilter
= param
;
392 return INVALID_PARAM
;
398 set_sampler_mag_filter(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
401 if (samp
->MagFilter
== param
)
408 samp
->MagFilter
= param
;
411 return INVALID_PARAM
;
417 set_sampler_lod_bias(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
420 if (samp
->LodBias
== param
)
424 samp
->LodBias
= param
;
430 set_sampler_border_colorf(struct gl_context
*ctx
,
431 struct gl_sampler_object
*samp
,
432 const GLfloat params
[4])
435 samp
->BorderColor
.f
[RCOMP
] = params
[0];
436 samp
->BorderColor
.f
[GCOMP
] = params
[1];
437 samp
->BorderColor
.f
[BCOMP
] = params
[2];
438 samp
->BorderColor
.f
[ACOMP
] = params
[3];
444 set_sampler_border_colori(struct gl_context
*ctx
,
445 struct gl_sampler_object
*samp
,
446 const GLint params
[4])
449 samp
->BorderColor
.i
[RCOMP
] = params
[0];
450 samp
->BorderColor
.i
[GCOMP
] = params
[1];
451 samp
->BorderColor
.i
[BCOMP
] = params
[2];
452 samp
->BorderColor
.i
[ACOMP
] = params
[3];
458 set_sampler_border_colorui(struct gl_context
*ctx
,
459 struct gl_sampler_object
*samp
,
460 const GLuint params
[4])
463 samp
->BorderColor
.ui
[RCOMP
] = params
[0];
464 samp
->BorderColor
.ui
[GCOMP
] = params
[1];
465 samp
->BorderColor
.ui
[BCOMP
] = params
[2];
466 samp
->BorderColor
.ui
[ACOMP
] = params
[3];
472 set_sampler_min_lod(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
475 if (samp
->MinLod
== param
)
479 samp
->MinLod
= param
;
485 set_sampler_max_lod(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
488 if (samp
->MaxLod
== param
)
492 samp
->MaxLod
= param
;
498 set_sampler_compare_mode(struct gl_context
*ctx
,
499 struct gl_sampler_object
*samp
, GLint param
)
501 if (!ctx
->Extensions
.ARB_shadow
)
502 return INVALID_PNAME
;
504 if (samp
->CompareMode
== param
)
507 if (param
== GL_NONE
||
508 param
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
510 samp
->CompareMode
= param
;
514 return INVALID_PARAM
;
519 set_sampler_compare_func(struct gl_context
*ctx
,
520 struct gl_sampler_object
*samp
, GLint param
)
522 if (!ctx
->Extensions
.ARB_shadow
)
523 return INVALID_PNAME
;
525 if (samp
->CompareFunc
== param
)
532 samp
->CompareFunc
= param
;
540 if (ctx
->Extensions
.EXT_shadow_funcs
) {
542 samp
->CompareFunc
= param
;
547 return INVALID_PARAM
;
553 set_sampler_max_anisotropy(struct gl_context
*ctx
,
554 struct gl_sampler_object
*samp
, GLfloat param
)
556 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
557 return INVALID_PNAME
;
559 if (samp
->MaxAnisotropy
== param
)
563 return INVALID_VALUE
;
566 /* clamp to max, that's what NVIDIA does */
567 samp
->MaxAnisotropy
= MIN2(param
, ctx
->Const
.MaxTextureMaxAnisotropy
);
573 set_sampler_cube_map_seamless(struct gl_context
*ctx
,
574 struct gl_sampler_object
*samp
, GLboolean param
)
576 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
577 return INVALID_PNAME
;
579 if (samp
->CubeMapSeamless
== param
)
582 if (param
!= GL_TRUE
&& param
!= GL_FALSE
)
583 return INVALID_VALUE
;
586 samp
->CubeMapSeamless
= param
;
591 set_sampler_srgb_decode(struct gl_context
*ctx
,
592 struct gl_sampler_object
*samp
, GLenum param
)
594 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
595 return INVALID_PNAME
;
597 if (samp
->sRGBDecode
== param
)
600 if (param
!= GL_DECODE_EXT
&& param
!= GL_SKIP_DECODE_EXT
)
601 return INVALID_VALUE
;
604 samp
->sRGBDecode
= param
;
609 _mesa_SamplerParameteri(GLuint sampler
, GLenum pname
, GLint param
)
611 struct gl_sampler_object
*sampObj
;
613 GET_CURRENT_CONTEXT(ctx
);
615 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
617 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameteri(sampler %u)",
623 case GL_TEXTURE_WRAP_S
:
624 res
= set_sampler_wrap_s(ctx
, sampObj
, param
);
626 case GL_TEXTURE_WRAP_T
:
627 res
= set_sampler_wrap_t(ctx
, sampObj
, param
);
629 case GL_TEXTURE_WRAP_R
:
630 res
= set_sampler_wrap_r(ctx
, sampObj
, param
);
632 case GL_TEXTURE_MIN_FILTER
:
633 res
= set_sampler_min_filter(ctx
, sampObj
, param
);
635 case GL_TEXTURE_MAG_FILTER
:
636 res
= set_sampler_mag_filter(ctx
, sampObj
, param
);
638 case GL_TEXTURE_MIN_LOD
:
639 res
= set_sampler_min_lod(ctx
, sampObj
, (GLfloat
) param
);
641 case GL_TEXTURE_MAX_LOD
:
642 res
= set_sampler_max_lod(ctx
, sampObj
, (GLfloat
) param
);
644 case GL_TEXTURE_LOD_BIAS
:
645 res
= set_sampler_lod_bias(ctx
, sampObj
, (GLfloat
) param
);
647 case GL_TEXTURE_COMPARE_MODE
:
648 res
= set_sampler_compare_mode(ctx
, sampObj
, param
);
650 case GL_TEXTURE_COMPARE_FUNC
:
651 res
= set_sampler_compare_func(ctx
, sampObj
, param
);
653 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
654 res
= set_sampler_max_anisotropy(ctx
, sampObj
, (GLfloat
) param
);
656 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
657 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, param
);
659 case GL_TEXTURE_SRGB_DECODE_EXT
:
660 res
= set_sampler_srgb_decode(ctx
, sampObj
, param
);
662 case GL_TEXTURE_BORDER_COLOR
:
673 /* state change - we do nothing special at this time */
676 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameteri(pname=%s)\n",
677 _mesa_lookup_enum_by_nr(pname
));
680 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameteri(param=%d)\n",
684 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameteri(param=%d)\n",
694 _mesa_SamplerParameterf(GLuint sampler
, GLenum pname
, GLfloat param
)
696 struct gl_sampler_object
*sampObj
;
698 GET_CURRENT_CONTEXT(ctx
);
700 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
702 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterf(sampler %u)",
708 case GL_TEXTURE_WRAP_S
:
709 res
= set_sampler_wrap_s(ctx
, sampObj
, (GLint
) param
);
711 case GL_TEXTURE_WRAP_T
:
712 res
= set_sampler_wrap_t(ctx
, sampObj
, (GLint
) param
);
714 case GL_TEXTURE_WRAP_R
:
715 res
= set_sampler_wrap_r(ctx
, sampObj
, (GLint
) param
);
717 case GL_TEXTURE_MIN_FILTER
:
718 res
= set_sampler_min_filter(ctx
, sampObj
, (GLint
) param
);
720 case GL_TEXTURE_MAG_FILTER
:
721 res
= set_sampler_mag_filter(ctx
, sampObj
, (GLint
) param
);
723 case GL_TEXTURE_MIN_LOD
:
724 res
= set_sampler_min_lod(ctx
, sampObj
, param
);
726 case GL_TEXTURE_MAX_LOD
:
727 res
= set_sampler_max_lod(ctx
, sampObj
, param
);
729 case GL_TEXTURE_LOD_BIAS
:
730 res
= set_sampler_lod_bias(ctx
, sampObj
, param
);
732 case GL_TEXTURE_COMPARE_MODE
:
733 res
= set_sampler_compare_mode(ctx
, sampObj
, (GLint
) param
);
735 case GL_TEXTURE_COMPARE_FUNC
:
736 res
= set_sampler_compare_func(ctx
, sampObj
, (GLint
) param
);
738 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
739 res
= set_sampler_max_anisotropy(ctx
, sampObj
, param
);
741 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
742 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, (GLboolean
) param
);
744 case GL_TEXTURE_SRGB_DECODE_EXT
:
745 res
= set_sampler_srgb_decode(ctx
, sampObj
, (GLenum
) param
);
747 case GL_TEXTURE_BORDER_COLOR
:
758 /* state change - we do nothing special at this time */
761 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterf(pname=%s)\n",
762 _mesa_lookup_enum_by_nr(pname
));
765 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterf(param=%f)\n",
769 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterf(param=%f)\n",
778 _mesa_SamplerParameteriv(GLuint sampler
, GLenum pname
, const GLint
*params
)
780 struct gl_sampler_object
*sampObj
;
782 GET_CURRENT_CONTEXT(ctx
);
784 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
786 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameteriv(sampler %u)",
792 case GL_TEXTURE_WRAP_S
:
793 res
= set_sampler_wrap_s(ctx
, sampObj
, params
[0]);
795 case GL_TEXTURE_WRAP_T
:
796 res
= set_sampler_wrap_t(ctx
, sampObj
, params
[0]);
798 case GL_TEXTURE_WRAP_R
:
799 res
= set_sampler_wrap_r(ctx
, sampObj
, params
[0]);
801 case GL_TEXTURE_MIN_FILTER
:
802 res
= set_sampler_min_filter(ctx
, sampObj
, params
[0]);
804 case GL_TEXTURE_MAG_FILTER
:
805 res
= set_sampler_mag_filter(ctx
, sampObj
, params
[0]);
807 case GL_TEXTURE_MIN_LOD
:
808 res
= set_sampler_min_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
810 case GL_TEXTURE_MAX_LOD
:
811 res
= set_sampler_max_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
813 case GL_TEXTURE_LOD_BIAS
:
814 res
= set_sampler_lod_bias(ctx
, sampObj
, (GLfloat
) params
[0]);
816 case GL_TEXTURE_COMPARE_MODE
:
817 res
= set_sampler_compare_mode(ctx
, sampObj
, params
[0]);
819 case GL_TEXTURE_COMPARE_FUNC
:
820 res
= set_sampler_compare_func(ctx
, sampObj
, params
[0]);
822 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
823 res
= set_sampler_max_anisotropy(ctx
, sampObj
, (GLfloat
) params
[0]);
825 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
826 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, params
[0]);
828 case GL_TEXTURE_SRGB_DECODE_EXT
:
829 res
= set_sampler_srgb_decode(ctx
, sampObj
, params
[0]);
831 case GL_TEXTURE_BORDER_COLOR
:
834 c
[0] = INT_TO_FLOAT(params
[0]);
835 c
[1] = INT_TO_FLOAT(params
[1]);
836 c
[2] = INT_TO_FLOAT(params
[2]);
837 c
[3] = INT_TO_FLOAT(params
[3]);
838 res
= set_sampler_border_colorf(ctx
, sampObj
, c
);
850 /* state change - we do nothing special at this time */
853 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameteriv(pname=%s)\n",
854 _mesa_lookup_enum_by_nr(pname
));
857 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameteriv(param=%d)\n",
861 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameteriv(param=%d)\n",
870 _mesa_SamplerParameterfv(GLuint sampler
, GLenum pname
, const GLfloat
*params
)
872 struct gl_sampler_object
*sampObj
;
874 GET_CURRENT_CONTEXT(ctx
);
876 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
878 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterfv(sampler %u)",
884 case GL_TEXTURE_WRAP_S
:
885 res
= set_sampler_wrap_s(ctx
, sampObj
, (GLint
) params
[0]);
887 case GL_TEXTURE_WRAP_T
:
888 res
= set_sampler_wrap_t(ctx
, sampObj
, (GLint
) params
[0]);
890 case GL_TEXTURE_WRAP_R
:
891 res
= set_sampler_wrap_r(ctx
, sampObj
, (GLint
) params
[0]);
893 case GL_TEXTURE_MIN_FILTER
:
894 res
= set_sampler_min_filter(ctx
, sampObj
, (GLint
) params
[0]);
896 case GL_TEXTURE_MAG_FILTER
:
897 res
= set_sampler_mag_filter(ctx
, sampObj
, (GLint
) params
[0]);
899 case GL_TEXTURE_MIN_LOD
:
900 res
= set_sampler_min_lod(ctx
, sampObj
, params
[0]);
902 case GL_TEXTURE_MAX_LOD
:
903 res
= set_sampler_max_lod(ctx
, sampObj
, params
[0]);
905 case GL_TEXTURE_LOD_BIAS
:
906 res
= set_sampler_lod_bias(ctx
, sampObj
, params
[0]);
908 case GL_TEXTURE_COMPARE_MODE
:
909 res
= set_sampler_compare_mode(ctx
, sampObj
, (GLint
) params
[0]);
911 case GL_TEXTURE_COMPARE_FUNC
:
912 res
= set_sampler_compare_func(ctx
, sampObj
, (GLint
) params
[0]);
914 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
915 res
= set_sampler_max_anisotropy(ctx
, sampObj
, params
[0]);
917 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
918 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, (GLboolean
) params
[0]);
920 case GL_TEXTURE_SRGB_DECODE_EXT
:
921 res
= set_sampler_srgb_decode(ctx
, sampObj
, (GLenum
) params
[0]);
923 case GL_TEXTURE_BORDER_COLOR
:
924 res
= set_sampler_border_colorf(ctx
, sampObj
, params
);
935 /* state change - we do nothing special at this time */
938 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterfv(pname=%s)\n",
939 _mesa_lookup_enum_by_nr(pname
));
942 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterfv(param=%f)\n",
946 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterfv(param=%f)\n",
955 _mesa_SamplerParameterIiv(GLuint sampler
, GLenum pname
, const GLint
*params
)
957 struct gl_sampler_object
*sampObj
;
959 GET_CURRENT_CONTEXT(ctx
);
961 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
963 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterIiv(sampler %u)",
969 case GL_TEXTURE_WRAP_S
:
970 res
= set_sampler_wrap_s(ctx
, sampObj
, params
[0]);
972 case GL_TEXTURE_WRAP_T
:
973 res
= set_sampler_wrap_t(ctx
, sampObj
, params
[0]);
975 case GL_TEXTURE_WRAP_R
:
976 res
= set_sampler_wrap_r(ctx
, sampObj
, params
[0]);
978 case GL_TEXTURE_MIN_FILTER
:
979 res
= set_sampler_min_filter(ctx
, sampObj
, params
[0]);
981 case GL_TEXTURE_MAG_FILTER
:
982 res
= set_sampler_mag_filter(ctx
, sampObj
, params
[0]);
984 case GL_TEXTURE_MIN_LOD
:
985 res
= set_sampler_min_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
987 case GL_TEXTURE_MAX_LOD
:
988 res
= set_sampler_max_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
990 case GL_TEXTURE_LOD_BIAS
:
991 res
= set_sampler_lod_bias(ctx
, sampObj
, (GLfloat
) params
[0]);
993 case GL_TEXTURE_COMPARE_MODE
:
994 res
= set_sampler_compare_mode(ctx
, sampObj
, params
[0]);
996 case GL_TEXTURE_COMPARE_FUNC
:
997 res
= set_sampler_compare_func(ctx
, sampObj
, params
[0]);
999 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1000 res
= set_sampler_max_anisotropy(ctx
, sampObj
, (GLfloat
) params
[0]);
1002 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1003 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, params
[0]);
1005 case GL_TEXTURE_SRGB_DECODE_EXT
:
1006 res
= set_sampler_srgb_decode(ctx
, sampObj
, (GLenum
) params
[0]);
1008 case GL_TEXTURE_BORDER_COLOR
:
1009 res
= set_sampler_border_colori(ctx
, sampObj
, params
);
1012 res
= INVALID_PNAME
;
1020 /* state change - we do nothing special at this time */
1023 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterIiv(pname=%s)\n",
1024 _mesa_lookup_enum_by_nr(pname
));
1027 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterIiv(param=%d)\n",
1031 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterIiv(param=%d)\n",
1041 _mesa_SamplerParameterIuiv(GLuint sampler
, GLenum pname
, const GLuint
*params
)
1043 struct gl_sampler_object
*sampObj
;
1045 GET_CURRENT_CONTEXT(ctx
);
1047 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1049 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterIuiv(sampler %u)",
1055 case GL_TEXTURE_WRAP_S
:
1056 res
= set_sampler_wrap_s(ctx
, sampObj
, params
[0]);
1058 case GL_TEXTURE_WRAP_T
:
1059 res
= set_sampler_wrap_t(ctx
, sampObj
, params
[0]);
1061 case GL_TEXTURE_WRAP_R
:
1062 res
= set_sampler_wrap_r(ctx
, sampObj
, params
[0]);
1064 case GL_TEXTURE_MIN_FILTER
:
1065 res
= set_sampler_min_filter(ctx
, sampObj
, params
[0]);
1067 case GL_TEXTURE_MAG_FILTER
:
1068 res
= set_sampler_mag_filter(ctx
, sampObj
, params
[0]);
1070 case GL_TEXTURE_MIN_LOD
:
1071 res
= set_sampler_min_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
1073 case GL_TEXTURE_MAX_LOD
:
1074 res
= set_sampler_max_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
1076 case GL_TEXTURE_LOD_BIAS
:
1077 res
= set_sampler_lod_bias(ctx
, sampObj
, (GLfloat
) params
[0]);
1079 case GL_TEXTURE_COMPARE_MODE
:
1080 res
= set_sampler_compare_mode(ctx
, sampObj
, params
[0]);
1082 case GL_TEXTURE_COMPARE_FUNC
:
1083 res
= set_sampler_compare_func(ctx
, sampObj
, params
[0]);
1085 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1086 res
= set_sampler_max_anisotropy(ctx
, sampObj
, (GLfloat
) params
[0]);
1088 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1089 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, params
[0]);
1091 case GL_TEXTURE_SRGB_DECODE_EXT
:
1092 res
= set_sampler_srgb_decode(ctx
, sampObj
, (GLenum
) params
[0]);
1094 case GL_TEXTURE_BORDER_COLOR
:
1095 res
= set_sampler_border_colorui(ctx
, sampObj
, params
);
1098 res
= INVALID_PNAME
;
1106 /* state change - we do nothing special at this time */
1109 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterIuiv(pname=%s)\n",
1110 _mesa_lookup_enum_by_nr(pname
));
1113 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterIuiv(param=%u)\n",
1117 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterIuiv(param=%u)\n",
1127 _mesa_GetSamplerParameteriv(GLuint sampler
, GLenum pname
, GLint
*params
)
1129 struct gl_sampler_object
*sampObj
;
1130 GET_CURRENT_CONTEXT(ctx
);
1132 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1134 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetSamplerParameteriv(sampler %u)",
1140 case GL_TEXTURE_WRAP_S
:
1141 *params
= sampObj
->WrapS
;
1143 case GL_TEXTURE_WRAP_T
:
1144 *params
= sampObj
->WrapT
;
1146 case GL_TEXTURE_WRAP_R
:
1147 *params
= sampObj
->WrapR
;
1149 case GL_TEXTURE_MIN_FILTER
:
1150 *params
= sampObj
->MinFilter
;
1152 case GL_TEXTURE_MAG_FILTER
:
1153 *params
= sampObj
->MagFilter
;
1155 case GL_TEXTURE_MIN_LOD
:
1156 *params
= (GLint
) sampObj
->MinLod
;
1158 case GL_TEXTURE_MAX_LOD
:
1159 *params
= (GLint
) sampObj
->MaxLod
;
1161 case GL_TEXTURE_LOD_BIAS
:
1162 *params
= (GLint
) sampObj
->LodBias
;
1164 case GL_TEXTURE_COMPARE_MODE
:
1165 if (!ctx
->Extensions
.ARB_shadow
)
1167 *params
= sampObj
->CompareMode
;
1169 case GL_TEXTURE_COMPARE_FUNC
:
1170 if (!ctx
->Extensions
.ARB_shadow
)
1172 *params
= sampObj
->CompareFunc
;
1174 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1175 *params
= (GLint
) sampObj
->MaxAnisotropy
;
1177 case GL_TEXTURE_BORDER_COLOR
:
1178 params
[0] = FLOAT_TO_INT(sampObj
->BorderColor
.f
[0]);
1179 params
[1] = FLOAT_TO_INT(sampObj
->BorderColor
.f
[1]);
1180 params
[2] = FLOAT_TO_INT(sampObj
->BorderColor
.f
[2]);
1181 params
[3] = FLOAT_TO_INT(sampObj
->BorderColor
.f
[3]);
1183 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1184 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1186 *params
= sampObj
->CubeMapSeamless
;
1188 case GL_TEXTURE_SRGB_DECODE_EXT
:
1189 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1191 *params
= (GLenum
) sampObj
->sRGBDecode
;
1199 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSamplerParameteriv(pname=%s)",
1200 _mesa_lookup_enum_by_nr(pname
));
1205 _mesa_GetSamplerParameterfv(GLuint sampler
, GLenum pname
, GLfloat
*params
)
1207 struct gl_sampler_object
*sampObj
;
1208 GET_CURRENT_CONTEXT(ctx
);
1210 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1212 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetSamplerParameterfv(sampler %u)",
1218 case GL_TEXTURE_WRAP_S
:
1219 *params
= (GLfloat
) sampObj
->WrapS
;
1221 case GL_TEXTURE_WRAP_T
:
1222 *params
= (GLfloat
) sampObj
->WrapT
;
1224 case GL_TEXTURE_WRAP_R
:
1225 *params
= (GLfloat
) sampObj
->WrapR
;
1227 case GL_TEXTURE_MIN_FILTER
:
1228 *params
= (GLfloat
) sampObj
->MinFilter
;
1230 case GL_TEXTURE_MAG_FILTER
:
1231 *params
= (GLfloat
) sampObj
->MagFilter
;
1233 case GL_TEXTURE_MIN_LOD
:
1234 *params
= sampObj
->MinLod
;
1236 case GL_TEXTURE_MAX_LOD
:
1237 *params
= sampObj
->MaxLod
;
1239 case GL_TEXTURE_LOD_BIAS
:
1240 *params
= sampObj
->LodBias
;
1242 case GL_TEXTURE_COMPARE_MODE
:
1243 if (!ctx
->Extensions
.ARB_shadow
)
1245 *params
= (GLfloat
) sampObj
->CompareMode
;
1247 case GL_TEXTURE_COMPARE_FUNC
:
1248 if (!ctx
->Extensions
.ARB_shadow
)
1250 *params
= (GLfloat
) sampObj
->CompareFunc
;
1252 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1253 *params
= sampObj
->MaxAnisotropy
;
1255 case GL_TEXTURE_BORDER_COLOR
:
1256 params
[0] = sampObj
->BorderColor
.f
[0];
1257 params
[1] = sampObj
->BorderColor
.f
[1];
1258 params
[2] = sampObj
->BorderColor
.f
[2];
1259 params
[3] = sampObj
->BorderColor
.f
[3];
1261 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1262 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1264 *params
= (GLfloat
) sampObj
->CubeMapSeamless
;
1266 case GL_TEXTURE_SRGB_DECODE_EXT
:
1267 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1269 *params
= (GLfloat
) sampObj
->sRGBDecode
;
1277 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSamplerParameterfv(pname=%s)",
1278 _mesa_lookup_enum_by_nr(pname
));
1283 _mesa_GetSamplerParameterIiv(GLuint sampler
, GLenum pname
, GLint
*params
)
1285 struct gl_sampler_object
*sampObj
;
1286 GET_CURRENT_CONTEXT(ctx
);
1288 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1290 _mesa_error(ctx
, GL_INVALID_VALUE
,
1291 "glGetSamplerParameterIiv(sampler %u)",
1297 case GL_TEXTURE_WRAP_S
:
1298 *params
= sampObj
->WrapS
;
1300 case GL_TEXTURE_WRAP_T
:
1301 *params
= sampObj
->WrapT
;
1303 case GL_TEXTURE_WRAP_R
:
1304 *params
= sampObj
->WrapR
;
1306 case GL_TEXTURE_MIN_FILTER
:
1307 *params
= sampObj
->MinFilter
;
1309 case GL_TEXTURE_MAG_FILTER
:
1310 *params
= sampObj
->MagFilter
;
1312 case GL_TEXTURE_MIN_LOD
:
1313 *params
= (GLint
) sampObj
->MinLod
;
1315 case GL_TEXTURE_MAX_LOD
:
1316 *params
= (GLint
) sampObj
->MaxLod
;
1318 case GL_TEXTURE_LOD_BIAS
:
1319 *params
= (GLint
) sampObj
->LodBias
;
1321 case GL_TEXTURE_COMPARE_MODE
:
1322 if (!ctx
->Extensions
.ARB_shadow
)
1324 *params
= sampObj
->CompareMode
;
1326 case GL_TEXTURE_COMPARE_FUNC
:
1327 if (!ctx
->Extensions
.ARB_shadow
)
1329 *params
= sampObj
->CompareFunc
;
1331 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1332 *params
= (GLint
) sampObj
->MaxAnisotropy
;
1334 case GL_TEXTURE_BORDER_COLOR
:
1335 params
[0] = sampObj
->BorderColor
.i
[0];
1336 params
[1] = sampObj
->BorderColor
.i
[1];
1337 params
[2] = sampObj
->BorderColor
.i
[2];
1338 params
[3] = sampObj
->BorderColor
.i
[3];
1340 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1341 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1343 *params
= sampObj
->CubeMapSeamless
;
1345 case GL_TEXTURE_SRGB_DECODE_EXT
:
1346 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1348 *params
= (GLenum
) sampObj
->sRGBDecode
;
1356 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSamplerParameterIiv(pname=%s)",
1357 _mesa_lookup_enum_by_nr(pname
));
1362 _mesa_GetSamplerParameterIuiv(GLuint sampler
, GLenum pname
, GLuint
*params
)
1364 struct gl_sampler_object
*sampObj
;
1365 GET_CURRENT_CONTEXT(ctx
);
1367 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1369 _mesa_error(ctx
, GL_INVALID_VALUE
,
1370 "glGetSamplerParameterIuiv(sampler %u)",
1376 case GL_TEXTURE_WRAP_S
:
1377 *params
= sampObj
->WrapS
;
1379 case GL_TEXTURE_WRAP_T
:
1380 *params
= sampObj
->WrapT
;
1382 case GL_TEXTURE_WRAP_R
:
1383 *params
= sampObj
->WrapR
;
1385 case GL_TEXTURE_MIN_FILTER
:
1386 *params
= sampObj
->MinFilter
;
1388 case GL_TEXTURE_MAG_FILTER
:
1389 *params
= sampObj
->MagFilter
;
1391 case GL_TEXTURE_MIN_LOD
:
1392 *params
= (GLuint
) sampObj
->MinLod
;
1394 case GL_TEXTURE_MAX_LOD
:
1395 *params
= (GLuint
) sampObj
->MaxLod
;
1397 case GL_TEXTURE_LOD_BIAS
:
1398 *params
= (GLuint
) sampObj
->LodBias
;
1400 case GL_TEXTURE_COMPARE_MODE
:
1401 if (!ctx
->Extensions
.ARB_shadow
)
1403 *params
= sampObj
->CompareMode
;
1405 case GL_TEXTURE_COMPARE_FUNC
:
1406 if (!ctx
->Extensions
.ARB_shadow
)
1408 *params
= sampObj
->CompareFunc
;
1410 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1411 *params
= (GLuint
) sampObj
->MaxAnisotropy
;
1413 case GL_TEXTURE_BORDER_COLOR
:
1414 params
[0] = sampObj
->BorderColor
.ui
[0];
1415 params
[1] = sampObj
->BorderColor
.ui
[1];
1416 params
[2] = sampObj
->BorderColor
.ui
[2];
1417 params
[3] = sampObj
->BorderColor
.ui
[3];
1419 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1420 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1422 *params
= sampObj
->CubeMapSeamless
;
1424 case GL_TEXTURE_SRGB_DECODE_EXT
:
1425 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1427 *params
= (GLenum
) sampObj
->sRGBDecode
;
1435 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSamplerParameterIuiv(pname=%s)",
1436 _mesa_lookup_enum_by_nr(pname
));
1441 _mesa_init_sampler_object_functions(struct dd_function_table
*driver
)
1443 driver
->NewSamplerObject
= _mesa_new_sampler_object
;
1444 driver
->DeleteSamplerObject
= _mesa_delete_sampler_object
;