Panagiotis Christopoulos Charitos 14 лет назад
Родитель
Сommit
3167f642ac
3 измененных файлов с 99 добавлено и 18 удалено
  1. 2 3
      src/Main.cpp
  2. 80 8
      src/Resources/Material2.cpp
  3. 17 7
      src/Resources/Material2.h

+ 2 - 3
src/Main.cpp

@@ -463,9 +463,8 @@ int main(int argc, char* argv[])
 {
 	try
 	{
-		boost::ptr_vector<Material2::FuncDefinition> defs;
-		Material2::parseShaderFileForFunctionDefinitions(
-			"lala.glsl", defs);
+		Material2 mtl;
+		mtl.load("lala.mtl");
 
 
 		return 0;

+ 80 - 8
src/Resources/Material2.cpp

@@ -30,7 +30,7 @@ boost::array<Material2::StdVarNameAndGlDataTypePair, Material2::SUV_NUM>
 	{"viewMat", GL_FLOAT_MAT4},
 	{"projectionMat", GL_FLOAT_MAT4},
 	{"modelViewMat", GL_FLOAT_MAT4},
-	{"ViewProjectionMat", GL_FLOAT_MAT4},
+	{"viewProjectionMat", GL_FLOAT_MAT4},
 	{"normalMat", GL_FLOAT_MAT3},
 	{"modelViewProjectionMat", GL_FLOAT_MAT4},
 	{"msNormalFai", GL_SAMPLER_2D},
@@ -63,6 +63,27 @@ Material2::BlendParam Material2::blendingParams[] =
 };
 
 
+//==============================================================================
+// Constructor                                                                 =
+//==============================================================================
+Material2::Material2()
+{
+	renderInBlendingStageFlag = false;
+	blendingSfactor = GL_ONE;
+	blendingDfactor = GL_ZERO;
+	depthTesting = true;
+	wireframe = false;
+	castsShadowFlag = true;
+}
+
+
+//==============================================================================
+// Destructor                                                                  =
+//==============================================================================
+Material2::~Material2()
+{}
+
+
 //==============================================================================
 // parseShaderFileForFunctionDefinitions                                       =
 //==============================================================================
@@ -423,12 +444,13 @@ void Material2::parseShaderProgramTag(const boost::property_tree::ptree& pt)
 {
 	using namespace boost::property_tree;
 
-	std::stringstream sprogSrc;
+	Vec<std::string> srcLines;
 
 	//
-	// inputs
+	// <includes></includes>
 	//
 	boost::ptr_vector<FuncDefinition> funcDefs;
+	Vec<std::string> includeLines;
 
 	const ptree& includesPt = pt.get_child("includes");
 	BOOST_FOREACH(const ptree::value_type& v, includesPt)
@@ -439,17 +461,67 @@ void Material2::parseShaderProgramTag(const boost::property_tree::ptree& pt)
 		}
 
 		const std::string& fname = v.second.data();
-		parseShaderFileForFunctionDefinitions(fname.c_str(), funcDefs);
+		//parseShaderFileForFunctionDefinitions(fname.c_str(), funcDefs);
+
+		includeLines.push_back("#pragma anki include \"" + fname + "\"");
+	}
+
+	std::sort(includeLines.begin(), includeLines.end(), compareStrings);
+	srcLines.assign(includeLines.begin(), includeLines.end());
+
+	//
+	// <ins></ins>
+	//
+	boost::optional<const ptree&> insPt = pt.get_child_optional("ins");
+	if(insPt)
+	{
+		BOOST_FOREACH(const ptree::value_type& v, insPt.get())
+		{
+			if(v.first != "include")
+			{
+				throw EXCEPTION("Expected include and not: " + v.first);
+			}
 
-		sprogSrc << "#pragma anki include " << fname << std::endl;
+			const std::string& name = v.second.data();
+		}
 	}
 
 	//
-	// ins
 	//
-	boost::optional<const ptree&> insPt = pt.get_optional("ins");
-	if(ins)
+	//
+	std::string src;
+	BOOST_FOREACH(const std::string& line, srcLines)
 	{
+		src += line + "\n";
+	}
+
+	std::cout << src << std::endl;
+}
+
 
+//==============================================================================
+// load                                                                        =
+//==============================================================================
+void Material2::load(const char* filename)
+{
+	try
+	{
+		using namespace boost::property_tree;
+		ptree pt;
+		read_xml(filename, pt);
+		parseMaterialTag(pt.get_child("material"));
+	}
+	catch(std::exception& e)
+	{
+		throw EXCEPTION("File \"" + filename + "\" failed: " + e.what());
 	}
 }
+
+
+//==============================================================================
+// compareStrings                                                              =
+//==============================================================================
+bool Material2::compareStrings(const std::string& a, const std::string& b)
+{
+	return a < b;
+}

+ 17 - 7
src/Resources/Material2.h

@@ -13,7 +13,7 @@
 class SProgAttribVar;
 class SProgUniVar;
 class ShaderProg;
-class MaterialUserInputVariable;
+class MaterialInputVariable;
 namespace Scanner {
 class Scanner;
 }
@@ -142,13 +142,17 @@ class Material2: private MaterialProperties
 		GETTER_R_BY_VAL(int, blendingDfactor, getBlendingDfactor)
 		GETTER_R_BY_VAL(bool, depthTesting, isDepthTestingEnabled)
 		GETTER_R_BY_VAL(bool, wireframe, isWireframeEnabled)
-		GETTER_R(boost::ptr_vector<MaterialUserInputVariable>, inVars,
-			getMaterialUserInputVariables)
+		GETTER_R(boost::ptr_vector<MaterialInputVariable>, inVars,
+			getMaterialInputVariables)
 
 		/// Access the base class just for copying in other classes
 		GETTER_R(MaterialProperties, *this, accessMaterialPropertiesBaseClass)
 
-		const ShaderProg& getShaderProgram() const {return *shaderProg;}
+		const ShaderProg& getColorPassShaderProgram() const
+			{return *cpShaderProg;}
+
+		const ShaderProg& getDepthPassShaderProgram() const
+			{return *dpShaderProg;}
 
 		/// Return NULL if the variable is not present in the shader program
 		const SProgAttribVar* getStandardAttributeVariable(
@@ -226,7 +230,7 @@ class Material2: private MaterialProperties
 		//======================================================================
 
 		/// The input variables
-		boost::ptr_vector<MaterialUserInputVariable> inVars;
+		boost::ptr_vector<MaterialInputVariable> inVars;
 
 		/// Used to check if a var exists in the shader program
 		static boost::array<StdVarNameAndGlDataTypePair, SAV_NUM>
@@ -238,8 +242,12 @@ class Material2: private MaterialProperties
 		boost::array<const SProgAttribVar*, SAV_NUM> stdAttribVars;
 		boost::array<const SProgUniVar*, SUV_NUM> stdUniVars;
 
-		/// The most important aspect of materials
-		RsrcPtr<ShaderProg> shaderProg;
+		/// The most important aspect of materials. Shader program for color
+		/// passes
+		RsrcPtr<ShaderProg> cpShaderProg;
+
+		/// Shader program for depth passes
+		RsrcPtr<ShaderProg> dpShaderProg;
 
 		/// Used to go from text to actual GL enum
 		static BlendParam blendingParams[];
@@ -272,6 +280,8 @@ class Material2: private MaterialProperties
 		/// Parse what is within the
 		/// @code <shaderProgram></shaderProgram> @endcode
 		void parseShaderProgramTag(const boost::property_tree::ptree& pt);
+
+		static bool compareStrings(const std::string& a, const std::string& b);
 };