Просмотр исходного кода

Rewritting the collision and other stuff

Panagiotis Christopoulos Charitos 15 лет назад
Родитель
Сommit
3ad427dc4c

Разница между файлами не показана из-за своего большого размера
+ 330 - 497
build/debug/Makefile


+ 38 - 0
src/Collision/CollisionShape.h

@@ -0,0 +1,38 @@
+#ifndef COLLISION_SHAPE
+#define COLLISION_SHAPE
+
+#include "Properties.h"
+
+
+class Plane;
+
+
+/// Abstact class for collision shapes
+class CollisionShape
+{
+	public:
+		enum CollisionShapeType
+		{
+			CST_LINE_SEG,
+			CST_RAY,
+			CST_PLANE,
+			CST_BSPHERE,
+			CST_AABB,
+			CST_OBB,
+			CST_NUM
+		};
+
+	PROPERTY_R(CollisionShapeType, type, getType)
+
+	public:
+		CollisionShape(CollisionShapeType type_): type(type_) {}
+
+		virtual void Render() = 0;
+
+		/// If the bounding volume intersects with the plane then the func returns 0, else it returns the distance. If the
+		/// distance is < 0 then the b.v. lies behind the plane and if > 0 then in front of it
+		virtual float testPlane(const Plane&) const = 0;
+};
+
+
+#endif

+ 0 - 82
src/Collision/LineSeg.h

@@ -1,82 +0,0 @@
-#ifndef LINESEG_H
-#define LINESEG_H
-
-#include "Common.h"
-#include "Math.h"
-
-
-class Plane;
-class Ray;
-class Sphere;
-class Aabb;
-class Obb;
-
-
-/**
- * Line segment
- */
-class LineSeg: public CollisionShape
-{
-	PROPERTY_RW(Vec3, origin, setOrigin, getOrigin) ///< P0
-	PROPERTY_RW(Vec3, dir, setDir, getDir) ///< P1 = origin+dir so dir = P1-origin
-
-	public:
-		// constructors & distructors
-		LineSeg() {}
-		LineSeg(const LineSeg& b);
-		LineSeg(const Vec3& origin_, const Vec3& dir_);
-
-		// std funcs
-		LineSeg getTransformed(const Vec3& translate, const Mat3& rotate, float scale) const;
-		void render();
-		float planeTest(const Plane& plane) const;
-		bool intersects(const Sphere& sphere) const;
-		bool intersects(const Aabb& aabb) const;
-		bool intersects(const Obb& obb) const;
-
-		// other funcs
-		float getLengthSquared() const;
-		float getLength() const;
-		/**
-		 * @name Distance funcs
-		 *
-		 * 1) If tc<0 then outside the line segment and close to origin. If tc>1 again outside the line segment and closer
-		 *    to dir. If >0 or <1 then inside the segment
-		 * 2) When we talk about distances we calc the distance between the point|line|ray etc and the P0 OR P1. For example
-		 *    the dist between a point and P0 or P1 depending of tc
-		 */
-		/**@{*/
-		float getDistanceSquared(const LineSeg& seg, float& sc, float& tc) const;   ///< Dist with another segment
-		float getDistanceSquared(const Ray& ray, float& sc, float& tc) const;       ///< Dist with a ray
-		float getDistanceSquared(const Vec3& point, float& tc) const;                ///< Dist with a point.
-		/**@}*/
-		void calcClosestPoints(const LineSeg& seg, Vec3& point0, Vec3& point1) const; ///< Between this and another LineSeg
-		void calcClosestPoints(const Ray& ray, Vec3& point0, Vec3& point1) const;     ///< Between this and a Ray
-		Vec3 calcClosestPoints(const Vec3& point) const;                              ///< Between this and a point
-};
-
-
-inline LineSeg::LineSeg(const LineSeg& b):
-	origin(b.origin),
-	dir(b.dir)
-{}
-
-
-inline LineSeg::LineSeg(const Vec3& origin_, const Vec3& dir_):
-	origin(origin_),
-	dir(dir_)
-{}
-
-
-inline float LineSeg::getLengthSquared() const
-{
-	return dir.getLengthSquared();
-}
-
-
-inline float LineSeg::getLength() const
-{
-	return dir.getLength();
-}
-
-#endif

+ 22 - 0
src/Collision/Plane.h

@@ -0,0 +1,22 @@
+#ifndef PLANE_H
+#define PLANE_H
+
+#include "CollisionShape.h"
+#include "Math.h"
+#include "Properties.h"
+
+
+/// Plane collision shape
+class Plane: public CollisionShape
+{
+	PROPERTY_RW(Vec3, normal, setNormal, getNormal)
+	PROPERTY_RW(float, offset, setOffset, getOffset)
+
+	public:
+		Plane(): CollisionShape(CST_PLANE) {}
+
+		void setFrom3Vec3(const Vec3& p0, const Vec3& p1, const Vec3& p2);
+};
+
+
+#endif

