Files
openglplayground/shaders.hh

93 lines
1.7 KiB
C++

#ifndef __OPENGLPLAYGROUND_SHADERS_HH__
#define __OPENGLPLAYGROUND_SHADERS_HH__
#include <string>
#include <unordered_map>
#include <glbinding/gl/types.h>
#include "common.hh"
class ShaderException : public GLException {
public:
ShaderException(std::string const& msg);
//~ShaderException() {}
std::string const& getMsg() const {return _msg;}
std::string toString() const override {
return "ShaderException: " + _msg;
}
private:
std::string _msg;
};
class Program;
class Shader {
public:
Shader() : _shaderID(0) {
}
protected:
Shader(std::string const& program, gl::GLenum type);
public:
virtual ~Shader();
unsigned getID() const {
return _shaderID;
}
protected:
unsigned int _shaderID;
};
class VertexShader : public Shader {
public:
VertexShader(std::string const& program) : Shader(program, GL_VERTEX_SHADER) {
}
};
class FragmentShader : public Shader {
public:
FragmentShader(std::string const& program) : Shader(program, GL_FRAGMENT_SHADER) {
}
};
class GeometryShader : public Shader {
public:
GeometryShader(std::string const& program) : Shader(program, GL_GEOMETRY_SHADER) {
}
};
class Program {
public:
Program(VertexShader& vertex, FragmentShader& frag);
Program(GeometryShader& geom, VertexShader& vertex, FragmentShader& frag);
~Program();
void use() const;
gl::GLint getUniformLocation(std::string const& name) const;
gl::GLint getAttribLocation(std::string const& name) const;
private:
GeometryShader* _geom;
VertexShader& _vertex;
FragmentShader& _frag;
unsigned _progID;
mutable std::unordered_map<std::string, gl::GLint> _uniformLocCache, _attribLocCache;
};
#endif