Sfoglia il codice sorgente

- Refactoring. Moving a few classes in a single huge file

Panagiotis Christopoulos Charitos 14 anni fa
parent
commit
3012164bd2

+ 117 - 18
anki/resource/Material.cpp

@@ -1,10 +1,10 @@
 #include "anki/resource/Material.h"
 #include "anki/resource/Material.h"
-#include "anki/resource/MaterialVariable.h"
 #include "anki/misc/PropertyTree.h"
 #include "anki/misc/PropertyTree.h"
 #include "anki/resource/MaterialShaderProgramCreator.h"
 #include "anki/resource/MaterialShaderProgramCreator.h"
 #include "anki/core/App.h"
 #include "anki/core/App.h"
 #include "anki/core/Globals.h"
 #include "anki/core/Globals.h"
 #include "anki/resource/ShaderProgram.h"
 #include "anki/resource/ShaderProgram.h"
+#include "anki/resource/Texture.h"
 #include <boost/foreach.hpp>
 #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>
@@ -19,14 +19,86 @@ namespace anki {
 
 
 
 
 //==============================================================================
 //==============================================================================
-// Statics                                                                     =
+// MaterialVariable                                                            =
+//==============================================================================
+
+//==============================================================================
+MaterialVariable::~MaterialVariable()
+{}
+
+
+//==============================================================================
+GLenum MaterialVariable::getGlDataType() const
+{
+	return oneSProgVar->getGlDataType();
+}
+
+
+//==============================================================================
+const std::string& MaterialVariable::getName() const
+{
+	return oneSProgVar->getName();
+}
+
+
+//==============================================================================
+void MaterialVariable::init(const char* shaderProgVarName,
+	const PassLevelToShaderProgramHashMap& sProgs)
+{
+	oneSProgVar = NULL;
+
+	// For all programs
+	PassLevelToShaderProgramHashMap::const_iterator it = sProgs.begin();
+	for(; it != sProgs.end(); ++it)
+	{
+		const ShaderProgram& sProg = *(it->second);
+		const PassLevelKey& key = it->first;
+
+		// Variable exists
+		if(sProg.uniformVariableExists(shaderProgVarName))
+		{
+			const ShaderProgramUniformVariable& sProgVar =
+				sProg.findUniformVariableByName(shaderProgVarName);
+
+			sProgVars[key] = &sProgVar;
+
+			// Set oneSProgVar
+			if(!oneSProgVar)
+			{
+				oneSProgVar = &sProgVar;
+			}
+
+			// Sanity check: All the sprog vars need to have same GL data type
+			if(oneSProgVar->getGlDataType() != sProgVar.getGlDataType() ||
+				oneSProgVar->getType() != sProgVar.getType())
+			{
+				throw ANKI_EXCEPTION("Incompatible shader "
+					"program variables: " +
+					shaderProgVarName);
+			}
+		}
+	}
+
+	// Extra sanity checks
+	if(!oneSProgVar)
+	{
+		throw ANKI_EXCEPTION("Variable not found in "
+			"any of the shader programs: " +
+			shaderProgVarName);
+	}
+}
+
+
+//==============================================================================
+// Material                                                                    =
+//==============================================================================
+
 //==============================================================================
 //==============================================================================
 
 
 // Dont make idiotic mistakes
 // Dont make idiotic mistakes
 #define TXT_AND_ENUM(x) \
 #define TXT_AND_ENUM(x) \
 	(#x, x)
 	(#x, x)
 
 
-
 ConstCharPtrHashMap<GLenum>::Type Material::txtToBlengGlEnum =
 ConstCharPtrHashMap<GLenum>::Type Material::txtToBlengGlEnum =
 	boost::assign::map_list_of
 	boost::assign::map_list_of
 	TXT_AND_ENUM(GL_ZERO)
 	TXT_AND_ENUM(GL_ZERO)
@@ -252,22 +324,18 @@ void Material::populateVariables(const boost::property_tree::ptree& pt)
 	using namespace boost::property_tree;
 	using namespace boost::property_tree;
 
 
 	//
 	//
-	// Get all names of all shader prog vars. Dont duplicate
+	// Get all names of all the uniforms. Dont duplicate
 	//
 	//
 	std::map<std::string, GLenum> allVarNames;
 	std::map<std::string, GLenum> allVarNames;
 
 
 	BOOST_FOREACH(const ShaderProgramResourcePointer& sProg, sProgs)
 	BOOST_FOREACH(const ShaderProgramResourcePointer& sProg, sProgs)
 	{
 	{
-		BOOST_FOREACH(const ShaderProgramVariable& v, sProg->getVariables())
+		BOOST_FOREACH(const ShaderProgramUniformVariable* v,
+			sProg->getUniformVariables())
 		{
 		{
-			if(v.getType() != ShaderProgramVariable::T_UNIFORM)
-			{
-				continue;
-			}
+			allVarNames[v->getName()] = v->getGlDataType();
 
 
-			allVarNames[v.getName()] = v.getGlDataType();
-
-			ANKI_INFO("--" << v.getName());
+			ANKI_INFO("--" << v->getName());
 		}
 		}
 	}
 	}
 
 
@@ -338,7 +406,38 @@ void Material::populateVariables(const boost::property_tree::ptree& pt)
 		{
 		{
 			ANKI_INFO("No value for " << name);
 			ANKI_INFO("No value for " << name);
 
 
-			v = new MaterialVariable(name.c_str(), eSProgs);
+			// Get the value
+			switch(dataType)
+			{
+				// sampler2D
+				case GL_SAMPLER_2D:
+					v = new MaterialVariable(name.c_str(), eSProgs,
+						TextureResourcePointer(), false);
+					break;
+				// float
+				case GL_FLOAT:
+					v = new MaterialVariable(name.c_str(), eSProgs,
+						float(), false);
+					break;
+				// vec2
+				case GL_FLOAT_VEC2:
+					v = new MaterialVariable(name.c_str(), eSProgs,
+						Vec2(), false);
+					break;
+				// vec3
+				case GL_FLOAT_VEC3:
+					v = new MaterialVariable(name.c_str(), eSProgs,
+						Vec3(), false);
+					break;
+				// vec4
+				case GL_FLOAT_VEC4:
+					v = new MaterialVariable(name.c_str(), eSProgs,
+						Vec4(), false);
+					break;
+				// default is error
+				default:
+					ANKI_ASSERT(0);
+			}
 		}
 		}
 		else
 		else
 		{
 		{
@@ -352,27 +451,27 @@ void Material::populateVariables(const boost::property_tree::ptree& pt)
 				// sampler2D
 				// sampler2D
 				case GL_SAMPLER_2D:
 				case GL_SAMPLER_2D:
 					v = new MaterialVariable(name.c_str(), eSProgs,
 					v = new MaterialVariable(name.c_str(), eSProgs,
-						value);
+						TextureResourcePointer(value.c_str()), true);
 					break;
 					break;
 				// float
 				// float
 				case GL_FLOAT:
 				case GL_FLOAT:
 					v = new MaterialVariable(name.c_str(), eSProgs,
 					v = new MaterialVariable(name.c_str(), eSProgs,
-						boost::lexical_cast<float>(value));
+						boost::lexical_cast<float>(value), true);
 					break;
 					break;
 				// vec2
 				// vec2
 				case GL_FLOAT_VEC2:
 				case GL_FLOAT_VEC2:
 					v = new MaterialVariable(name.c_str(), eSProgs,
 					v = new MaterialVariable(name.c_str(), eSProgs,
-						setMathType<Vec2, 2>(value.c_str()));
+						setMathType<Vec2, 2>(value.c_str()), true);
 					break;
 					break;
 				// vec3
 				// vec3
 				case GL_FLOAT_VEC3:
 				case GL_FLOAT_VEC3:
 					v = new MaterialVariable(name.c_str(), eSProgs,
 					v = new MaterialVariable(name.c_str(), eSProgs,
-						setMathType<Vec3, 3>(value.c_str()));
+						setMathType<Vec3, 3>(value.c_str()), true);
 					break;
 					break;
 				// vec4
 				// vec4
 				case GL_FLOAT_VEC4:
 				case GL_FLOAT_VEC4:
 					v = new MaterialVariable(name.c_str(), eSProgs,
 					v = new MaterialVariable(name.c_str(), eSProgs,
-						setMathType<Vec4, 4>(value.c_str()));
+						setMathType<Vec4, 4>(value.c_str()), true);
 					break;
 					break;
 				// default is error
 				// default is error
 				default:
 				default:

+ 173 - 3
anki/resource/Material.h

@@ -2,22 +2,192 @@
 #define ANKI_RESOURCE_MATERIAL_H
 #define ANKI_RESOURCE_MATERIAL_H
 
 
 #include "anki/resource/MaterialCommon.h"
 #include "anki/resource/MaterialCommon.h"
-#include "anki/resource/MaterialProperties.h"
-#include "anki/resource/MaterialVariable.h"
 #include "anki/resource/Resource.h"
 #include "anki/resource/Resource.h"
 #include "anki/util/ConstCharPtrHashMap.h"
 #include "anki/util/ConstCharPtrHashMap.h"
+#include "anki/util/StringList.h"
+#include "anki/math/Math.h"
 #include <GL/glew.h>
 #include <GL/glew.h>
 #include <boost/ptr_container/ptr_vector.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
 #include <boost/array.hpp>
 #include <boost/array.hpp>
 #include <boost/scoped_ptr.hpp>
 #include <boost/scoped_ptr.hpp>
 #include <boost/property_tree/ptree_fwd.hpp>
 #include <boost/property_tree/ptree_fwd.hpp>
 #include <boost/range/iterator_range.hpp>
 #include <boost/range/iterator_range.hpp>
+#include <boost/noncopyable.hpp>
+#include <boost/variant.hpp>
 
 
 
 
 namespace anki {
 namespace anki {
 
 
 
 
 class ShaderProgram;
 class ShaderProgram;
+class ShaderProgramUniformVariable;
+
+
+/// Holds the shader variables. Its a container for shader program variables
+/// that share the same name
+class MaterialVariable: public boost::noncopyable
+{
+public:
+	/// 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 uniform variable. The pointer may be null
+	typedef PassLevelHashMap<const ShaderProgramUniformVariable*>::Type
+		PassLevelToShaderProgramUniformVariableHashMap;
+
+	/// @name Constructors & destructor
+	/// @{
+	template<typename Type>
+	MaterialVariable(
+		const char* shaderProgVarName,
+		const PassLevelToShaderProgramHashMap& sProgs,
+		const Type& val,
+		bool init_)
+		: initialized(init_)
+	{
+		init(shaderProgVarName, sProgs);
+		data = val;
+	}
+
+	~MaterialVariable();
+	/// @}
+
+	/// @name Accessors
+	/// @{
+	const Variant& getVariant() const
+	{
+		return data;
+	}
+
+	/// Given a key return the uniform
+	const ShaderProgramUniformVariable& getShaderProgramUniformVariable(
+		const PassLevelKey& key) const
+	{
+		ANKI_ASSERT(inPass(key));
+		const ShaderProgramUniformVariable* var = sProgVars.at(key);
+		ANKI_ASSERT(var != NULL);
+		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;
+
+	/// Get the name of all the shader program variables
+	const std::string& getName() const;
+
+	bool getInitialized() const
+	{
+		return initialized;
+	}
+	/// @}
+
+private:
+	/// If not initialized then the renderer should set the value
+	bool initialized;
+	PassLevelToShaderProgramUniformVariableHashMap sProgVars;
+	Variant data;
+
+	/// Keep one ShaderProgramVariable here for easy access of the common
+	/// variable stuff like name or GL data type etc
+	const ShaderProgramUniformVariable* oneSProgVar;
+
+	/// Common constructor code
+	void init(const char* shaderProgVarName,
+		const PassLevelToShaderProgramHashMap& shaderProgsArr);
+};
+
+
+/// Contains a few properties that other classes may use. For an explanation of
+/// 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;
+
+	bool shadow;
+
+	int blendingSfactor; ///< Default GL_ONE
+	int blendingDfactor; ///< Default GL_ZERO
+
+	bool depthTesting;
+
+	bool wireframe;
+};
 
 
 
 
 /// Material resource
 /// Material resource
@@ -97,7 +267,7 @@ class ShaderProgram;
 /// (4): AKA uniforms
 /// (4): AKA uniforms
 ///
 ///
 /// (5): The order of the shaders is crucial
 /// (5): The order of the shaders is crucial
-class Material: public MaterialProperties
+class Material: public MaterialProperties, public boost::noncopyable
 {
 {
 public:
 public:
 	typedef boost::ptr_vector<MaterialVariable> VarsContainer;
 	typedef boost::ptr_vector<MaterialVariable> VarsContainer;

+ 0 - 99
anki/resource/MaterialProperties.h

@@ -1,99 +0,0 @@
-#ifndef ANKI_RESOURCE_MATERIAL_PROPERTIES_H
-#define ANKI_RESOURCE_MATERIAL_PROPERTIES_H
-
-#include "anki/util/StringList.h"
-#include "anki/util/StdTypes.h"
-#include <GL/glew.h>
-
-
-namespace anki {
-
-
-/// Contains a few properties that other classes may use. For an explanation of
-/// 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;
-
-	bool shadow;
-
-	int blendingSfactor; ///< Default GL_ONE
-	int blendingDfactor; ///< Default GL_ZERO
-
-	bool depthTesting;
-	
-	bool wireframe;
-};
-
-
-} // end namespace
-
-
-#endif

+ 0 - 85
anki/resource/MaterialVariable.cpp

@@ -1,85 +0,0 @@
-#include "anki/resource/MaterialVariable.h"
-#include "anki/resource/ShaderProgramVariable.h"
-#include "anki/resource/ShaderProgram.h"
-#include "anki/util/Assert.h"
-#include "anki/util/Exception.h"
-
-
-namespace anki {
-
-
-//==============================================================================
-MaterialVariable::MaterialVariable(
-	const char* shaderProgVarName,
-	const PassLevelToShaderProgramHashMap& sProgs)
-	: type(T_BUILDIN)
-{
-	init(shaderProgVarName, sProgs);
-}
-
-
-//==============================================================================
-template <>
-MaterialVariable::MaterialVariable(
-	const char* shaderProgVarName,
-	const PassLevelToShaderProgramHashMap& sProgs,
-	const std::string& val)
-	: initialized(true)
-{
-	init(shaderProgVarName, sProgs);
-	data = TextureResourcePointer();
-	boost::get<TextureResourcePointer>(data).load(val.c_str());
-}
-
-
-//==============================================================================
-void MaterialVariable::init(const char* shaderProgVarName,
-	const PassLevelToShaderProgramHashMap& sProgs)
-{
-	oneSProgVar = NULL;
-
-	// For all sprogs
-	PassLevelToShaderProgramHashMap::const_iterator it = sProgs.begin();
-	for(; it != sProgs.end(); ++it)
-	{
-		const ShaderProgram& sProg = *(it->second);
-		const PassLevelKey& key = it->first;
-
-		if(sProg.uniformVariableExists(shaderProgVarName))
-		{
-			const ShaderProgramUniformVariable& sProgVar =
-				sProg.findUniformVariableByName(shaderProgVarName);
-
-			sProgVars[key] = &sProgVar;
-
-			if(!oneSProgVar)
-			{
-				oneSProgVar = &sProgVar;
-			}
-
-			// Sanity check: All the sprog vars need to have same GL data type
-			if(oneSProgVar->getGlDataType() != sProgVar.getGlDataType() ||
-				oneSProgVar->getType() != sProgVar.getType())
-			{
-				throw ANKI_EXCEPTION("Incompatible shader "
-					"program variables: " +
-					shaderProgVarName);
-			}
-		}
-		else
-		{
-			sProgVars[key] = NULL;
-		}
-	}
-
-	// Extra sanity checks
-	if(!oneSProgVar)
-	{
-		throw ANKI_EXCEPTION("Variable not found in "
-			"any of the shader programs: " +
-			shaderProgVarName);
-	}
-}
-
-
-} // end namespace

+ 0 - 126
anki/resource/MaterialVariable.h

@@ -1,126 +0,0 @@
-#ifndef ANKI_RESOURCE_MATERIAL_VARIABLE_H
-#define ANKI_RESOURCE_MATERIAL_VARIABLE_H
-
-#include "anki/resource/ShaderProgramUniformVariable.h"
-#include "anki/resource/MaterialCommon.h"
-#include "anki/math/Math.h"
-#include "anki/resource/Resource.h"
-#include "anki/resource/Texture.h" // For one of the constructors
-#include "anki/util/Assert.h"
-#include <GL/glew.h>
-#include <string>
-#include <boost/variant.hpp>
-
-
-namespace anki {
-
-
-/// Holds the shader variables. Its a container for shader program variables
-/// that share the same name
-class MaterialVariable
-{
-public:
-	/// 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 uniform variable. The pointer may be null
-	typedef PassLevelHashMap<const ShaderProgramUniformVariable*>::Type
-		PassLevelToShaderProgramUniformVariableHashMap;
-
-	/// @name Constructors & destructor
-	/// @{
-
-	/// For build-ins
-	template<typename Type>
-	MaterialVariable(
-		const char* shaderProgVarName,
-		const PassLevelToShaderProgramHashMap& sProgs)
-		: initialized(false)
-	{
-		init(shaderProgVarName, sProgs);
-		data = Type();
-	}
-
-	/// For user defined
-	template<typename Type>
-	MaterialVariable(
-		const char* shaderProgVarName,
-		const PassLevelToShaderProgramHashMap& sProgs,
-		const Type& val)
-		: initialized(true)
-	{
-		init(shaderProgVarName, sProgs);
-		data = val;
-	}
-	/// @}
-		
-	/// @name Accessors
-	/// @{
-	const Variant& getVariant() const
-	{
-		return data;
-	}
-
-	/// XXX
-	const ShaderProgramUniformVariable& getShaderProgramUniformVariable(
-		const PassLevelKey& key) const
-	{
-		ANKI_ASSERT(inPass(key));
-		const ShaderProgramUniformVariable* 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();
-	}
-
-	bool getInitialized() const
-	{
-		return initialized;
-	}
-	/// @}
-
-private:
-	bool initialized;
-	PassLevelToShaderProgramUniformVariableHashMap sProgVars;
-	Variant data;
-
-	/// Keep one ShaderProgramVariable here for easy access of the common
-	/// variable stuff like name or GL data type etc
-	const ShaderProgramUniformVariable* oneSProgVar;
-
-	/// Common constructor code
-	void init(const char* shaderProgVarName,
-		const PassLevelToShaderProgramHashMap& shaderProgsArr);
-};
-
-
-/// Declaration for specialized XXX
-template<>
-MaterialVariable::MaterialVariable(
-	const char* shaderProgVarName,
-	const PassLevelToShaderProgramHashMap& sProgs,
-	const std::string& val);
-
-
-} // end namespace
-
-
-#endif

+ 5 - 4
anki/resource/ModelPatch.cpp

@@ -1,6 +1,7 @@
 #include "anki/resource/ModelPatch.h"
 #include "anki/resource/ModelPatch.h"
 #include "anki/resource/Mesh.h"
 #include "anki/resource/Mesh.h"
 #include "anki/resource/Material.h"
 #include "anki/resource/Material.h"
+#include "anki/resource/ShaderProgram.h"
 
 
 
 
 namespace anki {
 namespace anki {
@@ -43,7 +44,7 @@ Vao* ModelPatch::createVao(const Material& mtl,
 {
 {
 	Vao* vao = new Vao;
 	Vao* vao = new Vao;
 
 
-	if(mtl.variableExistsAndInKey("position", key))
+	if(mtl.getShaderProgram(key).uniformVariableExists("position"))
 	{
 	{
 		ANKI_ASSERT(vbos[Mesh::VBO_VERT_POSITIONS] != NULL);
 		ANKI_ASSERT(vbos[Mesh::VBO_VERT_POSITIONS] != NULL);
 
 
@@ -51,7 +52,7 @@ Vao* ModelPatch::createVao(const Material& mtl,
 			0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
 			0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
 	}
 	}
 
 
-	if(mtl.variableExistsAndInKey("normal", key))
+	if(mtl.getShaderProgram(key).uniformVariableExists("normal"))
 	{
 	{
 		ANKI_ASSERT(vbos[Mesh::VBO_VERT_NORMALS] != NULL);
 		ANKI_ASSERT(vbos[Mesh::VBO_VERT_NORMALS] != NULL);
 
 
@@ -59,7 +60,7 @@ Vao* ModelPatch::createVao(const Material& mtl,
 			1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
 			1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
 	}
 	}
 
 
-	if(mtl.variableExistsAndInKey("tangent", key))
+	if(mtl.getShaderProgram(key).uniformVariableExists("tangent"))
 	{
 	{
 		ANKI_ASSERT(vbos[Mesh::VBO_VERT_TANGENTS] != NULL);
 		ANKI_ASSERT(vbos[Mesh::VBO_VERT_TANGENTS] != NULL);
 
 
@@ -67,7 +68,7 @@ Vao* ModelPatch::createVao(const Material& mtl,
 			2, 4, GL_FLOAT, GL_FALSE, 0, NULL);
 			2, 4, GL_FLOAT, GL_FALSE, 0, NULL);
 	}
 	}
 
 
-	if(mtl.variableExistsAndInKey("texCoords", key))
+	if(mtl.getShaderProgram(key).uniformVariableExists("texCoords"))
 	{
 	{
 		vao->attachArrayBufferVbo(*vbos[Mesh::VBO_TEX_COORDS],
 		vao->attachArrayBufferVbo(*vbos[Mesh::VBO_TEX_COORDS],
 			3, 2, GL_FLOAT, GL_FALSE, 0, NULL);
 			3, 2, GL_FLOAT, GL_FALSE, 0, NULL);

+ 2 - 2
anki/resource/ModelPatch.h

@@ -14,8 +14,8 @@ namespace anki {
 class Material;
 class Material;
 
 
 
 
-/// Its one part of the many used in the Model class. Its basically a container
-/// for a Mesh and it's Material
+/// Its a chunk of a model. Its very important class and it binds the material
+/// with the mesh
 class ModelPatch
 class ModelPatch
 {
 {
 public:
 public:

+ 3 - 5
anki/resource/PassLevelKey.h

@@ -14,16 +14,14 @@ struct PassLevelKey
 	uint level;
 	uint level;
 
 
 	PassLevelKey()
 	PassLevelKey()
-	:	pass(0),
-	 	level(0)
+		: pass(0), level(0)
 	{}
 	{}
 
 
 	PassLevelKey(uint pass_, uint level_)
 	PassLevelKey(uint pass_, uint level_)
-	:	pass(pass_),
-	 	level(level_)
+		: pass(pass_), level(level_)
 	{}
 	{}
 
 
-	/// Hash creation method
+	/// Create hash
 	size_t operator()(const PassLevelKey& b) const
 	size_t operator()(const PassLevelKey& b) const
 	{
 	{
 		return pass * 1000 + level;
 		return pass * 1000 + level;

+ 12 - 4
anki/resource/ResourcePointer.h

@@ -19,16 +19,23 @@ public:
 
 
 	/// Default constructor
 	/// Default constructor
 	ResourcePointer()
 	ResourcePointer()
-	:	hook(NULL)
+		: hook(NULL)
 	{}
 	{}
 
 
 	/// Copy constructor
 	/// Copy constructor
 	ResourcePointer(const Self& b)
 	ResourcePointer(const Self& b)
-	:	hook(NULL)
+		: hook(NULL)
 	{
 	{
 		copy(b);
 		copy(b);
 	}
 	}
 
 
+	/// Construct and load
+	ResourcePointer(const char* filename)
+		: hook(NULL)
+	{
+		load(filename);
+	}
+
 	~ResourcePointer()
 	~ResourcePointer()
 	{
 	{
 		unload();
 		unload();
@@ -74,7 +81,7 @@ public:
 	}
 	}
 
 
 private:
 private:
-	/// Points to a container in the resource manager
+	/// Points to an element located in a container in the resource manager
 	Hook* hook;
 	Hook* hook;
 
 
 	/// Unloads the resource @see loadRsrc
 	/// Unloads the resource @see loadRsrc
@@ -87,7 +94,8 @@ private:
 		}
 		}
 	}
 	}
 
 
-	/// XXX
+	/// If this empty and @a b empty then unload. If @a b has something then
+	/// unload this and load exactly what @b has. In everything else do nothing
 	void copy(const Self& b)
 	void copy(const Self& b)
 	{
 	{
 		if(b.hook == NULL)
 		if(b.hook == NULL)

+ 109 - 0
anki/resource/ShaderProgram.cpp

@@ -3,9 +3,11 @@
 #include "anki/core/App.h" // To get cache dir
 #include "anki/core/App.h" // To get cache dir
 #include "anki/gl/GlException.h"
 #include "anki/gl/GlException.h"
 #include "anki/core/Logger.h"
 #include "anki/core/Logger.h"
+#include "anki/math/Math.h"
 #include "anki/util/Util.h"
 #include "anki/util/Util.h"
 #include "anki/core/Globals.h"
 #include "anki/core/Globals.h"
 #include "anki/util/Exception.h"
 #include "anki/util/Exception.h"
+#include "anki/resource/Texture.h"
 #include <boost/filesystem.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/foreach.hpp>
 #include <boost/foreach.hpp>
@@ -17,6 +19,113 @@
 namespace anki {
 namespace anki {
 
 
 
 
+//==============================================================================
+// ShaderProgramVariable                                                       =
+//==============================================================================
+
+//==============================================================================
+void ShaderProgramUniformVariable::doSanityChecks() const
+{
+	ANKI_ASSERT(getLocation() != -1);
+	ANKI_ASSERT(GlStateMachineSingleton::get().getCurrentProgramGlId() ==
+		getFatherSProg().getGlId());
+	ANKI_ASSERT(glGetUniformLocation(getFatherSProg().getGlId(),
+		getName().c_str()) == getLocation());
+}
+
+
+//==============================================================================
+void ShaderProgramUniformVariable::set(const float x) const
+{
+	doSanityChecks();
+	ANKI_ASSERT(getGlDataType() == GL_FLOAT);
+
+	glUniform1f(getLocation(), x);
+}
+
+
+//==============================================================================
+void ShaderProgramUniformVariable::set(const Vec2& x) const
+{
+	glUniform2f(getLocation(), x.x(), x.y());
+}
+
+
+//==============================================================================
+void ShaderProgramUniformVariable::set(const float x[], uint size) const
+{
+	doSanityChecks();
+	ANKI_ASSERT(getGlDataType() == GL_FLOAT);
+	ANKI_ASSERT(size > 1);
+	glUniform1fv(getLocation(), size, x);
+}
+
+
+//==============================================================================
+void ShaderProgramUniformVariable::set(const Vec2 x[], uint size) const
+{
+	doSanityChecks();
+	ANKI_ASSERT(getGlDataType() == GL_FLOAT_VEC2);
+	ANKI_ASSERT(size > 1);
+	glUniform2fv(getLocation(), size, &(const_cast<Vec2&>(x[0]))[0]);
+}
+
+
+//==============================================================================
+void ShaderProgramUniformVariable::set(const Vec3 x[], uint size) const
+{
+	doSanityChecks();
+	ANKI_ASSERT(getGlDataType() == GL_FLOAT_VEC3);
+	ANKI_ASSERT(size > 0);
+	glUniform3fv(getLocation(), size, &(const_cast<Vec3&>(x[0]))[0]);
+}
+
+
+//==============================================================================
+void ShaderProgramUniformVariable::set(const Vec4 x[], uint size) const
+{
+	doSanityChecks();
+	ANKI_ASSERT(getGlDataType() == GL_FLOAT_VEC4);
+	ANKI_ASSERT(size > 0);
+	glUniform4fv(getLocation(), size, &(const_cast<Vec4&>(x[0]))[0]);
+}
+
+
+//==============================================================================
+void ShaderProgramUniformVariable::set(const Mat3 x[], uint size) const
+{
+	doSanityChecks();
+	ANKI_ASSERT(getGlDataType() == GL_FLOAT_MAT3);
+	ANKI_ASSERT(size > 0);
+	glUniformMatrix3fv(getLocation(), size, true, &(x[0])[0]);
+}
+
+
+//==============================================================================
+void ShaderProgramUniformVariable::set(const Mat4 x[], uint size) const
+{
+	doSanityChecks();
+	ANKI_ASSERT(getGlDataType() == GL_FLOAT_MAT4);
+	ANKI_ASSERT(size > 0);
+	glUniformMatrix4fv(getLocation(), size, true, &(x[0])[0]);
+}
+
+
+//==============================================================================
+void ShaderProgramUniformVariable::set(const Texture& tex, uint texUnit) const
+{
+	doSanityChecks();
+	ANKI_ASSERT(getGlDataType() == GL_SAMPLER_2D ||
+		getGlDataType() == GL_SAMPLER_2D_SHADOW);
+	tex.bind(texUnit);
+	glUniform1i(getLocation(), texUnit);
+}
+
+
+//==============================================================================
+// ShaderProgram                                                               =
+//==============================================================================
+
 //==============================================================================
 //==============================================================================
 
 
 #define SHADER_PROGRAM_EXCEPTION(x) ANKI_EXCEPTION( \
 #define SHADER_PROGRAM_EXCEPTION(x) ANKI_EXCEPTION( \

+ 140 - 5
anki/resource/ShaderProgram.h

@@ -3,8 +3,7 @@
 
 
 #include "anki/util/ConstCharPtrHashMap.h"
 #include "anki/util/ConstCharPtrHashMap.h"
 #include "anki/util/Assert.h"
 #include "anki/util/Assert.h"
-#include "anki/resource/ShaderProgramUniformVariable.h"
-#include "anki/resource/ShaderProgramAttributeVariable.h"
+#include "anki/math/Forward.h"
 #include "anki/gl/GlStateMachine.h"
 #include "anki/gl/GlStateMachine.h"
 #include "anki/core/Globals.h"
 #include "anki/core/Globals.h"
 #include <boost/ptr_container/ptr_vector.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
@@ -16,6 +15,141 @@
 namespace anki {
 namespace anki {
 
 
 
 
+class ShaderProgram;
+class Texture;
+
+
+/// 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_)
+		: loc(loc_), name(name_), glDataType(glDataType_), type(type_),
+			fatherSProg(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 T_ATTRIBUTE or @ref T_UNIFORM
+	/// We need the ShaderProg of this variable mainly for sanity checks
+	const ShaderProgram& fatherSProg;
+};
+
+
+/// Uniform shader variable
+class ShaderProgramUniformVariable: public ShaderProgramVariable
+{
+public:
+	ShaderProgramUniformVariable(
+		int loc,
+		const char* name,
+		GLenum glDataType,
+		const ShaderProgram& fatherSProg)
+		: ShaderProgramVariable(loc, name, glDataType, T_UNIFORM, fatherSProg)
+	{}
+
+	/// @name Set the var
+	/// @{
+	void set(const float x) const;
+	void set(const Vec2& x) const;
+	void set(const Vec3& x) const
+	{
+		set(&x, 1);
+	}
+	void set(const Vec4& x) const
+	{
+		set(&x, 1);
+	}
+	void set(const Mat3& x) const
+	{
+		set(&x, 1);
+	}
+	void set(const Mat4& x) const
+	{
+		set(&x, 1);
+	}
+	void set(const Texture& tex, uint texUnit) const;
+
+	void set(const float x[], uint size) const;
+	void set(const Vec2 x[], uint size) const;
+	void set(const Vec3 x[], uint size) const;
+	void set(const Vec4 x[], uint size) const;
+	void set(const Mat3 x[], uint size) const;
+	void set(const Mat4 x[], uint size) const;
+
+	/// @tparam Type float, Vec2, etc
+	template<typename Type>
+	void set(const std::vector<Type>& c)
+	{
+		set(&c[0], c.size());
+	}
+	/// @}
+
+private:
+	/// Standard set uniform checks
+	/// - Check if initialized
+	/// - if the current shader program is the var's shader program
+	/// - if the GL driver gives the same location as the one the var has
+	void doSanityChecks() const;
+};
+
+
+/// Attribute shader program variable
+class ShaderProgramAttributeVariable: public ShaderProgramVariable
+{
+public:
+	ShaderProgramAttributeVariable(
+		int loc_, const char* name_, GLenum glDataType_,
+		const ShaderProgram& fatherSProg_)
+		: ShaderProgramVariable(loc_, name_, glDataType_, T_ATTRIBUTE,
+			fatherSProg_)
+	{}
+};
+
+
 /// Shader program resource
 /// Shader program resource
 ///
 ///
 /// Shader program. Combines a fragment and a vertex shader. Every shader
 /// Shader program. Combines a fragment and a vertex shader. Every shader
@@ -33,8 +167,10 @@ public:
 		AttributeVariablesContainer;
 		AttributeVariablesContainer;
 
 
 	ShaderProgram()
 	ShaderProgram()
-		: glId(UNINITIALIZED_ID)
-	{}
+	{
+		glId = vertShaderGlId = tcShaderGlId = teShaderGlId =
+			geomShaderGlId = fragShaderGlId = UNINITIALIZED_ID;
+	}
 
 
 	~ShaderProgram();
 	~ShaderProgram();
 
 
@@ -97,7 +233,6 @@ public:
 	/// @param sProgFPathName The file pathname of the shader prog
 	/// @param sProgFPathName The file pathname of the shader prog
 	/// @param preAppendedSrcCode The source code we want to write on top
 	/// @param preAppendedSrcCode The source code we want to write on top
 	/// of the shader prog
 	/// of the shader prog
-	/// @param newFNamePrefix The prefix of the new shader prog
 	/// @return The file pathname of the new shader prog. Its
 	/// @return The file pathname of the new shader prog. Its
 	/// $HOME/.anki/cache/newFNamePrefix_fName
 	/// $HOME/.anki/cache/newFNamePrefix_fName
 	static std::string createSrcCodeToCache(const char* sProgFPathName,
 	static std::string createSrcCodeToCache(const char* sProgFPathName,

+ 0 - 30
anki/resource/ShaderProgramAttributeVariable.h

@@ -1,30 +0,0 @@
-#ifndef ANKI_RESOURCE_SHADER_PROGRAM_ATTRIBUTE_VARIABLE_H
-#define ANKI_RESOURCE_SHADER_PROGRAM_ATTRIBUTE_VARIABLE_H
-
-#include "anki/resource/ShaderProgramVariable.h"
-
-
-namespace anki {
-
-
-/// Attribute shader program variable
-class ShaderProgramAttributeVariable: public ShaderProgramVariable
-{
-public:
-	ShaderProgramAttributeVariable(
-		int loc, const char* name, GLenum glDataType,
-		const ShaderProgram& fatherSProg);
-};
-
-
-inline ShaderProgramAttributeVariable::ShaderProgramAttributeVariable(
-	int loc, const char* name,
-	GLenum glDataType, const ShaderProgram& fatherSProg)
-	: ShaderProgramVariable(loc, name, glDataType, T_ATTRIBUTE, fatherSProg)
-{}
-
-
-} // end namespace
-
-
-#endif

+ 0 - 104
anki/resource/ShaderProgramUniformVariable.cpp

@@ -1,104 +0,0 @@
-#include "anki/resource/ShaderProgramUniformVariable.h"
-#include "anki/resource/ShaderProgram.h"
-#include "anki/resource/Texture.h"
-#include "anki/gl/GlStateMachine.h"
-
-
-namespace anki {
-
-
-//==============================================================================
-void ShaderProgramUniformVariable::doSanityChecks() const
-{
-	ANKI_ASSERT(getLocation() != -1);
-	ANKI_ASSERT(GlStateMachineSingleton::get().getCurrentProgramGlId() ==
-		getFatherSProg().getGlId());
-	ANKI_ASSERT(glGetUniformLocation(getFatherSProg().getGlId(),
-		getName().c_str()) == getLocation());
-}
-
-
-//==============================================================================
-// set uniforms                                                                =
-//==============================================================================
-
-void ShaderProgramUniformVariable::set(const float x) const
-{
-	doSanityChecks();
-	ANKI_ASSERT(getGlDataType() == GL_FLOAT);
-
-	glUniform1f(getLocation(), x);
-}
-
-
-void ShaderProgramUniformVariable::set(const Vec2& x) const
-{
-	glUniform2f(getLocation(), x.x(), x.y());
-}
-
-
-void ShaderProgramUniformVariable::set(const float x[], uint size) const
-{
-	doSanityChecks();
-	ANKI_ASSERT(getGlDataType() == GL_FLOAT);
-	ANKI_ASSERT(size > 1);
-	glUniform1fv(getLocation(), size, x);
-}
-
-
-void ShaderProgramUniformVariable::set(const Vec2 x[], uint size) const
-{
-	doSanityChecks();
-	ANKI_ASSERT(getGlDataType() == GL_FLOAT_VEC2);
-	ANKI_ASSERT(size > 1);
-	glUniform2fv(getLocation(), size, &(const_cast<Vec2&>(x[0]))[0]);
-}
-
-
-void ShaderProgramUniformVariable::set(const Vec3 x[], uint size) const
-{
-	doSanityChecks();
-	ANKI_ASSERT(getGlDataType() == GL_FLOAT_VEC3);
-	ANKI_ASSERT(size > 0);
-	glUniform3fv(getLocation(), size, &(const_cast<Vec3&>(x[0]))[0]);
-}
-
-
-void ShaderProgramUniformVariable::set(const Vec4 x[], uint size) const
-{
-	doSanityChecks();
-	ANKI_ASSERT(getGlDataType() == GL_FLOAT_VEC4);
-	ANKI_ASSERT(size > 0);
-	glUniform4fv(getLocation(), size, &(const_cast<Vec4&>(x[0]))[0]);
-}
-
-
-void ShaderProgramUniformVariable::set(const Mat3 x[], uint size) const
-{
-	doSanityChecks();
-	ANKI_ASSERT(getGlDataType() == GL_FLOAT_MAT3);
-	ANKI_ASSERT(size > 0);
-	glUniformMatrix3fv(getLocation(), size, true, &(x[0])[0]);
-}
-
-
-void ShaderProgramUniformVariable::set(const Mat4 x[], uint size) const
-{
-	doSanityChecks();
-	ANKI_ASSERT(getGlDataType() == GL_FLOAT_MAT4);
-	ANKI_ASSERT(size > 0);
-	glUniformMatrix4fv(getLocation(), size, true, &(x[0])[0]);
-}
-
-
-void ShaderProgramUniformVariable::set(const Texture& tex, uint texUnit) const
-{
-	doSanityChecks();
-	ANKI_ASSERT(getGlDataType() == GL_SAMPLER_2D ||
-		getGlDataType() == GL_SAMPLER_2D_SHADOW);
-	tex.bind(texUnit);
-	glUniform1i(getLocation(), texUnit);
-}
-
-
-} // end namespace

+ 0 - 76
anki/resource/ShaderProgramUniformVariable.h

@@ -1,76 +0,0 @@
-#ifndef ANKI_RESOURCE_SHADER_PROGRAM_UNIFORM_VARIABLE_H
-#define ANKI_RESOURCE_SHADER_PROGRAM_UNIFORM_VARIABLE_H
-
-#include "anki/resource/ShaderProgramVariable.h"
-#include "anki/math/Math.h"
-#include <vector>
-
-
-namespace anki {
-
-
-class Texture;
-
-
-/// Uniform shader variable
-class ShaderProgramUniformVariable: public ShaderProgramVariable
-{
-public:
-	ShaderProgramUniformVariable(
-		int loc,
-		const char* name,
-		GLenum glDataType,
-		const ShaderProgram& fatherSProg)
-		: ShaderProgramVariable(loc, name, glDataType, T_UNIFORM, fatherSProg)
-	{}
-
-	/// @name Set the var
-	/// @{
-	void set(const float x) const;
-	void set(const Vec2& x) const;
-	void set(const Vec3& x) const
-	{
-		set(&x, 1);
-	}
-	void set(const Vec4& x) const
-	{
-		set(&x, 1);
-	}
-	void set(const Mat3& x) const
-	{
-		set(&x, 1);
-	}
-	void set(const Mat4& x) const
-	{
-		set(&x, 1);
-	}
-	void set(const Texture& tex, uint texUnit) const;
-
-	void set(const float x[], uint size) const;
-	void set(const Vec2 x[], uint size) const;
-	void set(const Vec3 x[], uint size) const;
-	void set(const Vec4 x[], uint size) const;
-	void set(const Mat3 x[], uint size) const;
-	void set(const Mat4 x[], uint size) const;
-
-	/// @tparam Type float, Vec2, etc
-	template<typename Type>
-	void set(const std::vector<Type>& c)
-	{
-		set(&c[0], c.size());
-	}
-	/// @}
-
-private:
-	/// Standard set uniform checks
-	/// - Check if initialized
-	/// - if the current shader program is the var's shader program
-	/// - if the GL driver gives the same location as the one the var has
-	void doSanityChecks() const;
-};
-
-
-} // end namespace
-
-
-#endif

+ 0 - 87
anki/resource/ShaderProgramVariable.h

@@ -1,87 +0,0 @@
-#ifndef ANKI_RESOURCE_SHADER_PROGRAM_VARIABLE_H
-#define ANKI_RESOURCE_SHADER_PROGRAM_VARIABLE_H
-
-#include <GL/glew.h>
-#include <string>
-#include <boost/noncopyable.hpp>
-
-
-namespace anki {
-
-
-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);
-
-	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 T_ATTRIBUTE or @ref T_UNIFORM
-	/// We need the ShaderProg of this variable mainly for sanity checks
-	const ShaderProgram& fatherSProg;
-};
-
-
-inline ShaderProgramVariable::ShaderProgramVariable(GLint loc_,
-	const char* name_, GLenum glDataType_,
-	Type type_, const ShaderProgram& fatherSHADER_PROGRAM_)
-:	loc(loc_),
-	name(name_),
-	glDataType(glDataType_),
-	type(type_),
-	fatherSProg(fatherSHADER_PROGRAM_)
-{}
-
-
-} // end namespace
-
-
-#endif

+ 58 - 8
anki/scene/MaterialRuntime.cpp

@@ -1,15 +1,71 @@
 #include "anki/scene/MaterialRuntime.h"
 #include "anki/scene/MaterialRuntime.h"
 #include "anki/resource/Material.h"
 #include "anki/resource/Material.h"
-#include "anki/scene/MaterialRuntimeVariable.h"
+#include "anki/resource/Texture.h"
+#include "anki/resource/Resource.h"
 #include <boost/foreach.hpp>
 #include <boost/foreach.hpp>
 
 
 
 
 namespace anki {
 namespace anki {
 
 
 
 
+//==============================================================================
+// MaterialRuntimeVariable                                                     =
+//==============================================================================
+
+//==============================================================================
+template <>
+void MaterialRuntimeVariable::ConstructVisitor::
+	operator()<TextureResourcePointer >(const TextureResourcePointer& x) const
+{
+	var.data = &x;
+}
+
+
+//==============================================================================
+MaterialRuntimeVariable::MaterialRuntimeVariable(
+	const MaterialVariable& mvar_)
+	: mvar(mvar_), buildinId(-1)
+{
+	// Initialize the data using a visitor
+	boost::apply_visitor(ConstructVisitor(*this), mvar.getVariant());
+}
+
+
+//==============================================================================
+MaterialRuntimeVariable::~MaterialRuntimeVariable()
+{}
+
+
+
+//==============================================================================
+template<>
+MaterialRuntimeVariable::ConstPtrRsrcPtrTexture&
+	MaterialRuntimeVariable::getValue<
+	MaterialRuntimeVariable::ConstPtrRsrcPtrTexture>()
+{
+	throw ANKI_EXCEPTION("You shouldn't call this getter");
+	return boost::get<ConstPtrRsrcPtrTexture>(data);
+}
+
+
+//==============================================================================
+template<>
+void MaterialRuntimeVariable::setValue<
+	MaterialRuntimeVariable::ConstPtrRsrcPtrTexture>(
+	const ConstPtrRsrcPtrTexture& v)
+{
+	throw ANKI_EXCEPTION("You shouldn't call this setter");
+	boost::get<ConstPtrRsrcPtrTexture>(data) = v;
+}
+
+
+//==============================================================================
+// MaterialRuntime                                                             =
+//==============================================================================
+
 //==============================================================================
 //==============================================================================
 MaterialRuntime::MaterialRuntime(const Material& mtl_)
 MaterialRuntime::MaterialRuntime(const Material& mtl_)
-:	mtl(mtl_)
+	: mtl(mtl_)
 {
 {
 	// Copy props
 	// Copy props
 	MaterialProperties& me = *this;
 	MaterialProperties& me = *this;
@@ -19,12 +75,6 @@ MaterialRuntime::MaterialRuntime(const Material& mtl_)
 	// Create vars
 	// Create vars
 	BOOST_FOREACH(const MaterialVariable& var, mtl.getVariables())
 	BOOST_FOREACH(const MaterialVariable& var, mtl.getVariables())
 	{
 	{
-		if(var.getShaderProgramVariableType() !=
-			ShaderProgramVariable::T_UNIFORM)
-		{
-			continue;
-		}
-
 		MaterialRuntimeVariable* varr = new MaterialRuntimeVariable(var);
 		MaterialRuntimeVariable* varr = new MaterialRuntimeVariable(var);
 		vars.push_back(varr);
 		vars.push_back(varr);
 		varNameToVar[varr->getMaterialVariable().getName().c_str()] = varr;
 		varNameToVar[varr->getMaterialVariable().getName().c_str()] = varr;

+ 135 - 19
anki/scene/MaterialRuntime.h

@@ -1,20 +1,141 @@
 #ifndef ANKI_SCENE_MATERIAL_RUNTIME_H
 #ifndef ANKI_SCENE_MATERIAL_RUNTIME_H
 #define ANKI_SCENE_MATERIAL_RUNTIME_H
 #define ANKI_SCENE_MATERIAL_RUNTIME_H
 
 
-#include "anki/resource/MaterialProperties.h"
+#include "anki/resource/Material.h"
 #include "anki/util/ConstCharPtrHashMap.h"
 #include "anki/util/ConstCharPtrHashMap.h"
-#include "anki/scene/MaterialRuntimeVariable.h"
+#include "anki/resource/Resource.h"
+#include "anki/math/Math.h"
 #include <boost/ptr_container/ptr_vector.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
 #include <boost/range/iterator_range.hpp>
 #include <boost/range/iterator_range.hpp>
+#include <boost/variant.hpp>
 
 
 
 
 namespace anki {
 namespace anki {
 
 
 
 
-class Material;
+class Texture;
+class MaterialVariable;
 
 
 
 
-/// One layer above material resource
+/// Variable of runtime materials
+/// This holds a copy of the MtlUserDefinedVar's data in order to be changed
+/// inside the main loop
+class MaterialRuntimeVariable
+{
+public:
+	typedef const TextureResourcePointer* ConstPtrRsrcPtrTexture;
+
+	/// The data union. The Texture resource is read-only at runtime
+	/// Don't EVER replace the texture with const Texture*. The asynchronous
+	/// operations will fail
+	typedef boost::variant<float, Vec2, Vec3, Vec4, Mat3,
+		Mat4, ConstPtrRsrcPtrTexture> Variant;
+
+	/// Constructor. Initialize using a material variable
+	MaterialRuntimeVariable(const MaterialVariable& mv);
+
+	/// Destructor
+	~MaterialRuntimeVariable();
+
+	/// @name Accessors
+	/// @{
+	const MaterialVariable& getMaterialVariable() const
+	{
+		return mvar;
+	}
+
+	const Variant& getDataVariant() const
+	{
+		return data;
+	}
+	Variant& getDataVariant()
+	{
+		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& getValue() 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& getValue()
+	{
+		return boost::get<Type>(data);
+	}
+
+	template<typename Type>
+	void setValue(const Type& v)
+	{
+		boost::get<Type>(data) = v;
+	}
+
+	int getBuildinId() const
+	{
+		return buildinId;
+	}
+	int& getBuildinId()
+	{
+		return buildinId;
+	}
+	void setBuildinId(const int x)
+	{
+		buildinId = x;
+	}
+	/// @}
+
+private:
+	/// Initialize the data using a visitor
+	class ConstructVisitor: public boost::static_visitor<void>
+	{
+		public:
+			MaterialRuntimeVariable& var;
+
+			ConstructVisitor(MaterialRuntimeVariable& var_)
+				: var(var_)
+			{}
+
+			/// Template method that applies to all DataVariant values
+			/// except texture resource
+			template<typename Type>
+			void operator()(const Type& x) const
+			{
+				var.getDataVariant() = x;
+			}
+	};
+
+	const MaterialVariable& mvar; ///< Know the resource
+	Variant data; /// The data
+	int buildinId;
+};
+
+
+// Declare specialized
+template <>
+void MaterialRuntimeVariable::ConstructVisitor::
+	operator()<TextureResourcePointer >(const TextureResourcePointer& x) const;
+
+// Declare specialized
+template<>
+MaterialRuntimeVariable::ConstPtrRsrcPtrTexture&
+	MaterialRuntimeVariable::getValue<
+	MaterialRuntimeVariable::ConstPtrRsrcPtrTexture>();
+
+// Declare specialized
+template<>
+void MaterialRuntimeVariable::setValue<
+	MaterialRuntimeVariable::ConstPtrRsrcPtrTexture>(
+	const ConstPtrRsrcPtrTexture& v);
+
+
+/// One layer above the material resource
 class MaterialRuntime: public MaterialProperties
 class MaterialRuntime: public MaterialProperties
 {
 {
 	public:
 	public:
@@ -38,21 +159,10 @@ class MaterialRuntime: public MaterialProperties
 
 
 		/// @name Accessors
 		/// @name Accessors
 		/// @{
 		/// @{
-		using MaterialProperties::getRenderingStage;
-		uint& getRenderingStage()
+		bool getShadow() const
 		{
 		{
-			return renderingStage;
-		}
-		void setRenderingStage(uint x)
-		{
-			renderingStage = x;
+			return shadow;
 		}
 		}
-
-		using MaterialProperties::getPasses;
-
-		using MaterialProperties::getLevelsOfDetail;
-
-		using MaterialProperties::getShadow;
 		bool& getShadow()
 		bool& getShadow()
 		{
 		{
 			return shadow;
 			return shadow;
@@ -88,7 +198,10 @@ class MaterialRuntime: public MaterialProperties
 			blendingDfactor = x;
 			blendingDfactor = x;
 		}
 		}
 
 
-		using MaterialProperties::getDepthTesting;
+		bool getDepthTesting() const
+		{
+			return depthTesting;
+		}
 		bool& getDepthTesting()
 		bool& getDepthTesting()
 		{
 		{
 			return depthTesting;
 			return depthTesting;
@@ -98,7 +211,10 @@ class MaterialRuntime: public MaterialProperties
 			depthTesting = x;
 			depthTesting = x;
 		}
 		}
 
 
-		using MaterialProperties::getWireframe;
+		bool getWireframe() const
+		{
+			return wireframe;
+		}
 		bool& getWireframe()
 		bool& getWireframe()
 		{
 		{
 			return wireframe;
 			return wireframe;

+ 0 - 60
anki/scene/MaterialRuntimeVariable.cpp

@@ -1,60 +0,0 @@
-#include "anki/scene/MaterialRuntimeVariable.h"
-#include "anki/resource/MaterialVariable.h"
-
-
-namespace anki {
-
-
-//==============================================================================
-template <>
-void MaterialRuntimeVariable::ConstructVisitor::
-	operator()<TextureResourcePointer >(const TextureResourcePointer& x) const
-{
-	var.data = &x;
-}
-
-
-//==============================================================================
-MaterialRuntimeVariable::MaterialRuntimeVariable(
-	const MaterialVariable& 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());
-}
-
-
-//==============================================================================
-MaterialRuntimeVariable::~MaterialRuntimeVariable()
-{}
-
-
-//==============================================================================
-// Specialized Accessors                                                       =
-//==============================================================================
-
-template<>
-MaterialRuntimeVariable::ConstPtrRsrcPtrTexture&
-	MaterialRuntimeVariable::getValue<
-	MaterialRuntimeVariable::ConstPtrRsrcPtrTexture>()
-{
-	throw ANKI_EXCEPTION("You shouldn't call this getter");
-	return boost::get<ConstPtrRsrcPtrTexture>(data);
-}
-
-
-template<>
-void MaterialRuntimeVariable::setValue<
-	MaterialRuntimeVariable::ConstPtrRsrcPtrTexture>(
-	const ConstPtrRsrcPtrTexture& v)
-{
-	throw ANKI_EXCEPTION("You shouldn't call this setter");
-	boost::get<ConstPtrRsrcPtrTexture>(data) = v;
-}
-
-
-} // end namespace

+ 0 - 137
anki/scene/MaterialRuntimeVariable.h

@@ -1,137 +0,0 @@
-#ifndef ANKI_SCENE_MATERIAL_RUNTIME_VARIABLE_H
-#define ANKI_SCENE_MATERIAL_RUNTIME_VARIABLE_H
-
-#include "anki/math/Math.h"
-#include "anki/resource/Resource.h"
-#include <boost/variant.hpp>
-
-
-namespace anki {
-
-
-class Texture;
-class MaterialVariable;
-
-
-/// Variable of runtime materials
-/// This holds a copy of the MtlUserDefinedVar's data in order to be changed
-/// inside the main loop
-class MaterialRuntimeVariable
-{
-	public:
-		typedef const TextureResourcePointer* ConstPtrRsrcPtrTexture;
-
-		/// The data union. The Texture resource is read-only at runtime
-		/// Don't EVER replace the texture with const Texture*. The asynchronous
-		/// operations will fail
-		typedef boost::variant<float, Vec2, Vec3, Vec4, Mat3,
-			Mat4, ConstPtrRsrcPtrTexture> Variant;
-
-		/// Constructor
-		MaterialRuntimeVariable(const MaterialVariable& mv);
-
-		/// Destructor
-		~MaterialRuntimeVariable();
-
-		/// @name Accessors
-		/// @{
-		const MaterialVariable& getMaterialVariable() const
-		{
-			return mvar;
-		}
-
-		const Variant& getDataVariant() const
-		{
-			return data;
-		}
-		Variant& getDataVariant()
-		{
-			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& getValue() 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& getValue()
-		{
-			return boost::get<Type>(data);
-		}
-
-		template<typename Type>
-		void setValue(const Type& v)
-		{
-			boost::get<Type>(data) = v;
-		}
-
-		int getBuildinId() const
-		{
-			return buildinId;
-		}
-		int& getBuildinId()
-		{
-			return buildinId;
-		}
-		void setBuildinId(const int x)
-		{
-			buildinId = x;
-		}
-		/// @}
-
-	private:
-		/// Initialize the data using a visitor
-		class ConstructVisitor: public boost::static_visitor<void>
-		{
-			public:
-				MaterialRuntimeVariable& var;
-
-				ConstructVisitor(MaterialRuntimeVariable& var_)
-				:	var(var_)
-				{}
-
-				/// Template method that applies to all DataVariant values
-				/// except texture resource
-				template<typename Type>
-				void operator()(const Type& x) const
-				{
-					var.getDataVariant() = x;
-				}
-		};
-
-		const MaterialVariable& mvar; ///< Know the resource
-		Variant data; /// The data
-		int buildinId;
-};
-
-
-// Declare specialized
-template <>
-void MaterialRuntimeVariable::ConstructVisitor::
-	operator()<TextureResourcePointer >(const TextureResourcePointer& x) const;
-
-// Declare specialized
-template<>
-MaterialRuntimeVariable::ConstPtrRsrcPtrTexture&
-	MaterialRuntimeVariable::getValue<
-	MaterialRuntimeVariable::ConstPtrRsrcPtrTexture>();
-
-// Declare specialized
-template<>
-void MaterialRuntimeVariable::setValue<
-	MaterialRuntimeVariable::ConstPtrRsrcPtrTexture>(
-	const ConstPtrRsrcPtrTexture& v);
-
-
-} // end namespace
-
-
-#endif

+ 1 - 1
build/clean

@@ -1,2 +1,2 @@
 #!/bin/bash
 #!/bin/bash
-rm -rf CMakeCache.txt CMakeFiles Makefile cmake_install.cmake src
+rm -rf CMakeCache.txt CMakeFiles Makefile cmake_install.cmake src doxyfile testapp anki