diff --git a/GUI/OpenGL/MiniGL.cpp b/GUI/OpenGL/MiniGL.cpp index 2c258bad..63cf17c3 100644 --- a/GUI/OpenGL/MiniGL.cpp +++ b/GUI/OpenGL/MiniGL.cpp @@ -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; @@ -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) @@ -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) @@ -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; diff --git a/GUI/OpenGL/MiniGL.h b/GUI/OpenGL/MiniGL.h index 7b98ea82..431d49cf 100644 --- a/GUI/OpenGL/MiniGL.h +++ b/GUI/OpenGL/MiniGL.h @@ -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 + 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 + 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); + } }; } diff --git a/Tools/PartioViewer/GUI/OpenGL/PartioViewer_OpenGL.cpp b/Tools/PartioViewer/GUI/OpenGL/PartioViewer_OpenGL.cpp index 3a4daad9..b3ec7411 100644 --- a/Tools/PartioViewer/GUI/OpenGL/PartioViewer_OpenGL.cpp +++ b/Tools/PartioViewer/GUI/OpenGL/PartioViewer_OpenGL.cpp @@ -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()); + glUniformMatrix4fv(shader->getUniform("modelview_matrix"), 1, GL_FALSE, &matrix(0,0)); + const Matrix4f pmatrix(MiniGL::getProjectionMatrix().cast()); + glUniformMatrix4fv(shader->getUniform("projection_matrix"), 1, GL_FALSE, &pmatrix(0,0)); glEnable(GL_DEPTH_TEST); glEnable(GL_PROGRAM_POINT_SIZE); @@ -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()); + glUniformMatrix4fv(m_meshShader.getUniform("modelview_matrix"), 1, GL_FALSE, &matrix(0,0)); + const Matrix4f pmatrix(MiniGL::getProjectionMatrix().cast()); + glUniformMatrix4fv(m_meshShader.getUniform("projection_matrix"), 1, GL_FALSE, &pmatrix(0,0)); glUniform3fv(m_meshShader.getUniform("surface_color"), 1, &boundary.color[0]);