Ver código fonte

Moving files & changing names

Panagiotis Christopoulos Charitos 14 anos atrás
pai
commit
2a3939c830
53 arquivos alterados com 691 adições e 851 exclusões
  1. 4 4
      shaders/MaterialVertex.glsl
  2. 1 1
      src/Core/Globals.h
  3. 1 1
      src/Core/parallel/Job.cpp
  4. 3 3
      src/Core/parallel/Job.h
  5. 1 1
      src/Core/parallel/Manager.cpp
  6. 3 3
      src/Core/parallel/Manager.h
  7. 2 2
      src/Main.cpp
  8. 0 40
      src/Renderer/SkinsDeformer.h
  9. 16 22
      src/Resources/Material.cpp
  10. 175 4
      src/Resources/Material.h
  11. 8 14
      src/Resources/MaterialBuildinVariable.cpp
  12. 5 10
      src/Resources/MaterialBuildinVariable.h
  13. 1 7
      src/Resources/MaterialCommon.cpp
  14. 0 6
      src/Resources/MaterialCommon.h
  15. 1 7
      src/Resources/MaterialProperties.h
  16. 20 26
      src/Resources/MaterialShaderProgramCreator.cpp
  17. 3 8
      src/Resources/MaterialShaderProgramCreator.h
  18. 18 24
      src/Resources/MaterialUserVariable.cpp
  19. 14 20
      src/Resources/MaterialUserVariable.h
  20. 4 10
      src/Resources/MaterialVariable.cpp
  21. 9 15
      src/Resources/MaterialVariable.h
  22. 2 2
      src/Resources/Mesh.h
  23. 13 18
      src/Resources/ShaderProgram.cpp
  24. 136 6
      src/Resources/ShaderProgram.h
  25. 5 11
      src/Resources/ShaderProgramAttributeVariable.h
  26. 7 13
      src/Resources/ShaderProgramPrePreprocessor.cpp
  27. 6 12
      src/Resources/ShaderProgramPrePreprocessor.h
  28. 9 15
      src/Resources/ShaderProgramUniformVariable.cpp
  29. 8 12
      src/Resources/ShaderProgramUniformVariable.h
  30. 4 8
      src/Resources/ShaderProgramVariable.h
  31. 0 15
      src/Resources/material/Fwd.h
  32. 0 189
      src/Resources/material/Material.h
  33. 0 15
      src/Resources/shader_program/Fwd.h
  34. 0 149
      src/Resources/shader_program/ShaderProgram.h
  35. 9 10
      src/Scene/MaterialRuntime.cpp
  36. 9 20
      src/Scene/MaterialRuntime.h
  37. 11 16
      src/Scene/MaterialRuntimeVariable.cpp
  38. 12 17
      src/Scene/MaterialRuntimeVariable.h
  39. 7 5
      src/Scene/ModelPatchNode.cpp
  40. 0 1
      src/Scene/ModelPatchNode.h
  41. 17 17
      src/Scene/PatchNode.cpp
  42. 23 11
      src/Scene/PatchNode.h
  43. 7 2
      src/Scene/RenderableNode.h
  44. 8 2
      src/Scene/Scene.cpp
  45. 5 1
      src/Scene/Scene.h
  46. 11 8
      src/Scene/SkelAnimModelNodeCtrl.cpp
  47. 1 1
      src/Scene/SkinNode.cpp
  48. 11 10
      src/Scene/SkinPatchNode.cpp
  49. 13 2
      src/Scene/SkinPatchNode.h
  50. 21 18
      src/Scene/SkinPatchNodeDeformer.cpp
  51. 28 0
      src/Scene/SkinPatchNodeDeformer.h
  52. 13 11
      src/Scene/VisibilityTester.cpp
  53. 6 6
      src/Scene/VisibilityTester.h

+ 4 - 4
shaders/MaterialVertex.glsl

@@ -3,16 +3,16 @@
 
 /// @name Attributes
 /// @{
-in vec3 position;
+layout(location = 0) in vec3 position;
 #if defined(USING_TEX_COORDS_ATTRIB)
-in vec2 texCoords;
+layout(location = 3) in vec2 texCoords;
 #endif
 #if defined(COLOR_PASS)
 #	if defined(USING_NORMAL_ATTRIB)
-in vec3 normal;
+layout(location = 1) in vec3 normal;
 #	endif
 #	if defined(USING_TANGENT_ATTRIB)
-in vec4 tangent;
+layout(location = 2) in vec4 tangent;
 #	endif
 #endif
 /// @}

+ 1 - 1
src/Core/Globals.h

@@ -22,7 +22,7 @@ namespace Event {
 typedef Singleton<class Manager> ManagerSingleton;
 }
 
