BsTextureView.h 3.1 KB

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