1// SuperTux
2// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3// Updated by GiBy 2013 for SDL2 <giby_the_kid@yahoo.fr>
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18#include "video/sdl/sdl_screen_renderer.hpp"
19
20#include "math/rect.hpp"
21#include "supertux/gameconfig.hpp"
22#include "supertux/globals.hpp"
23#include "util/log.hpp"
24#include "video/sdl/sdl_painter.hpp"
25#include "video/sdl/sdl_video_system.hpp"
26
27SDLScreenRenderer::SDLScreenRenderer(SDLVideoSystem& video_system, SDL_Renderer* renderer) :
28 m_video_system(video_system),
29 m_renderer(renderer),
30 m_painter(m_video_system, *this, m_renderer)
31{
32 SDL_RendererInfo info;
33 if (SDL_GetRendererInfo(m_renderer, &info) != 0)
34 {
35 log_warning << "Couldn't get RendererInfo: " << SDL_GetError() << std::endl;
36 }
37 else
38 {
39 log_info << "SDL_Renderer: " << info.name << std::endl;
40 log_info << "SDL_RendererFlags: " << std::endl;
41 if (info.flags & SDL_RENDERER_SOFTWARE) { log_info << " SDL_RENDERER_SOFTWARE" << std::endl; }
42 if (info.flags & SDL_RENDERER_ACCELERATED) { log_info << " SDL_RENDERER_ACCELERATED" << std::endl; }
43 if (info.flags & SDL_RENDERER_PRESENTVSYNC) { log_info << " SDL_RENDERER_PRESENTVSYNC" << std::endl; }
44 if (info.flags & SDL_RENDERER_TARGETTEXTURE) { log_info << " SDL_RENDERER_TARGETTEXTURE" << std::endl; }
45 log_info << "Texture Formats: " << std::endl;
46 for (size_t i = 0; i < info.num_texture_formats; ++i)
47 {
48 log_info << " " << SDL_GetPixelFormatName(info.texture_formats[i]) << std::endl;
49 }
50 log_info << "Max Texture Width: " << info.max_texture_width << std::endl;
51 log_info << "Max Texture Height: " << info.max_texture_height << std::endl;
52 }
53}
54
55SDLScreenRenderer::~SDLScreenRenderer()
56{
57}
58
59void
60SDLScreenRenderer::start_draw()
61{
62 const Rect& viewport = m_video_system.get_viewport().get_rect();
63 const Vector& scale = m_video_system.get_viewport().get_scale();
64
65 SDL_Rect sdl_viewport = { viewport.left, viewport.top,
66 viewport.get_width(), viewport.get_height() };
67
68 // SetViewport() works in scaled screen coordinates, so we have to
69 // reset it to 1.0, 1.0 to get meaningful results
70 SDL_RenderSetScale(m_renderer, 1.0f, 1.0f);
71 SDL_RenderSetViewport(m_renderer, &sdl_viewport);
72 SDL_RenderSetScale(m_renderer, scale.x, scale.y);
73
74 SDL_SetRenderDrawColor(m_renderer, 0, 0, 0, 255);
75 SDL_RenderClear(m_renderer);
76}
77
78void
79SDLScreenRenderer::end_draw()
80{
81}
82
83Rect
84SDLScreenRenderer::get_rect() const
85{
86 return m_video_system.get_viewport().get_rect();
87}
88
89Size
90SDLScreenRenderer::get_logical_size() const
91{
92 return m_video_system.get_viewport().get_screen_size();
93}
94
95void
96SDLScreenRenderer::flip()
97{
98 SDL_RenderPresent(m_renderer);
99}
100
101/* EOF */
102