Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 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 "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 }; |
Michael Ludwig | f23a152 | 2018-12-10 11:36:13 -0500 | [diff] [blame] | 19 | enum class WrapMode : uint8_t { kClamp, kRepeat, kMirrorRepeat, kClampToBorder }; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 20 | |
| 21 | static constexpr GrSamplerState ClampNearest() { return GrSamplerState(); } |
| 22 | static constexpr GrSamplerState ClampBilerp() { |
| 23 | return GrSamplerState(WrapMode::kClamp, Filter::kBilerp); |
| 24 | } |
| 25 | |
| 26 | constexpr GrSamplerState() : GrSamplerState(WrapMode::kClamp, Filter::kNearest) {} |
| 27 | |
| 28 | constexpr GrSamplerState(WrapMode wrapXAndY, Filter filter) |
| 29 | : fWrapModes{wrapXAndY, wrapXAndY}, fFilter(filter) {} |
| 30 | |
| 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 | |
| 43 | Filter filter() const { return fFilter; } |
| 44 | |
| 45 | void setFilterMode(Filter filterMode) { fFilter = filterMode; } |
| 46 | |
| 47 | void setWrapModeX(const WrapMode wrap) { fWrapModes[0] = wrap; } |
| 48 | void setWrapModeY(const WrapMode wrap) { fWrapModes[1] = wrap; } |
| 49 | |
| 50 | WrapMode wrapModeX() const { return fWrapModes[0]; } |
| 51 | WrapMode wrapModeY() const { return fWrapModes[1]; } |
| 52 | |
| 53 | bool isRepeated() const { |
Michael Ludwig | f23a152 | 2018-12-10 11:36:13 -0500 | [diff] [blame] | 54 | return (WrapMode::kClamp != fWrapModes[0] && WrapMode::kClampToBorder != fWrapModes[0]) || |
| 55 | (WrapMode::kClamp != fWrapModes[1] && WrapMode::kClampToBorder != fWrapModes[1]); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 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 |