Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Octree View Frustum Culling Example #27

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ option(WITH_AUDIO_EXAMPLE "Build audio example (requires Magnum Audio library)"
option(WITH_BULLET_EXAMPLE "Build Bullet integration example (requires BulletIntegration library)" OFF)
cmake_dependent_option(WITH_CUBEMAP_EXAMPLE "Build CubeMap example (requires JpegImporter plugin)" OFF "NOT MAGNUM_TARGET_GLES" OFF)
cmake_dependent_option(WITH_MOTIONBLUR_EXAMPLE "Build MotionBlur example" OFF "NOT MAGNUM_TARGET_GLES" OFF)
option(WITH_OCTREE_EXAMPLE "Build Octree: example" OFF)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the : is superfluous

option(WITH_OVR_EXAMPLE "Build OVR example" OFF)
option(WITH_PICKING_EXAMPLE "Build Picking example" OFF)
option(WITH_PRIMITIVES_EXAMPLE "Build Primitives example" OFF)
Expand Down
210 changes: 210 additions & 0 deletions modules/FindMagnumExtras.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
#.rst:
# Find Magnum extras
# ------------------
#
# Finds Magnum extras. Basic usage::
#
# find_package(MagnumExtras REQUIRED)
#
# This command tries to find Magnum extras and then defines the following:
#
# MagnumExtras_FOUND - Whether Magnum extras were found
#
# This command alone is useless without specifying the components:
#
# Octree - Octree BSP structure for Magnum::SceneGraph
#
# Example usage with specifying additional components is:
#
# find_package(MagnumExtras REQUIRED SomeLibraryThatDoesntExistYet)
#
# For each component is then defined:
#
# MagnumExtras_*_FOUND - Whether the component was found
# MagnumExtras::* - Component imported target
#
# The package is found if either debug or release version of each requested
# library is found. If both debug and release libraries are found, proper
# version is chosen based on actual build configuration of the project (i.e.
# Debug build is linked to debug libraries, Release build to release
# libraries).
#
# Additionally these variables are defined for internal usage:
#
# MAGNUMEXTRAS_INCLUDE_DIR - Magnum extras include dir (w/o
# dependencies)
# MAGNUMEXTRAS_*_LIBRARY_DEBUG - Debug version of given library, if found
# MAGNUMEXTRAS_*_LIBRARY_RELEASE - Release version of given library, if
# found
#

#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016
# Vladimír Vondruš <mosra@centrum.cz>
# Copyright © 2016 Jonathan Hale <squareys@googlemail.com>
#
# 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.
#

# Corrade library dependencies
set(_MAGNUMEXTRAS_CORRADE_DEPENDENCIES )

foreach(_component ${MagnumExtras_FIND_COMPONENTS})
string(TOUPPER ${_component} _COMPONENT)

# (none yet)

list(APPEND _MAGNUMEXTRAS_CORRADE_DEPENDENCIES ${_MAGNUMEXTRAS_${_COMPONENT}_CORRADE_DEPENDENCIES})
endforeach()
find_package(Corrade REQUIRED ${_MAGNUMEXTRAS_CORRADE_DEPENDENCIES})

# Magnum library dependencies
set(_MAGNUMEXTRAS_MAGNUM_DEPENDENCIES )
foreach(_component ${MagnumExtras_FIND_COMPONENTS})
string(TOUPPER ${_component} _COMPONENT)

if(_component MATCHES Octree)
set(_MAGNUMEXTRAS_${_COMPONENT}_MAGNUM_DEPENDENCIES Shapes)
endif()

if(_component MATCHES SceneGraph)
set(_MAGNUMEXTRAS_${_COMPONENT}_MAGNUM_DEPENDENCIES SceneGraph)
endif()

list(APPEND _MAGNUMEXTRAS_MAGNUM_DEPENDENCIES ${_MAGNUMEXTRAS_${_COMPONENT}_MAGNUM_DEPENDENCIES})
endforeach()
find_package(Magnum REQUIRED ${_MAGNUMEXTRAS_MAGNUM_DEPENDENCIES})

# Global integration include dir
find_path(MAGNUMEXTRAS_INCLUDE_DIR Magnum
HINTS ${MAGNUM_INCLUDE_DIR})
mark_as_advanced(MAGNUMEXTRAS_INCLUDE_DIR)

# Ensure that all inter-component dependencies are specified as well
set(_MAGNUMEXTRAS_ADDITIONAL_COMPONENTS )
foreach(_component ${MagnumExtras_FIND_COMPONENTS})
string(TOUPPER ${_component} _COMPONENT)

# (no inter-component dependencies yet)
if(_component MATCHES SceneGraph)
set(_MAGNUMEXTRAS_${_COMPONENT}_DEPENDENCIES Octree)
endif()

# Mark the dependencies as required if the component is also required
if(MagnumExtras_FIND_REQUIRED_${_component})
foreach(_dependency ${})
set(MagnumExtras_FIND_REQUIRED_${_dependency} TRUE)
endforeach()
endif()

list(APPEND _MAGNUMEXTRAS_ADDITIONAL_COMPONENTS ${_MAGNUMEXTRAS_${_COMPONENT}_DEPENDENCIES})
endforeach()

# Join the lists, remove duplicate components
if(_MAGNUMEXTRAS_ADDITIONAL_COMPONENTS)
list(INSERT MagnumExtras_FIND_COMPONENTS 0 ${_MAGNUMEXTRAS_ADDITIONAL_COMPONENTS})
endif()
if(MagnumExtras_FIND_COMPONENTS)
list(REMOVE_DUPLICATES MagnumExtras_FIND_COMPONENTS)
endif()

# Component distinction (listing them explicitly to avoid mistakes with finding
# components from other repositories)
set(_MAGNUMEXTRAS_LIBRARY_COMPONENTS "(Octree|SceneGraph)")

# Additional components
foreach(_component ${MagnumExtras_FIND_COMPONENTS})
string(TOUPPER ${_component} _COMPONENT)

# Create imported target in case the library is found. If the project is
# added as subproject to CMake, the target already exists and all the
# required setup is already done from the build tree.
if(TARGET MagnumExtras::${_component})
set(MagnumExtras_${_component}_FOUND TRUE)
else()
# Library components
if(_component MATCHES ${_MAGNUMEXTRAS_LIBRARY_COMPONENTS})
add_library(MagnumExtras::${_component} UNKNOWN IMPORTED)

# Try to find both debug and release version
find_library(MAGNUMEXTRAS_${_COMPONENT}_LIBRARY_DEBUG Magnum${_component}-d)
find_library(MAGNUMEXTRAS_${_COMPONENT}_LIBRARY_RELEASE Magnum${_component})
mark_as_advanced(MAGNUMEXTRAS_${_COMPONENT}_LIBRARY_DEBUG
MAGNUMEXTRAS_${_COMPONENT}_LIBRARY_RELEASE)

if(MAGNUMEXTRAS_${_COMPONENT}_LIBRARY_RELEASE)
set_property(TARGET MagnumExtras::${_component} APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
set_property(TARGET MagnumExtras::${_component} PROPERTY
IMPORTED_LOCATION_RELEASE ${MAGNUMEXTRAS_${_COMPONENT}_LIBRARY_RELEASE})
endif()

if(MAGNUMEXTRAS_${_COMPONENT}_LIBRARY_DEBUG)
set_property(TARGET MagnumExtras::${_component} APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG)
set_property(TARGET MagnumExtras::${_component} PROPERTY
IMPORTED_LOCATION_DEBUG ${MAGNUMEXTRAS_${_COMPONENT}_LIBRARY_DEBUG})
endif()
endif()

# (none yet)

# Find library includes
if(_component MATCHES ${_MAGNUMEXTRAS_LIBRARY_COMPONENTS})
find_path(_MAGNUMEXTRAS_${_COMPONENT}_INCLUDE_DIR
NAMES ${_component}.h
HINTS ${MAGNUMEXTRAS_INCLUDE_DIR}/Magnum/${_component})
endif()

if(_component MATCHES ${_MAGNUMEXTRAS_LIBRARY_COMPONENTS})
# Link to Corrade dependencies, link to core Magnum library and
# other Magnum dependencies
foreach(_dependency ${_MAGNUMEXTRAS_${_COMPONENT}_CORRADE_DEPENDENCIES})
set_property(TARGET MagnumExtras::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES Corrade::${_dependency})
endforeach()
set_property(TARGET MagnumExtras::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES Magnum::Magnum)
foreach(_dependency ${_MAGNUMEXTRAS_${_COMPONENT}_MAGNUM_DEPENDENCIES})
set_property(TARGET MagnumExtras::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES Magnum::${_dependency})
endforeach()

# Add inter-project dependencies
foreach(_dependency ${_MAGNUMEXTRAS_${_COMPONENT}_DEPENDENCIES})
set_property(TARGET MagnumExtras::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES MagnumExtras::${_dependency})
endforeach()
endif()

# Decide if the library was found
if(_component MATCHES ${_MAGNUMEXTRAS_LIBRARY_COMPONENTS} AND _MAGNUMEXTRAS_${_COMPONENT}_INCLUDE_DIR AND (MAGNUMEXTRAS_${_COMPONENT}_LIBRARY_DEBUG OR MAGNUMEXTRAS_${_COMPONENT}_LIBRARY_RELEASE))
set(MagnumExtras_${_component}_FOUND TRUE)
else()
set(MagnumExtras_${_component}_FOUND FALSE)
endif()
endif()
endforeach()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MagnumExtras
REQUIRED_VARS MAGNUMEXTRAS_INCLUDE_DIR
HANDLE_COMPONENTS)
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ if(WITH_MOTIONBLUR_EXAMPLE)
add_subdirectory(motionblur)
endif()

if(WITH_OCTREE_EXAMPLE)
add_subdirectory(octree)
endif()

if(WITH_OVR_EXAMPLE)
add_subdirectory(ovr)
endif()
Expand Down
65 changes: 65 additions & 0 deletions src/octree/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015
# Vladimír Vondruš <mosra@centrum.cz>
# Copyright © 2015 Jonathan Hale <squareys@googlemail.com>
#
# 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.
#

cmake_minimum_required(VERSION 2.8.12)
project(MagnumOctreeExample)

# CMake policies: enable MACOSX_RPATH by default
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()
# Don't treat imported targets with :: as files
if(POLICY CMP0028)
cmake_policy(SET CMP0028 NEW)
endif()

find_package(Magnum REQUIRED
SceneGraph
Shaders
Primitives
Sdl2Application)

find_package(MagnumExtras REQUIRED
Octree
SceneGraph)


set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CORRADE_CXX_FLAGS}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace with

set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)

Also please no more than one successive empty line ;)


add_executable(magnum-octree OctreeExample.cpp)
target_link_libraries(magnum-octree
Magnum::Shaders
Magnum::SceneGraph
Magnum::Primitives
Magnum::Application
MagnumExtras::Octree
MagnumExtras::SceneGraph
Magnum::Magnum)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you order the libraries so all Magnum:: are together? If the link order matters, then there is a problem in the FindMagnumExtras.cmake module (each imported target should have its dependencies implicitly and not expect the user to link the dependencies explicitly).


target_compile_features(magnum-octree PRIVATE cxx_range_for)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed (we expect C++11 conforming compiler).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, I put that there, because the c++11 flag was not set for my compiler.


install(TARGETS magnum-octree DESTINATION ${MAGNUM_BINARY_INSTALL_DIR})
install(FILES README.md DESTINATION ${MAGNUM_DATA_INSTALL_DIR}/examples RENAME README-octree.md)
Loading