コード例 #1
0
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);
}
コード例 #2
0
void SceneSaver::CopyTexture(const FilePath &texturePathname, Set<String> &errorLog)
{
    FilePath descriptorPathname = TextureDescriptor::GetDescriptorPathname(texturePathname);
	
	TextureDescriptor* desc = TextureDescriptor::CreateFromFile(descriptorPathname);
	if(desc->IsCubeMap())
	{
		sceneUtils.CopyFile(descriptorPathname, errorLog);
		
		Vector<String> faceNames;
		Texture::GenerateCubeFaceNames(descriptorPathname.GetAbsolutePathname().c_str(), faceNames);
		for(Vector<String>::iterator it = faceNames.begin();
			it != faceNames.end();
			++it)
		{
			sceneUtils.CopyFile(*it, errorLog);
		}
	}
	else
	{
		FilePath pngPathname = GPUFamilyDescriptor::CreatePathnameForGPU(texturePathname, GPU_UNKNOWN, FORMAT_RGBA8888);

		sceneUtils.CopyFile(descriptorPathname, errorLog);
		sceneUtils.CopyFile(pngPathname, errorLog);
	}
	
	SafeRelease(desc);
}
コード例 #3
0
	void SkyboxRenderObject::UpdateMaterial()
	{
		if(renderBatchArray.size() > 0)
		{
			Material* skyboxMaterial = renderBatchArray[0]->GetMaterial();
			
			//since the renderBatchArray is entirely controlled by SkyboxRenderObject
			//we can safely assume that objects in render batch array are properly initialized
			//and have material in place (no need to check for NULL)
			
            DAVA::Texture* tx = NULL;
            TextureDescriptor *descriptor = TextureDescriptor::CreateFromFile(texturePath);
            if(descriptor && descriptor->IsCubeMap())
            {
                tx = DAVA::Texture::CreateFromFile(texturePath, Texture::TEXTURE_CUBE);
            }
            else
            {
				tx = Texture::CreatePink(Texture::TEXTURE_CUBE);
            }
            
            skyboxMaterial->SetTexture(Material::TEXTURE_DIFFUSE, tx);

            SafeRelease(descriptor);
            tx->Release();
		}
	}
コード例 #4
0
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);
    }
}
コード例 #5
0
	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;
	}
