TextureExampleComponent.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 <RHI/BasicRHIComponent.h>
  10. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  11. #include <Atom/RHI/BufferPool.h>
  12. #include <Atom/RHI.Reflect/SamplerState.h>
  13. #include <AzCore/Component/TickBus.h>
  14. #include <AzCore/Math/Vector2.h>
  15. #include <Utils/ImGuiSidebar.h>
  16. namespace AtomSampleViewer
  17. {
  18. class TextureExampleComponent final
  19. : public BasicRHIComponent
  20. , public AZ::TickBus::Handler
  21. {
  22. public:
  23. AZ_COMPONENT(TextureExampleComponent, "{4B992C42-F1B9-42BE-BB7B-21ED4C2C0A4C}", AZ::Component);
  24. static void Reflect(AZ::ReflectContext* context);
  25. TextureExampleComponent();
  26. ~TextureExampleComponent() = default;
  27. protected:
  28. AZ_DISABLE_COPY(TextureExampleComponent);
  29. // AZ::Component
  30. virtual void Activate() override;
  31. virtual void Deactivate() override;
  32. // AZ::TickBus::Handler ...
  33. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  34. void DrawSamplerSettings();
  35. AZ::RHI::ShaderInputImageIndex m_textureInputIndex;
  36. AZ::RHI::ShaderInputSamplerIndex m_samplerInputIndex;
  37. AZ::RHI::ShaderInputConstantIndex m_useStaticSamplerInputIndex;
  38. AZ::RHI::ShaderInputConstantIndex m_objectMatrixInputIndex;
  39. AZ::RHI::ShaderInputConstantIndex m_uvMatrixInputIndex;
  40. AZ::RHI::Ptr<AZ::RHI::BufferPool> m_bufferPool;
  41. AZ::RHI::Ptr<AZ::RHI::Buffer> m_indexBuffer;
  42. AZ::RHI::Ptr<AZ::RHI::Buffer> m_positionBuffer;
  43. AZ::RHI::Ptr<AZ::RHI::Buffer> m_uvBuffer;
  44. AZ::RHI::GeometryView m_geometryView;
  45. AZ::RHI::ConstPtr<AZ::RHI::PipelineState> m_pipelineState;
  46. AZ::Data::Instance<AZ::RPI::ShaderResourceGroup> m_shaderResourceGroup;
  47. struct BufferData
  48. {
  49. AZStd::array<VertexPosition, 4> m_positions;
  50. AZStd::array<VertexUV, 4> m_uvs;
  51. AZStd::array<uint16_t, 6> m_indices;
  52. };
  53. AZ::RHI::DeviceDrawItem m_drawItem;
  54. AZ::RHI::SamplerState m_samplerState;
  55. bool m_useStaticSampler = true;
  56. AZ::Vector2 m_uvOffset = AZ::Vector2(0.0f);
  57. AZ::Vector2 m_uvScale = AZ::Vector2(1.0f);
  58. bool m_updateSRG = true;
  59. ImGuiSidebar m_imguiSidebar;
  60. };
  61. }