+ 23 - 13
src/Core/App.cpp

@@ -1,6 +1,7 @@
 #include <GL/glew.h>
 #include <sstream>
 #include <SDL/SDL.h>
+#include <iostream>
 #include <boost/filesystem.hpp>
 #include "App.h"
 #include "Scene.h"
@@ -8,11 +9,20 @@
 #include "ScriptingEngine.h"
 #include "StdinListener.h"
 #include "MessageHandler.h"
+#include "Messaging.h"
 
 
 bool App::isCreated = false;
 
 
+//======================================================================================================================
+// handleMessageHanlderMsgs                                                                                            =
+//======================================================================================================================
+void App::handleMessageHanlderMsgs(const char* file, int line, const char* func, const std::string& msg)
+{
+	std::cout << file << ":" << line << " " << func << ": " << msg << std::endl;
+}
+
 //======================================================================================================================
 // parseCommandLineArgs                                                                                                =
 //======================================================================================================================
@@ -64,21 +74,21 @@ App::App(int argc, char* argv[], Object* parent):
 	isCreated = true;
 
 	// dirs
-	settingsPath = filesystem::path(getenv("HOME")) / ".anki";
-	if(!filesystem::exists(settingsPath))
+	settingsPath = boost::filesystem::path(getenv("HOME")) / ".anki";
+	if(!boost::filesystem::exists(settingsPath))
 	{
-		INFO("Creating settings dir \"" << settingsPath << "\"");
+		INFO("Creating settings dir \"" + settingsPath.string() + "\"");
 		filesystem::create_directory(settingsPath);
 	}
 
 	cachePath = settingsPath / "cache";
 	if(filesystem::exists(cachePath))
 	{
-		INFO("Deleting dir \"" << cachePath << "\"");
+		INFO("Deleting dir \"" + cachePath.string() + "\"");
 		filesystem::remove_all(cachePath);
 	}
 
-	INFO("Creating cache dir \"" << cachePath << "\"");
+	INFO("Creating cache dir \"" + cachePath.string() + "\"");
 	filesystem::create_directory(cachePath);
 
 	// create the subsystems. WATCH THE ORDER
@@ -105,17 +115,15 @@ void App::initWindow()
 	INFO("SDL window initializing...");
 
 	if(SDL_Init(SDL_INIT_VIDEO) < 0)
-		FATAL("Failed to init SDL_VIDEO");
+	{
+		throw EXCEPTION("Failed to init SDL_VIDEO");
+	}
 
 	// print driver name
 	const char* driverName = SDL_GetCurrentVideoDriver();
 	if(driverName != NULL)
 	{
-		INFO("Video driver name: " << driverName);
-	}
-	else
-	{
-		ERROR("Failed to obtain the video driver name");
+		INFO("Video driver name: " + driverName);
 	}
 
 	// set GL attribs
@@ -130,7 +138,9 @@ void App::initWindow()
 	                             SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
 
 	if(!windowId)
-		FATAL("Cannot create main window");
+	{
+		throw EXCEPTION("Cannot create main window");
+	}
 
 	glContext = SDL_GL_CreateContext(windowId);
 
