Ver Fonte

Material (wont compile)

Panagiotis Christopoulos Charitos há 14 anos atrás
pai
commit
c7d7919d30

+ 2 - 2
src/Main.cpp

@@ -44,7 +44,7 @@
 #include "Events/SceneColor.h"
 #include "Events/SceneColor.h"
 #include "Events/MainRendererPpsHdr.h"
 #include "Events/MainRendererPpsHdr.h"
 #include "Resources/ShaderProgramPrePreprocessor.h"
 #include "Resources/ShaderProgramPrePreprocessor.h"
-#include "Resources/Material2.h"
+#include "Resources/Material.h"
 #include "Core/ParallelJobs/Manager.h"
 #include "Core/ParallelJobs/Manager.h"
 #include "Renderer/Drawers/PhysDbgDrawer.h"
 #include "Renderer/Drawers/PhysDbgDrawer.h"
 
 
@@ -127,7 +127,7 @@ void init()
 {
 {
 	INFO("Other init...");
 	INFO("Other init...");
 
 
-	Material2 mtl;
+	Material mtl;
 	mtl.load("lala.mtl");
 	mtl.load("lala.mtl");
 
 
 	srand(unsigned(time(NULL)));
 	srand(unsigned(time(NULL)));

+ 1 - 1
src/Renderer/Drawers/SceneDrawer.h

@@ -29,7 +29,7 @@ class SceneDrawer
 			RPT_DEPTH
 			RPT_DEPTH
 		};
 		};
 
 
-		/// The one and only contructor
+		/// The one and only constructor
 		SceneDrawer(const Renderer& r_): r(r_) {}
 		SceneDrawer(const Renderer& r_): r(r_) {}
 
 
 		void renderRenderableNode(const RenderableNode& renderable,
 		void renderRenderableNode(const RenderableNode& renderable,

+ 227 - 375
src/Resources/Material.cpp

@@ -1,113 +1,39 @@
-#include <cstring>
+#include "Material.h"
+#include "MaterialVariable.h"
+#include "Misc/PropertyTree.h"
+#include "MaterialShaderProgramCreator.h"
+#include "Core/App.h"
+#include "Core/Globals.h"
+#include "ShaderProgram.h"
+#include <boost/foreach.hpp>
 #include <boost/property_tree/ptree.hpp>
 #include <boost/property_tree/ptree.hpp>
 #include <boost/property_tree/xml_parser.hpp>
 #include <boost/property_tree/xml_parser.hpp>
-#include <boost/foreach.hpp>
-#include <boost/lexical_cast.hpp>
-#include "Resources/Material.h"
-#include "Resources/Texture.h"
-#include "Resources/ShaderProgram.h"
-#include "Misc/PropertyTree.h"
+#include <boost/assign/list_of.hpp>
+#include <boost/functional/hash.hpp>
 
 
 
 
 //==============================================================================
 //==============================================================================
 // Statics                                                                     =
 // Statics                                                                     =
 //==============================================================================
 //==============================================================================
-boost::array<Material::StdVarNameAndGlDataTypePair, Material::SAV_NUM>
-	Material::stdAttribVarInfos =
-{{
-	{"position", GL_FLOAT_VEC3},
-	{"tangent", GL_FLOAT_VEC4},
-	{"normal", GL_FLOAT_VEC3},
-	{"texCoords", GL_FLOAT_VEC2}
-}};
-
-boost::array<Material::StdVarNameAndGlDataTypePair, Material::SUV_NUM>
-	Material::stdUniVarInfos =
-{{
-	{"modelMat", GL_FLOAT_MAT4},
-	{"viewMat", GL_FLOAT_MAT4},
-	{"projectionMat", GL_FLOAT_MAT4},
-	{"modelViewMat", GL_FLOAT_MAT4},
-	{"ViewProjectionMat", GL_FLOAT_MAT4},
-	{"normalMat", GL_FLOAT_MAT3},
-	{"modelViewProjectionMat", GL_FLOAT_MAT4},
-	{"msNormalFai", GL_SAMPLER_2D},
-	{"msDiffuseFai", GL_SAMPLER_2D},
-	{"msSpecularFai", GL_SAMPLER_2D},
-	{"msDepthFai", GL_SAMPLER_2D},
-	{"isFai", GL_SAMPLER_2D},
-	{"ppsPrePassFai", GL_SAMPLER_2D},
-	{"ppsPostPassFai", GL_SAMPLER_2D},
-	{"rendererSize", GL_FLOAT_VEC2},
-	{"sceneAmbientColor", GL_FLOAT_VEC3},
-	{"blurring", GL_FLOAT},
-}};
-
-Material::PreprocDefines Material::msGenericDefines[] =
-{
-	{"DIFFUSE_MAPPING", 'd'},
-	{"NORMAL_MAPPING", 'n'},
-	{"SPECULAR_MAPPING", 's'},
-	{"PARALLAX_MAPPING", 'p'},
-	{"ENVIRONMENT_MAPPING", 'e'},
-	{"ALPHA_TESTING", 'a'},
-	{0, 0}
-};
-
-Material::PreprocDefines Material::dpGenericDefines[] =
-{
-	{"ALPHA_TESTING", 'a'},
-	{0, 0}
-};
-
-
-//==============================================================================
-// Blending stuff                                                              =
-//==============================================================================
-
-struct BlendParam
-{
-	int glEnum;
-	const char* str;
-};
-
-static BlendParam blendingParams[] =
-{
-	{GL_ZERO, "GL_ZERO"},
-	{GL_ONE, "GL_ONE"},
-	{GL_DST_COLOR, "GL_DST_COLOR"},
-	{GL_ONE_MINUS_DST_COLOR, "GL_ONE_MINUS_DST_COLOR"},
-	{GL_SRC_ALPHA, "GL_SRC_ALPHA"},
-	{GL_ONE_MINUS_SRC_ALPHA, "GL_ONE_MINUS_SRC_ALPHA"},
-	{GL_DST_ALPHA, "GL_DST_ALPHA"},
-	{GL_ONE_MINUS_DST_ALPHA, "GL_ONE_MINUS_DST_ALPHA"},
-	{GL_SRC_ALPHA_SATURATE, "GL_SRC_ALPHA_SATURATE"},
-	{GL_SRC_COLOR, "GL_SRC_COLOR"},
-	{GL_ONE_MINUS_SRC_COLOR, "GL_ONE_MINUS_SRC_COLOR"},
-	{0, NULL}
-};
-
-static bool searchBlendEnum(const char* str, int& gl_enum)
-{
-	BlendParam* ptr = &blendingParams[0];
-	while(true)
-	{
-		if(ptr->str == NULL)
-		{
-			break;
-		}
 
 
-		if(!strcmp(ptr->str, str))
-		{
-			gl_enum = ptr->glEnum;
-			return true;
-		}
+// Dont make idiotic mistakes
+#define TXT_AND_ENUM(x) \
+	(#x, x)
 
 
-		++ptr;
-	}
 
 
-	return false;
-}
+ConstCharPtrHashMap<GLenum>::Type Material::txtToBlengGlEnum =
+	boost::assign::map_list_of
+	TXT_AND_ENUM(GL_ZERO)
+	TXT_AND_ENUM(GL_ONE)
+	TXT_AND_ENUM(GL_DST_COLOR)
+	TXT_AND_ENUM(GL_ONE_MINUS_DST_COLOR)
+	TXT_AND_ENUM(GL_SRC_ALPHA)
+	TXT_AND_ENUM(GL_ONE_MINUS_SRC_ALPHA)
+	TXT_AND_ENUM(GL_DST_ALPHA)
+	TXT_AND_ENUM(GL_ONE_MINUS_DST_ALPHA)
+	TXT_AND_ENUM(GL_SRC_ALPHA_SATURATE)
+	TXT_AND_ENUM(GL_SRC_COLOR)
+	TXT_AND_ENUM(GL_ONE_MINUS_SRC_COLOR);
 
 
 
 
 //==============================================================================
 //==============================================================================
@@ -124,6 +50,13 @@ Material::Material()
 }
 }
 
 
 
 
+//==============================================================================
+// Destructor                                                                  =
+//==============================================================================
+Material::~Material()
+{}
+
+
 //==============================================================================
 //==============================================================================
 // load                                                                        =
 // load                                                                        =
 //==============================================================================
 //==============================================================================
@@ -132,340 +65,259 @@ void Material::load(const char* filename)
 	try
 	try
 	{
 	{
 		using namespace boost::property_tree;
 		using namespace boost::property_tree;
-		ptree rpt;
-		read_xml(filename, rpt);
+		ptree pt;
+		read_xml(filename, pt);
+		parseMaterialTag(pt.get_child("material"));
+	}
+	catch(std::exception& e)
+	{
+		throw EXCEPTION("File \"" + filename + "\" failed: " + e.what());
+	}
+}
 
 
-		const ptree& pt = rpt.get_child("material");
 
 
-		//
-		// shaderProg
-		//
-		const ptree& shaderProgTree = pt.get_child("shaderProg");
+//==============================================================================
+// parseMaterialTag                                                            =
+//==============================================================================
+void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
+{
+	using namespace boost::property_tree;
 
 
-		boost::optional<std::string> file =
-			shaderProgTree.get_optional<std::string>("file");
-		boost::optional<const ptree&> customMsSProgTree =
-			shaderProgTree.get_child_optional("customMsSProg");
-		boost::optional<const ptree&> customDpSProgTree =
-			shaderProgTree.get_child_optional("customDpSProg");
+	//
+	// castsShadow
+	//
+	boost::optional<bool> shadow =
+		PropertyTree::getBoolOptional(pt, "castsShadow");
+	if(shadow)
+	{
+		castsShadowFlag = shadow.get();
+	}
 
 
-		// Just file
-		if(file)
-		{
-			shaderProg.loadRsrc(file.get().c_str());
-		}
-		// customMsSProg
-		else if(customMsSProgTree)
-		{
-			std::string source;
-
-			parseCustomShader(msGenericDefines, customMsSProgTree.get(),
-				source);
-			std::string shaderFilename =
-				ShaderProgram::createSrcCodeToCache("shaders/MsMpGeneric.glsl",
-					source.c_str());
-			shaderProg.loadRsrc(shaderFilename.c_str());
-		}
-		// customDpSProg
-		else if(customDpSProgTree)
-		{
-			std::string source;
-
-			parseCustomShader(dpGenericDefines, customDpSProgTree.get(),
-				source);
-			std::string shaderFilename =
-				ShaderProgram::createSrcCodeToCache("shaders/DpGeneric.glsl",
-					source.c_str());
-			shaderProg.loadRsrc(shaderFilename.c_str());
-		}
-		// Error
-		else
-		{
-			throw EXCEPTION("Expected file or customMsSProg or customDpSProg");
-		}
+	//
+	// renderInBlendingStage
+	//
+	boost::optional<bool> bs =
+		PropertyTree::getBoolOptional(pt, "renderInBlendingStage");
+	if(bs)
+	{
+		renderInBlendingStageFlag = bs.get();
+	}
 
 
-		//
-		// renderInBlendingStageFlag
-		//
-		boost::optional<bool> blendingStage_ =
-			PropertyTree::getBoolOptional(pt, "blendingStage");
-		if(blendingStage_)
+	//
+	// blendFunctions
+	//
+	boost::optional<const ptree&> blendFuncsTree =
+		pt.get_child_optional("blendFunctions");
+	if(blendFuncsTree)
+	{
+		// sFactor
 		{
 		{
-			renderInBlendingStageFlag = blendingStage_.get();
-		}
+			const std::string& tmp =
+				blendFuncsTree.get().get<std::string>("sFactor");
 
 
-		//
-		// blendFuncs
-		//
-		boost::optional<const ptree&> blendFuncsTree =
-			pt.get_child_optional("blendFuncs");
-		if(blendFuncsTree)
-		{
-			int glEnum;
+			ConstCharPtrHashMap<GLenum>::Type::const_iterator it =
+				txtToBlengGlEnum.find(tmp.c_str());
 
 
-			// sFactor
-			std::string sFactor_ =
-				blendFuncsTree.get().get<std::string>("sFactor");
-			if(!searchBlendEnum(sFactor_.c_str(), glEnum))
+			if(it == txtToBlengGlEnum.end())
 			{
 			{
-				throw EXCEPTION("Incorrect blending factor \"" +
-					sFactor_ + "\"");
+				throw EXCEPTION("Incorrect blend enum: " + tmp);
 			}
 			}
-			blendingSfactor = glEnum;
 
 
-			// dFactor
-			std::string dFactor_ =
+			blendingSfactor = it->second;
+		}
+
+		// dFactor
+		{
+			const std::string& tmp =
 				blendFuncsTree.get().get<std::string>("dFactor");
 				blendFuncsTree.get().get<std::string>("dFactor");
-			if(!searchBlendEnum(dFactor_.c_str(), glEnum))
+
+			ConstCharPtrHashMap<GLenum>::Type::const_iterator it =
+				txtToBlengGlEnum.find(tmp.c_str());
+
+			if(it == txtToBlengGlEnum.end())
 			{
 			{
-				throw EXCEPTION("Incorrect blending factor \"" + dFactor_ +
-					"\"");
+				throw EXCEPTION("Incorrect blend enum: " + tmp);
 			}
 			}
-			blendingDfactor = glEnum;
-		}
 
 
-		//
-		// depthTesting
-		//
-		boost::optional<bool> depthTesting_ =
-			PropertyTree::getBoolOptional(pt, "depthTesting");
-		if(depthTesting_)
-		{
-			depthTesting = depthTesting_.get();
+			blendingDfactor = it->second;
 		}
 		}
+	}
 
 
-		//
-		// wireframe
-		//
-		boost::optional<bool> wireframe_ =
-			PropertyTree::getBoolOptional(pt, "wireframe");
-		if(wireframe_)
-		{
-			wireframe = wireframe_.get();
-		}
+	//
+	// depthTesting
+	//
+	boost::optional<bool> dp =
+		PropertyTree::getBoolOptional(pt, "depthTesting");
+	if(dp)
+	{
+		depthTesting = dp.get();
+	}
 
 
-		//
-		// userDefinedVars
-		//
-		boost::optional<const ptree&> userDefinedVarsTree =
-			pt.get_child_optional("userDefinedVars");
-		if(userDefinedVarsTree)
-		{
-			BOOST_FOREACH(const ptree::value_type& v, userDefinedVarsTree.get())
-			{
-				if(v.first != "userDefinedVar")
-				{
-					throw EXCEPTION("Expected userDefinedVar and not " +
-						v.first);
-				}
+	//
+	// wireframe
+	//
+	boost::optional<bool> wf =
+		PropertyTree::getBoolOptional(pt, "wireframe");
+	if(wf)
+	{
+		wireframe = wf.get();
+	}
 
 
-				const ptree& userDefinedVarTree = v.second;
-				std::string varName =
-					userDefinedVarTree.get<std::string>("name");
+	//
+	// shaderProgram
+	//
+	MaterialShaderProgramCreator mspc(pt.get_child("shaderProgram"));
 
 
-				// check if the uniform exists
-				if(!shaderProg->uniformVariableExists(varName.c_str()))
-				{
-					throw EXCEPTION("The variable \"" + varName +
-						"\" is not an active uniform");
-				}
+	std::string cpSrc = "#define COLOR_PASS\n" + mspc.getShaderProgramSource();
+	std::string dpSrc = "#define DEPTH_PASS\n" + mspc.getShaderProgramSource();
 
 
-				const ptree& valueTree = userDefinedVarTree.get_child("value");
+	std::string cfile = createShaderProgSourceToCache(cpSrc);
+	std::string dfile = createShaderProgSourceToCache(dpSrc);
 
 
-				const UniformShaderProgramVariable& uni =
-					shaderProg->getUniformVariable(varName.c_str());
+	cpShaderProg.loadRsrc(cfile.c_str());
+	dpShaderProg.loadRsrc(dfile.c_str());
 
 
-				// read the values
-				switch(uni.getGlDataType())
-				{
-					// texture
-					case GL_SAMPLER_2D:
-					{
-						parseTextureTag(valueTree, uni);
-						break;
-					}
-					// float
-					case GL_FLOAT:
-						userDefinedVars.push_back(new MtlUserDefinedVar(uni,
-							PropertyTree::getFloat(valueTree)));
-						break;
-					// vec2
-					case GL_FLOAT_VEC2:
-						userDefinedVars.push_back(new MtlUserDefinedVar(uni,
-							PropertyTree::getVec2(valueTree)));
-						break;
-					// vec3
-					case GL_FLOAT_VEC3:
-						userDefinedVars.push_back(new MtlUserDefinedVar(uni,
-							PropertyTree::getVec3(valueTree)));
-						break;
-					// vec4
-					case GL_FLOAT_VEC4:
-						userDefinedVars.push_back(new MtlUserDefinedVar(uni,
-							PropertyTree::getVec4(valueTree)));
-						break;
-				};
-			} // end for all userDefinedVars
-		} // end userDefinedVars
-		initStdShaderVars();
-	}
-	catch(std::exception& e)
-	{
-		throw EXCEPTION("Material \"" + filename + "\": " + e.what());
-	}
+	INFO(cpShaderProg->getShaderInfoString());
+	INFO(dpShaderProg->getShaderInfoString());
+
+	//boost::optional<>
+	getVariables(pt.get_child("shaderProgram.inputs"));
 }
 }
 
 
 
 
 //==============================================================================
 //==============================================================================
