Skip to content

Commit

Permalink
Call drawPoints in PhysicsServerExample
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Oct 15, 2021
1 parent b81c331 commit e7460f1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions examples/CommonInterfaces/CommonRenderInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct CommonRenderInterface
virtual void drawLine(const double from[4], const double to[4], const double color[4], double lineWidth) = 0;
virtual void drawPoint(const float* position, const float color[4], float pointDrawSize) = 0;
virtual void drawPoint(const double* position, const double color[4], double pointDrawSize) = 0;
virtual void drawPoints(const float* positions, const float* colors, int numPoints, int pointStrideInBytes, float pointDrawSize) = 0;
virtual void drawTexturedTriangleMesh(float worldPosition[3], float worldOrientation[4], const float* vertices, int numvertices, const unsigned int* indices, int numIndices, float color[4], int textureIndex = -1, int vertexLayout = 0) = 0;

virtual int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices, int primitiveType = B3_GL_TRIANGLES, int textureIndex = -1) = 0;
Expand Down
15 changes: 13 additions & 2 deletions examples/OpenGLWindow/GLInstancingRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,7 @@ void GLInstancingRenderer::drawPoint(const float* positions, const float color[4
{
drawPoints(positions, color, 1, 3 * sizeof(float), pointDrawSize);
}
void GLInstancingRenderer::drawPoints(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, float pointDrawSize)
void GLInstancingRenderer::drawPoints(const float* positions, const float* colors, int numPoints, int pointStrideInBytes, float pointDrawSize)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
Expand All @@ -1898,13 +1898,23 @@ void GLInstancingRenderer::drawPoints(const float* positions, const float color[
glUseProgram(linesShader);
glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &m_data->m_projectionMatrix[0]);
glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &m_data->m_viewMatrix[0]);
glUniform4f(lines_colour, color[0], color[1], color[2], color[3]);

glPointSize(pointDrawSize);
glBindVertexArray(lineVertexArrayObject);

glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);

#if 1
// FIXME: this is slow. cannot draw with color efficiently
for (int i = 0; i < numPoints; i++) {
glUniform4f(lines_colour, colors[4 * i + 0], colors[4 * i + 1], colors[4 * i + 2], colors[4 * i + 3]);
glBufferSubData(GL_ARRAY_BUFFER, 0, pointStrideInBytes, positions + i * (pointStrideInBytes / sizeof(float)));
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, pointStrideInBytes / sizeof(float), GL_FLOAT, GL_FALSE, pointStrideInBytes, 0);
glDrawArrays(GL_POINTS, 0, 1);
}
#else
glUniform4f(lines_colour, colors[0], colors[1], colors[2], colors[3]);
int maxPointsInBatch = MAX_POINTS_IN_BATCH;
int remainingPoints = numPoints;
int offsetNumPoints = 0;
Expand All @@ -1926,6 +1936,7 @@ void GLInstancingRenderer::drawPoints(const float* positions, const float color[
break;
}
}
#endif

glBindVertexArray(0);
glPointSize(1);
Expand Down
3 changes: 3 additions & 0 deletions examples/OpenGLWindow/SimpleOpenGL2Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,9 @@ void SimpleOpenGL2Renderer::drawPoint(const float* position, const float color[4
void SimpleOpenGL2Renderer::drawPoint(const double* position, const double color[4], double pointDrawSize)
{
}
void SimpleOpenGL2Renderer::drawPoints(const float* positions, const float* colors, int numPoints, int pointStrideInBytes, float pointDrawSize)
{
}

void SimpleOpenGL2Renderer::updateShape(int shapeIndex, const float* vertices, int numVertices)
{
Expand Down
2 changes: 2 additions & 0 deletions examples/OpenGLWindow/SimpleOpenGL2Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class SimpleOpenGL2Renderer : public CommonRenderInterface

virtual void drawPoint(const double* position, const double color[4], double pointDrawSize);

virtual void drawPoints(const float* positions, const float* colors, int numPoints, int pointStrideInBytes, float pointDrawSize);

virtual void updateShape(int shapeIndex, const float* vertices, int numVertices);

virtual void clearZBuffer();
Expand Down
22 changes: 16 additions & 6 deletions examples/SharedMemory/PhysicsServerExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3031,14 +3031,24 @@ void PhysicsServerExample::drawUserDebugLines()

for (int i = 0; i < m_multiThreadedHelper->m_userDebugPoints.size(); i++) {
const double* positions = m_multiThreadedHelper->m_userDebugPoints[i].m_debugPointPositions;
const double* colorsRGB = m_multiThreadedHelper->m_userDebugPoints[i].m_debugPointColors;
const double* colors = m_multiThreadedHelper->m_userDebugPoints[i].m_debugPointColors;
const int pointNum = m_multiThreadedHelper->m_userDebugPoints[i].m_debugPointNum;
const double sz = m_multiThreadedHelper->m_userDebugPoints[i].m_pointSize;
for (int j = 0; j < pointNum; j++){
float pos[3] = {(float)positions[3 * j + 0], (float)positions[3 * j + 1], (float)positions[3 * j + 2]};
float colorRGBA[4] = {(float)colorsRGB[3 * j + 0], (float)colorsRGB[3 * j + 1], (float)colorsRGB[3 * j + 2], (float)1.};
m_guiHelper->getAppInterface()->m_renderer->drawPoint(pos, colorRGBA, sz);
}

float* pos = (float*)malloc(pointNum * 3 * sizeof(float));
float* col = (float*)malloc(pointNum * 4 * sizeof(float));
for (int i = 0; i < pointNum; i++) {
pos[3 * i + 0] = (float)positions[3 * i + 0];
pos[3 * i + 1] = (float)positions[3 * i + 1];
pos[3 * i + 2] = (float)positions[3 * i + 2];
col[4 * i + 0] = (float)colors[3 * i + 0];
col[4 * i + 1] = (float)colors[3 * i + 1];
col[4 * i + 2] = (float)colors[3 * i + 2];
col[4 * i + 3] = 1;
}
m_guiHelper->getAppInterface()->m_renderer->drawPoints(pos, col, pointNum, 3 * sizeof(float), sz);
free(pos);
free(col);
}
}
}
Expand Down

0 comments on commit e7460f1

Please sign in to comment.