Sampler.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (C) 2009-present, 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. // Sampler initializer
  9. class SamplerInitInfo : public GrBaseInitInfo
  10. {
  11. public:
  12. F32 m_minLod = -1000.0f;
  13. F32 m_maxLod = 1000.0f;
  14. F32 m_lodBias = 0.0f;
  15. SamplingFilter m_minMagFilter = SamplingFilter::kNearest;
  16. SamplingFilter m_mipmapFilter = SamplingFilter::kNearest;
  17. CompareOperation m_compareOperation = CompareOperation::kAlways;
  18. U8 m_anisotropyLevel = 0;
  19. SamplingAddressing m_addressing = SamplingAddressing::kRepeat;
  20. SamplerInitInfo() = default;
  21. SamplerInitInfo(CString name)
  22. : GrBaseInitInfo(name)
  23. {
  24. }
  25. U64 computeHash() const
  26. {
  27. Array<U32, 8> arr;
  28. U32 count = 0;
  29. arr[count++] = asU32(m_minLod);
  30. arr[count++] = asU32(m_maxLod);
  31. arr[count++] = asU32(m_lodBias);
  32. arr[count++] = U32(m_minMagFilter);
  33. arr[count++] = U32(m_mipmapFilter);
  34. arr[count++] = U32(m_compareOperation);
  35. arr[count++] = m_anisotropyLevel;
  36. arr[count++] = U32(m_addressing);
  37. return computeObjectHash(arr);
  38. }
  39. };
  40. // GPU sampler
  41. class Sampler : public GrObject
  42. {
  43. ANKI_GR_OBJECT
  44. public:
  45. static constexpr GrObjectType kClassType = GrObjectType::kSampler;
  46. protected:
  47. Sampler(CString name)
  48. : GrObject(kClassType, name)
  49. {
  50. }
  51. ~Sampler()
  52. {
  53. }
  54. private:
  55. [[nodiscard]] static Sampler* newInstance(const SamplerInitInfo& init);
  56. };
  57. } // end namespace anki