X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fshader.cpp;fp=source%2Fcore%2Fshader.cpp;h=0000000000000000000000000000000000000000;hb=6065f6622cc275dc0b20baaf7c267e71169d18f3;hp=9950e4970e913a7aba25aed333ecb044c7c8bdc3;hpb=c4aeeced7b397d46772577775bd3a0d6c4706cba;p=libs%2Fgl.git diff --git a/source/core/shader.cpp b/source/core/shader.cpp deleted file mode 100644 index 9950e497..00000000 --- a/source/core/shader.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include -#include -#include -#include -#include -#include "error.h" -#include "misc.h" -#include "shader.h" - -using namespace std; - -namespace Msp { -namespace GL { - -Shader::Shader(GLenum t) -{ - init(t); -} - -Shader::Shader(GLenum t, const string &src) -{ - init(t); - - source(src); - compile(); -} - -void Shader::init(GLenum t) -{ - static Require _req_base(ARB_shader_objects); - compiled = false; - - if(t==GL_FRAGMENT_SHADER) - static Require _req(ARB_fragment_shader); - else if(t==GL_VERTEX_SHADER) - static Require _req(ARB_vertex_shader); - else if(t==GL_GEOMETRY_SHADER) - static Require _req(ARB_geometry_shader4); - - id = glCreateShader(t); -} - -Shader::~Shader() -{ - if(id) - glDeleteShader(id); -} - -void Shader::source(unsigned count, const char **str, const int *len) -{ - glShaderSource(id, count, str, len); -} - -void Shader::source(const string &str) -{ - source(str.data(), str.size()); -} - -void Shader::source(const char *str, int len) -{ - source(1, &str, &len); -} - -void Shader::compile() -{ - glCompileShader(id); - compiled = get_shader_i(id, GL_COMPILE_STATUS); - if(!compiled) - throw compile_error(get_info_log()); - -#ifdef DEBUG - string info_log = get_info_log(); - if(!info_log.empty()) - IO::print("Shader compile info log:\n%s", info_log); -#endif -} - -unsigned Shader::steal_id() -{ - unsigned result = id; - id = 0; - return result; -} - -string Shader::get_info_log() const -{ - GLsizei len = get_shader_i(id, GL_INFO_LOG_LENGTH); - string log(len+1, 0); - glGetShaderInfoLog(id, len+1, &len, &log[0]); - log.erase(len); - return log; -} - - -VertexShader::VertexShader(): - Shader(GL_VERTEX_SHADER) -{ } - -VertexShader::VertexShader(const string &src): - Shader(GL_VERTEX_SHADER, src) -{ } - - -FragmentShader::FragmentShader(): - Shader(GL_FRAGMENT_SHADER) -{ } - -FragmentShader::FragmentShader(const string &src): - Shader(GL_FRAGMENT_SHADER, src) -{ } - - -GeometryShader::GeometryShader(): - Shader(GL_GEOMETRY_SHADER) -{ } - -GeometryShader::GeometryShader(const string &src): - Shader(GL_GEOMETRY_SHADER, src) -{ } - -} // namespace GL -} // namespace Msp