ShaderManagementConsoleDocument.h 4.2 KB

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