Browse Source

Exceptions

Panagiotis Christopoulos Charitos 15 years ago
parent
commit
cde431ee61

File diff suppressed because it is too large
+ 269 - 262
build/debug/Makefile


+ 1 - 1
build/debug/gen.cfg.py

@@ -9,6 +9,6 @@ executableName = "anki"
 
 compiler = "g++"
 
-compilerFlags = "-DDEBUG_ENABLED=1 -DPLATFORM_LINUX -DREVISION=\\\"`svnversion -c ../..`\\\" -c -pedantic-errors -pedantic -ansi -Wall -Wextra -W -Wno-long-long -pipe -g3 -pg -fsingle-precision-constant"
+compilerFlags = "-DDEBUG_ENABLED=1 -DPLATFORM_LINUX -DREVISION=\\\"`svnversion -c ../..`\\\" -c -pedantic-errors -pedantic -ansi -Wall -Wextra -W -Wno-long-long -Wfatal-errors -pipe -g3 -pg -fsingle-precision-constant"
 
 linkerFlags = "-rdynamic -pg -L../../extern/lib-x86-64-linux -Wl,-Bstatic -lBulletSoftBody -lBulletDynamics -lBulletCollision -lLinearMath -lGLEW -lGLU -Wl,-Bdynamic -lGL -ljpeg -lSDL -lpng -lpython2.6 -lboost_system -lboost_python -lboost_filesystem -lboost_thread"

+ 111 - 52
docs/doxyfile

@@ -1,4 +1,4 @@
-# Doxyfile 1.5.8
+# Doxyfile 1.6.3
 
 # This file describes the settings to be used by the documentation system
 # doxygen (www.doxygen.org) for a project
@@ -54,11 +54,11 @@ CREATE_SUBDIRS         = NO
 # information to generate all constant output in the proper language. 
 # The default language is English, other supported languages are: 
 # Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, 
-# Croatian, Czech, Danish, Dutch, Farsi, Finnish, French, German, Greek, 
-# Hungarian, Italian, Japanese, Japanese-en (Japanese with English messages), 
-# Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, Polish, 
-# Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, Slovene, 
-# Spanish, Swedish, and Ukrainian.
+# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, 
+# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English 
+# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, 
+# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, 
+# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese.
 
 OUTPUT_LANGUAGE        = English
 
@@ -224,7 +224,8 @@ OPTIMIZE_OUTPUT_VHDL   = NO
 # the parsers supported by doxygen: IDL, Java, Javascript, C#, C, C++, D, PHP, 
 # Objective-C, Python, Fortran, VHDL, C, C++. For instance to make doxygen treat 
 # .inc files as Fortran files (default is PHP), and .f files as C (default is Fortran), 
-# use: inc=Fortran f=C
+# use: inc=Fortran f=C. Note that for custom extensions you also need to set
+# FILE_PATTERNS otherwise the files are not read by doxygen.
 
 EXTENSION_MAPPING      = 
 
@@ -396,6 +397,12 @@ HIDE_SCOPE_NAMES       = NO
 
 SHOW_INCLUDE_FILES     = YES
 
+# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen 
+# will list include files with double quotes in the documentation 
+# rather than with sharp brackets.
+
+FORCE_LOCAL_INCLUDES   = NO
+
 # If the INLINE_INFO tag is set to YES (the default) then a tag [inline] 
 # is inserted in the documentation for inline members.
 
@@ -415,6 +422,16 @@ SORT_MEMBER_DOCS       = YES
 
 SORT_BRIEF_DOCS        = NO
 
+# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen
+# will sort the (brief and detailed) documentation of class members so that
+# constructors and destructors are listed first. If set to NO (the default)
+# the constructors will appear in the respective orders defined by
+# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS.
+# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO
+# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO.
+
+SORT_MEMBERS_CTORS_1ST = NO
+
 # If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the 
 # hierarchy of group names into alphabetical order. If set to NO (the default) 
 # the group names will appear in their defined order.
@@ -827,6 +844,12 @@ HTML_FOOTER            =
 
 HTML_STYLESHEET        = 
 
+# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML 
+# page will contain the date and time when the page was generated. Setting 
+# this to NO can help when comparing the output of multiple runs.
+
+HTML_TIMESTAMP         = YES
+
 # If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, 
 # files or namespaces will be aligned in HTML using tables. If set to 
 # NO a bullet list will be used.
@@ -960,6 +983,23 @@ QHP_SECT_FILTER_ATTRS  =
 
 QHG_LOCATION           = 
 
+# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files  
+# will be generated, which together with the HTML files, form an Eclipse help  
+# plugin. To install this plugin and make it available under the help contents 
+# menu in Eclipse, the contents of the directory containing the HTML and XML 
+# files needs to be copied into the plugins directory of eclipse. The name of 
+# the directory within the plugins directory should be the same as 
+# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before
+# the help appears.
+
+GENERATE_ECLIPSEHELP   = NO
+
+# A unique identifier for the eclipse help plugin. When installing the plugin 
+# the directory name containing the HTML and XML files should also have 
+# this name.
+
+ECLIPSE_DOC_ID         = org.doxygen.Project
+
 # The DISABLE_INDEX tag can be used to turn on/off the condensed index at 
 # top of each HTML page. The value NO (the default) enables the index and 
 # the value YES disables it.
@@ -973,20 +1013,18 @@ ENUM_VALUES_PER_LINE   = 4
 
 # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index 
 # structure should be generated to display hierarchical information. 
-# If the tag value is set to FRAME, a side panel will be generated 
+# If the tag value is set to YES, a side panel will be generated 
 # containing a tree-like index structure (just like the one that 
 # is generated for HTML Help). For this to work a browser that supports 
-# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, 
-# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are 
-# probably better off using the HTML help feature. Other possible values 
-# for this tag are: HIERARCHIES, which will generate the Groups, Directories, 
-# and Class Hierarchy pages using a tree view instead of an ordered list; 
-# ALL, which combines the behavior of FRAME and HIERARCHIES; and NONE, which 
-# disables this behavior completely. For backwards compatibility with previous 
-# releases of Doxygen, the values YES and NO are equivalent to FRAME and NONE 
-# respectively.
-
-GENERATE_TREEVIEW      = ALL
+# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). 
+# Windows users are probably better off using the HTML help feature.
+
+GENERATE_TREEVIEW      = YES
+
+# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, 
+# and Class Hierarchy pages using a tree view instead of an ordered list.
+
+USE_INLINE_TREES       = NO
 
 # If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be 
 # used to set the initial width (in pixels) of the frame in which the tree 
@@ -1002,6 +1040,26 @@ TREEVIEW_WIDTH         = 250
 
 FORMULA_FONTSIZE       = 10
 
+# When the SEARCHENGINE tag is enabled doxygen will generate a search box
+# for the HTML output. The underlying search engine uses javascript 
+# and DHTML and should work on any modern browser. Note that when using
+# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets
+# (GENERATE_DOCSET) there is already a search function so this one should 
+# typically be disabled. For large projects the javascript based search engine 
+# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution.
+
+SEARCHENGINE           = YES
+
+# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
+# implemented using a PHP enabled web server instead of at the web client
+# using Javascript. Doxygen will generate the search PHP script and index 
+# file to put on the web server. The advantage of the server
+# based approach is that it scales better to large projects and allows
+# full text search. The disadvances is that it is more difficult to setup 
+# and does not have live searching capabilities.
+
+SERVER_BASED_SEARCH    = NO
+
 #---------------------------------------------------------------------------
 # configuration options related to the LaTeX output
 #---------------------------------------------------------------------------
@@ -1018,7 +1076,10 @@ GENERATE_LATEX         = NO
 LATEX_OUTPUT           = doxygen-latex
 
 # The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be 
-# invoked. If left blank `latex' will be used as the default command name.
+# invoked. If left blank `latex' will be used as the default command name. 
+# Note that when enabling USE_PDFLATEX this option is only used for 
+# generating bitmaps for formulas in the HTML output, but not in the 
+# Makefile that is written to the output directory.
 
 LATEX_CMD_NAME         = latex
 
@@ -1078,6 +1139,13 @@ LATEX_BATCHMODE        = YES
 
 LATEX_HIDE_INDICES     = NO
 
+# If LATEX_SOURCE_CODE is set to YES then doxygen will include
+# source code with syntax highlighting in the LaTeX output.
+# Note that which sources are shown also depends on other settings
+# such as SOURCE_BROWSER.
+
+LATEX_SOURCE_CODE      = NO
+
 #---------------------------------------------------------------------------
 # configuration options related to the RTF output
 #---------------------------------------------------------------------------
@@ -1229,7 +1297,7 @@ PERLMOD_PRETTY         = YES
 PERLMOD_MAKEVAR_PREFIX = 
 
 #---------------------------------------------------------------------------
-# Configuration options related to the preprocessor   
+# Configuration options related to the preprocessor
 #---------------------------------------------------------------------------
 
 # If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will 
@@ -1260,26 +1328,26 @@ SEARCH_INCLUDES        = YES
 # contain include files that are not input files but should be processed by 
 # the preprocessor.
 
-INCLUDE_PATH           = ../src/Scripting/ \ 
-                         ../src/Math/ \ 
-                         ../src/Misc/ \ 
-                         ../src/ \ 
-                         ../src/Renderer/ \ 
-                         ../src/Scene/ \ 
-                         ../src/Ui/ \ 
-                         ../src/Resources/ \ 
-                         ../src/Util/ \ 
-                         ../src/Scene/Controllers/ \ 
-                         ../src/Physics/ \ 
-                         ../src/Renderer/BufferObjects/ \ 
-                         ../src/Resources/Helpers/ \ 
-                         ../src/Resources/Core/ \ 
-                         ../src/Core/ \ 
-                         ../src/Scripting/Math \ 
-                         ../src/Scripting/Util \ 
-                         ../src/Scripting/Core \ 
-                         ../src/Scripting/Scene \ 
-                         ../src/Scripting/Renderer \ 
+INCLUDE_PATH           = ../src/Scripting/ \
+                         ../src/Math/ \
+                         ../src/Misc/ \
+                         ../src/ \
+                         ../src/Renderer/ \
+                         ../src/Scene/ \
+                         ../src/Ui/ \
+                         ../src/Resources/ \
+                         ../src/Util/ \
+                         ../src/Scene/Controllers/ \
+                         ../src/Physics/ \
+                         ../src/Renderer/BufferObjects/ \
+                         ../src/Resources/Helpers/ \
+                         ../src/Resources/Core/ \
+                         ../src/Core/ \
+                         ../src/Scripting/Math \
+                         ../src/Scripting/Util \
+                         ../src/Scripting/Core \
+                         ../src/Scripting/Scene \
+                         ../src/Scripting/Renderer \
                          ../src/Input
 
 # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard 
