소스 검색

Refactoring

Panagiotis Christopoulos Charitos 15 년 전
부모
커밋
dc8300cff0

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 354 - 359
build/debug/Makefile


+ 1 - 1
src/Misc/TestHeader.cpp

@@ -1 +1 @@
-#include "Math.h"
+#include "Vbo.h"

+ 33 - 20
src/Renderer/Bs.cpp

@@ -11,18 +11,24 @@
 //======================================================================================================================
 void Bs::createFbo()
 {
-	fbo.create();
-	fbo.bind();
+	try
+	{
+		fbo.create();
+		fbo.bind();
 
-	fbo.setNumOfColorAttachements(1);
+		fbo.setNumOfColorAttachements(1);
 
-	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, r.pps.prePassFai.getGlId(), 0);
-	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
+		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, r.pps.prePassFai.getGlId(), 0);
+		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
 
-	if(!fbo.isGood())
-		FATAL("Cannot create deferred shading blending stage FBO");
+		fbo.checkIfGood();
 
-	fbo.unbind();
+		fbo.unbind();
+	}
+	catch(std::exception& e)
+	{
+		throw EXCEPTION("Failed to create blending stage FBO");
+	}
 }
 
 
@@ -31,18 +37,24 @@ void Bs::createFbo()
 //======================================================================================================================
 void Bs::createRefractFbo()
 {
-	refractFbo.create();
-	refractFbo.bind();
+	try
+	{
+		refractFbo.create();
+		refractFbo.bind();
 
-	refractFbo.setNumOfColorAttachements(1);
+		refractFbo.setNumOfColorAttachements(1);
 
-	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, refractFai.getGlId(), 0);
-	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
+		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, refractFai.getGlId(), 0);
+		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
 
-	if(!refractFbo.isGood())
-		FATAL("Cannot create deferred shading blending stage FBO");
+		refractFbo.checkIfGood();
 
-	refractFbo.unbind();
+		refractFbo.unbind();
+	}
+	catch(std::exception& e)
+	{
+		throw EXCEPTION("Failed to create blending stage refract FBO");
+	}
 }
 
 
@@ -54,7 +66,6 @@ void Bs::init(const RendererInitializer& /*initializer*/)
 	createFbo();
 	refractFai.createEmpty2D(r.getWidth(), r.getHeight(), GL_RGBA8, GL_RGBA, GL_FLOAT);
 	createRefractFbo();
-
 	refractSProg.loadRsrc("shaders/BsRefract.glsl");
 }
 
@@ -75,11 +86,13 @@ void Bs::run()
 
 		if(meshNode->mesh->material.get() == NULL)
 		{
-			ERROR("Mesh \"" << meshNode->mesh->getRsrcName() << "\" doesnt have material" );
-			continue;
+			throw EXCEPTION("Mesh \"" + meshNode->mesh->getRsrcName() + "\" doesnt have material" );
 		}
 
-		if(!meshNode->mesh->material->blends) continue;
+		if(!meshNode->mesh->material->blends)
+		{
+			continue;
+		}
 
 		// refracts
 		if(meshNode->mesh->material->stdUniVars[Material::SUV_PPS_PRE_PASS_FAI])

+ 30 - 45
src/Renderer/BufferObjects/Fbo.h

@@ -1,50 +1,36 @@
-#ifndef _FBO_H_
-#define _FBO_H_
+#ifndef FBO_H
+#define FBO_H
 
 #include <GL/glew.h>
