Instead take an object oriented approach.
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);
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);
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);
Shader &PostProcessor::get_fullscreen_vertex_shader()
{
- static Shader shader(VERTEX_SHADER, fullscreen_vs_source);
+ static VertexShader shader(fullscreen_vs_source);
return shader;
}
{
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();
}
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)
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()
void Program::Loader::vertex_shader(const string &src)
{
- obj.attach_shader_owned(new Shader(VERTEX_SHADER, src));
+ obj.attach_shader_owned(new VertexShader(src));
}
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);
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);
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
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);
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