@@ -1317,7 +1385,7 @@ EXPAND_AS_DEFINED      =
 SKIP_FUNCTION_MACROS   = YES
 
 #---------------------------------------------------------------------------
-# Configuration::additions related to external references   
+# Configuration::additions related to external references
 #---------------------------------------------------------------------------
 
 # The TAGFILES option can be used to specify one or more tagfiles. 
@@ -1360,7 +1428,7 @@ EXTERNAL_GROUPS        = YES
 PERL_PATH              = /usr/bin/perl
 
 #---------------------------------------------------------------------------
-# Configuration options related to the dot tool   
+# Configuration options related to the dot tool
 #---------------------------------------------------------------------------
 
 # If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will 
@@ -1552,12 +1620,3 @@ GENERATE_LEGEND        = YES
 # the various graphs.
 
 DOT_CLEANUP            = YES
-
-#---------------------------------------------------------------------------
-# Options related to the search engine
-#---------------------------------------------------------------------------
-
-# The SEARCHENGINE tag specifies whether or not a search engine should be 
-# used. If set to NO the values of all tags below this one will be ignored.
-
-SEARCHENGINE           = YES

+ 9 - 17
src/Misc/Parser.h

@@ -2,7 +2,6 @@
 #define PARSER_H
 
 #include <boost/lexical_cast.hpp>
-#include "Common.h"
 #include "Exception.h"
 #include "Scanner.h"
 
@@ -14,22 +13,15 @@ namespace Parser {
 //======================================================================================================================
 // Parser macros                                                                                                       =
 //======================================================================================================================
-#define PARSE_ERR(x) ERROR("Parse Error (" << scanner.getScriptName() << ':' << scanner.getLineNumber() << "): " << x)
-#define PARSE_WARN(x) WARNING("Parse Warning (" << scanner.getScriptName() << ':' << scanner.getLineNumber() << "): " << x)
+#define PARSER_EXCEPTION(x) \
+	EXCEPTION("Parser exception (" + scanner.getScriptName() + ':' + \
+	boost::lexical_cast<std::string>(scanner.getLineNumber()) + "): " + x)
 
-#define PARSER_THROW_EXCEPTION(x) \
-	THROW_EXCEPTION("Parser failed (" + scanner.getScriptName() + ':' + \
-	                lexical_cast<string>(scanner.getLineNumber()) + "): " + x)
+#define PARSER_EXCEPTION_EXPECTED(x) \
+	PARSER_EXCEPTION("Expected " + x + " and not " + scanner.getCrntToken().getInfoStr())
 
-#define PARSER_THROW_EXCEPTION_EXPECTED(x) \
-	PARSER_THROW_EXCEPTION("Expected " + x + " and not " + scanner.getCrntToken().getInfoStr())
-
-#define PARSER_THROW_EXCEPTION_UNEXPECTED(x) \
-	PARSER_THROW_EXCEPTION("Unexpected token " + scanner.getCrntToken().getInfoStr())
-
-// common parser errors
-#define PARSE_ERR_EXPECTED(x) PARSE_ERR("Expected " << x << " and not " << scanner.getCrntToken().getInfoStr());
-#define PARSE_ERR_UNEXPECTED() PARSE_ERR("Unexpected token " << scanner.getCrntToken().getInfoStr());
+#define PARSER_EXCEPTION_UNEXPECTED() \
+	PARSER_EXCEPTION("Unexpected token " + scanner.getCrntToken().getInfoStr())
 
 
 //======================================================================================================================
@@ -48,7 +40,7 @@ namespace Parser {
  * @param arr The array that the func returns the numbers
  * @return True if the parsing was successful
 */
-template <typename Type>
+/*template <typename Type>
 bool parseArrOfNumbers(Scanner& scanner, bool bracket, bool signs, uint size, Type* arr)
 {
 	const Scanner::Token* token;
@@ -116,7 +108,7 @@ bool parseArrOfNumbers(Scanner& scanner, bool bracket, bool signs, uint size, Ty
 	}
 
 	return true;
-}
+}*/
 
 
 /// Parse a single number

+ 6 - 6
src/Misc/Parser.inl.h

@@ -31,14 +31,14 @@ void parseNumber(Scanner& scanner, bool sign, Type& out)
 			}
 			else if(token->getCode() != Scanner::TC_NUMBER)
 			{
-				PARSER_THROW_EXCEPTION_EXPECTED("number or sign");
+				throw PARSER_EXCEPTION_EXPECTED("number or sign");
 			}
 		}
 
 		// check the number
 		if(token->getCode() != Scanner::TC_NUMBER)
 		{
-			PARSER_THROW_EXCEPTION_EXPECTED("number");
+			throw PARSER_EXCEPTION_EXPECTED("number");
 		}
 
 		if(token->getDataType() == Scanner::DT_FLOAT)
@@ -54,7 +54,7 @@ void parseNumber(Scanner& scanner, bool sign, Type& out)
 	}
 	catch(std::exception& e)
 	{
-		THROW_EXCEPTION(e.what());
+		throw EXCEPTION(e.what());
 	}
 }
 
@@ -73,7 +73,7 @@ void parseMathVector(Scanner& scanner, Type& out)
 		// {
 		if(token->getCode() != Scanner::TC_LBRACKET)
 		{
-			PARSER_THROW_EXCEPTION_EXPECTED("{");
+			throw PARSER_EXCEPTION_EXPECTED("{");
 		}
 
 		// numbers
@@ -88,12 +88,12 @@ void parseMathVector(Scanner& scanner, Type& out)
 		token = &scanner.getNextToken();
 		if(token->getCode() != Scanner::TC_RBRACKET)
 		{
-			PARSER_THROW_EXCEPTION_EXPECTED("}");
+			throw PARSER_EXCEPTION_EXPECTED("}");
 		}
 	}
 	catch(std::exception& e)
 	{
-		THROW_EXCEPTION(e.what());
+		throw EXCEPTION(e.what());
 	}
 }
 

+ 20 - 20
src/Resources/Helpers/Image.cpp

@@ -1,6 +1,6 @@
 #include <png.h>
 #include <boost/filesystem.hpp>
-#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string.hpp> // for to_lower
 #include <fstream>
 #include "Image.h"
 #include "Exception.h"
@@ -24,7 +24,7 @@ void Image::loadUncompressedTga(fstream& fs, uint& bpp)
 	fs.read((char*)&header6[0], sizeof(header6));
 	if(fs.gcount() != sizeof(header6))
 	{
-		THROW_EXCEPTION("Cannot read info header");
+		throw EXCEPTION("Cannot read info header");
 	}
 
 	width  = header6[1] * 256 + header6[0];
@@ -33,7 +33,7 @@ void Image::loadUncompressedTga(fstream& fs, uint& bpp)
 
 	if((width <= 0) || (height <= 0) || ((bpp != 24) && (bpp !=32)))
 	{
-		THROW_EXCEPTION("Invalid image information");
+		throw EXCEPTION("Invalid image information");
 	}
 
 	// read the data
@@ -44,7 +44,7 @@ void Image::loadUncompressedTga(fstream& fs, uint& bpp)
 	fs.read(reinterpret_cast<char*>(&data[0]), imageSize);
 	if(fs.gcount() != imageSize)
 	{
-		THROW_EXCEPTION("Cannot read image data");
+		throw EXCEPTION("Cannot read image data");
 	}
 
 	// swap red with blue
@@ -66,7 +66,7 @@ void Image::loadCompressedTga(fstream& fs, uint& bpp)
 	fs.read((char*)&header6[0], sizeof(header6));
 	if(fs.gcount() != sizeof(header6))
 	{
-		THROW_EXCEPTION("Cannot read info header");
+		throw EXCEPTION("Cannot read info header");
 	}
 
 	width  = header6[1] * 256 + header6[0];
@@ -75,7 +75,7 @@ void Image::loadCompressedTga(fstream& fs, uint& bpp)
 
 	if((width <= 0) || (height <= 0) || ((bpp != 24) && (bpp !=32)))
 	{
-		THROW_EXCEPTION("Invalid texture information");
+		throw EXCEPTION("Invalid texture information");
 	}
 
 
@@ -95,7 +95,7 @@ void Image::loadCompressedTga(fstream& fs, uint& bpp)
 		fs.read((char*)&chunkheader, sizeof(unsigned char));
 		if(fs.gcount() != sizeof(unsigned char))
 		{
-			THROW_EXCEPTION("Cannot read RLE header");
+			throw EXCEPTION("Cannot read RLE header");
 		}
 
 		if(chunkheader < 128)
@@ -106,7 +106,7 @@ void Image::loadCompressedTga(fstream& fs, uint& bpp)
 				fs.read((char*)&colorbuffer[0], bytesPerPxl);
 				if(fs.gcount() != bytesPerPxl)
 				{
-					THROW_EXCEPTION("Cannot read image data");
+					throw EXCEPTION("Cannot read image data");
 				}
 
 				data[currentbyte		] = colorbuffer[2];
@@ -123,7 +123,7 @@ void Image::loadCompressedTga(fstream& fs, uint& bpp)
 
 				if(currentpixel > pixelcount)
 				{
-					THROW_EXCEPTION("Too many pixels read");
+					throw EXCEPTION("Too many pixels read");
 				}
 			}
 		}
@@ -133,7 +133,7 @@ void Image::loadCompressedTga(fstream& fs, uint& bpp)
 			fs.read((char*)&colorbuffer[0], bytesPerPxl);
 			if(fs.gcount() != bytesPerPxl)
 			{
-				THROW_EXCEPTION("Cannot read from file");
+				throw EXCEPTION("Cannot read from file");
 			}
 
 			for(int counter = 0; counter < chunkheader; counter++)
@@ -152,7 +152,7 @@ void Image::loadCompressedTga(fstream& fs, uint& bpp)
 
 				if(currentpixel > pixelcount)
 				{
-					THROW_EXCEPTION("Too many pixels read");
+					throw EXCEPTION("Too many pixels read");
 				}
 			}
 		}
