glsl/pp: Add sl_pp_context_add_extension().

This way third parties are able to add supported extension strings.
This commit is contained in:
Michal Krol 2009-12-10 12:38:22 +01:00
parent 068596c9a7
commit 91e164b3d0
6 changed files with 64 additions and 16 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -28,8 +28,34 @@
#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,
@ -37,14 +63,7 @@ sl_pp_process_extension(struct sl_pp_context *context,
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;
}
}
}

View File

@ -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

View File

@ -45,6 +45,11 @@ sl_pp_context_destroy(struct sl_pp_context *context);
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);