42 isProgramCreated( false ),
43 isShaderLinked( false ),
46 geomInputType( GL_LINES ),
47 geomOutputType( GL_LINES )
70 if( glIsShader( shader ) )
73 glDeleteShader( shader );
86 const std::string shaderSource =
ReadSource( aShaderSourceName );
93 GLuint geometryOutputType )
116 glGetProgramiv(
programNumber, GL_INFO_LOG_LENGTH, &maxLength );
117 maxLength = maxLength + 1;
118 char* linkInfoLog =
new char[maxLength];
119 glGetProgramInfoLog(
programNumber, maxLength, &maxLength, linkInfoLog );
120 std::cerr <<
"Shader linking error:" << std::endl;
121 std::cerr << linkInfoLog;
122 delete[] linkInfoLog;
132 GLint location = glGetUniformLocation(
programNumber, aParameterName.c_str() );
137 throw std::runtime_error(
"Could not find shader uniform: " + aParameterName );
161 float arr[4] = { f0, f1, f2, f3 };
168 glUniform2f(
parameterLocation[aParameterNumber],
static_cast<GLfloat
>( aValue.
x ),
static_cast<GLfloat
>( aValue.
y ) );
174 return glGetAttribLocation(
programNumber, aAttributeName.c_str() );
180 GLint glInfoLogLength = 0;
181 GLint writtenChars = 0;
184 glGetProgramiv( aProgram, GL_INFO_LOG_LENGTH, &glInfoLogLength );
187 if( glInfoLogLength > 2 )
189 GLchar* glInfoLog =
new GLchar[glInfoLogLength];
190 glGetProgramInfoLog( aProgram, glInfoLogLength, &writtenChars, glInfoLog );
199 GLint glInfoLogLength = 0;
200 GLint writtenChars = 0;
203 glGetShaderiv( aShader, GL_INFO_LOG_LENGTH, &glInfoLogLength );
206 if( glInfoLogLength > 2 )
208 GLchar* glInfoLog =
new GLchar[glInfoLogLength];
209 glGetShaderInfoLog( aShader, glInfoLogLength, &writtenChars, glInfoLog );
219 std::ifstream inputFile( aShaderSourceName.c_str(), std::ifstream::in );
220 std::string shaderSource;
223 throw std::runtime_error(
"Can't read the shader source: " + aShaderSourceName );
225 std::string shaderSourceLine;
228 while( getline( inputFile, shaderSourceLine ) )
230 shaderSource += shaderSourceLine;
231 shaderSource +=
"\n";
250 GLuint shaderNumber = glCreateShader( aShaderType );
257 glShaderSource( shaderNumber,
static_cast<GLsizei
>( aSize ), (
const GLchar**) aArray,
nullptr );
261 glCompileShader( shaderNumber );
263 glGetShaderiv( shaderNumber, GL_COMPILE_STATUS, &status );
265 if( status != GL_TRUE )
270 glGetShaderiv( shaderNumber, GL_INFO_LOG_LENGTH, &maxLength );
273 std::vector<GLchar> errorLog( (
size_t) maxLength );
274 glGetShaderInfoLog( shaderNumber, maxLength, &maxLength, &errorLog[0] );
278 glDeleteShader( shaderNumber );
280 throw std::runtime_error( &errorLog[0] );
static std::string ReadSource(const std::string &aShaderSourceName)
Read the shader source file.
bool active
Is any of shaders used?
bool LoadShaderFromFile(SHADER_TYPE aShaderType, const std::string &aShaderSourceName)
Load one of the built-in shaders and compiles it.
bool isProgramCreated
Flag for program creation.
std::deque< GLuint > shaderNumbers
Shader number list.
void SetParameter(int aParameterNumber, float aValue) const
Set a parameter of the shader.
GLuint geomInputType
Output type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.].
bool loadShaderFromStringArray(SHADER_TYPE aShaderType, const char **aArray, size_t aSize)
Compile vertex of fragment shader source code into the program.
std::deque< GLint > parameterLocation
Location of the parameter.
GLuint programNumber
Shader program number.
bool Link()
Link the shaders.
bool isShaderLinked
Is the shader linked?
void ConfigureGeometryShader(GLuint maxVertices, GLuint geometryInputType, GLuint geometryOutputType)
Configure the geometry shader - has to be done before linking!
bool LoadShaderFromStrings(SHADER_TYPE aShaderType, Args &&... aArgs)
Add a shader and compile the shader sources.
void shaderInfo(GLuint aShader)
Get the shader information.
void programInfo(GLuint aProgram)
Get the shader program information.
int AddParameter(const std::string &aParameterName)
Add a parameter to the parameter queue.
GLuint maximumVertices
The maximum of vertices to be generated.
int GetAttribute(const std::string &aAttributeName) const
Get an attribute location.
void Deactivate()
Deactivate the shader and use the default OpenGL program.
The Cairo implementation of the graphics abstraction layer.
SHADER_TYPE
Type definition for the shader.
@ SHADER_TYPE_GEOMETRY
Geometry shader.