From 0f1a93af2597b2880a1a748e6bd0effe52350171 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Fri, 2 Jun 2017 16:26:08 +1100 Subject: [PATCH] Added some code to make my recent changes work with a software renderer --- src/gui/core/canvas.cpp | 10 ++++++++++ src/gui/widgets/widget.cpp | 2 ++ src/video.cpp | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/src/gui/core/canvas.cpp b/src/gui/core/canvas.cpp index 855c6056410b..ef34841bcb5a 100644 --- a/src/gui/core/canvas.cpp +++ b/src/gui/core/canvas.cpp @@ -1171,6 +1171,9 @@ void image_shape::draw( << image_->h << " to " << w << ',' << h << ".\n"; // Textures are automatically scaled to size. +#ifdef SW_RENDERING_LEGACY_MODE + surf = scale_surface(image_, w, h); +#endif } } } @@ -1179,6 +1182,13 @@ void image_shape::draw( surf = image_; } +#ifdef SW_RENDERING_LEGACY_MODE + /* HACK: not sure why, but SW rendering has some problems with copying the surface to the texture and + * corrupts certain semi-transparent pixels. This is a hacky workaround. + */ + SDL_SetSurfaceAlphaMod(surf, 254); +#endif + dst_clip.w = w ? w : surf->w; dst_clip.h = h ? h : surf->h; diff --git a/src/gui/widgets/widget.cpp b/src/gui/widgets/widget.cpp index 291836cdbdaa..6a53cd65a405 100644 --- a/src/gui/widgets/widget.cpp +++ b/src/gui/widgets/widget.cpp @@ -385,12 +385,14 @@ class viewport_and_clip_rect_setter SDL_Rect clip_rect = widget.calculate_clipping_rectangle(x_offset, y_offset); +#ifndef SW_RENDERING_LEGACY_MODE // Adjust clip rect origin to match the viewport origin. Currently, the both rects are mapped to // absolute screen coordinates. However, setting the viewport essentially moves the screen origin, // meaning if both the viewport rect and clip rect have x = 100, then clipping will actually // happen at x = 200. clip_rect.x -= dst_rect.x; clip_rect.y -= dst_rect.y; +#endif SDL_RenderSetClipRect(renderer_, &clip_rect); } diff --git a/src/video.cpp b/src/video.cpp index bad5c78d712b..efa99f73677c 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -226,7 +226,11 @@ void CVideo::init_window() } // Initialize window +#ifdef SW_RENDERING_LEGACY_MODE + window.reset(new sdl::window("", x, y, w, h, video_flags, SDL_RENDERER_SOFTWARE | SDL_RENDERER_TARGETTEXTURE)); +#else window.reset(new sdl::window("", x, y, w, h, video_flags, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE)); +#endif std::cerr << "Setting mode to " << w << "x" << h << std::endl;