Use CSmartPtr for vertex program

--HG--
branch : multipass-stereo
This commit is contained in:
kaetemi 2013-09-10 00:31:26 +02:00
parent 8f4fe87b7b
commit 0429e67903
10 changed files with 77 additions and 61 deletions

View file

@ -86,6 +86,9 @@ struct CGPUProgramFeatures
ModelViewProjectionTranspose = 0x00000400,
ModelViewProjectionInverseTranspose = 0x00000800,
// Fog
Fog = 0x00001000,
//
// Rough example, modify as necessary.
//
@ -144,6 +147,8 @@ struct CGPUProgramIndices
uint ModelViewProjectionTranspose;
uint ModelViewProjectionInverseTranspose;
uint Fog;
//
// Rough example, modify as necessary.
//

View file

@ -84,7 +84,7 @@ private:
bool _IsPointLight;
//
enum { NumVp = 8};
static std::auto_ptr<CVertexProgram> _VertexProgram[NumVp];
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgram[NumVp];
};
} // NL3D

View file

@ -112,7 +112,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 std::auto_ptr<CVertexProgram> _VertexProgram[NumVp];
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgram[NumVp];
// WindTree Time for this mesh param setup. Stored in mesh because same for all instances.
float _CurrentTime[HrcDepth];

View file

@ -247,17 +247,17 @@ private:
static bool _GridSizeTouched;
//
static std::auto_ptr<CVertexProgram> _VertexProgramBump1;
static std::auto_ptr<CVertexProgram> _VertexProgramBump2;
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgramBump1;
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgramBump2;
//
static std::auto_ptr<CVertexProgram> _VertexProgramBump1Diffuse;
static std::auto_ptr<CVertexProgram> _VertexProgramBump2Diffuse;
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgramBump1Diffuse;
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgramBump2Diffuse;
//
static std::auto_ptr<CVertexProgram> _VertexProgramNoBump;
static std::auto_ptr<CVertexProgram> _VertexProgramNoBumpDiffuse;
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgramNoBump;
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgramNoBumpDiffuse;
//
static std::auto_ptr<CVertexProgram> _VertexProgramNoWave;
static std::auto_ptr<CVertexProgram> _VertexProgramNoWaveDiffuse;
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgramNoWave;
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgramNoWaveDiffuse;
};

View file

