From 72ffca1dade0605f0b79ecaaa630e2ba89a5e457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 21 Nov 2012 14:37:20 +0100 Subject: [PATCH 01/11] Cube primitive has now flat normals. Exactly how would everyone expect. --- src/Primitives/Cube.cpp | 95 +++++++++++++++++++++++++++++++++-------- src/Primitives/Cube.h | 3 +- 2 files changed, 79 insertions(+), 19 deletions(-) diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index 739f2e6dd..12d92139f 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -21,30 +21,91 @@ using namespace std; namespace Magnum { namespace Primitives { -Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ - 0, 2, 1, - 2, 3, 1, - 1, 3, 5, - 3, 7, 5, - 5, 7, 4, - 7, 6, 4, - 4, 6, 0, - 6, 2, 0, - 2, 7, 3, - 2, 6, 7, - 4, 1, 5, - 4, 0, 1 -}, {new vector}, {new vector{ +Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, nullptr, {new vector{ + {-1.0f, -1.0f, 1.0f}, + { 1.0f, -1.0f, 1.0f}, + { 1.0f, 1.0f, 1.0f}, /* +Z */ + {-1.0f, -1.0f, 1.0f}, + { 1.0f, 1.0f, 1.0f}, + {-1.0f, 1.0f, 1.0f}, + + { 1.0f, -1.0f, 1.0f}, + { 1.0f, -1.0f, -1.0f}, + { 1.0f, 1.0f, -1.0f}, /* +X */ + { 1.0f, -1.0f, 1.0f}, + { 1.0f, 1.0f, -1.0f}, + { 1.0f, 1.0f, 1.0f}, + + {-1.0f, 1.0f, 1.0f}, + { 1.0f, 1.0f, 1.0f}, + { 1.0f, 1.0f, -1.0f}, /* +Y */ + {-1.0f, 1.0f, 1.0f}, + { 1.0f, 1.0f, -1.0f}, + {-1.0f, 1.0f, -1.0f}, + + { 1.0f, -1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, + {-1.0f, 1.0f, -1.0f}, /* -Z */ { 1.0f, -1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}, { 1.0f, 1.0f, -1.0f}, - {-1.0f, -1.0f, 1.0f}, + + {-1.0f, -1.0f, -1.0f}, + { 1.0f, -1.0f, -1.0f}, + { 1.0f, -1.0f, 1.0f}, /* -Y */ + {-1.0f, -1.0f, -1.0f}, { 1.0f, -1.0f, 1.0f}, + {-1.0f, -1.0f, 1.0f}, + + {-1.0f, -1.0f, -1.0f}, + {-1.0f, -1.0f, 1.0f}, + {-1.0f, 1.0f, 1.0f}, /* -X */ + {-1.0f, -1.0f, -1.0f}, {-1.0f, 1.0f, 1.0f}, - { 1.0f, 1.0f, 1.0f} + {-1.0f, 1.0f, -1.0f} +}}, {new vector{ + { 0.0f, 0.0f, 1.0f}, + { 0.0f, 0.0f, 1.0f}, + { 0.0f, 0.0f, 1.0f}, /* +Z */ + { 0.0f, 0.0f, 1.0f}, + { 0.0f, 0.0f, 1.0f}, + { 0.0f, 0.0f, 1.0f}, + + { 1.0f, 0.0f, 0.0f}, + { 1.0f, 0.0f, 0.0f}, + { 1.0f, 0.0f, 0.0f}, /* +X */ + { 1.0f, 0.0f, 0.0f}, + { 1.0f, 0.0f, 0.0f}, + { 1.0f, 0.0f, 0.0f}, + + { 0.0f, 1.0f, 0.0f}, + { 0.0f, 1.0f, 0.0f}, + { 0.0f, 1.0f, 0.0f}, /* +Y */ + { 0.0f, 1.0f, 0.0f}, + { 0.0f, 1.0f, 0.0f}, + { 0.0f, 1.0f, 0.0f}, + + { 0.0f, 0.0f, -1.0f}, + { 0.0f, 0.0f, -1.0f}, + { 0.0f, 0.0f, -1.0f}, /* -Z */ + { 0.0f, 0.0f, -1.0f}, + { 0.0f, 0.0f, -1.0f}, + { 0.0f, 0.0f, -1.0f}, + + { 0.0f, -1.0f, 0.0f}, + { 0.0f, -1.0f, 0.0f}, + { 0.0f, -1.0f, 0.0f}, /* -Y */ + { 0.0f, -1.0f, 0.0f}, + { 0.0f, -1.0f, 0.0f}, + { 0.0f, -1.0f, 0.0f}, + + {-1.0f, 0.0f, 0.0f}, + {-1.0f, 0.0f, 0.0f}, + {-1.0f, 0.0f, 0.0f}, /* -X */ + {-1.0f, 0.0f, 0.0f}, + {-1.0f, 0.0f, 0.0f}, + {-1.0f, 0.0f, 0.0f} }}, {}) { - positions(0)->assign(normals(0)->begin(), normals(0)->end()); } }} diff --git a/src/Primitives/Cube.h b/src/Primitives/Cube.h index e3ed55951..cf390389f 100644 --- a/src/Primitives/Cube.h +++ b/src/Primitives/Cube.h @@ -26,8 +26,7 @@ namespace Magnum { namespace Primitives { /** @brief 3D cube primitive -Indexed triangle mesh with smooth normals. -@todo Does anyone EVER want smooth normals on a cube?! +2x2x2 cube. Non-indexed triangle mesh with flat normals. */ class Cube: public Trade::MeshData3D { public: From 985b28cf07f7bbb3addad17ac4408f8e0f8d986f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 21 Nov 2012 19:15:20 +0100 Subject: [PATCH 02/11] Sdl2Application: fix modifiers everywhere, not only for key press. --- src/Platform/Sdl2Application.cpp | 37 ++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index 59c2080f6..6e81c4ab1 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -20,6 +20,24 @@ namespace Magnum { namespace Platform { +namespace { + +/* + * Fix up the modifiers -- we want >= operator to work properly on Shift, + * Ctrl, Alt, but SDL generates different event for left / right keys, thus + * (modifiers >= Shift) would pass only if both left and right were pressed, + * which is usually not what the developers wants. + */ +Sdl2Application::InputEvent::Modifiers fixedModifiers(Uint16 mod) { + Sdl2Application::InputEvent::Modifiers modifiers(static_cast(mod)); + if(modifiers & Sdl2Application::InputEvent::Modifier::Shift) modifiers |= Sdl2Application::InputEvent::Modifier::Shift; + if(modifiers & Sdl2Application::InputEvent::Modifier::Ctrl) modifiers |= Sdl2Application::InputEvent::Modifier::Ctrl; + if(modifiers & Sdl2Application::InputEvent::Modifier::Alt) modifiers |= Sdl2Application::InputEvent::Modifier::Alt; + return modifiers; +} + +} + Sdl2Application::Sdl2Application(int, char**, const std::string& name, const Math::Vector2& size): _redraw(true) { if(SDL_Init(SDL_INIT_VIDEO) < 0) { Error() << "Cannot initialize SDL."; @@ -85,20 +103,7 @@ int Sdl2Application::exec() { case SDL_KEYDOWN: case SDL_KEYUP: { - /* - * Fix up the modifiers -- we want >= operator to work - * properly on Shift, Ctrl, Alt, but SDL generates - * different event for left / right keys, thus - * (modifiers >= Shift) would pass only if both left and - * right were pressed, which is usually not what the - * developers wants. - */ - InputEvent::Modifiers modifiers(static_cast(event.key.keysym.mod)); - if(modifiers & InputEvent::Modifier::Shift) modifiers |= InputEvent::Modifier::Shift; - if(modifiers & InputEvent::Modifier::Ctrl) modifiers |= InputEvent::Modifier::Ctrl; - if(modifiers & InputEvent::Modifier::Alt) modifiers |= InputEvent::Modifier::Alt; - - KeyEvent e(static_cast(event.key.keysym.sym), modifiers); + KeyEvent e(static_cast(event.key.keysym.sym), fixedModifiers(event.key.keysym.mod)); event.type == SDL_KEYDOWN ? keyPressEvent(e) : keyReleaseEvent(e); break; } @@ -143,13 +148,13 @@ void Sdl2Application::setMouseLocked(bool enabled) { Sdl2Application::InputEvent::Modifiers Sdl2Application::MouseEvent::modifiers() { if(modifiersLoaded) return _modifiers; modifiersLoaded = true; - return _modifiers = static_cast(SDL_GetModState()); + return _modifiers = fixedModifiers(SDL_GetModState()); } Sdl2Application::InputEvent::Modifiers Sdl2Application::MouseMoveEvent::modifiers() { if(modifiersLoaded) return _modifiers; modifiersLoaded = true; - return _modifiers = static_cast(SDL_GetModState()); + return _modifiers = fixedModifiers(SDL_GetModState()); } }} From 757ca13514411b2af63585b05702e0f2bb5e39f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 21 Nov 2012 19:28:43 +0100 Subject: [PATCH 03/11] Sdl2Application: don't request specific OpenGL version. I don't want to ditch old Intels with GL 2.1 yet. Also now the version reported in Context is really the highest supported version, which optimizes extension presence checks a bit. --- src/Platform/Sdl2Application.cpp | 4 ---- src/Platform/Sdl2Application.h | 8 +++----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index 6e81c4ab1..165cbcfe8 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -44,10 +44,6 @@ Sdl2Application::Sdl2Application(int, char**, const std::string& name, const Mat exit(1); } - /* Request OpenGL 3.2 */ - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); - /* Enable double buffering and 24bt depth buffer */ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index 6118890b9..ab3eb217d 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -37,8 +37,9 @@ namespace Platform { /** @nosubgrouping @brief SDL2 application -Application using [Simple DirectMedia Layer](www.libsdl.org/). Supports -keyboard and mouse handling. +Application using [Simple DirectMedia Layer](www.libsdl.org/). Centered +non-resizable window with double-buffered OpenGL context and 24bit depth +buffer. Supports keyboard and mouse handling. @section Sdl2Application-usage Usage @@ -65,9 +66,6 @@ class Sdl2Application { * @param argv Arguments of `main()` function * @param title Window title * @param size Window size - * - * Creates centered non-resizable window with double-buffered - * OpenGL 3.2 context with 24bit depth buffer. */ Sdl2Application(int argc, char** argv, const std::string& title = "Magnum SDL2 application", const Math::Vector2& size = Math::Vector2(800, 600)); From 04c8f2136090a0cf65e773de0ae0696783a2c557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 21 Nov 2012 21:11:23 +0100 Subject: [PATCH 04/11] Fixed serious issue with Context::is*Supported(). Some extensions are not part of any core OpenGL version (such as EXT_direct_state_access, EXT_texture_filter_anisotropic etc.), thus they have None for core version. Current mechanism in Context::isExtensionSupported() is that it checks for core version first and if that is supported, it doesn't check for the extension itself. Until now Context::isVersionSupported(None) returned always true, which meant that all non-core extensions were marked as supported _everywhere_. --- src/Context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Context.h b/src/Context.h index d74630b15..b34db7072 100644 --- a/src/Context.h +++ b/src/Context.h @@ -36,7 +36,7 @@ namespace Implementation { /** @brief OpenGL version */ enum class Version: GLint { - None = 0, /**< @brief Unspecified */ + None = 0xFFFF, /**< @brief Unspecified */ #ifndef MAGNUM_TARGET_GLES GL210 = 210, /**< @brief OpenGL 2.1 / GLSL 1.20 */ GL300 = 300, /**< @brief OpenGL 3.0 / GLSL 1.30 */ From 99ac6ff8125b79b3388c91aaca6d473b9b7bf307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 21 Nov 2012 21:26:01 +0100 Subject: [PATCH 05/11] Added missing extensions into Context.cpp. --- src/Context.cpp | 5 ++++- src/Extensions.h | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Context.cpp b/src/Context.cpp index 2b2eddd68..48cf17e56 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -38,7 +38,10 @@ const std::vector& Extension::extensions(Version version) { static const std::vector empty; #ifndef MAGNUM_TARGET_GLES static const std::vector extensions{ - _extension(GL,EXT,texture_filter_anisotropic)}; + _extension(GL,AMD,vertex_shader_layer), + _extension(GL,AMD,shader_trinary_minmax), + _extension(GL,EXT,texture_filter_anisotropic), + _extension(GL,EXT,direct_state_access)}; static const std::vector extensions300{ _extension(GL,APPLE,flush_buffer_range), _extension(GL,APPLE,vertex_array_object), diff --git a/src/Extensions.h b/src/Extensions.h index 472b45a91..7551d8946 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -48,6 +48,9 @@ namespace Extensions { constexpr static Version coreVersion() { return Version::_coreVersion; } \ constexpr static const char* string() { return #prefix "_" #vendor "_" #extension; } \ }; + +/* IMPORTANT: don't forget to add new extensions also in Context.cpp */ + namespace GL { #line 1 namespace AMD { From def1d7b3c6853eb9cf6bdcdde71a754528a22fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 22 Nov 2012 00:21:03 +0100 Subject: [PATCH 06/11] Class for putting marks into OpenGL command stream for use in debuggers. --- src/CMakeLists.txt | 2 ++ src/Context.cpp | 5 +++- src/DebugMarker.cpp | 48 ++++++++++++++++++++++++++++++++++++ src/DebugMarker.h | 60 +++++++++++++++++++++++++++++++++++++++++++++ src/Extensions.h | 2 ++ 5 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 src/DebugMarker.cpp create mode 100644 src/DebugMarker.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d073f76f1..3ac3038d5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,6 +16,7 @@ set(Magnum_SRCS AbstractShaderProgram.cpp Buffer.cpp Context.cpp + DebugMarker.cpp Framebuffer.cpp Image.cpp IndexedMesh.cpp @@ -55,6 +56,7 @@ set(Magnum_HEADERS Color.h Context.h CubeMapTexture.h + DebugMarker.h DimensionTraits.h Extensions.h Framebuffer.h diff --git a/src/Context.cpp b/src/Context.cpp index 48cf17e56..df6b751af 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -27,6 +27,7 @@ #include "IndexedMesh.h" #include "Mesh.h" #include "Implementation/State.h" +#include "DebugMarker.h" using namespace std; @@ -41,7 +42,8 @@ const std::vector& Extension::extensions(Version version) { _extension(GL,AMD,vertex_shader_layer), _extension(GL,AMD,shader_trinary_minmax), _extension(GL,EXT,texture_filter_anisotropic), - _extension(GL,EXT,direct_state_access)}; + _extension(GL,EXT,direct_state_access), + _extension(GL,GREMEDY,string_marker)}; static const std::vector extensions300{ _extension(GL,APPLE,flush_buffer_range), _extension(GL,APPLE,vertex_array_object), @@ -249,6 +251,7 @@ Context::Context() { #ifndef MAGNUM_TARGET_GLES BufferedTexture::initializeContextBasedFunctionality(this); #endif + DebugMarker::initializeContextBasedFunctionality(this); IndexedMesh::initializeContextBasedFunctionality(this); Mesh::initializeContextBasedFunctionality(this); } diff --git a/src/DebugMarker.cpp b/src/DebugMarker.cpp new file mode 100644 index 000000000..490128344 --- /dev/null +++ b/src/DebugMarker.cpp @@ -0,0 +1,48 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "DebugMarker.h" + +#include + +#include "Context.h" +#include "Extensions.h" + +namespace Magnum { + +DebugMarker::MarkImplementation DebugMarker::markImplementation = &DebugMarker::markImplementationDefault; + +void DebugMarker::initializeContextBasedFunctionality(Context* context) { + if(context->isExtensionSupported()) { + Debug() << "DebugMarker: using" << Extensions::GL::GREMEDY::string_marker::string() << "features"; + + markImplementation = &DebugMarker::markImplementationDebugger; + } +} + +void DebugMarker::markImplementationDefault(const std::string&) {} + +void DebugMarker::markImplementationDebugger(const std::string& string) { + /** @todo Re-enable when extension wrangler is available for ES */ + #ifndef MAGNUM_TARGET_GLES + glStringMarkerGREMEDY(string.length(), string.c_str()); + #else + #if 0 + glInsertEventMarkerEXT(string.length(), string.c_str()); + #endif + #endif +} + +} diff --git a/src/DebugMarker.h b/src/DebugMarker.h new file mode 100644 index 000000000..942c38dad --- /dev/null +++ b/src/DebugMarker.h @@ -0,0 +1,60 @@ +#ifndef Magnum_DebugMarker_h +#define Magnum_DebugMarker_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::DebugMarker + */ + +#include + +#include "Magnum.h" + +#include "magnumVisibility.h" + +namespace Magnum { + +/** +@brief Debug marker + +Allows putting debug marker into OpenGL command stream for use with various +debuggers, such as ApiTrace or gDEBugger. +@requires_extension %Extension @extension{GREMEDY,string_marker}. If not + available, this class does nothing. +@requires_es_extension %Extension @es_extension{EXT,debug_marker}. If not + available, this class does nothing. +*/ +class MAGNUM_EXPORT DebugMarker { + friend class Context; + + public: + /** @brief Put string mark into OpenGL command stream */ + inline static void mark(const std::string& string) { + markImplementation(string); + } + + private: + static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); + + typedef void(*MarkImplementation)(const std::string&); + static MAGNUM_LOCAL void markImplementationDefault(const std::string& string); + static MAGNUM_LOCAL void markImplementationDebugger(const std::string& string); + static MarkImplementation markImplementation; +}; + +} + +#endif diff --git a/src/Extensions.h b/src/Extensions.h index 7551d8946..6d3fb27a6 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -136,6 +136,8 @@ namespace GL { _extension(GL,EXT,transform_feedback, GL210, GL300) // #352 _extension(GL,EXT,direct_state_access, GL210, None) // #353 _extension(GL,EXT,texture_snorm, GL300, GL310) // #365 + } namespace GREMEDY { + _extension(GL,GREMEDY,string_marker, GL210, None) // #311 } namespace INTEL { /* INTEL_map_texture not supported */ // #429 } namespace NV { From 642ab3b74dc14f86b4d1d27ea1a7e22528488bc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 22 Nov 2012 00:30:35 +0100 Subject: [PATCH 07/11] WTF? --- src/Shaders/VertexColorShader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shaders/VertexColorShader.h b/src/Shaders/VertexColorShader.h index 4fa87b65d..1c68a147a 100644 --- a/src/Shaders/VertexColorShader.h +++ b/src/Shaders/VertexColorShader.h @@ -41,7 +41,7 @@ template class SHADERS_EXPORT VertexColorShader: public typedef Attribute<0, typename DimensionTraits::PointType> Position; /** @brief Vertex color */ - typedef Attribute<1, Math::Point2D> Color; + typedef Attribute<1, Color3> Color; VertexColorShader(); From d2f0a2a045727abdbec63d65e2487ed4686f5bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 22 Nov 2012 00:45:03 +0100 Subject: [PATCH 08/11] Using default template arguments instead of GLfloat everywhere. It was mainly in DimensionTraits usage. Also using DimensionTraits::*Type for private members of physics shapes instead of manually specified superclasses. The header is still included because of all the inline accessors, so why not use the same type inside the class. --- src/Physics/AbstractShape.h | 2 +- src/Physics/AxisAlignedBox.cpp | 4 ++-- src/Physics/AxisAlignedBox.h | 18 +++++++++--------- src/Physics/Box.cpp | 2 +- src/Physics/Box.h | 12 ++++++------ src/Physics/Capsule.cpp | 8 ++++---- src/Physics/Capsule.h | 18 +++++++++--------- .../Implementation/AbstractDebugRenderer.h | 2 +- .../Implementation/AbstractShapeRenderer.h | 2 +- .../Implementation/AxisAlignedBoxRenderer.cpp | 2 +- src/Physics/Implementation/BoxRenderer.cpp | 2 +- src/Physics/Implementation/BoxRenderer.h | 2 +- src/Physics/Implementation/DebugRenderer.h | 2 +- src/Physics/Line.cpp | 6 +++--- src/Physics/Line.h | 18 +++++++++--------- src/Physics/LineSegment.h | 2 +- src/Physics/ObjectShape.cpp | 2 +- src/Physics/Plane.h | 2 +- src/Physics/Point.cpp | 4 ++-- src/Physics/Point.h | 12 ++++++------ src/Physics/ShapeGroup.cpp | 2 +- src/Physics/ShapeGroup.h | 2 +- src/Physics/Sphere.cpp | 6 +++--- src/Physics/Sphere.h | 12 ++++++------ src/SceneGraph/Test/ObjectTest.cpp | 16 ++++++++-------- src/Shaders/FlatShader.h | 4 ++-- src/Shaders/VertexColorShader.h | 4 ++-- 27 files changed, 84 insertions(+), 84 deletions(-) diff --git a/src/Physics/AbstractShape.h b/src/Physics/AbstractShape.h index a8320aa0d..c4e6dff67 100644 --- a/src/Physics/AbstractShape.h +++ b/src/Physics/AbstractShape.h @@ -105,7 +105,7 @@ template class PHYSICS_EXPORT AbstractShape { * Applies transformation to user-defined shape properties and caches * them for later usage in collision detection. */ - virtual void applyTransformation(const typename DimensionTraits::MatrixType& transformation) = 0; + virtual void applyTransformation(const typename DimensionTraits::MatrixType& transformation) = 0; /** * @brief Detect collision with other shape diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index 63b288fcc..8b15efa27 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -20,8 +20,8 @@ namespace Magnum { namespace Physics { -template void AxisAlignedBox::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { - _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); +template void AxisAlignedBox::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { + _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); _transformedSize = transformation.rotationScaling()*_size; } diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index 711491575..2c00e8f35 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -34,44 +34,44 @@ namespace Magnum { namespace Physics { template class PHYSICS_EXPORT AxisAlignedBox: public AbstractShape { public: /** @brief Constructor */ - inline AxisAlignedBox(const typename DimensionTraits::VectorType& position, const typename DimensionTraits::VectorType& size): _position(position), _transformedPosition(position), _size(size), _transformedSize(size) {} + inline AxisAlignedBox(const typename DimensionTraits::VectorType& position, const typename DimensionTraits::VectorType& size): _position(position), _transformedPosition(position), _size(size), _transformedSize(size) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::AxisAlignedBox; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; /** @brief Position */ - inline typename DimensionTraits::VectorType position() const { + inline typename DimensionTraits::VectorType position() const { return _position; } /** @brief Set position */ - inline void setPosition(const typename DimensionTraits::VectorType& position) { + inline void setPosition(const typename DimensionTraits::VectorType& position) { _position = position; } /** @brief Size */ - inline typename DimensionTraits::VectorType size() const { return _size; } + inline typename DimensionTraits::VectorType size() const { return _size; } /** @brief Set size */ - inline void setSize(const typename DimensionTraits::VectorType& size) { + inline void setSize(const typename DimensionTraits::VectorType& size) { _size = size; } /** @brief Transformed position */ - inline typename DimensionTraits::VectorType transformedPosition() const { + inline typename DimensionTraits::VectorType transformedPosition() const { return _transformedPosition; } /** @brief Transformed size */ - inline typename DimensionTraits::VectorType transformedSize() const { + inline typename DimensionTraits::VectorType transformedSize() const { return _transformedSize; } private: - Math::Vector _position, _transformedPosition, + typename DimensionTraits::VectorType _position, _transformedPosition, _size, _transformedSize; }; diff --git a/src/Physics/Box.cpp b/src/Physics/Box.cpp index 2b0eb5725..e1ed39501 100644 --- a/src/Physics/Box.cpp +++ b/src/Physics/Box.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Physics { -template void Box::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { +template void Box::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformedTransformation = (transformation*_transformation); } diff --git a/src/Physics/Box.h b/src/Physics/Box.h index 81959172e..87f259a12 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -36,31 +36,31 @@ namespace Magnum { namespace Physics { template class PHYSICS_EXPORT Box: public AbstractShape { public: /** @brief Constructor */ - inline Box(const typename DimensionTraits::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {} + inline Box(const typename DimensionTraits::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Box; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; /** @brief Transformation */ - inline typename DimensionTraits::MatrixType transformation() const { + inline typename DimensionTraits::MatrixType transformation() const { return _transformation; } /** @brief Set transformation */ - inline void setTransformation(const typename DimensionTraits::MatrixType& transformation) { + inline void setTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformation = transformation; } /** @brief Transformed transformation */ - inline typename DimensionTraits::MatrixType transformedTransformation() const { + inline typename DimensionTraits::MatrixType transformedTransformation() const { return _transformedTransformation; } private: - Math::Matrix _transformation, + typename DimensionTraits::MatrixType _transformation, _transformedTransformation; }; diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index 0c9c1b288..0c9a8882e 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -27,10 +27,10 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { -template void Capsule::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { - _transformedA = (transformation*typename DimensionTraits::PointType(_a)).vector(); - _transformedB = (transformation*typename DimensionTraits::PointType(_b)).vector(); - float scaling = (transformation.rotationScaling()*typename DimensionTraits::VectorType(1/Math::Constants::sqrt3())).length(); +template void Capsule::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { + _transformedA = (transformation*typename DimensionTraits::PointType(_a)).vector(); + _transformedB = (transformation*typename DimensionTraits::PointType(_b)).vector(); + float scaling = (transformation.rotationScaling()*typename DimensionTraits::VectorType(1/Math::Constants::sqrt3())).length(); _transformedRadius = scaling*_radius; } diff --git a/src/Physics/Capsule.h b/src/Physics/Capsule.h index af8a19a36..3c5aad2d6 100644 --- a/src/Physics/Capsule.h +++ b/src/Physics/Capsule.h @@ -37,33 +37,33 @@ applying transformation, the scale factor is averaged from all axes. template class PHYSICS_EXPORT Capsule: public AbstractShape { public: /** @brief Constructor */ - inline Capsule(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} + inline Capsule(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Capsule; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; bool collides(const AbstractShape* other) const override; /** @brief Start point */ - inline typename DimensionTraits::VectorType a() const { + inline typename DimensionTraits::VectorType a() const { return _a; } /** @brief End point */ - inline typename DimensionTraits::VectorType b() const { + inline typename DimensionTraits::VectorType b() const { return _a; } /** @brief Set start point */ - inline void setA(const typename DimensionTraits::VectorType& a) { + inline void setA(const typename DimensionTraits::VectorType& a) { _a = a; } /** @brief Set end point */ - inline void setB(const typename DimensionTraits::VectorType& b) { + inline void setB(const typename DimensionTraits::VectorType& b) { _b = b; } @@ -74,12 +74,12 @@ template class PHYSICS_EXPORT Capsule: public AbstractS inline void setRadius(float radius) { _radius = radius; } /** @brief Transformed first point */ - inline typename DimensionTraits::VectorType transformedA() const { + inline typename DimensionTraits::VectorType transformedA() const { return _transformedA; } /** @brief Transformed second point */ - inline typename DimensionTraits::VectorType transformedB() const { + inline typename DimensionTraits::VectorType transformedB() const { return _transformedB; } @@ -95,7 +95,7 @@ template class PHYSICS_EXPORT Capsule: public AbstractS bool operator%(const Sphere& other) const; private: - Math::Vector _a, _transformedA, + typename DimensionTraits::VectorType _a, _transformedA, _b, _transformedB; float _radius, _transformedRadius; }; diff --git a/src/Physics/Implementation/AbstractDebugRenderer.h b/src/Physics/Implementation/AbstractDebugRenderer.h index 0b3af89c2..3d699899b 100644 --- a/src/Physics/Implementation/AbstractDebugRenderer.h +++ b/src/Physics/Implementation/AbstractDebugRenderer.h @@ -38,7 +38,7 @@ template class AbstractDebugRenderer { virtual ~AbstractDebugRenderer(); - virtual void draw(Resource& options, const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) = 0; + virtual void draw(Resource& options, const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) = 0; protected: Resource> shader; diff --git a/src/Physics/Implementation/AbstractShapeRenderer.h b/src/Physics/Implementation/AbstractShapeRenderer.h index 276d53ba2..737e29895 100644 --- a/src/Physics/Implementation/AbstractShapeRenderer.h +++ b/src/Physics/Implementation/AbstractShapeRenderer.h @@ -38,7 +38,7 @@ template class AbstractShapeRenderer { virtual ~AbstractShapeRenderer(); - virtual void draw(Resource& options, const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) = 0; + virtual void draw(Resource& options, const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) = 0; protected: Resource> shader; diff --git a/src/Physics/Implementation/AxisAlignedBoxRenderer.cpp b/src/Physics/Implementation/AxisAlignedBoxRenderer.cpp index 57e701116..d53732742 100644 --- a/src/Physics/Implementation/AxisAlignedBoxRenderer.cpp +++ b/src/Physics/Implementation/AxisAlignedBoxRenderer.cpp @@ -22,7 +22,7 @@ namespace Magnum { namespace Physics { namespace Implementation { -template void AxisAlignedBoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractCamera* camera) { +template void AxisAlignedBoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractCamera* camera) { typename DimensionTraits::MatrixType transformation = DimensionTraits::MatrixType::translation(axisAlignedBox.transformedPosition())* DimensionTraits::MatrixType::scaling(axisAlignedBox.transformedSize()); diff --git a/src/Physics/Implementation/BoxRenderer.cpp b/src/Physics/Implementation/BoxRenderer.cpp index 1624e7aa3..ea4531324 100644 --- a/src/Physics/Implementation/BoxRenderer.cpp +++ b/src/Physics/Implementation/BoxRenderer.cpp @@ -22,7 +22,7 @@ namespace Magnum { namespace Physics { namespace Implementation { -template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractCamera* camera) { +template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractCamera* camera) { this->shader->setTransformationProjection(camera->projectionMatrix()*camera->cameraMatrix()*box.transformedTransformation()) ->setColor(options->color) ->use(); diff --git a/src/Physics/Implementation/BoxRenderer.h b/src/Physics/Implementation/BoxRenderer.h index c1e248478..4513155c1 100644 --- a/src/Physics/Implementation/BoxRenderer.h +++ b/src/Physics/Implementation/BoxRenderer.h @@ -27,7 +27,7 @@ template class BoxRenderer: public AbstractBoxRenderer< public: inline BoxRenderer(Box& box): box(box) {} - void draw(Resource& options, const typename DimensionTraits::MatrixType& transformation, typename SceneGraph::AbstractCamera* camera) override; + void draw(Resource& options, const typename DimensionTraits::MatrixType& transformation, typename SceneGraph::AbstractCamera* camera) override; private: Box& box; diff --git a/src/Physics/Implementation/DebugRenderer.h b/src/Physics/Implementation/DebugRenderer.h index fdb19e268..87e806392 100644 --- a/src/Physics/Implementation/DebugRenderer.h +++ b/src/Physics/Implementation/DebugRenderer.h @@ -44,7 +44,7 @@ template class DebugRenderer: public SceneGraph::Drawab renderers.push_back(renderer); } - inline void draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) override { + inline void draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) override { for(auto i: renderers) i->draw(options, transformationMatrix, camera); } diff --git a/src/Physics/Line.cpp b/src/Physics/Line.cpp index c067306c0..65533e3ef 100644 --- a/src/Physics/Line.cpp +++ b/src/Physics/Line.cpp @@ -20,9 +20,9 @@ namespace Magnum { namespace Physics { -template void Line::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { - _transformedA = (transformation*typename DimensionTraits::PointType(_a)).vector(); - _transformedB = (transformation*typename DimensionTraits::PointType(_b)).vector(); +template void Line::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { + _transformedA = (transformation*typename DimensionTraits::PointType(_a)).vector(); + _transformedB = (transformation*typename DimensionTraits::PointType(_b)).vector(); } /* Explicitly instantiate the templates */ diff --git a/src/Physics/Line.h b/src/Physics/Line.h index 39cb70363..df509d87d 100644 --- a/src/Physics/Line.h +++ b/src/Physics/Line.h @@ -35,46 +35,46 @@ namespace Magnum { namespace Physics { template class PHYSICS_EXPORT Line: public AbstractShape { public: /** @brief Constructor */ - inline Line(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {} + inline Line(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Line; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; /** @brief First point */ - inline typename DimensionTraits::VectorType a() const { + inline typename DimensionTraits::VectorType a() const { return _a; } /** @brief Second point */ - inline typename DimensionTraits::VectorType b() const { + inline typename DimensionTraits::VectorType b() const { return _a; } /** @brief Set first point */ - inline void setA(const typename DimensionTraits::VectorType& a) { + inline void setA(const typename DimensionTraits::VectorType& a) { _a = a; } /** @brief Set second point */ - inline void setB(const typename DimensionTraits::VectorType& b) { + inline void setB(const typename DimensionTraits::VectorType& b) { _b = b; } /** @brief Transformed first point */ - inline typename DimensionTraits::VectorType transformedA() const { + inline typename DimensionTraits::VectorType transformedA() const { return _transformedA; } /** @brief Transformed second point */ - inline typename DimensionTraits::VectorType transformedB() const { + inline typename DimensionTraits::VectorType transformedB() const { return _transformedB; } private: - Math::Vector _a, _transformedA, + typename DimensionTraits::VectorType _a, _transformedA, _b, _transformedB; }; diff --git a/src/Physics/LineSegment.h b/src/Physics/LineSegment.h index 8c0d00242..4ed4b9449 100644 --- a/src/Physics/LineSegment.h +++ b/src/Physics/LineSegment.h @@ -31,7 +31,7 @@ namespace Magnum { namespace Physics { template class LineSegment: public Line { public: /** @brief Constructor */ - inline LineSegment(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): Line(a, b) {} + inline LineSegment(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): Line(a, b) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::LineSegment; diff --git a/src/Physics/ObjectShape.cpp b/src/Physics/ObjectShape.cpp index 4ce8e4ce7..446433d5a 100644 --- a/src/Physics/ObjectShape.cpp +++ b/src/Physics/ObjectShape.cpp @@ -36,7 +36,7 @@ template void ObjectShape::markDirty() { group()->setDirty(); } -template void ObjectShape::clean(const typename DimensionTraits::MatrixType& absoluteTransformation) { +template void ObjectShape::clean(const typename DimensionTraits::MatrixType& absoluteTransformation) { if(_shape) _shape->applyTransformation(absoluteTransformation); } diff --git a/src/Physics/Plane.h b/src/Physics/Plane.h index 2397aa2e2..253e41484 100644 --- a/src/Physics/Plane.h +++ b/src/Physics/Plane.h @@ -39,7 +39,7 @@ class PHYSICS_EXPORT Plane: public AbstractShape<3> { void applyTransformation(const Matrix4& transformation) override; bool collides(const AbstractShape<3>* other) const override; #else - void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; bool collides(const AbstractShape* other) const override; #endif diff --git a/src/Physics/Point.cpp b/src/Physics/Point.cpp index 6ca6df6f4..06850fd68 100644 --- a/src/Physics/Point.cpp +++ b/src/Physics/Point.cpp @@ -20,8 +20,8 @@ namespace Magnum { namespace Physics { -template void Point::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { - _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); +template void Point::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { + _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); } template class Point<2>; diff --git a/src/Physics/Point.h b/src/Physics/Point.h index 142b315e0..a228173f9 100644 --- a/src/Physics/Point.h +++ b/src/Physics/Point.h @@ -34,31 +34,31 @@ namespace Magnum { namespace Physics { template class PHYSICS_EXPORT Point: public AbstractShape { public: /** @brief Constructor */ - inline Point(const typename DimensionTraits::VectorType& position): _position(position), _transformedPosition(position) {} + inline Point(const typename DimensionTraits::VectorType& position): _position(position), _transformedPosition(position) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Point; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; /** @brief Position */ - inline typename DimensionTraits::VectorType position() const { + inline typename DimensionTraits::VectorType position() const { return _position; } /** @brief Set position */ - inline void setPosition(const typename DimensionTraits::VectorType& position) { + inline void setPosition(const typename DimensionTraits::VectorType& position) { _position = position; } /** @brief Transformed position */ - inline typename DimensionTraits::VectorType transformedPosition() const { + inline typename DimensionTraits::VectorType transformedPosition() const { return _transformedPosition; } private: - Math::Vector _position, _transformedPosition; + typename DimensionTraits::VectorType _position, _transformedPosition; }; /** @brief Two-dimensional point */ diff --git a/src/Physics/ShapeGroup.cpp b/src/Physics/ShapeGroup.cpp index 83a5f7178..3352a2664 100644 --- a/src/Physics/ShapeGroup.cpp +++ b/src/Physics/ShapeGroup.cpp @@ -43,7 +43,7 @@ template ShapeGroup& ShapeGroup return *this; } -template void ShapeGroup::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { +template void ShapeGroup::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { if(a) a->applyTransformation(transformation); if(b) b->applyTransformation(transformation); } diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index 8a3533e84..04992413d 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -105,7 +105,7 @@ template class PHYSICS_EXPORT ShapeGroup: public Abstra return AbstractShape::Type::ShapeGroup; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; bool collides(const AbstractShape* other) const override; diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index b0f578871..91caac41d 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -28,7 +28,7 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { namespace { - template static typename DimensionTraits::VectorType unitVector(); + template static typename DimensionTraits::VectorType unitVector(); template<> inline Vector2 unitVector<2>() { return Vector2(1/Math::Constants::sqrt2()); @@ -39,8 +39,8 @@ namespace { } } -template void Sphere::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { - _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); +template void Sphere::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { + _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); float scaling = (transformation.rotationScaling()*unitVector()).length(); _transformedRadius = scaling*_radius; } diff --git a/src/Physics/Sphere.h b/src/Physics/Sphere.h index 1fd8cc378..f77cf8415 100644 --- a/src/Physics/Sphere.h +++ b/src/Physics/Sphere.h @@ -37,23 +37,23 @@ applying transformation, the scale factor is averaged from all axes. template class PHYSICS_EXPORT Sphere: public AbstractShape { public: /** @brief Constructor */ - inline Sphere(const typename DimensionTraits::VectorType& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} + inline Sphere(const typename DimensionTraits::VectorType& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Sphere; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; bool collides(const AbstractShape* other) const override; /** @brief Position */ - inline typename DimensionTraits::VectorType position() const { + inline typename DimensionTraits::VectorType position() const { return _position; } /** @brief Set position */ - inline void setPosition(const typename DimensionTraits::VectorType& position) { + inline void setPosition(const typename DimensionTraits::VectorType& position) { _position = position; } @@ -64,7 +64,7 @@ template class PHYSICS_EXPORT Sphere: public AbstractSh inline void setRadius(float radius) { _radius = radius; } /** @brief Transformed position */ - inline typename DimensionTraits::VectorType transformedPosition() const { + inline typename DimensionTraits::VectorType transformedPosition() const { return _transformedPosition; } @@ -86,7 +86,7 @@ template class PHYSICS_EXPORT Sphere: public AbstractSh bool operator%(const Sphere& other) const; private: - Math::Vector _position, + typename DimensionTraits::VectorType _position, _transformedPosition; float _radius, _transformedRadius; }; diff --git a/src/SceneGraph/Test/ObjectTest.cpp b/src/SceneGraph/Test/ObjectTest.cpp index 376f859b3..abe60f4c7 100644 --- a/src/SceneGraph/Test/ObjectTest.cpp +++ b/src/SceneGraph/Test/ObjectTest.cpp @@ -27,12 +27,12 @@ CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::ObjectTest) namespace Magnum { namespace SceneGraph { namespace Test { -typedef SceneGraph::Object> Object3D; -typedef SceneGraph::Scene> Scene3D; +typedef SceneGraph::Object> Object3D; +typedef SceneGraph::Scene> Scene3D; -class CachingObject: public Object3D, AbstractFeature<3, GLfloat> { +class CachingObject: public Object3D, AbstractFeature<3> { public: - inline CachingObject(Object3D* parent = nullptr): Object3D(parent), AbstractFeature<3, GLfloat>(this) { + inline CachingObject(Object3D* parent = nullptr): Object3D(parent), AbstractFeature<3>(this) { setCachedTransformations(CachedTransformation::Absolute); } @@ -189,9 +189,9 @@ void ObjectTest::transformations() { void ObjectTest::setClean() { Scene3D scene; - class CachingFeature: public AbstractFeature<3, GLfloat> { + class CachingFeature: public AbstractFeature<3> { public: - CachingFeature(AbstractObject<3, GLfloat>* object): AbstractFeature<3, GLfloat>(object) { + CachingFeature(AbstractObject<3>* object): AbstractFeature<3>(object) { setCachedTransformations(CachedTransformation::Absolute); } @@ -202,9 +202,9 @@ void ObjectTest::setClean() { } }; - class CachingInvertedFeature: public AbstractFeature<3, GLfloat> { + class CachingInvertedFeature: public AbstractFeature<3> { public: - CachingInvertedFeature(AbstractObject<3, GLfloat>* object): AbstractFeature<3, GLfloat>(object) { + CachingInvertedFeature(AbstractObject<3>* object): AbstractFeature<3>(object) { setCachedTransformations(CachedTransformation::InvertedAbsolute); } diff --git a/src/Shaders/FlatShader.h b/src/Shaders/FlatShader.h index bbdca99e5..af839d760 100644 --- a/src/Shaders/FlatShader.h +++ b/src/Shaders/FlatShader.h @@ -38,7 +38,7 @@ Draws whole mesh with one color. template class SHADERS_EXPORT FlatShader: public AbstractShaderProgram { public: /** @brief Vertex position */ - typedef Attribute<0, typename DimensionTraits::PointType> Position; + typedef Attribute<0, typename DimensionTraits::PointType> Position; FlatShader(); @@ -46,7 +46,7 @@ template class SHADERS_EXPORT FlatShader: public Abstra * @brief Set transformation and projection matrix * @return Pointer to self (for method chaining) */ - FlatShader* setTransformationProjection(const typename DimensionTraits::MatrixType& matrix) { + FlatShader* setTransformationProjection(const typename DimensionTraits::MatrixType& matrix) { setUniform(transformationProjectionUniform, matrix); return this; } diff --git a/src/Shaders/VertexColorShader.h b/src/Shaders/VertexColorShader.h index 1c68a147a..437e1a7ed 100644 --- a/src/Shaders/VertexColorShader.h +++ b/src/Shaders/VertexColorShader.h @@ -38,7 +38,7 @@ Draws vertex-colored mesh. template class SHADERS_EXPORT VertexColorShader: public AbstractShaderProgram { public: /** @brief Vertex position */ - typedef Attribute<0, typename DimensionTraits::PointType> Position; + typedef Attribute<0, typename DimensionTraits::PointType> Position; /** @brief Vertex color */ typedef Attribute<1, Color3> Color; @@ -49,7 +49,7 @@ template class SHADERS_EXPORT VertexColorShader: public * @brief Set transformation and projection * @return Pointer to self (for method chaining) */ - inline VertexColorShader* setTransformationProjection(const typename DimensionTraits::MatrixType& matrix) { + inline VertexColorShader* setTransformationProjection(const typename DimensionTraits::MatrixType& matrix) { setUniform(transformationProjectionUniform, matrix); return this; } From 5b707d35248efbd75ee4a3b2cd45e1a6042bbd9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 22 Nov 2012 00:53:33 +0100 Subject: [PATCH 09/11] Using GLfloat as default template parameter also in Color. --- src/AbstractTexture.h | 2 +- src/Color.h | 14 ++++++++++++-- src/CubeMapTexture.h | 2 +- src/CubeMapTextureArray.h | 2 +- src/Framebuffer.h | 4 ++-- src/Magnum.h | 4 ++-- src/Mesh.h | 2 +- src/Physics/DebugDrawResourceManager.h | 4 ++-- src/Shaders/FlatShader.h | 2 +- src/Shaders/PhongShader.h | 8 ++++---- src/Shaders/VertexColorShader.h | 2 +- src/Texture.h | 2 +- 12 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index a9942dffe..ae43129c7 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -677,7 +677,7 @@ class MAGNUM_EXPORT AbstractTexture { * with @def_gl{TEXTURE_BORDER_COLOR} * @requires_gl Texture border is not available in OpenGL ES. */ - inline AbstractTexture* setBorderColor(const Color4& color) { + inline AbstractTexture* setBorderColor(const Color4<>& color) { (this->*parameterfvImplementation)(GL_TEXTURE_BORDER_COLOR, color.data()); return this; } diff --git a/src/Color.h b/src/Color.h index 36d4ad4c8..300fa549a 100644 --- a/src/Color.h +++ b/src/Color.h @@ -145,7 +145,12 @@ range @f$ [0.0, 1.0] @f$. */ /* Not using template specialization because some internal functions are impossible to explicitly instantiate */ -template class Color3: public Math::Vector3 { +#ifndef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +class Color3: public Math::Vector3 { public: /** @brief Corresponding floating-point type for HSV computation */ typedef typename Math::MathTypeTraits::FloatingPointType FloatingPointType; @@ -291,7 +296,12 @@ See Color3 for more information. */ /* Not using template specialization because some internal functions are impossible to explicitly instantiate */ -template class Color4: public Math::Vector4 { +#ifndef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +class Color4: public Math::Vector4 { public: /** @copydoc Color3::FloatingPointType */ typedef typename Color3::FloatingPointType FloatingPointType; diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index df1d3b77f..5141f0a24 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -121,7 +121,7 @@ class CubeMapTexture: public AbstractTexture { return this; } #ifndef MAGNUM_TARGET_GLES - inline CubeMapTexture* setBorderColor(const Color4& color) { + inline CubeMapTexture* setBorderColor(const Color4<>& color) { AbstractTexture::setBorderColor(color); return this; } diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 0aa441935..fdf55ca79 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -133,7 +133,7 @@ class CubeMapTextureArray: public AbstractTexture { AbstractTexture::setMagnificationFilter(filter); return this; } - inline CubeMapTextureArray* setBorderColor(const Color4& color) { + inline CubeMapTextureArray* setBorderColor(const Color4<>& color) { AbstractTexture::setBorderColor(color); return this; } diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 6099ecea1..afe0a57f1 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -165,7 +165,7 @@ class MAGNUM_EXPORT Framebuffer { * Initial value is `{0.0f, 0.0f, 0.0f, 1.0f}`. * @see @fn_gl{ClearColor} */ - inline static void setClearColor(const Color4& color) { + inline static void setClearColor(const Color4<>& color) { glClearColor(color.r(), color.g(), color.b(), color.a()); } @@ -631,7 +631,7 @@ class MAGNUM_EXPORT Framebuffer { * @attention You have to enable blending with setFeature() first. * @see @fn_gl{BlendColor} */ - inline static void setBlendColor(const Color4& color) { + inline static void setBlendColor(const Color4<>& color) { glBlendColor(color.r(), color.g(), color.b(), color.a()); } diff --git a/src/Magnum.h b/src/Magnum.h index 56579b81e..4701864a0 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -113,8 +113,8 @@ typedef BufferedImage<3> BufferedImage3D; class BufferedTexture; #endif -template class Color3; -template class Color4; +template class Color3; +template class Color4; enum class Version: GLint; class Context; diff --git a/src/Mesh.h b/src/Mesh.h index d90687956..21930fad8 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -83,7 +83,7 @@ component ordering (e.g. directly from @ref Trade::TgaImporter "TGA file"): @code class MyShader: public AbstractShaderProgram { public: - typedef Attribute<1, Color4> Color; + typedef Attribute<1, Color4<>> Color; // ... }; diff --git a/src/Physics/DebugDrawResourceManager.h b/src/Physics/DebugDrawResourceManager.h index 041e77134..d7a2fff44 100644 --- a/src/Physics/DebugDrawResourceManager.h +++ b/src/Physics/DebugDrawResourceManager.h @@ -37,7 +37,7 @@ namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Physics { namespace Implementation { struct Options { - Color3 color; + Color3<> color; }; template class DebugRenderer; }} @@ -86,7 +86,7 @@ class PHYSICS_EXPORT DebugDrawResourceManager: public ResourceManager color; /**< @brief Color */ + Color3<> color; /**< @brief Color */ }; #else typedef Implementation::Options Options; diff --git a/src/Shaders/FlatShader.h b/src/Shaders/FlatShader.h index af839d760..68ff70231 100644 --- a/src/Shaders/FlatShader.h +++ b/src/Shaders/FlatShader.h @@ -55,7 +55,7 @@ template class SHADERS_EXPORT FlatShader: public Abstra * @brief Set color * @return Pointer to self (for method chaining) */ - FlatShader* setColor(const Color3& color) { + FlatShader* setColor(const Color3<>& color) { setUniform(colorUniform, color); return this; } diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index efccc6f88..9ec97be53 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -46,7 +46,7 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { * * If not set, default value is `(0.0f, 0.0f, 0.0f)`. */ - inline PhongShader* setAmbientColor(const Color3& color) { + inline PhongShader* setAmbientColor(const Color3<>& color) { setUniform(ambientColorUniform, color); return this; } @@ -55,7 +55,7 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { * @brief Set diffuse color * @return Pointer to self (for method chaining) */ - inline PhongShader* setDiffuseColor(const Color3& color) { + inline PhongShader* setDiffuseColor(const Color3<>& color) { setUniform(diffuseColorUniform, color); return this; } @@ -66,7 +66,7 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { * * If not set, default value is `(1.0f, 1.0f, 1.0f)`. */ - inline PhongShader* setSpecularColor(const Color3& color) { + inline PhongShader* setSpecularColor(const Color3<>& color) { setUniform(specularColorUniform, color); return this; } @@ -117,7 +117,7 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { * * If not set, default value is `(1.0f, 1.0f, 1.0f)`. */ - inline PhongShader* setLightColor(const Color3& color) { + inline PhongShader* setLightColor(const Color3<>& color) { setUniform(lightColorUniform, color); return this; } diff --git a/src/Shaders/VertexColorShader.h b/src/Shaders/VertexColorShader.h index 437e1a7ed..fbed9f38a 100644 --- a/src/Shaders/VertexColorShader.h +++ b/src/Shaders/VertexColorShader.h @@ -41,7 +41,7 @@ template class SHADERS_EXPORT VertexColorShader: public typedef Attribute<0, typename DimensionTraits::PointType> Position; /** @brief Vertex color */ - typedef Attribute<1, Color3> Color; + typedef Attribute<1, Color3<>> Color; VertexColorShader(); diff --git a/src/Texture.h b/src/Texture.h index c73550993..91cca9459 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -203,7 +203,7 @@ template class Texture: public AbstractTexture { return this; } #ifndef MAGNUM_TARGET_GLES - inline Texture* setBorderColor(const Color4& color) { + inline Texture* setBorderColor(const Color4<>& color) { AbstractTexture::setBorderColor(color); return this; } From a5e8d4535cab1faeac6ae5baa8bdfd6f9809eda5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 22 Nov 2012 01:31:00 +0100 Subject: [PATCH 10/11] Debug output operator for Version enum. --- src/Context.cpp | 24 ++++++++++++++++++++++++ src/Context.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/src/Context.cpp b/src/Context.cpp index df6b751af..8809955b5 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -33,6 +33,30 @@ using namespace std; namespace Magnum { +Debug operator<<(Debug debug, Version value) { + switch(value) { + #define _c(value) case Version::value: return debug << "Version::" #value; + _c(None) + #ifndef MAGNUM_TARGET_GLES + _c(GL210) + _c(GL300) + _c(GL310) + _c(GL320) + _c(GL330) + _c(GL400) + _c(GL410) + _c(GL420) + _c(GL430) + #else + _c(GLES200) + _c(GLES300) + #endif + #undef _c + } + + return debug << "Version::(invalid)"; +} + const std::vector& Extension::extensions(Version version) { #define _extension(prefix, vendor, extension) \ {Extensions::prefix::vendor::extension::Index, Extensions::prefix::vendor::extension::requiredVersion(), Extensions::prefix::vendor::extension::coreVersion(), Extensions::prefix::vendor::extension::string()} diff --git a/src/Context.h b/src/Context.h index b34db7072..959a3ad6a 100644 --- a/src/Context.h +++ b/src/Context.h @@ -76,6 +76,9 @@ enum class Version: GLint { #endif }; +/** @debugoperator{Magnum::Context} */ +Debug MAGNUM_EXPORT operator<<(Debug debug, Version value); + /** @brief Run-time information about OpenGL extension From ef1642aea11cfbae3de779984088fc1704348179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 22 Nov 2012 01:16:57 +0100 Subject: [PATCH 11/11] Added MAGNUM_ASSERT_{VERSION,EXTENSION}_SUPPORTED() macros. --- src/Context.cpp | 28 +++++++++--------- src/Context.h | 75 ++++++++++++++++++++++++++++++++++++++++++++---- src/Extensions.h | 2 ++ 3 files changed, 86 insertions(+), 19 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index 8809955b5..0f3f839e0 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -35,26 +35,26 @@ namespace Magnum { Debug operator<<(Debug debug, Version value) { switch(value) { - #define _c(value) case Version::value: return debug << "Version::" #value; - _c(None) + #define _c(value, string) case Version::value: return debug << string; + _c(None, "None") #ifndef MAGNUM_TARGET_GLES - _c(GL210) - _c(GL300) - _c(GL310) - _c(GL320) - _c(GL330) - _c(GL400) - _c(GL410) - _c(GL420) - _c(GL430) + _c(GL210, "OpenGL 2.1") + _c(GL300, "OpenGL 3.0") + _c(GL310, "OpenGL 3.1") + _c(GL320, "OpenGL 3.2") + _c(GL330, "OpenGL 3.3") + _c(GL400, "OpenGL 4.0") + _c(GL410, "OpenGL 4.1") + _c(GL420, "OpenGL 4.2") + _c(GL430, "OpenGL 4.3") #else - _c(GLES200) - _c(GLES300) + _c(GLES200, "OpenGL ES 2.0") + _c(GLES300, "OpenGL ES 3.0") #endif #undef _c } - return debug << "Version::(invalid)"; + return debug << "Invalid"; } const std::vector& Extension::extensions(Version version) { diff --git a/src/Context.h b/src/Context.h index 959a3ad6a..b9def93a4 100644 --- a/src/Context.h +++ b/src/Context.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Enum Version, class Magnum::Context, Magnum::Extension + * @brief Enum Version, class Magnum::Context, Magnum::Extension, macro MAGNUM_ASSERT_VERSION_SUPPORTED(), MAGNUM_ASSERT_EXTENSION_SUPPORTED() */ #include @@ -34,7 +34,11 @@ namespace Implementation { } #endif -/** @brief OpenGL version */ +/** +@brief OpenGL version + +@see Context, MAGNUM_ASSERT_VERSION_SUPPORTED() +*/ enum class Version: GLint { None = 0xFFFF, /**< @brief Unspecified */ #ifndef MAGNUM_TARGET_GLES @@ -200,7 +204,7 @@ class MAGNUM_EXPORT Context { /** * @brief Whether given OpenGL version is supported * - * @see supportedVersion() + * @see supportedVersion(), MAGNUM_ASSERT_VERSION_SUPPORTED() */ inline bool isVersionSupported(Version version) const { return _version >= version; @@ -235,7 +239,8 @@ class MAGNUM_EXPORT Context { * } * @endcode * - * @see isExtensionSupported(const Extension&) const + * @see isExtensionSupported(const Extension&) const, + * MAGNUM_ASSERT_EXTENSION_SUPPORTED() */ template inline bool isExtensionSupported() const { return isVersionSupported(T::coreVersion()) || (isVersionSupported(T::requiredVersion()) && extensionStatus[T::Index]); @@ -248,7 +253,8 @@ class MAGNUM_EXPORT Context { * hardware, but for general usage prefer isExtensionSupported() const, * as it does most operations in compile time. * - * @see supportedExtensions(), Extension::extensions() + * @see supportedExtensions(), Extension::extensions(), + * MAGNUM_ASSERT_EXTENSION_SUPPORTED() */ inline bool isExtensionSupported(const Extension& extension) const { return isVersionSupported(extension._coreVersion) || (isVersionSupported(extension._requiredVersion) && extensionStatus[extension._index]); @@ -271,6 +277,65 @@ class MAGNUM_EXPORT Context { Implementation::State* _state; }; +/** @hideinitializer +@brief Assert that given OpenGL version is supported +@param version Version + +Useful for initial checks on availability of required features. + +By default, if assertion fails, an message is printed to error output and the +application exits with value `-3`. If `CORRADE_NO_ASSERT` is defined, this +macro does nothing. Example usage: +@code +MAGNUM_ASSERT_VERSION_SUPPORTED(Version::GL330); +@endcode + +@see @ref Magnum::Context::isVersionSupported() "Context::isVersionSupported()", + MAGNUM_ASSERT_EXTENSION_SUPPORTED(), CORRADE_ASSERT(), + CORRADE_INTERNAL_ASSERT() +*/ +#ifdef CORRADE_NO_ASSERT +#define MAGNUM_ASSERT_VERSION_SUPPORTED(version) do {} while(0) +#else +#define MAGNUM_ASSERT_VERSION_SUPPORTED(version) \ + do { \ + if(!Context::current()->isVersionSupported(version)) { \ + Corrade::Utility::Error() << "Magnum: required version" << version << "is not supported"; \ + exit(-3); \ + } \ + } while(0) +#endif + +/** @hideinitializer +@brief Assert that given OpenGL extension is supported +@param extension Extension name (from @ref Magnum::Extensions "Extensions" + namespace) + +Useful for initial checks on availability of required features. + +By default, if assertion fails, an message is printed to error output and the +application exits with value `-3`. If `CORRADE_NO_ASSERT` is defined, this +macro does nothing. Example usage: +@code +MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::geometry_shader4); +@endcode + +@see @ref Magnum::Context::isExtensionSupported() "Context::isExtensionSupported()", + MAGNUM_ASSERT_VERSION_SUPPORTED(), CORRADE_ASSERT(), + CORRADE_INTERNAL_ASSERT() +*/ +#ifdef CORRADE_NO_ASSERT +#define MAGNUM_ASSERT_EXTENSION_SUPPORTED(extension) do {} while(0) +#else +#define MAGNUM_ASSERT_EXTENSION_SUPPORTED(extension) \ + do { \ + if(!Context::current()->isExtensionSupported()) { \ + Corrade::Utility::Error() << "Magnum: required extension" << extension::string() << "is not supported"; \ + exit(-3); \ + } \ + } while(0) +#endif + } #endif diff --git a/src/Extensions.h b/src/Extensions.h index 6d3fb27a6..ab1f78830 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -33,6 +33,8 @@ and string(), but these structs are better suited for compile-time decisions rather than Extension instances. See Context::isExtensionSupported() for example usage. +@see MAGNUM_ASSERT_EXTENSION_SUPPORTED() + @todo Manual indices for extensions, this has gaps @todo Unhide ES2_compatibility, ES3_compatibility on ES @todo Add ES and GL 4.3 extensions