Browse Source

Fixing Drawers and all that follows that

Panagiotis Christopoulos Charitos 13 years ago
parent
commit
eb34f32f77

+ 0 - 1
anki/gl/Fbo.h

@@ -2,7 +2,6 @@
 #define ANKI_GL_FBO_H
 #define ANKI_GL_FBO_H
 
 
 #include "anki/util/Assert.h"
 #include "anki/util/Assert.h"
-#include "anki/util/StdTypes.h"
 #include "anki/util/Exception.h"
 #include "anki/util/Exception.h"
 #include <GL/glew.h>
 #include <GL/glew.h>
 #include <array>
 #include <array>

+ 16 - 3
anki/gl/ShaderProgram.cpp

@@ -109,8 +109,8 @@ void ShaderProgramUniformVariable::set(const Texture& tex)
 	ANKI_ASSERT(getGlDataType() == GL_SAMPLER_2D 
 	ANKI_ASSERT(getGlDataType() == GL_SAMPLER_2D 
 		|| getGlDataType() == GL_SAMPLER_2D_SHADOW);
 		|| getGlDataType() == GL_SAMPLER_2D_SHADOW);
 	
 	
-	tex.bind();
-	glUniform1i(getLocation(), tex.getUnit());
+	uint32_t unit = tex.bind();
+	glUniform1i(getLocation(), unit);
 }
 }
 
 
 //==============================================================================
 //==============================================================================
@@ -124,7 +124,8 @@ const char* ShaderProgram::stdSourceCode =
 	//"precision lowp float;\n"
 	//"precision lowp float;\n"
 #if defined(NDEBUG)
 #if defined(NDEBUG)
 	"#pragma optimize(on)\n"
 	"#pragma optimize(on)\n"
-	"#pragma debug(off)\n";
+	"#pragma debug(off)\n"
+	"#define NDEBUG\n";
 #else
 #else
 	"#pragma optimize(of)\n"
 	"#pragma optimize(of)\n"
 	"#pragma debug(on)\n";
 	"#pragma debug(on)\n";
@@ -417,6 +418,18 @@ const ShaderProgramUniformVariable* ShaderProgram::findUniformVariableByName(
 	return it->second;
 	return it->second;
 }
 }
 
 
+//==============================================================================
+ShaderProgramUniformVariable* ShaderProgram::findUniformVariableByName(
+	const char* name)
+{
+	NameToUniVarHashMap::iterator it = nameToUniVar.find(name);
+	if(it == nameToUniVar.end())
+	{
+		return nullptr;
+	}
+	return it->second;
+}
+
 //==============================================================================
 //==============================================================================
 void ShaderProgram::cleanAllUniformsDirtyFlags()
 void ShaderProgram::cleanAllUniformsDirtyFlags()
 {
 {

+ 3 - 0
anki/gl/ShaderProgram.h

@@ -282,6 +282,9 @@ public:
 	const ShaderProgramVariable* findVariableByName(const char* varName) const;
 	const ShaderProgramVariable* findVariableByName(const char* varName) const;
 	const ShaderProgramUniformVariable* findUniformVariableByName(
 	const ShaderProgramUniformVariable* findUniformVariableByName(
 		const char* varName) const;
 		const char* varName) const;
+	/// Non-const version because of the class setters
+	ShaderProgramUniformVariable* findUniformVariableByName(
+		const char* varName);
 	const ShaderProgramAttributeVariable* findAttributeVariableByName(
 	const ShaderProgramAttributeVariable* findAttributeVariableByName(
 		const char* varName) const;
 		const char* varName) const;
 	/// @}
 	/// @}

+ 5 - 3
anki/gl/Texture.cpp

@@ -107,7 +107,7 @@ uint32_t TextureUnits::choseUnit(const Texture& tex, bool& allreadyBinded)
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-void TextureUnits::bindTexture(const Texture& tex)
+uint32_t TextureUnits::bindTexture(const Texture& tex)
 {
 {
 	bool allreadyBinded;
 	bool allreadyBinded;
 	uint32_t unit = choseUnit(tex, allreadyBinded);
 	uint32_t unit = choseUnit(tex, allreadyBinded);
@@ -117,6 +117,8 @@ void TextureUnits::bindTexture(const Texture& tex)
 		activateUnit(unit);
 		activateUnit(unit);
 		glBindTexture(tex.getTarget(), tex.getGlId());
 		glBindTexture(tex.getTarget(), tex.getGlId());
 	}
 	}
+
+	return unit;
 }
 }
 
 
 //==============================================================================
 //==============================================================================
@@ -238,9 +240,9 @@ void Texture::create(const Initializer& init)
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-void Texture::bind() const
+uint32_t Texture::bind() const
 {
 {
-	TextureUnitsSingleton::get().bindTexture(*this);
+	return TextureUnitsSingleton::get().bindTexture(*this);
 }
 }
 
 
 //==============================================================================
 //==============================================================================

+ 5 - 3
anki/gl/Texture.h

@@ -84,9 +84,10 @@ public:
 	void activateUnit(uint32_t unit);
 	void activateUnit(uint32_t unit);
 
 
 	/// Bind the texture to a unit. It's not sure that it will activate the unit
 	/// Bind the texture to a unit. It's not sure that it will activate the unit
-	void bindTexture(const Texture& tex);
+	/// @return The texture unit index
+	uint32_t bindTexture(const Texture& tex);
 
 
-	/// XXX
+	/// Like bindTexture but ensure that the unit is active
 	void bindTextureAndActivateUnit(const Texture& tex);
 	void bindTextureAndActivateUnit(const Texture& tex);
 
 
 	/// Unbind a texture from it's unit
 	/// Unbind a texture from it's unit