@ -415,7 +415,7 @@ void CDriverGL::setUniformParams(TProgram program, const CGPUProgramParams &para
{
const std::string &name = params.getNameByOffset(offset);
nlassert(!name.empty() /* missing both parameter name and index, code error */);
uint index = prog->getUniformIndex(name);
uint index = prog->getUniformIndex(name.c_str());
nlassert(index != ~0 /* invalid parameter name */);
params.map(index, name);
}

View file

@ -84,112 +84,121 @@ void IGPUProgram::buildInfo(CSource *source)
if (features.DriverFlags & CGPUProgramFeatures::ModelView)
{
m_Indices.ModelView = getUniformIndex("nlModelView");
m_Indices.ModelView = getUniformIndex("modelView");
if (m_Indices.ModelView == ~0)
{
nlwarning("Missing 'nlModelView' in gpu program '%s', ModelView disabled", source->DisplayName.c_str());
nlwarning("Missing 'modelView' in gpu program '%s', ModelView disabled", source->DisplayName.c_str());
features.DriverFlags &= ~CGPUProgramFeatures::ModelView;
}
}
if (features.DriverFlags & CGPUProgramFeatures::ModelViewInverse)
{
m_Indices.ModelViewInverse = getUniformIndex("nlModelViewInverse");
m_Indices.ModelViewInverse = getUniformIndex("modelViewInverse");
if (m_Indices.ModelViewInverse == ~0)
{
nlwarning("Missing 'nlModelViewInverse' in gpu program '%s', ModelViewInverse disabled", source->DisplayName.c_str());
nlwarning("Missing 'modelViewInverse' in gpu program '%s', ModelViewInverse disabled", source->DisplayName.c_str());
features.DriverFlags &= ~CGPUProgramFeatures::ModelViewInverse;
}
}
if (features.DriverFlags & CGPUProgramFeatures::ModelViewTranspose)
{
m_Indices.ModelViewTranspose = getUniformIndex("nlModelViewTranspose");
m_Indices.ModelViewTranspose = getUniformIndex("modelViewTranspose");
if (m_Indices.ModelViewTranspose == ~0)
{
nlwarning("Missing 'nlModelViewTranspose' in gpu program '%s', ModelViewTranspose disabled", source->DisplayName.c_str());
nlwarning("Missing 'modelViewTranspose' in gpu program '%s', ModelViewTranspose disabled", source->DisplayName.c_str());
features.DriverFlags &= ~CGPUProgramFeatures::ModelViewTranspose;
}
}
if (features.DriverFlags & CGPUProgramFeatures::ModelViewInverseTranspose)
{
m_Indices.ModelViewInverseTranspose = getUniformIndex("nlModelViewInverseTranspose");
m_Indices.ModelViewInverseTranspose = getUniformIndex("modelViewInverseTranspose");
if (m_Indices.ModelViewInverseTranspose == ~0)
{
nlwarning("Missing 'nlModelViewInverseTranspose' in gpu program '%s', ModelViewInverseTranspose disabled", source->DisplayName.c_str());
nlwarning("Missing 'modelViewInverseTranspose' in gpu program '%s', ModelViewInverseTranspose disabled", source->DisplayName.c_str());
features.DriverFlags &= ~CGPUProgramFeatures::ModelViewInverseTranspose;
}
}
if (features.DriverFlags & CGPUProgramFeatures::Projection)
{
m_Indices.Projection = getUniformIndex("nlProjection");
m_Indices.Projection = getUniformIndex("projection");
if (m_Indices.Projection == ~0)
{
nlwarning("Missing 'nlProjection' in gpu program '%s', Projection disabled", source->DisplayName.c_str());
nlwarning("Missing 'projection' in gpu program '%s', Projection disabled", source->DisplayName.c_str());
features.DriverFlags &= ~CGPUProgramFeatures::Projection;
}
}
if (features.DriverFlags & CGPUProgramFeatures::ProjectionInverse)
{
m_Indices.ProjectionInverse = getUniformIndex("nlProjectionInverse");
m_Indices.ProjectionInverse = getUniformIndex("projectionInverse");
if (m_Indices.ProjectionInverse == ~0)
{
nlwarning("Missing 'nlProjectionInverse' in gpu program '%s', ProjectionInverse disabled", source->DisplayName.c_str());
nlwarning("Missing 'projectionInverse' in gpu program '%s', ProjectionInverse disabled", source->DisplayName.c_str());
features.DriverFlags &= ~CGPUProgramFeatures::ProjectionInverse;
}
}
if (features.DriverFlags & CGPUProgramFeatures::ProjectionTranspose)
{
m_Indices.ProjectionTranspose = getUniformIndex("nlProjectionTranspose");
m_Indices.ProjectionTranspose = getUniformIndex("projectionTranspose");
if (m_Indices.ProjectionTranspose == ~0)
{
nlwarning("Missing 'nlProjectionTranspose' in gpu program '%s', ProjectionTranspose disabled", source->DisplayName.c_str());
nlwarning("Missing 'projectionTranspose' in gpu program '%s', ProjectionTranspose disabled", source->DisplayName.c_str());
features.DriverFlags &= ~CGPUProgramFeatures::ProjectionTranspose;
}
}
if (features.DriverFlags & CGPUProgramFeatures::ProjectionInverseTranspose)
{
m_Indices.ProjectionInverseTranspose = getUniformIndex("nlProjectionInverseTranspose");
m_Indices.ProjectionInverseTranspose = getUniformIndex("projectionInverseTranspose");
if (m_Indices.ProjectionInverseTranspose == ~0)
{
nlwarning("Missing 'nlProjectionInverseTranspose' in gpu program '%s', ProjectionInverseTranspose disabled", source->DisplayName.c_str());
nlwarning("Missing 'projectionInverseTranspose' in gpu program '%s', ProjectionInverseTranspose disabled", source->DisplayName.c_str());
features.DriverFlags &= ~CGPUProgramFeatures::ProjectionInverseTranspose;
}
}
if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjection)
{
m_Indices.ModelViewProjection = getUniformIndex("nlModelViewProjection");
m_Indices.ModelViewProjection = getUniformIndex("modelViewProjection");
if (m_Indices.ModelViewProjection == ~0)
{
nlwarning("Missing 'nlModelViewProjection' in gpu program '%s', ModelViewProjection disabled", source->DisplayName.c_str());
nlwarning("Missing 'modelViewProjection' in gpu program '%s', ModelViewProjection disabled", source->DisplayName.c_str());
features.DriverFlags &= ~CGPUProgramFeatures::ModelViewProjection;
}
}
if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjectionInverse)
{
m_Indices.ModelViewProjectionInverse = getUniformIndex("nlModelViewProjectionInverse");
m_Indices.ModelViewProjectionInverse = getUniformIndex("modelViewProjectionInverse");
if (m_Indices.ModelViewProjectionInverse == ~0)
{
nlwarning("Missing 'nlModelViewProjectionInverse' in gpu program '%s', ModelViewProjectionInverse disabled", source->DisplayName.c_str());
nlwarning("Missing 'modelViewProjectionInverse' in gpu program '%s', ModelViewProjectionInverse disabled", source->DisplayName.c_str());
features.DriverFlags &= ~CGPUProgramFeatures::ModelViewProjectionInverse;
}
}
if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjectionTranspose)
{
m_Indices.ModelViewProjectionTranspose = getUniformIndex("nlModelViewProjectionTranspose");
m_Indices.ModelViewProjectionTranspose = getUniformIndex("modelViewProjectionTranspose");
if (m_Indices.ModelViewProjectionTranspose == ~0)
{
nlwarning("Missing 'nlModelViewProjectionTranspose' in gpu program '%s', ModelViewProjectionTranspose disabled", source->DisplayName.c_str());
nlwarning("Missing 'modelViewProjectionTranspose' in gpu program '%s', ModelViewProjectionTranspose disabled", source->DisplayName.c_str());
features.DriverFlags &= ~CGPUProgramFeatures::ModelViewProjectionTranspose;
}
}
if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjectionInverseTranspose)
{
m_Indices.ModelViewProjectionInverseTranspose = getUniformIndex("nlModelViewProjectionInverseTranspose");
m_Indices.ModelViewProjectionInverseTranspose = getUniformIndex("modelViewProjectionInverseTranspose");
if (m_Indices.ModelViewProjectionInverseTranspose == ~0)
{
nlwarning("Missing 'nlModelViewProjectionInverseTranspose' in gpu program '%s', ModelViewProjectionInverseTranspose disabled", source->DisplayName.c_str());
nlwarning("Missing 'modelViewProjectionInverseTranspose' in gpu program '%s', ModelViewProjectionInverseTranspose disabled", source->DisplayName.c_str());
features.DriverFlags &= ~CGPUProgramFeatures::ModelViewProjectionInverseTranspose;
}
}
if (features.DriverFlags & CGPUProgramFeatures::Fog)
{
m_Indices.Fog = getUniformIndex("fog");
if (m_Indices.Fog == ~0)
{
nlwarning("Missing 'fog' in gpu program '%s', Fog disabled", source->DisplayName.c_str());
features.DriverFlags &= ~CGPUProgramFeatures::Fog;
}
}
//
// Rough example, modify as necessary.

