BsTextureView.h 3.1 KB

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