3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include "arb_shader_objects.h"
10 #include "extension.h"
18 Shader::Shader(ShaderType t)
23 Shader::Shader(ShaderType t, const string &src)
31 void Shader::init(ShaderType t)
35 if(t==FRAGMENT_SHADER)
36 static RequireExtension _ext("GL_ARB_fragment_shader");
37 else if(t==VERTEX_SHADER)
38 static RequireExtension _ext("GL_ARB_vertex_shader");
40 id=glCreateShaderObjectARB(t);
45 glDeleteObjectARB(id);
48 void Shader::source(sizei count, const char **str, const int *len)
50 glShaderSourceARB(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()
65 glCompileShaderARB(id);
66 if(!(compiled=get_param(GL_COMPILE_STATUS)))
67 throw CompileError(get_info_log());
70 int Shader::get_param(GLenum param) const
73 glGetObjectParameterivARB(id, param, &value);
77 string Shader::get_info_log() const
79 sizei len=get_param(GL_INFO_LOG_LENGTH);
81 glGetInfoLogARB(id, len+1, reinterpret_cast<GLsizei *>(&len), log);
82 return string(log, len);