From: <axl...@us...> - 2010-11-21 04:02:03
|
Revision: 766 http://hgengine.svn.sourceforge.net/hgengine/?rev=766&view=rev Author: axlecrusher Date: 2010-11-21 04:01:56 +0000 (Sun, 21 Nov 2010) Log Message: ----------- Optimize access to commonly modified shader attributes by using pointers to the attributes rather than searching for the attributes each time. Storing pointers to attributes does not seem like the best way to do this. I think there may be a better way to do this, like having a enumeration for each attribute, or an integer computer at compile time to represent a specific attribute. Modified Paths: -------------- Mercury2/modules/ParticleEmitter.cpp Mercury2/modules/ParticleEmitter.h Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Mercury2/src/Shader.cpp Mercury2/src/Shader.h Modified: Mercury2/modules/ParticleEmitter.cpp =================================================================== --- Mercury2/modules/ParticleEmitter.cpp 2010-11-13 21:42:25 UTC (rev 765) +++ Mercury2/modules/ParticleEmitter.cpp 2010-11-21 04:01:56 UTC (rev 766) @@ -95,7 +95,8 @@ m_particles(NULL), GenerateParticlesClbk(NULL), m_fLastD(0),m_fLastI(0), m_dBegin(0), m_dEnd(0), - m_iBegin(0), m_iEnd(0) + m_iBegin(0), m_iEnd(0), + m_shdrAttrEmitterTime(NULL) { m_bufferID[0] = 0; m_iForcePasses = m_iForcePasses | (1<<15); @@ -280,11 +281,12 @@ void ParticleEmitter::Render(const MercuryMatrix& matrix) { - ShaderAttribute sa; - sa.type = ShaderAttribute::TYPE_FLOAT; - sa.value.fFloat = m_age; - Shader::SetAttribute("EmitterTime", sa); + if (m_shdrAttrEmitterTime==NULL) + m_shdrAttrEmitterTime = Shader::GetAttribute("EmitterTime"); + m_shdrAttrEmitterTime->type = ShaderAttribute::TYPE_FLOAT; + m_shdrAttrEmitterTime->value.fFloat = m_age; + GLCALL( glPushAttrib(GL_ENABLE_BIT|GL_CURRENT_BIT) ); GLCALL( glDisable(GL_CULL_FACE) ); Modified: Mercury2/modules/ParticleEmitter.h =================================================================== --- Mercury2/modules/ParticleEmitter.h 2010-11-13 21:42:25 UTC (rev 765) +++ Mercury2/modules/ParticleEmitter.h 2010-11-21 04:01:56 UTC (rev 766) @@ -88,6 +88,9 @@ void *m_dBegin, *m_dEnd; //pointers to area of the m_vertexDynamicData that changed void *m_iBegin, *m_iEnd; //pointers to area of the m_indexData that changed + ShaderAttribute* m_shdrAttrEmitterTime; + + std::list< ParticleBase* > m_active, m_inactive; static uint32_t m_particlesDrawn; }; Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2010-11-13 21:42:25 UTC (rev 765) +++ Mercury2/src/MercuryNode.cpp 2010-11-21 04:01:56 UTC (rev 766) @@ -18,7 +18,8 @@ MercuryNode::MercuryNode() :m_parent(NULL), m_prevSibling(NULL), m_nextSibling(NULL), m_flags(SAVECHILDREN & ENABLESAVE), - m_iPasses( DEFAULT_PASSES ), m_iForcePasses( 0 ) + m_iPasses( DEFAULT_PASSES ), m_iForcePasses( 0 ), + m_shaderAttrModelMatrix(NULL) { m_pGlobalMatrix = &MercuryMatrix::IdentityMatrix; m_pModelViewMatrix = &MercuryMatrix::IdentityMatrix; @@ -238,7 +239,7 @@ const MercuryMatrix& matrix = GetGlobalMatrix(); const MercuryMatrix& modelView = GetModelViewMatrix(); //get the one computed in the last transform - ShaderAttribute sa; +// ShaderAttribute sa; //A lot of this stuff could be moved into the transform node, BUT //the alpha render path requires that all things things happen, so @@ -246,10 +247,13 @@ //RenderGraph::RenderAlpha GLCALL( glLoadMatrix( modelView ) ); - sa.type = ShaderAttribute::TYPE_MATRIX; - sa.value.matrix = matrix.Ptr(); - Shader::SetAttribute("HG_ModelMatrix", sa); + if (m_shaderAttrModelMatrix == NULL) + m_shaderAttrModelMatrix = Shader::GetAttribute("HG_ModelMatrix"); + + m_shaderAttrModelMatrix->type = ShaderAttribute::TYPE_MATRIX; + m_shaderAttrModelMatrix->value.matrix = matrix.Ptr(); + Render( modelView ); //calls on children assets //call render on other render graph entries under me @@ -262,7 +266,7 @@ } GLCALL( glLoadMatrix( modelView ) ); - Shader::SetAttribute("HG_ModelMatrix", sa); + m_shaderAttrModelMatrix->value.matrix = matrix.Ptr(); PostRender( modelView ); //calls on children assets Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2010-11-13 21:42:25 UTC (rev 765) +++ Mercury2/src/MercuryNode.h 2010-11-21 04:01:56 UTC (rev 766) @@ -17,6 +17,7 @@ Each node exists as a single entity in the scene graph. **/ +#include <Shader.h> #define STANDARD_PASS 7 ///Which passes, by default, should be run on all nodes. @@ -173,6 +174,7 @@ const MercuryMatrix * m_pGlobalMatrix; const MercuryMatrix * m_pModelViewMatrix; + ShaderAttribute* m_shaderAttrModelMatrix; friend class RenderGraph; }; Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2010-11-13 21:42:25 UTC (rev 765) +++ Mercury2/src/Shader.cpp 2010-11-21 04:01:56 UTC (rev 766) @@ -462,6 +462,19 @@ return -1; } +ShaderAttribute* Shader::GetAttribute(const MString& name) +{ + ShaderAttribute* a = m_globalAttributes.get(name); + if (a == NULL) + { + ShaderAttribute blank; + m_globalAttributes[name] = blank; + a = m_globalAttributes.get(name); + } + + return a; +} + void Shader::SetAttribute(const MString& name, const ShaderAttribute& x) { m_globalAttributes[name] = x; Modified: Mercury2/src/Shader.h =================================================================== --- Mercury2/src/Shader.h 2010-11-13 21:42:25 UTC (rev 765) +++ Mercury2/src/Shader.h 2010-11-21 04:01:56 UTC (rev 766) @@ -82,6 +82,7 @@ virtual void LoadFromXML(const XMLNode& node); + static ShaderAttribute* GetAttribute(const MString& name); static void SetAttribute(const MString& name, const ShaderAttribute& x); static void RemoveAttribute(const MString& name); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |