Updated wind tree program container

This commit is contained in:
kaetemi 2013-09-13 20:45:06 +02:00
parent ba945f30a8
commit a0fbb152ee
2 changed files with 78 additions and 22 deletions

View file

@ -24,6 +24,7 @@
namespace NL3D {
class CVertexProgramWindTree;
// ***************************************************************************
/**
@ -35,6 +36,7 @@ namespace NL3D {
class CMeshVPWindTree : public IMeshVertexProgram
{
public:
friend class CVertexProgramWindTree;
enum {HrcDepth= 3};
@ -112,7 +114,7 @@ private:
/** The 16 versions: Specular or not (0 or 2), + normalize normal or not (0 or 1).
* All multiplied by 4, because support from 0 to 3 pointLights activated. (0.., 4.., 8.., 12..)
*/
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgram[NumVp];
static NLMISC::CSmartPtr<CVertexProgramWindTree> _VertexProgram[NumVp];
// WindTree Time for this mesh param setup. Stored in mesh because same for all instances.
float _CurrentTime[HrcDepth];

View file

@ -39,7 +39,7 @@ static const uint VPLightConstantStart= 24;
// ***************************************************************************
NLMISC::CSmartPtr<CVertexProgram> CMeshVPWindTree::_VertexProgram[CMeshVPWindTree::NumVp];
NLMISC::CSmartPtr<CVertexProgramWindTree> CMeshVPWindTree::_VertexProgram[CMeshVPWindTree::NumVp];
static const char* WindTreeVPCodeWave=
"!!VP1.0 \n\
@ -79,6 +79,59 @@ static const char* WindTreeVPCodeEnd=
END \n\
";
class CVertexProgramWindTree : public CVertexProgramLighted
{
public:
class CIdx
{
};
CVertexProgramWindTree(uint numPls, bool specular, bool normalize);
virtual ~CVertexProgramWindTree() { };
virtual void buildInfo();
const CIdx &idx() const { return m_Idx; }
bool PerMeshSetup;
private:
CIdx m_Idx;
};
CVertexProgramWindTree::CVertexProgramWindTree(uint numPls, bool specular, bool normalize)
{
// lighted settings
m_FeaturesLighted.SupportSpecular = specular;
m_FeaturesLighted.NumActivePointLights = numPls;
m_FeaturesLighted.Normalize = normalize;
m_FeaturesLighted.CtStartNeLVP = VPLightConstantStart;
// constants cache
PerMeshSetup = false;
// nelvp
{
std::string vpCode = std::string(WindTreeVPCodeWave)
+ CRenderTrav::getLightVPFragmentNeLVP(numPls, VPLightConstantStart, specular, normalize)
+ WindTreeVPCodeEnd;
CSource *source = new CSource();
source->DisplayName = NLMISC::toString("nelvp/MeshVPWindTree/%i/%s/%s", numPls, specular ? "spec" : "nospec", normalize ? "normalize" : "nonormalize");
source->Profile = CVertexProgram::nelvp;
source->setSource(vpCode);
addSource(source);
}
// TODO_VP_GLSL
}
void CVertexProgramWindTree::buildInfo()
{
CVertexProgramLighted::buildInfo();
}
// ***************************************************************************
float CMeshVPWindTree::speedCos(float angle)
{
@ -142,9 +195,6 @@ void CMeshVPWindTree::initInstance(CMeshBaseInstance *mbi)
// All vpcode and begin() written for HrcDepth==3
nlassert(HrcDepth==3);
// combine fragments.
string vpCode;
// For all possible VP.
for(uint i=0;i<NumVp;i++)
{
@ -153,12 +203,8 @@ void CMeshVPWindTree::initInstance(CMeshBaseInstance *mbi)
bool normalize= (i&1)!=0;
bool specular= (i&2)!=0;
// combine fragments
vpCode= string(WindTreeVPCodeWave)
+ CRenderTrav::getLightVPFragmentNeLVP(numPls, VPLightConstantStart, specular, normalize)
+ WindTreeVPCodeEnd;
_VertexProgram[i] = new CVertexProgram(vpCode.c_str());
// TODO_VP_GLSL
// combine
_VertexProgram[i] = new CVertexProgramWindTree(numPls, normalize, specular);
}
}
@ -378,9 +424,6 @@ bool CMeshVPWindTree::isMBRVpOk(IDriver *driver) const
// ***************************************************************************
void CMeshVPWindTree::beginMBRMesh(IDriver *driver, CScene *scene)
{
// precompute mesh
setupPerMesh(driver, scene);
/* Since need a VertexProgram Activation before activeVBHard, activate a default one
bet the common one will be "NoPointLight, NoSpecular, No ForceNormalize" => 0.
*/
@ -388,14 +431,15 @@ void CMeshVPWindTree::beginMBRMesh(IDriver *driver, CScene *scene)
// activate VP.
driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP]);
// precompute mesh
setupPerMesh(driver, scene);
_VertexProgram[_LastMBRIdVP]->PerMeshSetup = true;
}
// ***************************************************************************
void CMeshVPWindTree::beginMBRInstance(IDriver *driver, CScene *scene, CMeshBaseInstance *mbi, const NLMISC::CMatrix &invertedModelMat)
{
// setup first constants for this instance
setupPerInstanceConstants(driver, scene, mbi, invertedModelMat);
// Get how many pointLights are setuped now.
nlassert(scene != NULL);
CRenderTrav *renderTrav= &scene->getRenderTrav();
@ -412,9 +456,19 @@ void CMeshVPWindTree::beginMBRInstance(IDriver *driver, CScene *scene, CMeshBase
{
_LastMBRIdVP= idVP;
driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP]);
if (!_VertexProgram[_LastMBRIdVP]->PerMeshSetup)
{
// precompute mesh
setupPerMesh(driver, scene);
_VertexProgram[_LastMBRIdVP]->PerMeshSetup = true;
}
}
// setup first constants for this instance
setupPerInstanceConstants(driver, scene, mbi, invertedModelMat);
}
// ***************************************************************************
void CMeshVPWindTree::endMBRMesh(IDriver *driver)
{