Sampler.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /// @addtogroup graphics
  9. /// @{
  10. /// Sampler initializer.
  11. class alignas(4) SamplerInitInfo : public GrBaseInitInfo
  12. {
  13. public:
  14. F32 m_minLod = -1000.0f;
  15. F32 m_maxLod = 1000.0f;
  16. F32 m_lodBias = 0.0f;
  17. SamplingFilter m_minMagFilter = SamplingFilter::NEAREST;
  18. SamplingFilter m_mipmapFilter = SamplingFilter::BASE;
  19. CompareOperation m_compareOperation = CompareOperation::ALWAYS;
  20. U8 m_anisotropyLevel = 0;
  21. SamplingAddressing m_addressing = SamplingAddressing::REPEAT;
  22. U8 _m_padding[3] = {0, 0, 0};
  23. SamplerInitInfo() = default;
  24. SamplerInitInfo(CString name)
  25. : GrBaseInitInfo(name)
  26. {
  27. }
  28. U64 computeHash() const
  29. {
  30. const U8* first = reinterpret_cast<const U8*>(&m_minLod);
  31. const U8* last = reinterpret_cast<const U8*>(&m_addressing) + sizeof(m_addressing);
  32. const U32 size = U32(last - first);
  33. ANKI_ASSERT(size
  34. == sizeof(F32) * 3 + sizeof(SamplingFilter) * 2 + sizeof(CompareOperation) + sizeof(I8)
  35. + sizeof(SamplingAddressing));
  36. return anki::computeHash(first, size);
  37. }
  38. };
  39. /// GPU sampler.
  40. class Sampler : public GrObject
  41. {
  42. ANKI_GR_OBJECT
  43. public:
  44. static const GrObjectType CLASS_TYPE = GrObjectType::SAMPLER;
  45. protected:
  46. /// Construct.
  47. Sampler(GrManager* manager, CString name)
  48. : GrObject(manager, CLASS_TYPE, name)
  49. {
  50. }
  51. /// Destroy.
  52. ~Sampler()
  53. {
  54. }
  55. private:
  56. /// Allocate and initialize a new instance.
  57. static ANKI_USE_RESULT Sampler* newInstance(GrManager* manager, const SamplerInitInfo& init);
  58. };
  59. /// @}
  60. } // end namespace anki