-// parseTextureTag                                                             =
+// createShaderProgSourceToCache                                               =
 //==============================================================================
 //==============================================================================
-void Material::parseTextureTag(const boost::property_tree::ptree& pt,
-	const UniformShaderProgramVariable& uni)
+std::string Material::createShaderProgSourceToCache(const std::string& source)
 {
 {
-	boost::optional<std::string> texture =
-		pt.get_optional<std::string>("texture");
+	// Create the hash
+	boost::hash<std::string> stringHash;
+	std::size_t h = stringHash(source);
+	std::string prefix = boost::lexical_cast<std::string>(h);
 
 
-	boost::optional<std::string> fai =
-		pt.get_optional<std::string>("fai");
+	// Create path
+	boost::filesystem::path newfPathName =
+		AppSingleton::getInstance().getCachePath() / (prefix + ".glsl");
 
 
-	if(texture)
-	{
-		userDefinedVars.push_back(new MtlUserDefinedVar(uni, texture.get()));
-	}
-	else if(fai)
+
+	// If file not exists write it
+	if(!boost::filesystem::exists(newfPathName))
 	{
 	{
-		if(fai.get() == "msDepthFai")
-		{
-			userDefinedVars.push_back(new MtlUserDefinedVar(uni,
-				MtlUserDefinedVar::MS_DEPTH_FAI));
-		}
-		else if(fai.get() == "isFai")
-		{
-			userDefinedVars.push_back(new MtlUserDefinedVar(uni,
-				MtlUserDefinedVar::IS_FAI));
-		}
-		else if(fai.get() == "ppsPrePassFai")
-		{
-			userDefinedVars.push_back(new MtlUserDefinedVar(uni,
-				MtlUserDefinedVar::PPS_PRE_PASS_FAI));
-		}
-		else if(fai.get() == "ppsPostPassFai")
+		// If not create it
+		std::ofstream f(newfPathName.string().c_str());
+		if(!f.is_open())
 		{
 		{
-			userDefinedVars.push_back(new MtlUserDefinedVar(uni,
-				MtlUserDefinedVar::PPS_POST_PASS_FAI));
+			throw EXCEPTION("Cannot open file for writing: " +
+				newfPathName.string());
 		}
 		}
-		else
-		{
-			throw EXCEPTION("incorrect FAI");
-		}
-	}
-	else
-	{
-		throw EXCEPTION("texture or fai expected");
+
+		f.write(source.c_str(), source.length());
+		f.close();
 	}
 	}
+
+	return newfPathName.string();
 }
 }
 
 
 
 
 //==============================================================================
 //==============================================================================
-// initStdShaderVars                                                           =
+// getVariables                                                                =
 //==============================================================================
 //==============================================================================
