diff options
author | Brian Paul <brianp@vmware.com> | 2009-01-07 18:44:00 -0700 |
---|---|---|
committer | Alan Hourihane <alanh@vmware.com> | 2009-01-09 11:16:38 +0000 |
commit | d33b0f1a8d7eb295cc403b12dce9d56b3f0393b2 (patch) | |
tree | 10b760f02ed28b270b6ad3d145edd6f9f16d7be8 | |
parent | 1169457ecaa470191f56bd740de90585d8eb349a (diff) |
glsl: pass GLcontext::Extension info down into GLSL preprocessor
Now the #extension directives can be handled properly.
-rw-r--r-- | src/mesa/shader/slang/slang_compile.c | 14 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_preprocess.c | 80 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_preprocess.h | 6 |
3 files changed, 65 insertions, 35 deletions
diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index b8044b1060..0a527f3220 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -2474,7 +2474,8 @@ static GLboolean compile_with_grammar(grammar id, const char *source, slang_code_unit * unit, slang_unit_type type, slang_info_log * infolog, slang_code_unit * builtin, - struct gl_shader *shader) + struct gl_shader *shader, + const struct gl_extensions *extensions) { byte *prod; GLuint size, start, version; @@ -2502,7 +2503,8 @@ compile_with_grammar(grammar id, const char *source, slang_code_unit * unit, /* Now preprocess the source string. */ slang_string_init(&preprocessed); - if (!_slang_preprocess_directives(&preprocessed, &source[start], infolog)) { + if (!_slang_preprocess_directives(&preprocessed, &source[start], + infolog, extensions)) { slang_string_free(&preprocessed); slang_info_log_error(infolog, "failed to preprocess the source."); return GL_FALSE; @@ -2575,7 +2577,8 @@ static const byte slang_vertex_builtin_gc[] = { static GLboolean compile_object(grammar * id, const char *source, slang_code_object * object, slang_unit_type type, slang_info_log * infolog, - struct gl_shader *shader) + struct gl_shader *shader, + const struct gl_extensions *extensions) { slang_code_unit *builtins = NULL; GLuint base_version = 110; @@ -2674,7 +2677,7 @@ compile_object(grammar * id, const char *source, slang_code_object * object, /* compile the actual shader - pass-in built-in library for external shader */ return compile_with_grammar(*id, source, &object->unit, type, infolog, - builtins, shader); + builtins, shader, extensions); } @@ -2697,7 +2700,8 @@ compile_shader(GLcontext *ctx, slang_code_object * object, _slang_code_object_dtr(object); _slang_code_object_ctr(object); - success = compile_object(&id, shader->Source, object, type, infolog, shader); + success = compile_object(&id, shader->Source, object, type, infolog, shader, + &ctx->Extensions); if (id != 0) grammar_destroy(id); if (!success) diff --git a/src/mesa/shader/slang/slang_preprocess.c b/src/mesa/shader/slang/slang_preprocess.c index 7d971627f5..76e757cb38 100644 --- a/src/mesa/shader/slang/slang_preprocess.c +++ b/src/mesa/shader/slang/slang_preprocess.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.5.2 * - * Copyright (C) 2005-2006 Brian Paul All Rights Reserved. + * Copyright (C) 2005-2008 Brian Paul All Rights Reserved. + * Copyright (C) 2009 VMware, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -475,52 +475,63 @@ pp_cond_stack_reevaluate (pp_cond_stack *self) self->top->effective = self->top->current && self->top[1].effective; } -/* + +/** * Extension enables through #extension directive. * NOTE: Currently, only enable/disable state is stored. */ - typedef struct { - GLboolean MESA_shader_debug; /* GL_MESA_shader_debug enable */ - GLboolean ARB_texture_rectangle; /* GL_ARB_texture_rectangle enable */ + GLboolean ARB_draw_buffers; + GLboolean ARB_texture_rectangle; } pp_ext; -/* + +/** * Disable all extensions. Called at startup and on #extension all: disable. */ static GLvoid -pp_ext_disable_all (pp_ext *self) +pp_ext_disable_all(pp_ext *self) { - self->MESA_shader_debug = GL_FALSE; + _mesa_memset(self, 0, sizeof(self)); } + +/** + * Called during preprocessor initialization to set the initial enable/disable + * state of extensions. + */ static GLvoid -pp_ext_init (pp_ext *self) +pp_ext_init(pp_ext *self, const struct gl_extensions *extensions) { pp_ext_disable_all (self); - self->ARB_texture_rectangle = GL_TRUE; - /* Other initialization code goes here. */ + if (extensions->ARB_draw_buffers) + self->ARB_draw_buffers = GL_TRUE; + if (extensions->NV_texture_rectangle) + self->ARB_texture_rectangle = GL_TRUE; } +/** + * Called in response to #extension directives to enable/disable + * the named extension. + */ static GLboolean -pp_ext_set (pp_ext *self, const char *name, GLboolean enable) +pp_ext_set(pp_ext *self, const char *name, GLboolean enable) { - if (_mesa_strcmp (name, "MESA_shader_debug") == 0) - self->MESA_shader_debug = enable; + if (_mesa_strcmp (name, "GL_ARB_draw_buffers") == 0) + self->ARB_draw_buffers = enable; else if (_mesa_strcmp (name, "GL_ARB_texture_rectangle") == 0) self->ARB_texture_rectangle = enable; - /* Next extension name tests go here. */ else return GL_FALSE; return GL_TRUE; } -/* - * The state of preprocessor: current line, file and version number, list of all defined macros - * and the #if/#endif context. - */ +/** + * The state of preprocessor: current line, file and version number, list + * of all defined macros and the #if/#endif context. + */ typedef struct { GLint line; @@ -533,7 +544,8 @@ typedef struct } pp_state; static GLvoid -pp_state_init (pp_state *self, slang_info_log *elog) +pp_state_init (pp_state *self, slang_info_log *elog, + const struct gl_extensions *extensions) { self->line = 0; self->file = 1; @@ -543,7 +555,7 @@ pp_state_init (pp_state *self, slang_info_log *elog) self->version = 110; #endif pp_symbols_init (&self->symbols); - pp_ext_init (&self->ext); + pp_ext_init (&self->ext, extensions); self->elog = elog; /* Initialize condition stack and create the global context. */ @@ -851,8 +863,10 @@ parse_if (slang_string *output, const byte *prod, GLuint *pi, GLint *result, pp_ #define BEHAVIOR_DISABLE 4 static GLboolean -preprocess_source (slang_string *output, const char *source, grammar pid, grammar eid, - slang_info_log *elog) +preprocess_source (slang_string *output, const char *source, + grammar pid, grammar eid, + slang_info_log *elog, + const struct gl_extensions *extensions) { static const char *predefined[] = { "__FILE__", @@ -873,7 +887,7 @@ preprocess_source (slang_string *output, const char *source, grammar pid, gramma return GL_FALSE; } - pp_state_init (&state, elog); + pp_state_init (&state, elog, extensions); /* add the predefined symbols to the symbol table */ for (i = 0; predefined[i]; i++) { @@ -1196,8 +1210,20 @@ error: return GL_FALSE; } + +/** + * Run preprocessor on source code. + * \param extensions indicates which GL extensions are enabled + * \param output the post-process results + * \param input the input text + * \param elog log to record warnings, errors + * \return GL_TRUE for success, GL_FALSE for error + */ GLboolean -_slang_preprocess_directives (slang_string *output, const char *input, slang_info_log *elog) +_slang_preprocess_directives(slang_string *output, + const char *input, + slang_info_log *elog, + const struct gl_extensions *extensions) { grammar pid, eid; GLboolean success; @@ -1213,7 +1239,7 @@ _slang_preprocess_directives (slang_string *output, const char *input, slang_inf grammar_destroy (pid); return GL_FALSE; } - success = preprocess_source (output, input, pid, eid, elog); + success = preprocess_source (output, input, pid, eid, elog, extensions); grammar_destroy (eid); grammar_destroy (pid); return success; diff --git a/src/mesa/shader/slang/slang_preprocess.h b/src/mesa/shader/slang/slang_preprocess.h index d8eb12e4ff..dd996a6314 100644 --- a/src/mesa/shader/slang/slang_preprocess.h +++ b/src/mesa/shader/slang/slang_preprocess.h @@ -33,8 +33,8 @@ extern GLboolean _slang_preprocess_version (const char *, GLuint *, GLuint *, slang_info_log *); extern GLboolean -_slang_preprocess_directives (slang_string *output, const char *input, - slang_info_log *); - +_slang_preprocess_directives(slang_string *output, const char *input, + slang_info_log *, + const struct gl_extensions *extensions); #endif /* SLANG_PREPROCESS_H */ |