Code: Select all
// So.. I've got this class called "Smart Shader"..
// It allows you to add Shader Parameters like Ints, FLoats etc to and instance of it at will
// so that ulitimately the Callback feeds only the relevant shader what is contained in the relevant "Smart Shader" class..
// Something similar to the "shader flags" used in the XML based post processor (water thing) form 2014..
// Only this time I don't use XML to add them, but rather in the code itself..
// I have a function like this..
// It "pushes_back" the String of the Parameter Name to an "const char*" array and also "pushes back"
// the Initial Value of the Variable (in this case float) to ANOTHER FLOAT array..
// I hope to keep these indices parrallel so that I can get a name from an index and a value from a name etc..
u32 SmartShader::AddVertexFloatParameter (const char* ParamName, f32 InitialVal)
{RunningVertexFloatIndex++;
VertexFloatParamNames.push_back(ParamName); // The resulting DROPPED INDEX should match the FOLLOWING push..
VertexFloatValues.push_back(InitialVal); // The resulting DROPPED INDEX should match the PREVIOUS push..
return RunningVertexFloatIndex - 1;
}
// So I go (as an example)..
SmartShaderCollection.AccessShader (2)-> AddVertexFloatParameter ("WaterYPosition", 0.0);
SmartShaderCollection.AccessShader (2)-> AddVertexFloatParameter ("WaterRed", 0.1);
SmartShaderCollection.AccessShader (2)-> AddVertexFloatParameter ("WaterGreen", 0.7);
SmartShaderCollection.AccessShader (2)-> AddVertexFloatParameter ("WaterBlue", 0.4);
// O.K.
// Now, I have a function..
u32 SmartShader::GetVertexFloatParamValueByName (const char* Name)
{
s32 AquiredIndex = VertexFloatParamNames.binary_search(Name);
if(AquiredIndex != -1)
return VertexFloatValues[AquiredIndex]; // Because The "Dropped Index" should be the same as for the "Names" ..
}
// Now I want to know what the value for "WaterBlue" is by using the the function..
f32 AquiredBlue = SmartShaderCollection.AccessShader (2)->GetVertexIntParamValueByName ("WaterBlue");
// Now "AquiredBlue" shoudl be "0.4" correct?
// Well It now is "0.0" the value of "WaterYPosition" as if the Indices somehow got REVERSED??
// Whats wrong..
// The main aim here is to to get the VALUE for a given parameter if I supply its NAME..
// The Smart Shaders CONTAINER looks like this..
class ShadersContainer
{public:
ShadersContainer();
~ShadersContainer();
void AddShader (char* VertFilename, char* FragFilename);
SmartShader* AccessShader(u32 Index);
private:
core::array <SmartShader> ShadersArray;
SmartShader TempShader;
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ShadersContainer:: ShadersContainer() { }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ShadersContainer::~ShadersContainer() { }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ShadersContainer::AddShader (char* VertFilename, char* FragFilename)
{
TempShader.SetVertexProgramFileName(VertFilename);
TempShader.SetFragmentShaderFileName(FragFilename);
ShadersArray.push_back(TempShader);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// This seems to work but I aint sure it is the best way..
SmartShader* ShadersContainer::AccessShader(u32 Index)
{return &ShadersArray[Index];
}