BsTextureView.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. * @note Right now texture views are only used for very specific internal purposes,
  47. * but a more general use might come in the future.
  48. */
  49. class BS_CORE_EXPORT TextureView : public CoreObject
  50. {
  51. public:
  52. class HashFunction
  53. {
  54. public:
  55. size_t operator()(const TEXTURE_VIEW_DESC &key) const;
  56. };
  57. class EqualFunction
  58. {
  59. public:
  60. bool operator()(const TEXTURE_VIEW_DESC &a, const TEXTURE_VIEW_DESC &b) const;
  61. };
  62. virtual ~TextureView();
  63. /**
  64. * @brief Returns the most detailed mip level visible by the view.
  65. */
  66. UINT32 getMostDetailedMip() const { return mDesc.mostDetailMip; }
  67. /**
  68. * @brief Returns the number of mip levels in a single slice visible by the view.
  69. */
  70. UINT32 getNumMips() const { return mDesc.numMips; }
  71. /**
  72. * @brief Returns the first array slice index visible by this view.
  73. */
  74. UINT32 getFirstArraySlice() const { return mDesc.firstArraySlice; }
  75. /**
  76. * @brief Returns the number of array slices visible by this view.
  77. */
  78. UINT32 getNumArraySlices() const { return mDesc.numArraySlices; }
  79. /**
  80. * @brief Returns texture view usage. This determines where on the pipeline can be
  81. * bind the view.
  82. */
  83. GpuViewUsage getUsage() const { return mDesc.usage; }
  84. /**
  85. * @brief Returns the descriptor structure used for initializing the view.
  86. */
  87. const TEXTURE_VIEW_DESC& getDesc() const { return mDesc; }
  88. /**
  89. * @brief Gets the owner texture the view is referencing.
  90. */
  91. TexturePtr getTexture() const { return mOwnerTexture; }
  92. protected:
  93. /**
  94. * @brief Initializes the texture view. This must be called right after construction.
  95. */
  96. virtual void initialize(TexturePtr texture, TEXTURE_VIEW_DESC& _desc);
  97. protected:
  98. friend class Texture;
  99. TEXTURE_VIEW_DESC mDesc;
  100. TexturePtr mOwnerTexture;
  101. TextureView();
  102. };
  103. }