@@ -172,14 +172,14 @@ void Image::loadTga(const char* filename)
 
 	if(!fs.good())
 	{
-		THROW_EXCEPTION("Cannot open file");
+		throw EXCEPTION("Cannot open file");
 	}
 
 	fs.read(&myTgaHeader[0], sizeof(myTgaHeader));
 	if(fs.gcount() != sizeof(myTgaHeader))
 	{
 		fs.close();
-		THROW_EXCEPTION("Cannot read file header");
+		throw EXCEPTION("Cannot read file header");
 	}
 
 	if(memcmp(tgaHeaderUncompressed, &myTgaHeader[0], sizeof(myTgaHeader)) == 0)
@@ -192,7 +192,7 @@ void Image::loadTga(const char* filename)
 	}
 	else
 	{
-		THROW_EXCEPTION("Invalid image header");
+		throw EXCEPTION("Invalid image header");
 	}
 
 	if(bpp == 32)
@@ -205,7 +205,7 @@ void Image::loadTga(const char* filename)
 	}
 	else
 	{
-		THROW_EXCEPTION("Invalid bps");
+		throw EXCEPTION("Invalid bps");
 	}
 
 	fs.close();
@@ -265,7 +265,7 @@ bool Image::loadPng(const char* filename, string& err) throw()
 	pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
 	if(!pngPtr)
 	{
-		THROW_EXCEPTION("png_create_read_struct failed");
+		throw EXCEPTION("png_create_read_struct failed");
 		goto cleanup;
 	}
 
@@ -327,7 +327,7 @@ bool Image::loadPng(const char* filename, string& err) throw()
 				// do nothing
 				break;
 			default:
-				THROW_EXCEPTION("Forgot to handle a color type");
+				throw EXCEPTION("Forgot to handle a color type");
 				break;
 		}
 
@@ -439,17 +439,17 @@ void Image::load(const char* filename)
 			string err;
 			if(!loadPng(filename, err))
 			{
-				THROW_EXCEPTION(err);
+				throw EXCEPTION(err);
 			}
 		}
 		else
 		{
-			THROW_EXCEPTION("Unsupported extension");
+			throw EXCEPTION("Unsupported extension");
 		}
 	}
 	catch(std::exception& e)
 	{
-		THROW_EXCEPTION("File \"" + filename + "\": " + e.what());
+		throw EXCEPTION("File \"" + filename + "\": " + e.what());
 	}
 }
 

+ 2 - 1
src/Resources/Helpers/Image.h

@@ -6,7 +6,8 @@
 #include "StdTypes.h"
 
 