コード例 #6
0
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();
	}
}
コード例 #7
0
void CubemapEditorDialog::LoadCubemap(const QString& path)
{
	FilePath filePath(path.toStdString());
	TextureDescriptor* texDescriptor = TextureDescriptor::CreateFromFile(filePath);
	
	if(NULL != texDescriptor &&
	   texDescriptor->IsCubeMap())
	{
		String fileNameWithoutExtension = filePath.GetFilename();
		String extension = filePath.GetExtension();
		fileNameWithoutExtension.replace(fileNameWithoutExtension.find(extension), extension.size(), "");

		bool cubemapLoadResult = true;
		for(int i = 0; i < CubemapUtils::GetMaxFaces(); ++i)
		{
			if(texDescriptor->dataSettings.faceDescription & (1 << CubemapUtils::MapUIToFrameworkFace(i)))
			{
				FilePath faceFilePath = filePath;
				faceFilePath.ReplaceFilename(fileNameWithoutExtension +
											 CubemapUtils::GetFaceNameSuffix(CubemapUtils::MapUIToFrameworkFace(i)) + "." +
											 CubemapUtils::GetDefaultFaceExtension());

				bool faceLoadResult = LoadImageTo(faceFilePath.GetAbsolutePathname(), i, true);
				cubemapLoadResult = cubemapLoadResult && faceLoadResult;
			}
		}
		
		if(!cubemapLoadResult)
		{
			ShowErrorDialog("This cubemap texture seems to be damaged.\nPlease repair it by setting image(s) to empty face(s) and save to disk.");
		}
	}
	else
	{
		if(NULL == texDescriptor)
		{
			ShowErrorDialog("Failed to load cubemap texture " + path.toStdString());
		}
		else
		{
			ShowErrorDialog("Failed to load cubemap texture " + path.toStdString() + ". Seems this is not a cubemap texture.");
		}
	}

	SafeDelete(texDescriptor);
}
コード例 #8
0
TextureDescriptor *TextureDescriptor::CreateFromFile(const FilePath &filePathname)
{
    if(filePathname.IsEmpty() || filePathname.GetType() == FilePath::PATH_IN_MEMORY)
        return NULL;

    FilePath descriptorPathname = GetDescriptorPathname(filePathname);
    TextureDescriptor *descriptor = new TextureDescriptor();
    bool loaded = descriptor->Load(descriptorPathname);
    if(!loaded)
    {
        Logger::Error("[TextureDescriptor::CreateFromFile(]: there are no descriptor file (%s).", descriptorPathname.GetAbsolutePathname().c_str());
        SafeRelease(descriptor);
        return NULL;
    }

    return descriptor;
}
コード例 #9
0
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();
}
コード例 #10
0
ファイル: texture.cpp プロジェクト: glmark2/glmark2
bool
Texture::load(const std::string &textureName, GLuint *pTexture, ...)
{
    // Make sure the named texture is in the map.
    TextureMap::const_iterator textureIt = TexturePrivate::textureMap.find(textureName);
    if (textureIt == TexturePrivate::textureMap.end())
    {
        return false;
    }

    // Pull the pathname out of the descriptor and use it for the PNG load.
    TextureDescriptor* desc = textureIt->second;
    const std::string& filename = desc->pathname();
    ImageData image;

    if (desc->filetype() == TextureDescriptor::FileTypePNG) {
        PNGReader reader(filename);
        if (!image.load(reader))
            return false;
    }
    else if (desc->filetype() == TextureDescriptor::FileTypeJPEG) {
        JPEGReader reader(filename);
        if (!image.load(reader))
            return false;
    }

    va_list ap;
    va_start(ap, pTexture);
    GLint arg;

    while ((arg = va_arg(ap, GLint)) != 0) {
        GLint arg2 = va_arg(ap, GLint);
        setup_texture(pTexture, image, arg, arg2);
        pTexture++;
    }

    va_end(ap);

    return true;
}
コード例 #11
0
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);
}
コード例 #12
0
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);
}
コード例 #13
0
ファイル: generate.cpp プロジェクト: Tetheta/sprouts
Mesh Generate::line(const vector<VectorF> &linePointsIn, TextureDescriptor texture, Color color,
                    float lineWidth)
{
    if(linePointsIn.size() < 2) // if less than 2 points then we can't have a line
    {
        return Mesh(new Mesh_t());
    }
    vector<VectorF> linePoints;
    linePoints.reserve(linePointsIn.size());
    linePoints.push_back(linePointsIn[0]);
    for(size_t i = 1; i < linePointsIn.size(); i++)
    {
        if(absSquared(linePointsIn[i] - linePoints.back()) >= eps * eps) // remove duplicates
            linePoints.push_back(linePointsIn[i]);
    }
    if(linePoints.size() < 2) // if less than 2 points then we can't have a line
    {
        return Mesh(new Mesh_t());
    }

    vector<Edge> edges;
    edges.reserve(linePoints.size());
    float distance = 0;
    edges.push_back(makeStartEdge(linePoints[0], linePoints[1], distance, lineWidth));
    distance += abs(linePoints[1] - linePoints[0]);
    for(size_t i = 2; i < linePoints.size(); i++)
    {
        edges.push_back(makeMiddleEdge(linePoints[i - 2], linePoints[i - 1], linePoints[i], distance, lineWidth));
        distance += abs(linePoints[i - 1] - linePoints[i]);
    }
    edges.push_back(makeEndEdge(linePoints[linePoints.size() - 2], linePoints[linePoints.size() - 1], distance, lineWidth));
    Mesh retval = nullptr;
    for(size_t i = 1; i < edges.size(); i++)
    {
        TextureDescriptor currentTexture = texture.subTexture(edges[i - 1].distance / distance, edges[i].distance / distance, 0, 1);
        Mesh mesh = Generate::quadrilateral(currentTexture, edges[i - 1].p2, color, edges[i].p2, color, edges[i].p1, color, edges[i - 1].p1, color);
        if(retval == nullptr)
            retval = mesh;
        else
            retval->add(mesh);
    }
    return retval;
}
コード例 #14
0
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!");
}
コード例 #15
0
void TextureDescriptorUtils::ResaveDescriptor(const FilePath & descriptorPathname) 
{
	TextureDescriptor *descriptor = TextureDescriptor::CreateFromFile(descriptorPathname);
	descriptor->Save();
	SafeRelease(descriptor);
}