Distributed under the LGPL
*/
-#define GL_GLEXT_PROTOTYPES
+#include "arb_shader_objects.h"
+#include "except.h"
+#include "extension.h"
#include "shader.h"
using namespace std;
Shader::Shader(ShaderType t)
{
- id=glCreateShader(t);
+ init(t);
+}
+
+Shader::Shader(ShaderType t, const string &src)
+{
+ init(t);
+
+ source(src);
+ compile();
+}
+
+void Shader::init(ShaderType t)
+{
+ compiled = false;
+
+ if(t==FRAGMENT_SHADER)
+ static RequireExtension _ext("GL_ARB_fragment_shader");
+ else if(t==VERTEX_SHADER)
+ static RequireExtension _ext("GL_ARB_vertex_shader");
+
+ id = glCreateShaderObjectARB(t);
}
Shader::~Shader()
{
- glDeleteShader(id);
+ glDeleteObjectARB(id);
}
-void Shader::source(sizei count, const char **str, const int *len)
+void Shader::source(unsigned count, const char **str, const int *len)
{
- glShaderSource(id, count, str, len);
+ glShaderSourceARB(id, count, str, len);
}
void Shader::source(const string &str)
source(1, &str, &len);
}
-bool Shader::compile()
+void Shader::compile()
{
- glCompileShader(id);
- compiled=get_param(GL_COMPILE_STATUS);
- return compiled;
+ glCompileShaderARB(id);
+ if(!(compiled = get_param(GL_COMPILE_STATUS)))
+ throw CompileError(get_info_log());
}
int Shader::get_param(GLenum param) const
{
int value;
- glGetShaderiv(id, param, &value);
+ glGetObjectParameterivARB(id, param, &value);
return value;
}
string Shader::get_info_log() const
{
- sizei len=get_param(GL_INFO_LOG_LENGTH);
+ GLsizei len = get_param(GL_INFO_LOG_LENGTH);
char log[len+1];
- glGetShaderInfoLog(id, len+1, reinterpret_cast<GLsizei *>(&len), log);
+ glGetInfoLogARB(id, len+1, &len, log);
return string(log, len);
}