Skip to content

Commit

Permalink
SDL/Window: removed pixel format member and promoted renderer info wh…
Browse files Browse the repository at this point in the history
…olly 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.
  • Loading branch information
Vultraz committed Jul 9, 2017
1 parent f8cf254 commit f9c0995
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 3 additions & 8 deletions src/sdl/window.cpp
Expand Up @@ -18,8 +18,6 @@
#include "sdl/surface.hpp"
#include "sdl/exception.hpp"

#include <SDL_render.h>

namespace sdl
{

Expand All @@ -31,7 +29,7 @@ window::window(const std::string& title,
const Uint32 window_flags,
const Uint32 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);
Expand All @@ -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);
}
Expand All @@ -59,8 +56,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();
Expand Down
11 changes: 9 additions & 2 deletions src/sdl/window.hpp
Expand Up @@ -19,6 +19,7 @@
* Contains a wrapper class for the @ref SDL_Window class.
*/

#include <SDL_render.h>
#include <SDL_video.h>

#include <string>
Expand Down Expand Up @@ -157,6 +158,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. ***** ***** *****/

/**
Expand All @@ -175,8 +182,8 @@ class window
/** The @ref SDL_Window we own. */
SDL_Window* window_;

/** The preferred pixel format for the renderer. */
Uint32 pixel_format_;
/** Info about the current renderer. */
SDL_RendererInfo info_;
};

} // namespace sdl

0 comments on commit f9c0995

Please sign in to comment.