]> git.tdb.fi Git - libs/gl.git/blobdiff - source/shader.cpp
Remove the deprecated ProgramBuilder class
[libs/gl.git] / source / shader.cpp
index 1b3455f1aa91270c810d0494ac80c3e80b7fe051..02dcc0dcff789fe142f9b47d4bde5ad2e48fe7fa 100644 (file)
@@ -1,6 +1,8 @@
 #include <msp/gl/extensions/arb_fragment_shader.h>
+#include <msp/gl/extensions/arb_geometry_shader4.h>
 #include <msp/gl/extensions/arb_shader_objects.h>
 #include <msp/gl/extensions/arb_vertex_shader.h>
+#include <msp/io/print.h>
 #include "error.h"
 #include "misc.h"
 #include "shader.h"
@@ -25,12 +27,15 @@ Shader::Shader(GLenum t, const string &src)
 
 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);
 }
@@ -61,15 +66,20 @@ void Shader::compile()
        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
 }
 
 string Shader::get_info_log() const
 {
        GLsizei len = get_shader_i(id, GL_INFO_LOG_LENGTH);
-       char *buf = new char[len+1];
-       glGetShaderInfoLog(id, len+1, &len, buf);
-       string log(buf, len);
-       delete[] buf;
+       string log(len+1, 0);
+       glGetShaderInfoLog(id, len+1, &len, &log[0]);
+       log.erase(len);
        return log;
 }
 
@@ -91,5 +101,14 @@ 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