BsSamplerOverrides.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsRenderBeastPrerequisites.h"
  5. namespace bs { namespace ct
  6. {
  7. /** @addtogroup RenderBeast
  8. * @{
  9. */
  10. /** Contains data about an overridden sampler states for a single pass. */
  11. struct PassSamplerOverrides
  12. {
  13. UINT32** stateOverrides;
  14. UINT32 numSets;
  15. };
  16. /** Contains data about a single overriden sampler state. */
  17. struct SamplerOverride
  18. {
  19. UINT32 paramIdx;
  20. UINT64 originalStateHash;
  21. SPtr<SamplerState> state;
  22. UINT32 set;
  23. UINT32 slot;
  24. };
  25. /** Contains data about an overridden sampler states in the entire material. */
  26. struct MaterialSamplerOverrides
  27. {
  28. PassSamplerOverrides* passes;
  29. SamplerOverride* overrides;
  30. UINT32 numPasses;
  31. UINT32 numOverrides;
  32. UINT32 refCount;
  33. bool isDirty;
  34. };
  35. /** Key used for uniquely identifying a sampler override entry. */
  36. struct SamplerOverrideKey
  37. {
  38. SamplerOverrideKey(const SPtr<Material>& material, UINT32 techniqueIdx)
  39. :material(material), techniqueIdx(techniqueIdx)
  40. { }
  41. bool operator== (const SamplerOverrideKey& rhs) const
  42. {
  43. return material == rhs.material && techniqueIdx == rhs.techniqueIdx;
  44. }
  45. bool operator!= (const SamplerOverrideKey& rhs) const
  46. {
  47. return !(*this == rhs);
  48. }
  49. SPtr<Material> material;
  50. UINT32 techniqueIdx;
  51. };
  52. /** Helper class for generating sampler overrides. */
  53. class SamplerOverrideUtility
  54. {
  55. public:
  56. /**
  57. * Generates a set of sampler overrides for the specified set of GPU program parameters. Overrides are generates
  58. * according to the provided render options.
  59. */
  60. static MaterialSamplerOverrides* generateSamplerOverrides(const SPtr<Shader>& shader,
  61. const SPtr<MaterialParams>& params,
  62. const SPtr<GpuParamsSet>& paramsSet,
  63. const SPtr<RenderBeastOptions>& options);
  64. /** Destroys sampler overrides previously generated with generateSamplerOverrides(). */
  65. static void destroySamplerOverrides(MaterialSamplerOverrides* overrides);
  66. /**
  67. * Checks if the provided sampler state requires an override, in case the render options have requirements not
  68. * fulfilled by current sampler state (for example filtering type).
  69. */
  70. static bool checkNeedsOverride(const SPtr<SamplerState>& samplerState,
  71. const SPtr<RenderBeastOptions>& options);
  72. /**
  73. * Generates a new sampler state override using the provided state as the basis. Overridden properties are taken
  74. * from the provided render options.
  75. */
  76. static SPtr<SamplerState> generateSamplerOverride(const SPtr<SamplerState>& samplerState,
  77. const SPtr<RenderBeastOptions>& options);
  78. };
  79. /** @} */
  80. }}
  81. /** @cond STDLIB */
  82. namespace std
  83. {
  84. /** Hash value generator for SamplerOverrideKey. */
  85. template<>
  86. struct hash<bs::ct::SamplerOverrideKey>
  87. {
  88. size_t operator()(const bs::ct::SamplerOverrideKey& key) const
  89. {
  90. size_t hash = 0;
  91. bs::hash_combine(hash, key.material);
  92. bs::hash_combine(hash, key.techniqueIdx);
  93. return hash;
  94. }
  95. };
  96. }
  97. /** @endcond */