23 if (vertex_shader[0] ==
'#') itsVertexShader.
set(
"vertex", vertex_shader, GL_VERTEX_SHADER);
24 else itsVertexShader.
load(vertex_shader, GL_VERTEX_SHADER);
26 if (fragment_shader[0] ==
'#') itsFragmentShader.
set(
"fragment", fragment_shader, GL_FRAGMENT_SHADER);
27 else itsFragmentShader.
load(fragment_shader, GL_FRAGMENT_SHADER);
29 itsId = glCreateProgram();
30 GL_CHECK(glAttachShader(itsId, itsVertexShader.
id()));
31 GL_CHECK(glAttachShader(itsId, itsFragmentShader.
id()));
34 LDEBUG(
"GPU program " << itsId <<
" created.");
51 glDetachShader(itsId, itsVertexShader.id());
52 glDetachShader(itsId, itsFragmentShader.id());
53 glDeleteProgram(itsId);
#define GL_CHECK(stmt)
Simple macro to check for OpenGL errors.
GPUprogram(char const *vertex_shader, char const *fragment_shader)
Constructor, loads and compiles the program, assigns it a program ID.
GLuint id() const
Get the program ID so we can tell OpenGL to use this program.
~GPUprogram()
Destructor, deletes the program from OpenGL and frees up the ID.
void load(char const *filename, GLuint type)
Load a shader from file.
void set(char const *name, char const *str, GLuint type)
Load a shader from inlined code in a C-string.
GLuint id() const
Get the shader's ID.
#define LDEBUG(msg)
Convenience macro for users to print out console or syslog messages, DEBUG level.