diff options
author | Brian Paul <[email protected]> | 2011-04-10 12:44:46 -0600 |
---|---|---|
committer | Brian Paul <[email protected]> | 2011-04-10 13:12:49 -0600 |
commit | ecfaab88b2577bd0395bc05d75a036126806a9c4 (patch) | |
tree | 5abb78f767f546778d551a57f7f2cfe20c479f50 /src/mesa/state_tracker | |
parent | 1cbd3a1cc734df16610a59dc49cdb42c70dc3270 (diff) |
mesa: move sampler state into new gl_sampler_object type
gl_texture_object contains an instance of this type for the regular
texture object sampling state. glGenSamplers() generates new instances
of gl_sampler_object which can override that state with glBindSampler().
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r-- | src/mesa/state_tracker/st_atom_sampler.c | 31 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_atom_texture.c | 18 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_texture.c | 12 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_texture.h | 15 |
4 files changed, 52 insertions, 24 deletions
diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index 19d41e7061a..808aa73a083 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -38,6 +38,7 @@ #include "st_cb_texture.h" #include "st_format.h" #include "st_atom.h" +#include "st_texture.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" @@ -138,6 +139,7 @@ update_samplers(struct st_context *st) if (samplersUsed & (1 << su)) { struct gl_texture_object *texobj; struct gl_texture_image *teximg; + struct gl_sampler_object *msamp; GLuint texUnit; if (fprog->Base.SamplersUsed & (1 << su)) @@ -152,25 +154,27 @@ update_samplers(struct st_context *st) teximg = texobj->Image[0][texobj->BaseLevel]; - sampler->wrap_s = gl_wrap_xlate(texobj->WrapS); - sampler->wrap_t = gl_wrap_xlate(texobj->WrapT); - sampler->wrap_r = gl_wrap_xlate(texobj->WrapR); + msamp = st_get_mesa_sampler(st->ctx, texUnit); - sampler->min_img_filter = gl_filter_to_img_filter(texobj->MinFilter); - sampler->min_mip_filter = gl_filter_to_mip_filter(texobj->MinFilter); - sampler->mag_img_filter = gl_filter_to_img_filter(texobj->MagFilter); + sampler->wrap_s = gl_wrap_xlate(msamp->WrapS); + sampler->wrap_t = gl_wrap_xlate(msamp->WrapT); + sampler->wrap_r = gl_wrap_xlate(msamp->WrapR); + + sampler->min_img_filter = gl_filter_to_img_filter(msamp->MinFilter); + sampler->min_mip_filter = gl_filter_to_mip_filter(msamp->MinFilter); + sampler->mag_img_filter = gl_filter_to_img_filter(msamp->MagFilter); if (texobj->Target != GL_TEXTURE_RECTANGLE_ARB) sampler->normalized_coords = 1; sampler->lod_bias = st->ctx->Texture.Unit[texUnit].LodBias + - texobj->LodBias; + msamp->LodBias; - sampler->min_lod = CLAMP(texobj->MinLod, + sampler->min_lod = CLAMP(msamp->MinLod, 0.0f, (GLfloat) texobj->MaxLevel - texobj->BaseLevel); sampler->max_lod = MIN2((GLfloat) texobj->MaxLevel - texobj->BaseLevel, - texobj->MaxLod); + msamp->MaxLod); if (sampler->max_lod < sampler->min_lod) { /* The GL spec doesn't seem to specify what to do in this case. * Swap the values. @@ -181,17 +185,18 @@ update_samplers(struct st_context *st) assert(sampler->min_lod <= sampler->max_lod); } - st_translate_color(texobj->BorderColor.f, + st_translate_color(msamp->BorderColor.f, teximg ? teximg->_BaseFormat : GL_RGBA, sampler->border_color); - sampler->max_anisotropy = (texobj->MaxAnisotropy == 1.0 ? 0 : (GLuint)texobj->MaxAnisotropy); + sampler->max_anisotropy = (msamp->MaxAnisotropy == 1.0 ? + 0 : (GLuint) msamp->MaxAnisotropy); /* only care about ARB_shadow, not SGI shadow */ - if (texobj->CompareMode == GL_COMPARE_R_TO_TEXTURE) { + if (msamp->CompareMode == GL_COMPARE_R_TO_TEXTURE) { sampler->compare_mode = PIPE_TEX_COMPARE_R_TO_TEXTURE; sampler->compare_func - = st_compare_func_to_pipe(texobj->CompareFunc); + = st_compare_func_to_pipe(msamp->CompareFunc); } st->state.num_samplers = su + 1; diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index 6b9f969ac00..e5fb8f86878 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -138,12 +138,13 @@ check_sampler_swizzle(struct pipe_sampler_view *sv, static INLINE struct pipe_sampler_view * st_create_texture_sampler_view_from_stobj(struct pipe_context *pipe, struct st_texture_object *stObj, + const struct gl_sampler_object *samp, enum pipe_format format) { struct pipe_sampler_view templ; GLuint swizzle = apply_depthmode(stObj->pt->format, stObj->base._Swizzle, - stObj->base.DepthMode); + samp->DepthMode); u_sampler_view_default_template(&templ, stObj->pt, @@ -164,6 +165,7 @@ st_create_texture_sampler_view_from_stobj(struct pipe_context *pipe, static INLINE struct pipe_sampler_view * st_get_texture_sampler_view_from_stobj(struct st_texture_object *stObj, struct pipe_context *pipe, + const struct gl_sampler_object *samp, enum pipe_format format) { if (!stObj || !stObj->pt) { @@ -172,7 +174,7 @@ st_get_texture_sampler_view_from_stobj(struct st_texture_object *stObj, if (!stObj->sampler_view) { stObj->sampler_view = - st_create_texture_sampler_view_from_stobj(pipe, stObj, format); + st_create_texture_sampler_view_from_stobj(pipe, stObj, samp, format); } return stObj->sampler_view; @@ -200,16 +202,20 @@ update_textures(struct st_context *st) struct st_texture_object *stObj; GLboolean retval; GLuint texUnit; + const struct gl_sampler_object *samp; if (fprog->Base.SamplersUsed & (1 << su)) texUnit = fprog->Base.SamplerUnits[su]; else texUnit = vprog->Base.SamplerUnits[su]; + samp = st_get_mesa_sampler(st->ctx, texUnit); + texObj = st->ctx->Texture.Unit[texUnit]._Current; if (!texObj) { texObj = st_get_default_texture(st); + samp = &texObj->Sampler; } stObj = st_texture_object(texObj); @@ -228,7 +234,7 @@ update_textures(struct st_context *st) enum pipe_format firstImageFormat = st_mesa_format_to_pipe_format(texFormat); - if ((stObj->base.sRGBDecode == GL_SKIP_DECODE_EXT) && + if ((samp->sRGBDecode == GL_SKIP_DECODE_EXT) && (_mesa_get_format_color_encoding(texFormat) == GL_SRGB)) { /* don't do sRGB->RGB conversion. Interpret the texture * texture data as linear values. @@ -248,12 +254,14 @@ update_textures(struct st_context *st) if (stObj->sampler_view) if (check_sampler_swizzle(stObj->sampler_view, stObj->base._Swizzle, - stObj->base.DepthMode) || + samp->DepthMode) || (st_view_format != stObj->sampler_view->format) || stObj->base.BaseLevel != stObj->sampler_view->u.tex.first_level) pipe_sampler_view_reference(&stObj->sampler_view, NULL); - sampler_view = st_get_texture_sampler_view_from_stobj(stObj, pipe, st_view_format); + sampler_view = st_get_texture_sampler_view_from_stobj(stObj, pipe, + samp, + st_view_format); } pipe_sampler_view_reference(&st->state.sampler_views[su], sampler_view); } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 302f2e1fa17..914c06b7023 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -362,8 +362,8 @@ guess_and_alloc_texture(struct st_context *st, * to re-allocating a texture buffer with space for more (or fewer) * mipmap levels later. */ - if ((stObj->base.MinFilter == GL_NEAREST || - stObj->base.MinFilter == GL_LINEAR || + if ((stObj->base.Sampler.MinFilter == GL_NEAREST || + stObj->base.Sampler.MinFilter == GL_LINEAR || stImage->base._BaseFormat == GL_DEPTH_COMPONENT || stImage->base._BaseFormat == GL_DEPTH_STENCIL_EXT) && !stObj->base.GenerateMipmap && @@ -1742,8 +1742,8 @@ st_finalize_texture(struct gl_context *ctx, * incomplete. In that case, we'll have set stObj->lastLevel before * we get here. */ - if (stObj->base.MinFilter == GL_LINEAR || - stObj->base.MinFilter == GL_NEAREST) + if (stObj->base.Sampler.MinFilter == GL_LINEAR || + stObj->base.Sampler.MinFilter == GL_NEAREST) stObj->lastLevel = stObj->base.BaseLevel; else stObj->lastLevel = stObj->base._MaxLevel; @@ -1890,8 +1890,8 @@ st_get_default_texture(struct st_context *st) texObj, texImg, 0, 0); - texObj->MinFilter = GL_NEAREST; - texObj->MagFilter = GL_NEAREST; + texObj->Sampler.MinFilter = GL_NEAREST; + texObj->Sampler.MagFilter = GL_NEAREST; texObj->_Complete = GL_TRUE; st->default_texture = texObj; diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h index d50c3c9af79..903e30df52f 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -163,6 +163,21 @@ st_get_texture_sampler_view(struct st_texture_object *stObj, } +/** + * Get pointer to the active sampler object for the given texture unit. + * This will either be a user-defined sampler object or the texture + * object's own sampler state. + */ +static INLINE struct gl_sampler_object * +st_get_mesa_sampler(const struct gl_context *ctx, GLuint unit) +{ + if (ctx->Texture.Unit[unit].Sampler) + return ctx->Texture.Unit[unit].Sampler; + else + return &ctx->Texture.Unit[unit]._Current->Sampler; +} + + extern struct pipe_resource * st_texture_create(struct st_context *st, enum pipe_texture_target target, |