From 86fa583a5582faa847e4e13e85d4ad979995c771 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 13 Nov 2014 21:11:53 +0100 Subject: [PATCH] [DEV] normalize openGL interface for matrix --- external/ege | 2 +- sources/ewol/compositing/Area.cpp | 2 +- sources/ewol/compositing/Drawing.cpp | 10 +++++++--- sources/ewol/compositing/Drawing.h | 5 +++-- sources/ewol/compositing/Image.cpp | 2 +- sources/ewol/compositing/Shaper.cpp | 2 +- sources/ewol/compositing/Text.cpp | 4 ++-- sources/ewol/compositing/TextDF.cpp | 4 ++-- sources/ewol/resource/Colored3DObject.cpp | 6 +++--- sources/ewol/resource/Program.cpp | 9 ++++++--- sources/ewol/resource/Program.h | 5 ++--- 11 files changed, 29 insertions(+), 22 deletions(-) diff --git a/external/ege b/external/ege index 59a2162d..714662d7 160000 --- a/external/ege +++ b/external/ege @@ -1 +1 @@ -Subproject commit 59a2162deb1cf0e1cad78f11f2bc1ffe36619baf +Subproject commit 714662d7a923c7c451b1a02a636c8c0e3fefce5c diff --git a/sources/ewol/compositing/Area.cpp b/sources/ewol/compositing/Area.cpp index 7066b69d..e8bb6d75 100644 --- a/sources/ewol/compositing/Area.cpp +++ b/sources/ewol/compositing/Area.cpp @@ -61,7 +61,7 @@ void ewol::compositing::Area::draw(bool _disableDepthTest) { // set Matrix : translation/positionMatrix mat4 tmpMatrix = ewol::openGL::getMatrix()*m_matrixApply; m_GLprogram->use(); - m_GLprogram->uniformMatrix4fv(m_GLMatrix, 1, tmpMatrix); + m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix); // TextureID m_GLprogram->setTexture0(m_GLtexID, m_resource->getId()); // position : diff --git a/sources/ewol/compositing/Drawing.cpp b/sources/ewol/compositing/Drawing.cpp index 08f7d09d..8b0ef79b 100644 --- a/sources/ewol/compositing/Drawing.cpp +++ b/sources/ewol/compositing/Drawing.cpp @@ -227,6 +227,7 @@ ewol::compositing::Drawing::Drawing() : m_GLprogram(nullptr), m_GLPosition(-1), m_GLMatrix(-1), + m_GLMatrixPosition(-1), m_GLColor(-1), m_thickness(0.0), m_triElement(0) { @@ -288,8 +289,9 @@ void ewol::compositing::Drawing::loadProgram() { // get the shader resource : if (nullptr != m_GLprogram ) { m_GLPosition = m_GLprogram->getAttribute("EW_coord3d"); - m_GLColor = m_GLprogram->getAttribute("EW_color"); - m_GLMatrix = m_GLprogram->getUniform("EW_MatrixTransformation"); + m_GLColor = m_GLprogram->getAttribute("EW_color"); + m_GLMatrix = m_GLprogram->getUniform("EW_MatrixTransformation"); + m_GLMatrixPosition = m_GLprogram->getUniform("EW_MatrixPosition"); } } @@ -306,7 +308,9 @@ void ewol::compositing::Drawing::draw(bool _disableDepthTest) { // set Matrix : translation/positionMatrix mat4 tmpMatrix = ewol::openGL::getMatrix()*m_matrixApply; m_GLprogram->use(); - m_GLprogram->uniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); + m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix); + mat4 tmpMatrix2; + m_GLprogram->uniformMatrix(m_GLMatrixPosition, tmpMatrix2); // position : m_GLprogram->sendAttribute(m_GLPosition, m_coord); // color : diff --git a/sources/ewol/compositing/Drawing.h b/sources/ewol/compositing/Drawing.h index 69c26dc9..dfdff3a8 100644 --- a/sources/ewol/compositing/Drawing.h +++ b/sources/ewol/compositing/Drawing.h @@ -30,8 +30,9 @@ namespace ewol { private: std::shared_ptr m_GLprogram; //!< pointer on the opengl display program int32_t m_GLPosition; //!< openGL id on the element (vertex buffer) - int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix) - int32_t m_GLColor; //!< openGL id on the element (color buffer) + int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix) + int32_t m_GLMatrixPosition; //!< position matrix + int32_t m_GLColor; //!< openGL id on the element (color buffer) private: // Background Color (display only when needed) std::vector m_coord; //!< internal position for the text display std::vector > m_coordColor; //!< internal color of the background diff --git a/sources/ewol/compositing/Image.cpp b/sources/ewol/compositing/Image.cpp index a35b52fb..17a1711c 100644 --- a/sources/ewol/compositing/Image.cpp +++ b/sources/ewol/compositing/Image.cpp @@ -78,7 +78,7 @@ void ewol::compositing::Image::draw(bool _disableDepthTest) { // set Matrix : translation/positionMatrix mat4 tmpMatrix = ewol::openGL::getMatrix()*m_matrixApply; m_GLprogram->use(); - m_GLprogram->uniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); + m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix); // TextureID if (m_resource != nullptr) { if (m_distanceFieldMode == true) { diff --git a/sources/ewol/compositing/Shaper.cpp b/sources/ewol/compositing/Shaper.cpp index 781f5c46..d06d3f34 100644 --- a/sources/ewol/compositing/Shaper.cpp +++ b/sources/ewol/compositing/Shaper.cpp @@ -184,7 +184,7 @@ void ewol::compositing::Shaper::draw(bool _disableDepthTest) { m_GLprogram->use(); // set Matrix : translation/positionMatrix mat4 tmpMatrix = ewol::openGL::getMatrix(); - m_GLprogram->uniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); + m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix); // position : m_GLprogram->sendAttribute(m_GLPosition, 2/*x,y*/, m_coord); // property diff --git a/sources/ewol/compositing/Text.cpp b/sources/ewol/compositing/Text.cpp index 94ba13c6..81882932 100644 --- a/sources/ewol/compositing/Text.cpp +++ b/sources/ewol/compositing/Text.cpp @@ -51,7 +51,7 @@ void ewol::compositing::Text::drawMT(const mat4& _transformationMatrix, bool _en mat4 camMatrix = ewol::openGL::getCameraMatrix(); mat4 tmpMatrix = projMatrix * camMatrix * _transformationMatrix; m_GLprogram->use(); - m_GLprogram->uniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); + m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix); // Texture : m_GLprogram->setTexture0(m_GLtexID, m_font->getId()); m_GLprogram->uniform1i(m_GLtextWidth, m_font->getOpenGlSize().x()); @@ -90,7 +90,7 @@ void ewol::compositing::Text::drawD(bool _disableDepthTest) { // set Matrix : translation/positionMatrix mat4 tmpMatrix = ewol::openGL::getMatrix()*m_matrixApply; m_GLprogram->use(); - m_GLprogram->uniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); + m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix); // Texture : m_GLprogram->setTexture0(m_GLtexID, m_font->getId()); m_GLprogram->uniform1i(m_GLtextWidth, m_font->getOpenGlSize().x()); diff --git a/sources/ewol/compositing/TextDF.cpp b/sources/ewol/compositing/TextDF.cpp index 88ad96c6..16bfb9e4 100644 --- a/sources/ewol/compositing/TextDF.cpp +++ b/sources/ewol/compositing/TextDF.cpp @@ -62,7 +62,7 @@ void ewol::compositing::TextDF::drawMT(const mat4& _transformationMatrix, bool _ mat4 camMatrix = ewol::openGL::getCameraMatrix(); mat4 tmpMatrix = projMatrix * camMatrix * _transformationMatrix; m_GLprogram->use(); - m_GLprogram->uniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); + m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix); // Texture : m_GLprogram->setTexture0(m_GLtexID, m_fontDF->getId()); m_GLprogram->uniform1i(m_GLtextWidth, m_fontDF->getOpenGlSize().x()); @@ -100,7 +100,7 @@ void ewol::compositing::TextDF::drawD(bool _disableDepthTest) { // set Matrix : translation/positionMatrix mat4 tmpMatrix = ewol::openGL::getMatrix()*m_matrixApply; m_GLprogram->use(); - m_GLprogram->uniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); + m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix); // Texture : m_GLprogram->setTexture0(m_GLtexID, m_fontDF->getId()); m_GLprogram->uniform1i(m_GLtextWidth, m_fontDF->getOpenGlSize().x()); diff --git a/sources/ewol/resource/Colored3DObject.cpp b/sources/ewol/resource/Colored3DObject.cpp index 321ff472..b1f7a084 100644 --- a/sources/ewol/resource/Colored3DObject.cpp +++ b/sources/ewol/resource/Colored3DObject.cpp @@ -59,7 +59,7 @@ void ewol::resource::Colored3DObject::draw(std::vector& _vertices, mat4 projMatrix = ewol::openGL::getMatrix(); mat4 camMatrix = ewol::openGL::getCameraMatrix(); mat4 tmpMatrix = projMatrix * camMatrix; - m_GLprogram->uniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); + m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix); // position : m_GLprogram->sendAttribute(m_GLPosition, 3/*x,y,z,unused*/, &_vertices[0], 4*sizeof(float)); // color : @@ -102,7 +102,7 @@ void ewol::resource::Colored3DObject::draw(std::vector& _vertices, mat4 projMatrix = ewol::openGL::getMatrix(); mat4 camMatrix = ewol::openGL::getCameraMatrix(); mat4 tmpMatrix = projMatrix * camMatrix * _transformationMatrix; - m_GLprogram->uniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); + m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix); // position : m_GLprogram->sendAttribute(m_GLPosition, 3/*x,y,z*/, &_vertices[0], 4*sizeof(float)); // color : @@ -142,7 +142,7 @@ void ewol::resource::Colored3DObject::drawLine(std::vector& _vertices, mat4 projMatrix = ewol::openGL::getMatrix(); mat4 camMatrix = ewol::openGL::getCameraMatrix(); mat4 tmpMatrix = projMatrix * camMatrix * _transformationMatrix; - m_GLprogram->uniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); + m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix); // position : m_GLprogram->sendAttribute(m_GLPosition, 3/*x,y,z*/, &_vertices[0], 4*sizeof(float)); // color : diff --git a/sources/ewol/resource/Program.cpp b/sources/ewol/resource/Program.cpp index a89ed848..d7638c01 100644 --- a/sources/ewol/resource/Program.cpp +++ b/sources/ewol/resource/Program.cpp @@ -358,7 +358,7 @@ void ewol::resource::Program::sendAttributePointer(int32_t _idElem, ////////////////////////////////////////////////////////////////////////////////////////////// -void ewol::resource::Program::uniformMatrix4fv(int32_t _idElem, int32_t _nbElement, mat4 _matrix, bool _transpose) { +void ewol::resource::Program::uniformMatrix(int32_t _idElem, const mat4& _matrix, bool _transpose) { if (0 == m_program) { return; } @@ -371,9 +371,12 @@ void ewol::resource::Program::uniformMatrix4fv(int32_t _idElem, int32_t _nbEleme } // note : Android des not supported the transposition of the matrix, then we will done it oursef: if (true == _transpose) { - _matrix.transpose(); + mat4 tmp = _matrix; + tmp.transpose(); + glUniformMatrix4fv(m_elementList[_idElem].m_elementId, 1, GL_FALSE, tmp.m_mat); + } else { + glUniformMatrix4fv(m_elementList[_idElem].m_elementId, 1, GL_FALSE, _matrix.m_mat); } - glUniformMatrix4fv(m_elementList[_idElem].m_elementId, _nbElement, GL_FALSE, _matrix.m_mat); //checkGlError("glUniformMatrix4fv", __LINE__); } diff --git a/sources/ewol/resource/Program.h b/sources/ewol/resource/Program.h index 6b5837e1..5d2c6372 100644 --- a/sources/ewol/resource/Program.h +++ b/sources/ewol/resource/Program.h @@ -113,11 +113,10 @@ namespace ewol { /** * @brief Send a uniform element to the spefified ID (not send if does not really exist in the openGL program) * @param[in] _idElem Id of the uniform that might be sended. - * @param[in] _nbElement Specifies the number of elements that are to be modified. This should be 1 if the targeted uniform variable is not an array, and 1 or more if it is an array. - * @param[in] _pointer Pointer on the data that might be sended + * @param[in] _matrix Matrix that might be sended. * @param[in] _transpose Transpose the matrix (needed all the taime in the normal openGl access (only not done in the openGL-ES2 due to the fact we must done it ourself) */ - void uniformMatrix4fv(int32_t _idElem, int32_t _nbElement, mat4 _matrix, bool _transpose=true); + void uniformMatrix(int32_t _idElem, const mat4& _matrix, bool _transpose=true); inline void uniform(int32_t _idElem, const etk::Color& _value) { uniform4f(_idElem, _value.r(), _value.g(), _value.b(), _value.a());