Sampler.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Gr/GrObject.h>
  7. namespace anki
  8. {
  9. /// @addtogroup graphics
  10. /// @{
  11. /// Sampler initializer.
  12. class alignas(4) SamplerInitInfo : public GrBaseInitInfo
  13. {
  14. public:
  15. F32 m_minLod = -1000.0f;
  16. F32 m_maxLod = 1000.0f;
  17. F32 m_lodBias = 0.0f;
  18. SamplingFilter m_minMagFilter = SamplingFilter::NEAREST;
  19. SamplingFilter m_mipmapFilter = SamplingFilter::BASE;
  20. CompareOperation m_compareOperation = CompareOperation::ALWAYS;
  21. U8 m_anisotropyLevel = 0;
  22. SamplingAddressing m_addressing = SamplingAddressing::REPEAT;
  23. U8 _m_padding[3] = {0, 0, 0};
  24. SamplerInitInfo() = default;
  25. SamplerInitInfo(CString name)
  26. : GrBaseInitInfo(name)
  27. {
  28. }
  29. U64 computeHash() const
  30. {
  31. const U8* first = reinterpret_cast<const U8*>(&m_minLod);
  32. const U8* last = reinterpret_cast<const U8*>(&m_addressing) + sizeof(m_addressing);
  33. const U32 size = U32(last - first);
  34. ANKI_ASSERT(size
  35. == sizeof(F32) * 3 + sizeof(SamplingFilter) * 2 + sizeof(CompareOperation) + sizeof(I8)
  36. + sizeof(SamplingAddressing));
  37. return anki::computeHash(first, size);
  38. }
  39. };
  40. /// GPU sampler.
  41. class Sampler : public GrObject
  42. {
  43. ANKI_GR_OBJECT
  44. public:
  45. static const GrObjectType CLASS_TYPE = GrObjectType::SAMPLER;
  46. protected:
  47. /// Construct.
  48. Sampler(GrManager* manager, CString name)
  49. : GrObject(manager, CLASS_TYPE, name)
  50. {
  51. }
  52. /// Destroy.
  53. ~Sampler()
  54. {
  55. }
  56. private:
  57. /// Allocate and initialize a new instance.
  58. static ANKI_USE_RESULT Sampler* newInstance(GrManager* manager, const SamplerInitInfo& init);
  59. };
  60. /// @}
  61. } // end namespace anki