-namespace ParallelJobs {
+namespace parallel {
 typedef Singleton<class Manager> ManagerSingleton;
 }
 

+ 1 - 1
src/Core/ParallelJobs/Job.cpp → src/Core/parallel/Job.cpp

@@ -2,7 +2,7 @@
 #include "Manager.h"
 
 
-namespace ParallelJobs {
+namespace parallel {
 
 
 //==============================================================================

+ 3 - 3
src/Core/ParallelJobs/Job.h → src/Core/parallel/Job.h

@@ -1,11 +1,11 @@
-#ifndef PARALLEL_JOBS_JOB_H
-#define PARALLEL_JOBS_JOB_H
+#ifndef PARALLEL_JOB_H
+#define PARALLEL_JOB_H
 
 #include <boost/thread.hpp>
 #include "Util/Accessors.h"
 
 
-namespace ParallelJobs {
+namespace parallel {
 
 
 class Manager;

+ 1 - 1
src/Core/ParallelJobs/Manager.cpp → src/Core/parallel/Manager.cpp

@@ -1,7 +1,7 @@
 #include "Manager.h"
 
 
-namespace ParallelJobs {
+namespace parallel {
 
 
 //==============================================================================

+ 3 - 3
src/Core/ParallelJobs/Manager.h → src/Core/parallel/Manager.h

@@ -1,12 +1,12 @@
-#ifndef PARALLEL_JOBS_MANAGER_H
-#define PARALLEL_JOBS_MANAGER_H
+#ifndef PARALLEL_MANAGER_H
+#define PARALLEL_MANAGER_H
 
 #include "Job.h"
 #include <boost/thread.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
 
 
-namespace ParallelJobs {
+namespace parallel {
 
 
 /// The job manager

+ 2 - 2
src/Main.cpp

@@ -45,7 +45,7 @@
 #include "Events/MainRendererPpsHdr.h"
 #include "Resources/ShaderProgramPrePreprocessor.h"
 #include "Resources/Material.h"
-#include "Core/ParallelJobs/Manager.h"
+#include "Core/parallel/Manager.h"
 #include "Renderer/Drawers/PhysDbgDrawer.h"
 
 
@@ -524,7 +524,7 @@ void initSubsystems(int argc, char* argv[])
 	StdinListenerSingleton::getInstance().start();
 
 	// Parallel jobs
-	ParallelJobs::ManagerSingleton::getInstance().init(4);
+	parallel::ManagerSingleton::getInstance().init(4);
 
 	// Add drawer to physics
 	SceneSingleton::getInstance().getPhysMasterContainer().setDebugDrawer(

+ 0 - 40
src/Renderer/SkinsDeformer.h

@@ -1,40 +0,0 @@
-#ifndef R_SKINS_DEFORMER_H
-#define R_SKINS_DEFORMER_H
-
-#include "Resources/RsrcPtr.h"
-
-
-class ShaderProgram;
-class SkinPatchNode;
-
-
-namespace R {
-
-
-/// @todo
-class SkinsDeformer
-{
-	public:
-		enum TfShaderProgAttrib
-		{
-			TFSPA_POSITION,
-			TFSPA_NORMAL,
-			TFSPA_TANGENT,
-			TFSPA_VERT_WEIGHT_BONES_NUM,
-			TFSPA_VERT_WEIGHT_BONE_IDS,
-			TFSPA_VERT_WEIGHT_WEIGHTS
-		};
-
-		void init();
-		void deform(SkinPatchNode& node);
-
-	private:
-		RsrcPtr<ShaderProgram> tfHwSkinningAllSProg;
-		RsrcPtr<ShaderProgram> tfHwSkinningPosSProg;
-};
-
-
-} // end namespace
-
-
-#endif

+ 16 - 22
src/Resources/material/Material.cpp → src/Resources/Material.cpp

@@ -1,10 +1,10 @@
 #include "Material.h"
-#include "Variable.h"
+#include "MaterialVariable.h"
 #include "Misc/PropertyTree.h"
-#include "ShaderProgramCreator.h"
+#include "MaterialShaderProgramCreator.h"
 #include "Core/App.h"
 #include "Core/Globals.h"
-#include "../ShaderProgram.h"
+#include "ShaderProgram.h"
 #include <boost/foreach.hpp>
 #include <boost/property_tree/ptree.hpp>
 #include <boost/property_tree/xml_parser.hpp>
@@ -13,9 +13,6 @@
 #include <algorithm>
 
 
-namespace material {
-
-
 //==============================================================================
 // Statics                                                                     =
 //==============================================================================
@@ -54,7 +51,7 @@ Material::Material()
 
 	// Reset tha array
 	std::fill(buildinsArr.begin(), buildinsArr.end(),
-		static_cast<BuildinVariable*>(NULL));
+		static_cast<MaterialBuildinVariable*>(NULL));
 }
 
 
@@ -174,7 +171,7 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 	//
 	// shaderProgram
 	//
-	ShaderProgramCreator mspc(pt.get_child("shaderProgram"));
+	MaterialShaderProgramCreator mspc(pt.get_child("shaderProgram"));
 
 	for(uint i = 0; i < PASS_TYPES_NUM; i++)
 	{
@@ -238,7 +235,7 @@ void Material::populateVariables(const boost::property_tree::ptree& pt)
 
 	BOOST_FOREACH(const RsrcPtr<ShaderProgram>& sProg, sProgs)
 	{
-		BOOST_FOREACH(const shader_program::Variable& v, sProg->getVariables())
+		BOOST_FOREACH(const ShaderProgramVariable& v, sProg->getVariables())
 		{
 			allVarNames[v.getName()] = v.getGlDataType();
 		}
@@ -247,7 +244,7 @@ void Material::populateVariables(const boost::property_tree::ptree& pt)
 	//
 	// Iterate shader program variables
 	//
-	Variable::ShaderPrograms sProgs_;
+	MaterialVariable::ShaderPrograms sProgs_;
 	for(uint i = 0; i < PASS_TYPES_NUM; i++)
 	{
 		sProgs_[i] = sProgs[i].get();
@@ -260,10 +257,10 @@ void Material::populateVariables(const boost::property_tree::ptree& pt)
 		GLenum dataType = it->second;
 
 		// Buildin?
-		if(BuildinVariable::isBuildin(svName))
+		if(MaterialBuildinVariable::isBuildin(svName))
 		{
-			BuildinVariable* v =
-				new BuildinVariable(svName, sProgs_);
+			MaterialBuildinVariable* v =
+				new MaterialBuildinVariable(svName, sProgs_);
 
 			mtlVars.push_back(v);
 			buildinsArr[v->getVariableEnum()] = v;
@@ -293,33 +290,33 @@ void Material::populateVariables(const boost::property_tree::ptree& pt)
 					svName);
 			}
 
-			UserVariable* v = NULL;
+			MaterialUserVariable* v = NULL;
 			// Get the value
 			switch(dataType)
 			{
 				// sampler2D
 				case GL_SAMPLER_2D:
-					v = new UserVariable(svName, sProgs_,
+					v = new MaterialUserVariable(svName, sProgs_,
 						valuePt->get<std::string>("sampler2D").c_str());
 					break;
 				// float
 				case GL_FLOAT:
-					v = new UserVariable(svName, sProgs_,
+					v = new MaterialUserVariable(svName, sProgs_,
 						PropertyTree::getFloat(*valuePt));
 					break;
 				// vec2
 				case GL_FLOAT_VEC2:
-					v = new UserVariable(svName, sProgs_,
+					v = new MaterialUserVariable(svName, sProgs_,
 						PropertyTree::getVec2(*valuePt));
 					break;
 				// vec3
 				case GL_FLOAT_VEC3:
-					v = new UserVariable(svName, sProgs_,
+					v = new MaterialUserVariable(svName, sProgs_,
 						PropertyTree::getVec3(*valuePt));
 					break;
 				// vec4
 				case GL_FLOAT_VEC4:
-					v = new UserVariable(svName, sProgs_,
+					v = new MaterialUserVariable(svName, sProgs_,
 						PropertyTree::getVec4(*valuePt));
 					break;
 				// default is error
@@ -332,6 +329,3 @@ void Material::populateVariables(const boost::property_tree::ptree& pt)
 		}
 	} // end for all sprog vars
 }
-
-
-} // end namespace

+ 175 - 4
src/Resources/Material.h

@@ -1,12 +1,183 @@
 #ifndef MATERIAL_H
 #define MATERIAL_H
 
-#include "material/Material.h"
+#include "MaterialUserVariable.h"
+#include "MaterialBuildinVariable.h"
+#include "MaterialCommon.h"
+#include "MaterialProperties.h"
+#include "Util/Accessors.h"
+#include "Util/ConstCharPtrHashMap.h"
+#include <GL/glew.h>
+#include <boost/ptr_container/ptr_vector.hpp>
+#include <boost/array.hpp>
+#include <boost/scoped_ptr.hpp>
+#include <boost/property_tree/ptree_fwd.hpp>
 
 
-/// Alias to material::Material
-class Material: public material::Material
-{};
+class ShaderProgram;
+
+
+/// Material resource
+///
+/// Every material keeps info of how to render a RenedrableNode. Using a node
+/// based logic it creates a couple of shader programs dynamically. One for
+/// color passes and one for depth. It also keeps two sets of material
+/// variables. The first is the build in and the second the user defined.
+/// During the renderer's shader setup the buildins will be set automatically,
+/// for the user variables the user needs to have its value in the material
+/// file. Some material variables may be present in both shader programs and
+/// some in only one of them
+///
+/// Material XML file format:
+/// @code
+/// <material>
+/// 	<castsShadow>true | false</castsShadow>
+///
+/// 	<renderInBlendingStage>true | false</renderInBlendingStage>
+///
+/// 	<blendFunctions>
+/// 		<sFactor>GL_SOMETHING</sFactor>
+/// 		<dFactor>GL_SOMETHING</dFactor>
+/// 	</blendFunctions>
+///
+/// 	<depthTesting>true | false</depthTesting>
+///
+/// 	<wireframe>true | false</wireframe>
+///
+/// 	<shaderProgram>
+/// 		<includes>
+/// 			<include>file.glsl</include>
+/// 			<include>file2.glsl</include>
+/// 		</includes>
+///
+/// 		<inputs>
+/// 			<input> *
+/// 				<name>xx</name>
+/// 				<value>
+/// 					<float>0.0</float> |
+/// 					<vec2><x>0.0</x><y>0.0</y></vec2> |
+/// 					<vec3><x>0.0</x><y>0.0</y><z>0.0</z></vec3> |
+/// 					<vec4><x>0.0</x><y>0.0</y><z>0.0</z><w>0.0</w></vec4> |
+/// 					<sampler2D>path/to/image.tga</sampler2D>
+/// 				</value>
+/// 			</input>
+/// 		</inputs>
+///
+/// 		<operations>
+/// 			<operation>
+/// 				<id>x</id>
+/// 				<function>functionName</function>
+/// 				<arguments>
+/// 					<argument>xx</argument>
+/// 					<argument>yy</argument>
+/// 				</arguments>
+/// 			</operation>
+/// 		</operations>
+///
+/// 	</shaderProgram>
+/// </material>
+/// @endcode
+/// *: For if the value is not set then the in variable will be build in or
+///    standard varying
+class Material: private MaterialProperties
+{
+	public:
+		//======================================================================
+		// Nested                                                              =
+		//======================================================================
+
+		typedef boost::ptr_vector<MaterialVariable> VarsContainer;
+
+		typedef boost::unordered_map<MaterialBuildinVariable::BuildinEnum,
+			MaterialBuildinVariable*> BuildinEnumToBuildinHashMap;
+
+		typedef boost::array<MaterialBuildinVariable*,
+			MaterialBuildinVariable::BUILDINS_NUM> BuildinsArr;
+
+		//======================================================================
+		// Methods                                                             =
+		//======================================================================
+
+		/// Initialize with default values
+		Material();
+
+		~Material();
+
+		/// @name Accessors
+		/// @{
+		GETTER_R_BY_VAL(bool, castsShadowFlag, castsShadow)
+		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)
+		GETTER_R_BY_VAL(bool, wireframe, isWireframeEnabled)
+
+		/// Access the base class just for copying in other classes
+		GETTER_R(MaterialProperties, *this, accessPropertiesBaseClass)
+
+		const ShaderProgram& getShaderProgram(PassType p) const
+			{return *sProgs[p];}
+
+		// Variable accessors
+		GETTER_R(VarsContainer, mtlVars, getVariables)
+		GETTER_R(Vec<MaterialUserVariable*>, userMtlVars, getUserVariables)
+		const MaterialBuildinVariable& getBuildinVariable(
+			MaterialBuildinVariable::BuildinEnum e) const;
+		/// @}
+
+		/// Load a material file
+		void load(const char* filename);
+
+		/// Check if a buildin variable exists
+		bool buildinVariableExits(MaterialBuildinVariable::BuildinEnum e)
+			const {return buildinsArr[e] != NULL;}
+
+	private:
+		//======================================================================
+		// Nested                                                              =
+		//======================================================================
+
+		typedef boost::array<RsrcPtr<ShaderProgram>, PASS_TYPES_NUM>
+			ShaderPrograms;
+
+		//======================================================================
+		// Members                                                             =
+		//======================================================================
+
+		/// From "GL_ZERO" return GL_ZERO
+		static ConstCharPtrHashMap<GLenum>::Type txtToBlengGlEnum;
+
+		/// All the material variables. Both buildins and user
+		VarsContainer mtlVars;
+
+		BuildinsArr buildinsArr; ///< To find. Initialize to int
+
+		Vec<MaterialUserVariable*> userMtlVars; ///< To iterate
+
+		/// The most important aspect of materials
+		ShaderPrograms sProgs;
+
+		//======================================================================
+		// Methods                                                             =
+		//======================================================================
+
+		/// Parse what is within the @code <material></material> @endcode
+		void parseMaterialTag(const boost::property_tree::ptree& pt);
+
+		/// XXX
+		std::string createShaderProgSourceToCache(const std::string& source);
+
+		/// XXX
+		void populateVariables(const boost::property_tree::ptree& pt);
+};
+
+
+inline const MaterialBuildinVariable& Material::getBuildinVariable(
+	MaterialBuildinVariable::BuildinEnum e) const
+{
+	ASSERT(buildinVariableExits(e));
+	return *buildinsArr[e];
+}
 
 
 #endif

+ 8 - 14
src/Resources/material/BuildinVariable.cpp → src/Resources/MaterialBuildinVariable.cpp

@@ -1,4 +1,4 @@
-#include "BuildinVariable.h"
+#include "MaterialBuildinVariable.h"
 #include "Util/Exception.h"
 #include "Util/Assert.h"
 #include <cstring>
@@ -6,15 +6,12 @@
 #include <boost/assign/list_of.hpp>
 
 
-namespace material {
-
-
 //==============================================================================
 // Statics                                                                     =
 //==============================================================================
 
-ConstCharPtrHashMap<BuildinVariable::BuildinEnum>::Type
-	BuildinVariable::buildinNameToEnum = boost::assign::map_list_of
+ConstCharPtrHashMap<MaterialBuildinVariable::BuildinEnum>::Type
+	MaterialBuildinVariable::buildinNameToEnum = boost::assign::map_list_of
 	("position", POSITION)
 	("tangent", TANGENT)
 	("normal", NORMAL)
@@ -38,8 +35,8 @@ ConstCharPtrHashMap<BuildinVariable::BuildinEnum>::Type
 	("blurring", BLURRING);
 
 
-boost::unordered_map<BuildinVariable::BuildinEnum, GLenum>
-	BuildinVariable::buildinToGlType = boost::assign::map_list_of
+boost::unordered_map<MaterialBuildinVariable::BuildinEnum, GLenum>
+	MaterialBuildinVariable::buildinToGlType = boost::assign::map_list_of
 	(POSITION, GL_FLOAT_VEC3)
 	(TANGENT, GL_FLOAT_VEC4)
 	(NORMAL, GL_FLOAT_VEC3)
@@ -66,10 +63,10 @@ boost::unordered_map<BuildinVariable::BuildinEnum, GLenum>
 //==============================================================================
 // Constructor                                                                 =
 //==============================================================================
-BuildinVariable::BuildinVariable(
+MaterialBuildinVariable::MaterialBuildinVariable(
 	const char* shaderProgVarName,
 	const ShaderPrograms& shaderProgsArr)
-:	Variable(BUILDIN, shaderProgVarName, shaderProgsArr),
+:	MaterialVariable(BUILDIN, shaderProgVarName, shaderProgsArr),
  	bEnum(BUILDINS_NUM)
 {
 	GLenum dataType;
@@ -91,7 +88,7 @@ BuildinVariable::BuildinVariable(
 //==============================================================================
 // isBuildin                                                                   =
 //==============================================================================
-bool BuildinVariable::isBuildin(const char* name,
+bool MaterialBuildinVariable::isBuildin(const char* name,
 	BuildinEnum* var, GLenum* dataType)
 {
 	ConstCharPtrHashMap<BuildinEnum>::Type::const_iterator it =
@@ -119,6 +116,3 @@ bool BuildinVariable::isBuildin(const char* name,
 
 	return true;
 }
-
-
-} // end namespace

+ 5 - 10
src/Resources/material/BuildinVariable.h → src/Resources/MaterialBuildinVariable.h

@@ -1,16 +1,13 @@
 #ifndef MATERIAL_BUILDIN_VARIABLE_H
 #define MATERIAL_BUILDIN_VARIABLE_H
 
-#include "Variable.h"
+#include "MaterialVariable.h"
 #include "Util/ConstCharPtrHashMap.h"
 #include <boost/array.hpp>
 
 
-namespace material {
-
-
 /// XXX
-class BuildinVariable: public Variable
+class MaterialBuildinVariable: public MaterialVariable
 {
 	public:
 		/// Standard attribute variables that are acceptable inside the
@@ -47,7 +44,7 @@ class BuildinVariable: public Variable
 			BUILDINS_NUM ///< The number of all buildin variables
 		};
 
-		BuildinVariable(
+		MaterialBuildinVariable(
 			const char* shaderProgVarName,
 			const ShaderPrograms& shaderProgsArr);
 
@@ -57,16 +54,14 @@ class BuildinVariable: public Variable
 			GLenum* dataType = NULL);
 
 	private:
-		/// Given a name of a variable find its BuildinVariable enum
+		/// Given a name of a variable find its MaterialBuildinVariable enum
 		static ConstCharPtrHashMap<BuildinEnum>::Type buildinNameToEnum;
 
-		/// Given a BuildinVariable enum it gives the GL type
+		/// Given a MaterialBuildinVariable enum it gives the GL type
 		static boost::unordered_map<BuildinEnum, GLenum> buildinToGlType;
 
 		BuildinEnum bEnum;
 };
 
 
-} // end namespace
-
 #endif

+ 1 - 7
src/Resources/material/Common.cpp → src/Resources/MaterialCommon.cpp

@@ -1,13 +1,7 @@
-#include "Common.h"
-
-
-namespace material {
+#include "MaterialCommon.h"
 
 
 boost::array<const char*, PASS_TYPES_NUM> passNames = {{
 	"COLOR_PASS",
 	"DEPTH_PASS"
 }};
-
-
-} // end namesapce

+ 0 - 6
src/Resources/material/Common.h → src/Resources/MaterialCommon.h

@@ -4,9 +4,6 @@
 #include <boost/array.hpp>
 
 
-namespace material {
-
-
 /// The types of the rendering passes
 enum PassType
 {
@@ -19,7 +16,4 @@ enum PassType
 extern boost::array<const char*, PASS_TYPES_NUM> passNames;
 
 
-} // end namespace
-
-
 #endif

+ 1 - 7
src/Resources/material/Properties.h → src/Resources/MaterialProperties.h

@@ -4,11 +4,8 @@
 #include <GL/glew.h>
 
 
-namespace material {
-
-
 /// Contains a few properties that other classes may use
-struct Properties
+struct MaterialProperties
 {
 	public:
 		/// Check if blending is enabled
@@ -29,7 +26,4 @@ struct Properties
 };
 
 
-} // end namespace
-
-
 #endif

+ 20 - 26
src/Resources/material/ShaderProgramCreator.cpp → src/Resources/MaterialShaderProgramCreator.cpp

@@ -1,21 +1,18 @@
-#include "ShaderProgramCreator.h"
+#include "MaterialShaderProgramCreator.h"
 #include "Util/Scanner/Scanner.h"
 #include "Misc/Parser.h"
-#include "BuildinVariable.h"
+#include "MaterialBuildinVariable.h"
 #include <boost/assign/list_of.hpp>
 #include <boost/foreach.hpp>
 #include <boost/property_tree/ptree.hpp>
 
 
-namespace material {
-
-
 //==============================================================================
 // Statics                                                                     =
 //==============================================================================
 
 boost::unordered_map<GLenum, const char*>
-ShaderProgramCreator::glTypeToTxt = boost::assign::map_list_of
+MaterialShaderProgramCreator::glTypeToTxt = boost::assign::map_list_of
 	(GL_FLOAT, "float")
 	(GL_FLOAT_VEC2, "vec2")
 	(GL_FLOAT_VEC3, "vec3")
@@ -26,7 +23,7 @@ ShaderProgramCreator::glTypeToTxt = boost::assign::map_list_of
 	(GL_NONE, "void");
 
 
-ConstCharPtrHashMap<GLenum>::Type ShaderProgramCreator::txtToGlType =
+ConstCharPtrHashMap<GLenum>::Type MaterialShaderProgramCreator::txtToGlType =
 	boost::assign::map_list_of
 	("float", GL_FLOAT)
 	("vec2", GL_FLOAT_VEC2)
@@ -38,22 +35,22 @@ ConstCharPtrHashMap<GLenum>::Type ShaderProgramCreator::txtToGlType =
 	("void", GL_NONE);
 
 
-boost::unordered_map<ShaderProgramCreator::ArgQualifier, const char*>
-	ShaderProgramCreator::argQualifierToTxt = boost::assign::map_list_of
+boost::unordered_map<MaterialShaderProgramCreator::ArgQualifier, const char*>
+	MaterialShaderProgramCreator::argQualifierToTxt = boost::assign::map_list_of
 	(AQ_IN, "in")
 	(AQ_OUT, "out")
 	(AQ_INOUT, "inout");
 
 
-ConstCharPtrHashMap<ShaderProgramCreator::ArgQualifier>::Type
-	ShaderProgramCreator::txtToArgQualifier = boost::assign::map_list_of
+ConstCharPtrHashMap<MaterialShaderProgramCreator::ArgQualifier>::Type
+	MaterialShaderProgramCreator::txtToArgQualifier = boost::assign::map_list_of
 	("in", AQ_IN)
 	("out", AQ_OUT)
 	("inout", AQ_INOUT);
 
 
 ConstCharPtrHashMap<GLenum>::Type
-	ShaderProgramCreator::varyingNameToGlType =
+	MaterialShaderProgramCreator::varyingNameToGlType =
 	boost::assign::map_list_of
 	("vTexCoords", GL_FLOAT_VEC2)
 	("vNormal", GL_FLOAT_VEC3)
@@ -65,7 +62,7 @@ ConstCharPtrHashMap<GLenum>::Type
 //==============================================================================
 // Constructor                                                                 =
 //==============================================================================
-ShaderProgramCreator::ShaderProgramCreator(
+MaterialShaderProgramCreator::MaterialShaderProgramCreator(
 	const boost::property_tree::ptree& pt)
 {
 	parseShaderProgramTag(pt);
@@ -75,14 +72,14 @@ ShaderProgramCreator::ShaderProgramCreator(
 //==============================================================================
 // Destructor                                                                  =
 //==============================================================================
-ShaderProgramCreator::~ShaderProgramCreator()
+MaterialShaderProgramCreator::~MaterialShaderProgramCreator()
 {}
 
 
 //==============================================================================
 // parseShaderFileForFunctionDefinitions                                       =
 //==============================================================================
-void ShaderProgramCreator::parseShaderFileForFunctionDefinitions(
+void MaterialShaderProgramCreator::parseShaderFileForFunctionDefinitions(
 	const char* filename)
 {
 	Scanner::Scanner scanner(filename, false);
@@ -277,7 +274,7 @@ void ShaderProgramCreator::parseShaderFileForFunctionDefinitions(
 //==============================================================================
 // parseUntilNewline                                                           =
 //==============================================================================
-void ShaderProgramCreator::parseUntilNewline(Scanner::Scanner& scanner)
+void MaterialShaderProgramCreator::parseUntilNewline(Scanner::Scanner& scanner)
 {
 	const Scanner::Token* token = &scanner.getCrntToken();
 	Scanner::TokenCode prevTc;
@@ -303,7 +300,7 @@ void ShaderProgramCreator::parseUntilNewline(Scanner::Scanner& scanner)
 //==============================================================================
 // getNextTokenAndSkipNewlines                                                 =
 //==============================================================================
-void ShaderProgramCreator::getNextTokenAndSkipNewlines(
+void MaterialShaderProgramCreator::getNextTokenAndSkipNewlines(
 	Scanner::Scanner& scanner)
 {
 	const Scanner::Token* token;
@@ -322,7 +319,7 @@ void ShaderProgramCreator::getNextTokenAndSkipNewlines(
 //==============================================================================
 // parseShaderProgramTag                                                       =
 //==============================================================================
-void ShaderProgramCreator::parseShaderProgramTag(
+void MaterialShaderProgramCreator::parseShaderProgramTag(
 	const boost::property_tree::ptree& pt)
 {
 	usingTexCoordsAttrib = usingNormalAttrib = usingTangentAttrib = false;
@@ -435,7 +432,7 @@ void ShaderProgramCreator::parseShaderProgramTag(
 //==============================================================================
 // parseInputTag                                                               =
 //==============================================================================
-void ShaderProgramCreator::parseInputTag(
+void MaterialShaderProgramCreator::parseInputTag(
 	const boost::property_tree::ptree& pt, std::string& line)
 {
 	using namespace boost::property_tree;
@@ -447,9 +444,9 @@ void ShaderProgramCreator::parseInputTag(
 	// Buildin or varying
 	if(!valuePt)
 	{
-		BuildinVariable::BuildinEnum tmp;
+		MaterialBuildinVariable::BuildinEnum tmp;
 
-		if(BuildinVariable::isBuildin(name.c_str(), &tmp, &glType))
+		if(MaterialBuildinVariable::isBuildin(name.c_str(), &tmp, &glType))
 		{
 			const char* glTypeTxt = glTypeToTxt.at(glType);
 			line += "uniform ";
@@ -512,7 +509,7 @@ void ShaderProgramCreator::parseInputTag(
 //==============================================================================
 // parseOperatorTag                                                            =
 //==============================================================================
-void ShaderProgramCreator::parseOperatorTag(
+void MaterialShaderProgramCreator::parseOperatorTag(
 	const boost::property_tree::ptree& pt)
 {
 	using namespace boost::property_tree;
@@ -579,11 +576,8 @@ void ShaderProgramCreator::parseOperatorTag(
 //==============================================================================
 // compareStrings                                                              =
 //==============================================================================
-bool ShaderProgramCreator::compareStrings(
+bool MaterialShaderProgramCreator::compareStrings(
 	const std::string& a, const std::string& b)
 {
 	return a < b;
 }
-
-
-} // end namespace

+ 3 - 8
src/Resources/material/ShaderProgramCreator.h → src/Resources/MaterialShaderProgramCreator.h

@@ -14,15 +14,12 @@ class Scanner;
 }
 
 
-namespace material {
-
-
 /// XXX
-class ShaderProgramCreator
+class MaterialShaderProgramCreator
 {
 	public:
-		ShaderProgramCreator(const boost::property_tree::ptree& pt);
-		~ShaderProgramCreator();
+		MaterialShaderProgramCreator(const boost::property_tree::ptree& pt);
+		~MaterialShaderProgramCreator();
 
 		/// XXX
 		const std::string& getShaderProgramSource() const {return source;}
@@ -143,6 +140,4 @@ class ShaderProgramCreator
 };
 
 
-} // end namespace
-
 #endif

+ 18 - 24
src/Resources/material/UserVariable.cpp → src/Resources/MaterialUserVariable.cpp

@@ -1,82 +1,76 @@
-#include "UserVariable.h"
-#include "../Texture.h"
-
-
-namespace material {
+#include "MaterialUserVariable.h"
+#include "Texture.h"
 
 
 //==============================================================================
 // Constructors & destructor                                                   =
 //==============================================================================
 
-UserVariable::UserVariable(
+MaterialUserVariable::MaterialUserVariable(
 	const char* shaderProgVarName,
 	const ShaderPrograms& shaderProgsArr,
 	float val)
-:	Variable(USER, shaderProgVarName, shaderProgsArr)
+:	MaterialVariable(USER, shaderProgVarName, shaderProgsArr)
 {
 	ASSERT(getGlDataType() == GL_FLOAT);
 	ASSERT(getShaderProgramVariableType() ==
-		shader_program::Variable::UNIFORM);
+		ShaderProgramVariable::UNIFORM);
 	data = val;
 }
 
 
-UserVariable::UserVariable(
+MaterialUserVariable::MaterialUserVariable(
 	const char* shaderProgVarName,
 	const ShaderPrograms& shaderProgsArr,
 	const Vec2& val)
-:	Variable(USER, shaderProgVarName, shaderProgsArr)
+:	MaterialVariable(USER, shaderProgVarName, shaderProgsArr)
 {
 	ASSERT(getGlDataType() == GL_FLOAT_VEC2);
 	ASSERT(getShaderProgramVariableType() ==
-		shader_program::Variable::UNIFORM);
+		ShaderProgramVariable::UNIFORM);
 	data = val;
 }
 
 
-UserVariable::UserVariable(
+MaterialUserVariable::MaterialUserVariable(
 	const char* shaderProgVarName,
 	const ShaderPrograms& shaderProgsArr,
 	const Vec3& val)
-:	Variable(USER, shaderProgVarName, shaderProgsArr)
+:	MaterialVariable(USER, shaderProgVarName, shaderProgsArr)
 {
 	ASSERT(getGlDataType() == GL_FLOAT_VEC3);
 	ASSERT(getShaderProgramVariableType() ==
-		shader_program::Variable::UNIFORM);
+		ShaderProgramVariable::UNIFORM);
 	data = val;
 }
 
 
-UserVariable::UserVariable(
+MaterialUserVariable::MaterialUserVariable(
 	const char* shaderProgVarName,
 	const ShaderPrograms& shaderProgsArr,
 	const Vec4& val)
-:	Variable(USER, shaderProgVarName, shaderProgsArr)
+:	MaterialVariable(USER, shaderProgVarName, shaderProgsArr)
 {
 	ASSERT(getGlDataType() == GL_FLOAT_VEC4);
 	ASSERT(getShaderProgramVariableType() ==
-		shader_program::Variable::UNIFORM);
+		ShaderProgramVariable::UNIFORM);
 	data = val;
 }
 
 
-UserVariable::UserVariable(
+MaterialUserVariable::MaterialUserVariable(
 	const char* shaderProgVarName,
 	const ShaderPrograms& shaderProgsArr,
 	const char* texFilename)
-:	Variable(USER, shaderProgVarName, shaderProgsArr)
+:	MaterialVariable(USER, shaderProgVarName, shaderProgsArr)
 {
 	ASSERT(getGlDataType() == GL_SAMPLER_2D);
 	ASSERT(getShaderProgramVariableType() ==
-		shader_program::Variable::UNIFORM);
+		ShaderProgramVariable::UNIFORM);
 	data = RsrcPtr<Texture>();
 	boost::get<RsrcPtr<Texture> >(data).loadRsrc(texFilename);
 }
 
 
-UserVariable::~UserVariable()
+MaterialUserVariable::~MaterialUserVariable()
 {}
-
-
-} // end namespace

+ 14 - 20
src/Resources/material/UserVariable.h → src/Resources/MaterialUserVariable.h

@@ -1,21 +1,18 @@
 #ifndef MATERIAL_USER_VARIABLE_H
 #define MATERIAL_USER_VARIABLE_H
 
-#include "Variable.h"
+#include "MaterialVariable.h"
 #include "Math/Math.h"
-#include "../RsrcPtr.h"
-#include "../shader_program/UniformVariable.h"
+#include "RsrcPtr.h"
+#include "ShaderProgramUniformVariable.h"
 #include <boost/variant.hpp>
 
 
 class Texture;
 
 
-namespace material {
-
-
 /// XXX
-class UserVariable: public Variable
+class MaterialUserVariable: public MaterialVariable
 {
 	public:
 		/// The data union
@@ -24,32 +21,32 @@ class UserVariable: public Variable
 
 		/// @name Constructors & destructor
 		/// @{
-		UserVariable(
+		MaterialUserVariable(
 			const char* shaderProgVarName,
 			const ShaderPrograms& shaderProgsArr,
 			float val);
 
-		UserVariable(
+		MaterialUserVariable(
 			const char* shaderProgVarName,
 			const ShaderPrograms& shaderProgsArr,
 			const Vec2& val);
 
-		UserVariable(
+		MaterialUserVariable(
 			const char* shaderProgVarName,
 			const ShaderPrograms& shaderProgsArr,
 			const Vec3& val);
 
-		UserVariable(
+		MaterialUserVariable(
 			const char* shaderProgVarName,
 			const ShaderPrograms& shaderProgsArr,
 			const Vec4& val);
 
-		UserVariable(
+		MaterialUserVariable(
 			const char* shaderProgVarName,
 			const ShaderPrograms& shaderProgsArr,
 			const char* texFilename);
 
-		~UserVariable();
+		~MaterialUserVariable();
 		/// @}
 
 		/// @name Accessors
@@ -63,7 +60,7 @@ class UserVariable: public Variable
 		const Type& getValue() const {return boost::get<Type>(data);}
 
 		/// Uses static cast to get the uniform
-		const shader_program::UniformVariable&
+		const ShaderProgramUniformVariable&
 			getShaderProgramUniformVariable(PassType p) const;
 		/// @}
 
@@ -72,15 +69,12 @@ class UserVariable: public Variable
 };
 
 
-inline const shader_program::UniformVariable&
-	UserVariable::getShaderProgramUniformVariable(PassType p) const
+inline const ShaderProgramUniformVariable&
+	MaterialUserVariable::getShaderProgramUniformVariable(PassType p) const
 {
-	return static_cast<const shader_program::UniformVariable&>(
+	return static_cast<const ShaderProgramUniformVariable&>(
 		getShaderProgramVariable(p));
 }
 
 
-} // end namespace
-
-
 #endif

+ 4 - 10
src/Resources/material/Variable.cpp → src/Resources/MaterialVariable.cpp

@@ -1,17 +1,14 @@
-#include "Variable.h"
-#include "../shader_program/Variable.h"
-#include "../ShaderProgram.h"
+#include "MaterialVariable.h"
+#include "ShaderProgramVariable.h"
+#include "ShaderProgram.h"
 #include "Util/Assert.h"
 #include "Util/Exception.h"
 
 
-namespace material {
-
-
 //==============================================================================
 // Constructor                                                                 =
 //==============================================================================
-Variable::Variable(
+MaterialVariable::MaterialVariable(
 	Type type_,
 	const char* shaderProgVarName,
 	const ShaderPrograms& shaderProgsArr)
@@ -47,6 +44,3 @@ Variable::Variable(
 					shaderProgVarName);
 	}
 }
-
-
-} // end namespace

+ 9 - 15
src/Resources/material/Variable.h → src/Resources/MaterialVariable.h

@@ -1,8 +1,8 @@
 #ifndef MATERIAL_VARIABLE_H
 #define MATERIAL_VARIABLE_H
 
-#include "Common.h"
-#include "../shader_program/Variable.h"
+#include "MaterialCommon.h"
+#include "ShaderProgramVariable.h"
 #include "Util/Accessors.h"
 #include "Util/Assert.h"
 #include <GL/glew.h>
@@ -13,11 +13,8 @@
 class ShaderProgram;
 
 
-namespace material {
-
-
 /// XXX
-class Variable
+class MaterialVariable
 {
 	public:
 		/// The type
@@ -32,11 +29,11 @@ class Variable
 			ShaderPrograms;
 
 		/// XXX
-		typedef boost::array<const shader_program::Variable*,
+		typedef boost::array<const ShaderProgramVariable*,
 			PASS_TYPES_NUM> ShaderProgramVariables;
 
 		/// XXX
-		Variable(
+		MaterialVariable(
 			Type type,
 			const char* shaderProgVarName,
 			const ShaderPrograms& shaderProgsArr);
@@ -46,7 +43,7 @@ class Variable
 		GETTER_R_BY_VAL(Type, type, getType)
 
 		/// XXX
-		const shader_program::Variable& getShaderProgramVariable(
+		const ShaderProgramVariable& getShaderProgramVariable(
 			PassType p) const;
 
 		/// XXX
@@ -59,7 +56,7 @@ class Variable
 		const char* getName() const {return oneSProgVar->getName().c_str();}
 
 		/// Get the type of all the shader program variables
-		shader_program::Variable::Type getShaderProgramVariableType() const
+		ShaderProgramVariable::Type getShaderProgramVariableType() const
 			{return oneSProgVar->getType();}
 		/// @}
 
@@ -69,11 +66,11 @@ class Variable
 
 		/// Keep one ShaderProgramVariable here for easy access of the common
 		/// variable stuff like name or GL data type etc
-		const shader_program::Variable* oneSProgVar;
+		const ShaderProgramVariable* oneSProgVar;
 };
 
 
-inline const shader_program::Variable& Variable::getShaderProgramVariable(
+inline const ShaderProgramVariable& MaterialVariable::getShaderProgramVariable(
 	PassType p) const
 {
 	ASSERT(inPass(p));
@@ -81,7 +78,4 @@ inline const shader_program::Variable& Variable::getShaderProgramVariable(
 }
 
 
-} // end namespace
-
-
 #endif

+ 2 - 2
src/Resources/Mesh.h

@@ -1,5 +1,5 @@
-#ifndef MODEL_H
-#define MODEL_H
+#ifndef MODEL_MODEL_H
+#define MODEL_MODEL_H
 
 #include <boost/ptr_container/ptr_vector.hpp>
 #include "RsrcPtr.h"

+ 13 - 18
src/Resources/shader_program/ShaderProgram.cpp → src/Resources/ShaderProgram.cpp

@@ -1,5 +1,5 @@
 #include "Resources/ShaderProgram.h"
-#include "PrePreprocessor.h"
+#include "ShaderProgramPrePreprocessor.h"
 #include "Core/App.h" // To get cache dir
 #include "GfxApi/GlException.h"
 #include "Core/Logger.h"
@@ -14,10 +14,8 @@
 #include <sstream>
 
 
-namespace shader_program {
-
-
-#define SHADER_PROGRAM_EXCEPTION(x) EXCEPTION("Shader prog \"" + rsrcFilename + \
+#define SHADER_PROGRAM_EXCEPTION(x) EXCEPTION( \
+	"Shader program \"" + rsrcFilename + \
 	"\": " + x)
 
 
@@ -155,8 +153,8 @@ void ShaderProgram::getUniAndAttribVars()
 			continue;
 		}
 
-		AttributeVariable* var =
-			new AttributeVariable(loc, &name_[0], type, *this);
+		ShaderProgramAttributeVariable* var =
+			new ShaderProgramAttributeVariable(loc, &name_[0], type, *this);
 		vars.push_back(var);
 		nameToVar[var->getName().c_str()] = var;
 		nameToAttribVar[var->getName().c_str()] = var;
@@ -181,8 +179,8 @@ void ShaderProgram::getUniAndAttribVars()
 			continue;
 		}
 
-		UniformVariable* var =
-			new UniformVariable(loc, &name_[0], type, *this);
+		ShaderProgramUniformVariable* var =
+			new ShaderProgramUniformVariable(loc, &name_[0], type, *this);
 		vars.push_back(var);
 		nameToVar[var->getName().c_str()] = var;
 		nameToUniVar[var->getName().c_str()] = var;
@@ -198,7 +196,7 @@ void ShaderProgram::load(const char* filename)
 	rsrcFilename = filename;
 	ASSERT(glId == std::numeric_limits<uint>::max());
 
-	PrePreprocessor pars(filename);
+	ShaderProgramPrePreprocessor pars(filename);
 
 	// 1) create and compile the shaders
 	std::string preprocSource = stdSourceCode;
@@ -245,7 +243,7 @@ void ShaderProgram::load(const char* filename)
 //==============================================================================
 // getVariable                                                                 =
 //==============================================================================
-const Variable& ShaderProgram::getVariable(const char* name) const
+const ShaderProgramVariable& ShaderProgram::getVariable(const char* name) const
 {
 	VarsHashMap::const_iterator it = nameToVar.find(name);
 	if(it == nameToVar.end())
@@ -259,7 +257,7 @@ const Variable& ShaderProgram::getVariable(const char* name) const
 //==============================================================================
 // getAttributeVariable                                                        =
 //==============================================================================
-const AttributeVariable& ShaderProgram::getAttributeVariable(
+const ShaderProgramAttributeVariable& ShaderProgram::getAttributeVariable(
 	const char* name) const
 {
 	AttribVarsHashMap::const_iterator it = nameToAttribVar.find(name);
@@ -274,7 +272,7 @@ const AttributeVariable& ShaderProgram::getAttributeVariable(
 //==============================================================================
 // getUniformVariable                                                          =
 //==============================================================================
-const UniformVariable& ShaderProgram::getUniformVariable(
+const ShaderProgramUniformVariable& ShaderProgram::getUniformVariable(
 	const char* name) const
 {
 	UniVarsHashMap::const_iterator it = nameToUniVar.find(name);
@@ -366,10 +364,10 @@ std::string ShaderProgram::getShaderInfoString() const
 	std::stringstream ss;
 
 	ss << "Variables:\n";
-	BOOST_FOREACH(const Variable& var, vars)
+	BOOST_FOREACH(const ShaderProgramVariable& var, vars)
 	{
 		ss << var.getName() << " " << var.getLoc() << " ";
-		if(var.getType() == Variable::ATTRIBUTE)
+		if(var.getType() == ShaderProgramVariable::ATTRIBUTE)
 		{
 			ss << "attribute";
 		}
@@ -382,6 +380,3 @@ std::string ShaderProgram::getShaderInfoString() const
 
 	return ss.str();
 }
-
-
-} // end namespace

+ 136 - 6
src/Resources/ShaderProgram.h

@@ -1,12 +1,142 @@
-#ifndef SHADER_PROGRAM_H
-#define SHADER_PROGRAM_H
+#ifndef SHADER_PROGRAM_SHADER_PROGRAM_H
+#define SHADER_PROGRAM_SHADER_PROGRAM_H
 
-#include "shader_program/ShaderProgram.h"
+#include "Util/ConstCharPtrHashMap.h"
+#include "Util/Assert.h"
+#include "ShaderProgramUniformVariable.h"
+#include "ShaderProgramAttributeVariable.h"
+#include "Util/Vec.h"
+#include "GfxApi/GlStateMachine.h"
+#include "Core/Globals.h"
+#include <boost/ptr_container/ptr_vector.hpp>
+#include <GL/glew.h>
+#include <limits>
 
 
-/// Alias to sprog::ShaderProgram
-class ShaderProgram: public shader_program::ShaderProgram
-{};
+/// Shader program @ref Resource
+///
+/// Shader program. Combines a fragment and a vertex shader. Every shader
+/// program consist of one OpenGL ID, a vector of uniform variables and a
+/// vector of attribute variables. Every variable is a struct that contains
+/// the variable's name, location, OpenGL data type and if it is a uniform or
+/// an attribute var.
+class ShaderProgram
+{
+	public:
+		ShaderProgram();
+		~ShaderProgram();
+
+		/// @name Accessors
+		/// @{
+		GLuint getGlId() const;
+		GETTER_R(boost::ptr_vector<ShaderProgramVariable>, vars, getVariables)
+		/// @}
+
+		/// Resource load
+		void load(const char* filename);
+
+		/// Bind the shader program
+		void bind() const;
+
+		/// @name Variable getters
+		/// Used to find and return the variable. They throw exception if
+		/// variable not found so ask if the variable with that name exists
+		/// prior using any of these
+		/// @{
+		const ShaderProgramVariable& getVariable(const char* varName) const;
+		const ShaderProgramUniformVariable&
+			getUniformVariable(const char* varName) const;
+		const ShaderProgramAttributeVariable&
+			getAttributeVariable(const char* varName) const;
+		/// @}
+
+		/// @name Check for variable existance
+		/// @{
+		bool variableExists(const char* varName) const;
+		bool uniformVariableExists(const char* varName) const;
+		bool attributeVariableExists(const char* varName) const;
+		/// @}
+
+		/// Used by @ref Material and @ref Renderer to create custom shaders in
+		/// the cache
+		/// @param sProgFPathName The file pathname of the shader prog
+		/// @param preAppendedSrcCode The source code we want to write on top
+		/// of the shader prog
+		/// @param newFNamePrefix The prefix of the new shader prog
+		/// @return The file pathname of the new shader prog. Its
+		/// $HOME/.anki/cache/newFNamePrefix_fName
+		static std::string createSrcCodeToCache(const char* sProgFPathName,
+			const char* preAppendedSrcCode);
+
+		/// For debuging
+		std::string getShaderInfoString() const;
+
+	private:
+		/// XXX
+		typedef ConstCharPtrHashMap<ShaderProgramVariable*>::Type VarsHashMap;
+
+		/// XXX
+		typedef ConstCharPtrHashMap<ShaderProgramUniformVariable*>::Type
+			UniVarsHashMap;
+
+		/// XXX
+		typedef ConstCharPtrHashMap<ShaderProgramAttributeVariable*>::Type
+			AttribVarsHashMap;
+
+		std::string rsrcFilename;
+		GLuint glId; ///< The OpenGL ID of the shader program
+		GLuint vertShaderGlId; ///< Vertex shader OpenGL id
+		GLuint geomShaderGlId; ///< Geometry shader OpenGL id
+		GLuint fragShaderGlId; ///< Fragment shader OpenGL id
+
+		/// Shader source that is used in ALL shader programs
+		static const char* stdSourceCode;
+
+		/// @name Containers
+		/// @{
+		boost::ptr_vector<ShaderProgramVariable> vars; ///< All the vars
+		VarsHashMap nameToVar; ///< Variable searching
+		UniVarsHashMap nameToUniVar; ///< Uniform searching
+		AttribVarsHashMap nameToAttribVar; ///< Attribute searching
+		/// @}
+
+		/// Query the driver to get the vars. After the linking of the shader
+		/// prog is done gather all the vars in custom containers
+		void getUniAndAttribVars();
+
+		/// Create and compile shader
+		/// @return The shader's OpenGL id
+		/// @exception Exception
+		uint createAndCompileShader(const char* sourceCode,
+			const char* preproc, int type) const;
+
+		/// Link the shader program
+		/// @exception Exception
+		void link() const;
+}; 
+
+
+//==============================================================================
+// Inlines                                                                     =
+//==============================================================================
+
+inline ShaderProgram::ShaderProgram()
+:	glId(std::numeric_limits<uint>::max())
+{}
+
+
+inline GLuint ShaderProgram::getGlId() const
+{
+	ASSERT(glId != std::numeric_limits<uint>::max());
+	return glId;
+}
+
+
+inline void ShaderProgram::bind() const
+{
+	ASSERT(glId != std::numeric_limits<uint>::max());
+	GlStateMachineSingleton::getInstance().useShaderProg(glId);
+}
 
 
 #endif

+ 5 - 11
src/Resources/shader_program/AttributeVariable.h → src/Resources/ShaderProgramAttributeVariable.h

@@ -1,30 +1,24 @@
 #ifndef SHADER_PROGRAM_ATTRIBUTE_VARIABLE_H
 #define SHADER_PROGRAM_ATTRIBUTE_VARIABLE_H
 
-#include "Variable.h"
-
-
-namespace shader_program {
+#include "ShaderProgramVariable.h"
 
 
 /// Attribute shader program variable
-class AttributeVariable: public Variable
+class ShaderProgramAttributeVariable: public ShaderProgramVariable
 {
 	public:
-		AttributeVariable(
+		ShaderProgramAttributeVariable(
 			int loc, const char* name, GLenum glDataType,
 			const ShaderProgram& fatherSProg);
 };
 
 
-inline AttributeVariable::AttributeVariable(
+inline ShaderProgramAttributeVariable::ShaderProgramAttributeVariable(
 	int loc, const char* name,
 	GLenum glDataType, const ShaderProgram& fatherSProg)
-:	Variable(loc, name, glDataType, ATTRIBUTE, fatherSProg)
+:	ShaderProgramVariable(loc, name, glDataType, ATTRIBUTE, fatherSProg)
 {}
 
 
-} // end namespace
-
-
 #endif

+ 7 - 13
src/Resources/shader_program/PrePreprocessor.cpp → src/Resources/ShaderProgramPrePreprocessor.cpp

@@ -1,4 +1,4 @@
-#include "PrePreprocessor.h"
+#include "ShaderProgramPrePreprocessor.h"
 #include "Misc/Parser.h"
 #include "Util/Util.h"
 #include "Util/Exception.h"
@@ -9,9 +9,6 @@
 #include <boost/foreach.hpp>
 
 
-namespace shader_program {
-
-
 static const char* MULTIPLE_DEF_MSG = " already defined in the same place. "
 	"Check for circular or multiple includance";
 
@@ -19,7 +16,7 @@ static const char* MULTIPLE_DEF_MSG = " already defined in the same place. "
 //==============================================================================
 // printSourceLines                                                            =
 //==============================================================================
-void PrePreprocessor::printSourceLines() const
+void ShaderProgramPrePreprocessor::printSourceLines() const
 {
 	for(uint i = 0; i < sourceLines.size(); ++i)
 	{
@@ -32,7 +29,7 @@ void PrePreprocessor::printSourceLines() const
 //==============================================================================
 // parseFileForPragmas                                                         =
 //==============================================================================
-void PrePreprocessor::parseFileForPragmas(
+void ShaderProgramPrePreprocessor::parseFileForPragmas(
 	const std::string& filename, int depth)
 {
 	// first check the depth
@@ -138,7 +135,7 @@ void PrePreprocessor::parseFileForPragmas(
 //=============================================================================/
 // parseFile                                                                   =
 //==============================================================================
-void PrePreprocessor::parseFile(const char* filename)
+void ShaderProgramPrePreprocessor::parseFile(const char* filename)
 {
 	try
 	{
@@ -221,7 +218,7 @@ void PrePreprocessor::parseFile(const char* filename)
 //==============================================================================
 // parseStartPragma                                                            =
 //==============================================================================
-void PrePreprocessor::parseStartPragma(Scanner::Scanner& scanner,
+void ShaderProgramPrePreprocessor::parseStartPragma(Scanner::Scanner& scanner,
 	const std::string& filename, uint depth, const Vec<std::string>& lines)
 {
 	const Scanner::Token* token = &scanner.getNextToken();
@@ -278,7 +275,7 @@ void PrePreprocessor::parseStartPragma(Scanner::Scanner& scanner,
 //==============================================================================
 // parseIncludePragma                                                          =
 //==============================================================================
-void PrePreprocessor::parseIncludePragma(
+void ShaderProgramPrePreprocessor::parseIncludePragma(
 	Scanner::Scanner& scanner, const std::string& /*filename*/, uint depth,
 	const Vec<std::string>& lines)
 {
@@ -310,7 +307,7 @@ void PrePreprocessor::parseIncludePragma(
 //==============================================================================
 // parseTrffbVarying                                                           =
 //==============================================================================
-void PrePreprocessor::parseTrffbVarying(Scanner::Scanner& scanner,
+void ShaderProgramPrePreprocessor::parseTrffbVarying(Scanner::Scanner& scanner,
 	const std::string& filename, uint /*depth*/, const Vec<std::string>& lines)
 {
 	const Scanner::Token* token = &scanner.getNextToken();
@@ -351,6 +348,3 @@ void PrePreprocessor::parseTrffbVarying(Scanner::Scanner& scanner,
 		throw PARSER_EXCEPTION_EXPECTED("identifier");
 	}
 }
-
-
-} // end namespace

+ 6 - 12
src/Resources/shader_program/PrePreprocessor.h → src/Resources/ShaderProgramPrePreprocessor.h

@@ -12,9 +12,6 @@ class Scanner;
 }
 
 
-namespace shader_program {
-
-
 /// Helper class used for shader program loading
 ///
 /// The class fills some of the GLSL spec deficiencies. It adds the include
@@ -29,17 +26,17 @@ namespace shader_program {
 /// - #pragma anki transformFeedbackVarying <varName>
 ///
 /// @note The order of the *ShaderBegins is important
-class PrePreprocessor
+class ShaderProgramPrePreprocessor
 {
 	public:
 		/// It loads a file and parses it
 		/// @param[in] filename The file to load
 		/// @exception Exception
-		PrePreprocessor(const char* filename)
+		ShaderProgramPrePreprocessor(const char* filename)
 			{parseFile(filename);}
 
 		/// Destructor does nothing
-		~PrePreprocessor() {}
+		~ShaderProgramPrePreprocessor() {}
 
 		/// @name Accessors
 		/// @{
@@ -147,14 +144,14 @@ class PrePreprocessor
 // Inlines                                                                     =
 //==============================================================================
 
-inline PrePreprocessor::Pragma::Pragma(
+inline ShaderProgramPrePreprocessor::Pragma::Pragma(
 	const std::string& definedInFile_, int definedInLine_)
 :	definedInFile(definedInFile_),
 	definedInLine(definedInLine_)
 {}
 
 
-inline PrePreprocessor::TrffbVaryingPragma::TrffbVaryingPragma(
+inline ShaderProgramPrePreprocessor::TrffbVaryingPragma::TrffbVaryingPragma(
 	const std::string& definedInFile_,
 	int definedInLine_, const std::string& name_)
 :	Pragma(definedInFile_, definedInLine_),
@@ -163,7 +160,7 @@ inline PrePreprocessor::TrffbVaryingPragma::TrffbVaryingPragma(
 
 
 template<typename Type>
-typename Vec<Type>::const_iterator PrePreprocessor::findNamed(
+typename Vec<Type>::const_iterator ShaderProgramPrePreprocessor::findNamed(
 	const Vec<Type>& vec, const std::string& what) const
 {
 	typename Vec<Type>::const_iterator it = vec.begin();
@@ -175,7 +172,4 @@ typename Vec<Type>::const_iterator PrePreprocessor::findNamed(
 }
 
 
-} // end namespace
-
-
 #endif

+ 9 - 15
src/Resources/shader_program/UniformVariable.cpp → src/Resources/ShaderProgramUniformVariable.cpp

@@ -1,16 +1,13 @@
-#include "UniformVariable.h"
+#include "ShaderProgramUniformVariable.h"
 #include "Resources/ShaderProgram.h"
 #include "Resources/Texture.h"
 #include "GfxApi/GlStateMachine.h"
 
 
-namespace shader_program {
-
-
 //==============================================================================
 // doSanityChecks                                                              =
 //==============================================================================
-void UniformVariable::doSanityChecks() const
+void ShaderProgramUniformVariable::doSanityChecks() const
 {
 	ASSERT(getLoc() != -1);
 	ASSERT(GlStateMachineSingleton::getInstance().getCurrentProgramGlId() ==
@@ -24,7 +21,7 @@ void UniformVariable::doSanityChecks() const
 // set uniforms                                                                =
 //==============================================================================
 
-void UniformVariable::set(const float f[], uint size) const
+void ShaderProgramUniformVariable::set(const float f[], uint size) const
 {
 	doSanityChecks();
 	ASSERT(getGlDataType() == GL_FLOAT);
@@ -40,7 +37,7 @@ void UniformVariable::set(const float f[], uint size) const
 }
 
 
-void UniformVariable::set(const Vec2 v2[], uint size) const
+void ShaderProgramUniformVariable::set(const Vec2 v2[], uint size) const
 {
 	doSanityChecks();
 	ASSERT(getGlDataType() == GL_FLOAT_VEC2);
@@ -55,7 +52,7 @@ void UniformVariable::set(const Vec2 v2[], uint size) const
 }
 
 
-void UniformVariable::set(const Vec3 v3[], uint size) const
+void ShaderProgramUniformVariable::set(const Vec3 v3[], uint size) const
 {
 	doSanityChecks();
 	ASSERT(getGlDataType() == GL_FLOAT_VEC3);
@@ -71,7 +68,7 @@ void UniformVariable::set(const Vec3 v3[], uint size) const
 }
 
 
-void UniformVariable::set(const Vec4 v4[], uint size) const
+void ShaderProgramUniformVariable::set(const Vec4 v4[], uint size) const
 {
 	doSanityChecks();
 	ASSERT(getGlDataType() == GL_FLOAT_VEC4);
@@ -79,7 +76,7 @@ void UniformVariable::set(const Vec4 v4[], uint size) const
 }
 
 
-void UniformVariable::set(const Mat3 m3[], uint size) const
+void ShaderProgramUniformVariable::set(const Mat3 m3[], uint size) const
 {
 	doSanityChecks();
 	ASSERT(getGlDataType() == GL_FLOAT_MAT3);
@@ -87,7 +84,7 @@ void UniformVariable::set(const Mat3 m3[], uint size) const
 }
 
 
-void UniformVariable::set(const Mat4 m4[], uint size) const
+void ShaderProgramUniformVariable::set(const Mat4 m4[], uint size) const
 {
 	doSanityChecks();
 	ASSERT(getGlDataType() == GL_FLOAT_MAT4);
@@ -95,7 +92,7 @@ void UniformVariable::set(const Mat4 m4[], uint size) const
 }
 
 
-void UniformVariable::set(const Texture& tex, uint texUnit) const
+void ShaderProgramUniformVariable::set(const Texture& tex, uint texUnit) const
 {
 	doSanityChecks();
 	ASSERT(getGlDataType() == GL_SAMPLER_2D ||
@@ -103,6 +100,3 @@ void UniformVariable::set(const Texture& tex, uint texUnit) const
 	tex.bind(texUnit);
 	glUniform1i(getLoc(), texUnit);
 }
-
-
-} // end namespace

+ 8 - 12
src/Resources/shader_program/UniformVariable.h → src/Resources/ShaderProgramUniformVariable.h

@@ -1,21 +1,20 @@
 #ifndef SHADER_PROGRAM_UNIFORM_VARIABLE_H
 #define SHADER_PROGRAM_UNIFORM_VARIABLE_H
 
-#include "Variable.h"
+#include "ShaderProgramVariable.h"
 #include "Math/Math.h"
 
 
 class Texture;
 
 
-namespace shader_program {
-
-
 /// Uniform shader variable
-class UniformVariable: public Variable
+class ShaderProgramUniformVariable: public ShaderProgramVariable
 {
 	public:
-		UniformVariable(int loc, const char* name,
+		ShaderProgramUniformVariable(
+			int loc,
+			const char* name,
 			GLenum glDataType,
 			const ShaderProgram& fatherSProg);
 
@@ -39,14 +38,11 @@ class UniformVariable: public Variable
 };
 
 
-inline UniformVariable::UniformVariable(
+inline ShaderProgramUniformVariable::ShaderProgramUniformVariable(
 	int loc_, const char* name_,
-	GLenum glDataType_, const ShaderProgram& fatherSHADER_PROGRAM_)
-:	Variable(loc_, name_, glDataType_, UNIFORM, fatherSHADER_PROGRAM_)
+	GLenum glDataType_, const ShaderProgram& father_)
+:	ShaderProgramVariable(loc_, name_, glDataType_, UNIFORM, father_)
 {}
 
 
-} // end namespace
-
-
 #endif

+ 4 - 8
src/Resources/shader_program/Variable.h → src/Resources/ShaderProgramVariable.h

@@ -5,14 +5,13 @@
 #include <GL/glew.h>
 #include <string>
 #include <boost/noncopyable.hpp>
-#include "Fwd.h"
 
 
-namespace shader_program {
+class ShaderProgram;
 
 
 /// Shader program variable. The type is attribute or uniform
-class Variable: public boost::noncopyable
+class ShaderProgramVariable: public boost::noncopyable
 {
 	public:
 		/// Shader var types
@@ -22,7 +21,7 @@ class Variable: public boost::noncopyable
 			UNIFORM
 		};
 
-		Variable(GLint loc, const char* name,
+		ShaderProgramVariable(GLint loc, const char* name,
 			GLenum glDataType, Type type,
 			const ShaderProgram& fatherSProg);
 
@@ -49,7 +48,7 @@ class Variable: public boost::noncopyable
 };
 
 
-inline Variable::Variable(GLint loc_,
+inline ShaderProgramVariable::ShaderProgramVariable(GLint loc_,
 	const char* name_, GLenum glDataType_,
 	Type type_, const ShaderProgram& fatherSHADER_PROGRAM_)
 :	loc(loc_),
@@ -60,7 +59,4 @@ inline Variable::Variable(GLint loc_,
 {}
 
 
-} // end namespace
-
-
 #endif

+ 0 - 15
src/Resources/material/Fwd.h

@@ -1,15 +0,0 @@
-#ifndef MATERIAL_FWD_H
-#define MATERIAL_FWD_H
-
-
-namespace material {
-
-class Variable;
-class BuildinVariable;
-class UserVariable;
-class Material;
-
-}
-
-
-#endif

+ 0 - 189
src/Resources/material/Material.h

@@ -1,189 +0,0 @@
-#ifndef MATERIAL_MATERIAL_H
-#define MATERIAL_MATERIAL_H
-
-#include "UserVariable.h"
-#include "BuildinVariable.h"
-#include "Common.h"
-#include "Properties.h"
-#include "Util/Accessors.h"
-#include "Util/ConstCharPtrHashMap.h"
-#include <GL/glew.h>
-#include <boost/ptr_container/ptr_vector.hpp>
-#include <boost/array.hpp>
-#include <boost/scoped_ptr.hpp>
-#include <boost/property_tree/ptree_fwd.hpp>
-
-
-class ShaderProgram;
-
-
-namespace material {
-
-
-/// Material resource
-///
-/// Every material keeps info of how to render a RenedrableNode. Using a node
-/// based logic it creates a couple of shader programs dynamically. One for
-/// color passes and one for depth. It also keeps two sets of material
-/// variables. The first is the build in and the second the user defined.
-/// During the renderer's shader setup the buildins will be set automatically,
-/// for the user variables the user needs to have its value in the material
-/// file. Some material variables may be present in both shader programs and
-/// some in only one of them
-///
-/// Material XML file format:
-/// @code
-/// <material>
-/// 	<castsShadow>true | false</castsShadow>
-///
-/// 	<renderInBlendingStage>true | false</renderInBlendingStage>
-///
-/// 	<blendFunctions>
-/// 		<sFactor>GL_SOMETHING</sFactor>
-/// 		<dFactor>GL_SOMETHING</dFactor>
-/// 	</blendFunctions>
-///
-/// 	<depthTesting>true | false</depthTesting>
-///
-/// 	<wireframe>true | false</wireframe>
-///
-/// 	<shaderProgram>
-/// 		<includes>
-/// 			<include>file.glsl</include>
-/// 			<include>file2.glsl</include>
-/// 		</includes>
-///
-/// 		<inputs>
-/// 			<input> *
-/// 				<name>xx</name>
-/// 				<value>
-/// 					<float>0.0</float> |
-/// 					<vec2><x>0.0</x><y>0.0</y></vec2> |
-/// 					<vec3><x>0.0</x><y>0.0</y><z>0.0</z></vec3> |
-/// 					<vec4><x>0.0</x><y>0.0</y><z>0.0</z><w>0.0</w></vec4> |
-/// 					<sampler2D>path/to/image.tga</sampler2D>
-/// 				</value>
-/// 			</input>
-/// 		</inputs>
-///
-/// 		<operations>
-/// 			<operation>
-/// 				<id>x</id>
-/// 				<function>functionName</function>
-/// 				<arguments>
-/// 					<argument>xx</argument>
-/// 					<argument>yy</argument>
-/// 				</arguments>
-/// 			</operation>
-/// 		</operations>
-///
-/// 	</shaderProgram>
-/// </material>
-/// @endcode
-/// *: For if the value is not set then the in variable will be build in or
-///    standard varying
-class Material: private Properties
-{
-	public:
-		//======================================================================
-		// Nested                                                              =
-		//======================================================================
-
-		typedef boost::ptr_vector<Variable> VarsContainer;
-
-		typedef boost::unordered_map<BuildinVariable::BuildinEnum,
-			BuildinVariable*> BuildinEnumToBuildinHashMap;
-
-		typedef boost::array<BuildinVariable*,
-			BuildinVariable::BUILDINS_NUM> BuildinsArr;
-
-		//======================================================================
-		// Methods                                                             =
-		//======================================================================
-
-		/// Initialize with default values
-		Material();
-
-		~Material();
-
-		/// @name Accessors
-		/// @{
-		GETTER_R_BY_VAL(bool, castsShadowFlag, castsShadow)
-		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)
-		GETTER_R_BY_VAL(bool, wireframe, isWireframeEnabled)
-
-		/// Access the base class just for copying in other classes
-		GETTER_R(Properties, *this, accessPropertiesBaseClass)
-
-		const ShaderProgram& getShaderProgram(PassType p) const
-			{return *sProgs[p];}
-
-		// Variable accessors
-		GETTER_R(VarsContainer, mtlVars, getVariables)
-		GETTER_R(Vec<UserVariable*>, userMtlVars, getUserVariables)
-		const BuildinVariable& getBuildinVariable(
-			BuildinVariable::BuildinEnum e) const;
-		/// @}
-
-		/// Load a material file
-		void load(const char* filename);
-
-		/// Check if a buildin variable exists
-		bool buildinVariableExits(BuildinVariable::BuildinEnum e)
-			const {return buildinsArr[e] != NULL;}
-
-	private:
-		//======================================================================
-		// Nested                                                              =
-		//======================================================================
-
-		typedef boost::array<RsrcPtr<ShaderProgram>, PASS_TYPES_NUM>
-			ShaderPrograms;
-
-		//======================================================================
-		// Members                                                             =
-		//======================================================================
-
-		/// From "GL_ZERO" return GL_ZERO
-		static ConstCharPtrHashMap<GLenum>::Type txtToBlengGlEnum;
-
-		/// All the material variables. Both buildins and user
-		VarsContainer mtlVars;
-
-		BuildinsArr buildinsArr; ///< To find. Initialize to int
-
-		Vec<UserVariable*> userMtlVars; ///< To iterate
-
-		/// The most important aspect of materials
-		ShaderPrograms sProgs;
-
-		//======================================================================
-		// Methods                                                             =
-		//======================================================================
-
-		/// Parse what is within the @code <material></material> @endcode
-		void parseMaterialTag(const boost::property_tree::ptree& pt);
-
-		/// XXX
-		std::string createShaderProgSourceToCache(const std::string& source);
-
-		/// XXX
-		void populateVariables(const boost::property_tree::ptree& pt);
-};
-
-
-inline const BuildinVariable& Material::getBuildinVariable(
-	BuildinVariable::BuildinEnum e) const
-{
-	ASSERT(buildinVariableExits(e));
-	return *buildinsArr[e];
-}
-
-
-} // end namespace
-
-
-#endif

+ 0 - 15
src/Resources/shader_program/Fwd.h

@@ -1,15 +0,0 @@
-#ifndef SHADER_PROGRAM_FWD_H
-#define SHADER_PROGRAM_FWD_H
-
-
-namespace shader_program {
-
-class ShaderProgram;
-class UniformVariable;
-class AttributeVariable;
-class PrePreprocessor;
-
-} // end namespace
-
-
-#endif

+ 0 - 149
src/Resources/shader_program/ShaderProgram.h

@@ -1,149 +0,0 @@
-#ifndef SHADER_PROGRAM_SHADER_PROGRAM_H
-#define SHADER_PROGRAM_SHADER_PROGRAM_H
-
-#include "Fwd.h"
-#include "Util/ConstCharPtrHashMap.h"
-#include "Util/Assert.h"
-#include "UniformVariable.h"
-#include "AttributeVariable.h"
-#include "Util/Vec.h"
-#include "GfxApi/GlStateMachine.h"
-#include "Core/Globals.h"
-#include <boost/ptr_container/ptr_vector.hpp>
-#include <GL/glew.h>
-#include <limits>
-
-
-namespace shader_program {
-
-
-/// Shader program @ref Resource
-///
-/// Shader program. Combines a fragment and a vertex shader. Every shader
-/// program consist of one OpenGL ID, a vector of uniform variables and a
-/// vector of attribute variables. Every variable is a struct that contains
-/// the variable's name, location, OpenGL data type and if it is a uniform or
-/// an attribute var.
-class ShaderProgram
-{
-	public:
-		ShaderProgram();
-		~ShaderProgram();
-
-		/// @name Accessors
-		/// @{
-		GLuint getGlId() const;
-		GETTER_R(boost::ptr_vector<Variable>, vars, getVariables)
-		/// @}
-
-		/// Resource load
-		void load(const char* filename);
-
-		/// Bind the shader program
-		void bind() const;
-
-		/// @name Variable getters
-		/// Used to find and return the variable. They throw exception if
-		/// variable not found so ask if the variable with that name exists
-		/// prior using any of these
-		/// @{
-		const Variable& getVariable(const char* varName) const;
-		const UniformVariable&
-			getUniformVariable(const char* varName) const;
-		const AttributeVariable&
-			getAttributeVariable(const char* varName) const;
-		/// @}
-
-		/// @name Check for variable existance
-		/// @{
-		bool variableExists(const char* varName) const;
-		bool uniformVariableExists(const char* varName) const;
-		bool attributeVariableExists(const char* varName) const;
-		/// @}
-
-		/// Used by @ref Material and @ref Renderer to create custom shaders in
-		/// the cache
-		/// @param sProgFPathName The file pathname of the shader prog
-		/// @param preAppendedSrcCode The source code we want to write on top
-		/// of the shader prog
-		/// @param newFNamePrefix The prefix of the new shader prog
-		/// @return The file pathname of the new shader prog. Its
-		/// $HOME/.anki/cache/newFNamePrefix_fName
-		static std::string createSrcCodeToCache(const char* sProgFPathName,
-			const char* preAppendedSrcCode);
-
-		/// For debuging
-		std::string getShaderInfoString() const;
-
-	private:
-		/// XXX
-		typedef ConstCharPtrHashMap<Variable*>::Type VarsHashMap;
-
-		/// XXX
-		typedef ConstCharPtrHashMap<UniformVariable*>::Type
-			UniVarsHashMap;
-
-		/// XXX
-		typedef ConstCharPtrHashMap<AttributeVariable*>::Type
-			AttribVarsHashMap;
-
-		std::string rsrcFilename;
-		GLuint glId; ///< The OpenGL ID of the shader program
-		GLuint vertShaderGlId; ///< Vertex shader OpenGL id
-		GLuint geomShaderGlId; ///< Geometry shader OpenGL id
-		GLuint fragShaderGlId; ///< Fragment shader OpenGL id
-
-		/// Shader source that is used in ALL shader programs
-		static const char* stdSourceCode;
-
-		/// @name Containers
-		/// @{
-		boost::ptr_vector<Variable> vars; ///< All the vars
-		VarsHashMap nameToVar; ///< Variable searching
-		UniVarsHashMap nameToUniVar; ///< Uniform searching
-		AttribVarsHashMap nameToAttribVar; ///< Attribute searching
-		/// @}
-
-		/// Query the driver to get the vars. After the linking of the shader
-		/// prog is done gather all the vars in custom containers
-		void getUniAndAttribVars();
-
-		/// Create and compile shader
-		/// @return The shader's OpenGL id
-		/// @exception Exception
-		uint createAndCompileShader(const char* sourceCode,
-			const char* preproc, int type) const;
-
-		/// Link the shader program
-		/// @exception Exception
-		void link() const;
-}; 
-
-
-//==============================================================================
-// Inlines                                                                     =
-//==============================================================================
-
-inline ShaderProgram::ShaderProgram()
-:	glId(std::numeric_limits<uint>::max())
-{}
-
-
-inline GLuint ShaderProgram::getGlId() const
-{
-	ASSERT(glId != std::numeric_limits<uint>::max());
-	return glId;
-}
-
-
-inline void ShaderProgram::bind() const
-{
-	ASSERT(glId != std::numeric_limits<uint>::max());
-	GlStateMachineSingleton::getInstance().useShaderProg(glId);
-}
-
-
-} // end namespace
-
-
-#endif

+ 9 - 10
src/Scene/material_runtime/MaterialRuntime.cpp → src/Scene/MaterialRuntime.cpp

@@ -1,6 +1,6 @@
 #include "MaterialRuntime.h"
 #include "Resources/Material.h"
-#include "UserVariableRuntime.h"
+#include "MaterialRuntimeVariable.h"
 #include <boost/foreach.hpp>
 
 
@@ -12,16 +12,15 @@ MaterialRuntime::MaterialRuntime(const Material& mtl_)
 {
 	// Copy props
 	MaterialProperties& me = *this;
-	const MaterialProperties& he = mtl.accessMaterialPropertiesBaseClass();
+	const MaterialProperties& he = mtl.accessPropertiesBaseClass();
 	me = he;
 
 	// Create vars
-	BOOST_FOREACH(const UserVariable* var, mtl.getUserVariables())
+	BOOST_FOREACH(const MaterialUserVariable* var, mtl.getUserVariables())
 	{
-		UserVariableRuntime* varr =
-			new UserVariableRuntime(*var);
+		MaterialRuntimeVariable* varr = new MaterialRuntimeVariable(*var);
 		vars.push_back(varr);
-		varNameToVar[varr->getUserVariable().getName().c_str()] = varr;
+		varNameToVar[varr->getMaterialUserVariable().getName()] = varr;
 	}
 }
 
@@ -36,10 +35,10 @@ MaterialRuntime::~MaterialRuntime()
 //==============================================================================
 // findVariableByName                                                          =
 //==============================================================================
-UserVariableRuntime& MaterialRuntime::findVariableByName(
+MaterialRuntimeVariable& MaterialRuntime::findVariableByName(
 	const char* name)
 {
-	ConstCharPtrHashMap<UserVariableRuntime*>::Type::iterator it =
+	ConstCharPtrHashMap<MaterialRuntimeVariable*>::Type::iterator it =
 		varNameToVar.find(name);
 	if(it == varNameToVar.end())
 	{
@@ -53,10 +52,10 @@ UserVariableRuntime& MaterialRuntime::findVariableByName(
 //==============================================================================
 // findVariableByName                                                          =
 //==============================================================================
-const UserVariableRuntime& MaterialRuntime::findVariableByName(
+const MaterialRuntimeVariable& MaterialRuntime::findVariableByName(
 	const char* name) const
 {
-	ConstCharPtrHashMap<UserVariableRuntime*>::Type::const_iterator
+	ConstCharPtrHashMap<MaterialRuntimeVariable*>::Type::const_iterator
 		it = varNameToVar.find(name);
 	if(it == varNameToVar.end())
 	{

+ 9 - 20
src/Scene/material_runtime/MaterialRuntime.h → src/Scene/MaterialRuntime.h

@@ -1,14 +1,14 @@
-#ifndef MATERIAL_RUNTIME_2_H
-#define MATERIAL_RUNTIME_2_H
+#ifndef MATERIAL_RUNTIME_MATERIAL_RUNTIME_H
+#define MATERIAL_RUNTIME_MATERIAL_RUNTIME_H
 
-#include "Resources/Material.h"
+#include "Resources/MaterialProperties.h"
 #include "Util/Accessors.h"
 #include "Util/ConstCharPtrHashMap.h"
 #include <boost/ptr_container/ptr_vector.hpp>
 
 
-class UserVariableRuntime;
 class Material;
+class MaterialRuntimeVariable;
 
 
 /// One layer above material resource
@@ -16,7 +16,7 @@ class MaterialRuntime: private MaterialProperties
 {
 	public:
 		/// A type
-		typedef boost::ptr_vector<UserVariableRuntime>
+		typedef boost::ptr_vector<MaterialRuntimeVariable>
 			VariablesContainer;
 
 		/// @name Constructors & destructors
@@ -43,33 +43,22 @@ class MaterialRuntime: private MaterialProperties
 		GETTER_R(Material, mtl, getMaterial);
 		/// @}
 
-		/// Find MaterialRuntimeUserDefinedVar variable. On failure it throws
-		/// an exception
+		/// Find a material runtime variable. On failure it throws an exception
 		/// @param[in] name The name of the var
 		/// @return It returns a MaterialRuntimeUserDefinedVar
 		/// @exception Exception
-		UserVariableRuntime& findVariableByName(
-			const char* name);
+		MaterialRuntimeVariable& findVariableByName(const char* name);
 
 		/// The const version of getUserDefinedVarByName
 		/// @see getUserDefinedVarByName
-		const UserVariableRuntime& findVariableByName(
+		const MaterialRuntimeVariable& findVariableByName(
 			const char* name) const;
 
-		bool isBlendingEnabled() const;
-
 	private:
 		const Material& mtl; ///< The resource
 		VariablesContainer vars;
-		ConstCharPtrHashMap<UserVariableRuntime*>::Type
-			varNameToVar;
+		ConstCharPtrHashMap<MaterialRuntimeVariable*>::Type varNameToVar;
 };
 
 
-inline bool MaterialRuntime::isBlendingEnabled() const
-{
-	return blendingSfactor != GL_ONE || blendingDfactor != GL_ZERO;
-}
-
-
 #endif

+ 11 - 16
src/Scene/material_runtime/Variable.cpp → src/Scene/MaterialRuntimeVariable.cpp

@@ -1,15 +1,12 @@
-#include "UserVariableRuntime.h"
-#include "Resources/UserVariable.h"
-
-
-namespace material_runtime {
+#include "MaterialRuntimeVariable.h"
+#include "Resources/MaterialUserVariable.h"
 
 
 //==============================================================================
 // ConstructVisitor::operator() <RsrcPtr<Texture> >                            =
 //==============================================================================
 template <>
-void UserVariableRuntime::ConstructVisitor::
+void MaterialRuntimeVariable::ConstructVisitor::
 	operator()<RsrcPtr<Texture> >(const RsrcPtr<Texture>& x) const
 {
 	udvr.data = &x;
@@ -19,8 +16,8 @@ void UserVariableRuntime::ConstructVisitor::
 //==============================================================================
 // Constructor                                                                 =
 //==============================================================================
-UserVariableRuntime::UserVariableRuntime(
-	const UserVariable& umv_)
+MaterialRuntimeVariable::MaterialRuntimeVariable(
+	const MaterialUserVariable& umv_)
 :	umv(umv_)
 {
 	// Initialize the data using a visitor
@@ -31,7 +28,7 @@ UserVariableRuntime::UserVariableRuntime(
 //==============================================================================
 // Destructor                                                                  =
 //==============================================================================
-UserVariableRuntime::~UserVariableRuntime()
+MaterialRuntimeVariable::~MaterialRuntimeVariable()
 {}
 
 
@@ -40,9 +37,9 @@ UserVariableRuntime::~UserVariableRuntime()
 //==============================================================================
 
 template<>
-UserVariableRuntime::ConstPtrRsrcPtrTexture&
-	UserVariableRuntime::getValue<
-	UserVariableRuntime::ConstPtrRsrcPtrTexture>()
+MaterialRuntimeVariable::ConstPtrRsrcPtrTexture&
+	MaterialRuntimeVariable::getValue<
+	MaterialRuntimeVariable::ConstPtrRsrcPtrTexture>()
 {
 	throw EXCEPTION("You shouldn't call this getter");
 	return boost::get<ConstPtrRsrcPtrTexture>(data);
@@ -50,13 +47,11 @@ UserVariableRuntime::ConstPtrRsrcPtrTexture&
 
 
 template<>
-void UserVariableRuntime::setValue<
-	UserVariableRuntime::ConstPtrRsrcPtrTexture>(
+void MaterialRuntimeVariable::setValue<
+	MaterialRuntimeVariable::ConstPtrRsrcPtrTexture>(
 	const ConstPtrRsrcPtrTexture& v)
 {
 	throw EXCEPTION("You shouldn't call this setter");
 	boost::get<ConstPtrRsrcPtrTexture>(data) = v;
 }
 
-
-} // end namespace

+ 12 - 17
src/Scene/material_runtime/Variable.h → src/Scene/MaterialRuntimeVariable.h

@@ -4,37 +4,35 @@
 #include "Util/Accessors.h"
 #include "Math/Math.h"
 #include "Resources/RsrcPtr.h"
-#include "Resources/material/Fwd.h"
 #include <boost/variant.hpp>
 
 
 class Texture;
+class MaterialUserVariable;
 
 
-namespace material_runtime {
-
-
+/// Variable of runtime materials
 /// This holds a copy of the MtlUserDefinedVar's data in order to be changed
 /// inside the main loop
-class Variable
+class MaterialRuntimeVariable
 {
 	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
+		/// Don't EVER replace the texture with const Texture*. The asynchronous
 		/// operations will fail
 		typedef boost::variant<float, Vec2, Vec3, Vec4,
 			ConstPtrRsrcPtrTexture> DataVariant;
 
 		/// Constructor
-		Variable(const material::UserVariable& umv);
+		MaterialRuntimeVariable(const MaterialUserVariable& umv);
 		/// Destructor
-		~Variable();
+		~MaterialRuntimeVariable();
 
 		/// @name Accessors
 		/// @{
-		GETTER_R(material::UserVariable, umv, getUserVariable)
+		GETTER_R(MaterialUserVariable, umv, getMaterialUserVariable)
 		GETTER_RW(DataVariant, data, getDataVariant)
 
 		/// Get the value of the variant
@@ -58,9 +56,9 @@ class Variable
 		class ConstructVisitor: public boost::static_visitor<void>
 		{
 			public:
-				Variable& udvr;
+				MaterialRuntimeVariable& udvr;
 
-				ConstructVisitor(Variable& udmvr);
+				ConstructVisitor(MaterialRuntimeVariable& udmvr);
 
 				/// Template method that applies to all DataVariant values
 				/// except texture resource
@@ -69,18 +67,15 @@ class Variable
 					{udvr.getDataVariant() = x;}
 		};
 
-		const material::UserVariable& umv; ///< Know the resource
+		const MaterialUserVariable& umv; ///< Know the resource
 		DataVariant data; /// The data
 };
 
 
-inline Variable::ConstructVisitor::ConstructVisitor(
-	material::UserVariable& udvr_)
+inline MaterialRuntimeVariable::ConstructVisitor::ConstructVisitor(
+	MaterialRuntimeVariable& udvr_)
 :	udvr(udvr_)
 {}
 
 
-} // end namespace
-
-
 #endif

+ 7 - 5
src/Scene/ModelPatchNode.cpp

@@ -12,8 +12,7 @@
 //==============================================================================
 ModelPatchNode::ModelPatchNode(const ModelPatch& modelPatch_,
 	ModelNode* parent)
-:	PatchNode(modelPatch_, parent),
-	modelPatch(modelPatch_)
+:	PatchNode(modelPatch_, parent)
 {
 	boost::array<const Vbo*, Mesh::VBOS_NUM> vboArr;
 
@@ -22,8 +21,11 @@ ModelPatchNode::ModelPatchNode(const ModelPatch& modelPatch_,
 		vboArr[i] = &rsrc.getMesh().getVbo((Mesh::Vbos)i);
 	}
 
-	createVao(rsrc.getCpMtl(), vboArr, cpVao);
-	createVao(rsrc.getDpMtl(), vboArr, dpVao);
+
+	for(uint i = 0; i < PASS_TYPES_NUM; i++)
+	{
+		createVao(rsrc.getMaterial(), vboArr, vaos[i]);
+	}
 }
 
 
@@ -33,6 +35,6 @@ ModelPatchNode::ModelPatchNode(const ModelPatch& modelPatch_,
 void ModelPatchNode::moveUpdate()
 {
 	visibilityShapeWSpace =
-		modelPatch.getMesh().getVisibilityShape().getTransformed(
+		rsrc.getMesh().getVisibilityShape().getTransformed(
 		getWorldTransform());
 }

+ 0 - 1
src/Scene/ModelPatchNode.h

@@ -19,7 +19,6 @@ class ModelPatchNode: public PatchNode
 		virtual void moveUpdate(); ///< Update the visibility shape
 
 	private:
-		const ModelPatch& modelPatch;
 		Col::Obb visibilityShapeWSpace;
 };
 

+ 17 - 17
src/Scene/PatchNode.cpp

@@ -8,11 +8,9 @@
 //==============================================================================
 PatchNode::PatchNode(const ModelPatch& modelPatch, SceneNode* parent)
 :	RenderableNode(true, parent),
-	rsrc(modelPatch)
-{
-	cpMtlRun.reset(new MaterialRuntime(rsrc.getCpMtl()));
-	dpMtlRun.reset(new MaterialRuntime(rsrc.getDpMtl()));
-}
+	rsrc(modelPatch),
+	mtlRun(new MaterialRuntime(rsrc.getMaterial()))
+{}
 
 
 //==============================================================================
@@ -23,32 +21,34 @@ void PatchNode::createVao(const Material& mtl, const boost::array<const Vbo*,
 {
 	vao.create();
 
-	if(mtl.getStdAttribVar(Material::SAV_POSITION) != NULL)
+	if(mtl.buildinVariableExits(MaterialBuildinVariable::POSITION))
 	{
+		ASSERT(vbos[Mesh::VBO_VERT_POSITIONS] != NULL);
+
 		vao.attachArrayBufferVbo(*vbos[Mesh::VBO_VERT_POSITIONS],
-			*mtl.getStdAttribVar(Material::SAV_POSITION),
-			3, GL_FLOAT, GL_FALSE, 0, NULL);
+			0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
 	}
 
-	if(mtl.getStdAttribVar(Material::SAV_NORMAL) != NULL)
+	if(mtl.buildinVariableExits(MaterialBuildinVariable::NORMAL))
 	{
+		ASSERT(vbos[Mesh::VBO_VERT_NORMALS] != NULL);
+
 		vao.attachArrayBufferVbo(*vbos[Mesh::VBO_VERT_NORMALS],
-			*mtl.getStdAttribVar(Material::SAV_NORMAL),
-			3, GL_FLOAT, GL_FALSE, 0, NULL);
+			1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
 	}
 
-	if(mtl.getStdAttribVar(Material::SAV_TANGENT) != NULL)
+	if(mtl.buildinVariableExits(MaterialBuildinVariable::TANGENT))
 	{
+		ASSERT(vbos[Mesh::VBO_VERT_TANGENTS] != NULL);
+
 		vao.attachArrayBufferVbo(*vbos[Mesh::VBO_VERT_TANGENTS],
-			*mtl.getStdAttribVar(Material::SAV_TANGENT),
-			4, GL_FLOAT, GL_FALSE, 0, NULL);
+			2, 4, GL_FLOAT, GL_FALSE, 0, NULL);
 	}
 
-	if(mtl.getStdAttribVar(Material::SAV_TEX_COORDS) != NULL)
+	if(mtl.buildinVariableExits(MaterialBuildinVariable::TEX_COORDS))
 	{
 		vao.attachArrayBufferVbo(*vbos[Mesh::VBO_TEX_COORDS],
-			*mtl.getStdAttribVar(Material::SAV_TEX_COORDS),
-			2, GL_FLOAT, GL_FALSE, 0, NULL);
+			3, 2, GL_FLOAT, GL_FALSE, 0, NULL);
 	}
 
 	vao.attachElementArrayBufferVbo(*vbos[Mesh::VBO_VERT_INDECES]);

+ 23 - 11
src/Scene/PatchNode.h

@@ -1,7 +1,6 @@
 #ifndef PATCH_NODE_H
 #define PATCH_NODE_H
 
-#include <boost/scoped_ptr.hpp>
 #include "GfxApi/BufferObjects/Vao.h"
 #include "GfxApi/BufferObjects/Vbo.h"
 #include "Resources/Mesh.h" // For the Vbos enum
@@ -9,6 +8,8 @@
 #include "Resources/ModelPatch.h"
 #include "RenderableNode.h"
 #include "MaterialRuntime.h"
+#include <boost/scoped_ptr.hpp>
+#include <boost/array.hpp>
 
 
 class Material;
@@ -26,26 +27,37 @@ class PatchNode: public RenderableNode
 
 		/// @name Accessors
 		/// @{
+
+		/// Implements RenderableNode::getVao
+		const Vao& getVao(PassType p) const {return vaos[p];}
+
+		/// Implements RenderableNode::getVertIdsNum
+		uint getVertIdsNum() const {return rsrc.getMesh().getVertIdsNum();}
+
+		/// Implements RenderableNode::getMaterial
+		const Material& getMaterial() const {return rsrc.getMaterial();}
+
+		/// Implements RenderableNode::getMaterialRuntime
 		MaterialRuntime& getMaterialRuntime() {return *mtlRun;}
+
+		/// Implements RenderableNode::getMaterialRuntime
 		const MaterialRuntime& getMaterialRuntime() const {return *mtlRun;}
 
 		const ModelPatch& getModelPatchRsrc() const {return rsrc;}
-		const Vao& getCpVao() const {return cpVao;}
-		const Vao& getDpVao() const {return dpVao;}
-		uint getVertIdsNum() const {return rsrc.getMesh().getVertIdsNum();}
 		/// @}
 
 	protected:
+		/// The sub-resource
 		const ModelPatch& rsrc;
-		/// VAO for depth passes. All VBOs could be attached except for the
-		/// vert weights
-		Vao dpVao;
-		/// VAO for MS and BS. All VBOs could be attached except for the
-		/// vert weights
-		Vao cpVao;
-		boost::scoped_ptr<MaterialRuntime> mtlRun;
+
+		/// The VAOs. All VBOs could be attached except for the vertex weights
+		boost::array<Vao, PASS_TYPES_NUM> vaos;
+
+		boost::scoped_ptr<MaterialRuntime> mtlRun; ///< Material runtime
 
 		/// Create a VAO given a material and an array of VBOs
+		/// The location of the uniform variables are hard coded. See
+		/// MaterialVertex.glsl
 		static void createVao(const Material& material,
 			const boost::array<const Vbo*, Mesh::VBOS_NUM>& vbos, Vao& vao);
 };

+ 7 - 2
src/Scene/RenderableNode.h

@@ -2,6 +2,7 @@
 #define RENDERABLE_NODE_H
 
 #include "SceneNode.h"
+#include "Resources/MaterialCommon.h"
 
 
 class Vao;
@@ -16,15 +17,19 @@ class RenderableNode: public SceneNode
 	public:
 		RenderableNode(bool inheritParentTrfFlag, SceneNode* parent);
 
-		virtual const Vao& getCpVao() const = 0; ///< Get color pass VAO
-		virtual const Vao& getDpVao() const = 0; ///< Get depth pass VAO
+		/// Get VAO depending the rendering pass
+		virtual const Vao& getVao(PassType p) const;
 
 		/// Get vert ids number for rendering
 		virtual uint getVertIdsNum() const = 0;
 
+		/// Get the material resource
 		virtual const Material& getMaterial() const = 0;
 
+		/// Get the material runtime
 		virtual MaterialRuntime& getMaterialRuntime() = 0;
+
+		/// Const version of getMaterialRuntime
 		virtual const MaterialRuntime& getMaterialRuntime() const = 0;
 };
 

+ 8 - 2
src/Scene/Scene.cpp

@@ -3,6 +3,7 @@
 #include "Util/Exception.h"
 #include "Scene.h"
 #include "VisibilityTester.h"
+#include "SkinPatchNodeDeformer.h"
 
 #include "Camera.h"
 #include "Light.h"
@@ -14,19 +15,24 @@
 
 
 //==============================================================================
-// Constructor                                                                 =
+// Constructors & destructor                                                   =
 //==============================================================================
+
 Scene::Scene()
 {
 	ambientCol = Vec3(0.1, 0.05, 0.05) * 4;
 	//sunPos = Vec3(0.0, 1.0, -1.0) * 50.0;
 
 	physMasterContainer.reset(new Phys::MasterContainer);
-
 	visibilityTester.reset(new VisibilityTester(*this));
+	skinsDeformer.reset(new SkinPatchNodeDeformer);
 }
 
 
+Scene::~Scene()
+{}
+
+
 //==============================================================================
 // registerNode                                                                =
 //==============================================================================

+ 5 - 1
src/Scene/Scene.h

@@ -15,6 +15,7 @@ class Controller;
 class ParticleEmitterNode;
 class ModelNode;
 class SkinNode;
+class SkinPatchNodeDeformer;
 
 
 /// The Scene contains all the dynamic entities
@@ -37,7 +38,7 @@ class Scene
 		};
 
 		Scene();
-		~Scene() {}
+		~Scene();
 
 		/// Put a node in the appropriate containers
 		void registerNode(SceneNode* node);
@@ -55,6 +56,8 @@ class Scene
 		Phys::MasterContainer& getPhysMasterContainer();
 		const Phys::MasterContainer& getPhysMasterContainer() const;
 		const VisibilityTester& getVisibilityTester() const;
+		const SkinPatchNodeDeformer& getSkinPatchNodeDeformer() const
+			{return *skinsDeformer;}
 
 		GETTER_RW(Types<SceneNode>::Container, nodes, getAllNodes)
 		GETTER_RW(Types<Light>::Container, lights, getLights)
@@ -82,6 +85,7 @@ class Scene
 		/// Connection with Bullet wrapper
 		boost::scoped_ptr<Phys::MasterContainer> physMasterContainer;
 		boost::scoped_ptr<VisibilityTester> visibilityTester;
+		boost::scoped_ptr<SkinPatchNodeDeformer> skinsDeformer;
 
 		/// Adds a node in a container
 		template<typename ContainerType, typename Type>

+ 11 - 8
src/Scene/SkelAnimModelNodeCtrl.cpp

@@ -6,7 +6,8 @@
 #include "Resources/Model.h"
 #include "Resources/Skin.h"
 #include "Core/Globals.h"
-#include "Renderer/MainRenderer.h"
+#include "SkinPatchNodeDeformer.h"
+#include "Scene.h"
 
 
 //==============================================================================
@@ -33,7 +34,7 @@ void SkelAnimModelNodeCtrl::interpolate(const SkelAnim& animation, float frame,
 	const Vec<uint>& keyframes = animation.getKeyframes();
 	float t = 0.0;
 	uint lPose = 0, rPose = 0;
-	for(uint j=0; j<keyframes.size(); j++)
+	for(uint j = 0; j < keyframes.size(); j++)
 	{
 		if((float)keyframes[j] == frame)
 		{
@@ -185,18 +186,20 @@ void SkelAnimModelNodeCtrl::update(float)
 	updateBoneTransforms(skinNode.getSkin().getSkeleton(),
 		skinNode.getBoneTranslations(), skinNode.getBoneRotations());
 
-	if(R::MainRendererSingleton::getInstance().getDbg().isEnabled() &&
-		R::MainRendererSingleton::getInstance().getDbg().isShowSkeletonsEnabled())
+	/*if(R::MainRendererSingleton::getInstance().getDbg().isEnabled() &&
+		R::MainRendererSingleton::getInstance().getDbg().
+			isShowSkeletonsEnabled())
 	{
 		deform(skinNode.getSkin().getSkeleton(),
 			skinNode.getBoneTranslations(), skinNode.getBoneRotations(),
 			skinNode.getHeads(), skinNode.getTails());
-	}
+	}*/
 
-	R::SkinsDeformer& sd =
-		R::MainRendererSingleton::getInstance().getSkinsDeformer();
+	const SkinPatchNodeDeformer& sd =
+		SceneSingleton::getInstance().getSkinPatchNodeDeformer();
 
-	BOOST_FOREACH(SkinPatchNode* skinPatchNode, skinNode.getPatcheNodes())
+	BOOST_FOREACH(SkinPatchNode* skinPatchNode,
+		skinNode.getPatcheNodes())
 	{
 		sd.deform(*skinPatchNode);
 	}

+ 1 - 1
src/Scene/SkinNode.cpp

@@ -1,8 +1,8 @@
-#include <boost/foreach.hpp>
 #include "SkinNode.h"
 #include "Resources/Skin.h"
 #include "SkinPatchNode.h"
 #include "Resources/Skeleton.h"
+#include <boost/foreach.hpp>
 
 
 //==============================================================================

+ 11 - 10
src/Scene/SkinPatchNode.cpp

@@ -1,6 +1,5 @@
 #include "SkinPatchNode.h"
 #include "SkinNode.h"
-#include "Renderer/SkinsDeformer.h"
 
 
 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
@@ -38,7 +37,7 @@ SkinPatchNode::SkinPatchNode(const ModelPatch& modelPatch_, SkinNode* parent)
 		vboArr[Mesh::VBO_VERT_POSITIONS] = &tfVbos[TFV_POSITIONS];
 
 		tfVao.attachArrayBufferVbo(mesh.getVbo(Mesh::VBO_VERT_POSITIONS),
-			R::SkinsDeformer::TFSPA_POSITION,
+			POSITION_LOC,
 			3,
 			GL_FLOAT,
 			false,
@@ -57,7 +56,7 @@ SkinPatchNode::SkinPatchNode(const ModelPatch& modelPatch_, SkinNode* parent)
 		vboArr[Mesh::VBO_VERT_NORMALS] = &tfVbos[TFV_NORMALS];
 
 		tfVao.attachArrayBufferVbo(mesh.getVbo(Mesh::VBO_VERT_NORMALS),
-			R::SkinsDeformer::TFSPA_NORMAL,
+			NORMAL_LOC,
 			3,
 			GL_FLOAT,
 			false,
@@ -76,7 +75,7 @@ SkinPatchNode::SkinPatchNode(const ModelPatch& modelPatch_, SkinNode* parent)
 		vboArr[Mesh::VBO_VERT_TANGENTS] = &tfVbos[TFV_TANGENTS];
 
 		tfVao.attachArrayBufferVbo(mesh.getVbo(Mesh::VBO_VERT_TANGENTS),
-			R::SkinsDeformer::TFSPA_TANGENT,
+			TANGENT_LOC,
 			4,
 			GL_FLOAT,
 			false,
@@ -88,7 +87,7 @@ SkinPatchNode::SkinPatchNode(const ModelPatch& modelPatch_, SkinNode* parent)
 	ASSERT(mesh.getVbo(Mesh::VBO_VERT_WEIGHTS).isCreated());
 
 	tfVao.attachArrayBufferVbo(mesh.getVbo(Mesh::VBO_VERT_WEIGHTS),
-		R::SkinsDeformer::TFSPA_VERT_WEIGHT_BONES_NUM,
+		VERT_WEIGHT_BONES_NUM_LOC,
 		1,
 		GL_FLOAT,
 		GL_FALSE,
@@ -97,7 +96,7 @@ SkinPatchNode::SkinPatchNode(const ModelPatch& modelPatch_, SkinNode* parent)
 
 
 	tfVao.attachArrayBufferVbo(mesh.getVbo(Mesh::VBO_VERT_WEIGHTS),
-		R::SkinsDeformer::TFSPA_VERT_WEIGHT_BONE_IDS,
+		VERT_WEIGHT_BONE_IDS_LOC,
 		4,
 		GL_FLOAT,
 		GL_FALSE,
@@ -105,14 +104,16 @@ SkinPatchNode::SkinPatchNode(const ModelPatch& modelPatch_, SkinNode* parent)
 		BUFFER_OFFSET(4));
 
 	tfVao.attachArrayBufferVbo(mesh.getVbo(Mesh::VBO_VERT_WEIGHTS),
-		R::SkinsDeformer::TFSPA_VERT_WEIGHT_WEIGHTS,
+		VERT_WEIGHT_WEIGHTS_LOC,
 		4,
 		GL_FLOAT,
 		GL_FALSE,
 		sizeof(MeshData::VertexWeight),
 		BUFFER_OFFSET(20));
 
-	// Rendering VAOs
-	createVao(rsrc.getCpMtl(), vboArr, cpVao);
-	createVao(rsrc.getDpMtl(), vboArr, dpVao);
+	// Create the rendering VAOs
+	for(uint i = 0; i < PASS_TYPES_NUM; i++)
+	{
+		createVao(rsrc.getMaterial(), vboArr, vaos[i]);
+	}
 }

+ 13 - 2
src/Scene/SkinPatchNode.h

@@ -1,5 +1,5 @@
-#ifndef SKIN_PATCH_NODE_H
-#define SKIN_PATCH_NODE_H
+#ifndef SKIN_NODE_SKIN_PATCH_NODE_H
+#define SKIN_NODE_SKIN_PATCH_NODE_H
 
 #include <boost/array.hpp>
 #include "PatchNode.h"
@@ -22,6 +22,17 @@ class SkinPatchNode: public PatchNode
 			TFV_NUM
 		};
 
+		/// See TfHwSkinningGeneric.glsl for the locations
+		enum TfShaderProgAttribLoc
+		{
+			POSITION_LOC,
+			NORMAL_LOC,
+			TANGENT_LOC,
+			VERT_WEIGHT_BONES_NUM_LOC,
+			VERT_WEIGHT_BONE_IDS_LOC,
+			VERT_WEIGHT_WEIGHTS_LOC
+		};
+
 		SkinPatchNode(const ModelPatch& modelPatch, SkinNode* parent);
 
 		/// @name Accessors

+ 21 - 18
src/Renderer/SkinsDeformer.cpp → src/Scene/SkinPatchNodeDeformer.cpp

@@ -1,16 +1,28 @@
-#include "SkinsDeformer.h"
+#include "SkinPatchNodeDeformer.h"
 #include "Resources/ShaderProgram.h"
-#include "Scene/SkinPatchNode.h"
-#include "Scene/SkinNode.h"
+#include "Resources/Material.h"
+#include "SkinPatchNode.h"
+#include "SkinNode.h"
 
 
-namespace R {
+//==============================================================================
+// Constructors & destructor                                                   =
+//==============================================================================
+
+SkinPatchNodeDeformer::SkinPatchNodeDeformer()
+{
+	init();
+}
+
+
+SkinPatchNodeDeformer::~SkinPatchNodeDeformer()
+{}
 
 
 //==============================================================================
 // init                                                                        =
 //==============================================================================
-void SkinsDeformer::init()
+void SkinPatchNodeDeformer::init()
 {
 	//
 	// Load the shaders
@@ -23,7 +35,7 @@ void SkinsDeformer::init()
 //==============================================================================
 // deform                                                                      =
 //==============================================================================
-void SkinsDeformer::deform(SkinPatchNode& node)
+void SkinPatchNodeDeformer::deform(SkinPatchNode& node) const
 {
 	ASSERT(node.getParent() != NULL); // The SkinPatchNodes always have parent
 	ASSERT(static_cast<SceneNode*>(node.getParent())->getSceneNodeType() ==
@@ -35,9 +47,10 @@ void SkinsDeformer::deform(SkinPatchNode& node)
 
 	// Chose sProg
 	const ShaderProgram* sProg;
+	const Material& mtl = node.getModelPatchRsrc().getMaterial();
 
-	if(node.getModelPatchRsrc().supportsNormals() &&
-	   node.getModelPatchRsrc().supportsTangents())
+	if(mtl.buildinVariableExits(MaterialBuildinVariable::NORMAL) &&
+	   mtl.buildinVariableExits(MaterialBuildinVariable::TANGENT))
 	{
 		sProg = tfHwSkinningAllSProg.get();
 	}
@@ -79,13 +92,3 @@ void SkinsDeformer::deform(SkinPatchNode& node)
 
 	GlStateMachineSingleton::getInstance().disable(GL_RASTERIZER_DISCARD);
 }
-
-
-} // end namespace
-
-
-
-
-
-
-

+ 28 - 0
src/Scene/SkinPatchNodeDeformer.h

@@ -0,0 +1,28 @@
+#ifndef SKIN_PATCH_NODE_DEFORMER_H
+#define SKIN_PATCH_NODE_DEFORMER_H
+
+#include "Resources/RsrcPtr.h"
+
+
+class ShaderProgram;
+class SkinPatchNode;
+
+
+/// XXX
+class SkinPatchNodeDeformer
+{
+	public:
+		SkinPatchNodeDeformer();
+		~SkinPatchNodeDeformer();
+
+		void deform(SkinPatchNode& node) const;
+
+	private:
+		RsrcPtr<ShaderProgram> tfHwSkinningAllSProg;
+		RsrcPtr<ShaderProgram> tfHwSkinningPosSProg;
+
+		void init();
+};
+
+
+#endif

+ 13 - 11
src/Scene/VisibilityTester.cpp

@@ -8,7 +8,7 @@
 #include "Collision/Sphere.h"
 #include "PointLight.h"
 #include "SpotLight.h"
-#include "Core/ParallelJobs/Manager.h"
+#include "Core/parallel/Manager.h"
 #include "Core/Logger.h"
 
 
@@ -140,12 +140,12 @@ void VisibilityTester::getRenderableNodes(bool skipShadowless,
 	jobParameters.bsRenderableNodesMtx = &bsRenderableNodesMtx;
 
 	for(uint i = 0;
-		i < ParallelJobs::ManagerSingleton::getInstance().getThreadsNum(); i++)
+		i < parallel::ManagerSingleton::getInstance().getThreadsNum(); i++)
 	{
-		ParallelJobs::ManagerSingleton::getInstance().assignNewJob(i,
+		parallel::ManagerSingleton::getInstance().assignNewJob(i,
 			getRenderableNodesJobCallback, jobParameters);
 	}
-	ParallelJobs::ManagerSingleton::getInstance().waitForAllJobsToFinish();
+	parallel::ManagerSingleton::getInstance().waitForAllJobsToFinish();
 
 	//
 	// Sort the renderables from closest to the camera to the farthest
@@ -163,8 +163,8 @@ void VisibilityTester::getRenderableNodes(bool skipShadowless,
 // getRenderableNodesJobCallback                                               =
 //==============================================================================
 void VisibilityTester::getRenderableNodesJobCallback(
-	ParallelJobs::JobParameters& data,
-	const ParallelJobs::Job& job)
+	parallel::JobParameters& data,
+	const parallel::Job& job)
 {
 	VisJobParameters& jobParameters = static_cast<VisJobParameters&>(data);
 
@@ -227,7 +227,7 @@ void VisibilityTester::getRenderableNodesJobCallback(
 
 			// Skip shadowless
 			if(skipShadowless &&
-				!modelPatchNode->getCpMtl().castsShadow())
+				!modelPatchNode->getMaterialRuntime().castsShadow())
 			{
 				continue;
 			}
@@ -235,7 +235,8 @@ void VisibilityTester::getRenderableNodesJobCallback(
 			// Test if visible by main camera
 			if(test(*modelPatchNode, cam))
 			{
-				if(modelPatchNode->getCpMtl().renderInBlendingStage())
+				if(modelPatchNode->getMaterialRuntime().
+					rendersInBlendingStage())
 				{
 					bsVisibles[bsI++] = modelPatchNode;
 				}
@@ -280,7 +281,8 @@ void VisibilityTester::getRenderableNodesJobCallback(
 		node->enableFlag(SceneNode::SNF_VISIBLE);
 
 		// Put all the patches into the visible container
-		BOOST_FOREACH(SkinPatchNode* patchNode, node->getPatcheNodes())
+		BOOST_FOREACH(SkinPatchNode* patchNode,
+			node->getPatcheNodes())
 		{
 			if(!patchNode->isFlagEnabled(SceneNode::SNF_ACTIVE))
 			{
@@ -289,12 +291,12 @@ void VisibilityTester::getRenderableNodesJobCallback(
 
 			// Skip shadowless
 			if(skipShadowless &&
-				!patchNode->getCpMtl().castsShadow())
+				!patchNode->getMaterialRuntime().castsShadow())
 			{
 				continue;
 			}
 
-			if(patchNode->getCpMtl().renderInBlendingStage())
+			if(patchNode->getMaterialRuntime().rendersInBlendingStage())
 			{
 				bsVisibles[bsI++] = patchNode;
 			}

+ 6 - 6
src/Scene/VisibilityTester.h

@@ -3,7 +3,7 @@
 
 #include "Util/Accessors.h"
 #include "Math/Math.h"
-#include "Core/ParallelJobs/Job.h"
+#include "Core/parallel/Job.h"
 #include <deque>
 #include <boost/thread.hpp>
 
@@ -42,8 +42,8 @@ class VisibilityTester
 			bool operator()(const SceneNode* a, const SceneNode* b) const;
 		};
 
-		/// The JobParameters that we feed in the ParallelJobs::Manager
-		struct VisJobParameters: ParallelJobs::JobParameters
+		/// The JobParameters that we feed in the parallel::Manager
+		struct VisJobParameters: parallel::JobParameters
 		{
 			const Camera* cam;
 			bool skipShadowless;
@@ -76,11 +76,11 @@ class VisibilityTester
 		void getRenderableNodes(bool skipShadowless, const Camera& cam,
 			VisibilityInfo& storage);
 
-		/// This static method will be fed into the ParallelJobs::Manager
+		/// This static method will be fed into the parallel::Manager
 		/// @param data This is actually a pointer to VisibilityTester
 		static void getRenderableNodesJobCallback(
-			ParallelJobs::JobParameters& data,
-			const ParallelJobs::Job& job);
+			parallel::JobParameters& data,
+			const parallel::Job& job);
 };