-void Material::initStdShaderVars()
+void Material::getVariables(const boost::property_tree::ptree& pt)
 {
 {
-	// sanity checks
-	if(!shaderProg.get())
-	{
-		throw EXCEPTION("Material without shader program is like cake "
-			"without sugar");
-	}
+	using namespace boost::property_tree;
 
 
-	// the attributes
-	for(uint i = 0; i < SAV_NUM; i++)
+	BOOST_FOREACH(const ShaderProgramVariable& sv,
+		cpShaderProg->getVariables())
 	{
 	{
-		// if the var is not in the sProg then... bye
-		if(!shaderProg->attributeVariableExists(stdAttribVarInfos[i].varName))
-		{
-			stdAttribVars[i] = NULL;
-			continue;
-		}
+		const char* svName = sv.getName().c_str();
 
 
-		// set the std var
-		stdAttribVars[i] = &shaderProg->getAttributeVariable(
-			stdAttribVarInfos[i].varName);
-
-		// check if the shader has different GL data type from that it suppose
-		// to have
-		if(stdAttribVars[i]->getGlDataType() != stdAttribVarInfos[i].dataType)
+		// XXX
+		const ShaderProgramVariable* dpSv = NULL;
+		if(dpShaderProg->variableExists(svName))
 		{
 		{
-			throw EXCEPTION("The \"" + stdAttribVarInfos[i].varName +
-				"\" attribute var has incorrect GL data type "
-				"from the expected");
+			dpSv = &dpShaderProg->getVariable(svName);
 		}
 		}
-	}
 
 
-	// the uniforms
-	for(uint i = 0; i < SUV_NUM; i++)
-	{
-		// if the var is not in the sProg then... bye
-		if(!shaderProg->uniformVariableExists(stdUniVarInfos[i].varName))
-		{
-			stdUniVars[i] = NULL;
-			continue;
-		}
+		MaterialVariable* mv = NULL;
 
 
-		// set the std var
-		stdUniVars[i] =
-			&shaderProg->getUniformVariable(stdUniVarInfos[i].varName);
-
-		// check if the shader has different GL data type from that it
-		// suppose to have
-		if(stdUniVars[i]->getGlDataType() != stdUniVarInfos[i].dataType)
+		// Buildin or user defined?
+		if(BuildinMaterialVariable::isBuildin(svName))
 		{
 		{
-			throw EXCEPTION("The \"" + stdUniVarInfos[i].varName +
-				"\" uniform var has incorrect GL data type from the expected");
+			mv = new BuildinMaterialVariable(&sv, dpSv, svName);
 		}
 		}
-	}
-}
+		else
+		{
+			// Get uniforms
+			if(sv.getType() != ShaderProgramVariable::SVT_UNIFORM)
+			{
+				throw EXCEPTION("XXX"); // XXX
+			}
 
 
+			const UniformShaderProgramVariable* uniC =
+				static_cast<const UniformShaderProgramVariable*>(&sv);
 
 
-//==============================================================================
-// parseCustomShader                                                           =
-//==============================================================================
-void Material::parseCustomShader(const PreprocDefines defines[],
-	const boost::property_tree::ptree& pt, std::string& source)
-{
-	using namespace boost::property_tree;
+			const UniformShaderProgramVariable* uniD = NULL;
 
 
-	boost::optional<const ptree&> definesTree =
-		pt.get_child_optional("defines");
-	if(!definesTree)
-	{
-		return;
-	}
+			if(dpSv)
+			{
+				const UniformShaderProgramVariable* uniD =
+					static_cast<const UniformShaderProgramVariable*>(dpSv);
+			}
 
 
-	BOOST_FOREACH(const ptree::value_type& v, definesTree.get())
-	{
-		if(v.first != "define")
-		{
-			throw EXCEPTION("Found " + v.first + " in defines");
-		}
+			// Find the ptree that contains the value
+			const ptree* valuePt = NULL;
+			BOOST_FOREACH(const ptree::value_type& v, pt)
+			{
+				if(v.first != "input")
+				{
+					throw EXCEPTION("XXX"); // XXX
+				}
 
 
-		const std::string& define = v.second.data();
+				if(v.second.get<std::string>("name") == svName)
+				{
+					valuePt = &v.second.get_child("value");
+					break;
+				}
+			}
 
 
-		const PreprocDefines* def = defines;
-		while(def->switchName != NULL)
-		{
-			if (define == def->switchName)
+			if(valuePt == NULL)
 			{
 			{
-				break;
+				throw EXCEPTION("Variable not buildin and not found: " +
+					svName);
 			}
 			}
-			++def;
-		}
 
 
-		if(def->switchName == NULL)
-		{
-			throw EXCEPTION("Not acceptable define " + define);
+			// Get the value
+			switch(sv.getGlDataType())
+			{
+				// sampler2D
+				case GL_SAMPLER_2D:
+					mv = new UserMaterialVariable(uniC, uniD,
+						valuePt->get<std::string>("sampler2D").c_str());
+					break;
+				// float
+				case GL_FLOAT:
+					mv = new UserMaterialVariable(uniC, uniD,
+						PropertyTree::getFloat(*valuePt));
+					break;
+				// vec2
+				case GL_FLOAT_VEC2:
+					mv = new UserMaterialVariable(uniC, uniD,
+						PropertyTree::getVec2(*valuePt));
+					break;
+				// vec3
+				case GL_FLOAT_VEC3:
+					mv = new UserMaterialVariable(uniC, uniD,
+						PropertyTree::getVec3(*valuePt));
+					break;
+				// vec4
+				case GL_FLOAT_VEC4:
+					mv = new UserMaterialVariable(uniC, uniD,
+						PropertyTree::getVec4(*valuePt));
+					break;
+				// default is error
+				default:
+					ASSERT(0);
+			}
 		}
 		}
-
-		source += "#define " + define + "\n";
 	}
 	}
 }
 }

+ 124 - 183
src/Resources/Material.h

@@ -1,19 +1,30 @@
-#ifndef MATERIAL_H
-#define MATERIAL_H
+#ifndef MATERIAL_2_H
+#define MATERIAL_2_H
 
 
+#include "Util/Accessors.h"
+#include "Util/ConstCharPtrHashMap.h"
+#include "UserMaterialVariable.h"
+#include "BuildinMaterialVariable.h"
+#include "RsrcPtr.h"
+#include <GL/glew.h>
 #include <boost/ptr_container/ptr_vector.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
-#include <boost/property_tree/ptree_fwd.hpp>
 #include <boost/array.hpp>
 #include <boost/array.hpp>
-#include "Math/Math.h"
-#include "Resources/ShaderProgram.h"
-#include "RsrcPtr.h"
-#include "MtlUserDefinedVar.h"
+#include <boost/scoped_ptr.hpp>
+#include <boost/property_tree/ptree_fwd.hpp>
+
+
+class AttributeShaderProgramVariable;
+class UniformShaderProgramVariable;
+class ShaderProgram;
+namespace Scanner {
+class Scanner;
+}
 
 
 
 
 /// Contains a few properties that other classes may use
 /// Contains a few properties that other classes may use
-struct MaterialProps
+struct MaterialProperties
 {
 {
-	///< Used in depth passes of shadowmapping and not in other depth passes
+	/// Used in depth passes of shadowmapping and not in other depth passes
 	/// like EarlyZ
 	/// like EarlyZ
 	bool castsShadowFlag;
 	bool castsShadowFlag;
 	/// The entities with blending are being rendered in blending stage and
 	/// The entities with blending are being rendered in blending stage and
@@ -26,223 +37,153 @@ struct MaterialProps
 };
 };
 
 
 
 
-/// Mesh material Resource
+/// Material resource
 ///
 ///
-/// Every material keeps info of how to render a MeshNode. Among this info it
-/// keeps the locations of attribute and uniform variables. The variables can
-/// be standard or user defined. The standard variables have standard names
-/// inside the shader program and we dont have to mention them in the .mtl
-/// files. The material init func scoops the shader program for standard
-/// variables and keeps a pointer to the variable. The standard variables are
-/// like the GL build-in variables (that we cannot longer use on GL >3) with a
-/// few additions. The user defined variables are defined and values inside
-/// the .mtl file. The attribute variables cannot be user defined, the uniform
-/// on the other hand can.
+/// Every material keeps info of how to render a RenedrableNode. Using a node
+/// based logic it creates a couple of shader programs dynamically. One for
+/// color passes and one for depth. It also keeps two sets of material
+/// variables. The first is the build in and the second the user defined.
+/// During the renderer's shader setup the buildins will be set automatically,
+/// for the user variables the user needs to have its value in the material
+/// file. Some material variables may be present in both shader programs and
+/// some in only one of them
 ///
 ///
-/// XML file format:
+/// Material XML file format:
 /// @code
 /// @code
 /// <material>
 /// <material>
-/// 	<shaderProg>
-/// 		<file>path/file.glsl</file> |
-/// 		<customMsSProg>
-/// 			[<defines>
-/// 				<define>DEFINE_SOMETHING</define>
-/// 				...
-/// 				<define>DEFINE_SOMETHING_ELSE</define>
-/// 			</defines>]
-/// 		</customMsSProg> |
-/// 		<customDpSProg>...</customDpSProg>
-/// 	</shaderProg>
+/// 	<castsShadow>true | false</castsShadow>
 ///
 ///
-/// 	[<renderInBlendingStageFlag>true|false</renderInBlendingStageFlag>]
+/// 	<renderInBlendingStage>true | false</renderInBlendingStage>
 ///
 ///
-/// 	[<blendFuncs> *
+/// 	<blendFunctions>
 /// 		<sFactor>GL_SOMETHING</sFactor>
 /// 		<sFactor>GL_SOMETHING</sFactor>
 /// 		<dFactor>GL_SOMETHING</dFactor>
 /// 		<dFactor>GL_SOMETHING</dFactor>
-/// 	</blendFuncs>]
+/// 	</blendFunctions>
 ///
 ///
-/// 	[<depthTesting>true|false</depthTesting>]
+/// 	<depthTesting>true | false</depthTesting>
 ///
 ///
-/// 	[<wireframe>true|false</wireframe>]
+/// 	<wireframe>true | false</wireframe>
 ///
 ///
-/// 	[<castsShadowFlag>true|false</castsShadowFlag>]
+/// 	<shaderProgram>
+/// 		<includes>
+/// 			<include>file.glsl</include>
+/// 			<include>file2.glsl</include>
+/// 		</includes>
 ///
 ///
-/// 	[<userDefinedVars>
-/// 		<userDefinedVar>
-/// 			<name>varNameInShader</name>
-/// 			<value> **
-/// 				<texture>path/tex.png</texture> |
-/// 				<fai>msDepthFai | isFai | ppsPrePassFai |
-///                 	ppsPostPassFai</fai> |
-/// 				<float>0.0</float> |
-/// 				<vec2><x>0.0</x><y>0.0</y></vec2> |
-/// 				<vec3><x>0.0</x><y>0.0</y><z>0.0</z></vec3> |
-/// 				<vec4><x>0.0</x><y>0.0</y><z>0.0</z><w>0.0</w></vec4>
-/// 			</value>
-/// 		</userDefinedVar>
-/// 		...
-/// 		<userDefinedVar>...</userDefinedVar>
-/// 	</userDefinedVars>]
-/// </material>
+/// 		<inputs>
+/// 			<input> *
+/// 				<name>xx</name>
+/// 				<value>
+/// 					<float>0.0</float> |
+/// 					<vec2><x>0.0</x><y>0.0</y></vec2> |
+/// 					<vec3><x>0.0</x><y>0.0</y><z>0.0</z></vec3> |
+/// 					<vec4><x>0.0</x><y>0.0</y><z>0.0</z><w>0.0</w></vec4> |
+/// 					<sampler2D>path/to/image.tga</sampler2D>
+/// 				</value>
+/// 			</input>
+/// 		</inputs>
 ///
 ///
