From 8276cb0140be19d5d2150df9c6450fa77c6429eb Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Thu, 24 Oct 2013 03:26:39 +0200 Subject: [PATCH] We shouldn't set up a generated or newly compiled shader program if we already have one ( set up from outside the driver for example ). --HG-- branch : gsoc2013-dfighter --- .../nel/src/3d/driver/opengl3/driver_opengl.h | 8 + .../driver/opengl3/driver_opengl_program.cpp | 149 ++++++++++-------- .../opengl3/driver_opengl_rendering.cpp | 14 ++ 3 files changed, 107 insertions(+), 64 deletions(-) diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl.h b/code/nel/src/3d/driver/opengl3/driver_opengl.h index 60679428d..708eea683 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl.h +++ b/code/nel/src/3d/driver/opengl3/driver_opengl.h @@ -708,6 +708,14 @@ private: friend class CVertexProgamDrvInfosGL3; private: + /// Simply sets the current programs to NULL + void nullPrograms() + { + currentProgram.vp = NULL; + currentProgram.pp = NULL; + currentProgram.gp = NULL; + } + // Version of the driver. Not the interface version!! Increment when implementation of the driver change. static const uint32 ReleaseVersion; diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp b/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp index 08e6db09f..5dd3570d0 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp @@ -513,11 +513,17 @@ namespace NL3D if( !sp.empty() ) { - if( !activeVertexProgram( sp.vp ) ) - return false; + if( currentProgram.vp == NULL ) + { + if( !activeVertexProgram( sp.vp ) ) + return false; + } - if( !activePixelProgram( sp.pp ) ) - return false; + if( currentProgram.pp == NULL ) + { + if( !activePixelProgram( sp.pp ) ) + return false; + } } else { @@ -565,22 +571,28 @@ namespace NL3D return false; } - if( !activeVertexProgram( vp ) ) + if( currentProgram.vp == NULL ) { - delete vp; - vp = NULL; - delete pp; - pp = NULL; - return false; + if( !activeVertexProgram( vp ) ) + { + delete vp; + vp = NULL; + delete pp; + pp = NULL; + return false; + } } - if( !activePixelProgram( pp ) ) + if( currentProgram.pp == NULL ) { - delete vp; - vp = NULL; - delete pp; - pp = NULL; - return false; + if( !activePixelProgram( pp ) ) + { + delete vp; + vp = NULL; + delete pp; + pp = NULL; + return false; + } } sp.vp = vp; @@ -596,6 +608,9 @@ namespace NL3D bool CDriverGL3::setupDynMatProgram( CMaterial& mat, uint pass ) { + if( ( currentProgram.vp != NULL ) && ( currentProgram.pp != NULL ) ) + return true; + CDynMaterial *m = mat.getDynMat(); const SRenderPass *rp = m->getPass( pass ); std::string shaderRef; @@ -606,67 +621,73 @@ namespace NL3D if( !usrShaderManager->getShader( shaderRef, &prg ) ) return false; - CVertexProgram *vp = new CVertexProgram(); - CPixelProgram *pp = new CPixelProgram(); - std::string shaderSource; std::string log; std::string name; - prg.getVP( shaderSource ); - prg.getName( name ); - + + if( currentProgram.vp == NULL ) { - IProgram::CSource *src = new IProgram::CSource(); - src->Profile = IProgram::glsl330v; - src->DisplayName = name; - src->setSource( shaderSource.c_str() ); - vp->addSource( src ); - } + prg.getVP( shaderSource ); + prg.getName( name ); + + CVertexProgram *vp = new CVertexProgram(); + { + IProgram::CSource *src = new IProgram::CSource(); + src->Profile = IProgram::glsl330v; + src->DisplayName = name; + src->setSource( shaderSource.c_str() ); + vp->addSource( src ); + } - if( !compileVertexProgram( vp ) ) - { - delete vp; - delete pp; - return false; + if( !compileVertexProgram( vp ) ) + { + delete vp; + return false; + } + + if( !activeVertexProgram( vp ) ) + { + delete vp; + return false; + } + + if( currentProgram.dynmatVP != NULL ) + delete currentProgram.dynmatVP; + currentProgram.dynmatVP = vp; + } - prg.getFP( shaderSource ); + if( currentProgram.pp == NULL ) { - IProgram::CSource *src = new IProgram::CSource(); - src->Profile = IProgram::glsl330f; - src->DisplayName = name; - src->setSource( shaderSource.c_str() ); - pp->addSource( src ); - } - if( !compilePixelProgram( pp ) ) - { - delete vp; - delete pp; - return false; - } + CPixelProgram *pp = new CPixelProgram(); - if( !activeVertexProgram( vp ) ) - { - delete vp; - delete pp; - return false; - } + prg.getFP( shaderSource ); + { + IProgram::CSource *src = new IProgram::CSource(); + src->Profile = IProgram::glsl330f; + src->DisplayName = name; + src->setSource( shaderSource.c_str() ); + pp->addSource( src ); + } + + if( !compilePixelProgram( pp ) ) + { + delete pp; + return false; + } - if( !activePixelProgram( pp ) ) - { - delete vp; - delete pp; - return false; - } + if( !activePixelProgram( pp ) ) + { + delete pp; + return false; + } - if( currentProgram.dynmatVP != NULL ) - delete currentProgram.dynmatVP; - currentProgram.dynmatVP = vp; + if( currentProgram.dynmatPP != NULL ) + delete currentProgram.dynmatPP; + currentProgram.dynmatPP = pp; - if( currentProgram.dynmatPP != NULL ) - delete currentProgram.dynmatPP; - currentProgram.dynmatPP = pp; + } return true; } diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_rendering.cpp b/code/nel/src/3d/driver/opengl3/driver_opengl_rendering.cpp index 82eb7b7c9..d59aa406d 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_rendering.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_rendering.cpp @@ -73,6 +73,8 @@ bool CDriverGL3::renderLines(CMaterial& mat, uint32 firstIndex, uint32 nlines) _PrimitiveProfileIn.NLines+= nlines; _PrimitiveProfileOut.NLines+= nlines; + nullPrograms(); + return true; } @@ -127,6 +129,8 @@ bool CDriverGL3::renderTriangles(CMaterial& mat, uint32 firstIndex, uint32 ntris _PrimitiveProfileIn.NTriangles+= ntris; _PrimitiveProfileOut.NTriangles+= ntris * nPass; + nullPrograms(); + return true; } @@ -160,6 +164,8 @@ bool CDriverGL3::renderSimpleTriangles(uint32 firstTri, uint32 ntris) _PrimitiveProfileIn.NTriangles+= ntris; _PrimitiveProfileOut.NTriangles+= ntris; + nullPrograms(); + return true; } @@ -201,6 +207,8 @@ bool CDriverGL3::renderRawPoints(CMaterial& mat, uint32 startIndex, uint32 numPo _PrimitiveProfileIn.NPoints+= numPoints; _PrimitiveProfileOut.NPoints+= numPoints * nPass; + nullPrograms(); + return true; } @@ -242,6 +250,8 @@ bool CDriverGL3::renderRawLines(CMaterial& mat, uint32 startIndex, uint32 numLin _PrimitiveProfileIn.NLines += numLines ; _PrimitiveProfileOut.NLines += numLines * nPass; + nullPrograms(); + return true; } @@ -285,6 +295,8 @@ bool CDriverGL3::renderRawTriangles(CMaterial& mat, uint32 startIndex, uint32 nu _PrimitiveProfileIn.NTriangles += numTris ; _PrimitiveProfileOut.NTriangles += numTris * nPass; + nullPrograms(); + return true; } @@ -408,6 +420,8 @@ bool CDriverGL3::renderRawQuads(CMaterial& mat, uint32 startIndex, uint32 numQua _PrimitiveProfileIn.NQuads += numQuads ; _PrimitiveProfileOut.NQuads += numQuads * nPass; + nullPrograms(); + return true; }