1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
35 #include "st_context.h"
38 #include "pipe/p_context.h"
39 #include "pipe/p_defines.h"
43 * Convert GLenum texcoord wrap tokens to pipe tokens.
46 gl_wrap_to_sp(GLenum wrap
)
50 return PIPE_TEX_WRAP_REPEAT
;
52 return PIPE_TEX_WRAP_CLAMP
;
53 case GL_CLAMP_TO_EDGE
:
54 return PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
55 case GL_CLAMP_TO_BORDER
:
56 return PIPE_TEX_WRAP_CLAMP_TO_BORDER
;
57 case GL_MIRRORED_REPEAT
:
58 return PIPE_TEX_WRAP_MIRROR_REPEAT
;
59 case GL_MIRROR_CLAMP_EXT
:
60 return PIPE_TEX_WRAP_MIRROR_CLAMP
;
61 case GL_MIRROR_CLAMP_TO_EDGE_EXT
:
62 return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
;
63 case GL_MIRROR_CLAMP_TO_BORDER_EXT
:
64 return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
;
73 gl_filter_to_mip_filter(GLenum filter
)
78 return PIPE_TEX_MIPFILTER_NONE
;
80 case GL_NEAREST_MIPMAP_NEAREST
:
81 case GL_LINEAR_MIPMAP_NEAREST
:
82 return PIPE_TEX_MIPFILTER_NEAREST
;
84 case GL_NEAREST_MIPMAP_LINEAR
:
85 case GL_LINEAR_MIPMAP_LINEAR
:
86 return PIPE_TEX_MIPFILTER_LINEAR
;
90 return PIPE_TEX_MIPFILTER_NONE
;
96 gl_filter_to_img_filter(GLenum filter
)
100 case GL_NEAREST_MIPMAP_NEAREST
:
101 case GL_NEAREST_MIPMAP_LINEAR
:
102 return PIPE_TEX_FILTER_NEAREST
;
105 case GL_LINEAR_MIPMAP_NEAREST
:
106 case GL_LINEAR_MIPMAP_LINEAR
:
107 return PIPE_TEX_FILTER_LINEAR
;
111 return PIPE_TEX_FILTER_NEAREST
;
118 update_samplers(struct st_context
*st
)
122 for (u
= 0; u
< st
->ctx
->Const
.MaxTextureImageUnits
; u
++) {
123 const struct gl_texture_object
*texobj
124 = st
->ctx
->Texture
.Unit
[u
]._Current
;
125 struct pipe_sampler_state sampler
;
127 memset(&sampler
, 0, sizeof(sampler
));
130 sampler
.wrap_s
= gl_wrap_to_sp(texobj
->WrapS
);
131 sampler
.wrap_t
= gl_wrap_to_sp(texobj
->WrapT
);
132 sampler
.wrap_r
= gl_wrap_to_sp(texobj
->WrapR
);
134 sampler
.min_img_filter
= gl_filter_to_img_filter(texobj
->MinFilter
);
135 sampler
.min_mip_filter
= gl_filter_to_mip_filter(texobj
->MinFilter
);
136 sampler
.mag_img_filter
= gl_filter_to_img_filter(texobj
->MagFilter
);
138 sampler
.lod_bias
= st
->ctx
->Texture
.Unit
[u
].LodBias
;
139 sampler
.min_lod
= texobj
->MinLod
;
140 sampler
.max_lod
= texobj
->MaxLod
;
141 sampler
.max_anisotropy
= texobj
->MaxAnisotropy
;
143 /* XXX more sampler state here */
146 const struct pipe_sampler_state
*cached_sampler
=
147 st_cached_sampler_state(st
, &sampler
);
149 if (cached_sampler
!= st
->state
.sampler
[u
]) {
150 /* state has changed */
151 st
->state
.sampler
[u
] = cached_sampler
;
152 st
->pipe
->bind_sampler_state(st
->pipe
, u
, cached_sampler
);
158 const struct st_tracked_state st_update_sampler
= {
159 .name
= "st_update_sampler",
161 .mesa
= _NEW_TEXTURE
,
164 .update
= update_samplers