Adjust order for meshvp

--HG--
branch : multipass-stereo
This commit is contained in:
kaetemi 2013-09-13 18:25:52 +02:00
parent 278e19743c
commit ab231ea700
2 changed files with 17 additions and 13 deletions

View file

@ -363,7 +363,7 @@ void CMeshVPPerPixelLight::initInstance(CMeshBaseInstance *mbi)
{
// init the vertexProgram code.
static bool vpCreated= false;
if(!vpCreated)
if (!vpCreated)
{
vpCreated= true;
@ -437,6 +437,8 @@ bool CMeshVPPerPixelLight::begin(IDriver *drv,
return false;
}
//
enable(true, drv); // must enable the vertex program before the vb is activated
//
CRenderTrav *renderTrav= &scene->getRenderTrav();
/// Setup for gouraud lighting
renderTrav->beginVPLightSetup(VPLightConstantStart,
@ -482,9 +484,7 @@ bool CMeshVPPerPixelLight::begin(IDriver *drv,
// c[0..3] take the ModelViewProjection Matrix. After setupModelMatrix();
drv->setConstantMatrix(0, IDriver::ModelViewProjection, IDriver::Identity);
//
enable(true, drv); // must enable the vertex program before the vb is activated
//
return true;
}
@ -538,6 +538,8 @@ bool CMeshVPPerPixelLight::setupForMaterial(const CMaterial &mat,
)
{
bool enabled = (mat.getShader() == CMaterial::PerPixelLighting || mat.getShader() == CMaterial::PerPixelLightingNoSpec);
bool change = (enabled != _Enabled);
enable(enabled, drv); // enable disable the vertex program (for material that don't have the right shader)
if (enabled)
{
CRenderTrav *renderTrav= &scene->getRenderTrav();
@ -547,8 +549,6 @@ bool CMeshVPPerPixelLight::setupForMaterial(const CMaterial &mat,
renderTrav->getStrongestLightColors(pplDiffuse, pplSpecular);
drv->setPerPixelLightingLight(pplDiffuse, pplSpecular, mat.getShininess());
}
bool change = (enabled != _Enabled);
enable(enabled, drv); // enable disable the vertex program (for material that don't have the right shader)
return change;
}
//=================================================================================

View file

@ -291,30 +291,34 @@ bool CMeshVPWindTree::begin(IDriver *driver, CScene *scene, CMeshBaseInstance *m
if (!(driver->supportVertexProgram() && !driver->isVertexProgramEmulated())) return false;
// precompute mesh
setupPerMesh(driver, scene);
// Setup instance constants
setupPerInstanceConstants(driver, scene, mbi, invertedModelMat);
// Activate the good VertexProgram
//===============
// Get how many pointLights are setuped now.
nlassert(scene != NULL);
CRenderTrav *renderTrav= &scene->getRenderTrav();
sint numPls= renderTrav->getNumVPLights()-1;
clamp(numPls, 0, CRenderTrav::MaxVPLight-1);
// Enable normalize only if requested by user. Because lighting don't manage correct "scale lighting"
uint idVP= (SpecularLighting?2:0) + (driver->isForceNormalize()?1:0) ;
// correct VP id for correct unmber of pls.
idVP= numPls*4 + idVP;
// activate VP.
driver->activeVertexProgram(_VertexProgram[idVP]);
// precompute mesh
setupPerMesh(driver, scene);
// Setup instance constants
setupPerInstanceConstants(driver, scene, mbi, invertedModelMat);
return true;
}