Browse Source

- New material

compiles, lots of bugs
Panagiotis Christopoulos Charitos 14 years ago
parent
commit
e3d015732d

+ 2 - 2
anki/renderer/Deformer.cpp

@@ -56,8 +56,8 @@ void Deformer::deform(SkinPatchNode& node) const
 	const ShaderProgram* sProg;
 	const Material& mtl = node.getModelPatchRsrc().getMaterial();
 
-	if(mtl.buildinVariableExits(MaterialBuildinVariable::MV_NORMAL) &&
-	   mtl.buildinVariableExits(MaterialBuildinVariable::MV_TANGENT))
+	if(mtl.variableExistsAndInKey("normal", PassLevelKey(0, 0)) &&
+	   mtl.variableExistsAndInKey("tangent", PassLevelKey(0, 0)))
 	{
 		sProg = tfHwSkinningAllSProg.get();
 	}

+ 1 - 1
anki/renderer/Ez.cpp

@@ -69,7 +69,7 @@ void Ez::run()
 
 	BOOST_FOREACH(const RenderableNode* node, cam.getVisibleMsRenderableNodes())
 	{
-		r.getSceneDrawer().renderRenderableNode(*node, cam, DEPTH_PASS);
+		r.getSceneDrawer().renderRenderableNode(*node, cam, PassLevelKey(1, 0));
 	}
 
 	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

+ 1 - 1
anki/renderer/Ms.cpp

@@ -120,7 +120,7 @@ void Ms::run()
 		r.getCamera().getVisibleMsRenderableNodes())
 	{
 		r.getSceneDrawer().renderRenderableNode(*node, r.getCamera(),
-			COLOR_PASS);
+			PassLevelKey(0, 0));
 	}
 
 	// restore depth

+ 58 - 52
anki/renderer/SceneDrawer.cpp

@@ -19,10 +19,10 @@ namespace anki {
 //==============================================================================
 SceneDrawer::UsrDefVarVisitor::UsrDefVarVisitor(
 	const MaterialRuntimeVariable& udvr_,
-	const Renderer& r_, PassType pt_, uint& texUnit_)
+	const Renderer& r_, const PassLevelKey& pt_, uint& texUnit_)
 :	udvr(udvr_),
 	r(r_),
-	pt(pt_),
+	key(pt_),
 	texUnit(texUnit_)
 {}
 
