diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl.h b/code/nel/src/3d/driver/OpenGL3/driver_opengl.h index 18d51324f..820fe549a 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl.h +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl.h @@ -1200,6 +1200,7 @@ private: } } void doRefreshRenderSetup(); + void refreshTexMatrices(); void setLightInternal(uint8 num, const CLight& light); void enableLightInternal(uint8 num, bool enable); diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_material.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_material.cpp index 86f4c99ea..a30727261 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_material.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_material.cpp @@ -166,8 +166,6 @@ void CDriverGL3::setupUserTextureMatrix(uint numStages, CMaterial& mat) || (mat.getFlags() & IDRV_MAT_USER_TEX_MAT_ALL) != 0 ) { - glMatrixMode(GL_TEXTURE); - // for each stage, setup the texture matrix if needed uint newMask = (mat.getFlags() & IDRV_MAT_USER_TEX_MAT_ALL) >> IDRV_MAT_USER_TEX_FIRST_BIT; uint shiftMask = 1; @@ -175,9 +173,8 @@ void CDriverGL3::setupUserTextureMatrix(uint numStages, CMaterial& mat) { if (newMask & shiftMask) // user matrix for this stage { - _DriverGLStates.activeTextureARB(k); - glLoadMatrixf(mat.getUserTexMat(k).get()); - + _UserTexMat[ k ] = mat.getUserTexMat( k ); + _UserTexMatDirty[ k ] = true; _UserTexMatEnabled |= shiftMask; } else @@ -187,15 +184,13 @@ void CDriverGL3::setupUserTextureMatrix(uint numStages, CMaterial& mat) (newMask & shiftMask) != (_UserTexMatEnabled & shiftMask) ) { - _DriverGLStates.activeTextureARB(k); - glLoadIdentity(); - + _UserTexMat[ k ].identity(); + _UserTexMatDirty[ k ] = true; _UserTexMatEnabled &= ~shiftMask; } } shiftMask <<= 1; } - glMatrixMode(GL_MODELVIEW); } } @@ -204,22 +199,18 @@ void CDriverGL3::disableUserTextureMatrix() H_AUTO_OGL(CDriverGL3_disableUserTextureMatrix) if (_UserTexMatEnabled != 0) { - glMatrixMode(GL_TEXTURE); - uint k = 0; do { if (_UserTexMatEnabled & (1 << k)) // user matrix for this stage { - _DriverGLStates.activeTextureARB(k); - glLoadIdentity(); - + _UserTexMat[ k ].identity(); + _UserTexMatDirty[ k ] = true; _UserTexMatEnabled &= ~ (1 << k); } ++k; } while (_UserTexMatEnabled != 0); - glMatrixMode(GL_MODELVIEW); } } @@ -1114,9 +1105,9 @@ void CDriverGL3::setupSpecularBegin() _DriverGLStates.setTexGenMode (1, GL_REFLECTION_MAP_ARB); // setup the good matrix for stage 1. - glMatrixMode(GL_TEXTURE); - glLoadMatrixf( _SpecularTexMtx.get() ); - glMatrixMode(GL_MODELVIEW); + _UserTexMat[ 1 ] = _SpecularTexMtx; + _UserTexMatDirty[ 1 ] = true; + } // *************************************************************************** @@ -1128,9 +1119,8 @@ void CDriverGL3::setupSpecularEnd() _DriverGLStates.setTexGenMode(1, 0); // Happiness !!! we have already enabled the stage 1 - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + _UserTexMat[ 1 ].identity(); + _UserTexMatDirty[ 1 ] = true; } // *************************************************************************** diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_matrix.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_matrix.cpp index 121317cad..a97c49cea 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_matrix.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_matrix.cpp @@ -188,6 +188,21 @@ void CDriverGL3::doRefreshRenderSetup() _RenderSetupDirty= false; } +void CDriverGL3::refreshTexMatrices() +{ + glMatrixMode( GL_TEXTURE ); + for( int i = 0; i < IDRV_MAT_MAXTEXTURES; i++ ) + { + if( _UserTexMatDirty[ i ] ) + { + _DriverGLStates.activeTextureARB( i ); + glLoadMatrixf( _UserTexMat[ i ].get() ); + _UserTexMatDirty[ i ] = false; + } + } + glMatrixMode( GL_MODELVIEW ); +} + #ifdef NL_STATIC } // NLDRIVERGL/ES #endif diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex.cpp index 1def82bd5..015b74e8c 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex.cpp @@ -225,6 +225,9 @@ bool CDriverGL3::renderLines(CMaterial& mat, uint32 firstIndex, uint32 nlines) { // setup the pass. setupPass(pass); + + refreshTexMatrices(); + // draw the primitives. if(nlines) { @@ -262,6 +265,8 @@ bool CDriverGL3::renderTriangles(CMaterial& mat, uint32 firstIndex, uint32 ntris if ( !setupMaterial(mat) || _LastIB._Values == NULL ) return false; + refreshTexMatrices(); + if (_CurrentVertexBufferHard && _CurrentVertexBufferHard->isInvalid()) return true; // render primitives. @@ -277,6 +282,8 @@ bool CDriverGL3::renderTriangles(CMaterial& mat, uint32 firstIndex, uint32 ntris // setup the pass. setupPass(pass); + refreshTexMatrices(); + // draw the primitives. if(ntris) { @@ -361,6 +368,9 @@ bool CDriverGL3::renderRawPoints(CMaterial& mat, uint32 startIndex, uint32 numPo { // setup the pass. setupPass(pass); + + refreshTexMatrices(); + // draw the primitives. if(numPoints) glDrawArrays(GL_POINTS, startIndex, numPoints); @@ -399,6 +409,9 @@ bool CDriverGL3::renderRawLines(CMaterial& mat, uint32 startIndex, uint32 numLin { // setup the pass. setupPass(pass); + + refreshTexMatrices(); + // draw the primitives. if(numLines) glDrawArrays(GL_LINES, startIndex << 1, numLines << 1); @@ -437,6 +450,9 @@ bool CDriverGL3::renderRawTriangles(CMaterial& mat, uint32 startIndex, uint32 nu { // setup the pass. setupPass(pass); + + refreshTexMatrices(); + // draw the primitives. if(numTris) { @@ -501,6 +517,8 @@ bool CDriverGL3::renderRawQuads(CMaterial& mat, uint32 startIndex, uint32 numQua // setup the pass. setupPass(pass); + refreshTexMatrices(); + uint32 currIndex = startIndex; uint32 numLeftQuads = numQuads;