12 #ifndef hifi_Sampler_h
13 #define hifi_Sampler_h
15 #include <glm/glm.hpp>
17 #include "RegisteredMetaTypes.h"
20 enum class ComparisonFunction {
38 FILTER_MIN_POINT_MAG_LINEAR,
39 FILTER_MIN_LINEAR_MAG_POINT,
40 FILTER_MIN_MAG_LINEAR,
42 FILTER_MIN_MAG_MIP_POINT,
43 FILTER_MIN_MAG_POINT_MIP_LINEAR,
44 FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT,
45 FILTER_MIN_POINT_MAG_MIP_LINEAR,
46 FILTER_MIN_LINEAR_MAG_MIP_POINT,
47 FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
48 FILTER_MIN_MAG_LINEAR_MIP_POINT,
49 FILTER_MIN_MAG_MIP_LINEAR,
65 static const uint8_t MAX_MIP_LEVEL = 0xFF;
69 glm::vec4 _borderColor{ 1.0f };
70 uint32_t _maxAnisotropy = 16;
72 uint8_t _filter = FILTER_MIN_MAG_MIP_LINEAR;
73 uint8_t _comparisonFunc = (uint8_t)ComparisonFunction::ALWAYS;
75 uint8_t _wrapModeU = WRAP_REPEAT;
76 uint8_t _wrapModeV = WRAP_REPEAT;
77 uint8_t _wrapModeW = WRAP_REPEAT;
79 uint8_t _mipOffset = 0;
81 uint8_t _maxMip = MAX_MIP_LEVEL;
84 Desc(
const Filter filter,
const WrapMode wrap = WRAP_REPEAT) : _filter(filter), _wrapModeU(wrap), _wrapModeV(wrap), _wrapModeW(wrap) {}
86 bool operator==(
const Desc& other)
const {
87 return _borderColor == other._borderColor &&
88 _maxAnisotropy == other._maxAnisotropy &&
89 _filter == other._filter &&
90 _comparisonFunc == other._comparisonFunc &&
91 _wrapModeU == other._wrapModeU &&
92 _wrapModeV == other._wrapModeV &&
93 _wrapModeW == other._wrapModeW &&
94 _mipOffset == other._mipOffset &&
95 _minMip == other._minMip &&
96 _maxMip == other._maxMip;
99 static_assert(
sizeof(Desc) == 28,
"Sampler::Desc size doesn't match.");
102 Sampler(
const Filter filter,
const WrapMode wrap = WRAP_REPEAT) : _desc(filter, wrap) {}
103 Sampler(
const Desc& desc) : _desc(desc) {}
106 const glm::vec4& getBorderColor()
const {
return _desc._borderColor; }
108 uint32_t getMaxAnisotropy()
const {
return _desc._maxAnisotropy; }
110 WrapMode getWrapModeU()
const {
return WrapMode(_desc._wrapModeU); }
111 WrapMode getWrapModeV()
const {
return WrapMode(_desc._wrapModeV); }
112 WrapMode getWrapModeW()
const {
return WrapMode(_desc._wrapModeW); }
114 Filter getFilter()
const {
return Filter(_desc._filter); }
115 ComparisonFunction getComparisonFunction()
const {
return ComparisonFunction(_desc._comparisonFunc); }
116 bool doComparison()
const {
return getComparisonFunction() != ComparisonFunction::ALWAYS; }
118 uint8_t getMipOffset()
const {
return _desc._mipOffset; }
119 uint8_t getMinMip()
const {
return _desc._minMip; }
120 uint8_t getMaxMip()
const {
return _desc._maxMip; }
122 const Desc& getDesc()
const {
return _desc; }
124 bool operator==(
const Sampler& other)
const {
125 return _desc == other._desc;
127 bool operator!=(
const Sampler& other)
const {
128 return !(*
this == other);
131 static Sampler parseSampler(
const QJsonObject&
object);
139 ser << d._borderColor;
140 ser << d._maxAnisotropy;
142 ser << d._comparisonFunc;
154 dsr >> d._borderColor;
155 dsr >> d._maxAnisotropy;
157 dsr >> d._comparisonFunc;
168 template<>
struct hash<Sampler> {
169 size_t operator()(
const Sampler& sampler)
const noexcept {
171 const auto& desc = sampler.getDesc();
172 hash_combine(result, desc._comparisonFunc, desc._filter, desc._maxAnisotropy, desc._maxMip, desc._minMip, desc._wrapModeU, desc._wrapModeV, desc._wrapModeW);
178 QDebug& operator<<(QDebug& dbg,
const Sampler& s);
180 QString wrapModeToString(Sampler::WrapMode mode);
181 Sampler::WrapMode wrapModeFromString(
const QString&
string);
RAII tracker of advance position.
Definition: SerDes.h:594
Data deserializer.
Definition: SerDes.h:573
RAII tracker of advance position.
Definition: SerDes.h:82
Data serializer.
Definition: SerDes.h:61