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);
49 void Shader::source(unsigned count, const char **str, const int *len)
51 glShaderSource(id, count, str, len);
54 void Shader::source(const string &str)
56 source(str.data(), str.size());
59 void Shader::source(const char *str, int len)
61 source(1, &str, &len);
64 void Shader::compile()
67 compiled = get_shader_i(id, GL_COMPILE_STATUS);
69 throw compile_error(get_info_log());
72 string info_log = get_info_log();
74 IO::print("Shader compile info log:\n%s", info_log);
78 unsigned Shader::steal_id()
85 string Shader::get_info_log() const
87 GLsizei len = get_shader_i(id, GL_INFO_LOG_LENGTH);
89 glGetShaderInfoLog(id, len+1, &len, &log[0]);
95 VertexShader::VertexShader():
96 Shader(GL_VERTEX_SHADER)
99 VertexShader::VertexShader(const string &src):
100 Shader(GL_VERTEX_SHADER, src)
104 FragmentShader::FragmentShader():
105 Shader(GL_FRAGMENT_SHADER)
108 FragmentShader::FragmentShader(const string &src):
109 Shader(GL_FRAGMENT_SHADER, src)
113 GeometryShader::GeometryShader():
114 Shader(GL_GEOMETRY_SHADER)
117 GeometryShader::GeometryShader(const string &src):
118 Shader(GL_GEOMETRY_SHADER, src)