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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
28 * \brief Functions for the GL_ARB_sampler_objects extension.
33 #include "main/glheader.h"
34 #include "main/context.h"
35 #include "main/dispatch.h"
36 #include "main/enums.h"
37 #include "main/hash.h"
38 #include "main/macros.h"
39 #include "main/mtypes.h"
40 #include "main/samplerobj.h"
43 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 /*mtx_lock(&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 /*mtx_unlock(&oldSamp->Mutex);*/
80 ASSERT(ctx
->Driver
.DeleteSamplerObject
);
81 ctx
->Driver
.DeleteSamplerObject(ctx
, oldSamp
);
89 /* reference new sampler */
90 /*mtx_lock(&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 /*mtx_unlock(&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
)
158 free(sampObj
->Label
);
164 _mesa_GenSamplers(GLsizei count
, GLuint
*samplers
)
166 GET_CURRENT_CONTEXT(ctx
);
170 if (MESA_VERBOSE
& VERBOSE_API
)
171 _mesa_debug(ctx
, "glGenSamplers(%d)\n", count
);
174 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenSamplers");
181 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->SamplerObjects
, count
);
183 /* Insert the ID and pointer to new sampler object into hash table */
184 for (i
= 0; i
< count
; i
++) {
185 struct gl_sampler_object
*sampObj
=
186 ctx
->Driver
.NewSamplerObject(ctx
, first
+ i
);
187 _mesa_HashInsert(ctx
->Shared
->SamplerObjects
, first
+ i
, sampObj
);
188 samplers
[i
] = first
+ i
;
194 _mesa_DeleteSamplers(GLsizei count
, const GLuint
*samplers
)
196 GET_CURRENT_CONTEXT(ctx
);
199 FLUSH_VERTICES(ctx
, 0);
202 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteSamplers(count)");
206 mtx_lock(&ctx
->Shared
->Mutex
);
208 for (i
= 0; i
< count
; i
++) {
211 struct gl_sampler_object
*sampObj
=
212 _mesa_lookup_samplerobj(ctx
, samplers
[i
]);
215 /* If the sampler is currently bound, unbind it. */
216 for (j
= 0; j
< ctx
->Const
.MaxCombinedTextureImageUnits
; j
++) {
217 if (ctx
->Texture
.Unit
[j
].Sampler
== sampObj
) {
218 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
219 _mesa_reference_sampler_object(ctx
, &ctx
->Texture
.Unit
[j
].Sampler
, NULL
);
223 /* The ID is immediately freed for re-use */
224 _mesa_HashRemove(ctx
->Shared
->SamplerObjects
, samplers
[i
]);
225 /* But the object exists until its reference count goes to zero */
226 _mesa_reference_sampler_object(ctx
, &sampObj
, NULL
);
231 mtx_unlock(&ctx
->Shared
->Mutex
);
236 _mesa_IsSampler(GLuint sampler
)
238 struct gl_sampler_object
*sampObj
;
239 GET_CURRENT_CONTEXT(ctx
);
241 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
246 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
248 return sampObj
!= NULL
;
253 _mesa_BindSampler(GLuint unit
, GLuint sampler
)
255 struct gl_sampler_object
*sampObj
;
256 GET_CURRENT_CONTEXT(ctx
);
258 if (unit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
259 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindSampler(unit %u)", unit
);
264 /* Use the default sampler object, the one contained in the texture
270 /* user-defined sampler object */
271 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
273 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindSampler(sampler)");
278 if (ctx
->Texture
.Unit
[unit
].Sampler
!= sampObj
) {
279 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
282 /* bind new sampler */
283 _mesa_reference_sampler_object(ctx
, &ctx
->Texture
.Unit
[unit
].Sampler
,
289 * Check if a coordinate wrap mode is legal.
290 * \return GL_TRUE if legal, GL_FALSE otherwise
293 validate_texture_wrap_mode(struct gl_context
*ctx
, GLenum wrap
)
295 const struct gl_extensions
* const e
= &ctx
->Extensions
;
299 case GL_CLAMP_TO_EDGE
:
301 case GL_MIRRORED_REPEAT
:
303 case GL_CLAMP_TO_BORDER
:
304 return e
->ARB_texture_border_clamp
;
305 case GL_MIRROR_CLAMP_EXT
:
306 return e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
;
307 case GL_MIRROR_CLAMP_TO_EDGE_EXT
:
308 return e
->ATI_texture_mirror_once
|| e
->EXT_texture_mirror_clamp
|| e
->ARB_texture_mirror_clamp_to_edge
;
309 case GL_MIRROR_CLAMP_TO_BORDER_EXT
:
310 return e
->EXT_texture_mirror_clamp
;
318 * This is called just prior to changing any sampler object state.
321 flush(struct gl_context
*ctx
)
323 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
327 #define INVALID_PARAM 0x100
328 #define INVALID_PNAME 0x101
329 #define INVALID_VALUE 0x102
332 set_sampler_wrap_s(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
335 if (samp
->WrapS
== param
)
337 if (validate_texture_wrap_mode(ctx
, param
)) {
342 return INVALID_PARAM
;
347 set_sampler_wrap_t(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
350 if (samp
->WrapT
== param
)
352 if (validate_texture_wrap_mode(ctx
, param
)) {
357 return INVALID_PARAM
;
362 set_sampler_wrap_r(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
365 if (samp
->WrapR
== param
)
367 if (validate_texture_wrap_mode(ctx
, param
)) {
372 return INVALID_PARAM
;
377 set_sampler_min_filter(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
380 if (samp
->MinFilter
== param
)
386 case GL_NEAREST_MIPMAP_NEAREST
:
387 case GL_LINEAR_MIPMAP_NEAREST
:
388 case GL_NEAREST_MIPMAP_LINEAR
:
389 case GL_LINEAR_MIPMAP_LINEAR
:
391 samp
->MinFilter
= param
;
394 return INVALID_PARAM
;
400 set_sampler_mag_filter(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
403 if (samp
->MagFilter
== param
)
410 samp
->MagFilter
= param
;
413 return INVALID_PARAM
;
419 set_sampler_lod_bias(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
422 if (samp
->LodBias
== param
)
426 samp
->LodBias
= param
;
432 set_sampler_border_colorf(struct gl_context
*ctx
,
433 struct gl_sampler_object
*samp
,
434 const GLfloat params
[4])
437 samp
->BorderColor
.f
[RCOMP
] = params
[0];
438 samp
->BorderColor
.f
[GCOMP
] = params
[1];
439 samp
->BorderColor
.f
[BCOMP
] = params
[2];
440 samp
->BorderColor
.f
[ACOMP
] = params
[3];
446 set_sampler_border_colori(struct gl_context
*ctx
,
447 struct gl_sampler_object
*samp
,
448 const GLint params
[4])
451 samp
->BorderColor
.i
[RCOMP
] = params
[0];
452 samp
->BorderColor
.i
[GCOMP
] = params
[1];
453 samp
->BorderColor
.i
[BCOMP
] = params
[2];
454 samp
->BorderColor
.i
[ACOMP
] = params
[3];
460 set_sampler_border_colorui(struct gl_context
*ctx
,
461 struct gl_sampler_object
*samp
,
462 const GLuint params
[4])
465 samp
->BorderColor
.ui
[RCOMP
] = params
[0];
466 samp
->BorderColor
.ui
[GCOMP
] = params
[1];
467 samp
->BorderColor
.ui
[BCOMP
] = params
[2];
468 samp
->BorderColor
.ui
[ACOMP
] = params
[3];
474 set_sampler_min_lod(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
477 if (samp
->MinLod
== param
)
481 samp
->MinLod
= param
;
487 set_sampler_max_lod(struct gl_context
*ctx
, struct gl_sampler_object
*samp
,
490 if (samp
->MaxLod
== param
)
494 samp
->MaxLod
= param
;
500 set_sampler_compare_mode(struct gl_context
*ctx
,
501 struct gl_sampler_object
*samp
, GLint param
)
503 if (!ctx
->Extensions
.ARB_shadow
)
504 return INVALID_PNAME
;
506 if (samp
->CompareMode
== param
)
509 if (param
== GL_NONE
||
510 param
== GL_COMPARE_R_TO_TEXTURE_ARB
) {
512 samp
->CompareMode
= param
;
516 return INVALID_PARAM
;
521 set_sampler_compare_func(struct gl_context
*ctx
,
522 struct gl_sampler_object
*samp
, GLint param
)
524 if (!ctx
->Extensions
.ARB_shadow
)
525 return INVALID_PNAME
;
527 if (samp
->CompareFunc
== param
)
540 samp
->CompareFunc
= param
;
543 return INVALID_PARAM
;
549 set_sampler_max_anisotropy(struct gl_context
*ctx
,
550 struct gl_sampler_object
*samp
, GLfloat param
)
552 if (!ctx
->Extensions
.EXT_texture_filter_anisotropic
)
553 return INVALID_PNAME
;
555 if (samp
->MaxAnisotropy
== param
)
559 return INVALID_VALUE
;
562 /* clamp to max, that's what NVIDIA does */
563 samp
->MaxAnisotropy
= MIN2(param
, ctx
->Const
.MaxTextureMaxAnisotropy
);
569 set_sampler_cube_map_seamless(struct gl_context
*ctx
,
570 struct gl_sampler_object
*samp
, GLboolean param
)
572 if (!_mesa_is_desktop_gl(ctx
)
573 || !ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
574 return INVALID_PNAME
;
576 if (samp
->CubeMapSeamless
== param
)
579 if (param
!= GL_TRUE
&& param
!= GL_FALSE
)
580 return INVALID_VALUE
;
583 samp
->CubeMapSeamless
= param
;
588 set_sampler_srgb_decode(struct gl_context
*ctx
,
589 struct gl_sampler_object
*samp
, GLenum param
)
591 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
592 return INVALID_PNAME
;
594 if (samp
->sRGBDecode
== param
)
597 if (param
!= GL_DECODE_EXT
&& param
!= GL_SKIP_DECODE_EXT
)
598 return INVALID_VALUE
;
601 samp
->sRGBDecode
= param
;
606 _mesa_SamplerParameteri(GLuint sampler
, GLenum pname
, GLint param
)
608 struct gl_sampler_object
*sampObj
;
610 GET_CURRENT_CONTEXT(ctx
);
612 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
614 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameteri(sampler %u)",
620 case GL_TEXTURE_WRAP_S
:
621 res
= set_sampler_wrap_s(ctx
, sampObj
, param
);
623 case GL_TEXTURE_WRAP_T
:
624 res
= set_sampler_wrap_t(ctx
, sampObj
, param
);
626 case GL_TEXTURE_WRAP_R
:
627 res
= set_sampler_wrap_r(ctx
, sampObj
, param
);
629 case GL_TEXTURE_MIN_FILTER
:
630 res
= set_sampler_min_filter(ctx
, sampObj
, param
);
632 case GL_TEXTURE_MAG_FILTER
:
633 res
= set_sampler_mag_filter(ctx
, sampObj
, param
);
635 case GL_TEXTURE_MIN_LOD
:
636 res
= set_sampler_min_lod(ctx
, sampObj
, (GLfloat
) param
);
638 case GL_TEXTURE_MAX_LOD
:
639 res
= set_sampler_max_lod(ctx
, sampObj
, (GLfloat
) param
);
641 case GL_TEXTURE_LOD_BIAS
:
642 res
= set_sampler_lod_bias(ctx
, sampObj
, (GLfloat
) param
);
644 case GL_TEXTURE_COMPARE_MODE
:
645 res
= set_sampler_compare_mode(ctx
, sampObj
, param
);
647 case GL_TEXTURE_COMPARE_FUNC
:
648 res
= set_sampler_compare_func(ctx
, sampObj
, param
);
650 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
651 res
= set_sampler_max_anisotropy(ctx
, sampObj
, (GLfloat
) param
);
653 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
654 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, param
);
656 case GL_TEXTURE_SRGB_DECODE_EXT
:
657 res
= set_sampler_srgb_decode(ctx
, sampObj
, param
);
659 case GL_TEXTURE_BORDER_COLOR
:
670 /* state change - we do nothing special at this time */
673 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameteri(pname=%s)\n",
674 _mesa_lookup_enum_by_nr(pname
));
677 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameteri(param=%d)\n",
681 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameteri(param=%d)\n",
691 _mesa_SamplerParameterf(GLuint sampler
, GLenum pname
, GLfloat param
)
693 struct gl_sampler_object
*sampObj
;
695 GET_CURRENT_CONTEXT(ctx
);
697 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
699 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterf(sampler %u)",
705 case GL_TEXTURE_WRAP_S
:
706 res
= set_sampler_wrap_s(ctx
, sampObj
, (GLint
) param
);
708 case GL_TEXTURE_WRAP_T
:
709 res
= set_sampler_wrap_t(ctx
, sampObj
, (GLint
) param
);
711 case GL_TEXTURE_WRAP_R
:
712 res
= set_sampler_wrap_r(ctx
, sampObj
, (GLint
) param
);
714 case GL_TEXTURE_MIN_FILTER
:
715 res
= set_sampler_min_filter(ctx
, sampObj
, (GLint
) param
);
717 case GL_TEXTURE_MAG_FILTER
:
718 res
= set_sampler_mag_filter(ctx
, sampObj
, (GLint
) param
);
720 case GL_TEXTURE_MIN_LOD
:
721 res
= set_sampler_min_lod(ctx
, sampObj
, param
);
723 case GL_TEXTURE_MAX_LOD
:
724 res
= set_sampler_max_lod(ctx
, sampObj
, param
);
726 case GL_TEXTURE_LOD_BIAS
:
727 res
= set_sampler_lod_bias(ctx
, sampObj
, param
);
729 case GL_TEXTURE_COMPARE_MODE
:
730 res
= set_sampler_compare_mode(ctx
, sampObj
, (GLint
) param
);
732 case GL_TEXTURE_COMPARE_FUNC
:
733 res
= set_sampler_compare_func(ctx
, sampObj
, (GLint
) param
);
735 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
736 res
= set_sampler_max_anisotropy(ctx
, sampObj
, param
);
738 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
739 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, (GLboolean
) param
);
741 case GL_TEXTURE_SRGB_DECODE_EXT
:
742 res
= set_sampler_srgb_decode(ctx
, sampObj
, (GLenum
) param
);
744 case GL_TEXTURE_BORDER_COLOR
:
755 /* state change - we do nothing special at this time */
758 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterf(pname=%s)\n",
759 _mesa_lookup_enum_by_nr(pname
));
762 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterf(param=%f)\n",
766 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterf(param=%f)\n",
775 _mesa_SamplerParameteriv(GLuint sampler
, GLenum pname
, const GLint
*params
)
777 struct gl_sampler_object
*sampObj
;
779 GET_CURRENT_CONTEXT(ctx
);
781 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
783 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameteriv(sampler %u)",
789 case GL_TEXTURE_WRAP_S
:
790 res
= set_sampler_wrap_s(ctx
, sampObj
, params
[0]);
792 case GL_TEXTURE_WRAP_T
:
793 res
= set_sampler_wrap_t(ctx
, sampObj
, params
[0]);
795 case GL_TEXTURE_WRAP_R
:
796 res
= set_sampler_wrap_r(ctx
, sampObj
, params
[0]);
798 case GL_TEXTURE_MIN_FILTER
:
799 res
= set_sampler_min_filter(ctx
, sampObj
, params
[0]);
801 case GL_TEXTURE_MAG_FILTER
:
802 res
= set_sampler_mag_filter(ctx
, sampObj
, params
[0]);
804 case GL_TEXTURE_MIN_LOD
:
805 res
= set_sampler_min_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
807 case GL_TEXTURE_MAX_LOD
:
808 res
= set_sampler_max_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
810 case GL_TEXTURE_LOD_BIAS
:
811 res
= set_sampler_lod_bias(ctx
, sampObj
, (GLfloat
) params
[0]);
813 case GL_TEXTURE_COMPARE_MODE
:
814 res
= set_sampler_compare_mode(ctx
, sampObj
, params
[0]);
816 case GL_TEXTURE_COMPARE_FUNC
:
817 res
= set_sampler_compare_func(ctx
, sampObj
, params
[0]);
819 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
820 res
= set_sampler_max_anisotropy(ctx
, sampObj
, (GLfloat
) params
[0]);
822 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
823 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, params
[0]);
825 case GL_TEXTURE_SRGB_DECODE_EXT
:
826 res
= set_sampler_srgb_decode(ctx
, sampObj
, params
[0]);
828 case GL_TEXTURE_BORDER_COLOR
:
831 c
[0] = INT_TO_FLOAT(params
[0]);
832 c
[1] = INT_TO_FLOAT(params
[1]);
833 c
[2] = INT_TO_FLOAT(params
[2]);
834 c
[3] = INT_TO_FLOAT(params
[3]);
835 res
= set_sampler_border_colorf(ctx
, sampObj
, c
);
847 /* state change - we do nothing special at this time */
850 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameteriv(pname=%s)\n",
851 _mesa_lookup_enum_by_nr(pname
));
854 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameteriv(param=%d)\n",
858 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameteriv(param=%d)\n",
867 _mesa_SamplerParameterfv(GLuint sampler
, GLenum pname
, const GLfloat
*params
)
869 struct gl_sampler_object
*sampObj
;
871 GET_CURRENT_CONTEXT(ctx
);
873 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
875 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterfv(sampler %u)",
881 case GL_TEXTURE_WRAP_S
:
882 res
= set_sampler_wrap_s(ctx
, sampObj
, (GLint
) params
[0]);
884 case GL_TEXTURE_WRAP_T
:
885 res
= set_sampler_wrap_t(ctx
, sampObj
, (GLint
) params
[0]);
887 case GL_TEXTURE_WRAP_R
:
888 res
= set_sampler_wrap_r(ctx
, sampObj
, (GLint
) params
[0]);
890 case GL_TEXTURE_MIN_FILTER
:
891 res
= set_sampler_min_filter(ctx
, sampObj
, (GLint
) params
[0]);
893 case GL_TEXTURE_MAG_FILTER
:
894 res
= set_sampler_mag_filter(ctx
, sampObj
, (GLint
) params
[0]);
896 case GL_TEXTURE_MIN_LOD
:
897 res
= set_sampler_min_lod(ctx
, sampObj
, params
[0]);
899 case GL_TEXTURE_MAX_LOD
:
900 res
= set_sampler_max_lod(ctx
, sampObj
, params
[0]);
902 case GL_TEXTURE_LOD_BIAS
:
903 res
= set_sampler_lod_bias(ctx
, sampObj
, params
[0]);
905 case GL_TEXTURE_COMPARE_MODE
:
906 res
= set_sampler_compare_mode(ctx
, sampObj
, (GLint
) params
[0]);
908 case GL_TEXTURE_COMPARE_FUNC
:
909 res
= set_sampler_compare_func(ctx
, sampObj
, (GLint
) params
[0]);
911 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
912 res
= set_sampler_max_anisotropy(ctx
, sampObj
, params
[0]);
914 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
915 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, (GLboolean
) params
[0]);
917 case GL_TEXTURE_SRGB_DECODE_EXT
:
918 res
= set_sampler_srgb_decode(ctx
, sampObj
, (GLenum
) params
[0]);
920 case GL_TEXTURE_BORDER_COLOR
:
921 res
= set_sampler_border_colorf(ctx
, sampObj
, params
);
932 /* state change - we do nothing special at this time */
935 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterfv(pname=%s)\n",
936 _mesa_lookup_enum_by_nr(pname
));
939 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterfv(param=%f)\n",
943 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterfv(param=%f)\n",
952 _mesa_SamplerParameterIiv(GLuint sampler
, GLenum pname
, const GLint
*params
)
954 struct gl_sampler_object
*sampObj
;
956 GET_CURRENT_CONTEXT(ctx
);
958 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
960 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterIiv(sampler %u)",
966 case GL_TEXTURE_WRAP_S
:
967 res
= set_sampler_wrap_s(ctx
, sampObj
, params
[0]);
969 case GL_TEXTURE_WRAP_T
:
970 res
= set_sampler_wrap_t(ctx
, sampObj
, params
[0]);
972 case GL_TEXTURE_WRAP_R
:
973 res
= set_sampler_wrap_r(ctx
, sampObj
, params
[0]);
975 case GL_TEXTURE_MIN_FILTER
:
976 res
= set_sampler_min_filter(ctx
, sampObj
, params
[0]);
978 case GL_TEXTURE_MAG_FILTER
:
979 res
= set_sampler_mag_filter(ctx
, sampObj
, params
[0]);
981 case GL_TEXTURE_MIN_LOD
:
982 res
= set_sampler_min_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
984 case GL_TEXTURE_MAX_LOD
:
985 res
= set_sampler_max_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
987 case GL_TEXTURE_LOD_BIAS
:
988 res
= set_sampler_lod_bias(ctx
, sampObj
, (GLfloat
) params
[0]);
990 case GL_TEXTURE_COMPARE_MODE
:
991 res
= set_sampler_compare_mode(ctx
, sampObj
, params
[0]);
993 case GL_TEXTURE_COMPARE_FUNC
:
994 res
= set_sampler_compare_func(ctx
, sampObj
, params
[0]);
996 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
997 res
= set_sampler_max_anisotropy(ctx
, sampObj
, (GLfloat
) params
[0]);
999 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1000 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, params
[0]);
1002 case GL_TEXTURE_SRGB_DECODE_EXT
:
1003 res
= set_sampler_srgb_decode(ctx
, sampObj
, (GLenum
) params
[0]);
1005 case GL_TEXTURE_BORDER_COLOR
:
1006 res
= set_sampler_border_colori(ctx
, sampObj
, params
);
1009 res
= INVALID_PNAME
;
1017 /* state change - we do nothing special at this time */
1020 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterIiv(pname=%s)\n",
1021 _mesa_lookup_enum_by_nr(pname
));
1024 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterIiv(param=%d)\n",
1028 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterIiv(param=%d)\n",
1038 _mesa_SamplerParameterIuiv(GLuint sampler
, GLenum pname
, const GLuint
*params
)
1040 struct gl_sampler_object
*sampObj
;
1042 GET_CURRENT_CONTEXT(ctx
);
1044 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1046 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterIuiv(sampler %u)",
1052 case GL_TEXTURE_WRAP_S
:
1053 res
= set_sampler_wrap_s(ctx
, sampObj
, params
[0]);
1055 case GL_TEXTURE_WRAP_T
:
1056 res
= set_sampler_wrap_t(ctx
, sampObj
, params
[0]);
1058 case GL_TEXTURE_WRAP_R
:
1059 res
= set_sampler_wrap_r(ctx
, sampObj
, params
[0]);
1061 case GL_TEXTURE_MIN_FILTER
:
1062 res
= set_sampler_min_filter(ctx
, sampObj
, params
[0]);
1064 case GL_TEXTURE_MAG_FILTER
:
1065 res
= set_sampler_mag_filter(ctx
, sampObj
, params
[0]);
1067 case GL_TEXTURE_MIN_LOD
:
1068 res
= set_sampler_min_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
1070 case GL_TEXTURE_MAX_LOD
:
1071 res
= set_sampler_max_lod(ctx
, sampObj
, (GLfloat
) params
[0]);
1073 case GL_TEXTURE_LOD_BIAS
:
1074 res
= set_sampler_lod_bias(ctx
, sampObj
, (GLfloat
) params
[0]);
1076 case GL_TEXTURE_COMPARE_MODE
:
1077 res
= set_sampler_compare_mode(ctx
, sampObj
, params
[0]);
1079 case GL_TEXTURE_COMPARE_FUNC
:
1080 res
= set_sampler_compare_func(ctx
, sampObj
, params
[0]);
1082 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1083 res
= set_sampler_max_anisotropy(ctx
, sampObj
, (GLfloat
) params
[0]);
1085 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1086 res
= set_sampler_cube_map_seamless(ctx
, sampObj
, params
[0]);
1088 case GL_TEXTURE_SRGB_DECODE_EXT
:
1089 res
= set_sampler_srgb_decode(ctx
, sampObj
, (GLenum
) params
[0]);
1091 case GL_TEXTURE_BORDER_COLOR
:
1092 res
= set_sampler_border_colorui(ctx
, sampObj
, params
);
1095 res
= INVALID_PNAME
;
1103 /* state change - we do nothing special at this time */
1106 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterIuiv(pname=%s)\n",
1107 _mesa_lookup_enum_by_nr(pname
));
1110 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSamplerParameterIuiv(param=%u)\n",
1114 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSamplerParameterIuiv(param=%u)\n",
1124 _mesa_GetSamplerParameteriv(GLuint sampler
, GLenum pname
, GLint
*params
)
1126 struct gl_sampler_object
*sampObj
;
1127 GET_CURRENT_CONTEXT(ctx
);
1129 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1131 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetSamplerParameteriv(sampler %u)",
1137 case GL_TEXTURE_WRAP_S
:
1138 *params
= sampObj
->WrapS
;
1140 case GL_TEXTURE_WRAP_T
:
1141 *params
= sampObj
->WrapT
;
1143 case GL_TEXTURE_WRAP_R
:
1144 *params
= sampObj
->WrapR
;
1146 case GL_TEXTURE_MIN_FILTER
:
1147 *params
= sampObj
->MinFilter
;
1149 case GL_TEXTURE_MAG_FILTER
:
1150 *params
= sampObj
->MagFilter
;
1152 case GL_TEXTURE_MIN_LOD
:
1153 *params
= (GLint
) sampObj
->MinLod
;
1155 case GL_TEXTURE_MAX_LOD
:
1156 *params
= (GLint
) sampObj
->MaxLod
;
1158 case GL_TEXTURE_LOD_BIAS
:
1159 *params
= (GLint
) sampObj
->LodBias
;
1161 case GL_TEXTURE_COMPARE_MODE
:
1162 if (!ctx
->Extensions
.ARB_shadow
)
1164 *params
= sampObj
->CompareMode
;
1166 case GL_TEXTURE_COMPARE_FUNC
:
1167 if (!ctx
->Extensions
.ARB_shadow
)
1169 *params
= sampObj
->CompareFunc
;
1171 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1172 *params
= (GLint
) sampObj
->MaxAnisotropy
;
1174 case GL_TEXTURE_BORDER_COLOR
:
1175 params
[0] = FLOAT_TO_INT(sampObj
->BorderColor
.f
[0]);
1176 params
[1] = FLOAT_TO_INT(sampObj
->BorderColor
.f
[1]);
1177 params
[2] = FLOAT_TO_INT(sampObj
->BorderColor
.f
[2]);
1178 params
[3] = FLOAT_TO_INT(sampObj
->BorderColor
.f
[3]);
1180 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1181 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1183 *params
= sampObj
->CubeMapSeamless
;
1185 case GL_TEXTURE_SRGB_DECODE_EXT
:
1186 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1188 *params
= (GLenum
) sampObj
->sRGBDecode
;
1196 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSamplerParameteriv(pname=%s)",
1197 _mesa_lookup_enum_by_nr(pname
));
1202 _mesa_GetSamplerParameterfv(GLuint sampler
, GLenum pname
, GLfloat
*params
)
1204 struct gl_sampler_object
*sampObj
;
1205 GET_CURRENT_CONTEXT(ctx
);
1207 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1209 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetSamplerParameterfv(sampler %u)",
1215 case GL_TEXTURE_WRAP_S
:
1216 *params
= (GLfloat
) sampObj
->WrapS
;
1218 case GL_TEXTURE_WRAP_T
:
1219 *params
= (GLfloat
) sampObj
->WrapT
;
1221 case GL_TEXTURE_WRAP_R
:
1222 *params
= (GLfloat
) sampObj
->WrapR
;
1224 case GL_TEXTURE_MIN_FILTER
:
1225 *params
= (GLfloat
) sampObj
->MinFilter
;
1227 case GL_TEXTURE_MAG_FILTER
:
1228 *params
= (GLfloat
) sampObj
->MagFilter
;
1230 case GL_TEXTURE_MIN_LOD
:
1231 *params
= sampObj
->MinLod
;
1233 case GL_TEXTURE_MAX_LOD
:
1234 *params
= sampObj
->MaxLod
;
1236 case GL_TEXTURE_LOD_BIAS
:
1237 *params
= sampObj
->LodBias
;
1239 case GL_TEXTURE_COMPARE_MODE
:
1240 if (!ctx
->Extensions
.ARB_shadow
)
1242 *params
= (GLfloat
) sampObj
->CompareMode
;
1244 case GL_TEXTURE_COMPARE_FUNC
:
1245 if (!ctx
->Extensions
.ARB_shadow
)
1247 *params
= (GLfloat
) sampObj
->CompareFunc
;
1249 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1250 *params
= sampObj
->MaxAnisotropy
;
1252 case GL_TEXTURE_BORDER_COLOR
:
1253 params
[0] = sampObj
->BorderColor
.f
[0];
1254 params
[1] = sampObj
->BorderColor
.f
[1];
1255 params
[2] = sampObj
->BorderColor
.f
[2];
1256 params
[3] = sampObj
->BorderColor
.f
[3];
1258 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1259 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1261 *params
= (GLfloat
) sampObj
->CubeMapSeamless
;
1263 case GL_TEXTURE_SRGB_DECODE_EXT
:
1264 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1266 *params
= (GLfloat
) sampObj
->sRGBDecode
;
1274 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSamplerParameterfv(pname=%s)",
1275 _mesa_lookup_enum_by_nr(pname
));
1280 _mesa_GetSamplerParameterIiv(GLuint sampler
, GLenum pname
, GLint
*params
)
1282 struct gl_sampler_object
*sampObj
;
1283 GET_CURRENT_CONTEXT(ctx
);
1285 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1287 _mesa_error(ctx
, GL_INVALID_VALUE
,
1288 "glGetSamplerParameterIiv(sampler %u)",
1294 case GL_TEXTURE_WRAP_S
:
1295 *params
= sampObj
->WrapS
;
1297 case GL_TEXTURE_WRAP_T
:
1298 *params
= sampObj
->WrapT
;
1300 case GL_TEXTURE_WRAP_R
:
1301 *params
= sampObj
->WrapR
;
1303 case GL_TEXTURE_MIN_FILTER
:
1304 *params
= sampObj
->MinFilter
;
1306 case GL_TEXTURE_MAG_FILTER
:
1307 *params
= sampObj
->MagFilter
;
1309 case GL_TEXTURE_MIN_LOD
:
1310 *params
= (GLint
) sampObj
->MinLod
;
1312 case GL_TEXTURE_MAX_LOD
:
1313 *params
= (GLint
) sampObj
->MaxLod
;
1315 case GL_TEXTURE_LOD_BIAS
:
1316 *params
= (GLint
) sampObj
->LodBias
;
1318 case GL_TEXTURE_COMPARE_MODE
:
1319 if (!ctx
->Extensions
.ARB_shadow
)
1321 *params
= sampObj
->CompareMode
;
1323 case GL_TEXTURE_COMPARE_FUNC
:
1324 if (!ctx
->Extensions
.ARB_shadow
)
1326 *params
= sampObj
->CompareFunc
;
1328 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1329 *params
= (GLint
) sampObj
->MaxAnisotropy
;
1331 case GL_TEXTURE_BORDER_COLOR
:
1332 params
[0] = sampObj
->BorderColor
.i
[0];
1333 params
[1] = sampObj
->BorderColor
.i
[1];
1334 params
[2] = sampObj
->BorderColor
.i
[2];
1335 params
[3] = sampObj
->BorderColor
.i
[3];
1337 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1338 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1340 *params
= sampObj
->CubeMapSeamless
;
1342 case GL_TEXTURE_SRGB_DECODE_EXT
:
1343 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1345 *params
= (GLenum
) sampObj
->sRGBDecode
;
1353 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSamplerParameterIiv(pname=%s)",
1354 _mesa_lookup_enum_by_nr(pname
));
1359 _mesa_GetSamplerParameterIuiv(GLuint sampler
, GLenum pname
, GLuint
*params
)
1361 struct gl_sampler_object
*sampObj
;
1362 GET_CURRENT_CONTEXT(ctx
);
1364 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
1366 _mesa_error(ctx
, GL_INVALID_VALUE
,
1367 "glGetSamplerParameterIuiv(sampler %u)",
1373 case GL_TEXTURE_WRAP_S
:
1374 *params
= sampObj
->WrapS
;
1376 case GL_TEXTURE_WRAP_T
:
1377 *params
= sampObj
->WrapT
;
1379 case GL_TEXTURE_WRAP_R
:
1380 *params
= sampObj
->WrapR
;
1382 case GL_TEXTURE_MIN_FILTER
:
1383 *params
= sampObj
->MinFilter
;
1385 case GL_TEXTURE_MAG_FILTER
:
1386 *params
= sampObj
->MagFilter
;
1388 case GL_TEXTURE_MIN_LOD
:
1389 *params
= (GLuint
) sampObj
->MinLod
;
1391 case GL_TEXTURE_MAX_LOD
:
1392 *params
= (GLuint
) sampObj
->MaxLod
;
1394 case GL_TEXTURE_LOD_BIAS
:
1395 *params
= (GLuint
) sampObj
->LodBias
;
1397 case GL_TEXTURE_COMPARE_MODE
:
1398 if (!ctx
->Extensions
.ARB_shadow
)
1400 *params
= sampObj
->CompareMode
;
1402 case GL_TEXTURE_COMPARE_FUNC
:
1403 if (!ctx
->Extensions
.ARB_shadow
)
1405 *params
= sampObj
->CompareFunc
;
1407 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
1408 *params
= (GLuint
) sampObj
->MaxAnisotropy
;
1410 case GL_TEXTURE_BORDER_COLOR
:
1411 params
[0] = sampObj
->BorderColor
.ui
[0];
1412 params
[1] = sampObj
->BorderColor
.ui
[1];
1413 params
[2] = sampObj
->BorderColor
.ui
[2];
1414 params
[3] = sampObj
->BorderColor
.ui
[3];
1416 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1417 if (!ctx
->Extensions
.AMD_seamless_cubemap_per_texture
)
1419 *params
= sampObj
->CubeMapSeamless
;
1421 case GL_TEXTURE_SRGB_DECODE_EXT
:
1422 if (!ctx
->Extensions
.EXT_texture_sRGB_decode
)
1424 *params
= (GLenum
) sampObj
->sRGBDecode
;
1432 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSamplerParameterIuiv(pname=%s)",
1433 _mesa_lookup_enum_by_nr(pname
));
1438 _mesa_init_sampler_object_functions(struct dd_function_table
*driver
)
1440 driver
->NewSamplerObject
= _mesa_new_sampler_object
;
1441 driver
->DeleteSamplerObject
= _mesa_delete_sampler_object
;