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
This commit is contained in:
bla
2018-09-09 22:58:08 -07:00
parent 9698c3d600
commit 8f711462e0
5 changed files with 26 additions and 49 deletions

View File

@@ -38,8 +38,13 @@ subject to the following restrictions:
#include "OpenGLWindow/Win32OpenGLWindow.h" #include "OpenGLWindow/Win32OpenGLWindow.h"
typedef Win32OpenGLWindow DefaultOpenGLWindow; typedef Win32OpenGLWindow DefaultOpenGLWindow;
#else #else
#ifdef BT_USE_EGL
#include "OpenGLWindow/EGLOpenGLWindow.h" #include "OpenGLWindow/EGLOpenGLWindow.h"
typedef EGLOpenGLWindow DefaultOpenGLWindow; typedef EGLOpenGLWindow DefaultOpenGLWindow;
#else
#include "OpenGLWindow/X11OpenGLWindow.h"
typedef X11OpenGLWindow DefaultOpenGLWindow;
#endif
#endif #endif
#include "OpenGLWindow/GLInstancingRenderer.h" #include "OpenGLWindow/GLInstancingRenderer.h"
@@ -935,6 +940,8 @@ void EGLRendererVisualShapeConverter::clearBuffers(TGAColor& clearColor)
void EGLRendererVisualShapeConverter::render() void EGLRendererVisualShapeConverter::render()
{ {
m_data->m_window->endRendering();
m_data->m_window->startRendering();
/* /*
ATTRIBUTE_ALIGNED16(float viewMat[16]); ATTRIBUTE_ALIGNED16(float viewMat[16]);
ATTRIBUTE_ALIGNED16(float projMat[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->updateCamera(m_data->m_upAxis);
m_data->m_instancingRenderer->renderScene(); m_data->m_instancingRenderer->renderScene();
m_data->m_window->endRendering();
m_data->m_window->startRendering();
} }

View File

@@ -6,7 +6,7 @@ project ("pybullet_eglRendererPlugin")
initEGL() initEGL()
includedirs {".","../../../../src", "../../../../examples", includedirs {".","../../../../src", "../../../../examples",
"../../../ThirdPartyLibs", ""../../examples/ThirdPartyLibs/glad"} "../../../ThirdPartyLibs", "../../examples/ThirdPartyLibs/glad"}
defines {"PHYSICS_IN_PROCESS_EXAMPLE_BROWSER", "STB_AGAIN"} defines {"PHYSICS_IN_PROCESS_EXAMPLE_BROWSER", "STB_AGAIN"}
hasCL = findOpenCL("clew") hasCL = findOpenCL("clew")

View File

@@ -15,6 +15,8 @@ ax = plt.gca()
pybullet.connect(pybullet.DIRECT) pybullet.connect(pybullet.DIRECT)
#pybullet.loadPlugin("eglRendererPlugin")
pybullet.loadURDF("plane.urdf",[0,0,-1]) pybullet.loadURDF("plane.urdf",[0,0,-1])
pybullet.loadURDF("r2d2.urdf") pybullet.loadURDF("r2d2.urdf")

View File

@@ -9596,7 +9596,7 @@ PyMODINIT_FUNC
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
PyInit_pybullet(void) PyInit_pybullet(void)
#else #else
#ifdef BT_USE_EGL #ifdef BT_USE_EGL2
initpybullet_egl(void) initpybullet_egl(void)
#else #else
#ifdef BT_PYBULLET_GRPC #ifdef BT_PYBULLET_GRPC

View File

@@ -1,33 +1,14 @@
from setuptools import find_packages from setuptools import find_packages
from sys import platform as _platform from sys import platform as _platform
import sys import sys
from glob import glob import glob
from distutils.core import setup from distutils.core import setup
from distutils.extension import Extension from distutils.extension import Extension
from distutils.util import get_platform from distutils.util import get_platform
from glob import glob
# 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
#see http://stackoverflow.com/a/8719066/295157 #see http://stackoverflow.com/a/8719066/295157
import os import os
@@ -42,9 +23,7 @@ CXX_FLAGS += '-DBT_USE_DOUBLE_PRECISION '
CXX_FLAGS += '-DBT_ENABLE_ENET ' CXX_FLAGS += '-DBT_ENABLE_ENET '
CXX_FLAGS += '-DBT_ENABLE_CLSOCKET ' CXX_FLAGS += '-DBT_ENABLE_CLSOCKET '
CXX_FLAGS += '-DB3_DUMP_PYTHON_VERSION ' 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] # libraries += [current_python]
@@ -71,6 +50,8 @@ sources = ["examples/pybullet/pybullet.c"]\
+["examples/TinyRenderer/tgaimage.cpp"]\ +["examples/TinyRenderer/tgaimage.cpp"]\
+["examples/TinyRenderer/our_gl.cpp"]\ +["examples/TinyRenderer/our_gl.cpp"]\
+["examples/TinyRenderer/TinyRenderer.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/pdControlPlugin/pdControlPlugin.cpp"]\
+["examples/SharedMemory/plugins/collisionFilterPlugin/collisionFilterPlugin.cpp"]\ +["examples/SharedMemory/plugins/collisionFilterPlugin/collisionFilterPlugin.cpp"]\
+["examples/SharedMemory/b3RobotSimulatorClientAPI_NoDirect.cpp"]\ +["examples/SharedMemory/b3RobotSimulatorClientAPI_NoDirect.cpp"]\
@@ -407,38 +388,28 @@ sources = ["examples/pybullet/pybullet.c"]\
+["examples/ThirdPartyLibs/Gwen/Platforms/Windows.cpp"]\ +["examples/ThirdPartyLibs/Gwen/Platforms/Windows.cpp"]\
+["examples/ThirdPartyLibs/Gwen/Renderers/OpenGL_DebugFont.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": if _platform == "linux" or _platform == "linux2":
print("linux!") libraries = ['dl','pthread']
libraries += ['dl','pthread']
CXX_FLAGS += '-DBT_USE_EGL '
CXX_FLAGS += '-D_LINUX ' CXX_FLAGS += '-D_LINUX '
CXX_FLAGS += '-DGLEW_STATIC ' CXX_FLAGS += '-DGLEW_STATIC '
CXX_FLAGS += '-DGLEW_INIT_OPENGL11_FUNCTIONS=1 ' CXX_FLAGS += '-DGLEW_INIT_OPENGL11_FUNCTIONS=1 '
CXX_FLAGS += '-DGLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS=1 ' CXX_FLAGS += '-DGLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS=1 '
CXX_FLAGS += '-DDYNAMIC_LOAD_X11_FUNCTIONS ' CXX_FLAGS += '-DDYNAMIC_LOAD_X11_FUNCTIONS '
CXX_FLAGS += '-DHAS_SOCKLEN_T ' CXX_FLAGS += '-DHAS_SOCKLEN_T '
CXX_FLAGS += '-DBT_USE_EGL '
CXX_FLAGS += '-fno-inline-functions-called-once' CXX_FLAGS += '-fno-inline-functions-called-once'
sources = sources + ["examples/ThirdPartyLibs/enet/unix.c"]\ sources = sources + ["examples/ThirdPartyLibs/enet/unix.c"]\
+["examples/OpenGLWindow/X11OpenGLWindow.cpp"]\ +["examples/OpenGLWindow/X11OpenGLWindow.cpp"]\
+["examples/ThirdPartyLibs/glad/gl.c"]\ +["examples/ThirdPartyLibs/glad/gl.c"]\
+["examples/ThirdPartyLibs/glad/glx.c"] +["examples/ThirdPartyLibs/glad/glx.c"]\
include_dirs += ["examples/ThirdPartyLibs/optionalX11"] +["examples/ThirdPartyLibs/glad/egl.c"]\
if 'BT_USE_EGL' in CXX_FLAGS: +["examples/OpenGLWindow/EGLOpenGLWindow.cpp"]
# linking with bullet's Glew libraries causes segfault
# for some reason.
sources += ['examples/ThirdPartyLibs/glad/egl.c']\
+ ['examples/OpenGLWindow/EGLOpenGLWindow.cpp']
include_dirs += ["examples/ThirdPartyLibs/optionalX11"]
elif _platform == "win32": elif _platform == "win32":
print("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 += '-DWIN32 '
CXX_FLAGS += '-D_WIN32 '
CXX_FLAGS += '-DGLEW_STATIC ' CXX_FLAGS += '-DGLEW_STATIC '
sources = sources + ["examples/ThirdPartyLibs/enet/win32.c"]\ sources = sources + ["examples/ThirdPartyLibs/enet/win32.c"]\
+["examples/OpenGLWindow/Win32Window.cpp"]\ +["examples/OpenGLWindow/Win32Window.cpp"]\
@@ -457,7 +428,7 @@ elif _platform == "darwin":
+["examples/OpenGLWindow/MacOpenGLWindowObjC.m"] +["examples/OpenGLWindow/MacOpenGLWindowObjC.m"]
else: else:
print("bsd!") print("bsd!")
libraries += ['GL','GLEW','pthread'] libraries = ['GL','GLEW','pthread']
os.environ['LDFLAGS'] = '-L/usr/X11R6/lib' os.environ['LDFLAGS'] = '-L/usr/X11R6/lib'
CXX_FLAGS += '-D_BSD ' CXX_FLAGS += '-D_BSD '
CXX_FLAGS += '-I/usr/X11R6/include ' CXX_FLAGS += '-I/usr/X11R6/include '
@@ -468,7 +439,6 @@ else:
+["examples/ThirdPartyLibs/glad/gl.c"]\ +["examples/ThirdPartyLibs/glad/gl.c"]\
+ sources + sources
setup_py_dir = os.path.dirname(os.path.realpath(__file__)) setup_py_dir = os.path.dirname(os.path.realpath(__file__))
need_files = [] need_files = []
@@ -523,4 +493,4 @@ setup(
package_dir = { '': 'examples/pybullet/gym'}, package_dir = { '': 'examples/pybullet/gym'},
packages=[x for x in find_packages('examples/pybullet/gym')], packages=[x for x in find_packages('examples/pybullet/gym')],
package_data = { 'pybullet_data': need_files } package_data = { 'pybullet_data': need_files }
) )