Chose the renderer driver instead of passing -1 (default).

This commit is contained in:
King_DuckZ 2014-08-06 17:44:28 +02:00
parent d5d75b034e
commit 5941e0af56
4 changed files with 58 additions and 2 deletions

View file

@ -24,8 +24,50 @@
#include <SDL2/SDL.h>
#include <stdexcept>
#include <sstream>
#include <ciso646>
#include <cstring>
#include <utility>
namespace cloonel {
namespace {
///----------------------------------------------------------------------
///----------------------------------------------------------------------
std::pair<int, std::string> GetRenderingDriver() {
typedef std::pair<int, std::string> RetPairType;
const int count = SDL_GetNumRenderDrivers();
int opengles = -1;
int opengles2 = -1;
int opengl = -1;
SDL_RendererInfo info;
for (int z = 0; z < count; ++z) {
const int ret = SDL_GetRenderDriverInfo(z, &info);
if (0 == ret) {
if (std::strcmp("opengles", info.name) == 0)
opengles = z;
else if (std::strcmp("opengles2", info.name) == 0)
opengles2 = z;
else if (std::strcmp("opengl", info.name) == 0)
opengl = z;
}
}
#if !defined(FORCE_OPENGLES)
if (opengl > -1)
return RetPairType(opengl, "opengl");
#endif
if (opengles2 > -1)
return RetPairType(opengles2, "opengles2");
if (opengles > -1)
return RetPairType(opengles, "opengles");
#if defined(FORCE_OPENGLES)
if (opengl > -1)
return RetPairType(opengl, "opengl");
#endif
return RetPairType(-1, "default");
}
} //unnamed namespace
struct SDLMain::LocalData {
SDL_Window* window;
SDL_Renderer* renderer;
@ -67,13 +109,19 @@ namespace cloonel {
throw std::runtime_error(SDL_GetError());
parInitSDL.initialized = true;
#if defined(FORCE_OPENGLES)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
#endif
const float2 wh(m_localData->sizeratio.Resolution());
SDL_Window* const win = SDL_CreateWindow(m_gameName.c_str(), 100, 100, static_cast<int>(wh.x()), static_cast<int>(wh.y()), SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
if (!win)
throw std::runtime_error(SDL_GetError());
parInitSDL.window = win;
SDL_Renderer* const renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
const auto rendererDriver = GetRenderingDriver();
m_rendererName = rendererDriver.second;
SDL_Renderer* const renderer = SDL_CreateRenderer(win, rendererDriver.first, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (!renderer)
throw std::runtime_error(SDL_GetError());
parInitSDL.renderer = renderer;