[Mesa-dev] [PATCH] TransformFeedback: Assign transform feedback varying slots in linker.
Marek Olšák
maraeo at gmail.com
Mon Oct 24 12:40:04 PDT 2011
Hi Dan,
I have written this function to parse expressions of the form
"name[x]" for parsing the list of transform feedback varyings with
indexing. It's good enough to pass the piglit tests, but I am not sure
whether it's good enough for GLSL 1.3. I use this code to query
locations of indexed varyings, particularly "gl_TexCoord[1]" in one of
my tests. Feel free to use this code.
My question to the others is whether this is the way it should be
done, or whether there is a better way. Thanks.
Marek
#include <cmath>
#ifndef Elements
#define Elements(x) (sizeof(x)/sizeof(*(x)))
#endif
struct tfeedback_decl {
char name[1024];
bool is_array;
unsigned array_index;
};
/* This expects expressions of the form "var" and "var[i]",
* where i is a literal.
*
* We don't have to be pedantic about what is a valid GLSL variable name,
* because any variable with an invalid name can't exist in the IR anyway. */
static bool parse_tfeedback_decl(const char *input,
struct tfeedback_decl *decl)
{
unsigned name_index = 0;
decl->is_array = false;
/* Parse the variable name. */
while (*input &&
((*input > 'a' && *input < 'z') ||
(*input > 'A' && *input < 'Z') ||
(*input > '0' && *input < '9') ||
*input == '_') &&
name_index < Elements(decl->name)-1) {
decl->name[name_index++] = *input;
input++;
}
decl->name[name_index++] = 0;
if (!*input) {
return true;
}
/* Parse the array index. */
if (*input == '[') {
input++;
if (*input && *input >= '0' && *input <= '9' &&
sscanf(input, "%u", &decl->array_index) == 1) {
decl->is_array = true;
input += (unsigned)(log(decl->array_index)/log(10)) + 1;
if (*input && *input == ']') {
input++;
if (!*input) {
return true;
}
}
}
}
return false;
}
More information about the mesa-dev
mailing list