00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "main/glheader.h"
00030 #include "main/context.h"
00031
00032 #include "pipe/p_defines.h"
00033 #include "st_context.h"
00034 #include "st_atom.h"
00035 #include "st_cb_bitmap.h"
00036 #include "st_program.h"
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 static const struct st_tracked_state *atoms[] =
00047 {
00048 &st_update_depth_stencil_alpha,
00049 &st_update_clip,
00050
00051 &st_finalize_textures,
00052 &st_update_shader,
00053
00054 &st_update_rasterizer,
00055 &st_update_polygon_stipple,
00056 &st_update_viewport,
00057 &st_update_scissor,
00058 &st_update_blend,
00059 &st_update_sampler,
00060 &st_update_texture,
00061 &st_update_framebuffer,
00062 &st_update_vs_constants,
00063 &st_update_fs_constants,
00064 &st_update_pixel_transfer
00065 };
00066
00067
00068 void st_init_atoms( struct st_context *st )
00069 {
00070 GLuint i;
00071
00072 st->atoms = malloc(sizeof(atoms));
00073 st->nr_atoms = sizeof(atoms)/sizeof(*atoms);
00074 memcpy(st->atoms, atoms, sizeof(atoms));
00075
00076
00077
00078 for (i = 0; i < st->nr_atoms; i++) {
00079 if (st->atoms[i] == &st_update_vs_constants) {
00080 st->atoms[i] = &st->constants.tracked_state[PIPE_SHADER_VERTEX];
00081 st->atoms[i][0] = st_update_vs_constants;
00082 }
00083
00084 if (st->atoms[i] == &st_update_fs_constants) {
00085 st->atoms[i] = &st->constants.tracked_state[PIPE_SHADER_FRAGMENT];
00086 st->atoms[i][0] = st_update_fs_constants;
00087 }
00088 }
00089 }
00090
00091
00092 void st_destroy_atoms( struct st_context *st )
00093 {
00094 if (st->atoms) {
00095 free(st->atoms);
00096 st->atoms = NULL;
00097 }
00098 }
00099
00100
00101
00102
00103
00104 static GLboolean check_state( const struct st_state_flags *a,
00105 const struct st_state_flags *b )
00106 {
00107 return ((a->mesa & b->mesa) ||
00108 (a->st & b->st));
00109 }
00110
00111 static void accumulate_state( struct st_state_flags *a,
00112 const struct st_state_flags *b )
00113 {
00114 a->mesa |= b->mesa;
00115 a->st |= b->st;
00116 }
00117
00118
00119 static void xor_states( struct st_state_flags *result,
00120 const struct st_state_flags *a,
00121 const struct st_state_flags *b )
00122 {
00123 result->mesa = a->mesa ^ b->mesa;
00124 result->st = a->st ^ b->st;
00125 }
00126
00127
00128
00129
00130 static void check_program_state( struct st_context *st )
00131 {
00132 GLcontext *ctx = st->ctx;
00133
00134 if (ctx->VertexProgram._Current != &st->vp->Base)
00135 st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
00136
00137 if (ctx->FragmentProgram._Current != &st->fp->Base)
00138 st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
00139
00140 }
00141
00142
00143
00144
00145
00146
00147 void st_validate_state( struct st_context *st )
00148 {
00149 struct st_state_flags *state = &st->dirty;
00150 GLuint i;
00151
00152
00153
00154
00155
00156 if (state->mesa & ~_NEW_PACKUNPACK)
00157 st_flush_bitmap_cache(st);
00158
00159 check_program_state( st );
00160
00161 if (state->st == 0)
00162 return;
00163
00164
00165
00166 if (1) {
00167
00168
00169
00170
00171 struct st_state_flags examined, prev;
00172 memset(&examined, 0, sizeof(examined));
00173 prev = *state;
00174
00175 for (i = 0; i < st->nr_atoms; i++) {
00176 const struct st_tracked_state *atom = st->atoms[i];
00177 struct st_state_flags generated;
00178
00179
00180
00181 if (!(atom->dirty.mesa || atom->dirty.st) ||
00182 !atom->update) {
00183 _mesa_printf("malformed atom %s\n", atom->name);
00184 assert(0);
00185 }
00186
00187 if (check_state(state, &atom->dirty)) {
00188 st->atoms[i]->update( st );
00189
00190 }
00191
00192 accumulate_state(&examined, &atom->dirty);
00193
00194
00195
00196
00197
00198 xor_states(&generated, &prev, state);
00199 assert(!check_state(&examined, &generated));
00200 prev = *state;
00201 }
00202
00203
00204 }
00205 else {
00206 const GLuint nr = st->nr_atoms;
00207
00208 for (i = 0; i < nr; i++) {
00209 if (check_state(state, &st->atoms[i]->dirty))
00210 st->atoms[i]->update( st );
00211 }
00212 }
00213
00214 memset(state, 0, sizeof(*state));
00215 }
00216
00217
00218