add initial Array class

This commit is contained in:
josh committed 2015-06-11 21:24:06 -04:00
1 parent e9cdd72ffc
commit f8de8368bb
3 files changed
+61 -1

No files matched your search

+2 -1
View File
@@ -1,9 +1,10 @@
#ifndef GLCXX_HPP
#define GLCXX_HPP
#include "glcxx/Array.hpp"
#include "glcxx/Buffer.hpp"
#include "glcxx/Error.hpp"
#include "glcxx/Program.hpp"
#include "glcxx/Shader.hpp"
#include "glcxx/Error.hpp"
#endif
+31
View File
@@ -0,0 +1,31 @@
#ifndef GLCXX_ARRAY_HPP
#define GLCXX_ARRAY_HPP
#include "glcxx/gl.hpp"
namespace glcxx
{
class Array
{
public:
Array();
~Array();
void create();
void bind()
{
glBindVertexArray(m_id);
}
GLuint id() const { return m_id; }
bool valid() const { return m_id > 0u; }
protected:
GLuint m_id;
};
};
#endif
+28
View File
@@ -0,0 +1,28 @@
#include "glcxx/Array.hpp"
#include "glcxx/Error.hpp"
namespace glcxx
{
Array::Array()
{
m_id = 0u;
}
Array::~Array()
{
if (m_id != 0u)
{
glDeleteVertexArrays(1, &m_id);
}
}
void Array::create()
{
glGenVertexArrays(1, &m_id);
if (m_id == 0u)
{
throw Error("Failed to allocate an OpenGL array");
}
}
}