Browse Source

Merge branch 'master' into compatibility

Conflicts:
	src/CMakeLists.txt
	src/MeshTools/CMakeLists.txt
Vladimír Vondruš 14 years ago
parent
commit
7ab72cafd8
  1. 49
      CMakeLists.txt
  2. 2
      PKGBUILD
  3. 2
      PKGBUILD-release
  4. 17
      README.md
  5. 47
      doc/building.dox
  6. 73
      doc/coding-style.dox
  7. 88
      modules/FindMagnum.cmake
  8. 87
      src/CMakeLists.txt
  9. 41
      src/Contexts/CMakeLists.txt
  10. 2
      src/Contexts/EglContext.cpp
  11. 3
      src/Contexts/EglContext.h
  12. 11
      src/Contexts/GlutContext.h
  13. 2
      src/Contexts/Sdl2Context.cpp
  14. 17
      src/Contexts/Sdl2Context.h
  15. 2
      src/Framebuffer.cpp
  16. 12
      src/Math/CMakeLists.txt
  17. 5
      src/Math/Geometry/CMakeLists.txt
  18. 2
      src/Math/Math.h
  19. 6
      src/Math/Matrix.h
  20. 55
      src/Math/Matrix3.h
  21. 49
      src/Math/Matrix4.h
  22. 4
      src/Math/Test/MathTypeTraitsTest.cpp
  23. 31
      src/Math/Test/Matrix3Test.cpp
  24. 3
      src/Math/Test/Matrix3Test.h
  25. 2
      src/Math/Test/MatrixTest.cpp
  26. 2
      src/Math/Test/VectorTest.cpp
  27. 4
      src/Math/Vector.h
  28. 30
      src/MeshTools/CMakeLists.txt
  29. 2
      src/MeshTools/Interleave.h
  30. 4
      src/MeshTools/Test/CleanTest.h
  31. 4
      src/MeshTools/Test/SubdivideTest.h
  32. 11
      src/Object.h
  33. 17
      src/Physics/CMakeLists.txt
  34. 10
      src/Primitives/CMakeLists.txt
  35. 2
      src/Scene.h
  36. 21
      src/Set.h
  37. 14
      src/Shaders/CMakeLists.txt
  38. 4
      src/Trade/AbstractImporter.cpp
  39. 62
      src/Trade/AbstractImporter.h
  40. 13
      src/Trade/CMakeLists.txt

49
CMakeLists.txt

