1 #include <msp/gl/extensions/arb_fragment_shader.h>
2 #include <msp/gl/extensions/arb_geometry_shader4.h>
3 #include <msp/gl/extensions/arb_shader_objects.h>
4 #include <msp/gl/extensions/arb_vertex_shader.h>
5 #include <msp/io/print.h>
15 Shader::Shader(GLenum t)
20 Shader::Shader(GLenum t, const string &src)
28 void Shader::init(GLenum t)
32 if(t==GL_FRAGMENT_SHADER)
33 static Require _req(ARB_fragment_shader);
34 else if(t==GL_VERTEX_SHADER)
35 static Require _req(ARB_vertex_shader);
36 else if(t==GL_GEOMETRY_SHADER)
37 static Require _req(ARB_geometry_shader4);
39 id = glCreateShader(t);
47 void Shader::source(unsigned count, const char **str, const int *len)
49 glShaderSource(id, count, str, len);
52 void Shader::source(const string &str)
54 source(str.data(), str.size());
57 void Shader::source(const char *str, int len)
59 source(1, &str, &len);
62 void Shader::compile()
65 compiled = get_shader_i(id, GL_COMPILE_STATUS);
67 throw compile_error(get_info_log());
70 string info_log = get_info_log();
72 IO::print("Shader compile info log:\n%s", info_log);
76 string Shader::get_info_log() const
78 GLsizei len = get_shader_i(id, GL_INFO_LOG_LENGTH);
79 char *buf = new char[len+1];
80 glGetShaderInfoLog(id, len+1, &len, buf);
87 VertexShader::VertexShader():
88 Shader(GL_VERTEX_SHADER)
91 VertexShader::VertexShader(const string &src):
92 Shader(GL_VERTEX_SHADER, src)
96 FragmentShader::FragmentShader():
97 Shader(GL_FRAGMENT_SHADER)
100 FragmentShader::FragmentShader(const string &src):
101 Shader(GL_FRAGMENT_SHADER, src)
105 GeometryShader::GeometryShader():
106 Shader(GL_GEOMETRY_SHADER)
109 GeometryShader::GeometryShader(const string &src):
110 Shader(GL_GEOMETRY_SHADER, src)