TextureExampleComponent.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/DrawItem.h>
  13. #include <Atom/RHI.Reflect/SamplerState.h>
  14. #include <AzCore/Component/TickBus.h>
  15. #include <AzCore/Math/Vector2.h>
  16. #include <Utils/ImGuiSidebar.h>
  17. namespace AtomSampleViewer
  18. {
  19. class TextureExampleComponent final
  20. : public BasicRHIComponent
  21. , public AZ::TickBus::Handler
  22. {
  23. public:
  24. AZ_COMPONENT(TextureExampleComponent, "{4B992C42-F1B9-42BE-BB7B-21ED4C2C0A4C}", AZ::Component);
  25. static void Reflect(AZ::ReflectContext* context);
  26. TextureExampleComponent();
  27. ~TextureExampleComponent() = default;
  28. protected:
  29. AZ_DISABLE_COPY(TextureExampleComponent);
  30. // AZ::Component
  31. virtual void Activate() override;
  32. virtual void Deactivate() override;
  33. // AZ::TickBus::Handler ...
  34. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  35. void DrawSamplerSettings();
  36. AZ::RHI::ShaderInputImageIndex m_textureInputIndex;
  37. AZ::RHI::ShaderInputSamplerIndex m_samplerInputIndex;
  38. AZ::RHI::ShaderInputConstantIndex m_useStaticSamplerInputIndex;
  39. AZ::RHI::ShaderInputConstantIndex m_objectMatrixInputIndex;
  40. AZ::RHI::ShaderInputConstantIndex m_uvMatrixInputIndex;
  41. AZ::RHI::Ptr<AZ::RHI::BufferPool> m_bufferPool;
  42. AZ::RHI::Ptr<AZ::RHI::Buffer> m_indexBuffer;
  43. AZ::RHI::Ptr<AZ::RHI::Buffer> m_positionBuffer;
  44. AZ::RHI::Ptr<AZ::RHI::Buffer> m_uvBuffer;
  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::DrawItem m_drawItem;
  54. AZStd::array<AZ::RHI::StreamBufferView, 2> m_streamBufferViews;
  55. AZ::RHI::SamplerState m_samplerState;
  56. bool m_useStaticSampler = true;
  57. AZ::Vector2 m_uvOffset = AZ::Vector2(0.0f);
  58. AZ::Vector2 m_uvScale = AZ::Vector2(1.0f);
  59. bool m_updateSRG = true;
  60. ImGuiSidebar m_imguiSidebar;
  61. };
  62. }