Commit 978b548c authored by Maciej Suminski's avatar Maciej Suminski

Small improvements to SHADER class.

parent ef865aab
...@@ -35,13 +35,14 @@ ...@@ -35,13 +35,14 @@
using namespace KiGfx; 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 ) ...@@ -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 ) if( isShaderLinked )
{ {
...@@ -195,19 +196,7 @@ bool SHADER::Link() ...@@ -195,19 +196,7 @@ bool SHADER::Link()
} }
void SHADER::Use() void SHADER::AddParameter( const std::string& aParameterName )
{
glUseProgram( programNumber );
}
void SHADER::Deactivate()
{
glUseProgram( 0 );
}
void SHADER::AddParameter( std::string aParameterName )
{ {
GLint location = glGetUniformLocation( programNumber, aParameterName.c_str() ); GLint location = glGetUniformLocation( programNumber, aParameterName.c_str() );
...@@ -224,7 +213,7 @@ void SHADER::SetParameter( int parameterNumber, float value ) ...@@ -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() ); return glGetAttribLocation( programNumber, aAttributeName.c_str() );
} }
...@@ -76,23 +76,42 @@ public: ...@@ -76,23 +76,42 @@ public:
* @param aShaderSourceName is the shader source file name. * @param aShaderSourceName is the shader source file name.
* @param aShaderType is the type of the shader. * @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. * @return true in case of success, false otherwise.
*/ */
bool Link(); 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. * @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! * @brief Configure the geometry shader - has to be done before linking!
...@@ -113,7 +132,7 @@ public: ...@@ -113,7 +132,7 @@ public:
* *
* @param aParameterName is the name of the parameter. * @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. * @brief Set a parameter of the shader.
...@@ -129,7 +148,7 @@ public: ...@@ -129,7 +148,7 @@ public:
* @param aAttributeName is the name of the attribute. * @param aAttributeName is the name of the attribute.
* @return the location. * @return the location.
*/ */
int GetAttribute( std::string aAttributeName ); int GetAttribute( std::string aAttributeName ) const;
private: private:
...@@ -152,6 +171,7 @@ private: ...@@ -152,6 +171,7 @@ private:
GLuint programNumber; ///< Shader program number GLuint programNumber; ///< Shader program number
bool isProgramCreated; ///< Flag for program creation bool isProgramCreated; ///< Flag for program creation
bool isShaderLinked; ///< Is the shader linked? bool isShaderLinked; ///< Is the shader linked?
bool active; ///< Is any of shaders used?
GLuint maximumVertices; ///< The maximum of vertices to be generated GLuint maximumVertices; ///< The maximum of vertices to be generated
GLuint geomInputType; ///< Input type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.] 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.] GLuint geomOutputType; ///< Output type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment