BsTextureView.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsCoreObject.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Data describing a texture view.
  8. */
  9. struct BS_CORE_EXPORT TEXTURE_VIEW_DESC
  10. {
  11. /**
  12. * First mip level of the parent texture the view binds (0 - base level).
  13. * This applied to all array slices specified below.
  14. */
  15. UINT32 mostDetailMip;
  16. /**
  17. * Number of mip levels to bind to the view.
  18. * This applied to all array slices specified below.
  19. */
  20. UINT32 numMips;
  21. /**
  22. * First array slice the view binds to. This will be array index for
  23. * 1D and 2D array textures, texture slice index for 3D textures, and
  24. * face index for cube textures(cube index * 6).
  25. */
  26. UINT32 firstArraySlice;
  27. /**
  28. * Number of array slices to bind tot he view. This will be number of
  29. * array elements for 1D and 2D array textures, number of slices for 3D textures,
  30. * and number of cubes for cube textures.
  31. */
  32. UINT32 numArraySlices;
  33. /**
  34. * Type of texture view.
  35. */
  36. GpuViewUsage usage;
  37. };
  38. /**
  39. * @brief Texture views allow you to reference only a party of a texture.
  40. * They may reference one or multiple mip-levels on one or multiple texture
  41. * array slices. Selected mip level will apply to all slices.
  42. *
  43. * They also allow you to re-purpose a texture. (e.g. make a render target
  44. * a bindable texture).
  45. */
  46. class BS_CORE_EXPORT TextureView
  47. {
  48. public:
  49. class HashFunction
  50. {
  51. public:
  52. size_t operator()(const TEXTURE_VIEW_DESC &key) const;
  53. };
  54. class EqualFunction
  55. {
  56. public:
  57. bool operator()(const TEXTURE_VIEW_DESC &a, const TEXTURE_VIEW_DESC &b) const;
  58. };
  59. virtual ~TextureView();
  60. /**
  61. * @brief Returns the most detailed mip level visible by the view.
  62. */
  63. UINT32 getMostDetailedMip() const { return mDesc.mostDetailMip; }
  64. /**
  65. * @brief Returns the number of mip levels in a single slice visible by the view.
  66. */
  67. UINT32 getNumMips() const { return mDesc.numMips; }
  68. /**
  69. * @brief Returns the first array slice index visible by this view.
  70. */
  71. UINT32 getFirstArraySlice() const { return mDesc.firstArraySlice; }
  72. /**
  73. * @brief Returns the number of array slices visible by this view.
  74. */
  75. UINT32 getNumArraySlices() const { return mDesc.numArraySlices; }
  76. /**
  77. * @brief Returns texture view usage. This determines where on the pipeline can be
  78. * bind the view.
  79. */
  80. GpuViewUsage getUsage() const { return mDesc.usage; }
  81. /**
  82. * @brief Returns the descriptor structure used for initializing the view.
  83. */
  84. const TEXTURE_VIEW_DESC& getDesc() const { return mDesc; }
  85. /**
  86. * @brief Gets the owner texture the view is referencing.
  87. */
  88. SPtr<TextureCore> getTexture() const { return mOwnerTexture; }
  89. protected:
  90. TextureView(const SPtr<TextureCore>& texture, const TEXTURE_VIEW_DESC& _desc);
  91. protected:
  92. friend class TextureCore;
  93. TEXTURE_VIEW_DESC mDesc;
  94. SPtr<TextureCore> mOwnerTexture;
  95. };
  96. }