st_atom_sampler.c File Reference

Include dependency graph for st_atom_sampler.c:

Go to the source code of this file.

Functions

static GLuint gl_wrap_to_sp (GLenum wrap)
 Convert GLenum texcoord wrap tokens to pipe tokens.
static GLuint gl_filter_to_mip_filter (GLenum filter)
static GLuint gl_filter_to_img_filter (GLenum filter)
static void update_samplers (struct st_context *st)

Variables

struct st_tracked_state st_update_sampler


Function Documentation

static GLuint gl_filter_to_img_filter ( GLenum  filter  )  [static]

Definition at line 101 of file st_atom_sampler.c.

References assert, PIPE_TEX_FILTER_LINEAR, and PIPE_TEX_FILTER_NEAREST.

00102 {
00103    switch (filter) {
00104    case GL_NEAREST:
00105    case GL_NEAREST_MIPMAP_NEAREST:
00106    case GL_NEAREST_MIPMAP_LINEAR:
00107       return PIPE_TEX_FILTER_NEAREST;
00108 
00109    case GL_LINEAR:
00110    case GL_LINEAR_MIPMAP_NEAREST:
00111    case GL_LINEAR_MIPMAP_LINEAR:
00112       return PIPE_TEX_FILTER_LINEAR;
00113 
00114    default:
00115       assert(0);
00116       return PIPE_TEX_FILTER_NEAREST;
00117    }
00118 }

static GLuint gl_filter_to_mip_filter ( GLenum  filter  )  [static]

Definition at line 78 of file st_atom_sampler.c.

References assert, PIPE_TEX_MIPFILTER_LINEAR, PIPE_TEX_MIPFILTER_NEAREST, and PIPE_TEX_MIPFILTER_NONE.

00079 {
00080    switch (filter) {
00081    case GL_NEAREST:
00082    case GL_LINEAR:
00083       return PIPE_TEX_MIPFILTER_NONE;
00084 
00085    case GL_NEAREST_MIPMAP_NEAREST:
00086    case GL_LINEAR_MIPMAP_NEAREST:
00087       return PIPE_TEX_MIPFILTER_NEAREST;
00088 
00089    case GL_NEAREST_MIPMAP_LINEAR:
00090    case GL_LINEAR_MIPMAP_LINEAR:
00091       return PIPE_TEX_MIPFILTER_LINEAR;
00092 
00093    default:
00094       assert(0);
00095       return PIPE_TEX_MIPFILTER_NONE;
00096    }
00097 }

static GLuint gl_wrap_to_sp ( GLenum  wrap  )  [static]

Convert GLenum texcoord wrap tokens to pipe tokens.

Definition at line 51 of file st_atom_sampler.c.

References assert, PIPE_TEX_WRAP_CLAMP, PIPE_TEX_WRAP_CLAMP_TO_BORDER, PIPE_TEX_WRAP_CLAMP_TO_EDGE, PIPE_TEX_WRAP_MIRROR_CLAMP, PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER, PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE, PIPE_TEX_WRAP_MIRROR_REPEAT, and PIPE_TEX_WRAP_REPEAT.

00052 {
00053    switch (wrap) {
00054    case GL_REPEAT:
00055       return PIPE_TEX_WRAP_REPEAT;
00056    case GL_CLAMP:
00057       return PIPE_TEX_WRAP_CLAMP;
00058    case GL_CLAMP_TO_EDGE:
00059       return PIPE_TEX_WRAP_CLAMP_TO_EDGE;
00060    case GL_CLAMP_TO_BORDER:
00061       return PIPE_TEX_WRAP_CLAMP_TO_BORDER;
00062    case GL_MIRRORED_REPEAT:
00063       return PIPE_TEX_WRAP_MIRROR_REPEAT;
00064    case GL_MIRROR_CLAMP_EXT:
00065       return PIPE_TEX_WRAP_MIRROR_CLAMP;
00066    case GL_MIRROR_CLAMP_TO_EDGE_EXT:
00067       return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE;
00068    case GL_MIRROR_CLAMP_TO_BORDER_EXT:
00069       return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER;
00070    default:
00071       assert(0);
00072       return 0;
00073    }
00074 }

static void update_samplers ( struct st_context st  )  [static]

Definition at line 122 of file st_atom_sampler.c.

