Panagiotis Christopoulos Charitos il y a 14 ans
Parent
commit
f42259c225

+ 2 - 1
src/Resources/Material2.h

@@ -129,7 +129,8 @@ class Material2: private MaterialProperties
 		GETTER_R_BY_VAL(bool, depthTesting, isDepthTestingEnabled)
 		GETTER_R_BY_VAL(bool, depthTesting, isDepthTestingEnabled)
 		GETTER_R_BY_VAL(bool, wireframe, isWireframeEnabled)
 		GETTER_R_BY_VAL(bool, wireframe, isWireframeEnabled)
 
 
-		GETTER_R(VarsContainer, mtlVars, getMaterialVariables)
+		GETTER_R(VarsContainer, mtlVars, getVariables)
+		GETTER_R(Vec<UserMaterialVariable*>, userMtlVars, getUserVariables)
 
 
 		/// Access the base class just for copying in other classes
 		/// Access the base class just for copying in other classes
 		GETTER_R(MaterialProperties, *this, accessMaterialPropertiesBaseClass)
 		GETTER_R(MaterialProperties, *this, accessMaterialPropertiesBaseClass)

+ 67 - 0
src/Scene/MaterialRuntime2.cpp

@@ -0,0 +1,67 @@
+#include "MaterialRuntime2.h"
+#include "Resources/Material2.h"
+#include "UserMaterialVariableRuntime.h"
+#include <boost/foreach.hpp>
+
+
+//==============================================================================
+// Constructor                                                                 =
+//==============================================================================
+MaterialRuntime2::MaterialRuntime2(const Material2& mtl_)
+:	mtl(mtl_)
+{
+	// Copy props
+	MaterialProperties& me = *this;
+	const MaterialProperties& he = mtl.accessMaterialPropertiesBaseClass();
+	me = he;
+
+	// Create vars
+	BOOST_FOREACH(const UserMaterialVariable* var, mtl.getUserVariables())
+	{
+		UserMaterialVariableRuntime* varr =
+			new UserMaterialVariableRuntime(*var);
+		vars.push_back(varr);
+		varNameToVar[varr->getUserMaterialVariable().getName().c_str()] = varr;
+	}
+}
+
+
+//==============================================================================
+// Destructor                                                                  =
+//==============================================================================
+MaterialRuntime2::~MaterialRuntime2()
+{}
+
+
+//==============================================================================
+// findVariableByName                                                          =
+//==============================================================================
+UserMaterialVariableRuntime& MaterialRuntime2::findVariableByName(
+	const char* name)
+{
+	ConstCharPtrHashMap<UserMaterialVariableRuntime*>::Type::iterator it =
+		varNameToVar.find(name);
+	if(it == varNameToVar.end())
+	{
+		throw EXCEPTION("Cannot get user defined variable with name \"" +
+			name + '\"');
+	}
+	return *(it->second);
+}
+
+
+//==============================================================================
+// findVariableByName                                                          =
+//==============================================================================
+const UserMaterialVariableRuntime& MaterialRuntime2::findVariableByName(
+	const char* name) const
+{
+	ConstCharPtrHashMap<UserMaterialVariableRuntime*>::Type::const_iterator
+		it = varNameToVar.find(name);
+	if(it == varNameToVar.end())
+	{
+		throw EXCEPTION("Cannot get user defined variable with name \"" +
+			name + '\"');
+	}
+	return *(it->second);
+}

+ 7 - 3
src/Scene/MaterialRuntime2.h

@@ -1,16 +1,18 @@
 #ifndef MATERIAL_RUNTIME_2_H
 #ifndef MATERIAL_RUNTIME_2_H
 #define MATERIAL_RUNTIME_2_H
 #define MATERIAL_RUNTIME_2_H
 
 
-#include "Resources/Material.h"
+#include "Resources/Material2.h"
 #include "Util/Accessors.h"
 #include "Util/Accessors.h"
+#include "Util/ConstCharPtrHashMap.h"
 #include <boost/ptr_container/ptr_vector.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
 
 
 
 
 class UserMaterialVariableRuntime;
 class UserMaterialVariableRuntime;
+class Material2;
 
 
 
 
 /// One layer above material resource
 /// One layer above material resource
-class MaterialRuntime2: private MaterialProps
+class MaterialRuntime2: private MaterialProperties
 {
 {
 	public:
 	public:
 		/// A type
 		/// A type
@@ -51,7 +53,7 @@ class MaterialRuntime2: private MaterialProps
 
 
 		/// The const version of getUserDefinedVarByName
 		/// The const version of getUserDefinedVarByName
 		/// @see getUserDefinedVarByName
 		/// @see getUserDefinedVarByName
-		const MaterialRuntimeUserDefinedVar& findVariableByName(
+		const UserMaterialVariableRuntime& findVariableByName(
 			const char* name) const;
 			const char* name) const;
 
 
 		bool isBlendingEnabled() const;
 		bool isBlendingEnabled() const;
@@ -59,6 +61,8 @@ class MaterialRuntime2: private MaterialProps
 	private:
 	private:
 		const Material2& mtl; ///< The resource
 		const Material2& mtl; ///< The resource
 		VariablesContainer vars;
 		VariablesContainer vars;
+		ConstCharPtrHashMap<UserMaterialVariableRuntime*>::Type
+			varNameToVar;
 };
 };
 
 
 
 

+ 1 - 1
src/Scene/UserMaterialVariableRuntime.cpp

@@ -14,7 +14,7 @@ void UserMaterialVariableRuntime::ConstructVisitor::
 
 
 
 
 //==============================================================================
 //==============================================================================
-// Constructor                                                                =
+// Constructor                                                                 =
 //==============================================================================
 //==============================================================================
 UserMaterialVariableRuntime::UserMaterialVariableRuntime(
 UserMaterialVariableRuntime::UserMaterialVariableRuntime(
 	const UserMaterialVariable& umv_)
 	const UserMaterialVariable& umv_)