Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
SamplerDescriptor.cpp
Go to the documentation of this file.
1
2
5
6namespace Divide
7{
8 namespace TypeUtil
9 {
10 static const char* TextureBorderColourToString(const TextureBorderColour colour) noexcept
11 {
12 return Names::textureBorderColour[to_base(colour)];
13 }
14
16 {
17 for (U8 i = 0; i < to_U8(TextureBorderColour::COUNT); ++i)
18 {
19 if (strcmp(colour.c_str(), Names::textureBorderColour[i]) == 0)
20 {
21 return static_cast<TextureBorderColour>(i);
22 }
23 }
24
26 }
27
28 static const char* WrapModeToString(const TextureWrap wrapMode) noexcept
29 {
30 return Names::textureWrap[to_base(wrapMode)];
31 }
32
33 static TextureWrap StringToWrapMode(const string& wrapMode)
34 {
35 for (U8 i = 0; i < to_U8(TextureWrap::COUNT); ++i)
36 {
37 if (strcmp(wrapMode.c_str(), Names::textureWrap[i]) == 0)
38 {
39 return static_cast<TextureWrap>(i);
40 }
41 }
42
43 return TextureWrap::COUNT;
44 }
45
46 static const char* TextureFilterToString(const TextureFilter filter) noexcept
47 {
48 return Names::textureFilter[to_base(filter)];
49 }
50
51 static TextureFilter StringToTextureFilter(const string& filter)
52 {
53 for (U8 i = 0; i < to_U8(TextureFilter::COUNT); ++i)
54 {
55 if (strcmp(filter.c_str(), Names::textureFilter[i]) == 0)
56 {
57 return static_cast<TextureFilter>(i);
58 }
59 }
60
62 }
63
64 static const char* TextureMipSamplingToString(TextureMipSampling sampling) noexcept
65 {
66 return Names::textureMipSampling[to_base(sampling)];
67 }
68
69 static TextureMipSampling StringToTextureMipSampling(const string& sampling)
70 {
71 for (U8 i = 0; i < to_U8(TextureMipSampling::COUNT); ++i)
72 {
73 if (strcmp(sampling.c_str(), Names::textureMipSampling[i]) == 0)
74 {
75 return static_cast<TextureMipSampling>(i);
76 }
77 }
78
80 }
81 } //namespace TypeUtil
82
83 namespace XMLParser
84 {
85 void saveToXML(const SamplerDescriptor& sampler, const std::string& entryName, boost::property_tree::ptree& pt)
86 {
87 pt.put(entryName + ".Sampler.Filter.<xmlattr>.min", TypeUtil::TextureFilterToString(sampler._minFilter));
88 pt.put(entryName + ".Sampler.Filter.<xmlattr>.mag", TypeUtil::TextureFilterToString(sampler._magFilter));
89 pt.put(entryName + ".Sampler.Filter.<xmlattr>.sampling", TypeUtil::TextureMipSamplingToString(sampler._mipSampling));
90 pt.put(entryName + ".Sampler.Map.<xmlattr>.U", TypeUtil::WrapModeToString(sampler._wrapU));
91 pt.put(entryName + ".Sampler.Map.<xmlattr>.V", TypeUtil::WrapModeToString(sampler._wrapV));
92 pt.put(entryName + ".Sampler.Map.<xmlattr>.W", TypeUtil::WrapModeToString(sampler._wrapW));
93 pt.put(entryName + ".Sampler.comparisonFunction", TypeUtil::ComparisonFunctionToString(sampler._depthCompareFunc));
94 pt.put(entryName + ".Sampler.anisotropy", to_U32(sampler._anisotropyLevel));
95 pt.put(entryName + ".Sampler.minLOD", sampler._lod._min);
96 pt.put(entryName + ".Sampler.maxLOD", sampler._lod._max);
97 pt.put(entryName + ".Sampler.biasLOD", sampler._lod._bias);
98 pt.put(entryName + ".Sampler.borderColour", TypeUtil::TextureBorderColourToString(sampler._borderColour));
99 pt.put(entryName + ".Sampler.customBorderColour.<xmlattr>.r", sampler._customBorderColour.r);
100 pt.put(entryName + ".Sampler.customBorderColour.<xmlattr>.g", sampler._customBorderColour.g);
101 pt.put(entryName + ".Sampler.customBorderColour.<xmlattr>.b", sampler._customBorderColour.b);
102 pt.put(entryName + ".Sampler.customBorderColour.<xmlattr>.a", sampler._customBorderColour.a);
103 }
104
105 SamplerDescriptor loadFromXML(const std::string& entryName, const boost::property_tree::ptree& pt)
106 {
107 SamplerDescriptor sampler = {};
108 sampler._minFilter = TypeUtil::StringToTextureFilter(pt.get<string>(entryName + ".Sampler.Filter.<xmlattr>.min", TypeUtil::TextureFilterToString(TextureFilter::LINEAR)));
109 sampler._magFilter = TypeUtil::StringToTextureFilter(pt.get<string>(entryName + ".Sampler.Filter.<xmlattr>.mag", TypeUtil::TextureFilterToString(TextureFilter::LINEAR)));
110 sampler._mipSampling = TypeUtil::StringToTextureMipSampling(pt.get<string>(entryName + ".Sampler.Filter.<xmlattr>.sampling", TypeUtil::TextureMipSamplingToString(TextureMipSampling::LINEAR)));
111 sampler._wrapU = TypeUtil::StringToWrapMode(pt.get<string>(entryName + ".Sampler.Map.<xmlattr>.U", TypeUtil::WrapModeToString(TextureWrap::REPEAT)));
112 sampler._wrapV = TypeUtil::StringToWrapMode(pt.get<string>(entryName + ".Sampler.Map.<xmlattr>.V", TypeUtil::WrapModeToString(TextureWrap::REPEAT)));
113 sampler._wrapW = TypeUtil::StringToWrapMode(pt.get<string>(entryName + ".Sampler.Map.<xmlattr>.W", TypeUtil::WrapModeToString(TextureWrap::REPEAT)));
114 sampler._depthCompareFunc = TypeUtil::StringToComparisonFunction(pt.get(entryName + ".Sampler.comparisonFunction", "LEQUAL").c_str());
115 sampler._anisotropyLevel = to_U8(pt.get(entryName + ".Sampler.anisotropy", 255u));
116 sampler._lod._min = pt.get(entryName + ".Sampler.minLOD", -1000.f);
117 sampler._lod._max = pt.get(entryName + ".Sampler.maxLOD", 1000.f);
118 sampler._lod._bias = pt.get(entryName + ".Sampler.biasLOD", 0.f);
121 {
122 pt.get(entryName + ".Sampler.customBorderColour.<xmlattr>.r", U8_ZERO),
123 pt.get(entryName + ".Sampler.customBorderColour.<xmlattr>.g", U8_ZERO),
124 pt.get(entryName + ".Sampler.customBorderColour.<xmlattr>.b", U8_ZERO),
125 pt.get(entryName + ".Sampler.customBorderColour.<xmlattr>.a", U8_ONE)
126 };
127
128 return sampler;
129 }
130 } //namespace XMLPareset
131} //namespace Divide
static constexpr const char * textureWrap[]
static constexpr const char * textureMipSampling[]
static constexpr const char * textureFilter[]
static constexpr const char * textureBorderColour[]
static TextureBorderColour StringToTextureBorderColour(const string &colour)
const char * TextureFilterToString(TextureFilter filter) noexcept
const char * ComparisonFunctionToString(ComparisonFunction func) noexcept
ComparisonFunction StringToComparisonFunction(const char *name) noexcept
const char * WrapModeToString(TextureWrap wrapMode) noexcept
static const char * TextureBorderColourToString(const TextureBorderColour colour) noexcept
TextureMipSampling StringToTextureMipSampling(const string &sampling)
const char * TextureMipSamplingToString(TextureMipSampling sampling) noexcept
TextureWrap StringToWrapMode(const string &wrapMode)
TextureFilter StringToTextureFilter(const string &filter)
SamplerDescriptor loadFromXML(const std::string &entryName, const boost::property_tree::ptree &pt)
void saveToXML(const SamplerDescriptor &sampler, const std::string &entryName, boost::property_tree::ptree &pt)
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
constexpr U32 to_U32(const T value)
uint8_t U8
constexpr U8 to_U8(const T value)
constexpr U8 U8_ONE
constexpr U8 U8_ZERO
constexpr auto to_base(const Type value) -> Type
TextureFilter _minFilter
Texture filtering mode.
TextureWrap _wrapU
Texture wrap mode (Or S-R-T)
U8 _anisotropyLevel
The value must be in the range [0...255] and is automatically clamped by the max HW supported level.
ComparisonFunction _depthCompareFunc
Used for depth comparison (COUNT = disabled)
TextureBorderColour _borderColour
Used with CLAMP_TO_BORDER as the background colour outside of the texture border.
TextureMipSampling _mipSampling
UColour4 _customBorderColour
Used with custom border colours.
F32 _min
OpenGL eg: used by TEXTURE_MIN_LOD and TEXTURE_MAX_LOD.
F32 _bias
OpenGL eg: used by TEXTURE_LOD_BIAS.