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

Adding exceptions. Wont compile

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

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

@@ -38,7 +38,7 @@ class Resource
 
 	public:
 		Resource(const ResourceType& type_);
-		virtual ~Resource();
+		virtual ~Resource() {DEBUG_ERR(referenceCounter != 0);}
 
 	private:
 		/// Load the resource
@@ -54,9 +54,8 @@ inline Resource::Resource(const ResourceType& type_):
 {}
 
 
-inline Resource::~Resource()
-{
-	DEBUG_ERR(referenceCounter != 0);
-}
+/// Special throwing exception macro for the resources
+#define RSRC_THROW_EXCEPTION(x) THROW_EXCEPTION("File \"" + getRsrcPath() + "/" + getRsrcName() + "\: " + x)
+
 
 #endif

+ 7 - 3
src/Resources/Core/RsrcContainer.inl.h

@@ -91,14 +91,18 @@ Type* RsrcContainer<Type>::load(const char* fname)
 	newInstance->path = path;
 	newInstance->referenceCounter = 1;
 
-	if(!newInstance->load(fname))
+	try
+	{
+		newInstance->load(fname);
+	}
+	catch(exception& e)
 	{
-		ERROR("Cannot load \"" << fname << '\"');
 		delete newInstance;
 		return NULL;
+		THROW_EXCEPTION("Cannot load \"" << fname << '\"');
 	}
-	BaseClass::push_back(newInstance);
 
+	BaseClass::push_back(newInstance);
 	return newInstance;
 }
 

+ 2 - 2
src/Resources/Extension.h

@@ -1,5 +1,5 @@
-#ifndef ENSION_H_
-#define ENSION_H_
+#ifndef EXTENSION_H
+#define EXTENSION_H
 
 #include "Common.h"
 #include "Resource.h"

+ 94 - 98
src/Resources/Helpers/Image.cpp

@@ -3,11 +3,11 @@
 #include <boost/algorithm/string.hpp>
 #include <fstream>
 #include "Image.h"
-#include "Util.h"
+#include "Exception.h"
 
 
-#define IMG_ERROR(x) ERROR("File \"" << filename << "\": " << x)
-#define IMG_WARNING(x) WARNING("File \"" << filename << "\": " << x)
+using namespace std;
+using namespace boost;
 
 
 uchar Image::tgaHeaderUncompressed[12] = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0};
@@ -17,15 +17,14 @@ uchar Image::tgaHeaderCompressed[12]   = {0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 //======================================================================================================================
 // loadUncompressedTga                                                                                                 =
 //======================================================================================================================
-bool Image::loadUncompressedTga(const char* filename, fstream& fs, uint& bpp)
+void Image::loadUncompressedTga(fstream& fs, uint& bpp)
 {
 	// read the info from header
 	uchar header6[6];
 	fs.read((char*)&header6[0], sizeof(header6));
 	if(fs.gcount() != sizeof(header6))
 	{
-		IMG_ERROR("Cannot read info header");
-		return false;
+		THROW_EXCEPTION("Cannot read info header");
 	}
 
 	width  = header6[1] * 256 + header6[0];
@@ -34,8 +33,7 @@ bool Image::loadUncompressedTga(const char* filename, fstream& fs, uint& bpp)
 
 	if((width <= 0) || (height <= 0) || ((bpp != 24) && (bpp !=32)))
 	{
-		IMG_ERROR("Invalid image information");
-		return false;
+		THROW_EXCEPTION("Invalid image information");
 	}
 
 	// read the data
@@ -46,8 +44,7 @@ bool Image::loadUncompressedTga(const char* filename, fstream& fs, uint& bpp)
 	fs.read(reinterpret_cast<char*>(&data[0]), imageSize);
 	if(fs.gcount() != imageSize)
 	{
-		IMG_ERROR("Cannot read image data");
-		return false;
+		THROW_EXCEPTION("Cannot read image data");
 	}
 
 	// swap red with blue
@@ -57,22 +54,19 @@ bool Image::loadUncompressedTga(const char* filename, fstream& fs, uint& bpp)
 		data[i] = data[i + 2];
 		data[i + 2] = temp;
 	}
-
-	return true;
 }
 
 
 //======================================================================================================================
 // loadCompressedTga                                                                                                   =
 //======================================================================================================================
-bool Image::loadCompressedTga(const char* filename, fstream& fs, uint& bpp)
+void Image::loadCompressedTga(fstream& fs, uint& bpp)
 {
 	unsigned char header6[6];
 	fs.read((char*)&header6[0], sizeof(header6));
 	if(fs.gcount() != sizeof(header6))
 	{
-		IMG_ERROR("Cannot read info header");
-		return false;
+		THROW_EXCEPTION("Cannot read info header");
 	}
 
 	width  = header6[1] * 256 + header6[0];
@@ -81,8 +75,7 @@ bool Image::loadCompressedTga(const char* filename, fstream& fs, uint& bpp)
 
 	if((width <= 0) || (height <= 0) || ((bpp != 24) && (bpp !=32)))
 	{
-		IMG_ERROR("Invalid texture information");
-		return false;
+		THROW_EXCEPTION("Invalid texture information");
 	}
 
 
@@ -102,8 +95,7 @@ bool Image::loadCompressedTga(const char* filename, fstream& fs, uint& bpp)
 		fs.read((char*)&chunkheader, sizeof(unsigned char));
 		if(fs.gcount() != sizeof(unsigned char))
 		{
-			IMG_ERROR("Cannot read RLE header");
-			return false;
+			THROW_EXCEPTION("Cannot read RLE header");
 		}
 
 		if(chunkheader < 128)
@@ -114,8 +106,7 @@ bool Image::loadCompressedTga(const char* filename, fstream& fs, uint& bpp)
 				fs.read((char*)&colorbuffer[0], bytesPerPxl);
 				if(fs.gcount() != bytesPerPxl)
 				{
-					IMG_ERROR("Cannot read image data");
-					return false;
+					THROW_EXCEPTION("Cannot read image data");
 				}
 
 				data[currentbyte		] = colorbuffer[2];
@@ -132,8 +123,7 @@ bool Image::loadCompressedTga(const char* filename, fstream& fs, uint& bpp)
 
 				if(currentpixel > pixelcount)
 				{
-					IMG_ERROR("Too many pixels read");
-					return false;
+					THROW_EXCEPTION("Too many pixels read");
 				}
 			}
 		}
@@ -143,8 +133,7 @@ bool Image::loadCompressedTga(const char* filename, fstream& fs, uint& bpp)
 			fs.read((char*)&colorbuffer[0], bytesPerPxl);
 			if(fs.gcount() != bytesPerPxl)
 			{
-				IMG_ERROR("Cannot read from file");
-				return false;
+				THROW_EXCEPTION("Cannot read from file");
 			}
 
 			for(int counter = 0; counter < chunkheader; counter++)
