Browse Source

Merge branch 'master' into compatibility

Vladimír Vondruš 11 years ago
parent
commit
e7676525eb
  1. 2
      modules/FindMagnum.cmake
  2. 5
      src/CMakeLists.txt
  3. 93
      src/Magnum/Platform/NaClApplication.cpp
  4. 19
      src/Magnum/Platform/NaClApplication.h

2
modules/FindMagnum.cmake

@ -246,7 +246,7 @@ foreach(component ${Magnum_FIND_COMPONENTS})
if(component MATCHES ".+AudioImporter") if(component MATCHES ".+AudioImporter")
set(_MAGNUM_${_COMPONENT}_DEPENDENCIES Audio) set(_MAGNUM_${_COMPONENT}_DEPENDENCIES Audio)
elseif(component MATCHES ".+(Font|FontConverter)") elseif(component MATCHES ".+(Font|FontConverter)")
set(_MAGNUM_${_COMPONENT}_DEPENDENCIES TextureTools Text) set(_MAGNUM_${_COMPONENT}_DEPENDENCIES Text TextureTools)
endif() endif()
list(APPEND _MAGNUM_ADDITIONAL_COMPONENTS ${_MAGNUM_${_COMPONENT}_DEPENDENCIES}) list(APPEND _MAGNUM_ADDITIONAL_COMPONENTS ${_MAGNUM_${_COMPONENT}_DEPENDENCIES})

5
src/CMakeLists.txt

@ -49,6 +49,11 @@ elseif(CORRADE_GCC45_COMPATIBILITY AND NOT CORRADE_GCC44_COMPATIBILITY)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing")
endif() endif()
# On MSVC remove /W3, as we are replacing it with /W4
if(MSVC)
string(REPLACE "/W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CORRADE_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CORRADE_CXX_FLAGS}")
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CORRADE_INCLUDE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CORRADE_INCLUDE_DIR})

93
src/Magnum/Platform/NaClApplication.cpp

