00001 #pragma once
00002
00003 #include "Vis.hpp"
00004
00008 class Shader
00009 {
00013 std::string vertex_source;
00014
00018 std::string fragment_source;
00019
00023 GLuint vertex_shader;
00024
00028 GLuint fragment_shader;
00029
00033 GLuint program;
00034
00035 public:
00036
00044 Shader(std::string file_name);
00045
00046 ~Shader();
00047
00051 void print_fragment_source();
00052
00056 void print_vertex_source();
00057
00061 void use();
00062
00066 void free();
00067
00071 void print_info()
00072 {
00073 std::cout << program << " " << vertex_shader << " " << fragment_shader << std::endl;
00074 }
00075
00079 void release()
00080 {
00081 glUseProgram(0);
00082 };
00083
00088 GLint get_attribute_location(std::string name)
00089 {
00090 return glGetAttribLocation(program, name.c_str());
00091 }
00092
00098 void set_uniform(const char* uniform, GLint value)
00099 {
00100 GLint uniformLocation = glGetUniformLocation(program, uniform);
00101 glUniform1i(uniformLocation, value);
00102 };
00103
00109 void set_uniform(const char* uniform, GLfloat value)
00110 {
00111 GLint uniformLocation = glGetUniformLocation(program, uniform);
00112 glUniform1f(uniformLocation, value);
00113 };
00114
00120 void set_uniform(const char* uniform, const Color4f &color)
00121 {
00122 GLint uniformLocation = glGetUniformLocation(program, uniform);
00123 glUniform4fv(uniformLocation, 1, (GLfloat*)&color);
00124 };
00125
00131 void set_uniform(const char* uniform, const V2f &vector)
00132 {
00133 GLint uniformLocation = glGetUniformLocation(program, uniform);
00134 glUniform2fv(uniformLocation, 1, (GLfloat*)&vector);
00135 };
00136
00142 void set_uniform(const char* uniform, const V3f &vector)
00143 {
00144 GLint uniformLocation = glGetUniformLocation(program, uniform);
00145 glUniform3fv(uniformLocation, 1, (GLfloat*)&vector);
00146 };
00147
00153 void set_uniform(const char* uniform, const M44f &matrix)
00154 {
00155 GLint uniformLocation = glGetUniformLocation(program, uniform);
00156 glUniformMatrix4fv(uniformLocation, 1, GL_FALSE, (GLfloat*)&matrix);
00157 };
00158
00164 void set_uniform1(const char* uniform, float *elements, int count)
00165 {
00166 GLint uniformLocation = glGetUniformLocation(program, uniform);
00167 glUniform1fv(uniformLocation, count, elements);
00168 };
00169
00175 void set_uniform2(const char* uniform, float *elements, int count)
00176 {
00177 GLint uniformLocation = glGetUniformLocation(program, uniform);
00178 glUniform2fv(uniformLocation, count, elements);
00179 };
00180
00186 void set_uniform3(const char* uniform, float *elements, int count)
00187 {
00188 GLint uniformLocation = glGetUniformLocation(program, uniform);
00189 glUniform3fv(uniformLocation, count, elements);
00190 };
00191
00197 void set_uniform4(const char* uniform, float *elements, int count)
00198 {
00199 GLint uniformLocation = glGetUniformLocation(program, uniform);
00200 glUniform4fv(uniformLocation, count, elements);
00201 };
00202
00203 };