74 if( glIsShader( shader ) )
77 glDeleteShader( shader );
90 const std::string shaderSource =
ReadSource( aShaderSourceName );
97 GLuint geometryOutputType )
120 glGetProgramiv(
programNumber, GL_INFO_LOG_LENGTH, &maxLength );
121 maxLength = maxLength + 1;
122 char* linkInfoLog =
new char[maxLength];
123 glGetProgramInfoLog(
programNumber, maxLength, &maxLength, linkInfoLog );
124 std::cerr <<
"Shader linking error:" << std::endl;
125 std::cerr << linkInfoLog;
126 delete[] linkInfoLog;
141 throw std::runtime_error(
"Could not find shader uniform: " + aParameterName );
166 float arr[4] = { f0, f1, f2, f3 };
175 static_cast<GLfloat
>( aValue.
y ) );
181 return glGetAttribLocation(
programNumber, aAttributeName.c_str() );
187 GLint glInfoLogLength = 0;
188 GLint writtenChars = 0;
191 glGetProgramiv( aProgram, GL_INFO_LOG_LENGTH, &glInfoLogLength );
194 if( glInfoLogLength > 2 )
196 GLchar* glInfoLog =
new GLchar[glInfoLogLength];
197 glGetProgramInfoLog( aProgram, glInfoLogLength, &writtenChars, glInfoLog );
206 GLint glInfoLogLength = 0;
207 GLint writtenChars = 0;
210 glGetShaderiv( aShader, GL_INFO_LOG_LENGTH, &glInfoLogLength );
213 if( glInfoLogLength > 2 )
215 GLchar* glInfoLog =
new GLchar[glInfoLogLength];
216 glGetShaderInfoLog( aShader, glInfoLogLength, &writtenChars, glInfoLog );
226 std::ifstream inputFile( aShaderSourceName.c_str(), std::ifstream::in );
227 std::string shaderSource;
230 throw std::runtime_error(
"Can't read the shader source: " + aShaderSourceName );
232 std::string shaderSourceLine;
235 while( getline( inputFile, shaderSourceLine ) )
237 shaderSource += shaderSourceLine;
238 shaderSource +=
"\n";
257 GLuint shaderNumber = glCreateShader( aShaderType );
264 glShaderSource( shaderNumber,
static_cast<GLsizei
>( aSize ), (
const GLchar**) aArray,
nullptr );
268 glCompileShader( shaderNumber );
270 glGetShaderiv( shaderNumber, GL_COMPILE_STATUS, &status );
272 if( status != GL_TRUE )
277 glGetShaderiv( shaderNumber, GL_INFO_LOG_LENGTH, &maxLength );
280 std::vector<GLchar> errorLog( (
size_t) maxLength );
281 glGetShaderInfoLog( shaderNumber, maxLength, &maxLength, &errorLog[0] );
285 glDeleteShader( shaderNumber );
287 throw std::runtime_error( &errorLog[0] );
296 if( GLAD_GL_ARB_geometry_shader4 || GLAD_GL_EXT_geometry_shader4 )
GLuint geomOutputType
Output type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.].
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 Abandon()
Give up ownership of the program and shader objects without deleting them.
void SetParameter(int aParameterNumber, float aValue) const
Set a parameter of the shader.
GLuint geomInputType
Input 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.
VECTOR2< double > VECTOR2D