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

+ 1 - 1
src/Resources/Material2.h

@@ -123,7 +123,7 @@ class Material2: private MaterialProperties
 		/// @name Accessors
 		/// @{
 		GETTER_R_BY_VAL(bool, castsShadowFlag, castsShadow)
-		GETTER_R_BY_VAL(bool, renderInBlendingStageFlag, renderInBlendingStage)
+		GETTER_R_BY_VAL(bool, renderInBlendingStageFlag, rendersInBlendingStage)
 		GETTER_R_BY_VAL(int, blendingSfactor, getBlendingSfactor)
 		GETTER_R_BY_VAL(int, blendingDfactor, getBlendingDfactor)
 		GETTER_R_BY_VAL(bool, depthTesting, isDepthTestingEnabled)

+ 36 - 1
src/Scene/MaterialRuntime2.h

@@ -25,12 +25,47 @@ class MaterialRuntime2: private MaterialProps
 
 		/// @name Accessors
 		/// @{
-		GETTER_RW(VariablesContainer, vars, getUserMaterialVariablesRuntime)
+		GETTER_SETTER_BY_VAL(bool, castsShadowFlag, castsShadow, setCastShadow)
+		GETTER_SETTER_BY_VAL(bool, renderInBlendingStageFlag,
+			rendersInBlendingStage, setRendersInBlendingStage)
+		GETTER_SETTER_BY_VAL(int, blendingSfactor, getBlendingSfactor,
+			setBlendingSFactor)
+		GETTER_SETTER_BY_VAL(int, blendingDfactor, getBlendingDfactor,
+			setBlendingDFactor)
+		GETTER_SETTER_BY_VAL(bool, depthTesting, isDepthTestingEnabled,
+			setDepthTestingEnabled)
+		GETTER_SETTER_BY_VAL(bool, wireframe, isWireframeEnabled,
+			setWireframeEnabled)
+
+		GETTER_RW(VariablesContainer, vars, getVariables)
+		GETTER_R(Material2, mtl, getMaterial);
 		/// @}
 
+		/// Find MaterialRuntimeUserDefinedVar variable. On failure it throws
+		/// an exception
+		/// @param[in] name The name of the var
+		/// @return It returns a MaterialRuntimeUserDefinedVar
+		/// @exception Exception
+		UserMaterialVariableRuntime& findVariableByName(
+			const char* name);
+
+		/// The const version of getUserDefinedVarByName
+		/// @see getUserDefinedVarByName
+		const MaterialRuntimeUserDefinedVar& findVariableByName(
+			const char* name) const;
+
+		bool isBlendingEnabled() const;
+
 	private:
+		const Material2& mtl; ///< The resource
 		VariablesContainer vars;
 };
 
 
+inline bool MaterialRuntime2::isBlendingEnabled() const
+{
+	return blendingSfactor != GL_ONE || blendingDfactor != GL_ZERO;
+}
+
+
 #endif

+ 44 - 1
src/Scene/UserMaterialVariableRuntime.cpp

@@ -2,6 +2,17 @@
 #include "Resources/UserMaterialVariable.h"
 
 
+//==============================================================================
+// ConstructVisitor::operator() <RsrcPtr<Texture> >                            =
+//==============================================================================
+template <>
+void UserMaterialVariableRuntime::ConstructVisitor::
+	operator()<RsrcPtr<Texture> >(const RsrcPtr<Texture>& x) const
+{
+	udvr.data = &x;
+}
+
+
 //==============================================================================
 // Constructor                                                                =
 //==============================================================================
@@ -9,5 +20,37 @@ UserMaterialVariableRuntime::UserMaterialVariableRuntime(
 	const UserMaterialVariable& umv_)
 :	umv(umv_)
 {
-	/// XXX
+	// Initialize the data using a visitor
+	boost::apply_visitor(ConstructVisitor(*this), umv.getDataVariant());
+}
+
+
+//==============================================================================
+// Destructor                                                                  =
+//==============================================================================
+UserMaterialVariableRuntime::~UserMaterialVariableRuntime()
+{}
+
+
+//==============================================================================
+// Specialized Accessors                                                       =
+//==============================================================================
+
+template<>
+UserMaterialVariableRuntime::ConstPtrRsrcPtrTexture&
+	UserMaterialVariableRuntime::getValue<
+	UserMaterialVariableRuntime::ConstPtrRsrcPtrTexture>()
+{
+	throw EXCEPTION("You shouldn't call this getter");
+	return boost::get<ConstPtrRsrcPtrTexture>(data);
+}
+
+
+template<>
+void UserMaterialVariableRuntime::setValue<
+	UserMaterialVariableRuntime::ConstPtrRsrcPtrTexture>(
+	const ConstPtrRsrcPtrTexture& v)
+{
+	throw EXCEPTION("You shouldn't call this setter");
+	boost::get<ConstPtrRsrcPtrTexture>(data) = v;
 }

+ 47 - 3
src/Scene/UserMaterialVariableRuntime.h

@@ -3,6 +3,7 @@
 
 #include "Util/Accessors.h"
 #include "Math/Math.h"
+#include "Resources/RsrcPtr.h"
 #include <boost/variant.hpp>
 
 
@@ -10,27 +11,70 @@ class UserMaterialVariable;
 class Texture;
 
 
-/// XXX
+/// This holds a copy of the MtlUserDefinedVar's data in order to be changed
+/// inside the main loop
 class UserMaterialVariableRuntime
 {
 	public:
+		typedef const RsrcPtr<Texture>* ConstPtrRsrcPtrTexture;
+
 		/// The data union. The Texture resource is read-only at runtime
+		/// Dont EVER replace the texture with const Texture*. The asynchronous
+		/// operations will fail
 		typedef boost::variant<float, Vec2, Vec3, Vec4,
-			const Texture*> DataVariant;
+			ConstPtrRsrcPtrTexture> DataVariant;
 
 		/// Constructor
 		UserMaterialVariableRuntime(const UserMaterialVariable& umv);
+		/// Destructor
+		~UserMaterialVariableRuntime();
 
 		/// @name Accessors
 		/// @{
 		GETTER_R(UserMaterialVariable, umv, getUserMaterialVariable)
+		GETTER_RW(DataVariant, data, getDataVariant)
+
+		/// Get the value of the variant
+		/// @exception boost::exception when you try to get the incorrect data
+		/// type
+		template<typename Type>
+		const Type& 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;}
 		/// @}
 
 	private:
+		/// Initialize the data using a visitor
+		class ConstructVisitor: public boost::static_visitor<void>
+		{
+			public:
+				UserMaterialVariableRuntime& udvr;
+
+				ConstructVisitor(UserMaterialVariableRuntime& udmvr);
+
+				/// Template method that applies to all DataVariant values
+				/// except texture resource
+				template<typename Type>
+				void operator()(const Type& x) const
+					{udvr.getDataVariant() = x;}
+		};
+
 		const UserMaterialVariable& umv; ///< Know the resource
-		DataVariant data;
+		DataVariant data; /// The data
 };
 
 
+inline UserMaterialVariableRuntime::ConstructVisitor::ConstructVisitor(
+	UserMaterialVariableRuntime& udvr_)
+:	udvr(udvr_)
+{}
+
+
 #endif