diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a95d0d81..990245bcc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ option(WITH_EVERYTHING "Build everything (doesn't include contexts)" ON) option(WITH_MESHTOOLS "Build MeshTools library" OFF) option(WITH_PHYSICS "Build Physics library" OFF) option(WITH_PRIMITIVES "Builf Primitives library" OFF) +option(WITH_SCENEGRAPH "Build SceneGraph library" OFF) option(WITH_SHADERS "Build Shaders library" OFF) cmake_dependent_option(WITH_EGLCONTEXT "Build EglContext library" OFF "TARGET_GLES" OFF) @@ -23,6 +24,7 @@ if(WITH_EVERYTHING) set(WITH_MESHTOOLS ON) set(WITH_PHYSICS ON) set(WITH_PRIMITIVES ON) + set(WITH_SCENEGRAPH ON) set(WITH_SHADERS ON) endif() diff --git a/doc/mainpage.dox b/doc/mainpage.dox index 3e369b994..8071252ee 100644 --- a/doc/mainpage.dox +++ b/doc/mainpage.dox @@ -6,8 +6,8 @@ Features: - Easy-to-use templated @ref Math "mathematical library" for matrix/vector calculations and @ref Math::Geometry "geometry". -- Hierarchical @ref Object "scene graph" which supports transformation caching - for better performance, classes for convenient usage of +- Hierarchical @ref SceneGraph "scene graph" which supports transformation + caching for better performance, classes for convenient usage of @ref AbstractShaderProgram "shaders", @ref Buffer "buffers" and @ref AbstractTexture "textures". Access to @ref Framebuffer "framebuffer" and @ref AbstractQuery "occlusion queries". diff --git a/doc/namespaces.dox b/doc/namespaces.dox index 1905ab375..5f9427928 100644 --- a/doc/namespaces.dox +++ b/doc/namespaces.dox @@ -7,8 +7,7 @@ /** @namespace Magnum @brief Root namespace -Contains classes needed for building meshes, setting up and rendering the -scene. +Contains classes for interacting with OpenGL. */ /** @dir Contexts @@ -58,6 +57,16 @@ Tools for generating, optimizing and cleaning meshes. Basic primitives for testing purposes. */ +/** @dir SceneGraph + * @brief Namespace Magnum::SceneGraph + */ +/** +@namespace Magnum::SceneGraph +@brief %Scene graph library + +Setting up and rendering the scene. +*/ + /** @dir Shaders * @brief Namespace Magnum::Shaders */ diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 09a41585c..778b7b77d 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -18,6 +18,7 @@ # MeshTools - MeshTools library # Physics - Physics library # Primitives - Library with stock geometric primitives (static) +# SceneGraph - Scene graph library # Shaders - Library with stock shaders # EglContext - EGL context (depends on EGL and X11 libraries) # GlutContext - GLUT context (depends on GLUT library) @@ -137,6 +138,11 @@ foreach(component ${Magnum_FIND_COMPONENTS}) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Cube.h) endif() + # Scene graph library + if(${component} STREQUAL SceneGraph) + set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Scene.h) + endif() + # Shaders library if(${component} STREQUAL Shaders) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES PhongShader.h) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a3639825c..5673b8e00 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,10 +19,8 @@ set(Magnum_SRCS AbstractTexture.cpp AbstractShaderProgram.cpp BufferedTexture.cpp - Camera.cpp Framebuffer.cpp IndexedMesh.cpp - Light.cpp Mesh.cpp Query.cpp Renderbuffer.cpp @@ -39,7 +37,6 @@ set(Magnum_HEADERS BufferedImage.h BufferedTexture.h Buffer.h - Camera.h Color.h CubeMapTextureArray.h CubeMapTexture.h @@ -47,13 +44,10 @@ set(Magnum_HEADERS Image.h ImageWrapper.h IndexedMesh.h - Light.h Magnum.h Mesh.h - Object.h Query.h Renderbuffer.h - Scene.h Shader.h SizeTraits.h Swizzle.h @@ -68,10 +62,6 @@ set(MagnumMath_SRCS Math/Math.cpp) add_library(MagnumMathObjects OBJECT ${MagnumMath_SRCS}) -# Files compiled with different flags for main library and unit test library -set(Magnum_GracefulAssert_SRCS - Object.cpp) - # Set shared library flags for the objects, as they will be part of shared lib # TODO: fix when CMake sets target_EXPORTS for OBJECT targets as well set_target_properties(MagnumObjects MagnumMathObjects PROPERTIES COMPILE_FLAGS "-DMagnumObjects_EXPORTS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") @@ -79,8 +69,7 @@ set_target_properties(MagnumObjects MagnumMathObjects PROPERTIES COMPILE_FLAGS " # Main library add_library(Magnum SHARED $ - $ - ${Magnum_GracefulAssert_SRCS}) + $) target_link_libraries(Magnum ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY}) if(NOT TARGET_GLES) target_link_libraries(Magnum ${OPENGL_gl_LIBRARY} ${GLEW_LIBRARY}) @@ -110,6 +99,10 @@ if(WITH_PRIMITIVES) add_subdirectory(Primitives) endif() +if(WITH_SCENEGRAPH) + add_subdirectory(SceneGraph) +endif() + if(WITH_SHADERS) add_subdirectory(Shaders) endif() @@ -119,8 +112,7 @@ if(BUILD_TESTS) # Library with graceful assert for testing add_library(MagnumTestLib SHARED - $ - ${Magnum_GracefulAssert_SRCS}) + $) set_target_properties(MagnumTestLib PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) target_link_libraries(MagnumTestLib ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY}) if(NOT TARGET_GLES) diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt new file mode 100644 index 000000000..dd8f5bee3 --- /dev/null +++ b/src/SceneGraph/CMakeLists.txt @@ -0,0 +1,42 @@ +# Files shared between main library and unit test library +set(MagnumSceneGraph_SRCS + Camera.cpp + Light.cpp) +set(MagnumSceneGraph_HEADERS + Camera.h + Light.h + Object.h + Scene.h + + magnumSceneGraphVisibility.h) +add_library(MagnumSceneGraphObjects OBJECT ${MagnumSceneGraph_SRCS}) + +# Files compiled with different flags for main library and unit test library +set(MagnumSceneGraph_GracefulAssert_SRCS + Object.cpp) + +# Set shared library flags for the objects, as they will be part of shared lib +# TODO: fix when CMake sets target_EXPORTS for OBJECT targets as well +set_target_properties(MagnumSceneGraphObjects PROPERTIES COMPILE_FLAGS "-DMagnumSceneGraphObjects_EXPORTS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") + +# SceneGraph library +add_library(MagnumSceneGraph SHARED + $ + ${MagnumSceneGraph_GracefulAssert_SRCS}) +target_link_libraries(MagnumSceneGraph Magnum) + +install(TARGETS MagnumSceneGraph DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) +install(FILES ${MagnumSceneGraph_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/SceneGraph) + +if(BUILD_TESTS) + enable_testing() + + # Library with graceful assert for testing + add_library(MagnumSceneGraphTestLib SHARED + $ + ${MagnumSceneGraph_GracefulAssert_SRCS}) + set_target_properties(MagnumSceneGraphTestLib PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) + target_link_libraries(MagnumSceneGraphTestLib Magnum) + + add_subdirectory(Test) +endif() diff --git a/src/Camera.cpp b/src/SceneGraph/Camera.cpp similarity index 98% rename from src/Camera.cpp rename to src/SceneGraph/Camera.cpp index f15454a27..d05ff63f1 100644 --- a/src/Camera.cpp +++ b/src/SceneGraph/Camera.cpp @@ -19,7 +19,7 @@ using namespace std; -namespace Magnum { +namespace Magnum { namespace SceneGraph { Camera::Camera(Object* parent): Object(parent), _aspectRatioPolicy(AspectRatioPolicy::Extend) {} @@ -122,4 +122,4 @@ void Camera::drawChildren(Object* object, const Matrix4& transformationMatrix) { } } -} +}} diff --git a/src/Camera.h b/src/SceneGraph/Camera.h similarity index 94% rename from src/Camera.h rename to src/SceneGraph/Camera.h index 3cecda517..47be24edb 100644 --- a/src/Camera.h +++ b/src/SceneGraph/Camera.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Camera_h -#define Magnum_Camera_h +#ifndef Magnum_SceneGraph_Camera_h +#define Magnum_SceneGraph_Camera_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Camera + * @brief Class Magnum::SceneGraph::Camera */ #include "Object.h" @@ -26,12 +26,12 @@ #undef far #endif -namespace Magnum { +namespace Magnum { namespace SceneGraph { /** @ingroup scene @brief %Camera object */ -class MAGNUM_EXPORT Camera: public Object { +class SCENEGRAPH_EXPORT Camera: public Object { public: /** * @brief Aspect ratio policy @@ -148,9 +148,9 @@ class MAGNUM_EXPORT Camera: public Object { Math::Vector2 _viewport; AspectRatioPolicy _aspectRatioPolicy; - MAGNUM_LOCAL void fixAspectRatio(); + SCENEGRAPH_LOCAL void fixAspectRatio(); }; -} +}} #endif diff --git a/src/Light.cpp b/src/SceneGraph/Light.cpp similarity index 94% rename from src/Light.cpp rename to src/SceneGraph/Light.cpp index 9c12bfff2..9b5eb5860 100644 --- a/src/Light.cpp +++ b/src/SceneGraph/Light.cpp @@ -15,7 +15,7 @@ #include "Light.h" -namespace Magnum { +namespace Magnum { namespace SceneGraph { void Light::clean(const Matrix4& absoluteTransformation) { Object::clean(absoluteTransformation); @@ -23,4 +23,4 @@ void Light::clean(const Matrix4& absoluteTransformation) { _position = absoluteTransformation[3]; } -} +}} diff --git a/src/Light.h b/src/SceneGraph/Light.h similarity index 86% rename from src/Light.h rename to src/SceneGraph/Light.h index 1675753f4..8a902b699 100644 --- a/src/Light.h +++ b/src/SceneGraph/Light.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Light_h -#define Magnum_Light_h +#ifndef Magnum_SceneGraph_Light_h +#define Magnum_SceneGraph_Light_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,19 +16,19 @@ */ /** @file - * @brief Class Magnum::Light + * @brief Class Magnum::SceneGraph::Light */ #include "Object.h" -namespace Magnum { +namespace Magnum { namespace SceneGraph { /** @ingroup scene * @brief Basic light object * * Provides cached light position. */ -class MAGNUM_EXPORT Light: public Object { +class SCENEGRAPH_EXPORT Light: public Object { public: /** * @brief Constructor @@ -54,6 +54,6 @@ class MAGNUM_EXPORT Light: public Object { Vector4 _position; }; -} +}} #endif diff --git a/src/Object.cpp b/src/SceneGraph/Object.cpp similarity index 98% rename from src/Object.cpp rename to src/SceneGraph/Object.cpp index 66614f7ed..5ee2d06a6 100644 --- a/src/Object.cpp +++ b/src/SceneGraph/Object.cpp @@ -16,12 +16,13 @@ #include "Object.h" #include + #include "Scene.h" #include "Camera.h" using namespace std; -namespace Magnum { +namespace Magnum { namespace SceneGraph { Object* Object::setParent(Object* parent) { /* Skip if nothing to do or this is scene */ @@ -149,4 +150,4 @@ void Object::setClean() { } } -} +}} diff --git a/src/Object.h b/src/SceneGraph/Object.h similarity index 97% rename from src/Object.h rename to src/SceneGraph/Object.h index d4df67530..66280e729 100644 --- a/src/Object.h +++ b/src/SceneGraph/Object.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Object_h -#define Magnum_Object_h +#ifndef Magnum_SceneGraph_Object_h +#define Magnum_SceneGraph_Object_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,14 +16,16 @@ */ /** @file - * @brief Class Magnum::Object + * @brief Class Magnum::SceneGraph::Object */ #include #include "Magnum.h" -namespace Magnum { +#include "magnumSceneGraphVisibility.h" + +namespace Magnum { namespace SceneGraph { class Scene; class Camera; @@ -44,7 +46,7 @@ class Camera; * @todo Transform transformation when changing parent, so the object stays in * place. */ -class MAGNUM_EXPORT Object { +class SCENEGRAPH_EXPORT Object { Object(const Object& other) = delete; Object(Object&& other) = delete; Object& operator=(const Object& other) = delete; @@ -268,7 +270,6 @@ class MAGNUM_EXPORT Object { inline void Object::draw(const Matrix4&, Camera*) {} inline void Object::clean(const Matrix4&) { dirty = false; } - -} +}} #endif diff --git a/src/Scene.h b/src/SceneGraph/Scene.h similarity index 86% rename from src/Scene.h rename to src/SceneGraph/Scene.h index 076e6f4ef..13b504ee4 100644 --- a/src/Scene.h +++ b/src/SceneGraph/Scene.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Scene_h -#define Magnum_Scene_h +#ifndef Magnum_SceneGraph_Scene_h +#define Magnum_SceneGraph_Scene_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,17 +16,17 @@ */ /** @file - * @brief Class Magnum::Scene + * @brief Class Magnum::SceneGraph::Scene */ #include "Object.h" -namespace Magnum { +namespace Magnum { namespace SceneGraph { /** @ingroup scene @brief %Scene */ -class MAGNUM_EXPORT Scene: public Object { +class SCENEGRAPH_EXPORT Scene: public Object { public: /** @brief Constructor */ inline Scene() { _parent = this; } @@ -42,6 +42,6 @@ class MAGNUM_EXPORT Scene: public Object { inline void draw(const Magnum::Matrix4&, Camera*) {} }; -} +}} #endif diff --git a/src/SceneGraph/Test/CMakeLists.txt b/src/SceneGraph/Test/CMakeLists.txt new file mode 100644 index 000000000..e0db0910d --- /dev/null +++ b/src/SceneGraph/Test/CMakeLists.txt @@ -0,0 +1,3 @@ +corrade_add_test2(SceneGraphObjectTest ObjectTest.cpp LIBRARIES MagnumSceneGraphTestLib) +corrade_add_test2(SceneGraphCameraTest CameraTest.cpp LIBRARIES MagnumSceneGraph) +corrade_add_test2(SceneGraphSceneTest SceneTest.cpp LIBRARIES MagnumSceneGraph) diff --git a/src/Test/CameraTest.cpp b/src/SceneGraph/Test/CameraTest.cpp similarity index 90% rename from src/Test/CameraTest.cpp rename to src/SceneGraph/Test/CameraTest.cpp index 4211d0235..508705b43 100644 --- a/src/Test/CameraTest.cpp +++ b/src/SceneGraph/Test/CameraTest.cpp @@ -15,12 +15,11 @@ #include "CameraTest.h" -#include "Camera.h" -#include "Scene.h" +#include "SceneGraph/Camera.h" -CORRADE_TEST_MAIN(Magnum::Test::CameraTest) +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::CameraTest) -namespace Magnum { namespace Test { +namespace Magnum { namespace SceneGraph { namespace Test { CameraTest::CameraTest() { addTests(&CameraTest::orthographic, @@ -51,4 +50,4 @@ void CameraTest::perspective() { CORRADE_COMPARE(camera.projectionMatrix(), a); } -}} +}}} diff --git a/src/Test/CameraTest.h b/src/SceneGraph/Test/CameraTest.h similarity index 83% rename from src/Test/CameraTest.h rename to src/SceneGraph/Test/CameraTest.h index 9f5424647..ec9a699b0 100644 --- a/src/Test/CameraTest.h +++ b/src/SceneGraph/Test/CameraTest.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Test_CameraTest_h -#define Magnum_Test_CameraTest_h +#ifndef Magnum_SceneGraph_Test_CameraTest_h +#define Magnum_SceneGraph_Test_CameraTest_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -17,7 +17,7 @@ #include -namespace Magnum { namespace Test { +namespace Magnum { namespace SceneGraph { namespace Test { class CameraTest: public Corrade::TestSuite::Tester { public: @@ -27,6 +27,6 @@ class CameraTest: public Corrade::TestSuite::Tester { void perspective(); }; -}} +}}} #endif diff --git a/src/Test/ObjectTest.cpp b/src/SceneGraph/Test/ObjectTest.cpp similarity index 97% rename from src/Test/ObjectTest.cpp rename to src/SceneGraph/Test/ObjectTest.cpp index 9e9f30a72..5a4f22a6e 100644 --- a/src/Test/ObjectTest.cpp +++ b/src/SceneGraph/Test/ObjectTest.cpp @@ -14,16 +14,16 @@ */ #include "ObjectTest.h" -#include "Scene.h" -#include "Camera.h" +#include "SceneGraph/Camera.h" +#include "SceneGraph/Scene.h" #include using namespace std; -CORRADE_TEST_MAIN(Magnum::Test::ObjectTest) +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::ObjectTest) -namespace Magnum { namespace Test { +namespace Magnum { namespace SceneGraph { namespace Test { ObjectTest::ObjectTest() { addTests(&ObjectTest::parenting, @@ -195,4 +195,4 @@ void ObjectTest::dirty() { CORRADE_VERIFY(childThree->isDirty()); } -}} +}}} diff --git a/src/Test/ObjectTest.h b/src/SceneGraph/Test/ObjectTest.h similarity index 88% rename from src/Test/ObjectTest.h rename to src/SceneGraph/Test/ObjectTest.h index da48eabab..8505bd59e 100644 --- a/src/Test/ObjectTest.h +++ b/src/SceneGraph/Test/ObjectTest.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Test_ObjectTest_h -#define Magnum_Test_ObjectTest_h +#ifndef Magnum_SceneGraph_Test_ObjectTest_h +#define Magnum_SceneGraph_Test_ObjectTest_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -17,9 +17,9 @@ #include -#include "Object.h" +#include "SceneGraph/Object.h" -namespace Magnum { namespace Test { +namespace Magnum { namespace SceneGraph { namespace Test { class ObjectTest: public Corrade::TestSuite::Tester { public: @@ -46,6 +46,6 @@ class ObjectTest: public Corrade::TestSuite::Tester { }; }; -}} +}}} #endif diff --git a/src/Test/SceneTest.cpp b/src/SceneGraph/Test/SceneTest.cpp similarity index 89% rename from src/Test/SceneTest.cpp rename to src/SceneGraph/Test/SceneTest.cpp index ac05d18e8..132c09e0b 100644 --- a/src/Test/SceneTest.cpp +++ b/src/SceneGraph/Test/SceneTest.cpp @@ -15,11 +15,11 @@ #include "SceneTest.h" -#include "Scene.h" +#include "SceneGraph/Scene.h" -CORRADE_TEST_MAIN(Magnum::Test::SceneTest) +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::SceneTest) -namespace Magnum { namespace Test { +namespace Magnum { namespace SceneGraph { namespace Test { SceneTest::SceneTest() { addTests(&SceneTest::transformation, @@ -48,4 +48,4 @@ void SceneTest::parent() { CORRADE_VERIFY(object.children().empty()); } -}} +}}} diff --git a/src/Test/SceneTest.h b/src/SceneGraph/Test/SceneTest.h similarity index 83% rename from src/Test/SceneTest.h rename to src/SceneGraph/Test/SceneTest.h index 77af6179d..6d1af5c9b 100644 --- a/src/Test/SceneTest.h +++ b/src/SceneGraph/Test/SceneTest.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Test_SceneTest_h -#define Magnum_Test_SceneTest_h +#ifndef Magnum_SceneGraph_Test_SceneTest_h +#define Magnum_SceneGraph_Test_SceneTest_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -17,7 +17,7 @@ #include -namespace Magnum { namespace Test { +namespace Magnum { namespace SceneGraph { namespace Test { class SceneTest: public Corrade::TestSuite::Tester { public: @@ -27,6 +27,6 @@ class SceneTest: public Corrade::TestSuite::Tester { void parent(); }; -}} +}}} #endif diff --git a/src/SceneGraph/magnumSceneGraphVisibility.h b/src/SceneGraph/magnumSceneGraphVisibility.h new file mode 100644 index 000000000..2e1c2e758 --- /dev/null +++ b/src/SceneGraph/magnumSceneGraphVisibility.h @@ -0,0 +1,30 @@ +#ifndef Magnum_SceneGraph_magnumSceneGraphVisibility_h +#define Magnum_SceneGraph_magnumSceneGraphVisibility_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. +*/ + +#ifdef _WIN32 + #if defined(MagnumSceneGraph_EXPORTS) || defined(MagnumSceneGraphObjects_EXPORTS) + #define SCENEGRAPH_EXPORT __declspec(dllexport) + #else + #define SCENEGRAPH_EXPORT __declspec(dllimport) + #endif + #define SCENEGRAPH_LOCAL +#else + #define SCENEGRAPH_EXPORT __attribute__ ((visibility ("default"))) + #define SCENEGRAPH_LOCAL __attribute__ ((visibility ("hidden"))) +#endif + +#endif diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 67650069a..f86d239e8 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -1,6 +1,2 @@ -corrade_add_test2(ObjectTest ObjectTest.cpp LIBRARIES MagnumTestLib) -corrade_add_test2(CameraTest CameraTest.cpp LIBRARIES Magnum) -corrade_add_test2(SceneTest SceneTest.cpp LIBRARIES Magnum) - corrade_add_test2(ColorTest ColorTest.cpp) corrade_add_test2(SwizzleTest SwizzleTest.cpp)