2
0
Эх сурвалжийг харах

- Moving a class in another file
- Making it compile

Panagiotis Christopoulos Charitos 14 жил өмнө
parent
commit
a8c5316186

+ 20 - 14
anki/collision/CollisionAlgorithmsMatrix.cpp

@@ -14,26 +14,29 @@ bool CollisionAlgorithmsMatrix::tcollide(const CollisionShape& a,
 	const CollisionShape& b)
 {
 	const T& t = static_cast<const T&>(a);
+	bool out;
 
 	switch(b.getCollisionShapeType())
 	{
 		case CollisionShape::CST_LINE_SEG:
-			return collide(t, static_cast<const LineSegment&>(b));
+			out = collide(t, static_cast<const LineSegment&>(b));
 		case CollisionShape::CST_RAY:
-			return collide(t, static_cast<const Ray&>(b));
+			out = collide(t, static_cast<const Ray&>(b));
 		case CollisionShape::CST_PLANE:
-			return collide(t, static_cast<const Plane&>(b));
+			out = collide(t, static_cast<const Plane&>(b));
 		case CollisionShape::CST_SPHERE:
-			return collide(t, static_cast<const Sphere&>(b));
+			out = collide(t, static_cast<const Sphere&>(b));
 		case CollisionShape::CST_AABB:
-			return collide(t, static_cast<const Aabb&>(b));
+			out = collide(t, static_cast<const Aabb&>(b));
 		case CollisionShape::CST_OBB:
-			return collide(t, static_cast<const Obb&>(b));
+			out = collide(t, static_cast<const Obb&>(b));
 		case CollisionShape::CST_PERSPECTIVE_CAMERA_FRUSTRUM:
-			return collide(t, static_cast<const PerspectiveCameraShape&>(b));
+			out = collide(t, static_cast<const PerspectiveCameraShape&>(b));
 		default:
 			ANKI_ASSERT(0 && "Forgot something");
 	}
+
+	return out;
 }
 
 