-/// Image class. Used in Texture::load. Supported types: TGA and PNG
+/// Image class.
+/// Used in Texture::load. Supported types: TGA and PNG
 class Image
 {
 	public:

+ 299 - 317
src/Resources/Helpers/ShaderPrePreprocessor.cpp

@@ -1,10 +1,16 @@
 #include <iomanip>
 #include <cstring>
+#include <iostream>
 #include <boost/lexical_cast.hpp>
 #include "ShaderPrePreprocessor.h"
-#include "Scanner.h"
 #include "Parser.h"
 #include "Util.h"
+#include "Exception.h"
+
+
+using namespace std;
+using namespace boost;
+
 
 const char* MULTIPLE_DEF_MSG = " already defined in the same place. Check for circular or multiple includance";
 
@@ -16,7 +22,7 @@ void ShaderPrePreprocessor::printSourceLines() const
 {
 	for(uint i=0; i<sourceLines.size(); ++i)
 	{
-		PRINT(setw(3) << i+1 << ": " << sourceLines[i]);
+		cout << setw(3) << i+1 << ": " << sourceLines[i] << endl;
 	}
 }
 
@@ -26,10 +32,11 @@ void ShaderPrePreprocessor::printSourceLines() const
 //======================================================================================================================
 void ShaderPrePreprocessor::printShaderVars() const
 {
-	PRINT("TYPE" << setw(20) << "NAME" << setw(4) << "LOC");
+	cout << "TYPE" << setw(20) << "NAME" << setw(4) << "LOC" << endl;
 	for(uint i=0; i<output.attributes.size(); ++i)
 	{
-		PRINT(setw(4) << "A" << setw(20) << output.attributes[i].name << setw(4) << output.attributes[i].customLoc);
+		cout << setw(4) << "A" << setw(20) << output.attributes[i].name << setw(4) << output.attributes[i].customLoc <<
+		     endl;
 	}
 }
 
@@ -52,411 +59,386 @@ Vec<ShaderPrePreprocessor::ShaderVarPragma>::iterator ShaderPrePreprocessor::fin
 //======================================================================================================================
 // parseFileForPragmas                                                                                                 =
 //======================================================================================================================
-bool ShaderPrePreprocessor::parseFileForPragmas(const string& filename, int depth)
+void ShaderPrePreprocessor::parseFileForPragmas(const string& filename, int depth)
 {
 	// first check the depth
 	if(depth > 99)
 	{
-		ERROR("File \"" << filename << "\": The include depth is too high. Probably circular includance");
-		return false;
+		throw EXCEPTION("File \"" + filename + "\": The include depth is too high. Probably circular includance");
 	}
 
 	// load file in lines
 	Vec<string> lines = Util::getFileLines(filename.c_str());
 	if(lines.size() < 1)
 	{
-		ERROR("File \"" << filename << "\": Cannot open or empty");
-		return false;
+		throw EXCEPTION("File \"" + filename + "\": Cannot open or empty");
 	}
 
-	// scanner
-	try
+	Scanner scanner(filename.c_str(), false);
+	const Scanner::Token* token;
+
+	while(true)
 	{
-		Scanner scanner(filename.c_str(), false);
-		const Scanner::Token* token;
+		token = &scanner.getNextToken();
 
-		while(true)
+		if(token->getCode() == Scanner::TC_SHARP)
 		{
 			token = &scanner.getNextToken();
-
-			if(token->getCode() == Scanner::TC_SHARP)
+			if(token->getCode() == Scanner::TC_IDENTIFIER && strcmp(token->getValue().getString(), "pragma") == 0)
 			{
 				token = &scanner.getNextToken();
-				if(token->getCode() == Scanner::TC_IDENTIFIER && strcmp(token->getValue().getString(), "pragma") == 0)
+				if(token->getCode() == Scanner::TC_IDENTIFIER && strcmp(token->getValue().getString(), "anki") == 0)
 				{
 					token = &scanner.getNextToken();
-					if(token->getCode() == Scanner::TC_IDENTIFIER && strcmp(token->getValue().getString(), "anki") == 0)
+					//
+					// vertShaderBegins
+					//
+					if(token->getCode() == Scanner::TC_IDENTIFIER &&
+						 strcmp(token->getValue().getString(), "vertShaderBegins") == 0)
 					{
-						token = &scanner.getNextToken();
-						//
-						// vertShaderBegins
-						//
-						if(token->getCode() == Scanner::TC_IDENTIFIER &&
-							 strcmp(token->getValue().getString(), "vertShaderBegins") == 0)
+						// play
+
+						// its defined in same place so there is probable circular includance
+						if(vertShaderBegins.definedInLine==scanner.getLineNumber() && vertShaderBegins.definedInFile==filename)
 						{
-							// play
+							throw PARSER_EXCEPTION("vertShaderBegins" + MULTIPLE_DEF_MSG);
+						}
 
-							// its defined in same place so there is probable circular includance
-							if(vertShaderBegins.definedInLine==scanner.getLineNumber() && vertShaderBegins.definedInFile==filename)
-							{
-								PARSE_ERR("vertShaderBegins" << MULTIPLE_DEF_MSG);
-								return false;
-							}
+						// already defined elsewhere => error
+						if(vertShaderBegins.definedInLine != -1)
+						{
+							throw PARSER_EXCEPTION("vertShaderBegins already defined at " + vertShaderBegins.definedInFile + ":" +
+																		 lexical_cast<string>(vertShaderBegins.definedInLine));
+						}
 
-							// already defined elsewhere => error
-							if(vertShaderBegins.definedInLine != -1)
-							{
-								PARSE_ERR("vertShaderBegins already defined at " << vertShaderBegins.definedInFile << ":" <<
-													 vertShaderBegins.definedInLine);
-								return false;
-							}
+						// vert shader should be before frag
+						if(fragShaderBegins.definedInLine != -1)
+						{
+							throw PARSER_EXCEPTION("vertShaderBegins must precede fragShaderBegins defined at " +
+																		 fragShaderBegins.definedInFile + ":" +
+																		 lexical_cast<string>(fragShaderBegins.definedInLine));
+						}
 
-							// vert shader should be before frag
-							if(fragShaderBegins.definedInLine != -1)
-							{
-								PARSE_ERR("vertShaderBegins must precede fragShaderBegins defined at " <<
-													fragShaderBegins.definedInFile << ":" << fragShaderBegins.definedInLine);
-								return false;
-							}
+						// vert shader should be before geom
+						if(geomShaderBegins.definedInLine != -1)
+						{
+							throw PARSER_EXCEPTION("vertShaderBegins must precede geomShaderBegins defined at " +
+																		 geomShaderBegins.definedInFile + ":" +
+																		 lexical_cast<string>(geomShaderBegins.definedInLine));
+						}
 
-							// vert shader should be before geom
-							if(geomShaderBegins.definedInLine != -1)
-							{
-								PARSE_ERR("vertShaderBegins must precede geomShaderBegins defined at " <<
-													geomShaderBegins.definedInFile << ":" << geomShaderBegins.definedInLine);
-								return false;
-							}
+						vertShaderBegins.definedInFile = filename;
+						vertShaderBegins.definedInLine = scanner.getLineNumber();
+						vertShaderBegins.globalLine = sourceLines.size() + 1;
+						sourceLines.push_back("#line " + lexical_cast<string>(scanner.getLineNumber()) + ' ' +
+																	lexical_cast<string>(depth) + " // " + lines[scanner.getLineNumber()-1]);
+						// stop play
+					}
+					//
+					// geomShaderBegins
+					//
+					else if(token->getCode() == Scanner::TC_IDENTIFIER &&
+									strcmp(token->getValue().getString(), "geomShaderBegins") == 0)
+					{
+						// play
 
-							vertShaderBegins.definedInFile = filename;
-							vertShaderBegins.definedInLine = scanner.getLineNumber();
-							vertShaderBegins.globalLine = sourceLines.size() + 1;
-							sourceLines.push_back("#line " + lexical_cast<string>(scanner.getLineNumber()) + ' ' +
-																		lexical_cast<string>(depth) + " // " + lines[scanner.getLineNumber()-1]);
-							// stop play
-						}
-						//
-						// geomShaderBegins
-						//
-						else if(token->getCode() == Scanner::TC_IDENTIFIER &&
-										strcmp(token->getValue().getString(), "geomShaderBegins") == 0)
+						// its defined in same place so there is probable circular includance
+						if(geomShaderBegins.definedInLine==scanner.getLineNumber() && geomShaderBegins.definedInFile==filename)
 						{
-							// play
+							throw PARSER_EXCEPTION("geomShaderBegins" + MULTIPLE_DEF_MSG);
+						}
 
-							// its defined in same place so there is probable circular includance
-							if(geomShaderBegins.definedInLine==scanner.getLineNumber() && geomShaderBegins.definedInFile==filename)
-							{
-								PARSE_ERR("geomShaderBegins" << MULTIPLE_DEF_MSG);
-								return false;
-							}
+						// already defined elsewhere => error
+						if(geomShaderBegins.definedInLine != -1)
+						{
+							throw PARSER_EXCEPTION("geomShaderBegins already defined at " + geomShaderBegins.definedInFile + ":" +
+																		 lexical_cast<string>(geomShaderBegins.definedInLine));
+						}
 
-							// already defined elsewhere => error
-							if(geomShaderBegins.definedInLine != -1)
-							{
-								PARSE_ERR("geomShaderBegins already defined at " << geomShaderBegins.definedInFile << ":" <<
-													 geomShaderBegins.definedInLine);
-								return false;
-							}
+						// vert shader entry point not defined => error
+						if(vertShaderBegins.definedInLine == -1)
+						{
+							throw PARSER_EXCEPTION("geomShaderBegins must follow vertShaderBegins");
+						}
 
-							// vert shader entry point not defined => error
-							if(vertShaderBegins.definedInLine == -1)
-							{
-								PARSE_ERR("geomShaderBegins must follow vertShaderBegins");
-								return false;
-							}
+						// frag shader entry point defined => error
+						if(fragShaderBegins.definedInLine != -1)
+						{
+							throw PARSER_EXCEPTION("geomShaderBegins must precede fragShaderBegins defined at " +
+																		 fragShaderBegins.definedInFile + ":" +
+																		 lexical_cast<string>(fragShaderBegins.definedInLine));
+						}
 
-							// frag shader entry point defined => error
-							if(fragShaderBegins.definedInLine != -1)
-							{
-								PARSE_ERR("geomShaderBegins must precede fragShaderBegins defined at " <<
-													fragShaderBegins.definedInFile << ":" << fragShaderBegins.definedInLine);
-								return false;
-							}
+						geomShaderBegins.definedInFile = filename;
+						geomShaderBegins.definedInLine = scanner.getLineNumber();
+						geomShaderBegins.globalLine = sourceLines.size() + 1;
+						sourceLines.push_back("#line " + lexical_cast<string>(scanner.getLineNumber()) + ' ' +
+																	lexical_cast<string>(depth) + " // " + lines[scanner.getLineNumber()-1]);
+						// stop play
+					}
+					//
+					// fragShaderBegins
+					//
+					else if(token->getCode() == Scanner::TC_IDENTIFIER &&
+									strcmp(token->getValue().getString(), "fragShaderBegins") == 0)
+					{
+						// play
 
-							geomShaderBegins.definedInFile = filename;
-							geomShaderBegins.definedInLine = scanner.getLineNumber();
-							geomShaderBegins.globalLine = sourceLines.size() + 1;
-							sourceLines.push_back("#line " + lexical_cast<string>(scanner.getLineNumber()) + ' ' +
-																		lexical_cast<string>(depth) + " // " + lines[scanner.getLineNumber()-1]);
-							// stop play
-						}
-						//
-						// fragShaderBegins
-						//
-						else if(token->getCode() == Scanner::TC_IDENTIFIER &&
-										strcmp(token->getValue().getString(), "fragShaderBegins") == 0)
+						// its defined in same place so there is probable circular includance
+						if(fragShaderBegins.definedInLine==scanner.getLineNumber() && fragShaderBegins.definedInFile==filename)
 						{
-							// play
-
-							// its defined in same place so there is probable circular includance
-							if(fragShaderBegins.definedInLine==scanner.getLineNumber() && fragShaderBegins.definedInFile==filename)
-							{
-								PARSE_ERR("fragShaderBegins" << MULTIPLE_DEF_MSG);
-								return false;
-							}
+							throw PARSER_EXCEPTION("fragShaderBegins" + MULTIPLE_DEF_MSG);
+						}
 
-							if(fragShaderBegins.definedInLine != -1) // if already defined elsewhere throw error
-							{
-								PARSE_ERR("fragShaderBegins already defined at " << fragShaderBegins.definedInFile << ":" <<
-													 fragShaderBegins.definedInLine);
-								return false;
-							}
+						if(fragShaderBegins.definedInLine != -1) // if already defined elsewhere throw error
+						{
+							throw PARSER_EXCEPTION("fragShaderBegins already defined at " + fragShaderBegins.definedInFile + ":" +
+																		 lexical_cast<string>(fragShaderBegins.definedInLine));
+						}
 
-							// vert shader entry point not defined
-							if(vertShaderBegins.definedInLine == -1)
-							{
-								PARSE_ERR("fragShaderBegins must follow vertShaderBegins");
-								return false;
-							}
+						// vert shader entry point not defined
+						if(vertShaderBegins.definedInLine == -1)
+						{
+							throw PARSER_EXCEPTION("fragShaderBegins must follow vertShaderBegins");
+						}
 
-							fragShaderBegins.definedInFile = filename;
-							fragShaderBegins.definedInLine = scanner.getLineNumber();
-							fragShaderBegins.globalLine = sourceLines.size() + 1;
+						fragShaderBegins.definedInFile = filename;
+						fragShaderBegins.definedInLine = scanner.getLineNumber();
+						fragShaderBegins.globalLine = sourceLines.size() + 1;
+						sourceLines.push_back("#line " + lexical_cast<string>(scanner.getLineNumber()) + ' ' +
+																	lexical_cast<string>(depth) + " // " + lines[scanner.getLineNumber()-1]);
+						// stop play
+					}
+					//
+					// include
+					//
+					else if(token->getCode() == Scanner::TC_IDENTIFIER && strcmp(token->getValue().getString(), "include") == 0)
+					{
+						token = &scanner.getNextToken();
+						if(token->getCode() == Scanner::TC_STRING)
+						{
+							// play
+							//int line = sourceLines.size();
+							sourceLines.push_back("#line 0 " + lexical_cast<string>(depth+1) + " // " +
+																		lines[scanner.getLineNumber()-1]);
+							parseFileForPragmas(token->getValue().getString(), depth+1);
 							sourceLines.push_back("#line " + lexical_cast<string>(scanner.getLineNumber()) + ' ' +
-																		lexical_cast<string>(depth) + " // " + lines[scanner.getLineNumber()-1]);
+																		lexical_cast<string>(depth) +  " // end of " + lines[scanner.getLineNumber()-1]);
 							// stop play
 						}
-						//
-						// include
-						//
-						else if(token->getCode() == Scanner::TC_IDENTIFIER && strcmp(token->getValue().getString(), "include") == 0)
+						else
 						{
-							token = &scanner.getNextToken();
-							if(token->getCode() == Scanner::TC_STRING)
-							{
-								// play
-								//int line = sourceLines.size();
-								sourceLines.push_back("#line 0 " + lexical_cast<string>(depth+1) + " // " +
-																			lines[scanner.getLineNumber()-1]);
-								if(!parseFileForPragmas(token->getValue().getString(), depth+1))
-									return false;
-								sourceLines.push_back("#line " + lexical_cast<string>(scanner.getLineNumber()) + ' ' +
-																			lexical_cast<string>(depth) +  " // end of " + lines[scanner.getLineNumber()-1]);
-								// stop play
-							}
-							else
-							{
-								PARSE_ERR_EXPECTED("string");
-								return false;
-							}
+							throw PARSER_EXCEPTION_EXPECTED("string");
 						}
-						//
-						// transformFeedbackVarying
-						//
-						else if(token->getCode() == Scanner::TC_IDENTIFIER &&
-										strcmp(token->getValue().getString(), "transformFeedbackVarying") == 0)
+					}
+					//
+					// transformFeedbackVarying
+					//
+					else if(token->getCode() == Scanner::TC_IDENTIFIER &&
+									strcmp(token->getValue().getString(), "transformFeedbackVarying") == 0)
+					{
+						token = &scanner.getNextToken();
+						if(token->getCode() == Scanner::TC_IDENTIFIER)
 						{
-							token = &scanner.getNextToken();
-							if(token->getCode() == Scanner::TC_IDENTIFIER)
+							string varName = token->getValue().getString();
+							// check if already defined and for circular includance
+							Vec<TrffbVaryingPragma>::const_iterator var = findNamed(output.trffbVaryings, varName);
+							if(var != output.trffbVaryings.end())
 							{
-								string varName = token->getValue().getString();
-								// check if already defined and for circular includance
-								Vec<TrffbVaryingPragma>::const_iterator var = findNamed(output.trffbVaryings, varName);
-								if(var != output.trffbVaryings.end())
+								if(var->definedInLine==scanner.getLineNumber() && var->definedInFile==filename)
 								{
-									if(var->definedInLine==scanner.getLineNumber() && var->definedInFile==filename)
-									{
-										PARSE_ERR("\"" << varName << "\"" << MULTIPLE_DEF_MSG);
-									}
-									else
-									{
-										PARSE_ERR("Varying \"" << varName << "\" already defined at " << var->definedInFile << ":" <<
-															var->definedInLine);
-									}
-									return false;
+									throw PARSER_EXCEPTION("\"" + varName + "\"" + MULTIPLE_DEF_MSG);
+								}
+								else
+								{
+									throw PARSER_EXCEPTION("Varying \"" + varName + "\" already defined at " + var->definedInFile +
+																				 ":" + lexical_cast<string>(var->definedInLine));
 								}
-
-								// all ok, push it back
-								output.trffbVaryings.push_back(TrffbVaryingPragma(filename, scanner.getLineNumber(), varName));
-								sourceLines.push_back(lines[scanner.getLineNumber()-1]);
-							}
-							else
-							{
-								PARSE_ERR_EXPECTED("identifier");
-								return false;
 							}
+
+							// all ok, push it back
+							output.trffbVaryings.push_back(TrffbVaryingPragma(filename, scanner.getLineNumber(), varName));
+							sourceLines.push_back(lines[scanner.getLineNumber() - 1]);
 						}
-						//
-						// attribute
-						//
-						else if(token->getCode() == Scanner::TC_IDENTIFIER && strcmp(token->getValue().getString(), "attribute") == 0)
+						else
+						{
+							throw PARSER_EXCEPTION_EXPECTED("identifier");
+						}
+					}
+					//
+					// attribute
+					//
+					else if(token->getCode() == Scanner::TC_IDENTIFIER && strcmp(token->getValue().getString(), "attribute") == 0)
+					{
+						token = &scanner.getNextToken();
+						if(token->getCode() == Scanner::TC_IDENTIFIER)
 						{
+							string varName = token->getValue().getString();
 							token = &scanner.getNextToken();
-							if(token->getCode() == Scanner::TC_IDENTIFIER)
+							if(token->getCode() == Scanner::TC_NUMBER && token->getDataType() == Scanner::DT_INT)
 							{
-								string varName = token->getValue().getString();
-								token = &scanner.getNextToken();
-								if(token->getCode() == Scanner::TC_NUMBER && token->getDataType() == Scanner::DT_INT)
-								{
-									uint loc = token->getValue().getInt();
+								uint loc = token->getValue().getInt();
 
-									// check if already defined and for circular includance
-									Vec<ShaderVarPragma>::const_iterator attrib = findNamed(output.attributes, varName);
-									if(attrib != output.attributes.end())
+								// check if already defined and for circular includance
+								Vec<ShaderVarPragma>::const_iterator attrib = findNamed(output.attributes, varName);
+								if(attrib != output.attributes.end())
+								{
+									if(attrib->definedInLine==scanner.getLineNumber() && attrib->definedInFile==filename)
 									{
-										if(attrib->definedInLine==scanner.getLineNumber() && attrib->definedInFile==filename)
-										{
-											PARSE_ERR("\"" << varName << "\"" << MULTIPLE_DEF_MSG);
-										}
-										else
-										{
-											PARSE_ERR("Attribute \"" << varName << "\" already defined at " << attrib->definedInFile << ":" <<
-																attrib->definedInLine);
-										}
-										return false;
+										throw PARSER_EXCEPTION("\"" + varName + "\"" + MULTIPLE_DEF_MSG);
 									}
-									// search if another var has the same loc
-									for(attrib = output.attributes.begin(); attrib!=output.attributes.end(); ++attrib)
+									else
 									{
-										if(attrib->customLoc == loc)
-										{
-											PARSE_ERR("The attributes \"" << attrib->name << "\" (" << attrib->definedInFile << ":" <<
-																attrib->definedInLine << ") and \"" << varName << "\" share the same location");
-											return false;
-										}
+										throw PARSER_EXCEPTION("Attribute \"" + varName + "\" already defined at " +
+																					 attrib->definedInFile + ":" + lexical_cast<string>(attrib->definedInLine));
 									}
-
-									// all ok, push it back
-									output.attributes.push_back(ShaderVarPragma(filename, scanner.getLineNumber(), varName, loc));
-									sourceLines.push_back(lines[scanner.getLineNumber()-1]);
 								}
-								else
+								// search if another var has the same loc
+								for(attrib = output.attributes.begin(); attrib!=output.attributes.end(); ++attrib)
 								{
-									PARSE_ERR_EXPECTED("integer");
-									return false;
+									if(attrib->customLoc == loc)
+									{
+										throw PARSER_EXCEPTION("The attributes \"" + attrib->name + "\" (" + attrib->definedInFile + ":" +
+																					 lexical_cast<string>(attrib->definedInLine) + ") and \"" + varName +
+																					 "\" share the same location");
+									}
 								}
+
+								// all ok, push it back
+								output.attributes.push_back(ShaderVarPragma(filename, scanner.getLineNumber(), varName, loc));
+								sourceLines.push_back(lines[scanner.getLineNumber()-1]);
 							}
 							else
 							{
-								PARSE_ERR_EXPECTED("identifier");
-								return false;
+								throw PARSER_EXCEPTION_EXPECTED("integer");
 							}
 						}
 						else
 						{
-							PARSE_ERR("#pragma anki followed by incorrect " << token->getInfoStr());
-							return false;
+							throw PARSER_EXCEPTION_EXPECTED("identifier");
 						}
-					} // end if anki
-
-					token = &scanner.getNextToken();
-					if(token->getCode()!=Scanner::TC_NEWLINE && token->getCode()!=Scanner::TC_EOF)
+					}
+					else
 					{
-						PARSE_ERR_EXPECTED("newline or end of file");
-						return false;
+						throw PARSER_EXCEPTION("#pragma anki followed by incorrect " + token->getInfoStr());
 					}
+				} // end if anki
 
-					if(token->getCode() == Scanner::TC_EOF)
-						break;
+				token = &scanner.getNextToken();
+				if(token->getCode()!=Scanner::TC_NEWLINE && token->getCode()!=Scanner::TC_EOF)
+				{
+					throw PARSER_EXCEPTION_EXPECTED("newline or end of file");
+				}
 
-				} // end if pragma
-			} // end if #
-			//
-			// newline
-			//
-			else if(token->getCode() == Scanner::TC_NEWLINE)
-			{
-				sourceLines.push_back(lines[scanner.getLineNumber() - 2]);
-				//PRINT(lines[scanner.getLineNmbr() - 2])
-			}
-			//
-			// EOF
-			//
-			else if(token->getCode() == Scanner::TC_EOF)
-			{
-				sourceLines.push_back(lines[scanner.getLineNumber() - 1]);
-				//PRINT(lines[scanner.getLineNmbr() - 1])
-				break;
-			}
-			//
-			// error
-			//
-			else if(token->getCode() == Scanner::TC_ERROR)
-			{
-				return false;
-			}
-		} // end while
-	}
-	catch(Exception& e)
-	{
-		ERROR(e.what());
-		return false;
-	}
-	
-	return true;
+				if(token->getCode() == Scanner::TC_EOF)
+				{
+					break;
+				}
+
+			} // end if pragma
+		} // end if #
+		//
+		// newline
+		//
+		else if(token->getCode() == Scanner::TC_NEWLINE)
+		{
+			sourceLines.push_back(lines[scanner.getLineNumber() - 2]);
+			//PRINT(lines[scanner.getLineNmbr() - 2])
+		}
+		//
+		// EOF
+		//
+		else if(token->getCode() == Scanner::TC_EOF)
+		{
+			sourceLines.push_back(lines[scanner.getLineNumber() - 1]);
+			//PRINT(lines[scanner.getLineNmbr() - 1])
+			break;
+		}
+		//
+		// error
+		//
+		else if(token->getCode() == Scanner::TC_ERROR)
+		{
+			// It will never get here
+		}
+	} // end while
 }
 
 
 //======================================================================================================================
 // parseFile                                                                                                           =
 //======================================================================================================================