@@ -163,21 +152,18 @@ bool Image::loadCompressedTga(const char* filename, fstream& fs, uint& bpp)
 
 				if(currentpixel > pixelcount)
 				{
-					IMG_ERROR("Too many pixels read");
-					return false;
+					THROW_EXCEPTION("Too many pixels read");
 				}
 			}
 		}
 	} while(currentpixel < pixelcount);
-
-	return true;
 }
 
 
 //======================================================================================================================
 // loadTga                                                                                                             =
 //======================================================================================================================
-bool Image::loadTga(const char* filename)
+void Image::loadTga(const char* filename)
 {
 	fstream fs;
 	char myTgaHeader[12];
@@ -186,53 +172,54 @@ bool Image::loadTga(const char* filename)
 
 	if(!fs.good())
 	{
-		IMG_ERROR("Cannot open file");
-		return false;
+		THROW_EXCEPTION("Cannot open file");
 	}
 
 	fs.read(&myTgaHeader[0], sizeof(myTgaHeader));
 	if(fs.gcount() != sizeof(myTgaHeader))
 	{
-		IMG_ERROR("Cannot read file header");
 		fs.close();
-		return false;
+		THROW_EXCEPTION("Cannot read file header");
 	}
 
-	bool funcsReturn;
 	if(memcmp(tgaHeaderUncompressed, &myTgaHeader[0], sizeof(myTgaHeader)) == 0)
 	{
-		funcsReturn = loadUncompressedTga(filename, fs, bpp);
+		loadUncompressedTga(fs, bpp);
 	}
 	else if(memcmp(tgaHeaderCompressed, &myTgaHeader[0], sizeof(myTgaHeader)) == 0)
 	{
-		funcsReturn = loadCompressedTga(filename, fs, bpp);
+		loadCompressedTga(fs, bpp);
 	}
 	else
 	{
-		IMG_ERROR("Invalid image header");
-		funcsReturn = false;
+		THROW_EXCEPTION("Invalid image header");
 	}
 
 	if(bpp == 32)
+	{
 		type = CT_RGBA;
+	}
 	else if(bpp == 24)
+	{
 		type = CT_RGB;
+	}
 	else
-		FATAL("See file");
+	{
+		THROW_EXCEPTION("Invalid bps");
+	}
 
 	fs.close();
-	return funcsReturn;
 }
 
 
 //======================================================================================================================
 // loadPng                                                                                                             =
 //======================================================================================================================
