Skip to content

Commit 6ed5df0

Browse files
committed
Further double-precision fixes
1 parent deab1df commit 6ed5df0

File tree

3 files changed

+43
-38
lines changed

3 files changed

+43
-38
lines changed

GUI/OpenGL/MiniGL.cpp

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int MiniGL::m_width = 0;
3636
int MiniGL::m_height = 0;
3737
int MiniGL::m_windowWidth = 0;
3838
int MiniGL::m_windowHeight = 0;
39-
Real MiniGL::m_devicePixelRatio = 1.0f;
39+
Real MiniGL::m_devicePixelRatio = 1.0;
4040
Quaternionr MiniGL::m_rotation;
4141
Real MiniGL::m_zoom = 1.0;
4242
Vector3r MiniGL::m_translation;
@@ -709,24 +709,24 @@ void MiniGL::viewport ()
709709

710710
void MiniGL::initLights ()
711711
{
712-
m_ambientIntensity << 0.2, 0.2, 0.2;
712+
m_ambientIntensity << 0.2f, 0.2f, 0.2f;
713713

714714
m_numLights = 3;
715715
m_diffuseIntensity.resize(m_numLights * 3);
716716
m_specularIntensity.resize(m_numLights * 3);
717717
m_lightPosition.resize(m_numLights * 3);
718718

719-
m_diffuseIntensity.segment<3>(0) << 0.9, 0.0, 0.0;
720-
m_specularIntensity.segment<3>(0) << 1.0, 1.0, 1.0;
721-
m_lightPosition.segment<3>(0) << -10.0, 10.0, 10.0;
719+
m_diffuseIntensity.segment<3>(0) << 0.9f, 0.0f, 0.0f;
720+
m_specularIntensity.segment<3>(0) << 1.0f, 1.0f, 1.0f;
721+
m_lightPosition.segment<3>(0) << -10.0f, 10.0f, 10.0f;
722722

723-
m_diffuseIntensity.segment<3>(1 * 3) << 0.0, 0.0, 0.9;
724-
m_specularIntensity.segment<3>(1 * 3) << 1.0, 1.0, 1.0;
725-
m_lightPosition.segment<3>(1 * 3) << 10.0, 10.0, 10.0;
723+
m_diffuseIntensity.segment<3>(1 * 3) << 0.0f, 0.0f, 0.9f;
724+
m_specularIntensity.segment<3>(1 * 3) << 1.0f, 1.0f, 1.0f;
725+
m_lightPosition.segment<3>(1 * 3) << 10.0f, 10.0f, 10.0f;
726726

727-
m_diffuseIntensity.segment<3>(2 * 3) << 0.0, 0.9, 0.0;
728-
m_specularIntensity.segment<3>(2 * 3) << 1.0, 1.0, 1.0;
729-
m_lightPosition.segment<3>(2 * 3) << 0.0, 10.0, 10.0;
727+
m_diffuseIntensity.segment<3>(2 * 3) << 0.0f, 0.9f, 0.0f;
728+
m_specularIntensity.segment<3>(2 * 3) << 1.0f, 1.0f, 1.0f;
729+
m_lightPosition.segment<3>(2 * 3) << 0.0f, 10.0f, 10.0f;
730730
}
731731

732732
void MiniGL::initShaders(const std::string& shaderPath)
@@ -811,22 +811,20 @@ void MiniGL::disableScreenShader()
811811
shader.end();
812812
}
813813

814-
void MiniGL::supplyVectors(GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const Real* data)
814+
void MiniGL::supplyVectors(GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const float* data)
815815
{
816816
glBindBuffer(GL_ARRAY_BUFFER, vbo);
817-
glBufferData(GL_ARRAY_BUFFER, n * dim * sizeof(Real), data, GL_STREAM_DRAW);
818-
glVertexAttribPointer(index, dim, GL_REAL, GL_FALSE, 0, (void*)0);
817+
glBufferData(GL_ARRAY_BUFFER, n * dim * sizeof(float), data, GL_STREAM_DRAW);
818+
glVertexAttribPointer(index, dim, GL_FLOAT, GL_FALSE, 0, (void*)0);
819819
glEnableVertexAttribArray(index);
820820
}
821821

822-
void MiniGL::supplyVertices(GLuint index, unsigned int numVectors, const Real* data)
822+
void MiniGL::supplyVectors(GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const double* data)
823823
{
824-
supplyVectors(index, m_vbo_vertices, 3, numVectors, data);
825-
}
826-
827-
void MiniGL::supplyNormals(GLuint index, unsigned int numVectors, const Real* data)
828-
{
829-
supplyVectors(index, m_vbo_normals, 3, numVectors, data);
824+
glBindBuffer(GL_ARRAY_BUFFER, vbo);
825+
glBufferData(GL_ARRAY_BUFFER, n * dim * sizeof(double), data, GL_STREAM_DRAW);
826+
glVertexAttribPointer(index, dim, GL_DOUBLE, GL_FALSE, 0, (void*)0);
827+
glEnableVertexAttribArray(index);
830828
}
831829

