RenderStates.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  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 <Atom/RHI.Reflect/RenderStates.h>
  9. #include <AzCore/Preprocessor/Enum.h>
  10. #include <AzCore/Preprocessor/EnumReflectUtils.h>
  11. #include <AzCore/RTTI/BehaviorContext.h>
  12. #include <AzCore/RTTI/TypeInfo.h>
  13. #include <AzCore/Serialization/EditContext.h>
  14. #include <AzCore/Serialization/SerializeContext.h>
  15. #include <AzCore/Utils/TypeHash.h>
  16. namespace AZ::RHI
  17. {
  18. AZ_ENUM_DEFINE_REFLECT_UTILITIES(CullMode);
  19. AZ_ENUM_DEFINE_REFLECT_UTILITIES(FillMode);
  20. AZ_ENUM_DEFINE_REFLECT_UTILITIES(DepthWriteMask);
  21. AZ_ENUM_DEFINE_REFLECT_UTILITIES(StencilOp);
  22. AZ_ENUM_DEFINE_REFLECT_UTILITIES(BlendFactor);
  23. AZ_ENUM_DEFINE_REFLECT_UTILITIES(BlendOp);
  24. void ReflectRenderStateEnums(ReflectContext* context)
  25. {
  26. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  27. {
  28. CullModeReflect(*serializeContext);
  29. FillModeReflect(*serializeContext);
  30. DepthWriteMaskReflect(*serializeContext);
  31. StencilOpReflect(*serializeContext);
  32. BlendFactorReflect(*serializeContext);
  33. BlendOpReflect(*serializeContext);
  34. }
  35. if (auto* behaviorContext = azrtti_cast<BehaviorContext*>(context))
  36. {
  37. CullModeReflect(*behaviorContext);
  38. FillModeReflect(*behaviorContext);
  39. DepthWriteMaskReflect(*behaviorContext);
  40. StencilOpReflect(*behaviorContext);
  41. BlendFactorReflect(*behaviorContext);
  42. BlendOpReflect(*behaviorContext);
  43. }
  44. }
  45. template<typename T>
  46. void MergeValue(T& resultValue, const T& valueToMerge, const T& invalidValue)
  47. {
  48. resultValue = (valueToMerge != invalidValue) ? valueToMerge : resultValue;
  49. }
  50. #define RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, prop) MergeValue(result.prop, stateToMerge.prop, invalidState.prop)
  51. void MergeStateInto(const RasterState& stateToMerge, RasterState& result)
  52. {
  53. const RasterState& invalidState = GetInvalidRasterState();
  54. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_fillMode);
  55. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_cullMode);
  56. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_depthBias);
  57. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_depthBiasClamp);
  58. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_depthBiasSlopeScale);
  59. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_multisampleEnable);
  60. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_depthClipEnable);
  61. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_conservativeRasterEnable);
  62. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_forcedSampleCount);
  63. }
  64. void MergeStateInto(const StencilOpState& stateToMerge, StencilOpState& result)
  65. {
  66. const StencilOpState& invalidState = GetInvalidStencilOpState();
  67. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_failOp);
  68. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_passOp);
  69. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_depthFailOp);
  70. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_func);
  71. }
  72. void MergeStateInto(const StencilState& stateToMerge, StencilState& result)
  73. {
  74. const StencilState& invalidState = GetInvalidStencilState();
  75. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_enable);
  76. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_readMask);
  77. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_writeMask);
  78. MergeStateInto(stateToMerge.m_backFace, result.m_backFace);
  79. MergeStateInto(stateToMerge.m_frontFace, result.m_frontFace);
  80. }
  81. void MergeStateInto(const DepthState& stateToMerge, DepthState& result)
  82. {
  83. const DepthState& invalidState = GetInvalidDepthState();
  84. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_enable);
  85. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_writeMask);
  86. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_func);
  87. }
  88. void MergeStateInto(const DepthStencilState& stateToMerge, DepthStencilState& result)
  89. {
  90. MergeStateInto(stateToMerge.m_depth, result.m_depth);
  91. MergeStateInto(stateToMerge.m_stencil, result.m_stencil);
  92. }
  93. void MergeStateInto(const TargetBlendState& stateToMerge, TargetBlendState& result)
  94. {
  95. const TargetBlendState& invalidState = GetInvalidTargetBlendState();
  96. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_enable);
  97. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_writeMask);
  98. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_blendSource);
  99. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_blendDest);
  100. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_blendOp);
  101. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_blendAlphaSource);
  102. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_blendAlphaDest);
  103. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_blendAlphaOp);
  104. }
  105. void MergeStateInto(const BlendState& stateToMerge, BlendState& result)
  106. {
  107. const BlendState& invalidState = GetInvalidBlendState();
  108. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_alphaToCoverageEnable);
  109. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_independentBlendEnable);
  110. for (uint32_t i = 0; i < Limits::Pipeline::AttachmentColorCountMax; ++i)
  111. {
  112. MergeStateInto(stateToMerge.m_targets[i], result.m_targets[i]);
  113. }
  114. }
  115. void MergeStateInto(const MultisampleState& stateToMerge, MultisampleState& result)
  116. {
  117. const MultisampleState& invalidState = GetInvalidMultisampleState();
  118. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_customPositionsCount);
  119. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_samples);
  120. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_quality);
  121. for (uint32_t positionIndex = 0; positionIndex < Limits::Pipeline::MultiSampleCustomLocationsCountMax; ++positionIndex)
  122. {
  123. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_customPositions[positionIndex].m_x);
  124. RENDER_STATES_MERGE_STATE_PROPERTY(result, stateToMerge, invalidState, m_customPositions[positionIndex].m_y);
  125. }
  126. }
  127. void MergeStateInto(const RenderStates& statesToMerge, RenderStates& result)
  128. {
  129. MergeStateInto(statesToMerge.m_multisampleState, result.m_multisampleState);
  130. MergeStateInto(statesToMerge.m_rasterState, result.m_rasterState);
  131. MergeStateInto(statesToMerge.m_blendState, result.m_blendState);
  132. MergeStateInto(statesToMerge.m_depthStencilState, result.m_depthStencilState);
  133. }
  134. #undef RENDER_STATES_MERGE_STATE_PROPERTY
  135. const RasterState& GetInvalidRasterState()
  136. {
  137. static const RasterState invalidState
  138. {
  139. FillMode::Invalid, // m_fillMode
  140. CullMode::Invalid, // m_cullMode
  141. RenderStates_InvalidInt, // m_depthBias
  142. RenderStates_InvalidFloat, // m_depthBiasClamp
  143. RenderStates_InvalidFloat, // m_depthBiasSlopeScale
  144. RenderStates_InvalidBool, // m_multisampleEnable
  145. RenderStates_InvalidBool, // m_depthClipEnable
  146. RenderStates_InvalidBool, // m_conservativeRasterEnable
  147. RenderStates_InvalidUInt // m_forcedSampleCount
  148. };
  149. return invalidState;
  150. }
  151. const DepthState& GetInvalidDepthState()
  152. {
  153. static const DepthState invalidState
  154. {
  155. RenderStates_InvalidBool, // m_enable
  156. DepthWriteMask::Invalid, // m_writeMask
  157. ComparisonFunc::Invalid // m_func
  158. };
  159. return invalidState;
  160. }
  161. const StencilOpState& GetInvalidStencilOpState()
  162. {
  163. static const StencilOpState invalidState
  164. {
  165. StencilOp::Invalid, // m_failOp
  166. StencilOp::Invalid, // m_depthFailOp
  167. StencilOp::Invalid, // m_passOp
  168. ComparisonFunc::Invalid // m_func
  169. };
  170. return invalidState;
  171. }
  172. const StencilState& GetInvalidStencilState()
  173. {
  174. static const StencilState invalidState
  175. {
  176. RenderStates_InvalidBool, // m_enable
  177. RenderStates_InvalidUInt, // m_readMask
  178. RenderStates_InvalidUInt, // m_writeMask
  179. GetInvalidStencilOpState(), // m_frontFace
  180. GetInvalidStencilOpState() // m_backFace
  181. };
  182. return invalidState;
  183. }
  184. const DepthStencilState& GetInvalidDepthStencilState()
  185. {
  186. static const DepthStencilState invalidState
  187. {
  188. GetInvalidDepthState(), // m_depth
  189. GetInvalidStencilState() // m_stencil
  190. };
  191. return invalidState;
  192. }
  193. const TargetBlendState& GetInvalidTargetBlendState()
  194. {
  195. static constexpr TargetBlendState invalidState
  196. {
  197. RenderStates_InvalidBool, // m_enable
  198. RenderStates_InvalidUInt, // m_writeMask
  199. BlendFactor::Invalid, // m_blendSource
  200. BlendFactor::Invalid, // m_blendDest
  201. BlendOp::Invalid, // m_blendOp
  202. BlendFactor::Invalid, // m_blendAlphaSource
  203. BlendFactor::Invalid, // m_blendAlphaDest
  204. BlendOp::Invalid // m_blendAlphaOp
  205. };
  206. return invalidState;
  207. }
  208. const BlendState& GetInvalidBlendState()
  209. {
  210. auto FillTargetBlendState = []()->AZStd::array<TargetBlendState, Limits::Pipeline::AttachmentColorCountMax>
  211. {
  212. AZStd::array<TargetBlendState, Limits::Pipeline::AttachmentColorCountMax> targets;
  213. targets.fill(GetInvalidTargetBlendState());
  214. return targets;
  215. };
  216. static const BlendState invalidState
  217. {
  218. RenderStates_InvalidBool, // m_alphaToCoverageEnable
  219. RenderStates_InvalidBool, // m_independentBlendEnable
  220. FillTargetBlendState() // m_targets
  221. };
  222. return invalidState;
  223. }
  224. const MultisampleState& GetInvalidMultisampleState()
  225. {
  226. auto FillInvalidState = []()->MultisampleState
  227. {
  228. MultisampleState invalidState;
  229. SamplePosition invalidSamplePosition;
  230. // Note SamplePosition has assertion to block invalid values in its non-default constructor.
  231. invalidSamplePosition.m_x = Limits::Pipeline::MultiSampleCustomLocationGridSize;
  232. invalidSamplePosition.m_y = Limits::Pipeline::MultiSampleCustomLocationGridSize;
  233. invalidState.m_customPositions.fill(invalidSamplePosition);
  234. invalidState.m_customPositionsCount = RenderStates_InvalidUInt;
  235. invalidState.m_samples = RenderStates_InvalidUInt16;
  236. invalidState.m_quality = RenderStates_InvalidUInt16;
  237. return invalidState;
  238. };
  239. // Restricted by its constructors, MultisampleState doesnt support argument list construction.
  240. static const MultisampleState invalidState = FillInvalidState();
  241. return invalidState;
  242. }
  243. const RenderStates& GetInvalidRenderStates()
  244. {
  245. static const RenderStates invalidStates
  246. {
  247. GetInvalidMultisampleState(), // m_multisampleState
  248. GetInvalidRasterState(), // m_rasterState
  249. GetInvalidBlendState(), // m_blendState
  250. GetInvalidDepthStencilState() // m_depthStencilState
  251. };
  252. return invalidStates;
  253. }
  254. HashValue64 RenderStates::GetHash(HashValue64 seed) const
  255. {
  256. return TypeHash64(*this, seed);
  257. }
  258. DepthStencilState DepthStencilState::CreateDepth()
  259. {
  260. DepthStencilState descriptor;
  261. descriptor.m_depth.m_func = ComparisonFunc::LessEqual;
  262. return descriptor;
  263. }
  264. DepthStencilState DepthStencilState::CreateReverseDepth()
  265. {
  266. DepthStencilState descriptor;
  267. descriptor.m_depth.m_func = ComparisonFunc::GreaterEqual;
  268. return descriptor;
  269. }
  270. DepthStencilState DepthStencilState::CreateDisabled()
  271. {
  272. DepthStencilState descriptor;
  273. descriptor.m_depth.m_enable = false;
  274. return descriptor;
  275. }
  276. void RasterState::Reflect(ReflectContext* context)
  277. {
  278. if (auto serializeContext = azrtti_cast<SerializeContext*>(context))
  279. {
  280. serializeContext->Class<RasterState>()
  281. ->Version(1)
  282. ->Field("depthBias", &RasterState::m_depthBias)
  283. ->Field("depthBiasClamp", &RasterState::m_depthBiasClamp)
  284. ->Field("depthBiasSlopeScale", &RasterState::m_depthBiasSlopeScale)
  285. ->Field("fillMode", &RasterState::m_fillMode)
  286. ->Field("cullMode", &RasterState::m_cullMode)
  287. ->Field("multisampleEnable", &RasterState::m_multisampleEnable)
  288. ->Field("depthClipEnable", &RasterState::m_depthClipEnable)
  289. ->Field("conservativeRasterEnable", &RasterState::m_conservativeRasterEnable)
  290. ->Field("forcedSampleCount", &RasterState::m_forcedSampleCount)
  291. ;
  292. if (auto editContext = serializeContext->GetEditContext())
  293. {
  294. editContext->Class<RasterState>("RasterState", "")
  295. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  296. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  297. ->DataElement(AZ::Edit::UIHandlers::Default, &RasterState::m_depthBias, "Depth Bias", "")
  298. ->DataElement(AZ::Edit::UIHandlers::Default, &RasterState::m_depthBiasClamp, "Depth Bias Clamp", "")
  299. ->DataElement(AZ::Edit::UIHandlers::Default, &RasterState::m_depthBiasSlopeScale, "Depth Bias Slope Scale", "")
  300. ->DataElement(AZ::Edit::UIHandlers::Default, &RasterState::m_fillMode, "Fill Mode", "")
  301. ->Attribute(AZ::Edit::Attributes::EnumValues, AZ::Edit::GetEnumConstantsFromTraits<FillMode>())
  302. ->DataElement(AZ::Edit::UIHandlers::Default, &RasterState::m_cullMode, "Cull Mode", "")
  303. ->Attribute(AZ::Edit::Attributes::EnumValues, AZ::Edit::GetEnumConstantsFromTraits<CullMode>())
  304. ->DataElement(AZ::Edit::UIHandlers::Default, &RasterState::m_multisampleEnable, "Multisample Enable", "")
  305. ->DataElement(AZ::Edit::UIHandlers::Default, &RasterState::m_depthClipEnable, "Depth Clip Enable", "")
  306. ->DataElement(AZ::Edit::UIHandlers::Default, &RasterState::m_conservativeRasterEnable, "Conservative Raster Enable", "")
  307. ->DataElement(AZ::Edit::UIHandlers::Default, &RasterState::m_forcedSampleCount, "Forced Sample Count", "")
  308. ;
  309. }
  310. }
  311. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  312. {
  313. behaviorContext->Class<RasterState>("RasterState")
  314. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  315. ->Attribute(AZ::Script::Attributes::Category, "RHI")
  316. ->Attribute(AZ::Script::Attributes::Module, "rhi")
  317. ->Constructor()
  318. ->Constructor<const RasterState&>()
  319. ->Property("depthBias", BehaviorValueProperty(&RasterState::m_depthBias))
  320. ->Property("depthBiasClamp", BehaviorValueProperty(&RasterState::m_depthBiasClamp))
  321. ->Property("depthBiasSlopeScale", BehaviorValueProperty(&RasterState::m_depthBiasSlopeScale))
  322. ->Property("fillMode", BehaviorValueProperty(&RasterState::m_fillMode))
  323. ->Property("cullMode", BehaviorValueProperty(&RasterState::m_cullMode))
  324. ->Property("multisampleEnable", BehaviorValueProperty(&RasterState::m_multisampleEnable))
  325. ->Property("depthClipEnable", BehaviorValueProperty(&RasterState::m_depthClipEnable))
  326. ->Property("conservativeRasterEnable", BehaviorValueProperty(&RasterState::m_conservativeRasterEnable))
  327. ->Property("forcedSampleCount", BehaviorValueProperty(&RasterState::m_forcedSampleCount))
  328. ;
  329. }
  330. }
  331. void StencilOpState::Reflect(ReflectContext* context)
  332. {
  333. if (auto serializeContext = azrtti_cast<SerializeContext*>(context))
  334. {
  335. serializeContext->Class<StencilOpState>()
  336. ->Version(1)
  337. ->Field("failOp", &StencilOpState::m_failOp)
  338. ->Field("depthFailOp", &StencilOpState::m_depthFailOp)
  339. ->Field("passOp", &StencilOpState::m_passOp)
  340. ->Field("func", &StencilOpState::m_func)
  341. ;
  342. if (auto editContext = serializeContext->GetEditContext())
  343. {
  344. editContext->Class<StencilOpState>("StencilOpState", "")
  345. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  346. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  347. ->DataElement(AZ::Edit::UIHandlers::Default, &StencilOpState::m_failOp, "Fail Op", "")
  348. ->Attribute(AZ::Edit::Attributes::EnumValues, AZ::Edit::GetEnumConstantsFromTraits<StencilOp>())
  349. ->DataElement(AZ::Edit::UIHandlers::Default, &StencilOpState::m_depthFailOp, "Depth Fail Op", "")
  350. ->Attribute(AZ::Edit::Attributes::EnumValues, AZ::Edit::GetEnumConstantsFromTraits<StencilOp>())
  351. ->DataElement(AZ::Edit::UIHandlers::Default, &StencilOpState::m_passOp, "Pass Op", "")
  352. ->Attribute(AZ::Edit::Attributes::EnumValues, AZ::Edit::GetEnumConstantsFromTraits<StencilOp>())
  353. ->DataElement(AZ::Edit::UIHandlers::Default, &StencilOpState::m_func, "Func", "")
  354. ->Attribute(AZ::Edit::Attributes::EnumValues, AZ::Edit::GetEnumConstantsFromTraits<ComparisonFunc>())
  355. ;
  356. }
  357. }
  358. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  359. {
  360. behaviorContext->Class<StencilOpState>("StencilOpState")
  361. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  362. ->Attribute(AZ::Script::Attributes::Category, "RHI")
  363. ->Attribute(AZ::Script::Attributes::Module, "rhi")
  364. ->Constructor()
  365. ->Constructor<const StencilOpState&>()
  366. ->Property("failOp", BehaviorValueProperty(&StencilOpState::m_failOp))
  367. ->Property("depthFailOp", BehaviorValueProperty(&StencilOpState::m_depthFailOp))
  368. ->Property("passOp", BehaviorValueProperty(&StencilOpState::m_passOp))
  369. ->Property("func", BehaviorValueProperty(&StencilOpState::m_func))
  370. ;
  371. }
  372. }
  373. void DepthState::Reflect(ReflectContext* context)
  374. {
  375. if (auto serializeContext = azrtti_cast<SerializeContext*>(context))
  376. {
  377. serializeContext->Class<DepthState>()
  378. ->Version(1)
  379. ->Field("enable", &DepthState::m_enable)
  380. ->Field("writeMask", &DepthState::m_writeMask)
  381. ->Field("compareFunc", &DepthState::m_func)
  382. ;
  383. if (auto editContext = serializeContext->GetEditContext())
  384. {
  385. editContext->Class<DepthState>("DepthState", "")
  386. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  387. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  388. ->DataElement(AZ::Edit::UIHandlers::Default, &DepthState::m_enable, "Enable", "")
  389. ->DataElement(AZ::Edit::UIHandlers::Default, &DepthState::m_writeMask, "Write Mask", "")
  390. ->Attribute(AZ::Edit::Attributes::EnumValues, AZ::Edit::GetEnumConstantsFromTraits<DepthWriteMask>())
  391. ->DataElement(AZ::Edit::UIHandlers::Default, &DepthState::m_func, "Func", "")
  392. ->Attribute(AZ::Edit::Attributes::EnumValues, AZ::Edit::GetEnumConstantsFromTraits<ComparisonFunc>())
  393. ;
  394. }
  395. }
  396. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  397. {
  398. behaviorContext->Class<DepthState>("DepthState")
  399. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  400. ->Attribute(AZ::Script::Attributes::Category, "RHI")
  401. ->Attribute(AZ::Script::Attributes::Module, "rhi")
  402. ->Constructor()
  403. ->Constructor<const DepthState&>()
  404. ->Property("enable", BehaviorValueProperty(&DepthState::m_enable))
  405. ->Property("writeMask", BehaviorValueProperty(&DepthState::m_writeMask))
  406. ->Property("compareFunc", BehaviorValueProperty(&DepthState::m_func))
  407. ;
  408. }
  409. }
  410. void StencilState::Reflect(ReflectContext* context)
  411. {
  412. if (auto serializeContext = azrtti_cast<SerializeContext*>(context))
  413. {
  414. serializeContext->Class<StencilState>()
  415. ->Version(1)
  416. ->Field("enable", &StencilState::m_enable)
  417. ->Field("readMask", &StencilState::m_readMask)
  418. ->Field("writeMask", &StencilState::m_writeMask)
  419. ->Field("frontFace", &StencilState::m_frontFace)
  420. ->Field("backFace", &StencilState::m_backFace)
  421. ;
  422. if (auto editContext = serializeContext->GetEditContext())
  423. {
  424. editContext->Class<StencilState>("StencilState", "")
  425. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  426. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  427. ->DataElement(AZ::Edit::UIHandlers::Default, &StencilState::m_enable, "Enable", "")
  428. ->DataElement(AZ::Edit::UIHandlers::Default, &StencilState::m_readMask, "Read Mask", "")
  429. ->DataElement(AZ::Edit::UIHandlers::Default, &StencilState::m_writeMask, "Write Mask", "")
  430. ->DataElement(AZ::Edit::UIHandlers::Default, &StencilState::m_frontFace, "Front Face", "")
  431. ->DataElement(AZ::Edit::UIHandlers::Default, &StencilState::m_backFace, "Back Face", "")
  432. ;
  433. }
  434. }
  435. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  436. {
  437. behaviorContext->Class<StencilState>("StencilState")
  438. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  439. ->Attribute(AZ::Script::Attributes::Category, "RHI")
  440. ->Attribute(AZ::Script::Attributes::Module, "rhi")
  441. ->Constructor()
  442. ->Constructor<const StencilState&>()
  443. ->Property("enable", BehaviorValueProperty(&StencilState::m_enable))
  444. ->Property("readMask", BehaviorValueProperty(&StencilState::m_readMask))
  445. ->Property("writeMask", BehaviorValueProperty(&StencilState::m_writeMask))
  446. ->Property("frontFace", BehaviorValueProperty(&StencilState::m_frontFace))
  447. ->Property("backFace", BehaviorValueProperty(&StencilState::m_backFace))
  448. ;
  449. }
  450. }
  451. void DepthStencilState::Reflect(ReflectContext* context)
  452. {
  453. if (auto serializeContext = azrtti_cast<SerializeContext*>(context))
  454. {
  455. serializeContext->Class<DepthStencilState>()
  456. ->Version(1)
  457. ->Field("depth", &DepthStencilState::m_depth)
  458. ->Field("stencil", &DepthStencilState::m_stencil)
  459. ;
  460. if (auto editContext = serializeContext->GetEditContext())
  461. {
  462. editContext->Class<DepthStencilState>("DepthStencilState", "")
  463. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  464. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  465. ->DataElement(AZ::Edit::UIHandlers::Default, &DepthStencilState::m_depth, "Depth", "")
  466. ->DataElement(AZ::Edit::UIHandlers::Default, &DepthStencilState::m_stencil, "Stencil", "")
  467. ;
  468. }
  469. }
  470. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  471. {
  472. behaviorContext->Class<DepthStencilState>("DepthStencilState")
  473. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  474. ->Attribute(AZ::Script::Attributes::Category, "RHI")
  475. ->Attribute(AZ::Script::Attributes::Module, "rhi")
  476. ->Constructor()
  477. ->Constructor<const DepthStencilState&>()
  478. ->Property("depth", BehaviorValueProperty(&DepthStencilState::m_depth))
  479. ->Property("stencil", BehaviorValueProperty(&DepthStencilState::m_stencil))
  480. ;
  481. }
  482. }
  483. void TargetBlendState::Reflect(ReflectContext* context)
  484. {
  485. if (auto serializeContext = azrtti_cast<SerializeContext*>(context))
  486. {
  487. serializeContext->Class<TargetBlendState>()
  488. ->Version(1)
  489. ->Field("enable", &TargetBlendState::m_enable)
  490. ->Field("blendSource", &TargetBlendState::m_blendSource)
  491. ->Field("blendDest", &TargetBlendState::m_blendDest)
  492. ->Field("blendOp", &TargetBlendState::m_blendOp)
  493. ->Field("blendAlphaSource", &TargetBlendState::m_blendAlphaSource)
  494. ->Field("blendAlphaDest", &TargetBlendState::m_blendAlphaDest)
  495. ->Field("blendAlphaOp", &TargetBlendState::m_blendAlphaOp)
  496. ->Field("writeMask", &TargetBlendState::m_writeMask)
  497. ;
  498. if (auto editContext = serializeContext->GetEditContext())
  499. {
  500. editContext->Class<TargetBlendState>("TargetBlendState", "")
  501. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  502. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  503. ->DataElement(AZ::Edit::UIHandlers::Default, &TargetBlendState::m_enable, "Enable", "")
  504. ->DataElement(AZ::Edit::UIHandlers::Default, &TargetBlendState::m_blendSource, "Blend Source", "")
  505. ->Attribute(AZ::Edit::Attributes::EnumValues, AZ::Edit::GetEnumConstantsFromTraits<BlendFactor>())
  506. ->DataElement(AZ::Edit::UIHandlers::Default, &TargetBlendState::m_blendDest, "Blend Dest", "")
  507. ->Attribute(AZ::Edit::Attributes::EnumValues, AZ::Edit::GetEnumConstantsFromTraits<BlendFactor>())
  508. ->DataElement(AZ::Edit::UIHandlers::Default, &TargetBlendState::m_blendOp, "Blend Op", "")
  509. ->Attribute(AZ::Edit::Attributes::EnumValues, AZ::Edit::GetEnumConstantsFromTraits<BlendOp>())
  510. ->DataElement(AZ::Edit::UIHandlers::Default, &TargetBlendState::m_blendAlphaSource, "Blend Alpha Source", "")
  511. ->Attribute(AZ::Edit::Attributes::EnumValues, AZ::Edit::GetEnumConstantsFromTraits<BlendFactor>())
  512. ->DataElement(AZ::Edit::UIHandlers::Default, &TargetBlendState::m_blendAlphaDest, "Blend Alpha Dest", "")
  513. ->Attribute(AZ::Edit::Attributes::EnumValues, AZ::Edit::GetEnumConstantsFromTraits<BlendFactor>())
  514. ->DataElement(AZ::Edit::UIHandlers::Default, &TargetBlendState::m_blendAlphaOp, "Blend Alpha Op", "")
  515. ->Attribute(AZ::Edit::Attributes::EnumValues, AZ::Edit::GetEnumConstantsFromTraits<BlendOp>())
  516. ->DataElement(AZ::Edit::UIHandlers::Default, &TargetBlendState::m_writeMask, "Write Mask", "")
  517. ;
  518. }
  519. }
  520. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  521. {
  522. behaviorContext->Class<TargetBlendState>("TargetBlendState")
  523. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  524. ->Attribute(AZ::Script::Attributes::Category, "RHI")
  525. ->Attribute(AZ::Script::Attributes::Module, "rhi")
  526. ->Constructor()
  527. ->Constructor<const TargetBlendState&>()
  528. ->Property("enable", BehaviorValueProperty(&TargetBlendState::m_enable))
  529. ->Property("blendSource", BehaviorValueProperty(&TargetBlendState::m_blendSource))
  530. ->Property("blendDest", BehaviorValueProperty(&TargetBlendState::m_blendDest))
  531. ->Property("blendOp", BehaviorValueProperty(&TargetBlendState::m_blendOp))
  532. ->Property("blendAlphaSource", BehaviorValueProperty(&TargetBlendState::m_blendAlphaSource))
  533. ->Property("blendAlphaDest", BehaviorValueProperty(&TargetBlendState::m_blendAlphaDest))
  534. ->Property("blendAlphaOp", BehaviorValueProperty(&TargetBlendState::m_blendAlphaOp))
  535. ->Property("writeMask", BehaviorValueProperty(&TargetBlendState::m_writeMask))
  536. ;
  537. }
  538. }
  539. void BlendState::Reflect(ReflectContext* context)
  540. {
  541. if (auto serializeContext = azrtti_cast<SerializeContext*>(context))
  542. {
  543. serializeContext->Class<BlendState>()
  544. ->Version(1)
  545. ->Field("alphaToCoverageEnable", &BlendState::m_alphaToCoverageEnable)
  546. ->Field("independentBlendEnable", &BlendState::m_independentBlendEnable)
  547. ->Field("targets", &BlendState::m_targets)
  548. ;
  549. if (auto editContext = serializeContext->GetEditContext())
  550. {
  551. editContext->Class<BlendState>("BlendState", "")
  552. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  553. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  554. ->DataElement(AZ::Edit::UIHandlers::Default, &BlendState::m_alphaToCoverageEnable, "Alpha To Coverage Enable", "")
  555. ->DataElement(AZ::Edit::UIHandlers::Default, &BlendState::m_independentBlendEnable, "Independent Blend Enable", "")
  556. ->DataElement(AZ::Edit::UIHandlers::Default, &BlendState::m_targets, "Targets", "")
  557. ;
  558. }
  559. }
  560. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  561. {
  562. behaviorContext->Class<BlendState>("BlendState")
  563. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  564. ->Attribute(AZ::Script::Attributes::Category, "RHI")
  565. ->Attribute(AZ::Script::Attributes::Module, "rhi")
  566. ->Constructor()
  567. ->Constructor<const BlendState&>()
  568. ->Property("alphaToCoverageEnable", BehaviorValueProperty(&BlendState::m_alphaToCoverageEnable))
  569. ->Property("independentBlendEnable", BehaviorValueProperty(&BlendState::m_independentBlendEnable))
  570. ->Property("targets", BehaviorValueProperty(&BlendState::m_targets))
  571. ;
  572. }
  573. }
  574. void SamplePosition::Reflect(ReflectContext* context)
  575. {
  576. if (auto serializeContext = azrtti_cast<SerializeContext*>(context))
  577. {
  578. serializeContext->Class<SamplePosition>()
  579. ->Version(1)
  580. ->Field("x", &SamplePosition::m_x)
  581. ->Field("y", &SamplePosition::m_y)
  582. ;
  583. if (auto editContext = serializeContext->GetEditContext())
  584. {
  585. editContext->Class<SamplePosition>("SamplePosition", "")
  586. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  587. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  588. ->DataElement(AZ::Edit::UIHandlers::Default, &SamplePosition::m_x, "X", "")
  589. ->DataElement(AZ::Edit::UIHandlers::Default, &SamplePosition::m_y, "Y", "")
  590. ;
  591. }
  592. }
  593. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  594. {
  595. behaviorContext->Class<SamplePosition>("SamplePosition")
  596. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  597. ->Attribute(AZ::Script::Attributes::Category, "RHI")
  598. ->Attribute(AZ::Script::Attributes::Module, "rhi")
  599. ->Constructor()
  600. ->Constructor<const SamplePosition&>()
  601. ->Property("x", BehaviorValueProperty(&SamplePosition::m_x))
  602. ->Property("y", BehaviorValueProperty(&SamplePosition::m_y))
  603. ;
  604. }
  605. }
  606. void MultisampleState::Reflect(ReflectContext* context)
  607. {
  608. SamplePosition::Reflect(context);
  609. if (auto serializeContext = azrtti_cast<SerializeContext*>(context))
  610. {
  611. serializeContext->Class<MultisampleState>()
  612. ->Version(1)
  613. ->Field("samples", &MultisampleState::m_samples)
  614. ->Field("quality", &MultisampleState::m_quality)
  615. ->Field("customPositions", &MultisampleState::m_customPositions)
  616. ->Field("customPositionsCount", &MultisampleState::m_customPositionsCount)
  617. ;
  618. if (auto editContext = serializeContext->GetEditContext())
  619. {
  620. editContext->Class<MultisampleState>("MultisampleState", "")
  621. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  622. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  623. ->DataElement(AZ::Edit::UIHandlers::Default, &MultisampleState::m_samples, "Samples", "")
  624. ->DataElement(AZ::Edit::UIHandlers::Default, &MultisampleState::m_quality, "Quality", "")
  625. ->DataElement(AZ::Edit::UIHandlers::Default, &MultisampleState::m_customPositions, "Custom Positions", "")
  626. ->DataElement(AZ::Edit::UIHandlers::Default, &MultisampleState::m_customPositionsCount, "Custom Positions Count", "")
  627. ;
  628. }
  629. }
  630. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  631. {
  632. behaviorContext->Class<MultisampleState>("MultisampleState")
  633. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  634. ->Attribute(AZ::Script::Attributes::Category, "RHI")
  635. ->Attribute(AZ::Script::Attributes::Module, "rhi")
  636. ->Constructor()
  637. ->Constructor<const MultisampleState&>()
  638. ->Property("samples", BehaviorValueProperty(&MultisampleState::m_samples))
  639. ->Property("quality", BehaviorValueProperty(&MultisampleState::m_quality))
  640. ->Property("customPositions", BehaviorValueProperty(&MultisampleState::m_customPositions))
  641. ->Property("customPositionsCount", BehaviorValueProperty(&MultisampleState::m_customPositionsCount))
  642. ;
  643. }
  644. }
  645. void RenderStates::Reflect(ReflectContext* context)
  646. {
  647. if (auto serializeContext = azrtti_cast<SerializeContext*>(context))
  648. {
  649. serializeContext->Class<RenderStates>()
  650. ->Version(1)
  651. ->Field("rasterState", &RenderStates::m_rasterState)
  652. ->Field("multisampleState", &RenderStates::m_multisampleState)
  653. ->Field("depthStencilState", &RenderStates::m_depthStencilState)
  654. ->Field("blendState", &RenderStates::m_blendState)
  655. ;
  656. if (auto editContext = serializeContext->GetEditContext())
  657. {
  658. editContext->Class<RenderStates>("RenderStates", "")
  659. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  660. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  661. ->DataElement(AZ::Edit::UIHandlers::Default, &RenderStates::m_rasterState, "Raster State", "")
  662. ->DataElement(AZ::Edit::UIHandlers::Default, &RenderStates::m_multisampleState, "Multisample State", "")
  663. ->DataElement(AZ::Edit::UIHandlers::Default, &RenderStates::m_depthStencilState, "DepthStencil State", "")
  664. ->DataElement(AZ::Edit::UIHandlers::Default, &RenderStates::m_blendState, "Blend State", "")
  665. ;
  666. }
  667. }
  668. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  669. {
  670. behaviorContext->Class<RenderStates>("RenderStates")
  671. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  672. ->Attribute(AZ::Script::Attributes::Category, "RHI")
  673. ->Attribute(AZ::Script::Attributes::Module, "rhi")
  674. ->Constructor()
  675. ->Constructor<const RenderStates&>()
  676. ->Property("rasterState", BehaviorValueProperty(&RenderStates::m_rasterState))
  677. ->Property("multisampleState", BehaviorValueProperty(&RenderStates::m_multisampleState))
  678. ->Property("depthStencilState", BehaviorValueProperty(&RenderStates::m_depthStencilState))
  679. ->Property("blendState", BehaviorValueProperty(&RenderStates::m_blendState))
  680. ;
  681. }
  682. }
  683. bool RenderStates::operator == (const RenderStates& rhs) const
  684. {
  685. return (memcmp(this, &rhs, sizeof(RenderStates)) == 0);
  686. }
  687. bool RasterState::operator == (const RasterState& rhs) const
  688. {
  689. return (memcmp(this, &rhs, sizeof(RasterState)) == 0);
  690. }
  691. bool StencilOpState::operator == (const StencilOpState& rhs) const
  692. {
  693. return (memcmp(this, &rhs, sizeof(StencilOpState)) == 0);
  694. }
  695. bool DepthState::operator == (const DepthState& rhs) const
  696. {
  697. return (memcmp(this, &rhs, sizeof(DepthState)) == 0);
  698. }
  699. bool StencilState::operator == (const StencilState& rhs) const
  700. {
  701. return (memcmp(this, &rhs, sizeof(StencilState)) == 0);
  702. }
  703. bool DepthStencilState::operator == (const DepthStencilState& rhs) const
  704. {
  705. return (memcmp(this, &rhs, sizeof(DepthStencilState)) == 0);
  706. }
  707. bool TargetBlendState::operator == (const TargetBlendState& rhs) const
  708. {
  709. return (memcmp(this, &rhs, sizeof(TargetBlendState)) == 0);
  710. }
  711. bool BlendState::operator == (const BlendState& rhs) const
  712. {
  713. return (memcmp(this, &rhs, sizeof(BlendState)) == 0);
  714. }
  715. }