summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2010-06-30 16:27:22 -0700
committerIan Romanick <[email protected]>2010-07-01 20:40:08 -0700
commit06143ea09411aa283ac3633bfbfa4326584cd952 (patch)
tree9823df6abda22c93745029eecd930e85fd9241f7
parent2d1223611700b33aab084f1927bfc1ff1b284115 (diff)
glsl2: Conditionally define preprocessor tokens for optional extensions
The only optional extension currently supported by the compiler is GL_EXT_texture_array.
-rw-r--r--src/glsl/glcpp/glcpp-parse.y10
-rw-r--r--src/glsl/glcpp/glcpp.c5
-rw-r--r--src/glsl/glcpp/glcpp.h7
-rw-r--r--src/glsl/glcpp/pp.c5
-rw-r--r--src/glsl/glsl_parser_extras.h3
-rw-r--r--src/glsl/main.cpp4
-rw-r--r--src/mesa/shader/ir_to_mesa.cpp3
7 files changed, 25 insertions, 12 deletions
diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index d4cb006bbcd..e5544fe29b8 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 @@ yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error)
}
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 @@ glcpp_parser_create (void)
_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 cc87e14950b..a245cb54060 100644
--- a/src/glsl/glcpp/glcpp.c
+++ b/src/glsl/glcpp/glcpp.c
@@ -69,15 +69,12 @@ load_text_file(void *ctx, const char *file_name)
}
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 2cfa98d2b1d..fc9511a67a8 100644
--- a/src/glsl/glcpp/glcpp.h
+++ b/src/glsl/glcpp/glcpp.h
@@ -158,8 +158,10 @@ struct glcpp_parser {
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 @@ void
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 a25b7b72a6b..1ce829a2c97 100644
--- a/src/glsl/glcpp/pp.c
+++ b/src/glsl/glcpp/pp.c
@@ -134,10 +134,11 @@ remove_line_continuations(glcpp_parser_t *ctx, const char *shader)
}
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);
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index 3aeba83cc52..dc3d23ac545 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -115,7 +115,8 @@ extern void _mesa_glsl_warning(const YYLTYPE *locp,
const char *fmt, ...);
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,
diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp
index c833c9cde6d..deaab7e0335 100644
--- a/src/glsl/main.cpp
+++ b/src/glsl/main.cpp
@@ -109,6 +109,7 @@ void
compile_shader(struct gl_shader *shader)
{
struct _mesa_glsl_parse_state *state;
+ struct gl_extensions ext;
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->ARB_texture_rectangle_enable = true;
+ memset(&ext, 0, sizeof(ext));
state->Const.MaxDrawBuffers = 2;
state->Const.MaxTextureCoords = 4;
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) {
_mesa_glsl_lexer_ctor(state, source);
diff --git a/src/mesa/shader/ir_to_mesa.cpp b/src/mesa/shader/ir_to_mesa.cpp
index 14abf602af2..918004c79f1 100644
--- a/src/mesa/shader/ir_to_mesa.cpp
+++ b/src/mesa/shader/ir_to_mesa.cpp
@@ -1713,7 +1713,8 @@ _mesa_glsl_compile_shader(GLcontext *ctx, struct gl_shader *shader)
state->Const.MaxTextureCoords = ctx->Const.MaxTextureCoordUnits;
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) {
_mesa_glsl_lexer_ctor(state, source);