Merge pull request #1309 from nleseul/effect-arg-modifier
libobs: Handle 'in', 'out', and 'inout' keywords in shader parsersmaster
commit
8c0be08040
|
@ -108,6 +108,10 @@ static void gl_write_var(struct gl_shader_parser *glsp, struct shader_var *var)
|
|||
dstr_cat(&glsp->gl_string, "uniform ");
|
||||
else if (var->var_type == SHADER_VAR_CONST)
|
||||
dstr_cat(&glsp->gl_string, "const ");
|
||||
else if (var->var_type == SHADER_VAR_INOUT)
|
||||
dstr_cat(&glsp->gl_string, "inout ");
|
||||
else if (var->var_type == SHADER_VAR_OUT)
|
||||
dstr_cat(&glsp->gl_string, "out ");
|
||||
|
||||
gl_write_type(glsp, var->type);
|
||||
dstr_cat(&glsp->gl_string, " ");
|
||||
|
|
|
@ -491,13 +491,40 @@ static inline int ep_parse_func_param(struct effect_parser *ep,
|
|||
struct ep_func *func, struct ep_var *var)
|
||||
{
|
||||
int code;
|
||||
bool var_type_keyword = false;
|
||||
|
||||
if (!cf_next_valid_token(&ep->cfp))
|
||||
return PARSE_EOF;
|
||||
|
||||
code = ep_check_for_keyword(ep, "uniform", &var->uniform);
|
||||
code = ep_check_for_keyword(ep, "in", &var_type_keyword);
|
||||
if (code == PARSE_EOF)
|
||||
return PARSE_EOF;
|
||||
else if (var_type_keyword)
|
||||
var->var_type = EP_VAR_IN;
|
||||
|
||||
if (!var_type_keyword) {
|
||||
code = ep_check_for_keyword(ep, "inout", &var_type_keyword);
|
||||
if (code == PARSE_EOF)
|
||||
return PARSE_EOF;
|
||||
else if (var_type_keyword)
|
||||
var->var_type = EP_VAR_INOUT;
|
||||
}
|
||||
|
||||
if (!var_type_keyword) {
|
||||
code = ep_check_for_keyword(ep, "out", &var_type_keyword);
|
||||
if (code == PARSE_EOF)
|
||||
return PARSE_EOF;
|
||||
else if (var_type_keyword)
|
||||
var->var_type = EP_VAR_OUT;
|
||||
}
|
||||
|
||||
if (!var_type_keyword) {
|
||||
code = ep_check_for_keyword(ep, "uniform", &var_type_keyword);
|
||||
if (code == PARSE_EOF)
|
||||
return PARSE_EOF;
|
||||
else if (var_type_keyword)
|
||||
var->var_type = EP_VAR_UNIFORM;
|
||||
}
|
||||
|
||||
code = cf_get_name(&ep->cfp, &var->type, "type", ")");
|
||||
if (code != PARSE_SUCCESS)
|
||||
|
@ -1083,8 +1110,14 @@ static inline void ep_write_func_sampler_deps(struct effect_parser *ep,
|
|||
|
||||
static inline void ep_write_var(struct dstr *shader, struct ep_var *var)
|
||||
{
|
||||
if (var->uniform)
|
||||
if (var->var_type == EP_VAR_INOUT)
|
||||
dstr_cat(shader, "inout ");
|
||||
else if (var->var_type == EP_VAR_OUT)
|
||||
dstr_cat(shader, "out ");
|
||||
else if (var->var_type == EP_VAR_UNIFORM)
|
||||
dstr_cat(shader, "uniform ");
|
||||
// The "in" input modifier is implied by default, so leave it blank
|
||||
// in that case.
|
||||
|
||||
dstr_cat(shader, var->type);
|
||||
dstr_cat(shader, " ");
|
||||
|
|
|
@ -37,9 +37,17 @@ struct dstr;
|
|||
/* ------------------------------------------------------------------------- */
|
||||
/* effect parser var data */
|
||||
|
||||
enum ep_var_type {
|
||||
EP_VAR_NONE,
|
||||
EP_VAR_IN = EP_VAR_NONE,
|
||||
EP_VAR_INOUT,
|
||||
EP_VAR_OUT,
|
||||
EP_VAR_UNIFORM
|
||||
};
|
||||
|
||||
struct ep_var {
|
||||
char *type, *name, *mapping;
|
||||
bool uniform;
|
||||
enum ep_var_type var_type;
|
||||
};
|
||||
|
||||
static inline void ep_var_init(struct ep_var *epv)
|
||||
|
|
|
@ -334,16 +334,40 @@ static inline int sp_parse_func_param(struct shader_parser *sp,
|
|||
struct shader_var *var)
|
||||
{
|
||||
int code;
|
||||
bool is_uniform = false;
|
||||
bool var_type_keyword = false;
|
||||
|
||||
if (!cf_next_valid_token(&sp->cfp))
|
||||
return PARSE_EOF;
|
||||
|
||||
code = sp_check_for_keyword(sp, "uniform", &is_uniform);
|
||||
code = sp_check_for_keyword(sp, "in", &var_type_keyword);
|
||||
if (code == PARSE_EOF)
|
||||
return PARSE_EOF;
|
||||
else if (var_type_keyword)
|
||||
var->var_type = SHADER_VAR_IN;
|
||||
|
||||
var->var_type = is_uniform ? SHADER_VAR_UNIFORM : SHADER_VAR_NONE;
|
||||
if (!var_type_keyword) {
|
||||
code = sp_check_for_keyword(sp, "inout", &var_type_keyword);
|
||||
if (code == PARSE_EOF)
|
||||
return PARSE_EOF;
|
||||
else if (var_type_keyword)
|
||||
var->var_type = SHADER_VAR_INOUT;
|
||||
}
|
||||
|
||||
if (!var_type_keyword) {
|
||||
code = sp_check_for_keyword(sp, "out", &var_type_keyword);
|
||||
if (code == PARSE_EOF)
|
||||
return PARSE_EOF;
|
||||
else if (var_type_keyword)
|
||||
var->var_type = SHADER_VAR_OUT;
|
||||
}
|
||||
|
||||
if (!var_type_keyword) {
|
||||
code = sp_check_for_keyword(sp, "uniform", &var_type_keyword);
|
||||
if (code == PARSE_EOF)
|
||||
return PARSE_EOF;
|
||||
else if (var_type_keyword)
|
||||
var->var_type = SHADER_VAR_UNIFORM;
|
||||
}
|
||||
|
||||
code = cf_get_name(&sp->cfp, &var->type, "type", ")");
|
||||
if (code != PARSE_SUCCESS)
|
||||
|
|
|
@ -38,6 +38,9 @@ EXPORT enum gs_address_mode get_address_mode(const char *address_mode);
|
|||
|
||||
enum shader_var_type {
|
||||
SHADER_VAR_NONE,
|
||||
SHADER_VAR_IN = SHADER_VAR_NONE,
|
||||
SHADER_VAR_INOUT,
|
||||
SHADER_VAR_OUT,
|
||||
SHADER_VAR_UNIFORM,
|
||||
SHADER_VAR_CONST
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue