[glsl] Put #line after any #version lines in the chunks

The GLSL compiler requires any #version lines to be the first (real)
line of the program, even #line causes an error, so if the first line of
the chunk starts with #version, insert the #line directive as the second
line.
This commit is contained in:
Bill Currie 2022-03-25 01:17:12 +09:00
parent 00362e9f4e
commit e263521330

View file

@ -129,8 +129,17 @@ GLSL_BuildShader (const char **effect_keys)
Sys_Printf ("Unknown shader key: '%s'\n", dot); Sys_Printf ("Unknown shader key: '%s'\n", dot);
goto error; goto error;
} }
shader->strings[num] = nva ("#line %d\n%s", chunk->start_line, if (strncmp ("#version ", chunk->text, 9) == 0) {
chunk->text); const char *eol = strchr (chunk->text, '\n');
int vline_len = eol ? eol - chunk->text + 1 : 0;
shader->strings[num] = nva ("%.*s#line %d\n%s", vline_len,
chunk->text,
chunk->start_line + 1,
chunk->text + vline_len);
} else {
shader->strings[num] = nva ("#line %d\n%s", chunk->start_line,
chunk->text);
}
shader->src[num] = strdup (ekey->str); shader->src[num] = strdup (ekey->str);
} }
dstring_delete (ekey); dstring_delete (ekey);