]> git.tdb.fi Git - libs/gl.git/commitdiff
Don't expose the shader type enum
authorMikko Rasa <tdb@tdb.fi>
Tue, 28 Aug 2012 10:34:09 +0000 (13:34 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 28 Aug 2012 10:34:09 +0000 (13:34 +0300)
Instead take an object oriented approach.

source/ambientocclusion.cpp
source/bloom.cpp
source/colorcurve.cpp
source/postprocessor.cpp
source/program.cpp
source/shader.cpp
source/shader.h

index e22e039159a39b1b57927c77aa47a4053f916080..de937cf6f359b5b138aaabeec6c0fd4ffeccf4ae 100644 (file)
@@ -69,11 +69,11 @@ AmbientOcclusion::AmbientOcclusion(unsigned w, unsigned h, float depth_ratio):
        quad(get_fullscreen_quad())
 {
        occlude_shader.attach_shader(get_fullscreen_vertex_shader());
-       occlude_shader.attach_shader_owned(new Shader(FRAGMENT_SHADER, occlude_fs));
+       occlude_shader.attach_shader_owned(new FragmentShader(occlude_fs));
        occlude_shader.link();
 
        combine_shader.attach_shader(get_fullscreen_vertex_shader());
-       combine_shader.attach_shader_owned(new Shader(FRAGMENT_SHADER, combine_fs));
+       combine_shader.attach_shader_owned(new FragmentShader(combine_fs));
        combine_shader.link();
 
        occlusion.storage(GL::RGB, w, h);
index 8a6ddbcd73b9ebda371518ded5a4a96502c5d5e8..b73ea16079622cf34013ff88739be77c94b4852b 100644 (file)
@@ -43,11 +43,11 @@ Bloom::Bloom(unsigned w, unsigned h):
        quad(get_fullscreen_quad())
 {
        blur_shader.attach_shader(get_fullscreen_vertex_shader());
-       blur_shader.attach_shader_owned(new Shader(FRAGMENT_SHADER, blur_fs));
+       blur_shader.attach_shader_owned(new FragmentShader(blur_fs));
        blur_shader.link();
 
        combine_shader.attach_shader(get_fullscreen_vertex_shader());
-       combine_shader.attach_shader_owned(new Shader(FRAGMENT_SHADER, combine_fs));
+       combine_shader.attach_shader_owned(new FragmentShader(combine_fs));
        combine_shader.link();
 
        blur_shdata[0].uniform("delta", 1.0f/w, 0.0f);
index 95c82491740765bfe47d9f18dbe7e33ef0adfeaf..d008593e047a0c2f9fed620471dcdea1057d794c 100644 (file)
@@ -43,8 +43,7 @@ ColorCurve::ColorCurve():
        quad(get_fullscreen_quad())
 {
        shprog.attach_shader(get_fullscreen_vertex_shader());
-       Shader *fs = new Shader(FRAGMENT_SHADER, fragment_src);
-       shprog.attach_shader_owned(fs);
+       shprog.attach_shader_owned(new FragmentShader(fragment_src));
        shprog.link();
 
        set_peak(0.2);
index add8b1ed1055daf5527cc34ed32331ba15be84e4..6c9408cb00db48772d361bfa8b5754338ea00c30 100644 (file)
@@ -21,7 +21,7 @@ namespace GL {
 
 Shader &PostProcessor::get_fullscreen_vertex_shader()
 {
-       static Shader shader(VERTEX_SHADER, fullscreen_vs_source);
+       static VertexShader shader(fullscreen_vs_source);
        return shader;
 }
 
index 729018a1a4b1edc69438d426c32426e82b19b09b..84b3cdd16f4e5e2f6fdfbca6c07f812917f3f07d 100644 (file)
@@ -128,8 +128,8 @@ Program::Program(const string &vert, const string &frag)
 {
        init();
 
-       attach_shader_owned(new Shader(VERTEX_SHADER, vert));
-       attach_shader_owned(new Shader(FRAGMENT_SHADER, frag));
+       attach_shader_owned(new VertexShader(vert));
+       attach_shader_owned(new FragmentShader(frag));
        link();
 }
 
@@ -179,8 +179,8 @@ void Program::add_standard_shaders(const StandardFeatures &features)
        string flags = features.create_flags();
        string vertex_src = process_standard_source(standard_vertex_src, flags);
        string fragment_src = process_standard_source(standard_fragment_src, flags);
-       attach_shader_owned(new Shader(VERTEX_SHADER, vertex_src));
-       attach_shader_owned(new Shader(FRAGMENT_SHADER, fragment_src));
+       attach_shader_owned(new VertexShader(vertex_src));
+       attach_shader_owned(new FragmentShader(fragment_src));
 }
 
 string Program::process_standard_source(const char **source, const string &flags)
@@ -477,7 +477,7 @@ void Program::Loader::attribute(unsigned i, const string &n)
 
 void Program::Loader::fragment_shader(const string &src)
 {
-       obj.attach_shader_owned(new Shader(FRAGMENT_SHADER, src));
+       obj.attach_shader_owned(new FragmentShader(src));
 }
 
 void Program::Loader::standard()
@@ -489,7 +489,7 @@ void Program::Loader::standard()
 
 void Program::Loader::vertex_shader(const string &src)
 {
-       obj.attach_shader_owned(new Shader(VERTEX_SHADER, src));
+       obj.attach_shader_owned(new VertexShader(src));
 }
 
 
index b0cf5a3ec63d3f6ed93c4727b955f5a187232ad3..0da1a6e9df448028cc9518e23c12207dbf751723 100644 (file)
@@ -9,12 +9,12 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-Shader::Shader(ShaderType t)
+Shader::Shader(GLenum t)
 {
        init(t);
 }
 
-Shader::Shader(ShaderType t, const string &src)
+Shader::Shader(GLenum t, const string &src)
 {
        init(t);
 
@@ -22,13 +22,13 @@ Shader::Shader(ShaderType t, const string &src)
        compile();
 }
 
-void Shader::init(ShaderType t)
+void Shader::init(GLenum t)
 {
        compiled = false;
 
-       if(t==FRAGMENT_SHADER)
+       if(t==GL_FRAGMENT_SHADER)
                static Require _req(ARB_fragment_shader);
-       else if(t==VERTEX_SHADER)
+       else if(t==GL_VERTEX_SHADER)
                static Require _req(ARB_vertex_shader);
 
        id = glCreateShader(t);
@@ -74,5 +74,23 @@ string Shader::get_info_log() const
        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)
+{ }
+
 } // namespace GL
 } // namespace Msp
index c1fd6b2294a47c57c38b62ce9aa41241c19bc9c6..63af9b3ab74862c10fb417b68bdaa18786c8e9b9 100644 (file)
@@ -7,25 +7,19 @@
 namespace Msp {
 namespace GL {
 
-enum ShaderType
-{
-       FRAGMENT_SHADER = GL_FRAGMENT_SHADER_ARB,
-       VERTEX_SHADER   = GL_VERTEX_SHADER_ARB
-};
-
 class Shader
 {
 private:
        unsigned id;
        bool compiled;
 
-public:
-       Shader(ShaderType t);
-       Shader(ShaderType t, const std::string &);
+protected:
+       Shader(GLenum t);
+       Shader(GLenum t, const std::string &);
 private:
-       void init(ShaderType);
+       void init(GLenum);
 public:
-       ~Shader();
+       virtual ~Shader();
 
        void source(unsigned count, const char **str, const int *len);
        void source(const std::string &str);
@@ -36,6 +30,22 @@ public:
        std::string get_info_log() const;
 };
 
+
+class VertexShader: public Shader
+{
+public:
+       VertexShader();
+       VertexShader(const std::string &);
+};
+
+
+class FragmentShader: public Shader
+{
+public:
+       FragmentShader();
+       FragmentShader(const std::string &);
+};
+
 } // namespace GL
 } // namespace Msp