2016-02-07 22:32:38 +00:00
|
|
|
//
|
|
|
|
// Shader.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 07/02/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Shader_hpp
|
|
|
|
#define Shader_hpp
|
|
|
|
|
2016-02-08 00:21:22 +00:00
|
|
|
#include "OpenGL.hpp"
|
|
|
|
|
2016-02-07 22:32:38 +00:00
|
|
|
namespace OpenGL {
|
2016-04-20 00:53:55 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
A @c Shader compiles and holds a shader object, based on a single
|
|
|
|
vertex program and a single fragment program. Attribute bindings
|
|
|
|
may be supplied if desired.
|
|
|
|
*/
|
|
|
|
class Shader {
|
|
|
|
public:
|
|
|
|
enum {
|
|
|
|
VertexShaderCompilationError,
|
|
|
|
FragmentShaderCompilationError,
|
|
|
|
ProgramLinkageError
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AttributeBinding {
|
|
|
|
const GLchar *name;
|
|
|
|
GLuint index;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Attempts to compile a shader, throwing @c VertexShaderCompilationError, @c FragmentShaderCompilationError or @c ProgramLinkageError upon failure.
|
|
|
|
@param vertex_shader The vertex shader source code.
|
|
|
|
@param fragment_shader The fragment shader source code.
|
|
|
|
@param attribute_bindings Either @c nullptr or an array terminated by an entry with a @c nullptr-name of attribute bindings.
|
|
|
|
*/
|
|
|
|
Shader(const char *vertex_shader, const char *fragment_shader, const AttributeBinding *attribute_bindings);
|
|
|
|
~Shader();
|
|
|
|
|
|
|
|
/*!
|
2016-05-01 15:07:49 +00:00
|
|
|
Performs an @c glUseProgram to make this the active shader unless:
|
|
|
|
(i) it was the previous shader bound; and
|
|
|
|
(ii) no calls have been received to unbind in the interim.
|
2016-04-20 00:53:55 +00:00
|
|
|
*/
|
|
|
|
void bind();
|
|
|
|
|
2016-05-01 15:07:49 +00:00
|
|
|
/*!
|
|
|
|
Unbinds the current instance of Shader, if one is bound.
|
|
|
|
*/
|
|
|
|
static void unbind();
|
|
|
|
|
2016-04-20 00:53:55 +00:00
|
|
|
/*!
|
|
|
|
Performs a @c glGetAttribLocation call.
|
|
|
|
@param name The name of the attribute to locate.
|
|
|
|
@returns The location of the requested attribute.
|
|
|
|
*/
|
|
|
|
GLint get_attrib_location(const GLchar *name);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Performs a @c glGetUniformLocation call.
|
|
|
|
@param name The name of the uniform to locate.
|
|
|
|
@returns The location of the requested uniform.
|
|
|
|
*/
|
|
|
|
GLint get_uniform_location(const GLchar *name);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
GLuint compile_shader(const char *source, GLenum type);
|
|
|
|
GLuint _shader_program;
|
|
|
|
};
|
|
|
|
|
2016-02-07 22:32:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Shader_hpp */
|