mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 22:20:21 +00:00
(glslang_util_cxx.cpp) Use string_starts_with
This commit is contained in:
parent
c600fbc6ff
commit
fe8a191012
@ -43,9 +43,9 @@ static std::string build_stage_source(
|
||||
* there is nothing to be gained from trying to replace
|
||||
* this ostringstream with a C-based alternative
|
||||
* (would require a rewrite of deps/glslang/glslang.cpp) */
|
||||
size_t i;
|
||||
std::ostringstream str;
|
||||
bool active = true;
|
||||
size_t i;
|
||||
|
||||
if (!lines)
|
||||
return "";
|
||||
@ -61,26 +61,33 @@ static std::string build_stage_source(
|
||||
{
|
||||
const char *line = lines->elems[i].data;
|
||||
|
||||
/* Identify 'stage' (fragment/vertex) */
|
||||
if (!strncmp("#pragma stage ", line, STRLEN_CONST("#pragma stage ")))
|
||||
if (string_starts_with(line, "#pragma"))
|
||||
{
|
||||
if (!string_is_empty(stage))
|
||||
/* Identify 'stage' (fragment/vertex) */
|
||||
if (!strncmp("#pragma stage ", line, STRLEN_CONST("#pragma stage ")))
|
||||
{
|
||||
char expected[128];
|
||||
if (!string_is_empty(stage))
|
||||
{
|
||||
char expected[128];
|
||||
|
||||
expected[0] = '\0';
|
||||
expected[0] = '\0';
|
||||
|
||||
strlcpy(expected, "#pragma stage ", sizeof(expected));
|
||||
strlcat(expected, stage, sizeof(expected));
|
||||
strlcpy(expected, "#pragma stage ", sizeof(expected));
|
||||
strlcat(expected, stage, sizeof(expected));
|
||||
|
||||
active = string_is_equal(expected, line);
|
||||
active = string_is_equal(expected, line);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (
|
||||
!strncmp("#pragma name ", line, STRLEN_CONST("#pragma name ")) ||
|
||||
!strncmp("#pragma format ", line, STRLEN_CONST("#pragma format ")))
|
||||
{
|
||||
/* Ignore */
|
||||
else if (
|
||||
!strncmp("#pragma name ", line,
|
||||
STRLEN_CONST("#pragma name ")) ||
|
||||
!strncmp("#pragma format ", line,
|
||||
STRLEN_CONST("#pragma format ")))
|
||||
{
|
||||
/* Ignore */
|
||||
}
|
||||
else if (active)
|
||||
str << line;
|
||||
}
|
||||
else if (active)
|
||||
str << line;
|
||||
@ -104,107 +111,110 @@ bool glslang_parse_meta(const struct string_list *lines, glslang_meta *meta)
|
||||
{
|
||||
const char *line = lines->elems[i].data;
|
||||
|
||||
/* Check for shader identifier */
|
||||
if (!strncmp("#pragma name ", line,
|
||||
STRLEN_CONST("#pragma name ")))
|
||||
if (string_starts_with(line, "#pragma"))
|
||||
{
|
||||
const char *str = NULL;
|
||||
|
||||
if (!meta->name.empty())
|
||||
/* Check for shader identifier */
|
||||
if (!strncmp("#pragma name ", line,
|
||||
STRLEN_CONST("#pragma name ")))
|
||||
{
|
||||
RARCH_ERR("[slang]: Trying to declare multiple names for file.\n");
|
||||
return false;
|
||||
}
|
||||
const char *str = NULL;
|
||||
|
||||
str = line + STRLEN_CONST("#pragma name ");
|
||||
while (*str == ' ')
|
||||
str++;
|
||||
|
||||
meta->name = str;
|
||||
}
|
||||
/* Check for shader parameters */
|
||||
else if (!strncmp("#pragma parameter ", line,
|
||||
STRLEN_CONST("#pragma parameter ")))
|
||||
{
|
||||
float initial, minimum, maximum, step;
|
||||
int ret = sscanf(
|
||||
line, "#pragma parameter %63s \"%63[^\"]\" %f %f %f %f",
|
||||
id, desc, &initial, &minimum, &maximum, &step);
|
||||
|
||||
if (ret == 5)
|
||||
{
|
||||
step = 0.1f * (maximum - minimum);
|
||||
ret = 6;
|
||||
}
|
||||
|
||||
if (ret == 6)
|
||||
{
|
||||
bool parameter_found = false;
|
||||
size_t parameter_index = 0;
|
||||
size_t j;
|
||||
|
||||
for (j = 0; j < meta->parameters.size(); j++)
|
||||
if (!meta->name.empty())
|
||||
{
|
||||
/* Note: LHS is a std:string, RHS is a C string.
|
||||
* (the glslang_meta stuff has to be C++) */
|
||||
if (meta->parameters[j].id == id)
|
||||
{
|
||||
parameter_found = true;
|
||||
parameter_index = j;
|
||||
break;
|
||||
}
|
||||
RARCH_ERR("[slang]: Trying to declare multiple names for file.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Allow duplicate #pragma parameter, but only
|
||||
* if they are exactly the same. */
|
||||
if (parameter_found)
|
||||
{
|
||||
const glslang_parameter *parameter =
|
||||
&meta->parameters[parameter_index];
|
||||
str = line + STRLEN_CONST("#pragma name ");
|
||||
while (*str == ' ')
|
||||
str++;
|
||||
|
||||
if ( parameter->desc != desc ||
|
||||
parameter->initial != initial ||
|
||||
parameter->minimum != minimum ||
|
||||
parameter->maximum != maximum ||
|
||||
parameter->step != step
|
||||
)
|
||||
meta->name = str;
|
||||
}
|
||||
/* Check for shader parameters */
|
||||
else if (!strncmp("#pragma parameter ", line,
|
||||
STRLEN_CONST("#pragma parameter ")))
|
||||
{
|
||||
float initial, minimum, maximum, step;
|
||||
int ret = sscanf(
|
||||
line, "#pragma parameter %63s \"%63[^\"]\" %f %f %f %f",
|
||||
id, desc, &initial, &minimum, &maximum, &step);
|
||||
|
||||
if (ret == 5)
|
||||
{
|
||||
step = 0.1f * (maximum - minimum);
|
||||
ret = 6;
|
||||
}
|
||||
|
||||
if (ret == 6)
|
||||
{
|
||||
bool parameter_found = false;
|
||||
size_t parameter_index = 0;
|
||||
size_t j;
|
||||
|
||||
for (j = 0; j < meta->parameters.size(); j++)
|
||||
{
|
||||
RARCH_ERR("[slang]: Duplicate parameters found for \"%s\", but arguments do not match.\n", id);
|
||||
return false;
|
||||
/* Note: LHS is a std:string, RHS is a C string.
|
||||
* (the glslang_meta stuff has to be C++) */
|
||||
if (meta->parameters[j].id == id)
|
||||
{
|
||||
parameter_found = true;
|
||||
parameter_index = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Allow duplicate #pragma parameter, but only
|
||||
* if they are exactly the same. */
|
||||
if (parameter_found)
|
||||
{
|
||||
const glslang_parameter *parameter =
|
||||
&meta->parameters[parameter_index];
|
||||
|
||||
if ( parameter->desc != desc ||
|
||||
parameter->initial != initial ||
|
||||
parameter->minimum != minimum ||
|
||||
parameter->maximum != maximum ||
|
||||
parameter->step != step
|
||||
)
|
||||
{
|
||||
RARCH_ERR("[slang]: Duplicate parameters found for \"%s\", but arguments do not match.\n", id);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
meta->parameters.push_back({ id, desc, initial, minimum, maximum, step });
|
||||
}
|
||||
else
|
||||
meta->parameters.push_back({ id, desc, initial, minimum, maximum, step });
|
||||
{
|
||||
RARCH_ERR("[slang]: Invalid #pragma parameter line: \"%s\".\n",
|
||||
line);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
/* Check for framebuffer format */
|
||||
else if (!strncmp("#pragma format ", line,
|
||||
STRLEN_CONST("#pragma format ")))
|
||||
{
|
||||
RARCH_ERR("[slang]: Invalid #pragma parameter line: \"%s\".\n",
|
||||
line);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/* Check for framebuffer format */
|
||||
else if (!strncmp("#pragma format ", line,
|
||||
STRLEN_CONST("#pragma format ")))
|
||||
{
|
||||
const char *str = NULL;
|
||||
const char *str = NULL;
|
||||
|
||||
if (meta->rt_format != SLANG_FORMAT_UNKNOWN)
|
||||
{
|
||||
RARCH_ERR("[slang]: Trying to declare format multiple times for file.\n");
|
||||
return false;
|
||||
}
|
||||
if (meta->rt_format != SLANG_FORMAT_UNKNOWN)
|
||||
{
|
||||
RARCH_ERR("[slang]: Trying to declare format multiple times for file.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
str = line + STRLEN_CONST("#pragma format ");
|
||||
while (*str == ' ')
|
||||
str++;
|
||||
str = line + STRLEN_CONST("#pragma format ");
|
||||
while (*str == ' ')
|
||||
str++;
|
||||
|
||||
meta->rt_format = glslang_find_format(str);
|
||||
meta->rt_format = glslang_find_format(str);
|
||||
|
||||
if (meta->rt_format == SLANG_FORMAT_UNKNOWN)
|
||||
{
|
||||
RARCH_ERR("[slang]: Failed to find format \"%s\".\n", str);
|
||||
return false;
|
||||
if (meta->rt_format == SLANG_FORMAT_UNKNOWN)
|
||||
{
|
||||
RARCH_ERR("[slang]: Failed to find format \"%s\".\n", str);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user