-/// *: Has nothing to do with the renderInBlendingStageFlag. blendFuncs can be
-///    in material stage as well
-/// **: Depends on the type of the var
+/// 		<operations>
+/// 			<operation>
+/// 				<id>x</id>
+/// 				<function>functionName</function>
+/// 				<arguments>
+/// 					<argument>xx</argument>
+/// 					<argument>yy</argument>
+/// 				</arguments>
+/// 			</operation>
+/// 		</operations>
+///
+/// 	</shaderProgram>
+/// </material>
 /// @endcode
 /// @endcode
-class Material: private MaterialProps
+/// *: For if the value is not set then the in variable will be build in or
+///    standard varying
+class Material: private MaterialProperties
 {
 {
 	public:
 	public:
-		/// Standard attribute variables that are acceptable inside the @ref
-		/// ShaderProg
-		enum StdAttribVars
-		{
-			SAV_POSITION,
-			SAV_TANGENT,
-			SAV_NORMAL,
-			SAV_TEX_COORDS,
-			SAV_NUM
-		};
-
-		/// Standard uniform variables. The Renderer sees what are applicable
-		/// and sets them
-		/// After changing the enum update also:
-		/// - Some statics in Material.cpp
-		/// - Renderer::setupShaderProg
-		/// - The generic material GLSL shader (maybe)
-		enum StdUniVars
-		{
-			// Matrices
-			SUV_MODEL_MAT,
-			SUV_VIEW_MAT,
-			SUV_PROJECTION_MAT,
-			SUV_MODELVIEW_MAT,
-			SUV_VIEWPROJECTION_MAT,
-			SUV_NORMAL_MAT,
-			SUV_MODELVIEWPROJECTION_MAT,
-			// FAIs (for materials in blending stage)
-			SUV_MS_NORMAL_FAI,
-			SUV_MS_DIFFUSE_FAI,
-			SUV_MS_SPECULAR_FAI,
-			SUV_MS_DEPTH_FAI,
-			SUV_IS_FAI,
-			SUV_PPS_PRE_PASS_FAI,
-			SUV_PPS_POST_PASS_FAI,
-			// Other
-			SUV_RENDERER_SIZE,
-			SUV_SCENE_AMBIENT_COLOR,
-			SUV_BLURRING,
-			// num
-			SUV_NUM ///< The number of standard uniform variables
-		};
+		//======================================================================
+		// Nested                                                              =
+		//======================================================================
+
+		typedef boost::ptr_vector<MaterialVariable> VarsContainer;
+
+		typedef boost::unordered_map<BuildinMaterialVariable::BuildinVariable,
+			BuildinMaterialVariable*> BuildinEnumToBuildinHashMap;
 
 
+		//======================================================================
+		// Methods                                                             =
+		//======================================================================
 
 
 		/// Initialize with default values
 		/// Initialize with default values
 		Material();
 		Material();
 
 
-		/// @see Resource::load
-		void load(const char* filename);
+		~Material();
 
 
 		/// @name Accessors
 		/// @name Accessors
 		/// @{
 		/// @{
-		const AttributeShaderProgramVariable* getStdAttribVar(
-			StdAttribVars id) const;
-		const UniformShaderProgramVariable* getStdUniVar(StdUniVars id) const;
-		const ShaderProgram& getShaderProg() const;
 		GETTER_R_BY_VAL(bool, castsShadowFlag, castsShadow)
 		GETTER_R_BY_VAL(bool, castsShadowFlag, castsShadow)
-		GETTER_R_BY_VAL(bool, renderInBlendingStageFlag, renderInBlendingStage)
+		GETTER_R_BY_VAL(bool, renderInBlendingStageFlag, rendersInBlendingStage)
 		GETTER_R_BY_VAL(int, blendingSfactor, getBlendingSfactor)
 		GETTER_R_BY_VAL(int, blendingSfactor, getBlendingSfactor)
 		GETTER_R_BY_VAL(int, blendingDfactor, getBlendingDfactor)
 		GETTER_R_BY_VAL(int, blendingDfactor, getBlendingDfactor)
 		GETTER_R_BY_VAL(bool, depthTesting, isDepthTestingEnabled)
 		GETTER_R_BY_VAL(bool, depthTesting, isDepthTestingEnabled)
 		GETTER_R_BY_VAL(bool, wireframe, isWireframeEnabled)
 		GETTER_R_BY_VAL(bool, wireframe, isWireframeEnabled)
-		GETTER_R(boost::ptr_vector<MtlUserDefinedVar>, userDefinedVars,
-			getUserDefinedVars)
+
+		GETTER_R(VarsContainer, mtlVars, getVariables)
+		GETTER_R(Vec<UserMaterialVariable*>, userMtlVars, getUserVariables)
 
 
 		/// Access the base class just for copying in other classes
 		/// Access the base class just for copying in other classes
-		GETTER_R(MaterialProps, *this, accessMaterialPropsBaseClass)
-		/// @}
+		GETTER_R(MaterialProperties, *this, accessMaterialPropertiesBaseClass)
 
 
-		/// @return Return true if the shader has references to texture
-		/// coordinates
-		bool hasTexCoords() const;
+		const ShaderProgram& getColorPassShaderProgram() const
+			{return *cpShaderProg;}
 
 
+		const ShaderProgram& getDepthPassShaderProgram() const
+			{return *dpShaderProg;}
+		/// @}
+
+		/// Return false if blendingSfactor is equal to GL_ONE and
+		/// blendingDfactor to GL_ZERO
 		bool isBlendingEnabled() const;
 		bool isBlendingEnabled() const;
 
 
-	private:
-		/// A simple pair-like structure
-		struct PreprocDefines
-		{
-			const char* switchName;
-			const char prefix;
-		};
-
-		/// Information for the standard shader program variables
-		struct StdVarNameAndGlDataTypePair
-		{
-			const char* varName;
-			GLenum dataType; ///< aka GL data type
-		};
-
-		boost::ptr_vector<MtlUserDefinedVar> userDefinedVars;
-
-		/// Material stage defines accepted in MsGeneric.glsl
-		static PreprocDefines msGenericDefines[];
-		/// Depth pass defines accepted in DpGeneric.glsl
-		static PreprocDefines dpGenericDefines[];
-		static boost::array<StdVarNameAndGlDataTypePair, SAV_NUM>
-			stdAttribVarInfos;
-		static boost::array<StdVarNameAndGlDataTypePair, SUV_NUM>
-			stdUniVarInfos;
-		boost::array<const AttributeShaderProgramVariable*, SAV_NUM>
-			stdAttribVars;
-		boost::array<const UniformShaderProgramVariable*, SUV_NUM> stdUniVars;
-		/// The most important aspect of materials
-		RsrcPtr<ShaderProgram> shaderProg;
-
-		/// The func sweeps all the variables of the shader program to find
-		/// standard shader program variables. It updates the stdAttribVars and
-		/// stdUniVars arrays.
-		/// @exception Exception
-		void initStdShaderVars();
-
-		/// Parse for a custom shader
-		/// @param[in] defines The acceptable defines array
-		/// @param[in] pt The property tree. Its not the root tree
-		/// @param[out] source The source to feed to
-		/// ShaderProgram::createSrcCodeToCache
-		static void parseCustomShader(const PreprocDefines defines[],
-			const boost::property_tree::ptree& pt,
-			std::string& source);
-
-		/// Parse the texture tag
-		void parseTextureTag(const boost::property_tree::ptree& pt,
-			const UniformShaderProgramVariable& uni);
-};
+		/// Load a material file
+		void load(const char* filename);
 
 
+	public: /// XXX
+		//======================================================================
+		// Members                                                             =
+		//======================================================================
 
 
-inline const AttributeShaderProgramVariable* Material::getStdAttribVar(
-	StdAttribVars id) const
-{
-	return stdAttribVars[id];
-}
+		/// All the material variables. Both buildins and user
+		VarsContainer mtlVars;
 
 
+		BuildinEnumToBuildinHashMap enumToBuildinMtlVar; ///< To find
 
 
-inline const UniformShaderProgramVariable* Material::getStdUniVar(
-	StdUniVars id) const
-{
-	return stdUniVars[id];
-}
+		Vec<UserMaterialVariable*> userMtlVars; ///< To iterate
 
 
+		/// The most important aspect of materials. Shader program for color
+		/// passes
+		RsrcPtr<ShaderProgram> cpShaderProg;
 
 
-inline const ShaderProgram& Material::getShaderProg() const
-{
-	return *shaderProg;
-}
+		/// Shader program for depth passes
+		RsrcPtr<ShaderProgram> dpShaderProg;
 
 
+		/// From "GL_ZERO" return GL_ZERO
+		static ConstCharPtrHashMap<GLenum>::Type txtToBlengGlEnum;
 
 
-inline bool Material::hasTexCoords() const
-{
-	return stdAttribVars[SAV_TEX_COORDS] != NULL;
-}
+		//======================================================================
+		// Methods                                                             =
+		//======================================================================
+
+		/// Parse what is within the @code <material></material> @endcode
+		void parseMaterialTag(const boost::property_tree::ptree& pt);
+
+		/// XXX
+		std::string createShaderProgSourceToCache(const std::string& source);
+
+		/// XXX
+		void getVariables(const boost::property_tree::ptree& pt);
+};
 
 
 
 
 inline bool Material::isBlendingEnabled() const
 inline bool Material::isBlendingEnabled() const

+ 0 - 323
src/Resources/Material2.cpp

