summaryrefslogtreecommitdiff
path: root/src/glsl/pp
diff options
context:
space:
mode:
authorMichal Krol <michal@vmware.com>2009-12-10 12:38:22 +0100
committerMichal Krol <michal@vmware.com>2009-12-10 12:38:22 +0100
commit91e164b3d0b1d36bfdf369266ae7e1ab396f1ba2 (patch)
treed8ed4e74e470d2c9b9bf9ad3d4ad0829dc4da0ba /src/glsl/pp
parent068596c9a7e8d330ffdff8ad8700bd6093b5bdea (diff)
glsl/pp: Add sl_pp_context_add_extension().
This way third parties are able to add supported extension strings.
Diffstat (limited to 'src/glsl/pp')
-rw-r--r--src/glsl/pp/sl_pp_context.h10
-rw-r--r--src/glsl/pp/sl_pp_dict.c2
-rw-r--r--src/glsl/pp/sl_pp_dict.h2
-rw-r--r--src/glsl/pp/sl_pp_extension.c49
-rw-r--r--src/glsl/pp/sl_pp_macro.c12
-rw-r--r--src/glsl/pp/sl_pp_public.h5
6 files changed, 64 insertions, 16 deletions
diff --git a/src/glsl/pp/sl_pp_context.h b/src/glsl/pp/sl_pp_context.h
index 569a2d735b..5e3ae72fdf 100644
--- a/src/glsl/pp/sl_pp_context.h
+++ b/src/glsl/pp/sl_pp_context.h
@@ -37,6 +37,13 @@
#define SL_PP_MAX_ERROR_MSG 1024
+#define SL_PP_MAX_EXTENSIONS 16
+
+struct sl_pp_extension {
+ int name; /*< VENDOR_extension_name */
+ int name_string; /*< GL_VENDOR_extension_name */
+};
+
struct sl_pp_context {
char *cstr_pool;
unsigned int cstr_pool_max;
@@ -46,6 +53,9 @@ struct sl_pp_context {
struct sl_pp_macro *macro;
struct sl_pp_macro **macro_tail;
+ struct sl_pp_extension extensions[SL_PP_MAX_EXTENSIONS];
+ unsigned int num_extensions;
+
unsigned int if_stack[SL_PP_MAX_IF_NESTING];
unsigned int if_ptr;
unsigned int if_value;
diff --git a/src/glsl/pp/sl_pp_dict.c b/src/glsl/pp/sl_pp_dict.c
index 2dd77a69e9..062139e6ac 100644
--- a/src/glsl/pp/sl_pp_dict.c
+++ b/src/glsl/pp/sl_pp_dict.c
@@ -45,8 +45,6 @@ int
sl_pp_dict_init(struct sl_pp_context *context)
{
ADD_NAME(context, all);
- ADD_NAME_STR(context, _GL_ARB_draw_buffers, "GL_ARB_draw_buffers");
- ADD_NAME_STR(context, _GL_ARB_texture_rectangle, "GL_ARB_texture_rectangle");
ADD_NAME(context, require);
ADD_NAME(context, enable);
diff --git a/src/glsl/pp/sl_pp_dict.h b/src/glsl/pp/sl_pp_dict.h
index 49f0e0bf9f..875217bd30 100644
--- a/src/glsl/pp/sl_pp_dict.h
+++ b/src/glsl/pp/sl_pp_dict.h
@@ -33,8 +33,6 @@ struct sl_pp_context;
struct sl_pp_dict {
int all;
- int _GL_ARB_draw_buffers;
- int _GL_ARB_texture_rectangle;
int require;
int enable;
diff --git a/src/glsl/pp/sl_pp_extension.c b/src/glsl/pp/sl_pp_extension.c
index 4148fd9a5a..67b24404d4 100644
--- a/src/glsl/pp/sl_pp_extension.c
+++ b/src/glsl/pp/sl_pp_extension.c
@@ -28,23 +28,42 @@
#include <stdlib.h>
#include <string.h>
#include "sl_pp_process.h"
+#include "sl_pp_public.h"
int
+sl_pp_context_add_extension(struct sl_pp_context *context,
+ const char *name,
+ const char *name_string)
+{
+ struct sl_pp_extension ext;
+
+ if (context->num_extensions == SL_PP_MAX_EXTENSIONS) {
+ return -1;
+ }
+
+ ext.name = sl_pp_context_add_unique_str(context, name);
+ if (ext.name == -1) {
+ return -1;
+ }
+
+ ext.name_string = sl_pp_context_add_unique_str(context, name_string);
+ if (ext.name_string == -1) {
+ return -1;
+ }
+
+ context->extensions[context->num_extensions++] = ext;
+ return 0;
+}
+
+int
sl_pp_process_extension(struct sl_pp_context *context,
const struct sl_pp_token_info *input,
unsigned int first,
unsigned int last,
struct sl_pp_process_state *state)
{
- int extensions[] = {
- context->dict.all,
- context->dict._GL_ARB_draw_buffers,
- context->dict._GL_ARB_texture_rectangle,
- -1
- };
int extension_name = -1;
- int *ext;
int behavior = -1;
struct sl_pp_token_info out;
@@ -59,11 +78,17 @@ sl_pp_process_extension(struct sl_pp_context *context,
}
/* Make sure the extension is supported. */
- out.data.extension = -1;
- for (ext = extensions; *ext != -1; ext++) {
- if (extension_name == *ext) {
- out.data.extension = extension_name;
- break;
+ if (extension_name == context->dict.all) {
+ out.data.extension = extension_name;
+ } else {
+ unsigned int i;
+
+ out.data.extension = -1;
+ for (i = 0; i < context->num_extensions; i++) {
+ if (extension_name == context->extensions[i].name_string) {
+ out.data.extension = extension_name;
+ break;
+ }
}
}
diff --git a/src/glsl/pp/sl_pp_macro.c b/src/glsl/pp/sl_pp_macro.c
index 29f1229dd7..05466c9a7c 100644
--- a/src/glsl/pp/sl_pp_macro.c
+++ b/src/glsl/pp/sl_pp_macro.c
@@ -163,6 +163,18 @@ sl_pp_macro_expand(struct sl_pp_context *context,
return 0;
}
+ /* Replace extension names with 1.
+ */
+ for (j = 0; j < context->num_extensions; j++) {
+ if (macro_name == context->extensions[j].name) {
+ if (!mute && _out_number(context, state, 1)) {
+ return -1;
+ }
+ (*pi)++;
+ return 0;
+ }
+ }
+
/* TODO: For FEATURE_es2_glsl, expand to 1 the following symbols.
* GL_ES
* GL_FRAGMENT_PRECISION_HIGH
diff --git a/src/glsl/pp/sl_pp_public.h b/src/glsl/pp/sl_pp_public.h
index 8317c7e378..20f208975e 100644
--- a/src/glsl/pp/sl_pp_public.h
+++ b/src/glsl/pp/sl_pp_public.h
@@ -46,6 +46,11 @@ const char *
sl_pp_context_error_message(const struct sl_pp_context *context);
int
+sl_pp_context_add_extension(struct sl_pp_context *context,
+ const char *name,
+ const char *name_string);
+
+int
sl_pp_context_add_unique_str(struct sl_pp_context *context,
const char *str);