diff options
author | 2016-06-08 15:05:28 +0200 | |
---|---|---|
committer | 2016-06-08 20:50:19 +0200 | |
commit | 54c48bd80120a3085e6d23f7cf6124b0657436e7 (patch) | |
tree | d060ec1b942d4d544597c1e7c5fa5898d921edb1 /video/out/opengl/user_shaders.c | |
parent | a15181e5df5ba8a21e6a5b953213f4a72690c47f (diff) |
vo_opengl: make user hook passes optional
User hooks can now use an extra WHEN expression to specify when the
shader should be run. For example, this can be used to only run a chroma
scaling shader `WHEN CHROMA.w LUMA.w <`.
There's a slight semantics change to user shaders: When trying to bind a
texture that does not exist, a shader will now be silently skipped
(similar to when the condition is false) instead of generating an error.
This allows shader stages to depend on an optional earlier stage without
having to copy/paste the same condition everywhere.
(In other words: there's an implicit condition on all of the bound
textures existing)
Diffstat (limited to 'video/out/opengl/user_shaders.c')
-rw-r--r-- | video/out/opengl/user_shaders.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/video/out/opengl/user_shaders.c b/video/out/opengl/user_shaders.c index 4e9c1c89e8..8f915a56e3 100644 --- a/video/out/opengl/user_shaders.c +++ b/video/out/opengl/user_shaders.c @@ -50,6 +50,9 @@ static bool parse_rpn_szexpr(struct bstr line, struct szexp out[MAX_SZEXP_SIZE]) case '-': exp->tag = SZEXP_OP2; exp->val.op = SZEXP_OP_SUB; continue; case '*': exp->tag = SZEXP_OP2; exp->val.op = SZEXP_OP_MUL; continue; case '/': exp->tag = SZEXP_OP2; exp->val.op = SZEXP_OP_DIV; continue; + case '!': exp->tag = SZEXP_OP1; exp->val.op = SZEXP_OP_NOT; continue; + case '>': exp->tag = SZEXP_OP2; exp->val.op = SZEXP_OP_GT; continue; + case '<': exp->tag = SZEXP_OP2; exp->val.op = SZEXP_OP_LT; continue; } if (isdigit(word.start[0])) { @@ -77,6 +80,7 @@ bool parse_user_shader_pass(struct mp_log *log, struct bstr *body, .offset = identity_trans, .width = {{ SZEXP_VAR_W, { .varname = bstr0("HOOKED") }}}, .height = {{ SZEXP_VAR_H, { .varname = bstr0("HOOKED") }}}, + .cond = {{ SZEXP_CONST, { .cval = 1.0 }}}, }; int hook_idx = 0; @@ -154,6 +158,14 @@ bool parse_user_shader_pass(struct mp_log *log, struct bstr *body, continue; } + if (bstr_eatstart0(&line, "WHEN")) { + if (!parse_rpn_szexpr(line, out->cond)) { + mp_err(log, "Error while parsing WHEN!\n"); + return false; + } + continue; + } + if (bstr_eatstart0(&line, "COMPONENTS")) { if (bstr_sscanf(line, "%d", &out->components) != 1) { mp_err(log, "Error while parsing COMPONENTS!\n"); |