- simplified the parser for blend modes

This commit is contained in:
Christoph Oelckers 2020-09-22 23:05:43 +02:00
parent ec0e2be607
commit d6bf4306eb

View file

@ -2986,10 +2986,7 @@ static int32_t defsparser(scriptfile *script)
if (scriptfile_getbraces(script,&glblenddefblockend)) if (scriptfile_getbraces(script,&glblenddefblockend))
break; break;
#ifdef USE_OPENGL
glblenddef_t * const glbdef = glb->def + (glblendtoken == T_REVERSE); glblenddef_t * const glbdef = glb->def + (glblendtoken == T_REVERSE);
#endif
while (!scriptfile_endofblock(script, glblenddefblockend)) while (!scriptfile_endofblock(script, glblenddefblockend))
{ {
int32_t glblenddeftoken = getatoken(script,glblenddeftokens,countof(glblenddeftokens)); int32_t glblenddeftoken = getatoken(script,glblenddeftokens,countof(glblenddeftokens));
@ -2998,60 +2995,31 @@ static int32_t defsparser(scriptfile *script)
case T_SRC: case T_SRC:
case T_DST: case T_DST:
{ {
static const tokenlist blendFuncTokens[] =
{
{ "ZERO", T_ZERO },
{ "ONE", T_ONE },
{ "SRC_COLOR", T_SRC_COLOR },
{ "ONE_MINUS_SRC_COLOR", T_ONE_MINUS_SRC_COLOR },
{ "SRC_ALPHA", T_SRC_ALPHA },
{ "ONE_MINUS_SRC_ALPHA", T_ONE_MINUS_SRC_ALPHA },
{ "DST_ALPHA", T_DST_ALPHA },
{ "ONE_MINUS_DST_ALPHA", T_ONE_MINUS_DST_ALPHA },
{ "DST_COLOR", T_DST_COLOR },
{ "ONE_MINUS_DST_COLOR", T_ONE_MINUS_DST_COLOR },
};
int32_t factortoken = getatoken(script,blendFuncTokens,countof(blendFuncTokens));
#ifdef USE_OPENGL
uint8_t * const factor = glblenddeftoken == T_SRC ? &glbdef->src : &glbdef->dst; uint8_t * const factor = glblenddeftoken == T_SRC ? &glbdef->src : &glbdef->dst;
switch (factortoken) if (script->Compare("ZERO")) *factor = STYLEALPHA_Zero;
{ else if (script->Compare("ONE")) *factor = STYLEALPHA_One;
case T_ZERO: *factor = STYLEALPHA_Zero; break; else if (script->Compare("SRC_COLOR")) *factor = STYLEALPHA_SrcCol;
case T_ONE: *factor = STYLEALPHA_One; break; else if (script->Compare("ONE_MINUS_SRC_COLOR")) *factor = STYLEALPHA_InvSrcCol;
case T_SRC_COLOR: *factor = STYLEALPHA_SrcCol; break; else if (script->Compare("SRC_ALPHA")) *factor = STYLEALPHA_Src;
case T_ONE_MINUS_SRC_COLOR: *factor = STYLEALPHA_InvSrcCol; break; else if (script->Compare("ONE_MINUS_SRC_ALPHA")) *factor = STYLEALPHA_InvSrc;
case T_SRC_ALPHA: *factor = STYLEALPHA_Src; break; else if (script->Compare("DST_ALPHA")) *factor = STYLEALPHA_Dst;
case T_ONE_MINUS_SRC_ALPHA: *factor = STYLEALPHA_InvSrc; break; else if (script->Compare("ONE_MINUS_DST_ALPHA")) *factor = STYLEALPHA_InvDst;
case T_DST_ALPHA: *factor = STYLEALPHA_Dst; break; else if (script->Compare("DST_COLOR")) *factor = STYLEALPHA_DstCol;
case T_ONE_MINUS_DST_ALPHA: *factor = STYLEALPHA_InvDst; break; else if (script->Compare("ONE_MINUS_DST_COLOR")) *factor = STYLEALPHA_InvDstCol;
case T_DST_COLOR: *factor = STYLEALPHA_DstCol; break; else script->ScriptMessage("Unknown blend operation %s", script->String);
case T_ONE_MINUS_DST_COLOR: *factor = STYLEALPHA_InvDstCol; break;
}
#else
UNREFERENCED_PARAMETER(factortoken);
#endif
break; break;
} }
case T_ALPHA: case T_ALPHA:
{ {
double tempalpha; double tempalpha;
scriptfile_getdouble(script,&tempalpha); scriptfile_getdouble(script,&tempalpha);
#ifdef USE_OPENGL
glbdef->alpha = (float)tempalpha; glbdef->alpha = (float)tempalpha;
#endif
break; break;
} }
} }
} }
#ifdef USE_OPENGL
if (glblendtoken == T_BOTH) if (glblendtoken == T_BOTH)
glb->def[1] = *glbdef; glb->def[1] = *glbdef;
#endif
break; break;
} }
} }