Browse Source

Platform: make SDL2 and GLFW apps buildable without TARGET_GL again.

I'm pretty sure this worked correctly in 2018.04.
pull/325/head
Vladimír Vondruš 7 years ago
parent
commit
053f406b7d
  1. 8
      src/Magnum/Platform/GlfwApplication.cpp
  2. 23
      src/Magnum/Platform/GlfwApplication.h
  3. 16
      src/Magnum/Platform/Sdl2Application.cpp
  4. 25
      src/Magnum/Platform/Sdl2Application.h
  5. 9
      src/Magnum/Platform/Test/GlfwApplicationTest.cpp
  6. 6
      src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

8
src/Magnum/Platform/GlfwApplication.cpp

@ -465,7 +465,11 @@ void GlfwApplication::setupCallbacks() {
}); });
glfwSetFramebufferSizeCallback(_window, [](GLFWwindow* const window, const int w, const int h) { glfwSetFramebufferSizeCallback(_window, [](GLFWwindow* const window, const int w, const int h) {
auto& app = *static_cast<GlfwApplication*>(glfwGetWindowUserPointer(window)); auto& app = *static_cast<GlfwApplication*>(glfwGetWindowUserPointer(window));
ViewportEvent e{{w, h}, app.framebufferSize(), app.dpiScaling()}; ViewportEvent e{{w, h}
#ifdef MAGNUM_TARGET_GL
, app.framebufferSize()
#endif
, app.dpiScaling()};
static_cast<GlfwApplication*>(glfwGetWindowUserPointer(window))->viewportEvent(e); static_cast<GlfwApplication*>(glfwGetWindowUserPointer(window))->viewportEvent(e);
}); });
glfwSetKeyCallback(_window, [](GLFWwindow* const window, const int key, int, const int action, const int mods) { glfwSetKeyCallback(_window, [](GLFWwindow* const window, const int key, int, const int action, const int mods) {
@ -523,6 +527,7 @@ Vector2i GlfwApplication::windowSize() const {
return size; return size;
} }
#ifdef MAGNUM_TARGET_GL
Vector2i GlfwApplication::framebufferSize() const { Vector2i GlfwApplication::framebufferSize() const {
CORRADE_ASSERT(_window, "Platform::GlfwApplication::framebufferSize(): no window opened", {}); CORRADE_ASSERT(_window, "Platform::GlfwApplication::framebufferSize(): no window opened", {});
@ -530,6 +535,7 @@ Vector2i GlfwApplication::framebufferSize() const {
glfwGetFramebufferSize(_window, &size.x(), &size.y()); glfwGetFramebufferSize(_window, &size.x(), &size.y());
return size; return size;
} }
#endif
void GlfwApplication::setSwapInterval(const Int interval) { void GlfwApplication::setSwapInterval(const Int interval) {
glfwSwapInterval(interval); glfwSwapInterval(interval);

23
src/Magnum/Platform/GlfwApplication.h

@ -1206,15 +1206,22 @@ class GlfwApplication::ViewportEvent {
*/ */
Vector2i windowSize() const { return _windowSize; } Vector2i windowSize() const { return _windowSize; }
#if defined(MAGNUM_TARGET_GL) || defined(DOXYGEN_GENERATING_OUTPUT)
/** /**
* @brief Framebuffer size * @brief Framebuffer size
* *
* On some platforms with HiDPI displays, framebuffer size can be * On some platforms with HiDPI displays, framebuffer size can be
* different from @ref windowSize(). See * different from @ref windowSize(). See
* @ref Platform-GlfwApplication-dpi for more information. * @ref Platform-GlfwApplication-dpi for more information.
* @see @ref GlfwApplication::framebufferSize() *
* @note This function is available only if Magnum is compiled with
* @ref MAGNUM_TARGET_GL enabled (done by default). See
* @ref building-features for more information.
*
* @see @ref GlfwApplication::framebufferSize(), @ref dpiScaling()
*/ */
Vector2i framebufferSize() const { return _framebufferSize; } Vector2i framebufferSize() const { return _framebufferSize; }
#endif
/** /**
* @brief DPI scaling * @brief DPI scaling
@ -1223,17 +1230,27 @@ class GlfwApplication::ViewportEvent {
* scaling value being changed in tandem with a window/framebuffer * scaling value being changed in tandem with a window/framebuffer
* size. Simply resizing a window doesn't change the DPI scaling value. * size. Simply resizing a window doesn't change the DPI scaling value.
* See @ref Platform-GlfwApplication-dpi for more information. * See @ref Platform-GlfwApplication-dpi for more information.
* @see @ref GlfwApplication::dpiScaling() * @see @ref GlfwApplication::dpiScaling(), @ref framebufferSize()
*/ */
Vector2 dpiScaling() const { return _dpiScaling; } Vector2 dpiScaling() const { return _dpiScaling; }
private: private:
friend GlfwApplication; friend GlfwApplication;
explicit ViewportEvent(const Vector2i& windowSize, const Vector2i& framebufferSize, const Vector2& dpiScaling): _windowSize{windowSize}, _framebufferSize{framebufferSize}, _dpiScaling{dpiScaling} {} explicit ViewportEvent(const Vector2i& windowSize,
#ifdef MAGNUM_TARGET_GL
const Vector2i& framebufferSize,
#endif
const Vector2& dpiScaling): _windowSize{windowSize},
#ifdef MAGNUM_TARGET_GL
_framebufferSize{framebufferSize},
#endif
_dpiScaling{dpiScaling} {}
const Vector2i _windowSize; const Vector2i _windowSize;
#ifdef MAGNUM_TARGET_GL
const Vector2i _framebufferSize; const Vector2i _framebufferSize;
#endif
const Vector2 _dpiScaling; const Vector2 _dpiScaling;
}; };

16
src/Magnum/Platform/Sdl2Application.cpp

@ -547,6 +547,7 @@ Vector2i Sdl2Application::windowSize() const {
return size; return size;
} }
#ifdef MAGNUM_TARGET_GL
Vector2i Sdl2Application::framebufferSize() const { Vector2i Sdl2Application::framebufferSize() const {
Vector2i size; Vector2i size;
#ifndef CORRADE_TARGET_EMSCRIPTEN #ifndef CORRADE_TARGET_EMSCRIPTEN
@ -558,6 +559,7 @@ Vector2i Sdl2Application::framebufferSize() const {
#endif #endif
return size; return size;
} }
#endif
#ifdef CORRADE_TARGET_EMSCRIPTEN #ifdef CORRADE_TARGET_EMSCRIPTEN
void Sdl2Application::setContainerCssClass(const std::string& cssClass) { void Sdl2Application::setContainerCssClass(const std::string& cssClass) {
@ -671,7 +673,11 @@ void Sdl2Application::mainLoopIteration() {
https://github.com/kripken/emscripten/issues/1731 */ https://github.com/kripken/emscripten/issues/1731 */
CORRADE_ASSERT_UNREACHABLE(); CORRADE_ASSERT_UNREACHABLE();
#else #else
ViewportEvent e{event, {event.window.data1, event.window.data2}, framebufferSize(), _dpiScaling}; ViewportEvent e{event, {event.window.data1, event.window.data2},
#ifdef MAGNUM_TARGET_GL
framebufferSize(),
#endif
_dpiScaling};
/** @todo handle also WM_DPICHANGED events when a window is moved between displays with different DPI */ /** @todo handle also WM_DPICHANGED events when a window is moved between displays with different DPI */
viewportEvent(e); viewportEvent(e);
_flags |= Flag::Redraw; _flags |= Flag::Redraw;
@ -835,7 +841,13 @@ void Sdl2Application::anyEvent(SDL_Event&) {
void Sdl2Application::viewportEvent(ViewportEvent& event) { void Sdl2Application::viewportEvent(ViewportEvent& event) {
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
CORRADE_IGNORE_DEPRECATED_PUSH CORRADE_IGNORE_DEPRECATED_PUSH
viewportEvent(event.framebufferSize()); viewportEvent(
#ifdef MAGNUM_TARGET_GL
event.framebufferSize()
#else
event.windowSize()
#endif
);
CORRADE_IGNORE_DEPRECATED_POP CORRADE_IGNORE_DEPRECATED_POP
#else #else
static_cast<void>(event); static_cast<void>(event);

25
src/Magnum/Platform/Sdl2Application.h

@ -657,7 +657,7 @@ class Sdl2Application {
* @ref MAGNUM_TARGET_GL enabled (done by default). See * @ref MAGNUM_TARGET_GL enabled (done by default). See
* @ref building-features for more information. * @ref building-features for more information.
* *
* @see @ref dpiScaling() * @see @ref Sdl2Application::framebufferSize(), @ref dpiScaling()
*/ */
Vector2i framebufferSize() const; Vector2i framebufferSize() const;
#endif #endif
@ -670,7 +670,7 @@ class Sdl2Application {
* zero vector, use @ref dpiScaling(const Configuration&) const for * zero vector, use @ref dpiScaling(const Configuration&) const for
* calculating a value independently. See @ref Platform-Sdl2Application-dpi * calculating a value independently. See @ref Platform-Sdl2Application-dpi
* for more information. * for more information.
* @see @ref framebufferSize() * @see @ref Sdl2Application::dpiScaling(), @ref framebufferSize()
*/ */
Vector2 dpiScaling() const { return _dpiScaling; } Vector2 dpiScaling() const { return _dpiScaling; }
@ -1740,15 +1740,22 @@ class Sdl2Application::ViewportEvent {
*/ */
Vector2i windowSize() const { return _windowSize; } Vector2i windowSize() const { return _windowSize; }
#if defined(MAGNUM_TARGET_GL) || defined(DOXYGEN_GENERATING_OUTPUT)
/** /**
* @brief Framebuffer size * @brief Framebuffer size
* *
* On some platforms with HiDPI displays, framebuffer size can be * On some platforms with HiDPI displays, framebuffer size can be
* different from @ref windowSize(). See * different from @ref windowSize(). See
* @ref Platform-Sdl2Application-dpi for more information. * @ref Platform-Sdl2Application-dpi for more information.
*
* @note This function is available only if Magnum is compiled with
* @ref MAGNUM_TARGET_GL enabled (done by default). See
* @ref building-features for more information.
*
* @see @ref Sdl2Application::framebufferSize() * @see @ref Sdl2Application::framebufferSize()
*/ */
Vector2i framebufferSize() const { return _framebufferSize; } Vector2i framebufferSize() const { return _framebufferSize; }
#endif
/** /**
* @brief DPI scaling * @brief DPI scaling
@ -1779,17 +1786,27 @@ class Sdl2Application::ViewportEvent {
#ifndef CORRADE_TARGET_EMSCRIPTEN #ifndef CORRADE_TARGET_EMSCRIPTEN
const SDL_Event& event, const SDL_Event& event,
#endif #endif
const Vector2i& windowSize, const Vector2i& framebufferSize, const Vector2& dpiScaling): const Vector2i& windowSize,
#ifdef MAGNUM_TARGET_GL
const Vector2i& framebufferSize,
#endif
const Vector2& dpiScaling):
#ifndef CORRADE_TARGET_EMSCRIPTEN #ifndef CORRADE_TARGET_EMSCRIPTEN
_event(event), _event(event),
#endif #endif
_windowSize{windowSize}, _framebufferSize{framebufferSize}, _dpiScaling{dpiScaling} {} _windowSize{windowSize},
#ifdef MAGNUM_TARGET_GL
_framebufferSize{framebufferSize},
#endif
_dpiScaling{dpiScaling} {}
#ifndef CORRADE_TARGET_EMSCRIPTEN #ifndef CORRADE_TARGET_EMSCRIPTEN
const SDL_Event& _event; const SDL_Event& _event;
#endif #endif
const Vector2i _windowSize; const Vector2i _windowSize;
#ifdef MAGNUM_TARGET_GL
const Vector2i _framebufferSize; const Vector2i _framebufferSize;
#endif
const Vector2 _dpiScaling; const Vector2 _dpiScaling;
}; };

9
src/Magnum/Platform/Test/GlfwApplicationTest.cpp

@ -30,6 +30,15 @@ namespace Magnum { namespace Platform { namespace Test { namespace {
struct GlfwApplicationTest: Platform::Application { struct GlfwApplicationTest: Platform::Application {
explicit GlfwApplicationTest(const Arguments& arguments): Platform::Application{arguments} {} explicit GlfwApplicationTest(const Arguments& arguments): Platform::Application{arguments} {}
/* For testing HiDPI resize events */
void viewportEvent(ViewportEvent& event) override {
Debug{} << "viewport event" << event.windowSize()
#ifdef MAGNUM_TARGET_GL
<< event.framebufferSize()
#endif
<< event.dpiScaling();
}
void keyPressEvent(KeyEvent& event) override { void keyPressEvent(KeyEvent& event) override {
#if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302 #if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302
Debug{} << "key press event:" << event.keyName(); Debug{} << "key press event:" << event.keyName();

6
src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

@ -42,7 +42,11 @@ struct Sdl2ApplicationTest: Platform::Application {
/* For testing HiDPI resize events */ /* For testing HiDPI resize events */
void viewportEvent(ViewportEvent& event) override { void viewportEvent(ViewportEvent& event) override {
Debug{} << "viewport event" << event.windowSize() << event.framebufferSize() << event.dpiScaling(); Debug{} << "viewport event" << event.windowSize()
#ifdef MAGNUM_TARGET_GL
<< event.framebufferSize()
#endif
<< event.dpiScaling();
} }
/* For testing event coordinates */ /* For testing event coordinates */

Loading…
Cancel
Save