@@ -34,16 +34,20 @@ SceneDrawer::UsrDefVarVisitor::UsrDefVarVisitor(
 template<typename Type>
 void SceneDrawer::UsrDefVarVisitor::operator()(const Type& x) const
 {
-	udvr.getMaterialUserVariable().getShaderProgramUniformVariable(pt).set(&x);
+	static_cast<const ShaderProgramUniformVariable&>(udvr.getMaterialVariable().
+		getShaderProgramVariable(key)).set(&x);
 }
 
 
-void SceneDrawer::UsrDefVarVisitor::operator()(const TextureResourcePointer* x) const
+void SceneDrawer::UsrDefVarVisitor::operator()(
+	const TextureResourcePointer* x) const
 {
 	const TextureResourcePointer& texPtr = *x;
 	texPtr->setRepeat(true);
-	udvr.getMaterialUserVariable().getShaderProgramUniformVariable(pt).
-		set(*texPtr, texUnit);
+
+	static_cast<const ShaderProgramUniformVariable&>(udvr.getMaterialVariable().
+		getShaderProgramVariable(key)).set(*texPtr, texUnit);
+
 	++texUnit;
 }
 
@@ -53,13 +57,13 @@ void SceneDrawer::UsrDefVarVisitor::operator()(const TextureResourcePointer* x)
 //==============================================================================
 void SceneDrawer::setupShaderProg(
 	const MaterialRuntime& mtlr,
-	PassType pt,
+	const PassLevelKey& pt,
 	const Transform& nodeWorldTransform,
 	const Camera& cam,
 	const Renderer& r,
 	float blurring)
 {
-	typedef MaterialBuildinVariable Mvb; // Short name
+	typedef MaterialVariable Mvb; // Short name
 	uint textureUnit = 0;
 	GlStateMachine& gl = GlStateMachineSingleton::get();
 	const Material& mtl = mtlr.getMaterial();
@@ -99,9 +103,9 @@ void SceneDrawer::setupShaderProg(
 	Mat4 modelViewProjectionMat;
 
 	// should I calculate the modelViewMat ?
-	if(mtl.buildinVariableExits(Mvb::MV_MODELVIEW_MAT, pt) ||
-		mtl.buildinVariableExits(Mvb::MV_MODELVIEWPROJECTION_MAT, pt) ||
-		mtl.buildinVariableExits(Mvb::MV_NORMAL_MAT, pt))
+	if(mtl.variableExistsAndInKey("modelViewMat", pt) ||
+		mtl.variableExistsAndInKey("modeViewProjectionMat", pt) ||
+		mtl.variableExistsAndInKey("normalMat", pt))
 	{
 		// Optimization
 		modelViewMat = (modelMat == Mat4::getIdentity()) ? viewMat :
@@ -109,99 +113,99 @@ void SceneDrawer::setupShaderProg(
 	}
 
 	// set matrices
-	if(mtl.buildinVariableExits(Mvb::MV_MODEL_MAT, pt))
+	if(mtl.variableExistsAndInKey("modelMat", pt))
 	{
-		mtl.getBuildinVariable(Mvb::MV_MODEL_MAT).
-			getShaderProgramUniformVariable(pt).set(&modelMat);
+		static_cast<const ShaderProgramUniformVariable&>(mtl.findVariableByName("modelMat").
+			getShaderProgramVariable(pt)).set(&modelMat);
 	}
 
-	if(mtl.buildinVariableExits(Mvb::MV_VIEW_MAT, pt))
+	if(mtl.variableExistsAndInKey("viewMat", pt))
 	{
-		mtl.getBuildinVariable(Mvb::MV_VIEW_MAT).
-			getShaderProgramUniformVariable(pt).set(&viewMat);
+		static_cast<const ShaderProgramUniformVariable&>(mtl.findVariableByName("viewMat").
+			getShaderProgramVariable(pt)).set(&viewMat);
 	}
 
-	if(mtl.buildinVariableExits(Mvb::MV_PROJECTION_MAT, pt))
+	if(mtl.variableExistsAndInKey("projectionMat", pt))
 	{
-		mtl.getBuildinVariable(Mvb::MV_PROJECTION_MAT).
-			getShaderProgramUniformVariable(pt).set(&projectionMat);
+		static_cast<const ShaderProgramUniformVariable&>(mtl.findVariableByName("projectionMat").
+			getShaderProgramVariable(pt)).set(&projectionMat);
 	}
 
-	if(mtl.buildinVariableExits(Mvb::MV_MODELVIEW_MAT, pt))
+	if(mtl.variableExistsAndInKey("modelViewMat", pt))
 	{
-		mtl.getBuildinVariable(Mvb::MV_MODELVIEW_MAT).
-			getShaderProgramUniformVariable(pt).set(&modelViewMat);
+		static_cast<const ShaderProgramUniformVariable&>(mtl.findVariableByName("modelMat").
+			getShaderProgramVariable(pt)).set(&modelViewMat);
 	}
 
-	if(mtl.buildinVariableExits(Mvb::MV_VIEWPROJECTION_MAT, pt))
+	if(mtl.variableExistsAndInKey("viewProjectionMat", pt))
 	{
-		mtl.getBuildinVariable(Mvb::MV_VIEWPROJECTION_MAT).
-			getShaderProgramUniformVariable(pt).set(&r.getViewProjectionMat());
+		static_cast<const ShaderProgramUniformVariable&>(mtl.findVariableByName("viewProjectionMat").
+			getShaderProgramVariable(pt)).set(&r.getViewProjectionMat());
 	}
 
-	if(mtl.buildinVariableExits(Mvb::MV_NORMAL_MAT, pt))
+	if(mtl.variableExistsAndInKey("normalMat", pt))
 	{
 		normalMat = modelViewMat.getRotationPart();
 
-		mtl.getBuildinVariable(Mvb::MV_NORMAL_MAT).
-			getShaderProgramUniformVariable(pt).set(&normalMat);
+		static_cast<const ShaderProgramUniformVariable&>(mtl.findVariableByName("normalMat").
+			getShaderProgramVariable(pt)).set(&normalMat);
 	}
 
-	if(mtl.buildinVariableExits(Mvb::MV_MODELVIEWPROJECTION_MAT, pt))
+	if(mtl.variableExistsAndInKey("modelViewProjectionMat", pt))
 	{
 		modelViewProjectionMat = projectionMat * modelViewMat;
 
-		mtl.getBuildinVariable(Mvb::MV_MODELVIEWPROJECTION_MAT).
-			getShaderProgramUniformVariable(pt).set(&modelViewProjectionMat);
+		static_cast<const ShaderProgramUniformVariable&>(mtl.findVariableByName("modelViewProjectionMat").
+			getShaderProgramVariable(pt)).set(&modelViewProjectionMat);
 	}
 
 
 	//
 	// FAis
 	//
-	if(mtl.buildinVariableExits(Mvb::MV_MS_NORMAL_FAI, pt))
+	/*if(mtl.variableExistsAndInKey(Mvb::MV_MS_NORMAL_FAI, pt))
 	{
 		mtl.getBuildinVariable(Mvb::MV_MS_NORMAL_FAI).
 			getShaderProgramUniformVariable(pt).set(
 			r.getMs().getNormalFai(), textureUnit++);
 	}
 
-	if(mtl.buildinVariableExits(Mvb::MV_MS_DIFFUSE_FAI, pt))
+	if(mtl.variableExistsAndInKey(Mvb::MV_MS_DIFFUSE_FAI, pt))
 	{
 		mtl.getBuildinVariable(Mvb::MV_MS_DIFFUSE_FAI).
 			getShaderProgramUniformVariable(pt).set(
 			r.getMs().getDiffuseFai(), textureUnit++);
 	}
 
-	if(mtl.buildinVariableExits(Mvb::MV_MS_SPECULAR_FAI, pt))
+	if(mtl.variableExistsAndInKey(Mvb::MV_MS_SPECULAR_FAI, pt))
 	{
 		mtl.getBuildinVariable(Mvb::MV_MS_SPECULAR_FAI).
 			getShaderProgramUniformVariable(pt).set(
 			r.getMs().getSpecularFai(), textureUnit++);
 	}
 
-	if(mtl.buildinVariableExits(Mvb::MV_MS_DEPTH_FAI, pt))
+	if(mtl.variableExistsAndInKey(Mvb::MV_MS_DEPTH_FAI, pt))
 	{
 		mtl.getBuildinVariable(Mvb::MV_MS_DEPTH_FAI).
 			getShaderProgramUniformVariable(pt).set(
 			r.getMs().getDepthFai(), textureUnit++);
 	}
 
-	if(mtl.buildinVariableExits(Mvb::MV_IS_FAI, pt))
+	if(mtl.variableExistsAndInKey(Mvb::MV_IS_FAI, pt))
 	{
 		mtl.getBuildinVariable(Mvb::MV_IS_FAI).
 			getShaderProgramUniformVariable(pt).set(
 			r.getIs().getFai(), textureUnit++);
 	}
 
-	if(mtl.buildinVariableExits(Mvb::MV_PPS_PRE_PASS_FAI, pt))
+	if(mtl.variableExistsAndInKey(Mvb::MV_PPS_PRE_PASS_FAI, pt))
 	{
 		mtl.getBuildinVariable(Mvb::MV_PPS_PRE_PASS_FAI).
 			getShaderProgramUniformVariable(pt).set(
 			r.getPps().getPrePassFai(), textureUnit++);
 	}
 
-	if(mtl.buildinVariableExits(Mvb::MV_PPS_POST_PASS_FAI, pt))
+	if(mtl.variableExistsAndInKey(Mvb::MV_PPS_POST_PASS_FAI, pt))
 	{
 		mtl.getBuildinVariable(Mvb::MV_PPS_POST_PASS_FAI).
 			getShaderProgramUniformVariable(pt).set(
@@ -212,28 +216,28 @@ void SceneDrawer::setupShaderProg(
 	//
 	// Other
 	//
-	if(mtl.buildinVariableExits(Mvb::MV_RENDERER_SIZE, pt))
+	if(mtl.variableExistsAndInKey(Mvb::MV_RENDERER_SIZE, pt))
 	{
 		Vec2 v(r.getWidth(), r.getHeight());
 		mtl.getBuildinVariable(Mvb::MV_RENDERER_SIZE).
 			getShaderProgramUniformVariable(pt).set(&v);
 	}
 
-	if(mtl.buildinVariableExits(Mvb::MV_SCENE_AMBIENT_COLOR, pt))
+	if(mtl.variableExistsAndInKey(Mvb::MV_SCENE_AMBIENT_COLOR, pt))
 	{
 		Vec3 col(SceneSingleton::get().getAmbientColor());
 		mtl.getBuildinVariable(Mvb::MV_SCENE_AMBIENT_COLOR).
 			getShaderProgramUniformVariable(pt).set(&col);
 	}
 
-	if(mtl.buildinVariableExits(Mvb::MV_BLURRING, pt))
+	if(mtl.variableExistsAndInKey(Mvb::MV_BLURRING, pt))
 	{
-		/*blurring *= 10.0;
-		ANKI_INFO(blurring);*/
+		blurring *= 10.0;
+		ANKI_INFO(blurring);
 		float b = blurring;
 		mtl.getBuildinVariable(Mvb::MV_BLURRING).
 			getShaderProgramUniformVariable(pt).set(&b);
-	}
+	}*/
 
 
 	//
@@ -241,7 +245,9 @@ void SceneDrawer::setupShaderProg(
 	//
 	BOOST_FOREACH(const MaterialRuntimeVariable& udvr, mtlr.getVariables())
 	{
-		if(!udvr.getMaterialUserVariable().inPass(pt))
+		if(!udvr.getMaterialVariable().inPass(pt) ||
+			udvr.getMaterialVariable().getShaderProgramVariableType() ==
+				ShaderProgramVariable::T_ATTRIBUTE)
 		{
 			continue;
 		}
@@ -258,14 +264,14 @@ void SceneDrawer::setupShaderProg(
 // renderRenderableNode                                                        =
 //==============================================================================
 void SceneDrawer::renderRenderableNode(const RenderableNode& node,
-	const Camera& cam, PassType pt) const
+	const Camera& cam, const PassLevelKey& key) const
 {
 	float blurring = 0.0;
 	const MaterialRuntime& mtlr = node.getMaterialRuntime();
 	const Material& mtl = mtlr.getMaterial();
 
 	// Calc the blur if needed
-	if(mtl.buildinVariableExits(MaterialBuildinVariable::MV_BLURRING, pt))
+	if(mtl.variableExistsAndInKey("blurring", key))
 	{
 		float prev = (node.getPrevWorldTransform().getOrigin() -
 			cam.getPrevWorldTransform().getOrigin()).getLength();
@@ -276,10 +282,10 @@ void SceneDrawer::renderRenderableNode(const RenderableNode& node,
 		blurring = abs(crnt - prev);
 	}
 
-	setupShaderProg(mtlr, pt, node.getWorldTransform(), cam, r, blurring);
-	node.getVao(pt).bind();
-	glDrawElements(GL_TRIANGLES, node.getVertIdsNum(), GL_UNSIGNED_SHORT, 0);
-	node.getVao(pt).unbind();
+	setupShaderProg(mtlr, key, node.getWorldTransform(), cam, r, blurring);
+	node.getVao(key).bind();
+	glDrawElements(GL_TRIANGLES, node.getVertIdsNum(key), GL_UNSIGNED_SHORT, 0);
+	node.getVao(key).unbind();
 }
 
 

+ 83 - 49
anki/renderer/SceneDrawer.h

@@ -22,55 +22,89 @@ class Renderer;
 /// It includes all the functions to render a RenderableNode
 class SceneDrawer
 {
-	public:
-		/// The one and only constructor
-		SceneDrawer(const Renderer& r_)
-		:	r(r_)
-		{}
-
-		void renderRenderableNode(const RenderableNode& renderable,
-			const Camera& cam, PassType passType) const;
-
-	private:
-		/// Set the uniform using this visitor
-		class UsrDefVarVisitor: public boost::static_visitor<>
-		{
-			public:
-				const MaterialRuntimeVariable& udvr;
-				const Renderer& r;
-				PassType pt;
-				uint& texUnit;
-
-				UsrDefVarVisitor(const MaterialRuntimeVariable& udvr,
-					const Renderer& r, PassType pt, uint& texUnit);
-
-				/// Functor
-				template<typename Type>
-				void operator()(const Type& x) const;
-
-				/// Functor
-				void operator()(const TextureResourcePointer* x) const;
-		};
-
-		const Renderer& r; ///< Keep it here cause the class wants a few stuff
-		                   ///< from it
-
-		/// This function:
-		/// - binds the shader program
-		/// - loads the uniforms
-		/// - sets the GL state
-		/// @param mtlr The material runtime
-		/// @param nodeWorldTransform The world transformation to pass to the
-		/// shader
-		/// @param cam Needed for some matrices (view & projection)
-		/// @param r The renderer, needed for some FAIs and some matrices
-		static void setupShaderProg(
-			const MaterialRuntime& mtlr,
-			PassType pt,
-			const Transform& nodeWorldTransform,
-			const Camera& cam,
-			const Renderer& r,
-			float blurring);
+public:
+	/// The one and only constructor
+	SceneDrawer(const Renderer& r_)
+	:	r(r_)
+	{}
+
+	void renderRenderableNode(const RenderableNode& renderable,
+		const Camera& cam, const PassLevelKey& key) const;
+
+private:
+	/// Standard attribute variables that are acceptable inside the
+	/// ShaderProgram
+	enum ShaderProgramVariable_
+	{
+			// Attributes
+			SPV_POSITION,
+			SPV_TANGENT,
+			SPV_NORMAL,
+			SPV_TEX_COORDS,
+			// Uniforms
+			// Matrices
+			SPV_MODEL_MAT,
+			SPV_VIEW_MAT,
+			SPV_PROJECTION_MAT,
+			SPV_MODELVIEW_MAT,
+			SPV_VIEWPROJECTION_MAT,
+			SPV_NORMAL_MAT,
+			SPV_MODELVIEWPROJECTION_MAT,
+			// FAIs (for materials in blending stage)
+			SPV_MS_NORMAL_FAI,
+			SPV_MS_DIFFUSE_FAI,
+			SPV_MS_SPECULAR_FAI,
+			SPV_MS_DEPTH_FAI,
+			SPV_IS_FAI,
+			SPV_PPS_PRE_PASS_FAI,
+			SPV_PPS_POST_PASS_FAI,
+			// Other
+			SPV_RENDERER_SIZE,
+			SPV_SCENE_AMBIENT_COLOR,
+			SPV_BLURRING,
+			// num
+			SPV_NUM ///< The number of all buildin variables
+	};
+
+	/// Set the uniform using this visitor
+	class UsrDefVarVisitor: public boost::static_visitor<>
+	{
+		public:
+			const MaterialRuntimeVariable& udvr;
+			const Renderer& r;
+			const PassLevelKey& key;
+			uint& texUnit;
+
+			UsrDefVarVisitor(const MaterialRuntimeVariable& udvr,
+				const Renderer& r, const PassLevelKey& key, uint& texUnit);
+
+			/// Functor
+			template<typename Type>
+			void operator()(const Type& x) const;
+
+			/// Functor
+			void operator()(const TextureResourcePointer* x) const;
+	};
+
+	const Renderer& r; ///< Keep it here cause the class wants a few stuff
+					   ///< from it
+
+	/// This function:
+	/// - binds the shader program
+	/// - loads the uniforms
+	/// - sets the GL state
+	/// @param mtlr The material runtime
+	/// @param nodeWorldTransform The world transformation to pass to the
+	/// shader
+	/// @param cam Needed for some matrices (view & projection)
+	/// @param r The renderer, needed for some FAIs and some matrices
+	static void setupShaderProg(
+		const MaterialRuntime& mtlr,
+		const PassLevelKey& key,
+		const Transform& nodeWorldTransform,
+		const Camera& cam,
+		const Renderer& r,
+		float blurring);
 };
 
 

+ 1 - 1
anki/renderer/Sm.cpp

@@ -154,7 +154,7 @@ void Sm::run(const Light& light, float distance)
 			{
 				const SpotLight& sl = static_cast<const SpotLight&>(light);
 				r.getSceneDrawer().renderRenderableNode(*node, sl.getCamera(),
-					DEPTH_PASS);
+					PassLevelKey(1, 0));
 				break;
 			}
 

+ 7 - 2
anki/resource/Material.cpp

@@ -190,7 +190,7 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 		{
 			std::stringstream src;
 
-			src << "#define LEVEL_" << level << std::endl;
+			src << "#define LOD_" << level << std::endl;
 			src << "#define PASS_" << passes[pid] << std::endl;
 			src << mspc.getShaderProgramSource() << std::endl;
 
@@ -210,7 +210,7 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 		}
 	}
 
-	populateVariables(pt.get_child("shaderProgram.inputs"));
+	populateVariables(pt.get_child("shaderProgram"));
 }
 
 
@@ -260,6 +260,11 @@ void Material::populateVariables(const boost::property_tree::ptree& pt)
 	{
 		BOOST_FOREACH(const ShaderProgramVariable& v, sProg->getVariables())
 		{
+			if(v.getType() != ShaderProgramVariable::T_UNIFORM)
+			{
+				continue;
+			}
+
 			allVarNames[v.getName()] = v.getGlDataType();
 		}
 	}

+ 93 - 113
anki/resource/Material.h

@@ -99,119 +99,99 @@ class ShaderProgram;
 /// (5): The order of the shaders is crucial
 class Material: public MaterialProperties
 {
-	public:
-		//======================================================================
-		// Nested                                                              =
-		//======================================================================
-
-		typedef boost::ptr_vector<MaterialVariable> VarsContainer;
-
-		//======================================================================
-		// Methods                                                             =
-		//======================================================================
-
-		Material();
-		~Material();
-
-		/// @name Accessors
-		/// @{
-
-		/// Access the base class just for copying in other classes
-		const MaterialProperties& getBaseClass() const
-		{
-			return *this;
-		}
-
-		const ShaderProgram& getShaderProgram(const PassLevelKey& key) const
-		{
-			return *eSProgs.at(key);
-		}
-
-		// Variable accessors
-		const VarsContainer& getVariables() const
-		{
-			return vars;
-		}
-		/// @}
-
-		/// Get by name
-		const MaterialVariable& findVariableByName(const char* name) const;
-
-		bool variableExists(const char* name) const
-		{
-			return nameToVar.find(name) != nameToVar.end();
-		}
-
-		/// Check if a variable exists in the shader program of the @a key
-		bool variableExistsAndInKey(const char* name,
-			const PassLevelKey& key) const
-		{
-			NameToVariableHashMap::const_iterator it = nameToVar.find(name);
-			return it != nameToVar.end() && it->second->inPass(key);
-		}
-
-		/// Load a material file
-		void load(const char* filename);
-
-		/// For sorting
-		bool operator<(const Material& b) const
-		{
-			return fname < b.fname;
-		}
-
-	private:
-		//======================================================================
-		// Nested                                                              =
-		//======================================================================
-		
-		/// Type for garbage collection
-		typedef boost::ptr_vector<ShaderProgramResourcePointer> ShaderPrograms;
-
-		typedef ConstCharPtrHashMap<MaterialVariable*>::Type
-			NameToVariableHashMap;
-
-		//======================================================================
-		// Members                                                             =
-		//======================================================================
-
-		/// From "GL_ZERO" return GL_ZERO
-		static ConstCharPtrHashMap<GLenum>::Type txtToBlengGlEnum;
-
-		std::string fname; ///< filename
-
-		/// All the material variables
-		VarsContainer vars;
-
-		NameToVariableHashMap nameToVar;
-
-		/// The most important aspect of materials. These are all the shader 
-		/// programs per level and per pass. Their number are NP * NL where
-		/// NP is the number of passes and NL the number of levels of detail
-		ShaderPrograms sProgs;
-		
-		/// For searching
-		PassLevelToShaderProgramHashMap eSProgs;
-
-		//======================================================================
-		// 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 populateVariables(const boost::property_tree::ptree& pt);
-
-		/// Get a string and split it into words
-		static StringList splitString(const char* str);
-
-		/// Parses something like this: "0.0 0.01 -1.2" and returns a valid
-		/// math type
-		template<typename Type, size_t n>
-		static Type setMathType(const char* str);
+public:
+	typedef boost::ptr_vector<MaterialVariable> VarsContainer;
+
+	Material();
+	~Material();
+
+	/// @name Accessors
+	/// @{
+
+	/// Access the base class just for copying in other classes
+	const MaterialProperties& getBaseClass() const
+	{
+		return *this;
+	}
+
+	const ShaderProgram& getShaderProgram(const PassLevelKey& key) const
+	{
+		return *eSProgs.at(key);
+	}
+
+	// Variable accessors
+	const VarsContainer& getVariables() const
+	{
+		return vars;
+	}
+	/// @}
+
+	/// Get by name
+	const MaterialVariable& findVariableByName(const char* name) const;
+
+	bool variableExists(const char* name) const
+	{
+		return nameToVar.find(name) != nameToVar.end();
+	}
+
+	/// Check if a variable exists in the shader program of the @a key
+	bool variableExistsAndInKey(const char* name,
+		const PassLevelKey& key) const
+	{
+		NameToVariableHashMap::const_iterator it = nameToVar.find(name);
+		return it != nameToVar.end() && it->second->inPass(key);
+	}
+
+	/// Load a material file
+	void load(const char* filename);
+
+	/// For sorting
+	bool operator<(const Material& b) const
+	{
+		return fname < b.fname;
+	}
+
+private:
+	/// Type for garbage collection
+	typedef boost::ptr_vector<ShaderProgramResourcePointer> ShaderPrograms;
+
+	typedef ConstCharPtrHashMap<MaterialVariable*>::Type
+		NameToVariableHashMap;
+
+	/// From "GL_ZERO" return GL_ZERO
+	static ConstCharPtrHashMap<GLenum>::Type txtToBlengGlEnum;
+
+	std::string fname; ///< filename
+
+	/// All the material variables
+	VarsContainer vars;
+
+	NameToVariableHashMap nameToVar;
+
+	/// The most important aspect of materials. These are all the shader
+	/// programs per level and per pass. Their number are NP * NL where
+	/// NP is the number of passes and NL the number of levels of detail
+	ShaderPrograms sProgs;
+
+	/// For searching
+	PassLevelToShaderProgramHashMap eSProgs;
+
+	/// 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 populateVariables(const boost::property_tree::ptree& pt);
+
+	/// Get a string and split it into words
+	static StringList splitString(const char* str);
+
+	/// Parses something like this: "0.0 0.01 -1.2" and returns a valid
+	/// math type
+	template<typename Type, size_t n>
+	static Type setMathType(const char* str);
 };
 
 

+ 76 - 76
anki/resource/MaterialProperties.h

@@ -13,83 +13,83 @@ namespace anki {
 /// the variables refer to Material class documentation
 class MaterialProperties
 {
-	public:
-		/// Initialize with default values
-		MaterialProperties()
-		{
-			renderingStage = 0;
-			levelsOfDetail = 1;
-			shadow = false;
-			blendingSfactor = GL_ONE;
-			blendingDfactor = GL_ZERO;
-			depthTesting = true;
-			wireframe = false;
-		}
-		
-		/// @name Accessors
-		/// @{
-		uint getRenderingStage() const
-		{
-			return renderingStage;
-		}
-		
-		const StringList& getPasses() const
-		{
-			return passes;
-		}
-		
-		uint getLevelsOfDetail() const
-		{
-			return levelsOfDetail;
-		}
-		
-		bool getShadow() const
-		{
-			return shadow;
-		}
-
-		int getBlendingSfactor() const
-		{
-			return blendingSfactor;
-		}
-
-		int getBlendingDfactor() const
-		{
-			return blendingDfactor;
-		}
-
-		bool getDepthTesting() const
-		{
-			return depthTesting;
-		}
-
-		bool getWireframe() const
-		{
-			return wireframe;
-		}
-		/// @}
-		
-		/// Check if blending is enabled
-		bool isBlendingEnabled() const
-		{
-			return blendingSfactor != GL_ONE || blendingDfactor != GL_ZERO;
-		}
-
-	protected:
-		uint renderingStage;
-		
-		StringList passes;
-		
-		uint levelsOfDetail;
+public:
+	/// Initialize with default values
+	MaterialProperties()
+	{
+		renderingStage = 0;
+		levelsOfDetail = 1;
+		shadow = false;
+		blendingSfactor = GL_ONE;
+		blendingDfactor = GL_ZERO;
+		depthTesting = true;
+		wireframe = false;
+	}
+
+	/// @name Accessors
+	/// @{
+	uint getRenderingStage() const
+	{
+		return renderingStage;
+	}
+
+	const StringList& getPasses() const
+	{
+		return passes;
+	}
+
+	uint getLevelsOfDetail() const
+	{
+		return levelsOfDetail;
+	}
+
+	bool getShadow() const
+	{
+		return shadow;
+	}
+
+	int getBlendingSfactor() const
+	{
+		return blendingSfactor;
+	}
+
+	int getBlendingDfactor() const
+	{
+		return blendingDfactor;
+	}
+
+	bool getDepthTesting() const
+	{
+		return depthTesting;
+	}
+
+	bool getWireframe() const
+	{
+		return wireframe;
+	}
+	/// @}
+
+	/// Check if blending is enabled
+	bool isBlendingEnabled() const
+	{
+		return blendingSfactor != GL_ONE || blendingDfactor != GL_ZERO;
+	}
+
+protected:
+	uint renderingStage;
+
+	StringList passes;
+
+	uint levelsOfDetail;
+
+	bool shadow;
+
+	int blendingSfactor; ///< Default GL_ONE
+	int blendingDfactor; ///< Default GL_ZERO
+
+	bool depthTesting;
 	
-		bool shadow;
-		
-		int blendingSfactor; ///< Default GL_ONE
-		int blendingDfactor; ///< Default GL_ZERO
-		
-		bool depthTesting;
-		
-		bool wireframe;
+	bool wireframe;
 };
 
 

+ 98 - 98
anki/resource/MaterialVariable.h

@@ -19,105 +19,105 @@ namespace anki {
 /// that share the same name
 class MaterialVariable
 {
-	public:
-		/// The type
-		enum Type
-		{
-			T_USER,
-			T_BUILDIN
-		};
+public:
+	/// The type
+	enum Type
+	{
+		T_USER,
+		T_BUILDIN
+	};
+
+	/// The data union (limited to a few types at the moment)
+	typedef boost::variant<float, Vec2, Vec3, Vec4, Mat3,
+		Mat4, TextureResourcePointer> Variant;
+
+	/// Given a pair of pass and level it returns a pointer to a
+	/// shader program variable. The pointer may be null
+	typedef PassLevelHashMap<const ShaderProgramVariable*>::Type
+		PassLevelToShaderProgramVariableHashMap;
+
+	/// @name Constructors & destructor
+	/// @{
+
+	/// For build-ins
+	MaterialVariable(
+		const char* shaderProgVarName,
+		const PassLevelToShaderProgramHashMap& sProgs);
+
+	/// For user defined
+	template<typename Type>
+	MaterialVariable(
+		const char* shaderProgVarName,
+		const PassLevelToShaderProgramHashMap& sProgs,
+		const Type& val)
+	{
+		init(shaderProgVarName, sProgs);
+		ANKI_ASSERT(getShaderProgramVariableType() ==
+			ShaderProgramVariable::T_UNIFORM);
+		data = val;
+	}
+	/// @}
 		
-		/// The data union (limited to a few types at the moment)
-		typedef boost::variant<float, Vec2, Vec3, Vec4, Mat3, 
-			Mat4, TextureResourcePointer> Variant;
-
-		/// Given a pair of pass and level it returns a pointer to a
-		/// shader program variable. The pointer may be null
-		typedef PassLevelHashMap<const ShaderProgramVariable*>::Type
-			PassLevelToShaderProgramVariableHashMap;
-
-		/// @name Constructors & destructor
-		/// @{
-		
-		/// For build-ins
-		MaterialVariable(
-			const char* shaderProgVarName,
-			const PassLevelToShaderProgramHashMap& sProgs);
-			
-		/// For user defined
-		template<typename Type>
-		MaterialVariable(
-			const char* shaderProgVarName,
-			const PassLevelToShaderProgramHashMap& sProgs,
-			const Type& val)
-		{
-			init(shaderProgVarName, sProgs);
-			ANKI_ASSERT(getShaderProgramVariableType() ==
-				ShaderProgramVariable::T_UNIFORM);
-			data = val;
-		}
-		/// @}
-			
-		/// @name Accessors
-		/// @{
-		Type getType() const
-		{
-			return type;
-		}
-
-		const Variant& getVariant() const
-		{
-			return data;
-		}
-
-		/// XXX
-		const ShaderProgramVariable& getShaderProgramVariable(
-			const PassLevelKey& key) const
-		{
-			ANKI_ASSERT(inPass(key));
-			const ShaderProgramVariable* var =
-				sProgVars.at(key);
-			return *var;
-		}
-
-		/// Check if the shader program of the given pass and level needs
-		/// contains this variable or not
-		bool inPass(const PassLevelKey& key) const
-		{
-			return sProgVars.find(key) != sProgVars.end();
-		}
-
-		/// Get the GL data type of all the shader program variables
-		GLenum getGlDataType() const
-		{
-			return oneSProgVar->getGlDataType();
-		}
-
-		/// Get the name of all the shader program variables
-		const std::string& getName() const
-		{
-			return oneSProgVar->getName();
-		}
-
-		/// Get the type of all the shader program variables
-		ShaderProgramVariable::Type getShaderProgramVariableType() const
-		{
-			return oneSProgVar->getType();
-		}
-		/// @}
-
-	private:
-		Type type;
-		PassLevelToShaderProgramVariableHashMap sProgVars;
-		Variant data;
-
-		/// Keep one ShaderProgramVariable here for easy access of the common
-		/// variable stuff like name or GL data type etc
-		const ShaderProgramVariable* oneSProgVar;
-
-		/// Common constructor code
-		void init(const char* shaderProgVarName,
-			const PassLevelToShaderProgramHashMap& shaderProgsArr);
+	/// @name Accessors
+	/// @{
+	Type getType() const
+	{
+		return type;
+	}
+
+	const Variant& getVariant() const
+	{
+		return data;
+	}
+
+	/// XXX
+	const ShaderProgramVariable& getShaderProgramVariable(
+		const PassLevelKey& key) const
+	{
+		ANKI_ASSERT(inPass(key));
+		const ShaderProgramVariable* var =
+			sProgVars.at(key);
+		return *var;
+	}
+
+	/// Check if the shader program of the given pass and level needs
+	/// contains this variable or not
+	bool inPass(const PassLevelKey& key) const
+	{
+		return sProgVars.find(key) != sProgVars.end();
+	}
+
+	/// Get the GL data type of all the shader program variables
+	GLenum getGlDataType() const
+	{
+		return oneSProgVar->getGlDataType();
+	}
+
+	/// Get the name of all the shader program variables
+	const std::string& getName() const
+	{
+		return oneSProgVar->getName();
+	}
+
+	/// Get the type of all the shader program variables
+	ShaderProgramVariable::Type getShaderProgramVariableType() const
+	{
+		return oneSProgVar->getType();
+	}
+	/// @}
+
+private:
+	Type type;
+	PassLevelToShaderProgramVariableHashMap sProgVars;
+	Variant data;
+
+	/// Keep one ShaderProgramVariable here for easy access of the common
+	/// variable stuff like name or GL data type etc
+	const ShaderProgramVariable* oneSProgVar;
+
+	/// Common constructor code
+	void init(const char* shaderProgVarName,
+		const PassLevelToShaderProgramHashMap& shaderProgsArr);
 };
 
 

+ 102 - 102
anki/resource/ShaderProgram.h

@@ -25,108 +25,108 @@ namespace anki {
 /// an attribute var.
 class ShaderProgram
 {
-	public:
-		ShaderProgram();
-		~ShaderProgram();
-
-		/// @name Accessors
-		/// @{
-		GLuint getGlId() const;
-
-		const boost::ptr_vector<ShaderProgramVariable>& getVariables() const
-		{
-			return vars;
-		}
-		/// @}
-
-		/// Resource load
-		void load(const char* filename);
-
-		/// Bind the shader program
-		void bind() const;
-
-		/// @name Variable getters
-		/// Used to find and return the variable. They throw exception if
-		/// variable not found so ask if the variable with that name exists
-		/// prior using any of these
-		/// @{
-		const ShaderProgramVariable& getVariableByName(
-			const char* varName) const;
-		const ShaderProgramUniformVariable& getUniformVariableByName(
-			const char* varName) const;
-		const ShaderProgramAttributeVariable& getAttributeVariableByName(
-			const char* varName) const;
-		/// @}
-
-		/// @name Check for variable existance
-		/// @{
-		bool variableExists(const char* varName) const;
-		bool uniformVariableExists(const char* varName) const;
-		bool attributeVariableExists(const char* varName) const;
-		/// @}
-
-		/// Used by @ref Material and @ref Renderer to create custom shaders in
-		/// the cache
-		/// @param sProgFPathName The file pathname of the shader prog
-		/// @param preAppendedSrcCode The source code we want to write on top
-		/// of the shader prog
-		/// @param newFNamePrefix The prefix of the new shader prog
-		/// @return The file pathname of the new shader prog. Its
-		/// $HOME/.anki/cache/newFNamePrefix_fName
-		static std::string createSrcCodeToCache(const char* sProgFPathName,
-			const char* preAppendedSrcCode);
-
-		/// For debuging
-		std::string getShaderInfoString() const;
-
-		/// For sorting
-		bool operator<(const ShaderProgram& b) const
-		{
-			return rsrcFilename < b.rsrcFilename;
-		}
-
-	private:
-		/// XXX
-		typedef ConstCharPtrHashMap<ShaderProgramVariable*>::Type VarsHashMap;
-
-		/// XXX
-		typedef ConstCharPtrHashMap<ShaderProgramUniformVariable*>::Type
-			UniVarsHashMap;
-
-		/// XXX
-		typedef ConstCharPtrHashMap<ShaderProgramAttributeVariable*>::Type
-			AttribVarsHashMap;
-
-		std::string rsrcFilename;
-		GLuint glId; ///< The OpenGL ID of the shader program
-		GLuint vertShaderGlId; ///< Vertex shader OpenGL id
-		GLuint geomShaderGlId; ///< Geometry shader OpenGL id
-		GLuint fragShaderGlId; ///< Fragment shader OpenGL id
-
-		/// Shader source that is used in ALL shader programs
-		static const char* stdSourceCode;
-
-		/// @name Containers
-		/// @{
-		boost::ptr_vector<ShaderProgramVariable> vars; ///< All the vars
-		VarsHashMap nameToVar; ///< Variable searching
-		UniVarsHashMap nameToUniVar; ///< Uniform searching
-		AttribVarsHashMap nameToAttribVar; ///< Attribute searching
-		/// @}
-
-		/// Query the driver to get the vars. After the linking of the shader
-		/// prog is done gather all the vars in custom containers
-		void getUniAndAttribVars();
-
-		/// Create and compile shader
-		/// @return The shader's OpenGL id
-		/// @exception Exception
-		uint createAndCompileShader(const char* sourceCode,
-			const char* preproc, int type) const;
-
-		/// Link the shader program
-		/// @exception Exception
-		void link() const;
+public:
+	ShaderProgram();
+	~ShaderProgram();
+
+	/// @name Accessors
+	/// @{
+	GLuint getGlId() const;
+
+	const boost::ptr_vector<ShaderProgramVariable>& getVariables() const
+	{
+		return vars;
+	}
+	/// @}
+
+	/// Resource load
+	void load(const char* filename);
+
+	/// Bind the shader program
+	void bind() const;
+
+	/// @name Variable getters
+	/// Used to find and return the variable. They throw exception if
+	/// variable not found so ask if the variable with that name exists
+	/// prior using any of these
+	/// @{
+	const ShaderProgramVariable& getVariableByName(
+		const char* varName) const;
+	const ShaderProgramUniformVariable& getUniformVariableByName(
+		const char* varName) const;
+	const ShaderProgramAttributeVariable& getAttributeVariableByName(
+		const char* varName) const;
+	/// @}
+
+	/// @name Check for variable existance
+	/// @{
+	bool variableExists(const char* varName) const;
+	bool uniformVariableExists(const char* varName) const;
+	bool attributeVariableExists(const char* varName) const;
+	/// @}
+
+	/// Used by @ref Material and @ref Renderer to create custom shaders in
+	/// the cache
+	/// @param sProgFPathName The file pathname of the shader prog
+	/// @param preAppendedSrcCode The source code we want to write on top
+	/// of the shader prog
+	/// @param newFNamePrefix The prefix of the new shader prog
+	/// @return The file pathname of the new shader prog. Its
+	/// $HOME/.anki/cache/newFNamePrefix_fName
+	static std::string createSrcCodeToCache(const char* sProgFPathName,
+		const char* preAppendedSrcCode);
+
+	/// For debuging
+	std::string getShaderInfoString() const;
+
+	/// For sorting
+	bool operator<(const ShaderProgram& b) const
+	{
+		return glId < b.glId;
+	}
+
+private:
+	/// XXX
+	typedef ConstCharPtrHashMap<ShaderProgramVariable*>::Type VarsHashMap;
+
+	/// XXX
+	typedef ConstCharPtrHashMap<ShaderProgramUniformVariable*>::Type
+		UniVarsHashMap;
+
+	/// XXX
+	typedef ConstCharPtrHashMap<ShaderProgramAttributeVariable*>::Type
+		AttribVarsHashMap;
+
+	std::string rsrcFilename;
+	GLuint glId; ///< The OpenGL ID of the shader program
+	GLuint vertShaderGlId; ///< Vertex shader OpenGL id
+	GLuint geomShaderGlId; ///< Geometry shader OpenGL id
+	GLuint fragShaderGlId; ///< Fragment shader OpenGL id
+
+	/// Shader source that is used in ALL shader programs
+	static const char* stdSourceCode;
+
+	/// @name Containers
+	/// @{
+	boost::ptr_vector<ShaderProgramVariable> vars; ///< All the vars
+	VarsHashMap nameToVar; ///< Variable searching
+	UniVarsHashMap nameToUniVar; ///< Uniform searching
+	AttribVarsHashMap nameToAttribVar; ///< Attribute searching
+	/// @}
+
+	/// Query the driver to get the vars. After the linking of the shader
+	/// prog is done gather all the vars in custom containers
+	void getUniAndAttribVars();
+
+	/// Create and compile shader
+	/// @return The shader's OpenGL id
+	/// @exception Exception
+	uint createAndCompileShader(const char* sourceCode,
+		const char* preproc, int type) const;
+
+	/// Link the shader program
+	/// @exception Exception
+	void link() const;
 }; 
 
 

+ 52 - 49
anki/resource/ShaderProgramVariable.h

@@ -15,55 +15,58 @@ class ShaderProgram;
 /// Shader program variable. The type is attribute or uniform
 class ShaderProgramVariable: public boost::noncopyable
 {
-	public:
-		/// Shader var types
-		enum Type
-		{
-			T_ATTRIBUTE,
-			T_UNIFORM
-		};
-
-		ShaderProgramVariable(GLint loc, const char* name,
-			GLenum glDataType, Type type,
-			const ShaderProgram& fatherSProg);
-
-		/// @name Accessors
-		/// @{
-		const ShaderProgram& getFatherSProg() const
-		{
-			return fatherSProg;
-		}
-
-		GLint getLocation() const
-		{
-			return loc;
-		}
-
-		const std::string& getName() const
-		{
-			return name;
-		}
-
-		GLenum getGlDataType() const
-		{
-			return glDataType;
-		}
-
-		Type getType() const
-		{
-			return type;
-		}
-		/// @}
-
-	private:
-		GLint loc; ///< GL location
-		std::string name; ///< The name inside the shader program
-		/// GL_FLOAT, GL_FLOAT_VEC2 etc. See
-		/// http://www.opengl.org/sdk/docs/man/xhtml/glGetActiveUniform.xml
-		GLenum glDataType;
-		Type type; ///< @ref ATTRIBUTE or @ref UNIFORM
-		/// We need the ShaderProg of this variable mainly for sanity checks
-		const ShaderProgram& fatherSProg;
+public:
+	/// Shader var types
+	enum Type
+	{
+		T_ATTRIBUTE,
+		T_UNIFORM
+	};
+
+	ShaderProgramVariable(GLint loc, const char* name,
+		GLenum glDataType, Type type,
+		const ShaderProgram& fatherSProg);
+
+	virtual ~ShaderProgramVariable()
+	{}
+
+	/// @name Accessors
+	/// @{
+	const ShaderProgram& getFatherSProg() const
+	{
+		return fatherSProg;
+	}
+
+	GLint getLocation() const
+	{
+		return loc;
+	}
+
+	const std::string& getName() const
+	{
+		return name;
+	}
+
+	GLenum getGlDataType() const
+	{
+		return glDataType;
+	}
+
+	Type getType() const
+	{
+		return type;
+	}
+	/// @}
+
+private:
+	GLint loc; ///< GL location
+	std::string name; ///< The name inside the shader program
+	/// GL_FLOAT, GL_FLOAT_VEC2 etc. See
+	/// http://www.opengl.org/sdk/docs/man/xhtml/glGetActiveUniform.xml
+	GLenum glDataType;
+	Type type; ///< @ref ATTRIBUTE or @ref UNIFORM
+	/// We need the ShaderProg of this variable mainly for sanity checks
+	const ShaderProgram& fatherSProg;
 };
 
 

+ 6 - 0
anki/scene/MaterialRuntime.cpp

@@ -19,6 +19,12 @@ MaterialRuntime::MaterialRuntime(const Material& mtl_)
 	// Create vars
 	BOOST_FOREACH(const MaterialVariable& var, mtl.getVariables())
 	{
+		if(var.getShaderProgramVariableType() !=
+			ShaderProgramVariable::T_UNIFORM)
+		{
+			continue;
+		}
+
 		MaterialRuntimeVariable* varr = new MaterialRuntimeVariable(var);
 		vars.push_back(varr);
 		varNameToVar[varr->getMaterialVariable().getName().c_str()] = varr;

+ 8 - 2
anki/scene/MaterialRuntime.h

@@ -62,7 +62,10 @@ class MaterialRuntime: public MaterialProperties
 			shadow = x;
 		}
 
-		using MaterialProperties::getBlendingSfactor;
+		int getBlendingSFactor() const
+		{
+			return blendingSfactor;
+		}
 		int& getBlendingSFactor()
 		{
 			return blendingSfactor;
@@ -72,7 +75,10 @@ class MaterialRuntime: public MaterialProperties
 			blendingSfactor = x;
 		}
 
-		using MaterialProperties::getBlendingDfactor;
+		int getBlendingDFactor() const
+		{
+			return blendingDfactor;
+		}
 		int& getBlendingDFactor()
 		{
 			return blendingDfactor;

+ 5 - 1
anki/scene/MaterialRuntimeVariable.cpp

@@ -17,8 +17,12 @@ void MaterialRuntimeVariable::ConstructVisitor::
 //==============================================================================
 MaterialRuntimeVariable::MaterialRuntimeVariable(
 	const MaterialVariable& mvar_)
-:	mvar(mvar_)
+:	mvar(mvar_),
+ 	buildinId(-1)
 {
+	ANKI_ASSERT(mvar.getShaderProgramVariableType() ==
+		ShaderProgramVariable::T_UNIFORM);
+
 	// Initialize the data using a visitor
 	boost::apply_visitor(ConstructVisitor(*this), mvar.getVariant());
 }

+ 14 - 0
anki/scene/MaterialRuntimeVariable.h

@@ -72,6 +72,19 @@ class MaterialRuntimeVariable
 		{
 			boost::get<Type>(data) = v;
 		}
+
+		int getBuildinId() const
+		{
+			return buildinId;
+		}
+		int& getBuildinId()
+		{
+			return buildinId;
+		}
+		void setBuildinId(const int x)
+		{
+			buildinId = x;
+		}
 		/// @}
 
 	private:
@@ -96,6 +109,7 @@ class MaterialRuntimeVariable
 
 		const MaterialVariable& mvar; ///< Know the resource
 		Variant data; /// The data
+		int buildinId;
 };
 
 

+ 1 - 17
anki/scene/ModelPatchNode.cpp

@@ -10,29 +10,13 @@
 namespace anki {
 
 
-//==============================================================================
-// Constructor                                                                 =
 //==============================================================================
 ModelPatchNode::ModelPatchNode(const ModelPatch& modelPatch, ModelNode& parent)
 :	PatchNode(modelPatch, SNF_NONE, parent)
-{
-	VboArray vboArr;
-
-	for(uint i = 0; i < Mesh::VBOS_NUM; i++)
-	{
-		vboArr[i] = &rsrc.getMesh().getVbo((Mesh::Vbos)i);
-	}
+{}
 
 
-	for(uint i = 0; i < PASS_TYPES_NUM; i++)
-	{
-		createVao(rsrc.getMaterial(), vboArr, vaos[i]);
-	}
-}
-
 
-//==============================================================================
-// moveUpdate                                                                  =
 //==============================================================================
 void ModelPatchNode::moveUpdate()
 {

+ 5 - 0
anki/scene/ModelPatchNode.h

@@ -24,6 +24,11 @@ class ModelPatchNode: public PatchNode
 			return &visibilityShapeWSpace;
 		}
 
+		/// Implements RenderableNode::getVao
+		const Vao& getVao(const PassLevelKey& k) const
+		{
+			return getModelPatchRsrc().getVao(k);
+		}
 
 		void init(const char*)
 		{}

+ 9 - 4
anki/scene/PatchNode.h

@@ -23,16 +23,18 @@ class Material;
 class PatchNode: public RenderableNode
 {
 	public:
+		typedef boost::array<const Vbo*, Mesh::VBOS_NUM> VboArray;
+
 		PatchNode(const ModelPatch& modelPatch, ulong flags,
 			SceneNode& parent);
 
 		/// @name Accessors
 		/// @{
 
-		/// Implements RenderableNode::getMaterial
-		const Material& getMaterial() const
+		/// Implements RenderableNode::getVertIdsNum
+		uint getVertIdsNum(const PassLevelKey& k) const
 		{
-			return rsrc.getMaterial();
+			return rsrc.getMesh().getVertIdsNum();
 		}
 
 		/// Implements RenderableNode::getMaterialRuntime
@@ -47,7 +49,10 @@ class PatchNode: public RenderableNode
 			return *mtlRun;
 		}
 
-		const ModelPatch& getModelPatchRsrc() const {return rsrc;}
+		const ModelPatch& getModelPatchRsrc() const
+		{
+			return rsrc;
+		}
 		/// @}
 
 	protected:

+ 0 - 3
anki/scene/RenderableNode.h

@@ -27,9 +27,6 @@ class RenderableNode: public SceneNode
 		/// Get vert ids number for rendering
 		virtual uint getVertIdsNum(const PassLevelKey& k) const = 0;
 
-		/// Get the material resource
-		virtual const Material& getMaterial() const = 0;
-
 		/// Get the material runtime
 		virtual MaterialRuntime& getMaterialRuntime() = 0;
 

+ 4 - 6
anki/scene/SkinPatchNode.cpp

@@ -15,7 +15,7 @@ namespace anki {
 SkinPatchNode::SkinPatchNode(const ModelPatch& modelPatch_, SkinNode& parent)
 :	PatchNode(modelPatch_, SNF_NONE, parent)
 {
-	VboArray vboArr;
+	ModelPatch::VboArray vboArr;
 
 	for(uint i = 0; i < Mesh::VBOS_NUM; i++)
 	{
@@ -114,11 +114,9 @@ SkinPatchNode::SkinPatchNode(const ModelPatch& modelPatch_, SkinNode& parent)
 		sizeof(MeshData::VertexWeight),
 		BUFFER_OFFSET(20));
 
-	// Create the rendering VAOs
-	for(uint i = 0; i < PASS_TYPES_NUM; i++)
-	{
-		createVao(mtlRun, vboArr, vaos[i]);
-	}
+
+	ModelPatch::createVaos(getMaterialRuntime().getMaterial(),
+		vboArr, vaos, vaosHashMap);
 }
 
 

+ 8 - 1
anki/scene/SkinPatchNode.h

@@ -52,10 +52,17 @@ class SkinPatchNode: public PatchNode
 		{
 			return tfVbos[i];
 		}
+
+		const Vao& getVao(const PassLevelKey& k) const
+		{
+			return *vaosHashMap.at(k);
+		}
 		/// @}
 
 	private:
-		/// VBOs that contain the deformed vertex attributes
+		ModelPatch::VaosContainer vaos;
+		ModelPatch::PassLevelToVaoHashMap vaosHashMap;
+
 		boost::array<Vbo, TFV_NUM> tfVbos;
 		Vao tfVao; ///< For TF passes
 };

+ 4 - 4
anki/scene/VisibilityTester.cpp

@@ -232,7 +232,7 @@ void VisibilityTester::getRenderableNodesJobCallback(
 
 			// Skip shadowless
 			if(skipShadowless &&
-				!modelPatchNode->getMaterialRuntime().getCastShadow())
+				!modelPatchNode->getMaterialRuntime().getShadow())
 			{
 				continue;
 			}
@@ -241,7 +241,7 @@ void VisibilityTester::getRenderableNodesJobCallback(
 			if(test(*modelPatchNode, cam))
 			{
 				if(modelPatchNode->getMaterialRuntime().
-					getRenderInBledingStage())
+					getRenderingStage() == 1)
 				{
 					bsVisibles[bsI++] = modelPatchNode;
 				}
@@ -296,12 +296,12 @@ void VisibilityTester::getRenderableNodesJobCallback(
 
 			// Skip shadowless
 			if(skipShadowless &&
-				!patchNode->getMaterialRuntime().getCastShadow())
+				!patchNode->getMaterialRuntime().getShadow())
 			{
 				continue;
 			}
 
-			if(patchNode->getMaterialRuntime().getRenderInBledingStage())
+			if(patchNode->getMaterialRuntime().getRenderingStage() == 1)
 			{
 				bsVisibles[bsI++] = patchNode;
 			}

+ 1 - 0
anki/script/ScriptManager.cpp

@@ -6,6 +6,7 @@
 #include <Python.h>
 
 
+using namespace boost;
 using namespace boost::python;
 
 

+ 2 - 2
anki/script/scene/MaterialRuntime.cpp

@@ -5,13 +5,13 @@
 WRAP(MaterialRuntime)
 {
 	class_<MaterialRuntime, noncopyable>("MaterialRuntime", no_init)
-		.def("getVariables",
+		/*.def("getVariables",
 			(MaterialRuntime::VariablesContainer&
 			(MaterialRuntime::*)())(&MaterialRuntime::getVariables),
 			return_value_policy<reference_existing_object>())
 
 		.def("getWireframe", (bool (MaterialRuntime::*)() const)(
 			&MaterialRuntime::getWireframe))
-		.def("setWireframe", &MaterialRuntime::setWireframe)
+		.def("setWireframe", &MaterialRuntime::setWireframe)*/
 	;
 }

+ 1 - 0
shaders/MaterialFragmentFunctions.glsl

@@ -1,3 +1,4 @@
+///
 #pragma anki include "shaders/Pack.glsl"
 
 

+ 3 - 5
shaders/MaterialVertex.glsl

@@ -30,11 +30,8 @@ out vec3 vVertPosViewSpace; ///< For env mapping. AKA view vector
 /// @}
 
 
-
-//==============================================================================
-// main                                                                        =
-//==============================================================================
-void main()
+/// Calculate the position and the varyings
+void doVertex()
 {
 #if defined(COLOR_PASS)
 	vNormal = normalMat * normal;
@@ -47,3 +44,4 @@ void main()
 
 	gl_Position = modelViewProjectionMat * vec4(position, 1.0);
 }
+

+ 2 - 2
testapp/Main.cpp

@@ -182,10 +182,10 @@ void init()
 	pentagram->setLocalTransform(Transform(Vec3(2, 0, 0), Mat3::getIdentity(), 1.0));*/
 
 	// Sponza
-	ModelNode* sponza = new ModelNode(scene, SceneNode::SNF_NONE, NULL);
+	/*ModelNode* sponza = new ModelNode(scene, SceneNode::SNF_NONE, NULL);
 	//sponza->init("maps/sponza/sponza.mdl");
 	sponza->init("maps/sponza-crytek/sponza_crytek.mdl");
-	sponza->setLocalTransform(Transform(Vec3(0.0), Mat3::getIdentity(), 0.05));
+	sponza->setLocalTransform(Transform(Vec3(0.0), Mat3::getIdentity(), 0.05));*/
 
 
 	// Imp