GrSamplerState.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright 2015 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef GrSamplerState_DEFINED
  8. #define GrSamplerState_DEFINED
  9. #include "GrTypes.h"
  10. /**
  11. * Represents the filtering and tile modes used to access a texture.
  12. */
  13. class GrSamplerState {
  14. public:
  15. enum class Filter : uint8_t { kNearest, kBilerp, kMipMap };
  16. enum class WrapMode : uint8_t { kClamp, kRepeat, kMirrorRepeat };
  17. static constexpr GrSamplerState ClampNearest() { return GrSamplerState(); }
  18. static constexpr GrSamplerState ClampBilerp() {
  19. return GrSamplerState(WrapMode::kClamp, Filter::kBilerp);
  20. }
  21. constexpr GrSamplerState() : GrSamplerState(WrapMode::kClamp, Filter::kNearest) {}
  22. constexpr GrSamplerState(WrapMode wrapXAndY, Filter filter)
  23. : fWrapModes{wrapXAndY, wrapXAndY}, fFilter(filter) {}
  24. constexpr GrSamplerState(const WrapMode wrapModes[2], Filter filter)
  25. : fWrapModes{wrapModes[0], wrapModes[1]}, fFilter(filter) {}
  26. constexpr GrSamplerState(const GrSamplerState&) = default;
  27. GrSamplerState& operator=(const GrSamplerState& that) {
  28. fWrapModes[0] = that.fWrapModes[0];
  29. fWrapModes[1] = that.fWrapModes[1];
  30. fFilter = that.fFilter;
  31. return *this;
  32. }
  33. Filter filter() const { return fFilter; }
  34. void setFilterMode(Filter filterMode) { fFilter = filterMode; }
  35. void setWrapModeX(const WrapMode wrap) { fWrapModes[0] = wrap; }
  36. void setWrapModeY(const WrapMode wrap) { fWrapModes[1] = wrap; }
  37. WrapMode wrapModeX() const { return fWrapModes[0]; }
  38. WrapMode wrapModeY() const { return fWrapModes[1]; }
  39. bool isRepeated() const {
  40. return WrapMode::kClamp != fWrapModes[0] || WrapMode::kClamp != fWrapModes[1];
  41. }
  42. bool operator==(const GrSamplerState& that) const {
  43. return fWrapModes[0] == that.fWrapModes[0] && fWrapModes[1] == that.fWrapModes[1] &&
  44. fFilter == that.fFilter;
  45. }
  46. bool operator!=(const GrSamplerState& that) const { return !(*this == that); }
  47. private:
  48. WrapMode fWrapModes[2];
  49. Filter fFilter;
  50. };
  51. #endif