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:
@@ -13,8 +13,13 @@ struct PrimInternalData
|
||||
GLint m_positionAttribute;
|
||||
GLint m_textureAttribute;
|
||||
GLuint m_vertexBuffer;
|
||||
GLuint m_vertexArrayObject;
|
||||
GLuint m_vertexBuffer2;
|
||||
|
||||
GLuint m_vertexArrayObject;
|
||||
GLuint m_vertexArrayObject2;
|
||||
|
||||
GLuint m_indexBuffer;
|
||||
GLuint m_indexBuffer2;
|
||||
GLuint m_texturehandle;
|
||||
};
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
struct PrimVec2
|
||||
{
|
||||
PrimVec2()
|
||||
{}
|
||||
PrimVec2(float x, float y)
|
||||
{
|
||||
p[0] = x;
|
||||
@@ -28,12 +30,21 @@ struct PrimVec4
|
||||
float p[4];
|
||||
};
|
||||
|
||||
typedef struct
|
||||
struct PrimVertex
|
||||
{
|
||||
PrimVertex(const PrimVec4 & p, const PrimVec4 & c, const PrimVec2& u)
|
||||
:position(p),
|
||||
colour(c),
|
||||
uv(u)
|
||||
{
|
||||
}
|
||||
|
||||
PrimVertex()
|
||||
{}
|
||||
PrimVec4 position;
|
||||
PrimVec4 colour;
|
||||
PrimVec2 uv;
|
||||
} PrimVertex;
|
||||
} ;
|
||||
|
||||
|
||||
class GLPrimitiveRenderer
|
||||
@@ -42,7 +53,7 @@ class GLPrimitiveRenderer
|
||||
int m_screenHeight;
|
||||
|
||||
struct PrimInternalData* m_data;
|
||||
|
||||
struct PrimInternalData2* m_data2;
|
||||
void loadBufferData();
|
||||
|
||||
public:
|
||||
@@ -56,6 +67,14 @@ public:
|
||||
void drawLine();//float from[4], float to[4], float color[4]);
|
||||
void setScreenSize(int width, int height);
|
||||
|
||||
void drawTexturedRect2(float x0, float y0, float x1, float y1, float color[4], float u0,float v0, float u1, float v1, int useRGBA=0);
|
||||
void drawTexturedRect2a(float x0, float y0, float x1, float y1, float color[4], float u0,float v0, float u1, float v1, int useRGBA=0);
|
||||
void flushBatchedRects();
|
||||
|
||||
|
||||
void drawTexturedRect3D2Text(bool useRGBA = true);
|
||||
void drawTexturedRect3D2(PrimVertex* vertices, int numVertices, bool useRGBA = true);
|
||||
|
||||
PrimInternalData* getData()
|
||||
{
|
||||
return m_data;
|
||||
|
||||
@@ -161,6 +161,7 @@ public:
|
||||
|
||||
virtual void StartClip()
|
||||
{
|
||||
|
||||
if (m_useTrueTypeFont)
|
||||
sth_flush_draw(m_font);
|
||||
Gwen::Rect rect = ClipRegion();
|
||||
@@ -181,6 +182,7 @@ public:
|
||||
|
||||
virtual void EndClip()
|
||||
{
|
||||
|
||||
if (m_useTrueTypeFont)
|
||||
sth_flush_draw(m_font);
|
||||
glDisable( GL_SCISSOR_TEST );
|
||||
@@ -196,16 +198,23 @@ public:
|
||||
}
|
||||
virtual void DrawFilledRect( Gwen::Rect rect )
|
||||
{
|
||||
// BT_PROFILE("GWEN_DrawFilledRect");
|
||||
Translate( rect );
|
||||
|
||||
m_primitiveRenderer->drawRect(rect.x, rect.y+m_yOffset, rect.x+rect.w, rect.y+rect.h+m_yOffset, m_currentColor);
|
||||
m_primitiveRenderer->drawRect(rect.x, rect.y+m_yOffset,
|
||||
rect.x+rect.w, rect.y+rect.h+m_yOffset, m_currentColor);
|
||||
|
||||
|
||||
// m_primitiveRenderer->drawTexturedRect2a(rect.x, rect.y+m_yOffset,
|
||||
// rect.x+rect.w, rect.y+rect.h+m_yOffset, m_currentColor,0,0,1,1);
|
||||
// m_yOffset+=rect.h+10;
|
||||
|
||||
}
|
||||
|
||||
void RenderText( Gwen::Font* pFont, Gwen::Point rasterPos, const Gwen::UnicodeString& text )
|
||||
{
|
||||
|
||||
// BT_PROFILE("GWEN_RenderText");
|
||||
|
||||
Gwen::String str = Gwen::Utility::UnicodeToString(text);
|
||||
const char* unicodeText = (const char*)str.c_str();
|
||||
|
||||
@@ -246,32 +255,33 @@ public:
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D,m_fontTextureId);
|
||||
float width = r.x;
|
||||
|
||||
while (unicodeText[pos])
|
||||
{
|
||||
|
||||
int c = unicodeText[pos];
|
||||
r.h = m_currentFont->m_CharHeight;
|
||||
r.w = m_currentFont->m_CharWidth[c]+extraSpacing;
|
||||
Gwen::Rect rect = r;
|
||||
Translate( rect );
|
||||
|
||||
m_primitiveRenderer->drawTexturedRect(rect.x, rect.y+m_yOffset, rect.x+rect.w, rect.y+rect.h+m_yOffset, m_currentColor,m_currentFont->m_CharU0[c],m_currentFont->m_CharV0[c],m_currentFont->m_CharU1[c],m_currentFont->m_CharV1[c]);
|
||||
m_primitiveRenderer->drawTexturedRect2(rect.x, rect.y+m_yOffset, rect.x+rect.w, rect.y+rect.h+m_yOffset, m_currentColor,m_currentFont->m_CharU0[c],m_currentFont->m_CharV0[c],m_currentFont->m_CharU1[c],m_currentFont->m_CharV1[c]);
|
||||
|
||||
//DrawTexturedRect(0,r,m_currentFont->m_CharU0[c],m_currentFont->m_CharV0[c],m_currentFont->m_CharU1[c],m_currentFont->m_CharV1[c]);
|
||||
// DrawFilledRect(r);
|
||||
|
||||
|
||||
|
||||
width += r.w;
|
||||
r.x = width;
|
||||
pos++;
|
||||
|
||||
}
|
||||
{
|
||||
m_primitiveRenderer->drawTexturedRect3D2Text(false);
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D,0);
|
||||
}
|
||||
|
||||
}
|
||||
Gwen::Point MeasureText( Gwen::Font* pFont, const Gwen::UnicodeString& text )
|
||||
{
|
||||
// BT_PROFILE("GWEN_MeasureText");
|
||||
Gwen::String str = Gwen::Utility::UnicodeToString(text);
|
||||
const char* unicodeText = (const char*)str.c_str();
|
||||
|
||||
@@ -341,7 +351,7 @@ public:
|
||||
|
||||
virtual void DrawTexturedRect( Gwen::Texture* pTexture, Gwen::Rect rect, float u1=0.0f, float v1=0.0f, float u2=1.0f, float v2=1.0f )
|
||||
{
|
||||
|
||||
// BT_PROFILE("DrawTexturedRect");
|
||||
Translate( rect );
|
||||
|
||||
//float eraseColor[4] = {0,0,0,0};
|
||||
|
||||
Reference in New Issue
Block a user