From d9e50ab8097e4a601141765cab6098d5c8ed78ff Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Thu, 27 Aug 2020 17:22:03 -0700 Subject: [PATCH] Implement DrawGraph.blend --- include/gfx/gfx.h | 1 + src/draw.c | 11 +++++++++++ src/hll/DrawGraph.c | 8 ++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/gfx/gfx.h b/include/gfx/gfx.h index a7de5e7..a5a22f5 100644 --- a/include/gfx/gfx.h +++ b/include/gfx/gfx.h @@ -103,6 +103,7 @@ void gfx_copy_use_amap_under(struct texture *dst, int dx, int dy, struct texture void gfx_copy_use_amap_border(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h, int threshold); void gfx_copy_amap_max(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h); void gfx_copy_amap_min(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h); +void gfx_blend(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h, int a); void gfx_blend_amap(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h); void gfx_blend_amap_alpha(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h, int a); void gfx_fill(struct texture *dst, int x, int y, int w, int h, int r, int g, int b); diff --git a/src/draw.c b/src/draw.c index 7421bde..c1ba280 100644 --- a/src/draw.c +++ b/src/draw.c @@ -250,6 +250,17 @@ void gfx_copy_amap_min(Texture *dst, int dx, int dy, Texture *src, int sx, int s restore_blend_mode(); } +void gfx_blend(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h, int a) +{ + glBlendFuncSeparate(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_ZERO, GL_ONE); + glBlendColor(0, 0, 0, a / 255.0); + + struct copy_data data = COPY_DATA(dx, dy, sx, sy, w, h); + run_copy_shader(©_shader.s, dst, src, &data); + + restore_blend_mode(); +} + void gfx_blend_amap(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h) { glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); diff --git a/src/hll/DrawGraph.c b/src/hll/DrawGraph.c index 2a44e6d..d87d7da 100644 --- a/src/hll/DrawGraph.c +++ b/src/hll/DrawGraph.c @@ -61,6 +61,11 @@ static void DrawGraph_CopyAMapMin(int dst, int dx, int dy, int src, int sx, int gfx_copy_amap_min(TEX(dst), dx, dy, TEX(src), sx, sy, w, h); } +static void DrawGraph_Blend(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha) +{ + gfx_blend(TEX(dst), dx, dy, TEX(src), sx, sy, w, h, alpha); +} + static void DrawGraph_BlendAMap(int dst, int dx, int dy, int src, int sx, int sy, int w, int h) { gfx_blend_amap(TEX(dst), dx, dy, TEX(src), sx, sy, w, h); @@ -161,7 +166,6 @@ static void DrawGraph_SetFontName(struct string *text) } //void DrawGraph_CopyColorReverse(int dst, int dx, int dy, int src, int sx, int sy, int w, int h); -//void DrawGraph_Blend(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha); //void DrawGraph_BlendSrcBright(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha, int rate); //void DrawGraph_BlendAddSatur(int dst, int dx, int dy, int src, int sx, int sy, int w, int h); //void DrawGraph_BlendAMapSrcOnly(int dst, int dx, int dy, int src, int sx, int sy, int w, int h); @@ -225,7 +229,7 @@ HLL_LIBRARY(DrawGraph, HLL_EXPORT(CopyUseAMapBorder, DrawGraph_CopyUseAMapBorder), HLL_EXPORT(CopyAMapMax, DrawGraph_CopyAMapMax), HLL_EXPORT(CopyAMapMin, DrawGraph_CopyAMapMin), - //HLL_EXPORT(Blend, DrawGraph_Blend), + HLL_EXPORT(Blend, DrawGraph_Blend), //HLL_EXPORT(BlendSrcBright, DrawGraph_BlendSrcBright), //HLL_EXPORT(BlendAddSatur, DrawGraph_BlendAddSatur), HLL_EXPORT(BlendAMap, DrawGraph_BlendAMap),