diff --git a/Sources/libetk/etk/Matrix.cpp b/Sources/libetk/etk/Matrix.cpp new file mode 100644 index 00000000..a7b30bfa --- /dev/null +++ b/Sources/libetk/etk/Matrix.cpp @@ -0,0 +1,102 @@ +/** + ******************************************************************************* + * @file etk/Matix.cpp + * @brief Ewol Tool Kit : generique Matrix type (Sources) + * @author Edouard DUPIN + * @date 29/08/2012 + * @par Project + * Ewol TK + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + + + +#include +#include +#include +#include + +etk::Matrix etk::matrix::Perspective(float left, float right, float bottom, float top, float nearVal, float farVal) +{ + etk::Matrix tmp; + for(int32_t iii=0; iii<4*4 ; iii++) { + tmp.m_mat[iii] = 0; + } + tmp.m_mat[0] = 2.0 / (right - left); + tmp.m_mat[5] = 2.0 / (top - bottom); + tmp.m_mat[10] = -2.0 / (farVal - nearVal); + tmp.m_mat[3] = -1*(right + left) / (right - left); + tmp.m_mat[7] = -1*(top + bottom) / (top - bottom); + tmp.m_mat[11] = -1*(farVal + nearVal) / (farVal - nearVal); + tmp.m_mat[15] = 1; + //TK_INFO("Perspective :"); + //etk::matrix::Display(tmp); + return tmp; +} + +etk::Matrix etk::matrix::Translate(float x, float y, float z) +{ + etk::Matrix tmp; + // set translation : + tmp.m_mat[3] = x; + tmp.m_mat[7] = y; + tmp.m_mat[11] = z; + //TK_INFO("Translate :"); + //etk::matrix::Display(tmp); + return tmp; +} + +etk::Matrix etk::matrix::Scale(float x, float y, float z) +{ + etk::Matrix tmp; + // set scale : + tmp.m_mat[0] = x; + tmp.m_mat[5] = y; + tmp.m_mat[10] = z; + //TK_INFO("Scale :"); + //etk::matrix::Display(tmp); + return tmp; +} + +etk::Matrix etk::matrix::rotate(float x, float y, float z, float angleRad) +{ + etk::Matrix tmp; + float cosVal = cos(angleRad); + float sinVal = sin(angleRad); + float invVal = 1.0-cosVal; + // set rotation : + tmp.m_mat[0] = x*x*invVal + cosVal; + tmp.m_mat[1] = x*y*invVal - z*cosVal; + tmp.m_mat[2] = x*z*invVal + y*sinVal; + + tmp.m_mat[4] = y*x*invVal + z*sinVal; + tmp.m_mat[5] = y*y*invVal + cosVal; + tmp.m_mat[6] = y*z*invVal - x*sinVal; + + tmp.m_mat[8] = z*x*invVal - y*sinVal; + tmp.m_mat[9] = z*y*invVal + x*sinVal; + tmp.m_mat[10] = z*z*invVal + cosVal; + return tmp; +} + + +void etk::matrix::Display(etk::Matrix& tmp) +{ + TK_INFO("matrix : (" << tmp.m_mat[0] << " , " << tmp.m_mat[1] << " , " << tmp.m_mat[2] << " , " << tmp.m_mat[3] << " , "); + TK_INFO(" " << tmp.m_mat[4] << " , " << tmp.m_mat[5] << " , " << tmp.m_mat[6] << " , " << tmp.m_mat[7] << " , "); + TK_INFO(" " << tmp.m_mat[8] << " , " << tmp.m_mat[9] << " , " << tmp.m_mat[10] << " , " << tmp.m_mat[11] << " , "); + TK_INFO(" " << tmp.m_mat[12] << " , " << tmp.m_mat[13] << " , " << tmp.m_mat[14] << " , " << tmp.m_mat[15] << " )"); +} diff --git a/Sources/libetk/etk/Matrix.h b/Sources/libetk/etk/Matrix.h new file mode 100644 index 00000000..8dda2a0d --- /dev/null +++ b/Sources/libetk/etk/Matrix.h @@ -0,0 +1,199 @@ +/** + ******************************************************************************* + * @file etk/Matix.h + * @brief Ewol Tool Kit : generique Matrix type (header) + * @author Edouard DUPIN + * @date 29/08/2012 + * @par Project + * Ewol TK + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#ifndef __ETK_TYPES_MATRIX_H__ +#define __ETK_TYPES_MATRIX_H__ + +namespace etk { + + class Matrix + { + public: + float m_mat[4*4]; + void Identity(void) { + for(int32_t iii=0; iii<4*4 ; iii++) { + m_mat[iii] = 0; + } + m_mat[0] = 1.0; + m_mat[5] = 1.0; + m_mat[10] = 1.0; + m_mat[15] = 1.0; + } + /***************************************************** + * Constructor + *****************************************************/ + Matrix(void) { + Identity(); + } + Matrix(const Matrix& obj) { + for(int32_t iii=0; iii<4*4 ; iii++) { + m_mat[iii] = obj.m_mat[iii]; + } + } + Matrix(float a1, float b1, float c1, float d1, + float a2, float b2, float c2, float d2, + float a3, float b3, float c3, float d3, + float a4, float b4, float c4, float d4) { + m_mat[0] = a1; + m_mat[1] = b1; + m_mat[2] = c1; + m_mat[3] = d1; + m_mat[4] = a2; + m_mat[5] = b2; + m_mat[6] = c2; + m_mat[7] = d2; + m_mat[8] = a3; + m_mat[9] = b3; + m_mat[10] = c3; + m_mat[11] = d3; + m_mat[12] = a4; + m_mat[13] = b4; + m_mat[14] = c4; + m_mat[15] = d4; + } + Matrix(float * obj) { + if (NULL == obj) { + Identity(); + return; + } + for(int32_t iii=0; iii<4*4 ; iii++) { + m_mat[iii] = obj[iii]; + } + } + /***************************************************** + * Destructor + *****************************************************/ + ~Matrix() { + + } + /***************************************************** + * = assigment + *****************************************************/ + const Matrix& operator= (const Matrix& obj ) { + for(int32_t iii=0; iii<4*4 ; iii++) { + m_mat[iii] = obj.m_mat[iii]; + } + return *this; + } + /***************************************************** + * == operator + *****************************************************/ + bool operator== (const Matrix& obj) const { + for(int32_t iii=0; iii<4*4 ; iii++) { + if(m_mat[iii] != obj.m_mat[iii]) { + return false; + } + } + return true; + } + /***************************************************** + * != operator + *****************************************************/ + bool operator!= (const Matrix& obj) const { + for(int32_t iii=0; iii<4*4 ; iii++) { + if(m_mat[iii] != obj.m_mat[iii]) { + return true; + } + } + return false; + } + /***************************************************** + * += operator + *****************************************************/ + const Matrix& operator+= (const Matrix& obj) { + for(int32_t iii=0; iii<4*4 ; iii++) { + m_mat[iii] += obj.m_mat[iii]; + } + return *this; + } + /***************************************************** + * + operator + *****************************************************/ + Matrix operator+ (const Matrix& obj) { + Matrix tmpp(*this); + tmpp += obj; + return tmpp; + } + /***************************************************** + * -= operator + *****************************************************/ + const Matrix& operator-= (const Matrix& obj) { + for(int32_t iii=0; iii<4*4 ; iii++) { + m_mat[iii] -= obj.m_mat[iii]; + } + return *this; + } + /***************************************************** + * - operator + *****************************************************/ + Matrix operator- (const Matrix& obj) { + Matrix tmpp(*this); + tmpp += obj; + return tmpp; + } + /***************************************************** + * *= operator + *****************************************************/ + const Matrix& operator*= (const Matrix& obj) { + // output Matrix + float matrixOut[4*4]; + for(int32_t jjj=0; jjj<4 ; jjj++) { + float* tmpLeft = m_mat + jjj*4; + for(int32_t iii=0; iii<4 ; iii++) { + const float* tmpUpper = obj.m_mat+iii; + float* tmpLeft2 = tmpLeft; + float tmpElement = 0; + for(int32_t kkk=0; kkk<4 ; kkk++) { + tmpElement += *tmpUpper * *tmpLeft2; + tmpUpper += 4; + tmpLeft2++; + } + matrixOut[jjj*4+iii] = tmpElement; + } + } + // set it at the output + for(int32_t iii=0; iii<4*4 ; iii++) { + m_mat[iii] = matrixOut[iii]; + } + return *this; + } + /***************************************************** + * * operator + *****************************************************/ + Matrix operator* (const Matrix& obj) { + Matrix tmpp(*this); + tmpp *= obj; + return tmpp; + } + }; + namespace matrix { + Matrix Perspective(float left, float right, float bottom, float top, float nearVal, float farVal); + Matrix Translate(float x=0.0, float y=0.0, float z=0.0); + Matrix Scale(float x=1.0, float y=1.0, float z=1.0); + Matrix rotate(float x, float y, float z, float angleRad=0.0); + void Display(Matrix& tmp); + }; +}; + +#endif diff --git a/Sources/libetk/etk/TypesCoordonate.h b/Sources/libetk/etk/TypesCoordonate.h index 5bf2a540..58194322 100644 --- a/Sources/libetk/etk/TypesCoordonate.h +++ b/Sources/libetk/etk/TypesCoordonate.h @@ -101,7 +101,7 @@ template class Vector2D Vector2D tmpp(x,y); tmpp.x -= (T)obj.x; tmpp.y -= (T)obj.y; - return *this; + return tmpp; } /***************************************************** * /= operator @@ -118,7 +118,7 @@ template class Vector2D Vector2D tmpp(x,y); tmpp.x /= (T)obj.x; tmpp.y /= (T)obj.y; - return *this; + return tmpp; } /***************************************************** * *= operator @@ -135,7 +135,7 @@ template class Vector2D Vector2D tmpp(x,y); tmpp.x *= (T)obj.x; tmpp.y *= (T)obj.y; - return *this; + return tmpp; } /***************************************************** * ++ operator diff --git a/Sources/libetk/file.mk b/Sources/libetk/file.mk index ffa9be8b..ad4aeea6 100644 --- a/Sources/libetk/file.mk +++ b/Sources/libetk/file.mk @@ -10,7 +10,8 @@ FILE_LIST = \ etk/Stream.cpp \ etk/File.cpp \ etk/RegExp.cpp \ - etk/tool.cpp + etk/tool.cpp \ + etk/Matrix.cpp ifeq ("$(TARGET_OS)","Windows") FILE_LIST += etk/Mutex.Windows.cpp diff --git a/Sources/libewol/Linux.mk b/Sources/libewol/Linux.mk index cc2388ea..60688aca 100644 --- a/Sources/libewol/Linux.mk +++ b/Sources/libewol/Linux.mk @@ -26,12 +26,11 @@ LOCAL_EXPORT_LDLIBS := -lGL -lX11 LOCAL_CFLAGS := -Wno-write-strings \ -DEWOL_VERSION_TAG_NAME="\"$(LOCAL_VERSION_TAG_SHORT)-$(BUILD_DIRECTORY_MODE)\"" \ -DLUA_COMPAT_ALL \ - -D__VIDEO__OPENGL_ES_2 \ -Wall -#LOCAL_CFLAGS += -D__VIDEO__OPENGL_ES_2 -#LOCAL_EXPORT_CFLAGS := -D__VIDEO__OPENGL_ES_2 +LOCAL_CFLAGS += -D__VIDEO__OPENGL_ES_2 +LOCAL_EXPORT_CFLAGS := -D__VIDEO__OPENGL_ES_2 # load the common sources file of the platform diff --git a/Sources/libewol/ewol/ResourceManager.cpp b/Sources/libewol/ewol/ResourceManager.cpp index 1bac7c78..e4cee604 100644 --- a/Sources/libewol/ewol/ResourceManager.cpp +++ b/Sources/libewol/ewol/ResourceManager.cpp @@ -196,41 +196,43 @@ bool ewol::resource::Keep(etk::UString& filename, ewol::Font*& object) return true; } - -bool ewol::resource::Keep(etk::UString& filename, ewol::Program*& object) -{ - EWOL_VERBOSE("KEEP : Program : file : \"" << filename << "\""); - object = static_cast(LocalKeep(filename)); - if (NULL != object) { +#ifdef __VIDEO__OPENGL_ES_2 + bool ewol::resource::Keep(etk::UString& filename, ewol::Program*& object) + { + EWOL_VERBOSE("KEEP : Program : file : \"" << filename << "\""); + object = static_cast(LocalKeep(filename)); + if (NULL != object) { + return true; + } + // need to crate a new one ... + object = new ewol::Program(filename); + if (NULL == object) { + EWOL_ERROR("allocation error of a resource : " << filename); + return false; + } + LocalAdd(object); return true; } - // need to crate a new one ... - object = new ewol::Program(filename); - if (NULL == object) { - EWOL_ERROR("allocation error of a resource : " << filename); - return false; - } - LocalAdd(object); - return true; -} +#endif - -bool ewol::resource::Keep(etk::UString& filename, ewol::Shader*& object) -{ - EWOL_VERBOSE("KEEP : Shader : file : \"" << filename << "\""); - object = static_cast(LocalKeep(filename)); - if (NULL != object) { +#ifdef __VIDEO__OPENGL_ES_2 + bool ewol::resource::Keep(etk::UString& filename, ewol::Shader*& object) + { + EWOL_VERBOSE("KEEP : Shader : file : \"" << filename << "\""); + object = static_cast(LocalKeep(filename)); + if (NULL != object) { + return true; + } + // need to crate a new one ... + object = new ewol::Shader(filename); + if (NULL == object) { + EWOL_ERROR("allocation error of a resource : " << filename); + return false; + } + LocalAdd(object); return true; } - // need to crate a new one ... - object = new ewol::Shader(filename); - if (NULL == object) { - EWOL_ERROR("allocation error of a resource : " << filename); - return false; - } - LocalAdd(object); - return true; -} +#endif bool ewol::resource::Keep(ewol::Texture*& object) { @@ -315,18 +317,22 @@ void ewol::resource::Release(ewol::Font*& object) Release(object2); object = NULL; } -void ewol::resource::Release(ewol::Program*& object) -{ - ewol::Resource* object2 = static_cast(object); - Release(object2); - object = NULL; -} -void ewol::resource::Release(ewol::Shader*& object) -{ - ewol::Resource* object2 = static_cast(object); - Release(object2); - object = NULL; -} +#ifdef __VIDEO__OPENGL_ES_2 + void ewol::resource::Release(ewol::Program*& object) + { + ewol::Resource* object2 = static_cast(object); + Release(object2); + object = NULL; + } +#endif +#ifdef __VIDEO__OPENGL_ES_2 + void ewol::resource::Release(ewol::Shader*& object) + { + ewol::Resource* object2 = static_cast(object); + Release(object2); + object = NULL; + } +#endif void ewol::resource::Release(ewol::Texture*& object) { ewol::Resource* object2 = static_cast(object); diff --git a/Sources/libewol/ewol/ResourceManager.h b/Sources/libewol/ewol/ResourceManager.h index d26d9777..11297474 100644 --- a/Sources/libewol/ewol/ResourceManager.h +++ b/Sources/libewol/ewol/ResourceManager.h @@ -50,16 +50,20 @@ namespace ewol // return the type of the resource ... bool Keep(etk::UString& filename, ewol::TexturedFont*& object); bool Keep(etk::UString& filename, ewol::Font*& object); - bool Keep(etk::UString& filename, ewol::Program*& object); - bool Keep(etk::UString& filename, ewol::Shader*& object); + #ifdef __VIDEO__OPENGL_ES_2 + bool Keep(etk::UString& filename, ewol::Program*& object); + bool Keep(etk::UString& filename, ewol::Shader*& object); + #endif bool Keep(ewol::Texture*& object); // no name needed here ... bool Keep(etk::UString& filename, ewol::TextureFile*& object, Vector2D size); void Release(ewol::Resource*& object); void Release(ewol::TexturedFont*& object); void Release(ewol::Font*& object); - void Release(ewol::Program*& object); - void Release(ewol::Shader*& object); + #ifdef __VIDEO__OPENGL_ES_2 + void Release(ewol::Program*& object); + void Release(ewol::Shader*& object); + #endif void Release(ewol::Texture*& object); void Release(ewol::TextureFile*& object); } diff --git a/Sources/libewol/ewol/oObject/2DColored.cpp b/Sources/libewol/ewol/oObject/2DColored.cpp index 096a99d8..589907a5 100644 --- a/Sources/libewol/ewol/oObject/2DColored.cpp +++ b/Sources/libewol/ewol/oObject/2DColored.cpp @@ -36,13 +36,13 @@ ewol::OObject2DColored::OObject2DColored(void) m_triElement = 0; SetColor(1.0, 1.0, 1.0, 1.0); #ifdef __VIDEO__OPENGL_ES_2 - etk::UString tmpString("color.prog"); - // get the shader resource : + etk::UString tmpString("color.prog"); + // get the shader resource : m_GLPosition = 0; if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) { m_GLPosition = m_GLprogram->GetAttribute("EW_coord2d"); m_GLColor = m_GLprogram->GetAttribute("EW_color"); - //m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation"); + m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation"); } #endif } @@ -52,7 +52,9 @@ ewol::OObject2DColored::~OObject2DColored(void) { m_coord.Clear(); m_coordColor.Clear(); - ewol::resource::Release(m_GLprogram); + #ifdef __VIDEO__OPENGL_ES_2 + ewol::resource::Release(m_GLprogram); + #endif } @@ -61,30 +63,21 @@ void ewol::OObject2DColored::Draw(void) if (m_coord.Size()<=0) { return; } - if (m_GLprogram==NULL) { - EWOL_ERROR("No shader ..."); - return; - } #ifdef __VIDEO__OPENGL_ES_2 + if (m_GLprogram==NULL) { + EWOL_ERROR("No shader ..."); + return; + } glPushMatrix(); glScalef(m_scaling.x, m_scaling.y, 1.0); m_GLprogram->Use(); + // set Matrix : translation/positionMatrix + etk::Matrix tmpMatrix = ewol::openGL::GetMatrix(); + m_GLprogram->SendUniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); // position : - glVertexAttribPointer(m_GLPosition, // attribute ID of OpenGL - 2, // number of elements per vertex, here (x,y) - GL_FLOAT, // the type of each element - GL_FALSE, // take our values as-is - 0, // no extra data between each position - &m_coord[0]); // Pointer on the buffer - glEnableVertexAttribArray(m_GLPosition); + m_GLprogram->SendAttribute(m_GLPosition, 2/*x,y*/, &m_coord[0]); // color : - glVertexAttribPointer(m_GLColor, // attribute ID of OpenGL - 4, // number of elements per vertex, here (r,g,b,a) - GL_FLOAT, // the type of each element - GL_FALSE, // take our values as-is - 0, // no extra data between each position - &m_coordColor[0]); // Pointer on the buffer - glEnableVertexAttribArray(m_GLColor); + m_GLprogram->SendAttribute(m_GLColor, 4/*r,g,b,a*/, &m_coordColor[0]); // Request the draw od the elements : glDrawArrays(GL_TRIANGLES, 0, m_coord.Size()); m_GLprogram->UnUse(); @@ -99,8 +92,7 @@ void ewol::OObject2DColored::Draw(void) // Set the vertex pointer to our vertex data glVertexPointer(2, GL_FLOAT, 0, &m_coord[0] ); - //glColorPointer(4, oglTypeFloat_t, 0, &m_coordColor[0] ); - glColorPointer(4, GL_FLOAT, 0, &m_coordColor[0] ); + glColorPointer(4, GL_UNSIGNED_BYTE, 0, &m_coordColor[0] ); // Render : draw all of the triangles at once glDrawArrays( GL_TRIANGLES, 0, m_coord.Size()); //glDrawElements( GL_TRIANGLES, 0, m_coord.Size()); diff --git a/Sources/libewol/ewol/oObject/2DColored.h b/Sources/libewol/ewol/oObject/2DColored.h index 333852cd..42b9ecfb 100644 --- a/Sources/libewol/ewol/oObject/2DColored.h +++ b/Sources/libewol/ewol/oObject/2DColored.h @@ -39,9 +39,9 @@ namespace ewol { protected: #ifdef __VIDEO__OPENGL_ES_2 ewol::Program* m_GLprogram; - GLint m_GLPosition; - GLint m_GLMatrix; - GLint m_GLColor; + int32_t m_GLPosition; + int32_t m_GLMatrix; + int32_t m_GLColor; #endif etk::Vector > m_coord; //!< internal coord of the object #ifdef __VIDEO__OPENGL_ES_2 diff --git a/Sources/libewol/ewol/oObject/2DTextColored.cpp b/Sources/libewol/ewol/oObject/2DTextColored.cpp index 560b5c0d..9b42f17f 100644 --- a/Sources/libewol/ewol/oObject/2DTextColored.cpp +++ b/Sources/libewol/ewol/oObject/2DTextColored.cpp @@ -80,7 +80,7 @@ ewol::OObject2DTextColored::OObject2DTextColored(etk::UString fontName, int32_t m_GLPosition = m_GLprogram->GetAttribute("EW_coord2d"); m_GLColor = m_GLprogram->GetAttribute("EW_color"); m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d"); - //m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation"); + m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation"); m_GLtexID = m_GLprogram->GetUniform("EW_texID"); } #endif @@ -101,7 +101,7 @@ ewol::OObject2DTextColored::OObject2DTextColored(void) : m_GLPosition = m_GLprogram->GetAttribute("EW_coord2d"); m_GLColor = m_GLprogram->GetAttribute("EW_color"); m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d"); - //m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation"); + m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation"); m_GLtexID = m_GLprogram->GetUniform("EW_texID"); } #endif @@ -137,39 +137,19 @@ void ewol::OObject2DTextColored::Draw(void) } glColor4f(1.0, 1.0, 1.0, 1.0); m_GLprogram->Use(); - glEnable(GL_TEXTURE_2D); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, m_font->GetId()); + // set Matrix : translation/positionMatrix + etk::Matrix tmpMatrix = ewol::openGL::GetMatrix(); + m_GLprogram->SendUniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); // TextureID - glUniform1i(m_GLtexID, /*GL_TEXTURE*/0); + m_GLprogram->SetTexture0(m_GLtexID, m_font->GetId()); // position : - glVertexAttribPointer(m_GLPosition, // attribute ID of OpenGL - 2, // number of elements per vertex, here (x,y) - GL_FLOAT, // the type of each element - GL_FALSE, // take our values as-is - 0, // no extra data between each position - &m_coord[0]); // Pointer on the buffer - glEnableVertexAttribArray(m_GLPosition); + m_GLprogram->SendAttribute(m_GLPosition, 2/*x,y*/, &m_coord[0]); // Texture : - glVertexAttribPointer(m_GLtexture, // attribute ID of OpenGL - 2, // number of elements per vertex, here (u,v) - GL_FLOAT, // the type of each element - GL_FALSE, // take our values as-is - 0, // no extra data between each position - &m_coordTex[0]); // Pointer on the buffer - glEnableVertexAttribArray(m_GLtexture); + m_GLprogram->SendAttribute(m_GLtexture, 2/*u,v*/, &m_coordTex[0]); // color : - glVertexAttribPointer(m_GLColor, // attribute ID of OpenGL - 4, // number of elements per vertex, here (r,g,b,a) - GL_FLOAT, // the type of each element - GL_FALSE, // take our values as-is - 0, // no extra data between each position - &m_coordColor[0]); // Pointer on the buffer - glEnableVertexAttribArray(m_GLColor); - + m_GLprogram->SendAttribute(m_GLColor, 4/*r,g,b,a*/, &m_coordColor[0]); // Request the draw od the elements : glDrawArrays(GL_TRIANGLES, 0, m_coord.Size()); - glDisable(GL_TEXTURE_2D); m_GLprogram->UnUse(); #else glEnable(GL_TEXTURE_2D); diff --git a/Sources/libewol/ewol/oObject/2DTextColored.h b/Sources/libewol/ewol/oObject/2DTextColored.h index 60f843aa..4e7607ab 100644 --- a/Sources/libewol/ewol/oObject/2DTextColored.h +++ b/Sources/libewol/ewol/oObject/2DTextColored.h @@ -47,11 +47,11 @@ namespace ewol { protected: #ifdef __VIDEO__OPENGL_ES_2 ewol::Program* m_GLprogram; - GLint m_GLPosition; - GLint m_GLMatrix; - GLint m_GLColor; - GLint m_GLtexture; - GLint m_GLtexID; + int32_t m_GLPosition; + int32_t m_GLMatrix; + int32_t m_GLColor; + int32_t m_GLtexture; + int32_t m_GLtexID; #endif ewol::TexturedFont* m_font; //!< ewol font system draw::Color m_color; //!< tmp text color ... diff --git a/Sources/libewol/ewol/oObject/2DTextured.cpp b/Sources/libewol/ewol/oObject/2DTextured.cpp index 951ca65a..dfb24a83 100644 --- a/Sources/libewol/ewol/oObject/2DTextured.cpp +++ b/Sources/libewol/ewol/oObject/2DTextured.cpp @@ -44,7 +44,7 @@ ewol::OObject2DTextured::OObject2DTextured(etk::UString textureName, float sizeX m_GLPosition = m_GLprogram->GetAttribute("EW_coord2d"); m_GLColor = m_GLprogram->GetAttribute("EW_color"); m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d"); - //m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation"); + m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation"); m_GLtexID = m_GLprogram->GetUniform("EW_texID"); } #endif @@ -77,39 +77,19 @@ void ewol::OObject2DTextured::Draw(void) } glColor4f(1.0, 1.0, 1.0, 1.0); m_GLprogram->Use(); - glEnable(GL_TEXTURE_2D); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, m_resource->GetId()); + // set Matrix : translation/positionMatrix + etk::Matrix tmpMatrix = ewol::openGL::GetMatrix(); + m_GLprogram->SendUniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); // TextureID - glUniform1i(m_GLtexID, /*GL_TEXTURE*/0); + m_GLprogram->SetTexture0(m_GLtexID, m_resource->GetId()); // position : - glVertexAttribPointer(m_GLPosition, // attribute ID of OpenGL - 2, // number of elements per vertex, here (x,y) - GL_FLOAT, // the type of each element - GL_FALSE, // take our values as-is - 0, // no extra data between each position - &m_coord[0]); // Pointer on the buffer - glEnableVertexAttribArray(m_GLPosition); + m_GLprogram->SendAttribute(m_GLPosition, 2/*x,y*/, &m_coord[0]); // Texture : - glVertexAttribPointer(m_GLtexture, // attribute ID of OpenGL - 2, // number of elements per vertex, here (u,v) - GL_FLOAT, // the type of each element - GL_FALSE, // take our values as-is - 0, // no extra data between each position - &m_coordTex[0]); // Pointer on the buffer - glEnableVertexAttribArray(m_GLtexture); + m_GLprogram->SendAttribute(m_GLtexture, 2/*u,v*/, &m_coordTex[0]); // color : - glVertexAttribPointer(m_GLColor, // attribute ID of OpenGL - 4, // number of elements per vertex, here (r,g,b,a) - GL_FLOAT, // the type of each element - GL_FALSE, // take our values as-is - 0, // no extra data between each position - &m_coordColor[0]); // Pointer on the buffer - glEnableVertexAttribArray(m_GLColor); - + m_GLprogram->SendAttribute(m_GLColor, 4/*r,g,b,a*/, &m_coordColor[0]); // Request the draw od the elements : glDrawArrays(GL_TRIANGLES, 0, m_coord.Size()); - glDisable(GL_TEXTURE_2D); m_GLprogram->UnUse(); #else glColor4f(1.0, 1.0, 1.0, 1.0); diff --git a/Sources/libewol/ewol/oObject/2DTextured.h b/Sources/libewol/ewol/oObject/2DTextured.h index b529a2c6..d0ea18d6 100644 --- a/Sources/libewol/ewol/oObject/2DTextured.h +++ b/Sources/libewol/ewol/oObject/2DTextured.h @@ -42,11 +42,11 @@ namespace ewol { protected: #ifdef __VIDEO__OPENGL_ES_2 ewol::Program* m_GLprogram; - GLint m_GLPosition; - GLint m_GLMatrix; - GLint m_GLColor; - GLint m_GLtexture; - GLint m_GLtexID; + int32_t m_GLPosition; + int32_t m_GLMatrix; + int32_t m_GLColor; + int32_t m_GLtexture; + int32_t m_GLtexID; #endif ewol::TextureFile* m_resource; //!< texture resources etk::Vector > m_coord; //!< internal coord of the object diff --git a/Sources/libewol/ewol/oObject/3DTextured.cpp b/Sources/libewol/ewol/oObject/3DTextured.cpp index 8d3da04d..fcea52a4 100644 --- a/Sources/libewol/ewol/oObject/3DTextured.cpp +++ b/Sources/libewol/ewol/oObject/3DTextured.cpp @@ -44,7 +44,7 @@ ewol::OObject3DTextured::OObject3DTextured(etk::UString textureName, float sizeX m_GLPosition = m_GLprogram->GetAttribute("EW_coord3d"); m_GLColor = m_GLprogram->GetAttribute("EW_color"); m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d"); - //m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation"); + m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation"); m_GLtexID = m_GLprogram->GetUniform("EW_texID"); } #endif @@ -77,39 +77,19 @@ void ewol::OObject3DTextured::Draw(void) } glColor4f(1.0, 1.0, 1.0, 1.0); m_GLprogram->Use(); - glEnable(GL_TEXTURE_2D); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, m_resource->GetId()); + // set Matrix : translation/positionMatrix + etk::Matrix tmpMatrix = ewol::openGL::GetMatrix(); + m_GLprogram->SendUniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); // TextureID - glUniform1i(m_GLtexID, /*GL_TEXTURE*/0); + m_GLprogram->SetTexture0(m_GLtexID, m_resource->GetId()); // position : - glVertexAttribPointer(m_GLPosition, // attribute ID of OpenGL - 3, // number of elements per vertex, here (x,y) - GL_FLOAT, // the type of each element - GL_FALSE, // take our values as-is - 0, // no extra data between each position - &m_coord[0]); // Pointer on the buffer - glEnableVertexAttribArray(m_GLPosition); + m_GLprogram->SendAttribute(m_GLPosition, 3/*x,y,z*/, &m_coord[0]); // Texture : - glVertexAttribPointer(m_GLtexture, // attribute ID of OpenGL - 2, // number of elements per vertex, here (u,v) - GL_FLOAT, // the type of each element - GL_FALSE, // take our values as-is - 0, // no extra data between each position - &m_coordTex[0]); // Pointer on the buffer - glEnableVertexAttribArray(m_GLtexture); + m_GLprogram->SendAttribute(m_GLtexture, 2/*u,v*/, &m_coordTex[0]); // color : - glVertexAttribPointer(m_GLColor, // attribute ID of OpenGL - 4, // number of elements per vertex, here (r,g,b,a) - GL_FLOAT, // the type of each element - GL_FALSE, // take our values as-is - 0, // no extra data between each position - &m_coordColor[0]); // Pointer on the buffer - glEnableVertexAttribArray(m_GLColor); - + m_GLprogram->SendAttribute(m_GLColor, 4/*r,g,b,a*/, &m_coordColor[0]); // Request the draw od the elements : glDrawArrays(GL_TRIANGLES, 0, m_coord.Size()); - glDisable(GL_TEXTURE_2D); m_GLprogram->UnUse(); #else glColor4f(1.0, 1.0, 1.0, 1.0); diff --git a/Sources/libewol/ewol/oObject/3DTextured.h b/Sources/libewol/ewol/oObject/3DTextured.h index 572d45ef..0a324e33 100644 --- a/Sources/libewol/ewol/oObject/3DTextured.h +++ b/Sources/libewol/ewol/oObject/3DTextured.h @@ -42,11 +42,11 @@ namespace ewol { protected: #ifdef __VIDEO__OPENGL_ES_2 ewol::Program* m_GLprogram; - GLint m_GLPosition; - GLint m_GLMatrix; - GLint m_GLColor; - GLint m_GLtexture; - GLint m_GLtexID; + int32_t m_GLPosition; + int32_t m_GLMatrix; + int32_t m_GLColor; + int32_t m_GLtexture; + int32_t m_GLtexID; #endif ewol::TextureFile* m_resource; //!< texture resources etk::Vector > m_coord; //!< internal coord of the object diff --git a/Sources/libewol/ewol/openGL/Program.cpp b/Sources/libewol/ewol/openGL/Program.cpp index 48e59dc3..239603d3 100644 --- a/Sources/libewol/ewol/openGL/Program.cpp +++ b/Sources/libewol/ewol/openGL/Program.cpp @@ -22,6 +22,8 @@ ******************************************************************************* */ +#ifdef __VIDEO__OPENGL_ES_2 + #include #include #include @@ -29,7 +31,8 @@ ewol::Program::Program(etk::UString& filename) : ewol::Resource(filename), - m_program(0) + m_program(0), + m_hasTexture(false) { // load data from file "all the time ..." @@ -89,6 +92,8 @@ ewol::Program::~Program(void) glDeleteProgram(m_program); m_program = 0; } + m_elementList.Clear(); + m_hasTexture = false; } static void checkGlError(const char* op) @@ -131,55 +136,104 @@ bool ewol::Program::CreateAndLink(void) return true; } -// TODO : Set it dynamic to prevent reload system error ... -GLint ewol::Program::GetAttribute(etk::UString& tmpElement) +int32_t ewol::Program::GetAttribute(etk::UString tmpElement) { - GLint elem = glGetAttribLocation(m_program, tmpElement.c_str()); - if (elem<0) { + // check if it exist previously : + for(int32_t iii=0; iiim_elementList.Size()) { + EWOL_ERROR("idElem = " << idElem << " not in [0.." << (m_elementList.Size()-1) << "]"); + return; + } + glUniformMatrix4fv(m_elementList[idElem].m_elementId, nbElement, GL_TRUE, pointer); +} + + void ewol::Program::Use(void) { glUseProgram(m_program); checkGlError("glUseProgram"); } + +void ewol::Program::SetTexture0(int32_t idElem, GLint textureOpenGlID) +{ + if (idElem<0 || idElem>m_elementList.Size()) { + return; + } + glEnable(GL_TEXTURE_2D); + glActiveTexture(GL_TEXTURE0); + // set the textureID + glBindTexture(GL_TEXTURE_2D, textureOpenGlID); + // Set the texture on the uniform attribute + glUniform1i(m_elementList[idElem].m_elementId, /*GL_TEXTURE*/0); + m_hasTexture = true; +} + void ewol::Program::UnUse(void) { + if (true == m_hasTexture) { + glDisable(GL_TEXTURE_2D); + m_hasTexture = false; + } glUseProgram(0); checkGlError("glUseProgram"); -} \ No newline at end of file +} + + +#endif diff --git a/Sources/libewol/ewol/openGL/Program.h b/Sources/libewol/ewol/openGL/Program.h index b7cae570..d213fa49 100644 --- a/Sources/libewol/ewol/openGL/Program.h +++ b/Sources/libewol/ewol/openGL/Program.h @@ -24,35 +24,44 @@ #ifndef __OPEN_GL__PROGRAM_H__ #define __OPEN_GL__PROGRAM_H__ - -#include -#include -#include -#include -#include - -namespace ewol -{ - class Program : public ewol::Resource - { - private : - GLuint m_program; - etk::Vector m_shaderList; - public: - Program(etk::UString& filename); - virtual ~Program(void); - const char* GetType(void) { return "ewol::Program"; }; - GLuint GetGL_ID(void) { return m_program; }; - bool CreateAndLink(void); - GLint GetAttribute(etk::UString& tmpElement); - GLint GetAttribute(const char* tmpElement); - GLint GetUniform(etk::UString& tmpElement); - GLint GetUniform(const char* tmpElement); - void Use(void); - void UnUse(void); - }; -}; - - + #ifdef __VIDEO__OPENGL_ES_2 + #include + #include + #include + #include + #include + + namespace ewol + { + class progAttributeElement + { + public : + etk::UString m_name; + GLint m_elementId; + bool m_isAttribute; + }; + + class Program : public ewol::Resource + { + private : + GLuint m_program; + etk::Vector m_shaderList; + etk::Vector m_elementList; + bool m_hasTexture; + public: + Program(etk::UString& filename); + virtual ~Program(void); + const char* GetType(void) { return "ewol::Program"; }; + bool CreateAndLink(void); + int32_t GetAttribute(etk::UString tmpElement); + void SendAttribute(int32_t idElem, int32_t nbElement, void* pointer, int32_t jumpBetweenSample=0); + int32_t GetUniform(etk::UString tmpElement); + void SendUniformMatrix4fv(int32_t idElem, int32_t nbElement, float* pointer); + void Use(void); + void SetTexture0(int32_t idElem, GLint textureOpenGlID); + void UnUse(void); + }; + }; + #endif #endif diff --git a/Sources/libewol/ewol/openGL/Shader.cpp b/Sources/libewol/ewol/openGL/Shader.cpp index 598d2b3c..14382d28 100644 --- a/Sources/libewol/ewol/openGL/Shader.cpp +++ b/Sources/libewol/ewol/openGL/Shader.cpp @@ -22,6 +22,8 @@ ******************************************************************************* */ +#ifdef __VIDEO__OPENGL_ES_2 + #include #include #include @@ -132,3 +134,5 @@ bool ewol::Shader::CompileAndSendShader(void) return true; } +#endif + diff --git a/Sources/libewol/ewol/openGL/Shader.h b/Sources/libewol/ewol/openGL/Shader.h index 3b7c76a0..1b22dd6e 100644 --- a/Sources/libewol/ewol/openGL/Shader.h +++ b/Sources/libewol/ewol/openGL/Shader.h @@ -24,30 +24,29 @@ #ifndef __OPEN_GL__SHADER_H__ #define __OPEN_GL__SHADER_H__ - -#include -#include -#include -#include - -namespace ewol -{ - class Shader : public ewol::Resource - { - private : - char* m_fileData; - GLuint m_shader; - GLenum m_type; - public: - Shader(etk::UString& filename); - virtual ~Shader(void); - const char* GetType(void) { return "ewol::Shader"; }; - GLuint GetGL_ID(void) { return m_shader; }; - GLenum GetShaderType(void) { return m_type; }; - bool CompileAndSendShader(void); - }; -}; - - + #ifdef __VIDEO__OPENGL_ES_2 + #include + #include + #include + #include + + namespace ewol + { + class Shader : public ewol::Resource + { + private : + char* m_fileData; + GLuint m_shader; + GLenum m_type; + public: + Shader(etk::UString& filename); + virtual ~Shader(void); + const char* GetType(void) { return "ewol::Shader"; }; + GLuint GetGL_ID(void) { return m_shader; }; + GLenum GetShaderType(void) { return m_type; }; + bool CompileAndSendShader(void); + }; + }; + #endif #endif diff --git a/Sources/libewol/ewol/openGL/openGL.cpp b/Sources/libewol/ewol/openGL/openGL.cpp index e0462ee7..0951a313 100644 --- a/Sources/libewol/ewol/openGL/openGL.cpp +++ b/Sources/libewol/ewol/openGL/openGL.cpp @@ -24,6 +24,7 @@ #include #include +#include void glOrthoMatrix(GLfloat left, @@ -67,107 +68,72 @@ void glOrthoEwol(GLfloat left, } -ewol::OglMatrix::OglMatrix(float left, float right, float bottom, float top, float nearVal, float farVal) +etk::Vector l_matrixList; + +void ewol::openGL::Init(void) { - Generate(left, right, bottom, top, nearVal, farVal); + // remove deprecated pb ... + l_matrixList.Clear(); + etk::Matrix tmpMat; + l_matrixList.PushBack(tmpMat); } -void ewol::OglMatrix::Generate(float left, float right, float bottom, float top, float nearVal, float farVal) + +void ewol::openGL::UnInit(void) { - int iii; - for(iii=0; iii<4*4 ; iii++) { - m_Matrix[iii] = 0; - } - m_Matrix[0] = 2.0 / (right - left); - m_Matrix[5] = 2.0 / (top - bottom); - m_Matrix[10] = -2.0 / (farVal - nearVal); - m_Matrix[3] = -1*(right + left) / (right - left); - m_Matrix[7] = -1*(top + bottom) / (top - bottom); - m_Matrix[11] = -1*(farVal + nearVal) / (farVal - nearVal); - m_Matrix[15] = 1; + l_matrixList.Clear(); } -ewol::OglMatrix::~OglMatrix() +void ewol::openGL::SetBasicMatrix(etk::Matrix& newOne) { - -} -//http://www.siteduzero.com/tutoriel-3-5003-les-matrices.html -static void MultiplyMatrix(float* inOut, float* mult) -{ - - // output Matrix - float matrixOut[4*4]; - for(int32_t jjj=0; jjj<4 ; jjj++) { - float* tmpLeft = inOut + jjj*4; - for(int32_t iii=0; iii<4 ; iii++) { - float* tmpUpper = mult+iii; - float* tmpLeft2 = tmpLeft; - float tmpElement = 0; - for(int32_t kkk=0; kkk<4 ; kkk++) { - tmpElement += *tmpUpper * *tmpLeft2; - tmpUpper += 4; - tmpLeft2++; - } - matrixOut[jjj*4+iii] = tmpElement; - } - } - // set it at the output - for(int32_t iii=0; iii<4*4 ; iii++) { - inOut[iii] = matrixOut[iii]; + if (l_matrixList.Size()!=1) { + EWOL_ERROR("matrix is not corect size in the stack : " << l_matrixList.Size()); } + l_matrixList.Clear(); + l_matrixList.PushBack(newOne); } -void ewol::OglMatrix::Translate(float x, float y, float z) +void ewol::openGL::SetMatrix(etk::Matrix& newOne) { - float matrix[4*4]; - for(int32_t iii=0; iii<4*4 ; iii++) { - matrix[iii] = 0; + if (l_matrixList.Size()==0) { + EWOL_ERROR("set matrix list is not corect size in the stack : " << l_matrixList.Size()); + l_matrixList.PushBack(newOne); + return; } - // set identity : - matrix[0] = 1; - matrix[5] = 1; - matrix[10] = 1; - matrix[15] = 1; - // set translation : - matrix[3] = x; - matrix[7] = y; - matrix[11] = y; - // generate output : - MultiplyMatrix(m_Matrix, matrix); + l_matrixList[l_matrixList.Size()-1] = newOne; } -void ewol::OglMatrix::Scale(float x, float y, float z) +void ewol::openGL::Push(void) { - float matrix[4*4]; - for(int32_t iii=0; iii<4*4 ; iii++) { - matrix[iii] = 0; + if (l_matrixList.Size()==0) { + EWOL_ERROR("set matrix list is not corect size in the stack : " << l_matrixList.Size()); + etk::Matrix tmp; + l_matrixList.PushBack(tmp); + return; } - // set identity : - matrix[0] = 1; - matrix[5] = 1; - matrix[10] = 1; - matrix[15] = 1; - // set scale : - matrix[0] = x; - matrix[5] = y; - matrix[10] = z; - // generate output : - MultiplyMatrix(m_Matrix, matrix); + etk::Matrix tmp = l_matrixList[l_matrixList.Size()-1]; + l_matrixList.PushBack(tmp); } -void ewol::OglMatrix::rotate(float x, float y, float z, float angle) +void ewol::openGL::Pop(void) { - float matrix[4*4]; - for(int32_t iii=0; iii<4*4 ; iii++) { - matrix[iii] = 0; + if (l_matrixList.Size()<=1) { + EWOL_ERROR("set matrix list is not corect size in the stack : " << l_matrixList.Size()); + l_matrixList.Clear(); + etk::Matrix tmp; + l_matrixList.PushBack(tmp); + return; } - // set identity : - matrix[0] = 1; - matrix[5] = 1; - matrix[10] = 1; - matrix[15] = 1; - // TODO ... - // generate output : - MultiplyMatrix(m_Matrix, matrix); + l_matrixList.PopBack(); +} + +etk::Matrix& ewol::openGL::GetMatrix(void) +{ + if (l_matrixList.Size()==0) { + EWOL_ERROR("set matrix list is not corect size in the stack : " << l_matrixList.Size()); + etk::Matrix tmp; + l_matrixList.PushBack(tmp); + } + return l_matrixList[l_matrixList.Size()-1]; } diff --git a/Sources/libewol/ewol/openGL/openGL.h b/Sources/libewol/ewol/openGL/openGL.h index 27e25210..43210ac3 100644 --- a/Sources/libewol/ewol/openGL/openGL.h +++ b/Sources/libewol/ewol/openGL/openGL.h @@ -25,29 +25,38 @@ #ifndef __OPEN_GL_H__ #define __OPEN_GL_H__ +#include + #ifdef __cplusplus extern "C" { #endif -#if defined(__TARGET_OS__Linux) +#if defined(__TARGET_OS__Linux) || defined(__TARGET_OS__Windows) #ifdef __VIDEO__OPENGL_ES_2 // TO ENABLE THE SHADER api ... #define GL_GLEXT_PROTOTYPES #endif #include + #ifdef __VIDEO__OPENGL_ES_2 + // This is to prevent the use of these element that is not allowed in the OpenGL ES + #undef glVertexPointer + #undef glTexCoordPointer + #undef glColorPointer + #undef glPopMatrix + #undef glPushMatrix + #undef glMatrixMode + #undef glLoadIdentity + #undef glTranslatef + #endif #elif defined(__TARGET_OS__Android) #ifdef __VIDEO__OPENGL_ES_2 + // Include openGL ES 2 #include #include #else - + // Include openGL ES 1 + #include #endif -#elif defined(__TARGET_OS__Windows) - #ifdef __VIDEO__OPENGL_ES_2 - // TO ENABLE THE SHADER api ... - #define GL_GLEXT_PROTOTYPES - #endif - #include #elif defined(__TARGET_OS__MacOs) #elif defined(__TARGET_OS__IOs) @@ -56,18 +65,20 @@ extern "C" { #error you need to specify a __TAGET_OS__ ... #endif +// TODO : Remove : deprecated .... void glOrthoEwol(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal); namespace ewol { - class OglMatrix{ - public : - float m_Matrix[4*4]; - OglMatrix(float left, float right, float bottom, float top, float nearVal, float farVal); - ~OglMatrix(); - void Generate(float left, float right, float bottom, float top, float nearVal, float farVal); - void Translate(float x=0.0, float y=0.0, float z=0.0); - void Scale(float x=1.0, float y=1.0, float z=1.0); - void rotate(float x, float y, float z, float angle=0.0); + namespace openGL { + void Init(void); + void UnInit(void); + // reset the basic element at this one ... remove all previous + void SetBasicMatrix(etk::Matrix& newOne); + // this is the same system as openGL-ES-1 but in openGL-ES-2 (here is the abstraction) + void SetMatrix(etk::Matrix& newOne); + void Push(void); + void Pop(void); + etk::Matrix& GetMatrix(void); }; }; diff --git a/Sources/libewol/ewol/os/eSystem.cpp b/Sources/libewol/ewol/os/eSystem.cpp index 0ea30f73..f03dee61 100644 --- a/Sources/libewol/ewol/os/eSystem.cpp +++ b/Sources/libewol/ewol/os/eSystem.cpp @@ -240,6 +240,7 @@ void eSystem::Init(void) EWOL_INFO("v" EWOL_VERSION_TAG_NAME); EWOL_INFO("Build Date: " BUILD_TIME); etk::InitDefaultFolder("ewolApplNoName"); + ewol::openGL::Init(); ewol::EObjectManager::Init(); ewol::EObjectMessageMultiCast::Init(); l_managementInput.Reset(); @@ -271,6 +272,7 @@ void eSystem::UnInit(void) ewol::EObjectMessageMultiCast::UnInit(); ewol::EObjectManager::UnInit(); ewol::resource::UnInit(); + ewol::openGL::UnInit(); l_managementInput.Reset(); l_msgSystem.Clean(); } diff --git a/Sources/libewol/ewol/os/gui.X11.cpp b/Sources/libewol/ewol/os/gui.X11.cpp index 7d387253..d8756e84 100644 --- a/Sources/libewol/ewol/os/gui.X11.cpp +++ b/Sources/libewol/ewol/os/gui.X11.cpp @@ -1178,19 +1178,6 @@ int main(int argc, char *argv[]) etk::File myIcon = APP_Icon(); SetIcon(myIcon); - GLuint shader; - /* creation */ - shader = glCreateShader(GL_VERTEX_SHADER); - if(shader == 0) { - /* erreur de creation :( */ - return -1; - } - /* utilisation ... */ - /* suppression */ - glDeleteShader(shader); - shader = 0; - - // Run ... X11_Run(); // close X11 : diff --git a/Sources/libewol/ewol/widget/Widget.cpp b/Sources/libewol/ewol/widget/Widget.cpp index 527b824a..0e409f47 100644 --- a/Sources/libewol/ewol/widget/Widget.cpp +++ b/Sources/libewol/ewol/widget/Widget.cpp @@ -225,7 +225,11 @@ void ewol::Widget::GenDraw(DrawProperty displayProp) // widget is hidden ... return; } - glPushMatrix(); + #ifdef __VIDEO__OPENGL_ES_2 + ewol::openGL::Push(); + #else + glPushMatrix(); + #endif if( (displayProp.m_origin.x > m_origin.x) || (displayProp.m_origin.x + displayProp.m_size.x < m_size.x + m_origin.x) ) { // here we invert the reference of the standard OpenGl view because the reference in the common display is Top left and not buttom left @@ -243,14 +247,23 @@ void ewol::Widget::GenDraw(DrawProperty displayProp) tmpOriginY, tmpclipX, m_size.y); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrthoEwol(-tmpclipX/2, tmpclipX/2, -m_size.y/2, m_size.y/2, -1, 1); - //glOrthoEwol(0., m_size.x, 0., -m_size.y, 1., 20.); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(-tmpclipX/2 - (tmpOriginX-m_origin.x), -m_size.y/2, -1.0); + #ifdef __VIDEO__OPENGL_ES_2 + etk::Matrix tmpTranslate = etk::matrix::Translate(-tmpclipX/2 - (tmpOriginX-m_origin.x), -m_size.y/2, -1.0); + etk::Matrix tmpProjection = etk::matrix::Perspective(-tmpclipX/2, tmpclipX/2, -m_size.y/2, m_size.y/2, -1, 1); + etk::Matrix tmpMat = tmpProjection * tmpTranslate; + // set internal matrix system : + ewol::openGL::SetMatrix(tmpMat); + #else + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrthoEwol(-tmpclipX/2, tmpclipX/2, -m_size.y/2, m_size.y/2, -1, 1); + //glOrthoEwol(0., m_size.x, 0., -m_size.y, 1., 20.); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(-tmpclipX/2 - (tmpOriginX-m_origin.x), -m_size.y/2, -1.0); + #endif + glLoadIdentity(); // Call the widget drawing methode displayProp.m_origin.x = tmpOriginX; displayProp.m_origin.y = tmpOriginY; @@ -262,19 +275,35 @@ void ewol::Widget::GenDraw(DrawProperty displayProp) m_origin.y, m_size.x, m_size.y); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrthoEwol(-m_size.x/2, m_size.x/2, -m_size.y/2, m_size.y/2, -1, 1); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(-m_size.x/2, -m_size.y/2, -1.0); + #ifdef __VIDEO__OPENGL_ES_2 + #if 1 + etk::Matrix tmpTranslate = etk::matrix::Translate(-m_size.x/2, -m_size.y/2, -1.0); + etk::Matrix tmpProjection = etk::matrix::Perspective(-m_size.x/2, m_size.x/2, -m_size.y/2, m_size.y/2, -1, 1); + etk::Matrix tmpMat = tmpProjection * tmpTranslate; + #else + etk::Matrix tmpMat = etk::matrix::Perspective(0, m_size.x, 0, m_size.y, -1, 1); + #endif + // set internal matrix system : + ewol::openGL::SetMatrix(tmpMat); + #else + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrthoEwol(-m_size.x/2, m_size.x/2, -m_size.y/2, m_size.y/2, -1, 1); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(-m_size.x/2, -m_size.y/2, -1.0); + #endif // Call the widget drawing methode displayProp.m_origin = m_origin; displayProp.m_size = m_size; OnDraw(displayProp); } - glPopMatrix(); + #ifdef __VIDEO__OPENGL_ES_2 + ewol::openGL::Pop(); + #else + glPopMatrix(); + #endif return; } diff --git a/Sources/libewol/ewol/widget/Windows.cpp b/Sources/libewol/ewol/widget/Windows.cpp index a6eedcab..b88336b8 100644 --- a/Sources/libewol/ewol/widget/Windows.cpp +++ b/Sources/libewol/ewol/widget/Windows.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -124,6 +125,10 @@ void ewol::Windows::SysDraw(void) glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + // clear the matrix system : + etk::Matrix newOne; + ewol::openGL::SetBasicMatrix(newOne); + ewol::DrawProperty displayProp; displayProp.m_windowsSize = m_size; displayProp.m_origin.x = 0; diff --git a/share/basicShader.frag b/share/basicShader.frag deleted file mode 100644 index 4b00534b..00000000 --- a/share/basicShader.frag +++ /dev/null @@ -1,6 +0,0 @@ - - -void main() { - gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); -} - diff --git a/share/basicShader.prog b/share/basicShader.prog deleted file mode 100644 index 40e03d34..00000000 --- a/share/basicShader.prog +++ /dev/null @@ -1,4 +0,0 @@ -basicShader.vert -basicShader.frag - - diff --git a/share/basicShader.vert b/share/basicShader.vert deleted file mode 100644 index c545f3a9..00000000 --- a/share/basicShader.vert +++ /dev/null @@ -1,7 +0,0 @@ - -attribute vec4 vPosition; - -void main() { - gl_Position = vPosition; -} - diff --git a/share/color.vert b/share/color.vert index 37714e77..b69a5ff3 100644 --- a/share/color.vert +++ b/share/color.vert @@ -7,8 +7,7 @@ uniform mat4 EW_MatrixTransformation; varying vec4 f_color; void main(void) { - //gl_Position = EW_MatrixTransformation * vec4(EW_coord2d, 0.0, 1.0); - gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(EW_coord2d, 0.0, 1.0); - //gl_Position = vec4(EW_coord2d, 0.0, 1.0); + gl_Position = EW_MatrixTransformation * vec4(EW_coord2d, 0.0, 1.0); + //gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(EW_coord2d, 0.0, 1.0); f_color = EW_color; } diff --git a/share/textured.vert b/share/textured.vert index 9ee07bb2..94f384d3 100644 --- a/share/textured.vert +++ b/share/textured.vert @@ -9,8 +9,8 @@ varying vec4 f_color; varying vec2 f_texcoord; void main(void) { - //gl_Position = EW_MatrixTransformation * vec4(EW_coord2d, 0.0, 1.0); - gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(EW_coord2d, 0.0, 1.0); + gl_Position = EW_MatrixTransformation * vec4(EW_coord2d, 0.0, 1.0); + //gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(EW_coord2d, 0.0, 1.0); // set texture output coord f_texcoord = EW_texture2d; // set output color : diff --git a/share/textured3D.vert b/share/textured3D.vert index d4bcb61d..794ab115 100644 --- a/share/textured3D.vert +++ b/share/textured3D.vert @@ -9,8 +9,8 @@ varying vec4 f_color; varying vec2 f_texcoord; void main(void) { - //gl_Position = EW_MatrixTransformation * vec4(EW_coord2d, 0.0, 1.0); - gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(EW_coord3d, 1.0); + gl_Position = EW_MatrixTransformation * vec4(EW_coord2d, 0.0, 1.0); + //gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(EW_coord3d, 1.0); // set texture output coord f_texcoord = EW_texture2d; // set output color :