From bee9d49515b69cfe4826b31907d5f000ca12ba9e Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Thu, 6 Oct 2011 15:17:21 +0200 Subject: [PATCH] Add premultiplied blending --- src/modules/graphics/Graphics.cpp | 1 + src/modules/graphics/Graphics.h | 1 + src/modules/graphics/opengl/Graphics.cpp | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 79c536b79..7f8e4dc82 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -121,6 +121,7 @@ namespace graphics { "additive", Graphics::BLEND_ADDITIVE }, { "subtractive", Graphics::BLEND_SUBTRACTIVE }, { "multiplicative", Graphics::BLEND_MULTIPLICATIVE }, + { "premultiplied", Graphics::BLEND_PREMULTIPLIED }, }; StringMap Graphics::blendModes(Graphics::blendModeEntries, sizeof(Graphics::blendModeEntries)); diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 0875f24a1..0fe150d6f 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -54,6 +54,7 @@ namespace graphics BLEND_ADDITIVE, BLEND_SUBTRACTIVE, BLEND_MULTIPLICATIVE, + BLEND_PREMULTIPLIED, BLEND_MAX_ENUM }; diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index a8935ed7a..527a487f8 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -659,6 +659,8 @@ namespace opengl glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); else if (mode == BLEND_MULTIPLICATIVE) glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); + else if (mode == BLEND_PREMULTIPLIED) + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); else // mode == BLEND_ADDITIVE || mode == BLEND_SUBTRACTIVE glBlendFunc(GL_SRC_ALPHA, GL_ONE); } @@ -684,8 +686,12 @@ namespace opengl return BLEND_ADDITIVE; else if (src == GL_SRC_ALPHA && dst == GL_ONE_MINUS_SRC_ALPHA) // && equation == GL_FUNC_ADD return BLEND_ALPHA; - else // src == GL_DST_COLOR && dst == GL_ONE_MINUS_SRC_ALPHA && equation == GL_FUNC_ADD + else if (src == GL_DST_COLOR && dst == GL_ONE_MINUS_SRC_ALPHA) // && equation == GL_FUNC_ADD return BLEND_MULTIPLICATIVE; + else if (src == GL_ONE && dst == GL_ONE_MINUS_SRC_ALPHA) // && equation == GL_FUNC_ADD + return BLEND_PREMULTIPLIED; + + return BLEND_MAX_ENUM; // Should never be reached. } Graphics::ColorMode Graphics::getColorMode()