diff --git a/code/nel/src/3d/driver/OpenGL3/driver_glsl_program.cpp b/code/nel/src/3d/driver/OpenGL3/driver_glsl_program.cpp index c852a01f1..b1273d5c3 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_glsl_program.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_glsl_program.cpp @@ -54,6 +54,7 @@ namespace NL3D if( itr != vertexPrograms.end() ) return false; + glGetError(); nglAttachShader( programId, shader->getShaderId() ); GLenum error = glGetError(); @@ -78,6 +79,7 @@ namespace NL3D if( itr != pixelPrograms.end() ) return false; + glGetError(); nglAttachShader( programId, shader->getShaderId() ); GLenum error = glGetError(); diff --git a/code/nel/src/3d/driver/OpenGL3/driver_glsl_shader_generator.cpp b/code/nel/src/3d/driver/OpenGL3/driver_glsl_shader_generator.cpp index 800099aee..52b30cf7c 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_glsl_shader_generator.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_glsl_shader_generator.cpp @@ -239,7 +239,7 @@ namespace NL3D void CGLSLShaderGenerator::addDiffuse() { - ss << "float diffuse = vec4( "; + ss << "vec4 diffuse = vec4( "; ss << float( material->getDiffuse().R / 255.0f ) << ", "; ss << float( material->getDiffuse().G / 255.0f ) << ", "; ss << float( material->getDiffuse().B / 255.0f ) << ", "; diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl.h b/code/nel/src/3d/driver/OpenGL3/driver_opengl.h index b83b3cc34..ea420d546 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl.h +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl.h @@ -1071,6 +1071,9 @@ private: void setupUVPtr(uint stage, CVertexBufferInfo &VB, uint uvId); + void setupNormalPass(); + + /// \name Lightmap. // @{ void computeLightMapInfos(const CMaterial &mat); 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 eecb0d267..02a4ab511 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_material.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_material.cpp @@ -577,6 +577,32 @@ void CDriverGL3::endMultiPass() } } + const char *samplers[ 4 ] = + { + "sampler0", + "sampler1", + "sampler2", + "sampler3" + }; + +void CDriverGL3::setupNormalPass() +{ + const CMaterial &mat = *_CurrentMaterial; + + for( int i = 0; i < 4; i++ ) + { + ITexture *t = mat.getTexture( i ); + if( t == NULL ) + continue; + + int index = getUniformLocation( samplers[ i ] ); + if( index == -1 ) + continue; + + setUniform1i( index, i ); + } +} + // *************************************************************************** void CDriverGL3::computeLightMapInfos (const CMaterial &mat) { 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 cb3c6c844..b3d00e646 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_program.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_program.cpp @@ -118,22 +118,25 @@ namespace NL3D bool CDriverGL3::renderTriangles2( CMaterial &mat, uint32 startIndex, uint32 numTris ) { + if( !setupMaterial( mat ) ) + return false; + if( !setupProgram( mat ) ) return false; //glDrawArrays( GL_TRIANGLES, startIndex * 3, numTris * 3 ); - if( numTris ) - { - if (_LastIB._Format == CIndexBuffer::Indices16) - { - glDrawElements(GL_TRIANGLES,3*numTris,GL_UNSIGNED_SHORT, ((uint16 *) _LastIB._Values)+startIndex); - } - else - { - nlassert(_LastIB._Format == CIndexBuffer::Indices32); - glDrawElements(GL_TRIANGLES,3*numTris,GL_UNSIGNED_INT, ((uint32 *) _LastIB._Values)+startIndex); - } + if( numTris ) + { + if (_LastIB._Format == CIndexBuffer::Indices16) + { + glDrawElements(GL_TRIANGLES,3*numTris,GL_UNSIGNED_SHORT, ((uint16 *) _LastIB._Values)+startIndex); + } + else + { + nlassert(_LastIB._Format == CIndexBuffer::Indices32); + glDrawElements(GL_TRIANGLES,3*numTris,GL_UNSIGNED_INT, ((uint32 *) _LastIB._Values)+startIndex); + } } releaseProgram(); @@ -186,9 +189,7 @@ namespace NL3D p->attachPixelProgram( pp ); if( !p->link( log ) ) { - delete vp; vp = NULL; - delete pp; pp = NULL; delete p; p = NULL; @@ -206,6 +207,13 @@ namespace NL3D setUniformMatrix4fv( mvpIndex, 1, false, mat.get() ); } + switch( mat.getShader() ) + { + case CMaterial::Normal: + setupNormalPass(); + break; + } + return true; }