3
0

TextureSettings.h 8.9 KB

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