Render with GLSL. Long way to go.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 11 years ago
parent 169ee413df
commit d67640dab6

@ -470,7 +470,7 @@ namespace NL3D
sampler++; 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(); generateTexEnv();

@ -377,6 +377,7 @@ public:
virtual bool setupMaterial(CMaterial& mat); virtual bool setupMaterial(CMaterial& mat);
bool setupProgram(CMaterial& mat); bool setupProgram(CMaterial& mat);
void releaseProgram();
virtual void startSpecularBatch(); virtual void startSpecularBatch();
virtual void endSpecularBatch(); virtual void endSpecularBatch();

@ -121,11 +121,31 @@ namespace NL3D
if( !setupProgram( mat ) ) if( !setupProgram( mat ) )
return false; 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; return true;
} }
static IProgram *vp;
static IProgram *pp;
static IProgramObject *p;
bool CDriverGL3::setupProgram( CMaterial &mat ) bool CDriverGL3::setupProgram( CMaterial &mat )
{ {
std::string vs; std::string vs;
@ -137,8 +157,66 @@ namespace NL3D
shaderGenerator->generateVS( vs ); shaderGenerator->generateVS( vs );
shaderGenerator->generatePS( ps ); 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; return true;
} }
void CDriverGL3::releaseProgram()
{
delete p;
p = NULL;
vp = NULL;
pp = NULL;
}
} }

@ -256,6 +256,8 @@ bool CDriverGL3::renderLines(CMaterial& mat, uint32 firstIndex, uint32 nlines)
bool CDriverGL3::renderTriangles(CMaterial& mat, uint32 firstIndex, uint32 ntris) bool CDriverGL3::renderTriangles(CMaterial& mat, uint32 firstIndex, uint32 ntris)
{ {
return renderTriangles2( mat, firstIndex, ntris );
H_AUTO_OGL(CDriverGL3_renderTriangles); H_AUTO_OGL(CDriverGL3_renderTriangles);
// update matrix and Light in OpenGL if needed // update matrix and Light in OpenGL if needed

Loading…
Cancel
Save