2 #include "arb_vertex_buffer_object.h"
11 const Buffer *Buffer::bound[4] = { 0, 0, 0, 0 };
13 Buffer::Buffer(BufferType t):
18 static RequireExtension _req_vbo("GL_ARB_vertex_buffer_object");
19 if(type==PIXEL_PACK_BUFFER || type==PIXEL_UNPACK_BUFFER)
20 static RequireExtension _req_pbo("GL_ARB_pixel_buffer_object");
22 glGenBuffersARB(1, &id);
27 glDeleteBuffersARB(1, &id);
30 void Buffer::set_usage(BufferUsage u)
35 void Buffer::data(unsigned sz, const void *d)
37 const Buffer *old = current(type);
39 glBufferDataARB(type, sz, d, usage);
44 void Buffer::sub_data(unsigned off, unsigned sz, const void *d)
46 const Buffer *old = current(type);
48 glBufferSubDataARB(type, off, sz, d);
52 void Buffer::bind_to(BufferType t) const
54 const Buffer *&ptr = binding(t);
57 glBindBufferARB(t, id);
62 void Buffer::unbind_from(BufferType type)
64 const Buffer *&ptr = binding(type);
67 glBindBufferARB(type, 0);
72 const Buffer *&Buffer::binding(BufferType type)
76 case ARRAY_BUFFER: return bound[0];
77 case ELEMENT_ARRAY_BUFFER: return bound[1];
78 case PIXEL_PACK_BUFFER: return bound[2];
79 case PIXEL_UNPACK_BUFFER: return bound[3];
80 default: throw invalid_argument("Buffer::binding");
84 void Buffer::restore(const Buffer *buf, BufferType type)
86 if(buf!=current(type))