BsTextureView.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. protected:
  70. TextureView(const TEXTURE_VIEW_DESC& _desc);
  71. protected:
  72. friend class Texture;
  73. TEXTURE_VIEW_DESC mDesc;
  74. };
  75. /** @} */
  76. }
  77. }