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 8 #ifndef GrSamplerState_DEFINED 9 #define GrSamplerState_DEFINED 10 11 #include "include/gpu/GrTypes.h" 12 13 /** 14 * Represents the filtering and tile modes used to access a texture. 15 */ 16 class GrSamplerState { 17 public: 18 enum class Filter : uint8_t { kNearest, kBilerp, kMipMap }; 19 enum class WrapMode : uint8_t { kClamp, kRepeat, kMirrorRepeat, kClampToBorder }; 20 ClampNearest()21 static constexpr GrSamplerState ClampNearest() { return GrSamplerState(); } ClampBilerp()22 static constexpr GrSamplerState ClampBilerp() { 23 return GrSamplerState(WrapMode::kClamp, Filter::kBilerp); 24 } 25 GrSamplerState()26 constexpr GrSamplerState() : GrSamplerState(WrapMode::kClamp, Filter::kNearest) {} 27 GrSamplerState(WrapMode wrapXAndY,Filter filter)28 constexpr GrSamplerState(WrapMode wrapXAndY, Filter filter) 29 : fWrapModes{wrapXAndY, wrapXAndY}, fFilter(filter) {} 30 GrSamplerState(const WrapMode wrapModes[2],Filter filter)31 constexpr GrSamplerState(const WrapMode wrapModes[2], Filter filter) 32 : fWrapModes{wrapModes[0], wrapModes[1]}, fFilter(filter) {} 33 34 constexpr GrSamplerState(const GrSamplerState&) = default; 35 36 GrSamplerState& operator=(const GrSamplerState& that) { 37 fWrapModes[0] = that.fWrapModes[0]; 38 fWrapModes[1] = that.fWrapModes[1]; 39 fFilter = that.fFilter; 40 return *this; 41 } 42 filter()43 Filter filter() const { return fFilter; } 44 setFilterMode(Filter filterMode)45 void setFilterMode(Filter filterMode) { fFilter = filterMode; } 46 setWrapModeX(const WrapMode wrap)47 void setWrapModeX(const WrapMode wrap) { fWrapModes[0] = wrap; } setWrapModeY(const WrapMode wrap)48 void setWrapModeY(const WrapMode wrap) { fWrapModes[1] = wrap; } 49 wrapModeX()50 WrapMode wrapModeX() const { return fWrapModes[0]; } wrapModeY()51 WrapMode wrapModeY() const { return fWrapModes[1]; } 52 isRepeated()53 bool isRepeated() const { 54 return (WrapMode::kClamp != fWrapModes[0] && WrapMode::kClampToBorder != fWrapModes[0]) || 55 (WrapMode::kClamp != fWrapModes[1] && WrapMode::kClampToBorder != fWrapModes[1]); 56 } 57 58 bool operator==(const GrSamplerState& that) const { 59 return fWrapModes[0] == that.fWrapModes[0] && fWrapModes[1] == that.fWrapModes[1] && 60 fFilter == that.fFilter; 61 } 62 63 bool operator!=(const GrSamplerState& that) const { return !(*this == that); } 64 65 private: 66 WrapMode fWrapModes[2]; 67 Filter fFilter; 68 }; 69 70 #endif 71