diff --git a/CMakeLists.txt b/CMakeLists.txt index 45273bf..fef7a7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,11 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11 -Wall -Wextra -pe set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11 -Wall -Wextra -pedantic -Wconversion") option(WITH_BUILTIN_PHYSFS "Force using the version of PhysFS accompanying the code even if a system library is available" OFF) +option(FORCE_OPENGLES "Try to chose the openGL ES renderer if available. Enable this on Raspberry Pi" OFF) + +if (FORCE_OPENGLES) + add_definitions(-DFORCE_OPENGLES) +endif (FORCE_OPENGLES) include(FindPkgConfig) PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2) @@ -26,7 +31,7 @@ endif(PHYSFS_FOUND) add_definitions( ${PNG_DEFINITIONS} - -DWITH_VERBOSE_OBS_MANAGER +# -DWITH_VERBOSE_OBS_MANAGER -DWITH_VERBOSE_COLLIDER ) diff --git a/src/main.cpp b/src/main.cpp index 1edfad4..c13a0f6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,6 +58,7 @@ int main (int, char* parArgv[]) { physfs.Append(GAME_BASE_PATH "/resources/", "resources"); sdlmain.Init(); + std::cout << "Using renderer \"" << sdlmain.GetRendererName() << "\"\n"; cloonel::GameplaySceneClassic game(&sdlmain); RunMainLoop(game); diff --git a/src/sdlmain.cpp b/src/sdlmain.cpp index 44c0d52..f2c9654 100644 --- a/src/sdlmain.cpp +++ b/src/sdlmain.cpp @@ -24,8 +24,50 @@ #include #include #include +#include +#include +#include namespace cloonel { + namespace { + ///---------------------------------------------------------------------- + ///---------------------------------------------------------------------- + std::pair GetRenderingDriver() { + typedef std::pair 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(wh.x()), static_cast(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; diff --git a/src/sdlmain.hpp b/src/sdlmain.hpp index 74e8ffd..725540c 100644 --- a/src/sdlmain.hpp +++ b/src/sdlmain.hpp @@ -42,6 +42,7 @@ namespace cloonel { size_t RegisterForResChange ( SizeNotifiableBase* parNotif ); void UnregisterForResChange ( size_t parID ) noexcept; void SwapRegisteredForResChange ( size_t parID, SizeNotifiableBase* parNotif ); + const std::string& GetRendererName ( void ) const { return m_rendererName; } private: struct LocalData; @@ -50,6 +51,7 @@ namespace cloonel { void ClearIFN ( LocalData& parData ) noexcept; const std::string m_gameName; + std::string m_rendererName; std::unique_ptr m_localData; }; } //namespace cloonel