3
0

Image.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/RPI.Reflect/Image/Image.h>
  9. #include <Atom/RPI.Reflect/Image/ImageAsset.h>
  10. #include <Atom/RHI/Factory.h>
  11. namespace AZ
  12. {
  13. namespace RPI
  14. {
  15. Image::Image()
  16. {
  17. /**
  18. * Image views are persistently initialized on their parent image, and
  19. * shader resource groups hold image view references. If we re-create the image
  20. * view instance entirely, that will not automatically propagate to dependent
  21. * shader resource groups.
  22. *
  23. * Image views remain valid when their host image shuts down and re-initializes
  24. * (it will force a rebuild), so the best course of action is to keep a persistent
  25. * pointer around at all times, and then only initialize the image view once.
  26. */
  27. auto& factory = RHI::Factory::Get();
  28. m_image = factory.CreateImage();
  29. AZ_Assert(m_image, "Failed to acquire an image instance from the RHI. Is the RHI initialized?");
  30. }
  31. bool Image::IsInitialized() const
  32. {
  33. return m_image->IsInitialized();
  34. }
  35. RHI::Image* Image::GetRHIImage()
  36. {
  37. return m_image.get();
  38. }
  39. const RHI::Image* Image::GetRHIImage() const
  40. {
  41. return m_image.get();
  42. }
  43. const RHI::ImageView* Image::GetImageView() const
  44. {
  45. return m_imageView.get();
  46. }
  47. const RHI::ImageDescriptor& Image::GetDescriptor() const
  48. {
  49. return m_image->GetDescriptor();
  50. }
  51. uint16_t Image::GetMipLevelCount()
  52. {
  53. return m_image->GetDescriptor().m_mipLevels;
  54. }
  55. RHI::ResultCode Image::UpdateImageContents(const RHI::ImageUpdateRequest& request)
  56. {
  57. RHI::ImagePool* imagePool = azrtti_cast<RHI::ImagePool*> (m_image->GetPool());
  58. return imagePool->UpdateImageContents(request);
  59. }
  60. }
  61. }