Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
TextureAssetCompiler.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System.Threading.Tasks;
4 
5 using SiliconStudio.Assets.Compiler;
6 using SiliconStudio.BuildEngine;
7 using SiliconStudio.Core;
8 using SiliconStudio.Core.IO;
9 using SiliconStudio.Core.Serialization;
10 using SiliconStudio.Core.Serialization.Assets;
11 using SiliconStudio.Paradox.Graphics;
12 
13 namespace SiliconStudio.Paradox.Assets.Texture
14 {
15  /// <summary>
16  /// Texture asset compiler.
17  /// </summary>
18  internal class TextureAssetCompiler : AssetCompilerBase<TextureAsset>
19  {
20  protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, TextureAsset asset, AssetCompilerResult result)
21  {
22  if (asset.Source == null)
23  {
24  result.Error("Source cannot be null for Texture Asset [{0}]", asset);
25  return;
26  }
27 
28  // Get absolute path of asset source on disk
29  var assetDirectory = assetAbsolutePath.GetParent();
30  var assetSource = UPath.Combine(assetDirectory, asset.Source);
31 
32  result.BuildSteps = new ListBuildStep { new TextureConvertCommand(urlInStorage,
33  new TextureConvertParameters(assetSource, asset, context.Platform, context.GetGraphicsPlatform(), context.GetGraphicsProfile(), context.GetTextureQuality(), false)) };
34  }
35 
36  /// <summary>
37  /// Command used to convert the texture in the storage
38  /// </summary>
39  internal class TextureConvertCommand : AssetCommand<TextureConvertParameters>
40  {
41  public TextureConvertCommand()
42  {
43  }
44 
45  public TextureConvertCommand(string url, TextureConvertParameters description)
46  : base(url, description)
47  {
48  }
49 
50  public override System.Collections.Generic.IEnumerable<ObjectUrl> GetInputFiles()
51  {
52  // TODO dependency not working
53  yield return new ObjectUrl(UrlType.File, asset.SourcePathFromDisk);
54  }
55 
56  protected override Task<ResultStatus> DoCommandOverride(ICommandContext commandContext)
57  {
58  var texture = asset.Texture;
59 
60  var importResult = TextureCommandHelper.ImportAndSaveTextureImage(asset.SourcePathFromDisk, Url, texture, asset, asset.SeparateAlpha, CancellationToken, commandContext.Logger);
61 
62  return Task.FromResult(importResult);
63  }
64 
65  protected override void ComputeAssemblyHash(BinarySerializationWriter writer)
66  {
67  writer.Write(DataSerializer.BinaryFormatVersion);
68 
69  // Since Image format is quite stable, we want to manually control it's assembly hash here
70  writer.Write(1);
71  }
72  }
73  }
74 
75 
76  /// <summary>
77  /// Parameters used for converting/processing the texture in the storage.
78  /// </summary>
79  [DataContract]
81  {
83  {
84  }
85 
87  UFile sourcePathFromDisk,
88  TextureAsset texture,
89  PlatformType platform,
90  GraphicsPlatform graphicsPlatform,
91  GraphicsProfile graphicsProfile,
92  TextureQuality textureQuality,
93  bool separateAlpha)
94  {
95  SourcePathFromDisk = sourcePathFromDisk;
96  Texture = texture;
97  Platform = platform;
98  GraphicsPlatform = graphicsPlatform;
99  GraphicsProfile = graphicsProfile;
100  TextureQuality = textureQuality;
101  SeparateAlpha = separateAlpha;
102  }
103 
105 
107 
109 
111 
113 
115 
116  public bool SeparateAlpha;
117  }
118 }
PlatformType Platform
Gets or sets the target platform for compiler is being used for.
Result of a compilation of assets when using IAssetCompiler.Compile
PlatformType
Describes the platform operating system.
Definition: PlatformType.cs:9
GraphicsPlatform
The graphics platform.
A command processing an Asset.
Definition: AssetCommand.cs:11
Implements SerializationStream as a binary writer.
TextureQuality
The desired texture quality.
The context used when compiling an asset in a Package.
TextureConvertParameters(UFile sourcePathFromDisk, TextureAsset texture, PlatformType platform, GraphicsPlatform graphicsPlatform, GraphicsProfile graphicsProfile, TextureQuality textureQuality, bool separateAlpha)
Parameters used for converting/processing the texture in the storage.
Platform specific queries and functions.
Definition: Platform.cs:15
GraphicsProfile
Identifies the set of supported devices for the demo based on device capabilities.
Defines a normalized file path. See UPath for details. This class cannot be inherited.
Definition: UFile.cs:13
Base class for texture resources.
Definition: Texture.cs:38