BsTextureView.h 2.9 KB

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