BsD3D11TextureView.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #pragma once
  2. #include "BsD3D11Prerequisites.h"
  3. #include "BsTextureView.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief DirectX implementation of a texture resource view.
  8. */
  9. class BS_D3D11_EXPORT D3D11TextureView : public TextureView
  10. {
  11. public:
  12. ~D3D11TextureView();
  13. /**
  14. * @brief Returns a shader resource view. Caller must take care this texture view
  15. * actually contains a shader resource view, otherwise it returns null.
  16. */
  17. ID3D11ShaderResourceView* getSRV() const { return mSRV; }
  18. /**
  19. * @brief Returns a render target view. Caller must take care this texture view
  20. * actually contains a render target view, otherwise it returns null.
  21. */
  22. ID3D11RenderTargetView* getRTV() const { return mRTV; }
  23. /**
  24. * @brief Returns a unordered access view. Caller must take care this texture view
  25. * actually contains a unordered access view, otherwise it returns null.
  26. */
  27. ID3D11UnorderedAccessView* getUAV() const { return mUAV; }
  28. /**
  29. * @brief Returns a depth stencil view. Caller must take care this texture view
  30. * actually contains a depth stencil view, otherwise it returns null.
  31. *
  32. * @param[in] readOnly Should the depth stencil view only support read operations (allows the bound texture to
  33. * be also used as a shader resource view while bound as a depth stencil target).
  34. */
  35. ID3D11DepthStencilView* getDSV(bool readOnly) const { return readOnly ? mRODSV : mDSV; }
  36. protected:
  37. friend class D3D11TextureCore;
  38. D3D11TextureView(const SPtr<TextureCore>& texture, const TEXTURE_VIEW_DESC& desc);
  39. private:
  40. /**
  41. * @brief Creates a shader resource view that allows the provided surfaces
  42. * to be bound as normal shader resources.
  43. *
  44. * @param texture Texture to create the resource view for.
  45. * @param mostDetailMip First mip level to create the resource view for (0 - base level).
  46. * @param numMips Number of mip levels to create the view for.
  47. * @param firstArraySlice First array slice to create the view for. This will be array index
  48. * for 1D and 2D array textures, texture slice index for 3D textures, and face
  49. * index for cube textures (cube index * 6).
  50. * @param numArraySlices Number of array slices to create the view for. This will be number of
  51. * array elements for 1D and 2D array textures, number of slices for 3D textures,
  52. * and number of cubes for cube textures.
  53. */
  54. ID3D11ShaderResourceView* createSRV(D3D11TextureCore* texture,
  55. UINT32 mostDetailMip, UINT32 numMips, UINT32 firstArraySlice, UINT32 numArraySlices);
  56. /**
  57. * @brief Creates a shader resource view that allows the provided surfaces
  58. * to be bound as render targets.
  59. *
  60. * @param texture Texture to create the resource view for.
  61. * @param mipSlice Mip level to create the resource view for (0 - base level).
  62. * @param firstArraySlice First array slice to create the view for. This will be array index
  63. * for 1D and 2D array textures, texture slice index for 3D textures, and face
  64. * index for cube textures (cube index * 6).
  65. * @param numArraySlices Number of array slices to create the view for. This will be number of
  66. * array elements for 1D and 2D array textures, number of slices for 3D textures,
  67. * and number of cubes for cube textures.
  68. */
  69. ID3D11RenderTargetView* createRTV(D3D11TextureCore* texture,
  70. UINT32 mipSlice, UINT32 firstArraySlice, UINT32 numArraySlices);
  71. /**
  72. * @brief Creates a shader resource view that allows the provided surfaces
  73. * to be bound as unordered access buffers.
  74. *
  75. * @param texture Texture to create the resource view for.
  76. * @param mipSlice Mip level to create the resource view for (0 - base level).
  77. * @param firstArraySlice First array slice to create the view for. This will be array index
  78. * for 1D and 2D array textures, texture slice index for 3D textures, and face
  79. * index for cube textures (cube index * 6).
  80. * @param numArraySlices Number of array slices to create the view for. This will be number of
  81. * array elements for 1D and 2D array textures, number of slices for 3D textures,
  82. * and number of cubes for cube textures.
  83. */
  84. ID3D11UnorderedAccessView* createUAV(D3D11TextureCore* texture,
  85. UINT32 mipSlice, UINT32 firstArraySlice, UINT32 numArraySlices);
  86. /**
  87. * @brief Creates a shader resource view that allows the provided surfaces
  88. * to be bound as depth stencil buffers.
  89. *
  90. * @param texture Texture to create the resource view for.
  91. * @param mipSlice Mip level to create the resource view for (0 - base level).
  92. * @param firstArraySlice First array slice to create the view for. This will be array index
  93. * for 1D and 2D array textures, texture slice index for 3D textures, and face
  94. * index for cube textures (cube index * 6).
  95. * @param numArraySlices Number of array slices to create the view for. This will be number of
  96. * array elements for 1D and 2D array textures, number of slices for 3D textures,
  97. * and number of cubes for cube textures.
  98. * @param readOnly Should the depth stencil view only support read operations (allows the bound texture to
  99. * be also used as a shader resource view while bound as a depth stencil target).
  100. */
  101. ID3D11DepthStencilView* createDSV(D3D11TextureCore* texture,
  102. UINT32 mipSlice, UINT32 firstArraySlice, UINT32 numArraySlices, bool readOnly);
  103. ID3D11ShaderResourceView* mSRV;
  104. ID3D11RenderTargetView* mRTV;
  105. ID3D11UnorderedAccessView* mUAV;
  106. ID3D11DepthStencilView* mDSV;
  107. ID3D11DepthStencilView* mRODSV;
  108. };
  109. }