BsTextureView.h 2.4 KB

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