@@ -41,25 +44,28 @@ bool CollisionAlgorithmsMatrix::tcollide(const CollisionShape& a,
 bool CollisionAlgorithmsMatrix::collide(const CollisionShape& a,
 	const CollisionShape& b)
 {
+	bool out;
 	switch(a.getCollisionShapeType())
 	{
 		case CollisionShape::CST_LINE_SEG:
-			return tcollide<LineSegment>(a, b);
+			out = tcollide<LineSegment>(a, b);
 		case CollisionShape::CST_RAY:
-			return tcollide<Ray>(a, b);
+			out = tcollide<Ray>(a, b);
 		case CollisionShape::CST_PLANE:
-			return tcollide<Plane>(a, b);
+			out = tcollide<Plane>(a, b);
 		case CollisionShape::CST_SPHERE:
-			return tcollide<Sphere>(a, b);
+			out = tcollide<Sphere>(a, b);
 		case CollisionShape::CST_AABB:
-			return tcollide<Aabb>(a, b);
+			out = tcollide<Aabb>(a, b);
 		case CollisionShape::CST_OBB:
-			return tcollide<Obb>(a, b);
+			out = tcollide<Obb>(a, b);
 		case CollisionShape::CST_PERSPECTIVE_CAMERA_FRUSTRUM:
-			return tcollide<PerspectiveCameraShape>(a, b);
+			out = tcollide<PerspectiveCameraShape>(a, b);
 		default:
 			ANKI_ASSERT(0 && "Forgot something");
 	}
+
+	return out;
 }
 
 

+ 1 - 1
anki/gl/Vao.cpp

@@ -1,7 +1,7 @@
 #include "anki/gl/Vao.h"
 #include "anki/gl/Vbo.h"
 #include "anki/util/Exception.h"
-#include "anki/resource/ShaderProgramAttributeVariable.h"
+#include "anki/resource/ShaderProgram.h"
 
 
 namespace anki {

+ 8 - 8
anki/renderer/Bl.cpp

@@ -104,8 +104,8 @@ void Bl::runSideBlur()
 	glBlendFunc(GL_ONE, GL_ONE);
 
 	sideBlurSProg->bind();
-	sideBlurSProg->getUniformVariableByName("tex").set(*sideBlurMap, 0);
-	sideBlurSProg->getUniformVariableByName("factor").set(sideBlurFactor);
+	sideBlurSProg->findUniformVariableByName("tex").set(*sideBlurMap, 0);
+	sideBlurSProg->findUniformVariableByName("factor").set(sideBlurFactor);
 
 	r.drawQuad();
 }
@@ -124,12 +124,12 @@ void Bl::runBlur()
 		hBlurFbo.bind();
 
 		hBlurSProg->bind();
-		hBlurSProg->getUniformVariableByName("img").set(
+		hBlurSProg->findUniformVariableByName("img").set(
 			r.getPps().getPostPassFai(), 0);
-		hBlurSProg->getUniformVariableByName("msNormalFai").set(
+		hBlurSProg->findUniformVariableByName("msNormalFai").set(
 			r.getMs().getNormalFai(), 1);
 		float tmp = r.getWidth();
-		hBlurSProg->getUniformVariableByName("imgDimension").set(tmp);
+		hBlurSProg->findUniformVariableByName("imgDimension").set(tmp);
 
 		r.drawQuad();
 
@@ -137,11 +137,11 @@ void Bl::runBlur()
 		vBlurFbo.bind();
 
 		vBlurSProg->bind();
-		vBlurSProg->getUniformVariableByName("img").set(blurFai, 0);
-		vBlurSProg->getUniformVariableByName("msNormalFai").set(
+		vBlurSProg->findUniformVariableByName("img").set(blurFai, 0);
+		vBlurSProg->findUniformVariableByName("msNormalFai").set(
 			r.getMs().getNormalFai(), 1);
 		tmp = r.getHeight();
-		vBlurSProg->getUniformVariableByName("imgDimension").set(tmp);
+		vBlurSProg->findUniformVariableByName("imgDimension").set(tmp);
 
 		r.drawQuad();
 	}

+ 6 - 10
anki/renderer/Dbg.cpp

@@ -25,15 +25,11 @@ namespace anki {
 //==============================================================================
 // Constructor                                                                 =
 //==============================================================================
-Dbg::Dbg(Renderer& r_):
-	SwitchableRenderingPass(r_),
-	showAxisEnabled(false),
-	showLightsEnabled(true),
-	showSkeletonsEnabled(true),
-	showCamerasEnabled(true),
-	showVisibilityBoundingShapesFlag(true),
-	sceneDbgDrawer(*this),
-	collisionDbgDrawer(*this)
+Dbg::Dbg(Renderer& r_)
+	: SwitchableRenderingPass(r_), showAxisEnabled(false),
+		showLightsEnabled(true), showSkeletonsEnabled(true),
+		showCamerasEnabled(true), showVisibilityBoundingShapesFlag(true),
+		sceneDbgDrawer(*this),collisionDbgDrawer(*this)
 {}
 
 
@@ -433,7 +429,7 @@ void Dbg::end()
 	colorsVbo.write(&colors[0], 0, sizeof(Vec3) * pointIndex);
 
 	Mat4 pmv = r.getViewProjectionMat() * modelMat;
-	sProg->getUniformVariableByName("modelViewProjectionMat").set(pmv);
+	sProg->findUniformVariableByName("modelViewProjectionMat").set(pmv);
 
 	vao.bind();
 	glDrawArrays(GL_LINES, 0, pointIndex);

+ 2 - 2
anki/renderer/Deformer.cpp

@@ -69,10 +69,10 @@ void Deformer::deform(SkinPatchNode& node) const
 	sProg->bind();
 
 	// Uniforms
-	sProg->getUniformVariableByName("skinningRotations").set(
+	sProg->findUniformVariableByName("skinningRotations").set(
 		&skinNode->getBoneRotations()[0], skinNode->getBoneRotations().size());
 
-	sProg->getUniformVariableByName("skinningTranslations").set(
+	sProg->findUniformVariableByName("skinningTranslations").set(
 		&skinNode->getBoneTranslations()[0],
 		skinNode->getBoneTranslations().size());
 

+ 3 - 3
anki/renderer/Ez.cpp

@@ -55,7 +55,7 @@ void Ez::run()
 		return;
 	}
 
-	const Camera& cam = r.getCamera();
+	Camera& cam = r.getCamera();
 
 	fbo.bind();
 
@@ -68,9 +68,9 @@ void Ez::run()
 
 	glClear(GL_DEPTH_BUFFER_BIT);
 
-	BOOST_FOREACH(const RenderableNode* node, cam.getVisibleMsRenderableNodes())
+	BOOST_FOREACH(RenderableNode* node, cam.getVisibleMsRenderableNodes())
 	{
-		r.getSceneDrawer().renderRenderableNode(*node, cam, PassLevelKey(1, 0));
+		r.getSceneDrawer().renderRenderableNode(cam, PassLevelKey(1, 0), *node);
 	}
 
 	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

+ 9 - 9
anki/renderer/Hdr.cpp

@@ -119,8 +119,8 @@ void Hdr::run()
 	// pass 0
 	toneFbo.bind();
 	toneSProg->bind();
-	toneSProg->getUniformVariableByName("exposure").set(exposure);
-	toneSProg->getUniformVariableByName("fai").set(
+	toneSProg->findUniformVariableByName("exposure").set(exposure);
+	toneSProg->findUniformVariableByName("fai").set(
 		r.getPps().getPrePassFai(), 0);
 	r.drawQuad();
 
@@ -134,24 +134,24 @@ void Hdr::run()
 		hblurSProg->bind();
 		if(i == 0)
 		{
-			hblurSProg->getUniformVariableByName("img").set(toneFai, 0);
+			hblurSProg->findUniformVariableByName("img").set(toneFai, 0);
 		}
 		else
 		{
-			hblurSProg->getUniformVariableByName("img").set(fai, 0);
+			hblurSProg->findUniformVariableByName("img").set(fai, 0);
 		}
 		//float tmp = float(w);
-		hblurSProg->getUniformVariableByName("imgDimension").set(float(w));
-		hblurSProg->getUniformVariableByName("blurringDist").set(
+		hblurSProg->findUniformVariableByName("imgDimension").set(float(w));
+		hblurSProg->findUniformVariableByName("blurringDist").set(
 			float(blurringDist / w));
 		r.drawQuad();
 
 		// vpass
 		vblurFbo.bind();
 		vblurSProg->bind();
-		vblurSProg->getUniformVariableByName("img").set(hblurFai, 0);
-		vblurSProg->getUniformVariableByName("imgDimension").set(float(h));
-		vblurSProg->getUniformVariableByName("blurringDist").set(
+		vblurSProg->findUniformVariableByName("img").set(hblurFai, 0);
+		vblurSProg->findUniformVariableByName("imgDimension").set(float(h));
+		vblurSProg->findUniformVariableByName("blurringDist").set(
 			float(blurringDist / h));
 		r.drawQuad();
 	}

+ 34 - 34
anki/renderer/Is.cpp

@@ -151,8 +151,8 @@ void Is::ambientPass(const Vec3& color)
 	ambientPassSProg->bind();
 
 	// set the uniforms
-	ambientPassSProg->getUniformVariableByName("ambientCol").set(color);
-	ambientPassSProg->getUniformVariableByName("sceneColMap").set(
+	ambientPassSProg->findUniformVariableByName("ambientCol").set(color);
+	ambientPassSProg->findUniformVariableByName("sceneColMap").set(
 		r.getMs().getDiffuseFai(), 0);
 
 	// Draw quad
@@ -163,7 +163,7 @@ void Is::ambientPass(const Vec3& color)
 //==============================================================================
 // pointLightPass                                                              =
 //==============================================================================
-void Is::pointLightPass(const PointLight& light)
+void Is::pointLightPass(PointLight& light)
 {
 	const Camera& cam = r.getCamera();
 
@@ -175,28 +175,28 @@ void Is::pointLightPass(const PointLight& light)
 	const ShaderProgram& shader = *pointLightSProg; // ensure the const-ness
 	shader.bind();
 
-	shader.getUniformVariableByName("msNormalFai").set(
+	shader.findUniformVariableByName("msNormalFai").set(
 		r.getMs().getNormalFai(), 0);
-	shader.getUniformVariableByName("msDiffuseFai").set(
+	shader.findUniformVariableByName("msDiffuseFai").set(
 		r.getMs().getDiffuseFai(), 1);
-	shader.getUniformVariableByName("msSpecularFai").set(
+	shader.findUniformVariableByName("msSpecularFai").set(
 		r.getMs().getSpecularFai(), 2);
-	shader.getUniformVariableByName("msDepthFai").set(
+	shader.findUniformVariableByName("msDepthFai").set(
 		r.getMs().getDepthFai(), 3);
-	shader.getUniformVariableByName("planes").set(r.getPlanes());
-	shader.getUniformVariableByName("limitsOfNearPlane").set(
+	shader.findUniformVariableByName("planes").set(r.getPlanes());
+	shader.findUniformVariableByName("limitsOfNearPlane").set(
 		r.getLimitsOfNearPlane());
-	shader.getUniformVariableByName("limitsOfNearPlane2").set(
+	shader.findUniformVariableByName("limitsOfNearPlane2").set(
 		r.getLimitsOfNearPlane2());
 	float zNear = cam.getZNear();
-	shader.getUniformVariableByName("zNear").set(zNear);
+	shader.findUniformVariableByName("zNear").set(zNear);
 	const Vec3& origin = light.getWorldTransform().getOrigin();
 	Vec3 lightPosEyeSpace = origin.getTransformed(cam.getViewMatrix());
-	shader.getUniformVariableByName("lightPos").set(lightPosEyeSpace);
-	shader.getUniformVariableByName("lightRadius").set(light.getRadius());
-	shader.getUniformVariableByName("lightDiffuseCol").set(
+	shader.findUniformVariableByName("lightPos").set(lightPosEyeSpace);
+	shader.findUniformVariableByName("lightRadius").set(light.getRadius());
+	shader.findUniformVariableByName("lightDiffuseCol").set(
 		light.getDiffuseColor());
-	shader.getUniformVariableByName("lightSpecularCol").set(
+	shader.findUniformVariableByName("lightSpecularCol").set(
 		light.getSpecularColor());
 
 	// render quad
@@ -207,7 +207,7 @@ void Is::pointLightPass(const PointLight& light)
 //==============================================================================
 // spotLightPass                                                               =
 //==============================================================================
-void Is::spotLightPass(const SpotLight& light)
+void Is::spotLightPass(SpotLight& light)
 {
 	const Camera& cam = r.getCamera();
 	bool withShadow = light.getCastShadow() && sm.getEnabled() &&
@@ -260,31 +260,31 @@ void Is::spotLightPass(const SpotLight& light)
 
 	// bind the FAIs
 	const Ms& ms = r.getMs();
-	shdr->getUniformVariableByName("msNormalFai").set(ms.getNormalFai(), 0);
-	shdr->getUniformVariableByName("msDiffuseFai").set(ms.getDiffuseFai(), 1);
-	shdr->getUniformVariableByName("msSpecularFai").set(ms.getSpecularFai(), 2);
-	shdr->getUniformVariableByName("msDepthFai").set(ms.getDepthFai(), 3);
+	shdr->findUniformVariableByName("msNormalFai").set(ms.getNormalFai(), 0);
+	shdr->findUniformVariableByName("msDiffuseFai").set(ms.getDiffuseFai(), 1);
+	shdr->findUniformVariableByName("msSpecularFai").set(ms.getSpecularFai(), 2);
+	shdr->findUniformVariableByName("msDepthFai").set(ms.getDepthFai(), 3);
 
 	// the ???
-	shdr->getUniformVariableByName("planes").set(r.getPlanes());
-	shdr->getUniformVariableByName("limitsOfNearPlane").set(
+	shdr->findUniformVariableByName("planes").set(r.getPlanes());
+	shdr->findUniformVariableByName("limitsOfNearPlane").set(
 		r.getLimitsOfNearPlane());
-	shdr->getUniformVariableByName("limitsOfNearPlane2").set(
+	shdr->findUniformVariableByName("limitsOfNearPlane2").set(
 		r.getLimitsOfNearPlane2());
 	float zNear = cam.getZNear();
-	shdr->getUniformVariableByName("zNear").set(zNear);
+	shdr->findUniformVariableByName("zNear").set(zNear);
 
 	// the light params
 	const Vec3& origin = light.getWorldTransform().getOrigin();
 	Vec3 lightPosEyeSpace = origin.getTransformed(cam.getViewMatrix());
-	shdr->getUniformVariableByName("lightPos").set(lightPosEyeSpace);
+	shdr->findUniformVariableByName("lightPos").set(lightPosEyeSpace);
 	float tmp = light.getDistance();
-	shdr->getUniformVariableByName("lightRadius").set(tmp);
-	shdr->getUniformVariableByName("lightDiffuseCol").set(
+	shdr->findUniformVariableByName("lightRadius").set(tmp);
+	shdr->findUniformVariableByName("lightDiffuseCol").set(
 		light.getDiffuseColor());
-	shdr->getUniformVariableByName("lightSpecularCol").set(
+	shdr->findUniformVariableByName("lightSpecularCol").set(
 		light.getSpecularColor());
-	shdr->getUniformVariableByName("lightTex").set(light.getTexture(), 4);
+	shdr->findUniformVariableByName("lightTex").set(light.getTexture(), 4);
 
 	// set texture matrix for texture & shadowmap projection
 	// Bias * P_light * V_light * inv(V_cam)
@@ -294,14 +294,14 @@ void Is::spotLightPass(const SpotLight& light)
 	texProjectionMat = biasMat4 * light.getCamera().getProjectionMatrix() *
 		Mat4::combineTransformations(light.getCamera().getViewMatrix(),
 		Mat4(cam.getWorldTransform()));
-	shdr->getUniformVariableByName("texProjectionMat").set(texProjectionMat);
+	shdr->findUniformVariableByName("texProjectionMat").set(texProjectionMat);
 
 	// the shadowmap
 	if(light.getCastShadow() && sm.getEnabled())
 	{
-		shdr->getUniformVariableByName("shadowMap").set(sm.getShadowMap(), 5);
+		shdr->findUniformVariableByName("shadowMap").set(sm.getShadowMap(), 5);
 		float smSize = sm.getShadowMap().getWidth();
-		shdr->getUniformVariableByName("shadowMapSize").set(smSize);
+		shdr->findUniformVariableByName("shadowMapSize").set(smSize);
 	}
 
 	// render quad
@@ -349,7 +349,7 @@ void Is::run()
 	GlStateMachineSingleton::get().enable(GL_STENCIL_TEST);
 
 	// for all lights
-	BOOST_FOREACH(const PointLight* light,
+	BOOST_FOREACH(PointLight* light,
 		r.getCamera().getVisiblePointLights())
 	{
 		/*if(light->getVisibleMsRenderableNodes().size() == 0)
@@ -359,7 +359,7 @@ void Is::run()
 		pointLightPass(*light);
 	}
 
-	BOOST_FOREACH(const SpotLight* light, r.getCamera().getVisibleSpotLights())
+	BOOST_FOREACH(SpotLight* light, r.getCamera().getVisibleSpotLights())
 	{
 		/*if(light->getVisibleMsRenderableNodes() == 0)
 		{

+ 2 - 2
anki/renderer/Is.h

@@ -58,10 +58,10 @@ class Is: private RenderingPass
 		void ambientPass(const Vec3& color);
 
 		/// The point light pass
-		void pointLightPass(const PointLight& plight);
+		void pointLightPass(PointLight& plight);
 
 		/// The spot light pass
-		void spotLightPass(const SpotLight& slight);
+		void spotLightPass(SpotLight& slight);
 
 		/// Used in @ref init
 		void initFbo();

+ 3 - 3
anki/renderer/MainRenderer.cpp

@@ -143,10 +143,10 @@ void MainRenderer::render(Camera& cam_)
 	GlStateMachineSingleton::get().enable(GL_DEPTH_TEST, false);
 	GlStateMachineSingleton::get().enable(GL_BLEND, false);
 	sProg->bind();
-	//sProg->getUniformVariableByName("rasterImage").set(ms.getDiffuseFai(), 0);
-	//sProg->getUniformVariableByName("rasterImage").
+	//sProg->findUniformVariableByName("rasterImage").set(ms.getDiffuseFai(), 0);
+	//sProg->findUniformVariableByName("rasterImage").
 	//	set(is.getFai(), 0);
-	sProg->getUniformVariableByName("rasterImage").set(pps.getPostPassFai(), 0);
+	sProg->findUniformVariableByName("rasterImage").set(pps.getPostPassFai(), 0);
 	drawQuad();
 }
 

+ 3 - 3
anki/renderer/Ms.cpp

@@ -116,11 +116,11 @@ void Ms::run()
 	glClear(GL_COLOR_BUFFER_BIT);
 
 	// render all
-	BOOST_FOREACH(const RenderableNode* node,
+	BOOST_FOREACH(RenderableNode* node,
 		r.getCamera().getVisibleMsRenderableNodes())
 	{
-		r.getSceneDrawer().renderRenderableNode(*node, r.getCamera(),
-			PassLevelKey(0, 0));
+		r.getSceneDrawer().renderRenderableNode(r.getCamera(),
+			PassLevelKey(0, 0), *node);
 	}
 
 	// restore depth

+ 4 - 4
anki/renderer/Pps.cpp

@@ -126,11 +126,11 @@ void Pps::runPrePass()
 		r.getWidth(), r.getHeight());
 
 	prePassSProg->bind();
-	prePassSProg->getUniformVariableByName("isFai").set(r.getIs().getFai(), 0);
+	prePassSProg->findUniformVariableByName("isFai").set(r.getIs().getFai(), 0);
 
 	if(ssao.getEnabled())
 	{
-		prePassSProg->getUniformVariableByName("ppsSsaoFai").set(
+		prePassSProg->findUniformVariableByName("ppsSsaoFai").set(
 			ssao.getFai(), 1);
 	}
 
@@ -159,11 +159,11 @@ void Pps::runPostPass()
 		r.getWidth(), r.getHeight());
 
 	postPassSProg->bind();
-	postPassSProg->getUniformVariableByName("ppsPrePassFai").set(
+	postPassSProg->findUniformVariableByName("ppsPrePassFai").set(
 		prePassFai, 0);
 	if(hdr.getEnabled())
 	{
-		postPassSProg->getUniformVariableByName("ppsHdrFai").set(
+		postPassSProg->findUniformVariableByName("ppsHdrFai").set(
 			hdr.getFai(), 1);
 	}
 

+ 5 - 1
anki/renderer/Renderer.h

@@ -105,6 +105,10 @@ class Renderer
 		{
 			return *cam;
 		}
+		Camera& getCamera()
+		{
+			return *cam;
+		}
 
 		const SceneDrawer& getSceneDrawer() const
 		{
@@ -229,7 +233,7 @@ class Renderer
 		uint width;
 		/// Height of the rendering. Don't confuse with the window width
 		uint height;
-		const Camera* cam; ///< Current camera
+		Camera* cam; ///< Current camera
 		/// Max color attachments an FBO can accept
 		static int maxColorAtachments;
 		SceneDrawer sceneDrawer;

+ 70 - 74
anki/renderer/SceneDrawer.cpp

@@ -40,54 +40,56 @@ boost::array<const char*, SceneDrawer::B_NUM> SceneDrawer::buildinsTxt = {{
 
 
 //==============================================================================
-SceneDrawer::UsrDefVarVisitor::UsrDefVarVisitor(
-	const MaterialRuntimeVariable& udvr_,
-	const Renderer& r_, const PassLevelKey& pt_, uint& texUnit_)
-	: udvr(udvr_), r(r_), key(pt_), texUnit(texUnit_)
+SceneDrawer::SetUniformVisitor::SetUniformVisitor(
+	const ShaderProgramUniformVariable& uni_, uint& texUnit_)
+	: uni(uni_), texUnit(texUnit_)
 {}
 
 
 //==============================================================================
-// Visitor functors                                                            =
-//==============================================================================
-
 template<typename Type>
-void SceneDrawer::UsrDefVarVisitor::operator()(const Type& x) const
+void SceneDrawer::SetUniformVisitor::operator()(const Type& x) const
 {
-	static_cast<const ShaderProgramUniformVariable&>(udvr.getMaterialVariable().
-		getShaderProgramVariable(key)).set(x);
+	uni.set(x);
 }
 
 
-void SceneDrawer::UsrDefVarVisitor::operator()(
-	const TextureResourcePointer* x) const
+//==============================================================================
+template<>
+void SceneDrawer::SetUniformVisitor::operator()<TextureResourcePointer>(
+	const TextureResourcePointer& x) const
 {
-	const TextureResourcePointer& texPtr = *x;
-	texPtr->setRepeat(true);
+	uni.set(*x, texUnit++);
+}
 
-	static_cast<const ShaderProgramUniformVariable&>(udvr.getMaterialVariable().
-		getShaderProgramVariable(key)).set(*texPtr, texUnit);
 
-	++texUnit;
+//==============================================================================
+void SceneDrawer::tryCalcModelViewMat(const Mat4& modelMat,
+	const Mat4& viewMat, bool& calculated, Mat4& modelViewMat)
+{
+	if(!calculated)
+	{
+		modelViewMat = (modelMat == Mat4::getIdentity()) ? viewMat :
+			Mat4::combineTransformations(viewMat, modelMat);
+
+		calculated = true;
+	}
 }
 
 
-//==============================================================================
-// setupShaderProg                                                             =
 //==============================================================================
 void SceneDrawer::setupShaderProg(
-	const MaterialRuntime& mtlr,
-	const PassLevelKey& pt,
+	const PassLevelKey& key,
 	const Transform& nodeWorldTransform,
+	const Transform& prevNodeWorldTransform,
 	const Camera& cam,
 	const Renderer& r,
-	float blurring)
+	MaterialRuntime& mtlr)
 {
-	typedef MaterialVariable Mvb; // Short name
 	uint textureUnit = 0;
 	GlStateMachine& gl = GlStateMachineSingleton::get();
 	const Material& mtl = mtlr.getMaterial();
-	const ShaderProgram& sprog = mtl.getShaderProgram(pt);
+	const ShaderProgram& sprog = mtl.getShaderProgram(key);
 
 	sprog.bind();
 
@@ -112,41 +114,18 @@ void SceneDrawer::setupShaderProg(
 	}
 
 	//
-	// Calc needed matrices
+	// Get needed matrices
 	//
 	Mat4 modelMat(nodeWorldTransform);
 	const Mat4& projectionMat = cam.getProjectionMatrix();
 	const Mat4& viewMat = cam.getViewMatrix();
 	Mat4 modelViewMat;
-	Mat3 normalMat;
-	Mat4 modelViewProjectionMat;
-
-	// should I calculate the modelViewMat ?
-	if(mtl.variableExistsAndInKey("modelViewMat", pt) ||
-		mtl.variableExistsAndInKey("modeViewProjectionMat", pt) ||
-		mtl.variableExistsAndInKey("normalMat", pt))
-	{
-		// Optimization
-		modelViewMat = (modelMat == Mat4::getIdentity()) ? viewMat :
-			Mat4::combineTransformations(viewMat, modelMat);
-	}
-
-	// normalMat?
-	if(mtl.variableExistsAndInKey("normalMat", pt))
-	{
-		normalMat = modelViewMat.getRotationPart();
-	}
-
-	// modelViewProjectionMat?
-	if(mtl.variableExistsAndInKey("modelViewProjectionMat", pt))
-	{
-		modelViewProjectionMat = projectionMat * modelViewMat;
-	}
+	bool modelViewMatCalculated = false;
 
 	//
 	// For all the vars
 	//
-	BOOST_FOREACH(const MaterialRuntimeVariable& mrvar, mtlr.getVariables())
+	BOOST_FOREACH(MaterialRuntimeVariable& mrvar, mtlr.getVariables())
 	{
 		const MaterialVariable& mvar = mrvar.getMaterialVariable();
 
@@ -203,17 +182,34 @@ void SceneDrawer::setupShaderProg(
 				uni.set(projectionMat);
 				break;
 			case B_MODEL_VIEW_MAT:
+			{
+				tryCalcModelViewMat(modelMat, viewMat, modelViewMatCalculated,
+					modelViewMat);
+
 				uni.set(modelViewMat);
 				break;
+			}
 			case B_VIEW_PROJECTION_MAT:
-				uni.set(viewProjectionMat);
+				uni.set(r.getViewProjectionMat());
 				break;
 			case B_NORMAL_MAT:
+			{
+				tryCalcModelViewMat(modelMat, viewMat, modelViewMatCalculated,
+					modelViewMat);
+
+				Mat3 normalMat = modelViewMat.getRotationPart();
 				uni.set(normalMat);
 				break;
+			}
 			case B_MODEL_VIEW_PROJECTION_MAT:
+			{
+				tryCalcModelViewMat(modelMat, viewMat, modelViewMatCalculated,
+					modelViewMat);
+
+				Mat4 modelViewProjectionMat = projectionMat * modelViewMat;
 				uni.set(modelViewProjectionMat);
 				break;
+			}
 			case B_MS_NORMAL_FAI:
 				uni.set(r.getMs().getNormalFai(), textureUnit++);
 				break;
@@ -230,26 +226,39 @@ void SceneDrawer::setupShaderProg(
 				uni.set(r.getIs().getFai(), textureUnit++);
 				break;
 			case B_PPS_PRE_PASS_FAI:
-				uni.set(r.getPps().getPreFai(), textureUnit++);
+				uni.set(r.getPps().getPrePassFai(), textureUnit++);
 				break;
 			case B_PPS_POST_PASS_FAI:
-				uni.set(r.getPps().getPostFai(), textureUnit++);
+				uni.set(r.getPps().getPostPassFai(), textureUnit++);
 				break;
 			case B_RENDERER_SIZE:
 			{
-				Vec2 v(r.getWidth(), r.getHeight());
-				uni.set(v);
+				uni.set(Vec2(r.getWidth(), r.getHeight()));
 				break;
 			}
 			case B_SCENE_AMBIENT_COLOR:
 				uni.set(SceneSingleton::get().getAmbientColor());
 				break;
 			case B_BLURRING:
+			{
+				float prev = (prevNodeWorldTransform.getOrigin() -
+					cam.getPrevWorldTransform().getOrigin()).getLength();
+
+				float crnt = (nodeWorldTransform.getOrigin() -
+					cam.getWorldTransform().getOrigin()).getLength();
+
+				float blurring = abs(crnt - prev);
 				uni.set(blurring);
 				break;
+			}
 			case B_NUM:
-				/// XXX
+			{
+				// ATTENTION: Don't EVER use the mutable version of
+				// MaterialRuntimeVariable::getVariant() here as it copies data
+				const MaterialRuntimeVariable::Variant& v = mrvar.getVariant();
+				boost::apply_visitor(SetUniformVisitor(uni, textureUnit), v);
 				break;
+			}
 		}
 	}
 
@@ -258,28 +267,15 @@ void SceneDrawer::setupShaderProg(
 
 
 //==============================================================================
-// renderRenderableNode                                                        =
-//==============================================================================
-void SceneDrawer::renderRenderableNode(const RenderableNode& node,
-	const Camera& cam, const PassLevelKey& key) const
+void SceneDrawer::renderRenderableNode(const Camera& cam,
+	const PassLevelKey& key, RenderableNode& node) const
 {
-	float blurring = 0.0;
-	const MaterialRuntime& mtlr = node.getMaterialRuntime();
+	MaterialRuntime& mtlr = node.getMaterialRuntime();
 	const Material& mtl = mtlr.getMaterial();
 
-	// Calc the blur if needed
-	if(mtl.variableExistsAndInKey("blurring", key))
-	{
-		float prev = (node.getPrevWorldTransform().getOrigin() -
-			cam.getPrevWorldTransform().getOrigin()).getLength();
-
-		float crnt = (node.getWorldTransform().getOrigin() -
-			cam.getWorldTransform().getOrigin()).getLength();
-
-		blurring = abs(crnt - prev);
-	}
+	setupShaderProg(key, node.getWorldTransform(),
+		node.getPrevWorldTransform(), cam, r, mtlr);
 
-	setupShaderProg(mtlr, key, node.getWorldTransform(), cam, r, blurring);
 	node.getVao(key).bind();
 	glDrawElements(GL_TRIANGLES, node.getVertIdsNum(key), GL_UNSIGNED_SHORT, 0);
 	node.getVao(key).unbind();

+ 13 - 14
anki/renderer/SceneDrawer.h

@@ -15,6 +15,7 @@ class Camera;
 class Material;
 class MaterialRuntime;
 class MaterialRuntimeVariable;
+class ShaderProgramUniformVariable;
 
 class Renderer;
 
@@ -28,8 +29,8 @@ public:
 		: r(r_)
 	{}
 
-	void renderRenderableNode(const RenderableNode& renderable,
-		const Camera& cam, const PassLevelKey& key) const;
+	void renderRenderableNode(const Camera& cam,
+		const PassLevelKey& key, RenderableNode& renderable) const;
 
 private:
 	/// Standard attribute variables that are acceptable inside the
@@ -61,23 +62,17 @@ private:
 	};
 
 	/// Set the uniform using this visitor
-	class UsrDefVarVisitor: public boost::static_visitor<>
+	class SetUniformVisitor: public boost::static_visitor<>
 	{
 	public:
-		const MaterialRuntimeVariable& udvr;
-		const Renderer& r;
-		const PassLevelKey& key;
+		const ShaderProgramUniformVariable& uni;
 		uint& texUnit;
 
-		UsrDefVarVisitor(const MaterialRuntimeVariable& udvr,
-			const Renderer& r, const PassLevelKey& key, uint& texUnit);
+		SetUniformVisitor(const ShaderProgramUniformVariable& uni,
+			uint& texUnit);
 
-		/// Functor
 		template<typename Type>
 		void operator()(const Type& x) const;
-
-		/// Functor
-		void operator()(const TextureResourcePointer* x) const;
 	};
 
 	static boost::array<const char*, B_NUM> buildinsTxt;
@@ -94,12 +89,16 @@ private:
 	/// @param cam Needed for some matrices (view & projection)
 	/// @param r The renderer, needed for some FAIs and some matrices
 	static void setupShaderProg(
-		const MaterialRuntime& mtlr,
 		const PassLevelKey& key,
 		const Transform& nodeWorldTransform,
+		const Transform& prevNodeWorldTransform,
 		const Camera& cam,
 		const Renderer& r,
-		float blurring);
+		MaterialRuntime& mtlr);
+
+	/// For code duplication
+	static void tryCalcModelViewMat(const Mat4& modelMat, const Mat4& viewMat,
+		bool& calculated, Mat4& modelViewMat);
 };
 
 

+ 4 - 5
anki/renderer/Sm.cpp

@@ -103,7 +103,7 @@ void Sm::initLevel(uint resolution, float distance, bool bilinear, Level& level)
 //==============================================================================
 // run                                                                         =
 //==============================================================================
-void Sm::run(const Light& light, float distance)
+void Sm::run(Light& light, float distance)
 {
 	if(!enabled)
 	{
@@ -146,16 +146,15 @@ void Sm::run(const Light& light, float distance)
 	GlStateMachineSingleton::get().enable(GL_POLYGON_OFFSET_FILL);
 
 	// render all
-	BOOST_FOREACH(const RenderableNode* node,
-		light.getVisibleMsRenderableNodes())
+	BOOST_FOREACH(RenderableNode* node, light.getVisibleMsRenderableNodes())
 	{
 		switch(light.getLightType())
 		{
 			case Light::LT_SPOT:
 			{
 				const SpotLight& sl = static_cast<const SpotLight&>(light);
-				r.getSceneDrawer().renderRenderableNode(*node, sl.getCamera(),
-					PassLevelKey(1, 0));
+				r.getSceneDrawer().renderRenderableNode(sl.getCamera(),
+					PassLevelKey(1, 0), *node);
 				break;
 			}
 

+ 1 - 1
anki/renderer/Sm.h

@@ -56,7 +56,7 @@ class Sm: private RenderingPass
 		/// @param[in] light The light
 		/// @param[in] distance The distance between the viewers camera and the
 		/// light
-		void run(const Light& light, float distance);
+		void run(Light& light, float distance); /// XXX order
 
 	private:
 		/// The shadowmap levels of detail

+ 4 - 4
anki/renderer/Smo.cpp

@@ -53,7 +53,7 @@ void Smo::init(const RendererInitializer& /*initializer*/)
 	sphereGeom.vao.create();
 	sphereGeom.vao.attachArrayBufferVbo(
 		sphereGeom.mesh->getVbo(Mesh::VBO_VERT_POSITIONS),
-		sProg->getAttributeVariableByName("position"), 3, GL_FLOAT,
+		sProg->findAttributeVariableByName("position"), 3, GL_FLOAT,
 		GL_FALSE, 0, NULL);
 	sphereGeom.vao.attachElementArrayBufferVbo(
 		sphereGeom.mesh->getVbo(Mesh::VBO_VERT_INDECES));
@@ -78,7 +78,7 @@ void Smo::initCamGeom()
 		camGeom[i].vao.create();
 		camGeom[i].vao.attachArrayBufferVbo(
 			camGeom[i].mesh->getVbo(Mesh::VBO_VERT_POSITIONS),
-			sProg->getAttributeVariableByName("position"), 3, GL_FLOAT,
+			sProg->findAttributeVariableByName("position"), 3, GL_FLOAT,
 			GL_FALSE, 0, NULL);
 		camGeom[i].vao.attachElementArrayBufferVbo(
 			camGeom[i].mesh->getVbo(Mesh::VBO_VERT_INDECES));
@@ -148,7 +148,7 @@ void Smo::run(const PointLight& light)
 	Mat4 modelMat = Mat4(light.getWorldTransform().getOrigin(),
 		Mat3::getIdentity(), light.getRadius() * SCALE);
 	Mat4 trf = r.getViewProjectionMat() * modelMat;
-	sProg->getUniformVariableByName("modelViewProjectionMat").set(trf);
+	sProg->findUniformVariableByName("modelViewProjectionMat").set(trf);
 
 	// render sphere to the stencil buffer
 	sphereGeom.vao.bind();
@@ -228,7 +228,7 @@ void Smo::run(const SpotLight& light)
 	Mat4 modelMat = Mat4(lcam.getWorldTransform());
 
 	Mat4 trf = r.getViewProjectionMat() * modelMat * localMat;
-	sProg->getUniformVariableByName("modelViewProjectionMat").set(trf);
+	sProg->findUniformVariableByName("modelViewProjectionMat").set(trf);
 
 	//
 	// Render

+ 14 - 14
anki/renderer/Ssao.cpp

@@ -124,37 +124,37 @@ void Ssao::run()
 	ssaoSProg->bind();
 	
 	// planes
-	ssaoSProg->getUniformVariableByName("planes").set(r.getPlanes());
+	ssaoSProg->findUniformVariableByName("planes").set(r.getPlanes());
 
 	// limitsOfNearPlane
-	ssaoSProg->getUniformVariableByName("limitsOfNearPlane").set(
+	ssaoSProg->findUniformVariableByName("limitsOfNearPlane").set(
 		r.getLimitsOfNearPlane());
 
 	// limitsOfNearPlane2
-	ssaoSProg->getUniformVariableByName("limitsOfNearPlane2").set(
+	ssaoSProg->findUniformVariableByName("limitsOfNearPlane2").set(
 		r.getLimitsOfNearPlane2());
 
 	// zNear
 	float zNear = cam.getZNear();
-	ssaoSProg->getUniformVariableByName("zNear").set(zNear);
+	ssaoSProg->findUniformVariableByName("zNear").set(zNear);
 
 	// msDepthFai
-	ssaoSProg->getUniformVariableByName("msDepthFai").set(
+	ssaoSProg->findUniformVariableByName("msDepthFai").set(
 		r.getMs().getDepthFai(), 0);
 
 	// noiseMap
-	ssaoSProg->getUniformVariableByName("noiseMap").set(*noiseMap, 1);
+	ssaoSProg->findUniformVariableByName("noiseMap").set(*noiseMap, 1);
 
 	// noiseMapSize
 	float noiseMapSize = noiseMap->getWidth();
-	ssaoSProg->getUniformVariableByName("noiseMapSize").set(noiseMapSize);
+	ssaoSProg->findUniformVariableByName("noiseMapSize").set(noiseMapSize);
 
 	// screenSize
 	Vec2 screenSize(width * 2, height * 2);
-	ssaoSProg->getUniformVariableByName("screenSize").set(screenSize);
+	ssaoSProg->findUniformVariableByName("screenSize").set(screenSize);
 
 	// msNormalFai
-	ssaoSProg->getUniformVariableByName("msNormalFai").set(
+	ssaoSProg->findUniformVariableByName("msNormalFai").set(
 		r.getMs().getNormalFai(), 2);
 
 	r.drawQuad();
@@ -172,22 +172,22 @@ void Ssao::run()
 		hblurSProg->bind();
 		if(i == 0)
 		{
-			hblurSProg->getUniformVariableByName("img").set(ssaoFai, 0);
+			hblurSProg->findUniformVariableByName("img").set(ssaoFai, 0);
 		}
 		else
 		{
-			hblurSProg->getUniformVariableByName("img").set(fai, 0);
+			hblurSProg->findUniformVariableByName("img").set(fai, 0);
 		}
 		float tmp = width;
-		hblurSProg->getUniformVariableByName("imgDimension").set(tmp);
+		hblurSProg->findUniformVariableByName("imgDimension").set(tmp);
 		r.drawQuad();
 
 		// vpass
 		vblurFbo.bind();
 		vblurSProg->bind();
-		vblurSProg->getUniformVariableByName("img").set(hblurFai, 0);
+		vblurSProg->findUniformVariableByName("img").set(hblurFai, 0);
 		tmp = height;
-		vblurSProg->getUniformVariableByName("imgDimension").set(tmp);
+		vblurSProg->findUniformVariableByName("imgDimension").set(tmp);
 		r.drawQuad();
 	}
 

+ 14 - 77
anki/resource/Mesh.h

@@ -19,98 +19,35 @@ class MeshBase
 {
 public:
 	MeshBase()
-	{
-		pVbo = nVbo = tVbo = wVbo = NULL;
-	}
+	{}
 
 	virtual ~MeshBase()
 	{}
 
 	/// @name Accessors
 	/// @{
-	const Vbo& getPositionsVbo() const
-	{
-		ANKI_ASSERT(pVbo != NULL);
-		return *pVbo;
-	}
-
-	const Vbo& getNormalsVbo() const
-	{
-		ANKI_ASSERT(nVbo != NULL);
-		return *nVbo;
-	}
-
-	const Vbo& getTangentsVbo() const
-	{
-		ANKI_ASSERT(tVbo != NULL);
-		return *tVbo;
-	}
-
-	const Vbo& getTextureCoordsVbo(uint channel) const
-	{
-		ANKI_ASSERT(texVbo[channel] != NULL);
-		return *texVbo[channel];
-	}
-
-	const Vbo& getIndecesVbo(uint lod) const
-	{
-		ANKI_ASSERT(iVbo[lod] != NULL);
-		return *iVbo[lod];
-	}
-
-	const Vbo& getWeightsVbo() const
-	{
-		ANKI_ASSERT(wVbo != NULL);
-		return *wVbo;
-	}
-
-	uint getTextureChannelsNumber() const
-	{
-		return texVbo.size();
-	}
-
-	uint getLodsNumber() const
-	{
-		ANKI_ASSERT(iVbo.size() > 0);
-		return iVbo.size();
-	}
-
-	uint getIndicesNumber(uint lod) const
-	{
-		ANKI_ASSERT(idsNum[lod] != 0);
-		return idsNum[lod];
-	}
-
-	uint getVertexNumber(uint lod) const
-	{
-		ANKI_ASSERT(vertsNum[lod] != 0);
-		return vertsNum[lod];
-	}
+	virtual const Vbo& getPositionsVbo() const = 0;
+	virtual const Vbo& getNormalsVbo() const = 0;
+	virtual const Vbo& getTangentsVbo() const = 0;
+	virtual const Vbo& getTextureCoordsVbo(uint channel) const = 0;
+	virtual const Vbo& getIndecesVbo(uint lod) const = 0;
+	virtual const Vbo& getWeightsVbo() const = 0;
+
+	virtual uint getTextureChannelsNumber() const = 0;
+	virtual uint getLodsNumber() const = 0;
+	virtual uint getIndicesNumber(uint lod) const = 0;
+	virtual uint getVertexNumber(uint lod) const = 0;
 	/// @}
 
 	/// @name Ask for geometry properties
 	/// @{
 	bool hasTexCoords() const
 	{
-		return texVbo.size() > 0;
+		return getTextureChannelsNumber() > 0;
 	}
 
-	bool hasWeights() const
-	{
-		return wVbo != NULL;
-	}
+	virtual bool hasWeights() const;
 	/// @}
-
-protected:
-	Vbo* pVbo; ///< Mandatory
-	Vbo* nVbo; ///< Mandatory
-	Vbo* tVbo; ///< Mandatory
-	std::vector<Vbo*> texVbo; ///< Optional. Tex coords per channel
-	std::vector<Vbo*> iVbo; ///< Mandatory. Indices VBO per LOD
-	Vbo* wVbo; ///< Optional
-
-	std::vector<uint> idsNum; ///< Indices count per LOD
-	std::vector<uint> vertsNum; ///< Vertex count per LOD
 };
 
 

+ 107 - 5
anki/resource/Model.cpp

@@ -1,20 +1,122 @@
-#include <boost/property_tree/ptree.hpp>
-#include <boost/property_tree/xml_parser.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/assign.hpp>
-#include <boost/range/iterator_range.hpp>
 #include "anki/resource/Model.h"
 #include "anki/resource/Material.h"
 #include "anki/resource/Mesh.h"
 #include "anki/resource/SkelAnim.h"
 #include "anki/resource/MeshData.h"
 #include "anki/resource/Skeleton.h"
+#include "anki/resource/ShaderProgram.h"
 #include <boost/foreach.hpp>
+#include <boost/property_tree/ptree.hpp>
+#include <boost/property_tree/xml_parser.hpp>
+#include <boost/assign.hpp>
+#include <boost/range/iterator_range.hpp>
 
 
 namespace anki {
 
 
+//==============================================================================
+// ModelPatch                                                                  =
+//==============================================================================
+
+//==============================================================================
+ModelPatch::ModelPatch(const char* meshFName, const char* mtlFName)
+{
+	// Load
+	mesh.load(meshFName);
+	mtl.load(mtlFName);
+
+	// Create VAOs
+	VboArray vboArr;
+	for(uint i = 0; i < Mesh::VBOS_NUM; i++)
+	{
+		vboArr[i] = &mesh->getVbo((Mesh::Vbos)i);
+	}
+
+	createVaos(*mtl, vboArr, vaos, vaosHashMap);
+}
+
+
+//==============================================================================
+ModelPatch::~ModelPatch()
+{}
+
+
+//==============================================================================
+bool ModelPatch::supportsHwSkinning() const
+{
+	return mesh->hasVertWeights();
+}
+
+
+//==============================================================================
+Vao* ModelPatch::createVao(const Material& mtl,
+	const VboArray& vbos,
+	const PassLevelKey& key)
+{
+	Vao* vao = new Vao;
+
+	if(mtl.getShaderProgram(key).uniformVariableExists("position"))
+	{
+		ANKI_ASSERT(vbos[Mesh::VBO_VERT_POSITIONS] != NULL);
+
+		vao->attachArrayBufferVbo(*vbos[Mesh::VBO_VERT_POSITIONS],
+			0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
+	}
+
+	if(mtl.getShaderProgram(key).uniformVariableExists("normal"))
+	{
+		ANKI_ASSERT(vbos[Mesh::VBO_VERT_NORMALS] != NULL);
+
+		vao->attachArrayBufferVbo(*vbos[Mesh::VBO_VERT_NORMALS],
+			1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
+	}
+
+	if(mtl.getShaderProgram(key).uniformVariableExists("tangent"))
+	{
+		ANKI_ASSERT(vbos[Mesh::VBO_VERT_TANGENTS] != NULL);
+
+		vao->attachArrayBufferVbo(*vbos[Mesh::VBO_VERT_TANGENTS],
+			2, 4, GL_FLOAT, GL_FALSE, 0, NULL);
+	}
+
+	if(mtl.getShaderProgram(key).uniformVariableExists("texCoords"))
+	{
+		vao->attachArrayBufferVbo(*vbos[Mesh::VBO_TEX_COORDS],
+			3, 2, GL_FLOAT, GL_FALSE, 0, NULL);
+	}
+
+	vao->attachElementArrayBufferVbo(*vbos[Mesh::VBO_VERT_INDECES]);
+
+	return vao;
+}
+
+
+//==============================================================================
+void ModelPatch::createVaos(const Material& mtl,
+	const VboArray& vbos,
+	VaosContainer& vaos,
+	PassLevelToVaoHashMap& vaosHashMap)
+{
+	for(uint level = 0; level < mtl.getLevelsOfDetail(); ++level)
+	{
+		for(uint pass = 0; pass < mtl.getPasses().size(); ++pass)
+		{
+			PassLevelKey key(pass, level);
+
+			Vao* vao = createVao(mtl, vbos, key);
+
+			vaos.push_back(vao);
+			vaosHashMap[key] = vao;
+		}
+	}
+}
+
+
+//==============================================================================
+// Model                                                                       =
+//==============================================================================
+
 //==============================================================================
 void Model::load(const char* filename)
 {

+ 55 - 4
anki/resource/Model.h

@@ -1,16 +1,67 @@
-#ifndef ANKI_RESOURCE_MODEL_MODEL_H
-#define ANKI_RESOURCE_MODEL_MODEL_H
+#ifndef ANKI_RESOURCE_MODEL_H
+#define ANKI_RESOURCE_MODEL_H
 
-#include <boost/ptr_container/ptr_vector.hpp>
 #include "anki/resource/Resource.h"
 #include "anki/gl/Vao.h"
-#include "anki/resource/ModelPatch.h"
 #include "anki/collision/Obb.h"
+#include "anki/resource/PassLevelKey.h"
+#include "anki/resource/Mesh.h"
+#include <boost/ptr_container/ptr_vector.hpp>
 
 
 namespace anki {
 
 
+/// Its a chunk of a model. Its very important class and it binds the material
+/// with the mesh
+class ModelPatch
+{
+public:
+	typedef boost::ptr_vector<Vao> VaosContainer;
+	typedef PassLevelHashMap<Vao*>::Type PassLevelToVaoHashMap;
+	typedef boost::array<const Vbo*, Mesh::VBOS_NUM> VboArray;
+
+	ModelPatch(const char* meshFName, const char* mtlFName);
+	~ModelPatch();
+
+	/// @name Accessors
+	/// @{
+	const Mesh& getMesh() const
+	{
+		return *mesh;
+	}
+
+	const Material& getMaterial() const
+	{
+		return *mtl;
+	}
+	/// @}
+
+	bool supportsHwSkinning() const;
+
+	const Vao& getVao(const PassLevelKey& key) const
+	{
+		return *vaosHashMap.at(key);
+	}
+
+	static void createVaos(const Material& mtl,
+		const VboArray& vbos,
+		VaosContainer& vaos,
+		PassLevelToVaoHashMap& vaosHashMap);
+
+private:
+	MeshResourcePointer mesh; ///< The geometry
+	MaterialResourcePointer mtl; ///< Material
+
+	VaosContainer vaos;
+	PassLevelToVaoHashMap vaosHashMap;
+
+	static Vao* createVao(const Material& mtl,
+		const VboArray& vbos,
+		const PassLevelKey& key);
+};
+
+
 /// Model is an entity that acts as a container for other resources. Models are
 /// all the non static objects in a map.
 ///

+ 0 - 106
anki/resource/ModelPatch.cpp

@@ -1,106 +0,0 @@
-#include "anki/resource/ModelPatch.h"
-#include "anki/resource/Mesh.h"
-#include "anki/resource/Material.h"
-#include "anki/resource/ShaderProgram.h"
-
-
-namespace anki {
-
-
-//==============================================================================
-ModelPatch::ModelPatch(const char* meshFName, const char* mtlFName)
-{
-	// Load
-	mesh.load(meshFName);
-	mtl.load(mtlFName);
-
-	// Create VAOs
-	VboArray vboArr;
-	for(uint i = 0; i < Mesh::VBOS_NUM; i++)
-	{
-		vboArr[i] = &mesh->getVbo((Mesh::Vbos)i);
-	}
-
-	createVaos(*mtl, vboArr, vaos, vaosHashMap);
-}
-
-
-//==============================================================================
-ModelPatch::~ModelPatch()
-{}
-
-
-//==============================================================================
-bool ModelPatch::supportsHwSkinning() const
-{
-	return mesh->hasVertWeights();
-}
-
-
-//==============================================================================
-Vao* ModelPatch::createVao(const Material& mtl,
-	const VboArray& vbos,
-	const PassLevelKey& key)
-{
-	Vao* vao = new Vao;
-
-	if(mtl.getShaderProgram(key).uniformVariableExists("position"))
-	{
-		ANKI_ASSERT(vbos[Mesh::VBO_VERT_POSITIONS] != NULL);
-
-		vao->attachArrayBufferVbo(*vbos[Mesh::VBO_VERT_POSITIONS],
-			0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
-	}
-
-	if(mtl.getShaderProgram(key).uniformVariableExists("normal"))
-	{
-		ANKI_ASSERT(vbos[Mesh::VBO_VERT_NORMALS] != NULL);
-
-		vao->attachArrayBufferVbo(*vbos[Mesh::VBO_VERT_NORMALS],
-			1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
-	}
-
-	if(mtl.getShaderProgram(key).uniformVariableExists("tangent"))
-	{
-		ANKI_ASSERT(vbos[Mesh::VBO_VERT_TANGENTS] != NULL);
-
-		vao->attachArrayBufferVbo(*vbos[Mesh::VBO_VERT_TANGENTS],
-			2, 4, GL_FLOAT, GL_FALSE, 0, NULL);
-	}
-
-	if(mtl.getShaderProgram(key).uniformVariableExists("texCoords"))
-	{
-		vao->attachArrayBufferVbo(*vbos[Mesh::VBO_TEX_COORDS],
-			3, 2, GL_FLOAT, GL_FALSE, 0, NULL);
-	}
-
-	vao->attachElementArrayBufferVbo(*vbos[Mesh::VBO_VERT_INDECES]);
-
-	return vao;
-}
-
-
-//==============================================================================
-void ModelPatch::createVaos(const Material& mtl,
-	const VboArray& vbos,
-	VaosContainer& vaos,
-	PassLevelToVaoHashMap& vaosHashMap)
-{
-	for(uint level = 0; level < mtl.getLevelsOfDetail(); ++level)
-	{
-		for(uint pass = 0; pass < mtl.getPasses().size(); ++pass)
-		{
-			PassLevelKey key(pass, level);
-
-			Vao* vao = createVao(mtl, vbos, key);
-
-			vaos.push_back(vao);
-			vaosHashMap[key] = vao;
-		}
-	}
-
-
-}
-
-
-} // end namespace

+ 0 - 70
anki/resource/ModelPatch.h

@@ -1,70 +0,0 @@
-#ifndef ANKI_RESOURCE_MODEL_PATCH_H
-#define ANKI_RESOURCE_MODEL_PATCH_H
-
-#include "anki/resource/Resource.h"
-#include "anki/resource/PassLevelKey.h"
-#include "anki/resource/Mesh.h"
-#include "anki/gl/Vao.h"
-#include <boost/ptr_container/ptr_vector.hpp>
-
-
-namespace anki {
-
-
-class Material;
-
-
-/// Its a chunk of a model. Its very important class and it binds the material
-/// with the mesh
-class ModelPatch
-{
-public:
-	typedef boost::ptr_vector<Vao> VaosContainer;
-	typedef PassLevelHashMap<Vao*>::Type PassLevelToVaoHashMap;
-	typedef boost::array<const Vbo*, Mesh::VBOS_NUM> VboArray;
-
-	ModelPatch(const char* meshFName, const char* mtlFName);
-	~ModelPatch();
-
-	/// @name Accessors
-	/// @{
-	const Mesh& getMesh() const
-	{
-		return *mesh;
-	}
-
-	const Material& getMaterial() const
-	{
-		return *mtl;
-	}
-	/// @}
-
-	bool supportsHwSkinning() const;
-
-	const Vao& getVao(const PassLevelKey& key) const
-	{
-		return *vaosHashMap.at(key);
-	}
-
-	static void createVaos(const Material& mtl,
-		const VboArray& vbos,
-		VaosContainer& vaos,
-		PassLevelToVaoHashMap& vaosHashMap);
-
-private:
-	MeshResourcePointer mesh; ///< The geometry
-	MaterialResourcePointer mtl; ///< Material
-
-	VaosContainer vaos;
-	PassLevelToVaoHashMap vaosHashMap;
-
-	static Vao* createVao(const Material& mtl,
-		const VboArray& vbos,
-		const PassLevelKey& key);
-};
-
-
-} // end namespace
-
-
-#endif

+ 2 - 2
anki/resource/ShaderProgramPrePreprocessor.h

@@ -67,7 +67,7 @@ protected:
 		int definedInLine;
 
 		Pragma()
-		:	definedInLine(-1)
+			: definedInLine(-1)
 		{}
 
 		Pragma(const std::string& definedInFile_, int definedInLine_)
@@ -102,7 +102,7 @@ protected:
 		int globalLine;
 
 		CodeBeginningPragma()
-		:	globalLine(-1)
+			: globalLine(-1)
 		{}
 	};
 

+ 1 - 1
anki/resource/Skin.cpp

@@ -6,7 +6,7 @@
 #include "anki/resource/Skeleton.h"
 #include "anki/resource/SkelAnim.h"
 #include "anki/resource/Mesh.h"
-#include "anki/resource/ModelPatch.h"
+#include "anki/resource/PassLevelKey.h"
 
 
 namespace anki {

+ 1 - 2
anki/scene/ModelPatchNode.cpp

@@ -2,7 +2,6 @@
 #include "anki/scene/ModelPatchNode.h"
 #include "anki/resource/Material.h"
 #include "anki/resource/MeshData.h"
-#include "anki/resource/ModelPatch.h"
 #include "anki/scene/ModelNode.h"
 #include "anki/scene/ModelNode.h"
 
@@ -12,7 +11,7 @@ namespace anki {
 
 //==============================================================================
 ModelPatchNode::ModelPatchNode(const ModelPatch& modelPatch, ModelNode& parent)
-:	PatchNode(modelPatch, SNF_NONE, parent)
+	: PatchNode(modelPatch, SNF_NONE, parent)
 {}
 
 

+ 1 - 1
anki/scene/PatchNode.h

@@ -5,7 +5,7 @@
 #include "anki/gl/Vbo.h"
 #include "anki/resource/Mesh.h" // For the Vbos enum
 #include "anki/resource/Resource.h"
-#include "anki/resource/ModelPatch.h"
+#include "anki/resource/Model.h"
 #include "anki/scene/RenderableNode.h"
 #include "anki/scene/MaterialRuntime.h"
 #include <boost/scoped_ptr.hpp>

+ 2 - 2
anki/scene/VisibilityInfo.h

@@ -18,8 +18,8 @@ class SpotLight;
 class VisibilityInfo
 {
 	public:
-		typedef std::deque<const RenderableNode*> RContainer;
-		typedef std::vector<const PointLight*> PLContainer;
+		typedef std::deque<RenderableNode*> RContainer;
+		typedef std::vector<PointLight*> PLContainer;
 		typedef std::vector<SpotLight*> SLContainer;
 
 		VisibilityInfo() {}

+ 1 - 1
anki/scene/VisibilityTester.cpp

@@ -186,7 +186,7 @@ void VisibilityTester::getRenderableNodesJobCallback(
 	uint count, from, to;
 	size_t nodesSize;
 
-	boost::array<const RenderableNode*, Scene::MAX_VISIBLE_NODES> msVisibles,
+	boost::array<RenderableNode*, Scene::MAX_VISIBLE_NODES> msVisibles,
 		bsVisibles;
 	uint msI = 0, bsI = 0;
 

+ 0 - 4
anki/script/ScriptManager.cpp

@@ -53,8 +53,6 @@ BOOST_PYTHON_MODULE(anki)
 namespace anki {
 
 
-//==============================================================================
-// init                                                                        =
 //==============================================================================
 void ScriptManager::init()
 {
@@ -70,8 +68,6 @@ void ScriptManager::init()
 }
 
 
-//==============================================================================
-// execScript                                                                  =
 //==============================================================================
 void ScriptManager::execScript(const char* script, const char* scriptName)
 {

+ 27 - 27
anki/script/ScriptManager.h

@@ -10,36 +10,36 @@ namespace anki {
 /// The scripting manager using Python
 class ScriptManager
 {
-	public:
-		ScriptManager() {init();}
-
-		/// Execute python script
-		/// @param script Script source
-		/// @return true on success
-		void execScript(const char* script, const char* scriptName = "unamed");
-
-		/// Expose a C++ variable to python
-		/// @param varName The name to referenced in python
-		/// @param var The actual variable
-		template<typename Type>
-		void exposeVar(const char* varName, Type* var);
-
-	private:
-		boost::python::object mainModule;
-		boost::python::object ankiModule;
-		boost::python::object mainNamespace;
-
-		void init();
+public:
+	ScriptManager()
+	{
+		init();
+	}
+
+	/// Execute python script
+	/// @param script Script source
+	/// @return true on success
+	void execScript(const char* script, const char* scriptName = "unamed");
+
+	/// Expose a C++ variable to python
+	/// @param varName The name to referenced in python
+	/// @param var The actual variable
+	template<typename Type>
+	void exposeVar(const char* varName, Type* var)
+	{
+		using namespace boost::python;
+		scope(ankiModule).attr(varName) = ptr(var);
+	}
+
+private:
+	boost::python::object mainModule;
+	boost::python::object ankiModule;
+	boost::python::object mainNamespace;
+
+	void init();
 };
 
 
-template<typename Type>
-inline void ScriptManager::exposeVar(const char* varName, Type* var)
-{
-	boost::python::scope(ankiModule).attr(varName) = boost::python::ptr(var);
-}
-
-
 } // end namespace
 
 

+ 14 - 0
anki/script/scene/MaterialRuntime.cpp

@@ -2,6 +2,20 @@
 #include "anki/scene/MaterialRuntime.h"
 
 
+WRAP(MaterialRuntimeVariable)
+{
+	class_<MaterialRuntimeVariable, noncopyable>("MaterialRuntimeVariable",
+		no_init)
+		/*.def("setValue", (void (MaterialRuntimeVariable::*)(const float&))
+			(&MaterialRuntimeVariable::setValue))
+		.def("setValue", (void (MaterialRuntimeVariable::*)(const Vec2&))
+			(&MaterialRuntimeVariable::setValue))
+		.def("setValue", (void (MaterialRuntimeVariable::*)(const Vec3&))
+			(&MaterialRuntimeVariable::setValue))*/
+	;
+}
+
+
 WRAP(MaterialRuntime)
 {
 	class_<MaterialRuntime, noncopyable>("MaterialRuntime", no_init)

+ 0 - 16
anki/script/scene/MaterialRuntimeVariable.cpp

@@ -1,16 +0,0 @@
-#include "anki/script/Common.h"
-#include "anki/scene/MaterialRuntimeVariable.h"
-
-
-WRAP(MaterialRuntimeVariable)
-{
-	class_<MaterialRuntimeVariable, noncopyable>("MaterialRuntimeVariable",
-		no_init)
-		.def("setValue", (void (MaterialRuntimeVariable::*)(const float&))
-			(&MaterialRuntimeVariable::setValue))
-		.def("setValue", (void (MaterialRuntimeVariable::*)(const Vec2&))
-			(&MaterialRuntimeVariable::setValue))
-		.def("setValue", (void (MaterialRuntimeVariable::*)(const Vec3&))
-			(&MaterialRuntimeVariable::setValue))
-	;
-}

+ 4 - 4
anki/ui/UiPainter.cpp

@@ -77,8 +77,8 @@ void UiPainter::drawText(const char* text)
 	// SProg (some)
 	sProg->bind();
 
-	sProg->getUniformVariableByName("texture").set(font->getMap(), 0);
-	sProg->getUniformVariableByName("color").set(col);
+	sProg->findUniformVariableByName("texture").set(font->getMap(), 0);
+	sProg->findUniformVariableByName("color").set(col);
 
 	// Vao
 	qVao.bind();
@@ -118,8 +118,8 @@ void UiPainter::drawText(const char* text)
 			trfM(1, 2) = p.y() + 2.0 * (font->getGlyphBearingY(cc) -
 				int(font->getGlyphHeight(cc))) / deviceSize.y();
 
-			sProg->getUniformVariableByName("transformation").set(trfM);
-			sProg->getUniformVariableByName("textureTranformation").set(
+			sProg->findUniformVariableByName("transformation").set(trfM);
+			sProg->findUniformVariableByName("textureTranformation").set(
 				font->getGlyphTextureMatrix(cc));
 
 			// Render