BsTextureView.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #pragma once
  5. #include "BsCorePrerequisites.h"
  6. #include "BsCoreObject.h"
  7. namespace BansheeEngine
  8. {
  9. /**
  10. * @brief Data describing a texture view.
  11. */
  12. struct BS_CORE_EXPORT TEXTURE_VIEW_DESC
  13. {
  14. /**
  15. * First mip level of the parent texture the view binds (0 - base level).
  16. * This applied to all array slices specified below.
  17. */
  18. UINT32 mostDetailMip;
  19. /**
  20. * Number of mip levels to bind to the view.
  21. * This applied to all array slices specified below.
  22. */
  23. UINT32 numMips;
  24. /**
  25. * First array slice the view binds to. This will be array index for
  26. * 1D and 2D array textures, texture slice index for 3D textures, and
  27. * face index for cube textures(cube index * 6).
  28. */
  29. UINT32 firstArraySlice;
  30. /**
  31. * Number of array slices to bind tot he view. This will be number of
  32. * array elements for 1D and 2D array textures, number of slices for 3D textures,
  33. * and number of cubes for cube textures.
  34. */
  35. UINT32 numArraySlices;
  36. /**
  37. * Type of texture view.
  38. */
  39. GpuViewUsage usage;
  40. };
  41. /**
  42. * @brief Texture views allow you to reference only a party of a texture.
  43. * They may reference one or multiple mip-levels on one or multiple texture
  44. * array slices. Selected mip level will apply to all slices.
  45. *
  46. * They also allow you to re-purpose a texture. (e.g. make a render target
  47. * a bindable texture).
  48. *
  49. * @note Right now texture views are only used for very specific internal purposes,
  50. * but a more general use might come in the future.
  51. */
  52. class BS_CORE_EXPORT TextureView : public CoreObject
  53. {
  54. public:
  55. class HashFunction
  56. {
  57. public:
  58. size_t operator()(const TEXTURE_VIEW_DESC &key) const;
  59. };
  60. class EqualFunction
  61. {
  62. public:
  63. bool operator()(const TEXTURE_VIEW_DESC &a, const TEXTURE_VIEW_DESC &b) const;
  64. };
  65. virtual ~TextureView();
  66. /**
  67. * @brief Returns the most detailed mip level visible by the view.
  68. */
  69. UINT32 getMostDetailedMip() const { return mDesc.mostDetailMip; }
  70. /**
  71. * @brief Returns the number of mip levels in a single slice visible by the view.
  72. */
  73. UINT32 getNumMips() const { return mDesc.numMips; }
  74. /**
  75. * @brief Returns the first array slice index visible by this view.
  76. */
  77. UINT32 getFirstArraySlice() const { return mDesc.firstArraySlice; }
  78. /**
  79. * @brief Returns the number of array slices visible by this view.
  80. */
  81. UINT32 getNumArraySlices() const { return mDesc.numArraySlices; }
  82. /**
  83. * @brief Returns texture view usage. This determines where on the pipeline can be
  84. * bind the view.
  85. */
  86. GpuViewUsage getUsage() const { return mDesc.usage; }
  87. /**
  88. * @brief Returns the descriptor structure used for initializing the view.
  89. */
  90. const TEXTURE_VIEW_DESC& getDesc() const { return mDesc; }
  91. /**
  92. * @brief Gets the owner texture the view is referencing.
  93. */
  94. TexturePtr getTexture() const { return mOwnerTexture; }
  95. protected:
  96. /**
  97. * @brief Initializes the texture view. This must be called right after construction.
  98. */
  99. virtual void initialize(TexturePtr texture, TEXTURE_VIEW_DESC& _desc);
  100. protected:
  101. friend class Texture;
  102. TEXTURE_VIEW_DESC mDesc;
  103. TexturePtr mOwnerTexture;
  104. TextureView();
  105. };
  106. }