diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index 7356df0..8621d61 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -67,6 +67,7 @@ foreach(target magnum_primitives magnum_scenegraph magnum_shaders + magnum_platform_cgl magnum_platform_egl magnum_platform_glx magnum_platform_glfw diff --git a/src/python/magnum/CMakeLists.txt b/src/python/magnum/CMakeLists.txt index 09e3432..f0a0410 100644 --- a/src/python/magnum/CMakeLists.txt +++ b/src/python/magnum/CMakeLists.txt @@ -42,6 +42,9 @@ find_package(Magnum COMPONENTS # Find platform-specific apps only on the platforms where it matters, so we # don't get confusing -- Could NOT find WindowlessWglApplication on Linux and # such +if(CORRADE_TARGET_APPLE AND NOT MAGNUM_TARGET_GLES) + find_package(Magnum COMPONENTS WindowlessCglApplication) +endif() if(CORRADE_TARGET_UNIX OR MAGNUM_TARGET_GLES) find_package(Magnum COMPONENTS WindowlessEglApplication) endif() @@ -215,6 +218,11 @@ else() list(APPEND magnum_LIBS Magnum::Sdl2Application) endif() + if(Magnum_WindowlessCglApplication_FOUND) + list(APPEND magnum_SRCS platform/cgl.cpp) + list(APPEND magnum_LIBS Magnum::WindowlessCglApplication) + endif() + if(Magnum_WindowlessEglApplication_FOUND) list(APPEND magnum_SRCS platform/egl.cpp) list(APPEND magnum_LIBS Magnum::WindowlessEglApplication) diff --git a/src/python/magnum/__init__.py b/src/python/magnum/__init__.py index dbe3878..3e2278c 100644 --- a/src/python/magnum/__init__.py +++ b/src/python/magnum/__init__.py @@ -40,7 +40,7 @@ for i in ['gl', 'meshtools', 'platform', 'primitives', 'scenegraph', 'shaders', # Platform has subpackages if 'platform' in globals(): - for i in ['glfw', 'sdl2', 'glx', 'wgl', 'egl']: + for i in ['glfw', 'sdl2', 'cgl', 'glx', 'wgl', 'egl']: if hasattr(platform, i): sys.modules['magnum.platform.' + i] = getattr(platform, i) # Scenegraph has subpackages diff --git a/src/python/magnum/bootstrap.h b/src/python/magnum/bootstrap.h index 71a3007..9e81732 100644 --- a/src/python/magnum/bootstrap.h +++ b/src/python/magnum/bootstrap.h @@ -81,6 +81,7 @@ namespace platform { void glfw(py::module_& m); void sdl2(py::module_& m); + void cgl(py::module_& m); void egl(py::module_& m); void glx(py::module_& m); void wgl(py::module_& m); diff --git a/src/python/magnum/platform/CMakeLists.txt b/src/python/magnum/platform/CMakeLists.txt index b4ff0f2..6ddd60a 100644 --- a/src/python/magnum/platform/CMakeLists.txt +++ b/src/python/magnum/platform/CMakeLists.txt @@ -46,6 +46,15 @@ if(NOT MAGNUM_BUILD_STATIC) LIBRARY_OUTPUT_DIRECTORY ${output_dir}/magnum/platform) endif() + if(Magnum_WindowlessCglApplication_FOUND) + pybind11_add_module(magnum_platform_cgl ${pybind11_add_module_SYSTEM} cgl.cpp) + target_link_libraries(magnum_platform_cgl PRIVATE Magnum::WindowlessCglApplication) + target_include_directories(magnum_platform_cgl PRIVATE ${PROJECT_SOURCE_DIR}/src/python) + set_target_properties(magnum_platform_cgl PROPERTIES + OUTPUT_NAME "cgl" + LIBRARY_OUTPUT_DIRECTORY ${output_dir}/magnum/platform) + endif() + if(Magnum_WindowlessEglApplication_FOUND) pybind11_add_module(magnum_platform_egl ${pybind11_add_module_SYSTEM} egl.cpp) target_link_libraries(magnum_platform_egl PRIVATE Magnum::WindowlessEglApplication) diff --git a/src/python/magnum/platform/cgl.cpp b/src/python/magnum/platform/cgl.cpp new file mode 100644 index 0000000..3976a04 --- /dev/null +++ b/src/python/magnum/platform/cgl.cpp @@ -0,0 +1,90 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, + 2020, 2021, 2022 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 + +#include "magnum/bootstrap.h" +#include "magnum/platform/windowlessapplication.h" +#include "magnum/platform/holder.h" + +namespace magnum { namespace platform { + +namespace { + int argc = 0; +} + +void cgl(py::module_& m) { + m.doc() = "CGL-based platform integration"; + + struct PyWindowlessApplication: Platform::WindowlessApplication { + explicit PyWindowlessApplication(const Configuration& configuration = Configuration{}): Platform::WindowlessApplication{Arguments{argc, nullptr}, configuration} {} + + int exec() override { + #ifdef __clang__ + /* ugh pybind don't tell me I AM THE FIRST ON EARTH to get a + warning here. Why there's no PYBIND11_OVERLOAD_PURE_NAME_ARG() + variant *with* arguments and one without? */ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" + #endif + PYBIND11_OVERLOAD_PURE_NAME( + int, + PyWindowlessApplication, + "exec", + ); + #ifdef __clang__ + #pragma GCC diagnostic pop + #endif + } + + /* The base doesn't have a virtual destructor because in C++ it's never + deleted through a pointer to the base. Here we need it, though. */ + virtual ~PyWindowlessApplication() {} + }; + + py::class_> windowlessGlxApplication{m, "WindowlessApplication", "Windowless CGL application"}; + + windowlessapplication(windowlessGlxApplication); + + /* Exposing a subclass to avoid the same type being exposed in multiple + (glx, egl...) modules. */ + struct PyContext: Platform::GLContext {}; + py::class_ glContext{m, "Context", "CGL-specific Magnum OpenGL context"}; + + context(glContext); +} + +}} + +#ifndef MAGNUM_BUILD_STATIC +/* TODO: remove declaration when https://github.com/pybind/pybind11/pull/1863 + is released */ +extern "C" PYBIND11_EXPORT PyObject* PyInit_cgl(); +PYBIND11_MODULE(cgl, m) { + magnum::platform::cgl(m); +} +#endif diff --git a/src/python/magnum/staticconfigure.h.cmake b/src/python/magnum/staticconfigure.h.cmake index 1f75e8a..f357253 100644 --- a/src/python/magnum/staticconfigure.h.cmake +++ b/src/python/magnum/staticconfigure.h.cmake @@ -36,6 +36,7 @@ #cmakedefine Magnum_GlfwApplication_FOUND #cmakedefine Magnum_Sdl2Application_FOUND +#cmakedefine Magnum_WindowlessCglApplication_FOUND #cmakedefine Magnum_WindowlessEglApplication_FOUND #cmakedefine Magnum_WindowlessGlxApplication_FOUND #cmakedefine Magnum_WindowlessWglApplication_FOUND diff --git a/src/python/magnum/test/__init__.py b/src/python/magnum/test/__init__.py index d936110..3931c3d 100644 --- a/src/python/magnum/test/__init__.py +++ b/src/python/magnum/test/__init__.py @@ -37,12 +37,15 @@ try: from magnum.platform.glx import WindowlessApplication except ImportError: try: - from magnum.platform.wgl import WindowlessApplication + from magnum.platform.cgl import WindowlessApplication except ImportError: try: - from magnum.platform.egl import WindowlessApplication + from magnum.platform.wgl import WindowlessApplication except ImportError: - WindowlessApplication = None + try: + from magnum.platform.egl import WindowlessApplication + except ImportError: + WindowlessApplication = None def setUpModule(): if os.environ.get('MAGNUM_SKIP_GL_TESTS') == 'ON': diff --git a/src/python/setup.py.cmake b/src/python/setup.py.cmake index 1e0badd..c67964e 100644 --- a/src/python/setup.py.cmake +++ b/src/python/setup.py.cmake @@ -42,6 +42,7 @@ extension_paths = { 'magnum.primitives': '${magnum_primitives_file}', 'magnum.scenegraph': '${magnum_scenegraph_file}', 'magnum.shaders': '${magnum_shaders_file}', + 'magnum.platform.cgl': '${magnum_platform_cgl_file}', 'magnum.platform.egl': '${magnum_platform_egl_file}', 'magnum.platform.glx': '${magnum_platform_glx_file}', 'magnum.platform.wgl': '${magnum_platform_wgl_file}',