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);
80 char *buf = new char[len+1];
81 glGetShaderInfoLog(id, len+1, &len, buf);
88 VertexShader::VertexShader():
89 Shader(GL_VERTEX_SHADER)
92 VertexShader::VertexShader(const string &src):
93 Shader(GL_VERTEX_SHADER, src)
97 FragmentShader::FragmentShader():
98 Shader(GL_FRAGMENT_SHADER)
101 FragmentShader::FragmentShader(const string &src):
102 Shader(GL_FRAGMENT_SHADER, src)
106 GeometryShader::GeometryShader():
107 Shader(GL_GEOMETRY_SHADER)
110 GeometryShader::GeometryShader(const string &src):
111 Shader(GL_GEOMETRY_SHADER, src)