@@ -1,323 +0,0 @@
-#include "Material2.h"
-#include "MaterialVariable.h"
-#include "Misc/PropertyTree.h"
-#include "MaterialShaderProgramCreator.h"
-#include "Core/App.h"
-#include "Core/Globals.h"
-#include "ShaderProgram.h"
-#include <boost/foreach.hpp>
-#include <boost/property_tree/ptree.hpp>
-#include <boost/property_tree/xml_parser.hpp>
-#include <boost/assign/list_of.hpp>
-#include <boost/functional/hash.hpp>
-
-
-//==============================================================================
-// Statics                                                                     =
-//==============================================================================
-
-// Dont make idiotic mistakes
-#define TXT_AND_ENUM(x) \
-	(#x, x)
-
-
-ConstCharPtrHashMap<GLenum>::Type Material2::txtToBlengGlEnum =
-	boost::assign::map_list_of
-	TXT_AND_ENUM(GL_ZERO)
-	TXT_AND_ENUM(GL_ONE)
-	TXT_AND_ENUM(GL_DST_COLOR)
-	TXT_AND_ENUM(GL_ONE_MINUS_DST_COLOR)
-	TXT_AND_ENUM(GL_SRC_ALPHA)
-	TXT_AND_ENUM(GL_ONE_MINUS_SRC_ALPHA)
-	TXT_AND_ENUM(GL_DST_ALPHA)
-	TXT_AND_ENUM(GL_ONE_MINUS_DST_ALPHA)
-	TXT_AND_ENUM(GL_SRC_ALPHA_SATURATE)
-	TXT_AND_ENUM(GL_SRC_COLOR)
-	TXT_AND_ENUM(GL_ONE_MINUS_SRC_COLOR);
-
-
-//==============================================================================
-// Constructor                                                                 =
-//==============================================================================
-Material2::Material2()
-{
-	renderInBlendingStageFlag = false;
-	blendingSfactor = GL_ONE;
-	blendingDfactor = GL_ZERO;
-	depthTesting = true;
-	wireframe = false;
-	castsShadowFlag = true;
-}
-
-
-//==============================================================================
-// Destructor                                                                  =
-//==============================================================================
-Material2::~Material2()
-{}
-
-
-//==============================================================================
-// 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());
-	}
-}
-
-
-//==============================================================================
-// parseMaterialTag                                                            =
-//==============================================================================
-void Material2::parseMaterialTag(const boost::property_tree::ptree& pt)
-{
-	using namespace boost::property_tree;
-
-	//
-	// castsShadow
-	//
-	boost::optional<bool> shadow =
-		PropertyTree::getBoolOptional(pt, "castsShadow");
-	if(shadow)
-	{
-		castsShadowFlag = shadow.get();
-	}
-
-	//
-	// renderInBlendingStage
-	//
-	boost::optional<bool> bs =
-		PropertyTree::getBoolOptional(pt, "renderInBlendingStage");
-	if(bs)
-	{
-		renderInBlendingStageFlag = bs.get();
-	}
-
-	//
-	// blendFunctions
-	//
-	boost::optional<const ptree&> blendFuncsTree =
-		pt.get_child_optional("blendFunctions");
-	if(blendFuncsTree)
-	{
-		// sFactor
-		{
-			const std::string& tmp =
-				blendFuncsTree.get().get<std::string>("sFactor");
-
-			ConstCharPtrHashMap<GLenum>::Type::const_iterator it =
-				txtToBlengGlEnum.find(tmp.c_str());
-
-			if(it == txtToBlengGlEnum.end())
-			{
-				throw EXCEPTION("Incorrect blend enum: " + tmp);
-			}
-
-			blendingSfactor = it->second;
-		}
-
-		// dFactor
-		{
-			const std::string& tmp =
-				blendFuncsTree.get().get<std::string>("dFactor");
-
-			ConstCharPtrHashMap<GLenum>::Type::const_iterator it =
-				txtToBlengGlEnum.find(tmp.c_str());
-
-			if(it == txtToBlengGlEnum.end())
-			{
-				throw EXCEPTION("Incorrect blend enum: " + tmp);
-			}
-
-			blendingDfactor = it->second;
-		}
-	}
-
-	//
-	// depthTesting
-	//
-	boost::optional<bool> dp =
-		PropertyTree::getBoolOptional(pt, "depthTesting");
-	if(dp)
-	{
-		depthTesting = dp.get();
-	}
-
-	//
-	// wireframe
-	//
-	boost::optional<bool> wf =
-		PropertyTree::getBoolOptional(pt, "wireframe");
-	if(wf)
-	{
-		wireframe = wf.get();
-	}
-
-	//
-	// shaderProgram
-	//
-	MaterialShaderProgramCreator mspc(pt.get_child("shaderProgram"));
-
-	std::string cpSrc = "#define COLOR_PASS\n" + mspc.getShaderProgramSource();
-	std::string dpSrc = "#define DEPTH_PASS\n" + mspc.getShaderProgramSource();
-
-	std::string cfile = createShaderProgSourceToCache(cpSrc);
-	std::string dfile = createShaderProgSourceToCache(dpSrc);
-
-	cpShaderProg.loadRsrc(cfile.c_str());
-	dpShaderProg.loadRsrc(dfile.c_str());
-
-	INFO(cpShaderProg->getShaderInfoString());
-	INFO(dpShaderProg->getShaderInfoString());
-
-	//boost::optional<>
-	getVariables(pt.get_child("shaderProgram.inputs"));
-}
-
-
-//==============================================================================
-// createShaderProgSourceToCache                                               =
-//==============================================================================
-std::string Material2::createShaderProgSourceToCache(const std::string& source)
-{
-	// Create the hash
-	boost::hash<std::string> stringHash;
-	std::size_t h = stringHash(source);
-	std::string prefix = boost::lexical_cast<std::string>(h);
-
-	// Create path
-	boost::filesystem::path newfPathName =
-		AppSingleton::getInstance().getCachePath() / (prefix + ".glsl");
-
-
-	// If file not exists write it
-	if(!boost::filesystem::exists(newfPathName))
-	{
-		// If not create it
-		std::ofstream f(newfPathName.string().c_str());
-		if(!f.is_open())
-		{
-			throw EXCEPTION("Cannot open file for writing: " +
-				newfPathName.string());
-		}
-
-		f.write(source.c_str(), source.length());
-		f.close();
-	}
-
-	return newfPathName.string();
-}
-
-
-//==============================================================================
-// getVariables                                                                =
-//==============================================================================
-void Material2::getVariables(const boost::property_tree::ptree& pt)
-{
-	using namespace boost::property_tree;
-
-	BOOST_FOREACH(const ShaderProgramVariable& sv,
-		cpShaderProg->getVariables())
-	{
-		const char* svName = sv.getName().c_str();
-
-		// XXX
-		const ShaderProgramVariable* dpSv = NULL;
-		if(dpShaderProg->variableExists(svName))
-		{
-			dpSv = &dpShaderProg->getVariable(svName);
-		}
-
-		MaterialVariable* mv = NULL;
-
-		// Buildin or user defined?
-		if(BuildinMaterialVariable::isBuildin(svName))
-		{
-			mv = new BuildinMaterialVariable(&sv, dpSv, svName);
-		}
-		else
-		{
-			// Get uniforms
-			if(sv.getType() != ShaderProgramVariable::SVT_UNIFORM)
-			{
-				throw EXCEPTION("XXX"); // XXX
-			}
-
-			const UniformShaderProgramVariable* uniC =
-				static_cast<const UniformShaderProgramVariable*>(&sv);
-
-			const UniformShaderProgramVariable* uniD = NULL;
-
-			if(dpSv)
-			{
-				const UniformShaderProgramVariable* uniD =
-					static_cast<const UniformShaderProgramVariable*>(dpSv);
-			}
-
-			// Find the ptree that contains the value
-			const ptree* valuePt = NULL;
-			BOOST_FOREACH(const ptree::value_type& v, pt)
-			{
-				if(v.first != "input")
-				{
-					throw EXCEPTION("XXX"); // XXX
-				}
-
-				if(v.second.get<std::string>("name") == svName)
-				{
-					valuePt = &v.second.get_child("value");
-					break;
-				}
-			}
-
-			if(valuePt == NULL)
-			{
-				throw EXCEPTION("Variable not buildin and not found: " +
-					svName);
-			}
-
-			// Get the value
-			switch(sv.getGlDataType())
-			{
-				// sampler2D
-				case GL_SAMPLER_2D:
-					mv = new UserMaterialVariable(uniC, uniD,
-						valuePt->get<std::string>("sampler2D").c_str());
-					break;
-				// float
-				case GL_FLOAT:
-					mv = new UserMaterialVariable(uniC, uniD,
-						PropertyTree::getFloat(*valuePt));
-					break;
-				// vec2
-				case GL_FLOAT_VEC2:
-					mv = new UserMaterialVariable(uniC, uniD,
-						PropertyTree::getVec2(*valuePt));
-					break;
-				// vec3
-				case GL_FLOAT_VEC3:
-					mv = new UserMaterialVariable(uniC, uniD,
-						PropertyTree::getVec3(*valuePt));
-					break;
-				// vec4
-				case GL_FLOAT_VEC4:
-					mv = new UserMaterialVariable(uniC, uniD,
-						PropertyTree::getVec4(*valuePt));
-					break;
-				// default is error
-				default:
-					ASSERT(0);
-			}
-		}
-	}
-}

+ 0 - 195
src/Resources/Material2.h