832830
void MiniGL::supplyIndices(GLuint vbo, unsigned int n, const unsigned int* data)
@@ -835,11 +833,6 @@ void MiniGL::supplyIndices(GLuint vbo, unsigned int n, const unsigned int* data)
835833
glBufferData(GL_ELEMENT_ARRAY_BUFFER, n * sizeof(unsigned int), data, GL_STREAM_DRAW);
836834
}
837835

838-
void MiniGL::supplyFaces(unsigned int numIndices, const unsigned int* data)
839-
{
840-
supplyIndices(m_vbo_faces, numIndices, data);
841-
}
842-
843836
void MiniGL::move(Real x, Real y, Real z)
844837
{
845838
m_translation[0] += x;

GUI/OpenGL/MiniGL.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,27 @@ namespace SPH
240240
static const GLuint getVboFaces() { return m_vbo_faces; }
241241

242242
// Fill a VBO with vector data and map to the VAO attribute at the specified index.
243-
static void supplyVectors(GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const Real* data);
243+
static void supplyVectors(GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const float* data);
244+
static void supplyVectors(GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const double* data);
244245
// Fill the dedicated VBO with 3D vertex data and map to the VAO attribute at the specified index.
245-
static void supplyVertices(GLuint index, unsigned int numVectors, const Real* data);
246+
template<typename T>
247+
static void supplyVertices(GLuint index, unsigned int numVectors, const T* data)
248+
{
249+
supplyVectors(index, m_vbo_vertices, 3, numVectors, data);
250+
}
246251
// Fill the dedicated VBO with 3D normal data and map to the VAO attribute at the specified index.
247-
static void supplyNormals(GLuint index, unsigned int numVectors, const Real* data);
252+
template<typename T>
253+
static void supplyNormals(GLuint index, unsigned int numVectors, const T* data)
254+
{
255+
supplyVectors(index, m_vbo_normals, 3, numVectors, data);
256+
}
248257
// Fill a VBO with index data.
249258
static void supplyIndices(GLuint vbo, unsigned int n, const unsigned int* data);
250259
// Fill the dedicated VBO with face index data.
251-
static void supplyFaces(unsigned int numIndices, const unsigned int* data);
260+
static void supplyFaces(unsigned int numIndices, const unsigned int* data)
261+
{
262+
supplyIndices(m_vbo_faces, numIndices, data);
263+
}
252264
};
253265
}
254266

Tools/PartioViewer/GUI/OpenGL/PartioViewer_OpenGL.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ void PartioViewer_OpenGL::pointShaderBegin(Shader *shader, const Real particleRa
152152
}
153153

154154

155-
const GLfloat* matrix = &MiniGL::getModelviewMatrix()(0,0);
156-
glUniformMatrix4fv(shader->getUniform("modelview_matrix"), 1, GL_FALSE, matrix);
157-
const GLfloat* pmatrix = &MiniGL::getProjectionMatrix()(0,0);
158-
glUniformMatrix4fv(shader->getUniform("projection_matrix"), 1, GL_FALSE, pmatrix);
155+
const Matrix4f matrix(MiniGL::getModelviewMatrix().cast<float>());
156+
glUniformMatrix4fv(shader->getUniform("modelview_matrix"), 1, GL_FALSE, &matrix(0,0));
157+
const Matrix4f pmatrix(MiniGL::getProjectionMatrix().cast<float>());
158+
glUniformMatrix4fv(shader->getUniform("projection_matrix"), 1, GL_FALSE, &pmatrix(0,0));
159159

160160
glEnable(GL_DEPTH_TEST);
161161
glEnable(GL_PROGRAM_POINT_SIZE);
@@ -310,10 +310,10 @@ void PartioViewer_OpenGL::render(const Boundary &boundary, const bool renderWall
310310
glUniform1f(m_meshShader.getUniform("shininess"), 5.0f);
311311
glUniform1f(m_meshShader.getUniform("specular_factor"), 0.2f);
312312

313-
const GLfloat* matrix = &MiniGL::getModelviewMatrix()(0,0);
314-
glUniformMatrix4fv(m_meshShader.getUniform("modelview_matrix"), 1, GL_FALSE, matrix);
315-
const GLfloat* pmatrix = &MiniGL::getProjectionMatrix()(0,0);
316-
glUniformMatrix4fv(m_meshShader.getUniform("projection_matrix"), 1, GL_FALSE, pmatrix);
313+
const Matrix4f matrix(MiniGL::getModelviewMatrix().cast<float>());
314+
glUniformMatrix4fv(m_meshShader.getUniform("modelview_matrix"), 1, GL_FALSE, &matrix(0,0));
315+
const Matrix4f pmatrix(MiniGL::getProjectionMatrix().cast<float>());
316+
glUniformMatrix4fv(m_meshShader.getUniform("projection_matrix"), 1, GL_FALSE, &pmatrix(0,0));
317317

318318
glUniform3fv(m_meshShader.getUniform("surface_color"), 1, &boundary.color[0]);
319319

0 commit comments

Comments
 (0)