-bool Image::loadPng(const char* filename)
+bool Image::loadPng(const char* filename, string& err) throw()
 {
-	/*
-	 * All locals
-	 */
+	//
+	// All locals
+	//
 	const uint PNG_SIG_SIZE = 8; // PNG header size
 	FILE* file = NULL;
 	png_structp pngPtr = NULL;
@@ -245,69 +232,69 @@ bool Image::loadPng(const char* filename)
 	uint colorType;
 	vector<png_bytep> rowPointers;
 
-	/*
-	 * Open file
-	 */
+	//
+	// Open file
+	//
 	file = fopen(filename, "rb");
 	if(file == NULL)
 	{
-		IMG_ERROR("Cannot open file");
+		err = "Cannot open file";
 		goto cleanup;
 	}
 
-	/*
-	 * Validate PNG header
-	 */
+	//
+	// Validate PNG header
+	//
 	png_byte pngsig[PNG_SIG_SIZE];
 	charsRead = fread(pngsig, 1, PNG_SIG_SIZE, file);
 	if(charsRead != PNG_SIG_SIZE)
 	{
-		IMG_ERROR("Cannot read PNG header");
+		err = "Cannot read PNG header";
 		goto cleanup;
 	}
 
 	if(png_sig_cmp(pngsig, 0, PNG_SIG_SIZE) != 0)
 	{
-		IMG_ERROR("File not PNG image");
+		err = "File not PNG image";
 		goto cleanup;
 	}
 
-	/*
-	 * Crete some PNG structs
-	 */
+	//
+	// Crete some PNG structs
+	//
 	pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
 	if(!pngPtr)
 	{
-		IMG_ERROR("png_create_read_struct failed");
+		THROW_EXCEPTION("png_create_read_struct failed");
 		goto cleanup;
 	}
 
 	infoPtr = png_create_info_struct(pngPtr);
 	if(!infoPtr)
 	{
-		IMG_ERROR("png_create_info_struct failed");
+		err = "png_create_info_struct failed";
 		goto cleanup;
 	}
 
-	/*
-	 * Set error handling
-	 */
+	//
+	// Set error handling
+	//
 	if(setjmp(png_jmpbuf(pngPtr)))
 	{
-		IMG_ERROR("Reading PNG file failed");
+		err = "Reading PNG file failed";
 		goto cleanup;
 	}
 
-	/*
-	 * Init io
-	 */
+	//
+	// Init io
+	//
 	png_init_io(pngPtr, file);
 	png_set_sig_bytes(pngPtr, PNG_SIG_SIZE); // PNG lib knows that we allready have read the header
 
-	/*
-	 * Read info and make conversions
-	 * This loop reads info, if not acceptable it calls libpng funcs to change them and re-runs the loop
-	 */
+	//
+	// Read info and make conversions
+	// This loop reads info, if not acceptable it calls libpng funcs to change them and re-runs the loop
+	//
 	png_read_info(pngPtr, infoPtr);
 	while(true)
 	{
@@ -321,7 +308,7 @@ bool Image::loadPng(const char* filename)
 		switch(colorType)
 		{
 			case PNG_COLOR_TYPE_PALETTE:
-				IMG_WARNING("Converting PNG_COLOR_TYPE_PALETTE to PNG_COLOR_TYPE_RGB or PNG_COLOR_TYPE_RGBA");
+				err = "Converting PNG_COLOR_TYPE_PALETTE to PNG_COLOR_TYPE_RGB or PNG_COLOR_TYPE_RGBA";
 				png_set_palette_to_rgb(pngPtr);
 				goto again;
 				break;
@@ -329,7 +316,7 @@ bool Image::loadPng(const char* filename)
 				// do nothing
 				break;
 			case PNG_COLOR_TYPE_GRAY_ALPHA:
-				IMG_WARNING("Cannot accept PNG_COLOR_TYPE_GRAY_ALPHA. Converting to PNG_COLOR_TYPE_GRAY");
+				err = "Cannot accept PNG_COLOR_TYPE_GRAY_ALPHA. Converting to PNG_COLOR_TYPE_GRAY";
 				png_set_strip_alpha(pngPtr);
 				goto again;
 				break;
@@ -340,21 +327,21 @@ bool Image::loadPng(const char* filename)
 				// do nothing
 				break;
 			default:
-				FATAL("Forgot to handle a color type");
+				THROW_EXCEPTION("Forgot to handle a color type");
 				break;
 		}
 
 		// 2) Convert the bit depths
 		if(colorType == PNG_COLOR_TYPE_GRAY && bitDepth < 8)
 		{
-			IMG_WARNING("Converting bit depth");
+			err = "Converting bit depth";
 			png_set_gray_1_2_4_to_8(pngPtr);
 			goto again;
 		}
 
 		if(bitDepth > 8)
 		{
-			IMG_WARNING("Converting bit depth");
+			err = "Converting bit depth";
 			png_set_strip_16(pngPtr);
 		}
 
@@ -368,13 +355,13 @@ bool Image::loadPng(const char* filename)
 	if((bitDepth != 8) ||
 		 (colorType != PNG_COLOR_TYPE_GRAY && colorType != PNG_COLOR_TYPE_RGB && colorType != PNG_COLOR_TYPE_RGBA))
 	{
-		IMG_ERROR("Sanity checks failed");
+		err = "Sanity checks failed";
 		goto cleanup;
 	}
 
-	/*
-	 * Read this sucker
-	 */
+	//
+	// Read this sucker
+	//
 	rowbytes = png_get_rowbytes(pngPtr, infoPtr);
 
 	rowPointers.resize(height * sizeof(png_bytep));
@@ -386,9 +373,9 @@ bool Image::loadPng(const char* filename)
 
 	png_read_image(pngPtr, &rowPointers[0]);
 
-	/*
-	 * Finalize
-	 */
+	//
+	// Finalize
+	//
 	switch(colorType)
 	{
 		case PNG_COLOR_TYPE_GRAY:
@@ -404,21 +391,27 @@ bool Image::loadPng(const char* filename)
 
 	ok = true;
 
-	/*
-	 * Cleanup
-	 */
+	//
+	// Cleanup
+	//
 	cleanup:
 
 	if(pngPtr)
 	{
 		if(infoPtr)
+		{
 			png_destroy_read_struct(&pngPtr, &infoPtr, NULL);
+		}
 		else
+		{
 			png_destroy_read_struct(&pngPtr, NULL, NULL);
+		}
 	}
 
 	if(file)
+	{
 		fclose(file);
+	}
 
 	return ok;
 }
@@ -427,7 +420,7 @@ bool Image::loadPng(const char* filename)
 //======================================================================================================================
 // load                                                                                                                =
 //======================================================================================================================
-bool Image::load(const char* filename)
+void Image::load(const char* filename)
 {
 	// get the extension
 	string ext = filesystem::path(filename).extension();
@@ -435,25 +428,28 @@ bool Image::load(const char* filename)
 
 
 	// load from this extension
-	if(ext == ".tga")
+	try
 	{
-		if(!loadTga(filename))
+		if(ext == ".tga")
 		{
-			return false;
+			loadTga(filename);
 		}
-	}
-	else if(ext == ".png")
-	{
-		if(!loadPng(filename))
+		else if(ext == ".png")
 		{
-			return false;
+			string err;
+			if(!loadPng(filename, err))
+			{
+				THROW_EXCEPTION(err);
+			}
+		}
+		else
+		{
+			THROW_EXCEPTION("Unsupported extension");
 		}
 	}
-	else
+	catch(std::exception& e)
 	{
-		IMG_ERROR("Unsupported extension");
-		return false;
+		THROW_EXCEPTION("File \"" + filename + "\": " + e.what());
 	}
-	return true;
 }
 

+ 44 - 25
src/Resources/Helpers/Image.h

@@ -1,50 +1,69 @@
 #ifndef IMAGE_H
 #define IMAGE_H
 
-#include "Common.h"
 #include "Vec.h"
+#include "Properties.h"
+#include "StdTypes.h"
 
 
-/**
- * Image class. Used in Texture::load. Supported images: TGA and PNG
- */
+/// Image class. Used in Texture::load. Supported types: TGA and PNG
 class Image
 {
 	public:
-		/**
-		 * The acceptable color types of AnKi
-		 */
+		/// The acceptable color types of AnKi
 		enum ColorType
 		{
-			CT_R,
-			CT_RGB,
-			CT_RGBA
+			CT_R, ///< Red only
+			CT_RGB, ///< RGB
+			CT_RGBA /// RGB and alpha
 		};
 
-	PROPERTY_R(uint, width, getWidth)
-	PROPERTY_R(uint, height, getHeight)
-	PROPERTY_R(ColorType, type, getType)
-	PROPERTY_R(Vec<uchar>, data, getData)
+	PROPERTY_R(uint, width, getWidth) ///< Image width
+	PROPERTY_R(uint, height, getHeight) ///< Image height
+	PROPERTY_R(ColorType, type, getType) ///< Image color type
+	PROPERTY_R(Vec<uchar>, data, getData) ///< Image data
 
 	public:
-		Image() {}
+		/// Load an image
+		/// @param[in] filename The image file to load
+		/// @exception Exception
+		Image(const char* filename) {load(filename);}
 		~Image() {}
-		bool load(const char* filename);
 
 	private:
+		/// @name TGA headers
+		/// @{
 		static uchar tgaHeaderUncompressed[12];
 		static uchar tgaHeaderCompressed[12];
+		/// @}
 
-		/**
-		 * @name TGA help functions
-		 */
-		/**@{*/
-		bool loadUncompressedTga(const char* filename, fstream& fs, uint& bpp);
-		bool loadCompressedTga(const char* filename, fstream& fs, uint& bpp);
-		/**@}*/
+		/// Load an image file
+		/// @param[in] filename The file to load
+		/// @exception Exception
+		void load(const char* filename);
 
-		bool loadPng(const char* filename);
-		bool loadTga(const char* filename);
+		/// Load a TGA
+		/// @param[in] filename The file to load
+		/// @exception Exception
+		void loadTga(const char* filename);
+
+		/// Used by loadTga
+		/// @param[in] fs The input
+		/// @param[out] bpp Bits per pixel
+		/// @exception Exception
+		void loadUncompressedTga(std::fstream& fs, uint& bpp);
+
+		/// Used by loadTga
+		/// @param[in] fs The input
+		/// @param[out] bpp Bits per pixel
+		/// @exception Exception
+		void loadCompressedTga(std::fstream& fs, uint& bpp);
+
+		/// Load PNG. Dont throw exception because libpng is in C
+		/// @param[in] filename The file to load
+		/// @param[out] err The error message
+		/// @return true on success
+		bool loadPng(const char* filename, std::string& err) throw();
 };
 
 

+ 37 - 53
src/Resources/Helpers/ShaderPrePreprocessor.h

@@ -1,38 +1,34 @@
-#ifndef _SHADERPARSER_H_
-#define _SHADERPARSER_H_
+#ifndef SHADER_PARSER_H
+#define SHADER_PARSER_H
 
 #include <limits>
 #include "Common.h"
 #include "Vec.h"
 
 
-/**
- * Helper class used for shader program loading
- *
- * The class fills some of the GLSL spec deficiencies. It adds the include preprocessor directive and the support to
- * have all the shaders in the same file. The file that includes all the shaders is called
- * ShaderPrePreprocessor-compatible.
- *
- * The preprocessor pragmas are:
- *
- * - #pragma anki vertShaderBegins
- * - #pragma anki geomShaderBegins
- * - #pragma anki fragShaderBegins
- * - #pragma anki attribute <varName> <customLocation>
- * - #pragma anki include "<filename>"
- * - #pragma anki transformFeedbackVarying <varName>
- *
- * @note The order of the *ShaderBegins is important
- */
+/// Helper class used for shader program loading
+///
+/// The class fills some of the GLSL spec deficiencies. It adds the include preprocessor directive and the support to
+/// have all the shaders in the same file. The file that includes all the shaders is called
+/// ShaderPrePreprocessor-compatible.
+///
+/// The preprocessor pragmas are:
+///
+/// - #pragma anki vertShaderBegins
+/// - #pragma anki geomShaderBegins
+/// - #pragma anki fragShaderBegins
+/// - #pragma anki attribute <varName> <customLocation>
+/// - #pragma anki include "<filename>"
+/// - #pragma anki transformFeedbackVarying <varName>
+///
+/// @note The order of the *ShaderBegins is important
 class ShaderPrePreprocessor
 {
 	//====================================================================================================================
 	// Nested                                                                                                            =
 	//====================================================================================================================
 	protected:
-		/**
-		 * The pragma base class
-		 */
+		/// The pragma base class
 		struct Pragma
 		{
 			string definedInFile;
@@ -68,17 +64,13 @@ class ShaderPrePreprocessor
 			CodeBeginningPragma();
 		};
 
-		/**
-		 * The output of the class packed in this struct
-		 */
+		/// The output of the class packed in this struct
 		struct Output
 		{
 			friend class ShaderPrePreprocessor;
 
 			PROPERTY_R(Vec<ShaderVarPragma>, attributes, getAttribLocs) ///< It holds the name and the custom location
-			/**
-			 * Names and and ids for transform feedback varyings
-			 */
+			/// Names and and ids for transform feedback varyings
 			PROPERTY_R(Vec<TrffbVaryingPragma>, trffbVaryings, getTrffbVaryings)
 			PROPERTY_R(string, vertShaderSource, getVertShaderSource) ///< The vert shader source
 			PROPERTY_R(string, geomShaderSource, getGeomShaderSource) ///< The geom shader source
@@ -97,11 +89,9 @@ class ShaderPrePreprocessor
 		ShaderPrePreprocessor() {}
 		~ShaderPrePreprocessor() {}
 
-		/**
-		 * Parse a ShaderPrePreprocessor formated GLSL file. Use getOutput to get the output
-		 * @param fname The file to parse
-		 * @return True on success
-		 */
+		/// Parse a ShaderPrePreprocessor formated GLSL file. Use getOutput to get the output
+		/// @param fname The file to parse
+		/// @return True on success
 		bool parseFile(const char* fname);
 
 	//====================================================================================================================
@@ -113,29 +103,23 @@ class ShaderPrePreprocessor
 		CodeBeginningPragma geomShaderBegins;
 		CodeBeginningPragma fragShaderBegins;
 		
-		/**
-		 * A recursive function that parses a file for pragmas and updates the output
-		 * @param filename The file to parse
-		 * @param depth The #line in GLSL does not support filename so an depth it being used. It also tracks the includance
-		 * depth
-		 * @return True on success
-		 */
+		/// A recursive function that parses a file for pragmas and updates the output
+		/// @param filename The file to parse
+		/// @param depth The #line in GLSL does not support filename so an depth it being used. It also tracks the includance
+		/// depth
+		/// @return True on success
 		bool parseFileForPragmas(const string& filename, int depth = 0);
 
-		/**
-		 * Searches inside the Output::uniforms or Output::attributes vectors
-		 * @param vec Output::uniforms or Output::attributes
-		 * @param name The name of the location
-		 * @return Iterator to the vector
-		 */
+		/// Searches inside the Output::uniforms or Output::attributes vectors
+		/// @param vec Output::uniforms or Output::attributes
+		/// @param name The name of the location
+		/// @return Iterator to the vector
 		Vec<ShaderVarPragma>::iterator findShaderVar(Vec<ShaderVarPragma>& vec, const string& name) const;
 
-		/**
-		 * Searches inside the Output::attributes or Output::trffbVaryings vectors
-		 * @param vec Output::uniforms or Output::trffbVaryings
-		 * @param what The name of the varying or attrib
-		 * @return Iterator to the vector
-		 */
+		/// Searches inside the Output::attributes or Output::trffbVaryings vectors
+		/// @param vec Output::uniforms or Output::trffbVaryings
+		/// @param what The name of the varying or attrib
+		/// @return Iterator to the vector
 		template<typename Type>
 		typename Vec<Type>::const_iterator findNamed(const Vec<Type>& vec, const string& what) const;
 

+ 12 - 16
src/Resources/LightData.cpp

@@ -22,7 +22,7 @@ LightData::LightData():
 //======================================================================================================================
 // load                                                                                                                =
 //======================================================================================================================
-bool LightData::load(const char* filename)
+void LightData::load(const char* filename)
 {
 	try
 	{
@@ -50,7 +50,7 @@ bool LightData::load(const char* filename)
 					}
 					else
 					{
-						PARSE_ERR_EXPECTED("LT_SPOT or LT_POINT");
+						PARSER_THROW_EXCEPTION_EXPECTED("LT_SPOT or LT_POINT");
 						return false;
 					}
 				}
@@ -71,7 +71,7 @@ bool LightData::load(const char* filename)
 				token = &scanner.getNextToken();
 				if(token->getCode() != Scanner::TC_NUMBER)
 				{
-					PARSE_ERR_EXPECTED("number");
+					PARSER_THROW_EXCEPTION_EXPECTED("number");
 					return false;
 				}
 
@@ -94,13 +94,13 @@ bool LightData::load(const char* filename)
 					}
 					else
 					{
-						PARSE_ERR_EXPECTED("true or false");
+						PARSER_THROW_EXCEPTION_EXPECTED("true or false");
 						return false;
 					}
 				}
 				else
 				{
-					PARSE_ERR_EXPECTED("true or false");
+					PARSER_THROW_EXCEPTION_EXPECTED("true or false");
 					return false;
 				}
 			}
@@ -110,7 +110,7 @@ bool LightData::load(const char* filename)
 				token = &scanner.getNextToken();
 				if(token->getCode() != Scanner::TC_NUMBER)
 				{
-					PARSE_ERR_EXPECTED("number");
+					PARSER_THROW_EXCEPTION_EXPECTED("number");
 					return false;
 				}
 
@@ -124,7 +124,7 @@ bool LightData::load(const char* filename)
 				token = &scanner.getNextToken();
 				if(token->getCode() != Scanner::TC_NUMBER)
 				{
-					PARSE_ERR_EXPECTED("number");
+					PARSER_THROW_EXCEPTION_EXPECTED("number");
 					return false;
 				}
 
@@ -138,7 +138,7 @@ bool LightData::load(const char* filename)
 				token = &scanner.getNextToken();
 				if(token->getCode() != Scanner::TC_NUMBER)
 				{
-					PARSE_ERR_EXPECTED("number");
+					PARSER_THROW_EXCEPTION_EXPECTED("number");
 					return false;
 				}
 
@@ -152,7 +152,7 @@ bool LightData::load(const char* filename)
 				token = &scanner.getNextToken();
 				if(token->getCode() != Scanner::TC_STRING)
 				{
-					PARSE_ERR_EXPECTED("string");
+					PARSER_THROW_EXCEPTION_EXPECTED("string");
 					return false;
 				}
 
@@ -170,23 +170,19 @@ bool LightData::load(const char* filename)
 			// other crap
 			else
 			{
-				PARSE_ERR_UNEXPECTED();
+				PARSER_THROW_EXCEPTION_UNEXPECTED();
 				return false;
 			}
 		} // end while
 	}
 	catch(std::exception& e)
 	{
-		ERROR(e.what());
-		return false;
+		THROW_EXCEPTION(e.what());
 	}
 	
 	// sanity checks
 	if(type == LT_NUM)
 	{
-		ERROR("Forgot to set type");
-		return false;
+		THROW_EXCEPTION("Forgot to set type");
 	}
