Przeglądaj źródła

The rev suffers from a serious bug
- Removing some functionality and replacing it with boost

Panagiotis Christopoulos Charitos 15 lat temu
rodzic
commit
154261a544

+ 5 - 4
src/Renderer/Hdr.cpp

@@ -4,6 +4,7 @@
  * Post-processing stage high dynamic range lighting pass
  */
 
+#include <boost/lexical_cast.hpp>
 #include "Renderer.h"
 #include "RsrcMngr.h"
 
@@ -60,14 +61,14 @@ void Renderer::Pps::Hdr::init()
 	string pps;
 	string prefix;
 
-	pps = "#define _PPS_HDR_PASS_0_\n#define IS_FAI_WIDTH " + Util::floatToStr(r.width) + "\n";
-	prefix = "Pass0IsFaiWidth" + Util::floatToStr(r.width);
+	pps = "#define _PPS_HDR_PASS_0_\n#define IS_FAI_WIDTH " + lexical_cast<string>(r.width) + "\n";
+	prefix = "Pass0IsFaiWidth" + lexical_cast<string>(r.width);
 	pass0SProg = RsrcMngr::shaders.load(ShaderProg::createSrcCodeToCache(shaderFname, pps.c_str(),
 	                                                                     prefix.c_str()).c_str());
 	pass0SProgFaiUniVar = pass0SProg->findUniVar("fai");
 
-	pps = "#define _PPS_HDR_PASS_1_\n#define PASS0_HEIGHT " + Util::floatToStr(height) + "\n";
-	prefix = "Pass1Pass0Height" + Util::floatToStr(height);
+	pps = "#define _PPS_HDR_PASS_1_\n#define PASS0_HEIGHT " + lexical_cast<string>(height) + "\n";
+	prefix = "Pass1Pass0Height" + lexical_cast<string>(height);
 	pass1SProg = RsrcMngr::shaders.load(ShaderProg::createSrcCodeToCache(shaderFname, pps.c_str(),
 	                                                                     prefix.c_str()).c_str());
 	pass1SProgFaiUniVar = pass1SProg->findUniVar("fai");

+ 3 - 2
src/Renderer/Is.cpp

@@ -4,6 +4,7 @@
  * Illumination stage
  */
 
+#include <boost/lexical_cast.hpp>
 #include "Renderer.h"
 #include "Camera.h"
 #include "Light.h"
@@ -141,8 +142,8 @@ void Renderer::Is::init()
 
 	// spot light w/t shadow
 	string pps = string("\n#define SPOT_LIGHT_ENABLED\n#define SHADOW_ENABLED\n") +