-#include "Common.h"
+#include "Exception.h"
 
 
-/**
- * The class is actually a wrapper to avoid common mistakes
- */
+/// The class is actually a wrapper to avoid common mistakes
 class Fbo
 {
 	PROPERTY_R(uint, glId, getGlId) ///< OpenGL identification
 
 	public:
-		Fbo();
+		Fbo(): glId(0) {}
 
-		/**
-		 * Creates a new FBO
-		 */
+		/// Creates a new FBO
 		void create();
 
-		/**
-		 * Binds FBO
-		 */
+		/// Binds FBO
 		void bind() const;
 
-		/**
-		 * Unbinds the FBO. Actually unbinds all FBOs
-		 */
+		/// Unbinds the FBO. Actually unbinds all FBOs
 		static void unbind();
 
-		/**
-		 * Checks the status of an initialized FBO
-		 * @return True if FBO is ok and false if not
-		 */
-		bool isGood() const;
+		/// 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 attachements of the FBO
 		void setNumOfColorAttachements(uint num) const;
 
-		/**
-		 * Returns the GL id of the current attached FBO
-		 * @return Returns the GL id of the current attached FBO
-		 */
+		/// Returns the GL id of the current attached FBO
+		/// @return Returns the GL id of the current attached FBO
 		static uint getCurrentFbo();
 };
 
@@ -53,21 +39,16 @@ class Fbo
 // Inlines                                                                                                             =
 //======================================================================================================================
 
-inline Fbo::Fbo():
-	glId(0)
-{}
-
-
 inline void Fbo::create()
 {
-	DEBUG_ERR(glId != 0); // FBO already initialized
+	RASSERT_THROW_EXCEPTION(glId != 0); // FBO already initialized
 	glGenFramebuffers(1, &glId);
 }
 
 
 inline void Fbo::bind() const
 {
-	DEBUG_ERR(glId == 0);  // FBO not initialized
+	RASSERT_THROW_EXCEPTION(glId == 0);  // FBO not initialized
 	glBindFramebuffer(GL_FRAMEBUFFER, glId);
 }
 
@@ -78,19 +59,22 @@ inline void Fbo::unbind()
 }
 
 
-inline bool Fbo::isGood() const
+inline void Fbo::checkIfGood() const
 {
-	DEBUG_ERR(glId == 0);  // FBO not initialized
-	DEBUG_ERR(getCurrentFbo() != glId); // another FBO is binded
+	RASSERT_THROW_EXCEPTION(glId == 0);  // FBO not initialized
+	RASSERT_THROW_EXCEPTION(getCurrentFbo() != glId); // another FBO is binded
 
-	return glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE;
+	if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
+	{
+		throw EXCEPTION("FBO is incomplete");
+	}
 }
 
 
 inline void Fbo::setNumOfColorAttachements(uint num) const
 {
-	DEBUG_ERR(glId == 0);  // FBO not initialized
-	DEBUG_ERR(getCurrentFbo() != glId); // another FBO is binded
+	RASSERT_THROW_EXCEPTION(glId == 0);  // FBO not initialized
+	RASSERT_THROW_EXCEPTION(getCurrentFbo() != glId); // another FBO is binded
 
 	if(num == 0)
 	{
@@ -99,11 +83,11 @@ inline void Fbo::setNumOfColorAttachements(uint num) const
 	}
 	else
 	{
-		static GLenum colorAttachments[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2,
-																				 GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5,
-																				 GL_COLOR_ATTACHMENT6, GL_COLOR_ATTACHMENT7 };
+		static GLenum colorAttachments[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2,
+																				GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5,
+																				GL_COLOR_ATTACHMENT6, GL_COLOR_ATTACHMENT7};
 
-		DEBUG_ERR(num > sizeof(colorAttachments)/sizeof(GLenum));
+		RASSERT_THROW_EXCEPTION(num > sizeof(colorAttachments)/sizeof(GLenum));
 		glDrawBuffers(num, colorAttachments);
 	}
 }
@@ -116,4 +100,5 @@ inline uint Fbo::getCurrentFbo()
 	return (uint)fboGlId;
 }
 
+
 #endif

+ 12 - 18
src/Renderer/BufferObjects/Vbo.h

@@ -1,23 +1,17 @@
-#ifndef _VBO_H_
-#define _VBO_H_
+#ifndef VBO_H
+#define VBO_H
 
-#include "Common.h"
 #include "BufferObject.h"
 
-/**
- * This is a wrapper for Vertex Buffer Objects to prevent us from making idiotic errors
- */
+
+/// This is a wrapper for Vertex Buffer Objects to prevent us from making idiotic errors
 class Vbo: public BufferObject
 {
 	public:
-		/**
-		 * It adds an extra check over @ref BufferObject::create. See @ref BufferObject::create for details
-		 */
-		bool create(GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_);
-
-		/**
-		 * Unbinds all VBOs, meaning both GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER targets
-		 */
+		/// It adds an extra check over @ref BufferObject::create. @see @ref BufferObject::create
+		void create(GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_);
+
+		/// Unbinds all VBOs, meaning both GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER targets
 		static void unbindAllTargets();
 };
 
@@ -26,11 +20,10 @@ class Vbo: public BufferObject
 // Inlines                                                                                                             =
 //======================================================================================================================
 
-inline bool Vbo::create(GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_)
+inline void Vbo::create(GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_)
 {
-	DEBUG_ERR(target_!=GL_ARRAY_BUFFER && target_!=GL_ELEMENT_ARRAY_BUFFER); // unacceptable target_
-
-	return BufferObject::create(target_, sizeInBytes, dataPtr, usage_);
+	RASSERT_THROW_EXCEPTION(target_ != GL_ARRAY_BUFFER && target_ != GL_ELEMENT_ARRAY_BUFFER); // unacceptable target_
+	BufferObject::create(target_, sizeInBytes, dataPtr, usage_);
 }
 
 
@@ -40,4 +33,5 @@ inline void Vbo::unbindAllTargets()
 	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);
 }
 
+
 #endif

+ 17 - 14
src/Renderer/Dbg.cpp

@@ -194,23 +194,24 @@ void Dbg::init(const RendererInitializer& initializer)
 {
 	enabled = initializer.dbg.enabled;
 
-	// create FBO Captain Blood
-	fbo.create();
-	fbo.bind();
-
-	// inform in what buffers we draw
-	fbo.setNumOfColorAttachements(1);
+	// create FBO
+	try
+	{
+		fbo.create();
+		fbo.bind();
 
-	// attach the textures
-	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, r.pps.postPassFai.getGlId(), 0);
-	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,  GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
+		fbo.setNumOfColorAttachements(1);
 
-	// test if success
-	if(!fbo.isGood())
-		FATAL("Cannot create debug FBO");
+		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, r.pps.postPassFai.getGlId(), 0);
+		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,  GL_TEXTURE_2D, r.ms.depthFai.getGlId(), 0);
 
-	// unbind
-	fbo.unbind();
+		fbo.checkIfGood();
+		fbo.unbind();
+	}
+	catch(std::exception& e)
+	{
+		throw EXCEPTION("Cannot create debug FBO: " + e.what());
+	}
 
 	// shader
 	sProg.loadRsrc("shaders/Dbg.glsl");