-
-	return true;
 }

+ 1 - 1
src/Resources/LightData.h

@@ -42,7 +42,7 @@ class LightData: public Resource
 	public:
 		LightData();
 		~LightData() {}
-		bool load(const char* filename);
+		void load(const char* filename);
 		const Texture& getTexture() const;
 
 	private:

+ 82 - 80
src/Resources/Material.cpp

@@ -9,8 +9,8 @@
 #include "MainRenderer.h"
 
 
-/// Customized @ref ERROR used in @ref Material class
-#define MTL_ERROR(x) ERROR("Material (" << getRsrcPath() << getRsrcName() << "): " << x);
+/// Customized THROW_EXCEPTION
+#define MTL_THROW_EXCEPTION(x) THROW_EXCEPTION("Material \"" + getRsrcPath() + getRsrcName() + "\": " + x)
 
 
 //======================================================================================================================
@@ -54,15 +54,15 @@ Material::StdVarNameAndGlDataTypePair Material::stdUniVarInfos[SUV_NUM] =
 // Stuff for custom material stage shader prgs                                                                         =
 //======================================================================================================================
 
+/// A simple pair-like structure
 struct MsSwitch
 {
 	const char* switchName;
 	const char prefix;
 };
 
-/**
- * See the docs for info about the switches
- */
+
+/// See the docs for info about the switches
 static MsSwitch msSwitches [] =
 {
 	{"DIFFUSE_MAPPING", 'd'},
@@ -120,7 +120,7 @@ static bool searchBlendEnum(const char* str, int& gl_enum)
 //======================================================================================================================
 // load                                                                                                                =
 //======================================================================================================================
-bool Material::load(const char* filename)
+void Material::load(const char* filename)
 {
 	try
 	{
@@ -131,17 +131,19 @@ bool Material::load(const char* filename)
 		{
 			token = &scanner.getNextToken();
 
-			//** SHADER_PROG **
+			//
+			// SHADER_PROG
+			//
 			if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "SHADER_PROG"))
 			{
 				if(shaderProg.get())
 				{
-					ERROR("Shader program already loaded");
-					return false;
+					PARSER_THROW_EXCEPTION("Shader program already loaded");
 				}
 
 				token = &scanner.getNextToken();
 				string shaderFilename;
+				// Just a string
 				if(token->getCode() == Scanner::TC_STRING)
 				{
 					shaderFilename = token->getValue().getString();
@@ -153,16 +155,14 @@ bool Material::load(const char* filename)
 					token = &scanner.getNextToken();
 					if(token->getCode() != Scanner::TC_LPAREN)
 					{
-						PARSE_ERR_EXPECTED("(");
-						return false;
+						PARSER_THROW_EXCEPTION_EXPECTED("(");
 					}
 
 					// shader prog
 					token = &scanner.getNextToken();
 					if(token->getCode() != Scanner::TC_STRING)
 					{
-						PARSE_ERR_EXPECTED("string");
-						return false;
+						PARSER_THROW_EXCEPTION_EXPECTED("string");
 					}
 					string sProgFilename = token->getValue().getString();
 
@@ -174,28 +174,30 @@ bool Material::load(const char* filename)
 						token = &scanner.getNextToken();
 
 						if(token->getCode() == Scanner::TC_RPAREN)
+						{
 							break;
+						}
 
 						if(token->getCode() != Scanner::TC_IDENTIFIER)
 						{
-							PARSE_ERR_EXPECTED("identifier");
-							return false;
+							PARSER_THROW_EXCEPTION_EXPECTED("identifier");
 						}
 
-						// check if acceptable value
+						// Check if acceptable value. Loop the switches array
 						MsSwitch* mss = msSwitches;
 						while(mss->switchName != NULL)
 						{
 							if(!strcmp(mss->switchName, token->getString()))
+							{
 								break;
+							}
 
 							++mss;
 						}
 
 						if(mss->switchName == NULL)
 						{
-							PARSE_ERR("Incorrect switch " << token->getString());
-							return false;
+							PARSER_THROW_EXCEPTION("Incorrect switch " + token->getString());
 						}
 
 						source += string("#define ") + token->getString() + "\n";
@@ -208,132 +210,140 @@ bool Material::load(const char* filename)
 				}
 				else
 				{
-					PARSE_ERR_EXPECTED("string or buildMsSProg");
-					return false;
+					PARSER_THROW_EXCEPTION_EXPECTED("string or buildMsSProg");
 				}
 
 				shaderProg.loadRsrc(shaderFilename.c_str());
 			}
-			//** DEPTH_MATERIAL **
+			//
+			// DEPTH_PASS_MATERIAL
+			//
 			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "DEPTH_PASS_MATERIAL"))
 			{
 				if(dpMtl.get())
-					ERROR("Depth material already loaded");
+				{
+					PARSER_THROW_EXCEPTION("Depth material already loaded");
+				}
 
 				token = &scanner.getNextToken();
 				if(token->getCode() != Scanner::TC_STRING)
 				{
-					PARSE_ERR_EXPECTED("string");
-					return false;
+					PARSER_THROW_EXCEPTION_EXPECTED("string");
 				}
 				dpMtl.loadRsrc(token->getValue().getString());
 			}