@ -58,16 +58,14 @@ NaClApplication::ConsoleDebugOutput::ConsoleDebugOutput(pp::Instance* instance):
Error::setOutput(&errorOutput); Error::setOutput(&errorOutput);
} }
/** @todo Delegating constructor when support for GCC 4.6 is dropped */ NaClApplication::NaClApplication(const Arguments& arguments, const Configuration& configuration): Instance(arguments), Graphics3DClient(this), MouseLock(this) {
_debugOutput.reset(new ConsoleDebugOutput{this});
NaClApplication::NaClApplication(const Arguments& arguments, const Configuration& configuration): Instance(arguments), Graphics3DClient(this), MouseLock(this), graphics(nullptr), fullscreen(nullptr), c(nullptr) {
debugOutput = new ConsoleDebugOutput(this);
createContext(configuration); createContext(configuration);
} }
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
NaClApplication::NaClApplication(const Arguments& arguments): Instance(arguments), Graphics3DClient(this), MouseLock(this), c(nullptr) { NaClApplication::NaClApplication(const Arguments& arguments): Instance(arguments), Graphics3DClient(this), MouseLock(this) {
debugOutput = new ConsoleDebugOutput(this); _debugOutput.reset(new ConsoleDebugOutput{this});
createContext(); createContext();
} }
#endif #endif
@ -77,9 +75,9 @@ NaClApplication::NaClApplication(const Arguments& arguments, std::nullptr_t)
#else #else
NaClApplication::NaClApplication(const Arguments& arguments, void*) NaClApplication::NaClApplication(const Arguments& arguments, void*)
#endif #endif
: Instance(arguments), Graphics3DClient(this), MouseLock(this), c(nullptr) : Instance(arguments), Graphics3DClient(this), MouseLock(this)
{ {
debugOutput = new ConsoleDebugOutput(this); _debugOutput.reset(new ConsoleDebugOutput{this});
} }
void NaClApplication::createContext() { createContext({}); } void NaClApplication::createContext() { createContext({}); }
@ -89,9 +87,9 @@ void NaClApplication::createContext(const Configuration& configuration) {
} }
bool NaClApplication::tryCreateContext(const Configuration& configuration) { bool NaClApplication::tryCreateContext(const Configuration& configuration) {
CORRADE_ASSERT(!c, "Platform::NaClApplication::tryCreateContext(): context already created", false); CORRADE_ASSERT(!_context, "Platform::NaClApplication::tryCreateContext(): context already created", false);
viewportSize = configuration.size(); _viewportSize = configuration.size();
const std::int32_t attributes[] = { const std::int32_t attributes[] = {
PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8,
@ -104,69 +102,62 @@ bool NaClApplication::tryCreateContext(const Configuration& configuration) {
PP_GRAPHICS3DATTRIB_NONE PP_GRAPHICS3DATTRIB_NONE
}; };
graphics = new pp::Graphics3D(this, attributes); _graphics.reset(new pp::Graphics3D(this, attributes));
if(graphics->is_null()) { if(_graphics->is_null()) {
Error() << "Platform::NaClApplication::tryCreateContext(): cannot create context"; Error() << "Platform::NaClApplication::tryCreateContext(): cannot create context";
delete graphics; _graphics.reset();
graphics = nullptr;
return false; return false;
} }
if(!BindGraphics(*graphics)) { if(!BindGraphics(*_graphics)) {
Error() << "Platform::NaClApplication::tryCreateContext(): cannot bind graphics"; Error() << "Platform::NaClApplication::tryCreateContext(): cannot bind graphics";
delete graphics; _graphics.reset();
graphics = nullptr;
return false; return false;
} }
fullscreen = new pp::Fullscreen(this); _fullscreen.reset(new pp::Fullscreen(this));
glSetCurrentContextPPAPI(graphics->pp_resource()); glSetCurrentContextPPAPI(_graphics->pp_resource());
/* Enable input handling for mouse and keyboard */ /* Enable input handling for mouse and keyboard */
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE|PP_INPUTEVENT_CLASS_WHEEL); RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE|PP_INPUTEVENT_CLASS_WHEEL);
RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
c = new Platform::Context; _context.reset(new Platform::Context);
return true; return true;
} }
NaClApplication::~NaClApplication() { NaClApplication::~NaClApplication() = default;
delete c;
delete fullscreen;
delete graphics;
delete debugOutput;
}
bool NaClApplication::isFullscreen() { bool NaClApplication::isFullscreen() {
return fullscreen->IsFullscreen(); return _fullscreen->IsFullscreen();
} }
bool NaClApplication::setFullscreen(bool enabled) { bool NaClApplication::setFullscreen(bool enabled) {
/* Given fullscreen mode already set or switching to it is in progress, done */ /* Given fullscreen mode already set or switching to it is in progress, done */
if(isFullscreen() == enabled || ((flags & Flag::FullscreenSwitchInProgress) && (flags & Flag::WillBeFullscreen) == enabled)) if(isFullscreen() == enabled || ((_flags & Flag::FullscreenSwitchInProgress) && (_flags & Flag::WillBeFullscreen) == enabled))
return true; return true;
/* Switch to opposite fullscreen mode is in progress, can't revert it back */ /* Switch to opposite fullscreen mode is in progress, can't revert it back */
if((flags & Flag::FullscreenSwitchInProgress) && (flags & Flag::WillBeFullscreen) != enabled) if((_flags & Flag::FullscreenSwitchInProgress) && (_flags & Flag::WillBeFullscreen) != enabled)
return false; return false;
/* Set fullscreen */ /* Set fullscreen */
if(!fullscreen->SetFullscreen(enabled)) if(!_fullscreen->SetFullscreen(enabled))
return false; return false;
/* Set flags */ /* Set flags */
flags |= Flag::FullscreenSwitchInProgress; _flags |= Flag::FullscreenSwitchInProgress;
enabled ? flags |= Flag::WillBeFullscreen : flags &= ~Flag::WillBeFullscreen; enabled ? _flags |= Flag::WillBeFullscreen : _flags &= ~Flag::WillBeFullscreen;
return true; return true;
} }
void NaClApplication::DidChangeView(const pp::View& view) { void NaClApplication::DidChangeView(const pp::View& view) {
/* Fullscreen switch in progress */ /* Fullscreen switch in progress */
if(flags & Flag::FullscreenSwitchInProgress) { if(_flags & Flag::FullscreenSwitchInProgress) {
/* Done, remove the progress flag */ /* Done, remove the progress flag */
if(isFullscreen() == bool(flags & Flag::WillBeFullscreen)) { if(isFullscreen() == bool(_flags & Flag::WillBeFullscreen)) {
flags &= ~Flag::FullscreenSwitchInProgress; _flags &= ~Flag::FullscreenSwitchInProgress;
flags |= Flag::Redraw; _flags |= Flag::Redraw;
} }
/* Don't process anything during the switch */ /* Don't process anything during the switch */
@ -176,9 +167,9 @@ void NaClApplication::DidChangeView(const pp::View& view) {
Vector2i size(view.GetRect().width(), view.GetRect().height()); Vector2i size(view.GetRect().width(), view.GetRect().height());
/* Canvas resized */ /* Canvas resized */
if(viewportSize != size) { if(_viewportSize != size) {
graphics->ResizeBuffers(size.x(), size.y()); _graphics->ResizeBuffers(size.x(), size.y());
viewportEvent(viewportSize = size); viewportEvent(_viewportSize = size);
} }
drawEvent(); drawEvent();
@ -186,9 +177,9 @@ void NaClApplication::DidChangeView(const pp::View& view) {
bool NaClApplication::HandleInputEvent(const pp::InputEvent& event) { bool NaClApplication::HandleInputEvent(const pp::InputEvent& event) {
/* Don't handle anything during switch from/to fullscreen */ /* Don't handle anything during switch from/to fullscreen */
if(flags & Flag::FullscreenSwitchInProgress) return false; if(_flags & Flag::FullscreenSwitchInProgress) return false;
Flags tmpFlags = flags; Flags tmpFlags = _flags;
switch(event.GetType()) { switch(event.GetType()) {
case PP_INPUTEVENT_TYPE_KEYDOWN: case PP_INPUTEVENT_TYPE_KEYDOWN:
@ -230,11 +221,11 @@ bool NaClApplication::HandleInputEvent(const pp::InputEvent& event) {
} }
/* Assume everything is properly sequential here */ /* Assume everything is properly sequential here */
CORRADE_INTERNAL_ASSERT((tmpFlags & Flag::SwapInProgress) == (flags & Flag::SwapInProgress)); CORRADE_INTERNAL_ASSERT((tmpFlags & Flag::SwapInProgress) == (_flags & Flag::SwapInProgress));
/* Redraw, if it won't be handled after swap automatically */ /* Redraw, if it won't be handled after swap automatically */
if((flags & Flag::Redraw) && !(flags & Flag::SwapInProgress)) { if((_flags & Flag::Redraw) && !(_flags & Flag::SwapInProgress)) {
flags &= ~Flag::Redraw; _flags &= ~Flag::Redraw;
drawEvent(); drawEvent();
} }
@ -243,20 +234,20 @@ bool NaClApplication::HandleInputEvent(const pp::InputEvent& event) {
void NaClApplication::swapBuffers() { void NaClApplication::swapBuffers() {
/* Swap already in progress, do nothing */ /* Swap already in progress, do nothing */
if(flags & Flag::SwapInProgress) return; if(_flags & Flag::SwapInProgress) return;
/* Swap buffers and call swapCallback() when done */ /* Swap buffers and call swapCallback() when done */
flags |= Flag::SwapInProgress; _flags |= Flag::SwapInProgress;
graphics->SwapBuffers(pp::CompletionCallback(&swapCallback, this)); _graphics->SwapBuffers(pp::CompletionCallback(&swapCallback, this));
} }
void NaClApplication::swapCallback(void* applicationInstance, std::int32_t) { void NaClApplication::swapCallback(void* applicationInstance, std::int32_t) {
NaClApplication* instance = static_cast<NaClApplication*>(applicationInstance); NaClApplication* instance = static_cast<NaClApplication*>(applicationInstance);
instance->flags &= ~Flag::SwapInProgress; instance->_flags &= ~Flag::SwapInProgress;
/* Redraw, if requested */ /* Redraw, if requested */
if(instance->flags & Flag::Redraw) { if(instance->_flags & Flag::Redraw) {
instance->flags &= ~Flag::Redraw; instance->_flags &= ~Flag::Redraw;
instance->drawEvent(); instance->drawEvent();
} }
} }
@ -271,7 +262,7 @@ void NaClApplication::setMouseLocked(bool enabled) {
void NaClApplication::mouseLockCallback(void* applicationInstance, std::int32_t) { void NaClApplication::mouseLockCallback(void* applicationInstance, std::int32_t) {
NaClApplication* instance = static_cast<NaClApplication*>(applicationInstance); NaClApplication* instance = static_cast<NaClApplication*>(applicationInstance);
instance->flags |= Flag::MouseLocked; instance->_flags |= Flag::MouseLocked;
} }
void NaClApplication::viewportEvent(const Vector2i&) {} void NaClApplication::viewportEvent(const Vector2i&) {}

19
src/Magnum/Platform/NaClApplication.h

@ -29,6 +29,7 @@
* @brief Class @ref Magnum::Platform::NaClApplication, macro @ref MAGNUM_NACLAPPLICATION_MAIN() * @brief Class @ref Magnum::Platform::NaClApplication, macro @ref MAGNUM_NACLAPPLICATION_MAIN()
*/ */
#include <memory>
#include <string> #include <string>
#include <Corrade/compatibility.h> #include <Corrade/compatibility.h>
#include <Corrade/Containers/EnumSet.h> #include <Corrade/Containers/EnumSet.h>
@ -283,7 +284,7 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public
void swapBuffers(); void swapBuffers();
/** @copydoc Sdl2Application::redraw() */ /** @copydoc Sdl2Application::redraw() */
void redraw() { flags |= Flag::Redraw; } void redraw() { _flags |= Flag::Redraw; }
#ifdef DOXYGEN_GENERATING_OUTPUT #ifdef DOXYGEN_GENERATING_OUTPUT
protected: protected:
@ -324,7 +325,7 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public
public: public:
/** @brief Whether mouse is locked */ /** @brief Whether mouse is locked */
bool isMouseLocked() const { return flags & Flag::MouseLocked; } bool isMouseLocked() const { return _flags & Flag::MouseLocked; }
/** /**
* @brief Enable or disable mouse locking * @brief Enable or disable mouse locking
@ -386,7 +387,7 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public
} }
void MouseLockLost() override { void MouseLockLost() override {
flags &= ~Flag::MouseLocked; _flags &= ~Flag::MouseLocked;
} }
void DidChangeView(const pp::View& view) override; void DidChangeView(const pp::View& view) override;
@ -396,13 +397,13 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public
static void swapCallback(void* applicationInstance, std::int32_t); static void swapCallback(void* applicationInstance, std::int32_t);
static void mouseLockCallback(void* applicationInstance, std::int32_t); static void mouseLockCallback(void* applicationInstance, std::int32_t);
pp::Graphics3D* graphics; std::unique_ptr<pp::Graphics3D> _graphics;
pp::Fullscreen* fullscreen; std::unique_ptr<pp::Fullscreen> _fullscreen;
Platform::Context* c; Vector2i _viewportSize;
Vector2i viewportSize; Flags _flags;
Flags flags;
ConsoleDebugOutput* debugOutput; std::unique_ptr<ConsoleDebugOutput> _debugOutput;
std::unique_ptr<Platform::Context> _context;
CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) CORRADE_ENUMSET_FRIEND_OPERATORS(Flags)
}; };

Loading…
Cancel
Save