Browse Source

python: add also windowless CGL application.

Not sure how I forgot this one.
pull/16/head
Vladimír Vondruš 4 years ago
parent
commit
3ce8b6d96e
  1. 1
      src/python/CMakeLists.txt
  2. 8
      src/python/magnum/CMakeLists.txt
  3. 2
      src/python/magnum/__init__.py
  4. 1
      src/python/magnum/bootstrap.h
  5. 9
      src/python/magnum/platform/CMakeLists.txt
  6. 90
      src/python/magnum/platform/cgl.cpp
  7. 1
      src/python/magnum/staticconfigure.h.cmake
  8. 9
      src/python/magnum/test/__init__.py
  9. 1
      src/python/setup.py.cmake

1
src/python/CMakeLists.txt

@ -67,6 +67,7 @@ foreach(target
magnum_primitives magnum_primitives
magnum_scenegraph magnum_scenegraph
magnum_shaders magnum_shaders
magnum_platform_cgl
magnum_platform_egl magnum_platform_egl
magnum_platform_glx magnum_platform_glx
magnum_platform_glfw magnum_platform_glfw

8
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 # Find platform-specific apps only on the platforms where it matters, so we
# don't get confusing -- Could NOT find WindowlessWglApplication on Linux and # don't get confusing -- Could NOT find WindowlessWglApplication on Linux and
# such # such
if(CORRADE_TARGET_APPLE AND NOT MAGNUM_TARGET_GLES)
find_package(Magnum COMPONENTS WindowlessCglApplication)
endif()
if(CORRADE_TARGET_UNIX OR MAGNUM_TARGET_GLES) if(CORRADE_TARGET_UNIX OR MAGNUM_TARGET_GLES)
find_package(Magnum COMPONENTS WindowlessEglApplication) find_package(Magnum COMPONENTS WindowlessEglApplication)
endif() endif()
@ -215,6 +218,11 @@ else()
list(APPEND magnum_LIBS Magnum::Sdl2Application) list(APPEND magnum_LIBS Magnum::Sdl2Application)
endif() endif()
if(Magnum_WindowlessCglApplication_FOUND)
list(APPEND magnum_SRCS platform/cgl.cpp)
list(APPEND magnum_LIBS Magnum::WindowlessCglApplication)
endif()
if(Magnum_WindowlessEglApplication_FOUND) if(Magnum_WindowlessEglApplication_FOUND)
list(APPEND magnum_SRCS platform/egl.cpp) list(APPEND magnum_SRCS platform/egl.cpp)
list(APPEND magnum_LIBS Magnum::WindowlessEglApplication) list(APPEND magnum_LIBS Magnum::WindowlessEglApplication)

2
src/python/magnum/__init__.py

@ -40,7 +40,7 @@ for i in ['gl', 'meshtools', 'platform', 'primitives', 'scenegraph', 'shaders',
# Platform has subpackages # Platform has subpackages
if 'platform' in globals(): 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) if hasattr(platform, i): sys.modules['magnum.platform.' + i] = getattr(platform, i)
# Scenegraph has subpackages # Scenegraph has subpackages

1
src/python/magnum/bootstrap.h

@ -81,6 +81,7 @@ namespace platform {
void glfw(py::module_& m); void glfw(py::module_& m);
void sdl2(py::module_& m); void sdl2(py::module_& m);
void cgl(py::module_& m);
void egl(py::module_& m); void egl(py::module_& m);
void glx(py::module_& m); void glx(py::module_& m);
void wgl(py::module_& m); void wgl(py::module_& m);

9
src/python/magnum/platform/CMakeLists.txt

@ -46,6 +46,15 @@ if(NOT MAGNUM_BUILD_STATIC)
LIBRARY_OUTPUT_DIRECTORY ${output_dir}/magnum/platform) LIBRARY_OUTPUT_DIRECTORY ${output_dir}/magnum/platform)
endif() 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) if(Magnum_WindowlessEglApplication_FOUND)
pybind11_add_module(magnum_platform_egl ${pybind11_add_module_SYSTEM} egl.cpp) pybind11_add_module(magnum_platform_egl ${pybind11_add_module_SYSTEM} egl.cpp)
target_link_libraries(magnum_platform_egl PRIVATE Magnum::WindowlessEglApplication) target_link_libraries(magnum_platform_egl PRIVATE Magnum::WindowlessEglApplication)

90
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š <mosra@centrum.cz>
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 <pybind11/pybind11.h>
#include <Magnum/Platform/WindowlessCglApplication.h>
#include <Magnum/Platform/GLContext.h>
#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_<PyWindowlessApplication, ApplicationHolder<PyWindowlessApplication>> 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_<PyContext> 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

1
src/python/magnum/staticconfigure.h.cmake

@ -36,6 +36,7 @@
#cmakedefine Magnum_GlfwApplication_FOUND #cmakedefine Magnum_GlfwApplication_FOUND
#cmakedefine Magnum_Sdl2Application_FOUND #cmakedefine Magnum_Sdl2Application_FOUND
#cmakedefine Magnum_WindowlessCglApplication_FOUND
#cmakedefine Magnum_WindowlessEglApplication_FOUND #cmakedefine Magnum_WindowlessEglApplication_FOUND
#cmakedefine Magnum_WindowlessGlxApplication_FOUND #cmakedefine Magnum_WindowlessGlxApplication_FOUND
#cmakedefine Magnum_WindowlessWglApplication_FOUND #cmakedefine Magnum_WindowlessWglApplication_FOUND

9
src/python/magnum/test/__init__.py

@ -37,12 +37,15 @@ try:
from magnum.platform.glx import WindowlessApplication from magnum.platform.glx import WindowlessApplication
except ImportError: except ImportError:
try: try:
from magnum.platform.wgl import WindowlessApplication from magnum.platform.cgl import WindowlessApplication
except ImportError: except ImportError:
try: try:
from magnum.platform.egl import WindowlessApplication from magnum.platform.wgl import WindowlessApplication
except ImportError: except ImportError:
WindowlessApplication = None try:
from magnum.platform.egl import WindowlessApplication
except ImportError:
WindowlessApplication = None
def setUpModule(): def setUpModule():
if os.environ.get('MAGNUM_SKIP_GL_TESTS') == 'ON': if os.environ.get('MAGNUM_SKIP_GL_TESTS') == 'ON':

1
src/python/setup.py.cmake

@ -42,6 +42,7 @@ extension_paths = {
'magnum.primitives': '${magnum_primitives_file}', 'magnum.primitives': '${magnum_primitives_file}',
'magnum.scenegraph': '${magnum_scenegraph_file}', 'magnum.scenegraph': '${magnum_scenegraph_file}',
'magnum.shaders': '${magnum_shaders_file}', 'magnum.shaders': '${magnum_shaders_file}',
'magnum.platform.cgl': '${magnum_platform_cgl_file}',
'magnum.platform.egl': '${magnum_platform_egl_file}', 'magnum.platform.egl': '${magnum_platform_egl_file}',
'magnum.platform.glx': '${magnum_platform_glx_file}', 'magnum.platform.glx': '${magnum_platform_glx_file}',
'magnum.platform.wgl': '${magnum_platform_wgl_file}', 'magnum.platform.wgl': '${magnum_platform_wgl_file}',

Loading…
Cancel
Save