-			//** BLENDS **
+			//
+			// BLENDS
+			//
 			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "BLENDS"))
 			{
 				token = &scanner.getNextToken();
 				if(token->getCode() != Scanner::TC_NUMBER)
 				{
-					PARSE_ERR_EXPECTED("number");
-					return false;
+					PARSER_THROW_EXCEPTION_EXPECTED("number");
 				}
 				blends = token->getValue().getInt();
 			}
-			//** BLENDING_SFACTOR **
+			//
+			// BLENDING_SFACTOR
+			//
 			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "BLENDING_SFACTOR"))
 			{
 				token = &scanner.getNextToken();
 				if(token->getCode() != Scanner::TC_IDENTIFIER)
 				{
-					PARSE_ERR_EXPECTED("identifier");
-					return false;
+					PARSER_THROW_EXCEPTION_EXPECTED("identifier");
 				}
 				int gl_enum;
 				if(!searchBlendEnum(token->getValue().getString(), gl_enum))
 				{
-					PARSE_ERR("Incorrect blending factor \"" << token->getValue().getString() << "\"");
-					return false;
+					PARSER_THROW_EXCEPTION("Incorrect blending factor \"" + token->getValue().getString() + "\"");
 				}
 				blendingSfactor = gl_enum;
 			}
-			//** BLENDING_DFACTOR **
+			//
+			// BLENDING_DFACTOR
+			//
 			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "BLENDING_DFACTOR"))
 			{
 				token = &scanner.getNextToken();
 				if(token->getCode() != Scanner::TC_IDENTIFIER)
 				{
-					PARSE_ERR_EXPECTED("identifier");
-					return false;
+					PARSER_THROW_EXCEPTION_EXPECTED("identifier");
 				}
 				int gl_enum;
 				if(!searchBlendEnum(token->getValue().getString(), gl_enum))
 				{
 					PARSE_ERR("Incorrect blending factor \"" << token->getValue().getString() << "\"");
-					return false;
 				}
 				blendingDfactor = gl_enum;
 			}
