1 #include <msp/gl/extensions/arb_fragment_shader.h>
2 #include <msp/gl/extensions/arb_shader_objects.h>
3 #include <msp/gl/extensions/arb_vertex_shader.h>
13 Shader::Shader(GLenum t)
18 Shader::Shader(GLenum t, const string &src)
26 void Shader::init(GLenum t)
30 if(t==GL_FRAGMENT_SHADER)
31 static Require _req(ARB_fragment_shader);
32 else if(t==GL_VERTEX_SHADER)
33 static Require _req(ARB_vertex_shader);
35 id = glCreateShader(t);
43 void Shader::source(unsigned count, const char **str, const int *len)
45 glShaderSource(id, count, str, len);
48 void Shader::source(const string &str)
50 source(str.data(), str.size());
53 void Shader::source(const char *str, int len)
55 source(1, &str, &len);
58 void Shader::compile()
61 compiled = get_shader_i(id, GL_COMPILE_STATUS);
63 throw compile_error(get_info_log());
66 string Shader::get_info_log() const
68 GLsizei len = get_shader_i(id, GL_INFO_LOG_LENGTH);
69 char *buf = new char[len+1];
70 glGetShaderInfoLog(id, len+1, &len, buf);
77 VertexShader::VertexShader():
78 Shader(GL_VERTEX_SHADER)
81 VertexShader::VertexShader(const string &src):
82 Shader(GL_VERTEX_SHADER, src)
86 FragmentShader::FragmentShader():
87 Shader(GL_FRAGMENT_SHADER)
90 FragmentShader::FragmentShader(const string &src):
91 Shader(GL_FRAGMENT_SHADER, src)