Cogs.Core
MaterialOptions.cpp
1#include "MaterialOptions.h"
2
3#include "Utilities/Parsing.h"
4
5#include "Foundation/StringView.h"
6#include "Foundation/Logging/Logger.h"
7
8namespace
9{
10 Cogs::Logging::Log logger = Cogs::Logging::getLogger("MaterialOptions");
11}
12
13void Cogs::Core::applyMaterialOption(MaterialOptions & options, const StringView & key, const StringView & value)
14{
15 const size_t code = key.hash();
16 const size_t valueCode = value.hash();
17
18 switch (code) {
19 case Cogs::hash("CullMode"):
20 {
21 switch (valueCode) {
22 case Cogs::hash("Front"):
23 options.cullMode = CullMode::Front;
24 break;
25 case Cogs::hash("Back"):
26 options.cullMode = CullMode::Back;
27 break;
28 default:
29 options.cullMode = CullMode::None;
30 break;
31 }
32 }
33 break;
34 case Cogs::hash("Transparency"):
35 case Cogs::hash("TransparencyMode"):
36 {
37 switch (valueCode) {
38 case Cogs::hash("On"):
39 options.transparencyMode = TransparencyMode::On;
40 break;
41 case Cogs::hash("Off"):
42 options.transparencyMode = TransparencyMode::Off;
43 break;
44 case Cogs::hash("Auto"):
45 options.transparencyMode = TransparencyMode::Auto;
46 break;
47 case Cogs::hash("Alpha"):
48 options.transparencyMode = TransparencyMode::Alpha;
49 break;
50 default:
51 LOG_WARNING(logger, "Unknown Transparency value '%.*s'", StringViewFormat(value));
52 break;
53 }
54 }
55 break;
56 case Cogs::hash("DrawOrder"):
57 options.drawOrder = parseInt(value, 0);
58 break;
59 case Cogs::hash("BlendMode"):
60 options.blendMode = parseEnum<BlendMode>(value, BlendMode::None);
61 break;
62 case Cogs::hash("DepthWrite"):
63 {
64 LOG_WARNING(logger, "DepthWrite Deprecated, please use DepthWriteEnabled instead.");
65 switch (valueCode) {
66 case Cogs::hash("Off"):
67 options.depthWriteEnabled = false;
68 break;
69 default:
70 options.depthWriteEnabled = true;
71 break;
72 }
73 }
74 break;
75 case Cogs::hash("DepthTest"):
76 {
77 LOG_WARNING(logger, "DepthTest Deprecated, please use DepthTestEnabled instead.");
78 switch (valueCode) {
79 case Cogs::hash("Off"):
80 options.depthTestEnabled = false;
81 break;
82 default:
83 options.depthTestEnabled = true;
84 break;
85 }
86 }
87 break;
88 case Cogs::hash("DepthWriteEnabled"):
89 {
90 options.depthWriteEnabled = parseBool(value, false);
91 }
92 break;
93 case Cogs::hash("DepthTestEnabled"):
94 {
95 options.depthTestEnabled = parseBool(value, false);
96 }
97 break;
98 case Cogs::hash("DepthFunc"):
99 {
100 options.depthFunc = parseEnum<DepthFunc>(value, DepthFunc::Less);
101 }
102 break;
103 case Cogs::hash("DepthTestAlwaysPass"):
104 LOG_WARNING_ONCE(logger, "DepthTestAlwaysPass Deprecated, please use DepthTestEnabled instead.");
105 if (parseBool(value, false)) {
106 options.depthFunc = DepthFunc::Always;
107 }
108 else {
109 options.depthFunc = DepthFunc::Less;
110 }
111 break;
112 case Cogs::hash("DepthBiasEnabled"):
113 {
114 options.depthBiasEnabled = parseBool(value, false);
115 }
116 break;
117 case Cogs::hash("DepthBiasConstant"):
118 {
119 options.depthBias.constant = parseFloat(value, 0.0f);
120 }
121 break;
122 case Cogs::hash("DepthBiasSlope"):
123 {
124 options.depthBias.slope = parseFloat(value, 0.0f);
125 }
126 break;
127 case Cogs::hash("DepthBiasClamp"):
128 {
129 options.depthBias.clamp = parseFloat(value, 0.0f);
130 }
131 break;
132 default:
133 // May be parsed elsewhere..
134 // LOG_WARNING(logger, "Unknown option key '%.*s'", StringViewFormat(key));
135 break;
136 }
137}
Log implementation class.
Definition: LogManager.h:139
@ Off
Disable capture and camera, consume no rendering resources.
BlendMode
Defines blending modes for rendering.
@ Alpha
Fetch elevation from alpha channel of elevation texture.
CullMode
Defines primitive culling modes.
@ Back
Back face of primitives discarded before rasterization.
@ Front
Front face of primitives discarded before rasterization.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Definition: LogManager.h:180
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
constexpr size_t hash() noexcept
Simple getter function that returns the initial value for fnv1a hashing.
Definition: HashFunctions.h:62