Browse Source

automatically regenerate mesh in nli when screen regenerated

David Rose 24 years ago
parent
commit
019e33ad8a

+ 13 - 0
panda/src/distort/nonlinearImager.cxx

@@ -104,6 +104,7 @@ add_screen(ProjectionScreen *screen) {
   new_screen._texture = (Texture *)NULL;
   new_screen._tex_width = 256;
   new_screen._tex_height = 256;
+  new_screen._last_screen = screen->get_last_screen();
   new_screen._active = true;
 
   // If the LensNode associated with the ProjectionScreen is an actual
@@ -335,6 +336,17 @@ recompute_if_stale() {
     UpdateSeq lens_change = _camera->get_lens()->get_last_change();
     if (_stale || lens_change != _camera_lens_change) {
       recompute();
+    } else {
+      // We're not overall stale, but maybe we need to recompute one
+      // or more of our screens.
+      Screens::iterator si;
+      for (si = _screens.begin(); si != _screens.end(); ++si) {
+        Screen &screen = (*si);
+        if (screen._active && 
+            screen._last_screen != screen._screen->get_last_screen()) {
+          recompute_screen(screen);
+        }
+      }
     }
   }
 }
@@ -370,6 +382,7 @@ recompute_screen(NonlinearImager::Screen &screen) {
 
   screen._texture = texture;
   screen._mesh_arc->set_transition(new TextureTransition(texture));
+  screen._last_screen = screen._screen->get_last_screen();
 }
 
 ////////////////////////////////////////////////////////////////////

+ 1 - 0
panda/src/distort/nonlinearImager.h

@@ -81,6 +81,7 @@ private:
     PT(LensNode) _source;
     PT_Node _scene;
     int _tex_width, _tex_height;
+    UpdateSeq _last_screen;
     bool _active;
   };
 

+ 15 - 0
panda/src/distort/projectionScreen.I

@@ -131,3 +131,18 @@ INLINE const Colorf &ProjectionScreen::
 get_frame_color() const {
   return _frame_color;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: ProjectionScreen::get_last_screen
+//       Access: Public
+//  Description: Returns an UpdateSeq corresponding to the last time a
+//               screen mesh was generated for the ProjectionScreen.
+//               Each time generate_screen() is called, this number is
+//               incremented; this allows other objects (like
+//               NonlinearImager) to know when they need to recompute
+//               themselves.
+////////////////////////////////////////////////////////////////////
+INLINE const UpdateSeq &ProjectionScreen::
+get_last_screen() const {
+  return _last_screen;
+}

+ 1 - 0
panda/src/distort/projectionScreen.cxx

@@ -208,6 +208,7 @@ generate_screen(LensNode *projector, const string &screen_name,
   geom_node->add_geom(geom);
 
   _stale = true;
+  ++_last_screen;
   return geom_node;
 }
 

+ 4 - 0
panda/src/distort/projectionScreen.h

@@ -77,6 +77,9 @@ PUBLISHED:
 
   void recompute();
 
+public:
+  INLINE const UpdateSeq &get_last_screen() const;
+
 private:
   void recompute_if_stale();
   void recompute_node(Node *node, LMatrix4f &rel_mat, bool &computed_rel_mat);
@@ -103,6 +106,7 @@ private:
   bool _computed_rel_top_mat;
   bool _stale;
   UpdateSeq _projector_lens_change;
+  UpdateSeq _last_screen;
 
 public:
   static TypeHandle get_class_type() {