fa2758de |
#ifndef GLSHADER_SHADER_HPP_
#define GLSHADER_SHADER_HPP_
|
772e8338 |
#include <map>
|
fa2758de |
#include <set>
#include <string>
#include <GL/glew.h>
class Shader
{
public:
using Paths = std::set<std::string>;
explicit Shader(Paths const & paths);
virtual ~Shader();
Shader(Shader &&) noexcept;
Shader(Shader const &) = delete;
Shader & operator=(Shader &&) = delete;
Shader & operator=(Shader const &) = delete;
|
772e8338 |
using Defines = std::map<std::string, std::string>;
|
30b3651e |
using Locations = std::map<std::string, GLuint>;
|
772e8338 |
|
fa2758de |
static void root(std::string const & root);
|
772e8338 |
static void defines(Defines const & defines);
|
30b3651e |
static void verts(Locations const & verts);
static void frags(Locations const & frags);
|
fa2758de |
GLuint program() const;
|
55f9c41b |
Shader & validate();
|
9a0c30b8 |
Shader & use();
|
55f9c41b |
|
fa2758de |
protected:
|
55f9c41b |
void validate_() const;
|
9a0c30b8 |
void current_(
std::string const & error
) const;
|
55f9c41b |
|
fa2758de |
GLuint program_;
std::string program_name_;
std::string static root_;
|
772e8338 |
Defines static defines_;
|
30b3651e |
Locations static verts_;
Locations static frags_;
|
fa2758de |
};
|
55f9c41b |
// Debug macros.
#ifndef NDEBUG
#define GLSHADER_DEBUG_(...) __VA_ARGS__
#else
#define GLSHADER_DEBUG_(...)
#endif // NDEBUG
|
fa2758de |
// Inline definitions.
#define GLSHADER_SET_(TYPE, NAME) \
inline void Shader::NAME(TYPE const & NAME) \
{ \
NAME##_ = NAME; \
}
GLSHADER_SET_(std::string, root)
|
772e8338 |
GLSHADER_SET_(Defines, defines)
|
30b3651e |
GLSHADER_SET_(Locations, verts)
GLSHADER_SET_(Locations, frags)
|
fa2758de |
inline GLuint Shader::program() const
{
return program_;
}
|
55f9c41b |
inline Shader & Shader::validate()
{
GLSHADER_DEBUG_(validate_();)
return *this;
}
|
9a0c30b8 |
inline Shader & Shader::use()
{
glUseProgram(program_);
return *this;
}
|
fa2758de |
#endif // GLSHADER_SHADER_HPP_
|