From c74551e5c78f3985d7849e029f7cdd5fe89cd8e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 9 Aug 2012 01:38:00 +0200 Subject: [PATCH 1/4] Doc++ --- src/Contexts/EglContext.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Contexts/EglContext.h b/src/Contexts/EglContext.h index 29a961856..02e337129 100644 --- a/src/Contexts/EglContext.h +++ b/src/Contexts/EglContext.h @@ -38,7 +38,7 @@ namespace Magnum { namespace Contexts { /** @brief X/EGL context -Currently only barebone implementation with no event handling. +Supports keyboard and mouse handling. */ class EglContext: public AbstractContext { public: @@ -172,6 +172,7 @@ class EglContext: public AbstractContext { /*@}*/ /** @{ @name Mouse handling */ + public: /** @brief Mouse button */ enum class MouseButton: unsigned int { @@ -199,6 +200,8 @@ class EglContext: public AbstractContext { */ virtual void mouseReleaseEvent(MouseButton button, const Math::Vector2& position); + /*@}*/ + private: Display* xDisplay; Window xWindow; From d5ab207552783accc944494117cf7165266f369d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 9 Aug 2012 01:58:23 +0200 Subject: [PATCH 2/4] Fixed compilation on non-GLES targets (oops). --- src/AbstractTexture.cpp | 6 +++--- src/AbstractTexture.h | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 625359b7f..fdce8c9ea 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -50,7 +50,7 @@ GLfloat AbstractTexture::maxSupportedAnisotropy() { void AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) { #ifndef MAGNUM_TARGET_GLES - CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE || mipmap == Mipmap::BaseLevel, "AbstractTexture: rectangle textures cannot have mipmaps", ) + CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE || mipmap == Mipmap::BaseLevel, "AbstractTexture: rectangle textures cannot have mipmaps", ); #endif bind(); @@ -60,7 +60,7 @@ void AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) { void AbstractTexture::generateMipmap() { #ifndef MAGNUM_TARGET_GLES - CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE, "AbstractTexture: rectangle textures cannot have mipmaps", ) + CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE, "AbstractTexture: rectangle textures cannot have mipmaps", ); #endif bind(); @@ -110,7 +110,7 @@ AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components comp #ifndef DOXYGEN_GENERATING_OUTPUT void AbstractTexture::DataHelper<2>::setWrapping(GLenum target, const Math::Vector<2, Wrapping>& wrapping) { #ifndef MAGNUM_TARGET_GLES - CORRADE_ASSERT(target != GL_TEXTURE_RECTANGLE || ((wrapping[0] == Wrapping::ClampToEdge || wrapping[0] == Wrapping::ClampToBorder) && (wrapping[0] == Wrapping::ClampToEdge || wrapping[1] == Wrapping::ClampToEdge)), "AbstractTexture: rectangle texture wrapping must either clamp to border or to edge", ) + CORRADE_ASSERT(target != GL_TEXTURE_RECTANGLE || ((wrapping[0] == Wrapping::ClampToEdge || wrapping[0] == Wrapping::ClampToBorder) && (wrapping[0] == Wrapping::ClampToEdge || wrapping[1] == Wrapping::ClampToEdge)), "AbstractTexture: rectangle texture wrapping must either clamp to border or to edge", ); #endif glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index ce766a7ab..cae04f499 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -327,19 +327,23 @@ class MAGNUM_EXPORT AbstractTexture { * Four-component RGBA, unsigned normalized, each component 4bit, * 16bit total. */ - RGBA4 = GL_RGBA4, + RGBA4 = GL_RGBA4 #ifndef MAGNUM_TARGET_GLES + , + /** * Three-component RGB, float, red and green 11bit, blue 10bit, * 32bit total. * @requires_gl * @requires_gl30 Extension @extension{EXT,packed_float} */ - RG11B10Float = GL_R11F_G11F_B10F, + RG11B10Float = GL_R11F_G11F_B10F #endif #if defined(GL_RGB565) || defined(DOXYGEN_GENERATING_OUTPUT) + , + /** * Three-component RGB, unsigned normalized, red and blue 5bit, * green 6bit, 16bit total. @@ -619,7 +623,7 @@ class MAGNUM_EXPORT AbstractTexture { * to `ClampToBorder`. * @requires_gl */ - inline void setBorderColor(const Color4& color) { + inline void setBorderColor(const Color4& color) { bind(); glTexParameterfv(_target, GL_TEXTURE_BORDER_COLOR, color.data()); } From d03fe4d41d4b63b7451369ad4575d39a3e2139d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 9 Aug 2012 02:03:48 +0200 Subject: [PATCH 3/4] Limited static polymorphism of EglContext and GlutContext. If being careful, it's now possible to swap GlutContext with EglContext. GlutContext doesn't have keyReleaseEvent() and many keys, but EglContext doesn't have e.g. mouseMotionEvent(). --- src/Contexts/EglContext.h | 3 +++ src/Contexts/GlutContext.h | 40 +++++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/Contexts/EglContext.h b/src/Contexts/EglContext.h index 02e337129..1c1c7f628 100644 --- a/src/Contexts/EglContext.h +++ b/src/Contexts/EglContext.h @@ -74,6 +74,9 @@ class EglContext: public AbstractContext { /** @copydoc GlutContext::swapBuffers() */ inline void swapBuffers() { eglSwapBuffers(display, surface); } + /** @todo implement */ + inline void redraw() {} + /*@}*/ /** @{ @name Keyboard handling */ diff --git a/src/Contexts/GlutContext.h b/src/Contexts/GlutContext.h index 454bd5b0a..17a3c921c 100644 --- a/src/Contexts/GlutContext.h +++ b/src/Contexts/GlutContext.h @@ -123,11 +123,13 @@ class GlutContext: public AbstractContext { protected: /** - * @brief Key event + * @brief Key press event + * @param key Key pressed + * @param position Cursor position * * Called when an key is pressed. Default implementation does nothing. */ - virtual void keyEvent(Key key, const Math::Vector2& position); + virtual void keyPressEvent(Key key, const Math::Vector2& position); /*@}*/ @@ -143,12 +145,6 @@ class GlutContext: public AbstractContext { WheelDown = 4 /**< Wheel down */ }; - /** @brief Mouse state */ - enum class MouseState: int { - Up = GLUT_UP, /**< No button pressed */ - Down = GLUT_DOWN /**< Button pressed */ - }; - /** @brief Mouse cursor */ enum class MouseCursor: int { Default = GLUT_CURSOR_INHERIT, /**< Default cursor provided by parent window */ @@ -177,12 +173,20 @@ class GlutContext: public AbstractContext { protected: /** - * @brief Mouse event + * @brief Mouse press event * - * Called when mouse button is pressed or released. Default - * implementation does nothing. + * Called when mouse button is pressed. Default implementation does + * nothing. + */ + virtual void mousePressEvent(MouseButton button, const Math::Vector2& position); + + /** + * @brief Mouse release event + * + * Called when mouse button is released. Default implementation does + * nothing. */ - virtual void mouseEvent(MouseButton button, MouseState state, const Math::Vector2& position); + virtual void mouseReleaseEvent(MouseButton button, const Math::Vector2& position); /** * @brief Mouse motion event @@ -202,11 +206,14 @@ class GlutContext: public AbstractContext { } inline static void staticKeyEvent(int key, int x, int y) { - instance->keyEvent(static_cast(key), {x, y}); + instance->keyPressEvent(static_cast(key), {x, y}); } inline static void staticMouseEvent(int button, int state, int x, int y) { - instance->mouseEvent(static_cast(button), static_cast(state), {x, y}); + if(state == GLUT_DOWN) + instance->mousePressEvent(static_cast(button), {x, y}); + else + instance->mouseReleaseEvent(static_cast(button), {x, y}); } inline static void staticMouseMotionEvent(int x, int y) { @@ -224,8 +231,9 @@ class GlutContext: public AbstractContext { }; /* Implementations for inline functions with unused parameters */ -inline void GlutContext::keyEvent(GlutContext::Key, const Math::Vector2&) {} -inline void GlutContext::mouseEvent(GlutContext::MouseButton, GlutContext::MouseState, const Math::Vector2&) {} +inline void GlutContext::keyPressEvent(GlutContext::Key, const Math::Vector2&) {} +inline void GlutContext::mousePressEvent(GlutContext::MouseButton, const Math::Vector2&) {} +inline void GlutContext::mouseReleaseEvent(GlutContext::MouseButton, const Math::Vector2&) {} inline void GlutContext::mouseMotionEvent(const Math::Vector2&) {} }} From 794f9bdec5af8eae46e177fffe2742fbaf79708e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 9 Aug 2012 02:19:29 +0200 Subject: [PATCH 4/4] Minor cleanup. --- src/Contexts/Sdl2Context.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Contexts/Sdl2Context.h b/src/Contexts/Sdl2Context.h index 221a2dccc..fb4b00a22 100644 --- a/src/Contexts/Sdl2Context.h +++ b/src/Contexts/Sdl2Context.h @@ -20,10 +20,10 @@ */ #include "Magnum.h" -#include +#include +#include #include "AbstractContext.h" -#include namespace Magnum { namespace Contexts {