Panagiotis Christopoulos Charitos %!s(int64=14) %!d(string=hai) anos
pai
achega
2c8bd455b7

+ 1 - 2
anki/renderer/SceneDrawer.h

@@ -62,9 +62,8 @@ private:
 	};
 	};
 
 
 	/// Set the uniform using this visitor
 	/// Set the uniform using this visitor
-	class SetUniformVisitor: public boost::static_visitor<>
+	struct SetUniformVisitor: public boost::static_visitor<>
 	{
 	{
-	public:
 		const ShaderProgramUniformVariable& uni;
 		const ShaderProgramUniformVariable& uni;
 		uint& texUnit;
 		uint& texUnit;
 
 

+ 6 - 0
anki/resource/Material.h

@@ -61,6 +61,12 @@ public:
 		return data;
 		return data;
 	}
 	}
 
 
+	template<typename T>
+	const T& getValue() const
+	{
+		return boost::get<T>(data);
+	}
+
 	/// Given a key return the uniform
 	/// Given a key return the uniform
 	const ShaderProgramUniformVariable& getShaderProgramUniformVariable(
 	const ShaderProgramUniformVariable& getShaderProgramUniformVariable(
 		const PassLevelKey& key) const
 		const PassLevelKey& key) const

+ 10 - 3
anki/scene/Property.h

@@ -6,7 +6,7 @@
 #include "anki/util/Assert.h"
 #include "anki/util/Assert.h"
 #include "anki/util/ConstCharPtrHashMap.h"
 #include "anki/util/ConstCharPtrHashMap.h"
 #include <boost/ptr_container/ptr_vector.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
-#include <boost/shared_ptr.hpp>
+#include <boost/scoped_ptr.hpp>
 #include <boost/noncopyable.hpp>
 #include <boost/noncopyable.hpp>
 
 
 
 
@@ -271,7 +271,14 @@ public:
 	/// Overrides Property::getValue()
 	/// Overrides Property::getValue()
 	const Value& getValue() const
 	const Value& getValue() const
 	{
 	{
-		return (sptr.get()) ? *sptr : *ptr;
+		if(sptr.get())
+		{
+			return *sptr;
+		}
+		else
+		{
+			return *ptr;
+		}
 	}
 	}
 
 
 	/// Overrides Property::setValue()
 	/// Overrides Property::setValue()
@@ -291,7 +298,7 @@ public:
 
 
 private:
 private:
 	const Value* ptr;
 	const Value* ptr;
-	boost::scoped_ptr sptr;
+	boost::scoped_ptr<Value> sptr;
 };
 };
 
 
 
 

+ 43 - 0
anki/scene/Renderable.cpp

@@ -0,0 +1,43 @@
+#include "anki/scene/Renderable.h"
+#include "anki/resource/Material.h"
+#include "anki/resource/Texture.h"
+#include <boost/foreach.hpp>
+
+
+namespace anki {
+
+
+struct XXXVisitor: boost::static_visitor<void>
+{
+	const MaterialVariable* mvar;
+	PropertyMap* pmap;
+
+	XXXVisitor(const MaterialVariable* mvar_, PropertyMap* pmap_)
+		: mvar(mvar_), pmap(pmap_)
+	{}
+
+	template<typename T>
+	void operator()(const T& x) const
+	{
+		MaterialVariableReadCowPointerProperty<T>* prop =
+			new MaterialVariableReadCowPointerProperty<T>(
+			mvar->getName().c_str(), &(mvar->getValue<T>()));
+
+		pmap->addNewProperty(prop);
+	}
+};
+
+
+//==============================================================================
+void Renderable::init(PropertyMap& pmap) const
+{
+	const Material& mtl = getMaterial();
+
+	BOOST_FOREACH(const MaterialVariable& mv, mtl.getVariables())
+	{
+		boost::apply_visitor(XXXVisitor(&mv, &pmap), mv.getVariant());
+	}
+}
+
+
+}  // namespace anki

+ 27 - 13
anki/scene/Renderable.h

@@ -1,18 +1,39 @@
 #ifndef ANKI_SCENE_RENDERABLE_H
 #ifndef ANKI_SCENE_RENDERABLE_H
 #define ANKI_SCENE_RENDERABLE_H
 #define ANKI_SCENE_RENDERABLE_H
 
 
+#include "anki/scene/Property.h"
+
 
 
 namespace anki {
 namespace anki {
 
 
 
 
 class ModelPatchBase;
 class ModelPatchBase;
 class Material;
 class Material;
-class PropertyMap;
+class MaterialVariable;
 
 
 
 
 /// @addtogroup Scene
 /// @addtogroup Scene
 /// @{
 /// @{
 
 
+
+/// XXX
+template<typename T>
+class MaterialVariableReadCowPointerProperty: public ReadCowPointerProperty<T>
+{
+public:
+	typedef T Value;
+	typedef ReadCowPointerProperty<T> Base;
+
+	/// @name Constructors/Destructor
+	/// @{
+	MaterialVariableReadCowPointerProperty(const char* name, const Value* x)
+		: Base(name, x)
+	{}
+	/// @}
+private:
+};
+
+
 /// Renderable interface
 /// Renderable interface
 ///
 ///
 /// Implemented by renderable scene nodes
 /// Implemented by renderable scene nodes
@@ -20,20 +41,13 @@ class Renderable
 {
 {
 public:
 public:
 	/// Access to VAOs
 	/// Access to VAOs
-	virtual const ModelPatchBase* getModelPatchBase() const
-	{
-		return NULL;
-	}
-
-	/// Get the material runtime. Dont access it from the ModelPatchBase
-	/// because the lights dont have one
-	virtual Material& getMaterial() = 0;
+	virtual const ModelPatchBase& getModelPatchBase() const = 0;
 
 
-	/// Access to property map to get the values of the shader variables
-	virtual PropertyMap& getPropertyMap() = 0;
-
-private:
+	/// Access the material
+	virtual const Material& getMaterial() const = 0;
 
 
+protected:
+	void init(PropertyMap& pmap) const;
 };
 };
 /// @}
 /// @}