diff --git a/modules/FindEGL.cmake b/modules/FindEGL.cmake new file mode 100644 index 0000000..5fbe6ad --- /dev/null +++ b/modules/FindEGL.cmake @@ -0,0 +1,85 @@ +#.rst: +# Find EGL +# -------- +# +# Finds the EGL library. This module defines: +# +# EGL_FOUND - True if EGL library is found +# EGL::EGL - EGL imported target +# +# Additionally these variables are defined for internal usage: +# +# EGL_LIBRARY - EGL library +# EGL_INCLUDE_DIR - Include dir +# + +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 +# 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. +# + +# Library +if(NOT CORRADE_TARGET_EMSCRIPTEN) + find_library(EGL_LIBRARY NAMES + EGL + + # ANGLE (CMake doesn't search for lib prefix on Windows) + libEGL + + # On iOS a part of OpenGLES + OpenGLES) + set(EGL_LIBRARY_NEEDED EGL_LIBRARY) +endif() + +# Include dir +find_path(EGL_INCLUDE_DIR NAMES + EGL/egl.h + + # iOS + EAGL.h) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(EGL DEFAULT_MSG + ${EGL_LIBRARY_NEEDED} + EGL_INCLUDE_DIR) + +if(NOT TARGET EGL::EGL) + if(EGL_LIBRARY_NEEDED) + # Work around BUGGY framework support on macOS + # http://public.kitware.com/pipermail/cmake/2016-April/063179.html + if(APPLE AND ${EGL_LIBRARY} MATCHES "\\.framework$") + add_library(EGL::EGL INTERFACE IMPORTED) + set_property(TARGET EGL::EGL APPEND PROPERTY + INTERFACE_LINK_LIBRARIES ${EGL_LIBRARY}) + else() + add_library(EGL::EGL UNKNOWN IMPORTED) + set_property(TARGET EGL::EGL PROPERTY + IMPORTED_LOCATION ${EGL_LIBRARY}) + endif() + else() + add_library(EGL::EGL INTERFACE IMPORTED) + endif() + + set_target_properties(EGL::EGL PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${EGL_INCLUDE_DIR}) +endif() diff --git a/src/python/magnum/CMakeLists.txt b/src/python/magnum/CMakeLists.txt index 5017980..df8bcc1 100644 --- a/src/python/magnum/CMakeLists.txt +++ b/src/python/magnum/CMakeLists.txt @@ -41,3 +41,5 @@ set_target_properties(magnum PROPERTIES file(GENERATE OUTPUT ${output_dir}/magnum/__init__.py INPUT ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py) + +add_subdirectory(platform) diff --git a/src/python/magnum/platform/CMakeLists.txt b/src/python/magnum/platform/CMakeLists.txt new file mode 100644 index 0000000..86b3d37 --- /dev/null +++ b/src/python/magnum/platform/CMakeLists.txt @@ -0,0 +1,52 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 +# 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. +# + +# *Not* REQUIRED +find_package(Magnum COMPONENTS + WindowlessEglApplication + WindowlessGlxApplication) + +if(Magnum_WindowlessEglApplication_FOUND) + pybind11_add_module(magnum_platform_egl egl.cpp) + target_link_libraries(magnum_platform_egl PRIVATE Magnum::WindowlessEglApplication) + target_include_directories(magnum_platform_egl PRIVATE ${PROJECT_SOURCE_DIR}/src/python) + set_target_properties(magnum_platform_egl PROPERTIES + FOLDER "python/platform" + OUTPUT_NAME "egl" + LIBRARY_OUTPUT_DIRECTORY ${output_dir}/magnum/platform) +endif() + +if(Magnum_WindowlessGlxApplication_FOUND) + pybind11_add_module(magnum_platform_glx glx.cpp) + target_link_libraries(magnum_platform_glx PRIVATE Magnum::WindowlessGlxApplication) + target_include_directories(magnum_platform_glx PRIVATE ${PROJECT_SOURCE_DIR}/src/python) + set_target_properties(magnum_platform_glx PROPERTIES + FOLDER "python/platform" + OUTPUT_NAME "glx" + LIBRARY_OUTPUT_DIRECTORY ${output_dir}/magnum/platform) +endif() + +file(GENERATE OUTPUT ${output_dir}/magnum/platform/__init__.py + INPUT ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py) diff --git a/src/python/magnum/platform/__init__.py b/src/python/magnum/platform/__init__.py new file mode 100644 index 0000000..3a75080 --- /dev/null +++ b/src/python/magnum/platform/__init__.py @@ -0,0 +1,34 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 +# 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. +# + +"""Platform-specific application and context creation""" + +try: + from .glx import WindowlessApplication +except ImportError: # pragma: no cover + try: + from .egl import WindowlessApplication + except ImportError: + pass diff --git a/src/python/magnum/platform/egl.cpp b/src/python/magnum/platform/egl.cpp new file mode 100644 index 0000000..c1b291d --- /dev/null +++ b/src/python/magnum/platform/egl.cpp @@ -0,0 +1,60 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 + 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 +#include + +#include "magnum/bootstrap.h" +#include "magnum/platform/windowlessapplication.h" + +namespace magnum { namespace platform { namespace { + +int argc = 0; + +void egl(py::module& m) { + struct PyWindowlessApplication: Platform::WindowlessApplication { + explicit PyWindowlessApplication(const Configuration& configuration = Configuration{}): Platform::WindowlessApplication{Arguments{argc, nullptr}, configuration} {} + + int exec() override { + PYBIND11_OVERLOAD_PURE_NAME( + int, + PyWindowlessApplication, + "exec", + ); + } + }; + + py::class_ windowlessEglApplication{m, "WindowlessApplication", "Windowless EGL application"}; + + windowlessapplication(windowlessEglApplication); +} + +}}} + +PYBIND11_MODULE(egl, m) { + m.doc() = "EGL-based platform integration"; + + magnum::platform::egl(m); +} diff --git a/src/python/magnum/platform/glx.cpp b/src/python/magnum/platform/glx.cpp new file mode 100644 index 0000000..21631e6 --- /dev/null +++ b/src/python/magnum/platform/glx.cpp @@ -0,0 +1,60 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 + 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 +#include + +#include "magnum/bootstrap.h" +#include "magnum/platform/windowlessapplication.h" + +namespace magnum { namespace platform { namespace { + +int argc = 0; + +void glx(py::module& m) { + struct PyWindowlessApplication: Platform::WindowlessApplication { + explicit PyWindowlessApplication(const Configuration& configuration = Configuration{}): Platform::WindowlessApplication{Arguments{argc, nullptr}, configuration} {} + + int exec() override { + PYBIND11_OVERLOAD_PURE_NAME( + int, + PyWindowlessApplication, + "exec", + ); + } + }; + + py::class_ windowlessGlxApplication{m, "WindowlessApplication", "Windowless GLX application"}; + + windowlessapplication(windowlessGlxApplication); +} + +}}} + +PYBIND11_MODULE(glx, m) { + m.doc() = "GLX-based platform integration"; + + magnum::platform::glx(m); +} diff --git a/src/python/magnum/platform/windowlessapplication.h b/src/python/magnum/platform/windowlessapplication.h new file mode 100644 index 0000000..9e303ce --- /dev/null +++ b/src/python/magnum/platform/windowlessapplication.h @@ -0,0 +1,49 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 + 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 + +#include "magnum/bootstrap.h" + +namespace magnum { namespace platform { + +template void windowlessapplication(py::class_& c) { + py::class_ configuration{c, "Configuration", "Configuration"}; + configuration + .def(py::init()); + /** @todo others */ + + c + /* Constructor */ + .def(py::init(), py::arg("configuration") = typename T::Configuration{}, + "Constructor") + /** @todo the nocreate ones */ + + .def("exec", &T::exec, "Execute application") + /** @todo more */ + ; +} + +}} diff --git a/src/python/setup.py.cmake b/src/python/setup.py.cmake index ddbb1f6..e538ff6 100644 --- a/src/python/setup.py.cmake +++ b/src/python/setup.py.cmake @@ -33,6 +33,8 @@ extension_paths = { # Filled in by cmake 'corrade.containers': '$', 'magnum._magnum': '$', + 'magnum.platform.egl': '$<$:$>', + 'magnum.platform.glx': '$<$:$>', } class TheExtensionIsAlreadyBuiltWhyThisHasToBeSoDamnComplicated(build_ext): @@ -42,7 +44,7 @@ class TheExtensionIsAlreadyBuiltWhyThisHasToBeSoDamnComplicated(build_ext): setup( name='magnum', - packages=['corrade', 'magnum'], + packages=['corrade', 'magnum', 'magnum.platform'], ext_modules=[Extension(name, sources=[]) for name, path in extension_paths.items() if path], cmdclass = { 'build_ext': TheExtensionIsAlreadyBuiltWhyThisHasToBeSoDamnComplicated