@@ -1,195 +0,0 @@
-#ifndef MATERIAL_2_H
-#define MATERIAL_2_H
-
-#include "Util/Accessors.h"
-#include "Util/ConstCharPtrHashMap.h"
-#include "UserMaterialVariable.h"
-#include "BuildinMaterialVariable.h"
-#include "RsrcPtr.h"
-#include <GL/glew.h>
-#include <boost/ptr_container/ptr_vector.hpp>
-#include <boost/array.hpp>
-#include <boost/scoped_ptr.hpp>
-#include <boost/property_tree/ptree_fwd.hpp>
-
-
-class AttributeShaderProgramVariable;
-class UniformShaderProgramVariable;
-class ShaderProgram;
-namespace Scanner {
-class Scanner;
-}
-
-
-/// Contains a few properties that other classes may use
-struct MaterialProperties
-{
-	/// Used in depth passes of shadowmapping and not in other depth passes
-	/// like EarlyZ
-	bool castsShadowFlag;
-	/// The entities with blending are being rendered in blending stage and
-	/// those without in material stage
-	bool renderInBlendingStageFlag;
-	int blendingSfactor; ///< Default GL_ONE
-	int blendingDfactor; ///< Default GL_ZERO
-	bool depthTesting;
-	bool wireframe;
-};
-
-
-/// Material resource
-///
-/// Every material keeps info of how to render a RenedrableNode. Using a node
-/// based logic it creates a couple of shader programs dynamically. One for
-/// color passes and one for depth. It also keeps two sets of material
-/// variables. The first is the build in and the second the user defined.
-/// During the renderer's shader setup the buildins will be set automatically,
-/// for the user variables the user needs to have its value in the material
-/// file. Some material variables may be present in both shader programs and
-/// some in only one of them
-///
-/// Material XML file format:
-/// @code
-/// <material>
-/// 	<castsShadow>true | false</castsShadow>
-///
-/// 	<renderInBlendingStage>true | false</renderInBlendingStage>
-///
-/// 	<blendFunctions>
-/// 		<sFactor>GL_SOMETHING</sFactor>
-/// 		<dFactor>GL_SOMETHING</dFactor>
-/// 	</blendFunctions>
-///
-/// 	<depthTesting>true | false</depthTesting>
-///
-/// 	<wireframe>true | false</wireframe>
-///
-/// 	<shaderProgram>
-/// 		<includes>
-/// 			<include>file.glsl</include>
-/// 			<include>file2.glsl</include>
-/// 		</includes>
-///
-/// 		<inputs>
-/// 			<input> *
-/// 				<name>xx</name>
-/// 				<value>
-/// 					<float>0.0</float> |
-/// 					<vec2><x>0.0</x><y>0.0</y></vec2> |
-/// 					<vec3><x>0.0</x><y>0.0</y><z>0.0</z></vec3> |
-/// 					<vec4><x>0.0</x><y>0.0</y><z>0.0</z><w>0.0</w></vec4> |
-/// 					<sampler2D>path/to/image.tga</sampler2D>
-/// 				</value>
-/// 			</input>
-/// 		</inputs>
-///
-/// 		<operations>
-/// 			<operation>
-/// 				<id>x</id>
-/// 				<function>functionName</function>
-/// 				<arguments>
-/// 					<argument>xx</argument>
-/// 					<argument>yy</argument>
-/// 				</arguments>
-/// 			</operation>
-/// 		</operations>
-///
-/// 	</shaderProgram>
-/// </material>
-/// @endcode
-/// *: For if the value is not set then the in variable will be build in or
-///    standard varying
-class Material2: private MaterialProperties
-{
-	public:
-		//======================================================================
-		// Nested                                                              =
-		//======================================================================
-
-		typedef boost::ptr_vector<MaterialVariable> VarsContainer;
-
-		typedef boost::unordered_map<BuildinMaterialVariable::BuildinVariable,
-			BuildinMaterialVariable*> BuildinEnumToBuildinHashMap;
-
-		//======================================================================
-		// Methods                                                             =
-		//======================================================================
-
-		/// Initialize with default values
-		Material2();
-
-		~Material2();
-
-		/// @name Accessors
-		/// @{
-		GETTER_R_BY_VAL(bool, castsShadowFlag, castsShadow)
-		GETTER_R_BY_VAL(bool, renderInBlendingStageFlag, rendersInBlendingStage)
-		GETTER_R_BY_VAL(int, blendingSfactor, getBlendingSfactor)
-		GETTER_R_BY_VAL(int, blendingDfactor, getBlendingDfactor)
-		GETTER_R_BY_VAL(bool, depthTesting, isDepthTestingEnabled)
-		GETTER_R_BY_VAL(bool, wireframe, isWireframeEnabled)
-
-		GETTER_R(VarsContainer, mtlVars, getVariables)
-		GETTER_R(Vec<UserMaterialVariable*>, userMtlVars, getUserVariables)
-
-		/// Access the base class just for copying in other classes
-		GETTER_R(MaterialProperties, *this, accessMaterialPropertiesBaseClass)
-
-		const ShaderProgram& getColorPassShaderProgram() const
-			{return *cpShaderProg;}
-
-		const ShaderProgram& getDepthPassShaderProgram() const
-			{return *dpShaderProg;}
-		/// @}
-
-		/// Return false if blendingSfactor is equal to GL_ONE and
-		/// blendingDfactor to GL_ZERO
-		bool isBlendingEnabled() const;
-
-		/// Load a material file
-		void load(const char* filename);
-
-	public: /// XXX
-		//======================================================================
-		// Members                                                             =
-		//======================================================================
-
-		/// All the material variables. Both buildins and user
-		VarsContainer mtlVars;
-
-		BuildinEnumToBuildinHashMap enumToBuildinMtlVar; ///< To find
-
-		Vec<UserMaterialVariable*> userMtlVars; ///< To iterate
-
-		/// The most important aspect of materials. Shader program for color
-		/// passes
-		RsrcPtr<ShaderProgram> cpShaderProg;
-
-		/// Shader program for depth passes
-		RsrcPtr<ShaderProgram> dpShaderProg;
-
-		/// From "GL_ZERO" return GL_ZERO
-		static ConstCharPtrHashMap<GLenum>::Type txtToBlengGlEnum;
-
-		//======================================================================
-		// Methods                                                             =
-		//======================================================================
-
-		/// Parse what is within the @code <material></material> @endcode
-		void parseMaterialTag(const boost::property_tree::ptree& pt);
-
-		/// XXX
-		std::string createShaderProgSourceToCache(const std::string& source);
-
-		/// XXX
-		void getVariables(const boost::property_tree::ptree& pt);
-};
-
-
-inline bool Material2::isBlendingEnabled() const
-{
-	return blendingSfactor != GL_ONE || blendingDfactor != GL_ZERO;
-}
-
-
-#endif

+ 0 - 1
src/Resources/Model.h

@@ -18,7 +18,6 @@
 /// 		<modelPatch>
 /// 		<modelPatch>
 /// 			<mesh>path/to/mesh.mesh</mesh>
 /// 			<mesh>path/to/mesh.mesh</mesh>
 /// 			<material>path/to/material.mtl</material>
 /// 			<material>path/to/material.mtl</material>
-/// 			<dpMaterial>path/to/dp.mtl</dpMaterial>
 /// 		</modelPatch>
 /// 		</modelPatch>
 /// 		...
 /// 		...
 /// 		<modelPatch>...</modelPatch>
 /// 		<modelPatch>...</modelPatch>

+ 1 - 1
src/Resources/ModelPatch.cpp

@@ -4,7 +4,7 @@
 
 
 
 
 //==============================================================================
 //==============================================================================
-// Constructors & Destructors                                                  =
+// Constructors & Destructor                                                   =
 //==============================================================================
 //==============================================================================
 
 
 ModelPatch::ModelPatch()
 ModelPatch::ModelPatch()

+ 2 - 5
src/Resources/ModelPatch.h

@@ -16,14 +16,12 @@ class ModelPatch
 		~ModelPatch();
 		~ModelPatch();
 
 
 		/// Load the resources
 		/// Load the resources
-		void load(const char* meshFName, const char* mtlFName,
-			const char* dpMtlFName);
+		void load(const char* meshFName, const char* mtlFName);
 
 
 		/// @name Accessors
 		/// @name Accessors
 		/// @{
 		/// @{
 		const Mesh& getMesh() const {return *mesh;}
 		const Mesh& getMesh() const {return *mesh;}
-		const Material& getCpMtl() const {return *cpMtl;}
-		const Material& getDpMtl() const {return *dpMtl;}
+		const Material& getMaterial() const {return *cpMtl;}
 		/// @}
 		/// @}
 
 
 		/// This only checks the mesh for vertex weights
 		/// This only checks the mesh for vertex weights
@@ -38,7 +36,6 @@ class ModelPatch
 	private:
 	private:
 		RsrcPtr<Mesh> mesh; ///< The geometry
 		RsrcPtr<Mesh> mesh; ///< The geometry
 		RsrcPtr<Material> cpMtl; ///< Material for MS and BS
 		RsrcPtr<Material> cpMtl; ///< Material for MS and BS
