summaryrefslogtreecommitdiffstats
path: root/src/mesa/state_tracker/st_atom_sampler.c
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2012-08-06 08:35:20 -0600
committerBrian Paul <[email protected]>2012-08-06 08:50:20 -0600
commit8eeeef37057e8f31834e421902c529b273295d0b (patch)
tree39d4b8fc9c451d9c781b9852557f09c45fd8d78a /src/mesa/state_tracker/st_atom_sampler.c
parent819e786339fe0eebcd6e8e0ec9e501da548846ba (diff)
st/mesa: merge fragment/vertex sampler update code
Reviewed-by: José Fonseca <[email protected]>
Diffstat (limited to 'src/mesa/state_tracker/st_atom_sampler.c')
-rw-r--r--src/mesa/state_tracker/st_atom_sampler.c106
1 files changed, 50 insertions, 56 deletions
diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c
index c219b21cb07..f39fd7551c2 100644
--- a/src/mesa/state_tracker/st_atom_sampler.c
+++ b/src/mesa/state_tracker/st_atom_sampler.c
@@ -195,88 +195,82 @@ convert_sampler(struct st_context *st,
}
+/**
+ * Update the gallium driver's sampler state for fragment, vertex or
+ * geometry shader stage.
+ */
static void
-update_vertex_samplers(struct st_context *st)
+update_shader_samplers(struct st_context *st,
+ unsigned shader_stage,
+ const struct gl_program *prog,
+ unsigned max_units,
+ struct pipe_sampler_state *samplers,
+ unsigned *num_samplers)
{
- const struct gl_context *ctx = st->ctx;
- struct gl_vertex_program *vprog = ctx->VertexProgram._Current;
- GLuint su;
- GLuint samplers_used = vprog->Base.SamplersUsed;
- const GLuint old_max = st->state.num_vertex_samplers;
-
- if (st->state.num_vertex_samplers == 0 && vprog->Base.SamplersUsed == 0)
- return;
-
- st->state.num_vertex_samplers = 0;
-
- /* loop over sampler units (aka tex image units) */
- for (su = 0; su < ctx->Const.MaxVertexTextureImageUnits; su++, samplers_used >>= 1) {
- struct pipe_sampler_state *sampler = st->state.vertex_samplers + su;
-
- if (samplers_used & 1) {
- GLuint texUnit = vprog->Base.SamplerUnits[su];
+ GLuint unit;
+ GLbitfield samplers_used;
+ const GLuint old_max = *num_samplers;
- convert_sampler(st, sampler, texUnit);
+ samplers_used = prog->SamplersUsed;
- st->state.num_vertex_samplers = su + 1;
-
- cso_single_sampler(st->cso_context, PIPE_SHADER_VERTEX, su, sampler);
- }
- else if (samplers_used != 0 || su < old_max) {
- cso_single_sampler(st->cso_context, PIPE_SHADER_VERTEX, su, NULL);
- } else {
- /* if we've reset all the old samplers and we have no more new ones */
- break;
- }
- }
- cso_single_sampler_done(st->cso_context, PIPE_SHADER_VERTEX);
-}
-
-
-static void
-update_fragment_samplers(struct st_context *st)
-{
- const struct gl_context *ctx = st->ctx;
- struct gl_fragment_program *fprog = ctx->FragmentProgram._Current;
- GLuint su;
- GLuint samplers_used = fprog->Base.SamplersUsed;
- const GLuint old_max = st->state.num_fragment_samplers;
-
- if (st->state.num_fragment_samplers == 0 && fprog->Base.SamplersUsed == 0)
+ if (*num_samplers == 0 && samplers_used == 0x0)
return;
- st->state.num_fragment_samplers = 0;
+ *num_samplers = 0;
/* loop over sampler units (aka tex image units) */
- for (su = 0; su < ctx->Const.MaxTextureImageUnits; su++, samplers_used >>= 1) {
- struct pipe_sampler_state *sampler = st->state.fragment_samplers + su;
+ for (unit = 0; unit < max_units; unit++, samplers_used >>= 1) {
+ struct pipe_sampler_state *sampler = samplers + unit;
if (samplers_used & 1) {
- GLuint texUnit = fprog->Base.SamplerUnits[su];
+ const GLuint texUnit = prog->SamplerUnits[unit];
convert_sampler(st, sampler, texUnit);
- st->state.num_fragment_samplers = su + 1;
+ *num_samplers = unit + 1;
- cso_single_sampler(st->cso_context, PIPE_SHADER_FRAGMENT, su, sampler);
+ cso_single_sampler(st->cso_context, shader_stage, unit, sampler);
}
- else if (samplers_used != 0 || su < old_max) {
- cso_single_sampler(st->cso_context, PIPE_SHADER_FRAGMENT, su, NULL);
- } else {
+ else if (samplers_used != 0 || unit < old_max) {
+ cso_single_sampler(st->cso_context, shader_stage, unit, NULL);
+ }
+ else {
/* if we've reset all the old samplers and we have no more new ones */
break;
}
}
- cso_single_sampler_done(st->cso_context, PIPE_SHADER_FRAGMENT);
+ cso_single_sampler_done(st->cso_context, shader_stage);
}
static void
update_samplers(struct st_context *st)
{
- update_fragment_samplers(st);
- update_vertex_samplers(st);
+ const struct gl_context *ctx = st->ctx;
+
+ update_shader_samplers(st,
+ PIPE_SHADER_FRAGMENT,
+ &ctx->FragmentProgram._Current->Base,
+ ctx->Const.MaxTextureImageUnits,
+ st->state.fragment_samplers,
+ &st->state.num_fragment_samplers);
+
+ update_shader_samplers(st,
+ PIPE_SHADER_VERTEX,
+ &ctx->VertexProgram._Current->Base,
+ ctx->Const.MaxVertexTextureImageUnits,
+ st->state.vertex_samplers,
+ &st->state.num_vertex_samplers);
+
+/*
+ update_shader_samplers(st,
+ PIPE_SHADER_GEOMETRY,
+ &ctx->GeometryProgram._Current->Base,
+ ctx->Const.MaxGeometryTextureImageUnits,
+ st->state.geometry_samplers,
+ &st->state.num_geometry_samplers);
+*/
}