diff options
author | chai <chaifix@163.com> | 2019-12-15 13:29:05 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-12-15 13:29:05 +0800 |
commit | a0b8ef3d482c965901f094879a79dd9c5fd8245c (patch) | |
tree | 1a28d49dc7a6bf0a279f10569cd7e40f3aaaedaa /src/core/device.c | |
parent | 749bbc6a54e50c297ab49d9e515a3679651d1461 (diff) |
*misc
Diffstat (limited to 'src/core/device.c')
-rw-r--r-- | src/core/device.c | 78 |
1 files changed, 73 insertions, 5 deletions
diff --git a/src/core/device.c b/src/core/device.c index 3566448..4b16d32 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -88,8 +88,8 @@ void ssr_init(ssr_Config* conf) { state.filtermode = FILTERMODE_POINT; state.wrapmode = WRAPMODE_CLAMP; - state.blendfactor.src = BLENDFACTOR_SRC_ALPHA; - state.blendfactor.dst = BLENDFACTOR_ONE_MINUS_SRC_ALPHA; + state.blendfactor.src = BLEND_SRC_ALPHA; + state.blendfactor.dst = BLEND_ONE_MINUS_SRC_ALPHA; } float ssr_getaspect() { @@ -313,14 +313,82 @@ void ssr_blend(Color32* src, Color32* dst, Color32* out) { ssrU_blend(state.blendfactor.src, state.blendfactor.dst, src, dst, out); } -void ssrU_blend(ssr_BlendFactor sfactor +static _blend(ssr_BlendFactor factor, Color32* src, Color32* dst, Color32* out) { + switch (factor) { + case BLEND_ONE: + break; + case BLEND_ZERO: + out->r = out->g = out->b = out->a = 0; + break; + case BLEND_SRC_COLOR: + out->r *= src->r; + out->g *= src->g; + out->b *= src->b; + out->a *= src->a; + break; + case BLEND_ONE_MINUS_SRC_COLOR: + out->r *= (1 - src->r); + out->g *= (1 - src->g); + out->b *= (1 - src->b); + out->a *= (1 - src->a); + break; + case BLEND_DST_COLOR: + out->r *= dst->r; + out->g *= dst->g; + out->b *= dst->b; + out->a *= dst->a; + break; + case BLEND_ONE_MINUS_DST_COLOR: + out->r *= (1 - dst->r); + out->g *= (1 - dst->g); + out->b *= (1 - dst->b); + out->a *= (1 - dst->a); + break; + case BLEND_SRC_ALPHA: + out->r *= src->a; + out->g *= src->a; + out->b *= src->a; + out->a *= src->a; + break; + case BLEND_ONE_MINUS_SRC_ALPHA: + out->r *= (1 - src->a); + out->g *= (1 - src->a); + out->b *= (1 - src->a); + out->a *= (1 - src->a); + break; + case BLEND_DST_ALPHA: + out->r *= dst->a; + out->g *= dst->a; + out->b *= dst->a; + out->a *= dst->a; + break; + case BLEND_ONE_MINUS_DST_ALPHA: + out->r *= (1 - dst->a); + out->g *= (1 - dst->a); + out->b *= (1 - dst->a); + out->a *= (1 - dst->a); + break; + default: + ssr_assert(FALSE); + break; + } +} + +void ssrU_blend( + ssr_BlendFactor sfactor , ssr_BlendFactor dfactor , Color32* src , Color32* dst , Color32* out ) { ssr_assert(src && dst && out); - + Color32 s0; s0 = *src; + _blend(sfactor, src, dst, src); + _blend(dfactor, &s0, dst, dst); + out->r = src->r + dst->r; + out->g = src->g + dst->g; + out->b = src->b + dst->b; + out->a = src->a + dst->a; } Color32 ssr_getfbocolor(uint x, uint y) { @@ -426,7 +494,7 @@ void ssr_draw(ssr_PrimitiveType primitive) { v2 = &state.verts[i2]; /*back face culling*/ - if (ssr_isenable(ENABLEMASK_BACKFACECULL)) { + if (ssr_isenable(ENABLE_BACKFACECULL)) { float w0 = 1 / h0->w, w1 = 1 / h1->w, w2 = 1 / h2->w; Vec3 ab, ac; ab.x = h1->x * w1 - h0->x * w0; |