-			//** DEPTH_TESTING **
+			//
+			// DEPTH_TESTING
+			//
 			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "DEPTH_TESTING"))
 			{
 				token = &scanner.getNextToken();
 				if(token->getCode() != Scanner::TC_NUMBER)
 				{
-					PARSE_ERR_EXPECTED("number");
-					return false;
+					PARSER_THROW_EXCEPTION_EXPECTED("number");
 				}
 				depthTesting = token->getValue().getInt();
 			}
-			//** WIREFRAME **
+			//
+			// WIREFRAME
+			//
 			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "WIREFRAME"))
 			{
 				token = &scanner.getNextToken();
 				if(token->getCode() != Scanner::TC_NUMBER)
 				{
-					PARSE_ERR_EXPECTED("number");
-					return false;
+					PARSER_THROW_EXCEPTION_EXPECTED("number");
 				}
 				wireframe = token->getValue().getInt();
 			}
-			//** CASTS_SHADOW **
+			//
+			// CASTS_SHADOW
+			//
 			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "CASTS_SHADOW"))
 			{
 				token = &scanner.getNextToken();
 				if(token->getCode() != Scanner::TC_NUMBER)
 				{
-					PARSE_ERR_EXPECTED("number");
-					return false;
+					PARSER_THROW_EXCEPTION_EXPECTED("number");
 				}
 				castsShadow = token->getValue().getInt();
 			}
-			//** USER_DEFINED_VARS **
+			//
+			// USER_DEFINED_VARS
+			//
 			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "USER_DEFINED_VARS"))
 			{
 				// first check if the shader is defined
 				if(shaderProg.get() == NULL)
 				{
-					PARSE_ERR("You have to define the shader program before the user defined vars");
-					return false;
+					PARSER_THROW_EXCEPTION("You have to define the shader program before the user defined vars");
 				}
 
-				// read {
+				// {
 				token = &scanner.getNextToken();
 				if(token->getCode() != Scanner::TC_LBRACKET)
 				{
-					PARSE_ERR_EXPECTED("{");
-					return false;
+					PARSER_THROW_EXCEPTION_EXPECTED("{");
 				}
 				// loop all the vars
 				do
 				{
 					// read the name
 					token = &scanner.getNextToken();
-					if(token->getCode() == Scanner::TC_RBRACKET) break;
+					if(token->getCode() == Scanner::TC_RBRACKET)
+					{
+						break;
+					}
 
 					if(token->getCode() != Scanner::TC_IDENTIFIER)
 					{
-						PARSE_ERR_EXPECTED("identifier");
-						return false;
+						PARSER_THROW_EXCEPTION_EXPECTED("identifier");
 					}
 
 					string varName;
@@ -345,8 +355,7 @@ bool Material::load(const char* filename)
 					// check if the uniform exists
 					if(!shaderProg->uniVarExists(varName.c_str()))
 					{
-						PARSE_ERR("The variable \"" << varName << "\" is not an active uniform");
-						return false;
+						PARSER_THROW_EXCEPTION("The variable \"" + varName + "\" is not an active uniform");
 					}
 
 					var.sProgVar = shaderProg->findUniVar(varName.c_str());
@@ -360,13 +369,10 @@ bool Material::load(const char* filename)
 							if(token->getCode() == Scanner::TC_STRING)
 							{
 								var.value.texture.loadRsrc(token->getValue().getString());
-								if(var.value.texture.get() == NULL)
-									return false;
 							}
 							else
 							{
-								PARSE_ERR_EXPECTED("string");
-								return false;
+								PARSER_THROW_EXCEPTION_EXPECTED("string");
 							}
 							break;
 						// float
@@ -378,8 +384,7 @@ bool Material::load(const char* filename)
 							}
 							else
 							{
-								PARSE_ERR_EXPECTED("float");
-								return false;
+								PARSER_THROW_EXCEPTION_EXPECTED("float");
 							}
 							break;
 						// vec2
@@ -399,39 +404,40 @@ bool Material::load(const char* filename)
 				}while(true); // end loop for all the vars
 
 			}
-			// end of file
+			//
+			// EOF
+			//
 			else if(token->getCode() == Scanner::TC_EOF)
 			{
 				break;
 			}
+			//
 			// other crap
+			//
 			else
 			{
-				PARSE_ERR_UNEXPECTED();
-				return false;
+				PARSER_THROW_EXCEPTION_UNEXPECTED();
 			}
 		} // end while
 	}
 	catch(std::exception& e)
 	{
 		ERROR(e.what());
-		return false;
 	}
 
-	return initStdShaderVars();
+	initStdShaderVars();
 }
 
 
 //======================================================================================================================
 // initStdShaderVars                                                                                                   =
 //======================================================================================================================
