3
0

ShaderManagementConsoleDocument.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/RPI.Edit/Shader/ShaderVariantListSourceData.h>
  10. #include <Atom/RPI.Reflect/Material/ShaderCollection.h>
  11. #include <Atom/RPI.Reflect/Shader/ShaderAsset.h>
  12. #include <AtomToolsFramework/Document/AtomToolsDocument.h>
  13. #include <AzCore/Asset/AssetCommon.h>
  14. #include <AzCore/RTTI/RTTI.h>
  15. #include <AzCore/std/containers/vector.h>
  16. #include <Document/ShaderManagementConsoleDocumentRequestBus.h>
  17. #include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
  18. namespace ShaderManagementConsole
  19. {
  20. //! ShaderManagementConsoleDocument provides an API for modifying and saving document properties.
  21. class ShaderManagementConsoleDocument
  22. : public AtomToolsFramework::AtomToolsDocument
  23. , public ShaderManagementConsoleDocumentRequestBus::Handler
  24. {
  25. public:
  26. AZ_RTTI(ShaderManagementConsoleDocument, "{C8FAF1C7-8665-423C-B1DD-82016231B17B}", AtomToolsFramework::AtomToolsDocument);
  27. AZ_CLASS_ALLOCATOR(ShaderManagementConsoleDocument, AZ::SystemAllocator);
  28. AZ_DISABLE_COPY_MOVE(ShaderManagementConsoleDocument);
  29. static void Reflect(AZ::ReflectContext* context);
  30. ShaderManagementConsoleDocument() = default;
  31. ShaderManagementConsoleDocument(const AZ::Crc32& toolId, const AtomToolsFramework::DocumentTypeInfo& documentTypeInfo);
  32. ~ShaderManagementConsoleDocument();
  33. // AtomToolsFramework::AtomToolsDocument overrides...
  34. static AtomToolsFramework::DocumentTypeInfo BuildDocumentTypeInfo();
  35. AtomToolsFramework::DocumentObjectInfoVector GetObjectInfo() const override;
  36. bool Open(const AZStd::string& loadPath) override;
  37. bool Save() override;
  38. bool SaveAsCopy(const AZStd::string& savePath) override;
  39. bool SaveAsChild(const AZStd::string& savePath) override;
  40. bool IsModified() const override;
  41. bool BeginEdit() override;
  42. bool EndEdit() override;
  43. // ShaderManagementConsoleDocumentRequestBus::Handler overrides...
  44. void AddOneVariantRow() override;
  45. void AppendSparseVariantSet(
  46. AZStd::vector<AZ::Name> optionHeaders,
  47. AZStd::vector<AZ::Name> matrixOfValues) override;
  48. void MultiplySparseVariantSet(
  49. AZStd::vector<AZ::Name> optionHeaders,
  50. AZStd::vector<AZ::Name> matrixOfValues) override;
  51. void DefragmentVariantList() override;
  52. void SetShaderVariantListSourceData(const AZ::RPI::ShaderVariantListSourceData& shaderVariantListSourceData) override;
  53. const AZ::RPI::ShaderVariantListSourceData& GetShaderVariantListSourceData() const override;
  54. size_t GetShaderOptionDescriptorCount() const override;
  55. const AZ::RPI::ShaderOptionDescriptor& GetShaderOptionDescriptor(size_t index) const override;
  56. DocumentVerificationResult Verify() const override;
  57. private:
  58. // AtomToolsFramework::AtomToolsDocument overrides...
  59. void Clear() override;
  60. // Write shader variant list source data to JSON
  61. bool SaveSourceData();
  62. // Read shader variant list source data from JSON and initialize the document
  63. bool LoadShaderSourceData();
  64. // Read shader source data from JSON then find all references to populate the shader variant list and initialize the document
  65. bool LoadShaderVariantListSourceData();
  66. // Copy shaderVariantIN to shaderVariantOUT, if the targetOption exist, update the value to targetValue
  67. // Return value is stableId += size of shaderVariantIN
  68. AZ::u32 UpdateOptionValue(
  69. AZStd::vector<AZ::RPI::ShaderVariantListSourceData::VariantInfo>& shaderVariantIN,
  70. AZStd::vector<AZ::RPI::ShaderVariantListSourceData::VariantInfo>& shaderVariantOUT,
  71. AZ::Name targetOption,
  72. AZ::Name targetValue,
  73. AZ::u32 stableId);
  74. // Source data for shader variant list
  75. AZ::RPI::ShaderVariantListSourceData m_shaderVariantListSourceData;
  76. // Backup copy of the shader variant list source data that will be saved for restoration during undo.
  77. AZ::RPI::ShaderVariantListSourceData m_shaderVariantListSourceDataBeforeEdit;
  78. // Shader asset for the corresponding shader variant list
  79. AZ::Data::Asset<AZ::RPI::ShaderAsset> m_shaderAsset;
  80. AZ::RPI::ShaderOptionDescriptor m_invalidDescriptor;
  81. // Flag tracking the modified state of the document.
  82. // Will be set to true anytime data is changed and cleared anytime the document is saved.
  83. bool m_modified = {};
  84. };
  85. } // namespace ShaderManagementConsole