Переглянути джерело

- Modify the Fbo
- Add Scanner exception

Panagiotis Christopoulos Charitos 14 роки тому
батько
коміт
697a3110ae

Різницю між файлами не показано, бо вона завелика
+ 0 - 1
build/debug/Makefile


+ 1 - 0
docs/todo

@@ -1,3 +1,4 @@
 - The light passes in IS should produce 1, 0, 1 and the play with the scene ambient color to see the results of the blending
 - Create n working threads with n contexts and make the IS parallel
 - Put uniform buffers in skinning 
+- Remove the Fbo::unbind from everywhere. There is no need for state change

+ 1 - 0
src/Main.cpp

@@ -39,6 +39,7 @@
 #include "SkinNode.h"
 #include "Skin.h"
 #include "MaterialRuntime.h"
+#include "ScannerException.h"
 
 
 // map (hard coded)

+ 10 - 7
src/Renderer/BufferObjects/Fbo.h

@@ -20,16 +20,16 @@ class Fbo
 		uint getGlId() const;
 
 		/// Binds FBO
-		void bind() const;
+		void bind(GLenum target = GL_FRAMEBUFFER);
 
-		/// Unbinds the FBO. Actually unbinds all FBOs
-		static void unbind();
+		/// Unbinds the FBO
+		void unbind();
 
 		/// Checks the status of an initialized FBO and if fails throw exception
 		/// @exception Exception
 		void checkIfGood() const;
 
-		/// Set the number of color attachements of the FBO
+		/// Set the number of color attachments of the FBO
 		void setNumOfColorAttachements(uint num) const;
 
 		/// Returns the GL id of the current attached FBO
@@ -44,6 +44,7 @@ class Fbo
 
 	private:
 		uint glId; ///< OpenGL identification
+		GLenum target; ///< How the buffer is bind
 
 		bool isCreated() const {return glId != 0;}
 };
@@ -76,16 +77,18 @@ inline Fbo::~Fbo()
 }
 
 
-inline void Fbo::bind() const
+inline void Fbo::bind(GLenum target_)
 {
 	ASSERT(isCreated());
-	glBindFramebuffer(GL_FRAMEBUFFER, glId);
+	target = target_;
+	ASSERT(target == GL_DRAW_FRAMEBUFFER || target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER);
+	glBindFramebuffer(target, glId);
 }
 
 
 inline void Fbo::unbind()
 {
-	glBindFramebuffer(GL_FRAMEBUFFER, 0);
+	glBindFramebuffer(target, 0);
 }
 
 

+ 1 - 1
src/Renderer/Hdr.cpp

@@ -133,5 +133,5 @@ void Hdr::run()
 	}
 
 	// end
-	Fbo::unbind();
+	glBindFramebuffer(GL_FRAMEBUFFER, 0); // Bind the window framebuffer
 }

+ 2 - 1
src/Renderer/MainRenderer.cpp

@@ -95,7 +95,8 @@ void MainRenderer::render(Camera& cam_)
 	//
 	// Render the PPS FAI to the framebuffer
 	//
-	Fbo::unbind();
+	glBindFramebuffer(GL_FRAMEBUFFER, 0); // Bind the window framebuffer
+
 	setViewport(0, 0, AppSingleton::getInstance().getWindowWidth(), AppSingleton::getInstance().getWindowHeight());
 	GlStateMachineSingleton::getInstance().setDepthTestEnabled(false);
 	GlStateMachineSingleton::getInstance().setBlendingEnabled(false);

+ 2 - 2
src/Renderer/Pps.cpp

@@ -131,7 +131,7 @@ void Pps::runPrePass()
 
 	r.drawQuad();
 
-	Fbo::unbind();
+	//Fbo::unbind();
 }
 
 
@@ -161,5 +161,5 @@ void Pps::runPostPass()
 
 	r.drawQuad();
 
-	Fbo::unbind();
+	//Fbo::unbind();
 }

+ 1 - 1
src/Renderer/Ssao.cpp

@@ -174,6 +174,6 @@ void Ssao::run()
 	}
 
 	// end
-	Fbo::unbind();
+	glBindFramebuffer(GL_FRAMEBUFFER, 0); // Bind the window framebuffer
 }
 

+ 1 - 1
src/Resources/SkelAnim.h

@@ -12,7 +12,7 @@ struct BonePose
 	public:
 		BonePose(const Quat& r, const Vec3& trs): rotation(r), translation(trs) {}
 
-		/// Copy contructor
+		/// Copy constructor
 		BonePose(const BonePose& b): rotation(b.rotation), translation(b.translation) {}
 
 		/// @name Accessors

+ 12 - 3
src/Util/Exception.cpp

@@ -25,10 +25,19 @@ Exception::Exception(const Exception& e):
 
 
 //======================================================================================================================
