summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerwincoumans <erwin.coumans@gmail.com>2022-04-23 15:52:10 -0700
committerGitHub <noreply@github.com>2022-04-23 15:52:10 -0700
commitce23bb9dce1d2fe1fb0b1f9522afec54853f462f (patch)
tree5f5f3f00612bd2f8b416758151f0c9d10fdd2a1e
parent0edcbd693a6f0866e9600df44a93740bad6e7cb9 (diff)
parentf263c422e22c4253a3f181ac317b42cb6dfe5ac4 (diff)
downloadbullet3-ce23bb9dce1d2fe1fb0b1f9522afec54853f462f.tar.gz
Merge pull request #4249 from erwincoumans/master
fix for debug lines / point rendering, introduced in PR #3996
-rw-r--r--examples/OpenGLWindow/GLInstancingRenderer.cpp80
-rw-r--r--examples/OpenGLWindow/Shaders/linesVS.glsl2
-rw-r--r--examples/OpenGLWindow/Shaders/linesVS.h3
-rw-r--r--examples/OpenGLWindow/Shaders/pointsPS.glsl10
-rw-r--r--examples/OpenGLWindow/Shaders/pointsPS.h10
-rw-r--r--examples/OpenGLWindow/Shaders/pointsVS.glsl15
-rw-r--r--examples/OpenGLWindow/Shaders/pointsVS.h16
7 files changed, 118 insertions, 18 deletions
diff --git a/examples/OpenGLWindow/GLInstancingRenderer.cpp b/examples/OpenGLWindow/GLInstancingRenderer.cpp
index 75e3d4cd9..66bd5bf44 100644
--- a/examples/OpenGLWindow/GLInstancingRenderer.cpp
+++ b/examples/OpenGLWindow/GLInstancingRenderer.cpp
@@ -98,7 +98,10 @@ struct caster2
#include "Shaders/segmentationMaskInstancingPS.h"
#include "Shaders/linesPS.h"
+#include "Shaders/pointsPS.h"
+
#include "Shaders/linesVS.h"
+#include "Shaders/pointsVS.h"
#include "GLRenderToTexture.h"
#include "stb_image/stb_image_write.h"
@@ -287,26 +290,43 @@ static GLuint triangleVertexBufferObject = 0;
static GLuint triangleVertexArrayObject = 0;
static GLuint triangleIndexVbo = 0;
-static GLuint linesShader; // The line renderer
+static GLuint linesShader; // The line renderer
+static GLuint pointsShader; // The point renderer
+
static GLuint useShadowMapInstancingShader; // The shadow instancing renderer
static GLuint createShadowMapInstancingShader; // The shadow instancing renderer
static GLuint projectiveTextureInstancingShader; // The projective texture instancing renderer
static GLuint segmentationMaskInstancingShader; // The segmentation mask instancing renderer
+
static GLuint instancingShader; // The instancing renderer
static GLuint instancingShaderPointSprite; // The point sprite instancing renderer
//static bool done = false;
+static GLint points_ModelViewMatrix = 0;
+static GLint points_ProjectionMatrix = 0;
+static GLint points_position = 0;
+static GLint points_colourIn = 0;
+static GLint points_colour = 0;
+GLuint pointsVertexBufferObject = 0;
+GLuint pointsVertexArrayObject = 0;
+GLuint pointsIndexVbo = 0;
+
static GLint lines_ModelViewMatrix = 0;
static GLint lines_ProjectionMatrix = 0;
static GLint lines_position = 0;
static GLint lines_colour = 0;
-static GLint lines_colourIn = 0;
+
GLuint lineVertexBufferObject = 0;
GLuint lineVertexArrayObject = 0;
GLuint lineIndexVbo = 0;
+
+
+
+
+
GLuint linesVertexBufferObject = 0;
GLuint linesVertexArrayObject = 0;
GLuint linesIndexVbo = 0;
@@ -1243,12 +1263,38 @@ void GLInstancingRenderer::InitShaders()
glBindVertexArray(0);
}
+ {
+ pointsShader = gltLoadShaderPair(pointsVertexShader, pointsFragmentShader);
+ points_ModelViewMatrix = glGetUniformLocation(pointsShader, "ModelViewMatrix");
+ points_ProjectionMatrix = glGetUniformLocation(pointsShader, "ProjectionMatrix");
+ points_colour = glGetUniformLocation(pointsShader, "colour");
+ points_colourIn = glGetAttribLocation(pointsShader, "colourIn");
+ points_position = glGetAttribLocation(pointsShader, "position");
+ glLinkProgram(pointsShader);
+ glUseProgram(pointsShader);
+ int max_viewports=-1;
+ glGetIntegerv(GL_MAX_VIEWPORTS, &max_viewports);
+ {
+ glGenVertexArrays(1, &pointsVertexArrayObject);
+ glBindVertexArray(pointsVertexArrayObject);
+
+ glGenBuffers(1, &pointsVertexBufferObject);
+ glGenBuffers(1, &pointsIndexVbo);
+
+ int sz = MAX_POINTS_IN_BATCH * sizeof(b3Vector3);
+ glBindVertexArray(pointsVertexArrayObject);
+ glBindBuffer(GL_ARRAY_BUFFER, pointsVertexBufferObject);
+ glBufferData(GL_ARRAY_BUFFER, sz, 0, GL_DYNAMIC_DRAW);
+
+ glBindVertexArray(0);
+ }
+
+ }
linesShader = gltLoadShaderPair(linesVertexShader, linesFragmentShader);
lines_ModelViewMatrix = glGetUniformLocation(linesShader, "ModelViewMatrix");
lines_ProjectionMatrix = glGetUniformLocation(linesShader, "ProjectionMatrix");
lines_colour = glGetUniformLocation(linesShader, "colour");
- lines_colourIn = glGetAttribLocation(linesShader, "colourIn");
lines_position = glGetAttribLocation(linesShader, "position");
glLinkProgram(linesShader);
glUseProgram(linesShader);
@@ -1267,6 +1313,9 @@ void GLInstancingRenderer::InitShaders()
glBindVertexArray(0);
}
+
+
+
{
glGenVertexArrays(1, &lineVertexArrayObject);
glBindVertexArray(lineVertexArrayObject);
@@ -1891,19 +1940,20 @@ 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* colors, int numPoints, int pointStrideInBytes, float pointDrawSize)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
b3Assert(glGetError() == GL_NO_ERROR);
- 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, 0, 0, 0, -1);
+ glUseProgram(pointsShader);
+ glUniformMatrix4fv(points_ProjectionMatrix, 1, false, &m_data->m_projectionMatrix[0]);
+ glUniformMatrix4fv(points_ModelViewMatrix, 1, false, &m_data->m_viewMatrix[0]);
+ glUniform4f(points_colour, 0, 0, 0, -1);
glPointSize(pointDrawSize);
- glBindVertexArray(lineVertexArrayObject);
+ glBindVertexArray(pointsVertexArrayObject);
int maxPointsInBatch = MAX_POINTS_IN_BATCH;
int remainingPoints = numPoints;
@@ -1913,15 +1963,15 @@ void GLInstancingRenderer::drawPoints(const float* positions, const float* color
int curPointsInBatch = b3Min(maxPointsInBatch, remainingPoints);
if (curPointsInBatch)
{
- glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);
+ glBindBuffer(GL_ARRAY_BUFFER, pointsVertexBufferObject);
glBufferSubData(GL_ARRAY_BUFFER, 0, curPointsInBatch * pointStrideInBytes, positions + offsetNumPoints * 3);
- glEnableVertexAttribArray(lines_position);
- glVertexAttribPointer(lines_position, 3, GL_FLOAT, GL_FALSE, pointStrideInBytes, 0);
+ glEnableVertexAttribArray(points_position);
+ glVertexAttribPointer(points_position, 3, GL_FLOAT, GL_FALSE, pointStrideInBytes, 0);
- glBindBuffer(GL_ARRAY_BUFFER, lineVertexArrayObject);
+ glBindBuffer(GL_ARRAY_BUFFER, pointsVertexArrayObject);
glBufferSubData(GL_ARRAY_BUFFER, 0, curPointsInBatch * 4 * sizeof(float), colors + offsetNumPoints * 4);
- glEnableVertexAttribArray(lines_colourIn);
- glVertexAttribPointer(lines_colourIn, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
+ glEnableVertexAttribArray(points_colourIn);
+ glVertexAttribPointer(points_colourIn, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
glDrawArrays(GL_POINTS, 0, curPointsInBatch);
remainingPoints -= curPointsInBatch;
@@ -1932,7 +1982,7 @@ void GLInstancingRenderer::drawPoints(const float* positions, const float* color
break;
}
}
-
+
glBindVertexArray(0);
glPointSize(1);
glUseProgram(0);
diff --git a/examples/OpenGLWindow/Shaders/linesVS.glsl b/examples/OpenGLWindow/Shaders/linesVS.glsl
index 335fac7bc..5ba8fd73e 100644
--- a/examples/OpenGLWindow/Shaders/linesVS.glsl
+++ b/examples/OpenGLWindow/Shaders/linesVS.glsl
@@ -11,7 +11,7 @@ out vec4 colourV;
void main (void)
{
- colourV = (colour[3] == -1) ? colourIn : colour;
+ colourV = colour;
gl_Position = ProjectionMatrix * ModelViewMatrix * position;
}
diff --git a/examples/OpenGLWindow/Shaders/linesVS.h b/examples/OpenGLWindow/Shaders/linesVS.h
index 0054b14cf..c69c5978b 100644
--- a/examples/OpenGLWindow/Shaders/linesVS.h
+++ b/examples/OpenGLWindow/Shaders/linesVS.h
@@ -5,11 +5,10 @@ static const char* linesVertexShader= \
"uniform mat4 ProjectionMatrix;\n"
"uniform vec4 colour;\n"
"in vec4 position;\n"
-"in vec4 colourIn;\n"
"out vec4 colourV;\n"
"void main (void)\n"
"{\n"
-" colourV = (colour[3] == -1) ? colourIn : colour;\n"
+" colourV = colour;\n"
" gl_Position = ProjectionMatrix * ModelViewMatrix * position;\n"
" \n"
"}\n"
diff --git a/examples/OpenGLWindow/Shaders/pointsPS.glsl b/examples/OpenGLWindow/Shaders/pointsPS.glsl
new file mode 100644
index 000000000..c646fa11b
--- /dev/null
+++ b/examples/OpenGLWindow/Shaders/pointsPS.glsl
@@ -0,0 +1,10 @@
+
+#version 150
+
+in vec4 colourV;
+out vec4 fragColour;
+
+void main(void)
+{
+ fragColour = colourV;
+}
diff --git a/examples/OpenGLWindow/Shaders/pointsPS.h b/examples/OpenGLWindow/Shaders/pointsPS.h
new file mode 100644
index 000000000..ace997f95
--- /dev/null
+++ b/examples/OpenGLWindow/Shaders/pointsPS.h
@@ -0,0 +1,10 @@
+//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
+static const char* pointsFragmentShader= \
+"#version 150\n"
+"in vec4 colourV;\n"
+"out vec4 fragColour;\n"
+"void main(void)\n"
+"{\n"
+" fragColour = colourV;\n"
+"}\n"
+;
diff --git a/examples/OpenGLWindow/Shaders/pointsVS.glsl b/examples/OpenGLWindow/Shaders/pointsVS.glsl
new file mode 100644
index 000000000..4b9520341
--- /dev/null
+++ b/examples/OpenGLWindow/Shaders/pointsVS.glsl
@@ -0,0 +1,15 @@
+#version 150
+
+uniform mat4 ModelViewMatrix;
+uniform mat4 ProjectionMatrix;
+uniform vec4 colour;
+in vec4 position;
+in vec4 colourIn;
+out vec4 colourV;
+
+void main (void)
+{
+ colourV = (colour[3] == -1) ? colourIn : colour;
+ gl_Position = ProjectionMatrix * ModelViewMatrix * position;
+
+}
diff --git a/examples/OpenGLWindow/Shaders/pointsVS.h b/examples/OpenGLWindow/Shaders/pointsVS.h
new file mode 100644
index 000000000..dda938603
--- /dev/null
+++ b/examples/OpenGLWindow/Shaders/pointsVS.h
@@ -0,0 +1,16 @@
+//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
+static const char* pointsVertexShader= \
+"#version 150 \n"
+"uniform mat4 ModelViewMatrix;\n"
+"uniform mat4 ProjectionMatrix;\n"
+"uniform vec4 colour;\n"
+"in vec4 position;\n"
+"in vec4 colourIn;\n"
+"out vec4 colourV;\n"
+"void main (void)\n"
+"{\n"
+" colourV = (colour[3] == -1) ? colourIn : colour;\n"
+" gl_Position = ProjectionMatrix * ModelViewMatrix * position;\n"
+" \n"
+"}\n"
+;