BsSamplerOverrides.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 BansheeEngine
  6. {
  7. /** @addtogroup RenderBeast
  8. * @{
  9. */
  10. /** Contains data about an overridden sampler states for a single pass stage. */
  11. struct StageSamplerOverrides
  12. {
  13. UINT32* stateOverrides;
  14. UINT32 numStates;
  15. };
  16. /** Contains data about an overridden sampler states for a single pass. */
  17. struct PassSamplerOverrides
  18. {
  19. StageSamplerOverrides* stages;
  20. UINT32 numStages;
  21. };
  22. /** Contains data about a single overriden sampler state. */
  23. struct SamplerOverride
  24. {
  25. UINT32 paramIdx;
  26. UINT64 originalStateHash;
  27. SPtr<SamplerStateCore> state;
  28. };
  29. /** Contains data about an overridden sampler states in the entire material. */
  30. struct MaterialSamplerOverrides
  31. {
  32. PassSamplerOverrides* passes;
  33. SamplerOverride* overrides;
  34. UINT32 numPasses;
  35. UINT32 numOverrides;
  36. UINT32 refCount;
  37. };
  38. /** Key used for uniquely identifying a sampler override entry. */
  39. struct SamplerOverrideKey
  40. {
  41. SamplerOverrideKey(const SPtr<MaterialCore>& material, UINT32 techniqueIdx)
  42. :material(material), techniqueIdx(techniqueIdx)
  43. { }
  44. bool operator== (const SamplerOverrideKey& rhs) const
  45. {
  46. return material == rhs.material && techniqueIdx == rhs.techniqueIdx;
  47. }
  48. bool operator!= (const SamplerOverrideKey& rhs) const
  49. {
  50. return !(*this == rhs);
  51. }
  52. SPtr<MaterialCore> material;
  53. UINT32 techniqueIdx;
  54. };
  55. /** Helper class for generating sampler overrides. */
  56. class BS_BSRND_EXPORT SamplerOverrideUtility
  57. {
  58. public:
  59. /**
  60. * Generates a set of sampler overrides for the specified set of GPU program parameters. Overrides are generates
  61. * according to the provided render options.
  62. */
  63. static MaterialSamplerOverrides* generateSamplerOverrides(const SPtr<ShaderCore>& shader,
  64. const SPtr<MaterialParamsCore>& params,
  65. const SPtr<GpuParamsSetCore>& paramsSet,
  66. const SPtr<RenderBeastOptions>& options);
  67. /** Destroys sampler overrides previously generated with generateSamplerOverrides(). */
  68. static void destroySamplerOverrides(MaterialSamplerOverrides* overrides);
  69. /**
  70. * Checks if the provided sampler state requires an override, in case the render options have requirements not
  71. * fulfilled by current sampler state (for example filtering type).
  72. */
  73. static bool checkNeedsOverride(const SPtr<SamplerStateCore>& samplerState,
  74. const SPtr<RenderBeastOptions>& options);
  75. /**
  76. * Generates a new sampler state override using the provided state as the basis. Overridden properties are taken
  77. * from the provided render options.
  78. */
  79. static SPtr<SamplerStateCore> generateSamplerOverride(const SPtr<SamplerStateCore>& samplerState,
  80. const SPtr<RenderBeastOptions>& options);
  81. };
  82. /** @} */
  83. }
  84. /** @cond STDLIB */
  85. namespace std
  86. {
  87. /** Hash value generator for SamplerOverrideKey. */
  88. template<>
  89. struct hash<BansheeEngine::SamplerOverrideKey>
  90. {
  91. size_t operator()(const BansheeEngine::SamplerOverrideKey& key) const
  92. {
  93. size_t hash = 0;
  94. BansheeEngine::hash_combine(hash, key.material);
  95. BansheeEngine::hash_combine(hash, key.techniqueIdx);
  96. return hash;
  97. }
  98. };
  99. }
  100. /** @endcond */