mirror of
https://github.com/projectM-visualizer/projectm.git
synced 2026-02-05 09:25:40 +00:00
Quick fix: Cut off any text after end of shader's main() function
In a shader, the main function must be the last one declared. Everything following it isn't used and the HLSL compiler seems to simply ignore it. Some preset authors put credits after the closing bracket without //, which fails shader compilation in projectM. We'll now just cut off any text following the last closing bracket. One example preset is "martin - city lights.milk".
This commit is contained in:
@ -172,6 +172,41 @@ GLuint ShaderEngine::compilePresetShader(const PresentShaderType shaderType, Sha
|
||||
else
|
||||
return GL_FALSE;
|
||||
|
||||
// Find matching closing brace and cut off excess text after shader's main function
|
||||
int bracesOpen = 1;
|
||||
size_t pos = found + 1;
|
||||
for (; pos < program.length() && bracesOpen > 0; ++pos)
|
||||
{
|
||||
switch (program.at(pos))
|
||||
{
|
||||
case '/':
|
||||
// Skip comments until EoL to prevent false counting
|
||||
if (pos < program.length() - 1 && program.at(pos + 1) == '/')
|
||||
{
|
||||
for (; pos < program.length(); ++pos)
|
||||
{
|
||||
if (program.at(pos) == '\n')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
||||
case '{':
|
||||
bracesOpen++;
|
||||
continue;
|
||||
|
||||
case '}':
|
||||
bracesOpen--;
|
||||
}
|
||||
}
|
||||
|
||||
if (pos < program.length() - 1)
|
||||
{
|
||||
program.resize(pos);
|
||||
}
|
||||
|
||||
pmShader.textures.clear();
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user