3
0

PresetSettings.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. #include <BuilderSettings/PresetSettings.h>
  9. #include <Processing/PixelFormatInfo.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. namespace ImageProcessingAtom
  12. {
  13. PresetSettings::PresetSettings()
  14. {
  15. }
  16. PresetSettings::PresetSettings(const PresetSettings& other)
  17. {
  18. DeepCopyMembers(other);
  19. }
  20. void PresetSettings::Reflect(AZ::ReflectContext* context)
  21. {
  22. AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
  23. if (serialize)
  24. {
  25. serialize->Class<PresetSettings>()
  26. ->Version(2)
  27. ->Field("UUID", &PresetSettings::m_uuid)
  28. ->Field("Name", &PresetSettings::m_name)
  29. ->Field("Description", &PresetSettings::m_description)
  30. ->Field("GenerateIBLOnly", &PresetSettings::m_generateIBLOnly)
  31. ->Field("RGB_Weight", &PresetSettings::m_rgbWeight)
  32. ->Field("SourceColor", &PresetSettings::m_srcColorSpace)
  33. ->Field("DestColor", &PresetSettings::m_destColorSpace)
  34. ->Field("FileMasks", &PresetSettings::m_fileMasks)
  35. ->Field("SuppressEngineReduce", &PresetSettings::m_suppressEngineReduce)
  36. ->Field("PixelFormat", &PresetSettings::m_pixelFormat)
  37. ->Field("PixelFormatAlpha", &PresetSettings::m_pixelFormatAlpha)
  38. ->Field("DiscardAlpha", &PresetSettings::m_discardAlpha)
  39. ->Field("MaxTextureSize", &PresetSettings::m_maxTextureSize)
  40. ->Field("MinTextureSize", &PresetSettings::m_minTextureSize)
  41. ->Field("IsPowerOf2", &PresetSettings::m_isPowerOf2)
  42. ->Field("SizeReduceLevel", &PresetSettings::m_sizeReduceLevel)
  43. ->Field("GlossFromNormal", &PresetSettings::m_glossFromNormals)
  44. ->Field("MipRenormalize", &PresetSettings::m_isMipRenormalize)
  45. ->Field("NumberResidentMips", &PresetSettings::m_numResidentMips)
  46. ->Field("Swizzle", &PresetSettings::m_swizzle)
  47. ->Field("CubemapSettings", &PresetSettings::m_cubemapSetting)
  48. ->Field("MipMapSetting", &PresetSettings::m_mipmapSetting)
  49. ->Field("OutputTypeHandling", &PresetSettings::m_outputTypeHandling)
  50. ;
  51. serialize->Enum<RGBWeight>()
  52. ->Value("Uniform", RGBWeight::uniform)
  53. ->Value("Luminance", RGBWeight::luminance)
  54. ->Value("CIEXYZ", RGBWeight::ciexyz)
  55. ;
  56. serialize->Enum<ColorSpace>()
  57. ->Value("Linear", ColorSpace::linear)
  58. ->Value("sRGB", ColorSpace::sRGB)
  59. ->Value("Auto", ColorSpace::autoSelect)
  60. ;
  61. serialize->Enum<CubemapFilterType>()
  62. ->Value("Disc", CubemapFilterType::disc)
  63. ->Value("Cone", CubemapFilterType::cone)
  64. ->Value("Cosine", CubemapFilterType::cosine)
  65. ->Value("Gaussian", CubemapFilterType::gaussian)
  66. ->Value("CosinePower", CubemapFilterType::cosine_power)
  67. ->Value("GGX", CubemapFilterType::ggx)
  68. ;
  69. serialize->Enum<MipGenType>()
  70. ->Value("Point", MipGenType::point)
  71. ->Value("Box", MipGenType::box)
  72. ->Value("Triangle", MipGenType::triangle)
  73. ->Value("Quadratic", MipGenType::quadratic)
  74. ->Value("Gaussian", MipGenType::gaussian)
  75. ->Value("BlackmanHarris", MipGenType::blackmanHarris)
  76. ->Value("KaiserSinc", MipGenType::kaiserSinc)
  77. ;
  78. serialize->Enum<EPixelFormat>()
  79. ->Value("R8G8B8A8", EPixelFormat::ePixelFormat_R8G8B8A8)
  80. ->Value("R8G8B8X8", EPixelFormat::ePixelFormat_R8G8B8X8)
  81. ->Value("R8G8", EPixelFormat::ePixelFormat_R8G8)
  82. ->Value("R8", EPixelFormat::ePixelFormat_R8)
  83. ->Value("A8", EPixelFormat::ePixelFormat_A8)
  84. ->Value("R16G16B16A16", EPixelFormat::ePixelFormat_R16G16B16A16)
  85. ->Value("R16G16", EPixelFormat::ePixelFormat_R16G16)
  86. ->Value("R16", EPixelFormat::ePixelFormat_R16)
  87. ->Value("ASTC_4x4", EPixelFormat::ePixelFormat_ASTC_4x4)
  88. ->Value("ASTC_5x4", EPixelFormat::ePixelFormat_ASTC_5x4)
  89. ->Value("ASTC_5x5", EPixelFormat::ePixelFormat_ASTC_5x5)
  90. ->Value("ASTC_6x5", EPixelFormat::ePixelFormat_ASTC_6x5)
  91. ->Value("ASTC_6x6", EPixelFormat::ePixelFormat_ASTC_6x6)
  92. ->Value("ASTC_8x5", EPixelFormat::ePixelFormat_ASTC_8x5)
  93. ->Value("ASTC_8x6", EPixelFormat::ePixelFormat_ASTC_8x6)
  94. ->Value("ASTC_8x8", EPixelFormat::ePixelFormat_ASTC_8x8)
  95. ->Value("ASTC_10x5", EPixelFormat::ePixelFormat_ASTC_10x5)
  96. ->Value("ASTC_10x6", EPixelFormat::ePixelFormat_ASTC_10x6)
  97. ->Value("ASTC_10x8", EPixelFormat::ePixelFormat_ASTC_10x8)
  98. ->Value("ASTC_10x10", EPixelFormat::ePixelFormat_ASTC_10x10)
  99. ->Value("ASTC_12x10", EPixelFormat::ePixelFormat_ASTC_12x10)
  100. ->Value("ASTC_12x12", EPixelFormat::ePixelFormat_ASTC_12x12)
  101. ->Value("BC1", EPixelFormat::ePixelFormat_BC1)
  102. ->Value("BC1a", EPixelFormat::ePixelFormat_BC1a)
  103. ->Value("BC3", EPixelFormat::ePixelFormat_BC3)
  104. ->Value("BC3t", EPixelFormat::ePixelFormat_BC3t)
  105. ->Value("BC4", EPixelFormat::ePixelFormat_BC4)
  106. ->Value("BC4s", EPixelFormat::ePixelFormat_BC4s)
  107. ->Value("BC5", EPixelFormat::ePixelFormat_BC5)
  108. ->Value("BC5s", EPixelFormat::ePixelFormat_BC5s)
  109. ->Value("BC6UH", EPixelFormat::ePixelFormat_BC6UH)
  110. ->Value("BC7", EPixelFormat::ePixelFormat_BC7)
  111. ->Value("BC7t", EPixelFormat::ePixelFormat_BC7t)
  112. ->Value("R9G9B9E5", EPixelFormat::ePixelFormat_R9G9B9E5)
  113. ->Value("R32G32B32A32F", EPixelFormat::ePixelFormat_R32G32B32A32F)
  114. ->Value("R32G32F", EPixelFormat::ePixelFormat_R32G32F)
  115. ->Value("R32F", EPixelFormat::ePixelFormat_R32F)
  116. ->Value("R16G16B16A16F", EPixelFormat::ePixelFormat_R16G16B16A16F)
  117. ->Value("R16G16F", EPixelFormat::ePixelFormat_R16G16F)
  118. ->Value("R16F", EPixelFormat::ePixelFormat_R16F)
  119. ->Value("B8G8R8A8", EPixelFormat::ePixelFormat_B8G8R8A8)
  120. ->Value("R8G8B8", EPixelFormat::ePixelFormat_R8G8B8)
  121. ->Value("B8G8R8", EPixelFormat::ePixelFormat_B8G8R8)
  122. ->Value("R32", EPixelFormat::ePixelFormat_R32)
  123. ->Value("Unknown", EPixelFormat::ePixelFormat_Unknown)
  124. ;
  125. serialize->Enum<OutputTypeHandling>()
  126. ->Value("Default", OutputTypeHandling::UseSpecifiedOutputType)
  127. ->Value("UseInputFormat", OutputTypeHandling::UseInputFormat)
  128. ;
  129. }
  130. }
  131. PresetSettings& PresetSettings::operator= (const PresetSettings& other)
  132. {
  133. DeepCopyMembers(other);
  134. return *this;
  135. }
  136. bool PresetSettings::operator==(const PresetSettings& other) const
  137. {
  138. bool arePointersEqual = true;
  139. ///////
  140. // MipMap Settings
  141. //////
  142. // If both pointers are allocated...
  143. if (m_mipmapSetting && other.m_mipmapSetting)
  144. {
  145. // If the allocated values are different...
  146. if (*m_mipmapSetting != *other.m_mipmapSetting)
  147. {
  148. arePointersEqual = false;
  149. }
  150. }
  151. // Otherwise, one or both pointers are un-allocated.
  152. // If only one pointer is allocated (via unequivalency)...
  153. else if (m_mipmapSetting != other.m_mipmapSetting)
  154. {
  155. arePointersEqual = false;
  156. }
  157. ///////
  158. // CubeMap Settings
  159. //////
  160. // If both pointers are allocated...
  161. if (m_cubemapSetting && other.m_cubemapSetting)
  162. {
  163. // If the allocated values are different...
  164. if (*m_cubemapSetting != *other.m_cubemapSetting)
  165. {
  166. arePointersEqual = false;
  167. }
  168. }
  169. // Otherwise, one or both pointers are un-allocated.
  170. // If only one pointer is allocated (via unequivalency)...
  171. else if (m_cubemapSetting != other.m_cubemapSetting)
  172. {
  173. arePointersEqual = false;
  174. }
  175. return
  176. arePointersEqual &&
  177. m_uuid == other.m_uuid &&
  178. m_name == other.m_name &&
  179. m_description == other.m_description &&
  180. m_generateIBLOnly == other.m_generateIBLOnly &&
  181. m_rgbWeight == other.m_rgbWeight &&
  182. m_srcColorSpace == other.m_srcColorSpace &&
  183. m_destColorSpace == other.m_destColorSpace &&
  184. m_fileMasks == other.m_fileMasks &&
  185. m_suppressEngineReduce == other.m_suppressEngineReduce &&
  186. m_pixelFormat == other.m_pixelFormat &&
  187. m_pixelFormatAlpha == other.m_pixelFormatAlpha &&
  188. m_discardAlpha == other.m_discardAlpha &&
  189. m_minTextureSize == other.m_minTextureSize &&
  190. m_maxTextureSize == other.m_maxTextureSize &&
  191. m_isPowerOf2 == other.m_isPowerOf2 &&
  192. m_sizeReduceLevel == other.m_sizeReduceLevel &&
  193. m_glossFromNormals == other.m_glossFromNormals &&
  194. m_swizzle == other.m_swizzle &&
  195. m_isMipRenormalize == other.m_isMipRenormalize &&
  196. m_numResidentMips == other.m_numResidentMips &&
  197. m_outputTypeHandling == other.m_outputTypeHandling
  198. ;
  199. }
  200. void PresetSettings::DeepCopyMembers(const PresetSettings& other)
  201. {
  202. if (this != &other)
  203. {
  204. if (other.m_mipmapSetting)
  205. {
  206. m_mipmapSetting = AZStd::make_unique<MipmapSettings>(*other.m_mipmapSetting);
  207. }
  208. if (other.m_cubemapSetting)
  209. {
  210. m_cubemapSetting = AZStd::make_unique<CubemapSettings>(*other.m_cubemapSetting);
  211. }
  212. m_uuid = other.m_uuid;
  213. m_name = other.m_name;
  214. m_description = other.m_description;
  215. m_generateIBLOnly = other.m_generateIBLOnly;
  216. m_rgbWeight = other.m_rgbWeight;
  217. m_srcColorSpace = other.m_srcColorSpace;
  218. m_destColorSpace = other.m_destColorSpace;
  219. m_fileMasks = other.m_fileMasks;
  220. m_suppressEngineReduce = other.m_suppressEngineReduce;
  221. m_pixelFormat = other.m_pixelFormat;
  222. m_pixelFormatAlpha = other.m_pixelFormatAlpha;
  223. m_discardAlpha = other.m_discardAlpha;
  224. m_minTextureSize = other.m_minTextureSize;
  225. m_maxTextureSize = other.m_maxTextureSize;
  226. m_isPowerOf2 = other.m_isPowerOf2;
  227. m_sizeReduceLevel = other.m_sizeReduceLevel;
  228. m_glossFromNormals = other.m_glossFromNormals;
  229. m_swizzle = other.m_swizzle;
  230. m_isMipRenormalize = other.m_isMipRenormalize;
  231. m_numResidentMips = other.m_numResidentMips;
  232. m_outputTypeHandling = other.m_outputTypeHandling;
  233. }
  234. }
  235. AZ::Vector3 PresetSettings::GetColorWeight()
  236. {
  237. switch (m_rgbWeight)
  238. {
  239. case RGBWeight::uniform:
  240. return AZ::Vector3(0.3333f, 0.3334f, 0.3333f);
  241. case RGBWeight::ciexyz:
  242. return AZ::Vector3(0.2126f, 0.7152f, 0.0722f);
  243. case RGBWeight::luminance:
  244. return AZ::Vector3(0.3086f, 0.6094f, 0.0820f);
  245. default:
  246. AZ_Assert(false, "color weight value need to be added to new rgbWeight enum");
  247. return AZ::Vector3(0.3333f, 0.3334f, 0.3333f);
  248. }
  249. }
  250. void MultiplatformPresetSettings::Reflect(AZ::ReflectContext* context)
  251. {
  252. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  253. {
  254. serializeContext->Class<MultiplatformPresetSettings>()
  255. ->Version(1)
  256. ->Field("DefaultPreset", &MultiplatformPresetSettings::m_defaultPreset)
  257. ->Field("PlatformsPresets", &MultiplatformPresetSettings::m_presets)
  258. ;
  259. }
  260. }
  261. const PresetSettings* MultiplatformPresetSettings::GetPreset(const PlatformName& platform) const
  262. {
  263. auto itr = m_presets.find(platform);
  264. if (itr != m_presets.end())
  265. {
  266. return &itr->second;
  267. }
  268. return &m_defaultPreset;
  269. }
  270. const PresetSettings& MultiplatformPresetSettings::GetDefaultPreset() const
  271. {
  272. return m_defaultPreset;
  273. }
  274. void MultiplatformPresetSettings::ClearPlatformPresets()
  275. {
  276. m_presets.clear();
  277. }
  278. void MultiplatformPresetSettings::SetDefaultPreset(const PresetSettings& preset)
  279. {
  280. m_defaultPreset = preset;
  281. }
  282. void MultiplatformPresetSettings::SetPresetForPlatform(const PresetSettings& preset, const PlatformName& platform)
  283. {
  284. AZ_Assert(!platform.empty(), "Platform string shouldn't be empty");
  285. if (!platform.empty())
  286. {
  287. m_presets[platform] = preset;
  288. }
  289. }
  290. void MultiplatformPresetSettings::SetPresetName(const PresetName& name)
  291. {
  292. m_defaultPreset.m_name = name;
  293. }
  294. const PresetName& MultiplatformPresetSettings::GetPresetName() const
  295. {
  296. return m_defaultPreset.m_name;
  297. }
  298. AZ::Uuid MultiplatformPresetSettings::GetPresetId() const
  299. {
  300. return m_defaultPreset.m_uuid;
  301. }
  302. } // namespace ImageProcessingAtom