@@ -227,7 +228,8 @@ public:
 	void create(const Initializer& init);
 	void create(const Initializer& init);
 
 
 	/// Bind the texture to a unit that the texture unit system will decide
 	/// Bind the texture to a unit that the texture unit system will decide
-	void bind() const;
+	/// @return The texture init
+	uint32_t bind() const;
 
 
 	/// Change the filtering type
 	/// Change the filtering type
 	void setFiltering(TextureFilteringType filterType)
 	void setFiltering(TextureFilteringType filterType)

+ 10 - 38
anki/renderer/Drawer.cpp

@@ -1,5 +1,5 @@
 #include "anki/renderer/Drawer.h"
 #include "anki/renderer/Drawer.h"
-#include "anki/resource/ShaderProgram.h"
+#include "anki/resource/ShaderProgramResource.h"
 #include "anki/physics/Convertors.h"
 #include "anki/physics/Convertors.h"
 #include "anki/collision/Collision.h"
 #include "anki/collision/Collision.h"
 #include "anki/scene/Frustumable.h"
 #include "anki/scene/Frustumable.h"
@@ -9,10 +9,8 @@
 #include "anki/scene/Camera.h"
 #include "anki/scene/Camera.h"
 #include "anki/scene/ModelNode.h"
 #include "anki/scene/ModelNode.h"
 
 