@@ -139,7 +149,7 @@ void App::initWindow()
 	iconImage = SDL_LoadBMP("gfx/icon.bmp");
 	if(iconImage == NULL)
 	{
-		ERROR("Cannot load window icon");
+		throw EXCEPTION("Cannot load window icon");
 	}
 	else
 	{

+ 14 - 14
src/Core/App.h

@@ -3,9 +3,11 @@
 
 #include <SDL/SDL.h>
 #include <boost/filesystem.hpp>
-#include "Common.h"
 #include "Object.h"
 #include "MessageHandler.h"
+#include "StdTypes.h"
+#include "Properties.h"
+#include "Exception.h"
 
 
 class ScriptingEngine;
@@ -15,6 +17,10 @@ class MainRenderer;
 class Camera;
 
 
+/// The one and only global variable
+extern class App* app;
+
+
 /**
  * This class holds all the global objects of the application and its also responsible for some of the SDL stuff.
  * It should be singleton
@@ -23,8 +29,8 @@ class App: public Object
 {
 	PROPERTY_R(uint, windowW, getWindowWidth) ///< The main window width
 	PROPERTY_R(uint, windowH, getWindowHeight) ///< The main window height
-	PROPERTY_R(filesystem::path, settingsPath, getSettingsPath)
-	PROPERTY_R(filesystem::path, cachePath, getCachePath)
+	PROPERTY_R(boost::filesystem::path, settingsPath, getSettingsPath)
+	PROPERTY_R(boost::filesystem::path, cachePath, getCachePath)
 
 	public:
 		uint timerTick;
@@ -103,43 +109,37 @@ inline bool App::isTerminalColoringEnabled() const
 
 inline Scene& App::getScene()
 {
-	DEBUG_ERR(scene == NULL);
+	RASSERT_THROW_EXCEPTION(scene == NULL);
 	return *scene;
 }
 
 
 inline ScriptingEngine& App::getScriptingEngine()
 {
-	DEBUG_ERR(scriptingEngine == NULL);
+	RASSERT_THROW_EXCEPTION(scriptingEngine == NULL);
 	return *scriptingEngine;
 }
 
 
 inline StdinListener& App::getStdinLintener()
 {
-	DEBUG_ERR(stdinListener == NULL);
+	RASSERT_THROW_EXCEPTION(stdinListener == NULL);
 	return *stdinListener;
 }
 
 
 inline MainRenderer& App::getMainRenderer()
 {
-	DEBUG_ERR(mainRenderer == NULL);
+	RASSERT_THROW_EXCEPTION(mainRenderer == NULL);
 	return *mainRenderer;
 }
 
 
 inline MessageHandler& App::getMessageHandler()
 {
-	/// @todo Check
+	RASSERT_THROW_EXCEPTION(mainRenderer == NULL);
 	return *messageHandler;
 }
 
 
-inline void App::handleMessageHanlderMsgs(const char* file, int line, const char* func, const std::string& msg)
-{
-	std::cout << file << ":" << line << " " << func << ": " << msg << std::endl;
-}
-
-
 #endif

+ 2 - 2
src/Core/Common.cpp

@@ -24,7 +24,7 @@ static const char* terminalColors [MT_NUM + 1] = {
 /**
  * The function gets __PRETTY_FUNCTION__ and strips it to get only the function name with its namespace
  */
-static string getFunctionFromPrettyFunction(const char* prettyFunction)
+static std::string getFunctionFromPrettyFunction(const char* prettyFunction)
 {
 	string ret(prettyFunction);
 
@@ -44,7 +44,7 @@ static string getFunctionFromPrettyFunction(const char* prettyFunction)
 //======================================================================================================================
 // msgPrefix                                                                                                           =
 //======================================================================================================================
-ostream& msgPrefix(MsgType msgType, const char* file, int line, const char* func)
+std::ostream& msgPrefix(MsgType msgType, const char* file, int line, const char* func)
 {
 	// select c stream
 	ostream* cs;

+ 8 - 12
src/Core/Common.h

@@ -1,7 +1,7 @@
 #ifndef COMMON_H
 #define COMMON_H
 
-#include <iostream>
+/*#include <iostream>
 #include "StdTypes.h"
 #include "Properties.h"
 #include "Exception.h"
@@ -13,10 +13,6 @@ namespace boost
 namespace M
 {}
 
-using namespace boost;
-using namespace std;
-using namespace M;
-
 
 //======================================================================================================================
 // Defines sanity checks                                                                                               =
@@ -46,9 +42,9 @@ enum MsgType
 	MT_NUM
 };
 
-extern ostream& msgPrefix(MsgType msgType, const char* file, int line, const char* func);
-extern ostream& msgSuffix(ostream& cs);
-extern ostream& msgSuffixFatal(ostream& cs);
+extern std::ostream& msgPrefix(MsgType msgType, const char* file, int line, const char* func);
+extern std::ostream& msgSuffix(std::ostream& cs);
+extern std::ostream& msgSuffixFatal(std::ostream& cs);
 extern bool msgGlError(const char* file, int line, const char* func);
 
 #ifdef __GNUG__
@@ -95,7 +91,7 @@ extern bool msgGlError(const char* file, int line, const char* func);
 
 
 /// Just print
-#define PRINT(x) cout << x << endl
+#define PRINT(x) std::cout << x << std::endl
 
 
 /// BUFFER_OFFSET
@@ -115,10 +111,10 @@ template <typename Type> inline void memZero(Type& t)
 //======================================================================================================================
 // Application                                                                                                         =
 //======================================================================================================================
-/**
+*
  * The only public variable @see App
- */
-extern class App* app;
+
+extern class App* app;*/
 
 
 #endif

+ 14 - 0
src/Core/Messaging.h

@@ -0,0 +1,14 @@
+#ifndef MESSAGING_H
+#define MESSAGING_H
+
+#include "App.h"
+#include "MessageHandler.h"
+
+#define INFO(x) \
+	app->getMessageHandler().write(std::string("Info: ") + x)
+
+#define WARNING(x) \
+	app->getMessageHandler().write(std::string("Warning: ") + x)
+
+
+#endif

+ 5 - 5
src/Core/StdinListener.cpp

@@ -14,7 +14,7 @@ void StdinListener::workingFunc()
 		buff[m] = '\0';
 		//cout << "read: " << buff << endl;
 		{
-			mutex::scoped_lock lock(mtx);
+			boost::mutex::scoped_lock lock(mtx);
 			q.push(buff);
 			//cout << "size:" << q.size() << endl;
 		}
@@ -25,10 +25,10 @@ void StdinListener::workingFunc()
 //======================================================================================================================
 // getLine                                                                                                             =
 //======================================================================================================================
-string StdinListener::getLine()
+std::string StdinListener::getLine()
 {
-	string ret;
-	mutex::scoped_lock lock(mtx);
+	std::string ret;
+	boost::mutex::scoped_lock lock(mtx);
 	//cout << "_size:" << q.size() << endl;
 	if(!q.empty())
 	{
@@ -44,5 +44,5 @@ string StdinListener::getLine()
 //======================================================================================================================
 void StdinListener::start()
 {
-	thrd = thread(&StdinListener::workingFunc, this);
+	thrd = boost::thread(&StdinListener::workingFunc, this);
 }

+ 5 - 8
src/Core/StdinListener.h

@@ -5,25 +5,22 @@
 #include <boost/thread/mutex.hpp>
 #include <string>
 #include <queue>
-#include "Common.h"
 #include "Object.h"
 
 
-/**
- * The listener of the stdin
- */
+/// The listener of the stdin
 class StdinListener: public Object
 {
 	public:
 		StdinListener(Object* parent = NULL): Object(parent) {}
 		~StdinListener() {}
-		string getLine();
+		std::string getLine();
 		void start();
 
 	private:
-		queue<string> q;
-		mutex mtx;
-		thread thrd;
+		std::queue<std::string> q;
+		boost::mutex mtx;
+		boost::thread thrd;
 
 		StdinListener(const StdinListener&); ///< Non copyable
 		void workingFunc(); ///< The thread function

+ 2 - 2
src/Misc/collision.h

@@ -1,5 +1,5 @@
-#ifndef _COLLISION_H_
-#define _COLLISION_H_
+#ifndef COLLISION_H
+#define COLLISION_H
 
 /*
 Info on how seperation tests work.

+ 1 - 0
src/Renderer/BufferObjects/Fbo.h

@@ -3,6 +3,7 @@
 
 #include <GL/glew.h>
 #include "Exception.h"
+#include "Properties.h"
 
 
 /// The class is actually a wrapper to avoid common mistakes

+ 22 - 9
src/Renderer/Ez.cpp

@@ -14,22 +14,30 @@ void Ez::init(const RendererInitializer& initializer)
 	enabled = initializer.ms.ez.enabled;
 
 	if(!enabled)
+	{
 		return;
+	}
 
 	//
 	// init FBO
 	//
-	fbo.create();
-	fbo.bind();
+	try
+	{
+		fbo.create();
+		fbo.bind();
 
-	fbo.setNumOfColorAttachements(0);
+		fbo.setNumOfColorAttachements(0);
 
-	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
+		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
 
-	if(!fbo.isGood())
-		FATAL("Cannot create shadowmapping FBO");
+		fbo.checkIfGood();
 
-	fbo.unbind();
+		fbo.unbind();
+	}
+	catch(std::exception& e)
+	{
+		throw EXCEPTION("Cannot create EarlyZ FBO");
+	}
 }
 
 
@@ -38,7 +46,10 @@ void Ez::init(const RendererInitializer& initializer)
 //======================================================================================================================
 void Ez::run()
 {
-	DEBUG_ERR(!enabled);
+	if(!enabled)
+	{
+		return;
+	}
 
 	fbo.bind();
 
@@ -52,9 +63,11 @@ void Ez::run()
 	{
 		MeshNode* meshNode = (*it);
 		if(meshNode->mesh->material->blends)
+		{
 			continue;
+		}
 
-		DEBUG_ERR(meshNode->mesh->material->dpMtl.get() == NULL);
+		RASSERT_THROW_EXCEPTION(meshNode->mesh->material->dpMtl.get() == NULL);
 
 		r.setupMaterial(*meshNode->mesh->material->dpMtl, *meshNode, r.getCamera());
 		meshNode->renderDepth();

+ 25 - 18
src/Renderer/Hdr.cpp

@@ -9,29 +9,35 @@
 //======================================================================================================================
 void Hdr::initFbo(Fbo& fbo, Texture& fai)
 {
-	int width = renderingQuality * r.getWidth();
-	int height = renderingQuality * r.getHeight();
+	try
+	{
+		int width = renderingQuality * r.getWidth();
+		int height = renderingQuality * r.getHeight();
 
-	// create FBO
-	fbo.create();
-	fbo.bind();
+		// create FBO
+		fbo.create();
+		fbo.bind();
 
-	// inform in what buffers we draw
-	fbo.setNumOfColorAttachements(1);
+		// inform in what buffers we draw
+		fbo.setNumOfColorAttachements(1);
 
-	// create the texes
-	fai.createEmpty2D(width, height, GL_RGB, GL_RGB, GL_FLOAT);
-	fai.setFiltering(Texture::TFT_LINEAR);
+		// create the texes
+		fai.createEmpty2D(width, height, GL_RGB, GL_RGB, GL_FLOAT);
+		fai.setFiltering(Texture::TFT_LINEAR);
 
-	// attach
-	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fai.getGlId(), 0);
+		// attach
+		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fai.getGlId(), 0);
 
-	// test if success
-	if(!fbo.isGood())
-		FATAL("Cannot create deferred shading post-processing stage HDR passes FBO");
+		// test if success
+		fbo.checkIfGood();
 
-	// unbind
-	fbo.unbind();
+		// unbind
+		fbo.unbind();
+	}
+	catch(std::exception& e)
+	{
+		throw EXCEPTION("Cannot create deferred shading post-processing stage HDR passes FBO: " + e.what());
+	}
 }
 
 
@@ -43,7 +49,9 @@ void Hdr::init(const RendererInitializer& initializer)
 	enabled = initializer.pps.hdr.enabled;
 
 	if(!enabled)
+	{
 		return;
+	}
 
 	renderingQuality = initializer.pps.hdr.renderingQuality;
 	blurringDist = initializer.pps.hdr.blurringDist;
@@ -71,7 +79,6 @@ void Hdr::init(const RendererInitializer& initializer)
 	vblurSProg.loadRsrc(ShaderProg::createSrcCodeToCache(SHADER_FILENAME, pps.c_str(), prefix.c_str()).c_str());
 }
 
-#include "App.h"
 
 //======================================================================================================================
 // runPass                                                                                                             =

+ 4 - 9
src/Renderer/Hdr.h

@@ -1,7 +1,6 @@
 #ifndef HDR_H
 #define HDR_H
 
-#include "Common.h"
 #include "RenderingStage.h"
 #include "Fbo.h"
 #include "Texture.h"
@@ -9,9 +8,7 @@
 #include "ShaderProg.h"
 
 
-/**
- * High dynamic range lighting pass
- */
+/// High dynamic range lighting pass
 class Hdr: private RenderingStage
 {
 	public:
@@ -23,10 +20,8 @@ class Hdr: private RenderingStage
 		void init(const RendererInitializer& initializer);
 		void run();
 
-		/**
-		 * Setters & getters
-		 */
-		/**@{*/
+		/// Setters & getters
+		/// @{
 		float getBlurringDist() {return blurringDist;}
 		void setBlurringDist(float f) {blurringDist = f;}
 		uint getBlurringIterations() {return blurringIterations;}
@@ -35,7 +30,7 @@ class Hdr: private RenderingStage
 		void setExposure(float f) {exposure = f;}
 		bool isEnabled() const {return enabled;}
 		float getRenderingQuality() const {return renderingQuality;}
-		/**@}*/
+		/// @}
 
 	private:
 		Fbo toneFbo;

+ 32 - 33
src/Renderer/Is.cpp

@@ -28,12 +28,12 @@ void Is::calcViewVectors()
 	for(int i=0; i<4; i++)
 	{
 		/*
-		 * Original Code:
-		 * Renderer::unProject(pixels[i][0], pixels[i][1], 10, cam.getViewMatrix(), cam.getProjectionMatrix(), viewport,
-		 *                     viewVectors[i].x, viewVectors[i].y, viewVectors[i].z);
-		 * viewVectors[i] = cam.getViewMatrix() * viewVectors[i];
-		 * The original code is the above 3 lines. The optimized follows:
-		 */
+		Original Code:
+		Renderer::unProject(pixels[i][0], pixels[i][1], 10, cam.getViewMatrix(), cam.getProjectionMatrix(), viewport,
+		                    viewVectors[i].x, viewVectors[i].y, viewVectors[i].z);
+		viewVectors[i] = cam.getViewMatrix() * viewVectors[i];
+		The original code is the above 3 lines. The optimized follows:
+		*/
 
 		Vec3 vec;
 		vec.x = (2.0 * (pixels[i][0] - viewport[0])) / viewport[2] - 1.0;
@@ -63,39 +63,38 @@ void Is::calcPlanes()
 //======================================================================================================================
 void Is::initFbo()
 {
-	// create FBO
-	fbo.create();
-	fbo.bind();
+	try
+	{
+		// create FBO
+		fbo.create();
+		fbo.bind();
 
-	// init the stencil render buffer
-	glGenRenderbuffers(1, &stencilRb);
-	glBindRenderbuffer(GL_RENDERBUFFER, stencilRb);
-	glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX, r.getWidth(), r.getHeight());
-	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilRb);
+		// init the stencil render buffer
+		glGenRenderbuffers(1, &stencilRb);
+		glBindRenderbuffer(GL_RENDERBUFFER, stencilRb);
+		glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX, r.getWidth(), r.getHeight());
+		glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilRb);
 
-	// inform in what buffers we draw
-	fbo.setNumOfColorAttachements(1);
+		// inform in what buffers we draw
+		fbo.setNumOfColorAttachements(1);
 
-	// create the txtrs
-	try
-	{
+		// create the FAI
 		fai.createEmpty2D(r.getWidth(), r.getHeight(), GL_RGB, GL_RGB, GL_FLOAT);
-	}
-	catch(Exception& e)
-	{
-		FATAL("Cannot create deferred shading illumination stage FAI");
-	}
 
-	// attach
-	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fai.getGlId(), 0);
-	//glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
+		// attach
+		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fai.getGlId(), 0);
+		//glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
 
-	// test if success
-	if(!fbo.isGood())
-		FATAL("Cannot create deferred shading illumination stage FBO");
+		// test if success
+		fbo.checkIfGood();
 
-	// unbind
-	fbo.unbind();
+		// unbind
+		fbo.unbind();
+	}
+	catch(std::exception& e)
+	{
+		throw EXCEPTION("Cannot create deferred shading illumination stage FBO: " + e.what());
+	}
 }
 
 
@@ -345,7 +344,7 @@ void Is::run()
 			}
 
 			default:
-				DEBUG_ERR(1);
+				RASSERT_THROW_EXCEPTION("WTF?");
 		}
 	}
 

