From de5928a61549a6ca66e6b9ff6e50b305f653888c Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 16 Feb 2010 10:42:05 -0700 Subject: sl/pp: re-do extension testing code The #extension directive should not effect which extension preprocessor symbols are defined/undefined; only whether/how the compiler accepts language features defined by the extension. --- src/glsl/pp/sl_pp_context.h | 9 ++++++++- src/glsl/pp/sl_pp_extension.c | 28 +++++++++++++++++++++++----- src/glsl/pp/sl_pp_if.c | 2 +- src/glsl/pp/sl_pp_public.h | 4 ++++ 4 files changed, 36 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/glsl/pp/sl_pp_context.h b/src/glsl/pp/sl_pp_context.h index b5419bc056b..1232f1e9e31 100644 --- a/src/glsl/pp/sl_pp_context.h +++ b/src/glsl/pp/sl_pp_context.h @@ -43,9 +43,16 @@ #define SL_PP_MAX_PREDEFINED 16 +enum sl_pp_extension_state { + SL_PP_EXTENSION_STATE_ENABLED, + SL_PP_EXTENSION_STATE_DISABLED, + SL_PP_EXTENSION_STATE_WARN, + SL_PP_EXTENSION_STATE_REQUIRE +}; + struct sl_pp_extension { int name; /*< GL_VENDOR_extension_name */ - int enabled; + enum sl_pp_extension_state state; }; struct sl_pp_predefined { diff --git a/src/glsl/pp/sl_pp_extension.c b/src/glsl/pp/sl_pp_extension.c index 1f00d94ebac..0816e815a4b 100644 --- a/src/glsl/pp/sl_pp_extension.c +++ b/src/glsl/pp/sl_pp_extension.c @@ -53,7 +53,7 @@ sl_pp_context_add_extension(struct sl_pp_context *context, return -1; } - ext.enabled = 0; + ext.state = SL_PP_EXTENSION_STATE_DISABLED; context->extensions[context->num_extensions++] = ext; @@ -62,6 +62,24 @@ sl_pp_context_add_extension(struct sl_pp_context *context, return 0; } + +enum sl_pp_extension_state +sl_pp_get_extension_state(const struct sl_pp_context *context, + int extension_name) +{ + unsigned i; + + for (i = 0; i < context->num_extensions; i++) { + if (extension_name == context->extensions[i].name) { + return context->extensions[i].state; + } + } + + assert(0 && "unknown extension"); + return SL_PP_EXTENSION_STATE_DISABLED; +} + + /** * Process a "#extension name: behavior" directive. */ @@ -140,7 +158,7 @@ sl_pp_process_extension(struct sl_pp_context *context, if (extension_name != context->dict.all) { assert(extension); - extension->enabled = 1; + extension->state = SL_PP_EXTENSION_STATE_REQUIRE; } } else if (behavior == context->dict.enable) { if (out.data.extension == -1) { @@ -155,7 +173,7 @@ sl_pp_process_extension(struct sl_pp_context *context, if (extension_name != context->dict.all) { assert(extension); - extension->enabled = 1; + extension->state = SL_PP_EXTENSION_STATE_ENABLED; } } else if (behavior == context->dict.warn) { if (out.data.extension == -1) { @@ -166,7 +184,7 @@ sl_pp_process_extension(struct sl_pp_context *context, if (extension_name != context->dict.all) { assert(extension); - extension->enabled = 1; + extension->state = SL_PP_EXTENSION_STATE_WARN; } } else if (behavior == context->dict.disable) { if (out.data.extension == -1) { @@ -177,7 +195,7 @@ sl_pp_process_extension(struct sl_pp_context *context, if (extension_name != context->dict.all) { assert(extension); - extension->enabled = 0; + extension->state = SL_PP_EXTENSION_STATE_DISABLED; } } else { strcpy(context->error_msg, "unrecognised behavior name"); diff --git a/src/glsl/pp/sl_pp_if.c b/src/glsl/pp/sl_pp_if.c index e233999ca8d..25cb7a3ca11 100644 --- a/src/glsl/pp/sl_pp_if.c +++ b/src/glsl/pp/sl_pp_if.c @@ -40,7 +40,7 @@ _macro_is_defined(struct sl_pp_context *context, for (i = 0; i < context->num_extensions; i++) { if (macro_name == context->extensions[i].name) { - return context->extensions[i].enabled; + return 1; } } diff --git a/src/glsl/pp/sl_pp_public.h b/src/glsl/pp/sl_pp_public.h index ca6f722543d..e4ad80d0b2a 100644 --- a/src/glsl/pp/sl_pp_public.h +++ b/src/glsl/pp/sl_pp_public.h @@ -55,6 +55,10 @@ int sl_pp_context_add_extension(struct sl_pp_context *context, const char *name); +enum sl_pp_extension_state +sl_pp_get_extension_state(const struct sl_pp_context *context, + int extension_name); + int sl_pp_context_add_predefined(struct sl_pp_context *context, const char *name, -- cgit v1.2.3