-
 namespace anki {
 namespace anki {
 
 
-
 //==============================================================================
 //==============================================================================
 // DebugDrawer                                                                 =
 // DebugDrawer                                                                 =
 //==============================================================================
 //==============================================================================
@@ -38,7 +36,6 @@ DebugDrawer::DebugDrawer()
 	crntCol = Vec3(1.0, 0.0, 0.0);
 	crntCol = Vec3(1.0, 0.0, 0.0);
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void DebugDrawer::drawLine(const Vec3& from, const Vec3& to, const Vec4& color)
 void DebugDrawer::drawLine(const Vec3& from, const Vec3& to, const Vec4& color)
 {
 {
@@ -49,7 +46,6 @@ void DebugDrawer::drawLine(const Vec3& from, const Vec3& to, const Vec4& color)
 	end();
 	end();
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void DebugDrawer::drawGrid()
 void DebugDrawer::drawGrid()
 {
 {
@@ -95,7 +91,6 @@ void DebugDrawer::drawGrid()
 	end();
 	end();
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void DebugDrawer::drawSphere(float radius, int complexity)
 void DebugDrawer::drawSphere(float radius, int complexity)
 {
 {
@@ -160,7 +155,6 @@ void DebugDrawer::drawSphere(float radius, int complexity)
 	end();
 	end();
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void DebugDrawer::drawCube(float size)
 void DebugDrawer::drawCube(float size)
 {
 {
@@ -189,7 +183,6 @@ void DebugDrawer::drawCube(float size)
 	end();
 	end();
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void DebugDrawer::setModelMat(const Mat4& modelMat_)
 void DebugDrawer::setModelMat(const Mat4& modelMat_)
 {
 {
@@ -198,14 +191,12 @@ void DebugDrawer::setModelMat(const Mat4& modelMat_)
 	modelMat = modelMat_;
 	modelMat = modelMat_;
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void DebugDrawer::begin()
 void DebugDrawer::begin()
 {
 {
 	ANKI_ASSERT(pointIndex == 0);
 	ANKI_ASSERT(pointIndex == 0);
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void DebugDrawer::end()
 void DebugDrawer::end()
 {
 {
@@ -215,7 +206,7 @@ void DebugDrawer::end()
 	colorsVbo.write(&colors[0], 0, sizeof(Vec3) * pointIndex);
 	colorsVbo.write(&colors[0], 0, sizeof(Vec3) * pointIndex);
 
 
 	Mat4 pmv = vpMat * modelMat;
 	Mat4 pmv = vpMat * modelMat;
-	sProg->findUniformVariableByName("modelViewProjectionMat").set(pmv);
+	sProg->findUniformVariableByName("modelViewProjectionMat")->set(pmv);
 
 
 	vao.bind();
 	vao.bind();
 	glDrawArrays(GL_LINES, 0, pointIndex);
 	glDrawArrays(GL_LINES, 0, pointIndex);
@@ -225,7 +216,6 @@ void DebugDrawer::end()
 	pointIndex = 0;
 	pointIndex = 0;
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void DebugDrawer::pushBackVertex(const Vec3& pos)
 void DebugDrawer::pushBackVertex(const Vec3& pos)
 {
 {
@@ -234,7 +224,6 @@ void DebugDrawer::pushBackVertex(const Vec3& pos)
 	++pointIndex;
 	++pointIndex;
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 // CollisionDebugDrawer                                                        =
 // CollisionDebugDrawer                                                        =
 //==============================================================================
 //==============================================================================
@@ -246,7 +235,6 @@ void CollisionDebugDrawer::visit(const Sphere& sphere)
 	dbg->drawSphere(sphere.getRadius());
 	dbg->drawSphere(sphere.getRadius());
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void CollisionDebugDrawer::visit(const Obb& obb)
 void CollisionDebugDrawer::visit(const Obb& obb)
 {
 {
@@ -268,7 +256,6 @@ void CollisionDebugDrawer::visit(const Obb& obb)
 	dbg->drawCube(2.0);
 	dbg->drawCube(2.0);
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void CollisionDebugDrawer::visit(const Plane& plane)
 void CollisionDebugDrawer::visit(const Plane& plane)
 {
 {
@@ -284,7 +271,6 @@ void CollisionDebugDrawer::visit(const Plane& plane)
 	dbg->drawGrid();
 	dbg->drawGrid();
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void CollisionDebugDrawer::visit(const Aabb& aabb)
 void CollisionDebugDrawer::visit(const Aabb& aabb)
 {
 {
@@ -305,7 +291,6 @@ void CollisionDebugDrawer::visit(const Aabb& aabb)
 	dbg->drawCube();
 	dbg->drawCube();
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void CollisionDebugDrawer::visit(const Frustum& f)
 void CollisionDebugDrawer::visit(const Frustum& f)
 {
 {
@@ -346,7 +331,6 @@ void CollisionDebugDrawer::visit(const Frustum& f)
 	}
 	}
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 // PhysicsDebugDrawer                                                          =
 // PhysicsDebugDrawer                                                          =
 //==============================================================================
 //==============================================================================
@@ -358,7 +342,6 @@ void PhysicsDebugDrawer::drawLine(const btVector3& from, const btVector3& to,
 	dbg->drawLine(toAnki(from), toAnki(to), Vec4(toAnki(color), 1.0));
 	dbg->drawLine(toAnki(from), toAnki(to), Vec4(toAnki(color), 1.0));
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void PhysicsDebugDrawer::drawSphere(btScalar radius,
 void PhysicsDebugDrawer::drawSphere(btScalar radius,
 	const btTransform& transform,
 	const btTransform& transform,
@@ -369,7 +352,6 @@ void PhysicsDebugDrawer::drawSphere(btScalar radius,
 	dbg->drawSphere(radius);
 	dbg->drawSphere(radius);
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void PhysicsDebugDrawer::drawBox(const btVector3& min, const btVector3& max,
 void PhysicsDebugDrawer::drawBox(const btVector3& min, const btVector3& max,
 	const btVector3& color)
 	const btVector3& color)
@@ -386,7 +368,6 @@ void PhysicsDebugDrawer::drawBox(const btVector3& min, const btVector3& max,
 	dbg->drawCube(1.0);
 	dbg->drawCube(1.0);
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void PhysicsDebugDrawer::drawBox(const btVector3& min, const btVector3& max,
 void PhysicsDebugDrawer::drawBox(const btVector3& min, const btVector3& max,
 	const btTransform& trans, const btVector3& color)
 	const btTransform& trans, const btVector3& color)
@@ -404,7 +385,6 @@ void PhysicsDebugDrawer::drawBox(const btVector3& min, const btVector3& max,
 	dbg->drawCube(1.0);
 	dbg->drawCube(1.0);
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void PhysicsDebugDrawer::drawContactPoint(const btVector3& /*pointOnB*/,
 void PhysicsDebugDrawer::drawContactPoint(const btVector3& /*pointOnB*/,
 	const btVector3& /*normalOnB*/,
 	const btVector3& /*normalOnB*/,
@@ -413,14 +393,12 @@ void PhysicsDebugDrawer::drawContactPoint(const btVector3& /*pointOnB*/,
 	//ANKI_WARNING("Unimplemented");
 	//ANKI_WARNING("Unimplemented");
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void PhysicsDebugDrawer::reportErrorWarning(const char* warningString)
 void PhysicsDebugDrawer::reportErrorWarning(const char* warningString)
 {
 {
 	throw ANKI_EXCEPTION(warningString);
 	throw ANKI_EXCEPTION(warningString);
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void PhysicsDebugDrawer::draw3dText(const btVector3& /*location*/,
 void PhysicsDebugDrawer::draw3dText(const btVector3& /*location*/,
 	const char* /*textString*/)
 	const char* /*textString*/)
@@ -428,7 +406,6 @@ void PhysicsDebugDrawer::draw3dText(const btVector3& /*location*/,
 	//ANKI_WARNING("Unimplemented");
 	//ANKI_WARNING("Unimplemented");
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 // SceneDebugDrawer                                                            =
 // SceneDebugDrawer                                                            =
 //==============================================================================
 //==============================================================================
@@ -496,7 +473,6 @@ void SceneDebugDrawer::draw(const OctreeNode& octnode, uint depth,
 	}
 	}
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 // RenderableDrawer                                                            =
 // RenderableDrawer                                                            =
 //==============================================================================
 //==============================================================================
@@ -504,8 +480,7 @@ void SceneDebugDrawer::draw(const OctreeNode& octnode, uint depth,
 /// Set the uniform using this visitor
 /// Set the uniform using this visitor
 struct SetUniformVisitor: public boost::static_visitor<void>
 struct SetUniformVisitor: public boost::static_visitor<void>
 {
 {
-	const ShaderProgramUniformVariable* uni;
-	uint* texUnit;
+	ShaderProgramUniformVariable* uni;
 
 
 	template<typename Type>
 	template<typename Type>
 	void operator()(const Type& x) const
 	void operator()(const Type& x) const
@@ -513,14 +488,8 @@ struct SetUniformVisitor: public boost::static_visitor<void>
 		uni->set(x);
 		uni->set(x);
 	}
 	}
 
 
-	void operator()(const TextureResourcePointer& x) const
-	{
-		uni->set(*x, (*texUnit)++);
-	}
-
 };
 };
 
 
-
 //==============================================================================
 //==============================================================================
 void RenderableDrawer::setupShaderProg(
 void RenderableDrawer::setupShaderProg(
 	const PassLevelKey& key,
 	const PassLevelKey& key,
@@ -529,21 +498,24 @@ void RenderableDrawer::setupShaderProg(
 {
 {
 	const Material& mtl = renderable.getMaterial();
 	const Material& mtl = renderable.getMaterial();
 	const ShaderProgram& sprog = mtl.getShaderProgram(key);
 	const ShaderProgram& sprog = mtl.getShaderProgram(key);
-	uint texunit = 0;
+#if !defined(NDEBUG)
+	int texturesCount = 0; // count the textures
+#endif
 
 
 	sprog.bind();
 	sprog.bind();
 	
 	
 	SetUniformVisitor vis;
 	SetUniformVisitor vis;
-	vis.texUnit = &texunit;
 
 
-	for(const MaterialVariable& mv : mtl.getVariables())
+	for(auto it = mtl.getVariablesBegin(); it != mtl.getVariablesEnd(); ++it)
 	{
 	{
+		MaterialVariable& mv = *it;
+
 		if(!mv.inPass(key))
 		if(!mv.inPass(key))
 		{
 		{
 			continue;
 			continue;
 		}
 		}
 
 
-		const ShaderProgramUniformVariable& uni = 
+		ShaderProgramUniformVariable& uni = 
 			mv.getShaderProgramUniformVariable(key);
 			mv.getShaderProgramUniformVariable(key);
 
 
 		vis.uni = &uni;
 		vis.uni = &uni;

+ 4 - 13
anki/renderer/Drawer.h

@@ -11,16 +11,8 @@
 #include <map>
 #include <map>
 #include <LinearMath/btIDebugDraw.h>
 #include <LinearMath/btIDebugDraw.h>
 
 
-
 namespace anki {
 namespace anki {
 
 
-
-class Octree;
-class OctreeNode;
-class Renderer;
-class Camera;
-
-
 /// Draws simple primitives
 /// Draws simple primitives
 class DebugDrawer
 class DebugDrawer
 {
 {
@@ -108,7 +100,6 @@ private:
 	DebugDrawer* dbg; ///< The debug drawer
 	DebugDrawer* dbg; ///< The debug drawer
 };
 };
 
 
-
 /// An implementation of btIDebugDraw used for debugging Bullet. See Bullet
 /// An implementation of btIDebugDraw used for debugging Bullet. See Bullet
 /// docs for details
 /// docs for details
 class PhysicsDebugDrawer: public btIDebugDraw
 class PhysicsDebugDrawer: public btIDebugDraw
@@ -150,6 +141,10 @@ private:
 	DebugDrawer* dbg;
 	DebugDrawer* dbg;
 };
 };
 
 
+class Octree;
+class OctreeNode;
+class Renderer;
+class Camera;
 
 
 /// This is a drawer for some scene nodes that need debug
 /// This is a drawer for some scene nodes that need debug
 class SceneDebugDrawer
 class SceneDebugDrawer
@@ -206,10 +201,8 @@ private:
 		uint depth, const Octree& octree) const;
 		uint depth, const Octree& octree) const;
 };
 };
 
 
-
 class PassLevelKey;
 class PassLevelKey;
 
 
-
 /// It includes all the functions to render a Renderable
 /// It includes all the functions to render a Renderable
 class RenderableDrawer
 class RenderableDrawer
 {
 {
@@ -231,8 +224,6 @@ private:
 		Renderable& renderable);
 		Renderable& renderable);
 };
 };
 
 
-
 } // namespace anki
 } // namespace anki
 
 
-
 #endif
 #endif

+ 2 - 2
anki/renderer/Renderer.h

@@ -15,7 +15,7 @@
 #include "anki/renderer/Dbg.h"
 #include "anki/renderer/Dbg.h"
 #include "anki/gl/GlException.h"
 #include "anki/gl/GlException.h"
 #include "anki/gl/GlStateMachine.h"
 #include "anki/gl/GlStateMachine.h"
-#include "anki/gl/TimeQuery.h"
+#include "anki/gl/Query.h"
 #include "anki/renderer/Drawer.h"
 #include "anki/renderer/Drawer.h"
 #include <boost/scoped_ptr.hpp>
 #include <boost/scoped_ptr.hpp>
 
 
@@ -231,7 +231,7 @@ protected:
 	/// @name Profiling stuff
 	/// @name Profiling stuff
 	/// @{
 	/// @{
 	double msTime, isTime, ppsTime, bsTime;
 	double msTime, isTime, ppsTime, bsTime;
-	boost::scoped_ptr<TimeQuery> msTq, isTq, ppsTq, bsTq;
+	boost::scoped_ptr<Query> msTq, isTq, ppsTq, bsTq;
 	bool enableStagesProfilingFlag;
 	bool enableStagesProfilingFlag;
 	/// @}
 	/// @}
 
 

+ 3 - 0
anki/resource/AsyncOperator.h

@@ -27,6 +27,9 @@ public:
 	public:
 	public:
 		bool ok;
 		bool ok;
 
 
+		virtual ~Request()
+		{}
+
 		/// Called in the worker thread
 		/// Called in the worker thread
 		virtual void exec() = 0;
 		virtual void exec() = 0;
 
 

+ 4 - 29
anki/resource/Material.cpp

@@ -14,10 +14,8 @@
 #include <boost/lexical_cast.hpp>
 #include <boost/lexical_cast.hpp>
 #include <algorithm>
 #include <algorithm>
 
 
-
 namespace anki {
 namespace anki {
 
 
-
 //==============================================================================
 //==============================================================================
 // MaterialVariable                                                            =
 // MaterialVariable                                                            =
 //==============================================================================
 //==============================================================================
@@ -33,29 +31,27 @@ GLenum MaterialVariable::getGlDataType() const
 	return oneSProgVar->getGlDataType();
 	return oneSProgVar->getGlDataType();
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 const std::string& MaterialVariable::getName() const
 const std::string& MaterialVariable::getName() const
 {
 {
 	return oneSProgVar->getName();
 	return oneSProgVar->getName();
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void MaterialVariable::init(const char* shaderProgVarName,
 void MaterialVariable::init(const char* shaderProgVarName,
 	const PassLevelToShaderProgramHashMap& sProgs)
 	const PassLevelToShaderProgramHashMap& sProgs)
 {
 {
-	oneSProgVar = NULL;
+	oneSProgVar = nullptr;
 
 
 	// For all programs
 	// For all programs
 	PassLevelToShaderProgramHashMap::const_iterator it = sProgs.begin();
 	PassLevelToShaderProgramHashMap::const_iterator it = sProgs.begin();
 	for(; it != sProgs.end(); ++it)
 	for(; it != sProgs.end(); ++it)
 	{
 	{
-		const ShaderProgram& sProg = *(it->second);
+		ShaderProgram& sProg = *(it->second);
 		const PassLevelKey& key = it->first;
 		const PassLevelKey& key = it->first;
 
 
 		// Variable exists
 		// Variable exists
-		const ShaderProgramUniformVariable* uni = 
+		ShaderProgramUniformVariable* uni = 
 			sProg.findUniformVariableByName(shaderProgVarName);
 			sProg.findUniformVariableByName(shaderProgVarName);
 		if(uni)
 		if(uni)
 		{
 		{
@@ -87,7 +83,6 @@ void MaterialVariable::init(const char* shaderProgVarName,
 	}
 	}
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 // Material                                                                    =
 // Material                                                                    =
 //==============================================================================
 //==============================================================================
@@ -112,17 +107,14 @@ ConstCharPtrHashMap<GLenum>::Type Material::txtToBlengGlEnum =
 	TXT_AND_ENUM(GL_SRC_COLOR)
 	TXT_AND_ENUM(GL_SRC_COLOR)
 	TXT_AND_ENUM(GL_ONE_MINUS_SRC_COLOR);
 	TXT_AND_ENUM(GL_ONE_MINUS_SRC_COLOR);
 
 
-
 //==============================================================================
 //==============================================================================
 Material::Material()
 Material::Material()
 {}
 {}
 
 
-
 //==============================================================================
 //==============================================================================
 Material::~Material()
 Material::~Material()
 {}
 {}
 
 
-
 //==============================================================================
 //==============================================================================
 void Material::load(const char* filename)
 void Material::load(const char* filename)
 {
 {
@@ -140,18 +132,15 @@ void Material::load(const char* filename)
 	}
 	}
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 {
 {
 	using namespace boost::property_tree;
 	using namespace boost::property_tree;
 
 
-	//
 	// renderingStage
 	// renderingStage
 	//
 	//
 	renderingStage = pt.get<int>("renderingStage");
 	renderingStage = pt.get<int>("renderingStage");
 
 
-	//
 	// passes
 	// passes
 	//
 	//
 	boost::optional<std::string> pass =
 	boost::optional<std::string> pass =
@@ -166,7 +155,6 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 		passes.push_back("DUMMY");
 		passes.push_back("DUMMY");
 	}
 	}
 
 
-	//
 	// levelsOfDetail
 	// levelsOfDetail
 	//
 	//
 	boost::optional<int> lod = pt.get_optional<int>("levelsOfDetail");
 	boost::optional<int> lod = pt.get_optional<int>("levelsOfDetail");
@@ -180,7 +168,6 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 		levelsOfDetail = 1;
 		levelsOfDetail = 1;
 	}
 	}
 
 
-	//
 	// shadow
 	// shadow
 	//
 	//
 	boost::optional<int> sw = pt.get_optional<int>("shadow");
 	boost::optional<int> sw = pt.get_optional<int>("shadow");
@@ -190,7 +177,6 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 		shadow = sw.get();
 		shadow = sw.get();
 	}
 	}
 
 
-	//
 	// blendFunctions
 	// blendFunctions
 	//
 	//
 	boost::optional<const ptree&> blendFuncsTree =
 	boost::optional<const ptree&> blendFuncsTree =
@@ -230,7 +216,6 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 		}
 		}
 	}
 	}
 
 
-	//
 	// depthTesting
 	// depthTesting
 	//
 	//
 	boost::optional<int> dp = pt.get_optional<int>("depthTesting");
 	boost::optional<int> dp = pt.get_optional<int>("depthTesting");
@@ -240,7 +225,6 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 		depthTesting = dp.get();
 		depthTesting = dp.get();
 	}
 	}
 
 
-	//
 	// wireframe
 	// wireframe
 	//
 	//
 	boost::optional<int> wf = pt.get_optional<int>("wireframe");
 	boost::optional<int> wf = pt.get_optional<int>("wireframe");
@@ -250,7 +234,6 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 		wireframe = wf.get();
 		wireframe = wf.get();
 	}
 	}
 
 
-	//
 	// shaderProgram
 	// shaderProgram
 	//
 	//
 	MaterialShaderProgramCreator mspc(pt.get_child("shaderProgram"));
 	MaterialShaderProgramCreator mspc(pt.get_child("shaderProgram"));
@@ -284,7 +267,6 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 	populateVariables(pt.get_child("shaderProgram"));
 	populateVariables(pt.get_child("shaderProgram"));
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 std::string Material::createShaderProgSourceToCache(const std::string& source)
 std::string Material::createShaderProgSourceToCache(const std::string& source)
 {
 {
@@ -316,13 +298,11 @@ std::string Material::createShaderProgSourceToCache(const std::string& source)
 	return newfPathName.string();
 	return newfPathName.string();
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void Material::populateVariables(const boost::property_tree::ptree& pt)
 void Material::populateVariables(const boost::property_tree::ptree& pt)
 {
 {
 	using namespace boost::property_tree;
 	using namespace boost::property_tree;
 
 
-	//
 	// Get all names of all the uniforms. Dont duplicate
 	// Get all names of all the uniforms. Dont duplicate
 	//
 	//
 	std::map<std::string, GLenum> allVarNames;
 	std::map<std::string, GLenum> allVarNames;
@@ -336,7 +316,6 @@ void Material::populateVariables(const boost::property_tree::ptree& pt)
 		}
 		}
 	}
 	}
 
 
-	//
 	// Iterate all the <input> and get the value
 	// Iterate all the <input> and get the value
 	//
 	//
 	std::map<std::string, std::string> nameToValue;
 	std::map<std::string, std::string> nameToValue;
@@ -382,7 +361,6 @@ void Material::populateVariables(const boost::property_tree::ptree& pt)
 		}
 		}
 	}
 	}
 
 
-	//
 	// Now combine
 	// Now combine
 	//
 	//
 	std::map<std::string, GLenum>::const_iterator it = allVarNames.begin();
 	std::map<std::string, GLenum>::const_iterator it = allVarNames.begin();
@@ -394,7 +372,7 @@ void Material::populateVariables(const boost::property_tree::ptree& pt)
 		std::map<std::string, std::string>::const_iterator it1 =
 		std::map<std::string, std::string>::const_iterator it1 =
 			nameToValue.find(name);
 			nameToValue.find(name);
 
 
-		MaterialVariable* v = NULL;
+		MaterialVariable* v = nullptr;
 
 
 		// Not found
 		// Not found
 		if(it1 == nameToValue.end())
 		if(it1 == nameToValue.end())
@@ -487,7 +465,6 @@ void Material::populateVariables(const boost::property_tree::ptree& pt)
 	}
 	}
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 template<typename Type, size_t n>
 template<typename Type, size_t n>
 Type Material::setMathType(const char* str)
 Type Material::setMathType(const char* str)
@@ -504,7 +481,6 @@ Type Material::setMathType(const char* str)
 	return out;
 	return out;
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 const MaterialVariable& Material::findVariableByName(const char* name) const
 const MaterialVariable& Material::findVariableByName(const char* name) const
 {
 {
@@ -517,5 +493,4 @@ const MaterialVariable& Material::findVariableByName(const char* name) const
 	return *(it->second);
 	return *(it->second);
 }
 }
 
 
-
 } // end namespace
 } // end namespace

+ 19 - 15
anki/resource/Material.h

@@ -12,20 +12,16 @@
 #include <boost/scoped_ptr.hpp>
 #include <boost/scoped_ptr.hpp>
 #include <boost/property_tree/ptree_fwd.hpp>
 #include <boost/property_tree/ptree_fwd.hpp>
 #include <boost/range/iterator_range.hpp>
 #include <boost/range/iterator_range.hpp>
-#include <boost/noncopyable.hpp>
 #include <boost/variant.hpp>
 #include <boost/variant.hpp>
 
 
-
 namespace anki {
 namespace anki {
 
 
-
 class ShaderProgram;
 class ShaderProgram;
 class ShaderProgramUniformVariable;
 class ShaderProgramUniformVariable;
 
 
-
 /// Holds the shader variables. Its a container for shader program variables
 /// Holds the shader variables. Its a container for shader program variables
 /// that share the same name
 /// that share the same name
-class MaterialVariable: public boost::noncopyable
+class MaterialVariable
 {
 {
 public:
 public:
 	/// The data union (limited to a few types at the moment)
 	/// The data union (limited to a few types at the moment)
@@ -34,9 +30,13 @@ public:
 
 
 	/// Given a pair of pass and level it returns a pointer to a
 	/// Given a pair of pass and level it returns a pointer to a
 	/// shader program uniform variable. The pointer may be null
 	/// shader program uniform variable. The pointer may be null
-	typedef PassLevelHashMap<const ShaderProgramUniformVariable*>::Type
+	typedef PassLevelHashMap<ShaderProgramUniformVariable*>::Type
 		PassLevelToShaderProgramUniformVariableHashMap;
 		PassLevelToShaderProgramUniformVariableHashMap;
 
 
+	// Non-copyable
+	MaterialVariable(const MaterialVariable&) = delete;
+	MaterialVariable& operator=(const MaterialVariable&) = delete;
+
 	/// @name Constructors & destructor
 	/// @name Constructors & destructor
 	/// @{
 	/// @{
 	template<typename Type>
 	template<typename Type>
@@ -68,12 +68,12 @@ public:
 	}
 	}
 
 
 	/// Given a key return the uniform
 	/// Given a key return the uniform
-	const ShaderProgramUniformVariable& getShaderProgramUniformVariable(
-		const PassLevelKey& key) const
+	ShaderProgramUniformVariable& getShaderProgramUniformVariable(
+		const PassLevelKey& key)
 	{
 	{
 		ANKI_ASSERT(inPass(key));
 		ANKI_ASSERT(inPass(key));
-		const ShaderProgramUniformVariable* var = sProgVars.at(key);
-		ANKI_ASSERT(var != NULL);
+		ShaderProgramUniformVariable* var = sProgVars.at(key);
+		ANKI_ASSERT(var != nullptr);
 		return *var;
 		return *var;
 	}
 	}
 
 
@@ -111,7 +111,6 @@ private:
 		const PassLevelToShaderProgramHashMap& shaderProgsArr);
 		const PassLevelToShaderProgramHashMap& shaderProgsArr);
 };
 };
 
 
-
 /// Contains a few properties that other classes may use. For an explanation of
 /// Contains a few properties that other classes may use. For an explanation of
 /// the variables refer to Material class documentation
 /// the variables refer to Material class documentation
 class MaterialProperties
 class MaterialProperties
@@ -177,7 +176,6 @@ public:
 	{
 	{
 		return blendingSfactor != GL_ONE || blendingDfactor != GL_ZERO;
 		return blendingSfactor != GL_ONE || blendingDfactor != GL_ZERO;
 	}
 	}
-
 protected:
 protected:
 	uint renderingStage;
 	uint renderingStage;
 
 
@@ -195,7 +193,6 @@ protected:
 	bool wireframe;
 	bool wireframe;
 };
 };
 
 
-
 /// Material resource
 /// Material resource
 ///
 ///
 /// Every material keeps info of how to render a RenedrableNode. Using a node
 /// Every material keeps info of how to render a RenedrableNode. Using a node
@@ -300,6 +297,15 @@ public:
 	{
 	{
 		return vars;
 		return vars;
 	}
 	}
+
+	VarsContainer::iterator getVariablesBegin()
+	{
+		return vars.begin();
+	}
+	VarsContainer::iterator getVariablesEnd()
+	{
+		return vars.end();
+	}
 	/// @}
 	/// @}
 
 
 	/// Get by name
 	/// Get by name
@@ -368,8 +374,6 @@ private:
 	static Type setMathType(const char* str);
 	static Type setMathType(const char* str);
 };
 };
 
 
-
 } // end namespace
 } // end namespace
 
 
-
 #endif
 #endif

+ 1 - 1
anki/resource/MaterialCommon.h

@@ -9,7 +9,7 @@ namespace anki {
 
 
 
 
 /// Given a pair of pass and level it returns a pointer to a shader program
 /// Given a pair of pass and level it returns a pointer to a shader program
-typedef PassLevelHashMap<const class ShaderProgram*>::Type
+typedef PassLevelHashMap<class ShaderProgram*>::Type
 	PassLevelToShaderProgramHashMap;
 	PassLevelToShaderProgramHashMap;
 
 
 
 

+ 3 - 9
anki/resource/ResourceManager.h

@@ -4,10 +4,8 @@
 #include <boost/ptr_container/ptr_vector.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
 #include <string>
 #include <string>
 
 
-
 namespace anki {
 namespace anki {
 
 
-
 /// Holds information about a resource
 /// Holds information about a resource
 template<typename Type>
 template<typename Type>
 struct ResourceHook
 struct ResourceHook
@@ -18,13 +16,12 @@ struct ResourceHook
 
 
 	bool operator==(const ResourceHook& b) const
 	bool operator==(const ResourceHook& b) const
 	{
 	{
-		return uuid == b.uuid &&
-			referenceCounter == b.referenceCounter &&
-			resource == b.resource;
+		return uuid == b.uuid 
+			&& referenceCounter == b.referenceCounter 
+			&& resource == b.resource;
 	}
 	}
 };
 };
 
 
-
 /// XXX
 /// XXX
 template<typename Type>
 template<typename Type>
 class ResourceManager
 class ResourceManager
@@ -61,11 +58,8 @@ protected:
 	virtual void deallocRsrc(Type* rsrc);
 	virtual void deallocRsrc(Type* rsrc);
 };
 };
 
 
-
 } // end namespace
 } // end namespace
 
 
-
 #include "anki/resource/ResourceManager.inl.h"
 #include "anki/resource/ResourceManager.inl.h"
 
 
-
 #endif
 #endif

+ 4 - 11
anki/resource/ResourceManager.inl.h

@@ -2,10 +2,8 @@
 #include "anki/util/Exception.h"
 #include "anki/util/Exception.h"
 #include "anki/util/Assert.h"
 #include "anki/util/Assert.h"
 
 
-
 namespace anki {
 namespace anki {
 
 
-
 //==============================================================================
 //==============================================================================
 template<typename Type>
 template<typename Type>
 void ResourceManager<Type>::allocAndLoadRsrc(
 void ResourceManager<Type>::allocAndLoadRsrc(
@@ -35,7 +33,6 @@ void ResourceManager<Type>::allocAndLoadRsrc(
 	}
 	}
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 template<typename Type>
 template<typename Type>
 typename ResourceManager<Type>::Hook& ResourceManager<Type>::load(
 typename ResourceManager<Type>::Hook& ResourceManager<Type>::load(
@@ -68,8 +65,8 @@ typename ResourceManager<Type>::Hook& ResourceManager<Type>::load(
 				delete hook;
 				delete hook;
 			}
 			}
 
 
-			throw ANKI_EXCEPTION("Cannot load \"" +
-				filename + "\"") << e;
+			throw ANKI_EXCEPTION("Cannot load \"" 
+				+ filename + "\"") << e;
 		}
 		}
 
 
 		hooks.push_back(hook);
 		hooks.push_back(hook);
@@ -77,7 +74,6 @@ typename ResourceManager<Type>::Hook& ResourceManager<Type>::load(
 	}
 	}
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 template<typename Type>
 template<typename Type>
 void ResourceManager<Type>::deallocRsrc(Type* rsrc)
 void ResourceManager<Type>::deallocRsrc(Type* rsrc)
@@ -88,7 +84,6 @@ void ResourceManager<Type>::deallocRsrc(Type* rsrc)
 	delete rsrc;
 	delete rsrc;
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 template<typename Type>
 template<typename Type>
 void ResourceManager<Type>::unload(const Hook& hook)
 void ResourceManager<Type>::unload(const Hook& hook)
@@ -99,8 +94,8 @@ void ResourceManager<Type>::unload(const Hook& hook)
 	// If not found
 	// If not found
 	if(it == hooks.end())
 	if(it == hooks.end())
 	{
 	{
-		throw ANKI_EXCEPTION("Resource hook incorrect (\"" +
-			hook.uuid + "\")");
+		throw ANKI_EXCEPTION("Resource hook incorrect (\"" 
+			+ hook.uuid + "\")");
 	}
 	}
 
 
 	ANKI_ASSERT(*it == hook);
 	ANKI_ASSERT(*it == hook);
@@ -115,7 +110,6 @@ void ResourceManager<Type>::unload(const Hook& hook)
 	}
 	}
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 template<typename Type>
 template<typename Type>
 typename ResourceManager<Type>::Iterator ResourceManager<Type>::find(
 typename ResourceManager<Type>::Iterator ResourceManager<Type>::find(
@@ -133,5 +127,4 @@ typename ResourceManager<Type>::Iterator ResourceManager<Type>::find(
 	return it;
 	return it;
 }
 }
 
 
-
 } // end namespace
 } // end namespace

+ 30 - 21
anki/resource/ResourcePointer.h

@@ -3,35 +3,32 @@
 
 
 #include "anki/util/Assert.h"
 #include "anki/util/Assert.h"
 
 
-
 namespace anki {
 namespace anki {
 
 
-
-/// This is a special smart pointer that points to Resource derivatives. It
-/// looks like auto_ptr but the main difference is that when its out of scope
+/// Special smart pointer that points to resource classes.
+///
+/// It looks like auto_ptr but the main difference is that when its out of scope
 /// it tries to unload the resource.
 /// it tries to unload the resource.
 template<typename Type, typename ResourceManagerSingleton>
 template<typename Type, typename ResourceManagerSingleton>
 class ResourcePointer
 class ResourcePointer
 {
 {
 public:
 public:
-	typedef ResourcePointer<Type, ResourceManagerSingleton> Self;
+	typedef Type Value; ///< Resource type
+	typedef ResourcePointer<Value, ResourceManagerSingleton> Self;
 	typedef typename ResourceManagerSingleton::Value::Hook Hook;
 	typedef typename ResourceManagerSingleton::Value::Hook Hook;
 
 
 	/// Default constructor
 	/// Default constructor
 	ResourcePointer()
 	ResourcePointer()
-		: hook(NULL)
 	{}
 	{}
 
 
 	/// Copy constructor
 	/// Copy constructor
 	ResourcePointer(const Self& b)
 	ResourcePointer(const Self& b)
-		: hook(NULL)
 	{
 	{
 		copy(b);
 		copy(b);
 	}
 	}
 
 
 	/// Construct and load
 	/// Construct and load
 	ResourcePointer(const char* filename)
 	ResourcePointer(const char* filename)
-		: hook(NULL)
 	{
 	{
 		load(filename);
 		load(filename);
 	}
 	}
@@ -43,19 +40,33 @@ public:
 
 
 	/// @name Accessors
 	/// @name Accessors
 	/// @{
 	/// @{
-	Type& operator*() const
+	const Value& operator*() const
 	{
 	{
-		ANKI_ASSERT(hook != NULL);
+		ANKI_ASSERT(hook != nullptr);
+		return *hook->resource;
+	}
+	Value& operator*()
+	{
+		ANKI_ASSERT(hook != nullptr);
 		return *hook->resource;
 		return *hook->resource;
 	}
 	}
 
 
-	Type* operator->() const
+	const Value* operator->() const
 	{
 	{
-		ANKI_ASSERT(hook != NULL);
+		ANKI_ASSERT(hook != nullptr);
+		return hook->resource;
+	}
+	Value* operator->()
+	{
+		ANKI_ASSERT(hook != nullptr);
 		return hook->resource;
 		return hook->resource;
 	}
 	}
 
 
-	Type* get() const
+	const Value* get() const
+	{
+		return hook->resource;
+	}
+	Value* get()
 	{
 	{
 		return hook->resource;
 		return hook->resource;
 	}
 	}
@@ -76,21 +87,21 @@ public:
 	/// Load the resource using the resource manager
 	/// Load the resource using the resource manager
 	void load(const char* filename)
 	void load(const char* filename)
 	{
 	{
-		ANKI_ASSERT(hook == NULL);
+		ANKI_ASSERT(hook == nullptr);
 		hook = &ResourceManagerSingleton::get().load(filename);
 		hook = &ResourceManagerSingleton::get().load(filename);
 	}
 	}
 
 
 private:
 private:
 	/// Points to an element located in a container in the resource manager
 	/// Points to an element located in a container in the resource manager
-	Hook* hook;
+	Hook* hook = nullptr;
 
 
 	/// Unloads the resource @see loadRsrc
 	/// Unloads the resource @see loadRsrc
 	void unload()
 	void unload()
 	{
 	{
-		if(hook != NULL)
+		if(hook != nullptr)
 		{
 		{
 			ResourceManagerSingleton::get().unload(*hook);
 			ResourceManagerSingleton::get().unload(*hook);
-			hook = NULL;
+			hook = nullptr;
 		}
 		}
 	}
 	}
 
 
@@ -98,9 +109,9 @@ private:
 	/// unload this and load exactly what @b has. In everything else do nothing
 	/// unload this and load exactly what @b has. In everything else do nothing
 	void copy(const Self& b)
 	void copy(const Self& b)
 	{
 	{
-		if(b.hook == NULL)
+		if(b.hook == nullptr)
 		{
 		{
-			if(hook != NULL)
+			if(hook != nullptr)
 			{
 			{
 				unload();
 				unload();
 			}
 			}
@@ -113,8 +124,6 @@ private:
 	}
 	}
 };
 };
 
 
-
 } // end namespace
 } // end namespace
 
 
-
 #endif
 #endif