2 #include "arb_vertex_buffer_object.h"
11 const Buffer *Buffer::bound[4] = { 0, 0, 0, 0 };
13 Buffer::Buffer(BufferType t):
17 static RequireExtension _req_vbo("GL_ARB_vertex_buffer_object");
18 if(type==PIXEL_PACK_BUFFER || type==PIXEL_UNPACK_BUFFER)
19 static RequireExtension _req_pbo("GL_ARB_pixel_buffer_object");
21 glGenBuffersARB(1, &id);
26 glDeleteBuffersARB(1, &id);
29 void Buffer::set_usage(BufferUsage u)
34 void Buffer::data(unsigned size, const void *d)
36 const Buffer *old = current(type);
38 glBufferDataARB(type, size, d, usage);
42 void Buffer::sub_data(unsigned offset, unsigned size, const void *d)
44 const Buffer *old = current(type);
46 glBufferSubDataARB(type, offset, size, d);
50 void Buffer::bind_to(BufferType t) const
52 const Buffer *&ptr = binding(t);
55 glBindBufferARB(t, id);
60 void Buffer::unbind_from(BufferType type)
62 const Buffer *&ptr = binding(type);
65 glBindBufferARB(type, 0);
70 const Buffer *&Buffer::binding(BufferType type)
74 case ARRAY_BUFFER: return bound[0];
75 case ELEMENT_ARRAY_BUFFER: return bound[1];
76 case PIXEL_PACK_BUFFER: return bound[2];
77 case PIXEL_UNPACK_BUFFER: return bound[3];
78 default: throw invalid_argument("Buffer::binding");
82 void Buffer::restore(const Buffer *buf, BufferType type)
84 if(buf!=current(type))