@ -2,21 +2,40 @@
cmake_minimum_required(VERSION 2.8)
project(Magnum)
include(CMakeDependentOption)
option(TARGET_GLES "Build for OpenGL ES 2 instead of desktop OpenGL" OFF)
option(GCC44_COMPATIBILITY "Enable compatibility mode for GCC 4.4 (might disable some features)" OFF)
option(GCC45_COMPATIBILITY "Enable compatibility mode for GCC 4.5 (might disable some features)" OFF)
# Parts of the library
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_SHADERS "Build Shaders library" OFF)
cmake_dependent_option(WITH_EGLCONTEXT "Build EglContext library" OFF "TARGET_GLES" OFF)
cmake_dependent_option(WITH_GLUTCONTEXT "Build GlutContext library" OFF "NOT TARGET_GLES" OFF)
option(WITH_SDL2CONTEXT "Build Sdl2Context library" OFF)
option(BUILD_TESTS "Build unit tests (requires Qt4)." OFF)
if(WITH_EVERYTHING)
set(WITH_MESHTOOLS ON)
set(WITH_PHYSICS ON)
set(WITH_PRIMITIVES ON)
set(WITH_SHADERS ON)
endif()
if(BUILD_TESTS)
find_package(Qt4)
if(NOT QT4_FOUND)
message(WARNING "Qt4 is required for building unit tests. No tests will be build.")
set(BUILD_TESTS OFF)
else()
enable_testing()
message(FATAL_ERROR "Qt4, required for building unit tests, was not found. Set BUILD_TESTS to OFF to skip building them.")
endif()
enable_testing()
endif()
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} VERSION_LESS 2.8.8)
@ -26,15 +45,19 @@ endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${Magnum_SOURCE_DIR}/modules/")
# Populate MAGNUM_*_INSTALL_DIR variables, check for dependencies
set(MAGNUM_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(MAGNUM_LIBRARY Magnum)
include(FindMagnum)
# Check dependencies
find_package(Corrade REQUIRED)
if(NOT TARGET_GLES)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
else()
find_package(OpenGLES2 REQUIRED)
endif()
# Installation paths
set(MAGNUM_LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
set(MAGNUM_CMAKE_MODULE_INSTALL_DIR ${CMAKE_ROOT}/Modules)
set(MAGNUM_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/Magnum)
add_subdirectory(modules)
add_subdirectory(src)
install(DIRECTORY src/ DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}
FILES_MATCHING PATTERN "*.h"
PATTERN "*/Test" EXCLUDE
PATTERN "src/Contexts" EXCLUDE)

2
PKGBUILD

@ -29,7 +29,7 @@ build() {
check() {
cd "$startdir/build"
ctest --output-on-failure
ctest --output-on-failure -E Benchmark
}
package() {

2
PKGBUILD-release

@ -28,7 +28,7 @@ build() {
check() {
cd "$startdir/build"
ctest --output-on-failure
ctest --output-on-failure -E Benchmark
}
package() {

17
README.md

@ -33,7 +33,8 @@ Minimal dependencies
which are tested to support everything needed: **GCC** >= 4.6 and **Clang**
>= 3.1.
* **CMake** >= 2.8.8 (needed for `OBJECT` library target)
* **OpenGL headers**, on Linux most probably shipped with Mesa
* **OpenGL** headers, on Linux most probably shipped with Mesa or
**OpenGL ES 2** headers, if targeting OpenGL ES.
* **GLEW** - OpenGL extension wrangler
* **Corrade** - Plugin management and utility library. You can get it at
http://mosra.cz/blog/corrade.php
@ -41,11 +42,14 @@ Minimal dependencies
Compilation, installation
-------------------------
The library can be built and installed using these four commands:
The library (for example with GLUT context) can be built and installed using
these four commands:
mkdir -p build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr .. && make
mkdir -p build && cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX=/usr \
-DWITH_GLUTCONTEXT=ON
make
make install
Building and running unit tests
@ -70,7 +74,8 @@ documentation can be build by running:
doxygen
in root directory (i.e. where `Doxyfile` is). Resulting HTML documentation
will be in `build/doc/` directory.
will be in `build/doc/` directory. You might need to create `build/` directory
if it doesn't exist yet.
PLUGINS AND EXAMPLES
====================

47
doc/building.dox

@ -1,3 +1,4 @@
namespace Magnum {
/** @page building Downloading and building
@brief Guide how to download and build %Magnum on different platforms.
@ -15,7 +16,7 @@ Minimal set of tools and libraries required for building is:
>= 3.1.
- **CMake** >= 2.8.8 (needed for `OBJECT` library target)
- **OpenGL** headers, on Linux most probably shipped with Mesa or
**OpenGL ES 2** headers, if targetting OpenGL ES 2.
**OpenGL ES 2** headers, if targeting OpenGL ES (see below).
- **GLEW** - OpenGL extension wrangler
- **Corrade** - Plugin management and utility library. You can get it at
http://github.com/mosra/corrade or at http://mosra.cz/blog/corrade.php.
@ -36,19 +37,45 @@ subdirectory:
git submodule update
@section building-compilation Compilation, installation
The library can be built and installed using these four commands:
The library (for example with GLUT context) can be built and installed using
these four commands. See below for more information about optional features.
mkdir -p build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr .. && make
mkdir -p build && cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX=/usr \
-DWITH_GLUTCONTEXT=ON
make
make install
By default the engine is built for desktop OpenGL. If you want to target
OpenGL ES 2, pass `-DTARGET_GLES=True` to CMake.
If you want to build with another compiler (e.g. Clang), pass
`-DCMAKE_CXX_COMPILER=clang++` to CMake.
@subsection building-optional Enabling or disabling features
By default the engine is built for desktop OpenGL. If you want to target
OpenGL ES, set `TARGET_GLES` to `ON` or pass `-DTARGET_GLES=ON` to CMake. Note
that some features are available for desktop OpenGL only, see @ref requires-gl.
By default the engine is built with everything except
@ref Contexts "context libraries". Using `WITH_*` CMake parameters you can
specify which parts will be built and which not:
- `WITH_EVERYTHING` - Defaults to `ON`, builds everything except contexts. If
set to `OFF`, only the main library is built and you can select additional
libraries with the following:
- `WITH_MESHTOOLS` - MeshTools library.
- `WITH_PHYSICS` - Physics library.
- `WITH_PRIMITIVES` - Primitives library.
- `WITH_SHADERS` - Shaders library.
None of the context libraries is built by default, regardless to
`WITH_EVERYTHING` is enabled or not:
- `WITH_EGLCONTEXT` - X/EGL context, available only if targeting OpenGL ES
(see above). Requires **X11** and **EGL** libraries.
- `WITH_GLUTCONTEXT` - GLUT context, available only if targeting desktop
OpenGL. Requires **GLUT** library.
- `WITH_SDL2CONTEXT` - SDL2 context. Requires **SDL2** library.
@subsection building-tests Building and running unit tests
If you want to build also unit tests (which are not built by default), pass
`-DBUILD_TESTS=True` to CMake. Unit tests use QtTest framework (you need at
@ -67,7 +94,8 @@ for math formulas. The documentation can be build by running
doxygen
in root directory (i.e. where `Doxyfile` is). Resulting HTML documentation
will be in `build/doc/` directory.
will be in `build/doc/` directory. You might need to create `build/` directory
if it doesn't exist yet.
@section building-arch Building ArchLinux packages
In `package/archlinux` directory is currently one PKGBUILD for Git development
@ -114,3 +142,4 @@ You may need to modify the `basic-mingw32.cmake` file and
`CMAKE_INSTALL_PREFIX` to suit your distribution filesystem hierarchy. If
everything goes well, in `build-win/` subdirectories will be the DLLs.
*/
}

73
doc/coding-style.dox

@ -9,6 +9,31 @@ Please note that if you have a good excuse to either break the rules or modify
them, feel free to do it (and update this guide accordingly, if appropriate).
Nothing is worse than rule that hurts productivity instead of improving it.
You can also take inspiration from other thorougly written coding style
guidelines of large projects:
- LLVM: http://llvm.org/docs/CodingStandards.html
- Qt: http://qt-project.org/wiki/Qt_Coding_Style
@section cmake CMake code
All cmake functions and macros (e.g. `add_executable()`, `set()`) are
lowercase, keywords (e.g. `FILES`, `DESTINATION`) are uppercase. Variables are
mostly uppercase with underscores between words, except for variables with
direct relation to any named target - then they have the target name as prefix
with no case change, followed with underscore, the rest of variable name is
uppercase, e.g. variable holding all sources for target `MagnuMeshTools` will
be named `MagnumMeshTools_SRCS`.
Multi-line calls (i.e. `set()`) have trailing parenthesis on the same line as
last parameter, *not* on separate line:
@code
set(Magnum_SRCS
Object.cpp
Camera.cpp
Light.cpp)
@endcode
@section cpp C++ code
@subsection cpp-files File naming and directory structure
@ -206,9 +231,10 @@ switch(type) {
}
@endcode
@subsubsection cpp-virtual Virtual functions
@subsubsection cpp-keywords Class member and function keywords
Only base virtual functions should have `virtual` keyword, not the
Use keywords in this order: `template virtual inline constexpr static`. Only
base virtual functions should have `virtual` keyword, not the
reimplementations.
@subsubsection cpp-includes Includes
@ -231,6 +257,49 @@ it should be wrapped on multiple lines, each successive line indented and the
line wrapping indicator `\` should be aligned around 80th column, preferably
on some tab-stop.
@subsection cpp-constexpr Constant expressions and constants
Use `constexpr` keyword as much as possible, mainly for getters and static
pure functions, e.g. Matrix4::translation(). If the function is not a single
return-statement, try hard to make it so.
Traits class members and class constants which are not meant to be referenced
or pointed to should be defined as inline (constexpr) function, because
declaring them as static const variable will result in another (probably
unwanted) symbol.
@subsection cpp-assert Assertions
Use asserts as much as possible. %Corrade utility library has convenient
`CORRADE_ASSERT()` macro, which does everything needed - checks the statement,
prints given message to error output and exits immediately or returns default
value:
@code
T operator[](size_t pos) const {
CORRADE_ASSERT(pos < size(), "Index out of range", T())
return data[pos];
}
@endcode
@subsection cpp-forbidden Forbidden C/C++ features
Don't use C-style casts, use C++-style `static_cast` and `reinterpret_cast`
instead. For numeric types (e.g. casting from int to float) you can use
"constructor cast":
@code
int a = 22;
int b = 7;
float pi = ((float) a)/b; // bad!
float pi = static_cast<float>(a)/b; // good
float pi = float(a)/b; // even better here
@endcode
Don't use RTTI (`dynamic_cast` and `std::typeinfo`) and exceptions. They
violate C++ principle of "don't pay for what you don't use" and thus they are
disabled in the code (GCC/Clang option `-fno-rtti -fno-exceptions`).
@section comments Comments
All comments should be in C-style (i.e. slash and asterisk, not two slashes).

88
modules/FindMagnum.cmake

@ -7,8 +7,12 @@
# This command tries to find Magnum library and then defines:
#
# MAGNUM_FOUND - Whether the library was found
# MAGNUM_LIBRARY - Magnum library
# MAGNUM_INCLUDE_DIR - Root include dir
# MAGNUM_TARGET_GLES - Defined if Magnum was built for OpenGL ES,
# slightly reducing feature count. The same variable is also #defined in
# Magnum headers.
# MAGNUM_LIBRARIES - Magnum library and dependent libraries
# MAGNUM_INCLUDE_DIRS - Root include dir and include dirs of
# dependencies
# MAGNUM_PLUGINS_IMPORTER_DIR - Directory with importer plugins
#
# This command will try to find only the base library, not the optional
@ -16,12 +20,15 @@
# Additional dependencies are specified by the components. The optional
# components are:
#
# GlutContext - GLUT context (depends on GLUT package)
# MeshTools - MeshTools library
# Physics - Physics library
# Primitives - Library with stock geometric primitives (static)
# Shaders - Library with stock shaders
#
# EglContext - EGL context (depends on EGL and X11 libraries)
# GlutContext - GLUT context (depends on GLUT library)
# Sdl2Context - SDL2 context (depends on SDL2 library)
#
# Example usage with specifying additional components is:
#
# find_package(Magnum [REQUIRED|COMPONENTS] MeshTools Primitives GlutContext)
@ -29,10 +36,15 @@
# For each component is then defined:
#
# MAGNUM_*_FOUND - Whether the component was found
# MAGNUM_*_LIBRARY - Component library
# MAGNUM_*_LIBRARIES - Component library and dependent libraries
# MAGNUM_*_INCLUDE_DIRS - Include dirs of module dependencies
#
# Additionally these variables are defined for internal usage:
#
# MAGNUM_INCLUDE_DIR - Root include dir (w/o dependencies)
# MAGNUM_LIBRARY - Magnum library (w/o dependencies)
# MAGNUM_*_LIBRARY - Component libraries (w/o dependencies)
#
# MAGNUM_LIBRARY_INSTALL_DIR - Library installation directory
# MAGNUM_PLUGINS_INSTALL_DIR - Plugin installation directory
# MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR - Importer plugin installation directory
@ -44,21 +56,29 @@
# Dependencies
find_package(Corrade REQUIRED)
if(NOT TARGET_GLES)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
else()
find_package(OpenGLES2 REQUIRED)
endif()
# Magnum library
find_library(MAGNUM_LIBRARY Magnum)
# Root include dir
find_path(MAGNUM_INCLUDE_DIR
NAMES Magnum.h
PATH_SUFFIXES Magnum
)
PATH_SUFFIXES Magnum)
# Configuration
file(READ ${MAGNUM_INCLUDE_DIR}/magnumConfigure.h _magnumConfigure)
# Built for OpenGL ES?
string(FIND "${_magnumConfigure}" "#define MAGNUM_TARGET_GLES" _TARGET_GLES)
if(NOT _TARGET_GLES EQUAL -1)
set(MAGNUM_TARGET_GLES 1)
endif()
if(NOT MAGNUM_TARGET_GLES)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
else()
find_package(OpenGLES2 REQUIRED)
endif()
# Additional components
foreach(component ${Magnum_FIND_COMPONENTS})
@ -77,7 +97,9 @@ foreach(component ${Magnum_FIND_COMPONENTS})
# GLUT context dependencies
if(${component} STREQUAL GlutContext)
find_package(GLUT)
if(NOT GLUT_FOUND)
if(GLUT_FOUND)
set(_MAGNUM_${_COMPONENT}_LIBRARIES ${GLUT_LIBRARIES})
else()
unset(MAGNUM_${_COMPONENT}_LIBRARY)
endif()
endif()
@ -85,17 +107,21 @@ foreach(component ${Magnum_FIND_COMPONENTS})
# SDL2 context dependencies
if(${component} STREQUAL Sdl2Context)
find_package(SDL2)
if(NOT SDL2_FOUND)
if(SDL2_FOUND)
set(_MAGNUM_${_COMPONENT}_LIBRARIES ${SDL2_LIBRARY})
set(_MAGNUM_${_COMPONENT}_INCLUDE_DIRS ${SDL2_INCLUDE_DIR})
else()
unset(MAGNUM_${_COMPONENT}_LIBRARY)
endif()
endif()
# X/EGL context dependencies
if(${component} STREQUAL EglContext)
find_package(OpenGLES2)
find_package(EGL)
find_package(X11)
if(NOT OPENGLES2_FOUND OR NOT EGL_FOUND OR NOT X11_FOUND)
if(EGL_FOUND AND X11_FOUND)
set(_MAGNUM_${_COMPONENT}_LIBRARIES ${EGL_LIBRARY} ${X11_LIBRARIES})
else()
unset(MAGNUM_${_COMPONENT}_LIBRARY)
endif()
endif()
@ -125,12 +151,13 @@ foreach(component ${Magnum_FIND_COMPONENTS})
if(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES)
find_path(_MAGNUM_${_COMPONENT}_INCLUDE_DIR
NAMES ${_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES}
PATHS ${MAGNUM_INCLUDE_DIR}/${_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX}
)
PATHS ${MAGNUM_INCLUDE_DIR}/${_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX})
endif()
# Decide if the library was found
if(MAGNUM_${_COMPONENT}_LIBRARY AND _MAGNUM_${_COMPONENT}_INCLUDE_DIR)
set(MAGNUM_${_COMPONENT}_LIBRARIES ${MAGNUM_${_COMPONENT}_LIBRARY} ${_MAGNUM_${_COMPONENT}_LIBRARIES})
set(MAGNUM_${_COMPONENT}_INCLUDE_DIRS ${_MAGNUM_${_COMPONENT}_INCLUDE_DIRS})
set(Magnum_${component}_FOUND TRUE)
else()
set(Magnum_${component}_FOUND FALSE)
@ -140,8 +167,22 @@ endforeach()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Magnum
REQUIRED_VARS MAGNUM_INCLUDE_DIR MAGNUM_LIBRARY
HANDLE_COMPONENTS
)
HANDLE_COMPONENTS)
# Dependent libraries and includes
set(MAGNUM_INCLUDE_DIRS ${MAGNUM_INCLUDE_DIR}
${CORRADE_INCLUDE_DIR})
set(MAGNUM_LIBRARIES ${MAGNUM_LIBRARY}
${CORRADE_UTILITY_LIBRARY}
${CORRADE_PLUGINMANAGER_LIBRARY})
if(NOT MAGNUM_TARGET_GLES)
set(MAGNUM_LIBRARIES ${MAGNUM_LIBRARIES}
${OPENGL_gl_LIBRARY}
${GLEW_LIBRARY})
else()
set(MAGNUM_LIBRARIES ${MAGNUM_LIBRARIES}
${OPENGLES2_LIBRARY})
endif()
# Installation dirs
set(MAGNUM_LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
@ -151,13 +192,14 @@ set(MAGNUM_CMAKE_MODULE_INSTALL_DIR ${CMAKE_ROOT}/Modules)
set(MAGNUM_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/Magnum)
set(MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/Magnum/Plugins)
mark_as_advanced(FORCE
MAGNUM_LIBRARY
MAGNUM_INCLUDE_DIR
MAGNUM_LIBRARY_INSTALL_DIR
MAGNUM_PLUGINS_INSTALL_DIR
MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR
MAGNUM_CMAKE_MODULE_INSTALL_DIR
MAGNUM_INCLUDE_INSTALL_DIR
MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR
)
MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR)
# Importer plugins dir
if(NOT WIN32)

87
src/CMakeLists.txt

@ -1,5 +1,10 @@
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -std=c++0x -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wold-style-cast -pedantic -std=c++0x -fvisibility=hidden -fno-rtti -fno-exceptions")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion")
endif()
# If targeting GLES, save it into configuration header
if(TARGET_GLES)
set(MAGNUM_TARGET_GLES 1)
endif()
@ -36,44 +41,67 @@ set(Magnum_SRCS
TypeTraits.cpp
Trade/AbstractImporter.cpp
Trade/MeshData.cpp
)
Trade/MeshData.cpp)
set(Magnum_HEADERS
AbstractImage.h
AbstractShaderProgram.h
AbstractTexture.h
BufferedImage.h
BufferedTexture.h
Buffer.h
Camera.h
CubeMapTextureArray.h
CubeMapTexture.h
Framebuffer.h
Image.h
ImageWrapper.h
IndexedMesh.h
Light.h
Magnum.h
Mesh.h
Object.h
Query.h
Renderbuffer.h
Scene.h
Set.h
Shader.h
SizeTraits.h
Texture.h
TypeTraits.h
magnumVisibility.h)
if(NOT CMAKE_NO_OBJECT_TARGET)
add_library(MagnumObjects OBJECT ${Magnum_SRCS})
endif()
# Files shared between main library and math unit test library
set(MagnumMath_SRCS
Math/Math.cpp
)
Math/Math.cpp)
if(NOT CMAKE_NO_OBJECT_TARGET)
add_library(MagnumMathObjects OBJECT ${MagnumMath_SRCS})
endif()
# 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
if(NOT CMAKE_NO_OBJECT_TARGET)
set_target_properties(MagnumObjects MagnumMathObjects PROPERTIES COMPILE_FLAGS "-DMagnumObjects_EXPORTS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}")
endif()
# Files compiled with different flags for main library and unit test library
set(Magnum_GracefulAssert_SRCS
Object.cpp
)
# Main library
if(NOT CMAKE_NO_OBJECT_TARGET)
add_library(Magnum SHARED
$<TARGET_OBJECTS:MagnumObjects>
$<TARGET_OBJECTS:MagnumMathObjects>
${Magnum_GracefulAssert_SRCS}
)
${Magnum_GracefulAssert_SRCS})
else()
add_library(Magnum SHARED
${Magnum_SRCS}
${MagnumMath_SRCS}
${Magnum_GracefulAssert_SRCS}
)
${Magnum_GracefulAssert_SRCS})
endif()
target_link_libraries(Magnum ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY})
if(NOT TARGET_GLES)
@ -81,32 +109,46 @@ if(NOT TARGET_GLES)
else()
target_link_libraries(Magnum ${OPENGLES2_LIBRARY})
endif()
install(TARGETS Magnum DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
install(FILES ${Magnum_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR})
# Install also configure file
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/magnumConfigure.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR})
add_subdirectory(Contexts)
add_subdirectory(Math)
add_subdirectory(MeshTools)
add_subdirectory(Physics)
add_subdirectory(Primitives)
add_subdirectory(Shaders)
add_subdirectory(Trade)
if(WITH_MESHTOOLS)
add_subdirectory(MeshTools)
endif()
if(WITH_PHYSICS)
add_subdirectory(Physics)
endif()
if(WITH_PRIMITIVES)
add_subdirectory(Primitives)
endif()
if(WITH_SHADERS)
add_subdirectory(Shaders)
endif()
if(BUILD_TESTS)
enable_testing()
include_directories(${QT_INCLUDE_DIR})
# Library with graceful assert for testing
if(NOT CMAKE_NO_OBJECT_TARGET)
add_library(MagnumTestLib SHARED
$<TARGET_OBJECTS:MagnumObjects>
${Magnum_GracefulAssert_SRCS}
)
${Magnum_GracefulAssert_SRCS})
else()
add_library(MagnumTestLib SHARED
${Magnum_SRCS}
${Magnum_GracefulAssert_SRCS}
)
${Magnum_GracefulAssert_SRCS})
endif()
set_target_properties(MagnumTestLib PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT)
target_link_libraries(MagnumTestLib ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY})
@ -116,6 +158,5 @@ if(BUILD_TESTS)
target_link_libraries(MagnumTestLib ${OPENGLES2_LIBRARY})
endif()
include_directories(${QT_INCLUDE_DIR})
add_subdirectory(Test)
endif()

41
src/Contexts/CMakeLists.txt

@ -1,36 +1,39 @@
install(FILES AbstractContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
# GLUT context
if(NOT TARGET_GLES)
if(WITH_GLUTCONTEXT)
find_package(GLUT)
if(GLUT_FOUND)
add_library(MagnumGlutContext STATIC GlutContext.cpp)
install(FILES GlutContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumGlutContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
else()
message(WARNING "GLUT library was not found. GLUT context library will not be generated.")
message(FATAL_ERROR "GLUT library, required by GlutContext, was not found. Set WITH_GLUTCONTEXT to OFF to skip building it.")
endif()
endif()
# SDL2 context
find_package(SDL2)
if(SDL2_FOUND)
include_directories(${SDL2_INCLUDE_DIR})
add_library(MagnumSdl2Context STATIC Sdl2Context.cpp)
install(FILES Sdl2Context.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumSdl2Context DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
else()
message(WARNING "SDL2 library was not found. SDL2 context library will not be generated.")
if(WITH_SDL2CONTEXT)
find_package(SDL2)
if(SDL2_FOUND)
include_directories(${SDL2_INCLUDE_DIR})
add_library(MagnumSdl2Context STATIC Sdl2Context.cpp)
install(FILES Sdl2Context.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumSdl2Context DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
else()
message(FATAL_ERROR "SDL2 library, required by Sdl2Context, was not found. Set WITH_SDL2CONTEXT to OFF to skip building it.")
endif()
endif()
# X/EGL context
find_package(OpenGLES2)
find_package(EGL)
find_package(X11)
if(OPENGLES2_FOUND AND EGL_FOUND AND X11_FOUND)
add_library(MagnumEglContext STATIC EglContext.cpp)
install(FILES EglContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumEglContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
else()
message(WARNING "OpenGL ES 2, EGL or X11 libraries were not found. EGL context library will not be generated.")
if(WITH_EGLCONTEXT)
find_package(EGL)
find_package(X11)
if(EGL_FOUND AND X11_FOUND)
add_library(MagnumEglContext STATIC EglContext.cpp)
install(FILES EglContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumEglContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
else()
message(FATAL_ERROR "EGL or X11 libraries, required by EglContext, were not found. Set WITH_EGLCONTEXT to OFF to skip building it.")
endif()
endif()

2
src/Contexts/EglContext.cpp

@ -15,6 +15,8 @@
#include "EglContext.h"
#define None 0L // redef Xlib nonsense
using namespace std;
namespace Magnum { namespace Contexts {

3
src/Contexts/EglContext.h

@ -22,6 +22,9 @@
#include "Magnum.h"
#include <X11/Xlib.h>
#ifdef None // undef Xlib nonsense to avoid conflicts
#undef None
#endif
#ifndef SUPPORT_X11
#define SUPPORT_X11 // OpenGL ES on BeagleBoard needs this (?)

11
src/Contexts/GlutContext.h

@ -127,7 +127,7 @@ class GlutContext: public AbstractContext {
*
* Called when an key is pressed. Default implementation does nothing.
*/
virtual inline void keyEvent(Key key, const Math::Vector2<int>& position) {}
virtual void keyEvent(Key key, const Math::Vector2<int>& position);
/*@}*/
@ -182,7 +182,7 @@ class GlutContext: public AbstractContext {
* Called when mouse button is pressed or released. Default
* implementation does nothing.
*/
virtual inline void mouseEvent(MouseButton button, MouseState state, const Math::Vector2<int>& position) {}
virtual void mouseEvent(MouseButton button, MouseState state, const Math::Vector2<int>& position);
/**
* @brief Mouse motion event
@ -192,7 +192,7 @@ class GlutContext: public AbstractContext {
*
* @see setMouseTracking()
*/
virtual inline void mouseMotionEvent(const Math::Vector2<int>& position) {}
virtual void mouseMotionEvent(const Math::Vector2<int>& position);
/*@}*/
@ -223,6 +223,11 @@ class GlutContext: public AbstractContext {
char** argv;
};
/* Implementations for inline functions with unused parameters */
inline void GlutContext::keyEvent(GlutContext::Key, const Math::Vector2<int>&) {}
inline void GlutContext::mouseEvent(GlutContext::MouseButton, GlutContext::MouseState, const Math::Vector2<int>&) {}
inline void GlutContext::mouseMotionEvent(const Math::Vector2<int>&) {}
}}
#endif

2
src/Contexts/Sdl2Context.cpp

@ -17,7 +17,7 @@
namespace Magnum { namespace Contexts {
Sdl2Context::Sdl2Context(int argc, char** argv, const std::string& name, const Math::Vector2<GLsizei>& size): _redraw(true) {
Sdl2Context::Sdl2Context(int, char**, const std::string& name, const Math::Vector2<GLsizei>& size): _redraw(true) {
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
Error() << "Cannot initialize SDL.";
exit(1);

17
src/Contexts/Sdl2Context.h

@ -96,13 +96,13 @@ class Sdl2Context: public AbstractContext {
* @param key Key pressed
* @param repeat Non-zero if this is a key repeat
*/
inline virtual void keyPressEvent(Key key, Uint8 repeat) {}
virtual void keyPressEvent(Key key, Uint8 repeat);
/**
* @brief Key release event
* @param key Key release
*/
inline virtual void keyReleaseEvent(Key key) {}
virtual void keyReleaseEvent(Key key);
/*@}*/
@ -138,7 +138,7 @@ class Sdl2Context: public AbstractContext {
* Called when mouse button is pressed or released. Default
* implementation does nothing.
*/
virtual inline void mouseEvent(MouseButton button, MouseState state, const Math::Vector2<int>& position) {}
virtual void mouseEvent(MouseButton button, MouseState state, const Math::Vector2<int>& position);
/**
* @brief Mouse wheel event
@ -148,7 +148,7 @@ class Sdl2Context: public AbstractContext {
* Called when mouse wheel is rotated. Default implementation does
* nothing.
*/
virtual inline void mouseWheelEvent(const Math::Vector2<int>& direction) {}
virtual void mouseWheelEvent(const Math::Vector2<int>& direction);
/**
* @brief Mouse motion event
@ -157,7 +157,7 @@ class Sdl2Context: public AbstractContext {
*
* Called when mouse is moved. Default implementation does nothing.
*/
virtual inline void mouseMotionEvent(const Math::Vector2<int>& position, const Math::Vector2<int>& delta) {}
virtual void mouseMotionEvent(const Math::Vector2<int>& position, const Math::Vector2<int>& delta);
/*@}*/
@ -168,6 +168,13 @@ class Sdl2Context: public AbstractContext {
bool _redraw;
};
/* Implementations for inline functions with unused parameters */
inline void Sdl2Context::keyPressEvent(Sdl2Context::Key, Uint8) {}
inline void Sdl2Context::keyReleaseEvent(Sdl2Context::Key) {}
inline void Sdl2Context::mouseEvent(Sdl2Context::MouseButton, Sdl2Context::MouseState, const Math::Vector2<int>&) {}
inline void Sdl2Context::mouseWheelEvent(const Math::Vector2<int>&) {}
inline void Sdl2Context::mouseMotionEvent(const Math::Vector2<int>&, const Math::Vector2<int>&) {}
}}
#endif

2
src/Framebuffer.cpp

@ -25,7 +25,7 @@ void Framebuffer::setFeature(Feature feature, bool enabled) {
/* Update clear mask, if needed */
ClearMask clearMaskChange;
if(feature == Feature::DepthTest) clearMaskChange = Clear::Color;
if(feature == Feature::DepthTest) clearMaskChange = Clear::Depth;
else if(feature == Feature::StencilTest) clearMaskChange = Clear::Stencil;
else return;

12
src/Math/CMakeLists.txt

@ -1,5 +1,17 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(MagnumMath_HEADERS
Math.h
MathTypeTraits.h
Matrix.h
Matrix3.h
Matrix4.h
Vector.h
Vector2.h
Vector3.h
Vector4.h)
install(FILES ${MagnumMath_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Math)
add_subdirectory(Geometry)
if(BUILD_TESTS)

5
src/Math/Geometry/CMakeLists.txt

@ -1,5 +1,10 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(MagnumMathGeometry_HEADERS
Distance.h
Intersection.h)
install(FILES ${MagnumMathGeometry_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Math/Geometry)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(Test)

2
src/Math/Math.h

@ -65,7 +65,7 @@ namespace Implementation {
}
};
template<> struct Pow<0> {
template<class T> inline constexpr T operator()(T base) const { return 1; }
template<class T> inline constexpr T operator()(T) const { return 1; }
};
}
#endif

6
src/Math/Matrix.h

@ -117,10 +117,10 @@ template<size_t size, class T> class Matrix {
#endif
/** @brief Copy constructor */
inline constexpr Matrix(const Matrix<size, T>& other) = default;
inline constexpr Matrix(const Matrix<size, T>&) = default;
/** @brief Assignment operator */
inline Matrix<size, T>& operator=(const Matrix<size, T>& other) = default;
inline Matrix<size, T>& operator=(const Matrix<size, T>&) = default;
/**
* @brief Raw data
@ -244,7 +244,7 @@ template<size_t size, class T> class Matrix {
return from(s, next..., first[sequence]...);
}
template<size_t ...sequence, class ...U> inline constexpr static Matrix<size, T> from(Implementation::Sequence<sequence...> s, T first, U... next) {
template<size_t ...sequence, class ...U> inline constexpr static Matrix<size, T> from(Implementation::Sequence<sequence...>, T first, U... next) {
return Matrix<size, T>(first, next...);
}

55
src/Math/Matrix3.h

@ -24,17 +24,64 @@
namespace Magnum { namespace Math {
/** @brief 3x3 matrix */
/**
@brief 3x3 matrix
Provides functions for transformations in 2D. See also Matrix4 for 3D
transformations.
*/
template<class T> class Matrix3: public Matrix<3, T> {
public:
/**
* @brief 2D translation matrix
* @param vec Translation vector
*
* @see Matrix4::translation()
*/
inline constexpr static Matrix3<T> translation(const Vector2<T>& vec) {
return Matrix3<T>( /* Column-major! */
T(1), T(0), T(0),
T(0), T(1), T(0),
vec.x(), vec.y(), T(1)
);
}
/**
* @brief 2D scaling matrix
* @param vec Scaling vector
*
* @see Matrix4::scaling()
*/
inline constexpr static Matrix3<T> scaling(const Vector2<T>& vec) {
return Matrix3<T>( /* Column-major! */
vec.x(), T(0), T(0),
T(0), vec.y(), T(0),
T(0), T(0), T(1)
);
}
/**
* @brief 3D rotation matrix
* @param angle Rotation angle (counterclockwise, in radians)
*
* @see Matrix4::rotation()
*/
static Matrix3<T> rotation(T angle) {
return Matrix3<T>( /* Column-major! */
T(cos(angle)), T(sin(angle)), T(0),
-T(sin(angle)), T(cos(angle)), T(0),
T(0), T(0), T(1)
);
}
/** @copydoc Matrix::Matrix(ZeroType) */
inline constexpr explicit Matrix3(typename Matrix<3, T>::ZeroType): Matrix<3, T>(Matrix<3, T>::Zero) {}
/** @copydoc Matrix::Matrix(IdentityType, T) */
inline constexpr explicit Matrix3(typename Matrix<3, T>::IdentityType = (Matrix<3, T>::Identity), T value = T(1)): Matrix<3, T>(
value, 0.0f, 0.0f,
0.0f, value, 0.0f,
0.0f, 0.0f, value
value, T(0), T(0),
T(0), value, T(0),
T(0), T(0), value
) {}
/** @copydoc Matrix::Matrix(T, U...) */

49
src/Math/Matrix4.h

@ -27,43 +27,52 @@ namespace Magnum { namespace Math {
/**
@brief 4x4 matrix
Provides functions for transformations in 3D. See also Matrix3 for 2D
transformations.
@todo Shearing
@todo Reflection
*/
template<class T> class Matrix4: public Matrix<4, T> {
public:
/**
* @brief Translation matrix
* @brief 3D translation matrix
* @param vec Translation vector
*
* @see Matrix3::translation()
*/
inline constexpr static Matrix4<T> translation(const Vector3<T>& vec) {
return Matrix4( /* Column-major! */
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
vec.x(), vec.y(), vec.z(), 1.0f
return Matrix4<T>( /* Column-major! */
T(1), T(0), T(0), T(0),
T(0), T(1), T(0), T(0),
T(0), T(0), T(1), T(0),
vec.x(), vec.y(), vec.z(), T(1)
);
}
/**
* @brief Scaling matrix
* @brief 3D scaling matrix
* @param vec Scaling vector
*
* @see Matrix3::scaling()
*/
inline constexpr static Matrix4 scaling(const Vector3<T>& vec) {
return Matrix4( /* Column-major! */
vec.x(), 0.0f, 0.0f, 0.0f,
0.0f, vec.y(), 0.0f, 0.0f,
0.0f, 0.0f, vec.z(), 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
inline constexpr static Matrix4<T> scaling(const Vector3<T>& vec) {
return Matrix4<T>( /* Column-major! */
vec.x(), T(0), T(0), T(0),
T(0), vec.y(), T(0), T(0),
T(0), T(0), vec.z(), T(0),
T(0), T(0), T(0), T(1)
);
}
/**
* @brief Rotation matrix
* @brief 3D rotation matrix
* @param angle Rotation angle (counterclockwise, in radians)
* @param vec Rotation vector
*
* @see Matrix3::rotation()
* @todo optimize - Assume the vectors are normalized?
*/
static Matrix4 rotation(T angle, const Vector3<T>& vec) {
static Matrix4<T> rotation(T angle, const Vector3<T>& vec) {
Vector3<T> vn = vec.normalized();
T sine = sin(angle);
@ -77,7 +86,7 @@ template<class T> class Matrix4: public Matrix<4, T> {
T yz = vn.y()*vn.z();
T zz = vn.z()*vn.z();
return Matrix4( /* Column-major! */
return Matrix4<T>( /* Column-major! */
cosine + xx*oneMinusCosine,
xy*oneMinusCosine + vn.z()*sine,
xz*oneMinusCosine - vn.y()*sine,
@ -99,10 +108,10 @@ template<class T> class Matrix4: public Matrix<4, T> {
/** @copydoc Matrix::Matrix(IdentityType, T) */
inline constexpr explicit Matrix4(typename Matrix<4, T>::IdentityType = (Matrix<4, T>::Identity), T value = T(1)): Matrix<4, T>(
value, 0.0f, 0.0f, 0.0f,
0.0f, value, 0.0f, 0.0f,
0.0f, 0.0f, value, 0.0f,
0.0f, 0.0f, 0.0f, value
value, T(0), T(0), T(0),
T(0), value, T(0), T(0),
T(0), T(0), value, T(0),
T(0), T(0), T(0), value
) {}
/** @copydoc Matrix::Matrix(T, U...) */

4
src/Math/Test/MathTypeTraitsTest.cpp

@ -47,8 +47,8 @@ template<class T> void MathTypeTraitsTest::_equalsIntegral() {
}
template<class T> void MathTypeTraitsTest::_equalsFloatingPoint() {
QVERIFY(MathTypeTraits<T>::equals(1.0f+MathTypeTraits<T>::epsilon()/2, 1.0f));
QVERIFY(!MathTypeTraits<T>::equals(1.0f+MathTypeTraits<T>::epsilon()*2, 1.0f));
QVERIFY(MathTypeTraits<T>::equals(T(1)+MathTypeTraits<T>::epsilon()/T(2), T(1)));
QVERIFY(!MathTypeTraits<T>::equals(T(1)+MathTypeTraits<T>::epsilon()*T(2), T(1)));
QEXPECT_FAIL(0, "Comparing to infinity is broken", Continue);
QVERIFY(MathTypeTraits<T>::equals(std::numeric_limits<T>::infinity(),

31
src/Math/Test/Matrix3Test.cpp

@ -19,6 +19,7 @@
#include <QtTest/QTest>
#include "Matrix3.h"
#include "Math.h"
QTEST_APPLESS_MAIN(Magnum::Math::Test::Matrix3Test)
@ -51,6 +52,36 @@ void Matrix3Test::constructIdentity() {
QVERIFY(identity3 == identity3Expected);
}
void Matrix3Test::translation() {
Matrix3 matrix(
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
3.0f, 1.0f, 1.0f
);
QVERIFY(Matrix3::translation({3.0f, 1.0f}) == matrix);
}
void Matrix3Test::scaling() {
Matrix3 matrix(
3.0f, 0.0f, 0.0f,
0.0f, 1.5f, 0.0f,
0.0f, 0.0f, 1.0f
);
QVERIFY(Matrix3::scaling({3.0f, 1.5f}) == matrix);
}
void Matrix3Test::rotation() {
Matrix3 matrix(
0.965926f, 0.258819f, 0.0f,
-0.258819f, 0.965926f, 0.0f,
0.0f, 0.0f, 1.0f
);
QVERIFY(Matrix3::rotation(deg(15.0f)) == matrix);
}
void Matrix3Test::debug() {
Matrix3 m(
3.0f, 5.0f, 8.0f,

3
src/Math/Test/Matrix3Test.h

@ -25,6 +25,9 @@ class Matrix3Test: public QObject {
private slots:
void constructIdentity();
void translation();
void scaling();
void rotation();
void debug();
};

2
src/Math/Test/MatrixTest.cpp

@ -110,7 +110,7 @@ void MatrixTest::data() {
m[1][2] = 1.5f;
QVERIFY(m[2][1] == 1.0f);
QCOMPARE(m[2][1], 1.0f);
QVERIFY(m[3] == vector);
Matrix4 expected(

2
src/Math/Test/VectorTest.cpp

@ -69,7 +69,7 @@ void VectorTest::copy() {
}
void VectorTest::dot() {
QVERIFY(Vector4::dot({1.0f, 0.5f, 0.75f, 1.5f}, {2.0f, 4.0f, 1.0f, 7.0f}) == 15.25f);
QCOMPARE(Vector4::dot({1.0f, 0.5f, 0.75f, 1.5f}, {2.0f, 4.0f, 1.0f, 7.0f}), 15.25f);
}
void VectorTest::multiplyDivide() {

4
src/Math/Vector.h

@ -109,10 +109,10 @@ template<size_t size, class T> class Vector {
}
/** @brief Copy constructor */
inline constexpr Vector(const Vector<size, T>& other) = default;
inline constexpr Vector(const Vector<size, T>&) = default;
/** @brief Assignment operator */
inline Vector<size, T>& operator=(const Vector<size, T>& other) = default;
inline Vector<size, T>& operator=(const Vector<size, T>&) = default;
/**
* @brief Raw data

30
src/MeshTools/CMakeLists.txt

@ -1,7 +1,17 @@
# Files shared between main library and unit test library
set(MagnumMeshTools_SRCS
Tipsify.cpp
)
Tipsify.cpp)
set(MagnumMeshTools_HEADERS
Clean.h
CombineIndexedArrays.h
CompressIndices.h
FlipNormals.h
GenerateFlatNormals.h
Interleave.h
Subdivide.h
Tipsify.h
magnumMeshToolsVisibility.h)
if(NOT CMAKE_NO_OBJECT_TARGET)
add_library(MagnumMeshToolsObjects OBJECT ${MagnumMeshTools_SRCS})
endif()
@ -15,24 +25,22 @@ endif()
# Files compiled with different flags for main library and unit test library
set(MagnumMeshTools_GracefulAssert_SRCS
FlipNormals.cpp
GenerateFlatNormals.cpp
)
GenerateFlatNormals.cpp)
# Main library
if(NOT CMAKE_NO_OBJECT_TARGET)
add_library(MagnumMeshTools SHARED
$<TARGET_OBJECTS:MagnumMeshToolsObjects>
${MagnumMeshTools_GracefulAssert_SRCS}
)
${MagnumMeshTools_GracefulAssert_SRCS})
else()
add_library(MagnumMeshTools SHARED
${MagnumMeshTools_SRCS}
${MagnumMeshTools_GracefulAssert_SRCS}
)
${MagnumMeshTools_GracefulAssert_SRCS})
endif()
target_link_libraries(MagnumMeshTools Magnum)
install(TARGETS MagnumMeshTools DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
install(FILES ${MagnumMeshTools_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/MeshTools)
if(BUILD_TESTS)
enable_testing()
@ -41,13 +49,11 @@ if(BUILD_TESTS)
if(NOT CMAKE_NO_OBJECT_TARGET)
add_library(MagnumMeshToolsTestLib SHARED
$<TARGET_OBJECTS:MagnumMeshToolsObjects>
${MagnumMeshTools_GracefulAssert_SRCS}
)
${MagnumMeshTools_GracefulAssert_SRCS})
else()
add_library(MagnumMeshToolsTestLib SHARED
${MagnumMeshTools_SRCS}
${MagnumMeshTools_GracefulAssert_SRCS}
)
${MagnumMeshTools_GracefulAssert_SRCS})
endif()
set_target_properties(MagnumMeshToolsTestLib PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT)
target_link_libraries(MagnumMeshToolsTestLib Magnum)

2
src/MeshTools/Interleave.h

@ -69,7 +69,7 @@ class Interleave {
return first.size();
}
template<class T, class ...U> inline static size_t stride(const T& first, const U&... next) {
template<class T, class ...U> inline static size_t stride(const T&, const U&... next) {
return sizeof(typename T::value_type) + stride(next...);
}

4
src/MeshTools/Test/CleanTest.h

@ -33,8 +33,8 @@ class CleanTest: public QObject {
Vector1(): data(0) {}
Vector1(int i): data(i) {}
int operator[](size_t i) const { return data; }
int& operator[](size_t i) { return data; }
int operator[](size_t) const { return data; }
int& operator[](size_t) { return data; }
bool operator==(Vector1 i) const { return i.data == data; }
Vector1 operator-(Vector1 i) const { return data-i.data; }

4
src/MeshTools/Test/SubdivideTest.h

@ -34,8 +34,8 @@ class SubdivideTest: public QObject {
Vector1(): data(0) {}
Vector1(int i): data(i) {}
int operator[](size_t i) const { return data; }
int& operator[](size_t i) { return data; }
int operator[](size_t) const { return data; }
int& operator[](size_t) { return data; }
bool operator==(Vector1 i) const { return i.data == data; }
Vector1 operator-(Vector1 i) const { return data-i.data; }

11
src/Object.h

@ -178,7 +178,7 @@ class MAGNUM_EXPORT Object {
*
* Default implementation does nothing.
*/
virtual void draw(const Matrix4& transformationMatrix, Camera* camera) {}
virtual void draw(const Matrix4& transformationMatrix, Camera* camera);
/** @{ @name Caching helpers
*
@ -253,9 +253,7 @@ class MAGNUM_EXPORT Object {
* }
* @endcode
*/
virtual inline void clean(const Matrix4& absoluteTransformation) {
dirty = false;
}
virtual void clean(const Matrix4& absoluteTransformation);
/*@}*/
@ -266,6 +264,11 @@ class MAGNUM_EXPORT Object {
bool dirty;
};
/* Implementations for inline functions with unused parameters */
inline void Object::draw(const Matrix4&, Camera*) {}
inline void Object::clean(const Matrix4&) { dirty = false; }
}
#endif

17
src/Physics/CMakeLists.txt

@ -5,14 +5,27 @@ set(MagnumPhysics_SRCS
Line.cpp
Plane.cpp
ShapeGroup.cpp
Sphere.cpp
)
Sphere.cpp)
set(MagnumPhysics_HEADERS
AbstractShape.h
AxisAlignedBox.h
Box.h
Capsule.h
Line.h
LineSegment.h
Plane.h
Point.h
ShapeGroup.h
Sphere.h
magnumPhysicsVisibility.h)
add_library(MagnumPhysics SHARED ${MagnumPhysics_SRCS})
target_link_libraries(MagnumPhysics Magnum)
install(TARGETS MagnumPhysics DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
install(FILES ${MagnumPhysics_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Physics)
if(BUILD_TESTS)
enable_testing()

10
src/Primitives/CMakeLists.txt

@ -3,13 +3,19 @@ set(MagnumPrimitives_SRCS
Cube.cpp
Icosphere.cpp
Plane.cpp
UVSphere.cpp
)
UVSphere.cpp)
set(MagnumPrimitives_HEADERS
Capsule.h
Cube.h
Icosphere.h
Plane.h
UVSphere.h)
add_library(MagnumPrimitives STATIC ${MagnumPrimitives_SRCS})
target_link_libraries(MagnumPrimitives Magnum)
install(TARGETS MagnumPrimitives DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
install(FILES ${MagnumPrimitives_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Primitives)
if(BUILD_TESTS)
enable_testing()

2
src/Scene.h

@ -39,7 +39,7 @@ class MAGNUM_EXPORT Scene: public Object {
void rotate(GLfloat angle, Vector3 vec, Transformation type = Transformation::Global) = delete;
private:
inline virtual void draw(const Magnum::Matrix4& transformationMatrix, Camera* camera) {}
inline void draw(const Magnum::Matrix4&, Camera*) {}
};
}

21
src/Set.h

@ -54,33 +54,17 @@ template<class T, class U> class Set {
/** @brief Create set from one value */
inline constexpr Set(T value): value(static_cast<UnderlyingType>(value)) {}
/** @brief Add value to the set */
inline constexpr Set<T, U> operator|(T other) const {
return Set<T, U>(value | static_cast<UnderlyingType>(other));
}
/** @brief Union of two sets */
inline constexpr Set<T, U> operator|(Set<T, U> other) const {
return Set<T, U>(value | other.value);
}
/** @brief Add value to the set and assign */
inline Set<T, U>& operator|=(T other) {
value |= static_cast<UnderlyingType>(other);
return *this;
}
/** @brief Union two sets and assign */
inline Set<T, U>& operator|=(Set<T, U> other) {
value |= other.value;
return *this;
}
/** @brief Check if given value is in the set */
inline constexpr T operator&(T other) const {
return static_cast<T>(value & static_cast<UnderlyingType>(other));
}
/** @brief Intersection of two sets */
inline constexpr Set<T, U> operator&(Set<T, U> other) const {
return Set<T, U>(value & other.value);
@ -97,6 +81,11 @@ template<class T, class U> class Set {
return Set<T, U>(~value);
}
/** @brief Value as boolean */
inline constexpr explicit operator bool() const {
return value == 0;
}
/** @brief Value in underlying type */
inline constexpr explicit operator UnderlyingType() const {
return value;

14
src/Shaders/CMakeLists.txt

@ -1,11 +1,15 @@
corrade_add_resource(Shaders MagnumShaders PhongShader.frag PhongShader.vert)
set(Shaders_SRCS
corrade_add_resource(MagnumShaders_RCS MagnumShaders PhongShader.frag PhongShader.vert)
set(MagnumShaders_SRCS
PhongShader.cpp
${Shaders}
)
${MagnumShaders_RCS})
set(MagnumShaders_HEADERS
PhongShader.h
add_library(MagnumShaders SHARED ${Shaders_SRCS})
magnumShadersVisibility.h)
add_library(MagnumShaders SHARED ${MagnumShaders_SRCS})
target_link_libraries(MagnumShaders Magnum)
install(TARGETS MagnumShaders DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
install(FILES ${MagnumShaders_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Shaders)

4
src/Trade/AbstractImporter.cpp

@ -19,12 +19,12 @@ using namespace std;
namespace Magnum { namespace Trade {
bool AbstractImporter::open(const std::string& filename) {
bool AbstractImporter::open(const std::string&) {
Error() << plugin() << "doesn't support opening files";
return false;
}
bool AbstractImporter::open(std::istream& in) {
bool AbstractImporter::open(std::istream&) {
Error() << plugin() << "doesn't support opening input streams";
return false;
}

62
src/Trade/AbstractImporter.h

@ -121,7 +121,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
* If no scene for given name exists, returns -1.
* @see SceneData::name()
*/
virtual inline int sceneForName(const std::string& name) { return -1; }
virtual int sceneForName(const std::string& name);
/**
* @brief %Scene
@ -129,7 +129,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
*
* Returns pointer to given scene or nullptr, if no such scene exists.
*/
virtual inline SceneData* scene(unsigned int id) { return nullptr; }
virtual SceneData* scene(unsigned int id);
/** @brief %Light count */
virtual inline unsigned int lightCount() const { return 0; }
@ -140,7 +140,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
* If no light for given name exists, returns -1.
* @see LightData::name()
*/
virtual inline int lightForName(const std::string& name) { return -1; }
virtual int lightForName(const std::string& name);
/**
* @brief %Light
@ -148,7 +148,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
*
* Returns pointer to given light or nullptr, if no such light exists.
*/
virtual inline LightData* light(unsigned int id) { return nullptr; }
virtual LightData* light(unsigned int id);
/** @brief %Camera count */
virtual inline unsigned int cameraCount() const { return 0; }
@ -159,7 +159,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
* If no camera for given name exists, returns -1.
* @see CameraData::name()
*/
virtual inline int cameraForName(const std::string& name) { return -1; }
virtual int cameraForName(const std::string& name);
/**
* @brief %Camera
@ -168,7 +168,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
* Returns pointer to given camera or nullptr, if no such camera
* exists.
*/
virtual inline CameraData* camera(unsigned int id) { return nullptr; }
virtual CameraData* camera(unsigned int id);
/** @brief %Object count */
virtual inline unsigned int objectCount() const { return 0; }
@ -179,7 +179,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
* If no scene for given name exists, returns -1.
* @see ObjectData::name()
*/
virtual inline int objectForName(const std::string& name) { return -1; }
virtual int objectForName(const std::string& name);
/**
* @brief %Object
@ -188,7 +188,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
* Returns pointer to given object or nullptr, if no such object
* exists.
*/
virtual inline ObjectData* object(unsigned int id) { return nullptr; }
virtual ObjectData* object(unsigned int id);
/** @brief %Mesh count */
virtual inline unsigned int meshCount() const { return 0; }
@ -199,7 +199,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
* If no mesh for given name exists, returns -1.
* @see MeshData::name()
*/
virtual inline int meshForName(const std::string& name) { return -1; }
virtual int meshForName(const std::string& name);
/**
* @brief %Mesh
@ -207,7 +207,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
*
* Returns pointer to given mesh or nullptr, if no such mesh exists.
*/
virtual inline MeshData* mesh(unsigned int id) { return nullptr; }
virtual MeshData* mesh(unsigned int id);
/** @brief Material count */
virtual inline unsigned int materialCount() const { return 0; }
@ -218,7 +218,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
* If no material for given name exists, returns -1.
* @see AbstractMaterialData::name()
*/
virtual inline int materialForName(const std::string& name) { return -1; }
virtual int materialForName(const std::string& name);
/**
* @brief Material
@ -227,7 +227,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
* Returns pointer to given material or nullptr, if no such material
* exists.
*/
virtual inline AbstractMaterialData* material(unsigned int id) { return nullptr; }
virtual AbstractMaterialData* material(unsigned int id);
/** @brief %Texture count */
virtual inline unsigned int textureCount() const { return 0; }
@ -238,7 +238,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
* If no texture for given name exists, returns -1.
* @see TextureData::name()
*/
virtual inline int textureForName(const std::string& name) { return -1; }
virtual int textureForName(const std::string& name);
/**
* @brief %Texture
@ -247,7 +247,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
* Returns pointer to given texture or nullptr, if no such texture
* exists.
*/
virtual inline TextureData* texture(unsigned int id) { return nullptr; }
virtual TextureData* texture(unsigned int id);
/** @brief One-dimensional image count */
virtual inline unsigned int image1DCount() const { return 0; }
@ -258,7 +258,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
* If no image for given name exists, returns -1.
* @see ImageData1D::name()
*/
virtual inline int image1DForName(const std::string& name) { return -1; }
virtual int image1DForName(const std::string& name);
/**
* @brief One-dimensional image
@ -266,7 +266,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
*
* Returns pointer to given image or nullptr, if no such image exists.
*/
virtual inline ImageData1D* image1D(unsigned int id) { return nullptr; }
virtual ImageData1D* image1D(unsigned int id);
/** @brief Two-dimensional image count */
virtual inline unsigned int image2DCount() const { return 0; }
@ -277,7 +277,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
* If no image for given name exists, returns -1.
* @see ImageData2D::name()
*/
virtual inline int image2DForName(const std::string& name) { return -1; }
virtual int image2DForName(const std::string& name);
/**
* @brief Two-dimensional image
@ -285,7 +285,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
*
* Returns pointer to given image or nullptr, if no such image exists.
*/
virtual inline ImageData2D* image2D(unsigned int id) { return nullptr; }
virtual ImageData2D* image2D(unsigned int id);
/** @brief Three-dimensional image count */
virtual inline unsigned int image3DCount() const { return 0; }
@ -296,7 +296,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
* If no image for given name exists, returns -1.
* @see ImageData3D::name()
*/
virtual inline int image3DForName(const std::string& name) { return -1; }
virtual int image3DForName(const std::string& name);
/**
* @brief Three-dimensional image
@ -304,13 +304,35 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin {
*
* Returns pointer to given image or nullptr, if no such image exists.
*/
virtual inline ImageData3D* image3D(unsigned int id) { return nullptr; }
virtual ImageData3D* image3D(unsigned int id);
/*@}*/
};
SET_OPERATORS(AbstractImporter::Features)
/* Implementations for inline functions with unused parameters */
inline int AbstractImporter::sceneForName(const std::string&) { return -1; }
inline SceneData* AbstractImporter::scene(unsigned int) { return nullptr; }
inline int AbstractImporter::lightForName(const std::string&) { return -1; }
inline LightData* AbstractImporter::light(unsigned int) { return nullptr; }
inline int AbstractImporter::cameraForName(const std::string&) { return -1; }
inline CameraData* AbstractImporter::camera(unsigned int) { return nullptr; }
inline int AbstractImporter::objectForName(const std::string&) { return -1; }
inline ObjectData* AbstractImporter::object(unsigned int) { return nullptr; }
inline int AbstractImporter::meshForName(const std::string&) { return -1; }
inline MeshData* AbstractImporter::mesh(unsigned int) { return nullptr; }
inline int AbstractImporter::materialForName(const std::string&) { return -1; }
inline AbstractMaterialData* AbstractImporter::material(unsigned int) { return nullptr; }
inline int AbstractImporter::textureForName(const std::string&) { return -1; }
inline TextureData* AbstractImporter::texture(unsigned int) { return nullptr; }
inline int AbstractImporter::image1DForName(const std::string&) { return -1; }
inline ImageData1D* AbstractImporter::image1D(unsigned int) { return nullptr; }
inline int AbstractImporter::image2DForName(const std::string&) { return -1; }
inline ImageData2D* AbstractImporter::image2D(unsigned int) { return nullptr; }
inline int AbstractImporter::image3DForName(const std::string&) { return -1; }
inline ImageData3D* AbstractImporter::image3D(unsigned int) { return nullptr; }
}}
#endif

13
src/Trade/CMakeLists.txt

@ -0,0 +1,13 @@
set(MagnumTrade_HEADERS
AbstractImporter.h
AbstractMaterialData.h
CameraData.h
ImageData.h
LightData.h
MeshData.h
MeshObjectData.h
ObjectData.h
PhongMaterialData.h
SceneData.h
TextureData.h)
install(FILES ${MagnumTrade_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Trade)
Loading…
Cancel
Save