From b58cf7eefb4822703a8077297b36efb7a1a4716a Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Sat, 1 Nov 2014 18:03:44 +0100 Subject: [PATCH 1/5] Java2D blending - fix swapped SRC and DST --- core/src/processing/core/PGraphicsJava2D.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/processing/core/PGraphicsJava2D.java b/core/src/processing/core/PGraphicsJava2D.java index a687c5944..79c5e3016 100644 --- a/core/src/processing/core/PGraphicsJava2D.java +++ b/core/src/processing/core/PGraphicsJava2D.java @@ -861,7 +861,7 @@ public class PGraphicsJava2D extends PGraphics { src.getDataElements(0, y, width, 1, srcPixels); dstIn.getDataElements(0, y, width, 1, dstPixels); for (int x = 0; x < width; x++) { - dstPixels[x] = blendColor(srcPixels[x], alphaFiller | dstPixels[x], mode); + dstPixels[x] = blendColor(alphaFiller | dstPixels[x], srcPixels[x], mode); } dstOut.setDataElements(0, y, width, 1, dstPixels); } From 7c9484c11fa44bf1fec028498c7893f30d9fe01e Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Sat, 1 Nov 2014 18:05:41 +0100 Subject: [PATCH 2/5] OpenGL blending - fixed SUBTRACT O = D - (S * SA) now matches Java2D --- core/src/processing/opengl/PGraphicsOpenGL.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 72d7dff47..03df5d4c8 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -6025,7 +6025,7 @@ public class PGraphicsOpenGL extends PGraphics { } else if (blendMode == SUBTRACT) { if (blendEqSupported) { pgl.blendEquation(PGL.FUNC_REVERSE_SUBTRACT); - pgl.blendFunc(PGL.ONE, PGL.SRC_ALPHA); + pgl.blendFunc(PGL.SRC_ALPHA, PGL.ONE); } else { PGraphics.showWarning(BLEND_DRIVER_ERROR, "SUBTRACT"); } From d8ba58288221dee3cc886801f92ee879c204a717 Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Sat, 1 Nov 2014 18:07:25 +0100 Subject: [PATCH 3/5] OpenGL blending - fixed MULTIPLY O = D * S now matches Java2D --- core/src/processing/opengl/PGraphicsOpenGL.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 03df5d4c8..bd4609c29 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -6056,7 +6056,7 @@ public class PGraphicsOpenGL extends PGraphics { if (blendEqSupported) { pgl.blendEquation(PGL.FUNC_ADD); } - pgl.blendFunc(PGL.DST_COLOR, PGL.SRC_COLOR); + pgl.blendFunc(PGL.ZERO, PGL.SRC_COLOR); } else if (blendMode == SCREEN) { if (blendEqSupported) { From 2de4067933905f0d7fb450fcd5ccafd26a60f26f Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Sat, 1 Nov 2014 18:08:03 +0100 Subject: [PATCH 4/5] OpenGL blending - removed unused functions --- core/src/processing/opengl/PGraphicsOpenGL.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index bd4609c29..7e25eacd4 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -6033,7 +6033,6 @@ public class PGraphicsOpenGL extends PGraphics { } else if (blendMode == LIGHTEST) { if (blendEqSupported) { pgl.blendEquation(PGL.FUNC_MAX); - pgl.blendFunc(PGL.SRC_ALPHA, PGL.DST_ALPHA); } else { PGraphics.showWarning(BLEND_DRIVER_ERROR, "LIGHTEST"); } @@ -6041,7 +6040,6 @@ public class PGraphicsOpenGL extends PGraphics { } else if (blendMode == DARKEST) { if (blendEqSupported) { pgl.blendEquation(PGL.FUNC_MIN); - pgl.blendFunc(PGL.SRC_ALPHA, PGL.DST_ALPHA); } else { PGraphics.showWarning(BLEND_DRIVER_ERROR, "DARKEST"); } From e85f406f0f8f96f4edef0f0b2f2560e464a2ebad Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Sat, 1 Nov 2014 18:20:56 +0100 Subject: [PATCH 5/5] OpenGL blending - alpha is added in all modes OA = SA + DA for all modes now matches Java2D --- .../processing/opengl/PGraphicsOpenGL.java | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 7e25eacd4..e685772d3 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -6012,55 +6012,73 @@ public class PGraphicsOpenGL extends PGraphics { } else if (blendMode == BLEND) { if (blendEqSupported) { - pgl.blendEquation(PGL.FUNC_ADD); + pgl.blendEquationSeparate(PGL.FUNC_ADD, + PGL.FUNC_ADD); } - pgl.blendFunc(PGL.SRC_ALPHA, PGL.ONE_MINUS_SRC_ALPHA); + pgl.blendFuncSeparate(PGL.SRC_ALPHA, PGL.ONE_MINUS_SRC_ALPHA, + PGL.ONE, PGL.ONE); } else if (blendMode == ADD) { if (blendEqSupported) { - pgl.blendEquation(PGL.FUNC_ADD); + pgl.blendEquationSeparate(PGL.FUNC_ADD, + PGL.FUNC_ADD); } - pgl.blendFunc(PGL.SRC_ALPHA, PGL.ONE); + pgl.blendFuncSeparate(PGL.SRC_ALPHA, PGL.ONE, + PGL.ONE, PGL.ONE); } else if (blendMode == SUBTRACT) { if (blendEqSupported) { - pgl.blendEquation(PGL.FUNC_REVERSE_SUBTRACT); - pgl.blendFunc(PGL.SRC_ALPHA, PGL.ONE); + pgl.blendEquationSeparate(PGL.FUNC_REVERSE_SUBTRACT, + PGL.FUNC_ADD); + pgl.blendFuncSeparate(PGL.SRC_ALPHA, PGL.ONE, + PGL.ONE, PGL.ONE); } else { PGraphics.showWarning(BLEND_DRIVER_ERROR, "SUBTRACT"); } } else if (blendMode == LIGHTEST) { if (blendEqSupported) { - pgl.blendEquation(PGL.FUNC_MAX); + pgl.blendEquationSeparate(PGL.FUNC_MAX, + PGL.FUNC_ADD); + pgl.blendFuncSeparate(PGL.ONE, PGL.ONE, + PGL.ONE, PGL.ONE); } else { PGraphics.showWarning(BLEND_DRIVER_ERROR, "LIGHTEST"); } } else if (blendMode == DARKEST) { if (blendEqSupported) { - pgl.blendEquation(PGL.FUNC_MIN); + pgl.blendEquationSeparate(PGL.FUNC_MIN, + PGL.FUNC_ADD); + pgl.blendFuncSeparate(PGL.ONE, PGL.ONE, + PGL.ONE, PGL.ONE); } else { PGraphics.showWarning(BLEND_DRIVER_ERROR, "DARKEST"); } } else if (blendMode == EXCLUSION) { if (blendEqSupported) { - pgl.blendEquation(PGL.FUNC_ADD); + pgl.blendEquationSeparate(PGL.FUNC_ADD, + PGL.FUNC_ADD); } - pgl.blendFunc(PGL.ONE_MINUS_DST_COLOR, PGL.ONE_MINUS_SRC_COLOR); + pgl.blendFuncSeparate(PGL.ONE_MINUS_DST_COLOR, PGL.ONE_MINUS_SRC_COLOR, + PGL.ONE, PGL.ONE); } else if (blendMode == MULTIPLY) { if (blendEqSupported) { - pgl.blendEquation(PGL.FUNC_ADD); + pgl.blendEquationSeparate(PGL.FUNC_ADD, + PGL.FUNC_ADD); } - pgl.blendFunc(PGL.ZERO, PGL.SRC_COLOR); + pgl.blendFuncSeparate(PGL.ZERO, PGL.SRC_COLOR, + PGL.ONE, PGL.ONE); } else if (blendMode == SCREEN) { if (blendEqSupported) { - pgl.blendEquation(PGL.FUNC_ADD); + pgl.blendEquationSeparate(PGL.FUNC_ADD, + PGL.FUNC_ADD); } - pgl.blendFunc(PGL.ONE_MINUS_DST_COLOR, PGL.ONE); + pgl.blendFuncSeparate(PGL.ONE_MINUS_DST_COLOR, PGL.ONE, + PGL.ONE, PGL.ONE); } else if (blendMode == DIFFERENCE) { PGraphics.showWarning(BLEND_RENDERER_ERROR, "DIFFERENCE");