Changed the default directory for the output files to be the current working directory,
with the --write-to-source-file-directory added to allow one to have the original behaviour of writing to the same directory as the original source file.
This commit is contained in:
parent
8a0e49d780
commit
b41e5ccc77
@ -30,13 +30,13 @@ void writeShader(osg::Shader* shader, const std::string& cppFileName, const std:
|
||||
searchAndReplace(shaderSource, "\r\n", "\n");
|
||||
searchAndReplace(shaderSource, "\r", "\n");
|
||||
searchAndReplace(shaderSource, "\"", "\\\"");
|
||||
|
||||
|
||||
std::string variableString = std::string("char ")+variableName+std::string("[] = ");
|
||||
|
||||
|
||||
std::string::size_type startOfLine = 0;
|
||||
std::string::size_type endOfLine = shaderSource.find_first_of('\n', startOfLine);
|
||||
|
||||
if (endOfLine==std::string::npos)
|
||||
|
||||
if (endOfLine==std::string::npos)
|
||||
{
|
||||
fout<<variableString<<shaderSource<<"\\n\";"<<std::endl;
|
||||
}
|
||||
@ -63,21 +63,25 @@ int main( int argc, char **argv )
|
||||
{
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
||||
// set up the usage document, in case we need to print out how to use this program.
|
||||
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
|
||||
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is a utility for converting glsl shader files into char arrays that can be compiled into applications.");
|
||||
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--shader <filename>","Shader file to create a .cpp file for.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--write-to-source-file-directory","Use the path to the source filename as the directory to write to.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line parameters");
|
||||
|
||||
// if user request help write it out to cout.
|
||||
if (arguments.read("-h") || arguments.read("--help"))
|
||||
{
|
||||
{
|
||||
arguments.getApplicationUsage()->write(std::cout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
bool useSamePathAsSourceFile = false;
|
||||
if (arguments.read("--write-to-source-file-directory")) useSamePathAsSourceFile = true;
|
||||
|
||||
std::string filename;
|
||||
if (arguments.read("--shader",filename))
|
||||
{
|
||||
@ -94,9 +98,11 @@ int main( int argc, char **argv )
|
||||
name[pos] = '_';
|
||||
pos = name.find_first_of(invalidCharacters);
|
||||
}
|
||||
|
||||
|
||||
std::string ext = osgDB::getFileExtension(filename);
|
||||
std::string cppFileName = osgDB::concatPaths(path, name + "_" + ext + ".cpp");
|
||||
std::string cppFileName = name + "_" + ext + ".cpp";
|
||||
if (useSamePathAsSourceFile) cppFileName = osgDB::concatPaths(path, cppFileName);
|
||||
|
||||
std::string variableName = name + "_" + ext;
|
||||
writeShader(shader.get(), cppFileName, variableName);
|
||||
|
||||
@ -107,7 +113,7 @@ int main( int argc, char **argv )
|
||||
std::cout<<"Error: could not find file '"<<filename<<"'"<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
std::cout<<"No appropriate command line options used."<<std::endl;
|
||||
|
Loading…
Reference in New Issue
Block a user