From b27653ef778172221b08e7b1049553def69b96d9 Mon Sep 17 00:00:00 2001 From: Ansgar Philippsen <ansgar.philippsen@gmail.com> Date: Fri, 25 Feb 2011 16:54:17 -0500 Subject: [PATCH] fixed view update in gfx entity --- modules/gfx/src/entity.cc | 61 ++++++++++++++++++++++----------------- modules/gfx/src/entity.hh | 11 ++++--- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/modules/gfx/src/entity.cc b/modules/gfx/src/entity.cc index 07a38b28f..0317fd8ea 100644 --- a/modules/gfx/src/entity.cc +++ b/modules/gfx/src/entity.cc @@ -222,31 +222,19 @@ void Entity::SetBlurFactors(float bf1,float bf2) void Entity::Rebuild() { - geom::Vec3 delta=GetTF().GetTrans()-GetTF().GetCenter(); + do_update_view(); // if necessary, update the views + this->ReapplyColorOps(); // re-color everything - if(update_view_) { - EntityView nv=this->GetView(); - trace_.ResetView(nv); - for (RendererMap::iterator i=renderer_.begin(), - e=renderer_.end(); i!=e; ++i) { - impl::EntityRenderer* r=i->second; - if (r->IsEnabled() && r->HasDataToRender()) { - i->second->ClearViews(); - i->second->AddView(nv); - i->second->UpdateViews(); - i->second->PrepareRendering(); - } - } - } + FlagRebuild(); // force renderer rebuilds in RenderGL call + Scene::Instance().RequestRedraw(); - this->ReapplyColorOps(); - FlagRebuild(); + // update center in transformation geom::Vec3 center=this->GetCenter(); Transform tf=this->GetTF(); tf.SetCenter(center); - tf.SetTrans(center+delta); + tf.SetTrans(center+GetTF().GetTrans()-GetTF().GetCenter()); this->SetTF(tf); - Scene::Instance().RequestRedraw(); + } void Entity::UpdatePositions() @@ -256,6 +244,7 @@ void Entity::UpdatePositions() impl::EntityRenderer* r=i->second; r->FlagPositionsDirty(); } + // Rebuild() here causes an recursive loop... FlagRebuild(); Scene::Instance().RequestRedraw(); } @@ -845,10 +834,7 @@ void Entity::ColorBy(const String& prop, mol::EntityView Entity::GetView() const { - if (update_view_) { - update_view_=false; - cached_view_=qv_.GetEntityView(); - } + do_update_view(); return cached_view_; } @@ -1018,11 +1004,12 @@ void Entity::ReapplyColorOps() GfxObj::ReapplyColorOps(); } -void Entity::UpdateView() +void Entity::UpdateView() { - update_view_=true; + update_view_=true; Rebuild(); - UpdatePositions(); + FlagRebuild(); + Scene::Instance().RequestRedraw(); } void Entity::SetSeqHack(bool b) @@ -1030,6 +1017,7 @@ void Entity::SetSeqHack(bool b) if(b!=trace_.GetSeqHack()) { trace_.SetSeqHack(b); FlagRebuild(); + Scene::Instance().RequestRedraw(); } } @@ -1038,4 +1026,25 @@ bool Entity::GetSeqHack() const return trace_.GetSeqHack(); } +void Entity::do_update_view() const +{ + // also signals an update in positions + if (update_view_) { + update_view_=false; + cached_view_=qv_.GetEntityView(); + trace_.ResetView(cached_view_); + for (RendererMap::iterator i=renderer_.begin(), + e=renderer_.end(); i!=e; ++i) { + impl::EntityRenderer* r=i->second; + if (r->IsEnabled() && r->HasDataToRender()) { + r->ClearViews(); + r->AddView(cached_view_); + r->UpdateViews(); + r->FlagPositionsDirty(); + r->PrepareRendering(); + } + } + } +} + }} // ns diff --git a/modules/gfx/src/entity.hh b/modules/gfx/src/entity.hh index d8571fcfc..1073b561a 100644 --- a/modules/gfx/src/entity.hh +++ b/modules/gfx/src/entity.hh @@ -155,8 +155,12 @@ public: void Rebuild(); /// \brief only grab updated positions, dont rebuild the whole thing + /// views won't be regenerated from stored queries void UpdatePositions(); + /// \brief forces all views to be regenerated from stored queries + void UpdateView(); + /// \brief set color for selection void SetColor(const Color& col, const String& selection=String("")); @@ -276,8 +280,6 @@ public: RenderOptionsPtr& render_options); bool HasSelection() const; - void UpdateView(); - void SetSeqHack(bool b); bool GetSeqHack() const; @@ -298,12 +300,13 @@ private: mutable geom::AlignedCuboid bbox_; mol::EntityView sel_; bool sel_update_; - impl::BackboneTrace trace_; + mutable impl::BackboneTrace trace_; void init(RenderMode::Type); void set_static_max_rad(); - + void do_update_view() const; + typedef boost::ptr_map<RenderMode::Type, impl::EntityRenderer> RendererMap; mutable RendererMap renderer_; -- GitLab