-// init                                                                                                                =
+// getInfoStr                                                                                                          =
+//======================================================================================================================
+std::string Exception::getInfoStr() const
+{
+	return std::string("(") + file + ":" + boost::lexical_cast<std::string>(line) + " " + func + ")";
+}
+
+
+//======================================================================================================================
+// what                                                                                                                =
 //======================================================================================================================
 const char* Exception::what() const throw()
 {
-	err = std::string("\n(") + file + ":" + boost::lexical_cast<std::string>(line) + " " + func + ") " + err;
-	return err.c_str();
+	errWhat = "\n" + getInfoStr() + " " + err;
+	return errWhat.c_str();
 }

+ 12 - 4
src/Util/Exception.h

@@ -18,14 +18,22 @@ class Exception: public std::exception
 		/// Destructor. Do nothing
 		~Exception() throw() {}
 
-		/// Return the error code
-		const char* what() const throw();
+		/// @name Accessors
+		/// @{
+		const std::string& getTheError() const {return err;}
+		/// @}
 
-	private:
-		mutable std::string err;
+		/// Return the error code formated with the other info
+		virtual const char* what() const throw();
+
+	protected:
+		std::string err;
+		mutable std::string errWhat;
 		const char* file;
 		int line;
 		const char* func;
+
+		std::string getInfoStr() const;
 };
 
 

+ 2 - 1
src/Util/Scanner/Scanner.cpp

@@ -8,12 +8,13 @@
 #include "Scanner.h"
 #include "Exception.h"
 #include "Assert.h"
+#include "ScannerException.h"
 
 
 namespace Scanner {
 
 #define SCANNER_EXCEPTION(x) \
-	EXCEPTION("Scanner exception (" + scriptName + ':' + boost::lexical_cast<std::string>(lineNmbr) + "): " + x)
+	Exception(std::string() + x, scriptName, lineNmbr, __FILE__, __LINE__, __func__)
 
 
 //======================================================================================================================

+ 1 - 1
src/Util/Scanner/Scanner.h

@@ -46,7 +46,7 @@ class Scanner
 		/// @param istream_ The stream from where to read
 		/// @param scriptName_ The name of the stream. For error reporting
 		/// @exception Exception
-		void loadIstream(std::istream& istream_, const char* scriptName_);
+		void loadIstream(std::istream& istream_, const char* scriptName_ = "unamed-istream");
 
 		/// Extracts all tokens and prints them. Used for debugging
 		void getAllPrintAll();

+ 40 - 0
src/Util/Scanner/ScannerException.cpp

@@ -0,0 +1,40 @@
+#include <boost/lexical_cast.hpp>
+#include "ScannerException.h"
+
+
+namespace Scanner {
+
+
+//======================================================================================================================
+// Constructor                                                                                                         =
+//======================================================================================================================
+Exception::Exception(const std::string& err, const std::string& scriptFilename_, int scriptLineNmbr_,
+                     const char* file, int line, const char* func):
+	BaseClass(err, file, line, func),
+	scriptFilename(scriptFilename_),
+	scriptLineNmbr(scriptLineNmbr_)
+{}
+
+
+//======================================================================================================================
+// Copy constructor                                                                                                    =
+//======================================================================================================================
+Exception::Exception(const Exception& e):
+	BaseClass(e),
+	scriptFilename(e.scriptFilename),
+	scriptLineNmbr(e.scriptLineNmbr)
+{}
+
+
+//======================================================================================================================
+// what                                                                                                                =
+//======================================================================================================================
+const char* Exception::what() const throw()
+{
+	errWhat = "\n" + getInfoStr() + " Scanner exception (" + scriptFilename + ':' +
+	          boost::lexical_cast<std::string>(scriptLineNmbr) + ") " + err;
+	return errWhat.c_str();
+}
+
+
+} // end namespace

+ 37 - 0
src/Util/Scanner/ScannerException.h

@@ -0,0 +1,37 @@
+#ifndef SCANNER_EXCEPTION_H
+#define SCANNER_EXCEPTION_H
+
+#include "Exception.h"
+
+
+namespace Scanner {
+
+
+class Exception: public ::Exception
+{
+	public:
+		typedef ::Exception BaseClass;
+
+		/// Constructor
+		Exception(const std::string& err, const std::string& scriptFilename, int scriptLineNmbr,
+				  const char* file = "unknown", int line = -1, const char* func = "unknown");
+
+		/// Copy constructor
+		Exception(const Exception& e);
+
+		/// Destructor. Do nothing
+		~Exception() throw() {}
+
+		/// Return the error code
+		virtual const char* what() const throw();
+
+	private:
+		std::string scriptFilename;
+		int scriptLineNmbr;
+};
+
+
+} // End namespace
+
+
+#endif

Деякі файли не було показано, через те що забагато файлів було змінено