1 #include "arb_vertex_buffer_object.h"
8 Buffer::Buffer(BufferType t):
12 static RequireExtension _req_vbo("GL_ARB_vertex_buffer_object");
13 if(type==PIXEL_PACK_BUFFER || type==PIXEL_UNPACK_BUFFER)
14 static RequireExtension _req_pbo("GL_ARB_pixel_buffer_object");
16 glGenBuffersARB(1, &id);
21 glDeleteBuffersARB(1, &id);
24 void Buffer::set_usage(BufferUsage u)
29 void Buffer::data(unsigned size, const void *d)
31 const Buffer *old = current(type);
33 glBufferDataARB(type, size, d, usage);
37 void Buffer::sub_data(unsigned offset, unsigned size, const void *d)
39 const Buffer *old = current(type);
41 glBufferSubDataARB(type, offset, size, d);
45 void Buffer::bind_to(BufferType t) const
47 const Buffer *&ptr = binding(t);
50 glBindBufferARB(t, id);
55 void Buffer::unbind_from(BufferType type)
57 const Buffer *&ptr = binding(type);
60 glBindBufferARB(type, 0);
65 const Buffer *&Buffer::binding(BufferType type)
69 case ARRAY_BUFFER: return bound[0];
70 case ELEMENT_ARRAY_BUFFER: return bound[1];
71 case PIXEL_PACK_BUFFER: return bound[2];
72 case PIXEL_UNPACK_BUFFER: return bound[3];
73 default: throw InvalidParameterValue("Invalid buffer type");
77 void Buffer::restore(const Buffer *buf, BufferType type)
79 if(buf!=current(type))
88 const Buffer *Buffer::bound[4] = { 0, 0, 0, 0 };