From d67640dab6cefe7e82c0fec1267adab004410fa3 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 31 Aug 2013 03:40:30 +0200 Subject: [PATCH] Render with GLSL. Long way to go. --HG-- branch : gsoc2013-dfighter --- .../OpenGL3/driver_glsl_shader_generator.cpp | 2 +- .../nel/src/3d/driver/OpenGL3/driver_opengl.h | 1 + .../driver/OpenGL3/driver_opengl_program.cpp | 80 ++++++++++++++++++- .../driver/OpenGL3/driver_opengl_vertex.cpp | 2 + 4 files changed, 83 insertions(+), 2 deletions(-) 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 8517f07d1..800099aee 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 @@ -470,7 +470,7 @@ namespace NL3D sampler++; } - ss << "vec4 texel = vec4( 1.0, 1.0, 1.0, 1.0 );" << std::endl; + ss << "vec4 texel = vec4( 0.0, 0.0, 0.0, 1.0 );" << std::endl; generateTexEnv(); diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl.h b/code/nel/src/3d/driver/OpenGL3/driver_opengl.h index c5f02b7c7..b83b3cc34 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl.h +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl.h @@ -377,6 +377,7 @@ public: virtual bool setupMaterial(CMaterial& mat); bool setupProgram(CMaterial& mat); + void releaseProgram(); virtual void startSpecularBatch(); virtual void endSpecularBatch(); 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 4e3ef9dfe..fe620f4f2 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_program.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_program.cpp @@ -121,11 +121,31 @@ namespace NL3D if( !setupProgram( mat ) ) return false; - glDrawArrays( GL_TRIANGLES, startIndex * 3, numTris * 3 ); + //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); + } + } + + releaseProgram(); return true; } + static IProgram *vp; + static IProgram *pp; + static IProgramObject *p; + + bool CDriverGL3::setupProgram( CMaterial &mat ) { std::string vs; @@ -137,8 +157,66 @@ namespace NL3D shaderGenerator->generateVS( vs ); shaderGenerator->generatePS( ps ); + vp = createVertexProgram(); + std::string log; + + vp->shaderSource( vs.c_str() ); + if( !vp->compile( log ) ) + { + delete vp; + vp = NULL; + nlinfo( "%s", log.c_str() ); + return false; + } + + pp = createPixelProgram(); + pp->shaderSource( ps.c_str() ); + if( !pp->compile( log ) ) + { + delete vp; + vp = NULL; + delete pp; + pp = NULL; + nlinfo( "%s", log.c_str() ); + return false; + } + + p = createProgramObject(); + p->attachVertexProgram( vp ); + p->attachPixelProgram( pp ); + if( !p->link( log ) ) + { + delete vp; + vp = NULL; + delete pp; + pp = NULL; + delete p; + p = NULL; + nlinfo( "%s", log.c_str() ); + return false; + } + + if( !activeProgramObject( p ) ) + return false; + + int mvpIndex = getUniformLocation( "mvpMatrix" ); + if( mvpIndex != -1 ) + { + CMatrix mat = _GLProjMat * _ModelViewMatrix; + setUniformMatrix4fv( mvpIndex, 1, false, mat.get() ); + } + return true; } + + void CDriverGL3::releaseProgram() + { + delete p; + p = NULL; + vp = NULL; + pp = NULL; + } + } 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 6f6c11c89..2da49cad0 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_vertex.cpp @@ -256,6 +256,8 @@ bool CDriverGL3::renderLines(CMaterial& mat, uint32 firstIndex, uint32 nlines) bool CDriverGL3::renderTriangles(CMaterial& mat, uint32 firstIndex, uint32 ntris) { + return renderTriangles2( mat, firstIndex, ntris ); + H_AUTO_OGL(CDriverGL3_renderTriangles); // update matrix and Light in OpenGL if needed