void ShaderVariableManager::loadStandards() {
	registerUniform(UniformDescription::MVP_MATRIX);
	registerUniform(UniformDescription::MV_MATRIX);
	registerUniform(UniformDescription::COLOR);
	registerUniform(UniformDescription::COLOR_TEXTURE);
	registerAttribute(AttributeDescription::POSITION);
	registerAttribute(AttributeDescription::COLOR);
	registerAttribute(AttributeDescription::NORMAL);
}
Beispiel #2
0
void Shader::registerUniforms(const std::string uniformNames[], int length)
{
	for(int i=0; i<length; i++)
	{
		registerUniform(uniformNames[i]); // Give it the actual value (dereferenced using [i])
	}
}
Beispiel #3
0
void ShaderProgram::parseUniform(const std::string &_s, const std::map <std::string,int> &_defines  )
{
 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;

 // first lets see what we need to parse
 if(_s.find("[") ==std::string::npos)
 {
   boost::char_separator<char> sep(" \t\r\n;");
   // generate our tokens based on the seperators above
   tokenizer tokens(_s, sep);
   // now we will copy them into a std::vector to process
   std::vector <std::string> data;
   // we do this as the tokenizer just does that so we can't get size etc
   data.assign(tokens.begin(),tokens.end());
   // uniform type name
   // we should as the glsl compiler will fail if we don't but best to be sure
   if(data.size() >=3)
   {
     registerUniform(data[2]);
   }
 }
 else
 {
   boost::char_separator<char> sep(" []\t\r\n;");
   // generate our tokens based on the seperators above
   tokenizer tokens(_s, sep);
   // now we will copy them into a std::vector to process
   std::vector <std::string> data;
   // we do this as the tokenizer just does that so we can't get size etc
   data.assign(tokens.begin(),tokens.end());
   // uniform type name
   // we should as the glsl compiler will fail if we don't but best to be sure
   if(data.size() >=3)
   {
     // so in this case data[3] is either a number or a constant
     int arraySize=0;
     // so we try and convert it if it's not a number
     try
     {
       arraySize=boost::lexical_cast<int> (data[3]);
     }
     // catch and lookup in the uniform array
     catch(boost::bad_lexical_cast)
     {
       std::map <std::string, int >::const_iterator def=_defines.find(data[3]);
       if(def !=_defines.end())
       {
         arraySize=def->second;
       }
     } // end catch
    // now loop and register each of the uniforms
     for(int i=0; i<arraySize; ++i)
     {
       // convert our uniform and register
       std::string uniform=boost::str(boost::format("%s[%d]") %data[2] %i);
       registerUniform(uniform);
     }
   }

 }
}