Reworks the $Core::commonShaderPath variable usage to be a static variable in ShaderGen for efficiency(only one getVariable when shadergen is initialized), as well as implements the ability to set a default value, and ensures that it tries to set a path even if the pref variable is missing which is important for ported projects from older builds.

This commit is contained in:
Areloch 2017-07-24 00:40:27 -05:00
parent 3d7c1bbbf7
commit 7567ca10c3
17 changed files with 65 additions and 55 deletions

View file

@ -29,7 +29,7 @@
#include "materials/processedMaterial.h"
#include "materials/materialFeatureTypes.h"
#include "shaderGen/shaderGenVars.h"
#include "shaderGen/shaderGen.h"
void BumpFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
@ -235,7 +235,7 @@ void BumpFeatGLSL::setTexData( Material::StageData &stageDat,
ParallaxFeatGLSL::ParallaxFeatGLSL()
: mIncludeDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/gl/torque.glsl" ))
: mIncludeDep(ShaderGen::smCommonShaderPath + String("/gl/torque.glsl" ))
{
addDependency( &mIncludeDep );
}

View file

@ -27,10 +27,10 @@
#include "shaderGen/shaderOp.h"
#include "shaderGen/shaderGenVars.h"
#include "gfx/gfxStructs.h"
#include "shaderGen/shaderGen.h"
PixelSpecularGLSL::PixelSpecularGLSL()
: mDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/gl/lighting.glsl" ))
: mDep(ShaderGen::smCommonShaderPath + String("/gl/lighting.glsl" ))
{
addDependency( &mDep );
}

View file

@ -35,6 +35,8 @@
#include "lighting/advanced/advancedLightBinManager.h"
#include "ts/tsShape.h"
#include "shaderGen/shaderGen.h"
LangElement * ShaderFeatureGLSL::setupTexSpaceMat( Vector<ShaderComponent*> &, // componentList
Var **texSpaceMat )
{
@ -830,7 +832,7 @@ Var* ShaderFeatureGLSL::addOutDetailTexCoord( Vector<ShaderComponent*> &compon
//****************************************************************************
DiffuseMapFeatGLSL::DiffuseMapFeatGLSL()
: mTorqueDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/gl/torque.glsl"))
: mTorqueDep(ShaderGen::smCommonShaderPath + String("/gl/torque.glsl"))
{
addDependency(&mTorqueDep);
}
@ -1951,7 +1953,7 @@ void ReflectCubeFeatGLSL::setTexData( Material::StageData &stageDat,
//****************************************************************************
RTLightingFeatGLSL::RTLightingFeatGLSL()
: mDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/gl/lighting.glsl" ))
: mDep(ShaderGen::smCommonShaderPath + String("/gl/lighting.glsl" ))
{
addDependency( &mDep );
}
@ -2164,7 +2166,7 @@ ShaderFeature::Resources RTLightingFeatGLSL::getResources( const MaterialFeature
//****************************************************************************
FogFeatGLSL::FogFeatGLSL()
: mFogDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/gl/torque.glsl" ))
: mFogDep(ShaderGen::smCommonShaderPath + String("/gl/torque.glsl" ))
{
addDependency( &mFogDep );
}
@ -2294,7 +2296,7 @@ ShaderFeature::Resources FogFeatGLSL::getResources( const MaterialFeatureData &f
//****************************************************************************
VisibilityFeatGLSL::VisibilityFeatGLSL()
: mTorqueDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/gl/torque.glsl" ))
: mTorqueDep(ShaderGen::smCommonShaderPath + String("/gl/torque.glsl" ))
{
addDependency( &mTorqueDep );
}
@ -2460,7 +2462,7 @@ void RenderTargetZeroGLSL::processPix( Vector<ShaderComponent*> &componentList,
//****************************************************************************
HDROutGLSL::HDROutGLSL()
: mTorqueDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/gl/torque.glsl" ))
: mTorqueDep(ShaderGen::smCommonShaderPath + String("/gl/torque.glsl" ))
{
addDependency( &mTorqueDep );
}
@ -2481,7 +2483,7 @@ void HDROutGLSL::processPix( Vector<ShaderComponent*> &componentList,
#include "T3D/fx/groundCover.h"
FoliageFeatureGLSL::FoliageFeatureGLSL()
: mDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/gl/foliage.glsl" ))
: mDep(ShaderGen::smCommonShaderPath + String("/gl/foliage.glsl" ))
{
addDependency( &mDep );
}
@ -2627,7 +2629,7 @@ void ParticleNormalFeatureGLSL::processVert(Vector<ShaderComponent*> &componentL
//****************************************************************************
ImposterVertFeatureGLSL::ImposterVertFeatureGLSL()
: mDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/gl/imposter.glsl" ))
: mDep(ShaderGen::smCommonShaderPath + String("/gl/imposter.glsl" ))
{
addDependency( &mDep );
}

View file

@ -37,7 +37,7 @@ void ShaderGenPrinterGLSL::printShaderHeader( Stream& stream )
stream.write( dStrlen(header1), header1 );
// Cheap HLSL compatibility.
String header3 = String("#include \"") + String(Con::getVariable("$Core::CommonShaderPath")) + String("/gl/hlslCompat.glsl\"\r\n");
String header3 = String("#include \"") + ShaderGen::smCommonShaderPath + String("/gl/hlslCompat.glsl\"\r\n");
stream.write(dStrlen(header3), header3.c_str());
const char* header4 = "\r\n";

View file

@ -29,7 +29,7 @@
#include "materials/processedMaterial.h"
#include "materials/materialFeatureTypes.h"
#include "shaderGen/shaderGenVars.h"
#include "shaderGen/shaderGen.h"
void BumpFeatHLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
@ -239,7 +239,7 @@ void BumpFeatHLSL::setTexData( Material::StageData &stageDat,
ParallaxFeatHLSL::ParallaxFeatHLSL()
: mIncludeDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/torque.hlsl" ))
: mIncludeDep(ShaderGen::smCommonShaderPath + String("/torque.hlsl" ))
{
addDependency( &mIncludeDep );
}

View file

@ -27,10 +27,10 @@
#include "shaderGen/shaderOp.h"
#include "shaderGen/shaderGenVars.h"
#include "gfx/gfxStructs.h"
#include "shaderGen/shaderGen.h"
PixelSpecularHLSL::PixelSpecularHLSL()
: mDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/lighting.hlsl" ))
: mDep(ShaderGen::smCommonShaderPath + String("/lighting.hlsl" ))
{
addDependency( &mDep );
}

View file

@ -35,6 +35,8 @@
#include "lighting/advanced/advancedLightBinManager.h"
#include "ts/tsShape.h"
#include "shaderGen/shaderGen.h"
LangElement * ShaderFeatureHLSL::setupTexSpaceMat( Vector<ShaderComponent*> &, // componentList
Var **texSpaceMat )
{
@ -821,7 +823,7 @@ Var* ShaderFeatureHLSL::addOutDetailTexCoord( Vector<ShaderComponent*> &compon
//****************************************************************************
DiffuseMapFeatHLSL::DiffuseMapFeatHLSL()
: mTorqueDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/torque.hlsl"))
: mTorqueDep(ShaderGen::smCommonShaderPath + String("/torque.hlsl"))
{
addDependency(&mTorqueDep);
}
@ -2021,7 +2023,7 @@ void ReflectCubeFeatHLSL::setTexData( Material::StageData &stageDat,
//****************************************************************************
RTLightingFeatHLSL::RTLightingFeatHLSL()
: mDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/lighting.hlsl" ))
: mDep(ShaderGen::smCommonShaderPath + String("/lighting.hlsl" ))
{
addDependency( &mDep );
}
@ -2234,7 +2236,7 @@ ShaderFeature::Resources RTLightingFeatHLSL::getResources( const MaterialFeature
//****************************************************************************
FogFeatHLSL::FogFeatHLSL()
: mFogDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/torque.hlsl" ))
: mFogDep(ShaderGen::smCommonShaderPath + String("/torque.hlsl" ))
{
addDependency( &mFogDep );
}
@ -2364,7 +2366,7 @@ ShaderFeature::Resources FogFeatHLSL::getResources( const MaterialFeatureData &f
//****************************************************************************
VisibilityFeatHLSL::VisibilityFeatHLSL()
: mTorqueDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/torque.hlsl" ))
: mTorqueDep(ShaderGen::smCommonShaderPath + String("/torque.hlsl" ))
{
addDependency( &mTorqueDep );
}
@ -2531,7 +2533,7 @@ void RenderTargetZeroHLSL::processPix( Vector<ShaderComponent*> &componentList,
//****************************************************************************
HDROutHLSL::HDROutHLSL()
: mTorqueDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/torque.hlsl" ))
: mTorqueDep(ShaderGen::smCommonShaderPath + String("/torque.hlsl" ))
{
addDependency( &mTorqueDep );
}
@ -2552,7 +2554,7 @@ void HDROutHLSL::processPix( Vector<ShaderComponent*> &componentList,
#include "T3D/fx/groundCover.h"
FoliageFeatureHLSL::FoliageFeatureHLSL()
: mDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/foliage.hlsl" ))
: mDep(ShaderGen::smCommonShaderPath + String("/foliage.hlsl" ))
{
addDependency( &mDep );
}
@ -2698,7 +2700,7 @@ void ParticleNormalFeatureHLSL::processVert(Vector<ShaderComponent*> &componentL
//****************************************************************************
ImposterVertFeatureHLSL::ImposterVertFeatureHLSL()
: mDep(String(Con::getVariable("$Core::CommonShaderPath")) + String("/imposter.hlsl" ))
: mDep(ShaderGen::smCommonShaderPath + String("/imposter.hlsl" ))
{
addDependency( &mDep );
}

View file

@ -49,6 +49,7 @@ MODULE_BEGIN( ShaderGen )
MODULE_END;
String ShaderGen::smCommonShaderPath(Con::getVariable("$Core::CommonShaderPath", "shaders/common"));
ShaderGen::ShaderGen()
{
@ -124,6 +125,8 @@ void ShaderGen::initShaderGen()
// Delete the auto-generated conditioner include file.
Torque::FS::Remove( "shadergen:/" + ConditionerFeature::ConditionerIncludeFileName );
smCommonShaderPath = String(Con::getVariable("$Core::CommonShaderPath", "shaders/common"));
}
void ShaderGen::generateShader( const MaterialFeatureData &featureData,

View file

@ -47,7 +47,6 @@
#include "materials/materialFeatureData.h"
#endif
/// Base class used by shaderGen to be API agnostic. Subclasses implement the various methods
/// in an API specific way.
class ShaderGenPrinter
@ -165,6 +164,8 @@ public:
void setComponentFactory(ShaderGenComponentFactory* factory) { mComponentFactory = factory; }
void setFileEnding(String ending) { mFileEnding = ending; }
static String smCommonShaderPath;
protected:
friend class ManagedSingleton<ShaderGen>;