/****************************************************************************** Copyright (C) 2013 by Hugh Bailey This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ******************************************************************************/ #ifndef GL_SHADER_PARSER_H #define GL_SHADER_PARSER_H /* * Parses shaders into GLSL. Shaders are almost identical to HLSL * model 5 so it requires quite a bit of tweaking to convert correctly. * Takes the parsed shader data, and builds a GLSL string out of it. */ #include "util/dstr.h" #include "graphics/shader-parser.h" struct gl_parser_attrib { struct dstr name; const char *mapping; }; static inline gl_parser_attrib_free(struct gl_parser_attrib *attr) { dstr_free(&attr->name); } struct gl_shader_parser { struct shader_parser parser; struct dstr gl_string; DARRAY(uint32_t) texture_samplers; DARRAY(struct gl_parser_attrib) attribs; }; static inline void gl_shader_parser_init(struct gl_shader_parser *glsp) { shader_parser_init(&glsp->parser); dstr_init(&glsp->gl_string); da_init(glsp->texture_samplers); da_init(glsp->attribs); } static inline void gl_shader_parser_free(struct gl_shader_parser *glsp) { size_t i; for (i = 0; i < glsp->attribs.num; i++) gl_parser_attrib_free(glsp->attribs.array+i); da_free(glsp->attribs); da_free(glsp->texture_samplers); dstr_free(&glsp->gl_string); shader_parser_free(&glsp->parser); } extern bool gl_shader_parse(struct gl_shader_parser *glsp, const char *shader_str, const char *file); #endif