Skip to content

Commit

Permalink
Added some code to make my recent changes work with a software renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Jun 12, 2017
1 parent 92518ae commit 0f1a93a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/gui/core/canvas.cpp
Expand Up @@ -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
}
}
}
Expand All @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/gui/widgets/widget.cpp
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/video.cpp
Expand Up @@ -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;

Expand Down

0 comments on commit 0f1a93a

Please sign in to comment.