|
From: <cn...@us...> - 2009-08-22 17:51:46
|
Revision: 510
http://hgengine.svn.sourceforge.net/hgengine/?rev=510&view=rev
Author: cnlohr
Date: 2009-08-22 17:51:38 +0000 (Sat, 22 Aug 2009)
Log Message:
-----------
allow multipass rendering
Modified Paths:
--------------
Mercury2/src/Mercury2.cpp
Mercury2/src/MercuryAsset.cpp
Mercury2/src/MercuryAsset.h
Mercury2/src/MercuryNode.cpp
Mercury2/src/MercuryNode.h
Mercury2/src/RenderGraph.cpp
Modified: Mercury2/src/Mercury2.cpp
===================================================================
--- Mercury2/src/Mercury2.cpp 2009-08-22 16:10:33 UTC (rev 509)
+++ Mercury2/src/Mercury2.cpp 2009-08-22 17:51:38 UTC (rev 510)
@@ -92,8 +92,17 @@
// renderGraph.Render();
// RenderableNode::RecursiveRender(root);
// printf("\n");
+
+
+ for( g_iPass = 2; g_iPass < 5; g_iPass++ ) //2,3,4
+ if( root->GetPasses() & (1<<g_iPass) )
+ root->RecursiveRender( );
+
root->RecursivePreRender();
- root->RecursiveRender();
+
+ for( g_iPass = 5; g_iPass < 15; g_iPass++ ) //5..15
+ if( root->GetPasses() & (1<<g_iPass) )
+ root->RecursiveRender( );
// renderGraph.RenderAlpha();
w->SwapBuffers();
Modified: Mercury2/src/MercuryAsset.cpp
===================================================================
--- Mercury2/src/MercuryAsset.cpp 2009-08-22 16:10:33 UTC (rev 509)
+++ Mercury2/src/MercuryAsset.cpp 2009-08-22 17:51:38 UTC (rev 510)
@@ -6,7 +6,7 @@
extern bool DOOCCLUSIONCULL;
MercuryAsset::MercuryAsset()
- :m_isInstanced(false), m_boundingVolume(NULL), m_loadState(NONE), m_ignoreCull(false)
+ :m_isInstanced(false), m_boundingVolume(NULL), m_loadState(NONE), m_ignoreCull(false), m_iPasses( DEFAULT_PASSES )
{
}
@@ -65,8 +65,16 @@
if ( !node.Attribute("ignorecull").empty() )
{
- SetIgnoreCull( node.Attribute("ignorecull")=="true" );
+ SetIgnoreCull( StrToBool( node.Attribute("ignorecull") ) );
}
+ if ( !node.Attribute("setPasses").empty() )
+ {
+ MVector< MString > out;
+ SplitStrings( node.Attribute("setPasses"), out, ",+", " \t", 2, 2 );
+ m_iPasses = 0;
+ for( unsigned i = 0; i < out.size(); i++ )
+ m_iPasses = m_iPasses | (1<<StrToInt( out[i] ) );
+ }
}
void MercuryAsset::DrawAxes()
@@ -86,7 +94,7 @@
}
MercuryAssetInstance::MercuryAssetInstance(MercuryAsset* asset)
- :m_asset( asset ), m_isCulled( false )
+ :m_asset( asset ), m_isCulled( false ), m_iPasses( asset->GetPasses() )
{
}
Modified: Mercury2/src/MercuryAsset.h
===================================================================
--- Mercury2/src/MercuryAsset.h 2009-08-22 16:10:33 UTC (rev 509)
+++ Mercury2/src/MercuryAsset.h 2009-08-22 17:51:38 UTC (rev 510)
@@ -58,6 +58,9 @@
inline void SetIgnoreCull(bool t) { m_ignoreCull = t; }
inline bool IgnoreCull() const { return m_ignoreCull; }
+
+ inline unsigned short GetPasses() { return m_iPasses; }
+ inline void SetPasses( unsigned short p ) { m_iPasses = p; }
protected:
void SetLoadState(LoadState ls); //thread safe
LoadState GetLoadState(); //thread safe
@@ -69,6 +72,7 @@
LoadState m_loadState;
MSemaphore m_lock;
bool m_ignoreCull;
+ unsigned short m_iPasses;
};
/** This holds the per-instance data for each asset instance.
@@ -85,10 +89,16 @@
inline bool Culled(bool t) { m_isCulled = t; return m_isCulled; }
inline OcclusionResult& GetOcclusionResult() { return m_occlusionResult; }
+
+ inline unsigned short GetPasses() { return m_iPasses; }
+ inline void SetPasses( unsigned short p ) { m_iPasses = p; }
private:
MAutoPtr< MercuryAsset > m_asset; //actual asset storage
OcclusionResult m_occlusionResult;
bool m_isCulled;
+
+ //We need to keep our own copy, since it may be changed in software from what the original one has.
+ unsigned short m_iPasses;
};
class LoaderThreadData
Modified: Mercury2/src/MercuryNode.cpp
===================================================================
--- Mercury2/src/MercuryNode.cpp 2009-08-22 16:10:33 UTC (rev 509)
+++ Mercury2/src/MercuryNode.cpp 2009-08-22 17:51:38 UTC (rev 510)
@@ -186,10 +186,10 @@
}
}
-void MercuryNode::RecursiveRender()
+void MercuryNode::RecursiveRender( )
{
- if ( IsHidden() || IsCulled() ) return;
-
+ if ( IsHidden() || IsCulled() || (! (m_iPasses & (1<<g_iPass))) ) return;
+
const MercuryMatrix& matrix = GetGlobalMatrix();
const MercuryMatrix& modelView = GetModelViewMatrix(); //get the one computed in the last transform
ShaderAttribute sa;
@@ -262,6 +262,16 @@
}
}
}
+
+ if ( !node.Attribute("setPasses").empty() )
+ {
+ MVector< MString > out;
+ SplitStrings( node.Attribute("setPasses"), out, ",+", " \t", 2, 2 );
+ m_iForcePasses = (1<<15);
+ for( unsigned i = 0; i < out.size(); i++ )
+ m_iForcePasses = m_iForcePasses | (1<<StrToInt( out[i] ) );
+ }
+
}
@@ -365,7 +375,9 @@
bool MercuryNode::m_rebuildRenderGraph = false;
__thread int g_iViewportID;
+__thread int g_iPass;
+
/***************************************************************************
* Copyright (C) 2008 by Joshua Allen *
* *
Modified: Mercury2/src/MercuryNode.h
===================================================================
--- Mercury2/src/MercuryNode.h 2009-08-22 16:10:33 UTC (rev 509)
+++ Mercury2/src/MercuryNode.h 2009-08-22 17:51:38 UTC (rev 510)
@@ -30,9 +30,17 @@
return false;}
*/
+
+#define STANDARD_PASS 7
+///Which passes, by default, should be run on all nodes.
+#define DEFAULT_PASSES ( (1<<STANDARD_PASS) )
+
///The Global Viewport ID for this thread (to enable multi-threaded functioning for Viewports)
extern __thread int g_iViewportID;
+///The Global Pass Number (which Pass is currently doing Render)
+extern __thread int g_iPass;
+
class MercuryNode : public MessageHandler
{
public:
@@ -106,6 +114,8 @@
const MercuryMatrix & GetGlobalMatrix() const { return m_pGlobalMatrix[g_iViewportID]; }
const MercuryMatrix & GetModelViewMatrix() const { return m_pModelViewMatrix[g_iViewportID]; }
+
+ inline unsigned short GetPasses() const { return m_iPasses; }
protected:
std::list< MercuryNode* > m_children; //These nodes are unique, not instanced
MercuryNode* m_parent;
@@ -120,6 +130,9 @@
bool m_culled;
bool IsInAssetList(MercuryAsset* asset) const;
+ unsigned short m_iPasses;
+ unsigned short m_iForcePasses; //If (1<<15) is set, then, we know the force is enabled.
+
//The asset is actually stored here
std::list< MercuryAssetInstance > m_assets;
Modified: Mercury2/src/RenderGraph.cpp
===================================================================
--- Mercury2/src/RenderGraph.cpp 2009-08-22 16:10:33 UTC (rev 509)
+++ Mercury2/src/RenderGraph.cpp 2009-08-22 17:51:38 UTC (rev 510)
@@ -56,18 +56,32 @@
//Update the Matrices
node->m_pGlobalMatrix = &node->FindGlobalMatrix();
- node->m_pModelViewMatrix = &node->FindModelViewMatrix();
-
+ node->m_pModelViewMatrix = &node->FindModelViewMatrix();
+
if ( node )
{
//found a new renderable
entry.m_children.push_back( RenderGraphEntry(&(node->FindGlobalMatrix()), node) );
lastEntry = &(entry.m_children.back());
}
+
+ unsigned short iPasses = 0;
for (MercuryNode* child = node->FirstChild(); child != NULL; child = node->NextChild(child))
+ {
Build(child, *lastEntry);
-
+ iPasses |= child->m_iPasses;
+ }
+
+ std::list< MercuryAssetInstance >::iterator i;
+ for (i = node->m_assets.begin(); i != node->m_assets.end(); ++i )
+ iPasses |= i->GetPasses();
+
+ if( node->m_iForcePasses & (1<<15 ) )
+ node->m_iPasses = node->m_iForcePasses;
+ else
+ node->m_iPasses = iPasses;
+
//coming back up the tree
// entry = lastEntry;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|