GLS  1.0.0
GL Stuff - A library aimed at reducing the boilerplate OpenGL code you always have to write.
shader< Type > Class Template Reference

Class encapsulating an OpenGL shader object. More...

#include <shader.hpp>

Public Member Functions

GLuint name () const
 Retrieve the OpenGL name of this shader. More...
 
bool compile (const std::string &source)
 Compile this shader from the given source. More...
 
std::string get_info_log () const
 Get the link information log. More...
 

Detailed Description

template<GLenum Type>
class gls::shader< Type >

Class encapsulating an OpenGL shader object.

A gls::shader is an object that encapsulates an OpenGL shader object.

Template Parameters
TypeThe type of this shader (e.g. GL_VERTEX_SHADER, GL_FRAGMENT_SHADER, etc.)

It is used along with other gls::shader objects as part of a gls::program object. Like all objects in GLS, the underlying name is generated at object construction and deleted at destruction. This can be retrieved with name().

In order to link a gls::shader object with other gls::shader objects as part of a gls::program, you need to have successfully compiled them all. If compiling fails, you can check the information log for the cause.

Example usage:

auto vertex_shader = gls::shader<GL_VERTEX_SHADER>();
if( !vertex_shader.compile( R"(
#version 150 core
in vec3 position;
void main() {
gl_Position = vec4( position, 1.0 );
}
)" ) ) {
... vertex shader failed to compile ...
}
auto fragment_shader = gls::shader<GL_FRAGMENT_SHADER>();
if( !fragment_shader.compile( R"(
#version 150 core
out vec4 frag_color;
void main() {
frag_color = vec4( 1.0, 1.0, 1.0, 1.0 );
}
)" ) ) {
... fragment shader failed to compile ...
}
auto program = gls::program();
if( !program.link( vertex_shader, fragment_shader ) ) {
... program failed to link ...
}

Member Function Documentation

GLuint name ( ) const

Retrieve the OpenGL name of this shader.

Returns
OpenGL name of this shader
bool compile ( const std::string &  source)

Compile this shader from the given source.

This will attempt to compile the shader using the given source. Checking the produced information log with get_info_log() can help to solve errors that occur or warnings the driver might have produced.

After successfully compiling a set of shaders, link them into a gls::program object in order to use them as part of the program.

Parameters
sourceString containing the source to compile
Returns
true if compiling was successful, false otherwise
std::string get_info_log ( ) const

Get the link information log.

After compiling, whether successful or not, an information log might be available. Check this information log for warnings after successful compiling, or errors after failed compiling. The information log may be empty if compiling was successful.

Returns
String containing the information log