From 8f711462e031e910a693bd099624adfecd1f6466 Mon Sep 17 00:00:00 2001 From: bla Date: Sun, 9 Sep 2018 22:58:08 -0700 Subject: [PATCH] fix setup.py to work better on Windows and Linux (with default eglPlugin static built-in, just use pybullet.loadPlugin("eglRendererPlugin") before loading/creating any objects. use end/startRendering (swap buffers) before the rendering in the eglPlugin --- .../eglRendererVisualShapeConverter.cpp | 9 ++- .../plugins/eglPlugin/premake4.lua | 2 +- examples/pybullet/examples/testrender.py | 2 + examples/pybullet/pybullet.c | 2 +- setup.py | 60 +++++-------------- 5 files changed, 26 insertions(+), 49 deletions(-) diff --git a/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp b/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp index 893440b0c..6dbba994e 100644 --- a/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp +++ b/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp @@ -38,8 +38,13 @@ subject to the following restrictions: #include "OpenGLWindow/Win32OpenGLWindow.h" typedef Win32OpenGLWindow DefaultOpenGLWindow; #else +#ifdef BT_USE_EGL #include "OpenGLWindow/EGLOpenGLWindow.h" typedef EGLOpenGLWindow DefaultOpenGLWindow; +#else +#include "OpenGLWindow/X11OpenGLWindow.h" +typedef X11OpenGLWindow DefaultOpenGLWindow; +#endif #endif #include "OpenGLWindow/GLInstancingRenderer.h" @@ -935,6 +940,8 @@ void EGLRendererVisualShapeConverter::clearBuffers(TGAColor& clearColor) void EGLRendererVisualShapeConverter::render() { + m_data->m_window->endRendering(); + m_data->m_window->startRendering(); /* ATTRIBUTE_ALIGNED16(float viewMat[16]); ATTRIBUTE_ALIGNED16(float projMat[16]); @@ -956,8 +963,6 @@ void EGLRendererVisualShapeConverter::render() m_data->m_instancingRenderer->updateCamera(m_data->m_upAxis); m_data->m_instancingRenderer->renderScene(); - m_data->m_window->endRendering(); - m_data->m_window->startRendering(); } diff --git a/examples/SharedMemory/plugins/eglPlugin/premake4.lua b/examples/SharedMemory/plugins/eglPlugin/premake4.lua index 972b0566a..a7f49943a 100644 --- a/examples/SharedMemory/plugins/eglPlugin/premake4.lua +++ b/examples/SharedMemory/plugins/eglPlugin/premake4.lua @@ -6,7 +6,7 @@ project ("pybullet_eglRendererPlugin") initEGL() includedirs {".","../../../../src", "../../../../examples", - "../../../ThirdPartyLibs", ""../../examples/ThirdPartyLibs/glad"} + "../../../ThirdPartyLibs", "../../examples/ThirdPartyLibs/glad"} defines {"PHYSICS_IN_PROCESS_EXAMPLE_BROWSER", "STB_AGAIN"} hasCL = findOpenCL("clew") diff --git a/examples/pybullet/examples/testrender.py b/examples/pybullet/examples/testrender.py index 758882f11..48fe8356c 100644 --- a/examples/pybullet/examples/testrender.py +++ b/examples/pybullet/examples/testrender.py @@ -15,6 +15,8 @@ ax = plt.gca() pybullet.connect(pybullet.DIRECT) + +#pybullet.loadPlugin("eglRendererPlugin") pybullet.loadURDF("plane.urdf",[0,0,-1]) pybullet.loadURDF("r2d2.urdf") diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index 2d5c9426e..525422b6f 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -9596,7 +9596,7 @@ PyMODINIT_FUNC #if PY_MAJOR_VERSION >= 3 PyInit_pybullet(void) #else -#ifdef BT_USE_EGL +#ifdef BT_USE_EGL2 initpybullet_egl(void) #else #ifdef BT_PYBULLET_GRPC diff --git a/setup.py b/setup.py index 2f08290b9..296572a94 100644 --- a/setup.py +++ b/setup.py @@ -1,33 +1,14 @@ + from setuptools import find_packages from sys import platform as _platform import sys -from glob import glob +import glob from distutils.core import setup from distutils.extension import Extension from distutils.util import get_platform - - -# monkey-patch for parallel compilation -import multiprocessing -import multiprocessing.pool -def parallelCCompile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None, depends=None): - # those lines are copied from distutils.ccompiler.CCompiler directly - macros, objects, extra_postargs, pp_opts, build = self._setup_compile(output_dir, macros, include_dirs, sources, depends, extra_postargs) - cc_args = self._get_cc_args(pp_opts, debug, extra_preargs) - # parallel code - N = 2*multiprocessing.cpu_count()# number of parallel compilations - def _single_compile(obj): - try: src, ext = build[obj] - except KeyError: return - self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) - # convert to list, imap is evaluated on-demand - list(multiprocessing.pool.ThreadPool(N).imap(_single_compile,objects)) - return objects -import distutils.ccompiler -distutils.ccompiler.CCompiler.compile=parallelCCompile - +from glob import glob #see http://stackoverflow.com/a/8719066/295157 import os @@ -42,9 +23,7 @@ CXX_FLAGS += '-DBT_USE_DOUBLE_PRECISION ' CXX_FLAGS += '-DBT_ENABLE_ENET ' CXX_FLAGS += '-DBT_ENABLE_CLSOCKET ' CXX_FLAGS += '-DB3_DUMP_PYTHON_VERSION ' -CXX_FLAGS += '-DSTATIC_EGLRENDERER_PLUGIN ' #comment to disable static egl plugin - - +CXX_FLAGS += '-DSTATIC_EGLRENDERER_PLUGIN ' # libraries += [current_python] @@ -71,6 +50,8 @@ sources = ["examples/pybullet/pybullet.c"]\ +["examples/TinyRenderer/tgaimage.cpp"]\ +["examples/TinyRenderer/our_gl.cpp"]\ +["examples/TinyRenderer/TinyRenderer.cpp"]\ ++["examples/SharedMemory/plugins/eglPlugin/eglRendererPlugin.cpp"]\ ++["examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp"]\ +["examples/SharedMemory/plugins/pdControlPlugin/pdControlPlugin.cpp"]\ +["examples/SharedMemory/plugins/collisionFilterPlugin/collisionFilterPlugin.cpp"]\ +["examples/SharedMemory/b3RobotSimulatorClientAPI_NoDirect.cpp"]\ @@ -407,38 +388,28 @@ sources = ["examples/pybullet/pybullet.c"]\ +["examples/ThirdPartyLibs/Gwen/Platforms/Windows.cpp"]\ +["examples/ThirdPartyLibs/Gwen/Renderers/OpenGL_DebugFont.cpp"]\ - -if 'STATIC_EGLRENDERER_PLUGIN' in CXX_FLAGS: - sources += ['examples/SharedMemory/plugins/eglPlugin/eglRendererPlugin.cpp']\ - + ['examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp'] - if _platform == "linux" or _platform == "linux2": - print("linux!") - libraries += ['dl','pthread'] - CXX_FLAGS += '-DBT_USE_EGL ' + libraries = ['dl','pthread'] CXX_FLAGS += '-D_LINUX ' CXX_FLAGS += '-DGLEW_STATIC ' CXX_FLAGS += '-DGLEW_INIT_OPENGL11_FUNCTIONS=1 ' CXX_FLAGS += '-DGLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS=1 ' CXX_FLAGS += '-DDYNAMIC_LOAD_X11_FUNCTIONS ' CXX_FLAGS += '-DHAS_SOCKLEN_T ' + CXX_FLAGS += '-DBT_USE_EGL ' CXX_FLAGS += '-fno-inline-functions-called-once' sources = sources + ["examples/ThirdPartyLibs/enet/unix.c"]\ +["examples/OpenGLWindow/X11OpenGLWindow.cpp"]\ +["examples/ThirdPartyLibs/glad/gl.c"]\ - +["examples/ThirdPartyLibs/glad/glx.c"] - include_dirs += ["examples/ThirdPartyLibs/optionalX11"] - if 'BT_USE_EGL' in CXX_FLAGS: - # linking with bullet's Glew libraries causes segfault - # for some reason. - sources += ['examples/ThirdPartyLibs/glad/egl.c']\ - + ['examples/OpenGLWindow/EGLOpenGLWindow.cpp'] + +["examples/ThirdPartyLibs/glad/glx.c"]\ + +["examples/ThirdPartyLibs/glad/egl.c"]\ + +["examples/OpenGLWindow/EGLOpenGLWindow.cpp"] + include_dirs += ["examples/ThirdPartyLibs/optionalX11"] elif _platform == "win32": print("win32!") - libraries += ['Ws2_32','Winmm','User32','Opengl32','kernel32','glu32','Gdi32','Comdlg32'] + libraries = ['Ws2_32','Winmm','User32','Opengl32','kernel32','glu32','Gdi32','Comdlg32'] CXX_FLAGS += '-DWIN32 ' - CXX_FLAGS += '-D_WIN32 ' CXX_FLAGS += '-DGLEW_STATIC ' sources = sources + ["examples/ThirdPartyLibs/enet/win32.c"]\ +["examples/OpenGLWindow/Win32Window.cpp"]\ @@ -457,7 +428,7 @@ elif _platform == "darwin": +["examples/OpenGLWindow/MacOpenGLWindowObjC.m"] else: print("bsd!") - libraries += ['GL','GLEW','pthread'] + libraries = ['GL','GLEW','pthread'] os.environ['LDFLAGS'] = '-L/usr/X11R6/lib' CXX_FLAGS += '-D_BSD ' CXX_FLAGS += '-I/usr/X11R6/include ' @@ -468,7 +439,6 @@ else: +["examples/ThirdPartyLibs/glad/gl.c"]\ + sources - setup_py_dir = os.path.dirname(os.path.realpath(__file__)) need_files = [] @@ -523,4 +493,4 @@ setup( package_dir = { '': 'examples/pybullet/gym'}, packages=[x for x in find_packages('examples/pybullet/gym')], package_data = { 'pybullet_data': need_files } -) \ No newline at end of file +)