~ Fixed RG88 and R8 textures not loading properly

~ Fixed combo setting based on the textures supplied to the image
~ Fixed vec4 shader constants not using the default value
  Should fix #87

Signed-off-by: Alexis Maiquez Murcia <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez Murcia 2022-04-07 23:34:03 +02:00
parent 8450413105
commit fca645b25a
3 changed files with 37 additions and 30 deletions

View File

@ -148,12 +148,14 @@ CTexture::CTexture (void* fileData)
if (this->m_header->format == TextureFormat::RG88) if (this->m_header->format == TextureFormat::RG88)
textureFormat = GL_RG; textureFormat = GL_RG;
else if (this->m_header->format == TextureFormat::R8) else if (this->m_header->format == TextureFormat::R8)
textureFormat = GL_R; textureFormat = GL_RED;
} }
switch (internalFormat) switch (internalFormat)
{ {
case GL_RGBA8: case GL_RGBA8:
case GL_RG8:
case GL_R8:
glTexImage2D (GL_TEXTURE_2D, level, internalFormat, glTexImage2D (GL_TEXTURE_2D, level, internalFormat,
width, height, 0, width, height, 0,
textureFormat, GL_UNSIGNED_BYTE, textureFormat, GL_UNSIGNED_BYTE,

View File

@ -316,13 +316,6 @@ namespace WallpaperEngine::Render::Shaders
it ++; it ++;
} }
} }
/*else if (*it == 'a')
{
if (this->peekString ("attribute", it) == true)
{
this->ignoreSpaces (it);
}
}*/
else if (*it == 'a') else if (*it == 'a')
{ {
// find attribute definitions // find attribute definitions
@ -387,7 +380,7 @@ namespace WallpaperEngine::Render::Shaders
this->m_compiledContent += "// [COMBO] " + configuration; this->m_compiledContent += "// [COMBO] " + configuration;
this->parseComboConfiguration (configuration); BREAK_IF_ERROR; this->parseComboConfiguration (configuration, 1); BREAK_IF_ERROR;
} }
else if (this->peekString ("[COMBO_OFF]", it) == true) else if (this->peekString ("[COMBO_OFF]", it) == true)
{ {
@ -400,10 +393,11 @@ namespace WallpaperEngine::Render::Shaders
this->m_compiledContent += "// [COMBO_OFF] " + configuration; this->m_compiledContent += "// [COMBO_OFF] " + configuration;
this->parseComboConfiguration (configuration); BREAK_IF_ERROR; this->parseComboConfiguration (configuration, 0); BREAK_IF_ERROR;
} }
else else
{ {
// the comment can be ignored and put back as is
this->ignoreUpToNextLineFeed(it); this->ignoreUpToNextLineFeed(it);
this->m_compiledContent.append (begin, it); this->m_compiledContent.append (begin, it);
} }
@ -500,7 +494,7 @@ namespace WallpaperEngine::Render::Shaders
#undef BREAK_IF_ERROR #undef BREAK_IF_ERROR
} }
void Compiler::parseComboConfiguration (const std::string& content) void Compiler::parseComboConfiguration (const std::string& content, int defaultValue)
{ {
json data = json::parse (content); json data = json::parse (content);
auto combo = jsonFindRequired (data, "combo", "cannot parse combo information"); auto combo = jsonFindRequired (data, "combo", "cannot parse combo information");
@ -520,7 +514,7 @@ namespace WallpaperEngine::Render::Shaders
if (defvalue == data.end ()) if (defvalue == data.end ())
{ {
// TODO: PROPERLY SUPPORT EMPTY COMBOS // TODO: PROPERLY SUPPORT EMPTY COMBOS
this->m_combos->insert (std::make_pair <std::string, int> (*combo, 0)); this->m_combos->insert (std::make_pair <std::string, int> (*combo, (int) defaultValue));
} }
else if ((*defvalue).is_number_float ()) else if ((*defvalue).is_number_float ())
{ {
@ -547,11 +541,13 @@ namespace WallpaperEngine::Render::Shaders
auto material = data.find ("material"); auto material = data.find ("material");
auto defvalue = data.find ("default"); auto defvalue = data.find ("default");
auto range = data.find ("range"); auto range = data.find ("range");
auto combo = data.find ("combo");
// this is not a real parameter // this is not a real parameter
if (material == data.end ()) auto constant = this->m_constants.end ();
return;
auto constant = this->m_constants.find (*material); if (material != data.end ())
constant = this->m_constants.find (*material);
if (constant == this->m_constants.end () && defvalue == data.end ()) if (constant == this->m_constants.end () && defvalue == data.end ())
{ {
@ -565,7 +561,9 @@ namespace WallpaperEngine::Render::Shaders
if (type == "vec4") if (type == "vec4")
{ {
parameter = new Variables::CShaderVariableVector4 ( parameter = new Variables::CShaderVariableVector4 (
WallpaperEngine::Core::aToVector4 (*defvalue) constant == this->m_constants.end ()
? WallpaperEngine::Core::aToVector4 (*defvalue)
: *(*constant).second->as <CShaderConstantVector4> ()->getValue ()
); );
} }
else if (type == "vec3") else if (type == "vec3")
@ -619,6 +617,9 @@ namespace WallpaperEngine::Render::Shaders
{ {
// add the new combo to the list // add the new combo to the list
this->m_combos->insert (std::make_pair <std::string, int> (*combo, 1)); this->m_combos->insert (std::make_pair <std::string, int> (*combo, 1));
if (textureName != data.end ())
{
// also ensure that the textureName is loaded and we know about it // also ensure that the textureName is loaded and we know about it
ITexture* texture = this->m_container->readTexture ((*textureName).get <std::string> ()); ITexture* texture = this->m_container->readTexture ((*textureName).get <std::string> ());
// extract the texture number from the name // extract the texture number from the name
@ -630,6 +631,7 @@ namespace WallpaperEngine::Render::Shaders
std::make_pair (index, texture) std::make_pair (index, texture)
); );
} }
}
// samplers are not saved, we can ignore them for now // samplers are not saved, we can ignore them for now
return; return;
@ -641,11 +643,14 @@ namespace WallpaperEngine::Render::Shaders
return; return;
} }
if (material != data.end ())
{
parameter->setIdentifierName (*material); parameter->setIdentifierName (*material);
parameter->setName (name); parameter->setName (name);
this->m_parameters.push_back (parameter); this->m_parameters.push_back (parameter);
} }
}
Variables::CShaderVariable* Compiler::findParameter (const std::string& identifier) Variables::CShaderVariable* Compiler::findParameter (const std::string& identifier)
{ {

View File

@ -188,7 +188,7 @@ namespace WallpaperEngine::Render::Shaders
* *
* @param content The parameter configuration * @param content The parameter configuration
*/ */
void parseComboConfiguration (const std::string& content); void parseComboConfiguration (const std::string& content, int defaultValue = 0);
/** /**
* Parses a parameter extra metadata created by wallpaper engine * Parses a parameter extra metadata created by wallpaper engine
* *