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.
36
struct dd_function_table;
38
static inline struct gl_sampler_object *
39
_mesa_get_samplerobj(struct gl_context *ctx, GLuint unit)
41
if (ctx->Texture.Unit[unit].Sampler)
42
return ctx->Texture.Unit[unit].Sampler;
43
else if (ctx->Texture.Unit[unit]._Current)
44
return &ctx->Texture.Unit[unit]._Current->Sampler;
50
/** Does the given filter state do mipmap filtering? */
51
static inline GLboolean
52
_mesa_is_mipmap_filter(const struct gl_sampler_object *samp)
54
return samp->Attrib.MinFilter != GL_NEAREST && samp->Attrib.MinFilter != GL_LINEAR;
59
_mesa_reference_sampler_object_(struct gl_context *ctx,
60
struct gl_sampler_object **ptr,
61
struct gl_sampler_object *samp);
64
_mesa_reference_sampler_object(struct gl_context *ctx,
65
struct gl_sampler_object **ptr,
66
struct gl_sampler_object *samp)
69
_mesa_reference_sampler_object_(ctx, ptr, samp);
72
extern struct gl_sampler_object *
73
_mesa_lookup_samplerobj(struct gl_context *ctx, GLuint name);
76
_mesa_bind_sampler(struct gl_context *ctx, GLuint unit,
77
struct gl_sampler_object *sampObj);
79
extern const enum pipe_tex_wrap wrap_to_gallium_table[32];
82
* Convert GLenum texcoord wrap tokens to pipe tokens.
84
static inline enum pipe_tex_wrap
85
wrap_to_gallium(GLenum wrap)
87
return wrap_to_gallium_table[wrap & 0x1f];
91
static inline enum pipe_tex_mipfilter
92
mipfilter_to_gallium(GLenum filter)
94
/* Take advantage of how the enums are defined. */
95
if (filter <= GL_LINEAR)
96
return PIPE_TEX_MIPFILTER_NONE;
97
if (filter <= GL_LINEAR_MIPMAP_NEAREST)
98
return PIPE_TEX_MIPFILTER_NEAREST;
100
return PIPE_TEX_MIPFILTER_LINEAR;
104
static inline enum pipe_tex_filter
105
filter_to_gallium(GLenum filter)
107
/* Take advantage of how the enums are defined. */
109
return PIPE_TEX_FILTER_LINEAR;
111
return PIPE_TEX_FILTER_NEAREST;
114
static inline enum pipe_tex_reduction_mode
115
reduction_to_gallium(GLenum reduction_mode)
117
switch (reduction_mode) {
119
return PIPE_TEX_REDUCTION_MIN;
121
return PIPE_TEX_REDUCTION_MAX;
122
case GL_WEIGHTED_AVERAGE_EXT:
124
return PIPE_TEX_REDUCTION_WEIGHTED_AVERAGE;
129
* Convert an OpenGL compare mode to a pipe tokens.
131
static inline enum pipe_compare_func
132
func_to_gallium(GLenum func)
134
/* Same values, just biased */
135
STATIC_ASSERT(PIPE_FUNC_NEVER == GL_NEVER - GL_NEVER);
136
STATIC_ASSERT(PIPE_FUNC_LESS == GL_LESS - GL_NEVER);
137
STATIC_ASSERT(PIPE_FUNC_EQUAL == GL_EQUAL - GL_NEVER);
138
STATIC_ASSERT(PIPE_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER);
139
STATIC_ASSERT(PIPE_FUNC_GREATER == GL_GREATER - GL_NEVER);
140
STATIC_ASSERT(PIPE_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER);
141
STATIC_ASSERT(PIPE_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER);
142
STATIC_ASSERT(PIPE_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER);
143
assert(func >= GL_NEVER);
144
assert(func <= GL_ALWAYS);
145
return (enum pipe_compare_func)(func - GL_NEVER);
149
_mesa_update_is_border_color_nonzero(struct gl_sampler_object *samp)
151
samp->Attrib.IsBorderColorNonZero = samp->Attrib.state.border_color.ui[0] ||
152
samp->Attrib.state.border_color.ui[1] ||
153
samp->Attrib.state.border_color.ui[2] ||
154
samp->Attrib.state.border_color.ui[3];
157
static inline enum pipe_tex_wrap
158
lower_gl_clamp(enum pipe_tex_wrap old_wrap, GLenum wrap, bool clamp_to_border)
160
if (wrap == GL_CLAMP)
161
return clamp_to_border ? PIPE_TEX_WRAP_CLAMP_TO_BORDER :
162
PIPE_TEX_WRAP_CLAMP_TO_EDGE;
163
else if (wrap == GL_MIRROR_CLAMP_EXT)
164
return clamp_to_border ? PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER :
165
PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE;
170
_mesa_lower_gl_clamp(struct gl_context *ctx, struct gl_sampler_object *samp)
172
if (ctx->DriverFlags.NewSamplersWithClamp) {
173
struct pipe_sampler_state *s = &samp->Attrib.state;
174
bool clamp_to_border = s->min_img_filter != PIPE_TEX_FILTER_NEAREST &&
175
s->mag_img_filter != PIPE_TEX_FILTER_NEAREST;
177
s->wrap_s = lower_gl_clamp((enum pipe_tex_wrap)s->wrap_s,
178
samp->Attrib.WrapS, clamp_to_border);
179
s->wrap_t = lower_gl_clamp((enum pipe_tex_wrap)s->wrap_t,
180
samp->Attrib.WrapT, clamp_to_border);
181
s->wrap_r = lower_gl_clamp((enum pipe_tex_wrap)s->wrap_r,
182
samp->Attrib.WrapR, clamp_to_border);
190
#endif /* SAMPLEROBJ_H */