コード例 #1
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();
		}
	}
コード例 #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
	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;
	}
コード例 #4
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);
}