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 * 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.
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/mfeatures.h"
39 #include "main/mtypes.h"
40 #include "main/samplerobj.h"
43 static struct gl_sampler_object
*
44 _mesa_lookup_samplerobj(struct gl_context
*ctx
, GLuint name
)
49 return (struct gl_sampler_object
*)
50 _mesa_HashLookup(ctx
->Shared
->SamplerObjects
, name
);
55 * Handle reference counting.
58 _mesa_reference_sampler_object_(struct gl_context
*ctx
,
59 struct gl_sampler_object
**ptr
,
60 struct gl_sampler_object
*samp
)
62 assert(*ptr
!= samp
); /* The inline wrapper should prevent no-op calls */
65 /* Unreference the old sampler */
66 GLboolean deleteFlag
= GL_FALSE
;
67 struct gl_sampler_object
*oldSamp
= *ptr
;
69 /*_glthread_LOCK_MUTEX(oldSamp->Mutex);*/
70 ASSERT(oldSamp
->RefCount
> 0);
73 printf("SamplerObj %p %d DECR to %d\n",
74 (void *) oldSamp
, oldSamp
->Name
, oldSamp
->RefCount
);
76 deleteFlag
= (oldSamp
->RefCount
== 0);
77 /*_glthread_UNLOCK_MUTEX(oldSamp->Mutex);*/
80 ASSERT(ctx
->Driver
.DeleteSamplerObject
);
81 ctx
->Driver
.DeleteSamplerObject(ctx
, oldSamp
);
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");
100 printf("SamplerObj %p %d INCR to %d\n",
101 (void *) samp
, samp
->Name
, samp
->RefCount
);
105 /*_glthread_UNLOCK_MUTEX(samp->Mutex);*/
111 * Initialize the fields of the given sampler object.
114 _mesa_init_sampler_object(struct gl_sampler_object
*sampObj
, GLuint name
)
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
;
138 * Fallback for ctx->Driver.NewSamplerObject();
140 struct gl_sampler_object
*
141 _mesa_new_sampler_object(struct gl_context
*ctx
, GLuint name
)
143 struct gl_sampler_object
*sampObj
= CALLOC_STRUCT(gl_sampler_object
);
145 _mesa_init_sampler_object(sampObj
, name
);
152 * Fallback for ctx->Driver.DeleteSamplerObject();
155 _mesa_delete_sampler_object(struct gl_context
*ctx
,
156 struct gl_sampler_object
*sampObj
)
163 _mesa_GenSamplers(GLsizei count
, GLuint
*samplers
)
165 GET_CURRENT_CONTEXT(ctx
);
169 ASSERT_OUTSIDE_BEGIN_END(ctx
);
171 if (MESA_VERBOSE
& VERBOSE_API
)
172 _mesa_debug(ctx
, "glGenSamplers(%d)\n", count
);
175 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenSamplers");
182 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->SamplerObjects
, count
);
184 /* Insert the ID and pointer to new sampler object into hash table */
185 for (i
= 0; i
< count
; i
++) {
186 struct gl_sampler_object
*sampObj
=
187 ctx
->Driver
.NewSamplerObject(ctx
, first
+ i
);
188 _mesa_HashInsert(ctx
->Shared
->SamplerObjects
, first
+ i
, sampObj
);
189 samplers
[i
] = first
+ i
;
195 _mesa_DeleteSamplers(GLsizei count
, const GLuint
*samplers
)
197 GET_CURRENT_CONTEXT(ctx
);
200 ASSERT_OUTSIDE_BEGIN_END(ctx
);
201 FLUSH_VERTICES(ctx
, 0);
204 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteSamplers(count)");
208 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
210 for (i
= 0; i
< count
; i
++) {
212 struct gl_sampler_object
*sampObj
=
213 _mesa_lookup_samplerobj(ctx
, samplers
[i
]);
215 /* The ID is immediately freed for re-use */
216 _mesa_HashRemove(ctx
->Shared
->SamplerObjects
, samplers
[i
]);
217 /* But the object exists until its reference count goes to zero */
218 _mesa_reference_sampler_object(ctx
, &sampObj
, NULL
);
223 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
228 _mesa_IsSampler(GLuint sampler
)
230 struct gl_sampler_object
*sampObj
;
231 GET_CURRENT_CONTEXT(ctx
);
233 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
238 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
240 return sampObj
!= NULL
;
245 _mesa_BindSampler(GLuint unit
, GLuint sampler
)
247 struct gl_sampler_object
*sampObj
;
248 GET_CURRENT_CONTEXT(ctx
);
250 if (unit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
251 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindSampler(unit %u)", unit
);
256 /* Use the default sampler object, the one contained in the texture
262 /* user-defined sampler object */
263 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
265 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindSampler(sampler)");
270 if (ctx
->Texture
.Unit
[unit
].Sampler
!= sampObj
) {
271 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
274 /* bind new sampler */
275 _mesa_reference_sampler_object(ctx
, &ctx
->Texture
.Unit
[unit
].Sampler
,
281 * Check if a coordinate wrap mode is legal.
282 * \return GL_TRUE if legal, GL_FALSE otherwise
285 validate_texture_wrap_mode(struct gl_context
*ctx
, GLenum wrap
)
287 const struct gl_extensions
* const e
= &ctx
->Extensions
;
291 case GL_CLAMP_TO_EDGE
:
293 case GL_MIRRORED_REPEAT
:
295 case GL_CLAMP_TO_BORDER
:
296 return e
->ARB_texture_border_clamp
;
297 case GL_MIRROR_CLAMP_EXT
:
298 return e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
;
299 case GL_MIRROR_CLAMP_TO_EDGE_EXT
:
300 return e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
;
301 case GL_MIRROR_CLAMP_TO_BORDER_EXT
:
302 return e
->EXT_texture_mirror_clamp
;
310 * This is called just prior to changing any sampler object state.
313 flush(struct gl_context
*ctx
)
315 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
319 #define INVALID_PARAM 0x100
320 #define INVALID_PNAME 0x101
321 #define INVALID_VALUE 0x102
324 set_sampler_wrap_s(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
327 if (samp
->WrapS
== param
)
329 if (validate_texture_wrap_mode(ctx
, param
)) {
334 return INVALID_PARAM
;
339 set_sampler_wrap_t(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
342 if (samp
->WrapT
== param
)
344 if (validate_texture_wrap_mode(ctx
, param
)) {
349 return INVALID_PARAM
;
354 set_sampler_wrap_r(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
357 if (samp
->WrapR
== param
)
359 if (validate_texture_wrap_mode(ctx
, param
)) {
364 return INVALID_PARAM
;
369 set_sampler_min_filter(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
372 if (samp
->MinFilter
== param
)
378 case GL_NEAREST_MIPMAP_NEAREST
:
379 case GL_LINEAR_MIPMAP_NEAREST
:
380 case GL_NEAREST_MIPMAP_LINEAR
:
381 case GL_LINEAR_MIPMAP_LINEAR
:
383 samp
->MinFilter
= param
;
386 return INVALID_PARAM
;
392 set_sampler_mag_filter(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
395 if (samp
->MagFilter
== param
)
402 samp
->MagFilter
= param
;
405 return INVALID_PARAM
;
411 set_sampler_lod_bias(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
414 if (samp
->LodBias
== param
)
418 samp
->LodBias
= param
;
424 set_sampler_border_colorf(struct gl_context
*ctx
,
425 struct gl_sampler_object
*samp
,
426 const GLfloat params
[4])
429 samp
->BorderColor
.f
[RCOMP
] = params
[0];
430 samp
->BorderColor
.f
[GCOMP
] = params
[1];
431 samp
->BorderColor
.f
[BCOMP
] = params
[2];
432 samp
->BorderColor
.f
[ACOMP
] = params
[3];
438 set_sampler_border_colori(struct gl_context
*ctx
,
439 struct gl_sampler_object
*samp
,
440 const GLint params
[4])
443 samp
->BorderColor
.i
[RCOMP
] = params
[0];
444 samp
->BorderColor
.i
[GCOMP
] = params
[1];
445 samp
->BorderColor
.i
[BCOMP
] = params
[2];
446 samp
->BorderColor
.i
[ACOMP
] = params
[3];
452 set_sampler_border_colorui(struct gl_context
*ctx
,
453 struct gl_sampler_object
*samp
,
454 const GLuint params
[4])
457 samp
->BorderColor
.ui
[RCOMP
] = params
[0];
458 samp
->BorderColor
.ui
[GCOMP
] = params
[1];
459 samp
->BorderColor
.ui
[BCOMP
] = params
[2];
460 samp
->BorderColor
.ui
[ACOMP
] = params
[3];
466 set_sampler_min_lod(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
469 if (samp
->MinLod
== param
)
473 samp
->MinLod
= param
;
479 set_sampler_max_lod(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
482 if (samp
->MaxLod
== param
)
486 samp
->MaxLod
= param
;
492 set_sampler_compare_mode(struct gl_context
*ctx
,
493 struct gl_sampler_object
*samp
, GLint param
)
495 if (!ctx
->Extensions
.ARB_shadow
)
496 return INVALID_PNAME
;
498 if (samp
->CompareMode
== param
)
501 if (param
== GL_NONE
||
502 param
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
504 samp
->CompareMode
= param
;
508 return INVALID_PARAM
;
513 set_sampler_compare_func(struct gl_context
*ctx
,
514 struct gl_sampler_object
*samp
, GLint param
)
516 if (!ctx
->Extensions
.ARB_shadow
)
517 return INVALID_PNAME
;
519 if (samp
->CompareFunc
== param
)
526 samp
->CompareFunc
= param
;
534 if (ctx
->Extensions
.EXT_shadow_funcs
) {
536 samp
->CompareFunc
= param
;
541 return INVALID_PARAM
;
547 set_sampler_max_anisotropy(struct gl_context
*ctx
,
548 struct gl_sampler_object
*samp
, GLfloat param
)
550 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
551 return INVALID_PNAME
;
553 if (samp
->MaxAnisotropy
== param
)
557 return INVALID_VALUE
;
560 /* clamp to max, that's what NVIDIA does */
561 samp
->MaxAnisotropy
= MIN2(param
, ctx
->Const
.MaxTextureMaxAnisotropy
);
567 set_sampler_cube_map_seamless(struct gl_context
*ctx
,
568 struct gl_sampler_object
*samp
, GLboolean param
)
570 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
571 return INVALID_PNAME
;
573 if (samp
->CubeMapSeamless
== param
)
576 if (param
!= GL_TRUE
&& param
!= GL_FALSE
)
577 return INVALID_VALUE
;
580 samp
->CubeMapSeamless
= param
;
585 set_sampler_srgb_decode(struct gl_context
*ctx
,
586 struct gl_sampler_object
*samp
, GLenum param
)
588 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
589 return INVALID_PNAME
;
591 if (samp
->sRGBDecode
== param
)
594 if (param
!= GL_DECODE_EXT
&& param
!= GL_SKIP_DECODE_EXT
)
595 return INVALID_VALUE
;
598 samp
->sRGBDecode
= param
;
603 _mesa_SamplerParameteri(GLuint sampler
, GLenum pname
, GLint param
)
605 struct gl_sampler_object
*sampObj
;
607 GET_CURRENT_CONTEXT(ctx
);
609 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
611 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameteri(sampler %u)",
617 case GL_TEXTURE_WRAP_S
:
618 res
= set_sampler_wrap_s(ctx
, sampObj
, param
);
620 case GL_TEXTURE_WRAP_T
:
621 res
= set_sampler_wrap_t(ctx
, sampObj
, param
);
623 case GL_TEXTURE_WRAP_R
:
624 res
= set_sampler_wrap_r(ctx
, sampObj
, param
);
626 case GL_TEXTURE_MIN_FILTER
:
627 res
= set_sampler_min_filter(ctx
, sampObj
, param
);
629 case GL_TEXTURE_MAG_FILTER
:
630 res
= set_sampler_mag_filter(ctx
, sampObj
, param
);
632 case GL_TEXTURE_MIN_LOD
:
633 res
= set_sampler_min_lod(ctx
, sampObj
, (GLfloat
) param
);
635 case GL_TEXTURE_MAX_LOD
:
636 res
= set_sampler_max_lod(ctx
, sampObj
, (GLfloat
) param
);
638 case GL_TEXTURE_LOD_BIAS
:
639 res
= set_sampler_lod_bias(ctx
, sampObj
, (GLfloat
) param
);
641 case GL_TEXTURE_COMPARE_MODE
:
642 res
= set_sampler_compare_mode(ctx
, sampObj
, param
);
644 case GL_TEXTURE_COMPARE_FUNC
:
645 res
= set_sampler_compare_func(ctx
, sampObj
, param
);
647 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
648 res
= set_sampler_max_anisotropy(ctx
, sampObj
, (GLfloat
) param
);
650 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
651 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, param
);
653 case GL_TEXTURE_SRGB_DECODE_EXT
:
654 res
= set_sampler_srgb_decode(ctx
, sampObj
, param
);
656 case GL_TEXTURE_BORDER_COLOR
:
667 /* state change - we do nothing special at this time */
670 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameteri(pname=%s)\n",
671 _mesa_lookup_enum_by_nr(pname
));
674 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameteri(param=%d)\n",
678 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameteri(param=%d)\n",
688 _mesa_SamplerParameterf(GLuint sampler
, GLenum pname
, GLfloat param
)
690 struct gl_sampler_object
*sampObj
;
692 GET_CURRENT_CONTEXT(ctx
);
694 ASSERT_OUTSIDE_BEGIN_END(ctx
);
696 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
698 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterf(sampler %u)",
704 case GL_TEXTURE_WRAP_S
:
705 res
= set_sampler_wrap_s(ctx
, sampObj
, (GLint
) param
);
707 case GL_TEXTURE_WRAP_T
:
708 res
= set_sampler_wrap_t(ctx
, sampObj
, (GLint
) param
);
710 case GL_TEXTURE_WRAP_R
:
711 res
= set_sampler_wrap_r(ctx
, sampObj
, (GLint
) param
);
713 case GL_TEXTURE_MIN_FILTER
:
714 res
= set_sampler_min_filter(ctx
, sampObj
, (GLint
) param
);
716 case GL_TEXTURE_MAG_FILTER
:
717 res
= set_sampler_mag_filter(ctx
, sampObj
, (GLint
) param
);
719 case GL_TEXTURE_MIN_LOD
:
720 res
= set_sampler_min_lod(ctx
, sampObj
, param
);
722 case GL_TEXTURE_MAX_LOD
:
723 res
= set_sampler_max_lod(ctx
, sampObj
, param
);
725 case GL_TEXTURE_LOD_BIAS
:
726 res
= set_sampler_lod_bias(ctx
, sampObj
, param
);
728 case GL_TEXTURE_COMPARE_MODE
:
729 res
= set_sampler_compare_mode(ctx
, sampObj
, (GLint
) param
);
731 case GL_TEXTURE_COMPARE_FUNC
:
732 res
= set_sampler_compare_func(ctx
, sampObj
, (GLint
) param
);
734 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
735 res
= set_sampler_max_anisotropy(ctx
, sampObj
, param
);
737 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
738 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, (GLboolean
) param
);
740 case GL_TEXTURE_SRGB_DECODE_EXT
:
741 res
= set_sampler_srgb_decode(ctx
, sampObj
, (GLenum
) param
);
743 case GL_TEXTURE_BORDER_COLOR
:
754 /* state change - we do nothing special at this time */
757 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterf(pname=%s)\n",
758 _mesa_lookup_enum_by_nr(pname
));
761 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterf(param=%f)\n",
765 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterf(param=%f)\n",
774 _mesa_SamplerParameteriv(GLuint sampler
, GLenum pname
, const GLint
*params
)
776 struct gl_sampler_object
*sampObj
;
778 GET_CURRENT_CONTEXT(ctx
);
780 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
782 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameteriv(sampler %u)",
788 case GL_TEXTURE_WRAP_S
:
789 res
= set_sampler_wrap_s(ctx
, sampObj
, params
[0]);
791 case GL_TEXTURE_WRAP_T
:
792 res
= set_sampler_wrap_t(ctx
, sampObj
, params
[0]);
794 case GL_TEXTURE_WRAP_R
:
795 res
= set_sampler_wrap_r(ctx
, sampObj
, params
[0]);
797 case GL_TEXTURE_MIN_FILTER
:
798 res
= set_sampler_min_filter(ctx
, sampObj
, params
[0]);
800 case GL_TEXTURE_MAG_FILTER
:
801 res
= set_sampler_mag_filter(ctx
, sampObj
, params
[0]);
803 case GL_TEXTURE_MIN_LOD
:
804 res
= set_sampler_min_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
806 case GL_TEXTURE_MAX_LOD
:
807 res
= set_sampler_max_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
809 case GL_TEXTURE_LOD_BIAS
:
810 res
= set_sampler_lod_bias(ctx
, sampObj
, (GLfloat
) params
[0]);
812 case GL_TEXTURE_COMPARE_MODE
:
813 res
= set_sampler_compare_mode(ctx
, sampObj
, params
[0]);
815 case GL_TEXTURE_COMPARE_FUNC
:
816 res
= set_sampler_compare_func(ctx
, sampObj
, params
[0]);
818 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
819 res
= set_sampler_max_anisotropy(ctx
, sampObj
, (GLfloat
) params
[0]);
821 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
822 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, params
[0]);
824 case GL_TEXTURE_SRGB_DECODE_EXT
:
825 res
= set_sampler_srgb_decode(ctx
, sampObj
, params
[0]);
827 case GL_TEXTURE_BORDER_COLOR
:
830 c
[0] = INT_TO_FLOAT(params
[0]);
831 c
[1] = INT_TO_FLOAT(params
[1]);
832 c
[2] = INT_TO_FLOAT(params
[2]);
833 c
[3] = INT_TO_FLOAT(params
[3]);
834 res
= set_sampler_border_colorf(ctx
, sampObj
, c
);
846 /* state change - we do nothing special at this time */
849 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameteriv(pname=%s)\n",
850 _mesa_lookup_enum_by_nr(pname
));
853 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameteriv(param=%d)\n",
857 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameteriv(param=%d)\n",
866 _mesa_SamplerParameterfv(GLuint sampler
, GLenum pname
, const GLfloat
*params
)
868 struct gl_sampler_object
*sampObj
;
870 GET_CURRENT_CONTEXT(ctx
);
872 ASSERT_OUTSIDE_BEGIN_END(ctx
);
874 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
876 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterfv(sampler %u)",
882 case GL_TEXTURE_WRAP_S
:
883 res
= set_sampler_wrap_s(ctx
, sampObj
, (GLint
) params
[0]);
885 case GL_TEXTURE_WRAP_T
:
886 res
= set_sampler_wrap_t(ctx
, sampObj
, (GLint
) params
[0]);
888 case GL_TEXTURE_WRAP_R
:
889 res
= set_sampler_wrap_r(ctx
, sampObj
, (GLint
) params
[0]);
891 case GL_TEXTURE_MIN_FILTER
:
892 res
= set_sampler_min_filter(ctx
, sampObj
, (GLint
) params
[0]);
894 case GL_TEXTURE_MAG_FILTER
:
895 res
= set_sampler_mag_filter(ctx
, sampObj
, (GLint
) params
[0]);
897 case GL_TEXTURE_MIN_LOD
:
898 res
= set_sampler_min_lod(ctx
, sampObj
, params
[0]);
900 case GL_TEXTURE_MAX_LOD
:
901 res
= set_sampler_max_lod(ctx
, sampObj
, params
[0]);
903 case GL_TEXTURE_LOD_BIAS
:
904 res
= set_sampler_lod_bias(ctx
, sampObj
, params
[0]);
906 case GL_TEXTURE_COMPARE_MODE
:
907 res
= set_sampler_compare_mode(ctx
, sampObj
, (GLint
) params
[0]);
909 case GL_TEXTURE_COMPARE_FUNC
:
910 res
= set_sampler_compare_func(ctx
, sampObj
, (GLint
) params
[0]);
912 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
913 res
= set_sampler_max_anisotropy(ctx
, sampObj
, params
[0]);
915 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
916 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, (GLboolean
) params
[0]);
918 case GL_TEXTURE_SRGB_DECODE_EXT
:
919 res
= set_sampler_srgb_decode(ctx
, sampObj
, (GLenum
) params
[0]);
921 case GL_TEXTURE_BORDER_COLOR
:
922 res
= set_sampler_border_colorf(ctx
, sampObj
, params
);
933 /* state change - we do nothing special at this time */
936 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterfv(pname=%s)\n",
937 _mesa_lookup_enum_by_nr(pname
));
940 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterfv(param=%f)\n",
944 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterfv(param=%f)\n",
953 _mesa_SamplerParameterIiv(GLuint sampler
, GLenum pname
, const GLint
*params
)
955 struct gl_sampler_object
*sampObj
;
957 GET_CURRENT_CONTEXT(ctx
);
959 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
961 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterIiv(sampler %u)",
967 case GL_TEXTURE_WRAP_S
:
968 res
= set_sampler_wrap_s(ctx
, sampObj
, params
[0]);
970 case GL_TEXTURE_WRAP_T
:
971 res
= set_sampler_wrap_t(ctx
, sampObj
, params
[0]);
973 case GL_TEXTURE_WRAP_R
:
974 res
= set_sampler_wrap_r(ctx
, sampObj
, params
[0]);
976 case GL_TEXTURE_MIN_FILTER
:
977 res
= set_sampler_min_filter(ctx
, sampObj
, params
[0]);
979 case GL_TEXTURE_MAG_FILTER
:
980 res
= set_sampler_mag_filter(ctx
, sampObj
, params
[0]);
982 case GL_TEXTURE_MIN_LOD
:
983 res
= set_sampler_min_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
985 case GL_TEXTURE_MAX_LOD
:
986 res
= set_sampler_max_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
988 case GL_TEXTURE_LOD_BIAS
:
989 res
= set_sampler_lod_bias(ctx
, sampObj
, (GLfloat
) params
[0]);
991 case GL_TEXTURE_COMPARE_MODE
:
992 res
= set_sampler_compare_mode(ctx
, sampObj
, params
[0]);
994 case GL_TEXTURE_COMPARE_FUNC
:
995 res
= set_sampler_compare_func(ctx
, sampObj
, params
[0]);
997 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
998 res
= set_sampler_max_anisotropy(ctx
, sampObj
, (GLfloat
) params
[0]);
1000 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1001 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, params
[0]);
1003 case GL_TEXTURE_SRGB_DECODE_EXT
:
1004 res
= set_sampler_srgb_decode(ctx
, sampObj
, (GLenum
) params
[0]);
1006 case GL_TEXTURE_BORDER_COLOR
:
1007 res
= set_sampler_border_colori(ctx
, sampObj
, params
);
1010 res
= INVALID_PNAME
;
1018 /* state change - we do nothing special at this time */
1021 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterIiv(pname=%s)\n",
1022 _mesa_lookup_enum_by_nr(pname
));
1025 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterIiv(param=%d)\n",
1029 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterIiv(param=%d)\n",
1039 _mesa_SamplerParameterIuiv(GLuint sampler
, GLenum pname
, const GLuint
*params
)
1041 struct gl_sampler_object
*sampObj
;
1043 GET_CURRENT_CONTEXT(ctx
);
1045 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1047 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterIuiv(sampler %u)",
1053 case GL_TEXTURE_WRAP_S
:
1054 res
= set_sampler_wrap_s(ctx
, sampObj
, params
[0]);
1056 case GL_TEXTURE_WRAP_T
:
1057 res
= set_sampler_wrap_t(ctx
, sampObj
, params
[0]);
1059 case GL_TEXTURE_WRAP_R
:
1060 res
= set_sampler_wrap_r(ctx
, sampObj
, params
[0]);
1062 case GL_TEXTURE_MIN_FILTER
:
1063 res
= set_sampler_min_filter(ctx
, sampObj
, params
[0]);
1065 case GL_TEXTURE_MAG_FILTER
:
1066 res
= set_sampler_mag_filter(ctx
, sampObj
, params
[0]);
1068 case GL_TEXTURE_MIN_LOD
:
1069 res
= set_sampler_min_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
1071 case GL_TEXTURE_MAX_LOD
:
1072 res
= set_sampler_max_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
1074 case GL_TEXTURE_LOD_BIAS
:
1075 res
= set_sampler_lod_bias(ctx
, sampObj
, (GLfloat
) params
[0]);
1077 case GL_TEXTURE_COMPARE_MODE
:
1078 res
= set_sampler_compare_mode(ctx
, sampObj
, params
[0]);
1080 case GL_TEXTURE_COMPARE_FUNC
:
1081 res
= set_sampler_compare_func(ctx
, sampObj
, params
[0]);
1083 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1084 res
= set_sampler_max_anisotropy(ctx
, sampObj
, (GLfloat
) params
[0]);
1086 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1087 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, params
[0]);
1089 case GL_TEXTURE_SRGB_DECODE_EXT
:
1090 res
= set_sampler_srgb_decode(ctx
, sampObj
, (GLenum
) params
[0]);
1092 case GL_TEXTURE_BORDER_COLOR
:
1093 res
= set_sampler_border_colorui(ctx
, sampObj
, params
);
1096 res
= INVALID_PNAME
;
1104 /* state change - we do nothing special at this time */
1107 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterIuiv(pname=%s)\n",
1108 _mesa_lookup_enum_by_nr(pname
));
1111 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterIuiv(param=%u)\n",
1115 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterIuiv(param=%u)\n",
1125 _mesa_GetSamplerParameteriv(GLuint sampler
, GLenum pname
, GLint
*params
)
1127 struct gl_sampler_object
*sampObj
;
1128 GET_CURRENT_CONTEXT(ctx
);
1130 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1132 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetSamplerParameteriv(sampler %u)",
1138 case GL_TEXTURE_WRAP_S
:
1139 *params
= sampObj
->WrapS
;
1141 case GL_TEXTURE_WRAP_T
:
1142 *params
= sampObj
->WrapT
;
1144 case GL_TEXTURE_WRAP_R
:
1145 *params
= sampObj
->WrapR
;
1147 case GL_TEXTURE_MIN_FILTER
:
1148 *params
= sampObj
->MinFilter
;
1150 case GL_TEXTURE_MAG_FILTER
:
1151 *params
= sampObj
->MagFilter
;
1153 case GL_TEXTURE_MIN_LOD
:
1154 *params
= (GLint
) sampObj
->MinLod
;
1156 case GL_TEXTURE_MAX_LOD
:
1157 *params
= (GLint
) sampObj
->MaxLod
;
1159 case GL_TEXTURE_LOD_BIAS
:
1160 *params
= (GLint
) sampObj
->LodBias
;
1162 case GL_TEXTURE_COMPARE_MODE
:
1163 if (!ctx
->Extensions
.ARB_shadow
)
1165 *params
= sampObj
->CompareMode
;
1167 case GL_TEXTURE_COMPARE_FUNC
:
1168 if (!ctx
->Extensions
.ARB_shadow
)
1170 *params
= sampObj
->CompareFunc
;
1172 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1173 *params
= (GLint
) sampObj
->MaxAnisotropy
;
1175 case GL_TEXTURE_BORDER_COLOR
:
1176 params
[0] = FLOAT_TO_INT(sampObj
->BorderColor
.f
[0]);
1177 params
[1] = FLOAT_TO_INT(sampObj
->BorderColor
.f
[1]);
1178 params
[2] = FLOAT_TO_INT(sampObj
->BorderColor
.f
[2]);
1179 params
[3] = FLOAT_TO_INT(sampObj
->BorderColor
.f
[3]);
1181 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1182 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1184 *params
= sampObj
->CubeMapSeamless
;
1186 case GL_TEXTURE_SRGB_DECODE_EXT
:
1187 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1189 *params
= (GLenum
) sampObj
->sRGBDecode
;
1197 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSamplerParameteriv(pname=%s)",
1198 _mesa_lookup_enum_by_nr(pname
));
1203 _mesa_GetSamplerParameterfv(GLuint sampler
, GLenum pname
, GLfloat
*params
)
1205 struct gl_sampler_object
*sampObj
;
1206 GET_CURRENT_CONTEXT(ctx
);
1208 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1210 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetSamplerParameterfv(sampler %u)",
1216 case GL_TEXTURE_WRAP_S
:
1217 *params
= (GLfloat
) sampObj
->WrapS
;
1219 case GL_TEXTURE_WRAP_T
:
1220 *params
= (GLfloat
) sampObj
->WrapT
;
1222 case GL_TEXTURE_WRAP_R
:
1223 *params
= (GLfloat
) sampObj
->WrapR
;
1225 case GL_TEXTURE_MIN_FILTER
:
1226 *params
= (GLfloat
) sampObj
->MinFilter
;
1228 case GL_TEXTURE_MAG_FILTER
:
1229 *params
= (GLfloat
) sampObj
->MagFilter
;
1231 case GL_TEXTURE_MIN_LOD
:
1232 *params
= sampObj
->MinLod
;
1234 case GL_TEXTURE_MAX_LOD
:
1235 *params
= sampObj
->MaxLod
;
1237 case GL_TEXTURE_LOD_BIAS
:
1238 *params
= sampObj
->LodBias
;
1240 case GL_TEXTURE_COMPARE_MODE
:
1241 if (!ctx
->Extensions
.ARB_shadow
)
1243 *params
= (GLfloat
) sampObj
->CompareMode
;
1245 case GL_TEXTURE_COMPARE_FUNC
:
1246 if (!ctx
->Extensions
.ARB_shadow
)
1248 *params
= (GLfloat
) sampObj
->CompareFunc
;
1250 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1251 *params
= sampObj
->MaxAnisotropy
;
1253 case GL_TEXTURE_BORDER_COLOR
:
1254 params
[0] = sampObj
->BorderColor
.f
[0];
1255 params
[1] = sampObj
->BorderColor
.f
[1];
1256 params
[2] = sampObj
->BorderColor
.f
[2];
1257 params
[3] = sampObj
->BorderColor
.f
[3];
1259 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1260 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1262 *params
= (GLfloat
) sampObj
->CubeMapSeamless
;
1264 case GL_TEXTURE_SRGB_DECODE_EXT
:
1265 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1267 *params
= (GLfloat
) sampObj
->sRGBDecode
;
1275 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSamplerParameterfv(pname=%s)",
1276 _mesa_lookup_enum_by_nr(pname
));
1281 _mesa_GetSamplerParameterIiv(GLuint sampler
, GLenum pname
, GLint
*params
)
1283 struct gl_sampler_object
*sampObj
;
1284 GET_CURRENT_CONTEXT(ctx
);
1286 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1288 _mesa_error(ctx
, GL_INVALID_VALUE
,
1289 "glGetSamplerParameterIiv(sampler %u)",
1295 case GL_TEXTURE_WRAP_S
:
1296 *params
= sampObj
->WrapS
;
1298 case GL_TEXTURE_WRAP_T
:
1299 *params
= sampObj
->WrapT
;
1301 case GL_TEXTURE_WRAP_R
:
1302 *params
= sampObj
->WrapR
;
1304 case GL_TEXTURE_MIN_FILTER
:
1305 *params
= sampObj
->MinFilter
;
1307 case GL_TEXTURE_MAG_FILTER
:
1308 *params
= sampObj
->MagFilter
;
1310 case GL_TEXTURE_MIN_LOD
:
1311 *params
= (GLint
) sampObj
->MinLod
;
1313 case GL_TEXTURE_MAX_LOD
:
1314 *params
= (GLint
) sampObj
->MaxLod
;
1316 case GL_TEXTURE_LOD_BIAS
:
1317 *params
= (GLint
) sampObj
->LodBias
;
1319 case GL_TEXTURE_COMPARE_MODE
:
1320 if (!ctx
->Extensions
.ARB_shadow
)
1322 *params
= sampObj
->CompareMode
;
1324 case GL_TEXTURE_COMPARE_FUNC
:
1325 if (!ctx
->Extensions
.ARB_shadow
)
1327 *params
= sampObj
->CompareFunc
;
1329 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1330 *params
= (GLint
) sampObj
->MaxAnisotropy
;
1332 case GL_TEXTURE_BORDER_COLOR
:
1333 params
[0] = sampObj
->BorderColor
.i
[0];
1334 params
[1] = sampObj
->BorderColor
.i
[1];
1335 params
[2] = sampObj
->BorderColor
.i
[2];
1336 params
[3] = sampObj
->BorderColor
.i
[3];
1338 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1339 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1341 *params
= sampObj
->CubeMapSeamless
;
1343 case GL_TEXTURE_SRGB_DECODE_EXT
:
1344 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1346 *params
= (GLenum
) sampObj
->sRGBDecode
;
1354 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSamplerParameterIiv(pname=%s)",
1355 _mesa_lookup_enum_by_nr(pname
));
1360 _mesa_GetSamplerParameterIuiv(GLuint sampler
, GLenum pname
, GLuint
*params
)
1362 struct gl_sampler_object
*sampObj
;
1363 GET_CURRENT_CONTEXT(ctx
);
1365 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1367 _mesa_error(ctx
, GL_INVALID_VALUE
,
1368 "glGetSamplerParameterIuiv(sampler %u)",
1374 case GL_TEXTURE_WRAP_S
:
1375 *params
= sampObj
->WrapS
;
1377 case GL_TEXTURE_WRAP_T
:
1378 *params
= sampObj
->WrapT
;
1380 case GL_TEXTURE_WRAP_R
:
1381 *params
= sampObj
->WrapR
;
1383 case GL_TEXTURE_MIN_FILTER
:
1384 *params
= sampObj
->MinFilter
;
1386 case GL_TEXTURE_MAG_FILTER
:
1387 *params
= sampObj
->MagFilter
;
1389 case GL_TEXTURE_MIN_LOD
:
1390 *params
= (GLuint
) sampObj
->MinLod
;
1392 case GL_TEXTURE_MAX_LOD
:
1393 *params
= (GLuint
) sampObj
->MaxLod
;
1395 case GL_TEXTURE_LOD_BIAS
:
1396 *params
= (GLuint
) sampObj
->LodBias
;
1398 case GL_TEXTURE_COMPARE_MODE
:
1399 if (!ctx
->Extensions
.ARB_shadow
)
1401 *params
= sampObj
->CompareMode
;
1403 case GL_TEXTURE_COMPARE_FUNC
:
1404 if (!ctx
->Extensions
.ARB_shadow
)
1406 *params
= sampObj
->CompareFunc
;
1408 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1409 *params
= (GLuint
) sampObj
->MaxAnisotropy
;
1411 case GL_TEXTURE_BORDER_COLOR
:
1412 params
[0] = sampObj
->BorderColor
.ui
[0];
1413 params
[1] = sampObj
->BorderColor
.ui
[1];
1414 params
[2] = sampObj
->BorderColor
.ui
[2];
1415 params
[3] = sampObj
->BorderColor
.ui
[3];
1417 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1418 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1420 *params
= sampObj
->CubeMapSeamless
;
1422 case GL_TEXTURE_SRGB_DECODE_EXT
:
1423 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1425 *params
= (GLenum
) sampObj
->sRGBDecode
;
1433 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSamplerParameterIuiv(pname=%s)",
1434 _mesa_lookup_enum_by_nr(pname
));
1439 _mesa_init_sampler_object_functions(struct dd_function_table
*driver
)
1441 driver
->NewSamplerObject
= _mesa_new_sampler_object
;
1442 driver
->DeleteSamplerObject
= _mesa_delete_sampler_object
;
1447 _mesa_init_sampler_object_dispatch(const struct gl_context
*ctx
,
1448 struct _glapi_table
*disp
)
1450 SET_GenSamplers(disp
, _mesa_GenSamplers
);
1451 SET_DeleteSamplers(disp
, _mesa_DeleteSamplers
);
1452 SET_IsSampler(disp
, _mesa_IsSampler
);
1453 SET_BindSampler(disp
, _mesa_BindSampler
);
1454 SET_SamplerParameteri(disp
, _mesa_SamplerParameteri
);
1455 SET_SamplerParameterf(disp
, _mesa_SamplerParameterf
);
1456 SET_SamplerParameteriv(disp
, _mesa_SamplerParameteriv
);
1457 SET_SamplerParameterfv(disp
, _mesa_SamplerParameterfv
);
1458 SET_GetSamplerParameteriv(disp
, _mesa_GetSamplerParameteriv
);
1459 SET_GetSamplerParameterfv(disp
, _mesa_GetSamplerParameterfv
);
1461 if (_mesa_is_desktop_gl(ctx
)) {
1462 SET_SamplerParameterIiv(disp
, _mesa_SamplerParameterIiv
);
1463 SET_SamplerParameterIuiv(disp
, _mesa_SamplerParameterIuiv
);
1464 SET_GetSamplerParameterIiv(disp
, _mesa_GetSamplerParameterIiv
);
1465 SET_GetSamplerParameterIuiv(disp
, _mesa_GetSamplerParameterIuiv
);