@@ -223,7 +224,9 @@ void Dbg::init(const RendererInitializer& initializer)
 void Dbg::run()
 {
 	if(!enabled)
+	{
 		return;
+	}
 
 	const Camera& cam = r.getCamera();
 

+ 4 - 9
src/Renderer/Dbg.h

@@ -1,7 +1,6 @@
 #ifndef DBG_H
 #define DBG_H
 
-#include "Common.h"
 #include "RenderingStage.h"
 #include "Fbo.h"
 #include "ShaderProg.h"
@@ -9,9 +8,7 @@
 #include "Math.h"
 
 
-/**
- * Debugging stage
- */
+/// Debugging stage
 class Dbg: public RenderingStage
 {
 	public:
@@ -25,16 +22,14 @@ class Dbg: public RenderingStage
 		void setModelMat(const Mat4& modelMat);
 		void drawLine(const Vec3& from, const Vec3& to, const Vec4& color);
 
-		/**
-		 * @name Setters & getters
-		 */
-		/**@{*/
+		/// @name Setters & getters
+		/// @{
 		bool isEnabled() const {return enabled;}
 		void setEnabled(bool flag) {enabled = flag;}
 		bool isShowSkeletonsEnabled() const {return showSkeletonsEnabled;}
 		void setShowSkeletonsEnabled(bool flag) {showSkeletonsEnabled = flag;}
 		/// @todo add others
-		/**@}*/
+		/// @}
 
 	private:
 		static const uint POSITION_ATTRIBUTE_ID = 0; ///< The glId of the attribute var for position in the dbg shader

+ 6 - 4
src/Resources/Core/Resource.h

@@ -1,8 +1,10 @@
 #ifndef RESOURCE_H
 #define RESOURCE_H
 
-#include "Common.h"
+#include <string>
 #include "Util.h"
+#include "Properties.h"
+#include "StdTypes.h"
 
 
 template<typename Type>
@@ -31,14 +33,14 @@ class Resource
 			RT_SCRIPT
 		};
 
-	PROPERTY_R(string, path, getRsrcPath);
-	PROPERTY_R(string, name, getRsrcName);
+	PROPERTY_R(std::string, path, getRsrcPath);
+	PROPERTY_R(std::string, name, getRsrcName);
 	PROPERTY_R(uint, referenceCounter, getRsrcReferencesNum);
 	PROPERTY_R(ResourceType, type, getRsrcType);
 
 	public:
 		Resource(const ResourceType& type_);
-		virtual ~Resource() {DEBUG_ERR(referenceCounter != 0);}
+		virtual ~Resource() {/*DEBUG_ERR(referenceCounter != 0);*/}
 
 	private:
 		/// Load the resource

+ 2 - 2
src/Resources/Extension.h

@@ -15,8 +15,8 @@ class Extension: public Resource
 		Extension();
 		~Extension();
 		void load(const char* filename);
-		template<typename Type>
-		int FooBar(Type* ptr) { DEBUG_ERR(foobarPtr==NULL); return (*foobarPtr)(reinterpret_cast<Type*>(ptr)); }
+		/*template<typename Type>
+		int FooBar(Type* ptr) { DEBUG_ERR(foobarPtr==NULL); return (*foobarPtr)(reinterpret_cast<Type*>(ptr)); }*/
 };
 
 

+ 1 - 1
src/Resources/LightData.h

@@ -54,7 +54,7 @@ class LightData: public Resource
 
 inline const Texture& LightData::getTexture() const
 {
-	DEBUG_ERR(texture.get() == NULL);
+	RASSERT_THROW_EXCEPTION(texture.get() == NULL);
 	return *texture;
 }
 

+ 4 - 14
src/Resources/Mesh.cpp