+ 14 - 15
src/Renderer/Is.h

@@ -1,7 +1,6 @@
 #ifndef IS_H
 #define IS_H
 
-#include "Common.h"
 #include "RenderingStage.h"
 #include "Fbo.h"
 #include "Sm.h"
@@ -13,9 +12,7 @@ class PointLight;
 class SpotLight;
 
 
-/**
- * Illumination stage
- */
+/// Illumination stage
 class Is: private RenderingStage
 {
 	public:
@@ -35,29 +32,31 @@ class Is: private RenderingStage
 		RsrcPtr<ShaderProg> spotLightNoShadowSProg; ///< Illumination stage spot light w/o shadow shader program
 		RsrcPtr<ShaderProg> spotLightShadowSProg; ///< Illumination stage spot light w/ shadow shader program
 
-		/**
-		 * @name Ptrs to uniform variables
-		 */
-		/**@{*/
+		/// @name Ptrs to uniform variables
+		/// @{
 		const ShaderProg::UniVar* ambientColUniVar;
 		const ShaderProg::UniVar* sceneColMapUniVar;
-		/**@}*/
+		/// @}
 
 		Vec3 viewVectors[4];
 		Vec2 planes;
 
-		/**
-		 * Calc the view vector that we will use inside the shader to calculate the frag pos in view space
-		 */
+		/// Calc the view vector that we will use inside the shader to calculate the frag pos in view space
 		void calcViewVectors();
 
-		/**
-		 * Calc the planes that we will use inside the shader to calculate the frag pos in view space
-		 */
+		/// Calc the planes that we will use inside the shader to calculate the frag pos in view space
 		void calcPlanes();
+
+		/// The ambient pass
 		void ambientPass(const Vec3& color);
+
+		/// The point light pass
 		void pointLightPass(const PointLight& light);
+
+		/// The spot light pass
 		void spotLightPass(const SpotLight& light);
+
+		/// Used in @ref init
 		void initFbo();
 };
 

