Implemented uniform querying, setting. Also updated the test triangle.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 11 years ago
parent 3ca6a98aec
commit d67198580a

@ -1025,16 +1025,28 @@ public:
/// Activates the specified GPU program object /// Activates the specified GPU program object
virtual bool activeProgramObject( IProgramObject *program ) = 0; virtual bool activeProgramObject( IProgramObject *program ){ return false; };
/// Creates a new GPU program object /// Creates a new GPU program object
virtual IProgramObject* createProgramObject() const = 0; virtual IProgramObject* createProgramObject() const { return NULL; }
/// Creates a new Vertex program /// Creates a new Vertex program
virtual IProgram* createVertexProgram() const = 0; virtual IProgram* createVertexProgram() const { return NULL; }
/// Creates a new Pixel program /// Creates a new Pixel program
virtual IProgram* createPixelProgram() const = 0; virtual IProgram* createPixelProgram() const { return NULL; }
virtual int getUniformLocation( const char *name ){ return -1; }
virtual void setUniform1f( uint index, float f ){}
virtual void setUniform4f( uint index, float f1, float f2, float f3, float f4 ){}
virtual void setUniform1i( uint index, int i ){}
virtual void setUniform4i( uint index, int i1, int i2, int i3, int i4 ){}
virtual void setUniform1u( uint index, uint u ){}
virtual void setUniform4u( uint index, uint u1, uint u2, uint u3, uint u4 ){}
virtual void setUniformMatrix2fv( uint index, uint count, bool transpose, const float *values ){}
virtual void setUniformMatrix3fv( uint index, uint count, bool transpose, const float *values ){}
virtual void setUniformMatrix4fv( uint index, uint count, bool transpose, const float *values ){}
/** /**
* Setup constant values. * Setup constant values.

@ -331,6 +331,8 @@ CDriverGL3::CDriverGL3()
_TextureTargetCubeFace = 0; _TextureTargetCubeFace = 0;
_TextureTargetUpload = false; _TextureTargetUpload = false;
currentProgram = NULL;
} }
// *************************************************************************** // ***************************************************************************

@ -1262,6 +1262,18 @@ private:
IProgram* createVertexProgram() const; IProgram* createVertexProgram() const;
IProgram* createPixelProgram() const; IProgram* createPixelProgram() const;
int getUniformLocation( const char *name );
void setUniform1f( uint index, float f );
void setUniform4f( uint index, float f1, float f2, float f3, float f4 );
void setUniform1i( uint index, int i );
void setUniform4i( uint index, int i1, int i2, int i3, int i4 );
void setUniform1u( uint index, uint u );
void setUniform4u( uint index, uint u1, uint u2, uint u3, uint u4 );
void setUniformMatrix2fv( uint index, uint count, bool transpose, const float *values );
void setUniformMatrix3fv( uint index, uint count, bool transpose, const float *values );
void setUniformMatrix4fv( uint index, uint count, bool transpose, const float *values );
void setConstant (uint index, float, float, float, float); void setConstant (uint index, float, float, float, float);
void setConstant (uint index, double, double, double, double); void setConstant (uint index, double, double, double, double);
void setConstant (uint indexStart, const NLMISC::CVector& value); void setConstant (uint indexStart, const NLMISC::CVector& value);
@ -1339,6 +1351,8 @@ private:
private: private:
IProgramObject *currentProgram;
bool setupARBVertexProgram (const CVPParser::TProgram &parsedProgram, GLuint id, bool &specularWritten); bool setupARBVertexProgram (const CVPParser::TProgram &parsedProgram, GLuint id, bool &specularWritten);
// init EMBM settings (set each stage to modify the next) // init EMBM settings (set each stage to modify the next)

@ -11,6 +11,7 @@ namespace NL3D
if( !program ) if( !program )
{ {
_VertexProgramEnabled = false; _VertexProgramEnabled = false;
currentProgram = NULL;
return true; return true;
} }
@ -31,6 +32,7 @@ namespace NL3D
return false; return false;
_VertexProgramEnabled = true; _VertexProgramEnabled = true;
currentProgram = program;
return true; return true;
} }
@ -51,6 +53,60 @@ namespace NL3D
return new CGLSLPixelProgram(); return new CGLSLPixelProgram();
} }
int CDriverGL3::getUniformLocation( const char *name )
{
if( currentProgram == NULL )
return -1;
return nglGetUniformLocation( currentProgram->getProgramId(), name );
}
void CDriverGL3::setUniform1f( uint index, float f )
{
nglUniform1f( index, f );
}
void CDriverGL3::setUniform4f( uint index, float f1, float f2, float f3, float f4 )
{
nglUniform4f( index, f1, f2, f3, f4 );
}
void CDriverGL3::setUniform1i( uint index, int i )
{
nglUniform1i( index, i );
}
void CDriverGL3::setUniform4i( uint index, int i1, int i2, int i3, int i4 )
{
nglUniform4i( index, i1, i2, i3, i4 );
}
void CDriverGL3::setUniform1u( uint index, uint u )
{
nglUniform1ui( index, u );
}
void CDriverGL3::setUniform4u( uint index, uint u1, uint u2, uint u3, uint u4 )
{
nglUniform4ui( index, u1, u2, u3, u4 );
}
void CDriverGL3::setUniformMatrix2fv( uint index, uint count, bool transpose, const float *values )
{
nglUniformMatrix2fv( index, count, transpose, values );
}
void CDriverGL3::setUniformMatrix3fv( uint index, uint count, bool transpose, const float *values )
{
nglUniformMatrix3fv( index, count, transpose, values );
}
void CDriverGL3::setUniformMatrix4fv( uint index, uint count, bool transpose, const float *values )
{
nglUniformMatrix4fv( index, count, transpose, values );
}
bool CDriverGL3::renderRawTriangles2( CMaterial &mat, uint32 startIndex, uint32 numTris ) bool CDriverGL3::renderRawTriangles2( CMaterial &mat, uint32 startIndex, uint32 numTris )
{ {
glDrawArrays( GL_TRIANGLES, startIndex * 3, numTris * 3 ); glDrawArrays( GL_TRIANGLES, startIndex * 3, numTris * 3 );

@ -450,7 +450,7 @@ namespace MaterialEditor
const char *vs = const char *vs =
"#version 330\n" "#version 330\n"
"\n" "\n"
"layout ( location = 0 )in vec4 vertex;\n" "layout ( location = 0 ) in vec4 vertex;\n"
"layout ( location = 3 ) in vec4 color;\n" "layout ( location = 3 ) in vec4 color;\n"
"out vec4 vColor;\n" "out vec4 vColor;\n"
"\n" "\n"
@ -466,9 +466,13 @@ namespace MaterialEditor
"in vec4 vColor;\n" "in vec4 vColor;\n"
"out vec4 color;\n" "out vec4 color;\n"
"\n" "\n"
"uniform float redShift;"
"\n"
"void main( void )\n" "void main( void )\n"
"{\n" "{\n"
"color = vColor;\n" "vec4 finalColor = vColor.rgba;\n"
"finalColor.r = redShift;\n"
"color = finalColor;\n"
"}\n"; "}\n";
void CNel3DInterface::drawTriangle() void CNel3DInterface::drawTriangle()
@ -561,6 +565,10 @@ namespace MaterialEditor
return; return;
} }
int opacityLocation = id->getUniformLocation( "redShift" );
if( opacityLocation != -1 )
id->setUniform1f( opacityLocation, 0.25f );
id->activeVertexBuffer( vb ); id->activeVertexBuffer( vb );
id->activeIndexBuffer( ib ); id->activeIndexBuffer( ib );

Loading…
Cancel
Save