mesa: move comment, change debug code
[mesa.git] / src / mesa / state_tracker / st_atom.c
index dfebfb4768c735032125e52439db8a2701d1b1cd..bf160fe10809bcbe6c576918f628c69fe3618c05 100644 (file)
  **************************************************************************/
 
 
-#include "glheader.h"
-#include "context.h"
+#include "main/glheader.h"
+#include "main/context.h"
 
+#include "pipe/p_defines.h"
 #include "st_context.h"
 #include "st_atom.h"
+#include "st_cb_bitmap.h"
+#include "st_program.h"
+#include "st_manager.h"
 
-       
 
-/* This is used to initialize st->atoms[].  We could use this list
- * directly except for a single atom, st_update_constants, which has a
- * .dirty value which changes according to the parameters of the
- * current fragment and vertex programs, and so cannot be a static
- * value.
+/**
+ * This is used to initialize st->atoms[].
  */
 static const struct st_tracked_state *atoms[] =
 {
-   &st_update_framebuffer,
-   &st_update_clear_color,
-   &st_update_depth,
+   &st_update_depth_stencil_alpha,
    &st_update_clip,
-   &st_update_fs,
-   &st_update_setup,
+
+   &st_finalize_textures,
+   &st_update_fp,
+   &st_update_gp,
+   &st_update_vp,
+
+   &st_update_rasterizer,
    &st_update_polygon_stipple,
    &st_update_viewport,
    &st_update_scissor,
    &st_update_blend,
-   &st_update_stencil,
-   /* will be patched out at runtime */
-/*    &st_update_constants */
+   &st_update_sampler,
+   &st_update_texture,
+   &st_update_framebuffer,
+   &st_update_msaa,
+   &st_update_vs_constants,
+   &st_update_gs_constants,
+   &st_update_fs_constants,
+   &st_update_pixel_transfer
 };
 
 
 void st_init_atoms( struct st_context *st )
 {
-   GLuint i;
-
-   st->atoms = malloc(sizeof(atoms));
-   st->nr_atoms = sizeof(atoms)/sizeof(*atoms);
-   memcpy(st->atoms, atoms, sizeof(atoms));
-
-   /* Patch in a pointer to the dynamic state atom:
-    */
-   for (i = 0; i < st->nr_atoms; i++)
-      if (st->atoms[i] == &st_update_constants)
-        st->atoms[i] = &st->constants.tracked_state;
-
-   memcpy(&st->constants.tracked_state, 
-          &st_update_constants,
-          sizeof(st_update_constants));
+   /* no-op */
 }
 
 
 void st_destroy_atoms( struct st_context *st )
 {
-   if (st->atoms) {
-      free(st->atoms);
-      st->atoms = NULL;
-   }
+   /* no-op */
 }
 
 
@@ -114,6 +105,23 @@ static void xor_states( struct st_state_flags *result,
 }
 
 
+/* Too complex to figure out, just check every time:
+ */
+static void check_program_state( struct st_context *st )
+{
+   struct gl_context *ctx = st->ctx;
+
+   if (ctx->VertexProgram._Current != &st->vp->Base)
+      st->dirty.st |= ST_NEW_VERTEX_PROGRAM;
+
+   if (ctx->FragmentProgram._Current != &st->fp->Base)
+      st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
+
+   if (ctx->GeometryProgram._Current != &st->gp->Base)
+      st->dirty.st |= ST_NEW_GEOMETRY_PROGRAM;
+}
+
+
 /***********************************************************************
  * Update all derived state:
  */
@@ -123,10 +131,27 @@ void st_validate_state( struct st_context *st )
    struct st_state_flags *state = &st->dirty;
    GLuint i;
 
+   /* The bitmap cache is immune to pixel unpack changes.
+    * Note that GLUT makes several calls to glPixelStore for each
+    * bitmap char it draws so this is an important check.
+    */
+   if (state->mesa & ~_NEW_PACKUNPACK)
+      st_flush_bitmap_cache(st);
+
+   check_program_state( st );
+
+   st_manager_validate_framebuffers(st);
+
    if (state->st == 0)
       return;
 
+   /*printf("%s %x/%x\n", __FUNCTION__, state->mesa, state->st);*/
+
+#ifdef NDEBUG
+   if (0) {
+#else
    if (1) {
+#endif
       /* Debug version which enforces various sanity checks on the
        * state flags which are generated and checked to help ensure
        * state atoms are ordered correctly in the list.
@@ -135,16 +160,21 @@ void st_validate_state( struct st_context *st )
       memset(&examined, 0, sizeof(examined));
       prev = *state;
 
-      for (i = 0; i < st->nr_atoms; i++) {      
-        const struct st_tracked_state *atom = st->atoms[i];
+      for (i = 0; i < Elements(atoms); i++) {   
+        const struct st_tracked_state *atom = atoms[i];
         struct st_state_flags generated;
+        
+        /*printf("atom %s %x/%x\n", atom->name, atom->dirty.mesa, atom->dirty.st);*/
 
-        assert(atom->dirty.mesa ||
-               atom->dirty.st);
-        assert(atom->update);
+        if (!(atom->dirty.mesa || atom->dirty.st) ||
+            !atom->update) {
+           printf("malformed atom %s\n", atom->name);
+           assert(0);
+        }
 
         if (check_state(state, &atom->dirty)) {
-           st->atoms[i]->update( st );
+           atoms[i]->update( st );
+           /*printf("after: %x\n", atom->dirty.mesa);*/
         }
 
         accumulate_state(&examined, &atom->dirty);
@@ -157,13 +187,13 @@ void st_validate_state( struct st_context *st )
         assert(!check_state(&examined, &generated));
         prev = *state;
       }
+      /*printf("\n");*/
+
    }
    else {
-      const GLuint nr = st->nr_atoms;
-
-      for (i = 0; i < nr; i++) {        
-        if (check_state(state, &st->atoms[i]->dirty))
-           st->atoms[i]->update( st );
+      for (i = 0; i < Elements(atoms); i++) {   
+        if (check_state(state, &atoms[i]->dirty))
+           atoms[i]->update( st );
       }
    }