glsl2: Conditionally define preprocessor tokens for optional extensions
The only optional extension currently supported by the compiler is
GL_EXT_texture_array.
diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index d4cb006..e5544fe 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -28,6 +28,7 @@
#include <inttypes.h>
#include "glcpp.h"
+#include "main/mtypes.h"
#define glcpp_print(stream, str) stream = talloc_strdup_append(stream, str)
#define glcpp_printf(stream, fmt, args...) \
@@ -894,7 +895,7 @@
}
glcpp_parser_t *
-glcpp_parser_create (void)
+glcpp_parser_create (const struct gl_extensions *extensions)
{
glcpp_parser_t *parser;
token_t *tok;
@@ -932,6 +933,13 @@
_token_list_append(list, tok);
_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);
return parser;
diff --git a/src/glsl/glcpp/glcpp.c b/src/glsl/glcpp/glcpp.c
index cc87e14..a245cb540 100644
--- a/src/glsl/glcpp/glcpp.c
+++ b/src/glsl/glcpp/glcpp.c
@@ -69,15 +69,12 @@
}
int
-preprocess(void *talloc_ctx, const char **shader, char **info_log);
-
-int
main (void)
{
void *ctx = talloc(NULL, void*);
const char *shader = load_text_file(ctx, NULL);
char *info_log = talloc_strdup(ctx, "");
- int ret = preprocess(ctx, &shader, &info_log);
+ int ret = preprocess(ctx, &shader, &info_log, NULL);
printf("%s", shader);
fprintf(stderr, "%s", info_log);
diff --git a/src/glsl/glcpp/glcpp.h b/src/glsl/glcpp/glcpp.h
index 2cfa98d..fc9511a 100644
--- a/src/glsl/glcpp/glcpp.h
+++ b/src/glsl/glcpp/glcpp.h
@@ -158,8 +158,10 @@
int error;
};
+struct gl_extensions;
+
glcpp_parser_t *
-glcpp_parser_create (void);
+glcpp_parser_create (const struct gl_extensions *extensions);
int
glcpp_parser_parse (glcpp_parser_t *parser);
@@ -168,7 +170,8 @@
glcpp_parser_destroy (glcpp_parser_t *parser);
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 */
diff --git a/src/glsl/glcpp/pp.c b/src/glsl/glcpp/pp.c
index a25b7b7..1ce829a 100644
--- a/src/glsl/glcpp/pp.c
+++ b/src/glsl/glcpp/pp.c
@@ -134,10 +134,11 @@
}
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;
- glcpp_parser_t *parser = glcpp_parser_create ();
+ glcpp_parser_t *parser = glcpp_parser_create (extensions);
*shader = remove_line_continuations(parser, *shader);
glcpp_lex_set_source_string (parser, *shader);