diff --git a/CMakeLists.txt b/CMakeLists.txt index cf29c4e72..43804efc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,16 +61,19 @@ elseif(CORRADE_TARGET_ANDROID) # OS X-specific application libraries elseif(CORRADE_TARGET_APPLE) cmake_dependent_option(WITH_WINDOWLESSCGLAPPLICATION "Build WindowlessCglApplication library" OFF "NOT WITH_MAGNUMINFO;NOT WITH_FONTCONVERTER;NOT WITH_DISTANCEFIELDCONVERTER" ON) + cmake_dependent_option(WITH_CGLCONTEXT "Build CglContext library" OFF "NOT TARGET_GLES" OFF) # X11, GLX and EGL-specific application libraries elseif(CORRADE_TARGET_UNIX) option(WITH_GLXAPPLICATION "Build GlxApplication library" OFF) cmake_dependent_option(WITH_WINDOWLESSGLXAPPLICATION "Build WindowlessGlxApplication library" OFF "NOT WITH_MAGNUMINFO;NOT WITH_FONTCONVERTER;NOT WITH_DISTANCEFIELDCONVERTER" ON) cmake_dependent_option(WITH_XEGLAPPLICATION "Build XEglApplication library" OFF "TARGET_GLES" OFF) + cmake_dependent_option(WITH_GLXCONTEXT "Build GlxContext library" OFF "NOT TARGET_GLES" OFF) # Windows-specific application libraries elseif(CORRADE_TARGET_WINDOWS) cmake_dependent_option(WITH_WINDOWLESSWGLAPPLICATION "Build WindowlessWglApplication library" OFF "NOT WITH_MAGNUMINFO;NOT WITH_FONTCONVERTER;NOT WITH_DISTANCEFIELDCONVERTER" ON) + cmake_dependent_option(WITH_WGLCONTEXT "Build WglContext library" OFF "NOT TARGET_GLES" OFF) endif() # Platform-independent (almost) application libraries diff --git a/doc/building.dox b/doc/building.dox index b4f38134e..2713c8614 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -205,6 +205,14 @@ platform best: - `WITH_WINDOWLESSNACLAPPLICATION` - @ref Platform::WindowlessNaClApplication "WindowlessNaClApplication" - `WITH_WINDOWLESSWGLAPPLICATION` - @ref Platform::WindowlessWglApplication "WindowlessWglApplication" +None of the context libraries is built by default. You need them only if you +choose to not use any application library (see @ref platform-custom for more +information): + +- `WITH_CGLCONTEXT` -- CGL context +- `WITH_GLXCONTEXT` -- GLX context +- `WITH_WGLCONTEXT` -- WGL context + There are also a few command-line utilities. They are currently available only on Linux, Mac OS X and Windows, also disabled by default: diff --git a/doc/cmake.dox b/doc/cmake.dox index b586ae336..1618241b5 100644 --- a/doc/cmake.dox +++ b/doc/cmake.dox @@ -102,6 +102,13 @@ Platform namespace is split into more components: - `%WindowlessNaClApplication` -- @ref Platform::WindowlessNaClApplication "WindowlessNaClApplication" - `%WindowlessWglApplication` -- @ref Platform::WindowlessWglApplication "WindowlessWglApplication" +For manual context creation (without application wrappers) there are also +platform-specific context libraries: + +- `CglContext` -- CGL context +- `GlxContext` -- GLX context +- `WglContext` -- WGL context + 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 @@ -143,7 +150,10 @@ If exactly one `*Application` or exactly one `Windowless*Application` component is requested and found, its libraries and include dirs are available in convenience aliases `MAGNUM_APPLICATION_LIBRARIES` / `MAGNUM_WINDOWLESSAPPLICATION_LIBRARIES` and `MAGNUM_APPLICATION_INCLUDE_DIRS` -/ `MAGNUM_WINDOWLESSAPPLICATION_INCLUDE_DIRS` to simplify porting. +/ `MAGNUM_WINDOWLESSAPPLICATION_INCLUDE_DIRS` to simplify porting. Similarly, +if exactly one `*Context` component is requested and found, its libraries and +include dirs are available in convenience aliases `MAGNUM_CONTEXT_LIBRARIES` +and `MAGNUM_CONTEXT_INCLUDE_DIRS`. The package is found if either debug or release version of each requested library (or plugin) is found. If both debug and release libraries (or plugins) diff --git a/doc/platform.dox b/doc/platform.dox index 54798e3df..3f23085b8 100644 --- a/doc/platform.dox +++ b/doc/platform.dox @@ -287,6 +287,35 @@ int main(int argc, char** argv) { } @endcode +On majority of platforms the @ref Platform::Context class does GL function +pointer loading using platform-specific APIs. In that case you also need to +find particular `*Context` library, add its include dir and then link to it. +These platform-specific libraries are available: + +- `CglContext` -- CGL context +- `GlxContext` -- GLX context +- `WglContext` -- WGL context + +Systems not listed here (such as Emscripten or NaCl) don't need any Context +library, because dynamic function pointer loading is not available on these. + +For example, when you create the OpenGL context using GLX, you need to find +`GlxContext` component, include `${MAGNUM_GLCCONTEXT_INCLUDE_DIRS}` and link to +`${MAGNUM_GLXCONTEXT_LIBRARIES}`. Similarly to application libraries, you can +also use generic `${MAGNUM_CONTEXT_INCLUDE_DIRS}` and `${MAGNUM_CONTEXT_LIBRARIES}`, +providing you requested only one `*Context` component in the `find_package()` +call. Complete example: +@code +find_package(Magnum REQUIRED GlxContext) + +include_directories(${MAGNUM_INCLUDE_DIRS} ${MAGNUM_CONTEXT_INCLUDE_DIRS}) + +add_executable(myapplication MyCustomApplication.cpp) +target_link_libraries(myapplication + ${MAGNUM_LIBRARIES} + ${MAGNUM_CONTEXT_LIBRARIES}) +@endcode + - Next page: @ref types */ }} diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 4c2a4b769..a89527f4b 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -60,6 +60,9 @@ # WindowlessGlxApplication - Windowless GLX application # WindowlessNaClApplication - Windowless NaCl application # WindowlessWglApplication - Windowless WGL application +# CglContext - CGL context +# GlxContext - GLX context +# WglContext - WGL context # Example usage with specifying additional components is: # find_package(Magnum [REQUIRED|COMPONENTS] # MeshTools Primitives GlutApplication) @@ -71,7 +74,10 @@ # component is requested and found, its libraries and include dirs are # available in convenience aliases MAGNUM_APPLICATION_LIBRARIES / # MAGNUM_WINDOWLESSAPPLICATION_LIBRARIES and MAGNUM_APPLICATION_INCLUDE_DIRS -# / MAGNUM_WINDOWLESSAPPLICATION_INCLUDE_DIRS to simplify porting. +# / MAGNUM_WINDOWLESSAPPLICATION_INCLUDE_DIRS to simplify porting. Similarly, +# if exactly one *Context component is requested and found, its libraries and +# include dirs are available in convenience aliases MAGNUM_CONTEXT_LIBRARIES +# and MAGNUM_CONTEXT_INCLUDE_DIRS. # # The package is found if either debug or release version of each requested # library (or plugin) is found. If both debug and release libraries (or @@ -409,6 +415,24 @@ foreach(component ${Magnum_FIND_COMPONENTS}) ${_MAGNUM_${_COMPONENT}_LIBRARIES} ${_WINDOWCONTEXT_MAGNUM_LIBRARIES_DEPENDENCY}) + # Context libraries + elseif(${component} MATCHES .+Context) + set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/Platform) + set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Context.h) + + # GLX context dependencies + if(${component} STREQUAL GlxStub) + find_package(X11) + if(X11_FOUND) + set(_MAGNUM_${_COMPONENT}_LIBRARIES ${X11_LIBRARIES}) + else() + unset(MAGNUM_${_COMPONENT}_LIBRARY) + endif() + endif() + + # No additional dependencies for CGL context + # No additional dependencies for WGL context + # Audio library elseif(${component} STREQUAL Audio) find_package(OpenAL) @@ -475,6 +499,18 @@ foreach(component ${Magnum_FIND_COMPONENTS}) unset(MAGNUM_APPLICATION_INCLUDE_DIRS) endif() endif() + + # Global aliases for *Context components. If already set, unset them to + # avoid ambiguity. + if(${component} MATCHES .+Context) + if(NOT DEFINED MAGNUM_CONTEXT_LIBRARIES AND NOT DEFINED MAGNUM_CONTEXT_INCLUDE_DIRS) + set(MAGNUM_CONTEXT_LIBRARIES ${MAGNUM_${_COMPONENT}_LIBRARIES}) + set(MAGNUM_CONTEXT_INCLUDE_DIRS ${MAGNUM_${_COMPONENT}_INCLUDE_DIRS}) + else() + unset(MAGNUM_CONTEXT_LIBRARIES) + unset(MAGNUM_CONTEXT_INCLUDE_DIRS) + endif() + endif() else() set(Magnum_${component}_FOUND FALSE) endif() diff --git a/src/Magnum/Platform/CMakeLists.txt b/src/Magnum/Platform/CMakeLists.txt index 90714f76d..88018dfe3 100644 --- a/src/Magnum/Platform/CMakeLists.txt +++ b/src/Magnum/Platform/CMakeLists.txt @@ -365,19 +365,52 @@ if(NOT MAGNUM_TARGET_GLES) endif() # CGL context -if(NEED_CGLCONTEXT) +if(NEED_CGLCONTEXT OR WITH_CGLCONTEXT) add_library(MagnumCglContextObjects OBJECT ${MagnumContext_SRCS}) + + # Also create proper static library, if requested + if(WITH_CGLCONTEXT) + # CMake-generated XCode projects had some problems when library + # consisted only of $ entries, thus compiling the + # sources again in this case + add_library(MagnumCglContext STATIC ${MagnumContext_SRCS}) + set_target_properties(MagnumCglContext PROPERTIES DEBUG_POSTFIX "-d") + install(TARGETS MagnumCglContext + RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} + LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} + ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) + endif() endif() # GLX context -if(NEED_GLXCONTEXT) +if(NEED_GLXCONTEXT OR WITH_GLXCONTEXT) add_library(MagnumGlxContextObjects OBJECT ${MagnumContext_SRCS}) set_target_properties(MagnumGlxContextObjects PROPERTIES COMPILE_DEFINITIONS "MAGNUM_PLATFORM_USE_GLX") + + # Also create proper static library, if requested + if(WITH_GLXCONTEXT) + add_library(MagnumGlxContext STATIC $) + set_target_properties(MagnumGlxContext PROPERTIES DEBUG_POSTFIX "-d") + install(TARGETS MagnumGlxContext + RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} + LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} + ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) + endif() endif() # WGL context -if(NEED_WGLCONTEXT) +if(NEED_WGLCONTEXT OR WITH_WGLCONTEXT) add_library(MagnumWglContextObjects OBJECT ${MagnumContext_SRCS}) + + # Also create proper static library, if requested + if(WITH_GLXCONTEXT) + add_library(MagnumWglContext STATIC $) + set_target_properties(MagnumWglContext PROPERTIES DEBUG_POSTFIX "-d") + install(TARGETS MagnumWglContext + RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} + LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} + ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) + endif() endif() # Magnum Info