View file

@ -32,7 +32,7 @@
namespace NL3D
{
std::auto_ptr<CVertexProgram> CMeshVPPerPixelLight::_VertexProgram[NumVp];
NLMISC::CSmartPtr<CVertexProgram> CMeshVPPerPixelLight::_VertexProgram[NumVp];
// ***************************************************************************
// Light VP fragment constants start at 24
@ -414,7 +414,7 @@ void CMeshVPPerPixelLight::initInstance(CMeshBaseInstance *mbi)
nlassert(0);
}
#endif
_VertexProgram[vp]= std::auto_ptr<CVertexProgram>(new CVertexProgram(vpCode.c_str()));
_VertexProgram[vp] = new CVertexProgram(vpCode.c_str());
}
}
@ -521,7 +521,7 @@ void CMeshVPPerPixelLight::enable(bool enabled, IDriver *drv)
| (SpecularLighting ? 2 : 0)
| (_IsPointLight ? 1 : 0);
//
drv->activeVertexProgram(_VertexProgram[idVP].get());
drv->activeVertexProgram(_VertexProgram[idVP]);
}
else
{

View file

@ -39,7 +39,7 @@ static const uint VPLightConstantStart= 24;
// ***************************************************************************
std::auto_ptr<CVertexProgram> CMeshVPWindTree::_VertexProgram[CMeshVPWindTree::NumVp];
NLMISC::CSmartPtr<CVertexProgram> CMeshVPWindTree::_VertexProgram[CMeshVPWindTree::NumVp];
static const char* WindTreeVPCodeWave=
"!!VP1.0 \n\
@ -157,7 +157,7 @@ void CMeshVPWindTree::initInstance(CMeshBaseInstance *mbi)
vpCode= string(WindTreeVPCodeWave)
+ CRenderTrav::getLightVPFragment(numPls, VPLightConstantStart, specular, normalize)
+ WindTreeVPCodeEnd;
_VertexProgram[i]= std::auto_ptr<CVertexProgram>(new CVertexProgram(vpCode.c_str()));
_VertexProgram[i] = new CVertexProgram(vpCode.c_str());
// TODO_VP_GLSL
}
}
@ -312,7 +312,7 @@ bool CMeshVPWindTree::begin(IDriver *driver, CScene *scene, CMeshBaseInstance *m
idVP= numPls*4 + idVP;
// activate VP.
driver->activeVertexProgram(_VertexProgram[idVP].get());
driver->activeVertexProgram(_VertexProgram[idVP]);
return true;
@ -383,7 +383,7 @@ void CMeshVPWindTree::beginMBRMesh(IDriver *driver, CScene *scene)
_LastMBRIdVP= 0;
// activate VP.
driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP].get());
driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP]);
}
// ***************************************************************************
@ -407,7 +407,7 @@ void CMeshVPWindTree::beginMBRInstance(IDriver *driver, CScene *scene, CMeshBase
if( idVP!=_LastMBRIdVP )
{
_LastMBRIdVP= idVP;
driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP].get());
driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP]);
}
}

