Ticket #2996: 0009-Add-externalTextureCompressTool-etct-parameter-to-ar.patch
File 0009-Add-externalTextureCompressTool-etct-parameter-to-ar.patch, 9.2 KB (added by , 9 years ago) |
---|
-
new file inaries/system/texturecompress.sh
From 7c6bd305aba5a808c39db3d793b957f91c78e246 Mon Sep 17 00:00:00 2001 From: BogDan Vatra <bogdan@kde.org> Date: Sun, 8 Feb 2015 20:11:29 +0200 Subject: [PATCH 9/9] Add externalTextureCompressTool | etct parameter to archivebuild Now the user can compress the textures using any compression he wants. Default script uses Mali's etcpack to compress the textures using ETC2. Uses: $ ./binaries/system/pyrogenesis -archivebuild=binaries/data/mods/public -archivebuild-output=temp/public.zip -archivebuild-compress -etct=/path/to/texture/compress/script.sh If -etct value is missing pyrogenesis will use the default script (./binaries/system/texturecompress.sh) --- binaries/system/texturecompress.sh | 64 +++++++++++++++++++++++++ source/graphics/TextureManager.cpp | 97 +++++++++++++++++++++++++++++++------- source/graphics/TextureManager.h | 2 +- source/main.cpp | 13 ++++- source/ps/ArchiveBuilder.cpp | 6 +-- source/ps/ArchiveBuilder.h | 3 +- 6 files changed, 162 insertions(+), 23 deletions(-) create mode 100755 binaries/system/texturecompress.sh diff --git a/binaries/system/texturecompress.sh b/binaries/system/texturecompress.sh new file mode 100755 index 0000000..4afa33b
- + 1 #!/bin/bash 2 3 # MALI etcpack script 4 5 set -e 6 7 ETCPACKTOOL=`which etcpack` 8 9 if [ $ETCPACKTOOL == '' ]; then 10 echo "Can't find etcpack in your path"; 11 exit 1 12 fi 13 14 INFILE='' 15 OUTFILE='' 16 FORMAT='' 17 MIPMAPS='' 18 while [ $# -gt 0 ]; do 19 case $1 in 20 -in ) 21 shift 22 INFILE=`realpath "$1"` 23 ;; 24 -out ) 25 shift 26 OUTFILE="$1" 27 ;; 28 -f ) 29 shift 30 FORMAT="$1" 31 ;; 32 -mipmaps ) 33 MIPMAPS="$1" 34 ;; 35 * ) 36 exit 1 37 esac 38 shift 39 done 40 41 if [ "$INFILE" = "" ]; then 42 echo "Missing -in parameter" 43 exit 1 44 fi 45 46 if [ "$OUTFILE" = "" ]; then 47 echo "Missing -out parameter" 48 exit 1 49 fi 50 51 if [ "$FORMAT" = "" ]; then 52 echo "Missing -f parameter" 53 exit 1 54 fi 55 56 INFILEDIR=$(dirname "$INFILE") 57 KTXFILENAME=$(basename "$INFILE") 58 KTXFILENAME="$INFILEDIR/${KTXFILENAME%.*}.ktx" 59 60 $ETCPACKTOOL "$INFILE" "$INFILEDIR" -c etc2 -ktx -f "$FORMAT" "$MIPMAPS" 61 62 mv "$KTXFILENAME" "$OUTFILE" 63 64 exit 0 -
source/graphics/TextureManager.cpp
diff --git a/source/graphics/TextureManager.cpp b/source/graphics/TextureManager.cpp index bb209af..044b3e0 100644
a b public: 307 307 m_TextureConverter.ConvertTexture(texture, sourcePath, looseCachePath, settings); 308 308 } 309 309 310 bool GenerateCachedTexture(const VfsPath& sourcePath, VfsPath& archiveCachePath) 310 bool ExternalCompressTool(const VfsPath &in, const VfsPath &out, const CTextureConverter::Settings &settings, const Path &compressTool) 311 { 312 bool hasAlpha = false; 313 { 314 shared_ptr<u8> file; 315 size_t fileSize; 316 if (m_VFS->LoadFile(in, file, fileSize) < 0) 317 { 318 LOGERROR("Failed to load texture \"%s\"", in.string8()); 319 return false; 320 } 321 322 Tex tex; 323 if (tex.decode(file, fileSize) < 0) 324 { 325 LOGERROR("Failed to decode texture \"%s\"", in.string8()); 326 return false; 327 } 328 hasAlpha = tex.hasAlpha(); 329 if (hasAlpha && tex.m_Bpp == 32) 330 { 331 hasAlpha = false; 332 u8* data = tex.get_data(); 333 for (size_t i = 0; i < tex.m_Width * tex.m_Height; ++i) 334 { 335 if (data[i*4+3] != 0xFF) 336 { 337 hasAlpha = true; 338 break; 339 } 340 } 341 } 342 } 343 344 Path inPath; 345 Path outPath; 346 { 347 m_VFS->GetRealPath(in, inPath); 348 shared_ptr<u8> dummy; 349 m_VFS->CreateFile(out, dummy, 0); 350 m_VFS->GetRealPath(out, outPath); 351 } 352 std::string command(compressTool.string8() + " -in \""); 353 command += inPath.string8() + "\" -out \"" + outPath.string8() + "\""; 354 if (settings.mipmap == CTextureConverter::MIP_TRUE) 355 command += " -mipmaps"; 356 if (hasAlpha) 357 command += " -f RGBA"; 358 else 359 command += " -f RGB"; 360 361 debug_printf(L"Executing %hs\n", command.c_str()); 362 int res = system(command.c_str()); 363 ENSURE(res == 0); 364 return res == 0; 365 } 366 367 bool GenerateCachedTexture(const VfsPath& sourcePath, VfsPath& archiveCachePath, const Path &compressTool) 311 368 { 312 369 archiveCachePath = m_CacheLoader.ArchiveCachePath(sourcePath); 313 370 314 371 CTextureProperties textureProps(sourcePath); 315 372 CTexturePtr texture = CreateTexture(textureProps); 316 373 CTextureConverter::Settings settings = GetConverterSettings(texture); 317 318 if (!m_TextureConverter.ConvertTexture(texture, sourcePath, VfsPath("cache") / archiveCachePath, settings)) 319 return false; 320 321 while (true) 322 { 323 CTexturePtr textureOut; 324 VfsPath dest; 325 bool ok; 326 if (m_TextureConverter.Poll(textureOut, dest, ok)) 327 return ok; 328 329 // Spin-loop is dumb but it works okay for now 330 SDL_Delay(0); 374 if (compressTool.empty() || 375 settings.format == CTextureConverter::FMT_ALPHA || 376 !(settings.format & (CTextureConverter::FMT_DXT1 | 377 CTextureConverter::FMT_DXT3 | 378 CTextureConverter::FMT_DXT5))) { 379 if (!m_TextureConverter.ConvertTexture(texture, sourcePath, VfsPath("cache") / archiveCachePath, settings)) 380 return false; 381 382 while (true) 383 { 384 CTexturePtr textureOut; 385 VfsPath dest; 386 bool ok; 387 if (m_TextureConverter.Poll(textureOut, dest, ok)) 388 return ok; 389 390 // Spin-loop is dumb but it works okay for now 391 SDL_Delay(0); 392 } 331 393 } 394 return ExternalCompressTool(sourcePath, VfsPath("cache") / archiveCachePath, settings, compressTool); 332 395 } 333 396 334 397 bool MakeProgress() … … bool CTextureManager::MakeProgress() 652 715 return m->MakeProgress(); 653 716 } 654 717 655 bool CTextureManager::GenerateCachedTexture(const VfsPath& path, VfsPath& outputPath )718 bool CTextureManager::GenerateCachedTexture(const VfsPath& path, VfsPath& outputPath, const Path &compressTool) 656 719 { 657 return m->GenerateCachedTexture(path, outputPath );720 return m->GenerateCachedTexture(path, outputPath, compressTool); 658 721 } 659 722 660 723 size_t CTextureManager::GetBytesUploaded() const -
source/graphics/TextureManager.h
diff --git a/source/graphics/TextureManager.h b/source/graphics/TextureManager.h index 296a3c8..a3914f2 100644
a b public: 109 109 * is intended for pre-caching textures in release archives. 110 110 * @return true on success 111 111 */ 112 bool GenerateCachedTexture(const VfsPath& path, VfsPath& outputPath );112 bool GenerateCachedTexture(const VfsPath& path, VfsPath& outputPath, const Path &compressTool); 113 113 114 114 /** 115 115 * Returns total number of bytes uploaded for all current texture. -
source/main.cpp
diff --git a/source/main.cpp b/source/main.cpp index f7053aa..ae7ed47 100644
a b static void RunGameOrAtlas(int argc, const char* argv[]) 476 476 else 477 477 zip = mod.Filename().ChangeExtension(L".zip"); 478 478 479 CArchiveBuilder builder(mod, paths.Cache(), args.Has("etc2") ? CArchiveBuilder::ETC2 : CArchiveBuilder::S3TC); 479 OsPath compressTool; 480 if (args.Has("externalTextureCompressTool")) { 481 compressTool = args.Get("externalTextureCompressTool"); 482 if (compressTool.empty()) 483 compressTool = args.GetArg0().Parent() / L"texturecompress.sh"; 484 } 485 if (args.Has("etct")) { 486 compressTool = args.Get("etct"); 487 if (compressTool.empty()) 488 compressTool = args.GetArg0().Parent() / L"texturecompress.sh"; 489 } 490 CArchiveBuilder builder(mod, paths.Cache(), compressTool); 480 491 481 492 // Add mods provided on the command line 482 493 // NOTE: We do not handle mods in the user mod path here -
source/ps/ArchiveBuilder.cpp
diff --git a/source/ps/ArchiveBuilder.cpp b/source/ps/ArchiveBuilder.cpp index 4adb307..20848d2 100644
a b 28 28 29 29 #include <boost/algorithm/string.hpp> 30 30 31 CArchiveBuilder::CArchiveBuilder(const OsPath& mod, const OsPath& tempdir ) :32 m_TempDir(tempdir), m_NumBaseMods(0) 31 CArchiveBuilder::CArchiveBuilder(const OsPath& mod, const OsPath& tempdir, const OsPath &compressTool) : 32 m_TempDir(tempdir), m_NumBaseMods(0), m_CompressTextureTool(compressTool) 33 33 { 34 34 m_VFS = CreateVfs(20*MiB); 35 35 … … void CArchiveBuilder::Build(const OsPath& archive, bool compress) 98 98 { 99 99 VfsPath cachedPath; 100 100 debug_printf(L"Converting texture %ls\n", realPath.string().c_str()); 101 bool ok = textureManager.GenerateCachedTexture(path, cachedPath );101 bool ok = textureManager.GenerateCachedTexture(path, cachedPath, m_CompressTextureTool ); 102 102 ENSURE(ok); 103 103 104 104 OsPath cachedRealPath; -
source/ps/ArchiveBuilder.h
diff --git a/source/ps/ArchiveBuilder.h b/source/ps/ArchiveBuilder.h index 3e578e6..133d111 100644
a b public: 36 36 * @param mod path to data/mods/foo directory, containing files for conversion 37 37 * @param tempdir path to a writable directory for temporary files 38 38 */ 39 CArchiveBuilder(const OsPath& mod, const OsPath& tempdir );39 CArchiveBuilder(const OsPath& mod, const OsPath& tempdir, const OsPath& compressTool); 40 40 41 41 ~CArchiveBuilder(); 42 42 … … private: 64 64 std::vector<VfsPath> m_Files; 65 65 OsPath m_TempDir; 66 66 size_t m_NumBaseMods; 67 const OsPath& m_CompressTextureTool; 67 68 }; 68 69 69 70 #endif // INCLUDED_ARCHIVEBUILDER