TextureSettings.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <BuilderSettings/ImageProcessingDefines.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <AzCore/RTTI/ReflectContext.h>
  12. #include <AzCore/Serialization/DataPatch.h>
  13. namespace ImageProcessingAtom
  14. {
  15. class TextureSettings;
  16. typedef AZStd::map<PlatformName, TextureSettings> MultiplatformTextureSettings;
  17. /**
  18. * TextureSettings is the configuration for processing one image. It contains a reference of preset and other parameters.
  19. * Some parameters are come from preset but overwrite them.
  20. * The texture settings may be different for each platform, so the different is saved as data patch per platform.
  21. * When automatically generate a new texture settings for an image file, use BuilderSettingManager::GetSuggestedPreset function to find the best preset
  22. * may fit this image, then use ApplyPreset to propagate values from preset settings to texture settings.
  23. * TextureSettings is intended to be editable for user to modify its value through texture editor tool.
  24. */
  25. class TextureSettings
  26. {
  27. public:
  28. AZ_TYPE_INFO(TextureSettings, "{980132FF-C450-425D-8AE0-BD96A8486177}");
  29. AZ_CLASS_ALLOCATOR(TextureSettings, AZ::SystemAllocator, 0);
  30. TextureSettings();
  31. /**
  32. * Returns an alpha offset value for certain mip. The alpha offset is interpolated from m_mipAlphaAdjust[]
  33. * and used for TransferAlphaCoverage only.
  34. * Check the comment of m_maintainAlphaCoverage for more detail on how it may work.
  35. */
  36. float ComputeMIPAlphaOffset(AZ::u32 mip) const;
  37. /**
  38. * Apply value of some preset settings to this texture settings
  39. */
  40. void ApplyPreset(PresetName presetName);
  41. /**
  42. * Performs a comprehensive comparison between two TextureSettings instances.
  43. * @param Reference to the settings which will be compared.
  44. * @param Optional. Serialize context. Will use global context if none is provided.
  45. * @return True, is both instances are equivalent.
  46. */
  47. bool Equals(const TextureSettings& other, AZ::SerializeContext* serializeContext = nullptr);
  48. /**
  49. * Applies texture settings to the instance (including overrides). Common settings are applied, unless specific platform is specified.
  50. * @param Reference to the settings which will be applied.
  51. * @param Optional. Applies settings as a platform override if a platform is specified.
  52. * @param Optional. Serialize context. Will use global context if none is provided.
  53. * @return Status outcome result.
  54. */
  55. StringOutcome ApplySettings(const TextureSettings& settings, const PlatformName& overridePlatform = PlatformName(), AZ::SerializeContext* serializeContext = nullptr);
  56. /**
  57. * Gets platform-specific texture settings obtained from the base settings version of a pre-loaded TextureSettings instance.
  58. * @param Name of platform to get the settings from.
  59. * @param Base TextureSettings which we will get overrides from.
  60. * @param Output TextureSettings which will contain the result of the function.
  61. * @param Optional. Serialize context. Will use global context if none is provided.
  62. * @return Status outcome result.
  63. */
  64. static StringOutcome GetPlatformSpecificTextureSetting(const PlatformName& platformName, const TextureSettings& baseTextureSettings, TextureSettings& textureSettingsOut, AZ::SerializeContext* serializeContext = nullptr);
  65. static void Reflect(AZ::ReflectContext* context);
  66. /**
  67. * Loads base texture settings obtained from ".assetinfo" file
  68. * @param FilePath absolute/relative path of the ".assetinfo" file.
  69. * @param Output TextureSettings which contain the result of the function, it may contains platform-specific overrides.
  70. * @param Optional. Serialize context. Will use global context if none is provided.
  71. * @return Status outcome result.
  72. */
  73. static StringOutcome LoadTextureSetting(const AZStd::string& filepath, TextureSettings& textureSettingPtrOut, AZ::SerializeContext* serializeContext = nullptr);
  74. /**
  75. * Writes base texture settings to a ".assetinfo" file (modern setting)
  76. * @param FilePath absolute/relative path of the ".assetinfo" file.
  77. * @param TextureSetting to be written on the disk, it may contains platform-specific overrides.
  78. * @param Optional. Serialize context. Will use global context if none is provided.
  79. * @return Status outcome result.
  80. */
  81. static StringOutcome WriteTextureSetting(const AZStd::string& filepath, TextureSettings& textureSetting, AZ::SerializeContext* serializeContext = nullptr);
  82. // Generates a MultiplatformTextureSettings collection with default texture settings for all
  83. static MultiplatformTextureSettings GenerateDefaultMultiplatformTextureSettings(const AZStd::string& imageFilepath);
  84. /**
  85. * Generates a TextureSetting instance of a particular image file for each supported platform.
  86. * @param filepath - A path to the texture file.
  87. * @param canOverridePreset - Returns whether the preset can be overriden. Will return false if the preset was selecting from a settings file created by the user.
  88. * @param serializeContext - Optional. Serialize context used for reflection/serialization
  89. * @return - The collection of TextureSetting instances. If error occurs, a default MultiplatformTextureSettings is returned (see GenerateDefaultMultiplatformTextureSettings()).
  90. */
  91. static const MultiplatformTextureSettings GetMultiplatformTextureSetting(const AZStd::string& filepath, bool& canOverridePreset, AZ::SerializeContext* serializeContext = nullptr);
  92. /**
  93. * Generates a TextureSetting instance of a particular image file for each supported platform.
  94. * @param textureSettings - A reference to an already-loaded texture settings.
  95. * @param serializeContext - Optional. Serialize context used for reflection/serialization
  96. * @return - The collection of TextureSetting instances. If error occurs, a default MultiplatformTextureSettings is returned (see GenerateDefaultMultiplatformTextureSettings()).
  97. */
  98. static const MultiplatformTextureSettings GetMultiplatformTextureSetting(const TextureSettings& textureSettings, AZ::SerializeContext* serializeContext = nullptr);
  99. static const char* ExtensionName;
  100. static const size_t s_MaxMipMaps = 6;
  101. // uuid of selected preset for this texture
  102. // We are deprecating preset UUID and switching to preset name as an unique id
  103. AZ::Uuid m_presetId;
  104. PresetName m_preset;
  105. // texture size reduce level. the value of this variable will override the same variable in PresetSettings
  106. unsigned int m_sizeReduceLevel;
  107. // "ser". Whether to enable suppress reduce resolution (m_sizeReduceLevel) during loading, 0(default)
  108. // the value of this variable will override the same variable in PresetSettings
  109. bool m_suppressEngineReduce;
  110. //enable generate mipmap or not
  111. bool m_enableMipmap;
  112. //"mc". not used in rc.ini. experimental
  113. //maybe relate to http://the-witness.net/news/2010/09/computing-alpha-mipmaps/
  114. bool m_maintainAlphaCoverage;
  115. // "M", adjust mipalpha, 0..50=normal..100. associate with ComputeMIPAlphaOffset function
  116. // only useful if m_maintainAlphaCoverage set to true.
  117. // This data type MUST be an AZStd::vector, even though we treat is as a fixed array. This is due to a limitation
  118. // during AZ::DataPatch serialization, where an element is allocated one by one while extending the container..
  119. AZStd::vector<AZ::u32> m_mipAlphaAdjust;
  120. MipGenEvalType m_mipGenEval;
  121. MipGenType m_mipGenType;
  122. private:
  123. // Platform overrides in form of DataPatch. Each entry is a patch for a specified platform.
  124. // This map is used to generate TextureSettings with overridden values. The map is empty if
  125. // the instance is for platform-specific settings.
  126. AZStd::map<PlatformName, AZ::DataPatch> m_platfromOverrides;
  127. // The platform which these settings override.
  128. // Blank if the instance is for common settings.
  129. PlatformName m_overridingPlatform;
  130. // Comparison operators only compare the base settings, they do not compare overrides.
  131. // For a comprehensive equality comparison, use Equals() function.
  132. bool operator==(const TextureSettings& other) const;
  133. bool operator!=(const TextureSettings& other) const;
  134. };
  135. } // namespace ImageProcessingAtom