X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fshader.cpp;h=967ac8a624dc63f92248dc7f604b99c44fe73c79;hp=61c2f0e56b0e7125bed8df5f0d9dad32c6ce736e;hb=f14435e58bfa0fa697a06ba9a454bb30cd37d9d8;hpb=3f285d3f4fd0a6790bf1efa780284dc7ba2287a2 diff --git a/source/shader.cpp b/source/shader.cpp index 61c2f0e5..967ac8a6 100644 --- a/source/shader.cpp +++ b/source/shader.cpp @@ -1,11 +1,6 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -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; @@ -13,27 +8,39 @@ using namespace std; namespace Msp { namespace GL { -Shader::Shader(ShaderType t): - id(glCreateShader(t)), - compiled(false) -{ } +Shader::Shader(ShaderType t) +{ + init(t); +} -Shader::Shader(ShaderType t, const string &src): - id(glCreateShader(t)), - compiled(false) +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) @@ -46,25 +53,21 @@ void Shader::source(const char *str, int len) source(1, &str, &len); } -bool Shader::compile() -{ - glCompileShader(id); - compiled=get_param(GL_COMPILE_STATUS); - return compiled; -} - -int Shader::get_param(GLenum param) const +void Shader::compile() { - int value; - glGetShaderiv(id, param, &value); - return value; + glCompileShaderARB(id); + int value = 0; + glGetObjectParameterivARB(id, GL_OBJECT_COMPILE_STATUS_ARB, &value); + if(!(compiled = value)) + throw CompileError(get_info_log()); } string Shader::get_info_log() const { - sizei len=get_param(GL_INFO_LOG_LENGTH); + GLsizei len = 0; + glGetObjectParameterivARB(id, GL_OBJECT_INFO_LOG_LENGTH_ARB, &len); char log[len+1]; - glGetShaderInfoLog(id, len+1, reinterpret_cast(&len), log); + glGetInfoLogARB(id, len+1, &len, log); return string(log, len); }