namespace GL {
const Buffer *Buffer::bound[5] = { 0, 0, 0, 0, 0 };
+BufferType buffer_types[] = { ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER, PIXEL_PACK_BUFFER, PIXEL_UNPACK_BUFFER, UNIFORM_BUFFER };
Buffer::Buffer(BufferType t):
type(t),
Buffer::~Buffer()
{
+ for(unsigned i=0; i<5; ++i)
+ if(bound[i]==this)
+ unbind_from(buffer_types[i]);
glDeleteBuffers(1, &id);
}
return new BufferRange(*this, s, o);
}
+void *Buffer::map(BufferAccess access)
+{
+ BindRestore _bind(this, type);
+ return glMapBuffer(type, access);
+}
+
+bool Buffer::unmap()
+{
+ BindRestore _bind(this, type);
+ return glUnmapBuffer(type);
+}
+
void Buffer::bind_to(BufferType t) const
{
if(t!=type)
throw out_of_range("BufferRange::BufferRange");
}
+BufferRange::~BufferRange()
+{
+ for(unsigned i=0; i<bound_uniform.size(); ++i)
+ if(bound_uniform[i]==this)
+ unbind_from(UNIFORM_BUFFER, i);
+}
+
void BufferRange::data(const void *d)
{
buffer.sub_data(offset, size, d);