Example #1
0
static void emitSingleInputVariable (EShLanguage lang, ETargetVersion targetVersion, const std::string& name, const std::string& ctor, EGlslSymbolType type, TPrecision prec, std::stringstream& attrib, std::stringstream& varying)
{
	// vertex shader: emit custom attributes
	if (lang == EShLangVertex && strncmp(name.c_str(), "gl_", 3) != 0)
	{
		int typeOffset = 0;
		
		// If the type is integer or bool based, we must convert to a float based
		// type. This is because GLSL does not allow int or bool based vertex attributes.
		//
		// NOTE: will need to be updated for more modern GLSL versions to allow this!
		if (type >= EgstInt && type <= EgstInt4)
			typeOffset += 4;
		if (type >= EgstBool && type <= EgstBool4)
			typeOffset += 8;
		
		attrib << GetVertexInputQualifier(targetVersion) << " " << getGLSLPrecisiontring(prec) << getTypeString((EGlslSymbolType)(type + typeOffset)) << " " << name << ";\n";
	}
	
	// fragment shader: emit varying
	if (lang == EShLangFragment)
	{
		AddFragmentInput(varying, targetVersion, prec, ctor, name);
	}
}
Example #2
0
/// Outputs the type of the symbol to the output buffer
///    \param out
///       The output buffer to write the type to
///    \param type
///       The type of the GLSL symbol to output
///    \param s
///       If it is a structure, a pointer to the structure to write out
void writeType (std::stringstream &out, EGlslSymbolType type, const GlslStruct *s, TPrecision precision)
{
	if (type >= EgstInt) // precision does not apply to void/bool
		out << getGLSLPrecisiontring (precision);

   switch (type)
   {
   case EgstVoid:  
   case EgstBool:  
   case EgstBool2: 
   case EgstBool3: 
   case EgstBool4: 
   case EgstInt:   
   case EgstInt2:  
   case EgstInt3:  
   case EgstInt4:  
   case EgstFloat: 
   case EgstFloat2:
   case EgstFloat3:
   case EgstFloat4:
   case EgstFloat2x2:
   case EgstFloat2x3:
   case EgstFloat2x4:
   case EgstFloat3x2:
   case EgstFloat3x3:
   case EgstFloat3x4:
   case EgstFloat4x2:
   case EgstFloat4x3:
   case EgstFloat4x4:
   case EgstSamplerGeneric: 
   case EgstSampler1D:
   case EgstSampler1DShadow:
   case EgstSampler2D:
   case EgstSampler2DShadow:
   case EgstSampler3D:
   case EgstSamplerCube:
   case EgstSamplerRect:
   case EgstSamplerRectShadow:
      out << typeString[type];
      break;
   case EgstStruct:
      if (s)
         out << s->getName();
      else
         out << "struct";
      break;
	case EgstTypeCount:
		break;
   }
}
Example #3
0
static inline void AddToVaryings (std::stringstream& s, TPrecision prec, const std::string& type, const std::string& name)
{
	if (strstr (name.c_str(), kUserVaryingPrefix) == name.c_str())
		s << "varying " << getGLSLPrecisiontring(prec) << type << " " << name << ";\n";
}
Example #4
0
static inline void AddFragmentInput (std::stringstream& s, ETargetVersion targetVersion, TPrecision prec, const std::string& type, const std::string& name)
{
	if (strstr (name.c_str(), kUserVaryingPrefix) == name.c_str())
		s << GetFragmentInputQualifier(targetVersion) << " " << getGLSLPrecisiontring(prec) << type << " " << name << ";\n";
}