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

- Removing from ANKI_ASSERT the iostream header
- Adding code to the new material

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

+ 8 - 7
anki/renderer/SceneDrawer.cpp

@@ -7,7 +7,6 @@
 #include "anki/core/App.h"
 #include "anki/scene/Scene.h"
 #include "anki/scene/MaterialRuntime.h"
-#include "anki/scene/MaterialRuntimeVariable.h"
 #include "anki/gl/GlStateMachine.h"
 #include <boost/foreach.hpp>
 
@@ -15,16 +14,11 @@
 namespace anki {
 
 
-//==============================================================================
-// Constructor                                                                 =
 //==============================================================================
 SceneDrawer::UsrDefVarVisitor::UsrDefVarVisitor(
 	const MaterialRuntimeVariable& udvr_,
 	const Renderer& r_, const PassLevelKey& pt_, uint& texUnit_)
-:	udvr(udvr_),
-	r(r_),
-	key(pt_),
-	texUnit(texUnit_)
+	: udvr(udvr_), r(r_), key(pt_), texUnit(texUnit_)
 {}
 
 
@@ -290,4 +284,11 @@ void SceneDrawer::renderRenderableNode(const RenderableNode& node,
 }
 
 
+//==============================================================================
+void SceneDrawer::setTheBuildins(MaterialRuntime& m)
+{
+
+}
+
+
 } // end namespace

+ 3 - 1
anki/renderer/SceneDrawer.h

@@ -25,7 +25,7 @@ class SceneDrawer
 public:
 	/// The one and only constructor
 	SceneDrawer(const Renderer& r_)
-	:	r(r_)
+		: r(r_)
 	{}
 
 	void renderRenderableNode(const RenderableNode& renderable,
@@ -105,6 +105,8 @@ private:
 		const Camera& cam,
 		const Renderer& r,
 		float blurring);
+
+	void setTheBuildins();
 };
 
 

+ 1 - 0
anki/resource/Texture.h

@@ -3,6 +3,7 @@
 
 #include "anki/util/StdTypes.h"
 #include "anki/util/Assert.h"
+#include <cstdlib>
 #include <limits>
 
 

+ 31 - 0
anki/scene/MaterialRuntime.cpp

@@ -2,6 +2,7 @@
 #include "anki/resource/Material.h"
 #include "anki/resource/Texture.h"
 #include "anki/resource/Resource.h"
+#include "anki/resource/ShaderProgram.h"
 #include <boost/foreach.hpp>
 
 
@@ -58,6 +59,36 @@ void MaterialRuntimeVariable::setValue<
 	boost::get<ConstPtrRsrcPtrTexture>(data) = v;
 }
 
+//==============================================================================
+template<typename Type>
+void MaterialRuntimeVariable::SetUniformVisitor::operator()(
+	const Type& x) const
+{
+	uni.set(x);
+}
+
+
+//==============================================================================
+template<>
+void MaterialRuntimeVariable::SetUniformVisitor::
+	operator()<MaterialRuntimeVariable::ConstPtrRsrcPtrTexture>(
+	const ConstPtrRsrcPtrTexture& x) const
+{
+	uni.set(*(x->get()), texUnit);
+	++texUnit;
+}
+
+
+//==============================================================================
+void MaterialRuntimeVariable::setUniformVariable(const PassLevelKey& k,
+	uint& texUnit)
+{
+	const ShaderProgramUniformVariable& uni =
+		mvar.getShaderProgramUniformVariable(k);
+
+	boost::apply_visitor(SetUniformVisitor(uni, texUnit), data);
+}
+
 
 //==============================================================================
 // MaterialRuntime                                                             =

+ 33 - 14
anki/scene/MaterialRuntime.h

@@ -91,24 +91,43 @@ public:
 	}
 	/// @}
 
+	/// Call one of the setters of the uniform variable
+	void setUniformVariable(const PassLevelKey& k, uint& texUnif);
+
 private:
 	/// Initialize the data using a visitor
 	class ConstructVisitor: public boost::static_visitor<void>
 	{
-		public:
-			MaterialRuntimeVariable& var;
-
-			ConstructVisitor(MaterialRuntimeVariable& var_)
-				: var(var_)
-			{}
-
-			/// Template method that applies to all DataVariant values
-			/// except texture resource
-			template<typename Type>
-			void operator()(const Type& x) const
-			{
-				var.getDataVariant() = x;
-			}
+	public:
+		MaterialRuntimeVariable& var;
+
+		ConstructVisitor(MaterialRuntimeVariable& var_)
+			: var(var_)
+		{}
+
+		/// Template method that applies to all Variant values except texture
+		/// resource
+		template<typename Type>
+		void operator()(const Type& x) const
+		{
+			var.getDataVariant() = x;
+		}
+	};
+
+	/// Set visitor
+	class SetUniformVisitor: public boost::static_visitor<void>
+	{
+	public:
+		const ShaderProgramUniformVariable& uni;
+		uint& texUnit;
+
+		SetUniformVisitor(const ShaderProgramUniformVariable& uni_,
+			uint& texUnit_)
+			: uni(uni_), texUnit(texUnit_)
+		{}
+
+		template<typename Type>
+		void operator()(const Type& x) const;
 	};
 
 	const MaterialVariable& mvar; ///< Know the resource

+ 23 - 0
anki/util/Assert.cpp

@@ -0,0 +1,23 @@
+#include <cstdlib>
+#include <iostream>
+
+
+namespace anki {
+
+
+//==============================================================================
+void akassert(bool expr, const char* exprTxt, const char* file, int line,
+	const char* func)
+{
+	if(!expr)
+	{
+		std::cerr << "(" << file << ":" << line << " " <<
+			func << ") " << "Assertion failed: " << exprTxt << std::endl;
+
+		asm("int $3");
+		abort();
+	}
+}
+
+
+} // end namespace

+ 7 - 10
anki/util/Assert.h

@@ -1,23 +1,20 @@
 #ifndef ANKI_UTIL_ASSERT_H
 #define ANKI_UTIL_ASSERT_H
 
-#include <iostream>
-#include <cstdlib>
-
 
 /// Assertion. Print an error and stop the debugger (if it runs through a
 /// debugger) and then abort
 #if defined(NDEBUG)
 #	define ANKI_ASSERT(x) ((void)0)
 #else
+
+/// Its separate so we will not include iostream
+extern void akassert(bool expr, const char* exprTxt, const char* file,
+	int line, const char* func);
+
 #	define ANKI_ASSERT(x) \
-		if(!(x)) { \
-			std::cerr << "(" << __FILE__ << ":" << __LINE__ << " " << \
-				__func__ << ") " << \
-				"Assertion failed: " << #x << std::endl; \
-			asm("int $3"); \
-			abort(); \
-		}
+	akassert((x), #x, __FILE__, __LINE__, __func__)
+
 #endif
 
 

+ 0 - 10
anki/util/BinaryStream.cpp

@@ -6,8 +6,6 @@
 namespace anki {
 
 
-//==============================================================================
-// read32bitNumber                                                             =
 //==============================================================================
 template<typename Type>
 Type BinaryStream::read32bitNumber()
@@ -39,8 +37,6 @@ Type BinaryStream::read32bitNumber()
 }
 
 
-//==============================================================================
-// readUint                                                                    =
 //==============================================================================
 uint BinaryStream::readUint()
 {
@@ -48,8 +44,6 @@ uint BinaryStream::readUint()
 }
 
 
-//==============================================================================
-// readFloat                                                                   =
 //==============================================================================
 float BinaryStream::readFloat()
 {
@@ -57,8 +51,6 @@ float BinaryStream::readFloat()
 }
 
 
-//==============================================================================
-// readString                                                                  =
 //==============================================================================
 std::string BinaryStream::readString()
 {
@@ -90,8 +82,6 @@ std::string BinaryStream::readString()
 }
 
 
-//==============================================================================
-// getMachineByteOrder                                                         =
 //==============================================================================
 BinaryStream::ByteOrder BinaryStream::getMachineByteOrder()
 {

+ 39 - 43
anki/util/BinaryStream.h

@@ -13,52 +13,48 @@ namespace anki {
 /// but it also contains methods for reading/writing binary data
 class BinaryStream: public std::iostream
 {
-	public:
-		/// The 2 available byte orders
-		enum ByteOrder
-		{
-			BO_LITTLE_ENDIAN, ///< The default
-			BO_BIG_ENDIAN
-		};
-
-		/// The one and only constructor
-		/// @param sb An std::streambuf for in/out
-		/// @param byteOrder The stream's byte order
-		BinaryStream(std::streambuf* sb, 
-			ByteOrder byteOrder = BO_LITTLE_ENDIAN);
-
-		/// Read unsigned int (32bit)
-		/// @exception Exception
-		uint readUint();
-
-		/// Read float (32bit)
-		/// @exception Exception
-		float readFloat();
-
-		/// Read a string. It reads the size as an unsigned int and then it 
-		/// reads the characters
-		/// @exception Exception
-		std::string readString();
-
-		/// Get machine byte order
-		/// @return The byte order of the current running platform
-		static ByteOrder getMachineByteOrder();
-
-	private:
-		ByteOrder byteOrder;
-
-		/// A little hack so we dont write duplicate code
-		template<typename Type>
-		Type read32bitNumber();
+public:
+	/// The 2 available byte orders
+	enum ByteOrder
+	{
+		BO_LITTLE_ENDIAN, ///< The default
+		BO_BIG_ENDIAN
+	};
+
+	/// The one and only constructor
+	/// @param sb An std::streambuf for in/out
+	/// @param byteOrder The stream's byte order
+	BinaryStream(std::streambuf* sb,
+		ByteOrder byteOrder_ = BO_LITTLE_ENDIAN)
+		: std::iostream(sb), byteOrder(byteOrder_)
+	{}
+
+	/// Read unsigned int (32bit)
+	/// @exception Exception
+	uint readUint();
+
+	/// Read float (32bit)
+	/// @exception Exception
+	float readFloat();
+
+	/// Read a string. It reads the size as an unsigned int and then it
+	/// reads the characters
+	/// @exception Exception
+	std::string readString();
+
+	/// Get machine byte order
+	/// @return The byte order of the current running platform
+	static ByteOrder getMachineByteOrder();
+
+private:
+	ByteOrder byteOrder;
+
+	/// A little hack so we dont write duplicate code
+	template<typename Type>
+	Type read32bitNumber();
 };
 
 
-inline BinaryStream::BinaryStream(std::streambuf* sb, ByteOrder byteOrder_):
-	std::iostream(sb),
-	byteOrder(byteOrder_)
-{}
-
-
 } // end namespace
 
 

+ 16 - 16
anki/util/Singleton.h

@@ -13,22 +13,22 @@ namespace anki {
 template<typename Type>
 class Singleton
 {
-	public:
-		typedef Type ValueType;
-
-		static Type& get()
-		{
-			return *(instance ? instance : (instance = new Type));
-		}
-
-	protected:
-		Singleton();
-		~Singleton();
-
-	private:
-		static Type* instance;
-		Singleton(Singleton const&);
-		Singleton& operator=(const Singleton&);
+public:
+	typedef Type ValueType;
+
+	static Type& get()
+	{
+		return *(instance ? instance : (instance = new Type));
+	}
+
+protected:
+	Singleton();
+	~Singleton();
+
+private:
+	static Type* instance;
+	Singleton(Singleton const&);
+	Singleton& operator=(const Singleton&);
 };
 
 

+ 8 - 8
anki/util/StringList.h

@@ -11,16 +11,16 @@ namespace anki {
 /// A simple convenience class
 class StringList: public std::vector<std::string>
 {
-	public:
-		typedef std::vector<std::string> Base; ///< Its the vector of strings
-		typedef Base::value_type StringType; ///< Its string
+public:
+	typedef std::vector<std::string> Base; ///< Its the vector of strings
+	typedef Base::value_type StringType; ///< Its string
 
-		/// Return the list as a single string
-		StringType join(const StringType& sep) const;
+	/// Return the list as a single string
+	StringType join(const StringType& sep) const;
 
-		/// XXX
-		static StringList splitString(const StringType& s,
-			const char* sep = " ");
+	/// XXX
+	static StringList splitString(const StringType& s,
+		const char* sep = " ");
 };
 
 

+ 20 - 20
anki/util/Util.h

@@ -12,33 +12,33 @@ namespace anki {
 /// Contains a few useful functions
 class Util
 {
-	public:
-		/// Pick a random number from min to max
-		static int randRange(int min, int max);
+public:
+	/// Pick a random number from min to max
+	static int randRange(int min, int max);
 
-		/// Pick a random number from min to max
-		static uint randRange(uint min, uint max);
+	/// Pick a random number from min to max
+	static uint randRange(uint min, uint max);
 
-		/// Pick a random number from min to max
-		static float randRange(float min, float max);
+	/// Pick a random number from min to max
+	static float randRange(float min, float max);
 
-		/// Pick a random number from min to max
-		static double randRange(double min, double max);
+	/// Pick a random number from min to max
+	static double randRange(double min, double max);
 
-		static float randFloat(float max);
+	static float randFloat(float max);
 
-		/// Open a text file and return its contents into a string
-		static std::string readFile(const char* filename);
+	/// Open a text file and return its contents into a string
+	static std::string readFile(const char* filename);
 
-		/// Open a text file and return its lines into a string vector
-		static std::vector<std::string> getFileLines(const char* filename);
+	/// Open a text file and return its lines into a string vector
+	static std::vector<std::string> getFileLines(const char* filename);
 
-		/// Get the size in bytes of a vector
-		template<typename Vec>
-		static size_t getVectorSizeInBytes(const Vec& v)
-		{
-			return v.size() * sizeof(typename Vec::value_type);
-		}
+	/// Get the size in bytes of a vector
+	template<typename Vec>
+	static size_t getVectorSizeInBytes(const Vec& v)
+	{
+		return v.size() * sizeof(typename Vec::value_type);
+	}
 };