pybullet, more robust multi-server connections
Windows shared memory: allow to use custom key. Improve GUI performance on Windows, submit letters in text as a batch (fewer draw-calls) quadruped.py: first try to connect to SHARED_MEMORY, if it fails (<0) use GUI increase Chrome about://tracing json export capacity (press 'p' in Example Browser) UDP physics server: add --port and --sharedMemoryKey command-line arguments PhysicsServerExample: add --sharedMemoryKey command-line option (for VR example too) ExampleBrowser: sleep a few milliseconds if rendering is too fast, use --minUpdateTimeMicroSecs=0 to disable
This commit is contained in:
@@ -48,10 +48,20 @@ static const char* fragmentShader3D= \
|
||||
|
||||
|
||||
static unsigned int s_indexData[6] = {0,1,2,0,2,3};
|
||||
#define MAX_VERTICES2 8192
|
||||
struct PrimInternalData2
|
||||
{
|
||||
PrimInternalData2()
|
||||
:m_numVerticesText(0),
|
||||
m_numVerticesRect(0)
|
||||
{
|
||||
}
|
||||
int m_numVerticesText;
|
||||
int m_numVerticesRect;
|
||||
PrimVertex m_verticesText[MAX_VERTICES2];
|
||||
PrimVertex m_verticesRect[MAX_VERTICES2];
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
GLPrimitiveRenderer::GLPrimitiveRenderer(int screenWidth, int screenHeight)
|
||||
:m_screenWidth(screenWidth),
|
||||
@@ -59,6 +69,7 @@ m_screenHeight(screenHeight)
|
||||
{
|
||||
|
||||
m_data = new PrimInternalData;
|
||||
m_data2 = new PrimInternalData2;
|
||||
|
||||
m_data->m_shaderProg = gltLoadShaderPair(vertexShader3D,fragmentShader3D);
|
||||
|
||||
@@ -109,6 +120,13 @@ void GLPrimitiveRenderer::loadBufferData()
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vertexBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(PrimVertex), vertexData, GL_DYNAMIC_DRAW);
|
||||
|
||||
glGenVertexArrays(1, &m_data->m_vertexArrayObject2);
|
||||
glBindVertexArray(m_data->m_vertexArrayObject2);
|
||||
glGenBuffers(1, &m_data->m_vertexBuffer2);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vertexBuffer2);
|
||||
glBufferData(GL_ARRAY_BUFFER, MAX_VERTICES2 * sizeof(PrimVertex), 0, GL_DYNAMIC_DRAW);
|
||||
|
||||
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
|
||||
@@ -116,7 +134,23 @@ void GLPrimitiveRenderer::loadBufferData()
|
||||
glGenBuffers(1, &m_data->m_indexBuffer);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_indexBuffer);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER,6*sizeof(int), s_indexData,GL_STATIC_DRAW);
|
||||
|
||||
|
||||
unsigned int indexData[MAX_VERTICES2*2];
|
||||
int count=0;
|
||||
for (int i=0;i<MAX_VERTICES2;i+=4)
|
||||
{
|
||||
indexData[count++]=i;
|
||||
indexData[count++]=i+1;
|
||||
indexData[count++]=i+2;
|
||||
|
||||
indexData[count++]=i;
|
||||
indexData[count++]=i+2;
|
||||
indexData[count++]=i+3;
|
||||
}
|
||||
glGenBuffers(1, &m_data->m_indexBuffer2);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_indexBuffer2);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER,count*sizeof(int), indexData,GL_STATIC_DRAW);
|
||||
|
||||
glEnableVertexAttribArray(m_data->m_positionAttribute);
|
||||
glEnableVertexAttribArray(m_data->m_colourAttribute);
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
@@ -182,6 +216,7 @@ GLPrimitiveRenderer::~GLPrimitiveRenderer()
|
||||
glBindTexture(GL_TEXTURE_2D,0);
|
||||
glDeleteProgram(m_data->m_shaderProg);
|
||||
delete m_data;
|
||||
delete m_data2;
|
||||
}
|
||||
|
||||
void GLPrimitiveRenderer::drawLine()
|
||||
@@ -299,6 +334,180 @@ void GLPrimitiveRenderer::drawTexturedRect3D(const PrimVertex& v0,const PrimVert
|
||||
|
||||
}
|
||||
|
||||
void GLPrimitiveRenderer::drawTexturedRect3D2Text( bool useRGBA)
|
||||
{
|
||||
drawTexturedRect3D2(&m_data2->m_verticesText[0],m_data2->m_numVerticesText,useRGBA);
|
||||
m_data2->m_numVerticesText = 0;
|
||||
}
|
||||
|
||||
void GLPrimitiveRenderer::drawTexturedRect3D2( PrimVertex* vertices, int numVertices, bool useRGBA)
|
||||
{
|
||||
//B3_PROFILE("drawTexturedRect3D2");
|
||||
if (numVertices==0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//B3_PROFILE("GLPrimitiveRenderer::drawTexturedRect3D");
|
||||
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
float identity[16]={1,0,0,0,
|
||||
0,1,0,0,
|
||||
0,0,1,0,
|
||||
0,0,0,1};
|
||||
|
||||
glUseProgram(m_data->m_shaderProg);
|
||||
|
||||
glUniformMatrix4fv(m_data->m_viewmatUniform, 1, false, identity);
|
||||
glUniformMatrix4fv(m_data->m_projMatUniform, 1, false, identity);
|
||||
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vertexBuffer2);
|
||||
glBindVertexArray(m_data->m_vertexArrayObject2);
|
||||
|
||||
bool useFiltering = false;
|
||||
if (useFiltering)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
} else
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
/* PrimVertex vertexData[4] = {
|
||||
v0,v1,v2,v3
|
||||
};
|
||||
*/
|
||||
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0,numVertices * sizeof(PrimVertex), vertices);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
PrimVec2 p( 0.f,0.f);//?b?0.5f * sinf(timeValue), 0.5f * cosf(timeValue) );
|
||||
if (useRGBA)
|
||||
{
|
||||
p.p[0] = 1.f;
|
||||
p.p[1] = 1.f;
|
||||
}
|
||||
|
||||
glUniform2fv(m_data->m_positionUniform, 1, (const GLfloat *)&p);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
glEnableVertexAttribArray(m_data->m_positionAttribute);
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
glEnableVertexAttribArray(m_data->m_colourAttribute);
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
glEnableVertexAttribArray(m_data->m_textureAttribute);
|
||||
|
||||
glVertexAttribPointer(m_data->m_positionAttribute, 4, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)0);
|
||||
glVertexAttribPointer(m_data->m_colourAttribute , 4, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)sizeof(PrimVec4));
|
||||
glVertexAttribPointer(m_data->m_textureAttribute , 2, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)(sizeof(PrimVec4)+sizeof(PrimVec4)));
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_indexBuffer2);
|
||||
|
||||
//glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
int indexCount = (numVertices/4)*6;
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
|
||||
glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, 0);
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
|
||||
glBindVertexArray(0);
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
//glDisableVertexAttribArray(m_data->m_textureAttribute);
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
glUseProgram(0);
|
||||
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void GLPrimitiveRenderer::drawTexturedRect2a(float x0, float y0, float x1, float y1, float color[4], float u0,float v0, float u1, float v1, int useRGBA)
|
||||
{
|
||||
|
||||
PrimVertex vertexData[4] = {
|
||||
{ PrimVec4(-1.f+2.f*x0/float(m_screenWidth), 1.f-2.f*y0/float(m_screenHeight), 0.f, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u0,v0)},
|
||||
{ PrimVec4(-1.f+2.f*x0/float(m_screenWidth), 1.f-2.f*y1/float(m_screenHeight), 0.f, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u0,v1)},
|
||||
{ PrimVec4( -1.f+2.f*x1/float(m_screenWidth), 1.f-2.f*y1/float(m_screenHeight), 0.f, 1.f ), PrimVec4(color[0], color[1], color[2], color[3]) ,PrimVec2(u1,v1)},
|
||||
{ PrimVec4( -1.f+2.f*x1/float(m_screenWidth), 1.f-2.f*y0/float(m_screenHeight), 0.f, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u1,v0)}
|
||||
};
|
||||
|
||||
int sz = m_data2->m_numVerticesText;
|
||||
|
||||
m_data2->m_verticesRect[m_data2->m_numVerticesRect++]=vertexData[0];
|
||||
m_data2->m_verticesRect[m_data2->m_numVerticesRect++]=vertexData[1];
|
||||
m_data2->m_verticesRect[m_data2->m_numVerticesRect++]=vertexData[2];
|
||||
m_data2->m_verticesRect[m_data2->m_numVerticesRect++]=vertexData[3];
|
||||
|
||||
|
||||
if (m_data2->m_numVerticesRect>=MAX_VERTICES2)
|
||||
{
|
||||
flushBatchedRects();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GLPrimitiveRenderer::flushBatchedRects()
|
||||
{
|
||||
if (m_data2->m_numVerticesRect==0)
|
||||
return;
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
glBindTexture(GL_TEXTURE_2D,m_data->m_texturehandle);
|
||||
drawTexturedRect3D2(m_data2->m_verticesRect, m_data2->m_numVerticesRect,0);
|
||||
m_data2->m_numVerticesRect=0;
|
||||
}
|
||||
void GLPrimitiveRenderer::drawTexturedRect2(float x0, float y0, float x1, float y1, float color[4], float u0,float v0, float u1, float v1, int useRGBA)
|
||||
{
|
||||
|
||||
PrimVertex vertexData[4] = {
|
||||
{ PrimVec4(-1.f+2.f*x0/float(m_screenWidth), 1.f-2.f*y0/float(m_screenHeight), 0.f, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u0,v0)},
|
||||
{ PrimVec4(-1.f+2.f*x0/float(m_screenWidth), 1.f-2.f*y1/float(m_screenHeight), 0.f, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u0,v1)},
|
||||
{ PrimVec4( -1.f+2.f*x1/float(m_screenWidth), 1.f-2.f*y1/float(m_screenHeight), 0.f, 1.f ), PrimVec4(color[0], color[1], color[2], color[3]) ,PrimVec2(u1,v1)},
|
||||
{ PrimVec4( -1.f+2.f*x1/float(m_screenWidth), 1.f-2.f*y0/float(m_screenHeight), 0.f, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u1,v0)}
|
||||
};
|
||||
|
||||
int sz = m_data2->m_numVerticesText;
|
||||
|
||||
m_data2->m_verticesText[m_data2->m_numVerticesText++]=vertexData[0];
|
||||
m_data2->m_verticesText[m_data2->m_numVerticesText++]=vertexData[1];
|
||||
m_data2->m_verticesText[m_data2->m_numVerticesText++]=vertexData[2];
|
||||
m_data2->m_verticesText[m_data2->m_numVerticesText++]=vertexData[3];
|
||||
|
||||
|
||||
if (m_data2->m_numVerticesText>=MAX_VERTICES2)
|
||||
{
|
||||
drawTexturedRect3D2(m_data2->m_verticesText, m_data2->m_numVerticesText,useRGBA);
|
||||
m_data2->m_numVerticesText=0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GLPrimitiveRenderer::drawTexturedRect(float x0, float y0, float x1, float y1, float color[4], float u0,float v0, float u1, float v1, int useRGBA)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user