PyBullet OpenGL/EGL hardware getCameraImage: use glViewport to reduce the glReadPixels calling cost dramatically for small images

PyBullet Allow OpenGL/EGL hardware to render segmentation mask. Use pybullet.ER_SEGMENTATION_MASK_OBJECT_AND_LINKINDEX or pybullet.ER_SEGMENTATION_MASK
PyBullet.removeBody fix indexing bug (use foundIndex, not i)
PyBullet bump up version to 2.2.3
This commit is contained in:
erwincoumans
2018-09-30 07:10:40 -07:00
parent 254edb61cb
commit 5bcd43711a
32 changed files with 746 additions and 189 deletions

View File

@@ -63,6 +63,26 @@ struct SimpleInternalData
GLRenderToTexture* m_renderTexture;
void* m_userPointer;
int m_upAxis; //y=1 or z=2 is supported
int m_customViewPortWidth;
int m_customViewPortHeight;
SimpleInternalData()
:m_fontTextureId(0),
m_largeFontTextureId(0),
m_fontStash(0),
m_fontStash2(0),
m_renderCallbacks(0),
m_renderCallbacks2(0),
m_droidRegular(0),
m_droidRegular2(0),
m_frameDumpPngFileName(0),
m_ffmpegFile(0),
m_renderTexture(0),
m_userPointer(0),
m_upAxis(0),
m_customViewPortWidth(-1),
m_customViewPortHeight(-1)
{
}
};
static SimpleOpenGL3App* gApp = 0;
@@ -288,11 +308,7 @@ SimpleOpenGL3App::SimpleOpenGL3App(const char* title, int width, int height, boo
gApp = this;
m_data = new SimpleInternalData;
m_data->m_frameDumpPngFileName = 0;
m_data->m_renderTexture = 0;
m_data->m_ffmpegFile = 0;
m_data->m_userPointer = 0;
m_data->m_upAxis = 1;
if (windowType == 0)
{
@@ -909,10 +925,26 @@ SimpleOpenGL3App::~SimpleOpenGL3App()
delete m_data;
}
void SimpleOpenGL3App::setViewport(int width, int height)
{
m_data->m_customViewPortWidth=width;
m_data->m_customViewPortHeight=height;
if (width>=0)
{
glViewport(0,0,width,height);
} else
{
glViewport(0,0,m_window->getRetinaScale()*m_instancingRenderer->getScreenWidth(),m_window->getRetinaScale()*m_instancingRenderer->getScreenHeight());
}
}
void SimpleOpenGL3App::getScreenPixels(unsigned char* rgbaBuffer, int bufferSizeInBytes, float* depthBuffer, int depthBufferSizeInBytes)
{
int width = (int)m_window->getRetinaScale() * m_instancingRenderer->getScreenWidth();
int height = (int)m_window->getRetinaScale() * m_instancingRenderer->getScreenHeight();
int width = m_data->m_customViewPortWidth>=0? m_data->m_customViewPortWidth : (int)m_window->getRetinaScale() * m_instancingRenderer->getScreenWidth();
int height = m_data->m_customViewPortHeight >=0? m_data->m_customViewPortHeight: (int)m_window->getRetinaScale() * m_instancingRenderer->getScreenHeight();
b3Assert((width * height * 4) == bufferSizeInBytes);
if ((width * height * 4) == bufferSizeInBytes)
{
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, rgbaBuffer);
@@ -920,6 +952,7 @@ void SimpleOpenGL3App::getScreenPixels(unsigned char* rgbaBuffer, int bufferSize
glstat = glGetError();
b3Assert(glstat == GL_NO_ERROR);
}
b3Assert((width * height * sizeof(float)) == depthBufferSizeInBytes);
if ((width * height * sizeof(float)) == depthBufferSizeInBytes)
{
glReadPixels(0, 0, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, depthBuffer);