From ce7bb8e891789db0869d17735f1118578ad6082b Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Mon, 30 Sep 2013 12:46:23 -0400 Subject: [PATCH] Add command line flags to choose between whether or not to use PVRTexLib or FasTC --- CLTool/src/clunix.cpp | 5 +++++ CLTool/src/clwin32.cpp | 43 ++++++++++++++++++++++++------------------ Core/include/TexComp.h | 5 +++++ Core/src/TexComp.cpp | 15 ++++++++++++++- 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/CLTool/src/clunix.cpp b/CLTool/src/clunix.cpp index f3307a3..188466b 100644 --- a/CLTool/src/clunix.cpp +++ b/CLTool/src/clunix.cpp @@ -101,6 +101,7 @@ int main(int argc, char **argv) { bool bUseSIMD = false; bool bSaveLog = false; bool bUseAtomics = false; + bool bUsePVRTexLib = false; ECompressionFormat format = eCompressionFormat_BPTC; bool knowArg = false; @@ -129,6 +130,9 @@ int main(int argc, char **argv) { } else { if(!strcmp(argv[fileArg], "PVRTC")) { format = eCompressionFormat_PVRTC; + } else if(!strcmp(argv[fileArg], "PVRTCLib")) { + format = eCompressionFormat_PVRTC; + bUsePVRTexLib = true; } } @@ -235,6 +239,7 @@ int main(int argc, char **argv) { settings.iQuality = quality; settings.iNumCompressions = numCompressions; settings.iJobSize = numJobs; + settings.bUsePVRTexLib = bUsePVRTexLib; if(bSaveLog) { settings.logStream = &logStream; } else { diff --git a/CLTool/src/clwin32.cpp b/CLTool/src/clwin32.cpp index a8c56f5..9104841 100644 --- a/CLTool/src/clwin32.cpp +++ b/CLTool/src/clwin32.cpp @@ -105,12 +105,26 @@ int _tmain(int argc, _TCHAR* argv[]) bool bUseSIMD = false; bool bSaveLog = false; bool bUseAtomics = false; + bool bUsePVRTexLib = false; ECompressionFormat format = eCompressionFormat_BPTC; - + bool knowArg = false; do { knowArg = false; + if(strcmp(argv[fileArg], "-n") == 0) { + fileArg++; + + if(fileArg == argc || (numCompressions = atoi(argv[fileArg])) < 0) { + PrintUsage(); + exit(1); + } + + fileArg++; + knowArg = true; + continue; + } + if(strcmp(argv[fileArg], "-f") == 0) { fileArg++; @@ -120,6 +134,9 @@ int _tmain(int argc, _TCHAR* argv[]) } else { if(!strcmp(argv[fileArg], "PVRTC")) { format = eCompressionFormat_PVRTC; + } else if(!strcmp(argv[fileArg], "PVRTCLib")) { + format = eCompressionFormat_PVRTC; + bUsePVRTexLib = true; } } @@ -128,19 +145,6 @@ int _tmain(int argc, _TCHAR* argv[]) continue; } - if(strcmp(argv[fileArg], "-n") == 0) { - fileArg++; - - if(fileArg == argc || (numCompressions = atoi(argv[fileArg])) < 0) { - PrintUsage(); - exit(1); - } - - fileArg++; - knowArg = true; - continue; - } - if(strcmp(argv[fileArg], "-l") == 0) { fileArg++; bSaveLog = true; @@ -200,6 +204,7 @@ int _tmain(int argc, _TCHAR* argv[]) knowArg = true; continue; } + } while(knowArg && fileArg < argc); if(fileArg == argc) { @@ -238,10 +243,12 @@ int _tmain(int argc, _TCHAR* argv[]) settings.iQuality = quality; settings.iNumCompressions = numCompressions; settings.iJobSize = numJobs; - if(bSaveLog) + settings.bUsePVRTexLib = bUsePVRTexLib; + if(bSaveLog) { settings.logStream = &logStream; - else + } else { settings.logStream = NULL; + } CompressedImage *ci = CompressImage(&img, settings); if(NULL == ci) { @@ -268,8 +275,8 @@ int _tmain(int argc, _TCHAR* argv[]) // Cleanup delete ci; - if(bSaveLog) + if(bSaveLog) { logFile.close(); - + } return 0; } diff --git a/Core/include/TexComp.h b/Core/include/TexComp.h index f62bbd6..8833828 100644 --- a/Core/include/TexComp.h +++ b/Core/include/TexComp.h @@ -86,6 +86,11 @@ struct SCompressionSettings { // in the platform and compiler will provide synchronization. bool bUseAtomics; + // This flag instructs the infrastructure to use the compression routine from + // PVRTexLib. If no such lib is found during configuration then this flag is + // ignored. The quality being used is the fastest compression quality. + bool bUsePVRTexLib; + // This is the output stream with which we should output the logs for the // compression functions. std::ostream *logStream; diff --git a/Core/src/TexComp.cpp b/Core/src/TexComp.cpp index 1926dd0..d0bbb7d 100644 --- a/Core/src/TexComp.cpp +++ b/Core/src/TexComp.cpp @@ -73,6 +73,15 @@ static void CompressPVRTC(const CompressionJob &cj) { PVRTCC::Compress(cj); } +static void CompressPVRTCLib(const CompressionJob &cj) { +#ifdef PVRTEXLIB_FOUND + PVRTCC::CompressPVRLib(cj); +#else + fprintf(stderr, "WARNING: PVRTexLib not found, defaulting to FasTC implementation.\n"); + PVRTCC::Compress(cj); +#endif +} + SCompressionSettings:: SCompressionSettings() : format(eCompressionFormat_BPTC) , bUseSIMD(false) @@ -122,7 +131,11 @@ static CompressionFunc ChooseFuncFromSettings(const SCompressionSettings &s) { case eCompressionFormat_PVRTC: { - return CompressPVRTC; + if(s.bUsePVRTexLib) { + return CompressPVRTCLib; + } else { + return CompressPVRTC; + } } default: