Panagiotis Christopoulos Charitos пре 13 година
родитељ
комит
fcdc88cb75
3 измењених фајлова са 48 додато и 33 уклоњено
  1. 43 27
      include/anki/resource/Material.h
  2. 5 5
      include/anki/util/Variant.h
  3. 0 1
      src/resource/Material.cpp

+ 43 - 27
include/anki/resource/Material.h

@@ -6,7 +6,8 @@
 #include "anki/util/ConstCharPtrHashMap.h"
 #include "anki/util/StringList.h"
 #include "anki/math/Math.h"
-#include <GL/glew.h>
+#include "anki/util/Visitor.h"
+#include "anki/gl/gl.h"
 #include <boost/ptr_container/ptr_vector.hpp>
 #include <boost/array.hpp>
 #include <boost/scoped_ptr.hpp>
@@ -19,27 +20,20 @@ namespace anki {
 class ShaderProgram;
 class ShaderProgramUniformVariable;
 
-/// XXX
-enum MaterialVariableDataType
-{
-	MVDT_FLOAT,
-	MVDT_VEC2,
-	MVDT_VEC3,
-	MVDT_VEC4,
-	MVDT_MAT3,
-	MVDT_MAT4,
-	MVDT_TEXTURE,
-	MVDT_COUNT
-};
+/// Material variable base. Its a visitable
+typedef Visitable<float, Vec2, Vec3, Vec4, Mat3, Mat4, TextureResourcePointer> 
+	MateriaVariableBase;
+
+// Forward
+template<typename T>
+class MaterialVariableTemplate;
 
 /// Holds the shader variables. Its a container for shader program variables
 /// that share the same name
-class MaterialVariable: public 
-	Visitable<float, Vec2, Vec3, Vec4, Mat3, Mat4, TextureResourcePointer>
+class MaterialVariable: public MateriaVariableBase
 {
 public:
-	typedef Visitable<float, Vec2, Vec3, Vec4, Mat3, Mat4, 
-		TextureResourcePointer> Base;
+	typedef MateriaVariableBase Base;
 
 	/// Given a pair of pass and level it returns a pointer to a
 	/// shader program uniform variable. The pointer may be nullptr
@@ -53,29 +47,32 @@ public:
 	/// @name Constructors & destructor
 	/// @{
 	MaterialVariable(
-		char* shaderProgVarName,
+		const char* shaderProgVarName,
 		const PassLevelToShaderProgramHashMap& sProgs,
 		bool init_,
-		MaterialVariableDataType type_)
+		uint8_t type_)
 		: type(type_), initialized(init_)
 	{
 		init(shaderProgVarName, sProgs);
 	}
 
-	~MaterialVariable();
+	virtual ~MaterialVariable();
 	/// @}
 
 	/// @name Accessors
 	/// @{
-	const Variant& getVariant() const
+	template<typename T>
+	const T& getValue() const
 	{
-		return data;
+		ANKI_ASSERT(Base::getTypeId<T>() == type);
+		return static_cast<const MaterialVariableTemplate<T>*>(this)->get();
 	}
 
 	template<typename T>
-	const T& getValue() const
+	void setValue(const T& x)
 	{
-		return boost::get<T>(data);
+		ANKI_ASSERT(Base::getTypeId<T>() == type);
+		static_cast<MaterialVariableTemplate<T>*>(this)->set(x);
 	}
 
 	/// Given a key return the uniform. If the uniform is not present in the
@@ -100,7 +97,7 @@ public:
 	/// @}
 
 private:
-	MaterialVariableDataType type;
+	uint8_t type; ///< Type id
 
 	/// If not initialized then there is no value given in the XML so it is
 	/// probably build in and the renderer should set the value on the shader
@@ -122,17 +119,36 @@ template<typename Data>
 class MaterialVariableTemplate: public MaterialVariable
 {
 public:
+	/// @name Constructors/Destructor
+	/// @{
 	MaterialVariableTemplate(
-		char* shaderProgVarName,
+		const char* shaderProgVarName,
 		const PassLevelToShaderProgramHashMap& sProgs,
 		const Data& val,
 		bool init_)
-		: MaterialVariable(shaderProgVarName, sProgs, data, init_,
+		: MaterialVariable(shaderProgVarName, sProgs, init_,
 			MaterialVariable::Base::getTypeId<Data>())
 	{
 		data = val;
 	}
 
+	~MaterialVariableTemplate()
+	{}
+	/// @}
+
+	/// @name Accessors
+	/// @{
+	const Data& get() const;
+	{
+		return data;
+	}
+
+	void set(const Data& x)
+	{
+		data = x;
+	}
+	/// @}
+
 private:
 	Data data;
 };

+ 5 - 5
include/anki/util/Variant.h

@@ -135,11 +135,11 @@ template<typename TData, typename TVariantBase>
 class VariantDerived: public TVariantBase
 {
 public:
-	typedef TData DataType;
-	typedef TVariantBase BaseType;
-	typedef VariantDerived<DataType, BaseType> SelfType;
-	typedef typename BaseType::ConstVisitorType ConstVisitorType;
-	typedef typename BaseType::MutableVisitorType MutableVisitorType;
+	typedef TData Data;
+	typedef TVariantBase Base;
+	typedef VariantDerived<DataType, BaseType> Self;
+	typedef typename BaseType::ConstVisitor ConstVisitor;
+	typedef typename BaseType::MutableVisitor MutableVisitor;
 
 	static const int TYPE_ID =
 		BaseType::BaseType::template getTypeId<SelfType>();

+ 0 - 1
src/resource/Material.cpp

@@ -5,7 +5,6 @@
 #include "anki/core/Globals.h"
 #include "anki/resource/ShaderProgramResource.h"
 #include "anki/resource/TextureResource.h"
-#include <boost/foreach.hpp>
 #include <boost/property_tree/ptree.hpp>
 #include <boost/property_tree/xml_parser.hpp>
 #include <boost/assign/list_of.hpp>