Cubemap.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 <ImageBuilderBaseType.h>
  10. namespace ImageProcessingAtom
  11. {
  12. // note: O3DE is right hand Z up coordinate
  13. // please don't change the order of the enum since we are using it to match the face id defined in AMD's CubemapGen
  14. // and they are using left hand Y up coordinate
  15. enum CubemapFace
  16. {
  17. FaceLeft = 0,
  18. FaceRight,
  19. FaceFront,
  20. FaceBack,
  21. FaceTop,
  22. FaceBottom,
  23. FaceCount
  24. };
  25. //we are treating the orientation of faces in 4x3 layout as the original direction.
  26. enum class CubemapFaceDirection
  27. {
  28. DirNoRotation = 0,
  29. DirRotateLeft90,
  30. DirRotateRight90,
  31. DirRotate180,
  32. DirMirrorHorizontal
  33. };
  34. //this class contains information to descript a cubemap layout
  35. class CubemapLayoutInfo
  36. {
  37. public:
  38. struct FaceInfo
  39. {
  40. AZ::u8 row;
  41. AZ::u8 column;
  42. CubemapFaceDirection direction;
  43. };
  44. //rows and columns of how cubemap's faces laid
  45. AZ::u8 m_rows;
  46. AZ::u8 m_columns;
  47. //the type of this layout info for
  48. CubemapLayoutType m_type;
  49. //the index of row and column where all the faces located
  50. FaceInfo m_faceInfos[FaceCount];
  51. CubemapLayoutInfo();
  52. void SetFaceInfo(CubemapFace face, AZ::u8 row, AZ::u8 col, CubemapFaceDirection dir);
  53. };
  54. //class to help doing operations with faces for an image as cubemap
  55. class CubemapLayout
  56. {
  57. public:
  58. //create a cubemapLayout object for the image. It can be used later to get image information as a cubemap
  59. static CubemapLayout* CreateCubemapLayout(IImageObjectPtr image);
  60. //get layout info for input layout type
  61. static CubemapLayoutInfo* GetCubemapLayoutInfo(CubemapLayoutType type);
  62. //get layout info for input image based on its size
  63. static CubemapLayoutInfo* GetCubemapLayoutInfo(IImageObjectPtr image);
  64. //public functions to get faces information for associated image
  65. AZ::u32 GetFaceSize();
  66. //get the rect where the face in the image
  67. void GetRectForFace(AZ::u32 mip, CubemapFace face, QRect& outRect);
  68. CubemapLayoutInfo* GetLayoutInfo();
  69. //set/get pixels' data from/to specific face. only works for mip 0
  70. void GetFaceData(CubemapFace face, void* outBuffer, AZ::u32& outSize);
  71. void SetFaceData(CubemapFace face, void* dataBuffer, AZ::u32 dataSize);
  72. //get the face's direction
  73. CubemapFaceDirection GetFaceDirection(CubemapFace face);
  74. //get memory for a face from Image data. only works for CubemapLayoutVertical since its memory for each face is continuous
  75. void* GetFaceMemBuffer(AZ::u32 mip, CubemapFace face, AZ::u32& outPitch);
  76. void SetToFaceMemBuffer(AZ::u32 mip, CubemapFace face, void* dataBuffer);
  77. private:
  78. //information for all supported cubemap layouts
  79. static CubemapLayoutInfo s_layoutList[CubemapLayoutTypeCount];
  80. //the image associated for this CubemapLayout
  81. IImageObjectPtr m_image;
  82. //the layout information of m_image
  83. CubemapLayoutInfo* m_info;
  84. //the size of the cubemap's face (which is square and power of 2).
  85. uint32 m_faceSize;
  86. //private constructor. User should always use CreateCubemapLayout create a layout for an image object
  87. CubemapLayout();
  88. //initialize information of all available cubemap layouts
  89. static void InitCubemapLayoutInfos();
  90. };
  91. // Helper function to convert Latitude-longitude map to cubemap
  92. bool IsValidLatLongMap(IImageObjectPtr latitudeMap);
  93. IImageObjectPtr ConvertLatLongMapToCubemap(IImageObjectPtr latitudeMap);
  94. }//end namspace ImageProcessing