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)
30 static Require _req_base(ARB_shader_objects);
33 if(t==GL_FRAGMENT_SHADER)
34 static Require _req(ARB_fragment_shader);
35 else if(t==GL_VERTEX_SHADER)
36 static Require _req(ARB_vertex_shader);
37 else if(t==GL_GEOMETRY_SHADER)
38 static Require _req(ARB_geometry_shader4);
40 id = glCreateShader(t);
48 void Shader::source(unsigned count, const char **str, const int *len)
50 glShaderSource(id, count, str, len);
53 void Shader::source(const string &str)
55 source(str.data(), str.size());
58 void Shader::source(const char *str, int len)
60 source(1, &str, &len);
63 void Shader::compile()
66 compiled = get_shader_i(id, GL_COMPILE_STATUS);
68 throw compile_error(get_info_log());
71 string info_log = get_info_log();
73 IO::print("Shader compile info log:\n%s", info_log);
77 string Shader::get_info_log() const
79 GLsizei len = get_shader_i(id, GL_INFO_LOG_LENGTH);
81 glGetShaderInfoLog(id, len+1, &len, &log[0]);
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)