66 if( glIsShader( shader ) )
69 glDeleteShader( shader );
82 const std::string shaderSource =
ReadSource( aShaderSourceName );
89 GLuint geometryOutputType )
112 glGetProgramiv(
programNumber, GL_INFO_LOG_LENGTH, &maxLength );
113 maxLength = maxLength + 1;
114 char* linkInfoLog =
new char[maxLength];
115 glGetProgramInfoLog(
programNumber, maxLength, &maxLength, linkInfoLog );
116 std::cerr <<
"Shader linking error:" << std::endl;
117 std::cerr << linkInfoLog;
118 delete[] linkInfoLog;
133 throw std::runtime_error(
"Could not find shader uniform: " + aParameterName );
158 float arr[4] = { f0, f1, f2, f3 };
167 static_cast<GLfloat
>( aValue.
y ) );
173 return glGetAttribLocation(
programNumber, aAttributeName.c_str() );
179 GLint glInfoLogLength = 0;
180 GLint writtenChars = 0;
183 glGetProgramiv( aProgram, GL_INFO_LOG_LENGTH, &glInfoLogLength );
186 if( glInfoLogLength > 2 )
188 GLchar* glInfoLog =
new GLchar[glInfoLogLength];
189 glGetProgramInfoLog( aProgram, glInfoLogLength, &writtenChars, glInfoLog );
198 GLint glInfoLogLength = 0;
199 GLint writtenChars = 0;
202 glGetShaderiv( aShader, GL_INFO_LOG_LENGTH, &glInfoLogLength );
205 if( glInfoLogLength > 2 )
207 GLchar* glInfoLog =
new GLchar[glInfoLogLength];
208 glGetShaderInfoLog( aShader, glInfoLogLength, &writtenChars, glInfoLog );
218 std::ifstream inputFile( aShaderSourceName.c_str(), std::ifstream::in );
219 std::string shaderSource;
222 throw std::runtime_error(
"Can't read the shader source: " + aShaderSourceName );
224 std::string shaderSourceLine;
227 while( getline( inputFile, shaderSourceLine ) )
229 shaderSource += shaderSourceLine;
230 shaderSource +=
"\n";
249 GLuint shaderNumber = glCreateShader( aShaderType );
256 glShaderSource( shaderNumber,
static_cast<GLsizei
>( aSize ), (
const GLchar**) aArray,
nullptr );
260 glCompileShader( shaderNumber );
262 glGetShaderiv( shaderNumber, GL_COMPILE_STATUS, &status );
264 if( status != GL_TRUE )
269 glGetShaderiv( shaderNumber, GL_INFO_LOG_LENGTH, &maxLength );
272 std::vector<GLchar> errorLog( (
size_t) maxLength );
273 glGetShaderInfoLog( shaderNumber, maxLength, &maxLength, &errorLog[0] );
277 glDeleteShader( shaderNumber );
279 throw std::runtime_error( &errorLog[0] );
288 if( GLAD_GL_ARB_geometry_shader4 || GLAD_GL_EXT_geometry_shader4 )
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.
VECTOR2< double > VECTOR2D