2 #include "arb_vertex_buffer_object.h"
11 Buffer::Buffer(BufferType t):
15 static RequireExtension _req_vbo("GL_ARB_vertex_buffer_object");
16 if(type==PIXEL_PACK_BUFFER || type==PIXEL_UNPACK_BUFFER)
17 static RequireExtension _req_pbo("GL_ARB_pixel_buffer_object");
19 glGenBuffersARB(1, &id);
24 glDeleteBuffersARB(1, &id);
27 void Buffer::set_usage(BufferUsage u)
32 void Buffer::data(unsigned size, const void *d)
34 const Buffer *old = current(type);
36 glBufferDataARB(type, size, d, usage);
40 void Buffer::sub_data(unsigned offset, unsigned size, const void *d)
42 const Buffer *old = current(type);
44 glBufferSubDataARB(type, offset, size, d);
48 void Buffer::bind_to(BufferType t) const
50 const Buffer *&ptr = binding(t);
53 glBindBufferARB(t, id);
58 void Buffer::unbind_from(BufferType type)
60 const Buffer *&ptr = binding(type);
63 glBindBufferARB(type, 0);
68 const Buffer *&Buffer::binding(BufferType type)
72 case ARRAY_BUFFER: return bound[0];
73 case ELEMENT_ARRAY_BUFFER: return bound[1];
74 case PIXEL_PACK_BUFFER: return bound[2];
75 case PIXEL_UNPACK_BUFFER: return bound[3];
76 default: throw invalid_argument("Buffer::binding");
80 void Buffer::restore(const Buffer *buf, BufferType type)
82 if(buf!=current(type))
91 const Buffer *Buffer::bound[4] = { 0, 0, 0, 0 };