FilePath TextureDescriptor::GetDescriptorPathname(const FilePath &texturePathname) { DVASSERT(!texturePathname.IsEmpty()); if(0 == CompareCaseInsensitive(texturePathname.GetExtension(), GetDescriptorExtension())) { return texturePathname; } DVASSERT(GPUFamilyDescriptor::GetGPUForPathname(texturePathname) == GPU_UNKNOWN); return FilePath::CreateWithNewExtension(texturePathname, GetDescriptorExtension()); }
bool LibDxtHelper::WriteDxtFile(const String & fileNameOriginal, int32 width, int32 height, uint8 * data, PixelFormat compressionFormat, bool generateMipmaps) { if(!( (compressionFormat >= FORMAT_DXT1 && compressionFormat <= FORMAT_DXT5NM)|| (compressionFormat == FORMAT_RGBA8888)) ) { Logger::Error("[LibDxtHelper::WriteDxtFile] Wrong copression format (%d).", compressionFormat); return false; } //creating tmp dds file, nvtt accept only filename.dds as input, because of this the last letter befor "." should be changed to "_". String extension = FileSystem::Instance()->GetExtension(fileNameOriginal); if(0 != CompareCaseInsensitive(extension, ".dds")) { Logger::Error("[LibDxtHelper::WriteDxtFile] Wrong input file name (%s).", fileNameOriginal.c_str()); return false; } nvtt::Format innerComprFormat = NvttHelper::GetNVTTFormatByPixelFormat(compressionFormat); if(nvtt::Format_BC5 == innerComprFormat) { //bc5 is unsupported, used to determinate fail in search Logger::Error("[LibDxtHelper::WriteDxtFile] Can't work with nvtt::Format_BC5."); return false; } uint32 imgDataSize = width * height * Texture::GetPixelFormatSizeInBytes(FORMAT_RGBA8888); NvttHelper::SwapBRChannels(data, imgDataSize); InputOptions inputOptions; inputOptions.setTextureLayout(TextureType_2D, width, height); inputOptions.setMipmapGeneration(generateMipmaps); inputOptions.setMipmapData(data, width, height); CompressionOptions compressionOptions; compressionOptions.setFormat(innerComprFormat); if(FORMAT_DXT1NM == compressionFormat) { compressionOptions.setColorWeights(1, 1, 0); } else if (FORMAT_DXT5NM == compressionFormat) { inputOptions.setNormalMap(true); } OutputOptions outputOptions; String fileName = FileSystem::Instance()->ReplaceExtension(fileNameOriginal, "_dds"); outputOptions.setFileName(fileName.c_str()); Compressor compressor; bool ret = compressor.process(inputOptions, compressionOptions, outputOptions); if(ret) { FileSystem::Instance()->DeleteFile(fileNameOriginal); if(!FileSystem::Instance()->MoveFile(fileName, fileNameOriginal, true)) { Logger::Error("[LibDxtHelper::WriteDxtFile] Temporary dds file renamig failed."); ret = false; } } else { Logger::Error("[LibDxtHelper::WriteDxtFile] Error during writing DDS file (%s).", fileName.c_str()); } return ret; }
bool FilePath::IsEqualToExtension( const String & extension ) const { String selfExtension = GetExtension(); return (CompareCaseInsensitive(extension, selfExtension) == 0); }