void TextureDescriptorUtils::CopyCompressionParams(const FilePath &descriptorPathname) { TextureDescriptor *descriptor = TextureDescriptor::CreateFromFile(descriptorPathname); if(!descriptor) return; const TextureDescriptor::Compression &srcCompression = descriptor->compression[GPU_POWERVR_IOS]; if(srcCompression.format == FORMAT_INVALID) { //source format not set SafeRelease(descriptor); return; } for(int32 gpu = GPU_POWERVR_ANDROID; gpu < GPU_FAMILY_COUNT; ++gpu) { if(descriptor->compression[gpu].format != FORMAT_INVALID) continue; descriptor->compression[gpu].compressToWidth = srcCompression.compressToWidth; descriptor->compression[gpu].compressToHeight = srcCompression.compressToHeight; descriptor->compression[gpu].sourceFileCrc = srcCompression.sourceFileCrc; if((srcCompression.format == FORMAT_PVR2 || srcCompression.format == FORMAT_PVR4) && (gpu != GPU_POWERVR_ANDROID)) { descriptor->compression[gpu].format = FORMAT_ETC1; } else { descriptor->compression[gpu].format = srcCompression.format; } } descriptor->Save(); SafeRelease(descriptor); }
void TextureDescriptorUtils::CreateDescriptorIfNeed(const FilePath &pngPathname) { FilePath descriptorPathname = TextureDescriptor::GetDescriptorPathname(pngPathname); if(false == FileSystem::Instance()->IsFile(descriptorPathname)) { TextureDescriptor *descriptor = new TextureDescriptor(); descriptor->Save(descriptorPathname); SafeRelease(descriptor); } }
FilePath TextureConverter::ConvertTexture(const TextureDescriptor &descriptor, eGPUFamily gpuFamily, bool updateAfterConversion, eConvertQuality quality) { const TextureDescriptor::Compression * compression = &descriptor.compression[gpuFamily]; FilePath outputPath; const String& outExtension = GPUFamilyDescriptor::GetCompressedFileExtension(gpuFamily, (DAVA::PixelFormat)compression->format); if(outExtension == ".pvr") { Logger::FrameworkDebug("Starting PVR (%s) conversion (%s)...", GlobalEnumMap<DAVA::PixelFormat>::Instance()->ToString(compression->format), descriptor.pathname.GetAbsolutePathname().c_str()); if(descriptor.dataSettings.GetIsNormalMap()) { outputPath = PVRConverter::Instance()->ConvertNormalMapPngToPvr(descriptor, gpuFamily, quality); } else { outputPath = PVRConverter::Instance()->ConvertPngToPvr(descriptor, gpuFamily, quality); } } else if(outExtension == ".dds") { DAVA::Logger::FrameworkDebug("Starting DXT(%s) conversion (%s)...", GlobalEnumMap<DAVA::PixelFormat>::Instance()->ToString(compression->format), descriptor.pathname.GetAbsolutePathname().c_str()); if(descriptor.IsCubeMap()) { outputPath = DXTConverter::ConvertCubemapPngToDxt(descriptor, gpuFamily); } else { outputPath = DXTConverter::ConvertPngToDxt(descriptor, gpuFamily); } } else { DVASSERT(false); } if(updateAfterConversion) { bool wasUpdated = descriptor.UpdateCrcForFormat(gpuFamily); if(wasUpdated) { // Potential problem may occur in case of multithread convertion of // one texture: Save() will dump to drive unvalid compression info // and final variant of descriptor must be dumped again after finishing // of all threads. descriptor.Save(); } } return outputPath; }
void LandscapeEditorDrawSystem::SaveTileMaskTexture() { if (!baseLandscape) { return; } if (!GetLandscapeProxy()->IsTilemaskChanged()) { return; } Texture* texture = baseLandscape->GetTexture(Landscape::TEXTURE_TILE_MASK); if (texture) { FilePath texturePathname = baseLandscape->GetTextureName(Landscape::TEXTURE_TILE_MASK); if (texturePathname.IsEmpty()) { return; } texturePathname.ReplaceExtension(".png"); eBlendMode srcBlend = RenderManager::Instance()->GetSrcBlend(); eBlendMode dstBlend = RenderManager::Instance()->GetDestBlend(); RenderManager::Instance()->SetBlendMode(BLEND_ONE, BLEND_ZERO); Image *image = texture->CreateImageFromMemory(); RenderManager::Instance()->SetBlendMode(srcBlend, dstBlend); if(image) { ImageLoader::Save(image, texturePathname); SafeRelease(image); } FilePath descriptorPathname = TextureDescriptor::GetDescriptorPathname(texturePathname); TextureDescriptor *descriptor = TextureDescriptor::CreateFromFile(descriptorPathname); if(!descriptor) { descriptor = new TextureDescriptor(); descriptor->pathname = descriptorPathname; descriptor->Save(); } SafeRelease(descriptor); GetLandscapeProxy()->ResetTilemaskChanged(); } }
void LightmapsPacker::CreateDescriptors() { FileList * fileList = new FileList(outputDir); int32 itemsCount = fileList->GetCount(); for(int32 i = 0; i < itemsCount; ++i) { const FilePath & filePath = fileList->GetPathname(i); if(fileList->IsDirectory(i) || !filePath.IsEqualToExtension(".png")) { continue; } TextureDescriptor descriptor; descriptor.Save(TextureDescriptor::GetDescriptorPathname(filePath)); } fileList->Release(); }
void LandscapePropertyControl::GenerateFullTiledTexture(DAVA::BaseObject *object, void *userData, void *callerData) { LandscapeNode *landscape = GetLandscape(); if (!landscape) return; String texPathname = landscape->SaveFullTiledTexture(); String descriptorPathname = TextureDescriptor::GetDescriptorPathname(texPathname); TextureDescriptor *descriptor = TextureDescriptor::CreateFromFile(descriptorPathname); if(!descriptor) { descriptor = new TextureDescriptor(); descriptor->pathname = descriptorPathname; descriptor->Save(); } propertyList->SetFilepathPropertyValue(String("property.landscape.texture.tiledtexture"), descriptor->pathname); landscape->SetTexture(LandscapeNode::TEXTURE_TILE_FULL, descriptor->pathname); SafeRelease(descriptor); }
void TextureDescriptorUtils::SetCompressionParams( const FilePath &descriptorPathname, const DAVA::Map<DAVA::eGPUFamily, DAVA::TextureDescriptor::Compression> & compressionParams, bool convertionEnabled, bool force) { TextureDescriptor *descriptor = TextureDescriptor::CreateFromFile(descriptorPathname); if(!descriptor) return; auto endIt = compressionParams.end(); for(auto it = compressionParams.begin(); it != endIt; ++it) { eGPUFamily gpu = it->first; if(force || (descriptor->compression[gpu].format == FORMAT_INVALID)) { descriptor->compression[gpu] = it->second; if(convertionEnabled) { ImageTools::ConvertImage(descriptor, gpu, (PixelFormat)descriptor->compression[gpu].format); } } } descriptor->Save(); SafeRelease(descriptor); }
void CubemapEditorDialog::SaveCubemap(const QString& path) { FilePath filePath(path.toStdString()); DAVA::uint8 faceMask = GetFaceMask(); //copy file to the location where .tex will be put. Add suffixes to file names to distinguish faces String fileNameWithoutExtension = filePath.GetFilename(); String extension = filePath.GetExtension(); fileNameWithoutExtension.replace(fileNameWithoutExtension.find(extension), extension.size(), ""); for(int i = 0 ; i < CubemapUtils::GetMaxFaces(); ++i) { if(!facePath[i].isNull()) { FilePath faceFilePath = filePath; faceFilePath.ReplaceFilename(fileNameWithoutExtension + CubemapUtils::GetFaceNameSuffix(CubemapUtils::MapUIToFrameworkFace(i)) + "." + CubemapUtils::GetDefaultFaceExtension()); DAVA::String targetFullPath = faceFilePath.GetAbsolutePathname().c_str(); if(facePath[i] != targetFullPath.c_str()) { if(QFile::exists(targetFullPath.c_str())) { int answer = ShowQuestion("File overwrite", "File " + targetFullPath + " already exist. Do you want to overwrite it with " + facePath[i].toStdString(), MB_FLAG_YES | MB_FLAG_NO, MB_FLAG_NO); if(MB_FLAG_YES == answer) { bool removeResult = QFile::remove(targetFullPath.c_str()); if(!removeResult) { ShowErrorDialog("Failed to copy texture " + facePath[i].toStdString() + " to " + targetFullPath.c_str()); return; } } else { continue; } } bool copyResult = QFile::copy(facePath[i], targetFullPath.c_str()); if(!copyResult) { ShowErrorDialog("Failed to copy texture " + facePath[i].toStdString() + " to " + targetFullPath); return; } } ClickableQLabel* faceLabel = GetLabelForFace(i); if(faceLabel->GetRotation() != 0) { QTransform transform; transform.rotate(faceLabel->GetRotation()); QImage qimg(targetFullPath.c_str()); QImage rotatedImage = qimg.transformed(transform); rotatedImage.save(targetFullPath.c_str()); faceLabel->SetRotation(0); } } } TextureDescriptor* descriptor = new TextureDescriptor(); bool descriptorReady = false; if(filePath.Exists()) { descriptorReady = descriptor->Load(filePath); } if(!descriptorReady) { descriptor->SetDefaultValues(); descriptor->drawSettings.wrapModeS = descriptor->drawSettings.wrapModeT = Texture::WRAP_CLAMP_TO_EDGE; } descriptor->dataSettings.faceDescription = faceMask; descriptor->Save(filePath); SafeDelete(descriptor); QMessageBox::information(this, "Cubemap texture save result", "Cubemap texture was saved successfully!"); }
void TextureDescriptorUtils::ResaveDescriptor(const FilePath & descriptorPathname) { TextureDescriptor *descriptor = TextureDescriptor::CreateFromFile(descriptorPathname); descriptor->Save(); SafeRelease(descriptor); }