-bool ShaderPrePreprocessor::parseFile(const char* filename)
+void ShaderPrePreprocessor::parseFile(const char* filename)
 {
-	// parse master file
-	if(!parseFileForPragmas(filename))
+	try
 	{
-		return false;
-	}
+		// parse master file
+		parseFileForPragmas(filename);
 
-	// rearrange the trffbVaryings
 
-	// sanity checks
-	if(vertShaderBegins.globalLine == -1)
-	{
-		ERROR("Entry point \"vertShaderBegins\" is not defined in file \"" << filename << "\"");
-		return false;
-	}
-	if(fragShaderBegins.globalLine == -1)
-	{
-		ERROR("Entry point \"fragShaderBegins\" is not defined in file \"" << filename << "\"");
-		return false;
-	}
+		// rearrange the trffbVaryings
 	
-	// construct shader's source code
-	{
-		// init
-		output.vertShaderSource = "";
-		output.geomShaderSource = "";
-		output.fragShaderSource = "";
-
-		// put global source code
-		for(int i=0; i<vertShaderBegins.globalLine-1; ++i)
+		// sanity checks
+		if(vertShaderBegins.globalLine == -1)
 		{
-			output.vertShaderSource += sourceLines[i] + "\n";
-
-			if(geomShaderBegins.definedInLine != -1)
-				output.geomShaderSource += sourceLines[i] + "\n";
-
-			output.fragShaderSource += sourceLines[i] + "\n";
+			throw EXCEPTION("Entry point \"vertShaderBegins\" is not defined");
 		}
-
-		// vert shader code
-		int limit = (geomShaderBegins.definedInLine != -1) ? geomShaderBegins.globalLine-1 : fragShaderBegins.globalLine-1;
-		for(int i=vertShaderBegins.globalLine-1; i<limit; ++i)
+		if(fragShaderBegins.globalLine == -1)
 		{
-			output.vertShaderSource += sourceLines[i] + "\n";
+			throw EXCEPTION("Entry point \"fragShaderBegins\" is not defined");
 		}
 
-		// geom shader code
-		if(geomShaderBegins.definedInLine != -1)
+		// construct shader's source code
 		{
-			for(int i=geomShaderBegins.globalLine-1; i<fragShaderBegins.globalLine-1; ++i)
+			// init
+			output.vertShaderSource = "";
+			output.geomShaderSource = "";
+			output.fragShaderSource = "";
+
+			// put global source code
+			for(int i=0; i<vertShaderBegins.globalLine-1; ++i)
 			{
-				output.geomShaderSource += sourceLines[i] + "\n";
+				output.vertShaderSource += sourceLines[i] + "\n";
+
+				if(geomShaderBegins.definedInLine != -1)
+				{
+					output.geomShaderSource += sourceLines[i] + "\n";
+				}
+
+				output.fragShaderSource += sourceLines[i] + "\n";
 			}
-		}
 
-		// frag shader code
-		for(int i=fragShaderBegins.globalLine-1; i<int(sourceLines.size()); ++i)
-		{
-			output.fragShaderSource += sourceLines[i] + "\n";
-		}
-	} // end construct shader's source code
+			// vert shader code
+			int limit = (geomShaderBegins.definedInLine != -1) ? geomShaderBegins.globalLine-1 : fragShaderBegins.globalLine-1;
+			for(int i=vertShaderBegins.globalLine-1; i<limit; ++i)
+			{
+				output.vertShaderSource += sourceLines[i] + "\n";
+			}
+
+			// geom shader code
+			if(geomShaderBegins.definedInLine != -1)
+			{
+				for(int i=geomShaderBegins.globalLine-1; i<fragShaderBegins.globalLine-1; ++i)
+				{
+					output.geomShaderSource += sourceLines[i] + "\n";
+				}
+			}
 
-	//PRINT("vertShaderBegins.globalLine: " << vertShaderBegins.globalLine)
-	//PRINT("fragShaderBegins.globalLine: " << fragShaderBegins.globalLine)
-	//printSourceLines();
-	//printShaderVars();
+			// frag shader code
+			for(int i=fragShaderBegins.globalLine-1; i<int(sourceLines.size()); ++i)
+			{
+				output.fragShaderSource += sourceLines[i] + "\n";
+			}
+		} // end construct shader's source code
 
-	return true;
+		//PRINT("vertShaderBegins.globalLine: " << vertShaderBegins.globalLine)
+		//PRINT("fragShaderBegins.globalLine: " << fragShaderBegins.globalLine)
+		//printSourceLines();
+		//printShaderVars();
+	}
+	catch(Exception& e)
+	{
+		throw EXCEPTION("Started from \"" + filename + "\": " + e.what());
+	}
 }
 

+ 38 - 41
src/Resources/Helpers/ShaderPrePreprocessor.h

@@ -2,8 +2,9 @@
 #define SHADER_PARSER_H
 
 #include <limits>
-#include "Common.h"
 #include "Vec.h"
+#include "StdTypes.h"
+#include "Properties.h"
 
 
 /// Helper class used for shader program loading
@@ -31,37 +32,37 @@ class ShaderPrePreprocessor
 		/// The pragma base class
 		struct Pragma
 		{
-			string definedInFile;
+			std::string definedInFile;
 			int    definedInLine;
-			Pragma();
-			Pragma(const string& definedInFile_, int definedInLine_);
+			Pragma(): definedInLine(-1) {}
+			Pragma(const std::string& definedInFile_, int definedInLine_);
 		};
 		
 		struct IncludePragma: Pragma
 		{
-			string filename;
+			std::string filename;
 		};
 		
 		struct ShaderVarPragma: Pragma
 		{
-			string name;
-			uint   customLoc;
+			std::string name;
+			uint customLoc;
 
-			ShaderVarPragma(const string& definedInFile_, int definedInLine_, const string& name_, uint customLoc_);
+			ShaderVarPragma(const std::string& definedInFile_, int definedInLine_, const std::string& name_, uint customLoc_);
 		};
 
 		struct TrffbVaryingPragma: Pragma
 		{
-			string name;
+			std::string name;
 
-			TrffbVaryingPragma(const string& definedInFile_, int definedInLine_, const string& name_);
+			TrffbVaryingPragma(const std::string& definedInFile_, int definedInLine_, const std::string& name_);
 		};
 	
 		struct CodeBeginningPragma: Pragma
 		{
 			int globalLine; ///< The line number in the ShaderPrePreprocessor-compatible file
 
-			CodeBeginningPragma();
+			CodeBeginningPragma(): globalLine(-1) {}
 		};
 
 		/// The output of the class packed in this struct
@@ -72,9 +73,9 @@ class ShaderPrePreprocessor
 			PROPERTY_R(Vec<ShaderVarPragma>, attributes, getAttribLocs) ///< It holds the name and the custom location
 			/// 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
-			PROPERTY_R(string, fragShaderSource, getFragShaderSource) ///< The frag shader source
+			PROPERTY_R(std::string, vertShaderSource, getVertShaderSource) ///< The vert shader source
+			PROPERTY_R(std::string, geomShaderSource, getGeomShaderSource) ///< The geom shader source
+			PROPERTY_R(std::string, fragShaderSource, getFragShaderSource) ///< The frag shader source
 		};
 
 	//====================================================================================================================
@@ -86,42 +87,47 @@ class ShaderPrePreprocessor
 	// Public                                                                                                            =
 	//====================================================================================================================
 	public:
-		ShaderPrePreprocessor() {}
-		~ShaderPrePreprocessor() {}
+		/// It loads a file and parses it
+		/// @param[in] filename The file to load
+		/// @exception Exception
+		ShaderPrePreprocessor(const char* filename) {parseFile(filename);}
 
-		/// 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);
+		/// Destructor does nothing
+		~ShaderPrePreprocessor() {}
 
 	//====================================================================================================================
 	// Protected                                                                                                         =
 	//====================================================================================================================
 	protected:
-		Vec<string> sourceLines;  ///< The parseFileForPragmas fills this
+		Vec<std::string> sourceLines;  ///< The parseFileForPragmas fills this
 		CodeBeginningPragma vertShaderBegins;
 		CodeBeginningPragma geomShaderBegins;
 		CodeBeginningPragma fragShaderBegins;
-		
+
+		/// Parse a ShaderPrePreprocessor formated GLSL file. Use getOutput to get the output
+		/// @param filename The file to parse
+		/// @exception Ecxeption
+		void parseFile(const char* filename);
+
 		/// 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);
+		/// @exception Ecxeption
+		void parseFileForPragmas(const std::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
-		Vec<ShaderVarPragma>::iterator findShaderVar(Vec<ShaderVarPragma>& vec, const string& name) const;
+		Vec<ShaderVarPragma>::iterator findShaderVar(Vec<ShaderVarPragma>& vec, const std::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
 		template<typename Type>
-		typename Vec<Type>::const_iterator findNamed(const Vec<Type>& vec, const string& what) const;
+		typename Vec<Type>::const_iterator findNamed(const Vec<Type>& vec, const std::string& what) const;
 
 		void printSourceLines() const;  ///< For debugging
 		void printShaderVars() const;  ///< For debugging
@@ -131,40 +137,31 @@ class ShaderPrePreprocessor
 //======================================================================================================================
 // Inlines                                                                                                             =
 //======================================================================================================================
-inline ShaderPrePreprocessor::Pragma::Pragma():
-	definedInLine(-1)
-{}
-
 
-inline ShaderPrePreprocessor::Pragma::Pragma(const string& definedInFile_, int definedInLine_):
+inline ShaderPrePreprocessor::Pragma::Pragma(const std::string& definedInFile_, int definedInLine_):
 	definedInFile(definedInFile_),
 	definedInLine(definedInLine_)
 {}
 
 
-inline ShaderPrePreprocessor::ShaderVarPragma::ShaderVarPragma(const string& definedInFile_, int definedInLine_,
-                                                               const string& name_, uint customLoc_):
+inline ShaderPrePreprocessor::ShaderVarPragma::ShaderVarPragma(const std::string& definedInFile_, int definedInLine_,
+                                                               const std::string& name_, uint customLoc_):
 	Pragma(definedInFile_, definedInLine_),
 	name(name_),
 	customLoc(customLoc_)
 {}
 
 
-inline ShaderPrePreprocessor::TrffbVaryingPragma::TrffbVaryingPragma(const string& definedInFile_,
+inline ShaderPrePreprocessor::TrffbVaryingPragma::TrffbVaryingPragma(const std::string& definedInFile_,
                                                                      int definedInLine_,
-                                                                     const string& name_):
+                                                                     const std::string& name_):
 	Pragma(definedInFile_, definedInLine_),
 	name(name_)
 {}
 
 
-inline ShaderPrePreprocessor::CodeBeginningPragma::CodeBeginningPragma():
-	globalLine(-1)
-{}
-
-
 template<typename Type>
-typename Vec<Type>::const_iterator ShaderPrePreprocessor::findNamed(const Vec<Type>& vec, const string& what) const
+typename Vec<Type>::const_iterator ShaderPrePreprocessor::findNamed(const Vec<Type>& vec, const std::string& what) const
 {
 	typename Vec<Type>::const_iterator it = vec.begin();
 	while(it != vec.end() && it->name != what)

+ 111 - 126
src/Resources/LightData.cpp

@@ -24,165 +24,150 @@ LightData::LightData():
 //======================================================================================================================
 void LightData::load(const char* filename)
 {
-	try
+	Scanner scanner(filename);
+	const Scanner::Token* token;
+	type = LT_NUM;
+
+	while(true)
 	{
-		Scanner scanner(filename);
-		const Scanner::Token* token;
-		type = LT_NUM;
+		token = &scanner.getNextToken();
 
-		while(true)
+		// type
+		if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "type"))
 		{
 			token = &scanner.getNextToken();
-
-			// type
-			if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "type"))
+			if(token->getCode() == Scanner::TC_IDENTIFIER)
 			{
-				token = &scanner.getNextToken();
-				if(token->getCode() == Scanner::TC_IDENTIFIER)
+				if(!strcmp(token->getValue().getString(), "LT_SPOT"))
 				{
-					if(!strcmp(token->getValue().getString(), "LT_SPOT"))
-					{
-						type = LT_SPOT;
-					}
-					else if(!strcmp(token->getValue().getString(), "LT_POINT"))
-					{
-						type = LT_POINT;
-					}
-					else
-					{
-						PARSER_THROW_EXCEPTION_EXPECTED("LT_SPOT or LT_POINT");
-						return false;
-					}
+					type = LT_SPOT;
+				}
+				else if(!strcmp(token->getValue().getString(), "LT_POINT"))
+				{
+					type = LT_POINT;
+				}
+				else
+				{
+					throw PARSER_EXCEPTION_EXPECTED("LT_SPOT or LT_POINT");
 				}
 			}
-			// diffuseCol
-			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "diffuseCol"))
-			{
-				Parser::parseMathVector(scanner, diffuseCol);
-			}
-			// specularCol
-			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "specularCol"))
+		}
+		// diffuseCol
+		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "diffuseCol"))
+		{
+			Parser::parseMathVector(scanner, diffuseCol);
+		}
+		// specularCol
+		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "specularCol"))
+		{
+			Parser::parseMathVector(scanner, specularCol);
+		}
+		// radius
+		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "radius"))
+		{
+			token = &scanner.getNextToken();
+			if(token->getCode() != Scanner::TC_NUMBER)
 			{
-				Parser::parseMathVector(scanner, specularCol);
+				throw PARSER_EXCEPTION_EXPECTED("number");
 			}
-			// radius
-			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "radius"))
+
+			radius = (token->getDataType() == Scanner::DT_FLOAT) ? token->getValue().getFloat() :
+																														 float(token->getValue().getInt());
+		}
+		// castsShadow
+		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "castsShadow"))
+		{
+			token = &scanner.getNextToken();
+			if(token->getCode() == Scanner::TC_IDENTIFIER)
 			{
-				token = &scanner.getNextToken();
-				if(token->getCode() != Scanner::TC_NUMBER)
+				if(!strcmp(token->getValue().getString(), "true"))
 				{
-					PARSER_THROW_EXCEPTION_EXPECTED("number");
-					return false;
+					castsShadow_ = true;
 				}
-
-				radius = (token->getDataType() == Scanner::DT_FLOAT) ? token->getValue().getFloat() :
-																															 float(token->getValue().getInt());
-			}
-			// castsShadow
-			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "castsShadow"))
-			{
-				token = &scanner.getNextToken();
-				if(token->getCode() == Scanner::TC_IDENTIFIER)
+				else if(!strcmp(token->getValue().getString(), "false"))
 				{
-					if(!strcmp(token->getValue().getString(), "true"))
-					{
-						castsShadow_ = true;
-					}
-					else if(!strcmp(token->getValue().getString(), "false"))
-					{
-						castsShadow_ = false;
-					}
-					else
-					{
-						PARSER_THROW_EXCEPTION_EXPECTED("true or false");
-						return false;
-					}
+					castsShadow_ = false;
 				}
 				else
 				{
-					PARSER_THROW_EXCEPTION_EXPECTED("true or false");
-					return false;
+					throw PARSER_EXCEPTION_EXPECTED("true or false");
 				}
 			}
