CmTextureView.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmCoreObject.h"
  4. #include "CmCommonEnums.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Data describing a texture view.
  9. */
  10. struct CM_EXPORT TEXTURE_VIEW_DESC
  11. {
  12. UINT32 mostDetailMip;
  13. UINT32 numMips;
  14. UINT32 firstArraySlice;
  15. UINT32 numArraySlices;
  16. GpuViewUsage usage;
  17. };
  18. /**
  19. * @brief Texture views allow you to reference only a party of a texture.
  20. * They may reference one or multiple mip-levels on one or multiple texture
  21. * array slices. Selected mip level will apply to all slices.
  22. *
  23. * They also allow you to re-purpose a texture. (e.g. make a render target
  24. * a bindable texture).
  25. *
  26. * @note Right now texture views are only used for very specific internal purposes,
  27. * but a more general use might come in the future.
  28. */
  29. class CM_EXPORT TextureView : public CoreObject
  30. {
  31. public:
  32. class HashFunction
  33. {
  34. public:
  35. size_t operator()(const TEXTURE_VIEW_DESC &key) const;
  36. };
  37. class EqualFunction
  38. {
  39. public:
  40. bool operator()(const TEXTURE_VIEW_DESC &a, const TEXTURE_VIEW_DESC &b) const;
  41. };
  42. virtual ~TextureView();
  43. /**
  44. * @brief Returns the most detailed mip level visible by the view.
  45. */
  46. UINT32 getMostDetailedMip() const { return mDesc.mostDetailMip; }
  47. /**
  48. * @brief Returns the number of mip levels in a single slice visible by the view.
  49. */
  50. UINT32 getNumMips() const { return mDesc.numMips; }
  51. /**
  52. * @brief Returns the first array slice index visible by this view.
  53. */
  54. UINT32 getFirstArraySlice() const { return mDesc.firstArraySlice; }
  55. /**
  56. * @brief Returns the number of array slices visible by this view.
  57. */
  58. UINT32 getNumArraySlices() const { return mDesc.numArraySlices; }
  59. /**
  60. * @brief Returns texture view usage. This determines where on the pipeline can be
  61. * bind the view.
  62. */
  63. GpuViewUsage getUsage() const { return mDesc.usage; }
  64. /**
  65. * @brief Returns the descriptor structure used for initializing the view.
  66. */
  67. const TEXTURE_VIEW_DESC& getDesc() const { return mDesc; }
  68. /**
  69. * @brief Gets the owner texture the view is referencing.
  70. */
  71. TexturePtr getTexture() const { return mOwnerTexture; }
  72. protected:
  73. /**
  74. * @brief Initializes the texture view. This must be called right after construction.
  75. */
  76. virtual void initialize(TexturePtr texture, TEXTURE_VIEW_DESC& _desc);
  77. protected:
  78. friend class Texture;
  79. TEXTURE_VIEW_DESC mDesc;
  80. TexturePtr mOwnerTexture;
  81. TextureView();
  82. };
  83. }