From f8de8368bb046844442107c51bc76a3251300f98 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 11 Jun 2015 21:24:06 -0400 Subject: [PATCH] add initial Array class --- include/glcxx.hpp | 3 ++- include/glcxx/Array.hpp | 31 +++++++++++++++++++++++++++++++ src/glcxx/Array.cpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 include/glcxx/Array.hpp create mode 100644 src/glcxx/Array.cpp diff --git a/include/glcxx.hpp b/include/glcxx.hpp index a6a1c30..dfdd893 100644 --- a/include/glcxx.hpp +++ b/include/glcxx.hpp @@ -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 diff --git a/include/glcxx/Array.hpp b/include/glcxx/Array.hpp new file mode 100644 index 0000000..9734a96 --- /dev/null +++ b/include/glcxx/Array.hpp @@ -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 diff --git a/src/glcxx/Array.cpp b/src/glcxx/Array.cpp new file mode 100644 index 0000000..f028bd6 --- /dev/null +++ b/src/glcxx/Array.cpp @@ -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"); + } + } +}