mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
fix: some textures applied were not the right ones
This commit is contained in:
parent
8adeefad9c
commit
94a4d9ecee
@ -215,18 +215,17 @@ std::map<int, Images::CMaterial::OverrideInfo> CEffect::overridesFromJSON (
|
|||||||
++textureNumber;
|
++textureNumber;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
if (texture.is_null ()) {
|
if (texture.is_null () && textureNumber > 0) {
|
||||||
if (textureNumber == 0) {
|
continue;
|
||||||
auto passTextures = (*material->getPasses ().begin ())->getTextures ();
|
}
|
||||||
|
|
||||||
if (passTextures.empty ()) {
|
if (textureNumber == 0) {
|
||||||
// TODO: SET CHECKERBOARD TEXTURE AS DEFAULT IN THESE SITUATIONS
|
auto passTextures = (*material->getPasses ().begin ())->getTextures ();
|
||||||
name = "";
|
|
||||||
} else {
|
if (passTextures.empty()) {
|
||||||
name = passTextures.begin ()->second;
|
continue;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
name = "";
|
name = passTextures.begin ()->second;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
name = texture;
|
name = texture;
|
||||||
|
@ -58,7 +58,7 @@ const CPass* CPass::fromJSON (const json& data, const CMaterial::OverrideInfo* o
|
|||||||
for (const auto& [name, value] : overrides->constants)
|
for (const auto& [name, value] : overrides->constants)
|
||||||
constants[name] = value;
|
constants[name] = value;
|
||||||
for (const auto& [id, value] : overrides->textures)
|
for (const auto& [id, value] : overrides->textures)
|
||||||
textures.insert(std::pair(id, value));
|
textures[id] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CPass (
|
return new CPass (
|
||||||
|
@ -219,7 +219,7 @@ void CPrettyPrinter::printPass (const CPass& pass, int passId) {
|
|||||||
this->decreaseIndentation ();
|
this->decreaseIndentation ();
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto fragmentTextures = pass.getShader ()->getFragmentTextures();
|
const auto fragmentTextures = pass.getShader ()->getFragment ().getTextures ();
|
||||||
|
|
||||||
if (fragmentTextures.size () > 0) {
|
if (fragmentTextures.size () > 0) {
|
||||||
this->m_out << "Fragment textures " << fragmentTextures.size () << ":";
|
this->m_out << "Fragment textures " << fragmentTextures.size () << ":";
|
||||||
@ -233,7 +233,7 @@ void CPrettyPrinter::printPass (const CPass& pass, int passId) {
|
|||||||
this->decreaseIndentation ();
|
this->decreaseIndentation ();
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto vertexTextures = pass.getShader ()->getVertexTextures ();
|
const auto vertexTextures = pass.getShader ()->getFragment ().getTextures ();
|
||||||
|
|
||||||
if (vertexTextures.size () > 0) {
|
if (vertexTextures.size () > 0) {
|
||||||
this->m_out << "Vertex textures " << textures.size () << ":";
|
this->m_out << "Vertex textures " << textures.size () << ":";
|
||||||
@ -261,6 +261,34 @@ void CPrettyPrinter::printPass (const CPass& pass, int passId) {
|
|||||||
this->decreaseIndentation ();
|
this->decreaseIndentation ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto vertexCombos = pass.getShader ()->getVertex ().getDiscoveredCombos ();
|
||||||
|
|
||||||
|
if (vertexCombos.size () > 0) {
|
||||||
|
this->m_out << "Vertex combos " << vertexCombos.size () << ":";
|
||||||
|
this->increaseIndentation ();
|
||||||
|
|
||||||
|
for (const auto& combo : vertexCombos) {
|
||||||
|
this->m_out << combo.first << " = " << combo.second;
|
||||||
|
this->lineEnd ();
|
||||||
|
}
|
||||||
|
|
||||||
|
this->decreaseIndentation ();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto fragmentCombos = pass.getShader ()->getFragment ().getDiscoveredCombos ();
|
||||||
|
|
||||||
|
if (fragmentCombos.size () > 0) {
|
||||||
|
this->m_out << "Vertex combos " << fragmentCombos.size () << ":";
|
||||||
|
this->increaseIndentation ();
|
||||||
|
|
||||||
|
for (const auto& combo : fragmentCombos) {
|
||||||
|
this->m_out << combo.first << " = " << combo.second;
|
||||||
|
this->lineEnd ();
|
||||||
|
}
|
||||||
|
|
||||||
|
this->decreaseIndentation ();
|
||||||
|
}
|
||||||
|
|
||||||
const auto constants = base->getConstants ();
|
const auto constants = base->getConstants ();
|
||||||
|
|
||||||
if (constants.size () > 0) {
|
if (constants.size () > 0) {
|
||||||
|
@ -447,10 +447,10 @@ void CPass::setupTextureUniforms () {
|
|||||||
// do the real, final texture setup for the whole process
|
// do the real, final texture setup for the whole process
|
||||||
auto cur = this->m_textures.begin ();
|
auto cur = this->m_textures.begin ();
|
||||||
const auto end = this->m_textures.end ();
|
const auto end = this->m_textures.end ();
|
||||||
auto fragCur = this->m_shader->getFragmentTextures ().begin ();
|
auto fragCur = this->m_shader->getFragment ().getTextures ().begin ();
|
||||||
const auto fragEnd = this->m_shader->getFragmentTextures ().end ();
|
const auto fragEnd = this->m_shader->getFragment ().getTextures ().end ();
|
||||||
auto vertCur = this->m_shader->getVertexTextures ().begin ();
|
auto vertCur = this->m_shader->getVertex ().getTextures ().begin ();
|
||||||
const auto vertEnd = this->m_shader->getVertexTextures ().end ();
|
const auto vertEnd = this->m_shader->getVertex ().getTextures ().end ();
|
||||||
auto bindCur = this->m_material->getMaterial ()->getTextureBinds ().begin ();
|
auto bindCur = this->m_material->getMaterial ()->getTextureBinds ().begin ();
|
||||||
const auto bindEnd = this->m_material->getMaterial ()->getTextureBinds ().end ();
|
const auto bindEnd = this->m_material->getMaterial ()->getTextureBinds ().end ();
|
||||||
|
|
||||||
@ -704,11 +704,11 @@ void CPass::setupShaderVariables () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& cur : this->m_shader->getVertexParameters ())
|
for (const auto& cur : this->m_shader->getVertex ().getParameters ())
|
||||||
if (this->m_uniforms.find (cur->getName ()) == this->m_uniforms.end ())
|
if (this->m_uniforms.find (cur->getName ()) == this->m_uniforms.end ())
|
||||||
this->addUniform (cur);
|
this->addUniform (cur);
|
||||||
|
|
||||||
for (const auto& cur : this->m_shader->getFragmentParameters ())
|
for (const auto& cur : this->m_shader->getVertex ().getParameters ())
|
||||||
if (this->m_uniforms.find (cur->getName ()) == this->m_uniforms.end ())
|
if (this->m_uniforms.find (cur->getName ()) == this->m_uniforms.end ())
|
||||||
this->addUniform (cur);
|
this->addUniform (cur);
|
||||||
}
|
}
|
||||||
|
@ -41,20 +41,12 @@ const std::string& CShader::fragment () {
|
|||||||
return this->m_fragment.compile ();
|
return this->m_fragment.compile ();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<Variables::CShaderVariable*>& CShader::getVertexParameters () const {
|
const CShaderUnit& CShader::getVertex () const {
|
||||||
return this->m_vertex.getParameters ();
|
return this->m_vertex;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<Variables::CShaderVariable*>& CShader::getFragmentParameters () const {
|
const CShaderUnit& CShader::getFragment () const {
|
||||||
return this->m_fragment.getParameters ();
|
return this->m_fragment;
|
||||||
}
|
|
||||||
|
|
||||||
const std::map<int, std::string>& CShader::getVertexTextures () const {
|
|
||||||
return this->m_fragment.getTextures ();
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::map<int, std::string>& CShader::getFragmentTextures () const {
|
|
||||||
return this->m_fragment.getTextures ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::map<std::string, int>& CShader::getCombos () const {
|
const std::map<std::string, int>& CShader::getCombos () const {
|
||||||
|
@ -54,21 +54,13 @@ class CShader {
|
|||||||
*/
|
*/
|
||||||
const std::string& fragment ();
|
const std::string& fragment ();
|
||||||
/**
|
/**
|
||||||
* @return The parameters the vertex shader needs
|
* @return The vertex shader unit
|
||||||
*/
|
*/
|
||||||
[[nodiscaard]]const std::vector<Variables::CShaderVariable*>& getVertexParameters () const;
|
[[nodiscard]] const CShaderUnit& getVertex () const;
|
||||||
/**
|
/**
|
||||||
* @return The parameters the fragment shader needs
|
* @return The fragment shader unit
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::vector<Variables::CShaderVariable*>& getFragmentParameters () const;
|
[[nodiscard]] const CShaderUnit& getFragment () const;
|
||||||
/**
|
|
||||||
* @return The textures required for the vertex shader
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::map<int, std::string>& getVertexTextures () const;
|
|
||||||
/**
|
|
||||||
* @return The textures required for the fragment shader
|
|
||||||
*/
|
|
||||||
[[nodiscard]] const std::map<int, std::string>& getFragmentTextures () const;
|
|
||||||
/**
|
/**
|
||||||
* @return The list of combos available for this shader after compilation
|
* @return The list of combos available for this shader after compilation
|
||||||
*/
|
*/
|
||||||
@ -94,22 +86,6 @@ class CShader {
|
|||||||
* The shader file this instance is loading
|
* The shader file this instance is loading
|
||||||
*/
|
*/
|
||||||
std::string m_file;
|
std::string m_file;
|
||||||
/**
|
|
||||||
* The original file content
|
|
||||||
*/
|
|
||||||
std::string m_content;
|
|
||||||
/**
|
|
||||||
* The final, compiled content ready to be used by OpenGL
|
|
||||||
*/
|
|
||||||
std::string m_processedContent;
|
|
||||||
/**
|
|
||||||
* The contents of all the included files
|
|
||||||
*/
|
|
||||||
std::string m_includeContent;
|
|
||||||
/**
|
|
||||||
* The type of shader
|
|
||||||
*/
|
|
||||||
CGLSLContext::UnitType m_type;
|
|
||||||
/**
|
/**
|
||||||
* The parameters the shader needs
|
* The parameters the shader needs
|
||||||
*/
|
*/
|
||||||
|
@ -402,6 +402,8 @@ void CShaderUnit::parseParameterConfiguration (const std::string& type, const st
|
|||||||
const auto textureName = data.find ("default");
|
const auto textureName = data.find ("default");
|
||||||
// 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 require = data.find ("require");
|
||||||
// now convert it to integer
|
// now convert it to integer
|
||||||
size_t index = value - '0';
|
size_t index = value - '0';
|
||||||
|
|
||||||
@ -409,14 +411,53 @@ void CShaderUnit::parseParameterConfiguration (const std::string& type, const st
|
|||||||
// if the texture exists (and is not null), add to the combo
|
// if the texture exists (and is not null), add to the combo
|
||||||
auto texture = this->m_textures.find (index);
|
auto texture = this->m_textures.find (index);
|
||||||
|
|
||||||
if (texture != this->m_textures.end () && (texture->second.empty () || textureName != data.end ())) {
|
if (textureName == data.end () && texture == this->m_textures.end ()) {
|
||||||
// add the new combo to the list
|
// is this required?
|
||||||
this->m_discoveredCombos.insert (std::make_pair (*combo, 1));
|
if (require == data.end ()) {
|
||||||
|
// if no require information we assume this one is always required, so signal it as such
|
||||||
|
sLog.exception ("Shader ", this->m_file, " requires a texture that is not present");
|
||||||
|
}
|
||||||
|
|
||||||
// textures linked to combos need to be tracked too
|
// some require conditions are set, validate these
|
||||||
if (this->m_usedCombos.find (*combo) == this->m_usedCombos.end ())
|
if (requireany == data.end ()) {
|
||||||
this->m_usedCombos.insert (std::make_pair (*combo, true));
|
// all values have to exist for this to be required
|
||||||
|
for (const auto& item : require->items ()) {
|
||||||
|
const std::string& macro = item.key ();
|
||||||
|
const auto it = this->m_combos.find (macro);
|
||||||
|
|
||||||
|
// these can not exist and that'd be fine, we just care about the values
|
||||||
|
if (it == this->m_combos.end ()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (it->second != item.value ()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sLog.exception ("Shader ", this->m_file, " requires a texture that is not present, activated by condition");
|
||||||
|
} else {
|
||||||
|
// any of the values set are valid, check for them
|
||||||
|
for (const auto& item : require->items ()) {
|
||||||
|
const std::string& macro = item.key ();
|
||||||
|
const auto it = this->m_combos.find (macro);
|
||||||
|
|
||||||
|
// these can not exist and that'd be fine, we just care about the values
|
||||||
|
if (it == this->m_combos.end ()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (it->second == item.value ()) {
|
||||||
|
sLog.exception ("Shader ", this->m_file, " requires a texture that is not present, activated by condition ", macro);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add the new combo to the list
|
||||||
|
this->m_discoveredCombos.insert (std::make_pair (*combo, 1));
|
||||||
|
|
||||||
|
// textures linked to combos need to be tracked too
|
||||||
|
if (this->m_usedCombos.find (*combo) == this->m_usedCombos.end ())
|
||||||
|
this->m_usedCombos.insert (std::make_pair (*combo, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textureName != data.end ())
|
if (textureName != data.end ())
|
||||||
|
@ -49,15 +49,6 @@ class CShaderUnit {
|
|||||||
* @return The textures this shader unit requires
|
* @return The textures this shader unit requires
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::map<int, std::string>& getTextures () const;
|
[[nodiscard]] const std::map<int, std::string>& getTextures () const;
|
||||||
|
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* Extracts any and all possible shader combo configurations
|
|
||||||
* available in this shader unit, prepares includes
|
|
||||||
* and lays the ground for the actual code to be ready
|
|
||||||
*/
|
|
||||||
void preprocess ();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The combos set for this shader unit by the configuration
|
* @return The combos set for this shader unit by the configuration
|
||||||
*/
|
*/
|
||||||
@ -67,6 +58,14 @@ class CShaderUnit {
|
|||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::map<std::string, int>& getDiscoveredCombos () const;
|
[[nodiscard]] const std::map<std::string, int>& getDiscoveredCombos () const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* Extracts any and all possible shader combo configurations
|
||||||
|
* available in this shader unit, prepares includes
|
||||||
|
* and lays the ground for the actual code to be ready
|
||||||
|
*/
|
||||||
|
void preprocess ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Parses the input shader looking for possible combo values that are required for it to properly work
|
* Parses the input shader looking for possible combo values that are required for it to properly work
|
||||||
|
Loading…
Reference in New Issue
Block a user