mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
chore: DynamicValues now keep track of current type, colors should be converted to vec4/ivec4 upon reading so alpha is correct, keep combo overrides too
This commit is contained in:
parent
04c85bebe4
commit
303a2b5624
@ -19,6 +19,7 @@ void CDynamicValue::update(float newValue) {
|
|||||||
this->m_float = newValue;
|
this->m_float = newValue;
|
||||||
this->m_int = static_cast<int> (newValue);
|
this->m_int = static_cast<int> (newValue);
|
||||||
this->m_bool = static_cast<int> (newValue) != 0;
|
this->m_bool = static_cast<int> (newValue) != 0;
|
||||||
|
this->m_type = UnderlyingType::Float;
|
||||||
|
|
||||||
this->propagate ();
|
this->propagate ();
|
||||||
}
|
}
|
||||||
@ -33,6 +34,7 @@ void CDynamicValue::update(int newValue) {
|
|||||||
this->m_float = static_cast<float> (newValue);
|
this->m_float = static_cast<float> (newValue);
|
||||||
this->m_int = newValue;
|
this->m_int = newValue;
|
||||||
this->m_bool = newValue != 0;
|
this->m_bool = newValue != 0;
|
||||||
|
this->m_type = UnderlyingType::Int;
|
||||||
|
|
||||||
this->propagate ();
|
this->propagate ();
|
||||||
}
|
}
|
||||||
@ -47,6 +49,7 @@ void CDynamicValue::update(bool newValue) {
|
|||||||
this->m_float = newValue;
|
this->m_float = newValue;
|
||||||
this->m_int = newValue;
|
this->m_int = newValue;
|
||||||
this->m_bool = newValue;
|
this->m_bool = newValue;
|
||||||
|
this->m_type = UnderlyingType::Boolean;
|
||||||
|
|
||||||
this->propagate ();
|
this->propagate ();
|
||||||
}
|
}
|
||||||
@ -61,6 +64,7 @@ void CDynamicValue::update(const glm::vec2& newValue) {
|
|||||||
this->m_float = newValue.x;
|
this->m_float = newValue.x;
|
||||||
this->m_int = static_cast<int> (newValue.x);
|
this->m_int = static_cast<int> (newValue.x);
|
||||||
this->m_bool = newValue.x != 0.0f;
|
this->m_bool = newValue.x != 0.0f;
|
||||||
|
this->m_type = UnderlyingType::Vec2;
|
||||||
|
|
||||||
this->propagate ();
|
this->propagate ();
|
||||||
}
|
}
|
||||||
@ -75,6 +79,7 @@ void CDynamicValue::update(const glm::vec3& newValue) {
|
|||||||
this->m_float = newValue.x;
|
this->m_float = newValue.x;
|
||||||
this->m_int = static_cast<int> (newValue.x);
|
this->m_int = static_cast<int> (newValue.x);
|
||||||
this->m_bool = newValue.x != 0.0f;
|
this->m_bool = newValue.x != 0.0f;
|
||||||
|
this->m_type = UnderlyingType::Vec3;
|
||||||
|
|
||||||
this->propagate ();
|
this->propagate ();
|
||||||
}
|
}
|
||||||
@ -89,6 +94,7 @@ void CDynamicValue::update(const glm::vec4& newValue) {
|
|||||||
this->m_float = newValue.x;
|
this->m_float = newValue.x;
|
||||||
this->m_int = static_cast<int> (newValue.x);
|
this->m_int = static_cast<int> (newValue.x);
|
||||||
this->m_bool = newValue.x != 0.0f;
|
this->m_bool = newValue.x != 0.0f;
|
||||||
|
this->m_type = UnderlyingType::Vec4;
|
||||||
|
|
||||||
this->propagate ();
|
this->propagate ();
|
||||||
}
|
}
|
||||||
@ -103,6 +109,7 @@ void CDynamicValue::update(const glm::ivec2& newValue) {
|
|||||||
this->m_float = static_cast<float> (newValue.x);
|
this->m_float = static_cast<float> (newValue.x);
|
||||||
this->m_int = static_cast<int> (newValue.x);
|
this->m_int = static_cast<int> (newValue.x);
|
||||||
this->m_bool = newValue.x != 0;
|
this->m_bool = newValue.x != 0;
|
||||||
|
this->m_type = UnderlyingType::IVec2;
|
||||||
|
|
||||||
this->propagate ();
|
this->propagate ();
|
||||||
}
|
}
|
||||||
@ -117,6 +124,7 @@ void CDynamicValue::update(const glm::ivec3& newValue) {
|
|||||||
this->m_float = static_cast<float> (newValue.x);
|
this->m_float = static_cast<float> (newValue.x);
|
||||||
this->m_int = static_cast<int> (newValue.x);
|
this->m_int = static_cast<int> (newValue.x);
|
||||||
this->m_bool = newValue.x != 0;
|
this->m_bool = newValue.x != 0;
|
||||||
|
this->m_type = UnderlyingType::IVec3;
|
||||||
|
|
||||||
this->propagate ();
|
this->propagate ();
|
||||||
}
|
}
|
||||||
@ -131,6 +139,7 @@ void CDynamicValue::update(const glm::ivec4& newValue) {
|
|||||||
this->m_float = static_cast<float> (newValue.x);
|
this->m_float = static_cast<float> (newValue.x);
|
||||||
this->m_int = static_cast<int> (newValue.x);
|
this->m_int = static_cast<int> (newValue.x);
|
||||||
this->m_bool = newValue.x != 0;
|
this->m_bool = newValue.x != 0;
|
||||||
|
this->m_type = UnderlyingType::IVec4;
|
||||||
|
|
||||||
this->propagate ();
|
this->propagate ();
|
||||||
}
|
}
|
||||||
@ -203,3 +212,7 @@ const int& CDynamicValue::getInt () const {
|
|||||||
const bool& CDynamicValue::getBool () const {
|
const bool& CDynamicValue::getBool () const {
|
||||||
return this->m_bool;
|
return this->m_bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CDynamicValue::UnderlyingType CDynamicValue::getType () const {
|
||||||
|
return this->m_type;
|
||||||
|
}
|
@ -19,6 +19,19 @@ class CDynamicValue {
|
|||||||
friend class WallpaperEngine::Data::Parsers::UserSettingParser;
|
friend class WallpaperEngine::Data::Parsers::UserSettingParser;
|
||||||
friend class WallpaperEngine::Data::Builders::UserSettingBuilder;
|
friend class WallpaperEngine::Data::Builders::UserSettingBuilder;
|
||||||
public:
|
public:
|
||||||
|
enum UnderlyingType {
|
||||||
|
Unknown = -1,
|
||||||
|
IVec4 = 0,
|
||||||
|
IVec3 = 1,
|
||||||
|
IVec2 = 2,
|
||||||
|
Vec4 = 3,
|
||||||
|
Vec3 = 4,
|
||||||
|
Vec2 = 5,
|
||||||
|
Float = 6,
|
||||||
|
Int = 7,
|
||||||
|
Boolean = 8
|
||||||
|
};
|
||||||
|
|
||||||
virtual ~CDynamicValue ();
|
virtual ~CDynamicValue ();
|
||||||
|
|
||||||
[[nodiscard]] const glm::ivec4& getIVec4 () const;
|
[[nodiscard]] const glm::ivec4& getIVec4 () const;
|
||||||
@ -30,6 +43,7 @@ class CDynamicValue {
|
|||||||
[[nodiscard]] const float& getFloat () const;
|
[[nodiscard]] const float& getFloat () const;
|
||||||
[[nodiscard]] const int& getInt () const;
|
[[nodiscard]] const int& getInt () const;
|
||||||
[[nodiscard]] const bool& getBool () const;
|
[[nodiscard]] const bool& getBool () const;
|
||||||
|
[[nodiscard]] UnderlyingType getType () const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connects the current instance to the given instance, updating it's values
|
* Connects the current instance to the given instance, updating it's values
|
||||||
@ -38,8 +52,6 @@ class CDynamicValue {
|
|||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
void connectOutgoing (CDynamicValue* value) const;
|
void connectOutgoing (CDynamicValue* value) const;
|
||||||
|
|
||||||
protected:
|
|
||||||
void update (float newValue);
|
void update (float newValue);
|
||||||
void update (int newValue);
|
void update (int newValue);
|
||||||
void update (bool newValue);
|
void update (bool newValue);
|
||||||
@ -49,6 +61,8 @@ class CDynamicValue {
|
|||||||
void update (const glm::ivec2& newValue);
|
void update (const glm::ivec2& newValue);
|
||||||
void update (const glm::ivec3& newValue);
|
void update (const glm::ivec3& newValue);
|
||||||
void update (const glm::ivec4& newValue);
|
void update (const glm::ivec4& newValue);
|
||||||
|
|
||||||
|
protected:
|
||||||
/**
|
/**
|
||||||
* Registers an incoming connection (another CDynamicValue affecting the current instance's value)
|
* Registers an incoming connection (another CDynamicValue affecting the current instance's value)
|
||||||
* Useful mainly for destroying the connection on delete
|
* Useful mainly for destroying the connection on delete
|
||||||
@ -65,6 +79,7 @@ class CDynamicValue {
|
|||||||
private:
|
private:
|
||||||
mutable std::vector<CDynamicValue*> m_outgoingConnections = {};
|
mutable std::vector<CDynamicValue*> m_outgoingConnections = {};
|
||||||
mutable std::vector<const CDynamicValue*> m_incomingConnections = {};
|
mutable std::vector<const CDynamicValue*> m_incomingConnections = {};
|
||||||
|
UnderlyingType m_type = UnderlyingType::Unknown;
|
||||||
// different values that we will be casted to automagically
|
// different values that we will be casted to automagically
|
||||||
glm::ivec4 m_ivec4 = {};
|
glm::ivec4 m_ivec4 = {};
|
||||||
glm::ivec3 m_ivec3 = {};
|
glm::ivec3 m_ivec3 = {};
|
||||||
|
@ -78,7 +78,7 @@ ImageUniquePtr ObjectParser::parseImage (
|
|||||||
const auto& properties = project.properties;
|
const auto& properties = project.properties;
|
||||||
const auto& effects = it.optional ("effects");
|
const auto& effects = it.optional ("effects");
|
||||||
|
|
||||||
return std::make_unique <Image> (
|
auto result = std::make_unique <Image> (
|
||||||
std::move (base),
|
std::move (base),
|
||||||
ImageData {
|
ImageData {
|
||||||
.origin = it.user ("origin", properties, glm::vec3 (0.0f)),
|
.origin = it.user ("origin", properties, glm::vec3 (0.0f)),
|
||||||
@ -86,7 +86,7 @@ ImageUniquePtr ObjectParser::parseImage (
|
|||||||
.angles = it.user ("angles", properties, glm::vec3 (0.0)),
|
.angles = it.user ("angles", properties, glm::vec3 (0.0)),
|
||||||
.visible = it.user ("visible", properties, true),
|
.visible = it.user ("visible", properties, true),
|
||||||
.alpha = it.user ("alpha", properties, 1.0f),
|
.alpha = it.user ("alpha", properties, 1.0f),
|
||||||
.color = it.user ("color", properties, glm::vec3 (1.0f)),
|
.color = it.user ("color", properties, glm::vec4 (1.0f)),
|
||||||
.alignment = it.optional ("alignment", std::string ("center")),
|
.alignment = it.optional ("alignment", std::string ("center")),
|
||||||
.size = it.optional ("size", glm::vec2 (0.0f)),
|
.size = it.optional ("size", glm::vec2 (0.0f)),
|
||||||
.parallaxDepth = it.optional ("parallaxDepth", glm::vec2 (0.0f)),
|
.parallaxDepth = it.optional ("parallaxDepth", glm::vec2 (0.0f)),
|
||||||
@ -96,6 +96,15 @@ ImageUniquePtr ObjectParser::parseImage (
|
|||||||
.effects = effects.has_value () ? parseEffects (*effects, project) : std::vector <ImageEffectUniquePtr> {},
|
.effects = effects.has_value () ? parseEffects (*effects, project) : std::vector <ImageEffectUniquePtr> {},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// color should be a vec4 for alpha, but it's read as vec3
|
||||||
|
if (result->color->value->getType () == DynamicValue::UnderlyingType::Vec3) {
|
||||||
|
result->color->value->update (glm::vec4 (result->color->value->getVec3 (), 1.0f));
|
||||||
|
} else if (result->color->value->getType () == DynamicValue::UnderlyingType::IVec3) {
|
||||||
|
result->color->value->update (glm::vec4 (result->color->value->getIVec3 (), 255));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector <ImageEffectUniquePtr> ObjectParser::parseEffects (const JSON& it, Project& project) {
|
std::vector <ImageEffectUniquePtr> ObjectParser::parseEffects (const JSON& it, Project& project) {
|
||||||
@ -163,10 +172,10 @@ TextureMap ObjectParser::parseTextureMap (const JSON& it) {
|
|||||||
textureIndex ++;
|
textureIndex ++;
|
||||||
|
|
||||||
if (cur.is_null ()) {
|
if (cur.is_null ()) {
|
||||||
continue;
|
result.emplace (textureIndex, "");
|
||||||
|
} else {
|
||||||
|
result.emplace (textureIndex, cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.emplace (textureIndex, cur);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -425,7 +425,7 @@ void CPass::setupShaders () {
|
|||||||
// TODO: USED TO BUILD THE TEXTURES LATER
|
// TODO: USED TO BUILD THE TEXTURES LATER
|
||||||
// use the combos copied from the pass so it includes the texture format
|
// use the combos copied from the pass so it includes the texture format
|
||||||
this->m_shader = new Render::Shaders::CShader (
|
this->m_shader = new Render::Shaders::CShader (
|
||||||
this->m_image.getContainer (), this->m_pass.shader, this->m_combos,
|
this->m_image.getContainer (), this->m_pass.shader, this->m_combos, this->m_override.combos,
|
||||||
this->m_pass.textures, this->m_override.textures, this->m_override.constants
|
this->m_pass.textures, this->m_override.textures, this->m_override.constants
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -608,7 +608,7 @@ void CPass::setupUniforms () {
|
|||||||
this->addUniform ("g_UserAlpha", image.alpha->value->getFloat ());
|
this->addUniform ("g_UserAlpha", image.alpha->value->getFloat ());
|
||||||
this->addUniform ("g_Alpha", image.alpha->value->getFloat ());
|
this->addUniform ("g_Alpha", image.alpha->value->getFloat ());
|
||||||
this->addUniform ("g_Color", image.color->value->getVec3 ());
|
this->addUniform ("g_Color", image.color->value->getVec3 ());
|
||||||
this->addUniform ("g_Color4", image.color->value->getVec4());
|
this->addUniform ("g_Color4", image.color->value->getVec4 ());
|
||||||
// TODO: VALIDATE THAT G_COMPOSITECOLOR REALLY COMES FROM THIS ONE
|
// TODO: VALIDATE THAT G_COMPOSITECOLOR REALLY COMES FROM THIS ONE
|
||||||
this->addUniform ("g_CompositeColor", image.color->value->getVec3 ());
|
this->addUniform ("g_CompositeColor", image.color->value->getVec3 ());
|
||||||
// add some external variables
|
// add some external variables
|
||||||
|
@ -19,20 +19,21 @@ using namespace WallpaperEngine::Assets;
|
|||||||
namespace WallpaperEngine::Render::Shaders {
|
namespace WallpaperEngine::Render::Shaders {
|
||||||
CShader::CShader (
|
CShader::CShader (
|
||||||
const CContainer& container, std::string filename,
|
const CContainer& container, std::string filename,
|
||||||
const ComboMap& combos, const TextureMap& textures,
|
const ComboMap& combos, const ComboMap& overrideCombos,
|
||||||
const TextureMap& overrideTextures,
|
const TextureMap& textures, const TextureMap& overrideTextures,
|
||||||
const ShaderConstantMap& constants
|
const ShaderConstantMap& constants
|
||||||
) :
|
) :
|
||||||
m_file (std::move (filename)),
|
m_file (std::move (filename)),
|
||||||
m_combos (combos),
|
m_combos (combos),
|
||||||
|
m_overrideCombos (overrideCombos),
|
||||||
m_passTextures (textures),
|
m_passTextures (textures),
|
||||||
m_overrideTextures (overrideTextures),
|
m_overrideTextures (overrideTextures),
|
||||||
m_vertex (
|
m_vertex (
|
||||||
CGLSLContext::UnitType_Vertex, filename, container.readVertexShader (filename),
|
CGLSLContext::UnitType_Vertex, filename, container.readVertexShader (filename),
|
||||||
container, constants, textures, overrideTextures, combos),
|
container, constants, textures, overrideTextures, combos, overrideCombos),
|
||||||
m_fragment (
|
m_fragment (
|
||||||
CGLSLContext::UnitType_Fragment, filename, container.readFragmentShader (filename),
|
CGLSLContext::UnitType_Fragment, filename, container.readFragmentShader (filename),
|
||||||
container, constants, textures, overrideTextures, combos) {
|
container, constants, textures, overrideTextures, combos, overrideCombos) {
|
||||||
// link shaders between them
|
// link shaders between them
|
||||||
this->m_vertex.linkToUnit (&this->m_fragment);
|
this->m_vertex.linkToUnit (&this->m_fragment);
|
||||||
this->m_fragment.linkToUnit (&this->m_vertex);
|
this->m_fragment.linkToUnit (&this->m_vertex);
|
||||||
|
@ -46,8 +46,8 @@ class CShader {
|
|||||||
*/
|
*/
|
||||||
CShader (
|
CShader (
|
||||||
const CContainer& container, std::string filename,
|
const CContainer& container, std::string filename,
|
||||||
const ComboMap& combos, const TextureMap& textures,
|
const ComboMap& combos, const ComboMap& overrideCombos,
|
||||||
const TextureMap& overrideTextures,
|
const TextureMap& textures, const TextureMap& overrideTextures,
|
||||||
const ShaderConstantMap& constants);
|
const ShaderConstantMap& constants);
|
||||||
/**
|
/**
|
||||||
* @return The vertex's shader coude for OpenGL to use
|
* @return The vertex's shader coude for OpenGL to use
|
||||||
@ -98,6 +98,10 @@ class CShader {
|
|||||||
* The combos the shader should be generated with
|
* The combos the shader should be generated with
|
||||||
*/
|
*/
|
||||||
const ComboMap& m_combos;
|
const ComboMap& m_combos;
|
||||||
|
/**
|
||||||
|
* The overriden combos
|
||||||
|
*/
|
||||||
|
const ComboMap& m_overrideCombos;
|
||||||
/**
|
/**
|
||||||
* The list of textures the pass knows about
|
* The list of textures the pass knows about
|
||||||
*/
|
*/
|
||||||
|
@ -58,7 +58,7 @@ using namespace WallpaperEngine::Render::Shaders;
|
|||||||
CShaderUnit::CShaderUnit (
|
CShaderUnit::CShaderUnit (
|
||||||
CGLSLContext::UnitType type, std::string file, std::string content, const CContainer& container,
|
CGLSLContext::UnitType type, std::string file, std::string content, const CContainer& container,
|
||||||
const ShaderConstantMap& constants, const TextureMap& passTextures, const TextureMap& overrideTextures,
|
const ShaderConstantMap& constants, const TextureMap& passTextures, const TextureMap& overrideTextures,
|
||||||
const ComboMap& combos
|
const ComboMap& combos, const ComboMap& overrideCombos
|
||||||
) :
|
) :
|
||||||
m_type (type),
|
m_type (type),
|
||||||
m_link (nullptr),
|
m_link (nullptr),
|
||||||
@ -69,6 +69,7 @@ CShaderUnit::CShaderUnit (
|
|||||||
m_passTextures (passTextures),
|
m_passTextures (passTextures),
|
||||||
m_overrideTextures (overrideTextures),
|
m_overrideTextures (overrideTextures),
|
||||||
m_combos (combos),
|
m_combos (combos),
|
||||||
|
m_overrideCombos (overrideCombos),
|
||||||
m_discoveredCombos (),
|
m_discoveredCombos (),
|
||||||
m_usedCombos () {
|
m_usedCombos () {
|
||||||
// pre-process the shader so the units are clear
|
// pre-process the shader so the units are clear
|
||||||
@ -335,14 +336,14 @@ void CShaderUnit::parseComboConfiguration (const std::string& content, int defau
|
|||||||
|
|
||||||
// check the combos
|
// check the combos
|
||||||
const auto entry = this->m_combos.find (combo->get<std::string> ());
|
const auto entry = this->m_combos.find (combo->get<std::string> ());
|
||||||
|
const auto entryOverride = this->m_overrideCombos.find (combo->get<std::string> ());
|
||||||
|
|
||||||
// add the combo to the found list
|
// add the combo to the found list
|
||||||
this->m_usedCombos.emplace (*combo, true);
|
this->m_usedCombos.emplace (*combo, true);
|
||||||
|
|
||||||
// if the combo was not found in the predefined values this means that the default value in the JSON data can be
|
// if the combo was not found in the predefined values this means that the default value in the JSON data can be
|
||||||
// used so only define the ones that are not already defined
|
// used so only define the ones that are not already defined
|
||||||
if (entry == this->m_combos.end ()) {
|
if (entry == this->m_combos.end () && entryOverride == this->m_overrideCombos.end ()) {
|
||||||
|
|
||||||
// if no combo is defined just load the default settings
|
// if no combo is defined just load the default settings
|
||||||
if (defvalue == data.end ()) {
|
if (defvalue == data.end ()) {
|
||||||
// TODO: PROPERLY SUPPORT EMPTY COMBOS
|
// TODO: PROPERLY SUPPORT EMPTY COMBOS
|
||||||
@ -406,6 +407,8 @@ void CShaderUnit::parseParameterConfiguration (
|
|||||||
// samplers can have special requirements, check what sampler we're working with and create definitions
|
// samplers can have special requirements, check what sampler we're working with and create definitions
|
||||||
// if needed
|
// if needed
|
||||||
const auto textureName = data.find ("default");
|
const auto textureName = data.find ("default");
|
||||||
|
// TODO: CREATE TEXTURE WITH THE GIVEN COLOR
|
||||||
|
const auto paintDefaultColor = data.find ("paintdefaultcolor");
|
||||||
// extract the texture number from the name
|
// extract the texture number from the name
|
||||||
const char value = name.at (std::string ("g_Texture").length ());
|
const char value = name.at (std::string ("g_Texture").length ());
|
||||||
const auto requireany = data.find ("requireany");
|
const auto requireany = data.find ("requireany");
|
||||||
@ -414,6 +417,10 @@ void CShaderUnit::parseParameterConfiguration (
|
|||||||
// TODO: BETTER CONVERSION HERE
|
// TODO: BETTER CONVERSION HERE
|
||||||
size_t index = value - '0';
|
size_t index = value - '0';
|
||||||
|
|
||||||
|
if (combo != data.end () && paintDefaultColor != data.end () && combo->get <std::string> () == "MASK" && this->m_file.find ("water")) {
|
||||||
|
sLog.debug("mask defaultcolor!");
|
||||||
|
}
|
||||||
|
|
||||||
if (combo != data.end ()) {
|
if (combo != data.end ()) {
|
||||||
// TODO: CLEANUP HOW THIS IS DETERMINED FIRST
|
// TODO: CLEANUP HOW THIS IS DETERMINED FIRST
|
||||||
// if the texture exists (and is not null), add to the combo
|
// if the texture exists (and is not null), add to the combo
|
||||||
@ -432,9 +439,10 @@ void CShaderUnit::parseParameterConfiguration (
|
|||||||
for (const auto& item : require->items ()) {
|
for (const auto& item : require->items ()) {
|
||||||
const std::string& macro = item.key ();
|
const std::string& macro = item.key ();
|
||||||
const auto it = this->m_combos.find (macro);
|
const auto it = this->m_combos.find (macro);
|
||||||
|
const auto itOverride = this->m_overrideCombos.find (macro);
|
||||||
|
|
||||||
// if any of the values matched, this option is required
|
// if any of the values matched, this option is required
|
||||||
if (it == this->m_combos.end () || it->second != item.value ()) {
|
if (it == this->m_combos.end () || itOverride != this->m_overrideCombos.end () || it->second != item.value ()) {
|
||||||
isRequired = true;
|
isRequired = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -446,9 +454,10 @@ void CShaderUnit::parseParameterConfiguration (
|
|||||||
for (const auto& item : require->items ()) {
|
for (const auto& item : require->items ()) {
|
||||||
const std::string& macro = item.key ();
|
const std::string& macro = item.key ();
|
||||||
const auto it = this->m_combos.find (macro);
|
const auto it = this->m_combos.find (macro);
|
||||||
|
const auto itOverride = this->m_overrideCombos.find (macro);
|
||||||
|
|
||||||
// these can not exist and that'd be fine, we just care about the values
|
// these can not exist and that'd be fine, we just care about the values
|
||||||
if (it != this->m_combos.end () && it->second == item.value ()) {
|
if ((it != this->m_combos.end () || itOverride != this->m_overrideCombos.end ()) && it->second == item.value ()) {
|
||||||
isRequired = false;
|
isRequired = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -463,9 +472,10 @@ void CShaderUnit::parseParameterConfiguration (
|
|||||||
// is the combo registered already?
|
// is the combo registered already?
|
||||||
// if not, add it with the default value
|
// if not, add it with the default value
|
||||||
const auto combo_it = this->m_combos.find (*combo);
|
const auto combo_it = this->m_combos.find (*combo);
|
||||||
|
const auto overridencombo_it = this->m_overrideCombos.find (*combo);
|
||||||
|
|
||||||
// there's already a combo providing this value, so it doesn't need to be added
|
// there's already a combo providing this value, so it doesn't need to be added
|
||||||
if (combo_it != this->m_combos.end ()) {
|
if (combo_it != this->m_combos.end () || overridencombo_it != this->m_overrideCombos.end ()) {
|
||||||
isRequired = false;
|
isRequired = false;
|
||||||
// otherwise a default value must be used
|
// otherwise a default value must be used
|
||||||
} else if (defvalue->is_string ()) {
|
} else if (defvalue->is_string ()) {
|
||||||
@ -535,27 +545,42 @@ const std::string& CShaderUnit::compile () {
|
|||||||
|
|
||||||
std::map<std::string, bool> addedCombos;
|
std::map<std::string, bool> addedCombos;
|
||||||
|
|
||||||
|
for (const auto& combo : this->m_overrideCombos) {
|
||||||
|
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
||||||
|
this->m_final += DEFINE_COMBO (combo.first, combo.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
addedCombos.emplace (combo.first, true);
|
||||||
|
}
|
||||||
// now add all the combos to the source
|
// now add all the combos to the source
|
||||||
for (const auto& combo : this->m_combos) {
|
for (const auto& combo : this->m_combos) {
|
||||||
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
||||||
this->m_final += DEFINE_COMBO (combo.first, combo.second);
|
this->m_final += DEFINE_COMBO (combo.first, combo.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addedCombos.emplace (combo.first, true);
|
||||||
}
|
}
|
||||||
for (const auto& combo : this->m_discoveredCombos) {
|
for (const auto& combo : this->m_discoveredCombos) {
|
||||||
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
||||||
this->m_final += DEFINE_COMBO (combo.first, combo.second);
|
this->m_final += DEFINE_COMBO (combo.first, combo.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addedCombos.emplace (combo.first, true);
|
||||||
}
|
}
|
||||||
if (this->m_link != nullptr) {
|
if (this->m_link != nullptr) {
|
||||||
for (const auto& combo : this->m_link->getCombos ()) {
|
for (const auto& combo : this->m_link->getCombos ()) {
|
||||||
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
||||||
this->m_final += DEFINE_COMBO (combo.first, combo.second);
|
this->m_final += DEFINE_COMBO (combo.first, combo.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addedCombos.emplace (combo.first, true);
|
||||||
}
|
}
|
||||||
for (const auto& combo : this->m_link->getDiscoveredCombos ()) {
|
for (const auto& combo : this->m_link->getDiscoveredCombos ()) {
|
||||||
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
if (addedCombos.find (combo.first) == addedCombos.end ()) {
|
||||||
this->m_final += DEFINE_COMBO (combo.first, combo.second);
|
this->m_final += DEFINE_COMBO (combo.first, combo.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addedCombos.emplace (combo.first, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class CShaderUnit {
|
|||||||
CShaderUnit (
|
CShaderUnit (
|
||||||
CGLSLContext::UnitType type, std::string file, std::string content, const CContainer& container,
|
CGLSLContext::UnitType type, std::string file, std::string content, const CContainer& container,
|
||||||
const ShaderConstantMap& constants, const TextureMap& passTextures,
|
const ShaderConstantMap& constants, const TextureMap& passTextures,
|
||||||
const TextureMap& overrideTextures, const ComboMap& combos);
|
const TextureMap& overrideTextures, const ComboMap& combos, const ComboMap& overrideCombos);
|
||||||
~CShaderUnit () = default;
|
~CShaderUnit () = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,6 +132,10 @@ class CShaderUnit {
|
|||||||
* Pre-defined values for the combos
|
* Pre-defined values for the combos
|
||||||
*/
|
*/
|
||||||
const ComboMap& m_combos;
|
const ComboMap& m_combos;
|
||||||
|
/**
|
||||||
|
* Pre-defined overriden values for the combos
|
||||||
|
*/
|
||||||
|
const ComboMap& m_overrideCombos;
|
||||||
/**
|
/**
|
||||||
* The combos discovered in the pre-processing step that were not in the combos list
|
* The combos discovered in the pre-processing step that were not in the combos list
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user