-bool Material::initStdShaderVars()
+void Material::initStdShaderVars()
 {
 	// sanity checks
 	if(!shaderProg.get())
 	{
-		MTL_ERROR("Without shader is like cake without sugar (missing SHADER_PROG)");
-		return false;
+		MTL_THROW_EXCEPTION("Without shader is like cake without sugar (missing SHADER_PROG)");
 	}
 
 	// the attributes
@@ -450,10 +456,9 @@ bool Material::initStdShaderVars()
 		// check if the shader has different GL data type from that it suppose to have
 		if(stdAttribVars[i]->getGlDataType() != stdAttribVarInfos[i].dataType)
 		{
-			MTL_ERROR("The \"" << stdAttribVarInfos[i].varName <<
-			          "\" attribute var has incorrect GL data type from the expected (0x" << hex <<
-			          stdAttribVars[i]->getGlDataType() << ")");
-			return false;
+			MTL_THROW_EXCEPTION("The \"" + stdAttribVarInfos[i].varName +
+			                    "\" attribute var has incorrect GL data type from the expected (0x" + hex +
+			                    stdAttribVars[i]->getGlDataType() + ")");
 		}
 	}
 
@@ -473,14 +478,11 @@ bool Material::initStdShaderVars()
 		// check if the shader has different GL data type from that it suppose to have
 		if(stdUniVars[i]->getGlDataType() != stdUniVarInfos[i].dataType)
 		{
-			MTL_ERROR("The \"" << stdUniVarInfos[i].varName <<
-			          "\" uniform var has incorrect GL data type from the expected (0x" << hex <<
-			          stdUniVars[i]->getGlDataType() << ")");
-			return false;
+			MTL_THROW_EXCEPTION("The \"" + stdUniVarInfos[i].varName +
+			                    "\" uniform var has incorrect GL data type from the expected (0x" + hex +
+			                    stdUniVars[i]->getGlDataType() + ")");
 		}
 	}
-
-	return true;
 }
 
 

+ 14 - 8
src/Resources/Material.h

@@ -19,6 +19,10 @@
 /// program for standard variables and keeps a pointer to the variable. The standard variables are like the GL build-in
 /// variables (that we cannot longer use on GL >3) with a few additions. The user defined variables are defined and
 /// values inside the .mtl file. The attribute variables cannot be user defined, the uniform on the other hand can.
+///
+/// File format:
+/// @code
+/// @endcode
 class Material: public Resource
 {
 	friend class Renderer; ///< For the setupMaterial
@@ -29,6 +33,12 @@ class Material: public Resource
 	friend class Mesh;
 	friend class MeshNode;
 
+	public:
+		Material();
+
+		/// @see Resource::load
+		void load(const char* filename);
+
 	private:
 		/// Standard attribute variables that are acceptable inside the @ref ShaderProg
 		enum StdAttribVars
@@ -115,17 +125,13 @@ class Material: public Resource
 		bool wireframe;
 		bool castsShadow; ///< Used in shadowmapping passes but not in Ez
 
-		/// The func sweeps all the variables of the shader program to find standard shader program variables. It updates the
-		/// stdAttribVars and stdUniVars arrays.
-		/// @return True on success
-		bool initStdShaderVars();
+		/// The func sweeps all the variables of the shader program to find standard shader program variables. It updates
+		/// the stdAttribVars and stdUniVars arrays.
+		/// @exception Exception
+		void initStdShaderVars();
 
 		bool hasHWSkinning() const {return stdAttribVars[SAV_VERT_WEIGHT_BONES_NUM] != NULL;}
 		bool hasAlphaTesting() const {return stdAttribVars[SAV_VERT_WEIGHT_BONES_NUM] != NULL;}
-
-	public:
-		Material();
-		bool load(const char* filename);
 };
 
 

+ 49 - 39
src/Resources/Mesh.cpp

@@ -4,28 +4,27 @@
 #include "BinaryStream.h"
 
 
-#define MESH_ERR(x) \
-	ERROR("File \"" << filename << "\": " << x)
+#define MESH_THROW_EXCEPTION(x) THROW_EXCEPTION("File \"" + filename + "\": " + x)
 
 
 //======================================================================================================================
 // load                                                                                                                =
 //======================================================================================================================
-bool Mesh::load(const char* filename)
+void Mesh::load(const char* filename)
 {
-	fstream file(filename, fstream::in | fstream::binary);
-
-	if(!file.is_open())
+	// Try
+	try
 	{
-		ERROR("Cannot open file \"" << filename << "\"");
-		return false;
-	}
+		// Open the file
+		fstream file(filename, fstream::in | fstream::binary);
+
+		if(!file.is_open())
+		{
+			THROW_EXCEPTION("Cannot open file \"" << filename << "\"");
+		}
 
-	BinaryStream bs(file.rdbuf());
+		BinaryStream bs(file.rdbuf());
 
-	// Try loading the file
-	try
-	{
 		// Magic word
 		char magic[8];
 		bs.read(magic, 8);
@@ -72,8 +71,7 @@ bool Mesh::load(const char* filename)
 				// a sanity check
 				if(tris[i].vertIds[j] >= vertCoords.size())
 				{
-					MESH_ERR("Incorrect vert index " << tris[i].vertIds[j] << " (" << i << ", " << j << ")");
-					return false;
+					THROW_EXCEPTION("Vert index out of bounds" + tris[i].vertIds[j] + " (" + i + ", " + j + ")");
 				}
 			}
 		}
@@ -104,15 +102,13 @@ bool Mesh::load(const char* filename)
 			// we treat as error if one vert doesnt have a bone
 			if(boneConnections < 1)
 			{
-				MESH_ERR("Vert \"" << i << "\" sould have have at least one bone");
-				return false;
+				THROW_EXCEPTION("Vert " + i + " sould have at least one bone");
 			}
 
 			// and here is another possible error
 			if(boneConnections > VertexWeight::MAX_BONES_PER_VERT)
 			{
-				MESH_ERR("Cannot have more than " << VertexWeight::MAX_BONES_PER_VERT << " bones per vertex");
-				return false;
+				THROW_EXCEPTION("Cannot have more than " + VertexWeight::MAX_BONES_PER_VERT + " bones per vertex");
 			}
 			vertWeights[i].bonesNum = boneConnections;
 
@@ -127,59 +123,63 @@ bool Mesh::load(const char* filename)
 				float weight = bs.readFloat();
 				vertWeights[i].weights[j] = weight;
 			}
-		}
+		} // end for all vert weights
+
+
+		doPostLoad();
 	}
 	catch(Exception& e)
 	{
-		MESH_ERR("Cannot read mesh: " << e.what());
-		return false;
+		MESH_THROW_EXCEPTION(e.what());
 	}
+}
 
