glsl2: Conditionally define preprocessor tokens for optional extensions

The only optional extension currently supported by the compiler is
GL_EXT_texture_array.
This commit is contained in:
Ian Romanick
2010-06-30 16:27:22 -07:00
parent 2d12236117
commit 06143ea094
7 changed files with 25 additions and 12 deletions

View File

@@ -28,6 +28,7 @@
#include <inttypes.h> #include <inttypes.h>
#include "glcpp.h" #include "glcpp.h"
#include "main/mtypes.h"
#define glcpp_print(stream, str) stream = talloc_strdup_append(stream, str) #define glcpp_print(stream, str) stream = talloc_strdup_append(stream, str)
#define glcpp_printf(stream, fmt, args...) \ #define glcpp_printf(stream, fmt, args...) \
@@ -894,7 +895,7 @@ yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error)
} }
glcpp_parser_t * glcpp_parser_t *
glcpp_parser_create (void) glcpp_parser_create (const struct gl_extensions *extensions)
{ {
glcpp_parser_t *parser; glcpp_parser_t *parser;
token_t *tok; token_t *tok;
@@ -932,6 +933,13 @@ glcpp_parser_create (void)
_token_list_append(list, tok); _token_list_append(list, tok);
_define_object_macro(parser, NULL, "GL_ARB_texture_rectangle", list); _define_object_macro(parser, NULL, "GL_ARB_texture_rectangle", list);
if ((extensions != NULL) && extensions->EXT_texture_array) {
list = _token_list_create(parser);
_token_list_append(list, tok);
_define_object_macro(parser, NULL,
"GL_EXT_texture_array", list);
}
talloc_unlink(parser, tok); talloc_unlink(parser, tok);
return parser; return parser;

View File

@@ -68,16 +68,13 @@ load_text_file(void *ctx, const char *file_name)
return text; return text;
} }
int
preprocess(void *talloc_ctx, const char **shader, char **info_log);
int int
main (void) main (void)
{ {
void *ctx = talloc(NULL, void*); void *ctx = talloc(NULL, void*);
const char *shader = load_text_file(ctx, NULL); const char *shader = load_text_file(ctx, NULL);
char *info_log = talloc_strdup(ctx, ""); char *info_log = talloc_strdup(ctx, "");
int ret = preprocess(ctx, &shader, &info_log); int ret = preprocess(ctx, &shader, &info_log, NULL);
printf("%s", shader); printf("%s", shader);
fprintf(stderr, "%s", info_log); fprintf(stderr, "%s", info_log);

View File

@@ -158,8 +158,10 @@ struct glcpp_parser {
int error; int error;
}; };
struct gl_extensions;
glcpp_parser_t * glcpp_parser_t *
glcpp_parser_create (void); glcpp_parser_create (const struct gl_extensions *extensions);
int int
glcpp_parser_parse (glcpp_parser_t *parser); glcpp_parser_parse (glcpp_parser_t *parser);
@@ -168,7 +170,8 @@ void
glcpp_parser_destroy (glcpp_parser_t *parser); glcpp_parser_destroy (glcpp_parser_t *parser);
int int
preprocess(void *talloc_ctx, const char **shader, char **info_log); preprocess(void *talloc_ctx, const char **shader, char **info_log,
const struct gl_extensions *extensions);
/* Functions for writing to the info log */ /* Functions for writing to the info log */

View File

@@ -134,10 +134,11 @@ remove_line_continuations(glcpp_parser_t *ctx, const char *shader)
} }
extern int extern int
preprocess(void *talloc_ctx, const char **shader, char **info_log) preprocess(void *talloc_ctx, const char **shader, char **info_log,
const struct gl_extensions *extensions)
{ {
int errors; int errors;
glcpp_parser_t *parser = glcpp_parser_create (); glcpp_parser_t *parser = glcpp_parser_create (extensions);
*shader = remove_line_continuations(parser, *shader); *shader = remove_line_continuations(parser, *shader);
glcpp_lex_set_source_string (parser, *shader); glcpp_lex_set_source_string (parser, *shader);

View File

@@ -115,7 +115,8 @@ extern void _mesa_glsl_warning(const YYLTYPE *locp,
const char *fmt, ...); const char *fmt, ...);
extern "C" { extern "C" {
extern int preprocess(void *ctx, const char **shader, char **info_log); extern int preprocess(void *ctx, const char **shader, char **info_log,
const struct gl_extensions *extensions);
} }
extern void _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, extern void _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state,

View File

@@ -109,6 +109,7 @@ void
compile_shader(struct gl_shader *shader) compile_shader(struct gl_shader *shader)
{ {
struct _mesa_glsl_parse_state *state; struct _mesa_glsl_parse_state *state;
struct gl_extensions ext;
state = talloc_zero(talloc_parent(shader), struct _mesa_glsl_parse_state); state = talloc_zero(talloc_parent(shader), struct _mesa_glsl_parse_state);
@@ -127,11 +128,12 @@ compile_shader(struct gl_shader *shader)
state->loop_or_switch_nesting = NULL; state->loop_or_switch_nesting = NULL;
state->ARB_texture_rectangle_enable = true; state->ARB_texture_rectangle_enable = true;
memset(&ext, 0, sizeof(ext));
state->Const.MaxDrawBuffers = 2; state->Const.MaxDrawBuffers = 2;
state->Const.MaxTextureCoords = 4; state->Const.MaxTextureCoords = 4;
const char *source = shader->Source; const char *source = shader->Source;
state->error = preprocess(state, &source, &state->info_log); state->error = preprocess(state, &source, &state->info_log, &ext);
if (!state->error) { if (!state->error) {
_mesa_glsl_lexer_ctor(state, source); _mesa_glsl_lexer_ctor(state, source);

View File

@@ -1713,7 +1713,8 @@ _mesa_glsl_compile_shader(GLcontext *ctx, struct gl_shader *shader)
state->Const.MaxTextureCoords = ctx->Const.MaxTextureCoordUnits; state->Const.MaxTextureCoords = ctx->Const.MaxTextureCoordUnits;
const char *source = shader->Source; const char *source = shader->Source;
state->error = preprocess(state, &source, &state->info_log); state->error = preprocess(state, &source, &state->info_log,
&ctx->Extensions);
if (!state->error) { if (!state->error) {
_mesa_glsl_lexer_ctor(state, source); _mesa_glsl_lexer_ctor(state, source);