Don't generate and cache shaders if they are set up from outside of the driver.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 11 years ago
parent 43ad0189c6
commit 681a0bc8f3

@ -584,8 +584,10 @@ namespace NL3D
generateShaderDesc( desc, mat ); generateShaderDesc( desc, mat );
// See if we've already generated and compiled this shader
sp = shaderCache.findShader( desc ); sp = shaderCache.findShader( desc );
// Yes we have!
if( !sp.empty() ) if( !sp.empty() )
{ {
if( currentProgram.vp == NULL ) if( currentProgram.vp == NULL )
@ -600,55 +602,62 @@ namespace NL3D
return false; return false;
} }
} }
// No we need to generate it now
else else
{ {
std::string vs; std::string vs;
std::string ps; std::string ps;
bool cacheShaders = true;
shaderGenerator->reset(); shaderGenerator->reset();
shaderGenerator->setMaterial( &mat ); shaderGenerator->setMaterial( &mat );
shaderGenerator->setVBFormat( _CurrentVertexBufferHard->VB->getVertexFormat() ); shaderGenerator->setVBFormat( _CurrentVertexBufferHard->VB->getVertexFormat() );
shaderGenerator->setShaderDesc( &desc ); shaderGenerator->setShaderDesc( &desc );
shaderGenerator->generateVS( vs );
shaderGenerator->generatePS( ps ); // If we don't already have a vertex program attached, we'll generate it now
if( currentProgram.vp == NULL )
vp = new CVertexProgram();
{ {
IProgram::CSource *src = new IProgram::CSource(); shaderGenerator->generateVS( vs );
src->Profile = IProgram::glsl330v; vp = new CVertexProgram();
src->DisplayName = ""; {
src->setSource( vs ); IProgram::CSource *src = new IProgram::CSource();
vp->addSource( src ); src->Profile = IProgram::glsl330v;
} src->DisplayName = "";
src->setSource( vs );
vp->addSource( src );
}
if( !compileVertexProgram( vp ) ) if( !compileVertexProgram( vp ) )
{ {
delete vp; delete vp;
vp = NULL; vp = NULL;
return false; return false;
}
if( !activeVertexProgram( vp ) )
{
delete vp;
vp = NULL;
return false;
}
} }
else
cacheShaders = false;
pp = new CPixelProgram(); // If we don't already have a pixel program attached, we'll generate it now
if( currentProgram.pp == NULL )
{ {
IProgram::CSource *src = new IProgram::CSource(); shaderGenerator->generatePS( ps );
src->Profile = IProgram::glsl330f; pp = new CPixelProgram();
src->DisplayName = ""; {
src->setSource( ps ); IProgram::CSource *src = new IProgram::CSource();
pp->addSource( src ); src->Profile = IProgram::glsl330f;
} src->DisplayName = "";
src->setSource( ps );
pp->addSource( src );
}
if( !compilePixelProgram( pp ) ) if( !compilePixelProgram( pp ) )
{
delete vp;
vp = NULL;
delete pp;
pp = NULL;
return false;
}
if( currentProgram.vp == NULL )
{
if( !activeVertexProgram( vp ) )
{ {
delete vp; delete vp;
vp = NULL; vp = NULL;
@ -656,10 +665,7 @@ namespace NL3D
pp = NULL; pp = NULL;
return false; return false;
} }
}
if( currentProgram.pp == NULL )
{
if( !activePixelProgram( pp ) ) if( !activePixelProgram( pp ) )
{ {
delete vp; delete vp;
@ -669,11 +675,18 @@ namespace NL3D
return false; return false;
} }
} }
else
sp.vp = vp; cacheShaders = false;
sp.pp = pp;
desc.setShaders( sp );
shaderCache.cacheShader( desc ); // If we already have a shader attached we won't cache this shaderpair, since we didn't generate it
if( cacheShaders )
{
sp.vp = vp;
sp.pp = pp;
desc.setShaders( sp );
shaderCache.cacheShader( desc );
}
} }
setupUniforms(); setupUniforms();

Loading…
Cancel
Save