+
+//======================================================================================================================
+// doPostLoad                                                                                                          =
+//======================================================================================================================
+void Mesh::doPostLoad()
+{
 	// Sanity checks
 	if(vertCoords.size()<1 || tris.size()<1)
 	{
-		ERROR("Vert coords and tris must be filled \"" << filename << "\"");
-		return false;
+		THROW_EXCEPTION("Vert coords and tris must be filled");
 	}
 	if(texCoords.size()!=0 && texCoords.size()!=vertCoords.size())
 	{
-		ERROR("Tex coords num must be zero or equal to vertex coords num \"" << filename << "\"");
-		return false;
+		THROW_EXCEPTION("Tex coords num must be zero or equal to vertex coords num");
 	}
 	if(vertWeights.size()!=0 && vertWeights.size()!=vertCoords.size())
 	{
-		ERROR("Vert weights num must be zero or equal to vertex coords num \"" << filename << "\"");
-		return false;
+		THROW_EXCEPTION("Vert weights num must be zero or equal to vertex coords num");
 	}
 
 	if(isRenderable())
 	{
 		createAllNormals();
 		if(texCoords.size() > 0)
+		{
 			createVertTangents();
+		}
 		createVertIndeces();
 		createVbos();
 		calcBSphere();
 
-		/*
-		 * Sanity checks continued
-		 */
+		// Sanity checks continued
 		if(material->stdAttribVars[Material::SAV_TEX_COORDS] != NULL && !vbos.texCoords.isCreated())
 		{
-			ERROR("The shader program (\"" << material->shaderProg->getRsrcName() <<
-						 "\") needs texture coord information that the mesh (\"" <<
-						 getRsrcName() << "\") doesn't have");
+			THROW_EXCEPTION("The shader program (\"" + material->shaderProg->getRsrcName() +
+						          "\") needs texture coord information that the mesh (\"" +
+						          getRsrcName() << "\") doesn't have");
 		}
 
 		if(material->hasHWSkinning() && !vbos.vertWeights.isCreated())
 		{
-			ERROR("The shader program (\"" << material->shaderProg->getRsrcName() <<
-						 "\") needs vertex weights that the mesh (\"" <<
-						 getRsrcName() << "\") doesn't have");
+			THROW_EXCEPTION("The shader program (\"" + material->shaderProg->getRsrcName() +
+						          "\") needs vertex weights that the mesh (\"" +
+						          getRsrcName() + "\") doesn't have");
 		}
 	}
-
-	return true;
 }
 
 
@@ -238,7 +238,9 @@ void Mesh::createVertNormals()
 	}
 
 	for(uint i=0; i<vertNormals.size(); i++)
+	{
 		vertNormals[i].normalize();
+	}
 }
 
 
@@ -322,11 +324,19 @@ void Mesh::createVbos()
 	vbos.vertCoords.create(GL_ARRAY_BUFFER, vertCoords.getSizeInBytes(), &vertCoords[0], GL_STATIC_DRAW);
 	vbos.vertNormals.create(GL_ARRAY_BUFFER, vertNormals.getSizeInBytes(), &vertNormals[0], GL_STATIC_DRAW);
 	if(vertTangents.size() > 1)
+	{
 		vbos.vertTangents.create(GL_ARRAY_BUFFER, vertTangents.getSizeInBytes(), &vertTangents[0], GL_STATIC_DRAW);
+	}
+
 	if(texCoords.size() > 1)
+	{
 		vbos.texCoords.create(GL_ARRAY_BUFFER, texCoords.getSizeInBytes(), &texCoords[0], GL_STATIC_DRAW);
+	}
+
 	if(vertWeights.size() > 1)
+	{
 		vbos.vertWeights.create(GL_ARRAY_BUFFER, vertWeights.getSizeInBytes(), &vertWeights[0], GL_STATIC_DRAW);
+	}
 }
 
 

+ 5 - 1
src/Resources/Mesh.h

@@ -80,7 +80,7 @@ class Mesh: public Resource
 
 		Mesh();
 		~Mesh() {}
-		bool load(const char* filename);
+		void load(const char* filename);
 
 		/// The mesh is renderable when the material is loaded
 		bool isRenderable() const;
@@ -93,6 +93,10 @@ class Mesh: public Resource
 		void createVertIndeces();
 		void createVbos();
 		void calcBSphere();
+
+		/// This func does some sanity checks and creates normals, tangents, VBOs etc
+		/// @exception Exception
+		void doPostLoad();
 };
 
 

+ 7 - 15
src/Resources/ParticleEmitterProps.cpp

@@ -66,7 +66,7 @@ bool ParticleEmitterPropsStruct::usingWorldGrav() const
 //======================================================================================================================
 // load                                                                                                                =
 //======================================================================================================================
-bool ParticleEmitterProps::load(const char* /*filename*/)
+void ParticleEmitterProps::load(const char* /*filename*/)
 {
 	// dummy load
 	particleLife = 7.0;
@@ -93,39 +93,31 @@ bool ParticleEmitterProps::load(const char* /*filename*/)
 	// sanity checks
 	if(particleLife <= 0.0)
 	{
-		ERROR(errMsg << "particleLife");
-		return false;
+		RSRC_THROW_EXCEPTION(errMsg + "particleLife");
 	}
 
 	if(particleLife - particleLifeMargin <= 0.0)
 	{
-		ERROR(errMsg << "particleLifeMargin");
-		return false;
+		RSRC_THROW_EXCEPTION(errMsg + "particleLifeMargin");
 	}
 
 	if(size <= 0.0)
 	{
-		ERROR(errMsg << "size");
-		return false;
+		RSRC_THROW_EXCEPTION(errMsg + "size");
 	}
 
 	if(maxNumOfParticles < 1)
 	{
-		ERROR(errMsg << "maxNumOfParticles");
-		return false;
+		RSRC_THROW_EXCEPTION(errMsg + "maxNumOfParticles");
 	}
 
 	if(emittionPeriod <= 0.0)
 	{
-		ERROR(errMsg << "emittionPeriod");
-		return false;
+		RSRC_THROW_EXCEPTION(errMsg + "emittionPeriod");
 	}
 
 	if(particlesPerEmittion < 1)
 	{
-		ERROR(errMsg << "particlesPerEmittion");
-		return false;
+		RSRC_THROW_EXCEPTION(errMsg + "particlesPerEmittion");
 	}
-
-	return true;
 }

+ 1 - 1
src/Resources/ParticleEmitterProps.h

@@ -56,7 +56,7 @@ class ParticleEmitterProps: public ParticleEmitterPropsStruct, public Resource
 		ParticleEmitterProps(): Resource(RT_PARTICLE_EMITTER_PROPS) {}
 		~ParticleEmitterProps() {}
 
-		bool load(const char* filename);
+		void load(const char* filename);
 };
 
 

+ 1 - 2
src/Resources/Script.cpp

@@ -10,8 +10,7 @@ bool Script::load(const char* filename)
 	source = Util::readFile(filename);
 	if(source.length() < 1)
 	{
-		ERROR("Cannot load script \"" << filename << "\"");
-		return false;
+		THROW_EXCEPTION("Cannot load script \"" << filename << "\"");
 	}
 	return true;
 }

+ 2 - 7
src/Resources/Script.h

@@ -9,18 +9,13 @@
 class Script: public Resource
 {
 	public:
-		Script();
+		Script(): Resource(RT_SCRIPT) {}
 		~Script() {}
-		bool load(const char* filename);
+		void load(const char* filename);
 
 	private:
 		string source;
 };
 
 
-inline Script::Script():
-	Resource(RT_SCRIPT)
-{}
-
-
 #endif