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
)
66 /* Unreference the old sampler */
67 GLboolean deleteFlag
= GL_FALSE
;
68 struct gl_sampler_object
*oldSamp
= *ptr
;
70 /*_glthread_LOCK_MUTEX(oldSamp->Mutex);*/
71 ASSERT(oldSamp
->RefCount
> 0);
74 printf("SamplerObj %p %d DECR to %d\n",
75 (void *) oldSamp
, oldSamp
->Name
, oldSamp
->RefCount
);
77 deleteFlag
= (oldSamp
->RefCount
== 0);
78 /*_glthread_UNLOCK_MUTEX(oldSamp->Mutex);*/
81 ASSERT(ctx
->Driver
.DeleteSamplerObject
);
82 ctx
->Driver
.DeleteSamplerObject(ctx
, oldSamp
);
90 /* reference new sampler */
91 /*_glthread_LOCK_MUTEX(samp->Mutex);*/
92 if (samp
->RefCount
== 0) {
93 /* this sampler's being deleted (look just above) */
94 /* Not sure this can every really happen. Warn if it does. */
95 _mesa_problem(NULL
, "referencing deleted sampler object");
101 printf("SamplerObj %p %d INCR to %d\n",
102 (void *) samp
, samp
->Name
, samp
->RefCount
);
106 /*_glthread_UNLOCK_MUTEX(samp->Mutex);*/
112 * Initialize the fields of the given sampler object.
115 _mesa_init_sampler_object(struct gl_sampler_object
*sampObj
, GLuint name
)
117 sampObj
->Name
= name
;
118 sampObj
->RefCount
= 1;
119 sampObj
->WrapS
= GL_REPEAT
;
120 sampObj
->WrapT
= GL_REPEAT
;
121 sampObj
->WrapR
= GL_REPEAT
;
122 sampObj
->MinFilter
= GL_NEAREST_MIPMAP_LINEAR
;
123 sampObj
->MagFilter
= GL_LINEAR
;
124 sampObj
->BorderColor
.f
[0] = 0.0;
125 sampObj
->BorderColor
.f
[1] = 0.0;
126 sampObj
->BorderColor
.f
[2] = 0.0;
127 sampObj
->BorderColor
.f
[3] = 0.0;
128 sampObj
->MinLod
= -1000.0F
;
129 sampObj
->MaxLod
= 1000.0F
;
130 sampObj
->LodBias
= 0.0F
;
131 sampObj
->MaxAnisotropy
= 1.0F
;
132 sampObj
->CompareMode
= GL_NONE
;
133 sampObj
->CompareFunc
= GL_LEQUAL
;
134 sampObj
->CompareFailValue
= 0.0;
135 sampObj
->sRGBDecode
= GL_DECODE_EXT
;
136 sampObj
->CubeMapSeamless
= GL_FALSE
;
137 sampObj
->DepthMode
= 0;
142 * Fallback for ctx->Driver.NewSamplerObject();
144 struct gl_sampler_object
*
145 _mesa_new_sampler_object(struct gl_context
*ctx
, GLuint name
)
147 struct gl_sampler_object
*sampObj
= CALLOC_STRUCT(gl_sampler_object
);
149 _mesa_init_sampler_object(sampObj
, name
);
156 * Fallback for ctx->Driver.DeleteSamplerObject();
159 _mesa_delete_sampler_object(struct gl_context
*ctx
,
160 struct gl_sampler_object
*sampObj
)
166 static void GLAPIENTRY
167 _mesa_GenSamplers(GLsizei count
, GLuint
*samplers
)
169 GET_CURRENT_CONTEXT(ctx
);
173 ASSERT_OUTSIDE_BEGIN_END(ctx
);
175 if (MESA_VERBOSE
& VERBOSE_API
)
176 _mesa_debug(ctx
, "glGenSamplers(%d)\n", count
);
179 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenSamplers");
186 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->SamplerObjects
, count
);
188 /* Insert the ID and pointer to new sampler object into hash table */
189 for (i
= 0; i
< count
; i
++) {
190 struct gl_sampler_object
*sampObj
=
191 ctx
->Driver
.NewSamplerObject(ctx
, first
+ i
);
192 _mesa_HashInsert(ctx
->Shared
->SamplerObjects
, first
+ i
, sampObj
);
193 samplers
[i
] = first
+ i
;
198 static void GLAPIENTRY
199 _mesa_DeleteSamplers(GLsizei count
, const GLuint
*samplers
)
201 GET_CURRENT_CONTEXT(ctx
);
204 ASSERT_OUTSIDE_BEGIN_END(ctx
);
205 FLUSH_VERTICES(ctx
, 0);
208 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteSamplers(count)");
212 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
214 for (i
= 0; i
< count
; i
++) {
216 struct gl_sampler_object
*sampObj
=
217 _mesa_lookup_samplerobj(ctx
, samplers
[i
]);
219 /* The ID is immediately freed for re-use */
220 _mesa_HashRemove(ctx
->Shared
->SamplerObjects
, samplers
[i
]);
221 /* But the object exists until its reference count goes to zero */
222 _mesa_reference_sampler_object(ctx
, &sampObj
, NULL
);
227 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
231 static GLboolean GLAPIENTRY
232 _mesa_IsSampler(GLuint sampler
)
234 struct gl_sampler_object
*sampObj
;
235 GET_CURRENT_CONTEXT(ctx
);
237 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
242 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
244 return sampObj
!= NULL
;
248 static void GLAPIENTRY
249 _mesa_BindSampler(GLuint unit
, GLuint sampler
)
251 struct gl_sampler_object
*sampObj
;
252 GET_CURRENT_CONTEXT(ctx
);
254 if (unit
>= ctx
->Const
.MaxTextureImageUnits
) {
255 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindSampler(unit %u)", unit
);
260 /* Use the default sampler object, the one contained in the texture
266 /* user-defined sampler object */
267 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
269 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindSampler(sampler)");
274 if (ctx
->Texture
.Unit
[unit
].Sampler
!= sampObj
) {
275 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
278 /* bind new sampler */
279 _mesa_reference_sampler_object(ctx
, &ctx
->Texture
.Unit
[unit
].Sampler
,
285 * Check if a coordinate wrap mode is legal.
286 * \return GL_TRUE if legal, GL_FALSE otherwise
289 validate_texture_wrap_mode(struct gl_context
*ctx
, GLenum wrap
)
291 const struct gl_extensions
* const e
= &ctx
->Extensions
;
295 case GL_CLAMP_TO_EDGE
:
298 case GL_CLAMP_TO_BORDER
:
299 return e
->ARB_texture_border_clamp
;
300 case GL_MIRRORED_REPEAT
:
301 return e
->ARB_texture_mirrored_repeat
;
302 case GL_MIRROR_CLAMP_EXT
:
303 return e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
;
304 case GL_MIRROR_CLAMP_TO_EDGE_EXT
:
305 return e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
;
306 case GL_MIRROR_CLAMP_TO_BORDER_EXT
:
307 return e
->EXT_texture_mirror_clamp
;
315 * This is called just prior to changing any sampler object state.
318 flush(struct gl_context
*ctx
)
320 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
324 #define INVALID_PARAM 0x100
325 #define INVALID_PNAME 0x101
326 #define INVALID_VALUE 0x102
329 set_sampler_wrap_s(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
332 if (samp
->WrapS
== param
)
334 if (validate_texture_wrap_mode(ctx
, param
)) {
339 return INVALID_PARAM
;
344 set_sampler_wrap_t(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
347 if (samp
->WrapT
== param
)
349 if (validate_texture_wrap_mode(ctx
, param
)) {
354 return INVALID_PARAM
;
359 set_sampler_wrap_r(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
362 if (samp
->WrapR
== param
)
364 if (validate_texture_wrap_mode(ctx
, param
)) {
369 return INVALID_PARAM
;
374 set_sampler_min_filter(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
377 if (samp
->MinFilter
== param
)
383 case GL_NEAREST_MIPMAP_NEAREST
:
384 case GL_LINEAR_MIPMAP_NEAREST
:
385 case GL_NEAREST_MIPMAP_LINEAR
:
386 case GL_LINEAR_MIPMAP_LINEAR
:
388 samp
->MinFilter
= param
;
391 return INVALID_PARAM
;
397 set_sampler_mag_filter(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
400 if (samp
->MagFilter
== param
)
407 samp
->MagFilter
= param
;
410 return INVALID_PARAM
;
416 set_sampler_lod_bias(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
419 if (samp
->LodBias
== param
)
423 samp
->LodBias
= param
;
429 set_sampler_border_colorf(struct gl_context
*ctx
,
430 struct gl_sampler_object
*samp
,
431 const GLfloat params
[4])
434 samp
->BorderColor
.f
[RCOMP
] = params
[0];
435 samp
->BorderColor
.f
[GCOMP
] = params
[1];
436 samp
->BorderColor
.f
[BCOMP
] = params
[2];
437 samp
->BorderColor
.f
[ACOMP
] = params
[3];
443 set_sampler_border_colori(struct gl_context
*ctx
,
444 struct gl_sampler_object
*samp
,
445 const GLint params
[4])
448 samp
->BorderColor
.i
[RCOMP
] = params
[0];
449 samp
->BorderColor
.i
[GCOMP
] = params
[1];
450 samp
->BorderColor
.i
[BCOMP
] = params
[2];
451 samp
->BorderColor
.i
[ACOMP
] = params
[3];
457 set_sampler_border_colorui(struct gl_context
*ctx
,
458 struct gl_sampler_object
*samp
,
459 const GLuint params
[4])
462 samp
->BorderColor
.ui
[RCOMP
] = params
[0];
463 samp
->BorderColor
.ui
[GCOMP
] = params
[1];
464 samp
->BorderColor
.ui
[BCOMP
] = params
[2];
465 samp
->BorderColor
.ui
[ACOMP
] = params
[3];
471 set_sampler_min_lod(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
474 if (samp
->MinLod
== param
)
478 samp
->MinLod
= param
;
484 set_sampler_max_lod(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
487 if (samp
->MaxLod
== param
)
491 samp
->MaxLod
= param
;
497 set_sampler_compare_mode(struct gl_context
*ctx
,
498 struct gl_sampler_object
*samp
, GLint param
)
500 if (!ctx
->Extensions
.ARB_shadow
)
501 return INVALID_PNAME
;
503 if (samp
->CompareMode
== param
)
506 if (param
== GL_NONE
||
507 param
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
509 samp
->CompareMode
= param
;
513 return INVALID_PARAM
;
518 set_sampler_compare_func(struct gl_context
*ctx
,
519 struct gl_sampler_object
*samp
, GLint param
)
521 if (!ctx
->Extensions
.ARB_shadow
)
522 return INVALID_PNAME
;
524 if (samp
->CompareFunc
== param
)
531 samp
->CompareFunc
= param
;
539 if (ctx
->Extensions
.EXT_shadow_funcs
) {
541 samp
->CompareFunc
= param
;
546 return INVALID_PARAM
;
552 set_sampler_max_anisotropy(struct gl_context
*ctx
,
553 struct gl_sampler_object
*samp
, GLfloat param
)
555 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
556 return INVALID_PNAME
;
558 if (samp
->MaxAnisotropy
== param
)
562 return INVALID_VALUE
;
565 /* clamp to max, that's what NVIDIA does */
566 samp
->MaxAnisotropy
= MIN2(param
, ctx
->Const
.MaxTextureMaxAnisotropy
);
572 set_sampler_cube_map_seamless(struct gl_context
*ctx
,
573 struct gl_sampler_object
*samp
, GLboolean param
)
575 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
576 return INVALID_PNAME
;
578 if (samp
->CubeMapSeamless
== param
)
581 if (param
!= GL_TRUE
&& param
!= GL_FALSE
)
582 return INVALID_VALUE
;
585 samp
->CubeMapSeamless
= param
;
590 static void GLAPIENTRY
591 _mesa_SamplerParameteri(GLuint sampler
, GLenum pname
, GLint param
)
593 struct gl_sampler_object
*sampObj
;
595 GET_CURRENT_CONTEXT(ctx
);
597 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
599 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameteri(sampler %u)",
605 case GL_TEXTURE_WRAP_S
:
606 res
= set_sampler_wrap_s(ctx
, sampObj
, param
);
608 case GL_TEXTURE_WRAP_T
:
609 res
= set_sampler_wrap_t(ctx
, sampObj
, param
);
611 case GL_TEXTURE_WRAP_R
:
612 res
= set_sampler_wrap_r(ctx
, sampObj
, param
);
614 case GL_TEXTURE_MIN_FILTER
:
615 res
= set_sampler_min_filter(ctx
, sampObj
, param
);
617 case GL_TEXTURE_MAG_FILTER
:
618 res
= set_sampler_mag_filter(ctx
, sampObj
, param
);
620 case GL_TEXTURE_MIN_LOD
:
621 res
= set_sampler_min_lod(ctx
, sampObj
, (GLfloat
) param
);
623 case GL_TEXTURE_MAX_LOD
:
624 res
= set_sampler_max_lod(ctx
, sampObj
, (GLfloat
) param
);
626 case GL_TEXTURE_LOD_BIAS
:
627 res
= set_sampler_lod_bias(ctx
, sampObj
, (GLfloat
) param
);
629 case GL_TEXTURE_COMPARE_MODE
:
630 res
= set_sampler_compare_mode(ctx
, sampObj
, param
);
632 case GL_TEXTURE_COMPARE_FUNC
:
633 res
= set_sampler_compare_func(ctx
, sampObj
, param
);
635 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
636 res
= set_sampler_max_anisotropy(ctx
, sampObj
, (GLfloat
) param
);
638 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
639 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, param
);
641 case GL_TEXTURE_BORDER_COLOR
:
652 /* state change - we do nothing special at this time */
655 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameteri(pname=%s)\n",
656 _mesa_lookup_enum_by_nr(pname
));
659 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameteri(param=%d)\n",
663 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameteri(param=%d)\n",
672 static void GLAPIENTRY
673 _mesa_SamplerParameterf(GLuint sampler
, GLenum pname
, GLfloat param
)
675 struct gl_sampler_object
*sampObj
;
677 GET_CURRENT_CONTEXT(ctx
);
679 ASSERT_OUTSIDE_BEGIN_END(ctx
);
681 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
683 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterf(sampler %u)",
689 case GL_TEXTURE_WRAP_S
:
690 res
= set_sampler_wrap_s(ctx
, sampObj
, (GLint
) param
);
692 case GL_TEXTURE_WRAP_T
:
693 res
= set_sampler_wrap_t(ctx
, sampObj
, (GLint
) param
);
695 case GL_TEXTURE_WRAP_R
:
696 res
= set_sampler_wrap_r(ctx
, sampObj
, (GLint
) param
);
698 case GL_TEXTURE_MIN_FILTER
:
699 res
= set_sampler_min_filter(ctx
, sampObj
, (GLint
) param
);
701 case GL_TEXTURE_MAG_FILTER
:
702 res
= set_sampler_mag_filter(ctx
, sampObj
, (GLint
) param
);
704 case GL_TEXTURE_MIN_LOD
:
705 res
= set_sampler_min_lod(ctx
, sampObj
, param
);
707 case GL_TEXTURE_MAX_LOD
:
708 res
= set_sampler_max_lod(ctx
, sampObj
, param
);
710 case GL_TEXTURE_LOD_BIAS
:
711 res
= set_sampler_lod_bias(ctx
, sampObj
, param
);
713 case GL_TEXTURE_COMPARE_MODE
:
714 res
= set_sampler_compare_mode(ctx
, sampObj
, (GLint
) param
);
716 case GL_TEXTURE_COMPARE_FUNC
:
717 res
= set_sampler_compare_func(ctx
, sampObj
, (GLint
) param
);
719 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
720 res
= set_sampler_max_anisotropy(ctx
, sampObj
, param
);
722 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
723 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, (GLboolean
) param
);
725 case GL_TEXTURE_BORDER_COLOR
:
736 /* state change - we do nothing special at this time */
739 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterf(pname=%s)\n",
740 _mesa_lookup_enum_by_nr(pname
));
743 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterf(param=%f)\n",
747 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterf(param=%f)\n",
755 static void GLAPIENTRY
756 _mesa_SamplerParameteriv(GLuint sampler
, GLenum pname
, const GLint
*params
)
758 struct gl_sampler_object
*sampObj
;
760 GET_CURRENT_CONTEXT(ctx
);
762 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
764 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameteriv(sampler %u)",
770 case GL_TEXTURE_WRAP_S
:
771 res
= set_sampler_wrap_s(ctx
, sampObj
, params
[0]);
773 case GL_TEXTURE_WRAP_T
:
774 res
= set_sampler_wrap_t(ctx
, sampObj
, params
[0]);
776 case GL_TEXTURE_WRAP_R
:
777 res
= set_sampler_wrap_r(ctx
, sampObj
, params
[0]);
779 case GL_TEXTURE_MIN_FILTER
:
780 res
= set_sampler_min_filter(ctx
, sampObj
, params
[0]);
782 case GL_TEXTURE_MAG_FILTER
:
783 res
= set_sampler_mag_filter(ctx
, sampObj
, params
[0]);
785 case GL_TEXTURE_MIN_LOD
:
786 res
= set_sampler_min_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
788 case GL_TEXTURE_MAX_LOD
:
789 res
= set_sampler_max_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
791 case GL_TEXTURE_LOD_BIAS
:
792 res
= set_sampler_lod_bias(ctx
, sampObj
, (GLfloat
) params
[0]);
794 case GL_TEXTURE_COMPARE_MODE
:
795 res
= set_sampler_compare_mode(ctx
, sampObj
, params
[0]);
797 case GL_TEXTURE_COMPARE_FUNC
:
798 res
= set_sampler_compare_func(ctx
, sampObj
, params
[0]);
800 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
801 res
= set_sampler_max_anisotropy(ctx
, sampObj
, (GLfloat
) params
[0]);
803 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
804 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, params
[0]);
806 case GL_TEXTURE_BORDER_COLOR
:
809 c
[0] = INT_TO_FLOAT(params
[0]);
810 c
[1] = INT_TO_FLOAT(params
[1]);
811 c
[2] = INT_TO_FLOAT(params
[2]);
812 c
[3] = INT_TO_FLOAT(params
[3]);
813 res
= set_sampler_border_colorf(ctx
, sampObj
, c
);
825 /* state change - we do nothing special at this time */
828 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameteriv(pname=%s)\n",
829 _mesa_lookup_enum_by_nr(pname
));
832 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameteriv(param=%d)\n",
836 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameteriv(param=%d)\n",
844 static void GLAPIENTRY
845 _mesa_SamplerParameterfv(GLuint sampler
, GLenum pname
, const GLfloat
*params
)
847 struct gl_sampler_object
*sampObj
;
849 GET_CURRENT_CONTEXT(ctx
);
851 ASSERT_OUTSIDE_BEGIN_END(ctx
);
853 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
855 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterfv(sampler %u)",
861 case GL_TEXTURE_WRAP_S
:
862 res
= set_sampler_wrap_s(ctx
, sampObj
, (GLint
) params
[0]);
864 case GL_TEXTURE_WRAP_T
:
865 res
= set_sampler_wrap_t(ctx
, sampObj
, (GLint
) params
[0]);
867 case GL_TEXTURE_WRAP_R
:
868 res
= set_sampler_wrap_r(ctx
, sampObj
, (GLint
) params
[0]);
870 case GL_TEXTURE_MIN_FILTER
:
871 res
= set_sampler_min_filter(ctx
, sampObj
, (GLint
) params
[0]);
873 case GL_TEXTURE_MAG_FILTER
:
874 res
= set_sampler_mag_filter(ctx
, sampObj
, (GLint
) params
[0]);
876 case GL_TEXTURE_MIN_LOD
:
877 res
= set_sampler_min_lod(ctx
, sampObj
, params
[0]);
879 case GL_TEXTURE_MAX_LOD
:
880 res
= set_sampler_max_lod(ctx
, sampObj
, params
[0]);
882 case GL_TEXTURE_LOD_BIAS
:
883 res
= set_sampler_lod_bias(ctx
, sampObj
, params
[0]);
885 case GL_TEXTURE_COMPARE_MODE
:
886 res
= set_sampler_compare_mode(ctx
, sampObj
, (GLint
) params
[0]);
888 case GL_TEXTURE_COMPARE_FUNC
:
889 res
= set_sampler_compare_func(ctx
, sampObj
, (GLint
) params
[0]);
891 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
892 res
= set_sampler_max_anisotropy(ctx
, sampObj
, params
[0]);
894 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
895 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, (GLboolean
) params
[0]);
897 case GL_TEXTURE_BORDER_COLOR
:
898 res
= set_sampler_border_colorf(ctx
, sampObj
, params
);
909 /* state change - we do nothing special at this time */
912 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterfv(pname=%s)\n",
913 _mesa_lookup_enum_by_nr(pname
));
916 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterfv(param=%f)\n",
920 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterfv(param=%f)\n",
928 static void GLAPIENTRY
929 _mesa_SamplerParameterIiv(GLuint sampler
, GLenum pname
, const GLint
*params
)
931 struct gl_sampler_object
*sampObj
;
933 GET_CURRENT_CONTEXT(ctx
);
935 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
937 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterIiv(sampler %u)",
943 case GL_TEXTURE_WRAP_S
:
944 res
= set_sampler_wrap_s(ctx
, sampObj
, params
[0]);
946 case GL_TEXTURE_WRAP_T
:
947 res
= set_sampler_wrap_t(ctx
, sampObj
, params
[0]);
949 case GL_TEXTURE_WRAP_R
:
950 res
= set_sampler_wrap_r(ctx
, sampObj
, params
[0]);
952 case GL_TEXTURE_MIN_FILTER
:
953 res
= set_sampler_min_filter(ctx
, sampObj
, params
[0]);
955 case GL_TEXTURE_MAG_FILTER
:
956 res
= set_sampler_mag_filter(ctx
, sampObj
, params
[0]);
958 case GL_TEXTURE_MIN_LOD
:
959 res
= set_sampler_min_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
961 case GL_TEXTURE_MAX_LOD
:
962 res
= set_sampler_max_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
964 case GL_TEXTURE_LOD_BIAS
:
965 res
= set_sampler_lod_bias(ctx
, sampObj
, (GLfloat
) params
[0]);
967 case GL_TEXTURE_COMPARE_MODE
:
968 res
= set_sampler_compare_mode(ctx
, sampObj
, params
[0]);
970 case GL_TEXTURE_COMPARE_FUNC
:
971 res
= set_sampler_compare_func(ctx
, sampObj
, params
[0]);
973 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
974 res
= set_sampler_max_anisotropy(ctx
, sampObj
, (GLfloat
) params
[0]);
976 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
977 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, params
[0]);
979 case GL_TEXTURE_BORDER_COLOR
:
980 res
= set_sampler_border_colori(ctx
, sampObj
, params
);
991 /* state change - we do nothing special at this time */
994 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterIiv(pname=%s)\n",
995 _mesa_lookup_enum_by_nr(pname
));
998 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterIiv(param=%d)\n",
1002 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterIiv(param=%d)\n",
1011 static void GLAPIENTRY
1012 _mesa_SamplerParameterIuiv(GLuint sampler
, GLenum pname
, const GLuint
*params
)
1014 struct gl_sampler_object
*sampObj
;
1016 GET_CURRENT_CONTEXT(ctx
);
1018 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1020 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterIuiv(sampler %u)",
1026 case GL_TEXTURE_WRAP_S
:
1027 res
= set_sampler_wrap_s(ctx
, sampObj
, params
[0]);
1029 case GL_TEXTURE_WRAP_T
:
1030 res
= set_sampler_wrap_t(ctx
, sampObj
, params
[0]);
1032 case GL_TEXTURE_WRAP_R
:
1033 res
= set_sampler_wrap_r(ctx
, sampObj
, params
[0]);
1035 case GL_TEXTURE_MIN_FILTER
:
1036 res
= set_sampler_min_filter(ctx
, sampObj
, params
[0]);
1038 case GL_TEXTURE_MAG_FILTER
:
1039 res
= set_sampler_mag_filter(ctx
, sampObj
, params
[0]);
1041 case GL_TEXTURE_MIN_LOD
:
1042 res
= set_sampler_min_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
1044 case GL_TEXTURE_MAX_LOD
:
1045 res
= set_sampler_max_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
1047 case GL_TEXTURE_LOD_BIAS
:
1048 res
= set_sampler_lod_bias(ctx
, sampObj
, (GLfloat
) params
[0]);
1050 case GL_TEXTURE_COMPARE_MODE
:
1051 res
= set_sampler_compare_mode(ctx
, sampObj
, params
[0]);
1053 case GL_TEXTURE_COMPARE_FUNC
:
1054 res
= set_sampler_compare_func(ctx
, sampObj
, params
[0]);
1056 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1057 res
= set_sampler_max_anisotropy(ctx
, sampObj
, (GLfloat
) params
[0]);
1059 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1060 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, params
[0]);
1062 case GL_TEXTURE_BORDER_COLOR
:
1063 res
= set_sampler_border_colorui(ctx
, sampObj
, params
);
1066 res
= INVALID_PNAME
;
1074 /* state change - we do nothing special at this time */
1077 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterIuiv(pname=%s)\n",
1078 _mesa_lookup_enum_by_nr(pname
));
1081 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterIuiv(param=%u)\n",
1085 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterIuiv(param=%u)\n",
1094 static void GLAPIENTRY
1095 _mesa_GetSamplerParameteriv(GLuint sampler
, GLenum pname
, GLint
*params
)
1097 struct gl_sampler_object
*sampObj
;
1098 GET_CURRENT_CONTEXT(ctx
);
1100 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1102 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetSamplerParameteriv(sampler %u)",
1108 case GL_TEXTURE_WRAP_S
:
1109 *params
= sampObj
->WrapS
;
1111 case GL_TEXTURE_WRAP_T
:
1112 *params
= sampObj
->WrapT
;
1114 case GL_TEXTURE_WRAP_R
:
1115 *params
= sampObj
->WrapR
;
1117 case GL_TEXTURE_MIN_FILTER
:
1118 *params
= sampObj
->MinFilter
;
1120 case GL_TEXTURE_MAG_FILTER
:
1121 *params
= sampObj
->MagFilter
;
1123 case GL_TEXTURE_MIN_LOD
:
1124 *params
= (GLint
) sampObj
->MinLod
;
1126 case GL_TEXTURE_MAX_LOD
:
1127 *params
= (GLint
) sampObj
->MaxLod
;
1129 case GL_TEXTURE_LOD_BIAS
:
1130 *params
= (GLint
) sampObj
->LodBias
;
1132 case GL_TEXTURE_COMPARE_MODE
:
1133 if (!ctx
->Extensions
.ARB_shadow
)
1135 *params
= sampObj
->CompareMode
;
1137 case GL_TEXTURE_COMPARE_FUNC
:
1138 if (!ctx
->Extensions
.ARB_shadow
)
1140 *params
= sampObj
->CompareFunc
;
1142 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1143 *params
= (GLint
) sampObj
->MaxAnisotropy
;
1145 case GL_TEXTURE_BORDER_COLOR
:
1146 params
[0] = FLOAT_TO_INT(sampObj
->BorderColor
.f
[0]);
1147 params
[1] = FLOAT_TO_INT(sampObj
->BorderColor
.f
[1]);
1148 params
[2] = FLOAT_TO_INT(sampObj
->BorderColor
.f
[2]);
1149 params
[3] = FLOAT_TO_INT(sampObj
->BorderColor
.f
[3]);
1151 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1152 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1154 *params
= sampObj
->CubeMapSeamless
;
1162 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSamplerParameteriv(pname=%s)",
1163 _mesa_lookup_enum_by_nr(pname
));
1167 static void GLAPIENTRY
1168 _mesa_GetSamplerParameterfv(GLuint sampler
, GLenum pname
, GLfloat
*params
)
1170 struct gl_sampler_object
*sampObj
;
1171 GET_CURRENT_CONTEXT(ctx
);
1173 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1175 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetSamplerParameterfv(sampler %u)",
1181 case GL_TEXTURE_WRAP_S
:
1182 *params
= (GLfloat
) sampObj
->WrapS
;
1184 case GL_TEXTURE_WRAP_T
:
1185 *params
= (GLfloat
) sampObj
->WrapT
;
1187 case GL_TEXTURE_WRAP_R
:
1188 *params
= (GLfloat
) sampObj
->WrapR
;
1190 case GL_TEXTURE_MIN_FILTER
:
1191 *params
= (GLfloat
) sampObj
->MinFilter
;
1193 case GL_TEXTURE_MAG_FILTER
:
1194 *params
= (GLfloat
) sampObj
->MagFilter
;
1196 case GL_TEXTURE_MIN_LOD
:
1197 *params
= sampObj
->MinLod
;
1199 case GL_TEXTURE_MAX_LOD
:
1200 *params
= sampObj
->MaxLod
;
1202 case GL_TEXTURE_LOD_BIAS
:
1203 *params
= sampObj
->LodBias
;
1205 case GL_TEXTURE_COMPARE_MODE
:
1206 if (!ctx
->Extensions
.ARB_shadow
)
1208 *params
= (GLfloat
) sampObj
->CompareMode
;
1210 case GL_TEXTURE_COMPARE_FUNC
:
1211 if (!ctx
->Extensions
.ARB_shadow
)
1213 *params
= (GLfloat
) sampObj
->CompareFunc
;
1215 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1216 *params
= sampObj
->MaxAnisotropy
;
1218 case GL_TEXTURE_BORDER_COLOR
:
1219 params
[0] = sampObj
->BorderColor
.f
[0];
1220 params
[1] = sampObj
->BorderColor
.f
[1];
1221 params
[2] = sampObj
->BorderColor
.f
[2];
1222 params
[3] = sampObj
->BorderColor
.f
[3];
1224 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1225 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1227 *params
= (GLfloat
) sampObj
->CubeMapSeamless
;
1235 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSamplerParameterfv(pname=%s)",
1236 _mesa_lookup_enum_by_nr(pname
));
1240 static void GLAPIENTRY
1241 _mesa_GetSamplerParameterIiv(GLuint sampler
, GLenum pname
, GLint
*params
)
1243 struct gl_sampler_object
*sampObj
;
1244 GET_CURRENT_CONTEXT(ctx
);
1246 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1248 _mesa_error(ctx
, GL_INVALID_VALUE
,
1249 "glGetSamplerParameterIiv(sampler %u)",
1255 case GL_TEXTURE_WRAP_S
:
1256 *params
= sampObj
->WrapS
;
1258 case GL_TEXTURE_WRAP_T
:
1259 *params
= sampObj
->WrapT
;
1261 case GL_TEXTURE_WRAP_R
:
1262 *params
= sampObj
->WrapR
;
1264 case GL_TEXTURE_MIN_FILTER
:
1265 *params
= sampObj
->MinFilter
;
1267 case GL_TEXTURE_MAG_FILTER
:
1268 *params
= sampObj
->MagFilter
;
1270 case GL_TEXTURE_MIN_LOD
:
1271 *params
= (GLint
) sampObj
->MinLod
;
1273 case GL_TEXTURE_MAX_LOD
:
1274 *params
= (GLint
) sampObj
->MaxLod
;
1276 case GL_TEXTURE_LOD_BIAS
:
1277 *params
= (GLint
) sampObj
->LodBias
;
1279 case GL_TEXTURE_COMPARE_MODE
:
1280 if (!ctx
->Extensions
.ARB_shadow
)
1282 *params
= sampObj
->CompareMode
;
1284 case GL_TEXTURE_COMPARE_FUNC
:
1285 if (!ctx
->Extensions
.ARB_shadow
)
1287 *params
= sampObj
->CompareFunc
;
1289 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1290 *params
= (GLint
) sampObj
->MaxAnisotropy
;
1292 case GL_TEXTURE_BORDER_COLOR
:
1293 params
[0] = sampObj
->BorderColor
.i
[0];
1294 params
[1] = sampObj
->BorderColor
.i
[1];
1295 params
[2] = sampObj
->BorderColor
.i
[2];
1296 params
[3] = sampObj
->BorderColor
.i
[3];
1298 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1299 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1301 *params
= sampObj
->CubeMapSeamless
;
1309 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSamplerParameterIiv(pname=%s)",
1310 _mesa_lookup_enum_by_nr(pname
));
1314 static void GLAPIENTRY
1315 _mesa_GetSamplerParameterIuiv(GLuint sampler
, GLenum pname
, GLuint
*params
)
1317 struct gl_sampler_object
*sampObj
;
1318 GET_CURRENT_CONTEXT(ctx
);
1320 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1322 _mesa_error(ctx
, GL_INVALID_VALUE
,
1323 "glGetSamplerParameterIuiv(sampler %u)",
1329 case GL_TEXTURE_WRAP_S
:
1330 *params
= sampObj
->WrapS
;
1332 case GL_TEXTURE_WRAP_T
:
1333 *params
= sampObj
->WrapT
;
1335 case GL_TEXTURE_WRAP_R
:
1336 *params
= sampObj
->WrapR
;
1338 case GL_TEXTURE_MIN_FILTER
:
1339 *params
= sampObj
->MinFilter
;
1341 case GL_TEXTURE_MAG_FILTER
:
1342 *params
= sampObj
->MagFilter
;
1344 case GL_TEXTURE_MIN_LOD
:
1345 *params
= (GLuint
) sampObj
->MinLod
;
1347 case GL_TEXTURE_MAX_LOD
:
1348 *params
= (GLuint
) sampObj
->MaxLod
;
1350 case GL_TEXTURE_LOD_BIAS
:
1351 *params
= (GLuint
) sampObj
->LodBias
;
1353 case GL_TEXTURE_COMPARE_MODE
:
1354 if (!ctx
->Extensions
.ARB_shadow
)
1356 *params
= sampObj
->CompareMode
;
1358 case GL_TEXTURE_COMPARE_FUNC
:
1359 if (!ctx
->Extensions
.ARB_shadow
)
1361 *params
= sampObj
->CompareFunc
;
1363 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1364 *params
= (GLuint
) sampObj
->MaxAnisotropy
;
1366 case GL_TEXTURE_BORDER_COLOR
:
1367 params
[0] = sampObj
->BorderColor
.ui
[0];
1368 params
[1] = sampObj
->BorderColor
.ui
[1];
1369 params
[2] = sampObj
->BorderColor
.ui
[2];
1370 params
[3] = sampObj
->BorderColor
.ui
[3];
1372 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1373 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1375 *params
= sampObj
->CubeMapSeamless
;
1383 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSamplerParameterIuiv(pname=%s)",
1384 _mesa_lookup_enum_by_nr(pname
));
1389 _mesa_init_sampler_object_functions(struct dd_function_table
*driver
)
1391 driver
->NewSamplerObject
= _mesa_new_sampler_object
;
1392 driver
->DeleteSamplerObject
= _mesa_delete_sampler_object
;
1397 _mesa_init_sampler_object_dispatch(struct _glapi_table
*disp
)
1399 SET_GenSamplers(disp
, _mesa_GenSamplers
);
1400 SET_DeleteSamplers(disp
, _mesa_DeleteSamplers
);
1401 SET_IsSampler(disp
, _mesa_IsSampler
);
1402 SET_BindSampler(disp
, _mesa_BindSampler
);
1403 SET_SamplerParameteri(disp
, _mesa_SamplerParameteri
);
1404 SET_SamplerParameterf(disp
, _mesa_SamplerParameterf
);
1405 SET_SamplerParameteriv(disp
, _mesa_SamplerParameteriv
);
1406 SET_SamplerParameterfv(disp
, _mesa_SamplerParameterfv
);
1407 SET_SamplerParameterIiv(disp
, _mesa_SamplerParameterIiv
);
1408 SET_SamplerParameterIuiv(disp
, _mesa_SamplerParameterIuiv
);
1409 SET_GetSamplerParameteriv(disp
, _mesa_GetSamplerParameteriv
);
1410 SET_GetSamplerParameterfv(disp
, _mesa_GetSamplerParameterfv
);
1411 SET_GetSamplerParameterIiv(disp
, _mesa_GetSamplerParameterIiv
);
1412 SET_GetSamplerParameterIuiv(disp
, _mesa_GetSamplerParameterIuiv
);