From c870d2471ee254ae075fd9d0225cafea4cae7ba9 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 13 Mar 2013 21:29:51 +0100 Subject: [PATCH] [DEV] display optimesation next step done --- sources/ewol/renderer/openGL.cpp | 129 ++++++++++++++++-- sources/ewol/renderer/openGL.h | 43 +++++- sources/ewol/renderer/os/eSystem.cpp | 4 + .../renderer/resources/Colored3DObject.cpp | 12 +- sources/ewol/renderer/resources/Mesh.cpp | 7 +- sources/ewol/renderer/resources/Program.cpp | 2 +- sources/ewol/widget/Scene.cpp | 34 ++--- sources/ewol/widget/Widget.cpp | 6 + sources/ewol/widget/Windows.cpp | 39 ++++-- 9 files changed, 220 insertions(+), 56 deletions(-) diff --git a/sources/ewol/renderer/openGL.cpp b/sources/ewol/renderer/openGL.cpp index 902502c0..29f1f211 100644 --- a/sources/ewol/renderer/openGL.cpp +++ b/sources/ewol/renderer/openGL.cpp @@ -12,7 +12,8 @@ etk::Vector l_matrixList; mat4 l_matrixCamera; -static uint32_t l_flags = 0; +static uint32_t l_flagsCurrent = 0; +static uint32_t l_flagsMustBeSet = 0; static uint32_t l_textureflags = 0; static int32_t l_programId = 0; @@ -23,7 +24,8 @@ void ewol::openGL::Init(void) mat4 tmpMat; l_matrixList.PushBack(tmpMat); l_matrixCamera.Identity(); - l_flags = 0; + l_flagsCurrent = 0; + l_flagsMustBeSet = 0; l_textureflags = 0; l_programId = -1; } @@ -118,16 +120,120 @@ void ewol::openGL::Swap(void) } -void ewol::openGL::Enable(uint32_t flagID) +//#define DIRECT_MODE + +typedef struct { + uint32_t curentFlag; + GLenum OGlFlag; +} correspondenceTable_ts; + +static correspondenceTable_ts basicFlag[] = { + {(uint32_t)ewol::openGL::FLAG_BLEND, GL_BLEND}, + #ifndef __TARGET_OS__Android + {(uint32_t)ewol::openGL::FLAG_CLIP_DISTANCE_I, GL_CLIP_DISTANCE0}, + {(uint32_t)ewol::openGL::FLAG_COLOR_LOGIC_OP, GL_COLOR_LOGIC_OP}, + #endif + {(uint32_t)ewol::openGL::FLAG_CULL_FACE, GL_CULL_FACE}, + #ifndef __TARGET_OS__Android + {(uint32_t)ewol::openGL::FLAG_DEBUG_OUTPUT, GL_DEBUG_OUTPUT}, + {(uint32_t)ewol::openGL::FLAG_DEBUG_OUTPUT_SYNCHRONOUS, GL_DEBUG_OUTPUT_SYNCHRONOUS}, + {(uint32_t)ewol::openGL::FLAG_DEPTH_CLAMP, GL_DEPTH_CLAMP}, + #endif + {(uint32_t)ewol::openGL::FLAG_DEPTH_TEST, GL_DEPTH_TEST}, + {(uint32_t)ewol::openGL::FLAG_DITHER, GL_DITHER}, + #ifndef __TARGET_OS__Android + {(uint32_t)ewol::openGL::FLAG_FRAMEBUFFER_SRGB, GL_FRAMEBUFFER_SRGB}, + {(uint32_t)ewol::openGL::FLAG_LINE_SMOOTH, GL_LINE_SMOOTH}, + {(uint32_t)ewol::openGL::FLAG_MULTISAMPLE, GL_MULTISAMPLE}, + #endif + {(uint32_t)ewol::openGL::FLAG_POLYGON_OFFSET_FILL, GL_POLYGON_OFFSET_FILL}, + #ifndef __TARGET_OS__Android + {(uint32_t)ewol::openGL::FLAG_POLYGON_OFFSET_LINE, GL_POLYGON_OFFSET_LINE}, + {(uint32_t)ewol::openGL::FLAG_POLYGON_OFFSET_POINT, GL_POLYGON_OFFSET_POINT}, + {(uint32_t)ewol::openGL::FLAG_POLYGON_SMOOTH, GL_POLYGON_SMOOTH}, + {(uint32_t)ewol::openGL::FLAG_PRIMITIVE_RESTART, GL_PRIMITIVE_RESTART}, + {(uint32_t)ewol::openGL::FLAG_PRIMITIVE_RESTART_FIXED_INDEX, GL_PRIMITIVE_RESTART_FIXED_INDEX}, + #endif + {(uint32_t)ewol::openGL::FLAG_SAMPLE_ALPHA_TO_COVERAGE, GL_SAMPLE_ALPHA_TO_COVERAGE}, + #ifndef __TARGET_OS__Android + {(uint32_t)ewol::openGL::FLAG_SAMPLE_ALPHA_TO_ONE, GL_SAMPLE_ALPHA_TO_ONE}, + #endif + {(uint32_t)ewol::openGL::FLAG_SAMPLE_COVERAGE, GL_SAMPLE_COVERAGE}, + #ifndef __TARGET_OS__Android + {(uint32_t)ewol::openGL::FLAG_SAMPLE_SHADING, GL_SAMPLE_SHADING}, + {(uint32_t)ewol::openGL::FLAG_SAMPLE_MASK, GL_SAMPLE_MASK}, + #endif + {(uint32_t)ewol::openGL::FLAG_SCISSOR_TEST, GL_SCISSOR_TEST}, + {(uint32_t)ewol::openGL::FLAG_STENCIL_TEST, GL_STENCIL_TEST}, + #ifndef __TARGET_OS__Android + {(uint32_t)ewol::openGL::FLAG_PROGRAM_POINT_SIZE, GL_PROGRAM_POINT_SIZE}, + #endif + {(uint32_t)ewol::openGL::FLAG_TEXTURE_2D, GL_TEXTURE_2D}, + #ifndef __TARGET_OS__Android + {(uint32_t)ewol::openGL::FLAG_ALPHA_TEST, GL_ALPHA_TEST}, + {(uint32_t)ewol::openGL::FLAG_FOG, GL_FOG} + #endif + //{(uint32_t)ewol::openGL::FLAG_, GL_} +}; +static int32_t basicFlagCount = sizeof(basicFlag) / sizeof(correspondenceTable_ts); + + +void ewol::openGL::Enable(ewol::openGL::openGlFlags_te flagID) { - glEnable(flagID); + #ifdef DIRECT_MODE + for (int32_t iii=0; iii" << l_flagsMustBeSet); + #endif } -void ewol::openGL::Disable(uint32_t flagID) +void ewol::openGL::Disable(ewol::openGL::openGlFlags_te flagID) { - glDisable(flagID); + #ifdef DIRECT_MODE + for (int32_t iii=0; iii" << l_flagsMustBeSet); + #endif } + + +void ewol::openGL::UpdateAllFlags(void) +{ + #ifdef DIRECT_MODE + return; + #endif + // check if fhags has change : + if (l_flagsMustBeSet==l_flagsCurrent ) { + return; + } + //EWOL_DEBUG(" ==>" << l_flagsMustBeSet); + for (int32_t iii=0; iii this enable mode difference ... */ void DrawArrays(uint32_t mode, int32_t first, int32_t count); - void DrawArraysInstanced(uint32_t mode, int32_t first, int32_t count, int32_t primcount); void DrawElements(uint32_t mode, int32_t count, uint32_t type, const void* indices); - void DrawRangeElements(uint32_t mode, int32_t start, int32_t end, int32_t count, uint32_t type, const void* indices); /** * @brief Use openGL program * @param[in] id Id of the program that might be used diff --git a/sources/ewol/renderer/os/eSystem.cpp b/sources/ewol/renderer/os/eSystem.cpp index cee5e326..b3a0bdc5 100644 --- a/sources/ewol/renderer/os/eSystem.cpp +++ b/sources/ewol/renderer/os/eSystem.cpp @@ -467,10 +467,12 @@ bool eSystem::Draw(bool displayEveryTime) { int64_t currentTime = ewol::GetTime(); // this is to prevent the multiple display at the a high frequency ... + #ifndef __PLATFORM__Android if(currentTime - previousDisplayTime < 1000000/120) { usleep(1000); return false; } + #endif previousDisplayTime = currentTime; if (true == isGlobalSystemInit) { @@ -511,9 +513,11 @@ l_FpsSystem.IncrementCounter(); } } l_FpsSystem.Toc(); + l_FpsFlush.Tic(); l_FpsFlush.IncrementCounter(); glFlush(); + //glFinish(); l_FpsFlush.Toc(); l_FpsSystemEvent.Draw(); diff --git a/sources/ewol/renderer/resources/Colored3DObject.cpp b/sources/ewol/renderer/resources/Colored3DObject.cpp index b3373fd3..bd9a728c 100644 --- a/sources/ewol/renderer/resources/Colored3DObject.cpp +++ b/sources/ewol/renderer/resources/Colored3DObject.cpp @@ -43,7 +43,7 @@ void ewol::Colored3DObject::Draw(etk::Vector& vertices, EWOL_ERROR("No shader ..."); return; } - ewol::openGL::Enable(GL_DEPTH_TEST); + ewol::openGL::Enable(ewol::openGL::FLAG_DEPTH_TEST); if (false==updateDepthBuffer) { glDepthMask(GL_FALSE); } @@ -67,7 +67,7 @@ void ewol::Colored3DObject::Draw(etk::Vector& vertices, if (false==updateDepthBuffer) { glDepthMask(GL_TRUE); } - ewol::openGL::Disable(GL_DEPTH_TEST); + ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST); } void ewol::Colored3DObject::Draw(etk::Vector& vertices, @@ -81,7 +81,7 @@ void ewol::Colored3DObject::Draw(etk::Vector& vertices, EWOL_ERROR("No shader ..."); return; } - ewol::openGL::Enable(GL_DEPTH_TEST); + ewol::openGL::Enable(ewol::openGL::FLAG_DEPTH_TEST); //EWOL_DEBUG(" Display " << m_coord.Size() << " elements" ); m_GLprogram->Use(); // set Matrix : translation/positionMatrix @@ -96,7 +96,7 @@ void ewol::Colored3DObject::Draw(etk::Vector& vertices, // Request the draw od the elements : ewol::openGL::DrawArrays(GL_TRIANGLES, 0, vertices.Size()); m_GLprogram->UnUse(); - ewol::openGL::Disable(GL_DEPTH_TEST); + ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST); } void ewol::Colored3DObject::DrawLine(etk::Vector& vertices, @@ -110,7 +110,7 @@ void ewol::Colored3DObject::DrawLine(etk::Vector& vertices, EWOL_ERROR("No shader ..."); return; } - ewol::openGL::Enable(GL_DEPTH_TEST); + ewol::openGL::Enable(ewol::openGL::FLAG_DEPTH_TEST); //EWOL_DEBUG(" Display " << m_coord.Size() << " elements" ); m_GLprogram->Use(); // set Matrix : translation/positionMatrix @@ -125,5 +125,5 @@ void ewol::Colored3DObject::DrawLine(etk::Vector& vertices, // Request the draw od the elements : ewol::openGL::DrawArrays(GL_LINES, 0, vertices.Size()); m_GLprogram->UnUse(); - ewol::openGL::Disable(GL_DEPTH_TEST); + ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST); } diff --git a/sources/ewol/renderer/resources/Mesh.cpp b/sources/ewol/renderer/resources/Mesh.cpp index 552105fb..9f9d1037 100644 --- a/sources/ewol/renderer/resources/Mesh.cpp +++ b/sources/ewol/renderer/resources/Mesh.cpp @@ -121,7 +121,7 @@ void ewol::Mesh::Draw(mat4& positionMatrix) EWOL_ERROR("No shader ..."); return; } - ewol::openGL::Enable(GL_DEPTH_TEST); + ewol::openGL::Enable(ewol::openGL::FLAG_DEPTH_TEST); //EWOL_DEBUG(" Display " << m_coord.Size() << " elements" ); m_GLprogram->Use(); // set Matrix : translation/positionMatrix @@ -147,8 +147,9 @@ void ewol::Mesh::Draw(mat4& positionMatrix) // Request the draw od the elements : ewol::openGL::DrawArrays(GL_TRIANGLES, 0, m_numberOfElments); m_GLprogram->UnUse(); - ewol::openGL::Disable(GL_DEPTH_TEST); - //glBindBuffer(GL_ARRAY_BUFFER,0); + ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST); + // TODO : UNDERSTAND why ... it is needed + glBindBuffer(GL_ARRAY_BUFFER,0); } // normal calculation of the normal face is really easy : diff --git a/sources/ewol/renderer/resources/Program.cpp b/sources/ewol/renderer/resources/Program.cpp index 15c94a0f..58fa0bba 100644 --- a/sources/ewol/renderer/resources/Program.cpp +++ b/sources/ewol/renderer/resources/Program.cpp @@ -666,7 +666,7 @@ void ewol::Program::Uniform4iv(int32_t idElem, int32_t nbElement, const int32_t //checkGlError("glUniform4iv", __LINE__); } - +//#define PROGRAM_DISPLAY_SPEED ////////////////////////////////////////////////////////////////////////////////////////////// #ifdef PROGRAM_DISPLAY_SPEED diff --git a/sources/ewol/widget/Scene.cpp b/sources/ewol/widget/Scene.cpp index 59fdd97d..3cae41c6 100644 --- a/sources/ewol/widget/Scene.cpp +++ b/sources/ewol/widget/Scene.cpp @@ -906,26 +906,26 @@ void widget::Scene::OnDraw(ewol::DrawProperty& displayProp) glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT1, GL_POSITION, light_position1); - ewol::openGL::Enable(GL_LIGHTING); - ewol::openGL::Enable(GL_LIGHT0); - ewol::openGL::Enable(GL_LIGHT1); + ewol::openGL::Enable(ewol::openGL::FLAG_LIGHTING); + ewol::openGL::Enable(ewol::openGL::FLAG_LIGHT0); + ewol::openGL::Enable(ewol::openGL::FLAG_LIGHT1); glShadeModel(GL_SMOOTH); - ewol::openGL::Enable(GL_DEPTH_TEST); + ewol::openGL::Enable(ewol::openGL::FLAG_DEPTH_TEST); glDepthFunc(GL_LESS); */ //updateCamera(); if(false/*m_enableshadows*/) { /* glClear(GL_STENCIL_BUFFER_BIT); - ewol::openGL::Enable(GL_CULL_FACE); + ewol::openGL::Enable(ewol::openGL::FLAG_CULL_FACE); renderscene(0); - ewol::openGL::Disable(GL_LIGHTING); + ewol::openGL::Disable(ewol::openGL::FLAG_LIGHTING); glDepthMask(GL_FALSE); glDepthFunc(GL_LEQUAL); - ewol::openGL::Enable(GL_STENCIL_TEST); + ewol::openGL::Enable(ewol::openGL::FLAG_STENCIL_TEST); glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE); glStencilFunc(GL_ALWAYS,1,0xFFFFFFFFL); glFrontFace(GL_CCW); @@ -939,34 +939,34 @@ void widget::Scene::OnDraw(ewol::DrawProperty& displayProp) glPolygonMode(GL_FRONT,GL_FILL); glPolygonMode(GL_BACK,GL_FILL); glShadeModel(GL_SMOOTH); - ewol::openGL::Enable(GL_DEPTH_TEST); + ewol::openGL::Enable(ewol::openGL::FLAG_DEPTH_TEST); glDepthFunc(GL_LESS); - ewol::openGL::Enable(GL_LIGHTING); + ewol::openGL::Enable(ewol::openGL::FLAG_LIGHTING); glDepthMask(GL_TRUE); glCullFace(GL_BACK); glFrontFace(GL_CCW); - ewol::openGL::Enable(GL_CULL_FACE); + ewol::openGL::Enable(ewol::openGL::FLAG_CULL_FACE); glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); glDepthFunc(GL_LEQUAL); glStencilFunc( GL_NOTEQUAL, 0, 0xFFFFFFFFL ); glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP ); - ewol::openGL::Disable(GL_LIGHTING); + ewol::openGL::Disable(ewol::openGL::FLAG_LIGHTING); renderscene(2); - ewol::openGL::Enable(GL_LIGHTING); + ewol::openGL::Enable(ewol::openGL::FLAG_LIGHTING); glDepthFunc(GL_LESS); - ewol::openGL::Disable(GL_STENCIL_TEST); - ewol::openGL::Disable(GL_CULL_FACE); + ewol::openGL::Disable(ewol::openGL::FLAG_STENCIL_TEST); + ewol::openGL::Disable(ewol::openGL::FLAG_CULL_FACE); */ } else { - //ewol::openGL::Disable(GL_CULL_FACE); + //ewol::openGL::Disable(ewol::openGL::FLAG_CULL_FACE); renderscene(0); } /* int32_t xOffset = 10; int32_t yStart = 20; int32_t yIncr = 20; - ewol::openGL::Disable(GL_LIGHTING); + ewol::openGL::Disable(ewol::openGL::FLAG_LIGHTING); glColor3f(0, 0, 0); if ((m_debugMode & btIDebugDraw::DBG_NoHelpText)==0) { @@ -974,7 +974,7 @@ void widget::Scene::OnDraw(ewol::DrawProperty& displayProp) showProfileInfo(xOffset,yStart,yIncr); resetPerspectiveProjection(); } - ewol::openGL::Disable(GL_LIGHTING); + ewol::openGL::Disable(ewol::openGL::FLAG_LIGHTING); */ //updateCamera(); diff --git a/sources/ewol/widget/Widget.cpp b/sources/ewol/widget/Widget.cpp index 85f76706..62ae6d9d 100644 --- a/sources/ewol/widget/Widget.cpp +++ b/sources/ewol/widget/Widget.cpp @@ -150,7 +150,10 @@ void ewol::Widget::GenDraw(DrawProperty displayProp) // Call the widget drawing methode displayProp.m_origin.setValue(tmpOriginX, tmpOriginY); displayProp.m_size.setValue(tmpclipX, m_size.y()); + //int64_t ___startTime = ewol::GetTime(); OnDraw(displayProp); + //float ___localTime = (float)(ewol::GetTime() - ___startTime) / 1000.0f; + //EWOL_DEBUG(" Widget1 : " << ___localTime << "ms "); } else { glViewport( m_origin.x(), m_origin.y(), @@ -165,7 +168,10 @@ void ewol::Widget::GenDraw(DrawProperty displayProp) // Call the widget drawing methode displayProp.m_origin = m_origin; displayProp.m_size = m_size; + //int64_t ___startTime = ewol::GetTime(); OnDraw(displayProp); + //float ___localTime = (float)(ewol::GetTime() - ___startTime) / 1000.0f; + //EWOL_DEBUG(" Widget2 : " << ___localTime << "ms "); } ewol::openGL::Pop(); return; diff --git a/sources/ewol/widget/Windows.cpp b/sources/ewol/widget/Windows.cpp index 2b5bef22..3ed2546d 100644 --- a/sources/ewol/widget/Windows.cpp +++ b/sources/ewol/widget/Windows.cpp @@ -97,18 +97,18 @@ void ewol::Windows::SysDraw(void) // set the size of the open GL system glViewport(0,0,m_size.x(),m_size.y()); - ewol::openGL::Disable(GL_DITHER); - //ewol::openGL::Disable(GL_BLEND); - ewol::openGL::Disable(GL_STENCIL_TEST); + ewol::openGL::Disable(ewol::openGL::FLAG_DITHER); + //ewol::openGL::Disable(ewol::openGL::FLAG_BLEND); + ewol::openGL::Disable(ewol::openGL::FLAG_STENCIL_TEST); + ewol::openGL::Disable(ewol::openGL::FLAG_ALPHA_TEST); + ewol::openGL::Disable(ewol::openGL::FLAG_FOG); #ifndef __TARGET_OS__Android - ewol::openGL::Disable(GL_ALPHA_TEST); - ewol::openGL::Disable(GL_FOG); glPixelZoom(1.0,1.0); #endif - ewol::openGL::Disable(GL_TEXTURE_2D); - ewol::openGL::Disable(GL_DEPTH_TEST); + ewol::openGL::Disable(ewol::openGL::FLAG_TEXTURE_2D); + ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST); - ewol::openGL::Enable(GL_BLEND); + ewol::openGL::Enable(ewol::openGL::FLAG_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // clear the matrix system : @@ -122,7 +122,7 @@ void ewol::Windows::SysDraw(void) GenDraw(displayProp); - ewol::openGL::Disable(GL_BLEND); + ewol::openGL::Disable(ewol::openGL::FLAG_BLEND); return; } @@ -138,20 +138,35 @@ void ewol::Windows::OnRegenerateDisplay(void) } } +//#define TEST_PERFO_WINDOWS void ewol::Windows::OnDraw(ewol::DrawProperty& displayProp) { - + #ifdef TEST_PERFO_WINDOWS + int64_t ___startTime0 = ewol::GetTime(); + #endif + // Clear the screen with transparency ... glClearColor(0.750, 0.750, 0.750, 0.5); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + #ifdef TEST_PERFO_WINDOWS + float ___localTime0 = (float)(ewol::GetTime() - ___startTime0) / 1000.0f; + EWOL_ERROR(" Windows000 : " << ___localTime0 << "ms "); + int64_t ___startTime1 = ewol::GetTime(); + #endif //EWOL_WARNING(" WINDOWS draw on " << m_currentDrawId); // first display the windows on the display if (NULL != m_subWidget) { m_subWidget->GenDraw(displayProp); //EWOL_DEBUG("Draw Windows"); } + #ifdef TEST_PERFO_WINDOWS + float ___localTime1 = (float)(ewol::GetTime() - ___startTime1) / 1000.0f; + EWOL_ERROR(" Windows111 : " << ___localTime1 << "ms "); + + int64_t ___startTime2 = ewol::GetTime(); + #endif // second display the pop-up for(int32_t iii=0; iii