+ 14 - 20
src/Renderer/MainRenderer.cpp

@@ -41,13 +41,17 @@ void MainRenderer::initGl()
 {
 	GLenum err = glewInit();
 	if(err != GLEW_OK)
-		FATAL("GLEW initialization failed");
+	{
+		throw EXCEPTION("GLEW initialization failed");
+	}
 
 	// print GL info
 	INFO("OpenGL info: OGL " << glGetString(GL_VERSION) << ", GLSL " << glGetString(GL_SHADING_LANGUAGE_VERSION));
 
 	if(!glewIsSupported("GL_VERSION_3_1"))
+	{
 		WARNING("OpenGL ver 3.1 not supported. The application may crash (and burn)");
+	}
 
 	// get max texture units
 	glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &Texture::textureUnitsNum);
@@ -98,15 +102,14 @@ void MainRenderer::render(Camera& cam_)
 //======================================================================================================================
 // takeScreenshotTga                                                                                                   =
 //======================================================================================================================
-bool MainRenderer::takeScreenshotTga(const char* filename)
+void MainRenderer::takeScreenshotTga(const char* filename)
 {
 	// open file and check
 	fstream fs;
 	fs.open(filename, ios::out|ios::binary);
 	if(!fs.good())
 	{
-		ERROR("Cannot create screenshot. File \"" << filename << "\"");
-		return false;
+		throw EXCEPTION("Cannot create screenshot. File \"" + filename + "\"");
 	}
 
 	// write headers
@@ -132,22 +135,20 @@ bool MainRenderer::takeScreenshotTga(const char* filename)
 	// end
 	fs.close();
 	free(buffer);
-	return true;
 }
 
 
 //======================================================================================================================
 // takeScreenshotJpeg                                                                                                  =
 //======================================================================================================================