-	             "#define SHADOWMAP_SIZE " + Util::intToStr(sm.resolution) + "\n";
-	string prefix = "SpotShadowSms" + Util::intToStr(sm.resolution);
+	             "#define SHADOWMAP_SIZE " + lexical_cast<string>(sm.resolution) + "\n";
+	string prefix = "SpotShadowSms" + lexical_cast<string>(sm.resolution);
 	if(sm.pcfEnabled)
 	{
 		pps += "#define PCF_ENABLED\n";

+ 7 - 4
src/Renderer/MainRenderer.cpp

@@ -2,6 +2,8 @@
 #include <cstdio>
 #include <jpeglib.h>
 #include <fstream>
+#include <boost/filesystem.hpp>
+#include <boost/algorithm/string.hpp>
 #include "MainRenderer.h"
 #include "App.h"
 #include "RendererInitializer.h"
@@ -189,21 +191,22 @@ bool MainRenderer::takeScreenshotJpeg(const char* filename)
 //======================================================================================================================
 void MainRenderer::takeScreenshot(const char* filename)
 {
-	string ext = Util::getFileExtension(filename);
+	string ext = filesystem::path(filename).extension();
+	to_lower(ext);
 	bool ret;
 
 	// exec from this extension
-	if(ext == "tga")
+	if(ext == ".tga")
 	{
 		ret = takeScreenshotTga(filename);
 	}
-	else if(ext == "jpg" || ext == "jpeg")
+	else if(ext == ".jpg" || ext == ".jpeg")
 	{
 		ret = takeScreenshotJpeg(filename);
 	}
 	else
 	{
-		ERROR("File \"" << filename << "\": Unsupported extension. Watch for capital");
+		ERROR("File \"" << filename << "\": Unsupported extension");
 		return;
 	}
 

+ 7 - 4
src/Renderer/Ssao.cpp

@@ -4,6 +4,7 @@
  * Post-processing stage screen space ambient occlusion pass
  */
 
+#include <boost/lexical_cast.hpp>
 #include "Renderer.h"
 #include "Camera.h"
 #include "RsrcMngr.h"
@@ -85,14 +86,16 @@ void Renderer::Pps::Ssao::init()
 
 	ssaoSProg = RsrcMngr::shaders.load("shaders/PpsSsao.glsl");
 
-	string pps = "#define _PPS_SSAO_PASS_0_\n#define PASS0_FAI_WIDTH " + Util::floatToStr(width) + "\n";
-	string prefix = "Pass0Width" + Util::floatToStr(width);
+	string pps = "#define _PPS_SSAO_PASS_0_\n#define PASS0_FAI_WIDTH " + lexical_cast<string>(static_cast<float>(width)) +
+	             "\n";
+	string prefix = "Pass0Width" + lexical_cast<string>(width);
 	blurSProg = RsrcMngr::shaders.load(ShaderProg::createSrcCodeToCache("shaders/PpsSsaoBlur.glsl", pps.c_str(),
 	                                                                     prefix.c_str()).c_str());
 
 
-	pps = "#define _PPS_SSAO_PASS_1_\n#define PASS1_FAI_HEIGHT " + Util::floatToStr(bheight) + "\n";
-	prefix = "Pass1Height" + Util::floatToStr(bheight);
+	pps = "#define _PPS_SSAO_PASS_1_\n#define PASS1_FAI_HEIGHT " + lexical_cast<string>(static_cast<float>(bheight)) +
+	      "\n";
+	prefix = "Pass1Height" + lexical_cast<string>(bheight);
 	blurSProg2 = RsrcMngr::shaders.load(ShaderProg::createSrcCodeToCache("shaders/PpsSsaoBlur.glsl", pps.c_str(),
 	                                                                      prefix.c_str()).c_str());
 

+ 10 - 9
src/Resources/Helpers/ShaderPrePreprocessor.cpp

@@ -1,5 +1,6 @@
 #include <iomanip>
 #include <cstring>
+#include <boost/lexical_cast.hpp>
 #include "ShaderPrePreprocessor.h"
 #include "Scanner.h"
 #include "Parser.h"
@@ -127,8 +128,8 @@ bool ShaderPrePreprocessor::parseFileForPragmas(const string& filename, int dept
 						vertShaderBegins.definedInFile = filename;
 						vertShaderBegins.definedInLine = scanner.getLineNumber();
 						vertShaderBegins.globalLine = sourceLines.size() + 1;
-						sourceLines.push_back(string("#line ") + Util::intToStr(scanner.getLineNumber()) + ' ' +
-						                      Util::intToStr(depth) + " // " + lines[scanner.getLineNumber()-1]);
+						sourceLines.push_back("#line " + lexical_cast<string>(scanner.getLineNumber()) + ' ' +
+						                      lexical_cast<string>(depth) + " // " + lines[scanner.getLineNumber()-1]);
 						// stop play
 					}
 /* geomShaderBegins */
@@ -170,8 +171,8 @@ bool ShaderPrePreprocessor::parseFileForPragmas(const string& filename, int dept
 						geomShaderBegins.definedInFile = filename;
 						geomShaderBegins.definedInLine = scanner.getLineNumber();
 						geomShaderBegins.globalLine = sourceLines.size() + 1;
-						sourceLines.push_back(string("#line ") + Util::intToStr(scanner.getLineNumber()) + ' ' +
-						                      Util::intToStr(depth) + " // " + lines[scanner.getLineNumber()-1]);
+						sourceLines.push_back("#line " + lexical_cast<string>(scanner.getLineNumber()) + ' ' +
+						                      lexical_cast<string>(depth) + " // " + lines[scanner.getLineNumber()-1]);
 						// stop play
 					}
 /* fragShaderBegins */
@@ -204,8 +205,8 @@ bool ShaderPrePreprocessor::parseFileForPragmas(const string& filename, int dept
 						fragShaderBegins.definedInFile = filename;
 						fragShaderBegins.definedInLine = scanner.getLineNumber();
 						fragShaderBegins.globalLine = sourceLines.size() + 1;
-						sourceLines.push_back(string("#line ") + Util::intToStr(scanner.getLineNumber()) + ' ' +
-						                      Util::intToStr(depth) + " // " + lines[scanner.getLineNumber()-1]);
+						sourceLines.push_back("#line " + lexical_cast<string>(scanner.getLineNumber()) + ' ' +
+						                      lexical_cast<string>(depth) + " // " + lines[scanner.getLineNumber()-1]);
 						// stop play
 					}
 /* include */
@@ -216,12 +217,12 @@ bool ShaderPrePreprocessor::parseFileForPragmas(const string& filename, int dept
 						{
 							// play
 							//int line = sourceLines.size();
-							sourceLines.push_back(string("#line 0 ") + Util::intToStr(depth+1) + " // " +
+							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(string("#line ") + Util::intToStr(scanner.getLineNumber()) + ' ' +
-							                      Util::intToStr(depth) +  " // end of " + lines[scanner.getLineNumber()-1]);
+							sourceLines.push_back("#line " + lexical_cast<string>(scanner.getLineNumber()) + ' ' +
+							                      lexical_cast<string>(depth) +  " // end of " + lines[scanner.getLineNumber()-1]);
 							// stop play
 						}
 						else

+ 26 - 1
src/Util/Common.cpp

@@ -1,6 +1,7 @@
 #include <iostream>
 #include <GL/glew.h>
 #include <GL/glu.h>
+#include <boost/filesystem.hpp>
 #include "Common.h"
 #include "App.h"
 #include "Util.h"
@@ -17,6 +18,29 @@ static const char* terminalColors [MT_NUM + 1] = {
 };
 
 
+//======================================================================================================================
+// getFunctionFromPrettyFunction                                                                                       =
+//======================================================================================================================
+/**
+ * The function gets __PRETTY_FUNCTION__ and strips it to get only the function name with its namespace
+ */
+static string getFunctionFromPrettyFunction(const char* prettyFunction)
+{
+	string ret(prettyFunction);
+
+	size_t index = ret.find("(");
+
+	if (index != string::npos)
+		ret.erase(index);
+
+	index = ret.rfind(" ");
+	if (index != string::npos)
+		ret.erase(0, index + 1);
+
+	return ret;
+}
+
+
 //======================================================================================================================
 // msgPrefix                                                                                                           =
 //======================================================================================================================
@@ -81,7 +105,8 @@ ostream& msgPrefix(MsgType msgType, const char* file, int line, const char* func
 	}
 
 	// print caller info
-	(*cs) << " (" << Util::cutPath(file) << ":" << line << " " << Util::getFunctionFromPrettyFunction(func) << "): ";
+	(*cs) << " (" << filesystem::path(file).filename() << ":" << line << " " << getFunctionFromPrettyFunction(func) <<
+	         "): ";
 
 	return (*cs);
 }

+ 0 - 123
src/Util/Util.cpp

@@ -71,127 +71,4 @@ Vec<string> getFileLines(const char* filename)
 }
 
 
-//======================================================================================================================
-// cutPath                                                                                                             =
-//======================================================================================================================
-char* cutPath(const char* path)
-{
-	char* str = (char*)path + strlen(path) - 1;
-	for(;;)
-	{
-		if((str-path)<=-1 || *str=='/' || *str=='\\')  break;
-		str--;
-	}
-	return str+1;
-}
-
-
-//======================================================================================================================
-// getPath                                                                                                             =
-//======================================================================================================================
-string getPath(const char* path)
-{
-	char* str = (char*)path + strlen(path) - 1;
-	for(;;)
-	{
-		if((str-path)<=-1 || *str=='/' || *str=='\\')  break;
-		-- str;
-	}
-	++str;
-	int n = str - path;
-	DEBUG_ERR(n<0 || n>100); // check the func. probably something wrong
-	string retStr;
-	retStr.assign(path, n);
-	return retStr;
-}
-
-
-//======================================================================================================================
-// getFunctionFromPrettyFunction                                                                                       =
-//======================================================================================================================
-string getFunctionFromPrettyFunction(const char* prettyFunction)
-{
-	string ret(prettyFunction);
-
-	size_t index = ret.find("(");
-
-	if (index != string::npos)
-		ret.erase(index);
-
-	index = ret.rfind(" ");
-	if (index != string::npos)
-		ret.erase(0, index + 1);
-
-	return ret;
-}
-
-
-//======================================================================================================================
-// getFileExtension                                                                                                    =
-//======================================================================================================================
-string getFileExtension(const char* path)
-{
-	char* str = (char*)path + strlen(path) - 1;
-	for(;;)
-	{
-		if((str-path)<=-1 || *str=='.')  break;
-		str--;
-	}
-
-	if(str == (char*)path + strlen(path) - 1) ERROR("Please put something after the '.' in path \"" << path << "\". Idiot");
-	if(str+1 == path) ERROR("Path \"" << path << "\" doesnt contain a '.'. What the fuck?");
-
-	return str+1;
-}
-
-
-//======================================================================================================================
-// intToStr                                                                                                            =
-//======================================================================================================================
-string intToStr(int i)
-{
-	char str [256];
-	char* pstr = str + ((sizeof(str)/sizeof(char)) - 1);
-	bool negative = false;
-
-	*pstr = '\0';
-
-	if(i < 0)
-	{
-		i = -i;
-		negative = true;
-	}
-
-	do
-	{
-		--pstr;
-		int remain = i % 10;
-		i = i / 10;
-		*pstr = '0' + remain;
-	} while(i != 0);
-
-	if(negative)
-	{
-		--pstr;
-		*pstr = '-';
-	}
-
-	return string(pstr);
-}
-
-
-//======================================================================================================================
-// floatToStr                                                                                                          =
-//======================================================================================================================
-string floatToStr(float f)
-{
-	char tmp [128];
-
-	sprintf(tmp, "%f", f);
-
-	string s(tmp);
-	return s;
-}
-
-
 } // end namesapce

+ 0 - 6
src/Util/Util.h

@@ -16,12 +16,6 @@ extern double randRange(double min, double max); ///< Pick a random number from
 
 extern string      readFile(const char* filename); ///< Open a text file and return its contents into a string
 extern Vec<string> getFileLines(const char* filename); ///< Open a text file and return its lines into a string vector
-extern string      getFileExtension(const char* path); ///< Self explanatory
-extern char*       cutPath(const char* path); ///< Given a full path return only the file. Used only to cut the path from __FILE__ and return the actual file name and some other cases
-extern string      getPath(const char* path); ///< Get a file and get its path
-extern string      getFunctionFromPrettyFunction(const char* pretty_function); /// The function gets __PRETTY_FUNCTION__ and strips it to get only the function name with its namespace
-extern string      intToStr(int); ///< Self explanatory
-extern string      floatToStr(float); ///< Self explanatory
 
 }