@@ -17,7 +17,7 @@ void Mesh::load(const char* filename)
 	try
 	{
 		// Open the file
-		fstream file(filename, fstream::in | fstream::binary);
+		std::fstream file(filename, std::fstream::in | std::fstream::binary);
 
 		if(!file.is_open())
 		{
@@ -35,10 +35,10 @@ void Mesh::load(const char* filename)
 		}
 
 		// Mesh name
-		string meshName = bs.readString();
+		std::string meshName = bs.readString();
 
 		// Material name
-		string materialName = bs.readString();
+		std::string materialName = bs.readString();
 		if(materialName.length() > 0)
 		{
 			material.loadRsrc(materialName.c_str());
@@ -167,7 +167,6 @@ void Mesh::doPostLoad()
 		}
 		createVertIndeces();
 		createVbos();
-		calcBSphere();
 
 		// Sanity checks continued
 		if(material->stdAttribVars[Material::SAV_TEX_COORDS] != NULL && !vbos.texCoords.isCreated())
@@ -192,7 +191,7 @@ void Mesh::doPostLoad()
 //======================================================================================================================
 void Mesh::createVertIndeces()
 {
-	DEBUG_ERR(vertIndeces.size() > 0);
+	RASSERT_THROW_EXCEPTION(vertIndeces.size() > 0);
 
 	vertIndeces.resize(tris.size() * 3);
 	for(uint i=0; i<tris.size(); i++)
@@ -344,15 +343,6 @@ void Mesh::createVbos()
 }
 
 
-//======================================================================================================================
-// calcBSphere                                                                                                         =
-//======================================================================================================================
-void Mesh::calcBSphere()
-{
-	bsphere.Set(&vertCoords[0], 0, vertCoords.size());
-}
-
-
 //======================================================================================================================
 // isRenderable                                                                                                        =
 //======================================================================================================================

+ 0 - 4
src/Resources/Mesh.h

@@ -1,11 +1,9 @@
 #ifndef MESH_H
 #define MESH_H
 
-#include "Common.h"
 #include "Math.h"
 #include "Vbo.h"
 #include "Resource.h"
-#include "collision.h"
 #include "RsrcPtr.h"
 
 
@@ -77,7 +75,6 @@ class Mesh: public Resource
 		Vec<ushort>       vertIndeces; ///< Generated if renderable. Used for vertex arrays & VBOs
 		Vbos              vbos; ///< Generated if renderable
 		RsrcPtr<Material> material; ///< Required. If empty then mesh not renderable
-		bsphere_t         bsphere; ///< @todo
 
 		Mesh();
 		~Mesh() {}
@@ -93,7 +90,6 @@ class Mesh: public Resource
 		void createVertTangents();
 		void createVertIndeces();
 		void createVbos();
-		void calcBSphere();
 
 		/// This func does some sanity checks and creates normals, tangents, VBOs etc
 		/// @exception Exception

+ 2 - 3
src/Resources/Path.h

@@ -1,7 +1,6 @@
-#ifndef _PATH_H_
-#define _PATH_H_
+#ifndef PATH_H
+#define PATH_H
 
-#include "Common.h"
 #include "Resource.h"
 #include "Math.h"
 

+ 3 - 4
src/Resources/Texture.cpp

@@ -1,6 +1,5 @@
 #include <GL/glew.h>
 #include "Texture.h"
-#include "Renderer.h"
 #include "Image.h"
 #include "GlException.h"
 
@@ -22,7 +21,7 @@ int Texture::anisotropyLevel = 8;
 //======================================================================================================================
 Texture::Texture():
 	Resource(RT_TEXTURE),
-	glId(numeric_limits<uint>::max()),
+	glId(std::numeric_limits<uint>::max()),
 	target(GL_TEXTURE_2D)
 {}
 
@@ -109,7 +108,7 @@ void Texture::load(const char* filename)
 
 		ON_GL_FAIL_THROW_EXCEPTION();
 	}
-	catch(exception& e)
+	catch(std::exception& e)
 	{
 		throw EXCEPTION("File \"" + filename + "\": " + e.what());
 	}
@@ -146,7 +145,7 @@ void Texture::createEmpty2D(float width_, float height_, int internalFormat, int
 void Texture::createEmpty2DMsaa(int samplesNum, int internalFormat, int width_, int height_, bool mimapping)
 {
 	target = GL_TEXTURE_2D_MULTISAMPLE;
-	DEBUG_ERR(isLoaded());
+	RASSERT_THROW_EXCEPTION(isLoaded());
 
 	glGenTextures(1, &glId);
 	bind(LAST_TEX_UNIT);

+ 2 - 2
src/Resources/Texture.h

@@ -81,14 +81,14 @@ class Texture: public Resource
 
 inline uint Texture::getGlId() const
 {
-	DEBUG_ERR(!isLoaded());
+	RASSERT_THROW_EXCEPTION(!isLoaded());
 	return glId;
 }
 
 
 inline bool Texture::isLoaded() const
 {
-	return glId != numeric_limits<uint>::max();
+	return glId != std::numeric_limits<uint>::max();
 }
 
 #endif

+ 1 - 1
src/Util/CharPtrHashMap.h

@@ -33,7 +33,7 @@ struct CompareCharPtrHashMapKeys
 /// The hash map that has as key an old school C string. When inserting the char MUST NOT point to a temporary or the
 /// evaluation function will fail.
 template<typename Type>
-class CharPtrHashMap: public unordered_map<const char*, Type, CreateCharPtrHashMapKey, CompareCharPtrHashMapKeys>
+class CharPtrHashMap: public boost::unordered_map<const char*, Type, CreateCharPtrHashMapKey, CompareCharPtrHashMapKeys>
 {};
 
 

+ 1 - 0
src/Util/Util.h

@@ -3,6 +3,7 @@
 
 #include <string>
 #include "Vec.h"
+#include "StdTypes.h"
 
 
 /// The namespace contains a few useful functions

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.