From 019e33ad8a3657b24f032ce85678713ec0706d66 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 14 Dec 2001 22:03:49 +0000 Subject: [PATCH] automatically regenerate mesh in nli when screen regenerated --- panda/src/distort/nonlinearImager.cxx | 13 +++++++++++++ panda/src/distort/nonlinearImager.h | 1 + panda/src/distort/projectionScreen.I | 15 +++++++++++++++ panda/src/distort/projectionScreen.cxx | 1 + panda/src/distort/projectionScreen.h | 4 ++++ 5 files changed, 34 insertions(+) diff --git a/panda/src/distort/nonlinearImager.cxx b/panda/src/distort/nonlinearImager.cxx index 5d6c2540da..5be3cf933a 100644 --- a/panda/src/distort/nonlinearImager.cxx +++ b/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(); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/distort/nonlinearImager.h b/panda/src/distort/nonlinearImager.h index 6327e46b8a..815d3beb49 100644 --- a/panda/src/distort/nonlinearImager.h +++ b/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; }; diff --git a/panda/src/distort/projectionScreen.I b/panda/src/distort/projectionScreen.I index 3442c75cfb..f2366d79bb 100644 --- a/panda/src/distort/projectionScreen.I +++ b/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; +} diff --git a/panda/src/distort/projectionScreen.cxx b/panda/src/distort/projectionScreen.cxx index 763a0f8295..8333f12379 100644 --- a/panda/src/distort/projectionScreen.cxx +++ b/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; } diff --git a/panda/src/distort/projectionScreen.h b/panda/src/distort/projectionScreen.h index 627b4a24bb..f16efa8525 100644 --- a/panda/src/distort/projectionScreen.h +++ b/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() {