-			// distance
-			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "distance"))
+			else
 			{
-				token = &scanner.getNextToken();
-				if(token->getCode() != Scanner::TC_NUMBER)
-				{
-					PARSER_THROW_EXCEPTION_EXPECTED("number");
-					return false;
-				}
-
-				distance = (token->getDataType() == Scanner::DT_FLOAT) ? token->getValue().getFloat() :
-																																 float(token->getValue().getInt());
-				type = LT_SPOT;
+				throw PARSER_EXCEPTION_EXPECTED("true or false");
 			}
-			// fovX
-			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "fovX"))
+		}
+		// distance
+		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "distance"))
+		{
+			token = &scanner.getNextToken();
+			if(token->getCode() != Scanner::TC_NUMBER)
 			{
-				token = &scanner.getNextToken();
-				if(token->getCode() != Scanner::TC_NUMBER)
-				{
-					PARSER_THROW_EXCEPTION_EXPECTED("number");
-					return false;
-				}
-
-				fovX = (token->getDataType() == Scanner::DT_FLOAT) ? token->getValue().getFloat() :
-																														 float(token->getValue().getInt());
-				type = LT_SPOT;
+				throw PARSER_EXCEPTION_EXPECTED("number");
 			}
-			// fovY
-			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "fovY"))
-			{
-				token = &scanner.getNextToken();
-				if(token->getCode() != Scanner::TC_NUMBER)
-				{
-					PARSER_THROW_EXCEPTION_EXPECTED("number");
-					return false;
-				}
 
-				fovY = (token->getDataType() == Scanner::DT_FLOAT) ? token->getValue().getFloat() :
-																														 float(token->getValue().getInt());
-				type = LT_SPOT;
-			}
-			// texture
-			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "texture"))
+			distance = (token->getDataType() == Scanner::DT_FLOAT) ? token->getValue().getFloat() :
+																															 float(token->getValue().getInt());
+			type = LT_SPOT;
+		}
+		// fovX
+		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "fovX"))
+		{
+			token = &scanner.getNextToken();
+			if(token->getCode() != Scanner::TC_NUMBER)
 			{
-				token = &scanner.getNextToken();
-				if(token->getCode() != Scanner::TC_STRING)
-				{
-					PARSER_THROW_EXCEPTION_EXPECTED("string");
-					return false;
-				}
-
-				texture.loadRsrc(token->getValue().getString());
-				texture->setRepeat(false);
-				texture->setAnisotropy(0);
-				texture->setFiltering(Texture::TFT_LINEAR);
-				type = LT_SPOT;
+				throw PARSER_EXCEPTION_EXPECTED("number");
 			}
-			// end of file
-			else if(token->getCode() == Scanner::TC_EOF)
+
+			fovX = (token->getDataType() == Scanner::DT_FLOAT) ? token->getValue().getFloat() :
+																													 float(token->getValue().getInt());
+			type = LT_SPOT;
+		}
+		// fovY
+		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "fovY"))
+		{
+			token = &scanner.getNextToken();
+			if(token->getCode() != Scanner::TC_NUMBER)
 			{
-				break;
+				throw PARSER_EXCEPTION_EXPECTED("number");
 			}
-			// other crap
-			else
+
+			fovY = (token->getDataType() == Scanner::DT_FLOAT) ? token->getValue().getFloat() :
+																													 float(token->getValue().getInt());
+			type = LT_SPOT;
+		}
+		// texture
+		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "texture"))
+		{
+			token = &scanner.getNextToken();
+			if(token->getCode() != Scanner::TC_STRING)
 			{
-				PARSER_THROW_EXCEPTION_UNEXPECTED();
-				return false;
+				throw PARSER_EXCEPTION_EXPECTED("string");
 			}
-		} // end while
-	}
-	catch(std::exception& e)
-	{
-		THROW_EXCEPTION(e.what());
-	}
+
+			texture.loadRsrc(token->getValue().getString());
+			texture->setRepeat(false);
+			texture->setAnisotropy(0);
+			texture->setFiltering(Texture::TFT_LINEAR);
+			type = LT_SPOT;
+		}
+		// end of file
+		else if(token->getCode() == Scanner::TC_EOF)
+		{
+			break;
+		}
+		// other crap
+		else
+		{
+			throw PARSER_EXCEPTION_UNEXPECTED();
+		}
+	} // end while
+
 	
 	// sanity checks
 	if(type == LT_NUM)
 	{
-		THROW_EXCEPTION("Forgot to set type");
+		throw EXCEPTION("File \"" + filename + "\": Forgot to set type");
 	}
 }

+ 69 - 56
src/Resources/Texture.cpp

@@ -39,67 +39,80 @@ Texture::~Texture()
 //======================================================================================================================
 // load                                                                                                                =
 //======================================================================================================================
-bool Texture::load(const char* filename)
+void Texture::load(const char* filename)
 {
-	target = GL_TEXTURE_2D;
-	if(isLoaded())
+	try
 	{
-		ERROR("Texture already loaded");
-		return false;
+		target = GL_TEXTURE_2D;
+		if(isLoaded())
+		{
+			THROW_ERROR("Texture already loaded");
+		}
+
+		Image img(filename);
+
+		// bind the texture
+		glGenTextures(1, &glId);
+		bind(LAST_TEX_UNIT);
+		if(mipmappingEnabled)
+		{
+			setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+		}
+		else
+		{
+			setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+		}
+
+		setTexParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+		setTexParameter(GL_TEXTURE_MAX_ANISOTROPY_EXT, float(anisotropyLevel));
+
+		// leave to GL_REPEAT. There is not real performance hit
+		setRepeat(true);
+
+		// chose formats
+		int internalFormat;
+		int format;
+		int type;
+		switch(img.getType())
+		{
+			case Image::CT_R:
+				internalFormat = (compressionEnabled) ? GL_COMPRESSED_RED : GL_RED;
+				format = GL_RED;
+				type = GL_UNSIGNED_BYTE;
+				break;
+
+			case Image::CT_RGB:
+				internalFormat = (compressionEnabled) ? GL_COMPRESSED_RGB : GL_RGB;
+				format = GL_RGB;
+				type = GL_UNSIGNED_BYTE;
+				break;
+
+			case Image::CT_RGBA:
+				internalFormat = (compressionEnabled) ? GL_COMPRESSED_RGBA : GL_RGBA;
+				format = GL_RGBA;
+				type = GL_UNSIGNED_BYTE;
+				break;
+
+			default:
+				THROW_ERROR("See file");
+		}
+
+		glTexImage2D(target, 0, internalFormat, img.getWidth(), img.getHeight(), 0, format, type, &img.getData()[0]);
+		if(mipmappingEnabled)
+		{
+			glGenerateMipmap(target);
+		}
+
+		if(!GL_OK())
+		{
+			THROW_EXCEPTION("OpenGL failed");
+		}
 	}
-
-	Image img;
-	if(!img.load(filename))
-		return false;
-
-	// bind the texture
-	glGenTextures(1, &glId);
-	bind(LAST_TEX_UNIT);
-	if(mipmappingEnabled)
-		setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
-	else
-		setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-
-	setTexParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
-	setTexParameter(GL_TEXTURE_MAX_ANISOTROPY_EXT, float(anisotropyLevel));
-
-	// leave to GL_REPEAT. There is not real performance hit
-	setRepeat(true);
-
-	// chose formats
-	int internalFormat;
-	int format;
-	int type;
-	switch(img.getType())
+	catch(exception& e)
 	{
-		case Image::CT_R:
-			internalFormat = (compressionEnabled) ? GL_COMPRESSED_RED : GL_RED;
-			format = GL_RED;
-			type = GL_UNSIGNED_BYTE;
-			break;
-
-		case Image::CT_RGB:
-			internalFormat = (compressionEnabled) ? GL_COMPRESSED_RGB : GL_RGB;
-			format = GL_RGB;
-			type = GL_UNSIGNED_BYTE;
-			break;
-
-		case Image::CT_RGBA:
-			internalFormat = (compressionEnabled) ? GL_COMPRESSED_RGBA : GL_RGBA;
-			format = GL_RGBA;
-			type = GL_UNSIGNED_BYTE;
-			break;
-
-		default:
-			FATAL("See file");
+		THROW_EXCEPTION("File \"" + filename + "\": " + e.what());
 	}
-
-	glTexImage2D(target, 0, internalFormat, img.getWidth(), img.getHeight(), 0, format, type, &img.getData()[0]);
-	if(mipmappingEnabled)
-		glGenerateMipmap(target);
-
-	return GL_OK();
 }
 
 

+ 12 - 3
src/Resources/Texture.h

@@ -9,7 +9,7 @@
 /// Texture resource class
 ///
 /// It loads or creates an image and then loads it in the GPU. Its an OpenGL container. It supports compressed and
