add GLBuffer class

This commit is contained in:
Josh Holtrop 2014-06-26 12:49:40 -04:00
parent 2f7bac1d75
commit 7c9c176c90
2 changed files with 54 additions and 0 deletions

30
src/gui/GLBuffer.cc Normal file
View File

@ -0,0 +1,30 @@
#include "GLBuffer.h"
namespace jes
{
GLBuffer::GLBuffer()
{
m_id = 0;
}
GLBuffer::~GLBuffer()
{
if (m_id > 0)
{
glDeleteBuffers(1, &m_id);
}
}
bool GLBuffer::create(GLenum target, GLenum usage, const void *ptr, size_t sz)
{
m_target = target;
glGenBuffers(1, &m_id);
if (m_id > 0)
{
bind();
glBufferData(target, sz, ptr, usage);
return true;
}
return false;
}
}

24
src/gui/GLBuffer.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef GLBUFFER_H
#define GLBUFFER_H
#include "gl3w.h"
#include "jes.h"
namespace jes
{
class GLBuffer
{
public:
GLBuffer();
~GLBuffer();
bool create(GLenum target, GLenum usage, const void *ptr, size_t sz);
GLuint get_id() { return m_id; }
void bind() { glBindBuffer(m_target, m_id); }
protected:
GLuint m_id;
GLenum m_target;
};
typedef Ref<GLBuffer> GLBufferRef;
}
#endif