References assert, st_fragment_program::Base, pipe_sampler_state::border_color, pipe_sampler_state::compare_func, pipe_sampler_state::compare_mode, st_context::cso_context, cso_single_sampler(), cso_single_sampler_done(), st_context::ctx, st_context::fp, gl_filter_to_img_filter(), gl_filter_to_mip_filter(), gl_wrap_to_sp(), pipe_sampler_state::lod_bias, pipe_sampler_state::mag_img_filter, MAX2, pipe_sampler_state::max_anisotropy, pipe_sampler_state::max_lod, MIN2, pipe_sampler_state::min_img_filter, pipe_sampler_state::min_lod, pipe_sampler_state::min_mip_filter, pipe_sampler_state::normalized_coords, st_context::num_samplers, PIPE_TEX_COMPARE_R_TO_TEXTURE, PIPE_TEX_FILTER_ANISO, st_context::samplers, st_compare_func_to_pipe(), st_get_default_texture(), st_context::state, pipe_sampler_state::wrap_r, pipe_sampler_state::wrap_s, and pipe_sampler_state::wrap_t.

00123 {
00124    const struct st_fragment_program *fs = st->fp;
00125    GLuint su;
00126 
00127    st->state.num_samplers = 0;
00128 
00129    /*printf("%s samplers used = 0x%x\n", __FUNCTION__, fs->Base.Base.SamplersUsed);*/
00130 
00131    /* loop over sampler units (aka tex image units) */
00132    for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) {
00133       struct pipe_sampler_state *sampler = st->state.samplers + su;
00134 
00135       memset(sampler, 0, sizeof(*sampler));
00136 
00137       if (fs->Base.Base.SamplersUsed & (1 << su)) {
00138          GLuint texUnit = fs->Base.Base.SamplerUnits[su];
00139          const struct gl_texture_object *texobj
00140             = st->ctx->Texture.Unit[texUnit]._Current;
00141 
00142          if (!texobj) {
00143             texobj = st_get_default_texture(st);
00144          }
00145 
00146          sampler->wrap_s = gl_wrap_to_sp(texobj->WrapS);
00147          sampler->wrap_t = gl_wrap_to_sp(texobj->WrapT);
00148          sampler->wrap_r = gl_wrap_to_sp(texobj->WrapR);
00149 
00150          sampler->min_img_filter = gl_filter_to_img_filter(texobj->MinFilter);
00151          sampler->min_mip_filter = gl_filter_to_mip_filter(texobj->MinFilter);
00152          sampler->mag_img_filter = gl_filter_to_img_filter(texobj->MagFilter);
00153 
00154          if (texobj->Target != GL_TEXTURE_RECTANGLE_ARB)
00155             sampler->normalized_coords = 1;
00156 
00157          sampler->lod_bias = st->ctx->Texture.Unit[su].LodBias;
00158          sampler->min_lod = MAX2(0.0f, texobj->MinLod);
00159          sampler->max_lod = MIN2(texobj->MaxLevel - texobj->BaseLevel,
00160                                  texobj->MaxLod);
00161          if (sampler->max_lod < sampler->min_lod) {
00162             /* The GL spec doesn't seem to specify what to do in this case.
00163              * Swap the values.
00164              */
00165             float tmp = sampler->max_lod;
00166             sampler->max_lod = sampler->min_lod;
00167             sampler->min_lod = tmp;
00168             assert(sampler->min_lod <= sampler->max_lod);
00169          }
00170 
00171          sampler->border_color[0] = texobj->BorderColor[RCOMP];
00172          sampler->border_color[1] = texobj->BorderColor[GCOMP];
00173          sampler->border_color[2] = texobj->BorderColor[BCOMP];
00174          sampler->border_color[3] = texobj->BorderColor[ACOMP];
00175 
00176          sampler->max_anisotropy = texobj->MaxAnisotropy;
00177          if (sampler->max_anisotropy > 1.0) {
00178             sampler->min_img_filter = PIPE_TEX_FILTER_ANISO;
00179             sampler->mag_img_filter = PIPE_TEX_FILTER_ANISO;
00180          }
00181 
00182          /* only care about ARB_shadow, not SGI shadow */
00183          if (texobj->CompareMode == GL_COMPARE_R_TO_TEXTURE) {
00184             sampler->compare_mode = PIPE_TEX_COMPARE_R_TO_TEXTURE;
00185             sampler->compare_func
00186                = st_compare_func_to_pipe(texobj->CompareFunc);
00187          }
00188 
00189          st->state.num_samplers = su + 1;
00190 
00191          /*printf("%s su=%u non-null\n", __FUNCTION__, su);*/
00192          cso_single_sampler(st->cso_context, su, sampler);
00193       }
00194       else {
00195          /*printf("%s su=%u null\n", __FUNCTION__, su);*/
00196          cso_single_sampler(st->cso_context, su, NULL);
00197       }
00198    }
00199 
00200    cso_single_sampler_done(st->cso_context);
00201 }


Variable Documentation

struct st_tracked_state st_update_sampler

Initial value:

 {
   "st_update_sampler",                                 
   {                                                    
      _NEW_TEXTURE,                                     
      0,                                                
   },
   update_samplers                                      
}

Definition at line 204 of file st_atom_sampler.c.


Generated on Tue Sep 29 06:25:51 2009 for Gallium3D by  doxygen 1.5.4