3
0

Image.cpp 2.1 KB

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