Merge pull request #2921 from JakubValtar/bugfix-blendmodes

Multiple blending fixes & improvements
This commit is contained in:
Ben Fry
2014-11-03 15:12:40 -05:00
2 changed files with 33 additions and 17 deletions
@@ -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);
}
+32 -16
View File
@@ -6012,57 +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.ONE, PGL.SRC_ALPHA);
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.blendFunc(PGL.SRC_ALPHA, PGL.DST_ALPHA);
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.blendFunc(PGL.SRC_ALPHA, PGL.DST_ALPHA);
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.DST_COLOR, 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");