-bool MainRenderer::takeScreenshotJpeg(const char* filename)
+void MainRenderer::takeScreenshotJpeg(const char* filename)
 {
 	// open file
 	FILE* outfile = fopen(filename, "wb");
 
 	if(!outfile)
 	{
-		ERROR("Cannot open file \"" << filename << "\"");
-		return false;
+		throw EXCEPTION("Cannot open file \"" + filename + "\"");
 	}
 
 	// set jpg params
@@ -184,7 +185,6 @@ bool MainRenderer::takeScreenshotJpeg(const char* filename)
 	// done
 	free(buffer);
 	fclose(outfile);
-	return true;
 }
 
 
@@ -193,28 +193,22 @@ bool MainRenderer::takeScreenshotJpeg(const char* filename)
 //======================================================================================================================
 void MainRenderer::takeScreenshot(const char* filename)
 {
-	string ext = filesystem::path(filename).extension();
+	std::string ext = filesystem::path(filename).extension();
 	to_lower(ext);
-	bool ret;
 
 	// exec from this extension
 	if(ext == ".tga")
 	{
-		ret = takeScreenshotTga(filename);
+		takeScreenshotTga(filename);
 	}
 	else if(ext == ".jpg" || ext == ".jpeg")
 	{
-		ret = takeScreenshotJpeg(filename);
+		takeScreenshotJpeg(filename);
 	}
 	else
 	{
-		ERROR("File \"" << filename << "\": Unsupported extension");
-		return;
+		throw EXCEPTION("File \"" + filename + "\": Unsupported extension");
 	}
-
-	if(!ret)
-		ERROR("In taking screenshot");
-	else
-		INFO("Screenshot \"" << filename << "\" saved");
+	INFO("Screenshot \"" << filename << "\" saved");
 }
 