-		RsrcPtr<Material> dpMtl; ///< Material for depth passes
 
 
 		/// Checks if a mesh and a material are compatible
 		/// Checks if a mesh and a material are compatible
 		static void doMeshAndMtlSanityChecks(const Mesh& mesh,
 		static void doMeshAndMtlSanityChecks(const Mesh& mesh,

+ 0 - 62
src/Resources/MtlUserDefinedVar.cpp

@@ -1,62 +0,0 @@
-#include "MtlUserDefinedVar.h"
-#include "Resources/Texture.h"
-
-
-//==============================================================================
-// Constructors                                                                =
-//==============================================================================
-
-template<>
-MtlUserDefinedVar::MtlUserDefinedVar(const UniformShaderProgramVariable& var, const Fai& fai_)
-:	sProgVar(var)
-{
-	ASSERT(var.getGlDataType() == GL_SAMPLER_2D);
-	data = fai_;
-}
-
-
-template<>
-MtlUserDefinedVar::MtlUserDefinedVar(const UniformShaderProgramVariable& var, const float& f)
-:	sProgVar(var)
-{
-	ASSERT(var.getGlDataType() == GL_FLOAT);
-	data = f;
-}
-
-
-template<>
-MtlUserDefinedVar::MtlUserDefinedVar(const UniformShaderProgramVariable& var, const Vec2& v)
-:	sProgVar(var)
-{
-	ASSERT(var.getGlDataType() == GL_FLOAT_VEC2);
-	data = v;
-}
-
-
-template<>
-MtlUserDefinedVar::MtlUserDefinedVar(const UniformShaderProgramVariable& var, const Vec3& v)
-:	sProgVar(var)
-{
-	ASSERT(var.getGlDataType() == GL_FLOAT_VEC3);
-	data = v;
-}
-
-
-template<>
-MtlUserDefinedVar::MtlUserDefinedVar(const UniformShaderProgramVariable& var, const Vec4& v)
-:	sProgVar(var)
-{
-	ASSERT(var.getGlDataType() == GL_FLOAT_VEC4);
-	data = v;
-}
-
-
-template<>
-MtlUserDefinedVar::MtlUserDefinedVar(const UniformShaderProgramVariable& var,
-	const std::string& texFilename)
-:	sProgVar(var)
-{
-	ASSERT(var.getGlDataType() == GL_SAMPLER_2D);
-	data = RsrcPtr<Texture>();
-	boost::get<RsrcPtr<Texture> >(data).loadRsrc(texFilename.c_str());
-}

+ 0 - 56
src/Resources/MtlUserDefinedVar.h

@@ -1,56 +0,0 @@
-#ifndef MTL_USER_DEFINED_VAR_H
-#define MTL_USER_DEFINED_VAR_H
-
-#include <boost/variant.hpp>
-#include "Util/Accessors.h"
-#include "Math/Math.h"
-#include "UniformShaderProgramVariable.h"
-#include "RsrcPtr.h"
-
-
-class Texture;
-
-
-/// Class for user defined material variables that will be passes in to the
-/// shader
-class MtlUserDefinedVar
-{
-	public:
-		/// The renderer's FAIs
-		enum Fai
-		{
-			MS_DEPTH_FAI, ///< Avoid it in MS
-			IS_FAI, ///< Use it anywhere
-			PPS_PRE_PASS_FAI, ///< Avoid it in BS
-			PPS_POST_PASS_FAI ///< Use it anywhere
-		};
-
-		/// The data union
-		typedef boost::variant<float, Vec2, Vec3, Vec4, RsrcPtr<Texture>, Fai>
-			DataVariant;
-
-		/// Contructor
-		/// @tparam Type Can be std::string, Fai, float, Vec2, Vec3, Vec4
-		template<typename Type>
-		MtlUserDefinedVar(const UniformShaderProgramVariable& sProgVar, const Type& val);
-
-		/// @name Accessors
-		/// @{
-		const UniformShaderProgramVariable& getUniVar() const {return sProgVar;}
-
-		const DataVariant& getDataVariant() const {return data;}
-
-		/// Get the value of the variant
-		/// @exception boost::exception when you try to get the incorrect data
-		/// type
-		template<typename Type>
-		const Type& get() const {return boost::get<Type>(data);}
-		/// @}
-
-	private:
-		DataVariant data;
-		const UniformShaderProgramVariable& sProgVar; ///< Know a part of the ShaderProg resource
-};
-
-
-#endif

+ 30 - 20
src/Scene/MaterialRuntime.cpp

@@ -1,37 +1,47 @@
-#include <boost/foreach.hpp>
 #include "MaterialRuntime.h"
 #include "MaterialRuntime.h"
 #include "Resources/Material.h"
 #include "Resources/Material.h"
-#include "Util/Exception.h"
+#include "UserMaterialVariableRuntime.h"
+#include <boost/foreach.hpp>
 
 
 
 
 //==============================================================================
 //==============================================================================
 // Constructor                                                                 =
 // Constructor                                                                 =
 //==============================================================================
 //==============================================================================
-MaterialRuntime::MaterialRuntime(const Material& mtl_):
-	mtl(mtl_)
+MaterialRuntime::MaterialRuntime(const Material& mtl_)
+:	mtl(mtl_)
 {
 {
-	MaterialProps& me = *this;
-	const MaterialProps& he = mtl.accessMaterialPropsBaseClass();
+	// Copy props
+	MaterialProperties& me = *this;
+	const MaterialProperties& he = mtl.accessMaterialPropertiesBaseClass();
 	me = he;
 	me = he;
 
 
-	BOOST_FOREACH(const MtlUserDefinedVar& udv, mtl.getUserDefinedVars())
+	// Create vars
+	BOOST_FOREACH(const UserMaterialVariable* var, mtl.getUserVariables())
 	{
 	{
-		MaterialRuntimeUserDefinedVar* udvr = new MaterialRuntimeUserDefinedVar(udv);
-		userDefVars.push_back(udvr);
-		userDefVarsHashMap[udvr->getName().c_str()] = udvr;
+		UserMaterialVariableRuntime* varr =
+			new UserMaterialVariableRuntime(*var);
+		vars.push_back(varr);
+		varNameToVar[varr->getUserMaterialVariable().getName().c_str()] = varr;
 	}
 	}
 }
 }
 
 
 
 
 //==============================================================================
 //==============================================================================
-// getUserDefinedVarByName                                                     =
+// Destructor                                                                  =
+//==============================================================================
+MaterialRuntime::~MaterialRuntime()
+{}
+
+
+//==============================================================================
+// findVariableByName                                                          =
 //==============================================================================
 //==============================================================================
-MaterialRuntimeUserDefinedVar& MaterialRuntime::getUserDefinedVarByName(
+UserMaterialVariableRuntime& MaterialRuntime::findVariableByName(
 	const char* name)
 	const char* name)
 {
 {
-	ConstCharPtrHashMap<MaterialRuntimeUserDefinedVar*>::Type::iterator it =
-		userDefVarsHashMap.find(name);
-	if(it == userDefVarsHashMap.end())
+	ConstCharPtrHashMap<UserMaterialVariableRuntime*>::Type::iterator it =
+		varNameToVar.find(name);
+	if(it == varNameToVar.end())
 	{
 	{
 		throw EXCEPTION("Cannot get user defined variable with name \"" +
 		throw EXCEPTION("Cannot get user defined variable with name \"" +
 			name + '\"');
 			name + '\"');
@@ -41,14 +51,14 @@ MaterialRuntimeUserDefinedVar& MaterialRuntime::getUserDefinedVarByName(
 
 
 
 
 //==============================================================================
 //==============================================================================
-// getUserDefinedVarByName                                                     =
+// findVariableByName                                                          =
 //==============================================================================
 //==============================================================================
-const MaterialRuntimeUserDefinedVar& MaterialRuntime::getUserDefinedVarByName(
+const UserMaterialVariableRuntime& MaterialRuntime::findVariableByName(
 	const char* name) const
 	const char* name) const
 {
 {
-	ConstCharPtrHashMap<MaterialRuntimeUserDefinedVar*>::Type::const_iterator
-		it = userDefVarsHashMap.find(name);
-	if(it == userDefVarsHashMap.end())
+	ConstCharPtrHashMap<UserMaterialVariableRuntime*>::Type::const_iterator
+		it = varNameToVar.find(name);
+	if(it == varNameToVar.end())
 	{
 	{
 		throw EXCEPTION("Cannot get user defined variable with name \"" +
 		throw EXCEPTION("Cannot get user defined variable with name \"" +
 			name + '\"');
 			name + '\"');

+ 36 - 86
src/Scene/MaterialRuntime.h

@@ -1,125 +1,75 @@
-#ifndef MATERIAL_RUNTIME_H
-#define MATERIAL_RUNTIME_H
+#ifndef MATERIAL_RUNTIME_2_H
+#define MATERIAL_RUNTIME_2_H
 
 
-#include <boost/ptr_container/ptr_vector.hpp>
-#include "MaterialRuntimeUserDefinedVar.h"
+#include "Resources/Material.h"
 #include "Util/Accessors.h"
 #include "Util/Accessors.h"
 #include "Util/ConstCharPtrHashMap.h"
 #include "Util/ConstCharPtrHashMap.h"
-#include "Resources/Material.h"
+#include <boost/ptr_container/ptr_vector.hpp>
+
+
+class UserMaterialVariableRuntime;
+class Material;
 
 
 
 
 /// One layer above material resource
 /// One layer above material resource
-class MaterialRuntime: private MaterialProps
+class MaterialRuntime: private MaterialProperties
 {
 {
 	public:
 	public:
 		/// A type
 		/// A type
-		typedef boost::ptr_vector<MaterialRuntimeUserDefinedVar>
-			MaterialRuntimeUserDefinedVarContainer;
+		typedef boost::ptr_vector<UserMaterialVariableRuntime>
+			VariablesContainer;
 
 
-		/// The one and only contructor
+		/// @name Constructors & destructors
+		/// @{
 		MaterialRuntime(const Material& mtl);
 		MaterialRuntime(const Material& mtl);
+		~MaterialRuntime();
+		/// @}
 
 
 		/// @name Accessors
 		/// @name Accessors
 		/// @{
 		/// @{
-		GETTER_RW(MaterialRuntimeUserDefinedVarContainer, userDefVars,
-			getUserDefinedVars)
+		GETTER_SETTER_BY_VAL(bool, castsShadowFlag, castsShadow, setCastShadow)
+		GETTER_SETTER_BY_VAL(bool, renderInBlendingStageFlag,
+			rendersInBlendingStage, setRendersInBlendingStage)
+		GETTER_SETTER_BY_VAL(int, blendingSfactor, getBlendingSfactor,
+			setBlendingSFactor)
+		GETTER_SETTER_BY_VAL(int, blendingDfactor, getBlendingDfactor,
+			setBlendingDFactor)
+		GETTER_SETTER_BY_VAL(bool, depthTesting, isDepthTestingEnabled,
+			setDepthTestingEnabled)
+		GETTER_SETTER_BY_VAL(bool, wireframe, isWireframeEnabled,
+			setWireframeEnabled)
+
+		GETTER_RW(VariablesContainer, vars, getVariables)
+		GETTER_R(Material, mtl, getMaterial);
+		/// @}
 
 
 		/// Find MaterialRuntimeUserDefinedVar variable. On failure it throws
 		/// Find MaterialRuntimeUserDefinedVar variable. On failure it throws
 		/// an exception
 		/// an exception
 		/// @param[in] name The name of the var
 		/// @param[in] name The name of the var
 		/// @return It returns a MaterialRuntimeUserDefinedVar
 		/// @return It returns a MaterialRuntimeUserDefinedVar
 		/// @exception Exception
 		/// @exception Exception
-		MaterialRuntimeUserDefinedVar& getUserDefinedVarByName(
+		UserMaterialVariableRuntime& findVariableByName(
 			const char* name);
 			const char* name);
 
 
 		/// The const version of getUserDefinedVarByName
 		/// The const version of getUserDefinedVarByName
 		/// @see getUserDefinedVarByName
 		/// @see getUserDefinedVarByName
-		const MaterialRuntimeUserDefinedVar& getUserDefinedVarByName(
+		const UserMaterialVariableRuntime& findVariableByName(
 			const char* name) const;
 			const char* name) const;
 
 
-		/// Get the resource
-		const Material& getMaterial() const {return mtl;}
-
-		/// Find var and set its value
-		template<typename Type>
-		void setUserDefVarValue(const char* name, const Type& value);
-
-		/// Find var and set its value
-		template<typename Type>
-		const Type& getUserDefVarValue(const char* name) const;
-
-		/// The non const version of getUserDefVarValue
-		template<typename Type>
-		Type& getUserDefVarValue(const char* name);
-
-		GETTER_SETTER_BY_VAL(bool, castsShadowFlag, castsShadow, setCastsShadow)
-		GETTER_SETTER_BY_VAL(bool, renderInBlendingStageFlag,
-			renderInBlendingStage, setRenderInBlendingStage)
-		GETTER_SETTER_BY_VAL(int, blendingSfactor, getBlendingSfactor,
-			setBlendingSfactor)
-		GETTER_SETTER_BY_VAL(int, blendingDfactor, getBlendingDfactor,
-			setBlendingDfactor)
-		GETTER_SETTER_BY_VAL(bool, depthTesting, isDepthTestingEnabled,
-			setDepthTestingEnabled)
-		GETTER_SETTER_BY_VAL(bool, wireframe, isWireframeEnabled,
-			setWireframeEnabled)
-
-		const AttributeShaderProgramVariable* getStdAttribVar(
-			Material::StdAttribVars id) const;
-		const UniformShaderProgramVariable*
-			getStdUniVar(Material::StdUniVars id) const;
-		const ShaderProgram& getShaderProg() const {return mtl.getShaderProg();}
-		/// @}
-
 		bool isBlendingEnabled() const;
 		bool isBlendingEnabled() const;
 
 
 	private:
 	private:
 		const Material& mtl; ///< The resource
 		const Material& mtl; ///< The resource
-		MaterialRuntimeUserDefinedVarContainer userDefVars;
-		/// For fast finding the variables
-		ConstCharPtrHashMap<MaterialRuntimeUserDefinedVar*>::Type
-			userDefVarsHashMap;
+		VariablesContainer vars;
+		ConstCharPtrHashMap<UserMaterialVariableRuntime*>::Type
+			varNameToVar;
 };
 };
 
 
 
 
-template<typename Type>
-const Type& MaterialRuntime::getUserDefVarValue(const char* name) const
-{
-	return getUserDefinedVarByName(name).get<Type>();
-}
-
-
-template<typename Type>
-Type& MaterialRuntime::getUserDefVarValue(const char* name)
-{
-	return getUserDefinedVarByName(name).get<Type>();
-}
-
-
-template<typename Type>
-void MaterialRuntime::setUserDefVarValue(const char* name, const Type& value)
-{
-	getUserDefinedVarByName(name).set<Type>(value);
-}
-
-
-inline const AttributeShaderProgramVariable* MaterialRuntime::getStdAttribVar(
-	Material::StdAttribVars id) const
-{
-	return mtl.getStdAttribVar(id);
-}
-
-
-inline const UniformShaderProgramVariable* MaterialRuntime::getStdUniVar(
-	Material::StdUniVars id) const
-{
-	return mtl.getStdUniVar(id);
-}
-
-
 inline bool MaterialRuntime::isBlendingEnabled() const
 inline bool MaterialRuntime::isBlendingEnabled() const
 {
 {
 	return blendingSfactor != GL_ONE || blendingDfactor != GL_ZERO;
 	return blendingSfactor != GL_ONE || blendingDfactor != GL_ZERO;
 }
 }
 
 
+
 #endif
 #endif

+ 0 - 67
src/Scene/MaterialRuntime2.cpp

@@ -1,67 +0,0 @@
-#include "MaterialRuntime2.h"
-#include "Resources/Material2.h"
-#include "UserMaterialVariableRuntime.h"
-#include <boost/foreach.hpp>
-
-
-//==============================================================================
-// Constructor                                                                 =
-//==============================================================================
-MaterialRuntime2::MaterialRuntime2(const Material2& mtl_)
-:	mtl(mtl_)
-{
-	// Copy props
-	MaterialProperties& me = *this;
-	const MaterialProperties& he = mtl.accessMaterialPropertiesBaseClass();
-	me = he;
-
-	// Create vars
-	BOOST_FOREACH(const UserMaterialVariable* var, mtl.getUserVariables())
-	{
-		UserMaterialVariableRuntime* varr =
-			new UserMaterialVariableRuntime(*var);
-		vars.push_back(varr);
-		varNameToVar[varr->getUserMaterialVariable().getName().c_str()] = varr;
-	}
-}
-
-
-//==============================================================================
-// Destructor                                                                  =
-//==============================================================================
-MaterialRuntime2::~MaterialRuntime2()
-{}
-
-
-//==============================================================================
-// findVariableByName                                                          =
-//==============================================================================
-UserMaterialVariableRuntime& MaterialRuntime2::findVariableByName(
-	const char* name)
-{
-	ConstCharPtrHashMap<UserMaterialVariableRuntime*>::Type::iterator it =
-		varNameToVar.find(name);
-	if(it == varNameToVar.end())
-	{
-		throw EXCEPTION("Cannot get user defined variable with name \"" +
-			name + '\"');
-	}
-	return *(it->second);
-}
-
-
-//==============================================================================
-// findVariableByName                                                          =
-//==============================================================================
-const UserMaterialVariableRuntime& MaterialRuntime2::findVariableByName(
-	const char* name) const
-{
-	ConstCharPtrHashMap<UserMaterialVariableRuntime*>::Type::const_iterator
-		it = varNameToVar.find(name);
-	if(it == varNameToVar.end())
-	{
-		throw EXCEPTION("Cannot get user defined variable with name \"" +
-			name + '\"');
-	}
-	return *(it->second);
-}

+ 0 - 75
src/Scene/MaterialRuntime2.h

@@ -1,75 +0,0 @@
-#ifndef MATERIAL_RUNTIME_2_H
-#define MATERIAL_RUNTIME_2_H
-
-#include "Resources/Material2.h"
-#include "Util/Accessors.h"
-#include "Util/ConstCharPtrHashMap.h"
-#include <boost/ptr_container/ptr_vector.hpp>
-
-
-class UserMaterialVariableRuntime;
-class Material2;
-
-
-/// One layer above material resource
-class MaterialRuntime2: private MaterialProperties
-{
-	public:
-		/// A type
-		typedef boost::ptr_vector<UserMaterialVariableRuntime>
-			VariablesContainer;
-
-		/// @name Constructors & destructors
-		/// @{
-		MaterialRuntime2(const Material2& mtl);
-		~MaterialRuntime2();
-		/// @}
-
-		/// @name Accessors
-		/// @{
-		GETTER_SETTER_BY_VAL(bool, castsShadowFlag, castsShadow, setCastShadow)
-		GETTER_SETTER_BY_VAL(bool, renderInBlendingStageFlag,
-			rendersInBlendingStage, setRendersInBlendingStage)
-		GETTER_SETTER_BY_VAL(int, blendingSfactor, getBlendingSfactor,
-			setBlendingSFactor)
-		GETTER_SETTER_BY_VAL(int, blendingDfactor, getBlendingDfactor,
-			setBlendingDFactor)
-		GETTER_SETTER_BY_VAL(bool, depthTesting, isDepthTestingEnabled,
-			setDepthTestingEnabled)
-		GETTER_SETTER_BY_VAL(bool, wireframe, isWireframeEnabled,
-			setWireframeEnabled)
-
-		GETTER_RW(VariablesContainer, vars, getVariables)
-		GETTER_R(Material2, mtl, getMaterial);
-		/// @}
-
-		/// Find MaterialRuntimeUserDefinedVar variable. On failure it throws
-		/// an exception
-		/// @param[in] name The name of the var
-		/// @return It returns a MaterialRuntimeUserDefinedVar
-		/// @exception Exception
-		UserMaterialVariableRuntime& findVariableByName(
-			const char* name);
-
-		/// The const version of getUserDefinedVarByName
-		/// @see getUserDefinedVarByName
-		const UserMaterialVariableRuntime& findVariableByName(
-			const char* name) const;
-
-		bool isBlendingEnabled() const;
-
-	private:
-		const Material2& mtl; ///< The resource
-		VariablesContainer vars;
-		ConstCharPtrHashMap<UserMaterialVariableRuntime*>::Type
-			varNameToVar;
-};
-
-
-inline bool MaterialRuntime2::isBlendingEnabled() const
-{
-	return blendingSfactor != GL_ONE || blendingDfactor != GL_ZERO;
-}
-
-
-#endif

+ 0 - 24
src/Scene/MaterialRuntimeUserDefinedVar.cpp

@@ -1,24 +0,0 @@
-#include "MaterialRuntimeUserDefinedVar.h"
-
-
-//==============================================================================
-// ConstructVisitor::operator() <RsrcPtr<Texture> >                            =
-//==============================================================================
-template <>
-void MaterialRuntimeUserDefinedVar::ConstructVisitor::
-	operator()<RsrcPtr<Texture> >(const RsrcPtr<Texture>& x) const
-{
-	udvr.data = &x;
-}
-
-
-//==============================================================================
-// Constructor                                                                 =
-//==============================================================================
-MaterialRuntimeUserDefinedVar::MaterialRuntimeUserDefinedVar(
-	const MtlUserDefinedVar& rsrc_)
-:	rsrc(rsrc_)
-{
-	// Initialize the data using a visitor
-	boost::apply_visitor(ConstructVisitor(*this), rsrc.getDataVariant());
-}

+ 0 - 71
src/Scene/MaterialRuntimeUserDefinedVar.h

@@ -1,71 +0,0 @@
-#ifndef MATERIAL_RUNTIME_USER_DEFINED_VAR_H
-#define MATERIAL_RUNTIME_USER_DEFINED_VAR_H
-
-#include "Resources/MtlUserDefinedVar.h"
-
-
-/// This holds a copy of the MtlUserDefinedVar's data in order to be changed
-/// inside the main loop
-class MaterialRuntimeUserDefinedVar
-{
-	friend class ConstructVisitor;
-
-	public:
-		/// The data union. The Texture resource is read-only at runtime
-		typedef boost::variant<float, Vec2, Vec3, Vec4,
-			const RsrcPtr<Texture>*, MtlUserDefinedVar::Fai> DataVariant;
-
-		/// The one and only constructor
-		MaterialRuntimeUserDefinedVar(const MtlUserDefinedVar& rsrc);
-
-		/// @name Accessors
-		/// @{
-		const UniformShaderProgramVariable& getUniVar() const {return rsrc.getUniVar();}
-
-		const std::string& getName() const {return getUniVar().getName();}
-
-		GETTER_RW(DataVariant, data, getDataVariant)
-
-		/// Get the value of the variant
-		/// @exception boost::exception when you try to get the incorrect data
-		/// type
-		template<typename Type>
-		const Type& get() const {return boost::get<Type>(data);}
-
-		/// Get the value of the variant
-		/// @exception boost::exception when you try to get the incorrect data
-		/// type
-		template<typename Type>
-		Type& get() {return boost::get<Type>(data);}
-
-		template<typename Type>
-		void set(const Type& v) {boost::get<Type>(data) = v;}
-		/// @}
-
-	private:
-		/// Initialize the data using a visitor
-		class ConstructVisitor: public boost::static_visitor<void>
-		{
-			public:
-				MaterialRuntimeUserDefinedVar& udvr;
-
-				ConstructVisitor(MaterialRuntimeUserDefinedVar& udvr_);
-
-				/// Template method that applies to all DataVariant values
-				/// except texture resource
-				template<typename Type>
-				void operator()(const Type& x) const {udvr.data = x;}
-		};
-
-		DataVariant data;
-		const MtlUserDefinedVar& rsrc; ///< Know the resource
-};
-
-
-inline MaterialRuntimeUserDefinedVar::ConstructVisitor::ConstructVisitor(
-	MaterialRuntimeUserDefinedVar& udvr_)
-:	udvr(udvr_)
-{}
-
-
-#endif