Jelajahi Sumber

Rebuilding the renderer

Panagiotis Christopoulos Charitos 13 tahun lalu
induk
melakukan
08a4519124

+ 22 - 2
anki/CMakeLists.txt

@@ -1,4 +1,24 @@
-project(anki)
+SET(ANKI_SUB_DIRS script renderer scene ui event 
+	input physics resource core misc gl collision math util)
 
-add_executable(anki main.cpp)
+SET(ANKI_LIBS "")
 
+FOREACH(TMP ${ANKI_SUB_DIRS})
+	ADD_SUBDIRECTORY(${TMP})
+	SET(ANKI_LIBS ${ANKI_LIBS} anki${TMP})
+ENDFOREACH()
+
+ADD_LIBRARY(anki)
+
+TARGET_LINK_LIBRARIES(anki ${ANKI_LIBS} BulletSoftBody BulletDynamics 
+	BulletCollision LinearMath GLEWmx GLU GL jpeg SDL png python${PYTHON_VER}
+	boost_system boost_python boost_filesystem boost_thread boost_regex 
+	freetype)
+
+SET_TARGET_PROPERTIES(anki PROPERTIES LINKER_LANGUAGE CXX)
+
+# Install
+#
+INSTALL(TARGETS anki DESTINATION ${LIB_INSTALL_DIR})
+
+INSTALL(DIRECTORY ${ANKI_PROJECT_SOURCE_DIR}/anki DESTINATION "${INCLUDE_INSTALL_DIR}" FILES_MATCHING PATTERN "*.h" PATTERN .svn EXCLUDE)

+ 0 - 117
anki/renderer/CollisionDbgDrawer.cpp

@@ -1,117 +0,0 @@
-#include "anki/renderer/CollisionDbgDrawer.h"
-#include "anki/renderer/Dbg.h"
-#include "anki/collision/Collision.h"
-
-
-namespace anki {
-
-
-//==============================================================================
-void CollisionDbgDrawer::visit(const Sphere& sphere)
-{
-	dbg->setModelMat(Mat4(sphere.getCenter(), Mat3::getIdentity(), 1.0));
-	dbg->drawSphere(sphere.getRadius());
-}
-
-
-//==============================================================================
-void CollisionDbgDrawer::visit(const Obb& obb)
-{
-	Mat4 scale(Mat4::getIdentity());
-	scale(0, 0) = obb.getExtend().x();
-	scale(1, 1) = obb.getExtend().y();
-	scale(2, 2) = obb.getExtend().z();
-
-	Mat4 rot(obb.getRotation());
-
-	Mat4 trs(obb.getCenter());
-
-	Mat4 tsl;
-	tsl = Mat4::combineTransformations(rot, scale);
-	tsl = Mat4::combineTransformations(trs, tsl);
-
-	dbg->setModelMat(tsl);
-	dbg->setColor(Vec3(1.0, 1.0, 0.0));
-	dbg->drawCube(2.0);
-}
-
-
-//==============================================================================
-void CollisionDbgDrawer::visit(const Plane& plane)
-{
-	const Vec3& n = plane.getNormal();
-	const float& o = plane.getOffset();
-	Quat q;
-	q.setFrom2Vec3(Vec3(0.0, 0.0, 1.0), n);
-	Mat3 rot(q);
-	rot.rotateXAxis(Math::PI / 2);
-	Mat4 trf(n * o, rot);
-
-	dbg->setModelMat(trf);
-	dbg->renderGrid();
-}
-
-
-//==============================================================================
-void CollisionDbgDrawer::visit(const Aabb& aabb)
-{
-	const Vec3& min = aabb.getMin();
-	const Vec3& max = aabb.getMax();
-
-	Mat4 trf = Mat4::getIdentity();
-	// Scale
-	for(uint i = 0; i < 3; ++i)
-	{
-		trf(i, i) = max[i] - min[i];
-	}
-
-	// Translation
-	trf.setTranslationPart((max + min) / 2.0);
-
-	dbg->setModelMat(trf);
-	dbg->drawCube();
-}
-
-
-//==============================================================================
-void CollisionDbgDrawer::visit(const Frustum& f)
-{
-	switch(f.getFrustumType())
-	{
-		case Frustum::FT_ORTHOGRAPHIC:
-			visit(static_cast<const OrthographicFrustum&>(f).getObb());
-			break;
-		case Frustum::FT_PERSPECTIVE:
-		{
-			dbg->setColor(Vec4(1.0, 0.0, 1.0, 1.0));
-			const PerspectiveFrustum& pf = 
-				static_cast<const PerspectiveFrustum&>(f);
-
-			float camLen = pf.getFar();
-			float tmp0 = camLen / tan((Math::PI - pf.getFovX()) * 0.5) + 0.001;
-			float tmp1 = camLen * tan(pf.getFovY() * 0.5) + 0.001;
-
-			Vec3 points[] = {
-				Vec3(0.0, 0.0, 0.0), // 0: eye point
-				Vec3(-tmp0, tmp1, -camLen), // 1: top left
-				Vec3(-tmp0, -tmp1, -camLen), // 2: bottom left
-				Vec3(tmp0, -tmp1, -camLen), // 3: bottom right
-				Vec3(tmp0, tmp1, -camLen) // 4: top right
-			};
-
-			const uint indeces[] = {0, 1, 0, 2, 0, 3, 0, 4, 1, 2, 2,
-				3, 3, 4, 4, 1};
-
-			dbg->begin();
-			for(uint i = 0; i < sizeof(indeces) / sizeof(uint); i++)
-			{
-				dbg->pushBackVertex(points[indeces[i]]);
-			}
-			dbg->end();
-			break;
-		}
-	}
-}
-
-
-} // end namespace

+ 0 - 52
anki/renderer/CollisionDbgDrawer.h

@@ -1,52 +0,0 @@
-#ifndef ANKI_RENDERER_COLLISION_DBG_DRAWER_H
-#define ANKI_RENDERER_COLLISION_DBG_DRAWER_H
-
-#include "anki/collision/CollisionShape.h"
-#include "anki/util/Assert.h"
-
-
-namespace anki {
-
-
-class Dbg;
-
-
-/// Contains methods to render the collision shapes
-class CollisionDbgDrawer: public CollisionShape::ConstVisitor
-{
-public:
-	/// Constructor
-	CollisionDbgDrawer(Dbg* dbg_)
-		: dbg(dbg_)
-	{}
-
-	void visit(const LineSegment&)
-	{
-		/// XXX
-		ANKI_ASSERT(0 && "ToDo");
-	}
-
-	void visit(const Obb&);
-
-	void visit(const Frustum&);
-
-	void visit(const Plane&);
-
-	void visit(const Ray&)
-	{
-		ANKI_ASSERT(0 && "ToDo");
-	}
-
-	void visit(const Sphere&);
-
-	void visit(const Aabb&);
-
-private:
-	Dbg* dbg; ///< The debug stage
-};
-
-
-} // end namespace
-
-
-#endif

+ 2 - 381
anki/renderer/Dbg.cpp

@@ -1,8 +1,6 @@
 #include "anki/renderer/Dbg.h"
 #include "anki/renderer/Renderer.h"
-#include "anki/renderer/CollisionDbgDrawer.h"
 #include "anki/renderer/RendererInitializer.h"
-#include "anki/renderer/SceneDbgDrawer.h"
 
 
 namespace anki {
@@ -10,175 +8,10 @@ namespace anki {
 
 //==============================================================================
 Dbg::Dbg(Renderer& r_)
-	: SwitchableRenderingPass(r_), flags(),
-		sceneDbgDrawer(*this), collisionDbgDrawer(*this)
+	: SwitchableRenderingPass(r_)
 {}
 
 
-//==============================================================================
-// drawLine                                                                    =
-//==============================================================================
-void Dbg::drawLine(const Vec3& from, const Vec3& to, const Vec4& color)
-{
-	setColor(color);
-	begin();
-		pushBackVertex(from);
-		pushBackVertex(to);
-	end();
-}
-
-
-//==============================================================================
-// renderGrid                                                                  =
-//==============================================================================
-void Dbg::renderGrid()
-{
-	Vec4 col0(0.5, 0.5, 0.5, 1.0);
-	Vec4 col1(0.0, 0.0, 1.0, 1.0);
-	Vec4 col2(1.0, 0.0, 0.0, 1.0);
-
-	const float SPACE = 1.0; // space between lines
-	const int NUM = 57;  // lines number. must be odd
-
-	const float GRID_HALF_SIZE = ((NUM - 1) * SPACE / 2);
-
-	setColor(col0);
-
-	begin();
-
-	for(int x = - NUM / 2 * SPACE; x < NUM / 2 * SPACE; x += SPACE)
-	{
-		setColor(col0);
-
-		// if the middle line then change color
-		if(x == 0)
-		{
-			setColor(col1);
-		}
-
-		// line in z
-		pushBackVertex(Vec3(x, 0.0, -GRID_HALF_SIZE));
-		pushBackVertex(Vec3(x, 0.0, GRID_HALF_SIZE));
-
-		// if middle line change col so you can highlight the x-axis
-		if(x == 0)
-		{
-			setColor(col2);
-		}
-
-		// line in the x
-		pushBackVertex(Vec3(-GRID_HALF_SIZE, 0.0, x));
-		pushBackVertex(Vec3(GRID_HALF_SIZE, 0.0, x));
-	}
-
-	// render
-	end();
-}
-
-
-//==============================================================================
-// drawSphere                                                                  =
-//==============================================================================
-void Dbg::drawSphere(float radius, int complexity)
-{
-	std::vector<Vec3>* sphereLines;
-
-	//
-	// Pre-calculate the sphere points5
-	//
-	std::map<uint, std::vector<Vec3> >::iterator it =
-		complexityToPreCalculatedSphere.find(complexity);
-
-	if(it != complexityToPreCalculatedSphere.end()) // Found
-	{
-		sphereLines = &(it->second);
-	}
-	else // Not found
-	{
-		complexityToPreCalculatedSphere[complexity] = std::vector<Vec3>();
-		sphereLines = &complexityToPreCalculatedSphere[complexity];
-
-		float fi = Math::PI / complexity;
-
-		Vec3 prev(1.0, 0.0, 0.0);
-		for(float th = fi; th < Math::PI * 2.0 + fi; th += fi)
-		{
-			Vec3 p = Mat3(Euler(0.0, th, 0.0)) * Vec3(1.0, 0.0, 0.0);
-
-			for(float th2 = 0.0; th2 < Math::PI; th2 += fi)
-			{
-				Mat3 rot(Euler(th2, 0.0, 0.0));
-
-				Vec3 rotPrev = rot * prev;
-				Vec3 rotP = rot * p;
-
-				sphereLines->push_back(rotPrev);
-				sphereLines->push_back(rotP);
-
-				Mat3 rot2(Euler(0.0, 0.0, Math::PI / 2));
-
-				sphereLines->push_back(rot2 * rotPrev);
-				sphereLines->push_back(rot2 * rotP);
-			}
-
-			prev = p;
-		}
-	}
-
-
-	//
-	// Render
-	//
-	modelMat = modelMat * Mat4(Vec3(0.0), Mat3::getIdentity(), radius);
-
-	begin();
-	BOOST_FOREACH(const Vec3& p, *sphereLines)
-	{
-		if(pointIndex >= MAX_POINTS_PER_DRAW)
-		{
-			end();
-			begin();
-		}
-
-		pushBackVertex(p);
-	}
-	end();
-}
-
-
-//==============================================================================
-// renderCube                                                                  =
-//==============================================================================
-void Dbg::drawCube(float size)
-{
-	Vec3 maxPos = Vec3(0.5 * size);
-	Vec3 minPos = Vec3(-0.5 * size);
-
-	boost::array<Vec3, 8> points = {{
-		Vec3(maxPos.x(), maxPos.y(), maxPos.z()),  // right top front
-		Vec3(minPos.x(), maxPos.y(), maxPos.z()),  // left top front
-		Vec3(minPos.x(), minPos.y(), maxPos.z()),  // left bottom front
-		Vec3(maxPos.x(), minPos.y(), maxPos.z()),  // right bottom front
-		Vec3(maxPos.x(), maxPos.y(), minPos.z()),  // right top back
-		Vec3(minPos.x(), maxPos.y(), minPos.z()),  // left top back
-		Vec3(minPos.x(), minPos.y(), minPos.z()),  // left bottom back
-		Vec3(maxPos.x(), minPos.y(), minPos.z())   // right bottom back
-	}};
-
-	boost::array<uint, 24> indeces = {{0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6,
-		7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7}};
-
-	begin();
-		BOOST_FOREACH(uint id, indeces)
-		{
-			pushBackVertex(points[id]);
-		}
-	end();
-}
-
-
-//==============================================================================
-// init                                                                        =
 //==============================================================================
 void Dbg::init(const RendererInitializer& initializer)
 {
@@ -206,38 +39,9 @@ void Dbg::init(const RendererInitializer& initializer)
 	{
 		throw ANKI_EXCEPTION("Cannot create debug FBO") << e;
 	}
-
-	//
-	// Shader prog
-	//
-	sProg.load("shaders/Dbg.glsl");
-
-	//
-	// VAO & VBOs
-	//
-	positionsVbo.create(GL_ARRAY_BUFFER, sizeof(positions), NULL,
-		GL_DYNAMIC_DRAW);
-	colorsVbo.create(GL_ARRAY_BUFFER, sizeof(colors), NULL, GL_DYNAMIC_DRAW);
-	vao.create();
-	const int positionAttribLoc = 0;
-	vao.attachArrayBufferVbo(positionsVbo, positionAttribLoc, 3, GL_FLOAT,
-		GL_FALSE, 0, NULL);
-	const int colorAttribLoc = 1;
-	vao.attachArrayBufferVbo(colorsVbo, colorAttribLoc, 3, GL_FLOAT, GL_FALSE,
-		0, NULL);
-
-	//
-	// Rest
-	//
-	pointIndex = 0;
-	ANKI_CHECK_GL_ERROR();
-	modelMat.setIdentity();
-	crntCol = Vec3(1.0, 0.0, 0.0);
 }
 
 
-//==============================================================================
-// runStage                                                                    =
 //==============================================================================
 void Dbg::run()
 {
@@ -246,190 +50,7 @@ void Dbg::run()
 		return;
 	}
 
-	fbo.bind();
-	sProg->bind();
-
-	// OGL stuff
-	GlStateMachineSingleton::get().setViewport(0, 0,
-		r.getWidth(), r.getHeight());
-	GlStateMachineSingleton::get().enable(GL_DEPTH_TEST, true);
-	GlStateMachineSingleton::get().enable(GL_BLEND, false);
-
-	setModelMat(Mat4::getIdentity());
-	renderGrid();
-
-	BOOST_FOREACH(const SceneNode* node,
-		SceneSingleton::get().getAllNodes())
-	{
-		if(!node->isFlagEnabled(SceneNode::SNF_VISIBLE))
-		{
-			continue;
-		}
-
-
-		switch(node->getSceneNodeType())
-		{
-			case SceneNode::SNT_CAMERA:
-				sceneDbgDrawer.drawCamera(static_cast<const Camera&>(*node));
-				break;
-			case SceneNode::SNT_LIGHT:
-				sceneDbgDrawer.drawLight(static_cast<const Light&>(*node));
-				break;
-			case SceneNode::SNT_PARTICLE_EMITTER_NODE:
-				sceneDbgDrawer.drawParticleEmitter(
-					static_cast<const ParticleEmitterNode&>(*node));
-				break;
-			case SceneNode::SNT_RENDERABLE_NODE:
-				/*if(showVisibilityBoundingShapesFlag)
-				{
-					const RenderableNode& rnode =
-						static_cast<const RenderableNode&>(*node);
-					collisionDbgDrawer.draw(rnode. getVisibilityShapeWSpace());
-				}*/
-				break;
-			case SceneNode::SNT_SKIN_NODE:
-			{
-				/*const SkinNode& node_ = static_cast<const SkinNode&>(*node);
-				sceneDbgDrawer.drawSkinNodeSkeleton(node_);
-				if(showVisibilityBoundingShapesFlag)
-				{
-					collisionDbgDrawer.draw(node_.getVisibilityShapeWSpace());
-				}*/
-				break;
-			}
-			default:
-				break;
-		}
-	}
-
-	///////////////
-	/*setColor(Vec3(1));
-	Obb obb(Vec3(0.0), Mat3::getIdentity(), Vec3(1.0, 2.0, 1.0));
-	Obb obb2(Vec3(0.0), Mat3::getIdentity(), Vec3(1.0, 1.5, 1.0));
-	obb = obb.getTransformed(SceneSingleton::get().getAllNodes()[1]->
-		getWorldTransform());
-	collisionDbgDrawer.draw(obb.getCompoundShape(obb2));
-	collisionDbgDrawer.draw(obb);
-	collisionDbgDrawer.draw(obb2);
-
-	setModelMat(Mat4::getIdentity());
-	boost::array<Vec3, 8> points;
-	obb.getExtremePoints(points);
-	setColor(Vec3(1, 0, 0));
-	begin();
-
-	enum
-	{
-		RTF,
-		LTF,
-		LBF,
-		RBF,
-		RTB,
-		LTB,
-		LBB,
-		RBB
-	};
-
-	Vec3 xAxis = obb.getRotation().getColumn(0);
-	Vec3 yAxis = obb.getRotation().getColumn(1);
-	Vec3 zAxis = obb.getRotation().getColumn(2);
-
-	Vec3 er = obb.getRotation() * obb.getExtend();
-
-	boost::array<uint, 24> indeces = {{0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6,
-		7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7}};
-
-	BOOST_FOREACH(uint id, indeces)
-	{
-		pushBackVertex(points[id]);
-	}
-	end();*/
-	///////////////
-
-
-	/*Octree* octree = new Octree(Aabb(Vec3(-10.0), Vec3(10.0)), 10);
-
-
-	Aabb aabb(horse->getModel().getVisibilityCollisionShape());
-	aabb.transform(horse->getWorldTransform());
-
-	OctreeNode* where = octree->place(aabb);
-
-	sceneDbgDrawer.drawOctree(*octree);
-	CollisionDbgDrawer vis(*this);
-	aabb.accept(vis);
-
-	if(where)
-	{
-		setColor(Vec3(1.0, 0.0, 0.0));
-		Aabb whereaabb = where->getAabb();
-		whereaabb.transform(Transform(Vec3(0.0), Mat3::getIdentity(), 0.99));
-		whereaabb.accept(vis);
-	}
-
-	delete octree;
-
-
-	SceneSingleton::get().getPhysWorld().getWorld().debugDrawWorld();*/
-
-	// Physics
-	/*glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-	setModelMat(Mat4::getIdentity());
-	app->getScene().getPhysics().debugDraw();
-	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);*/
-}
-
-
-//==============================================================================
-// setModelMat                                                                 =
-//==============================================================================
-void Dbg::setModelMat(const Mat4& modelMat_)
-{
-	ANKI_ASSERT(pointIndex == 0); // This means that the func called after begin
-	                         // and before end
-	modelMat = modelMat_;
-}
-
-
-//==============================================================================
-// begin                                                                       =
-//==============================================================================
-void Dbg::begin()
-{
-	ANKI_ASSERT(pointIndex == 0);
-}
-
-
-//==============================================================================
-// end                                                                         =
-//==============================================================================
-void Dbg::end()
-{
-	ANKI_ASSERT(pointIndex != 0);
-
-	positionsVbo.write(&positions[0], 0, sizeof(Vec3) * pointIndex);
-	colorsVbo.write(&colors[0], 0, sizeof(Vec3) * pointIndex);
-
-	Mat4 pmv = r.getViewProjectionMat() * modelMat;
-	sProg->findUniformVariableByName("modelViewProjectionMat").set(pmv);
-
-	vao.bind();
-	glDrawArrays(GL_LINES, 0, pointIndex);
-	vao.unbind();
-
-	// Cleanup
-	pointIndex = 0;
-}
-
-
-//==============================================================================
-// pushBackVertex                                                              =
-//==============================================================================
-void Dbg::pushBackVertex(const Vec3& pos)
-{
-	positions[pointIndex] = pos;
-	colors[pointIndex] = crntCol;
-	++pointIndex;
+	/// TODO
 }
 
 

+ 1 - 42
anki/renderer/Dbg.h

@@ -5,13 +5,7 @@
 #include <map>
 #include "anki/renderer/RenderingPass.h"
 #include "anki/gl/Fbo.h"
-#include "anki/resource/ShaderProgram.h"
-#include "anki/resource/Resource.h"
-#include "anki/math/Math.h"
-#include "anki/gl/Vbo.h"
-#include "anki/gl/Vao.h"
-#include "anki/renderer/SceneDbgDrawer.h"
-#include "anki/renderer/CollisionDbgDrawer.h"
+#include "anki/renderer/Drawer.h"
 
 
 namespace anki {
@@ -25,44 +19,9 @@ public:
 	
 	void init(const RendererInitializer& initializer);
 	void run();
-	
-	void renderGrid();
-	void drawSphere(float radius, int complexity = 4);
-	void drawCube(float size = 1.0);
-	void drawLine(const Vec3& from, const Vec3& to, const Vec4& color);
-
-	/// @name Render functions. Imitate the GL 1.1 immediate mode
-	/// @{
-	void begin(); ///< Initiates the draw
-	void end(); ///< Draws
-	void pushBackVertex(const Vec3& pos); ///< Something like glVertex
-	/// Something like glColor
-	void setColor(const Vec3& col) {crntCol = col;}
-	/// Something like glColor
-	void setColor(const Vec4& col) {crntCol = Vec3(col);}
-	void setModelMat(const Mat4& modelMat);
-	/// @}
 
 private:
-	uint flags;
 	Fbo fbo;
-	ShaderProgramResourcePointer sProg;
-	static const uint MAX_POINTS_PER_DRAW = 256;
-	boost::array<Vec3, MAX_POINTS_PER_DRAW> positions;
-	boost::array<Vec3, MAX_POINTS_PER_DRAW> colors;
-	Mat4 modelMat;
-	uint pointIndex;
-	Vec3 crntCol;
-	Vbo positionsVbo;
-	Vbo colorsVbo;
-	Vao vao;
-	SceneDbgDrawer sceneDbgDrawer;
-	CollisionDbgDrawer collisionDbgDrawer;
-
-	/// This is a container of some precalculated spheres. Its a map that
-	/// from sphere complexity it returns a vector of lines (Vec3s in
-	/// pairs)
-	std::map<uint, std::vector<Vec3>> complexityToPreCalculatedSphere;
 };
 
 

+ 15 - 34
anki/renderer/Deformer.cpp

@@ -1,7 +1,6 @@
 #include "anki/renderer/Deformer.h"
 #include "anki/resource/ShaderProgram.h"
 #include "anki/resource/Material.h"
-#include "anki/scene/SkinPatchNode.h"
 #include "anki/scene/SkinNode.h"
 #include "anki/renderer/MainRenderer.h"
 
@@ -10,26 +9,13 @@ namespace anki {
 
 
 //==============================================================================
-// Constructors & destructor                                                   =
-//==============================================================================
-
-Deformer::Deformer(const MainRenderer& mainR_)
-:	mainR(mainR_)
-{
-	init();
-}
-
-
 Deformer::~Deformer()
 {}
 
 
-//==============================================================================
-// init                                                                        =
 //==============================================================================
 void Deformer::init()
 {
-	//
 	// Load the shaders
 	//
 	tfHwSkinningAllSProg.load("shaders/TfHwSkinningPosNormTan.glsl");
@@ -38,26 +24,20 @@ void Deformer::init()
 
 
 //==============================================================================
-// deform                                                                      =
-//==============================================================================
-void Deformer::deform(SkinPatchNode& node) const
+void Deformer::deform(SkinNode& skinNode, SkinPatchNode& node) const
 {
-	ANKI_ASSERT(node.getParent() != NULL); // The SkinPatchNodes always have parent
-	ANKI_ASSERT(node.getParent()->getSceneNodeType() ==
-		SceneNode::SNT_SKIN_NODE); // And their parent must be SkinNode
-	ANKI_ASSERT(node.isFlagEnabled(SceneNode::SNF_VISIBLE)); // And it should be
-	                                                    // visible
-
-	SkinNode* skinNode = static_cast<SkinNode*>(node.getParent());
+	ANKI_ASSERT(node.getMovable()->getParent() != NULL
+		&& "The SkinPatchNode should always have parent");
 
 	GlStateMachineSingleton::get().enable(GL_RASTERIZER_DISCARD);
 
 	// Chose sProg
+	//
 	const ShaderProgram* sProg;
-	const Material& mtl = node.getModelPatchRsrc().getMaterial();
+	const Material& mtl = node.getMaterial();
 
-	if(mtl.variableExistsAndInKey("normal", PassLevelKey(0, 0)) &&
-	   mtl.variableExistsAndInKey("tangent", PassLevelKey(0, 0)))
+	if(mtl.variableExistsAndInKey("normal", PassLevelKey(0, 0))
+		&& mtl.variableExistsAndInKey("tangent", PassLevelKey(0, 0)))
 	{
 		sProg = tfHwSkinningAllSProg.get();
 	}
@@ -69,31 +49,32 @@ void Deformer::deform(SkinPatchNode& node) const
 	sProg->bind();
 
 	// Uniforms
+	//
 	sProg->findUniformVariableByName("skinningRotations").set(
-		&skinNode->getBoneRotations()[0], skinNode->getBoneRotations().size());
+		&skinNode.getBoneRotations()[0], skinNode.getBoneRotations().size());
 
 	sProg->findUniformVariableByName("skinningTranslations").set(
-		&skinNode->getBoneTranslations()[0],
-		skinNode->getBoneTranslations().size());
+		&skinNode.getBoneTranslations()[0],
+		skinNode.getBoneTranslations().size());
 
 	node.getTfVao().bind();
 
 	// TF
 	glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0,
-		node.getTfVbo(SkinPatchNode::TFV_POSITIONS).getGlId());
+		node.getSkinMesh().getTfVbo(SkinMesh::VBO_TF_POSITIONS)->getGlId());
 
 	if(sProg == tfHwSkinningAllSProg.get())
 	{
 		glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 1,
-			node.getTfVbo(SkinPatchNode::TFV_NORMALS).getGlId());
+			node.getSkinMesh().getTfVbo(SkinMesh::VBO_TF_NORMALS)->getGlId());
 		glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 2,
-			node.getTfVbo(SkinPatchNode::TFV_TANGENTS).getGlId());
+			node.getSkinMesh().getTfVbo(SkinMesh::VBO_TF_TANGENTS)->getGlId());
 	}
 
 	//glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, this->Query);
 	glBeginTransformFeedback(GL_POINTS);
 		glDrawArrays(GL_POINTS, 0,
-			node.getModelPatchRsrc().getMesh().getVertsNum());
+			node.getSkinMesh().getVerticesNumber(0));
 	glEndTransformFeedback();
 	//glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
 

+ 5 - 4
anki/renderer/Deformer.h

@@ -9,7 +9,6 @@ namespace anki {
 
 class ShaderProgram;
 class SkinPatchNode;
-class MainRenderer;
 
 
 /// SkinPatchNode deformer. It gets a SkinPatchNode and using transform
@@ -17,13 +16,15 @@ class MainRenderer;
 class Deformer
 {
 	public:
-		Deformer(const MainRenderer& mainR);
+		Deformer()
+		{
+			init();
+		}
 		~Deformer();
 
-		void deform(SkinPatchNode& node) const;
+		void deform(SkinPatchNode& node, SkinPatchNode& subNode) const;
 
 	private:
-		const MainRenderer& mainR; ///< Know your father
 		ShaderProgramResourcePointer tfHwSkinningAllSProg;
 		ShaderProgramResourcePointer tfHwSkinningPosSProg;
 

+ 63 - 15
anki/renderer/Drawer.cpp

@@ -4,6 +4,10 @@
 #include "anki/collision/Collision.h"
 #include "anki/scene/Frustumable.h"
 #include "anki/scene/Octree.h"
+#include "anki/resource/Material.h"
+#include "anki/scene/Renderable.h"
+#include "anki/scene/Camera.h"
+#include "anki/scene/ModelNode.h"
 
 
 namespace anki {
@@ -232,11 +236,11 @@ void DebugDrawer::pushBackVertex(const Vec3& pos)
 
 
 //==============================================================================
-// CollisionDbgDrawer                                                          =
+// CollisionDebugDrawer                                                        =
 //==============================================================================
 
 //==============================================================================
-void CollisionDbgDrawer::visit(const Sphere& sphere)
+void CollisionDebugDrawer::visit(const Sphere& sphere)
 {
 	dbg->setModelMat(Mat4(sphere.getCenter(), Mat3::getIdentity(), 1.0));
 	dbg->drawSphere(sphere.getRadius());
@@ -244,7 +248,7 @@ void CollisionDbgDrawer::visit(const Sphere& sphere)
 
 
 //==============================================================================
-void CollisionDbgDrawer::visit(const Obb& obb)
+void CollisionDebugDrawer::visit(const Obb& obb)
 {
 	Mat4 scale(Mat4::getIdentity());
 	scale(0, 0) = obb.getExtend().x();
@@ -266,7 +270,7 @@ void CollisionDbgDrawer::visit(const Obb& obb)
 
 
 //==============================================================================
-void CollisionDbgDrawer::visit(const Plane& plane)
+void CollisionDebugDrawer::visit(const Plane& plane)
 {
 	const Vec3& n = plane.getNormal();
 	const float& o = plane.getOffset();
@@ -282,7 +286,7 @@ void CollisionDbgDrawer::visit(const Plane& plane)
 
 
 //==============================================================================
-void CollisionDbgDrawer::visit(const Aabb& aabb)
+void CollisionDebugDrawer::visit(const Aabb& aabb)
 {
 	const Vec3& min = aabb.getMin();
 	const Vec3& max = aabb.getMax();
@@ -303,7 +307,7 @@ void CollisionDbgDrawer::visit(const Aabb& aabb)
 
 
 //==============================================================================
-void CollisionDbgDrawer::visit(const Frustum& f)
+void CollisionDebugDrawer::visit(const Frustum& f)
 {
 	switch(f.getFrustumType())
 	{
@@ -449,7 +453,7 @@ void SceneDebugDrawer::draw(const Frustumable& fr) const
 {
 	const Frustum& fs = fr.getFrustum();
 
-	CollisionDbgDrawer coldraw(dbg);
+	CollisionDebugDrawer coldraw(dbg);
 	fs.accept(coldraw);
 }
 
@@ -459,7 +463,7 @@ void SceneDebugDrawer::draw(const Spatial& x) const
 {
 	const CollisionShape& cs = x.getSpatialCollisionShape();
 
-	CollisionDbgDrawer coldraw(dbg);
+	CollisionDebugDrawer coldraw(dbg);
 	cs.accept(coldraw);
 }
 
@@ -479,7 +483,7 @@ void SceneDebugDrawer::draw(const OctreeNode& octnode, uint depth,
 	Vec3 color = Vec3(1.0 - float(depth) / float(octree.getMaxDepth()));
 	dbg->setColor(color);
 
-	CollisionDbgDrawer v(dbg);
+	CollisionDebugDrawer v(dbg);
 	octnode.getAabb().accept(v);
 
 	// Children
@@ -511,7 +515,7 @@ struct SetUniformVisitor: public boost::static_visitor<void>
 
 	void operator()(const TextureResourcePointer& x) const
 	{
-		uni->set(*x, *texUnit++);
+		uni->set(*x, (*texUnit)++);
 	}
 
 };
@@ -521,11 +525,11 @@ struct SetUniformVisitor: public boost::static_visitor<void>
 void SceneDrawer::setupShaderProg(
 	const PassLevelKey& key,
 	const Camera& cam,
-	Renderable& renderable)
+	SceneNode& renderable)
 {
-	const Material& mtl = renderable.getMaterial();
+	const Material& mtl = renderable.getRenderable()->getMaterial();
 	const ShaderProgram& sprog = mtl.getShaderProgram(key);
-	uint textunit = 0;
+	uint texunit = 0;
 
 	sprog.bind();
 	
@@ -534,11 +538,55 @@ void SceneDrawer::setupShaderProg(
 
 	for(const MaterialVariable& mv : mtl.getVariables())
 	{
-		vis.uni = &mv.getShaderProgramUniformVariable(key);
+		if(!mv.inPass(key))
+		{
+			continue;
+		}
+
+		const ShaderProgramUniformVariable& uni = 
+			mv.getShaderProgramUniformVariable(key);
+
+		vis.uni = &uni;
+		const std::string& name = uni.getName();
+
+		if(name == "modelViewProjectionMat")
+		{
+			Mat4 mvp = 
+				Mat4(renderable.findPropertyBaseByName("worldTransform").
+				getValue<Transform>()) 
+				* cam.getViewMatrix() * cam.getProjectionMatrix();
 
-		boost::visit(vis, mv.getVariant());
+			uni.set(mvp);
+		}
+		else
+		{
+			boost::apply_visitor(vis, mv.getVariant());
+		}
 	}
 }
 
 
+//==============================================================================
+void SceneDrawer::render(const Camera& cam, uint pass, 
+	SceneNode& node) 
+{
+	/*float dist = (node.getWorldTransform().getOrigin() -
+		cam.getWorldTransform().getOrigin()).getLength();
+	uint lod = std::min(r.calculateLod(dist), mtl.getLevelsOfDetail() - 1);*/
+
+	PassLevelKey key(pass, 0);
+
+	// Setup shader
+	setupShaderProg(key, cam, node);
+
+	// Render
+	uint indecesNum = 
+		node.getRenderable()->getModelPatchBase().getIndecesNumber(0);
+
+	node.getRenderable()->getModelPatchBase().getVao(key).bind();
+	glDrawElements(GL_TRIANGLES, indecesNum, GL_UNSIGNED_SHORT, 0);
+	node.getRenderable()->getModelPatchBase().getVao(key).unbind();
+}
+
+
 }  // namespace anki

+ 7 - 4
anki/renderer/Drawer.h

@@ -75,11 +75,11 @@ private:
 
 
 /// Contains methods to render the collision shapes
-class CollisionDbgDrawer: public CollisionShape::ConstVisitor
+class CollisionDebugDrawer: public CollisionShape::ConstVisitor
 {
 public:
 	/// Constructor
-	CollisionDbgDrawer(DebugDrawer* dbg_)
+	CollisionDebugDrawer(DebugDrawer* dbg_)
 		: dbg(dbg_)
 	{}
 
@@ -207,6 +207,9 @@ private:
 };
 
 
+class PassLevelKey;
+
+
 /// It includes all the functions to render a Renderable
 class SceneDrawer
 {
@@ -217,7 +220,7 @@ public:
 	{}
 
 	void render(const Camera& cam,
-		uint pass, Renderable& renderable);
+		uint pass, SceneNode& renderable);
 
 private:
 	Renderer* r;
@@ -225,7 +228,7 @@ private:
 	void setupShaderProg(
 		const PassLevelKey& key,
 		const Camera& cam,
-		Renderable& renderable);
+		SceneNode& renderable);
 };
 
 

+ 1 - 356
anki/renderer/Is.cpp

@@ -1,19 +1,5 @@
 #include "anki/renderer/Is.h"
 #include "anki/renderer/Renderer.h"
-#include "anki/scene/Camera.h"
-#include "anki/scene/Light.h"
-#include "anki/scene/PointLight.h"
-#include "anki/scene/SpotLight.h"
-#include "anki/resource/LightRsrc.h"
-#include "anki/core/App.h"
-#include "anki/resource/LightRsrc.h"
-#include "anki/renderer/Sm.h"
-#include "anki/renderer/Smo.h"
-#include "anki/scene/Scene.h"
-
-#include <boost/lexical_cast.hpp>
-#include <boost/foreach.hpp>
-#include <boost/array.hpp>
 
 
 #define BLEND_ENABLE true
@@ -22,357 +8,16 @@
 namespace anki {
 
 
-//==============================================================================
-// Constructor                                                                 =
 //==============================================================================
 Is::Is(Renderer& r_)
 	: RenderingPass(r_), sm(r_), smo(r_)
 {}
 
 
-//==============================================================================
-// initFbo                                                                     =
-//==============================================================================
-void Is::initFbo()
-{
-	try
-	{
-		// create FBO
-		fbo.create();
-		fbo.bind();
-
-		// inform in what buffers we draw
-		fbo.setNumOfColorAttachements(1);
-
-		// create the FAI
-		Renderer::createFai(r.getWidth(), r.getHeight(), GL_RGB, GL_RGB,
-			GL_FLOAT, fai);
-
-		// attach
-		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
-			GL_TEXTURE_2D, fai.getGlId(), 0);
-		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
-			GL_TEXTURE_2D, copyMsDepthFai.getGlId(), 0);
-
-		// test if success
-		fbo.checkIfGood();
-
-		// unbind
-		fbo.unbind();
-	}
-	catch(std::exception& e)
-	{
-		throw ANKI_EXCEPTION("Cannot create deferred shading illumination "
-			"stage FBO") << e;
-	}
-}
-
-
-//==============================================================================
-// initCopy                                                                    =
-//==============================================================================
-void Is::initCopy()
-{
-	try
-	{
-		// Read
-		readFbo.create();
-		readFbo.bind();
-		readFbo.setNumOfColorAttachements(0);
-		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
-			GL_TEXTURE_2D, r.getMs().getDepthFai().getGlId(), 0);
-		readFbo.unbind();
-
-		// Write
-		Renderer::createFai(r.getWidth(), r.getHeight(), GL_DEPTH24_STENCIL8,
-			GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, copyMsDepthFai);
-
-		writeFbo.create();
-		writeFbo.bind();
-		writeFbo.setNumOfColorAttachements(0);
-		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
-			GL_TEXTURE_2D, copyMsDepthFai.getGlId(), 0);
-		writeFbo.unbind();
-	}
-	catch(std::exception& e)
-	{
-		throw ANKI_EXCEPTION("Cannot create deferred shading "
-			"illumination stage additional FBO") << e;
-	}
-}
-
-
-//==============================================================================
-// init                                                                        =
-//==============================================================================
-void Is::init(const RendererInitializer& initializer)
-{
-	// init passes
-	smo.init(initializer);
-	sm.init(initializer);
-
-	// load the shaders
-	ambientPassSProg.load("shaders/IsAp.glsl");
-
-	// point light
-	pointLightSProg.load(ShaderProgram::createSrcCodeToCache(
-		"shaders/IsLpGeneric.glsl", "#define POINT_LIGHT_ENABLED\n").c_str());
-
-	// spot light no shadow
-	spotLightNoShadowSProg.load(ShaderProgram::createSrcCodeToCache(
-		"shaders/IsLpGeneric.glsl", "#define SPOT_LIGHT_ENABLED\n").c_str());
-
-	// spot light w/t shadow
-	std::string pps = std::string("#define SPOT_LIGHT_ENABLED\n"
-	                              "#define SHADOW_ENABLED\n");
-	if(sm.isPcfEnabled())
-	{
-		pps += "#define PCF_ENABLED\n";
-	}
-	spotLightShadowSProg.load(ShaderProgram::createSrcCodeToCache(
-		"shaders/IsLpGeneric.glsl", pps.c_str()).c_str());
-
-	// init the rest
-	initCopy();
-	initFbo();
-}
-
-
-//==============================================================================
-// ambientPass                                                                 =
-//==============================================================================
-void Is::ambientPass(const Vec3& color)
-{
-	GlStateMachineSingleton::get().enable(GL_BLEND, false);
-
-	// set the shader
-	ambientPassSProg->bind();
-
-	// set the uniforms
-	ambientPassSProg->findUniformVariableByName("ambientCol").set(color);
-	ambientPassSProg->findUniformVariableByName("sceneColMap").set(
-		r.getMs().getDiffuseFai(), 0);
-
-	// Draw quad
-	r.drawQuad();
-}
-
-
-//==============================================================================
-// pointLightPass                                                              =
-//==============================================================================
-void Is::pointLightPass(PointLight& light)
-{
-	const Camera& cam = r.getCamera();
-
-	// stencil optimization
-	smo.run(light);
-	GlStateMachineSingleton::get().enable(GL_DEPTH_TEST, false);
-
-	// shader prog
-	const ShaderProgram& shader = *pointLightSProg; // ensure the const-ness
-	shader.bind();
-
-	shader.findUniformVariableByName("msNormalFai").set(
-		r.getMs().getNormalFai(), 0);
-	shader.findUniformVariableByName("msDiffuseFai").set(
-		r.getMs().getDiffuseFai(), 1);
-	shader.findUniformVariableByName("msSpecularFai").set(
-		r.getMs().getSpecularFai(), 2);
-	shader.findUniformVariableByName("msDepthFai").set(
-		r.getMs().getDepthFai(), 3);
-	shader.findUniformVariableByName("planes").set(r.getPlanes());
-	shader.findUniformVariableByName("limitsOfNearPlane").set(
-		r.getLimitsOfNearPlane());
-	shader.findUniformVariableByName("limitsOfNearPlane2").set(
-		r.getLimitsOfNearPlane2());
-	float zNear = cam.getZNear();
-	shader.findUniformVariableByName("zNear").set(zNear);
-	const Vec3& origin = light.getWorldTransform().getOrigin();
-	Vec3 lightPosEyeSpace = origin.getTransformed(cam.getViewMatrix());
-	shader.findUniformVariableByName("lightPos").set(lightPosEyeSpace);
-	shader.findUniformVariableByName("lightRadius").set(light.getRadius());
-	shader.findUniformVariableByName("lightDiffuseCol").set(
-		light.getDiffuseColor());
-	shader.findUniformVariableByName("lightSpecularCol").set(
-		light.getSpecularColor());
-
-	// render quad
-	r.drawQuad();
-}
-
-
-//==============================================================================
-// spotLightPass                                                               =
-//==============================================================================
-void Is::spotLightPass(SpotLight& light)
-{
-	const Camera& cam = r.getCamera();
-	bool withShadow = light.getCastShadow() && sm.getEnabled() &&
-		(light.getVisibleMsRenderableNodes().size() > 0);
-
-	// shadow mapping
-	if(withShadow)
-	{
-		Vec3 zAxis = light.getWorldTransform().getRotation().getColumn(2);
-		LineSegment seg(light.getWorldTransform().getOrigin(),
-			-zAxis * light.getCamera().getZFar());
-
-		const Plane& plane = cam.getWSpaceFrustumPlane(Camera::FP_NEAR);
-
-		float dist = seg.testPlane(plane);
-
-		sm.run(light, dist);
-
-		// restore the IS FBO
-		fbo.bind();
-
-		// and restore blending and depth test
-		GlStateMachineSingleton::get().enable(GL_BLEND, BLEND_ENABLE);
-		glBlendFunc(GL_ONE, GL_ONE);
-		GlStateMachineSingleton::get().enable(GL_DEPTH_TEST, false);
-		GlStateMachineSingleton::get().setViewport(0, 0,
-			r.getWidth(), r.getHeight());
-	}
-
-	// stencil optimization
-	smo.run(light);
-	GlStateMachineSingleton::get().enable(GL_DEPTH_TEST, false);
-
-	// set the texture
-	//light.getTexture().setRepeat(false);
-
-	// shader prog
-	const ShaderProgram* shdr;
-
-	if(withShadow)
-	{
-		shdr = spotLightShadowSProg.get();
-	}
-	else
-	{
-		shdr = spotLightNoShadowSProg.get();
-	}
-
-	shdr->bind();
-
-	// bind the FAIs
-	const Ms& ms = r.getMs();
-	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->findUniformVariableByName("planes").set(r.getPlanes());
-	shdr->findUniformVariableByName("limitsOfNearPlane").set(
-		r.getLimitsOfNearPlane());
-	shdr->findUniformVariableByName("limitsOfNearPlane2").set(
-		r.getLimitsOfNearPlane2());
-	float zNear = cam.getZNear();
-	shdr->findUniformVariableByName("zNear").set(zNear);
-
-	// the light params
-	const Vec3& origin = light.getWorldTransform().getOrigin();
-	Vec3 lightPosEyeSpace = origin.getTransformed(cam.getViewMatrix());
-	shdr->findUniformVariableByName("lightPos").set(lightPosEyeSpace);
-	float tmp = light.getDistance();
-	shdr->findUniformVariableByName("lightRadius").set(tmp);
-	shdr->findUniformVariableByName("lightDiffuseCol").set(
-		light.getDiffuseColor());
-	shdr->findUniformVariableByName("lightSpecularCol").set(
-		light.getSpecularColor());
-	shdr->findUniformVariableByName("lightTex").set(light.getTexture(), 4);
-
-	// set texture matrix for texture & shadowmap projection
-	// Bias * P_light * V_light * inv(V_cam)
-	static Mat4 biasMat4(0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5,
-		0.5, 0.0, 0.0, 0.0, 1.0);
-	Mat4 texProjectionMat;
-	texProjectionMat = biasMat4 * light.getCamera().getProjectionMatrix() *
-		Mat4::combineTransformations(light.getCamera().getViewMatrix(),
-		Mat4(cam.getWorldTransform()));
-	shdr->findUniformVariableByName("texProjectionMat").set(texProjectionMat);
-
-	// the shadowmap
-	if(light.getCastShadow() && sm.getEnabled())
-	{
-		shdr->findUniformVariableByName("shadowMap").set(sm.getShadowMap(), 5);
-		float smSize = sm.getShadowMap().getWidth();
-		shdr->findUniformVariableByName("shadowMapSize").set(smSize);
-	}
-
-	// render quad
-	r.drawQuad();
-}
-
-
-//==============================================================================
-// copyDepth                                                                   =
-//==============================================================================
-void Is::copyDepth()
-{
-	readFbo.bind(GL_READ_FRAMEBUFFER);
-	writeFbo.bind(GL_DRAW_FRAMEBUFFER);
-	glBlitFramebuffer(0, 0, r.getWidth(), r.getHeight(), 0, 0, r.getWidth(),
-	    r.getHeight(), GL_DEPTH_BUFFER_BIT, GL_NEAREST);
-}
-
-
-//==============================================================================
-// run                                                                         =
 //==============================================================================
 void Is::run()
 {
-	// OGL stuff
-	GlStateMachineSingleton::get().setViewport(0, 0,
-		r.getWidth(), r.getHeight());
-
-	// Copy
-	if(r.getFramesNum() % 2 == 0)
-	{
-		copyDepth();
-	}
-
-	// FBO
-	fbo.bind();
-
-	// ambient pass
-	GlStateMachineSingleton::get().enable(GL_DEPTH_TEST, false);
-	ambientPass(SceneSingleton::get().getAmbientColor());
-
-	// light passes
-	GlStateMachineSingleton::get().enable(GL_BLEND, BLEND_ENABLE);
-	glBlendFunc(GL_ONE, GL_ONE);
-	GlStateMachineSingleton::get().enable(GL_STENCIL_TEST);
-
-	// for all lights
-	BOOST_FOREACH(PointLight* light,
-		r.getCamera().getVisiblePointLights())
-	{
-		/*if(light->getVisibleMsRenderableNodes().size() == 0)
-		{
-			continue;
-		}*/
-		pointLightPass(*light);
-	}
-
-	BOOST_FOREACH(SpotLight* light, r.getCamera().getVisibleSpotLights())
-	{
-		/*if(light->getVisibleMsRenderableNodes() == 0)
-		{
-			continue;
-		}*/
-		spotLightPass(*light);
-	}
-	
-
-	GlStateMachineSingleton::get().disable(GL_STENCIL_TEST);
-
-	// FBO
-	//fbo.unbind();
-
-	ANKI_CHECK_GL_ERROR();
+	/// TODO
 }
 
 

+ 1 - 34
anki/renderer/Is.h

@@ -37,40 +37,7 @@ public:
 	/// @}
 
 private:
-	Sm sm; ///< Shadowmapping pass
-	Smo smo; /// Stencil masking optimizations pass
-	Fbo fbo; ///< This FBO writes to the Is::fai
-	Texture fai; ///< The one and only FAI
-	uint stencilRb; ///< Illumination stage stencil buffer
-	Texture copyMsDepthFai;
-	Fbo readFbo;
-	Fbo writeFbo;
-	/// Illumination stage ambient pass shader program
-	ShaderProgramResourcePointer ambientPassSProg;
-	/// Illumination stage point light shader program
-	ShaderProgramResourcePointer pointLightSProg;
-	/// Illumination stage spot light w/o shadow shader program
-	ShaderProgramResourcePointer spotLightNoShadowSProg;
-	/// Illumination stage spot light w/ shadow shader program
-	ShaderProgramResourcePointer spotLightShadowSProg;
-
-	/// The ambient pass
-	void ambientPass(const Vec3& color);
-
-	/// The point light pass
-	void pointLightPass(PointLight& plight);
-
-	/// The spot light pass
-	void spotLightPass(SpotLight& slight);
-
-	/// Used in @ref init
-	void initFbo();
-
-	/// Init the copy stuff
-	void initCopy();
-
-	/// Copy the MS depth FAI to one of our own
-	void copyDepth();
+	Texture fai;
 };
 
 

+ 0 - 101
anki/renderer/PhysDbgDrawer.cpp

@@ -1,101 +0,0 @@
-#include "anki/renderer/PhysDbgDrawer.h"
-#include "anki/renderer/Dbg.h"
-#include "anki/physics/Convertors.h"
-#include "anki/core/Logger.h"
-
-
-namespace anki {
-
-
-//==============================================================================
-// drawLine                                                                    =
-//==============================================================================
-void PhysDbgDrawer::drawLine(const btVector3& from, const btVector3& to,
-	const btVector3& color)
-{
-	dbg.drawLine(toAnki(from), toAnki(to), Vec4(toAnki(color), 1.0));
-}
-
-
-//==============================================================================
-// drawSphere                                                                  =
-//==============================================================================
-void PhysDbgDrawer::drawSphere(btScalar radius, const btTransform& transform,
-	const btVector3& color)
-{
-	dbg.setColor(toAnki(color));
-	dbg.setModelMat(Mat4(toAnki(transform)));
-	dbg.drawSphere(radius);
-}
-
-
-//==============================================================================
-// drawBox                                                                     =
-//==============================================================================
-void PhysDbgDrawer::drawBox(const btVector3& min, const btVector3& max,
-	const btVector3& color)
-{
-	Mat4 trf(Mat4::getIdentity());
-	trf(0, 0) = max.getX() - min.getX();
-	trf(1, 1) = max.getY() - min.getY();
-	trf(2, 2) = max.getZ() - min.getZ();
-	trf(0, 3) = (max.getX() + min.getX()) / 2.0;
-	trf(1, 3) = (max.getY() + min.getY()) / 2.0;
-	trf(2, 3) = (max.getZ() + min.getZ()) / 2.0;
-	dbg.setModelMat(trf);
-	dbg.setColor(toAnki(color));
-	dbg.drawCube(1.0);
-}
-
-
-//==============================================================================
-// drawBox                                                                     =
-//==============================================================================
-void PhysDbgDrawer::drawBox(const btVector3& min, const btVector3& max,
-	const btTransform& trans, const btVector3& color)
-{
-	Mat4 trf(Mat4::getIdentity());
-	trf(0, 0) = max.getX() - min.getX();
-	trf(1, 1) = max.getY() - min.getY();
-	trf(2, 2) = max.getZ() - min.getZ();
-	trf(0, 3) = (max.getX() + min.getX()) / 2.0;
-	trf(1, 3) = (max.getY() + min.getY()) / 2.0;
-	trf(2, 3) = (max.getZ() + min.getZ()) / 2.0;
-	trf = Mat4::combineTransformations(Mat4(toAnki(trans)), trf);
-	dbg.setModelMat(trf);
-	dbg.setColor(toAnki(color));
-	dbg.drawCube(1.0);
-}
-
-
-//==============================================================================
-// drawContactPoint                                                            =
-//==============================================================================
-void PhysDbgDrawer::drawContactPoint(const btVector3& /*pointOnB*/,
-	const btVector3& /*normalOnB*/,
-	btScalar /*distance*/, int /*lifeTime*/, const btVector3& /*color*/)
-{
-	//ANKI_WARNING("Unimplemented");
-}
-
-
-//==============================================================================
-// reportErrorWarning                                                          =
-//==============================================================================
-void PhysDbgDrawer::reportErrorWarning(const char* warningString)
-{
-	throw ANKI_EXCEPTION(warningString);
-}
-
-
-//==============================================================================
-// draw3dText                                                                  =
-//==============================================================================
-void PhysDbgDrawer::draw3dText(const btVector3& /*location*/,
-	const char* /*textString*/)
-{
-	//ANKI_WARNING("Unimplemented");
-}
-
-
-} // end namespace

+ 0 - 50
anki/renderer/PhysDbgDrawer.h

@@ -1,50 +0,0 @@
-#ifndef ANKI_RENDERER_PHY_DBG_DRAWER_H
-#define ANKI_RENDERER_PHY_DBG_DRAWER_H
-
-#include <LinearMath/btIDebugDraw.h>
-
-
-namespace anki {
-
-
-class Dbg;
-
-
-/// An implementation of btIDebugDraw used for debugging Bullet. See Bullet
-/// docs for details
-class PhysDbgDrawer: public btIDebugDraw
-{
-	public:
-		PhysDbgDrawer(Dbg& dbg_): dbg(dbg_) {}
-
-		void drawLine(const btVector3& from, const btVector3& to,
-			const btVector3& color);
-
-		void drawContactPoint(const btVector3& pointOnB,
-			const btVector3& normalOnB, btScalar distance, int lifeTime,
-			const btVector3& color);
-
-		void drawSphere(btScalar radius, const btTransform& transform,
-			const btVector3& color);
-
-		void drawBox(const btVector3& bbMin, const btVector3& bbMax,
-			const btVector3& color);
-
-		void drawBox(const btVector3& bbMin, const btVector3& bbMax,
-			const btTransform& trans, const btVector3& color);
-
-		void reportErrorWarning(const char* warningString);
-		void draw3dText(const btVector3& location, const char* textString);
-		void setDebugMode(int debugMode_) {debugMode = debugMode_;}
-		int getDebugMode() const {return debugMode;}
-
-	private:
-		int debugMode;
-		Dbg& dbg;
-};
-
-
-} // end namespace
-
-
-#endif

+ 6 - 6
anki/renderer/Renderer.cpp

@@ -1,7 +1,7 @@
 #include "anki/renderer/Renderer.h"
 #include "anki/renderer/RendererInitializer.h"
 #include "anki/util/Exception.h"
-#include "anki/scene/PerspectiveCamera.h"
+#include "anki/scene/Camera.h"
 
 
 namespace anki {
@@ -10,7 +10,7 @@ namespace anki {
 //==============================================================================
 Renderer::Renderer()
 	: ms(*this), is(*this), pps(*this), bs(*this), width(640), height(480),
-		sceneDrawer(*this)
+		sceneDrawer(this)
 {
 	enableStagesProfilingFlag = false;
 	lodDistance = 10.0;
@@ -73,7 +73,7 @@ void Renderer::render(Camera& cam_)
 	//
 	// Calc a few vars
 	//
-	calcPlanes(Vec2(cam->getZNear(), cam->getZFar()), planes);
+	calcPlanes(Vec2(cam->getNear(), cam->getFar()), planes);
 
 	ANKI_ASSERT(cam->getCameraType() == Camera::CT_PERSPECTIVE);
 	const PerspectiveCamera& pcam = static_cast<const PerspectiveCamera&>(*cam);
@@ -182,9 +182,9 @@ void Renderer::calcPlanes(const Vec2& cameraRange, Vec2& planes)
 void Renderer::calcLimitsOfNearPlane(const PerspectiveCamera& pcam,
 	Vec2& limitsOfNearPlane)
 {
-	limitsOfNearPlane.y() = pcam.getZNear() * tan(0.5 * pcam.getFovY());
-	limitsOfNearPlane.x() = limitsOfNearPlane.y() *
-		(pcam.getFovX() / pcam.getFovY());
+	limitsOfNearPlane.y() = pcam.getNear() * tan(0.5 * pcam.getFovY());
+	limitsOfNearPlane.x() = limitsOfNearPlane.y()
+		* (pcam.getFovX() / pcam.getFovY());
 }
 
 

+ 1 - 2
anki/renderer/Renderer.h

@@ -14,7 +14,6 @@
 #include "anki/renderer/Bs.h"
 #include "anki/renderer/Dbg.h"
 #include "anki/gl/GlException.h"
-#include "anki/renderer/SceneDrawer.h"
 #include "anki/gl/GlStateMachine.h"
 #include "anki/gl/TimeQuery.h"
 #include <boost/scoped_ptr.hpp>
@@ -210,7 +209,7 @@ public:
 
 	/// Calculates two values needed for the calculation of the fragment
 	/// position in view space.
-	static void calcLimitsOfNearPlane(const PerspectiveCamera& cam,
+	static void calcLimitsOfNearPlane(const class PerspectiveCamera& cam,
 		Vec2& limitsOfNearPlane);
 
 	/// Get the LOD given the distance of an object from the camera

+ 0 - 76
anki/renderer/SceneDbgDrawer.cpp

@@ -1,76 +0,0 @@
-#include "anki/renderer/SceneDbgDrawer.h"
-#include "anki/renderer/Dbg.h"
-#include "anki/renderer/CollisionDbgDrawer.h"
-#include "anki/scene/Octree.h"
-#include "anki/scene/Frustumable.h"
-#include "anki/scene/Spatial.h"
-
-
-namespace anki {
-
-
-//==============================================================================
-void SceneDbgDrawer::draw(const SceneNode& node)
-{
-	if(isFlagEnabled(DF_FRUSTUMABLE) && node.getFrustumable())
-	{
-		draw(*node.getFrustumable());
-	}
-
-	if(isFlagEnabled(DF_SPATIAL) && node.getSpatial())
-	{
-		draw(*node.getSpatial());
-	}
-}
-
-
-//==============================================================================
-void SceneDbgDrawer::draw(const Frustumable& fr) const
-{
-	const Frustum& fs = fr.getFrustum();
-
-	CollisionDbgDrawer coldraw(dbg);
-	fs.accept(coldraw);
-}
-
-
-//==============================================================================
-void SceneDbgDrawer::draw(const Spatial& x) const
-{
-	const CollisionShape& cs = x.getSpatialCollisionShape();
-
-	CollisionDbgDrawer coldraw(dbg);
-	cs.accept(coldraw);
-}
-
-
-//==============================================================================
-void SceneDbgDrawer::draw(const Octree& octree) const
-{
-	dbg->setColor(Vec3(1.0));
-	draw(octree.getRoot(), 0, octree);
-}
-
-
-//==============================================================================
-void SceneDbgDrawer::draw(const OctreeNode& octnode, uint depth,
-	const Octree& octree) const
-{
-	Vec3 color = Vec3(1.0 - float(depth) / float(octree.getMaxDepth()));
-	dbg->setColor(color);
-
-	CollisionDbgDrawer v(dbg);
-	octnode.getAabb().accept(v);
-
-	// Children
-	for(uint i = 0; i < 8; ++i)
-	{
-		if(octnode.getChildren()[i] != NULL)
-		{
-			draw(*octnode.getChildren()[i], depth + 1, octree);
-		}
-	}
-}
-
-
-} // end namespace

+ 0 - 75
anki/renderer/SceneDbgDrawer.h

@@ -1,75 +0,0 @@
-#ifndef ANKI_RENDERER_SCENE_DBG_DRAWER_H
-#define ANKI_RENDERER_SCENE_DBG_DRAWER_H
-
-#include "anki/util/StdTypes.h"
-#include "anki/scene/SceneNode.h"
-
-
-namespace anki {
-
-
-class Dbg;
-class Octree;
-class OctreeNode;
-
-
-/// This is a drawer for some scene nodes that need debug
-class SceneDbgDrawer
-{
-public:
-	enum DebugFlag
-	{
-		DF_NONE = 0,
-		DF_SPATIAL = 1,
-		DF_MOVABLE = 2,
-		DF_FRUSTUMABLE = 4
-	};
-
-	SceneDbgDrawer(Dbg* d)
-		: dbg(d), flags(DF_NONE)
-	{}
-
-	virtual ~SceneDbgDrawer()
-	{}
-
-	/// @name Flag manipulation
-	/// @{
-	void enableFlag(DebugFlag flag, bool enable = true)
-	{
-		flags = enable ? flags | flag : flags & ~flag;
-	}
-	void disableFlag(DebugFlag flag)
-	{
-		enableFlag(flag, false);
-	}
-	bool isFlagEnabled(DebugFlag flag) const
-	{
-		return flags & flag;
-	}
-	uint getFlagsBitmask() const
-	{
-		return flags;
-	}
-	/// @}
-
-	void draw(const SceneNode& node);
-
-	virtual void draw(const Octree& octree) const;
-
-private:
-	Dbg* dbg;
-	uint flags;
-
-	virtual void draw(const Frustumable& fr) const;
-
-	virtual void draw(const Spatial& sp) const;
-
-	virtual void draw(const OctreeNode& octnode,
-		uint depth, const Octree& octree) const;
-};
-
-
-} // end namespace
-
-
-#endif

+ 0 - 294
anki/renderer/SceneDrawer.cpp

@@ -1,294 +0,0 @@
-#include "anki/renderer/SceneDrawer.h"
-#include "anki/math/Math.h"
-#include "anki/resource/Material.h"
-#include "anki/scene/RenderableNode.h"
-#include "anki/scene/Camera.h"
-#include "anki/renderer/Renderer.h"
-#include "anki/core/App.h"
-#include "anki/scene/Scene.h"
-#include "anki/scene/MaterialRuntime.h"
-#include "anki/gl/GlStateMachine.h"
-#include <boost/foreach.hpp>
-#include <algorithm>
-
-
-namespace anki {
-
-
-//==============================================================================
-boost::array<const char*, SceneDrawer::B_NUM> SceneDrawer::buildinsTxt = {{
-	// Matrices
-	"modelMat",
-	"viewMat",
-	"projectionMat",
-	"modelViewMat",
-	"viewProjectionMat",
-	"normalMat",
-	"modelViewProjectionMat",
-	// FAIs (for materials in blending stage)
-	"msNormalFai",
-	"msDiffuseFai",
-	"msSpecularFai",
-	"msDepthFai",
-	"isFai",
-	"ppsPrePassFai",
-	"ppsPostPassFai",
-	// Other
-	"rendererSize",
-	"sceneAmbientColor",
-	"blurring"
-}};
-
-
-//==============================================================================
-SceneDrawer::SetUniformVisitor::SetUniformVisitor(
-	const ShaderProgramUniformVariable& uni_, uint& texUnit_)
-	: uni(uni_), texUnit(texUnit_)
-{}
-
-
-//==============================================================================
-template<typename Type>
-void SceneDrawer::SetUniformVisitor::operator()(const Type& x) const
-{
-	uni.set(x);
-}
-
-
-//==============================================================================
-template<>
-void SceneDrawer::SetUniformVisitor::operator()<TextureResourcePointer>(
-	const TextureResourcePointer& x) const
-{
-	uni.set(*x, 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;
-	}
-}
-
-
-//==============================================================================
-void SceneDrawer::setupShaderProg(
-	const PassLevelKey& key,
-	const Transform& nodeWorldTransform,
-	const Transform& prevNodeWorldTransform,
-	const Camera& cam,
-	const Renderer& r,
-	MaterialRuntime& mtlr)
-{
-	uint textureUnit = 0;
-	GlStateMachine& gl = GlStateMachineSingleton::get();
-	const Material& mtl = mtlr.getMaterial();
-	const ShaderProgram& sprog = mtl.getShaderProgram(key);
-
-	sprog.bind();
-
-	//
-	// FFP stuff
-	//
-	gl.enable(GL_BLEND, mtlr.isBlendingEnabled());
-	if(mtlr.isBlendingEnabled())
-	{
-		glBlendFunc(mtlr.getBlendingSFactor(), mtlr.getBlendingDFactor());
-	}
-
-	gl.enable(GL_DEPTH_TEST, mtlr.getDepthTesting());
-
-	if(mtlr.getWireframe())
-	{
-		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-	}
-	else
-	{
-		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-	}
-
-	//
-	// Get needed matrices
-	//
-	Mat4 modelMat(nodeWorldTransform);
-	const Mat4& projectionMat = cam.getProjectionMatrix();
-	const Mat4& viewMat = cam.getViewMatrix();
-	Mat4 modelViewMat;
-	bool modelViewMatCalculated = false;
-
-	//
-	// For all the vars
-	//
-	BOOST_FOREACH(MaterialRuntimeVariable& mrvar, mtlr.getVariables())
-	{
-		const MaterialVariable& mvar = mrvar.getMaterialVariable();
-
-		// Skip some
-		if(!mvar.inPass(key))
-		{
-			continue;
-		}
-
-		// Set the buildinId for all
-		if(mrvar.getBuildinId() == -1)
-		{
-			for(uint i = 0; i < B_NUM; i++)
-			{
-				if(mvar.getName() == buildinsTxt[i])
-				{
-					mrvar.setBuildinId(i);
-					break;
-				}
-			}
-
-			// If still -1 thn set it as B_NUM
-			if(mrvar.getBuildinId() == -1)
-			{
-				mrvar.setBuildinId(B_NUM);
-			}
-		}
-
-		// Sanity checks
-		if(mrvar.getBuildinId() == B_NUM && !mvar.getInitialized())
-		{
-			ANKI_WARNING("Uninitialized variable: " << mvar.getName());
-		}
-
-		if(mrvar.getBuildinId() != B_NUM && mvar.getInitialized())
-		{
-			ANKI_WARNING("The renderer will override the given value for: " <<
-				mvar.getName());
-		}
-
-		// Big switch
-		const ShaderProgramUniformVariable& uni =
-			mvar.getShaderProgramUniformVariable(key);
-
-		switch(mrvar.getBuildinId())
-		{
-			case B_MODEL_MAT:
-				uni.set(modelMat);
-				break;
-			case B_VIEW_MAT:
-				uni.set(viewMat);
-				break;
-			case B_PROJECTION_MAT:
-				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(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;
-			case B_MS_DIFFUSE_FAI:
-				uni.set(r.getMs().getDiffuseFai(), textureUnit++);
-				break;
-			case B_MS_SPECULAR_FAI:
-				uni.set(r.getMs().getSpecularFai(), textureUnit++);
-				break;
-			case B_MS_DEPTH_FAI:
-				uni.set(r.getMs().getDepthFai(), textureUnit++);
-				break;
-			case B_IS_FAI:
-				uni.set(r.getIs().getFai(), textureUnit++);
-				break;
-			case B_PPS_PRE_PASS_FAI:
-				uni.set(r.getPps().getPrePassFai(), textureUnit++);
-				break;
-			case B_PPS_POST_PASS_FAI:
-				uni.set(r.getPps().getPostPassFai(), textureUnit++);
-				break;
-			case B_RENDERER_SIZE:
-			{
-				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:
-			{
-				// 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;
-			}
-		}
-	}
-
-	ANKI_CHECK_GL_ERROR();
-}
-
-
-//==============================================================================
-void SceneDrawer::renderRenderableNode(const Camera& cam,
-	uint pass, RenderableNode& node) const
-{
-	MaterialRuntime& mtlr = node.getMaterialRuntime();
-	const Material& mtl = mtlr.getMaterial();
-
-	// Calc the LOD and the key
-	float dist = (node.getWorldTransform().getOrigin() -
-		cam.getWorldTransform().getOrigin()).getLength();
-	uint lod = std::min(r.calculateLod(dist), mtl.getLevelsOfDetail() - 1);
-
-	PassLevelKey key(pass, lod);
-
-	// Setup shader
-	setupShaderProg(key, node.getWorldTransform(),
-		node.getPrevWorldTransform(), cam, r, mtlr);
-
-	node.getVao(key).bind();
-	glDrawElements(GL_TRIANGLES, node.getVertIdsNum(key), GL_UNSIGNED_SHORT, 0);
-	node.getVao(key).unbind();
-}
-
-
-} // end namespace

+ 0 - 107
anki/renderer/SceneDrawer.h

@@ -1,107 +0,0 @@
-#ifndef ANKI_RENDERER_SCENE_DRAWER_H
-#define ANKI_RENDERER_SCENE_DRAWER_H
-
-#include "anki/math/Math.h"
-#include "anki/resource/MaterialCommon.h"
-#include "anki/resource/Resource.h"
-#include <boost/variant.hpp>
-
-
-namespace anki {
-
-
-class RenderableNode;
-class Camera;
-class Material;
-class MaterialRuntime;
-class MaterialRuntimeVariable;
-class ShaderProgramUniformVariable;
-
-class Renderer;
-
-
-/// It includes all the functions to render a RenderableNode
-class SceneDrawer
-{
-public:
-	/// The one and only constructor
-	SceneDrawer(const Renderer& r_)
-		: r(r_)
-	{}
-
-	void renderRenderableNode(const Camera& cam,
-		uint pass, RenderableNode& renderable) const;
-
-private:
-	/// Standard attribute variables that are acceptable inside the
-	/// ShaderProgram
-	enum Buildins
-	{
-		// Matrices
-		B_MODEL_MAT,
-		B_VIEW_MAT,
-		B_PROJECTION_MAT,
-		B_MODEL_VIEW_MAT,
-		B_VIEW_PROJECTION_MAT,
-		B_NORMAL_MAT,
-		B_MODEL_VIEW_PROJECTION_MAT,
-		// FAIs (for materials in blending stage)
-		B_MS_NORMAL_FAI,
-		B_MS_DIFFUSE_FAI,
-		B_MS_SPECULAR_FAI,
-		B_MS_DEPTH_FAI,
-		B_IS_FAI,
-		B_PPS_PRE_PASS_FAI,
-		B_PPS_POST_PASS_FAI,
-		// Other
-		B_RENDERER_SIZE,
-		B_SCENE_AMBIENT_COLOR,
-		B_BLURRING,
-		// num
-		B_NUM ///< The number of all buildin variables
-	};
-
-	/// Set the uniform using this visitor
-	struct SetUniformVisitor: public boost::static_visitor<>
-	{
-		const ShaderProgramUniformVariable& uni;
-		uint& texUnit;
-
-		SetUniformVisitor(const ShaderProgramUniformVariable& uni,
-			uint& texUnit);
-
-		template<typename Type>
-		void operator()(const Type& x) const;
-	};
-
-	static boost::array<const char*, B_NUM> buildinsTxt;
-	const Renderer& r; ///< Keep it here cause the class wants a few stuff
-					   ///< from it
-
-	/// This function:
-	/// - binds the shader program
-	/// - loads the uniforms
-	/// - sets the GL state
-	/// @param mtlr The material runtime
-	/// @param nodeWorldTransform The world transformation to pass to the
-	/// shader
-	/// @param cam Needed for some matrices (view & projection)
-	/// @param r The renderer, needed for some FAIs and some matrices
-	static void setupShaderProg(
-		const PassLevelKey& key,
-		const Transform& nodeWorldTransform,
-		const Transform& prevNodeWorldTransform,
-		const Camera& cam,
-		const Renderer& r,
-		MaterialRuntime& mtlr);
-
-	/// For code duplication
-	static void tryCalcModelViewMat(const Mat4& modelMat, const Mat4& viewMat,
-		bool& calculated, Mat4& modelViewMat);
-};
-
-
-} // end namespace
-
-
-#endif

+ 1 - 223
anki/renderer/Smo.cpp

@@ -1,247 +1,25 @@
 #include "anki/renderer/Smo.h"
 #include "anki/renderer/Renderer.h"
 #include "anki/scene/Light.h"
-#include "anki/resource/LightRsrc.h"
-#include "anki/scene/PointLight.h"
-#include "anki/scene/SpotLight.h"
-#include "anki/scene/Camera.h"
-#include "anki/gl/Vao.h"
-#include "anki/gl/Vbo.h"
-#include "anki/scene/PerspectiveCamera.h"
-#include "anki/scene/OrthographicCamera.h"
-#include "anki/resource/Mesh.h"
 
 
 namespace anki {
 
 
-const float THRESHOLD = 0.2;
-
-
-//==============================================================================
-// Geom                                                                        =
-//==============================================================================
-
-Smo::Geom::Geom()
-{}
-
-
-Smo::Geom::~Geom()
-{}
-
-
-//==============================================================================
-// Destructor                                                                  =
 //==============================================================================
 Smo::~Smo()
 {}
 
 
-//==============================================================================
-// init                                                                        =
 //==============================================================================
 void Smo::init(const RendererInitializer& /*initializer*/)
 {
-	sProg.load("shaders/IsSmo.glsl");
-
-	//
-	// Geometry stuff
-	//
-
-	// Sphere
-	sphereGeom.mesh.load("engine-rsrc/sphere.mesh");
-	sphereGeom.vao.create();
-	sphereGeom.vao.attachArrayBufferVbo(
-		sphereGeom.mesh->getVbo(Mesh::VBO_VERT_POSITIONS),
-		sProg->findAttributeVariableByName("position"), 3, GL_FLOAT,
-		GL_FALSE, 0, NULL);
-	sphereGeom.vao.attachElementArrayBufferVbo(
-		sphereGeom.mesh->getVbo(Mesh::VBO_VERT_INDECES));
-
-	// Cameras
-	initCamGeom();
-}
-
-
-//==============================================================================
-// initCamGeom                                                                 =
-//==============================================================================
-void Smo::initCamGeom()
-{
-	boost::array<const char*, Camera::CT_NUM> files = {{
-		"engine-rsrc/pyramid.mesh", "engine-rsrc/cube.mesh"}};
-	ANKI_ASSERT(Camera::CT_PERSPECTIVE == 0);
-
-	for(uint i = 0; i < Camera::CT_NUM; i++)
-	{
-		camGeom[i].mesh.load(files[i]);
-		camGeom[i].vao.create();
-		camGeom[i].vao.attachArrayBufferVbo(
-			camGeom[i].mesh->getVbo(Mesh::VBO_VERT_POSITIONS),
-			sProg->findAttributeVariableByName("position"), 3, GL_FLOAT,
-			GL_FALSE, 0, NULL);
-		camGeom[i].vao.attachElementArrayBufferVbo(
-			camGeom[i].mesh->getVbo(Mesh::VBO_VERT_INDECES));
-	}
-}
-
-
-//==============================================================================
-// setUpGl                                                                     =
-//==============================================================================
-void Smo::setUpGl(bool inside)
-{
-	glStencilFunc(GL_ALWAYS, 0x1, 0x1);
-	glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
-	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
-	glClear(GL_STENCIL_BUFFER_BIT);
-
-	if(inside)
-	{
-		glCullFace(GL_FRONT);
-		GlStateMachineSingleton::get().enable(GL_DEPTH_TEST, false);
-	}
-	else
-	{
-		glDepthMask(GL_FALSE);
-		GlStateMachineSingleton::get().enable(GL_DEPTH_TEST, true);
-	}
 }
 
 
 //==============================================================================
-// restoreGl                                                                   =
-//==============================================================================
-void Smo::restoreGl(bool inside)
+void Smo::run(const Light& light) 
 {
-	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
-	glStencilFunc(GL_EQUAL, 0x1, 0x1);
-
-	if(inside)
-	{
-		glCullFace(GL_BACK);
-	}
-	else
-	{
-		glDepthMask(GL_TRUE);
-	}
-}
-
-
-//==============================================================================
-// run [PointLight]                                                            =
-//==============================================================================
-void Smo::run(const PointLight& light)
-{
-	const Vec3& o = light.getWorldTransform().getOrigin();
-	const Vec3& c = r.getCamera().getWorldTransform().getOrigin();
-	bool inside =  (o - c).getLength() <=
-		(light.getRadius() + r.getCamera().getZNear() + THRESHOLD);
-
-	// set GL state
-	setUpGl(inside);
-
-	// set shared prog
-	const float SCALE = 1.0; // we scale the sphere a little
-	sProg->bind();
-	Mat4 modelMat = Mat4(light.getWorldTransform().getOrigin(),
-		Mat3::getIdentity(), light.getRadius() * SCALE);
-	Mat4 trf = r.getViewProjectionMat() * modelMat;
-	sProg->findUniformVariableByName("modelViewProjectionMat").set(trf);
-
-	// render sphere to the stencil buffer
-	sphereGeom.vao.bind();
-	glDrawElements(GL_TRIANGLES, sphereGeom.mesh->getVertIdsNum(),
-		GL_UNSIGNED_SHORT, 0);
-	sphereGeom.vao.unbind();
-
-	// restore GL
-	restoreGl(inside);
-}
-
-
-//==============================================================================
-// run [SpotLight]                                                             =
-//==============================================================================
-void Smo::run(const SpotLight& light)
-{
-	const Camera& lcam = light.getCamera();
-
-	const Vec3& origin = r.getCamera().getWorldTransform().getOrigin();
-	float radius = r.getCamera().getZNear() + THRESHOLD;
-	bool inside =  lcam.insideFrustum(Sphere(origin, radius));
-
-	// set GL state
-	setUpGl(inside);
-
-	// Calc the camera shape scale matrix
-	Mat4 localMat(Mat4::getIdentity());
-	const Geom& cg = camGeom[lcam.getCameraType()];
-
-	switch(lcam.getCameraType())
-	{
-		case Camera::CT_PERSPECTIVE:
-		{
-			const PerspectiveCamera& pcam =
-				static_cast<const PerspectiveCamera&>(lcam);
-			// Scale in x
-			localMat(0, 0) = tan(pcam.getFovX() / 2.0) * pcam.getZFar();
-			// Scale in y
-			localMat(1, 1) = tan(pcam.getFovY() / 2.0) * pcam.getZFar();
-			localMat(2, 2) = pcam.getZFar(); // Scale in z
-			break;
-		}
-
-		case Camera::CT_ORTHOGRAPHIC:
-		{
-			const OrthographicCamera& ocam =
-				static_cast<const OrthographicCamera&>(lcam);
-			Vec3 tsl;
-			float left = ocam.getLeft();
-			float right = ocam.getRight();
-			float zNear = ocam.getZNear();
-			float zFar = ocam.getZFar();
-			float top = ocam.getTop();
-			float bottom = ocam.getBottom();
-
-			localMat(0, 0) = (right - left) / 2.0;
-			tsl.x() = (right + left) / 2.0;
-
-			localMat(1, 1) = (top - bottom) / 2.0;
-			tsl.y() = (top + bottom) / 2.0;
-
-			localMat(2, 2) = (zFar - zNear) / 2.0;
-			tsl.z() = -(zNear + zFar) / 2.0;
-
-			localMat.setTranslationPart(tsl);
-			break;
-		}
-
-		case Camera::CT_NUM:
-			ANKI_ASSERT(false && "WTF?");
-			break;
-	}
-
-	// Setup the sprog
-	sProg->bind();
-	Mat4 modelMat = Mat4(lcam.getWorldTransform());
-
-	Mat4 trf = r.getViewProjectionMat() * modelMat * localMat;
-	sProg->findUniformVariableByName("modelViewProjectionMat").set(trf);
-
-	//
-	// Render
-	//
-	//mesh->get
-
-	cg.vao.bind();
-	glDrawElements(GL_TRIANGLES, cg.mesh->getVertIdsNum(),
-		GL_UNSIGNED_SHORT, 0);
-	cg.vao.unbind();
-
-	// restore GL state
-	restoreGl(inside);
 }
 
 

+ 9 - 38
anki/renderer/Smo.h

@@ -2,57 +2,28 @@
 #define ANKI_RENDERER_SMO_H
 
 #include "anki/renderer/RenderingPass.h"
-#include "anki/gl/Fbo.h"
-#include "anki/resource/ShaderProgram.h"
-#include "anki/resource/Resource.h"
-#include "anki/gl/Vbo.h"
-#include "anki/gl/Vao.h"
-#include "anki/scene/Camera.h"
 
 
 namespace anki {
 
 
-class PointLight;
-class SpotLight;
+class Light;
 
 
 /// Stencil masking optimizations
 class Smo: public RenderingPass
 {
-	public:
-		Smo(Renderer& r_)
-		:	RenderingPass(r_)
-		{}
+public:
+	Smo(Renderer& r_)
+		: RenderingPass(r_)
+	{}
 
-		~Smo();
-		void init(const RendererInitializer& initializer);
-		void run(const PointLight& light);
-		void run(const SpotLight& light);
+	~Smo();
 
-	private:
-		/// @todo
-		struct Geom
-		{
-			Geom();
-			~Geom();
+	void init(const RendererInitializer& initializer);
+	void run(const Light& light);
 
-			MeshResourcePointer mesh;
-			Vao vao;
-		};
-
-		Geom sphereGeom;
-
-		/// An array of geometry stuff. For perspective cameras the shape is a
-		/// pyramid, see the blend file with the vertex positions
-		boost::array<Geom, Camera::CT_NUM> camGeom;
-
-		ShaderProgramResourcePointer sProg;
-
-		void initCamGeom();
-
-		void setUpGl(bool inside);
-		void restoreGl(bool inside);
+private:
 };
 
 

+ 7 - 0
anki/resource/Model.h

@@ -13,6 +13,8 @@ namespace anki {
 
 
 /// Model patch interface class
+///
+/// Its very important class and it binds the material with the mesh
 class ModelPatchBase
 {
 public:
@@ -32,6 +34,11 @@ public:
 		return *vaosMap.at(key);
 	}
 
+	uint getIndecesNumber(uint lod) const
+	{
+		return getMeshBase().getIndicesNumber(lod);
+	}
+
 protected:
 	VaosContainer vaos;
 	PassLevelToVaoMap vaosMap;

+ 20 - 0
anki/scene/Camera.h

@@ -60,6 +60,26 @@ public:
 	{
 		return viewMat;
 	}
+
+	float getNear() const
+	{
+		return frustum->getNear();
+	}
+	void setNear(float x)
+	{
+		frustum->setNear(x);
+		frustumUpdate();
+	}
+
+	float getFar() const
+	{
+		return frustum->getFar();
+	}
+	void setFar(float x)
+	{
+		frustum->setFar(x);
+		frustumUpdate();
+	}
 	/// @}
 
 	/// @name SceneNode virtuals

+ 2 - 1
anki/scene/Light.h

@@ -36,7 +36,8 @@ public:
 	enum LightType
 	{
 		LT_POINT,
-		LT_SPOT
+		LT_SPOT,
+		LT_NUM
 	};
 
 	/// @name Constructors

+ 2 - 2
anki/scene/SkinNode.h

@@ -34,11 +34,11 @@ public:
 	};
 
 	/// Create the @a tfVbos with empty data
-	SkinMesh(const MeshBase* mesh_);
+	SkinMesh(const MeshBase* mesh);
 
 	/// @name Accessors
 	/// @{
-	const Vbo* getTfVbo(TfVboId id) const
+	const Vbo* getTfVbo(TfVboId id) const /// XXX Why pointer?
 	{
 		return &tfVbos[id];
 	}