Skip to content

Commit

Permalink
Further double-precision fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ruberith committed Sep 20, 2024
1 parent deab1df commit 6ed5df0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 38 deletions.
45 changes: 19 additions & 26 deletions GUI/OpenGL/MiniGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int MiniGL::m_width = 0;
int MiniGL::m_height = 0;
int MiniGL::m_windowWidth = 0;
int MiniGL::m_windowHeight = 0;
Real MiniGL::m_devicePixelRatio = 1.0f;
Real MiniGL::m_devicePixelRatio = 1.0;
Quaternionr MiniGL::m_rotation;
Real MiniGL::m_zoom = 1.0;
Vector3r MiniGL::m_translation;
Expand Down Expand Up @@ -709,24 +709,24 @@ void MiniGL::viewport ()

void MiniGL::initLights ()
{
m_ambientIntensity << 0.2, 0.2, 0.2;
m_ambientIntensity << 0.2f, 0.2f, 0.2f;

m_numLights = 3;
m_diffuseIntensity.resize(m_numLights * 3);
m_specularIntensity.resize(m_numLights * 3);
m_lightPosition.resize(m_numLights * 3);

m_diffuseIntensity.segment<3>(0) << 0.9, 0.0, 0.0;
m_specularIntensity.segment<3>(0) << 1.0, 1.0, 1.0;
m_lightPosition.segment<3>(0) << -10.0, 10.0, 10.0;
m_diffuseIntensity.segment<3>(0) << 0.9f, 0.0f, 0.0f;
m_specularIntensity.segment<3>(0) << 1.0f, 1.0f, 1.0f;
m_lightPosition.segment<3>(0) << -10.0f, 10.0f, 10.0f;

m_diffuseIntensity.segment<3>(1 * 3) << 0.0, 0.0, 0.9;
m_specularIntensity.segment<3>(1 * 3) << 1.0, 1.0, 1.0;
m_lightPosition.segment<3>(1 * 3) << 10.0, 10.0, 10.0;
m_diffuseIntensity.segment<3>(1 * 3) << 0.0f, 0.0f, 0.9f;
m_specularIntensity.segment<3>(1 * 3) << 1.0f, 1.0f, 1.0f;
m_lightPosition.segment<3>(1 * 3) << 10.0f, 10.0f, 10.0f;

m_diffuseIntensity.segment<3>(2 * 3) << 0.0, 0.9, 0.0;
m_specularIntensity.segment<3>(2 * 3) << 1.0, 1.0, 1.0;
m_lightPosition.segment<3>(2 * 3) << 0.0, 10.0, 10.0;
m_diffuseIntensity.segment<3>(2 * 3) << 0.0f, 0.9f, 0.0f;
m_specularIntensity.segment<3>(2 * 3) << 1.0f, 1.0f, 1.0f;
m_lightPosition.segment<3>(2 * 3) << 0.0f, 10.0f, 10.0f;
}

void MiniGL::initShaders(const std::string& shaderPath)
Expand Down Expand Up @@ -811,22 +811,20 @@ void MiniGL::disableScreenShader()
shader.end();
}

void MiniGL::supplyVectors(GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const Real* data)
void MiniGL::supplyVectors(GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const float* data)
{
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, n * dim * sizeof(Real), data, GL_STREAM_DRAW);
glVertexAttribPointer(index, dim, GL_REAL, GL_FALSE, 0, (void*)0);
glBufferData(GL_ARRAY_BUFFER, n * dim * sizeof(float), data, GL_STREAM_DRAW);
glVertexAttribPointer(index, dim, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(index);
}

void MiniGL::supplyVertices(GLuint index, unsigned int numVectors, const Real* data)
void MiniGL::supplyVectors(GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const double* data)
{
supplyVectors(index, m_vbo_vertices, 3, numVectors, data);
}

void MiniGL::supplyNormals(GLuint index, unsigned int numVectors, const Real* data)
{
supplyVectors(index, m_vbo_normals, 3, numVectors, data);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, n * dim * sizeof(double), data, GL_STREAM_DRAW);
glVertexAttribPointer(index, dim, GL_DOUBLE, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(index);
}

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

void MiniGL::supplyFaces(unsigned int numIndices, const unsigned int* data)
{
supplyIndices(m_vbo_faces, numIndices, data);
}

void MiniGL::move(Real x, Real y, Real z)
{
m_translation[0] += x;
Expand Down
20 changes: 16 additions & 4 deletions GUI/OpenGL/MiniGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,27 @@ namespace SPH
static const GLuint getVboFaces() { return m_vbo_faces; }

// Fill a VBO with vector data and map to the VAO attribute at the specified index.
static void supplyVectors(GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const Real* data);
static void supplyVectors(GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const float* data);
static void supplyVectors(GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const double* data);
// Fill the dedicated VBO with 3D vertex data and map to the VAO attribute at the specified index.
static void supplyVertices(GLuint index, unsigned int numVectors, const Real* data);
template<typename T>
static void supplyVertices(GLuint index, unsigned int numVectors, const T* data)
{
supplyVectors(index, m_vbo_vertices, 3, numVectors, data);
}
// Fill the dedicated VBO with 3D normal data and map to the VAO attribute at the specified index.
static void supplyNormals(GLuint index, unsigned int numVectors, const Real* data);
template<typename T>
static void supplyNormals(GLuint index, unsigned int numVectors, const T* data)
{
supplyVectors(index, m_vbo_normals, 3, numVectors, data);
}
// Fill a VBO with index data.
static void supplyIndices(GLuint vbo, unsigned int n, const unsigned int* data);
// Fill the dedicated VBO with face index data.
static void supplyFaces(unsigned int numIndices, const unsigned int* data);
static void supplyFaces(unsigned int numIndices, const unsigned int* data)
{
supplyIndices(m_vbo_faces, numIndices, data);
}
};
}

Expand Down
16 changes: 8 additions & 8 deletions Tools/PartioViewer/GUI/OpenGL/PartioViewer_OpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ void PartioViewer_OpenGL::pointShaderBegin(Shader *shader, const Real particleRa
}


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

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

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

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

Expand Down

0 comments on commit 6ed5df0

Please sign in to comment.