From 79fde3b1c18262f1585705547158d25d571ee68a Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Tue, 20 Jun 2017 13:21:51 +1100 Subject: [PATCH] SDL/Window: removed pixel format member and promoted renderer info wholly to class member The pixel format member was really rather useless, since SDL_RenderInfo returns an array of supported formats and only the first one was being saved. --- src/sdl/window.cpp | 11 +++-------- src/sdl/window.hpp | 11 +++++++++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/sdl/window.cpp b/src/sdl/window.cpp index 3186932faf61..799cb88de83c 100644 --- a/src/sdl/window.cpp +++ b/src/sdl/window.cpp @@ -18,8 +18,6 @@ #include "sdl/surface.hpp" #include "sdl/exception.hpp" -#include - namespace sdl { @@ -31,7 +29,7 @@ window::window(const std::string& title, const uint32_t window_flags, const uint32_t render_flags) : window_(SDL_CreateWindow(title.c_str(), x, y, w, h, window_flags)) - , pixel_format_(SDL_PIXELFORMAT_UNKNOWN) + , info_() { if(!window_) { throw exception("Failed to create a SDL_Window object.", true); @@ -42,13 +40,12 @@ window::window(const std::string& title, throw exception("Failed to create a SDL_Renderer object.", true); } - SDL_RendererInfo info; - if(SDL_GetRendererInfo(*this, &info) != 0) { + if(SDL_GetRendererInfo(*this, &info_) != 0) { throw exception("Failed to retrieve the information of the renderer.", true); } - if(info.num_texture_formats == 0) { + if(info_.num_texture_formats == 0) { throw exception("The renderer has no texture information available.\n", false); } @@ -63,8 +60,6 @@ window::window(const std::string& title, // Use linear scaling when rendering, if applicable. SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); - pixel_format_ = info.texture_formats[0]; - fill(0,0,0); render(); diff --git a/src/sdl/window.hpp b/src/sdl/window.hpp index 4ae222bf33d7..4a8a5ea9137f 100644 --- a/src/sdl/window.hpp +++ b/src/sdl/window.hpp @@ -19,6 +19,7 @@ * Contains a wrapper class for the @ref SDL_Window class. */ +#include #include #include @@ -167,6 +168,12 @@ class window int get_display_index(); + /** Gets the renderer info for this window. */ + const SDL_RendererInfo& get_renderer_info() const + { + return info_; + } + /***** ***** ***** Conversion operators. ***** ***** *****/ /** @@ -185,8 +192,8 @@ class window /** The @ref SDL_Window we own. */ SDL_Window* window_; - /** The preferred pixel format for the renderer. */ - uint32_t pixel_format_; + /** Info about the current renderer. */ + SDL_RendererInfo info_; }; } // namespace sdl