+ 13 - 26
src/Renderer/MainRenderer.h

@@ -1,13 +1,10 @@
 #ifndef MAIN_RENDERER_H
 #define MAIN_RENDERER_H
 
-#include "Common.h"
 #include "Renderer.h"
 
 
-/**
- * Main onscreen renderer
- */
+/// Main onscreen renderer
 class MainRenderer: public Renderer
 {
 	public:
@@ -17,44 +14,34 @@ class MainRenderer: public Renderer
 
 		~MainRenderer() throw() {}
 
-		/**
-		 * @name Setters & getters
-		 */
-		/**@{*/
+		/// @name Setters & getters
+		/// @{
 		int& getScreenshotJpegQuality() {return screenshotJpegQuality;}
 		void setScreenshotJpegQuality(int i) {screenshotJpegQuality = i;}
 		float getRenderingQuality() const {return renderingQuality;}
-		/**@}*/
+		/// @}
 
-		/**
-		 * The same as Renderer::init but with additional initialization. @see Renderer::init
-		 */
+		/// The same as Renderer::init but with additional initialization. @see Renderer::init
 		void init(const RendererInitializer& initializer);
 
-		/**
-		 * The same as Renderer::render but in addition it renders the final FAI to the framebuffer
-		 * @param cam @see Renderer::render
-		 */
+		/// The same as Renderer::render but in addition it renders the final FAI to the framebuffer
+		/// @param cam @see Renderer::render
 		void render(Camera& cam);
 
-		/**
-		 * Save the color buffer to a tga (lossless & uncompressed & slow) or jpeg (lossy & compressed * fast)
-		 * @param filename The file to save
-		 */
+		/// Save the color buffer to a tga (lossless & uncompressed & slow) or jpeg (lossy & compressed/// fast)
+		/// @param filename The file to save
 		void takeScreenshot(const char* filename);
 
 	private:
 		RsrcPtr<ShaderProg> sProg; ///< Final pass' shader program
 		int screenshotJpegQuality; ///< The quality of the JPEG screenshots. From 0 to 100
 
-		/**
-		 * The global rendering quality of the raster image. Its a percentage of the application's window size. From
-		 * 0.0(low) to 1.0(high)
-		 */
+		/// The global rendering quality of the raster image. Its a percentage of the application's window size. From
+		/// 0.0(low) to 1.0(high)
 		float renderingQuality;
 
-		bool takeScreenshotTga(const char* filename);
-		bool takeScreenshotJpeg(const char* filename);
+		void takeScreenshotTga(const char* filename);
+		void takeScreenshotJpeg(const char* filename);
 		static void initGl();
 };
 

+ 3 - 2
src/Renderer/Renderer.cpp

