Implement blend modes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
diff --git a/src/render/ps2/SDL_render_ps2.c b/src/render/ps2/SDL_render_ps2.c
index de31a25..2ebf274 100644
--- a/src/render/ps2/SDL_render_ps2.c
+++ b/src/render/ps2/SDL_render_ps2.c
@@ -379,6 +379,42 @@ PS2_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
return 0;
}
+static void
+PS2_SetBlendMode(PS2_RenderData *data, int blendMode)
+{
+ #define A_COLOR_SOURCE 0
+ #define A_COLOR_DEST 1
+ #define A_COLOR_NULL 2
+ #define A_ALPHA_SOURCE 0
+ #define A_ALPHA_DEST 1
+ #define A_ALPHA_FIX 2
+
+ switch (blendMode)
+ {
+ case SDL_BLENDMODE_NONE: {
+ data->gsGlobal->PrimAlphaEnable = GS_SETTING_OFF;
+ break;
+ }
+ case SDL_BLENDMODE_BLEND:{
+ gsKit_set_primalpha(data->gsGlobal, GS_SETREG_ALPHA(A_COLOR_SOURCE, A_COLOR_DEST, A_ALPHA_SOURCE, A_COLOR_DEST, 0), 0);
+ data->gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
+ break;
+ }
+ case SDL_BLENDMODE_ADD: {
+ gsKit_set_primalpha(data->gsGlobal, GS_SETREG_ALPHA(A_COLOR_SOURCE, A_COLOR_NULL, A_ALPHA_FIX, A_COLOR_DEST, 0x80), 0);
+ data->gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
+ break;
+ }
+ case SDL_BLENDMODE_MUL:
+ case SDL_BLENDMODE_MOD: {
+ /* We don't fully support MOD and MUL, however this is the best we can do */
+ gsKit_set_primalpha(data->gsGlobal, GS_SETREG_ALPHA(A_COLOR_DEST, A_COLOR_NULL, A_ALPHA_SOURCE, A_COLOR_SOURCE, 0x80), 0);
+ data->gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
+ break;
+ }
+ }
+}
+
static int
PS2_RenderGeometry(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *cmd)
{
@@ -391,6 +427,8 @@ PS2_RenderGeometry(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *cm
const size_t count = cmd->data.draw.count;
+ PS2_SetBlendMode(data, cmd->data.draw.blend);
+
if (cmd->data.draw.texture) {
const texture_vertex *verts = (texture_vertex *) (vertices + cmd->data.draw.first);
GSTEXTURE *ps2_tex = (GSTEXTURE *) cmd->data.draw.texture->driverdata;
@@ -476,6 +514,8 @@ PS2_RenderLines(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand * cmd)
const color_vertex *verts = (color_vertex *) (vertices + cmd->data.draw.first);
+ PS2_SetBlendMode(data, cmd->data.draw.blend);
+
for (i = 0; i < count-1; i++, verts++) {
x1 = verts[i*2].x;
y1 = verts[i*2].y;
@@ -505,6 +545,8 @@ PS2_RenderPoints(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand * cmd
const uint8_t ColorB = cmd->data.draw.b >> 1;
const uint8_t ColorA = cmd->data.draw.a >> 1;
+ PS2_SetBlendMode(data, cmd->data.draw.blend);
+
color = GS_SETREG_RGBAQ(ColorR, ColorG, ColorB, ColorA, 0x00);
const clear_vertex *verts = (clear_vertex *) (vertices + cmd->data.draw.first);