Small improvements to SHADER class.
This commit is contained in:
parent
ef865aab68
commit
978b548c64
|
@ -35,13 +35,14 @@
|
|||
|
||||
using namespace KiGfx;
|
||||
|
||||
SHADER::SHADER()
|
||||
SHADER::SHADER() :
|
||||
isProgramCreated( false ),
|
||||
isShaderLinked( false ),
|
||||
maximumVertices( 4 ),
|
||||
active( false ),
|
||||
geomInputType( GL_LINES ),
|
||||
geomOutputType( GL_LINES )
|
||||
{
|
||||
isProgramCreated = false;
|
||||
isShaderLinked = false;
|
||||
maximumVertices = 4;
|
||||
geomInputType = GL_LINES;
|
||||
geomOutputType = GL_LINES;
|
||||
}
|
||||
|
||||
|
||||
|
@ -108,7 +109,7 @@ std::string SHADER::ReadSource( std::string aShaderSourceName )
|
|||
}
|
||||
|
||||
|
||||
void SHADER::AddSource( std::string aShaderSourceName, ShaderType aShaderType )
|
||||
void SHADER::AddSource( const std::string& aShaderSourceName, ShaderType aShaderType )
|
||||
{
|
||||
if( isShaderLinked )
|
||||
{
|
||||
|
@ -195,19 +196,7 @@ bool SHADER::Link()
|
|||
}
|
||||
|
||||
|
||||
void SHADER::Use()
|
||||
{
|
||||
glUseProgram( programNumber );
|
||||
}
|
||||
|
||||
|
||||
void SHADER::Deactivate()
|
||||
{
|
||||
glUseProgram( 0 );
|
||||
}
|
||||
|
||||
|
||||
void SHADER::AddParameter( std::string aParameterName )
|
||||
void SHADER::AddParameter( const std::string& aParameterName )
|
||||
{
|
||||
GLint location = glGetUniformLocation( programNumber, aParameterName.c_str() );
|
||||
|
||||
|
@ -224,7 +213,7 @@ void SHADER::SetParameter( int parameterNumber, float value )
|
|||
}
|
||||
|
||||
|
||||
int SHADER::GetAttribute( std::string aAttributeName )
|
||||
int SHADER::GetAttribute( std::string aAttributeName ) const
|
||||
{
|
||||
return glGetAttribLocation( programNumber, aAttributeName.c_str() );
|
||||
}
|
||||
|
|
|
@ -76,23 +76,42 @@ public:
|
|||
* @param aShaderSourceName is the shader source file name.
|
||||
* @param aShaderType is the type of the shader.
|
||||
*/
|
||||
void AddSource( std::string aShaderSourceName, ShaderType aShaderType );
|
||||
void AddSource( const std::string& aShaderSourceName, ShaderType aShaderType );
|
||||
|
||||
/**
|
||||
* Link the shaders.
|
||||
* @brief Link the shaders.
|
||||
*
|
||||
* @return true in case of success, false otherwise.
|
||||
*/
|
||||
bool Link();
|
||||
|
||||
/**
|
||||
* Use the shader.
|
||||
* @brief Use the shader.
|
||||
*/
|
||||
void Use();
|
||||
inline void Use()
|
||||
{
|
||||
glUseProgram( programNumber );
|
||||
active = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deactivate the shader and use the default OpenGL program.
|
||||
*/
|
||||
void Deactivate();
|
||||
inline void Deactivate()
|
||||
{
|
||||
glUseProgram( 0 );
|
||||
active = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the current state of the shader.
|
||||
*
|
||||
* @return True if any of shaders is enabled.
|
||||
*/
|
||||
inline bool IsActive() const
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the geometry shader - has to be done before linking!
|
||||
|
@ -113,7 +132,7 @@ public:
|
|||
*
|
||||
* @param aParameterName is the name of the parameter.
|
||||
*/
|
||||
void AddParameter( std::string aParameterName );
|
||||
void AddParameter( const std::string& aParameterName );
|
||||
|
||||
/**
|
||||
* @brief Set a parameter of the shader.
|
||||
|
@ -129,7 +148,7 @@ public:
|
|||
* @param aAttributeName is the name of the attribute.
|
||||
* @return the location.
|
||||
*/
|
||||
int GetAttribute( std::string aAttributeName );
|
||||
int GetAttribute( std::string aAttributeName ) const;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -152,6 +171,7 @@ private:
|
|||
GLuint programNumber; ///< Shader program number
|
||||
bool isProgramCreated; ///< Flag for program creation
|
||||
bool isShaderLinked; ///< Is the shader linked?
|
||||
bool active; ///< Is any of shaders used?
|
||||
GLuint maximumVertices; ///< The maximum of vertices to be generated
|
||||
GLuint geomInputType; ///< Input type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.]
|
||||
GLuint geomOutputType; ///< Output type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.]
|
||||
|
|
Loading…
Reference in New Issue