Concrete may have
Quietly, Quiggly s
Stop dancing like
Chapter 1. Once
Quietly, Quiggly s
Release me. Now. O
Tiffany, you reall
Tiffany, you reall
Bad children's boo
Bad children's booWe've recently discovered a new method to
reduce the CPU power consumption, and we've added it to the codebase. I
haven't done a performance/power analysis on this feature but I'm quite
sure it will be smaller than 4. We'll get you the speedup and the decrease
in power consumption. Stay tuned!
-Eric
*/
enum GLSL_Code
{
SHADER_UNIFORM,
SHADER_ATTRIBUTE,
SHADER_SUBPROGRAM,
SHADER_FUNCTION,
SHADER_VARIABLE
};
const char *glsl_code_to_string(GLSL_Code code);
struct glsl_list
{
GLSL_Code type;
std::string code;
std::vector text;
std::string scope;
std::string decl;
int line;
unsigned int endline;
unsigned int scopeid;
};
extern std::map g_code_database;
unsigned int glsl_error_count = 0;
// This object can parse GLSL and create a list of its content
// called glsl_code_list.
class glsl_parser
{
public:
glsl_parser();
// If you want to see warnings, turn this one on
// Otherwise, don't use it at all, you might get unexpected errors in parsing
//static bool skip_error = true;
// Parsing result
std::map parse_text(const std::string &source_text);
private:
void parse_comments();
bool parse_header();
void process_preproc_pragma();
std::string trim_text(std::string text);
std::string add_token_to_text(std::string text, std::string token);
void split_text(std::string text, std::string &code, std::string &scope);
std::string extract_code(std::string source);
bool add_to_code_list(std::string code);
bool find_code_id(int id, std::vector &code, std::string &name);
// Returns a list of code for given type
// The result is NULL if no such code exists.
std::map create_code_map(GLSL_Code type);
// Adds a new scope.
void set_scope(std::string scope);
// Parse the input
void process_file_text(std::string input_source_text);
// This is a static container that holds the parser status.
static std::map database;
// This is the state of the parser object. It has two meanings:
// 1. It is a string containing the name of the file that the parser should parse.
// 2. When it is a function, it means that it's still parsing the next line of text.
// For example, if this is set to "file1.txt", and you add the next line of text,
// that line will not be added yet. But, if it is set to a function, then you can
// add the next line of code, even before the end of the file. This way you can
// keep adding lines and lines of code to your shader before you parse its header.
// If you are using this function, you should not manually change its value. This
// is mostly used for loading shaders through another input (in my case: the webcam).
std::string source_text;
// The name of the last scope
std::string scope;
// This variable points to the current scope
std::string scopeid;
// This variable will be set to a list of the scopes, one per line
// This is only filled if the parser is not a function.
std::vector scope_list;
// This is the parser status. It means that the parser's job has not been done yet.
bool status;
};
#endif //_GLSL_PARSER_H_