View file

@ -908,6 +908,10 @@ void CWaterModel::setupMaterialNVertexShader(IDriver *drv, CWaterShape *shape, c
//=========================//
// setup Water material //
//=========================//
shape->initVertexProgram();
CVertexProgram *program = shape->_ColorMap ? CWaterShape::_VertexProgramNoWaveDiffuse : CWaterShape::_VertexProgramNoWave;
drv->activeVertexProgram(program);
// TODO_VP_MATERIAL
CWaterModel::_WaterMat.setTexture(0, shape->_BumpMap[0]);
CWaterModel::_WaterMat.setTexture(1, shape->_BumpMap[1]);
CWaterModel::_WaterMat.setTexture(3, shape->_ColorMap);
@ -969,8 +973,6 @@ void CWaterModel::setupMaterialNVertexShader(IDriver *drv, CWaterShape *shape, c
cst[10].set(0.5f, 0.5f, 0.f, 1.f); // used to scale reflected ray into the envmap
/// set all our constants in one call
drv->setConstant(cstOffset, sizeof(cst) / sizeof(cst[0]) - cstOffset, (float *) &cst[cstOffset]);
shape->initVertexProgram();
drv->activeVertexProgram(shape->_ColorMap ? CWaterShape::_VertexProgramNoWaveDiffuse.get() : CWaterShape::_VertexProgramNoWave.get());
drv->setConstantFog(4);
}

View file

@ -188,15 +188,15 @@ uint32 CWaterShape::_XGridBorder = 4;
uint32 CWaterShape::_YGridBorder = 4;
uint32 CWaterShape::_MaxGridSize;
bool CWaterShape::_GridSizeTouched = true;
std::auto_ptr<CVertexProgram> CWaterShape::_VertexProgramBump1;
std::auto_ptr<CVertexProgram> CWaterShape::_VertexProgramBump2;
std::auto_ptr<CVertexProgram> CWaterShape::_VertexProgramBump1Diffuse;
std::auto_ptr<CVertexProgram> CWaterShape::_VertexProgramBump2Diffuse;
std::auto_ptr<CVertexProgram> CWaterShape::_VertexProgramNoBump;
std::auto_ptr<CVertexProgram> CWaterShape::_VertexProgramNoBumpDiffuse;
NLMISC::CSmartPtr<CVertexProgram> CWaterShape::_VertexProgramBump1;
NLMISC::CSmartPtr<CVertexProgram> CWaterShape::_VertexProgramBump2;
NLMISC::CSmartPtr<CVertexProgram> CWaterShape::_VertexProgramBump1Diffuse;
NLMISC::CSmartPtr<CVertexProgram> CWaterShape::_VertexProgramBump2Diffuse;
NLMISC::CSmartPtr<CVertexProgram> CWaterShape::_VertexProgramNoBump;
NLMISC::CSmartPtr<CVertexProgram> CWaterShape::_VertexProgramNoBumpDiffuse;
// water with no waves
std::auto_ptr<CVertexProgram> CWaterShape::_VertexProgramNoWave;
std::auto_ptr<CVertexProgram> CWaterShape::_VertexProgramNoWaveDiffuse;
NLMISC::CSmartPtr<CVertexProgram> CWaterShape::_VertexProgramNoWave;
NLMISC::CSmartPtr<CVertexProgram> CWaterShape::_VertexProgramNoWaveDiffuse;
/** Build a vertex program for water depending on requirements
@ -322,17 +322,17 @@ void CWaterShape::initVertexProgram()
if (!created)
{
// waves
_VertexProgramBump1 = std::auto_ptr<CVertexProgram>(BuildWaterVP(false, true, false));
_VertexProgramBump2 = std::auto_ptr<CVertexProgram>(BuildWaterVP(false, true, true));
_VertexProgramBump1 = BuildWaterVP(false, true, false);
_VertexProgramBump2 = BuildWaterVP(false, true, true);
_VertexProgramBump1Diffuse = std::auto_ptr<CVertexProgram>(BuildWaterVP(true, true, false));
_VertexProgramBump2Diffuse = std::auto_ptr<CVertexProgram>(BuildWaterVP(true, true, true));
_VertexProgramBump1Diffuse = BuildWaterVP(true, true, false);
_VertexProgramBump2Diffuse = BuildWaterVP(true, true, true);
_VertexProgramNoBump = std::auto_ptr<CVertexProgram>(BuildWaterVP(false, false, false));
_VertexProgramNoBumpDiffuse = std::auto_ptr<CVertexProgram>(BuildWaterVP(true, false, false));
_VertexProgramNoBump = BuildWaterVP(false, false, false);
_VertexProgramNoBumpDiffuse = BuildWaterVP(true, false, false);
// no waves
_VertexProgramNoWave.reset(new CVertexProgram(WaterVPNoWave)); // TODO_VP_GLSL
_VertexProgramNoWaveDiffuse.reset(new CVertexProgram(WaterVPNoWaveDiffuse)); // TODO_VP_GLSL
_VertexProgramNoWave = new CVertexProgram(WaterVPNoWave); // TODO_VP_GLSL
_VertexProgramNoWaveDiffuse = new CVertexProgram(WaterVPNoWaveDiffuse); // TODO_VP_GLSL
created = true;
}
}