Add the call to bcm_host_init/deinit() on raspberry pi.

This commit is contained in:
King_DuckZ 2014-08-06 21:04:57 +02:00
parent 0d2f584229
commit 6cf749c82c
2 changed files with 51 additions and 3 deletions

View file

@ -7,10 +7,14 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11 -Wall -Wextra
option(WITH_BUILTIN_PHYSFS "Force using the version of PhysFS accompanying the code even if a system library is available" OFF) 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) option(FORCE_OPENGLES "Try to chose the openGL ES renderer if available. Enable this on Raspberry Pi" OFF)
option(RASPBERRY_PI "Compile for Raspberry Pi" OFF)
if (FORCE_OPENGLES) if (FORCE_OPENGLES OR RASPBERRY_PI)
add_definitions(-DFORCE_OPENGLES) add_definitions(-DFORCE_OPENGLES)
endif (FORCE_OPENGLES) if (RASPBERRY_PI)
add_definitions(-DRASPBERRY_PI)
endif(RASPBERRY_PI)
endif (FORCE_OPENGLES OR RASPBERRY_PI)
include(FindPkgConfig) include(FindPkgConfig)
PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2) PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
@ -35,6 +39,16 @@ add_definitions(
-DWITH_VERBOSE_COLLIDER -DWITH_VERBOSE_COLLIDER
) )
if (RASPBERRY_PI)
message(STATUS "Will build for Raspberry Pi")
include_directories(SYSTEM
/opt/vc/include
)
link_directories(
/opt/vc/lib
)
endif (RASPBERRY_PI)
include_directories(SYSTEM include_directories(SYSTEM
${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIR}
${PNG_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS}
@ -93,3 +107,9 @@ target_link_libraries(${PROJECT_NAME}
${PHYSFS_LIBRARY} ${PHYSFS_LIBRARY}
${PNG_LIBRARIES} ${PNG_LIBRARIES}
) )
if (RASPBERRY_PI)
target_link_libraries(${PROJECT_NAME}
bcm_host
)
endif(RASPBERRY_PI)

View file

@ -28,6 +28,10 @@
#include <cstring> #include <cstring>
#include <utility> #include <utility>
#if defined(RASPBERRY_PI)
#include <bcm_host.h>
#endif
namespace cloonel { namespace cloonel {
namespace { namespace {
///---------------------------------------------------------------------- ///----------------------------------------------------------------------
@ -74,6 +78,9 @@ namespace cloonel {
SizeRatio sizeratio; SizeRatio sizeratio;
ObserversManager<SizeNotifiableBase*> resChangeNotifList; ObserversManager<SizeNotifiableBase*> resChangeNotifList;
bool initialized; bool initialized;
#if defined(RASPBERRY_PI)
bool bcmInitialized;
#endif
}; };
///------------------------------------------------------------------------ ///------------------------------------------------------------------------
@ -83,12 +90,19 @@ namespace cloonel {
m_localData(new LocalData) m_localData(new LocalData)
{ {
m_localData->sizeratio.SetOriginal(static_cast<float2>(parReferenceRes), static_cast<float2>(parRes)); m_localData->sizeratio.SetOriginal(static_cast<float2>(parReferenceRes), static_cast<float2>(parRes));
m_localData->initialized = false;
#if defined(RASPBERRY_PI)
m_localData->bcmInitialized = false;
#endif
} }
///------------------------------------------------------------------------ ///------------------------------------------------------------------------
///------------------------------------------------------------------------ ///------------------------------------------------------------------------
SDLMain::~SDLMain() noexcept { SDLMain::~SDLMain() noexcept {
ClearIFN(*m_localData); ClearIFN(*m_localData);
#if defined(RASPBERRY_PI)
assert(not m_localData->bcmInitialized);
#endif
} }
///------------------------------------------------------------------------ ///------------------------------------------------------------------------
@ -109,6 +123,12 @@ namespace cloonel {
throw std::runtime_error(SDL_GetError()); throw std::runtime_error(SDL_GetError());
parInitSDL.initialized = true; parInitSDL.initialized = true;
#if defined(RASPBERRY_PI)
assert(not parInitSDL.bcmInitialized);
bcm_host_init();
parInitSDL.bcmInitialized = true;
#endif
#if defined(FORCE_OPENGLES) #if defined(FORCE_OPENGLES)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
#endif #endif
@ -134,9 +154,17 @@ namespace cloonel {
SDL_DestroyRenderer(parInitSDL.renderer); SDL_DestroyRenderer(parInitSDL.renderer);
if (parInitSDL.window) if (parInitSDL.window)
SDL_DestroyWindow(parInitSDL.window); SDL_DestroyWindow(parInitSDL.window);
if (parInitSDL.initialized) if (parInitSDL.initialized) {
parInitSDL.initialized = false;
SDL_Quit(); SDL_Quit();
} }
#if defined(RASPBERRY_PI)
if (parInitSDL.bcmInitialized) {
parInitSDL.bcmInitialized = false;
bcm_host_deinit();
}
#endif
}
///------------------------------------------------------------------------ ///------------------------------------------------------------------------
///------------------------------------------------------------------------ ///------------------------------------------------------------------------