minor fix in GL3+ rendering
This commit is contained in:
@@ -29,7 +29,11 @@ void drawCloth(class GLInstancingRenderer* renderer)
|
|||||||
err = glGetError();
|
err = glGetError();
|
||||||
assert(err==GL_NO_ERROR);
|
assert(err==GL_NO_ERROR);
|
||||||
float pointColor[4]={1,0.4,0.4,1};
|
float pointColor[4]={1,0.4,0.4,1};
|
||||||
renderer->drawPoints(&cloth->X[0].x,pointColor,total_points,sizeof(float3),6);
|
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
renderer->drawPoints(&cloth->X[0].x,pointColor,total_points,sizeof(float3),3);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
err = glGetError();
|
err = glGetError();
|
||||||
assert(err==GL_NO_ERROR);
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ float shadowMapHeight=8192;
|
|||||||
float shadowMapWorldSize=100;
|
float shadowMapWorldSize=100;
|
||||||
float WHEEL_MULTIPLIER=0.01f;
|
float WHEEL_MULTIPLIER=0.01f;
|
||||||
float MOUSE_MOVE_MULTIPLIER = 0.4f;
|
float MOUSE_MOVE_MULTIPLIER = 0.4f;
|
||||||
|
#define MAX_POINTS_IN_BATCH 1024
|
||||||
|
#define MAX_LINES_IN_BATCH 1024
|
||||||
|
|
||||||
|
|
||||||
#include "OpenGLInclude.h"
|
#include "OpenGLInclude.h"
|
||||||
#include "b3gWindowInterface.h"
|
#include "b3gWindowInterface.h"
|
||||||
@@ -324,6 +327,9 @@ GLuint lineVertexBufferObject=0;
|
|||||||
GLuint lineVertexArrayObject=0;
|
GLuint lineVertexArrayObject=0;
|
||||||
GLuint lineIndexVbo = 0;
|
GLuint lineIndexVbo = 0;
|
||||||
|
|
||||||
|
GLuint linesVertexBufferObject=0;
|
||||||
|
GLuint linesVertexArrayObject=0;
|
||||||
|
GLuint linesIndexVbo = 0;
|
||||||
|
|
||||||
|
|
||||||
static GLint useShadow_ModelViewMatrix=0;
|
static GLint useShadow_ModelViewMatrix=0;
|
||||||
@@ -736,20 +742,34 @@ void GLInstancingRenderer::InitShaders()
|
|||||||
glLinkProgram(linesShader);
|
glLinkProgram(linesShader);
|
||||||
glUseProgram(linesShader);
|
glUseProgram(linesShader);
|
||||||
|
|
||||||
|
{
|
||||||
|
glGenVertexArrays(1, &linesVertexArrayObject);
|
||||||
|
glBindVertexArray(linesVertexArrayObject);
|
||||||
|
|
||||||
|
glGenBuffers(1, &linesVertexBufferObject);
|
||||||
|
glGenBuffers(1, &linesIndexVbo);
|
||||||
|
|
||||||
|
int sz = MAX_LINES_IN_BATCH*sizeof(b3Vector3);
|
||||||
|
glBindVertexArray(linesVertexArrayObject);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, linesVertexBufferObject);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sz, 0, GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
|
glBindVertexArray(0);
|
||||||
|
}
|
||||||
|
{
|
||||||
glGenVertexArrays(1, &lineVertexArrayObject);
|
glGenVertexArrays(1, &lineVertexArrayObject);
|
||||||
glBindVertexArray(lineVertexArrayObject);
|
glBindVertexArray(lineVertexArrayObject);
|
||||||
|
|
||||||
glGenBuffers(1, &lineVertexBufferObject);
|
glGenBuffers(1, &lineVertexBufferObject);
|
||||||
glGenBuffers(1, &lineIndexVbo);
|
glGenBuffers(1, &lineIndexVbo);
|
||||||
|
|
||||||
int sz = 8*sizeof(float);
|
int sz = MAX_POINTS_IN_BATCH*sizeof(b3Vector3);
|
||||||
glBindVertexArray(lineVertexArrayObject);
|
glBindVertexArray(lineVertexArrayObject);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);
|
glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sz, 0, GL_DYNAMIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sz, 0, GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
}
|
||||||
|
|
||||||
//glGetIntegerv(GL_ALIASED_LINE_WIDTH_RANGE, range);
|
//glGetIntegerv(GL_ALIASED_LINE_WIDTH_RANGE, range);
|
||||||
glGetIntegerv(GL_SMOOTH_LINE_WIDTH_RANGE, lineWidthRange);
|
glGetIntegerv(GL_SMOOTH_LINE_WIDTH_RANGE, lineWidthRange);
|
||||||
@@ -1333,13 +1353,30 @@ void GLInstancingRenderer::drawPoints(const float* positions, const float color[
|
|||||||
glBindVertexArray(lineVertexArrayObject);
|
glBindVertexArray(lineVertexArrayObject);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);
|
glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);
|
||||||
glBufferData(GL_ARRAY_BUFFER, numPoints*pointStrideInBytes, positions, GL_STATIC_DRAW);
|
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, 0);
|
int maxPointsInBatch = MAX_POINTS_IN_BATCH;
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);
|
int remainingPoints = numPoints;
|
||||||
|
int offsetNumPoints= 0;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
int curPointsInBatch = b3Min(maxPointsInBatch, remainingPoints);
|
||||||
|
if (curPointsInBatch)
|
||||||
|
{
|
||||||
|
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, 0, curPointsInBatch*pointStrideInBytes, positions + offsetNumPoints*(pointStrideInBytes / sizeof(float)));
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
int numFloats = pointStrideInBytes/sizeof(float);
|
int numFloats = 3;// pointStrideInBytes / sizeof(float);
|
||||||
glVertexAttribPointer(0, numFloats, GL_FLOAT, GL_FALSE, 0, 0);
|
glVertexAttribPointer(0, numFloats, GL_FLOAT, GL_FALSE, pointStrideInBytes, 0);
|
||||||
glDrawArrays(GL_POINTS, 0, numPoints);
|
glDrawArrays(GL_POINTS, 0, curPointsInBatch);
|
||||||
|
remainingPoints -= curPointsInBatch;
|
||||||
|
offsetNumPoints += curPointsInBatch;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
glPointSize(1);
|
glPointSize(1);
|
||||||
}
|
}
|
||||||
@@ -1365,18 +1402,23 @@ void GLInstancingRenderer::drawLines(const float* positions, const float color[4
|
|||||||
glUniform4f(lines_colour,color[0],color[1],color[2],color[3]);
|
glUniform4f(lines_colour,color[0],color[1],color[2],color[3]);
|
||||||
|
|
||||||
// glPointSize(pointDrawSize);
|
// glPointSize(pointDrawSize);
|
||||||
glBindVertexArray(lineVertexArrayObject);
|
glBindVertexArray(linesVertexArrayObject);
|
||||||
|
|
||||||
err = glGetError();
|
err = glGetError();
|
||||||
b3Assert(err==GL_NO_ERROR);
|
b3Assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);
|
glBindBuffer(GL_ARRAY_BUFFER, linesVertexBufferObject);
|
||||||
glBufferData(GL_ARRAY_BUFFER, numPoints*pointStrideInBytes, positions, GL_STATIC_DRAW);
|
|
||||||
|
{
|
||||||
|
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, numPoints*pointStrideInBytes, 0,GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, 0, numPoints*pointStrideInBytes, positions);
|
||||||
err = glGetError();
|
err = glGetError();
|
||||||
b3Assert(err == GL_NO_ERROR);
|
b3Assert(err == GL_NO_ERROR);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject);
|
glBindBuffer(GL_ARRAY_BUFFER, linesVertexBufferObject);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
err = glGetError();
|
err = glGetError();
|
||||||
@@ -1388,13 +1430,15 @@ void GLInstancingRenderer::drawLines(const float* positions, const float color[4
|
|||||||
b3Assert(err == GL_NO_ERROR);
|
b3Assert(err == GL_NO_ERROR);
|
||||||
|
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, lineIndexVbo);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, linesIndexVbo);
|
||||||
int indexBufferSizeInBytes = numIndices*sizeof(int);
|
int indexBufferSizeInBytes = numIndices*sizeof(int);
|
||||||
|
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexBufferSizeInBytes, NULL, GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexBufferSizeInBytes, NULL, GL_DYNAMIC_DRAW);
|
||||||
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexBufferSizeInBytes, indices);
|
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexBufferSizeInBytes, indices);
|
||||||
|
|
||||||
glDrawElements(GL_LINES, numIndices, GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_LINES, numIndices, GL_UNSIGNED_INT, 0);
|
||||||
|
}
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
// for (int i=0;i<numIndices;i++)
|
// for (int i=0;i<numIndices;i++)
|
||||||
|
|||||||
@@ -280,6 +280,12 @@ void SimpleOpenGL3App::drawGrid(int gridSize, float yOffset)
|
|||||||
m_instancingRenderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(0,1,0),b3MakeVector3(0,1,0),3);
|
m_instancingRenderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(0,1,0),b3MakeVector3(0,1,0),3);
|
||||||
m_instancingRenderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(0,0,1),b3MakeVector3(0,0,1),3);
|
m_instancingRenderer->drawLine(b3MakeVector3(0,0,0),b3MakeVector3(0,0,1),b3MakeVector3(0,0,1),3);
|
||||||
|
|
||||||
|
// void GLInstancingRenderer::drawPoints(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, float pointDrawSize)
|
||||||
|
|
||||||
|
//we don't use drawPoints because all points would have the same color
|
||||||
|
// b3Vector3 points[3] = { b3MakeVector3(1, 0, 0), b3MakeVector3(0, 1, 0), b3MakeVector3(0, 0, 1) };
|
||||||
|
// m_instancingRenderer->drawPoints(&points[0].x, b3MakeVector3(1, 0, 0), 3, sizeof(b3Vector3), 6);
|
||||||
|
|
||||||
m_instancingRenderer->drawPoint(b3MakeVector3(1,0,0),b3MakeVector3(1,0,0),6);
|
m_instancingRenderer->drawPoint(b3MakeVector3(1,0,0),b3MakeVector3(1,0,0),6);
|
||||||
m_instancingRenderer->drawPoint(b3MakeVector3(0,1,0),b3MakeVector3(0,1,0),6);
|
m_instancingRenderer->drawPoint(b3MakeVector3(0,1,0),b3MakeVector3(0,1,0),6);
|
||||||
m_instancingRenderer->drawPoint(b3MakeVector3(0,0,1),b3MakeVector3(0,0,1),6);
|
m_instancingRenderer->drawPoint(b3MakeVector3(0,0,1),b3MakeVector3(0,0,1),6);
|
||||||
|
|||||||
Reference in New Issue
Block a user