From: <cn...@us...> - 2009-08-18 05:23:39
|
Revision: 486 http://hgengine.svn.sourceforge.net/hgengine/?rev=486&view=rev Author: cnlohr Date: 2009-08-18 05:23:32 +0000 (Tue, 18 Aug 2009) Log Message: ----------- use Memoized Matrices (Find and remember the location, so we can GetGlobalMatrix instead of FindGlobalMatrix()) Modified Paths: -------------- Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Mercury2/src/RenderGraph.cpp Mercury2/src/TransformNode.cpp Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-08-18 05:21:53 UTC (rev 485) +++ Mercury2/src/MercuryNode.cpp 2009-08-18 05:23:32 UTC (rev 486) @@ -14,7 +14,9 @@ REGISTER_NODE_TYPE(MercuryNode); MercuryNode::MercuryNode() - :m_parent(NULL), m_prevSibling(NULL), m_nextSibling(NULL), m_hidden(false), m_useAlphaPath(false), m_culled(false) + :m_parent(NULL), m_prevSibling(NULL), + m_nextSibling(NULL), m_hidden(false), + m_useAlphaPath(false), m_culled(false) { } @@ -173,7 +175,7 @@ { if ( IsHidden() ) return; - const MercuryMatrix& matrix = FindGlobalMatrix(); + const MercuryMatrix& matrix = GetGlobalMatrix(); PreRender( matrix ); //calls on children assets @@ -188,8 +190,8 @@ { if ( IsHidden() || IsCulled() ) return; - const MercuryMatrix& matrix = FindGlobalMatrix(); - const MercuryMatrix& modelView = FindModelViewMatrix(); //get the one computed in the last transform + const MercuryMatrix& matrix = GetGlobalMatrix(); + const MercuryMatrix& modelView = GetModelViewMatrix(); //get the one computed in the last transform //A lot of this stuff could be moved into the transform node, BUT @@ -370,6 +372,8 @@ } bool MercuryNode::m_rebuildRenderGraph = false; +__thread int g_iViewportID; + /*************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-08-18 05:21:53 UTC (rev 485) +++ Mercury2/src/MercuryNode.h 2009-08-18 05:23:32 UTC (rev 486) @@ -27,6 +27,10 @@ while(tn) { if (typeid(x) == typeid(*tn)) return true; tn = *n; } \ return false;} */ + +///The Global Viewport ID for this thread (to enable multi-threaded functioning for Viewports) +extern __thread int g_iViewportID; + class MercuryNode : public MessageHandler { public: @@ -91,18 +95,16 @@ virtual void PreRender(const MercuryMatrix& matrix); virtual void Render(const MercuryMatrix& matrix); virtual void PostRender(const MercuryMatrix& matrix); - - ///This will get the world space matrix - const MercuryMatrix& FindGlobalMatrix() const; - const MercuryMatrix& FindModelViewMatrix() const; - + virtual bool IsCulled(const MercuryMatrix& matrix); inline bool IsHidden() { return m_hidden; } inline void SetCulled(bool t) { m_culled = t; } inline bool IsCulled() const { return m_culled; } virtual MercuryMatrix ManipulateMatrix(const MercuryMatrix& matrix); - + + const MercuryMatrix & GetGlobalMatrix() const { return m_pGlobalMatrix[g_iViewportID]; } + const MercuryMatrix & GetModelViewMatrix() const { return m_pModelViewMatrix[g_iViewportID]; } protected: std::list< MercuryNode* > m_children; //These nodes are unique, not instanced MercuryNode* m_parent; @@ -112,13 +114,10 @@ static bool m_rebuildRenderGraph; MString m_name; - bool m_hidden; - public: //XXX: This will become private sooner or later... It is temporarily public for other work. - bool IsInAssetList(MercuryAsset* asset) const; + bool m_hidden; bool m_useAlphaPath; - - private: bool m_culled; + bool IsInAssetList(MercuryAsset* asset) const; //The asset is actually stored here std::list< MercuryAssetInstance > m_assets; @@ -129,6 +128,15 @@ // std::list< MercuryAsset* > m_prerender; // std::list< MercuryAsset* > m_render; // std::list< MercuryAsset* > m_postrender; + + ///This will get the world space matrix + const MercuryMatrix& FindGlobalMatrix() const; + const MercuryMatrix& FindModelViewMatrix() const; + + const MercuryMatrix * m_pGlobalMatrix; + const MercuryMatrix * m_pModelViewMatrix; + + friend class RenderGraph; }; class NodeFactory Modified: Mercury2/src/RenderGraph.cpp =================================================================== --- Mercury2/src/RenderGraph.cpp 2009-08-18 05:21:53 UTC (rev 485) +++ Mercury2/src/RenderGraph.cpp 2009-08-18 05:23:32 UTC (rev 486) @@ -53,6 +53,10 @@ { RenderGraphEntry* lastEntry = &entry; // MercuryNode* rn = MercuryNode::Cast(node); + + //Update the Matrices + node->m_pGlobalMatrix = &node->FindGlobalMatrix(); + node->m_pModelViewMatrix = &node->FindModelViewMatrix(); if ( node ) { @@ -72,7 +76,7 @@ { StoreRenderState srs; srs.Save(); - srs.Matrix = node->FindGlobalMatrix(); + srs.Matrix = node->GetGlobalMatrix(); srs.Node = node; MercuryVertex p = srs.Matrix * MercuryVertex(0,0,0,1); Modified: Mercury2/src/TransformNode.cpp =================================================================== --- Mercury2/src/TransformNode.cpp 2009-08-18 05:21:53 UTC (rev 485) +++ Mercury2/src/TransformNode.cpp 2009-08-18 05:23:32 UTC (rev 486) @@ -20,7 +20,7 @@ { if ( IsHidden() ) return; - const MercuryMatrix& matrix = FindGlobalMatrix(); + const MercuryMatrix& matrix = GetGlobalMatrix(); m_modelView = ManipulateMatrix( matrix ); glLoadMatrix( m_modelView ); @@ -32,7 +32,7 @@ { if ( IsHidden() ) return; - const MercuryMatrix& matrix = FindGlobalMatrix(); + const MercuryMatrix& matrix = GetGlobalMatrix(); m_modelView = ManipulateMatrix( matrix ); glLoadMatrix( m_modelView ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |