Explorar o código

- Implementing the LOD calculation in the renderer
- Optimizing the standard shaders by adding a few locks
- Extend the material a bit

Panagiotis Christopoulos Charitos %!s(int64=14) %!d(string=hai) anos
pai
achega
30b6e4c50d

+ 3 - 1
CMakeLists.txt

@@ -136,7 +136,9 @@ ELSEIF(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
 ENDIF()
 
 IF(CMAKE_BUILD_TYPE STREQUAL Debug)
-	ADD_DEFINITIONS("-D_GLIBCXX_DEBUG -D_GLIBXX_DEBUG_PEDANTIC")
+	# Removed because they do not work with boost::regexpr and who knows what
+	# else
+	#ADD_DEFINITIONS("-D_GLIBCXX_DEBUG -D_GLIBXX_DEBUG_PEDANTIC")
 ELSE()
 	ADD_DEFINITIONS("-DBOOST_DISABLE_ASSERTS -mtune=core2 -ffast-math")
 ENDIF()

+ 1 - 1
anki/renderer/Ez.cpp

@@ -70,7 +70,7 @@ void Ez::run()
 
 	BOOST_FOREACH(RenderableNode* node, cam.getVisibleMsRenderableNodes())
 	{
-		r.getSceneDrawer().renderRenderableNode(cam, PassLevelKey(1, 0), *node);
+		r.getSceneDrawer().renderRenderableNode(cam, 1, *node);
 	}
 
 	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

+ 1 - 1
anki/renderer/Ms.cpp

@@ -120,7 +120,7 @@ void Ms::run()
 		r.getCamera().getVisibleMsRenderableNodes())
 	{
 		r.getSceneDrawer().renderRenderableNode(r.getCamera(),
-			PassLevelKey(0, 0), *node);
+			0, *node);
 	}
 
 	// restore depth

+ 4 - 26
anki/renderer/Renderer.cpp

@@ -8,30 +8,20 @@ namespace anki {
 
 
 //==============================================================================
-// Constructor                                                                 =
-//==============================================================================
-Renderer::Renderer():
-	ms(*this),
-	is(*this),
-	pps(*this),
-	bs(*this),
-	width(640),
-	height(480),
-	sceneDrawer(*this)
+Renderer::Renderer()
+	: ms(*this), is(*this), pps(*this), bs(*this), width(640), height(480),
+		sceneDrawer(*this)
 {
 	enableStagesProfilingFlag = false;
+	lodDistance = 3.0;
 }
 
 
-//==============================================================================
-// Destructor                                                                  =
 //==============================================================================
 Renderer::~Renderer()
 {}
 
 
-//==============================================================================
-// init                                                                        =
 //==============================================================================
 void Renderer::init(const RendererInitializer& initializer)
 {
@@ -75,8 +65,6 @@ void Renderer::init(const RendererInitializer& initializer)
 }
 
 
-//==============================================================================
-// render                                                                      =
 //==============================================================================
 void Renderer::render(Camera& cam_)
 {
@@ -129,8 +117,6 @@ void Renderer::render(Camera& cam_)
 }
 
 
-//==============================================================================
-// drawQuad                                                                    =
 //==============================================================================
 void Renderer::drawQuad()
 {
@@ -141,8 +127,6 @@ void Renderer::drawQuad()
 }
 
 
-//==============================================================================
-// unproject                                                                   =
 //==============================================================================
 Vec3 Renderer::unproject(const Vec3& windowCoords, const Mat4& modelViewMat,
 	const Mat4& projectionMat, const int view[4])
@@ -163,8 +147,6 @@ Vec3 Renderer::unproject(const Vec3& windowCoords, const Mat4& modelViewMat,
 }
 
 
-//==============================================================================
-// createFai                                                                   =
 //==============================================================================
 void Renderer::createFai(uint width, uint height, int internalFormat,
 	int format, int type, Texture& fai)
@@ -185,8 +167,6 @@ void Renderer::createFai(uint width, uint height, int internalFormat,
 }
 
 
-//==============================================================================
-// calcPlanes                                                                  =
 //==============================================================================
 void Renderer::calcPlanes(const Vec2& cameraRange, Vec2& planes)
 {
@@ -198,8 +178,6 @@ void Renderer::calcPlanes(const Vec2& cameraRange, Vec2& planes)
 }
 
 
-//==============================================================================
-// calcLimitsOfNearPlane                                                       =
 //==============================================================================
 void Renderer::calcLimitsOfNearPlane(const PerspectiveCamera& pcam,
 	Vec2& limitsOfNearPlane)

+ 235 - 228
anki/renderer/Renderer.h

@@ -35,234 +35,241 @@ class ModelNode;
 /// for security cameras for example
 class Renderer
 {
-	public:
-		/// The types of rendering a ModelNode
-		enum ModelNodeRenderType
-		{
-			MNRT_MS, ///< In material stage
-			MNRT_DP, ///< In a depth pass
-			MNRT_BS  ///< In blending stage
-		};
-
-		Renderer();
-		~Renderer();
-
-		/// @name Accessors
-		/// @{
-		const Ms& getMs() const
-		{
-			return ms;
-		}
-		Ms& getMs()
-		{
-			return ms;
-		}
-
-		const Is& getIs() const
-		{
-			return is;
-		}
-		Is& getIs()
-		{
-			return is;
-		}
-
-		const Pps& getPps() const
-		{
-			return pps;
-		}
-		Pps& getPps()
-		{
-			return pps;
-		}
-
-		uint getWidth() const
-		{
-			return width;
-		}
-
-		uint getHeight() const
-		{
-			return height;
-		}
-
-		float getAspectRatio() const
-		{
-			return float(width) / height;
-		}
-
-		uint getFramesNum() const
-		{
-			return framesNum;
-		}
-
-		const Mat4& getViewProjectionMat() const
-		{
-			return viewProjectionMat;
-		}
-
-		const Camera& getCamera() const
-		{
-			return *cam;
-		}
-		Camera& getCamera()
-		{
-			return *cam;
-		}
-
-		const SceneDrawer& getSceneDrawer() const
-		{
-			return sceneDrawer;
-		}
-		SceneDrawer& getSceneDrawer()
-		{
-			return sceneDrawer;
-		}
-
-		const Vec2& getPlanes() const
-		{
-			return planes;
-		}
-
-		const Vec2& getLimitsOfNearPlane() const
-		{
-			return limitsOfNearPlane;
-		}
-
-		const Vec2& getLimitsOfNearPlane2() const
-		{
-			return limitsOfNearPlane2;
-		}
-
-		double getMsTime() const
-		{
-			return msTime;
-		}
-
-		double getIsTime() const
-		{
-			return isTime;
-		}
-
-		double getPpsTime() const
-		{
-			return ppsTime;
-		}
-
-		double getBsTime() const
-		{
-			return bsTime;
-		}
-
-		bool getStagesProfilingEnabled() const
-		{
-			return enableStagesProfilingFlag;
-		}
-		bool& getStagesProfilingEnabled()
-		{
-			return enableStagesProfilingFlag;
-		}
-		void setStagesProfilingEnabled(const bool x)
-		{
-			enableStagesProfilingFlag = x;
-		}
-		/// @}
-
-		/// Init the renderer given an initialization class
-		/// @param initializer The initializer class
-		void init(const RendererInitializer& initializer);
-
-		/// This function does all the rendering stages and produces a final FAI
-		/// @param cam The camera from where the rendering will be done
-		void render(Camera& cam);
-
-		/// My version of gluUnproject
-		/// @param windowCoords Window screen coords
-		/// @param modelViewMat The modelview matrix
-		/// @param projectionMat The projection matrix
-		/// @param view The view vector
-		/// @return The unprojected coords
-		static Vec3 unproject(const Vec3& windowCoords,
-			const Mat4& modelViewMat, const Mat4& projectionMat,
-			const int view[4]);
-
-		/// Draws a quad. Actually it draws 2 triangles because OpenGL will no
-		/// longer support quads
-		void drawQuad();
-
-		/// Create FAI texture
-		static void createFai(uint width, uint height, int internalFormat,
-			int format, int type, Texture& fai);
-
-		/// Calculate the planes needed for the calculation of the fragment
-		/// position z in view space. Having the fragment's depth, the camera's
-		/// zNear and zFar the z of the fragment is being calculated inside the
-		/// fragment shader from:
-		/// @code z = (- zFar * zNear) / (zFar - depth * (zFar - zNear))
-		/// @endcode
-		/// The above can be optimized and this method actually pre-calculates a
-		/// few things in order to lift a few calculations from the fragment
-		/// shader. So the z is:
-		/// @code z =  -planes.y / (planes.x + depth) @endcode
-		/// @param[in] cameraRange The zNear, zFar
-		/// @param[out] planes The planes
-		static void calcPlanes(const Vec2& cameraRange, Vec2& planes);
-
-		/// Calculates two values needed for the calculation of the fragment
-		/// position in view space.
-		static void calcLimitsOfNearPlane(const PerspectiveCamera& cam,
-			Vec2& limitsOfNearPlane);
-
-	protected:
-		/// @name Rendering stages
-		/// @{
-		Ms ms; ///< Material rendering stage
-		Is is; ///< Illumination rendering stage
-		Pps pps; ///< Postprocessing rendering stage
-		Bs bs; ///< Blending stage
-		/// @}
-
-		/// @name Profiling stuff
-		/// @{
-		double msTime, isTime, ppsTime, bsTime;
-		boost::scoped_ptr<TimeQuery> msTq, isTq, ppsTq, bsTq;
-		bool enableStagesProfilingFlag;
-		/// @}
-
-		/// Width of the rendering. Don't confuse with the window width
-		uint width;
-		/// Height of the rendering. Don't confuse with the window width
-		uint height;
-		Camera* cam; ///< Current camera
-		/// Max color attachments an FBO can accept
-		static int maxColorAtachments;
-		SceneDrawer sceneDrawer;
-
-		/// @name Optimization vars
-		/// Used in other stages
-		/// @{
-
-		/// Used to to calculate the frag pos in view space inside a few shader
-		/// programs
-		Vec2 planes;
-		/// Used to to calculate the frag pos in view space inside a few shader
-		/// programs
-		Vec2 limitsOfNearPlane;
-		/// Used to to calculate the frag pos in view space inside a few shader
-		/// programs
-		Vec2 limitsOfNearPlane2;
-		/// @}
-
-	private:
-		uint framesNum; ///< Frame number
-		Mat4 viewProjectionMat; ///< Precalculated in case anyone needs it
-
-		/// @name For drawing a quad into the active framebuffer
-		/// @{
-		Vbo quadPositionsVbo; ///< The VBO for quad positions
-		Vbo quadVertIndecesVbo; ///< The VBO for quad array buffer elements
-		Vao quadVao; ///< This VAO is used everywhere except material stage
-		/// @}
+public:
+	/// The types of rendering a ModelNode
+	enum ModelNodeRenderType
+	{
+		MNRT_MS, ///< In material stage
+		MNRT_DP, ///< In a depth pass
+		MNRT_BS  ///< In blending stage
+	};
+
+	Renderer();
+	~Renderer();
+
+	/// @name Accessors
+	/// @{
+	const Ms& getMs() const
+	{
+		return ms;
+	}
+	Ms& getMs()
+	{
+		return ms;
+	}
+
+	const Is& getIs() const
+	{
+		return is;
+	}
+	Is& getIs()
+	{
+		return is;
+	}
+
+	const Pps& getPps() const
+	{
+		return pps;
+	}
+	Pps& getPps()
+	{
+		return pps;
+	}
+
+	uint getWidth() const
+	{
+		return width;
+	}
+
+	uint getHeight() const
+	{
+		return height;
+	}
+
+	float getAspectRatio() const
+	{
+		return float(width) / height;
+	}
+
+	uint getFramesNum() const
+	{
+		return framesNum;
+	}
+
+	const Mat4& getViewProjectionMat() const
+	{
+		return viewProjectionMat;
+	}
+
+	const Camera& getCamera() const
+	{
+		return *cam;
+	}
+	Camera& getCamera()
+	{
+		return *cam;
+	}
+
+	const SceneDrawer& getSceneDrawer() const
+	{
+		return sceneDrawer;
+	}
+	SceneDrawer& getSceneDrawer()
+	{
+		return sceneDrawer;
+	}
+
+	const Vec2& getPlanes() const
+	{
+		return planes;
+	}
+
+	const Vec2& getLimitsOfNearPlane() const
+	{
+		return limitsOfNearPlane;
+	}
+
+	const Vec2& getLimitsOfNearPlane2() const
+	{
+		return limitsOfNearPlane2;
+	}
+
+	double getMsTime() const
+	{
+		return msTime;
+	}
+
+	double getIsTime() const
+	{
+		return isTime;
+	}
+
+	double getPpsTime() const
+	{
+		return ppsTime;
+	}
+
+	double getBsTime() const
+	{
+		return bsTime;
+	}
+
+	bool getStagesProfilingEnabled() const
+	{
+		return enableStagesProfilingFlag;
+	}
+	bool& getStagesProfilingEnabled()
+	{
+		return enableStagesProfilingFlag;
+	}
+	void setStagesProfilingEnabled(const bool x)
+	{
+		enableStagesProfilingFlag = x;
+	}
+	/// @}
+
+	/// Init the renderer given an initialization class
+	/// @param initializer The initializer class
+	void init(const RendererInitializer& initializer);
+
+	/// This function does all the rendering stages and produces a final FAI
+	/// @param cam The camera from where the rendering will be done
+	void render(Camera& cam);
+
+	/// My version of gluUnproject
+	/// @param windowCoords Window screen coords
+	/// @param modelViewMat The modelview matrix
+	/// @param projectionMat The projection matrix
+	/// @param view The view vector
+	/// @return The unprojected coords
+	static Vec3 unproject(const Vec3& windowCoords,
+		const Mat4& modelViewMat, const Mat4& projectionMat,
+		const int view[4]);
+
+	/// Draws a quad. Actually it draws 2 triangles because OpenGL will no
+	/// longer support quads
+	void drawQuad();
+
+	/// Create FAI texture
+	static void createFai(uint width, uint height, int internalFormat,
+		int format, int type, Texture& fai);
+
+	/// Calculate the planes needed for the calculation of the fragment
+	/// position z in view space. Having the fragment's depth, the camera's
+	/// zNear and zFar the z of the fragment is being calculated inside the
+	/// fragment shader from:
+	/// @code z = (- zFar * zNear) / (zFar - depth * (zFar - zNear))
+	/// @endcode
+	/// The above can be optimized and this method actually pre-calculates a
+	/// few things in order to lift a few calculations from the fragment
+	/// shader. So the z is:
+	/// @code z =  -planes.y / (planes.x + depth) @endcode
+	/// @param[in] cameraRange The zNear, zFar
+	/// @param[out] planes The planes
+	static void calcPlanes(const Vec2& cameraRange, Vec2& planes);
+
+	/// Calculates two values needed for the calculation of the fragment
+	/// position in view space.
+	static void calcLimitsOfNearPlane(const PerspectiveCamera& cam,
+		Vec2& limitsOfNearPlane);
+
+	/// Get the LOD given the distance of an object from the camera
+	uint calculateLod(float distance) const
+	{
+		return distance / lodDistance;
+	}
+
+protected:
+	/// @name Rendering stages
+	/// @{
+	Ms ms; ///< Material rendering stage
+	Is is; ///< Illumination rendering stage
+	Pps pps; ///< Postprocessing rendering stage
+	Bs bs; ///< Blending stage
+	/// @}
+
+	/// @name Profiling stuff
+	/// @{
+	double msTime, isTime, ppsTime, bsTime;
+	boost::scoped_ptr<TimeQuery> msTq, isTq, ppsTq, bsTq;
+	bool enableStagesProfilingFlag;
+	/// @}
+
+	/// Width of the rendering. Don't confuse with the window width
+	uint width;
+	/// Height of the rendering. Don't confuse with the window width
+	uint height;
+	Camera* cam; ///< Current camera
+	/// Max color attachments an FBO can accept
+	static int maxColorAtachments;
+	SceneDrawer sceneDrawer;
+	float lodDistance; ///< Distance that used to calculate the LOD
+
+	/// @name Optimization vars
+	/// Used in other stages
+	/// @{
+
+	/// Used to to calculate the frag pos in view space inside a few shader
+	/// programs
+	Vec2 planes;
+	/// Used to to calculate the frag pos in view space inside a few shader
+	/// programs
+	Vec2 limitsOfNearPlane;
+	/// Used to to calculate the frag pos in view space inside a few shader
+	/// programs
+	Vec2 limitsOfNearPlane2;
+	/// @}
+
+private:
+	uint framesNum; ///< Frame number
+	Mat4 viewProjectionMat; ///< Precalculated in case anyone needs it
+
+	/// @name For drawing a quad into the active framebuffer
+	/// @{
+	Vbo quadPositionsVbo; ///< The VBO for quad positions
+	Vbo quadVertIndecesVbo; ///< The VBO for quad array buffer elements
+	Vao quadVao; ///< This VAO is used everywhere except material stage
+	/// @}
 };
 
 

+ 9 - 1
anki/renderer/SceneDrawer.cpp

@@ -9,6 +9,7 @@
 #include "anki/scene/MaterialRuntime.h"
 #include "anki/gl/GlStateMachine.h"
 #include <boost/foreach.hpp>
+#include <algorithm>
 
 
 namespace anki {
@@ -268,11 +269,18 @@ void SceneDrawer::setupShaderProg(
 
 //==============================================================================
 void SceneDrawer::renderRenderableNode(const Camera& cam,
-	const PassLevelKey& key, RenderableNode& node) const
+	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);
 

+ 1 - 1
anki/renderer/SceneDrawer.h

@@ -30,7 +30,7 @@ public:
 	{}
 
 	void renderRenderableNode(const Camera& cam,
-		const PassLevelKey& key, RenderableNode& renderable) const;
+		uint pass, RenderableNode& renderable) const;
 
 private:
 	/// Standard attribute variables that are acceptable inside the

+ 1 - 1
anki/renderer/Sm.cpp

@@ -154,7 +154,7 @@ void Sm::run(Light& light, float distance)
 			{
 				const SpotLight& sl = static_cast<const SpotLight&>(light);
 				r.getSceneDrawer().renderRenderableNode(sl.getCamera(),
-					PassLevelKey(1, 0), *node);
+					1, *node);
 				break;
 			}
 

+ 1 - 1
anki/resource/Material.cpp

@@ -262,7 +262,7 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 		{
 			std::stringstream src;
 
-			src << "#define LOD_" << level << std::endl;
+			src << "#define LOD " << level << std::endl;
 			src << "#define PASS_" << passes[pid] << std::endl;
 			src << mspc.getShaderProgramSource() << std::endl;
 

+ 3 - 0
anki/resource/MaterialShaderProgramCreator.cpp

@@ -195,7 +195,10 @@ void MaterialShaderProgramCreator::parseOperationTag(
 	}
 	
 	line << ");";
+
+	srcLines.push_back("#if defined(" + funcName + "_DEFINED)");
 	srcLines.push_back("\t" + line.str());
+	srcLines.push_back("#endif");
 }
 
 

+ 81 - 85
anki/ui/UiFtFontLoader.h

@@ -17,99 +17,95 @@ namespace anki {
 /// gather the metrics for each glyph
 class UiFtFontLoader
 {
-	public:
-		/// Contains info about the glyphs
-		class Glyph
-		{
-			friend class UiFtFontLoader;
-
-			public:
-				FT_Glyph_Metrics getMetrics() const
-				{
-					return metrics;
-				}
-
-			private:
-				FT_Glyph glyph;
-				FT_Glyph_Metrics metrics;
-		};
-
-		enum
-		{
-			GLYPHS_NUM = 128,
-			GLYPH_COLUMNS = 16,
-			GLYPH_ROWS = 8
-		};
-
-		/// One and only constructor
-		UiFtFontLoader(const char* filename, const FT_Vector& fontSize);
-
-		/// @name Accessors
-		/// @{
-		const uchar* getImage() const
-		{
-			return &img[0];
-		}
-
-		const FT_Vector& getImageSize() const
-		{
-			return imgSize;
-		}
-
-		boost::iterator_range<std::vector<Glyph>::const_iterator>
-			getGlyphs() const
-		{
-			return boost::iterator_range<std::vector<Glyph>::const_iterator>(
-				glyphs.begin(), glyphs.end());
-		}
-
-		uint getLineHeight() const
-		{
-			return lineHeight;
-		}
-		/// @}
-
-		/// Save the image (img) to TGA. Its for debugging purposes
-		void saveImage(const char* filename) const;
+public:
+	/// Contains info about the glyphs
+	class Glyph
+	{
+		friend class UiFtFontLoader;
 
-		static FT_Int toPixels(FT_Int a)
+	public:
+		FT_Glyph_Metrics getMetrics() const
 		{
-			return a >> 6;
+			return metrics;
 		}
 
 	private:
-		/// @name Data
-		/// @{
-		FT_Library library;
-		FT_Face face;
-		std::vector<Glyph> glyphs;
-		std::vector<uchar> img;
-		FT_Vector imgSize;
-		uint lineHeight; ///< Calculated as the max height among all glyphs
-		/// @}
-
-		/// Reads the face and extracts the glyphs
-		void getAllGlyphs();
-
-		/// Copy one bitmap to img
-		void copyBitmap(const uchar* srcImg, const FT_Vector& srcSize,
-			const FT_Vector& pos);
-
-		/// Compute image size (imgSize) using the glyphs set
-		void computeImageSize();
-
-		/// Given a filename and a font size create an image with all the glyphs
-		void createImage(const char* filename, const FT_Vector& fontSize);
+		FT_Glyph glyph;
+		FT_Glyph_Metrics metrics;
+	};
+
+	enum
+	{
+		GLYPHS_NUM = 128,
+		GLYPH_COLUMNS = 16,
+		GLYPH_ROWS = 8
+	};
+
+	/// One and only constructor
+	UiFtFontLoader(const char* filename, const FT_Vector& fontSize)
+	{
+		createImage(filename, fontSize);
+	}
+
+	/// @name Accessors
+	/// @{
+	const uchar* getImage() const
+	{
+		return &img[0];
+	}
+
+	const FT_Vector& getImageSize() const
+	{
+		return imgSize;
+	}
+
+	boost::iterator_range<std::vector<Glyph>::const_iterator>
+		getGlyphs() const
+	{
+		return boost::iterator_range<std::vector<Glyph>::const_iterator>(
+			glyphs.begin(), glyphs.end());
+	}
+
+	uint getLineHeight() const
+	{
+		return lineHeight;
+	}
+	/// @}
+
+	/// Save the image (img) to TGA. Its for debugging purposes
+	void saveImage(const char* filename) const;
+
+	static FT_Int toPixels(FT_Int a)
+	{
+		return a >> 6;
+	}
+
+private:
+	/// @name Data
+	/// @{
+	FT_Library library;
+	FT_Face face;
+	std::vector<Glyph> glyphs;
+	std::vector<uchar> img;
+	FT_Vector imgSize;
+	uint lineHeight; ///< Calculated as the max height among all glyphs
+	/// @}
+
+	/// Reads the face and extracts the glyphs
+	void getAllGlyphs();
+
+	/// Copy one bitmap to img
+	void copyBitmap(const uchar* srcImg, const FT_Vector& srcSize,
+		const FT_Vector& pos);
+
+	/// Compute image size (imgSize) using the glyphs set
+	void computeImageSize();
+
+	/// Given a filename and a font size create an image with all the glyphs
+	void createImage(const char* filename, const FT_Vector& fontSize);
 };
 
 
-inline UiFtFontLoader::UiFtFontLoader(const char* filename,
-	const FT_Vector& fontSize)
-{
-	createImage(filename, fontSize);
-}
-
-
 } // end namespace
 
 

+ 65 - 65
anki/ui/UiPainter.h

@@ -17,71 +17,71 @@ class UiFont;
 /// @todo
 class UiPainter
 {
-	public:
-		UiPainter(const Vec2& deviceSize);
-
-		/// @name Accessors
-		/// @{
-		const Vec2& getPosition() const
-		{
-			return pos;
-		}
-		Vec2& getPosition()
-		{
-			return pos;
-		}
-		void setPosition(const Vec2& x)
-		{
-			pos = x;
-		}
-
-		const Vec4& getColor() const
-		{
-			return col;
-		}
-		Vec4& getColor()
-		{
-			return col;
-		}
-		void setColor(const Vec4& x)
-		{
-			col = x;
-		}
-
-		void setFont(const char* fontFilename, uint nominalWidth,
-			uint nominalHeight);
-
-		const UiFont& getFont() const
-		{
-			return *font;
-		}
-		/// @}
-
-		void drawText(const char* text);
-		void drawText(const std::string& str)
-		{
-			drawText(str.c_str());
-		}
-		void drawFormatedText(const char* format, ...);
-
-	private:
-		/// @name Data
-		/// @{
-		boost::scoped_ptr<UiFont> font;
-		ShaderProgramResourcePointer sProg;
-
-		Vec2 pos;
-		Vec4 col;
-		uint tabSize;
-
-		Vbo qPositionsVbo;
-		Vbo qIndecesVbo;
-		Vao qVao;
-
-		Vec2 deviceSize; ///< The size of the device in pixels
-		/// @}
-
-		void init();
+public:
+	UiPainter(const Vec2& deviceSize);
+
+	/// @name Accessors
+	/// @{
+	const Vec2& getPosition() const
+	{
+		return pos;
+	}
+	Vec2& getPosition()
+	{
+		return pos;
+	}
+	void setPosition(const Vec2& x)
+	{
+		pos = x;
+	}
+
+	const Vec4& getColor() const
+	{
+		return col;
+	}
+	Vec4& getColor()
+	{
+		return col;
+	}
+	void setColor(const Vec4& x)
+	{
+		col = x;
+	}
+
+	void setFont(const char* fontFilename, uint nominalWidth,
+		uint nominalHeight);
+
+	const UiFont& getFont() const
+	{
+		return *font;
+	}
+	/// @}
+
+	void drawText(const char* text);
+	void drawText(const std::string& str)
+	{
+		drawText(str.c_str());
+	}
+	void drawFormatedText(const char* format, ...);
+
+private:
+	/// @name Data
+	/// @{
+	boost::scoped_ptr<UiFont> font;
+	ShaderProgramResourcePointer sProg;
+
+	Vec2 pos;
+	Vec4 col;
+	uint tabSize;
+
+	Vbo qPositionsVbo;
+	Vbo qIndecesVbo;
+	Vao qVao;
+
+	Vec2 deviceSize; ///< The size of the device in pixels
+	/// @}
+
+	void init();
 };
 
 

+ 10 - 10
anki/ui/UiPainterDevice.h

@@ -14,19 +14,19 @@ class Texture;
 /// This actually and FBO but with size info
 class UiPainterDevice: public Fbo
 {
-	public:
-		/// Constructor
-		UiPainterDevice(Texture& colorFai);
+public:
+	/// Constructor
+	UiPainterDevice(Texture& colorFai);
 
-		/// @name Accessors
-		/// @{
-		Vec2 getSize() const;
-		/// @}
+	/// @name Accessors
+	/// @{
+	Vec2 getSize() const;
+	/// @}
 
-	private:
-		Texture& colorFai;
+private:
+	Texture& colorFai;
 
-		void create();
+	void create();
 };
 
 

+ 2 - 3
anki/util/HighRezTimer.cpp

@@ -7,9 +7,8 @@ namespace anki {
 
 
 //==============================================================================
-HighRezTimer::HighRezTimer():
-	startTime(0.0),
-	stopTime(0.0)
+HighRezTimer::HighRezTimer()
+	: startTime(0.0), stopTime(0.0)
 {}
 
 

+ 33 - 35
shaders/MaterialFragmentFunctions.glsl

@@ -1,22 +1,25 @@
-///
+/// @file 
+/// The file contains common functions for fragment operations
 #pragma anki include "shaders/Pack.glsl"
 
 
 #define MAX_SHININESS 128.0
 
 
-//==============================================================================
-// getNormalFromTexture                                                        =
 //==============================================================================
 /// @param[in] normal The fragment's normal in view space
 /// @param[in] tangent The tangent
 /// @param[in] tangent Extra stuff for the tangent
 /// @param[in] map The map
 /// @param[in] texCoords Texture coordinates
+#if defined(PASS_COLOR)
+#	define getNormalFromTexture_DEFINED
 vec3 getNormalFromTexture(in vec3 normal, in vec3 tangent, in float tangentW,
 	in sampler2D map, in vec2 texCoords)
 {
-#if defined(PASS_COLOR)
+#	if LOD > 0
+	return normalize(normal);
+#	else
 	vec3 n = normalize(normal);
 	vec3 t = normalize(tangent);
 	vec3 b = cross(n, t) * tangentW;
@@ -26,38 +29,36 @@ vec3 getNormalFromTexture(in vec3 normal, in vec3 tangent, in float tangentW,
 	vec3 nAtTangentspace = (texture(map, texCoords).rgb - 0.5) * 2.0;
 
 	return normalize(tbnMat * nAtTangentspace);
-#else
-	return vec3(0.0);
-#endif
+#	endif
 }
+#endif
 
 
-//==============================================================================
-// getNormalSimple                                                             =
 //==============================================================================
 /// Just normalize
+#if defined(PASS_COLOR)
+#	define getNormalSimple_DEFINED
 vec3 getNormalSimple(in vec3 normal)
 {
-#if defined(PASS_COLOR)
 	return normalize(normal);
-#else
-	return vec3(0.0);
-#endif
 }
+#endif
 
 
-//==============================================================================
-// getEnvironmentColor                                                         =
 //==============================================================================
 /// Environment mapping calculations
 /// @param[in] vertPosViewSpace Fragment position in view space
 /// @param[in] normal Fragment's normal in view space as well
 /// @param[in] map The env map
 /// @return The color
+#if defined(PASS_COLOR)
+#	define getEnvironmentColor_DEFINED
 vec3 getEnvironmentColor(in vec3 vertPosViewSpace, in vec3 normal,
 	in sampler2D map)
 {
-#if defined(PASS_COLOR)
+#	if LOD > 0
+	return vec3(0.0);
+#	else
 	// In case of normal mapping I could play with vertex's normal but this 
 	// gives better results and its allready computed
 	
@@ -69,14 +70,11 @@ vec3 getEnvironmentColor(in vec3 vertPosViewSpace, in vec3 normal,
 
 	vec3 semCol = texture(map, semTexCoords).rgb;
 	return semCol;
-#else
-	return vec3(0.0);
-#endif
+#	endif
 }
+#endif
 
 
-//==============================================================================
-// getDiffuseColorAndDoAlphaTesting                                            =
 //==============================================================================
 /// Using a 4-channel texture and a tolerance discard the fragment if the 
 /// texture's alpha is less than the tolerance
@@ -84,6 +82,7 @@ vec3 getEnvironmentColor(in vec3 vertPosViewSpace, in vec3 normal,
 /// @param[in] tolerance Tolerance value
 /// @param[in] texCoords Texture coordinates
 /// @return The RGB channels of the map
+#define getDiffuseColorAndDoAlphaTesting_DEFINED
 vec3 getDiffuseColorAndDoAlphaTesting(
 	in sampler2D map,
 	in vec2 texCoords,
@@ -96,34 +95,34 @@ vec3 getDiffuseColorAndDoAlphaTesting(
 		discard;
 	}
 	return col.rgb;
-#else
+#else // Depth
+#	if LOD > 0
+	return vec3(0.0);
+#	else
 	float a = texture(map, texCoords).a;
 	if(a < tolerance)
 	{
 		discard;
 	}
 	return vec3(0.0);
+#	endif
 #endif
 }
 
 
-//==============================================================================
-// readRgbFromTexture                                                          =
 //==============================================================================
 /// Just read the RGB color from texture
+#if defined(PASS_COLOR)
+#	define readRgbFromTexture_DEFINED
 vec3 readRgbFromTexture(in sampler2D tex, in vec2 texCoords)
 {
-#if defined(PASS_COLOR)
 	return texture(tex, texCoords).rgb;
-#else
-	return vec3(0.0);
-#endif
 }
+#endif
 
 
 //==============================================================================
-// add2Vec3                                                                    =
-//==============================================================================
+#define add2Vec3_DEFINED
 vec3 add2Vec3(in vec3 a, in vec3 b)
 {
 	return a + b;
@@ -131,9 +130,9 @@ vec3 add2Vec3(in vec3 a, in vec3 b)
 
 
 //==============================================================================
-// writeFais                                                                   =
-//==============================================================================
-/// XXX
+/// Write the data to FAIs
+#if defined(PASS_COLOR)
+#	define writeFais_DEFINED
 void writeFais(
 	in vec3 diffCol, 
 	in vec3 normal, 
@@ -141,9 +140,8 @@ void writeFais(
 	in float shininess, 
 	in float blurring)
 {
-#if defined(PASS_COLOR)
 	fMsNormalFai = vec3(packNormal(normal), blurring);
 	fMsDiffuseFai = diffCol;
 	fMsSpecularFai = vec4(specularCol, shininess / MAX_SHININESS);
-#endif
 }
+#endif

+ 4 - 0
shaders/MaterialFragmentVariables.glsl

@@ -1,15 +1,19 @@
 /// @name Uniforms
 /// @{
+#if defined(PASS_COLOR)
 uniform float blurring;
+#endif
 /// @}
 
 /// @name Varyings
 /// @{
 in vec2 vTexCoords;
+#if defined(PASS_COLOR)
 in vec3 vNormal;
 in vec3 vTangent;
 in float vTangentW;
 in vec3 vVertPosViewSpace;
+#endif
 /// @}
 
 /// @name Fragment out

+ 8 - 0
shaders/MaterialVertex.glsl

@@ -14,8 +14,10 @@ layout(location = 2) in vec4 tangent;
 /// @name Uniforms
 /// @{
 uniform mat4 modelViewProjectionMat;
+#if defined(PASS_COLOR)
 uniform mat3 normalMat;
 uniform mat4 modelViewMat;
+#endif
 /// @}
 
 /// @name Varyings
@@ -30,7 +32,9 @@ out vec3 vVertPosViewSpace; ///< For env mapping. AKA view vector
 /// @}
 
 
+//==============================================================================
 /// Calculate the position and the varyings
+#define doVertex_DEFINED
 void doVertex()
 {
 #if defined(PASS_COLOR)
@@ -40,7 +44,11 @@ void doVertex()
 	vVertPosViewSpace = vec3(modelViewMat * vec4(position, 1.0));
 #endif
 
+#if defined(PASS_DEPTH) && LOD > 0
+	// No tex coords for you
+#else
 	vTexCoords = texCoords;
+#endif
 
 	gl_Position = modelViewProjectionMat * vec4(position, 1.0);
 }