From 94806801e34ee05fe801bdaad43dfa4b74cef1fd Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 23 Mar 2021 15:04:20 +0100 Subject: [PATCH] Add p3headlessgl render plug-in on Linux using EGL as fallback for GLX Fixes #1086 --- direct/src/dist/commands.py | 2 +- makepanda/makepanda.py | 35 ++++++++++++++++--- makepanda/makewheel.py | 3 +- panda/metalibs/pandagl/pandagl.cxx | 13 +++++-- panda/metalibs/pandagl/pandagl.h | 4 +++ panda/src/egldisplay/config_egldisplay.cxx | 2 +- panda/src/egldisplay/eglGraphicsPipe.cxx | 6 ++-- panda/src/egldisplay/eglGraphicsPipe.h | 4 ++- panda/src/egldisplay/eglGraphicsPixmap.cxx | 4 +-- panda/src/egldisplay/eglGraphicsPixmap.h | 4 +-- .../egldisplay/eglGraphicsStateGuardian.cxx | 10 +++--- .../src/egldisplay/eglGraphicsStateGuardian.h | 4 +-- panda/src/egldisplay/eglGraphicsWindow.cxx | 4 +-- panda/src/egldisplay/eglGraphicsWindow.h | 4 +-- 14 files changed, 69 insertions(+), 30 deletions(-) diff --git a/direct/src/dist/commands.py b/direct/src/dist/commands.py index b51c2dd642..ca2b1aa519 100644 --- a/direct/src/dist/commands.py +++ b/direct/src/dist/commands.py @@ -277,7 +277,7 @@ class build_apps(setuptools.Command): 'libpthread.so.*', 'libc.so.*', 'ld-linux-x86-64.so.*', 'libgl.so.*', 'libx11.so.*', 'libncursesw.so.*', 'libz.so.*', 'librt.so.*', 'libutil.so.*', 'libnsl.so.1', 'libXext.so.6', - 'libXrender.so.1', 'libICE.so.6', 'libSM.so.6', + 'libXrender.so.1', 'libICE.so.6', 'libSM.so.6', 'libEGL.so.1', 'libgobject-2.0.so.0', 'libgthread-2.0.so.0', 'libglib-2.0.so.0', # macOS diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index c457a7fe12..71f8c00e3e 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -1255,6 +1255,14 @@ if not PkgSkip("EIGEN"): # will turn them into runtime assertions. DefSymbol("ALWAYS", "EIGEN_NO_STATIC_ASSERT") +if not PkgSkip("EGL"): + DefSymbol('EGL', 'HAVE_EGL', '') + if PkgSkip("X11"): + DefSymbol('EGL', 'EGL_NO_X11', '') + +if not PkgSkip("X11"): + DefSymbol('X11', 'USE_X11', '') + ######################################################################## ## ## Give a Status Report on Command-Line Options @@ -3243,6 +3251,8 @@ configprc = configprc.replace('\r\n', '\n') if (GetTarget() == 'windows'): configprc = configprc.replace("$XDG_CACHE_HOME/panda3d", "$USER_APPDATA/Panda3D-%s" % MAJOR_VERSION) +elif not PkgSkip("X11") and not PkgSkip("GL") and not PkgSkip("EGL") and not GetLinkAllStatic(): + configprc = configprc.replace("#load-display pandadx9", "aux-display p3headlessgl") else: configprc = configprc.replace("aux-display pandadx9", "") @@ -3591,9 +3601,10 @@ elif GetTarget() == 'darwin': elif GetTarget() == 'android': CopyAllHeaders('panda/src/android') CopyAllHeaders('panda/src/androiddisplay') -else: +if not PkgSkip('X11'): CopyAllHeaders('panda/src/x11display') - CopyAllHeaders('panda/src/glxdisplay') + if not PkgSkip('GL'): + CopyAllHeaders('panda/src/glxdisplay') CopyAllHeaders('panda/src/egldisplay') CopyAllHeaders('panda/metalibs/pandagl') CopyAllHeaders('panda/metalibs/pandagles') @@ -5156,7 +5167,6 @@ if (GetTarget() == 'windows' and PkgSkip("GL")==0 and not RUNTIME): # If we're not compiling with any windowing system at all, but we do have EGL, # we can use that to create a headless libpandagl instead. if not PkgSkip("EGL") and not PkgSkip("GL") and PkgSkip("X11") and GetTarget() not in ('windows', 'darwin') and not RUNTIME: - DefSymbol('EGL', 'HAVE_EGL', '') OPTS=['DIR:panda/src/egldisplay', 'DIR:panda/src/glstuff', 'BUILDING:PANDAGL', 'GL', 'EGL'] TargetAdd('pandagl_egldisplay_composite1.obj', opts=OPTS, input='p3egldisplay_composite1.cxx') OPTS=['DIR:panda/metalibs/pandagl', 'BUILDING:PANDAGL', 'GL', 'EGL'] @@ -5168,13 +5178,28 @@ if not PkgSkip("EGL") and not PkgSkip("GL") and PkgSkip("X11") and GetTarget() n TargetAdd('libpandagl.dll', input=COMMON_PANDA_LIBS) TargetAdd('libpandagl.dll', opts=['MODULE', 'GL', 'EGL', 'CGGL']) +elif not PkgSkip("EGL") and not PkgSkip("GL") and GetTarget() not in ('windows', 'darwin') and not RUNTIME: + # As a temporary solution for #1086, build this module, which we can use as a + # fallback to OpenGL for headless systems. + DefSymbol('EGL', 'HAVE_EGL', '') + OPTS=['DIR:panda/src/egldisplay', 'DIR:panda/src/glstuff', 'BUILDING:PANDAGL', 'GL', 'EGL'] + TargetAdd('p3headlessgl_egldisplay_composite1.obj', opts=OPTS, input='p3egldisplay_composite1.cxx') + OPTS=['DIR:panda/metalibs/pandagl', 'BUILDING:PANDAGL', 'GL', 'EGL'] + TargetAdd('p3headlessgl_pandagl.obj', opts=OPTS, input='pandagl.cxx') + TargetAdd('libp3headlessgl.dll', input='p3headlessgl_pandagl.obj') + TargetAdd('libp3headlessgl.dll', input='p3glgsg_config_glgsg.obj') + TargetAdd('libp3headlessgl.dll', input='p3glgsg_glgsg.obj') + TargetAdd('libp3headlessgl.dll', input='p3headlessgl_egldisplay_composite1.obj') + TargetAdd('libp3headlessgl.dll', input=COMMON_PANDA_LIBS) + TargetAdd('libp3headlessgl.dll', opts=['MODULE', 'GL', 'EGL', 'CGGL']) + # # DIRECTORY: panda/src/egldisplay/ # if (PkgSkip("EGL")==0 and PkgSkip("GLES")==0 and not RUNTIME): DefSymbol('GLES', 'OPENGLES_1', '') - OPTS=['DIR:panda/src/egldisplay', 'DIR:panda/src/glstuff', 'BUILDING:PANDAGLES', 'GLES', 'EGL'] + OPTS=['DIR:panda/src/egldisplay', 'DIR:panda/src/glstuff', 'BUILDING:PANDAGLES', 'GLES', 'EGL', 'X11'] TargetAdd('pandagles_egldisplay_composite1.obj', opts=OPTS, input='p3egldisplay_composite1.cxx') OPTS=['DIR:panda/metalibs/pandagles', 'BUILDING:PANDAGLES', 'GLES', 'EGL'] TargetAdd('pandagles_pandagles.obj', opts=OPTS, input='pandagles.cxx') @@ -5193,7 +5218,7 @@ if (PkgSkip("EGL")==0 and PkgSkip("GLES")==0 and not RUNTIME): if (PkgSkip("EGL")==0 and PkgSkip("GLES2")==0 and not RUNTIME): DefSymbol('GLES2', 'OPENGLES_2', '') - OPTS=['DIR:panda/src/egldisplay', 'DIR:panda/src/glstuff', 'BUILDING:PANDAGLES2', 'GLES2', 'EGL'] + OPTS=['DIR:panda/src/egldisplay', 'DIR:panda/src/glstuff', 'BUILDING:PANDAGLES2', 'GLES2', 'EGL', 'X11'] TargetAdd('pandagles2_egldisplay_composite1.obj', opts=OPTS, input='p3egldisplay_composite1.cxx') OPTS=['DIR:panda/metalibs/pandagles2', 'BUILDING:PANDAGLES2', 'GLES2', 'EGL'] TargetAdd('pandagles2_pandagles2.obj', opts=OPTS, input='pandagles2.cxx') diff --git a/makepanda/makewheel.py b/makepanda/makewheel.py index aaf7efa24e..57d0fe2242 100644 --- a/makepanda/makewheel.py +++ b/makepanda/makewheel.py @@ -90,7 +90,7 @@ ABI_TAG = get_abi_tag() EXCLUDE_EXT = [".pyc", ".pyo", ".N", ".prebuilt", ".xcf", ".plist", ".vcproj", ".sln"] # Plug-ins to install. -PLUGIN_LIBS = ["pandagl", "pandagles", "pandagles2", "pandadx9", "p3tinydisplay", "p3ptloader", "p3assimp", "p3ffmpeg", "p3openal_audio", "p3fmod_audio"] +PLUGIN_LIBS = ["pandagl", "pandagles", "pandagles2", "pandadx9", "p3tinydisplay", "p3ptloader", "p3assimp", "p3ffmpeg", "p3openal_audio", "p3fmod_audio", "p3headlessgl"] # Libraries included in manylinux ABI that should be ignored. See PEP 513/571/599. MANYLINUX_LIBS = [ @@ -103,6 +103,7 @@ MANYLINUX_LIBS = [ # These are not mentioned in manylinux1 spec but should nonetheless always # be excluded. "linux-vdso.so.1", "linux-gate.so.1", "ld-linux.so.2", "libdrm.so.2", + "libEGL.so.1", ] # Binaries to never scan for dependencies on non-Windows systems. diff --git a/panda/metalibs/pandagl/pandagl.cxx b/panda/metalibs/pandagl/pandagl.cxx index e6f01d9ce2..1a317fbdca 100644 --- a/panda/metalibs/pandagl/pandagl.cxx +++ b/panda/metalibs/pandagl/pandagl.cxx @@ -26,7 +26,7 @@ #include "glxGraphicsPipe.h" #endif -#if defined(HAVE_EGL) && !defined(HAVE_X11) +#ifdef HAVE_EGL #include "config_egldisplay.h" #include "eglGraphicsPipe.h" #endif @@ -59,7 +59,7 @@ init_libpandagl() { init_libglxdisplay(); #endif -#if defined(HAVE_EGL) && !defined(HAVE_X11) +#ifdef HAVE_EGL init_libegldisplay(); #endif } @@ -84,9 +84,16 @@ get_pipe_type_pandagl() { return glxGraphicsPipe::get_class_type().get_index(); #endif -#if defined(HAVE_EGL) && !defined(HAVE_X11) +#ifdef HAVE_EGL return eglGraphicsPipe::get_class_type().get_index(); #endif return 0; } + +#if defined(HAVE_EGL) && !defined(USE_X11) +int +get_pipe_type_p3headlessgl() { + return eglGraphicsPipe::get_class_type().get_index(); +} +#endif diff --git a/panda/metalibs/pandagl/pandagl.h b/panda/metalibs/pandagl/pandagl.h index 2a25a86587..3fb84b2152 100644 --- a/panda/metalibs/pandagl/pandagl.h +++ b/panda/metalibs/pandagl/pandagl.h @@ -12,4 +12,8 @@ EXPCL_PANDAGL void init_libpandagl(); extern "C" EXPCL_PANDAGL int get_pipe_type_pandagl(); +#if defined(HAVE_EGL) && !defined(USE_X11) +extern "C" EXPCL_PANDAGL int get_pipe_type_p3headlessgl(); +#endif + #endif diff --git a/panda/src/egldisplay/config_egldisplay.cxx b/panda/src/egldisplay/config_egldisplay.cxx index e80137290d..0903a3bd88 100644 --- a/panda/src/egldisplay/config_egldisplay.cxx +++ b/panda/src/egldisplay/config_egldisplay.cxx @@ -48,7 +48,7 @@ init_libegldisplay() { eglGraphicsBuffer::init_type(); eglGraphicsPipe::init_type(); -#ifdef HAVE_X11 +#ifdef USE_X11 eglGraphicsPixmap::init_type(); eglGraphicsWindow::init_type(); #endif diff --git a/panda/src/egldisplay/eglGraphicsPipe.cxx b/panda/src/egldisplay/eglGraphicsPipe.cxx index 6ce38433cb..a75aec5170 100644 --- a/panda/src/egldisplay/eglGraphicsPipe.cxx +++ b/panda/src/egldisplay/eglGraphicsPipe.cxx @@ -53,7 +53,7 @@ eglGraphicsPipe() { //NB. if the X11 display failed to open, _display will be 0, which is a valid // input to eglGetDisplay - it means to open the default display. -#ifdef HAVE_X11 +#ifdef USE_X11 _egl_display = eglGetDisplay((NativeDisplayType) _display); #else _egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); @@ -207,7 +207,7 @@ make_output(const std::string &name, // First thing to try: an eglGraphicsWindow if (retry == 0) { -#ifdef HAVE_X11 +#ifdef USE_X11 if (!_display) { return nullptr; } @@ -290,7 +290,7 @@ make_output(const std::string &name, // Fourth thing to try: an eglGraphicsPixmap. if (retry == 3) { -#ifdef HAVE_X11 +#ifdef USE_X11 if (!_display) { return nullptr; } diff --git a/panda/src/egldisplay/eglGraphicsPipe.h b/panda/src/egldisplay/eglGraphicsPipe.h index def344a61c..ec99f4a446 100644 --- a/panda/src/egldisplay/eglGraphicsPipe.h +++ b/panda/src/egldisplay/eglGraphicsPipe.h @@ -16,12 +16,14 @@ #include "pandabase.h" -#ifdef HAVE_X11 +#ifdef USE_X11 #include "x11GraphicsPipe.h" typedef x11GraphicsPipe BaseGraphicsPipe; #else #include "graphicsPipe.h" typedef GraphicsPipe BaseGraphicsPipe; +#undef EGL_NO_X11 +#define EGL_NO_X11 1 #endif #ifdef OPENGLES_2 diff --git a/panda/src/egldisplay/eglGraphicsPixmap.cxx b/panda/src/egldisplay/eglGraphicsPixmap.cxx index 946499746c..64630e43de 100644 --- a/panda/src/egldisplay/eglGraphicsPixmap.cxx +++ b/panda/src/egldisplay/eglGraphicsPixmap.cxx @@ -13,7 +13,7 @@ #include "eglGraphicsPixmap.h" -#ifdef HAVE_X11 +#ifdef USE_X11 #include "eglGraphicsWindow.h" #include "eglGraphicsStateGuardian.h" @@ -245,4 +245,4 @@ open_buffer() { return true; } -#endif // HAVE_X11 +#endif // USE_X11 diff --git a/panda/src/egldisplay/eglGraphicsPixmap.h b/panda/src/egldisplay/eglGraphicsPixmap.h index 95cb7842c0..cddb3430d3 100644 --- a/panda/src/egldisplay/eglGraphicsPixmap.h +++ b/panda/src/egldisplay/eglGraphicsPixmap.h @@ -16,7 +16,7 @@ #include "pandabase.h" -#ifdef HAVE_X11 +#ifdef USE_X11 #include "eglGraphicsPipe.h" #include "graphicsBuffer.h" @@ -69,6 +69,6 @@ private: static TypeHandle _type_handle; }; -#endif // HAVE_X11 +#endif // USE_X11 #endif diff --git a/panda/src/egldisplay/eglGraphicsStateGuardian.cxx b/panda/src/egldisplay/eglGraphicsStateGuardian.cxx index 26f55f3b74..70924505ad 100644 --- a/panda/src/egldisplay/eglGraphicsStateGuardian.cxx +++ b/panda/src/egldisplay/eglGraphicsStateGuardian.cxx @@ -187,7 +187,7 @@ choose_pixel_format(const FrameBufferProperties &properties, best_props = fbprops; } } -#ifdef HAVE_X11 +#ifdef USE_X11 X11_Display *display = egl_pipe->get_display(); if (display) { int screen = egl_pipe->get_screen(); @@ -233,7 +233,7 @@ choose_pixel_format(const FrameBufferProperties &properties, int err = eglGetError(); if (_context && err == EGL_SUCCESS) { -#ifdef HAVE_X11 +#ifdef USE_X11 if (!display || _visual) #endif { @@ -262,7 +262,7 @@ choose_pixel_format(const FrameBufferProperties &properties, << get_egl_error_string(err) << "\n"; _fbconfig = 0; _context = 0; -#ifdef HAVE_X11 +#ifdef USE_X11 _visual = 0; #endif } @@ -306,7 +306,7 @@ egl_is_at_least_version(int major_version, int minor_version) const { */ void eglGraphicsStateGuardian:: gl_flush() const { -#ifdef HAVE_X11 +#ifdef USE_X11 // This call requires synchronization with X. LightReMutexHolder holder(eglGraphicsPipe::_x_mutex); #endif @@ -318,7 +318,7 @@ gl_flush() const { */ GLenum eglGraphicsStateGuardian:: gl_get_error() const { -#ifdef HAVE_X11 +#ifdef USE_X11 // This call requires synchronization with X. LightReMutexHolder holder(eglGraphicsPipe::_x_mutex); #endif diff --git a/panda/src/egldisplay/eglGraphicsStateGuardian.h b/panda/src/egldisplay/eglGraphicsStateGuardian.h index 608e9aa080..1a7a036609 100644 --- a/panda/src/egldisplay/eglGraphicsStateGuardian.h +++ b/panda/src/egldisplay/eglGraphicsStateGuardian.h @@ -17,7 +17,7 @@ #include "pandabase.h" #include "eglGraphicsPipe.h" -#ifdef HAVE_X11 +#ifdef USE_X11 #include "get_x11.h" #endif @@ -55,7 +55,7 @@ public: EGLContext _share_context; EGLContext _context; EGLDisplay _egl_display; -#ifdef HAVE_X11 +#ifdef USE_X11 XVisualInfo *_visual = nullptr; #endif EGLConfig _fbconfig; diff --git a/panda/src/egldisplay/eglGraphicsWindow.cxx b/panda/src/egldisplay/eglGraphicsWindow.cxx index c85ff9d8df..31002c9fa6 100644 --- a/panda/src/egldisplay/eglGraphicsWindow.cxx +++ b/panda/src/egldisplay/eglGraphicsWindow.cxx @@ -13,7 +13,7 @@ #include "eglGraphicsWindow.h" -#ifdef HAVE_X11 +#ifdef USE_X11 #include "eglGraphicsStateGuardian.h" #include "config_egldisplay.h" @@ -279,4 +279,4 @@ open_window() { return true; } -#endif // HAVE_X11 +#endif // USE_X11 diff --git a/panda/src/egldisplay/eglGraphicsWindow.h b/panda/src/egldisplay/eglGraphicsWindow.h index 1c359aa666..1a5efad7fd 100644 --- a/panda/src/egldisplay/eglGraphicsWindow.h +++ b/panda/src/egldisplay/eglGraphicsWindow.h @@ -16,7 +16,7 @@ #include "pandabase.h" -#ifdef HAVE_X11 +#ifdef USE_X11 #include "eglGraphicsPipe.h" #include "x11GraphicsWindow.h" @@ -67,6 +67,6 @@ private: #include "eglGraphicsWindow.I" -#endif // HAVE_X11 +#endif // USE_X11 #endif