-/// uncompressed TGAs and all formats of PNG (PNG loading comes through SDL_image)
+/// uncompressed TGAs and some of the formats of PNG (PNG loading uses libpng)
 ///
 /// @note The last texture unit is reserved and you cannot use it
 class Texture: public Resource
@@ -32,8 +32,17 @@ class Texture: public Resource
 
 		/// @name Create tex funcs
 		/// @{
-		bool load(const char* filename);
-		bool createEmpty2D(float width, float height, int internalFormat, int format, uint type_);
+
+		/// Load image
+		/// @exception Exception
+		void load(const char* filename);
+
+		/// Create empty texture.
+		/// Used by the Renderer
+		void createEmpty2D(float width, float height, int internalFormat, int format, uint type_);
+
+		/// Create empty texture with MSAA.
+		/// Used by the Renderer
 		bool createEmpty2DMsaa(int samplesNum, int internalFormat, int width_, int height_, bool mimapping);
 		/// @}
 

+ 3 - 3
src/Util/Exception.h

@@ -2,7 +2,7 @@
 #define EXCEPTION_H
 
 #include <exception>
-#include <sstream>
+#include <string>
 
 
 /// Custom exception that takes. Throw it used the THROW_EXCEPTION macro
@@ -28,12 +28,12 @@ inline Exception::Exception(const std::string& err_, const char* file, int line,
 }
 
 
-#define THROW_EXCEPTION(x) throw Exception(std::string() + x, __FILE__, __LINE__, __func__)
+#define EXCEPTION(x) Exception(std::string() + x, __FILE__, __LINE__, __func__)
 
 #if DEBUG_ENABLED == 1
 	#define RASSERT_THROW_EXCEPTION(x) \
 		if(x) \
-			THROW_EXCEPTION("Reverse assertion failed: " #x)
+			throw EXCEPTION("Reverse assertion failed: " #x)
 #else
 	#define RASSERT_THROW_EXCEPTION(x)
 #endif

+ 30 - 20
src/Util/Scanner.cpp

@@ -13,8 +13,8 @@ using namespace std;
 using namespace boost;
 
 
-#define SCANNER_THROW_EXCEPTION(x) \
-	THROW_EXCEPTION(string("Scanner failed (") + scriptName + ':' + lexical_cast<string>(lineNmbr) + "): " + x)
+#define SCANNER_EXCEPTION(x) \
+	EXCEPTION(string("Scanner exception (") + scriptName + ':' + lexical_cast<string>(lineNmbr) + "): " + x)
 
 
 //======================================================================================================================
@@ -149,9 +149,20 @@ Scanner::AsciiFlag Scanner::asciiLookupTable [128] = {AC_ERROR};
 void Scanner::initAsciiMap()
 {
 	memset(&asciiLookupTable[0], AC_ERROR, sizeof(asciiLookupTable));
-	for(uint x='a'; x<='z'; x++) asciiLookupTable[x] = AC_LETTER;
-	for(uint x='A'; x<='Z'; x++) asciiLookupTable[x] = AC_LETTER;
-	for(uint x='0'; x<='9'; x++) asciiLookupTable[x] = AC_DIGIT;
+	for(uint x='a'; x<='z'; x++)
+	{
+		asciiLookupTable[x] = AC_LETTER;
+	}
+
+	for(uint x='A'; x<='Z'; x++)
+	{
+		asciiLookupTable[x] = AC_LETTER;
+	}
+
+	for(uint x='0'; x<='9'; x++)
+	{
+		asciiLookupTable[x] = AC_DIGIT;
+	}
 
 	asciiLookupTable[':'] = asciiLookupTable['['] = asciiLookupTable[']'] = asciiLookupTable['('] = AC_SPECIAL;
 	asciiLookupTable[')'] = asciiLookupTable['.'] = asciiLookupTable['{'] = asciiLookupTable['}'] = AC_SPECIAL;
@@ -231,7 +242,7 @@ char Scanner::getNextChar()
 	}
 	else if(lookupAscii(*pchar) == AC_ERROR)
 	{
-		SCANNER_THROW_EXCEPTION("Unacceptable char '" + *pchar + "' 0x" + lexical_cast<string>(static_cast<uint>(*pchar)));
+		throw SCANNER_EXCEPTION("Unacceptable char '" + *pchar + "' 0x" + lexical_cast<string>(static_cast<uint>(*pchar)));
 	}
 
 	return *pchar;
@@ -273,7 +284,7 @@ void Scanner::loadFile(const char* filename_)
 	inFstream.open(filename_);
 	if(!inFstream.good())
 	{
-		THROW_EXCEPTION("Cannot open file \"" + filename_ + '\"');
+		throw EXCEPTION("Cannot open file \"" + filename_ + '\"');
 	}
 	
 	loadIstream(inFstream, filename_);
@@ -287,7 +298,7 @@ void Scanner::loadIstream(istream& istream_, const char* scriptName_)
 {
 	if(inStream != NULL)
 	{
-		THROW_EXCEPTION("Tokenizer already initialized");
+		throw EXCEPTION("Tokenizer already initialized");
 	}
 
 	inStream = &istream_;
@@ -396,7 +407,7 @@ const Scanner::Token& Scanner::getNextToken()
 				break;
 			case AC_ERROR:
 			default:
-				SCANNER_THROW_EXCEPTION("Unexpected character \'" + *pchar + '\'');
+				throw SCANNER_EXCEPTION("Unexpected character \'" + *pchar + '\'');
 				getNextChar();
 				goto start;
 		}
@@ -526,7 +537,7 @@ void Scanner::checkComment()
 	//error
 	error:
 		crntToken.code = TC_ERROR;
-		SCANNER_THROW_EXCEPTION("Incorrect comment ending");
+		throw SCANNER_EXCEPTION("Incorrect comment ending");
 }
 
 
@@ -832,7 +843,7 @@ void Scanner::checkNumber()
 		}
 
 		*tmpStr = '\0';
-		SCANNER_THROW_EXCEPTION("Bad number suffix \"" + crntToken.asString + '\"');
+		throw SCANNER_EXCEPTION("Bad number suffix \"" + crntToken.asString + '\"');
 }
 
 
@@ -851,7 +862,7 @@ void Scanner::checkString()
 		{
 			crntToken.code = TC_ERROR;
 			*tmpStr = '\0';
-			SCANNER_THROW_EXCEPTION("Incorrect string ending \"" + crntToken.asString + '\"');
+			throw SCANNER_EXCEPTION("Incorrect string ending \"" + crntToken.asString + '\"');
 			return;
 		}
 		// Escape Codes
@@ -862,7 +873,7 @@ void Scanner::checkString()
 			{
 				crntToken.code = TC_ERROR;
 				*tmpStr = '\0';
-				SCANNER_THROW_EXCEPTION("Incorrect string ending \"" + crntToken.asString + '\"');
+				throw SCANNER_EXCEPTION("Incorrect string ending \"" + crntToken.asString + '\"');
 				return;
 			}
 
@@ -901,7 +912,7 @@ void Scanner::checkString()
 				case '\0':
 					break; // not an escape char but works almost the same
 				default:
-					SCANNER_THROW_EXCEPTION("Unrecognized escape character \'\\" + ch + '\'');
+					throw SCANNER_EXCEPTION("Unrecognized escape character \'\\" + ch + '\'');
 					*tmpStr++ = ch;
 			}
 		}
@@ -939,13 +950,13 @@ void Scanner::checkChar()
 
 	if(ch=='\0' || ch==eofChar) // check char after '
 	{
-		SCANNER_THROW_EXCEPTION("Newline in constant");
+		throw SCANNER_EXCEPTION("Newline in constant");
 		return;
 	}
 
 	if (ch=='\'') // if '
 	{
-		SCANNER_THROW_EXCEPTION("Empty constant");
+		throw SCANNER_EXCEPTION("Empty constant");
 		getNextChar();
 		return;
 	}
@@ -956,7 +967,7 @@ void Scanner::checkChar()
 		*tmpStr++ = ch;
 		if(ch=='\0' || ch==eofChar) //check again after the \.
 		{
-			SCANNER_THROW_EXCEPTION("Newline in constant");
+			throw SCANNER_EXCEPTION("Newline in constant");
 			return;
 		}
 
@@ -994,7 +1005,7 @@ void Scanner::checkChar()
 				break;
 			default:
 				ch0 = ch;
-				SCANNER_THROW_EXCEPTION("Unrecognized escape character \'\\" + ch + '\'');
+				throw SCANNER_EXCEPTION("Unrecognized escape character \'\\" + ch + '\'');
 		}
 		crntToken.value.char_ = ch0;
 	}
@@ -1012,8 +1023,7 @@ void Scanner::checkChar()
 		return;
 	}
 
-	SCANNER_THROW_EXCEPTION("Expected \'");
-	return;
+	throw SCANNER_EXCEPTION("Expected \'");
 }
 
 

+ 10 - 1
src/Util/Scanner.h

@@ -134,26 +134,35 @@ class Scanner
 	// Public                                                                                                            =
 	//====================================================================================================================
 	public:
+		/// Constructor #1
 		/// @param newlinesAsWhitespace @see newlinesAsWhitespace
+		/// @exception Exception
 		Scanner(bool newlinesAsWhitespace = true) {init(newlinesAsWhitespace);}
 
+		/// Constructor #2
 		/// @see loadFile
 		/// @param newlinesAsWhitespace @see newlinesAsWhitespace
+		/// @exception Exception
 		Scanner(const char* filename, bool newlinesAsWhitespace = true);
 
+		/// Constructor #3
 		/// @see loadIstream
 		/// @param newlinesAsWhitespace @see newlinesAsWhitespace
+		/// @exception Exception
 		Scanner(std::istream& istream_, const char* scriptName_ = "unamed-istream", bool newlinesAsWhitespace = true);
 
-		~Scanner() {void unload();}
+		~Scanner() {unload();}
 
 		/// Extracts all tokens and prints them. Used for debugging
 		void getAllPrintAll();
 
 		/// Get the next token from the stream
+		/// @return The next Token
+		/// @exception Exception
 		const Token& getNextToken();
 
 		/// Accessor for the current token
+		/// @return The current Token
 		const Token& getCrntToken() const {return crntToken;}
 
 		/// Get the name of the input stream

Some files were not shown because too many files changed in this diff