initial glcxx development
This commit is contained in:
commit
f8af892c0d
9 files changed
+329
No files matched your search
@@ -0,0 +1,8 @@
|
||||
#ifndef GLCXX_HPP
|
||||
#define GLCXX_HPP
|
||||
|
||||
#include "glcxx/Buffer.hpp"
|
||||
#include "glcxx/Program.hpp"
|
||||
#include "glcxx/Shader.hpp"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef GLCXX_BUFFER_HPP
|
||||
#define GLCXX_BUFFER_HPP
|
||||
|
||||
#include "glcxx/gl.hpp"
|
||||
|
||||
namespace glcxx
|
||||
{
|
||||
class Buffer
|
||||
{
|
||||
public:
|
||||
Buffer();
|
||||
|
||||
~Buffer();
|
||||
|
||||
void create(GLenum target, GLenum usage, const void *ptr, size_t sz);
|
||||
|
||||
GLuint id() const { return m_id; }
|
||||
|
||||
void bind() const { glBindBuffer(m_target, m_id); }
|
||||
|
||||
bool valid() const { return m_id > 0u; }
|
||||
|
||||
protected:
|
||||
GLuint m_id;
|
||||
|
||||
GLenum m_target;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef GLCXX_ERROR_HPP
|
||||
#define GLCXX_ERROR_HPP
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace glcxx
|
||||
{
|
||||
|
||||
class Error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
Error(const std::string & msg) : std::runtime_error(msg)
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,73 @@
|
||||
#ifndef GLCXX_PROGRAM_HPP
|
||||
#define GLCXX_PROGRAM_HPP
|
||||
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include "glcxx/Shader.hpp"
|
||||
|
||||
namespace glcxx
|
||||
{
|
||||
class Program
|
||||
{
|
||||
public:
|
||||
Program();
|
||||
|
||||
~Program();
|
||||
|
||||
GLuint id() const { return m_id; }
|
||||
|
||||
void use() const { glUseProgram(m_id); }
|
||||
|
||||
bool valid() const { return m_id > 0u; }
|
||||
|
||||
template <typename... Shaders>
|
||||
void create(Shaders... shaders)
|
||||
{
|
||||
allocate();
|
||||
_create(shaders...);
|
||||
}
|
||||
|
||||
void attach_shader(const Shader & shader) const
|
||||
{
|
||||
glAttachShader(m_id, shader.id());
|
||||
}
|
||||
|
||||
void attach_shader(std::unique_ptr<Shader> shader) const
|
||||
{
|
||||
glAttachShader(m_id, shader->id());
|
||||
}
|
||||
|
||||
void attach_shader(std::shared_ptr<Shader> shader) const
|
||||
{
|
||||
glAttachShader(m_id, shader->id());
|
||||
}
|
||||
|
||||
void bind_attribute(const char * name, GLuint index) const
|
||||
{
|
||||
glBindAttribLocation(m_id, index, name);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void bind_attributes(const char * name, GLuint index, Args... args) const
|
||||
{
|
||||
bind_attribute(name, index);
|
||||
bind_attributes(args...);
|
||||
}
|
||||
|
||||
protected:
|
||||
void allocate();
|
||||
|
||||
void _create() const;
|
||||
|
||||
template <typename T, typename... Shaders>
|
||||
void _create(T shader, Shaders... args) const
|
||||
{
|
||||
attach_shader(shader);
|
||||
_create(args...);
|
||||
}
|
||||
|
||||
GLuint m_id;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef GLCXX_SHADER_HPP
|
||||
#define GLCXX_SHADER_HPP
|
||||
|
||||
#include "glcxx/gl.hpp"
|
||||
|
||||
namespace glcxx
|
||||
{
|
||||
class Shader
|
||||
{
|
||||
public:
|
||||
Shader();
|
||||
|
||||
~Shader();
|
||||
|
||||
void create(GLenum shaderType, const char *source);
|
||||
|
||||
GLuint id() const { return m_id; }
|
||||
|
||||
bool valid() const { return m_id > 0u; }
|
||||
|
||||
protected:
|
||||
GLuint m_id;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef GLCXX_GL_HPP
|
||||
#define GLCXX_GL_HPP
|
||||
|
||||
#ifdef GLCXX_GL_INCLUDE
|
||||
#include GLCXX_GL_INCLUDE
|
||||
#else
|
||||
#include "GL/gl.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user