BsTextureView.h 3.1 KB

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