From 5f950f0b503117520486ac0cf5145c81923c335b Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Thu, 31 Jul 2014 21:27:38 +0200 Subject: [PATCH] Implemented support for different blend modes in SDL --- src/video/sdl/sdl_painter.cpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/video/sdl/sdl_painter.cpp b/src/video/sdl/sdl_painter.cpp index ff241b3b4..963307485 100644 --- a/src/video/sdl/sdl_painter.cpp +++ b/src/video/sdl/sdl_painter.cpp @@ -18,13 +18,46 @@ #include "SDL.h" +#include "util/log.hpp" #include "video/drawing_request.hpp" #include "video/sdl/sdl_texture.hpp" +namespace { + +SDL_BlendMode blend2sdl(const Blend& blend) +{ + if (blend.sfactor == GL_ONE && + blend.dfactor == GL_ZERO) + { + return SDL_BLENDMODE_NONE; + } + else if (blend.sfactor == GL_SRC_ALPHA && + blend.dfactor == GL_ONE_MINUS_SRC_ALPHA) + { + return SDL_BLENDMODE_BLEND; + } + else if (blend.sfactor == GL_SRC_ALPHA && + blend.dfactor == GL_ONE) + { + return SDL_BLENDMODE_ADD; + } + else if (blend.sfactor == GL_DST_COLOR && + blend.dfactor == GL_ZERO) + { + return SDL_BLENDMODE_MOD; + } + else + { + log_warning << "unknown blend mode combinations: sfactor=" << blend.sfactor << " dfactor=" << blend.dfactor << std::endl; + return SDL_BLENDMODE_BLEND; + } +} + +} // namespace + void SDLPainter::draw_surface(SDL_Renderer* renderer, const DrawingRequest& request) { - //FIXME: support parameters request.blend const Surface* surface = (const Surface*) request.request_data; boost::shared_ptr sdltexture = boost::dynamic_pointer_cast(surface->get_texture()); @@ -40,6 +73,7 @@ SDLPainter::draw_surface(SDL_Renderer* renderer, const DrawingRequest& request) Uint8 a = static_cast(request.color.alpha * request.alpha * 255); SDL_SetTextureColorMod(sdltexture->get_texture(), r, g, b); SDL_SetTextureAlphaMod(sdltexture->get_texture(), a); + SDL_SetTextureBlendMode(sdltexture->get_texture(), blend2sdl(request.blend)); SDL_RendererFlip flip = SDL_FLIP_NONE; if (surface->get_flipx() || request.drawing_effect == HORIZONTAL_FLIP) @@ -81,6 +115,7 @@ SDLPainter::draw_surface_part(SDL_Renderer* renderer, const DrawingRequest& requ Uint8 a = static_cast(request.color.alpha * request.alpha * 255); SDL_SetTextureColorMod(sdltexture->get_texture(), r, g, b); SDL_SetTextureAlphaMod(sdltexture->get_texture(), a); + SDL_SetTextureBlendMode(sdltexture->get_texture(), blend2sdl(request.blend)); SDL_RendererFlip flip = SDL_FLIP_NONE; if (surface->surface->get_flipx() || request.drawing_effect == HORIZONTAL_FLIP) -- 2.11.0