~ 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)
textureFormat = GL_RG;
else if (this->m_header->format == TextureFormat::R8)
textureFormat = GL_R;
textureFormat = GL_RED;
}
switch (internalFormat)
{
case GL_RGBA8:
case GL_RG8:
case GL_R8:
glTexImage2D (GL_TEXTURE_2D, level, internalFormat,
width, height, 0,
textureFormat, GL_UNSIGNED_BYTE,

View File

@ -316,13 +316,6 @@ namespace WallpaperEngine::Render::Shaders
it ++;
}
}
/*else if (*it == 'a')
{
if (this->peekString ("attribute", it) == true)
{
this->ignoreSpaces (it);
}
}*/
else if (*it == 'a')
{
// find attribute definitions
@ -387,7 +380,7 @@ namespace WallpaperEngine::Render::Shaders
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)
{
@ -400,11 +393,12 @@ namespace WallpaperEngine::Render::Shaders
this->m_compiledContent += "// [COMBO_OFF] " + configuration;
this->parseComboConfiguration (configuration); BREAK_IF_ERROR;
this->parseComboConfiguration (configuration, 0); BREAK_IF_ERROR;
}
else
{
this->ignoreUpToNextLineFeed (it);
// the comment can be ignored and put back as is
this->ignoreUpToNextLineFeed(it);
this->m_compiledContent.append (begin, it);
}
}
@ -500,7 +494,7 @@ namespace WallpaperEngine::Render::Shaders
#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);
auto combo = jsonFindRequired (data, "combo", "cannot parse combo information");
@ -520,7 +514,7 @@ namespace WallpaperEngine::Render::Shaders
if (defvalue == data.end ())
{
// 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 ())
{
@ -547,11 +541,13 @@ namespace WallpaperEngine::Render::Shaders
auto material = data.find ("material");
auto defvalue = data.find ("default");
auto range = data.find ("range");
auto combo = data.find ("combo");
// this is not a real parameter
if (material == data.end ())
return;
auto constant = this->m_constants.find (*material);
auto constant = this->m_constants.end ();
if (material != data.end ())
constant = this->m_constants.find (*material);
if (constant == this->m_constants.end () && defvalue == data.end ())
{
@ -565,7 +561,9 @@ namespace WallpaperEngine::Render::Shaders
if (type == "vec4")
{
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")
@ -619,16 +617,20 @@ namespace WallpaperEngine::Render::Shaders
{
// add the new combo to the list
this->m_combos->insert (std::make_pair <std::string, int> (*combo, 1));
// also ensure that the textureName is loaded and we know about it
ITexture* texture = this->m_container->readTexture ((*textureName).get <std::string> ());
// extract the texture number from the name
char value = name.at (std::string("g_Texture").length ());
// now convert it to integer
int index = value - '0';
this->m_textures.insert (
std::make_pair (index, texture)
);
if (textureName != data.end ())
{
// also ensure that the textureName is loaded and we know about it
ITexture* texture = this->m_container->readTexture ((*textureName).get <std::string> ());
// extract the texture number from the name
char value = name.at (std::string("g_Texture").length ());
// now convert it to integer
int index = value - '0';
this->m_textures.insert (
std::make_pair (index, texture)
);
}
}
// samplers are not saved, we can ignore them for now
@ -641,10 +643,13 @@ namespace WallpaperEngine::Render::Shaders
return;
}
parameter->setIdentifierName (*material);
parameter->setName (name);
if (material != data.end ())
{
parameter->setIdentifierName (*material);
parameter->setName (name);
this->m_parameters.push_back (parameter);
this->m_parameters.push_back (parameter);
}
}
Variables::CShaderVariable* Compiler::findParameter (const std::string& identifier)

View File

@ -188,7 +188,7 @@ namespace WallpaperEngine::Render::Shaders
*
* @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
*