diff --git a/CMakeLists.txt b/CMakeLists.txt index 80e8d9650..c898fe09a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,8 +48,6 @@ cmake_dependent_option(WITH_SHADERS "Build Shaders library" ON "NOT WITH_DEBUGTO cmake_dependent_option(WITH_SHAPES "Build Shapes library" ON "NOT WITH_DEBUGTOOLS" ON) option(WITH_TEXT "Build Text library" ON) cmake_dependent_option(WITH_TEXTURETOOLS "Build TextureTools library" ON "NOT WITH_TEXT;NOT WITH_DISTANCEFIELDCONVERTER" ON) -option(WITH_MAGNUMINFO "Build magnum-info utility" OFF) -cmake_dependent_option(WITH_DISTANCEFIELDCONVERTER "Build magnum-distancefield utility" OFF "NOT TARGET_GLES" OFF) # Application libraries if(CORRADE_TARGET_NACL) @@ -63,6 +61,22 @@ else() option(WITH_SDL2APPLICATION "Build Sdl2Application library" OFF) endif() +# Utilities (currently depending on WindowlessGlxApplication) +if(UNIX OR CORRADE_TARGET_NACL) + option(WITH_MAGNUMINFO "Build magnum-info utility" OFF) +endif() +if(UNIX) + cmake_dependent_option(WITH_FONTCONVERTER "Build magnum-fontconverter utility" OFF "NOT TARGET_GLES" OFF) + cmake_dependent_option(WITH_DISTANCEFIELDCONVERTER "Build magnum-distancefieldconverter utility" OFF "NOT TARGET_GLES" OFF) +endif() + +# Plugins +cmake_dependent_option(WITH_MAGNUMFONT "Build MagnumFont plugin" OFF "WITH_TEXT" OFF) +cmake_dependent_option(WITH_MAGNUMFONTCONVERTER "Build MagnumFontConverter plugin" OFF "NOT MAGNUM_TARGET_GLES;WITH_TEXT" OFF) +cmake_dependent_option(WITH_TGAIMAGECONVERTER "Build TgaImageConverter plugin" OFF "NOT WITH_MAGNUMFONTCONVERTER" ON) +cmake_dependent_option(WITH_TGAIMPORTER "Build TgaImporter plugin" OFF "NOT WITH_MAGNUMFONT" ON) +cmake_dependent_option(WITH_WAVAUDIOIMPORTER "Build WavAudioImporter plugin" OFF "WITH_AUDIO" OFF) + option(BUILD_DEPRECATED "Include deprecated API in the build" ON) if(BUILD_DEPRECATED) set(MAGNUM_BUILD_DEPRECATED 1) @@ -142,9 +156,16 @@ endif() include(CorradeLibSuffix) set(MAGNUM_BINARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin) set(MAGNUM_LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}) +set(MAGNUM_PLUGINS_INSTALL_DIR ${MAGNUM_LIBRARY_INSTALL_DIR}/magnum) +set(MAGNUM_PLUGINS_FONT_INSTALL_DIR ${MAGNUM_PLUGINS_INSTALL_DIR}/fonts) +set(MAGNUM_PLUGINS_FONTCONVERTER_INSTALL_DIR ${MAGNUM_PLUGINS_INSTALL_DIR}/fontconverters) +set(MAGNUM_PLUGINS_IMAGECONVERTER_INSTALL_DIR ${MAGNUM_PLUGINS_INSTALL_DIR}/imageconverters) +set(MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR ${MAGNUM_PLUGINS_INSTALL_DIR}/importers) +set(MAGNUM_PLUGINS_AUDIOIMPORTER_INSTALL_DIR ${MAGNUM_PLUGINS_INSTALL_DIR}/audioimporters) set(MAGNUM_DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/magnum) set(MAGNUM_CMAKE_FIND_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) add_subdirectory(external) add_subdirectory(modules) diff --git a/PKGBUILD b/PKGBUILD index c04bc16ee..9e1cdf500 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -30,6 +30,11 @@ build() { -DWITH_GLUTAPPLICATION=ON \ -DWITH_GLXAPPLICATION=ON \ -DWITH_SDL2APPLICATION=ON \ + -DWITH_MAGNUMFONT=ON \ + -DWITH_MAGNUMFONTCONVERTER=ON \ + -DWITH_TGAIMAGECONVERTER=ON \ + -DWITH_TGAIMPORTER=ON \ + -DWITH_WAVAUDIOIMPORTER=ON \ -DBUILD_TESTS=TRUE \ -G Ninja ninja diff --git a/PKGBUILD-emscripten b/PKGBUILD-emscripten index f80ca8080..30993b1f2 100644 --- a/PKGBUILD-emscripten +++ b/PKGBUILD-emscripten @@ -7,7 +7,7 @@ arch=('any') url="http://mosra.cz/blog/magnum.php" license=('MIT') depends=('emscripten-corrade') -makedepends=('cmake') +makedepends=('cmake' 'ninja') options=(!strip !buildflags) build() { @@ -18,7 +18,8 @@ build() { cmake .. \ -DCMAKE_MODULE_PATH="$startdir/toolchains/modules" \ -DCMAKE_TOOLCHAIN_FILE="$startdir/toolchains/generic/Emscripten.cmake" \ - -DWITH_AUDIO=OFF + -DWITH_AUDIO=OFF \ + -G Ninja fi cd "$startdir/build-emscripten" @@ -27,11 +28,15 @@ build() { -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr/emscripten/system \ -DWITH_AUDIO=OFF \ - -DWITH_SDL2APPLICATION=ON - make + -DWITH_SDL2APPLICATION=ON \ + -DWITH_MAGNUMFONT=ON \ + -DWITH_TGAIMAGECONVERTER=ON \ + -DWITH_TGAIMPORTER=ON \ + -DWITH_WAVAUDIOIMPORTER=ON + ninja } package() { cd "$startdir/build-emscripten" - make DESTDIR="$pkgdir/" install + DESTDIR="$pkgdir/" ninja install } diff --git a/PKGBUILD-es2 b/PKGBUILD-es2 index 79dddbd32..3fdc6db93 100644 --- a/PKGBUILD-es2 +++ b/PKGBUILD-es2 @@ -7,7 +7,7 @@ arch=('i686' 'x86_64') url="https://github.com/mosra/magnum" license=('MIT') depends=('corrade' 'openal') -makedepends=('cmake') +makedepends=('cmake' 'ninja') options=(!strip) provides=('magnum-git') @@ -27,8 +27,13 @@ build() { -DTARGET_GLES=ON \ -DTARGET_GLES2=ON \ -DWITH_MAGNUMINFO=OFF \ - -DWITH_XEGLAPPLICATION=ON - make + -DWITH_XEGLAPPLICATION=ON \ + -DWITH_MAGNUMFONT=ON \ + -DWITH_TGAIMAGECONVERTER=ON \ + -DWITH_TGAIMPORTER=ON \ + -DWITH_WAVAUDIOIMPORTER=ON \ + -G Ninja + ninja } check() { @@ -38,5 +43,5 @@ check() { package() { cd "$startdir/build-es2" - make DESTDIR="$pkgdir/" install + DESTDIR="$pkgdir/" ninja install } diff --git a/PKGBUILD-es2desktop b/PKGBUILD-es2desktop index 9b6eda6fc..ec8961771 100644 --- a/PKGBUILD-es2desktop +++ b/PKGBUILD-es2desktop @@ -7,7 +7,7 @@ arch=('i686' 'x86_64') url="https://github.com/mosra/magnum" license=('MIT') depends=('corrade' 'openal') -makedepends=('cmake') +makedepends=('cmake' 'ninja') options=(!strip) provides=('magnum-git') @@ -29,8 +29,13 @@ build() { -DTARGET_DESKTOP_GLES=ON \ -DWITH_MAGNUMINFO=ON \ -DWITH_GLXAPPLICATION=ON \ - -DWITH_WINDOWLESSGLXAPPLICATION=ON - make + -DWITH_WINDOWLESSGLXAPPLICATION=ON \ + -DWITH_MAGNUMFONT=ON \ + -DWITH_TGAIMAGECONVERTER=ON \ + -DWITH_TGAIMPORTER=ON \ + -DWITH_WAVAUDIOIMPORTER=ON \ + -G Ninja + ninja } check() { @@ -40,5 +45,5 @@ check() { package() { cd "$startdir/build-es2desktop" - make DESTDIR="$pkgdir/" install + DESTDIR="$pkgdir/" ninja install } diff --git a/PKGBUILD-es3 b/PKGBUILD-es3 index d9297b4c7..1182f880c 100644 --- a/PKGBUILD-es3 +++ b/PKGBUILD-es3 @@ -7,7 +7,7 @@ arch=('i686' 'x86_64') url="https://github.com/mosra/magnum" license=('MIT') depends=('corrade' 'openal') -makedepends=('cmake') +makedepends=('cmake' 'ninja') options=(!strip) provides=('magnum-git') @@ -27,8 +27,13 @@ build() { -DTARGET_GLES=ON \ -DTARGET_GLES2=OFF \ -DWITH_MAGNUMINFO=OFF \ - -DWITH_XEGLAPPLICATION=ON - make + -DWITH_XEGLAPPLICATION=ON \ + -DWITH_MAGNUMFONT=ON \ + -DWITH_TGAIMAGECONVERTER=ON \ + -DWITH_TGAIMPORTER=ON \ + -DWITH_WAVAUDIOIMPORTER=ON \ + -G Ninja + ninja } check() { @@ -38,5 +43,5 @@ check() { package() { cd "$startdir/build-es3" - make DESTDIR="$pkgdir/" install + DESTDIR="$pkgdir/" ninja install } diff --git a/PKGBUILD-gcc46 b/PKGBUILD-gcc46 new file mode 100644 index 000000000..4912b65e7 --- /dev/null +++ b/PKGBUILD-gcc46 @@ -0,0 +1,49 @@ +# Author: mosra +pkgname=magnum +pkgver=dev.gcc46 +pkgrel=1 +pkgdesc="C++11 and OpenGL 2D/3D graphics engine (built with GCC 4.6)" +arch=('i686' 'x86_64') +url="https://github.com/mosra/magnum" +license=('MIT') +depends=('corrade' 'openal' 'freeglut' 'sdl2') +makedepends=('cmake' 'ninja' 'gcc46') +options=(!strip) +provides=('magnum-git') + +build() { + if [ ! -d "$startdir/build-gcc46" ] ; then + mkdir "$startdir/build-gcc46" + cd "$startdir/build-gcc46" + + cmake .. \ + -DCMAKE_CXX_COMPILER=g++-4.6 \ + -G Ninja + fi + + cd "$startdir/build-gcc46" + + cmake .. \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DWITH_GLUTAPPLICATION=ON \ + -DWITH_GLXAPPLICATION=ON \ + -DWITH_SDL2APPLICATION=ON \ + -DWITH_MAGNUMFONT=ON \ + -DWITH_MAGNUMFONTCONVERTER=ON \ + -DWITH_TGAIMAGECONVERTER=ON \ + -DWITH_TGAIMPORTER=ON \ + -DWITH_WAVAUDIOIMPORTER=ON \ + -DBUILD_TESTS=TRUE + ninja +} + +check() { + cd "$startdir/build-gcc46" + ctest --output-on-failure +} + +package() { + cd "$startdir/build-gcc46" + DESTDIR="$pkgdir/" ninja install +} diff --git a/PKGBUILD-gcc47 b/PKGBUILD-gcc47 new file mode 100644 index 000000000..64b6b4d7b --- /dev/null +++ b/PKGBUILD-gcc47 @@ -0,0 +1,49 @@ +# Author: mosra +pkgname=magnum +pkgver=dev.gcc47 +pkgrel=1 +pkgdesc="C++11 and OpenGL 2D/3D graphics engine (built with GCC 4.7)" +arch=('i686' 'x86_64') +url="https://github.com/mosra/magnum" +license=('MIT') +depends=('corrade' 'openal' 'freeglut' 'sdl2') +makedepends=('cmake' 'ninja' 'gcc47') +options=(!strip) +provides=('magnum-git') + +build() { + if [ ! -d "$startdir/build-gcc47" ] ; then + mkdir "$startdir/build-gcc47" + cd "$startdir/build-gcc47" + + cmake .. \ + -DCMAKE_CXX_COMPILER=g++-4.7 \ + -G Ninja + fi + + cd "$startdir/build-gcc47" + + cmake .. \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DWITH_GLUTAPPLICATION=ON \ + -DWITH_GLXAPPLICATION=ON \ + -DWITH_SDL2APPLICATION=ON \ + -DWITH_MAGNUMFONT=ON \ + -DWITH_MAGNUMFONTCONVERTER=ON \ + -DWITH_TGAIMAGECONVERTER=ON \ + -DWITH_TGAIMPORTER=ON \ + -DWITH_WAVAUDIOIMPORTER=ON \ + -DBUILD_TESTS=TRUE + ninja +} + +check() { + cd "$startdir/build-gcc47" + ctest --output-on-failure +} + +package() { + cd "$startdir/build-gcc47" + DESTDIR="$pkgdir/" ninja install +} diff --git a/PKGBUILD-mingw32 b/PKGBUILD-mingw32 index 460c6f938..a168e4c5c 100644 --- a/PKGBUILD-mingw32 +++ b/PKGBUILD-mingw32 @@ -7,7 +7,7 @@ arch=('any') url="https://github.com/mosra/magnum" license=('MIT') depends=('mingw32-runtime' 'mingw32-corrade' 'mingw32-freeglut' 'mingw32-openal') -makedepends=('mingw32-gcc' 'cmake' 'corrade') +makedepends=('mingw32-gcc' 'cmake' 'ninja' 'corrade') options=(!buildflags !strip) build() { @@ -20,11 +20,17 @@ build() { -DCMAKE_TOOLCHAIN_FILE=../toolchains/archlinux/basic-mingw32.cmake \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr/i486-mingw32 \ - -DWITH_GLUTAPPLICATION=ON - make + -DWITH_GLUTAPPLICATION=ON \ + -DWITH_MAGNUMFONT=ON \ + -DWITH_MAGNUMFONTCONVERTER=ON \ + -DWITH_TGAIMAGECONVERTER=ON \ + -DWITH_TGAIMPORTER=ON \ + -DWITH_WAVAUDIOIMPORTER=ON \ + -G Ninja + ninja } package() { cd "$startdir/build-win" - make DESTDIR="$pkgdir/" install + DESTDIR="$pkgdir/" ninja install } diff --git a/PKGBUILD-nacl-glibc b/PKGBUILD-nacl-glibc index 05fd46e88..72c00cdd7 100644 --- a/PKGBUILD-nacl-glibc +++ b/PKGBUILD-nacl-glibc @@ -7,7 +7,7 @@ arch=('any') url="https://github.com/mosra/magnum" license=('MIT') depends=('nacl-corrade') -makedepends=('nacl-sdk' 'cmake') +makedepends=('nacl-sdk' 'cmake' 'corrade' 'ninja') options=(!buildflags !strip) build() { @@ -22,8 +22,14 @@ build() { -DCMAKE_INSTALL_PREFIX=/usr/nacl \ -DWITH_MAGNUMINFO=OFF \ -DWITH_NACLAPPLICATION=ON \ - -DLIB_SUFFIX=/32 - make + -DWITH_MAGNUMFONT=ON \ + -DWITH_MAGNUMFONTCONVERTER=ON \ + -DWITH_TGAIMAGECONVERTER=ON \ + -DWITH_TGAIMPORTER=ON \ + -DWITH_WAVAUDIOIMPORTER=ON \ + -DLIB_SUFFIX=/32 \ + -G Ninja + ninja # Build 64bit mkdir -p "$startdir/build-nacl-glibc-x86-64" @@ -35,17 +41,23 @@ build() { -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr/nacl \ -DWITH_MAGNUMINFO=OFF \ - -DWITH_NACLAPPLICATION=ON - make + -DWITH_NACLAPPLICATION=ON \ + -DWITH_MAGNUMFONT=ON \ + -DWITH_MAGNUMFONTCONVERTER=ON \ + -DWITH_TGAIMAGECONVERTER=ON \ + -DWITH_TGAIMPORTER=ON \ + -DWITH_WAVAUDIOIMPORTER=ON \ + -G Ninja + ninja } package() { # Install 32bit cd "$startdir/build-nacl-glibc-x86-32" - make DESTDIR="$pkgdir/" install + DESTDIR="$pkgdir/" ninja install # Install 64bit (the headers will be overwritten, but they are (and should # be) the same for both versions cd "$startdir/build-nacl-glibc-x86-64" - make DESTDIR="$pkgdir/" install + DESTDIR="$pkgdir/" ninja install } diff --git a/PKGBUILD-nacl-newlib b/PKGBUILD-nacl-newlib index 35b96cf8d..a92e6e7c2 100644 --- a/PKGBUILD-nacl-newlib +++ b/PKGBUILD-nacl-newlib @@ -7,7 +7,7 @@ arch=('any') url="https://github.com/mosra/magnum" license=('MIT') depends=('nacl-corrade') -makedepends=('nacl-sdk' 'cmake') +makedepends=('nacl-sdk' 'cmake' 'corrade' 'ninja') options=(!buildflags !strip) build() { @@ -24,8 +24,14 @@ build() { -DWITH_MAGNUMINFO=ON \ -DWITH_NACLAPPLICATION=ON \ -DWITH_WINDOWLESSNACLAPPLICATION=ON \ - -DLIB_SUFFIX=/32 - make + -DWITH_MAGNUMFONT=ON \ + -DWITH_MAGNUMFONTCONVERTER=ON \ + -DWITH_TGAIMAGECONVERTER=ON \ + -DWITH_TGAIMPORTER=ON \ + -DWITH_WAVAUDIOIMPORTER=ON \ + -DLIB_SUFFIX=/32 \ + -G Ninja + ninja # Build 64bit mkdir -p "$startdir/build-nacl-newlib-x86-64" @@ -39,14 +45,20 @@ build() { -DWITH_AUDIO=OFF \ -DWITH_MAGNUMINFO=ON \ -DWITH_NACLAPPLICATION=ON \ - -DWITH_WINDOWLESSNACLAPPLICATION=ON - make + -DWITH_WINDOWLESSNACLAPPLICATION=ON \ + -DWITH_MAGNUMFONT=ON \ + -DWITH_MAGNUMFONTCONVERTER=ON \ + -DWITH_TGAIMAGECONVERTER=ON \ + -DWITH_TGAIMPORTER=ON \ + -DWITH_WAVAUDIOIMPORTER=ON \ + -G Ninja + ninja } package() { # Install 32bit cd "$startdir/build-nacl-newlib-x86-32" - make DESTDIR="$pkgdir/" install + DESTDIR="$pkgdir/" ninja install # Strip 32bit binaries /usr/nacl/toolchain/linux_x86_newlib/bin/i686-nacl-strip ${pkgdir}/usr/nacl/bin/*x86-32.nexe @@ -54,7 +66,7 @@ package() { # Install 64bit (the headers will be overwritten, but they are (and should # be) the same for both versions cd "$startdir/build-nacl-newlib-x86-64" - make DESTDIR="$pkgdir/" install + DESTDIR="$pkgdir/" ninja install # Strip 64bit binaries /usr/nacl/toolchain/linux_x86_newlib/bin/x86_64-nacl-strip ${pkgdir}/usr/nacl/bin/*x86-64.nexe diff --git a/PKGBUILD-release b/PKGBUILD-release index 8d46bfea6..1d41b3cfe 100644 --- a/PKGBUILD-release +++ b/PKGBUILD-release @@ -7,7 +7,7 @@ arch=('i686' 'x86_64') url="https://github.com/mosra/magnum" license=('MIT') depends=('corrade' 'openal' 'sdl2' 'freeglut') -makedepends=('cmake') +makedepends=('cmake' 'ninja') provides=('magnum-git') build() { @@ -24,9 +24,15 @@ build() { -DCMAKE_INSTALL_PREFIX=/usr \ -DWITH_GLUTAPPLICATION=ON \ -DWITH_GLXAPPLICATION=ON \ - -DWITH_SDL2APPLICATION=ON - -DBUILD_TESTS=TRUE - make + -DWITH_SDL2APPLICATION=ON \ + -DWITH_MAGNUMFONT=ON \ + -DWITH_MAGNUMFONTCONVERTER=ON \ + -DWITH_TGAIMAGECONVERTER=ON \ + -DWITH_TGAIMPORTER=ON \ + -DWITH_WAVAUDIOIMPORTER=ON \ + -DBUILD_TESTS=TRUE \ + -G Ninja + ninja } check() { @@ -36,5 +42,5 @@ check() { package() { cd "$startdir/build" - make DESTDIR="$pkgdir/" install + DESTDIR="$pkgdir/" ninja install } diff --git a/doc/best-practices.dox b/doc/best-practices.dox index 1d64c1929..2b04dffe9 100644 --- a/doc/best-practices.dox +++ b/doc/best-practices.dox @@ -57,17 +57,17 @@ information. - [Best practices for 3D graphics](https://developers.google.com/native-client/beta/devguide/coding/3D-graphics#best-practices) -@subsubsection best-practices-nacl-buffer-types Native Client requires unique buffer binding +@subsection best-practices-web-buffer-types Native Client and Emscripten require unique buffer binding -As noted in the above link, buffers in NaCl implementation need to be bound -only to one unique target, i.e., @ref Buffer bound to @ref Buffer::Target::Array -cannot be later rebound to @ref Buffer::Target::ElementArray. However, %Magnum -by default uses any sufficient target when binding the buffer internally (e.g. -for setting data or copying). To avoid this, set target hint to desired target, -either in constructor or using @ref Buffer::setTargetHint(). +As noted in the above link, buffers in NaCl implementation and and also in +WebGL need to be bound only to one unique target, i.e., @ref Buffer bound to +@ref Buffer::Target::Array cannot be later rebound to @ref Buffer::Target::ElementArray. +However, %Magnum by default uses any sufficient target when binding the buffer +internally (e.g. for setting data or copying). To avoid this, set target hint +to desired target, either in constructor or using @ref Buffer::setTargetHint(). To ease up the development, @ref Mesh checks proper target hint when adding -vertex and index buffers. +vertex and index buffers in both Native Client and Emscripten. @section best-practices-hw Hardware-specific diff --git a/doc/building.dox b/doc/building.dox index 800f3c569..c0ee2f5e0 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -136,44 +136,67 @@ CMake and C++ sources, see @ref cmake and @ref src/Magnum.h for more information. See also @ref corrade-cmake and @ref src/Corrade.h for additional information. -By default the engine is built with nearly everything except Audio library and -application libraries (see below). Using `WITH_*` CMake parameters you can -specify which parts will be built and which not: - - - `WITH_AUDIO` - Audio library. Depends on **OpenAL** library, not built by - default. - - `WITH_DEBUGTOOLS` - DebugTools library. Enables also building of MeshTools, - Primitives, SceneGraph, Shaders and Shapes libraries. - - `WITH_MESHTOOLS` - MeshTools library. Enabled automatically if `WITH_DEBUGTOOLS` - is enabled. - - `WITH_PRIMITIVES` - Primitives library. Enabled automatically if `WITH_DEBUGTOOLS` - is enabled. - - `WITH_SCENEGRAPH` - SceneGraph library. Enabled automatically if `WITH_DEBUGTOOLS` - or `WITH_SHAPES` is enabled. - - `WITH_SHADERS` - Shaders library. Enabled automatically if `WITH_DEBUGTOOLS` - is enabled. - - `WITH_SHAPES` - Shapes library. Enables also building of SceneGraph library. - Enabled automatically if `WITH_DEBUGTOOLS` is enabled. - - `WITH_TEXT` - Text library. Enables also building of TextureTools library. - - `WITH_TEXTURETOOLS` - TextureTools library. Enabled automatically if `WITH_TEXT` - or `WITH_DISTANCEFIELDCONVERTER` is enabled. - - `WITH_MAGNUMINFO` - `magnum-info` executable, provides information about the - engine and OpenGL capabilities. - - `WITH_DISTANCEFIELDCONVERTER` - `magnum-distancefield` executable for - converting black&white images to distance field textures. Enables also - building of TextureTools library. +By default the engine is built with nearly everything except Audio library, +plugins and application libraries (see below). Using `WITH_*` CMake parameters +you can specify which parts will be built and which not: + +- `WITH_AUDIO` - Audio library. Depends on **OpenAL** library, not built by + default. +- `WITH_DEBUGTOOLS` - DebugTools library. Enables also building of MeshTools, + Primitives, SceneGraph, Shaders and Shapes libraries. +- `WITH_MESHTOOLS` - MeshTools library. Enabled automatically if + `WITH_DEBUGTOOLS` is enabled. +- `WITH_PRIMITIVES` - Primitives library. Enabled automatically if + `WITH_DEBUGTOOLS` is enabled. +- `WITH_SCENEGRAPH` - SceneGraph library. Enabled automatically if + `WITH_DEBUGTOOLS` or `WITH_SHAPES` is enabled. +- `WITH_SHADERS` - Shaders library. Enabled automatically if `WITH_DEBUGTOOLS` + is enabled. +- `WITH_SHAPES` - Shapes library. Enables also building of SceneGraph + library. Enabled automatically if `WITH_DEBUGTOOLS` is enabled. +- `WITH_TEXT` - Text library. Enables also building of TextureTools library. +- `WITH_TEXTURETOOLS` - TextureTools library. Enabled automatically if + `WITH_TEXT` or `WITH_DISTANCEFIELDCONVERTER` is enabled. None of the @ref Platform "application libraries" is built by default (and you need at least one). Choose the one which suits your requirements and your platform best: -- `WITH_GLUTAPPLICATION` - @ref Platform::GlutApplication "GlutApplication" -- `WITH_GLXAPPLICATION` - @ref Platform::GlxApplication "GlxApplication" -- `WITH_NACLAPPLICATION` - @ref Platform::NaClApplication "NaClApplication" -- `WITH_SDL2APPLICATION` - @ref Platform::Sdl2Application "Sdl2Application" -- `WITH_XEGLAPPLICATION` - @ref Platform::XEglApplication "XEglApplication" -- `WITH_WINDOWLESSGLXAPPLICATION` - @ref Platform::WindowlessGlxApplication "WindowlessGlxApplication" -- `WITH_WINDOWLESSNACLAPPLICATION` - @ref Platform::WindowlessNaClApplication "WindowlessNaClApplication" +- `WITH_GLUTAPPLICATION` - @ref Platform::GlutApplication "GlutApplication" +- `WITH_GLXAPPLICATION` - @ref Platform::GlxApplication "GlxApplication" +- `WITH_NACLAPPLICATION` - @ref Platform::NaClApplication "NaClApplication" +- `WITH_SDL2APPLICATION` - @ref Platform::Sdl2Application "Sdl2Application" +- `WITH_XEGLAPPLICATION` - @ref Platform::XEglApplication "XEglApplication" +- `WITH_WINDOWLESSGLXAPPLICATION` - @ref Platform::WindowlessGlxApplication "WindowlessGlxApplication" +- `WITH_WINDOWLESSNACLAPPLICATION` - @ref Platform::WindowlessNaClApplication "WindowlessNaClApplication" + +There are also a few command-line utilities. They are currently available only +on Linux and are disabled by default: + +- `WITH_MAGNUMINFO` - `magnum-info` executable, provides information about + the engine and OpenGL capabilities. +- `WITH_FONTCONVERTER` - `magnum-fontconverter` executable for converting + fonts to raster ones. Enables also building of Text library. +- `WITH_DISTANCEFIELDCONVERTER` - `magnum-distancefieldconverter` executable + for converting black&white images to distance field textures. Enables also + building of TextureTools library. + +Magnum also contains a set of dependency-less plugins for importing essential +file formats. Additional plugins are provided in separate plugin repository, +see @ref building-plugins for more information. None of the plugins is built by +default. + +- `WITH_MAGNUMFONT` -- @ref Text::MagnumFont "MagnumFont" plugin. Available + only if `WITH_TEXT` is enabled. Enables also building of + @ref Trade::TgaImporter "TgaImporter" plugin. +- `WITH_MAGNUMFONTCONVERTER` -- @ref Text::MagnumFontConverter "MagnumFontConverter" + plugin. Available only if `WITH_TEXT` is enabled. Enables also building of + @ref Trade::TgaImageConverter "TgaImageConverter" plugin. +- `WITH_TGAIMPORTER` -- @ref Trade::TgaImporter "TgaImporter" plugin. +- `WITH_TGAIMAGECONVERTER` -- @ref Trade::TgaImageConverter "TgaImageConverter" + plugin. +- `WITH_WAVAUDIOIMPORTER` -- @ref Audio::WavImporter "WavAudioImporter" + plugin. Available only if `WITH_AUDIO` is enabled. Note that [each namespace](namespaces.html) and all @ref Platform libraries contain more detailed information about dependencies, availability on diff --git a/doc/cmake.dox b/doc/cmake.dox index fbea44ae0..ae37c4cc5 100644 --- a/doc/cmake.dox +++ b/doc/cmake.dox @@ -40,42 +40,71 @@ Basic usage is: This command tries to find base %Magnum library and then defines these variables: -- `MAGNUM_FOUND` -- Whether the library was found -- `MAGNUM_LIBRARIES` -- %Magnum library and dependent libraries -- `MAGNUM_INCLUDE_DIRS` -- Root include dir and include dirs of dependencies -- `MAGNUM_PLUGINS_FONT_DIR` -- Directory with font plugins -- `MAGNUM_PLUGINS_IMPORTER_DIR` -- Directory with importer plugins +- `MAGNUM_FOUND` -- Whether the library was found +- `MAGNUM_LIBRARIES` -- %Magnum library and dependent libraries +- `MAGNUM_INCLUDE_DIRS` -- Root include dir and include dirs of dependencies +- `MAGNUM_PLUGINS_DIR` -- Base directory with plugins. You can modify it + (e.g. set it to `.` when deploying on Windows with plugins stored + relatively to the executable), the following `MAGNUM_PLUGINS_*_DIR` + variables depend on it. +- `MAGNUM_PLUGINS_INCLUDE_DIR -- Include dir with plugins +- `MAGNUM_PLUGINS_FONT_DIR` -- Directory with font plugins +- `MAGNUM_PLUGINS_FONTCONVERTER_DIR` -- Directory with font converter plugins +- `MAGNUM_PLUGINS_IMAGECONVERTER_DIR` -- Directory with image converter + plugins +- `MAGNUM_PLUGINS_IMPORTER_DIR` -- Directory with importer plugins +- `MAGNUM_PLUGINS_AUDIOIMPORTER_DIR` -- Directory with audio importer plugins However, this command will try to find only the base library, not the optional components. The base library depends on %Corrade and OpenGL libraries (or OpenGL ES libraries). Additional dependencies are specified by the components. The optional components are: -- `%Audio` -- Audio library -- `%DebugTools` -- DebugTools library (depends on `%MeshTools`, - `%Primitives`, `%SceneGraph`, `%Shaders` and `%Shapes` components) -- `%MeshTools` -- MeshTools library -- `%Primitives` -- Primitives library -- `%SceneGraph` -- SceneGraph library -- `%Shaders` -- Shaders library -- `%Shapes` -- Shapes library (depends on `%SceneGraph` component) -- `%Text` -- Text library (depends on `%TextureTools` component) -- `%TextureTools` -- TextureTools library +- `%Audio` -- Audio library +- `%DebugTools` -- DebugTools library (depends on `%MeshTools`, + `%Primitives`, `%SceneGraph`, `%Shaders` and `%Shapes` components) +- `%MeshTools` -- MeshTools library +- `%Primitives` -- Primitives library +- `%SceneGraph` -- SceneGraph library +- `%Shaders` -- Shaders library +- `%Shapes` -- Shapes library (depends on `%SceneGraph` component) +- `%Text` -- Text library (depends on `%TextureTools` component) +- `%TextureTools` -- TextureTools library Platform namespace is split into more components: -- `%GlutApplication` -- @ref Platform::GlutApplication "GlutApplication" -- `%GlxApplication` -- @ref Platform::GlxApplication "GlxApplication" -- `%NaClApplication` -- @ref Platform::NaClApplication "NaClApplication" -- `%Sdl2Application` -- @ref Platform::Sdl2Application "Sdl2Application" -- `%XEglApplication` -- @ref Platform::XEglApplication "XEglApplication" -- `%WindowlessNaClApplication` -- @ref Platform::WindowlessNaClApplication "WindowlessNaClApplication" -- `%WindowlessGlxApplication` -- @ref Platform::WindowlessGlxApplication "WindowlessGlxApplication" - -Note that [each namespace](namespaces.html) and all @ref Platform libraries -contain more detailed information about dependencies, availability on -particular platform and also guide how to enable given library in build and use -it with CMake. +- `%GlutApplication` -- @ref Platform::GlutApplication "GlutApplication" +- `%GlxApplication` -- @ref Platform::GlxApplication "GlxApplication" +- `%NaClApplication` -- @ref Platform::NaClApplication "NaClApplication" +- `%Sdl2Application` -- @ref Platform::Sdl2Application "Sdl2Application" +- `%XEglApplication` -- @ref Platform::XEglApplication "XEglApplication" +- `%WindowlessGlxApplication` -- @ref Platform::WindowlessGlxApplication "WindowlessGlxApplication" +- `%WindowlessNaClApplication` -- @ref Platform::WindowlessNaClApplication "WindowlessNaClApplication" + +The library also contains a set of plugins for importing essential file +formats. Additional plugins are provided in separate plugin repository, see +@ref cmake-plugins for more information. If you are going to use dynamic +plugins (the default) via plugin manager, they don't need to be handled via +CMake. The manager will look for them at runtime at specified location and +loads them dynamically. However, if they are built as static (see +@ref building-plugins for more information), they need to be linked into the +executable and then explicitly imported. Also if you are going to use them as +dependencies, you need to find the dependency and then link to it. + +- `MagnumFont` -- @ref Text::MagnumFont "MagnumFont" plugin (depends on + `%Text` component and `TgaImporter` plugin) +- `MagnumFontConverter` -- @ref Text::MagnumFontConverter "MagnumFontConverter" + plugin (depends on `%Text` component and `%TgaImageConverter` plugin) +- `TgaImageConverter` -- @ref Trade::TgaImageConverter "TgaImageConverter" + plugin +- `TgaImporter` -- @ref Trade::TgaImporter "TgaImporter" plugin +- `WavAudioImporter` -- @ref Audio::WavImporter "WavAudioImporter" plugin + (depends on `%Audio` component) + +Note that [each namespace](namespaces.html), all @ref Platform libraries and +each plugin class contain more detailed information about dependencies, +availability on particular platform and also guide how to enable given library +in build and use it with CMake. Example usage with specifying additional components is: @@ -83,9 +112,9 @@ Example usage with specifying additional components is: For each component is then defined: -- `MAGNUM_*_FOUND` -- Whether the component was found -- `MAGNUM_*_LIBRARIES` -- Component library and dependent libraries -- `MAGNUM_*_INCLUDE_DIRS` -- Include dirs of module dependencies +- `MAGNUM_*_FOUND` -- Whether the component was found +- `MAGNUM_*_LIBRARIES` -- Component library and dependent libraries +- `MAGNUM_*_INCLUDE_DIRS` -- Include dirs of module dependencies If exactly one `*Application` or exactly one `Windowless*Application` component is requested and found, its libraries and include dirs are available in @@ -96,15 +125,15 @@ convenience aliases `MAGNUM_APPLICATION_LIBRARIES` / Features of found %Magnum library are exposed in these CMake variables, they are also available as preprocessor variables if including Magnum.h: -- `MAGNUM_BUILD_DEPRECATED` -- Defined if compiled with deprecated APIs - included -- `MAGNUM_BUILD_STATIC` -- Defined if built as static libraries. Default are - shared libraries. -- `MAGNUM_TARGET_GLES` -- Defined if compiled for OpenGL ES -- `MAGNUM_TARGET_GLES2` -- Defined if compiled for OpenGL ES 2.0 -- `MAGNUM_TARGET_GLES3` -- Defined if compiled for OpenGL ES 3.0 -- `MAGNUM_TARGET_DESKTOP_GLES` -- Defined if compiled with OpenGL ES emulation - on desktop OpenGL +- `MAGNUM_BUILD_DEPRECATED` -- Defined if compiled with deprecated APIs + included +- `MAGNUM_BUILD_STATIC` -- Defined if built as static libraries. Default are + shared libraries. +- `MAGNUM_TARGET_GLES` -- Defined if compiled for OpenGL ES +- `MAGNUM_TARGET_GLES2` -- Defined if compiled for OpenGL ES 2.0 +- `MAGNUM_TARGET_GLES3` -- Defined if compiled for OpenGL ES 3.0 +- `MAGNUM_TARGET_DESKTOP_GLES` -- Defined if compiled with OpenGL ES + emulation on desktop OpenGL %Corrade library provides also its own set of CMake macros and variables, see @ref corrade-cmake "its documentation" for more information. diff --git a/doc/namespaces.dox b/doc/namespaces.dox index 043c7676e..d24c2076a 100644 --- a/doc/namespaces.dox +++ b/doc/namespaces.dox @@ -139,6 +139,10 @@ library, you need to request `%MeshTools` component in CMake and link to information. */ +/** @dir Plugins + * @brief Basic plugins + */ + /** @dir Primitives * @brief Namespace Magnum::Primitives */ diff --git a/external/OpenGL/GL/gl_magnum.c b/external/OpenGL/GL/gl_magnum.c index 3276c865c..7de5af8a4 100644 --- a/external/OpenGL/GL/gl_magnum.c +++ b/external/OpenGL/GL/gl_magnum.c @@ -2605,19 +2605,6 @@ static ogl_StrToExtMap ExtensionMap[8] = { static int g_extensionMapSize = 8; -static ogl_StrToExtMap *FindExtEntry(const char *extensionName) -{ - int loop; - ogl_StrToExtMap *currLoc = ExtensionMap; - for(loop = 0; loop < g_extensionMapSize; ++loop, ++currLoc) - { - if(strcmp(extensionName, currLoc->extensionName) == 0) - return currLoc; - } - - return NULL; -} - static void ClearExtensionVars() { ogl_ext_AMD_vertex_shader_layer = ogl_LOAD_FAILED; @@ -2630,65 +2617,29 @@ static void ClearExtensionVars() ogl_ext_GREMEDY_string_marker = ogl_LOAD_FAILED; } - -static void LoadExtByName(const char *extensionName) -{ - ogl_StrToExtMap *entry = NULL; - entry = FindExtEntry(extensionName); - if(entry) - { - if(entry->LoadExtension) - { - int numFailed = entry->LoadExtension(); - if(numFailed == 0) - { - *(entry->extensionVariable) = ogl_LOAD_SUCCEEDED; - } - else - { - *(entry->extensionVariable) = ogl_LOAD_SUCCEEDED + numFailed; - } - } - else - { - *(entry->extensionVariable) = ogl_LOAD_SUCCEEDED; - } - } -} - - -static void ProcExtsFromExtString(const char *strExtList) +static void LoadExts() { - size_t iExtListLen = strlen(strExtList); - const char *strExtListEnd = strExtList + iExtListLen; - const char *strCurrPos = strExtList; - char strWorkBuff[256]; - - while(*strCurrPos) - { - /*Get the extension at our position.*/ - int iStrLen = 0; - const char *strEndStr = strchr(strCurrPos, ' '); - int iStop = 0; - if(strEndStr == NULL) - { - strEndStr = strExtListEnd; - iStop = 1; - } - - iStrLen = (int)((ptrdiff_t)strEndStr - (ptrdiff_t)strCurrPos); - - if(iStrLen > 255) - return; - - strncpy(strWorkBuff, strCurrPos, iStrLen); - strWorkBuff[iStrLen] = '\0'; - - LoadExtByName(strWorkBuff); - - strCurrPos = strEndStr + 1; - if(iStop) break; - } + int loop; + ogl_StrToExtMap *entry = ExtensionMap; + for(loop = 0; loop < g_extensionMapSize; ++loop, ++entry) + { + if(entry->LoadExtension) + { + int numFailed = entry->LoadExtension(); + if(numFailed == 0) + { + *(entry->extensionVariable) = ogl_LOAD_SUCCEEDED; + } + else + { + *(entry->extensionVariable) = ogl_LOAD_SUCCEEDED + numFailed; + } + } + else + { + *(entry->extensionVariable) = ogl_LOAD_SUCCEEDED; + } + } } int ogl_LoadFunctions() @@ -2696,10 +2647,7 @@ int ogl_LoadFunctions() int numFailed = 0; ClearExtensionVars(); - _ptrc_glGetString = (const GLubyte * (CODEGEN_FUNCPTR *)(GLenum))IntGetProcAddress("glGetString"); - if(!_ptrc_glGetString) return ogl_LOAD_FAILED; - - ProcExtsFromExtString((const char *)_ptrc_glGetString(GL_EXTENSIONS)); + LoadExts(); numFailed = Load_Version_4_4(); if(numFailed == 0) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index c6223bf79..4991b5758 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -7,6 +7,7 @@ # MAGNUM_LIBRARIES - Magnum library and dependent libraries # MAGNUM_INCLUDE_DIRS - Root include dir and include dirs of # dependencies +# MAGNUM_PLUGINS_INCLUDE_DIR - Include dir with plugins # MAGNUM_PLUGINS_DIR - Base directory with plugins. You can modify # it (e.g. set it to `.` when deploying on Windows with plugins stored # relatively to the executable), the following MAGNUM_PLUGINS_*_DIR @@ -30,13 +31,20 @@ # Shapes - Shapes library (depends on SceneGraph component) # Text - Text library (depends on TextureTools component) # TextureTools - TextureTools library +# MagnumFont - Magnum bitmap font plugin (depends on Text component +# and TgaImporter plugin) +# MagnumFontConverter - Magnum bitmap font converter plugin (depends on Text +# component and TgaImageConverter plugin) +# TgaImageConverter - TGA image converter plugin +# TgaImporter - TGA importer plugin +# WavAudioImporter - WAV audio importer plugin (depends on Audio component) # GlutApplication - GLUT application # GlxApplication - GLX application # NaClApplication - NaCl application # Sdl2Application - SDL2 application # XEglApplication - X/EGL application -# WindowlessNaClApplication - Windowless NaCl application # WindowlessGlxApplication - Windowless GLX application +# WindowlessNaClApplication - Windowless NaCl application # Example usage with specifying additional components is: # find_package(Magnum [REQUIRED|COMPONENTS] # MeshTools Primitives GlutApplication) @@ -167,15 +175,66 @@ endif() foreach(component ${Magnum_FIND_COMPONENTS}) string(TOUPPER ${component} _COMPONENT) - # Find the library - find_library(MAGNUM_${_COMPONENT}_LIBRARY Magnum${component}) + # AudioImporter plugin specific name suffixes + if(${component} MATCHES ".+AudioImporter$") + set(_MAGNUM_${_COMPONENT}_IS_PLUGIN 1) + set(_MAGNUM_${_COMPONENT}_PATH_SUFFIX audioimporters) + + # Audio importer class is Audio::*Importer, thus we need to convert + # *AudioImporter.h to *Importer.h + string(REPLACE "AudioImporter" "Importer" _MAGNUM_${_COMPONENT}_HEADER_NAME "${component}") + set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${_MAGNUM_${_COMPONENT}_HEADER_NAME}.h) + + # Importer plugin specific name suffixes + elseif(${component} MATCHES ".+Importer$") + set(_MAGNUM_${_COMPONENT}_IS_PLUGIN 1) + set(_MAGNUM_${_COMPONENT}_PATH_SUFFIX importers) + + # Font plugin specific name suffixes + elseif(${component} MATCHES ".+Font$") + set(_MAGNUM_${_COMPONENT}_IS_PLUGIN 1) + set(_MAGNUM_${_COMPONENT}_PATH_SUFFIX fonts) + + # ImageConverter plugin specific name suffixes + elseif(${component} MATCHES ".+ImageConverter$") + set(_MAGNUM_${_COMPONENT}_IS_PLUGIN 1) + set(_MAGNUM_${_COMPONENT}_PATH_SUFFIX imageconverters) + + # FontConverter plugin specific name suffixes + elseif(${component} MATCHES ".+FontConverter$") + set(_MAGNUM_${_COMPONENT}_IS_PLUGIN 1) + set(_MAGNUM_${_COMPONENT}_PATH_SUFFIX fontconverters) + endif() + + # Set plugin defaults, find the plugin + if(_MAGNUM_${_COMPONENT}_IS_PLUGIN) + set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Plugins/${component}) + + # Don't override the one for *AudioImporter plugins + if(NOT _MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES) + set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${component}.h) + endif() + + # Dynamic plugins don't have any prefix (e.g. `lib` on Linux), search + # with empty prefix and then reset that back so we don't accidentaly + # break something else + set(_tmp_prefixes ${CMAKE_FIND_LIBRARY_PREFIXES}) + set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "") + find_library(MAGNUM_${_COMPONENT}_LIBRARY ${component} + PATH_SUFFIXES magnum/${_MAGNUM_${_COMPONENT}_PATH_SUFFIX}) + set(CMAKE_FIND_LIBRARY_PREFIXES ${_tmp_prefixes}) - set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX ${component}) + # Set library defaults, find the library + else() + set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX ${component}) + set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${component}.h) + + find_library(MAGNUM_${_COMPONENT}_LIBRARY Magnum${component}) + endif() # Applications if(${component} MATCHES .+Application) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Platform) - set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${component}.h) # GLUT application dependencies if(${component} STREQUAL GlutApplication) @@ -223,12 +282,9 @@ foreach(component ${Magnum_FIND_COMPONENTS}) unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() endif() - endif() # Audio library - if(${component} STREQUAL Audio) - set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Audio.h) - + elseif(${component} STREQUAL Audio) find_package(OpenAL) if(OPENAL_FOUND) set(_MAGNUM_${_COMPONENT}_LIBRARIES ${OPENAL_LIBRARY}) @@ -236,45 +292,17 @@ foreach(component ${Magnum_FIND_COMPONENTS}) else() unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() - endif() - - # DebugTools library - if(${component} STREQUAL DebugTools) - set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES DebugTools.h) - endif() # Mesh tools library - if(${component} STREQUAL MeshTools) + elseif(${component} STREQUAL MeshTools) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES CompressIndices.h) - endif() # Primitives library - if(${component} STREQUAL Primitives) + elseif(${component} STREQUAL Primitives) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Cube.h) - endif() - - # Scene graph library - if(${component} STREQUAL SceneGraph) - set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES SceneGraph.h) - endif() - - # Shaders library - if(${component} STREQUAL Shaders) - set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Shaders.h) - endif() - - # Shapes library - if(${component} STREQUAL Shapes) - set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Shapes.h) - endif() - - # Text library - if(${component} STREQUAL Text) - set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Text.h) - endif() # TextureTools library - if(${component} STREQUAL TextureTools) + elseif(${component} STREQUAL TextureTools) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Atlas.h) endif() @@ -367,6 +395,7 @@ set(MAGNUM_PLUGINS_DIR ${MAGNUM_PLUGINS_INSTALL_DIR} CACHE PATH "Base directory where to look for Magnum plugins") # Plugin directories +set(MAGNUM_PLUGINS_INCLUDE_DIR ${MAGNUM_INCLUDE_DIR}/Plugins) set(MAGNUM_PLUGINS_FONT_DIR ${MAGNUM_PLUGINS_DIR}/fonts) set(MAGNUM_PLUGINS_FONTCONVERTER_DIR ${MAGNUM_PLUGINS_DIR}/fontconverters) set(MAGNUM_PLUGINS_IMAGECONVERTER_DIR ${MAGNUM_PLUGINS_DIR}/imageconverters) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index c6504d974..4b8f347de 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -132,10 +132,20 @@ layout(location = 0, index = 0) out vec4 color; layout(location = 1, index = 1) out vec3 normal; @endcode -If you don't have the required extension, you can use functions -bindAttributeLocation() and bindFragmentDataLocation() / -bindFragmentDataLocationIndexed() between attaching the shaders and linking -the program: +If you don't have the required extension, declare the attributes without +`layout()` qualifier and use functions @ref bindAttributeLocation() and +@ref bindFragmentDataLocation() / @ref bindFragmentDataLocationIndexed() between +attaching the shaders and linking the program. Note that additional syntax +changes may be needed for GLSL 1.20 and GLSL ES 1.0. +@code +in vec4 position; +in vec3 normal; +in vec2 textureCoordinates; +@endcode +@code +out vec4 color; +out vec3 normal; +@endcode @code // Shaders attached... @@ -174,8 +184,14 @@ layout(location = 0) uniform mat4 transformation; layout(location = 1) uniform mat4 projection; @endcode -If you don't have the required extension, you can get uniform location using -uniformLocation() after linking stage: +If you don't have the required extension, declare the uniforms without the +`layout()` qualifier and get uniform location using @ref uniformLocation() +*after* linking stage. Note that additional syntax changes may be needed for +GLSL 1.20 and GLSL ES 1.0. +@code +uniform mat4 transformation; +uniform mat4 projection; +@endcode @code Int transformationUniform = uniformLocation("transformation"); Int projectionUniform = uniformLocation("projection"); @@ -199,7 +215,13 @@ layout(binding = 1) uniform sampler2D specularTexture; @endcode If you don't have the required extension (or if you want to change the layer -later), you can set the texture layer uniform using setUniform(Int, Int): +later), declare the uniforms without the `layout()` qualifier and set the +texture layer uniform using @ref setUniform(Int, Int). Note that additional +syntax changes may be needed for GLSL 1.20 and GLSL ES 1.0. +@code +uniform sampler2D diffuseTexture; +uniform sampler2D specularTexture; +@endcode @code setUniform(DiffuseTextureUniform, DiffuseTextureLayer); setUniform(SpecularTextureUniform, SpecularTextureLayer); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c3b7b0688..744c69d09 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -205,6 +205,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/magnumConfigure.h DESTINATION ${MAGNUM add_subdirectory(Math) add_subdirectory(Platform) +add_subdirectory(Plugins) add_subdirectory(Trade) if(WITH_AUDIO) diff --git a/src/ImageReference.h b/src/ImageReference.h index 1366bc2bc..f41007d2c 100644 --- a/src/ImageReference.h +++ b/src/ImageReference.h @@ -48,6 +48,7 @@ to change image properties, only data pointer. Interchangeable with Image, BufferImage or Trade::ImageData. @see ImageReference1D, ImageReference2D, ImageReference3D +@todo Provide const version somewhat */ template class ImageReference: public AbstractImage { public: @@ -59,9 +60,6 @@ template class ImageReference: public AbstractImage { * @param type Data type of pixel data * @param size %Image size * @param data %Image data - * - * Note that the image data are not copied on construction, but they - * are deleted on class destruction. */ constexpr explicit ImageReference(ColorFormat format, ColorType type, const typename DimensionTraits::VectorType& size, void* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast(data)) {} diff --git a/src/Math/Functions.h b/src/Math/Functions.h index 5e5e49d05..193da9c06 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -211,6 +211,51 @@ template Vector abs(const Vector& a } #endif +/** @brief Nearest not larger integer */ +#ifdef DOXYGEN_GENERATING_OUTPUT +template inline T floor(const T& a); +#else +template inline typename std::enable_if::value, T>::type floor(T a) { + return std::floor(a); +} +template Vector floor(const Vector& a) { + Vector out; + for(std::size_t i = 0; i != size; ++i) + out[i] = std::floor(a[i]); + return out; +} +#endif + +/** @brief Round value to nearest integer */ +#ifdef DOXYGEN_GENERATING_OUTPUT +template inline T round(const T& a); +#else +template inline typename std::enable_if::value, T>::type round(T a) { + return std::round(a); +} +template Vector round(const Vector& a) { + Vector out; + for(std::size_t i = 0; i != size; ++i) + out[i] = std::round(a[i]); + return out; +} +#endif + +/** @brief Nearest not smaller integer */ +#ifdef DOXYGEN_GENERATING_OUTPUT +template inline T ceil(const T& a); +#else +template inline typename std::enable_if::value, T>::type ceil(T a) { + return std::ceil(a); +} +template Vector ceil(const Vector& a) { + Vector out; + for(std::size_t i = 0; i != size; ++i) + out[i] = std::ceil(a[i]); + return out; +} +#endif + /** @brief Square root @@ -242,10 +287,7 @@ template inline typename std::enable_if::value, T return T(1)/std::sqrt(a); } template Vector sqrtInverted(const Vector& a) { - Vector out; - for(std::size_t i = 0; i != size; ++i) - out[i] = T(1)/std::sqrt(a[i]); - return out; + return Vector(T(1))/sqrt(a); } #endif @@ -265,7 +307,7 @@ template inline typename std::enable_if::value, T template Vector clamp(const Vector& value, T min, T max) { Vector out; for(std::size_t i = 0; i != size; ++i) - out[i] = std::min(std::max(value[i], min), max); + out[i] = clamp(value[i], min, max); return out; } #endif @@ -344,8 +386,9 @@ Converts integral value from full range of given *unsigned* integral type to value in range @f$ [0, 1] @f$ or from *signed* integral to range @f$ [-1, 1] @f$. @note For best precision, resulting `FloatingPoint` type should be always - larger that `Integral` type (e.g. Double from Int, LongDouble from Long and - similarly for vector types). + larger that `Integral` type (e.g. @ref Magnum::Float "Float" from + @ref Magnum::Short "Short", @ref Magnum::Double "Double" from + @ref Magnum::Int "Int" and similarly for vector types). @attention To ensure the integral type is correctly detected when using literals, this function should be called with both template parameters @@ -358,7 +401,7 @@ Float a = normalize('\xFF'); Float b = normalize('\xFF'); @endcode -@see denormalize() +@see @ref denormalize() */ #ifdef DOXYGEN_GENERATING_OUTPUT template inline FloatingPoint normalize(const Integral& value); @@ -393,13 +436,14 @@ Converts floating-point value in range @f$ [0, 1] @f$ to full range of given integral type. @note For best precision, `FloatingPoint` type should be always larger that - resulting `Integral` type (e.g. Double to Int, LongDouble to Long and - similarly for vector types). + resulting `Integral` type (e.g. @ref Magnum::Float "Float" to + @ref Magnum::Short "Short", @ref Magnum::Double "Double" to @ref Magnum::Int "Int" + and similarly for vector types). @attention Return value for floating point numbers outside the normalized range is undefined. -@see normalize() +@see @ref normalize() */ #ifdef DOXYGEN_GENERATING_OUTPUT template inline Integral denormalize(const FloatingPoint& value); diff --git a/src/Math/Geometry/Rectangle.h b/src/Math/Geometry/Rectangle.h index 21f3bb331..5d7ba1a66 100644 --- a/src/Math/Geometry/Rectangle.h +++ b/src/Math/Geometry/Rectangle.h @@ -132,6 +132,11 @@ template class Rectangle { /** @brief %Rectangle height */ constexpr T height() const { return _topRight.y() - _bottomLeft.y(); } + /** @brief Translated rectangle */ + Rectangle translated(const Vector2& vec) { + return {_bottomLeft + vec, _topRight + vec}; + }; + private: Vector2 _bottomLeft; Vector2 _topRight; diff --git a/src/Math/Geometry/Test/RectangleTest.cpp b/src/Math/Geometry/Test/RectangleTest.cpp index b7d10facb..8bb46f434 100644 --- a/src/Math/Geometry/Test/RectangleTest.cpp +++ b/src/Math/Geometry/Test/RectangleTest.cpp @@ -44,6 +44,8 @@ class RectangleTest: public Corrade::TestSuite::Tester { void compare(); void size(); + void translated(); + void debug(); void configuration(); }; @@ -63,6 +65,8 @@ RectangleTest::RectangleTest() { &RectangleTest::compare, &RectangleTest::size, + &RectangleTest::translated, + &RectangleTest::debug, &RectangleTest::configuration}); } @@ -144,6 +148,11 @@ void RectangleTest::size() { CORRADE_COMPARE(rect.height(), 7); } +void RectangleTest::translated() { + CORRADE_COMPARE(Rectanglei({34, 23}, {47, 30}).translated({-17, 40}), + Rectanglei({17, 63}, {30, 70})); +} + void RectangleTest::debug() { std::ostringstream o; Debug(&o) << Rectanglei({34, 23}, {47, 30}); diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index 2d83cf349..1b86f1985 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -39,6 +39,11 @@ class FunctionsTest: public Corrade::TestSuite::Tester { void maxList(); void sign(); void abs(); + + void floor(); + void round(); + void ceil(); + void sqrt(); void sqrtInverted(); void clamp(); @@ -76,6 +81,11 @@ FunctionsTest::FunctionsTest() { &FunctionsTest::maxList, &FunctionsTest::sign, &FunctionsTest::abs, + + &FunctionsTest::floor, + &FunctionsTest::round, + &FunctionsTest::ceil, + &FunctionsTest::sqrt, &FunctionsTest::sqrtInverted, &FunctionsTest::clamp, @@ -135,6 +145,21 @@ void FunctionsTest::abs() { CORRADE_COMPARE(Math::abs(Vector3i(5, -3, 2)), Vector3i(5, 3, 2)); } +void FunctionsTest::floor() { + CORRADE_COMPARE(Math::floor(0.7f), 0.0f); + CORRADE_COMPARE(Math::floor(Vector3(2.3f, 0.7f, 1.5f)), Vector3(2.0f, 0.0f, 1.0f)); +} + +void FunctionsTest::round() { + CORRADE_COMPARE(Math::round(2.3f), 2.0f); + CORRADE_COMPARE(Math::round(Vector3(2.3f, 0.7f, 1.5f)), Vector3(2.0f, 1.0f, 2.0f)); +} + +void FunctionsTest::ceil() { + CORRADE_COMPARE(Math::ceil(2.3f), 3.0f); + CORRADE_COMPARE(Math::ceil(Vector3(2.3f, 0.7f, 1.5f)), Vector3(3.0f, 1.0f, 2.0f)); +} + void FunctionsTest::sqrt() { CORRADE_COMPARE(Math::sqrt(16), 4); CORRADE_COMPARE(Math::sqrt(Vector3i(256, 1, 0)), Vector3i(16, 1, 0)); diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 1c114ac4e..5f27f7320 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -74,6 +74,7 @@ class VectorTest: public Corrade::TestSuite::Tester { void multiplyDivideIntegral(); void multiplyDivideComponentWise(); void multiplyDivideComponentWiseIntegral(); + void modulo(); void bitwise(); void compare(); @@ -128,6 +129,7 @@ VectorTest::VectorTest() { &VectorTest::multiplyDivideIntegral, &VectorTest::multiplyDivideComponentWise, &VectorTest::multiplyDivideComponentWiseIntegral, + &VectorTest::modulo, &VectorTest::bitwise, &VectorTest::compare, @@ -342,6 +344,15 @@ void VectorTest::multiplyDivideComponentWiseIntegral() { /* Using integer vector as divisor is not supported */ } +void VectorTest::modulo() { + typedef Math::Vector<2, Int> Vector2i; + + const Vector2i a(4, 13); + const Vector2i b(2, 5); + CORRADE_COMPARE(a % 2, Vector2i(0, 1)); + CORRADE_COMPARE(a % b, Vector2i(0, 3)); +} + void VectorTest::bitwise() { typedef Math::Vector<2, Int> Vector2i; @@ -484,9 +495,16 @@ void VectorTest::subclassTypes() { CORRADE_VERIFY((std::is_same::value)); CORRADE_VERIFY((std::is_same::value)); - /* Bitwise operations */ + /* Modulo operations */ const Vec2i ci; Vec2i i; + const Int j = {}; + CORRADE_VERIFY((std::is_same::value)); + CORRADE_VERIFY((std::is_same::value)); + CORRADE_VERIFY((std::is_same::value)); + CORRADE_VERIFY((std::is_same::value)); + + /* Bitwise operations */ CORRADE_VERIFY((std::is_same::value)); CORRADE_VERIFY((std::is_same::value)); CORRADE_VERIFY((std::is_same::value)); @@ -533,6 +551,10 @@ void VectorTest::subclass() { CORRADE_COMPARE(Vec2(-2.0f, 5.0f)*Vec2(1.5f, -2.0f), Vec2(-3.0f, -10.0f)); CORRADE_COMPARE(Vec2(-2.0f, 5.0f)/Vec2(2.0f/3.0f, -0.5f), Vec2(-3.0f, -10.0f)); + /* Modulo operations */ + CORRADE_COMPARE(Vec2i(4, 13) % 2, Vec2i(0, 1)); + CORRADE_COMPARE(Vec2i(4, 13) % Vec2i(2, 5), Vec2i(0, 3)); + /* Bitwise operations */ CORRADE_COMPARE(~Vec2i(85, 240), Vec2i(-86, -241)); CORRADE_COMPARE(Vec2i(85, 240) & Vec2i(170, 85), Vec2i(0, 80)); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 80ab89d9b..d7dfa9dfb 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -573,6 +573,70 @@ template inline Vector operator/( return out; } +/** @relates Vector +@brief Do modulo of integral vector and assign + +The computation is done in-place. +*/ +template inline +#ifdef DOXYGEN_GENERATING_OUTPUT +Vector& +#else +typename std::enable_if::value, Vector&>::type +#endif +operator%=(Vector& a, Integral b) { + for(std::size_t i = 0; i != size; ++i) + a[i] %= b; + + return a; +} + +/** @relates Vector +@brief Modulo of integral vector +*/ +template inline +#ifdef DOXYGEN_GENERATING_OUTPUT +Vector +#else +typename std::enable_if::value, Vector>::type +#endif +operator%(const Vector& a, Integral b) { + Vector copy(a); + return copy %= b; +} + +/** @relates Vector +@brief Do modulo of two integral vectors and assign + +The computation is done in-place. +*/ +template inline +#ifdef DOXYGEN_GENERATING_OUTPUT +Vector& +#else +typename std::enable_if::value, Vector&>::type +#endif +operator%=(Vector& a, const Vector& b) { + for(std::size_t i = 0; i != size; ++i) + a[i] %= b[i]; + + return a; +} + +/** @relates Vector +@brief Modulo of two integral vectors +*/ +template inline +#ifdef DOXYGEN_GENERATING_OUTPUT +Vector +#else +typename std::enable_if::value, Vector>::type +#endif +operator%(const Vector& a, const Vector& b) { + Vector copy(a); + return copy %= b; +} + /** @relates Vector @brief Bitwise NOT of integral vector */ @@ -1067,6 +1131,21 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit return number/static_cast&>(vector); \ } \ \ + template inline typename std::enable_if::value, Type&>::type operator%=(Type& a, Integral b) { \ + static_cast&>(a) %= b; \ + return a; \ + } \ + template inline typename std::enable_if::value, Type>::type operator%(const Type& a, Integral b) { \ + return static_cast&>(a) % b; \ + } \ + template inline typename std::enable_if::value, Type&>::type operator%=(Type& a, const Math::Vector& b) { \ + static_cast&>(a) %= b; \ + return a; \ + } \ + template inline typename std::enable_if::value, Type>::type operator%(const Type& a, const Math::Vector& b) { \ + return static_cast&>(a) % b; \ + } \ + \ template inline typename std::enable_if::value, Type>::type operator~(const Type& vector) { \ return ~static_cast&>(vector); \ } \ diff --git a/src/Math/instantiation.cpp b/src/Math/instantiation.cpp index 1bf7f918b..fcb4772a8 100644 --- a/src/Math/instantiation.cpp +++ b/src/Math/instantiation.cpp @@ -58,23 +58,23 @@ template struct ConfigurationValue>; template struct ConfigurationValue>; -#ifndef _WIN32 +#ifndef __MINGW32__ template struct ConfigurationValue>; #endif template struct ConfigurationValue>; template struct ConfigurationValue>; -#ifndef _WIN32 +#ifndef __MINGW32__ template struct ConfigurationValue>; #endif template struct ConfigurationValue>; template struct ConfigurationValue>; -#ifndef _WIN32 +#ifndef __MINGW32__ template struct ConfigurationValue>; #endif #ifndef MAGNUM_TARGET_GLES template struct ConfigurationValue>; template struct ConfigurationValue>; -#ifndef _WIN32 +#ifndef __MINGW32__ template struct ConfigurationValue>; #endif #endif diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 2e8acd372..e7ecd6d83 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -138,7 +138,7 @@ Mesh& Mesh::operator=(Mesh&& other) noexcept { } Mesh& Mesh::setIndexBuffer(Buffer& buffer, GLintptr offset, IndexType type, UnsignedInt start, UnsignedInt end) { - #ifdef CORRADE_TARGET_NACL + #if defined(CORRADE_TARGET_NACL) || defined(CORRADE_TARGET_EMSCRIPTEN) CORRADE_ASSERT(buffer.targetHint() == Buffer::Target::ElementArray, "Mesh::setIndexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::ElementArray << "but got" << buffer.targetHint(), *this); #endif @@ -265,7 +265,7 @@ void Mesh::destroyImplementationVAO() { } void Mesh::attributePointerImplementationDefault(const Attribute& attribute) { - #ifdef CORRADE_TARGET_NACL + #if defined(CORRADE_TARGET_NACL) || defined(CORRADE_TARGET_EMSCRIPTEN) CORRADE_ASSERT(attribute.buffer->targetHint() == Buffer::Target::Array, "Mesh::addVertexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::Array << "but got" << attribute.buffer->targetHint(), ); #endif @@ -274,7 +274,7 @@ void Mesh::attributePointerImplementationDefault(const Attribute& attribute) { } void Mesh::attributePointerImplementationVAO(const Attribute& attribute) { - #ifdef CORRADE_TARGET_NACL + #if defined(CORRADE_TARGET_NACL) || defined(CORRADE_TARGET_EMSCRIPTEN) CORRADE_ASSERT(attribute.buffer->targetHint() == Buffer::Target::Array, "Mesh::addVertexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::Array << "but got" << attribute.buffer->targetHint(), ); #endif diff --git a/src/Platform/AbstractXApplication.cpp b/src/Platform/AbstractXApplication.cpp index c4d523d37..a2d2846aa 100644 --- a/src/Platform/AbstractXApplication.cpp +++ b/src/Platform/AbstractXApplication.cpp @@ -174,6 +174,12 @@ int AbstractXApplication::exec() { return 0; } +void AbstractXApplication::keyPressEvent(KeyEvent&) {} +void AbstractXApplication::keyReleaseEvent(KeyEvent&) {} +void AbstractXApplication::mousePressEvent(MouseEvent&) {} +void AbstractXApplication::mouseReleaseEvent(MouseEvent&) {} +void AbstractXApplication::mouseMoveEvent(MouseMoveEvent&) {} + AbstractXApplication::Configuration::Configuration(): _title("Magnum X Application"), _size(800, 600) {} AbstractXApplication::Configuration::~Configuration() = default; diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index 9c330faff..6a5a412ea 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -493,13 +493,6 @@ class AbstractXApplication::MouseMoveEvent: public AbstractXApplication::InputEv const Vector2i _position; }; -/* Implementations for inline functions with unused parameters */ -inline void AbstractXApplication::keyPressEvent(KeyEvent&) {} -inline void AbstractXApplication::keyReleaseEvent(KeyEvent&) {} -inline void AbstractXApplication::mousePressEvent(MouseEvent&) {} -inline void AbstractXApplication::mouseReleaseEvent(MouseEvent&) {} -inline void AbstractXApplication::mouseMoveEvent(MouseMoveEvent&) {} - }} #endif diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index 46b60f929..03e14004c 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -22,6 +22,15 @@ # DEALINGS IN THE SOFTWARE. # +# Headers +set(Platform_HEADERS + Platform.h + Screen.h + ScreenedApplication.h + ScreenedApplication.hpp) + +install(FILES ${Platform_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) + # GLUT application if(WITH_GLUTAPPLICATION) find_package(GLUT) @@ -169,7 +178,7 @@ endif() # Magnum Info if(WITH_MAGNUMINFO) if(NOT UNIX AND NOT CORRADE_TARGET_NACL) - message(FATAL_ERROR "magnum-info is not available on this platform. Set WITH_MAGNUMINFO to OFF to suppress this warning.") + message(FATAL_ERROR "magnum-info is not available on this platform. Set WITH_MAGNUMINFO to OFF to skip building it.") endif() add_executable(magnum-info magnum-info.cpp) diff --git a/src/Platform/GlutApplication.cpp b/src/Platform/GlutApplication.cpp index 86c4532ce..7f632590a 100644 --- a/src/Platform/GlutApplication.cpp +++ b/src/Platform/GlutApplication.cpp @@ -26,6 +26,8 @@ #include "Context.h" +#include "Platform/ScreenedApplication.hpp" + namespace Magnum { namespace Platform { GlutApplication* GlutApplication::instance = nullptr; @@ -115,7 +117,16 @@ void GlutApplication::staticMouseMoveEvent(int x, int y) { instance->mouseMoveEvent(e); } +void GlutApplication::keyPressEvent(KeyEvent&) {} +void GlutApplication::keyReleaseEvent(KeyEvent&) {} +void GlutApplication::mousePressEvent(MouseEvent&) {} +void GlutApplication::mouseReleaseEvent(MouseEvent&) {} +void GlutApplication::mouseMoveEvent(MouseMoveEvent&) {} + GlutApplication::Configuration::Configuration(): _title("Magnum GLUT Application"), _size(800, 600), _sampleCount(0) {} GlutApplication::Configuration::~Configuration() = default; +template class BasicScreen; +template class BasicScreenedApplication; + }} diff --git a/src/Platform/GlutApplication.h b/src/Platform/GlutApplication.h index ef5aa22a6..b6aa9fbde 100644 --- a/src/Platform/GlutApplication.h +++ b/src/Platform/GlutApplication.h @@ -30,10 +30,12 @@ #include +#include "Platform/Platform.h" #include "Math/Vector2.h" #include "Magnum.h" -#include "OpenGL.h" +/* We must include our own GL headers first to avoid conflicts */ +#include "OpenGL.h" #include namespace Magnum { @@ -202,6 +204,14 @@ class GlutApplication { */ virtual void keyPressEvent(KeyEvent& event); + /** + * @brief Key release event + * + * Included only for compatibility with other toolkits, doesn't get + * called at all. + */ + virtual void keyReleaseEvent(KeyEvent& event); + /*@}*/ /** @{ @name Mouse handling */ @@ -546,6 +556,8 @@ When no other application header is included this macro is also aliased to #ifndef DOXYGEN_GENERATING_OUTPUT #ifndef MAGNUM_APPLICATION_MAIN typedef GlutApplication Application; +typedef BasicScreen Screen; +typedef BasicScreenedApplication ScreenedApplication; #define MAGNUM_APPLICATION_MAIN(className) MAGNUM_GLUTAPPLICATION_MAIN(className) #else #undef MAGNUM_APPLICATION_MAIN @@ -554,12 +566,6 @@ typedef GlutApplication Application; CORRADE_ENUMSET_OPERATORS(GlutApplication::MouseMoveEvent::Buttons) -/* Implementations for inline functions with unused parameters */ -inline void GlutApplication::keyPressEvent(KeyEvent&) {} -inline void GlutApplication::mousePressEvent(MouseEvent&) {} -inline void GlutApplication::mouseReleaseEvent(MouseEvent&) {} -inline void GlutApplication::mouseMoveEvent(MouseMoveEvent&) {} - }} #endif diff --git a/src/Platform/GlxApplication.cpp b/src/Platform/GlxApplication.cpp index ad864107c..b9f4b3d37 100644 --- a/src/Platform/GlxApplication.cpp +++ b/src/Platform/GlxApplication.cpp @@ -24,6 +24,7 @@ #include "GlxApplication.h" +#include "Platform/ScreenedApplication.hpp" #include "Platform/Implementation/GlxContextHandler.h" namespace Magnum { namespace Platform { @@ -37,4 +38,7 @@ GlxApplication::GlxApplication(const Arguments& arguments, void*) #endif : AbstractXApplication(new Implementation::GlxContextHandler, arguments, nullptr) {} +template class BasicScreen; +template class BasicScreenedApplication; + }} diff --git a/src/Platform/GlxApplication.h b/src/Platform/GlxApplication.h index a9687e5e7..db298ab7e 100644 --- a/src/Platform/GlxApplication.h +++ b/src/Platform/GlxApplication.h @@ -29,6 +29,7 @@ */ #include "Platform/AbstractXApplication.h" +#include "Platform/Platform.h" namespace Magnum { namespace Platform { @@ -108,6 +109,8 @@ When no other application header is included this macro is also aliased to #ifndef DOXYGEN_GENERATING_OUTPUT #ifndef MAGNUM_APPLICATION_MAIN typedef GlxApplication Application; +typedef BasicScreen Screen; +typedef BasicScreenedApplication ScreenedApplication; #define MAGNUM_APPLICATION_MAIN(className) MAGNUM_GLXAPPLICATION_MAIN(className) #else #undef MAGNUM_APPLICATION_MAIN diff --git a/src/Platform/NaClApplication.cpp b/src/Platform/NaClApplication.cpp index bc8cefe4b..418aaa77e 100644 --- a/src/Platform/NaClApplication.cpp +++ b/src/Platform/NaClApplication.cpp @@ -30,6 +30,7 @@ #include #include "Context.h" +#include "Platform/ScreenedApplication.hpp" namespace Magnum { namespace Platform { @@ -255,4 +256,13 @@ void NaClApplication::mouseLockCallback(void* applicationInstance, std::int32_t) instance->flags |= Flag::MouseLocked; } +void NaClApplication::keyPressEvent(KeyEvent&) {} +void NaClApplication::keyReleaseEvent(KeyEvent&) {} +void NaClApplication::mousePressEvent(MouseEvent&) {} +void NaClApplication::mouseReleaseEvent(MouseEvent&) {} +void NaClApplication::mouseMoveEvent(MouseMoveEvent&) {} + +template class BasicScreen; +template class BasicScreenedApplication; + }} diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 965283622..0f86558f2 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -37,6 +37,7 @@ #include #include +#include "Platform/Platform.h" #include "Math/Vector2.h" #include "Magnum.h" @@ -669,6 +670,8 @@ When no other application header is included this macro is also aliased to #ifndef DOXYGEN_GENERATING_OUTPUT #ifndef MAGNUM_APPLICATION_MAIN typedef NaClApplication Application; +typedef BasicScreen Screen; +typedef BasicScreenedApplication ScreenedApplication; #define MAGNUM_APPLICATION_MAIN(className) MAGNUM_NACLAPPLICATION_MAIN(className) #else #undef MAGNUM_APPLICATION_MAIN @@ -678,13 +681,6 @@ typedef NaClApplication Application; CORRADE_ENUMSET_OPERATORS(NaClApplication::InputEvent::Modifiers) CORRADE_ENUMSET_OPERATORS(NaClApplication::InputEvent::Buttons) -/* Implementations for inline functions with unused parameters */ -inline void NaClApplication::keyPressEvent(KeyEvent&) {} -inline void NaClApplication::keyReleaseEvent(KeyEvent&) {} -inline void NaClApplication::mousePressEvent(MouseEvent&) {} -inline void NaClApplication::mouseReleaseEvent(MouseEvent&) {} -inline void NaClApplication::mouseMoveEvent(MouseMoveEvent&) {} - }} #endif diff --git a/src/Platform/Platform.h b/src/Platform/Platform.h new file mode 100644 index 000000000..051685343 --- /dev/null +++ b/src/Platform/Platform.h @@ -0,0 +1,38 @@ +#ifndef Magnum_Platform_Platform_h +#define Magnum_Platform_Platform_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file + * @brief Forward declarations for @ref Magnum::Platform namespace + */ + +namespace Magnum { namespace Platform { + +template class BasicScreen; +template class BasicScreenedApplication; + +}} + +#endif diff --git a/src/Platform/Screen.h b/src/Platform/Screen.h new file mode 100644 index 000000000..805fbd2f2 --- /dev/null +++ b/src/Platform/Screen.h @@ -0,0 +1,265 @@ +#ifndef Magnum_Platform_AbstractScreen_h +#define Magnum_Platform_AbstractScreen_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file + * @brief Class @ref Magnum::Platform::BasicScreen + */ + +#include + +#include "Platform/ScreenedApplication.h" + +namespace Magnum { namespace Platform { + +namespace Implementation { + enum class PropagatedScreenEvent: UnsignedByte { + Draw = 1 << 0, + Input = 1 << 1 + }; + + typedef Containers::EnumSet PropagatedScreenEvents; + CORRADE_ENUMSET_OPERATORS(PropagatedScreenEvents) +} + +/** +@brief Base for application screens + +See @ref BasicScreenedApplication for more information. + +If exactly one application header is included, this class is also aliased to +`Platform::Screen`. + +@section Screen-explicit-specializations Explicit template specializations + +The following specialization are explicitly compiled into each particular +`*Application` library. For other specializations you have to use +@ref ScreenedApplication.hpp implementation file to avoid linker errors. See +@ref compilation-speedup-hpp for more information. + +- @ref GlutApplication "BasicScreen" +- @ref GlxApplication "BasicScreen" +- @ref NaClApplication "BasicScreen" +- @ref Sdl2Application "BasicScreen" +- @ref XEglApplication "BasicScreen" +*/ +template class BasicScreen: private Containers::LinkedListItem, BasicScreenedApplication> { + friend class Containers::LinkedListItem, BasicScreenedApplication>; + friend class Containers::LinkedList>; + friend class BasicScreenedApplication; + + public: + #ifdef DOXYGEN_GENERATING_OUTPUT + /** + * @brief Event propagated to given screen + * + * @see @ref PropagatedEvents, @ref BasicScreen::setPropagatedEvents() + */ + enum class PropagatedEvent: UnsignedByte { + /** + * Draw event. + * + * When enabled, drawEvent() is propagated to this screen. + */ + Draw = 1 << 0, + + /** + * Input events. + * + * When enabled, keyPressEvent(), keyReleaseEvent(), mousePressEvent(), + * mouseReleaseEvent() and mouseMoveEvent() are propagated to this + * screen. + */ + Input = 1 << 1 + }; + + /** + * @brief Events propagated to given screen + * + * @see @ref setPropagatedEvents() + */ + typedef Containers::EnumSet PropagatedEvents; + #else + typedef Implementation::PropagatedScreenEvent PropagatedEvent; + typedef Implementation::PropagatedScreenEvents PropagatedEvents; + #endif + + /** @brief Input event */ + typedef typename BasicScreenedApplication::InputEvent InputEvent; + + /** @brief Key event */ + typedef typename BasicScreenedApplication::KeyEvent KeyEvent; + + /** @brief Mouse event */ + typedef typename BasicScreenedApplication::MouseEvent MouseEvent; + + /** @brief Mouse move event */ + typedef typename BasicScreenedApplication::MouseMoveEvent MouseMoveEvent; + + explicit BasicScreen(); + ~BasicScreen(); + + /** @brief Events propagated to this screen */ + PropagatedEvents propagatedEvents() const { return _propagatedEvents; } + + /** + * @brief Set events propagated to this screen + * + * For non-propagated events related event functions are not called. + * No events are propagated by default, call this function in + * @ref focusEvent() and @ref blurEvent() to reflect focus changes. + */ + void setPropagatedEvents(PropagatedEvents events) { _propagatedEvents = events; } + + /** @brief %Application holding this screen */ + template> T* application() { + return static_cast(Containers::LinkedListItem, BasicScreenedApplication>::list()); + } + /** @overload */ + template> const T* application() const { + return static_cast(Containers::LinkedListItem, BasicScreenedApplication>::list()); + } + + /** + * @brief Next nearer screen + * + * @see @ref BasicScreenedApplication::frontScreen(), + * @ref BasicScreenedApplication::backScreen() + */ + BasicScreen* nextNearerScreen() { + return Containers::LinkedListItem, BasicScreenedApplication>::previous(); + } + /** @overload */ + const BasicScreen* nextNearerScreen() const { + return Containers::LinkedListItem, BasicScreenedApplication>::previous(); + } + + /** + * @brief Next farther screen + * + * @see @ref BasicScreenedApplication::frontScreen(), + * @ref BasicScreenedApplication::backScreen() + */ + BasicScreen* nextFartherScreen() { + return Containers::LinkedListItem, BasicScreenedApplication>::next(); + } + /** @overload */ + const BasicScreen* nextFartherScreen() const { + return Containers::LinkedListItem, BasicScreenedApplication>::next(); + } + + protected: + /** @brief Request redraw */ + virtual void redraw() { application()->redraw(); } + + /** + * @brief Focus event + * + * Called when screen is focused using @ref BasicScreenedApplication::focusScreen() + * or @ref BasicScreenedApplication::addScreen(). + */ + virtual void focusEvent() = 0; + + /** + * @brief Blur event + * + * Called when another screen is focused using @ref BasicScreenedApplication::focusScreen(), + * @ref BasicScreenedApplication::addScreen() or before the screen is + * removed from application using @ref BasicScreenedApplication::removeScreen(). + */ + virtual void blurEvent() = 0; + + /** + * @brief Viewport event + * + * Called from holder application when viewport size changes. See + * @ref Sdl2Application::viewportEvent() "*Application::viewportEvent()" + * for more information. Setting viewport on default framebuffer should + * be done by the holder application. + */ + virtual void viewportEvent(const Vector2i& size) = 0; + + /** + * @brief Draw event + * + * Called when @ref PropagatedEvent::Draw is enabled and the screen is + * redrawn. See @ref Sdl2Application::viewportEvent() "*Application::viewportEvent()" + * for more information. Buffer swapping and clearing of default + * framebufer should be done by the holder application. + */ + virtual void drawEvent() = 0; + + /** + * @brief Key press event + * + * Called when @ref PropagatedEvent::Input is enabled and an key is + * pressed. See @ref Sdl2Application::keyPressEvent() "*Application::keyPressEvent()" + * for more information. + */ + virtual void keyPressEvent(KeyEvent& event); + + /** + * @brief Key release event + * + * Called when @ref PropagatedEvent::Input is enabled and an key is + * released. See @ref Sdl2Application::keyReleaseEvent() "*Application::keyReleaseEvent()" + * for more information. + */ + virtual void keyReleaseEvent(KeyEvent& event); + + /** + * @brief Mouse press event + * + * Called when @ref PropagatedEvent::Input is enabled and mouse button + * is pressed. See @ref Sdl2Application::mousePressEvent() "*Application::mousePressEvent()" + * for more information. + */ + virtual void mousePressEvent(MouseEvent& event); + + /** + * @brief Mouse release event + * + * Called when @ref PropagatedEvent::Input is enabled and mouse button + * is released. See @ref Sdl2Application::mouseReleaseEvent() "*Application::mouseReleaseEvent()" + * for more information. + */ + virtual void mouseReleaseEvent(MouseEvent& event); + + /** + * @brief Mouse move event + * + * Called when @ref PropagatedEvent::Input is enabled and mouse is + * moved. See @ref Sdl2Application::mouseMoveEvent() "*Application::mouseMoveEvent()" + * for more information. + */ + virtual void mouseMoveEvent(MouseMoveEvent& event); + + private: + PropagatedEvents _propagatedEvents; +}; + +}} + +#endif diff --git a/src/Platform/ScreenedApplication.h b/src/Platform/ScreenedApplication.h new file mode 100644 index 000000000..3bc129f2d --- /dev/null +++ b/src/Platform/ScreenedApplication.h @@ -0,0 +1,199 @@ +#ifndef Magnum_Platform_ScreenedApplication_h +#define Magnum_Platform_ScreenedApplication_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file + * @brief Class @ref Magnum::Platform::BasicScreenedApplication + */ + +#include +#include + +#include "Platform/Platform.h" + +namespace Magnum { namespace Platform { + +/** +@brief Base for applications with screen management + +Manages list of screens and propagates events to them. + +If exactly one application header is included, this class is also aliased to +`Platform::ScreenedApplication`. + +Each @ref BasicScreen "Screen" specifies which set of events should be +propagated to it using @ref BasicScreen::setPropagatedEvents(). When +application gets an event, they are propagated to the screens: + +- @ref Sdl2Application::viewportEvent() "viewportEvent()" is propagated to + all screens. +- @ref Sdl2Application::drawEvent() "drawEvent()" is propagated in + back-to-front order to screens which have @ref BasicScreen::PropagatedEvent::Draw + enabled. +- Input events (@ref Sdl2Application::keyPressEvent() "keyPressEvent()", + @ref Sdl2Application::keyReleaseEvent() "keyReleaseEvent()", + @ref Sdl2Application::mousePressEvent() "mousePressEvent()", + @ref Sdl2Application::mouseReleaseEvent() "mouseReleaseEvent()" + and @ref Sdl2Application::mouseMoveEvent() "mouseMoveEvent()") + are propagated in front-to-back order to screens which have + @ref BasicScreen::PropagatedEvent::Input enabled. If any screen sets the + event as accepted, it is not propagated further. + +Traversing through the list of screens is done like following: +@code +// front-to-back +for(Screen* s = app.frontScreen(); s; s = s->nextFartherScreen()) { + // ... +} + +// back-to-front +for(Screen* s = app.backScreen(); s; s = s->nextNearerScreen()) { + // ... +} +@endcode + +@section ScreenedApplication-explicit-specializations Explicit template specializations + +The following specialization are explicitly compiled into each particular +`*Application` library. For other specializations you have to use +@ref ScreenedApplication.hpp implementation file to avoid linker errors. See +@ref compilation-speedup-hpp for more information. + +- @ref GlutApplication "BasicScreenedApplication" +- @ref GlxApplication "BasicScreenedApplication" +- @ref NaClApplication "BasicScreenedApplication" +- @ref Sdl2Application "BasicScreenedApplication" +- @ref XEglApplication "BasicScreenedApplication" +*/ +template class BasicScreenedApplication: public Application, private Containers::LinkedList> { + friend class Containers::LinkedList>; + friend class Containers::LinkedListItem, BasicScreenedApplication>; + friend class BasicScreen; + + public: + /** @copydoc Sdl2Application::Sdl2Application(const Arguments, const Configuration&) */ + BasicScreenedApplication(const typename Application::Arguments& arguments, const typename Application::Configuration& configuration = Application::Configuration()): Application(arguments, configuration) {} + + /** @copydoc Sdl2Application::Sdl2Application(const Arguments&, std::nullptr_t) */ + BasicScreenedApplication(const typename Application::Arguments& arguments, std::nullptr_t): Application(arguments, nullptr) {} + + /** + * @brief Add screen to application + * @return Reference to self (for method chaining) + * + * The new screen is added as backmost. If this is the first screen + * added, @ref BasicScreen::focusEvent() is called. If not, neither + * @ref BasicScreen::blurEvent() nor @ref BasicScreen::focusEvent() is + * called (i.e. the screen default state is used). + */ + BasicScreenedApplication& addScreen(BasicScreen& screen); + + /** + * @brief Remove screen from application + * @return Reference to self (for method chaining) + * + * The screen is blurred before removing. Deleting the object is left + * up to the user. + * @see @ref BasicScreen::blurEvent() + */ + BasicScreenedApplication& removeScreen(BasicScreen& screen); + + /** + * @brief Focus screen + * @return Reference to self (for method chaining) + * + * Moves the screen to front. Previously focused screen is blurred and + * this screen is focused. + * @see @ref BasicScreen::blurEvent(), @ref BasicScreen::focusEvent() + */ + BasicScreenedApplication& focusScreen(BasicScreen& screen); + + /** + * @brief Front screen + * + * @see @ref BasicScreen::nextFartherScreen(), @ref BasicScreen::nextNearerScreen() + */ + BasicScreen* frontScreen() { + return Containers::LinkedList>::first(); + } + /** @overload */ + const BasicScreen* frontScreen() const { + return Containers::LinkedList>::first(); + } + + /** + * @brief Back screen + * + * @see @ref BasicScreen::nextFartherScreen(), @ref BasicScreen::nextNearerScreen() + */ + BasicScreen* backScreen() { + return Containers::LinkedList>::last(); + } + /** @overload */ + const BasicScreen* backScreen() const { + return Containers::LinkedList>::last(); + } + + protected: + /** + * @brief Global viewport event + * + * Called when window size changes, *before* all screens' + * @ref BasicScreen::viewportEvent() "viewportEvent()". You should at + * least pass the new size to @ref DefaultFramebuffer::setViewport(). + * + * Note that this function might not get called at all if the window + * size doesn't change. You are responsible for configuring the initial + * state yourself, viewport of default framebuffer can be retrieved + * from @ref DefaultFramebuffer::viewport(). + */ + virtual void globalViewportEvent(const Vector2i& size) = 0; + + /** + * @brief Draw event + * + * Called *after* all screens' @ref BasicScreen::drawEvent() "drawEvent()". + * You should call at least @ref Sdl2Application::swapBuffers() "swapBuffers()". + * If you want to draw immediately again, call also + * @ref Sdl2Application::redraw() "redraw()". + */ + virtual void globalDrawEvent() = 0; + + private: + /* The user is supposed to override only globalViewportEvent() and + globalDrawEvent(), these implementations are dispatching the events + to attached screens. */ + void viewportEvent(const Vector2i& size) override final; + void drawEvent() override final; + void keyPressEvent(typename Application::KeyEvent& event) override final; + void keyReleaseEvent(typename Application::KeyEvent& event) override final; + void mousePressEvent(typename Application::MouseEvent& event) override final; + void mouseReleaseEvent(typename Application::MouseEvent& event) override final; + void mouseMoveEvent(typename Application::MouseMoveEvent& event) override final; +}; + +}} + +#endif diff --git a/src/Platform/ScreenedApplication.hpp b/src/Platform/ScreenedApplication.hpp new file mode 100644 index 000000000..6cf03ddb9 --- /dev/null +++ b/src/Platform/ScreenedApplication.hpp @@ -0,0 +1,136 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file + * @brief @ref compilation-speedup-hpp "Template implementation" for @ref ScreenedApplication.h and @ref Screen.h + */ + +#include "ScreenedApplication.h" + +#include "Platform/Screen.h" + +namespace Magnum { namespace Platform { + +template BasicScreen::BasicScreen() = default; +template BasicScreen::~BasicScreen() = default; + +template void BasicScreen::keyPressEvent(KeyEvent&) {} +template void BasicScreen::keyReleaseEvent(KeyEvent&) {} +template void BasicScreen::mousePressEvent(MouseEvent&) {} +template void BasicScreen::mouseReleaseEvent(MouseEvent&) {} +template void BasicScreen::mouseMoveEvent(MouseMoveEvent&) {} + +template BasicScreenedApplication& BasicScreenedApplication::addScreen(BasicScreen& screen) { + Containers::LinkedList>::insert(&screen); + if(frontScreen() == &screen) screen.focusEvent(); + Application::redraw(); + return *this; +} + +template BasicScreenedApplication& BasicScreenedApplication::removeScreen(BasicScreen& screen) { + screen.blurEvent(); + Containers::LinkedList>::erase(&screen); + Application::redraw(); + return *this; +} + +template BasicScreenedApplication& BasicScreenedApplication::focusScreen(BasicScreen& screen) { + /* Already focused, nothing to do */ + if(frontScreen() == &screen) return *this; + + frontScreen()->blurEvent(); + Containers::LinkedList>::move(&screen, frontScreen()); + screen.focusEvent(); + Application::redraw(); + return *this; +} + +template void BasicScreenedApplication::viewportEvent(const Vector2i& size) { + /* Call viewport event after all other (because of framebuffer resizing) */ + globalViewportEvent(size); + + for(BasicScreen* s = Containers::LinkedList>::first(); s; s = s->next()) + s->viewportEvent(size); +} + +template void BasicScreenedApplication::drawEvent() { + /* Back-to-front rendering */ + for(BasicScreen* s = backScreen(); s; s = s->nextNearerScreen()) + if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Draw) s->drawEvent(); + + /* Call global event after all other (because of buffer swapping) */ + globalDrawEvent(); +} + +template void BasicScreenedApplication::keyPressEvent(typename Application::KeyEvent& event) { + /* Front-to-back event propagation, stop when the event gets accepted */ + for(BasicScreen* s = frontScreen(); s; s = s->nextFartherScreen()) { + if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { + s->keyPressEvent(event); + if(event.isAccepted()) break; + } + } +} + +template void BasicScreenedApplication::keyReleaseEvent(typename Application::KeyEvent& event) { + /* Front-to-back event propagation, stop when the event gets accepted */ + for(BasicScreen* s = frontScreen(); s; s = s->nextFartherScreen()) { + if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { + s->keyReleaseEvent(event); + if(event.isAccepted()) break; + } + } +} + +template void BasicScreenedApplication::mousePressEvent(typename Application::MouseEvent& event) { + /* Front-to-back event propagation, stop when the event gets accepted */ + for(BasicScreen* s = frontScreen(); s; s = s->nextFartherScreen()) { + if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { + s->mousePressEvent(event); + if(event.isAccepted()) break; + } + } +} + +template void BasicScreenedApplication::mouseReleaseEvent(typename Application::MouseEvent& event) { + /* Front-to-back event propagation, stop when the event gets accepted */ + for(BasicScreen* s = frontScreen(); s; s = s->nextFartherScreen()) { + if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { + s->mouseReleaseEvent(event); + if(event.isAccepted()) break; + } + } +} + +template void BasicScreenedApplication::mouseMoveEvent(typename Application::MouseMoveEvent& event) { + /* Front-to-back event propagation, stop when the event gets accepted */ + for(BasicScreen* s = frontScreen(); s; s = s->nextFartherScreen()) { + if(s->propagatedEvents() & Implementation::PropagatedScreenEvent::Input) { + s->mouseMoveEvent(event); + if(event.isAccepted()) break; + } + } +} + +}} diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index efb7338c5..457cb5238 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -29,6 +29,7 @@ #endif #include "Context.h" +#include "Platform/ScreenedApplication.hpp" namespace Magnum { namespace Platform { @@ -248,6 +249,12 @@ void Sdl2Application::setMouseLocked(bool enabled) { #endif } +void Sdl2Application::keyPressEvent(KeyEvent&) {} +void Sdl2Application::keyReleaseEvent(KeyEvent&) {} +void Sdl2Application::mousePressEvent(MouseEvent&) {} +void Sdl2Application::mouseReleaseEvent(MouseEvent&) {} +void Sdl2Application::mouseMoveEvent(MouseMoveEvent&) {} + Sdl2Application::Configuration::Configuration(): _title("Magnum SDL2 Application"), _size(800, 600), _flags(Flag::Resizable), _sampleCount(0) {} Sdl2Application::Configuration::~Configuration() = default; @@ -263,4 +270,7 @@ Sdl2Application::InputEvent::Modifiers Sdl2Application::MouseMoveEvent::modifier return _modifiers = fixedModifiers(SDL_GetModState()); } +template class BasicScreen; +template class BasicScreenedApplication; + }} diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index 025b28553..319006b60 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -30,6 +30,7 @@ #include +#include "Platform/Platform.h" #include "Math/Vector2.h" #include "Magnum.h" @@ -656,6 +657,8 @@ When no other application header is included this macro is also aliased to #ifndef DOXYGEN_GENERATING_OUTPUT #ifndef MAGNUM_APPLICATION_MAIN typedef Sdl2Application Application; +typedef BasicScreen Screen; +typedef BasicScreenedApplication ScreenedApplication; #define MAGNUM_APPLICATION_MAIN(className) MAGNUM_SDL2APPLICATION_MAIN(className) #else #undef MAGNUM_APPLICATION_MAIN @@ -665,13 +668,6 @@ typedef Sdl2Application Application; CORRADE_ENUMSET_OPERATORS(Sdl2Application::InputEvent::Modifiers) CORRADE_ENUMSET_OPERATORS(Sdl2Application::MouseMoveEvent::Buttons) -/* Implementations for inline functions with unused parameters */ -inline void Sdl2Application::keyPressEvent(KeyEvent&) {} -inline void Sdl2Application::keyReleaseEvent(KeyEvent&) {} -inline void Sdl2Application::mousePressEvent(MouseEvent&) {} -inline void Sdl2Application::mouseReleaseEvent(MouseEvent&) {} -inline void Sdl2Application::mouseMoveEvent(MouseMoveEvent&) {} - }} #endif diff --git a/src/Platform/XEglApplication.cpp b/src/Platform/XEglApplication.cpp index 94bc7ad02..264e955ea 100644 --- a/src/Platform/XEglApplication.cpp +++ b/src/Platform/XEglApplication.cpp @@ -24,6 +24,7 @@ #include "XEglApplication.h" +#include "Platform/ScreenedApplication.hpp" #include "Platform/Implementation/EglContextHandler.h" namespace Magnum { namespace Platform { @@ -37,4 +38,7 @@ XEglApplication::XEglApplication(const Arguments& arguments, void*) #endif : AbstractXApplication(new Implementation::EglContextHandler, arguments, nullptr) {} +template class BasicScreen; +template class BasicScreenedApplication; + }} diff --git a/src/Platform/XEglApplication.h b/src/Platform/XEglApplication.h index 33b946388..e4f698f00 100644 --- a/src/Platform/XEglApplication.h +++ b/src/Platform/XEglApplication.h @@ -28,6 +28,7 @@ * @brief Class @ref Magnum::Platform::XEglApplication */ +#include "Platform/Platform.h" #include "Platform/AbstractXApplication.h" namespace Magnum { namespace Platform { @@ -109,6 +110,8 @@ When no other application header is included this macro is also aliased to #ifndef DOXYGEN_GENERATING_OUTPUT #ifndef MAGNUM_APPLICATION_MAIN typedef XEglApplication Application; +typedef BasicScreen Screen; +typedef BasicScreenedApplication ScreenedApplication; #define MAGNUM_APPLICATION_MAIN(className) MAGNUM_XEGLAPPLICATION_MAIN(className) #else #undef MAGNUM_APPLICATION_MAIN diff --git a/src/Plugins/CMakeLists.txt b/src/Plugins/CMakeLists.txt new file mode 100644 index 000000000..f7324492d --- /dev/null +++ b/src/Plugins/CMakeLists.txt @@ -0,0 +1,54 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +# Wrapper for creating given plugin type +macro(add_plugin) + if(NOT BUILD_STATIC) + corrade_add_plugin(${ARGN}) + else() + corrade_add_static_plugin(${ARGN}) + endif() +endmacro() + +if(WITH_TEXT AND WITH_MAGNUMFONT) + add_subdirectory(MagnumFont) +endif() + +if(WITH_TEXT AND WITH_MAGNUMFONTCONVERTER AND NOT MAGNUM_TARGET_GLES) + add_subdirectory(MagnumFontConverter) +endif() + +if(WITH_TGAIMAGECONVERTER) + add_subdirectory(TgaImageConverter) +endif() + +if(WITH_TGAIMPORTER) + add_subdirectory(TgaImporter) +endif() + +if(WITH_AUDIO AND WITH_WAVAUDIOIMPORTER) + add_subdirectory(WavAudioImporter) +endif() diff --git a/src/Plugins/MagnumFont/CMakeLists.txt b/src/Plugins/MagnumFont/CMakeLists.txt index 11d09f8e5..9ea4bb7a8 100644 --- a/src/Plugins/MagnumFont/CMakeLists.txt +++ b/src/Plugins/MagnumFont/CMakeLists.txt @@ -22,8 +22,6 @@ # DEALINGS IN THE SOFTWARE. # -find_package(Magnum REQUIRED Text) - set(MagnumFont_SOURCES MagnumFont.cpp) @@ -37,9 +35,7 @@ add_plugin(MagnumFont ${MAGNUM_PLUGINS_FONT_INSTALL_DIR} MagnumFont.conf $ pluginRegistrationMagnumFont.cpp) -target_link_libraries(MagnumFont - ${MAGNUM_LIBRARIES} - ${MAGNUM_TEXT_LIBRARIES}) +target_link_libraries(MagnumFont Magnum MagnumText) if(WIN32) target_link_libraries(MagnumFont TgaImporter) @@ -49,10 +45,6 @@ install(FILES ${MagnumFont_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL if(BUILD_GL_TESTS) add_library(MagnumFontTestLib STATIC $) - target_link_libraries(MagnumFontTestLib - ${MAGNUM_LIBRARIES} - ${MAGNUM_TEXT_LIBRARIES} - TgaImporterTestLib) - + target_link_libraries(MagnumFontTestLib Magnum MagnumText TgaImporterTestLib) add_subdirectory(Test) endif() diff --git a/src/Plugins/MagnumFont/MagnumFont.cpp b/src/Plugins/MagnumFont/MagnumFont.cpp index e3a98809c..fdb5996db 100644 --- a/src/Plugins/MagnumFont/MagnumFont.cpp +++ b/src/Plugins/MagnumFont/MagnumFont.cpp @@ -25,11 +25,11 @@ #include "MagnumFont.h" #include -#include -#include -#include -#include -#include +#include "Containers/Array.h" +#include "Utility/Directory.h" +#include "Utility/Unicode.h" +#include "Text/GlyphCache.h" +#include "Trade/ImageData.h" #include "TgaImporter/TgaImporter.h" @@ -49,15 +49,15 @@ struct MagnumFont::Data { namespace { class MagnumFontLayouter: public AbstractLayouter { public: - explicit MagnumFontLayouter(const std::unordered_map& glyphId, const std::vector& glyphAdvance, const GlyphCache& cache, Float fontSize, Float textSize, const std::string& text); - - std::tuple renderGlyph(UnsignedInt i) override; + explicit MagnumFontLayouter(const std::vector& glyphAdvance, const GlyphCache& cache, Float fontSize, Float textSize, std::vector&& glyphs); private: + std::tuple doRenderGlyph(UnsignedInt i) override; + const std::vector& glyphAdvance; const GlyphCache& cache; const Float fontSize, textSize; - std::vector glyphs; + const std::vector glyphs; }; } @@ -71,63 +71,63 @@ auto MagnumFont::doFeatures() const -> Features { return Feature::OpenData|Featu bool MagnumFont::doIsOpened() const { return _opened; } -void MagnumFont::doOpenData(const std::vector>>& data, const Float) { +std::pair MagnumFont::doOpenData(const std::vector>>& data, const Float) { /* We need just the configuration file and image file */ if(data.size() != 2) { Error() << "Text::MagnumFont::openData(): wanted two files, got" << data.size(); - return; + return {}; } /* Open the configuration file */ std::istringstream in(std::string(reinterpret_cast(data[0].second.begin()), data[0].second.size())); Utility::Configuration conf(in, Utility::Configuration::Flag::SkipComments); if(!conf.isValid() || conf.isEmpty()) { - Error() << "Text::MagnumFont::openData(): cannot open file" << data[0].first << conf.isValid(); - return; + Error() << "Text::MagnumFont::openData(): cannot open file" << data[0].first; + return {}; } /* Check version */ if(conf.value("version") != 1) { Error() << "Text::MagnumFont::openData(): unsupported file version, expected 1 but got" << conf.value("version"); - return; + return {}; } /* Check that we have also the image file */ if(conf.value("image") != data[1].first) { Error() << "Text::MagnumFont::openData(): expected file" << conf.value("image") << "but got" << data[1].first; - return; + return {}; } /* Open and load image file */ Trade::TgaImporter importer; if(!importer.openData(data[1].second)) { Error() << "Text::MagnumFont::openData(): cannot open image file"; - return; + return {}; } std::optional image = importer.image2D(0); if(!image) { Error() << "Text::MagnumFont::openData(): cannot load image file"; - return; + return {}; } - openInternal(std::move(conf), std::move(*image)); + return openInternal(std::move(conf), std::move(*image)); } -void MagnumFont::doOpenFile(const std::string& filename, Float) { +std::pair MagnumFont::doOpenFile(const std::string& filename, Float) { /* Open the configuration file */ Utility::Configuration conf(filename, Utility::Configuration::Flag::ReadOnly|Utility::Configuration::Flag::SkipComments); if(!conf.isValid() || conf.isEmpty()) { Error() << "Text::MagnumFont::openFile(): cannot open file" << filename << conf.isValid(); - return; + return {}; } /* Check version */ if(conf.value("version") != 1) { Error() << "Text::MagnumFont::openFile(): unsupported file version, expected 1 but got" << conf.value("version"); - return; + return {}; } /* Open and load image file */ @@ -135,21 +135,20 @@ void MagnumFont::doOpenFile(const std::string& filename, Float) { Trade::TgaImporter importer; if(!importer.openFile(imageFilename)) { Error() << "Text::MagnumFont::openFile(): cannot open image file" << imageFilename; - return; + return {}; } std::optional image = importer.image2D(0); if(!image) { Error() << "Text::MagnumFont::openFile(): cannot load image file"; - return; + return {}; } - openInternal(std::move(conf), std::move(*image)); + return openInternal(std::move(conf), std::move(*image)); } -void MagnumFont::openInternal(Utility::Configuration&& conf, Trade::ImageData2D&& image) { +std::pair MagnumFont::openInternal(Utility::Configuration&& conf, Trade::ImageData2D&& image) { /* Everything okay, save the data internally */ _opened = new Data{std::move(conf), std::move(image), {}, {}}; - _size = _opened->conf.value("fontSize"); /* Glyph advances */ const std::vector glyphs = _opened->conf.groups("glyph"); @@ -169,6 +168,8 @@ void MagnumFont::openInternal(Utility::Configuration&& conf, Trade::ImageData2D& _opened->glyphId.insert({c->value("unicode"), glyphId}); #endif } + + return {_opened->conf.value("fontSize"), _opened->conf.value("lineHeight")}; } void MagnumFont::doClose() { @@ -185,12 +186,12 @@ Vector2 MagnumFont::doGlyphAdvance(const UnsignedInt glyph) { return glyph < _opened->glyphAdvance.size() ? _opened->glyphAdvance[glyph] : Vector2(); } -GlyphCache* MagnumFont::doCreateGlyphCache() { +std::unique_ptr MagnumFont::doCreateGlyphCache() { /* Set cache image */ - auto cache = new Text::GlyphCache( + std::unique_ptr cache(new Text::GlyphCache( _opened->conf.value("originalImageSize"), _opened->image.size(), - _opened->conf.value("padding")); + _opened->conf.value("padding"))); cache->setImage({}, _opened->image); /* Fill glyph map */ @@ -201,25 +202,25 @@ GlyphCache* MagnumFont::doCreateGlyphCache() { return cache; } -AbstractLayouter* MagnumFont::doLayout(const GlyphCache& cache, Float size, const std::string& text) { - return new MagnumFontLayouter(_opened->glyphId, _opened->glyphAdvance, cache, this->size(), size, text); -} - -namespace { - -MagnumFontLayouter::MagnumFontLayouter(const std::unordered_map& glyphId, const std::vector& glyphAdvance, const GlyphCache& cache, Float fontSize, Float textSize, const std::string& text): glyphAdvance(glyphAdvance), cache(cache), fontSize(fontSize), textSize(textSize) { +std::unique_ptr MagnumFont::doLayout(const GlyphCache& cache, Float size, const std::string& text) { /* Get glyph codes from characters */ + std::vector glyphs; glyphs.reserve(text.size()); for(std::size_t i = 0; i != text.size(); ) { UnsignedInt codepoint; std::tie(codepoint, i) = Utility::Unicode::nextChar(text, i); - const auto it = glyphId.find(codepoint); - glyphs.push_back(it == glyphId.end() ? 0 : it->second); + const auto it = _opened->glyphId.find(codepoint); + glyphs.push_back(it == _opened->glyphId.end() ? 0 : it->second); } - _glyphCount = glyphs.size(); + + return std::unique_ptr(new MagnumFontLayouter(_opened->glyphAdvance, cache, this->size(), size, std::move(glyphs))); } -std::tuple MagnumFontLayouter::renderGlyph(UnsignedInt i) { +namespace { + +MagnumFontLayouter::MagnumFontLayouter(const std::vector& glyphAdvance, const GlyphCache& cache, const Float fontSize, const Float textSize, std::vector&& glyphs): AbstractLayouter(glyphs.size()), glyphAdvance(glyphAdvance), cache(cache), fontSize(fontSize), textSize(textSize), glyphs(std::move(glyphs)) {} + +std::tuple MagnumFontLayouter::doRenderGlyph(const UnsignedInt i) { /* Position of the texture in the resulting glyph, texture coordinates */ Vector2i position; Rectanglei rectangle; diff --git a/src/Plugins/MagnumFont/MagnumFont.h b/src/Plugins/MagnumFont/MagnumFont.h index 18690b750..99fc3de5f 100644 --- a/src/Plugins/MagnumFont/MagnumFont.h +++ b/src/Plugins/MagnumFont/MagnumFont.h @@ -28,8 +28,8 @@ * @brief Class Magnum::Text::MagnumFont */ -#include -#include +#include "Text/AbstractFont.h" +#include "Trade/Trade.h" namespace Magnum { namespace Text { @@ -40,9 +40,8 @@ This plugin depends on @ref Trade::TgaImporter "TgaImporter" plugin and is built if `WITH_MAGNUMFONT` is enabled in CMake. To use dynamic plugin, you need to load `%MagnumFont` plugin from `fonts/` subdirectory of your plugin dir. To use static plugin or use this as a dependency of another plugin, you need to -request `%MagnumFont` component in CMake and link to -`${MAGNUMPLUGINS_MAGNUMFONT_LIBRARIES}`. See @ref building-plugins and -@ref cmake-plugins for more information. +request `%MagnumFont` component in CMake and link to `${MAGNUM_MAGNUMFONT_LIBRARIES}`. +See @ref building and @ref cmake for more information. The font consists of two files, one text file containing character and glyph info and one TGA file containing the glyphs in distance field format. The font @@ -116,9 +115,9 @@ class MagnumFont: public AbstractFont { bool doIsOpened() const override; - void doOpenData(const std::vector>>& data, Float) override; + std::pair doOpenData(const std::vector>>& data, Float) override; - void doOpenFile(const std::string& filename, Float) override; + std::pair doOpenFile(const std::string& filename, Float) override; void doClose() override; @@ -126,13 +125,13 @@ class MagnumFont: public AbstractFont { Vector2 doGlyphAdvance(UnsignedInt glyph) override; - GlyphCache* doCreateGlyphCache() override; + std::unique_ptr doCreateGlyphCache() override; - AbstractLayouter* doLayout(const GlyphCache& cache, Float size, const std::string& text) override; + std::unique_ptr doLayout(const GlyphCache& cache, Float size, const std::string& text) override; - Data* _opened; + std::pair openInternal(Utility::Configuration&& conf, Trade::ImageData2D&& image); - void openInternal(Utility::Configuration&& conf, Trade::ImageData2D&& image); + Data* _opened; }; }} diff --git a/src/Plugins/MagnumFont/Test/MagnumFontTest.cpp b/src/Plugins/MagnumFont/Test/MagnumFontTest.cpp index 35b130f8e..c46d5d293 100644 --- a/src/Plugins/MagnumFont/Test/MagnumFontTest.cpp +++ b/src/Plugins/MagnumFont/Test/MagnumFontTest.cpp @@ -22,10 +22,10 @@ DEALINGS IN THE SOFTWARE. */ -#include -#include #include +#include "Test/AbstractOpenGLTester.h" +#include "Text/GlyphCache.h" #include "MagnumFont/MagnumFont.h" #include "magnumFontTestConfigure.h" @@ -51,6 +51,7 @@ void MagnumFontTest::properties() { MagnumFont font; CORRADE_VERIFY(font.openFile(Utility::Directory::join(MAGNUMFONT_TEST_DIR, "font.conf"), 0.0f)); CORRADE_COMPARE(font.size(), 16.0f); + CORRADE_COMPARE(font.lineHeight(), 39.7333f); CORRADE_COMPARE(font.glyphAdvance(font.glyphId(U'W')), Vector2(23.0f, 0.0f)); } @@ -63,41 +64,43 @@ void MagnumFontTest::layout() { cache.insert(font.glyphId(U'W'), {25, 34}, {{0, 8}, {16, 128}}); cache.insert(font.glyphId(U'e'), {25, 12}, {{16, 4}, {64, 32}}); - AbstractLayouter* layouter = font.layout(cache, 0.5f, "Wave"); + auto layouter = font.layout(cache, 0.5f, "Wave"); CORRADE_VERIFY(layouter); CORRADE_COMPARE(layouter->glyphCount(), 4); + Rectangle rectangle; Rectangle position; Rectangle textureCoordinates; - Vector2 advance; /* 'W' */ - std::tie(position, textureCoordinates, advance) = layouter->renderGlyph(0); + Vector2 cursorPosition; + std::tie(position, textureCoordinates) = layouter->renderGlyph(0, cursorPosition = {}, rectangle); CORRADE_COMPARE(position, Rectangle({0.78125f, 1.0625f}, {1.28125f, 4.8125f})); CORRADE_COMPARE(textureCoordinates, Rectangle({0, 0.03125f}, {0.0625f, 0.5f})); - CORRADE_COMPARE(advance, Vector2(0.71875f, 0.0f)); + CORRADE_COMPARE(cursorPosition, Vector2(0.71875f, 0.0f)); /* 'a' (not found) */ - std::tie(position, textureCoordinates, advance) = layouter->renderGlyph(1); + std::tie(position, textureCoordinates) = layouter->renderGlyph(1, cursorPosition = {}, rectangle); CORRADE_COMPARE(position, Rectangle()); CORRADE_COMPARE(textureCoordinates, Rectangle()); - CORRADE_COMPARE(advance, Vector2(0.25f, 0.0f)); + CORRADE_COMPARE(cursorPosition, Vector2(0.25f, 0.0f)); /* 'v' (not found) */ - std::tie(position, textureCoordinates, advance) = layouter->renderGlyph(2); + std::tie(position, textureCoordinates) = layouter->renderGlyph(2, cursorPosition = {}, rectangle); CORRADE_COMPARE(position, Rectangle()); CORRADE_COMPARE(textureCoordinates, Rectangle()); - CORRADE_COMPARE(advance, Vector2(0.25f, 0.0f)); + CORRADE_COMPARE(cursorPosition, Vector2(0.25f, 0.0f)); /* 'e' */ - std::tie(position, textureCoordinates, advance) = layouter->renderGlyph(3); + std::tie(position, textureCoordinates) = layouter->renderGlyph(3, cursorPosition = {}, rectangle); CORRADE_COMPARE(position, Rectangle({0.78125f, 0.375f}, {2.28125f, 1.25f})); CORRADE_COMPARE(textureCoordinates, Rectangle({0.0625f, 0.015625f}, {0.25f, 0.125f})); - CORRADE_COMPARE(advance, Vector2(0.375f, 0.0f)); + CORRADE_COMPARE(cursorPosition, Vector2(0.375f, 0.0f)); } void MagnumFontTest::createGlyphCache() { /** @todo */ + CORRADE_SKIP("Not yet implemented"); } }}} diff --git a/src/Plugins/MagnumFont/Test/font.conf b/src/Plugins/MagnumFont/Test/font.conf index 4c2a3baea..7cf2c7b9b 100644 --- a/src/Plugins/MagnumFont/Test/font.conf +++ b/src/Plugins/MagnumFont/Test/font.conf @@ -3,6 +3,7 @@ image=font.tga originalImageSize=1536 1536 padding=24 24 fontSize=16 +lineHeight=39.7333 [char] unicode=57 glyph=2 diff --git a/src/Plugins/MagnumFont/pluginRegistrationMagnumFont.cpp b/src/Plugins/MagnumFont/pluginRegistrationMagnumFont.cpp index 3250c4f96..374ca3657 100644 --- a/src/Plugins/MagnumFont/pluginRegistrationMagnumFont.cpp +++ b/src/Plugins/MagnumFont/pluginRegistrationMagnumFont.cpp @@ -25,4 +25,4 @@ #include "MagnumFont/MagnumFont.h" CORRADE_PLUGIN_REGISTER(MagnumFont, Magnum::Text::MagnumFont, - "cz.mosra.magnum.Text.AbstractFont/0.2") + "cz.mosra.magnum.Text.AbstractFont/0.2.3") diff --git a/src/Plugins/MagnumFontConverter/CMakeLists.txt b/src/Plugins/MagnumFontConverter/CMakeLists.txt index 71efa0c47..f73442afb 100644 --- a/src/Plugins/MagnumFontConverter/CMakeLists.txt +++ b/src/Plugins/MagnumFontConverter/CMakeLists.txt @@ -22,8 +22,6 @@ # DEALINGS IN THE SOFTWARE. # -find_package(Magnum REQUIRED Text) - set(MagnumFontConverter_SOURCES MagnumFontConverter.cpp) @@ -37,9 +35,7 @@ add_plugin(MagnumFontConverter ${MAGNUM_PLUGINS_FONTCONVERTER_INSTALL_DIR} MagnumFontConverter.conf $ pluginRegistrationMagnumFontConverter.cpp) -target_link_libraries(MagnumFontConverter - ${MAGNUM_LIBRARIES} - ${MAGNUM_TEXT_LIBRARIES}) +target_link_libraries(MagnumFontConverter Magnum MagnumText) if(WIN32) target_link_libraries(MagnumFontConverter TgaImageConverter) @@ -49,9 +45,6 @@ install(FILES ${MagnumFontConverter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUD if(BUILD_GL_TESTS) add_library(MagnumFontConverterTestLib STATIC $) - target_link_libraries(MagnumFontConverterTestLib - ${MAGNUM_LIBRARIES} - ${MAGNUM_TEXT_LIBRARIES} - TgaImageConverterTestLib) + target_link_libraries(MagnumFontConverterTestLib Magnum MagnumText TgaImageConverterTestLib) add_subdirectory(Test) endif() diff --git a/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp b/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp index 0e841fca3..1e6f381b2 100644 --- a/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp +++ b/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp @@ -27,11 +27,12 @@ #include #include #include -#include -#include -#include -#include -#include + +#include "ColorFormat.h" +#include "Image.h" +#include "Text/GlyphCache.h" +#include "Text/AbstractFont.h" +#include "TgaImageConverter/TgaImageConverter.h" namespace Magnum { namespace Text { @@ -43,7 +44,7 @@ auto MagnumFontConverter::doFeatures() const -> Features { return Feature::ExportFont|Feature::ConvertData|Feature::MultiFile; } -#ifndef _WIN32 +#ifndef __MINGW32__ std::vector>> MagnumFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const #else std::vector>> MagnumFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::vector& characters) const @@ -56,6 +57,7 @@ std::vector>> MagnumFont configuration.setValue("originalImageSize", cache.textureSize()); configuration.setValue("padding", cache.padding()); configuration.setValue("fontSize", font.size()); + configuration.setValue("lineHeight", font.lineHeight()); /* Compress glyph IDs so the glyphs are in consecutive array, glyph 0 should stay at position 0 */ diff --git a/src/Plugins/MagnumFontConverter/MagnumFontConverter.h b/src/Plugins/MagnumFontConverter/MagnumFontConverter.h index 8c363f84b..808c3be4e 100644 --- a/src/Plugins/MagnumFontConverter/MagnumFontConverter.h +++ b/src/Plugins/MagnumFontConverter/MagnumFontConverter.h @@ -28,7 +28,7 @@ * @brief Class Magnum::Text::MagnumFontConverter */ -#include +#include "Text/AbstractFontConverter.h" namespace Magnum { namespace Text { @@ -45,8 +45,8 @@ to read back the generated data. It depends on to load `%MagnumFontConverter` plugin from `fontconverters/` subdirectory of your plugin dir. To use static plugin or use this as a dependency of another plugin, you need to request `%MagnumFontConverter` component in CMake and link -to `${MAGNUMPLUGINS_MAGNUMFONTCONVERTER_LIBRARIES}`. See @ref building-plugins -and @ref cmake-plugins for more information. +to `${MAGNUM_MAGNUMFONTCONVERTER_LIBRARIES}`. See @ref building and @ref cmake +for more information. */ class MagnumFontConverter: public Text::AbstractFontConverter { public: @@ -58,7 +58,7 @@ class MagnumFontConverter: public Text::AbstractFontConverter { private: Features doFeatures() const override; - #ifndef _WIN32 + #ifndef __MINGW32__ std::vector>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const override; #else std::vector>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::vector& characters) const override; diff --git a/src/Plugins/MagnumFontConverter/Test/CMakeLists.txt b/src/Plugins/MagnumFontConverter/Test/CMakeLists.txt index a6b28e93e..91b3d9470 100644 --- a/src/Plugins/MagnumFontConverter/Test/CMakeLists.txt +++ b/src/Plugins/MagnumFontConverter/Test/CMakeLists.txt @@ -25,12 +25,10 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/magnumFontConverterTestConfigure.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/magnumFontConverterTestConfigure.h) -include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../FreeTypeFont/Test/ - ${CMAKE_CURRENT_BINARY_DIR}/../../MagnumFont/Test/ +include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../MagnumFont/Test/ ${CMAKE_CURRENT_BINARY_DIR}) corrade_add_test(MagnumFontConverterTest MagnumFontConverterTest.cpp LIBRARIES MagnumFontConverterTestLib - FreeTypeFontTestLib TgaImporterTestLib ${GL_TEST_LIBRARIES}) diff --git a/src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp b/src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp index 9e00c415c..e0676f0e3 100644 --- a/src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp +++ b/src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp @@ -24,18 +24,18 @@ #include #include -#include -#include -#include -#include -#include -#include - -#include "FreeTypeFont/FreeTypeFont.h" + +#include "ColorFormat.h" +#include "Extensions.h" +#include "TextureFormat.h" +#include "Test/AbstractOpenGLTester.h" +#include "Text/GlyphCache.h" +#include "Trade/ImageData.h" + +#include "Text/AbstractFont.h" #include "MagnumFontConverter/MagnumFontConverter.h" #include "TgaImporter/TgaImporter.h" -#include "freeTypeFontTestConfigure.h" #include "magnumFontTestConfigure.h" #include "magnumFontConverterTestConfigure.h" @@ -45,19 +45,11 @@ class MagnumFontConverterTest: public Magnum::Test::AbstractOpenGLTester { public: explicit MagnumFontConverterTest(); - ~MagnumFontConverterTest(); - void exportFont(); }; MagnumFontConverterTest::MagnumFontConverterTest() { addTests({&MagnumFontConverterTest::exportFont}); - - FreeTypeFont::initialize(); -} - -MagnumFontConverterTest::~MagnumFontConverterTest() { - FreeTypeFont::finalize(); } void MagnumFontConverterTest::exportFont() { @@ -65,9 +57,43 @@ void MagnumFontConverterTest::exportFont() { Utility::Directory::rm(Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font.conf")); Utility::Directory::rm(Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font.tga")); - /* Open font */ - FreeTypeFont font; - CORRADE_VERIFY(font.openFile(Utility::Directory::join(FREETYPEFONT_TEST_DIR, "Oxygen.ttf"), 16.0f)); + /* Fake font with fake cache */ + class FakeFont: public Text::AbstractFont { + public: + explicit FakeFont(): _opened(false) {} + + private: + void doClose() { _opened = false; } + bool doIsOpened() const { return _opened; } + std::pair doOpenFile(const std::string&, Float) { + _opened = true; + return {16.0f, 39.7333f}; + } + Features doFeatures() const { return {}; } + std::unique_ptr doLayout(const GlyphCache&, Float, const std::string&) { return nullptr; } + + UnsignedInt doGlyphId(const char32_t character) { + switch(character) { + case 'W': return 2; + case 'e': return 1; + } + + return 0; + } + + Vector2 doGlyphAdvance(const UnsignedInt glyph) { + switch(glyph) { + case 0: return {8, 0}; + case 1: return {12, 0}; + case 2: return {23, 0}; + } + + CORRADE_ASSERT_UNREACHABLE(); + } + + bool _opened; + } font; + font.openFile({}, {}); /* Create fake cache */ MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); diff --git a/src/Plugins/MagnumFontConverter/pluginRegistrationMagnumFontConverter.cpp b/src/Plugins/MagnumFontConverter/pluginRegistrationMagnumFontConverter.cpp index a0bbc18ce..4f7bc44df 100644 --- a/src/Plugins/MagnumFontConverter/pluginRegistrationMagnumFontConverter.cpp +++ b/src/Plugins/MagnumFontConverter/pluginRegistrationMagnumFontConverter.cpp @@ -25,4 +25,4 @@ #include "MagnumFontConverter/MagnumFontConverter.h" CORRADE_PLUGIN_REGISTER(MagnumFontConverter, Magnum::Text::MagnumFontConverter, - "cz.mosra.magnum.Text.AbstractFontConverter/0.1") + "cz.mosra.magnum.Text.AbstractFontConverter/0.1.1") diff --git a/src/Plugins/TgaImageConverter/CMakeLists.txt b/src/Plugins/TgaImageConverter/CMakeLists.txt index f72e90679..1ef44c77a 100644 --- a/src/Plugins/TgaImageConverter/CMakeLists.txt +++ b/src/Plugins/TgaImageConverter/CMakeLists.txt @@ -35,12 +35,12 @@ add_plugin(TgaImageConverter ${MAGNUM_PLUGINS_IMAGECONVERTER_INSTALL_DIR} TgaImageConverter.conf $ pluginRegistrationTgaImageConverter.cpp) -target_link_libraries(TgaImageConverter ${MAGNUM_LIBRARIES}) +target_link_libraries(TgaImageConverter Magnum) install(FILES ${TgaImageConverter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/TgaImageConverter) if(BUILD_TESTS) add_library(TgaImageConverterTestLib SHARED $) - target_link_libraries(TgaImageConverterTestLib ${MAGNUM_LIBRARIES}) + target_link_libraries(TgaImageConverterTestLib Magnum) add_subdirectory(Test) endif() diff --git a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp index 20e1a5c77..3688a6dcd 100644 --- a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp +++ b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp @@ -27,11 +27,12 @@ #include #include #include -#include -#include -#include -#include -#include + +#include "ColorFormat.h" +#include "Image.h" +#include "Trade/ImageData.h" +#include "TgaImageConverter/TgaImageConverter.h" +#include "TgaImporter/TgaImporter.h" #include "configure.h" diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp index e273226ae..fdb9c8c11 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp @@ -26,14 +26,16 @@ #include #include -#include -#include -#include -#include + +#include "Containers/Array.h" +#include "Utility/Endianness.h" +#include "ColorFormat.h" +#include "Image.h" #ifdef MAGNUM_TARGET_GLES #include -#include +#include "Math/Swizzle.h" +#include "Math/Vector4.h" #endif #include "TgaImporter/TgaHeader.h" @@ -81,14 +83,14 @@ Containers::Array TgaImageConverter::doExportToData(const ImageRe std::copy(image.data(), image.data()+pixelSize*image.size().product(), data.begin()+sizeof(TgaHeader)); #ifdef MAGNUM_TARGET_GLES - if(image->format() == ColorFormat::RGB) { + if(image.format() == ColorFormat::RGB) { auto pixels = reinterpret_cast*>(data.begin()+sizeof(TgaHeader)); std::transform(pixels, pixels + image.size().product(), pixels, - [](Math::Vector3 pixel) { return swizzle<'b', 'g', 'r'>(pixel); }); + [](Math::Vector3 pixel) { return Math::swizzle<'b', 'g', 'r'>(pixel); }); } else if(image.format() == ColorFormat::RGBA) { auto pixels = reinterpret_cast*>(data.begin()+sizeof(TgaHeader)); std::transform(pixels, pixels + image.size().product(), pixels, - [](Math::Vector4 pixel) { return swizzle<'b', 'g', 'r', 'a'>(pixel); }); + [](Math::Vector4 pixel) { return Math::swizzle<'b', 'g', 'r', 'a'>(pixel); }); } #endif diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.h b/src/Plugins/TgaImageConverter/TgaImageConverter.h index face4c643..7acaa4dfd 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.h +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.h @@ -28,7 +28,7 @@ * @brief Class Magnum::Trade::TgaImageConverter */ -#include +#include "Trade/AbstractImageConverter.h" #ifndef DOXYGEN_GENERATING_OUTPUT #if defined(TgaImageConverter_EXPORTS) || defined(TgaImageConverterObjects_EXPORTS) @@ -51,8 +51,8 @@ This plugin is built if `WITH_TGAIMAGECONVERTER` is enabled in CMake. To use dynamic plugin, you need to load `%TgaImageConverter` plugin from `imageconverters/` subdirectory of your plugin dir. To use static plugin or use this as a dependency of another plugin, you need to request `%TgaImageConverter` -component in CMake and link to `${MAGNUMPLUGINS_TGAIMAGECONVERTER_LIBRARIES}`. -See @ref building-plugins and @ref cmake-plugins for more information. +component in CMake and link to `${MAGNUM_TGAIMAGECONVERTER_LIBRARIES}`. See +@ref building and @ref cmake for more information. */ class MAGNUM_TRADE_TGAIMAGECONVERTER_EXPORT TgaImageConverter: public AbstractImageConverter { public: diff --git a/src/Plugins/TgaImporter/CMakeLists.txt b/src/Plugins/TgaImporter/CMakeLists.txt index 90b63a1ea..a979859f3 100644 --- a/src/Plugins/TgaImporter/CMakeLists.txt +++ b/src/Plugins/TgaImporter/CMakeLists.txt @@ -36,12 +36,12 @@ add_plugin(TgaImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} TgaImporter.conf $ pluginRegistrationTgaImporter.cpp) -target_link_libraries(TgaImporter ${MAGNUM_LIBRARIES}) +target_link_libraries(TgaImporter Magnum) install(FILES ${TgaImporter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/TgaImporter) if(BUILD_TESTS) add_library(TgaImporterTestLib SHARED $) - target_link_libraries(TgaImporterTestLib ${MAGNUM_LIBRARIES}) + target_link_libraries(TgaImporterTestLib Magnum) add_subdirectory(Test) endif() diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 7f08d8c62..67dd92e7a 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -26,9 +26,9 @@ #include #include #include -#include -#include +#include "ColorFormat.h" +#include "Trade/ImageData.h" #include "TgaImporter/TgaImporter.h" #include "configure.h" @@ -39,7 +39,7 @@ class TgaImporterTest: public TestSuite::Tester { public: TgaImporterTest(); - void openInexistent(); + void openNonexistent(); void openShort(); void paletted(); void compressed(); @@ -55,7 +55,7 @@ class TgaImporterTest: public TestSuite::Tester { }; TgaImporterTest::TgaImporterTest() { - addTests({&TgaImporterTest::openInexistent, + addTests({&TgaImporterTest::openNonexistent, &TgaImporterTest::openShort, &TgaImporterTest::paletted, &TgaImporterTest::compressed, @@ -70,13 +70,13 @@ TgaImporterTest::TgaImporterTest() { &TgaImporterTest::file}); } -void TgaImporterTest::openInexistent() { +void TgaImporterTest::openNonexistent() { std::ostringstream debug; Error::setOutput(&debug); TgaImporter importer; - CORRADE_VERIFY(!importer.openFile("inexistent.file")); - CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::openFile(): cannot open file inexistent.file\n"); + CORRADE_VERIFY(!importer.openFile("nonexistent.file")); + CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::openFile(): cannot open file nonexistent.file\n"); } void TgaImporterTest::openShort() { diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index b941d19c3..353c03da0 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -28,14 +28,16 @@ #include #include #include -#include -#include + +#include "ColorFormat.h" +#include "Trade/ImageData.h" #ifdef MAGNUM_TARGET_GLES #include -#include -#include -#include +#include "Math/Swizzle.h" +#include "Math/Vector4.h" +#include "Context.h" +#include "Extensions.h" #endif #include "TgaHeader.h" @@ -44,11 +46,11 @@ namespace Magnum { namespace Trade { namespace { constexpr Math::Vector3 bgr(const Math::Vector3& vec) { - return swizzle<'b', 'g', 'r'>(vec); + return Math::swizzle<'b', 'g', 'r'>(vec); } constexpr Math::Vector4 bgra(const Math::Vector4& vec) { - return swizzle<'b', 'g', 'r', 'a'>(vec); + return Math::swizzle<'b', 'g', 'r', 'a'>(vec); } } diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 95deeeebb..3a5e2c497 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -51,8 +51,8 @@ This plugin is built if `WITH_TGAIMPORTER` is enabled in CMake. To use dynamic plugin, you need to load `%TgaImporter` plugin from `importers/` subdirectory of your plugin dir. To use static plugin or use this as a dependency of another plugin, you need to request `%TgaImporter` component in CMake and link to -`${MAGNUMPLUGINS_TGAIMPORTER_LIBRARIES}`. See @ref building-plugins and -@ref cmake-plugins for more information. +`${MAGNUM_TGAIMPORTER_LIBRARIES}`. See @ref building and @ref cmake for more +information. The images are imported with @ref ColorType::UnsignedByte and @ref ColorFormat::BGR, @ref ColorFormat::BGRA or @ref ColorFormat::Red, respectively. Grayscale images diff --git a/src/Plugins/WavAudioImporter/CMakeLists.txt b/src/Plugins/WavAudioImporter/CMakeLists.txt index 71bce608f..4f25d3ab6 100644 --- a/src/Plugins/WavAudioImporter/CMakeLists.txt +++ b/src/Plugins/WavAudioImporter/CMakeLists.txt @@ -22,9 +22,7 @@ # DEALINGS IN THE SOFTWARE. # -find_package(Magnum REQUIRED Audio) - -include_directories(${MAGNUM_AUDIO_INCLUDE_DIRS}) +include_directories(${OPENAL_INCLUDE_DIR}) set(WavAudioImporter_SRCS WavImporter.cpp) @@ -40,12 +38,12 @@ add_plugin(WavAudioImporter ${MAGNUM_PLUGINS_AUDIOIMPORTER_INSTALL_DIR} WavAudioImporter.conf $ pluginRegistrationWavAudioImporter.cpp) -target_link_libraries(WavAudioImporter ${MAGNUM_LIBRARIES} ${MAGNUM_AUDIO_LIBRARIES}) +target_link_libraries(WavAudioImporter Magnum MagnumAudio) install(FILES ${WavAudioImporter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/WavAudioImporter) if(BUILD_TESTS) add_library(WavAudioImporterTestLib STATIC $) - target_link_libraries(WavAudioImporterTestLib ${MAGNUM_LIBRARIES} ${MAGNUM_AUDIO_LIBRARIES}) + target_link_libraries(WavAudioImporterTestLib Magnum MagnumAudio) add_subdirectory(Test) endif() diff --git a/src/Plugins/WavAudioImporter/WavHeader.h b/src/Plugins/WavAudioImporter/WavHeader.h index e472b8f5f..32779d21c 100644 --- a/src/Plugins/WavAudioImporter/WavHeader.h +++ b/src/Plugins/WavAudioImporter/WavHeader.h @@ -28,7 +28,7 @@ * @brief Struct Magnum::Audio::WavHeader */ -#include +#include "Types.h" namespace Magnum { namespace Audio { diff --git a/src/Plugins/WavAudioImporter/WavImporter.h b/src/Plugins/WavAudioImporter/WavImporter.h index fe7f8010e..12fae4634 100644 --- a/src/Plugins/WavAudioImporter/WavImporter.h +++ b/src/Plugins/WavAudioImporter/WavImporter.h @@ -30,7 +30,8 @@ #include #include -#include