BsSamplerOverrides.h 3.3 KB

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