@@ -4,6 +4,7 @@
 #include "Material.h"
 #include "App.h"
 #include "Scene.h"
+#include "Exception.h"
 
 
 //======================================================================================================================
@@ -42,7 +43,7 @@ void Renderer::init(const RendererInitializer& initializer)
 	// a few sanity checks
 	if(width < 10 || height < 10)
 	{
-		FATAL("Incorrect width");
+		throw EXCEPTION("Incorrect width");
 	}
 
 	// init the stages. Careful with the order!!!!!!!!!!
@@ -77,7 +78,7 @@ void Renderer::render(Camera& cam_)
 //======================================================================================================================
 void Renderer::drawQuad(int vertCoordsAttribLoc)
 {
-	DEBUG_ERR(vertCoordsAttribLoc == -1);
+	RASSERT_THROW_EXCEPTION(vertCoordsAttribLoc == -1);
 	glEnableVertexAttribArray(vertCoordsAttribLoc);
 	glVertexAttribPointer(vertCoordsAttribLoc, 2, GL_FLOAT, false, 0, quadVertCoords);
 	glDrawArrays(GL_QUADS, 0, 4);

+ 0 - 1
src/Renderer/Renderer.h

@@ -1,7 +1,6 @@
 #ifndef RENDERER_H
 #define RENDERER_H
 
-#include "Common.h"
 #include "Math.h"
 #include "Fbo.h"
 #include "Texture.h"

+ 2 - 2
src/Scene/Camera.h

@@ -1,5 +1,5 @@
-#ifndef _CAMERA_H_
-#define _CAMERA_H_
+#ifndef CAMERA_H
+#define CAMERA_H
 
 #include <fstream>
 #include <cstring>

+ 11 - 22
src/Scene/Scene.h

@@ -1,11 +1,10 @@
 #ifndef SCENE_H
 #define SCENE_H
 
-#include <memory>
-#include "Common.h"
 #include "Object.h"
 #include "skybox.h"
 #include "Physics.h"
+#include "Exception.h"
 
 
 class SceneNode;
@@ -17,9 +16,7 @@ class Controller;
 class ParticleEmitter;
 
 
-/**
- * The Scene contains all the dynamic entities
- */
+/// The Scene contains all the dynamic entities
 class Scene: public Object
 {
 	//PROPERTY_RW(Vec3, ambientCol, setAmbientCol, getAmbientCol) ///< The global ambient color
@@ -27,9 +24,7 @@ class Scene: public Object
 	//PROPERTY_R(Physics*, phyWorld, getPhysics) ///< Connection with bullet
 
 	public:
-		/**
-		 * @brief The container template class. Extends vector
-		 */
+		/// The container template class. Extends vector
 		template<typename Type> class Container: public Vec<Type*>
 		{};
 
@@ -55,28 +50,22 @@ class Scene: public Object
 		void updateAllWorldStuff();
 		void updateAllControllers();
 
-		/**
-		 * @name Accessors
-		 */
-		/**@{*/
+		/// @name Accessors
+		/// @{
 		Vec3& getAmbientCol() {return ambientCol;}
 		void setAmbientCol(const Vec3& col) {ambientCol = col;}
 		Physics& getPhysics();
-		/**@}*/
+		/// @}
 
 	private:
 		Vec3 ambientCol; ///< The global ambient color
 		Physics* physics; ///< Connection with Bullet wrapper
 
-		/**
-		 * Adds a node in a container
-		 */
+		/// Adds a node in a container
 		template<typename ContainerType, typename Type>
 		void putBackNode(ContainerType& container, Type* x);
 
-		/**
-		 * Removes a node from a container
-		 */
+		/// Removes a node from a container
 		template<typename ContainerType, typename Type>
 		void eraseNode(ContainerType& container, Type* x);
 };
@@ -85,7 +74,7 @@ class Scene: public Object
 template<typename ContainerType, typename Type>
 inline void Scene::putBackNode(ContainerType& container, Type* x)
 {
-	DEBUG_ERR(std::find(container.begin(), container.end(), x) != container.end());
+	RASSERT_THROW_EXCEPTION(std::find(container.begin(), container.end(), x) != container.end());
 	container.push_back(x);
 }
 
@@ -94,14 +83,14 @@ template<typename ContainerType, typename Type>
 inline void Scene::eraseNode(ContainerType& container, Type* x)
 {
 	typename ContainerType::iterator it = std::find(container.begin(), container.end(), x);
-	DEBUG_ERR(it == container.end());
+	RASSERT_THROW_EXCEPTION(it == container.end());
 	container.erase(it);
 }
 
 
 inline Physics& Scene::getPhysics()
 {
-	DEBUG_ERR(physics == NULL);
+	RASSERT_THROW_EXCEPTION(physics == NULL);
 	return *physics;
 }
 

Некоторые файлы не были показаны из-за большого количества измененных файлов